@jaypie/express 1.2.4-rc7 → 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;
@@ -1290,6 +1292,70 @@ function summarizeResponse(res, extras) {
1290
1292
 
1291
1293
  // Cast logger to extended interface for runtime features not in type definitions
1292
1294
  const logger$1 = logger$2.log;
1295
+ //
1296
+ //
1297
+ // Helpers - Safe response methods to bypass dd-trace interception
1298
+ //
1299
+ /**
1300
+ * Check if response is a Lambda mock response with direct internal access.
1301
+ */
1302
+ function isLambdaMockResponse(res) {
1303
+ const mock = res;
1304
+ return (mock._headers instanceof Map &&
1305
+ Array.isArray(mock._chunks) &&
1306
+ typeof mock.buildResult === "function");
1307
+ }
1308
+ /**
1309
+ * Safely send a JSON response, avoiding dd-trace interception.
1310
+ * For Lambda mock responses, directly manipulates internal state instead of
1311
+ * using stream methods (write/end) which dd-trace intercepts.
1312
+ */
1313
+ function safeSendJson(res, statusCode, data) {
1314
+ if (isLambdaMockResponse(res)) {
1315
+ // Direct internal state manipulation - bypasses dd-trace completely
1316
+ res._headers.set("content-type", "application/json");
1317
+ res.statusCode = statusCode;
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
+ }
1326
+ return;
1327
+ }
1328
+ // Fall back to standard Express methods for real responses
1329
+ res.status(statusCode).json(data);
1330
+ }
1331
+ /**
1332
+ * Safely send a response body, avoiding dd-trace interception.
1333
+ * For Lambda mock responses, directly manipulates internal state instead of
1334
+ * using stream methods (write/end) which dd-trace intercepts.
1335
+ */
1336
+ function safeSend(res, statusCode, body) {
1337
+ if (isLambdaMockResponse(res)) {
1338
+ // Direct internal state manipulation - bypasses dd-trace completely
1339
+ res.statusCode = statusCode;
1340
+ if (body !== undefined) {
1341
+ const chunk = Buffer.from(body);
1342
+ res._chunks.push(chunk);
1343
+ }
1344
+ res._headersSent = true;
1345
+ // Signal completion if a promise is waiting
1346
+ if (res._resolve) {
1347
+ res._resolve(res.buildResult());
1348
+ }
1349
+ return;
1350
+ }
1351
+ // Fall back to standard Express methods for real responses
1352
+ if (body !== undefined) {
1353
+ res.status(statusCode).send(body);
1354
+ }
1355
+ else {
1356
+ res.status(statusCode).send();
1357
+ }
1358
+ }
1293
1359
  function expressHandler(handlerOrOptions, optionsOrHandler) {
1294
1360
  /* eslint-enable no-redeclare */
1295
1361
  let handler;
@@ -1506,30 +1572,30 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1506
1572
  if (typeof response === "object") {
1507
1573
  if (typeof response.json ===
1508
1574
  "function") {
1509
- res.json(response.json());
1575
+ safeSendJson(res, status, response.json());
1510
1576
  }
1511
1577
  else {
1512
- res.status(status).json(response);
1578
+ safeSendJson(res, status, response);
1513
1579
  }
1514
1580
  }
1515
1581
  else if (typeof response === "string") {
1516
1582
  try {
1517
- res.status(status).json(JSON.parse(response));
1583
+ safeSendJson(res, status, JSON.parse(response));
1518
1584
  }
1519
1585
  catch {
1520
- res.status(status).send(response);
1586
+ safeSend(res, status, response);
1521
1587
  }
1522
1588
  }
1523
1589
  else if (response === true) {
1524
- res.status(kit.HTTP.CODE.CREATED).send();
1590
+ safeSend(res, kit.HTTP.CODE.CREATED);
1525
1591
  }
1526
1592
  else {
1527
- res.status(status).send(response);
1593
+ safeSend(res, status, response);
1528
1594
  }
1529
1595
  }
1530
1596
  else {
1531
1597
  // No response
1532
- res.status(kit.HTTP.CODE.NO_CONTENT).send();
1598
+ safeSend(res, kit.HTTP.CODE.NO_CONTENT);
1533
1599
  }
1534
1600
  }
1535
1601
  else {