@jaypie/express 1.2.10 → 1.2.11-dev.0
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/cjs/index.cjs +86 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +86 -8
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -659,6 +659,10 @@ class LambdaResponseStreaming extends Writable {
|
|
|
659
659
|
// Survives prototype manipulation from Express and dd-trace.
|
|
660
660
|
this[JAYPIE_LAMBDA_STREAMING] =
|
|
661
661
|
true;
|
|
662
|
+
// DIAGNOSTIC: Log symbol assignment
|
|
663
|
+
console.log("[DIAG:LambdaResponseStreaming:constructor] Symbol set", {
|
|
664
|
+
symbolValue: this[JAYPIE_LAMBDA_STREAMING],
|
|
665
|
+
});
|
|
662
666
|
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
663
667
|
// dd-trace patches HTTP methods and expects this internal state.
|
|
664
668
|
if (kOutHeaders) {
|
|
@@ -846,8 +850,17 @@ class LambdaResponseStreaming extends Writable {
|
|
|
846
850
|
return this._headersSent;
|
|
847
851
|
}
|
|
848
852
|
flushHeaders() {
|
|
849
|
-
|
|
853
|
+
// DIAGNOSTIC: Log every flushHeaders call with stack trace
|
|
854
|
+
const caller = new Error().stack?.split("\n").slice(1, 5).join("\n");
|
|
855
|
+
console.log("[DIAG:LambdaResponseStreaming:flushHeaders] Called", {
|
|
856
|
+
statusCode: this.statusCode,
|
|
857
|
+
headersSent: this._headersSent,
|
|
858
|
+
caller,
|
|
859
|
+
});
|
|
860
|
+
if (this._headersSent) {
|
|
861
|
+
console.log("[DIAG:LambdaResponseStreaming:flushHeaders] Already sent, returning early");
|
|
850
862
|
return;
|
|
863
|
+
}
|
|
851
864
|
const headers = {};
|
|
852
865
|
for (const [key, value] of this._headers) {
|
|
853
866
|
headers[key] = Array.isArray(value) ? value.join(", ") : String(value);
|
|
@@ -856,6 +869,10 @@ class LambdaResponseStreaming extends Writable {
|
|
|
856
869
|
headers,
|
|
857
870
|
statusCode: this.statusCode,
|
|
858
871
|
};
|
|
872
|
+
// DIAGNOSTIC: Log what we're sending to Lambda
|
|
873
|
+
console.log("[DIAG:LambdaResponseStreaming:flushHeaders] Creating wrapped stream", {
|
|
874
|
+
metadata,
|
|
875
|
+
});
|
|
859
876
|
// Wrap the stream with metadata using awslambda global
|
|
860
877
|
this._wrappedStream = awslambda.HttpResponseStream.from(this._responseStream, metadata);
|
|
861
878
|
this._headersSent = true;
|
|
@@ -889,6 +906,14 @@ class LambdaResponseStreaming extends Writable {
|
|
|
889
906
|
return this;
|
|
890
907
|
}
|
|
891
908
|
status(code) {
|
|
909
|
+
// DIAGNOSTIC: Log status code changes
|
|
910
|
+
const caller = new Error().stack?.split("\n").slice(1, 4).join("\n");
|
|
911
|
+
console.log("[DIAG:LambdaResponseStreaming:status] Setting status", {
|
|
912
|
+
newCode: code,
|
|
913
|
+
previousCode: this.statusCode,
|
|
914
|
+
headersSent: this._headersSent,
|
|
915
|
+
caller,
|
|
916
|
+
});
|
|
892
917
|
this.statusCode = code;
|
|
893
918
|
return this;
|
|
894
919
|
}
|
|
@@ -934,10 +959,17 @@ class LambdaResponseStreaming extends Writable {
|
|
|
934
959
|
const buffer = Buffer.isBuffer(chunk)
|
|
935
960
|
? chunk
|
|
936
961
|
: Buffer.from(chunk, encoding);
|
|
962
|
+
// DIAGNOSTIC: Log every write
|
|
963
|
+
console.log("[DIAG:LambdaResponseStreaming:_write] Called", {
|
|
964
|
+
chunkLength: buffer.length,
|
|
965
|
+
headersSent: this._headersSent,
|
|
966
|
+
statusCode: this.statusCode,
|
|
967
|
+
});
|
|
937
968
|
if (!this._headersSent) {
|
|
938
969
|
// Buffer writes until headers are sent
|
|
939
970
|
this._pendingWrites.push({ callback: () => callback(), chunk: buffer });
|
|
940
971
|
// Auto-flush headers on first write
|
|
972
|
+
console.log("[DIAG:LambdaResponseStreaming:_write] Auto-flushing headers on first write");
|
|
941
973
|
this.flushHeaders();
|
|
942
974
|
}
|
|
943
975
|
else {
|
|
@@ -946,7 +978,14 @@ class LambdaResponseStreaming extends Writable {
|
|
|
946
978
|
}
|
|
947
979
|
}
|
|
948
980
|
_final(callback) {
|
|
981
|
+
// DIAGNOSTIC: Log _final call
|
|
982
|
+
console.log("[DIAG:LambdaResponseStreaming:_final] Called", {
|
|
983
|
+
headersSent: this._headersSent,
|
|
984
|
+
statusCode: this.statusCode,
|
|
985
|
+
hasWrappedStream: !!this._wrappedStream,
|
|
986
|
+
});
|
|
949
987
|
if (!this._headersSent) {
|
|
988
|
+
console.log("[DIAG:LambdaResponseStreaming:_final] Headers not sent, flushing now");
|
|
950
989
|
this.flushHeaders();
|
|
951
990
|
}
|
|
952
991
|
this._wrappedStream?.end();
|
|
@@ -1459,7 +1498,8 @@ const decorateResponse = (res, { handler = "", version = process.env.PROJECT_VER
|
|
|
1459
1498
|
// X-Powered-By, override "Express" but nothing else
|
|
1460
1499
|
const currentPoweredBy = safeGetHeader(extRes, HTTP.HEADER.POWERED_BY);
|
|
1461
1500
|
if (!currentPoweredBy || currentPoweredBy === "Express") {
|
|
1462
|
-
|
|
1501
|
+
// DIAGNOSTIC: Include dev marker to verify build deployment
|
|
1502
|
+
safeSetHeader(extRes, HTTP.HEADER.POWERED_BY, `${JAYPIE.LIB.EXPRESS}#dev-178`);
|
|
1463
1503
|
}
|
|
1464
1504
|
// X-Project-Environment
|
|
1465
1505
|
if (process.env.PROJECT_ENV) {
|
|
@@ -1556,8 +1596,16 @@ function isLambdaMockResponse(res) {
|
|
|
1556
1596
|
* Uses Symbol marker to survive prototype chain modifications from Express and dd-trace.
|
|
1557
1597
|
*/
|
|
1558
1598
|
function isLambdaStreamingResponse(res) {
|
|
1559
|
-
|
|
1560
|
-
|
|
1599
|
+
const symbolValue = res[JAYPIE_LAMBDA_STREAMING];
|
|
1600
|
+
const result = symbolValue === true;
|
|
1601
|
+
// DIAGNOSTIC: Log symbol check
|
|
1602
|
+
console.log("[DIAG:expressHandler:isLambdaStreamingResponse] Check", {
|
|
1603
|
+
symbolValue,
|
|
1604
|
+
result,
|
|
1605
|
+
resConstructorName: res?.constructor?.name,
|
|
1606
|
+
hasFlushHeaders: typeof res.flushHeaders === "function",
|
|
1607
|
+
});
|
|
1608
|
+
return result;
|
|
1561
1609
|
}
|
|
1562
1610
|
/**
|
|
1563
1611
|
* Safely send a JSON response, avoiding dd-trace interception.
|
|
@@ -1591,15 +1639,29 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1591
1639
|
return;
|
|
1592
1640
|
}
|
|
1593
1641
|
// Fall back to standard Express methods for real responses
|
|
1642
|
+
// DIAGNOSTIC: Log before setting status
|
|
1643
|
+
console.log("[DIAG:expressHandler:safeSendJson] Before res.status()", {
|
|
1644
|
+
statusCode,
|
|
1645
|
+
currentStatusCode: res.statusCode,
|
|
1646
|
+
});
|
|
1594
1647
|
res.status(statusCode);
|
|
1648
|
+
console.log("[DIAG:expressHandler:safeSendJson] After res.status()", {
|
|
1649
|
+
statusCode,
|
|
1650
|
+
newStatusCode: res.statusCode,
|
|
1651
|
+
});
|
|
1595
1652
|
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1596
1653
|
// initialize the stream wrapper. This ensures the status code is captured
|
|
1597
1654
|
// before any writes occur (which would auto-flush with default 200).
|
|
1598
1655
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1599
|
-
|
|
1600
|
-
|
|
1656
|
+
const isStreaming = isLambdaStreamingResponse(res);
|
|
1657
|
+
console.log("[DIAG:expressHandler:safeSendJson] Streaming check", {
|
|
1658
|
+
isStreaming,
|
|
1659
|
+
});
|
|
1660
|
+
if (isStreaming && typeof res.flushHeaders === "function") {
|
|
1661
|
+
console.log("[DIAG:expressHandler:safeSendJson] Calling flushHeaders explicitly");
|
|
1601
1662
|
res.flushHeaders();
|
|
1602
1663
|
}
|
|
1664
|
+
console.log("[DIAG:expressHandler:safeSendJson] Calling res.json()");
|
|
1603
1665
|
res.json(data);
|
|
1604
1666
|
}
|
|
1605
1667
|
/**
|
|
@@ -1628,19 +1690,35 @@ function safeSend(res, statusCode, body) {
|
|
|
1628
1690
|
return;
|
|
1629
1691
|
}
|
|
1630
1692
|
// Fall back to standard Express methods for real responses
|
|
1693
|
+
// DIAGNOSTIC: Log before setting status
|
|
1694
|
+
console.log("[DIAG:expressHandler:safeSend] Before res.status()", {
|
|
1695
|
+
statusCode,
|
|
1696
|
+
currentStatusCode: res.statusCode,
|
|
1697
|
+
hasBody: body !== undefined,
|
|
1698
|
+
});
|
|
1631
1699
|
res.status(statusCode);
|
|
1700
|
+
console.log("[DIAG:expressHandler:safeSend] After res.status()", {
|
|
1701
|
+
statusCode,
|
|
1702
|
+
newStatusCode: res.statusCode,
|
|
1703
|
+
});
|
|
1632
1704
|
// CRITICAL: For Lambda streaming responses, flush headers before send to
|
|
1633
1705
|
// initialize the stream wrapper. This ensures the status code is captured
|
|
1634
1706
|
// before any writes occur (which would auto-flush with default 200).
|
|
1635
1707
|
// Uses Symbol marker for reliable detection that survives prototype manipulation.
|
|
1636
|
-
|
|
1637
|
-
|
|
1708
|
+
const isStreaming = isLambdaStreamingResponse(res);
|
|
1709
|
+
console.log("[DIAG:expressHandler:safeSend] Streaming check", {
|
|
1710
|
+
isStreaming,
|
|
1711
|
+
});
|
|
1712
|
+
if (isStreaming && typeof res.flushHeaders === "function") {
|
|
1713
|
+
console.log("[DIAG:expressHandler:safeSend] Calling flushHeaders explicitly");
|
|
1638
1714
|
res.flushHeaders();
|
|
1639
1715
|
}
|
|
1640
1716
|
if (body !== undefined) {
|
|
1717
|
+
console.log("[DIAG:expressHandler:safeSend] Calling res.send(body)");
|
|
1641
1718
|
res.send(body);
|
|
1642
1719
|
}
|
|
1643
1720
|
else {
|
|
1721
|
+
console.log("[DIAG:expressHandler:safeSend] Calling res.send() (no body)");
|
|
1644
1722
|
res.send();
|
|
1645
1723
|
}
|
|
1646
1724
|
}
|