@zuplo/cli 6.51.60 → 6.51.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/editor/server/server.ts"],"names":[],"mappings":"AAKA,OAAgB,EAAqB,eAAe,EAAE,MAAM,SAAS,CAAC;AA2BtE,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,SAAS;IACb,OAAO,EAAE,eAAe,CAAC;IAChC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAqB;IAEpC,OAAO,CAAC,UAAU,CAAM;IAExB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAU;gBAG5B,OAAO,GAAE,aAKR;IAgBH,IAAI,QAAa,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/editor/server/server.ts"],"names":[],"mappings":"AAKA,OAAgB,EAAqB,eAAe,EAAE,MAAM,SAAS,CAAC;AA2BtE,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,SAAS;IACb,OAAO,EAAE,eAAe,CAAC;IAChC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAqB;IAEpC,OAAO,CAAC,UAAU,CAAM;IAExB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAU;gBAG5B,OAAO,GAAE,aAKR;IAgBH,IAAI,QAAa,OAAO,CAAC,IAAI,CAAC,CAkP5B;IAEF,KAAK,QAAa,OAAO,CAAC,IAAI,CAAC,CAkC7B;IAEF,KAAK,QAAa,OAAO,CAAC,IAAI,CAAC,CAE7B;IAEF,KAAK,QAAa,OAAO,CAAC,IAAI,CAAC,CAsB7B;CACH"}
|
|
@@ -124,15 +124,16 @@ export class ApiServer {
|
|
|
124
124
|
event: "route-designer: /save-open-api-updates",
|
|
125
125
|
});
|
|
126
126
|
const bodyContent = request.body;
|
|
127
|
-
|
|
127
|
+
for (const fileData of bodyContent) {
|
|
128
128
|
const openApiFilePath = path.join(this.workingDir, "config", fileData.filePath);
|
|
129
129
|
if (!(await fileExists(openApiFilePath))) {
|
|
130
|
-
|
|
130
|
+
reply.code(404).send({
|
|
131
131
|
message: `Cannot find file named '${fileData.filePath}'`,
|
|
132
132
|
});
|
|
133
|
+
return;
|
|
133
134
|
}
|
|
134
135
|
await fs.writeFile(openApiFilePath, JSON.stringify(fileData.content, null, 2));
|
|
135
|
-
}
|
|
136
|
+
}
|
|
136
137
|
reply.code(200).send({ message: "Changes were saved successfully" });
|
|
137
138
|
},
|
|
138
139
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/editor/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,OAA+C,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC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, { readFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport fastifyStatic from \"@fastify/static\";\nimport chokidar from \"chokidar\";\nimport Fastify, { FastifyBaseLogger, FastifyInstance } from \"fastify\";\nimport { FastifySSEPlugin } from \"fastify-sse-v2\";\nimport { captureEvent, shutdownAnalytics } from \"../../common/analytics/lib.js\";\nimport { logger } from \"../../common/logger.js\";\nimport { printDiagnosticsToConsole } from \"../../common/output.js\";\nimport { corsPlugin } from \"./cors-plugin.js\";\nimport { dirExists, fileExists } from \"./xfs.js\";\n\nconst POLICIES_FILENAME = \"policies.json\";\nconst CONFIG_DIR = \"config\";\n\ninterface FunctionPickerMethod {\n name: string;\n isHandlerInvocable: boolean;\n}\n\ninterface FunctionPickerModule {\n name: string;\n filepath: string;\n methods: FunctionPickerMethod[];\n}\n\ninterface FileSaveBody {\n filePath: string;\n content: object;\n}\n\ninterface ServerOptions {\n cliArgs: unknown;\n workingDir: string;\n port: number;\n isStandalone: boolean;\n}\n\nexport class ApiServer {\n public fastify: FastifyInstance;\n private listenerHost: string;\n private watcher: chokidar.FSWatcher;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private sseContext: any;\n\n private cliArgs: unknown;\n private workingDir: string;\n private listenerPort: number;\n private isStandalone: boolean;\n\n constructor(\n options: ServerOptions = {\n cliArgs: {},\n workingDir: \".\",\n port: 9100,\n isStandalone: true,\n }\n ) {\n this.cliArgs = options.cliArgs;\n this.workingDir = options.workingDir;\n this.listenerPort = options.port;\n this.isStandalone = options.isStandalone;\n this.listenerHost = \"localhost\";\n this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));\n this.fastify = Fastify({\n logger: logger as FastifyBaseLogger,\n trustProxy: true,\n disableRequestLogging: true,\n bodyLimit: 104857600, // 100mb\n });\n }\n\n init = async (): Promise<void> => {\n const cliArgs = this.cliArgs;\n this.fastify.register(corsPlugin, { origin: true });\n this.fastify.register(FastifySSEPlugin);\n\n const editorRootPath = fileURLToPath(new URL(\"../\", import.meta.url));\n this.fastify.register(fastifyStatic, {\n root: editorRootPath,\n });\n\n this.fastify.register((instance, _options, done) => {\n instance.get(\"/\", {\n handler: async (_request, reply) => {\n await captureEvent({ argv: cliArgs, event: \"route-designer: /\" });\n let html = await readFile(\n path.join(editorRootPath, \"index.html\"),\n \"utf-8\"\n );\n html = html.replace(\n \"__SERVER_DATA__\",\n JSON.stringify({\n server_address: this.listenerHost,\n server_port: this.listenerPort,\n })\n );\n reply.type(\"text/html\").send(html);\n },\n });\n\n instance.get(\"/open-api-content\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /open-api-content\",\n });\n\n const { path: filePath } = request.query as { path: string | null };\n if (filePath === null || filePath === undefined) {\n return reply.code(404).send(\"You must select a file to work with\");\n }\n\n const openApiFilePath = path.join(\n this.workingDir,\n \"config\",\n filePath\n );\n if (!(await fileExists(openApiFilePath))) {\n return reply\n .code(404)\n .send({ message: `Cannot find file named '${filePath}'` });\n }\n\n const policiesPath = path.join(\n this.workingDir,\n \"config\",\n POLICIES_FILENAME\n );\n if (!(await fileExists(policiesPath))) {\n return reply.code(404).send({\n message: `Cannot find a '${POLICIES_FILENAME}' file in the '${CONFIG_DIR}'`,\n });\n }\n\n // read & send\n const openApiFileContent = await fs.readFile(\n openApiFilePath,\n \"utf-8\"\n );\n const policiesContent = await fs.readFile(policiesPath, \"utf-8\");\n\n const payload = [\n {\n path: filePath,\n content: JSON.parse(openApiFileContent),\n },\n {\n path: POLICIES_FILENAME,\n content: JSON.parse(policiesContent),\n },\n ];\n reply.code(200).send(payload);\n },\n });\n\n instance.get(\"/open-api-files\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /open-api-files\",\n });\n const projectConfigPath = path.join(this.workingDir, CONFIG_DIR);\n if (!(await dirExists(projectConfigPath))) {\n request.log.warn(\n `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`\n );\n return reply.code(404).send({\n message: `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`,\n });\n }\n\n const files = await readdir(projectConfigPath);\n const openApiFiles = files.filter((fileName) =>\n fileName.endsWith(\".oas.json\")\n );\n reply.code(200).send(openApiFiles);\n },\n });\n\n instance.route<{ Body: FileSaveBody[] }>({\n method: \"POST\",\n\n url: \"/save-open-api-updates\",\n handler: async (request, reply): Promise<void> => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /save-open-api-updates\",\n });\n\n const bodyContent = request.body;\n\n bodyContent.forEach(async (fileData) => {\n const openApiFilePath = path.join(\n this.workingDir,\n \"config\",\n fileData.filePath\n );\n if (!(await fileExists(openApiFilePath))) {\n return reply.code(404).send({\n message: `Cannot find file named '${fileData.filePath}'`,\n });\n }\n\n await fs.writeFile(\n openApiFilePath,\n JSON.stringify(fileData.content, null, 2) as string\n );\n });\n\n reply.code(200).send({ message: \"Changes were saved successfully\" });\n },\n });\n\n // SSE endpoint for real-time updates\n instance.get(\"/updates\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /updates\",\n });\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (this.watcher && this.watcher.closed === true) {\n // @NOTE - some UI interactions send a close event & we need to reenable\n // the watcher in the next event subscription request\n this.watcher = chokidar.watch(\n path.join(this.workingDir, CONFIG_DIR)\n );\n }\n\n this.watcher.on(\"change\", (filePath: string) => {\n const eventData = JSON.stringify({ type: \"update\", filePath });\n reply.sse({ id: Date.now().toString(), data: eventData });\n });\n\n request.raw.on(\"close\", async () => {\n await this.watcher.close();\n });\n\n // @NOTE - Initial reply to successfully initialize SSE connection\n reply.sse({\n id: Date.now().toString(),\n data: JSON.stringify({ filePath: POLICIES_FILENAME, type: \"init\" }),\n retry: 10,\n });\n this.sseContext = reply.sseContext;\n },\n });\n\n instance.get(\"/modules-data\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /modules-data\",\n });\n\n const projectModulesPath = path.join(this.workingDir, \"modules\");\n if (!(await dirExists(projectModulesPath))) {\n request.log.warn(\n `Cannot find the project 'modules' folder. Make sure '${this.workingDir}' has a 'modules' folder.`\n );\n return reply.code(200).send([]);\n }\n\n const files = await readdir(projectModulesPath);\n const modulesFiles = files.filter((fileName) =>\n fileName.endsWith(\".ts\")\n );\n\n const results: FunctionPickerModule[] = [];\n\n // @NOTE - its either this or bundling 40mb of typescript in the cli\n for (const moduleFileName of modulesFiles) {\n const fullPath = path.join(projectModulesPath, moduleFileName);\n const fileContent = await fs.readFile(fullPath, \"utf-8\");\n const exports: FunctionPickerMethod[] = [];\n\n // Regular expression to find default export\n const defaultExportRegex = /(?:export\\s+(default))/g;\n if (defaultExportRegex.exec(fileContent)) {\n exports.push({ name: \"default\", isHandlerInvocable: true });\n }\n\n // Regular expression to match exported functions/classes\n const functionRegex =\n /(?:export\\s+(function|class))\\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;\n\n let match;\n while ((match = functionRegex.exec(fileContent))) {\n exports.push({ name: match[2], isHandlerInvocable: true });\n }\n\n results.push({\n name: moduleFileName,\n filepath: `./modules/${moduleFileName}`,\n methods: exports,\n });\n }\n\n reply.code(200).send(results);\n },\n });\n\n instance.get(\"/ping\", {\n handler: async (_request, reply) => {\n reply.code(200).send();\n },\n });\n\n done();\n });\n };\n\n start = async (): Promise<void> => {\n await this.init();\n\n // See https://github.com/fastify/help/issues/641\n this.fastify.log.level = \"silent\";\n const start = async () => {\n return new Promise<void>((resolve, reject) => {\n this.fastify.listen(\n { port: this.listenerPort, host: this.listenerHost },\n (err) => {\n if (err) {\n reject(err);\n }\n\n this.fastify.log.level = \"info\";\n\n if (this.isStandalone) {\n printDiagnosticsToConsole(\"Started route designer\");\n printDiagnosticsToConsole(\"Ctrl+C to exit\");\n printDiagnosticsToConsole(\"\");\n printDiagnosticsToConsole(\n `📘 Route Designer: http://${this.listenerHost}:${this.listenerPort}`\n );\n printDiagnosticsToConsole(\"\");\n printDiagnosticsToConsole(\"\");\n }\n\n resolve();\n }\n );\n });\n };\n\n await start();\n };\n\n ready = async (): Promise<void> => {\n return this.fastify.ready();\n };\n\n close = async (): Promise<void> => {\n if (this.isStandalone) {\n printDiagnosticsToConsole(\"Closing route designer\");\n }\n\n try {\n void shutdownAnalytics();\n\n if (this.sseContext) {\n this.sseContext.source.end();\n }\n\n if (this.watcher) {\n await this.watcher.close();\n }\n\n await this.fastify.close();\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n process.exit();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/editor/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,OAA+C,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAC1C,MAAM,UAAU,GAAG,QAAQ,CAAC;AAyB5B,MAAM,OAAO,SAAS;IACb,OAAO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AAC;QACL,CAAC,CAAC;QAEF,MAAM,KAAK,EAAE,CAAC;IAChB,CAAC,CAAC;IAEF,KAAK,GAAG,KAAK,IAAmB,EAAE;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC,CAAC;IAEF,KAAK,GAAG,KAAK,IAAmB,EAAE;QAChC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,yBAAyB,CAAC,wBAAwB,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,CAAC;YACH,KAAK,iBAAiB,EAAE,CAAC;YAEzB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAC/B,CAAC;YAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7B,CAAC;YAED,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YAEb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC,CAAC;CACH","sourcesContent":["import fs, { readFile, readdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport fastifyStatic from \"@fastify/static\";\nimport chokidar from \"chokidar\";\nimport Fastify, { FastifyBaseLogger, FastifyInstance } from \"fastify\";\nimport { FastifySSEPlugin } from \"fastify-sse-v2\";\nimport { captureEvent, shutdownAnalytics } from \"../../common/analytics/lib.js\";\nimport { logger } from \"../../common/logger.js\";\nimport { printDiagnosticsToConsole } from \"../../common/output.js\";\nimport { corsPlugin } from \"./cors-plugin.js\";\nimport { dirExists, fileExists } from \"./xfs.js\";\n\nconst POLICIES_FILENAME = \"policies.json\";\nconst CONFIG_DIR = \"config\";\n\ninterface FunctionPickerMethod {\n name: string;\n isHandlerInvocable: boolean;\n}\n\ninterface FunctionPickerModule {\n name: string;\n filepath: string;\n methods: FunctionPickerMethod[];\n}\n\ninterface FileSaveBody {\n filePath: string;\n content: object;\n}\n\ninterface ServerOptions {\n cliArgs: unknown;\n workingDir: string;\n port: number;\n isStandalone: boolean;\n}\n\nexport class ApiServer {\n public fastify: FastifyInstance;\n private listenerHost: string;\n private watcher: chokidar.FSWatcher;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private sseContext: any;\n\n private cliArgs: unknown;\n private workingDir: string;\n private listenerPort: number;\n private isStandalone: boolean;\n\n constructor(\n options: ServerOptions = {\n cliArgs: {},\n workingDir: \".\",\n port: 9100,\n isStandalone: true,\n }\n ) {\n this.cliArgs = options.cliArgs;\n this.workingDir = options.workingDir;\n this.listenerPort = options.port;\n this.isStandalone = options.isStandalone;\n this.listenerHost = \"localhost\";\n this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));\n this.fastify = Fastify({\n logger: logger as FastifyBaseLogger,\n trustProxy: true,\n disableRequestLogging: true,\n bodyLimit: 104857600, // 100mb\n });\n }\n\n init = async (): Promise<void> => {\n const cliArgs = this.cliArgs;\n this.fastify.register(corsPlugin, { origin: true });\n this.fastify.register(FastifySSEPlugin);\n\n const editorRootPath = fileURLToPath(new URL(\"../\", import.meta.url));\n this.fastify.register(fastifyStatic, {\n root: editorRootPath,\n });\n\n this.fastify.register((instance, _options, done) => {\n instance.get(\"/\", {\n handler: async (_request, reply) => {\n await captureEvent({ argv: cliArgs, event: \"route-designer: /\" });\n let html = await readFile(\n path.join(editorRootPath, \"index.html\"),\n \"utf-8\"\n );\n html = html.replace(\n \"__SERVER_DATA__\",\n JSON.stringify({\n server_address: this.listenerHost,\n server_port: this.listenerPort,\n })\n );\n reply.type(\"text/html\").send(html);\n },\n });\n\n instance.get(\"/open-api-content\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /open-api-content\",\n });\n\n const { path: filePath } = request.query as { path: string | null };\n if (filePath === null || filePath === undefined) {\n return reply.code(404).send(\"You must select a file to work with\");\n }\n\n const openApiFilePath = path.join(\n this.workingDir,\n \"config\",\n filePath\n );\n if (!(await fileExists(openApiFilePath))) {\n return reply\n .code(404)\n .send({ message: `Cannot find file named '${filePath}'` });\n }\n\n const policiesPath = path.join(\n this.workingDir,\n \"config\",\n POLICIES_FILENAME\n );\n if (!(await fileExists(policiesPath))) {\n return reply.code(404).send({\n message: `Cannot find a '${POLICIES_FILENAME}' file in the '${CONFIG_DIR}'`,\n });\n }\n\n // read & send\n const openApiFileContent = await fs.readFile(\n openApiFilePath,\n \"utf-8\"\n );\n const policiesContent = await fs.readFile(policiesPath, \"utf-8\");\n\n const payload = [\n {\n path: filePath,\n content: JSON.parse(openApiFileContent),\n },\n {\n path: POLICIES_FILENAME,\n content: JSON.parse(policiesContent),\n },\n ];\n reply.code(200).send(payload);\n },\n });\n\n instance.get(\"/open-api-files\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /open-api-files\",\n });\n const projectConfigPath = path.join(this.workingDir, CONFIG_DIR);\n if (!(await dirExists(projectConfigPath))) {\n request.log.warn(\n `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`\n );\n return reply.code(404).send({\n message: `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`,\n });\n }\n\n const files = await readdir(projectConfigPath);\n const openApiFiles = files.filter((fileName) =>\n fileName.endsWith(\".oas.json\")\n );\n reply.code(200).send(openApiFiles);\n },\n });\n\n instance.route<{ Body: FileSaveBody[] }>({\n method: \"POST\",\n\n url: \"/save-open-api-updates\",\n handler: async (request, reply): Promise<void> => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /save-open-api-updates\",\n });\n\n const bodyContent = request.body;\n\n for (const fileData of bodyContent) {\n const openApiFilePath = path.join(\n this.workingDir,\n \"config\",\n fileData.filePath\n );\n if (!(await fileExists(openApiFilePath))) {\n reply.code(404).send({\n message: `Cannot find file named '${fileData.filePath}'`,\n });\n return;\n }\n\n await fs.writeFile(\n openApiFilePath,\n JSON.stringify(fileData.content, null, 2) as string\n );\n }\n\n reply.code(200).send({ message: \"Changes were saved successfully\" });\n },\n });\n\n // SSE endpoint for real-time updates\n instance.get(\"/updates\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /updates\",\n });\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (this.watcher && this.watcher.closed === true) {\n // @NOTE - some UI interactions send a close event & we need to reenable\n // the watcher in the next event subscription request\n this.watcher = chokidar.watch(\n path.join(this.workingDir, CONFIG_DIR)\n );\n }\n\n this.watcher.on(\"change\", (filePath: string) => {\n const eventData = JSON.stringify({ type: \"update\", filePath });\n reply.sse({ id: Date.now().toString(), data: eventData });\n });\n\n request.raw.on(\"close\", async () => {\n await this.watcher.close();\n });\n\n // @NOTE - Initial reply to successfully initialize SSE connection\n reply.sse({\n id: Date.now().toString(),\n data: JSON.stringify({ filePath: POLICIES_FILENAME, type: \"init\" }),\n retry: 10,\n });\n this.sseContext = reply.sseContext;\n },\n });\n\n instance.get(\"/modules-data\", {\n handler: async (request, reply) => {\n await captureEvent({\n argv: cliArgs,\n event: \"route-designer: /modules-data\",\n });\n\n const projectModulesPath = path.join(this.workingDir, \"modules\");\n if (!(await dirExists(projectModulesPath))) {\n request.log.warn(\n `Cannot find the project 'modules' folder. Make sure '${this.workingDir}' has a 'modules' folder.`\n );\n return reply.code(200).send([]);\n }\n\n const files = await readdir(projectModulesPath);\n const modulesFiles = files.filter((fileName) =>\n fileName.endsWith(\".ts\")\n );\n\n const results: FunctionPickerModule[] = [];\n\n // @NOTE - its either this or bundling 40mb of typescript in the cli\n for (const moduleFileName of modulesFiles) {\n const fullPath = path.join(projectModulesPath, moduleFileName);\n const fileContent = await fs.readFile(fullPath, \"utf-8\");\n const exports: FunctionPickerMethod[] = [];\n\n // Regular expression to find default export\n const defaultExportRegex = /(?:export\\s+(default))/g;\n if (defaultExportRegex.exec(fileContent)) {\n exports.push({ name: \"default\", isHandlerInvocable: true });\n }\n\n // Regular expression to match exported functions/classes\n const functionRegex =\n /(?:export\\s+(function|class))\\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;\n\n let match;\n while ((match = functionRegex.exec(fileContent))) {\n exports.push({ name: match[2], isHandlerInvocable: true });\n }\n\n results.push({\n name: moduleFileName,\n filepath: `./modules/${moduleFileName}`,\n methods: exports,\n });\n }\n\n reply.code(200).send(results);\n },\n });\n\n instance.get(\"/ping\", {\n handler: async (_request, reply) => {\n reply.code(200).send();\n },\n });\n\n done();\n });\n };\n\n start = async (): Promise<void> => {\n await this.init();\n\n // See https://github.com/fastify/help/issues/641\n this.fastify.log.level = \"silent\";\n const start = async () => {\n return new Promise<void>((resolve, reject) => {\n this.fastify.listen(\n { port: this.listenerPort, host: this.listenerHost },\n (err) => {\n if (err) {\n reject(err);\n }\n\n this.fastify.log.level = \"info\";\n\n if (this.isStandalone) {\n printDiagnosticsToConsole(\"Started route designer\");\n printDiagnosticsToConsole(\"Ctrl+C to exit\");\n printDiagnosticsToConsole(\"\");\n printDiagnosticsToConsole(\n `📘 Route Designer: http://${this.listenerHost}:${this.listenerPort}`\n );\n printDiagnosticsToConsole(\"\");\n printDiagnosticsToConsole(\"\");\n }\n\n resolve();\n }\n );\n });\n };\n\n await start();\n };\n\n ready = async (): Promise<void> => {\n return this.fastify.ready();\n };\n\n close = async (): Promise<void> => {\n if (this.isStandalone) {\n printDiagnosticsToConsole(\"Closing route designer\");\n }\n\n try {\n void shutdownAnalytics();\n\n if (this.sseContext) {\n this.sseContext.source.end();\n }\n\n if (this.watcher) {\n await this.watcher.close();\n }\n\n await this.fastify.close();\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n process.exit();\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "6.51.
|
|
3
|
+
"version": "6.51.61",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@opentelemetry/api": "1.9.0",
|
|
30
30
|
"@sentry/node": "9.22.0",
|
|
31
31
|
"@swc/core": "1.10.18",
|
|
32
|
-
"@zuplo/core": "^6.51.
|
|
33
|
-
"@zuplo/openapi-tools": "^6.51.
|
|
34
|
-
"@zuplo/runtime": "^6.51.
|
|
32
|
+
"@zuplo/core": "^6.51.61",
|
|
33
|
+
"@zuplo/openapi-tools": "^6.51.61",
|
|
34
|
+
"@zuplo/runtime": "^6.51.61",
|
|
35
35
|
"as-table": "1.0.55",
|
|
36
36
|
"chalk": "5.4.1",
|
|
37
37
|
"chokidar": "3.5.3",
|