@astrale-os/adapter-cloudflare 0.5.0-beta.9 → 0.5.0-beta.91
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/CHANGELOG.md +1097 -0
- package/README.md +20 -2
- package/dist/adapter.d.ts +15 -0
- package/dist/adapter.js +76 -0
- package/dist/build/artifact.d.ts +7 -0
- package/dist/build/artifact.js +165 -0
- package/dist/build/bundle/admit.d.ts +1 -0
- package/dist/build/bundle/admit.js +9 -0
- package/dist/build/closure.d.ts +2 -0
- package/dist/build/closure.js +22 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +13 -1
- package/dist/build/codegen/wrangler.js +35 -18
- package/dist/build/configuration/addressing.d.ts +2 -0
- package/dist/build/configuration/addressing.js +11 -0
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +11 -0
- package/dist/build/configuration/worker-name.d.ts +2 -0
- package/dist/build/configuration/worker-name.js +18 -0
- package/dist/build/configuration.d.ts +5 -0
- package/dist/build/configuration.js +5 -0
- package/dist/build/direct.d.ts +4 -0
- package/dist/build/direct.js +93 -0
- package/dist/build/frontend/files.d.ts +7 -0
- package/dist/build/frontend/files.js +60 -0
- package/dist/build/frontend/routes.d.ts +2 -0
- package/dist/build/frontend/routes.js +11 -0
- package/dist/build/index.d.ts +8 -16
- package/dist/build/index.js +7 -16
- package/dist/build/materialize.d.ts +4 -0
- package/dist/build/materialize.js +10 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -0
- package/dist/build/worker/artifact.d.ts +40 -0
- package/dist/build/worker/artifact.js +1 -0
- package/dist/build/worker/artifact.load.d.ts +3 -0
- package/dist/build/worker/artifact.load.js +308 -0
- package/dist/build/worker/artifact.manifest.d.ts +48 -0
- package/dist/build/worker/artifact.manifest.js +87 -0
- package/dist/build/worker/artifact.paths.d.ts +4 -0
- package/dist/build/worker/artifact.paths.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +2 -0
- package/dist/build/worker/codegen/entry.js +28 -0
- package/dist/build/worker/codegen/service.d.ts +18 -0
- package/dist/build/worker/codegen/service.js +53 -0
- package/dist/build/worker/execution.prepare.d.ts +18 -0
- package/dist/build/worker/execution.prepare.js +112 -0
- package/dist/build/worker/index.d.ts +2 -0
- package/dist/build/worker/index.js +1 -0
- package/dist/build/worker/modules.d.ts +11 -0
- package/dist/build/worker/modules.js +26 -0
- package/dist/build/worker/runtime.d.ts +10 -0
- package/dist/build/worker/runtime.js +35 -0
- package/dist/build/worker/specifier.d.ts +1 -0
- package/dist/build/worker/specifier.js +5 -0
- package/dist/cloudflare.d.ts +1 -34
- package/dist/cloudflare.js +1 -205
- package/dist/deploy/deploy.d.ts +16 -0
- package/dist/deploy/deploy.js +204 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.js +1 -0
- package/dist/deploy/output.d.ts +2 -0
- package/dist/deploy/output.js +10 -0
- package/dist/development/develop.d.ts +15 -0
- package/dist/development/develop.js +270 -0
- package/dist/development/frontend.d.ts +11 -0
- package/dist/development/frontend.js +109 -0
- package/dist/development/host.d.ts +2 -0
- package/dist/development/host.js +46 -0
- package/dist/development/port.d.ts +1 -0
- package/dist/development/port.js +12 -0
- package/dist/development/readiness.d.ts +14 -0
- package/dist/development/readiness.js +71 -0
- package/dist/development/resolved-fetch.d.ts +17 -0
- package/dist/development/resolved-fetch.js +80 -0
- package/dist/development/worker-output.d.ts +2 -0
- package/dist/development/worker-output.js +25 -0
- package/dist/development/worker.d.ts +17 -0
- package/dist/development/worker.js +147 -0
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +3 -0
- package/dist/identity/material.d.ts +7 -0
- package/dist/identity/material.js +42 -0
- package/dist/identity/secret.d.ts +3 -0
- package/dist/identity/secret.js +7 -0
- package/dist/identity/source.d.ts +26 -0
- package/dist/identity/source.js +127 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/params.d.ts +39 -7
- package/dist/params.js +0 -1
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -0
- package/dist/release/index.js +2 -0
- package/dist/release/staged-worker-name.d.ts +3 -0
- package/dist/release/staged-worker-name.js +10 -0
- package/dist/worker/entry.d.ts +44 -0
- package/dist/worker/entry.js +184 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +2 -61
- package/dist/worker/index.js +2 -212
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +27 -0
- package/dist/wrangler/deploy.d.ts +24 -0
- package/dist/wrangler/deploy.js +44 -0
- package/dist/wrangler/index.d.ts +5 -0
- package/dist/wrangler/index.js +5 -0
- package/dist/wrangler/process.d.ts +17 -0
- package/dist/wrangler/process.js +115 -0
- package/dist/wrangler/secrets.d.ts +6 -0
- package/dist/wrangler/secrets.js +58 -0
- package/dist/wrangler/status.d.ts +14 -0
- package/dist/wrangler/status.js +56 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +34 -19
- package/template/astrale.config.ts +25 -17
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -26
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -263
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -117
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts +0 -88
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -283
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/fetch.d.ts.map +0 -1
- package/dist/worker/fetch.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -127
- package/src/build/frontend.ts +0 -324
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -161
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -372
- package/src/cloudflare.ts +0 -251
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/fetch.ts +0 -46
- package/src/worker/index.ts +0 -325
- package/src/worker/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Cloudflare Worker deployment adapter for Astrale Domains.
|
|
4
4
|
|
|
5
|
-
During the SDK beta program, install the beta
|
|
5
|
+
During the SDK beta program, install the beta package set explicitly:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @astrale-os/sdk@beta @astrale-os/adapter-cloudflare@beta
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Bare installs return to stable releases when the
|
|
11
|
+
Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
|
|
12
|
+
|
|
13
|
+
`pnpm dev` starts the Worker and optional Vite frontend with hot reload on collision-free allocated
|
|
14
|
+
ports. It does not own Kernel installation or public ingress; the managed Astrale adapter composes
|
|
15
|
+
those lifecycle responsibilities around this provider-local session.
|
|
16
|
+
|
|
17
|
+
## Provider-local staging
|
|
18
|
+
|
|
19
|
+
Managed Cloudflare providers may stage immutable implementation candidates without exposing their
|
|
20
|
+
identity to Publications or installed Kernels:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { stagedWorkerName } from '@astrale-os/adapter-cloudflare/release'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This subpath is runtime-safe. `stagedWorkerName(providerDeployment)` addresses one private staged
|
|
27
|
+
candidate. The public Worker name and `/invoke` endpoint remain stable across compatible
|
|
28
|
+
implementation and Schema updates. Provider staging identity never enters Release, Publication,
|
|
29
|
+
Kernel routing, or graph identity.
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { type CloudflareDeployDependencies } from './deploy/index.js';
|
|
6
|
+
import { developCloudflare } from './development/develop.js';
|
|
7
|
+
import { signingIdentity } from './identity/source.js';
|
|
8
|
+
export interface CloudflareDependencies extends CloudflareDeployDependencies {
|
|
9
|
+
readonly artifact: typeof artifact;
|
|
10
|
+
readonly develop: typeof developCloudflare;
|
|
11
|
+
readonly signingIdentity: typeof signingIdentity;
|
|
12
|
+
}
|
|
13
|
+
export declare function cloudflare(environments: Readonly<Record<string, CloudflareParams>>): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
|
|
14
|
+
export declare function cloudflareWithDependencies(environments: Readonly<Record<string, CloudflareParams>>, dependencies: CloudflareDependencies): import("@astrale-os/sdk/deployment/adapter").Adapter<CloudflareParams>;
|
|
15
|
+
export declare function waitForReadiness(verify: typeof verifyReadiness, release: Release, signal?: AbortSignal): Promise<void>;
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { defineAdapter } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { artifact, materialize } from './build/artifact.js';
|
|
5
|
+
import { deployCloudflare } from './deploy/index.js';
|
|
6
|
+
import { developCloudflare } from './development/develop.js';
|
|
7
|
+
import { signingIdentity } from './identity/source.js';
|
|
8
|
+
import { runWranglerDeploy } from './wrangler/deploy.js';
|
|
9
|
+
import { runWranglerDeploymentStatus } from './wrangler/status.js';
|
|
10
|
+
const packageVersion = createRequire(import.meta.url)('../package.json')
|
|
11
|
+
.version;
|
|
12
|
+
export function cloudflare(environments) {
|
|
13
|
+
return cloudflareWithDependencies(environments, {
|
|
14
|
+
artifact,
|
|
15
|
+
materialize,
|
|
16
|
+
runWranglerDeploy,
|
|
17
|
+
runWranglerDeploymentStatus,
|
|
18
|
+
develop: developCloudflare,
|
|
19
|
+
signingIdentity,
|
|
20
|
+
waitForReadiness: (release, signal) => waitForReadiness(verifyReadiness, release, signal),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function cloudflareWithDependencies(environments, dependencies) {
|
|
24
|
+
return defineAdapter({
|
|
25
|
+
name: 'cloudflare',
|
|
26
|
+
version: packageVersion,
|
|
27
|
+
environments,
|
|
28
|
+
prepare: dependencies.artifact,
|
|
29
|
+
develop: (parameters, context) => dependencies.develop(parameters, context),
|
|
30
|
+
deploy: (parameters, context) => deployCloudflare(parameters, context, dependencies),
|
|
31
|
+
secretsFile: (parameters) => parameters.secrets,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export async function waitForReadiness(verify, release, signal) {
|
|
35
|
+
const deadline = Date.now() + 90_000;
|
|
36
|
+
let last;
|
|
37
|
+
while (Date.now() < deadline) {
|
|
38
|
+
throwIfAborted(signal);
|
|
39
|
+
try {
|
|
40
|
+
await verify(release, {
|
|
41
|
+
signal: signal === undefined
|
|
42
|
+
? AbortSignal.timeout(5_000)
|
|
43
|
+
: AbortSignal.any([signal, AbortSignal.timeout(5_000)]),
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
catch (cause) {
|
|
48
|
+
throwIfAborted(signal);
|
|
49
|
+
last = cause;
|
|
50
|
+
await pause(signal);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw last instanceof Error ? last : new Error('Cloudflare Release did not become ready.');
|
|
54
|
+
}
|
|
55
|
+
function pause(signal) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const timer = setTimeout(done, 1_000);
|
|
58
|
+
const abort = () => done(abortError(signal));
|
|
59
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
60
|
+
function done(cause) {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
signal?.removeEventListener('abort', abort);
|
|
63
|
+
if (cause === undefined)
|
|
64
|
+
resolve();
|
|
65
|
+
else
|
|
66
|
+
reject(cause);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function throwIfAborted(signal) {
|
|
71
|
+
if (signal?.aborted)
|
|
72
|
+
throw abortError(signal);
|
|
73
|
+
}
|
|
74
|
+
function abortError(signal) {
|
|
75
|
+
return signal?.reason instanceof Error ? signal.reason : new Error('Deployment interrupted.');
|
|
76
|
+
}
|
|
@@ -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,165 @@
|
|
|
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/files.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 = context.mode === 'development'
|
|
42
|
+
? []
|
|
43
|
+
: await frontendFiles({
|
|
44
|
+
frontend: context.build.frontend,
|
|
45
|
+
projectDir: context.projectDir,
|
|
46
|
+
});
|
|
47
|
+
const releaseConfig = generateWranglerConfig({
|
|
48
|
+
workerName: name,
|
|
49
|
+
main: `./${RELEASE_ENTRY}`,
|
|
50
|
+
...(params.route === undefined ? {} : { route: params.route }),
|
|
51
|
+
vars: runtimeVars(params, configuredIssuer),
|
|
52
|
+
secretBindings: [SIGNING_IDENTITY_BINDING],
|
|
53
|
+
modules: { baseDir: './bundle', rules: [{ type: 'ESModule', globs: ['service.mjs'] }] },
|
|
54
|
+
...(context.build.frontend?.source.kind === 'vite'
|
|
55
|
+
? {
|
|
56
|
+
frontend: {
|
|
57
|
+
directory: './frontend',
|
|
58
|
+
routes: frontendRoutes(context.build.frontend),
|
|
59
|
+
dev: false,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
: {}),
|
|
63
|
+
...(router === undefined
|
|
64
|
+
? {}
|
|
65
|
+
: { router: { binding: router.binding, service: router.service } }),
|
|
66
|
+
...(params.wrangler === undefined ? {} : { wrangler: params.wrangler }),
|
|
67
|
+
selfBinding: false,
|
|
68
|
+
});
|
|
69
|
+
const runtime = admitWorkerRuntimeConfiguration(releaseConfig);
|
|
70
|
+
const deployment = workerDeployment({
|
|
71
|
+
release: {
|
|
72
|
+
entrypoint: RELEASE_ENTRY,
|
|
73
|
+
modules: [
|
|
74
|
+
{ path: RELEASE_ENTRY, kind: 'esm', content: modules.entry },
|
|
75
|
+
{ path: RELEASE_SERVICE, kind: 'esm', content: modules.service },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
runtime,
|
|
79
|
+
bindings: {
|
|
80
|
+
vars: runtime.vars,
|
|
81
|
+
services: runtime.services,
|
|
82
|
+
requiredSecrets: [SIGNING_IDENTITY_BINDING],
|
|
83
|
+
},
|
|
84
|
+
...(frontend.length === 0
|
|
85
|
+
? {}
|
|
86
|
+
: {
|
|
87
|
+
assets: {
|
|
88
|
+
files: frontend.map((file) => {
|
|
89
|
+
const contentType = file.mediaType ?? inferMediaType(file.path);
|
|
90
|
+
return {
|
|
91
|
+
path: `/${file.path}`,
|
|
92
|
+
content: file.bytes(),
|
|
93
|
+
...(contentType === undefined ? {} : { contentType }),
|
|
94
|
+
};
|
|
95
|
+
}),
|
|
96
|
+
notFound: 'none',
|
|
97
|
+
runWorkerFirst: true,
|
|
98
|
+
htmlHandling: 'none',
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
const manifest = encodeWorkerArtifactManifest({
|
|
103
|
+
origin: context.build.schema.compiled.root.origin,
|
|
104
|
+
revision,
|
|
105
|
+
deployment,
|
|
106
|
+
release: {
|
|
107
|
+
entrypoint: RELEASE_ENTRY,
|
|
108
|
+
modules: [
|
|
109
|
+
{ path: RELEASE_ENTRY, kind: 'esm', digest: workerContentDigest(modules.entry) },
|
|
110
|
+
{ path: RELEASE_SERVICE, kind: 'esm', digest: workerContentDigest(modules.service) },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
runtime: {
|
|
114
|
+
compatibilityDate: runtime.compatibilityDate,
|
|
115
|
+
compatibilityFlags: runtime.compatibilityFlags,
|
|
116
|
+
},
|
|
117
|
+
bindings: {
|
|
118
|
+
vars: runtime.vars,
|
|
119
|
+
services: runtime.services,
|
|
120
|
+
requiredSecrets: [SIGNING_IDENTITY_BINDING],
|
|
121
|
+
},
|
|
122
|
+
...(frontend.length === 0
|
|
123
|
+
? {}
|
|
124
|
+
: {
|
|
125
|
+
assets: {
|
|
126
|
+
files: frontend.map((file) => {
|
|
127
|
+
const contentType = file.mediaType ?? inferMediaType(file.path);
|
|
128
|
+
return {
|
|
129
|
+
path: `/${file.path}`,
|
|
130
|
+
artifactPath: `frontend/${file.path}`,
|
|
131
|
+
digest: workerContentDigest(file.bytes()),
|
|
132
|
+
...(contentType === undefined ? {} : { contentType }),
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
135
|
+
notFound: 'none',
|
|
136
|
+
runWorkerFirst: true,
|
|
137
|
+
htmlHandling: 'none',
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
const files = [
|
|
142
|
+
{ path: RELEASE_ENTRY, content: modules.entry },
|
|
143
|
+
{ path: RELEASE_SERVICE, content: modules.service },
|
|
144
|
+
{ path: WORKER_MANIFEST_PATH, content: manifest },
|
|
145
|
+
...frontend.map((file) => ({
|
|
146
|
+
path: `frontend/${file.path}`,
|
|
147
|
+
content: file.bytes(),
|
|
148
|
+
})),
|
|
149
|
+
...(direct ? [{ path: 'wrangler.jsonc', content: encoder.encode(releaseConfig) }] : []),
|
|
150
|
+
];
|
|
151
|
+
return Object.freeze({
|
|
152
|
+
entrypoint: RELEASE_ENTRY,
|
|
153
|
+
files: Object.freeze(files),
|
|
154
|
+
addressing: configuredIssuer === undefined
|
|
155
|
+
? Object.freeze({ kind: 'provider-assigned', claim: name })
|
|
156
|
+
: Object.freeze({
|
|
157
|
+
kind: 'configured',
|
|
158
|
+
addressing: addressing(configuredIssuer),
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
await rm(directory, { recursive: true, force: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -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,17 @@
|
|
|
12
12
|
* (extra bindings: KV, R2, D1, queues, …) — see `mergeUserConfig`.
|
|
13
13
|
*/
|
|
14
14
|
import { deepMergeConfig } from './merge.js';
|
|
15
|
-
//
|
|
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
|
-
|
|
23
|
-
|
|
22
|
+
// Domain execution calls its Kernel through the invocation's public issuer. Cloudflare must
|
|
23
|
+
// route same-zone callbacks through the public front door instead of bypassing Worker routes.
|
|
24
|
+
compatibility_flags: ['nodejs_compat', 'global_fetch_strictly_public'],
|
|
25
|
+
workers_dev: opts.route === undefined,
|
|
24
26
|
version_metadata: { binding: 'ASTRALE_VERSION_METADATA' },
|
|
25
27
|
observability: { enabled: true },
|
|
26
28
|
};
|
|
@@ -31,19 +33,19 @@ export function generateWranglerConfig(opts) {
|
|
|
31
33
|
config.assets = {
|
|
32
34
|
directory: opts.frontend.directory,
|
|
33
35
|
binding: 'ASSETS',
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
html_handling: 'none',
|
|
37
|
+
run_worker_first: opts.frontend.dev
|
|
38
|
+
? true
|
|
39
|
+
: [
|
|
40
|
+
'/invoke',
|
|
41
|
+
'/install',
|
|
42
|
+
'/install/*',
|
|
43
|
+
'/health',
|
|
44
|
+
'/health/*',
|
|
45
|
+
'/.well-known',
|
|
46
|
+
'/.well-known/*',
|
|
47
|
+
...opts.frontend.routes,
|
|
48
|
+
],
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
const services = [];
|
|
@@ -57,6 +59,18 @@ export function generateWranglerConfig(opts) {
|
|
|
57
59
|
if (opts.vars && Object.keys(opts.vars).length > 0) {
|
|
58
60
|
config.vars = opts.vars;
|
|
59
61
|
}
|
|
62
|
+
if (opts.secretBindings && opts.secretBindings.length > 0) {
|
|
63
|
+
config.secrets = { required: [...opts.secretBindings] };
|
|
64
|
+
}
|
|
65
|
+
if (opts.modules !== undefined) {
|
|
66
|
+
config.find_additional_modules = true;
|
|
67
|
+
config.base_dir = opts.modules.baseDir;
|
|
68
|
+
config.rules = opts.modules.rules.map((rule) => ({
|
|
69
|
+
type: rule.type,
|
|
70
|
+
globs: [...rule.globs],
|
|
71
|
+
fallthrough: true,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
60
74
|
const merged = opts.wrangler ? mergeUserConfig(config, opts.wrangler) : config;
|
|
61
75
|
return JSON.stringify(merged, null, 2) + '\n';
|
|
62
76
|
}
|
|
@@ -67,7 +81,11 @@ const ADAPTER_OWNED_KEYS = [
|
|
|
67
81
|
'assets',
|
|
68
82
|
'routes',
|
|
69
83
|
'compatibility_date',
|
|
84
|
+
'workers_dev',
|
|
70
85
|
'version_metadata',
|
|
86
|
+
'secrets',
|
|
87
|
+
'find_additional_modules',
|
|
88
|
+
'base_dir',
|
|
71
89
|
];
|
|
72
90
|
/**
|
|
73
91
|
* Deep-merge the dev's raw wrangler overlay over the generated config, after
|
|
@@ -83,4 +101,3 @@ function mergeUserConfig(base, user) {
|
|
|
83
101
|
}
|
|
84
102
|
return deepMergeConfig(base, user);
|
|
85
103
|
}
|
|
86
|
-
//# sourceMappingURL=wrangler.js.map
|
|
@@ -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,9 @@
|
|
|
1
|
+
const MAXIMUM_TIMER_MS = 2_147_483_647;
|
|
2
|
+
export function workerInvocationTimeout(value) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > MAXIMUM_TIMER_MS) {
|
|
6
|
+
throw new TypeError('Cloudflare invocationTimeoutMs must be a positive integer within the platform timer range.');
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { deploymentAddressing } from './configuration/addressing.js';
|
|
2
|
+
export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
|
|
3
|
+
export { workerRequestLimit } from './configuration/request-limit.js';
|
|
4
|
+
export { resolveRouter } from './configuration/router.js';
|
|
5
|
+
export { workerName } from './configuration/worker-name.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { deploymentAddressing } from './configuration/addressing.js';
|
|
2
|
+
export { workerInvocationTimeout } from './configuration/invocation-timeout.js';
|
|
3
|
+
export { workerRequestLimit } from './configuration/request-limit.js';
|
|
4
|
+
export { resolveRouter } from './configuration/router.js';
|
|
5
|
+
export { workerName } from './configuration/worker-name.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { CloudflareParams } from '../params.js';
|
|
3
|
+
import type { WorkerArtifact } from './worker/index.js';
|
|
4
|
+
export declare function admitDirectPlacement(artifact: PreparedArtifact, worker: WorkerArtifact, parameters: CloudflareParams): void;
|