@jaypie/express 1.2.4-rc7 → 1.2.4-rc8

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/esm/index.js CHANGED
@@ -1288,6 +1288,55 @@ function summarizeResponse(res, extras) {
1288
1288
 
1289
1289
  // Cast logger to extended interface for runtime features not in type definitions
1290
1290
  const logger$1 = log;
1291
+ //
1292
+ //
1293
+ // Helpers - Safe response methods to bypass dd-trace interception
1294
+ //
1295
+ /**
1296
+ * Check if response is a Lambda mock response with direct _headers access.
1297
+ */
1298
+ function isLambdaMockResponse(res) {
1299
+ return res._headers instanceof Map;
1300
+ }
1301
+ /**
1302
+ * Safely send a JSON response, avoiding dd-trace interception.
1303
+ * For Lambda mock responses, directly sets headers and writes to stream.
1304
+ */
1305
+ function safeSendJson(res, statusCode, data) {
1306
+ if (isLambdaMockResponse(res)) {
1307
+ // Direct access for Lambda mock responses - bypasses dd-trace
1308
+ res._headers.set("content-type", "application/json");
1309
+ res.statusCode = statusCode;
1310
+ res.end(JSON.stringify(data));
1311
+ return;
1312
+ }
1313
+ // Fall back to standard Express methods for real responses
1314
+ res.status(statusCode).json(data);
1315
+ }
1316
+ /**
1317
+ * Safely send a response body, avoiding dd-trace interception.
1318
+ * For Lambda mock responses, directly writes to stream.
1319
+ */
1320
+ function safeSend(res, statusCode, body) {
1321
+ if (isLambdaMockResponse(res)) {
1322
+ // Direct access for Lambda mock responses - bypasses dd-trace
1323
+ res.statusCode = statusCode;
1324
+ if (body !== undefined) {
1325
+ res.end(body);
1326
+ }
1327
+ else {
1328
+ res.end();
1329
+ }
1330
+ return;
1331
+ }
1332
+ // Fall back to standard Express methods for real responses
1333
+ if (body !== undefined) {
1334
+ res.status(statusCode).send(body);
1335
+ }
1336
+ else {
1337
+ res.status(statusCode).send();
1338
+ }
1339
+ }
1291
1340
  function expressHandler(handlerOrOptions, optionsOrHandler) {
1292
1341
  /* eslint-enable no-redeclare */
1293
1342
  let handler;
@@ -1504,30 +1553,30 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1504
1553
  if (typeof response === "object") {
1505
1554
  if (typeof response.json ===
1506
1555
  "function") {
1507
- res.json(response.json());
1556
+ safeSendJson(res, status, response.json());
1508
1557
  }
1509
1558
  else {
1510
- res.status(status).json(response);
1559
+ safeSendJson(res, status, response);
1511
1560
  }
1512
1561
  }
1513
1562
  else if (typeof response === "string") {
1514
1563
  try {
1515
- res.status(status).json(JSON.parse(response));
1564
+ safeSendJson(res, status, JSON.parse(response));
1516
1565
  }
1517
1566
  catch {
1518
- res.status(status).send(response);
1567
+ safeSend(res, status, response);
1519
1568
  }
1520
1569
  }
1521
1570
  else if (response === true) {
1522
- res.status(HTTP.CODE.CREATED).send();
1571
+ safeSend(res, HTTP.CODE.CREATED);
1523
1572
  }
1524
1573
  else {
1525
- res.status(status).send(response);
1574
+ safeSend(res, status, response);
1526
1575
  }
1527
1576
  }
1528
1577
  else {
1529
1578
  // No response
1530
- res.status(HTTP.CODE.NO_CONTENT).send();
1579
+ safeSend(res, HTTP.CODE.NO_CONTENT);
1531
1580
  }
1532
1581
  }
1533
1582
  else {