@astrale-os/adapter-astrale 0.5.0-beta.18 → 0.5.0-beta.180

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 (54) hide show
  1. package/README.md +161 -2
  2. package/dist/adapter.d.ts +7 -16
  3. package/dist/adapter.js +27 -266
  4. package/dist/admit.d.ts +7 -0
  5. package/dist/admit.js +44 -0
  6. package/dist/cli/commands/call.d.ts +15 -0
  7. package/dist/cli/commands/call.js +36 -0
  8. package/dist/cli/commands/version.d.ts +12 -0
  9. package/dist/cli/commands/version.js +56 -0
  10. package/dist/cli/diagnostic.d.ts +6 -0
  11. package/dist/cli/diagnostic.js +28 -0
  12. package/dist/cli/error.d.ts +7 -0
  13. package/dist/cli/error.js +29 -0
  14. package/dist/cli/executable.d.ts +2 -0
  15. package/dist/cli/executable.js +54 -0
  16. package/dist/cli/identity.d.ts +5 -0
  17. package/dist/cli/identity.js +11 -0
  18. package/dist/cli/json.d.ts +2 -0
  19. package/dist/cli/json.js +39 -0
  20. package/dist/cli/process.d.ts +18 -0
  21. package/dist/cli/process.js +108 -0
  22. package/dist/configure.d.ts +17 -0
  23. package/dist/configure.js +40 -0
  24. package/dist/deploy/deploy-release.d.ts +30 -0
  25. package/dist/deploy/deploy-release.js +168 -0
  26. package/dist/deploy/list.d.ts +22 -0
  27. package/dist/deploy/list.js +63 -0
  28. package/dist/deploy/readiness.d.ts +17 -0
  29. package/dist/deploy/readiness.js +56 -0
  30. package/dist/index.d.ts +21 -10
  31. package/dist/index.js +21 -10
  32. package/dist/params.d.ts +25 -36
  33. package/dist/services/api.d.ts +35 -0
  34. package/dist/services/api.js +39 -0
  35. package/dist/services/client.d.ts +93 -0
  36. package/dist/services/client.js +116 -0
  37. package/dist/services/directory.d.ts +16 -0
  38. package/dist/services/directory.js +78 -0
  39. package/dist/services/index.d.ts +44 -0
  40. package/dist/services/index.js +27 -0
  41. package/dist/services/request.d.ts +25 -0
  42. package/dist/services/request.js +71 -0
  43. package/package.json +15 -8
  44. package/template/astrale.config.ts +27 -38
  45. package/dist/cli.d.ts +0 -15
  46. package/dist/cli.js +0 -48
  47. package/dist/prerequisite.d.ts +0 -19
  48. package/dist/prerequisite.js +0 -59
  49. package/dist/service/addressing.d.ts +0 -3
  50. package/dist/service/addressing.js +0 -16
  51. package/dist/service/artifact.d.ts +0 -34
  52. package/dist/service/artifact.js +0 -122
  53. package/dist/service/readiness.d.ts +0 -3
  54. package/dist/service/readiness.js +0 -16
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # `@astrale-os/adapter-astrale`
2
2
 
3
- Managed Astrale platform deployment adapter for Astrale Domains.
3
+ Managed Astrale platform deployment adapter for Astrale Domains: every deploy is an immutable
4
+ deployment hosted by Admin's Services.
4
5
 
5
6
  During the SDK beta program, install the beta package set explicitly:
6
7
 
@@ -8,4 +9,162 @@ During the SDK beta program, install the beta package set explicitly:
8
9
  npm install @astrale-os/sdk@beta @astrale-os/adapter-astrale@beta
