unnbound-events 2.0.20 → 2.0.21-beta.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/lib/event.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface IncomingEvent<R extends IncomingRequest = IncomingRequest> {
|
|
|
25
25
|
export interface StrictEventHandlerResult {
|
|
26
26
|
status: StatusCode;
|
|
27
27
|
headers?: Record<string, string>;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Response body. Objects are JSON-serialized; `Uint8Array` (including Buffer)
|
|
30
|
+
* and `ArrayBuffer` are sent verbatim as binary — required for protocols like
|
|
31
|
+
* AS2 whose responses (signed S/MIME MDNs) must not be JSON-mangled. Set the
|
|
32
|
+
* `content-type` header explicitly when returning binary.
|
|
33
|
+
*/
|
|
34
|
+
body?: object | Uint8Array | ArrayBuffer | undefined | null;
|
|
29
35
|
}
|
|
30
36
|
export type EventHandlerResult = Partial<StrictEventHandlerResult> | undefined | null | undefined;
|
|
@@ -8,12 +8,12 @@ export interface Endpoint<I> {
|
|
|
8
8
|
(path: string, middleware: MiddlewareHandler<I>, handler: Handler<I>): MaybePromise<void>;
|
|
9
9
|
}
|
|
10
10
|
export type EndpointArgs<I> = [path: string, handler: Handler<I>] | [path: string, middleware: MiddlewareHandler<I>, handler: Handler<I>];
|
|
11
|
-
export declare const buildEndpointArguments: (...args: EndpointArgs<EventVariables<{}>>) => (string |
|
|
11
|
+
export declare const buildEndpointArguments: (...args: EndpointArgs<EventVariables<{}>>) => (string | Handler<Context<EventEnvironment<{}>, any, {}>, Response> | MiddlewareHandler<Context<EventEnvironment<{}>, any, {}>>)[];
|
|
12
12
|
export declare const parseEndpointArguments: (...args: EndpointArgs<EventVariables<{}>>) => {
|
|
13
13
|
path: string;
|
|
14
14
|
middlewares: MiddlewareHandler<EventVariables<{}>>[];
|
|
15
15
|
handler: Handler<EventVariables<{}>, EventHandlerResult>;
|
|
16
16
|
};
|
|
17
17
|
export declare const patchEndpoint: <V extends object>(handler: Handler<EventVariables<V>>) => Handler<Context<EventEnvironment<V>>, Response>;
|
|
18
|
-
export declare const respondWith: (context: Context, result: StrictEventHandlerResult) => (Response & import("hono").TypedResponse<null, 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511
|
|
18
|
+
export declare const respondWith: (context: Context, result: StrictEventHandlerResult) => (Response & import("hono").TypedResponse<never, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "json">) | (Response & import("hono").TypedResponse<null, -1 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">) | (Response & import("hono").TypedResponse<ArrayBuffer, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">);
|
|
19
19
|
export declare const attachTraceHeaders: (headers?: Record<string, string>) => Record<string, string> | undefined;
|
|
@@ -33,6 +33,15 @@ const respondWith = (context, result) => {
|
|
|
33
33
|
const headers = (0, exports.attachTraceHeaders)(result.headers);
|
|
34
34
|
if (!result.body)
|
|
35
35
|
return context.body(null, result.status, headers);
|
|
36
|
+
// Binary bodies (Buffer/Uint8Array/ArrayBuffer) go out verbatim — JSON-serializing
|
|
37
|
+
// them corrupts wire protocols like AS2, whose signed S/MIME MDN response must be
|
|
38
|
+
// byte-exact. Buffers can be views over a pooled ArrayBuffer, so slice to the view.
|
|
39
|
+
if (result.body instanceof Uint8Array || result.body instanceof ArrayBuffer) {
|
|
40
|
+
const bytes = result.body instanceof ArrayBuffer
|
|
41
|
+
? result.body
|
|
42
|
+
: result.body.buffer.slice(result.body.byteOffset, result.body.byteOffset + result.body.byteLength);
|
|
43
|
+
return context.body(bytes, result.status, headers);
|
|
44
|
+
}
|
|
36
45
|
return context.json(result.body, result.status, headers);
|
|
37
46
|
};
|
|
38
47
|
exports.respondWith = respondWith;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare const buildIncomingPayload: (event: IncomingEvent<MatchedIncoming
|
|
|
17
17
|
source: EventSource;
|
|
18
18
|
delay: number | undefined;
|
|
19
19
|
http: {
|
|
20
|
-
response?: StrictEventHandlerResult | undefined;
|
|
21
20
|
url: string;
|
|
22
21
|
method: string;
|
|
23
22
|
query: Record<string, any>;
|
|
@@ -26,8 +25,9 @@ export declare const buildIncomingPayload: (event: IncomingEvent<MatchedIncoming
|
|
|
26
25
|
incoming: boolean;
|
|
27
26
|
request: {
|
|
28
27
|
headers: Record<string, string>;
|
|
29
|
-
body:
|
|
28
|
+
body: unknown;
|
|
30
29
|
};
|
|
30
|
+
response?: StrictEventHandlerResult | undefined;
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
export declare const batchArray: <T>(array: T[], size: number) => T[][];
|
package/dist/lib/utils.js
CHANGED
|
@@ -78,13 +78,20 @@ const deserializeMetadata = (request) => ({
|
|
|
78
78
|
source: request.headers[sourceKey],
|
|
79
79
|
timestamp: request.headers[timestampKey] ? Number.parseInt(request.headers[timestampKey]) : undefined,
|
|
80
80
|
});
|
|
81
|
+
/** Trace-safe body representation: binary bodies become a marker, not a byte dump. */
|
|
82
|
+
const describeBody = (body) => {
|
|
83
|
+
if (body instanceof Uint8Array || body instanceof ArrayBuffer) {
|
|
84
|
+
return { binary: true, byteLength: body.byteLength };
|
|
85
|
+
}
|
|
86
|
+
return (0, utils_1.safeJsonParse)(body);
|
|
87
|
+
};
|
|
81
88
|
const buildResponsePayload = (result) => ({
|
|
82
89
|
status: result?.status ?? 204,
|
|
83
90
|
headers: {
|
|
84
91
|
'content-type': 'application/json; charset=utf-8',
|
|
85
92
|
...(result?.headers ? (0, exports.normalizeHeaders)(result.headers) : undefined),
|
|
86
93
|
},
|
|
87
|
-
body: result?.body ? (
|
|
94
|
+
body: result?.body ? describeBody(result.body) : undefined,
|
|
88
95
|
});
|
|
89
96
|
const buildIncomingPayload = (event, result) => {
|
|
90
97
|
return {
|
|
@@ -102,7 +109,7 @@ const buildIncomingPayload = (event, result) => {
|
|
|
102
109
|
incoming: true,
|
|
103
110
|
request: {
|
|
104
111
|
headers: event.request.headers,
|
|
105
|
-
body: (
|
|
112
|
+
body: describeBody(event.request.body),
|
|
106
113
|
},
|
|
107
114
|
...(result && {
|
|
108
115
|
response: result.error
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
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.0.
|
|
4
|
+
"version": "2.0.21-beta.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
11
|
+
"format": "biome format --write .",
|
|
12
|
+
"format:check": "biome format .",
|
|
13
|
+
"prepublishOnly": "pnpm run build",
|
|
14
|
+
"start:example": "tsx watch examples/node-server.ts",
|
|
15
|
+
"version:bump": "npm version patch"
|
|
16
|
+
},
|
|
7
17
|
"author": "Unnbound Team",
|
|
8
18
|
"license": "MIT",
|
|
9
19
|
"repository": {
|
|
@@ -25,7 +35,6 @@
|
|
|
25
35
|
"devDependencies": {
|
|
26
36
|
"@types/jest": "^29.5.12",
|
|
27
37
|
"@types/node": "^24.12.2",
|
|
28
|
-
"typescript": "^5.8.3",
|
|
29
38
|
"vitest": "^4.0.15"
|
|
30
39
|
},
|
|
31
40
|
"files": [
|
|
@@ -36,14 +45,5 @@
|
|
|
36
45
|
"engines": {
|
|
37
46
|
"node": ">=22"
|
|
38
47
|
},
|
|
39
|
-
"sideEffects": false
|
|
40
|
-
|
|
41
|
-
"build": "tsc",
|
|
42
|
-
"test": "vitest run",
|
|
43
|
-
"typecheck": "tsgo --noEmit",
|
|
44
|
-
"format": "biome format --write .",
|
|
45
|
-
"format:check": "biome format .",
|
|
46
|
-
"start:example": "tsx watch examples/node-server.ts",
|
|
47
|
-
"version:bump": "npm version patch"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
48
|
+
"sideEffects": false
|
|
49
|
+
}
|