@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,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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,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/server/handle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createRemoteServer } from './create';
|
|
2
|
+
export type { RemoteServerConfig } from './config';
|
|
3
|
+
export type { RemoteServer, RemoteServerHandle } from './handle';
|
|
4
|
+
export { derivePublicJwk } from './jwks';
|
|
5
|
+
export { requireEnv } from './require-env';
|
|
6
|
+
export { canonicalizeServingUrl } from './serving-url';
|
|
7
|
+
export { createWorkerEntry } from './worker-entry';
|
|
8
|
+
export type { WorkerEntry, WorkerEntryConfig } from './worker-entry';
|
|
9
|
+
export { workerMeta } from './worker-meta';
|
|
10
|
+
export { startNodeServer } from './start';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createRemoteServer } from './create';
|
|
2
|
+
export { derivePublicJwk } from './jwks';
|
|
3
|
+
export { requireEnv } from './require-env';
|
|
4
|
+
export { canonicalizeServingUrl } from './serving-url';
|
|
5
|
+
export { createWorkerEntry } from './worker-entry';
|
|
6
|
+
export { workerMeta } from './worker-meta';
|
|
7
|
+
export { startNodeServer } from './start';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a public JWK from a private one.
|
|
3
|
+
*
|
|
4
|
+
* Strips the private components for both EC keys (drops `d`) and RSA keys
|
|
5
|
+
* (drops `d`, `p`, `q`, `dp`, `dq`, `qi`, and `oth` — the additional-primes
|
|
6
|
+
* array on multi-prime RSA keys). The result is safe to publish at
|
|
7
|
+
* `<url>/.well-known/jwks.json` so downstream verifiers can validate
|
|
8
|
+
* signatures the server produced.
|
|
9
|
+
*/
|
|
10
|
+
export declare function derivePublicJwk(privateKey: JsonWebKey): Record<string, unknown>;
|
|
11
|
+
//# sourceMappingURL=jwks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwks.d.ts","sourceRoot":"","sources":["../../src/server/jwks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO/E"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a public JWK from a private one.
|
|
3
|
+
*
|
|
4
|
+
* Strips the private components for both EC keys (drops `d`) and RSA keys
|
|
5
|
+
* (drops `d`, `p`, `q`, `dp`, `dq`, `qi`, and `oth` — the additional-primes
|
|
6
|
+
* array on multi-prime RSA keys). The result is safe to publish at
|
|
7
|
+
* `<url>/.well-known/jwks.json` so downstream verifiers can validate
|
|
8
|
+
* signatures the server produced.
|
|
9
|
+
*/
|
|
10
|
+
export function derivePublicJwk(privateKey) {
|
|
11
|
+
// oxlint-disable-next-line no-unused-vars
|
|
12
|
+
const { d, p, q, dp, dq, qi, oth, ...publicJwk } = privateKey;
|
|
13
|
+
return publicJwk;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=jwks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwks.js","sourceRoot":"","sources":["../../src/server/jwks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,UAAU,eAAe,CAAC,UAAsB;IACpD,0CAA0C;IAC1C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,UAGlD,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a string-typed env var (process.env on Node, the Worker `env` binding
|
|
3
|
+
* on Cloudflare) and throw a clear error if it is missing or empty.
|
|
4
|
+
*
|
|
5
|
+
* Use this for **identity-bearing** values (issuer, baseDomain, audience,
|
|
6
|
+
* worker URL) where a guessed default silently mints wrong JWTs or bakes
|
|
7
|
+
* wrong refs into persisted artifacts. The conventional `?? 'literal'`
|
|
8
|
+
* fallback is the anti-pattern this exists to replace.
|
|
9
|
+
*
|
|
10
|
+
* In local dev these live in each domain worker's `worker/.dev.vars` (read
|
|
11
|
+
* natively by `wrangler dev`), so this throw never fires in a properly-prepared
|
|
12
|
+
* dev environment — only when wiring is genuinely missing.
|
|
13
|
+
*/
|
|
14
|
+
export declare function requireEnv(env: unknown, name: string, hint?: string): string;
|
|
15
|
+
//# sourceMappingURL=require-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-env.d.ts","sourceRoot":"","sources":["../../src/server/require-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a string-typed env var (process.env on Node, the Worker `env` binding
|
|
3
|
+
* on Cloudflare) and throw a clear error if it is missing or empty.
|
|
4
|
+
*
|
|
5
|
+
* Use this for **identity-bearing** values (issuer, baseDomain, audience,
|
|
6
|
+
* worker URL) where a guessed default silently mints wrong JWTs or bakes
|
|
7
|
+
* wrong refs into persisted artifacts. The conventional `?? 'literal'`
|
|
8
|
+
* fallback is the anti-pattern this exists to replace.
|
|
9
|
+
*
|
|
10
|
+
* In local dev these live in each domain worker's `worker/.dev.vars` (read
|
|
11
|
+
* natively by `wrangler dev`), so this throw never fires in a properly-prepared
|
|
12
|
+
* dev environment — only when wiring is genuinely missing.
|
|
13
|
+
*/
|
|
14
|
+
export function requireEnv(env, name, hint) {
|
|
15
|
+
const v = env?.[name];
|
|
16
|
+
if (typeof v === 'string' && v.length > 0)
|
|
17
|
+
return v;
|
|
18
|
+
const help = hint ? ` (${hint})` : '';
|
|
19
|
+
throw new Error(`Missing required env var: ${name}${help}`);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=require-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-env.js","sourceRoot":"","sources":["../../src/server/require-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,IAAY,EAAE,IAAa;IAClE,MAAM,CAAC,GAAI,GAAkD,EAAE,CAAC,IAAI,CAAC,CAAA;IACrE,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,CAAA;IACnD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,GAAG,IAAI,EAAE,CAAC,CAAA;AAC7D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalize a worker's serving URL into its `iss` identity.
|
|
3
|
+
*
|
|
4
|
+
* Returns the full URL with trailing slash(es) stripped — the base path is
|
|
5
|
+
* preserved (an issuer may carry a non-empty path, like `…/kernel/host`). This
|
|
6
|
+
* is the single canonical form used for outbound signing, the JWKS issuer,
|
|
7
|
+
* `/meta`, the install credential, and any `Identity.iss` a domain seeds, so the
|
|
8
|
+
* value a worker SIGNS always matches the value the kernel LOOKS UP (the kernel
|
|
9
|
+
* canonicalizes the verified `iss` the same way and does an exact-match lookup).
|
|
10
|
+
*
|
|
11
|
+
* Throws if `url` is not a parseable absolute URL.
|
|
12
|
+
*/
|
|
13
|
+
export declare function canonicalizeServingUrl(url: string): string;
|
|
14
|
+
//# sourceMappingURL=serving-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serving-url.d.ts","sourceRoot":"","sources":["../../src/server/serving-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS1D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalize a worker's serving URL into its `iss` identity.
|
|
3
|
+
*
|
|
4
|
+
* Returns the full URL with trailing slash(es) stripped — the base path is
|
|
5
|
+
* preserved (an issuer may carry a non-empty path, like `…/kernel/host`). This
|
|
6
|
+
* is the single canonical form used for outbound signing, the JWKS issuer,
|
|
7
|
+
* `/meta`, the install credential, and any `Identity.iss` a domain seeds, so the
|
|
8
|
+
* value a worker SIGNS always matches the value the kernel LOOKS UP (the kernel
|
|
9
|
+
* canonicalizes the verified `iss` the same way and does an exact-match lookup).
|
|
10
|
+
*
|
|
11
|
+
* Throws if `url` is not a parseable absolute URL.
|
|
12
|
+
*/
|
|
13
|
+
// INVARIANT (cross-repo): issuer PRODUCERS must strip trailing path slashes
|
|
14
|
+
// BEFORE a value becomes an iss. kernel-core's `normalizeIssuerId` only strips
|
|
15
|
+
// a lone trailing slash on an EMPTY path, so `https://x/base/` and
|
|
16
|
+
// `https://x/base` are distinct issuer identities to the kernel — this
|
|
17
|
+
// function and the kernel's `installSourceBase` both pre-strip with the same
|
|
18
|
+
// rule so the two sides can never mint diverging identities for one worker.
|
|
19
|
+
export function canonicalizeServingUrl(url) {
|
|
20
|
+
try {
|
|
21
|
+
return new URL(url).href.replace(/\/+$/, '');
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error(`canonicalizeServingUrl: expected a full URL (got "${url}") — ` +
|
|
25
|
+
'it is the worker serving URL and its JWT issuer identity.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=serving-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serving-url.js","sourceRoot":"","sources":["../../src/server/serving-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,4EAA4E;AAC5E,+EAA+E;AAC/E,mEAAmE;AACnE,uEAAuE;AACvE,6EAA6E;AAC7E,4EAA4E;AAC5E,MAAM,UAAU,sBAAsB,CAAC,GAAW;IAChD,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,qDAAqD,GAAG,OAAO;YAC7D,2DAA2D,CAC9D,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node HTTP convenience starter.
|
|
3
|
+
*
|
|
4
|
+
* Dynamically imports `@hono/node-server` so the SDK stays runtime-agnostic
|
|
5
|
+
* — only Node consumers actually pull in the dep. For Bun / Deno /
|
|
6
|
+
* Cloudflare, consumers go through `server.app.fetch` directly.
|
|
7
|
+
*/
|
|
8
|
+
import type { Hono } from 'hono';
|
|
9
|
+
import type { RemoteServerHandle } from './handle';
|
|
10
|
+
export declare function startNodeServer(app: Hono, port?: number): Promise<RemoteServerHandle>;
|
|
11
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/server/start.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAEhC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAElD,wBAAsB,eAAe,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,SAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwBzF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node HTTP convenience starter.
|
|
3
|
+
*
|
|
4
|
+
* Dynamically imports `@hono/node-server` so the SDK stays runtime-agnostic
|
|
5
|
+
* — only Node consumers actually pull in the dep. For Bun / Deno /
|
|
6
|
+
* Cloudflare, consumers go through `server.app.fetch` directly.
|
|
7
|
+
*/
|
|
8
|
+
export async function startNodeServer(app, port = 3000) {
|
|
9
|
+
const { serve } = await import('@hono/node-server');
|
|
10
|
+
// oxlint-disable-next-line no-explicit-any
|
|
11
|
+
const server = serve({ fetch: app.fetch, port });
|
|
12
|
+
await new Promise((resolve, reject) => {
|
|
13
|
+
if (server.listening)
|
|
14
|
+
return resolve();
|
|
15
|
+
server.once('listening', () => resolve());
|
|
16
|
+
// Without this, a bind failure (e.g. EADDRINUSE on a busy port) emits
|
|
17
|
+
// `'error'` and never `'listening'`, leaving the Promise — and startup —
|
|
18
|
+
// hung forever with no diagnostic.
|
|
19
|
+
server.once('error', (err) => reject(err));
|
|
20
|
+
});
|
|
21
|
+
const address = server.address();
|
|
22
|
+
const actualPort = address?.port ?? port;
|
|
23
|
+
return {
|
|
24
|
+
port: actualPort,
|
|
25
|
+
close: () => new Promise((resolve, reject) => {
|
|
26
|
+
server.close((err) => (err ? reject(err) : resolve()));
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/server/start.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAS,EAAE,IAAI,GAAG,IAAI;IAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IACnD,2CAA2C;IAC3C,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,CAAQ,CAAA;IAEvD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,IAAI,MAAM,CAAC,SAAS;YAAE,OAAO,OAAO,EAAE,CAAA;QACtC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;QACzC,sEAAsE;QACtE,yEAAyE;QACzE,mCAAmC;QACnC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAA8C,CAAA;IAC5E,MAAM,UAAU,GAAG,OAAO,EAAE,IAAI,IAAI,IAAI,CAAA;IAExC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,GAAG,EAAE,CACV,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAiB,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QACtE,CAAC,CAAC;KACL,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createWorkerEntry` — the shared worker `fetch` plumbing every Astrale domain
|
|
3
|
+
* worker (and the cloudflare adapter's codegen) needs, so it lives in ONE place
|
|
4
|
+
* instead of being copy-pasted per worker:
|
|
5
|
+
*
|
|
6
|
+
* • resolve the serving URL (== `iss`), canonicalize it (so the value matches
|
|
7
|
+
* what `createRemoteServer` signs with and the kernel pins), and cache the
|
|
8
|
+
* built app per distinct URL;
|
|
9
|
+
* • optional self-binding routing: when a `SELF` service binding is provided,
|
|
10
|
+
* route same-host subrequests (e.g. `ctx.callRemote` back into this domain)
|
|
11
|
+
* through it — Cloudflare forbids a Worker fetching its own hostname. This is
|
|
12
|
+
* the ONLY reason a `globalThis.fetch` override is installed, and only when a
|
|
13
|
+
* `selfBinding` is configured;
|
|
14
|
+
* • optional SPA hook (e.g. `/ui/*` served from an `ASSETS` binding).
|
|
15
|
+
*
|
|
16
|
+
* The worker's OWN JWKS (`<url>/.well-known/jwks.json`) is served as a normal
|
|
17
|
+
* route by `createRemoteServer`; the verifier resolves a self-issued credential
|
|
18
|
+
* from the in-memory key (see `auth/verify.ts`), so no self-fetch shim is needed.
|
|
19
|
+
*
|
|
20
|
+
* The worker file is then just schema + methods + a `build(url, env)` callback.
|
|
21
|
+
*/
|
|
22
|
+
import type { RemoteServerConfig } from './config';
|
|
23
|
+
type Fetcher = {
|
|
24
|
+
fetch(request: Request): Response | Promise<Response>;
|
|
25
|
+
};
|
|
26
|
+
export interface WorkerEntryConfig<TDeps> {
|
|
27
|
+
/**
|
|
28
|
+
* Build the `createRemoteServer` config for the resolved serving `url`. Called
|
|
29
|
+
* once per distinct URL (the resulting app is cached), with the same `env` the
|
|
30
|
+
* request carries — so it can read additional bindings (e.g. a base domain).
|
|
31
|
+
*/
|
|
32
|
+
build: (url: string, env: TDeps) => RemoteServerConfig<TDeps>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the raw serving URL from `env` (+ the per-request origin, for workers
|
|
35
|
+
* that fall back to the request host). Defaults to the `WORKER_URL` env var.
|
|
36
|
+
* The result is always canonicalized before use.
|
|
37
|
+
*/
|
|
38
|
+
resolveUrl?: (env: TDeps, requestOrigin: string) => string;
|
|
39
|
+
/** Optional: the `SELF` service binding used to route same-host subrequests. */
|
|
40
|
+
selfBinding?: (env: TDeps) => Fetcher | null | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Optional: handle a request before it reaches the kernel app — e.g. serve a
|
|
43
|
+
* SPA under `/ui/*` or a same-origin `/api/*` endpoint the view calls. Return
|
|
44
|
+
* a `Response` to short-circuit, or `undefined` to fall through to the domain
|
|
45
|
+
* dispatch.
|
|
46
|
+
*/
|
|
47
|
+
before?: (env: TDeps, url: URL, request: Request) => Response | undefined | Promise<Response | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional: transform the request on the fall-through path, just before it
|
|
50
|
+
* reaches the kernel app (e.g. rewrite the hostname for wildcard-subdomain
|
|
51
|
+
* routing). Not applied when `before` short-circuits.
|
|
52
|
+
*/
|
|
53
|
+
rewriteRequest?: (env: TDeps, request: Request) => Request;
|
|
54
|
+
}
|
|
55
|
+
export interface WorkerEntry<TDeps> {
|
|
56
|
+
fetch(request: Request, env: TDeps): Response | Promise<Response>;
|
|
57
|
+
}
|
|
58
|
+
export declare function createWorkerEntry<TDeps>(config: WorkerEntryConfig<TDeps>): WorkerEntry<TDeps>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=worker-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAMlD,KAAK,OAAO,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAA;AAGxE,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC;;;;OAIG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,KAAK,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC7D;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,KAAK,MAAM,CAAA;IAC1D,gFAAgF;IAChF,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;IACxD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CACP,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,KACb,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACzD;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;CAC3D;AAED,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,C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