@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.
- 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 +41 -0
- package/dist/auth/compose.d.ts.map +1 -0
- package/dist/auth/compose.js +45 -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 +43 -0
- package/dist/auth/kernel-client.d.ts.map +1 -0
- package/dist/auth/kernel-client.js +146 -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 +96 -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 +239 -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 +34 -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 +5 -5
- package/src/auth/compose.ts +27 -2
- package/src/auth/kernel-client.ts +103 -11
- package/src/define/remote-function.ts +10 -0
- package/src/server/auxiliary-routes.ts +3 -1
- package/src/server/start.ts +5 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mount worker-side routes for `defineView` and `defineRemoteFunction` entries.
|
|
3
|
+
*
|
|
4
|
+
* Each entry's effective `FunctionBinding` is resolved once at boot (host
|
|
5
|
+
* pattern, path, http verb) and a Hono route is registered that runs the
|
|
6
|
+
* shared SDK auth pipeline (verify inbound credential, optionally enforce /
|
|
7
|
+
* optional / public), Zod validation of input AND output (RemoteFunction
|
|
8
|
+
* only — Views are transport-only), the author's `authorize` hook, and
|
|
9
|
+
* finally `render` / `execute`.
|
|
10
|
+
*
|
|
11
|
+
* Bindings whose host is not a sub-domain of this worker's host are skipped
|
|
12
|
+
* (the graph node was still materialized; the route lives elsewhere).
|
|
13
|
+
*/
|
|
14
|
+
import { isKernelErrorClassifiable, KERNEL_ERROR_CODES, kernelErrorHttpStatus, } from '@astrale-os/kernel-api';
|
|
15
|
+
import { isSubdomainOf, matchHost, compileHostMatcher, parseUrlTemplate, } from '@astrale-os/kernel-api/routed';
|
|
16
|
+
import { buildCorsHeaders } from '@astrale-os/kernel-server';
|
|
17
|
+
import { makeSelfKernel } from '../auth/kernel-client';
|
|
18
|
+
import { resolveInboundAuth } from '../auth/resolve';
|
|
19
|
+
import { runAuthorize } from '../dispatch/authorize';
|
|
20
|
+
import { makeCallRemote } from '../dispatch/call-remote';
|
|
21
|
+
import { SdkResultValidationError, SdkValidationError } from '../dispatch/errors';
|
|
22
|
+
import { validateParams, validateResult } from '../dispatch/validate';
|
|
23
|
+
export function mountAuxiliaryRoutes(config) {
|
|
24
|
+
const { app, url, views, viewBindings, remoteFunctions, remoteFunctionBindings, deps, identities, cors, } = config;
|
|
25
|
+
const workerHost = parseUrlTemplate(url).hostPattern;
|
|
26
|
+
const corsHeaders = buildCorsHeaders(cors);
|
|
27
|
+
if (views && viewBindings) {
|
|
28
|
+
for (const [slug, def] of Object.entries(views)) {
|
|
29
|
+
const binding = viewBindings[slug];
|
|
30
|
+
if (!binding || !def.render)
|
|
31
|
+
continue;
|
|
32
|
+
const identity = requireAuxIdentity('view', slug, identities.views[slug]);
|
|
33
|
+
mountEntry({
|
|
34
|
+
app,
|
|
35
|
+
binding,
|
|
36
|
+
workerHost,
|
|
37
|
+
defaultMethod: 'GET',
|
|
38
|
+
auth: def.auth,
|
|
39
|
+
identity,
|
|
40
|
+
corsHeaders,
|
|
41
|
+
// Views are transport-only (iframe HTML/redirect) — the kernel client
|
|
42
|
+
// built by `resolveInboundAuth` is intentionally NOT forwarded. Code
|
|
43
|
+
// inside the loaded iframe talks back to the kernel via the shell
|
|
44
|
+
// (WebSocket), not via this worker route.
|
|
45
|
+
run: async ({ c, params, auth }) => {
|
|
46
|
+
if (def.authorize)
|
|
47
|
+
await runAuthorize(def.authorize, { c, params, auth, deps });
|
|
48
|
+
return def.render({ c, params, auth, deps });
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (remoteFunctions && remoteFunctionBindings) {
|
|
54
|
+
for (const [slug, def] of Object.entries(remoteFunctions)) {
|
|
55
|
+
const binding = remoteFunctionBindings[slug];
|
|
56
|
+
if (!binding)
|
|
57
|
+
continue;
|
|
58
|
+
const identity = requireAuxIdentity('remote function', slug, identities.remoteFunctions[slug]);
|
|
59
|
+
mountEntry({
|
|
60
|
+
app,
|
|
61
|
+
binding,
|
|
62
|
+
workerHost,
|
|
63
|
+
defaultMethod: 'POST',
|
|
64
|
+
auth: def.auth,
|
|
65
|
+
identity,
|
|
66
|
+
corsHeaders,
|
|
67
|
+
run: async ({ c, auth, kernel, callRemote }) => {
|
|
68
|
+
const selfKernel = makeSelfKernel(identity, deps);
|
|
69
|
+
const rawBody = await c.req.json().catch(() => ({}));
|
|
70
|
+
const validation = validateParams(def.inputSchema, rawBody);
|
|
71
|
+
if (!validation.ok) {
|
|
72
|
+
throw new SdkValidationError(validation.issues);
|
|
73
|
+
}
|
|
74
|
+
const ctx = { params: validation.data, c, auth, deps, kernel, callRemote, selfKernel };
|
|
75
|
+
if (def.authorize)
|
|
76
|
+
await runAuthorize(def.authorize, ctx);
|
|
77
|
+
const result = await def.execute(ctx);
|
|
78
|
+
const outValidation = validateResult(def.outputSchema, result);
|
|
79
|
+
if (!outValidation.ok) {
|
|
80
|
+
throw new SdkResultValidationError(outValidation.issues, def.ref);
|
|
81
|
+
}
|
|
82
|
+
return c.json({ result: outValidation.data });
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// ── Internal ───────────────────────────────────────────────────────────────
|
|
89
|
+
/**
|
|
90
|
+
* Every materialized aux callable must have an identity in the install-time
|
|
91
|
+
* `subs` claim — a missing one means the build pipeline passed a compiled
|
|
92
|
+
* domain that doesn't include this callable to `buildAuxIdentityMap()`.
|
|
93
|
+
*/
|
|
94
|
+
function requireAuxIdentity(kind, slug, identity) {
|
|
95
|
+
if (identity)
|
|
96
|
+
return identity;
|
|
97
|
+
throw new Error(`mountAuxiliaryRoutes: no identity registered for ${kind} "${slug}". ` +
|
|
98
|
+
`Pass a compiled domain that includes this ${kind} to buildAuxIdentityMap().`);
|
|
99
|
+
}
|
|
100
|
+
const PLACEHOLDER_RE = /\{(\w+)([+*])?\}/g;
|
|
101
|
+
function mountEntry(args) {
|
|
102
|
+
const { app, binding, workerHost, defaultMethod, run, auth, identity, corsHeaders } = args;
|
|
103
|
+
const remoteUrl = binding.remoteUrl;
|
|
104
|
+
if (!remoteUrl)
|
|
105
|
+
return;
|
|
106
|
+
const parsed = parseUrlTemplate(remoteUrl);
|
|
107
|
+
if (parsed.hostPattern && !isSubdomainOf(parsed.hostPattern, workerHost))
|
|
108
|
+
return;
|
|
109
|
+
const fullPath = joinPath(parsed.basePath, binding.route?.path ?? '');
|
|
110
|
+
const honoPath = toHonoPath(fullPath);
|
|
111
|
+
const httpMethod = binding.route?.method ?? defaultMethod;
|
|
112
|
+
// `route.method` can be any `HttpMethod` (PUT/PATCH/DELETE/*), but only GET
|
|
113
|
+
// and POST are wired below. Fail loudly at mount time rather than silently
|
|
114
|
+
// registering no handler (which would 404 the real request while the OPTIONS
|
|
115
|
+
// preflight still reports the route exists).
|
|
116
|
+
if (httpMethod !== 'GET' && httpMethod !== 'POST') {
|
|
117
|
+
throw new Error(`mountAuxiliaryRoutes: unsupported HTTP method "${httpMethod}" for route "${honoPath}". ` +
|
|
118
|
+
`Aux routes (views / remote functions) support only GET and POST.`);
|
|
119
|
+
}
|
|
120
|
+
// Local-dev requests target literal `localhost`, but bindings reference a
|
|
121
|
+
// logical host (`dist.localhost`) — so only enforce a Host-header match
|
|
122
|
+
// when the binding has actual placeholders to extract.
|
|
123
|
+
const hostMatcher = parsed.hostPlaceholders.length > 0 ? compileHostMatcher(parsed.hostPattern) : null;
|
|
124
|
+
const pathParamNames = collectPlaceholderNames(fullPath);
|
|
125
|
+
const handler = async (c) => {
|
|
126
|
+
// Apply CORS to every response. `c.json(...)` / `c.body(...)` pick up the
|
|
127
|
+
// headers via the Hono context; raw `Response` objects — a View's `render`
|
|
128
|
+
// return, and `errorResponse` in the catch — do NOT, so the final returned
|
|
129
|
+
// Response is also passed through `applyCorsToResponse`.
|
|
130
|
+
applyCorsToContext(c, corsHeaders);
|
|
131
|
+
try {
|
|
132
|
+
let hostParams = {};
|
|
133
|
+
if (hostMatcher) {
|
|
134
|
+
const match = matchHost(hostMatcher, c.req.header('host') ?? '');
|
|
135
|
+
if (!match)
|
|
136
|
+
return c.notFound();
|
|
137
|
+
hostParams = match;
|
|
138
|
+
}
|
|
139
|
+
const pathParams = {};
|
|
140
|
+
for (const name of pathParamNames) {
|
|
141
|
+
const value = c.req.param(name);
|
|
142
|
+
if (value !== undefined)
|
|
143
|
+
pathParams[name] = decodeURIComponent(value);
|
|
144
|
+
}
|
|
145
|
+
const { auth: resolvedAuth, kernel } = await resolveInboundAuth(stripBearerPrefix(c.req.header('authorization') ?? ''), auth, identity);
|
|
146
|
+
const response = await run({
|
|
147
|
+
c,
|
|
148
|
+
params: { ...hostParams, ...pathParams },
|
|
149
|
+
auth: resolvedAuth,
|
|
150
|
+
kernel,
|
|
151
|
+
callRemote: makeCallRemote(kernel),
|
|
152
|
+
});
|
|
153
|
+
return applyCorsToResponse(response, corsHeaders);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
return applyCorsToResponse(errorResponse(err), corsHeaders);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
if (httpMethod === 'GET')
|
|
160
|
+
app.get(honoPath, handler);
|
|
161
|
+
else if (httpMethod === 'POST')
|
|
162
|
+
app.post(honoPath, handler);
|
|
163
|
+
// Per-route preflight — mirrors `createKernelApp`'s per-route
|
|
164
|
+
// `app.options(...)` pattern (kernel/server/app/create.ts:112,145). Avoid
|
|
165
|
+
// a wildcard `app.options('*', ...)`: it would intercept the kernel
|
|
166
|
+
// envelope's own preflights mounted later on this same Hono instance.
|
|
167
|
+
app.options(honoPath, (c) => {
|
|
168
|
+
applyCorsToContext(c, corsHeaders);
|
|
169
|
+
return c.body(null, 204);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function applyCorsToContext(c, headers) {
|
|
173
|
+
for (const [name, value] of Object.entries(headers))
|
|
174
|
+
c.header(name, value);
|
|
175
|
+
}
|
|
176
|
+
function applyCorsToResponse(response, headers) {
|
|
177
|
+
try {
|
|
178
|
+
for (const [name, value] of Object.entries(headers))
|
|
179
|
+
response.headers.set(name, value);
|
|
180
|
+
return response;
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Some Responses have immutable headers — notably `Response.redirect(...)`,
|
|
184
|
+
// which a View's `render` is documented to return. Rebuild with a mutable
|
|
185
|
+
// header copy so CORS still applies (status / body / location preserved).
|
|
186
|
+
const merged = new Headers(response.headers);
|
|
187
|
+
for (const [name, value] of Object.entries(headers))
|
|
188
|
+
merged.set(name, value);
|
|
189
|
+
return new Response(response.body, {
|
|
190
|
+
status: response.status,
|
|
191
|
+
statusText: response.statusText,
|
|
192
|
+
headers: merged,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function collectPlaceholderNames(path) {
|
|
197
|
+
return [...path.matchAll(PLACEHOLDER_RE)].map((m) => m[1]);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Serialize an error as the canonical kernel error envelope
|
|
201
|
+
* `{ error: { code, message, data } }` with the matching HTTP status. This is
|
|
202
|
+
* the exact shape the routed client (`kernel-client` HttpRoutedTransport.
|
|
203
|
+
* decodeError) parses — it routes on `error.code` and reads `error.data` for
|
|
204
|
+
* field-level detail (a flat `{ error: '<string>' }` body silently degrades to
|
|
205
|
+
* a generic INTERNAL_ERROR client-side). Every SDK error class (AuthMissingError,
|
|
206
|
+
* SdkValidationError, SdkResultValidationError, AuthorizationDeniedError, …) plus
|
|
207
|
+
* the kernel-core errors `resolveInboundAuth` rethrows all implement
|
|
208
|
+
* `toKernelErrorPayload`, so one branch covers them; only a raw non-classifiable
|
|
209
|
+
* Error falls back to 500.
|
|
210
|
+
*/
|
|
211
|
+
function errorResponse(err) {
|
|
212
|
+
const payload = isKernelErrorClassifiable(err)
|
|
213
|
+
? err.toKernelErrorPayload()
|
|
214
|
+
: {
|
|
215
|
+
code: KERNEL_ERROR_CODES.INTERNAL_ERROR,
|
|
216
|
+
message: err instanceof Error ? err.message : 'Internal error',
|
|
217
|
+
};
|
|
218
|
+
return Response.json({ error: payload }, { status: kernelErrorHttpStatus(payload.code) });
|
|
219
|
+
}
|
|
220
|
+
function joinPath(a, b) {
|
|
221
|
+
if (!b)
|
|
222
|
+
return a;
|
|
223
|
+
if (!a)
|
|
224
|
+
return b;
|
|
225
|
+
const left = a.endsWith('/') ? a.slice(0, -1) : a;
|
|
226
|
+
const right = b.startsWith('/') ? b : `/${b}`;
|
|
227
|
+
return `${left}${right}` || '/';
|
|
228
|
+
}
|
|
229
|
+
/** Convert `/foo/{id}` / `/{name+}` / `/{name*}` to Hono syntax. */
|
|
230
|
+
function toHonoPath(path) {
|
|
231
|
+
return path
|
|
232
|
+
.replace(/\{(\w+)\+\}/g, ':$1{.+}')
|
|
233
|
+
.replace(/\{(\w+)\*\}/g, ':$1{.*}')
|
|
234
|
+
.replace(/\{(\w+)\}/g, ':$1');
|
|
235
|
+
}
|
|
236
|
+
function stripBearerPrefix(value) {
|
|
237
|
+
return value.trim().replace(/^Bearer\s+/i, '');
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=auxiliary-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auxiliary-routes.js","sourceRoot":"","sources":["../../src/server/auxiliary-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,GAEtB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GAGjB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAmB,MAAM,2BAA2B,CAAA;AAQ7E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,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C,IAAY;IAC9B,OAAO,IAAI;SACR,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC;SAClC,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC;SAClC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RemoteServerConfig` — input shape for `createRemoteServer`.
|
|
3
|
+
*
|
|
4
|
+
* Identity is per-function: `iss` = the worker's serving URL (`config.url`),
|
|
5
|
+
* `sub` = the function path, signed on each dispatch. No single `subject`.
|
|
6
|
+
*/
|
|
7
|
+
import type { CorsConfig, WsAdapter } from '@astrale-os/kernel-server';
|
|
8
|
+
import type { Context } from 'hono';
|
|
9
|
+
import type { Hono } from 'hono';
|
|
10
|
+
import type { RemoteDomain } from '../domain/define';
|
|
11
|
+
export type RemoteServerConfig<TDeps> = {
|
|
12
|
+
/** Domain produced by `defineRemoteDomain(...)`. */
|
|
13
|
+
domain: RemoteDomain;
|
|
14
|
+
/** Dependency container passed to every handler as `ctx.deps`. */
|
|
15
|
+
deps: TDeps;
|
|
16
|
+
/**
|
|
17
|
+
* Server URL — the serving location AND the worker's JWT issuer identity
|
|
18
|
+
* (`iss`), decoupled from the addressing `origin` slug.
|
|
19
|
+
*
|
|
20
|
+
* The server's public key is published at `<url>/.well-known/jwks.json`
|
|
21
|
+
* so downstream verifiers can validate credentials signed by this server.
|
|
22
|
+
*/
|
|
23
|
+
url: string;
|
|
24
|
+
/** Private key used to sign outbound credentials. Public form is exposed via JWKS. */
|
|
25
|
+
privateKey: JsonWebKey;
|
|
26
|
+
/** Allowed transports. `'http'` is mandatory. `'ws'` is opt-in. Defaults to `['http']`. */
|
|
27
|
+
transports?: readonly ('http' | 'ws')[];
|
|
28
|
+
/**
|
|
29
|
+
* Runtime-specific WS adapter (from `hono/bun`, `@hono/node-ws`, `hono/deno`).
|
|
30
|
+
* Required when `transports` includes `'ws'`.
|
|
31
|
+
*/
|
|
32
|
+
ws?: WsAdapter;
|
|
33
|
+
/** CORS configuration. Defaults to `{ origin: '*' }`. */
|
|
34
|
+
cors?: CorsConfig;
|
|
35
|
+
/** Optional health endpoint path (defaults to `/health`; `false` disables). */
|
|
36
|
+
health?: string | false;
|
|
37
|
+
/** Pre-existing Hono app to attach to (for nesting the SDK under a parent router). */
|
|
38
|
+
app?: Hono;
|
|
39
|
+
/**
|
|
40
|
+
* Provenance stamped onto the auto-mounted `/meta` endpoint. Typically
|
|
41
|
+
* injected at build time by the bundler so downstream tooling can detect
|
|
42
|
+
* version drift between deployed server and expected schema.
|
|
43
|
+
*/
|
|
44
|
+
meta?: {
|
|
45
|
+
sdkCommit?: string;
|
|
46
|
+
schemaHash?: string;
|
|
47
|
+
domainName?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Typed colon-path to a callable the installing kernel calls ONCE as the
|
|
51
|
+
* system identity, immediately after the domain installs. Use it to seed
|
|
52
|
+
* nodes and self-grant. Must be a semantic domain path under this domain's
|
|
53
|
+
* own origin (`/:origin:class.X:seed` / `/:origin:interface.Ops:seed`) — the
|
|
54
|
+
* kernel's origin guard refuses absolute tree paths, which cannot prove
|
|
55
|
+
* their origin from the string alone. Returned verbatim in the install
|
|
56
|
+
* bundle (a routing hint — the signed `graph_hash` already constrains what
|
|
57
|
+
* the callable can be).
|
|
58
|
+
*
|
|
59
|
+
* Example: `/:crm.acme.dev:class.Note:seed`
|
|
60
|
+
*/
|
|
61
|
+
postInstall?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Cross-domain dependencies by origin. Returned in the install bundle; the
|
|
64
|
+
* kernel verifies each origin is already present on the instance before
|
|
65
|
+
* installing, and refuses with a clear error if one is missing.
|
|
66
|
+
*/
|
|
67
|
+
requires?: readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* Optional private install hook. Throw to deny the install request.
|
|
70
|
+
* The public URL install contract still receives no caller kernel
|
|
71
|
+
* credential; private installs use the bearer token only.
|
|
72
|
+
*/
|
|
73
|
+
install?: {
|
|
74
|
+
authorize?: (args: {
|
|
75
|
+
c: Context;
|
|
76
|
+
token?: string;
|
|
77
|
+
kernelIssuer: string;
|
|
78
|
+
nonce: string;
|
|
79
|
+
deps: TDeps;
|
|
80
|
+
}) => void | Promise<void>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,MAAM,kBAAkB,CAAC,KAAK,IAAI;IACtC,oDAAoD;IACpD,MAAM,EAAE,YAAY,CAAA;IACpB,kEAAkE;IAClE,IAAI,EAAE,KAAK,CAAA;IACX;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,CAAA;IACX,sFAAsF;IACtF,UAAU,EAAE,UAAU,CAAA;IACtB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;IACvC;;;OAGG;IACH,EAAE,CAAC,EAAE,SAAS,CAAA;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACvB,sFAAsF;IACtF,GAAG,CAAC,EAAE,IAAI,CAAA;IACV;;;;OAIG;IACH,IAAI,CAAC,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;IACD;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE;YACjB,CAAC,EAAE,OAAO,CAAA;YACV,KAAK,CAAC,EAAE,MAAM,CAAA;YACd,YAAY,EAAE,MAAM,CAAA;YACpB,KAAK,EAAE,MAAM,CAAA;YACb,IAAI,EAAE,KAAK,CAAA;SACZ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3B,CAAA;CACF,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RemoteServerConfig` — input shape for `createRemoteServer`.
|
|
3
|
+
*
|
|
4
|
+
* Identity is per-function: `iss` = the worker's serving URL (`config.url`),
|
|
5
|
+
* `sub` = the function path, signed on each dispatch. No single `subject`.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createRemoteServer` — the SDK's entry point for running a remote domain.
|
|
3
|
+
*
|
|
4
|
+
* Identity is per-function: the dispatcher signs `iss` = the worker's serving
|
|
5
|
+
* URL (`effectiveIssuer`, decoupled from the addressing `origin`) and `sub` =
|
|
6
|
+
* the origin-addressed function path on each dispatch.
|
|
7
|
+
*
|
|
8
|
+
* Composes:
|
|
9
|
+
* methods ← Map keyed by BoundMethod.ref (built by dispatch/resolve)
|
|
10
|
+
* effectiveIssuer ← config.issuer ?? config.url
|
|
11
|
+
* dispatcher ← SdkDispatcher(compiled, methods, deps, privateKey)
|
|
12
|
+
* jwks ← derivePublicJwk(privateKey), keyed by effectiveIssuer
|
|
13
|
+
* /meta ← provenance endpoint (sdkCommit, schemaHash, domainName)
|
|
14
|
+
* auxiliary routes ← view / remote-function handlers from defineRemoteDomain
|
|
15
|
+
* app ← createKernelApp(dispatcher, contracts, host, jwks, transports, ...)
|
|
16
|
+
* start ← startNodeServer(app, port)
|
|
17
|
+
*/
|
|
18
|
+
import type { RemoteServerConfig } from './config';
|
|
19
|
+
import type { RemoteServer } from './handle';
|
|
20
|
+
export declare function createRemoteServer<TDeps>(config: RemoteServerConfig<TDeps>): RemoteServer;
|
|
21
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAeH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAsB,MAAM,UAAU,CAAA;AAahE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,GAAG,YAAY,CA+JzF"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createRemoteServer` — the SDK's entry point for running a remote domain.
|
|
3
|
+
*
|
|
4
|
+
* Identity is per-function: the dispatcher signs `iss` = the worker's serving
|
|
5
|
+
* URL (`effectiveIssuer`, decoupled from the addressing `origin`) and `sub` =
|
|
6
|
+
* the origin-addressed function path on each dispatch.
|
|
7
|
+
*
|
|
8
|
+
* Composes:
|
|
9
|
+
* methods ← Map keyed by BoundMethod.ref (built by dispatch/resolve)
|
|
10
|
+
* effectiveIssuer ← config.issuer ?? config.url
|
|
11
|
+
* dispatcher ← SdkDispatcher(compiled, methods, deps, privateKey)
|
|
12
|
+
* jwks ← derivePublicJwk(privateKey), keyed by effectiveIssuer
|
|
13
|
+
* /meta ← provenance endpoint (sdkCommit, schemaHash, domainName)
|
|
14
|
+
* auxiliary routes ← view / remote-function handlers from defineRemoteDomain
|
|
15
|
+
* app ← createKernelApp(dispatcher, contracts, host, jwks, transports, ...)
|
|
16
|
+
* start ← startNodeServer(app, port)
|
|
17
|
+
*/
|
|
18
|
+
import { deriveAllowedAlgorithms } from '@astrale-os/kernel-core';
|
|
19
|
+
import { collectFunctionSubs, domainInstallRequestSchema, hashInstallGraph, } from '@astrale-os/kernel-core/domain';
|
|
20
|
+
import { createKernelApp } from '@astrale-os/kernel-server';
|
|
21
|
+
import { Hono } from 'hono';
|
|
22
|
+
import { importJWK, SignJWT } from 'jose';
|
|
23
|
+
import { MetaSchema } from '../deploy/meta';
|
|
24
|
+
import { SdkDispatcher } from '../dispatch/dispatcher';
|
|
25
|
+
import { buildAuxIdentityMap } from '../dispatch/identity';
|
|
26
|
+
import { buildMethodIndex } from '../dispatch/resolve';
|
|
27
|
+
import { buildInstallGraph, buildInstallGraphHash } from '../domain/build-spec';
|
|
28
|
+
import { toSdkContract } from '../domain/contract';
|
|
29
|
+
import { materializeRemoteDomain } from '../domain/define';
|
|
30
|
+
import { mountAuxiliaryRoutes } from './auxiliary-routes';
|
|
31
|
+
import { derivePublicJwk } from './jwks';
|
|
32
|
+
import { canonicalizeServingUrl } from './serving-url';
|
|
33
|
+
export function createRemoteServer(config) {
|
|
34
|
+
const methods = buildMethodIndex(config.domain.methods);
|
|
35
|
+
// The worker's identity (`iss`) is its full serving URL (base path included,
|
|
36
|
+
// trailing slash stripped) — decoupled from the addressing `origin` slug. One
|
|
37
|
+
// canonical value drives outbound signing, the JWKS issuer, `/meta`, and the
|
|
38
|
+
// install credential. Must equal the URL the kernel fetched the domain at.
|
|
39
|
+
const iss = canonicalizeServingUrl(config.url);
|
|
40
|
+
// Re-materialize the domain with the real serving url (`iss`) so the aux
|
|
41
|
+
// View/Function `binding.remoteUrl` resolve to this host — the define-time
|
|
42
|
+
// placeholder is discarded. `compiled`/`auxiliary` drive everything below;
|
|
43
|
+
// `iss` is the single source for both bindings and identity.
|
|
44
|
+
const { compiled, auxiliary } = materializeRemoteDomain(config.domain, iss);
|
|
45
|
+
const dispatcher = new SdkDispatcher({
|
|
46
|
+
compiled,
|
|
47
|
+
methods,
|
|
48
|
+
deps: config.deps,
|
|
49
|
+
privateKey: config.privateKey,
|
|
50
|
+
issuer: iss,
|
|
51
|
+
// The canonicalized serving URL, NOT the raw config.url: `ctx.url` is
|
|
52
|
+
// documented as the worker's `iss` identity, so the two must be one value.
|
|
53
|
+
url: iss,
|
|
54
|
+
});
|
|
55
|
+
const publicJwk = derivePublicJwk(config.privateKey);
|
|
56
|
+
const jwks = {
|
|
57
|
+
issuer: iss,
|
|
58
|
+
loadOwnKeys: async () => [publicJwk],
|
|
59
|
+
};
|
|
60
|
+
// `/meta`'s `schemaHash` is computed from the LIVE domain graph (lazy +
|
|
61
|
+
// cached). `hashInstallGraph` is id-independent/deterministic, so an
|
|
62
|
+
// independent build (a deploy script) produces the SAME hash — `deployCheck`
|
|
63
|
+
// can compare its expected value against this and detect genuine schema drift.
|
|
64
|
+
// An explicit `config.meta.schemaHash` still wins as an override for
|
|
65
|
+
// offline/pinned spec producers, but normal deploys omit it.
|
|
66
|
+
let cachedSchemaHash = null;
|
|
67
|
+
const resolveSchemaHash = () => config.meta?.schemaHash !== undefined
|
|
68
|
+
? Promise.resolve(config.meta.schemaHash)
|
|
69
|
+
: (cachedSchemaHash ??= buildInstallGraphHash(config.domain, iss));
|
|
70
|
+
// Register `/meta` on the host app before `createKernelApp` mounts its
|
|
71
|
+
// catch-all routes so the verbatim path wins.
|
|
72
|
+
const hostApp = config.app ?? new Hono();
|
|
73
|
+
const metaBase = {
|
|
74
|
+
iss,
|
|
75
|
+
sdkCommit: config.meta?.sdkCommit,
|
|
76
|
+
domainName: config.meta?.domainName ?? compiled.$.origin,
|
|
77
|
+
};
|
|
78
|
+
hostApp.get('/meta', async (c) => c.json(MetaSchema.parse({ ...metaBase, schemaHash: await resolveSchemaHash() })));
|
|
79
|
+
hostApp.post('/_astrale/install-domain', async (c) => {
|
|
80
|
+
const parsed = domainInstallRequestSchema.safeParse(await c.req.json().catch(() => null));
|
|
81
|
+
if (!parsed.success) {
|
|
82
|
+
return c.json({ error: 'Invalid install request', issues: parsed.error.issues }, 400);
|
|
83
|
+
}
|
|
84
|
+
const token = bearerToken(c.req.header('authorization'));
|
|
85
|
+
try {
|
|
86
|
+
await config.install?.authorize?.({
|
|
87
|
+
c,
|
|
88
|
+
...(token ? { token } : {}),
|
|
89
|
+
kernelIssuer: parsed.data.kernelIssuer,
|
|
90
|
+
nonce: parsed.data.nonce,
|
|
91
|
+
deps: config.deps,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return c.json({ error: 'Install denied', message: err.message }, 403);
|
|
96
|
+
}
|
|
97
|
+
// Build the install graph. `buildInstallGraph` re-materializes the domain
|
|
98
|
+
// with the serving url (`iss`), so every `binding.remoteUrl` points at this
|
|
99
|
+
// host — the same single value as the credential's `iss` below. The kernel
|
|
100
|
+
// hashes exactly this graph; no install-time rewrite.
|
|
101
|
+
const graph = buildInstallGraph(config.domain, iss);
|
|
102
|
+
const graphHash = await hashInstallGraph(graph);
|
|
103
|
+
const origin = compiled.$.origin;
|
|
104
|
+
// `postInstall` + `requires` ride in BOTH the signed credential claims and
|
|
105
|
+
// the bundle body, and the kernel rejects any bundle field that disagrees
|
|
106
|
+
// with its signed claim — so derive them once and reuse for both.
|
|
107
|
+
const bundleExtras = {
|
|
108
|
+
...(config.postInstall ? { postInstall: config.postInstall } : {}),
|
|
109
|
+
...(config.requires && config.requires.length > 0 ? { requires: config.requires } : {}),
|
|
110
|
+
};
|
|
111
|
+
// The credential's `iss` is the worker's serving URL (`iss`, computed above)
|
|
112
|
+
// — the kernel pins it to the URL it fetched the domain at and verifies this
|
|
113
|
+
// credential against that issuer's JWKS.
|
|
114
|
+
const credential = await signInstallCredential({
|
|
115
|
+
privateKey: config.privateKey,
|
|
116
|
+
issuer: iss,
|
|
117
|
+
audience: parsed.data.kernelIssuer,
|
|
118
|
+
nonce: parsed.data.nonce,
|
|
119
|
+
graphHash,
|
|
120
|
+
subs: collectFunctionSubs(compiled),
|
|
121
|
+
...bundleExtras,
|
|
122
|
+
});
|
|
123
|
+
return c.json({
|
|
124
|
+
origin,
|
|
125
|
+
graph,
|
|
126
|
+
identity: { credential },
|
|
127
|
+
...bundleExtras,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
// Resolved once and shared between the kernel envelope (createKernelApp) and
|
|
131
|
+
// the aux routes (mountAuxiliaryRoutes) so both honor the same policy.
|
|
132
|
+
const cors = config.cors ?? { origin: '*' };
|
|
133
|
+
// Worker-side wires for defineView / defineRemoteFunction. Mounted before
|
|
134
|
+
// the kernel catch-all. Each aux route gets its own per-slug identity
|
|
135
|
+
// (issuer + key + the aux node's AbsolutePath as subject) so outbound
|
|
136
|
+
// `kernel.call(...)` from a handler signs with that path — matching the
|
|
137
|
+
// identity the install-time `subs` claim registered for the node, the
|
|
138
|
+
// same way Methods work.
|
|
139
|
+
if (auxiliary) {
|
|
140
|
+
const auxIdentities = buildAuxIdentityMap(compiled, config.privateKey, iss);
|
|
141
|
+
mountAuxiliaryRoutes({
|
|
142
|
+
app: hostApp,
|
|
143
|
+
url: auxiliary.url,
|
|
144
|
+
// oxlint-disable-next-line no-explicit-any
|
|
145
|
+
views: config.domain.views,
|
|
146
|
+
viewBindings: auxiliary.viewBindings,
|
|
147
|
+
remoteFunctions: config.domain.remoteFunctions,
|
|
148
|
+
remoteFunctionBindings: auxiliary.remoteFunctionBindings,
|
|
149
|
+
deps: config.deps,
|
|
150
|
+
identities: auxIdentities,
|
|
151
|
+
cors,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const { app } = createKernelApp({
|
|
155
|
+
kernel: dispatcher,
|
|
156
|
+
domain: config.domain.methods.map(toSdkContract),
|
|
157
|
+
host: { url: config.url },
|
|
158
|
+
jwks,
|
|
159
|
+
transports: config.transports,
|
|
160
|
+
cors,
|
|
161
|
+
health: config.health,
|
|
162
|
+
app: hostApp,
|
|
163
|
+
ws: config.ws,
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
app,
|
|
167
|
+
// The canonical serving URL = the worker's `iss` identity. Exposed so a
|
|
168
|
+
// worker that also seeds `Identity.iss` on graph nodes (e.g. recruitment's
|
|
169
|
+
// self-seed) stamps the SAME canonical value the dispatcher signs with —
|
|
170
|
+
// never the raw env.WORKER_URL — so the kernel's exact-match lookup resolves.
|
|
171
|
+
iss,
|
|
172
|
+
async start(port) {
|
|
173
|
+
const nodeStartModule = './start';
|
|
174
|
+
const { startNodeServer } = await import(nodeStartModule);
|
|
175
|
+
return startNodeServer(app, port);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function bearerToken(header) {
|
|
180
|
+
if (!header)
|
|
181
|
+
return undefined;
|
|
182
|
+
const match = /^Bearer\s+(.+)$/i.exec(header.trim());
|
|
183
|
+
return match?.[1];
|
|
184
|
+
}
|
|
185
|
+
async function signInstallCredential(args) {
|
|
186
|
+
const alg = deriveAllowedAlgorithms(args.privateKey)[0];
|
|
187
|
+
if (!alg) {
|
|
188
|
+
throw new Error(`createRemoteServer: cannot derive install signing algorithm from JWK (kty=${args.privateKey.kty}).`);
|
|
189
|
+
}
|
|
190
|
+
const kid = args.privateKey.kid;
|
|
191
|
+
const header = typeof kid === 'string' ? { alg, kid } : { alg };
|
|
192
|
+
const key = await importJWK(args.privateKey, alg);
|
|
193
|
+
// `postInstall` + `requires` are signed (not just carried in the bundle) so a
|
|
194
|
+
// MITM can't retarget the system-authority hook or forge dependencies
|
|
195
|
+
return new SignJWT({
|
|
196
|
+
subs: args.subs,
|
|
197
|
+
nonce: args.nonce,
|
|
198
|
+
graph_hash: args.graphHash,
|
|
199
|
+
...(args.postInstall ? { postInstall: args.postInstall } : {}),
|
|
200
|
+
...(args.requires ? { requires: args.requires } : {}),
|
|
201
|
+
})
|
|
202
|
+
.setProtectedHeader(header)
|
|
203
|
+
.setIssuer(args.issuer)
|
|
204
|
+
.setSubject(args.issuer)
|
|
205
|
+
.setAudience(args.audience)
|
|
206
|
+
.setIssuedAt()
|
|
207
|
+
.setExpirationTime('10m')
|
|
208
|
+
.sign(key);
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAMzC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,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,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA;IAC/D,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAEjD,8EAA8E;IAC9E,sEAAsE;IACtE,OAAO,IAAI,OAAO,CAAC;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,UAAU,EAAE,IAAI,CAAC,SAAS;QAC1B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,CAAC;SACC,kBAAkB,CAAC,MAAM,CAAC;SAC1B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;SACtB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC1B,WAAW,EAAE;SACb,iBAAiB,CAAC,KAAK,CAAC;SACxB,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `RemoteServer` and `RemoteServerHandle` — output shapes for the SDK server.
|
|
3
|
+
*
|
|
4
|
+
* `RemoteServer` is what `createRemoteServer` returns: the assembled Hono
|
|
5
|
+
* app plus a Node convenience helper. `RemoteServerHandle` is what `start()`
|
|
6
|
+
* resolves to: the bound port and a `close()` function for graceful shutdown.
|
|
7
|
+
*/
|
|
8
|
+
import type { Hono } from 'hono';
|
|
9
|
+
export type RemoteServer = {
|
|
10
|
+
/**
|
|
11
|
+
* The assembled Hono app. Use `app.fetch` for any runtime
|
|
12
|
+
* (Bun, Deno, Cloudflare Workers, or Node via `@hono/node-server`).
|
|
13
|
+
*/
|
|
14
|
+
app: Hono;
|
|
15
|
+
/**
|
|
16
|
+
* The worker's canonical serving URL — its `iss` identity (full URL, trailing
|
|
17
|
+
* slash stripped, base path preserved). The single value the dispatcher signs
|
|
18
|
+
* with and the kernel pins. Read it to seed `Identity.iss` on graph nodes so
|
|
19
|
+
* the seeded value matches the signing issuer (never re-derive from a raw env).
|
|
20
|
+
*/
|
|
21
|
+
iss: string;
|
|
22
|
+
/**
|
|
23
|
+
* Convenience helper: start a Node HTTP server on the given port using
|
|
24
|
+
* `@hono/node-server` (loaded via dynamic import). For other runtimes,
|
|
25
|
+
* use `app.fetch` directly.
|
|
26
|
+
*/
|
|
27
|
+
start: (port?: number) => Promise<RemoteServerHandle>;
|
|
28
|
+
};
|
|
29
|
+
export type RemoteServerHandle = {
|
|
30
|
+
/** The port the server is listening on (resolved even if `port: 0` was requested). */
|
|
31
|
+
port: number;
|
|
32
|
+
/** Stop the server and release the port. */
|
|
33
|
+
close: () => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/server/handle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAEhC,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,GAAG,EAAE,IAAI,CAAA;IACT;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;OAIG;IACH,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACtD,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B,CAAA"}
|