@astrale-os/adapter-cloudflare 0.5.0-beta.167 → 0.5.0-beta.169

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.
Files changed (91) hide show
  1. package/README.md +79 -12
  2. package/dist/adapter.d.ts +17 -9
  3. package/dist/adapter.js +29 -56
  4. package/dist/build/codegen/wrangler.d.ts +16 -0
  5. package/dist/build/codegen/wrangler.js +20 -6
  6. package/dist/build/configuration/settings.d.ts +0 -9
  7. package/dist/build/configuration/settings.js +3 -32
  8. package/dist/build/configuration.d.ts +1 -3
  9. package/dist/build/configuration.js +1 -3
  10. package/dist/build/index.d.ts +10 -4
  11. package/dist/build/index.js +10 -4
  12. package/dist/build/worker/upload.d.ts +22 -1
  13. package/dist/build/worker/upload.js +40 -0
  14. package/dist/index.d.ts +14 -12
  15. package/dist/index.js +13 -11
  16. package/dist/{deploy → legacy/direct}/deploy.d.ts +6 -6
  17. package/dist/{deploy → legacy/direct}/deploy.js +8 -8
  18. package/dist/legacy/direct/identity/index.d.ts +11 -0
  19. package/dist/legacy/direct/identity/index.js +11 -0
  20. package/dist/{identity → legacy/direct/identity}/source.d.ts +1 -1
  21. package/dist/{identity → legacy/direct/identity}/source.js +2 -2
  22. package/dist/legacy/direct/index.d.ts +27 -0
  23. package/dist/legacy/direct/index.js +27 -0
  24. package/dist/{build/direct.d.ts → legacy/direct/placement.d.ts} +2 -2
  25. package/dist/{build/direct.js → legacy/direct/placement.js} +4 -3
  26. package/dist/{build/artifact.d.ts → legacy/direct/prepare.d.ts} +1 -1
  27. package/dist/{build/artifact.js → legacy/direct/prepare.js} +13 -10
  28. package/dist/legacy/direct/readiness.d.ts +34 -0
  29. package/dist/legacy/direct/readiness.js +95 -0
  30. package/dist/legacy/direct/vars.d.ts +27 -0
  31. package/dist/legacy/direct/vars.js +53 -0
  32. package/dist/{worker/legacy/direct.d.ts → legacy/direct/worker.d.ts} +2 -2
  33. package/dist/{wrangler → legacy/direct/wrangler}/deploy.js +3 -3
  34. package/dist/{wrangler → legacy/direct/wrangler}/status.js +1 -1
  35. package/dist/{wrangler → legacy/direct/wrangler}/triggers.js +2 -2
  36. package/dist/{wrangler → legacy/direct/wrangler}/versions.js +3 -3
  37. package/dist/namespace/api.d.ts +59 -0
  38. package/dist/namespace/api.js +212 -0
  39. package/dist/namespace/configure.d.ts +26 -0
  40. package/dist/namespace/configure.js +199 -0
  41. package/dist/namespace/coordinates.d.ts +35 -0
  42. package/dist/namespace/coordinates.js +89 -0
  43. package/dist/namespace/deploy-release.d.ts +49 -0
  44. package/dist/namespace/deploy-release.js +398 -0
  45. package/dist/namespace/index.d.ts +12 -0
  46. package/dist/namespace/index.js +12 -0
  47. package/dist/namespace/readiness.d.ts +40 -0
  48. package/dist/namespace/readiness.js +81 -0
  49. package/dist/namespace/routing.d.ts +42 -0
  50. package/dist/namespace/routing.js +126 -0
  51. package/dist/namespace/script.d.ts +106 -0
  52. package/dist/namespace/script.js +278 -0
  53. package/dist/params.d.ts +62 -7
  54. package/dist/worker/build-digest.d.ts +16 -0
  55. package/dist/worker/build-digest.js +34 -0
  56. package/dist/worker/entry.js +15 -5
  57. package/dist/worker/front.d.ts +5 -1
  58. package/dist/worker/front.js +1 -1
  59. package/dist/worker/index.d.ts +2 -1
  60. package/dist/worker/index.js +2 -1
  61. package/dist/wrangler/index.d.ts +0 -2
  62. package/dist/wrangler/index.js +0 -2
  63. package/package.json +4 -4
  64. package/template/astrale.config.ts +3 -3
  65. package/dist/build/configuration/legacy/direct.d.ts +0 -15
  66. package/dist/build/configuration/legacy/direct.js +0 -19
  67. package/dist/deploy/index.d.ts +0 -1
  68. package/dist/deploy/index.js +0 -1
  69. package/dist/deploy/readiness.d.ts +0 -5
  70. package/dist/deploy/readiness.js +0 -21
  71. package/dist/identity/index.d.ts +0 -3
  72. package/dist/identity/index.js +0 -3
  73. /package/dist/{build/configuration → legacy/direct}/addressing.d.ts +0 -0
  74. /package/dist/{build/configuration → legacy/direct}/addressing.js +0 -0
  75. /package/dist/{identity → legacy/direct/identity}/secret.d.ts +0 -0
  76. /package/dist/{identity → legacy/direct/identity}/secret.js +0 -0
  77. /package/dist/{build → legacy/direct}/materialize.d.ts +0 -0
  78. /package/dist/{build → legacy/direct}/materialize.js +0 -0
  79. /package/dist/{build/configuration → legacy/direct}/worker-name.d.ts +0 -0
  80. /package/dist/{build/configuration → legacy/direct}/worker-name.js +0 -0
  81. /package/dist/{worker/legacy/direct.js → legacy/direct/worker.js} +0 -0
  82. /package/dist/{wrangler → legacy/direct/wrangler}/deploy.d.ts +0 -0
  83. /package/dist/{deploy → legacy/direct/wrangler}/output.d.ts +0 -0
  84. /package/dist/{deploy → legacy/direct/wrangler}/output.js +0 -0
  85. /package/dist/{wrangler → legacy/direct/wrangler}/rollout.d.ts +0 -0
  86. /package/dist/{wrangler → legacy/direct/wrangler}/rollout.js +0 -0
  87. /package/dist/{wrangler → legacy/direct/wrangler}/secrets.d.ts +0 -0
  88. /package/dist/{wrangler → legacy/direct/wrangler}/secrets.js +0 -0
  89. /package/dist/{wrangler → legacy/direct/wrangler}/status.d.ts +0 -0
  90. /package/dist/{wrangler → legacy/direct/wrangler}/triggers.d.ts +0 -0
  91. /package/dist/{wrangler → legacy/direct/wrangler}/versions.d.ts +0 -0
