brakit 0.7.1 → 0.7.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/api.js CHANGED
@@ -1618,7 +1618,7 @@ var AnalysisEngine = class {
1618
1618
  };
1619
1619
 
1620
1620
  // src/index.ts
1621
- var VERSION = "0.7.1";
1621
+ var VERSION = "0.7.2";
1622
1622
  export {
1623
1623
  AdapterRegistry,
1624
1624
  AnalysisEngine,
@@ -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.1";
696
+ var VERSION = "0.7.2";
697
697
 
698
698
  // src/cli/commands/install.ts
699
699
  var IMPORT_LINE = `import "brakit";`;
@@ -3669,7 +3669,7 @@ var init_src = __esm({
3669
3669
  init_rules();
3670
3670
  init_engine();
3671
3671
  init_insights2();
3672
- VERSION = "0.7.1";
3672
+ VERSION = "0.7.2";
3673
3673
  }
3674
3674
  });
3675
3675
 
@@ -6296,49 +6296,48 @@ function outgoingToIncoming(headers) {
6296
6296
  function captureInProcess(req, res, requestId) {
6297
6297
  const startTime = performance.now();
6298
6298
  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
6299
  const resChunks = [];
6311
6300
  let resSize = 0;
6312
6301
  const originalWrite = res.write;
6313
6302
  const originalEnd = res.end;
6314
- res.write = function(chunk, ...args) {
6315
- if (chunk && resSize < DEFAULT_MAX_BODY_CAPTURE) {
6316
- const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
6317
- resChunks.push(buf);
6318
- resSize += buf.length;
6303
+ res.write = function(...args) {
6304
+ try {
6305
+ const chunk = args[0];
6306
+ if (chunk != null && typeof chunk !== "function" && resSize < DEFAULT_MAX_BODY_CAPTURE) {
6307
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
6308
+ resChunks.push(buf);
6309
+ resSize += buf.length;
6310
+ }
6311
+ } catch {
6319
6312
  }
6320
- return originalWrite.apply(this, [chunk, ...args]);
6313
+ return originalWrite.apply(this, args);
6321
6314
  };
6322
6315
  res.end = function(...args) {
6323
- const chunk = typeof args[0] !== "function" ? args[0] : void 0;
6324
- if (chunk && resSize < DEFAULT_MAX_BODY_CAPTURE) {
6325
- const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
6326
- resChunks.push(buf);
6316
+ try {
6317
+ const chunk = typeof args[0] !== "function" ? args[0] : void 0;
6318
+ if (chunk != null && resSize < DEFAULT_MAX_BODY_CAPTURE) {
6319
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
6320
+ resChunks.push(buf);
6321
+ }
6322
+ } catch {
6327
6323
  }
6328
6324
  const result = originalEnd.apply(this, args);
6329
- defaultStore.capture({
6330
- requestId,
6331
- method,
6332
- url: req.url ?? "/",
6333
- requestHeaders: req.headers,
6334
- requestBody: reqChunks.length > 0 ? Buffer.concat(reqChunks) : null,
6335
- statusCode: res.statusCode,
6336
- responseHeaders: outgoingToIncoming(res.getHeaders()),
6337
- responseBody: resChunks.length > 0 ? Buffer.concat(resChunks) : null,
6338
- responseContentType: String(res.getHeader("content-type") ?? ""),
6339
- startTime,
6340
- config: { maxBodyCapture: DEFAULT_MAX_BODY_CAPTURE }
6341
- });
6325
+ try {
6326
+ defaultStore.capture({
6327
+ requestId,
6328
+ method,
6329
+ url: req.url ?? "/",
6330
+ requestHeaders: req.headers,
6331
+ requestBody: null,
6332
+ statusCode: res.statusCode,
6333
+ responseHeaders: outgoingToIncoming(res.getHeaders()),
6334
+ responseBody: resChunks.length > 0 ? Buffer.concat(resChunks) : null,
6335
+ responseContentType: String(res.getHeader("content-type") ?? ""),
6336
+ startTime,
6337
+ config: { maxBodyCapture: DEFAULT_MAX_BODY_CAPTURE }
6338
+ });
6339
+ } catch {
6340
+ }
6342
6341
  return result;
6343
6342
  };
6344
6343
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brakit",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "See what your API is really doing. Security scanning, N+1 detection, duplicate calls, DB queries — one command, zero config.",
5
5
  "type": "module",
6
6
  "bin": {