@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.
Files changed (249) hide show
  1. package/README.md +256 -0
  2. package/dist/adapter.d.ts +11 -0
  3. package/dist/adapter.js +54 -0
  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 +5 -0
  11. package/dist/build/closure.js +28 -0
  12. package/dist/build/codegen/execution.d.ts +3 -0
  13. package/dist/build/codegen/execution.js +2 -0
  14. package/dist/build/codegen/merge.d.ts +0 -1
  15. package/dist/build/codegen/merge.js +0 -1
  16. package/dist/build/codegen/wrangler.d.ts +32 -5
  17. package/dist/build/codegen/wrangler.js +77 -21
  18. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  19. package/dist/build/configuration/invocation-timeout.js +9 -0
  20. package/dist/build/configuration/request-limit.d.ts +2 -0
  21. package/dist/build/configuration/request-limit.js +9 -0
  22. package/dist/build/configuration/router.d.ts +7 -0
  23. package/dist/build/configuration/router.js +17 -0
  24. package/dist/build/configuration/settings.d.ts +6 -0
  25. package/dist/build/configuration/settings.js +40 -0
  26. package/dist/build/configuration.d.ts +4 -0
  27. package/dist/build/configuration.js +4 -0
  28. package/dist/build/frontend/files.d.ts +19 -0
  29. package/dist/build/frontend/files.js +99 -0
  30. package/dist/build/frontend/readiness.d.ts +16 -0
  31. package/dist/build/frontend/readiness.js +21 -0
  32. package/dist/build/frontend/revision.d.ts +5 -0
  33. package/dist/build/frontend/revision.js +14 -0
  34. package/dist/build/frontend/vite.d.ts +14 -0
  35. package/dist/build/frontend/vite.js +42 -0
  36. package/dist/build/frontend/vite.process.d.ts +7 -0
  37. package/dist/build/frontend/vite.process.js +65 -0
  38. package/dist/build/frontend/vite.runner.d.ts +1 -0
  39. package/dist/build/frontend/vite.runner.js +155 -0
  40. package/dist/build/index.d.ts +12 -16
  41. package/dist/build/index.js +12 -16
  42. package/dist/build/material.d.ts +10 -0
  43. package/dist/build/material.js +25 -0
  44. package/dist/build/metafile.d.ts +5 -0
  45. package/dist/build/metafile.js +14 -0
  46. package/dist/build/qualification.d.ts +5 -0
  47. package/dist/build/qualification.js +7 -0
  48. package/dist/build/roots.d.ts +2 -0
  49. package/dist/build/roots.js +34 -0
  50. package/dist/build/worker/codegen/entry.d.ts +9 -0
  51. package/dist/build/worker/codegen/entry.js +65 -0
  52. package/dist/build/worker/codegen/literal.d.ts +28 -0
  53. package/dist/build/worker/codegen/literal.js +136 -0
  54. package/dist/build/worker/codegen/service.d.ts +14 -0
  55. package/dist/build/worker/codegen/service.js +57 -0
  56. package/dist/build/worker/execution.prepare.d.ts +20 -0
  57. package/dist/build/worker/execution.prepare.js +129 -0
  58. package/dist/build/worker/media-type.d.ts +1 -0
  59. package/dist/build/worker/media-type.js +20 -0
  60. package/dist/build/worker/modules.d.ts +20 -0
  61. package/dist/build/worker/modules.js +32 -0
  62. package/dist/build/worker/specifier.d.ts +5 -0
  63. package/dist/build/worker/specifier.js +15 -0
  64. package/dist/build/worker/upload.d.ts +23 -0
  65. package/dist/build/worker/upload.js +42 -0
  66. package/dist/cloudflare.d.ts +1 -34
  67. package/dist/cloudflare.js +1 -205
  68. package/dist/hosting/activation.d.ts +38 -0
  69. package/dist/hosting/activation.js +109 -0
  70. package/dist/hosting/assets.d.ts +14 -0
  71. package/dist/hosting/assets.js +53 -0
  72. package/dist/hosting/bounded.d.ts +10 -0
  73. package/dist/hosting/bounded.js +32 -0
  74. package/dist/hosting/bytes.d.ts +6 -0
  75. package/dist/hosting/bytes.js +25 -0
  76. package/dist/hosting/client.d.ts +144 -0
  77. package/dist/hosting/client.js +491 -0
  78. package/dist/hosting/dispatcher/cron.d.mts +10 -0
  79. package/dist/hosting/dispatcher/cron.mjs +135 -0
  80. package/dist/hosting/dispatcher/deployments.d.mts +26 -0
  81. package/dist/hosting/dispatcher/deployments.mjs +158 -0
  82. package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
  83. package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
  84. package/dist/hosting/dispatcher/env.d.mts +51 -0
  85. package/dist/hosting/dispatcher/failure.d.mts +4 -0
  86. package/dist/hosting/dispatcher/failure.mjs +15 -0
  87. package/dist/hosting/dispatcher/index.d.mts +4 -0
  88. package/dist/hosting/dispatcher/index.mjs +8 -0
  89. package/dist/hosting/dispatcher/modules.d.ts +24 -0
  90. package/dist/hosting/dispatcher/modules.js +55 -0
  91. package/dist/hosting/dispatcher/services.d.mts +23 -0
  92. package/dist/hosting/dispatcher/services.mjs +202 -0
  93. package/dist/hosting/identity.d.ts +15 -0
  94. package/dist/hosting/identity.js +36 -0
  95. package/dist/hosting/index.d.ts +34 -0
  96. package/dist/hosting/index.js +32 -0
  97. package/dist/hosting/kv.d.ts +90 -0
  98. package/dist/hosting/kv.js +207 -0
  99. package/dist/hosting/listing.d.ts +34 -0
  100. package/dist/hosting/listing.js +50 -0
  101. package/dist/hosting/names.d.ts +16 -0
  102. package/dist/hosting/names.js +28 -0
  103. package/dist/hosting/provision/account.d.ts +11 -0
  104. package/dist/hosting/provision/account.js +86 -0
  105. package/dist/hosting/provision/dispatcher.d.ts +42 -0
  106. package/dist/hosting/provision/dispatcher.js +99 -0
  107. package/dist/hosting/provision/ingress.d.ts +12 -0
  108. package/dist/hosting/provision/ingress.js +31 -0
  109. package/dist/hosting/provision/plan.d.ts +143 -0
  110. package/dist/hosting/provision/plan.js +246 -0
  111. package/dist/hosting/provision/routing.d.ts +82 -0
  112. package/dist/hosting/provision/routing.js +226 -0
  113. package/dist/hosting/readiness.d.ts +53 -0
  114. package/dist/hosting/readiness.js +82 -0
  115. package/dist/hosting/refusal.d.ts +28 -0
  116. package/dist/hosting/refusal.js +13 -0
  117. package/dist/hosting/retirement.d.ts +70 -0
  118. package/dist/hosting/retirement.js +107 -0
  119. package/dist/hosting/retry-after.d.ts +6 -0
  120. package/dist/hosting/retry-after.js +55 -0
  121. package/dist/hosting/script.d.ts +186 -0
  122. package/dist/hosting/script.js +324 -0
  123. package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
  124. package/dist/hosting/testing/fake-cloudflare.js +757 -0
  125. package/dist/hosting/testing/index.d.ts +6 -0
  126. package/dist/hosting/testing/index.js +6 -0
  127. package/dist/hosting/time.d.ts +4 -0
  128. package/dist/hosting/time.js +20 -0
  129. package/dist/identity/binding.d.ts +2 -0
  130. package/dist/identity/binding.js +2 -0
  131. package/dist/identity/material.d.ts +6 -0
  132. package/dist/identity/material.js +29 -0
  133. package/dist/index.d.ts +14 -13
  134. package/dist/index.js +13 -12
  135. package/dist/namespace/configure.d.ts +22 -0
  136. package/dist/namespace/configure.js +199 -0
  137. package/dist/namespace/coordinates.d.ts +15 -0
  138. package/dist/namespace/coordinates.js +49 -0
  139. package/dist/namespace/deploy-release.d.ts +53 -0
  140. package/dist/namespace/deploy-release.js +389 -0
  141. package/dist/namespace/hosting.d.ts +29 -0
  142. package/dist/namespace/hosting.js +120 -0
  143. package/dist/namespace/index.d.ts +12 -0
  144. package/dist/namespace/index.js +12 -0
  145. package/dist/namespace/list.d.ts +18 -0
  146. package/dist/namespace/list.js +63 -0
  147. package/dist/namespace/readiness.d.ts +30 -0
  148. package/dist/namespace/readiness.js +31 -0
  149. package/dist/namespace/record.d.ts +21 -0
  150. package/dist/namespace/record.js +53 -0
  151. package/dist/params.d.ts +63 -66
  152. package/dist/params.js +0 -1
  153. package/dist/release/build.d.ts +35 -0
  154. package/dist/release/build.js +44 -0
  155. package/dist/release/deployment.d.ts +44 -0
  156. package/dist/release/deployment.js +141 -0
  157. package/dist/release/index.d.ts +2 -0
  158. package/dist/release/index.js +2 -0
  159. package/dist/worker/binary.d.ts +21 -0
  160. package/dist/worker/binary.js +31 -0
  161. package/dist/worker/build-digest.d.ts +10 -0
  162. package/dist/worker/build-digest.js +22 -0
  163. package/dist/worker/cache.d.ts +28 -0
  164. package/dist/worker/cache.js +70 -0
  165. package/dist/worker/durable.d.ts +3 -0
  166. package/dist/worker/durable.js +5 -0
  167. package/dist/worker/entry.d.ts +47 -0
  168. package/dist/worker/entry.js +135 -0
  169. package/dist/worker/fetch.d.ts +11 -0
  170. package/dist/worker/fetch.js +31 -0
  171. package/dist/worker/front.d.ts +56 -0
  172. package/dist/worker/front.js +59 -0
  173. package/dist/worker/frontend.d.ts +4 -0
  174. package/dist/worker/frontend.js +83 -0
  175. package/dist/worker/identity.d.ts +7 -0
  176. package/dist/worker/identity.js +23 -0
  177. package/dist/worker/index.d.ts +6 -48
  178. package/dist/worker/index.js +6 -186
  179. package/dist/worker/restate.d.ts +6 -0
  180. package/dist/worker/restate.js +6 -0
  181. package/dist/worker/settings.d.ts +47 -0
  182. package/dist/worker/settings.js +163 -0
  183. package/dist/wrangler/bundle.d.ts +10 -0
  184. package/dist/wrangler/bundle.js +27 -0
  185. package/dist/wrangler/index.d.ts +3 -0
  186. package/dist/wrangler/index.js +3 -0
  187. package/dist/wrangler/process.d.ts +15 -0
  188. package/dist/wrangler/process.js +113 -0
  189. package/dist/wrangler/type-generation.d.ts +6 -0
  190. package/dist/wrangler/type-generation.js +19 -0
  191. package/package.json +47 -22
  192. package/template/astrale.config.ts +43 -29
  193. package/dist/build/codegen/identity.d.ts +0 -10
  194. package/dist/build/codegen/identity.d.ts.map +0 -1
  195. package/dist/build/codegen/identity.js +0 -32
  196. package/dist/build/codegen/identity.js.map +0 -1
  197. package/dist/build/codegen/merge.d.ts.map +0 -1
  198. package/dist/build/codegen/merge.js.map +0 -1
  199. package/dist/build/codegen/worker.d.ts +0 -12
  200. package/dist/build/codegen/worker.d.ts.map +0 -1
  201. package/dist/build/codegen/worker.js +0 -40
  202. package/dist/build/codegen/worker.js.map +0 -1
  203. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  204. package/dist/build/codegen/wrangler.js.map +0 -1
  205. package/dist/build/frontend.d.ts +0 -26
  206. package/dist/build/frontend.d.ts.map +0 -1
  207. package/dist/build/frontend.js +0 -263
  208. package/dist/build/frontend.js.map +0 -1
  209. package/dist/build/index.d.ts.map +0 -1
  210. package/dist/build/index.js.map +0 -1
  211. package/dist/build/parse-output.d.ts +0 -27
  212. package/dist/build/parse-output.d.ts.map +0 -1
  213. package/dist/build/parse-output.js +0 -58
  214. package/dist/build/parse-output.js.map +0 -1
  215. package/dist/build/prepare.d.ts +0 -18
  216. package/dist/build/prepare.d.ts.map +0 -1
  217. package/dist/build/prepare.js +0 -117
  218. package/dist/build/prepare.js.map +0 -1
  219. package/dist/build/worker.d.ts +0 -15
  220. package/dist/build/worker.d.ts.map +0 -1
  221. package/dist/build/worker.js +0 -21
  222. package/dist/build/worker.js.map +0 -1
  223. package/dist/build/wrangler-cli.d.ts +0 -86
  224. package/dist/build/wrangler-cli.d.ts.map +0 -1
  225. package/dist/build/wrangler-cli.js +0 -275
  226. package/dist/build/wrangler-cli.js.map +0 -1
  227. package/dist/cloudflare.d.ts.map +0 -1
  228. package/dist/cloudflare.js.map +0 -1
  229. package/dist/index.d.ts.map +0 -1
  230. package/dist/index.js.map +0 -1
  231. package/dist/params.d.ts.map +0 -1
  232. package/dist/params.js.map +0 -1
  233. package/dist/worker/index.d.ts.map +0 -1
  234. package/dist/worker/index.js.map +0 -1
  235. package/src/build/codegen/identity.ts +0 -40
  236. package/src/build/codegen/merge.ts +0 -92
  237. package/src/build/codegen/worker.ts +0 -53
  238. package/src/build/codegen/wrangler.ts +0 -127
  239. package/src/build/frontend.ts +0 -324
  240. package/src/build/index.ts +0 -29
  241. package/src/build/parse-output.ts +0 -60
  242. package/src/build/prepare.ts +0 -161
  243. package/src/build/worker.ts +0 -37
  244. package/src/build/wrangler-cli.ts +0 -362
  245. package/src/cloudflare.ts +0 -251
  246. package/src/index.ts +0 -21
  247. package/src/params.ts +0 -92
  248. package/src/worker/index.ts +0 -276
  249. package/src/worker/tsconfig.json +0 -10
