brakit 0.7.2 → 0.7.4
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 +32 -7
- 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.4";
|
|
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.4";
|
|
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,6 +6294,21 @@ 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
|
+
}
|
|
6306
|
+
function toBuffer(chunk) {
|
|
6307
|
+
if (Buffer.isBuffer(chunk)) return chunk;
|
|
6308
|
+
if (chunk instanceof Uint8Array) return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
6309
|
+
if (typeof chunk === "string") return Buffer.from(chunk);
|
|
6310
|
+
return null;
|
|
6311
|
+
}
|
|
6296
6312
|
function captureInProcess(req, res, requestId) {
|
|
6297
6313
|
const startTime = performance.now();
|
|
6298
6314
|
const method = req.method ?? "GET";
|
|
@@ -6304,9 +6320,11 @@ function captureInProcess(req, res, requestId) {
|
|
|
6304
6320
|
try {
|
|
6305
6321
|
const chunk = args[0];
|
|
6306
6322
|
if (chunk != null && typeof chunk !== "function" && resSize < DEFAULT_MAX_BODY_CAPTURE) {
|
|
6307
|
-
const buf =
|
|
6308
|
-
|
|
6309
|
-
|
|
6323
|
+
const buf = toBuffer(chunk);
|
|
6324
|
+
if (buf) {
|
|
6325
|
+
resChunks.push(buf);
|
|
6326
|
+
resSize += buf.length;
|
|
6327
|
+
}
|
|
6310
6328
|
}
|
|
6311
6329
|
} catch {
|
|
6312
6330
|
}
|
|
@@ -6316,13 +6334,20 @@ function captureInProcess(req, res, requestId) {
|
|
|
6316
6334
|
try {
|
|
6317
6335
|
const chunk = typeof args[0] !== "function" ? args[0] : void 0;
|
|
6318
6336
|
if (chunk != null && resSize < DEFAULT_MAX_BODY_CAPTURE) {
|
|
6319
|
-
const buf =
|
|
6320
|
-
|
|
6337
|
+
const buf = toBuffer(chunk);
|
|
6338
|
+
if (buf) {
|
|
6339
|
+
resChunks.push(buf);
|
|
6340
|
+
}
|
|
6321
6341
|
}
|
|
6322
6342
|
} catch {
|
|
6323
6343
|
}
|
|
6324
6344
|
const result = originalEnd.apply(this, args);
|
|
6325
6345
|
try {
|
|
6346
|
+
const encoding = String(res.getHeader("content-encoding") ?? "").toLowerCase();
|
|
6347
|
+
let body = resChunks.length > 0 ? Buffer.concat(resChunks) : null;
|
|
6348
|
+
if (body && encoding) {
|
|
6349
|
+
body = decompress(body, encoding);
|
|
6350
|
+
}
|
|
6326
6351
|
defaultStore.capture({
|
|
6327
6352
|
requestId,
|
|
6328
6353
|
method,
|
|
@@ -6331,7 +6356,7 @@ function captureInProcess(req, res, requestId) {
|
|
|
6331
6356
|
requestBody: null,
|
|
6332
6357
|
statusCode: res.statusCode,
|
|
6333
6358
|
responseHeaders: outgoingToIncoming(res.getHeaders()),
|
|
6334
|
-
responseBody:
|
|
6359
|
+
responseBody: body,
|
|
6335
6360
|
responseContentType: String(res.getHeader("content-type") ?? ""),
|
|
6336
6361
|
startTime,
|
|
6337
6362
|
config: { maxBodyCapture: DEFAULT_MAX_BODY_CAPTURE }
|
package/package.json
CHANGED