@astrale-os/sdk 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/bin.d.ts +7 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +15 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/dotenv.d.ts +13 -0
- package/dist/cli/dotenv.d.ts.map +1 -0
- package/dist/cli/dotenv.js +46 -0
- package/dist/cli/dotenv.js.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/run.d.ts +79 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +569 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/spec.d.ts +19 -0
- package/dist/cli/spec.d.ts.map +1 -0
- package/dist/cli/spec.js +31 -0
- package/dist/cli/spec.js.map +1 -0
- package/dist/config/adapter.d.ts +140 -0
- package/dist/config/adapter.d.ts.map +1 -0
- package/dist/config/adapter.js +40 -0
- package/dist/config/adapter.js.map +1 -0
- package/dist/config/define-domain.d.ts +112 -0
- package/dist/config/define-domain.d.ts.map +1 -0
- package/dist/config/define-domain.js +98 -0
- package/dist/config/define-domain.js.map +1 -0
- package/dist/config/deploy.d.ts +28 -0
- package/dist/config/deploy.d.ts.map +1 -0
- package/dist/config/deploy.js +24 -0
- package/dist/config/deploy.js.map +1 -0
- package/dist/config/index.d.ts +21 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +18 -0
- package/dist/config/index.js.map +1 -0
- package/dist/define/remote-function.d.ts +19 -11
- package/dist/define/remote-function.d.ts.map +1 -1
- package/dist/define/remote-function.js.map +1 -1
- package/dist/dispatch/call-remote.d.ts +7 -3
- package/dist/dispatch/call-remote.d.ts.map +1 -1
- package/dist/dispatch/call-remote.js.map +1 -1
- package/dist/dispatch/dispatcher.d.ts.map +1 -1
- package/dist/dispatch/dispatcher.js +8 -4
- package/dist/dispatch/dispatcher.js.map +1 -1
- package/dist/dispatch/index.d.ts +1 -1
- package/dist/dispatch/index.d.ts.map +1 -1
- package/dist/dispatch/index.js.map +1 -1
- package/dist/dispatch/self.d.ts +46 -10
- package/dist/dispatch/self.d.ts.map +1 -1
- package/dist/dispatch/self.js +65 -8
- package/dist/dispatch/self.js.map +1 -1
- package/dist/domain/define.d.ts +3 -3
- package/dist/domain/define.js +3 -3
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/method/class.d.ts.map +1 -1
- package/dist/method/class.js.map +1 -1
- package/dist/method/context.d.ts +32 -7
- package/dist/method/context.d.ts.map +1 -1
- package/dist/method/index.d.ts +1 -1
- package/dist/method/index.d.ts.map +1 -1
- package/dist/method/single.d.ts +16 -11
- package/dist/method/single.d.ts.map +1 -1
- package/dist/method/single.js.map +1 -1
- package/dist/server/domain-entry.d.ts +67 -0
- package/dist/server/domain-entry.d.ts.map +1 -0
- package/dist/server/domain-entry.js +58 -0
- package/dist/server/domain-entry.js.map +1 -0
- package/dist/server/index.d.ts +3 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/worker-entry.d.ts +40 -5
- package/dist/server/worker-entry.d.ts.map +1 -1
- package/dist/server/worker-entry.js +68 -19
- package/dist/server/worker-entry.js.map +1 -1
- package/package.json +12 -3
- package/src/cli/bin.ts +15 -0
- package/src/cli/dotenv.ts +45 -0
- package/src/cli/index.ts +15 -0
- package/src/cli/run.ts +675 -0
- package/src/cli/spec.ts +42 -0
- package/src/config/adapter.ts +172 -0
- package/src/config/define-domain.ts +218 -0
- package/src/config/deploy.ts +35 -0
- package/src/config/index.ts +31 -0
- package/src/define/remote-function.ts +42 -13
- package/src/dispatch/call-remote.ts +7 -2
- package/src/dispatch/dispatcher.ts +8 -4
- package/src/dispatch/index.ts +1 -1
- package/src/dispatch/self.ts +96 -10
- package/src/domain/define.ts +3 -3
- package/src/index.ts +25 -4
- package/src/method/class.ts +4 -3
- package/src/method/context.ts +38 -7
- package/src/method/index.ts +1 -1
- package/src/method/single.ts +30 -11
- package/src/server/domain-entry.ts +113 -0
- package/src/server/index.ts +3 -1
- package/src/server/worker-entry.ts +80 -20
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `domainWorkerEntry` — the one-call worker entry for a standalone domain.
|
|
3
|
+
*
|
|
4
|
+
* It folds the three steps every hand-rolled worker used to wire by hand —
|
|
5
|
+
* compile the runtime domain (`defineRemoteDomain`), build the server
|
|
6
|
+
* (`createRemoteServer`), and wrap it in the shared fetch plumbing
|
|
7
|
+
* (`createWorkerEntry`) — into a single declaration. The author passes the raw
|
|
8
|
+
* modules (`schema` / `methods` / `views` / `functions`) plus the identity and
|
|
9
|
+
* deploy bits; the helper does the rest. This is what the cloudflare adapter's
|
|
10
|
+
* codegen emits, and the recommended surface for a hand-rolled worker.
|
|
11
|
+
*
|
|
12
|
+
* Drop down to `createWorkerEntry` + `defineRemoteDomain` (from
|
|
13
|
+
* `@astrale-os/sdk/domain`) only when the worker needs something this config
|
|
14
|
+
* can't express — e.g. a serving-URL-dependent domain build (views stamped with
|
|
15
|
+
* the live url) or a globally-injected signing key resolved per request.
|
|
16
|
+
*/
|
|
17
|
+
import type { Core, Schema } from '@astrale-os/kernel-dsl';
|
|
18
|
+
import type { Hono } from 'hono';
|
|
19
|
+
import type { AnyRemoteFunctionDef, ViewDef } from '../define';
|
|
20
|
+
import type { SchemaMethodsImpl } from '../method';
|
|
21
|
+
import type { RemoteServerConfig } from './config';
|
|
22
|
+
import type { WorkerEntry, WorkerEntryConfig } from './worker-entry';
|
|
23
|
+
export interface DomainWorkerEntryConfig<S extends Schema, TEnv, TDeps> {
|
|
24
|
+
/** The domain schema. */
|
|
25
|
+
schema: S;
|
|
26
|
+
/** Method implementations, typed against `schema` under `TDeps`. */
|
|
27
|
+
methods: SchemaMethodsImpl<S, TDeps>;
|
|
28
|
+
/** Optional Core override (extra genesis nodes / wiring). */
|
|
29
|
+
core?: Core<S>;
|
|
30
|
+
/** Views (iframe-mountable UIs) keyed by slug. */
|
|
31
|
+
views?: Record<string, ViewDef<TDeps>>;
|
|
32
|
+
/** Standalone Functions (callables not bound to a class) keyed by slug. */
|
|
33
|
+
functions?: Record<string, AnyRemoteFunctionDef>;
|
|
34
|
+
/**
|
|
35
|
+
* The worker's signing key (its `iss` identity material). A static JWK, or a
|
|
36
|
+
* resolver from `env` for keys injected as a secret / shared globally.
|
|
37
|
+
*/
|
|
38
|
+
privateKey: JsonWebKey | ((env: TEnv) => JsonWebKey);
|
|
39
|
+
/** Cross-domain deps by origin — verified present at install. */
|
|
40
|
+
requires?: readonly string[];
|
|
41
|
+
/** Typed colon-path the kernel calls once as __SYSTEM__ after install. */
|
|
42
|
+
postInstall?: string;
|
|
43
|
+
/** Provenance stamped on `/meta`. */
|
|
44
|
+
meta?: RemoteServerConfig<TDeps>['meta'];
|
|
45
|
+
/**
|
|
46
|
+
* Map the worker `env` to the handler dependency container. Defaults to
|
|
47
|
+
* passing `env` straight through (the common case where handlers read
|
|
48
|
+
* bindings directly).
|
|
49
|
+
*/
|
|
50
|
+
deps?: (env: TEnv, url: string) => TDeps;
|
|
51
|
+
/** Optional pre-built host Hono app (CORS / logging / extra routes). */
|
|
52
|
+
app?: (env: TEnv) => Hono;
|
|
53
|
+
resolveUrl?: WorkerEntryConfig<TEnv>['resolveUrl'];
|
|
54
|
+
selfBinding?: WorkerEntryConfig<TEnv>['selfBinding'];
|
|
55
|
+
routeSubrequest?: WorkerEntryConfig<TEnv>['routeSubrequest'];
|
|
56
|
+
before?: WorkerEntryConfig<TEnv>['before'];
|
|
57
|
+
rewriteRequest?: WorkerEntryConfig<TEnv>['rewriteRequest'];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Curried so `TDeps` can be fixed explicitly (it types `methods`/`views`) while
|
|
61
|
+
* `S` is inferred from `schema` — mirroring `defineRemoteDomain`. The common
|
|
62
|
+
* case `domainWorkerEntry<Env>()({ … })` leaves `TDeps = TEnv` (handlers read
|
|
63
|
+
* the env directly); pass both — `domainWorkerEntry<Env, Deps>()` — when the
|
|
64
|
+
* handler deps differ from the worker bindings and a `deps` mapper is supplied.
|
|
65
|
+
*/
|
|
66
|
+
export declare function domainWorkerEntry<TEnv, TDeps = TEnv>(): <S extends Schema>(config: DomainWorkerEntryConfig<S, TEnv, TDeps>) => WorkerEntry<TEnv>;
|
|
67
|
+
//# sourceMappingURL=domain-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-entry.d.ts","sourceRoot":"","sources":["../../src/server/domain-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAEhC,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAKpE,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,KAAK;IACpE,yBAAyB;IACzB,MAAM,EAAE,CAAC,CAAA;IACT,oEAAoE;IACpE,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACpC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,kDAAkD;IACl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AiCrB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `domainWorkerEntry` — the one-call worker entry for a standalone domain.
|
|
3
|
+
*
|
|
4
|
+
* It folds the three steps every hand-rolled worker used to wire by hand —
|
|
5
|
+
* compile the runtime domain (`defineRemoteDomain`), build the server
|
|
6
|
+
* (`createRemoteServer`), and wrap it in the shared fetch plumbing
|
|
7
|
+
* (`createWorkerEntry`) — into a single declaration. The author passes the raw
|
|
8
|
+
* modules (`schema` / `methods` / `views` / `functions`) plus the identity and
|
|
9
|
+
* deploy bits; the helper does the rest. This is what the cloudflare adapter's
|
|
10
|
+
* codegen emits, and the recommended surface for a hand-rolled worker.
|
|
11
|
+
*
|
|
12
|
+
* Drop down to `createWorkerEntry` + `defineRemoteDomain` (from
|
|
13
|
+
* `@astrale-os/sdk/domain`) only when the worker needs something this config
|
|
14
|
+
* can't express — e.g. a serving-URL-dependent domain build (views stamped with
|
|
15
|
+
* the live url) or a globally-injected signing key resolved per request.
|
|
16
|
+
*/
|
|
17
|
+
import { defineRemoteDomain } from '../domain';
|
|
18
|
+
import { createWorkerEntry } from './worker-entry';
|
|
19
|
+
/**
|
|
20
|
+
* Curried so `TDeps` can be fixed explicitly (it types `methods`/`views`) while
|
|
21
|
+
* `S` is inferred from `schema` — mirroring `defineRemoteDomain`. The common
|
|
22
|
+
* case `domainWorkerEntry<Env>()({ … })` leaves `TDeps = TEnv` (handlers read
|
|
23
|
+
* the env directly); pass both — `domainWorkerEntry<Env, Deps>()` — when the
|
|
24
|
+
* handler deps differ from the worker bindings and a `deps` mapper is supplied.
|
|
25
|
+
*/
|
|
26
|
+
export function domainWorkerEntry() {
|
|
27
|
+
return function (config) {
|
|
28
|
+
const domain = defineRemoteDomain()({
|
|
29
|
+
schema: config.schema,
|
|
30
|
+
methods: config.methods,
|
|
31
|
+
...(config.core ? { core: config.core } : {}),
|
|
32
|
+
...(config.views ? { views: config.views } : {}),
|
|
33
|
+
...(config.functions ? { remoteFunctions: config.functions } : {}),
|
|
34
|
+
});
|
|
35
|
+
return createWorkerEntry({
|
|
36
|
+
...(config.resolveUrl ? { resolveUrl: config.resolveUrl } : {}),
|
|
37
|
+
...(config.selfBinding ? { selfBinding: config.selfBinding } : {}),
|
|
38
|
+
...(config.routeSubrequest ? { routeSubrequest: config.routeSubrequest } : {}),
|
|
39
|
+
...(config.before ? { before: config.before } : {}),
|
|
40
|
+
...(config.rewriteRequest ? { rewriteRequest: config.rewriteRequest } : {}),
|
|
41
|
+
// `createWorkerEntry` conflates the worker env and the handler deps into a
|
|
42
|
+
// single type param; we keep them distinct in the public config and bridge
|
|
43
|
+
// here. The runtime deps (and the methods typed against them) are correct;
|
|
44
|
+
// only this assembly is cast.
|
|
45
|
+
build: (url, env) => ({
|
|
46
|
+
domain,
|
|
47
|
+
deps: config.deps ? config.deps(env, url) : env,
|
|
48
|
+
url,
|
|
49
|
+
privateKey: typeof config.privateKey === 'function' ? config.privateKey(env) : config.privateKey,
|
|
50
|
+
...(config.requires && config.requires.length > 0 ? { requires: config.requires } : {}),
|
|
51
|
+
...(config.postInstall ? { postInstall: config.postInstall } : {}),
|
|
52
|
+
...(config.meta ? { meta: config.meta } : {}),
|
|
53
|
+
...(config.app ? { app: config.app(env) } : {}),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=domain-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-entry.js","sourceRoot":"","sources":["../../src/server/domain-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAUH,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AA2ClD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UACL,MAA+C;QAE/C,MAAM,MAAM,GAAG,kBAAkB,EA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AG,EAAE,GAAG,EAAE,EAAE,CAClB,CAAC;gBACC,MAAM;gBACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,GAAwB;gBACrE,GAAG;gBACH,UAAU,EACR,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU;gBACtF,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvF,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChD,CAAwC;SAC5C,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export type { RemoteServer, RemoteServerHandle } from './handle';
|
|
|
4
4
|
export { derivePublicJwk } from './jwks';
|
|
5
5
|
export { requireEnv } from './require-env';
|
|
6
6
|
export { canonicalizeServingUrl } from './serving-url';
|
|
7
|
-
export { createWorkerEntry } from './worker-entry';
|
|
7
|
+
export { assets, createWorkerEntry } from './worker-entry';
|
|
8
8
|
export type { WorkerEntry, WorkerEntryConfig } from './worker-entry';
|
|
9
|
+
export { domainWorkerEntry } from './domain-entry';
|
|
10
|
+
export type { DomainWorkerEntryConfig } from './domain-entry';
|
|
9
11
|
export { workerMeta } from './worker-meta';
|
|
10
12
|
export { startNodeServer } from './start';
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/server/index.js
CHANGED
|
@@ -2,7 +2,8 @@ export { createRemoteServer } from './create';
|
|
|
2
2
|
export { derivePublicJwk } from './jwks';
|
|
3
3
|
export { requireEnv } from './require-env';
|
|
4
4
|
export { canonicalizeServingUrl } from './serving-url';
|
|
5
|
-
export { createWorkerEntry } from './worker-entry';
|
|
5
|
+
export { assets, createWorkerEntry } from './worker-entry';
|
|
6
|
+
export { domainWorkerEntry } from './domain-entry';
|
|
6
7
|
export { workerMeta } from './worker-meta';
|
|
7
8
|
export { startNodeServer } from './start';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
* • resolve the serving URL (== `iss`), canonicalize it (so the value matches
|
|
7
7
|
* what `createRemoteServer` signs with and the kernel pins), and cache the
|
|
8
8
|
* built app per distinct URL;
|
|
9
|
-
* • optional
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
9
|
+
* • optional subrequest routing: a `globalThis.fetch` override (installed ONLY
|
|
10
|
+
* when `selfBinding` and/or `routeSubrequest` is configured) redirects
|
|
11
|
+
* certain outbound fetches through a caller-supplied binding — `selfBinding`
|
|
12
|
+
* for same-host fetches (a Worker can't fetch its own hostname), and the
|
|
13
|
+
* vendor-neutral `routeSubrequest` for any caller policy (e.g. instance
|
|
14
|
+
* hostnames a same-zone Worker→Worker fetch would 522 on). The SDK names no
|
|
15
|
+
* backend or topology; the caller owns the predicate + the fetcher;
|
|
14
16
|
* • optional SPA hook (e.g. `/ui/*` served from an `ASSETS` binding).
|
|
15
17
|
*
|
|
16
18
|
* The worker's OWN JWKS (`<url>/.well-known/jwks.json`) is served as a normal
|
|
@@ -43,6 +45,17 @@ export interface WorkerEntryConfig<TDeps> {
|
|
|
43
45
|
resolveUrl?: (env: TDeps, requestOrigin: string) => string;
|
|
44
46
|
/** Optional: the `SELF` service binding used to route same-host subrequests. */
|
|
45
47
|
selfBinding?: (env: TDeps) => Fetcher | null | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Optional, vendor-neutral: route an OUTBOUND subrequest through a
|
|
50
|
+
* caller-supplied fetcher instead of the network — for hosts a Worker can't
|
|
51
|
+
* reach directly over the edge (e.g. a platform router on the SAME zone:
|
|
52
|
+
* Cloudflare 522s a same-zone Worker→Worker public `fetch`). Return a `Fetcher`
|
|
53
|
+
* to route the request through, or null/undefined to fall through to the normal
|
|
54
|
+
* fetch. The SDK names no backend or topology — the CALLER owns BOTH the
|
|
55
|
+
* predicate (which hosts) and the fetcher (the binding). This generalizes
|
|
56
|
+
* `selfBinding` (same-origin → SELF) to any caller policy; both are honored.
|
|
57
|
+
*/
|
|
58
|
+
routeSubrequest?: (url: URL, env: TDeps) => Fetcher | null | undefined;
|
|
46
59
|
/**
|
|
47
60
|
* Optional: handle a request before it reaches the kernel app — e.g. serve a
|
|
48
61
|
* SPA under `/ui/*` or a same-origin `/api/*` endpoint the view calls. Return
|
|
@@ -72,6 +85,28 @@ export interface WorkerEntry<TDeps> {
|
|
|
72
85
|
* fails — it can never make this worker speak for another origin.
|
|
73
86
|
*/
|
|
74
87
|
export declare function clientOrigin(url: URL, request: Request): string;
|
|
88
|
+
/**
|
|
89
|
+
* Build a `before` hook that serves a static-asset `binding` (e.g. a Workers
|
|
90
|
+
* Assets binding) mounted under `base` (default `/ui`) — the runtime half of a
|
|
91
|
+
* domain's `client` binding. Returns `undefined` for non-matching paths (and
|
|
92
|
+
* when no binding is present) so the request falls through to domain dispatch.
|
|
93
|
+
*
|
|
94
|
+
* Asset URLs are rooted at `base` (a client bundler sets `base: '<base>/'`);
|
|
95
|
+
* this hook strips that prefix before delegating to the binding, so
|
|
96
|
+
* `<base>/x.js` resolves from the binding's root. When `devProxy` yields a URL
|
|
97
|
+
* (local dev), requests are proxied there instead — the seam for a bundler's
|
|
98
|
+
* HMR dev server. Whether unknown sub-paths fall back to `index.html` is the
|
|
99
|
+
* binding's own concern (e.g. wrangler's `not_found_handling`), not baked in
|
|
100
|
+
* here.
|
|
101
|
+
*
|
|
102
|
+
* Lives here, type-checked and testable, instead of being emitted as a string
|
|
103
|
+
* by every adapter's worker codegen.
|
|
104
|
+
*/
|
|
105
|
+
export declare function assets<TDeps>(opts: {
|
|
106
|
+
base?: string;
|
|
107
|
+
binding: (env: TDeps) => Fetcher | null | undefined;
|
|
108
|
+
devProxy?: (env: TDeps) => string | null | undefined;
|
|
109
|
+
}): (env: TDeps, url: URL, request: Request) => Response | Promise<Response> | undefined;
|
|
75
110
|
export declare function createWorkerEntry<TDeps>(config: WorkerEntryConfig<TDeps>): WorkerEntry<TDeps>;
|
|
76
111
|
export {};
|
|
77
112
|
//# sourceMappingURL=worker-entry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAMlD,KAAK,OAAO,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAA;AAGxE,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC;;;;OAIG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,KAAK,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC7D;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,KAAK,MAAM,CAAA;IAC1D,gFAAgF;IAChF,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;IACxD;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EA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`), canonicalize it (so the value matches
|
|
7
7
|
* what `createRemoteServer` signs with and the kernel pins), and cache the
|
|
8
8
|
* built app per distinct URL;
|
|
9
|
-
* • optional
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
9
|
+
* • optional subrequest routing: a `globalThis.fetch` override (installed ONLY
|
|
10
|
+
* when `selfBinding` and/or `routeSubrequest` is configured) redirects
|
|
11
|
+
* certain outbound fetches through a caller-supplied binding — `selfBinding`
|
|
12
|
+
* for same-host fetches (a Worker can't fetch its own hostname), and the
|
|
13
|
+
* vendor-neutral `routeSubrequest` for any caller policy (e.g. instance
|
|
14
|
+
* hostnames a same-zone Worker→Worker fetch would 522 on). The SDK names no
|
|
15
|
+
* backend or topology; the caller owns the predicate + the fetcher;
|
|
14
16
|
* • optional SPA hook (e.g. `/ui/*` served from an `ASSETS` binding).
|
|
15
17
|
*
|
|
16
18
|
* The worker's OWN JWKS (`<url>/.well-known/jwks.json`) is served as a normal
|
|
@@ -41,6 +43,43 @@ export function clientOrigin(url, request) {
|
|
|
41
43
|
const scheme = forwarded?.split(',')[0]?.trim().toLowerCase();
|
|
42
44
|
return scheme === 'https' ? `https://${url.host}` : url.origin;
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Build a `before` hook that serves a static-asset `binding` (e.g. a Workers
|
|
48
|
+
* Assets binding) mounted under `base` (default `/ui`) — the runtime half of a
|
|
49
|
+
* domain's `client` binding. Returns `undefined` for non-matching paths (and
|
|
50
|
+
* when no binding is present) so the request falls through to domain dispatch.
|
|
51
|
+
*
|
|
52
|
+
* Asset URLs are rooted at `base` (a client bundler sets `base: '<base>/'`);
|
|
53
|
+
* this hook strips that prefix before delegating to the binding, so
|
|
54
|
+
* `<base>/x.js` resolves from the binding's root. When `devProxy` yields a URL
|
|
55
|
+
* (local dev), requests are proxied there instead — the seam for a bundler's
|
|
56
|
+
* HMR dev server. Whether unknown sub-paths fall back to `index.html` is the
|
|
57
|
+
* binding's own concern (e.g. wrangler's `not_found_handling`), not baked in
|
|
58
|
+
* here.
|
|
59
|
+
*
|
|
60
|
+
* Lives here, type-checked and testable, instead of being emitted as a string
|
|
61
|
+
* by every adapter's worker codegen.
|
|
62
|
+
*/
|
|
63
|
+
export function assets(opts) {
|
|
64
|
+
const base = (opts.base ?? '/ui').replace(/\/+$/, '');
|
|
65
|
+
const prefix = `${base}/`;
|
|
66
|
+
return (env, url, request) => {
|
|
67
|
+
const binding = opts.binding(env);
|
|
68
|
+
if (!binding)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (url.pathname !== base && !url.pathname.startsWith(prefix))
|
|
71
|
+
return undefined;
|
|
72
|
+
const devUrl = opts.devProxy?.(env);
|
|
73
|
+
if (devUrl) {
|
|
74
|
+
const devBase = devUrl.replace(/\/+$/, '');
|
|
75
|
+
return fetch(new Request(`${devBase}${url.pathname}${url.search}`, request));
|
|
76
|
+
}
|
|
77
|
+
// `<base>` → `/`, `<base>/x` → `/x`: serve from the binding's root.
|
|
78
|
+
const stripped = url.pathname.slice(base.length) || '/';
|
|
79
|
+
const rewritten = new URL(stripped + url.search, url.origin);
|
|
80
|
+
return binding.fetch(new Request(rewritten, request));
|
|
81
|
+
};
|
|
82
|
+
}
|
|
44
83
|
export function createWorkerEntry(config) {
|
|
45
84
|
// Cache the built app per distinct resolved URL — plural and bounded. On the
|
|
46
85
|
// request-origin fallback the URL legitimately alternates for one worker
|
|
@@ -51,6 +90,7 @@ export function createWorkerEntry(config) {
|
|
|
51
90
|
const MAX_CACHED_APPS = 4;
|
|
52
91
|
const apps = new Map();
|
|
53
92
|
let self = null;
|
|
93
|
+
let routeEnv = null;
|
|
54
94
|
function getApp(url, env) {
|
|
55
95
|
const cached = apps.get(url);
|
|
56
96
|
if (cached)
|
|
@@ -64,28 +104,35 @@ export function createWorkerEntry(config) {
|
|
|
64
104
|
apps.set(url, { origin: new URL(url).origin, app });
|
|
65
105
|
return app;
|
|
66
106
|
}
|
|
67
|
-
// A Worker can't fetch its own hostname
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
// (A self-issued credential's JWKS is resolved in-memory by the
|
|
72
|
-
// fetched — see `auth/verify.ts` — so no self-JWKS
|
|
73
|
-
if (config.selfBinding) {
|
|
107
|
+
// A Worker can't fetch its own hostname (SELF), nor — on Cloudflare — a
|
|
108
|
+
// same-zone hostname routed to another Worker (the `routeSubrequest` case).
|
|
109
|
+
// When either is configured, override `globalThis.fetch` to redirect those
|
|
110
|
+
// subrequests through the caller's fetcher. Workers with neither get no global
|
|
111
|
+
// mutation. (A self-issued credential's JWKS is resolved in-memory by the
|
|
112
|
+
// verifier, not fetched — see `auth/verify.ts` — so no self-JWKS shim is needed.)
|
|
113
|
+
if (config.selfBinding || config.routeSubrequest) {
|
|
74
114
|
const originalFetch = globalThis.fetch;
|
|
75
115
|
globalThis.fetch = (async (input, init) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
const href = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
117
|
+
try {
|
|
118
|
+
const u = new URL(href);
|
|
119
|
+
// same-origin → SELF (a Worker can't fetch its own hostname)
|
|
120
|
+
if (self && apps.size > 0) {
|
|
80
121
|
for (const cached of apps.values()) {
|
|
81
|
-
if (cached.origin === origin)
|
|
122
|
+
if (cached.origin === u.origin)
|
|
82
123
|
return self.fetch(new Request(input, init));
|
|
83
124
|
}
|
|
84
125
|
}
|
|
85
|
-
|
|
86
|
-
|
|
126
|
+
// caller policy → its fetcher (e.g. a platform router on the same zone)
|
|
127
|
+
if (config.routeSubrequest && routeEnv) {
|
|
128
|
+
const via = config.routeSubrequest(u, routeEnv);
|
|
129
|
+
if (via)
|
|
130
|
+
return via.fetch(new Request(input, init));
|
|
87
131
|
}
|
|
88
132
|
}
|
|
133
|
+
catch {
|
|
134
|
+
// non-absolute URL — fall through to the original fetch
|
|
135
|
+
}
|
|
89
136
|
return originalFetch(input, init);
|
|
90
137
|
});
|
|
91
138
|
}
|
|
@@ -93,6 +140,8 @@ export function createWorkerEntry(config) {
|
|
|
93
140
|
async fetch(request, env) {
|
|
94
141
|
if (config.selfBinding)
|
|
95
142
|
self ??= config.selfBinding(env) ?? null;
|
|
143
|
+
if (config.routeSubrequest)
|
|
144
|
+
routeEnv = env;
|
|
96
145
|
// Only parse the request URL when a hook actually needs it.
|
|
97
146
|
const requestUrl = config.before || config.resolveUrl ? new URL(request.url) : null;
|
|
98
147
|
if (config.before && requestUrl) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AA2DtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,GAAQ,EAAE,OAAgB;IACrD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,GAAG,CAAC,MAAM,CAAA;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;IAC1D,mFAAmF;IACnF,MAAM,MAAM,GAAG,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7D,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAA;AAChE,CAAC;AAED;;;;;;;;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AA;YAC1C,4DAA4D;YAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACnF,IAAI,MAAM,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;gBAChC,wEAAwE;gBACxE,2EAA2E;gBAC3E,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;gBAC7D,IAAI,OAAO,KAAK,SAAS;oBAAE,OAAO,OAAO,CAAA;YAC3C,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU;gBAC3B,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,UAAW,EAAE,OAAO,CAAC,CAAC;gBAC5D,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,oDAAoD,CAAC,CAAA;YACvF,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;YACvC,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;YACxF,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAC3C,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Astrale Remote Domain SDK - Define and deploy domains as standalone Hono servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrale",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "git+https://github.com/astrale-os/sdk.git"
|
|
17
17
|
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"astrale-domain": "./dist/cli/bin.js"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist",
|
|
20
23
|
"src"
|
|
@@ -31,6 +34,14 @@
|
|
|
31
34
|
"types": "./dist/server/index.d.ts",
|
|
32
35
|
"import": "./dist/server/index.js"
|
|
33
36
|
},
|
|
37
|
+
"./domain": {
|
|
38
|
+
"types": "./dist/domain/index.d.ts",
|
|
39
|
+
"import": "./dist/domain/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./cli": {
|
|
42
|
+
"types": "./dist/cli/index.d.ts",
|
|
43
|
+
"import": "./dist/cli/index.js"
|
|
44
|
+
},
|
|
34
45
|
"./deploy": {
|
|
35
46
|
"types": "./dist/deploy/index.d.ts",
|
|
36
47
|
"import": "./dist/deploy/index.js"
|
|
@@ -50,8 +61,6 @@
|
|
|
50
61
|
"zod": "^4.3.6"
|
|
51
62
|
},
|
|
52
63
|
"devDependencies": {
|
|
53
|
-
"@astrale-os/kernel-host": ">=0.4.0 <1.0.0",
|
|
54
|
-
"@astrale-os/kernel-test": ">=0.4.0 <1.0.0",
|
|
55
64
|
"@astrale-os/ox": ">=0.1.0 <1.0.0",
|
|
56
65
|
"@astrale/commitlint-config": "npm:@jsr/astrale__commitlint-config@~2.0.0",
|
|
57
66
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
package/src/cli/bin.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* `astrale-domain` bin entry. Runs under bun (native TS) so it can import the
|
|
4
|
+
* project's `astrale.config.ts` directly — matching the `astrale` CLI.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { run } from './run'
|
|
8
|
+
|
|
9
|
+
run(process.argv.slice(2))
|
|
10
|
+
.then((code) => process.exit(code))
|
|
11
|
+
.catch((err: unknown) => {
|
|
12
|
+
process.stderr.write(`\x1b[31m✗\x1b[0m ${(err as Error).message ?? String(err)}\n`)
|
|
13
|
+
if (process.env.DEBUG) process.stderr.write(`${(err as Error).stack ?? ''}\n`)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal dotenv parser — the secrets-file boundary.
|
|
3
|
+
*
|
|
4
|
+
* `secrets: '.env.<env>'` in an adapter's params points a gitignored file whose
|
|
5
|
+
* entire contents are secrets. `loadDotenvFile` reads it into a flat
|
|
6
|
+
* `Record<string,string>` the CLI hands the adapter (injected into the local
|
|
7
|
+
* runtime in dev, pushed to a secret store in prod). No `process.env` mutation,
|
|
8
|
+
* no interpolation magic beyond `${VAR}` against earlier keys in the same file.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
|
|
13
|
+
export function parseDotenv(contents: string): Record<string, string> {
|
|
14
|
+
const out: Record<string, string> = {}
|
|
15
|
+
for (const raw of contents.split('\n')) {
|
|
16
|
+
const line = raw.trim()
|
|
17
|
+
if (!line || line.startsWith('#')) continue
|
|
18
|
+
const match = /^(?:export\s+)?([A-Za-z_]\w*)\s*=\s*(.*)$/.exec(line)
|
|
19
|
+
if (!match) continue
|
|
20
|
+
const [, key, rawValue] = match
|
|
21
|
+
let value = rawValue.trim()
|
|
22
|
+
// Single quotes mean a LITERAL value (standard dotenv): no `${VAR}`
|
|
23
|
+
// interpolation, so a secret that legitimately contains a literal `${...}`
|
|
24
|
+
// (e.g. a password) survives intact instead of being silently blanked.
|
|
25
|
+
const singleQuoted = value.length >= 2 && value.startsWith("'") && value.endsWith("'")
|
|
26
|
+
if ((value.length >= 2 && value.startsWith('"') && value.endsWith('"')) || singleQuoted) {
|
|
27
|
+
value = value.slice(1, -1)
|
|
28
|
+
}
|
|
29
|
+
out[key] = singleQuoted
|
|
30
|
+
? value
|
|
31
|
+
: value.replace(/\$\{(\w+)\}/g, (_, name: string) => out[name] ?? '')
|
|
32
|
+
}
|
|
33
|
+
return out
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Read + parse a dotenv file. Returns `{}` if the file is absent (CI-safe). */
|
|
37
|
+
export function loadDotenvFile(path: string): Record<string, string> {
|
|
38
|
+
let contents: string
|
|
39
|
+
try {
|
|
40
|
+
contents = readFileSync(path, 'utf-8')
|
|
41
|
+
} catch {
|
|
42
|
+
return {}
|
|
43
|
+
}
|
|
44
|
+
return parseDotenv(contents)
|
|
45
|
+
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@astrale-os/sdk/cli` — the `astrale-domain` CLI (dev | build | deploy) and
|
|
3
|
+
* the dotenv secrets-file boundary, folded in from the former
|
|
4
|
+
* `@astrale-os/devkit` package.
|
|
5
|
+
*
|
|
6
|
+
* Node-only: the CLI imports `node:fs`/`node:module`/`node:url` and runs under
|
|
7
|
+
* Bun (it imports the project's `astrale.config.ts` directly). This subpath is
|
|
8
|
+
* deliberately NOT re-exported from the package barrel — pulling it into the
|
|
9
|
+
* isomorphic `.` entry would poison browser/worker bundlers that traverse every
|
|
10
|
+
* re-export (the same rule that keeps `./server` and `./deploy` off the barrel).
|
|
11
|
+
* The bin lives at `./bin`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export { run, parseArgs } from './run'
|
|
15
|
+
export { parseDotenv, loadDotenvFile } from './dotenv'
|