@lark-apaas/devtool-kits 1.2.9 → 1.2.10-alpha.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 +203 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2385,6 +2385,144 @@ function generateUUID() {
|
|
|
2385
2385
|
});
|
|
2386
2386
|
}
|
|
2387
2387
|
__name(generateUUID, "generateUUID");
|
|
2388
|
+
async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
2389
|
+
if (!await fileExists(filePath)) {
|
|
2390
|
+
return void 0;
|
|
2391
|
+
}
|
|
2392
|
+
const config = {
|
|
2393
|
+
maxEntriesPerTrace: 10,
|
|
2394
|
+
chunkSize: 64 * 1024
|
|
2395
|
+
};
|
|
2396
|
+
const builders = /* @__PURE__ */ new Map();
|
|
2397
|
+
const completedCalls = [];
|
|
2398
|
+
const createTraceBuilder = /* @__PURE__ */ __name((traceId) => ({
|
|
2399
|
+
traceId,
|
|
2400
|
+
entries: [],
|
|
2401
|
+
method: void 0,
|
|
2402
|
+
path: void 0,
|
|
2403
|
+
startTime: void 0,
|
|
2404
|
+
endTime: void 0,
|
|
2405
|
+
statusCode: void 0,
|
|
2406
|
+
durationMs: void 0,
|
|
2407
|
+
hasCompleted: false
|
|
2408
|
+
}), "createTraceBuilder");
|
|
2409
|
+
const shouldIncludeInCompletedCalls = /* @__PURE__ */ __name((builder) => {
|
|
2410
|
+
const alreadyAdded = completedCalls.some((call) => call.traceId === builder.traceId);
|
|
2411
|
+
if (alreadyAdded) {
|
|
2412
|
+
return false;
|
|
2413
|
+
}
|
|
2414
|
+
const isAutomationTrigger = builder.path?.endsWith(path7);
|
|
2415
|
+
if (!isAutomationTrigger) {
|
|
2416
|
+
return false;
|
|
2417
|
+
}
|
|
2418
|
+
if (trigger && builder.entries.length > 0) {
|
|
2419
|
+
const requestEntry = builder.entries.find((e) => e.request_body?.trigger);
|
|
2420
|
+
if (requestEntry?.request_body?.trigger) {
|
|
2421
|
+
return String(requestEntry.request_body.trigger) === trigger && (triggerID ? requestEntry?.request_body?.triggerID === triggerID : true);
|
|
2422
|
+
}
|
|
2423
|
+
return false;
|
|
2424
|
+
}
|
|
2425
|
+
return true;
|
|
2426
|
+
}, "shouldIncludeInCompletedCalls");
|
|
2427
|
+
const updateBuilderMetadata = /* @__PURE__ */ __name((builder, entry) => {
|
|
2428
|
+
if (entry.method && !builder.method) builder.method = String(entry.method);
|
|
2429
|
+
if (entry.path && !builder.path) builder.path = String(entry.path);
|
|
2430
|
+
builder.entries.push(entry);
|
|
2431
|
+
if (builder.entries.length > config.maxEntriesPerTrace) {
|
|
2432
|
+
builder.entries.shift();
|
|
2433
|
+
}
|
|
2434
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2435
|
+
completedCalls.push(builder);
|
|
2436
|
+
if (limit && completedCalls.length > limit) {
|
|
2437
|
+
completedCalls.pop();
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
}, "updateBuilderMetadata");
|
|
2441
|
+
const handleRequestCompleted = /* @__PURE__ */ __name((builder, entry, message) => {
|
|
2442
|
+
builder.hasCompleted = true;
|
|
2443
|
+
builder.endTime = entry.time;
|
|
2444
|
+
builder.statusCode = extractNumber(message, /status_code:\s*(\d+)/);
|
|
2445
|
+
builder.durationMs = extractNumber(message, /duration_ms:\s*(\d+)/);
|
|
2446
|
+
if (!builder.path && entry.path) {
|
|
2447
|
+
builder.path = String(entry.path);
|
|
2448
|
+
}
|
|
2449
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2450
|
+
completedCalls.push(builder);
|
|
2451
|
+
if (limit && completedCalls.length > limit) {
|
|
2452
|
+
completedCalls.pop();
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}, "handleRequestCompleted");
|
|
2456
|
+
const processLogEntry = /* @__PURE__ */ __name((entry) => {
|
|
2457
|
+
const { trace_id: traceId, message = "" } = entry;
|
|
2458
|
+
if (!traceId) return;
|
|
2459
|
+
let builder = builders.get(traceId);
|
|
2460
|
+
if (!builder) {
|
|
2461
|
+
builder = createTraceBuilder(traceId);
|
|
2462
|
+
builders.set(traceId, builder);
|
|
2463
|
+
}
|
|
2464
|
+
updateBuilderMetadata(builder, entry);
|
|
2465
|
+
if (!builder.hasCompleted && (message.includes("HTTP request completed") || message.includes("HTTP request failed"))) {
|
|
2466
|
+
handleRequestCompleted(builder, entry, message);
|
|
2467
|
+
}
|
|
2468
|
+
if (message.includes("HTTP request started") && !builder.startTime) {
|
|
2469
|
+
builder.startTime = entry.time;
|
|
2470
|
+
}
|
|
2471
|
+
}, "processLogEntry");
|
|
2472
|
+
const processLine = /* @__PURE__ */ __name((line) => {
|
|
2473
|
+
const entry = parseLogLine2(line);
|
|
2474
|
+
if (entry?.trace_id) {
|
|
2475
|
+
processLogEntry(entry);
|
|
2476
|
+
}
|
|
2477
|
+
}, "processLine");
|
|
2478
|
+
await readFileReverse(filePath, config.chunkSize, processLine);
|
|
2479
|
+
return {
|
|
2480
|
+
page: 1,
|
|
2481
|
+
pageSize: completedCalls.length,
|
|
2482
|
+
totalCalls: completedCalls.length,
|
|
2483
|
+
totalPages: 1,
|
|
2484
|
+
calls: completedCalls.map((builder) => ({
|
|
2485
|
+
traceId: builder.traceId,
|
|
2486
|
+
method: builder.method,
|
|
2487
|
+
path: builder.path,
|
|
2488
|
+
startTime: builder.startTime,
|
|
2489
|
+
endTime: builder.endTime,
|
|
2490
|
+
statusCode: builder.statusCode,
|
|
2491
|
+
durationMs: builder.durationMs,
|
|
2492
|
+
entries: builder.entries.slice().reverse()
|
|
2493
|
+
}))
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
__name(readTriggerList, "readTriggerList");
|
|
2497
|
+
async function readTriggerDetail(filePath, path7, instanceID) {
|
|
2498
|
+
const exists = await fileExists(filePath);
|
|
2499
|
+
if (!exists) {
|
|
2500
|
+
return void 0;
|
|
2501
|
+
}
|
|
2502
|
+
const matches = [];
|
|
2503
|
+
const stream = (0, import_node_fs7.createReadStream)(filePath, {
|
|
2504
|
+
encoding: "utf8"
|
|
2505
|
+
});
|
|
2506
|
+
const rl = (0, import_node_readline.createInterface)({
|
|
2507
|
+
input: stream,
|
|
2508
|
+
crlfDelay: Infinity
|
|
2509
|
+
});
|
|
2510
|
+
for await (const line of rl) {
|
|
2511
|
+
const entry = parseLogLine2(line);
|
|
2512
|
+
if (!entry) continue;
|
|
2513
|
+
const isAutomationTrigger = entry.path?.endsWith(path7);
|
|
2514
|
+
const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
|
|
2515
|
+
if (!isAutomationTrigger || !hasInstanceID) continue;
|
|
2516
|
+
matches.push(entry);
|
|
2517
|
+
}
|
|
2518
|
+
rl.close();
|
|
2519
|
+
stream.close();
|
|
2520
|
+
return {
|
|
2521
|
+
instanceID,
|
|
2522
|
+
entries: matches
|
|
2523
|
+
};
|
|
2524
|
+
}
|
|
2525
|
+
__name(readTriggerDetail, "readTriggerDetail");
|
|
2388
2526
|
|
|
2389
2527
|
// src/middlewares/dev-logs/controller.ts
|
|
2390
2528
|
function handleNotFound(res, filePath, message = "Log file not found") {
|
|
@@ -2504,6 +2642,59 @@ function createGetServerLogsHandler(logDir) {
|
|
|
2504
2642
|
};
|
|
2505
2643
|
}
|
|
2506
2644
|
__name(createGetServerLogsHandler, "createGetServerLogsHandler");
|
|
2645
|
+
function createGetTriggerListHandler(logDir) {
|
|
2646
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
|
|
2647
|
+
return async (req, res) => {
|
|
2648
|
+
const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
|
|
2649
|
+
if (!trigger) {
|
|
2650
|
+
return res.status(400).json({
|
|
2651
|
+
message: "trigger is required"
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
|
|
2655
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2656
|
+
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2657
|
+
try {
|
|
2658
|
+
const result = await readTriggerList(traceLogPath, trigger, path7, limit, triggerID);
|
|
2659
|
+
if (!result) {
|
|
2660
|
+
return handleNotFound(res, traceLogPath);
|
|
2661
|
+
}
|
|
2662
|
+
res.json({
|
|
2663
|
+
file: getRelativePath(traceLogPath),
|
|
2664
|
+
path: path7,
|
|
2665
|
+
...result
|
|
2666
|
+
});
|
|
2667
|
+
} catch (error) {
|
|
2668
|
+
handleError(res, error, "Failed to read trace log");
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
}
|
|
2672
|
+
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2673
|
+
function createGetTriggerDetailHandler(logDir) {
|
|
2674
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2675
|
+
return async (req, res) => {
|
|
2676
|
+
const instanceID = (req.params.instanceID || "").trim();
|
|
2677
|
+
if (!instanceID) {
|
|
2678
|
+
return res.status(400).json({
|
|
2679
|
+
message: "instanceID is required"
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2682
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2683
|
+
try {
|
|
2684
|
+
const result = await readTriggerDetail(traceLogPath, path7, instanceID);
|
|
2685
|
+
if (!result) {
|
|
2686
|
+
return handleNotFound(res, traceLogPath);
|
|
2687
|
+
}
|
|
2688
|
+
res.json({
|
|
2689
|
+
file: getRelativePath(traceLogPath),
|
|
2690
|
+
...result
|
|
2691
|
+
});
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
handleError(res, error, "Failed to read trace log");
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2696
|
+
}
|
|
2697
|
+
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2507
2698
|
|
|
2508
2699
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2509
2700
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2580,6 +2771,8 @@ function createDevLogRouter(options = {}) {
|
|
|
2580
2771
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2581
2772
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2582
2773
|
router.get("/server-logs", createGetServerLogsHandler(logDir));
|
|
2774
|
+
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2775
|
+
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2583
2776
|
router.get("/health", createHealthCheckHandler());
|
|
2584
2777
|
return router;
|
|
2585
2778
|
}
|
|
@@ -2606,6 +2799,16 @@ var DEV_LOGS_ROUTES = [
|
|
|
2606
2799
|
method: "GET",
|
|
2607
2800
|
path: "/server-logs",
|
|
2608
2801
|
description: "Get server logs in ServerLog format (compatible with frontend)"
|
|
2802
|
+
},
|
|
2803
|
+
{
|
|
2804
|
+
method: "GET",
|
|
2805
|
+
path: "/trace/trigger/list",
|
|
2806
|
+
description: "Get trigger list (automation trigger) in trace.log"
|
|
2807
|
+
},
|
|
2808
|
+
{
|
|
2809
|
+
method: "GET",
|
|
2810
|
+
path: "/trace/trigger/:instanceID",
|
|
2811
|
+
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2609
2812
|
}
|
|
2610
2813
|
];
|
|
2611
2814
|
function createDevLogsMiddleware(options = {}) {
|