@yinuo-ngm/server 1.0.20 → 1.0.21
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/lib/app.js +0 -4
- package/lib/env.js +5 -1
- package/lib/plugins/success-handle.plugin.js +1 -1
- package/lib/plugins/ws/topics/nginx.ws.js +1 -1
- package/lib/plugins/ws/ws.context.js +3 -1
- package/lib/plugins/ws/ws.plugin.js +14 -2
- package/lib/routes/api-client/collection.routes.js +35 -35
- package/lib/routes/api-client/env.routes.js +12 -8
- package/lib/routes/api-client/history.routes.js +10 -5
- package/lib/routes/api-client/request.routes.js +14 -8
- package/lib/routes/api-client/route-mappers.d.ts +7 -0
- package/lib/routes/api-client/route-mappers.js +78 -0
- package/lib/routes/api-client/send.routes.js +12 -8
- package/lib/routes/config.routes.js +73 -49
- package/lib/routes/deps.route.js +47 -5
- package/lib/routes/nginx/nginx-config.routes.js +3 -3
- package/lib/routes/nginx/nginx-lifecycle.routes.js +14 -13
- package/lib/routes/nginx/nginx-module.routes.js +6 -6
- package/lib/routes/nginx/nginx-route.context.d.ts +16 -1
- package/lib/routes/nginx/nginx-route.context.js +136 -1
- package/lib/routes/nginx/nginx-server.routes.js +5 -5
- package/lib/routes/project.routes.js +90 -13
- package/lib/routes/sprite-browse.routes.js +17 -11
- package/lib/routes/sprite.routes.d.ts +1 -1
- package/lib/routes/sprite.routes.js +68 -11
- package/lib/routes/svn.routes.js +48 -14
- package/lib/routes/task.routes.js +99 -7
- package/package.json +7 -7
- package/www/3rdpartylicenses.txt +5 -5
- package/www/browser/{chunk-OZCK4XVV.js → chunk-2VJVGBXG.js} +1 -1
- package/www/browser/{chunk-FL6GDGHW.js → chunk-3ODVU46S.js} +1 -1
- package/www/browser/chunk-442QFABJ.js +1 -0
- package/www/browser/{chunk-WD2EKZQC.js → chunk-6J6G7JEP.js} +1 -1
- package/www/browser/{chunk-7U44RF5F.js → chunk-6UFDNETG.js} +1 -1
- package/www/browser/{chunk-75W3GVSO.js → chunk-7AKVG375.js} +1 -1
- package/www/browser/chunk-7GLWEFTM.js +1 -0
- package/www/browser/{chunk-DIJPUYIA.js → chunk-7QR6RHLA.js} +1 -1
- package/www/browser/{chunk-HJTXXSMC.js → chunk-CO3CQHKV.js} +1 -1
- package/www/browser/{chunk-3XNNQFWR.js → chunk-CPJTSA6E.js} +1 -1
- package/www/browser/chunk-DENFXXOY.js +1 -0
- package/www/browser/{chunk-HDNG236Q.js → chunk-HC5KLPHD.js} +1 -1
- package/www/browser/chunk-HJAP6WBI.js +1 -0
- package/www/browser/{chunk-N2PELLMM.js → chunk-JM6DCZP6.js} +7 -7
- package/www/browser/chunk-K6C5ZIV2.js +20 -0
- package/www/browser/chunk-M6NZ6C2R.js +2 -0
- package/www/browser/{chunk-RGOYDY7H.js → chunk-MBPB43C6.js} +1 -1
- package/www/browser/chunk-MPLGMTLT.js +3 -0
- package/www/browser/chunk-NNOWADVM.js +1 -0
- package/www/browser/{chunk-M4QRBV3K.js → chunk-NREWZQVN.js} +1 -1
- package/www/browser/{chunk-6YYNHZ2A.js → chunk-OUGN4APK.js} +1 -1
- package/www/browser/chunk-PB2LGZNW.js +1 -0
- package/www/browser/chunk-PDI3HSSH.js +4 -0
- package/www/browser/chunk-PUG3VNTI.js +3 -0
- package/www/browser/{chunk-QJP5F735.js → chunk-PY3AUTHC.js} +1 -1
- package/www/browser/{chunk-3M56F2S2.js → chunk-R4HSZU2J.js} +1 -1
- package/www/browser/{chunk-DE6E23ET.js → chunk-RKK4I2RT.js} +1 -1
- package/www/browser/chunk-RMIYLAEM.js +1 -0
- package/www/browser/chunk-RZA3IFQV.js +2 -0
- package/www/browser/{chunk-K7PESFPY.js → chunk-SD2HFD54.js} +1 -1
- package/www/browser/{chunk-BTQIUVTQ.js → chunk-SEJGGBE2.js} +1 -1
- package/www/browser/chunk-SSCUT2GF.js +1 -0
- package/www/browser/chunk-TCBOC5FF.js +1 -0
- package/www/browser/{chunk-AZ6SIMYH.js → chunk-TS5ZQYYY.js} +1 -1
- package/www/browser/chunk-TVJHI463.js +1 -0
- package/www/browser/{chunk-YNW4HEJO.js → chunk-TXAXE73U.js} +17 -17
- package/www/browser/{chunk-4X42HB6N.js → chunk-U2YWR3HF.js} +1 -1
- package/www/browser/{chunk-D2ODDESN.js → chunk-U3EUR236.js} +1 -1
- package/www/browser/chunk-UKCMUTYL.js +1 -0
- package/www/browser/{chunk-DLGJD6YU.js → chunk-UPOORT3S.js} +1 -1
- package/www/browser/chunk-VW3S7C2Z.js +1 -0
- package/www/browser/chunk-VZYJ3MSW.js +15 -0
- package/www/browser/{chunk-AELTP6YN.js → chunk-WCHN62X6.js} +1 -1
- package/www/browser/chunk-WWIPELAV.js +1 -0
- package/www/browser/{chunk-B3C35ET3.js → chunk-WYNERG74.js} +1 -1
- package/www/browser/{chunk-ZTDLWBW5.js → chunk-XJDJL3TQ.js} +1 -1
- package/www/browser/{chunk-EEDA5U4V.js → chunk-YV6QPLF5.js} +1 -1
- package/www/browser/{chunk-ONXBYGIG.js → chunk-YVRGRFK2.js} +1 -1
- package/www/browser/index.html +1 -1
- package/www/browser/main-7GYUOEJY.js +38 -0
- package/lib/plugins/api-client.plugin.d.ts +0 -3
- package/lib/plugins/api-client.plugin.js +0 -55
- package/lib/plugins/nginx.binding.store.d.ts +0 -4
- package/lib/plugins/nginx.binding.store.js +0 -39
- package/lib/plugins/nginx.plugin.d.ts +0 -3
- package/lib/plugins/nginx.plugin.js +0 -23
- package/www/browser/chunk-2L7NUOMX.js +0 -2
- package/www/browser/chunk-2NZJ7CN2.js +0 -20
- package/www/browser/chunk-3CM4SKDO.js +0 -15
- package/www/browser/chunk-3OHBKMAA.js +0 -1
- package/www/browser/chunk-4LBSLURA.js +0 -1
- package/www/browser/chunk-5DYX4DUX.js +0 -11
- package/www/browser/chunk-6SYVDN5L.js +0 -1
- package/www/browser/chunk-AMXRL4GR.js +0 -1
- package/www/browser/chunk-AV2ZODEH.js +0 -1
- package/www/browser/chunk-CN5J4WNO.js +0 -1
- package/www/browser/chunk-FK6Z4HLL.js +0 -1
- package/www/browser/chunk-FXCG34QS.js +0 -1
- package/www/browser/chunk-H5HGMOE6.js +0 -1
- package/www/browser/chunk-HB3HECPD.js +0 -1
- package/www/browser/chunk-HUMCWAKJ.js +0 -3
- package/www/browser/chunk-IKB3EQCP.js +0 -2
- package/www/browser/chunk-OSBDR36P.js +0 -1
- package/www/browser/chunk-XLFHB7RS.js +0 -3
- package/www/browser/main-N64WJCHX.js +0 -34
package/lib/app.js
CHANGED
|
@@ -12,8 +12,6 @@ const routes_plugin_1 = __importDefault(require("./plugins/routes.plugin"));
|
|
|
12
12
|
const static_plugin_1 = __importDefault(require("./plugins/static.plugin"));
|
|
13
13
|
const success_handle_plugin_1 = __importDefault(require("./plugins/success-handle.plugin"));
|
|
14
14
|
const ws_plugin_1 = __importDefault(require("./plugins/ws/ws.plugin"));
|
|
15
|
-
const api_client_plugin_1 = __importDefault(require("./plugins/api-client.plugin"));
|
|
16
|
-
const nginx_plugin_1 = __importDefault(require("./plugins/nginx.plugin"));
|
|
17
15
|
const env_1 = require("./env");
|
|
18
16
|
function normalizeLogLevel(v) {
|
|
19
17
|
const lv = (v ?? "").toLowerCase().trim();
|
|
@@ -46,9 +44,7 @@ async function createServer() {
|
|
|
46
44
|
await fastify.register(error_handler_plugin_1.errorHandlerPlugin);
|
|
47
45
|
await fastify.register(success_handle_plugin_1.default);
|
|
48
46
|
await fastify.register(core_plugin_1.default);
|
|
49
|
-
await fastify.register(nginx_plugin_1.default);
|
|
50
47
|
await fastify.register(ws_plugin_1.default);
|
|
51
|
-
await fastify.register(api_client_plugin_1.default);
|
|
52
48
|
await fastify.register(routes_plugin_1.default);
|
|
53
49
|
await fastify.register(static_plugin_1.default);
|
|
54
50
|
fastify.addHook('onClose', async () => {
|
package/lib/env.js
CHANGED
|
@@ -6,8 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.env = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const isDevMode = process.env.NODE_ENV === "development" ||
|
|
10
|
+
process.env.npm_lifecycle_event === "dev" ||
|
|
11
|
+
process.env.npm_lifecycle_event === "dev:server";
|
|
12
|
+
const defaultPort = isDevMode ? 3211 : 3210;
|
|
9
13
|
exports.env = {
|
|
10
|
-
port: Number(process.env.NGM_SERVER_PORT ||
|
|
14
|
+
port: Number(process.env.NGM_SERVER_PORT || defaultPort),
|
|
11
15
|
host: process.env.NGM_SERVER_HOST || "127.0.0.1",
|
|
12
16
|
dataDir: process.env.NGM_DATA_DIR ||
|
|
13
17
|
path_1.default.join(os_1.default.homedir(), ".ng-manager"),
|
|
@@ -10,7 +10,7 @@ exports.successHandlerPlugin = (0, fastify_plugin_1.default)(async (app) => {
|
|
|
10
10
|
if (reply.statusCode < 200 || reply.statusCode >= 300) {
|
|
11
11
|
return payload;
|
|
12
12
|
}
|
|
13
|
-
if (payload === undefined
|
|
13
|
+
if (payload === undefined) {
|
|
14
14
|
return payload;
|
|
15
15
|
}
|
|
16
16
|
const type = reply.getHeader("content-type");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WsContext = void 0;
|
|
4
|
+
const protocol_1 = require("@yinuo-ngm/protocol");
|
|
4
5
|
class WsContext {
|
|
5
6
|
constructor(connId, socket) {
|
|
6
7
|
this.socket = socket;
|
|
@@ -10,7 +11,8 @@ class WsContext {
|
|
|
10
11
|
send(msg) {
|
|
11
12
|
if (this.socket.readyState !== this.socket.OPEN)
|
|
12
13
|
return;
|
|
13
|
-
|
|
14
|
+
const payload = msg.version ? msg : { ...msg, version: protocol_1.PROTOCOL_VERSION };
|
|
15
|
+
this.socket.send(JSON.stringify(payload));
|
|
14
16
|
}
|
|
15
17
|
addSub(topic, key) {
|
|
16
18
|
const set = this.subs.get(topic) ?? new Set();
|
|
@@ -29,7 +29,7 @@ exports.default = (0, fastify_plugin_1.default)(async function wsPlugin(fastify)
|
|
|
29
29
|
getSvnRuntimeByProjectId: (projectId, tail) => fastify.core.svnSync.getRuntimeByProjectId(projectId, tail),
|
|
30
30
|
}, () => clients.values());
|
|
31
31
|
router.register(svnSyncHandler);
|
|
32
|
-
const nginxHandler = (0, topics_1.createNginxTopicHandler)({ logService: fastify.nginx
|
|
32
|
+
const nginxHandler = (0, topics_1.createNginxTopicHandler)({ logService: fastify.core.nginx?.log }, () => clients.values());
|
|
33
33
|
router.register(nginxHandler);
|
|
34
34
|
const offs = [];
|
|
35
35
|
const events = fastify.core.events;
|
|
@@ -48,6 +48,18 @@ exports.default = (0, fastify_plugin_1.default)(async function wsPlugin(fastify)
|
|
|
48
48
|
offs.push(events.on(core_1.Events.TASK_FAILED, (e) => {
|
|
49
49
|
taskHandler.pushEvent("failed", e);
|
|
50
50
|
}));
|
|
51
|
+
offs.push(events.on(core_1.Events.TASK_ANALYZE_STARTED, (e) => {
|
|
52
|
+
taskHandler.pushEvent("analyzeStarted", e);
|
|
53
|
+
}));
|
|
54
|
+
offs.push(events.on(core_1.Events.TASK_ANALYZE_FINISHED, (e) => {
|
|
55
|
+
taskHandler.pushEvent("analyzeFinished", e);
|
|
56
|
+
}));
|
|
57
|
+
offs.push(events.on(core_1.Events.TASK_ANALYZE_FAILED, (e) => {
|
|
58
|
+
taskHandler.pushEvent("analyzeFailed", e);
|
|
59
|
+
}));
|
|
60
|
+
offs.push(events.on(core_1.Events.TASK_RUNTIME_UPDATED, (e) => {
|
|
61
|
+
taskHandler.pushEvent("snapshot", e);
|
|
62
|
+
}));
|
|
51
63
|
offs.push(events.on(core_1.Events.SYSLOG_APPENDED, (e) => {
|
|
52
64
|
syslogHandler.push(e.entry);
|
|
53
65
|
}));
|
|
@@ -79,7 +91,7 @@ exports.default = (0, fastify_plugin_1.default)(async function wsPlugin(fastify)
|
|
|
79
91
|
}
|
|
80
92
|
catch { }
|
|
81
93
|
});
|
|
82
|
-
fastify.nginx.log.stopAll();
|
|
94
|
+
fastify.core.nginx.log.stopAll();
|
|
83
95
|
clients.clear();
|
|
84
96
|
});
|
|
85
97
|
fastify.get("/ws", { websocket: true }, (ws) => {
|
|
@@ -3,36 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.apiClientCollectionsRoutes = apiClientCollectionsRoutes;
|
|
4
4
|
const api_1 = require("@yinuo-ngm/api");
|
|
5
5
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
6
|
-
const
|
|
6
|
+
const route_mappers_1 = require("./route-mappers");
|
|
7
7
|
function assertProjectScope(scope, projectId) {
|
|
8
|
-
if (scope === "project" && !projectId)
|
|
9
|
-
throw new
|
|
8
|
+
if (scope === "project" && !projectId) {
|
|
9
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
10
|
+
}
|
|
10
11
|
}
|
|
11
12
|
function now() { return Date.now(); }
|
|
12
13
|
async function apiClientCollectionsRoutes(fastify) {
|
|
13
|
-
const api = fastify.
|
|
14
|
+
const api = fastify.core.apiClient;
|
|
14
15
|
fastify.get("/", async (req) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const scope = (req.query?.scope ?? "project");
|
|
17
|
+
assertProjectScope(scope, req.query?.projectId);
|
|
18
|
+
const collections = await api.listCollections(scope, req.query?.projectId);
|
|
19
|
+
return collections.sort((a, b) => (a.parentId ?? "").localeCompare(b.parentId ?? "") ||
|
|
20
|
+
a.order - b.order ||
|
|
21
|
+
a.name.localeCompare(b.name)).map(route_mappers_1.toApiCollectionEntityDto);
|
|
20
22
|
});
|
|
21
23
|
fastify.get("/bundle", async (req) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
assertProjectScope(scope, q.projectId);
|
|
24
|
+
const scope = (req.query?.scope ?? "project");
|
|
25
|
+
assertProjectScope(scope, req.query?.projectId);
|
|
25
26
|
const [collections, requests] = await Promise.all([
|
|
26
|
-
api.listCollections(scope,
|
|
27
|
-
api.listRequests(scope,
|
|
27
|
+
api.listCollections(scope, req.query?.projectId),
|
|
28
|
+
api.listRequests(scope, req.query?.projectId),
|
|
28
29
|
]);
|
|
29
|
-
const cols =
|
|
30
|
+
const cols = collections.sort((a, b) => (a.parentId ?? "").localeCompare(b.parentId ?? "") ||
|
|
30
31
|
a.order - b.order ||
|
|
31
|
-
(a.name ?? "").localeCompare(b.name ?? ""));
|
|
32
|
-
const reqs =
|
|
32
|
+
(a.name ?? "").localeCompare(b.name ?? "")).map(route_mappers_1.toApiCollectionEntityDto);
|
|
33
|
+
const reqs = requests.sort((a, b) => (a.collectionId ?? "").localeCompare(b.collectionId ?? "") ||
|
|
33
34
|
(a.order ?? 0) - (b.order ?? 0) ||
|
|
34
|
-
(a.name ?? "").localeCompare(b.name ?? ""));
|
|
35
|
-
|
|
35
|
+
(a.name ?? "").localeCompare(b.name ?? "")).map(route_mappers_1.toApiRequestEntityDto);
|
|
36
|
+
const response = { collections: cols, requests: reqs };
|
|
37
|
+
return response;
|
|
36
38
|
});
|
|
37
39
|
fastify.post("/", async (req) => {
|
|
38
40
|
const body = req.body;
|
|
@@ -52,17 +54,16 @@ async function apiClientCollectionsRoutes(fastify) {
|
|
|
52
54
|
updatedAt: ts,
|
|
53
55
|
};
|
|
54
56
|
await api.saveCollection(entity, scope, body.projectId);
|
|
55
|
-
return entity;
|
|
57
|
+
return (0, route_mappers_1.toApiCollectionEntityDto)(entity);
|
|
56
58
|
});
|
|
57
59
|
fastify.post("/:id", async (req) => {
|
|
58
|
-
const params = req.params;
|
|
59
60
|
const q = req.query;
|
|
60
61
|
const body = req.body;
|
|
61
|
-
const scope = (q
|
|
62
|
-
assertProjectScope(scope, q
|
|
63
|
-
const old = await api.getCollection(params.id, scope, q
|
|
62
|
+
const scope = (q?.scope ?? "project");
|
|
63
|
+
assertProjectScope(scope, q?.projectId);
|
|
64
|
+
const old = await api.getCollection(req.params.id, scope, q?.projectId);
|
|
64
65
|
if (!old) {
|
|
65
|
-
throw new errors_1.ApiError(errors_1.ApiErrorCodes.API_COLLECTION_NOT_FOUND, `collection not found: ${params.id}`);
|
|
66
|
+
throw new errors_1.ApiError(errors_1.ApiErrorCodes.API_COLLECTION_NOT_FOUND, `collection not found: ${req.params.id}`);
|
|
66
67
|
}
|
|
67
68
|
const ts = now();
|
|
68
69
|
const next = {
|
|
@@ -72,25 +73,24 @@ async function apiClientCollectionsRoutes(fastify) {
|
|
|
72
73
|
order: body.order !== undefined ? Number(body.order) : old.order,
|
|
73
74
|
updatedAt: ts,
|
|
74
75
|
};
|
|
75
|
-
await api.saveCollection(next, scope, q
|
|
76
|
-
return next;
|
|
76
|
+
await api.saveCollection(next, scope, q?.projectId);
|
|
77
|
+
return (0, route_mappers_1.toApiCollectionEntityDto)(next);
|
|
77
78
|
});
|
|
78
79
|
fastify.delete("/:id", async (req) => {
|
|
79
|
-
const params = req.params;
|
|
80
80
|
const q = req.query;
|
|
81
|
-
const scope = (q
|
|
82
|
-
assertProjectScope(scope, q
|
|
83
|
-
const allCols = await api.listCollections(scope, q
|
|
84
|
-
const hasChildCol = allCols.some(c => (c.parentId ?? null) === params.id);
|
|
81
|
+
const scope = (q?.scope ?? "project");
|
|
82
|
+
assertProjectScope(scope, q?.projectId);
|
|
83
|
+
const allCols = await api.listCollections(scope, q?.projectId);
|
|
84
|
+
const hasChildCol = allCols.some(c => (c.parentId ?? null) === req.params.id);
|
|
85
85
|
if (hasChildCol) {
|
|
86
86
|
throw new errors_1.ApiError(errors_1.ApiErrorCodes.API_COLLECTION_NOT_EMPTY, "collection has child collections");
|
|
87
87
|
}
|
|
88
|
-
const reqs = await api.listRequests(scope, q
|
|
89
|
-
const hasReq = reqs.some(
|
|
88
|
+
const reqs = await api.listRequests(scope, q?.projectId);
|
|
89
|
+
const hasReq = reqs.some(r => (r.collectionId ?? null) === req.params.id);
|
|
90
90
|
if (hasReq) {
|
|
91
91
|
throw new errors_1.ApiError(errors_1.ApiErrorCodes.API_COLLECTION_NOT_EMPTY, "collection has requests");
|
|
92
92
|
}
|
|
93
|
-
await api.deleteCollection(params.id, scope, q
|
|
93
|
+
await api.deleteCollection(req.params.id, scope, q?.projectId);
|
|
94
94
|
return { ok: true };
|
|
95
95
|
});
|
|
96
96
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientEnvsRoutes = apiClientEnvsRoutes;
|
|
4
4
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
const route_mappers_1 = require("./route-mappers");
|
|
5
6
|
function parseScope(q) {
|
|
6
7
|
const scope = (q?.scope ?? "project");
|
|
7
8
|
const projectId = q?.projectId;
|
|
@@ -11,35 +12,38 @@ function parseScope(q) {
|
|
|
11
12
|
return { scope, projectId };
|
|
12
13
|
}
|
|
13
14
|
async function apiClientEnvsRoutes(fastify) {
|
|
14
|
-
const
|
|
15
|
+
const api = fastify.core.apiClient;
|
|
15
16
|
fastify.get("/", async (req) => {
|
|
16
17
|
const { scope, projectId } = parseScope(req.query);
|
|
17
|
-
|
|
18
|
+
const items = await api.listEnvs(scope, projectId);
|
|
19
|
+
return items.map(route_mappers_1.toApiEnvironmentEntityDto);
|
|
18
20
|
});
|
|
19
21
|
fastify.get("/:id", async (req, reply) => {
|
|
20
22
|
const { scope, projectId } = parseScope(req.query);
|
|
21
23
|
const id = req.params.id;
|
|
22
|
-
const item = await
|
|
24
|
+
const item = await api.getEnv(id, scope, projectId);
|
|
23
25
|
if (!item) {
|
|
24
26
|
reply.code(404);
|
|
25
27
|
return { message: "env not found", id };
|
|
26
28
|
}
|
|
27
|
-
return item;
|
|
29
|
+
return (0, route_mappers_1.toApiEnvironmentEntityDto)(item);
|
|
28
30
|
});
|
|
29
31
|
fastify.post("/", async (req) => {
|
|
30
32
|
const body = req.body;
|
|
31
33
|
const scope = body?.scope ?? "project";
|
|
32
|
-
if (scope === "project" && !body.projectId)
|
|
34
|
+
if (scope === "project" && !body.projectId) {
|
|
33
35
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
34
|
-
|
|
36
|
+
}
|
|
37
|
+
if (!body?.env?.id) {
|
|
35
38
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "env.id is required");
|
|
36
|
-
|
|
39
|
+
}
|
|
40
|
+
await api.saveEnv(body.env, scope, body.projectId);
|
|
37
41
|
return { id: body.env.id };
|
|
38
42
|
});
|
|
39
43
|
fastify.delete("/:id", async (req) => {
|
|
40
44
|
const { scope, projectId } = parseScope(req.query);
|
|
41
45
|
const id = req.params.id;
|
|
42
|
-
await
|
|
46
|
+
await api.deleteEnv(id, scope, projectId);
|
|
43
47
|
return { id };
|
|
44
48
|
});
|
|
45
49
|
}
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientHistoryRoutes = apiClientHistoryRoutes;
|
|
4
4
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
const route_mappers_1 = require("./route-mappers");
|
|
5
6
|
function parseScope(q) {
|
|
6
7
|
const scope = (q?.scope ?? "project");
|
|
7
8
|
const projectId = q?.projectId;
|
|
8
|
-
if (scope === "project" && !projectId)
|
|
9
|
+
if (scope === "project" && !projectId) {
|
|
9
10
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
11
|
+
}
|
|
10
12
|
return { scope, projectId };
|
|
11
13
|
}
|
|
12
14
|
function parseNum(v, fallback) {
|
|
@@ -14,24 +16,27 @@ function parseNum(v, fallback) {
|
|
|
14
16
|
return Number.isFinite(n) ? n : fallback;
|
|
15
17
|
}
|
|
16
18
|
async function apiClientHistoryRoutes(fastify) {
|
|
17
|
-
const api = fastify.
|
|
19
|
+
const api = fastify.core.apiClient;
|
|
18
20
|
fastify.get("/", async (req) => {
|
|
19
21
|
const { scope, projectId } = parseScope(req.query);
|
|
20
22
|
const limit = parseNum(req.query?.limit, 50);
|
|
21
23
|
const offset = parseNum(req.query?.offset, 0);
|
|
22
|
-
|
|
24
|
+
const items = await api.listHistory({ scope, projectId, limit, offset });
|
|
25
|
+
return items.map(route_mappers_1.toApiHistoryEntityDto);
|
|
23
26
|
});
|
|
24
27
|
fastify.post("/purge", async (req) => {
|
|
25
28
|
const body = req.body;
|
|
26
29
|
const scope = body?.scope ?? "project";
|
|
27
|
-
if (scope === "project" && !body.projectId)
|
|
30
|
+
if (scope === "project" && !body.projectId) {
|
|
28
31
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
32
|
+
}
|
|
29
33
|
const removed = await api.purgeHistory({
|
|
30
34
|
scope,
|
|
31
35
|
projectId: body.projectId,
|
|
32
36
|
olderThan: body.olderThan,
|
|
33
37
|
maxCount: body.maxCount,
|
|
34
38
|
});
|
|
35
|
-
|
|
39
|
+
const response = { removed };
|
|
40
|
+
return response;
|
|
36
41
|
});
|
|
37
42
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientRequestsRoutes = apiClientRequestsRoutes;
|
|
4
4
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
const route_mappers_1 = require("./route-mappers");
|
|
5
6
|
function parseScope(q) {
|
|
6
7
|
const scope = (q?.scope ?? "project");
|
|
7
8
|
const projectId = q?.projectId;
|
|
@@ -11,11 +12,11 @@ function parseScope(q) {
|
|
|
11
12
|
return { scope, projectId };
|
|
12
13
|
}
|
|
13
14
|
async function apiClientRequestsRoutes(fastify) {
|
|
14
|
-
const api = fastify.
|
|
15
|
+
const api = fastify.core.apiClient;
|
|
15
16
|
fastify.get("/", async (req) => {
|
|
16
17
|
const { scope, projectId } = parseScope(req.query);
|
|
17
18
|
const items = await api.listRequests(scope, projectId);
|
|
18
|
-
return items;
|
|
19
|
+
return items.map(route_mappers_1.toApiRequestEntityDto);
|
|
19
20
|
});
|
|
20
21
|
fastify.get("/:id", async (req, reply) => {
|
|
21
22
|
const { scope, projectId } = parseScope(req.query);
|
|
@@ -25,28 +26,33 @@ async function apiClientRequestsRoutes(fastify) {
|
|
|
25
26
|
reply.code(404);
|
|
26
27
|
return { message: "request not found", id };
|
|
27
28
|
}
|
|
28
|
-
return item;
|
|
29
|
+
return (0, route_mappers_1.toApiRequestEntityDto)(item);
|
|
29
30
|
});
|
|
30
31
|
fastify.post("/", async (req) => {
|
|
31
32
|
const body = req.body;
|
|
32
33
|
const scope = body?.scope ?? "project";
|
|
33
|
-
if (scope === "project" && !body.projectId)
|
|
34
|
+
if (scope === "project" && !body.projectId) {
|
|
34
35
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
35
|
-
|
|
36
|
+
}
|
|
37
|
+
if (!body?.request?.id) {
|
|
36
38
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request.id is required");
|
|
39
|
+
}
|
|
37
40
|
await api.saveRequest(body.request, scope, body.projectId);
|
|
38
41
|
return { id: body.request.id };
|
|
39
42
|
});
|
|
40
43
|
fastify.post("/update", async (req) => {
|
|
41
44
|
const body = req.body;
|
|
42
45
|
const scope = body?.scope ?? "project";
|
|
43
|
-
if (scope === "project" && !body.projectId)
|
|
46
|
+
if (scope === "project" && !body.projectId) {
|
|
44
47
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
45
|
-
|
|
48
|
+
}
|
|
49
|
+
if (!body?.request?.id) {
|
|
46
50
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request.id is required");
|
|
51
|
+
}
|
|
47
52
|
const old = await api.getRequest(body.request.id, scope, body.projectId);
|
|
48
|
-
if (!old)
|
|
53
|
+
if (!old) {
|
|
49
54
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.NOT_FOUND, "request not found: " + body.request.id);
|
|
55
|
+
}
|
|
50
56
|
const updated = {
|
|
51
57
|
...old,
|
|
52
58
|
...body.request,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiCollectionEntityDto, ApiEnvironmentEntityDto, ApiHistoryEntityDto, ApiRequestEntityDto, SendResultDto } from "@yinuo-ngm/protocol";
|
|
2
|
+
import type { ApiCollectionEntity, ApiEnvironmentEntity, ApiHistoryEntity, ApiRequestEntity, SendResult } from "@yinuo-ngm/api";
|
|
3
|
+
export declare function toApiRequestEntityDto(entity: ApiRequestEntity): ApiRequestEntityDto;
|
|
4
|
+
export declare function toApiEnvironmentEntityDto(entity: ApiEnvironmentEntity): ApiEnvironmentEntityDto;
|
|
5
|
+
export declare function toApiCollectionEntityDto(entity: ApiCollectionEntity): ApiCollectionEntityDto;
|
|
6
|
+
export declare function toApiHistoryEntityDto(entity: ApiHistoryEntity): ApiHistoryEntityDto;
|
|
7
|
+
export declare function toSendResultDto(result: SendResult): SendResultDto;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toApiRequestEntityDto = toApiRequestEntityDto;
|
|
4
|
+
exports.toApiEnvironmentEntityDto = toApiEnvironmentEntityDto;
|
|
5
|
+
exports.toApiCollectionEntityDto = toApiCollectionEntityDto;
|
|
6
|
+
exports.toApiHistoryEntityDto = toApiHistoryEntityDto;
|
|
7
|
+
exports.toSendResultDto = toSendResultDto;
|
|
8
|
+
function toApiRequestEntityDto(entity) {
|
|
9
|
+
return {
|
|
10
|
+
id: entity.id,
|
|
11
|
+
name: entity.name,
|
|
12
|
+
method: entity.method,
|
|
13
|
+
url: entity.url,
|
|
14
|
+
query: entity.query ?? [],
|
|
15
|
+
pathParams: entity.pathParams ?? [],
|
|
16
|
+
headers: entity.headers ?? [],
|
|
17
|
+
body: entity.body,
|
|
18
|
+
auth: entity.auth,
|
|
19
|
+
options: entity.options,
|
|
20
|
+
collectionId: entity.collectionId,
|
|
21
|
+
order: entity.order,
|
|
22
|
+
tags: entity.tags,
|
|
23
|
+
createdAt: entity.createdAt,
|
|
24
|
+
updatedAt: entity.updatedAt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function toApiEnvironmentEntityDto(entity) {
|
|
28
|
+
return {
|
|
29
|
+
id: entity.id,
|
|
30
|
+
name: entity.name,
|
|
31
|
+
scope: entity.scope,
|
|
32
|
+
projectId: entity.projectId,
|
|
33
|
+
baseUrl: entity.baseUrl,
|
|
34
|
+
variables: entity.variables ?? [],
|
|
35
|
+
createdAt: entity.createdAt,
|
|
36
|
+
updatedAt: entity.updatedAt,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function toApiCollectionEntityDto(entity) {
|
|
40
|
+
return {
|
|
41
|
+
id: entity.id,
|
|
42
|
+
name: entity.name,
|
|
43
|
+
kind: entity.kind,
|
|
44
|
+
scope: entity.scope,
|
|
45
|
+
projectId: entity.projectId,
|
|
46
|
+
nodes: entity.nodes ?? [],
|
|
47
|
+
parentId: entity.parentId,
|
|
48
|
+
order: entity.order,
|
|
49
|
+
createdAt: entity.createdAt,
|
|
50
|
+
updatedAt: entity.updatedAt,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function toApiHistoryEntityDto(entity) {
|
|
54
|
+
return {
|
|
55
|
+
id: entity.id,
|
|
56
|
+
projectId: entity.projectId,
|
|
57
|
+
collectionId: entity.collectionId,
|
|
58
|
+
requestSnapshot: toApiRequestEntityDto(entity.requestSnapshot),
|
|
59
|
+
resolved: {
|
|
60
|
+
url: entity.resolved.url,
|
|
61
|
+
headers: entity.resolved.headers,
|
|
62
|
+
},
|
|
63
|
+
response: entity.response,
|
|
64
|
+
error: entity.error,
|
|
65
|
+
metrics: entity.metrics,
|
|
66
|
+
createdAt: entity.createdAt,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function toSendResultDto(result) {
|
|
70
|
+
return {
|
|
71
|
+
historyId: result.historyId,
|
|
72
|
+
response: result.response,
|
|
73
|
+
error: result.error,
|
|
74
|
+
metrics: result.metrics,
|
|
75
|
+
curl: result.curl,
|
|
76
|
+
responseSetCookies: result.responseSetCookies,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -3,15 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.apiClientSendRoutes = apiClientSendRoutes;
|
|
4
4
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
5
|
const hub_cookie_jar_1 = require("./hub-cookie-jar");
|
|
6
|
+
const route_mappers_1 = require("./route-mappers");
|
|
6
7
|
async function apiClientSendRoutes(fastify) {
|
|
7
|
-
const api = fastify.
|
|
8
|
+
const api = fastify.core.apiClient;
|
|
8
9
|
fastify.post("/", async (req) => {
|
|
9
10
|
const body = req.body;
|
|
10
|
-
const scope = body.scope ?? "project";
|
|
11
|
-
if (scope === "project" && !body.projectId)
|
|
11
|
+
const scope = (body.scope ?? "project");
|
|
12
|
+
if (scope === "project" && !body.projectId) {
|
|
12
13
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
13
|
-
|
|
14
|
+
}
|
|
15
|
+
if (!body.request && !body.requestId) {
|
|
14
16
|
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request or requestId is required");
|
|
17
|
+
}
|
|
15
18
|
const useCookieJar = body.useCookieJar !== false;
|
|
16
19
|
const sessionKey = body.sessionKey ?? `${scope}:${body.projectId ?? "global"}:${body.envId ?? "default"}`;
|
|
17
20
|
if (body.clearCookieJar) {
|
|
@@ -39,7 +42,7 @@ async function apiClientSendRoutes(fastify) {
|
|
|
39
42
|
(0, hub_cookie_jar_1.mergeCookieJar)(sessionKey, setCookies);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
return result;
|
|
45
|
+
return (0, route_mappers_1.toSendResultDto)(result);
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
async function buildRequestWithCookie(api, params) {
|
|
@@ -51,10 +54,11 @@ async function buildRequestWithCookie(api, params) {
|
|
|
51
54
|
: undefined);
|
|
52
55
|
if (!requestEntity)
|
|
53
56
|
return params.request;
|
|
57
|
+
const entity = requestEntity;
|
|
54
58
|
const next = {
|
|
55
|
-
...
|
|
56
|
-
headers: Array.isArray(
|
|
57
|
-
auth:
|
|
59
|
+
...entity,
|
|
60
|
+
headers: Array.isArray(entity.headers) ? [...entity.headers] : [],
|
|
61
|
+
auth: entity.auth ? { ...entity.auth } : undefined,
|
|
58
62
|
};
|
|
59
63
|
if (next.auth?.type === "cookie" && next.auth?.cookie?.value) {
|
|
60
64
|
return next;
|