@lark-apaas/devtool-kits 1.2.17-alpha.24 → 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 +8 -260
- 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 +8 -259
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -232,14 +232,6 @@ declare function getQuery(req: AnyRequest): Record<string, string>;
|
|
|
232
232
|
*/
|
|
233
233
|
declare function getQueryParam(req: AnyRequest, key: string): string | undefined;
|
|
234
234
|
|
|
235
|
-
/**
|
|
236
|
-
* Creates api-routes middleware for listing application API routes
|
|
237
|
-
* Used by the API Debug Panel in the platform
|
|
238
|
-
*
|
|
239
|
-
* Note: Temporarily mounted at /dev/logs for debugging. Will move to dedicated path after confirming it works.
|
|
240
|
-
*/
|
|
241
|
-
declare function createApiRoutesMiddleware(): RouteMiddleware;
|
|
242
|
-
|
|
243
235
|
/**
|
|
244
236
|
* Register middlewares for Express-compatible servers or Vite
|
|
245
237
|
* @param server - Express app or Vite middleware instance
|
|
@@ -279,4 +271,4 @@ declare function createApiRoutesMiddleware(): RouteMiddleware;
|
|
|
279
271
|
*/
|
|
280
272
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
281
273
|
|
|
282
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware,
|
|
274
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, getQuery, getQueryParam, handleDevProxyError, normalizeBasePath, parseAndGenerateNestResourceTemplate, postprocessDrizzleSchema, registerMiddlewares, sendError, sendJson, sendSuccess };
|
package/dist/index.d.ts
CHANGED
|
@@ -232,14 +232,6 @@ declare function getQuery(req: AnyRequest): Record<string, string>;
|
|
|
232
232
|
*/
|
|
233
233
|
declare function getQueryParam(req: AnyRequest, key: string): string | undefined;
|
|
234
234
|
|
|
235
|
-
/**
|
|
236
|
-
* Creates api-routes middleware for listing application API routes
|
|
237
|
-
* Used by the API Debug Panel in the platform
|
|
238
|
-
*
|
|
239
|
-
* Note: Temporarily mounted at /dev/logs for debugging. Will move to dedicated path after confirming it works.
|
|
240
|
-
*/
|
|
241
|
-
declare function createApiRoutesMiddleware(): RouteMiddleware;
|
|
242
|
-
|
|
243
235
|
/**
|
|
244
236
|
* Register middlewares for Express-compatible servers or Vite
|
|
245
237
|
* @param server - Express app or Vite middleware instance
|
|
@@ -279,4 +271,4 @@ declare function createApiRoutesMiddleware(): RouteMiddleware;
|
|
|
279
271
|
*/
|
|
280
272
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
281
273
|
|
|
282
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware,
|
|
274
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type Options, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, getQuery, getQueryParam, handleDevProxyError, normalizeBasePath, parseAndGenerateNestResourceTemplate, postprocessDrizzleSchema, registerMiddlewares, sendError, sendJson, sendSuccess };
|
package/dist/index.js
CHANGED
|
@@ -1894,10 +1894,8 @@ function parsePinoLog(line, source) {
|
|
|
1894
1894
|
statusCode: pinoLog.status_code,
|
|
1895
1895
|
durationMs: pinoLog.duration_ms,
|
|
1896
1896
|
ip: pinoLog.ip,
|
|
1897
|
-
pageRoute: pinoLog.page_route,
|
|
1898
1897
|
requestBody: pinoLog.request_body,
|
|
1899
|
-
responseBody: pinoLog.response_body
|
|
1900
|
-
queryParams: pinoLog.query_params
|
|
1898
|
+
responseBody: pinoLog.response_body
|
|
1901
1899
|
},
|
|
1902
1900
|
tags: [
|
|
1903
1901
|
source
|
|
@@ -2801,10 +2799,8 @@ function parsePinoLog2(line, source) {
|
|
|
2801
2799
|
statusCode: pinoLog.status_code,
|
|
2802
2800
|
durationMs: pinoLog.duration_ms,
|
|
2803
2801
|
ip: pinoLog.ip,
|
|
2804
|
-
pageRoute: pinoLog.page_route,
|
|
2805
2802
|
requestBody: pinoLog.request_body,
|
|
2806
|
-
responseBody: pinoLog.response_body
|
|
2807
|
-
queryParams: pinoLog.query_params
|
|
2803
|
+
responseBody: pinoLog.response_body
|
|
2808
2804
|
},
|
|
2809
2805
|
tags: [
|
|
2810
2806
|
source
|
|
@@ -3255,109 +3251,6 @@ function createSSEHandler(logDir, options = {}) {
|
|
|
3255
3251
|
}
|
|
3256
3252
|
__name(createSSEHandler, "createSSEHandler");
|
|
3257
3253
|
|
|
3258
|
-
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3259
|
-
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3260
|
-
function extractModuleFromPath(path7) {
|
|
3261
|
-
const segments = path7.split("/").filter(Boolean);
|
|
3262
|
-
let startIndex = 0;
|
|
3263
|
-
if (segments[0] === "api") {
|
|
3264
|
-
startIndex = 1;
|
|
3265
|
-
}
|
|
3266
|
-
if (segments[startIndex]?.match(/^v\d+$/)) {
|
|
3267
|
-
startIndex++;
|
|
3268
|
-
}
|
|
3269
|
-
const moduleName = segments[startIndex];
|
|
3270
|
-
if (!moduleName || moduleName.startsWith(":")) {
|
|
3271
|
-
return "default";
|
|
3272
|
-
}
|
|
3273
|
-
return moduleName;
|
|
3274
|
-
}
|
|
3275
|
-
__name(extractModuleFromPath, "extractModuleFromPath");
|
|
3276
|
-
function generateRouteId(method, path7) {
|
|
3277
|
-
const cleanPath = path7.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3278
|
-
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3279
|
-
}
|
|
3280
|
-
__name(generateRouteId, "generateRouteId");
|
|
3281
|
-
function capitalize(str) {
|
|
3282
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3283
|
-
}
|
|
3284
|
-
__name(capitalize, "capitalize");
|
|
3285
|
-
function groupRoutesByModule(routes) {
|
|
3286
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
3287
|
-
routes.forEach((route) => {
|
|
3288
|
-
const existing = groupMap.get(route.module) || [];
|
|
3289
|
-
existing.push(route);
|
|
3290
|
-
groupMap.set(route.module, existing);
|
|
3291
|
-
});
|
|
3292
|
-
const groups = [];
|
|
3293
|
-
groupMap.forEach((apis, moduleName) => {
|
|
3294
|
-
groups.push({
|
|
3295
|
-
id: moduleName,
|
|
3296
|
-
name: capitalize(moduleName),
|
|
3297
|
-
apis: apis.sort((a, b) => a.path.localeCompare(b.path))
|
|
3298
|
-
});
|
|
3299
|
-
});
|
|
3300
|
-
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3301
|
-
}
|
|
3302
|
-
__name(groupRoutesByModule, "groupRoutesByModule");
|
|
3303
|
-
async function fetchRoutesFromBackend(basePath) {
|
|
3304
|
-
const normalizedBasePath = basePath.replace(/\/+$/, "");
|
|
3305
|
-
const url = `http://localhost:${SERVER_PORT}${normalizedBasePath}/api/__framework__/debug`;
|
|
3306
|
-
const response = await fetch(url, {
|
|
3307
|
-
method: "GET",
|
|
3308
|
-
headers: {
|
|
3309
|
-
"Accept": "application/json"
|
|
3310
|
-
}
|
|
3311
|
-
});
|
|
3312
|
-
if (!response.ok) {
|
|
3313
|
-
throw new Error(`Failed to fetch routes: ${response.status}`);
|
|
3314
|
-
}
|
|
3315
|
-
const data = await response.json();
|
|
3316
|
-
const routeConfig = data["\u8DEF\u7531\u914D\u7F6E"];
|
|
3317
|
-
if (!routeConfig || !routeConfig.routes || !Array.isArray(routeConfig.routes)) {
|
|
3318
|
-
console.warn("[api-list] Invalid routes data:", routeConfig);
|
|
3319
|
-
return [];
|
|
3320
|
-
}
|
|
3321
|
-
const debugRoutes = routeConfig.routes;
|
|
3322
|
-
return debugRoutes.filter((route) => {
|
|
3323
|
-
return route.path.includes("/api/") && !route.path.includes("__framework__") && !route.path.includes("__innerapi__") && !route.path.includes("/api/capability");
|
|
3324
|
-
}).map((route) => {
|
|
3325
|
-
const apiPathMatch = route.path.match(/\/api\/.*/);
|
|
3326
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : route.path;
|
|
3327
|
-
const method = route.method || "ALL";
|
|
3328
|
-
return {
|
|
3329
|
-
id: generateRouteId(method, apiPath),
|
|
3330
|
-
path: apiPath,
|
|
3331
|
-
method,
|
|
3332
|
-
module: extractModuleFromPath(apiPath)
|
|
3333
|
-
};
|
|
3334
|
-
});
|
|
3335
|
-
}
|
|
3336
|
-
__name(fetchRoutesFromBackend, "fetchRoutesFromBackend");
|
|
3337
|
-
function createApiListHandler() {
|
|
3338
|
-
return async (req, res) => {
|
|
3339
|
-
res.header("Access-Control-Allow-Origin", "*");
|
|
3340
|
-
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3341
|
-
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3342
|
-
try {
|
|
3343
|
-
const basePath = process.env.CLIENT_BASE_PATH || "";
|
|
3344
|
-
const routes = await fetchRoutesFromBackend(basePath);
|
|
3345
|
-
const groups = groupRoutesByModule(routes);
|
|
3346
|
-
res.json({
|
|
3347
|
-
groups,
|
|
3348
|
-
total: routes.length
|
|
3349
|
-
});
|
|
3350
|
-
} catch (error) {
|
|
3351
|
-
console.error("[api-list] Failed to fetch routes:", error);
|
|
3352
|
-
res.status(500).json({
|
|
3353
|
-
error: "Failed to fetch routes",
|
|
3354
|
-
message: error instanceof Error ? error.message : "Unknown error"
|
|
3355
|
-
});
|
|
3356
|
-
}
|
|
3357
|
-
};
|
|
3358
|
-
}
|
|
3359
|
-
__name(createApiListHandler, "createApiListHandler");
|
|
3360
|
-
|
|
3361
3254
|
// src/middlewares/dev-logs/router.ts
|
|
3362
3255
|
function createDevLogRouter(options = {}) {
|
|
3363
3256
|
const logDir = resolveLogDir(options.logDir);
|
|
@@ -3371,7 +3264,6 @@ function createDevLogRouter(options = {}) {
|
|
|
3371
3264
|
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
3372
3265
|
router.get("/trace/capability/list", createGetCapabilityTraceListHandler(logDir));
|
|
3373
3266
|
router.get("/health", createHealthCheckHandler());
|
|
3374
|
-
router.get("/api-list", createApiListHandler());
|
|
3375
3267
|
return router;
|
|
3376
3268
|
}
|
|
3377
3269
|
__name(createDevLogRouter, "createDevLogRouter");
|
|
@@ -3407,11 +3299,6 @@ var DEV_LOGS_ROUTES = [
|
|
|
3407
3299
|
method: "GET",
|
|
3408
3300
|
path: "/trace/trigger/:instanceID",
|
|
3409
3301
|
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
3410
|
-
},
|
|
3411
|
-
{
|
|
3412
|
-
method: "GET",
|
|
3413
|
-
path: "/api-list",
|
|
3414
|
-
description: "Get all API routes grouped by module"
|
|
3415
3302
|
}
|
|
3416
3303
|
];
|
|
3417
3304
|
function createDevLogsMiddleware(options = {}) {
|
|
@@ -3531,8 +3418,12 @@ __name(handleError2, "handleError");
|
|
|
3531
3418
|
function createDevLogRouter2(options = {}) {
|
|
3532
3419
|
const logDir = resolveLogDir2(options.logDir);
|
|
3533
3420
|
const router = express3.Router();
|
|
3534
|
-
router.post("/collect", express3.json(
|
|
3535
|
-
|
|
3421
|
+
router.post("/collect", express3.json({
|
|
3422
|
+
limit: "50mb"
|
|
3423
|
+
}), collectLogsHandler(logDir, options.fileName || "client.log"));
|
|
3424
|
+
router.post("/collect-batch", express3.json({
|
|
3425
|
+
limit: "50mb"
|
|
3426
|
+
}), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
|
|
3536
3427
|
return router;
|
|
3537
3428
|
}
|
|
3538
3429
|
__name(createDevLogRouter2, "createDevLogRouter");
|
|
@@ -3620,147 +3511,6 @@ function serializeError3(error) {
|
|
|
3620
3511
|
}
|
|
3621
3512
|
__name(serializeError3, "serializeError");
|
|
3622
3513
|
|
|
3623
|
-
// src/middlewares/api-routes/router.ts
|
|
3624
|
-
import express4 from "express";
|
|
3625
|
-
function extractModuleFromPath2(path7) {
|
|
3626
|
-
const segments = path7.split("/").filter(Boolean);
|
|
3627
|
-
let startIndex = 0;
|
|
3628
|
-
if (segments[0] === "api") {
|
|
3629
|
-
startIndex = 1;
|
|
3630
|
-
}
|
|
3631
|
-
if (segments[startIndex]?.match(/^v\d+$/)) {
|
|
3632
|
-
startIndex++;
|
|
3633
|
-
}
|
|
3634
|
-
const moduleName = segments[startIndex];
|
|
3635
|
-
if (!moduleName || moduleName.startsWith(":")) {
|
|
3636
|
-
return "default";
|
|
3637
|
-
}
|
|
3638
|
-
return moduleName;
|
|
3639
|
-
}
|
|
3640
|
-
__name(extractModuleFromPath2, "extractModuleFromPath");
|
|
3641
|
-
function generateRouteId2(method, path7) {
|
|
3642
|
-
const cleanPath = path7.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3643
|
-
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3644
|
-
}
|
|
3645
|
-
__name(generateRouteId2, "generateRouteId");
|
|
3646
|
-
function capitalize2(str) {
|
|
3647
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3648
|
-
}
|
|
3649
|
-
__name(capitalize2, "capitalize");
|
|
3650
|
-
function extractRoutes(app) {
|
|
3651
|
-
const router = app._router;
|
|
3652
|
-
if (!router?.stack) {
|
|
3653
|
-
return [];
|
|
3654
|
-
}
|
|
3655
|
-
const routes = [];
|
|
3656
|
-
const seenRoutes = /* @__PURE__ */ new Set();
|
|
3657
|
-
const processLayer = /* @__PURE__ */ __name((layer, basePath = "") => {
|
|
3658
|
-
if (layer.route) {
|
|
3659
|
-
const path7 = basePath + layer.route.path;
|
|
3660
|
-
if (!path7.includes("/api/") || path7.includes("__framework__") || path7.includes("__innerapi__")) {
|
|
3661
|
-
return;
|
|
3662
|
-
}
|
|
3663
|
-
const methods = Object.keys(layer.route.methods).filter((m) => layer.route.methods[m]);
|
|
3664
|
-
methods.forEach((method) => {
|
|
3665
|
-
const upperMethod = method.toUpperCase();
|
|
3666
|
-
const routeKey = `${upperMethod}:${path7}`;
|
|
3667
|
-
if (seenRoutes.has(routeKey)) {
|
|
3668
|
-
return;
|
|
3669
|
-
}
|
|
3670
|
-
seenRoutes.add(routeKey);
|
|
3671
|
-
const apiPathMatch = path7.match(/\/api\/.*/);
|
|
3672
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : path7;
|
|
3673
|
-
routes.push({
|
|
3674
|
-
id: generateRouteId2(upperMethod, apiPath),
|
|
3675
|
-
path: apiPath,
|
|
3676
|
-
method: upperMethod,
|
|
3677
|
-
module: extractModuleFromPath2(apiPath)
|
|
3678
|
-
});
|
|
3679
|
-
});
|
|
3680
|
-
}
|
|
3681
|
-
if (layer.name === "router" && layer.handle?.stack) {
|
|
3682
|
-
let prefix = basePath;
|
|
3683
|
-
if (layer.regexp) {
|
|
3684
|
-
const pattern = new RegExp("^\\^\\\\?(.*?)(?:\\\\/\\?|$)");
|
|
3685
|
-
const match = layer.regexp.source.match(pattern);
|
|
3686
|
-
if (match) {
|
|
3687
|
-
prefix = basePath + match[1].replace(/\\\//g, "/");
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
layer.handle.stack.forEach((subLayer) => processLayer(subLayer, prefix));
|
|
3691
|
-
}
|
|
3692
|
-
}, "processLayer");
|
|
3693
|
-
router.stack.forEach((layer) => processLayer(layer));
|
|
3694
|
-
return routes;
|
|
3695
|
-
}
|
|
3696
|
-
__name(extractRoutes, "extractRoutes");
|
|
3697
|
-
function groupRoutesByModule2(routes) {
|
|
3698
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
3699
|
-
routes.forEach((route) => {
|
|
3700
|
-
const existing = groupMap.get(route.module) || [];
|
|
3701
|
-
existing.push(route);
|
|
3702
|
-
groupMap.set(route.module, existing);
|
|
3703
|
-
});
|
|
3704
|
-
const groups = [];
|
|
3705
|
-
groupMap.forEach((apis, moduleName) => {
|
|
3706
|
-
groups.push({
|
|
3707
|
-
id: moduleName,
|
|
3708
|
-
name: capitalize2(moduleName),
|
|
3709
|
-
apis: apis.sort((a, b) => a.path.localeCompare(b.path))
|
|
3710
|
-
});
|
|
3711
|
-
});
|
|
3712
|
-
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3713
|
-
}
|
|
3714
|
-
__name(groupRoutesByModule2, "groupRoutesByModule");
|
|
3715
|
-
function createApiRoutesRouter() {
|
|
3716
|
-
console.log("[api-routes] createApiRoutesRouter called");
|
|
3717
|
-
const router = express4.Router();
|
|
3718
|
-
console.log("[api-routes] router created, adding /api-list route");
|
|
3719
|
-
router.get("/api-list", (req, res) => {
|
|
3720
|
-
console.log("[api-routes] /api-list handler called");
|
|
3721
|
-
res.header("Access-Control-Allow-Origin", "*");
|
|
3722
|
-
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3723
|
-
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3724
|
-
try {
|
|
3725
|
-
const routes = extractRoutes(req.app);
|
|
3726
|
-
const groups = groupRoutesByModule2(routes);
|
|
3727
|
-
res.json({
|
|
3728
|
-
groups,
|
|
3729
|
-
total: routes.length
|
|
3730
|
-
});
|
|
3731
|
-
} catch (error) {
|
|
3732
|
-
console.error("[api-routes] Failed to extract routes:", error);
|
|
3733
|
-
res.status(500).json({
|
|
3734
|
-
error: "Failed to extract routes",
|
|
3735
|
-
message: error instanceof Error ? error.message : "Unknown error"
|
|
3736
|
-
});
|
|
3737
|
-
}
|
|
3738
|
-
});
|
|
3739
|
-
return router;
|
|
3740
|
-
}
|
|
3741
|
-
__name(createApiRoutesRouter, "createApiRoutesRouter");
|
|
3742
|
-
|
|
3743
|
-
// src/middlewares/api-routes/index.ts
|
|
3744
|
-
var API_ROUTES_ROUTES = [
|
|
3745
|
-
{
|
|
3746
|
-
method: "GET",
|
|
3747
|
-
path: "/api-list",
|
|
3748
|
-
description: "Get all API routes grouped by module"
|
|
3749
|
-
}
|
|
3750
|
-
];
|
|
3751
|
-
function createApiRoutesMiddleware() {
|
|
3752
|
-
return {
|
|
3753
|
-
name: "api-routes",
|
|
3754
|
-
mountPath: "/dev/api",
|
|
3755
|
-
routes: API_ROUTES_ROUTES,
|
|
3756
|
-
enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
|
|
3757
|
-
createRouter: /* @__PURE__ */ __name((_context) => {
|
|
3758
|
-
return createApiRoutesRouter();
|
|
3759
|
-
}, "createRouter")
|
|
3760
|
-
};
|
|
3761
|
-
}
|
|
3762
|
-
__name(createApiRoutesMiddleware, "createApiRoutesMiddleware");
|
|
3763
|
-
|
|
3764
3514
|
// src/middlewares/index.ts
|
|
3765
3515
|
function enhanceForCompat(req, res) {
|
|
3766
3516
|
if (!res.status) {
|
|
@@ -3883,7 +3633,6 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
3883
3633
|
}
|
|
3884
3634
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
3885
3635
|
export {
|
|
3886
|
-
createApiRoutesMiddleware,
|
|
3887
3636
|
createCollectLogsMiddleware,
|
|
3888
3637
|
createDevLogsMiddleware,
|
|
3889
3638
|
createOpenapiMiddleware,
|