@astrale-os/sdk 0.1.1 → 0.1.2
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/auth/authenticate.d.ts +24 -0
- package/dist/auth/authenticate.d.ts.map +1 -0
- package/dist/auth/authenticate.js +29 -0
- package/dist/auth/authenticate.js.map +1 -0
- package/dist/auth/check.d.ts +39 -0
- package/dist/auth/check.d.ts.map +1 -0
- package/dist/auth/check.js +54 -0
- package/dist/auth/check.js.map +1 -0
- package/dist/auth/compose.d.ts +22 -0
- package/dist/auth/compose.d.ts.map +1 -0
- package/dist/auth/compose.js +23 -0
- package/dist/auth/compose.js.map +1 -0
- package/dist/auth/errors.d.ts +16 -0
- package/dist/auth/errors.d.ts.map +1 -0
- package/dist/auth/errors.js +26 -0
- package/dist/auth/errors.js.map +1 -0
- package/dist/auth/identity.d.ts +16 -0
- package/dist/auth/identity.d.ts.map +1 -0
- package/dist/auth/identity.js +2 -0
- package/dist/auth/identity.js.map +1 -0
- package/dist/auth/index.d.ts +12 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/kernel-client.d.ts +28 -0
- package/dist/auth/kernel-client.d.ts.map +1 -0
- package/dist/auth/kernel-client.js +84 -0
- package/dist/auth/kernel-client.js.map +1 -0
- package/dist/auth/resolve.d.ts +19 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +43 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/sign.d.ts +15 -0
- package/dist/auth/sign.d.ts.map +1 -0
- package/dist/auth/sign.js +24 -0
- package/dist/auth/sign.js.map +1 -0
- package/dist/auth/verify.d.ts +26 -0
- package/dist/auth/verify.d.ts.map +1 -0
- package/dist/auth/verify.js +96 -0
- package/dist/auth/verify.js.map +1 -0
- package/dist/define/index.d.ts +5 -0
- package/dist/define/index.d.ts.map +1 -0
- package/dist/define/index.js +3 -0
- package/dist/define/index.js.map +1 -0
- package/dist/define/remote-function.d.ts +86 -0
- package/dist/define/remote-function.d.ts.map +1 -0
- package/dist/define/remote-function.js +25 -0
- package/dist/define/remote-function.js.map +1 -0
- package/dist/define/view.d.ts +86 -0
- package/dist/define/view.d.ts.map +1 -0
- package/dist/define/view.js +28 -0
- package/dist/define/view.js.map +1 -0
- package/dist/deploy/check.d.ts +30 -0
- package/dist/deploy/check.d.ts.map +1 -0
- package/dist/deploy/check.js +82 -0
- package/dist/deploy/check.js.map +1 -0
- package/dist/deploy/hash-spec.d.ts +9 -0
- package/dist/deploy/hash-spec.d.ts.map +1 -0
- package/dist/deploy/hash-spec.js +29 -0
- package/dist/deploy/hash-spec.js.map +1 -0
- package/dist/deploy/index.d.ts +4 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +4 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/deploy/meta.d.ts +18 -0
- package/dist/deploy/meta.d.ts.map +1 -0
- package/dist/deploy/meta.js +22 -0
- package/dist/deploy/meta.js.map +1 -0
- package/dist/dispatch/authorize.d.ts +14 -0
- package/dist/dispatch/authorize.d.ts.map +1 -0
- package/dist/dispatch/authorize.js +24 -0
- package/dist/dispatch/authorize.js.map +1 -0
- package/dist/dispatch/call-remote.d.ts +35 -0
- package/dist/dispatch/call-remote.d.ts.map +1 -0
- package/dist/dispatch/call-remote.js +37 -0
- package/dist/dispatch/call-remote.js.map +1 -0
- package/dist/dispatch/dispatcher.d.ts +60 -0
- package/dist/dispatch/dispatcher.d.ts.map +1 -0
- package/dist/dispatch/dispatcher.js +177 -0
- package/dist/dispatch/dispatcher.js.map +1 -0
- package/dist/dispatch/errors.d.ts +47 -0
- package/dist/dispatch/errors.d.ts.map +1 -0
- package/dist/dispatch/errors.js +76 -0
- package/dist/dispatch/errors.js.map +1 -0
- package/dist/dispatch/execute.d.ts +33 -0
- package/dist/dispatch/execute.d.ts.map +1 -0
- package/dist/dispatch/execute.js +24 -0
- package/dist/dispatch/execute.js.map +1 -0
- package/dist/dispatch/identity.d.ts +73 -0
- package/dist/dispatch/identity.d.ts.map +1 -0
- package/dist/dispatch/identity.js +106 -0
- package/dist/dispatch/identity.js.map +1 -0
- package/dist/dispatch/index.d.ts +8 -0
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/dispatch/index.js +8 -0
- package/dist/dispatch/index.js.map +1 -0
- package/dist/dispatch/resolve.d.ts +27 -0
- package/dist/dispatch/resolve.d.ts.map +1 -0
- package/dist/dispatch/resolve.js +65 -0
- package/dist/dispatch/resolve.js.map +1 -0
- package/dist/dispatch/self.d.ts +27 -0
- package/dist/dispatch/self.d.ts.map +1 -0
- package/dist/dispatch/self.js +25 -0
- package/dist/dispatch/self.js.map +1 -0
- package/dist/dispatch/validate.d.ts +35 -0
- package/dist/dispatch/validate.d.ts.map +1 -0
- package/dist/dispatch/validate.js +27 -0
- package/dist/dispatch/validate.js.map +1 -0
- package/dist/domain/build-spec.d.ts +37 -0
- package/dist/domain/build-spec.d.ts.map +1 -0
- package/dist/domain/build-spec.js +95 -0
- package/dist/domain/build-spec.js.map +1 -0
- package/dist/domain/contract.d.ts +17 -0
- package/dist/domain/contract.d.ts.map +1 -0
- package/dist/domain/contract.js +26 -0
- package/dist/domain/contract.js.map +1 -0
- package/dist/domain/define.d.ts +82 -0
- package/dist/domain/define.d.ts.map +1 -0
- package/dist/domain/define.js +99 -0
- package/dist/domain/define.js.map +1 -0
- package/dist/domain/extend-core.d.ts +49 -0
- package/dist/domain/extend-core.d.ts.map +1 -0
- package/dist/domain/extend-core.js +182 -0
- package/dist/domain/extend-core.js.map +1 -0
- package/dist/domain/index.d.ts +5 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +4 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/method/class.d.ts +70 -0
- package/dist/method/class.d.ts.map +1 -0
- package/dist/method/class.js +26 -0
- package/dist/method/class.js.map +1 -0
- package/dist/method/context.d.ts +43 -0
- package/dist/method/context.d.ts.map +1 -0
- package/dist/method/context.js +10 -0
- package/dist/method/context.js.map +1 -0
- package/dist/method/index.d.ts +6 -0
- package/dist/method/index.d.ts.map +1 -0
- package/dist/method/index.js +3 -0
- package/dist/method/index.js.map +1 -0
- package/dist/method/single.d.ts +88 -0
- package/dist/method/single.d.ts.map +1 -0
- package/dist/method/single.js +18 -0
- package/dist/method/single.js.map +1 -0
- package/dist/server/auxiliary-routes.d.ts +44 -0
- package/dist/server/auxiliary-routes.d.ts.map +1 -0
- package/dist/server/auxiliary-routes.js +237 -0
- package/dist/server/auxiliary-routes.js.map +1 -0
- package/dist/server/config.d.ts +83 -0
- package/dist/server/config.d.ts.map +1 -0
- package/dist/server/config.js +8 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/create.d.ts +21 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/create.js +210 -0
- package/dist/server/create.js.map +1 -0
- package/dist/server/handle.d.ts +35 -0
- package/dist/server/handle.d.ts.map +1 -0
- package/dist/server/handle.js +9 -0
- package/dist/server/handle.js.map +1 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/jwks.d.ts +11 -0
- package/dist/server/jwks.d.ts.map +1 -0
- package/dist/server/jwks.js +15 -0
- package/dist/server/jwks.js.map +1 -0
- package/dist/server/require-env.d.ts +15 -0
- package/dist/server/require-env.d.ts.map +1 -0
- package/dist/server/require-env.js +21 -0
- package/dist/server/require-env.js.map +1 -0
- package/dist/server/serving-url.d.ts +14 -0
- package/dist/server/serving-url.d.ts.map +1 -0
- package/dist/server/serving-url.js +28 -0
- package/dist/server/serving-url.js.map +1 -0
- package/dist/server/start.d.ts +11 -0
- package/dist/server/start.d.ts.map +1 -0
- package/dist/server/start.js +30 -0
- package/dist/server/start.js.map +1 -0
- package/dist/server/worker-entry.d.ts +60 -0
- package/dist/server/worker-entry.d.ts.map +1 -0
- package/dist/server/worker-entry.js +79 -0
- package/dist/server/worker-entry.js.map +1 -0
- package/dist/server/worker-meta.d.ts +6 -0
- package/dist/server/worker-meta.d.ts.map +1 -0
- package/dist/server/worker-meta.js +10 -0
- package/dist/server/worker-meta.js.map +1 -0
- package/package.json +1 -1
|
@@ -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
|
+
//# source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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,eA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AC,CAAA;AACrC,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,oBAAoB,CAClC,KAAoC,EACpC,GAA4B;IAE5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QAC9B,MAAM,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACnC,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,SAAS,aAAa,CAAC,KAAoC,EAAE,KAAc;IACzE,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;IACrD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,wBAAwB,CAAC,GAAG,CAAC,MAA4C,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjG,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAA;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,CAAC,aAAa,IAAI,KAAK,CAC9B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 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,qBAA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,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;IAED,oBAAoB;QAClB,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA;IAC9E,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler execution — pipeline step 4.
|
|
3
|
+
*
|
|
4
|
+
* Calls the resolved handler's `execute` with a fully assembled
|
|
5
|
+
* `RemoteContext`: validated params, auth context, optional bound self,
|
|
6
|
+
* typed deps, and a kernel `BoundClientSessionView`. The handler may return a
|
|
7
|
+
* value, a Promise, or an async generator (for `output: 'stream'`).
|
|
8
|
+
*/
|
|
9
|
+
import type { FnMap } from '@astrale-os/kernel-client';
|
|
10
|
+
import type { BoundClientSessionView } from '@astrale-os/kernel-client/session';
|
|
11
|
+
import type { AuthContext } from '@astrale-os/kernel-core';
|
|
12
|
+
import type { CallRemoteFn } from './call-remote';
|
|
13
|
+
import type { SelfResult } from './self';
|
|
14
|
+
type HandlerFn = (...args: any[]) => any;
|
|
15
|
+
export type ExecuteParams = {
|
|
16
|
+
/** Handler may omit `execute` when authored as a stub (spec-only binding). */
|
|
17
|
+
handler: {
|
|
18
|
+
execute?: HandlerFn;
|
|
19
|
+
};
|
|
20
|
+
/** Namespaced ref of the dispatched method — names the offending method in the
|
|
21
|
+
* stub-leak diagnostic below (the dispatcher passes `bound.ref`). */
|
|
22
|
+
ref?: string;
|
|
23
|
+
params: Record<string, unknown>;
|
|
24
|
+
auth: AuthContext | null;
|
|
25
|
+
self: SelfResult | undefined;
|
|
26
|
+
deps: unknown;
|
|
27
|
+
url: string;
|
|
28
|
+
kernel: BoundClientSessionView<FnMap> | null;
|
|
29
|
+
callRemote: CallRemoteFn;
|
|
30
|
+
};
|
|
31
|
+
export declare function executeHandler(ctx: ExecuteParams): Promise<unknown>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/dispatch/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAGxC,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AAExC,MAAM,MAAM,aAAa,GAAG;IAC1B,8EAA8E;IAC9E,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;IAChC;0EACsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,IAAI,EAAE,WAAW,GAAG,IAAI,CAAA;IACxB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;IAC5B,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;IAC5C,UAAU,EAAE,YAAY,CAAA;CACzB,CAAA;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBzE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler execution — pipeline step 4.
|
|
3
|
+
*
|
|
4
|
+
* Calls the resolved handler's `execute` with a fully assembled
|
|
5
|
+
* `RemoteContext`: validated params, auth context, optional bound self,
|
|
6
|
+
* typed deps, and a kernel `BoundClientSessionView`. The handler may return a
|
|
7
|
+
* value, a Promise, or an async generator (for `output: 'stream'`).
|
|
8
|
+
*/
|
|
9
|
+
export async function executeHandler(ctx) {
|
|
10
|
+
if (typeof ctx.handler.execute !== 'function') {
|
|
11
|
+
throw new Error(`executeHandler: handler${ctx.ref ? ` for "${ctx.ref}"` : ''} has no \`execute\` body — ` +
|
|
12
|
+
`this is a binding stub that should have been resolved to a remote redirect upstream.`);
|
|
13
|
+
}
|
|
14
|
+
return ctx.handler.execute({
|
|
15
|
+
params: ctx.params,
|
|
16
|
+
auth: ctx.auth,
|
|
17
|
+
self: ctx.self,
|
|
18
|
+
deps: ctx.deps,
|
|
19
|
+
url: ctx.url,
|
|
20
|
+
kernel: ctx.kernel,
|
|
21
|
+
callRemote: ctx.callRemote,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/dispatch/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2BH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAkB;IACrD,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,0BAA0B,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,6BAA6B;YACvF,sFAAsF,CACzF,CAAA;IACH,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;QACzB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-callable identity — dispatcher runtime + install-time wiring.
|
|
3
|
+
*
|
|
4
|
+
* Two flavors of callable get an identity per the install-time identity
|
|
5
|
+
* binding: Methods on classes/interfaces (sub = MethodPath) and auto-
|
|
6
|
+
* materialized core function nodes — RemoteFunctions and Views (sub =
|
|
7
|
+
* AbsolutePath of the node under `core/{functions,views}/<slug>`).
|
|
8
|
+
*
|
|
9
|
+
* At server startup the method dispatcher and the View / RemoteFunction
|
|
10
|
+
* route mounter pre-compute, for every materialized callable, the
|
|
11
|
+
* `RemoteIdentityConfig` they sign outbound kernel calls with. The kernel
|
|
12
|
+
* then matches an existing function identity instead of provisioning a
|
|
13
|
+
* generic one.
|
|
14
|
+
*
|
|
15
|
+
* **Single source of truth:** every helper here is a thin lens over the
|
|
16
|
+
* canonical `resolveCallables` from `@astrale-os/kernel-core/domain`. The
|
|
17
|
+
* kernel validates install subs against the SAME function — drift = 0
|
|
18
|
+
* by construction. This closes the previous SDK-side gap where
|
|
19
|
+
* `collectMethodPaths` filtered to `own|override` and silently dropped
|
|
20
|
+
* `sealed`/`default` interface methods (which DO materialize as nodes).
|
|
21
|
+
*/
|
|
22
|
+
import type { BoundMethod, CompiledDomain } from '@astrale-os/kernel-core/domain';
|
|
23
|
+
import type { RemoteIdentityConfig } from '../auth/identity';
|
|
24
|
+
import type { AnyRemoteHandler } from '../method/single';
|
|
25
|
+
/**
|
|
26
|
+
* For each materialized method node, emit its `MethodPath` (semantic,
|
|
27
|
+
* layout-independent) keyed by the method's namespaced ref. Used to
|
|
28
|
+
* build the install `subs` claim and to look up runtime per-method
|
|
29
|
+
* subjects in `buildIdentityMap`.
|
|
30
|
+
*
|
|
31
|
+
* Includes every method node the kernel materializes — class own/override
|
|
32
|
+
* AND interface own (sealed/default/override). Inherited (non-overriding)
|
|
33
|
+
* class methods reuse the interface's node via a `method_of` edge and
|
|
34
|
+
* are correctly absent here.
|
|
35
|
+
*/
|
|
36
|
+
export declare function collectMethodPaths(compiled: CompiledDomain): Record<string, string>;
|
|
37
|
+
/** `{ views, remoteFunctions }` buckets keyed by slug — the shared shape
|
|
38
|
+
* for every per-aux-callable map (paths, identity configs). */
|
|
39
|
+
export type AuxBuckets<T> = {
|
|
40
|
+
views: Record<string, T>;
|
|
41
|
+
remoteFunctions: Record<string, T>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* slug → `AbsolutePath.raw` for each auto-materialized aux node
|
|
45
|
+
* (RemoteFunction / View). These nodes live at
|
|
46
|
+
* `/<origin>/core/{functions,views}/<slug>` and have no class+method
|
|
47
|
+
* decomposition that would justify a MethodPath — their identity is their
|
|
48
|
+
* graph position.
|
|
49
|
+
*/
|
|
50
|
+
export type AuxIdentityPaths = AuxBuckets<string>;
|
|
51
|
+
export declare function collectAuxIdentityPaths(compiled: CompiledDomain): AuxIdentityPaths;
|
|
52
|
+
/**
|
|
53
|
+
* slug → `RemoteIdentityConfig` for each auto-materialized View /
|
|
54
|
+
* RemoteFunction. Built once at server startup; consumed by
|
|
55
|
+
* `mountAuxiliaryRoutes` so each handler signs outbound `kernel.call(...)`
|
|
56
|
+
* with its own `sub` (the node's AbsolutePath). Mirrors `buildIdentityMap`.
|
|
57
|
+
*/
|
|
58
|
+
export type AuxIdentityMap = AuxBuckets<RemoteIdentityConfig>;
|
|
59
|
+
export declare function buildAuxIdentityMap(compiled: CompiledDomain, privateKey: JsonWebKey, issuer: string): AuxIdentityMap;
|
|
60
|
+
/**
|
|
61
|
+
* Pre-resolve per-method identity configs. Lookup is by BoundMethod instance,
|
|
62
|
+
* so the dispatcher pays O(1) per call instead of re-constructing the config.
|
|
63
|
+
*
|
|
64
|
+
* `iss` = the worker's own **serving URL** (`issuer` arg, e.g.
|
|
65
|
+
* `https://crm.test.com`) — its cryptographic identity, DECOUPLED from the
|
|
66
|
+
* domain's addressing `origin` (a graph slug). The kernel stamps the same
|
|
67
|
+
* value on each function node at install (it pins `iss` to the URL it fetched
|
|
68
|
+
* the domain at) and verifies inbound credentials against that issuer's JWKS
|
|
69
|
+
* (OIDC discovery). The function `sub` stays the origin-addressed MethodPath —
|
|
70
|
+
* `sub` = which function, `iss` = who signs.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildIdentityMap(compiled: CompiledDomain, methods: BoundMethod<AnyRemoteHandler>[], privateKey: JsonWebKey, issuer: string): Map<BoundMethod<AnyRemoteHandler>, RemoteIdentityConfig>;
|
|
73
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/dispatch/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAIjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnF;AAED;gEACgE;AAChE,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACxB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;CACnC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;AAEjD,wBAAgB,uBAA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