@astrale-os/adapter-cloudflare 0.4.10 → 0.5.0-beta.100

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 (214) hide show
  1. package/CHANGELOG.md +1193 -0
  2. package/README.md +29 -0
  3. package/dist/adapter.d.ts +15 -0
  4. package/dist/adapter.js +76 -0
  5. package/dist/build/artifact.d.ts +7 -0
  6. package/dist/build/artifact.js +165 -0
  7. package/dist/build/bundle/admit.d.ts +1 -0
  8. package/dist/build/bundle/admit.js +9 -0
  9. package/dist/build/closure.d.ts +2 -0
  10. package/dist/build/closure.js +22 -0
  11. package/dist/build/codegen/execution.d.ts +3 -0
  12. package/dist/build/codegen/execution.js +2 -0
  13. package/dist/{codegen → build/codegen}/merge.d.ts +0 -1
  14. package/dist/{codegen → build/codegen}/merge.js +0 -1
  15. package/dist/{codegen → build/codegen}/wrangler.d.ts +19 -4
  16. package/dist/{codegen → build/codegen}/wrangler.js +49 -13
  17. package/dist/build/configuration/addressing.d.ts +2 -0
  18. package/dist/build/configuration/addressing.js +11 -0
  19. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  20. package/dist/build/configuration/invocation-timeout.js +9 -0
  21. package/dist/build/configuration/request-limit.d.ts +2 -0
  22. package/dist/build/configuration/request-limit.js +9 -0
  23. package/dist/build/configuration/router.d.ts +7 -0
  24. package/dist/build/configuration/router.js +11 -0
  25. package/dist/build/configuration/worker-name.d.ts +2 -0
  26. package/dist/build/configuration/worker-name.js +18 -0
  27. package/dist/build/configuration.d.ts +5 -0
  28. package/dist/build/configuration.js +5 -0
  29. package/dist/build/direct.d.ts +4 -0
  30. package/dist/build/direct.js +93 -0
  31. package/dist/build/frontend/files.d.ts +7 -0
  32. package/dist/build/frontend/files.js +60 -0
  33. package/dist/build/frontend/routes.d.ts +2 -0
  34. package/dist/build/frontend/routes.js +11 -0
  35. package/dist/build/index.d.ts +8 -0
  36. package/dist/build/index.js +7 -0
  37. package/dist/build/materialize.d.ts +4 -0
  38. package/dist/build/materialize.js +10 -0
  39. package/dist/build/metafile.d.ts +5 -0
  40. package/dist/build/metafile.js +14 -0
  41. package/dist/build/qualification.d.ts +5 -0
  42. package/dist/build/qualification.js +7 -0
  43. package/dist/build/roots.d.ts +2 -0
  44. package/dist/build/roots.js +34 -0
  45. package/dist/build/worker/artifact.d.ts +40 -0
  46. package/dist/build/worker/artifact.js +1 -0
  47. package/dist/build/worker/artifact.load.d.ts +3 -0
  48. package/dist/build/worker/artifact.load.js +308 -0
  49. package/dist/build/worker/artifact.manifest.d.ts +48 -0
  50. package/dist/build/worker/artifact.manifest.js +87 -0
  51. package/dist/build/worker/artifact.paths.d.ts +4 -0
  52. package/dist/build/worker/artifact.paths.js +25 -0
  53. package/dist/build/worker/codegen/entry.d.ts +2 -0
  54. package/dist/build/worker/codegen/entry.js +28 -0
  55. package/dist/build/worker/codegen/service.d.ts +18 -0
  56. package/dist/build/worker/codegen/service.js +53 -0
  57. package/dist/build/worker/execution.prepare.d.ts +18 -0
  58. package/dist/build/worker/execution.prepare.js +112 -0
  59. package/dist/build/worker/index.d.ts +2 -0
  60. package/dist/build/worker/index.js +1 -0
  61. package/dist/build/worker/modules.d.ts +11 -0
  62. package/dist/build/worker/modules.js +26 -0
  63. package/dist/build/worker/runtime.d.ts +10 -0
  64. package/dist/build/worker/runtime.js +35 -0
  65. package/dist/build/worker/specifier.d.ts +1 -0
  66. package/dist/build/worker/specifier.js +5 -0
  67. package/dist/cloudflare.d.ts +1 -37
  68. package/dist/cloudflare.js +1 -271
  69. package/dist/deploy/deploy.d.ts +16 -0
  70. package/dist/deploy/deploy.js +204 -0
  71. package/dist/deploy/index.d.ts +1 -0
  72. package/dist/deploy/index.js +1 -0
  73. package/dist/deploy/output.d.ts +2 -0
  74. package/dist/deploy/output.js +10 -0
  75. package/dist/development/develop.d.ts +15 -0
  76. package/dist/development/develop.js +270 -0
  77. package/dist/development/frontend.d.ts +11 -0
  78. package/dist/development/frontend.js +109 -0
  79. package/dist/development/host.d.ts +2 -0
  80. package/dist/development/host.js +46 -0
  81. package/dist/development/port.d.ts +1 -0
  82. package/dist/development/port.js +12 -0
  83. package/dist/development/readiness.d.ts +14 -0
  84. package/dist/development/readiness.js +71 -0
  85. package/dist/development/resolved-fetch.d.ts +17 -0
  86. package/dist/development/resolved-fetch.js +80 -0
  87. package/dist/development/worker-output.d.ts +2 -0
  88. package/dist/development/worker-output.js +25 -0
  89. package/dist/development/worker.d.ts +17 -0
  90. package/dist/development/worker.js +147 -0
  91. package/dist/identity/binding.d.ts +2 -0
  92. package/dist/identity/binding.js +2 -0
  93. package/dist/identity/index.d.ts +3 -0
  94. package/dist/identity/index.js +3 -0
  95. package/dist/identity/material.d.ts +7 -0
  96. package/dist/identity/material.js +42 -0
  97. package/dist/identity/secret.d.ts +3 -0
  98. package/dist/identity/secret.js +7 -0
  99. package/dist/identity/source.d.ts +26 -0
  100. package/dist/identity/source.js +127 -0
  101. package/dist/index.d.ts +8 -8
  102. package/dist/index.js +7 -7
  103. package/dist/params.d.ts +50 -23
  104. package/dist/params.js +0 -1
  105. package/dist/release/deployment.d.ts +44 -0
  106. package/dist/release/deployment.js +141 -0
  107. package/dist/release/index.d.ts +2 -0
  108. package/dist/release/index.js +2 -0
  109. package/dist/release/staged-worker-name.d.ts +3 -0
  110. package/dist/release/staged-worker-name.js +10 -0
  111. package/dist/worker/entry.d.ts +44 -0
  112. package/dist/worker/entry.js +184 -0
  113. package/dist/worker/fetch.d.ts +11 -0
  114. package/dist/worker/fetch.js +31 -0
  115. package/dist/worker/identity.d.ts +7 -0
  116. package/dist/worker/identity.js +23 -0
  117. package/dist/worker/index.d.ts +2 -0
  118. package/dist/worker/index.js +2 -0
  119. package/dist/wrangler/bundle.d.ts +10 -0
  120. package/dist/wrangler/bundle.js +27 -0
  121. package/dist/wrangler/deploy.d.ts +24 -0
  122. package/dist/wrangler/deploy.js +44 -0
  123. package/dist/wrangler/index.d.ts +5 -0
  124. package/dist/wrangler/index.js +5 -0
  125. package/dist/wrangler/process.d.ts +17 -0
  126. package/dist/wrangler/process.js +115 -0
  127. package/dist/wrangler/secrets.d.ts +6 -0
  128. package/dist/wrangler/secrets.js +58 -0
  129. package/dist/wrangler/status.d.ts +14 -0
  130. package/dist/wrangler/status.js +56 -0
  131. package/dist/wrangler/type-generation.d.ts +6 -0
  132. package/dist/wrangler/type-generation.js +19 -0
  133. package/package.json +41 -18
  134. package/template/astrale.config.ts +26 -18
  135. package/dist/assets-pack.d.ts +0 -8
  136. package/dist/assets-pack.d.ts.map +0 -1
  137. package/dist/assets-pack.js +0 -30
  138. package/dist/assets-pack.js.map +0 -1
  139. package/dist/build.d.ts +0 -16
  140. package/dist/build.d.ts.map +0 -1
  141. package/dist/build.js +0 -15
  142. package/dist/build.js.map +0 -1
  143. package/dist/client.d.ts +0 -17
  144. package/dist/client.d.ts.map +0 -1
  145. package/dist/client.js +0 -59
  146. package/dist/client.js.map +0 -1
  147. package/dist/cloudflare.d.ts.map +0 -1
  148. package/dist/cloudflare.js.map +0 -1
  149. package/dist/codegen/identity.d.ts +0 -10
  150. package/dist/codegen/identity.d.ts.map +0 -1
  151. package/dist/codegen/identity.js +0 -32
  152. package/dist/codegen/identity.js.map +0 -1
  153. package/dist/codegen/merge.d.ts.map +0 -1
  154. package/dist/codegen/merge.js.map +0 -1
  155. package/dist/codegen/worker.d.ts +0 -51
  156. package/dist/codegen/worker.d.ts.map +0 -1
  157. package/dist/codegen/worker.js +0 -120
  158. package/dist/codegen/worker.js.map +0 -1
  159. package/dist/codegen/wrangler.d.ts.map +0 -1
  160. package/dist/codegen/wrangler.js.map +0 -1
  161. package/dist/index.d.ts.map +0 -1
  162. package/dist/index.js.map +0 -1
  163. package/dist/params.d.ts.map +0 -1
  164. package/dist/params.js.map +0 -1
  165. package/dist/parse-output.d.ts +0 -25
  166. package/dist/parse-output.d.ts.map +0 -1
  167. package/dist/parse-output.js +0 -53
  168. package/dist/parse-output.js.map +0 -1
  169. package/dist/wrangler-cli.d.ts +0 -78
  170. package/dist/wrangler-cli.d.ts.map +0 -1
  171. package/dist/wrangler-cli.js +0 -251
  172. package/dist/wrangler-cli.js.map +0 -1
  173. package/src/assets-pack.ts +0 -32
  174. package/src/build.ts +0 -16
  175. package/src/client.ts +0 -89
  176. package/src/cloudflare.ts +0 -321
  177. package/src/codegen/identity.ts +0 -40
  178. package/src/codegen/merge.ts +0 -92
  179. package/src/codegen/worker.ts +0 -136
  180. package/src/codegen/wrangler.ts +0 -105
  181. package/src/index.ts +0 -21
  182. package/src/params.ts +0 -96
  183. package/src/parse-output.ts +0 -54
  184. package/src/wrangler-cli.ts +0 -324
  185. package/template/.env.example +0 -9
  186. package/template/.gitignore.template +0 -16
  187. package/template/CLAUDE.md +0 -13
  188. package/template/README.md +0 -47
  189. package/template/client/.gitignore.template +0 -4
  190. package/template/client/__tests__/app.test.tsx +0 -15
  191. package/template/client/components.json +0 -25
  192. package/template/client/index.html +0 -12
  193. package/template/client/package.json +0 -35
  194. package/template/client/src/app.tsx +0 -52
  195. package/template/client/src/components/ui/cn.ts +0 -6
  196. package/template/client/src/main.tsx +0 -9
  197. package/template/client/src/styles.css +0 -78
  198. package/template/client/tsconfig.json +0 -26
  199. package/template/client/vite.config.ts +0 -22
  200. package/template/client/vitest.config.ts +0 -13
  201. package/template/core/README.md +0 -7
  202. package/template/deps.ts +0 -9
  203. package/template/domain.ts +0 -11
  204. package/template/env.ts +0 -8
  205. package/template/icons.ts +0 -4
  206. package/template/integrations/README.md +0 -7
  207. package/template/oxlint.config.ts +0 -1
  208. package/template/package.json +0 -58
  209. package/template/pnpm-workspace.yaml +0 -31
  210. package/template/runtime/index.ts +0 -8
  211. package/template/schema/index.ts +0 -10
  212. package/template/simulation/README.md +0 -12
  213. package/template/tsconfig.json +0 -28
  214. package/template/vitest.config.ts +0 -7