@@ -0,0 +1,30 @@
1
+ import type { Release } from '@astrale-os/sdk/deployment/release';
2
+ /**
3
+ * How long a deployment this deploy activated may take to serve: the dispatcher reads the label's
4
+ * new `record:<label>` from Workers KV, which propagates within about a minute.
5
+ */
6
+ export declare const ACTIVATION_READINESS_MS = 120000;
7
+ /**
8
+ * How long an already active deployment may take to serve the version an in-place secret write
9
+ * minted: Cloudflare serves it after about 4 s (OPS-2 X1).
10
+ */
11
+ export declare const ROTATION_READINESS_MS = 30000;
12
+ /**
13
+ * Wait until the deployment serves exactly its sealed release at its public URL, through the
14
+ * dispatcher (so after activation), from exactly the provider version this deploy made: its
15
+ * `release.json` (release and build digests), its Bundle and its issuer documents, each answered
16
+ * with `X-Astrale-Worker-Version` equal to that version. Bounded and cancellable; HTTPS
17
+ * verification is never weakened.
18
+ */
19
+ export declare function waitForNamespaceReadiness(input: {
20
+ /** The sealed release the deployment must serve at its URL. */
21
+ readonly release: Release;
22
+ /** The provider version that must answer, in the UUID form the Worker reports. */
23
+ readonly version: string;
24
+ readonly timeoutMs: number;
25
+ readonly signal: AbortSignal;
26
+ readonly fetch: typeof fetch;
27
+ /** Wait between attempts, and the clock the deadline is read on; replaceable in tests. */
28
+ readonly pause?: (ms: number, signal?: AbortSignal) => Promise<void>;
29
+ readonly now?: () => number;
30
+ }): Promise<void>;
@@ -0,0 +1,31 @@
1
+ import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
2
+ import { publicFetcher, waitForReadiness } from '../hosting/readiness.js';
3
+ /**
4
+ * How long a deployment this deploy activated may take to serve: the dispatcher reads the label's
5
+ * new `record:<label>` from Workers KV, which propagates within about a minute.
6
+ */
7
+ export const ACTIVATION_READINESS_MS = 120_000;
8
+ /**
9
+ * How long an already active deployment may take to serve the version an in-place secret write
10
+ * minted: Cloudflare serves it after about 4 s (OPS-2 X1).
11
+ */
12
+ export const ROTATION_READINESS_MS = 30_000;
13
+ /**
14
+ * Wait until the deployment serves exactly its sealed release at its public URL, through the
15
+ * dispatcher (so after activation), from exactly the provider version this deploy made: its
16
+ * `release.json` (release and build digests), its Bundle and its issuer documents, each answered
17
+ * with `X-Astrale-Worker-Version` equal to that version. Bounded and cancellable; HTTPS
18
+ * verification is never weakened.
19
+ */
20
+ export async function waitForNamespaceReadiness(input) {
21
+ await waitForReadiness({
22
+ url: new URL(input.release.url).origin,
23
+ version: input.version,
24
+ fetcher: publicFetcher(input.fetch),
25
+ timeoutMs: input.timeoutMs,
26
+ signal: input.signal,
27
+ check: (fetch, signal) => verifyReadiness(input.release, { fetch, signal }).then(() => { }),
28
+ ...(input.pause === undefined ? {} : { pause: input.pause }),
29
+ ...(input.now === undefined ? {} : { now: input.now }),
30
+ });
31
+ }
@@ -0,0 +1,21 @@
1
+ import type { DeploymentRecordV1 } from '@astrale-os/sdk/deployment/address';
2
+ import type { WorkerRecord } from '@astrale-os/sdk/deployment/worker';
3
+ /**
4
+ * The `DeploymentRecordV1` a label published, admitted as that label's own; anything else under a
5
+ * namespace label (no record, another media type, a record of another script) is refused as
6
+ * `record-invalid`.
7
+ */
8
+ export declare function publishedRecord(stored: WorkerRecord | null, label: string): DeploymentRecordV1;
9
+ /**
10
+ * Whether two records declare the same deployment: same origin, environment, release, build,
11
+ * Schema revision, configuration and script. Only the commit may differ: a redeploy of identical
12
+ * bytes and configuration from another commit is the same deployment, whose record keeps the
13
+ * commit it was first activated from. This is namespace mode's re-publication rule; the kit itself
14
+ * only ever keeps the same bytes.
15
+ */
16
+ export declare function sameRelease(left: DeploymentRecordV1, right: DeploymentRecordV1): boolean;
17
+ /**
18
+ * A published record as a listing returns it, unadmitted: its JSON value (JSON `null` included),
19
+ * its text when it is not JSON, `null` when the label publishes no record.
20
+ */
21
+ export declare function listedRecord(stored: WorkerRecord | null): unknown;
@@ -0,0 +1,53 @@
1
+ import { decodeDeploymentRecord } from '@astrale-os/sdk/deployment/address';
2
+ import { HostingRefusal } from '../hosting/refusal.js';
3
+ /**
4
+ * The `DeploymentRecordV1` a label published, admitted as that label's own; anything else under a
5
+ * namespace label (no record, another media type, a record of another script) is refused as
6
+ * `record-invalid`.
7
+ */
8
+ export function publishedRecord(stored, label) {
9
+ let record;
10
+ try {
11
+ if (stored === null)
12
+ throw new TypeError('The deployment publishes no record.');
13
+ record = decodeDeploymentRecord(stored);
14
+ }
15
+ catch {
16
+ throw new HostingRefusal('record-invalid', `The record of ${label} is not a DeploymentRecordV1.`);
17
+ }
18
+ if (record.providerScript !== label) {
19
+ throw new HostingRefusal('record-invalid', `The record published under ${label} names the script ${record.providerScript}.`);
20
+ }
21
+ return record;
22
+ }
23
+ /**
24
+ * Whether two records declare the same deployment: same origin, environment, release, build,
25
+ * Schema revision, configuration and script. Only the commit may differ: a redeploy of identical
26
+ * bytes and configuration from another commit is the same deployment, whose record keeps the
27
+ * commit it was first activated from. This is namespace mode's re-publication rule; the kit itself
28
+ * only ever keeps the same bytes.
29
+ */
30
+ export function sameRelease(left, right) {
31
+ return (left.origin === right.origin &&
32
+ left.environment === right.environment &&
33
+ left.releaseDigest === right.releaseDigest &&
34
+ left.buildDigest === right.buildDigest &&
35
+ left.schemaRevision === right.schemaRevision &&
36
+ left.configuration === right.configuration &&
37
+ left.providerScript === right.providerScript);
38
+ }
39
+ /**
40
+ * A published record as a listing returns it, unadmitted: its JSON value (JSON `null` included),
41
+ * its text when it is not JSON, `null` when the label publishes no record.
42
+ */
43
+ export function listedRecord(stored) {
44
+ if (stored === null)
45
+ return null;
46
+ const text = new TextDecoder().decode(stored.bytes);
47
+ try {
48
+ return JSON.parse(text);
49
+ }
50
+ catch {
51
+ return text;
52
+ }
53
+ }
package/dist/params.d.ts CHANGED
@@ -1,91 +1,88 @@
1
+ import type { DurableServing, ExchangeOptions } from '@astrale-os/sdk/execution';
1
2
  /**
2
- * `CloudflareParams` — the provider-typed config for the Cloudflare adapter.
3
- *
4
- * One type covers every env; per-env differences are just optional fields. The
5
- * same `{ dev, prod, canary, … }` map a developer writes in `astrale.config.ts`
6
- * is `Record<string, CloudflareParams>`.
7
- *
8
- * Three deployment shapes fall out of which fields are set:
9
- * • dev (local) — `watch()` runs `wrangler dev`; URL = http://localhost:<port>
10
- * • dev-remote — `deploy()` with no `route`; URL = https://<name>.<sub>.workers.dev
11
- * • remote (custom) — `deploy()` with `route`; URL = https://<route>
3
+ * The platform dispatch namespace an Environment deploys into. Each Release
4
+ * becomes one immutable script named by its deployment label, answering at
5
+ * `https://<label>.<routingDomain>` through the platform dispatcher; nothing is ever replaced in
6
+ * place. Only the platform deploys there (Shell, Services and the other platform Domains), so its
7
+ * lines are readable.
12
8
  */