9
10
  ```
10
11
 
11
- Bare installs return to stable releases when the package set is promoted and npm `latest` advances.
12
+ One adapter value configures one Project Environment:
13
+
14
+ ```ts
15
+ export default defineProject({
16
+ domain,
17
+ environments: {
18
+ development: {
19
+ deployment: astrale({ secrets: '.env.dev' }),
20
+ },
21
+ production: {
22
+ deployment: astrale({ secrets: '.env.production' }),
23
+ },
24
+ },
25
+ })
26
+ ```
27
+
28
+ `astrale-domain deploy <environment>` builds the release locally and makes one immutable
29
+ deployment of it on Admin's Services, as a version of the Service of the Domain's origin and the
30
+ Environment: its own Worker script at its own URL, `https://<line>-<content>.<routingDomain>`. The
31
+ line comes from the Domain's origin and the Environment name, is opaque (a fingerprint), and names
32
+ the Service, whose stable URL `https://<line>.<routingDomain>` serves its current deployment. The
33
+ first deploy creates the Service, and every deploy makes the Service serve the deployment it
34
+ created or reused. The content covers the build and the frozen Worker configuration
35
+ (`WorkerConfigurationV1`: variables, the execution settings and durable options the generated
36
+ Worker reads from `ASTRALE_SETTINGS`, the Workers runtime, the names of the declared secrets, never
37
+ their values, and what the Domain asks of Services: its record and a key of its own), so one URL
38
+ serves one release and a changed variable gives another URL.
39
+
40
+ Admin's Services knows nothing of Domains: it hosts any Cloudflare Worker from a
41
+ `WorkerDeploymentRequestV1` (`@astrale-os/sdk/deployment/worker`). The adapter builds every Domain
42
+ fact itself: the project is the Domain's origin, so its Service keeps the name of the Domain's
43
+ line; the build manifest members are the Bundle's own, so Services binds the release's build digest
44
+ as `ASTRALE_BUILD_DIGEST`; the record is the Domain's `DeploymentRecordV1` document (media type
45
+ `application/vnd.astrale.deployment-record+json;v=1`), which Services serves byte for byte at
46
+ `/.well-known/astrale/deployment.json`; and Services probes the release's `release.json`, Bundle and
47
+ issuer documents before it activates the deployment. Since the configuration digest is the Worker
48
+ configuration's, the label of a release deployed before this contract is not the label of the same
49
+ release deployed now: the first deploy after an upgrade creates a new deployment at a new URL, and
50
+ the earlier one keeps serving its own until it is retired. The commit the deploy runs from is recorded but never part of the label: the same release
51
+ deployed from a later commit, or from a dirty or clean working tree, reuses its deployment, whose
52
+ record keeps the commit of the deploy that created it. Each deployment is its own issuer, with a signing
53
+ key Services generates for it: there is no key file to keep or distribute. Deploying a new release
54
+ leaves earlier deployments served at their own URLs; Services keeps each one until it is retired,
55
+ with no preview, expiry or retention to manage.
56
+
57
+ Every Environment deploys as the authenticated Astrale CLI identity, selected with `--as` when
58
+ needed. The adapter names no `owner`, so a Service its first deploy creates is owned by that
59
+ identity; a Service owned by another Identity, which the caller neither is nor acts as, is refused
60
+ as `service-owned-elsewhere`. Give a Service to another owner with its `transfer` Method.
61
+ `admin` names the Admin bookmark of the astrale CLI to deploy through; by default the CLI's
62
+ configured Admin target.
63
+
64
+ Set `ASTRALE_BIN` to an absolute executable path to pin the CLI used for deployments and Services calls. It takes precedence over the recorded installation and `PATH`; an invalid override fails
65
+ with an error. For example: `ASTRALE_BIN=/opt/astrale/bin/astrale astrale-domain deploy qa --as deployer`.
66
+
67
+ `durable` declares what a Domain serving durable Workflows tells the workflow engine (run
68
+ retention, retry before pausing, the deadline of each Step). The options are frozen into the
69
+ deployment's configuration (`settings.durableOptions`), so another value is another deployment,
70
+ and a durable run stays on the deployment that started it. A hosted deployment binds no service,
71
+ no dispatch namespace and no router.
72
+
73
+ The adapter calls the static Methods of `CloudflareService` on Admin's Services with
74
+ `astrale call --admin` (astrale CLI 1.0.0-beta.126 or newer): `CloudflareService.hosting` to read
75
+ the routing domain, then `CloudflareService.deploy`, a non-durable Action, with the request on
76
+ stdin; `list` calls `CloudflareService.list` for the project of the Domain's origin. It never calls an instance and never installs the
77
+ Domain: install the URL the deploy prints with `astrale domain install <url> --direct -i <instance>`.
78
+
79
+ Secrets come from the file `secrets` names. A new deployment binds the file's current values. A
80
+ redeploy of the same release (same label) reuses its deployment and rewrites that deployment's
81
+ secrets in place when they changed (`Secrets: updated`); the new values are served once
82
+ propagated, which is eventually consistent (about 4 s). No other deployment's secrets are ever
83
+ written. A secret name added or removed changes the configuration, so it is a new deployment.
84
+
85
+ `astrale-domain list [--environment <name>] [--json]` lists, Environment by Environment, the
86
+ deployments of the Services the caller owns or acts as the owner of (`CloudflareService.list`,
87
+ which changes nothing): each one's release, its name computed from its record
88
+ (`1.4.2 + 7 commits · a1b2c3d · staging`), its state, `active (current)` for the one its Service
89
+ serves (`current` in `--json`), its URL, and its call target on the Admin instance. A Services
90
+ deployment is listed `published` until it is retired (`withdrawn` once retiring), with no last
91
+ call or expiry: Services counts neither. Each row carries the record its deployment published,
92
+ unadmitted; a record this SDK refuses is listed from its host's facts.
93
+
94
+ The call target names two nodes. `callTarget.service`,
95
+ `@<serviceId>::services.astrale.ai:class.CloudflareService`, takes the Service's Methods, which
96
+ act on the Service and the deployment it currently serves: `promote` (`{ "label": "<label>" }`,
97
+ to roll back or forward to one of its active deployments), `setSecret` (`{ "name", "value" }`, to
98
+ rewrite one secret of the current deployment in place without redeploying), `secrets`,
99
+ `setSchedule` and `schedules` (UTC crons run on the current deployment), `logs`, `transfer`
100
+ (`{ "owner" }`) and `delete`. `callTarget.path`, `@<id>::services.astrale.ai:class.CloudflareDeployment`,
101
+ takes `retire` (`{}`), the emergency stop of that deployment alone. Call them with
102
+ `astrale call "<node>.method.<method>" --admin -d @file` (`--admin=<callTarget.admin>` when it
103
+ names a bookmark).
104
+
105
+ The deploy is ready once the deployment URL serves exactly the sealed release: its `release.json`
106
+ (release digest and build digest), its Bundle and its issuer documents. Readiness is cancellable
107
+ and bounded to two minutes; certificate verification is never disabled. Services refusals are
108
+ reported with their reason (`service-owned-elsewhere`, `deployment-conflict`, ...). A validation or
109
+ ownership refusal changes nothing. `service-unavailable` waited on, or lost to, another operation on
110
+ the deployment and may follow effects: a creation that lost its lease after uploading, or an
111
+ in-place secret rewrite that wrote part of the values. Rerunning the same deploy converges on the
112
+ same deployment.
113
+
114
+ The removed instance mode (`instance`, `serviceKey`, `name`, `signingIdentity`) is refused with the
115
+ configuration to write instead. A Project Environment that declares `installation` is refused before
116
+ any effect, naming the commands that replace it. Iterate with `astrale-domain deploy development`,
117
+ then install the URL it prints.
118
+
119
+ The managed Worker is the one `@astrale-os/adapter-cloudflare` builds: it owns frontend response
120
+ headers and routing, and it is the only server-side code. Bundling therefore refuses a built
121
+ frontend whose root contains `_headers`, `_redirects`, or `.assetsignore`, in any letter case,
122
+ before anything is uploaded: Services would serve them as public files, whereas a direct Cloudflare
123
+ deployment would apply them as Workers Static Assets configuration. It likewise refuses a root name
124
+ starting with `_worker.js`, in that exact case, such as a Cloudflare Pages `_worker.js` file or
125
+ directory: Services would publish that possible server-side code, whereas Wrangler refuses to
126
+ upload it. Vite copies its public directory (`public/` by default) to that root, so remove or
127
+ rename them there. The same names below the root remain ordinary files.
128
+
129
+ ## Any Cloudflare Worker
130
+
131
+ `@astrale-os/adapter-astrale/services` deploys any Worker on Admin's Services, the same way and
132
+ with the same session: a cron job, an API or a scaffolded Service, with no Cloudflare account.
133
+
134
+ ```ts
135
+ import { callService, deployWorker, readWorkerDirectory } from '@astrale-os/adapter-astrale/services'
136
+
137
+ const worker = await readWorkerDirectory('.dist', { mainModule: 'worker.mjs' })
138
+ const { state, deployment } = await deployWorker({
139
+ project: 'nightly-report',
140
+ environment: 'production',
141
+ worker,
142
+ configuration: { compatibilityDate: '2026-09-01', vars: { KERNEL: 'https://…' } },
143
+ secrets: { ACCOUNT_PRIVATE_JWK: process.env.ACCOUNT_PRIVATE_JWK! },
144
+ readiness: ['/health'],
145
+ })
146
+ await callService(deployment.serviceId, 'setSchedule', { crons: ['*/5 * * * *'] })
147
+ ```
148
+
149
+ - `readWorkerDirectory(directory, { mainModule, assets? })` reads a built Worker: every file is a
150
+ module loaded by its extension (`.js`/`.mjs` ES modules, `.wasm`, `.txt`/`.html`/`.sql` text,
151
+ `.bin` data; source maps left out), and every file of `assets` a static asset.
152
+ - `deployWorker(input, options?)` deploys it as a deployment of the Service of `project` and
153
+ `environment`, created on the first deploy and owned by the caller; the configuration may be the
154
+ input of `workerConfiguration` (`@astrale-os/sdk/deployment/worker`), whose secret names default
155
+ to those of `secrets`. The same code and configuration reuse their deployment and rewrite its
156
+ secrets in place. It answers the deployment (`created` or `reused`), or throws a
157
+ `ServicesRefusal` with Services' reason.
158
+ - `readiness` paths must answer 200 with `x-astrale-worker-version` set to the `id` of the
159
+ `ASTRALE_VERSION_METADATA` binding before Services activates the deployment. Services binds
160
+ `WORKER_URL`, `ASTRALE_BUILD_DIGEST` and `ASTRALE_VERSION_METADATA` on every deployment, a key as
161
+ `ASTRALE_SIGNING_IDENTITY` when the configuration asks `signingIdentity`, and serves the given
162
+ `record` at `/.well-known/astrale/deployment.json`.
163
+ - `listWorkerDeployments({ project?, environment? })`, `servicesHosting()` and
164
+ `callService(serviceId, method, data)` (`promote`, `setSecret`, `setSchedule`, `schedules`,
165
+ `logs`, `transfer`, `delete`) read and act on the caller's Services. A scheduled Service is called
166
+ `POST /__scheduled` on its current deployment, with `x-astrale-cron` and
167
+ `x-astrale-scheduled-time`; the public never reaches that path.
168
+
169
+ Each call runs `astrale call --admin` as the CLI's identity; `options` names an Admin bookmark
170
+ (`admin`), an identity to act as (`identity`) or a credential (`credential`).
package/dist/adapter.d.ts CHANGED
@@ -1,17 +1,8 @@
1
- import type { ArtifactSource, PrepareContext, WatchContext, WatchHandle } from '@astrale-os/sdk/deployment/adapter';
2
- import { signingIdentity } from '@astrale-os/adapter-cloudflare/build';
1
+ import type { Deployment } from '@astrale-os/sdk/deployment';
2
+ import type { Adapter } from '@astrale-os/sdk/deployment/adapter';
3
+ import type { AstraleDependencies } from './deploy/deploy-release.js';
3
4
  import type { AstraleParams } from './params.js';
