brakit 0.7.1 → 0.7.3
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/api.js +1 -1
- package/dist/bin/brakit.js +1 -1
- package/dist/runtime/index.js +49 -35
- package/package.json +1 -1
package/dist/api.js
CHANGED
package/dist/bin/brakit.js
CHANGED
|
@@ -693,7 +693,7 @@ import { resolve as resolve2 } from "path";
|
|
|
693
693
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
694
694
|
|
|
695
695
|
// src/index.ts
|
|
696
|
-
var VERSION = "0.7.
|
|
696
|
+
var VERSION = "0.7.3";
|
|
697
697
|
|
|
698
698
|
// src/cli/commands/install.ts
|
|
699
699
|
var IMPORT_LINE = `import "brakit";`;
|
package/dist/runtime/index.js
CHANGED
|
@@ -3669,7 +3669,7 @@ var init_src = __esm({
|
|
|
3669
3669
|
init_rules();
|
|
3670
3670
|
init_engine();
|
|
3671
3671
|
init_insights2();
|
|
3672
|
-
VERSION = "0.7.
|
|
3672
|
+
VERSION = "0.7.3";
|
|
3673
3673
|
}
|
|
3674
3674
|
});
|
|
3675
3675
|
|
|
@@ -6281,6 +6281,7 @@ var init_guard = __esm({
|
|
|
6281
6281
|
});
|
|
6282
6282
|
|
|
6283
6283
|
// src/runtime/capture.ts
|
|
6284
|
+
import { gunzipSync, brotliDecompressSync, inflateSync } from "zlib";
|
|
6284
6285
|
function outgoingToIncoming(headers) {
|
|
6285
6286
|
const result = {};
|
|
6286
6287
|
for (const [key, value] of Object.entries(headers)) {
|
|
@@ -6293,52 +6294,65 @@ function outgoingToIncoming(headers) {
|
|
|
6293
6294
|
}
|
|
6294
6295
|
return result;
|
|
6295
6296
|
}
|
|
6297
|
+
function decompress(body, encoding) {
|
|
6298
|
+
try {
|
|
6299
|
+
if (encoding === "gzip") return gunzipSync(body);
|
|
6300
|
+
if (encoding === "br") return brotliDecompressSync(body);
|
|
6301
|
+
if (encoding === "deflate") return inflateSync(body);
|
|
6302
|
+
} catch {
|
|
6303
|
+
}
|
|
6304
|
+
return body;
|
|
6305
|
+
}
|
|
6296
6306
|
function captureInProcess(req, res, requestId) {
|
|
6297
6307
|
const startTime = performance.now();
|
|
6298
6308
|
const method = req.method ?? "GET";
|
|
6299
|
-
const shouldCaptureBody = method !== "GET" && method !== "HEAD";
|
|
6300
|
-
const reqChunks = [];
|
|
6301
|
-
let reqSize = 0;
|
|
6302
|
-
if (shouldCaptureBody) {
|
|
6303
|
-
req.on("data", (chunk) => {
|
|
6304
|
-
if (reqSize < DEFAULT_MAX_BODY_CAPTURE) {
|
|
6305
|
-
reqChunks.push(chunk);
|
|
6306
|
-
reqSize += chunk.length;
|
|
6307
|
-
}
|
|
6308
|
-
});
|
|
6309
|
-
}
|
|
6310
6309
|
const resChunks = [];
|
|
6311
6310
|
let resSize = 0;
|
|
6312
6311
|
const originalWrite = res.write;
|
|
6313
6312
|
const originalEnd = res.end;
|
|
6314
|
-
res.write = function(
|
|
6315
|
-
|
|
6316
|
-
const
|
|
6317
|
-
|
|
6318
|
-
|
|
6313
|
+
res.write = function(...args) {
|
|
6314
|
+
try {
|
|
6315
|
+
const chunk = args[0];
|
|
6316
|
+
if (chunk != null && typeof chunk !== "function" && resSize < DEFAULT_MAX_BODY_CAPTURE) {
|
|
6317
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
6318
|
+
resChunks.push(buf);
|
|
6319
|
+
resSize += buf.length;
|
|
6320
|
+
}
|
|
6321
|
+
} catch {
|
|
6319
6322
|
}
|
|
6320
|
-
return originalWrite.apply(this,
|
|
6323
|
+
return originalWrite.apply(this, args);
|
|
6321
6324
|
};
|
|
6322
6325
|
res.end = function(...args) {
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6326
|
+
try {
|
|
6327
|
+
const chunk = typeof args[0] !== "function" ? args[0] : void 0;
|
|
6328
|
+
if (chunk != null && resSize < DEFAULT_MAX_BODY_CAPTURE) {
|
|
6329
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
6330
|
+
resChunks.push(buf);
|
|
6331
|
+
}
|
|
6332
|
+
} catch {
|
|
6327
6333
|
}
|
|
6328
6334
|
const result = originalEnd.apply(this, args);
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6335
|
+
try {
|
|
6336
|
+
const encoding = String(res.getHeader("content-encoding") ?? "").toLowerCase();
|
|
6337
|
+
let body = resChunks.length > 0 ? Buffer.concat(resChunks) : null;
|
|
6338
|
+
if (body && encoding) {
|
|
6339
|
+
body = decompress(body, encoding);
|
|
6340
|
+
}
|
|
6341
|
+
defaultStore.capture({
|
|
6342
|
+
requestId,
|
|
6343
|
+
method,
|
|
6344
|
+
url: req.url ?? "/",
|
|
6345
|
+
requestHeaders: req.headers,
|
|
6346
|
+
requestBody: null,
|
|
6347
|
+
statusCode: res.statusCode,
|
|
6348
|
+
responseHeaders: outgoingToIncoming(res.getHeaders()),
|
|
6349
|
+
responseBody: body,
|
|
6350
|
+
responseContentType: String(res.getHeader("content-type") ?? ""),
|
|
6351
|
+
startTime,
|
|
6352
|
+
config: { maxBodyCapture: DEFAULT_MAX_BODY_CAPTURE }
|
|
6353
|
+
});
|
|
6354
|
+
} catch {
|
|
6355
|
+
}
|
|
6342
6356
|
return result;
|
|
6343
6357
|
};
|
|
6344
6358
|
}
|
package/package.json
CHANGED