@astrale-os/adapter-cloudflare 0.5.0-beta.52 → 0.5.0-beta.54

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.
package/dist/adapter.js CHANGED
@@ -92,6 +92,7 @@ export function cloudflareWithDependencies(environments, dependencies) {
92
92
  remote: parameters.remote ?? false,
93
93
  secrets,
94
94
  autoPickPort: parameters.port === undefined,
95
+ pinLocalOrigin: parameters.host === undefined && parameters.remote !== true,
95
96
  ...(parameters.host === undefined ? {} : { ip: '0.0.0.0' }),
96
97
  onReload: context.onReload,
97
98
  });
@@ -1,9 +1,9 @@
1
- import type { BuildMaterial } from '@astrale-os/sdk/deployment/build';
1
+ import type { Build } from '@astrale-os/sdk/deployment/build';
2
2
  export interface ExecutionCodegenOptions {
3
3
  readonly origin: string;
4
4
  readonly runtimeSpecifier: string;
5
5
  readonly workerSpecifier?: string;
6
- readonly material: BuildMaterial;
6
+ readonly build: Build;
7
7
  readonly maximumRequestBytes?: number;
8
8
  readonly providerAssignedWorker?: string;
9
9
  readonly router?: {
@@ -1,5 +1,7 @@
1
+ import { generatedMaterial } from '@astrale-os/sdk/deployment/build';
1
2
  export function generateExecutionService(options) {
2
3
  const workerSpecifier = options.workerSpecifier ?? '@astrale-os/adapter-cloudflare/worker';
4
+ const generated = generatedMaterial(options.build);
3
5
  const router = options.router;
4
6
  const routerPredicate = router === undefined
5
7
  ? ''
@@ -17,15 +19,15 @@ function isInstanceHost(host: string): boolean {
17
19
  if (env.${router.binding} && isInstanceHost(url.hostname)) return env.${router.binding}
18
20
  return null
19
21
  },`;
20
- const frontend = options.material.frontend === undefined
22
+ const frontend = generated.material.frontend === undefined
21
23
  ? ''
22
- : ` frontend: ${JSON.stringify(options.material.frontend)} as const satisfies NonNullable<BuildMaterial['frontend']>,\n`;
24
+ : ` frontend: ${JSON.stringify(generated.material.frontend)} as const satisfies NonNullable<BuildMaterial['frontend']>,\n`;
23
25
  return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
24
26
  // Domain origin: ${options.origin}
25
- import type { BuildMaterial } from '@astrale-os/sdk/deployment/build'
27
+ import type { BuildMaterial, GeneratedBuildMaterial } from '@astrale-os/sdk/deployment/build'
26
28
  import type { CloudflareAdapterBindings } from ${JSON.stringify(workerSpecifier)}
27
29
 
28
- import { cloudflareWorkerEntry } from ${JSON.stringify(workerSpecifier)}
30
+ import { generatedCloudflareWorkerEntry } from ${JSON.stringify(workerSpecifier)}
29
31
  import { decodeSigningIdentity, runtimeBindings } from ${JSON.stringify(workerSpecifier)}
30
32
 
31
33
  type WorkerEnv = CloudflareEnv & CloudflareAdapterBindings & {
@@ -33,10 +35,10 @@ type WorkerEnv = CloudflareEnv & CloudflareAdapterBindings & {
33
35
  }
34
36
  type RuntimeEnv = Omit<WorkerEnv, 'ASTRALE_SIGNING_IDENTITY'>
35
37
  ${routerPredicate}
36
- export default cloudflareWorkerEntry<WorkerEnv, RuntimeEnv>()({
38
+ export default generatedCloudflareWorkerEntry<WorkerEnv, RuntimeEnv>()({
37
39
  ${frontend} load: async () => ({
38
40
  runtime: (await import(${JSON.stringify(options.runtimeSpecifier)})).default,
39
- material: ${JSON.stringify(options.material)} as const satisfies BuildMaterial,
41
+ material: ${JSON.stringify(generated)} as unknown as GeneratedBuildMaterial,
40
42
  }),
41
43
  privateKey: (env) => decodeSigningIdentity(env.ASTRALE_SIGNING_IDENTITY),
42
44
  resolveEnvironment: runtimeBindings,
@@ -1,4 +1,3 @@
1
- import { material } from '@astrale-os/sdk/deployment/build';
2
1
  import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3
2
  import { dirname, join, relative, resolve } from 'node:path';
4
3
  import { SIGNING_IDENTITY_BINDING } from '../../identity/binding.js';
@@ -20,7 +19,7 @@ export async function prepareExecution(input) {
20
19
  origin: input.context.build.schema.compiled.root.origin,
21
20
  runtimeSpecifier,
22
21
  workerSpecifier,
23
- material: material(input.context.build),
22
+ build: input.context.build,
24
23
  ...(maximumRequestBytes === undefined ? {} : { maximumRequestBytes }),
25
24
  ...(input.configuredIssuer === undefined && input.direct
26
25
  ? { providerAssignedWorker: input.name }
@@ -9,6 +9,8 @@ export declare function runWranglerDev(args: {
9
9
  remote: boolean;
10
10
  readonly ip?: string;
11
11
  readonly autoPickPort?: boolean;
12
+ /** Pin ordinary local requests to one stable issuer after the final port is selected. */
13
+ readonly pinLocalOrigin?: boolean;
12
14
  readonly secrets: Readonly<Record<string, string>>;
13
15
  readonly onReload: () => void;
14
16
  readonly onLog?: (line: string) => void;
@@ -15,6 +15,7 @@ export async function runWranglerDev(args) {
15
15
  }
16
16
  const secretEnvironment = await createSecretEnvironment(args.secrets);
17
17
  const redact = secretRedactor(args.secrets);
18
+ const fallbackUrl = `http://localhost:${args.port}`;
18
19
  const wranglerArgs = [
19
20
  ...prefix,
20
21
  'dev',
@@ -26,6 +27,7 @@ export async function runWranglerDev(args) {
26
27
  'http',
27
28
  '--ip',
28
29
  args.ip ?? '127.0.0.1',
30
+ ...(args.pinLocalOrigin ? ['--var', `WORKER_URL:${fallbackUrl}`] : []),
29
31
  ...(secretEnvironment === undefined ? [] : ['--env-file', secretEnvironment.path]),
30
32
  ...(args.remote ? ['--remote'] : []),
31
33
  ];
@@ -41,7 +43,6 @@ export async function runWranglerDev(args) {
41
43
  await secretEnvironment?.remove();
42
44
  throw cause;
43
45
  }
44
- const fallbackUrl = `http://localhost:${args.port}`;
45
46
  let resolved = false;
46
47
  let buildErrorTail = '';
47
48
  let outputTail = '';
@@ -103,7 +104,7 @@ export async function runWranglerDev(args) {
103
104
  throw cause;
104
105
  }
105
106
  return {
106
- url,
107
+ url: args.pinLocalOrigin ? fallbackUrl : url,
107
108
  async stop() {
108
109
  try {
109
110
  await stopChild(child);
@@ -1,5 +1,5 @@
1
1
  import type { JsonWebKey } from '@astrale-os/sdk/auth';
2
- import type { BuildMaterial } from '@astrale-os/sdk/deployment/build/material';
2
+ import type { BuildMaterial, GeneratedBuildMaterial } from '@astrale-os/sdk/deployment/build/material';
3
3
  import type { ExecutionContext } from '@astrale-os/sdk/execution';
4
4
  import type { Runtime } from '@astrale-os/sdk/runtime';
5
5
  export interface Fetcher {
@@ -16,11 +16,11 @@ export interface CloudflareAdapterBindings {
16
16
  get(name: string): Fetcher;
17
17
  };
18
18
  }
19
- export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings extends CloudflareAdapterBindings, Environment> {
19
+ export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings extends CloudflareAdapterBindings, Environment, Material = BuildMaterial> {
20
20
  /** Generated frontend evidence available without restoring the execution Build. */
21
21
  readonly frontend?: BuildMaterial['frontend'];
22
22
  /** Load the exact Runtime and Build once, after the isolate has accepted a request. */
23
- readonly load: () => CloudflareWorkerSource<RuntimeValue> | Promise<CloudflareWorkerSource<RuntimeValue>>;
23
+ readonly load: () => CloudflareWorkerSource<RuntimeValue, Material> | Promise<CloudflareWorkerSource<RuntimeValue, Material>>;
24
24
  readonly privateKey: JsonWebKey | ((bindings: Bindings) => JsonWebKey);
25
25
  readonly resolveEnvironment?: (bindings: Bindings) => Environment;
26
26
  readonly resolveUrl?: (bindings: Bindings, requestOrigin: string) => string;
@@ -30,12 +30,14 @@ export interface CloudflareWorkerConfig<RuntimeValue extends Runtime, Bindings e
30
30
  readonly invocationTimeoutMs?: number;
31
31
  readonly maximumRequestBytes?: number;
32
32
  }
33
- export interface CloudflareWorkerSource<RuntimeValue extends Runtime> {
33
+ export interface CloudflareWorkerSource<RuntimeValue extends Runtime, Material = BuildMaterial> {
34
34
  readonly runtime: RuntimeValue;
35
- readonly material: BuildMaterial;
35
+ readonly material: Material;
36
36
  }
37
37
  export interface CloudflareWorker<Bindings> {
38
38
  fetch(request: Request, environment: Bindings, executionContext?: ExecutionContext): Response | Promise<Response>;
39
39
  }
40
40
  /** Compose one exact revision Service; the provider gateway owns revision selection. */
41
- export declare function cloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment>) => CloudflareWorker<Bindings>;
41
+ export declare function cloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, BuildMaterial>) => CloudflareWorker<Bindings>;
42
+ /** Compose generated execution code whose exact Build material carries build-owner evidence. */
43
+ export declare function generatedCloudflareWorkerEntry<Bindings extends CloudflareAdapterBindings, Environment = Bindings>(): <RuntimeValue extends Runtime>(config: CloudflareWorkerConfig<RuntimeValue, Bindings, Environment, GeneratedBuildMaterial>) => CloudflareWorker<Bindings>;
@@ -1,10 +1,17 @@
1
1
  import { issuer } from '@astrale-os/sdk/auth';
2
- import { restoreBuild } from '@astrale-os/sdk/deployment/build/material';
2
+ import { restoreBuild, restoreGeneratedBuild } from '@astrale-os/sdk/deployment/build/material';
3
3
  import { addressing, assemble } from '@astrale-os/sdk/deployment/release/runtime';
4
4
  import { createIdentity, serve } from '@astrale-os/sdk/execution';
5
5
  import { dispatchCloudflareRequest, prepareCloudflareRequest } from './fetch.js';
6
6
  /** Compose one exact revision Service; the provider gateway owns revision selection. */
7
7
  export function cloudflareWorkerEntry() {
8
+ return createCloudflareWorkerEntry(restoreBuild);
9
+ }
10
+ /** Compose generated execution code whose exact Build material carries build-owner evidence. */
11
+ export function generatedCloudflareWorkerEntry() {
12
+ return createCloudflareWorkerEntry(restoreGeneratedBuild);
13
+ }
14
+ function createCloudflareWorkerEntry(restore) {
8
15
  return function (config) {
9
16
  let currentIssuer;
10
17
  let realized;
@@ -14,7 +21,7 @@ export function cloudflareWorkerEntry() {
14
21
  realized = Promise.resolve()
15
22
  .then(config.load)
16
23
  .then((source) => {
17
- const build = restoreBuild(source.material, source.runtime);
24
+ const build = restore(source.material, source.runtime);
18
25
  const application = serve({
19
26
  runtime: source.runtime,
20
27
  load(environment) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/adapter-cloudflare",
3
- "version": "0.5.0-beta.52",
3
+ "version": "0.5.0-beta.54",
4
4
  "description": "Deploy an Astrale application through Cloudflare Workers",
5
5
  "keywords": [
6
6
  "adapter",
@@ -45,7 +45,7 @@
45
45
  "hono": "^4.6.20",
46
46
  "jose": "^6.1.3",
47
47
  "wrangler": "4.123.0",
48
- "@astrale-os/sdk": "0.5.0-beta.49"
48
+ "@astrale-os/sdk": "0.5.0-beta.51"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@astrale-os/ox": ">=0.1.0 <1.0.0",
@@ -60,7 +60,7 @@
60
60
  "node": ">=22"
61
61
  },
62
62
  "scripts": {
63
- "typecheck": "tsc --noEmit",
63
+ "typecheck": "tsc --noEmit && tsc --noEmit -p __tests__/tsconfig.types.json",
64
64
  "test": "vitest run",
65
65
  "lint": "oxlint --disable-nested-config .",
66
66
  "format": "pnpm exec oxfmt --write .",