package/README.md CHANGED
@@ -10,16 +10,81 @@ npm install @astrale-os/sdk@beta @astrale-os/adapter-cloudflare@beta
10
10
 
11
11
  Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
12
12
 
13
- One `cloudflare()` value configures one Project Environment. `astrale-domain dev <environment>`
14
- builds locally and deploys each admitted Worker and frontend update remotely through the same path
15
- as `deploy`; it starts no local Worker, Vite server, or tunnel. Omitting `route` uses the observed
16
- stable `*.workers.dev` issuer. Add `installation: { instance: '...' }` to the Project Environment
17
- when generic tooling should reconcile the ready Release onto an Astrale Kernel.
13
+ One `cloudflare()` value configures one Project Environment, in one of two modes. With
14
+ `namespace`, each release becomes one immutable deployment in a platform dispatch namespace. Without
15
+ it, the Environment is on the legacy direct mode: one stable Worker, replaced in place by each
16
+ deploy. A deploy never installs: install the URL it prints with
17
+ `astrale domain install <url> --direct -i <instance>`.
18
18
 
19
19
  Generated Worker modules are minified by default, including separately loaded runtime modules.
20
20
  The Environment's `wrangler` overlay cannot change minification: every Environment of one source
21
21
  must emit the same JavaScript bytes. `cloudflare({ wrangler: { minify: false } })` is rejected.
22
22
 
23
+ ## Namespace mode
24
+
25
+ ```ts
26
+ production: {
27
+ deployment: cloudflare({
28
+ namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
29
+ secrets: '.env.production',
30
+ }),
31
+ },
32
+ ```
33
+
34
+ Only the platform deploys there (Shell, Services and the other platform Domains), so every line is
35
+ readable. `astrale-domain deploy <environment>` uploads one script named by the deployment label,
36
+ create-only (`If-None-Match: *`), which answers at `https://<label>.<routingDomain>` through the
37
+ platform dispatcher. Nothing is ever replaced in place: another build or configuration is another
38
+ label.
39
+
40
+ - **Credentials.** `CLOUDFLARE_API_TOKEN` must edit the namespace's scripts and the values of its
41
+ routing KV; the account is `namespace.account`, else `CLOUDFLARE_ACCOUNT_ID`. Neither is ever
42
+ written to the configuration.
43
+ - **Routing KV.** The deploy finds the namespace's routing KV by its title,
44
+ `astrale-deployment-routing-<first 16 bytes of sha256(name), in hexadecimal>`, which the platform
45
+ provisioning creates. A namespace without it is refused before any effect.
46
+ - **Bindings.** Each new deployment binds `WORKER_URL`, `ASTRALE_BUILD_DIGEST`, `ASTRALE_SETTINGS`
47
+ (the router as `ROUTER`), the author's `vars`, the service bindings of `wrangler.services`, the
48
+ router, its version metadata, and as `secret_text` exactly the Environment's secrets and
49
+ `ASTRALE_SIGNING_IDENTITY`, a key generated for that deployment and kept nowhere else. Its tags
50
+ name its artifact (build digest), line and key; never `astrale-service`, which is Services'.
51
+ - **Activation.** The deploy writes `summary:<label>` (owner `platform`, state `active`, retention
52
+ `preview`, the activation instant), then `record:<label>`, whose presence makes the dispatcher
53
+ route the label. Neither ever holds a provider version or a secret digest. Readiness then waits,
54
+ bounded, until the URL serves the sealed release from the provider version the upload created.
55
+ - **Reuse.** A redeploy of the same release finds the script under its label. It is reused only
56
+ when its artifact and line tags and its record name this build and configuration (or, when an
57
+ interrupted deploy left it unactivated, when it binds exactly this configuration). Then only that
58
+ script's declared secrets are rewritten in place, and readiness waits for the version the
59
+ rewrite minted. Anything else is a `deployment-conflict`, refused with nothing written; no other
60
+ deployment is ever touched.
61
+ - **Retention.** `retain` (called once a Publication commits) marks the summary `published`, which
62
+ the platform's preview expiry never retires. A label the platform withdrew (`retirement:<label>`)
63
+ answers `DEPLOYMENT_RETIRED` at the dispatcher and is refused by every later deploy.
64
+ - **Refused.** A direct-mode parameter beside `namespace` (`route`, `workerName`, `identityIssuer`,
65
+ `addressing`, `signingIdentity`), a `router.binding` other than `ROUTER`, and any `wrangler` key
66
+ but `services`, `dispatch_namespaces` and `compatibility_flags`, `triggers` first: an immutable
67
+ deployment runs no cron of its own. A `dispatch_namespaces` entry is exactly
68
+ `{ binding, namespace }`; it is frozen into the configuration (`bindings.dispatchNamespaces`), so
69
+ into the label, bound at the create-only upload, and never names the platform namespace the
70
+ deployment lives in (AM-174). Which namespaces a deployment may bind is its host's to decide.
71
+ `durable` is frozen into the configuration (`settings.durableOptions`, AM-175), so into the
72
+ label, and bound in `ASTRALE_SETTINGS`: a durable run stays on the deployment that started it.
73
+ `astrale-domain dev` serves only direct-mode Environments.
74
+
75
+ ## Legacy direct mode
76
+
77
+ Deprecated: replaced by namespace mode, and deleted with the legacy deploy path (D10) once no
78
+ configuration on any repository's main selects direct mode. Its consumers until they move: the
79
+ domains configurations of ai-gateway, closing, grc, integrations and issues; domains organization,
80
+ whose `prod` binds an EU-jurisdiction R2 bucket that namespace mode does not admit yet; the Services
81
+ `beta`, `prod` and `development` environments and its frozen `admin-beta`; the Shell and its frozen
82
+ `legacy-v3`; and ui:domain.
83
+
84
+ `astrale-domain dev <environment>` builds locally and deploys each admitted Worker and frontend
85
+ update remotely through the same path as `deploy`; it starts no local Worker, Vite server, or
86
+ tunnel. Omitting `route` uses the observed stable `*.workers.dev` issuer.
87
+
23
88
  One watcher serializes its own updates. For an existing Worker, it uploads a candidate, reconciles
