@lark-apaas/devtool-kits 1.2.7 → 1.2.8-alpha.1
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
|
@@ -2359,6 +2359,144 @@ function generateUUID() {
|
|
|
2359
2359
|
});
|
|
2360
2360
|
}
|
|
2361
2361
|
__name(generateUUID, "generateUUID");
|
|
2362
|
+
async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
2363
|
+
if (!await fileExists(filePath)) {
|
|
2364
|
+
return void 0;
|
|
2365
|
+
}
|
|
2366
|
+
const config = {
|
|
2367
|
+
maxEntriesPerTrace: 10,
|
|
2368
|
+
chunkSize: 64 * 1024
|
|
2369
|
+
};
|
|
2370
|
+
const builders = /* @__PURE__ */ new Map();
|
|
2371
|
+
const completedCalls = [];
|
|
2372
|
+
const createTraceBuilder = /* @__PURE__ */ __name((traceId) => ({
|
|
2373
|
+
traceId,
|
|
2374
|
+
entries: [],
|
|
2375
|
+
method: void 0,
|
|
2376
|
+
path: void 0,
|
|
2377
|
+
startTime: void 0,
|
|
2378
|
+
endTime: void 0,
|
|
2379
|
+
statusCode: void 0,
|
|
2380
|
+
durationMs: void 0,
|
|
2381
|
+
hasCompleted: false
|
|
2382
|
+
}), "createTraceBuilder");
|
|
2383
|
+
const shouldIncludeInCompletedCalls = /* @__PURE__ */ __name((builder) => {
|
|
2384
|
+
const alreadyAdded = completedCalls.some((call) => call.traceId === builder.traceId);
|
|
2385
|
+
if (alreadyAdded) {
|
|
2386
|
+
return false;
|
|
2387
|
+
}
|
|
2388
|
+
const isAutomationTrigger = builder.path?.endsWith(path7);
|
|
2389
|
+
if (!isAutomationTrigger) {
|
|
2390
|
+
return false;
|
|
2391
|
+
}
|
|
2392
|
+
if (trigger && builder.entries.length > 0) {
|
|
2393
|
+
const requestEntry = builder.entries.find((e) => e.request_body?.trigger);
|
|
2394
|
+
if (requestEntry?.request_body?.trigger) {
|
|
2395
|
+
return String(requestEntry.request_body.trigger) === trigger && (triggerID ? requestEntry?.request_body?.triggerID === triggerID : true);
|
|
2396
|
+
}
|
|
2397
|
+
return false;
|
|
2398
|
+
}
|
|
2399
|
+
return true;
|
|
2400
|
+
}, "shouldIncludeInCompletedCalls");
|
|
2401
|
+
const updateBuilderMetadata = /* @__PURE__ */ __name((builder, entry) => {
|
|
2402
|
+
if (entry.method && !builder.method) builder.method = String(entry.method);
|
|
2403
|
+
if (entry.path && !builder.path) builder.path = String(entry.path);
|
|
2404
|
+
builder.entries.push(entry);
|
|
2405
|
+
if (builder.entries.length > config.maxEntriesPerTrace) {
|
|
2406
|
+
builder.entries.shift();
|
|
2407
|
+
}
|
|
2408
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2409
|
+
completedCalls.push(builder);
|
|
2410
|
+
if (limit && completedCalls.length > limit) {
|
|
2411
|
+
completedCalls.pop();
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
}, "updateBuilderMetadata");
|
|
2415
|
+
const handleRequestCompleted = /* @__PURE__ */ __name((builder, entry, message) => {
|
|
2416
|
+
builder.hasCompleted = true;
|
|
2417
|
+
builder.endTime = entry.time;
|
|
2418
|
+
builder.statusCode = extractNumber(message, /status_code:\s*(\d+)/);
|
|
2419
|
+
builder.durationMs = extractNumber(message, /duration_ms:\s*(\d+)/);
|
|
2420
|
+
if (!builder.path && entry.path) {
|
|
2421
|
+
builder.path = String(entry.path);
|
|
2422
|
+
}
|
|
2423
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2424
|
+
completedCalls.push(builder);
|
|
2425
|
+
if (limit && completedCalls.length > limit) {
|
|
2426
|
+
completedCalls.pop();
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}, "handleRequestCompleted");
|
|
2430
|
+
const processLogEntry = /* @__PURE__ */ __name((entry) => {
|
|
2431
|
+
const { trace_id: traceId, message = "" } = entry;
|
|
2432
|
+
if (!traceId) return;
|
|
2433
|
+
let builder = builders.get(traceId);
|
|
2434
|
+
if (!builder) {
|
|
2435
|
+
builder = createTraceBuilder(traceId);
|
|
2436
|
+
builders.set(traceId, builder);
|
|
2437
|
+
}
|
|
2438
|
+
updateBuilderMetadata(builder, entry);
|
|
2439
|
+
if (!builder.hasCompleted && (message.includes("HTTP request completed") || message.includes("HTTP request failed"))) {
|
|
2440
|
+
handleRequestCompleted(builder, entry, message);
|
|
2441
|
+
}
|
|
2442
|
+
if (message.includes("HTTP request started") && !builder.startTime) {
|
|
2443
|
+
builder.startTime = entry.time;
|
|
2444
|
+
}
|
|
2445
|
+
}, "processLogEntry");
|
|
2446
|
+
const processLine = /* @__PURE__ */ __name((line) => {
|
|
2447
|
+
const entry = parseLogLine2(line);
|
|
2448
|
+
if (entry?.trace_id) {
|
|
2449
|
+
processLogEntry(entry);
|
|
2450
|
+
}
|
|
2451
|
+
}, "processLine");
|
|
2452
|
+
await readFileReverse(filePath, config.chunkSize, processLine);
|
|
2453
|
+
return {
|
|
2454
|
+
page: 1,
|
|
2455
|
+
pageSize: completedCalls.length,
|
|
2456
|
+
totalCalls: completedCalls.length,
|
|
2457
|
+
totalPages: 1,
|
|
2458
|
+
calls: completedCalls.map((builder) => ({
|
|
2459
|
+
traceId: builder.traceId,
|
|
2460
|
+
method: builder.method,
|
|
2461
|
+
path: builder.path,
|
|
2462
|
+
startTime: builder.startTime,
|
|
2463
|
+
endTime: builder.endTime,
|
|
2464
|
+
statusCode: builder.statusCode,
|
|
2465
|
+
durationMs: builder.durationMs,
|
|
2466
|
+
entries: builder.entries.slice().reverse()
|
|
2467
|
+
}))
|
|
2468
|
+
};
|
|
2469
|
+
}
|
|
2470
|
+
__name(readTriggerList, "readTriggerList");
|
|
2471
|
+
async function readTriggerDetail(filePath, path7, instanceID) {
|
|
2472
|
+
const exists = await fileExists(filePath);
|
|
2473
|
+
if (!exists) {
|
|
2474
|
+
return void 0;
|
|
2475
|
+
}
|
|
2476
|
+
const matches = [];
|
|
2477
|
+
const stream = (0, import_node_fs7.createReadStream)(filePath, {
|
|
2478
|
+
encoding: "utf8"
|
|
2479
|
+
});
|
|
2480
|
+
const rl = (0, import_node_readline.createInterface)({
|
|
2481
|
+
input: stream,
|
|
2482
|
+
crlfDelay: Infinity
|
|
2483
|
+
});
|
|
2484
|
+
for await (const line of rl) {
|
|
2485
|
+
const entry = parseLogLine2(line);
|
|
2486
|
+
if (!entry) continue;
|
|
2487
|
+
const isAutomationTrigger = entry.path?.endsWith(path7);
|
|
2488
|
+
const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
|
|
2489
|
+
if (!isAutomationTrigger || !hasInstanceID) continue;
|
|
2490
|
+
matches.push(entry);
|
|
2491
|
+
}
|
|
2492
|
+
rl.close();
|
|
2493
|
+
stream.close();
|
|
2494
|
+
return {
|
|
2495
|
+
instanceID,
|
|
2496
|
+
entries: matches
|
|
2497
|
+
};
|
|
2498
|
+
}
|
|
2499
|
+
__name(readTriggerDetail, "readTriggerDetail");
|
|
2362
2500
|
|
|
2363
2501
|
// src/middlewares/dev-logs/controller.ts
|
|
2364
2502
|
function handleNotFound(res, filePath, message = "Log file not found") {
|
|
@@ -2478,6 +2616,59 @@ function createGetServerLogsHandler(logDir) {
|
|
|
2478
2616
|
};
|
|
2479
2617
|
}
|
|
2480
2618
|
__name(createGetServerLogsHandler, "createGetServerLogsHandler");
|
|
2619
|
+
function createGetTriggerListHandler(logDir) {
|
|
2620
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
|
|
2621
|
+
return async (req, res) => {
|
|
2622
|
+
const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
|
|
2623
|
+
if (!trigger) {
|
|
2624
|
+
return res.status(400).json({
|
|
2625
|
+
message: "trigger is required"
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
|
|
2629
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2630
|
+
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2631
|
+
try {
|
|
2632
|
+
const result = await readTriggerList(traceLogPath, trigger, path7, limit, triggerID);
|
|
2633
|
+
if (!result) {
|
|
2634
|
+
return handleNotFound(res, traceLogPath);
|
|
2635
|
+
}
|
|
2636
|
+
res.json({
|
|
2637
|
+
file: getRelativePath(traceLogPath),
|
|
2638
|
+
path: path7,
|
|
2639
|
+
...result
|
|
2640
|
+
});
|
|
2641
|
+
} catch (error) {
|
|
2642
|
+
handleError(res, error, "Failed to read trace log");
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
}
|
|
2646
|
+
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2647
|
+
function createGetTriggerDetailHandler(logDir) {
|
|
2648
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2649
|
+
return async (req, res) => {
|
|
2650
|
+
const instanceID = (req.params.instanceID || "").trim();
|
|
2651
|
+
if (!instanceID) {
|
|
2652
|
+
return res.status(400).json({
|
|
2653
|
+
message: "instanceID is required"
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2656
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2657
|
+
try {
|
|
2658
|
+
const result = await readTriggerDetail(traceLogPath, path7, instanceID);
|
|
2659
|
+
if (!result) {
|
|
2660
|
+
return handleNotFound(res, traceLogPath);
|
|
2661
|
+
}
|
|
2662
|
+
res.json({
|
|
2663
|
+
file: getRelativePath(traceLogPath),
|
|
2664
|
+
...result
|
|
2665
|
+
});
|
|
2666
|
+
} catch (error) {
|
|
2667
|
+
handleError(res, error, "Failed to read trace log");
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2671
|
+
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2481
2672
|
|
|
2482
2673
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2483
2674
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2554,6 +2745,8 @@ function createDevLogRouter(options = {}) {
|
|
|
2554
2745
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2555
2746
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2556
2747
|
router.get("/server-logs", createGetServerLogsHandler(logDir));
|
|
2748
|
+
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2749
|
+
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2557
2750
|
router.get("/health", createHealthCheckHandler());
|
|
2558
2751
|
return router;
|
|
2559
2752
|
}
|
|
@@ -2580,6 +2773,16 @@ var DEV_LOGS_ROUTES = [
|
|
|
2580
2773
|
method: "GET",
|
|
2581
2774
|
path: "/server-logs",
|
|
2582
2775
|
description: "Get server logs in ServerLog format (compatible with frontend)"
|
|
2776
|
+
},
|
|
2777
|
+
{
|
|
2778
|
+
method: "GET",
|
|
2779
|
+
path: "/trace/trigger/list",
|
|
2780
|
+
description: "Get trigger list (automation trigger) in trace.log"
|
|
2781
|
+
},
|
|
2782
|
+
{
|
|
2783
|
+
method: "GET",
|
|
2784
|
+
path: "/trace/trigger/:instanceID",
|
|
2785
|
+
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2583
2786
|
}
|
|
2584
2787
|
];
|
|
2585
2788
|
function createDevLogsMiddleware(options = {}) {
|