@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;
package/dist/esm/index.js CHANGED
@@ -190,6 +190,8 @@ class LambdaResponseBuffered extends Writable {
190
190
  this.socket = {
191
191
  remoteAddress: "127.0.0.1",
192
192
  };
193
+ // Internal state exposed for direct manipulation by safe response methods
194
+ // that need to bypass dd-trace interception of stream methods
193
195
  this._chunks = [];
194
196
  this._headers = new Map();
195
197
  this._headersSent = false;
@@ -1293,21 +1295,32 @@ const logger$1 = log;
1293
1295
  // Helpers - Safe response methods to bypass dd-trace interception
1294
1296
  //
1295
1297
  /**
1296
- * Check if response is a Lambda mock response with direct _headers access.
1298
+ * Check if response is a Lambda mock response with direct internal access.
1297
1299
  */
1298
1300
  function isLambdaMockResponse(res) {
1299
- return res._headers instanceof Map;
1301
+ const mock = res;
1302
+ return (mock._headers instanceof Map &&
1303
+ Array.isArray(mock._chunks) &&
1304
+ typeof mock.buildResult === "function");
1300
1305
  }
1301
1306
  /**
1302
1307
  * Safely send a JSON response, avoiding dd-trace interception.
1303
- * For Lambda mock responses, directly sets headers and writes to stream.
1308
+ * For Lambda mock responses, directly manipulates internal state instead of
1309
+ * using stream methods (write/end) which dd-trace intercepts.
1304
1310
  */
1305
1311
  function safeSendJson(res, statusCode, data) {
1306
1312
  if (isLambdaMockResponse(res)) {
1307
- // Direct access for Lambda mock responses - bypasses dd-trace
1313
+ // Direct internal state manipulation - bypasses dd-trace completely
1308
1314
  res._headers.set("content-type", "application/json");
1309
1315
  res.statusCode = statusCode;
1310
- res.end(JSON.stringify(data));
1316
+ // Directly push to chunks array instead of using stream write/end
1317
+ const chunk = Buffer.from(JSON.stringify(data));
1318
+ res._chunks.push(chunk);
1319
+ res._headersSent = true;
1320
+ // Signal completion if a promise is waiting
1321
+ if (res._resolve) {
1322
+ res._resolve(res.buildResult());
1323
+ }
1311
1324
  return;
1312
1325
  }
1313
1326
  // Fall back to standard Express methods for real responses
@@ -1315,17 +1328,21 @@ function safeSendJson(res, statusCode, data) {
1315
1328
  }
1316
1329
  /**
1317
1330
  * Safely send a response body, avoiding dd-trace interception.
1318
- * For Lambda mock responses, directly writes to stream.
1331
+ * For Lambda mock responses, directly manipulates internal state instead of
1332
+ * using stream methods (write/end) which dd-trace intercepts.
1319
1333
  */
1320
1334
  function safeSend(res, statusCode, body) {
1321
1335
  if (isLambdaMockResponse(res)) {
1322
- // Direct access for Lambda mock responses - bypasses dd-trace
1336
+ // Direct internal state manipulation - bypasses dd-trace completely
1323
1337
  res.statusCode = statusCode;
1324
1338
  if (body !== undefined) {
1325
- res.end(body);
1339
+ const chunk = Buffer.from(body);
1340
+ res._chunks.push(chunk);
1326
1341
  }
1327
- else {
1328
- res.end();
1342
+ res._headersSent = true;
1343
+ // Signal completion if a promise is waiting
1344
+ if (res._resolve) {
1345
+ res._resolve(res.buildResult());
1329
1346
  }
1330
1347
  return;
1331
1348
  }