24
89
  configured triggers, and stages the candidate at 0% while the previous version retains 100% of normal
25
90
  HTTP traffic. Exact-version probes verify Publication, Bundle, and serving identity before promotion;
@@ -41,12 +106,6 @@ Routes, custom domains, schedules, and other non-versioned provider settings are
41
106
  Wrangler before candidate probing; they can remain changed after a failed attempt. Candidate readiness
42
107
  protects the HTTP implementation, not an atomic rollback of external resources or trigger settings.
43
108
 
44
- When an Environment also declares `installation`, the SDK excludes another local checkout that
45
- targets the same resolved `Kernel issuer + Domain origin` (including bookmark aliases), reconciles
46
- exact installed Release evidence, and opens
47
- the default View when the Domain has a frontend. These are Project-tooling behaviors rather
48
- than Cloudflare adapter responsibilities.
49
-
50
109
  ## Frontend files
51
110
 
52
111
  The Worker runs before Workers Static Assets on every request and owns frontend response headers
@@ -89,7 +148,7 @@ same bytes. Each deployment binds its own values as plain Worker bindings:
89
148
  | --- | --- |
90
149
  | `WORKER_URL` | serving origin of the deployment |
91
150
  | `ASTRALE_SETTINGS` | canonical JSON of `{ invocationTimeoutMs, maximumRequestBytes, router, tokenExchange }`, defaults resolved, with optional `durableOptions` |
92
- | `ASTRALE_BUILD_DIGEST` | build digest, bound only by hosts that deploy immutable Workers; never by a stable Worker |
151
+ | `ASTRALE_BUILD_DIGEST` | build digest the host recomputed from the uploaded bytes, bound only by hosts that deploy immutable Workers; never by a stable Worker |
93
152
  | `IDENTITY_ISS`, `ASTRALE_PROVIDER_ASSIGNED_WORKER` | **legacy direct mode only** (deprecated): a stable issuer behind another route, and the workers.dev claim |
94
153
 
95
154
  These names are adapter-owned: preparation refuses an author var, or a `wrangler.vars` entry, that
@@ -97,6 +156,14 @@ takes one, and deployment refuses a secret that does. A host that deploys the Wo
97
156
  the settings with `encodeWorkerSettings` from `@astrale-os/adapter-cloudflare/worker`. A generated
98
157
  Worker refuses execution without `ASTRALE_SETTINGS`.
99
158
 
159
+ `ASTRALE_BUILD_DIGEST` selects what the Worker serves. Bound, the Worker is an immutable deployment:
160
+ it seals the `DomainRelease` v4 of its code at its `WORKER_URL`, which is its issuer, and serves it
161
+ at `/.well-known/astrale/release.json` beside its frozen v3 projection at `domain.json`; it admits
162
+ only routing that names that exact release or projection. Unbound, it is a stable Worker and serves
163
+ exactly the v3 Publication of today, answering 404 at `release.json`. The Worker refuses execution,
164
+ instead of falling back to v3, when the digest is malformed, when it is bound without `WORKER_URL`,
165
+ or beside a direct-mode binding or a configured `identityIssuer`.
166
+
100
167
  The two direct-mode bindings are deprecated. Their replacement is an immutable deployment, whose
101
168
  host binds `WORKER_URL` to the deployment URL, which is also its issuer (namespace mode). They are
102
169
  deleted with direct mode, once the Shell, Services, Issues, domains and ui configurations deploy in
package/dist/adapter.d.ts CHANGED
@@ -1,15 +1,23 @@
1
1
  import type { Deployment } from '@astrale-os/sdk/deployment';
2
- import type { LegacyAdapter } from '@astrale-os/sdk/deployment/adapter';
3
- import type { legacy } from '@astrale-os/sdk/deployment/release';
4
- import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
2
+ import type { Adapter } from '@astrale-os/sdk/deployment/adapter';
3
+ import type { CloudflareDeployDependencies } from './legacy/direct/index.js';
4
+ import type { NamespaceDependencies } from './namespace/index.js';
5
5
  import type { CloudflareParams } from './params.js';
