@fabricorg/webhook-delivery 0.1.2 → 0.1.3
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/CHANGELOG.md +23 -0
- package/README.md +10 -4
- package/dist/index.cjs +8641 -6289
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2227 -779
- package/dist/index.d.ts +2227 -779
- package/dist/index.js +8640 -6287
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +1089 -746
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +102 -32
- package/dist/node.d.ts +102 -32
- package/dist/node.js +1088 -744
- package/dist/node.js.map +1 -1
- package/package.json +8 -7
- package/dist/destination-joCBtgvY.d.cts +0 -1444
- package/dist/destination-joCBtgvY.d.ts +0 -1444
package/dist/node.d.cts
CHANGED
|
@@ -1,29 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "@fabricorg/platform-host";
|
|
2
|
+
//#region src/ports.d.ts
|
|
3
|
+
/** Bounds every awaited port call. */
|
|
4
|
+
interface WebhookCallOptions {
|
|
5
|
+
/** The absolute time after which the call's result is ignored. */
|
|
6
|
+
readonly deadline: Date;
|
|
7
|
+
/** Aborted when the caller stops waiting; implementations should stop work. */
|
|
8
|
+
readonly signal: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
/** One resolved address of a destination host. */
|
|
11
|
+
interface WebhookResolvedAddress {
|
|
12
|
+
readonly address: string;
|
|
13
|
+
readonly family: 4 | 6;
|
|
14
|
+
}
|
|
15
|
+
/** A destination that passed the URL rules and whose every resolved answer is public. */
|
|
16
|
+
interface WebhookVettedDestination {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
/** Kept for SNI and certificate hostname verification. */
|
|
19
|
+
readonly hostname: string;
|
|
20
|
+
readonly port: 443;
|
|
21
|
+
/** The vetted addresses the transport posts to without re-resolving. */
|
|
22
|
+
readonly addresses: readonly WebhookResolvedAddress[];
|
|
23
|
+
}
|
|
24
|
+
/** One HTTP request handed to the transport. */
|
|
25
|
+
interface WebhookTransportRequest {
|
|
26
|
+
readonly destination: WebhookVettedDestination;
|
|
27
|
+
readonly method: "POST";
|
|
28
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
29
|
+
readonly body: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What the transport observed. `not_sent` means the request never started
|
|
33
|
+
* (deadline already passed, or the signal aborted while queued) and the
|
|
34
|
+
* dispatcher releases the intent without spending budget. `timeout` covers a
|
|
35
|
+
* deadline or abort after the request started. Response bodies are not
|
|
36
|
+
* returned.
|
|
37
|
+
*/
|
|
38
|
+
type WebhookTransportResult = {
|
|
39
|
+
readonly kind: "response";
|
|
40
|
+
readonly status: number;
|
|
41
|
+
readonly retryAfter?: string | null;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "network_error" | "timeout" | "dns_failure" | "invalid_url" | "private_address";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "not_sent";
|
|
46
|
+
readonly reason: "deadline_expired" | "aborted";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Posts to the vetted address without re-resolving, verifies certificate and
|
|
50
|
+
* hostname, refuses redirects and bounds the response. It must reject a
|
|
51
|
+
* handoff whose deadline has passed and never start a request whose signal
|
|
52
|
+
* aborted while queued (R3).
|
|
53
|
+
*/
|
|
54
|
+
interface WebhookTransport {
|
|
55
|
+
send(request: WebhookTransportRequest, options: WebhookCallOptions): Promise<WebhookTransportResult>;
|
|
56
|
+
}
|
|
57
|
+
/** The injected clock. */
|
|
58
|
+
interface WebhookClock {
|
|
59
|
+
now(): Date;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/node/transport.d.ts
|
|
4
63
|
/** The default response body cap: past it the connection is closed (the crossing chunk is already read). */
|
|
5
|
-
declare const DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES = 65536;
|
|
64
|
+
export declare const DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES = 65536;
|
|
6
65
|
/** The default number of requests one transport runs at once; later calls wait in its queue. */
|
|
7
|
-
declare const DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS = 16;
|
|
66
|
+
export declare const DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS = 16;
|
|
8
67
|
/** Options for {@link createNodeWebhookTransport}. */
|
|
9
68
|
interface NodeWebhookTransportOptions {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Response body bytes after which the connection is closed; default
|
|
71
|
+
* {@link DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES}. The check runs per
|
|
72
|
+
* chunk, so the bytes read can exceed it by up to one chunk. The body is
|
|
73
|
+
* discarded as it arrives and never kept or returned: only the status and
|
|
74
|
+
* `Retry-After` are.
|
|
75
|
+
*/
|
|
76
|
+
readonly maxResponseBytes?: number;
|
|
77
|
+
/** Requests in flight at once; default {@link DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS}. */
|
|
78
|
+
readonly maxConcurrentRequests?: number;
|
|
79
|
+
/**
|
|
80
|
+
* PEM trust anchors that replace Node's bundled roots, for a receiver
|
|
81
|
+
* behind a private CA. Certificate and hostname verification stay on.
|
|
82
|
+
*/
|
|
83
|
+
readonly ca?: string | readonly string[];
|
|
84
|
+
/** The clock the call's deadline is compared with; the system clock by default. */
|
|
85
|
+
readonly clock?: WebhookClock;
|
|
27
86
|
}
|
|
28
87
|
/**
|
|
29
88
|
* The Node `WebhookTransport` (ADR 0018 decision 6, R3, R8).
|
|
@@ -68,16 +127,27 @@ interface NodeWebhookTransportOptions {
|
|
|
68
127
|
* @throws {WebhookDeliveryConfigError} when `maxResponseBytes` or
|
|
69
128
|
* `maxConcurrentRequests` (at most 1024) is not a positive whole number.
|
|
70
129
|
*/
|
|
71
|
-
declare function createNodeWebhookTransport(options?: NodeWebhookTransportOptions): WebhookTransport;
|
|
72
|
-
|
|
130
|
+
export declare function createNodeWebhookTransport(options?: NodeWebhookTransportOptions): WebhookTransport;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/destination.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* Looks up a hostname's addresses. It is passed `{ deadline, signal }`; the
|
|
135
|
+
* resolver aborts `signal` when it stops waiting, and ignores any answer that
|
|
136
|
+
* arrives after that. Each answer is `{ address, family }` with a textual IPv4
|
|
137
|
+
* or IPv6 address. `createNodeWebhookDnsLookup()` at
|
|
138
|
+
* `@fabricorg/webhook-delivery/node` is one implementation.
|
|
139
|
+
*/
|
|
140
|
+
type WebhookDnsLookup = (hostname: string, options: WebhookCallOptions) => Promise<readonly WebhookResolvedAddress[]>;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/node/lookup.d.ts
|
|
73
143
|
/** The default per-query timeout of {@link createNodeWebhookDnsLookup}. */
|
|
74
|
-
declare const DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS = 5000;
|
|
144
|
+
export declare const DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS = 5000;
|
|
75
145
|
/** Options for {@link createNodeWebhookDnsLookup}. */
|
|
76
146
|
interface NodeWebhookDnsLookupOptions {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
/** DNS servers (`"ip"` or `"ip:port"`), as `Resolver.setServers` takes them; the system's by default. */
|
|
148
|
+
readonly servers?: readonly string[];
|
|
149
|
+
/** Timeout of each A and AAAA query; default {@link DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS}. */
|
|
150
|
+
readonly timeoutMs?: number;
|
|
81
151
|
}
|
|
82
152
|
/**
|
|
83
153
|
* A {@link WebhookDnsLookup} for `createWebhookDestinationResolver()` built on
|
|
@@ -99,6 +169,6 @@ interface NodeWebhookDnsLookupOptions {
|
|
|
99
169
|
* @throws {WebhookDeliveryConfigError} when `timeoutMs` is not a positive
|
|
100
170
|
* whole number of at most `WEBHOOK_MAX_TIMER_MS`.
|
|
101
171
|
*/
|
|
102
|
-
declare function createNodeWebhookDnsLookup(options?: NodeWebhookDnsLookupOptions): WebhookDnsLookup;
|
|
103
|
-
|
|
104
|
-
export {
|
|
172
|
+
export declare function createNodeWebhookDnsLookup(options?: NodeWebhookDnsLookupOptions): WebhookDnsLookup;
|
|
173
|
+
//#endregion
|
|
174
|
+
export type { NodeWebhookDnsLookupOptions, NodeWebhookTransportOptions };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,29 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "@fabricorg/platform-host";
|
|
2
|
+
//#region src/ports.d.ts
|
|
3
|
+
/** Bounds every awaited port call. */
|
|
4
|
+
interface WebhookCallOptions {
|
|
5
|
+
/** The absolute time after which the call's result is ignored. */
|
|
6
|
+
readonly deadline: Date;
|
|
7
|
+
/** Aborted when the caller stops waiting; implementations should stop work. */
|
|
8
|
+
readonly signal: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
/** One resolved address of a destination host. */
|
|
11
|
+
interface WebhookResolvedAddress {
|
|
12
|
+
readonly address: string;
|
|
13
|
+
readonly family: 4 | 6;
|
|
14
|
+
}
|
|
15
|
+
/** A destination that passed the URL rules and whose every resolved answer is public. */
|
|
16
|
+
interface WebhookVettedDestination {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
/** Kept for SNI and certificate hostname verification. */
|
|
19
|
+
readonly hostname: string;
|
|
20
|
+
readonly port: 443;
|
|
21
|
+
/** The vetted addresses the transport posts to without re-resolving. */
|
|
22
|
+
readonly addresses: readonly WebhookResolvedAddress[];
|
|
23
|
+
}
|
|
24
|
+
/** One HTTP request handed to the transport. */
|
|
25
|
+
interface WebhookTransportRequest {
|
|
26
|
+
readonly destination: WebhookVettedDestination;
|
|
27
|
+
readonly method: "POST";
|
|
28
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
29
|
+
readonly body: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What the transport observed. `not_sent` means the request never started
|
|
33
|
+
* (deadline already passed, or the signal aborted while queued) and the
|
|
34
|
+
* dispatcher releases the intent without spending budget. `timeout` covers a
|
|
35
|
+
* deadline or abort after the request started. Response bodies are not
|
|
36
|
+
* returned.
|
|
37
|
+
*/
|
|
38
|
+
type WebhookTransportResult = {
|
|
39
|
+
readonly kind: "response";
|
|
40
|
+
readonly status: number;
|
|
41
|
+
readonly retryAfter?: string | null;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "network_error" | "timeout" | "dns_failure" | "invalid_url" | "private_address";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "not_sent";
|
|
46
|
+
readonly reason: "deadline_expired" | "aborted";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Posts to the vetted address without re-resolving, verifies certificate and
|
|
50
|
+
* hostname, refuses redirects and bounds the response. It must reject a
|
|
51
|
+
* handoff whose deadline has passed and never start a request whose signal
|
|
52
|
+
* aborted while queued (R3).
|
|
53
|
+
*/
|
|
54
|
+
interface WebhookTransport {
|
|
55
|
+
send(request: WebhookTransportRequest, options: WebhookCallOptions): Promise<WebhookTransportResult>;
|
|
56
|
+
}
|
|
57
|
+
/** The injected clock. */
|
|
58
|
+
interface WebhookClock {
|
|
59
|
+
now(): Date;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/node/transport.d.ts
|
|
4
63
|
/** The default response body cap: past it the connection is closed (the crossing chunk is already read). */
|
|
5
|
-
declare const DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES = 65536;
|
|
64
|
+
export declare const DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES = 65536;
|
|
6
65
|
/** The default number of requests one transport runs at once; later calls wait in its queue. */
|
|
7
|
-
declare const DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS = 16;
|
|
66
|
+
export declare const DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS = 16;
|
|
8
67
|
/** Options for {@link createNodeWebhookTransport}. */
|
|
9
68
|
interface NodeWebhookTransportOptions {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Response body bytes after which the connection is closed; default
|
|
71
|
+
* {@link DEFAULT_NODE_WEBHOOK_MAX_RESPONSE_BYTES}. The check runs per
|
|
72
|
+
* chunk, so the bytes read can exceed it by up to one chunk. The body is
|
|
73
|
+
* discarded as it arrives and never kept or returned: only the status and
|
|
74
|
+
* `Retry-After` are.
|
|
75
|
+
*/
|
|
76
|
+
readonly maxResponseBytes?: number;
|
|
77
|
+
/** Requests in flight at once; default {@link DEFAULT_NODE_WEBHOOK_MAX_CONCURRENT_REQUESTS}. */
|
|
78
|
+
readonly maxConcurrentRequests?: number;
|
|
79
|
+
/**
|
|
80
|
+
* PEM trust anchors that replace Node's bundled roots, for a receiver
|
|
81
|
+
* behind a private CA. Certificate and hostname verification stay on.
|
|
82
|
+
*/
|
|
83
|
+
readonly ca?: string | readonly string[];
|
|
84
|
+
/** The clock the call's deadline is compared with; the system clock by default. */
|
|
85
|
+
readonly clock?: WebhookClock;
|
|
27
86
|
}
|
|
28
87
|
/**
|
|
29
88
|
* The Node `WebhookTransport` (ADR 0018 decision 6, R3, R8).
|
|
@@ -68,16 +127,27 @@ interface NodeWebhookTransportOptions {
|
|
|
68
127
|
* @throws {WebhookDeliveryConfigError} when `maxResponseBytes` or
|
|
69
128
|
* `maxConcurrentRequests` (at most 1024) is not a positive whole number.
|
|
70
129
|
*/
|
|
71
|
-
declare function createNodeWebhookTransport(options?: NodeWebhookTransportOptions): WebhookTransport;
|
|
72
|
-
|
|
130
|
+
export declare function createNodeWebhookTransport(options?: NodeWebhookTransportOptions): WebhookTransport;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/destination.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* Looks up a hostname's addresses. It is passed `{ deadline, signal }`; the
|
|
135
|
+
* resolver aborts `signal` when it stops waiting, and ignores any answer that
|
|
136
|
+
* arrives after that. Each answer is `{ address, family }` with a textual IPv4
|
|
137
|
+
* or IPv6 address. `createNodeWebhookDnsLookup()` at
|
|
138
|
+
* `@fabricorg/webhook-delivery/node` is one implementation.
|
|
139
|
+
*/
|
|
140
|
+
type WebhookDnsLookup = (hostname: string, options: WebhookCallOptions) => Promise<readonly WebhookResolvedAddress[]>;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/node/lookup.d.ts
|
|
73
143
|
/** The default per-query timeout of {@link createNodeWebhookDnsLookup}. */
|
|
74
|
-
declare const DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS = 5000;
|
|
144
|
+
export declare const DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS = 5000;
|
|
75
145
|
/** Options for {@link createNodeWebhookDnsLookup}. */
|
|
76
146
|
interface NodeWebhookDnsLookupOptions {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
/** DNS servers (`"ip"` or `"ip:port"`), as `Resolver.setServers` takes them; the system's by default. */
|
|
148
|
+
readonly servers?: readonly string[];
|
|
149
|
+
/** Timeout of each A and AAAA query; default {@link DEFAULT_NODE_WEBHOOK_DNS_TIMEOUT_MS}. */
|
|
150
|
+
readonly timeoutMs?: number;
|
|
81
151
|
}
|
|
82
152
|
/**
|
|
83
153
|
* A {@link WebhookDnsLookup} for `createWebhookDestinationResolver()` built on
|
|
@@ -99,6 +169,6 @@ interface NodeWebhookDnsLookupOptions {
|
|
|
99
169
|
* @throws {WebhookDeliveryConfigError} when `timeoutMs` is not a positive
|
|
100
170
|
* whole number of at most `WEBHOOK_MAX_TIMER_MS`.
|
|
101
171
|
*/
|
|
102
|
-
declare function createNodeWebhookDnsLookup(options?: NodeWebhookDnsLookupOptions): WebhookDnsLookup;
|
|
103
|
-
|
|
104
|
-
export {
|
|
172
|
+
export declare function createNodeWebhookDnsLookup(options?: NodeWebhookDnsLookupOptions): WebhookDnsLookup;
|
|
173
|
+
//#endregion
|
|
174
|
+
export type { NodeWebhookDnsLookupOptions, NodeWebhookTransportOptions };
|