@astrale-os/adapter-cloudflare 0.5.0-beta.22 → 0.5.0-beta.220
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 +246 -0
- package/dist/adapter.d.ts +9 -15
- package/dist/adapter.js +43 -129
- package/dist/build/bundle/admit.d.ts +3 -0
- package/dist/build/bundle/admit.js +47 -0
- package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
- package/dist/build/bundle/compiled-wasm-loader.js +21 -0
- package/dist/build/bundler.d.ts +21 -0
- package/dist/build/bundler.js +96 -0
- package/dist/build/closure.d.ts +4 -1
- package/dist/build/closure.js +7 -1
- package/dist/build/codegen/execution.d.ts +3 -13
- package/dist/build/codegen/execution.js +2 -44
- package/dist/build/codegen/wrangler.d.ts +28 -10
- package/dist/build/codegen/wrangler.js +71 -21
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +17 -0
- package/dist/build/configuration/settings.d.ts +6 -0
- package/dist/build/configuration/settings.js +40 -0
- package/dist/build/configuration.d.ts +4 -9
- package/dist/build/configuration.js +4 -40
- package/dist/build/frontend/files.d.ts +19 -0
- package/dist/build/frontend/files.js +99 -0
- package/dist/build/frontend/readiness.d.ts +16 -0
- package/dist/build/frontend/readiness.js +21 -0
- package/dist/build/frontend/revision.d.ts +5 -0
- package/dist/build/frontend/revision.js +14 -0
- package/dist/build/frontend/vite.d.ts +14 -0
- package/dist/build/frontend/vite.js +42 -0
- package/dist/build/frontend/vite.process.d.ts +7 -0
- package/dist/build/frontend/vite.process.js +65 -0
- package/dist/build/frontend/vite.runner.d.ts +1 -0
- package/dist/build/frontend/vite.runner.js +155 -0
- package/dist/build/index.d.ts +10 -6
- package/dist/build/index.js +10 -6
- package/dist/build/material.d.ts +10 -0
- package/dist/build/material.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +9 -0
- package/dist/build/worker/codegen/entry.js +65 -0
- package/dist/build/worker/codegen/literal.d.ts +28 -0
- package/dist/build/worker/codegen/literal.js +136 -0
- package/dist/build/worker/codegen/service.d.ts +14 -0
- package/dist/build/worker/codegen/service.js +57 -0
- package/dist/build/worker/execution.prepare.d.ts +20 -0
- package/dist/build/worker/execution.prepare.js +129 -0
- package/dist/build/worker/media-type.d.ts +1 -0
- package/dist/build/worker/media-type.js +20 -0
- package/dist/build/worker/modules.d.ts +20 -0
- package/dist/build/worker/modules.js +32 -0
- package/dist/build/worker/specifier.d.ts +5 -0
- package/dist/build/worker/specifier.js +15 -0
- package/dist/build/worker/upload.d.ts +23 -0
- package/dist/build/worker/upload.js +42 -0
- package/dist/hosting/activation.d.ts +46 -0
- package/dist/hosting/activation.js +127 -0
- package/dist/hosting/assets.d.ts +14 -0
- package/dist/hosting/assets.js +53 -0
- package/dist/hosting/bounded.d.ts +10 -0
- package/dist/hosting/bounded.js +32 -0
- package/dist/hosting/bytes.d.ts +6 -0
- package/dist/hosting/bytes.js +25 -0
- package/dist/hosting/client.d.ts +144 -0
- package/dist/hosting/client.js +491 -0
- package/dist/hosting/dispatcher/cron.d.mts +10 -0
- package/dist/hosting/dispatcher/cron.mjs +135 -0
- package/dist/hosting/dispatcher/deployments.d.mts +26 -0
- package/dist/hosting/dispatcher/deployments.mjs +158 -0
- package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
- package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
- package/dist/hosting/dispatcher/env.d.mts +51 -0
- package/dist/hosting/dispatcher/failure.d.mts +4 -0
- package/dist/hosting/dispatcher/failure.mjs +15 -0
- package/dist/hosting/dispatcher/index.d.mts +4 -0
- package/dist/hosting/dispatcher/index.mjs +8 -0
- package/dist/hosting/dispatcher/modules.d.ts +24 -0
- package/dist/hosting/dispatcher/modules.js +55 -0
- package/dist/hosting/dispatcher/services.d.mts +23 -0
- package/dist/hosting/dispatcher/services.mjs +202 -0
- package/dist/hosting/identity.d.ts +15 -0
- package/dist/hosting/identity.js +36 -0
- package/dist/hosting/index.d.ts +34 -0
- package/dist/hosting/index.js +32 -0
- package/dist/hosting/kv.d.ts +90 -0
- package/dist/hosting/kv.js +207 -0
- package/dist/hosting/listing.d.ts +34 -0
- package/dist/hosting/listing.js +49 -0
- package/dist/hosting/names.d.ts +16 -0
- package/dist/hosting/names.js +28 -0
- package/dist/hosting/provision/account.d.ts +11 -0
- package/dist/hosting/provision/account.js +86 -0
- package/dist/hosting/provision/dispatcher.d.ts +42 -0
- package/dist/hosting/provision/dispatcher.js +99 -0
- package/dist/hosting/provision/ingress.d.ts +12 -0
- package/dist/hosting/provision/ingress.js +31 -0
- package/dist/hosting/provision/plan.d.ts +143 -0
- package/dist/hosting/provision/plan.js +246 -0
- package/dist/hosting/provision/routing.d.ts +82 -0
- package/dist/hosting/provision/routing.js +226 -0
- package/dist/hosting/readiness.d.ts +53 -0
- package/dist/hosting/readiness.js +82 -0
- package/dist/hosting/refusal.d.ts +28 -0
- package/dist/hosting/refusal.js +13 -0
- package/dist/hosting/retirement.d.ts +68 -0
- package/dist/hosting/retirement.js +99 -0
- package/dist/hosting/retry-after.d.ts +6 -0
- package/dist/hosting/retry-after.js +55 -0
- package/dist/hosting/script.d.ts +186 -0
- package/dist/hosting/script.js +324 -0
- package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
- package/dist/hosting/testing/fake-cloudflare.js +757 -0
- package/dist/hosting/testing/index.d.ts +6 -0
- package/dist/hosting/testing/index.js +6 -0
- package/dist/hosting/time.d.ts +4 -0
- package/dist/hosting/time.js +20 -0
- package/dist/identity/binding.d.ts +1 -1
- package/dist/identity/binding.js +1 -1
- package/dist/identity/material.d.ts +1 -2
- package/dist/identity/material.js +5 -18
- package/dist/index.d.ts +14 -12
- package/dist/index.js +13 -11
- package/dist/namespace/configure.d.ts +22 -0
- package/dist/namespace/configure.js +199 -0
- package/dist/namespace/coordinates.d.ts +15 -0
- package/dist/namespace/coordinates.js +49 -0
- package/dist/namespace/deploy-release.d.ts +53 -0
- package/dist/namespace/deploy-release.js +386 -0
- package/dist/namespace/hosting.d.ts +29 -0
- package/dist/namespace/hosting.js +120 -0
- package/dist/namespace/index.d.ts +12 -0
- package/dist/namespace/index.js +12 -0
- package/dist/namespace/list.d.ts +18 -0
- package/dist/namespace/list.js +63 -0
- package/dist/namespace/readiness.d.ts +30 -0
- package/dist/namespace/readiness.js +31 -0
- package/dist/namespace/record.d.ts +21 -0
- package/dist/namespace/record.js +53 -0
- package/dist/params.d.ts +60 -76
- package/dist/release/build.d.ts +35 -0
- package/dist/release/build.js +44 -0
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -2
- package/dist/release/index.js +2 -2
- package/dist/worker/binary.d.ts +21 -0
- package/dist/worker/binary.js +31 -0
- package/dist/worker/build-digest.d.ts +10 -0
- package/dist/worker/build-digest.js +22 -0
- package/dist/worker/cache.d.ts +28 -0
- package/dist/worker/cache.js +70 -0
- package/dist/worker/durable.d.ts +3 -0
- package/dist/worker/durable.js +5 -0
- package/dist/worker/entry.d.ts +38 -25
- package/dist/worker/entry.js +87 -109
- package/dist/worker/front.d.ts +56 -0
- package/dist/worker/front.js +59 -0
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +83 -0
- package/dist/worker/index.d.ts +4 -1
- package/dist/worker/index.js +4 -1
- package/dist/worker/restate.d.ts +6 -0
- package/dist/worker/restate.js +6 -0
- package/dist/worker/settings.d.ts +47 -0
- package/dist/worker/settings.js +163 -0
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +27 -0
- package/dist/wrangler/index.d.ts +3 -0
- package/dist/wrangler/index.js +3 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +113 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +36 -14
- package/template/astrale.config.ts +42 -36
- package/dist/build/artifact.d.ts +0 -8
- package/dist/build/artifact.js +0 -179
- package/dist/build/codegen/gateway.d.ts +0 -1
- package/dist/build/codegen/gateway.js +0 -7
- package/dist/build/frontend-v1.d.ts +0 -16
- package/dist/build/frontend-v1.js +0 -133
- package/dist/build/parse-output.d.ts +0 -26
- package/dist/build/parse-output.js +0 -57
- package/dist/build/wrangler-cli.d.ts +0 -105
- package/dist/build/wrangler-cli.js +0 -448
- package/dist/deploy/deploy.d.ts +0 -17
- package/dist/deploy/deploy.js +0 -207
- package/dist/deploy/index.d.ts +0 -1
- package/dist/deploy/index.js +0 -1
- package/dist/identity/secret.d.ts +0 -3
- package/dist/identity/secret.js +0 -7
- package/dist/identity/source.d.ts +0 -26
- package/dist/identity/source.js +0 -98
- package/dist/release/namespace.d.ts +0 -2
- package/dist/release/namespace.js +0 -6
- package/dist/release/target.d.ts +0 -2
- package/dist/release/target.js +0 -9
- package/dist/worker/gateway.d.ts +0 -15
- package/dist/worker/gateway.js +0 -26
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { retryAfterMs } from './retry-after.js';
|
|
2
|
+
import { wait } from './time.js';
|
|
3
|
+
/** Cloudflare's REST API. The kit calls it directly: Wrangler has no create-only upload. */
|
|
4
|
+
export const CLOUDFLARE_API_BASE = 'https://api.cloudflare.com/client/v4';
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
6
|
+
/** A multipart upload (a script, an asset bucket) may take longer than any other call. */
|
|
7
|
+
const FORM_TIMEOUT_FLOOR_MS = 120_000;
|
|
8
|
+
const MAXIMUM_JSON_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
const MAXIMUM_TEXT_RESPONSE_BYTES = 1024 * 1024;
|
|
10
|
+
/** Without `Retry-After`, a rate-limited resend backs off from one second, doubling. */
|
|
11
|
+
const RATE_LIMIT_BACKOFF_MS = 1_000;
|
|
12
|
+
/** The most entries one page of a numbered listing asks for, as Cloudflare caps KV namespaces. */
|
|
13
|
+
const PAGE_SIZE = 1_000;
|
|
14
|
+
/** A deploy's policy: three resends, none waiting more than 10 s. */
|
|
15
|
+
export const DEFAULT_RATE_LIMIT = Object.freeze({
|
|
16
|
+
retries: 3,
|
|
17
|
+
maximumWaitMs: 10_000,
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* An operator command's policy: it has no deadline, so it waits out the five minutes Cloudflare
|
|
21
|
+
* blocks a user (the token owner) that went over its API limit.
|
|
22
|
+
*/
|
|
23
|
+
export const OPERATOR_RATE_LIMIT = Object.freeze({
|
|
24
|
+
retries: 5,
|
|
25
|
+
maximumWaitMs: 300_000,
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* A Cloudflare API refusal or failure. `status` is the HTTP status (absent when no response came
|
|
29
|
+
* back); `codes` are the error codes of Cloudflare's envelope (10018 for a create-only upload over
|
|
30
|
+
* an existing script). The message names the operation, never an account, script, key or value.
|
|
31
|
+
*/
|
|
32
|
+
export class CloudflareApiError extends Error {
|
|
33
|
+
name = 'CloudflareApiError';
|
|
34
|
+
kind;
|
|
35
|
+
status;
|
|
36
|
+
codes;
|
|
37
|
+
constructor(kind, message, status, codes = [], options) {
|
|
38
|
+
super(message, options);
|
|
39
|
+
this.kind = kind;
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.codes = Object.freeze([...codes]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The Cloudflare account API the hosting kit calls: dispatch namespaces and their scripts, account
|
|
46
|
+
* Workers, Workers KV, zones' DNS records and Worker routes. It runs wherever `fetch` does (Node or
|
|
47
|
+
* a Worker), reads bounded bodies, waits out rate limits by policy and turns every failure into a
|
|
48
|
+
* `CloudflareApiError`. Responses are never followed across redirects.
|
|
49
|
+
*/
|
|
50
|
+
export class CloudflareClient {
|
|
51
|
+
accountId;
|
|
52
|
+
token;
|
|
53
|
+
fetcher;
|
|
54
|
+
base;
|
|
55
|
+
signal;
|
|
56
|
+
deadline;
|
|
57
|
+
timeoutMs;
|
|
58
|
+
rateLimit;
|
|
59
|
+
pause;
|
|
60
|
+
now;
|
|
61
|
+
constructor(options) {
|
|
62
|
+
if (!stable(options.accountId))
|
|
63
|
+
invalid('Cloudflare accountId is required.');
|
|
64
|
+
if (!stable(options.token)) {
|
|
65
|
+
throw new CloudflareApiError('unauthorized', 'Cloudflare API token is required.');
|
|
66
|
+
}
|
|
67
|
+
this.accountId = options.accountId;
|
|
68
|
+
this.token = options.token;
|
|
69
|
+
this.base = (options.base ?? CLOUDFLARE_API_BASE).replace(/\/+$/u, '');
|
|
70
|
+
if (options.fetch === undefined && !allowedHost(this.base)) {
|
|
71
|
+
invalid('Cloudflare API base must be api.cloudflare.com or a loopback host.');
|
|
72
|
+
}
|
|
73
|
+
this.fetcher = options.fetch ?? ((input, init) => fetch(input, init));
|
|
74
|
+
this.signal = options.signal;
|
|
75
|
+
this.deadline = options.deadline;
|
|
76
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
77
|
+
if (!positiveInteger(this.timeoutMs))
|
|
78
|
+
invalid('Cloudflare timeoutMs must be positive.');
|
|
79
|
+
const rateLimit = options.rateLimit ?? DEFAULT_RATE_LIMIT;
|
|
80
|
+
if (rateLimit !== false &&
|
|
81
|
+
(!Number.isSafeInteger(rateLimit.retries) ||
|
|
82
|
+
rateLimit.retries < 0 ||
|
|
83
|
+
!positiveInteger(rateLimit.maximumWaitMs))) {
|
|
84
|
+
invalid('Cloudflare rateLimit needs non-negative retries and a positive maximumWaitMs.');
|
|
85
|
+
}
|
|
86
|
+
this.rateLimit = rateLimit;
|
|
87
|
+
this.pause = options.pause ?? wait;
|
|
88
|
+
this.now = options.now ?? Date.now;
|
|
89
|
+
}
|
|
90
|
+
/** `/accounts/<account><path>`. */
|
|
91
|
+
account(path) {
|
|
92
|
+
return `/accounts/${encodeURIComponent(this.accountId)}${path}`;
|
|
93
|
+
}
|
|
94
|
+
/** `/zones/<zone><path>`. */
|
|
95
|
+
zone(zoneId, path) {
|
|
96
|
+
if (!stable(zoneId))
|
|
97
|
+
invalid('Cloudflare zone id is required.');
|
|
98
|
+
return `/zones/${encodeURIComponent(zoneId)}${path}`;
|
|
99
|
+
}
|
|
100
|
+
/** Send a JSON request (or none) and return the envelope's `result`. */
|
|
101
|
+
async json(method, path, body) {
|
|
102
|
+
return (await this.send(method, path, jsonBody(body))).result;
|
|
103
|
+
}
|
|
104
|
+
/** Send an effect whose success may answer an envelope or no body at all. */
|
|
105
|
+
async effect(method, path, body) {
|
|
106
|
+
await this.send(method, path, jsonBody(body), true);
|
|
107
|
+
}
|
|
108
|
+
/** One page of a JSON listing, its page evidence admitted. */
|
|
109
|
+
async page(path) {
|
|
110
|
+
const envelope = await this.send('GET', path, {});
|
|
111
|
+
const info = envelope.resultInfo;
|
|
112
|
+
if (info !== undefined && info !== null && !isRecord(info))
|
|
113
|
+
upstream('page evidence');
|
|
114
|
+
const cursor = isRecord(info) ? info.cursor : undefined;
|
|
115
|
+
const page = isRecord(info) ? info.page : undefined;
|
|
116
|
+
const totalPages = isRecord(info) ? info.total_pages : undefined;
|
|
117
|
+
if (cursor !== undefined && cursor !== null && typeof cursor !== 'string') {
|
|
118
|
+
upstream('page cursor');
|
|
119
|
+
}
|
|
120
|
+
if (page !== undefined && !positiveInteger(page))
|
|
121
|
+
upstream('page evidence');
|
|
122
|
+
if (totalPages !== undefined && !Number.isSafeInteger(totalPages))
|
|
123
|
+
upstream('page evidence');
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
result: envelope.result,
|
|
126
|
+
...(typeof cursor === 'string' && cursor.length > 0 ? { cursor } : {}),
|
|
127
|
+
...(page === undefined ? {} : { page: page }),
|
|
128
|
+
...(totalPages === undefined ? {} : { totalPages: totalPages }),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Every entry of a cursor-paged listing (`?cursor=`), across all of its pages. `path` may carry a
|
|
133
|
+
* query already. A cursor that repeats fails: the listing would never end.
|
|
134
|
+
*/
|
|
135
|
+
async cursorList(path) {
|
|
136
|
+
const entries = [];
|
|
137
|
+
const seen = new Set();
|
|
138
|
+
let cursor;
|
|
139
|
+
for (;;) {
|
|
140
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
141
|
+
const page = await this.page(cursor === undefined ? path : `${path}${separator}cursor=${encodeURIComponent(cursor)}`);
|
|
142
|
+
if (!Array.isArray(page.result))
|
|
143
|
+
upstream('listing');
|
|
144
|
+
entries.push(...page.result);
|
|
145
|
+
if (page.cursor === undefined)
|
|
146
|
+
return Object.freeze(entries);
|
|
147
|
+
if (seen.has(page.cursor)) {
|
|
148
|
+
throw new CloudflareApiError('upstream', 'Cloudflare repeated a listing cursor.');
|
|
149
|
+
}
|
|
150
|
+
seen.add(page.cursor);
|
|
151
|
+
cursor = page.cursor;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Every entry of a numbered listing (`?per_page=&page=`), across all of its pages, stopping at
|
|
156
|
+
* the first page `found` matches (when given). A page that is not the one asked, or a total that
|
|
157
|
+
* changes between pages, fails.
|
|
158
|
+
*/
|
|
159
|
+
async pagedList(path, found, perPage = PAGE_SIZE) {
|
|
160
|
+
const entries = [];
|
|
161
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
162
|
+
let total;
|
|
163
|
+
for (let number = 1;; number += 1) {
|
|
164
|
+
const page = await this.page(`${path}${separator}per_page=${perPage}&page=${number}`);
|
|
165
|
+
if (!Array.isArray(page.result))
|
|
166
|
+
upstream('listing');
|
|
167
|
+
if ((page.page !== undefined && page.page !== number) ||
|
|
168
|
+
(total !== undefined && page.totalPages !== undefined && page.totalPages !== total)) {
|
|
169
|
+
upstream('page evidence');
|
|
170
|
+
}
|
|
171
|
+
total = page.totalPages ?? total;
|
|
172
|
+
entries.push(...page.result);
|
|
173
|
+
if (found !== undefined && page.result.some(found))
|
|
174
|
+
return Object.freeze(entries);
|
|
175
|
+
if (page.totalPages === undefined || number >= page.totalPages) {
|
|
176
|
+
return Object.freeze(entries);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Send a multipart form (a script upload, an asset bucket) and return the envelope's `result`.
|
|
182
|
+
* `bearer` replaces the API token (an asset upload session's token).
|
|
183
|
+
*/
|
|
184
|
+
async form(method, path, body, options = {}) {
|
|
185
|
+
return (await this.send(method, path, {
|
|
186
|
+
body,
|
|
187
|
+
...(options.bearer === undefined ? {} : { bearer: options.bearer }),
|
|
188
|
+
...(options.headers === undefined ? {} : { headers: options.headers }),
|
|
189
|
+
timeoutMs: Math.max(this.timeoutMs, FORM_TIMEOUT_FLOOR_MS),
|
|
190
|
+
})).result;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A raw text request, for KV values: the response body as text, or undefined when a GET or a
|
|
194
|
+
* DELETE answers 404. Bodies are bounded to 1 MiB.
|
|
195
|
+
*/
|
|
196
|
+
async text(method, path, body) {
|
|
197
|
+
const response = await this.request(method, path, body === undefined ? {} : { body: body.text, headers: { 'content-type': body.contentType } });
|
|
198
|
+
if (response.status === 404 && (method === 'GET' || method === 'DELETE')) {
|
|
199
|
+
await discard(response);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const text = await this.read(response, MAXIMUM_TEXT_RESPONSE_BYTES, method, path);
|
|
203
|
+
if (!response.ok)
|
|
204
|
+
throw failure(method, path, response.status, decodeEnvelope(text));
|
|
205
|
+
return text;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A raw GET of bytes, for a KV value whose bytes are its meaning (a deployment record): the
|
|
209
|
+
* response body, or undefined when it answers 404. Bodies are bounded to 1 MiB.
|
|
210
|
+
*/
|
|
211
|
+
async bytes(path) {
|
|
212
|
+
const response = await this.request('GET', path, {});
|
|
213
|
+
if (response.status === 404) {
|
|
214
|
+
await discard(response);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
let bytes;
|
|
218
|
+
try {
|
|
219
|
+
bytes = await boundedBytes(response, MAXIMUM_TEXT_RESPONSE_BYTES);
|
|
220
|
+
}
|
|
221
|
+
catch (cause) {
|
|
222
|
+
if (cause instanceof CloudflareApiError)
|
|
223
|
+
throw cause;
|
|
224
|
+
this.unavailable('GET', path, cause);
|
|
225
|
+
}
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
throw failure('GET', path, response.status, decodeEnvelope(new TextDecoder().decode(bytes)));
|
|
228
|
+
}
|
|
229
|
+
return bytes;
|
|
230
|
+
}
|
|
231
|
+
async send(method, path, input, allowEmptySuccess = false) {
|
|
232
|
+
const response = await this.request(method, path, input);
|
|
233
|
+
const text = await this.read(response, MAXIMUM_JSON_RESPONSE_BYTES, method, path);
|
|
234
|
+
const envelope = decodeEnvelope(text);
|
|
235
|
+
if (!response.ok || envelope?.success === false) {
|
|
236
|
+
throw failure(method, path, response.status, envelope);
|
|
237
|
+
}
|
|
238
|
+
if (envelope === undefined) {
|
|
239
|
+
if (allowEmptySuccess && text.length === 0) {
|
|
240
|
+
return { success: true, errors: [], result: null };
|
|
241
|
+
}
|
|
242
|
+
throw new CloudflareApiError('upstream', `Cloudflare ${method} ${describe(path)} returned no JSON envelope.`, response.status);
|
|
243
|
+
}
|
|
244
|
+
return envelope;
|
|
245
|
+
}
|
|
246
|
+
async request(method, path, input) {
|
|
247
|
+
if (!path.startsWith('/accounts/') && !path.startsWith('/zones')) {
|
|
248
|
+
throw new TypeError('Cloudflare API path is invalid.');
|
|
249
|
+
}
|
|
250
|
+
for (let attempt = 0;; attempt += 1) {
|
|
251
|
+
this.signal?.throwIfAborted();
|
|
252
|
+
let response;
|
|
253
|
+
try {
|
|
254
|
+
response = await this.fetcher(`${this.base}${path}`, {
|
|
255
|
+
method,
|
|
256
|
+
headers: { authorization: `Bearer ${input.bearer ?? this.token}`, ...input.headers },
|
|
257
|
+
...(input.body === undefined ? {} : { body: input.body }),
|
|
258
|
+
// Workers admit only `follow` and `manual`; a redirect is a failure either way.
|
|
259
|
+
redirect: 'manual',
|
|
260
|
+
signal: this.requestSignal(input.timeoutMs ?? this.timeoutMs),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
catch (cause) {
|
|
264
|
+
this.unavailable(method, path, cause);
|
|
265
|
+
}
|
|
266
|
+
const waitMs = this.rateLimitWait(response, attempt);
|
|
267
|
+
if (waitMs === undefined)
|
|
268
|
+
return response;
|
|
269
|
+
await discard(response);
|
|
270
|
+
try {
|
|
271
|
+
await this.pause(waitMs, this.signal);
|
|
272
|
+
}
|
|
273
|
+
catch (cause) {
|
|
274
|
+
this.unavailable(method, path, cause);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/** The request timeout, bounded by the deadline and the caller's cancellation. */
|
|
279
|
+
requestSignal(timeoutMs) {
|
|
280
|
+
const bounded = this.deadline === undefined
|
|
281
|
+
? timeoutMs
|
|
282
|
+
: Math.min(timeoutMs, Math.max(1, Math.ceil(this.deadline - this.now())));
|
|
283
|
+
const timeout = AbortSignal.timeout(bounded);
|
|
284
|
+
return this.signal === undefined ? timeout : AbortSignal.any([this.signal, timeout]);
|
|
285
|
+
}
|
|
286
|
+
/** The wait before resending a rate-limited request, or undefined when its response stands. */
|
|
287
|
+
rateLimitWait(response, attempt) {
|
|
288
|
+
const policy = this.rateLimit;
|
|
289
|
+
if (response.status !== 429 || policy === false || attempt >= policy.retries)
|
|
290
|
+
return undefined;
|
|
291
|
+
const waitMs = retryAfterMs(response.headers.get('retry-after'), this.now()) ??
|
|
292
|
+
Math.min(policy.maximumWaitMs, RATE_LIMIT_BACKOFF_MS * 2 ** attempt);
|
|
293
|
+
if (waitMs > policy.maximumWaitMs)
|
|
294
|
+
return undefined;
|
|
295
|
+
if (this.deadline !== undefined && this.now() + waitMs >= this.deadline)
|
|
296
|
+
return undefined;
|
|
297
|
+
return waitMs;
|
|
298
|
+
}
|
|
299
|
+
async read(response, maximumBytes, method, path) {
|
|
300
|
+
try {
|
|
301
|
+
return await boundedText(response, maximumBytes);
|
|
302
|
+
}
|
|
303
|
+
catch (cause) {
|
|
304
|
+
if (cause instanceof CloudflareApiError)
|
|
305
|
+
throw cause;
|
|
306
|
+
this.unavailable(method, path, cause);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
unavailable(method, path, cause) {
|
|
310
|
+
if (this.signal?.aborted === true)
|
|
311
|
+
throw this.signal.reason ?? cause;
|
|
312
|
+
throw new CloudflareApiError('unavailable', `Cloudflare ${method} ${describe(path)} is unavailable.`, undefined, [], { cause });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** Whether a failure is Cloudflare saying the resource does not exist. */
|
|
316
|
+
export function isNotFound(cause) {
|
|
317
|
+
return cause instanceof CloudflareApiError && cause.kind === 'not_found';
|
|
318
|
+
}
|
|
319
|
+
function jsonBody(body) {
|
|
320
|
+
return body === undefined
|
|
321
|
+
? {}
|
|
322
|
+
: { body: JSON.stringify(body), headers: { 'content-type': 'application/json' } };
|
|
323
|
+
}
|
|
324
|
+
function decodeEnvelope(text) {
|
|
325
|
+
let value;
|
|
326
|
+
try {
|
|
327
|
+
value = JSON.parse(text);
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
if (!isRecord(value) || typeof value.success !== 'boolean')
|
|
333
|
+
return undefined;
|
|
334
|
+
const errors = value.errors;
|
|
335
|
+
if (errors !== undefined && errors !== null && !Array.isArray(errors))
|
|
336
|
+
return undefined;
|
|
337
|
+
const admitted = [];
|
|
338
|
+
for (const error of errors ?? []) {
|
|
339
|
+
if (!isRecord(error))
|
|
340
|
+
return undefined;
|
|
341
|
+
admitted.push({ code: error.code, message: error.message });
|
|
342
|
+
}
|
|
343
|
+
return Object.freeze({
|
|
344
|
+
success: value.success,
|
|
345
|
+
errors: Object.freeze(admitted),
|
|
346
|
+
result: value.result,
|
|
347
|
+
...(Object.hasOwn(value, 'result_info') ? { resultInfo: value.result_info } : {}),
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/** A Cloudflare failure, naming its error codes and messages but never a request body. */
|
|
351
|
+
function failure(method, path, status, envelope) {
|
|
352
|
+
const errors = envelope?.errors ?? [];
|
|
353
|
+
const codes = errors
|
|
354
|
+
.map((error) => error.code)
|
|
355
|
+
.filter((code) => typeof code === 'number');
|
|
356
|
+
const detail = errors
|
|
357
|
+
.map((error) => error.message)
|
|
358
|
+
.filter((message) => typeof message === 'string')
|
|
359
|
+
.map((message) => (message.length <= 200 ? message : `${message.slice(0, 197)}...`))
|
|
360
|
+
.join('; ')
|
|
361
|
+
.replace(/\.$/u, '');
|
|
362
|
+
return new CloudflareApiError(kindOf(status), `Cloudflare ${method} ${describe(path)} failed with HTTP ${status}` +
|
|
363
|
+
`${codes.length > 0 ? ` [${codes.join(', ')}]` : ''}${detail === '' ? '' : `: ${detail}`}.`, status, codes);
|
|
364
|
+
}
|
|
365
|
+
function kindOf(status) {
|
|
366
|
+
if (status === 401 || status === 403)
|
|
367
|
+
return 'unauthorized';
|
|
368
|
+
if (status === 404)
|
|
369
|
+
return 'not_found';
|
|
370
|
+
// A rate limit refuses the caller's pace, never the request: retrying later succeeds.
|
|
371
|
+
if (status === 429 || status >= 500)
|
|
372
|
+
return 'unavailable';
|
|
373
|
+
if (status >= 400)
|
|
374
|
+
return 'invalid';
|
|
375
|
+
return 'upstream';
|
|
376
|
+
}
|
|
377
|
+
/** What a path addresses, without its account, zone, namespace, script or key names. */
|
|
378
|
+
function describe(path) {
|
|
379
|
+
const route = path.split('?', 1)[0];
|
|
380
|
+
if (route.includes('/assets-upload-session'))
|
|
381
|
+
return 'asset upload session';
|
|
382
|
+
if (route.includes('/workers/assets/upload'))
|
|
383
|
+
return 'asset upload';
|
|
384
|
+
if (route.endsWith('/secrets'))
|
|
385
|
+
return 'script secret';
|
|
386
|
+
if (route.endsWith('/settings'))
|
|
387
|
+
return 'script settings';
|
|
388
|
+
if (route.endsWith('/subdomain'))
|
|
389
|
+
return 'workers.dev subdomain';
|
|
390
|
+
if (route.endsWith('/schedules'))
|
|
391
|
+
return 'script schedules';
|
|
392
|
+
if (route.includes('/dispatch/namespaces/') && route.includes('/scripts')) {
|
|
393
|
+
return 'namespace script';
|
|
394
|
+
}
|
|
395
|
+
if (route.includes('/dispatch/namespaces'))
|
|
396
|
+
return 'dispatch namespace';
|
|
397
|
+
if (route.includes('/workers/scripts'))
|
|
398
|
+
return 'Worker';
|
|
399
|
+
if (route.includes('/workers/domains'))
|
|
400
|
+
return 'Workers custom domain';
|
|
401
|
+
if (/\/storage\/kv\/namespaces\/[^/]+\/keys/u.test(route))
|
|
402
|
+
return 'KV keys';
|
|
403
|
+
if (/\/storage\/kv\/namespaces\/[^/]+\/values/u.test(route))
|
|
404
|
+
return 'KV value';
|
|
405
|
+
if (route.includes('/storage/kv/namespaces'))
|
|
406
|
+
return 'KV namespace';
|
|
407
|
+
if (route.includes('/dns_records'))
|
|
408
|
+
return 'DNS record';
|
|
409
|
+
if (route.includes('/workers/routes'))
|
|
410
|
+
return 'Worker route';
|
|
411
|
+
if (route.startsWith('/zones'))
|
|
412
|
+
return 'zone';
|
|
413
|
+
return 'request';
|
|
414
|
+
}
|
|
415
|
+
async function boundedText(response, maximumBytes) {
|
|
416
|
+
return new TextDecoder().decode(await boundedBytes(response, maximumBytes));
|
|
417
|
+
}
|
|
418
|
+
async function boundedBytes(response, maximumBytes) {
|
|
419
|
+
const declared = response.headers.get('content-length');
|
|
420
|
+
if (declared !== null) {
|
|
421
|
+
const bytes = Number(declared);
|
|
422
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0 || bytes > maximumBytes) {
|
|
423
|
+
await discard(response);
|
|
424
|
+
throw new CloudflareApiError('upstream', 'Cloudflare response body is too large.');
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (response.body === null)
|
|
428
|
+
return new Uint8Array();
|
|
429
|
+
const reader = response.body.getReader();
|
|
430
|
+
const parts = [];
|
|
431
|
+
let size = 0;
|
|
432
|
+
for (;;) {
|
|
433
|
+
const part = await reader.read();
|
|
434
|
+
if (part.done)
|
|
435
|
+
break;
|
|
436
|
+
size += part.value.byteLength;
|
|
437
|
+
if (size > maximumBytes) {
|
|
438
|
+
try {
|
|
439
|
+
await reader.cancel('Cloudflare response body is too large.');
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
// Cancellation is cleanup; it cannot replace the overflow failure.
|
|
443
|
+
}
|
|
444
|
+
throw new CloudflareApiError('upstream', 'Cloudflare response body is too large.');
|
|
445
|
+
}
|
|
446
|
+
parts.push(part.value);
|
|
447
|
+
}
|
|
448
|
+
const bytes = new Uint8Array(size);
|
|
449
|
+
let offset = 0;
|
|
450
|
+
for (const part of parts) {
|
|
451
|
+
bytes.set(part, offset);
|
|
452
|
+
offset += part.byteLength;
|
|
453
|
+
}
|
|
454
|
+
return bytes;
|
|
455
|
+
}
|
|
456
|
+
function allowedHost(base) {
|
|
457
|
+
try {
|
|
458
|
+
const host = new URL(base).hostname.toLowerCase();
|
|
459
|
+
return (host === 'api.cloudflare.com' ||
|
|
460
|
+
host === 'localhost' ||
|
|
461
|
+
host === '127.0.0.1' ||
|
|
462
|
+
host === '[::1]' ||
|
|
463
|
+
host.endsWith('.localhost'));
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async function discard(response) {
|
|
470
|
+
try {
|
|
471
|
+
await response.body?.cancel();
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
// Releasing a response is cleanup; it never decides an outcome.
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function isRecord(value) {
|
|
478
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
479
|
+
}
|
|
480
|
+
function stable(value) {
|
|
481
|
+
return typeof value === 'string' && value.length > 0 && value.trim() === value;
|
|
482
|
+
}
|
|
483
|
+
function positiveInteger(value) {
|
|
484
|
+
return Number.isSafeInteger(value) && value > 0;
|
|
485
|
+
}
|
|
486
|
+
function invalid(message) {
|
|
487
|
+
throw new CloudflareApiError('invalid', message);
|
|
488
|
+
}
|
|
489
|
+
function upstream(what) {
|
|
490
|
+
throw new CloudflareApiError('upstream', `Cloudflare returned invalid ${what}.`);
|
|
491
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function isUtcCron(expression: unknown): expression is string
|
|
2
|
+
export function canonicalUtcCrons(input: unknown): readonly string[] | undefined
|
|
3
|
+
export function matches(expression: string, date: Date): boolean
|
|
4
|
+
export function fieldMatches(
|
|
5
|
+
field: string,
|
|
6
|
+
value: number,
|
|
7
|
+
minimum: number,
|
|
8
|
+
maximum: number,
|
|
9
|
+
names?: Readonly<Record<string, number>>,
|
|
10
|
+
): boolean
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Dependency-free five-field UTC crons: what `cron:<name>` holds and what the dispatcher fires.
|
|
5
|
+
* Uploaded as the dispatcher module `cron.mjs`; the kit validates schedules with the same code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const MONTHS = {
|
|
9
|
+
jan: 1,
|
|
10
|
+
feb: 2,
|
|
11
|
+
mar: 3,
|
|
12
|
+
apr: 4,
|
|
13
|
+
may: 5,
|
|
14
|
+
jun: 6,
|
|
15
|
+
jul: 7,
|
|
16
|
+
aug: 8,
|
|
17
|
+
sep: 9,
|
|
18
|
+
oct: 10,
|
|
19
|
+
nov: 11,
|
|
20
|
+
dec: 12,
|
|
21
|
+
}
|
|
22
|
+
const DAYS = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 }
|
|
23
|
+
|
|
24
|
+
/** Admit one dependency-free five-field UTC cron expression. */
|
|
25
|
+
/** @param {unknown} expression */
|
|
26
|
+
export function isUtcCron(expression) {
|
|
27
|
+
if (typeof expression !== 'string') return false
|
|
28
|
+
const fields = expression.trim().split(/\s+/u)
|
|
29
|
+
return (
|
|
30
|
+
fields.length === 5 &&
|
|
31
|
+
fieldValid(fields[0], 0, 59) &&
|
|
32
|
+
fieldValid(fields[1], 0, 23) &&
|
|
33
|
+
fieldValid(fields[2], 1, 31) &&
|
|
34
|
+
fieldValid(fields[3], 1, 12, MONTHS) &&
|
|
35
|
+
fieldValid(fields[4], 0, 7, DAYS)
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Admit one duplicate-free canonical UTC cron array after a representation boundary. */
|
|
40
|
+
/** @param {unknown} input */
|
|
41
|
+
export function canonicalUtcCrons(input) {
|
|
42
|
+
if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) return undefined
|
|
43
|
+
const canonical = input.map((value) => value.trim().toLowerCase())
|
|
44
|
+
if (!canonical.every(isUtcCron) || new Set(canonical).size !== canonical.length) return undefined
|
|
45
|
+
return Object.freeze(canonical)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Match one admitted five-field UTC cron expression. */
|
|
49
|
+
/** @param {string} expression @param {Date} date */
|
|
50
|
+
export function matches(expression, date) {
|
|
51
|
+
if (!isUtcCron(expression) || !Number.isFinite(date.getTime())) return false
|
|
52
|
+
const [minute, hour, dayOfMonth, month, dayOfWeek] = expression.trim().split(/\s+/u)
|
|
53
|
+
if (!fieldMatches(minute, date.getUTCMinutes(), 0, 59)) return false
|
|
54
|
+
if (!fieldMatches(hour, date.getUTCHours(), 0, 23)) return false
|
|
55
|
+
if (!fieldMatches(month, date.getUTCMonth() + 1, 1, 12, MONTHS)) return false
|
|
56
|
+
const monthDayMatches = fieldMatches(dayOfMonth, date.getUTCDate(), 1, 31)
|
|
57
|
+
const weekDayMatches =
|
|
58
|
+
fieldMatches(dayOfWeek, date.getUTCDay(), 0, 7, DAYS) ||
|
|
59
|
+
(date.getUTCDay() === 0 && fieldMatches(dayOfWeek, 7, 0, 7, DAYS))
|
|
60
|
+
// Vixie marks a day field as wildcard by its leading character, including */n.
|
|
61
|
+
return dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*')
|
|
62
|
+
? monthDayMatches && weekDayMatches
|
|
63
|
+
: monthDayMatches || weekDayMatches
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {string} field @param {number} value @param {number} minimum @param {number} maximum @param {Readonly<Record<string, number>>} [names] */
|
|
67
|
+
export function fieldMatches(field, value, minimum, maximum, names) {
|
|
68
|
+
for (const segment of field.split(',')) {
|
|
69
|
+
const parsed = parseSegment(segment, minimum, maximum, names)
|
|
70
|
+
if (parsed === undefined) continue
|
|
71
|
+
if (
|
|
72
|
+
value >= parsed.lower &&
|
|
73
|
+
value <= parsed.upper &&
|
|
74
|
+
(value - parsed.lower) % parsed.step === 0
|
|
75
|
+
) {
|
|
76
|
+
return true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @param {string} field @param {number} minimum @param {number} maximum @param {Readonly<Record<string, number>>} [names] */
|
|
83
|
+
function fieldValid(field, minimum, maximum, names) {
|
|
84
|
+
const segments = field.split(',')
|
|
85
|
+
return (
|
|
86
|
+
segments.length > 0 &&
|
|
87
|
+
segments.every((segment) => parseSegment(segment, minimum, maximum, names) !== undefined)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @param {string} segment @param {number} minimum @param {number} maximum @param {Readonly<Record<string, number>>} [names] */
|
|
92
|
+
function parseSegment(segment, minimum, maximum, names) {
|
|
93
|
+
const parts = segment.split('/')
|
|
94
|
+
if (parts.length > 2 || parts[0] === '') return undefined
|
|
95
|
+
const basis = parts[0]
|
|
96
|
+
const rawStep = parts[1]
|
|
97
|
+
const step = rawStep === undefined ? 1 : Number(rawStep)
|
|
98
|
+
if (!Number.isSafeInteger(step) || step < 1) return undefined
|
|
99
|
+
let lower
|
|
100
|
+
let upper
|
|
101
|
+
if (basis === '*') {
|
|
102
|
+
lower = minimum
|
|
103
|
+
upper = maximum
|
|
104
|
+
} else if (basis.includes('-')) {
|
|
105
|
+
const range = basis.split('-')
|
|
106
|
+
if (range.length !== 2) return undefined
|
|
107
|
+
lower = resolve(range[0], names)
|
|
108
|
+
upper = resolve(range[1], names)
|
|
109
|
+
} else {
|
|
110
|
+
if (rawStep !== undefined) return undefined
|
|
111
|
+
lower = resolve(basis, names)
|
|
112
|
+
upper = lower
|
|
113
|
+
}
|
|
114
|
+
if (
|
|
115
|
+
lower === undefined ||
|
|
116
|
+
upper === undefined ||
|
|
117
|
+
lower < minimum ||
|
|
118
|
+
upper > maximum ||
|
|
119
|
+
lower > upper
|
|
120
|
+
) {
|
|
121
|
+
return undefined
|
|
122
|
+
}
|
|
123
|
+
return { lower, upper, step }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {string} token @param {Readonly<Record<string, number>>} [names] */
|
|
127
|
+
function resolve(token, names) {
|
|
128
|
+
if (token.length === 0) return undefined
|
|
129
|
+
const key = token.toLowerCase()
|
|
130
|
+
const named = names !== undefined && Object.hasOwn(names, key) ? names[key] : undefined
|
|
131
|
+
if (named !== undefined) return named
|
|
132
|
+
if (!/^\d+$/u.test(token)) return undefined
|
|
133
|
+
const value = Number(token)
|
|
134
|
+
return Number.isSafeInteger(value) ? value : undefined
|
|
135
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DispatcherEnvironment } from './env.mjs'
|
|
2
|
+
|
|
3
|
+
/** What `record:<label>` holds: its bytes, and its media type when the deployment publishes one. */
|
|
4
|
+
export interface PublishedRecord {
|
|
5
|
+
readonly body: ArrayBuffer
|
|
6
|
+
readonly contentType?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** The probe path the dispatcher never counts as a call (`retirementVisible`). */
|
|
10
|
+
export const RETIREMENT_PROBE_PATH: '/__services_retirement_probe__'
|
|
11
|
+
/** Whether a host label is a deployment label, as the dispatcher admits it (≤ 57 characters). */
|
|
12
|
+
export function isDeploymentLabel(label: string): boolean
|
|
13
|
+
/** Route one request to one deployment label: record endpoint, tombstone, activation, call. */
|
|
14
|
+
export function dispatchDeployment(
|
|
15
|
+
request: Request,
|
|
16
|
+
environment: DispatcherEnvironment,
|
|
17
|
+
label: string,
|
|
18
|
+
): Promise<Response>
|
|
19
|
+
/**
|
|
20
|
+
* The record that activates a label: `null` when `record:<label>` is absent or carries no
|
|
21
|
+
* `{"contentType":...}` metadata, which activates nothing.
|
|
22
|
+
*/
|
|
23
|
+
export function activationRecord(
|
|
24
|
+
environment: Pick<DispatcherEnvironment, 'SCHEDULES'>,
|
|
25
|
+
label: string,
|
|
26
|
+
): Promise<PublishedRecord | null>
|