@lark-apaas/devtool-kits 1.2.7 → 1.2.8-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 +202 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +202 -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) {
|
|
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;
|
|
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,58 @@ 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 path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2629
|
+
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2630
|
+
try {
|
|
2631
|
+
const result = await readTriggerList(traceLogPath, trigger, path7, limit);
|
|
2632
|
+
if (!result) {
|
|
2633
|
+
return handleNotFound(res, traceLogPath);
|
|
2634
|
+
}
|
|
2635
|
+
res.json({
|
|
2636
|
+
file: getRelativePath(traceLogPath),
|
|
2637
|
+
path: path7,
|
|
2638
|
+
...result
|
|
2639
|
+
});
|
|
2640
|
+
} catch (error) {
|
|
2641
|
+
handleError(res, error, "Failed to read trace log");
|
|
2642
|
+
}
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2646
|
+
function createGetTriggerDetailHandler(logDir) {
|
|
2647
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2648
|
+
return async (req, res) => {
|
|
2649
|
+
const instanceID = (req.params.instanceID || "").trim();
|
|
2650
|
+
if (!instanceID) {
|
|
2651
|
+
return res.status(400).json({
|
|
2652
|
+
message: "instanceID is required"
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2656
|
+
try {
|
|
2657
|
+
const result = await readTriggerDetail(traceLogPath, path7, instanceID);
|
|
2658
|
+
if (!result) {
|
|
2659
|
+
return handleNotFound(res, traceLogPath);
|
|
2660
|
+
}
|
|
2661
|
+
res.json({
|
|
2662
|
+
file: getRelativePath(traceLogPath),
|
|
2663
|
+
...result
|
|
2664
|
+
});
|
|
2665
|
+
} catch (error) {
|
|
2666
|
+
handleError(res, error, "Failed to read trace log");
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2481
2671
|
|
|
2482
2672
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2483
2673
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2554,6 +2744,8 @@ function createDevLogRouter(options = {}) {
|
|
|
2554
2744
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2555
2745
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2556
2746
|
router.get("/server-logs", createGetServerLogsHandler(logDir));
|
|
2747
|
+
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2748
|
+
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2557
2749
|
router.get("/health", createHealthCheckHandler());
|
|
2558
2750
|
return router;
|
|
2559
2751
|
}
|
|
@@ -2580,6 +2772,16 @@ var DEV_LOGS_ROUTES = [
|
|
|
2580
2772
|
method: "GET",
|
|
2581
2773
|
path: "/server-logs",
|
|
2582
2774
|
description: "Get server logs in ServerLog format (compatible with frontend)"
|
|
2775
|
+
},
|
|
2776
|
+
{
|
|
2777
|
+
method: "GET",
|
|
2778
|
+
path: "/trace/trigger/list",
|
|
2779
|
+
description: "Get trigger list (automation trigger) in trace.log"
|
|
2780
|
+
},
|
|
2781
|
+
{
|
|
2782
|
+
method: "GET",
|
|
2783
|
+
path: "/trace/trigger/:instanceID",
|
|
2784
|
+
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2583
2785
|
}
|
|
2584
2786
|
];
|
|
2585
2787
|
function createDevLogsMiddleware(options = {}) {
|