@astrale-os/adapter-astrale 0.5.0-beta.21 → 0.5.0-beta.210
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/README.md +161 -2
- package/dist/adapter.d.ts +7 -16
- package/dist/adapter.js +27 -266
- package/dist/admit.d.ts +7 -0
- package/dist/admit.js +44 -0
- package/dist/cli/commands/call.d.ts +15 -0
- package/dist/cli/commands/call.js +36 -0
- package/dist/cli/commands/version.d.ts +12 -0
- package/dist/cli/commands/version.js +56 -0
- package/dist/cli/diagnostic.d.ts +6 -0
- package/dist/cli/diagnostic.js +28 -0
- package/dist/cli/error.d.ts +7 -0
- package/dist/cli/error.js +29 -0
- package/dist/cli/executable.d.ts +2 -0
- package/dist/cli/executable.js +54 -0
- package/dist/cli/identity.d.ts +5 -0
- package/dist/cli/identity.js +11 -0
- package/dist/cli/json.d.ts +2 -0
- package/dist/cli/json.js +39 -0
- package/dist/cli/process.d.ts +18 -0
- package/dist/cli/process.js +109 -0
- package/dist/configure.d.ts +17 -0
- package/dist/configure.js +40 -0
- package/dist/deploy/deploy-release.d.ts +30 -0
- package/dist/deploy/deploy-release.js +168 -0
- package/dist/deploy/list.d.ts +22 -0
- package/dist/deploy/list.js +63 -0
- package/dist/deploy/readiness.d.ts +17 -0
- package/dist/deploy/readiness.js +56 -0
- package/dist/index.d.ts +21 -10
- package/dist/index.js +21 -10
- package/dist/params.d.ts +25 -36
- package/dist/services/api.d.ts +35 -0
- package/dist/services/api.js +39 -0
- package/dist/services/client.d.ts +93 -0
- package/dist/services/client.js +116 -0
- package/dist/services/directory.d.ts +16 -0
- package/dist/services/directory.js +78 -0
- package/dist/services/index.d.ts +44 -0
- package/dist/services/index.js +27 -0
- package/dist/services/request.d.ts +25 -0
- package/dist/services/request.js +71 -0
- package/package.json +18 -11
- package/template/astrale.config.ts +27 -38
- package/dist/cli.d.ts +0 -15
- package/dist/cli.js +0 -48
- package/dist/prerequisite.d.ts +0 -19
- package/dist/prerequisite.js +0 -59
- package/dist/service/addressing.d.ts +0 -3
- package/dist/service/addressing.js +0 -16
- package/dist/service/artifact.d.ts +0 -34
- package/dist/service/artifact.js +0 -122
- package/dist/service/readiness.d.ts +0 -3
- package/dist/service/readiness.js +0 -16
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ListContext, ListedDeployment } from '@astrale-os/sdk/deployment/adapter';
|
|
2
|
+
import type { AstraleParams } from '../params.js';
|
|
3
|
+
import type { AstraleDependencies } from './deploy-release.js';
|
|
4
|
+
/**
|
|
5
|
+
* The deployments of one Environment's Service that Admin's Services keeps for the caller, who
|
|
6
|
+
* owns that Service or acts as its owner through `extends_with`, in Services' order: what Services
|
|
7
|
+
* knows of each one, the record it publishes (unadmitted: the listing admits it), whether the
|
|
8
|
+
* Service serves it, and where it and its Service are called on Admin's Kernel. Nothing changes:
|
|
9
|
+
* one `CloudflareService.list` call through `astrale call --admin`, for the project of the
|
|
10
|
+
* Domain's origin.
|
|
11
|
+
*
|
|
12
|
+
* Services keeps every deployment until it is retired and counts no call, so each one is listed as
|
|
13
|
+
* `published`, without a last call or an expiry, and a retiring or retired one as `withdrawn`: a
|
|
14
|
+
* retirement is always an operator's. Its Service's name is the line of its label.
|
|
15
|
+
*
|
|
16
|
+
* Each deployment and its Service are called by their nodes on the Admin instance this adapter
|
|
17
|
+
* deploys through, the `admin` bookmark when it names one: `astrale call
|
|
18
|
+
* "<callTarget.service>.method.setSecret" --admin` rewrites one secret of the deployment the
|
|
19
|
+
* Service serves, and `astrale call "<callTarget.path>.method.retire" --admin` retires this
|
|
20
|
+
* deployment alone.
|
|
21
|
+
*/
|
|
22
|
+
export declare function listAstraleDeployments(parameters: AstraleParams, context: ListContext, dependencies: AstraleDependencies): Promise<readonly ListedDeployment[]>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { decodeWorkerDeploymentList } from '@astrale-os/sdk/deployment/worker';
|
|
2
|
+
import { authorityArguments } from '../cli/identity.js';
|
|
3
|
+
import { deploymentCallPath, SERVICES_METHODS, serviceCallPath } from '../services/api.js';
|
|
4
|
+
import { requireAstraleCli, servicesSummary } from '../services/client.js';
|
|
5
|
+
import { listedRecord } from '../services/request.js';
|
|
6
|
+
/**
|
|
7
|
+
* The deployments of one Environment's Service that Admin's Services keeps for the caller, who
|
|
8
|
+
* owns that Service or acts as its owner through `extends_with`, in Services' order: what Services
|
|
9
|
+
* knows of each one, the record it publishes (unadmitted: the listing admits it), whether the
|
|
10
|
+
* Service serves it, and where it and its Service are called on Admin's Kernel. Nothing changes:
|
|
11
|
+
* one `CloudflareService.list` call through `astrale call --admin`, for the project of the
|
|
12
|
+
* Domain's origin.
|
|
13
|
+
*
|
|
14
|
+
* Services keeps every deployment until it is retired and counts no call, so each one is listed as
|
|
15
|
+
* `published`, without a last call or an expiry, and a retiring or retired one as `withdrawn`: a
|
|
16
|
+
* retirement is always an operator's. Its Service's name is the line of its label.
|
|
17
|
+
*
|
|
18
|
+
* Each deployment and its Service are called by their nodes on the Admin instance this adapter
|
|
19
|
+
* deploys through, the `admin` bookmark when it names one: `astrale call
|
|
20
|
+
* "<callTarget.service>.method.setSecret" --admin` rewrites one secret of the deployment the
|
|
21
|
+
* Service serves, and `astrale call "<callTarget.path>.method.retire" --admin` retires this
|
|
22
|
+
* deployment alone.
|
|
23
|
+
*/
|
|
24
|
+
export async function listAstraleDeployments(parameters, context, dependencies) {
|
|
25
|
+
// `astrale-domain` runs in its Project directory.
|
|
26
|
+
const projectDir = process.cwd();
|
|
27
|
+
const executable = await requireAstraleCli(projectDir, context.signal, dependencies);
|
|
28
|
+
const hosted = decodeWorkerDeploymentList(await dependencies.callAdmin({
|
|
29
|
+
executable,
|
|
30
|
+
projectDir,
|
|
31
|
+
...(parameters.admin === undefined ? {} : { admin: parameters.admin }),
|
|
32
|
+
path: SERVICES_METHODS.list,
|
|
33
|
+
authority: authorityArguments(context.identity === undefined ? {} : { identity: context.identity }),
|
|
34
|
+
data: { project: context.origin, environment: context.environment },
|
|
35
|
+
signal: context.signal,
|
|
36
|
+
}));
|
|
37
|
+
return Object.freeze(hosted.map((deployment) => listed(servicesSummary(deployment), parameters.admin)));
|
|
38
|
+
}
|
|
39
|
+
/** One deployment Services lists, as an adapter lists it (`ListedDeployment`). */
|
|
40
|
+
function listed(deployment, admin) {
|
|
41
|
+
const withdrawn = deployment.state === 'retiring' || deployment.state === 'retired';
|
|
42
|
+
return Object.freeze({
|
|
43
|
+
id: deployment.id,
|
|
44
|
+
url: deployment.url,
|
|
45
|
+
label: deployment.label,
|
|
46
|
+
line: deployment.service,
|
|
47
|
+
owner: deployment.owner,
|
|
48
|
+
state: deployment.state,
|
|
49
|
+
retention: 'published',
|
|
50
|
+
createdAt: deployment.createdAt,
|
|
51
|
+
...(deployment.retiredAt === undefined ? {} : { retiredAt: deployment.retiredAt }),
|
|
52
|
+
...(withdrawn ? { retirement: 'withdrawn' } : {}),
|
|
53
|
+
...(deployment.signingKeyId === undefined ? {} : { signingKeyId: deployment.signingKeyId }),
|
|
54
|
+
...listedRecord(deployment.record),
|
|
55
|
+
current: deployment.current,
|
|
56
|
+
callTarget: Object.freeze({
|
|
57
|
+
kind: 'services',
|
|
58
|
+
path: deploymentCallPath(deployment.id),
|
|
59
|
+
service: serviceCallPath(deployment.serviceId),
|
|
60
|
+
...(admin === undefined ? {} : { admin }),
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Release } from '@astrale-os/sdk/deployment/release';
|
|
2
|
+
import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
|
|
3
|
+
/**
|
|
4
|
+
* How long a deployment may take to serve its release at its URL. Its hostname sits under the
|
|
5
|
+
* Services wildcard route and certificate, so no certificate is issued for it; what remains is the
|
|
6
|
+
* dispatcher reading the deployment's activation record, which Workers KV propagates within about
|
|
7
|
+
* a minute. Keep the wait cancellable and bounded; never weaken HTTPS verification.
|
|
8
|
+
*/
|
|
9
|
+
export declare const READINESS_TIMEOUT_MS = 120000;
|
|
10
|
+
/** One readiness check of the release a deployment serves at its URL. */
|
|
11
|
+
export type ReadinessCheck = (release: Release, options: NonNullable<Parameters<typeof verifyReadiness>[1]>) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Wait until the deployment serves exactly its sealed release at its URL: its `release.json`
|
|
14
|
+
* (release digest and build digest), its Bundle and its issuer documents. The URL serves one
|
|
15
|
+
* release only, so a deployment that answers with it serves this build and nothing else.
|
|
16
|
+
*/
|
|
17
|
+
export declare function waitForReadiness(release: Release, signal: AbortSignal, verify?: ReadinessCheck): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
|
|
2
|
+
/**
|
|
3
|
+
* How long a deployment may take to serve its release at its URL. Its hostname sits under the
|
|
4
|
+
* Services wildcard route and certificate, so no certificate is issued for it; what remains is the
|
|
5
|
+
* dispatcher reading the deployment's activation record, which Workers KV propagates within about
|
|
6
|
+
* a minute. Keep the wait cancellable and bounded; never weaken HTTPS verification.
|
|
7
|
+
*/
|
|
8
|
+
export const READINESS_TIMEOUT_MS = 120_000;
|
|
9
|
+
const ATTEMPT_TIMEOUT_MS = 5_000;
|
|
10
|
+
const RETRY_DELAY_MS = 1_000;
|
|
11
|
+
/**
|
|
12
|
+
* Wait until the deployment serves exactly its sealed release at its URL: its `release.json`
|
|
13
|
+
* (release digest and build digest), its Bundle and its issuer documents. The URL serves one
|
|
14
|
+
* release only, so a deployment that answers with it serves this build and nothing else.
|
|
15
|
+
*/
|
|
16
|
+
export async function waitForReadiness(release, signal, verify = verifyReadiness) {
|
|
17
|
+
const deadline = Date.now() + READINESS_TIMEOUT_MS;
|
|
18
|
+
let last;
|
|
19
|
+
while (Date.now() < deadline) {
|
|
20
|
+
throwIfAborted(signal);
|
|
21
|
+
try {
|
|
22
|
+
await verify(release, {
|
|
23
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(ATTEMPT_TIMEOUT_MS)]),
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
catch (cause) {
|
|
28
|
+
throwIfAborted(signal);
|
|
29
|
+
last = cause;
|
|
30
|
+
await pause(signal);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw last instanceof Error ? last : new Error('The deployment did not serve its release.');
|
|
34
|
+
}
|
|
35
|
+
function pause(signal) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const timer = setTimeout(done, RETRY_DELAY_MS);
|
|
38
|
+
const abort = () => done(abortError(signal));
|
|
39
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
40
|
+
function done(cause) {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
signal.removeEventListener('abort', abort);
|
|
43
|
+
if (cause === undefined)
|
|
44
|
+
resolve();
|
|
45
|
+
else
|
|
46
|
+
reject(cause);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function throwIfAborted(signal) {
|
|
51
|
+
if (signal.aborted)
|
|
52
|
+
throw abortError(signal);
|
|
53
|
+
}
|
|
54
|
+
function abortError(signal) {
|
|
55
|
+
return signal.reason instanceof Error ? signal.reason : new Error('Deployment interrupted.');
|
|
56
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@astrale-os/adapter-astrale` — deploy an Astrale domain as
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* `@astrale-os/adapter-astrale` — deploy an Astrale domain as immutable deployments hosted by
|
|
3
|
+
* Admin's Services (no Cloudflare account, no wrangler auth, no key file: the only credential is
|
|
4
|
+
* your `astrale auth login` session).
|
|
5
5
|
*
|
|
6
6
|
* import { astrale } from '@astrale-os/adapter-astrale'
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* environments: {
|
|
9
|
+
* development: { deployment: astrale({ secrets: '.env.dev' }) },
|
|
10
|
+
* production: {
|
|
11
|
+
* deployment: astrale({ secrets: '.env.production' }),
|
|
12
|
+
* },
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* `astrale-domain deploy <environment>` builds locally and makes one immutable deployment per
|
|
16
|
+
* release of the Service of the Domain's origin and the Environment: its own script at its own
|
|
17
|
+
* URL, `https://<line>-<content>.<routingDomain>`, while the Service's stable URL,
|
|
18
|
+
* `https://<line>.<routingDomain>`, serves the deployment last promoted, by default the latest. It
|
|
19
|
+
* calls Admin's Services with `astrale call --admin` as the authenticated identity, never an
|
|
20
|
+
* instance, and never installs the Domain: `astrale domain install <url> -i <instance>`
|
|
21
|
+
* installs the URL it prints. A redeploy of the same release reuses its deployment and rewrites
|
|
22
|
+
* its secrets in place when the secrets file changed; no other deployment is ever touched.
|
|
12
23
|
*
|
|
13
24
|
* It builds the SAME Cloudflare Workers bundle the `cloudflare` adapter ships
|
|
14
|
-
* (via `@astrale-os/adapter-cloudflare/build`)
|
|
15
|
-
*
|
|
16
|
-
* For deploying to YOUR OWN Cloudflare account instead, use
|
|
25
|
+
* (via `@astrale-os/adapter-cloudflare/build`) and deploys it as Services deploys any Worker
|
|
26
|
+
* (`@astrale-os/sdk/deployment/worker`); `@astrale-os/adapter-astrale/services` deploys any other
|
|
27
|
+
* Worker the same way. For deploying to YOUR OWN Cloudflare account instead, use
|
|
17
28
|
* `@astrale-os/adapter-cloudflare`.
|
|
18
29
|
*/
|
|
19
30
|
export { astrale } from './adapter.js';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@astrale-os/adapter-astrale` — deploy an Astrale domain as
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* `@astrale-os/adapter-astrale` — deploy an Astrale domain as immutable deployments hosted by
|
|
3
|
+
* Admin's Services (no Cloudflare account, no wrangler auth, no key file: the only credential is
|
|
4
|
+
* your `astrale auth login` session).
|
|
5
5
|
*
|
|
6
6
|
* import { astrale } from '@astrale-os/adapter-astrale'
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* environments: {
|
|
9
|
+
* development: { deployment: astrale({ secrets: '.env.dev' }) },
|
|
10
|
+
* production: {
|
|
11
|
+
* deployment: astrale({ secrets: '.env.production' }),
|
|
12
|
+
* },
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* `astrale-domain deploy <environment>` builds locally and makes one immutable deployment per
|
|
16
|
+
* release of the Service of the Domain's origin and the Environment: its own script at its own
|
|
17
|
+
* URL, `https://<line>-<content>.<routingDomain>`, while the Service's stable URL,
|
|
18
|
+
* `https://<line>.<routingDomain>`, serves the deployment last promoted, by default the latest. It
|
|
19
|
+
* calls Admin's Services with `astrale call --admin` as the authenticated identity, never an
|
|
20
|
+
* instance, and never installs the Domain: `astrale domain install <url> -i <instance>`
|
|
21
|
+
* installs the URL it prints. A redeploy of the same release reuses its deployment and rewrites
|
|
22
|
+
* its secrets in place when the secrets file changed; no other deployment is ever touched.
|
|
12
23
|
*
|
|
13
24
|
* It builds the SAME Cloudflare Workers bundle the `cloudflare` adapter ships
|
|
14
|
-
* (via `@astrale-os/adapter-cloudflare/build`)
|
|
15
|
-
*
|
|
16
|
-
* For deploying to YOUR OWN Cloudflare account instead, use
|
|
25
|
+
* (via `@astrale-os/adapter-cloudflare/build`) and deploys it as Services deploys any Worker
|
|
26
|
+
* (`@astrale-os/sdk/deployment/worker`); `@astrale-os/adapter-astrale/services` deploys any other
|
|
27
|
+
* Worker the same way. For deploying to YOUR OWN Cloudflare account instead, use
|
|
17
28
|
* `@astrale-os/adapter-cloudflare`.
|
|
18
29
|
*/
|
|
19
30
|
export { astrale } from './adapter.js';
|
package/dist/params.d.ts
CHANGED
|
@@ -1,51 +1,40 @@
|
|
|
1
|
+
import type { DurableWorkerOptions } from '@astrale-os/adapter-cloudflare';
|
|
2
|
+
import type { ExchangeOptions } from '@astrale-os/sdk/execution';
|
|
1
3
|
/**
|
|
2
4
|
* `AstraleParams` — the provider-typed config for the Astrale-managed adapter.
|
|
3
5
|
*
|
|
4
|
-
* One
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* installs it — so `instance` is required for `deploy`, ignored by `watch`.
|
|
11
|
-
* Frontend source, routes, and build ownership live on the authored Application;
|
|
12
|
-
* adapter environments select delivery only.
|
|
6
|
+
* One value configures one Project Environment. `deploy` makes one immutable deployment per
|
|
7
|
+
* release of the Service of the Environment's origin and name on Admin's Services, and
|
|
8
|
+
* never installs the Domain: `astrale domain install <url>` installs the URL it prints. Each
|
|
9
|
+
* deployment is its own issuer at its own URL, with a signing key Services generates for it; there
|
|
10
|
+
* is no key file to keep. Frontend source, routes, and build ownership live on the authored
|
|
11
|
+
* Domain; adapter environments select delivery only.
|
|
13
12
|
*/
|
|
14
13
|
export interface AstraleParams {
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* (local dev) — so dev-only envs may omit it.
|
|
15
|
+
* The Admin bookmark `astrale call --admin` reaches Admin's Services through. Default: the Admin
|
|
16
|
+
* target the astrale CLI is configured with.
|
|
19
17
|
*/
|
|
20
|
-
readonly
|
|
21
|
-
/** Service name on the platform. Default: the origin's first DNS label. */
|
|
22
|
-
readonly name?: string;
|
|
18
|
+
readonly admin?: string;
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
20
|
+
* Gitignored secrets file loaded by SDK tooling. A new deployment binds its current values; a
|
|
21
|
+
* redeploy of the same release rewrites them in place on that deployment only.
|
|
26
22
|
*/
|
|
27
|
-
readonly servicesOrigin?: string;
|
|
28
|
-
/** CLI identity (`--as`) for the deploy/install calls. Default: the CLI's active identity. */
|
|
29
|
-
readonly identity?: string;
|
|
30
|
-
/** Gitignored secrets file loaded by SDK tooling and applied through the provider boundary. */
|
|
31
23
|
readonly secrets?: string;
|
|
24
|
+
/** Plain variables frozen into each deployment: another value is another deployment. */
|
|
25
|
+
readonly vars?: Readonly<Record<string, string>>;
|
|
26
|
+
/** Maximum encoded invocation request bytes retained by the generated Worker Server. */
|
|
27
|
+
readonly maximumRequestBytes?: number;
|
|
32
28
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `.astrale/identity.json` when omitted.
|
|
29
|
+
* Configure the caller-only managed Domain token exchange lifetime, or disable exchange.
|
|
30
|
+
* The default maximum is 30 minutes; production and CI environments may select a shorter bound.
|
|
36
31
|
*/
|
|
37
|
-
readonly
|
|
38
|
-
/** Local dev port for `wrangler dev`. Default 8787. */
|
|
39
|
-
readonly port?: number;
|
|
32
|
+
readonly tokenExchange?: ExchangeOptions | false;
|
|
40
33
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* identity (`iss`) doesn't drift to the proxy's internal hostname.
|
|
46
|
-
* Usually injected by `pnpm dev --host <url>` rather than written here.
|
|
34
|
+
* What a Worker serving durable Workflows declares to the workflow engine: run retention, retry
|
|
35
|
+
* before pausing and the deadline of each Step. Frozen into each deployment's configuration
|
|
36
|
+
* (`settings.durableOptions`, CT16), so another value is another deployment (AM-175). Canonical
|
|
37
|
+
* callbacks discover engine keys from their Kernel.
|
|
47
38
|
*/
|
|
48
|
-
readonly
|
|
49
|
-
/** Extra plain vars for local `watch`. */
|
|
50
|
-
readonly vars?: Readonly<Record<string, string>>;
|
|
39
|
+
readonly durable?: DurableWorkerOptions;
|
|
51
40
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The Services Domain origin, as Admin's Kernel names its installation (not a network host). */
|
|
2
|
+
export declare const SERVICES_ORIGIN = "services.astrale.ai";
|
|
3
|
+
/**
|
|
4
|
+
* The Services class whose nodes are the Services Admin's Services hosts: one per project and
|
|
5
|
+
* environment, named by the opaque fingerprint of the two, whose stable URL serves its current
|
|
6
|
+
* deployment. A Domain's project is its origin.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SERVICE_CLASS = "services.astrale.ai:class.CloudflareService";
|
|
9
|
+
/** The Services class whose nodes are the immutable deployments of those Services. */
|
|
10
|
+
export declare const DEPLOYMENT_CLASS = "services.astrale.ai:class.CloudflareDeployment";
|
|
11
|
+
/**
|
|
12
|
+
* The static `CloudflareService` Methods of Admin's Services this package calls: `hosting` reads
|
|
13
|
+
* where Services and deployments are addressed, `deploy` creates or reuses one deployment of the
|
|
14
|
+
* Service of its project and environment (creating that Service on its first deploy) from a
|
|
15
|
+
* `WorkerDeploymentRequestV1`, and `list` reads the deployments of the Services the caller owns.
|
|
16
|
+
* They run on Admin's Kernel through `astrale call --admin` (CT21).
|
|
17
|
+
*/
|
|
18
|
+
export declare const SERVICES_METHODS: Readonly<{
|
|
19
|
+
hosting: "/:services.astrale.ai:class.CloudflareService:hosting";
|
|
20
|
+
deploy: "/:services.astrale.ai:class.CloudflareService:deploy";
|
|
21
|
+
list: "/:services.astrale.ai:class.CloudflareService:list";
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Where one hosted Service is called on Admin's Kernel: its node, `@<serviceId>`, qualified by its
|
|
25
|
+
* class. Its instance Methods act on the Service and its current deployment:
|
|
26
|
+
* `astrale call "<path>.method.setSecret" --admin` rewrites one secret of the deployment the
|
|
27
|
+
* Service serves, and `promote`, `transfer`, `secrets`, `setSchedule`, `schedules`, `logs` and
|
|
28
|
+
* `delete` are called the same way.
|
|
29
|
+
*/
|
|
30
|
+
export declare function serviceCallPath(serviceId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Where one hosted deployment is called on Admin's Kernel: its node, `@<id>`, qualified by its
|
|
33
|
+
* class, whose only instance Method is `retire`, the emergency stop of that deployment alone.
|
|
34
|
+
*/
|
|
35
|
+
export declare function deploymentCallPath(id: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** The Services Domain origin, as Admin's Kernel names its installation (not a network host). */
|
|
2
|
+
export const SERVICES_ORIGIN = 'services.astrale.ai';
|
|
3
|
+
/**
|
|
4
|
+
* The Services class whose nodes are the Services Admin's Services hosts: one per project and
|
|
5
|
+
* environment, named by the opaque fingerprint of the two, whose stable URL serves its current
|
|
6
|
+
* deployment. A Domain's project is its origin.
|
|
7
|
+
*/
|
|
8
|
+
export const SERVICE_CLASS = `${SERVICES_ORIGIN}:class.CloudflareService`;
|
|
9
|
+
/** The Services class whose nodes are the immutable deployments of those Services. */
|
|
10
|
+
export const DEPLOYMENT_CLASS = `${SERVICES_ORIGIN}:class.CloudflareDeployment`;
|
|
11
|
+
/**
|
|
12
|
+
* The static `CloudflareService` Methods of Admin's Services this package calls: `hosting` reads
|
|
13
|
+
* where Services and deployments are addressed, `deploy` creates or reuses one deployment of the
|
|
14
|
+
* Service of its project and environment (creating that Service on its first deploy) from a
|
|
15
|
+
* `WorkerDeploymentRequestV1`, and `list` reads the deployments of the Services the caller owns.
|
|
16
|
+
* They run on Admin's Kernel through `astrale call --admin` (CT21).
|
|
17
|
+
*/
|
|
18
|
+
export const SERVICES_METHODS = Object.freeze({
|
|
19
|
+
hosting: `/:${SERVICE_CLASS}:hosting`,
|
|
20
|
+
deploy: `/:${SERVICE_CLASS}:deploy`,
|
|
21
|
+
list: `/:${SERVICE_CLASS}:list`,
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Where one hosted Service is called on Admin's Kernel: its node, `@<serviceId>`, qualified by its
|
|
25
|
+
* class. Its instance Methods act on the Service and its current deployment:
|
|
26
|
+
* `astrale call "<path>.method.setSecret" --admin` rewrites one secret of the deployment the
|
|
27
|
+
* Service serves, and `promote`, `transfer`, `secrets`, `setSchedule`, `schedules`, `logs` and
|
|
28
|
+
* `delete` are called the same way.
|
|
29
|
+
*/
|
|
30
|
+
export function serviceCallPath(serviceId) {
|
|
31
|
+
return `@${serviceId}::${SERVICE_CLASS}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Where one hosted deployment is called on Admin's Kernel: its node, `@<id>`, qualified by its
|
|
35
|
+
* class, whose only instance Method is `retire`, the emergency stop of that deployment alone.
|
|
36
|
+
*/
|
|
37
|
+
export function deploymentCallPath(id) {
|
|
38
|
+
return `@${id}::${DEPLOYMENT_CLASS}`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { WorkerCode, WorkerConfigurationInput, WorkerConfigurationV1, WorkerDeploymentListRequestV1, WorkerDeploymentRejectionReason, WorkerDeploymentResult, WorkerDeploymentSummary, WorkerHostingV1, WorkerRecord } from '@astrale-os/sdk/deployment/worker';
|
|
2
|
+
import type { callAdmin } from '../cli/commands/call.js';
|
|
3
|
+
import type { requireCliVersion } from '../cli/commands/version.js';
|
|
4
|
+
import type { resolveCliExecutable } from '../cli/executable.js';
|
|
5
|
+
/** The astrale CLI effects a Services client has, replaceable in tests. */
|
|
6
|
+
export interface ServicesDependencies {
|
|
7
|
+
readonly resolveCliExecutable: typeof resolveCliExecutable;
|
|
8
|
+
readonly requireCliVersion: typeof requireCliVersion;
|
|
9
|
+
readonly callAdmin: typeof callAdmin;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* How a call reaches Admin's Services: through the astrale CLI (`astrale call --admin`), as the
|
|
13
|
+
* CLI's authenticated identity, one it acts as (`identity`, `--as`) or a credential (`--creds`).
|
|
14
|
+
*/
|
|
15
|
+
export interface ServicesOptions {
|
|
16
|
+
/** The Admin bookmark of the astrale CLI; its configured Admin target when absent. */
|
|
17
|
+
readonly admin?: string;
|
|
18
|
+
/** The Identity to act as (`--as`); never with `credential`. */
|
|
19
|
+
readonly identity?: string;
|
|
20
|
+
/** A credential to call with (`--creds`); never with `identity`. */
|
|
21
|
+
readonly credential?: string;
|
|
22
|
+
/** Where the astrale CLI runs; the current directory when absent. */
|
|
23
|
+
readonly directory?: string;
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** One Worker to deploy as a deployment of the Service of its project and environment. */
|
|
27
|
+
export interface WorkerDeploy {
|
|
28
|
+
/** Any project name (`PROJECT_NAME`): the Service is named by it and the environment. */
|
|
29
|
+
readonly project: string;
|
|
30
|
+
readonly environment: string;
|
|
31
|
+
readonly worker: WorkerCode;
|
|
32
|
+
/**
|
|
33
|
+
* Its configuration, or what it freezes: the secret names default to the names of `secrets`,
|
|
34
|
+
* and `record` to whether a record is given.
|
|
35
|
+
*/
|
|
36
|
+
readonly configuration: WorkerConfigurationV1 | WorkerConfigurationInput;
|
|
37
|
+
/** Secret values, bound to a new deployment or rewritten in place on the reused one. */
|
|
38
|
+
readonly secrets?: Readonly<Record<string, string>>;
|
|
39
|
+
/** A record Services serves verbatim at `/.well-known/astrale/deployment.json`. */
|
|
40
|
+
readonly record?: WorkerRecord;
|
|
41
|
+
/**
|
|
42
|
+
* Paths that must answer 200 with `x-astrale-worker-version` (the `id` of the
|
|
43
|
+
* `ASTRALE_VERSION_METADATA` binding) before the deployment is activated.
|
|
44
|
+
*/
|
|
45
|
+
readonly readiness?: readonly string[];
|
|
46
|
+
/** The Identity owning a Service this deploy creates; the caller when absent. */
|
|
47
|
+
readonly owner?: string;
|
|
48
|
+
/** Whether the Service serves the deployment once it is active; `true` when absent. */
|
|
49
|
+
readonly promote?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** What a deploy made: its deployment, `created` or `reused`, and what it did to its secrets. */
|
|
52
|
+
export type WorkerDeployed = Extract<WorkerDeploymentResult, {
|
|
53
|
+
readonly kind: 'deployed';
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Why Admin's Services refused a deploy. A refusal changed nothing, except that a
|
|
57
|
+
* `service-unavailable` may follow effects: rerunning the same deploy converges.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ServicesRefusal extends Error {
|
|
60
|
+
readonly reason: WorkerDeploymentRejectionReason;
|
|
61
|
+
readonly retryAfter?: string | undefined;
|
|
62
|
+
readonly name = "ServicesRefusal";
|
|
63
|
+
constructor(reason: WorkerDeploymentRejectionReason, message: string, retryAfter?: string | undefined);
|
|
64
|
+
}
|
|
65
|
+
/** The Services client over these astrale CLI effects. */
|
|
66
|
+
export declare function servicesClient(dependencies: ServicesDependencies): Readonly<{
|
|
67
|
+
/** Where Admin's Services addresses Services and deployments. Changes nothing. */
|
|
68
|
+
hosting(options?: ServicesOptions): Promise<WorkerHostingV1>;
|
|
69
|
+
/**
|
|
70
|
+
* Deploy one Worker: one non-durable `CloudflareService.deploy` call, its secrets never
|
|
71
|
+
* journaled. The same code and configuration in the same Service reuse their deployment; a
|
|
72
|
+
* refusal throws a `ServicesRefusal`.
|
|
73
|
+
*/
|
|
74
|
+
deploy(input: WorkerDeploy, options?: ServicesOptions): Promise<WorkerDeployed>;
|
|
75
|
+
/** The deployments of the caller's Services, of one project or environment when given. */
|
|
76
|
+
list(filter?: WorkerDeploymentListRequestV1, options?: ServicesOptions): Promise<readonly WorkerDeploymentSummary[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Call one Method of a Service the caller owns, by the Service's node id: `promote`
|
|
79
|
+
* (`{ label }`), `setSecret` (`{ name, value }`), `secrets`, `setSchedule` (`{ crons }`),
|
|
80
|
+
* `schedules`, `logs`, `transfer` (`{ owner }`) or `delete`. Answers its JSON result.
|
|
81
|
+
*/
|
|
82
|
+
callService(serviceId: string, method: string, data?: unknown, options?: ServicesOptions): Promise<unknown>;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* A summary Admin's Services answers, its ids admitted as the Kernel node ids its Methods are
|
|
86
|
+
* called by (`serviceCallPath`, `deploymentCallPath`).
|
|
87
|
+
*/
|
|
88
|
+
export declare function servicesSummary<Summary extends {
|
|
89
|
+
readonly id: string;
|
|
90
|
+
readonly serviceId: string;
|
|
91
|
+
}>(summary: Summary): Summary;
|
|
92
|
+
/** Resolve the astrale CLI once per operation and require the release that serves `call --admin`. */
|
|
93
|
+
export declare function requireAstraleCli(projectDir: string, signal: AbortSignal, dependencies: Pick<ServicesDependencies, 'resolveCliExecutable' | 'requireCliVersion'>): Promise<string>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { decodeWorkerDeploymentList, decodeWorkerDeploymentResponse, decodeWorkerHosting, encodeWorkerDeploymentRequest, isWorkerConfiguration, workerConfiguration, } from '@astrale-os/sdk/deployment/worker';
|
|
2
|
+
import { isNodeId } from '@astrale-os/sdk/graph/node';
|
|
3
|
+
import { authorityArguments } from '../cli/identity.js';
|
|
4
|
+
import { SERVICES_METHODS, serviceCallPath } from './api.js';
|
|
5
|
+
/**
|
|
6
|
+
* Why Admin's Services refused a deploy. A refusal changed nothing, except that a
|
|
7
|
+
* `service-unavailable` may follow effects: rerunning the same deploy converges.
|
|
8
|
+
*/
|
|
9
|
+
export class ServicesRefusal extends Error {
|
|
10
|
+
reason;
|
|
11
|
+
retryAfter;
|
|
12
|
+
name = 'ServicesRefusal';
|
|
13
|
+
constructor(reason, message, retryAfter) {
|
|
14
|
+
super(`Admin Services refused the deployment (${reason}): ${message}` +
|
|
15
|
+
(retryAfter === undefined ? '' : ` Retry after ${retryAfter}.`));
|
|
16
|
+
this.reason = reason;
|
|
17
|
+
this.retryAfter = retryAfter;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The Services client over these astrale CLI effects. */
|
|
21
|
+
export function servicesClient(dependencies) {
|
|
22
|
+
/** Resolve the astrale CLI once per call and require the release that serves `call --admin`. */
|
|
23
|
+
const call = async (path, data, options) => {
|
|
24
|
+
const projectDir = options.directory ?? process.cwd();
|
|
25
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
26
|
+
const authority = authorityArguments({
|
|
27
|
+
...(options.identity === undefined ? {} : { identity: options.identity }),
|
|
28
|
+
...(options.credential === undefined ? {} : { credential: options.credential }),
|
|
29
|
+
});
|
|
30
|
+
const executable = await requireAstraleCli(projectDir, signal, dependencies);
|
|
31
|
+
return dependencies.callAdmin({
|
|
32
|
+
executable,
|
|
33
|
+
projectDir,
|
|
34
|
+
...(options.admin === undefined ? {} : { admin: options.admin }),
|
|
35
|
+
path,
|
|
36
|
+
authority,
|
|
37
|
+
data,
|
|
38
|
+
signal,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return Object.freeze({
|
|
42
|
+
/** Where Admin's Services addresses Services and deployments. Changes nothing. */
|
|
43
|
+
async hosting(options = {}) {
|
|
44
|
+
return decodeWorkerHosting(await call(SERVICES_METHODS.hosting, {}, options));
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Deploy one Worker: one non-durable `CloudflareService.deploy` call, its secrets never
|
|
48
|
+
* journaled. The same code and configuration in the same Service reuse their deployment; a
|
|
49
|
+
* refusal throws a `ServicesRefusal`.
|
|
50
|
+
*/
|
|
51
|
+
async deploy(input, options = {}) {
|
|
52
|
+
const secrets = input.secrets ?? {};
|
|
53
|
+
const configuration = isWorkerConfiguration(input.configuration)
|
|
54
|
+
? input.configuration
|
|
55
|
+
: workerConfiguration({
|
|
56
|
+
secrets: Object.keys(secrets),
|
|
57
|
+
record: input.record !== undefined,
|
|
58
|
+
...input.configuration,
|
|
59
|
+
});
|
|
60
|
+
const request = await encodeWorkerDeploymentRequest({
|
|
61
|
+
project: input.project,
|
|
62
|
+
environment: input.environment,
|
|
63
|
+
worker: input.worker,
|
|
64
|
+
configuration,
|
|
65
|
+
secrets,
|
|
66
|
+
...(input.record === undefined ? {} : { record: input.record }),
|
|
67
|
+
...(input.readiness === undefined ? {} : { readiness: input.readiness }),
|
|
68
|
+
...(input.owner === undefined ? {} : { owner: input.owner }),
|
|
69
|
+
...(input.promote === undefined ? {} : { promote: input.promote }),
|
|
70
|
+
});
|
|
71
|
+
const response = decodeWorkerDeploymentResponse(await call(SERVICES_METHODS.deploy, request, options));
|
|
72
|
+
if (response.kind === 'rejected') {
|
|
73
|
+
throw new ServicesRefusal(response.reason, response.message, response.retryAfter);
|
|
74
|
+
}
|
|
75
|
+
if (servicesSummary(response.deployment).label !== request.label) {
|
|
76
|
+
throw new TypeError(`Admin Services answered with deployment ${response.deployment.label}, not ${request.label}.`);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
},
|
|
80
|
+
/** The deployments of the caller's Services, of one project or environment when given. */
|
|
81
|
+
async list(filter = {}, options = {}) {
|
|
82
|
+
return Object.freeze(decodeWorkerDeploymentList(await call(SERVICES_METHODS.list, filter, options)).map(servicesSummary));
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Call one Method of a Service the caller owns, by the Service's node id: `promote`
|
|
86
|
+
* (`{ label }`), `setSecret` (`{ name, value }`), `secrets`, `setSchedule` (`{ crons }`),
|
|
87
|
+
* `schedules`, `logs`, `transfer` (`{ owner }`) or `delete`. Answers its JSON result.
|
|
88
|
+
*/
|
|
89
|
+
async callService(serviceId, method, data = {}, options = {}) {
|
|
90
|
+
if (!isNodeId(serviceId))
|
|
91
|
+
throw new TypeError('A Service is called by its node id.');
|
|
92
|
+
if (!/^[A-Za-z][A-Za-z0-9_]{0,127}$/u.test(method)) {
|
|
93
|
+
throw new TypeError('A Service Method is named by its member name.');
|
|
94
|
+
}
|
|
95
|
+
return call(`${serviceCallPath(serviceId)}.method.${method}`, data, options);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A summary Admin's Services answers, its ids admitted as the Kernel node ids its Methods are
|
|
101
|
+
* called by (`serviceCallPath`, `deploymentCallPath`).
|
|
102
|
+
*/
|
|
103
|
+
export function servicesSummary(summary) {
|
|
104
|
+
for (const member of ['id', 'serviceId']) {
|
|
105
|
+
if (!isNodeId(summary[member])) {
|
|
106
|
+
throw new TypeError(`Admin Services returned an invalid deployment answer (${member}).`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return summary;
|
|
110
|
+
}
|
|
111
|
+
/** Resolve the astrale CLI once per operation and require the release that serves `call --admin`. */
|
|
112
|
+
export async function requireAstraleCli(projectDir, signal, dependencies) {
|
|
113
|
+
const executable = await dependencies.resolveCliExecutable();
|
|
114
|
+
await dependencies.requireCliVersion({ executable, projectDir, signal });
|
|
115
|
+
return executable;
|
|
116
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WorkerBuildManifest, WorkerCode } from '@astrale-os/sdk/deployment/worker';
|
|
2
|
+
/**
|
|
3
|
+
* Read one built Worker from disk: every file of `directory` is a module, named by its path
|
|
4
|
+
* relative to it (`/`-separated) and loaded by its extension (`.js` and `.mjs` as ES modules,
|
|
5
|
+
* `.wasm`, `.txt`, `.html` and `.sql` as their kind, `.bin` as data); source maps are left out, and
|
|
6
|
+
* any other file is refused. Every file of `assets`, when given, is a static asset served at its
|
|
7
|
+
* path relative to it. The code is admitted as Admin's Services admits it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readWorkerDirectory(directory: string, options: {
|
|
10
|
+
/** The module the Worker starts from, by its name relative to `directory`. */
|
|
11
|
+
readonly mainModule: string;
|
|
12
|
+
/** A directory of static assets the Worker serves through `ASSETS`. */
|
|
13
|
+
readonly assets?: string;
|
|
14
|
+
/** The build manifest members the Worker is identified by; `WORKER_BUILD_MANIFEST` by default. */
|
|
15
|
+
readonly manifest?: WorkerBuildManifest;
|
|
16
|
+
}): Promise<WorkerCode>;
|