6
- import { artifact } from './build/artifact.js';
7
- import { type CloudflareDeployDependencies } from './deploy/index.js';
8
- import { signingIdentity } from './identity/source.js';
6
+ import { artifact, signingIdentity } from './legacy/direct/index.js';
7
+ export { waitForReadiness, type ReadinessCheck } from './legacy/direct/index.js';
8
+ export type { NamespaceDependencies } from './namespace/index.js';
9
9
  export interface CloudflareDependencies extends CloudflareDeployDependencies {
10
10
  readonly artifact: typeof artifact;
11
11
  readonly signingIdentity: typeof signingIdentity;
12
+ /** The effects of namespace mode. Default: `fetch`, `process.env`, a new key, the clock. */
13
+ readonly namespace?: NamespaceDependencies;
12
14
  }
13
- export declare function cloudflare(parameters?: CloudflareParams): Deployment<CloudflareParams, LegacyAdapter<CloudflareParams>>;
14
- export declare function cloudflareWithDependencies(parameters: CloudflareParams, dependencies: CloudflareDependencies): Deployment<CloudflareParams, LegacyAdapter<CloudflareParams>>;
15
- export declare function waitForReadiness(verify: typeof verifyReadiness, release: legacy.Release, signal?: AbortSignal): Promise<void>;
15
+ /**
16
+ * Deploy one Project Environment through Cloudflare Workers.
17
+ *
18
+ * With `namespace`, each release becomes one immutable deployment in that platform dispatch
19
+ * namespace (adapter interface v2). Without it, the Environment stays on the legacy direct mode:
20
+ * one stable Worker replaced in place by each deploy (CT33).
21
+ */
22
+ export declare function cloudflare(parameters?: CloudflareParams): Deployment<CloudflareParams, Adapter<CloudflareParams>>;
23
+ export declare function cloudflareWithDependencies(parameters: CloudflareParams, dependencies: CloudflareDependencies): Deployment<CloudflareParams, Adapter<CloudflareParams>>;
package/dist/adapter.js CHANGED
@@ -1,16 +1,19 @@
1
1
  import { defineAdapter, defineDeployment } from '@astrale-os/sdk/deployment/adapter';
2
- import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
3
2
  import { createRequire } from 'node:module';
4
- import { artifact, materialize } from './build/artifact.js';
5
3
  import { cloudflareWorkerBundler } from './build/bundler.js';
6
- import { verifyWorkerFrontend } from './build/frontend/readiness.js';
7
- import { deployCloudflare } from './deploy/index.js';
8
- import { versionReadinessFetch } from './deploy/readiness.js';
9
- import { signingIdentity } from './identity/source.js';
10
- import { runWranglerRollout } from './wrangler/rollout.js';
11
- import { runWranglerDeploymentStatus } from './wrangler/status.js';
4
+ import { createSigningIdentity } from './identity/material.js';
5
+ import { artifact, deployCloudflare, directReadiness, materialize, runWranglerDeploymentStatus, runWranglerRollout, signingIdentity, } from './legacy/direct/index.js';
6
+ import { admitNamespace, configureNamespace, deployNamespaceRelease, placeNamespace, retainNamespaceDeployment, } from './namespace/index.js';
7
+ export { waitForReadiness } from './legacy/direct/index.js';
12
8
  const packageVersion = createRequire(import.meta.url)('../package.json')
13
9
  .version;
