@lark-apaas/devtool-kits 1.2.15 → 1.2.16-beta.0

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
@@ -1261,11 +1261,8 @@ async function parseAndGenerateNestResourceTemplate(options) {
1261
1261
  __name(parseAndGenerateNestResourceTemplate, "parseAndGenerateNestResourceTemplate");
1262
1262
 
1263
1263
  // src/helpers/proxy-error/index.ts
1264
- var import_node_fs3 = __toESM(require("fs"), 1);
1265
- var import_node_path3 = __toESM(require("path"), 1);
1266
- var import_node_http = __toESM(require("http"), 1);
1267
- var import_node_https = __toESM(require("https"), 1);
1268
- var errorHtmlTemplate = null;
1264
+ var http = __toESM(require("http"), 1);
1265
+ var https = __toESM(require("https"), 1);
1269
1266
  function isConnectionError(err) {
1270
1267
  const code = err.code;
1271
1268
  const connectionErrorCodes = [
@@ -1278,12 +1275,12 @@ function isConnectionError(err) {
1278
1275
  return connectionErrorCodes.includes(code || "");
1279
1276
  }
1280
1277
  __name(isConnectionError, "isConnectionError");
1281
- function checkServiceAvailable(targetUrl, timeout = 1e3) {
1278
+ function checkServiceAvailable(targetUrl, timeout = 2e3) {
1282
1279
  return new Promise((resolve) => {
1283
1280
  try {
1284
1281
  const url = new URL(targetUrl);
1285
1282
  const isHttps = url.protocol === "https:";
1286
- const httpModule = isHttps ? import_node_https.default : import_node_http.default;
1283
+ const httpModule = isHttps ? https : http;
1287
1284
  const req = httpModule.request({
1288
1285
  hostname: url.hostname,
1289
1286
  port: url.port || (isHttps ? 443 : 80),
@@ -1291,8 +1288,7 @@ function checkServiceAvailable(targetUrl, timeout = 1e3) {
1291
1288
  method: "HEAD",
1292
1289
  timeout
1293
1290
  }, (res) => {
1294
- const available = res.statusCode !== 502 && !res.headers["x-proxy-error-page"];
1295
- resolve(available);
1291
+ resolve(res.statusCode !== 502);
1296
1292
  });
1297
1293
  req.on("timeout", () => {
1298
1294
  req.destroy();
@@ -1302,7 +1298,7 @@ function checkServiceAvailable(targetUrl, timeout = 1e3) {
1302
1298
  resolve(false);
1303
1299
  });
1304
1300
  req.end();
1305
- } catch (e) {
1301
+ } catch {
1306
1302
  resolve(false);
1307
1303
  }
1308
1304
  });
@@ -1320,194 +1316,61 @@ async function waitForServiceRecovery(targetUrl, timeout, interval) {
1320
1316
  return false;
1321
1317
  }
1322
1318
  __name(waitForServiceRecovery, "waitForServiceRecovery");
1323
- function getDirname() {
1324
- return __dirname;
1325
- }
1326
- __name(getDirname, "getDirname");
1327
- function getErrorHtmlTemplate() {
1328
- if (!errorHtmlTemplate) {
1329
- const dirname = getDirname();
1330
- const htmlPath = import_node_path3.default.join(dirname, "error.html");
1331
- errorHtmlTemplate = import_node_fs3.default.readFileSync(htmlPath, "utf-8");
1332
- }
1333
- return errorHtmlTemplate;
1334
- }
1335
- __name(getErrorHtmlTemplate, "getErrorHtmlTemplate");
1336
- function parseLogLine(line) {
1337
- const trimmed = line.trim();
1338
- if (!trimmed) return null;
1339
- const match = trimmed.match(/^\[\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\]\s+\[server\]\s+(.*)$/);
1340
- if (match) {
1341
- const content = match[1].trim();
1342
- return content || null;
1343
- }
1344
- return null;
1345
- }
1346
- __name(parseLogLine, "parseLogLine");
1347
- async function readRecentErrorLogs(logDir, maxLogs, fileName) {
1348
- const logFilePath = import_node_path3.default.join(logDir, fileName);
1349
- let fileStats;
1350
- try {
1351
- fileStats = await import_node_fs3.default.promises.stat(logFilePath);
1352
- } catch {
1353
- return {
1354
- logs: [],
1355
- hasCompileError: false
1356
- };
1357
- }
1358
- const fileSize = fileStats.size;
1359
- const maxReadSize = 1024 * 1024;
1360
- const readSize = Math.min(fileSize, maxReadSize);
1361
- const startPosition = Math.max(0, fileSize - readSize);
1362
- const buffer = Buffer.allocUnsafe(readSize);
1363
- let fileHandle;
1364
- try {
1365
- fileHandle = await import_node_fs3.default.promises.open(logFilePath, "r");
1366
- await fileHandle.read(buffer, 0, readSize, startPosition);
1367
- } catch (error) {
1368
- console.error("[Proxy Error]: Failed to read log file:", error);
1369
- return {
1370
- logs: [],
1371
- hasCompileError: false
1372
- };
1373
- } finally {
1374
- if (fileHandle) {
1375
- await fileHandle.close();
1376
- }
1377
- }
1378
- const content = buffer.toString("utf8");
1379
- const lines = content.split("\n");
1380
- if (startPosition > 0 && lines.length > 0) {
1381
- lines.shift();
1382
- }
1383
- const allLines = [];
1384
- for (const line of lines) {
1385
- const parsed = parseLogLine(line);
1386
- if (parsed !== null) {
1387
- allLines.push(parsed);
1388
- }
1389
- }
1390
- let startIndex = -1;
1391
- for (let i = allLines.length - 1; i >= 0; i--) {
1392
- const line = allLines[i];
1393
- if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
1394
- startIndex = i;
1395
- break;
1396
- }
1397
- }
1398
- if (startIndex === -1) {
1399
- console.log("[Proxy Error]: No compilation start marker found, returning last logs");
1400
- const fallbackLogs = allLines.slice(-maxLogs);
1401
- const hasCompileError2 = checkForErrors(fallbackLogs);
1402
- return {
1403
- logs: fallbackLogs,
1404
- hasCompileError: hasCompileError2
1405
- };
1406
- }
1407
- let endIndex = allLines.length;
1408
- for (let i = startIndex + 1; i < allLines.length; i++) {
1409
- const line = allLines[i];
1410
- if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
1411
- endIndex = i;
1412
- break;
1413
- }
1414
- }
1415
- const errorSection = allLines.slice(startIndex, endIndex);
1416
- const hasCompileError = checkForErrors(errorSection);
1417
- const logs = errorSection.length > maxLogs ? errorSection.slice(-maxLogs) : errorSection;
1418
- return {
1419
- logs,
1420
- hasCompileError
1421
- };
1422
- }
1423
- __name(readRecentErrorLogs, "readRecentErrorLogs");
1424
- function checkForErrors(logs) {
1425
- for (const line of logs) {
1426
- const compileErrorMatch = line.match(/Found (\d+) errors?\. Watching for file changes/);
1427
- if (compileErrorMatch) {
1428
- const errorCount = parseInt(compileErrorMatch[1], 10);
1429
- if (errorCount > 0) {
1430
- console.log(`[Proxy Error]: Found ${errorCount} compilation error(s)`);
1431
- return true;
1432
- }
1433
- }
1434
- }
1435
- return false;
1319
+ function send502Json(res) {
1320
+ if (res.headersSent) return;
1321
+ res.writeHead(502, {
1322
+ "Content-Type": "application/json; charset=utf-8",
1323
+ "Cache-Control": "no-cache, no-store, must-revalidate"
1324
+ });
1325
+ res.end(JSON.stringify({
1326
+ error: "Bad Gateway",
1327
+ message: "Backend service is temporarily unavailable"
1328
+ }));
1436
1329
  }
1437
- __name(checkForErrors, "checkForErrors");
1438
- function injectTemplateData(template, clientBasePath, parentOrigin) {
1439
- return template.replace("{{.clientBasePath}}", clientBasePath).replace("{{.parentOrigin}}", parentOrigin);
1330
+ __name(send502Json, "send502Json");
1331
+ function sendRedirect(req, res) {
1332
+ if (res.headersSent) return;
1333
+ const originalUrl = req.url || "/";
1334
+ console.log("[Proxy] Service recovered, redirecting to", originalUrl);
1335
+ res.writeHead(302, {
1336
+ "Location": originalUrl,
1337
+ "Cache-Control": "no-cache, no-store, must-revalidate"
1338
+ });
1339
+ res.end();
1440
1340
  }
1441
- __name(injectTemplateData, "injectTemplateData");
1341
+ __name(sendRedirect, "sendRedirect");
1442
1342
  function handleDevProxyError(err, req, res, options) {
1443
- const { logDir = import_node_path3.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}`, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
1444
- const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
1445
- console.error("[Proxy Error]:", err.message, clientBasePathWithoutSlash);
1343
+ const { retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}` } = options || {};
1344
+ console.error("[Proxy] Error:", err.message);
1446
1345
  if (res.headersSent) {
1447
- console.error("[Proxy Error]: Headers already sent, cannot send error page");
1346
+ console.error("[Proxy] Headers already sent, cannot handle error");
1347
+ return;
1348
+ }
1349
+ if (!isConnectionError(err)) {
1350
+ console.log("[Proxy] Non-connection error, returning 502");
1351
+ send502Json(res);
1448
1352
  return;
1449
1353
  }
1354
+ console.log("[Proxy] Connection error, waiting for service recovery...");
1450
1355
  (async () => {
1451
1356
  try {
1452
- const isConnError = isConnectionError(err);
1453
- const { hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
1454
- if (isConnError && !hasCompileError) {
1455
- console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
1456
- try {
1457
- new URL(target);
1458
- } catch (e) {
1459
- console.error("[Proxy Error]: Invalid target URL:", target);
1460
- console.log("[Proxy Error]: Showing error page due to invalid target");
1461
- }
1462
- console.log(`[Proxy Error]: Waiting for service recovery at ${target} (timeout: ${retryTimeout}ms)...`);
1463
- const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
1464
- if (recovered) {
1465
- console.log("[Proxy Error]: Service recovered within timeout, sending 302 redirect");
1466
- sendSimpleRedirect(req, res);
1467
- return;
1468
- }
1469
- console.log("[Proxy Error]: Service did not recover within timeout, showing error page with probe");
1470
- }
1471
- if (isConnError && !hasCompileError) {
1472
- console.log("[Proxy Error]: Showing error page with auto-refresh probe");
1357
+ const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
1358
+ if (recovered) {
1359
+ sendRedirect(req, res);
1473
1360
  } else {
1474
- console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
1361
+ console.log("[Proxy] Service did not recover within timeout, returning 502");
1362
+ send502Json(res);
1475
1363
  }
1476
- const template = getErrorHtmlTemplate();
1477
- const parentOrigin = process.env.FORCE_FRAMEWORK_DOMAIN_MAIN || "";
1478
- const html = injectTemplateData(template, clientBasePathWithoutSlash, parentOrigin);
1479
- res.writeHead(200, {
1480
- "Content-Type": "text/html; charset=utf-8",
1481
- "Cache-Control": "no-cache, no-store, must-revalidate",
1482
- "X-Proxy-Error-Page": "true"
1483
- });
1484
- res.end(html);
1485
1364
  } catch (error) {
1486
- console.error("[Proxy Error]: Failed to handle error:", error);
1487
- if (!res.headersSent) {
1488
- res.writeHead(502, {
1489
- "Content-Type": "text/plain; charset=utf-8"
1490
- });
1491
- res.end(`Node \u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898`);
1492
- }
1365
+ console.error("[Proxy] Error during recovery wait:", error);
1366
+ send502Json(res);
1493
1367
  }
1494
1368
  })();
1495
1369
  }
1496
1370
  __name(handleDevProxyError, "handleDevProxyError");
1497
- function sendSimpleRedirect(req, res) {
1498
- if (res.headersSent) return;
1499
- const originalUrl = req.url || "/";
1500
- console.log("[Proxy Error]: Sending 302 redirect to", originalUrl);
1501
- res.writeHead(302, {
1502
- "Location": originalUrl,
1503
- "Cache-Control": "no-cache, no-store, must-revalidate"
1504
- });
1505
- res.end();
1506
- }
1507
- __name(sendSimpleRedirect, "sendSimpleRedirect");
1508
1371
 
1509
1372
  // src/middlewares/index.ts
1510
- var import_node_path10 = __toESM(require("path"), 1);
1373
+ var import_node_path9 = __toESM(require("path"), 1);
1511
1374
 
1512
1375
  // src/middlewares/openapi/router.ts
1513
1376
  var import_express = __toESM(require("express"), 1);
@@ -1517,21 +1380,21 @@ var import_promises2 = __toESM(require("fs/promises"), 1);
1517
1380
  var import_node_crypto = __toESM(require("crypto"), 1);
1518
1381
 
1519
1382
  // src/middlewares/openapi/services.ts
1520
- var import_node_fs5 = require("fs");
1521
- var import_node_path5 = __toESM(require("path"), 1);
1383
+ var import_node_fs4 = require("fs");
1384
+ var import_node_path4 = __toESM(require("path"), 1);
1522
1385
  var import_typescript = __toESM(require("typescript"), 1);
1523
1386
 
1524
1387
  // src/middlewares/openapi/utils.ts
1525
- var import_node_path4 = __toESM(require("path"), 1);
1526
- var import_node_fs4 = require("fs");
1388
+ var import_node_path3 = __toESM(require("path"), 1);
1389
+ var import_node_fs3 = require("fs");
1527
1390
  async function findControllerFiles(dir) {
1528
1391
  const files = [];
1529
1392
  async function scan(currentDir) {
1530
- const entries = await import_node_fs4.promises.readdir(currentDir, {
1393
+ const entries = await import_node_fs3.promises.readdir(currentDir, {
1531
1394
  withFileTypes: true
1532
1395
  });
1533
1396
  for (const entry of entries) {
1534
- const fullPath = import_node_path4.default.join(currentDir, entry.name);
1397
+ const fullPath = import_node_path3.default.join(currentDir, entry.name);
1535
1398
  if (entry.isDirectory()) {
1536
1399
  await scan(fullPath);
1537
1400
  } else if (entry.isFile() && entry.name.endsWith(".controller.ts")) {
@@ -1623,21 +1486,21 @@ __name(transformOpenapiPaths, "transformOpenapiPaths");
1623
1486
  // src/middlewares/openapi/services.ts
1624
1487
  async function enhanceOpenApiWithSourceInfo(options = {}) {
1625
1488
  const startTime = Date.now();
1626
- const openapiPath = options.openapiPath || import_node_path5.default.resolve(__dirname, "../client/src/api/gen/openapi.json");
1627
- const serverDir = options.serverDir || import_node_path5.default.resolve(__dirname, "../server");
1489
+ const openapiPath = options.openapiPath || import_node_path4.default.resolve(__dirname, "../client/src/api/gen/openapi.json");
1490
+ const serverDir = options.serverDir || import_node_path4.default.resolve(__dirname, "../server");
1628
1491
  const writeFile2 = options.writeFile !== false;
1629
1492
  let openapi;
1630
1493
  if (options.openapiData) {
1631
1494
  openapi = JSON.parse(JSON.stringify(options.openapiData));
1632
1495
  } else {
1633
- const openapiContent = await import_node_fs5.promises.readFile(openapiPath, "utf-8");
1496
+ const openapiContent = await import_node_fs4.promises.readFile(openapiPath, "utf-8");
1634
1497
  openapi = JSON.parse(openapiContent);
1635
1498
  }
1636
1499
  const controllerFiles = await findControllerFiles(serverDir);
1637
1500
  const sourceMap = await buildSourceMap(controllerFiles, processControllerFile);
1638
1501
  const enhanced = enhanceOpenApiPaths(openapi, sourceMap);
1639
1502
  if (writeFile2) {
1640
- await import_node_fs5.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
1503
+ await import_node_fs4.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
1641
1504
  }
1642
1505
  const duration = Date.now() - startTime;
1643
1506
  return {
@@ -1652,8 +1515,8 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
1652
1515
  }
1653
1516
  __name(enhanceOpenApiWithSourceInfo, "enhanceOpenApiWithSourceInfo");
1654
1517
  async function processControllerFile(filePath) {
1655
- const relativePath = import_node_path5.default.relative(process.cwd(), filePath);
1656
- const content = await import_node_fs5.promises.readFile(filePath, "utf-8");
1518
+ const relativePath = import_node_path4.default.relative(process.cwd(), filePath);
1519
+ const content = await import_node_fs4.promises.readFile(filePath, "utf-8");
1657
1520
  const sourceFile = import_typescript.default.createSourceFile(filePath, content, import_typescript.default.ScriptTarget.Latest, true);
1658
1521
  return extractControllerMetadata(sourceFile, relativePath);
1659
1522
  }
@@ -1818,8 +1681,8 @@ __name(createOpenapiMiddleware, "createOpenapiMiddleware");
1818
1681
  var import_express2 = __toESM(require("express"), 1);
1819
1682
 
1820
1683
  // src/middlewares/dev-logs/utils.ts
1821
- var import_node_fs6 = require("fs");
1822
- var import_node_path6 = require("path");
1684
+ var import_node_fs5 = require("fs");
1685
+ var import_node_path5 = require("path");
1823
1686
 
1824
1687
  // src/middlewares/dev-logs/helper/path-matcher.ts
1825
1688
  function pathPatternToRegex(pattern) {
@@ -1851,33 +1714,33 @@ function hasSpecialPatterns(pattern) {
1851
1714
  return /[{*]/.test(pattern);
1852
1715
  }
1853
1716
  __name(hasSpecialPatterns, "hasSpecialPatterns");
1854
- function normalizePathForMatching(path8) {
1855
- return path8.replace(/\/+/g, "/").replace(/\/+$/, "");
1717
+ function normalizePathForMatching(path7) {
1718
+ return path7.replace(/\/+/g, "/").replace(/\/+$/, "");
1856
1719
  }
1857
1720
  __name(normalizePathForMatching, "normalizePathForMatching");
1858
1721
 
1859
1722
  // src/middlewares/dev-logs/utils.ts
1860
1723
  function resolveLogDir(provided) {
1861
1724
  if (!provided) {
1862
- return (0, import_node_path6.join)(process.cwd(), "logs");
1725
+ return (0, import_node_path5.join)(process.cwd(), "logs");
1863
1726
  }
1864
- return (0, import_node_path6.isAbsolute)(provided) ? provided : (0, import_node_path6.join)(process.cwd(), provided);
1727
+ return (0, import_node_path5.isAbsolute)(provided) ? provided : (0, import_node_path5.join)(process.cwd(), provided);
1865
1728
  }
1866
1729
  __name(resolveLogDir, "resolveLogDir");
1867
1730
  function getRelativePath(filePath) {
1868
- return (0, import_node_path6.relative)(process.cwd(), filePath);
1731
+ return (0, import_node_path5.relative)(process.cwd(), filePath);
1869
1732
  }
1870
1733
  __name(getRelativePath, "getRelativePath");
1871
1734
  async function fileExists(filePath) {
1872
1735
  try {
1873
- await import_node_fs6.promises.access(filePath);
1736
+ await import_node_fs5.promises.access(filePath);
1874
1737
  return true;
1875
1738
  } catch {
1876
1739
  return false;
1877
1740
  }
1878
1741
  }
1879
1742
  __name(fileExists, "fileExists");
1880
- function parseLogLine2(line) {
1743
+ function parseLogLine(line) {
1881
1744
  const trimmed = line.trim();
1882
1745
  if (!trimmed) return void 0;
1883
1746
  try {
@@ -1886,7 +1749,7 @@ function parseLogLine2(line) {
1886
1749
  return void 0;
1887
1750
  }
1888
1751
  }
1889
- __name(parseLogLine2, "parseLogLine");
1752
+ __name(parseLogLine, "parseLogLine");
1890
1753
  function extractNumber(message, pattern) {
1891
1754
  if (typeof message !== "string") return void 0;
1892
1755
  const match = message.match(pattern);
@@ -1920,8 +1783,8 @@ function resolveLogFilePath(baseDir, fileName) {
1920
1783
  if (segments.some((segment) => segment === "..")) {
1921
1784
  throw new Error("Invalid log file path");
1922
1785
  }
1923
- const resolved = (0, import_node_path6.join)(baseDir, segments.join("/"));
1924
- const rel = (0, import_node_path6.relative)(baseDir, resolved);
1786
+ const resolved = (0, import_node_path5.join)(baseDir, segments.join("/"));
1787
+ const rel = (0, import_node_path5.relative)(baseDir, resolved);
1925
1788
  if (rel.startsWith("..")) {
1926
1789
  throw new Error("Access to the specified log file is denied");
1927
1790
  }
@@ -1950,12 +1813,12 @@ function serializeError(error) {
1950
1813
  __name(serializeError, "serializeError");
1951
1814
 
1952
1815
  // src/middlewares/dev-logs/controller.ts
1953
- var import_node_path8 = require("path");
1816
+ var import_node_path7 = require("path");
1954
1817
 
1955
1818
  // src/middlewares/dev-logs/services/file-reader.ts
1956
- var import_node_fs7 = require("fs");
1819
+ var import_node_fs6 = require("fs");
1957
1820
  async function readFileReverse(filePath, chunkSize, processLine) {
1958
- const handle = await import_node_fs7.promises.open(filePath, "r");
1821
+ const handle = await import_node_fs6.promises.open(filePath, "r");
1959
1822
  try {
1960
1823
  const stats = await handle.stat();
1961
1824
  let position = stats.size;
@@ -2137,7 +2000,7 @@ function parseStdLog(line, source) {
2137
2000
  __name(parseStdLog, "parseStdLog");
2138
2001
 
2139
2002
  // src/middlewares/dev-logs/services/trace.service.ts
2140
- var import_node_fs8 = require("fs");
2003
+ var import_node_fs7 = require("fs");
2141
2004
  var import_node_readline = require("readline");
2142
2005
  async function readLogEntriesByTrace(filePath, traceId, limit) {
2143
2006
  const exists = await fileExists(filePath);
@@ -2145,7 +2008,7 @@ async function readLogEntriesByTrace(filePath, traceId, limit) {
2145
2008
  return void 0;
2146
2009
  }
2147
2010
  const matches = [];
2148
- const stream = (0, import_node_fs8.createReadStream)(filePath, {
2011
+ const stream = (0, import_node_fs7.createReadStream)(filePath, {
2149
2012
  encoding: "utf8"
2150
2013
  });
2151
2014
  const rl = (0, import_node_readline.createInterface)({
@@ -2153,7 +2016,7 @@ async function readLogEntriesByTrace(filePath, traceId, limit) {
2153
2016
  crlfDelay: Infinity
2154
2017
  });
2155
2018
  for await (const line of rl) {
2156
- const entry = parseLogLine2(line);
2019
+ const entry = parseLogLine(line);
2157
2020
  if (!entry) continue;
2158
2021
  if (entry.trace_id !== traceId) continue;
2159
2022
  matches.push(entry);
@@ -2227,7 +2090,7 @@ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter, method
2227
2090
  }
2228
2091
  }, "processLogEntry");
2229
2092
  const processLine = /* @__PURE__ */ __name((line) => {
2230
- const entry = parseLogLine2(line);
2093
+ const entry = parseLogLine(line);
2231
2094
  if (entry?.trace_id) {
2232
2095
  processLogEntry(entry);
2233
2096
  }
@@ -2243,7 +2106,7 @@ async function readLogFilePage(filePath, page, pageSize) {
2243
2106
  const capacity = page * pageSize;
2244
2107
  const buffer = [];
2245
2108
  let totalLines = 0;
2246
- const stream = (0, import_node_fs8.createReadStream)(filePath, {
2109
+ const stream = (0, import_node_fs7.createReadStream)(filePath, {
2247
2110
  encoding: "utf8"
2248
2111
  });
2249
2112
  const rl = (0, import_node_readline.createInterface)({
@@ -2293,9 +2156,9 @@ async function readLogFilePage(filePath, page, pageSize) {
2293
2156
  __name(readLogFilePage, "readLogFilePage");
2294
2157
 
2295
2158
  // src/middlewares/dev-logs/services/server-log.service.ts
2296
- var import_node_fs9 = require("fs");
2159
+ var import_node_fs8 = require("fs");
2297
2160
  var import_node_readline2 = require("readline");
2298
- var import_node_path7 = require("path");
2161
+ var import_node_path6 = require("path");
2299
2162
  async function readServerLogs(logDir, options = {}) {
2300
2163
  const limit = options.limit || 100;
2301
2164
  const offset = options.offset || 0;
@@ -2341,16 +2204,16 @@ async function readLogsBySource(logDir, source) {
2341
2204
  let filePath;
2342
2205
  let parser;
2343
2206
  if (source === "server") {
2344
- filePath = (0, import_node_path7.join)(logDir, "server.log");
2207
+ filePath = (0, import_node_path6.join)(logDir, "server.log");
2345
2208
  parser = /* @__PURE__ */ __name((line) => parsePinoLog(line, "server"), "parser");
2346
2209
  } else if (source === "trace") {
2347
- filePath = (0, import_node_path7.join)(logDir, "trace.log");
2210
+ filePath = (0, import_node_path6.join)(logDir, "trace.log");
2348
2211
  parser = /* @__PURE__ */ __name((line) => parsePinoLog(line, "trace"), "parser");
2349
2212
  } else if (source === "server-std") {
2350
- filePath = (0, import_node_path7.join)(logDir, "server.std.log");
2213
+ filePath = (0, import_node_path6.join)(logDir, "server.std.log");
2351
2214
  parser = /* @__PURE__ */ __name((line) => parseStdLog(line, "server-std"), "parser");
2352
2215
  } else if (source === "client-std") {
2353
- filePath = (0, import_node_path7.join)(logDir, "client.std.log");
2216
+ filePath = (0, import_node_path6.join)(logDir, "client.std.log");
2354
2217
  parser = /* @__PURE__ */ __name((line) => parseStdLog(line, "client-std"), "parser");
2355
2218
  } else {
2356
2219
  console.warn(`[readLogsBySource] Unknown source: ${source}`);
@@ -2364,7 +2227,7 @@ async function readLogsBySource(logDir, source) {
2364
2227
  let stream = null;
2365
2228
  let rl = null;
2366
2229
  try {
2367
- stream = (0, import_node_fs9.createReadStream)(filePath, {
2230
+ stream = (0, import_node_fs8.createReadStream)(filePath, {
2368
2231
  encoding: "utf8"
2369
2232
  });
2370
2233
  rl = (0, import_node_readline2.createInterface)({
@@ -2397,9 +2260,9 @@ async function readLogsBySource(logDir, source) {
2397
2260
  __name(readLogsBySource, "readLogsBySource");
2398
2261
 
2399
2262
  // src/middlewares/dev-logs/services/trigger.service.ts
2400
- var import_node_fs10 = require("fs");
2263
+ var import_node_fs9 = require("fs");
2401
2264
  var import_node_readline3 = require("readline");
2402
- async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2265
+ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
2403
2266
  if (!await fileExists(filePath)) {
2404
2267
  return void 0;
2405
2268
  }
@@ -2425,7 +2288,7 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2425
2288
  if (alreadyAdded) {
2426
2289
  return false;
2427
2290
  }
2428
- const isAutomationTrigger = builder.path?.endsWith(path8);
2291
+ const isAutomationTrigger = builder.path?.endsWith(path7);
2429
2292
  if (!isAutomationTrigger) {
2430
2293
  return false;
2431
2294
  }
@@ -2484,7 +2347,7 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2484
2347
  }
2485
2348
  }, "processLogEntry");
2486
2349
  const processLine = /* @__PURE__ */ __name((line) => {
2487
- const entry = parseLogLine2(line);
2350
+ const entry = parseLogLine(line);
2488
2351
  if (entry?.trace_id) {
2489
2352
  processLogEntry(entry);
2490
2353
  }
@@ -2508,13 +2371,13 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2508
2371
  };
2509
2372
  }
2510
2373
  __name(readTriggerList, "readTriggerList");
2511
- async function readTriggerDetail(filePath, path8, instanceID) {
2374
+ async function readTriggerDetail(filePath, path7, instanceID) {
2512
2375
  const exists = await fileExists(filePath);
2513
2376
  if (!exists) {
2514
2377
  return void 0;
2515
2378
  }
2516
2379
  const matches = [];
2517
- const stream = (0, import_node_fs10.createReadStream)(filePath, {
2380
+ const stream = (0, import_node_fs9.createReadStream)(filePath, {
2518
2381
  encoding: "utf8"
2519
2382
  });
2520
2383
  const rl = (0, import_node_readline3.createInterface)({
@@ -2522,9 +2385,9 @@ async function readTriggerDetail(filePath, path8, instanceID) {
2522
2385
  crlfDelay: Infinity
2523
2386
  });
2524
2387
  for await (const line of rl) {
2525
- const entry = parseLogLine2(line);
2388
+ const entry = parseLogLine(line);
2526
2389
  if (!entry) continue;
2527
- const isAutomationTrigger = entry.path?.endsWith(path8);
2390
+ const isAutomationTrigger = entry.path?.endsWith(path7);
2528
2391
  const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
2529
2392
  if (!isAutomationTrigger || !hasInstanceID) continue;
2530
2393
  matches.push(entry);
@@ -2618,7 +2481,7 @@ async function readCapabilityTraceList(filePath, capabilityId, limit) {
2618
2481
  updateBuilderMetadata(builder, entry);
2619
2482
  }, "processLogEntry");
2620
2483
  const processLine = /* @__PURE__ */ __name((line) => {
2621
- const entry = parseLogLine2(line);
2484
+ const entry = parseLogLine(line);
2622
2485
  if (entry?.capability_id) {
2623
2486
  processLogEntry(entry);
2624
2487
  }
@@ -2665,7 +2528,7 @@ function handleError(res, error, message = "Failed to read log file") {
2665
2528
  }
2666
2529
  __name(handleError, "handleError");
2667
2530
  function createGetTraceEntriesHandler(logDir) {
2668
- const appLogPath = (0, import_node_path8.join)(logDir, "server.log");
2531
+ const appLogPath = (0, import_node_path7.join)(logDir, "server.log");
2669
2532
  return async (req, res) => {
2670
2533
  const traceId = (req.params.traceId || "").trim();
2671
2534
  if (!traceId) {
@@ -2692,7 +2555,7 @@ function createGetTraceEntriesHandler(logDir) {
2692
2555
  }
2693
2556
  __name(createGetTraceEntriesHandler, "createGetTraceEntriesHandler");
2694
2557
  function createGetRecentTracesHandler(logDir) {
2695
- const traceLogPath = (0, import_node_path8.join)(logDir, "trace.log");
2558
+ const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
2696
2559
  return async (req, res) => {
2697
2560
  const page = parsePositiveInt(req.query.page, 1);
2698
2561
  const pageSize = parseLimit(req.query.pageSize, 10, 100);
@@ -2769,7 +2632,7 @@ function createGetServerLogsHandler(logDir) {
2769
2632
  }
2770
2633
  __name(createGetServerLogsHandler, "createGetServerLogsHandler");
2771
2634
  function createGetTriggerListHandler(logDir) {
2772
- const traceLogPath = (0, import_node_path8.join)(logDir, "trace.log");
2635
+ const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
2773
2636
  return async (req, res) => {
2774
2637
  const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
2775
2638
  if (!trigger) {
@@ -2778,16 +2641,16 @@ function createGetTriggerListHandler(logDir) {
2778
2641
  });
2779
2642
  }
2780
2643
  const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
2781
- const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2644
+ const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2782
2645
  const limit = parseLimit(req.query.limit, 10, 200);
2783
2646
  try {
2784
- const result = await readTriggerList(traceLogPath, trigger, path8, limit, triggerID);
2647
+ const result = await readTriggerList(traceLogPath, trigger, path7, limit, triggerID);
2785
2648
  if (!result) {
2786
2649
  return handleNotFound(res, traceLogPath);
2787
2650
  }
2788
2651
  res.json({
2789
2652
  file: getRelativePath(traceLogPath),
2790
- path: path8,
2653
+ path: path7,
2791
2654
  ...result
2792
2655
  });
2793
2656
  } catch (error) {
@@ -2797,7 +2660,7 @@ function createGetTriggerListHandler(logDir) {
2797
2660
  }
2798
2661
  __name(createGetTriggerListHandler, "createGetTriggerListHandler");
2799
2662
  function createGetTriggerDetailHandler(logDir) {
2800
- const traceLogPath = (0, import_node_path8.join)(logDir, "server.log");
2663
+ const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
2801
2664
  return async (req, res) => {
2802
2665
  const instanceID = (req.params.instanceID || "").trim();
2803
2666
  if (!instanceID) {
@@ -2805,9 +2668,9 @@ function createGetTriggerDetailHandler(logDir) {
2805
2668
  message: "instanceID is required"
2806
2669
  });
2807
2670
  }
2808
- const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2671
+ const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2809
2672
  try {
2810
- const result = await readTriggerDetail(traceLogPath, path8, instanceID);
2673
+ const result = await readTriggerDetail(traceLogPath, path7, instanceID);
2811
2674
  if (!result) {
2812
2675
  return handleNotFound(res, traceLogPath);
2813
2676
  }
@@ -2822,7 +2685,7 @@ function createGetTriggerDetailHandler(logDir) {
2822
2685
  }
2823
2686
  __name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
2824
2687
  function createGetCapabilityTraceListHandler(logDir) {
2825
- const serverLogPath = (0, import_node_path8.join)(logDir, "server.log");
2688
+ const serverLogPath = (0, import_node_path7.join)(logDir, "server.log");
2826
2689
  return async (req, res) => {
2827
2690
  const capabilityId = typeof req.query.capability_id === "string" ? req.query.capability_id.trim() : void 0;
2828
2691
  if (!capabilityId) {
@@ -2848,11 +2711,11 @@ function createGetCapabilityTraceListHandler(logDir) {
2848
2711
  __name(createGetCapabilityTraceListHandler, "createGetCapabilityTraceListHandler");
2849
2712
 
2850
2713
  // src/middlewares/dev-logs/health.controller.ts
2851
- var import_node_http2 = __toESM(require("http"), 1);
2714
+ var import_node_http = __toESM(require("http"), 1);
2852
2715
  function checkServiceHealth(host, port, timeout) {
2853
2716
  return new Promise((resolve) => {
2854
2717
  const startTime = Date.now();
2855
- const req = import_node_http2.default.request({
2718
+ const req = import_node_http.default.request({
2856
2719
  hostname: host,
2857
2720
  port,
2858
2721
  path: "/",
@@ -2915,8 +2778,8 @@ function createHealthCheckHandler(options = {}) {
2915
2778
  __name(createHealthCheckHandler, "createHealthCheckHandler");
2916
2779
 
2917
2780
  // src/middlewares/dev-logs/sse/log-watcher.ts
2918
- var fs9 = __toESM(require("fs"), 1);
2919
- var path6 = __toESM(require("path"), 1);
2781
+ var fs8 = __toESM(require("fs"), 1);
2782
+ var path5 = __toESM(require("path"), 1);
2920
2783
  function mapPinoLevelToServerLogLevel2(pinoLevel) {
2921
2784
  if (typeof pinoLevel === "string") {
2922
2785
  const lower = pinoLevel.toLowerCase();
@@ -3131,13 +2994,13 @@ var LogWatcher = class {
3131
2994
  * Watch a single log file
3132
2995
  */
3133
2996
  watchFile(config) {
3134
- const filePath = path6.join(this.logDir, config.fileName);
3135
- if (!fs9.existsSync(filePath)) {
2997
+ const filePath = path5.join(this.logDir, config.fileName);
2998
+ if (!fs8.existsSync(filePath)) {
3136
2999
  this.log(`File not found, skipping: ${config.fileName}`);
3137
3000
  return;
3138
3001
  }
3139
3002
  try {
3140
- const stats = fs9.statSync(filePath);
3003
+ const stats = fs8.statSync(filePath);
3141
3004
  this.filePositions.set(config.fileName, stats.size);
3142
3005
  this.log(`Initialized position for ${config.fileName}: ${stats.size} bytes`);
3143
3006
  } catch (error) {
@@ -3145,7 +3008,7 @@ var LogWatcher = class {
3145
3008
  this.filePositions.set(config.fileName, 0);
3146
3009
  }
3147
3010
  try {
3148
- const watcher = fs9.watch(filePath, (eventType) => {
3011
+ const watcher = fs8.watch(filePath, (eventType) => {
3149
3012
  if (eventType === "change") {
3150
3013
  this.handleFileChange(config);
3151
3014
  }
@@ -3180,10 +3043,10 @@ var LogWatcher = class {
3180
3043
  * Handle file change event - read new content
3181
3044
  */
3182
3045
  handleFileChange(config) {
3183
- const filePath = path6.join(this.logDir, config.fileName);
3046
+ const filePath = path5.join(this.logDir, config.fileName);
3184
3047
  const lastPosition = this.filePositions.get(config.fileName) || 0;
3185
3048
  try {
3186
- const stats = fs9.statSync(filePath);
3049
+ const stats = fs8.statSync(filePath);
3187
3050
  const currentSize = stats.size;
3188
3051
  if (currentSize < lastPosition) {
3189
3052
  this.log(`File ${config.fileName} was truncated, resetting position`);
@@ -3196,11 +3059,11 @@ var LogWatcher = class {
3196
3059
  }
3197
3060
  const readSize = currentSize - lastPosition;
3198
3061
  const buffer = Buffer.alloc(readSize);
3199
- const fd = fs9.openSync(filePath, "r");
3062
+ const fd = fs8.openSync(filePath, "r");
3200
3063
  try {
3201
- fs9.readSync(fd, buffer, 0, readSize, lastPosition);
3064
+ fs8.readSync(fd, buffer, 0, readSize, lastPosition);
3202
3065
  } finally {
3203
- fs9.closeSync(fd);
3066
+ fs8.closeSync(fd);
3204
3067
  }
3205
3068
  this.filePositions.set(config.fileName, currentSize);
3206
3069
  const content = buffer.toString("utf8");
@@ -3503,18 +3366,18 @@ var import_path2 = require("path");
3503
3366
  var import_fs2 = __toESM(require("fs"), 1);
3504
3367
 
3505
3368
  // src/middlewares/collect-logs/utils.ts
3506
- var import_node_path9 = require("path");
3507
- var import_node_fs11 = __toESM(require("fs"), 1);
3369
+ var import_node_path8 = require("path");
3370
+ var import_node_fs10 = __toESM(require("fs"), 1);
3508
3371
  function resolveLogDir2(provided) {
3509
3372
  if (!provided) {
3510
- return (0, import_node_path9.join)(process.cwd(), "logs");
3373
+ return (0, import_node_path8.join)(process.cwd(), "logs");
3511
3374
  }
3512
- return (0, import_node_path9.isAbsolute)(provided) ? provided : (0, import_node_path9.join)(process.cwd(), provided);
3375
+ return (0, import_node_path8.isAbsolute)(provided) ? provided : (0, import_node_path8.join)(process.cwd(), provided);
3513
3376
  }
3514
3377
  __name(resolveLogDir2, "resolveLogDir");
3515
3378
  function ensureDir(dir) {
3516
- if (!import_node_fs11.default.existsSync(dir)) {
3517
- import_node_fs11.default.mkdirSync(dir, {
3379
+ if (!import_node_fs10.default.existsSync(dir)) {
3380
+ import_node_fs10.default.mkdirSync(dir, {
3518
3381
  recursive: true
3519
3382
  });
3520
3383
  }
@@ -3637,7 +3500,7 @@ function isGlobalMiddleware(middleware) {
3637
3500
  }
3638
3501
  __name(isGlobalMiddleware, "isGlobalMiddleware");
3639
3502
  function computeMountPath(basePath, mountPath) {
3640
- const routePath = import_node_path10.default.posix.join(basePath, mountPath);
3503
+ const routePath = import_node_path9.default.posix.join(basePath, mountPath);
3641
3504
  return routePath.startsWith("/") ? routePath : `/${routePath}`;
3642
3505
  }
3643
3506
  __name(computeMountPath, "computeMountPath");
@@ -3645,7 +3508,7 @@ function logMiddlewareRegistration(middleware, fullMountPath) {
3645
3508
  if (middleware.routes && middleware.routes.length > 0) {
3646
3509
  console.log(`[Middleware] Registered: ${middleware.name} at ${fullMountPath}`);
3647
3510
  middleware.routes.forEach((route) => {
3648
- const routePath = route.path === "/" ? fullMountPath : import_node_path10.default.posix.join(fullMountPath, route.path);
3511
+ const routePath = route.path === "/" ? fullMountPath : import_node_path9.default.posix.join(fullMountPath, route.path);
3649
3512
  console.log(` ${route.method} ${routePath} - ${route.description}`);
3650
3513
  });
3651
3514
  } else {