@astrale-os/sdk 0.1.5 → 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.
Files changed (108) hide show
  1. package/dist/auth/verify.d.ts +2 -0
  2. package/dist/auth/verify.d.ts.map +1 -1
  3. package/dist/auth/verify.js +81 -26
  4. package/dist/auth/verify.js.map +1 -1
  5. package/dist/cli/bin.d.ts +7 -0
  6. package/dist/cli/bin.d.ts.map +1 -0
  7. package/dist/cli/bin.js +15 -0
  8. package/dist/cli/bin.js.map +1 -0
  9. package/dist/cli/dotenv.d.ts +13 -0
  10. package/dist/cli/dotenv.d.ts.map +1 -0
  11. package/dist/cli/dotenv.js +46 -0
  12. package/dist/cli/dotenv.js.map +1 -0
  13. package/dist/cli/index.d.ts +15 -0
  14. package/dist/cli/index.d.ts.map +1 -0
  15. package/dist/cli/index.js +15 -0
  16. package/dist/cli/index.js.map +1 -0
  17. package/dist/cli/run.d.ts +79 -0
  18. package/dist/cli/run.d.ts.map +1 -0
  19. package/dist/cli/run.js +569 -0
  20. package/dist/cli/run.js.map +1 -0
  21. package/dist/cli/spec.d.ts +19 -0
  22. package/dist/cli/spec.d.ts.map +1 -0
  23. package/dist/cli/spec.js +31 -0
  24. package/dist/cli/spec.js.map +1 -0
  25. package/dist/config/adapter.d.ts +140 -0
  26. package/dist/config/adapter.d.ts.map +1 -0
  27. package/dist/config/adapter.js +40 -0
  28. package/dist/config/adapter.js.map +1 -0
  29. package/dist/config/define-domain.d.ts +112 -0
  30. package/dist/config/define-domain.d.ts.map +1 -0
  31. package/dist/config/define-domain.js +98 -0
  32. package/dist/config/define-domain.js.map +1 -0
  33. package/dist/config/deploy.d.ts +28 -0
  34. package/dist/config/deploy.d.ts.map +1 -0
  35. package/dist/config/deploy.js +24 -0
  36. package/dist/config/deploy.js.map +1 -0
  37. package/dist/config/index.d.ts +21 -0
  38. package/dist/config/index.d.ts.map +1 -0
  39. package/dist/config/index.js +18 -0
  40. package/dist/config/index.js.map +1 -0
  41. package/dist/define/remote-function.d.ts +19 -11
  42. package/dist/define/remote-function.d.ts.map +1 -1
  43. package/dist/define/remote-function.js.map +1 -1
  44. package/dist/dispatch/call-remote.d.ts +7 -3
  45. package/dist/dispatch/call-remote.d.ts.map +1 -1
  46. package/dist/dispatch/call-remote.js.map +1 -1
  47. package/dist/dispatch/dispatcher.d.ts.map +1 -1
  48. package/dist/dispatch/dispatcher.js +8 -4
  49. package/dist/dispatch/dispatcher.js.map +1 -1
  50. package/dist/dispatch/index.d.ts +1 -1
  51. package/dist/dispatch/index.d.ts.map +1 -1
  52. package/dist/dispatch/index.js.map +1 -1
  53. package/dist/dispatch/self.d.ts +46 -10
  54. package/dist/dispatch/self.d.ts.map +1 -1
  55. package/dist/dispatch/self.js +65 -8
  56. package/dist/dispatch/self.js.map +1 -1
  57. package/dist/domain/define.d.ts +3 -3
  58. package/dist/domain/define.js +3 -3
  59. package/dist/index.d.ts +5 -4
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +8 -2
  62. package/dist/index.js.map +1 -1
  63. package/dist/method/class.d.ts.map +1 -1
  64. package/dist/method/class.js.map +1 -1
  65. package/dist/method/context.d.ts +32 -7
  66. package/dist/method/context.d.ts.map +1 -1
  67. package/dist/method/index.d.ts +1 -1
  68. package/dist/method/index.d.ts.map +1 -1
  69. package/dist/method/single.d.ts +16 -11
  70. package/dist/method/single.d.ts.map +1 -1
  71. package/dist/method/single.js.map +1 -1
  72. package/dist/server/domain-entry.d.ts +67 -0
  73. package/dist/server/domain-entry.d.ts.map +1 -0
  74. package/dist/server/domain-entry.js +58 -0
  75. package/dist/server/domain-entry.js.map +1 -0
  76. package/dist/server/index.d.ts +3 -1
  77. package/dist/server/index.d.ts.map +1 -1
  78. package/dist/server/index.js +2 -1
  79. package/dist/server/index.js.map +1 -1
  80. package/dist/server/worker-entry.d.ts +57 -5
  81. package/dist/server/worker-entry.d.ts.map +1 -1
  82. package/dist/server/worker-entry.js +108 -24
  83. package/dist/server/worker-entry.js.map +1 -1
  84. package/package.json +12 -3
  85. package/src/auth/verify.ts +89 -28
  86. package/src/cli/bin.ts +15 -0
  87. package/src/cli/dotenv.ts +45 -0
  88. package/src/cli/index.ts +15 -0
  89. package/src/cli/run.ts +675 -0
  90. package/src/cli/spec.ts +42 -0
  91. package/src/config/adapter.ts +172 -0
  92. package/src/config/define-domain.ts +218 -0
  93. package/src/config/deploy.ts +35 -0
  94. package/src/config/index.ts +31 -0
  95. package/src/define/remote-function.ts +42 -13
  96. package/src/dispatch/call-remote.ts +7 -2
  97. package/src/dispatch/dispatcher.ts +8 -4
  98. package/src/dispatch/index.ts +1 -1
  99. package/src/dispatch/self.ts +96 -10
  100. package/src/domain/define.ts +3 -3
  101. package/src/index.ts +25 -4
  102. package/src/method/class.ts +4 -3
  103. package/src/method/context.ts +38 -7
  104. package/src/method/index.ts +1 -1
  105. package/src/method/single.ts +30 -11
  106. package/src/server/domain-entry.ts +113 -0
  107. package/src/server/index.ts +3 -1
  108. package/src/server/worker-entry.ts +122 -23