10
+ /**
11
+ * Deploy one Project Environment through Cloudflare Workers.
12
+ *
13
+ * With `namespace`, each release becomes one immutable deployment in that platform dispatch
14
+ * namespace (adapter interface v2). Without it, the Environment stays on the legacy direct mode:
15
+ * one stable Worker replaced in place by each deploy (CT33).
16
+ */
14
17
  export function cloudflare(parameters = {}) {
15
18
  return cloudflareWithDependencies(parameters, {
16
19
  artifact,
@@ -18,67 +21,37 @@ export function cloudflare(parameters = {}) {
18
21
  runWranglerRollout,
19
22
  runWranglerDeploymentStatus,
20
23
  signingIdentity,
21
- waitForReadiness: (release, signal, version, worker, workerName) => waitForReadiness(async (release, options) => {
22
- const checks = {
23
- ...options,
24
- fetch: versionReadinessFetch(release.addressing.publicUrl, version, globalThis.fetch, workerName, release.addressing.issuer),
25
- };
26
- await verifyReadiness(release, checks);
27
- await verifyWorkerFrontend(release, worker, checks);
28
- }, release, signal),
24
+ waitForReadiness: directReadiness,
29
25
  });
30
26
  }
31
27
  export function cloudflareWithDependencies(parameters, dependencies) {
28
+ const namespace = dependencies.namespace ?? platformNamespaceDependencies();
32
29
  const adapter = defineAdapter({
33
30
  name: 'cloudflare',
34
31
  version: packageVersion,
35
32
  bundler: cloudflareWorkerBundler,
33
+ admit: admitCloudflare,
34
+ configure: configureNamespace,
35
+ placement: async (parameters) => placeNamespace(parameters),
36
+ deployRelease: (parameters, context) => deployNamespaceRelease(parameters, context, namespace),
37
+ retain: (parameters, context) => retainNamespaceDeployment(parameters, context, namespace),
38
+ // Legacy direct mode (CT33 `legacy-direct`), deleted with it (D10).
36
39
  prepare: dependencies.artifact,
37
40
  deploy: (parameters, context) => deployCloudflare(parameters, context, dependencies),
38
41
  secretsFile: (parameters) => parameters.secrets,
39
42
  });
40
43
  return defineDeployment(adapter, parameters);
41
44
  }
42
- export async function waitForReadiness(verify, release, signal) {
43
- const deadline = Date.now() + 90_000;
44
- let last;
45
- while (Date.now() < deadline) {
46
- throwIfAborted(signal);
47
- try {
48
- await verify(release, {
49
- signal: signal === undefined
50
- ? AbortSignal.timeout(5_000)
51
- : AbortSignal.any([signal, AbortSignal.timeout(5_000)]),
52
- });
53
- return;
54
- }
55
- catch (cause) {
56
- throwIfAborted(signal);
57
- last = cause;
58
- await pause(signal);
59
- }
60
- }
61
- throw last instanceof Error ? last : new Error('Cloudflare Release did not become ready.');
45
+ /** Refuse a malformed `namespace` when the Project is defined, before any build. */
46
+ function admitCloudflare(parameters) {
47
+ if (parameters.namespace !== undefined)
48
+ admitNamespace(parameters.namespace);
62
49
  }
63
- function pause(signal) {
64
- return new Promise((resolve, reject) => {
65
- const timer = setTimeout(done, 1_000);
66
- const abort = () => done(abortError(signal));
67
- signal?.addEventListener('abort', abort, { once: true });
68
- function done(cause) {
69
- clearTimeout(timer);
70
- signal?.removeEventListener('abort', abort);
71
- if (cause === undefined)
72
- resolve();
73
- else
74
- reject(cause);
75
- }
50
+ function platformNamespaceDependencies() {
51
+ return Object.freeze({
52
+ fetch: (input, init) => fetch(input, init),
53
+ environment: process.env,
54
+ createSigningIdentity,
55
+ now: () => new Date(),
76
56
  });
77
57
  }
78
- function throwIfAborted(signal) {
79
- if (signal?.aborted)
80
- throw abortError(signal);
81
- }
82
- function abortError(signal) {
83
- return signal?.reason instanceof Error ? signal.reason : new Error('Deployment interrupted.');
84
- }
@@ -54,4 +54,20 @@ export interface WranglerCodegenOptions {
54
54
  */
55
55
  wrangler?: Record<string, unknown>;
56
56
  }
57
+ /**
58
+ * The Workers runtime every generated Worker runs on, wherever it is deployed: its compatibility
59
+ * date, kept on the runtime baseline qualified with Wrangler 4.123.0, and its compatibility flags.
60
+ * Domain execution calls its Kernel through the invocation's public issuer, so Cloudflare must route
61
+ * same-zone callbacks through the public front door instead of bypassing Worker routes
62
+ * (`global_fetch_strictly_public`). An immutable deployment freezes it into its configuration.
63
+ */
64
+ export declare const GENERATED_WORKER_RUNTIME: Readonly<{
65
+ compatibilityDate: "2026-08-11";
66
+ compatibilityFlags: readonly string[];
67
+ }>;
57
68
  export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
69
+ /**
70
+ * Whether a compatibility flag shapes the bundle (Wrangler's bundler reads it), so that no
71
+ * Environment may add it: bundling takes no Environment.
72
+ */
73
+ export declare function isBundlingCompatibilityFlag(flag: string): boolean;
@@ -12,16 +12,23 @@
12
12
  * (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
13
13
  */
14
14
  import { deepMergeConfig } from './merge.js';
15
- // Keep the generated date on the runtime baseline qualified with Wrangler 4.123.0.
16
- const COMPATIBILITY_DATE = '2026-08-11';
15
+ /**
16
+ * The Workers runtime every generated Worker runs on, wherever it is deployed: its compatibility
17
+ * date, kept on the runtime baseline qualified with Wrangler 4.123.0, and its compatibility flags.
18
+ * Domain execution calls its Kernel through the invocation's public issuer, so Cloudflare must route
19
+ * same-zone callbacks through the public front door instead of bypassing Worker routes
20
+ * (`global_fetch_strictly_public`). An immutable deployment freezes it into its configuration.
21
+ */
22
+ export const GENERATED_WORKER_RUNTIME = Object.freeze({
23
+ compatibilityDate: '2026-08-11',
24
+ compatibilityFlags: Object.freeze(['nodejs_compat', 'global_fetch_strictly_public']),
25
+ });
17
26
  export function generateWranglerConfig(opts) {
18
27
  const config = {
19
28
  name: opts.workerName,
20
29
  main: opts.main ?? './worker.gen.ts',
21
- compatibility_date: COMPATIBILITY_DATE,
22
- // Domain execution calls its Kernel through the invocation's public issuer. Cloudflare must
23
- // route same-zone callbacks through the public front door instead of bypassing Worker routes.
24
- compatibility_flags: ['nodejs_compat', 'global_fetch_strictly_public'],
30
+ compatibility_date: GENERATED_WORKER_RUNTIME.compatibilityDate,
31
+ compatibility_flags: [...GENERATED_WORKER_RUNTIME.compatibilityFlags],
25
32
  workers_dev: opts.route === undefined,
26
33
  version_metadata: { binding: 'ASTRALE_VERSION_METADATA' },
27
34
  observability: { enabled: true },
@@ -100,6 +107,13 @@ const BUNDLING_KEYS = [
100
107
  ];
101
108
  /** Compatibility flags Wrangler's bundler reads: Node.js polyfills, `navigator`, fetch typing, Python. */
102
109
  const BUNDLING_FLAG = /nodejs|navigator|fetch_iterable_type_support|python_workers/u;
110
+ /**
111
+ * Whether a compatibility flag shapes the bundle (Wrangler's bundler reads it), so that no
112
+ * Environment may add it: bundling takes no Environment.
113
+ */
114
+ export function isBundlingCompatibilityFlag(flag) {
115
+ return BUNDLING_FLAG.test(flag);
116
+ }
103
117
  /**
104
118
  * Deep-merge the dev's raw wrangler overlay over the generated config, after
105
119
  * refusing any attempt to override an adapter-owned key or a bundler input. Throwing (rather than
@@ -4,12 +4,3 @@ import type { WorkerSettings } from '../../worker/settings.js';
4
4
  export declare function isAdapterVar(name: string): boolean;
5
5
  /** Resolve one Environment's execution settings, defaults included, as its deployment binds them. */
6
6
  export declare function workerSettings(parameters: CloudflareParams): WorkerSettings;
7
- /**
8
- * The plain bindings one stable Worker deployment carries: the author's vars, its execution
9
- * settings and serving origin, and the legacy direct-mode bindings. Never `ASTRALE_BUILD_DIGEST`:
10
- * only an immutable deployment may answer for a build digest.
11
- */
12
- export declare function deploymentVars(parameters: CloudflareParams, deployment: {
13
- readonly configuredIssuer?: string;
14
- readonly providerAssignedWorker?: string;
15
- }): Readonly<Record<string, string>>;
@@ -1,7 +1,7 @@
1
1
  import { maximumExchangeTtl } from '@astrale-os/sdk/execution';
2
- import { captureDurableOptions, DEFAULT_INVOCATION_TIMEOUT_MS, DEFAULT_MAXIMUM_REQUEST_BYTES, encodeWorkerSettings, SETTINGS_BINDING, } from '../../worker/settings.js';
2
+ import { BUILD_DIGEST_BINDING } from '../../worker/build-digest.js';
3
+ import { captureDurableOptions, DEFAULT_INVOCATION_TIMEOUT_MS, DEFAULT_MAXIMUM_REQUEST_BYTES, SETTINGS_BINDING, } from '../../worker/settings.js';
3
4
  import { workerInvocationTimeout } from './invocation-timeout.js';
4
- import { directDeploymentVars } from './legacy/direct.js';
5
5
  import { workerRequestLimit } from './request-limit.js';
6
6
  import { resolveRouter } from './router.js';
7
7
  /**
@@ -10,7 +10,7 @@ import { resolveRouter } from './router.js';
10
10
  */
11
11
  const ADAPTER_VARS = new Set([
12
12
  'WORKER_URL',
13
- 'ASTRALE_BUILD_DIGEST',
13
+ BUILD_DIGEST_BINDING,
14
14
  SETTINGS_BINDING,
15
15
  'IDENTITY_ISS',
16
16
  'ASTRALE_PROVIDER_ASSIGNED_WORKER',
@@ -40,32 +40,3 @@ export function workerSettings(parameters) {
40
40
  }),
41
41
  });
42
42
  }
43
- /**
44
- * The plain bindings one stable Worker deployment carries: the author's vars, its execution
45
- * settings and serving origin, and the legacy direct-mode bindings. Never `ASTRALE_BUILD_DIGEST`:
46
- * only an immutable deployment may answer for a build digest.
47
- */
48
- export function deploymentVars(parameters, deployment) {
49
- const authored = [
50
- ...Object.keys(parameters.vars ?? {}),
51
- ...Object.keys(wranglerVars(parameters.wrangler)),
52
- ];
53
- const owned = authored.filter(isAdapterVar);
54
- if (owned.length > 0) {
55
- throw new TypeError(`Cloudflare var(s) ${owned.join(', ')} are adapter-owned bindings.`);
56
- }
57
- return Object.freeze({
58
- ...parameters.vars,
59
- [SETTINGS_BINDING]: encodeWorkerSettings(workerSettings(parameters)),
60
- ...(deployment.configuredIssuer === undefined
61
- ? {}
62
- : { WORKER_URL: deployment.configuredIssuer }),
63
- ...directDeploymentVars(parameters, deployment),
64
- });
65
- }
66
- function wranglerVars(wrangler) {
67
- const vars = wrangler?.vars;
68
- return vars !== null && typeof vars === 'object' && !Array.isArray(vars)
69
- ? vars
70
- : {};
71
- }
@@ -1,6 +1,4 @@
1
- export { deploymentAddressing } from './configuration/addressing.js';
2
1
  export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
3
2
  export { workerRequestLimit } from './configuration/request-limit.js';
4
3
  export { resolveRouter } from './configuration/router.js';
5
- export { deploymentVars, isAdapterVar, workerSettings } from './configuration/settings.js';
6
- export { workerName } from './configuration/worker-name.js';
4
+ export { isAdapterVar, workerSettings } from './configuration/settings.js';
@@ -1,6 +1,4 @@
1
- export { deploymentAddressing } from './configuration/addressing.js';
2
1
  export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
3
2
  export { workerRequestLimit } from './configuration/request-limit.js';
4
3
  export { resolveRouter } from './configuration/router.js';
5
- export { deploymentVars, isAdapterVar, workerSettings } from './configuration/settings.js';
6
- export { workerName } from './configuration/worker-name.js';
4
+ export { isAdapterVar, workerSettings } from './configuration/settings.js';
@@ -1,12 +1,18 @@
1
1
  export { generateBuildMaterialModule } from './material.js';
2
- export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
3
2
  export { cloudflareWorkerBundler } from './bundler.js';
4
3
  export { loadWorkerArtifact } from './worker/index.js';
5
4
  export type { WorkerArtifact } from './worker/index.js';
6
- export { uploadBuildDigest, uploadBuildEvidence, workerUpload } from './worker/upload.js';
7
- export { isAdapterVar, resolveRouter, workerName } from './configuration.js';
5
+ export { bundleUpload, uploadBuildDigest, uploadBuildEvidence, workerUpload, type BundleUpload, } from './worker/upload.js';
6
+ export { isAdapterVar, resolveRouter, workerSettings } from './configuration.js';
7
+ export { GENERATED_WORKER_RUNTIME } from './codegen/wrangler.js';
8
8
  export { frontendFiles } from './frontend/files.js';
9
9
  export { verifyWorkerFrontend } from './frontend/readiness.js';
10
10
  export { qualifyWorkerBundle } from './qualification.js';
11
11
  export { assertSingletonRuntimeRoots } from './roots.js';
12
- export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerTypes, } from '../wrangler/index.js';
12
+ export { runWranglerBundle, runWranglerTypes } from '../wrangler/index.js';
13
+ /**
14
+ * @deprecated Legacy direct mode only (`../legacy/direct/index.ts`): preparation of a stable
15
+ * Worker, its Wrangler deployment and its name. Replacement: `cloudflare({ namespace })`, which
16
+ * deploys one immutable deployment per release. Deleted with direct mode (D10).
17
+ */
18
+ export { artifact, materialize, prepareWorkerArtifact, runWranglerDeploy, runWranglerDeploymentStatus, workerName, } from '../legacy/direct/index.js';
@@ -1,11 +1,17 @@
1
1
  export { generateBuildMaterialModule } from './material.js';
2
- export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
3
2
  export { cloudflareWorkerBundler } from './bundler.js';
4
3
  export { loadWorkerArtifact } from './worker/index.js';
5
- export { uploadBuildDigest, uploadBuildEvidence, workerUpload } from './worker/upload.js';
6
- export { isAdapterVar, resolveRouter, workerName } from './configuration.js';
4
+ export { bundleUpload, uploadBuildDigest, uploadBuildEvidence, workerUpload, } from './worker/upload.js';
5
+ export { isAdapterVar, resolveRouter, workerSettings } from './configuration.js';
6
+ export { GENERATED_WORKER_RUNTIME } from './codegen/wrangler.js';
7
7
  export { frontendFiles } from './frontend/files.js';
8
8
  export { verifyWorkerFrontend } from './frontend/readiness.js';
9
9
  export { qualifyWorkerBundle } from './qualification.js';
10
10
  export { assertSingletonRuntimeRoots } from './roots.js';
11
- export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerTypes, } from '../wrangler/index.js';
11
+ export { runWranglerBundle, runWranglerTypes } from '../wrangler/index.js';
12
+ /**
13
+ * @deprecated Legacy direct mode only (`../legacy/direct/index.ts`): preparation of a stable
14
+ * Worker, its Wrangler deployment and its name. Replacement: `cloudflare({ namespace })`, which
15
+ * deploys one immutable deployment per release. Deleted with direct mode (D10).
16
+ */
17
+ export { artifact, materialize, prepareWorkerArtifact, runWranglerDeploy, runWranglerDeploymentStatus, workerName, } from '../legacy/direct/index.js';
@@ -1,10 +1,31 @@
1
- import type { PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
1
+ import type { Bundle, PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
2
2
  import type { Build } from '@astrale-os/sdk/deployment/build';
3
3
  import type { BuildDigest } from '@astrale-os/sdk/deployment/build/manifest';
4
4
  import type { WorkerArtifact } from './artifact.js';
5
5
  import { type WorkerUpload } from '../../release/build.js';
6
6
  /** The portable upload of one prepared Worker: exactly the modules and assets Services receives. */
7
7
  export declare function workerUpload(artifact: PreparedArtifact, worker: WorkerArtifact): WorkerUpload;
8
+ /**
9
+ * The portable upload of one Bundle of the Cloudflare Worker bundler, as an immutable deployment's
10
+ * host receives it: the entry and the modules it loads (ES modules and their WASM), and the
11
+ * frontend as Worker assets with the media type their extension names. Its build digest is the Bundle's own, so the host that
12
+ * recomputes it from these bytes finds exactly the build the release names; any other Bundle is
13
+ * refused.
14
+ */
15
+ export declare function bundleUpload(bundle: Bundle): BundleUpload;
16
+ /** The Worker upload of one Bundle, with each module's kind and each asset's media type. */
17
+ export interface BundleUpload extends WorkerUpload {
18
+ readonly modules: readonly {
19
+ readonly name: string;
20
+ readonly kind: 'esm' | 'wasm';
21
+ readonly bytes: Uint8Array;
22
+ }[];
23
+ readonly assets?: readonly {
24
+ readonly path: string;
25
+ readonly bytes: Uint8Array;
26
+ readonly contentType?: string;
27
+ }[];
28
+ }
8
29
  /** Build digest of the portable upload of one prepared Worker. */
9
30
  export declare function uploadBuildDigest(artifact: PreparedArtifact, worker: WorkerArtifact): BuildDigest;
10
31
  /** Record that preparation placed the CLI's Bundle for this Build. */
@@ -1,5 +1,8 @@
1
1
  import { buildDigest } from '@astrale-os/sdk/deployment/build/manifest';
2
2
  import { workerBuildManifest } from '../../release/build.js';
3
+ import { bundledWorker } from '../bundler.js';
4
+ import { inferMediaType } from './artifact.manifest.js';
5
+ import { RELEASE_ENTRY } from './execution.prepare.js';
3
6
  /** The portable upload of one prepared Worker: exactly the modules and assets Services receives. */
4
7
  export function workerUpload(artifact, worker) {
5
8
  const root = artifact.build.schema.compiled.root;
@@ -17,6 +20,43 @@ export function workerUpload(artifact, worker) {
17
20
  : { assets: worker.assets.files.map((file) => ({ path: file.path, bytes: file.bytes() })) }),
18
21
  });
19
22
  }
23
+ /**
24
+ * The portable upload of one Bundle of the Cloudflare Worker bundler, as an immutable deployment's
25
+ * host receives it: the entry and the modules it loads (ES modules and their WASM), and the
26
+ * frontend as Worker assets with the media type their extension names. Its build digest is the Bundle's own, so the host that
27
+ * recomputes it from these bytes finds exactly the build the release names; any other Bundle is
28
+ * refused.
29
+ */
30
+ export function bundleUpload(bundle) {
31
+ const worker = bundledWorker(bundle, bundle.build);
32
+ const root = bundle.build.schema.compiled.root;
33
+ const upload = Object.freeze({
34
+ origin: root.origin,
35
+ revision: root.revision,
36
+ bundle: bundle.manifest.schema.bundle,
37
+ entry: RELEASE_ENTRY,
38
+ modules: Object.freeze([
39
+ Object.freeze({ name: RELEASE_ENTRY, kind: 'esm', bytes: worker.entry }),
40
+ ...worker.modules.map((module) => Object.freeze({ name: module.path, kind: module.kind, bytes: module.content })),
41
+ ]),
42
+ ...(worker.frontend.length === 0
43
+ ? {}
44
+ : {
45
+ assets: Object.freeze(worker.frontend.map((file) => {
46
+ const contentType = inferMediaType(file.path);
47
+ return Object.freeze({
48
+ path: `/${file.path}`,
49
+ bytes: file.bytes(),
50
+ ...(contentType === undefined ? {} : { contentType }),
51
+ });
52
+ })),
53
+ }),
54
+ });
55
+ if (buildDigest(workerBuildManifest(upload)) !== bundle.digest) {
56
+ throw new TypeError('Worker upload of the Bundle does not reproduce its build digest.');
57
+ }
58
+ return upload;
59
+ }
20
60
  /** Build digest of the portable upload of one prepared Worker. */
21
61
  export function uploadBuildDigest(artifact, worker) {
22
62
  return buildDigest(workerBuildManifest(workerUpload(artifact, worker)));
package/dist/index.d.ts CHANGED
@@ -1,22 +1,24 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale Domain through
3
- * Cloudflare Workers on YOUR OWN Cloudflare account.
2
+ * `@astrale-os/adapter-cloudflare` — deploy an Astrale Domain through Cloudflare Workers.
4
3
  *
5
4
  * import { cloudflare } from '@astrale-os/adapter-cloudflare'
6
5
  *
7
6
  * environments: {
8
- * development: { deployment: cloudflare({ secrets: '.env.dev' }) },
9
- * production: { deployment: cloudflare({ route: 'crm.acme.dev' }) },
7
+ * production: {
8
+ * deployment: cloudflare({
9
+ * namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
10
+ * }),
11
+ * },
10
12
  * }
11
13
  *
12
- * `astrale-domain dev <environment>` remotely deploys each admitted update;
13
- * an Environment with no `route` ships to
14
- * `*.workers.dev`; an env with a `route` ships to that custom domain.
14
+ * With `namespace`, each release becomes one immutable deployment in that platform dispatch
15
+ * namespace, at `https://<label>.<routingDomain>`. Without it, the Environment is on the legacy
16
+ * direct mode (deprecated): one stable Worker on `route` or `*.workers.dev`, replaced in place by
17
+ * each deploy, which `astrale-domain dev <environment>` also serves.
15
18
  *
16
- * Prefer a managed deploy (no Cloudflare account)? Use
17
- * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
18
- * `/build` toolkit and ships it through the Astrale platform. Generic Project
19
- * tooling owns optional Kernel installation after provider readiness.
19
+ * Prefer a managed deploy (no Cloudflare account)? Use `@astrale-os/adapter-astrale`, which builds
20
+ * the same bundle via this package's `/build` toolkit and ships it through the Astrale platform. A
21
+ * deploy never installs: `astrale domain install <url>` installs the URL it prints.
20
22
  */
21
23
  export { cloudflare } from './cloudflare.js';
22
- export type { CloudflareParams, DurableWorkerOptions } from './params.js';
24
+ export type { CloudflareNamespace, CloudflareParams, DurableWorkerOptions } from './params.js';
package/dist/index.js CHANGED
@@ -1,21 +1,23 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale Domain through
3
- * Cloudflare Workers on YOUR OWN Cloudflare account.
2
+ * `@astrale-os/adapter-cloudflare` — deploy an Astrale Domain through Cloudflare Workers.
4
3
  *
5
4
  * import { cloudflare } from '@astrale-os/adapter-cloudflare'
6
5
  *
7
6
  * environments: {
8
- * development: { deployment: cloudflare({ secrets: '.env.dev' }) },
9
- * production: { deployment: cloudflare({ route: 'crm.acme.dev' }) },
7
+ * production: {
8
+ * deployment: cloudflare({
9
+ * namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
10
+ * }),
11
+ * },
10
12
  * }
11
13
  *
12
- * `astrale-domain dev <environment>` remotely deploys each admitted update;
13
- * an Environment with no `route` ships to
14
- * `*.workers.dev`; an env with a `route` ships to that custom domain.
14
+ * With `namespace`, each release becomes one immutable deployment in that platform dispatch
15
+ * namespace, at `https://<label>.<routingDomain>`. Without it, the Environment is on the legacy
16
+ * direct mode (deprecated): one stable Worker on `route` or `*.workers.dev`, replaced in place by
17
+ * each deploy, which `astrale-domain dev <environment>` also serves.
15
18
  *
16
- * Prefer a managed deploy (no Cloudflare account)? Use
17
- * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
18
- * `/build` toolkit and ships it through the Astrale platform. Generic Project
19
- * tooling owns optional Kernel installation after provider readiness.
19
+ * Prefer a managed deploy (no Cloudflare account)? Use `@astrale-os/adapter-astrale`, which builds
20
+ * the same bundle via this package's `/build` toolkit and ships it through the Astrale platform. A
21
+ * deploy never installs: `astrale domain install <url>` installs the URL it prints.
20
22
  */
21
23
  export { cloudflare } from './cloudflare.js';