@jaypie/express 1.2.4-rc8 → 1.2.4-rc9

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.
@@ -11,10 +11,10 @@ export declare class LambdaResponseBuffered extends Writable {
11
11
  readonly socket: {
12
12
  remoteAddress: string;
13
13
  };
14
- private _chunks;
15
- private _headers;
16
- private _headersSent;
17
- private _resolve;
14
+ _chunks: Buffer[];
15
+ _headers: Map<string, string | string[]>;
16
+ _headersSent: boolean;
17
+ _resolve: ((result: LambdaResponse) => void) | null;
18
18
  constructor();
19
19
  getResult(): Promise<LambdaResponse>;
20
20
  setHeader(name: string, value: number | string | string[]): this;
@@ -53,7 +53,7 @@ export declare class LambdaResponseBuffered extends Writable {
53
53
  _write(chunk: Buffer | string, encoding: BufferEncoding, // eslint-disable-line no-undef
54
54
  callback: (error?: Error | null) => void): void;
55
55
  _final(callback: (error?: Error | null) => void): void;
56
- private buildResult;
56
+ buildResult(): LambdaResponse;
57
57
  private isBinaryContentType;
58
58
  }
59
59
  export default LambdaResponseBuffered;
@@ -192,6 +192,8 @@ class LambdaResponseBuffered extends node_stream.Writable {
192
192
  this.socket = {
193
193
  remoteAddress: "127.0.0.1",
194
194
  };
195
+ // Internal state exposed for direct manipulation by safe response methods
196
+ // that need to bypass dd-trace interception of stream methods
195
197
  this._chunks = [];
196
198
  this._headers = new Map();
197
199
  this._headersSent = false;
@@ -1295,21 +1297,32 @@ const logger$1 = logger$2.log;
1295
1297
  // Helpers - Safe response methods to bypass dd-trace interception
1296
1298
  //
1297
1299
  /**
1298
- * Check if response is a Lambda mock response with direct _headers access.
1300
+ * Check if response is a Lambda mock response with direct internal access.
1299
1301
  */
1300
1302
  function isLambdaMockResponse(res) {
1301
- return res._headers instanceof Map;
1303
+ const mock = res;
1304
+ return (mock._headers instanceof Map &&
1305
+ Array.isArray(mock._chunks) &&
1306
+ typeof mock.buildResult === "function");
1302
1307
  }
1303
1308
  /**
1304
1309
  * Safely send a JSON response, avoiding dd-trace interception.
1305
- * For Lambda mock responses, directly sets headers and writes to stream.
1310
+ * For Lambda mock responses, directly manipulates internal state instead of
1311
+ * using stream methods (write/end) which dd-trace intercepts.
1306
1312
  */
1307
1313
  function safeSendJson(res, statusCode, data) {
1308
1314
  if (isLambdaMockResponse(res)) {
1309
- // Direct access for Lambda mock responses - bypasses dd-trace
1315
+ // Direct internal state manipulation - bypasses dd-trace completely
1310
1316
  res._headers.set("content-type", "application/json");
1311
1317
  res.statusCode = statusCode;
1312
- res.end(JSON.stringify(data));
1318
+ // Directly push to chunks array instead of using stream write/end
1319
+ const chunk = Buffer.from(JSON.stringify(data));
1320
+ res._chunks.push(chunk);
1321
+ res._headersSent = true;
1322
+ // Signal completion if a promise is waiting
1323
+ if (res._resolve) {
1324
+ res._resolve(res.buildResult());
1325
+ }
1313
1326
  return;
1314
1327
  }
1315
1328
  // Fall back to standard Express methods for real responses
@@ -1317,17 +1330,21 @@ function safeSendJson(res, statusCode, data) {
1317
1330
  }
1318
1331
  /**
1319
1332
  * Safely send a response body, avoiding dd-trace interception.
1320
- * For Lambda mock responses, directly writes to stream.
1333
+ * For Lambda mock responses, directly manipulates internal state instead of
1334
+ * using stream methods (write/end) which dd-trace intercepts.
1321
1335
  */
1322
1336
  function safeSend(res, statusCode, body) {
1323
1337
  if (isLambdaMockResponse(res)) {
1324
- // Direct access for Lambda mock responses - bypasses dd-trace
1338
+ // Direct internal state manipulation - bypasses dd-trace completely
1325
1339
  res.statusCode = statusCode;
1326
1340
  if (body !== undefined) {
1327
- res.end(body);
1341
+ const chunk = Buffer.from(body);
1342
+ res._chunks.push(chunk);
1328
1343
  }
1329
- else {
1330
- res.end();
1344
+ res._headersSent = true;
1345
+ // Signal completion if a promise is waiting
1346
+ if (res._resolve) {
1347
+ res._resolve(res.buildResult());
1331
1348
  }
1332
1349
  return;
1333
1350
  }