13
- export interface CloudflareParams {
9
+ export interface CloudflareNamespace {
10
+ /** The dispatch namespace, e.g. `'astrale-platform'`. Its routing KV is found from this name. */
11
+ readonly name: string;
12
+ /** The DNS name the platform dispatcher answers under, e.g. `'platform.astrale.ai'`. */
13
+ readonly routingDomain: string;
14
14
  /**
15
- * Custom route / hostname for a routed deploy, e.g. `'crm.acme.dev'`. Omit to
16
- * deploy to `*.workers.dev`. Ignored by local `wrangler dev` (URL is
17
- * localhost) but still used as the placeholder base domain there.
15
+ * The Cloudflare account that holds the namespace. Default: `CLOUDFLARE_ACCOUNT_ID`. The API
16
+ * token is always read from `CLOUDFLARE_API_TOKEN`, never from the configuration.
18
17
  */
19
- readonly route?: string;
18
+ readonly account?: string;
19
+ }
20
+ /** One immutable-deployment Environment in a Cloudflare dispatch namespace. */
21
+ export interface CloudflareParams {
22
+ readonly namespace: CloudflareNamespace;
20
23
  /** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
21
24
  readonly secrets?: string;
22
- /** Local dev port for `wrangler dev`. Default 8787. */
23
- readonly port?: number;
24
- /**
25
- * Public URL the dev server is reached through (tunnel / sandbox preview /
26
- * reverse proxy), e.g. `'https://my-box.preview.dev'`. Sets BOTH effects an
27
- * off-localhost dev needs: wrangler binds 0.0.0.0 (reachable from outside)
28
- * and `WORKER_URL` is pinned to this URL so the worker's per-request-Host
29
- * identity (`iss`) doesn't drift to the proxy's internal hostname.
30
- * Usually injected by `pnpm dev --host <url>` rather than written here.
31
- */
32
- readonly host?: string;
33
- /** Override the Worker name. Default: derived from the domain origin. */
34
- readonly workerName?: string;
35
- /** Run `wrangler dev --remote` (edge isolate) instead of local workerd. */
36
- readonly remote?: boolean;
37
25
  /** Extra plain (non-secret) vars to inject as Worker vars. */
38
26
  readonly vars?: Record<string, string>;
39
27
  /**
40
- * Escape hatch: raw wrangler config deep-merged over the generated base. Use
41
- * it to declare extra bindings the adapter has no typed field for — KV, R2,
42
- * D1, queues, service bindings, extra `compatibility_flags`, cron `triggers`,
43
- * Hyperdrive, etc.
44
- *
45
- * wrangler: {
46
- * kv_namespaces: [{ binding: 'CACHE', id: '<kv-id>' }],
47
- * r2_buckets: [{ binding: 'FILES', bucket_name: 'my-bucket' }],
48
- * }
49
- *
50
- * The merge is additive: arrays concat (so your `services` keep the adapter's
51
- * `SELF` binding and your `compatibility_flags` keep `nodejs_compat`); new
52
- * keys are added as-is. The adapter-owned keys `name`, `main`, `assets`,
53
- * `routes` are rejected — use `workerName` and `route` instead. Avoid
54
- * the reserved binding names `SELF` and `ASSETS`. Durable Objects need extra
55
- * worker-entry codegen and aren't supported through this field yet.
28
+ * Maximum encoded invocation request bytes retained by the Worker Server.
29
+ * Defaults to 1 MiB and is capped at 16 MiB. Increase only from measured
30
+ * application traffic; Release and Bundle delivery have separate limits. A streamed
31
+ * binary request is not retained: it is capped by the largest `maximumBytes` among
32
+ * the Domain's binary Functions instead.
33
+ */
34
+ readonly maximumRequestBytes?: number;
35
+ /**
36
+ * Maximum wall-clock lifetime of one invocation, including Workflow steps and
37
+ * returned streams. Defaults to 30 seconds. Increase this for intentionally
38
+ * long provider orchestration while retaining a finite application budget. A binary
39
+ * request of a Domain with binary Functions lives up to 30 minutes, or this budget
40
+ * when it is longer.
41
+ */
42
+ readonly invocationTimeoutMs?: number;
43
+ /**
44
+ * Configure the caller-only Domain token exchange lifetime, or disable exchange.
45
+ * The default maximum is 30 minutes; production and CI environments may select a shorter bound.
46
+ */
47
+ readonly tokenExchange?: ExchangeOptions | false;
48
+ /**
49
+ * What a Worker serving durable Workflows declares to the workflow engine, as `serve({ durable })`
50
+ * does: run retention, retry before pausing and the deadline of each Step. Canonical callbacks
51
+ * discover engine keys from their Kernel. The options are frozen into each
52
+ * deployment's configuration (`settings.durableOptions`), so another value is another deployment
53
+ * (AM-175).
54
+ */
55
+ readonly durable?: DurableWorkerOptions;
56
+ /**
57
+ * Extra frozen Worker configuration. Accepts only services, dispatch_namespaces and
58
+ * compatibility_flags; an immutable deployment runs no cron of its own. Bundle-shaping
59
+ * options and the platform namespace are refused.
56
60
  */
57
61
  readonly wrangler?: Record<string, unknown>;
58
62
  /**
59
- * Route subrequests to platform INSTANCE hostnames through a service binding
60
- * instead of the public edge. A Cloudflare Worker can't fetch a same-zone
61
- * hostname served by another Worker — Cloudflare 522s it — so without this the
62
- * worker can't fetch an instance kernel's JWKS to verify an inbound credential
63
- * from that instance, and every cross-instance call (install hooks, the GUI's
64
- * delegated calls, authed views) fails with `2002 Credential verification
65
- * failed`. Point it at a router Worker that reaches those hosts internally
66
- * (Astrale: `admin-router`).
63
+ * Optional private routing through a service binding. By default, subrequests use
64
+ * their public URLs; generated Workers enable `global_fetch_strictly_public` so
65
+ * same-zone Worker calls honor public routes too.
67
66
  *
68
- * Wires BOTH halves the SDK needs: the `<binding>` service binding in the
69
- * generated wrangler config, and a `routeSubrequest` predicate in the worker
70
- * entry that diverts matching hosts through it.
67
+ * Wires both halves the SDK needs: the `ROUTER` service binding in the
68
+ * deployment's wrangler config, and the host suffix and label rule bound in
69
+ * `ASTRALE_SETTINGS`, which the Worker applies to divert matching hosts
70
+ * through that binding.
71
71
  *
72
- * ON BY DEFAULT (targets `admin-router`) so every adapter-deployed worker can
73
- * verify cross-instance credentials out of the box. Pass `false` to disable
74
- * (a domain that never talks to another instance, or an account without a
75
- * router), or an object to override the target / binding name / host match.
72
+ * Opt in only when the selected router owns every hostname matched by the
73
+ * suffix/label predicate. A shared DNS suffix is not proof of router ownership:
74
+ * standalone Domain deployments may share it with managed instances.
76
75
  *
77
- * router: false // opt out
78
- * router: { service: 'my-router' } // override target
76
+ * router: false // explicit public routing (the default)
77
+ * router: { service: 'my-router' } // opt into a private router
79
78
  */
80
79
  readonly router?: false | {
81
80
  /** Router Worker the binding targets. Default `'admin-router'`. */
82
81
  readonly service?: string;
83
- /** Service-binding name the worker reads. Default `'ROUTER'`. */
84
- readonly binding?: string;
85
82
  /** Host suffix that marks an instance host. Default `'.astrale.ai'`. */
86
83
  readonly hostSuffix?: string;
87
84
  /** Min dot-separated label count for an instance host. Default `4` (`<slug>.<region>.astrale.ai`). */
88
85
  readonly minLabels?: number;
89
86
  };
90
87
  }
91
- //# sourceMappingURL=params.d.ts.map
88
+ export type DurableWorkerOptions = Pick<DurableServing, 'retentionMs' | 'retry' | 'stepTimeoutMs'>;
package/dist/params.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=params.js.map
@@ -0,0 +1,35 @@
1
+ import type { BuildManifestV1 } from '@astrale-os/sdk/deployment/build/manifest';
2
+ /**
3
+ * The bundler of every generated Cloudflare Worker, whichever adapter deploys it. Its version names
4
+ * the upload layout below, not a package release: a Services host recomputes the same build digest
5
+ * from the same bytes whatever SDK it runs.
6
+ */
7
+ export declare const CLOUDFLARE_WORKER_BUNDLER: Readonly<{
8
+ id: "cloudflare-worker";
9
+ version: "1";
10
+ }>;
11
+ /** Portable Worker upload: what Services receives, and what a dispatch namespace upload carries. */
12
+ export interface WorkerUpload {
13
+ readonly origin: string;
14
+ readonly revision: BuildManifestV1['schema']['revision'];
15
+ /** Digest of the Domain Schema bundle. */
16
+ readonly bundle: BuildManifestV1['schema']['bundle'];
17
+ readonly entry: string;
18
+ readonly modules: readonly {
19
+ readonly name: string;
20
+ readonly bytes: Uint8Array;
21
+ }[];
22
+ /** Static assets by their absolute Worker asset path (`/index.html`). */
23
+ readonly assets?: readonly {
24
+ readonly path: string;
25
+ readonly bytes: Uint8Array;
26
+ }[];
27
+ }
28
+ /**
29
+ * The one build manifest of a Worker upload, computed on the exact upload the deploy sends; the
30
+ * SDK, Services and namespace mode all identify Worker code through it. Modules keep their uploaded
31
+ * name; a static asset `/<path>` is the file `assets/<path>`.
32
+ */
33
+ export declare function workerBuildManifest(upload: WorkerUpload): BuildManifestV1;
34
+ /** The build-manifest file of one Worker asset path. */
35
+ export declare function workerAssetFile(path: string): string;
@@ -0,0 +1,44 @@
1
+ import { buildManifest } from '@astrale-os/sdk/deployment/build/manifest';
2
+ /**
3
+ * The bundler of every generated Cloudflare Worker, whichever adapter deploys it. Its version names
4
+ * the upload layout below, not a package release: a Services host recomputes the same build digest
5
+ * from the same bytes whatever SDK it runs.
6
+ */
7
+ export const CLOUDFLARE_WORKER_BUNDLER = Object.freeze({
8
+ id: 'cloudflare-worker',
9
+ version: '1',
10
+ });
11
+ /**
12
+ * The one build manifest of a Worker upload, computed on the exact upload the deploy sends; the
13
+ * SDK, Services and namespace mode all identify Worker code through it. Modules keep their uploaded
14
+ * name; a static asset `/<path>` is the file `assets/<path>`.
15
+ */
16
+ export function workerBuildManifest(upload) {
17
+ if (upload === null || typeof upload !== 'object' || !Array.isArray(upload.modules)) {
18
+ throw new TypeError('Worker upload is invalid.');
19
+ }
20
+ if (upload.assets !== undefined && !Array.isArray(upload.assets)) {
21
+ throw new TypeError('Worker upload assets are invalid.');
22
+ }
23
+ return buildManifest({
24
+ origin: upload.origin,
25
+ revision: upload.revision,
26
+ bundle: upload.bundle,
27
+ bundler: CLOUDFLARE_WORKER_BUNDLER,
28
+ entrypoint: upload.entry,
29
+ files: [
30
+ ...upload.modules.map((module) => ({ path: module.name, content: module.bytes })),
31
+ ...(upload.assets ?? []).map((asset) => ({
32
+ path: workerAssetFile(asset.path),
33
+ content: asset.bytes,
34
+ })),
35
+ ],
36
+ });
37
+ }
38
+ /** The build-manifest file of one Worker asset path. */
39
+ export function workerAssetFile(path) {
40
+ if (typeof path !== 'string' || !path.startsWith('/')) {
41
+ throw new TypeError('Worker asset path must be absolute.');
42
+ }
43
+ return `assets${path}`;
44
+ }
@@ -0,0 +1,44 @@
1
+ declare const WORKER_DEPLOYMENT_ID: unique symbol;
2
+ /** Provider-local identity for one immutable staged Cloudflare implementation. */
3
+ export type WorkerDeploymentId = `sha256:${string}` & {
4
+ readonly [WORKER_DEPLOYMENT_ID]: true;
5
+ };
6
+ export interface WorkerDeploymentInput {
7
+ readonly release: {
8
+ readonly entrypoint: string;
9
+ readonly modules: readonly {
10
+ readonly path: string;
11
+ readonly kind: 'esm' | 'wasm' | 'text' | 'data';
12
+ readonly content: Uint8Array;
13
+ }[];
14
+ };
15
+ readonly runtime: {
16
+ readonly compatibilityDate: string;
17
+ readonly compatibilityFlags: readonly string[];
18
+ };
19
+ readonly bindings: {
20
+ readonly vars: Readonly<Record<string, string>>;
21
+ readonly services: readonly {
22
+ readonly name: string;
23
+ readonly service: string;
24
+ }[];
25
+ readonly requiredSecrets: readonly string[];
26
+ };
27
+ readonly assets?: {
28
+ readonly files: readonly {
29
+ readonly path: string;
30
+ readonly content: Uint8Array;
31
+ readonly contentType?: string;
32
+ }[];
33
+ readonly notFound: 'none' | '404-page' | 'single-page-application';
34
+ readonly runWorkerFirst: boolean;
35
+ readonly htmlHandling?: 'none';
36
+ };
37
+ }
38
+ /** Canonical provider material used only for staging, promotion, rollback, and cleanup. */
39
+ export declare function workerDeploymentMaterial(input: WorkerDeploymentInput): Uint8Array;
40
+ /** Identify one immutable Cloudflare implementation without changing SDK or Publication identity. */
41
+ export declare function workerDeployment(input: WorkerDeploymentInput): WorkerDeploymentId;
42
+ /** Admit a serialized provider deployment identity at a Cloudflare boundary. */
43
+ export declare function acceptWorkerDeployment(input: unknown): WorkerDeploymentId;
44
+ export {};
@@ -0,0 +1,141 @@
1
+ import { sha256 } from '@noble/hashes/sha2.js';
2
+ const DEPLOYMENT = /^sha256:[0-9a-f]{64}$/u;
3
+ /** Canonical provider material used only for staging, promotion, rollback, and cleanup. */
4
+ export function workerDeploymentMaterial(input) {
5
+ const release = executable(input.release);
6
+ const compatibilityFlags = uniqueStrings(input.runtime.compatibilityFlags, 'compatibility flag');
7
+ const vars = Object.fromEntries(Object.entries(input.bindings.vars)
8
+ .map(([name, value]) => {
9
+ stable(name, 'Variable binding name');
10
+ if (typeof value !== 'string')
11
+ invalid();
12
+ return [name, value];
13
+ })
14
+ .sort(([left], [right]) => compare(left, right)));
15
+ const services = [...input.bindings.services]
16
+ .map((binding) => ({
17
+ name: stable(binding.name, 'Service binding name'),
18
+ service: stable(binding.service, 'Service binding target'),
19
+ }))
20
+ .sort((left, right) => compare(left.name, right.name));
21
+ unique(services.map((binding) => binding.name), 'Service binding name');
22
+ const requiredSecrets = uniqueStrings(input.bindings.requiredSecrets, 'required secret');
23
+ unique([...Object.keys(vars), ...services.map((binding) => binding.name), ...requiredSecrets], 'Worker binding name');
24
+ const assets = input.assets === undefined ? undefined : canonicalAssets(input.assets);
25
+ return new TextEncoder().encode(`${JSON.stringify({
26
+ format: 'astrale.cloudflare.deployment',
27
+ version: 1,
28
+ release,
29
+ runtime: {
30
+ compatibilityDate: stable(input.runtime.compatibilityDate, 'compatibility date'),
31
+ compatibilityFlags,
32
+ },
33
+ bindings: { vars, services, requiredSecrets },
34
+ ...(assets === undefined ? {} : { assets }),
35
+ })}\n`);
36
+ }
37
+ /** Identify one immutable Cloudflare implementation without changing SDK or Publication identity. */
38
+ export function workerDeployment(input) {
39
+ let hexadecimal = '';
40
+ for (const byte of sha256(workerDeploymentMaterial(input))) {
41
+ hexadecimal += byte.toString(16).padStart(2, '0');
42
+ }
43
+ return `sha256:${hexadecimal}`;
44
+ }
45
+ /** Admit a serialized provider deployment identity at a Cloudflare boundary. */
46
+ export function acceptWorkerDeployment(input) {
47
+ if (typeof input !== 'string' || !DEPLOYMENT.test(input)) {
48
+ throw new TypeError('Cloudflare Worker deployment identity is invalid.');
49
+ }
50
+ return input;
51
+ }
52
+ function executable(input) {
53
+ const entrypoint = stablePath(input.entrypoint, 'Worker release entrypoint');
54
+ const modules = input.modules
55
+ .map((module) => ({
56
+ path: stablePath(module.path, 'Worker release module path'),
57
+ kind: module.kind,
58
+ digest: content(module.content),
59
+ }))
60
+ .sort((left, right) => compare(left.path, right.path));
61
+ unique(modules.map((module) => module.path), 'Worker release module path');
62
+ if (!modules.some((module) => module.path === entrypoint && module.kind === 'esm')) {
63
+ throw new TypeError('Worker release entrypoint must be an ES module in its module set.');
64
+ }
65
+ return { entrypoint, modules };
66
+ }
67
+ function canonicalAssets(input) {
68
+ const files = input.files
69
+ .map((file) => ({
70
+ path: stableAssetPath(file.path),
71
+ digest: content(file.content),
72
+ ...(file.contentType === undefined
73
+ ? {}
74
+ : { contentType: stable(file.contentType, 'Worker asset content type') }),
75
+ }))
76
+ .sort((left, right) => compare(left.path, right.path));
77
+ unique(files.map((file) => file.path), 'Worker asset path');
78
+ if (!['none', '404-page', 'single-page-application'].includes(input.notFound))
79
+ invalid();
80
+ if (input.htmlHandling !== undefined && input.htmlHandling !== 'none')
81
+ invalid();
82
+ return {
83
+ files,
84
+ notFound: input.notFound,
85
+ runWorkerFirst: input.runWorkerFirst,
86
+ htmlHandling: input.htmlHandling ?? 'none',
87
+ };
88
+ }
89
+ function uniqueStrings(input, label) {
90
+ const values = input.map((value) => stable(value, label)).sort(compare);
91
+ unique(values, label);
92
+ return values;
93
+ }
94
+ function unique(values, label) {
95
+ if (new Set(values).size !== values.length) {
96
+ throw new TypeError(`${label} must be unique.`);
97
+ }
98
+ }
99
+ function content(value) {
100
+ if (!(value instanceof Uint8Array))
101
+ invalid();
102
+ let hexadecimal = '';
103
+ for (const byte of sha256(value))
104
+ hexadecimal += byte.toString(16).padStart(2, '0');
105
+ return `sha256:${hexadecimal}`;
106
+ }
107
+ function stablePath(value, label) {
108
+ const admitted = stable(value, label);
109
+ if (admitted.startsWith('/') ||
110
+ admitted.includes('\\') ||
111
+ admitted.split('/').some((part) => part.length === 0 || part === '.' || part === '..')) {
112
+ invalid();
113
+ }
114
+ return admitted;
115
+ }
116
+ function stableAssetPath(value) {
117
+ const admitted = stable(value, 'Worker asset path');
118
+ if (!admitted.startsWith('/') ||
119
+ admitted.includes('\\') ||
120
+ admitted.includes('?') ||
121
+ admitted.includes('#') ||
122
+ admitted
123
+ .slice(1)
124
+ .split('/')
125
+ .some((part) => part.length === 0 || part === '.' || part === '..')) {
126
+ invalid();
127
+ }
128
+ return admitted;
129
+ }
130
+ function stable(value, label) {
131
+ if (typeof value !== 'string' || value.length === 0 || value.trim() !== value) {
132
+ throw new TypeError(`${label} must be stable non-empty text.`);
133
+ }
134
+ return value;
135
+ }
136
+ function compare(left, right) {
137
+ return left < right ? -1 : left > right ? 1 : 0;
138
+ }
139
+ function invalid() {
140
+ throw new TypeError('Cloudflare Worker deployment material is invalid.');
141
+ }
@@ -0,0 +1,2 @@
1
+ export { CLOUDFLARE_WORKER_BUNDLER, workerBuildManifest, type WorkerUpload } from './build.js';
2
+ export { acceptWorkerDeployment, workerDeployment, workerDeploymentMaterial, type WorkerDeploymentId, type WorkerDeploymentInput, } from './deployment.js';
@@ -0,0 +1,2 @@
1
+ export { CLOUDFLARE_WORKER_BUNDLER, workerBuildManifest } from './build.js';
2
+ export { acceptWorkerDeployment, workerDeployment, workerDeploymentMaterial, } from './deployment.js';
@@ -0,0 +1,21 @@
1
+ import type { Build } from '@astrale-os/sdk/deployment/build';
2
+ /**
3
+ * Lifetime of one streamed binary request, upload included: the Kernel's own Server gives a blob
4
+ * upload the same 30 minutes.
5
+ */
6
+ export declare const BINARY_REQUEST_TIMEOUT_MS: number;
7
+ /** Longest wait for the next chunk of a binary body while the Action reads it, as the Kernel's. */
8
+ export declare const BINARY_REQUEST_IDLE_TIMEOUT_MS = 60000;
9
+ /** The Kernel Server limits a Worker serves binary requests under. */
10
+ export interface BinaryRequestLimits {
11
+ readonly maximumBinaryRequestBytes: number;
12
+ readonly binaryRequestTimeoutMs: number;
13
+ readonly binaryRequestIdleTimeoutMs: number;
14
+ }
15
+ /**
16
+ * The streamed binary request budget of one Build: the largest `maximumBytes` among the binary
17
+ * Functions its Domain declares, so the deployment admits every body one of them accepts and
18
+ * admission still holds each Function to its own. A Build without a binary Function keeps the
19
+ * Kernel Server defaults: `maximumRequestBytes` and `invocationTimeoutMs`.
20
+ */
21
+ export declare function binaryRequestLimits(build: Pick<Build, 'schema'>, invocationTimeoutMs: number): BinaryRequestLimits | undefined;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Lifetime of one streamed binary request, upload included: the Kernel's own Server gives a blob
3
+ * upload the same 30 minutes.
4
+ */
5
+ export const BINARY_REQUEST_TIMEOUT_MS = 30 * 60_000;
6
+ /** Longest wait for the next chunk of a binary body while the Action reads it, as the Kernel's. */
7
+ export const BINARY_REQUEST_IDLE_TIMEOUT_MS = 60_000;
8
+ /**
9
+ * The streamed binary request budget of one Build: the largest `maximumBytes` among the binary
10
+ * Functions its Domain declares, so the deployment admits every body one of them accepts and
11
+ * admission still holds each Function to its own. A Build without a binary Function keeps the
12
+ * Kernel Server defaults: `maximumRequestBytes` and `invocationTimeoutMs`.
13
+ */
14
+ export function binaryRequestLimits(build, invocationTimeoutMs) {
15
+ const compiled = build.schema.compiled;
16
+ const root = compiled.closure.find(({ origin }) => origin === compiled.root.origin);
17
+ let maximumBytes;
18
+ for (const definition of root?.definitions.functions ?? []) {
19
+ if (typeof definition.input === 'number')
20
+ continue;
21
+ maximumBytes = Math.max(maximumBytes ?? 0, definition.input.maximumBytes);
22
+ }
23
+ if (maximumBytes === undefined)
24
+ return undefined;
25
+ return Object.freeze({
26
+ maximumBinaryRequestBytes: maximumBytes,
27
+ // A deployment that already grants every invocation longer keeps that budget for uploads.
28
+ binaryRequestTimeoutMs: Math.max(invocationTimeoutMs, BINARY_REQUEST_TIMEOUT_MS),
29
+ binaryRequestIdleTimeoutMs: BINARY_REQUEST_IDLE_TIMEOUT_MS,
30
+ });
31
+ }
@@ -0,0 +1,10 @@
1
+ import type { BuildDigest } from '@astrale-os/sdk/deployment/build/manifest';
2
+ import type { CloudflareAdapterBindings } from './front.js';
3
+ /**
4
+ * Plain binding an immutable-deployment host (Services, the platform namespace) binds at the
5
+ * create-only upload: the build digest it recomputed from the uploaded bytes. No stable Worker
6
+ * receives it, and no author var or secret may take its name.
7
+ */
8
+ export declare const BUILD_DIGEST_BINDING = "ASTRALE_BUILD_DIGEST";
9
+ /** The exact host-bound build digest this immutable deployment serves. */
10
+ export declare function deploymentBuildDigest(bindings: CloudflareAdapterBindings): BuildDigest;