@astrale-os/sdk 0.4.13 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/domain/extend-functions.d.ts.map +1 -1
  2. package/dist/domain/extend-functions.js +2 -1
  3. package/dist/domain/extend-functions.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/linter/project.d.ts +6 -0
  9. package/dist/linter/project.d.ts.map +1 -1
  10. package/dist/linter/project.js +69 -7
  11. package/dist/linter/project.js.map +1 -1
  12. package/dist/server/auxiliary-routes.d.ts +5 -1
  13. package/dist/server/auxiliary-routes.d.ts.map +1 -1
  14. package/dist/server/auxiliary-routes.js +15 -6
  15. package/dist/server/auxiliary-routes.js.map +1 -1
  16. package/dist/server/index.d.ts +4 -2
  17. package/dist/server/index.d.ts.map +1 -1
  18. package/dist/server/index.js +2 -1
  19. package/dist/server/index.js.map +1 -1
  20. package/dist/server/service-entry.d.ts +32 -0
  21. package/dist/server/service-entry.d.ts.map +1 -0
  22. package/dist/server/service-entry.js +150 -0
  23. package/dist/server/service-entry.js.map +1 -0
  24. package/dist/server/worker-entry.d.ts +7 -3
  25. package/dist/server/worker-entry.d.ts.map +1 -1
  26. package/dist/server/worker-entry.js +7 -1
  27. package/dist/server/worker-entry.js.map +1 -1
  28. package/dist/service/functions.d.ts +148 -0
  29. package/dist/service/functions.d.ts.map +1 -0
  30. package/dist/service/functions.js +115 -0
  31. package/dist/service/functions.js.map +1 -0
  32. package/dist/service/index.d.ts +3 -0
  33. package/dist/service/index.d.ts.map +1 -0
  34. package/dist/service/index.js +2 -0
  35. package/dist/service/index.js.map +1 -0
  36. package/package.json +1 -1
  37. package/src/domain/extend-functions.ts +5 -1
  38. package/src/index.ts +18 -0
  39. package/src/linter/docs/RULES.md +1 -1
  40. package/src/linter/project.ts +88 -6
  41. package/src/server/auxiliary-routes.ts +34 -7
  42. package/src/server/index.ts +10 -2
  43. package/src/server/service-entry.ts +209 -0
  44. package/src/server/worker-entry.ts +18 -5
  45. package/src/service/functions.ts +164 -0
  46. package/src/service/index.ts +18 -0
