@astrale-os/adapter-cloudflare 0.5.0-beta.2 → 0.5.0-beta.200
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 +256 -0
- package/dist/adapter.d.ts +11 -0
- package/dist/adapter.js +54 -0
- 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 +5 -0
- package/dist/build/closure.js +28 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +32 -5
- package/dist/build/codegen/wrangler.js +77 -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 -0
- package/dist/build/configuration.js +4 -0
- 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 +12 -16
- package/dist/build/index.js +12 -16
- package/dist/build/material.d.ts +10 -0
- package/dist/build/material.js +25 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -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/cloudflare.d.ts +1 -34
- package/dist/cloudflare.js +1 -205
- package/dist/hosting/activation.d.ts +38 -0
- package/dist/hosting/activation.js +109 -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 +50 -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 +70 -0
- package/dist/hosting/retirement.js +107 -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 +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/material.d.ts +6 -0
- package/dist/identity/material.js +29 -0
- package/dist/index.d.ts +14 -13
- package/dist/index.js +13 -12
- 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 +389 -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 +63 -66
- package/dist/params.js +0 -1
- 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 -0
- package/dist/release/index.js +2 -0
- 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 +47 -0
- package/dist/worker/entry.js +135 -0
- package/dist/worker/fetch.d.ts +11 -0
- package/dist/worker/fetch.js +31 -0
- 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/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +6 -48
- package/dist/worker/index.js +6 -186
- 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 +47 -22
- package/template/astrale.config.ts +43 -29
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -26
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -263
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -117
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts +0 -86
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -275
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -127
- package/src/build/frontend.ts +0 -324
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -161
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -362
- package/src/cloudflare.ts +0 -251
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/index.ts +0 -276
- package/src/worker/tsconfig.json +0 -10
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { acceptDeploymentRecord, configurationDigest, deploymentContent, deploymentLabel, deploymentLine, deploymentUrl, DEPLOYMENT_RECORD_FORMAT, DEPLOYMENT_RECORD_VERSION, encodeDeploymentRecord, isFrozenConfiguration, } from '@astrale-os/sdk/deployment/address';
|
|
2
|
+
import { bundleUpload } from '../build/worker/upload.js';
|
|
3
|
+
import { activateDeployment, readRecord } from '../hosting/activation.js';
|
|
4
|
+
import { CloudflareApiError, CloudflareClient } from '../hosting/client.js';
|
|
5
|
+
import { retirementKey, RoutingKv } from '../hosting/kv.js';
|
|
6
|
+
import { routingKvTitle } from '../hosting/names.js';
|
|
7
|
+
import { HostingRefusal } from '../hosting/refusal.js';
|
|
8
|
+
import { ASSETS_BINDING, artifactOf, deploymentBindings, deploymentTags, isExistingScript, observeScript, putScriptSecret, scriptSecretNames, scriptSettings, settingsBind, SIGNING_IDENTITY_BINDING, uploadDeploymentScript, versionUuid, } from '../hosting/script.js';
|
|
9
|
+
import { frozenSettings } from './configure.js';
|
|
10
|
+
import { namespaceCoordinates } from './coordinates.js';
|
|
11
|
+
import { ACTIVATION_READINESS_MS, ROTATION_READINESS_MS, waitForNamespaceReadiness, } from './readiness.js';
|
|
12
|
+
import { publishedRecord, sameRelease } from './record.js';
|
|
13
|
+
/** Services' tag on the scripts it hosts. A namespace-mode script never carries it. */
|
|
14
|
+
export const SERVICES_TAG = 'astrale-service';
|
|
15
|
+
/**
|
|
16
|
+
* Where namespace mode places an Environment's deployments: under the namespace's routing domain,
|
|
17
|
+
* on a readable line. No effect.
|
|
18
|
+
*/
|
|
19
|
+
export function placeNamespace(parameters) {
|
|
20
|
+
const coordinates = namespaceCoordinates(parameters);
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
addressing: 'readable',
|
|
23
|
+
routingDomain: coordinates.routingDomain,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create, or reuse, the immutable deployment of one sealed release in the dispatch namespace,
|
|
28
|
+
* through the hosting kit.
|
|
29
|
+
*
|
|
30
|
+
* A new deployment is one script named by its label, uploaded create-only (`If-None-Match: *`)
|
|
31
|
+
* with a key generated for it, the build digest of its bytes, its settings and the Environment's
|
|
32
|
+
* current secrets: its `secret_text` bindings are exactly the configuration's declared secrets and
|
|
33
|
+
* its key (AM-132). Its record is then written, whose presence activates the label at the
|
|
34
|
+
* dispatcher. Readiness then waits until the URL serves the sealed release from the version the
|
|
35
|
+
* upload created (its `deployment_id`, in UUID form): the dispatcher serves no label before its
|
|
36
|
+
* record, so readiness follows activation.
|
|
37
|
+
*
|
|
38
|
+
* A label that already names a script is this release's deployment only when the script's artifact
|
|
39
|
+
* and line tags name this build on this line and `record:<label>` declares the same release and
|
|
40
|
+
* configuration (`sameRelease`), or, never activated, when the script binds exactly this
|
|
41
|
+
* configuration. Then that one script's declared secrets are rewritten in place and readiness waits
|
|
42
|
+
* for the version the rewrite minted. Anything else is a `deployment-conflict`, and nothing is
|
|
43
|
+
* written. No other script or record is ever touched (AM-4'). A `summary:<label>` an older adapter
|
|
44
|
+
* wrote is ignored: it is never read, written or deleted. A deployment is never identified by a
|
|
45
|
+
* provider version, which a secret written in place changes (OPS-2 X1).
|
|
46
|
+
*/
|
|
47
|
+
export async function deployNamespaceRelease(parameters, context, dependencies) {
|
|
48
|
+
let deployment;
|
|
49
|
+
try {
|
|
50
|
+
const plan = deploymentPlan(parameters, context);
|
|
51
|
+
const client = namespaceClient(plan.coordinates, context.signal, dependencies);
|
|
52
|
+
const kv = await RoutingKv.open(client, { title: await routingKvTitle(plan.coordinates.name) });
|
|
53
|
+
if ((await kv.get(retirementKey(plan.label))) !== undefined) {
|
|
54
|
+
throw new HostingRefusal('deployment-retired', `${plan.label} was withdrawn and is never served again; change the release to deploy ` +
|
|
55
|
+
'another deployment.');
|
|
56
|
+
}
|
|
57
|
+
deployment = new NamespaceDeployment(plan, client, kv, context, dependencies);
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
return failed('prerequisite', NONE, cause);
|
|
61
|
+
}
|
|
62
|
+
return deployment.run();
|
|
63
|
+
}
|
|
64
|
+
function deploymentPlan(parameters, context) {
|
|
65
|
+
const coordinates = namespaceCoordinates(parameters);
|
|
66
|
+
const { configuration, release, bundle } = context;
|
|
67
|
+
if (!isFrozenConfiguration(configuration)) {
|
|
68
|
+
throw new TypeError('A dispatch namespace deploys a FrozenConfigurationV1 only.');
|
|
69
|
+
}
|
|
70
|
+
if (context.placement.addressing !== 'readable' ||
|
|
71
|
+
context.placement.routingDomain !== coordinates.routingDomain) {
|
|
72
|
+
throw new TypeError('The deployment was not placed in this dispatch namespace.');
|
|
73
|
+
}
|
|
74
|
+
const document = release.document;
|
|
75
|
+
const line = deploymentLine({
|
|
76
|
+
origin: document.origin,
|
|
77
|
+
environment: context.environment,
|
|
78
|
+
addressing: 'readable',
|
|
79
|
+
});
|
|
80
|
+
const label = deploymentLabel(line, deploymentContent(bundle.digest, configuration));
|
|
81
|
+
if (label !== context.label) {
|
|
82
|
+
throw new TypeError(`The deployment label ${context.label} is not the label of this release.`);
|
|
83
|
+
}
|
|
84
|
+
const url = deploymentUrl(label, coordinates.routingDomain);
|
|
85
|
+
if (new URL(release.url).origin !== url || release.buildDigest !== bundle.digest) {
|
|
86
|
+
throw new TypeError('The sealed release names another URL or build than this deployment.');
|
|
87
|
+
}
|
|
88
|
+
const declared = configuration.bindings.secrets;
|
|
89
|
+
const supplied = Object.keys(context.secrets).sort();
|
|
90
|
+
if (supplied.length !== declared.length ||
|
|
91
|
+
supplied.some((name, index) => name !== declared[index])) {
|
|
92
|
+
throw new TypeError(`The Environment's secrets (${supplied.join(', ') || 'none'}) are not the secret names its ` +
|
|
93
|
+
`configuration declares (${declared.join(', ') || 'none'}).`);
|
|
94
|
+
}
|
|
95
|
+
const record = acceptDeploymentRecord({
|
|
96
|
+
format: DEPLOYMENT_RECORD_FORMAT,
|
|
97
|
+
version: DEPLOYMENT_RECORD_VERSION,
|
|
98
|
+
origin: document.origin,
|
|
99
|
+
environment: context.environment,
|
|
100
|
+
releaseDigest: document.digest,
|
|
101
|
+
buildDigest: bundle.digest,
|
|
102
|
+
schemaRevision: document.schema.revision,
|
|
103
|
+
configuration: configurationDigest(configuration),
|
|
104
|
+
providerScript: label,
|
|
105
|
+
commit: context.commit,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
coordinates,
|
|
109
|
+
label,
|
|
110
|
+
line,
|
|
111
|
+
url,
|
|
112
|
+
configuration,
|
|
113
|
+
buildDigest: bundle.digest,
|
|
114
|
+
upload: bundleUpload(bundle),
|
|
115
|
+
record,
|
|
116
|
+
secrets: context.secrets,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** One deploy's provider effects, in their order; every failure says what the host may now hold. */
|
|
120
|
+
class NamespaceDeployment {
|
|
121
|
+
plan;
|
|
122
|
+
client;
|
|
123
|
+
kv;
|
|
124
|
+
context;
|
|
125
|
+
dependencies;
|
|
126
|
+
provider = NONE;
|
|
127
|
+
constructor(plan, client, kv, context, dependencies) {
|
|
128
|
+
this.plan = plan;
|
|
129
|
+
this.client = client;
|
|
130
|
+
this.kv = kv;
|
|
131
|
+
this.context = context;
|
|
132
|
+
this.dependencies = dependencies;
|
|
133
|
+
}
|
|
134
|
+
async run() {
|
|
135
|
+
let deployed;
|
|
136
|
+
try {
|
|
137
|
+
const existing = await this.observe();
|
|
138
|
+
// A script that appears between the read and the create-only upload is reused like any other.
|
|
139
|
+
deployed =
|
|
140
|
+
(existing === undefined ? await this.create() : undefined) ??
|
|
141
|
+
(await this.reuse(existing ?? (await this.observe())));
|
|
142
|
+
}
|
|
143
|
+
catch (cause) {
|
|
144
|
+
return failed('provider', this.provider, cause);
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
await waitForNamespaceReadiness({
|
|
148
|
+
release: this.context.release,
|
|
149
|
+
version: deployed.version,
|
|
150
|
+
timeoutMs: deployed.activated ? ACTIVATION_READINESS_MS : ROTATION_READINESS_MS,
|
|
151
|
+
signal: this.context.signal,
|
|
152
|
+
fetch: this.dependencies.fetch,
|
|
153
|
+
...(this.dependencies.pause === undefined ? {} : { pause: this.dependencies.pause }),
|
|
154
|
+
...(this.dependencies.clock === undefined ? {} : { now: this.dependencies.clock }),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
catch (cause) {
|
|
158
|
+
return failed('readiness', this.provider, cause);
|
|
159
|
+
}
|
|
160
|
+
return Object.freeze({
|
|
161
|
+
status: 'ready',
|
|
162
|
+
state: deployed.state,
|
|
163
|
+
record: deployed.record,
|
|
164
|
+
url: this.plan.url,
|
|
165
|
+
secrets: Object.freeze({ state: deployed.secrets }),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
observe() {
|
|
169
|
+
return observeScript(this.client, this.plan.coordinates.name, this.plan.label);
|
|
170
|
+
}
|
|
171
|
+
/** The bindings this deployment's upload declares, with its key's text. */
|
|
172
|
+
bindings(signingIdentity) {
|
|
173
|
+
const { plan } = this;
|
|
174
|
+
const { configuration } = plan;
|
|
175
|
+
return deploymentBindings({
|
|
176
|
+
url: plan.url,
|
|
177
|
+
buildDigest: plan.buildDigest,
|
|
178
|
+
settings: frozenSettings(configuration),
|
|
179
|
+
vars: configuration.vars,
|
|
180
|
+
services: configuration.bindings.services,
|
|
181
|
+
dispatchNamespaces: configuration.bindings.dispatchNamespaces,
|
|
182
|
+
...(configuration.router === false ? {} : { router: configuration.router.service }),
|
|
183
|
+
signingIdentity,
|
|
184
|
+
secrets: plan.secrets,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/** Upload a new deployment and activate it; undefined when its label meanwhile names a script. */
|
|
188
|
+
async create() {
|
|
189
|
+
const { plan } = this;
|
|
190
|
+
const identity = await this.dependencies.createSigningIdentity();
|
|
191
|
+
let script;
|
|
192
|
+
try {
|
|
193
|
+
script = await uploadDeploymentScript({
|
|
194
|
+
client: this.client,
|
|
195
|
+
namespace: plan.coordinates.name,
|
|
196
|
+
label: plan.label,
|
|
197
|
+
mainModule: plan.upload.entry,
|
|
198
|
+
modules: plan.upload.modules,
|
|
199
|
+
...(plan.upload.assets === undefined ? {} : { assets: plan.upload.assets }),
|
|
200
|
+
compatibilityDate: plan.configuration.runtime.compatibilityDate,
|
|
201
|
+
compatibilityFlags: plan.configuration.runtime.compatibilityFlags,
|
|
202
|
+
bindings: this.bindings(identity.secret),
|
|
203
|
+
tags: deploymentTags({
|
|
204
|
+
buildDigest: plan.buildDigest,
|
|
205
|
+
line: plan.line,
|
|
206
|
+
keyId: identity.keyId,
|
|
207
|
+
}),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (cause) {
|
|
211
|
+
if (isExistingScript(cause))
|
|
212
|
+
return undefined;
|
|
213
|
+
// A refusal Cloudflare answered below 500 wrote nothing; anything else may have.
|
|
214
|
+
this.provider =
|
|
215
|
+
cause instanceof CloudflareApiError && cause.status !== undefined && cause.status < 500
|
|
216
|
+
? NONE
|
|
217
|
+
: UNKNOWN;
|
|
218
|
+
throw cause;
|
|
219
|
+
}
|
|
220
|
+
this.partial();
|
|
221
|
+
const record = await this.publish();
|
|
222
|
+
this.applied();
|
|
223
|
+
return {
|
|
224
|
+
state: 'created',
|
|
225
|
+
record,
|
|
226
|
+
secrets: 'bound',
|
|
227
|
+
version: versionUuid(script.version),
|
|
228
|
+
activated: true,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** Reuse the script an earlier deploy of this exact release left under its label. */
|
|
232
|
+
async reuse(existing) {
|
|
233
|
+
const { plan, client } = this;
|
|
234
|
+
const namespace = plan.coordinates.name;
|
|
235
|
+
if (existing === undefined) {
|
|
236
|
+
this.provider = UNKNOWN;
|
|
237
|
+
throw new Error(`The script ${plan.label} changed while it was deployed; deploy again.`);
|
|
238
|
+
}
|
|
239
|
+
if (existing.tags.includes(SERVICES_TAG) ||
|
|
240
|
+
existing.artifact !== artifactOf(plan.buildDigest) ||
|
|
241
|
+
existing.line !== plan.line ||
|
|
242
|
+
existing.keyId === undefined) {
|
|
243
|
+
throw conflict(`The script ${plan.label} holds another artifact, line or key than this release.`);
|
|
244
|
+
}
|
|
245
|
+
const record = await this.published();
|
|
246
|
+
if (record === undefined) {
|
|
247
|
+
// Uploaded but never activated (an earlier deploy stopped before its record): it is this
|
|
248
|
+
// release's deployment only when it binds exactly this configuration.
|
|
249
|
+
await this.requireConfiguration();
|
|
250
|
+
}
|
|
251
|
+
const declared = plan.configuration.bindings.secrets;
|
|
252
|
+
const bound = await scriptSecretNames(client, namespace, plan.label);
|
|
253
|
+
const expected = [...declared, SIGNING_IDENTITY_BINDING].sort();
|
|
254
|
+
if (bound.length !== expected.length || bound.some((name, index) => name !== expected[index])) {
|
|
255
|
+
throw conflict(`The script ${plan.label} binds other secrets than its configuration declares.`);
|
|
256
|
+
}
|
|
257
|
+
for (const name of declared) {
|
|
258
|
+
this.partial();
|
|
259
|
+
await putScriptSecret(client, namespace, plan.label, name, plan.secrets[name]);
|
|
260
|
+
}
|
|
261
|
+
// A secret written in place mints a new provider version and answers none: read it back.
|
|
262
|
+
const current = await this.observe();
|
|
263
|
+
if (current === undefined ||
|
|
264
|
+
current.etag !== existing.etag ||
|
|
265
|
+
current.artifact !== existing.artifact ||
|
|
266
|
+
current.line !== existing.line ||
|
|
267
|
+
current.keyId !== existing.keyId) {
|
|
268
|
+
this.provider = UNKNOWN;
|
|
269
|
+
throw new Error(`The script ${plan.label} changed while its secrets were rewritten; deploy again.`);
|
|
270
|
+
}
|
|
271
|
+
const stored = record ?? (await this.publish());
|
|
272
|
+
this.applied();
|
|
273
|
+
return {
|
|
274
|
+
state: 'reused',
|
|
275
|
+
record: stored,
|
|
276
|
+
secrets: declared.length === 0 ? 'unchanged' : 'updated',
|
|
277
|
+
version: versionUuid(current.version),
|
|
278
|
+
activated: record === undefined,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The record this label was activated with, when it declares this release (`sameRelease`, so
|
|
283
|
+
* only its commit may differ); undefined when the label is not activated. Another record is a
|
|
284
|
+
* `deployment-conflict`, and anything but a `DeploymentRecordV1` is refused (`record-invalid`).
|
|
285
|
+
*/
|
|
286
|
+
async published() {
|
|
287
|
+
const { label, record } = this.plan;
|
|
288
|
+
const stored = await readRecord(this.kv, label);
|
|
289
|
+
if (stored === undefined)
|
|
290
|
+
return undefined;
|
|
291
|
+
const published = publishedRecord(stored, label);
|
|
292
|
+
if (!sameRelease(published, record)) {
|
|
293
|
+
throw conflict(`The record of ${label} declares another release or configuration.`);
|
|
294
|
+
}
|
|
295
|
+
return published;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Activate the label with this release's record, or keep the one an earlier deploy of the same
|
|
299
|
+
* release published, which the deployment then keeps with its commit.
|
|
300
|
+
*/
|
|
301
|
+
async publish() {
|
|
302
|
+
try {
|
|
303
|
+
await activateDeployment(this.kv, this.plan.label, encodeDeploymentRecord(this.plan.record));
|
|
304
|
+
return this.plan.record;
|
|
305
|
+
}
|
|
306
|
+
catch (cause) {
|
|
307
|
+
// The kit keeps only the same bytes: an earlier deploy of this release from another commit
|
|
308
|
+
// published another document, which this deployment keeps.
|
|
309
|
+
if (!(cause instanceof HostingRefusal) || cause.reason !== 'deployment-conflict')
|
|
310
|
+
throw cause;
|
|
311
|
+
const stored = await this.published();
|
|
312
|
+
if (stored === undefined)
|
|
313
|
+
throw cause;
|
|
314
|
+
return stored;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/** A never-activated script binds exactly what this deployment's configuration names. */
|
|
318
|
+
async requireConfiguration() {
|
|
319
|
+
const { plan } = this;
|
|
320
|
+
const settings = await scriptSettings(this.client, plan.coordinates.name, plan.label);
|
|
321
|
+
const expected = [
|
|
322
|
+
...this.bindings(''),
|
|
323
|
+
...((plan.upload.assets ?? []).length === 0
|
|
324
|
+
? []
|
|
325
|
+
: [{ type: 'assets', name: ASSETS_BINDING }]),
|
|
326
|
+
];
|
|
327
|
+
if (!settingsBind(settings, {
|
|
328
|
+
compatibilityDate: plan.configuration.runtime.compatibilityDate,
|
|
329
|
+
compatibilityFlags: plan.configuration.runtime.compatibilityFlags,
|
|
330
|
+
bindings: expected,
|
|
331
|
+
})) {
|
|
332
|
+
throw conflict(`The script ${plan.label} was never activated and binds another configuration than this ` +
|
|
333
|
+
'release.');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
partial() {
|
|
337
|
+
if (this.provider.kind !== 'applied') {
|
|
338
|
+
this.provider = Object.freeze({
|
|
339
|
+
kind: 'partial',
|
|
340
|
+
evidence: Object.freeze({ label: this.plan.label }),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
applied() {
|
|
345
|
+
this.provider = Object.freeze({
|
|
346
|
+
kind: 'applied',
|
|
347
|
+
evidence: Object.freeze({ label: this.plan.label, url: this.plan.url }),
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/** What a deploy asks of `CLOUDFLARE_API_TOKEN`, as a missing token is told. */
|
|
352
|
+
const DEPLOY_TOKEN = 'a token that edits the scripts of the dispatch namespace and the values of its routing KV';
|
|
353
|
+
/**
|
|
354
|
+
* The kit's Cloudflare client for the namespace's account, with the token of
|
|
355
|
+
* `CLOUDFLARE_API_TOKEN`; `token` says what the operation needs of it.
|
|
356
|
+
*/
|
|
357
|
+
export function namespaceClient(coordinates, signal, dependencies, token = DEPLOY_TOKEN) {
|
|
358
|
+
const accountId = coordinates.account ?? dependencies.environment.CLOUDFLARE_ACCOUNT_ID;
|
|
359
|
+
if (accountId === undefined || !/^[0-9a-f]{32}$/u.test(accountId)) {
|
|
360
|
+
throw new TypeError('Namespace mode needs the Cloudflare account: set `namespace.account` or CLOUDFLARE_ACCOUNT_ID.');
|
|
361
|
+
}
|
|
362
|
+
const secret = dependencies.environment.CLOUDFLARE_API_TOKEN;
|
|
363
|
+
if (secret === undefined || secret.length === 0 || secret.trim() !== secret) {
|
|
364
|
+
throw new TypeError(`Namespace mode needs CLOUDFLARE_API_TOKEN: ${token}.`);
|
|
365
|
+
}
|
|
366
|
+
return new CloudflareClient({
|
|
367
|
+
accountId,
|
|
368
|
+
token: secret,
|
|
369
|
+
fetch: dependencies.fetch,
|
|
370
|
+
signal,
|
|
371
|
+
...(dependencies.apiBase === undefined ? {} : { base: dependencies.apiBase }),
|
|
372
|
+
...(dependencies.pause === undefined ? {} : { pause: dependencies.pause }),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function conflict(message) {
|
|
376
|
+
return new HostingRefusal('deployment-conflict', message);
|
|
377
|
+
}
|
|
378
|
+
const NONE = Object.freeze({ kind: 'none' });
|
|
379
|
+
const UNKNOWN = Object.freeze({ kind: 'unknown' });
|
|
380
|
+
function failed(phase, provider, cause) {
|
|
381
|
+
const error = cause instanceof HostingRefusal
|
|
382
|
+
? new Error(`The dispatch namespace refused the deployment (${cause.reason}): ${cause.message}`, {
|
|
383
|
+
cause,
|
|
384
|
+
})
|
|
385
|
+
: cause instanceof Error
|
|
386
|
+
? cause
|
|
387
|
+
: new Error(String(cause));
|
|
388
|
+
return Object.freeze({ status: 'failed', phase, provider, error });
|
|
389
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AdapterCommand, AdapterCommandContext, AdapterCommandResult } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { HostingPlan } from '../hosting/provision/plan.js';
|
|
3
|
+
import type { CloudflareParams } from '../params.js';
|
|
4
|
+
import type { NamespaceDependencies } from './deploy-release.js';
|
|
5
|
+
type HostingDependencies = Pick<NamespaceDependencies, 'fetch' | 'environment' | 'apiBase' | 'pause'>;
|
|
6
|
+
/** What `cloudflare plan|init --json` answers: the kit's plan, or what it provisioned. */
|
|
7
|
+
export interface NamespaceHostingResult {
|
|
8
|
+
readonly applied: boolean;
|
|
9
|
+
readonly blockers: readonly string[];
|
|
10
|
+
readonly summary: readonly string[];
|
|
11
|
+
readonly detail: HostingPlan;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The provider commands of adapter-cloudflare: `astrale-domain cloudflare plan <environment>`
|
|
15
|
+
* reads the account and prints what provisioning the Environment's host does and what blocks it;
|
|
16
|
+
* `astrale-domain cloudflare init <environment>` provisions it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function hostingCommands(dependencies: HostingDependencies): Readonly<Record<'plan' | 'init', AdapterCommand<CloudflareParams>>>;
|
|
19
|
+
/**
|
|
20
|
+
* Plan, or provision (`apply`), the hosting of one namespace-mode Environment with the kit, on the
|
|
21
|
+
* account and token of `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`: its dispatch namespace,
|
|
22
|
+
* the routing KV under the title every deployer finds, the dispatcher Worker (`--dispatcher`, else
|
|
23
|
+
* `<namespace>-dispatcher`) and the wildcard ingress of the routing domain in the zone of
|
|
24
|
+
* `CLOUDFLARE_ZONE_ID`, else the account's zone that holds the routing domain. A routing domain
|
|
25
|
+
* must be dedicated to the dispatcher: anything else at, under or above it blocks, and nothing is
|
|
26
|
+
* written. A plan with blockers answers exit code 1.
|
|
27
|
+
*/
|
|
28
|
+
export declare function namespaceHosting(parameters: CloudflareParams, context: AdapterCommandContext, apply: boolean, dependencies: HostingDependencies): Promise<AdapterCommandResult>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CloudflareClient, OPERATOR_RATE_LIMIT } from '../hosting/client.js';
|
|
2
|
+
import { isWorkerName } from '../hosting/names.js';
|
|
3
|
+
import { applyHosting, planHosting } from '../hosting/provision/plan.js';
|
|
4
|
+
import { findZone } from '../hosting/provision/routing.js';
|
|
5
|
+
import { namespaceCoordinates } from './coordinates.js';
|
|
6
|
+
/** What `hosting` asks of `CLOUDFLARE_API_TOKEN`, as a missing token is told. */
|
|
7
|
+
const HOSTING_TOKEN = 'a token with Workers Scripts Edit, Workers KV Storage Edit, Workers Routes Edit and Zone DNS ' +
|
|
8
|
+
'Edit on the routing domain';
|
|
9
|
+
const DISPATCHER_OPTION = 'the account Worker that dispatches the namespace (default: <namespace>-dispatcher)';
|
|
10
|
+
/**
|
|
11
|
+
* The provider commands of adapter-cloudflare: `astrale-domain cloudflare plan <environment>`
|
|
12
|
+
* reads the account and prints what provisioning the Environment's host does and what blocks it;
|
|
13
|
+
* `astrale-domain cloudflare init <environment>` provisions it.
|
|
14
|
+
*/
|
|
15
|
+
export function hostingCommands(dependencies) {
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
plan: {
|
|
18
|
+
summary: "plan the hosting of this Environment's dispatch namespace, with reads only",
|
|
19
|
+
options: { dispatcher: DISPATCHER_OPTION },
|
|
20
|
+
run: (parameters, context) => namespaceHosting(parameters, context, false, dependencies),
|
|
21
|
+
},
|
|
22
|
+
init: {
|
|
23
|
+
summary: "provision the hosting of this Environment's dispatch namespace on your account",
|
|
24
|
+
options: { dispatcher: DISPATCHER_OPTION },
|
|
25
|
+
run: (parameters, context) => namespaceHosting(parameters, context, true, dependencies),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Plan, or provision (`apply`), the hosting of one namespace-mode Environment with the kit, on the
|
|
31
|
+
* account and token of `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`: its dispatch namespace,
|
|
32
|
+
* the routing KV under the title every deployer finds, the dispatcher Worker (`--dispatcher`, else
|
|
33
|
+
* `<namespace>-dispatcher`) and the wildcard ingress of the routing domain in the zone of
|
|
34
|
+
* `CLOUDFLARE_ZONE_ID`, else the account's zone that holds the routing domain. A routing domain
|
|
35
|
+
* must be dedicated to the dispatcher: anything else at, under or above it blocks, and nothing is
|
|
36
|
+
* written. A plan with blockers answers exit code 1.
|
|
37
|
+
*/
|
|
38
|
+
export async function namespaceHosting(parameters, context, apply, dependencies) {
|
|
39
|
+
const coordinates = namespaceCoordinates(parameters);
|
|
40
|
+
const worker = context.options.dispatcher ?? `${coordinates.name}-dispatcher`;
|
|
41
|
+
if (!isWorkerName(worker)) {
|
|
42
|
+
throw new TypeError(`The dispatcher Worker name ${worker} is invalid; pass one with \`--dispatcher <worker>\`.`);
|
|
43
|
+
}
|
|
44
|
+
const accountId = coordinates.account ?? dependencies.environment.CLOUDFLARE_ACCOUNT_ID;
|
|
45
|
+
if (accountId === undefined || !/^[0-9a-f]{32}$/u.test(accountId)) {
|
|
46
|
+
throw new TypeError('Hosting needs the Cloudflare account: set `namespace.account` or CLOUDFLARE_ACCOUNT_ID.');
|
|
47
|
+
}
|
|
48
|
+
const token = dependencies.environment.CLOUDFLARE_API_TOKEN;
|
|
49
|
+
if (token === undefined || token.length === 0 || token.trim() !== token) {
|
|
50
|
+
throw new TypeError(`Hosting needs CLOUDFLARE_API_TOKEN: ${HOSTING_TOKEN}.`);
|
|
51
|
+
}
|
|
52
|
+
const client = new CloudflareClient({
|
|
53
|
+
accountId,
|
|
54
|
+
token,
|
|
55
|
+
fetch: dependencies.fetch,
|
|
56
|
+
signal: context.signal,
|
|
57
|
+
rateLimit: OPERATOR_RATE_LIMIT,
|
|
58
|
+
...(dependencies.apiBase === undefined ? {} : { base: dependencies.apiBase }),
|
|
59
|
+
...(dependencies.pause === undefined ? {} : { pause: dependencies.pause }),
|
|
60
|
+
});
|
|
61
|
+
const zone = dependencies.environment.CLOUDFLARE_ZONE_ID ??
|
|
62
|
+
(await findZone(client, coordinates.routingDomain));
|
|
63
|
+
if (zone === undefined || zone.length === 0) {
|
|
64
|
+
throw new TypeError(`The account has no zone holding ${coordinates.routingDomain}; add the domain to Cloudflare ` +
|
|
65
|
+
'or set CLOUDFLARE_ZONE_ID.');
|
|
66
|
+
}
|
|
67
|
+
const config = {
|
|
68
|
+
client,
|
|
69
|
+
namespace: coordinates.name,
|
|
70
|
+
routingDomain: coordinates.routingDomain,
|
|
71
|
+
zone,
|
|
72
|
+
dispatcher: { worker },
|
|
73
|
+
fetch: dependencies.fetch,
|
|
74
|
+
};
|
|
75
|
+
const plan = await planHosting(config);
|
|
76
|
+
if (!apply)
|
|
77
|
+
return report(plan, false, plan, context.environment);
|
|
78
|
+
const provisioned = await applyHosting(config, plan);
|
|
79
|
+
return report(provisioned, true, plan, context.environment);
|
|
80
|
+
}
|
|
81
|
+
function report(detail, applied, plan, environment) {
|
|
82
|
+
const summary = [
|
|
83
|
+
`Account ${plan.account}`,
|
|
84
|
+
`Dispatch namespace ${plan.namespace.name}: ${plan.namespace.state}` +
|
|
85
|
+
(plan.namespace.unactivated.length === 0
|
|
86
|
+
? ''
|
|
87
|
+
: ` (${plan.namespace.unactivated.length} script(s) never activated)`),
|
|
88
|
+
`Routing KV ${plan.routingKv.title ?? plan.routingKv.id}: ${plan.routingKv.state}`,
|
|
89
|
+
`Calls dataset ${plan.callsDataset ?? 'none'}`,
|
|
90
|
+
`Dispatcher Worker ${plan.dispatcher.worker}: ${plan.dispatcher.state === 'present' ? 'upload again' : 'create'} (${plan.dispatcher.modules.join(', ')})`,
|
|
91
|
+
...(plan.routing === null
|
|
92
|
+
? []
|
|
93
|
+
: [
|
|
94
|
+
`Wildcard DNS *.${plan.routing.routingDomain} (AAAA 100::, proxied): ${plan.routing.dns}`,
|
|
95
|
+
`Worker route ${plan.routing.pattern}: ${plan.routing.route}`,
|
|
96
|
+
]),
|
|
97
|
+
...(applied && 'ingress' in detail
|
|
98
|
+
? [`Ingress: ${String(detail.ingress)}`]
|
|
99
|
+
: []),
|
|
100
|
+
];
|
|
101
|
+
const result = Object.freeze({
|
|
102
|
+
applied,
|
|
103
|
+
blockers: plan.blockers,
|
|
104
|
+
summary: Object.freeze(summary),
|
|
105
|
+
detail,
|
|
106
|
+
});
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
exitCode: plan.blockers.length === 0 ? 0 : 1,
|
|
109
|
+
lines: Object.freeze([
|
|
110
|
+
...summary,
|
|
111
|
+
applied
|
|
112
|
+
? `Provisioned; deploy with astrale-domain deploy ${environment}.`
|
|
113
|
+
: plan.blockers.length === 0
|
|
114
|
+
? `Nothing was written; provision with astrale-domain cloudflare init ${environment}.`
|
|
115
|
+
: 'Nothing was written; provisioning is refused until every blocker is removed.',
|
|
116
|
+
]),
|
|
117
|
+
warnings: Object.freeze(plan.blockers.map((blocker) => `Blocked: ${blocker}`)),
|
|
118
|
+
result,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace mode of adapter-cloudflare (D4, CT33 `canonical`): each release of an Environment
|
|
3
|
+
* becomes one immutable script in a dispatch namespace, named by its deployment label and
|
|
4
|
+
* activated by its record in the namespace's routing KV. A thin layer over the hosting kit
|
|
5
|
+
* (`../hosting`), which owns every Cloudflare call, the KV contract and the dispatcher.
|
|
6
|
+
*/
|
|
7
|
+
export { configureNamespace, frozenSettings } from './configure.js';
|
|
8
|
+
export { admitNamespace, namespaceCoordinates, type NamespaceCoordinates } from './coordinates.js';
|
|
9
|
+
export { deployNamespaceRelease, namespaceClient, placeNamespace, SERVICES_TAG, type NamespaceDependencies, } from './deploy-release.js';
|
|
10
|
+
export { hostingCommands, namespaceHosting, type NamespaceHostingResult } from './hosting.js';
|
|
11
|
+
export { listNamespaceDeployments } from './list.js';
|
|
12
|
+
export { ACTIVATION_READINESS_MS, ROTATION_READINESS_MS, waitForNamespaceReadiness, } from './readiness.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace mode of adapter-cloudflare (D4, CT33 `canonical`): each release of an Environment
|
|
3
|
+
* becomes one immutable script in a dispatch namespace, named by its deployment label and
|
|
4
|
+
* activated by its record in the namespace's routing KV. A thin layer over the hosting kit
|
|
5
|
+
* (`../hosting`), which owns every Cloudflare call, the KV contract and the dispatcher.
|
|
6
|
+
*/
|
|
7
|
+
export { configureNamespace, frozenSettings } from './configure.js';
|
|
8
|
+
export { admitNamespace, namespaceCoordinates } from './coordinates.js';
|
|
9
|
+
export { deployNamespaceRelease, namespaceClient, placeNamespace, SERVICES_TAG, } from './deploy-release.js';
|
|
10
|
+
export { hostingCommands, namespaceHosting } from './hosting.js';
|
|
11
|
+
export { listNamespaceDeployments } from './list.js';
|
|
12
|
+
export { ACTIVATION_READINESS_MS, ROTATION_READINESS_MS, waitForNamespaceReadiness, } from './readiness.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ListContext, ListedDeployment } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { CloudflareParams } from '../params.js';
|
|
3
|
+
import type { NamespaceDependencies } from './deploy-release.js';
|
|
4
|
+
/**
|
|
5
|
+
* The deployments of one Environment that its dispatch namespace keeps, in label order: every
|
|
6
|
+
* label of the Environment's line that `record:<label>` activated or `retirement:<label>`
|
|
7
|
+
* withdrew in the routing KV found by its derived title, each with its script. Nothing is written.
|
|
8
|
+
*
|
|
9
|
+
* The state is what the dispatcher serves: `active` (record and script, no tombstone), `retiring`
|
|
10
|
+
* (tombstoned, the script not deleted yet: the dispatcher answers 410), `retired` (tombstoned and
|
|
11
|
+
* its script deleted) and `failed` (activated, but no script answers under the label any more: the
|
|
12
|
+
* dispatcher answers 503 until a deploy of the same release recreates it). A script uploaded and
|
|
13
|
+
* never activated is not listed: nothing in the routing KV names it. Each row carries its record as
|
|
14
|
+
* stored, unadmitted (the listing admits it), its call target (the namespace and the script), and,
|
|
15
|
+
* while its script exists, the instant Cloudflare created it and its key. A namespace keeps no
|
|
16
|
+
* retention, expiry or last call, and an older adapter's `summary:<label>` is never read.
|
|
17
|
+
*/
|
|
18
|
+
export declare function listNamespaceDeployments(parameters: CloudflareParams, context: ListContext, dependencies: NamespaceDependencies): Promise<readonly ListedDeployment[]>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { deploymentLine, deploymentUrl } from '@astrale-os/sdk/deployment/address';
|
|
2
|
+
import { RoutingKv } from '../hosting/kv.js';
|
|
3
|
+
import { listLineDeployments } from '../hosting/listing.js';
|
|
4
|
+
import { routingKvTitle } from '../hosting/names.js';
|
|
5
|
+
import { namespaceCoordinates } from './coordinates.js';
|
|
6
|
+
import { namespaceClient } from './deploy-release.js';
|
|
7
|
+
import { listedRecord } from './record.js';
|
|
8
|
+
/** What a listing asks of `CLOUDFLARE_API_TOKEN`, as a missing token is told. */
|
|
9
|
+
const LIST_TOKEN = 'a token that reads the scripts of the dispatch namespace and the values of its routing KV';
|
|
10
|
+
/**
|
|
11
|
+
* The deployments of one Environment that its dispatch namespace keeps, in label order: every
|
|
12
|
+
* label of the Environment's line that `record:<label>` activated or `retirement:<label>`
|
|
13
|
+
* withdrew in the routing KV found by its derived title, each with its script. Nothing is written.
|
|
14
|
+
*
|
|
15
|
+
* The state is what the dispatcher serves: `active` (record and script, no tombstone), `retiring`
|
|
16
|
+
* (tombstoned, the script not deleted yet: the dispatcher answers 410), `retired` (tombstoned and
|
|
17
|
+
* its script deleted) and `failed` (activated, but no script answers under the label any more: the
|
|
18
|
+
* dispatcher answers 503 until a deploy of the same release recreates it). A script uploaded and
|
|
19
|
+
* never activated is not listed: nothing in the routing KV names it. Each row carries its record as
|
|
20
|
+
* stored, unadmitted (the listing admits it), its call target (the namespace and the script), and,
|
|
21
|
+
* while its script exists, the instant Cloudflare created it and its key. A namespace keeps no
|
|
22
|
+
* retention, expiry or last call, and an older adapter's `summary:<label>` is never read.
|
|
23
|
+
*/
|
|
24
|
+
export async function listNamespaceDeployments(parameters, context, dependencies) {
|
|
25
|
+
const coordinates = namespaceCoordinates(parameters);
|
|
26
|
+
const client = namespaceClient(coordinates, context.signal, dependencies, LIST_TOKEN);
|
|
27
|
+
const kv = await RoutingKv.open(client, { title: await routingKvTitle(coordinates.name) });
|
|
28
|
+
const line = deploymentLine({
|
|
29
|
+
origin: context.origin,
|
|
30
|
+
environment: context.environment,
|
|
31
|
+
addressing: 'readable',
|
|
32
|
+
});
|
|
33
|
+
const deployments = await listLineDeployments({ client, kv, namespace: coordinates.name, line });
|
|
34
|
+
return Object.freeze(deployments.map((deployment) => Object.freeze({
|
|
35
|
+
id: deployment.label,
|
|
36
|
+
url: deploymentUrl(deployment.label, coordinates.routingDomain),
|
|
37
|
+
label: deployment.label,
|
|
38
|
+
line,
|
|
39
|
+
owner: coordinates.name,
|
|
40
|
+
state: stateOf(deployment),
|
|
41
|
+
...createdAt(deployment.script?.createdOn),
|
|
42
|
+
...(deployment.retired ? { retirement: 'withdrawn' } : {}),
|
|
43
|
+
...(deployment.script?.keyId === undefined
|
|
44
|
+
? {}
|
|
45
|
+
: { signingKeyId: deployment.script.keyId }),
|
|
46
|
+
...(deployment.record === undefined ? {} : { record: listedRecord(deployment.record) }),
|
|
47
|
+
callTarget: Object.freeze({
|
|
48
|
+
kind: 'namespace',
|
|
49
|
+
namespace: coordinates.name,
|
|
50
|
+
script: deployment.label,
|
|
51
|
+
}),
|
|
52
|
+
})));
|
|
53
|
+
}
|
|
54
|
+
function stateOf(deployment) {
|
|
55
|
+
if (deployment.retired)
|
|
56
|
+
return deployment.script === undefined ? 'retired' : 'retiring';
|
|
57
|
+
return deployment.script === undefined ? 'failed' : 'active';
|
|
58
|
+
}
|
|
59
|
+
/** The instant Cloudflare created the script, as `Date.prototype.toISOString` writes it. */
|
|
60
|
+
function createdAt(createdOn) {
|
|
61
|
+
const instant = createdOn === undefined ? Number.NaN : Date.parse(createdOn);
|
|
62
|
+
return Number.isFinite(instant) ? { createdAt: new Date(instant).toISOString() } : {};
|
|
63
|
+
}
|