@zuplo/cli 6.62.1 → 6.62.2
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.
- package/dist/dev/handler.d.ts.map +1 -1
- package/dist/dev/handler.js +6 -18
- package/dist/dev/handler.js.map +1 -1
- package/dist/editor/handler.d.ts.map +1 -1
- package/dist/editor/handler.js +19 -12
- package/dist/editor/handler.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/editor/assets/index-300931c5.css +0 -1
- package/dist/editor/assets/index-7e947de6.d.ts +0 -2
- package/dist/editor/assets/index-7e947de6.d.ts.map +0 -1
- package/dist/editor/assets/index-7e947de6.js +0 -10915
- package/dist/editor/assets/index-7e947de6.js.map +0 -1
- package/dist/editor/favicon.ico +0 -0
- package/dist/editor/icons/arrow_head_down.svg +0 -7
- package/dist/editor/icons/arrow_head_up.svg +0 -7
- package/dist/editor/icons/arrow_line.svg +0 -7
- package/dist/editor/index.html +0 -22
- package/dist/editor/server/cors-plugin.d.ts +0 -13
- package/dist/editor/server/cors-plugin.d.ts.map +0 -1
- package/dist/editor/server/cors-plugin.js +0 -16
- package/dist/editor/server/cors-plugin.js.map +0 -1
- package/dist/editor/server/server.d.ts +0 -24
- package/dist/editor/server/server.d.ts.map +0 -1
- package/dist/editor/server/server.js +0 -255
- package/dist/editor/server/server.js.map +0 -1
- package/dist/editor/server/xfs.d.ts +0 -3
- package/dist/editor/server/xfs.d.ts.map +0 -1
- package/dist/editor/server/xfs.js +0 -20
- package/dist/editor/server/xfs.js.map +0 -1
package/dist/editor/favicon.ico
DELETED
|
Binary file
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg width="14px" height="14px" viewBox="0 0 14 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
-
<title>arrow_head_down</title>
|
|
4
|
-
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
-
<path id="Line" d="M6.99834712,-141.001647 L6.99999728,-140.50165 L7.47525555,3.50160715 L7.495,9.589 L11.0386287,3.24149839 L11.2823198,2.80490399 L12.1555086,3.29228609 L11.9118176,3.72888049 L7.43824456,11.7436883 L7.00501603,12.5198562 L6.56667377,11.7465648 L2.04029578,3.76145977 L1.79372826,3.32648338 L2.66368103,2.83334834 L2.91024855,3.26832473 L6.495,9.593 L6.475261,3.50490747 L6.00000272,-140.49835 L5.99835257,-140.998347 L6.99834712,-141.001647 Z" fill="#EA00BD" fill-rule="nonzero"></path>
|
|
6
|
-
</g>
|
|
7
|
-
</svg>
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg width="14px" height="14px" viewBox="0 0 14 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
-
<title>arrow_head_up</title>
|
|
4
|
-
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
-
<path id="Line" d="M6.49498397,1.98014385 L6.93332623,2.7534352 L11.4597042,10.7385402 L11.7062717,11.1735166 L10.836319,11.6666517 L10.5897514,11.2316753 L7.004,4.906 L7.024739,10.9950925 L7.47525555,147.501607 L7.495,153.589 L11.0386287,147.241498 L11.2823198,146.804904 L12.1555086,147.292286 L11.9118176,147.72888 L7.43824456,155.743688 L7.00501603,156.519856 L6.56667377,155.746565 L2.04029578,147.76146 L1.79372826,147.326483 L2.66368103,146.833348 L2.91024855,147.268325 L6.495,153.593 L6.475261,147.504907 L6.02474445,10.9983928 L6.004,4.91 L2.46137125,11.2585016 L2.2176802,11.695096 L1.3444914,11.2077139 L1.58818244,10.7711195 L6.06175544,2.75631167 L6.49498397,1.98014385 Z" fill="#EA00BD" fill-rule="nonzero"></path>
|
|
6
|
-
</g>
|
|
7
|
-
</svg>
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg width="14px" height="6px" viewBox="0 0 14 6" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
-
<title>arrow_line</title>
|
|
4
|
-
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
-
<path id="Line" d="M6.99834712,-136.001647 L6.99999728,-135.50165 L7.47525555,8.50160715 L7.495,14.589 L11.0386287,8.24149839 L11.2823198,7.80490399 L12.1555086,8.29228609 L11.9118176,8.72888049 L7.43824456,16.7436883 L7.00501603,17.5198562 L6.56667377,16.7465648 L2.04029578,8.76145977 L1.79372826,8.32648338 L2.66368103,7.83334834 L2.91024855,8.26832473 L6.495,14.593 L6.475261,8.50490747 L6.00000272,-135.49835 L5.99835257,-135.998347 L6.99834712,-136.001647 Z" fill="#EA00BD" fill-rule="nonzero"></path>
|
|
6
|
-
</g>
|
|
7
|
-
</svg>
|
package/dist/editor/index.html
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" href="/favicon.ico" />
|
|
6
|
-
<style>
|
|
7
|
-
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@500&display=swap");
|
|
8
|
-
</style>
|
|
9
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
10
|
-
<title>Zuplo Local Designer</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-7e947de6.js"></script>
|
|
12
|
-
<link rel="stylesheet" href="/assets/index-300931c5.css" />
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<div id="root"></div>
|
|
16
|
-
|
|
17
|
-
<script>
|
|
18
|
-
// Set the global window variable
|
|
19
|
-
window.SERVER_DATA = __SERVER_DATA__;
|
|
20
|
-
</script>
|
|
21
|
-
</body>
|
|
22
|
-
</html>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const corsPlugin: (
|
|
2
|
-
fastify: import("fastify").FastifyInstance<
|
|
3
|
-
import("fastify").RawServerDefault,
|
|
4
|
-
import("http").IncomingMessage,
|
|
5
|
-
import("http").ServerResponse<import("http").IncomingMessage>,
|
|
6
|
-
import("fastify").FastifyBaseLogger,
|
|
7
|
-
import("fastify").FastifyTypeProviderDefault
|
|
8
|
-
>,
|
|
9
|
-
opts: {
|
|
10
|
-
origin: boolean;
|
|
11
|
-
}
|
|
12
|
-
) => Promise<void>;
|
|
13
|
-
//# sourceMappingURL=cors-plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cors-plugin.d.ts","sourceRoot":"","sources":["../../../src/editor/server/cors-plugin.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,2QAGf;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,kBAmBzB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import cors from "@fastify/cors";
|
|
2
|
-
import fp from "fastify-plugin";
|
|
3
|
-
export const corsPlugin = fp(async function (fastify, opts) {
|
|
4
|
-
fastify.register(cors, () => {
|
|
5
|
-
return (req, callback) => {
|
|
6
|
-
const corsOptions = {
|
|
7
|
-
origin: opts.origin,
|
|
8
|
-
};
|
|
9
|
-
if (/^localhost$/m.test(req.headers.origin ?? "")) {
|
|
10
|
-
corsOptions.origin = false;
|
|
11
|
-
}
|
|
12
|
-
callback(null, corsOptions);
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
//# sourceMappingURL=cors-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cors-plugin.js","sourceRoot":"","sources":["../../../src/editor/server/cors-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,eAAe,CAAC;AAEjC,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,KAAK,WAChC,OAAO,EAEP,IAAyB;IAEzB,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE;QAE1B,OAAO,CAAC,GAAmB,EAAE,QAAa,EAAE,EAAE;YAC5C,MAAM,WAAW,GAAG;gBAElB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC;YAGF,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;gBAClD,WAAW,CAAC,MAAM,GAAG,KAAK,CAAC;YAC7B,CAAC;YAGD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC9B,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import cors from \"@fastify/cors\";\nimport { FastifyRequest } from \"fastify\";\nimport fp from \"fastify-plugin\";\n\nexport const corsPlugin = fp(async function (\n fastify,\n // origin=true is NOT recommended for production as it enables reflection exploits\n opts: { origin: boolean }\n) {\n fastify.register(cors, () => {\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n return (req: FastifyRequest, callback: any) => {\n const corsOptions = {\n // This is NOT recommended for production as it enables reflection exploits\n origin: opts.origin,\n };\n\n // do not include CORS headers for requests from localhost\n if (/^localhost$/m.test(req.headers.origin ?? \"\")) {\n corsOptions.origin = false;\n }\n\n // callback expects two parameters: error and options\n callback(null, corsOptions);\n };\n });\n});\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { FastifyInstance } from "fastify";
|
|
2
|
-
interface ServerOptions {
|
|
3
|
-
cliArgs: unknown;
|
|
4
|
-
workingDir: string;
|
|
5
|
-
port: number;
|
|
6
|
-
isStandalone: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare class ApiServer {
|
|
9
|
-
fastify: FastifyInstance;
|
|
10
|
-
private listenerHost;
|
|
11
|
-
private watcher;
|
|
12
|
-
private sseContext;
|
|
13
|
-
private cliArgs;
|
|
14
|
-
private workingDir;
|
|
15
|
-
private listenerPort;
|
|
16
|
-
private isStandalone;
|
|
17
|
-
constructor(options?: ServerOptions);
|
|
18
|
-
init: () => Promise<void>;
|
|
19
|
-
start: () => Promise<void>;
|
|
20
|
-
ready: () => Promise<void>;
|
|
21
|
-
close: () => Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CAqP5B;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"}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import fs, { readFile, readdir } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import fastifyStatic from "@fastify/static";
|
|
5
|
-
import chokidar from "chokidar";
|
|
6
|
-
import Fastify from "fastify";
|
|
7
|
-
import { FastifySSEPlugin } from "fastify-sse-v2";
|
|
8
|
-
import { captureEvent, shutdownAnalytics } from "../../common/analytics/lib.js";
|
|
9
|
-
import { logger } from "../../common/logger.js";
|
|
10
|
-
import { printDiagnosticsToConsole } from "../../common/output.js";
|
|
11
|
-
import { corsPlugin } from "./cors-plugin.js";
|
|
12
|
-
import { dirExists, fileExists } from "./xfs.js";
|
|
13
|
-
const POLICIES_FILENAME = "policies.json";
|
|
14
|
-
const CONFIG_DIR = "config";
|
|
15
|
-
export class ApiServer {
|
|
16
|
-
fastify;
|
|
17
|
-
listenerHost;
|
|
18
|
-
watcher;
|
|
19
|
-
sseContext;
|
|
20
|
-
cliArgs;
|
|
21
|
-
workingDir;
|
|
22
|
-
listenerPort;
|
|
23
|
-
isStandalone;
|
|
24
|
-
constructor(options = {
|
|
25
|
-
cliArgs: {},
|
|
26
|
-
workingDir: ".",
|
|
27
|
-
port: 9100,
|
|
28
|
-
isStandalone: true,
|
|
29
|
-
}) {
|
|
30
|
-
this.cliArgs = options.cliArgs;
|
|
31
|
-
this.workingDir = options.workingDir;
|
|
32
|
-
this.listenerPort = options.port;
|
|
33
|
-
this.isStandalone = options.isStandalone;
|
|
34
|
-
this.listenerHost = "localhost";
|
|
35
|
-
this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));
|
|
36
|
-
this.fastify = Fastify({
|
|
37
|
-
logger: logger,
|
|
38
|
-
trustProxy: true,
|
|
39
|
-
disableRequestLogging: true,
|
|
40
|
-
bodyLimit: 104857600,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
init = async () => {
|
|
44
|
-
const cliArgs = this.cliArgs;
|
|
45
|
-
this.fastify.register(corsPlugin, { origin: true });
|
|
46
|
-
this.fastify.register(FastifySSEPlugin);
|
|
47
|
-
const editorRootPath = fileURLToPath(new URL("../", import.meta.url));
|
|
48
|
-
this.fastify.register(fastifyStatic, {
|
|
49
|
-
root: editorRootPath,
|
|
50
|
-
});
|
|
51
|
-
this.fastify.register((instance, _options, done) => {
|
|
52
|
-
instance.get("/", {
|
|
53
|
-
handler: async (_request, reply) => {
|
|
54
|
-
await captureEvent({ argv: cliArgs, event: "route-designer: /" });
|
|
55
|
-
let html = await readFile(path.join(editorRootPath, "index.html"), "utf-8");
|
|
56
|
-
html = html.replace("__SERVER_DATA__", JSON.stringify({
|
|
57
|
-
server_address: this.listenerHost,
|
|
58
|
-
server_port: this.listenerPort,
|
|
59
|
-
}));
|
|
60
|
-
reply.type("text/html").send(html);
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
instance.get("/open-api-content", {
|
|
64
|
-
handler: async (request, reply) => {
|
|
65
|
-
await captureEvent({
|
|
66
|
-
argv: cliArgs,
|
|
67
|
-
event: "route-designer: /open-api-content",
|
|
68
|
-
});
|
|
69
|
-
const { path: filePath } = request.query;
|
|
70
|
-
if (filePath === null || filePath === undefined) {
|
|
71
|
-
return reply.code(404).send("You must select a file to work with");
|
|
72
|
-
}
|
|
73
|
-
const openApiFilePath = path.join(this.workingDir, "config", filePath);
|
|
74
|
-
if (!(await fileExists(openApiFilePath))) {
|
|
75
|
-
return reply
|
|
76
|
-
.code(404)
|
|
77
|
-
.send({ message: `Cannot find file named '${filePath}'` });
|
|
78
|
-
}
|
|
79
|
-
const policiesPath = path.join(this.workingDir, "config", POLICIES_FILENAME);
|
|
80
|
-
if (!(await fileExists(policiesPath))) {
|
|
81
|
-
return reply.code(404).send({
|
|
82
|
-
message: `Cannot find a '${POLICIES_FILENAME}' file in the '${CONFIG_DIR}'`,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
const openApiFileContent = await fs.readFile(openApiFilePath, "utf-8");
|
|
86
|
-
const policiesContent = await fs.readFile(policiesPath, "utf-8");
|
|
87
|
-
const payload = [
|
|
88
|
-
{
|
|
89
|
-
path: filePath,
|
|
90
|
-
content: JSON.parse(openApiFileContent),
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
path: POLICIES_FILENAME,
|
|
94
|
-
content: JSON.parse(policiesContent),
|
|
95
|
-
},
|
|
96
|
-
];
|
|
97
|
-
reply.code(200).send(payload);
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
instance.get("/open-api-files", {
|
|
101
|
-
handler: async (request, reply) => {
|
|
102
|
-
await captureEvent({
|
|
103
|
-
argv: cliArgs,
|
|
104
|
-
event: "route-designer: /open-api-files",
|
|
105
|
-
});
|
|
106
|
-
const projectConfigPath = path.join(this.workingDir, CONFIG_DIR);
|
|
107
|
-
if (!(await dirExists(projectConfigPath))) {
|
|
108
|
-
request.log.warn(`Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`);
|
|
109
|
-
return reply.code(404).send({
|
|
110
|
-
message: `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
const files = await readdir(projectConfigPath);
|
|
114
|
-
const openApiFiles = files.filter((fileName) => fileName.endsWith(".oas.json"));
|
|
115
|
-
reply.code(200).send(openApiFiles);
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
instance.route({
|
|
119
|
-
method: "POST",
|
|
120
|
-
url: "/save-open-api-updates",
|
|
121
|
-
handler: async (request, reply) => {
|
|
122
|
-
await captureEvent({
|
|
123
|
-
argv: cliArgs,
|
|
124
|
-
event: "route-designer: /save-open-api-updates",
|
|
125
|
-
});
|
|
126
|
-
const bodyContent = request.body;
|
|
127
|
-
for (const fileData of bodyContent) {
|
|
128
|
-
const openApiFilePath = path.join(this.workingDir, "config", fileData.filePath);
|
|
129
|
-
if (!(await fileExists(openApiFilePath))) {
|
|
130
|
-
reply.code(404).send({
|
|
131
|
-
message: `Cannot find file named '${fileData.filePath}'`,
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
await fs.writeFile(openApiFilePath, JSON.stringify(fileData.content, null, 2));
|
|
136
|
-
}
|
|
137
|
-
reply.code(200).send({ message: "Changes were saved successfully" });
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
instance.get("/updates", {
|
|
141
|
-
handler: async (request, reply) => {
|
|
142
|
-
await captureEvent({
|
|
143
|
-
argv: cliArgs,
|
|
144
|
-
event: "route-designer: /updates",
|
|
145
|
-
});
|
|
146
|
-
if (this.watcher && this.watcher.closed === true) {
|
|
147
|
-
this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));
|
|
148
|
-
}
|
|
149
|
-
this.watcher.on("change", (filePath) => {
|
|
150
|
-
const eventData = JSON.stringify({ type: "update", filePath });
|
|
151
|
-
reply.sse({ id: Date.now().toString(), data: eventData });
|
|
152
|
-
});
|
|
153
|
-
request.raw.on("close", async () => {
|
|
154
|
-
await this.watcher.close();
|
|
155
|
-
});
|
|
156
|
-
reply.sse({
|
|
157
|
-
id: Date.now().toString(),
|
|
158
|
-
data: JSON.stringify({ filePath: POLICIES_FILENAME, type: "init" }),
|
|
159
|
-
retry: 10,
|
|
160
|
-
});
|
|
161
|
-
this.sseContext = reply.sseContext;
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
instance.get("/modules-data", {
|
|
165
|
-
handler: async (request, reply) => {
|
|
166
|
-
await captureEvent({
|
|
167
|
-
argv: cliArgs,
|
|
168
|
-
event: "route-designer: /modules-data",
|
|
169
|
-
});
|
|
170
|
-
const projectModulesPath = path.join(this.workingDir, "modules");
|
|
171
|
-
if (!(await dirExists(projectModulesPath))) {
|
|
172
|
-
request.log.warn(`Cannot find the project 'modules' folder. Make sure '${this.workingDir}' has a 'modules' folder.`);
|
|
173
|
-
return reply.code(200).send([]);
|
|
174
|
-
}
|
|
175
|
-
const files = await readdir(projectModulesPath);
|
|
176
|
-
const modulesFiles = files.filter((fileName) => fileName.endsWith(".ts"));
|
|
177
|
-
const results = [];
|
|
178
|
-
for (const moduleFileName of modulesFiles) {
|
|
179
|
-
const fullPath = path.join(projectModulesPath, moduleFileName);
|
|
180
|
-
const fileContent = await fs.readFile(fullPath, "utf-8");
|
|
181
|
-
const exports = [];
|
|
182
|
-
const defaultExportRegex = /(?:export\s+(default))/g;
|
|
183
|
-
if (defaultExportRegex.exec(fileContent)) {
|
|
184
|
-
exports.push({ name: "default", isHandlerInvocable: true });
|
|
185
|
-
}
|
|
186
|
-
const functionRegex = /(?:export\s+(function|class))\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;
|
|
187
|
-
let match;
|
|
188
|
-
while ((match = functionRegex.exec(fileContent))) {
|
|
189
|
-
exports.push({ name: match[2], isHandlerInvocable: true });
|
|
190
|
-
}
|
|
191
|
-
results.push({
|
|
192
|
-
name: moduleFileName,
|
|
193
|
-
filepath: `./modules/${moduleFileName}`,
|
|
194
|
-
methods: exports,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
reply.code(200).send(results);
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
instance.get("/ping", {
|
|
201
|
-
handler: async (_request, reply) => {
|
|
202
|
-
reply.code(200).send();
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
done();
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
start = async () => {
|
|
209
|
-
await this.init();
|
|
210
|
-
this.fastify.log.level = "silent";
|
|
211
|
-
const start = async () => {
|
|
212
|
-
return new Promise((resolve, reject) => {
|
|
213
|
-
this.fastify.listen({ port: this.listenerPort, host: this.listenerHost }, (err) => {
|
|
214
|
-
if (err) {
|
|
215
|
-
reject(err);
|
|
216
|
-
}
|
|
217
|
-
this.fastify.log.level = "info";
|
|
218
|
-
if (this.isStandalone) {
|
|
219
|
-
printDiagnosticsToConsole("Started route designer");
|
|
220
|
-
printDiagnosticsToConsole("Ctrl+C to exit");
|
|
221
|
-
printDiagnosticsToConsole("");
|
|
222
|
-
printDiagnosticsToConsole(`📘 Route Designer: http://${this.listenerHost}:${this.listenerPort}`);
|
|
223
|
-
printDiagnosticsToConsole("");
|
|
224
|
-
printDiagnosticsToConsole("");
|
|
225
|
-
}
|
|
226
|
-
resolve();
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
await start();
|
|
231
|
-
};
|
|
232
|
-
ready = async () => {
|
|
233
|
-
return this.fastify.ready();
|
|
234
|
-
};
|
|
235
|
-
close = async () => {
|
|
236
|
-
if (this.isStandalone) {
|
|
237
|
-
printDiagnosticsToConsole("Closing route designer");
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
void shutdownAnalytics();
|
|
241
|
-
if (this.sseContext) {
|
|
242
|
-
this.sseContext.source.end();
|
|
243
|
-
}
|
|
244
|
-
if (this.watcher) {
|
|
245
|
-
await this.watcher.close();
|
|
246
|
-
}
|
|
247
|
-
await this.fastify.close();
|
|
248
|
-
}
|
|
249
|
-
catch (err) {
|
|
250
|
-
console.log(err);
|
|
251
|
-
}
|
|
252
|
-
process.exit();
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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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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 // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\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 // biome-ignore lint/style/useNamingConvention: External API property\n server_address: this.listenerHost,\n // biome-ignore lint/style/useNamingConvention: External API property\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 // biome-ignore lint/style/useNamingConvention: API field\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 // @ts-expect-error\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 // biome-ignore lint/suspicious/noAssignInExpressions: Migrated from ESLint\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 // biome-ignore lint/suspicious/noConsole: Uesr output\n console.log(err);\n }\n process.exit();\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xfs.d.ts","sourceRoot":"","sources":["../../../src/editor/server/xfs.ts"],"names":[],"mappings":"AAEA,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOjE;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOhE"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
export async function fileExists(fsPath) {
|
|
3
|
-
try {
|
|
4
|
-
const stat = await fs.stat(fsPath);
|
|
5
|
-
return stat.isFile();
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export async function dirExists(fsPath) {
|
|
12
|
-
try {
|
|
13
|
-
const stat = await fs.stat(fsPath);
|
|
14
|
-
return stat.isDirectory();
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=xfs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xfs.js","sourceRoot":"","sources":["../../../src/editor/server/xfs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc;IAC7C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc;IAC5C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import fs from \"node:fs/promises\";\n\nexport async function fileExists(fsPath: string): Promise<boolean> {\n try {\n const stat = await fs.stat(fsPath);\n return stat.isFile();\n } catch {\n return false;\n }\n}\n\nexport async function dirExists(fsPath: string): Promise<boolean> {\n try {\n const stat = await fs.stat(fsPath);\n return stat.isDirectory();\n } catch {\n return false;\n }\n}\n"]}
|