@@ -0,0 +1,150 @@
1
+ import { K } from '@astrale-os/kernel-core';
2
+ import { Hono } from 'hono';
3
+ import { makeFunctionContext } from '../auth/function-context.js';
4
+ import { buildFunctionSchemas, DEFAULT_FUNCTIONS_FOLDER } from '../domain/extend-functions.js';
5
+ import { SERVICE_FUNCTIONS_PATH, ServiceFunctionDiscoveryRequestSchema, signServiceFunctionManifest, toServiceFunctionManifestEntries, } from '../service/functions.js';
6
+ import { mountAuxiliaryRoutes } from './auxiliary-routes.js';
7
+ import { createAppWorkerEntry } from './worker-entry.js';
8
+ /** A Service worker with zero or more first-class kernel Functions.
9
+ *
10
+ * The function map is the only declaration: it drives both HTTP routes and the
11
+ * signed deploy-time manifest. Function identities are read lazily from the
12
+ * graph after Services has reconciled them, while every Function reuses the
13
+ * Service's one private signing key. */
14
+ export function serviceWorkerEntry(config) {
15
+ const functions = config.functions ?? {};
16
+ const functionsFolder = config.functionsFolder ?? DEFAULT_FUNCTIONS_FOLDER;
17
+ return createAppWorkerEntry({
18
+ buildApp: (url, env) => {
19
+ const app = new Hono();
20
+ const serviceIdentity = identityFromEnv(env);
21
+ const { schemas, bindings } = buildFunctionSchemas(functions, url, functionsFolder);
22
+ assertLocalBindings(url, bindings);
23
+ const resolveFunctionIdentity = createFunctionIdentityResolver(env, serviceIdentity);
24
+ app.get('/', (c) => c.json({ ok: true, kind: 'astrale-service' }));
25
+ app.post(SERVICE_FUNCTIONS_PATH, async (c) => {
26
+ const parsed = ServiceFunctionDiscoveryRequestSchema.safeParse(await c.req.json().catch(() => null));
27
+ if (!parsed.success) {
28
+ return c.json({ error: 'Invalid service function discovery request' }, 400);
29
+ }
30
+ const response = await signServiceFunctionManifest({
31
+ version: 1,
32
+ service: {
33
+ issuer: serviceIdentity.issuer,
34
+ subject: serviceIdentity.subject,
35
+ },
36
+ functions: toServiceFunctionManifestEntries(schemas),
37
+ }, parsed.data, serviceIdentity);
38
+ return c.json(response);
39
+ });
40
+ mountAuxiliaryRoutes({
41
+ app,
42
+ url,
43
+ remoteFunctions: functions,
44
+ remoteFunctionBindings: bindings,
45
+ deps: env,
46
+ resolveIdentity: (kind, slug) => {
47
+ if (kind !== 'remoteFunction') {
48
+ throw new Error(`serviceWorkerEntry cannot resolve ${kind} identity ${slug}`);
49
+ }
50
+ return resolveFunctionIdentity(slug);
51
+ },
52
+ cors: config.cors ?? { origin: '*' },
53
+ });
54
+ return app;
55
+ },
56
+ resolveUrl: config.resolveUrl ?? ((_env, requestOrigin) => requestOrigin),
57
+ selfBinding: config.selfBinding,
58
+ routeSubrequest: config.routeSubrequest,
59
+ });
60
+ }
61
+ function identityFromEnv(env) {
62
+ return {
63
+ issuer: required(env, 'IDENTITY_ISS'),
64
+ subject: required(env, 'IDENTITY_SUB'),
65
+ privateKey: parsePrivateKey(required(env, 'IDENTITY_PRIVATE_KEY')),
66
+ };
67
+ }
68
+ function createFunctionIdentityResolver(env, serviceIdentity) {
69
+ const kernelUrl = required(env, 'ASTRALE_KERNEL_AUDIENCE');
70
+ let cachedAt = 0;
71
+ let identities = new Map();
72
+ const ttlMs = 60_000;
73
+ return async (slug) => {
74
+ if (Date.now() - cachedAt >= ttlMs || !identities.has(slug)) {
75
+ const kernel = await makeFunctionContext(serviceIdentity, env, {
76
+ ref: 'service',
77
+ defaultKernelUrl: kernelUrl,
78
+ }).kernel();
79
+ const service = await kernel.get(`@${serviceIdentity.subject}`);
80
+ if (!service)
81
+ throw new Error(`Service @${serviceIdentity.subject} is not readable`);
82
+ const folder = await kernel.get(`${service.path.raw}/functions`);
83
+ const nodes = folder
84
+ ? await (await kernel.children(folder.path, {
85
+ classes: [K.$.c('Function').path.class],
86
+ limit: 500,
87
+ })).all()
88
+ : [];
89
+ identities = readFunctionIdentities(nodes, serviceIdentity.issuer);
90
+ cachedAt = Date.now();
91
+ }
92
+ const identity = identities.get(slug);
93
+ if (!identity)
94
+ throw new Error(`Function identity function.${slug} is not registered`);
95
+ return hostedFunctionIdentity(identity, serviceIdentity);
96
+ };
97
+ }
98
+ /** Reuse only the Service's signing key. A hosted Function's inbound audience
99
+ * defaults to its own issuer; the Service HTTP origin is merely transport. */
100
+ export function hostedFunctionIdentity(identity, serviceIdentity) {
101
+ return { ...identity, privateKey: serviceIdentity.privateKey };
102
+ }
103
+ function readFunctionIdentities(nodes, serviceIssuer) {
104
+ const result = new Map();
105
+ for (const node of nodes) {
106
+ const ref = node.props[K.$.i('Function').ref.key];
107
+ const issuer = node.props[K.Identity.iss.key];
108
+ const subject = node.props[K.Identity.sub.key];
109
+ if (typeof ref !== 'string' ||
110
+ !ref.startsWith('function.') ||
111
+ typeof issuer !== 'string' ||
112
+ typeof subject !== 'string') {
113
+ continue;
114
+ }
115
+ if (issuer !== serviceIssuer) {
116
+ throw new Error(`Function ${ref} does not share its hosting Service issuer`);
117
+ }
118
+ result.set(ref.slice('function.'.length), { issuer, subject });
119
+ }
120
+ return result;
121
+ }
122
+ function assertLocalBindings(url, bindings) {
123
+ const origin = new URL(url).origin;
124
+ for (const [slug, binding] of Object.entries(bindings)) {
125
+ if (!binding.remoteUrl || new URL(binding.remoteUrl).origin !== origin) {
126
+ throw new Error(`serviceWorkerEntry function.${slug} must be hosted by this Service origin`);
127
+ }
128
+ }
129
+ }
130
+ function required(env, key) {
131
+ const value = env[key];
132
+ if (typeof value !== 'string' || value.length === 0) {
133
+ throw new Error(`Missing service variable ${String(key)}`);
134
+ }
135
+ return value;
136
+ }
137
+ function parsePrivateKey(value) {
138
+ let parsed;
139
+ try {
140
+ parsed = JSON.parse(value);
141
+ }
142
+ catch (error) {
143
+ throw new Error('IDENTITY_PRIVATE_KEY is not valid JSON', { cause: error });
144
+ }
145
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
146
+ throw new Error('IDENTITY_PRIVATE_KEY is not a JWK object');
147
+ }
148
+ return parsed;
149
+ }
150
+ //# sourceMappingURL=service-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-entry.js","sourceRoot":"","sources":["../../src/server/service-entry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,yBAAyB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAM3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAC9F,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACrC,2BAA2B,EAC3B,gCAAgC,GACjC,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAkBxD;;;;;wCAKwC;AACxC,MAAM,UAAU,kBAAkB,CAChC,MAAsC;IAEtC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAA;IACxC,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,wBAAwB,CAAA;IAE1E,OAAO,oBAAoB,CAAO;QAChC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACrB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;YACtB,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;YAC5C,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,oBAAoB,CAAC,SAAS,EAAE,GAAG,EAAE,eAAe,CAAC,CAAA;YACnF,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;YAClC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA;YAEpF,GAAG,CAAC,GAAG,CA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IACH,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAwC,GAAS,EAAE,GAAe;IACjF,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACtB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC7E,CAAC;IACD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC7D,CAAC;IACD,OAAO,MAAoB,CAAA;AAC7B,CAAC"}
@@ -23,17 +23,17 @@
23
23
  */
