@astrale-os/sdk 0.1.1 → 0.1.3

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 (198) hide show
  1. package/dist/auth/authenticate.d.ts +24 -0
  2. package/dist/auth/authenticate.d.ts.map +1 -0
  3. package/dist/auth/authenticate.js +29 -0
  4. package/dist/auth/authenticate.js.map +1 -0
  5. package/dist/auth/check.d.ts +39 -0
  6. package/dist/auth/check.d.ts.map +1 -0
  7. package/dist/auth/check.js +54 -0
  8. package/dist/auth/check.js.map +1 -0
  9. package/dist/auth/compose.d.ts +41 -0
  10. package/dist/auth/compose.d.ts.map +1 -0
  11. package/dist/auth/compose.js +45 -0
  12. package/dist/auth/compose.js.map +1 -0
  13. package/dist/auth/errors.d.ts +16 -0
  14. package/dist/auth/errors.d.ts.map +1 -0
  15. package/dist/auth/errors.js +26 -0
  16. package/dist/auth/errors.js.map +1 -0
  17. package/dist/auth/identity.d.ts +16 -0
  18. package/dist/auth/identity.d.ts.map +1 -0
  19. package/dist/auth/identity.js +2 -0
  20. package/dist/auth/identity.js.map +1 -0
  21. package/dist/auth/index.d.ts +12 -0
  22. package/dist/auth/index.d.ts.map +1 -0
  23. package/dist/auth/index.js +9 -0
  24. package/dist/auth/index.js.map +1 -0
  25. package/dist/auth/kernel-client.d.ts +43 -0
  26. package/dist/auth/kernel-client.d.ts.map +1 -0
  27. package/dist/auth/kernel-client.js +146 -0
  28. package/dist/auth/kernel-client.js.map +1 -0
  29. package/dist/auth/resolve.d.ts +19 -0
  30. package/dist/auth/resolve.d.ts.map +1 -0
  31. package/dist/auth/resolve.js +43 -0
  32. package/dist/auth/resolve.js.map +1 -0
  33. package/dist/auth/sign.d.ts +15 -0
  34. package/dist/auth/sign.d.ts.map +1 -0
  35. package/dist/auth/sign.js +24 -0
  36. package/dist/auth/sign.js.map +1 -0
  37. package/dist/auth/verify.d.ts +26 -0
  38. package/dist/auth/verify.d.ts.map +1 -0
  39. package/dist/auth/verify.js +96 -0
  40. package/dist/auth/verify.js.map +1 -0
  41. package/dist/define/index.d.ts +5 -0
  42. package/dist/define/index.d.ts.map +1 -0
  43. package/dist/define/index.js +3 -0
  44. package/dist/define/index.js.map +1 -0
  45. package/dist/define/remote-function.d.ts +96 -0
  46. package/dist/define/remote-function.d.ts.map +1 -0
  47. package/dist/define/remote-function.js +25 -0
  48. package/dist/define/remote-function.js.map +1 -0
  49. package/dist/define/view.d.ts +86 -0
  50. package/dist/define/view.d.ts.map +1 -0
  51. package/dist/define/view.js +28 -0
  52. package/dist/define/view.js.map +1 -0
  53. package/dist/deploy/check.d.ts +30 -0
  54. package/dist/deploy/check.d.ts.map +1 -0
  55. package/dist/deploy/check.js +82 -0
  56. package/dist/deploy/check.js.map +1 -0
  57. package/dist/deploy/hash-spec.d.ts +9 -0
  58. package/dist/deploy/hash-spec.d.ts.map +1 -0
  59. package/dist/deploy/hash-spec.js +29 -0
  60. package/dist/deploy/hash-spec.js.map +1 -0
  61. package/dist/deploy/index.d.ts +4 -0
  62. package/dist/deploy/index.d.ts.map +1 -0
  63. package/dist/deploy/index.js +4 -0
  64. package/dist/deploy/index.js.map +1 -0
  65. package/dist/deploy/meta.d.ts +18 -0
  66. package/dist/deploy/meta.d.ts.map +1 -0
  67. package/dist/deploy/meta.js +22 -0
  68. package/dist/deploy/meta.js.map +1 -0
  69. package/dist/dispatch/authorize.d.ts +14 -0
  70. package/dist/dispatch/authorize.d.ts.map +1 -0
  71. package/dist/dispatch/authorize.js +24 -0
  72. package/dist/dispatch/authorize.js.map +1 -0
  73. package/dist/dispatch/call-remote.d.ts +35 -0
  74. package/dist/dispatch/call-remote.d.ts.map +1 -0
  75. package/dist/dispatch/call-remote.js +37 -0
  76. package/dist/dispatch/call-remote.js.map +1 -0
  77. package/dist/dispatch/dispatcher.d.ts +60 -0
  78. package/dist/dispatch/dispatcher.d.ts.map +1 -0
  79. package/dist/dispatch/dispatcher.js +177 -0
  80. package/dist/dispatch/dispatcher.js.map +1 -0
  81. package/dist/dispatch/errors.d.ts +47 -0
  82. package/dist/dispatch/errors.d.ts.map +1 -0
  83. package/dist/dispatch/errors.js +76 -0
  84. package/dist/dispatch/errors.js.map +1 -0
  85. package/dist/dispatch/execute.d.ts +33 -0
  86. package/dist/dispatch/execute.d.ts.map +1 -0
  87. package/dist/dispatch/execute.js +24 -0
  88. package/dist/dispatch/execute.js.map +1 -0
  89. package/dist/dispatch/identity.d.ts +73 -0
  90. package/dist/dispatch/identity.d.ts.map +1 -0
  91. package/dist/dispatch/identity.js +106 -0
  92. package/dist/dispatch/identity.js.map +1 -0
  93. package/dist/dispatch/index.d.ts +8 -0
  94. package/dist/dispatch/index.d.ts.map +1 -0
  95. package/dist/dispatch/index.js +8 -0
  96. package/dist/dispatch/index.js.map +1 -0
  97. package/dist/dispatch/resolve.d.ts +27 -0
  98. package/dist/dispatch/resolve.d.ts.map +1 -0
  99. package/dist/dispatch/resolve.js +65 -0
  100. package/dist/dispatch/resolve.js.map +1 -0
  101. package/dist/dispatch/self.d.ts +27 -0
  102. package/dist/dispatch/self.d.ts.map +1 -0
  103. package/dist/dispatch/self.js +25 -0
  104. package/dist/dispatch/self.js.map +1 -0
  105. package/dist/dispatch/validate.d.ts +35 -0
  106. package/dist/dispatch/validate.d.ts.map +1 -0
  107. package/dist/dispatch/validate.js +27 -0
  108. package/dist/dispatch/validate.js.map +1 -0
  109. package/dist/domain/build-spec.d.ts +37 -0
  110. package/dist/domain/build-spec.d.ts.map +1 -0
  111. package/dist/domain/build-spec.js +95 -0
  112. package/dist/domain/build-spec.js.map +1 -0
  113. package/dist/domain/contract.d.ts +17 -0
  114. package/dist/domain/contract.d.ts.map +1 -0
  115. package/dist/domain/contract.js +26 -0
  116. package/dist/domain/contract.js.map +1 -0
  117. package/dist/domain/define.d.ts +82 -0
  118. package/dist/domain/define.d.ts.map +1 -0
  119. package/dist/domain/define.js +99 -0
  120. package/dist/domain/define.js.map +1 -0
  121. package/dist/domain/extend-core.d.ts +49 -0
  122. package/dist/domain/extend-core.d.ts.map +1 -0
  123. package/dist/domain/extend-core.js +182 -0
  124. package/dist/domain/extend-core.js.map +1 -0
  125. package/dist/domain/index.d.ts +5 -0
  126. package/dist/domain/index.d.ts.map +1 -0
  127. package/dist/domain/index.js +4 -0
  128. package/dist/domain/index.js.map +1 -0
  129. package/dist/index.d.ts +19 -0
  130. package/dist/index.d.ts.map +1 -0
  131. package/dist/index.js +32 -0
  132. package/dist/index.js.map +1 -0
  133. package/dist/method/class.d.ts +70 -0
  134. package/dist/method/class.d.ts.map +1 -0
  135. package/dist/method/class.js +26 -0
  136. package/dist/method/class.js.map +1 -0
  137. package/dist/method/context.d.ts +43 -0
  138. package/dist/method/context.d.ts.map +1 -0
  139. package/dist/method/context.js +10 -0
  140. package/dist/method/context.js.map +1 -0
  141. package/dist/method/index.d.ts +6 -0
  142. package/dist/method/index.d.ts.map +1 -0
  143. package/dist/method/index.js +3 -0
  144. package/dist/method/index.js.map +1 -0
  145. package/dist/method/single.d.ts +88 -0
  146. package/dist/method/single.d.ts.map +1 -0
  147. package/dist/method/single.js +18 -0
  148. package/dist/method/single.js.map +1 -0
  149. package/dist/server/auxiliary-routes.d.ts +44 -0
  150. package/dist/server/auxiliary-routes.d.ts.map +1 -0
  151. package/dist/server/auxiliary-routes.js +239 -0
  152. package/dist/server/auxiliary-routes.js.map +1 -0
  153. package/dist/server/config.d.ts +83 -0
  154. package/dist/server/config.d.ts.map +1 -0
  155. package/dist/server/config.js +8 -0
  156. package/dist/server/config.js.map +1 -0
  157. package/dist/server/create.d.ts +21 -0
  158. package/dist/server/create.d.ts.map +1 -0
  159. package/dist/server/create.js +210 -0
  160. package/dist/server/create.js.map +1 -0
  161. package/dist/server/handle.d.ts +35 -0
  162. package/dist/server/handle.d.ts.map +1 -0
  163. package/dist/server/handle.js +9 -0
  164. package/dist/server/handle.js.map +1 -0
  165. package/dist/server/index.d.ts +11 -0
  166. package/dist/server/index.d.ts.map +1 -0
  167. package/dist/server/index.js +8 -0
  168. package/dist/server/index.js.map +1 -0
  169. package/dist/server/jwks.d.ts +11 -0
  170. package/dist/server/jwks.d.ts.map +1 -0
  171. package/dist/server/jwks.js +15 -0
  172. package/dist/server/jwks.js.map +1 -0
  173. package/dist/server/require-env.d.ts +15 -0
  174. package/dist/server/require-env.d.ts.map +1 -0
  175. package/dist/server/require-env.js +21 -0
  176. package/dist/server/require-env.js.map +1 -0
  177. package/dist/server/serving-url.d.ts +14 -0
  178. package/dist/server/serving-url.d.ts.map +1 -0
  179. package/dist/server/serving-url.js +28 -0
  180. package/dist/server/serving-url.js.map +1 -0
  181. package/dist/server/start.d.ts +11 -0
  182. package/dist/server/start.d.ts.map +1 -0
  183. package/dist/server/start.js +34 -0
  184. package/dist/server/start.js.map +1 -0
  185. package/dist/server/worker-entry.d.ts +60 -0
  186. package/dist/server/worker-entry.d.ts.map +1 -0
  187. package/dist/server/worker-entry.js +79 -0
  188. package/dist/server/worker-entry.js.map +1 -0
  189. package/dist/server/worker-meta.d.ts +6 -0
  190. package/dist/server/worker-meta.d.ts.map +1 -0
  191. package/dist/server/worker-meta.js +10 -0
  192. package/dist/server/worker-meta.js.map +1 -0
  193. package/package.json +5 -5
  194. package/src/auth/compose.ts +27 -2
  195. package/src/auth/kernel-client.ts +103 -11
  196. package/src/define/remote-function.ts +10 -0
  197. package/src/server/auxiliary-routes.ts +3 -1
  198. package/src/server/start.ts +5 -1
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hash a `spec.json` file deterministically. Only the schema payload
3
+ * (`nodes` + `edges`) is hashed — the `meta` block carries `builtAt`
4
+ * timestamps that would poison drift detection.
5
+ *
6
+ * Returns `sha256:<hex>`.
7
+ */
8
+ export declare function hashSpecFile(path: string): string;
9
+ //# sourceMappingURL=hash-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-spec.d.ts","sourceRoot":"","sources":["../../src/deploy/hash-spec.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKjD"}
@@ -0,0 +1,29 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
3
+ const HASH_ALGORITHM = 'sha256';
4
+ /**
5
+ * Hash a `spec.json` file deterministically. Only the schema payload
6
+ * (`nodes` + `edges`) is hashed — the `meta` block carries `builtAt`
7
+ * timestamps that would poison drift detection.
8
+ *
9
+ * Returns `sha256:<hex>`.
10
+ */
11
+ export function hashSpecFile(path) {
12
+ const raw = readFileSync(path, 'utf-8');
13
+ const parsed = JSON.parse(raw);
14
+ const canonical = canonicalJson({ nodes: parsed.nodes ?? [], edges: parsed.edges ?? [] });
15
+ return `${HASH_ALGORITHM}:${createHash(HASH_ALGORITHM).update(canonical).digest('hex')}`;
16
+ }
17
+ function canonicalJson(value) {
18
+ if (value === null || typeof value !== 'object')
19
+ return JSON.stringify(value);
20
+ if (Array.isArray(value))
21
+ return '[' + value.map(canonicalJson).join(',') + ']';
22
+ const keys = Object.keys(value).sort();
23
+ return ('{' +
24
+ keys
25
+ .map((k) => JSON.stringify(k) + ':' + canonicalJson(value[k]))
26
+ .join(',') +
27
+ '}');
28
+ }
29
+ //# sourceMappingURL=hash-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-spec.js","sourceRoot":"","sources":["../../src/deploy/hash-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,cAAc,GAAG,QAAQ,CAAA;AAE/B;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyC,CAAA;IACtE,MAAM,SAAS,GAAG,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,CAAA;IACzF,OAAO,GAAG,cAAc,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;AAC1F,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;IAC/E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC,IAAI,EAAE,CAAA;IACjE,OAAO,CACL,GAAG;QACH,IAAI;aACD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,aAAa,CAAE,KAAiC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1F,IAAI,CAAC,GAAG,CAAC;QACZ,GAAG,CACJ,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { MetaSchema, type Meta } from './meta';
2
+ export { hashSpecFile } from './hash-spec';
3
+ export { deployCheck, type DeployCheckOptions } from './check';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/deploy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { MetaSchema } from './meta';
2
+ export { hashSpecFile } from './hash-spec';
3
+ export { deployCheck } from './check';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/deploy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,QAAQ,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAA2B,MAAM,SAAS,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `/meta` payload — the contract between `createRemoteServer` (producer)
3
+ * and `deployCheck` (verifier). Both sides parse through `MetaSchema`, so
4
+ * a new field added here flows to both paths and drift is caught at the
5
+ * boundary rather than silently skipped.
6
+ *
7
+ * Scope: **domain workers only**. Kernels rely on OIDC discovery
8
+ * (`/.well-known/openid-configuration`) + JWKS — they have no `/meta`.
9
+ */
10
+ import { z } from 'zod';
11
+ export declare const MetaSchema: z.ZodObject<{
12
+ iss: z.ZodString;
13
+ sdkCommit: z.ZodOptional<z.ZodString>;
14
+ schemaHash: z.ZodOptional<z.ZodString>;
15
+ domainName: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strip>;
17
+ export type Meta = z.infer<typeof MetaSchema>;
18
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/deploy/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,UAAU;;;;;iBAUrB,CAAA;AAEF,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `/meta` payload — the contract between `createRemoteServer` (producer)
3
+ * and `deployCheck` (verifier). Both sides parse through `MetaSchema`, so
4
+ * a new field added here flows to both paths and drift is caught at the
5
+ * boundary rather than silently skipped.
6
+ *
7
+ * Scope: **domain workers only**. Kernels rely on OIDC discovery
8
+ * (`/.well-known/openid-configuration`) + JWKS — they have no `/meta`.
9
+ */
10
+ import { z } from 'zod';
11
+ export const MetaSchema = z.object({
12
+ /** Base URL where JWKS is published. Always stamped by `createRemoteServer`
13
+ * and required by `deployCheck` to verify JWKS reachability. */
14
+ iss: z.string().min(1),
15
+ /** Short git SHA of the SDK used to build the worker. */
16
+ sdkCommit: z.string().optional(),
17
+ /** Deterministic hash of the compiled spec (`sha256:<hex>`). */
18
+ schemaHash: z.string().optional(),
19
+ /** Local directory name under `kernel/domains/<...>/` — used to auto-resolve the local spec. */
20
+ domainName: z.string().optional(),
21
+ });
22
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/deploy/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC;qEACiE;IACjE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,yDAAyD;IACzD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,gEAAgE;IAChE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,gGAAgG;IAChG,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Shared `authorize`-hook runner.
3
+ *
4
+ * Both the method dispatcher (`dispatcher.ts`) and the worker-side aux routes
5
+ * (`server/auxiliary-routes.ts`) let an author deny a call by throwing from an
6
+ * `authorize` hook. They MUST agree on the wire semantics: an already-typed
7
+ * `AuthorizationDeniedError` passes through unchanged (so callers can attach
8
+ * hints), and any other thrown error is wrapped into `AuthorizationDeniedError`
9
+ * (→ `PERMISSION_DENIED` / HTTP 403). Centralised here so the two call sites
10
+ * cannot drift — previously the aux routes awaited `authorize` directly, so a
11
+ * plain `Error` thrown to deny leaked out as a 500 instead of a 403.
12
+ */
13
+ export declare function runAuthorize<C>(hook: (ctx: C) => void | Promise<void>, ctx: C): Promise<void>;
14
+ //# sourceMappingURL=authorize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../src/dispatch/authorize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACtC,GAAG,EAAE,CAAC,GACL,OAAO,CAAC,IAAI,CAAC,CAUf"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared `authorize`-hook runner.
3
+ *
4
+ * Both the method dispatcher (`dispatcher.ts`) and the worker-side aux routes
5
+ * (`server/auxiliary-routes.ts`) let an author deny a call by throwing from an
6
+ * `authorize` hook. They MUST agree on the wire semantics: an already-typed
7
+ * `AuthorizationDeniedError` passes through unchanged (so callers can attach
8
+ * hints), and any other thrown error is wrapped into `AuthorizationDeniedError`
9
+ * (→ `PERMISSION_DENIED` / HTTP 403). Centralised here so the two call sites
10
+ * cannot drift — previously the aux routes awaited `authorize` directly, so a
11
+ * plain `Error` thrown to deny leaked out as a 500 instead of a 403.
12
+ */
13
+ import { AuthorizationDeniedError } from './errors';
14
+ export async function runAuthorize(hook, ctx) {
15
+ try {
16
+ await hook(ctx);
17
+ }
18
+ catch (err) {
19
+ if (err instanceof AuthorizationDeniedError)
20
+ throw err;
21
+ throw new AuthorizationDeniedError(err instanceof Error ? err.message : 'Authorization denied', err);
22
+ }
23
+ }
24
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/dispatch/authorize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAEnD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAsC,EACtC,GAAM;IAEN,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,GAAG,CAAC,CAAA;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,wBAAwB;YAAE,MAAM,GAAG,CAAA;QACtD,MAAM,IAAI,wBAAwB,CAChC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,EAC3D,GAAG,CACJ,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `ctx.callRemote` — call ANOTHER worker's remote method from a handler.
3
+ *
4
+ * A worker's `kernel.call('/dom/class.X/method', …)` signs `aud = <kernel>`,
5
+ * which is correct for a **kernel syscall** (it runs in the kernel) but is
6
+ * rejected by a **remote method** (a Function with `binding.remoteUrl`, i.e.
7
+ * another worker) — the target worker verifies `aud` against its own identity
8
+ * and throws `Credential audience mismatch` at authentication.
9
+ *
10
+ * `callRemote` is now a thin wrapper over the bound kernel session: the kernel
11
+ * resolves a remote-bound path to a redirect carrying the worker's URL and its
12
+ * `iss`, and the session (configured in `bindKernel`) follows it reactively —
13
+ * minting a kernel-signed delegation envelope scoped to that `iss` via the
14
+ * caller's own `@<subject>::mintDelegationCredential`, then dialing the worker.
15
+ * Instance-method `self` is injected by the kernel resolver into the redirect,
16
+ * so a bare `kernel.call(path, params)` is all that's needed here.
17
+ *
18
+ * Prerequisite (authorization, unchanged): the calling Function's identity must
19
+ * hold `USE` on `Identity.mintDelegationCredential` AND the target method's own
20
+ * grants — the session only fixes the audience (authentication), not grants.
21
+ */
22
+ import type { ClientSessionCallOptions } from '@astrale-os/kernel-client/session';
23
+ /** Minimal kernel-call surface callRemote needs (the bound view satisfies it). */
24
+ type KernelCaller = {
25
+ call: (method: string, params: unknown, opts?: ClientSessionCallOptions) => Promise<unknown>;
26
+ };
27
+ export type CallRemoteFn = (path: string, params?: Record<string, unknown>) => Promise<unknown>;
28
+ /**
29
+ * Build the `callRemote` helper for one handler invocation. `kernel` is the
30
+ * handler's bound kernel view (or `null` for a public/unauthenticated request,
31
+ * where `callRemote` cannot mint and throws on use).
32
+ */
33
+ export declare function makeCallRemote(kernel: KernelCaller | null): CallRemoteFn;
34
+ export {};
35
+ //# sourceMappingURL=call-remote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-remote.d.ts","sourceRoot":"","sources":["../../src/dispatch/call-remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAEjF,kFAAkF;AAClF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7F,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/F;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,YAAY,CAWxE"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `ctx.callRemote` — call ANOTHER worker's remote method from a handler.
3
+ *
4
+ * A worker's `kernel.call('/dom/class.X/method', …)` signs `aud = <kernel>`,
5
+ * which is correct for a **kernel syscall** (it runs in the kernel) but is
6
+ * rejected by a **remote method** (a Function with `binding.remoteUrl`, i.e.
7
+ * another worker) — the target worker verifies `aud` against its own identity
8
+ * and throws `Credential audience mismatch` at authentication.
9
+ *
10
+ * `callRemote` is now a thin wrapper over the bound kernel session: the kernel
11
+ * resolves a remote-bound path to a redirect carrying the worker's URL and its
12
+ * `iss`, and the session (configured in `bindKernel`) follows it reactively —
13
+ * minting a kernel-signed delegation envelope scoped to that `iss` via the
14
+ * caller's own `@<subject>::mintDelegationCredential`, then dialing the worker.
15
+ * Instance-method `self` is injected by the kernel resolver into the redirect,
16
+ * so a bare `kernel.call(path, params)` is all that's needed here.
17
+ *
18
+ * Prerequisite (authorization, unchanged): the calling Function's identity must
19
+ * hold `USE` on `Identity.mintDelegationCredential` AND the target method's own
20
+ * grants — the session only fixes the audience (authentication), not grants.
21
+ */
22
+ /**
23
+ * Build the `callRemote` helper for one handler invocation. `kernel` is the
24
+ * handler's bound kernel view (or `null` for a public/unauthenticated request,
25
+ * where `callRemote` cannot mint and throws on use).
26
+ */
27
+ export function makeCallRemote(kernel) {
28
+ return async (path, params = {}) => {
29
+ if (!kernel) {
30
+ throw new Error('callRemote requires an authenticated request — no kernel credential (public method?)');
31
+ }
32
+ // The bound session auto-follows the kernel's redirect and mints for the
33
+ // worker's `iss`; a remote-bound path therefore just works as a kernel.call.
34
+ return kernel.call(path, params);
35
+ };
36
+ }
37
+ //# sourceMappingURL=call-remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-remote.js","sourceRoot":"","sources":["../../src/dispatch/call-remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAA2B;IACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,EAAE,EAAE;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,sFAAsF,CACvF,CAAA;QACH,CAAC;QACD,yEAAyE;QACzE,6EAA6E;QAC7E,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `SdkDispatcher` — implements `KernelAPI` by running the SDK's pipeline.
3
+ *
4
+ * Built once at server startup from the domain's `CompiledDomain` plus a typed
5
+ * deps container and a private JWK. Per-method identity configs are
6
+ * pre-resolved into a Map so dispatch is O(1) per call.
7
+ *
8
+ * Pipeline per call:
9
+ * resolve method → authenticate → validate → resolve self → execute
10
+ */
11
+ import type { AuthedKernelAPI, DispatchResult, KernelAPI } from '@astrale-os/kernel-api';
12
+ import type { CredentialInput, Path } from '@astrale-os/kernel-core';
13
+ import type { CompiledDomain } from '@astrale-os/kernel-core/domain';
14
+ import type { MethodIndex } from './resolve';
15
+ export type SdkDispatcherConfig<TDeps> = {
16
+ /** The compiled domain — source of the method layout and origin-addressed subs. */
17
+ compiled: CompiledDomain;
18
+ /** Pre-built method map: ref → BoundMethod. */
19
+ methods: MethodIndex;
20
+ /** Dependency container injected into every handler. */
21
+ deps: TDeps;
22
+ /** Private key for signing outbound per-function credentials. */
23
+ privateKey: JsonWebKey;
24
+ /**
25
+ * The worker's identity (`iss`) for outbound per-function credentials — its
26
+ * serving URL (e.g. `https://crm.test.com`), DECOUPLED from the domain's
27
+ * addressing `origin`. Matches the `iss` the kernel pins on each node at
28
+ * install (the URL it fetched the domain at).
29
+ */
30
+ issuer: string;
31
+ /** The worker's serving URL (`config.url`) — exposed to handlers as `ctx.url`. */
32
+ url: string;
33
+ };
34
+ export declare class SdkDispatcher<TDeps = unknown> implements KernelAPI {
35
+ private readonly methods;
36
+ private readonly deps;
37
+ private readonly identities;
38
+ private readonly issuer;
39
+ private readonly url;
40
+ private readonly privateKey;
41
+ constructor(config: SdkDispatcherConfig<TDeps>);
42
+ call(path: Path | string, credential: CredentialInput, params: unknown, opts?: {
43
+ self?: string;
44
+ }): Promise<unknown>;
45
+ stream(path: Path | string, credential: CredentialInput, params: unknown, opts?: {
46
+ self?: string;
47
+ }): Promise<AsyncGenerator<unknown>>;
48
+ /**
49
+ * SDK dispatch never redirects — the SDK server IS the remote destination.
50
+ * Every call resolves locally; we just classify the return as value or stream
51
+ * and hand it back to the kernel-api orchestrator.
52
+ */
53
+ dispatch(path: Path | string, credential: CredentialInput, params: unknown, opts?: {
54
+ self?: string;
55
+ }): Promise<DispatchResult>;
56
+ as(credential: CredentialInput): AuthedKernelAPI;
57
+ private run;
58
+ private identityFor;
59
+ }
60
+ //# sourceMappingURL=dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/dispatch/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAExF,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAIjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAY5C,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI;IACvC,mFAAmF;IACnF,QAAQ,EAAE,cAAc,CAAA;IACxB,+CAA+C;IAC/C,OAAO,EAAE,WAAW,CAAA;IACpB,wDAAwD;IACxD,IAAI,EAAE,KAAK,CAAA;IACX,iEAAiE;IACjE,UAAU,EAAE,UAAU,CAAA;IACtB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAA;IACd,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,qBAAa,aAAa,CAAC,KAAK,GAAG,OAAO,CAAE,YAAW,SAAS;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0D;IACrF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC,YAAY,MAAM,EAAE,mBAAmB,CAAC,KAAK,CAAC,EAY7C;IAEK,IAAI,CACR,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,OAAO,CAAC,OAAO,CAAC,CAElB;IAEK,MAAM,CACV,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAMlC;IAED;;;;OAIG;IACG,QAAQ,CACZ,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,OAAO,CAAC,cAAc,CAAC,CAKzB;IAED,EAAE,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,CAK/C;YAEa,GAAG;IA0EjB,OAAO,CAAC,WAAW;CAapB"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * `SdkDispatcher` — implements `KernelAPI` by running the SDK's pipeline.
3
+ *
4
+ * Built once at server startup from the domain's `CompiledDomain` plus a typed
5
+ * deps container and a private JWK. Per-method identity configs are
6
+ * pre-resolved into a Map so dispatch is O(1) per call.
7
+ *
8
+ * Pipeline per call:
9
+ * resolve method → authenticate → validate → resolve self → execute
10
+ */
11
+ import { resolveInboundAuth } from '../auth/resolve';
12
+ import { runAuthorize } from './authorize';
13
+ import { makeCallRemote } from './call-remote';
14
+ import { MethodNotFoundError, SdkResultValidationError, SdkValidationError } from './errors';
15
+ import { executeHandler } from './execute';
16
+ import { buildIdentityMap } from './identity';
17
+ import { resolveMethod } from './resolve';
18
+ import { resolveSelf } from './self';
19
+ import { validateParams, validateResult } from './validate';
20
+ export class SdkDispatcher {
21
+ methods;
22
+ deps;
23
+ identities;
24
+ issuer;
25
+ url;
26
+ privateKey;
27
+ constructor(config) {
28
+ this.methods = config.methods;
29
+ this.deps = config.deps;
30
+ this.issuer = config.issuer;
31
+ this.url = config.url;
32
+ this.privateKey = config.privateKey;
33
+ const methodList = Array.from(new Set(config.methods.values()));
34
+ const identityMethods = methodList.filter((bound) => methodAuthPolicy(bound) !== 'public');
35
+ this.identities =
36
+ identityMethods.length > 0
37
+ ? buildIdentityMap(config.compiled, identityMethods, config.privateKey, config.issuer)
38
+ : new Map();
39
+ }
40
+ async call(path, credential, params, opts) {
41
+ return this.run(path, credential, params, opts?.self);
42
+ }
43
+ async stream(path, credential, params, opts) {
44
+ const result = await this.run(path, credential, params, opts?.self);
45
+ if (!isAsyncGenerator(result)) {
46
+ throw new Error(`Method "${pathToString(path)}" did not return an async generator`);
47
+ }
48
+ return result;
49
+ }
50
+ /**
51
+ * SDK dispatch never redirects — the SDK server IS the remote destination.
52
+ * Every call resolves locally; we just classify the return as value or stream
53
+ * and hand it back to the kernel-api orchestrator.
54
+ */
55
+ async dispatch(path, credential, params, opts) {
56
+ const result = await this.run(path, credential, params, opts?.self);
57
+ return isAsyncGenerator(result)
58
+ ? { kind: 'stream', generator: result }
59
+ : { kind: 'value', value: result };
60
+ }
61
+ as(credential) {
62
+ return {
63
+ call: (path, params) => this.call(path, credential, params),
64
+ stream: (path, params) => this.stream(path, credential, params),
65
+ };
66
+ }
67
+ async run(path, credential, params, selfRef) {
68
+ const bound = resolveMethod(this.methods, path);
69
+ if (!bound)
70
+ throw new MethodNotFoundError(pathToString(path));
71
+ const authPolicy = bound.handler.auth ?? 'required';
72
+ const fnIdentity = this.identityFor(bound);
73
+ const { auth, kernel } = await resolveInboundAuth(credential, authPolicy, fnIdentity);
74
+ if (typeof params !== 'object' || params === null || Array.isArray(params)) {
75
+ throw new SdkValidationError([{ path: [], message: 'Params must be a plain object' }]);
76
+ }
77
+ const validation = validateParams(bound.inputSchema, params);
78
+ if (!validation.ok) {
79
+ throw new SdkValidationError(validation.issues);
80
+ }
81
+ // `undefined` (not `null`) for static methods — matches the `self` type on
82
+ // `RemoteContext` / `MethodImpl`, which is `undefined` for static methods.
83
+ let resolvedSelf;
84
+ if (!bound.isStatic) {
85
+ if (selfRef === undefined || selfRef === null || selfRef === '') {
86
+ throw new SdkValidationError([{ path: ['self'], message: 'Required for non-static method' }], `"${bound.owner}.${bound.method}" is an instance method — it needs a target node. ` +
87
+ `Either call it via instance dispatch (e.g. "@<nodeId>::${bound.method}" ` +
88
+ `or "/path/to/node::${bound.method}"), or pass "self" in dispatch opts ` +
89
+ `(e.g. { self: "@<nodeId>" }).`);
90
+ }
91
+ try {
92
+ resolvedSelf = resolveSelf(String(selfRef));
93
+ }
94
+ catch (err) {
95
+ // A malformed caller-supplied `self` is bad client input, not a server
96
+ // fault — surface it as VALIDATION_ERROR (422), matching the sibling
97
+ // missing-self branch above, instead of INTERNAL_ERROR (500).
98
+ throw new SdkValidationError([
99
+ {
100
+ path: ['self'],
101
+ message: err instanceof Error ? err.message : 'Failed to resolve self',
102
+ },
103
+ ], `Invalid "self" target "${selfRef}": ${err instanceof Error ? err.message : 'unparseable path'}`);
104
+ }
105
+ }
106
+ const handler = bound.handler;
107
+ const handlerParams = validation.data;
108
+ const callRemote = makeCallRemote(kernel);
109
+ const ctx = {
110
+ params: handlerParams,
111
+ auth,
112
+ self: resolvedSelf,
113
+ deps: this.deps,
114
+ url: this.url,
115
+ kernel,
116
+ callRemote,
117
+ };
118
+ if (handler.authorize)
119
+ await runAuthorize(handler.authorize, ctx);
120
+ const result = await executeHandler({ handler, ref: bound.ref, ...ctx });
121
+ return validateOutput(bound, result);
122
+ }
123
+ identityFor(bound) {
124
+ const identity = this.identities.get(bound);
125
+ if (!identity) {
126
+ if (methodAuthPolicy(bound) === 'public') {
127
+ return { issuer: this.issuer, subject: bound.ref, privateKey: this.privateKey };
128
+ }
129
+ throw new Error(`SdkDispatcher: no identity config for "${bound.owner}.${bound.method}" — ` +
130
+ `method is registered in the index but missing from the identity map.`);
131
+ }
132
+ return identity;
133
+ }
134
+ }
135
+ function methodAuthPolicy(bound) {
136
+ return bound.handler.auth ?? 'required';
137
+ }
138
+ function pathToString(path) {
139
+ return typeof path === 'string' ? path : path.raw;
140
+ }
141
+ /**
142
+ * Validate a handler's output against `bound.outputSchema`, mirroring the
143
+ * kernel's dispatcher (`runtime/.../dispatcher.ts` + `events.ts`):
144
+ * - `binary` outputs skip validation (no schema applies).
145
+ * - async-generator outputs (`output: 'stream'`) are wrapped so each chunk
146
+ * is validated as it is yielded.
147
+ * - all other (`value`) outputs are validated once and returned parsed.
148
+ * Returns the synchronous shape (value or generator) so the caller's
149
+ * `dispatch()` can classify it without awaiting a stream to completion.
150
+ */
151
+ function validateOutput(bound, result) {
152
+ if (bound.output === 'binary')
153
+ return result;
154
+ if (isAsyncGenerator(result))
155
+ return validateOutputStream(bound, result);
156
+ return validateChunk(bound, result);
157
+ }
158
+ async function* validateOutputStream(bound, gen) {
159
+ for await (const chunk of gen) {
160
+ yield validateChunk(bound, chunk);
161
+ }
162
+ }
163
+ /** Parse one output value against `bound.outputSchema` or throw a 500-class error. */
164
+ function validateChunk(bound, value) {
165
+ const out = validateResult(bound.outputSchema, value);
166
+ if (!out.ok) {
167
+ throw new SdkResultValidationError(out.issues, bound.ref);
168
+ }
169
+ return out.data;
170
+ }
171
+ function isAsyncGenerator(value) {
172
+ return (value !== null &&
173
+ value !== undefined &&
174
+ typeof value === 'object' &&
175
+ Symbol.asyncIterator in value);
176
+ }
177
+ //# sourceMappingURL=dispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/dispatch/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,WAAW,EAAmB,MAAM,QAAQ,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAsB3D,MAAM,OAAO,aAAa;IACP,OAAO,CAAa;IACpB,IAAI,CAAO;IACX,UAAU,CAA0D;IACpE,MAAM,CAAQ;IACd,GAAG,CAAQ;IACX,UAAU,CAAY;IAEvC,YAAY,MAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA;QACrB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAA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
5
+ * convert them into typed `KernelErrorPayload` values automatically.
6
+ */
7
+ import type { KernelErrorPayload, KernelErrorClassifiable } from '@astrale-os/kernel-api';
8
+ /** A single Zod issue, normalized to the path/message the payload carries. */
9
+ type ValidationIssue = {
10
+ path: (string | number)[];
11
+ message: string;
12
+ };
13
+ export declare class MethodNotFoundError extends Error implements KernelErrorClassifiable {
14
+ constructor(method: string);
15
+ toKernelErrorPayload(): KernelErrorPayload;
16
+ }
17
+ export declare class SdkValidationError extends Error implements KernelErrorClassifiable {
18
+ readonly issues: ValidationIssue[];
19
+ constructor(issues: ValidationIssue[], message?: string);
20
+ toKernelErrorPayload(): KernelErrorPayload;
21
+ }
22
+ /**
23
+ * Thrown when a handler's return value (or a stream chunk) fails validation
24
+ * against its `outputSchema`. This is a server/handler fault — the author's
25
+ * code produced data that violates its own declared contract — so it maps to
26
+ * `INTERNAL_ERROR` (→ HTTP 500), NOT the `VALIDATION_ERROR` (422) used for
27
+ * bad caller input. Mirrors the kernel's `ResultValidationError`.
28
+ */
29
+ export declare class SdkResultValidationError extends Error implements KernelErrorClassifiable {
30
+ readonly issues: ValidationIssue[];
31
+ readonly ref?: string | undefined;
32
+ constructor(issues: ValidationIssue[], ref?: string | undefined);
33
+ toKernelErrorPayload(): KernelErrorPayload;
34
+ }
35
+ /**
36
+ * Thrown by a `RemoteHandler.authorize` hook to deny a call.
37
+ *
38
+ * Wraps any error the hook throws — handlers can throw a plain `Error` and
39
+ * the dispatcher converts it. Already-typed `AuthorizationDeniedError`
40
+ * instances are passed through unchanged so callers can attach hints.
41
+ */
42
+ export declare class AuthorizationDeniedError extends Error implements KernelErrorClassifiable {
43
+ constructor(message: string, cause?: unknown);
44
+ toKernelErrorPayload(): KernelErrorPayload;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/dispatch/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAIzF,8EAA8E;AAC9E,KAAK,eAAe,GAAG;IAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAWrE,qBAAa,mBAAoB,SAAQ,KAAM,YAAW,uBAAuB;IAC/E,YAAY,MAAM,EAAE,MAAM,EAGzB;IAED,oBAAoB,IAAI,kBAAkB,CAEzC;CACF;AAED,qBAAa,kBAAmB,SAAQ,KAAM,YAAW,uBAAuB;IAE5E,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE;IADpC,YACW,MAAM,EAAE,eAAe,EAAE,EAClC,OAAO,CAAC,EAAE,MAAM,EAIjB;IAED,oBAAoB,IAAI,kBAAkB,CAMzC;CACF;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,KAAM,YAAW,uBAAuB;IAElF,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM;IAFvB,YACW,MAAM,EAAE,eAAe,EAAE,EACzB,GAAG,CAAC,EAAE,MAAM,YAAA,EAItB;IAED,oBAAoB,IAAI,kBAAkB,CAMzC;CACF;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,KAAM,YAAW,uBAAuB;IACpF,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAG3C;IAED,oBAAoB,IAAI,kBAAkB,CAEzC;CACF"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Errors thrown by the dispatch pipeline.
3
+ *
4
+ * Each implements `KernelErrorClassifiable` so `kernel-api/dispatch` can
5
+ * convert them into typed `KernelErrorPayload` values automatically.
6
+ */
7
+ import { KERNEL_ERROR_CODES } from '@astrale-os/kernel-api';
8
+ /** Shape Zod issues into the `data.errors` array of a `KernelErrorPayload`. */
9
+ function toPayloadErrors(issues) {
10
+ return issues.map((i) => ({ path: i.path, code: 'INVALID', message: i.message }));
11
+ }
12
+ export class MethodNotFoundError extends Error {
13
+ constructor(method) {
14
+ super(`Method not found: ${method}`);
15
+ this.name = 'MethodNotFoundError';
16
+ }
17
+ toKernelErrorPayload() {
18
+ return { code: KERNEL_ERROR_CODES.METHOD_NOT_FOUND, message: this.message };
19
+ }
20
+ }
21
+ export class SdkValidationError extends Error {
22
+ issues;
23
+ constructor(issues, message) {
24
+ super(message ?? 'Invalid params');
25
+ this.issues = issues;
26
+ this.name = 'SdkValidationError';
27
+ }
28
+ toKernelErrorPayload() {
29
+ return {
30
+ code: KERNEL_ERROR_CODES.VALIDATION_ERROR,
31
+ message: this.message,
32
+ data: { errors: toPayloadErrors(this.issues) },
33
+ };
34
+ }
35
+ }
36
+ /**
37
+ * Thrown when a handler's return value (or a stream chunk) fails validation
38
+ * against its `outputSchema`. This is a server/handler fault — the author's
39
+ * code produced data that violates its own declared contract — so it maps to
40
+ * `INTERNAL_ERROR` (→ HTTP 500), NOT the `VALIDATION_ERROR` (422) used for
41
+ * bad caller input. Mirrors the kernel's `ResultValidationError`.
42
+ */
43
+ export class SdkResultValidationError extends Error {
44
+ issues;
45
+ ref;
46
+ constructor(issues, ref) {
47
+ super(`Function${ref ? ` "${ref}"` : ''} returned an invalid result`);
48
+ this.issues = issues;
49
+ this.ref = ref;
50
+ this.name = 'SdkResultValidationError';
51
+ }
52
+ toKernelErrorPayload() {
53
+ return {
54
+ code: KERNEL_ERROR_CODES.INTERNAL_ERROR,
55
+ message: this.message,
56
+ data: { errors: toPayloadErrors(this.issues) },
57
+ };
58
+ }
59
+ }
60
+ /**
61
+ * Thrown by a `RemoteHandler.authorize` hook to deny a call.
62
+ *
63
+ * Wraps any error the hook throws — handlers can throw a plain `Error` and
64
+ * the dispatcher converts it. Already-typed `AuthorizationDeniedError`
65
+ * instances are passed through unchanged so callers can attach hints.
66
+ */
67
+ export class AuthorizationDeniedError extends Error {
68
+ constructor(message, cause) {
69
+ super(message, { cause });
70
+ this.name = 'AuthorizationDeniedError';
71
+ }
72
+ toKernelErrorPayload() {
73
+ return { code: KERNEL_ERROR_CODES.PERMISSION_DENIED, message: this.message };
74
+ }
75
+ }
76
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/dispatch/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAK3D,+EAA+E;AAC/E,SAAS,eAAe,CAAC,MAAyB;IAKhD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AACnF,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,MAAc;QACxB,KAAK,CAAC,qBAAqB,MAAM,EAAE,CAAC,CAAA;QACpC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;IAED,oBAAoB;QAClB,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA;IAC7E,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEhC,MAAM;IADjB,YACW,MAAyB,EAClC,OAAgB;QAEhB,KAAK,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAA;sBAHzB,MAAM;QAIf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;IAED,oBAAoB;QAClB,OAAO;YACL,IAAI,EAAE,kBAAkB,CAAC,gBAAgB;YACzC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,EAAE,MA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