| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'dotenv/config';
- import { readFile } from 'node:fs/promises';
- import { randomUUID } from 'node:crypto';
- import { fileURLToPath } from 'node:url';
- import { dirname, resolve } from 'node:path';
- const required = ['PARSE_SERVER_URL', 'PARSE_APP_ID', 'PARSE_MASTER_KEY'];
- for (const name of required) if (!process.env[name]?.trim()) throw new Error(`${name} is required`);
- const registryBase = (process.env.FUNCTION_REGISTRY_SERVER_URL || process.env.PARSE_SERVER_URL).replace(/\/+$/, '');
- const registryAppId = process.env.FUNCTION_REGISTRY_APP_ID || process.env.PARSE_APP_ID;
- const registryMasterKey = process.env.FUNCTION_REGISTRY_MASTER_KEY || process.env.PARSE_MASTER_KEY;
- const headers = { 'Content-Type': 'application/json', 'X-Parse-Application-Id': registryAppId, 'X-Parse-Master-Key': registryMasterKey };
- const __dirname = dirname(fileURLToPath(import.meta.url));
- // Deploy only the original consolidated gateway
- const FUNCTION = {
- name: 'vSaaSVocGateway',
- path: '/saas-voc-gateway',
- file: 'saas-voc-gateway.js',
- desc: 'SaaS VOC allow-listed Cloud Function gateway',
- objectId: 'ZLDvkbQ16D',
- };
- async function deployFunction() {
- const filePath = resolve(__dirname, '..', 'cloud-functions', FUNCTION.file);
- const code = await readFile(filePath, 'utf8');
- const url = `${registryBase}/classes/Function/${FUNCTION.objectId}`;
- const payload = {
- name: FUNCTION.name,
- desc: FUNCTION.desc,
- type: 'standalone',
- path: FUNCTION.path,
- paramList: [{ name: 'params', type: 'Object', required: true }],
- code,
- respType: 'json',
- respJson: { success: true, data: null, requestId: randomUUID() },
- isDeleted: false,
- };
- const response = await fetch(url, {
- method: 'PUT',
- headers,
- body: JSON.stringify(payload),
- });
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(`Function deployment failed: HTTP ${response.status} - ${errorText}`);
- }
- const result = await response.json();
- return { ok: true, objectId: result.objectId };
- }
- async function main() {
- console.log(`Deploying ${FUNCTION.name}...`);
- const result = await deployFunction();
- console.log(`✓ ${FUNCTION.name} (${result.objectId})`);
- console.log(`Path: ${FUNCTION.path}`);
- }
- main().catch((error) => {
- console.error('Deployment failed:', error);
- process.exitCode = 1;
- });
|