@venturekit/integrations 0.0.50 → 0.0.51
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/README.md +45 -2
- package/dist/http/client.d.ts +24 -1
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +70 -22
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/net/address.d.ts +29 -0
- package/dist/net/address.d.ts.map +1 -0
- package/dist/net/address.js +133 -0
- package/dist/net/address.js.map +1 -0
- package/dist/net/errors.d.ts +25 -0
- package/dist/net/errors.d.ts.map +1 -0
- package/dist/net/errors.js +33 -0
- package/dist/net/errors.js.map +1 -0
- package/dist/net/index.d.ts +16 -0
- package/dist/net/index.d.ts.map +1 -0
- package/dist/net/index.js +12 -0
- package/dist/net/index.js.map +1 -0
- package/dist/net/policy.d.ts +85 -0
- package/dist/net/policy.d.ts.map +1 -0
- package/dist/net/policy.js +125 -0
- package/dist/net/policy.js.map +1 -0
- package/dist/net/secure-fetch.d.ts +44 -0
- package/dist/net/secure-fetch.d.ts.map +1 -0
- package/dist/net/secure-fetch.js +233 -0
- package/dist/net/secure-fetch.js.map +1 -0
- package/dist/webhooks/webhooks.d.ts +62 -22
- package/dist/webhooks/webhooks.d.ts.map +1 -1
- package/dist/webhooks/webhooks.js +161 -121
- package/dist/webhooks/webhooks.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ event × endpoint, retries with backoff, a delivery log with replay.
|
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
import {
|
|
23
|
-
createWebhookEndpoint, enqueueWebhook, deliverWebhooksOnce, verifyWebhookSignature,
|
|
23
|
+
createWebhookEndpoint, updateWebhookEndpoint, enqueueWebhook, deliverWebhooksOnce, verifyWebhookSignature,
|
|
24
24
|
} from '@venturekit/integrations';
|
|
25
25
|
import { query, withTransaction } from '@venturekit/data';
|
|
26
26
|
|
|
@@ -29,6 +29,9 @@ const { endpoint, secret } = await createWebhookEndpoint(query, {
|
|
|
29
29
|
url: 'https://customer.example/hooks', tenantId, eventTypes: ['invoice.paid'],
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
// Every later operation names the tenant it is confined to
|
|
33
|
+
await updateWebhookEndpoint(query, { tenantId }, endpoint.id, { enabled: false });
|
|
34
|
+
|
|
32
35
|
// 2. Your code enqueues in the same transaction as the state change
|
|
33
36
|
await withTransaction(async (tx) => {
|
|
34
37
|
await invoices.markPaid(tx, invoice.id);
|
|
@@ -48,7 +51,40 @@ after `maxAttempts` (default 8); `listWebhookDeliveries` / `replayWebhookDeliver
|
|
|
48
51
|
back a customer-facing log. The request carries `X-VK-Webhook-Id`,
|
|
49
52
|
`X-VK-Event-Id` (the receiver's idempotency key), `X-VK-Event-Type`,
|
|
50
53
|
`X-VK-Timestamp` and `X-VK-Signature: v1=<HMAC-SHA256("${timestamp}.${body}")>`.
|
|
51
|
-
|
|
54
|
+
|
|
55
|
+
Endpoint URLs are chosen by customers, so registration and every delivery
|
|
56
|
+
run under the outbound policy (see below): `https://` and public addresses
|
|
57
|
+
only, re-checked on every DNS answer. A refused destination is marked `dead`
|
|
58
|
+
at once, and the delivery log records failure categories (`timeout`,
|
|
59
|
+
`network error`, `HTTP 503`, `destination refused`) — never raw socket
|
|
60
|
+
errors. `vk dev` opens loopback receivers; pass `outboundPolicy` to open a
|
|
61
|
+
known internal receiver in a deployment.
|
|
62
|
+
|
|
63
|
+
Every operation on an existing endpoint or delivery (`get`, `update`,
|
|
64
|
+
`rotate…Secret`, `delete`, `listWebhookDeliveries`, `replayWebhookDelivery`,
|
|
65
|
+
`listWebhookEndpoints`) takes a `{ tenantId }` scope, so an id from a
|
|
66
|
+
request can never reach another tenant's rows.
|
|
67
|
+
|
|
68
|
+
## Outbound-request security (`@venturekit/integrations/net`)
|
|
69
|
+
|
|
70
|
+
Use `secureFetch` for every URL your server fetches on behalf of someone
|
|
71
|
+
else — customer webhooks, user-supplied media or link-preview URLs:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { secureFetch, OutboundRequestBlockedError } from '@venturekit/integrations/net';
|
|
75
|
+
|
|
76
|
+
const res = await secureFetch(url, { method: 'GET' }, { maxResponseBytes: 5_000_000 });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
It returns a standard `Response` and enforces, at every redirect hop:
|
|
80
|
+
`https:` only (plus `http:` under `vk dev`), no credentials in URLs, no
|
|
81
|
+
loopback / private / link-local / reserved addresses — including IPv6 forms
|
|
82
|
+
that embed an IPv4 address — checked on every DNS answer at connect time,
|
|
83
|
+
a redirect cap with credentials dropped across origins, one deadline for the
|
|
84
|
+
whole exchange, and a body-size cap after decompression. Open one internal
|
|
85
|
+
destination explicitly with
|
|
86
|
+
`{ allowNonPublic: (d) => d.hostname === 'minio.internal' }` or restrict to
|
|
87
|
+
an allow-list with `{ allowedHosts: ['.example.com'] }`.
|
|
52
88
|
|
|
53
89
|
Tables `vk_webhook_endpoints` / `vk_webhook_deliveries` ship with the package's
|
|
54
90
|
migrations and are applied by `vk migrate` / `vk deploy` like every other
|
|
@@ -66,6 +102,13 @@ const key = apiKey({ ssm: '/myapp/prod/api-key' });
|
|
|
66
102
|
const client = apiClient({ baseUrl: 'https://api.example.com', onRequest: [apiKeyHeader(key, 'X-Api-Key', '')] });
|
|
67
103
|
```
|
|
68
104
|
|
|
105
|
+
Request paths resolve **under** `baseUrl` (`/customers` on
|
|
106
|
+
`https://api.stripe.com/v1` is `…/v1/customers`); absolute URLs,
|
|
107
|
+
protocol-relative `//host` paths and `../` escapes are refused, so the
|
|
108
|
+
client's default headers only ever reach the API they were configured for.
|
|
109
|
+
`Retry-After` is honored up to `retry.maxRetryAfterMs` (30 s) and bodies are
|
|
110
|
+
capped at `maxResponseBytes` (10 MiB).
|
|
111
|
+
|
|
69
112
|
For keys your *customers* present to *your* API, see `@venturekit/auth/server`'s
|
|
70
113
|
`createApiKey` / `apiKeyAuth`.
|
|
71
114
|
|
package/dist/http/client.d.ts
CHANGED
|
@@ -26,7 +26,14 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export interface ApiClientOptions {
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Base URL for all requests (e.g. 'https://api.stripe.com/v1'). Request
|
|
31
|
+
* paths are resolved UNDER it — `/customers` becomes
|
|
32
|
+
* `https://api.stripe.com/v1/customers` — and may never leave it: an
|
|
33
|
+
* absolute URL, a protocol-relative `//host` or a `../` that climbs out of
|
|
34
|
+
* the base path is refused, so the client's default headers (API keys)
|
|
35
|
+
* can only ever be sent to the API they were configured for.
|
|
36
|
+
*/
|
|
30
37
|
baseUrl: string;
|
|
31
38
|
/** Default headers sent with every request */
|
|
32
39
|
headers?: Record<string, string>;
|
|
@@ -40,6 +47,11 @@ export interface ApiClientOptions {
|
|
|
40
47
|
onResponse?: ResponseInterceptor[];
|
|
41
48
|
/** Error interceptor — called on any error before it's thrown */
|
|
42
49
|
onError?: ErrorInterceptor;
|
|
50
|
+
/**
|
|
51
|
+
* Largest response body read, in bytes (default 10 MiB). A larger body
|
|
52
|
+
* fails the request instead of being buffered into memory.
|
|
53
|
+
*/
|
|
54
|
+
maxResponseBytes?: number;
|
|
43
55
|
}
|
|
44
56
|
export interface RetryOptions {
|
|
45
57
|
/** Max number of retries (default: 0 = no retry) */
|
|
@@ -50,6 +62,12 @@ export interface RetryOptions {
|
|
|
50
62
|
backoffMultiplier?: number;
|
|
51
63
|
/** HTTP status codes that trigger a retry (default: [408, 429, 500, 502, 503, 504]) */
|
|
52
64
|
retryableStatuses?: number[];
|
|
65
|
+
/**
|
|
66
|
+
* Ceiling on a server-requested `Retry-After` delay, in ms (default
|
|
67
|
+
* 30 000). The header is the upstream's to choose; without a ceiling a
|
|
68
|
+
* hostile or broken upstream can park the caller until its own timeout.
|
|
69
|
+
*/
|
|
70
|
+
maxRetryAfterMs?: number;
|
|
53
71
|
}
|
|
54
72
|
export interface ApiRequestOptions {
|
|
55
73
|
/** Request body (automatically JSON-stringified if object) */
|
|
@@ -103,6 +121,11 @@ export interface ApiClient {
|
|
|
103
121
|
delete<T = unknown>(path: string, options?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
104
122
|
request<T = unknown>(method: string, path: string, options?: ApiRequestOptions): Promise<ApiResponse<T>>;
|
|
105
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve `path` under `baseUrl`, refusing anything that would land outside
|
|
126
|
+
* it (another origin, or above the base path via `..`).
|
|
127
|
+
*/
|
|
128
|
+
export declare function resolveRequestUrl(baseUrl: string, path: string, params?: Record<string, string | number | boolean | undefined>): string;
|
|
106
129
|
/**
|
|
107
130
|
* Create a configured API client for calling third-party APIs.
|
|
108
131
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,MAAM,WAAW,gBAAgB;IAC/B
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB,wDAAwD;IACxD,SAAS,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAEjC,yDAAyD;IACzD,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAEnC,iEA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AAC,CAAC,CAAC,CAAC,CAAC;IACrF,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACxF,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1G;AAaD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAC7D,MAAM,CAmBR;AAmED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA6L9D"}
|
package/dist/http/client.js
CHANGED
|
@@ -45,8 +45,23 @@ export class ApiError extends Error {
|
|
|
45
45
|
// Helpers
|
|
46
46
|
// ---------------------------------------------------------------------------
|
|
47
47
|
const DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const DEFAULT_MAX_RETRY_AFTER_MS = 30_000;
|
|
49
|
+
const DEFAULT_MAX_RESPONSE_BYTES = 10 * 1024 * 1024;
|
|
50
|
+
/** A scheme (`https:`, `javascript:`), a protocol-relative `//host`, or a backslash variant browsers treat as one. */
|
|
51
|
+
const NON_RELATIVE_PATH = /^(?:[a-z][a-z0-9+.-]*:|[/\\]{2})/i;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve `path` under `baseUrl`, refusing anything that would land outside
|
|
54
|
+
* it (another origin, or above the base path via `..`).
|
|
55
|
+
*/
|
|
56
|
+
export function resolveRequestUrl(baseUrl, path, params) {
|
|
57
|
+
if (NON_RELATIVE_PATH.test(path)) {
|
|
58
|
+
throw new Error(`[venturekit/integrations] apiClient: request path must be relative to baseUrl (got "${path}")`);
|
|
59
|
+
}
|
|
60
|
+
const base = new URL(baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);
|
|
61
|
+
const url = new URL(path.replace(/^\/+/, ''), base);
|
|
62
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname)) {
|
|
63
|
+
throw new Error(`[venturekit/integrations] apiClient: request path "${path}" escapes baseUrl`);
|
|
64
|
+
}
|
|
50
65
|
if (params) {
|
|
51
66
|
for (const [key, value] of Object.entries(params)) {
|
|
52
67
|
if (value !== undefined) {
|
|
@@ -56,6 +71,42 @@ function buildUrl(baseUrl, path, params) {
|
|
|
56
71
|
}
|
|
57
72
|
return url.toString();
|
|
58
73
|
}
|
|
74
|
+
/** `origin + pathname` — what error messages show (query strings may carry keys). */
|
|
75
|
+
function describeUrl(url) {
|
|
76
|
+
const parsed = new URL(url);
|
|
77
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
78
|
+
}
|
|
79
|
+
/** Delay before the next attempt, honoring a numeric `Retry-After` up to `ceilingMs`. */
|
|
80
|
+
function retryDelayMs(retryAfter, fallbackMs, ceilingMs) {
|
|
81
|
+
const seconds = retryAfter === null ? Number.NaN : Number(retryAfter.trim());
|
|
82
|
+
const requested = Number.isFinite(seconds) && seconds >= 0 ? seconds * 1000 : fallbackMs;
|
|
83
|
+
return Math.min(requested, ceilingMs);
|
|
84
|
+
}
|
|
85
|
+
/** Read a body as text, refusing one larger than `limit` bytes. */
|
|
86
|
+
async function readBodyText(response, limit) {
|
|
87
|
+
const declared = Number(response.headers.get('content-length'));
|
|
88
|
+
if (Number.isFinite(declared) && declared > limit) {
|
|
89
|
+
await response.body?.cancel().catch(() => undefined);
|
|
90
|
+
throw new Error(`Response body exceeds the ${limit}-byte limit`);
|
|
91
|
+
}
|
|
92
|
+
if (!response.body)
|
|
93
|
+
return '';
|
|
94
|
+
const reader = response.body.getReader();
|
|
95
|
+
const chunks = [];
|
|
96
|
+
let total = 0;
|
|
97
|
+
for (;;) {
|
|
98
|
+
const { done, value } = await reader.read();
|
|
99
|
+
if (done)
|
|
100
|
+
break;
|
|
101
|
+
total += value.byteLength;
|
|
102
|
+
if (total > limit) {
|
|
103
|
+
await reader.cancel().catch(() => undefined);
|
|
104
|
+
throw new Error(`Response body exceeds the ${limit}-byte limit`);
|
|
105
|
+
}
|
|
106
|
+
chunks.push(value);
|
|
107
|
+
}
|
|
108
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
109
|
+
}
|
|
59
110
|
function headersToRecord(headers) {
|
|
60
111
|
const result = {};
|
|
61
112
|
headers.forEach((value, key) => {
|
|
@@ -95,10 +146,11 @@ async function sleep(ms) {
|
|
|
95
146
|
* ```
|
|
96
147
|
*/
|
|
97
148
|
export function apiClient(options) {
|
|
98
|
-
const { baseUrl, headers: defaultHeaders = {}, timeout: defaultTimeout = 30_000, retry: retryConfig = {}, onRequest = [], onResponse = [], onError, } = options;
|
|
99
|
-
const { maxRetries = 0, initialDelayMs = 1000, backoffMultiplier = 2, retryableStatuses = DEFAULT_RETRYABLE_STATUSES, } = retryConfig;
|
|
149
|
+
const { baseUrl, headers: defaultHeaders = {}, timeout: defaultTimeout = 30_000, retry: retryConfig = {}, onRequest = [], onResponse = [], onError, maxResponseBytes = DEFAULT_MAX_RESPONSE_BYTES, } = options;
|
|
150
|
+
const { maxRetries = 0, initialDelayMs = 1000, backoffMultiplier = 2, retryableStatuses = DEFAULT_RETRYABLE_STATUSES, maxRetryAfterMs = DEFAULT_MAX_RETRY_AFTER_MS, } = retryConfig;
|
|
100
151
|
async function request(method, path, reqOptions = {}) {
|
|
101
|
-
const url =
|
|
152
|
+
const url = resolveRequestUrl(baseUrl, path, reqOptions.params);
|
|
153
|
+
const shownUrl = describeUrl(url);
|
|
102
154
|
const timeoutMs = reqOptions.timeout ?? defaultTimeout;
|
|
103
155
|
const contentType = reqOptions.form
|
|
104
156
|
? 'application/x-www-form-urlencoded'
|
|
@@ -136,19 +188,18 @@ export function apiClient(options) {
|
|
|
136
188
|
const response = await fetch(url, fetchInit);
|
|
137
189
|
clearTimeout(timeoutId);
|
|
138
190
|
const responseHeaders = headersToRecord(response.headers);
|
|
139
|
-
// Parse response body
|
|
140
|
-
|
|
191
|
+
// Parse response body (size-capped)
|
|
192
|
+
const text = await readBodyText(response, maxResponseBytes);
|
|
141
193
|
const contentTypeHeader = response.headers.get('content-type') ?? '';
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
194
|
+
const data = contentTypeHeader.includes('application/json')
|
|
195
|
+
? text
|
|
196
|
+
? JSON.parse(text)
|
|
197
|
+
: null
|
|
198
|
+
: text;
|
|
148
199
|
// Non-success status
|
|
149
200
|
if (!response.ok) {
|
|
150
201
|
const apiError = new ApiError({
|
|
151
|
-
message: `${method} ${
|
|
202
|
+
message: `${method} ${shownUrl} failed with status ${response.status}`,
|
|
152
203
|
status: response.status,
|
|
153
204
|
headers: responseHeaders,
|
|
154
205
|
data,
|
|
@@ -157,11 +208,8 @@ export function apiClient(options) {
|
|
|
157
208
|
});
|
|
158
209
|
// Retry on retryable statuses
|
|
159
210
|
if (attempt < maxRetries && retryableStatuses.includes(response.status)) {
|
|
160
|
-
// Respect Retry-After
|
|
161
|
-
const
|
|
162
|
-
const delay = retryAfter
|
|
163
|
-
? parseInt(retryAfter, 10) * 1000
|
|
164
|
-
: initialDelayMs * Math.pow(backoffMultiplier, attempt);
|
|
211
|
+
// Respect a numeric Retry-After, bounded by maxRetryAfterMs.
|
|
212
|
+
const delay = retryDelayMs(response.headers.get('retry-after'), initialDelayMs * Math.pow(backoffMultiplier, attempt), maxRetryAfterMs);
|
|
165
213
|
await sleep(delay);
|
|
166
214
|
lastError = apiError;
|
|
167
215
|
continue;
|
|
@@ -196,7 +244,7 @@ export function apiClient(options) {
|
|
|
196
244
|
if (userAborted) {
|
|
197
245
|
const reason = reqOptions.signal.reason;
|
|
198
246
|
const abortError = new ApiError({
|
|
199
|
-
message: `Request aborted by caller: ${method} ${
|
|
247
|
+
message: `Request aborted by caller: ${method} ${shownUrl}${reason ? ` — ${reason instanceof Error ? reason.message : String(reason)}` : ''}`,
|
|
200
248
|
status: 0,
|
|
201
249
|
headers: {},
|
|
202
250
|
data: reason ?? null,
|
|
@@ -209,8 +257,8 @@ export function apiClient(options) {
|
|
|
209
257
|
throw abortError;
|
|
210
258
|
}
|
|
211
259
|
const errMsg = isAbort
|
|
212
|
-
? `Request timeout after ${timeoutMs}ms: ${method} ${
|
|
213
|
-
: `Network error: ${method} ${
|
|
260
|
+
? `Request timeout after ${timeoutMs}ms: ${method} ${shownUrl}`
|
|
261
|
+
: `Network error: ${method} ${shownUrl} — ${error instanceof Error ? error.message : String(error)}`;
|
|
214
262
|
lastError = new ApiError({
|
|
215
263
|
message: errMsg,
|
|
216
264
|
status: 0,
|
package/dist/http/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAuFH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjB,MAAM,CAAS;IACf,OAAO,CAAyB;IAChC,IAAI,CAAU;IACd,GAAG,CAAS;IACZ,MAAM,CAAS;IAE/B,YAAY,OAOX;QACC,KAAK,CAAC,OAAO,CAAC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BAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
* });
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
+
export * from './net/index.js';
|
|
41
42
|
export { apiClient, ApiError, } from './http/client.js';
|
|
42
43
|
export type { ApiClient, ApiClientOptions, ApiRequestOptions, ApiResponse, RetryOptions, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, } from './http/client.js';
|
|
43
44
|
export { oauth2, createMemoryTokenStore, createDynamoDBTokenStore, } from './auth/oauth2.js';
|
|
@@ -45,5 +46,5 @@ export type { OAuth2Client, OAuth2Options, ClientCredentialsOptions, Authorizati
|
|
|
45
46
|
export { apiKey, apiKeyHeader, } from './auth/api-keys.js';
|
|
46
47
|
export type { ApiKeyHandle, ApiKeySource, ApiKeyFromEnv, ApiKeyFromSSM, ApiKeyFromSecret, } from './auth/api-keys.js';
|
|
47
48
|
export { createWebhookEndpoint, listWebhookEndpoints, getWebhookEndpoint, updateWebhookEndpoint, rotateWebhookEndpointSecret, deleteWebhookEndpoint, enqueueWebhook, deliverWebhooksOnce, listWebhookDeliveries, replayWebhookDelivery, signWebhookPayload, verifyWebhookSignature, generateWebhookSecret, webhookBackoffSeconds, WEBHOOK_HEADERS, } from './webhooks/webhooks.js';
|
|
48
|
-
export type { Querier as WebhookQuerier, WebhookEndpoint, WebhookDelivery, WebhookDeliveryStatus, CreateWebhookEndpointInput, EnqueueWebhookInput, DeliverWebhooksOptions, DeliverWebhooksResult, } from './webhooks/webhooks.js';
|
|
49
|
+
export type { Querier as WebhookQuerier, WebhookEndpoint, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpointPatch, WebhookPolicyOptions, WebhookScope, WebhookTransport, CreateWebhookEndpointInput, EnqueueWebhookInput, DeliverWebhooksOptions, DeliverWebhooksResult, } from './webhooks/webhooks.js';
|
|
49
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,EACL,SAAS,EACT,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,wBAAwB,EACxB,QAAQ,EACR,UAAU,EACV,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,MAAM,EACN,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,OAAO,IAAI,cAAc,EACzB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EACL,SAAS,EACT,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,wBAAwB,EACxB,QAAQ,EACR,UAAU,EACV,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,MAAM,EACN,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,OAAO,IAAI,cAAc,EACzB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc;AACd,OAAO,EACL,SAAS,EACT,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAY1B,SAAS;AACT,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAW1B,qBAAqB;AACrB,OAAO,EACL,MAAM,EACN,YAAY,GACb,MAAM,oBAAoB,CAAC;AAS5B,kEAAkE;AAClE,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,0EAA0E;AAC1E,cAAc,gBAAgB,CAAC;AAE/B,cAAc;AACd,OAAO,EACL,SAAS,EACT,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAY1B,SAAS;AACT,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAW1B,qBAAqB;AACrB,OAAO,EACL,MAAM,EACN,YAAY,GACb,MAAM,oBAAoB,CAAC;AAS5B,kEAAkE;AAClE,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP address classification for outbound-request policy.
|
|
3
|
+
*
|
|
4
|
+
* A server that fetches a URL someone else chose (a customer's webhook
|
|
5
|
+
* endpoint, a media URL from a CMS) must not be steerable at the network it
|
|
6
|
+
* runs in: the loopback interface, the VPC, link-local services such as the
|
|
7
|
+
* instance-metadata endpoint, or address space that is not routable at all.
|
|
8
|
+
* {@link classifyAddress} answers "what kind of destination is this?" for any
|
|
9
|
+
* literal IPv4 / IPv6 address, including the IPv6 forms that EMBED an IPv4
|
|
10
|
+
* address (IPv4-mapped, IPv4-compatible, NAT64, 6to4) — the classic bypass of
|
|
11
|
+
* filters that only look at the IPv4 tables.
|
|
12
|
+
*
|
|
13
|
+
* Built on `node:net`'s `BlockList`, so prefix matching is the runtime's own
|
|
14
|
+
* and the tables below are the whole policy.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* What a destination address is. Everything other than `public` is refused by
|
|
18
|
+
* the default outbound policy.
|
|
19
|
+
*/
|
|
20
|
+
export type AddressCategory = 'public' | 'private' | 'loopback' | 'link-local' | 'shared' | 'unspecified' | 'multicast' | 'reserved';
|
|
21
|
+
/**
|
|
22
|
+
* Classify a literal IP address. Anything that is not a valid IPv4 / IPv6
|
|
23
|
+
* literal is `reserved` — callers treat an address they cannot reason about
|
|
24
|
+
* as unreachable rather than public.
|
|
25
|
+
*/
|
|
26
|
+
export declare function classifyAddress(address: string): AddressCategory;
|
|
27
|
+
/** True when {@link classifyAddress} answers `public`. */
|
|
28
|
+
export declare function isPublicAddress(address: string): boolean;
|
|
29
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/net/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,SAAS,GACT,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,aAAa,GACb,WAAW,GACX,UAAU,CAAC;AA+Ff;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAUhE;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP address classification for outbound-request policy.
|
|
3
|
+
*
|
|
4
|
+
* A server that fetches a URL someone else chose (a customer's webhook
|
|
5
|
+
* endpoint, a media URL from a CMS) must not be steerable at the network it
|
|
6
|
+
* runs in: the loopback interface, the VPC, link-local services such as the
|
|
7
|
+
* instance-metadata endpoint, or address space that is not routable at all.
|
|
8
|
+
* {@link classifyAddress} answers "what kind of destination is this?" for any
|
|
9
|
+
* literal IPv4 / IPv6 address, including the IPv6 forms that EMBED an IPv4
|
|
10
|
+
* address (IPv4-mapped, IPv4-compatible, NAT64, 6to4) — the classic bypass of
|
|
11
|
+
* filters that only look at the IPv4 tables.
|
|
12
|
+
*
|
|
13
|
+
* Built on `node:net`'s `BlockList`, so prefix matching is the runtime's own
|
|
14
|
+
* and the tables below are the whole policy.
|
|
15
|
+
*/
|
|
16
|
+
import { BlockList, isIP } from 'node:net';
|
|
17
|
+
/** IANA special-purpose ranges (RFC 6890 and successors) that are not publicly routable. */
|
|
18
|
+
const SPECIAL_RANGES = [
|
|
19
|
+
['unspecified', 'ipv4', '0.0.0.0', 8],
|
|
20
|
+
['private', 'ipv4', '10.0.0.0', 8],
|
|
21
|
+
['shared', 'ipv4', '100.64.0.0', 10], // carrier-grade NAT
|
|
22
|
+
['loopback', 'ipv4', '127.0.0.0', 8],
|
|
23
|
+
['link-local', 'ipv4', '169.254.0.0', 16], // includes 169.254.169.254 (instance metadata)
|
|
24
|
+
['private', 'ipv4', '172.16.0.0', 12],
|
|
25
|
+
['reserved', 'ipv4', '192.0.0.0', 24], // IETF protocol assignments
|
|
26
|
+
['reserved', 'ipv4', '192.0.2.0', 24], // TEST-NET-1
|
|
27
|
+
['reserved', 'ipv4', '192.88.99.0', 24], // deprecated 6to4 relay anycast
|
|
28
|
+
['private', 'ipv4', '192.168.0.0', 16],
|
|
29
|
+
['reserved', 'ipv4', '198.18.0.0', 15], // benchmarking
|
|
30
|
+
['reserved', 'ipv4', '198.51.100.0', 24], // TEST-NET-2
|
|
31
|
+
['reserved', 'ipv4', '203.0.113.0', 24], // TEST-NET-3
|
|
32
|
+
['multicast', 'ipv4', '224.0.0.0', 4],
|
|
33
|
+
['reserved', 'ipv4', '240.0.0.0', 4], // includes 255.255.255.255
|
|
34
|
+
['unspecified', 'ipv6', '::', 128],
|
|
35
|
+
['loopback', 'ipv6', '::1', 128],
|
|
36
|
+
['reserved', 'ipv6', '100::', 64], // discard-only
|
|
37
|
+
['private', 'ipv6', '64:ff9b:1::', 48], // local-use NAT64
|
|
38
|
+
['reserved', 'ipv6', '2001::', 23], // IETF protocol assignments (Teredo, ORCHID, benchmarking…)
|
|
39
|
+
['reserved', 'ipv6', '2001:db8::', 32], // documentation
|
|
40
|
+
['private', 'ipv6', 'fc00::', 7], // unique local
|
|
41
|
+
['link-local', 'ipv6', 'fe80::', 10],
|
|
42
|
+
['reserved', 'ipv6', 'fec0::', 10], // deprecated site-local
|
|
43
|
+
['multicast', 'ipv6', 'ff00::', 8],
|
|
44
|
+
];
|
|
45
|
+
const BLOCK_LISTS = (() => {
|
|
46
|
+
const byCategory = new Map();
|
|
47
|
+
for (const [category, family, network, prefix] of SPECIAL_RANGES) {
|
|
48
|
+
let list = byCategory.get(category);
|
|
49
|
+
if (!list) {
|
|
50
|
+
list = new BlockList();
|
|
51
|
+
byCategory.set(category, list);
|
|
52
|
+
}
|
|
53
|
+
list.addSubnet(network, prefix, family);
|
|
54
|
+
}
|
|
55
|
+
return [...byCategory.entries()];
|
|
56
|
+
})();
|
|
57
|
+
function lookupCategory(address, family) {
|
|
58
|
+
for (const [category, list] of BLOCK_LISTS) {
|
|
59
|
+
if (list.check(address, family))
|
|
60
|
+
return category;
|
|
61
|
+
}
|
|
62
|
+
return 'public';
|
|
63
|
+
}
|
|
64
|
+
/** Expand an IPv6 address into its eight 16-bit groups, or `null` when malformed. */
|
|
65
|
+
function ipv6Groups(address) {
|
|
66
|
+
let text = address.split('%')[0].toLowerCase();
|
|
67
|
+
const dottedTail = /(\d{1,3}(?:\.\d{1,3}){3})$/.exec(text);
|
|
68
|
+
if (dottedTail) {
|
|
69
|
+
const octets = dottedTail[1].split('.').map(Number);
|
|
70
|
+
if (octets.some((o) => o > 255))
|
|
71
|
+
return null;
|
|
72
|
+
const high = ((octets[0] << 8) | octets[1]).toString(16);
|
|
73
|
+
const low = ((octets[2] << 8) | octets[3]).toString(16);
|
|
74
|
+
text = `${text.slice(0, -dottedTail[1].length)}${high}:${low}`;
|
|
75
|
+
}
|
|
76
|
+
const halves = text.split('::');
|
|
77
|
+
if (halves.length > 2)
|
|
78
|
+
return null;
|
|
79
|
+
const head = halves[0] ? halves[0].split(':') : [];
|
|
80
|
+
const tail = halves.length === 2 && halves[1] ? halves[1].split(':') : [];
|
|
81
|
+
const missing = 8 - head.length - tail.length;
|
|
82
|
+
if (halves.length === 1 ? missing !== 0 : missing < 1)
|
|
83
|
+
return null;
|
|
84
|
+
const groups = [...head, ...new Array(halves.length === 2 ? missing : 0).fill('0'), ...tail];
|
|
85
|
+
const values = groups.map((g) => (/^[0-9a-f]{1,4}$/.test(g) ? parseInt(g, 16) : Number.NaN));
|
|
86
|
+
return values.some(Number.isNaN) ? null : values;
|
|
87
|
+
}
|
|
88
|
+
function groupsToIpv4(high, low) {
|
|
89
|
+
return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The IPv4 address an IPv6 address carries, for the forms whose reachability
|
|
93
|
+
* is decided by that IPv4 address: IPv4-mapped (`::ffff:a.b.c.d`),
|
|
94
|
+
* IPv4-compatible (`::a.b.c.d`), well-known NAT64 (`64:ff9b::/96`) and 6to4
|
|
95
|
+
* (`2002::/16`).
|
|
96
|
+
*/
|
|
97
|
+
function embeddedIpv4(groups) {
|
|
98
|
+
const zeros = (from, to) => groups.slice(from, to).every((g) => g === 0);
|
|
99
|
+
if (zeros(0, 5) && groups[5] === 0xffff)
|
|
100
|
+
return groupsToIpv4(groups[6], groups[7]);
|
|
101
|
+
if (zeros(0, 6) && (groups[6] !== 0 || groups[7] > 1))
|
|
102
|
+
return groupsToIpv4(groups[6], groups[7]);
|
|
103
|
+
if (groups[0] === 0x64 && groups[1] === 0xff9b && zeros(2, 6))
|
|
104
|
+
return groupsToIpv4(groups[6], groups[7]);
|
|
105
|
+
if (groups[0] === 0x2002)
|
|
106
|
+
return groupsToIpv4(groups[1], groups[2]);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Classify a literal IP address. Anything that is not a valid IPv4 / IPv6
|
|
111
|
+
* literal is `reserved` — callers treat an address they cannot reason about
|
|
112
|
+
* as unreachable rather than public.
|
|
113
|
+
*/
|
|
114
|
+
export function classifyAddress(address) {
|
|
115
|
+
const bare = address.startsWith('[') && address.endsWith(']') ? address.slice(1, -1) : address;
|
|
116
|
+
const version = isIP(bare.split('%')[0]);
|
|
117
|
+
if (version === 4)
|
|
118
|
+
return lookupCategory(bare, 'ipv4');
|
|
119
|
+
if (version !== 6)
|
|
120
|
+
return 'reserved';
|
|
121
|
+
const groups = ipv6Groups(bare);
|
|
122
|
+
if (!groups)
|
|
123
|
+
return 'reserved';
|
|
124
|
+
const ipv4 = embeddedIpv4(groups);
|
|
125
|
+
if (ipv4)
|
|
126
|
+
return lookupCategory(ipv4, 'ipv4');
|
|
127
|
+
return lookupCategory(bare.split('%')[0], 'ipv6');
|
|
128
|
+
}
|
|
129
|
+
/** True when {@link classifyAddress} answers `public`. */
|
|
130
|
+
export function isPublicAddress(address) {
|
|
131
|
+
return classifyAddress(address) === 'public';
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/net/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAkB3C,4FAA4F;AAC5F,MAAM,cAAc,GAAsE;IACxF,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IACrC,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAClC,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,oBAAoB;IAC1D,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IACpC,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC,EAAE,+CAA+C;IAC1F,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,CAAC;IACrC,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,4BAA4B;IACnE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,aAAa;IACpD,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC,EAAE,gCAAgC;IACzE,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC;IACtC,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,eAAe;IACvD,CAAC,UAAU,EAAE,MAAM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Q,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors raised by the outbound-request policy and transport.
|
|
3
|
+
*
|
|
4
|
+
* They carry a stable `code` / `reason` so a caller can tell a refused
|
|
5
|
+
* destination (permanent — retrying cannot help) from a network failure
|
|
6
|
+
* (transient) without parsing messages, and can report the refusal to an
|
|
7
|
+
* end user WITHOUT echoing what the network looked like behind it.
|
|
8
|
+
*/
|
|
9
|
+
/** Why a request was refused before (or instead of) reaching the network. */
|
|
10
|
+
export type OutboundBlockReason = 'invalid_url' | 'protocol_not_allowed' | 'credentials_in_url' | 'host_not_allowed' | 'non_public_address' | 'unresolvable_host' | 'too_many_redirects' | 'redirect_not_allowed';
|
|
11
|
+
/** The destination is not one the policy lets this process reach. */
|
|
12
|
+
export declare class OutboundRequestBlockedError extends Error {
|
|
13
|
+
readonly reason: OutboundBlockReason;
|
|
14
|
+
readonly code: "OUTBOUND_REQUEST_BLOCKED";
|
|
15
|
+
constructor(reason: OutboundBlockReason, message: string);
|
|
16
|
+
}
|
|
17
|
+
/** The response body exceeded the policy's `maxResponseBytes`. */
|
|
18
|
+
export declare class OutboundResponseTooLargeError extends Error {
|
|
19
|
+
readonly limitBytes: number;
|
|
20
|
+
readonly code: "OUTBOUND_RESPONSE_TOO_LARGE";
|
|
21
|
+
constructor(limitBytes: number);
|
|
22
|
+
}
|
|
23
|
+
/** True for either policy error — the request will not succeed on retry. */
|
|
24
|
+
export declare function isOutboundPolicyError(err: unknown): err is OutboundRequestBlockedError | OutboundResponseTooLargeError;
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/net/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6EAA6E;AAC7E,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,sBAAsB,GACtB,oBAAoB,GACpB,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,GACpB,sBAAsB,CAAC;AAE3B,qEAAqE;AACrE,qBAAa,2BAA4B,SAAQ,KAAK;IAIlD,QAAQ,CAAC,MAAM,EAAE,mBAAmB;IAHtC,QAAQ,CAAC,IAAI,EAAG,0BAA0B,CAAU;gBAGzC,MAAM,EAAE,mBAAmB,EACpC,OAAO,EAAE,MAAM;CAKlB;AAED,kEAAkE;AAClE,qBAAa,6BAA8B,SAAQ,KAAK;IAG1C,QAAQ,CAAC,UAAU,EAAE,MAAM;IAFvC,QAAQ,CAAC,IAAI,EAAG,6BAA6B,CAAU;gBAElC,UAAU,EAAE,MAAM;CAIxC;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,2BAA2B,GAAG,6BAA6B,CAEpE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors raised by the outbound-request policy and transport.
|
|
3
|
+
*
|
|
4
|
+
* They carry a stable `code` / `reason` so a caller can tell a refused
|
|
5
|
+
* destination (permanent — retrying cannot help) from a network failure
|
|
6
|
+
* (transient) without parsing messages, and can report the refusal to an
|
|
7
|
+
* end user WITHOUT echoing what the network looked like behind it.
|
|
8
|
+
*/
|
|
9
|
+
/** The destination is not one the policy lets this process reach. */
|
|
10
|
+
export class OutboundRequestBlockedError extends Error {
|
|
11
|
+
reason;
|
|
12
|
+
code = 'OUTBOUND_REQUEST_BLOCKED';
|
|
13
|
+
constructor(reason, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.reason = reason;
|
|
16
|
+
this.name = 'OutboundRequestBlockedError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** The response body exceeded the policy's `maxResponseBytes`. */
|
|
20
|
+
export class OutboundResponseTooLargeError extends Error {
|
|
21
|
+
limitBytes;
|
|
22
|
+
code = 'OUTBOUND_RESPONSE_TOO_LARGE';
|
|
23
|
+
constructor(limitBytes) {
|
|
24
|
+
super(`Response body exceeds the ${limitBytes}-byte limit`);
|
|
25
|
+
this.limitBytes = limitBytes;
|
|
26
|
+
this.name = 'OutboundResponseTooLargeError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** True for either policy error — the request will not succeed on retry. */
|
|
30
|
+
export function isOutboundPolicyError(err) {
|
|
31
|
+
return err instanceof OutboundRequestBlockedError || err instanceof OutboundResponseTooLargeError;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/net/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,qEAAqE;AACrE,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAIzC;IAHF,IAAI,GAAG,0BAAmC,CAAC;IAEpD,YACW,MAA2B,EACpC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAqB;QAIpC,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED,kEAAkE;AAClE,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAGjC;IAFZ,IAAI,GAAG,6BAAsC,CAAC;IAEvD,YAAqB,UAAkB;QACrC,KAAK,CAAC,6BAA6B,UAAU,aAAa,CAAC,CAAC;QADzC,eAAU,GAAV,UAAU,CAAQ;QAErC,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC9C,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB,CACnC,GAAY;IAEZ,OAAO,GAAG,YAAY,2BAA2B,IAAI,GAAG,YAAY,6BAA6B,CAAC;AACpG,CAAC"}
|