@astrale-os/adapter-cloudflare 0.5.0-beta.170 → 0.5.0-beta.172

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.
@@ -4,4 +4,4 @@ export type SigningIdentityMaterial = JsonWebKey & {
4
4
  };
5
5
  export declare function createSigningIdentity(): Promise<SigningIdentityMaterial>;
6
6
  /** Admit private Ed25519 material and its collision-resistant public identity. */
7
- export declare function admitSigningIdentity(input: unknown, owner: string, legacyKeyId?: string): Promise<SigningIdentityMaterial>;
7
+ export declare function admitSigningIdentity(input: unknown, owner: string): Promise<SigningIdentityMaterial>;
@@ -9,7 +9,7 @@ export async function createSigningIdentity() {
9
9
  }, 'generated identity');
10
10
  }
11
11
  /** Admit private Ed25519 material and its collision-resistant public identity. */
12
- export async function admitSigningIdentity(input, owner, legacyKeyId) {
12
+ export async function admitSigningIdentity(input, owner) {
13
13
  if (input === null || typeof input !== 'object' || Array.isArray(input))
14
14
  invalid(owner);
15
15
  const value = input;
@@ -22,20 +22,16 @@ export async function admitSigningIdentity(input, owner, legacyKeyId) {
22
22
  value.d.length === 0) {
23
23
  invalid(owner);
24
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) {
25
+ if (value.kid !== (await calculateJwkThumbprint(value))) {
30
26
  throw new TypeError(`Cloudflare signing identity '${owner}' must use its JWK thumbprint as kid.`);
31
27
  }
32
28
  try {
33
- await importJWK(admitted, 'EdDSA');
29
+ await importJWK(value, 'EdDSA');
34
30
  }
35
31
  catch (cause) {
36
32
  throw invalid(owner, cause);
37
33
  }
38
- return admitted;
34
+ return value;
39
35
  }
40
36
  function invalid(owner, cause) {
41
37
  throw new TypeError(`Cloudflare signing identity '${owner}' is not a private Ed25519 JWK.`, cause === undefined ? undefined : { cause });
@@ -17,8 +17,6 @@ export async function deployCloudflare(parameters, context, dependencies) {
17
17
  const identity = await dependencies.signingIdentity({
18
18
  projectDir: context.projectDir,
19
19
  source: parameters.signingIdentity,
20
- origin: context.artifact.build.schema.compiled.root.origin,
21
- mode: 'deploy',
22
20
  });
23
21
  secrets = signingIdentitySecrets(context.secrets, identity);
24
22
  }
@@ -1,4 +1,14 @@
1
1
  import { SIGNING_IDENTITY_BINDING } from '../../../identity/binding.js';
2
+ /**
3
+ * The one stable signing key a direct-mode Worker binds, read from the `signingIdentity` file its
4
+ * Environment retains. Nothing generates such a file any more: each direct-mode consumer deploys
5
+ * with the key its stable Worker was installed under, and a new Environment deploys with adapter
6
+ * astrale, or in namespace mode for platform publishers, both of which generate a key for each
7
+ * deployment (Identité [.60832]).
8
+ *
9
+ * @deprecated Legacy direct mode only. Replacement: `cloudflare({ namespace })`. Deleted with direct
10
+ * mode (D10, see `../index.ts`).
11
+ */
2
12
  export interface SigningIdentitySource {
3
13
  readonly binding: typeof SIGNING_IDENTITY_BINDING;
4
14
  readonly path: string;
@@ -7,20 +17,13 @@ export interface SigningIdentitySource {
7
17
  }
8
18
  export interface SigningIdentityInput {
9
19
  readonly projectDir: string;
10
- readonly origin: string;
20
+ /** The Environment's `signingIdentity` file, relative to the Project directory or absolute. */
11
21
  readonly source?: string;
12
- readonly mode: 'local' | 'deploy';
13
22
  }
14
- /** Resolve one admitted Domain signing identity for local or remote provider custody. */
23
+ /** Read the retained signing key of one direct-mode Environment. */
15
24
  export declare function signingIdentity(input: SigningIdentityInput): Promise<SigningIdentitySource>;
16
25
  /**
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.
26
+ * Read an explicitly retained deployment identity. Deployment never generates one: a missing file
27
+ * is a pre-provider configuration failure, not an implicit key rotation.
20
28
  */
21
29
  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>;
@@ -1,97 +1,24 @@
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';
1
+ import { readFile } from 'node:fs/promises';
2
+ import { isAbsolute, resolve } from 'node:path';
5
3
  import { SIGNING_IDENTITY_BINDING } from '../../../identity/binding.js';
6
- import { admitSigningIdentity, createSigningIdentity } from '../../../identity/material.js';
7
- const DEFAULT_IDENTITY = join('.astrale', 'identity.json');
8
- /** Resolve one admitted Domain signing identity for local or remote provider custody. */
4
+ import { admitSigningIdentity } from '../../../identity/material.js';
5
+ /** Read the retained signing key of one direct-mode Environment. */
9
6
  export function signingIdentity(input) {
10
- return input.mode === 'local'
11
- ? localSigningIdentity(input.projectDir, input.source, input.origin)
12
- : readSigningIdentity(input.projectDir, input.source);
7
+ return readSigningIdentity(input.projectDir, input.source);
13
8
  }
14
9
  /**
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.
10
+ * Read an explicitly retained deployment identity. Deployment never generates one: a missing file
11
+ * is a pre-provider configuration failure, not an implicit key rotation.
18
12
  */
19
13
  export async function readSigningIdentity(projectDir, declaration) {
20
14
  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.');
15
+ throw new TypeError("Cloudflare direct-mode deployment requires 'signingIdentity: <private-jwk-file>', the " +
16
+ 'retained key of its stable Worker. A new Environment deploys with adapter astrale ' +
17
+ '(`astrale()`), or, for platform publishers, in namespace mode (`cloudflare({ namespace })`); ' +
18
+ 'both generate a key for each deployment.');
23
19
  }
24
20
  return readSource(pathOf(projectDir, declaration), declaration);
25
21
  }
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
22
  async function readSource(path, declaration) {
96
23
  let source;
97
24
  try {
@@ -46,7 +46,11 @@ export declare function placeNamespace(parameters: CloudflareParams): Placement;
46
46
  export declare function deployNamespaceRelease(parameters: CloudflareParams, context: ReleaseDeployContext, dependencies: NamespaceDependencies): Promise<ReleaseDeployResult>;
47
47
  /**
48
48
  * Keep one published deployment of the platform namespace: its summary's retention becomes
49
- * `published`, which the platform's preview expiry never retires. Nothing else changes.
49
+ * `published`, which the platform's preview expiry never retires. Nothing else changes. A label the
50
+ * namespace holds no active deployment of is a `RetainRefusal` (`absent`, or `retired` once
51
+ * withdrawn), which no rerun changes; a failed read or write rejects as it is, and a rerun keeps it.
52
+ * A tombstone withdraws the label whatever its summary still says, as the dispatcher reads it, so
53
+ * it is refused before the summary is read or written.
50
54
  */
51
55
  export declare function retainNamespaceDeployment(parameters: CloudflareParams, context: RetainContext, dependencies: NamespaceDependencies): Promise<void>;
52
56
  /**
@@ -1,3 +1,4 @@
1
+ import { RetainRefusal } from '@astrale-os/sdk/deployment/adapter';
1
2
  import { acceptDeploymentRecord, configurationDigest, deploymentContent, deploymentLabel, deploymentLine, deploymentUrl, DEPLOYMENT_RECORD_FORMAT, DEPLOYMENT_RECORD_VERSION, PLATFORM_OWNER, } from '@astrale-os/sdk/deployment/address';
2
3
  import { bundleUpload } from '../build/worker/upload.js';
3
4
  import { SIGNING_IDENTITY_BINDING } from '../identity/binding.js';
@@ -56,18 +57,25 @@ export async function deployNamespaceRelease(parameters, context, dependencies)
56
57
  }
57
58
  /**
58
59
  * Keep one published deployment of the platform namespace: its summary's retention becomes
59
- * `published`, which the platform's preview expiry never retires. Nothing else changes.
60
+ * `published`, which the platform's preview expiry never retires. Nothing else changes. A label the
61
+ * namespace holds no active deployment of is a `RetainRefusal` (`absent`, or `retired` once
62
+ * withdrawn), which no rerun changes; a failed read or write rejects as it is, and a rerun keeps it.
63
+ * A tombstone withdraws the label whatever its summary still says, as the dispatcher reads it, so
64
+ * it is refused before the summary is read or written.
60
65
  */
61
66
  export async function retainNamespaceDeployment(parameters, context, dependencies) {
62
67
  const coordinates = namespaceCoordinates(parameters);
63
68
  const api = cloudflareApi(coordinates, context.signal, dependencies);
64
69
  const routing = await PlatformRouting.open(api, coordinates.routingKvTitle);
70
+ if ((await routing.retirement(context.label)) !== undefined) {
71
+ throw new RetainRefusal('retired', `${context.label} was withdrawn and is never served again, so it can no longer be retained.`);
72
+ }
65
73
  const summary = await routing.summary(context.label);
66
74
  if (summary === undefined || (await routing.record(context.label)) === undefined) {
67
- throw new NamespaceRefusal('deployment-conflict', `The platform namespace has no active deployment ${context.label} to retain.`);
75
+ throw new RetainRefusal('absent', `The platform namespace has no active deployment ${context.label} to retain.`);
68
76
  }
69
77
  if (summary.state !== 'active') {
70
- throw new NamespaceRefusal('deployment-retired', `${context.label} is ${summary.state} and can no longer be retained.`);
78
+ throw new RetainRefusal('retired', `${context.label} is ${summary.state} and can no longer be retained.`);
71
79
  }
72
80
  if (summary.retention === 'published')
73
81
  return;
@@ -273,11 +281,13 @@ class NamespaceDeployment {
273
281
  }
274
282
  /**
275
283
  * Write the summary, then the record whose presence activates the label (AM-131), so an active
276
- * label always has a summary. A summary already there is kept; so is a record of this release.
284
+ * label always has a summary. A record of this release already there is kept; so is a summary,
285
+ * except that it is made to name this script's URL and key when it names another script's.
277
286
  */
278
287
  async activate(keyId) {
279
288
  const { plan } = this;
280
- if ((await this.routing.summary(plan.label)) === undefined) {
289
+ const summary = await this.routing.summary(plan.label);
290
+ if (summary === undefined) {
281
291
  await this.routing.writeSummary({
282
292
  id: plan.label,
283
293
  url: plan.url,
@@ -290,6 +300,12 @@ class NamespaceDeployment {
290
300
  signingKeyId: keyId,
291
301
  });
292
302
  }
303
+ else if (summary.url !== plan.url || summary.signingKeyId !== keyId) {
304
+ // A script deleted outside any retirement leaves its summary naming a key no script holds,
305
+ // which a later deploy and the platform tooling refuse: it follows the script recreated
306
+ // under the label, and keeps the label's activation instant, retention and state.
307
+ await this.routing.writeSummary({ ...summary, url: plan.url, signingKeyId: keyId });
308
+ }
293
309
  const record = await this.routing.activate(plan.record);
294
310
  this.applied();
295
311
  return record;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/adapter-cloudflare",
3
- "version": "0.5.0-beta.170",
3
+ "version": "0.5.0-beta.172",
4
4
  "description": "Deploy an Astrale Domain through Cloudflare Workers",
5
5
  "keywords": [
6
6
  "adapter",
@@ -35,10 +35,6 @@
35
35
  "types": "./dist/build/index.d.ts",
36
36
  "import": "./dist/build/index.js"
37
37
  },
38
- "./identity": {
39
- "types": "./dist/legacy/direct/identity/index.d.ts",
40
- "import": "./dist/legacy/direct/identity/index.js"
41
- },
42
38
  "./worker": {
43
39
  "types": "./dist/worker/index.d.ts",
44
40
  "import": "./dist/worker/index.js"
@@ -61,7 +57,7 @@
61
57
  "registry": "https://registry.npmjs.org/"
62
58
  },
63
59
  "dependencies": {
64
- "@astrale-os/sdk": "0.6.0-beta.15",
60
+ "@astrale-os/sdk": "0.6.0-beta.17",
65
61
  "@noble/hashes": "2.3.0",
66
62
  "@restatedev/restate-sdk-cloudflare-workers": "1.17.0",
67
63
  "hono": "^4.6.20",
@@ -1,9 +1,19 @@
1
1
  /**
2
2
  * One Project definition, with explicit software-factory Environments.
3
3
  *
4
- * `pnpm dev` watches and deploys the development Environment remotely. A deploy
5
- * never installs: install the URL it prints with
6
- * `astrale domain install <url> --direct -i <instance>`.
4
+ * Every Environment deploys into the platform's dispatch namespace (namespace
5
+ * mode), where only the platform deploys: Shell, Services and the other
6
+ * platform Domains. `astrale-domain deploy <environment>` makes one immutable
7
+ * deployment of this release, at its own URL under the namespace's routing
8
+ * domain, with a signing key generated for it, and prints that URL. A deploy
9
+ * never installs the Domain: install the URL it prints with
10
+ * `astrale domain install <url> --direct -i <instance>`. Redeploying the same
11
+ * release reuses its deployment; a changed secrets file is then rewritten in
12
+ * place on that deployment only.
13
+ *
14
+ * `CLOUDFLARE_API_TOKEN` must edit the namespace's scripts and its routing KV,
15
+ * and `CLOUDFLARE_ACCOUNT_ID` names the account that holds it unless
16
+ * `namespace.account` does. Neither token nor secret is written here.
7
17
  */
8
18
  import { cloudflare } from '@astrale-os/adapter-cloudflare'
9
19
  import { defineProject } from '@astrale-os/sdk/project'
@@ -11,22 +21,24 @@ import { dataset, tests } from '@astrale-os/sdk/testing'
11
21
 
12
22
  import { domain } from './domain.js'
13
23
 
24
+ /**
25
+ * The platform dispatch namespace and the DNS name its dispatcher answers
26
+ * under, as the platform provisioning created them. Replace both placeholders
27
+ * with the platform's coordinates: a deploy finds the namespace's routing KV
28
+ * from its name and refuses, before any effect, a namespace without one.
29
+ */
30
+ const namespace = { name: 'your-platform-namespace', routingDomain: 'deployments.example.dev' }
31
+
14
32
  export default defineProject({
15
33
  domain,
16
34
 
17
35
  environments: {
18
36
  development: {
19
- deployment: cloudflare({
20
- secrets: '.env.dev',
21
- signingIdentity: '.astrale/identity.json',
22
- }),
37
+ deployment: cloudflare({ namespace, secrets: '.env.dev' }),
23
38
  },
24
39
 
25
40
  production: {
26
- deployment: cloudflare({
27
- route: 'astrale-domain.example.dev',
28
- signingIdentity: '.astrale/identity.json',
29
- }),
41
+ deployment: cloudflare({ namespace }),
30
42
  },
31
43
  },
32
44
 
@@ -1,11 +0,0 @@
1
- /**
2
- * Custody of the one stable signing key a direct-mode Worker binds: the `signingIdentity` file
3
- * (`.astrale/identity.json`), generated once for local development and read by every remote deploy.
4
- *
5
- * @deprecated Legacy direct mode only. Replacement: namespace mode generates a key for each new
6
- * deployment and binds it once (`cloudflare({ namespace })`); there is no file to keep. Consumers:
7
- * create-astrale-domain's direct scaffold (until S11) and adapter-astrale's instance mode (until
8
- * S8). Deleted with direct mode (D10, see `../index.ts`).
9
- */
10
- export { signingIdentity } from './source.js';
11
- export { signingIdentitySecrets } from './secret.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Custody of the one stable signing key a direct-mode Worker binds: the `signingIdentity` file
3
- * (`.astrale/identity.json`), generated once for local development and read by every remote deploy.
4
- *
5
- * @deprecated Legacy direct mode only. Replacement: namespace mode generates a key for each new
6
- * deployment and binds it once (`cloudflare({ namespace })`); there is no file to keep. Consumers:
7
- * create-astrale-domain's direct scaffold (until S11) and adapter-astrale's instance mode (until
8
- * S8). Deleted with direct mode (D10, see `../index.ts`).
9
- */
10
- export { signingIdentity } from './source.js';
11
- export { signingIdentitySecrets } from './secret.js';