@lark-apaas/devtool-kits 1.2.17-alpha.23 → 1.2.17-alpha.25
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/index.cjs +11 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -9
- package/dist/index.d.ts +1 -9
- package/dist/index.js +11 -261
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
createApiRoutesMiddleware: () => createApiRoutesMiddleware,
|
|
35
34
|
createCollectLogsMiddleware: () => createCollectLogsMiddleware,
|
|
36
35
|
createDevLogsMiddleware: () => createDevLogsMiddleware,
|
|
37
36
|
createOpenapiMiddleware: () => createOpenapiMiddleware,
|
|
@@ -1652,7 +1651,7 @@ function createOpenapiRouter(options, context) {
|
|
|
1652
1651
|
const { openapiFilePath, enableEnhancement, serverDir } = options;
|
|
1653
1652
|
const router = import_express.default.Router();
|
|
1654
1653
|
const handler = createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir);
|
|
1655
|
-
router.get("/", (req, res) => handler(req, res, context));
|
|
1654
|
+
router.get("/openapi.json", (req, res) => handler(req, res, context));
|
|
1656
1655
|
return router;
|
|
1657
1656
|
}
|
|
1658
1657
|
__name(createOpenapiRouter, "createOpenapiRouter");
|
|
@@ -1661,7 +1660,7 @@ __name(createOpenapiRouter, "createOpenapiRouter");
|
|
|
1661
1660
|
var OPENAPI_ROUTES = [
|
|
1662
1661
|
{
|
|
1663
1662
|
method: "GET",
|
|
1664
|
-
path: "/",
|
|
1663
|
+
path: "/openapi.json",
|
|
1665
1664
|
description: "Serve enhanced OpenAPI specification with source code references"
|
|
1666
1665
|
}
|
|
1667
1666
|
];
|
|
@@ -1669,7 +1668,7 @@ function createOpenapiMiddleware(options) {
|
|
|
1669
1668
|
const { openapiFilePath, enableEnhancement = true, serverDir } = options;
|
|
1670
1669
|
return {
|
|
1671
1670
|
name: "openapi",
|
|
1672
|
-
mountPath: "/dev
|
|
1671
|
+
mountPath: "/dev",
|
|
1673
1672
|
routes: OPENAPI_ROUTES,
|
|
1674
1673
|
enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
|
|
1675
1674
|
createRouter: /* @__PURE__ */ __name((context) => {
|
|
@@ -1941,10 +1940,8 @@ function parsePinoLog(line, source) {
|
|
|
1941
1940
|
statusCode: pinoLog.status_code,
|
|
1942
1941
|
durationMs: pinoLog.duration_ms,
|
|
1943
1942
|
ip: pinoLog.ip,
|
|
1944
|
-
referer: pinoLog.referer,
|
|
1945
1943
|
requestBody: pinoLog.request_body,
|
|
1946
|
-
responseBody: pinoLog.response_body
|
|
1947
|
-
queryParams: pinoLog.query_params
|
|
1944
|
+
responseBody: pinoLog.response_body
|
|
1948
1945
|
},
|
|
1949
1946
|
tags: [
|
|
1950
1947
|
source
|
|
@@ -2849,8 +2846,7 @@ function parsePinoLog2(line, source) {
|
|
|
2849
2846
|
durationMs: pinoLog.duration_ms,
|
|
2850
2847
|
ip: pinoLog.ip,
|
|
2851
2848
|
requestBody: pinoLog.request_body,
|
|
2852
|
-
responseBody: pinoLog.response_body
|
|
2853
|
-
queryParams: pinoLog.query_params
|
|
2849
|
+
responseBody: pinoLog.response_body
|
|
2854
2850
|
},
|
|
2855
2851
|
tags: [
|
|
2856
2852
|
source
|
|
@@ -3301,109 +3297,6 @@ function createSSEHandler(logDir, options = {}) {
|
|
|
3301
3297
|
}
|
|
3302
3298
|
__name(createSSEHandler, "createSSEHandler");
|
|
3303
3299
|
|
|
3304
|
-
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3305
|
-
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3306
|
-
function extractModuleFromPath(path7) {
|
|
3307
|
-
const segments = path7.split("/").filter(Boolean);
|
|
3308
|
-
let startIndex = 0;
|
|
3309
|
-
if (segments[0] === "api") {
|
|
3310
|
-
startIndex = 1;
|
|
3311
|
-
}
|
|
3312
|
-
if (segments[startIndex]?.match(/^v\d+$/)) {
|
|
3313
|
-
startIndex++;
|
|
3314
|
-
}
|
|
3315
|
-
const moduleName = segments[startIndex];
|
|
3316
|
-
if (!moduleName || moduleName.startsWith(":")) {
|
|
3317
|
-
return "default";
|
|
3318
|
-
}
|
|
3319
|
-
return moduleName;
|
|
3320
|
-
}
|
|
3321
|
-
__name(extractModuleFromPath, "extractModuleFromPath");
|
|
3322
|
-
function generateRouteId(method, path7) {
|
|
3323
|
-
const cleanPath = path7.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3324
|
-
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3325
|
-
}
|
|
3326
|
-
__name(generateRouteId, "generateRouteId");
|
|
3327
|
-
function capitalize(str) {
|
|
3328
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3329
|
-
}
|
|
3330
|
-
__name(capitalize, "capitalize");
|
|
3331
|
-
function groupRoutesByModule(routes) {
|
|
3332
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
3333
|
-
routes.forEach((route) => {
|
|
3334
|
-
const existing = groupMap.get(route.module) || [];
|
|
3335
|
-
existing.push(route);
|
|
3336
|
-
groupMap.set(route.module, existing);
|
|
3337
|
-
});
|
|
3338
|
-
const groups = [];
|
|
3339
|
-
groupMap.forEach((apis, moduleName) => {
|
|
3340
|
-
groups.push({
|
|
3341
|
-
id: moduleName,
|
|
3342
|
-
name: capitalize(moduleName),
|
|
3343
|
-
apis: apis.sort((a, b) => a.path.localeCompare(b.path))
|
|
3344
|
-
});
|
|
3345
|
-
});
|
|
3346
|
-
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3347
|
-
}
|
|
3348
|
-
__name(groupRoutesByModule, "groupRoutesByModule");
|
|
3349
|
-
async function fetchRoutesFromBackend(basePath) {
|
|
3350
|
-
const normalizedBasePath = basePath.replace(/\/+$/, "");
|
|
3351
|
-
const url = `http://localhost:${SERVER_PORT}${normalizedBasePath}/api/__framework__/debug`;
|
|
3352
|
-
const response = await fetch(url, {
|
|
3353
|
-
method: "GET",
|
|
3354
|
-
headers: {
|
|
3355
|
-
"Accept": "application/json"
|
|
3356
|
-
}
|
|
3357
|
-
});
|
|
3358
|
-
if (!response.ok) {
|
|
3359
|
-
throw new Error(`Failed to fetch routes: ${response.status}`);
|
|
3360
|
-
}
|
|
3361
|
-
const data = await response.json();
|
|
3362
|
-
const routeConfig = data["\u8DEF\u7531\u914D\u7F6E"];
|
|
3363
|
-
if (!routeConfig || !routeConfig.routes || !Array.isArray(routeConfig.routes)) {
|
|
3364
|
-
console.warn("[api-list] Invalid routes data:", routeConfig);
|
|
3365
|
-
return [];
|
|
3366
|
-
}
|
|
3367
|
-
const debugRoutes = routeConfig.routes;
|
|
3368
|
-
return debugRoutes.filter((route) => {
|
|
3369
|
-
return route.path.includes("/api/") && !route.path.includes("__framework__") && !route.path.includes("__innerapi__") && !route.path.includes("/api/capability");
|
|
3370
|
-
}).map((route) => {
|
|
3371
|
-
const apiPathMatch = route.path.match(/\/api\/.*/);
|
|
3372
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : route.path;
|
|
3373
|
-
const method = route.method || "ALL";
|
|
3374
|
-
return {
|
|
3375
|
-
id: generateRouteId(method, apiPath),
|
|
3376
|
-
path: apiPath,
|
|
3377
|
-
method,
|
|
3378
|
-
module: extractModuleFromPath(apiPath)
|
|
3379
|
-
};
|
|
3380
|
-
});
|
|
3381
|
-
}
|
|
3382
|
-
__name(fetchRoutesFromBackend, "fetchRoutesFromBackend");
|
|
3383
|
-
function createApiListHandler() {
|
|
3384
|
-
return async (req, res) => {
|
|
3385
|
-
res.header("Access-Control-Allow-Origin", "*");
|
|
3386
|
-
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3387
|
-
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3388
|
-
try {
|
|
3389
|
-
const basePath = process.env.CLIENT_BASE_PATH || "";
|
|
3390
|
-
const routes = await fetchRoutesFromBackend(basePath);
|
|
3391
|
-
const groups = groupRoutesByModule(routes);
|
|
3392
|
-
res.json({
|
|
3393
|
-
groups,
|
|
3394
|
-
total: routes.length
|
|
3395
|
-
});
|
|
3396
|
-
} catch (error) {
|
|
3397
|
-
console.error("[api-list] Failed to fetch routes:", error);
|
|
3398
|
-
res.status(500).json({
|
|
3399
|
-
error: "Failed to fetch routes",
|
|
3400
|
-
message: error instanceof Error ? error.message : "Unknown error"
|
|
3401
|
-
});
|
|
3402
|
-
}
|
|
3403
|
-
};
|
|
3404
|
-
}
|
|
3405
|
-
__name(createApiListHandler, "createApiListHandler");
|
|
3406
|
-
|
|
3407
3300
|
// src/middlewares/dev-logs/router.ts
|
|
3408
3301
|
function createDevLogRouter(options = {}) {
|
|
3409
3302
|
const logDir = resolveLogDir(options.logDir);
|
|
@@ -3417,7 +3310,6 @@ function createDevLogRouter(options = {}) {
|
|
|
3417
3310
|
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
3418
3311
|
router.get("/trace/capability/list", createGetCapabilityTraceListHandler(logDir));
|
|
3419
3312
|
router.get("/health", createHealthCheckHandler());
|
|
3420
|
-
router.get("/api-list", createApiListHandler());
|
|
3421
3313
|
return router;
|
|
3422
3314
|
}
|
|
3423
3315
|
__name(createDevLogRouter, "createDevLogRouter");
|
|
@@ -3453,11 +3345,6 @@ var DEV_LOGS_ROUTES = [
|
|
|
3453
3345
|
method: "GET",
|
|
3454
3346
|
path: "/trace/trigger/:instanceID",
|
|
3455
3347
|
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
3456
|
-
},
|
|
3457
|
-
{
|
|
3458
|
-
method: "GET",
|
|
3459
|
-
path: "/api-list",
|
|
3460
|
-
description: "Get all API routes grouped by module"
|
|
3461
3348
|
}
|
|
3462
3349
|
];
|
|
3463
3350
|
function createDevLogsMiddleware(options = {}) {
|
|
@@ -3577,8 +3464,12 @@ __name(handleError2, "handleError");
|
|
|
3577
3464
|
function createDevLogRouter2(options = {}) {
|
|
3578
3465
|
const logDir = resolveLogDir2(options.logDir);
|
|
3579
3466
|
const router = import_express3.default.Router();
|
|
3580
|
-
router.post("/collect", import_express3.default.json(
|
|
3581
|
-
|
|
3467
|
+
router.post("/collect", import_express3.default.json({
|
|
3468
|
+
limit: "50mb"
|
|
3469
|
+
}), collectLogsHandler(logDir, options.fileName || "client.log"));
|
|
3470
|
+
router.post("/collect-batch", import_express3.default.json({
|
|
3471
|
+
limit: "50mb"
|
|
3472
|
+
}), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
|
|
3582
3473
|
return router;
|
|
3583
3474
|
}
|
|
3584
3475
|
__name(createDevLogRouter2, "createDevLogRouter");
|
|
@@ -3666,147 +3557,6 @@ function serializeError3(error) {
|
|
|
3666
3557
|
}
|
|
3667
3558
|
__name(serializeError3, "serializeError");
|
|
3668
3559
|
|
|
3669
|
-
// src/middlewares/api-routes/router.ts
|
|
3670
|
-
var import_express4 = __toESM(require("express"), 1);
|
|
3671
|
-
function extractModuleFromPath2(path7) {
|
|
3672
|
-
const segments = path7.split("/").filter(Boolean);
|
|
3673
|
-
let startIndex = 0;
|
|
3674
|
-
if (segments[0] === "api") {
|
|
3675
|
-
startIndex = 1;
|
|
3676
|
-
}
|
|
3677
|
-
if (segments[startIndex]?.match(/^v\d+$/)) {
|
|
3678
|
-
startIndex++;
|
|
3679
|
-
}
|
|
3680
|
-
const moduleName = segments[startIndex];
|
|
3681
|
-
if (!moduleName || moduleName.startsWith(":")) {
|
|
3682
|
-
return "default";
|
|
3683
|
-
}
|
|
3684
|
-
return moduleName;
|
|
3685
|
-
}
|
|
3686
|
-
__name(extractModuleFromPath2, "extractModuleFromPath");
|
|
3687
|
-
function generateRouteId2(method, path7) {
|
|
3688
|
-
const cleanPath = path7.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3689
|
-
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3690
|
-
}
|
|
3691
|
-
__name(generateRouteId2, "generateRouteId");
|
|
3692
|
-
function capitalize2(str) {
|
|
3693
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3694
|
-
}
|
|
3695
|
-
__name(capitalize2, "capitalize");
|
|
3696
|
-
function extractRoutes(app) {
|
|
3697
|
-
const router = app._router;
|
|
3698
|
-
if (!router?.stack) {
|
|
3699
|
-
return [];
|
|
3700
|
-
}
|
|
3701
|
-
const routes = [];
|
|
3702
|
-
const seenRoutes = /* @__PURE__ */ new Set();
|
|
3703
|
-
const processLayer = /* @__PURE__ */ __name((layer, basePath = "") => {
|
|
3704
|
-
if (layer.route) {
|
|
3705
|
-
const path7 = basePath + layer.route.path;
|
|
3706
|
-
if (!path7.includes("/api/") || path7.includes("__framework__") || path7.includes("__innerapi__")) {
|
|
3707
|
-
return;
|
|
3708
|
-
}
|
|
3709
|
-
const methods = Object.keys(layer.route.methods).filter((m) => layer.route.methods[m]);
|
|
3710
|
-
methods.forEach((method) => {
|
|
3711
|
-
const upperMethod = method.toUpperCase();
|
|
3712
|
-
const routeKey = `${upperMethod}:${path7}`;
|
|
3713
|
-
if (seenRoutes.has(routeKey)) {
|
|
3714
|
-
return;
|
|
3715
|
-
}
|
|
3716
|
-
seenRoutes.add(routeKey);
|
|
3717
|
-
const apiPathMatch = path7.match(/\/api\/.*/);
|
|
3718
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : path7;
|
|
3719
|
-
routes.push({
|
|
3720
|
-
id: generateRouteId2(upperMethod, apiPath),
|
|
3721
|
-
path: apiPath,
|
|
3722
|
-
method: upperMethod,
|
|
3723
|
-
module: extractModuleFromPath2(apiPath)
|
|
3724
|
-
});
|
|
3725
|
-
});
|
|
3726
|
-
}
|
|
3727
|
-
if (layer.name === "router" && layer.handle?.stack) {
|
|
3728
|
-
let prefix = basePath;
|
|
3729
|
-
if (layer.regexp) {
|
|
3730
|
-
const pattern = new RegExp("^\\^\\\\?(.*?)(?:\\\\/\\?|$)");
|
|
3731
|
-
const match = layer.regexp.source.match(pattern);
|
|
3732
|
-
if (match) {
|
|
3733
|
-
prefix = basePath + match[1].replace(/\\\//g, "/");
|
|
3734
|
-
}
|
|
3735
|
-
}
|
|
3736
|
-
layer.handle.stack.forEach((subLayer) => processLayer(subLayer, prefix));
|
|
3737
|
-
}
|
|
3738
|
-
}, "processLayer");
|
|
3739
|
-
router.stack.forEach((layer) => processLayer(layer));
|
|
3740
|
-
return routes;
|
|
3741
|
-
}
|
|
3742
|
-
__name(extractRoutes, "extractRoutes");
|
|
3743
|
-
function groupRoutesByModule2(routes) {
|
|
3744
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
3745
|
-
routes.forEach((route) => {
|
|
3746
|
-
const existing = groupMap.get(route.module) || [];
|
|
3747
|
-
existing.push(route);
|
|
3748
|
-
groupMap.set(route.module, existing);
|
|
3749
|
-
});
|
|
3750
|
-
const groups = [];
|
|
3751
|
-
groupMap.forEach((apis, moduleName) => {
|
|
3752
|
-
groups.push({
|
|
3753
|
-
id: moduleName,
|
|
3754
|
-
name: capitalize2(moduleName),
|
|
3755
|
-
apis: apis.sort((a, b) => a.path.localeCompare(b.path))
|
|
3756
|
-
});
|
|
3757
|
-
});
|
|
3758
|
-
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3759
|
-
}
|
|
3760
|
-
__name(groupRoutesByModule2, "groupRoutesByModule");
|
|
3761
|
-
function createApiRoutesRouter() {
|
|
3762
|
-
console.log("[api-routes] createApiRoutesRouter called");
|
|
3763
|
-
const router = import_express4.default.Router();
|
|
3764
|
-
console.log("[api-routes] router created, adding /api-list route");
|
|
3765
|
-
router.get("/api-list", (req, res) => {
|
|
3766
|
-
console.log("[api-routes] /api-list handler called");
|
|
3767
|
-
res.header("Access-Control-Allow-Origin", "*");
|
|
3768
|
-
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3769
|
-
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3770
|
-
try {
|
|
3771
|
-
const routes = extractRoutes(req.app);
|
|
3772
|
-
const groups = groupRoutesByModule2(routes);
|
|
3773
|
-
res.json({
|
|
3774
|
-
groups,
|
|
3775
|
-
total: routes.length
|
|
3776
|
-
});
|
|
3777
|
-
} catch (error) {
|
|
3778
|
-
console.error("[api-routes] Failed to extract routes:", error);
|
|
3779
|
-
res.status(500).json({
|
|
3780
|
-
error: "Failed to extract routes",
|
|
3781
|
-
message: error instanceof Error ? error.message : "Unknown error"
|
|
3782
|
-
});
|
|
3783
|
-
}
|
|
3784
|
-
});
|
|
3785
|
-
return router;
|
|
3786
|
-
}
|
|
3787
|
-
__name(createApiRoutesRouter, "createApiRoutesRouter");
|
|
3788
|
-
|
|
3789
|
-
// src/middlewares/api-routes/index.ts
|
|
3790
|
-
var API_ROUTES_ROUTES = [
|
|
3791
|
-
{
|
|
3792
|
-
method: "GET",
|
|
3793
|
-
path: "/api-list",
|
|
3794
|
-
description: "Get all API routes grouped by module"
|
|
3795
|
-
}
|
|
3796
|
-
];
|
|
3797
|
-
function createApiRoutesMiddleware() {
|
|
3798
|
-
return {
|
|
3799
|
-
name: "api-routes",
|
|
3800
|
-
mountPath: "/dev/api",
|
|
3801
|
-
routes: API_ROUTES_ROUTES,
|
|
3802
|
-
enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
|
|
3803
|
-
createRouter: /* @__PURE__ */ __name((_context) => {
|
|
3804
|
-
return createApiRoutesRouter();
|
|
3805
|
-
}, "createRouter")
|
|
3806
|
-
};
|
|
3807
|
-
}
|
|
3808
|
-
__name(createApiRoutesMiddleware, "createApiRoutesMiddleware");
|
|
3809
|
-
|
|
3810
3560
|
// src/middlewares/index.ts
|
|
3811
3561
|
function enhanceForCompat(req, res) {
|
|
3812
3562
|
if (!res.status) {
|
|
@@ -3930,7 +3680,6 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
3930
3680
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
3931
3681
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3932
3682
|
0 && (module.exports = {
|
|
3933
|
-
createApiRoutesMiddleware,
|
|
3934
3683
|
createCollectLogsMiddleware,
|
|
3935
3684
|
createDevLogsMiddleware,
|
|
3936
3685
|
createOpenapiMiddleware,
|