@astrale-os/adapter-cloudflare 0.5.0-beta.6 → 0.5.0-beta.61

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 (171) hide show
  1. package/README.md +25 -0
  2. package/dist/adapter.d.ts +17 -0
  3. package/dist/adapter.js +177 -0
  4. package/dist/build/artifact.d.ts +7 -0
  5. package/dist/build/artifact.js +163 -0
  6. package/dist/build/bundle/admit.d.ts +1 -0
  7. package/dist/build/bundle/admit.js +9 -0
  8. package/dist/build/closure.d.ts +2 -0
  9. package/dist/build/closure.js +22 -0
  10. package/dist/build/codegen/execution.d.ts +3 -0
  11. package/dist/build/codegen/execution.js +2 -0
  12. package/dist/build/codegen/merge.d.ts +0 -1
  13. package/dist/build/codegen/merge.js +0 -1
  14. package/dist/build/codegen/wrangler.d.ts +13 -1
  15. package/dist/build/codegen/wrangler.js +32 -17
  16. package/dist/build/configuration/addressing.d.ts +2 -0
  17. package/dist/build/configuration/addressing.js +11 -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 +11 -0
  22. package/dist/build/configuration/worker-name.d.ts +2 -0
  23. package/dist/build/configuration/worker-name.js +18 -0
  24. package/dist/build/configuration.d.ts +4 -0
  25. package/dist/build/configuration.js +4 -0
  26. package/dist/build/direct.d.ts +4 -0
  27. package/dist/build/direct.js +93 -0
  28. package/dist/build/frontend/routes.d.ts +2 -0
  29. package/dist/build/frontend/routes.js +11 -0
  30. package/dist/build/frontend-v1.d.ts +16 -0
  31. package/dist/build/frontend-v1.js +133 -0
  32. package/dist/build/index.d.ts +10 -16
  33. package/dist/build/index.js +9 -16
  34. package/dist/build/materialize.d.ts +4 -0
  35. package/dist/build/materialize.js +10 -0
  36. package/dist/build/metafile.d.ts +5 -0
  37. package/dist/build/metafile.js +14 -0
  38. package/dist/build/parse-output.d.ts +0 -1
  39. package/dist/build/parse-output.js +0 -1
  40. package/dist/build/qualification.d.ts +5 -0
  41. package/dist/build/qualification.js +7 -0
  42. package/dist/build/roots.d.ts +2 -0
  43. package/dist/build/roots.js +34 -0
  44. package/dist/build/worker/artifact.d.ts +40 -0
  45. package/dist/build/worker/artifact.js +1 -0
  46. package/dist/build/worker/artifact.load.d.ts +3 -0
  47. package/dist/build/worker/artifact.load.js +308 -0
  48. package/dist/build/worker/artifact.manifest.d.ts +48 -0
  49. package/dist/build/worker/artifact.manifest.js +87 -0
  50. package/dist/build/worker/artifact.paths.d.ts +4 -0
  51. package/dist/build/worker/artifact.paths.js +25 -0
  52. package/dist/build/worker/codegen/entry.d.ts +2 -0
  53. package/dist/build/worker/codegen/entry.js +28 -0
  54. package/dist/build/worker/codegen/service.d.ts +15 -0
  55. package/dist/build/worker/codegen/service.js +51 -0
  56. package/dist/build/worker/execution.prepare.d.ts +18 -0
  57. package/dist/build/worker/execution.prepare.js +107 -0
  58. package/dist/build/worker/index.d.ts +2 -0
  59. package/dist/build/worker/index.js +1 -0
  60. package/dist/build/worker/modules.d.ts +11 -0
  61. package/dist/build/worker/modules.js +26 -0
  62. package/dist/build/worker/runtime.d.ts +10 -0
  63. package/dist/build/worker/runtime.js +35 -0
  64. package/dist/build/worker/specifier.d.ts +1 -0
  65. package/dist/build/worker/specifier.js +5 -0
  66. package/dist/build/wrangler/bundle.d.ts +10 -0
  67. package/dist/build/wrangler/bundle.js +29 -0
  68. package/dist/build/wrangler/deploy.d.ts +24 -0
  69. package/dist/build/wrangler/deploy.js +44 -0
  70. package/dist/build/wrangler/development.d.ts +17 -0
  71. package/dist/build/wrangler/development.js +136 -0
  72. package/dist/build/wrangler/process.d.ts +17 -0
  73. package/dist/build/wrangler/process.js +115 -0
  74. package/dist/build/wrangler/secrets.d.ts +6 -0
  75. package/dist/build/wrangler/secrets.js +58 -0
  76. package/dist/build/wrangler/status.d.ts +14 -0
  77. package/dist/build/wrangler/status.js +56 -0
  78. package/dist/build/wrangler/type-generation.d.ts +6 -0
  79. package/dist/build/wrangler/type-generation.js +19 -0
  80. package/dist/build/wrangler-cli.d.ts +6 -86
  81. package/dist/build/wrangler-cli.js +6 -275
  82. package/dist/cloudflare.d.ts +1 -34
  83. package/dist/cloudflare.js +1 -205
  84. package/dist/deploy/deploy.d.ts +15 -0
  85. package/dist/deploy/deploy.js +204 -0
  86. package/dist/deploy/index.d.ts +1 -0
  87. package/dist/deploy/index.js +1 -0
  88. package/dist/identity/binding.d.ts +2 -0
  89. package/dist/identity/binding.js +2 -0
  90. package/dist/identity/material.d.ts +7 -0
  91. package/dist/identity/material.js +42 -0
  92. package/dist/identity/secret.d.ts +3 -0
  93. package/dist/identity/secret.js +7 -0
  94. package/dist/identity/source.d.ts +26 -0
  95. package/dist/identity/source.js +98 -0
  96. package/dist/index.d.ts +3 -4
  97. package/dist/index.js +3 -4
  98. package/dist/params.d.ts +24 -5
  99. package/dist/params.js +0 -1
  100. package/dist/release/deployment.d.ts +44 -0
  101. package/dist/release/deployment.js +141 -0
  102. package/dist/release/index.d.ts +2 -0
  103. package/dist/release/index.js +2 -0
  104. package/dist/release/staged-worker-name.d.ts +3 -0
  105. package/dist/release/staged-worker-name.js +10 -0
  106. package/dist/worker/entry.d.ts +43 -0
  107. package/dist/worker/entry.js +181 -0
  108. package/dist/worker/fetch.d.ts +0 -1
  109. package/dist/worker/fetch.js +0 -1
  110. package/dist/worker/identity.d.ts +7 -0
  111. package/dist/worker/identity.js +23 -0
  112. package/dist/worker/index.d.ts +2 -59
  113. package/dist/worker/index.js +2 -216
  114. package/package.json +30 -19
  115. package/template/astrale.config.ts +19 -11
  116. package/dist/build/codegen/identity.d.ts +0 -10
  117. package/dist/build/codegen/identity.d.ts.map +0 -1
  118. package/dist/build/codegen/identity.js +0 -32
  119. package/dist/build/codegen/identity.js.map +0 -1
  120. package/dist/build/codegen/merge.d.ts.map +0 -1
  121. package/dist/build/codegen/merge.js.map +0 -1
  122. package/dist/build/codegen/worker.d.ts +0 -12
  123. package/dist/build/codegen/worker.d.ts.map +0 -1
  124. package/dist/build/codegen/worker.js +0 -40
  125. package/dist/build/codegen/worker.js.map +0 -1
  126. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  127. package/dist/build/codegen/wrangler.js.map +0 -1
  128. package/dist/build/frontend.d.ts +0 -26
  129. package/dist/build/frontend.d.ts.map +0 -1
  130. package/dist/build/frontend.js +0 -263
  131. package/dist/build/frontend.js.map +0 -1
  132. package/dist/build/index.d.ts.map +0 -1
  133. package/dist/build/index.js.map +0 -1
  134. package/dist/build/parse-output.d.ts.map +0 -1
  135. package/dist/build/parse-output.js.map +0 -1
  136. package/dist/build/prepare.d.ts +0 -18
  137. package/dist/build/prepare.d.ts.map +0 -1
  138. package/dist/build/prepare.js +0 -117
  139. package/dist/build/prepare.js.map +0 -1
  140. package/dist/build/worker.d.ts +0 -15
  141. package/dist/build/worker.d.ts.map +0 -1
  142. package/dist/build/worker.js +0 -21
  143. package/dist/build/worker.js.map +0 -1
  144. package/dist/build/wrangler-cli.d.ts.map +0 -1
  145. package/dist/build/wrangler-cli.js.map +0 -1
  146. package/dist/cloudflare.d.ts.map +0 -1
  147. package/dist/cloudflare.js.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/index.js.map +0 -1
  150. package/dist/params.d.ts.map +0 -1
  151. package/dist/params.js.map +0 -1
  152. package/dist/worker/fetch.d.ts.map +0 -1
  153. package/dist/worker/fetch.js.map +0 -1
  154. package/dist/worker/index.d.ts.map +0 -1
  155. package/dist/worker/index.js.map +0 -1
  156. package/src/build/codegen/identity.ts +0 -40
  157. package/src/build/codegen/merge.ts +0 -92
  158. package/src/build/codegen/worker.ts +0 -53
  159. package/src/build/codegen/wrangler.ts +0 -127
  160. package/src/build/frontend.ts +0 -324
  161. package/src/build/index.ts +0 -29
  162. package/src/build/parse-output.ts +0 -60
  163. package/src/build/prepare.ts +0 -161
  164. package/src/build/worker.ts +0 -37
  165. package/src/build/wrangler-cli.ts +0 -362
  166. package/src/cloudflare.ts +0 -251
  167. package/src/index.ts +0 -21
  168. package/src/params.ts +0 -92
  169. package/src/worker/fetch.ts +0 -46
  170. package/src/worker/index.ts +0 -327
  171. package/src/worker/tsconfig.json +0 -10
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # `@astrale-os/adapter-cloudflare`
2
+
3
+ Cloudflare Worker deployment adapter for Astrale Domains.
4
+
5
+ During the SDK beta program, install the beta package set explicitly:
6
+
7
+ ```bash
8
+ npm install @astrale-os/sdk@beta @astrale-os/adapter-cloudflare@beta
9
+ ```
10
+
11
+ Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
12
+
13
+ ## Provider-local staging
14
+
15
+ Managed Cloudflare providers may stage immutable implementation candidates without exposing their
16
+ identity to Publications or installed Kernels:
17
+
18
+ ```ts
19
+ import { stagedWorkerName } from '@astrale-os/adapter-cloudflare/release'
20
+ ```
21
+
22
+ This subpath is runtime-safe. `stagedWorkerName(providerDeployment)` addresses one private staged
23
+ candidate. The public Worker name and `/invoke` endpoint remain stable across compatible
24
+ implementation and Schema updates. Provider staging identity never enters Release, Publication,
25
+ Kernel routing, or graph identity.
@@ -0,0 +1,17 @@
1
+ import type { Release } from '@astrale-os/sdk/deployment/release';
2
+ import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
3
+ import type { CloudflareParams } from './params.js';
4
+ import { artifact } from './build/artifact.js';
5
+ import { startFrontend } from './build/frontend-v1.js';
6
+ import { runWranglerDev } from './build/wrangler-cli.js';
7
+ import { type CloudflareDeployDependencies } from './deploy/index.js';
8
+ import { signingIdentity } from './identity/source.js';
9
+ export interface CloudflareDependencies extends CloudflareDeployDependencies {
10
+ readonly artifact: typeof artifact;
11
+ readonly runWranglerDev: typeof runWranglerDev;
12
+ readonly startFrontend: typeof startFrontend;
13
+ readonly signingIdentity: typeof signingIdentity;
14
+ }
15
+ export declare function cloudflare(environments: Readonly<Record<string, CloudflareParams>>): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
16
+ export declare function cloudflareWithDependencies(environments: Readonly<Record<string, CloudflareParams>>, dependencies: CloudflareDependencies): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
17
+ export declare function waitForReadiness(verify: typeof verifyReadiness, release: Release, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,177 @@
1
+ import { defineAdapter } from '@astrale-os/sdk/deployment/adapter';
2
+ import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { createRequire } from 'node:module';
5
+ import { join } from 'node:path';
6
+ import { artifact, materialize } from './build/artifact.js';
7
+ import { generateWranglerConfig } from './build/codegen/wrangler.js';
8
+ import { resolveRouter, workerName } from './build/configuration.js';
9
+ import { startFrontend } from './build/frontend-v1.js';
10
+ import { loadWorkerArtifact } from './build/worker/index.js';
11
+ import { workerModules } from './build/worker/modules.js';
12
+ import { runWranglerDeploymentStatus, runWranglerDeploy, runWranglerDev, } from './build/wrangler-cli.js';
13
+ import { deployCloudflare } from './deploy/index.js';
14
+ import { signingIdentitySecrets } from './identity/secret.js';
15
+ import { signingIdentity } from './identity/source.js';
16
+ const packageVersion = createRequire(import.meta.url)('../package.json')
17
+ .version;
18
+ export function cloudflare(environments) {
19
+ return cloudflareWithDependencies(environments, {
20
+ artifact,
21
+ materialize,
22
+ runWranglerDeploy,
23
+ runWranglerDeploymentStatus,
24
+ runWranglerDev,
25
+ startFrontend,
26
+ signingIdentity,
27
+ waitForReadiness: (release, signal) => waitForReadiness(verifyReadiness, release, signal),
28
+ });
29
+ }
30
+ export function cloudflareWithDependencies(environments, dependencies) {
31
+ return defineAdapter({
32
+ name: 'cloudflare',
33
+ version: packageVersion,
34
+ environments,
35
+ prepare: dependencies.artifact,
36
+ async watch(parameters, context) {
37
+ const workerArtifact = loadWorkerArtifact(context.artifact);
38
+ const identity = await dependencies.signingIdentity({
39
+ projectDir: context.projectDir,
40
+ source: parameters.signingIdentity,
41
+ origin: context.artifact.build.schema.compiled.root.origin,
42
+ mode: 'local',
43
+ });
44
+ const secrets = signingIdentitySecrets(context.secrets, identity);
45
+ const directory = join(context.projectDir, '.astrale', 'runtime');
46
+ await dependencies.materialize(directory, context.artifact.files);
47
+ const frontend = await dependencies.startFrontend({
48
+ frontend: context.artifact.build.frontend,
49
+ projectDir: context.projectDir,
50
+ });
51
+ const name = workerName(parameters, context.artifact.build.schema.compiled.root.origin);
52
+ // A local workerd cannot reach the default deployed router Worker through a service
53
+ // binding. Keep it for remote isolates and explicit multi-Worker development; ordinary
54
+ // local execution falls back to the admitted fetch path when ROUTER is absent.
55
+ const router = parameters.remote === true || parameters.router !== undefined
56
+ ? resolveRouter(parameters.router)
57
+ : undefined;
58
+ const configPath = join(directory, 'wrangler.watch.jsonc');
59
+ await writeFile(configPath, generateWranglerConfig({
60
+ workerName: name,
61
+ main: `./${workerArtifact.release.entrypoint}`,
62
+ modules: workerModules(workerArtifact.release),
63
+ vars: {
64
+ ...parameters.vars,
65
+ ...(parameters.host === undefined ? {} : { WORKER_URL: parameters.host }),
66
+ ...(frontend === undefined ? {} : { FRONTEND_DEV_URL: frontend.url }),
67
+ },
68
+ secretBindings: Object.keys(secrets).sort(),
69
+ ...(context.artifact.build.frontend?.source.kind === 'vite'
70
+ ? {
71
+ frontend: {
72
+ directory: './frontend',
73
+ routes: frontendRoutes(context.artifact),
74
+ dev: true,
75
+ },
76
+ }
77
+ : {}),
78
+ ...(router === undefined
79
+ ? {}
80
+ : { router: { binding: router.binding, service: router.service } }),
81
+ ...(parameters.wrangler === undefined ? {} : { wrangler: parameters.wrangler }),
82
+ selfBinding: true,
83
+ }));
84
+ let worker;
85
+ try {
86
+ worker = await dependencies.runWranglerDev({
87
+ projectDir: context.projectDir,
88
+ configPath,
89
+ port: parameters.port ?? 8787,
90
+ remote: parameters.remote ?? false,
91
+ secrets,
92
+ autoPickPort: parameters.port === undefined,
93
+ pinLocalOrigin: parameters.host === undefined && parameters.remote !== true,
94
+ ...(parameters.host === undefined ? {} : { ip: '0.0.0.0' }),
95
+ onReload: context.onReload,
96
+ });
97
+ }
98
+ catch (cause) {
99
+ await frontend?.stop().catch(() => undefined);
100
+ throw cause;
101
+ }
102
+ return Object.freeze({
103
+ url: parameters.host ?? worker.url,
104
+ localUrl: worker.url,
105
+ async stop() {
106
+ const results = await Promise.allSettled([
107
+ worker.stop(),
108
+ frontend?.stop() ?? Promise.resolve(),
109
+ ]);
110
+ const failures = results.filter((result) => result.status === 'rejected');
111
+ if (failures.length === 1)
112
+ throw failures[0].reason;
113
+ if (failures.length > 1) {
114
+ throw new AggregateError(failures.map((failure) => failure.reason), 'Cloudflare development cleanup failed.');
115
+ }
116
+ },
117
+ });
118
+ },
119
+ deploy: (parameters, context) => deployCloudflare(parameters, context, dependencies),
120
+ secretsFile: (parameters) => parameters.secrets,
121
+ });
122
+ }
123
+ function frontendRoutes(artifact) {
124
+ const frontend = artifact.build.frontend;
125
+ if (frontend === undefined || frontend.source.kind !== 'vite')
126
+ return [];
127
+ return Object.freeze(frontend.routes
128
+ .flatMap((route) => frontend.source.kind === 'vite' && frontend.source.spa && route.path !== '/'
129
+ ? [route.path, `${route.path}/*`]
130
+ : route.path === '/'
131
+ ? ['/*']
132
+ : [route.path])
133
+ .sort());
134
+ }
135
+ export async function waitForReadiness(verify, release, signal) {
136
+ const deadline = Date.now() + 90_000;
137
+ let last;
138
+ while (Date.now() < deadline) {
139
+ throwIfAborted(signal);
140
+ try {
141
+ await verify(release, {
142
+ signal: signal === undefined
143
+ ? AbortSignal.timeout(5_000)
144
+ : AbortSignal.any([signal, AbortSignal.timeout(5_000)]),
145
+ });
146
+ return;
147
+ }
148
+ catch (cause) {
149
+ throwIfAborted(signal);
150
+ last = cause;
151
+ await pause(signal);
152
+ }
153
+ }
154
+ throw last instanceof Error ? last : new Error('Cloudflare Release did not become ready.');
155
+ }
156
+ function pause(signal) {
157
+ return new Promise((resolve, reject) => {
158
+ const timer = setTimeout(done, 1_000);
159
+ const abort = () => done(abortError(signal));
160
+ signal?.addEventListener('abort', abort, { once: true });
161
+ function done(cause) {
162
+ clearTimeout(timer);
163
+ signal?.removeEventListener('abort', abort);
164
+ if (cause === undefined)
165
+ resolve();
166
+ else
167
+ reject(cause);
168
+ }
169
+ });
170
+ }
171
+ function throwIfAborted(signal) {
172
+ if (signal?.aborted)
173
+ throw abortError(signal);
174
+ }
175
+ function abortError(signal) {
176
+ return signal?.reason instanceof Error ? signal.reason : new Error('Deployment interrupted.');
177
+ }
@@ -0,0 +1,7 @@
1
+ import type { ArtifactSource, PrepareContext } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { CloudflareParams } from '../params.js';
3
+ export { materialize } from './materialize.js';
4
+ /** Prepare one portable Worker whose public provider address remains stable across builds. */
5
+ export declare function artifact(params: CloudflareParams, context: PrepareContext): Promise<ArtifactSource>;
6
+ /** Prepare the complete portable Cloudflare Worker without direct Wrangler placement files. */
7
+ export declare function prepareWorkerArtifact(params: CloudflareParams, context: PrepareContext): Promise<ArtifactSource>;
@@ -0,0 +1,163 @@
1
+ import { addressing } from '@astrale-os/sdk/deployment/release';
2
+ import { mkdir, mkdtemp, rm } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { SIGNING_IDENTITY_BINDING } from '../identity/binding.js';
5
+ import { workerDeployment } from '../release/index.js';
6
+ import { generateWranglerConfig } from './codegen/wrangler.js';
7
+ import { deploymentAddressing, resolveRouter, workerName } from './configuration.js';
8
+ import { frontendFiles } from './frontend-v1.js';
9
+ import { frontendRoutes } from './frontend/routes.js';
10
+ import { encodeWorkerArtifactManifest, inferMediaType, workerContentDigest, WORKER_MANIFEST_PATH, } from './worker/artifact.manifest.js';
11
+ import { prepareExecution, RELEASE_ENTRY, RELEASE_SERVICE, runtimeVars, } from './worker/execution.prepare.js';
12
+ import { admitWorkerRuntimeConfiguration } from './worker/runtime.js';
13
+ export { materialize } from './materialize.js';
14
+ const encoder = new TextEncoder();
15
+ /** Prepare one portable Worker whose public provider address remains stable across builds. */
16
+ export async function artifact(params, context) {
17
+ return prepare(params, context, true);
18
+ }
19
+ /** Prepare the complete portable Cloudflare Worker without direct Wrangler placement files. */
20
+ export async function prepareWorkerArtifact(params, context) {
21
+ return prepare(params, context, false);
22
+ }
23
+ async function prepare(params, context, direct) {
24
+ const stateDirectory = join(context.projectDir, '.astrale');
25
+ await mkdir(stateDirectory, { recursive: true });
26
+ const directory = await mkdtemp(join(stateDirectory, 'prepare-'));
27
+ try {
28
+ const router = resolveRouter(params.router);
29
+ const name = workerName(params, context.build.schema.compiled.root.origin);
30
+ const revision = context.build.schema.compiled.root.revision;
31
+ const configuredIssuer = deploymentAddressing(params);
32
+ const modules = await prepareExecution({
33
+ params,
34
+ context,
35
+ directory,
36
+ name,
37
+ direct,
38
+ configuredIssuer,
39
+ router,
40
+ });
41
+ const frontend = await frontendFiles({
42
+ frontend: context.build.frontend,
43
+ projectDir: context.projectDir,
44
+ });
45
+ const releaseConfig = generateWranglerConfig({
46
+ workerName: name,
47
+ main: `./${RELEASE_ENTRY}`,
48
+ ...(params.route === undefined ? {} : { route: params.route }),
49
+ vars: runtimeVars(params, configuredIssuer),
50
+ secretBindings: [SIGNING_IDENTITY_BINDING],
51
+ modules: { baseDir: './bundle', rules: [{ type: 'ESModule', globs: ['service.mjs'] }] },
52
+ ...(context.build.frontend?.source.kind === 'vite'
53
+ ? {
54
+ frontend: {
55
+ directory: './frontend',
56
+ routes: frontendRoutes(context.build.frontend),
57
+ dev: false,
58
+ },
59
+ }
60
+ : {}),
61
+ ...(router === undefined
62
+ ? {}
63
+ : { router: { binding: router.binding, service: router.service } }),
64
+ ...(params.wrangler === undefined ? {} : { wrangler: params.wrangler }),
65
+ selfBinding: false,
66
+ });
67
+ const runtime = admitWorkerRuntimeConfiguration(releaseConfig);
68
+ const deployment = workerDeployment({
69
+ release: {
70
+ entrypoint: RELEASE_ENTRY,
71
+ modules: [
72
+ { path: RELEASE_ENTRY, kind: 'esm', content: modules.entry },
73
+ { path: RELEASE_SERVICE, kind: 'esm', content: modules.service },
74
+ ],
75
+ },
76
+ runtime,
77
+ bindings: {
78
+ vars: runtime.vars,
79
+ services: runtime.services,
80
+ requiredSecrets: [SIGNING_IDENTITY_BINDING],
81
+ },
82
+ ...(frontend.length === 0
83
+ ? {}
84
+ : {
85
+ assets: {
86
+ files: frontend.map((file) => {
87
+ const contentType = file.mediaType ?? inferMediaType(file.path);
88
+ return {
89
+ path: `/${file.path}`,
90
+ content: file.bytes(),
91
+ ...(contentType === undefined ? {} : { contentType }),
92
+ };
93
+ }),
94
+ notFound: 'none',
95
+ runWorkerFirst: true,
96
+ htmlHandling: 'none',
97
+ },
98
+ }),
99
+ });
100
+ const manifest = encodeWorkerArtifactManifest({
101
+ origin: context.build.schema.compiled.root.origin,
102
+ revision,
103
+ deployment,
104
+ release: {
105
+ entrypoint: RELEASE_ENTRY,
106
+ modules: [
107
+ { path: RELEASE_ENTRY, kind: 'esm', digest: workerContentDigest(modules.entry) },
108
+ { path: RELEASE_SERVICE, kind: 'esm', digest: workerContentDigest(modules.service) },
109
+ ],
110
+ },
111
+ runtime: {
112
+ compatibilityDate: runtime.compatibilityDate,
113
+ compatibilityFlags: runtime.compatibilityFlags,
114
+ },
115
+ bindings: {
116
+ vars: runtime.vars,
117
+ services: runtime.services,
118
+ requiredSecrets: [SIGNING_IDENTITY_BINDING],
119
+ },
120
+ ...(frontend.length === 0
121
+ ? {}
122
+ : {
123
+ assets: {
124
+ files: frontend.map((file) => {
125
+ const contentType = file.mediaType ?? inferMediaType(file.path);
126
+ return {
127
+ path: `/${file.path}`,
128
+ artifactPath: `frontend/${file.path}`,
129
+ digest: workerContentDigest(file.bytes()),
130
+ ...(contentType === undefined ? {} : { contentType }),
131
+ };
132
+ }),
133
+ notFound: 'none',
134
+ runWorkerFirst: true,
135
+ htmlHandling: 'none',
136
+ },
137
+ }),
138
+ });
139
+ const files = [
140
+ { path: RELEASE_ENTRY, content: modules.entry },
141
+ { path: RELEASE_SERVICE, content: modules.service },
142
+ { path: WORKER_MANIFEST_PATH, content: manifest },
143
+ ...frontend.map((file) => ({
144
+ path: `frontend/${file.path}`,
145
+ content: file.bytes(),
146
+ })),
147
+ ...(direct ? [{ path: 'wrangler.jsonc', content: encoder.encode(releaseConfig) }] : []),
148
+ ];
149
+ return Object.freeze({
150
+ entrypoint: RELEASE_ENTRY,
151
+ files: Object.freeze(files),
152
+ addressing: configuredIssuer === undefined
153
+ ? Object.freeze({ kind: 'provider-assigned', claim: name })
154
+ : Object.freeze({
155
+ kind: 'configured',
156
+ addressing: addressing(configuredIssuer),
157
+ }),
158
+ });
159
+ }
160
+ finally {
161
+ await rm(directory, { recursive: true, force: true });
162
+ }
163
+ }
@@ -0,0 +1 @@
1
+ export declare function admitWorkerBundle(path: string): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ export async function admitWorkerBundle(path) {
3
+ const loaded = (await import(`${pathToFileURL(path).href}?admit=${Date.now()}`));
4
+ if (loaded.default === null ||
5
+ typeof loaded.default !== 'object' ||
6
+ typeof Reflect.get(loaded.default, 'fetch') !== 'function') {
7
+ throw new TypeError('Generated Worker bundle does not export a Fetch handler.');
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ /** Prove emitted Worker reachability excludes authoring, compilation, and broad Core Schema owners. */
2
+ export declare function assertRuntimeClosure(metafilePath: string): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { readWranglerMetafile } from './metafile.js';
2
+ const FORBIDDEN_RUNTIME_INPUTS = [
3
+ '/v1/builder/',
4
+ '/v1/compiled/compiler/',
5
+ '/node_modules/ajv/',
6
+ '/node_modules/re2js/',
7
+ '/kernel-core/domain/',
8
+ '/core/domain/',
9
+ '/kernel-core/schema/index.',
10
+ '/core/schema/index.',
11
+ ];
12
+ /** Prove emitted Worker reachability excludes authoring, compilation, and broad Core Schema owners. */
13
+ export async function assertRuntimeClosure(metafilePath) {
14
+ const metafile = await readWranglerMetafile(metafilePath);
15
+ const forbidden = Object.keys(metafile.inputs).filter((input) => {
16
+ const normalized = `/${input.replaceAll('\\', '/')}`.replace(/(\/node_modules\/@astrale-os\/kernel-[^/]+)\/dist\//gu, '$1/');
17
+ return FORBIDDEN_RUNTIME_INPUTS.some((fragment) => normalized.includes(fragment));
18
+ });
19
+ if (forbidden.length > 0) {
20
+ throw new Error(`Cloudflare Worker reaches build-side modules: ${forbidden.sort().join(', ')}.`);
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ export { generateExecutionEntry } from '../worker/codegen/entry.js';
2
+ export { generateExecutionService } from '../worker/codegen/service.js';
3
+ export type { ExecutionCodegenOptions } from '../worker/codegen/service.js';
@@ -0,0 +1,2 @@
1
+ export { generateExecutionEntry } from '../worker/codegen/entry.js';
2
+ export { generateExecutionService } from '../worker/codegen/service.js';
@@ -17,4 +17,3 @@
17
17
  * the caller (`generateWranglerConfig`), not here — this stays a generic merge.
18
18
  */
19
19
  export declare function deepMergeConfig(base: Record<string, unknown>, overlay: Record<string, unknown>): Record<string, unknown>;
20
- //# sourceMappingURL=merge.d.ts.map
@@ -88,4 +88,3 @@ function isPlainObject(v) {
88
88
  function isPrimitive(v) {
89
89
  return v === null || (typeof v !== 'object' && typeof v !== 'function');
90
90
  }
91
- //# sourceMappingURL=merge.js.map
@@ -13,15 +13,28 @@
13
13
  */
14
14
  export interface WranglerCodegenOptions {
15
15
  workerName: string;
16
+ /** Provider-ready entrypoint relative to the generated config. */
17
+ main?: string;
16
18
  /** Full custom hostname for a routed deploy (e.g. 'crm.acme.dev'). */
17
19
  route?: string;
18
20
  /** Exact materialized local frontend; absence means no ASSETS binding. */
19
21
  frontend?: {
20
22
  readonly directory: string;
21
23
  readonly routes: readonly string[];
24
+ readonly dev: boolean;
22
25
  };
23
26
  /** Plain (non-secret) vars to bake in. */
24
27
  vars?: Record<string, string>;
28
+ /** Secret binding names required by generated Worker code. */
29
+ secretBindings?: readonly string[];
30
+ /** Modules retained outside the startup entry and loaded on demand. */
31
+ modules?: {
32
+ readonly baseDir: string;
33
+ readonly rules: readonly {
34
+ readonly type: 'ESModule' | 'CompiledWasm' | 'Text' | 'Data';
35
+ readonly globs: readonly string[];
36
+ }[];
37
+ };
25
38
  /** Add the SELF service binding (autobinding). */
26
39
  selfBinding: boolean;
27
40
  /**
@@ -43,4 +56,3 @@ export interface WranglerCodegenOptions {
43
56
  wrangler?: Record<string, unknown>;
44
57
  }
45
58
  export declare function generateWranglerConfig(opts: WranglerCodegenOptions): string;
46
- //# sourceMappingURL=wrangler.d.ts.map
@@ -12,15 +12,15 @@
12
12
  * (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
13
13
  */
14
14
  import { deepMergeConfig } from './merge.js';
15
- // Wrangler 4.121.0's pinned workerd accepts dates through 2026-08-11.
15
+ // Keep the generated date on the runtime baseline qualified with Wrangler 4.123.0.
16
16
  const COMPATIBILITY_DATE = '2026-08-11';
17
17
  export function generateWranglerConfig(opts) {
18
18
  const config = {
19
19
  name: opts.workerName,
20
- main: './worker.gen.ts',
20
+ main: opts.main ?? './worker.gen.ts',
21
21
  compatibility_date: COMPATIBILITY_DATE,
22
22
  compatibility_flags: ['nodejs_compat'],
23
- workers_dev: true,
23
+ workers_dev: opts.route === undefined,
24
24
  version_metadata: { binding: 'ASTRALE_VERSION_METADATA' },
25
25
  observability: { enabled: true },
26
26
  };
@@ -31,19 +31,19 @@ export function generateWranglerConfig(opts) {
31
31
  config.assets = {
32
32
  directory: opts.frontend.directory,
33
33
  binding: 'ASSETS',
34
- run_worker_first: [
35
- '/invoke',
36
- '/invoke/*',
37
- '/install',
38
- '/install/*',
39
- '/health',
40
- '/health/*',
41
- '/meta',
42
- '/meta/*',
43
- '/.well-known',
44
- '/.well-known/*',
45
- ...opts.frontend.routes,
46
- ],
34
+ html_handling: 'none',
35
+ run_worker_first: opts.frontend.dev
36
+ ? true
37
+ : [
38
+ '/invoke',
39
+ '/install',
40
+ '/install/*',
41
+ '/health',
42
+ '/health/*',
43
+ '/.well-known',
44
+ '/.well-known/*',
45
+ ...opts.frontend.routes,
46
+ ],
47
47
  };
48
48
  }
49
49
  const services = [];
@@ -57,6 +57,18 @@ export function generateWranglerConfig(opts) {
57
57
  if (opts.vars && Object.keys(opts.vars).length > 0) {
58
58
  config.vars = opts.vars;
59
59
  }
60
+ if (opts.secretBindings && opts.secretBindings.length > 0) {
61
+ config.secrets = { required: [...opts.secretBindings] };
62
+ }
63
+ if (opts.modules !== undefined) {
64
+ config.find_additional_modules = true;
65
+ config.base_dir = opts.modules.baseDir;
66
+ config.rules = opts.modules.rules.map((rule) => ({
67
+ type: rule.type,
68
+ globs: [...rule.globs],
69
+ fallthrough: true,
70
+ }));
71
+ }
60
72
  const merged = opts.wrangler ? mergeUserConfig(config, opts.wrangler) : config;
61
73
  return JSON.stringify(merged, null, 2) + '\n';
62
74
  }
@@ -67,7 +79,11 @@ const ADAPTER_OWNED_KEYS = [
67
79
  'assets',
68
80
  'routes',
69
81
  'compatibility_date',
82
+ 'workers_dev',
70
83
  'version_metadata',
84
+ 'secrets',
85
+ 'find_additional_modules',
86
+ 'base_dir',
71
87
  ];
72
88
  /**
73
89
  * Deep-merge the dev's raw wrangler overlay over the generated config, after
@@ -83,4 +99,3 @@ function mergeUserConfig(base, user) {
83
99
  }
84
100
  return deepMergeConfig(base, user);
85
101
  }
86
- //# sourceMappingURL=wrangler.js.map
@@ -0,0 +1,2 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function deploymentAddressing(parameters: CloudflareParams): string | undefined;
@@ -0,0 +1,11 @@
1
+ import { addressing } from '@astrale-os/sdk/deployment/release';
2
+ export function deploymentAddressing(parameters) {
3
+ const routed = parameters.route === undefined ? undefined : addressing(`https://${parameters.route}`).issuer;
4
+ if (parameters.addressing === undefined)
5
+ return routed;
6
+ const configured = addressing(parameters.addressing).issuer;
7
+ if (routed !== undefined && configured !== routed) {
8
+ throw new TypeError('Cloudflare route and addressing identify different origins.');
9
+ }
10
+ return configured;
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function workerRequestLimit(value: CloudflareParams['maximumRequestBytes']): number | undefined;
@@ -0,0 +1,9 @@
1
+ const MAXIMUM_REQUEST_BYTES = 16 * 1024 * 1024;
2
+ export function workerRequestLimit(value) {
3
+ if (value === undefined)
4
+ return undefined;
5
+ if (!Number.isSafeInteger(value) || value <= 0 || value > MAXIMUM_REQUEST_BYTES) {
6
+ throw new TypeError('Cloudflare maximumRequestBytes must be a positive integer at most 16 MiB.');
7
+ }
8
+ return value;
9
+ }
@@ -0,0 +1,7 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function resolveRouter(input: CloudflareParams['router']): {
3
+ readonly binding: string;
4
+ readonly service: string;
5
+ readonly hostSuffix: string;
6
+ readonly minLabels: number;
7
+ } | undefined;
@@ -0,0 +1,11 @@
1
+ export function resolveRouter(input) {
2
+ if (input === false)
3
+ return undefined;
4
+ const value = input ?? {};
5
+ return Object.freeze({
6
+ binding: value.binding ?? 'ROUTER',
7
+ service: value.service ?? 'admin-router',
8
+ hostSuffix: value.hostSuffix ?? '.astrale.ai',
9
+ minLabels: value.minLabels ?? 4,
10
+ });
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { CloudflareParams } from '../../params.js';
2
+ export declare function workerName(parameters: CloudflareParams, origin: string): string;
@@ -0,0 +1,18 @@
1
+ import { createHash } from 'node:crypto';
2
+ const WORKER_NAME = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u;
3
+ export function workerName(parameters, origin) {
4
+ if (parameters.workerName !== undefined) {
5
+ if (!WORKER_NAME.test(parameters.workerName) || parameters.workerName.length > 63) {
6
+ throw new TypeError('Cloudflare workerName is invalid.');
7
+ }
8
+ return parameters.workerName;
9
+ }
10
+ const readable = origin
11
+ .toLowerCase()
12
+ .replace(/[^a-z0-9]+/gu, '-')
13
+ .slice(0, 12)
14
+ .replace(/^-+|-+$/gu, '') || 'domain';
15
+ const hexadecimal = createHash('sha256').update(origin).digest('hex');
16
+ const identity = BigInt(`0x${hexadecimal}`).toString(36).padStart(50, '0');
17
+ return `${readable}-${identity}`;
18
+ }