24
24
  import type { ExecutionContext } from 'hono';
25
25
  import type { RemoteServerConfig } from './config.js';
26
- type Fetcher = {
26
+ export type Fetcher = {
27
27
  fetch(request: Request): Response | Promise<Response>;
28
28
  };
29
- type App = {
29
+ export type WorkerApp = {
30
30
  fetch(request: Request, env?: unknown, executionCtx?: ExecutionContext): Response | Promise<Response>;
31
31
  };
32
32
  /** A built app cached by its serving URL: `origin` for same-origin matching,
33
33
  * `app` for in-process self-dispatch. */
34
34
  type CachedApp = {
35
35
  origin: string;
36
- app: App;
36
+ app: WorkerApp;
37
37
  };
38
38
  /**
39
39
  * Choose where an OUTBOUND subrequest to `u` is routed — or `null` to let the
@@ -111,6 +111,9 @@ export interface WorkerEntryConfig<TDeps> {
111
111
  */
112
112
  rewriteRequest?: (env: TDeps, request: Request) => Request;
113
113
  }
114
+ export interface AppWorkerEntryConfig<TDeps> extends Omit<WorkerEntryConfig<TDeps>, 'build'> {
115
+ buildApp: (url: string, env: TDeps) => WorkerApp;
116
+ }
114
117
  export interface WorkerEntry<TDeps> {
115
118
  fetch(request: Request, env: TDeps, executionCtx?: ExecutionContext): Response | Promise<Response>;
116
119
  }
@@ -149,5 +152,6 @@ export declare function assets<TDeps>(opts: {
149
152
  devProxy?: (env: TDeps) => string | null | undefined;
150
153
  }): (env: TDeps, url: URL, request: Request) => Response | Promise<Response> | undefined;
151
154
  export declare function createWorkerEntry<TDeps>(config: WorkerEntryConfig<TDeps>): WorkerEntry<TDeps>;
155
+ export declare function createAppWorkerEntry<TDeps>(config: AppWorkerEntryConfig<TDeps>): WorkerEntry<TDeps>;
152
156
  export {};
153
157
  //# sourceMappingURL=worker-entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAMrD,KAAK,OAAO,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAA;AACxE,KAAK,GAAG,GAAG;IACT,KAAK,CACH,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,OAAO,EACb,YAAY,CAAC,EAAE,gBAAgB,GAC9B,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAChC,CAAA;AAED;yCACyC;AACzC,KAAK,SAAS,GAAG;IAAE,M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A;CACrD,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,CAiBvF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAK7F;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EACxC,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAClC,WAAW,CAAC,KAAK,CAAC,CAsEpB"}
@@ -118,6 +118,12 @@ export function assets(opts) {
118
118
  };
119
119
  }