@@ -0,0 +1,17 @@
1
+ export interface WorkerHandle {
2
+ readonly url: string;
3
+ readonly finished: Promise<void>;
4
+ stop(): Promise<void>;
5
+ }
6
+ export declare function startWorker(args: {
7
+ projectDir: string;
8
+ configPath: string;
9
+ port: number;
10
+ remote: boolean;
11
+ readonly ip?: string;
12
+ readonly autoPickPort?: boolean;
13
+ /** Pin ordinary local requests to one stable issuer after the final port is selected. */
14
+ readonly pinLocalOrigin?: boolean;
15
+ readonly secrets: Readonly<Record<string, string>>;
16
+ readonly onLog?: (line: string) => void;
17
+ }): Promise<WorkerHandle>;
@@ -0,0 +1,147 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { createServer } from 'node:net';
3
+ import { stopChild, wranglerCommand, wranglerProcessEnv } from '../wrangler/process.js';
4
+ import { createSecretEnvironment, secretRedactor } from '../wrangler/secrets.js';
5
+ import { runWranglerTypes } from '../wrangler/type-generation.js';
6
+ import { parseWorkerReadyUrl } from './worker-output.js';
7
+ export async function startWorker(args) {
8
+ await runWranglerTypes(args);
9
+ const { cmd, prefix } = wranglerCommand(args.projectDir);
10
+ const bindHost = args.ip ?? '127.0.0.1';
11
+ if (args.autoPickPort && !(await portFree(args.port, bindHost))) {
12
+ const picked = await ephemeralPort(bindHost);
13
+ args.onLog?.(`port ${args.port} is taken — using ${picked} instead (pass --port to pin one)`);
14
+ args = { ...args, port: picked };
15
+ }
16
+ const secretEnvironment = await createSecretEnvironment(args.secrets);
17
+ const redact = secretRedactor(args.secrets);
18
+ const fallbackUrl = `http://localhost:${args.port}`;
19
+ const wranglerArgs = [
20
+ ...prefix,
21
+ 'dev',
22
+ '--config',
23
+ args.configPath,
24
+ '--port',
25
+ String(args.port),
26
+ '--local-protocol',
27
+ 'http',
28
+ '--ip',
29
+ args.ip ?? '127.0.0.1',
30
+ ...(args.pinLocalOrigin ? ['--var', `WORKER_URL:${fallbackUrl}`] : []),
31
+ ...(secretEnvironment === undefined ? [] : ['--env-file', secretEnvironment.path]),
32
+ ...(args.remote ? ['--remote'] : []),
33
+ ];
34
+ let child;
35
+ try {
36
+ child = spawn(cmd, wranglerArgs, {
37
+ cwd: args.projectDir,
38
+ stdio: ['ignore', 'pipe', 'pipe'],
39
+ env: wranglerProcessEnv(args.projectDir),
40
+ });
41
+ }
42
+ catch (cause) {
43
+ await secretEnvironment?.remove();
44
+ throw cause;
45
+ }
46
+ let resolved = false;
47
+ let buildErrorTail = '';
48
+ let outputTail = '';
49
+ let url;
50
+ try {
51
+ url = await new Promise((resolve, reject) => {
52
+ const onData = (buf) => {
53
+ const text = redact(buf.toString());
54
+ outputTail = (outputTail + text).slice(-3000);
55
+ for (const line of text.split('\n')) {
56
+ if (line.trim())
57
+ args.onLog?.(line);
58
+ }
59
+ if (/✘ \[ERROR\]|Build failed|Could not resolve "/.test(text)) {
60
+ buildErrorTail = (buildErrorTail + text).slice(-2000);
61
+ }
62
+ if (!resolved) {
63
+ const ready = parseWorkerReadyUrl(text, args.port);
64
+ if (ready) {
65
+ resolved = true;
66
+ resolve(ready);
67
+ }
68
+ }
69
+ };
70
+ child.stdout?.on('data', onData);
71
+ child.stderr?.on('data', onData);
72
+ child.on('exit', (code) => {
73
+ if (!resolved) {
74
+ resolved = true;
75
+ reject(new Error(`wrangler dev exited before becoming ready (code ${code ?? 'null'}).\n${outputTail}`));
76
+ }
77
+ });
78
+ child.on('error', (error) => {
79
+ if (!resolved) {
80
+ resolved = true;
81
+ reject(error);
82
+ }
83
+ });
84
+ setTimeout(() => {
85
+ if (!resolved && child.exitCode === null) {
86
+ resolved = true;
87
+ if (buildErrorTail) {
88
+ reject(new Error(`worker build failed — the dev server would hang silently.\n${buildErrorTail}`));
89
+ }
90
+ else {
91
+ reject(new Error(`wrangler dev did not report local readiness at ${fallbackUrl}.\n${outputTail}`));
92
+ }
93
+ }
94
+ }, 15_000).unref?.();
95
+ });
96
+ }
97
+ catch (cause) {
98
+ await stopChild(child);
99
+ await secretEnvironment?.remove();
100
+ throw cause;
101
+ }
102
+ let stopping = false;
103
+ const finished = new Promise((resolve, reject) => {
104
+ child.once('exit', (code, signal) => {
105
+ if (stopping)
106
+ resolve();
107
+ else {
108
+ reject(new Error(`wrangler dev stopped unexpectedly (code ${code ?? 'null'}, signal ${signal ?? 'none'}).\n${outputTail}`));
109
+ }
110
+ });
111
+ child.once('error', reject);
112
+ });
113
+ return Object.freeze({
114
+ url: args.pinLocalOrigin ? fallbackUrl : url,
115
+ finished,
116
+ async stop() {
117
+ if (stopping)
118
+ return finished;
119
+ stopping = true;
120
+ try {
121
+ await stopChild(child);
122
+ }
123
+ finally {
124
+ await secretEnvironment?.remove();
125
+ }
126
+ },
127
+ });
128
+ }
129
+ function portFree(port, host) {
130
+ return new Promise((resolve) => {
131
+ const server = createServer();
132
+ server.once('error', () => resolve(false));
133
+ server.once('listening', () => server.close(() => resolve(true)));
134
+ server.listen(port, host);
135
+ });
136
+ }
137
+ function ephemeralPort(host) {
138
+ return new Promise((resolve, reject) => {
139
+ const server = createServer();
140
+ server.once('error', reject);
141
+ server.listen(0, host, () => {
142
+ const address = server.address();
143
+ const port = typeof address === 'object' && address ? address.port : 0;
144
+ server.close(() => resolve(port));
145
+ });
146
+ });
147
+ }
@@ -0,0 +1,2 @@
1
+ /** Adapter-owned Worker secret that carries the Domain signing private JWK. */
2
+ export declare const SIGNING_IDENTITY_BINDING = "ASTRALE_SIGNING_IDENTITY";
@@ -0,0 +1,2 @@
1
+ /** Adapter-owned Worker secret that carries the Domain signing private JWK. */
2
+ export const SIGNING_IDENTITY_BINDING = 'ASTRALE_SIGNING_IDENTITY';
@@ -0,0 +1,3 @@
1
+ /** Dependency-light custody surface for Cloudflare Domain signing identities. */
2
+ export { signingIdentity } from './source.js';
3
+ export { signingIdentitySecrets } from './secret.js';
@@ -0,0 +1,3 @@
1
+ /** Dependency-light custody surface for Cloudflare Domain signing identities. */
2
+ export { signingIdentity } from './source.js';
3
+ export { signingIdentitySecrets } from './secret.js';
@@ -0,0 +1,7 @@
1
+ import type { JsonWebKey } from '@astrale-os/sdk/auth';
2
+ export type SigningIdentityMaterial = JsonWebKey & {
3
+ readonly kid: string;
4
+ };
5
+ export declare function createSigningIdentity(): Promise<SigningIdentityMaterial>;
6
+ /** Admit private Ed25519 material and its collision-resistant public identity. */
7
+ export declare function admitSigningIdentity(input: unknown, owner: string, legacyKeyId?: string): Promise<SigningIdentityMaterial>;
@@ -0,0 +1,42 @@
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
+ }
11
+ /** Admit private Ed25519 material and its collision-resistant public identity. */
12
+ export async function admitSigningIdentity(input, owner, legacyKeyId) {
13
+ if (input === null || typeof input !== 'object' || Array.isArray(input))
14
+ invalid(owner);
15
+ const value = input;
16
+ if (value.kty !== 'OKP' ||
17
+ value.crv !== 'Ed25519' ||
18
+ value.alg !== 'EdDSA' ||
19
+ typeof value.x !== 'string' ||
20
+ value.x.length === 0 ||
21
+ typeof value.d !== 'string' ||
22
+ value.d.length === 0) {
23
+ invalid(owner);
24
+ }
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) {
30
+ throw new TypeError(`Cloudflare signing identity '${owner}' must use its JWK thumbprint as kid.`);
31
+ }
32
+ try {
33
+ await importJWK(admitted, 'EdDSA');
34
+ }
35
+ catch (cause) {
36
+ throw invalid(owner, cause);
37
+ }
38
+ return admitted;
39
+ }
40
+ function invalid(owner, cause) {
41
+ throw new TypeError(`Cloudflare signing identity '${owner}' is not a private Ed25519 JWK.`, cause === undefined ? undefined : { cause });
42
+ }
@@ -0,0 +1,3 @@
1
+ import type { SigningIdentitySource } from './source.js';
2
+ /** Add the adapter-owned identity without allowing a second secret authority. */
3
+ export declare function signingIdentitySecrets(secrets: Readonly<Record<string, string>>, identity: SigningIdentitySource): Readonly<Record<string, string>>;
@@ -0,0 +1,7 @@
1
+ /** Add the adapter-owned identity without allowing a second secret authority. */
2
+ export function signingIdentitySecrets(secrets, identity) {
3
+ if (Object.hasOwn(secrets, identity.binding)) {
4
+ throw new TypeError(`${identity.binding} is adapter-owned; configure 'signingIdentity' instead of declaring that secret.`);
5
+ }
6
+ return Object.freeze({ ...secrets, [identity.binding]: identity.secret });
7
+ }
@@ -0,0 +1,26 @@
1
+ import { SIGNING_IDENTITY_BINDING } from './binding.js';
2
+ export interface SigningIdentitySource {
3
+ readonly binding: typeof SIGNING_IDENTITY_BINDING;
4
+ readonly path: string;
5
+ readonly secret: string;
6
+ readonly keyId: string;
7
+ }
8
+ export interface SigningIdentityInput {
9
+ readonly projectDir: string;
10
+ readonly origin: string;
11
+ readonly source?: string;
12
+ readonly mode: 'local' | 'deploy';
13
+ }
14
+ /** Resolve one admitted Domain signing identity for local or remote provider custody. */
15
+ export declare function signingIdentity(input: SigningIdentityInput): Promise<SigningIdentitySource>;
16
+ /**
17
+ * Read an explicitly retained deployment identity. Deployment never generates
18
+ * one: a missing file is a pre-provider configuration failure, not an implicit
19
+ * key rotation.
20
+ */
21
+ export declare function readSigningIdentity(projectDir: string, declaration: string | undefined): Promise<SigningIdentitySource>;
22
+ /**
23
+ * Resolve local development identity. The default is generated once inside
24
+ * `.astrale`; an explicit source is always read-only and must already exist.
25
+ */
26
+ export declare function localSigningIdentity(projectDir: string, declaration: string | undefined, origin: string): Promise<SigningIdentitySource>;
@@ -0,0 +1,127 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { existsSync } from 'node:fs';
3
+ import { link, mkdir, open, readFile, unlink } from 'node:fs/promises';
4
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
5
+ import { SIGNING_IDENTITY_BINDING } from './binding.js';
6
+ import { admitSigningIdentity, createSigningIdentity } from './material.js';
7
+ const DEFAULT_IDENTITY = join('.astrale', 'identity.json');
8
+ /** Resolve one admitted Domain signing identity for local or remote provider custody. */
9
+ export function signingIdentity(input) {
10
+ return input.mode === 'local'
11
+ ? localSigningIdentity(input.projectDir, input.source, input.origin)
12
+ : readSigningIdentity(input.projectDir, input.source);
13
+ }
14
+ /**
15
+ * Read an explicitly retained deployment identity. Deployment never generates
16
+ * one: a missing file is a pre-provider configuration failure, not an implicit
17
+ * key rotation.
18
+ */
19
+ export async function readSigningIdentity(projectDir, declaration) {
20
+ if (declaration === undefined || declaration.length === 0) {
21
+ throw new TypeError("Cloudflare deployment requires 'signingIdentity: <private-jwk-file>'. " +
22
+ 'Run local development once to create .astrale/identity.json, then retain that file in managed secret storage.');
23
+ }
24
+ return readSource(pathOf(projectDir, declaration), declaration);
25
+ }
26
+ /**
27
+ * Resolve local development identity. The default is generated once inside
28
+ * `.astrale`; an explicit source is always read-only and must already exist.
29
+ */
30
+ export async function localSigningIdentity(projectDir, declaration, origin) {
31
+ if (declaration !== undefined)
32
+ return readSource(pathOf(projectDir, declaration), declaration);
33
+ const path = join(projectDir, DEFAULT_IDENTITY);
34
+ if (!existsSync(path)) {
35
+ const legacy = join(projectDir, '.astrale', 'identity.ts');
36
+ if (existsSync(legacy))
37
+ await migrateLegacyIdentity(legacy, path, origin);
38
+ else
39
+ await generateIdentity(path);
40
+ }
41
+ return readSource(path, DEFAULT_IDENTITY);
42
+ }
43
+ async function generateIdentity(path) {
44
+ const value = await createSigningIdentity();
45
+ if (await installIdentity(path, value)) {
46
+ process.stderr.write(`\x1b[33m!\x1b[0m new signing identity generated at .astrale/identity.json (kid ${value.kid}).\n` +
47
+ ` Retain it in managed secret storage before deploying; remote deploy fails closed without an explicit identity file.\n`);
48
+ }
49
+ }
50
+ async function migrateLegacyIdentity(legacy, destination, origin) {
51
+ const source = await readFile(legacy, 'utf8');
52
+ const match = /export const PRIVATE_JWK = (\{[\s\S]*\}) as const\n?$/u.exec(source);
53
+ if (match?.[1] === undefined)
54
+ throw invalidIdentity(legacy);
55
+ let decoded;
56
+ try {
57
+ decoded = JSON.parse(match[1]);
58
+ }
59
+ catch (cause) {
60
+ throw invalidIdentity(legacy, cause);
61
+ }
62
+ const value = await admitSigningIdentity(decoded, legacy, `${origin}-key`);
63
+ if (await installIdentity(destination, value)) {
64
+ process.stderr.write(`\x1b[33m!\x1b[0m migrated .astrale/identity.ts to secret-backed .astrale/identity.json (kid ${value.kid}).\n`);
65
+ }
66
+ }
67
+ /** Publish a complete owner-only identity once; concurrent environments reuse the winner. */
68
+ async function installIdentity(path, value) {
69
+ await mkdir(dirname(path), { recursive: true });
70
+ const staging = `${path}.${process.pid}.${randomUUID()}.next`;
71
+ const file = await open(staging, 'wx', 0o600);
72
+ try {
73
+ await file.writeFile(`${JSON.stringify(value, null, 2)}\n`, 'utf8');
74
+ await file.sync();
75
+ }
76
+ catch (cause) {
77
+ await file.close();
78
+ await unlink(staging).catch(() => undefined);
79
+ throw cause;
80
+ }
81
+ await file.close();
82
+ try {
83
+ await link(staging, path);
84
+ return true;
85
+ }
86
+ catch (cause) {
87
+ if (!(cause instanceof Error && 'code' in cause && cause.code === 'EEXIST'))
88
+ throw cause;
89
+ return false;
90
+ }
91
+ finally {
92
+ await unlink(staging).catch(() => undefined);
93
+ }
94
+ }
95
+ async function readSource(path, declaration) {
96
+ let source;
97
+ try {
98
+ source = await readFile(path, 'utf8');
99
+ }
100
+ catch (cause) {
101
+ if (!(cause instanceof Error && 'code' in cause && cause.code === 'ENOENT'))
102
+ throw cause;
103
+ throw new TypeError(`Cloudflare signing identity '${declaration}' is missing at ${path}.`, {
104
+ cause,
105
+ });
106
+ }
107
+ let decoded;
108
+ try {
109
+ decoded = JSON.parse(source);
110
+ }
111
+ catch (cause) {
112
+ throw invalidIdentity(declaration, cause);
113
+ }
114
+ const value = await admitSigningIdentity(decoded, declaration);
115
+ return Object.freeze({
116
+ binding: SIGNING_IDENTITY_BINDING,
117
+ path,
118
+ secret: JSON.stringify(value),
119
+ keyId: value.kid,
120
+ });
121
+ }
122
+ function pathOf(projectDir, declaration) {
123
+ return isAbsolute(declaration) ? declaration : resolve(projectDir, declaration);
124
+ }
125
+ function invalidIdentity(owner, cause) {
126
+ return new TypeError(`Cloudflare signing identity '${owner}' is not a private Ed25519 JWK.`, cause === undefined ? undefined : { cause });
127
+ }
package/dist/index.d.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale domain as a standalone
3
- * Cloudflare Worker on YOUR OWN Cloudflare account.
2
+ * `@astrale-os/adapter-cloudflare` — deploy an Astrale application through
3
+ * Cloudflare Workers on YOUR OWN Cloudflare account.
4
4
  *
