@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.js
CHANGED
|
@@ -2095,6 +2095,146 @@ async function readLogFilePage(filePath, page, pageSize) {
|
|
|
2095
2095
|
};
|
|
2096
2096
|
}
|
|
2097
2097
|
__name(readLogFilePage, "readLogFilePage");
|
|
2098
|
+
async function readTriggerList(filePath, trigger, path7, limit) {
|
|
2099
|
+
if (!await fileExists(filePath)) {
|
|
2100
|
+
return void 0;
|
|
2101
|
+
}
|
|
2102
|
+
const config = {
|
|
2103
|
+
maxEntriesPerTrace: 10,
|
|
2104
|
+
chunkSize: 64 * 1024
|
|
2105
|
+
};
|
|
2106
|
+
const builders = /* @__PURE__ */ new Map();
|
|
2107
|
+
const completedCalls = [];
|
|
2108
|
+
const createTraceBuilder = /* @__PURE__ */ __name((traceId) => ({
|
|
2109
|
+
traceId,
|
|
2110
|
+
entries: [],
|
|
2111
|
+
method: void 0,
|
|
2112
|
+
path: void 0,
|
|
2113
|
+
startTime: void 0,
|
|
2114
|
+
endTime: void 0,
|
|
2115
|
+
statusCode: void 0,
|
|
2116
|
+
durationMs: void 0,
|
|
2117
|
+
hasCompleted: false
|
|
2118
|
+
}), "createTraceBuilder");
|
|
2119
|
+
const shouldIncludeInCompletedCalls = /* @__PURE__ */ __name((builder) => {
|
|
2120
|
+
const alreadyAdded = completedCalls.some((call) => call.traceId === builder.traceId);
|
|
2121
|
+
if (alreadyAdded) {
|
|
2122
|
+
return false;
|
|
2123
|
+
}
|
|
2124
|
+
if (!builder.hasCompleted) {
|
|
2125
|
+
return false;
|
|
2126
|
+
}
|
|
2127
|
+
const isAutomationTrigger = builder.path === path7;
|
|
2128
|
+
if (!isAutomationTrigger) {
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
if (trigger && builder.entries.length > 0) {
|
|
2132
|
+
const requestEntry = builder.entries.find((e) => e.request_body?.trigger);
|
|
2133
|
+
if (requestEntry?.request_body?.trigger) {
|
|
2134
|
+
return String(requestEntry.request_body.trigger) === trigger;
|
|
2135
|
+
}
|
|
2136
|
+
return false;
|
|
2137
|
+
}
|
|
2138
|
+
return true;
|
|
2139
|
+
}, "shouldIncludeInCompletedCalls");
|
|
2140
|
+
const updateBuilderMetadata = /* @__PURE__ */ __name((builder, entry) => {
|
|
2141
|
+
if (entry.method && !builder.method) builder.method = String(entry.method);
|
|
2142
|
+
if (entry.path && !builder.path) builder.path = String(entry.path);
|
|
2143
|
+
builder.entries.push(entry);
|
|
2144
|
+
if (builder.entries.length > config.maxEntriesPerTrace) {
|
|
2145
|
+
builder.entries.shift();
|
|
2146
|
+
}
|
|
2147
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2148
|
+
completedCalls.push(builder);
|
|
2149
|
+
if (limit && completedCalls.length > limit) {
|
|
2150
|
+
completedCalls.shift();
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
}, "updateBuilderMetadata");
|
|
2154
|
+
const handleRequestCompleted = /* @__PURE__ */ __name((builder, entry, message) => {
|
|
2155
|
+
builder.hasCompleted = true;
|
|
2156
|
+
builder.endTime = entry.time;
|
|
2157
|
+
builder.statusCode = extractNumber(message, /status_code:\s*(\d+)/);
|
|
2158
|
+
builder.durationMs = extractNumber(message, /duration_ms:\s*(\d+)/);
|
|
2159
|
+
if (!builder.path && entry.path) {
|
|
2160
|
+
builder.path = String(entry.path);
|
|
2161
|
+
}
|
|
2162
|
+
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2163
|
+
completedCalls.push(builder);
|
|
2164
|
+
if (limit && completedCalls.length > limit) {
|
|
2165
|
+
completedCalls.shift();
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
}, "handleRequestCompleted");
|
|
2169
|
+
const processLogEntry = /* @__PURE__ */ __name((entry) => {
|
|
2170
|
+
const { trace_id: traceId, message = "" } = entry;
|
|
2171
|
+
if (!traceId) return;
|
|
2172
|
+
let builder = builders.get(traceId);
|
|
2173
|
+
if (!builder) {
|
|
2174
|
+
builder = createTraceBuilder(traceId);
|
|
2175
|
+
builders.set(traceId, builder);
|
|
2176
|
+
}
|
|
2177
|
+
updateBuilderMetadata(builder, entry);
|
|
2178
|
+
if (!builder.hasCompleted && (message.includes("HTTP request completed") || message.includes("HTTP request failed"))) {
|
|
2179
|
+
handleRequestCompleted(builder, entry, message);
|
|
2180
|
+
}
|
|
2181
|
+
if (message.includes("HTTP request started") && !builder.startTime) {
|
|
2182
|
+
builder.startTime = entry.time;
|
|
2183
|
+
}
|
|
2184
|
+
}, "processLogEntry");
|
|
2185
|
+
const processLine = /* @__PURE__ */ __name((line) => {
|
|
2186
|
+
const entry = parseLogLine2(line);
|
|
2187
|
+
if (entry?.trace_id) {
|
|
2188
|
+
processLogEntry(entry);
|
|
2189
|
+
}
|
|
2190
|
+
}, "processLine");
|
|
2191
|
+
await readFileReverse(filePath, config.chunkSize, processLine);
|
|
2192
|
+
return {
|
|
2193
|
+
page: 1,
|
|
2194
|
+
pageSize: completedCalls.length,
|
|
2195
|
+
totalCalls: completedCalls.length,
|
|
2196
|
+
totalPages: 1,
|
|
2197
|
+
calls: completedCalls.map((builder) => ({
|
|
2198
|
+
traceId: builder.traceId,
|
|
2199
|
+
method: builder.method,
|
|
2200
|
+
path: builder.path,
|
|
2201
|
+
startTime: builder.startTime,
|
|
2202
|
+
endTime: builder.endTime,
|
|
2203
|
+
statusCode: builder.statusCode,
|
|
2204
|
+
durationMs: builder.durationMs,
|
|
2205
|
+
entries: builder.entries.slice().reverse()
|
|
2206
|
+
}))
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
__name(readTriggerList, "readTriggerList");
|
|
2210
|
+
async function readTriggerDetail(filePath, instanceID) {
|
|
2211
|
+
const exists = await fileExists(filePath);
|
|
2212
|
+
if (!exists) {
|
|
2213
|
+
return void 0;
|
|
2214
|
+
}
|
|
2215
|
+
const matches = [];
|
|
2216
|
+
const stream = createReadStream(filePath, {
|
|
2217
|
+
encoding: "utf8"
|
|
2218
|
+
});
|
|
2219
|
+
const rl = createInterface({
|
|
2220
|
+
input: stream,
|
|
2221
|
+
crlfDelay: Infinity
|
|
2222
|
+
});
|
|
2223
|
+
for await (const line of rl) {
|
|
2224
|
+
const entry = parseLogLine2(line);
|
|
2225
|
+
if (!entry) continue;
|
|
2226
|
+
const hasInstanceID = entry.message?.includes(`instanceID=${instanceID}`);
|
|
2227
|
+
if (!hasInstanceID) continue;
|
|
2228
|
+
matches.push(entry);
|
|
2229
|
+
}
|
|
2230
|
+
rl.close();
|
|
2231
|
+
stream.close();
|
|
2232
|
+
return {
|
|
2233
|
+
instanceID,
|
|
2234
|
+
entries: matches
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
__name(readTriggerDetail, "readTriggerDetail");
|
|
2098
2238
|
|
|
2099
2239
|
// src/middlewares/dev-logs/controller.ts
|
|
2100
2240
|
function handleNotFound(res, filePath, message = "Log file not found") {
|
|
@@ -2188,6 +2328,57 @@ function createGetLogFileHandler(logDir) {
|
|
|
2188
2328
|
};
|
|
2189
2329
|
}
|
|
2190
2330
|
__name(createGetLogFileHandler, "createGetLogFileHandler");
|
|
2331
|
+
function createGetTriggerListHandler(logDir) {
|
|
2332
|
+
const traceLogPath = join3(logDir, "trace.log");
|
|
2333
|
+
return async (req, res) => {
|
|
2334
|
+
const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
|
|
2335
|
+
if (!trigger) {
|
|
2336
|
+
return res.status(400).json({
|
|
2337
|
+
message: "trigger is required"
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2341
|
+
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2342
|
+
try {
|
|
2343
|
+
const result = await readTriggerList(traceLogPath, trigger, path7, limit);
|
|
2344
|
+
if (!result) {
|
|
2345
|
+
return handleNotFound(res, traceLogPath);
|
|
2346
|
+
}
|
|
2347
|
+
res.json({
|
|
2348
|
+
file: getRelativePath(traceLogPath),
|
|
2349
|
+
path: path7,
|
|
2350
|
+
...result
|
|
2351
|
+
});
|
|
2352
|
+
} catch (error) {
|
|
2353
|
+
handleError(res, error, "Failed to read trace log");
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2358
|
+
function createGetTriggerDetailHandler(logDir) {
|
|
2359
|
+
const traceLogPath = join3(logDir, "server.log");
|
|
2360
|
+
return async (req, res) => {
|
|
2361
|
+
const instanceID = (req.params.instanceID || "").trim();
|
|
2362
|
+
if (!instanceID) {
|
|
2363
|
+
return res.status(400).json({
|
|
2364
|
+
message: "instanceID is required"
|
|
2365
|
+
});
|
|
2366
|
+
}
|
|
2367
|
+
try {
|
|
2368
|
+
const result = await readTriggerDetail(traceLogPath, instanceID);
|
|
2369
|
+
if (!result) {
|
|
2370
|
+
return handleNotFound(res, traceLogPath);
|
|
2371
|
+
}
|
|
2372
|
+
res.json({
|
|
2373
|
+
file: getRelativePath(traceLogPath),
|
|
2374
|
+
...result
|
|
2375
|
+
});
|
|
2376
|
+
} catch (error) {
|
|
2377
|
+
handleError(res, error, "Failed to read trace log");
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2191
2382
|
|
|
2192
2383
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2193
2384
|
import http2 from "http";
|
|
@@ -2263,6 +2454,8 @@ function createDevLogRouter(options = {}) {
|
|
|
2263
2454
|
router.get("/app/trace/:traceId", createGetTraceEntriesHandler(logDir));
|
|
2264
2455
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2265
2456
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2457
|
+
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2458
|
+
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2266
2459
|
router.get("/health", createHealthCheckHandler());
|
|
2267
2460
|
return router;
|
|
2268
2461
|
}
|
|
@@ -2284,6 +2477,16 @@ var DEV_LOGS_ROUTES = [
|
|
|
2284
2477
|
method: "GET",
|
|
2285
2478
|
path: "/files/:fileName",
|
|
2286
2479
|
description: "Get paginated log file content by file name"
|
|
2480
|
+
},
|
|
2481
|
+
{
|
|
2482
|
+
method: "GET",
|
|
2483
|
+
path: "/trace/trigger/list",
|
|
2484
|
+
description: "Get trigger list (automation trigger) in trace.log"
|
|
2485
|
+
},
|
|
2486
|
+
{
|
|
2487
|
+
method: "GET",
|
|
2488
|
+
path: "/trace/trigger/:instanceID",
|
|
2489
|
+
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2287
2490
|
}
|
|
2288
2491
|
];
|
|
2289
2492
|
function createDevLogsMiddleware(options = {}) {
|