@@ -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;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IACtC,2EAA2E;IAC3E,SAAS,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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,EAAS,CAAC;YACzC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7C,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAO;YAC7B,GAAG,CAAC,MAAM,CAAC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AAM,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"}
@@ -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;AAClD,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,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"}
@@ -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
@@ -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 self-binding routing: when a `SELF` service binding is provided,
10
- * route same-host subrequests (e.g. `ctx.callRemote` back into this domain)
11
- * through it Cloudflare forbids a Worker fetching its own hostname. This is
12
- * the ONLY reason a `globalThis.fetch` override is installed, and only when a
13
- * `selfBinding` is configured;
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
@@ -34,10 +36,26 @@ export interface WorkerEntryConfig<TDeps> {
34
36
  * Resolve the raw serving URL from `env` (+ the per-request origin, for workers
35
37
  * that fall back to the request host). Defaults to the `WORKER_URL` env var.
36
38
  * The result is always canonicalized before use.
39
+ *
40
+ * The `requestOrigin` honors an `X-Forwarded-Proto: https` upgrade (see
41
+ * `clientOrigin`), so a dev worker behind a TLS-terminating proxy (cloudflared
42
+ * tunnel, reverse proxy) resolves its public `https://` origin, not the raw
43
+ * `http://` one workerd sees.
37
44
  */
38
45
  resolveUrl?: (env: TDeps, requestOrigin: string) => string;
39
46
  /** Optional: the `SELF` service binding used to route same-host subrequests. */
40
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;
41
59
  /**
42
60
  * Optional: handle a request before it reaches the kernel app — e.g. serve a
43
61
  * SPA under `/ui/*` or a same-origin `/api/*` endpoint the view calls. Return
@@ -55,6 +73,40 @@ export interface WorkerEntryConfig<TDeps> {
55
73
  export interface WorkerEntry<TDeps> {
56
74
  fetch(request: Request, env: TDeps): Response | Promise<Response>;
57
75
  }
76
+ /**
77
+ * The request origin as the CLIENT reached it — i.e. the origin a fallback
78
+ * serving URL (and therefore the `iss`) may be derived from. Behind a
79
+ * TLS-terminating proxy (a cloudflared tunnel in front of `wrangler dev`, any
80
+ * reverse proxy) the worker sees plain HTTP, so `request.url` says `http://…`
81
+ * while the public URL is `https://…`; the proxy advertises the original
82
+ * scheme via `X-Forwarded-Proto`. Honoring it is restricted to the http→https
83
+ * UPGRADE of the SAME host (never a downgrade, never a host change), so a
84
+ * spoofed header can at worst derive an `iss` the kernel's JWKS check then
85
+ * fails — it can never make this worker speak for another origin.
86
+ */
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;
58
110
  export declare function createWorkerEntry<TDeps>(config: WorkerEntryConfig<TDeps>): WorkerEntry<TDeps>;
59
111
  export {};
60
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;;;;;;;;;;;;;;;;;;;;GAoBG;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;;;;OAIG;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;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CACP,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,KACb,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACzD;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;CAC3D;AAED,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClE;AAED,wBAAgB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AC,KAAK;IAChC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAM/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;IACnD,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CACrD,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,CAiBvF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CA0E7F"}
@@ -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 self-binding routing: when a `SELF` service binding is provided,
10
- * route same-host subrequests (e.g. `ctx.callRemote` back into this domain)
11
- * through it Cloudflare forbids a Worker fetching its own hostname. This is
12
- * the ONLY reason a `globalThis.fetch` override is installed, and only when a
13
- * `selfBinding` is configured;
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
@@ -22,35 +24,115 @@
22
24
  import { createRemoteServer } from './create';
23
25
  import { requireEnv } from './require-env';
24
26
  import { canonicalizeServingUrl } from './serving-url';
27
+ /**
28
+ * The request origin as the CLIENT reached it — i.e. the origin a fallback
29
+ * serving URL (and therefore the `iss`) may be derived from. Behind a
30
+ * TLS-terminating proxy (a cloudflared tunnel in front of `wrangler dev`, any
31
+ * reverse proxy) the worker sees plain HTTP, so `request.url` says `http://…`
32
+ * while the public URL is `https://…`; the proxy advertises the original
33
+ * scheme via `X-Forwarded-Proto`. Honoring it is restricted to the http→https
34
+ * UPGRADE of the SAME host (never a downgrade, never a host change), so a
35
+ * spoofed header can at worst derive an `iss` the kernel's JWKS check then
36
+ * fails — it can never make this worker speak for another origin.
37
+ */
38
+ export function clientOrigin(url, request) {
39
+ if (url.protocol !== 'http:')
40
+ return url.origin;
41
+ const forwarded = request.headers.get('x-forwarded-proto');
42
+ // Multiple proxies append: "https, http" — the first hop is the client-facing one.
43
+ const scheme = forwarded?.split(',')[0]?.trim().toLowerCase();
44
+ return scheme === 'https' ? `https://${url.host}` : url.origin;
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
+ }
25
83
  export function createWorkerEntry(config) {
26
- let cache = null;
84
+ // Cache the built app per distinct resolved URL — plural and bounded. On the
85
+ // request-origin fallback the URL legitimately alternates for one worker
86
+ // (direct http hits vs https-upgraded tunnel hits, workers.dev + custom
87
+ // domain), and a single slot would tear down and rebuild the whole app on
88
+ // every alternation. The bound caps abuse via attacker-minted Host /
89
+ // X-Forwarded-Proto values on that same fallback path.
90
+ const MAX_CACHED_APPS = 4;
91
+ const apps = new Map();
27
92
  let self = null;
93
+ let routeEnv = null;
28
94
  function getApp(url, env) {
29
- if (cache && cache.url === url)
30
- return cache.app;
95
+ const cached = apps.get(url);
96
+ if (cached)
97
+ return cached.app;
31
98
  const { app } = createRemoteServer(config.build(url, env));
32
- cache = { url, origin: new URL(url).origin, app };
99
+ if (apps.size >= MAX_CACHED_APPS) {
100
+ const oldest = apps.keys().next().value;
101
+ if (oldest !== undefined)
102
+ apps.delete(oldest);
103
+ }
104
+ apps.set(url, { origin: new URL(url).origin, app });
33
105
  return app;
34
106
  }
35
- // A Worker can't fetch its own hostname. When a SELF service binding is
36
- // configured, route same-host subrequests (e.g. `ctx.callRemote` back into
37
- // this domain) through it. This is the only reason to override
38
- // `globalThis.fetch` workers without a `selfBinding` get no global mutation.
39
- // (A self-issued credential's JWKS is resolved in-memory by the verifier, not
40
- // fetched — see `auth/verify.ts` — so no self-JWKS interception is needed.)
41
- 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) {
42
114
  const originalFetch = globalThis.fetch;
43
115
  globalThis.fetch = (async (input, init) => {
44
- if (cache && self) {
45
- const href = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
46
- try {
47
- if (new URL(href).origin === cache.origin)
48
- return self.fetch(new Request(input, init));
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) {
121
+ for (const cached of apps.values()) {
122
+ if (cached.origin === u.origin)
123
+ return self.fetch(new Request(input, init));
124
+ }
49
125
  }
50
- catch {
51
- // non-absolute URL fall through to the original fetch
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));
52
131
  }
53
132
  }
133
+ catch {
134
+ // non-absolute URL — fall through to the original fetch
135
+ }
54
136
  return originalFetch(input, init);
55
137
  });
