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