120
120
  export function createWorkerEntry(config) {
121
+ return createAppWorkerEntry({
122
+ ...config,
123
+ buildApp: (url, env) => createRemoteServer(config.build(url, env)).app,
124
+ });
125
+ }
126
+ export function createAppWorkerEntry(config) {
121
127
  // Cache the built app per distinct resolved URL — plural and bounded. On the
122
128
  // request-origin fallback the URL legitimately alternates for one worker
123
129
  // (direct http hits vs https-upgraded tunnel hits, workers.dev + custom
@@ -132,7 +138,7 @@ export function createWorkerEntry(config) {
132
138
  const cached = apps.get(url);
133
139
  if (cached)
134
140
  return cached.app;
135
- const { app } = createRemoteServer(config.build(url, env));
141
+ const app = config.buildApp(url, env);
136
142
  if (apps.size >= MAX_CACHED_APPS) {
137
143
  const oldest = apps.keys().next().value;
138
144
  if (oldest !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../../src/server/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAezD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MA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M,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;YACxF,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,148 @@
1
+ import type { FunctionBinding } from '@astrale-os/kernel-api/routed';
2
+ import type { FunctionSchema } from '@astrale-os/kernel-core/domain';
3
+ import { z } from 'zod';
4
+ import type { RemoteIdentityConfig } from '../auth/identity.js';
5
+ export declare const SERVICE_FUNCTIONS_PATH = "/_astrale/functions";
6
+ export declare const SERVICE_FUNCTIONS_PURPOSE = "astrale.service-functions.v1";
7
+ export declare const ServiceFunctionManifestEntrySchema: z.ZodObject<{
8
+ slug: z.ZodString;
9
+ ref: z.ZodString;
10
+ inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
11
+ outputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
12
+ output: z.ZodDefault<z.ZodEnum<{
13
+ binary: "binary";
14
+ stream: "stream";
15
+ value: "value";
16
+ }>>;
17
+ binding: z.ZodObject<{
18
+ remoteUrl: z.ZodOptional<z.ZodString>;
19
+ route: z.ZodOptional<z.ZodObject<{
20
+ method: z.ZodEnum<{
21
+ "*": "*";
22
+ DELETE: "DELETE";
23
+ GET: "GET";
24
+ PATCH: "PATCH";
25
+ POST: "POST";
26
+ PUT: "PUT";
27
+ }>;
28
+ path: z.ZodString;
29
+ self: z.ZodOptional<z.ZodString>;
30
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
31
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
32
+ body: z.ZodOptional<z.ZodUnknown>;
33
+ credential: z.ZodOptional<z.ZodUnknown>;
34
+ }, z.core.$strip>>;
35
+ auth: z.ZodOptional<z.ZodEnum<{
36
+ optional: "optional";
37
+ public: "public";
38
+ required: "required";
39
+ }>>;
40
+ }, z.core.$strip>;
41
+ }, z.core.$strip>;
42
+ export declare const ServiceFunctionManifestSchema: z.ZodObject<{
43
+ version: z.ZodLiteral<1>;
44
+ service: z.ZodObject<{
45
+ issuer: z.ZodString;
46
+ subject: z.ZodString;
47
+ }, z.core.$strip>;
48
+ functions: z.ZodArray<z.ZodObject<{
49
+ slug: z.ZodString;
50
+ ref: z.ZodString;
51
+ inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
52
+ outputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
53
+ output: z.ZodDefault<z.ZodEnum<{
54
+ binary: "binary";
55
+ stream: "stream";
56
+ value: "value";
57
+ }>>;
58
+ binding: z.ZodObject<{
59
+ remoteUrl: z.ZodOptional<z.ZodString>;
60
+ route: z.ZodOptional<z.ZodObject<{
61
+ method: z.ZodEnum<{
62
+ "*": "*";
63
+ DELETE: "DELETE";
64
+ GET: "GET";
65
+ PATCH: "PATCH";
66
+ POST: "POST";
67
+ PUT: "PUT";
68
+ }>;
69
+ path: z.ZodString;
70
+ self: z.ZodOptional<z.ZodString>;
71
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
72
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ body: z.ZodOptional<z.ZodUnknown>;
74
+ credential: z.ZodOptional<z.ZodUnknown>;
75
+ }, z.core.$strip>>;
76
+ auth: z.ZodOptional<z.ZodEnum<{
77
+ optional: "optional";
78
+ public: "public";
79
+ required: "required";
80
+ }>>;
81
+ }, z.core.$strip>;
82
+ }, z.core.$strip>>;
83
+ }, z.core.$strip>;
84
+ export declare const ServiceFunctionDiscoveryRequestSchema: z.ZodObject<{
85
+ kernelIssuer: z.ZodString;
86
+ nonce: z.ZodString;
87
+ }, z.core.$strip>;
88
+ export declare const ServiceFunctionDiscoveryResponseSchema: z.ZodObject<{
89
+ version: z.ZodLiteral<1>;
90
+ service: z.ZodObject<{
91
+ issuer: z.ZodString;
92
+ subject: z.ZodString;
93
+ }, z.core.$strip>;
94
+ functions: z.ZodArray<z.ZodObject<{
95
+ slug: z.ZodString;
96
+ ref: z.ZodString;
97
+ inputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
98
+ outputSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
99
+ output: z.ZodDefault<z.ZodEnum<{
100
+ binary: "binary";
101
+ stream: "stream";
102
+ value: "value";
103
+ }>>;
104
+ binding: z.ZodObject<{
105
+ remoteUrl: z.ZodOptional<z.ZodString>;
106
+ route: z.ZodOptional<z.ZodObject<{
107
+ method: z.ZodEnum<{
108
+ "*": "*";
109
+ DELETE: "DELETE";
110
+ GET: "GET";
111
+ PATCH: "PATCH";
112
+ POST: "POST";
113
+ PUT: "PUT";
114
+ }>;
115
+ path: z.ZodString;
116
+ self: z.ZodOptional<z.ZodString>;
117
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
118
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
119
+ body: z.ZodOptional<z.ZodUnknown>;
120
+ credential: z.ZodOptional<z.ZodUnknown>;
121
+ }, z.core.$strip>>;
122
+ auth: z.ZodOptional<z.ZodEnum<{
123
+ optional: "optional";
124
+ public: "public";
125
+ required: "required";
126
+ }>>;
127
+ }, z.core.$strip>;
128
+ }, z.core.$strip>>;
129
+ identity: z.ZodObject<{
130
+ credential: z.ZodString;
131
+ }, z.core.$strip>;
132
+ }, z.core.$strip>;
133
+ export type ServiceFunctionManifestEntry = z.infer<typeof ServiceFunctionManifestEntrySchema>;
134
+ export type ServiceFunctionManifest = z.infer<typeof ServiceFunctionManifestSchema>;
135
+ export type ServiceFunctionDiscoveryRequest = z.infer<typeof ServiceFunctionDiscoveryRequestSchema>;
136
+ export type ServiceFunctionDiscoveryResponse = z.infer<typeof ServiceFunctionDiscoveryResponseSchema>;
137
+ export declare function toServiceFunctionManifestEntries(schemas: readonly FunctionSchema[]): ServiceFunctionManifestEntry[];
138
+ export declare function signServiceFunctionManifest(manifest: ServiceFunctionManifest, request: ServiceFunctionDiscoveryRequest, identity: RemoteIdentityConfig): Promise<ServiceFunctionDiscoveryResponse>;
139
+ export declare function verifyServiceFunctionManifest(input: unknown, expected: {
140
+ kernelIssuer: string;
141
+ nonce: string;
142
+ serviceIssuer: string;
143
+ serviceSubject: string;
144
+ publicKey: JsonWebKey;
145
+ }): Promise<ServiceFunctionDiscoveryResponse>;
146
+ export declare function hashServiceFunctionManifest(manifest: ServiceFunctionManifest): Promise<string>;
147
+ export declare function functionBindingForManifest(binding: FunctionBinding, auth: 'required' | 'optional' | 'public' | undefined): FunctionBinding;
148
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/service/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAKpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAI/D,eAAO,MAAM,sBAAsB,wBAAwB,CAAA;AAC3D,eAAO,MAAM,yBAAyB,iCAAiC,CAAA;AAIvE,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO7C,CAAA;AAEF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIxC,CAAA;AAEF,eAAO,MAAM,qCAAqC;;;iBAGhD,CAAA;AAEF,eAAO,MAAM,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAEjD,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAA;AAC7F,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AACnF,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qCAAqC,CAAC,CAAA;AACnG,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,sCAAsC,CAC9C,CAAA;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,4BAA4B,EAAE,CAchC;AAED,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,uBAAuB,EACjC,OAAO,EAAE,+BAA+B,EACxC,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,gCAAgC,CAAC,CAc3C;AAED,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE;IACR,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,UAAU,CAAA;CACtB,GACA,OAAO,CAAC,gCAAgC,CAAC,CAkC3C;AAED,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GACnD,eAAe,CAEjB"}
@@ -0,0 +1,115 @@
1
+ import { deriveAllowedAlgorithms } from '@astrale-os/kernel-core';
2
+ import { functionBindingSchema, functionOutputSchema } from '@astrale-os/kernel-core/domain';
3
+ import { importJWK, jwtVerify } from 'jose';
4
+ import { z } from 'zod';
5
+ import { signCredential } from '../auth/sign.js';
6
+ export const SERVICE_FUNCTIONS_PATH = '/_astrale/functions';
7
+ export const SERVICE_FUNCTIONS_PURPOSE = 'astrale.service-functions.v1';
8
+ const JsonSchema = z.record(z.string(), z.unknown());
9
+ export const ServiceFunctionManifestEntrySchema = z.object({
10
+ slug: z.string().regex(/^[a-z][a-z0-9-]*$/),
11
+ ref: z.string().regex(/^function\.[a-z][a-z0-9-]*$/),
12
+ inputSchema: JsonSchema,
13
+ outputSchema: JsonSchema,
14
+ output: functionOutputSchema.default('value'),
15
+ binding: functionBindingSchema.unwrap(),
16
+ });
17
+ export const ServiceFunctionManifestSchema = z.object({
18
+ version: z.literal(1),
19
+ service: z.object({ issuer: z.string().min(1), subject: z.string().min(1) }),
20
+ functions: z.array(ServiceFunctionManifestEntrySchema).max(500),
21
+ });
22
+ export const ServiceFunctionDiscoveryRequestSchema = z.object({
23
+ kernelIssuer: z.string().url(),
24
+ nonce: z.string().min(16).max(256),
25
+ });
26
+ export const ServiceFunctionDiscoveryResponseSchema = ServiceFunctionManifestSchema.extend({
27
+ identity: z.object({ credential: z.string().min(1) }),
28
+ });
29
+ export function toServiceFunctionManifestEntries(schemas) {
30
+ return schemas
31
+ .map((schema) => {
32
+ const slug = schema.ref.slice('function.'.length);
33
+ return ServiceFunctionManifestEntrySchema.parse({
34
+ slug,
35
+ ref: schema.ref,
36
+ inputSchema: schema.inputSchema,
37
+ outputSchema: schema.outputSchema,
38
+ output: schema.output ?? 'value',
39
+ binding: schema.binding,
40
+ });
41
+ })
42
+ .sort((a, b) => a.slug.localeCompare(b.slug));
43
+ }
44
+ export async function signServiceFunctionManifest(manifest, request, identity) {
45
+ const parsedManifest = ServiceFunctionManifestSchema.parse(manifest);
46
+ const manifestHash = await hashServiceFunctionManifest(parsedManifest);
47
+ const credential = await signCredential({ purpose: SERVICE_FUNCTIONS_PURPOSE, nonce: request.nonce, manifestHash }, {
48
+ issuer: identity.issuer,
49
+ subject: identity.subject,
50
+ audience: request.kernelIssuer,
51
+ privateKey: identity.privateKey,
52
+ ttl: '2m',
53
+ });
54
+ return { ...parsedManifest, identity: { credential } };
55
+ }
56
+ export async function verifyServiceFunctionManifest(input, expected) {
57
+ const response = ServiceFunctionDiscoveryResponseSchema.parse(input);
58
+ if (response.service.issuer !== expected.serviceIssuer ||
59
+ response.service.subject !== expected.serviceSubject) {
60
+ throw new Error('service function manifest identity does not match the deployed Service');
61
+ }
62
+ const algorithms = deriveAllowedAlgorithms(expected.publicKey);
63
+ const algorithm = algorithms[0];
64
+ if (!algorithm)
65
+ throw new Error('service function manifest public key has no supported algorithm');
66
+ const key = await importJWK(expected.publicKey, algorithm);
67
+ const verified = await jwtVerify(response.identity.credential, key, {
68
+ algorithms,
69
+ issuer: expected.serviceIssuer,
70
+ subject: expected.serviceSubject,
71
+ audience: expected.kernelIssuer,
72
+ });
73
+ const expectedHash = await hashServiceFunctionManifest({
74
+ version: response.version,
75
+ service: response.service,
76
+ functions: response.functions,
77
+ });
78
+ if (verified.payload.purpose !== SERVICE_FUNCTIONS_PURPOSE) {
79
+ throw new Error('service function manifest credential has the wrong purpose');
80
+ }
81
+ if (verified.payload.nonce !== expected.nonce) {
82
+ throw new Error('service function manifest credential has the wrong nonce');
83
+ }
84
+ if (verified.payload.manifestHash !== expectedHash) {
85
+ throw new Error('service function manifest credential does not cover the returned manifest');
86
+ }
87
+ return response;
88
+ }
89
+ export async function hashServiceFunctionManifest(manifest) {
90
+ const bytes = new TextEncoder().encode(canonicalJson(ServiceFunctionManifestSchema.parse(manifest)));
91
+ const digest = await crypto.subtle.digest('SHA-256', bytes);
92
+ return `sha256:${hex(new Uint8Array(digest))}`;
93
+ }
94
+ export function functionBindingForManifest(binding, auth) {
95
+ return { ...binding, auth: auth ?? 'required' };
96
+ }
97
+ function canonicalJson(value) {
98
+ if (value === null || typeof value !== 'object')
99
+ return JSON.stringify(value);
100
+ if (Array.isArray(value))
101
+ return `[${value.map(canonicalJson).join(',')}]`;
102
+ const entries = Object.entries(value)
103
+ .filter(([, item]) => item !== undefined)
104
+ .sort(([a], [b]) => a.localeCompare(b));
105
+ return `{${entries
106
+ .map(([key, item]) => `${JSON.stringify(key)}:${canonicalJson(item)}`)
107
+ .join(',')}}`;
108
+ }
109
+ function hex(bytes) {
110
+ let value = '';
111
+ for (const byte of bytes)
112
+ value += byte.toString(16).padStart(2, '0');
113
+ return value;
114
+ }
115
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/service/functions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AAC5F,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAA;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,8BAA8B,CAAA;AAEvE,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AAEpD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,CAAC,MAAM,CAAC;IACzD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC;IAC3C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC;IACpD,WAAW,EAAE,UAAU;IACvB,YAAY,EAAE,UAAU;IACxB,MAAM,EAAE,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC;IAC7C,OAAO,EAAE,qBAAqB,CAAC,MAAM,EAAE;CACxC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IACpD,OAAO,E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,KAAK;QAAE,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACrE,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { SERVICE_FUNCTIONS_PATH, SERVICE_FUNCTIONS_PURPOSE, ServiceFunctionDiscoveryRequestSchema, ServiceFunctionDiscoveryResponseSchema, ServiceFunctionManifestEntrySchema, ServiceFunctionManifestSchema, hashServiceFunctionManifest, signServiceFunctionManifest, toServiceFunctionManifestEntries, verifyServiceFunctionManifest, } from './functions.js';
2
+ export type { ServiceFunctionDiscoveryRequest, ServiceFunctionDiscoveryResponse, ServiceFunctionManifest, ServiceFunctionManifestEntry, } from './functions.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,qCAAqC,EACrC,sCAAsC,EACtC,kCAAkC,EAClC,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,gBAAgB,CAAA;AACvB,YAAY,EACV,+BAA+B,EAC/B,gCAAgC,EAChC,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { SERVICE_FUNCTIONS_PATH, SERVICE_FUNCTIONS_PURPOSE, ServiceFunctionDiscoveryRequestSchema, ServiceFunctionDiscoveryResponseSchema, ServiceFunctionManifestEntrySchema, ServiceFunctionManifestSchema, hashServiceFunctionManifest, signServiceFunctionManifest, toServiceFunctionManifestEntries, verifyServiceFunctionManifest, } from './functions.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,qCAAqC,EACrC,sCAAsC,EACtC,kCAAkC,EAClC,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,gBAAgB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/sdk",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Astrale Remote Domain SDK - Define and deploy domains as standalone Hono servers",
5
5
  "keywords": [
6
6
  "astrale",
@@ -24,6 +24,7 @@ import { zodToJsonSchema } from '@astrale-os/kernel-core/domain'
24
24
 
25
25
  import type { AnyRemoteFunctionDef } from '../define/remote-function.js'
26
26
 
27
+ import { functionBindingForManifest } from '../service/functions.js'
27
28
  import { resolveBinding } from './binding.js'
28
29
 
29
30
  /**
@@ -92,7 +93,10 @@ export function buildFunctionSchemas(
92
93
  const schemas: FunctionSchema[] = []
93
94
  const bindings: Record<string, FunctionBinding> = {}
94
95
  for (const [slug, def] of Object.entries(functions)) {
95
- const binding = resolveBinding(def.binding, url, functionsFolder, slug)
96
+ const binding = functionBindingForManifest(
97
+ resolveBinding(def.binding, url, functionsFolder, slug),
98
+ def.auth,
99
+ )
96
100
  bindings[slug] = binding
97
101
  schemas.push({
98
102
  ref: `function.${slug}`,
package/src/index.ts CHANGED
@@ -97,6 +97,24 @@ export type { Defer, DeferredTask, Sleep } from '@astrale-os/kernel-server'
97
97
  export { MetaSchema } from './deploy/meta.js'
98
98
  export type { Meta } from './deploy/meta.js'
99
99
 
100
+ // ─── Service-hosted Functions ───────────────────────────────────────────
101
+ export {
102
+ SERVICE_FUNCTIONS_PATH,
103
+ ServiceFunctionDiscoveryRequestSchema,
104
+ ServiceFunctionDiscoveryResponseSchema,
105
+ ServiceFunctionManifestEntrySchema,
106
+ ServiceFunctionManifestSchema,
107
+ hashServiceFunctionManifest,
108
+ signServiceFunctionManifest,
109
+ verifyServiceFunctionManifest,
110
+ } from './service/index.js'
111
+ export type {
112
+ ServiceFunctionDiscoveryRequest,
113
+ ServiceFunctionDiscoveryResponse,
114
+ ServiceFunctionManifest,
115
+ ServiceFunctionManifestEntry,
116
+ } from './service/index.js'
117
+
100
118
  // ─── Route binding (re-exported from kernel-api for consumer convenience) ─
101
119
  export type {
102
120
  AuthPolicy,
@@ -57,7 +57,7 @@ claim that its SDK or analyzer implementation exists.
57
57
 
58
58
  | Slug | Owner | Scope | Automation | Default | Fix | Invariant and detection contract |
59
59
  | --- | --- | --- | --- | --- | --- | --- |
60
- | `core-is-pure` | `analyzer` | `project` | `implement` | error | none | Production files under `core/` must not reach known effectful Astrale/Node packages or the project's `runtime`, `functions`, `integrations`, `client`, or `simulation` layers; detection follows resolved relative imports and excludes tests. Unknown third-party packages are not guessed to be effectful. |
60
+ | `core-is-pure` | `analyzer` | `project` | `implement` | error | none | Production files under `core/` must not reach known effectful Astrale/Node packages or the project's `runtime`, `functions`, `integrations`, `client`, or `simulation` layers; detection follows resolved local imports, including package-import aliases, and excludes tests. Unknown third-party packages are not guessed to be effectful. |
61
61
  | `core-has-no-async` | `oxlint` | `file` | `implement` | error | none | Production files under `core/` must not declare async functions or async generators, or use top-level `await`/`for await`; tests are excluded. |
62
62
  | `integrations-enter-through-deps` | `analyzer` | `project` | `research` | off | none | Runtime handlers receive external clients through the domain dependency container and must not construct provider clients or import configured singletons directly. |
63
63
  | `deps-construction-has-no-effects` | `oxlint` | `file` | `research` | off | none | The dependency factory may construct clients from configuration but must not await, fetch, call the kernel, read time/randomness, or perform request-specific I/O. |