@lark-apaas/devtool-kits 0.1.0-alpha.4 → 0.1.0-alpha.7

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
@@ -1370,8 +1370,8 @@ var require_node = __commonJS({
1370
1370
  }
1371
1371
  break;
1372
1372
  case "FILE":
1373
- var fs7 = require("fs");
1374
- stream2 = new fs7.SyncWriteStream(fd2, {
1373
+ var fs9 = require("fs");
1374
+ stream2 = new fs9.SyncWriteStream(fd2, {
1375
1375
  autoClose: false
1376
1376
  });
1377
1377
  stream2._type = "fs";
@@ -21250,8 +21250,8 @@ var require_node2 = __commonJS({
21250
21250
  }
21251
21251
  break;
21252
21252
  case "FILE":
21253
- var fs7 = require("fs");
21254
- stream2 = new fs7.SyncWriteStream(fd2, {
21253
+ var fs9 = require("fs");
21254
+ stream2 = new fs9.SyncWriteStream(fd2, {
21255
21255
  autoClose: false
21256
21256
  });
21257
21257
  stream2._type = "fs";
@@ -22020,8 +22020,8 @@ var require_node3 = __commonJS({
22020
22020
  }
22021
22021
  break;
22022
22022
  case "FILE":
22023
- var fs7 = require("fs");
22024
- stream2 = new fs7.SyncWriteStream(fd2, {
22023
+ var fs9 = require("fs");
22024
+ stream2 = new fs9.SyncWriteStream(fd2, {
22025
22025
  autoClose: false
22026
22026
  });
22027
22027
  stream2._type = "fs";
@@ -22942,11 +22942,11 @@ var require_view = __commonJS({
22942
22942
  "use strict";
22943
22943
  var debug = require_src3()("express:view");
22944
22944
  var path5 = require("path");
22945
- var fs7 = require("fs");
22945
+ var fs9 = require("fs");
22946
22946
  var dirname = path5.dirname;
22947
22947
  var basename = path5.basename;
22948
22948
  var extname = path5.extname;
22949
- var join3 = path5.join;
22949
+ var join5 = path5.join;
22950
22950
  var resolve = path5.resolve;
22951
22951
  module2.exports = View;
22952
22952
  function View(name, options) {
@@ -22995,12 +22995,12 @@ var require_view = __commonJS({
22995
22995
  }, "render");
22996
22996
  View.prototype.resolve = /* @__PURE__ */ __name(function resolve2(dir, file) {
22997
22997
  var ext = this.ext;
22998
- var path6 = join3(dir, file);
22998
+ var path6 = join5(dir, file);
22999
22999
  var stat = tryStat(path6);
23000
23000
  if (stat && stat.isFile()) {
23001
23001
  return path6;
23002
23002
  }
23003
- path6 = join3(dir, basename(file, ext), "index" + ext);
23003
+ path6 = join5(dir, basename(file, ext), "index" + ext);
23004
23004
  stat = tryStat(path6);
23005
23005
  if (stat && stat.isFile()) {
23006
23006
  return path6;
@@ -23009,7 +23009,7 @@ var require_view = __commonJS({
23009
23009
  function tryStat(path6) {
23010
23010
  debug('stat "%s"', path6);
23011
23011
  try {
23012
- return fs7.statSync(path6);
23012
+ return fs9.statSync(path6);
23013
23013
  } catch (e) {
23014
23014
  return void 0;
23015
23015
  }
@@ -23658,8 +23658,8 @@ var require_node4 = __commonJS({
23658
23658
  }
23659
23659
  break;
23660
23660
  case "FILE":
23661
- var fs7 = require("fs");
23662
- stream2 = new fs7.SyncWriteStream(fd2, {
23661
+ var fs9 = require("fs");
23662
+ stream2 = new fs9.SyncWriteStream(fd2, {
23663
23663
  autoClose: false
23664
23664
  });
23665
23665
  stream2._type = "fs";
@@ -23860,7 +23860,7 @@ var require_mime = __commonJS({
23860
23860
  "../../../node_modules/mime/mime.js"(exports2, module2) {
23861
23861
  "use strict";
23862
23862
  var path5 = require("path");
23863
- var fs7 = require("fs");
23863
+ var fs9 = require("fs");
23864
23864
  function Mime() {
23865
23865
  this.types = /* @__PURE__ */ Object.create(null);
23866
23866
  this.extensions = /* @__PURE__ */ Object.create(null);
@@ -23882,7 +23882,7 @@ var require_mime = __commonJS({
23882
23882
  };
23883
23883
  Mime.prototype.load = function(file) {
23884
23884
  this._loading = file;
23885
- var map = {}, content = fs7.readFileSync(file, "ascii"), lines = content.split(/[\r\n]+/);
23885
+ var map = {}, content = fs9.readFileSync(file, "ascii"), lines = content.split(/[\r\n]+/);
23886
23886
  lines.forEach(function(line) {
23887
23887
  var fields = line.replace(/\s*#.*|^\s*|\s*$/g, "").split(/\s+/);
23888
23888
  map[fields.shift()] = fields;
@@ -24127,7 +24127,7 @@ var require_send = __commonJS({
24127
24127
  var escapeHtml = require_escape_html();
24128
24128
  var etag = require_etag();
24129
24129
  var fresh = require_fresh();
24130
- var fs7 = require("fs");
24130
+ var fs9 = require("fs");
24131
24131
  var mime = require_mime();
24132
24132
  var ms = require_ms5();
24133
24133
  var onFinished = require_on_finished();
@@ -24137,7 +24137,7 @@ var require_send = __commonJS({
24137
24137
  var Stream = require("stream");
24138
24138
  var util = require("util");
24139
24139
  var extname = path5.extname;
24140
- var join3 = path5.join;
24140
+ var join5 = path5.join;
24141
24141
  var normalize = path5.normalize;
24142
24142
  var resolve = path5.resolve;
24143
24143
  var sep = path5.sep;
@@ -24354,7 +24354,7 @@ var require_send = __commonJS({
24354
24354
  return res;
24355
24355
  }
24356
24356
  parts = path6.split(sep);
24357
- path6 = normalize(join3(root, path6));
24357
+ path6 = normalize(join5(root, path6));
24358
24358
  } else {
24359
24359
  if (UP_PATH_REGEXP.test(path6)) {
24360
24360
  debug('malicious path "%s"', path6);
@@ -24460,7 +24460,7 @@ var require_send = __commonJS({
24460
24460
  var i = 0;
24461
24461
  var self = this;
24462
24462
  debug('stat "%s"', path6);
24463
- fs7.stat(path6, /* @__PURE__ */ __name(function onstat(err, stat) {
24463
+ fs9.stat(path6, /* @__PURE__ */ __name(function onstat(err, stat) {
24464
24464
  if (err && err.code === "ENOENT" && !extname(path6) && path6[path6.length - 1] !== sep) {
24465
24465
  return next(err);
24466
24466
  }
@@ -24475,7 +24475,7 @@ var require_send = __commonJS({
24475
24475
  }
24476
24476
  var p = path6 + "." + self._extensions[i++];
24477
24477
  debug('stat "%s"', p);
24478
- fs7.stat(p, function(err2, stat) {
24478
+ fs9.stat(p, function(err2, stat) {
24479
24479
  if (err2) return next(err2);
24480
24480
  if (stat.isDirectory()) return next();
24481
24481
  self.emit("file", p, stat);
@@ -24492,9 +24492,9 @@ var require_send = __commonJS({
24492
24492
  if (err) return self.onStatError(err);
24493
24493
  return self.error(404);
24494
24494
  }
24495
- var p = join3(path6, self._index[i]);
24495
+ var p = join5(path6, self._index[i]);
24496
24496
  debug('stat "%s"', p);
24497
- fs7.stat(p, function(err2, stat) {
24497
+ fs9.stat(p, function(err2, stat) {
24498
24498
  if (err2) return next(err2);
24499
24499
  if (stat.isDirectory()) return next();
24500
24500
  self.emit("file", p, stat);
@@ -24507,7 +24507,7 @@ var require_send = __commonJS({
24507
24507
  SendStream.prototype.stream = /* @__PURE__ */ __name(function stream(path6, options) {
24508
24508
  var self = this;
24509
24509
  var res = this.res;
24510
- var stream2 = fs7.createReadStream(path6, options);
24510
+ var stream2 = fs9.createReadStream(path6, options);
24511
24511
  this.emit("stream", stream2);
24512
24512
  stream2.pipe(res);
24513
24513
  function cleanup() {
@@ -27345,7 +27345,7 @@ var require_response = __commonJS({
27345
27345
  var encodeUrl = require_encodeurl();
27346
27346
  var escapeHtml = require_escape_html();
27347
27347
  var http = require("http");
27348
- var isAbsolute2 = require_utils2().isAbsolute;
27348
+ var isAbsolute3 = require_utils2().isAbsolute;
27349
27349
  var onFinished = require_on_finished();
27350
27350
  var path5 = require("path");
27351
27351
  var statuses = require_statuses();
@@ -27551,7 +27551,7 @@ var require_response = __commonJS({
27551
27551
  done = options;
27552
27552
  opts = {};
27553
27553
  }
27554
- if (!opts.root && !isAbsolute2(path6)) {
27554
+ if (!opts.root && !isAbsolute3(path6)) {
27555
27555
  throw new TypeError("path must be absolute or specify root to res.sendFile");
27556
27556
  }
27557
27557
  var pathname = encodeURI(path6);
@@ -28091,6 +28091,7 @@ var require_express2 = __commonJS({
28091
28091
  // src/index.ts
28092
28092
  var index_exports = {};
28093
28093
  __export(index_exports, {
28094
+ createCollectLogsMiddleware: () => createCollectLogsMiddleware,
28094
28095
  createDevLogsMiddleware: () => createDevLogsMiddleware,
28095
28096
  createOpenapiMiddleware: () => createOpenapiMiddleware,
28096
28097
  normalizeBasePath: () => normalizeBasePath,
@@ -28401,7 +28402,7 @@ function collapseExtraBlankLines(text) {
28401
28402
  __name(collapseExtraBlankLines, "collapseExtraBlankLines");
28402
28403
 
28403
28404
  // src/middlewares/index.ts
28404
- var import_node_path6 = __toESM(require("path"), 1);
28405
+ var import_node_path7 = __toESM(require("path"), 1);
28405
28406
 
28406
28407
  // src/middlewares/openapi/router.ts
28407
28408
  var import_express = __toESM(require_express2(), 1);
@@ -28802,6 +28803,13 @@ function matchesPath(actualPath, pattern) {
28802
28803
  return matchesPathPattern(actualPath, pattern);
28803
28804
  }
28804
28805
  __name(matchesPath, "matchesPath");
28806
+ function matchesMethod(actualMethod, expectedMethod) {
28807
+ if (!actualMethod || !expectedMethod) {
28808
+ return false;
28809
+ }
28810
+ return actualMethod.toUpperCase() === expectedMethod.toUpperCase();
28811
+ }
28812
+ __name(matchesMethod, "matchesMethod");
28805
28813
  function serializeError(error) {
28806
28814
  return error instanceof Error ? {
28807
28815
  name: error.name,
@@ -28845,7 +28853,7 @@ async function readLogEntriesByTrace(filePath, traceId, limit) {
28845
28853
  return matches;
28846
28854
  }
28847
28855
  __name(readLogEntriesByTrace, "readLogEntriesByTrace");
28848
- async function readRecentTraceCalls(filePath, page, pageSize, pathFilter) {
28856
+ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter, methodFilter) {
28849
28857
  if (!await fileExists(filePath)) {
28850
28858
  return void 0;
28851
28859
  }
@@ -28882,7 +28890,9 @@ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter) {
28882
28890
  if (!builder.path && entry.path) {
28883
28891
  builder.path = String(entry.path);
28884
28892
  }
28885
- const shouldInclude = !pathFilter || matchesPath(builder.path, pathFilter);
28893
+ const pathMatches = !pathFilter || matchesPath(builder.path, pathFilter);
28894
+ const methodMatches = !methodFilter || matchesMethod(builder.method, methodFilter);
28895
+ const shouldInclude = pathMatches && methodMatches;
28886
28896
  if (shouldInclude) {
28887
28897
  completedCalls.push(builder);
28888
28898
  }
@@ -29072,8 +29082,9 @@ function createGetRecentTracesHandler(logDir) {
29072
29082
  const page = parsePositiveInt(req.query.page, 1);
29073
29083
  const pageSize = parseLimit(req.query.pageSize, 10, 100);
29074
29084
  const pathFilter = typeof req.query.path === "string" ? req.query.path.trim() : void 0;
29085
+ const methodFilter = typeof req.query.method === "string" ? req.query.method.trim().toUpperCase() : void 0;
29075
29086
  try {
29076
- const result = await readRecentTraceCalls(traceLogPath, page, pageSize, pathFilter);
29087
+ const result = await readRecentTraceCalls(traceLogPath, page, pageSize, pathFilter, methodFilter);
29077
29088
  if (!result) {
29078
29089
  return handleNotFound(res, traceLogPath);
29079
29090
  }
@@ -29081,6 +29092,7 @@ function createGetRecentTracesHandler(logDir) {
29081
29092
  file: getRelativePath(traceLogPath),
29082
29093
  ...result,
29083
29094
  path: pathFilter || null,
29095
+ method: methodFilter || null,
29084
29096
  count: result.calls.length
29085
29097
  });
29086
29098
  } catch (error) {
@@ -29137,7 +29149,7 @@ var DEV_LOGS_ROUTES = [
29137
29149
  {
29138
29150
  method: "GET",
29139
29151
  path: "/trace/recent",
29140
- description: "Get recent trace calls with pagination and optional path filter"
29152
+ description: "Get recent trace calls with pagination and optional path/method filters"
29141
29153
  },
29142
29154
  {
29143
29155
  method: "GET",
@@ -29161,6 +29173,101 @@ function createDevLogsMiddleware(options = {}) {
29161
29173
  }
29162
29174
  __name(createDevLogsMiddleware, "createDevLogsMiddleware");
29163
29175
 
29176
+ // src/middlewares/collect-logs/router.ts
29177
+ var import_express3 = __toESM(require_express2(), 1);
29178
+
29179
+ // src/middlewares/collect-logs/controller.ts
29180
+ var import_path = require("path");
29181
+ var import_fs = __toESM(require("fs"), 1);
29182
+
29183
+ // src/middlewares/collect-logs/utils.ts
29184
+ var import_node_path6 = require("path");
29185
+ var import_node_fs6 = __toESM(require("fs"), 1);
29186
+ function resolveLogDir2(provided) {
29187
+ if (!provided) {
29188
+ return (0, import_node_path6.join)(process.cwd(), "logs");
29189
+ }
29190
+ return (0, import_node_path6.isAbsolute)(provided) ? provided : (0, import_node_path6.join)(process.cwd(), provided);
29191
+ }
29192
+ __name(resolveLogDir2, "resolveLogDir");
29193
+ function ensureDir(dir) {
29194
+ if (!import_node_fs6.default.existsSync(dir)) {
29195
+ import_node_fs6.default.mkdirSync(dir, {
29196
+ recursive: true
29197
+ });
29198
+ }
29199
+ }
29200
+ __name(ensureDir, "ensureDir");
29201
+ function serializeError2(error) {
29202
+ return error instanceof Error ? {
29203
+ name: error.name,
29204
+ message: error.message
29205
+ } : {
29206
+ message: String(error)
29207
+ };
29208
+ }
29209
+ __name(serializeError2, "serializeError");
29210
+
29211
+ // src/middlewares/collect-logs/controller.ts
29212
+ function collectLogsHandler(logDir, fileName) {
29213
+ const filePath = (0, import_path.join)(logDir, fileName);
29214
+ ensureDir(logDir);
29215
+ return async (req, res) => {
29216
+ try {
29217
+ const logContent = req.body;
29218
+ const logLine = JSON.stringify(logContent) + "\n";
29219
+ await import_fs.default.promises.appendFile(filePath, logLine);
29220
+ res.json({
29221
+ success: true
29222
+ });
29223
+ } catch (error) {
29224
+ handleError2(res, error, "Failed to collect logs");
29225
+ }
29226
+ };
29227
+ }
29228
+ __name(collectLogsHandler, "collectLogsHandler");
29229
+ function handleError2(res, error, message = "Failed to collect logs") {
29230
+ res.status(500).json({
29231
+ message,
29232
+ error: serializeError2(error)
29233
+ });
29234
+ }
29235
+ __name(handleError2, "handleError");
29236
+
29237
+ // src/middlewares/collect-logs/router.ts
29238
+ function createDevLogRouter2(options = {}) {
29239
+ const logDir = resolveLogDir2(options.logDir);
29240
+ const router = import_express3.default.Router();
29241
+ router.post("/collect", import_express3.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
29242
+ return router;
29243
+ }
29244
+ __name(createDevLogRouter2, "createDevLogRouter");
29245
+
29246
+ // src/middlewares/collect-logs/index.ts
29247
+ var DEV_LOGS_ROUTES2 = [
29248
+ {
29249
+ method: "POST",
29250
+ path: "/collect",
29251
+ description: "Collect logs from client."
29252
+ }
29253
+ ];
29254
+ function createCollectLogsMiddleware(options = {}) {
29255
+ const { logDir } = options;
29256
+ return {
29257
+ name: "collect-logs",
29258
+ mountPath: "/dev/logs",
29259
+ routes: DEV_LOGS_ROUTES2,
29260
+ enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
29261
+ createRouter: /* @__PURE__ */ __name((context) => {
29262
+ return createDevLogRouter2({
29263
+ logDir: logDir || context.logDir,
29264
+ fileName: options.fileName || "client.log"
29265
+ });
29266
+ }, "createRouter")
29267
+ };
29268
+ }
29269
+ __name(createCollectLogsMiddleware, "createCollectLogsMiddleware");
29270
+
29164
29271
  // src/middlewares/index.ts
29165
29272
  function isRouteMiddleware(middleware) {
29166
29273
  return "createRouter" in middleware && middleware.createRouter !== void 0;
@@ -29171,7 +29278,7 @@ function isGlobalMiddleware(middleware) {
29171
29278
  }
29172
29279
  __name(isGlobalMiddleware, "isGlobalMiddleware");
29173
29280
  function computeMountPath(basePath, mountPath) {
29174
- const routePath = import_node_path6.default.posix.join(basePath, mountPath);
29281
+ const routePath = import_node_path7.default.posix.join(basePath, mountPath);
29175
29282
  return routePath.startsWith("/") ? routePath : `/${routePath}`;
29176
29283
  }
29177
29284
  __name(computeMountPath, "computeMountPath");
@@ -29179,7 +29286,7 @@ function logMiddlewareRegistration(middleware, fullMountPath) {
29179
29286
  if (middleware.routes && middleware.routes.length > 0) {
29180
29287
  console.log(`[Middleware] Registered: ${middleware.name} at ${fullMountPath}`);
29181
29288
  middleware.routes.forEach((route) => {
29182
- const routePath = route.path === "/" ? fullMountPath : import_node_path6.default.posix.join(fullMountPath, route.path);
29289
+ const routePath = route.path === "/" ? fullMountPath : import_node_path7.default.posix.join(fullMountPath, route.path);
29183
29290
  console.log(` ${route.method} ${routePath} - ${route.description}`);
29184
29291
  });
29185
29292
  } else {
@@ -29239,6 +29346,7 @@ async function registerMiddlewares(server, middlewares, options) {
29239
29346
  __name(registerMiddlewares, "registerMiddlewares");
29240
29347
  // Annotate the CommonJS export names for ESM import in node:
29241
29348
  0 && (module.exports = {
29349
+ createCollectLogsMiddleware,
29242
29350
  createDevLogsMiddleware,
29243
29351
  createOpenapiMiddleware,
29244
29352
  normalizeBasePath,