unnbound-events 2.1.0-beta.1 → 2.1.0-beta.2
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/lib/routing/as2.js +30 -2
- package/package.json +1 -1
package/dist/lib/routing/as2.js
CHANGED
|
@@ -5,6 +5,32 @@ const unnbound_logger_sdk_1 = require("unnbound-logger-sdk");
|
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const endpoint_1 = require("./endpoint");
|
|
8
|
+
/**
|
|
9
|
+
* Transient platform failures a partner should re-send against. `As2SdkError` already computed
|
|
10
|
+
* these from the platform response, but it arrives here as a plain unknown — this package cannot
|
|
11
|
+
* import `@ontemper/as2` (the dependency runs the other way), so the shape is read defensively.
|
|
12
|
+
*/
|
|
13
|
+
const RETRYABLE_AS2_STATUSES = [502, 503, 504];
|
|
14
|
+
/**
|
|
15
|
+
* AS2 partners drive their re-send behaviour off the status code, so collapsing every failure to
|
|
16
|
+
* a flat 500 throws away the one signal telling them to try again — the same signal the
|
|
17
|
+
* in-flight/parked path already sends deliberately as a 503. Lift the transient statuses onto the
|
|
18
|
+
* wire; the message stays generic so no internal detail reaches the partner.
|
|
19
|
+
*/
|
|
20
|
+
const toWireFailure = (error) => {
|
|
21
|
+
if (error && typeof error === 'object') {
|
|
22
|
+
const { name, status } = error;
|
|
23
|
+
const retryable = RETRYABLE_AS2_STATUSES.find((candidate) => candidate === status);
|
|
24
|
+
if (name === 'As2SdkError' && retryable) {
|
|
25
|
+
return new error_1.ServerError({
|
|
26
|
+
message: 'AS2 message could not be processed; retry later',
|
|
27
|
+
status: retryable,
|
|
28
|
+
cause: error,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return error_1.ServerError.fromError(error);
|
|
33
|
+
};
|
|
8
34
|
/**
|
|
9
35
|
* Verify-then-bind AS2 endpoint. The public `x-unnbound-trace-id` header is never AS2
|
|
10
36
|
* continuation authority: the route starts on a fresh trace, runs `prepare` (the hidden
|
|
@@ -38,7 +64,7 @@ const as2Endpoint = (prepare, handler) => {
|
|
|
38
64
|
}
|
|
39
65
|
catch (error) {
|
|
40
66
|
return (0, unnbound_logger_sdk_1.withTrace)(async () => {
|
|
41
|
-
const failure =
|
|
67
|
+
const failure = toWireFailure(error);
|
|
42
68
|
// Bookend the request on its own failure trace: the span records the sanitized
|
|
43
69
|
// AS2 payload and rethrows; the wire response carries no protocol claims.
|
|
44
70
|
await (0, unnbound_logger_sdk_1.startSpan)('Event request', () => Promise.reject(failure), (o) => (0, utils_1.buildAs2IncomingPayload)(event, o)).catch(() => undefined);
|
|
@@ -61,7 +87,9 @@ const as2Endpoint = (prepare, handler) => {
|
|
|
61
87
|
catch (error) {
|
|
62
88
|
// The span above already logged the failure on the bound trace; respond with the
|
|
63
89
|
// sanitized shape instead of rethrowing into the header-derived middleware trace.
|
|
64
|
-
|
|
90
|
+
// `acknowledge()` runs in here too, so a transient platform failure keeps its
|
|
91
|
+
// retryable status rather than becoming an indistinguishable 500.
|
|
92
|
+
const result = toWireFailure(error).toJson();
|
|
65
93
|
return { ...result, headers: (0, endpoint_1.attachTraceHeaders)(result.headers) };
|
|
66
94
|
}
|
|
67
95
|
}, { traceId });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unnbound-events",
|
|
3
3
|
"description": "Unified events SDK to handle HTTP routes and queued messages with a single routing API.",
|
|
4
|
-
"version": "2.1.0-beta.
|
|
4
|
+
"version": "2.1.0-beta.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "Unnbound Team",
|