4
- import { callAstrale, runAstrale } from './cli.js';
5
- import { ensureServices } from './prerequisite.js';
6
- import { waitForReadiness } from './service/readiness.js';
7
- export interface AstraleDependencies {
8
- prepare(parameters: AstraleParams, context: PrepareContext): Promise<ArtifactSource>;
9
- watch(parameters: AstraleParams, context: WatchContext): Promise<WatchHandle>;
10
- ensureServices: typeof ensureServices;
11
- callAstrale: typeof callAstrale;
12
- runAstrale: typeof runAstrale;
13
- waitForReadiness: typeof waitForReadiness;
14
- signingIdentity: typeof signingIdentity;
15
- }
16
- export declare function astrale(environments: Readonly<Record<string, AstraleParams>>): import("@astrale-os/sdk/deployment/adapter").Adapter<AstraleParams>;
17
- export declare function astraleWithDependencies(environments: Readonly<Record<string, AstraleParams>>, dependencies: AstraleDependencies): import("@astrale-os/sdk/deployment/adapter").Adapter<AstraleParams>;
5
+ export type { AstraleDependencies } from './deploy/deploy-release.js';
6
+ /** Deploy one Project Environment as immutable deployments on Admin's Services. */
7
+ export declare function astrale(parameters?: AstraleParams): Deployment<AstraleParams, Adapter<AstraleParams>>;
8
+ export declare function astraleWithDependencies(parameters: AstraleParams, dependencies: AstraleDependencies): Deployment<AstraleParams, Adapter<AstraleParams>>;
package/dist/adapter.js CHANGED
@@ -1,276 +1,37 @@
1
- import { cloudflare } from '@astrale-os/adapter-cloudflare';
2
- import { signingIdentity, signingIdentitySecrets } from '@astrale-os/adapter-cloudflare/build';
3
- import { defineAdapter } from '@astrale-os/sdk/deployment/adapter';
4
- import { addressing, assemble } from '@astrale-os/sdk/deployment/release';
1
+ import { cloudflareWorkerBundler } from '@astrale-os/adapter-cloudflare/build';
2
+ import { defineAdapter, defineDeployment } from '@astrale-os/sdk/deployment/adapter';
5
3
  import { createRequire } from 'node:module';
