@jaypie/express 1.2.9 → 1.2.10
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OutgoingHttpHeaders } from "node:http";
|
|
2
2
|
import { Writable } from "node:stream";
|
|
3
3
|
import type { ResponseStream } from "./types.js";
|
|
4
|
+
export declare const JAYPIE_LAMBDA_STREAMING: unique symbol;
|
|
4
5
|
/**
|
|
5
6
|
* Mock ServerResponse that streams directly to Lambda responseStream.
|
|
6
7
|
* Uses awslambda.HttpResponseStream.from() to set status and headers.
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -626,6 +626,9 @@ class LambdaResponseBuffered extends node_stream.Writable {
|
|
|
626
626
|
//
|
|
627
627
|
// Constants
|
|
628
628
|
//
|
|
629
|
+
// Symbol to identify Lambda streaming responses. Uses Symbol.for() to ensure
|
|
630
|
+
// the same symbol is used across bundles/realms. Survives prototype manipulation.
|
|
631
|
+
const JAYPIE_LAMBDA_STREAMING = Symbol.for("@jaypie/express/LambdaStreaming");
|
|
629
632
|
// Get Node's internal kOutHeaders symbol from ServerResponse prototype.
|
|
630
633
|
// This is needed for compatibility with Datadog dd-trace instrumentation,
|
|
631
634
|
// which patches HTTP methods and expects this internal state to exist.
|
|
@@ -654,6 +657,10 @@ class LambdaResponseStreaming extends node_stream.Writable {
|
|
|
654
657
|
this._pendingWrites = [];
|
|
655
658
|
this._wrappedStream = null;
|
|
656
659
|
this._responseStream = responseStream;
|
|
660
|
+
// Mark as Lambda streaming response using Symbol for reliable detection.
|
|
661
|
+
// Survives prototype manipulation from Express and dd-trace.
|
|
662
|
+
this[JAYPIE_LAMBDA_STREAMING] =
|
|
663
|
+
true;
|
|
657
664
|
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
658
665
|
// dd-trace patches HTTP methods and expects this internal state.
|
|
659
666
|
if (kOutHeaders) {
|
|
@@ -1026,13 +1033,6 @@ function createLambdaHandler(app, _options) {
|
|
|
1026
1033
|
await runExpressApp(app, req, res);
|
|
1027
1034
|
// Get Lambda response - await explicitly to ensure we have the result
|
|
1028
1035
|
result = await res.getResult();
|
|
1029
|
-
// Debug: Log the response before returning
|
|
1030
|
-
console.log("[createLambdaHandler] Returning response:", JSON.stringify({
|
|
1031
|
-
statusCode: result.statusCode,
|
|
1032
|
-
headers: result.headers,
|
|
1033
|
-
bodyLength: result.body?.length,
|
|
1034
|
-
isBase64Encoded: result.isBase64Encoded,
|
|
1035
|
-
}));
|
|
1036
1036
|
return result;
|
|
1037
1037
|
}
|
|
1038
1038
|
catch (error) {
|
|
@@ -1553,6 +1553,14 @@ const logger$1 = logger$2.log;
|
|
|
1553
1553
|
function isLambdaMockResponse(res) {
|
|
1554
1554
|
return (res[JAYPIE_LAMBDA_MOCK] === true);
|
|
1555
1555
|
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Check if response is a Lambda streaming response.
|
|
1558
|
+
* Uses Symbol marker to survive prototype chain modifications from Express and dd-trace.
|
|
1559
|
+
*/
|
|
1560
|
+
function isLambdaStreamingResponse(res) {
|
|
1561
|
+
return (res[JAYPIE_LAMBDA_STREAMING] ===
|
|
1562
|
+
true);
|
|
1563
|
+
}
|
|
1556
1564
|
/**
|
|
1557
1565
|
* Safely send a JSON response, avoiding dd-trace interception.
|
|
1558
1566
|
* For Lambda mock responses, directly manipulates internal state instead of
|
|
@@ -1587,9 +1595,11 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1587
1595
|
// Fall back to standard Express methods for real responses
|
|
1588
1596
|
res.status(statusCode);
|
|
1589
1597
|
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1590
|
-
// initialize the stream wrapper.
|
|
1591
|
-
//
|
|
1592
|
-
|
|
1598
|
+
// initialize the stream wrapper. This ensures the status code is captured
|
|
1599
|
+
// before any writes occur (which would auto-flush with default 200).
|
|
1600
|
+
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1601
|
+
if (isLambdaStreamingResponse(res) &&
|
|
1602
|
+
typeof res.flushHeaders === "function") {
|
|
1593
1603
|
res.flushHeaders();
|
|
1594
1604
|
}
|
|
1595
1605
|
res.json(data);
|
|
@@ -1622,9 +1632,11 @@ function safeSend(res, statusCode, body) {
|
|
|
1622
1632
|
// Fall back to standard Express methods for real responses
|
|
1623
1633
|
res.status(statusCode);
|
|
1624
1634
|
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1625
|
-
// initialize the stream wrapper.
|
|
1626
|
-
//
|
|
1627
|
-
|
|
1635
|
+
// initialize the stream wrapper. This ensures the status code is captured
|
|
1636
|
+
// before any writes occur (which would auto-flush with default 200).
|
|
1637
|
+
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1638
|
+
if (isLambdaStreamingResponse(res) &&
|
|
1639
|
+
typeof res.flushHeaders === "function") {
|
|
1628
1640
|
res.flushHeaders();
|
|
1629
1641
|
}
|
|
1630
1642
|
if (body !== undefined) {
|