@lark-apaas/devtool-kits 1.2.5-alpha.0 → 1.2.5-alpha.2
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
|
@@ -2136,6 +2136,146 @@ async function readLogFilePage(filePath, page, pageSize) {
|
|
|
2136
2136
|
};
|
|
2137
2137
|
}
|
|
2138
2138
|
__name(readLogFilePage, "readLogFilePage");
|
|
2139
|
+
async function readTriggerList(filePath, trigger, path7, limit) {
|
|
2140
|
+
if (!await fileExists(filePath)) {
|
|
2141
|
+
return void 0;
|
|
2142
|
+
}
|
|
2143
|
+
const config = {
|
|
2144
|
+
maxEntriesPerTrace: 10,
|
|
2145
|
+
chunkSize: 64 * 1024
|
|
2146
|
+
};
|
|
2147
|
+
const builders = /* @__PURE__ */ new Map();
|
|
2148
|
+
const completedCalls = [];
|
|
2149
|
+
const createTraceBuilder = /* @__PURE__ */ __name((traceId) => ({
|
|
2150
|
+
traceId,
|
|
2151
|
+
entries: [],
|
|
2152
|
+
method: void 0,
|
|
2153
|
+
path: void 0,
|
|
2154
|
+
startTime: void 0,
|
|
2155
|
+
endTime: void 0,
|
|
2156
|
+
statusCode: void 0,
|
|
2157
|
+
durationMs: void 0,
|
|
2158
|
+
hasCompleted: false
|
|
2159
|
+
}), "createTraceBuilder");
|
|
2160
|
+
const shouldIncludeInCompletedCalls = /* @__PURE__ */ __name((builder) => {
|
|
2161
|
+
const alreadyAdded = completedCalls.some((call) => call.traceId === builder.traceId);
|
|
2162
|
+
if (alreadyAdded) {
|
|
2163
|
+
return false;
|
|
2164
|
+
}
|
|
2165
|
+
if (!builder.hasCompleted) {
|
|
2166
|
+
return false;
|
|
2167
|
+
}
|
|
2168
|
+
const isAutomationTrigger = builder.path === path7;
|
|
2169
|
+
if (!isAutomationTrigger) {
|
|
2170
|
+
return false;
|
|
2171
|
+
}
|
|
2172
|
+
if (trigger && builder.entries.length > 0) {
|
|
2173
|
+
const requestEntry = builder.entries.find((e) => e.request_body?.trigger);
|
|
2174
|
+
if (requestEntry?.request_body?.trigger) {
|
|
2175
|
+
return String(requestEntry.request_body.trigger) === trigger;
|
|
2176
|
+
}
|
|
2177
|
+
return false;
|
|
2178
|
+
}
|
|
2179
|
+
return true;
|
|
2180
|
+
}, "shouldIncludeInCompletedCalls");
|
|
2181
|
+
const updateBuilderMetadata = /* @__PURE__ */ __name((builder, entry) => {
|
|
2182
|
+
if (entry.method && !builder.method) builder.method = String(entry.method);
|
|
2183
|
+
if (entry.path && !builder.path) builder.path = String(entry.path);
|
|
2184
|
+
builder.entries.push(entry);
|
|
2185
|
+
if (builder.entries.length > config.maxEntriesPerTrace) {
|
|
2186
|
+
builder.entries.shift();
|
|
2187
|
+
}
|
|
2188
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2189
|
+
completedCalls.push(builder);
|
|
2190
|
+
if (limit && completedCalls.length > limit) {
|
|
2191
|
+
completedCalls.shift();
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}, "updateBuilderMetadata");
|
|
2195
|
+
const handleRequestCompleted = /* @__PURE__ */ __name((builder, entry, message) => {
|
|
2196
|
+
builder.hasCompleted = true;
|
|
2197
|
+
builder.endTime = entry.time;
|
|
2198
|
+
builder.statusCode = extractNumber(message, /status_code:\s*(\d+)/);
|
|
2199
|
+
builder.durationMs = extractNumber(message, /duration_ms:\s*(\d+)/);
|
|
2200
|
+
if (!builder.path && entry.path) {
|
|
2201
|
+
builder.path = String(entry.path);
|
|
2202
|
+
}
|
|
2203
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2204
|
+
completedCalls.push(builder);
|
|
2205
|
+
if (limit && completedCalls.length > limit) {
|
|
2206
|
+
completedCalls.shift();
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}, "handleRequestCompleted");
|
|
2210
|
+
const processLogEntry = /* @__PURE__ */ __name((entry) => {
|
|
2211
|
+
const { trace_id: traceId, message = "" } = entry;
|
|
2212
|
+
if (!traceId) return;
|
|
2213
|
+
let builder = builders.get(traceId);
|
|
2214
|
+
if (!builder) {
|
|
2215
|
+
builder = createTraceBuilder(traceId);
|
|
2216
|
+
builders.set(traceId, builder);
|
|
2217
|
+
}
|
|
2218
|
+
updateBuilderMetadata(builder, entry);
|
|
2219
|
+
if (!builder.hasCompleted && (message.includes("HTTP request completed") || message.includes("HTTP request failed"))) {
|
|
2220
|
+
handleRequestCompleted(builder, entry, message);
|
|
2221
|
+
}
|
|
2222
|
+
if (message.includes("HTTP request started") && !builder.startTime) {
|
|
2223
|
+
builder.startTime = entry.time;
|
|
2224
|
+
}
|
|
2225
|
+
}, "processLogEntry");
|
|
2226
|
+
const processLine = /* @__PURE__ */ __name((line) => {
|
|
2227
|
+
const entry = parseLogLine2(line);
|
|
2228
|
+
if (entry?.trace_id) {
|
|
2229
|
+
processLogEntry(entry);
|
|
2230
|
+
}
|
|
2231
|
+
}, "processLine");
|
|
2232
|
+
await readFileReverse(filePath, config.chunkSize, processLine);
|
|
2233
|
+
return {
|
|
2234
|
+
page: 1,
|
|
2235
|
+
pageSize: completedCalls.length,
|
|
2236
|
+
totalCalls: completedCalls.length,
|
|
2237
|
+
totalPages: 1,
|
|
2238
|
+
calls: completedCalls.map((builder) => ({
|
|
2239
|
+
traceId: builder.traceId,
|
|
2240
|
+
method: builder.method,
|
|
2241
|
+
path: builder.path,
|
|
2242
|
+
startTime: builder.startTime,
|
|
2243
|
+
endTime: builder.endTime,
|
|
2244
|
+
statusCode: builder.statusCode,
|
|
2245
|
+
durationMs: builder.durationMs,
|
|
2246
|
+
entries: builder.entries.slice().reverse()
|
|
2247
|
+
}))
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
__name(readTriggerList, "readTriggerList");
|
|
2251
|
+
async function readTriggerDetail(filePath, instanceID) {
|
|
2252
|
+
const exists = await fileExists(filePath);
|
|
2253
|
+
if (!exists) {
|
|
2254
|
+
return void 0;
|
|
2255
|
+
}
|
|
2256
|
+
const matches = [];
|
|
2257
|
+
const stream = (0, import_node_fs7.createReadStream)(filePath, {
|
|
2258
|
+
encoding: "utf8"
|
|
2259
|
+
});
|
|
2260
|
+
const rl = (0, import_node_readline.createInterface)({
|
|
2261
|
+
input: stream,
|
|
2262
|
+
crlfDelay: Infinity
|
|
2263
|
+
});
|
|
2264
|
+
for await (const line of rl) {
|
|
2265
|
+
const entry = parseLogLine2(line);
|
|
2266
|
+
if (!entry) continue;
|
|
2267
|
+
const hasInstanceID = entry.message?.includes(`instanceID=${instanceID}`);
|
|
2268
|
+
if (!hasInstanceID) continue;
|
|
2269
|
+
matches.push(entry);
|
|
2270
|
+
}
|
|
2271
|
+
rl.close();
|
|
2272
|
+
stream.close();
|
|
2273
|
+
return {
|
|
2274
|
+
instanceID,
|
|
2275
|
+
entries: matches
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
__name(readTriggerDetail, "readTriggerDetail");
|
|
2139
2279
|
|
|
2140
2280
|
// src/middlewares/dev-logs/controller.ts
|
|
2141
2281
|
function handleNotFound(res, filePath, message = "Log file not found") {
|
|
@@ -2229,6 +2369,57 @@ function createGetLogFileHandler(logDir) {
|
|
|
2229
2369
|
};
|
|
2230
2370
|
}
|
|
2231
2371
|
__name(createGetLogFileHandler, "createGetLogFileHandler");
|
|
2372
|
+
function createGetTriggerListHandler(logDir) {
|
|
2373
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
|
|
2374
|
+
return async (req, res) => {
|
|
2375
|
+
const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
|
|
2376
|
+
if (!trigger) {
|
|
2377
|
+
return res.status(400).json({
|
|
2378
|
+
message: "trigger is required"
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2382
|
+
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2383
|
+
try {
|
|
2384
|
+
const result = await readTriggerList(traceLogPath, trigger, path7, limit);
|
|
2385
|
+
if (!result) {
|
|
2386
|
+
return handleNotFound(res, traceLogPath);
|
|
2387
|
+
}
|
|
2388
|
+
res.json({
|
|
2389
|
+
file: getRelativePath(traceLogPath),
|
|
2390
|
+
path: path7,
|
|
2391
|
+
...result
|
|
2392
|
+
});
|
|
2393
|
+
} catch (error) {
|
|
2394
|
+
handleError(res, error, "Failed to read trace log");
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2399
|
+
function createGetTriggerDetailHandler(logDir) {
|
|
2400
|
+
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2401
|
+
return async (req, res) => {
|
|
2402
|
+
const instanceID = (req.params.instanceID || "").trim();
|
|
2403
|
+
if (!instanceID) {
|
|
2404
|
+
return res.status(400).json({
|
|
2405
|
+
message: "instanceID is required"
|
|
2406
|
+
});
|
|
2407
|
+
}
|
|
2408
|
+
try {
|
|
2409
|
+
const result = await readTriggerDetail(traceLogPath, instanceID);
|
|
2410
|
+
if (!result) {
|
|
2411
|
+
return handleNotFound(res, traceLogPath);
|
|
2412
|
+
}
|
|
2413
|
+
res.json({
|
|
2414
|
+
file: getRelativePath(traceLogPath),
|
|
2415
|
+
...result
|
|
2416
|
+
});
|
|
2417
|
+
} catch (error) {
|
|
2418
|
+
handleError(res, error, "Failed to read trace log");
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2232
2423
|
|
|
2233
2424
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2234
2425
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2304,6 +2495,8 @@ function createDevLogRouter(options = {}) {
|
|
|
2304
2495
|
router.get("/app/trace/:traceId", createGetTraceEntriesHandler(logDir));
|
|
2305
2496
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2306
2497
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2498
|
+
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2499
|
+
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2307
2500
|
router.get("/health", createHealthCheckHandler());
|
|
2308
2501
|
return router;
|
|
2309
2502
|
}
|
|
@@ -2325,6 +2518,16 @@ var DEV_LOGS_ROUTES = [
|
|
|
2325
2518
|
method: "GET",
|
|
2326
2519
|
path: "/files/:fileName",
|
|
2327
2520
|
description: "Get paginated log file content by file name"
|
|
2521
|
+
},
|
|
2522
|
+
{
|
|
2523
|
+
method: "GET",
|
|
2524
|
+
path: "/trace/trigger/list",
|
|
2525
|
+
description: "Get trigger list (automation trigger) in trace.log"
|
|
2526
|
+
},
|
|
2527
|
+
{
|
|
2528
|
+
method: "GET",
|
|
2529
|
+
path: "/trace/trigger/:instanceID",
|
|
2530
|
+
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2328
2531
|
}
|
|
2329
2532
|
];
|
|
2330
2533
|
function createDevLogsMiddleware(options = {}) {
|