@astrale-os/adapter-cloudflare 0.5.0-beta.20 → 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.
Files changed (201) hide show
  1. package/README.md +245 -0
  2. package/dist/adapter.d.ts +9 -15
  3. package/dist/adapter.js +43 -129
  4. package/dist/build/bundle/admit.d.ts +3 -0
  5. package/dist/build/bundle/admit.js +47 -0
  6. package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
  7. package/dist/build/bundle/compiled-wasm-loader.js +21 -0
  8. package/dist/build/bundler.d.ts +21 -0
  9. package/dist/build/bundler.js +96 -0
  10. package/dist/build/closure.d.ts +4 -1
  11. package/dist/build/closure.js +7 -1
  12. package/dist/build/codegen/execution.d.ts +3 -13
  13. package/dist/build/codegen/execution.js +2 -44
  14. package/dist/build/codegen/wrangler.d.ts +28 -10
  15. package/dist/build/codegen/wrangler.js +71 -21
  16. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  17. package/dist/build/configuration/invocation-timeout.js +9 -0
  18. package/dist/build/configuration/request-limit.d.ts +2 -0
  19. package/dist/build/configuration/request-limit.js +9 -0
  20. package/dist/build/configuration/router.d.ts +7 -0
  21. package/dist/build/configuration/router.js +17 -0
  22. package/dist/build/configuration/settings.d.ts +6 -0
  23. package/dist/build/configuration/settings.js +40 -0
  24. package/dist/build/configuration.d.ts +4 -9
  25. package/dist/build/configuration.js +4 -40
  26. package/dist/build/frontend/files.d.ts +19 -0
  27. package/dist/build/frontend/files.js +99 -0
  28. package/dist/build/frontend/readiness.d.ts +16 -0
  29. package/dist/build/frontend/readiness.js +21 -0
  30. package/dist/build/frontend/revision.d.ts +5 -0
  31. package/dist/build/frontend/revision.js +14 -0
  32. package/dist/build/frontend/vite.d.ts +14 -0
  33. package/dist/build/frontend/vite.js +42 -0
  34. package/dist/build/frontend/vite.process.d.ts +7 -0
  35. package/dist/build/frontend/vite.process.js +65 -0
  36. package/dist/build/frontend/vite.runner.d.ts +1 -0
  37. package/dist/build/frontend/vite.runner.js +155 -0
  38. package/dist/build/index.d.ts +10 -6
  39. package/dist/build/index.js +10 -6
  40. package/dist/build/material.d.ts +10 -0
  41. package/dist/build/material.js +25 -0
  42. package/dist/build/worker/codegen/entry.d.ts +9 -0
  43. package/dist/build/worker/codegen/entry.js +65 -0
  44. package/dist/build/worker/codegen/literal.d.ts +28 -0
  45. package/dist/build/worker/codegen/literal.js +136 -0
  46. package/dist/build/worker/codegen/service.d.ts +14 -0
  47. package/dist/build/worker/codegen/service.js +57 -0
  48. package/dist/build/worker/execution.prepare.d.ts +20 -0
  49. package/dist/build/worker/execution.prepare.js +129 -0
  50. package/dist/build/worker/media-type.d.ts +1 -0
  51. package/dist/build/worker/media-type.js +20 -0
  52. package/dist/build/worker/modules.d.ts +20 -0
  53. package/dist/build/worker/modules.js +32 -0
  54. package/dist/build/worker/specifier.d.ts +5 -0
  55. package/dist/build/worker/specifier.js +15 -0
  56. package/dist/build/worker/upload.d.ts +23 -0
  57. package/dist/build/worker/upload.js +42 -0
  58. package/dist/hosting/activation.d.ts +38 -0
  59. package/dist/hosting/activation.js +109 -0
  60. package/dist/hosting/assets.d.ts +14 -0
  61. package/dist/hosting/assets.js +53 -0
  62. package/dist/hosting/bounded.d.ts +10 -0
  63. package/dist/hosting/bounded.js +32 -0
  64. package/dist/hosting/bytes.d.ts +6 -0
  65. package/dist/hosting/bytes.js +25 -0
  66. package/dist/hosting/client.d.ts +144 -0
  67. package/dist/hosting/client.js +491 -0
  68. package/dist/hosting/dispatcher/cron.d.mts +10 -0
  69. package/dist/hosting/dispatcher/cron.mjs +135 -0
  70. package/dist/hosting/dispatcher/deployments.d.mts +26 -0
  71. package/dist/hosting/dispatcher/deployments.mjs +158 -0
  72. package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
  73. package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
  74. package/dist/hosting/dispatcher/env.d.mts +51 -0
  75. package/dist/hosting/dispatcher/failure.d.mts +4 -0
  76. package/dist/hosting/dispatcher/failure.mjs +15 -0
  77. package/dist/hosting/dispatcher/index.d.mts +4 -0
  78. package/dist/hosting/dispatcher/index.mjs +8 -0
  79. package/dist/hosting/dispatcher/modules.d.ts +24 -0
  80. package/dist/hosting/dispatcher/modules.js +55 -0
  81. package/dist/hosting/dispatcher/services.d.mts +23 -0
  82. package/dist/hosting/dispatcher/services.mjs +202 -0
  83. package/dist/hosting/identity.d.ts +15 -0
  84. package/dist/hosting/identity.js +36 -0
  85. package/dist/hosting/index.d.ts +34 -0
  86. package/dist/hosting/index.js +32 -0
  87. package/dist/hosting/kv.d.ts +90 -0
  88. package/dist/hosting/kv.js +207 -0
  89. package/dist/hosting/listing.d.ts +34 -0
  90. package/dist/hosting/listing.js +50 -0
  91. package/dist/hosting/names.d.ts +16 -0
  92. package/dist/hosting/names.js +28 -0
  93. package/dist/hosting/provision/account.d.ts +11 -0
  94. package/dist/hosting/provision/account.js +86 -0
  95. package/dist/hosting/provision/dispatcher.d.ts +42 -0
  96. package/dist/hosting/provision/dispatcher.js +99 -0
  97. package/dist/hosting/provision/ingress.d.ts +12 -0
  98. package/dist/hosting/provision/ingress.js +31 -0
  99. package/dist/hosting/provision/plan.d.ts +143 -0
  100. package/dist/hosting/provision/plan.js +246 -0
  101. package/dist/hosting/provision/routing.d.ts +82 -0
  102. package/dist/hosting/provision/routing.js +226 -0
  103. package/dist/hosting/readiness.d.ts +53 -0
  104. package/dist/hosting/readiness.js +82 -0
  105. package/dist/hosting/refusal.d.ts +28 -0
  106. package/dist/hosting/refusal.js +13 -0
  107. package/dist/hosting/retirement.d.ts +70 -0
  108. package/dist/hosting/retirement.js +107 -0
  109. package/dist/hosting/retry-after.d.ts +6 -0
  110. package/dist/hosting/retry-after.js +55 -0
  111. package/dist/hosting/script.d.ts +186 -0
  112. package/dist/hosting/script.js +324 -0
  113. package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
  114. package/dist/hosting/testing/fake-cloudflare.js +757 -0
  115. package/dist/hosting/testing/index.d.ts +6 -0
  116. package/dist/hosting/testing/index.js +6 -0
  117. package/dist/hosting/time.d.ts +4 -0
  118. package/dist/hosting/time.js +20 -0
  119. package/dist/identity/binding.d.ts +1 -1
  120. package/dist/identity/binding.js +1 -1
  121. package/dist/identity/material.d.ts +1 -2
  122. package/dist/identity/material.js +5 -18
  123. package/dist/index.d.ts +14 -12
  124. package/dist/index.js +13 -11
  125. package/dist/namespace/configure.d.ts +22 -0
  126. package/dist/namespace/configure.js +199 -0
  127. package/dist/namespace/coordinates.d.ts +15 -0
  128. package/dist/namespace/coordinates.js +49 -0
  129. package/dist/namespace/deploy-release.d.ts +53 -0
  130. package/dist/namespace/deploy-release.js +389 -0
  131. package/dist/namespace/hosting.d.ts +29 -0
  132. package/dist/namespace/hosting.js +120 -0
  133. package/dist/namespace/index.d.ts +12 -0
  134. package/dist/namespace/index.js +12 -0
  135. package/dist/namespace/list.d.ts +18 -0
  136. package/dist/namespace/list.js +63 -0
  137. package/dist/namespace/readiness.d.ts +30 -0
  138. package/dist/namespace/readiness.js +31 -0
  139. package/dist/namespace/record.d.ts +21 -0
  140. package/dist/namespace/record.js +53 -0
  141. package/dist/params.d.ts +60 -76
  142. package/dist/release/build.d.ts +35 -0
  143. package/dist/release/build.js +44 -0
  144. package/dist/release/deployment.d.ts +44 -0
  145. package/dist/release/deployment.js +141 -0
  146. package/dist/release/index.d.ts +2 -2
  147. package/dist/release/index.js +2 -2
  148. package/dist/worker/binary.d.ts +21 -0
  149. package/dist/worker/binary.js +31 -0
  150. package/dist/worker/build-digest.d.ts +10 -0
  151. package/dist/worker/build-digest.js +22 -0
  152. package/dist/worker/cache.d.ts +28 -0
  153. package/dist/worker/cache.js +70 -0
  154. package/dist/worker/durable.d.ts +3 -0
  155. package/dist/worker/durable.js +5 -0
  156. package/dist/worker/entry.d.ts +38 -25
  157. package/dist/worker/entry.js +87 -109
  158. package/dist/worker/front.d.ts +56 -0
  159. package/dist/worker/front.js +59 -0
  160. package/dist/worker/frontend.d.ts +4 -0
  161. package/dist/worker/frontend.js +83 -0
  162. package/dist/worker/index.d.ts +4 -1
  163. package/dist/worker/index.js +4 -1
  164. package/dist/worker/restate.d.ts +6 -0
  165. package/dist/worker/restate.js +6 -0
  166. package/dist/worker/settings.d.ts +47 -0
  167. package/dist/worker/settings.js +163 -0
  168. package/dist/wrangler/bundle.d.ts +10 -0
  169. package/dist/wrangler/bundle.js +27 -0
  170. package/dist/wrangler/index.d.ts +3 -0
  171. package/dist/wrangler/index.js +3 -0
  172. package/dist/wrangler/process.d.ts +15 -0
  173. package/dist/wrangler/process.js +113 -0
  174. package/dist/wrangler/type-generation.d.ts +6 -0
  175. package/dist/wrangler/type-generation.js +19 -0
  176. package/package.json +39 -12
  177. package/template/astrale.config.ts +42 -36
  178. package/dist/build/artifact.d.ts +0 -8
  179. package/dist/build/artifact.js +0 -179
  180. package/dist/build/codegen/gateway.d.ts +0 -1
  181. package/dist/build/codegen/gateway.js +0 -7
  182. package/dist/build/frontend-v1.d.ts +0 -16
  183. package/dist/build/frontend-v1.js +0 -133
  184. package/dist/build/parse-output.d.ts +0 -26
  185. package/dist/build/parse-output.js +0 -57
  186. package/dist/build/wrangler-cli.d.ts +0 -105
  187. package/dist/build/wrangler-cli.js +0 -448
  188. package/dist/deploy/deploy.d.ts +0 -17
  189. package/dist/deploy/deploy.js +0 -207
  190. package/dist/deploy/index.d.ts +0 -1
  191. package/dist/deploy/index.js +0 -1
  192. package/dist/identity/secret.d.ts +0 -3
  193. package/dist/identity/secret.js +0 -7
  194. package/dist/identity/source.d.ts +0 -26
  195. package/dist/identity/source.js +0 -98
  196. package/dist/release/namespace.d.ts +0 -2
  197. package/dist/release/namespace.js +0 -6
  198. package/dist/release/target.d.ts +0 -2
  199. package/dist/release/target.js +0 -9
  200. package/dist/worker/gateway.d.ts +0 -15
  201. package/dist/worker/gateway.js +0 -26
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@astrale-os/adapter-cloudflare/hosting/testing` — one fake Cloudflare account for tests of a
3
+ * hosting built on the kit: the Workers for Platforms API, Workers KV, account Workers, zones, and
4
+ * public requests served by the REAL kit dispatcher (or a consumer's dispatcher).
5
+ */
6
+ export { FAKE_ACCOUNT, FAKE_API_BASE, FAKE_TOKEN, FAKE_ZONE, FakeCloudflare, type FakeBinding, type FakeCloudflareOptions, type FakeScript, type FakeWorker, type RecordedRequest, type ScriptRunner, } from './fake-cloudflare.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@astrale-os/adapter-cloudflare/hosting/testing` — one fake Cloudflare account for tests of a
3
+ * hosting built on the kit: the Workers for Platforms API, Workers KV, account Workers, zones, and
4
+ * public requests served by the REAL kit dispatcher (or a consumer's dispatcher).
5
+ */
6
+ export { FAKE_ACCOUNT, FAKE_API_BASE, FAKE_TOKEN, FAKE_ZONE, FakeCloudflare, } from './fake-cloudflare.js';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Wait `ms` without outliving the caller: a cancellation rejects the wait with the signal's reason.
3
+ */
4
+ export declare function wait(ms: number, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Wait `ms` without outliving the caller: a cancellation rejects the wait with the signal's reason.
3
+ */
4
+ export function wait(ms, signal) {
5
+ return new Promise((resolve, reject) => {
6
+ if (signal?.aborted === true) {
7
+ reject(signal.reason);
8
+ return;
9
+ }
10
+ const abort = () => {
11
+ clearTimeout(timer);
12
+ reject(signal?.reason);
13
+ };
14
+ const timer = setTimeout(() => {
15
+ signal?.removeEventListener('abort', abort);
16
+ resolve();
17
+ }, ms);
18
+ signal?.addEventListener('abort', abort, { once: true });
19
+ });
20
+ }
@@ -1,2 +1,2 @@
1
- /** Adapter-owned Worker secret that carries the execution identity private JWK. */
1
+ /** Adapter-owned Worker secret that carries the Domain signing private JWK. */
2
2
  export declare const SIGNING_IDENTITY_BINDING = "ASTRALE_SIGNING_IDENTITY";
@@ -1,2 +1,2 @@
1
- /** Adapter-owned Worker secret that carries the execution identity private JWK. */
1
+ /** Adapter-owned Worker secret that carries the Domain signing private JWK. */
2
2
  export const SIGNING_IDENTITY_BINDING = 'ASTRALE_SIGNING_IDENTITY';
@@ -2,6 +2,5 @@ import type { JsonWebKey } from '@astrale-os/sdk/auth';
2
2
  export type SigningIdentityMaterial = JsonWebKey & {
3
3
  readonly kid: string;
4
4
  };
5
- export declare function createSigningIdentity(): Promise<SigningIdentityMaterial>;
6
5
  /** Admit private Ed25519 material and its collision-resistant public identity. */
7
- export declare function admitSigningIdentity(input: unknown, owner: string, legacyKeyId?: string): Promise<SigningIdentityMaterial>;
6
+ export declare function admitSigningIdentity(input: unknown, owner: string): Promise<SigningIdentityMaterial>;
@@ -1,15 +1,6 @@
1
- import { calculateJwkThumbprint, exportJWK, generateKeyPair, importJWK } from 'jose';
2
- export async function createSigningIdentity() {
3
- const { privateKey } = await generateKeyPair('EdDSA', { extractable: true });
4
- const exported = await exportJWK(privateKey);
5
- return admitSigningIdentity({
6
- ...exported,
7
- alg: 'EdDSA',
8
- kid: await calculateJwkThumbprint(exported),
9
- }, 'generated identity');
10
- }
1
+ import { calculateJwkThumbprint, importJWK } from 'jose';
11
2
  /** Admit private Ed25519 material and its collision-resistant public identity. */
12
- export async function admitSigningIdentity(input, owner, legacyKeyId) {
3
+ export async function admitSigningIdentity(input, owner) {
13
4
  if (input === null || typeof input !== 'object' || Array.isArray(input))
14
5
  invalid(owner);
15
6
  const value = input;
@@ -22,20 +13,16 @@ export async function admitSigningIdentity(input, owner, legacyKeyId) {
22
13
  value.d.length === 0) {
23
14
  invalid(owner);
24
15
  }
25
- const thumbprint = await calculateJwkThumbprint(value);
26
- const admitted = legacyKeyId !== undefined && (value.kid === undefined || value.kid === legacyKeyId)
27
- ? { ...value, kid: thumbprint }
28
- : value;
29
- if (admitted.kid !== thumbprint) {
16
+ if (value.kid !== (await calculateJwkThumbprint(value))) {
30
17
  throw new TypeError(`Cloudflare signing identity '${owner}' must use its JWK thumbprint as kid.`);
31
18
  }
32
19
  try {
33
- await importJWK(admitted, 'EdDSA');
20
+ await importJWK(value, 'EdDSA');
34
21
  }
35
22
  catch (cause) {
36
23
  throw invalid(owner, cause);
37
24
  }
38
- return admitted;
25
+ return value;
39
26
  }
40
27
  function invalid(owner, cause) {
41
28
  throw new TypeError(`Cloudflare signing identity '${owner}' is not a private Ed25519 JWK.`, cause === undefined ? undefined : { cause });
package/dist/index.d.ts CHANGED
@@ -1,20 +1,22 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale application 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
- * adapter: cloudflare({
8
- * dev: { secrets: '.env.dev' },
9
- * prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
10
- * })
6
+ * environments: {
7
+ * production: {
8
+ * deployment: cloudflare({
9
+ * namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
10
+ * }),
11
+ * },
12
+ * }
11
13
  *
12
- * `dev` runs `wrangler dev` locally; an env with no `route` ships to
13
- * `*.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>`. Each deployment keeps its release immutable.
14
16
  *
15
- * Prefer a managed deploy (no Cloudflare account)? Use
16
- * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
17
- * `/build` toolkit and ships it through the Astrale platform.
17
+ * Prefer a managed deploy (no Cloudflare account)? Use `@astrale-os/adapter-astrale`, which builds
18
+ * the same bundle via this package's `/build` toolkit and ships it through the Astrale platform. A
19
+ * deploy never installs: `astrale domain install <url>` installs the URL it prints.
18
20
  */
19
21
  export { cloudflare } from './cloudflare.js';
20
- export type { CloudflareParams } from './params.js';
22
+ export type { CloudflareNamespace, CloudflareParams, DurableWorkerOptions } from './params.js';
package/dist/index.js CHANGED
@@ -1,19 +1,21 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale application 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
- * adapter: cloudflare({
8
- * dev: { secrets: '.env.dev' },
9
- * prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
10
- * })
6
+ * environments: {
7
+ * production: {
8
+ * deployment: cloudflare({
9
+ * namespace: { name: 'astrale-platform', routingDomain: 'platform.astrale.ai' },
10
+ * }),
11
+ * },
12
+ * }
11
13
  *
12
- * `dev` runs `wrangler dev` locally; an env with no `route` ships to
13
- * `*.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>`. Each deployment keeps its release immutable.
14
16
  *
15
- * Prefer a managed deploy (no Cloudflare account)? Use
16
- * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
17
- * `/build` toolkit and ships it through the Astrale platform.
17
+ * Prefer a managed deploy (no Cloudflare account)? Use `@astrale-os/adapter-astrale`, which builds
18
+ * the same bundle via this package's `/build` toolkit and ships it through the Astrale platform. A
19
+ * deploy never installs: `astrale domain install <url>` installs the URL it prints.
18
20
  */
19
21
  export { cloudflare } from './cloudflare.js';
@@ -0,0 +1,22 @@
1
+ import type { ConfigureContext } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { FrozenConfigurationV1 } from '@astrale-os/sdk/deployment/address';
3
+ import type { CloudflareParams } from '../params.js';
4
+ /**
5
+ * What one deployment of a namespace-mode Environment freezes beside its build (CT16): the author's
6
+ * variables, the execution settings the generated Worker runs under, defaults resolved, its durable
7
+ * options when the Environment declares them (AM-175), the Workers runtime of every generated
8
+ * Worker plus the author's extra compatibility flags, the service and
9
+ * dispatch namespace bindings the configuration names, the router and the names of the
10
+ * Environment's secrets.
11
+ *
12
+ * Pure: the same parameters and secret names give the same configuration, so the same release
13
+ * gives the same deployment label on every run. Nothing an immutable deployment cannot carry is
14
+ * dropped silently: a `wrangler` key outside `services`, `dispatch_namespaces` and
15
+ * `compatibility_flags` is refused, `triggers` first (an immutable deployment runs no cron of its
16
+ * own, D13), and so is a router binding other than `ROUTER`. A dispatch namespace binding never
17
+ * names the namespace the deployment itself lives in (AM-174); which other namespaces a deployment
18
+ * may bind is its host's to decide (Services refuses any on a tenant deployment).
19
+ */
20
+ export declare function configureNamespace(parameters: CloudflareParams, context: ConfigureContext): FrozenConfigurationV1;
21
+ /** `ASTRALE_SETTINGS` of one deployment: its frozen settings, the router bound as `ROUTER`. */
22
+ export declare function frozenSettings(configuration: FrozenConfigurationV1): string;
@@ -0,0 +1,199 @@
1
+ import { frozenConfiguration } from '@astrale-os/sdk/deployment/address';
2
+ import { GENERATED_WORKER_RUNTIME, isBundlingCompatibilityFlag } from '../build/codegen/wrangler.js';
3
+ import { isAdapterVar, resolveRouter, workerSettings } from '../build/configuration.js';
4
+ import { isWorkerName } from '../hosting/names.js';
5
+ import { ASSETS_BINDING, ROUTER_BINDING, SIGNING_IDENTITY_BINDING, VERSION_METADATA_BINDING, } from '../hosting/script.js';
6
+ import { encodeWorkerSettings } from '../worker/settings.js';
7
+ import { namespaceCoordinates } from './coordinates.js';
8
+ /** Binding names the adapter owns on an immutable deployment: no author name takes them. */
9
+ const RESERVED = new Set([
10
+ SIGNING_IDENTITY_BINDING,
11
+ VERSION_METADATA_BINDING,
12
+ ROUTER_BINDING,
13
+ ASSETS_BINDING,
14
+ 'SELF',
15
+ ]);
16
+ const BINDING_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/u;
17
+ const COMPATIBILITY_FLAG = /^[a-z0-9_]+$/u;
18
+ /** The only `wrangler` keys an immutable deployment's frozen configuration can carry. */
19
+ const NAMESPACE_WRANGLER_KEYS = [
20
+ 'services',
21
+ 'dispatch_namespaces',
22
+ 'compatibility_flags',
23
+ ];
24
+ /**
25
+ * What one deployment of a namespace-mode Environment freezes beside its build (CT16): the author's
26
+ * variables, the execution settings the generated Worker runs under, defaults resolved, its durable
27
+ * options when the Environment declares them (AM-175), the Workers runtime of every generated
28
+ * Worker plus the author's extra compatibility flags, the service and
29
+ * dispatch namespace bindings the configuration names, the router and the names of the
30
+ * Environment's secrets.
31
+ *
32
+ * Pure: the same parameters and secret names give the same configuration, so the same release
33
+ * gives the same deployment label on every run. Nothing an immutable deployment cannot carry is
34
+ * dropped silently: a `wrangler` key outside `services`, `dispatch_namespaces` and
35
+ * `compatibility_flags` is refused, `triggers` first (an immutable deployment runs no cron of its
36
+ * own, D13), and so is a router binding other than `ROUTER`. A dispatch namespace binding never
37
+ * names the namespace the deployment itself lives in (AM-174); which other namespaces a deployment
38
+ * may bind is its host's to decide (Services refuses any on a tenant deployment).
39
+ */
40
+ export function configureNamespace(parameters, context) {
41
+ const coordinates = namespaceCoordinates(parameters);
42
+ const wrangler = admitWrangler(parameters.wrangler, coordinates.name);
43
+ const vars = parameters.vars ?? {};
44
+ const { services, dispatchNamespaces } = wrangler;
45
+ const secrets = [...context.secrets];
46
+ const owned = [
47
+ ...Object.keys(vars),
48
+ ...services.map((binding) => binding.name),
49
+ ...dispatchNamespaces.map((binding) => binding.name),
50
+ ...secrets,
51
+ ]
52
+ .filter((name) => isAdapterVar(name) || RESERVED.has(name))
53
+ .sort();
54
+ if (owned.length > 0) {
55
+ throw new TypeError(`Cloudflare Environment ${context.environment} binds ${[...new Set(owned)].join(', ')}, ` +
56
+ 'which an immutable deployment binds itself; rename the variable, secret, service or ' +
57
+ 'dispatch namespace binding.');
58
+ }
59
+ for (const name of [...Object.keys(vars), ...secrets]) {
60
+ if (!BINDING_NAME.test(name)) {
61
+ throw new TypeError(`Cloudflare binding name ${name} is invalid.`);
62
+ }
63
+ }
64
+ const router = resolveRouter(parameters.router);
65
+ const settings = workerSettings(parameters);
66
+ return frozenConfiguration({
67
+ vars,
68
+ settings: {
69
+ maximumRequestBytes: settings.maximumRequestBytes,
70
+ invocationTimeoutMs: settings.invocationTimeoutMs,
71
+ tokenExchange: settings.tokenExchange,
72
+ ...(settings.durableOptions === undefined ? {} : { durableOptions: settings.durableOptions }),
73
+ },
74
+ runtime: {
75
+ compatibilityDate: GENERATED_WORKER_RUNTIME.compatibilityDate,
76
+ compatibilityFlags: [
77
+ ...new Set([
78
+ ...GENERATED_WORKER_RUNTIME.compatibilityFlags,
79
+ ...wrangler.compatibilityFlags,
80
+ ]),
81
+ ],
82
+ },
83
+ bindings: { services, dispatchNamespaces, secrets },
84
+ router: router === undefined
85
+ ? false
86
+ : { service: router.service, hostSuffix: router.hostSuffix, minLabels: router.minLabels },
87
+ });
88
+ }
89
+ /** `ASTRALE_SETTINGS` of one deployment: its frozen settings, the router bound as `ROUTER`. */
90
+ export function frozenSettings(configuration) {
91
+ const { settings, router } = configuration;
92
+ return encodeWorkerSettings({
93
+ ...settings,
94
+ router: router === false
95
+ ? false
96
+ : { binding: ROUTER_BINDING, hostSuffix: router.hostSuffix, minLabels: router.minLabels },
97
+ });
98
+ }
99
+ function admitWrangler(input, platform) {
100
+ if (input === undefined)
101
+ return { services: [], dispatchNamespaces: [], compatibilityFlags: [] };
102
+ if (input === null || typeof input !== 'object' || Array.isArray(input)) {
103
+ throw new TypeError('Cloudflare `wrangler` must be an object.');
104
+ }
105
+ if (Object.hasOwn(input, 'triggers')) {
106
+ throw new TypeError('cloudflare({ namespace }) refuses `wrangler.triggers`: an immutable deployment runs no ' +
107
+ 'cron of its own.');
108
+ }
109
+ const unsupported = Object.keys(input).filter((key) => !NAMESPACE_WRANGLER_KEYS.includes(key));
110
+ if (unsupported.length > 0) {
111
+ throw new TypeError(`cloudflare({ namespace }) cannot carry \`wrangler\` key(s) ${unsupported.join(', ')}: an ` +
112
+ 'immutable deployment binds only what its frozen configuration names, so its `wrangler` ' +
113
+ 'takes only `services`, `dispatch_namespaces` and `compatibility_flags`. Use `vars` for ' +
114
+ 'plain variables.');
115
+ }
116
+ return {
117
+ services: serviceBindings(input.services),
118
+ dispatchNamespaces: dispatchNamespaceBindings(input.dispatch_namespaces, platform),
119
+ compatibilityFlags: compatibilityFlags(input.compatibility_flags),
120
+ };
121
+ }
122
+ function serviceBindings(input) {
123
+ if (input === undefined)
124
+ return [];
125
+ if (!Array.isArray(input)) {
126
+ throw new TypeError('Cloudflare `wrangler.services` must be a list of `{ binding, service }`.');
127
+ }
128
+ return input.map((entry) => {
129
+ const value = entry;
130
+ if (value === null ||
131
+ typeof value !== 'object' ||
132
+ Array.isArray(value) ||
133
+ Object.keys(value).some((key) => key !== 'binding' && key !== 'service') ||
134
+ typeof value.binding !== 'string' ||
135
+ !BINDING_NAME.test(value.binding) ||
136
+ typeof value.service !== 'string' ||
137
+ !isWorkerName(value.service)) {
138
+ throw new TypeError('Cloudflare `wrangler.services` entries of a namespace deployment are exactly ' +
139
+ '`{ binding, service }`, a binding name and the name of a Worker of the account.');
140
+ }
141
+ return { name: value.binding, service: value.service };
142
+ });
143
+ }
144
+ /**
145
+ * The dispatch namespaces one deployment binds (AM-174): exactly `{ binding, namespace }` each, a
146
+ * Worker binding name and a Cloudflare dispatch namespace name, each binding name once. The
147
+ * namespace the deployment lives in is refused: a deployment never dispatches into its own
148
+ * platform namespace.
149
+ */
150
+ function dispatchNamespaceBindings(input, platform) {
151
+ if (input === undefined)
152
+ return [];
153
+ if (!Array.isArray(input)) {
154
+ throw new TypeError('Cloudflare `wrangler.dispatch_namespaces` must be a list of `{ binding, namespace }`.');
155
+ }
156
+ const bindings = input.map((entry) => {
157
+ const value = entry;
158
+ if (value === null ||
159
+ typeof value !== 'object' ||
160
+ Array.isArray(value) ||
161
+ Object.keys(value).some((key) => key !== 'binding' && key !== 'namespace') ||
162
+ typeof value.binding !== 'string' ||
163
+ !BINDING_NAME.test(value.binding) ||
164
+ typeof value.namespace !== 'string' ||
165
+ !isWorkerName(value.namespace)) {
166
+ throw new TypeError('Cloudflare `wrangler.dispatch_namespaces` entries of a namespace deployment are exactly ' +
167
+ '`{ binding, namespace }`, a binding name and the name of a dispatch namespace of the ' +
168
+ 'account.');
169
+ }
170
+ if (value.namespace === platform) {
171
+ throw new TypeError(`Cloudflare \`wrangler.dispatch_namespaces\` binds ${value.binding} to ${platform}, the ` +
172
+ 'platform namespace the deployment lives in; a deployment never dispatches into it.');
173
+ }
174
+ return { name: value.binding, namespace: value.namespace };
175
+ });
176
+ const names = bindings.map((binding) => binding.name);
177
+ const repeated = names.filter((name, index) => names.indexOf(name) !== index);
178
+ if (repeated.length > 0) {
179
+ throw new TypeError(`Cloudflare \`wrangler.dispatch_namespaces\` binds ${[...new Set(repeated)].join(', ')} ` +
180
+ 'more than once.');
181
+ }
182
+ return bindings;
183
+ }
184
+ function compatibilityFlags(input) {
185
+ if (input === undefined)
186
+ return [];
187
+ if (!Array.isArray(input) || input.some((flag) => typeof flag !== 'string')) {
188
+ throw new TypeError('Cloudflare `wrangler.compatibility_flags` must be a list of flags.');
189
+ }
190
+ const flags = input;
191
+ const generated = GENERATED_WORKER_RUNTIME.compatibilityFlags;
192
+ const refused = flags.filter((flag) => !COMPATIBILITY_FLAG.test(flag) ||
193
+ (isBundlingCompatibilityFlag(flag) && !generated.includes(flag)));
194
+ if (refused.length > 0) {
195
+ throw new TypeError(`wrangler: compatibility_flags ${refused.join(', ')} shape(s) the bundle or are invalid; ` +
196
+ 'bundling uses the adapter base configuration only.');
197
+ }
198
+ return flags;
199
+ }
@@ -0,0 +1,15 @@
1
+ import type { CloudflareNamespace, CloudflareParams } from '../params.js';
2
+ /** One admitted dispatch namespace of an Environment. */
3
+ export interface NamespaceCoordinates {
4
+ readonly name: string;
5
+ readonly routingDomain: string;
6
+ /** The account of `namespace.account`, else of `CLOUDFLARE_ACCOUNT_ID` at deploy time. */
7
+ readonly account?: string;
8
+ }
9
+ /**
10
+ * Admit the namespace of one Environment. Pure: the account and the token are read only when a deploy runs, and the
11
+ * routing KV is found by the title the kit derives from the name (`routingKvTitle`).
12
+ */
13
+ export declare function namespaceCoordinates(parameters: CloudflareParams): NamespaceCoordinates;
14
+ /** Admit the shape of one `namespace` parameter, before any effect. */
15
+ export declare function admitNamespace(namespace: CloudflareNamespace): void;
@@ -0,0 +1,49 @@
1
+ import { isWorkerName } from '../hosting/names.js';
2
+ /**
3
+ * Services' deployments namespaces (`astrale-deployments-<hex32>`): their scripts are managed by
4
+ * Services, which binds and retires them through its own Kernel. A namespace-mode Environment never
5
+ * deploys into one, even when a routing KV under its derived title exists.
6
+ */
7
+ const SERVICES_DEPLOYMENTS_NAMESPACE = /^astrale-deployments-[0-9a-f]{32}$/u;
8
+ const ROUTING_DOMAIN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
9
+ const ACCOUNT = /^[0-9a-f]{32}$/u;
10
+ /**
11
+ * Admit the namespace of one Environment. Pure: the account and the token are read only when a deploy runs, and the
12
+ * routing KV is found by the title the kit derives from the name (`routingKvTitle`).
13
+ */
14
+ export function namespaceCoordinates(parameters) {
15
+ const namespace = parameters.namespace;
16
+ if (namespace === undefined) {
17
+ throw new TypeError('Cloudflare deployment requires namespace: { name, routingDomain }.');
18
+ }
19
+ admitNamespace(namespace);
20
+ return Object.freeze({
21
+ name: namespace.name,
22
+ routingDomain: namespace.routingDomain,
23
+ ...(namespace.account === undefined ? {} : { account: namespace.account }),
24
+ });
25
+ }
26
+ /** Admit the shape of one `namespace` parameter, before any effect. */
27
+ export function admitNamespace(namespace) {
28
+ if (namespace === null || typeof namespace !== 'object' || Array.isArray(namespace)) {
29
+ throw new TypeError('Cloudflare `namespace` must be `{ name, routingDomain, account? }`.');
30
+ }
31
+ const unknown = Object.keys(namespace).filter((key) => key !== 'name' && key !== 'routingDomain' && key !== 'account');
32
+ if (unknown.length > 0) {
33
+ throw new TypeError(`Cloudflare \`namespace\` has unknown key(s): ${unknown.join(', ')}.`);
34
+ }
35
+ if (typeof namespace.name !== 'string' ||
36
+ !isWorkerName(namespace.name) ||
37
+ SERVICES_DEPLOYMENTS_NAMESPACE.test(namespace.name)) {
38
+ throw new TypeError('Cloudflare `namespace.name` must name a dispatch namespace (lower-case letters, digits and ' +
39
+ "dashes), never one of Services' deployments namespaces.");
40
+ }
41
+ if (typeof namespace.routingDomain !== 'string' ||
42
+ !ROUTING_DOMAIN.test(namespace.routingDomain)) {
43
+ throw new TypeError('Cloudflare `namespace.routingDomain` must be a lower-case DNS name.');
44
+ }
45
+ if (namespace.account !== undefined &&
46
+ (typeof namespace.account !== 'string' || !ACCOUNT.test(namespace.account))) {
47
+ throw new TypeError('Cloudflare `namespace.account` must be a 32-character account id.');
48
+ }
49
+ }
@@ -0,0 +1,53 @@
1
+ import type { Placement, ReleaseDeployContext, ReleaseDeployResult } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { DeploymentSigningIdentity } from '../hosting/identity.js';
3
+ import type { CloudflareParams } from '../params.js';
4
+ import type { NamespaceCoordinates } from './coordinates.js';
5
+ import { CloudflareClient } from '../hosting/client.js';
6
+ /** Services' tag on the scripts it hosts. A namespace-mode script never carries it. */
7
+ export declare const SERVICES_TAG = "astrale-service";
8
+ /** The effects of namespace mode, replaceable in tests. */
9
+ export interface NamespaceDependencies {
10
+ /** Reaches the Cloudflare API, and the deployment URL for readiness. */
11
+ readonly fetch: typeof fetch;
12
+ /** Where the account (`CLOUDFLARE_ACCOUNT_ID`) and the API token (`CLOUDFLARE_API_TOKEN`) are read. */
13
+ readonly environment: Readonly<Record<string, string | undefined>>;
14
+ /** Generate the Ed25519 key of one new deployment. */
15
+ readonly createSigningIdentity: () => Promise<DeploymentSigningIdentity>;
16
+ /** Wait between attempts (rate limits, readiness), and the clock their deadlines are read on. */
17
+ readonly pause?: (ms: number, signal?: AbortSignal) => Promise<void>;
18
+ readonly clock?: () => number;
19
+ /** The Cloudflare API base; a test serves a fake one. */
20
+ readonly apiBase?: string;
21
+ }
22
+ /**
23
+ * Where namespace mode places an Environment's deployments: under the namespace's routing domain,
24
+ * on a readable line. No effect.
25
+ */
26
+ export declare function placeNamespace(parameters: CloudflareParams): Placement;
27
+ /**
28
+ * Create, or reuse, the immutable deployment of one sealed release in the dispatch namespace,
29
+ * through the hosting kit.
30
+ *
31
+ * A new deployment is one script named by its label, uploaded create-only (`If-None-Match: *`)
32
+ * with a key generated for it, the build digest of its bytes, its settings and the Environment's
33
+ * current secrets: its `secret_text` bindings are exactly the configuration's declared secrets and
34
+ * its key (AM-132). Its record is then written, whose presence activates the label at the
35
+ * dispatcher. Readiness then waits until the URL serves the sealed release from the version the
36
+ * upload created (its `deployment_id`, in UUID form): the dispatcher serves no label before its
37
+ * record, so readiness follows activation.
38
+ *
39
+ * A label that already names a script is this release's deployment only when the script's artifact
40
+ * and line tags name this build on this line and `record:<label>` declares the same release and
41
+ * configuration (`sameRelease`), or, never activated, when the script binds exactly this
42
+ * configuration. Then that one script's declared secrets are rewritten in place and readiness waits
43
+ * for the version the rewrite minted. Anything else is a `deployment-conflict`, and nothing is
44
+ * written. No other script or record is ever touched (AM-4'). A `summary:<label>` an older adapter
45
+ * wrote is ignored: it is never read, written or deleted. A deployment is never identified by a
46
+ * provider version, which a secret written in place changes (OPS-2 X1).
47
+ */
48
+ export declare function deployNamespaceRelease(parameters: CloudflareParams, context: ReleaseDeployContext, dependencies: NamespaceDependencies): Promise<ReleaseDeployResult>;
49
+ /**
50
+ * The kit's Cloudflare client for the namespace's account, with the token of
51
+ * `CLOUDFLARE_API_TOKEN`; `token` says what the operation needs of it.
52
+ */
53
+ export declare function namespaceClient(coordinates: NamespaceCoordinates, signal: AbortSignal, dependencies: Pick<NamespaceDependencies, 'fetch' | 'environment' | 'pause' | 'apiBase'>, token?: string): CloudflareClient;