@lark-apaas/devtool-kits 1.2.17-alpha.3 → 1.2.17-alpha.30

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 CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  handleDevProxyError: () => handleDevProxyError,
40
40
  normalizeBasePath: () => normalizeBasePath,
41
41
  parseAndGenerateNestResourceTemplate: () => parseAndGenerateNestResourceTemplate,
42
+ parseApiRoutes: () => parseApiRoutes,
42
43
  postprocessDrizzleSchema: () => postprocessDrizzleSchema,
43
44
  registerMiddlewares: () => registerMiddlewares,
44
45
  sendError: () => sendError,
@@ -1386,6 +1387,7 @@ var import_node_crypto = __toESM(require("crypto"), 1);
1386
1387
 
1387
1388
  // src/middlewares/openapi/services.ts
1388
1389
  var import_node_fs4 = require("fs");
1390
+ var fsSync = __toESM(require("fs"), 1);
1389
1391
  var import_node_path4 = __toESM(require("path"), 1);
1390
1392
  var import_typescript = __toESM(require("typescript"), 1);
1391
1393
 
@@ -1608,6 +1610,120 @@ function extractControllerMetadata(sourceFile, filePath) {
1608
1610
  return metadata;
1609
1611
  }
1610
1612
  __name(extractControllerMetadata, "extractControllerMetadata");
1613
+ var HTTP_DECORATOR_NAMES = [
1614
+ "Get",
1615
+ "Post",
1616
+ "Put",
1617
+ "Delete",
1618
+ "Patch",
1619
+ "Options",
1620
+ "Head",
1621
+ "All"
1622
+ ];
1623
+ function findControllerFilesSync(dir) {
1624
+ const files = [];
1625
+ function scan(currentDir) {
1626
+ let entries;
1627
+ try {
1628
+ entries = fsSync.readdirSync(currentDir, {
1629
+ withFileTypes: true
1630
+ });
1631
+ } catch {
1632
+ return;
1633
+ }
1634
+ for (const entry of entries) {
1635
+ const fullPath = import_node_path4.default.join(currentDir, entry.name);
1636
+ if (entry.isDirectory()) {
1637
+ scan(fullPath);
1638
+ } else if (entry.isFile() && entry.name.endsWith(".controller.ts")) {
1639
+ files.push(fullPath);
1640
+ }
1641
+ }
1642
+ }
1643
+ __name(scan, "scan");
1644
+ scan(dir);
1645
+ return files;
1646
+ }
1647
+ __name(findControllerFilesSync, "findControllerFilesSync");
1648
+ function normalizeApiPath(controllerPath, routePath) {
1649
+ const combined = routePath ? `${controllerPath}/${routePath}` : controllerPath;
1650
+ let normalized = combined.replace(/\/+/g, "/");
1651
+ if (!normalized.startsWith("/")) normalized = `/${normalized}`;
1652
+ if (normalized.length > 1 && normalized.endsWith("/")) normalized = normalized.slice(0, -1);
1653
+ return normalized;
1654
+ }
1655
+ __name(normalizeApiPath, "normalizeApiPath");
1656
+ function parseControllerRoutes(filePath) {
1657
+ let content;
1658
+ try {
1659
+ content = fsSync.readFileSync(filePath, "utf-8");
1660
+ } catch {
1661
+ return [];
1662
+ }
1663
+ const sourceFile = import_typescript.default.createSourceFile(filePath, content, import_typescript.default.ScriptTarget.Latest, true);
1664
+ const routes = [];
1665
+ function getDecoratorsCompat(node) {
1666
+ if ("modifiers" in node && Array.isArray(node.modifiers)) {
1667
+ return node.modifiers.filter((mod) => mod.kind === import_typescript.default.SyntaxKind.Decorator);
1668
+ }
1669
+ if ("decorators" in node && Array.isArray(node.decorators)) {
1670
+ return node.decorators;
1671
+ }
1672
+ return [];
1673
+ }
1674
+ __name(getDecoratorsCompat, "getDecoratorsCompat");
1675
+ function getStringArg(expr) {
1676
+ if (expr.arguments.length > 0 && import_typescript.default.isStringLiteral(expr.arguments[0])) {
1677
+ return expr.arguments[0].text;
1678
+ }
1679
+ return "";
1680
+ }
1681
+ __name(getStringArg, "getStringArg");
1682
+ function visit(node) {
1683
+ if (import_typescript.default.isClassDeclaration(node)) {
1684
+ let controllerPath = "";
1685
+ for (const dec of getDecoratorsCompat(node)) {
1686
+ if (import_typescript.default.isCallExpression(dec.expression)) {
1687
+ const name = dec.expression.expression.getText(sourceFile);
1688
+ if (name === "Controller") {
1689
+ controllerPath = getStringArg(dec.expression);
1690
+ break;
1691
+ }
1692
+ }
1693
+ }
1694
+ for (const member of node.members) {
1695
+ if (!import_typescript.default.isMethodDeclaration(member)) continue;
1696
+ for (const dec of getDecoratorsCompat(member)) {
1697
+ if (!import_typescript.default.isCallExpression(dec.expression)) continue;
1698
+ const decoratorName = dec.expression.expression.getText(sourceFile);
1699
+ if (!HTTP_DECORATOR_NAMES.includes(decoratorName)) continue;
1700
+ const routePath = getStringArg(dec.expression);
1701
+ const fullPath = normalizeApiPath(controllerPath, routePath);
1702
+ const method = decoratorName === "All" ? "*" : decoratorName.toUpperCase();
1703
+ routes.push({
1704
+ method,
1705
+ path: fullPath
1706
+ });
1707
+ }
1708
+ }
1709
+ }
1710
+ import_typescript.default.forEachChild(node, visit);
1711
+ }
1712
+ __name(visit, "visit");
1713
+ visit(sourceFile);
1714
+ return routes;
1715
+ }
1716
+ __name(parseControllerRoutes, "parseControllerRoutes");
1717
+ function parseApiRoutes(serverDir) {
1718
+ const resolvedDir = import_node_path4.default.resolve(serverDir);
1719
+ const controllerFiles = findControllerFilesSync(resolvedDir);
1720
+ const routes = [];
1721
+ for (const filePath of controllerFiles) {
1722
+ routes.push(...parseControllerRoutes(filePath));
1723
+ }
1724
+ return routes;
1725
+ }
1726
+ __name(parseApiRoutes, "parseApiRoutes");
1611
1727
 