6
- import { callAstrale, identityArguments, runAstrale } from './cli.js';
7
- import { ensureServices, ServicesPrerequisiteError } from './prerequisite.js';
8
- import { serviceName, servicePath, servicesDeployMethod } from './service/addressing.js';
9
- import { deploymentPayload } from './service/artifact.js';
10
- import { waitForReadiness } from './service/readiness.js';
11
- const SERVICES_ORIGIN = 'services.astrale.ai';
12
- const NONE = Object.freeze({ kind: 'none' });
4
+ import { admitAstraleParameters } from './admit.js';
5
+ import { callAdmin } from './cli/commands/call.js';
6
+ import { requireCliVersion } from './cli/commands/version.js';
7
+ import { resolveCliExecutable } from './cli/executable.js';
8
+ import { configureAstrale } from './configure.js';
9
+ import { deployAstraleRelease, placeAstrale } from './deploy/deploy-release.js';
10
+ import { listAstraleDeployments } from './deploy/list.js';
11
+ import { waitForReadiness } from './deploy/readiness.js';
13
12
  const packageVersion = createRequire(import.meta.url)('../package.json')
14
13
  .version;
15
- const local = cloudflare({ internal: {} });
16
- export function astrale(environments) {
17
- return astraleWithDependencies(environments, {
18
- prepare: (parameters, context) => local.prepare(cloudflareParameters(parameters, false), context),
19
- watch: (parameters, context) => local.watch(cloudflareParameters(parameters, true), context),
20
- ensureServices,
21
- callAstrale,
22
- runAstrale,
23
- waitForReadiness,
24
- signingIdentity,
14
+ /** Deploy one Project Environment as immutable deployments on Admin's Services. */
15
+ export function astrale(parameters = {}) {
16
+ return astraleWithDependencies(parameters, {
17
+ resolveCliExecutable,
18
+ requireCliVersion,
19
+ callAdmin,
20
+ waitForReadiness: (release, signal) => waitForReadiness(release, signal),
25
21
  });
26
22
  }
27
- export function astraleWithDependencies(environments, dependencies) {
28
- return defineAdapter({
23
+ export function astraleWithDependencies(parameters, dependencies) {
24
+ const adapter = defineAdapter({
29
25
  name: 'astrale',
30
26
  version: packageVersion,
31
- environments,
32
- prepare: dependencies.prepare,
33
- watch: dependencies.watch,
34
- async deploy(parameters, context) {
35
- if (parameters.instance === undefined) {
36
- return failed('prerequisite', progress(), new TypeError('Astrale deployment requires an instance.'));
37
- }
38
- let secrets;
39
- let signing;
40
- try {
41
- signing = await dependencies.signingIdentity({
42
- projectDir: context.projectDir,
43
- source: parameters.signingIdentity,
44
- origin: context.artifact.build.schema.compiled.root.origin,
45
- mode: 'deploy',
46
- });
47
- secrets = signingIdentitySecrets(context.secrets, signing);
48
- }
49
- catch (cause) {
50
- return failed('prerequisite', progress(), cause);
51
- }
52
- const instance = parameters.instance;
53
- const servicesOrigin = parameters.servicesOrigin ?? SERVICES_ORIGIN;
54
- const identity = identityArguments(parameters.identity);
55
- let prerequisite;
56
- try {
57
- const evidence = await dependencies.ensureServices({
58
- projectDir: context.projectDir,
59
- instance,
60
- servicesOrigin,
61
- identity,
62
- run: dependencies.runAstrale,
63
- });
64
- prerequisite =
65
- evidence.state === 'installed'
66
- ? Object.freeze({ kind: 'applied', evidence })
67
- : NONE;
68
- }
69
- catch (cause) {
70
- const prerequisite = cause instanceof ServicesPrerequisiteError && cause.mutation === 'installed'
71
- ? Object.freeze({
72
- kind: 'applied',
73
- evidence: Object.freeze({ origin: servicesOrigin, state: 'installed' }),
74
- })
75
- : cause instanceof ServicesPrerequisiteError && cause.mutation === 'unknown'
76
- ? Object.freeze({ kind: 'unknown' })
77
- : NONE;
78
- return failed('prerequisite', progress({ prerequisite }), cause);
79
- }
80
- const origin = context.artifact.build.schema.compiled.root.origin;
81
- const name = parameters.name ?? serviceName(origin);
82
- let payload;
83
- try {
84
- payload = deploymentPayload(context.artifact, { origin, name, vars: parameters.vars });
85
- }
86
- catch (cause) {
87
- return failed('provider', progress({ prerequisite }), cause);
88
- }
89
- let deployed;
90
- try {
91
- deployed = await dependencies.callAstrale({
92
- projectDir: context.projectDir,
93
- instance,
94
- path: servicesDeployMethod(servicesOrigin),
95
- identity,
96
- data: payload,
97
- });
98
- }
99
- catch (cause) {
100
- return failed('provider', progress({ prerequisite, provider: { kind: 'unknown' } }), cause);
101
- }
102
- const expectedPath = servicePath(origin);
103
- let observation;
104
- try {
105
- observation = deployedService(deployed, expectedPath);
106
- }
107
- catch (cause) {
108
- return failed('provider', progress({
109
- prerequisite,
110
- provider: { kind: 'partial' },
111
- }), cause);
112
- }
113
- const url = observation.url;
114
- const applied = Object.freeze({
115
- kind: 'applied',
116
- evidence: Object.freeze({
117
- provider: 'astrale',
118
- deployment: observation.digest,
119
- artifact: context.artifact.digest,
120
- }),
121
- });
122
- if (url === undefined) {
123
- return failed('addressing', progress({ prerequisite, provider: applied }), new Error('Astrale Services deployment returned no URL.'));
124
- }
125
- let selected;
126
- try {
127
- selected = addressing(url);
128
- }
129
- catch (cause) {
130
- return failed('addressing', progress({ prerequisite, provider: applied }), cause);
131
- }
132
- const provider = Object.freeze({
133
- kind: 'applied',
134
- evidence: Object.freeze({ ...applied.evidence, issuer: selected.issuer }),
135
- });
136
- let configuration = NONE;
137
- const secretNames = [signing.binding, ...Object.keys(context.secrets).sort()];
138
- const configured = [];
139
- if (secretNames.length > 0) {
140
- try {
141
- for (const secret of secretNames) {
142
- await dependencies.callAstrale({
143
- projectDir: context.projectDir,
144
- instance,
145
- path: `${servicePath(origin)}::setSecret`,
146
- identity,
147
- data: { name: secret, value: secrets[secret] },
148
- });
149
- configured.push(secret);
150
- }
151
- configuration = Object.freeze({
152
- kind: 'applied',
153
- evidence: Object.freeze({ names: secretNames }),
154
- });
155
- }
156
- catch (cause) {
157
- const configuration = configured.length === 0
158
- ? { kind: 'unknown' }
159
- : {
160
- kind: 'partial',
161
- evidence: Object.freeze({ names: Object.freeze([...configured]) }),
162
- };
163
- return failed('configuration', progress({ prerequisite, provider, configuration }), cause);
164
- }
165
- }
166
- let release;
167
- try {
168
- release = assemble(context.artifact.build, selected);
169
- }
170
- catch (cause) {
171
- return failed('release', progress({ prerequisite, provider, configuration }), cause);
172
- }
173
- try {
174
- await dependencies.waitForReadiness(release);
175
- }
176
- catch (cause) {
177
- return failed('readiness', progress({ prerequisite, provider, configuration }), cause, release);
178
- }
179
- let installation;
180
- try {
181
- await dependencies.runAstrale({
182
- projectDir: context.projectDir,
183
- input: [
184
- 'domain',
185
- 'install',
186
- url,
187
- '--direct',
188
- '-i',
189
- instance,
190
- '--allow-identity-override',
191
- '--json',
192
- '--timeout',
193
- '240000',
194
- ...identity,
195
- ],
196
- });
197
- installation = Object.freeze({
198
- kind: 'applied',
199
- evidence: Object.freeze({ instance, origin }),
200
- });
201
- }
202
- catch (cause) {
203
- return failed('installation', progress({ prerequisite, provider, configuration, installation: { kind: 'unknown' } }), cause, release);
204
- }
205
- return Object.freeze({
206
- status: 'ready',
207
- phase: 'complete',
208
- progress: Object.freeze({
209
- ...progress({ prerequisite, configuration, installation }),
210
- provider,
211
- }),
212
- release,
213
- });
214
- },
27
+ // Services hosts the same generated Worker: both adapters share one build.
28
+ bundler: cloudflareWorkerBundler,
29
+ admit: admitAstraleParameters,
30
+ configure: configureAstrale,
31
+ placement: (parameters, context) => placeAstrale(parameters, context, dependencies),
32
+ deployRelease: (parameters, context) => deployAstraleRelease(parameters, context, dependencies),
33
+ list: (parameters, context) => listAstraleDeployments(parameters, context, dependencies),
215
34
  secretsFile: (parameters) => parameters.secrets,
216
35
  });
217
- }
218
- function cloudflareParameters(parameters, watch) {
219
- return Object.freeze({
220
- ...(parameters.port === undefined ? {} : { port: parameters.port }),
221
- ...(watch && parameters.host !== undefined ? { host: parameters.host } : {}),
222
- ...(parameters.vars === undefined ? {} : { vars: parameters.vars }),
223
- ...(parameters.signingIdentity === undefined
224
- ? {}
225
- : { signingIdentity: parameters.signingIdentity }),
226
- });
227
- }
228
- function deployedService(input, expectedPath) {
229
- if (input === null || typeof input !== 'object' || Array.isArray(input))
230
- invalidDeployment();
231
- const value = input;
232
- if (value.error !== undefined && value.error !== null)
233
- invalidDeployment();
234
- if (value.state !== 'ready') {
235
- throw new TypeError('Astrale Services deployment did not report ready provider state.');
236
- }
237
- if (value.path !== expectedPath) {
238
- throw new TypeError('Astrale Services deployment returned a different Service path.');
239
- }
240
- if (typeof value.digest !== 'string' || value.digest.length === 0) {
241
- throw new TypeError('Astrale Services deployment returned an invalid provider digest.');
242
- }
243
- let url;
244
- if (typeof value.url === 'string') {
245
- try {
246
- url = new URL(value.url).href.replace(/\/$/u, '');
247
- }
248
- catch {
249
- // Addressing admission below retains the successful provider effect.
250
- }
251
- }
252
- return Object.freeze({
253
- ...(url === undefined ? {} : { url }),
254
- digest: value.digest,
255
- });
256
- }
257
- function invalidDeployment() {
258
- throw new TypeError('Astrale Services deployment returned invalid provider evidence.');
259
- }
260
- function progress(input = {}) {
261
- return Object.freeze({
262
- prerequisite: input.prerequisite ?? NONE,
263
- provider: input.provider ?? NONE,
264
- configuration: input.configuration ?? NONE,
265
- installation: input.installation ?? NONE,
266
- });
267
- }
268
- function failed(phase, deploymentProgress, cause, release) {
269
- return Object.freeze({
270
- status: 'failed',
271
- phase,
272
- progress: deploymentProgress,
273
- error: cause instanceof Error ? cause : new Error(String(cause)),
274
- ...(release === undefined ? {} : { release }),
275
- });
36
+ return defineDeployment(adapter, parameters);
276
37
  }
@@ -0,0 +1,7 @@
1
+ import type { AdapterEnvironmentContext } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { AstraleParams } from './params.js';
3
+ /**
4
+ * Refuse, when the Project loads, an Environment this adapter cannot deploy: an unknown or removed
5
+ * parameter or a malformed Admin bookmark.
6
+ */
7
+ export declare function admitAstraleParameters(parameters: AstraleParams, context: AdapterEnvironmentContext): void;
package/dist/admit.js ADDED
@@ -0,0 +1,44 @@
1
+ /** The parameters an Environment of this adapter declares. */
2
+ const PARAMETERS = Object.freeze([
3
+ 'admin',
4
+ 'secrets',
5
+ 'vars',
6
+ 'maximumRequestBytes',
7
+ 'tokenExchange',
8
+ 'durable',
9
+ ]);
10
+ /** The longest Admin bookmark name an Environment may name. */
11
+ const MAXIMUM_NAME_LENGTH = 256;
12
+ /**
13
+ * Refuse, when the Project loads, an Environment this adapter cannot deploy: an unknown or removed
14
+ * parameter or a malformed Admin bookmark.
15
+ */
16
+ export function admitAstraleParameters(parameters, context) {
17
+ const values = parameters;
18
+ // A parameter is declared when its value is not `undefined`, as optional parameters read.
19
+ const declared = Reflect.ownKeys(values).filter((key) => values[key] !== undefined);
20
+ const environment = `Astrale Environment ${context.environment}`;
21
+ const unknown = declared.filter((key) => !isOneOf(key, PARAMETERS));
22
+ if (unknown.length > 0) {
23
+ throw new TypeError(`${environment} declares unknown parameters ${names(unknown)}.`);
24
+ }
25
+ if (parameters.admin !== undefined &&
26
+ (!stable(parameters.admin, MAXIMUM_NAME_LENGTH) ||
27
+ parameters.admin.startsWith('-') ||
28
+ parameters.admin.includes('='))) {
29
+ throw new TypeError(`${environment} names an invalid admin: the name of an Admin bookmark of the astrale CLI.`);
30
+ }
31
+ }
32
+ /** A non-empty single token: no whitespace or control character, within `maximum` characters. */
33
+ function stable(value, maximum) {
34
+ return (typeof value === 'string' &&
35
+ value.length > 0 &&
36
+ value.length <= maximum &&
37
+ !/[\s\p{Cc}]/u.test(value));
38
+ }
39
+ function isOneOf(key, list) {
40
+ return typeof key === 'string' && list.includes(key);
41
+ }
42
+ function names(keys) {
43
+ return keys.map((key) => `\`${String(key)}\``).join(', ');
44
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Call one Domain Method on Admin's Kernel with `astrale call --admin` (CT21) and decode its JSON
3
+ * result. The input goes through stdin (`-d -`), never argv, since it can hold the Environment's
4
+ * secrets; `--admin=<bookmark>` keeps a bookmark from being read as a param.
5
+ */
6
+ export declare function callAdmin(input: {
7
+ readonly executable: string;
8
+ readonly projectDir: string;
9
+ /** The Admin bookmark; the CLI's configured Admin target when absent. */
10
+ readonly admin?: string;
11
+ readonly path: string;
12
+ readonly authority: readonly string[];
13
+ readonly data: unknown;
14
+ readonly signal: AbortSignal;
15
+ }): Promise<unknown>;
@@ -0,0 +1,36 @@
1
+ import { CliProcessError } from '../error.js';
2
+ import { decodeJson } from '../json.js';
3
+ import { runCliProcess } from '../process.js';
4
+ /** How long a call to Admin's Services may take, and the CLI process around it. */
5
+ const CALL_TIMEOUT_MS = 240_000;
6
+ const PROCESS_TIMEOUT_MS = 250_000;
7
+ /**
8
+ * Call one Domain Method on Admin's Kernel with `astrale call --admin` (CT21) and decode its JSON
9
+ * result. The input goes through stdin (`-d -`), never argv, since it can hold the Environment's
10
+ * secrets; `--admin=<bookmark>` keeps a bookmark from being read as a param.
11
+ */
12
+ export async function callAdmin(input) {
13
+ const result = await runCliProcess({
14
+ executable: input.executable,
15
+ projectDir: input.projectDir,
16
+ args: [
17
+ '--ci',
18
+ '--no-prompt',
19
+ 'call',
20
+ input.path,
21
+ input.admin === undefined ? '--admin' : `--admin=${input.admin}`,
22
+ '--json',
23
+ '--timeout',
24
+ String(CALL_TIMEOUT_MS),
25
+ ...input.authority,
26
+ '-d',
27
+ '-',
28
+ ],
29
+ stdin: JSON.stringify(input.data),
30
+ signal: input.signal,
31
+ timeoutMs: PROCESS_TIMEOUT_MS,
32
+ });
33
+ if (!result.ok)
34
+ throw new CliProcessError('command', `call ${input.path}`, result.failure);
35
+ return decodeJson(result.stdout, `astrale call ${input.path} success`);
36
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The first astrale CLI release whose `call` runs on the Admin kernel (`--admin`) and reads its
3
+ * input from stdin with `-d -` (CT21, cli#579), built on an SDK that reads an R1 Kernel's Schema
4
+ * introspection (cli#581): every deploy reaches Admin's Services that way. cli 1.0.0-beta.125
5
+ * carries neither.
6
+ */
7
+ export declare const MINIMUM_ASTRALE_CLI_VERSION = "1.0.0-beta.126";
8
+ export declare function requireCliVersion(input: {
9
+ readonly executable: string;
10
+ readonly projectDir: string;
11
+ readonly signal: AbortSignal;
12
+ }): Promise<string>;