@arbol-ai/maximus 7.4.0 → 8.0.0
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/README.md +36 -38
- package/bin/maximus.js +4 -0
- package/config/oxfmt.mjs +1 -0
- package/config/oxlint.mjs +10 -0
- package/dist/analytics/analytics.d.ts +21 -9
- package/dist/analytics/analytics.js +19 -5
- package/dist/body.d.ts +1 -1
- package/dist/body.js +2 -2
- package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
- package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
- package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
- package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
- package/dist/chunks/define-app-CfVZBt7D.js +336 -0
- package/dist/chunks/{errors-D7zG9kx9.js → errors-WfyKhiyk.js} +9 -4
- package/dist/chunks/{execution-kVUJPy1A.js → execution-CfZEx_JP.js} +28 -15
- package/dist/chunks/generate-C-9FKW0o.js +197 -0
- package/dist/chunks/handler-DWTGoduQ.js +140 -0
- package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
- package/dist/chunks/{http-paths-yKD6TSNJ.js → http-paths-DMBxwpp6.js} +50 -31
- package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
- package/dist/chunks/names-ncD7A3DV.js +280 -0
- package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
- package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
- package/dist/chunks/pages-DyC0m8Zb.js +14 -0
- package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
- package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
- package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
- package/dist/chunks/query-kind-CWKAXEME.js +40 -0
- package/dist/chunks/record-DQUDTpEA.js +10 -0
- package/dist/chunks/result-CKgZHrnj.js +56 -0
- package/dist/chunks/{runtime-DlqA7J38.js → runtime-CVVf5hmp.js} +50 -26
- package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
- package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
- package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
- package/dist/chunks/server-CCc7fil4.js +410 -0
- package/dist/chunks/src--HZrH1U9.js +568 -0
- package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
- package/dist/chunks/{types-DQdfRF3f.d.ts → types-BQYB4Ads.d.ts} +993 -341
- package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
- package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
- package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
- package/dist/diagnostics.d.ts +6 -4
- package/dist/diagnostics.js +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -11
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +5 -4
- package/dist/mcp/index.d.ts +3 -2
- package/dist/mcp/index.js +5 -387
- package/dist/postgres/index.d.ts +25 -8
- package/dist/postgres/index.js +17 -8
- package/dist/project/config.d.ts +110 -72
- package/dist/project/config.js +161 -45
- package/dist/project/index.d.ts +17 -4
- package/dist/project/index.js +44 -9
- package/dist/projection.d.ts +14 -13
- package/dist/projection.js +8 -32
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +2 -2
- package/dist/standard-failures.d.ts +2 -89
- package/dist/tooling/cli.js +149 -105
- package/dist/tooling/testing.js +2 -2
- package/dist/vite/cloudflare-workers.js +25 -0
- package/dist/vite/index.d.ts +157 -0
- package/dist/vite/index.js +1477 -0
- package/dist/webhooks.d.ts +12 -10
- package/dist/webhooks.js +26 -12
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +26 -22
- package/skills/maximus/SKILL.md +165 -68
- package/skills/maximus/references/deploying.md +73 -0
- package/skills/maximus/references/errors-and-results.md +114 -55
- package/skills/maximus/references/project.md +202 -0
- package/skills/maximus/references/routes-and-tools.md +256 -0
- package/skills/maximus/references/testing.md +137 -50
- package/skills/maximus/references/transports.md +113 -100
- package/skills/maximus/references/writing-code.md +84 -0
- package/templates/mcp/mcp/instructions.md.template +2 -0
- package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
- package/templates/mcp/tests/mcp.test.ts.template +36 -0
- package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
- package/templates/project/.github/workflows/ci.yml.template +4 -1
- package/templates/project/CLAUDE.md.template +41 -25
- package/templates/project/README.md.template +54 -48
- package/templates/project/middleware/10-response.ts.template +5 -2
- package/templates/project/package.json.template +13 -9
- package/templates/project/pages/index.ts.template +2 -4
- package/templates/project/routes/v1/greeting.get.ts.template +10 -0
- package/templates/project/routes/v1/greeting.post.ts.template +12 -0
- package/templates/project/tests/greeting.test.ts.template +45 -0
- package/templates/project/tsconfig.json.template +8 -6
- package/templates/project/vite.config.ts.template +15 -7
- package/templates/web/app/main.tsx.template +16 -0
- package/templates/web/app/root.tsx.template +17 -0
- package/templates/web/app/routes/index.tsx.template +9 -0
- package/templates/web/index.html.template +12 -0
- package/templates/web/package.json.template +12 -0
- package/templates/web/tsconfig.json.template +7 -0
- package/templates/web/vite.config.ts.template +22 -0
- package/dist/chunks/builder-BiXv7d2v.js +0 -100
- package/dist/chunks/define-app-DvD_1jUE.js +0 -625
- package/dist/chunks/prepare-project-CMyGSEtI.js +0 -236
- package/dist/chunks/prepare-project-MtS0-W_n.js +0 -3
- package/dist/chunks/record-DY-lX9w1.js +0 -34
- package/dist/chunks/src-N3oyx5QF.js +0 -1091
- package/dist/client/client.d.ts +0 -129
- package/dist/client/client.js +0 -321
- package/dist/tooling/vite.d.ts +0 -3
- package/dist/tooling/vite.js +0 -57
- package/skills/maximus/references/adding-an-operation.md +0 -179
- package/skills/maximus/references/building-a-service.md +0 -167
- package/skills/maximus/references/migration-from-v2.md +0 -62
- package/skills/maximus/references/migration-to-v5.md +0 -37
- package/skills/maximus/references/publishing-and-verification.md +0 -42
- package/templates/project/cloudflare.config.ts.template +0 -24
- package/templates/project/maximus.config.ts.template +0 -20
- package/templates/project/routes/v1/greeting.ts.template +0 -38
- package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
- package/templates/service/.github/workflows/ci.yml.template +0 -21
- package/templates/service/.gitignore.template +0 -9
- package/templates/service/CLAUDE.md.template +0 -5
- package/templates/service/README.md.template +0 -45
- package/templates/service/cloudflare.config.ts.template +0 -30
- package/templates/service/package.json.template +0 -36
- package/templates/service/src/app.ts.template +0 -30
- package/templates/service/src/index.ts.template +0 -13
- package/templates/service/tests/contract.test.ts.template +0 -12
- package/templates/service/tsconfig.json.template +0 -16
- package/templates/service/vite.config.ts.template +0 -13
- package/templates/service/vitest.config.ts.template +0 -10
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import { Kind, OptionalKind, Static, Static as Static$1, Static as Static$2, StaticDecode, TArray, TLiteral, TObject, TOptional, TProperties, TRecord, TSchema, TSchema as TSchema$1, TSchema as TSchema$2, TString, TTransform, TTuple, TUnion, TUnsafe, TransformKind, Type as Type$1, Type as Type$2, Type as t, Type as t$1 } from "@sinclair/typebox";
|
|
2
|
-
import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
|
|
3
|
-
/** A file an HTTP operation answers with: its bytes, media type, filename and exact length. */
|
|
4
|
-
interface Attachment {
|
|
5
|
-
/** The file's bytes, as a buffer or an unlocked stream. */
|
|
6
|
-
body: ReadableStream<Uint8Array> | Uint8Array;
|
|
7
|
-
/** The media type sent as `content-type`: `type/subtype`, at most 255 characters. */
|
|
8
|
-
contentType: string;
|
|
9
|
-
/** The name sent in `content-disposition`: 1 to 512 characters, without control characters or slashes. */
|
|
10
|
-
filename: string;
|
|
11
|
-
/** Exact body length, checked before headers and while streaming. */
|
|
12
|
-
byteLength: number;
|
|
13
|
-
}
|
|
14
|
-
/** The output of an operation that answers with a file (`http.response: 'attachment'`). */
|
|
15
|
-
declare const AttachmentOutputSchema: import("@sinclair/typebox").TUnsafe<Attachment>;
|
|
16
2
|
/**
|
|
17
3
|
* Request correlation: request ids (a UUID, or a ray id from a trusted Cloudflare edge), W3C `traceparent`
|
|
18
4
|
* parsing, and the correlation that durable work persists.
|
|
19
5
|
*/
|
|
20
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Whether a value is a request id: a UUID or a Cloudflare ray id. A request id correlates diagnostics; never
|
|
8
|
+
* use one as authority or as a deduplication key.
|
|
9
|
+
*/
|
|
21
10
|
declare function isRequestId(value: unknown): value is string;
|
|
22
11
|
/**
|
|
23
|
-
*
|
|
24
|
-
* Cloudflare edge or a
|
|
25
|
-
*
|
|
12
|
+
* A request id: `trustedEdgeRay` when it is a valid request id, otherwise a random UUID. Pass a ray id only
|
|
13
|
+
* from the Cloudflare edge or from a caller authenticated separately, never an `x-request-id` or `cf-ray`
|
|
14
|
+
* value an untrusted caller sent.
|
|
26
15
|
*/
|
|
27
16
|
declare function createRequestId(trustedEdgeRay?: string | null): string;
|
|
28
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* A parsed W3C `traceparent` header of version 00. Parsing one starts no span, decides no sampling and
|
|
19
|
+
* authenticates nothing.
|
|
20
|
+
*/
|
|
29
21
|
interface TraceParent {
|
|
30
22
|
/** The trace id: 32 lowercase hexadecimal characters, never all zeros. */
|
|
31
23
|
traceId: string;
|
|
@@ -37,9 +29,9 @@ interface TraceParent {
|
|
|
37
29
|
/** Reads a W3C `traceparent` header of version 00, or nothing when it is malformed or all zeros. */
|
|
38
30
|
declare function parseTraceParent(value: string | null | undefined): TraceParent | undefined;
|
|
39
31
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* No principal,
|
|
32
|
+
* The correlation durable work persists with its domain data, so each later attempt can be tied to the
|
|
33
|
+
* request that started it: the owner starts a span for each attempt and links it to the origin, rather than
|
|
34
|
+
* keeping the request's span open. No principal, token, baggage, arguments or customer ids belong in it.
|
|
43
35
|
*/
|
|
44
36
|
interface DurableCorrelation {
|
|
45
37
|
/** The id of the request that started the work: a UUID or a Cloudflare ray id. */
|
|
@@ -52,28 +44,23 @@ interface DurableCorrelation {
|
|
|
52
44
|
}
|
|
53
45
|
/**
|
|
54
46
|
* The correlation to persist with durable work: a valid request id and, when it parses, the originating
|
|
55
|
-
* `traceparent`.
|
|
47
|
+
* `traceparent`. A request id that is not one throws a TypeError.
|
|
56
48
|
*/
|
|
57
49
|
declare function durableCorrelation(requestId: string, originTraceParent?: string): DurableCorrelation;
|
|
58
50
|
/** The `data` of a failure whose code declares none: an empty object. */
|
|
59
51
|
interface FailureData {}
|
|
60
52
|
/**
|
|
61
53
|
* A failure as every transport carries it: a stable code, a message for people that never contains input
|
|
62
|
-
* values, whether repeating the request may succeed, and the data its code declares.
|
|
54
|
+
* values, whether repeating the request may succeed, and the data its code declares. Its fields come from
|
|
55
|
+
* `FailureSchema`, so the type and the wire schema cannot drift apart.
|
|
63
56
|
*/
|
|
64
|
-
|
|
65
|
-
/** The failure code, stable across releases, that clients branch on, such as `NOT_FOUND`. */
|
|
66
|
-
code: string;
|
|
67
|
-
/** What went wrong, for people; it never contains input values. */
|
|
68
|
-
message: string;
|
|
69
|
-
/** Whether repeating the same request may succeed. */
|
|
70
|
-
retryable: boolean;
|
|
57
|
+
type Failure<Data = FailureData> = Omit<Static<typeof FailureSchema>, 'data'> & {
|
|
71
58
|
/**
|
|
72
59
|
* The details the code declares, such as `issues` for `INVALID_INPUT`; an empty object when it declares
|
|
73
60
|
* none.
|
|
74
61
|
*/
|
|
75
62
|
data: Data;
|
|
76
|
-
}
|
|
63
|
+
};
|
|
77
64
|
/**
|
|
78
65
|
* One failure of a catalog: its code, HTTP status, message, retryability, Retry-After seconds and,
|
|
79
66
|
* optionally, the strict schema of its data.
|
|
@@ -89,12 +76,12 @@ interface ErrorDefinition {
|
|
|
89
76
|
retryable?: boolean;
|
|
90
77
|
/** The seconds a client waits before retrying, sent as `Retry-After`. */
|
|
91
78
|
retryAfter?: number;
|
|
92
|
-
/**
|
|
79
|
+
/** The strict object schema of the failure's `data`; without one, its data is the empty object. */
|
|
93
80
|
dataSchema?: TObject<TProperties>;
|
|
94
81
|
}
|
|
95
82
|
/**
|
|
96
|
-
* Every failure, whatever its code: the
|
|
97
|
-
*
|
|
83
|
+
* Every failure, whatever its code: the shape each catalog's failures narrow, which every service's errors
|
|
84
|
+
* share. The OpenAPI document names each code's own failure, `NoteNotFoundFailure`, which fixes its code.
|
|
98
85
|
*/
|
|
99
86
|
declare const FailureSchema: TObject<{
|
|
100
87
|
code: import("@sinclair/typebox").TString;
|
|
@@ -250,7 +237,9 @@ type WithoutReservedNames<D> = [Extract<keyof D, ReservedName>] extends [never]
|
|
|
250
237
|
/**
|
|
251
238
|
* An error catalog: the standard failures and the application's own, each with a fixed code, status, message
|
|
252
239
|
* and retry semantics. `catalog.name.create(data?)` builds a failure; the application validates every failure
|
|
253
|
-
* an operation returns against the catalog.
|
|
240
|
+
* an operation returns against the catalog. It throws a TypeError for a name the standard failures or the
|
|
241
|
+
* catalog's members use, a code that is not uppercase words joined by underscores, a repeated code, a status
|
|
242
|
+
* outside 400 to 599, or a `dataSchema` that is not a strict object.
|
|
254
243
|
*/
|
|
255
244
|
declare function defineErrors<const D extends Record<string, ErrorDefinition>>(domain: WithoutReservedNames<D>): DefinedErrors<D>;
|
|
256
245
|
/**
|
|
@@ -265,7 +254,26 @@ declare function resultSchema<O extends TSchema, F extends TSchema>(value: O, er
|
|
|
265
254
|
ok: TLiteral<false>;
|
|
266
255
|
error: F;
|
|
267
256
|
}>]>;
|
|
268
|
-
/**
|
|
257
|
+
/** A file an HTTP operation answers with: its bytes, media type, filename and exact length. */
|
|
258
|
+
interface Attachment {
|
|
259
|
+
/** The file's bytes, as a buffer or an unlocked stream. */
|
|
260
|
+
body: ReadableStream<Uint8Array> | Uint8Array;
|
|
261
|
+
/** The media type sent as `content-type`: `type/subtype`, at most 255 characters. */
|
|
262
|
+
contentType: string;
|
|
263
|
+
/**
|
|
264
|
+
* The name sent in `content-disposition`: 1 to 512 characters, without control characters, slashes or
|
|
265
|
+
* backslashes.
|
|
266
|
+
*/
|
|
267
|
+
filename: string;
|
|
268
|
+
/**
|
|
269
|
+
* The body's exact length in bytes, sent as `content-length`: checked against a buffer before anything is
|
|
270
|
+
* sent, and held to while a stream is sent. At most the operation's `maxOutputBytes`.
|
|
271
|
+
*/
|
|
272
|
+
byteLength: number;
|
|
273
|
+
}
|
|
274
|
+
/** The output of an operation that answers with a file (`http.response: 'attachment'`). */
|
|
275
|
+
declare const AttachmentOutputSchema: import("@sinclair/typebox").TUnsafe<Attachment>;
|
|
276
|
+
/** A successful outcome and its value. Each transport presents it in its own envelope. */
|
|
269
277
|
interface Success<T> {
|
|
270
278
|
/** Always `true`, which marks a success. */
|
|
271
279
|
ok: true;
|
|
@@ -293,10 +301,19 @@ declare function err<E>(error: E): FailureResult<E>;
|
|
|
293
301
|
* its value, or a failure with a well-formed error. Anything else is not an answer at all.
|
|
294
302
|
*/
|
|
295
303
|
declare function isResult(value: unknown): value is Result<unknown, Failure>;
|
|
304
|
+
/** Why a byte body could not be read: it exceeds the limit, it is compressed, or it broke off. */
|
|
305
|
+
type BodyFailure = Failure & {
|
|
306
|
+
code: 'REQUEST_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'INVALID_INPUT';
|
|
307
|
+
};
|
|
296
308
|
/** The raw body of an operation declared with `http.body: 'bytes'`, read on demand. */
|
|
297
309
|
interface BinaryBody {
|
|
298
|
-
/**
|
|
299
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Reads the body within the operation's byte limit, once: every call answers the first read's result.
|
|
312
|
+
* `UNSUPPORTED_MEDIA_TYPE` for a compressed body, `REQUEST_TOO_LARGE` beyond the limit and `INVALID_INPUT`
|
|
313
|
+
* for a malformed length or a body that broke off or was aborted. Call it once the handler has admitted the
|
|
314
|
+
* resource the body is for.
|
|
315
|
+
*/
|
|
316
|
+
read: () => Promise<Result<Uint8Array<ArrayBuffer>, BodyFailure>>;
|
|
300
317
|
}
|
|
301
318
|
/** Opaque owner codecs already carry their decoded static type; only native transforms need traversal. */
|
|
302
319
|
type HasNativeTransform<S extends TSchema> = typeof TransformKind extends keyof S ? true : string extends S[typeof Kind] ? false : S extends TObject<infer P> ? true extends { [K in keyof P]: HasNativeTransform<P[K]>; }[keyof P] ? true : false : S extends TArray<infer I> ? HasNativeTransform<I> : S extends TUnion<infer U> | TTuple<infer U> ? HasNativeTransform<U[number]> : S extends TRecord<TSchema, infer V> ? HasNativeTransform<V> : false;
|
|
@@ -320,16 +337,30 @@ declare function matchesScopes(required: readonly string[], granted: readonly st
|
|
|
320
337
|
* OAuth protected-resource metadata (RFC 9728): the resources an application publishes and the document
|
|
321
338
|
* that describes each one.
|
|
322
339
|
*/
|
|
323
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* One OAuth protected resource an application publishes (`tokens.resources`), described by its
|
|
342
|
+
* configuration and never by the request's host.
|
|
343
|
+
*/
|
|
324
344
|
interface OAuthResource<E = unknown> {
|
|
325
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* The resource identifier clients request tokens for, an HTTPS URL, or a function of the env that answers
|
|
347
|
+
* it.
|
|
348
|
+
*/
|
|
326
349
|
audience: string | ((env: E) => string);
|
|
327
|
-
/**
|
|
350
|
+
/**
|
|
351
|
+
* The authorization servers that issue tokens for the resource, HTTPS URLs without a query, or a function
|
|
352
|
+
* of the env that answers them. Publishing them changes nothing about how tokens are verified.
|
|
353
|
+
*/
|
|
328
354
|
authorizationServers: readonly string[] | ((env: E) => readonly string[]);
|
|
329
|
-
/**
|
|
355
|
+
/** The scopes the document lists as `scopes_supported`, which may differ from the operations' scopes. */
|
|
330
356
|
scopes: readonly string[];
|
|
331
357
|
}
|
|
332
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* The RFC 9728 document of one resource: its `resource`, `authorization_servers`, `bearer_methods_supported`
|
|
360
|
+
* (`header`) and `scopes_supported`, read from configuration and the env, never from the request. It throws a
|
|
361
|
+
* TypeError when the audience or an issuer is not an HTTPS URL without credentials or a fragment (an issuer
|
|
362
|
+
* also without a query), when no issuer is named, or when a scope is malformed.
|
|
363
|
+
*/
|
|
333
364
|
declare function protectedResourceMetadata<E>(resource: OAuthResource<E>, env: E): {
|
|
334
365
|
resource: string;
|
|
335
366
|
authorization_servers: string[];
|
|
@@ -387,7 +418,12 @@ type TokenPrincipal = Static<typeof TokenPrincipalSchema>;
|
|
|
387
418
|
* plain HTTP bearer scheme with `description` saying how to obtain one, no
|
|
388
419
|
* OAuth discovery is served, and a 401 does not point at any. It requires
|
|
389
420
|
* `resolve` and cannot serve the MCP transport, whose clients discover
|
|
390
|
-
* authorization through OAuth
|
|
421
|
+
* authorization through OAuth, nor publish `resources`.
|
|
422
|
+
* - `oauth+bearer`: people present OAuth access tokens and machines bearer
|
|
423
|
+
* tokens the application verifies, such as workload keys; `resolve`, which
|
|
424
|
+
* it requires, verifies both. OpenAPI publishes the authorization-code flow
|
|
425
|
+
* and a bearer scheme with `description`, each operation offering the ones
|
|
426
|
+
* its `actorKinds` name, which every operation must then declare.
|
|
391
427
|
*/
|
|
392
428
|
type TokenScheme = {
|
|
393
429
|
type: 'oauth';
|
|
@@ -398,7 +434,33 @@ type TokenScheme = {
|
|
|
398
434
|
type: 'oauth+bearer';
|
|
399
435
|
description: string;
|
|
400
436
|
};
|
|
401
|
-
/**
|
|
437
|
+
/**
|
|
438
|
+
* Where a request presents its token: `authorization`, as a bearer token of the `Authorization` header, or
|
|
439
|
+
* `cloudflare-access`, as the application token Cloudflare Access sets in `Cf-Access-Jwt-Assertion` on each
|
|
440
|
+
* request it lets through.
|
|
441
|
+
*/
|
|
442
|
+
type TokenSource = 'authorization' | 'cloudflare-access';
|
|
443
|
+
/**
|
|
444
|
+
* What a Cloudflare Access application token grants, under the `cloudflare-access` source. Access decides who
|
|
445
|
+
* reaches the application and grants no scope, so the policy states them: every person Access lets through
|
|
446
|
+
* holds `people`, and a service token what `services` lists under its client id. The organization is named
|
|
447
|
+
* once, as `organizationId` or as the claim `claims.organization` names.
|
|
448
|
+
*/
|
|
449
|
+
interface TokenAccess {
|
|
450
|
+
/** The organization every caller acts in, when the tokens carry none: an application of one tenant. */
|
|
451
|
+
organizationId?: string;
|
|
452
|
+
/** The scopes every person Access lets through holds, each of the application's namespace. */
|
|
453
|
+
people: readonly string[];
|
|
454
|
+
/**
|
|
455
|
+
* The scopes of each service token, by its client id (`<id>.access`, its token's `common_name`); a service
|
|
456
|
+
* token not listed holds none.
|
|
457
|
+
*/
|
|
458
|
+
services?: Readonly<Record<string, readonly string[]>>;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* What `tokens.resolve` and a `tokens.resourceMetadataUrl` function receive about the request being admitted.
|
|
462
|
+
* It belongs to that request: never keep it beyond it.
|
|
463
|
+
*/
|
|
402
464
|
interface TokenResolutionContext<E = unknown> {
|
|
403
465
|
/** The request's environment bindings, as scoped by `aroundOperation` when it wraps the operation. */
|
|
404
466
|
readonly env: E;
|
|
@@ -406,7 +468,11 @@ interface TokenResolutionContext<E = unknown> {
|
|
|
406
468
|
readonly request: Request;
|
|
407
469
|
/** Where the request arrived: `mcp` at a transport's path, such as `/mcp`, else `http`. */
|
|
408
470
|
readonly surface: 'http' | 'mcp';
|
|
409
|
-
/**
|
|
471
|
+
/**
|
|
472
|
+
* Every scope the application declares (its operations' scopes and conditional scopes, and each transport's
|
|
473
|
+
* scope), for a resolver that maps its own grants onto them. They are what the application can grant, never
|
|
474
|
+
* what the caller holds.
|
|
475
|
+
*/
|
|
410
476
|
readonly applicationScopes: readonly string[];
|
|
411
477
|
/**
|
|
412
478
|
* Keeps work running after the response, such as the Worker's `ExecutionContext`; absent when the handler
|
|
@@ -451,11 +517,11 @@ interface TokenClaims {
|
|
|
451
517
|
*/
|
|
452
518
|
machineSubject?: '{client}@clients' | '{client}';
|
|
453
519
|
}
|
|
454
|
-
/** A token `
|
|
520
|
+
/** A token `vp dev` accepts from localhost, so a service runs without an authorization server. */
|
|
455
521
|
interface TokenDevelopment {
|
|
456
522
|
/**
|
|
457
|
-
* The env binding that holds the token, such as `DEVELOPMENT_TOKEN` set in `.dev.vars
|
|
458
|
-
*
|
|
523
|
+
* The env binding that holds the token, such as `DEVELOPMENT_TOKEN` set in `.dev.vars`, which `maximus()`
|
|
524
|
+
* declares in development alone; at least 32 characters, or it never matches.
|
|
459
525
|
*/
|
|
460
526
|
binding: string;
|
|
461
527
|
/** The organization the developer acts in; `local-development` by default. */
|
|
@@ -463,20 +529,23 @@ interface TokenDevelopment {
|
|
|
463
529
|
}
|
|
464
530
|
/**
|
|
465
531
|
* How the application verifies bearer tokens: the audiences they must carry, the OAuth issuer and its JWKS,
|
|
466
|
-
* or the application's own `resolve`, the scheme OpenAPI publishes and the OAuth discovery it serves
|
|
532
|
+
* or the application's own `resolve`, the scheme OpenAPI publishes and the OAuth discovery it serves; or,
|
|
533
|
+
* under the `cloudflare-access` source, Cloudflare Access application tokens and what they grant.
|
|
467
534
|
*/
|
|
468
535
|
interface TokenPolicy<E = unknown> {
|
|
469
536
|
/**
|
|
470
537
|
* The audience access tokens must carry, or a list of audiences any one of which a token may carry
|
|
471
538
|
* (the service's own and a gateway's in front of it, for example). The first is the canonical
|
|
472
|
-
* resource that OAuth discovery names.
|
|
539
|
+
* resource that OAuth discovery names. Under Cloudflare Access, the application's AUD tag.
|
|
473
540
|
*/
|
|
474
541
|
audience: string | readonly string[];
|
|
475
542
|
/**
|
|
476
|
-
* The OAuth authorization server, an absolute HTTPS URL
|
|
477
|
-
*
|
|
543
|
+
* The OAuth authorization server, an absolute HTTPS URL that a token must name as `iss`, or a list of the
|
|
544
|
+
* issuer identifiers one server answers to, such as an Auth0 tenant's own domain and its custom domain. The
|
|
545
|
+
* first is canonical: the authorization server discovery names, and what the JWKS and the endpoints resolve
|
|
546
|
+
* against. Required unless `scheme.type` is `bearer`, or `resolve` verifies Cloudflare Access tokens itself.
|
|
478
547
|
*/
|
|
479
|
-
issuer?: string;
|
|
548
|
+
issuer?: string | readonly string[];
|
|
480
549
|
/** The issuer's JWKS URL, resolved against `issuer` and HTTPS only; defaults to `.well-known/jwks.json`. */
|
|
481
550
|
jwksUri?: string;
|
|
482
551
|
/**
|
|
@@ -494,20 +563,53 @@ interface TokenPolicy<E = unknown> {
|
|
|
494
563
|
algorithms?: readonly TokenAlgorithm[];
|
|
495
564
|
/**
|
|
496
565
|
* Where the access tokens put the organization, the scopes, the client and a person's permissions, and the
|
|
497
|
-
* subject a machine's carries; the standard claims and Auth0's conventions by default.
|
|
566
|
+
* subject a machine's carries; the standard claims and Auth0's conventions by default. Under Cloudflare
|
|
567
|
+
* Access, only the organization's claim.
|
|
498
568
|
*/
|
|
499
569
|
claims?: TokenClaims;
|
|
570
|
+
/**
|
|
571
|
+
* Where requests present their tokens: `authorization` (the default), as a bearer token, or
|
|
572
|
+
* `cloudflare-access`, as the application token Cloudflare Access sets in `Cf-Access-Jwt-Assertion`, which
|
|
573
|
+
* is then the only place a token is read: never `Authorization`, never the `CF_Authorization` cookie. The
|
|
574
|
+
* development token is a bearer token from localhost under either source. Under `cloudflare-access`, no
|
|
575
|
+
* OAuth discovery is served, a 401 challenges with a plain `Bearer`, writes a browser sends for another
|
|
576
|
+
* site are refused, and no MCP transport can be mounted.
|
|
577
|
+
*/
|
|
578
|
+
source?: TokenSource;
|
|
579
|
+
/**
|
|
580
|
+
* What Cloudflare Access application tokens grant under the `cloudflare-access` source: the scopes of a
|
|
581
|
+
* person and of each service token, and the organization every caller acts in. Without it, `resolve`
|
|
582
|
+
* verifies Access tokens itself.
|
|
583
|
+
*/
|
|
584
|
+
access?: TokenAccess;
|
|
500
585
|
/**
|
|
501
586
|
* A token accepted from localhost as a developer holding every scope the application declares. A request
|
|
502
587
|
* to any other host never matches, and neither does a token shorter than 32 characters. Never set the
|
|
503
588
|
* token on a deployed Worker.
|
|
504
589
|
*/
|
|
505
590
|
development?: TokenDevelopment;
|
|
506
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* Verifies every token the request presents at the policy's `source` itself, in place of the default
|
|
593
|
+
* verification; only the development token is checked before it. It answers the token's principal, or a
|
|
594
|
+
* failure Result: `FORBIDDEN` answers 403 and any other failure 401. Verify the token cryptographically. A
|
|
595
|
+
* principal that does not match `TokenPrincipalSchema`, a client whose class disagrees with the actor kind
|
|
596
|
+
* (a `machine` client is a `service`), a machine whose actor id is not its client id or
|
|
597
|
+
* `<client id>@clients` (except under `oauth+bearer`), and a thrown error answer `UNAUTHORIZED`. The
|
|
598
|
+
* operation's scopes are then checked against the principal's.
|
|
599
|
+
*/
|
|
507
600
|
resolve?: (token: string, context?: TokenResolutionContext<E>) => Promise<TokenPrincipal | Result<TokenPrincipal, Failure>>;
|
|
508
|
-
/**
|
|
601
|
+
/**
|
|
602
|
+
* The protected-resource metadata URL a 401 challenge names, `WWW-Authenticate: Bearer
|
|
603
|
+
* resource_metadata="…"`, when it is not the default document below the base path: a URL, a function of the
|
|
604
|
+
* request that answers one, or `null` for a plain `Bearer` challenge. Set it when the API and its OAuth
|
|
605
|
+
* resource have different origins or paths, and whenever `resources` lists any.
|
|
606
|
+
*/
|
|
509
607
|
resourceMetadataUrl?: string | null | ((context: TokenResolutionContext<E>) => string | null);
|
|
510
|
-
/**
|
|
608
|
+
/**
|
|
609
|
+
* Protected-resource metadata documents (RFC 9728) to serve instead of the default one, by absolute path
|
|
610
|
+
* at or below `/.well-known/oauth-protected-resource`, one per resource. When set, the default document
|
|
611
|
+
* answers `NOT_FOUND`. A `bearer` scheme cannot set it.
|
|
612
|
+
*/
|
|
511
613
|
resources?: Readonly<Record<string, OAuthResource<E>>>;
|
|
512
614
|
/**
|
|
513
615
|
* How clients obtain tokens, as OpenAPI and discovery publish it: `oauth` (the default), `bearer` for
|
|
@@ -518,15 +620,30 @@ interface TokenPolicy<E = unknown> {
|
|
|
518
620
|
/**
|
|
519
621
|
* The principal a verified access token grants, read where `mapping` says. A subject of the shape
|
|
520
622
|
* `mapping.machineSubject` names, `<client id>@clients` by default, is a machine; anyone else is a person,
|
|
521
|
-
* who holds only the granted scopes their permissions claim also lists. Malformed or inconsistent claims
|
|
522
|
-
*
|
|
623
|
+
* who holds only the granted scopes their permissions claim also lists. Malformed or inconsistent claims,
|
|
624
|
+
* such as a missing `sub`, a subject shaped like another client's, or a token of the client credentials grant
|
|
625
|
+
* (`gty: client-credentials`, as Auth0 names it) whose subject is not a machine's, are refused as
|
|
626
|
+
* `UNAUTHORIZED`.
|
|
523
627
|
*/
|
|
524
628
|
declare function projectToken(claims: unknown, mapping?: TokenClaims): Result<TokenPrincipal, Failure>;
|
|
525
|
-
/**
|
|
629
|
+
/**
|
|
630
|
+
* Verifies OAuth access tokens against the issuer's JWKS and answers their claims, or throws for a token it
|
|
631
|
+
* refuses: the signature by one of the policy's algorithms (`RS256` by default), an `iss` that is one of the
|
|
632
|
+
* policy's issuers, an `aud` that names any one of the policy's audiences, `exp` and `sub`, with five seconds
|
|
633
|
+
* of clock tolerance, and a `typ` header, when the token has one, of a plain JWT or an RFC 9068 access token
|
|
634
|
+
* (`at+jwt`). The JWKS, at `jwksUri` resolved against the first issuer, is fetched within ten seconds and
|
|
635
|
+
* cached for ten minutes. An issuer or JWKS URL that is not HTTPS throws a TypeError at construction.
|
|
636
|
+
*/
|
|
526
637
|
declare function createTokenVerifier<E>(policy: TokenPolicy<E>): (token: string) => Promise<import("jose").JWTPayload>;
|
|
527
638
|
/**
|
|
528
|
-
* Admits a request by its
|
|
529
|
-
*
|
|
639
|
+
* Admits a request by its token: verifies it (the development token, a bearer token from a local host; else
|
|
640
|
+
* the policy's own `resolve` when it has one; else, for OAuth, against the issuer's JWKS, or for Cloudflare
|
|
641
|
+
* Access, against the team's keys, projected by `access`) and checks that its scopes admit the request. The
|
|
642
|
+
* token is the bearer token of `Authorization`, or under the `cloudflare-access` source the application token
|
|
643
|
+
* of `Cf-Access-Jwt-Assertion` alone. A request without a token, with one longer than 16384 characters, or
|
|
644
|
+
* with an `x-api-key` header is refused; without `resolve` (or, for a bearer token, a development token), the
|
|
645
|
+
* token must be a compact JWS. Refusals are `UNAUTHORIZED` or `FORBIDDEN` failures, never exceptions. `given`
|
|
646
|
+
* stands in for the JWKS check in tests, answering a token's claims.
|
|
530
647
|
*/
|
|
531
648
|
declare function createTokenAuthorization<E>(policy: TokenPolicy<E>, given?: (token: string) => Promise<unknown>): (request: Request, scope: string | readonly string[], context?: TokenResolutionContext<E>, scopeMatch?: ScopeMatch) => Promise<Result<TokenPrincipal, Failure>>;
|
|
532
649
|
/** Where background work goes: the runtime's `waitUntil`, such as a Worker's ExecutionContext. */
|
|
@@ -600,8 +717,9 @@ interface AdmissionObservation {
|
|
|
600
717
|
errorCode: string;
|
|
601
718
|
}
|
|
602
719
|
/**
|
|
603
|
-
* Receives observations
|
|
604
|
-
*
|
|
720
|
+
* Receives observations of operation calls and refused admissions as background work, while telemetry is on
|
|
721
|
+
* and the runtime gives the call a `waitUntil`, and unexpected errors as they happen. An observer that fails
|
|
722
|
+
* affects neither the response nor another observer.
|
|
605
723
|
*/
|
|
606
724
|
interface Observer<E> {
|
|
607
725
|
/**
|
|
@@ -635,12 +753,15 @@ interface TelemetryConfig<E> {
|
|
|
635
753
|
* the others.
|
|
636
754
|
*/
|
|
637
755
|
observers?: readonly Observer<E>[];
|
|
638
|
-
/**
|
|
756
|
+
/**
|
|
757
|
+
* Returns the trace id of the span the tracing exporter has active, which observations carry when it is a
|
|
758
|
+
* valid W3C trace id. Read it from the active span, never from a request header, and never generate one.
|
|
759
|
+
*/
|
|
639
760
|
traceId?: () => string | null;
|
|
640
761
|
}
|
|
641
762
|
/**
|
|
642
|
-
* Whether telemetry is on for this env: it is unless `enabled` is false, or a function that returns false
|
|
643
|
-
* has no env to read.
|
|
763
|
+
* Whether telemetry is on for this env: it is unless `enabled` is false, or a function that returns false,
|
|
764
|
+
* has no env to read or throws.
|
|
644
765
|
*/
|
|
645
766
|
declare function telemetryEnabled<E>(config: Pick<TelemetryConfig<E>, 'enabled'> | undefined, env: E | undefined): boolean;
|
|
646
767
|
/**
|
|
@@ -652,10 +773,14 @@ declare function withDiagnostics<T>(enabled: boolean, callback: () => T, observe
|
|
|
652
773
|
declare function diagnosticsEnabled(): boolean;
|
|
653
774
|
/**
|
|
654
775
|
* Logs an unexpected error by its safe description only (`maximus.unexpected`: error and cause names, issue
|
|
655
|
-
* count, stack locations; never a message) and tells the observers.
|
|
776
|
+
* count, stack locations; never a message) and tells the observers of the current `withDiagnostics` scope.
|
|
777
|
+
* It does nothing while diagnostics are off.
|
|
656
778
|
*/
|
|
657
779
|
declare function reportUnexpected(error: unknown, surface?: string, requestId?: string): void;
|
|
658
|
-
/**
|
|
780
|
+
/**
|
|
781
|
+
* Hands the observation of one operation call to the observers, as background work. Nothing is recorded
|
|
782
|
+
* while telemetry is off or without a background context.
|
|
783
|
+
*/
|
|
659
784
|
declare function recordExecution<E>(manifest: {
|
|
660
785
|
name: string;
|
|
661
786
|
telemetry?: TelemetryConfig<E>;
|
|
@@ -666,9 +791,12 @@ declare function recordExecution<E>(manifest: {
|
|
|
666
791
|
started: number;
|
|
667
792
|
result: Result<unknown, Failure>;
|
|
668
793
|
}): void;
|
|
669
|
-
/**
|
|
794
|
+
/**
|
|
795
|
+
* What the transport verified about a call's token, kept apart from the principal: the surface, the granted
|
|
796
|
+
* scopes, the OAuth client and the token itself. Context preparation and handlers receive a frozen copy.
|
|
797
|
+
*/
|
|
670
798
|
interface InvocationAuthority {
|
|
671
|
-
/** The transport whose admission verified the token
|
|
799
|
+
/** The transport whose admission verified the token: `http` or `mcp`. */
|
|
672
800
|
readonly surface: 'http' | 'mcp';
|
|
673
801
|
/** The scopes the verified token grants, which a handler checks its `conditionalScopes` against. */
|
|
674
802
|
readonly scopes: readonly string[];
|
|
@@ -678,8 +806,8 @@ interface InvocationAuthority {
|
|
|
678
806
|
* The bearer token the call was admitted with, verified: on an HTTP or MCP call to the service's origin,
|
|
679
807
|
* including one a gateway forwards. It is the caller's OAuth access token, unless
|
|
680
808
|
* `tokens.resolve` admitted another credential (a workload key under `oauth+bearer`) or it is the
|
|
681
|
-
* development token; absent under the application's own `bearer` scheme.
|
|
682
|
-
* service as the same caller,
|
|
809
|
+
* development token; absent under the application's own `bearer` scheme. An operation passes it on to call
|
|
810
|
+
* another service as the same caller, and that service verifies it again. Never log, store or return it.
|
|
683
811
|
*/
|
|
684
812
|
readonly token?: string;
|
|
685
813
|
}
|
|
@@ -690,7 +818,7 @@ interface InvocationAuthority {
|
|
|
690
818
|
interface Invocation<Env> {
|
|
691
819
|
/** The Worker's bindings; inside `http.aroundOperation`, the environment that hook passed to `run`. */
|
|
692
820
|
env: Env;
|
|
693
|
-
/**
|
|
821
|
+
/** The request body's reader, present only on an HTTP operation that declares `http.body: 'bytes'`. */
|
|
694
822
|
readonly body?: BinaryBody;
|
|
695
823
|
/**
|
|
696
824
|
* The verified caller: its actor, actor kind, organization and request id. Scope every tenant query by its
|
|
@@ -698,28 +826,34 @@ interface Invocation<Env> {
|
|
|
698
826
|
*/
|
|
699
827
|
principal: Principal;
|
|
700
828
|
/**
|
|
701
|
-
* The verified token's surface, scopes and
|
|
702
|
-
* over
|
|
829
|
+
* The verified token's surface, scopes, client and token, on HTTP and MCP calls whose token names a client;
|
|
830
|
+
* absent over RPC and for a token that names no client.
|
|
703
831
|
*/
|
|
704
832
|
readonly authority?: InvocationAuthority;
|
|
705
|
-
/**
|
|
833
|
+
/** The operation's input, decoded and checked once; preparation must neither check it again nor log it. */
|
|
706
834
|
readonly input?: unknown;
|
|
707
|
-
/**
|
|
835
|
+
/** The name of the operation being called, which the builder sets; never taken from caller input. */
|
|
708
836
|
readonly operation?: string;
|
|
709
|
-
/**
|
|
837
|
+
/**
|
|
838
|
+
* Where the call keeps best-effort work running after its answer, the runtime's `waitUntil`; absent when
|
|
839
|
+
* the runtime gives none.
|
|
840
|
+
*/
|
|
710
841
|
readonly background?: BackgroundContext;
|
|
711
842
|
}
|
|
712
|
-
/** One scope, or several
|
|
843
|
+
/** One scope, or several: any one of them admits the caller, or every one under `scopeMatch: 'all'`. */
|
|
713
844
|
type OperationScope = string | readonly [string, ...string[]];
|
|
714
|
-
/** Whether an operation belongs in public contracts
|
|
845
|
+
/** Whether an operation belongs in public contracts: the OpenAPI document and the discovery metadata. */
|
|
715
846
|
declare function isPublicOperation(declaration: {
|
|
716
847
|
visibility?: 'public' | 'internal';
|
|
717
848
|
}): boolean;
|
|
718
|
-
/** The scopes of an operation as a list
|
|
849
|
+
/** The scopes of an operation as a list. */
|
|
719
850
|
declare function operationScopes(declaration: {
|
|
720
851
|
scope: OperationScope;
|
|
721
852
|
}): readonly string[];
|
|
722
|
-
/**
|
|
853
|
+
/**
|
|
854
|
+
* Whether granted scopes admit an operation: any one of its scopes, or every one under `scopeMatch: 'all'`.
|
|
855
|
+
* HTTP admission, MCP listing and calls, and execution share it.
|
|
856
|
+
*/
|
|
723
857
|
declare function operationMatchesScopes(declaration: {
|
|
724
858
|
scope: OperationScope;
|
|
725
859
|
scopeMatch?: ScopeMatch;
|
|
@@ -729,24 +863,39 @@ declare function operationMatchesScopes(declaration: {
|
|
|
729
863
|
* explicitly, its visibility and the actors it admits.
|
|
730
864
|
*/
|
|
731
865
|
interface Exposure {
|
|
732
|
-
/**
|
|
866
|
+
/** The principal kinds the operation admits: every kind when omitted. */
|
|
733
867
|
actorKinds?: readonly Principal['actorKind'][];
|
|
734
|
-
/**
|
|
868
|
+
/** The HTTP route: its method, its versioned path and how its body and answer travel. */
|
|
735
869
|
http?: {
|
|
870
|
+
/** The route's method; only a read may use `GET`. */
|
|
736
871
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
872
|
+
/**
|
|
873
|
+
* The versioned path template, such as `/v1/notes/{noteId}`, served below the HTTP handler's `basePath`.
|
|
874
|
+
* A `{parameter}` fills a whole segment and names a required string input field.
|
|
875
|
+
*/
|
|
737
876
|
path: string;
|
|
877
|
+
/**
|
|
878
|
+
* `bytes`: the body is raw bytes the handler reads on demand, and the input comes from the path, the
|
|
879
|
+
* query string and `headers`. Not allowed on `GET`, nor on an operation that is also an MCP tool or RPC
|
|
880
|
+
* method.
|
|
881
|
+
*/
|
|
738
882
|
body?: 'bytes';
|
|
739
|
-
/**
|
|
883
|
+
/**
|
|
884
|
+
* Input fields of a byte operation read from request headers, by field name:
|
|
885
|
+
* `{ checksum: 'x-checksum' }`. The input schema decodes them; `authorization`, `cookie`, `host`,
|
|
886
|
+
* `content-length` and `content-encoding` are never input.
|
|
887
|
+
*/
|
|
740
888
|
headers?: Readonly<Record<string, string>>;
|
|
889
|
+
/** `attachment`: the operation answers a file, its output `AttachmentOutputSchema`. HTTP-only. */
|
|
741
890
|
response?: 'attachment';
|
|
891
|
+
/** The status of a successful answer; 200 by default. */
|
|
742
892
|
successStatus?: 200 | 201 | 202;
|
|
743
893
|
};
|
|
744
894
|
/**
|
|
745
|
-
* `internal
|
|
746
|
-
* scope-checked like any other, but it is absent from the public OpenAPI
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
* not authorization: the scope is what admits the caller.
|
|
895
|
+
* `public` (the default) or `internal`, an operation for the service's own staff. An internal operation
|
|
896
|
+
* stays routed and scope-checked like any other, but it is absent from the public OpenAPI document and from
|
|
897
|
+
* the protected-resource `scopes_supported`; MCP lists it, as every tool, only to tokens that carry its
|
|
898
|
+
* scope. Hiding is not authorization: the scope is what admits the caller.
|
|
750
899
|
*/
|
|
751
900
|
visibility?: 'public' | 'internal';
|
|
752
901
|
/**
|
|
@@ -754,8 +903,11 @@ interface Exposure {
|
|
|
754
903
|
* outside the service (`openWorldHint`, default `true`).
|
|
755
904
|
*/
|
|
756
905
|
mcp?: {
|
|
906
|
+
/** The tool's unique name: a lowercase letter, then up to 63 letters, digits or underscores. */
|
|
757
907
|
name: string;
|
|
908
|
+
/** Whether repeating a call is safe, published as the tool's `idempotentHint`. */
|
|
758
909
|
idempotent: boolean;
|
|
910
|
+
/** Whether the tool reaches outside the service, published as its `openWorldHint`; `true` when absent. */
|
|
759
911
|
openWorld?: boolean;
|
|
760
912
|
};
|
|
761
913
|
/**
|
|
@@ -771,19 +923,24 @@ interface Exposure {
|
|
|
771
923
|
*/
|
|
772
924
|
interface OperationShape extends Exposure {
|
|
773
925
|
/**
|
|
774
|
-
* The scope a caller needs
|
|
775
|
-
* caller (`['notes:notes:read', 'notes:notes:write']`: a write grant
|
|
776
|
-
*
|
|
926
|
+
* The scope a caller needs, `<namespace>:<resource>:<action>`. Several scopes mean any one of them admits
|
|
927
|
+
* the caller (`['notes:notes:read', 'notes:notes:write']`: a write grant also reads), unless `scopeMatch`
|
|
928
|
+
* is `all`. Published as OpenAPI security requirements: one per scope, or one with every scope under `all`.
|
|
777
929
|
*/
|
|
778
930
|
scope: OperationScope;
|
|
779
|
-
/**
|
|
931
|
+
/** How several scopes admit a caller: `any` (the default) needs one of them, `all` needs every one. */
|
|
780
932
|
scopeMatch?: ScopeMatch;
|
|
781
|
-
/**
|
|
933
|
+
/**
|
|
934
|
+
* Scopes the handler checks itself, against `authority.scopes`, for particular resources or fields:
|
|
935
|
+
* namespaced, listed once and distinct from the scopes that admit the call. A call without `authority`,
|
|
936
|
+
* such as one over RPC or with a token that names no client, is refused with `FORBIDDEN` before it runs.
|
|
937
|
+
*/
|
|
782
938
|
conditionalScopes?: readonly string[];
|
|
783
939
|
/**
|
|
784
940
|
* The domain failure codes the operation may answer, besides the standard ones every operation may.
|
|
785
|
-
* Declared, they are all its documents list, and any other domain failure it returns
|
|
786
|
-
* INTERNAL_ERROR and is reported. Omitted, every failure of the catalog is
|
|
941
|
+
* Declared, they are all its documents list, and any other domain failure it returns, from its context,
|
|
942
|
+
* middleware or handler, becomes INTERNAL_ERROR and is reported. Omitted, every failure of the catalog is
|
|
943
|
+
* listed and allowed.
|
|
787
944
|
*/
|
|
788
945
|
failures?: readonly string[];
|
|
789
946
|
/** A short human name: the OpenAPI `summary` and the MCP tool's title. */
|
|
@@ -810,57 +967,75 @@ interface OperationShape extends Exposure {
|
|
|
810
967
|
*/
|
|
811
968
|
output: TSchema;
|
|
812
969
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* whose input is legitimately large (a CSV
|
|
816
|
-
* application-wide; the ceiling is 16 MiB. Not allowed on GET operations,
|
|
817
|
-
*
|
|
970
|
+
* The largest request body this operation accepts, in bytes: its JSON body, or its byte body under
|
|
971
|
+
* `http.body: 'bytes'`. A larger one answers `REQUEST_TOO_LARGE`. Defaults to the application's
|
|
972
|
+
* `maxBodyBytes` (32 KiB by default). Raise it only for operations whose input is legitimately large (a CSV
|
|
973
|
+
* import, a document), never application-wide; the ceiling is 16 MiB. Not allowed on GET operations, whose
|
|
974
|
+
* input is the query string.
|
|
818
975
|
*/
|
|
819
976
|
maxBodyBytes?: number;
|
|
820
|
-
/**
|
|
977
|
+
/**
|
|
978
|
+
* The largest output this operation answers, in bytes: its value's JSON, or an attachment's `byteLength`.
|
|
979
|
+
* Defaults to the application's `maxOutputBytes` (256 KiB by default), up to 16 MiB. A larger output is the
|
|
980
|
+
* server's error, `INTERNAL_ERROR`.
|
|
981
|
+
*/
|
|
821
982
|
maxOutputBytes?: number;
|
|
822
983
|
/** The handler: it receives the prepared context and the decoded input and returns a `Result`. */
|
|
823
984
|
execute: (context: never, input: never) => unknown;
|
|
824
|
-
/**
|
|
985
|
+
/**
|
|
986
|
+
* The context preparation and middleware the builder captured when the operation was declared, so each
|
|
987
|
+
* mounted module keeps its own; without it, execution uses the application's `context` and `middleware`.
|
|
988
|
+
*/
|
|
825
989
|
pipeline?: {
|
|
990
|
+
/** Prepares the call's context from its invocation; a failure it returns answers the call. */
|
|
826
991
|
context: (invocation: never) => Promise<Result<unknown, Failure>>;
|
|
992
|
+
/** The middleware that wraps the handler, in the order it runs. */
|
|
827
993
|
middleware: readonly OperationMiddleware<never>[];
|
|
828
994
|
};
|
|
829
995
|
}
|
|
830
996
|
/**
|
|
831
|
-
*
|
|
832
|
-
*
|
|
997
|
+
* The fields of an operation's definition besides its exposure, as `.operation()` takes them: its scope,
|
|
998
|
+
* words, effect, failures, schemas and limits.
|
|
833
999
|
*/
|
|
834
|
-
|
|
835
|
-
scope: OperationScope;
|
|
836
|
-
scopeMatch?: ScopeMatch;
|
|
837
|
-
conditionalScopes?: readonly string[];
|
|
838
|
-
title: string;
|
|
839
|
-
description: string;
|
|
840
|
-
group?: string;
|
|
841
|
-
effect: OperationShape['effect'];
|
|
1000
|
+
type OperationFields<I extends TSchema, O extends TSchema> = Omit<OperationShape, keyof Exposure | 'input' | 'output' | 'execute' | 'pipeline'> & {
|
|
842
1001
|
input: I;
|
|
843
1002
|
output: O;
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1003
|
+
};
|
|
1004
|
+
/** A definition with the exposure its declaration names, keeping that exposure's literal types. */
|
|
1005
|
+
type OperationDefinition<I extends TSchema, O extends TSchema, X> = X & OperationFields<I, O>;
|
|
1006
|
+
/** What a handler receives besides its input: the prepared context and, for a declared byte body, its reader. */
|
|
1007
|
+
type OperationContext<C, X> = C & (X extends {
|
|
1008
|
+
http: {
|
|
1009
|
+
body: 'bytes';
|
|
1010
|
+
};
|
|
1011
|
+
} ? {
|
|
1012
|
+
body: BinaryBody;
|
|
1013
|
+
} : object);
|
|
1014
|
+
/** An operation's handler: the prepared context and the decoded input in, a Result of its output out. */
|
|
1015
|
+
type OperationHandler<C, I extends TSchema, O extends TSchema, X> = (context: OperationContext<C, X>, input: StaticDecode$1<I>) => Promise<Result<Static<O>, Failure>>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Declares one operation on its own, keeping its literal types. The builder's `.operation()` is the usual way
|
|
1018
|
+
* to declare one. As there, `execute` receives the decoded input, `StaticDecode<typeof input>`.
|
|
1019
|
+
*/
|
|
1020
|
+
declare function operation<C, I extends TSchema, O extends TSchema, const X extends Exposure>(definition: OperationDefinition<I, O, X> & {
|
|
1021
|
+
execute: OperationHandler<C, I, O, X>;
|
|
1022
|
+
}): X & Omit<OperationShape, "execute" | "input" | "output" | "pipeline" | keyof Exposure> & {
|
|
853
1023
|
input: I;
|
|
854
1024
|
output: O;
|
|
855
|
-
|
|
1025
|
+
} & {
|
|
1026
|
+
execute: OperationHandler<C, I, O, X>;
|
|
856
1027
|
};
|
|
857
1028
|
/** The intersection of a union's members: the operations of every composed group. */
|
|
858
1029
|
type Intersection<U> = (U extends unknown ? (value: U) => void : never) extends ((value: infer I) => void) ? I : never;
|
|
859
|
-
/**
|
|
1030
|
+
/**
|
|
1031
|
+
* Merges groups of operations into one, never overwriting: a name two groups declare throws a TypeError,
|
|
1032
|
+
* `Duplicate operation: <name>`, which names the route or tool of each when both have one.
|
|
1033
|
+
*/
|
|
860
1034
|
declare function composeOperations<const G extends readonly Record<string, OperationShape>[]>(...groups: G): Intersection<G[number]>;
|
|
861
1035
|
/**
|
|
862
|
-
* Code that wraps an operation after admission and preparation: it receives the context and `next`, which
|
|
863
|
-
*
|
|
1036
|
+
* Code that wraps an operation after admission and preparation: it receives the context and `next`, which
|
|
1037
|
+
* runs the rest of the chain and the handler, and returns a Result. It calls `next` at most once: a second
|
|
1038
|
+
* call rejects.
|
|
864
1039
|
*/
|
|
865
1040
|
type OperationMiddleware<C> = (context: C, next: () => Promise<Result<unknown, Failure>>) => Promise<Result<unknown, Failure>>;
|
|
866
1041
|
/** A Markdown usage guide, served over MCP as a resource and a reusable prompt. */
|
|
@@ -910,12 +1085,22 @@ interface McpConfiguration {
|
|
|
910
1085
|
* transport reads.
|
|
911
1086
|
*/
|
|
912
1087
|
interface AppManifest<Env, C, Ops extends Record<string, OperationShape>> {
|
|
913
|
-
/**
|
|
1088
|
+
/**
|
|
1089
|
+
* The service's identifier, a lowercase kebab-case word of 2 to 64 characters: the MCP server name and the
|
|
1090
|
+
* `service` that `/health` and telemetry report.
|
|
1091
|
+
*/
|
|
914
1092
|
name: string;
|
|
915
1093
|
/** The prefix of every scope, `<namespace>:<resource>:<action>`; it matches `^[a-z][a-z0-9-]{1,63}$`. */
|
|
916
1094
|
namespace: string;
|
|
917
1095
|
/** The service's human name: OpenAPI `info.title`, the MCP server title and the OAuth `resource_name`. */
|
|
918
1096
|
title: string;
|
|
1097
|
+
/** What the service is for, in a sentence or two: OpenAPI `info.description`. */
|
|
1098
|
+
description?: string;
|
|
1099
|
+
/**
|
|
1100
|
+
* What each group of operations holds, by the group's name, such as
|
|
1101
|
+
* `{ Notes: "The notes of the caller's organization." }`: the description of its OpenAPI tag.
|
|
1102
|
+
*/
|
|
1103
|
+
groups?: Readonly<Record<string, string>>;
|
|
919
1104
|
/**
|
|
920
1105
|
* The service's version: OpenAPI `info.version`, the MCP server version and the `version` that `/health`
|
|
921
1106
|
* reports.
|
|
@@ -957,11 +1142,13 @@ interface AppManifest<Env, C, Ops extends Record<string, OperationShape>> {
|
|
|
957
1142
|
*/
|
|
958
1143
|
telemetry?: TelemetryConfig<Env>;
|
|
959
1144
|
/**
|
|
960
|
-
* A Workers rate limiting binding each HTTP and MCP call must pass, per organization and actor;
|
|
961
|
-
*
|
|
1145
|
+
* A Workers rate limiting binding each HTTP and MCP call must pass, per organization and actor; each
|
|
1146
|
+
* message of an MCP batch counts as a call. A refusal answers `RATE_LIMITED`.
|
|
962
1147
|
*/
|
|
963
1148
|
rateLimit?: {
|
|
1149
|
+
/** The name of the rate limiting binding in the env. */
|
|
964
1150
|
binding: keyof Env;
|
|
1151
|
+
/** The `Retry-After` seconds a refusal sends; 60 by default. */
|
|
965
1152
|
retryAfter?: number;
|
|
966
1153
|
};
|
|
967
1154
|
/**
|
|
@@ -985,15 +1172,13 @@ type ApplicationConfiguration<E> = Omit<AppManifest<E, Invocation<E>, Record<nev
|
|
|
985
1172
|
type DistinctOperations<Ops, M> = [Extract<keyof M, keyof Ops>] extends [never] ? unknown : {
|
|
986
1173
|
readonly 'Operations declared twice': Extract<keyof M, keyof Ops>;
|
|
987
1174
|
};
|
|
988
|
-
/** An operation's definition as `.operation()` takes it: its scope, exposure, words, schemas and limits. */
|
|
989
|
-
type OperationFields<I extends TSchema, O extends TSchema> = Omit<OperationShape, keyof Exposure | 'input' | 'output' | 'execute' | 'pipeline'> & {
|
|
990
|
-
input: I;
|
|
991
|
-
output: O;
|
|
992
|
-
};
|
|
993
|
-
type Definition<I extends TSchema, O extends TSchema, X extends Exposure> = X & OperationFields<I, O>;
|
|
994
1175
|
/** Refuses a definition field no operation has, such as a misspelled one, which would otherwise do nothing. */
|
|
995
1176
|
type KnownOperationFields<X> = Readonly<Record<Exclude<keyof X, keyof OperationShape>, never>>;
|
|
996
|
-
/**
|
|
1177
|
+
/**
|
|
1178
|
+
* An application under construction, as `maximus()` starts it. Every method returns a new builder and leaves
|
|
1179
|
+
* this one unchanged, so resource modules built from one base share its inferred context without overwriting
|
|
1180
|
+
* each other's operations.
|
|
1181
|
+
*/
|
|
997
1182
|
declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape>> {
|
|
998
1183
|
/**
|
|
999
1184
|
* The application declared so far: its configuration, context preparation, middleware and operations, which
|
|
@@ -1001,24 +1186,23 @@ declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape
|
|
|
1001
1186
|
*/
|
|
1002
1187
|
readonly definition: AppManifest<E, C, Ops>;
|
|
1003
1188
|
private readonly root;
|
|
1189
|
+
/**
|
|
1190
|
+
* Wraps `definition`. `root` identifies the application the builder descends from, and `.mount()` admits
|
|
1191
|
+
* only modules of the same one. Start an application with `maximus()` instead.
|
|
1192
|
+
*/
|
|
1004
1193
|
constructor(definition: AppManifest<E, C, Ops>, root?: object);
|
|
1005
1194
|
/**
|
|
1006
1195
|
* Declares an operation: a camelCase name no other operation uses, its definition (scope, words, effect,
|
|
1007
1196
|
* schemas and exposure) and its handler, which receives the prepared context and the decoded input and
|
|
1008
|
-
* returns a Result.
|
|
1197
|
+
* returns a Result. A name declared twice throws a TypeError, `Duplicate operation: <name>`.
|
|
1009
1198
|
*/
|
|
1010
|
-
operation<const N extends string, I extends TSchema, O extends TSchema, const X extends Exposure>(name: N extends keyof Ops ? never : N, definition:
|
|
1011
|
-
http: {
|
|
1012
|
-
body: 'bytes';
|
|
1013
|
-
};
|
|
1014
|
-
} ? {
|
|
1015
|
-
body: BinaryBody;
|
|
1016
|
-
} : object), input: StaticDecode$1<I>) => Promise<Result<Static<O>, Failure>>): ApplicationBuilder<E, C, Ops & Record<N, Definition<I, O, X> & {
|
|
1199
|
+
operation<const N extends string, I extends TSchema, O extends TSchema, const X extends Exposure>(name: N extends keyof Ops ? never : N, definition: OperationDefinition<I, O, X> & KnownOperationFields<X>, execute: OperationHandler<C, I, O, X>): ApplicationBuilder<E, C, Ops & Record<N, OperationDefinition<I, O, X> & {
|
|
1017
1200
|
execute: typeof execute;
|
|
1018
1201
|
}>>;
|
|
1019
1202
|
/**
|
|
1020
1203
|
* Adds what `resolve` returns to the context of every operation declared after it. It runs after admission
|
|
1021
|
-
* and before the middleware; a failure it returns answers the call. Derive before declaring operations
|
|
1204
|
+
* and before the middleware; a failure it returns answers the call. Derive before declaring operations: on
|
|
1205
|
+
* a builder that already has one, it throws a TypeError.
|
|
1022
1206
|
*/
|
|
1023
1207
|
derive<D extends object>(resolve: (context: C) => Promise<Result<D, Failure>>): ApplicationBuilder<E, C & D, Ops>;
|
|
1024
1208
|
/**
|
|
@@ -1028,21 +1212,434 @@ declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape
|
|
|
1028
1212
|
use(middleware: OperationMiddleware<C>): ApplicationBuilder<E, C, Ops>;
|
|
1029
1213
|
/**
|
|
1030
1214
|
* Adds the operations of a resource module built from the same application; each keeps the context and
|
|
1031
|
-
* middleware it was declared with.
|
|
1215
|
+
* middleware it was declared with. A module of another application, or one that declares an operation this
|
|
1216
|
+
* builder has, throws a TypeError.
|
|
1032
1217
|
*/
|
|
1033
1218
|
mount<MC, M extends Record<string, OperationShape>>(module: ApplicationBuilder<E, MC, M> & DistinctOperations<Ops, M>): ApplicationBuilder<E, C, Ops & M>;
|
|
1034
1219
|
/**
|
|
1035
|
-
* Checks every rule the application must keep and returns it. A refusal is a TypeError
|
|
1036
|
-
*
|
|
1220
|
+
* Checks every rule the application must keep and returns it. A refusal is a TypeError whose message names
|
|
1221
|
+
* the rule; most of the rules about one operation also name that operation.
|
|
1037
1222
|
*/
|
|
1038
1223
|
build(): AppManifest<E, C, Ops>;
|
|
1039
1224
|
}
|
|
1040
1225
|
/**
|
|
1041
|
-
* Starts an application: its name, scope namespace, origin, token policy, error catalog and
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1226
|
+
* Starts an application: its name, scope namespace, title, version, origin, token policy, error catalog and
|
|
1227
|
+
* RPC callers, and its optional limits, rate limit, telemetry and MCP configuration. Chain `.derive()` and
|
|
1228
|
+
* `.use()` to prepare each call, `.operation()` to declare operations, `.mount()` to compose resource modules
|
|
1229
|
+
* that share this base, then `.build()`.
|
|
1044
1230
|
*/
|
|
1045
1231
|
declare function maximus<E>(configuration: ApplicationConfiguration<E>): ApplicationBuilder<E, Invocation<E>, Record<never, never>>;
|
|
1232
|
+
/**
|
|
1233
|
+
* `@arbol-ai/maximus/failures`: the framework's own failures as plain data: code, HTTP status,
|
|
1234
|
+
* message, retryability and Retry-After. No runtime and no schema library, for a dispatcher that presents
|
|
1235
|
+
* them, such as an API gateway. `defineErrors` builds their schemas from this same table.
|
|
1236
|
+
*/
|
|
1237
|
+
/** One of the framework's own failures. */
|
|
1238
|
+
interface StandardFailure {
|
|
1239
|
+
/** The stable code clients branch on, such as `RATE_LIMITED`. */
|
|
1240
|
+
readonly code: string;
|
|
1241
|
+
/** The HTTP status that answers it. */
|
|
1242
|
+
readonly status: number;
|
|
1243
|
+
/** A fixed message for people; it never carries request data. */
|
|
1244
|
+
readonly message: string;
|
|
1245
|
+
/** Whether the same request may succeed later; false when absent. */
|
|
1246
|
+
readonly retryable?: boolean;
|
|
1247
|
+
/** The seconds a client waits before retrying, sent as `Retry-After`. */
|
|
1248
|
+
readonly retryAfter?: number;
|
|
1249
|
+
}
|
|
1250
|
+
/** The framework's own failures, by the name `standardErrors` gives each. */
|
|
1251
|
+
declare const STANDARD_FAILURES: {
|
|
1252
|
+
readonly invalidInput: {
|
|
1253
|
+
readonly code: 'INVALID_INPUT';
|
|
1254
|
+
readonly status: 400;
|
|
1255
|
+
readonly message: 'The request does not match the published schema.';
|
|
1256
|
+
};
|
|
1257
|
+
readonly unauthorized: {
|
|
1258
|
+
readonly code: 'UNAUTHORIZED';
|
|
1259
|
+
readonly status: 401;
|
|
1260
|
+
readonly message: 'A valid access token is required.';
|
|
1261
|
+
};
|
|
1262
|
+
readonly forbidden: {
|
|
1263
|
+
readonly code: 'FORBIDDEN';
|
|
1264
|
+
readonly status: 403;
|
|
1265
|
+
readonly message: 'The token does not authorize this operation.';
|
|
1266
|
+
};
|
|
1267
|
+
readonly notFound: {
|
|
1268
|
+
readonly code: 'NOT_FOUND';
|
|
1269
|
+
readonly status: 404;
|
|
1270
|
+
readonly message: 'The requested operation does not exist.';
|
|
1271
|
+
};
|
|
1272
|
+
readonly methodNotAllowed: {
|
|
1273
|
+
readonly code: 'HTTP_METHOD_NOT_ALLOWED';
|
|
1274
|
+
readonly status: 405;
|
|
1275
|
+
readonly message: 'The HTTP method is not supported for this resource.';
|
|
1276
|
+
};
|
|
1277
|
+
readonly tooLarge: {
|
|
1278
|
+
readonly code: 'REQUEST_TOO_LARGE';
|
|
1279
|
+
readonly status: 413;
|
|
1280
|
+
readonly message: 'The request exceeds the allowed size.';
|
|
1281
|
+
};
|
|
1282
|
+
readonly unsupportedMedia: {
|
|
1283
|
+
readonly code: 'UNSUPPORTED_MEDIA_TYPE';
|
|
1284
|
+
readonly status: 415;
|
|
1285
|
+
readonly message: 'The request content type is not supported.';
|
|
1286
|
+
};
|
|
1287
|
+
readonly rateLimited: {
|
|
1288
|
+
readonly code: 'RATE_LIMITED';
|
|
1289
|
+
readonly status: 429;
|
|
1290
|
+
readonly message: 'The request rate limit was exceeded. Try again later.';
|
|
1291
|
+
readonly retryable: true;
|
|
1292
|
+
readonly retryAfter: 60;
|
|
1293
|
+
};
|
|
1294
|
+
readonly internal: {
|
|
1295
|
+
readonly code: 'INTERNAL_ERROR';
|
|
1296
|
+
readonly status: 500;
|
|
1297
|
+
readonly message: 'The service could not complete the operation.';
|
|
1298
|
+
};
|
|
1299
|
+
readonly upstreamUnavailable: {
|
|
1300
|
+
readonly code: 'UPSTREAM_UNAVAILABLE';
|
|
1301
|
+
readonly status: 503;
|
|
1302
|
+
readonly message: 'The upstream service could not complete the request.';
|
|
1303
|
+
readonly retryable: true;
|
|
1304
|
+
};
|
|
1305
|
+
readonly upstreamTimeout: {
|
|
1306
|
+
readonly code: 'UPSTREAM_TIMEOUT';
|
|
1307
|
+
readonly status: 504;
|
|
1308
|
+
readonly message: 'The upstream service did not respond before its deadline.';
|
|
1309
|
+
readonly retryable: true;
|
|
1310
|
+
};
|
|
1311
|
+
/**
|
|
1312
|
+
* A write may have been applied and its answer was lost. Never retried: the caller reconciles (reads
|
|
1313
|
+
* the resource or polls the operation) before deciding to repeat anything.
|
|
1314
|
+
*/
|
|
1315
|
+
readonly outcomeUnknown: {
|
|
1316
|
+
readonly code: 'OUTCOME_UNKNOWN';
|
|
1317
|
+
readonly status: 502;
|
|
1318
|
+
readonly message: 'The operation may have been applied; check its result before repeating it.';
|
|
1319
|
+
};
|
|
1320
|
+
};
|
|
1321
|
+
declare global {
|
|
1322
|
+
/**
|
|
1323
|
+
* What a project registers about its application, so every handler is typed without importing it:
|
|
1324
|
+
* `base`, the builder its routes bind to, `errors`, its error catalog, and `env`, its Worker's bindings.
|
|
1325
|
+
* `maximus prepare` writes the registration in `.maximus/register.d.ts`; without one, handlers receive
|
|
1326
|
+
* the bare invocation and fail with standard failures. Global, so it merges however the package's
|
|
1327
|
+
* declarations are bundled.
|
|
1328
|
+
*/
|
|
1329
|
+
interface MaximusRegister {}
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* A registered member, or its fallback when the project registers none. Only that member is read: the base
|
|
1333
|
+
* depends on `context.ts`, whose types read the registered bindings.
|
|
1334
|
+
*/
|
|
1335
|
+
type Registered<K extends string, Fallback> = K extends keyof MaximusRegister ? MaximusRegister[K] : Fallback;
|
|
1336
|
+
/** The registered Worker's bindings. */
|
|
1337
|
+
type RegisteredEnv = Registered<'env', unknown>;
|
|
1338
|
+
/** The context every handler receives: what the registered base prepares. */
|
|
1339
|
+
type RegisteredContext = Registered<'base', never> extends ApplicationBuilder<infer _E, infer C, infer _O> ? C : Invocation<unknown>;
|
|
1340
|
+
/** The definitions of the registered error catalog. */
|
|
1341
|
+
type CatalogDefinitions = Registered<'errors', typeof standardErrors> extends {
|
|
1342
|
+
definitions: infer D;
|
|
1343
|
+
} ? D : never;
|
|
1344
|
+
/** Every code of the registered catalog: literal codes, or `string` for a catalog typed as `ErrorCatalog`. */
|
|
1345
|
+
type CatalogCode = { [K in keyof CatalogDefinitions]: CatalogDefinitions[K] extends {
|
|
1346
|
+
code: infer C extends string;
|
|
1347
|
+
} ? C : never; }[keyof CatalogDefinitions];
|
|
1348
|
+
/** The code of every standard failure, which any operation may answer without declaring it. */
|
|
1349
|
+
type StandardCode = (typeof STANDARD_FAILURES)[keyof typeof STANDARD_FAILURES]['code'];
|
|
1350
|
+
/** The standard codes only routing and admission answer, before an operation runs: never a handler's. */
|
|
1351
|
+
type AdmissionCode = 'NOT_FOUND' | 'HTTP_METHOD_NOT_ALLOWED' | 'UNAUTHORIZED';
|
|
1352
|
+
/** The standard codes of reading a body, which a byte body's `read()` answers and a handler only returns. */
|
|
1353
|
+
type BodyCode = 'REQUEST_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE';
|
|
1354
|
+
/** The standard codes a handler, a context or middleware may fail with itself. */
|
|
1355
|
+
type OperationStandardCode = Exclude<StandardCode, AdmissionCode | BodyCode>;
|
|
1356
|
+
/** The codes a declaration may list in `failures`: the catalog's own. */
|
|
1357
|
+
type DomainCode = Exclude<CatalogCode, StandardCode>;
|
|
1358
|
+
/** The definition of the registered catalog that has this code. */
|
|
1359
|
+
type DefinitionWithCode<Code> = Extract<{ [K in keyof CatalogDefinitions]: CatalogDefinitions[K] extends {
|
|
1360
|
+
code: Code;
|
|
1361
|
+
} ? CatalogDefinitions[K] : never; }[keyof CatalogDefinitions], ErrorDefinition>;
|
|
1362
|
+
/** What `fail` takes after the code: the data the code declares, or any data when codes are untyped. */
|
|
1363
|
+
type FailureArguments<Code extends string> = string extends CatalogCode ? [data?: Readonly<Record<string, unknown>>] : CreateArguments<DefinitionWithCode<Code>>;
|
|
1364
|
+
/**
|
|
1365
|
+
* The codes a handler may fail with: the domain failures it declares, or every one, and the standard ones
|
|
1366
|
+
* an operation answers itself.
|
|
1367
|
+
*/
|
|
1368
|
+
type AllowedCode<X> = (X extends {
|
|
1369
|
+
failures: readonly (infer C extends string)[];
|
|
1370
|
+
} ? C : DomainCode) | OperationStandardCode;
|
|
1371
|
+
/**
|
|
1372
|
+
* A failure a handler answers with, `return fail('TASK_NOT_FOUND')`: an expected outcome, never thrown.
|
|
1373
|
+
* `fail` creates one, and so does a byte body's `read()` that cannot read the body.
|
|
1374
|
+
*/
|
|
1375
|
+
declare class Failed<Code extends string = string> {
|
|
1376
|
+
/** Keeps the class nominal: an object of the same shape is not a failure. */
|
|
1377
|
+
private readonly nominal;
|
|
1378
|
+
/** The catalog failure the call answers. */
|
|
1379
|
+
readonly failure: Failure & {
|
|
1380
|
+
code: Code;
|
|
1381
|
+
};
|
|
1382
|
+
constructor(failure: Failure & {
|
|
1383
|
+
code: Code;
|
|
1384
|
+
});
|
|
1385
|
+
/** Whether a handler's answer is a failure rather than its output. */
|
|
1386
|
+
static is(value: unknown): value is Failed;
|
|
1387
|
+
}
|
|
1388
|
+
/** Answers a failure of the catalog by its code, with the data the code declares. */
|
|
1389
|
+
type Fail<Codes extends string> = <const Code extends Codes>(code: Code, ...data: FailureArguments<Code>) => Failed<Code>;
|
|
1390
|
+
/** A schema, or the fields of a strict object schema. */
|
|
1391
|
+
type SchemaOrFields = TSchema | TProperties;
|
|
1392
|
+
/** The schema `input` or `output` stands for: itself, or the strict object of its fields. */
|
|
1393
|
+
type SchemaOf<S> = S extends TSchema ? S : S extends TProperties ? TObject<S> : never;
|
|
1394
|
+
/** A field a declaration names, or none when it leaves the field out (its type parameter stays `never`). */
|
|
1395
|
+
type Field<K extends string, T> = [T] extends [never] ? unknown : Record<K, T>;
|
|
1396
|
+
/**
|
|
1397
|
+
* The fields of a declaration its types depend on, as it names them: its failures, HTTP options, MCP tool,
|
|
1398
|
+
* RPC exposure, effect, visibility and operation id.
|
|
1399
|
+
*/
|
|
1400
|
+
type DeclaredFields<F, H, M, R, E, V, N> = Field<'failures', F> & Field<'http', H> & Field<'mcp', M> & Field<'rpc', R> & Field<'effect', E> & Field<'visibility', V> & Field<'operationId', N>;
|
|
1401
|
+
/**
|
|
1402
|
+
* A route's byte body, read on demand once the route has admitted its target: its bytes, or the failure the
|
|
1403
|
+
* route answers as it is, `if (!bytes.ok) return bytes.error`.
|
|
1404
|
+
*/
|
|
1405
|
+
interface RouteBody {
|
|
1406
|
+
/**
|
|
1407
|
+
* Reads the body, once, within the route's `maxBodyBytes`: `REQUEST_TOO_LARGE` beyond it,
|
|
1408
|
+
* `UNSUPPORTED_MEDIA_TYPE` for a compressed body and `INVALID_INPUT` for one that broke off.
|
|
1409
|
+
*/
|
|
1410
|
+
read: () => Promise<Result<Uint8Array<ArrayBuffer>, Failed<BodyFailure['code']>>>;
|
|
1411
|
+
}
|
|
1412
|
+
/** What a handler receives: the prepared context, its decoded input, `fail` and, for a byte body, its reader. */
|
|
1413
|
+
type HandlerArguments<C, I extends TSchema, X> = Omit<C, 'input' | 'body'> & {
|
|
1414
|
+
/** The input, decoded against its schema. */
|
|
1415
|
+
readonly input: StaticDecode$1<I>;
|
|
1416
|
+
/** Answers a failure of the catalog: `return fail('TASK_NOT_FOUND')`. */
|
|
1417
|
+
readonly fail: Fail<AllowedCode<X>>;
|
|
1418
|
+
} & (X extends {
|
|
1419
|
+
http: {
|
|
1420
|
+
body: 'bytes';
|
|
1421
|
+
};
|
|
1422
|
+
} ? {
|
|
1423
|
+
readonly body: RouteBody;
|
|
1424
|
+
} : unknown);
|
|
1425
|
+
/** What a handler answers: its output, or a failure from `fail`, at once or as a promise. */
|
|
1426
|
+
type HandlerAnswer<O extends TSchema, X> = Answer<Static<O>, X>;
|
|
1427
|
+
/** A value, or a failure from `fail`, at once or as a promise. */
|
|
1428
|
+
type Answer<V, X> = V | Failed<AllowedCode<X> | BodyCode> | Promise<V | Failed<AllowedCode<X> | BodyCode>>;
|
|
1429
|
+
/** The empty strict object a route answers when it declares no output. */
|
|
1430
|
+
type NoOutput = TObject<Record<never, never>>;
|
|
1431
|
+
/** The output schema a declaration stands for: the one it declares, or the empty object. */
|
|
1432
|
+
type OutputSchema<O> = [O] extends [never] ? NoOutput : SchemaOf<O>;
|
|
1433
|
+
/**
|
|
1434
|
+
* What a handler that declares no output returns: nothing, or the empty object. An async handler without a
|
|
1435
|
+
* return statement answers `Promise<void>`, which `undefined` would refuse.
|
|
1436
|
+
*/
|
|
1437
|
+
type Nothing = Record<string, never> | void;
|
|
1438
|
+
/** What a handler returns: its declared output or, when it declares none, nothing at all. */
|
|
1439
|
+
type OutputValue<O> = [O] extends [never] ? Nothing : Static<SchemaOf<O>>;
|
|
1440
|
+
/** The HTTP options a route may set: its path and method come from its filename. */
|
|
1441
|
+
type HandlerHttp = Omit<NonNullable<Exposure['http']>, 'method' | 'path'>;
|
|
1442
|
+
/** A route's MCP tool: its name and, when they differ from its method's, its hints. */
|
|
1443
|
+
interface HandlerMcp {
|
|
1444
|
+
/** The tool's unique name: a lowercase letter, then up to 63 letters, digits or underscores. */
|
|
1445
|
+
name: string;
|
|
1446
|
+
/** Whether repeating a call is safe; by default, as its HTTP method is (GET, PUT and DELETE are). */
|
|
1447
|
+
idempotent?: boolean;
|
|
1448
|
+
/** Whether the tool reaches outside the service; `true` unless declared. */
|
|
1449
|
+
openWorld?: boolean;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* A route's contract, what `defineHandler` takes after the handler: its schemas and the fields it declares,
|
|
1453
|
+
* each derived or empty when left out. A contract kept in a `const` keeps its types with
|
|
1454
|
+
* `satisfies HandlerOptions`; an annotation would widen them.
|
|
1455
|
+
*/
|
|
1456
|
+
interface HandlerOptions {
|
|
1457
|
+
/** The input schema, or its fields; none when the route takes no input. */
|
|
1458
|
+
input?: SchemaOrFields;
|
|
1459
|
+
/** The output schema, or its fields; none when the route answers the empty object. */
|
|
1460
|
+
output?: SchemaOrFields;
|
|
1461
|
+
/**
|
|
1462
|
+
* A short human name: the OpenAPI `summary` and the MCP tool's title. By default, the method and path in
|
|
1463
|
+
* words: `Get a note` for `GET /v1/notes/{noteId}`, `List notes` for `GET /v1/notes`.
|
|
1464
|
+
*/
|
|
1465
|
+
title?: string;
|
|
1466
|
+
/** What the route does, for people and agents. A route that is also an MCP tool requires it. */
|
|
1467
|
+
description?: string;
|
|
1468
|
+
/**
|
|
1469
|
+
* The OpenAPI tag that groups the route with its resource's other routes. By default, the first fixed
|
|
1470
|
+
* segment after the version, in words: `Notes` for `/v1/notes/{noteId}`.
|
|
1471
|
+
*/
|
|
1472
|
+
group?: string;
|
|
1473
|
+
/**
|
|
1474
|
+
* The OpenAPI `operationId` and the native RPC method. By default, the method and path as an action:
|
|
1475
|
+
* `listNotes` for `GET /v1/notes`, `getNote` for `GET /v1/notes/{noteId}`, `createNote` for
|
|
1476
|
+
* `POST /v1/notes` and `archiveNote` for `POST /v1/notes/{noteId}/archive`.
|
|
1477
|
+
*/
|
|
1478
|
+
operationId?: string;
|
|
1479
|
+
/**
|
|
1480
|
+
* The scope a caller needs: by default, `<namespace>:<resource>:read` for a read and
|
|
1481
|
+
* `<namespace>:<resource>:write` otherwise, the resource being the first fixed segment after the version,
|
|
1482
|
+
* in kebab-case.
|
|
1483
|
+
*/
|
|
1484
|
+
scope?: OperationShape['scope'];
|
|
1485
|
+
/** Whether several scopes are alternatives (`any`, the default) or all required. */
|
|
1486
|
+
scopeMatch?: OperationShape['scopeMatch'];
|
|
1487
|
+
/**
|
|
1488
|
+
* Scopes the handler checks against `authority.scopes` for particular resources or fields, besides the one
|
|
1489
|
+
* that admits the call. A call without `authority` is refused with `FORBIDDEN`.
|
|
1490
|
+
*/
|
|
1491
|
+
conditionalScopes?: OperationShape['conditionalScopes'];
|
|
1492
|
+
/** Whether it reads, writes or deletes: by default, GET reads, DELETE deletes and the rest write. */
|
|
1493
|
+
effect?: OperationShape['effect'];
|
|
1494
|
+
/** The domain failure codes it may answer, besides the standard ones; every one when omitted. */
|
|
1495
|
+
failures?: readonly DomainCode[];
|
|
1496
|
+
/**
|
|
1497
|
+
* The principal kinds it admits: every kind when omitted. Every operation declares them under the
|
|
1498
|
+
* `oauth+bearer` token scheme.
|
|
1499
|
+
*/
|
|
1500
|
+
actorKinds?: Exposure['actorKinds'];
|
|
1501
|
+
/** `internal` keeps it out of the public OpenAPI document and the discovery metadata. */
|
|
1502
|
+
visibility?: Exposure['visibility'];
|
|
1503
|
+
/**
|
|
1504
|
+
* The HTTP options besides the path and method: a byte body, header-sourced fields, an attachment, the
|
|
1505
|
+
* success status.
|
|
1506
|
+
*/
|
|
1507
|
+
http?: HandlerHttp;
|
|
1508
|
+
/** Also serve the route as an MCP tool with this name. */
|
|
1509
|
+
mcp?: HandlerMcp;
|
|
1510
|
+
/** Also serve it as a native RPC method, to every allowed caller or to the listed ones. */
|
|
1511
|
+
rpc?: Exposure['rpc'];
|
|
1512
|
+
/**
|
|
1513
|
+
* The largest request body it accepts, in bytes: its JSON body, or its byte body. By default, the
|
|
1514
|
+
* application's limit.
|
|
1515
|
+
*/
|
|
1516
|
+
maxBodyBytes?: number;
|
|
1517
|
+
/** The largest output it answers, in bytes. By default, the application's limit. */
|
|
1518
|
+
maxOutputBytes?: number;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* A route as `defineHandler` declares it, before binding gives it a path and a method. `X` holds the fields
|
|
1522
|
+
* its types depend on; `C` is the context its handler expects, the registered one, which the base it binds
|
|
1523
|
+
* to must prepare.
|
|
1524
|
+
*/
|
|
1525
|
+
interface HandlerDeclaration<I extends TSchema, O extends TSchema, X, C = RegisteredContext> {
|
|
1526
|
+
/** The fields the route declares besides its schemas. */
|
|
1527
|
+
readonly options: Omit<HandlerOptions, 'input' | 'output'>;
|
|
1528
|
+
/** The input schema; an empty strict object when the route declares none. */
|
|
1529
|
+
readonly input: I;
|
|
1530
|
+
/** The output schema. */
|
|
1531
|
+
readonly output: O;
|
|
1532
|
+
/** Answers one call. */
|
|
1533
|
+
readonly handler: (args: HandlerArguments<C, I, X>) => HandlerAnswer<O, X>;
|
|
1534
|
+
}
|
|
1535
|
+
/** The fields `defineHandler` types from its contract, as the contract names them. */
|
|
1536
|
+
type HandlerContract<I, O, F, H, M, R, E, V, N> = Omit<HandlerOptions, 'input' | 'output' | 'failures' | 'http' | 'mcp' | 'rpc' | 'effect' | 'visibility' | 'operationId'> & {
|
|
1537
|
+
input?: I;
|
|
1538
|
+
output?: O;
|
|
1539
|
+
failures?: F;
|
|
1540
|
+
http?: H;
|
|
1541
|
+
mcp?: M;
|
|
1542
|
+
rpc?: R;
|
|
1543
|
+
effect?: E;
|
|
1544
|
+
visibility?: V;
|
|
1545
|
+
operationId?: N;
|
|
1546
|
+
} & ([M] extends [never] ? unknown : {
|
|
1547
|
+
description: string;
|
|
1548
|
+
});
|
|
1549
|
+
/**
|
|
1550
|
+
* Declares a route as its file's default export: its handler, then its contract. The filename gives its path
|
|
1551
|
+
* and method: `routes/v1/tasks/[taskId].delete.ts` answers `DELETE /v1/tasks/{taskId}` below the API's base
|
|
1552
|
+
* path, `/api` by default. The handler receives one object, `{ input, principal, env, fail, …context }`, and
|
|
1553
|
+
* returns its output or `fail(code)`. The contract's `input` and `output` are schemas or the fields of strict
|
|
1554
|
+
* objects; without a contract, the route takes no input and answers the empty object.
|
|
1555
|
+
*/
|
|
1556
|
+
declare function defineHandler<O extends SchemaOrFields = never, I extends SchemaOrFields = TObject<Record<never, never>>, const F extends readonly DomainCode[] = never, const H extends HandlerHttp = never, const M extends HandlerMcp = never, const R extends NonNullable<Exposure['rpc']> = never, const E extends OperationShape['effect'] = never, const V extends NonNullable<Exposure['visibility']> = never, const N extends string = never>(
|
|
1557
|
+
/** Answers one call: its output, or `fail(code)`. */
|
|
1558
|
+
handler: (args: HandlerArguments<RegisteredContext, SchemaOf<I>, DeclaredFields<F, H, M, R, E, V, N>>) => Answer<OutputValue<O>, DeclaredFields<F, H, M, R, E, V, N>>, contract?: HandlerContract<I, O, F, H, M, R, E, V, N>): HandlerDeclaration<SchemaOf<I>, OutputSchema<O>, DeclaredFields<F, H, M, R, E, V, N>>;
|
|
1559
|
+
/**
|
|
1560
|
+
* A tool's contract, what `defineTool` takes after the handler: its schemas, description, effect and the
|
|
1561
|
+
* rest. Its scope defaults to `<namespace>:<file>:read` for a read and `<namespace>:<file>:write` otherwise,
|
|
1562
|
+
* the file being the tool's file name without its extension.
|
|
1563
|
+
*/
|
|
1564
|
+
interface ToolOptions extends Omit<HandlerOptions, 'description' | 'effect' | 'operationId' | 'http' | 'mcp' | 'visibility'> {
|
|
1565
|
+
/** What the tool does, for the agents that choose it. */
|
|
1566
|
+
description: string;
|
|
1567
|
+
/** Whether it reads, writes or deletes: its MCP hints and default scope follow it. */
|
|
1568
|
+
effect: OperationShape['effect'];
|
|
1569
|
+
/** Whether repeating a call is safe; by default, only a read is. */
|
|
1570
|
+
idempotent?: boolean;
|
|
1571
|
+
/** Whether the tool reaches outside the service; `true` unless declared. */
|
|
1572
|
+
openWorld?: boolean;
|
|
1573
|
+
}
|
|
1574
|
+
/** A tool as `defineTool` declares it, before binding names it after its file; `X` and `C` as for a route. */
|
|
1575
|
+
interface ToolDeclaration<I extends TSchema, O extends TSchema, X, C = RegisteredContext> {
|
|
1576
|
+
/** The fields the tool declares besides its schemas. */
|
|
1577
|
+
readonly options: Omit<ToolOptions, 'input' | 'output'>;
|
|
1578
|
+
/** The input schema; an empty strict object when the tool takes none. */
|
|
1579
|
+
readonly input: I;
|
|
1580
|
+
/** The output schema. */
|
|
1581
|
+
readonly output: O;
|
|
1582
|
+
/** Answers one call. */
|
|
1583
|
+
readonly handler: (args: HandlerArguments<C, I, X>) => HandlerAnswer<O, X>;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Declares a tool only MCP serves, as its file's default export: its handler, then its contract.
|
|
1587
|
+
* `mcp/tools/summarize-tasks.ts` is the tool `summarize_tasks`, the operation `summarizeTasks` and, by
|
|
1588
|
+
* default, the title `Summarize tasks`. The contract states its description and effect; its handler works as
|
|
1589
|
+
* a route's.
|
|
1590
|
+
*/
|
|
1591
|
+
declare function defineTool<const E extends OperationShape['effect'] = never, O extends SchemaOrFields = never, I extends SchemaOrFields = TObject<Record<never, never>>, const F extends readonly DomainCode[] = never, const R extends NonNullable<Exposure['rpc']> = never>(
|
|
1592
|
+
/** Answers one call: its output, or `fail(code)`. */
|
|
1593
|
+
handler: (args: HandlerArguments<RegisteredContext, SchemaOf<I>, DeclaredFields<F, never, never, R, E, never, never>>) => Answer<OutputValue<O>, DeclaredFields<F, never, never, R, E, never, never>>, contract: Omit<ToolOptions, 'input' | 'output' | 'effect' | 'failures' | 'rpc'> & {
|
|
1594
|
+
input?: I;
|
|
1595
|
+
output?: O;
|
|
1596
|
+
failures?: F;
|
|
1597
|
+
rpc?: R;
|
|
1598
|
+
} & ([E] extends [never] ? {
|
|
1599
|
+
effect: OperationShape['effect'];
|
|
1600
|
+
} : {
|
|
1601
|
+
effect: E;
|
|
1602
|
+
})): ToolDeclaration<SchemaOf<I>, OutputSchema<O>, DeclaredFields<F, never, never, R, E, never, never>>;
|
|
1603
|
+
/** What preparing a call's context receives: the verified invocation and `fail`. */
|
|
1604
|
+
type ContextArguments<E = RegisteredEnv> = Invocation<E> & {
|
|
1605
|
+
/** Answers the call with a failure of the catalog instead of preparing its context. */
|
|
1606
|
+
readonly fail: Fail<DomainCode | OperationStandardCode>;
|
|
1607
|
+
};
|
|
1608
|
+
/** The context every handler receives, as `defineContext` declares it; `E` is the registered bindings. */
|
|
1609
|
+
interface ContextDeclaration<D, E = RegisteredEnv> {
|
|
1610
|
+
/** Prepares one call's context from its invocation. */
|
|
1611
|
+
readonly prepare: (args: ContextArguments<E>) => D | Failed | Promise<D | Failed>;
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Declares, as `context.ts`'s default export, what every handler receives besides the invocation: it runs
|
|
1615
|
+
* once per call after admission and returns the values handlers destructure, such as a store scoped to
|
|
1616
|
+
* `principal.organizationId`, or `fail(code)` to answer the call instead. A route that lists its `failures`
|
|
1617
|
+
* answers a domain code of the context only when it lists that code too.
|
|
1618
|
+
*/
|
|
1619
|
+
declare function defineContext<D extends object>(prepare: (args: ContextArguments) => D | Failed | Promise<D | Failed>): ContextDeclaration<D>;
|
|
1620
|
+
/**
|
|
1621
|
+
* The context a `context.ts` declaration prepares: the invocation and its values. Operation middleware is
|
|
1622
|
+
* typed with it, `defineOperationMiddleware<PreparedContext<typeof context>>`, importing the type alone.
|
|
1623
|
+
*/
|
|
1624
|
+
type PreparedContext<T> = T extends ContextDeclaration<infer D, infer E> ? Invocation<E> & Exclude<D, Failed> : never;
|
|
1625
|
+
/** The token fields an application states in code, as `auth.ts` declares them; the rest are configuration. */
|
|
1626
|
+
type AuthOptions<E = RegisteredEnv> = Pick<TokenPolicy<E>, 'resolve' | 'resourceMetadataUrl' | 'resources'>;
|
|
1627
|
+
/**
|
|
1628
|
+
* Declares, as `auth.ts`'s default export, how the application verifies tokens itself: `resolve`, which
|
|
1629
|
+
* replaces the default OAuth verification for every token but the development token (for credentials the
|
|
1630
|
+
* configured issuer does not issue, such as an application session or a workload key), and its OAuth
|
|
1631
|
+
* resources and their metadata URL. Verify every token cryptographically and parse its principal strictly.
|
|
1632
|
+
* The issuer, audience, scheme and every other field stay in configuration: any of them here throws a
|
|
1633
|
+
* TypeError rather than overriding it.
|
|
1634
|
+
*/
|
|
1635
|
+
declare function defineAuth<const A extends AuthOptions>(auth: A & Record<Exclude<keyof A, keyof AuthOptions>, never>): A;
|
|
1636
|
+
/**
|
|
1637
|
+
* Declares, as `telemetry.ts`'s default export, what the application's diagnostics do: whether Maximus writes
|
|
1638
|
+
* its log events, calls observers and annotates spans (`enabled`, on by default), the observers that receive
|
|
1639
|
+
* each call's safe metadata, such as `analytics()` from `@arbol-ai/maximus/analytics`, and how to read the
|
|
1640
|
+
* active trace id (`traceId`). Any other field throws a TypeError.
|
|
1641
|
+
*/
|
|
1642
|
+
declare function defineTelemetry(telemetry: TelemetryConfig<RegisteredEnv>): TelemetryConfig<RegisteredEnv>;
|
|
1046
1643
|
/**
|
|
1047
1644
|
* Checks a value against a schema without decoding it: the value when it matches, else an `INVALID_INPUT`
|
|
1048
1645
|
* failure without issues. Use `decodeInput` for input with defaults and codecs.
|
|
@@ -1065,8 +1662,12 @@ declare function parseInput<Schema extends TSchema>(schema: Schema, input: unkno
|
|
|
1065
1662
|
};
|
|
1066
1663
|
/** Checks a value against a schema and returns it typed, or throws a TypeError that names no value. */
|
|
1067
1664
|
declare function parseSchema<Schema extends TSchema>(schema: Schema, input: unknown): Static<Schema>;
|
|
1068
|
-
/**
|
|
1069
|
-
*
|
|
1665
|
+
/**
|
|
1666
|
+
* Decodes input against its schema: admits only a bounded plain JSON tree, applies the declared defaults to a
|
|
1667
|
+
* copy, checks it and runs its codecs. Throws a `SchemaValidationError` (or TypeBox's assertion error) when the
|
|
1668
|
+
* input is refused, and whatever an owner codec throws otherwise. Output is checked, never decoded: what a
|
|
1669
|
+
* handler returns must already be canonical.
|
|
1670
|
+
*/
|
|
1070
1671
|
declare function decodeSchema<Schema extends TSchema>(schema: Schema, input: unknown): StaticDecode$1<Schema>;
|
|
1071
1672
|
/** Field issues a refusal carries: enough to correct the input, never an input value. */
|
|
1072
1673
|
interface InputIssue {
|
|
@@ -1076,14 +1677,11 @@ interface InputIssue {
|
|
|
1076
1677
|
message: string;
|
|
1077
1678
|
}
|
|
1078
1679
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
* field issues
|
|
1680
|
+
* Decodes input as `decodeSchema` does and answers a refusal as the `INVALID_INPUT` failure, with its first
|
|
1681
|
+
* field issues: where the input failed and what was expected, never a value. A fault of an owner codec, an
|
|
1682
|
+
* error that refuses nothing, is thrown for the caller to report: it is the server's failure, not the input's.
|
|
1081
1683
|
*/
|
|
1082
1684
|
declare function decodeInput<Schema extends TSchema>(schema: Schema, input: unknown): {
|
|
1083
|
-
error?: undefined;
|
|
1084
|
-
ok: true;
|
|
1085
|
-
value: StaticDecode$1<Schema>;
|
|
1086
|
-
} | {
|
|
1087
1685
|
value?: undefined;
|
|
1088
1686
|
ok: false;
|
|
1089
1687
|
error: {
|
|
@@ -1094,6 +1692,10 @@ declare function decodeInput<Schema extends TSchema>(schema: Schema, input: unkn
|
|
|
1094
1692
|
issues: InputIssue[];
|
|
1095
1693
|
};
|
|
1096
1694
|
};
|
|
1695
|
+
} | {
|
|
1696
|
+
error?: undefined;
|
|
1697
|
+
ok: true;
|
|
1698
|
+
value: StaticDecode$1<Schema>;
|
|
1097
1699
|
};
|
|
1098
1700
|
/** Type-only: the key under which a codec's schema type carries its wire type. No schema object has it. */
|
|
1099
1701
|
declare const WIRE: unique symbol;
|
|
@@ -1155,7 +1757,12 @@ declare const strictObject: <S extends TSchema>(schema: S) => S;
|
|
|
1155
1757
|
declare const looseObject: <S extends TSchema>(schema: S) => S;
|
|
1156
1758
|
/** The object with more properties, keeping how it treats unknown keys. */
|
|
1157
1759
|
declare const extendObject: <P extends TProperties, Q extends TProperties>(schema: TObject<P>, properties: Q) => TObject<P & Q>;
|
|
1158
|
-
/**
|
|
1760
|
+
/**
|
|
1761
|
+
* Reads a field through `normalize`. For a string, or a string that may be null, the pattern, format and
|
|
1762
|
+
* lengths apply to the normalized value, so the wire may send a raw spelling (another case, surrounding
|
|
1763
|
+
* spaces); any other schema checks the raw value first. The wire type stays the schema's own. Runs inside
|
|
1764
|
+
* `inputSchema()`.
|
|
1765
|
+
*/
|
|
1159
1766
|
declare const normalizeSchema: <S extends TSchema, O>(schema: S, normalize: (value: Static<S>) => O) => TUnsafe<O> & WireType<SchemaInput<S>> & (S extends TOptional<TSchema> ? {
|
|
1160
1767
|
[OptionalKind]: 'Optional';
|
|
1161
1768
|
} : Record<never, never>) & (S extends {
|
|
@@ -1163,7 +1770,10 @@ declare const normalizeSchema: <S extends TSchema, O>(schema: S, normalize: (val
|
|
|
1163
1770
|
} ? {
|
|
1164
1771
|
default: D;
|
|
1165
1772
|
} : Record<never, never>);
|
|
1166
|
-
/**
|
|
1773
|
+
/**
|
|
1774
|
+
* Decodes a field with `transform` once its value passes `schema`: the wire sends what `schema` checks, and
|
|
1775
|
+
* the handler receives what `transform` returns. Runs inside `inputSchema()`.
|
|
1776
|
+
*/
|
|
1167
1777
|
declare const transformSchema: <S extends TSchema, O>(schema: S, transform: (value: Static<S>) => O) => TUnsafe<O> & WireType<SchemaInput<S>> & (S extends TOptional<TSchema> ? {
|
|
1168
1778
|
[OptionalKind]: 'Optional';
|
|
1169
1779
|
} : Record<never, never>) & (S extends {
|
|
@@ -1184,15 +1794,18 @@ declare const inspectSchema: <S extends TSchema>(schema: S, inspect: (value: Sta
|
|
|
1184
1794
|
addIssue: (issue: SchemaIssue) => void;
|
|
1185
1795
|
}) => void) => S;
|
|
1186
1796
|
/**
|
|
1187
|
-
* Refuses a value the schema admits when `predicate` rejects it, with `
|
|
1188
|
-
*
|
|
1797
|
+
* Refuses a value the schema admits when `predicate` rejects it, with a `custom` issue whose message and path
|
|
1798
|
+
* `detail` gives (`Invalid value` at the field by default). Runs inside `inputSchema()`.
|
|
1189
1799
|
*/
|
|
1190
1800
|
declare const refineSchema: <S extends TSchema>(schema: S, predicate: (value: Static<S>) => unknown, detail?: string | {
|
|
1191
1801
|
message?: string;
|
|
1192
1802
|
error?: string;
|
|
1193
1803
|
path?: (string | number)[];
|
|
1194
1804
|
}) => S;
|
|
1195
|
-
/**
|
|
1805
|
+
/**
|
|
1806
|
+
* A URL, of at most `maxLength` characters when given, whose protocol (without its colon, such as `https`)
|
|
1807
|
+
* and, optionally, hostname match the given patterns. Runs inside `inputSchema()`.
|
|
1808
|
+
*/
|
|
1196
1809
|
declare const urlSchema: (options: {
|
|
1197
1810
|
protocol: RegExp;
|
|
1198
1811
|
hostname?: RegExp;
|
|
@@ -1225,7 +1838,8 @@ type Checked<S extends TSchema> = {
|
|
|
1225
1838
|
/**
|
|
1226
1839
|
* Reads untrusted data — a stored record, a provider or model answer — through its schema's owner
|
|
1227
1840
|
* semantics: defaults applied, normalizers run before their checks, unknown keys of a strip object
|
|
1228
|
-
* dropped. A refusal carries every issue with its path; nothing is coerced.
|
|
1841
|
+
* dropped. A refusal carries every issue with its path; nothing is coerced. An owner codec that fails
|
|
1842
|
+
* throws what it threw.
|
|
1229
1843
|
*/
|
|
1230
1844
|
declare function checkSchema<S extends TSchema>(schema: S, input: unknown): Checked<S>;
|
|
1231
1845
|
/** `checkSchema`, throwing its SchemaValidationError on refusal. */
|
|
@@ -1242,8 +1856,10 @@ declare const PageInfoSchema: TObject<{
|
|
|
1242
1856
|
/** How to reach a list's neighboring pages. */
|
|
1243
1857
|
type PageInfo = Static<typeof PageInfoSchema>;
|
|
1244
1858
|
/**
|
|
1245
|
-
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25
|
|
1246
|
-
* A list whose items are costly lowers the maximum:
|
|
1859
|
+
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25, or the maximum when it is lower)
|
|
1860
|
+
* when the caller sends none. A list whose items are costly lowers the maximum:
|
|
1861
|
+
* `{ ...PageQueryFields, limit: pageLimit({ maximum: 20 }) }`. A default outside 1 to the maximum, or a
|
|
1862
|
+
* value that is not an integer, throws a TypeError.
|
|
1247
1863
|
*/
|
|
1248
1864
|
declare function pageLimit(options?: {
|
|
1249
1865
|
maximum?: number;
|
|
@@ -1251,7 +1867,10 @@ declare function pageLimit(options?: {
|
|
|
1251
1867
|
}): import("@sinclair/typebox").TInteger & {
|
|
1252
1868
|
default: number;
|
|
1253
1869
|
};
|
|
1254
|
-
/**
|
|
1870
|
+
/**
|
|
1871
|
+
* The query fields of a list, spread into its input beside its own filters: an optional opaque `cursor`, a
|
|
1872
|
+
* `direction` (`forward` by default, or `backward`) and a `limit` (`pageLimit()`).
|
|
1873
|
+
*/
|
|
1255
1874
|
declare const PageQueryFields: {
|
|
1256
1875
|
cursor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
1257
1876
|
direction: import("@sinclair/typebox").TUnion<[TLiteral<"forward">, TLiteral<"backward">]> & {
|
|
@@ -1279,9 +1898,9 @@ interface Page<Item> {
|
|
|
1279
1898
|
pageInfo: PageInfo;
|
|
1280
1899
|
}
|
|
1281
1900
|
/**
|
|
1282
|
-
* The output of a list of `item`, named by `$id` (`AppointmentPage`)
|
|
1283
|
-
*
|
|
1284
|
-
* one suffixed `_2`.
|
|
1901
|
+
* The output of a list of `item`, named by `$id` (`AppointmentPage`), a PascalCase name of up to 128
|
|
1902
|
+
* characters; any other throws a TypeError. Give each list its own name and use it for that list only: two
|
|
1903
|
+
* different shapes under one `$id` become two components, the second one suffixed `_2`.
|
|
1285
1904
|
*/
|
|
1286
1905
|
declare function Page<Item extends TSchema>(item: Item, options: {
|
|
1287
1906
|
$id: string;
|
|
@@ -1294,28 +1913,34 @@ declare const PhoneNumberSchema: TString;
|
|
|
1294
1913
|
declare const HttpsUrlSchema: TString;
|
|
1295
1914
|
/** A `#rrggbb` color, named `HexColor`. */
|
|
1296
1915
|
declare const HexColorSchema: TString;
|
|
1297
|
-
/** What
|
|
1916
|
+
/** What a delete answers: the deleted resource's id and `deleted: true`, named `DeletedObject`. */
|
|
1298
1917
|
declare const DeletedObjectSchema: import("@sinclair/typebox").TObject<{
|
|
1299
1918
|
id: TString;
|
|
1300
1919
|
deleted: import("@sinclair/typebox").TLiteral<true>;
|
|
1301
1920
|
}>;
|
|
1302
1921
|
/** What a `delete` answers: the id and `deleted: true`. */
|
|
1303
1922
|
type DeletedObject = Static<typeof DeletedObjectSchema>;
|
|
1304
|
-
/**
|
|
1923
|
+
/**
|
|
1924
|
+
* A link that grants access by itself until it expires, such as a file download: its HTTPS `url` and its
|
|
1925
|
+
* `expiresAt` date-time, named `SignedUrl`.
|
|
1926
|
+
*/
|
|
1305
1927
|
declare const SignedUrlSchema: import("@sinclair/typebox").TObject<{
|
|
1306
1928
|
url: TString;
|
|
1307
1929
|
expiresAt: TString;
|
|
1308
1930
|
}>;
|
|
1309
1931
|
/** A URL that grants access by itself, and when it expires. */
|
|
1310
1932
|
type SignedUrl = Static<typeof SignedUrlSchema>;
|
|
1311
|
-
/** Another resource, by its id and the name people know it by
|
|
1933
|
+
/** Another resource, by its id and the name people know it by, named `NamedReference`. */
|
|
1312
1934
|
declare const NamedReferenceSchema: import("@sinclair/typebox").TObject<{
|
|
1313
1935
|
id: TString;
|
|
1314
1936
|
name: TString;
|
|
1315
1937
|
}>;
|
|
1316
1938
|
/** Another resource, by id and name. */
|
|
1317
1939
|
type NamedReference = Static<typeof NamedReferenceSchema>;
|
|
1318
|
-
/**
|
|
1940
|
+
/**
|
|
1941
|
+
* A postal address, shaped as FHIR `Address` (its lines, city, state, postal code, ISO 3166-1 alpha-2 country
|
|
1942
|
+
* code and use), every field optional, named `PostalAddress`.
|
|
1943
|
+
*/
|
|
1319
1944
|
declare const PostalAddressSchema: import("@sinclair/typebox").TObject<{
|
|
1320
1945
|
city: import("@sinclair/typebox").TOptional<TString>;
|
|
1321
1946
|
countryCode: import("@sinclair/typebox").TOptional<TString>;
|
|
@@ -1336,6 +1961,17 @@ declare const EmptyInputSchema: import("@sinclair/typebox").TObject<{}>;
|
|
|
1336
1961
|
declare const OrganizationIdSchema: import("@sinclair/typebox").TString;
|
|
1337
1962
|
/** A lowercase RFC 9562 UUID of version 1 to 8, named `Uuid`. */
|
|
1338
1963
|
declare const UuidSchema: import("@sinclair/typebox").TString;
|
|
1964
|
+
/**
|
|
1965
|
+
* The principal a verified Access application token grants under `policy.access`. A person, whose token
|
|
1966
|
+
* names them in `sub` and carries no `common_name`, acts as `sub` (never as their email) through a `human`
|
|
1967
|
+
* client, the application's audience, and holds `access.people`. A service token, whose token has an empty
|
|
1968
|
+
* `sub` and its client id as `common_name`, acts as that client id through a `machine` client of the same
|
|
1969
|
+
* id, and holds what `access.services` lists under it, else nothing. Each acts in `access.organizationId`, or
|
|
1970
|
+
* in the organization the claim `claims.organization` holds. Anything else is refused as `UNAUTHORIZED`: a
|
|
1971
|
+
* token whose `type` is not `app` (an Access organization token, for one), a token that is neither a person's
|
|
1972
|
+
* nor a service token's, an organization missing or malformed or named by both, and a policy without `access`.
|
|
1973
|
+
*/
|
|
1974
|
+
declare function projectAccessToken(claims: unknown, policy: Pick<TokenPolicy, 'audience' | 'access' | 'claims'>): Result<TokenPrincipal, Failure>;
|
|
1339
1975
|
/**
|
|
1340
1976
|
* What a transport receives for one admitted request: the request and its id, the verified caller, the
|
|
1341
1977
|
* application, the operations it may serve, the OpenAPI document, and `invoke`, which runs an operation
|
|
@@ -1356,10 +1992,15 @@ interface TransportContext {
|
|
|
1356
1992
|
authenticated: TokenPrincipal;
|
|
1357
1993
|
/** The application the transport serves: its name, title, version, public origin and MCP configuration. */
|
|
1358
1994
|
application: {
|
|
1995
|
+
/** The service's identifier, which names the MCP server. */
|
|
1359
1996
|
name: string;
|
|
1997
|
+
/** The service's human name. */
|
|
1360
1998
|
title: string;
|
|
1999
|
+
/** The service's version. */
|
|
1361
2000
|
version: string;
|
|
2001
|
+
/** The service's public HTTPS base URL. */
|
|
1362
2002
|
origin: string;
|
|
2003
|
+
/** The MCP server's instructions, guides and skills, when the application configures them. */
|
|
1363
2004
|
mcp?: McpConfiguration;
|
|
1364
2005
|
};
|
|
1365
2006
|
/**
|
|
@@ -1374,18 +2015,25 @@ interface TransportContext {
|
|
|
1374
2015
|
/** The public URL of one of the application's own paths, such as `/openapi.json`, below its base path. */
|
|
1375
2016
|
url: (path: string) => string;
|
|
1376
2017
|
/**
|
|
1377
|
-
* Runs one of `operations` as the verified caller and answers its Result
|
|
1378
|
-
* `NOT_FOUND`, and
|
|
2018
|
+
* Runs one of `operations` through the shared execution path as the verified caller and answers its Result:
|
|
2019
|
+
* an operation not among them fails with `NOT_FOUND`, and one whose scopes the caller lacks with
|
|
2020
|
+
* `FORBIDDEN`.
|
|
1379
2021
|
*/
|
|
1380
2022
|
invoke: (name: string, operation: OperationShape, input: unknown) => Promise<Result<unknown, Failure>>;
|
|
1381
2023
|
/**
|
|
1382
|
-
*
|
|
1383
|
-
* caller's rate limit as a request of its own
|
|
1384
|
-
*
|
|
2024
|
+
* Admits the requests this HTTP request carries beyond its first, such as the rest of a JSON-RPC batch,
|
|
2025
|
+
* each against the caller's rate limit as a request of its own, before any of them runs. Answers the
|
|
2026
|
+
* refusal to send when the limit refuses one, as admission answers a request over the limit; admission
|
|
2027
|
+
* counted the first.
|
|
2028
|
+
*/
|
|
2029
|
+
admitCarried: (requests: number) => Promise<Response | undefined>;
|
|
2030
|
+
/**
|
|
2031
|
+
* Records a refusal the transport answers itself, such as a call to a tool the caller cannot see, as
|
|
2032
|
+
* admission records the refusals HTTP answers: its code, and the operation when it names one.
|
|
1385
2033
|
*/
|
|
1386
|
-
|
|
1387
|
-
/**
|
|
1388
|
-
|
|
2034
|
+
refused: (failure: Failure, operation?: string) => void;
|
|
2035
|
+
/** The request body the transport received, as text; admission read it within the transport's limit. */
|
|
2036
|
+
body: string;
|
|
1389
2037
|
/** The body limit HTTP applies to an operation; a transport holds each invocation to it. */
|
|
1390
2038
|
bodyLimit: (operation: OperationShape) => number;
|
|
1391
2039
|
}
|
|
@@ -1394,7 +2042,10 @@ interface TransportContext {
|
|
|
1394
2042
|
* admits and its handler.
|
|
1395
2043
|
*/
|
|
1396
2044
|
interface HttpTransport {
|
|
1397
|
-
/**
|
|
2045
|
+
/**
|
|
2046
|
+
* The protocol the transport speaks, whatever its path: `mcp` marks the MCP transport, of which a handler
|
|
2047
|
+
* mounts at most one. A transport at `/mcp` counts as the MCP transport either way.
|
|
2048
|
+
*/
|
|
1398
2049
|
protocol?: 'mcp';
|
|
1399
2050
|
/**
|
|
1400
2051
|
* The exact path the transport answers, such as `/mcp`; it stays absolute when the application has a base
|
|
@@ -1419,24 +2070,31 @@ interface HttpTransport {
|
|
|
1419
2070
|
interface RouteContext {
|
|
1420
2071
|
/** The request id echoed in `x-request-id`; use it to correlate diagnostics. */
|
|
1421
2072
|
requestId: string;
|
|
1422
|
-
/**
|
|
2073
|
+
/**
|
|
2074
|
+
* Answers a failure of the application's catalog as the failure envelope, with its status, this request's
|
|
2075
|
+
* id and the given headers: for a refusal the route makes itself. A failure outside the catalog throws a
|
|
2076
|
+
* TypeError, which the handler answers as `INTERNAL_ERROR`.
|
|
2077
|
+
*/
|
|
1423
2078
|
fail: (failure: Failure, headers?: ResponseInit['headers']) => Response;
|
|
1424
|
-
/**
|
|
2079
|
+
/**
|
|
2080
|
+
* Keeps work running after the response, through the runtime's `waitUntil` when the handler has one. Best
|
|
2081
|
+
* effort, never durable.
|
|
2082
|
+
*/
|
|
1425
2083
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
1426
2084
|
}
|
|
1427
2085
|
/**
|
|
1428
|
-
* A plain HTTP route outside token admission, for callers that cannot present a
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
2086
|
+
* A plain HTTP route outside token admission, for callers that cannot present a bearer token: provider
|
|
2087
|
+
* webhooks (signed bodies), signed links, OAuth callbacks. The handler owns authentication completely: it
|
|
2088
|
+
* must verify a signature or token before it treats the request as data. Plain routes share the handler's
|
|
2089
|
+
* diagnostics, request id and response headers (`x-request-id`, `x-content-type-options: nosniff`,
|
|
2090
|
+
* `server-timing`, and `cache-control: private, no-store` unless the route sets its own); they never receive
|
|
2091
|
+
* a principal and are absent from OpenAPI.
|
|
1434
2092
|
*/
|
|
1435
2093
|
type HttpRoute<E> = (request: Request, env: E, context: RouteContext) => Promise<Response>;
|
|
1436
2094
|
/**
|
|
1437
|
-
* Wraps
|
|
1438
|
-
*
|
|
1439
|
-
* `next`
|
|
2095
|
+
* Wraps every request before token admission, once the origin is admitted. It receives a copy of the request
|
|
2096
|
+
* without its body, so it can neither read the body nor change the headers admission reads, and it sees no
|
|
2097
|
+
* principal. `next` runs the rest of the handling, at most once and before the wrapper settles.
|
|
1440
2098
|
*/
|
|
1441
2099
|
type HttpMiddleware<E> = (request: Request, env: E, context: RouteContext, next: () => Promise<Response>) => Promise<Response>;
|
|
1442
2100
|
/**
|
|
@@ -1444,9 +2102,16 @@ type HttpMiddleware<E> = (request: Request, env: E, context: RouteContext, next:
|
|
|
1444
2102
|
* routes and mounts, a base path, a fallback and request hooks.
|
|
1445
2103
|
*/
|
|
1446
2104
|
interface HttpOptions<E = unknown> {
|
|
1447
|
-
/**
|
|
2105
|
+
/**
|
|
2106
|
+
* Request wrappers, run in order around everything after the origin check; an error one throws answers
|
|
2107
|
+
* `INTERNAL_ERROR`. Each entry must be a function.
|
|
2108
|
+
*/
|
|
1448
2109
|
middleware?: readonly HttpMiddleware<E>[];
|
|
1449
|
-
/**
|
|
2110
|
+
/**
|
|
2111
|
+
* The exact HTTPS origins the handler answers, such as `https://notes.example.com`. A request to another
|
|
2112
|
+
* origin answers `NOT_FOUND` before any middleware, hook, route or token check runs. An empty list, or an
|
|
2113
|
+
* origin that is not an exact HTTPS origin, throws at construction.
|
|
2114
|
+
*/
|
|
1450
2115
|
origins?: readonly string[];
|
|
1451
2116
|
/**
|
|
1452
2117
|
* Test seam for the default OAuth verification: returns a token's claims in place of the JWT check; claim
|
|
@@ -1460,27 +2125,49 @@ interface HttpOptions<E = unknown> {
|
|
|
1460
2125
|
annotate?: (operation: string, requestId: string) => void;
|
|
1461
2126
|
/**
|
|
1462
2127
|
* Protocol transports served beside the operations, such as `mcp()`; one per path, and at most one MCP
|
|
1463
|
-
* transport.
|
|
2128
|
+
* transport, which an application with `mcp` configuration requires.
|
|
1464
2129
|
*/
|
|
1465
2130
|
transports?: readonly HttpTransport[];
|
|
1466
2131
|
/**
|
|
1467
|
-
* Plain routes by exact path.
|
|
1468
|
-
* operation or transport path are reserved. A route may sit
|
|
1469
|
-
* transport's path (a second MCP server at `/mcp/agent-runtime`): the
|
|
1470
|
-
*
|
|
2132
|
+
* Plain routes by exact path: absolute paths of unreserved characters. The native paths, paths of the form
|
|
2133
|
+
* `/v<n>/…` below the base path, and every operation or transport path are reserved. A route may sit
|
|
2134
|
+
* beneath a transport's path (a second MCP server at `/mcp/agent-runtime`): the transport answers only its
|
|
2135
|
+
* exact path.
|
|
1471
2136
|
*/
|
|
1472
2137
|
routes?: Readonly<Record<string, HttpRoute<E>>>;
|
|
1473
|
-
/**
|
|
2138
|
+
/**
|
|
2139
|
+
* The path the operations and the native documents (the index, `/openapi.json`, OAuth discovery and, by
|
|
2140
|
+
* default, `/health`) are served below, such as `/api`; transports, plain routes and mounts keep their
|
|
2141
|
+
* absolute paths.
|
|
2142
|
+
*/
|
|
1474
2143
|
basePath?: string;
|
|
1475
|
-
/**
|
|
2144
|
+
/**
|
|
2145
|
+
* The absolute path of the liveness check, which answers a GET without a token with
|
|
2146
|
+
* `{ status: 'ok', service, version }` and probes no dependency; `/health` below the base path by default.
|
|
2147
|
+
*/
|
|
1476
2148
|
healthPath?: string;
|
|
1477
|
-
/**
|
|
2149
|
+
/**
|
|
2150
|
+
* Handlers by path prefix: each answers its prefix and every path below it (`/files` and `/files/a`, never
|
|
2151
|
+
* `/filesystem`), and where mounts nest, the longest prefix answers. A mount may neither contain a native,
|
|
2152
|
+
* operation, transport or plain route path nor sit below a transport or plain route.
|
|
2153
|
+
*/
|
|
1478
2154
|
mounts?: Readonly<Record<string, HttpRoute<E>>>;
|
|
1479
|
-
/**
|
|
2155
|
+
/**
|
|
2156
|
+
* Runs for every request after the middleware and before routing: a response it returns answers the
|
|
2157
|
+
* request, and `null` lets it continue. It sees no principal.
|
|
2158
|
+
*/
|
|
1480
2159
|
before?: (request: Request, env: E, context: RouteContext) => Response | null | Promise<Response | null>;
|
|
1481
|
-
/**
|
|
2160
|
+
/**
|
|
2161
|
+
* Answers a request nothing else claims, in place of `NOT_FOUND`. It never receives a native path or a
|
|
2162
|
+
* path the handler reserves: one below the base path, under `/.well-known` or `/v<n>`, or below a
|
|
2163
|
+
* transport's path.
|
|
2164
|
+
*/
|
|
1482
2165
|
fallback?: HttpRoute<E>;
|
|
1483
|
-
/**
|
|
2166
|
+
/**
|
|
2167
|
+
* Wraps each matched HTTP operation before its token is checked: it receives the request, the env and the
|
|
2168
|
+
* operation's name and effect, and calls `run` once with the env the call then uses, for its token
|
|
2169
|
+
* resolution and as its handler's `env`. A second call to `run` throws. MCP requests do not reach it.
|
|
2170
|
+
*/
|
|
1484
2171
|
aroundOperation?: (request: Request, env: E, operation: Readonly<{
|
|
1485
2172
|
name: string;
|
|
1486
2173
|
effect: OperationShape['effect'];
|
|
@@ -1489,7 +2176,10 @@ interface HttpOptions<E = unknown> {
|
|
|
1489
2176
|
/**
|
|
1490
2177
|
* Serves an application over HTTP as one function, `(request, env, background?) => Promise<Response>`: its
|
|
1491
2178
|
* operations at their routes, the OpenAPI document as JSON and YAML, OAuth discovery, `/health`, transports
|
|
1492
|
-
* such as MCP, plain routes and mounts.
|
|
2179
|
+
* such as MCP, plain routes and mounts. Every response but a protocol upgrade (101) carries `x-request-id`,
|
|
2180
|
+
* `x-content-type-options: nosniff`, `server-timing` and `cache-control: private, no-store`, unless a plain
|
|
2181
|
+
* route, mount, fallback or `before` hook sets its own `cache-control`. Construction throws a TypeError for a
|
|
2182
|
+
* path two of them would claim, and for an option, token scheme or token source it cannot serve.
|
|
1493
2183
|
*/
|
|
1494
2184
|
declare function createHttpHandler<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>, hooks?: HttpOptions<E>): (request: Request, env: E, background?: BackgroundContext) => Promise<Response>;
|
|
1495
2185
|
/**
|
|
@@ -1498,13 +2188,26 @@ declare function createHttpHandler<E, C, O extends Record<string, OperationShape
|
|
|
1498
2188
|
*/
|
|
1499
2189
|
/** Whether a byte operation may read one of its input fields from this header. */
|
|
1500
2190
|
declare function isInputHeaderName(header: string): boolean;
|
|
1501
|
-
/**
|
|
2191
|
+
/**
|
|
2192
|
+
* The parameter names of a declared route template, in order. A template is versioned (`/v1/…`) with at least
|
|
2193
|
+
* one segment after the version, each fixed or a complete `{parameter}` with a unique, safe name; anything
|
|
2194
|
+
* else throws a TypeError. It reads declared templates, never a request's path.
|
|
2195
|
+
*/
|
|
1502
2196
|
declare function operationPathParameters(path: string): string[];
|
|
1503
|
-
/**
|
|
2197
|
+
/**
|
|
2198
|
+
* One path segment, percent-decoded, or null when it does not decode or decodes to a value
|
|
2199
|
+
* `isPathParameterValue` refuses, so decoding cannot change which route a path reaches.
|
|
2200
|
+
*/
|
|
1504
2201
|
declare function decodePathParameter(segment: string): string | null;
|
|
1505
|
-
/**
|
|
2202
|
+
/**
|
|
2203
|
+
* Whether a value can be a path parameter: a nonempty string other than `.` and `..`, without a slash, a
|
|
2204
|
+
* backslash, a control character or a lone surrogate, so it stays one segment when encoded.
|
|
2205
|
+
*/
|
|
1506
2206
|
declare function isPathParameterValue(value: unknown): value is string;
|
|
1507
|
-
/**
|
|
2207
|
+
/**
|
|
2208
|
+
* What the router reads of a definition: its method and path template. Its other fields come back unchanged
|
|
2209
|
+
* in a match; checking a request's input is not the router's work.
|
|
2210
|
+
*/
|
|
1508
2211
|
interface HttpRouteDefinition {
|
|
1509
2212
|
/**
|
|
1510
2213
|
* The method and versioned path template to route, such as `GET /v1/notes/{noteId}`; a definition without
|
|
@@ -1523,15 +2226,18 @@ interface HttpRouteMatch<D> {
|
|
|
1523
2226
|
parameters: Readonly<Record<string, string>>;
|
|
1524
2227
|
}
|
|
1525
2228
|
/**
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
2229
|
+
* The router for a set of definitions: `match(method, path)` finds the one route a request reaches, with its
|
|
2230
|
+
* decoded parameters, and `ownsPath(path)` says whether any route answers a path. A definition without `http`
|
|
2231
|
+
* is skipped. Construction throws a TypeError for an unsupported method, a malformed template, a duplicate
|
|
2232
|
+
* route, or two templates that could match the same path. A fixed route is one map lookup; templates compile
|
|
2233
|
+
* into states with one transition per segment, so matching never scans the routes.
|
|
1528
2234
|
*/
|
|
1529
2235
|
declare function createHttpRouteResolver<D extends HttpRouteDefinition>(definitions: readonly D[]): {
|
|
1530
2236
|
match: (method: string, path: string) => HttpRouteMatch<D> | null;
|
|
1531
|
-
/**
|
|
2237
|
+
/** Whether any route answers a declared path, so a transport cannot claim an operation's path. */
|
|
1532
2238
|
ownsPath(path: string): boolean;
|
|
1533
2239
|
};
|
|
1534
|
-
/**
|
|
2240
|
+
/** Every reason a bounded read can fail with: the values of a body failure's `data.reason`. */
|
|
1535
2241
|
declare const HTTP_BODY_FAILURES: readonly ['too_large', 'invalid_length', 'invalid_json', 'invalid_utf8', 'unexpected_content_type', 'aborted', 'read_failed'];
|
|
1536
2242
|
/** Why a body could not be read. */
|
|
1537
2243
|
type HttpBodyFailureReason = (typeof HTTP_BODY_FAILURES)[number];
|
|
@@ -1544,160 +2250,106 @@ interface HttpBodyFailure extends Failure<{
|
|
|
1544
2250
|
}
|
|
1545
2251
|
/** How much of a body to read, and until when. */
|
|
1546
2252
|
interface BodyReadOptions {
|
|
1547
|
-
/**
|
|
2253
|
+
/**
|
|
2254
|
+
* The most body bytes to read, a positive safe integer; a longer body fails as `too_large`, and any other
|
|
2255
|
+
* value throws a RangeError.
|
|
2256
|
+
*/
|
|
1548
2257
|
maxBytes: number;
|
|
1549
|
-
/**
|
|
2258
|
+
/**
|
|
2259
|
+
* Aborts the read, which then fails as `aborted`. For a response, pass the signal its `fetch` used, so one
|
|
2260
|
+
* deadline covers the request and its body.
|
|
2261
|
+
*/
|
|
1550
2262
|
signal?: AbortSignal;
|
|
1551
2263
|
}
|
|
1552
2264
|
/** What a body is read from: a request or a response. */
|
|
1553
2265
|
type BodySource = Pick<Request, 'body' | 'headers'>;
|
|
1554
2266
|
/**
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
2267
|
+
* Reads a request's or a response's body as bytes, at most `maxBytes` of them, chunked bodies included, and
|
|
2268
|
+
* answers them unchanged, as a signature check needs them; an absent body is no bytes. A `content-length`
|
|
2269
|
+
* that is malformed or above the limit is refused before reading. Every expected failure is a result
|
|
2270
|
+
* (`too_large`, `invalid_length`, `aborted` or `read_failed`), and a refused body is cancelled without
|
|
2271
|
+
* waiting for the other side.
|
|
1558
2272
|
*/
|
|
1559
2273
|
declare function readBodyBytes(source: BodySource, options: BodyReadOptions): Promise<Result<Uint8Array<ArrayBuffer>, HttpBodyFailure>>;
|
|
1560
|
-
/**
|
|
2274
|
+
/**
|
|
2275
|
+
* Reads a body as `readBodyBytes` does and decodes it as UTF-8. Invalid UTF-8 fails as `invalid_utf8`,
|
|
2276
|
+
* unless `fatalUtf8: false` replaces it with U+FFFD, as a provider that signs its decoded text may require.
|
|
2277
|
+
*/
|
|
1561
2278
|
declare function readBodyText(source: BodySource, options: BodyReadOptions & {
|
|
1562
2279
|
fatalUtf8?: boolean;
|
|
1563
2280
|
}): Promise<Result<string, HttpBodyFailure>>;
|
|
1564
|
-
/**
|
|
2281
|
+
/**
|
|
2282
|
+
* Whether a Content-Type value is `application/json` or a structured `+json` type such as
|
|
2283
|
+
* `application/problem+json`, whatever its parameters and case.
|
|
2284
|
+
*/
|
|
1565
2285
|
declare function isJsonMediaType(value: string | null): boolean;
|
|
1566
|
-
/**
|
|
2286
|
+
/**
|
|
2287
|
+
* Reads a JSON body within `maxBytes` and parses it, as `unknown` for a schema to check. A Content-Type other
|
|
2288
|
+
* than `application/json` (or any `+json` type, with `allowJsonSuffix`) fails as `unexpected_content_type`
|
|
2289
|
+
* before anything is read, and text that does not parse as `invalid_json`; the other failures are
|
|
2290
|
+
* `readBodyText`'s.
|
|
2291
|
+
*/
|
|
1567
2292
|
declare function readJsonBody(source: Pick<Request, 'body' | 'headers'>, options: {
|
|
1568
2293
|
maxBytes: number;
|
|
1569
2294
|
signal?: AbortSignal;
|
|
1570
2295
|
allowJsonSuffix?: boolean;
|
|
1571
2296
|
}): Promise<Result<unknown, HttpBodyFailure>>;
|
|
1572
|
-
/**
|
|
2297
|
+
/**
|
|
2298
|
+
* Reads a response's JSON body as `readJsonBody` does, accepting any `+json` type: a 204 or 205 reads as
|
|
2299
|
+
* `null`, and a signal already aborted fails as `aborted` without reading. Pass the signal the `fetch` used,
|
|
2300
|
+
* so one deadline covers the request and its body.
|
|
2301
|
+
*/
|
|
1573
2302
|
declare function readJsonResponse(response: Response, options: {
|
|
1574
2303
|
maxBytes: number;
|
|
1575
2304
|
signal: AbortSignal;
|
|
1576
2305
|
}): Promise<Result<unknown, HttpBodyFailure>>;
|
|
1577
|
-
/**
|
|
2306
|
+
/**
|
|
2307
|
+
* The seconds a `Retry-After` value asks a client to wait, as delta seconds or as an HTTP date relative to
|
|
2308
|
+
* `nowMs`, rounded up and held between 0 and `maximum` (an hour by default); undefined when the value is
|
|
2309
|
+
* absent or unreadable. It is a hint: it never makes repeating a write safe.
|
|
2310
|
+
*/
|
|
1578
2311
|
declare function retryAfterSeconds(value: string | null, nowMs: number, maximum?: number): number | undefined;
|
|
1579
2312
|
/**
|
|
1580
2313
|
* The document the origin serves at `/openapi.json`: every public operation that declares an HTTP route,
|
|
1581
|
-
* never an internal one
|
|
1582
|
-
*
|
|
2314
|
+
* never an internal one, under one tag per group. Each request body, success envelope and failure is a named
|
|
2315
|
+
* component, which a generated client names its types after; each operation also carries its scopes,
|
|
2316
|
+
* effect, limits in force, MCP tool hints and native RPC as `x-*` extensions.
|
|
1583
2317
|
*
|
|
1584
2318
|
* Every schema reference in it is a local `#/components/schemas/<name>` pointer: the `$id`-named
|
|
1585
2319
|
* schemas of its paths and components (TypeBox Recursive/Ref) become components, as `bundleSchemas`
|
|
1586
|
-
* describes.
|
|
2320
|
+
* describes. A schema `$id` that takes the name of a component the document writes itself, and a component
|
|
2321
|
+
* named as a generator names an operation's own types, such as `CreateNoteResponse`, throw a TypeError.
|
|
1587
2322
|
*/
|
|
1588
2323
|
declare function createOpenApi<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>, options?: {
|
|
1589
|
-
/**
|
|
2324
|
+
/**
|
|
2325
|
+
* Adds an adapter's `x-` extensions to each documented operation, from its name and declaration; a key
|
|
2326
|
+
* without the `x-` prefix throws a TypeError. Schemas in the extensions are bundled into the document's
|
|
2327
|
+
* components with the rest.
|
|
2328
|
+
*/
|
|
1590
2329
|
operationExtensions?: (name: string, operation: OperationShape) => Record<`x-${string}`, unknown>;
|
|
1591
2330
|
}): Record<string, unknown>;
|
|
1592
2331
|
/**
|
|
1593
|
-
* The
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
declare function defineApp<Env, C>(): <const Ops extends Record<string, OperationShape>>(manifest: AppManifest<Env, C, Ops>) => AppManifest<Env, C, Ops>;
|
|
1600
|
-
/** A Workers static-assets binding; product stores and secrets never satisfy this capability. */
|
|
1601
|
-
interface AssetBinding {
|
|
1602
|
-
/** Answers a request with the uploaded build file at its URL path. */
|
|
1603
|
-
fetch: (request: Request) => Promise<Response>;
|
|
1604
|
-
}
|
|
1605
|
-
/** The names of the env bindings that are asset bindings. */
|
|
1606
|
-
type AssetBindingName<E> = { [K in keyof E]-?: E[K] extends AssetBinding ? K : never; }[keyof E] & string;
|
|
1607
|
-
/** Explicit assets policy. Unknown paths never receive the SPA shell. */
|
|
1608
|
-
interface WorkerAssetsOptions<E> {
|
|
1609
|
-
/** Environment binding whose fetch method serves the uploaded build files. */
|
|
1610
|
-
binding: AssetBindingName<E>;
|
|
1611
|
-
/** Known SPA routes. Stateless expressions may admit product-owned detail routes. */
|
|
1612
|
-
pages?: {
|
|
1613
|
-
paths: readonly string[];
|
|
1614
|
-
patterns?: readonly RegExp[];
|
|
1615
|
-
/** Build shell fetched for admitted pages; defaults to /index.html. */
|
|
1616
|
-
shell?: string;
|
|
1617
|
-
};
|
|
1618
|
-
/** Named build files that must revalidate, such as manifests and service workers. */
|
|
1619
|
-
files?: readonly string[];
|
|
1620
|
-
/** Slash-delimited namespaces containing content-hashed, immutable build files. */
|
|
1621
|
-
immutablePrefixes?: readonly string[];
|
|
1622
|
-
/** Product browser policy, including CSP. Native content type and cache policy remain authoritative. */
|
|
1623
|
-
headers?: HeadersInit | ((request: Request, env: E) => HeadersInit);
|
|
1624
|
-
/**
|
|
1625
|
-
* Development under Vite (the Cloudflare Vite plugin), whose dev server stands behind the binding:
|
|
1626
|
-
* a GET the Worker does not serve as a page, file or immutable asset (Vite's client, modules and
|
|
1627
|
-
* sources) is forwarded to it as it came. Pass `import.meta.env.DEV`, which a production build sets to
|
|
1628
|
-
* false: a deployed Worker must never forward unknown paths.
|
|
1629
|
-
*/
|
|
1630
|
-
development?: boolean;
|
|
1631
|
-
}
|
|
1632
|
-
/** Typed organization credential preparation for one derived operation group. */
|
|
1633
|
-
declare function credentials<Schema extends TSchema$1>(options: {
|
|
1634
|
-
principal: Principal;
|
|
1635
|
-
accounts: {
|
|
1636
|
-
getByName: (name: string) => {
|
|
1637
|
-
readCredential: (organizationId: string) => Promise<Result<unknown, Failure>>;
|
|
1638
|
-
};
|
|
1639
|
-
};
|
|
1640
|
-
schema: Schema;
|
|
1641
|
-
}): Promise<Result<{
|
|
1642
|
-
credential: Static$1<Schema>;
|
|
1643
|
-
}, Failure>>;
|
|
1644
|
-
/**
|
|
1645
|
-
* The RPC methods of a Worker's entrypoint: one per operation that declares `rpc`, taking the caller's
|
|
1646
|
-
* principal and the input and answering a Result.
|
|
2332
|
+
* The document of the operations an application serves over native RPC, which another service binds to:
|
|
2333
|
+
* each operation that declares `rpc`, internal ones and tools included, as `POST /rpc/<name>` whose body is
|
|
2334
|
+
* the operation's whole input, with its answer and failures named as in the HTTP document. No HTTP route
|
|
2335
|
+
* answers these paths: each names a method of the Worker's `Service` entrypoint, which a Service Binding
|
|
2336
|
+
* calls with the caller's principal. `maximus openapi` writes it to `rpc.openapi.json`, and a caller's
|
|
2337
|
+
* `services` option types its binding from it.
|
|
1647
2338
|
*/
|
|
1648
|
-
|
|
1649
|
-
rpc: true | {
|
|
1650
|
-
callers: readonly string[];
|
|
1651
|
-
};
|
|
1652
|
-
} ? K : never]: (principal: Principal, input: Static$1<Ops[K]['input']>) => Promise<Result<Static$1<Ops[K]['output']>, Failure>>; };
|
|
1653
|
-
/**
|
|
1654
|
-
* What `createWorker` returns: the default export's handler, the named entrypoint for Worker RPC, and
|
|
1655
|
-
* wrappers that run your own entrypoints and Durable Objects inside the application's diagnostics.
|
|
1656
|
-
*/
|
|
1657
|
-
interface WorkerRuntime<E, O extends Record<string, OperationShape>> {
|
|
1658
|
-
/** The Worker's default export: `fetch` for HTTP, plus the other `handlers` given to `createWorker`. */
|
|
1659
|
-
handler: ExportedHandler<E>;
|
|
1660
|
-
/**
|
|
1661
|
-
* A `WorkerEntrypoint` class with one method per operation that declares `rpc`; export it by name for
|
|
1662
|
-
* Service Bindings to call.
|
|
1663
|
-
*/
|
|
1664
|
-
entrypoint: new (ctx: ExecutionContext, env: E) => WorkerEntrypoint<E> & RpcMethods<O>;
|
|
1665
|
-
/**
|
|
1666
|
-
* Wraps your own `WorkerEntrypoint` class so its methods run inside the application's diagnostics; it keeps
|
|
1667
|
-
* its methods and type.
|
|
1668
|
-
*/
|
|
1669
|
-
service: <D extends new (ctx: ExecutionContext, env: E) => WorkerEntrypoint<E>>(implementation: D) => D;
|
|
1670
|
-
/**
|
|
1671
|
-
* Wraps a Durable Object class so its methods run inside the application's diagnostics; it keeps its
|
|
1672
|
-
* methods and type.
|
|
1673
|
-
*/
|
|
1674
|
-
durableObject: <T extends DurableObject<E>, D extends new (state: DurableObject['ctx'], env: E) => T>(implementation: D) => D;
|
|
1675
|
-
}
|
|
2339
|
+
declare function createRpcOpenApi<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>): Record<string, unknown>;
|
|
1676
2340
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
2341
|
+
* The execution path every transport shares: checks that the caller may run the operation (its scopes when
|
|
2342
|
+
* `authority` is given, its actor kind, and `authority` itself when the operation has conditional scopes),
|
|
2343
|
+
* decodes the input, prepares the context, runs the middleware and the handler, then checks the result
|
|
2344
|
+
* against the catalog, the declared failures, the output schema and the output limit. A refused caller
|
|
2345
|
+
* answers `FORBIDDEN` and a refused input `INVALID_INPUT`. An unexpected error becomes `INTERNAL_ERROR`,
|
|
2346
|
+
* reported while telemetry is on, and is never thrown.
|
|
1679
2347
|
*/
|
|
1680
|
-
|
|
1681
|
-
/** The Worker's other handlers (`scheduled`, `queue`, …), merged into the default export. */
|
|
1682
|
-
handlers?: Omit<ExportedHandler<E>, 'fetch'>;
|
|
1683
|
-
/** Protocol transports served beside the operations, such as `mcp()`. */
|
|
1684
|
-
transports?: HttpOptions<E>['transports'];
|
|
1685
|
-
/** Native HTTP mounting, product admission and static/protocol composition. */
|
|
1686
|
-
http?: Omit<HttpOptions<E>, 'transports' | 'routes' | 'annotate'>;
|
|
1687
|
-
/** Explicit build files and SPA page admission, served through the native HTTP fallback. */
|
|
1688
|
-
assets?: WorkerAssetsOptions<E>;
|
|
1689
|
-
/**
|
|
1690
|
-
* Plain routes outside token admission (provider webhooks, signed links,
|
|
1691
|
-
* OAuth callbacks), by exact path. Each handler verifies its own signature
|
|
1692
|
-
* or token before reading the request. They run inside the same handler,
|
|
1693
|
-
* so diagnostics cover them too.
|
|
1694
|
-
*/
|
|
1695
|
-
routes?: Readonly<Record<string, HttpRoute<E>>>;
|
|
1696
|
-
}
|
|
2348
|
+
declare function executeOperation<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>, operation: OperationShape, env: E, principal: Principal, input: unknown, authority?: InvocationAuthority, background?: BackgroundContext, body?: BinaryBody): Promise<Result<unknown, Failure>>;
|
|
1697
2349
|
/**
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
2350
|
+
* Checks an application against every rule `.build()` enforces, then hands it back unchanged; a refusal is a
|
|
2351
|
+
* TypeError. Curried, so `Env` and `C` can be given explicitly while the operations' types are inferred from
|
|
2352
|
+
* the argument.
|
|
1701
2353
|
*/
|
|
1702
|
-
declare function
|
|
1703
|
-
export {
|
|
2354
|
+
declare function defineApp<Env, C>(): <const Ops extends Record<string, OperationShape>>(manifest: AppManifest<Env, C, Ops>) => AppManifest<Env, C, Ops>;
|
|
2355
|
+
export { PageInfo as $, Success as $n, StandardFailure as $t, TransportContext as A, TokenAlgorithm as An, ContextArguments as At, DeletedObject as B, Principal as Bn, HandlerOptions as Bt, isPathParameterValue as C, TelemetryConfig as Cn, urlSchema as Ct, HttpRoute as D, telemetryEnabled as Dn, parseInput as Dt, HttpOptions as E, reportUnexpected as En, decodeSchema as Et, Static$2 as F, TokenScheme as Fn, HandlerAnswer as Ft, NamedReference as G, protectedResourceMetadata as Gn, ToolDeclaration as Gt, EmailAddressSchema as H, TokenClient as Hn, RouteBody as Ht, TSchema$2 as I, TokenSource as In, HandlerArguments as It, PostalAddress as J, StaticDecode$1 as Jn, defineContext as Jt, NamedReferenceSchema as K, ScopeMatch as Kn, ToolOptions as Kt, Type$2 as L, createTokenAuthorization as Ln, HandlerDeclaration as Lt, projectAccessToken as M, TokenDevelopment as Mn, DomainCode as Mt, EmptyInputSchema as N, TokenPolicy as Nn, Fail as Nt, HttpTransport as O, withDiagnostics as On, parseSchema as Ot, OrganizationIdSchema as P, TokenResolutionContext as Pn, Failed as Pt, Page as Q, Result as Qn, STANDARD_FAILURES as Qt, UuidSchema as R, createTokenVerifier as Rn, HandlerHttp as Rt, isInputHeaderName as S, Observer as Sn, transformSchema as St, HttpMiddleware as T, recordExecution as Tn, decodeInput as Tt, HexColorSchema as U, TokenPrincipal as Un, SchemaOf as Ut, DeletedObjectSchema as V, PrincipalSchema as Vn, PreparedContext as Vt, HttpsUrlSchema as W, OAuthResource as Wn, SchemaOrFields as Wt, SignedUrl as X, BodyFailure as Xn, defineTelemetry as Xt, PostalAddressSchema as Y, BinaryBody as Yn, defineHandler as Yt, SignedUrlSchema as Z, FailureResult as Zn, defineTool as Zt, readBodyText as _, operationMatchesScopes as _n, TraceParent as _r, normalizeSchema as _t, Type$1 as a, Invocation as an, CreateArguments as ar, Checked as at, createHttpRouteResolver as b, BackgroundContext as bn, isRequestId as br, strictObject as bt, createRpcOpenApi as c, McpGuide as cn, ErrorDefinition as cr, SchemaInput as ct, readJsonResponse as d, OperationMiddleware as dn, FailureData as dr, defaultSchema as dt, ApplicationBuilder as en, err as er, PageInfoSchema as et, retryAfterSeconds as f, OperationScope as fn, FailureSchema as fr, extendObject as ft, readBodyBytes as g, operation as gn, DurableCorrelation as gr, looseObject as gt, HttpBodyFailureReason as h, isPublicOperation as hn, standardErrors as hr, literalUnion as ht, TSchema$1 as i, Exposure as in, AttachmentOutputSchema as ir, pageLimit as it, createHttpHandler as j, TokenClaims as jn, ContextDeclaration as jt, RouteContext as k, TokenAccess as kn, AuthOptions as kt, isJsonMediaType as l, McpSkill as ln, ErrorFactory as lr, SchemaIssue as lt, HttpBodyFailure as m, composeOperations as mn, resultSchema as mr, inspectSchema as mt, executeOperation as n, maximus as nn, ok as nr, PageQueryFields as nt, t as o, InvocationAuthority as on, DefinedErrors as or, checkSchema as ot, BodyReadOptions as p, OperationShape as pn, defineErrors as pr, inputSchema as pt, PhoneNumberSchema as q, matchesScopes as qn, defineAuth as qt, Static$1 as r, AppManifest as rn, Attachment as rr, TPage as rt, createOpenApi as s, McpConfiguration as sn, ErrorCatalog as sr, readSchema as st, defineApp as t, ApplicationConfiguration as tn, isResult as tr, PageQuery as tt, readJsonBody as u, OperationHandler as un, Failure as ur, SchemaValidationError as ut, HttpRouteDefinition as v, operationScopes as vn, createRequestId as vr, pipeSchema as vt, operationPathParameters as w, diagnosticsEnabled as wn, InputIssue as wt, decodePathParameter as x, ExecutionObservation as xn, parseTraceParent as xr, stripObject as xt, HttpRouteMatch as y, AdmissionObservation as yn, durableCorrelation as yr, refineSchema as yt, t$1 as z, projectToken as zn, HandlerMcp as zt };
|