1612
1728
  // src/middlewares/openapi/controller.ts
1613
1729
  function createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir) {
@@ -1940,8 +2056,10 @@ function parsePinoLog(line, source) {
1940
2056
  statusCode: pinoLog.status_code,
1941
2057
  durationMs: pinoLog.duration_ms,
1942
2058
  ip: pinoLog.ip,
2059
+ pageRoute: pinoLog.page_route,
1943
2060
  requestBody: pinoLog.request_body,
1944
- responseBody: pinoLog.response_body
2061
+ responseBody: pinoLog.response_body,
2062
+ queryParams: pinoLog.query_params
1945
2063
  },
1946
2064
  tags: [
1947
2065
  source
@@ -2845,8 +2963,10 @@ function parsePinoLog2(line, source) {
2845
2963
  statusCode: pinoLog.status_code,
2846
2964
  durationMs: pinoLog.duration_ms,
2847
2965
  ip: pinoLog.ip,
2966
+ pageRoute: pinoLog.page_route,
2848
2967
  requestBody: pinoLog.request_body,
2849
- responseBody: pinoLog.response_body
2968
+ responseBody: pinoLog.response_body,
2969
+ queryParams: pinoLog.query_params
2850
2970
  },
2851
2971
  tags: [
2852
2972
  source
@@ -3297,6 +3417,106 @@ function createSSEHandler(logDir, options = {}) {
3297
3417
  }
3298
3418
  __name(createSSEHandler, "createSSEHandler");
3299
3419
 
3420
+ // src/middlewares/dev-logs/api-list-handler.ts
3421
+ var SERVER_PORT = process.env.SERVER_PORT || "3000";
3422
+ function extractModuleFromPath(path7) {
3423
+ const segments = path7.split("/").filter(Boolean);
3424
+ let startIndex = 0;
3425
+ if (segments[0] === "api") {
3426
+ startIndex = 1;
3427
+ }
3428
+ if (segments[startIndex]?.match(/^v\d+$/)) {
3429
+ startIndex++;
3430
+ }
3431
+ const moduleName = segments[startIndex];
3432
+ if (!moduleName || moduleName.startsWith(":")) {
3433
+ return "default";
3434
+ }
3435
+ return moduleName;
3436
+ }
3437
+ __name(extractModuleFromPath, "extractModuleFromPath");
3438
+ function generateRouteId(method, path7) {
3439
+ const cleanPath = path7.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
3440
+ return `${method.toLowerCase()}_${cleanPath}`;
3441
+ }
3442
+ __name(generateRouteId, "generateRouteId");
3443
+ function capitalize(str) {
3444
+ return str.charAt(0).toUpperCase() + str.slice(1);
3445
+ }
3446
+ __name(capitalize, "capitalize");
3447
+ function groupRoutesByModule(routes) {
3448
+ const groupMap = /* @__PURE__ */ new Map();
3449
+ routes.forEach((route) => {
3450
+ const existing = groupMap.get(route.module) || [];
3451
+ existing.push(route);
3452
+ groupMap.set(route.module, existing);
3453
+ });
3454
+ const groups = [];
3455
+ groupMap.forEach((apis, moduleName) => {
3456
+ groups.push({
3457
+ id: moduleName,
3458
+ name: capitalize(moduleName),
3459
+ apis: apis.sort((a, b) => a.path.localeCompare(b.path))
3460
+ });
3461
+ });
3462
+ return groups.sort((a, b) => a.name.localeCompare(b.name));
3463
+ }
3464
+ __name(groupRoutesByModule, "groupRoutesByModule");
3465
+ async function fetchRoutesFromBackend(basePath) {
3466
+ const normalizedBasePath = basePath.replace(/\/+$/, "");
3467
+ const url = `http://localhost:${SERVER_PORT}${normalizedBasePath}/api/__framework__/debug`;
3468
+ const response = await fetch(url, {
3469
+ method: "GET",
3470
+ headers: {
3471
+ "Accept": "application/json"
3472
+ }
3473
+ });
3474
+ if (!response.ok) {
3475
+ throw new Error(`Failed to fetch routes: ${response.status}`);
3476
+ }
3477
+ const data = await response.json();
3478
+ const routeConfig = data["\u8DEF\u7531\u914D\u7F6E"];
3479
+ if (!routeConfig || !routeConfig.routes || !Array.isArray(routeConfig.routes)) {
3480
+ console.warn("[api-list] Invalid routes data:", routeConfig);
3481
+ return [];
3482
+ }
3483
+ const debugRoutes = routeConfig.routes;
3484
+ return debugRoutes.filter((route) => {
3485
+ return route.path.includes("/api/") && !route.path.includes("__framework__") && !route.path.includes("__innerapi__") && !route.path.includes("/api/capability");
3486
+ }).map((route) => {
3487
+ const apiPathMatch = route.path.match(/\/api\/.*/);
3488
+ const apiPath = apiPathMatch ? apiPathMatch[0] : route.path;
3489
+ const method = route.method || "ALL";
3490
+ return {
3491
+ id: generateRouteId(method, apiPath),
3492
+ path: apiPath,
3493
+ method,
3494
+ module: extractModuleFromPath(apiPath)
3495
+ };
3496
+ });
3497
+ }
3498
+ __name(fetchRoutesFromBackend, "fetchRoutesFromBackend");
3499
+ function createApiListHandler() {
3500
+ return async (_req, res) => {
3501
+ try {
3502
+ const basePath = process.env.CLIENT_BASE_PATH || "";
3503
+ const routes = await fetchRoutesFromBackend(basePath);
3504
+ const groups = groupRoutesByModule(routes);
3505
+ res.json({
3506
+ groups,
3507
+ total: routes.length
3508
+ });
3509
+ } catch (error) {
3510
+ console.error("[api-list] Failed to fetch routes:", error);
3511
+ res.status(500).json({
3512
+ error: "Failed to fetch routes",
3513
+ message: error instanceof Error ? error.message : "Unknown error"
3514
+ });
3515
+ }
3516
+ };
3517
+ }
3518
+ __name(createApiListHandler, "createApiListHandler");
3519
+
3300
3520
  // src/middlewares/dev-logs/router.ts
3301
3521
  function createDevLogRouter(options = {}) {
3302
3522
  const logDir = resolveLogDir(options.logDir);
@@ -3310,6 +3530,7 @@ function createDevLogRouter(options = {}) {
3310
3530
  router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
3311
3531
  router.get("/trace/capability/list", createGetCapabilityTraceListHandler(logDir));
3312
3532
  router.get("/health", createHealthCheckHandler());
3533
+ router.get("/api-list", createApiListHandler());
3313
3534
  return router;
3314
3535
  }
3315
3536
  __name(createDevLogRouter, "createDevLogRouter");
@@ -3345,6 +3566,11 @@ var DEV_LOGS_ROUTES = [
3345
3566
  method: "GET",
3346
3567
  path: "/trace/trigger/:instanceID",
3347
3568
  description: "Get trigger detail (automation trigger) in trace.log by instanceID"
3569
+ },
3570
+ {
3571
+ method: "GET",
3572
+ path: "/api-list",
3573
+ description: "Get all API routes grouped by module"
3348
3574
  }
3349
3575
  ];
3350
3576
  function createDevLogsMiddleware(options = {}) {
@@ -3461,11 +3687,21 @@ function handleError2(res, error, message = "Failed to collect logs") {
3461
3687
  __name(handleError2, "handleError");
3462
3688
 
3463
3689
  // src/middlewares/collect-logs/router.ts
3690
+ var DEFAULT_BODY_SIZE_LIMIT = "1mb";
3691
+ function getBodySizeLimit() {
3692
+ return process.env.BODY_SIZE_LIMIT || DEFAULT_BODY_SIZE_LIMIT;
3693
+ }
3694
+ __name(getBodySizeLimit, "getBodySizeLimit");
3464
3695
  function createDevLogRouter2(options = {}) {
3465
3696
  const logDir = resolveLogDir2(options.logDir);
3466
3697
  const router = import_express3.default.Router();
3467
- router.post("/collect", import_express3.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
3468
- router.post("/collect-batch", import_express3.default.json(), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
3698
+ const bodyLimit = getBodySizeLimit();
3699
+ router.post("/collect", import_express3.default.json({
3700
+ limit: bodyLimit
3701
+ }), collectLogsHandler(logDir, options.fileName || "client.log"));
3702
+ router.post("/collect-batch", import_express3.default.json({
3703
+ limit: bodyLimit
3704
+ }), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
3469
3705
  return router;
3470
3706
  }
3471
3707
  __name(createDevLogRouter2, "createDevLogRouter");
@@ -3684,6 +3920,7 @@ __name(registerMiddlewares, "registerMiddlewares");
3684
3920
  handleDevProxyError,
3685
3921
  normalizeBasePath,
3686
3922
  parseAndGenerateNestResourceTemplate,
3923
+ parseApiRoutes,
3687
3924
  postprocessDrizzleSchema,
3688
3925
  registerMiddlewares,
3689
3926
  sendError,