56
138
  }
@@ -58,6 +140,8 @@ export function createWorkerEntry(config) {
58
140
  async fetch(request, env) {
59
141
  if (config.selfBinding)
60
142
  self ??= config.selfBinding(env) ?? null;
143
+ if (config.routeSubrequest)
144
+ routeEnv = env;
61
145
  // Only parse the request URL when a hook actually needs it.
62
146
  const requestUrl = config.before || config.resolveUrl ? new URL(request.url) : null;
63
147
  if (config.before && requestUrl) {
@@ -68,7 +152,7 @@ export function createWorkerEntry(config) {
68
152
  return handled;
69
153
  }
70
154
  const raw = config.resolveUrl
71
- ? config.resolveUrl(env, requestUrl.origin)
155
+ ? config.resolveUrl(env, clientOrigin(requestUrl, request))
72
156
  : requireEnv(env, 'WORKER_URL', "the worker's public serving URL (its iss identity)");
73
157
  const url = canonicalizeServingUrl(raw);
74
158
  const dispatched = config.rewriteRequest ? config.rewriteRequest(env, request) : request;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AA2CtD,MAAM,UAAU,iBAAiB,CAAQ,MAAgC;IACvE,IAAI,KAAK,GAAqD,IAAI,CAAA;IAClE,IAAI,IAAI,GAAmB,IAAI,CAAA;IAE/B,SAAS,MAAM,CAAC,GAAW,EAAE,GAAU;QACrC,IAAI,KAAK,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC,GAAG,CAAA;QAChD,MAAM,EAAE,GAAG,EAAE,GAAG,kBAAkB,CAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;QACjE,KAAK,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EA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C,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.5",
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",