5
5
  * import { cloudflare } from '@astrale-os/adapter-cloudflare'
6
6
  *
7
7
  * adapter: cloudflare({
8
- * dev: { client: { dir: 'client' }, secrets: '.env.dev' },
9
- * prod: { client: { dir: 'client' }, route: 'crm.acme.dev', secrets: '.env.prod' },
8
+ * dev: { secrets: '.env.dev' },
9
+ * prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
10
10
  * })
11
11
  *
12
- * `dev` runs `wrangler dev` locally; an env with no `route` ships to
12
+ * `dev` runs the Worker and optional Vite frontend on allocated local ports;
13
+ * an env with no `route` ships to
13
14
  * `*.workers.dev`; an env with a `route` ships to that custom domain.
14
15
  *
15
16
  * Prefer a managed deploy (no Cloudflare account)? Use
16
17
  * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
17
18
  * `/build` toolkit and ships it through the Astrale platform.
18
19
  */
19
- export { cloudflare } from './cloudflare';
20
- export type { CloudflareParams } from './params';
21
- //# sourceMappingURL=index.d.ts.map
20
+ export { cloudflare } from './cloudflare.js';
21
+ export type { CloudflareParams } from './params.js';
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
1
  /**
2
- * `@astrale-os/adapter-cloudflare` — deploy an Astrale domain as a standalone
3
- * Cloudflare Worker on YOUR OWN Cloudflare account.
2
+ * `@astrale-os/adapter-cloudflare` — deploy an Astrale application through
3
+ * Cloudflare Workers on YOUR OWN Cloudflare account.
4
4
  *
5
5
  * import { cloudflare } from '@astrale-os/adapter-cloudflare'
6
6
  *
7
7
  * adapter: cloudflare({
8
- * dev: { client: { dir: 'client' }, secrets: '.env.dev' },
9
- * prod: { client: { dir: 'client' }, route: 'crm.acme.dev', secrets: '.env.prod' },
8
+ * dev: { secrets: '.env.dev' },
9
+ * prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
10
10
  * })
11
11
  *
12
- * `dev` runs `wrangler dev` locally; an env with no `route` ships to
12
+ * `dev` runs the Worker and optional Vite frontend on allocated local ports;
13
+ * an env with no `route` ships to
13
14
  * `*.workers.dev`; an env with a `route` ships to that custom domain.
14
15
  *
15
16
  * Prefer a managed deploy (no Cloudflare account)? Use
16
17
  * `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
17
18
  * `/build` toolkit and ships it through the Astrale platform.
18
19
  */
