@lark-apaas/devtool-kits 1.2.17-alpha.22 → 1.2.17-alpha.23

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
@@ -31,6 +31,7 @@ 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,
34
35
  createCollectLogsMiddleware: () => createCollectLogsMiddleware,
35
36
  createDevLogsMiddleware: () => createDevLogsMiddleware,
36
37
  createOpenapiMiddleware: () => createOpenapiMiddleware,
@@ -1651,7 +1652,7 @@ function createOpenapiRouter(options, context) {
1651
1652
  const { openapiFilePath, enableEnhancement, serverDir } = options;
1652
1653
  const router = import_express.default.Router();
1653
1654
  const handler = createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir);
1654
- router.get("/openapi.json", (req, res) => handler(req, res, context));
1655
+ router.get("/", (req, res) => handler(req, res, context));
1655
1656
  return router;
1656
1657
  }
1657
1658
  __name(createOpenapiRouter, "createOpenapiRouter");
@@ -1660,7 +1661,7 @@ __name(createOpenapiRouter, "createOpenapiRouter");
1660
1661
  var OPENAPI_ROUTES = [
1661
1662
  {
1662
1663
  method: "GET",
1663
- path: "/openapi.json",
1664
+ path: "/",
1664
1665
  description: "Serve enhanced OpenAPI specification with source code references"
1665
1666
  }
1666
1667
  ];
@@ -1668,7 +1669,7 @@ function createOpenapiMiddleware(options) {
1668
1669
  const { openapiFilePath, enableEnhancement = true, serverDir } = options;
1669
1670
  return {
1670
1671
  name: "openapi",
1671
- mountPath: "/dev",
1672
+ mountPath: "/dev/openapi.json",
1672
1673
  routes: OPENAPI_ROUTES,
1673
1674
  enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
1674
1675
  createRouter: /* @__PURE__ */ __name((context) => {
@@ -1940,8 +1941,10 @@ function parsePinoLog(line, source) {
1940
1941
  statusCode: pinoLog.status_code,
1941
1942
  durationMs: pinoLog.duration_ms,
1942
1943
  ip: pinoLog.ip,
1944
+ referer: pinoLog.referer,
1943
1945
  requestBody: pinoLog.request_body,
1944
- responseBody: pinoLog.response_body
1946
+ responseBody: pinoLog.response_body,
1947
+ queryParams: pinoLog.query_params
1945
1948
  },
1946
1949
  tags: [
1947
1950
  source
@@ -2846,7 +2849,8 @@ function parsePinoLog2(line, source) {
2846
2849
  durationMs: pinoLog.duration_ms,
2847
2850
  ip: pinoLog.ip,
2848
2851
  requestBody: pinoLog.request_body,
2849
- responseBody: pinoLog.response_body
2852
+ responseBody: pinoLog.response_body,
2853
+ queryParams: pinoLog.query_params
2850
2854
  },
2851
2855
  tags: [
2852
2856
  source
@@ -3297,6 +3301,109 @@ function createSSEHandler(logDir, options = {}) {
3297
3301
  }
3298
3302
  __name(createSSEHandler, "createSSEHandler");
3299
3303
 
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
+
3300
3407
  // src/middlewares/dev-logs/router.ts
3301
3408
  function createDevLogRouter(options = {}) {
3302
3409
  const logDir = resolveLogDir(options.logDir);
@@ -3310,6 +3417,7 @@ function createDevLogRouter(options = {}) {
3310
3417
  router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
3311
3418
  router.get("/trace/capability/list", createGetCapabilityTraceListHandler(logDir));
3312
3419
  router.get("/health", createHealthCheckHandler());
3420
+ router.get("/api-list", createApiListHandler());
3313
3421
  return router;
3314
3422
  }
3315
3423
  __name(createDevLogRouter, "createDevLogRouter");
@@ -3345,6 +3453,11 @@ var DEV_LOGS_ROUTES = [
3345
3453
  method: "GET",
3346
3454
  path: "/trace/trigger/:instanceID",
3347
3455
  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"
3348
3461
  }
3349
3462
  ];
3350
3463
  function createDevLogsMiddleware(options = {}) {
@@ -3464,12 +3577,8 @@ __name(handleError2, "handleError");
3464
3577
  function createDevLogRouter2(options = {}) {
3465
3578
  const logDir = resolveLogDir2(options.logDir);
3466
3579
  const router = import_express3.default.Router();
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"));
3580
+ router.post("/collect", import_express3.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
3581
+ router.post("/collect-batch", import_express3.default.json(), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
3473
3582
  return router;
3474
3583
  }
3475
3584
  __name(createDevLogRouter2, "createDevLogRouter");
@@ -3557,6 +3666,147 @@ function serializeError3(error) {
3557
3666
  }
3558
3667
  __name(serializeError3, "serializeError");
3559
3668
 
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
+
3560
3810
  // src/middlewares/index.ts
3561
3811
  function enhanceForCompat(req, res) {
3562
3812
  if (!res.status) {
@@ -3680,6 +3930,7 @@ async function registerMiddlewares(server, middlewares, options) {
3680
3930
  __name(registerMiddlewares, "registerMiddlewares");
3681
3931
  // Annotate the CommonJS export names for ESM import in node:
3682
3932
  0 && (module.exports = {
3933
+ createApiRoutesMiddleware,
3683
3934
  createCollectLogsMiddleware,
3684
3935
  createDevLogsMiddleware,
3685
3936
  createOpenapiMiddleware,