19
- export { cloudflare } from './cloudflare';
20
- //# sourceMappingURL=index.js.map
20
+ export { cloudflare } from './cloudflare.js';
package/dist/params.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ClientConfig } from './client';
1
+ import type { ExchangeOptions } from '@astrale-os/sdk/execution';
2
2
  /**
3
3
  * `CloudflareParams` — the provider-typed config for the Cloudflare adapter.
4
4
  *
@@ -7,23 +7,35 @@ import type { ClientConfig } from './client';
7
7
  * is `Record<string, CloudflareParams>`.
8
8
  *
9
9
  * Three deployment shapes fall out of which fields are set:
10
- * • dev (local) — `watch()` runs `wrangler dev`; URL = http://localhost:<port>
10
+ * • dev (local) — `develop()` runs `wrangler dev`; URL = an allocated loopback port
11
11
  * • dev-remote — `deploy()` with no `route`; URL = https://<name>.<sub>.workers.dev
12
12
  * • remote (custom) — `deploy()` with `route`; URL = https://<route>
13
13
  */
14
14
  export interface CloudflareParams {
15
- /** Frontend assets to build and serve for this env's mounted `/ui` views. */
16
- client?: ClientConfig;
17
15
  /**
18
16
  * Custom route / hostname for a routed deploy, e.g. `'crm.acme.dev'`. Omit to
19
17
  * deploy to `*.workers.dev`. Ignored by local `wrangler dev` (URL is
20
18
  * localhost) but still used as the placeholder base domain there.
21
19
  */
22
- route?: string;
20
+ readonly route?: string;
21
+ /**
22
+ * Exact public Addressing expected after deployment. Use this for an already
23
+ * known provider-assigned address such as `*.workers.dev`; `route` remains
24
+ * the field that asks Cloudflare to attach a custom hostname. When both are
25
+ * present they must identify the same HTTPS origin.
26
+ */
27
+ readonly addressing?: string;
23
28
  /** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
24
- secrets?: string;
25
- /** Local dev port for `wrangler dev`. Default 8787. */
26
- port?: number;
29
+ readonly secrets?: string;
30
+ /**
31
+ * Private Ed25519 JWK file retained outside source control. Remote deploys
32
+ * require this explicit source so a fresh runner cannot silently rotate an
33
+ * installed Domain identity. Local development generates `.astrale/identity.json`
34
+ * once when this field is omitted.
35
+ */
36
+ readonly signingIdentity?: string;
37
+ /** Strict local development port. Omit to allocate an available loopback port. */
38
+ readonly port?: number;
27
39
  /**
28
40
  * Public URL the dev server is reached through (tunnel / sandbox preview /
29
41
  * reverse proxy), e.g. `'https://my-box.preview.dev'`. Sets BOTH effects an
@@ -32,13 +44,29 @@ export interface CloudflareParams {
32
44
  * identity (`iss`) doesn't drift to the proxy's internal hostname.
33
45
  * Usually injected by `pnpm dev --host <url>` rather than written here.
34
46
  */
35
- host?: string;
47
+ readonly host?: string;
36
48
  /** Override the Worker name. Default: derived from the domain origin. */
37
- workerName?: string;
49
+ readonly workerName?: string;
38
50
  /** Run `wrangler dev --remote` (edge isolate) instead of local workerd. */
39
- remote?: boolean;
51
+ readonly remote?: boolean;
40
52
  /** Extra plain (non-secret) vars to inject as Worker vars. */
41
- vars?: Record<string, string>;
53
+ readonly vars?: Record<string, string>;
54
+ /**
55
+ * Maximum encoded invocation request bytes retained by the Worker Server.
56
+ * Defaults to 1 MiB and is capped at 16 MiB. Increase only from measured
57
+ * application traffic; Publication and Bundle delivery have separate limits.
58
+ */
59
+ readonly maximumRequestBytes?: number;
60
+ /**
61
+ * Maximum wall-clock lifetime of one invocation, including Workflow steps and
62
+ * returned streams. Defaults to 30 seconds. Increase this for intentionally
63
+ * long provider orchestration while retaining a finite application budget.
64
+ */
65
+ readonly invocationTimeoutMs?: number;
66
+ /**
67
+ * Configure the caller-only Domain token exchange lifetime, or disable exchange.
68
+ */
69
+ readonly tokenExchange?: ExchangeOptions | false;
42
70
  /**
43
71
  * Escape hatch: raw wrangler config deep-merged over the generated base. Use
44
72
  * it to declare extra bindings the adapter has no typed field for — KV, R2,
@@ -57,16 +85,16 @@ export interface CloudflareParams {
57
85
  * the reserved binding names `SELF` and `ASSETS`. Durable Objects need extra
58
86
  * worker-entry codegen and aren't supported through this field yet.
59
87
  */
60
- wrangler?: Record<string, unknown>;
88
+ readonly wrangler?: Record<string, unknown>;
61
89
  /**
62
90
  * Route subrequests to platform INSTANCE hostnames through a service binding
63
91
  * instead of the public edge. A Cloudflare Worker can't fetch a same-zone
64
92
  * hostname served by another Worker — Cloudflare 522s it — so without this the
65
93
  * worker can't fetch an instance kernel's JWKS to verify an inbound credential
66
- * from that instance, and every cross-instance call (install hooks, the GUI's
67
- * delegated calls, authed views) fails with `2002 Credential verification
68
- * failed`. Point it at a router Worker that reaches those hosts internally
69
- * (Astrale: `admin-router`).
94
+ * from that instance, and every cross-instance call (install hooks, delegated
95
+ * GUI calls, and traffic initiated from a Shell-handshaken View) fails with
96
+ * `2002 Credential verification failed`. Point it at a router Worker that
97
+ * reaches those hosts internally (Astrale: `admin-router`).
70
98
  *
71
99
  * Wires BOTH halves the SDK needs: the `<binding>` service binding in the
72
100
  * generated wrangler config, and a `routeSubrequest` predicate in the worker
@@ -80,15 +108,14 @@ export interface CloudflareParams {
80
108
  * router: false // opt out
81
109
  * router: { service: 'my-router' } // override target
82
110
  */
83
- router?: false | {
111
+ readonly router?: false | {
84
112
  /** Router Worker the binding targets. Default `'admin-router'`. */
85
- service?: string;
113
+ readonly service?: string;
86
114
  /** Service-binding name the worker reads. Default `'ROUTER'`. */
87
- binding?: string;
115
+ readonly binding?: string;
88
116
  /** Host suffix that marks an instance host. Default `'.astrale.ai'`. */
89
- hostSuffix?: string;
117
+ readonly hostSuffix?: string;
90
118
  /** Min dot-separated label count for an instance host. Default `4` (`<slug>.<region>.astrale.ai`). */
91
- minLabels?: number;
119
+ readonly minLabels?: number;
92
120
  };
93
121
  }
94
- //# sourceMappingURL=params.d.ts.map
package/dist/params.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=params.js.map
@@ -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 {};