@arbol-ai/maximus 7.4.0 → 8.0.1
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-x7uY70_1.js +341 -0
- package/dist/chunks/{errors-D7zG9kx9.js → errors-C5w9WY1l.js} +10 -5
- package/dist/chunks/{execution-kVUJPy1A.js → execution-rOiLo8VG.js} +28 -15
- package/dist/chunks/generate-C-9FKW0o.js +197 -0
- package/dist/chunks/handler-iebR-urt.js +141 -0
- package/dist/chunks/http-layout-DS8DnPyu.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-CeolxIqa.js +1588 -0
- package/dist/chunks/openapi-file-Bz9FRaE6.js +83 -0
- package/dist/chunks/pages-iZTvFs5a.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-D94vx21X.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-Bzf1Q1_4.js +410 -0
- package/dist/chunks/src-CPrJpbOM.js +573 -0
- package/dist/chunks/{standard-failures-CLjxS2ea.js → standard-failures-Lh4mSfwG.js} +1 -1
- package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
- package/dist/chunks/{types-DQdfRF3f.d.ts → types-DTIuIEJ-.d.ts} +1000 -342
- package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
- package/dist/chunks/workers-types-BRk_Xa_5.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/standard-failures.js +1 -1
- 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;
|
|
@@ -117,7 +104,7 @@ declare const STANDARD: {
|
|
|
117
104
|
readonly notFound: {
|
|
118
105
|
readonly code: 'NOT_FOUND';
|
|
119
106
|
readonly status: 404;
|
|
120
|
-
readonly message: 'The requested
|
|
107
|
+
readonly message: 'The requested resource does not exist.';
|
|
121
108
|
};
|
|
122
109
|
readonly methodNotAllowed: {
|
|
123
110
|
readonly code: 'HTTP_METHOD_NOT_ALLOWED';
|
|
@@ -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,59 @@ 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
|
+
* Optional WWW-Authenticate value for a 401 or 403 refusal, including a resolver's missing-scope
|
|
610
|
+
* failure. Null keeps the default 401 challenge and leaves a 403 without a challenge. This hook
|
|
611
|
+
* changes response metadata only; it cannot admit a refused request.
|
|
612
|
+
*/
|
|
613
|
+
challenge?: (failure: Failure, context: TokenResolutionContext<E>) => string | null;
|
|
614
|
+
/**
|
|
615
|
+
* Protected-resource metadata documents (RFC 9728) to serve instead of the default one, by absolute path
|
|
616
|
+
* at or below `/.well-known/oauth-protected-resource`, one per resource. When set, the default document
|
|
617
|
+
* answers `NOT_FOUND`. A `bearer` scheme cannot set it.
|
|
618
|
+
*/
|
|
511
619
|
resources?: Readonly<Record<string, OAuthResource<E>>>;
|
|
512
620
|
/**
|
|
513
621
|
* How clients obtain tokens, as OpenAPI and discovery publish it: `oauth` (the default), `bearer` for
|
|
@@ -518,15 +626,30 @@ interface TokenPolicy<E = unknown> {
|
|
|
518
626
|
/**
|
|
519
627
|
* The principal a verified access token grants, read where `mapping` says. A subject of the shape
|
|
520
628
|
* `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
|
-
*
|
|
629
|
+
* who holds only the granted scopes their permissions claim also lists. Malformed or inconsistent claims,
|
|
630
|
+
* such as a missing `sub`, a subject shaped like another client's, or a token of the client credentials grant
|
|
631
|
+
* (`gty: client-credentials`, as Auth0 names it) whose subject is not a machine's, are refused as
|
|
632
|
+
* `UNAUTHORIZED`.
|
|
523
633
|
*/
|
|
524
634
|
declare function projectToken(claims: unknown, mapping?: TokenClaims): Result<TokenPrincipal, Failure>;
|
|
525
|
-
/**
|
|
635
|
+
/**
|
|
636
|
+
* Verifies OAuth access tokens against the issuer's JWKS and answers their claims, or throws for a token it
|
|
637
|
+
* refuses: the signature by one of the policy's algorithms (`RS256` by default), an `iss` that is one of the
|
|
638
|
+
* policy's issuers, an `aud` that names any one of the policy's audiences, `exp` and `sub`, with five seconds
|
|
639
|
+
* of clock tolerance, and a `typ` header, when the token has one, of a plain JWT or an RFC 9068 access token
|
|
640
|
+
* (`at+jwt`). The JWKS, at `jwksUri` resolved against the first issuer, is fetched within ten seconds and
|
|
641
|
+
* cached for ten minutes. An issuer or JWKS URL that is not HTTPS throws a TypeError at construction.
|
|
642
|
+
*/
|
|
526
643
|
declare function createTokenVerifier<E>(policy: TokenPolicy<E>): (token: string) => Promise<import("jose").JWTPayload>;
|
|
527
644
|
/**
|
|
528
|
-
* Admits a request by its
|
|
529
|
-
*
|
|
645
|
+
* Admits a request by its token: verifies it (the development token, a bearer token from a local host; else
|
|
646
|
+
* the policy's own `resolve` when it has one; else, for OAuth, against the issuer's JWKS, or for Cloudflare
|
|
647
|
+
* Access, against the team's keys, projected by `access`) and checks that its scopes admit the request. The
|
|
648
|
+
* token is the bearer token of `Authorization`, or under the `cloudflare-access` source the application token
|
|
649
|
+
* of `Cf-Access-Jwt-Assertion` alone. A request without a token, with one longer than 16384 characters, or
|
|
650
|
+
* with an `x-api-key` header is refused; without `resolve` (or, for a bearer token, a development token), the
|
|
651
|
+
* token must be a compact JWS. Refusals are `UNAUTHORIZED` or `FORBIDDEN` failures, never exceptions. `given`
|
|
652
|
+
* stands in for the JWKS check in tests, answering a token's claims.
|
|
530
653
|
*/
|
|
531
654
|
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
655
|
/** Where background work goes: the runtime's `waitUntil`, such as a Worker's ExecutionContext. */
|
|
@@ -600,8 +723,9 @@ interface AdmissionObservation {
|
|
|
600
723
|
errorCode: string;
|
|
601
724
|
}
|
|
602
725
|
/**
|
|
603
|
-
* Receives observations
|
|
604
|
-
*
|
|
726
|
+
* Receives observations of operation calls and refused admissions as background work, while telemetry is on
|
|
727
|
+
* and the runtime gives the call a `waitUntil`, and unexpected errors as they happen. An observer that fails
|
|
728
|
+
* affects neither the response nor another observer.
|
|
605
729
|
*/
|
|
606
730
|
interface Observer<E> {
|
|
607
731
|
/**
|
|
@@ -635,12 +759,15 @@ interface TelemetryConfig<E> {
|
|
|
635
759
|
* the others.
|
|
636
760
|
*/
|
|
637
761
|
observers?: readonly Observer<E>[];
|
|
638
|
-
/**
|
|
762
|
+
/**
|
|
763
|
+
* Returns the trace id of the span the tracing exporter has active, which observations carry when it is a
|
|
764
|
+
* valid W3C trace id. Read it from the active span, never from a request header, and never generate one.
|
|
765
|
+
*/
|
|
639
766
|
traceId?: () => string | null;
|
|
640
767
|
}
|
|
641
768
|
/**
|
|
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.
|
|
769
|
+
* Whether telemetry is on for this env: it is unless `enabled` is false, or a function that returns false,
|
|
770
|
+
* has no env to read or throws.
|
|
644
771
|
*/
|
|
645
772
|
declare function telemetryEnabled<E>(config: Pick<TelemetryConfig<E>, 'enabled'> | undefined, env: E | undefined): boolean;
|
|
646
773
|
/**
|
|
@@ -652,10 +779,14 @@ declare function withDiagnostics<T>(enabled: boolean, callback: () => T, observe
|
|
|
652
779
|
declare function diagnosticsEnabled(): boolean;
|
|
653
780
|
/**
|
|
654
781
|
* 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.
|
|
782
|
+
* count, stack locations; never a message) and tells the observers of the current `withDiagnostics` scope.
|
|
783
|
+
* It does nothing while diagnostics are off.
|
|
656
784
|
*/
|
|
657
785
|
declare function reportUnexpected(error: unknown, surface?: string, requestId?: string): void;
|
|
658
|
-
/**
|
|
786
|
+
/**
|
|
787
|
+
* Hands the observation of one operation call to the observers, as background work. Nothing is recorded
|
|
788
|
+
* while telemetry is off or without a background context.
|
|
789
|
+
*/
|
|
659
790
|
declare function recordExecution<E>(manifest: {
|
|
660
791
|
name: string;
|
|
661
792
|
telemetry?: TelemetryConfig<E>;
|
|
@@ -666,9 +797,12 @@ declare function recordExecution<E>(manifest: {
|
|
|
666
797
|
started: number;
|
|
667
798
|
result: Result<unknown, Failure>;
|
|
668
799
|
}): void;
|
|
669
|
-
/**
|
|
800
|
+
/**
|
|
801
|
+
* What the transport verified about a call's token, kept apart from the principal: the surface, the granted
|
|
802
|
+
* scopes, the OAuth client and the token itself. Context preparation and handlers receive a frozen copy.
|
|
803
|
+
*/
|
|
670
804
|
interface InvocationAuthority {
|
|
671
|
-
/** The transport whose admission verified the token
|
|
805
|
+
/** The transport whose admission verified the token: `http` or `mcp`. */
|
|
672
806
|
readonly surface: 'http' | 'mcp';
|
|
673
807
|
/** The scopes the verified token grants, which a handler checks its `conditionalScopes` against. */
|
|
674
808
|
readonly scopes: readonly string[];
|
|
@@ -678,8 +812,8 @@ interface InvocationAuthority {
|
|
|
678
812
|
* The bearer token the call was admitted with, verified: on an HTTP or MCP call to the service's origin,
|
|
679
813
|
* including one a gateway forwards. It is the caller's OAuth access token, unless
|
|
680
814
|
* `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,
|
|
815
|
+
* development token; absent under the application's own `bearer` scheme. An operation passes it on to call
|
|
816
|
+
* another service as the same caller, and that service verifies it again. Never log, store or return it.
|
|
683
817
|
*/
|
|
684
818
|
readonly token?: string;
|
|
685
819
|
}
|
|
@@ -690,7 +824,7 @@ interface InvocationAuthority {
|
|
|
690
824
|
interface Invocation<Env> {
|
|
691
825
|
/** The Worker's bindings; inside `http.aroundOperation`, the environment that hook passed to `run`. */
|
|
692
826
|
env: Env;
|
|
693
|
-
/**
|
|
827
|
+
/** The request body's reader, present only on an HTTP operation that declares `http.body: 'bytes'`. */
|
|
694
828
|
readonly body?: BinaryBody;
|
|
695
829
|
/**
|
|
696
830
|
* The verified caller: its actor, actor kind, organization and request id. Scope every tenant query by its
|
|
@@ -698,28 +832,34 @@ interface Invocation<Env> {
|
|
|
698
832
|
*/
|
|
699
833
|
principal: Principal;
|
|
700
834
|
/**
|
|
701
|
-
* The verified token's surface, scopes and
|
|
702
|
-
* over
|
|
835
|
+
* The verified token's surface, scopes, client and token, on HTTP and MCP calls whose token names a client;
|
|
836
|
+
* absent over RPC and for a token that names no client.
|
|
703
837
|
*/
|
|
704
838
|
readonly authority?: InvocationAuthority;
|
|
705
|
-
/**
|
|
839
|
+
/** The operation's input, decoded and checked once; preparation must neither check it again nor log it. */
|
|
706
840
|
readonly input?: unknown;
|
|
707
|
-
/**
|
|
841
|
+
/** The name of the operation being called, which the builder sets; never taken from caller input. */
|
|
708
842
|
readonly operation?: string;
|
|
709
|
-
/**
|
|
843
|
+
/**
|
|
844
|
+
* Where the call keeps best-effort work running after its answer, the runtime's `waitUntil`; absent when
|
|
845
|
+
* the runtime gives none.
|
|
846
|
+
*/
|
|
710
847
|
readonly background?: BackgroundContext;
|
|
711
848
|
}
|
|
712
|
-
/** One scope, or several
|
|
849
|
+
/** One scope, or several: any one of them admits the caller, or every one under `scopeMatch: 'all'`. */
|
|
713
850
|
type OperationScope = string | readonly [string, ...string[]];
|
|
714
|
-
/** Whether an operation belongs in public contracts
|
|
851
|
+
/** Whether an operation belongs in public contracts: the OpenAPI document and the discovery metadata. */
|
|
715
852
|
declare function isPublicOperation(declaration: {
|
|
716
853
|
visibility?: 'public' | 'internal';
|
|
717
854
|
}): boolean;
|
|
718
|
-
/** The scopes of an operation as a list
|
|
855
|
+
/** The scopes of an operation as a list. */
|
|
719
856
|
declare function operationScopes(declaration: {
|
|
720
857
|
scope: OperationScope;
|
|
721
858
|
}): readonly string[];
|
|
722
|
-
/**
|
|
859
|
+
/**
|
|
860
|
+
* Whether granted scopes admit an operation: any one of its scopes, or every one under `scopeMatch: 'all'`.
|
|
861
|
+
* HTTP admission, MCP listing and calls, and execution share it.
|
|
862
|
+
*/
|
|
723
863
|
declare function operationMatchesScopes(declaration: {
|
|
724
864
|
scope: OperationScope;
|
|
725
865
|
scopeMatch?: ScopeMatch;
|
|
@@ -729,24 +869,39 @@ declare function operationMatchesScopes(declaration: {
|
|
|
729
869
|
* explicitly, its visibility and the actors it admits.
|
|
730
870
|
*/
|
|
731
871
|
interface Exposure {
|
|
732
|
-
/**
|
|
872
|
+
/** The principal kinds the operation admits: every kind when omitted. */
|
|
733
873
|
actorKinds?: readonly Principal['actorKind'][];
|
|
734
|
-
/**
|
|
874
|
+
/** The HTTP route: its method, its versioned path and how its body and answer travel. */
|
|
735
875
|
http?: {
|
|
876
|
+
/** The route's method; only a read may use `GET`. */
|
|
736
877
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
878
|
+
/**
|
|
879
|
+
* The versioned path template, such as `/v1/notes/{noteId}`, served below the HTTP handler's `basePath`.
|
|
880
|
+
* A `{parameter}` fills a whole segment and names a required string input field.
|
|
881
|
+
*/
|
|
737
882
|
path: string;
|
|
883
|
+
/**
|
|
884
|
+
* `bytes`: the body is raw bytes the handler reads on demand, and the input comes from the path, the
|
|
885
|
+
* query string and `headers`. Not allowed on `GET`, nor on an operation that is also an MCP tool or RPC
|
|
886
|
+
* method.
|
|
887
|
+
*/
|
|
738
888
|
body?: 'bytes';
|
|
739
|
-
/**
|
|
889
|
+
/**
|
|
890
|
+
* Input fields of a byte operation read from request headers, by field name:
|
|
891
|
+
* `{ checksum: 'x-checksum' }`. The input schema decodes them; `authorization`, `cookie`, `host`,
|
|
892
|
+
* `content-length` and `content-encoding` are never input.
|
|
893
|
+
*/
|
|
740
894
|
headers?: Readonly<Record<string, string>>;
|
|
895
|
+
/** `attachment`: the operation answers a file, its output `AttachmentOutputSchema`. HTTP-only. */
|
|
741
896
|
response?: 'attachment';
|
|
897
|
+
/** The status of a successful answer; 200 by default. */
|
|
742
898
|
successStatus?: 200 | 201 | 202;
|
|
743
899
|
};
|
|
744
900
|
/**
|
|
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.
|
|
901
|
+
* `public` (the default) or `internal`, an operation for the service's own staff. An internal operation
|
|
902
|
+
* stays routed and scope-checked like any other, but it is absent from the public OpenAPI document and from
|
|
903
|
+
* the protected-resource `scopes_supported`; MCP lists it, as every tool, only to tokens that carry its
|
|
904
|
+
* scope. Hiding is not authorization: the scope is what admits the caller.
|
|
750
905
|
*/
|
|
751
906
|
visibility?: 'public' | 'internal';
|
|
752
907
|
/**
|
|
@@ -754,8 +909,11 @@ interface Exposure {
|
|
|
754
909
|
* outside the service (`openWorldHint`, default `true`).
|
|
755
910
|
*/
|
|
756
911
|
mcp?: {
|
|
912
|
+
/** The tool's unique name: a lowercase letter, then up to 63 letters, digits or underscores. */
|
|
757
913
|
name: string;
|
|
914
|
+
/** Whether repeating a call is safe, published as the tool's `idempotentHint`. */
|
|
758
915
|
idempotent: boolean;
|
|
916
|
+
/** Whether the tool reaches outside the service, published as its `openWorldHint`; `true` when absent. */
|
|
759
917
|
openWorld?: boolean;
|
|
760
918
|
};
|
|
761
919
|
/**
|
|
@@ -771,19 +929,24 @@ interface Exposure {
|
|
|
771
929
|
*/
|
|
772
930
|
interface OperationShape extends Exposure {
|
|
773
931
|
/**
|
|
774
|
-
* The scope a caller needs
|
|
775
|
-
* caller (`['notes:notes:read', 'notes:notes:write']`: a write grant
|
|
776
|
-
*
|
|
932
|
+
* The scope a caller needs, `<namespace>:<resource>:<action>`. Several scopes mean any one of them admits
|
|
933
|
+
* the caller (`['notes:notes:read', 'notes:notes:write']`: a write grant also reads), unless `scopeMatch`
|
|
934
|
+
* is `all`. Published as OpenAPI security requirements: one per scope, or one with every scope under `all`.
|
|
777
935
|
*/
|
|
778
936
|
scope: OperationScope;
|
|
779
|
-
/**
|
|
937
|
+
/** How several scopes admit a caller: `any` (the default) needs one of them, `all` needs every one. */
|
|
780
938
|
scopeMatch?: ScopeMatch;
|
|
781
|
-
/**
|
|
939
|
+
/**
|
|
940
|
+
* Scopes the handler checks itself, against `authority.scopes`, for particular resources or fields:
|
|
941
|
+
* namespaced, listed once and distinct from the scopes that admit the call. A call without `authority`,
|
|
942
|
+
* such as one over RPC or with a token that names no client, is refused with `FORBIDDEN` before it runs.
|
|
943
|
+
*/
|
|
782
944
|
conditionalScopes?: readonly string[];
|
|
783
945
|
/**
|
|
784
946
|
* 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
|
|
947
|
+
* Declared, they are all its documents list, and any other domain failure it returns, from its context,
|
|
948
|
+
* middleware or handler, becomes INTERNAL_ERROR and is reported. Omitted, every failure of the catalog is
|
|
949
|
+
* listed and allowed.
|
|
787
950
|
*/
|
|
788
951
|
failures?: readonly string[];
|
|
789
952
|
/** A short human name: the OpenAPI `summary` and the MCP tool's title. */
|
|
@@ -810,57 +973,75 @@ interface OperationShape extends Exposure {
|
|
|
810
973
|
*/
|
|
811
974
|
output: TSchema;
|
|
812
975
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* whose input is legitimately large (a CSV
|
|
816
|
-
* application-wide; the ceiling is 16 MiB. Not allowed on GET operations,
|
|
817
|
-
*
|
|
976
|
+
* The largest request body this operation accepts, in bytes: its JSON body, or its byte body under
|
|
977
|
+
* `http.body: 'bytes'`. A larger one answers `REQUEST_TOO_LARGE`. Defaults to the application's
|
|
978
|
+
* `maxBodyBytes` (32 KiB by default). Raise it only for operations whose input is legitimately large (a CSV
|
|
979
|
+
* import, a document), never application-wide; the ceiling is 16 MiB. Not allowed on GET operations, whose
|
|
980
|
+
* input is the query string.
|
|
818
981
|
*/
|
|
819
982
|
maxBodyBytes?: number;
|
|
820
|
-
/**
|
|
983
|
+
/**
|
|
984
|
+
* The largest output this operation answers, in bytes: its value's JSON, or an attachment's `byteLength`.
|
|
985
|
+
* Defaults to the application's `maxOutputBytes` (256 KiB by default), up to 16 MiB. A larger output is the
|
|
986
|
+
* server's error, `INTERNAL_ERROR`.
|
|
987
|
+
*/
|
|
821
988
|
maxOutputBytes?: number;
|
|
822
989
|
/** The handler: it receives the prepared context and the decoded input and returns a `Result`. */
|
|
823
990
|
execute: (context: never, input: never) => unknown;
|
|
824
|
-
/**
|
|
991
|
+
/**
|
|
992
|
+
* The context preparation and middleware the builder captured when the operation was declared, so each
|
|
993
|
+
* mounted module keeps its own; without it, execution uses the application's `context` and `middleware`.
|
|
994
|
+
*/
|
|
825
995
|
pipeline?: {
|
|
996
|
+
/** Prepares the call's context from its invocation; a failure it returns answers the call. */
|
|
826
997
|
context: (invocation: never) => Promise<Result<unknown, Failure>>;
|
|
998
|
+
/** The middleware that wraps the handler, in the order it runs. */
|
|
827
999
|
middleware: readonly OperationMiddleware<never>[];
|
|
828
1000
|
};
|
|
829
1001
|
}
|
|
830
1002
|
/**
|
|
831
|
-
*
|
|
832
|
-
*
|
|
1003
|
+
* The fields of an operation's definition besides its exposure, as `.operation()` takes them: its scope,
|
|
1004
|
+
* words, effect, failures, schemas and limits.
|
|
833
1005
|
*/
|
|
834
|
-
|
|
835
|
-
scope: OperationScope;
|
|
836
|
-
scopeMatch?: ScopeMatch;
|
|
837
|
-
conditionalScopes?: readonly string[];
|
|
838
|
-
title: string;
|
|
839
|
-
description: string;
|
|
840
|
-
group?: string;
|
|
841
|
-
effect: OperationShape['effect'];
|
|
1006
|
+
type OperationFields<I extends TSchema, O extends TSchema> = Omit<OperationShape, keyof Exposure | 'input' | 'output' | 'execute' | 'pipeline'> & {
|
|
842
1007
|
input: I;
|
|
843
1008
|
output: O;
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1009
|
+
};
|
|
1010
|
+
/** A definition with the exposure its declaration names, keeping that exposure's literal types. */
|
|
1011
|
+
type OperationDefinition<I extends TSchema, O extends TSchema, X> = X & OperationFields<I, O>;
|
|
1012
|
+
/** What a handler receives besides its input: the prepared context and, for a declared byte body, its reader. */
|
|
1013
|
+
type OperationContext<C, X> = C & (X extends {
|
|
1014
|
+
http: {
|
|
1015
|
+
body: 'bytes';
|
|
1016
|
+
};
|
|
1017
|
+
} ? {
|
|
1018
|
+
body: BinaryBody;
|
|
1019
|
+
} : object);
|
|
1020
|
+
/** An operation's handler: the prepared context and the decoded input in, a Result of its output out. */
|
|
1021
|
+
type OperationHandler<C, I extends TSchema, O extends TSchema, X> = (context: OperationContext<C, X>, input: StaticDecode$1<I>) => Promise<Result<Static<O>, Failure>>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Declares one operation on its own, keeping its literal types. The builder's `.operation()` is the usual way
|
|
1024
|
+
* to declare one. As there, `execute` receives the decoded input, `StaticDecode<typeof input>`.
|
|
1025
|
+
*/
|
|
1026
|
+
declare function operation<C, I extends TSchema, O extends TSchema, const X extends Exposure>(definition: OperationDefinition<I, O, X> & {
|
|
1027
|
+
execute: OperationHandler<C, I, O, X>;
|
|
1028
|
+
}): X & Omit<OperationShape, "execute" | "input" | "output" | "pipeline" | keyof Exposure> & {
|
|
853
1029
|
input: I;
|
|
854
1030
|
output: O;
|
|
855
|
-
|
|
1031
|
+
} & {
|
|
1032
|
+
execute: OperationHandler<C, I, O, X>;
|
|
856
1033
|
};
|
|
857
1034
|
/** The intersection of a union's members: the operations of every composed group. */
|
|
858
1035
|
type Intersection<U> = (U extends unknown ? (value: U) => void : never) extends ((value: infer I) => void) ? I : never;
|
|
859
|
-
/**
|
|
1036
|
+
/**
|
|
1037
|
+
* Merges groups of operations into one, never overwriting: a name two groups declare throws a TypeError,
|
|
1038
|
+
* `Duplicate operation: <name>`, which names the route or tool of each when both have one.
|
|
1039
|
+
*/
|
|
860
1040
|
declare function composeOperations<const G extends readonly Record<string, OperationShape>[]>(...groups: G): Intersection<G[number]>;
|
|
861
1041
|
/**
|
|
862
|
-
* Code that wraps an operation after admission and preparation: it receives the context and `next`, which
|
|
863
|
-
*
|
|
1042
|
+
* Code that wraps an operation after admission and preparation: it receives the context and `next`, which
|
|
1043
|
+
* runs the rest of the chain and the handler, and returns a Result. It calls `next` at most once: a second
|
|
1044
|
+
* call rejects.
|
|
864
1045
|
*/
|
|
865
1046
|
type OperationMiddleware<C> = (context: C, next: () => Promise<Result<unknown, Failure>>) => Promise<Result<unknown, Failure>>;
|
|
866
1047
|
/** A Markdown usage guide, served over MCP as a resource and a reusable prompt. */
|
|
@@ -910,12 +1091,22 @@ interface McpConfiguration {
|
|
|
910
1091
|
* transport reads.
|
|
911
1092
|
*/
|
|
912
1093
|
interface AppManifest<Env, C, Ops extends Record<string, OperationShape>> {
|
|
913
|
-
/**
|
|
1094
|
+
/**
|
|
1095
|
+
* The service's identifier, a lowercase kebab-case word of 2 to 64 characters: the MCP server name and the
|
|
1096
|
+
* `service` that `/health` and telemetry report.
|
|
1097
|
+
*/
|
|
914
1098
|
name: string;
|
|
915
1099
|
/** The prefix of every scope, `<namespace>:<resource>:<action>`; it matches `^[a-z][a-z0-9-]{1,63}$`. */
|
|
916
1100
|
namespace: string;
|
|
917
1101
|
/** The service's human name: OpenAPI `info.title`, the MCP server title and the OAuth `resource_name`. */
|
|
918
1102
|
title: string;
|
|
1103
|
+
/** What the service is for, in a sentence or two: OpenAPI `info.description`. */
|
|
1104
|
+
description?: string;
|
|
1105
|
+
/**
|
|
1106
|
+
* What each group of operations holds, by the group's name, such as
|
|
1107
|
+
* `{ Notes: "The notes of the caller's organization." }`: the description of its OpenAPI tag.
|
|
1108
|
+
*/
|
|
1109
|
+
groups?: Readonly<Record<string, string>>;
|
|
919
1110
|
/**
|
|
920
1111
|
* The service's version: OpenAPI `info.version`, the MCP server version and the `version` that `/health`
|
|
921
1112
|
* reports.
|
|
@@ -957,11 +1148,13 @@ interface AppManifest<Env, C, Ops extends Record<string, OperationShape>> {
|
|
|
957
1148
|
*/
|
|
958
1149
|
telemetry?: TelemetryConfig<Env>;
|
|
959
1150
|
/**
|
|
960
|
-
* A Workers rate limiting binding each HTTP and MCP call must pass, per organization and actor;
|
|
961
|
-
*
|
|
1151
|
+
* A Workers rate limiting binding each HTTP and MCP call must pass, per organization and actor; each
|
|
1152
|
+
* message of an MCP batch counts as a call. A refusal answers `RATE_LIMITED`.
|
|
962
1153
|
*/
|
|
963
1154
|
rateLimit?: {
|
|
1155
|
+
/** The name of the rate limiting binding in the env. */
|
|
964
1156
|
binding: keyof Env;
|
|
1157
|
+
/** The `Retry-After` seconds a refusal sends; 60 by default. */
|
|
965
1158
|
retryAfter?: number;
|
|
966
1159
|
};
|
|
967
1160
|
/**
|
|
@@ -985,15 +1178,13 @@ type ApplicationConfiguration<E> = Omit<AppManifest<E, Invocation<E>, Record<nev
|
|
|
985
1178
|
type DistinctOperations<Ops, M> = [Extract<keyof M, keyof Ops>] extends [never] ? unknown : {
|
|
986
1179
|
readonly 'Operations declared twice': Extract<keyof M, keyof Ops>;
|
|
987
1180
|
};
|
|
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
1181
|
/** Refuses a definition field no operation has, such as a misspelled one, which would otherwise do nothing. */
|
|
995
1182
|
type KnownOperationFields<X> = Readonly<Record<Exclude<keyof X, keyof OperationShape>, never>>;
|
|
996
|
-
/**
|
|
1183
|
+
/**
|
|
1184
|
+
* An application under construction, as `maximus()` starts it. Every method returns a new builder and leaves
|
|
1185
|
+
* this one unchanged, so resource modules built from one base share its inferred context without overwriting
|
|
1186
|
+
* each other's operations.
|
|
1187
|
+
*/
|
|
997
1188
|
declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape>> {
|
|
998
1189
|
/**
|
|
999
1190
|
* The application declared so far: its configuration, context preparation, middleware and operations, which
|
|
@@ -1001,24 +1192,23 @@ declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape
|
|
|
1001
1192
|
*/
|
|
1002
1193
|
readonly definition: AppManifest<E, C, Ops>;
|
|
1003
1194
|
private readonly root;
|
|
1195
|
+
/**
|
|
1196
|
+
* Wraps `definition`. `root` identifies the application the builder descends from, and `.mount()` admits
|
|
1197
|
+
* only modules of the same one. Start an application with `maximus()` instead.
|
|
1198
|
+
*/
|
|
1004
1199
|
constructor(definition: AppManifest<E, C, Ops>, root?: object);
|
|
1005
1200
|
/**
|
|
1006
1201
|
* Declares an operation: a camelCase name no other operation uses, its definition (scope, words, effect,
|
|
1007
1202
|
* schemas and exposure) and its handler, which receives the prepared context and the decoded input and
|
|
1008
|
-
* returns a Result.
|
|
1203
|
+
* returns a Result. A name declared twice throws a TypeError, `Duplicate operation: <name>`.
|
|
1009
1204
|
*/
|
|
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> & {
|
|
1205
|
+
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
1206
|
execute: typeof execute;
|
|
1018
1207
|
}>>;
|
|
1019
1208
|
/**
|
|
1020
1209
|
* 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
|
|
1210
|
+
* and before the middleware; a failure it returns answers the call. Derive before declaring operations: on
|
|
1211
|
+
* a builder that already has one, it throws a TypeError.
|
|
1022
1212
|
*/
|
|
1023
1213
|
derive<D extends object>(resolve: (context: C) => Promise<Result<D, Failure>>): ApplicationBuilder<E, C & D, Ops>;
|
|
1024
1214
|
/**
|
|
@@ -1028,21 +1218,434 @@ declare class ApplicationBuilder<E, C, Ops extends Record<string, OperationShape
|
|
|
1028
1218
|
use(middleware: OperationMiddleware<C>): ApplicationBuilder<E, C, Ops>;
|
|
1029
1219
|
/**
|
|
1030
1220
|
* Adds the operations of a resource module built from the same application; each keeps the context and
|
|
1031
|
-
* middleware it was declared with.
|
|
1221
|
+
* middleware it was declared with. A module of another application, or one that declares an operation this
|
|
1222
|
+
* builder has, throws a TypeError.
|
|
1032
1223
|
*/
|
|
1033
1224
|
mount<MC, M extends Record<string, OperationShape>>(module: ApplicationBuilder<E, MC, M> & DistinctOperations<Ops, M>): ApplicationBuilder<E, C, Ops & M>;
|
|
1034
1225
|
/**
|
|
1035
|
-
* Checks every rule the application must keep and returns it. A refusal is a TypeError
|
|
1036
|
-
*
|
|
1226
|
+
* Checks every rule the application must keep and returns it. A refusal is a TypeError whose message names
|
|
1227
|
+
* the rule; most of the rules about one operation also name that operation.
|
|
1037
1228
|
*/
|
|
1038
1229
|
build(): AppManifest<E, C, Ops>;
|
|
1039
1230
|
}
|
|
1040
1231
|
/**
|
|
1041
|
-
* Starts an application: its name, scope namespace, origin, token policy, error catalog and
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1232
|
+
* Starts an application: its name, scope namespace, title, version, origin, token policy, error catalog and
|
|
1233
|
+
* RPC callers, and its optional limits, rate limit, telemetry and MCP configuration. Chain `.derive()` and
|
|
1234
|
+
* `.use()` to prepare each call, `.operation()` to declare operations, `.mount()` to compose resource modules
|
|
1235
|
+
* that share this base, then `.build()`.
|
|
1044
1236
|
*/
|
|
1045
1237
|
declare function maximus<E>(configuration: ApplicationConfiguration<E>): ApplicationBuilder<E, Invocation<E>, Record<never, never>>;
|
|
1238
|
+
/**
|
|
1239
|
+
* `@arbol-ai/maximus/failures`: the framework's own failures as plain data: code, HTTP status,
|
|
1240
|
+
* message, retryability and Retry-After. No runtime and no schema library, for a dispatcher that presents
|
|
1241
|
+
* them, such as an API gateway. `defineErrors` builds their schemas from this same table.
|
|
1242
|
+
*/
|
|
1243
|
+
/** One of the framework's own failures. */
|
|
1244
|
+
interface StandardFailure {
|
|
1245
|
+
/** The stable code clients branch on, such as `RATE_LIMITED`. */
|
|
1246
|
+
readonly code: string;
|
|
1247
|
+
/** The HTTP status that answers it. */
|
|
1248
|
+
readonly status: number;
|
|
1249
|
+
/** A fixed message for people; it never carries request data. */
|
|
1250
|
+
readonly message: string;
|
|
1251
|
+
/** Whether the same request may succeed later; false when absent. */
|
|
1252
|
+
readonly retryable?: boolean;
|
|
1253
|
+
/** The seconds a client waits before retrying, sent as `Retry-After`. */
|
|
1254
|
+
readonly retryAfter?: number;
|
|
1255
|
+
}
|
|
1256
|
+
/** The framework's own failures, by the name `standardErrors` gives each. */
|
|
1257
|
+
declare const STANDARD_FAILURES: {
|
|
1258
|
+
readonly invalidInput: {
|
|
1259
|
+
readonly code: 'INVALID_INPUT';
|
|
1260
|
+
readonly status: 400;
|
|
1261
|
+
readonly message: 'The request does not match the published schema.';
|
|
1262
|
+
};
|
|
1263
|
+
readonly unauthorized: {
|
|
1264
|
+
readonly code: 'UNAUTHORIZED';
|
|
1265
|
+
readonly status: 401;
|
|
1266
|
+
readonly message: 'A valid access token is required.';
|
|
1267
|
+
};
|
|
1268
|
+
readonly forbidden: {
|
|
1269
|
+
readonly code: 'FORBIDDEN';
|
|
1270
|
+
readonly status: 403;
|
|
1271
|
+
readonly message: 'The token does not authorize this operation.';
|
|
1272
|
+
};
|
|
1273
|
+
readonly notFound: {
|
|
1274
|
+
readonly code: 'NOT_FOUND';
|
|
1275
|
+
readonly status: 404;
|
|
1276
|
+
readonly message: 'The requested resource does not exist.';
|
|
1277
|
+
};
|
|
1278
|
+
readonly methodNotAllowed: {
|
|
1279
|
+
readonly code: 'HTTP_METHOD_NOT_ALLOWED';
|
|
1280
|
+
readonly status: 405;
|
|
1281
|
+
readonly message: 'The HTTP method is not supported for this resource.';
|
|
1282
|
+
};
|
|
1283
|
+
readonly tooLarge: {
|
|
1284
|
+
readonly code: 'REQUEST_TOO_LARGE';
|
|
1285
|
+
readonly status: 413;
|
|
1286
|
+
readonly message: 'The request exceeds the allowed size.';
|
|
1287
|
+
};
|
|
1288
|
+
readonly unsupportedMedia: {
|
|
1289
|
+
readonly code: 'UNSUPPORTED_MEDIA_TYPE';
|
|
1290
|
+
readonly status: 415;
|
|
1291
|
+
readonly message: 'The request content type is not supported.';
|
|
1292
|
+
};
|
|
1293
|
+
readonly rateLimited: {
|
|
1294
|
+
readonly code: 'RATE_LIMITED';
|
|
1295
|
+
readonly status: 429;
|
|
1296
|
+
readonly message: 'The request rate limit was exceeded. Try again later.';
|
|
1297
|
+
readonly retryable: true;
|
|
1298
|
+
readonly retryAfter: 60;
|
|
1299
|
+
};
|
|
1300
|
+
readonly internal: {
|
|
1301
|
+
readonly code: 'INTERNAL_ERROR';
|
|
1302
|
+
readonly status: 500;
|
|
1303
|
+
readonly message: 'The service could not complete the operation.';
|
|
1304
|
+
};
|
|
1305
|
+
readonly upstreamUnavailable: {
|
|
1306
|
+
readonly code: 'UPSTREAM_UNAVAILABLE';
|
|
1307
|
+
readonly status: 503;
|
|
1308
|
+
readonly message: 'The upstream service could not complete the request.';
|
|
1309
|
+
readonly retryable: true;
|
|
1310
|
+
};
|
|
1311
|
+
readonly upstreamTimeout: {
|
|
1312
|
+
readonly code: 'UPSTREAM_TIMEOUT';
|
|
1313
|
+
readonly status: 504;
|
|
1314
|
+
readonly message: 'The upstream service did not respond before its deadline.';
|
|
1315
|
+
readonly retryable: true;
|
|
1316
|
+
};
|
|
1317
|
+
/**
|
|
1318
|
+
* A write may have been applied and its answer was lost. Never retried: the caller reconciles (reads
|
|
1319
|
+
* the resource or polls the operation) before deciding to repeat anything.
|
|
1320
|
+
*/
|
|
1321
|
+
readonly outcomeUnknown: {
|
|
1322
|
+
readonly code: 'OUTCOME_UNKNOWN';
|
|
1323
|
+
readonly status: 502;
|
|
1324
|
+
readonly message: 'The operation may have been applied; check its result before repeating it.';
|
|
1325
|
+
};
|
|
1326
|
+
};
|
|
1327
|
+
declare global {
|
|
1328
|
+
/**
|
|
1329
|
+
* What a project registers about its application, so every handler is typed without importing it:
|
|
1330
|
+
* `base`, the builder its routes bind to, `errors`, its error catalog, and `env`, its Worker's bindings.
|
|
1331
|
+
* `maximus prepare` writes the registration in `.maximus/register.d.ts`; without one, handlers receive
|
|
1332
|
+
* the bare invocation and fail with standard failures. Global, so it merges however the package's
|
|
1333
|
+
* declarations are bundled.
|
|
1334
|
+
*/
|
|
1335
|
+
interface MaximusRegister {}
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* A registered member, or its fallback when the project registers none. Only that member is read: the base
|
|
1339
|
+
* depends on `context.ts`, whose types read the registered bindings.
|
|
1340
|
+
*/
|
|
1341
|
+
type Registered<K extends string, Fallback> = K extends keyof MaximusRegister ? MaximusRegister[K] : Fallback;
|
|
1342
|
+
/** The registered Worker's bindings. */
|
|
1343
|
+
type RegisteredEnv = Registered<'env', unknown>;
|
|
1344
|
+
/** The context every handler receives: what the registered base prepares. */
|
|
1345
|
+
type RegisteredContext = Registered<'base', never> extends ApplicationBuilder<infer _E, infer C, infer _O> ? C : Invocation<unknown>;
|
|
1346
|
+
/** The definitions of the registered error catalog. */
|
|
1347
|
+
type CatalogDefinitions = Registered<'errors', typeof standardErrors> extends {
|
|
1348
|
+
definitions: infer D;
|
|
1349
|
+
} ? D : never;
|
|
1350
|
+
/** Every code of the registered catalog: literal codes, or `string` for a catalog typed as `ErrorCatalog`. */
|
|
1351
|
+
type CatalogCode = { [K in keyof CatalogDefinitions]: CatalogDefinitions[K] extends {
|
|
1352
|
+
code: infer C extends string;
|
|
1353
|
+
} ? C : never; }[keyof CatalogDefinitions];
|
|
1354
|
+
/** The code of every standard failure, which any operation may answer without declaring it. */
|
|
1355
|
+
type StandardCode = (typeof STANDARD_FAILURES)[keyof typeof STANDARD_FAILURES]['code'];
|
|
1356
|
+
/** The standard codes only routing and admission answer, before an operation runs: never a handler's. */
|
|
1357
|
+
type AdmissionCode = 'NOT_FOUND' | 'HTTP_METHOD_NOT_ALLOWED' | 'UNAUTHORIZED';
|
|
1358
|
+
/** The standard codes of reading a body, which a byte body's `read()` answers and a handler only returns. */
|
|
1359
|
+
type BodyCode = 'REQUEST_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE';
|
|
1360
|
+
/** The standard codes a handler, a context or middleware may fail with itself. */
|
|
1361
|
+
type OperationStandardCode = Exclude<StandardCode, AdmissionCode | BodyCode>;
|
|
1362
|
+
/** The codes a declaration may list in `failures`: the catalog's own. */
|
|
1363
|
+
type DomainCode = Exclude<CatalogCode, StandardCode>;
|
|
1364
|
+
/** The definition of the registered catalog that has this code. */
|
|
1365
|
+
type DefinitionWithCode<Code> = Extract<{ [K in keyof CatalogDefinitions]: CatalogDefinitions[K] extends {
|
|
1366
|
+
code: Code;
|
|
1367
|
+
} ? CatalogDefinitions[K] : never; }[keyof CatalogDefinitions], ErrorDefinition>;
|
|
1368
|
+
/** What `fail` takes after the code: the data the code declares, or any data when codes are untyped. */
|
|
1369
|
+
type FailureArguments<Code extends string> = string extends CatalogCode ? [data?: Readonly<Record<string, unknown>>] : CreateArguments<DefinitionWithCode<Code>>;
|
|
1370
|
+
/**
|
|
1371
|
+
* The codes a handler may fail with: the domain failures it declares, or every one, and the standard ones
|
|
1372
|
+
* an operation answers itself.
|
|
1373
|
+
*/
|
|
1374
|
+
type AllowedCode<X> = (X extends {
|
|
1375
|
+
failures: readonly (infer C extends string)[];
|
|
1376
|
+
} ? C : DomainCode) | OperationStandardCode;
|
|
1377
|
+
/**
|
|
1378
|
+
* A failure a handler answers with, `return fail('TASK_NOT_FOUND')`: an expected outcome, never thrown.
|
|
1379
|
+
* `fail` creates one, and so does a byte body's `read()` that cannot read the body.
|
|
1380
|
+
*/
|
|
1381
|
+
declare class Failed<Code extends string = string> {
|
|
1382
|
+
/** Keeps the class nominal: an object of the same shape is not a failure. */
|
|
1383
|
+
private readonly nominal;
|
|
1384
|
+
/** The catalog failure the call answers. */
|
|
1385
|
+
readonly failure: Failure & {
|
|
1386
|
+
code: Code;
|
|
1387
|
+
};
|
|
1388
|
+
constructor(failure: Failure & {
|
|
1389
|
+
code: Code;
|
|
1390
|
+
});
|
|
1391
|
+
/** Whether a handler's answer is a failure rather than its output. */
|
|
1392
|
+
static is(value: unknown): value is Failed;
|
|
1393
|
+
}
|
|
1394
|
+
/** Answers a failure of the catalog by its code, with the data the code declares. */
|
|
1395
|
+
type Fail<Codes extends string> = <const Code extends Codes>(code: Code, ...data: FailureArguments<Code>) => Failed<Code>;
|
|
1396
|
+
/** A schema, or the fields of a strict object schema. */
|
|
1397
|
+
type SchemaOrFields = TSchema | TProperties;
|
|
1398
|
+
/** The schema `input` or `output` stands for: itself, or the strict object of its fields. */
|
|
1399
|
+
type SchemaOf<S> = S extends TSchema ? S : S extends TProperties ? TObject<S> : never;
|
|
1400
|
+
/** A field a declaration names, or none when it leaves the field out (its type parameter stays `never`). */
|
|
1401
|
+
type Field<K extends string, T> = [T] extends [never] ? unknown : Record<K, T>;
|
|
1402
|
+
/**
|
|
1403
|
+
* The fields of a declaration its types depend on, as it names them: its failures, HTTP options, MCP tool,
|
|
1404
|
+
* RPC exposure, effect, visibility and operation id.
|
|
1405
|
+
*/
|
|
1406
|
+
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>;
|
|
1407
|
+
/**
|
|
1408
|
+
* A route's byte body, read on demand once the route has admitted its target: its bytes, or the failure the
|
|
1409
|
+
* route answers as it is, `if (!bytes.ok) return bytes.error`.
|
|
1410
|
+
*/
|
|
1411
|
+
interface RouteBody {
|
|
1412
|
+
/**
|
|
1413
|
+
* Reads the body, once, within the route's `maxBodyBytes`: `REQUEST_TOO_LARGE` beyond it,
|
|
1414
|
+
* `UNSUPPORTED_MEDIA_TYPE` for a compressed body and `INVALID_INPUT` for one that broke off.
|
|
1415
|
+
*/
|
|
1416
|
+
read: () => Promise<Result<Uint8Array<ArrayBuffer>, Failed<BodyFailure['code']>>>;
|
|
1417
|
+
}
|
|
1418
|
+
/** What a handler receives: the prepared context, its decoded input, `fail` and, for a byte body, its reader. */
|
|
1419
|
+
type HandlerArguments<C, I extends TSchema, X> = Omit<C, 'input' | 'body'> & {
|
|
1420
|
+
/** The input, decoded against its schema. */
|
|
1421
|
+
readonly input: StaticDecode$1<I>;
|
|
1422
|
+
/** Answers a failure of the catalog: `return fail('TASK_NOT_FOUND')`. */
|
|
1423
|
+
readonly fail: Fail<AllowedCode<X>>;
|
|
1424
|
+
} & (X extends {
|
|
1425
|
+
http: {
|
|
1426
|
+
body: 'bytes';
|
|
1427
|
+
};
|
|
1428
|
+
} ? {
|
|
1429
|
+
readonly body: RouteBody;
|
|
1430
|
+
} : unknown);
|
|
1431
|
+
/** What a handler answers: its output, or a failure from `fail`, at once or as a promise. */
|
|
1432
|
+
type HandlerAnswer<O extends TSchema, X> = Answer<Static<O>, X>;
|
|
1433
|
+
/** A value, or a failure from `fail`, at once or as a promise. */
|
|
1434
|
+
type Answer<V, X> = V | Failed<AllowedCode<X> | BodyCode> | Promise<V | Failed<AllowedCode<X> | BodyCode>>;
|
|
1435
|
+
/** The empty strict object a route answers when it declares no output. */
|
|
1436
|
+
type NoOutput = TObject<Record<never, never>>;
|
|
1437
|
+
/** The output schema a declaration stands for: the one it declares, or the empty object. */
|
|
1438
|
+
type OutputSchema<O> = [O] extends [never] ? NoOutput : SchemaOf<O>;
|
|
1439
|
+
/**
|
|
1440
|
+
* What a handler that declares no output returns: nothing, or the empty object. An async handler without a
|
|
1441
|
+
* return statement answers `Promise<void>`, which `undefined` would refuse.
|
|
1442
|
+
*/
|
|
1443
|
+
type Nothing = Record<string, never> | void;
|
|
1444
|
+
/** What a handler returns: its declared output or, when it declares none, nothing at all. */
|
|
1445
|
+
type OutputValue<O> = [O] extends [never] ? Nothing : Static<SchemaOf<O>>;
|
|
1446
|
+
/** The HTTP options a route may set: its path and method come from its filename. */
|
|
1447
|
+
type HandlerHttp = Omit<NonNullable<Exposure['http']>, 'method' | 'path'>;
|
|
1448
|
+
/** A route's MCP tool: its name and, when they differ from its method's, its hints. */
|
|
1449
|
+
interface HandlerMcp {
|
|
1450
|
+
/** The tool's unique name: a lowercase letter, then up to 63 letters, digits or underscores. */
|
|
1451
|
+
name: string;
|
|
1452
|
+
/** Whether repeating a call is safe; by default, as its HTTP method is (GET, PUT and DELETE are). */
|
|
1453
|
+
idempotent?: boolean;
|
|
1454
|
+
/** Whether the tool reaches outside the service; `true` unless declared. */
|
|
1455
|
+
openWorld?: boolean;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* A route's contract, what `defineHandler` takes after the handler: its schemas and the fields it declares,
|
|
1459
|
+
* each derived or empty when left out. A contract kept in a `const` keeps its types with
|
|
1460
|
+
* `satisfies HandlerOptions`; an annotation would widen them.
|
|
1461
|
+
*/
|
|
1462
|
+
interface HandlerOptions {
|
|
1463
|
+
/** The input schema, or its fields; none when the route takes no input. */
|
|
1464
|
+
input?: SchemaOrFields;
|
|
1465
|
+
/** The output schema, or its fields; none when the route answers the empty object. */
|
|
1466
|
+
output?: SchemaOrFields;
|
|
1467
|
+
/**
|
|
1468
|
+
* A short human name: the OpenAPI `summary` and the MCP tool's title. By default, the method and path in
|
|
1469
|
+
* words: `Get a note` for `GET /v1/notes/{noteId}`, `List notes` for `GET /v1/notes`.
|
|
1470
|
+
*/
|
|
1471
|
+
title?: string;
|
|
1472
|
+
/** What the route does, for people and agents. A route that is also an MCP tool requires it. */
|
|
1473
|
+
description?: string;
|
|
1474
|
+
/**
|
|
1475
|
+
* The OpenAPI tag that groups the route with its resource's other routes. By default, the first fixed
|
|
1476
|
+
* segment after the version, in words: `Notes` for `/v1/notes/{noteId}`.
|
|
1477
|
+
*/
|
|
1478
|
+
group?: string;
|
|
1479
|
+
/**
|
|
1480
|
+
* The OpenAPI `operationId` and the native RPC method. By default, the method and path as an action:
|
|
1481
|
+
* `listNotes` for `GET /v1/notes`, `getNote` for `GET /v1/notes/{noteId}`, `createNote` for
|
|
1482
|
+
* `POST /v1/notes` and `archiveNote` for `POST /v1/notes/{noteId}/archive`.
|
|
1483
|
+
*/
|
|
1484
|
+
operationId?: string;
|
|
1485
|
+
/**
|
|
1486
|
+
* The scope a caller needs: by default, `<namespace>:<resource>:read` for a read and
|
|
1487
|
+
* `<namespace>:<resource>:write` otherwise, the resource being the first fixed segment after the version,
|
|
1488
|
+
* in kebab-case.
|
|
1489
|
+
*/
|
|
1490
|
+
scope?: OperationShape['scope'];
|
|
1491
|
+
/** Whether several scopes are alternatives (`any`, the default) or all required. */
|
|
1492
|
+
scopeMatch?: OperationShape['scopeMatch'];
|
|
1493
|
+
/**
|
|
1494
|
+
* Scopes the handler checks against `authority.scopes` for particular resources or fields, besides the one
|
|
1495
|
+
* that admits the call. A call without `authority` is refused with `FORBIDDEN`.
|
|
1496
|
+
*/
|
|
1497
|
+
conditionalScopes?: OperationShape['conditionalScopes'];
|
|
1498
|
+
/** Whether it reads, writes or deletes: by default, GET reads, DELETE deletes and the rest write. */
|
|
1499
|
+
effect?: OperationShape['effect'];
|
|
1500
|
+
/** The domain failure codes it may answer, besides the standard ones; every one when omitted. */
|
|
1501
|
+
failures?: readonly DomainCode[];
|
|
1502
|
+
/**
|
|
1503
|
+
* The principal kinds it admits: every kind when omitted. Every operation declares them under the
|
|
1504
|
+
* `oauth+bearer` token scheme.
|
|
1505
|
+
*/
|
|
1506
|
+
actorKinds?: Exposure['actorKinds'];
|
|
1507
|
+
/** `internal` keeps it out of the public OpenAPI document and the discovery metadata. */
|
|
1508
|
+
visibility?: Exposure['visibility'];
|
|
1509
|
+
/**
|
|
1510
|
+
* The HTTP options besides the path and method: a byte body, header-sourced fields, an attachment, the
|
|
1511
|
+
* success status.
|
|
1512
|
+
*/
|
|
1513
|
+
http?: HandlerHttp;
|
|
1514
|
+
/** Also serve the route as an MCP tool with this name. */
|
|
1515
|
+
mcp?: HandlerMcp;
|
|
1516
|
+
/** Also serve it as a native RPC method, to every allowed caller or to the listed ones. */
|
|
1517
|
+
rpc?: Exposure['rpc'];
|
|
1518
|
+
/**
|
|
1519
|
+
* The largest request body it accepts, in bytes: its JSON body, or its byte body. By default, the
|
|
1520
|
+
* application's limit.
|
|
1521
|
+
*/
|
|
1522
|
+
maxBodyBytes?: number;
|
|
1523
|
+
/** The largest output it answers, in bytes. By default, the application's limit. */
|
|
1524
|
+
maxOutputBytes?: number;
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* A route as `defineHandler` declares it, before binding gives it a path and a method. `X` holds the fields
|
|
1528
|
+
* its types depend on; `C` is the context its handler expects, the registered one, which the base it binds
|
|
1529
|
+
* to must prepare.
|
|
1530
|
+
*/
|
|
1531
|
+
interface HandlerDeclaration<I extends TSchema, O extends TSchema, X, C = RegisteredContext> {
|
|
1532
|
+
/** The fields the route declares besides its schemas. */
|
|
1533
|
+
readonly options: Omit<HandlerOptions, 'input' | 'output'>;
|
|
1534
|
+
/** The input schema; an empty strict object when the route declares none. */
|
|
1535
|
+
readonly input: I;
|
|
1536
|
+
/** The output schema. */
|
|
1537
|
+
readonly output: O;
|
|
1538
|
+
/** Answers one call. */
|
|
1539
|
+
readonly handler: (args: HandlerArguments<C, I, X>) => HandlerAnswer<O, X>;
|
|
1540
|
+
}
|
|
1541
|
+
/** The fields `defineHandler` types from its contract, as the contract names them. */
|
|
1542
|
+
type HandlerContract<I, O, F, H, M, R, E, V, N> = Omit<HandlerOptions, 'input' | 'output' | 'failures' | 'http' | 'mcp' | 'rpc' | 'effect' | 'visibility' | 'operationId'> & {
|
|
1543
|
+
input?: I;
|
|
1544
|
+
output?: O;
|
|
1545
|
+
failures?: F;
|
|
1546
|
+
http?: H;
|
|
1547
|
+
mcp?: M;
|
|
1548
|
+
rpc?: R;
|
|
1549
|
+
effect?: E;
|
|
1550
|
+
visibility?: V;
|
|
1551
|
+
operationId?: N;
|
|
1552
|
+
} & ([M] extends [never] ? unknown : {
|
|
1553
|
+
description: string;
|
|
1554
|
+
});
|
|
1555
|
+
/**
|
|
1556
|
+
* Declares a route as its file's default export: its handler, then its contract. The filename gives its path
|
|
1557
|
+
* and method: `routes/v1/tasks/[taskId].delete.ts` answers `DELETE /v1/tasks/{taskId}` below the API's base
|
|
1558
|
+
* path, `/api` by default. The handler receives one object, `{ input, principal, env, fail, …context }`, and
|
|
1559
|
+
* returns its output or `fail(code)`. The contract's `input` and `output` are schemas or the fields of strict
|
|
1560
|
+
* objects; without a contract, the route takes no input and answers the empty object.
|
|
1561
|
+
*/
|
|
1562
|
+
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>(
|
|
1563
|
+
/** Answers one call: its output, or `fail(code)`. */
|
|
1564
|
+
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>>;
|
|
1565
|
+
/**
|
|
1566
|
+
* A tool's contract, what `defineTool` takes after the handler: its schemas, description, effect and the
|
|
1567
|
+
* rest. Its scope defaults to `<namespace>:<file>:read` for a read and `<namespace>:<file>:write` otherwise,
|
|
1568
|
+
* the file being the tool's file name without its extension.
|
|
1569
|
+
*/
|
|
1570
|
+
interface ToolOptions extends Omit<HandlerOptions, 'description' | 'effect' | 'operationId' | 'http' | 'mcp' | 'visibility'> {
|
|
1571
|
+
/** What the tool does, for the agents that choose it. */
|
|
1572
|
+
description: string;
|
|
1573
|
+
/** Whether it reads, writes or deletes: its MCP hints and default scope follow it. */
|
|
1574
|
+
effect: OperationShape['effect'];
|
|
1575
|
+
/** Whether repeating a call is safe; by default, only a read is. */
|
|
1576
|
+
idempotent?: boolean;
|
|
1577
|
+
/** Whether the tool reaches outside the service; `true` unless declared. */
|
|
1578
|
+
openWorld?: boolean;
|
|
1579
|
+
}
|
|
1580
|
+
/** A tool as `defineTool` declares it, before binding names it after its file; `X` and `C` as for a route. */
|
|
1581
|
+
interface ToolDeclaration<I extends TSchema, O extends TSchema, X, C = RegisteredContext> {
|
|
1582
|
+
/** The fields the tool declares besides its schemas. */
|
|
1583
|
+
readonly options: Omit<ToolOptions, 'input' | 'output'>;
|
|
1584
|
+
/** The input schema; an empty strict object when the tool takes none. */
|
|
1585
|
+
readonly input: I;
|
|
1586
|
+
/** The output schema. */
|
|
1587
|
+
readonly output: O;
|
|
1588
|
+
/** Answers one call. */
|
|
1589
|
+
readonly handler: (args: HandlerArguments<C, I, X>) => HandlerAnswer<O, X>;
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Declares a tool only MCP serves, as its file's default export: its handler, then its contract.
|
|
1593
|
+
* `mcp/tools/summarize-tasks.ts` is the tool `summarize_tasks`, the operation `summarizeTasks` and, by
|
|
1594
|
+
* default, the title `Summarize tasks`. The contract states its description and effect; its handler works as
|
|
1595
|
+
* a route's.
|
|
1596
|
+
*/
|
|
1597
|
+
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>(
|
|
1598
|
+
/** Answers one call: its output, or `fail(code)`. */
|
|
1599
|
+
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'> & {
|
|
1600
|
+
input?: I;
|
|
1601
|
+
output?: O;
|
|
1602
|
+
failures?: F;
|
|
1603
|
+
rpc?: R;
|
|
1604
|
+
} & ([E] extends [never] ? {
|
|
1605
|
+
effect: OperationShape['effect'];
|
|
1606
|
+
} : {
|
|
1607
|
+
effect: E;
|
|
1608
|
+
})): ToolDeclaration<SchemaOf<I>, OutputSchema<O>, DeclaredFields<F, never, never, R, E, never, never>>;
|
|
1609
|
+
/** What preparing a call's context receives: the verified invocation and `fail`. */
|
|
1610
|
+
type ContextArguments<E = RegisteredEnv> = Invocation<E> & {
|
|
1611
|
+
/** Answers the call with a failure of the catalog instead of preparing its context. */
|
|
1612
|
+
readonly fail: Fail<DomainCode | OperationStandardCode>;
|
|
1613
|
+
};
|
|
1614
|
+
/** The context every handler receives, as `defineContext` declares it; `E` is the registered bindings. */
|
|
1615
|
+
interface ContextDeclaration<D, E = RegisteredEnv> {
|
|
1616
|
+
/** Prepares one call's context from its invocation. */
|
|
1617
|
+
readonly prepare: (args: ContextArguments<E>) => D | Failed | Promise<D | Failed>;
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Declares, as `context.ts`'s default export, what every handler receives besides the invocation: it runs
|
|
1621
|
+
* once per call after admission and returns the values handlers destructure, such as a store scoped to
|
|
1622
|
+
* `principal.organizationId`, or `fail(code)` to answer the call instead. A route that lists its `failures`
|
|
1623
|
+
* answers a domain code of the context only when it lists that code too.
|
|
1624
|
+
*/
|
|
1625
|
+
declare function defineContext<D extends object>(prepare: (args: ContextArguments) => D | Failed | Promise<D | Failed>): ContextDeclaration<D>;
|
|
1626
|
+
/**
|
|
1627
|
+
* The context a `context.ts` declaration prepares: the invocation and its values. Operation middleware is
|
|
1628
|
+
* typed with it, `defineOperationMiddleware<PreparedContext<typeof context>>`, importing the type alone.
|
|
1629
|
+
*/
|
|
1630
|
+
type PreparedContext<T> = T extends ContextDeclaration<infer D, infer E> ? Invocation<E> & Exclude<D, Failed> : never;
|
|
1631
|
+
/** The token fields an application states in code, as `auth.ts` declares them; the rest are configuration. */
|
|
1632
|
+
type AuthOptions<E = RegisteredEnv> = Pick<TokenPolicy<E>, 'resolve' | 'challenge' | 'resourceMetadataUrl' | 'resources'>;
|
|
1633
|
+
/**
|
|
1634
|
+
* Declares, as `auth.ts`'s default export, how the application verifies tokens itself: `resolve`, which
|
|
1635
|
+
* replaces the default OAuth verification for every token but the development token (for credentials the
|
|
1636
|
+
* configured issuer does not issue, such as an application session or a workload key), and its OAuth
|
|
1637
|
+
* resources and their metadata URL. Verify every token cryptographically and parse its principal strictly.
|
|
1638
|
+
* The issuer, audience, scheme and every other field stay in configuration: any of them here throws a
|
|
1639
|
+
* TypeError rather than overriding it.
|
|
1640
|
+
*/
|
|
1641
|
+
declare function defineAuth<const A extends AuthOptions>(auth: A & Record<Exclude<keyof A, keyof AuthOptions>, never>): A;
|
|
1642
|
+
/**
|
|
1643
|
+
* Declares, as `telemetry.ts`'s default export, what the application's diagnostics do: whether Maximus writes
|
|
1644
|
+
* its log events, calls observers and annotates spans (`enabled`, on by default), the observers that receive
|
|
1645
|
+
* each call's safe metadata, such as `analytics()` from `@arbol-ai/maximus/analytics`, and how to read the
|
|
1646
|
+
* active trace id (`traceId`). Any other field throws a TypeError.
|
|
1647
|
+
*/
|
|
1648
|
+
declare function defineTelemetry(telemetry: TelemetryConfig<RegisteredEnv>): TelemetryConfig<RegisteredEnv>;
|
|
1046
1649
|
/**
|
|
1047
1650
|
* Checks a value against a schema without decoding it: the value when it matches, else an `INVALID_INPUT`
|
|
1048
1651
|
* failure without issues. Use `decodeInput` for input with defaults and codecs.
|
|
@@ -1065,8 +1668,12 @@ declare function parseInput<Schema extends TSchema>(schema: Schema, input: unkno
|
|
|
1065
1668
|
};
|
|
1066
1669
|
/** Checks a value against a schema and returns it typed, or throws a TypeError that names no value. */
|
|
1067
1670
|
declare function parseSchema<Schema extends TSchema>(schema: Schema, input: unknown): Static<Schema>;
|
|
1068
|
-
/**
|
|
1069
|
-
*
|
|
1671
|
+
/**
|
|
1672
|
+
* Decodes input against its schema: admits only a bounded plain JSON tree, applies the declared defaults to a
|
|
1673
|
+
* copy, checks it and runs its codecs. Throws a `SchemaValidationError` (or TypeBox's assertion error) when the
|
|
1674
|
+
* input is refused, and whatever an owner codec throws otherwise. Output is checked, never decoded: what a
|
|
1675
|
+
* handler returns must already be canonical.
|
|
1676
|
+
*/
|
|
1070
1677
|
declare function decodeSchema<Schema extends TSchema>(schema: Schema, input: unknown): StaticDecode$1<Schema>;
|
|
1071
1678
|
/** Field issues a refusal carries: enough to correct the input, never an input value. */
|
|
1072
1679
|
interface InputIssue {
|
|
@@ -1076,14 +1683,11 @@ interface InputIssue {
|
|
|
1076
1683
|
message: string;
|
|
1077
1684
|
}
|
|
1078
1685
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
* field issues
|
|
1686
|
+
* Decodes input as `decodeSchema` does and answers a refusal as the `INVALID_INPUT` failure, with its first
|
|
1687
|
+
* field issues: where the input failed and what was expected, never a value. A fault of an owner codec, an
|
|
1688
|
+
* error that refuses nothing, is thrown for the caller to report: it is the server's failure, not the input's.
|
|
1081
1689
|
*/
|
|
1082
1690
|
declare function decodeInput<Schema extends TSchema>(schema: Schema, input: unknown): {
|
|
1083
|
-
error?: undefined;
|
|
1084
|
-
ok: true;
|
|
1085
|
-
value: StaticDecode$1<Schema>;
|
|
1086
|
-
} | {
|
|
1087
1691
|
value?: undefined;
|
|
1088
1692
|
ok: false;
|
|
1089
1693
|
error: {
|
|
@@ -1094,6 +1698,10 @@ declare function decodeInput<Schema extends TSchema>(schema: Schema, input: unkn
|
|
|
1094
1698
|
issues: InputIssue[];
|
|
1095
1699
|
};
|
|
1096
1700
|
};
|
|
1701
|
+
} | {
|
|
1702
|
+
error?: undefined;
|
|
1703
|
+
ok: true;
|
|
1704
|
+
value: StaticDecode$1<Schema>;
|
|
1097
1705
|
};
|
|
1098
1706
|
/** Type-only: the key under which a codec's schema type carries its wire type. No schema object has it. */
|
|
1099
1707
|
declare const WIRE: unique symbol;
|
|
@@ -1155,7 +1763,12 @@ declare const strictObject: <S extends TSchema>(schema: S) => S;
|
|
|
1155
1763
|
declare const looseObject: <S extends TSchema>(schema: S) => S;
|
|
1156
1764
|
/** The object with more properties, keeping how it treats unknown keys. */
|
|
1157
1765
|
declare const extendObject: <P extends TProperties, Q extends TProperties>(schema: TObject<P>, properties: Q) => TObject<P & Q>;
|
|
1158
|
-
/**
|
|
1766
|
+
/**
|
|
1767
|
+
* Reads a field through `normalize`. For a string, or a string that may be null, the pattern, format and
|
|
1768
|
+
* lengths apply to the normalized value, so the wire may send a raw spelling (another case, surrounding
|
|
1769
|
+
* spaces); any other schema checks the raw value first. The wire type stays the schema's own. Runs inside
|
|
1770
|
+
* `inputSchema()`.
|
|
1771
|
+
*/
|
|
1159
1772
|
declare const normalizeSchema: <S extends TSchema, O>(schema: S, normalize: (value: Static<S>) => O) => TUnsafe<O> & WireType<SchemaInput<S>> & (S extends TOptional<TSchema> ? {
|
|
1160
1773
|
[OptionalKind]: 'Optional';
|
|
1161
1774
|
} : Record<never, never>) & (S extends {
|
|
@@ -1163,7 +1776,10 @@ declare const normalizeSchema: <S extends TSchema, O>(schema: S, normalize: (val
|
|
|
1163
1776
|
} ? {
|
|
1164
1777
|
default: D;
|
|
1165
1778
|
} : Record<never, never>);
|
|
1166
|
-
/**
|
|
1779
|
+
/**
|
|
1780
|
+
* Decodes a field with `transform` once its value passes `schema`: the wire sends what `schema` checks, and
|
|
1781
|
+
* the handler receives what `transform` returns. Runs inside `inputSchema()`.
|
|
1782
|
+
*/
|
|
1167
1783
|
declare const transformSchema: <S extends TSchema, O>(schema: S, transform: (value: Static<S>) => O) => TUnsafe<O> & WireType<SchemaInput<S>> & (S extends TOptional<TSchema> ? {
|
|
1168
1784
|
[OptionalKind]: 'Optional';
|
|
1169
1785
|
} : Record<never, never>) & (S extends {
|
|
@@ -1184,15 +1800,18 @@ declare const inspectSchema: <S extends TSchema>(schema: S, inspect: (value: Sta
|
|
|
1184
1800
|
addIssue: (issue: SchemaIssue) => void;
|
|
1185
1801
|
}) => void) => S;
|
|
1186
1802
|
/**
|
|
1187
|
-
* Refuses a value the schema admits when `predicate` rejects it, with `
|
|
1188
|
-
*
|
|
1803
|
+
* Refuses a value the schema admits when `predicate` rejects it, with a `custom` issue whose message and path
|
|
1804
|
+
* `detail` gives (`Invalid value` at the field by default). Runs inside `inputSchema()`.
|
|
1189
1805
|
*/
|
|
1190
1806
|
declare const refineSchema: <S extends TSchema>(schema: S, predicate: (value: Static<S>) => unknown, detail?: string | {
|
|
1191
1807
|
message?: string;
|
|
1192
1808
|
error?: string;
|
|
1193
1809
|
path?: (string | number)[];
|
|
1194
1810
|
}) => S;
|
|
1195
|
-
/**
|
|
1811
|
+
/**
|
|
1812
|
+
* A URL, of at most `maxLength` characters when given, whose protocol (without its colon, such as `https`)
|
|
1813
|
+
* and, optionally, hostname match the given patterns. Runs inside `inputSchema()`.
|
|
1814
|
+
*/
|
|
1196
1815
|
declare const urlSchema: (options: {
|
|
1197
1816
|
protocol: RegExp;
|
|
1198
1817
|
hostname?: RegExp;
|
|
@@ -1225,7 +1844,8 @@ type Checked<S extends TSchema> = {
|
|
|
1225
1844
|
/**
|
|
1226
1845
|
* Reads untrusted data — a stored record, a provider or model answer — through its schema's owner
|
|
1227
1846
|
* 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.
|
|
1847
|
+
* dropped. A refusal carries every issue with its path; nothing is coerced. An owner codec that fails
|
|
1848
|
+
* throws what it threw.
|
|
1229
1849
|
*/
|
|
1230
1850
|
declare function checkSchema<S extends TSchema>(schema: S, input: unknown): Checked<S>;
|
|
1231
1851
|
/** `checkSchema`, throwing its SchemaValidationError on refusal. */
|
|
@@ -1242,8 +1862,10 @@ declare const PageInfoSchema: TObject<{
|
|
|
1242
1862
|
/** How to reach a list's neighboring pages. */
|
|
1243
1863
|
type PageInfo = Static<typeof PageInfoSchema>;
|
|
1244
1864
|
/**
|
|
1245
|
-
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25
|
|
1246
|
-
* A list whose items are costly lowers the maximum:
|
|
1865
|
+
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25, or the maximum when it is lower)
|
|
1866
|
+
* when the caller sends none. A list whose items are costly lowers the maximum:
|
|
1867
|
+
* `{ ...PageQueryFields, limit: pageLimit({ maximum: 20 }) }`. A default outside 1 to the maximum, or a
|
|
1868
|
+
* value that is not an integer, throws a TypeError.
|
|
1247
1869
|
*/
|
|
1248
1870
|
declare function pageLimit(options?: {
|
|
1249
1871
|
maximum?: number;
|
|
@@ -1251,7 +1873,10 @@ declare function pageLimit(options?: {
|
|
|
1251
1873
|
}): import("@sinclair/typebox").TInteger & {
|
|
1252
1874
|
default: number;
|
|
1253
1875
|
};
|
|
1254
|
-
/**
|
|
1876
|
+
/**
|
|
1877
|
+
* The query fields of a list, spread into its input beside its own filters: an optional opaque `cursor`, a
|
|
1878
|
+
* `direction` (`forward` by default, or `backward`) and a `limit` (`pageLimit()`).
|
|
1879
|
+
*/
|
|
1255
1880
|
declare const PageQueryFields: {
|
|
1256
1881
|
cursor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
1257
1882
|
direction: import("@sinclair/typebox").TUnion<[TLiteral<"forward">, TLiteral<"backward">]> & {
|
|
@@ -1279,9 +1904,9 @@ interface Page<Item> {
|
|
|
1279
1904
|
pageInfo: PageInfo;
|
|
1280
1905
|
}
|
|
1281
1906
|
/**
|
|
1282
|
-
* The output of a list of `item`, named by `$id` (`AppointmentPage`)
|
|
1283
|
-
*
|
|
1284
|
-
* one suffixed `_2`.
|
|
1907
|
+
* The output of a list of `item`, named by `$id` (`AppointmentPage`), a PascalCase name of up to 128
|
|
1908
|
+
* characters; any other throws a TypeError. Give each list its own name and use it for that list only: two
|
|
1909
|
+
* different shapes under one `$id` become two components, the second one suffixed `_2`.
|
|
1285
1910
|
*/
|
|
1286
1911
|
declare function Page<Item extends TSchema>(item: Item, options: {
|
|
1287
1912
|
$id: string;
|
|
@@ -1294,28 +1919,34 @@ declare const PhoneNumberSchema: TString;
|
|
|
1294
1919
|
declare const HttpsUrlSchema: TString;
|
|
1295
1920
|
/** A `#rrggbb` color, named `HexColor`. */
|
|
1296
1921
|
declare const HexColorSchema: TString;
|
|
1297
|
-
/** What
|
|
1922
|
+
/** What a delete answers: the deleted resource's id and `deleted: true`, named `DeletedObject`. */
|
|
1298
1923
|
declare const DeletedObjectSchema: import("@sinclair/typebox").TObject<{
|
|
1299
1924
|
id: TString;
|
|
1300
1925
|
deleted: import("@sinclair/typebox").TLiteral<true>;
|
|
1301
1926
|
}>;
|
|
1302
1927
|
/** What a `delete` answers: the id and `deleted: true`. */
|
|
1303
1928
|
type DeletedObject = Static<typeof DeletedObjectSchema>;
|
|
1304
|
-
/**
|
|
1929
|
+
/**
|
|
1930
|
+
* A link that grants access by itself until it expires, such as a file download: its HTTPS `url` and its
|
|
1931
|
+
* `expiresAt` date-time, named `SignedUrl`.
|
|
1932
|
+
*/
|
|
1305
1933
|
declare const SignedUrlSchema: import("@sinclair/typebox").TObject<{
|
|
1306
1934
|
url: TString;
|
|
1307
1935
|
expiresAt: TString;
|
|
1308
1936
|
}>;
|
|
1309
1937
|
/** A URL that grants access by itself, and when it expires. */
|
|
1310
1938
|
type SignedUrl = Static<typeof SignedUrlSchema>;
|
|
1311
|
-
/** Another resource, by its id and the name people know it by
|
|
1939
|
+
/** Another resource, by its id and the name people know it by, named `NamedReference`. */
|
|
1312
1940
|
declare const NamedReferenceSchema: import("@sinclair/typebox").TObject<{
|
|
1313
1941
|
id: TString;
|
|
1314
1942
|
name: TString;
|
|
1315
1943
|
}>;
|
|
1316
1944
|
/** Another resource, by id and name. */
|
|
1317
1945
|
type NamedReference = Static<typeof NamedReferenceSchema>;
|
|
1318
|
-
/**
|
|
1946
|
+
/**
|
|
1947
|
+
* A postal address, shaped as FHIR `Address` (its lines, city, state, postal code, ISO 3166-1 alpha-2 country
|
|
1948
|
+
* code and use), every field optional, named `PostalAddress`.
|
|
1949
|
+
*/
|
|
1319
1950
|
declare const PostalAddressSchema: import("@sinclair/typebox").TObject<{
|
|
1320
1951
|
city: import("@sinclair/typebox").TOptional<TString>;
|
|
1321
1952
|
countryCode: import("@sinclair/typebox").TOptional<TString>;
|
|
@@ -1336,6 +1967,17 @@ declare const EmptyInputSchema: import("@sinclair/typebox").TObject<{}>;
|
|
|
1336
1967
|
declare const OrganizationIdSchema: import("@sinclair/typebox").TString;
|
|
1337
1968
|
/** A lowercase RFC 9562 UUID of version 1 to 8, named `Uuid`. */
|
|
1338
1969
|
declare const UuidSchema: import("@sinclair/typebox").TString;
|
|
1970
|
+
/**
|
|
1971
|
+
* The principal a verified Access application token grants under `policy.access`. A person, whose token
|
|
1972
|
+
* names them in `sub` and carries no `common_name`, acts as `sub` (never as their email) through a `human`
|
|
1973
|
+
* client, the application's audience, and holds `access.people`. A service token, whose token has an empty
|
|
1974
|
+
* `sub` and its client id as `common_name`, acts as that client id through a `machine` client of the same
|
|
1975
|
+
* id, and holds what `access.services` lists under it, else nothing. Each acts in `access.organizationId`, or
|
|
1976
|
+
* in the organization the claim `claims.organization` holds. Anything else is refused as `UNAUTHORIZED`: a
|
|
1977
|
+
* token whose `type` is not `app` (an Access organization token, for one), a token that is neither a person's
|
|
1978
|
+
* nor a service token's, an organization missing or malformed or named by both, and a policy without `access`.
|
|
1979
|
+
*/
|
|
1980
|
+
declare function projectAccessToken(claims: unknown, policy: Pick<TokenPolicy, 'audience' | 'access' | 'claims'>): Result<TokenPrincipal, Failure>;
|
|
1339
1981
|
/**
|
|
1340
1982
|
* What a transport receives for one admitted request: the request and its id, the verified caller, the
|
|
1341
1983
|
* application, the operations it may serve, the OpenAPI document, and `invoke`, which runs an operation
|
|
@@ -1356,10 +1998,15 @@ interface TransportContext {
|
|
|
1356
1998
|
authenticated: TokenPrincipal;
|
|
1357
1999
|
/** The application the transport serves: its name, title, version, public origin and MCP configuration. */
|
|
1358
2000
|
application: {
|
|
2001
|
+
/** The service's identifier, which names the MCP server. */
|
|
1359
2002
|
name: string;
|
|
2003
|
+
/** The service's human name. */
|
|
1360
2004
|
title: string;
|
|
2005
|
+
/** The service's version. */
|
|
1361
2006
|
version: string;
|
|
2007
|
+
/** The service's public HTTPS base URL. */
|
|
1362
2008
|
origin: string;
|
|
2009
|
+
/** The MCP server's instructions, guides and skills, when the application configures them. */
|
|
1363
2010
|
mcp?: McpConfiguration;
|
|
1364
2011
|
};
|
|
1365
2012
|
/**
|
|
@@ -1374,18 +2021,25 @@ interface TransportContext {
|
|
|
1374
2021
|
/** The public URL of one of the application's own paths, such as `/openapi.json`, below its base path. */
|
|
1375
2022
|
url: (path: string) => string;
|
|
1376
2023
|
/**
|
|
1377
|
-
* Runs one of `operations` as the verified caller and answers its Result
|
|
1378
|
-
* `NOT_FOUND`, and
|
|
2024
|
+
* Runs one of `operations` through the shared execution path as the verified caller and answers its Result:
|
|
2025
|
+
* an operation not among them fails with `NOT_FOUND`, and one whose scopes the caller lacks with
|
|
2026
|
+
* `FORBIDDEN`.
|
|
1379
2027
|
*/
|
|
1380
2028
|
invoke: (name: string, operation: OperationShape, input: unknown) => Promise<Result<unknown, Failure>>;
|
|
1381
2029
|
/**
|
|
1382
|
-
*
|
|
1383
|
-
* caller's rate limit as a request of its own
|
|
1384
|
-
*
|
|
2030
|
+
* Admits the requests this HTTP request carries beyond its first, such as the rest of a JSON-RPC batch,
|
|
2031
|
+
* each against the caller's rate limit as a request of its own, before any of them runs. Answers the
|
|
2032
|
+
* refusal to send when the limit refuses one, as admission answers a request over the limit; admission
|
|
2033
|
+
* counted the first.
|
|
1385
2034
|
*/
|
|
1386
|
-
|
|
1387
|
-
/**
|
|
1388
|
-
|
|
2035
|
+
admitCarried: (requests: number) => Promise<Response | undefined>;
|
|
2036
|
+
/**
|
|
2037
|
+
* Records a refusal the transport answers itself, such as a call to a tool the caller cannot see, as
|
|
2038
|
+
* admission records the refusals HTTP answers: its code, and the operation when it names one.
|
|
2039
|
+
*/
|
|
2040
|
+
refused: (failure: Failure, operation?: string) => void;
|
|
2041
|
+
/** The request body the transport received, as text; admission read it within the transport's limit. */
|
|
2042
|
+
body: string;
|
|
1389
2043
|
/** The body limit HTTP applies to an operation; a transport holds each invocation to it. */
|
|
1390
2044
|
bodyLimit: (operation: OperationShape) => number;
|
|
1391
2045
|
}
|
|
@@ -1394,7 +2048,10 @@ interface TransportContext {
|
|
|
1394
2048
|
* admits and its handler.
|
|
1395
2049
|
*/
|
|
1396
2050
|
interface HttpTransport {
|
|
1397
|
-
/**
|
|
2051
|
+
/**
|
|
2052
|
+
* The protocol the transport speaks, whatever its path: `mcp` marks the MCP transport, of which a handler
|
|
2053
|
+
* mounts at most one. A transport at `/mcp` counts as the MCP transport either way.
|
|
2054
|
+
*/
|
|
1398
2055
|
protocol?: 'mcp';
|
|
1399
2056
|
/**
|
|
1400
2057
|
* The exact path the transport answers, such as `/mcp`; it stays absolute when the application has a base
|
|
@@ -1419,24 +2076,31 @@ interface HttpTransport {
|
|
|
1419
2076
|
interface RouteContext {
|
|
1420
2077
|
/** The request id echoed in `x-request-id`; use it to correlate diagnostics. */
|
|
1421
2078
|
requestId: string;
|
|
1422
|
-
/**
|
|
2079
|
+
/**
|
|
2080
|
+
* Answers a failure of the application's catalog as the failure envelope, with its status, this request's
|
|
2081
|
+
* id and the given headers: for a refusal the route makes itself. A failure outside the catalog throws a
|
|
2082
|
+
* TypeError, which the handler answers as `INTERNAL_ERROR`.
|
|
2083
|
+
*/
|
|
1423
2084
|
fail: (failure: Failure, headers?: ResponseInit['headers']) => Response;
|
|
1424
|
-
/**
|
|
2085
|
+
/**
|
|
2086
|
+
* Keeps work running after the response, through the runtime's `waitUntil` when the handler has one. Best
|
|
2087
|
+
* effort, never durable.
|
|
2088
|
+
*/
|
|
1425
2089
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
1426
2090
|
}
|
|
1427
2091
|
/**
|
|
1428
|
-
* A plain HTTP route outside token admission, for callers that cannot present a
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
2092
|
+
* A plain HTTP route outside token admission, for callers that cannot present a bearer token: provider
|
|
2093
|
+
* webhooks (signed bodies), signed links, OAuth callbacks. The handler owns authentication completely: it
|
|
2094
|
+
* must verify a signature or token before it treats the request as data. Plain routes share the handler's
|
|
2095
|
+
* diagnostics, request id and response headers (`x-request-id`, `x-content-type-options: nosniff`,
|
|
2096
|
+
* `server-timing`, and `cache-control: private, no-store` unless the route sets its own); they never receive
|
|
2097
|
+
* a principal and are absent from OpenAPI.
|
|
1434
2098
|
*/
|
|
1435
2099
|
type HttpRoute<E> = (request: Request, env: E, context: RouteContext) => Promise<Response>;
|
|
1436
2100
|
/**
|
|
1437
|
-
* Wraps
|
|
1438
|
-
*
|
|
1439
|
-
* `next`
|
|
2101
|
+
* Wraps every request before token admission, once the origin is admitted. It receives a copy of the request
|
|
2102
|
+
* without its body, so it can neither read the body nor change the headers admission reads, and it sees no
|
|
2103
|
+
* principal. `next` runs the rest of the handling, at most once and before the wrapper settles.
|
|
1440
2104
|
*/
|
|
1441
2105
|
type HttpMiddleware<E> = (request: Request, env: E, context: RouteContext, next: () => Promise<Response>) => Promise<Response>;
|
|
1442
2106
|
/**
|
|
@@ -1444,9 +2108,16 @@ type HttpMiddleware<E> = (request: Request, env: E, context: RouteContext, next:
|
|
|
1444
2108
|
* routes and mounts, a base path, a fallback and request hooks.
|
|
1445
2109
|
*/
|
|
1446
2110
|
interface HttpOptions<E = unknown> {
|
|
1447
|
-
/**
|
|
2111
|
+
/**
|
|
2112
|
+
* Request wrappers, run in order around everything after the origin check; an error one throws answers
|
|
2113
|
+
* `INTERNAL_ERROR`. Each entry must be a function.
|
|
2114
|
+
*/
|
|
1448
2115
|
middleware?: readonly HttpMiddleware<E>[];
|
|
1449
|
-
/**
|
|
2116
|
+
/**
|
|
2117
|
+
* The exact HTTPS origins the handler answers, such as `https://notes.example.com`. A request to another
|
|
2118
|
+
* origin answers `NOT_FOUND` before any middleware, hook, route or token check runs. An empty list, or an
|
|
2119
|
+
* origin that is not an exact HTTPS origin, throws at construction.
|
|
2120
|
+
*/
|
|
1450
2121
|
origins?: readonly string[];
|
|
1451
2122
|
/**
|
|
1452
2123
|
* Test seam for the default OAuth verification: returns a token's claims in place of the JWT check; claim
|
|
@@ -1460,27 +2131,49 @@ interface HttpOptions<E = unknown> {
|
|
|
1460
2131
|
annotate?: (operation: string, requestId: string) => void;
|
|
1461
2132
|
/**
|
|
1462
2133
|
* Protocol transports served beside the operations, such as `mcp()`; one per path, and at most one MCP
|
|
1463
|
-
* transport.
|
|
2134
|
+
* transport, which an application with `mcp` configuration requires.
|
|
1464
2135
|
*/
|
|
1465
2136
|
transports?: readonly HttpTransport[];
|
|
1466
2137
|
/**
|
|
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
|
-
*
|
|
2138
|
+
* Plain routes by exact path: absolute paths of unreserved characters. The native paths, paths of the form
|
|
2139
|
+
* `/v<n>/…` below the base path, and every operation or transport path are reserved. A route may sit
|
|
2140
|
+
* beneath a transport's path (a second MCP server at `/mcp/agent-runtime`): the transport answers only its
|
|
2141
|
+
* exact path.
|
|
1471
2142
|
*/
|
|
1472
2143
|
routes?: Readonly<Record<string, HttpRoute<E>>>;
|
|
1473
|
-
/**
|
|
2144
|
+
/**
|
|
2145
|
+
* The path the operations and the native documents (the index, `/openapi.json`, OAuth discovery and, by
|
|
2146
|
+
* default, `/health`) are served below, such as `/api`; transports, plain routes and mounts keep their
|
|
2147
|
+
* absolute paths.
|
|
2148
|
+
*/
|
|
1474
2149
|
basePath?: string;
|
|
1475
|
-
/**
|
|
2150
|
+
/**
|
|
2151
|
+
* The absolute path of the liveness check, which answers a GET without a token with
|
|
2152
|
+
* `{ status: 'ok', service, version }` and probes no dependency; `/health` below the base path by default.
|
|
2153
|
+
*/
|
|
1476
2154
|
healthPath?: string;
|
|
1477
|
-
/**
|
|
2155
|
+
/**
|
|
2156
|
+
* Handlers by path prefix: each answers its prefix and every path below it (`/files` and `/files/a`, never
|
|
2157
|
+
* `/filesystem`), and where mounts nest, the longest prefix answers. A mount may neither contain a native,
|
|
2158
|
+
* operation, transport or plain route path nor sit below a transport or plain route.
|
|
2159
|
+
*/
|
|
1478
2160
|
mounts?: Readonly<Record<string, HttpRoute<E>>>;
|
|
1479
|
-
/**
|
|
2161
|
+
/**
|
|
2162
|
+
* Runs for every request after the middleware and before routing: a response it returns answers the
|
|
2163
|
+
* request, and `null` lets it continue. It sees no principal.
|
|
2164
|
+
*/
|
|
1480
2165
|
before?: (request: Request, env: E, context: RouteContext) => Response | null | Promise<Response | null>;
|
|
1481
|
-
/**
|
|
2166
|
+
/**
|
|
2167
|
+
* Answers a request nothing else claims, in place of `NOT_FOUND`. It never receives a native path or a
|
|
2168
|
+
* path the handler reserves: one below the base path, under `/.well-known` or `/v<n>`, or below a
|
|
2169
|
+
* transport's path.
|
|
2170
|
+
*/
|
|
1482
2171
|
fallback?: HttpRoute<E>;
|
|
1483
|
-
/**
|
|
2172
|
+
/**
|
|
2173
|
+
* Wraps each matched HTTP operation before its token is checked: it receives the request, the env and the
|
|
2174
|
+
* operation's name and effect, and calls `run` once with the env the call then uses, for its token
|
|
2175
|
+
* resolution and as its handler's `env`. A second call to `run` throws. MCP requests do not reach it.
|
|
2176
|
+
*/
|
|
1484
2177
|
aroundOperation?: (request: Request, env: E, operation: Readonly<{
|
|
1485
2178
|
name: string;
|
|
1486
2179
|
effect: OperationShape['effect'];
|
|
@@ -1489,7 +2182,10 @@ interface HttpOptions<E = unknown> {
|
|
|
1489
2182
|
/**
|
|
1490
2183
|
* Serves an application over HTTP as one function, `(request, env, background?) => Promise<Response>`: its
|
|
1491
2184
|
* operations at their routes, the OpenAPI document as JSON and YAML, OAuth discovery, `/health`, transports
|
|
1492
|
-
* such as MCP, plain routes and mounts.
|
|
2185
|
+
* such as MCP, plain routes and mounts. Every response but a protocol upgrade (101) carries `x-request-id`,
|
|
2186
|
+
* `x-content-type-options: nosniff`, `server-timing` and `cache-control: private, no-store`, unless a plain
|
|
2187
|
+
* route, mount, fallback or `before` hook sets its own `cache-control`. Construction throws a TypeError for a
|
|
2188
|
+
* path two of them would claim, and for an option, token scheme or token source it cannot serve.
|
|
1493
2189
|
*/
|
|
1494
2190
|
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
2191
|
/**
|
|
@@ -1498,13 +2194,26 @@ declare function createHttpHandler<E, C, O extends Record<string, OperationShape
|
|
|
1498
2194
|
*/
|
|
1499
2195
|
/** Whether a byte operation may read one of its input fields from this header. */
|
|
1500
2196
|
declare function isInputHeaderName(header: string): boolean;
|
|
1501
|
-
/**
|
|
2197
|
+
/**
|
|
2198
|
+
* The parameter names of a declared route template, in order. A template is versioned (`/v1/…`) with at least
|
|
2199
|
+
* one segment after the version, each fixed or a complete `{parameter}` with a unique, safe name; anything
|
|
2200
|
+
* else throws a TypeError. It reads declared templates, never a request's path.
|
|
2201
|
+
*/
|
|
1502
2202
|
declare function operationPathParameters(path: string): string[];
|
|
1503
|
-
/**
|
|
2203
|
+
/**
|
|
2204
|
+
* One path segment, percent-decoded, or null when it does not decode or decodes to a value
|
|
2205
|
+
* `isPathParameterValue` refuses, so decoding cannot change which route a path reaches.
|
|
2206
|
+
*/
|
|
1504
2207
|
declare function decodePathParameter(segment: string): string | null;
|
|
1505
|
-
/**
|
|
2208
|
+
/**
|
|
2209
|
+
* Whether a value can be a path parameter: a nonempty string other than `.` and `..`, without a slash, a
|
|
2210
|
+
* backslash, a control character or a lone surrogate, so it stays one segment when encoded.
|
|
2211
|
+
*/
|
|
1506
2212
|
declare function isPathParameterValue(value: unknown): value is string;
|
|
1507
|
-
/**
|
|
2213
|
+
/**
|
|
2214
|
+
* What the router reads of a definition: its method and path template. Its other fields come back unchanged
|
|
2215
|
+
* in a match; checking a request's input is not the router's work.
|
|
2216
|
+
*/
|
|
1508
2217
|
interface HttpRouteDefinition {
|
|
1509
2218
|
/**
|
|
1510
2219
|
* The method and versioned path template to route, such as `GET /v1/notes/{noteId}`; a definition without
|
|
@@ -1523,15 +2232,18 @@ interface HttpRouteMatch<D> {
|
|
|
1523
2232
|
parameters: Readonly<Record<string, string>>;
|
|
1524
2233
|
}
|
|
1525
2234
|
/**
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
2235
|
+
* The router for a set of definitions: `match(method, path)` finds the one route a request reaches, with its
|
|
2236
|
+
* decoded parameters, and `ownsPath(path)` says whether any route answers a path. A definition without `http`
|
|
2237
|
+
* is skipped. Construction throws a TypeError for an unsupported method, a malformed template, a duplicate
|
|
2238
|
+
* route, or two templates that could match the same path. A fixed route is one map lookup; templates compile
|
|
2239
|
+
* into states with one transition per segment, so matching never scans the routes.
|
|
1528
2240
|
*/
|
|
1529
2241
|
declare function createHttpRouteResolver<D extends HttpRouteDefinition>(definitions: readonly D[]): {
|
|
1530
2242
|
match: (method: string, path: string) => HttpRouteMatch<D> | null;
|
|
1531
|
-
/**
|
|
2243
|
+
/** Whether any route answers a declared path, so a transport cannot claim an operation's path. */
|
|
1532
2244
|
ownsPath(path: string): boolean;
|
|
1533
2245
|
};
|
|
1534
|
-
/**
|
|
2246
|
+
/** Every reason a bounded read can fail with: the values of a body failure's `data.reason`. */
|
|
1535
2247
|
declare const HTTP_BODY_FAILURES: readonly ['too_large', 'invalid_length', 'invalid_json', 'invalid_utf8', 'unexpected_content_type', 'aborted', 'read_failed'];
|
|
1536
2248
|
/** Why a body could not be read. */
|
|
1537
2249
|
type HttpBodyFailureReason = (typeof HTTP_BODY_FAILURES)[number];
|
|
@@ -1544,160 +2256,106 @@ interface HttpBodyFailure extends Failure<{
|
|
|
1544
2256
|
}
|
|
1545
2257
|
/** How much of a body to read, and until when. */
|
|
1546
2258
|
interface BodyReadOptions {
|
|
1547
|
-
/**
|
|
2259
|
+
/**
|
|
2260
|
+
* The most body bytes to read, a positive safe integer; a longer body fails as `too_large`, and any other
|
|
2261
|
+
* value throws a RangeError.
|
|
2262
|
+
*/
|
|
1548
2263
|
maxBytes: number;
|
|
1549
|
-
/**
|
|
2264
|
+
/**
|
|
2265
|
+
* Aborts the read, which then fails as `aborted`. For a response, pass the signal its `fetch` used, so one
|
|
2266
|
+
* deadline covers the request and its body.
|
|
2267
|
+
*/
|
|
1550
2268
|
signal?: AbortSignal;
|
|
1551
2269
|
}
|
|
1552
2270
|
/** What a body is read from: a request or a response. */
|
|
1553
2271
|
type BodySource = Pick<Request, 'body' | 'headers'>;
|
|
1554
2272
|
/**
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
2273
|
+
* Reads a request's or a response's body as bytes, at most `maxBytes` of them, chunked bodies included, and
|
|
2274
|
+
* answers them unchanged, as a signature check needs them; an absent body is no bytes. A `content-length`
|
|
2275
|
+
* that is malformed or above the limit is refused before reading. Every expected failure is a result
|
|
2276
|
+
* (`too_large`, `invalid_length`, `aborted` or `read_failed`), and a refused body is cancelled without
|
|
2277
|
+
* waiting for the other side.
|
|
1558
2278
|
*/
|
|
1559
2279
|
declare function readBodyBytes(source: BodySource, options: BodyReadOptions): Promise<Result<Uint8Array<ArrayBuffer>, HttpBodyFailure>>;
|
|
1560
|
-
/**
|
|
2280
|
+
/**
|
|
2281
|
+
* Reads a body as `readBodyBytes` does and decodes it as UTF-8. Invalid UTF-8 fails as `invalid_utf8`,
|
|
2282
|
+
* unless `fatalUtf8: false` replaces it with U+FFFD, as a provider that signs its decoded text may require.
|
|
2283
|
+
*/
|
|
1561
2284
|
declare function readBodyText(source: BodySource, options: BodyReadOptions & {
|
|
1562
2285
|
fatalUtf8?: boolean;
|
|
1563
2286
|
}): Promise<Result<string, HttpBodyFailure>>;
|
|
1564
|
-
/**
|
|
2287
|
+
/**
|
|
2288
|
+
* Whether a Content-Type value is `application/json` or a structured `+json` type such as
|
|
2289
|
+
* `application/problem+json`, whatever its parameters and case.
|
|
2290
|
+
*/
|
|
1565
2291
|
declare function isJsonMediaType(value: string | null): boolean;
|
|
1566
|
-
/**
|
|
2292
|
+
/**
|
|
2293
|
+
* Reads a JSON body within `maxBytes` and parses it, as `unknown` for a schema to check. A Content-Type other
|
|
2294
|
+
* than `application/json` (or any `+json` type, with `allowJsonSuffix`) fails as `unexpected_content_type`
|
|
2295
|
+
* before anything is read, and text that does not parse as `invalid_json`; the other failures are
|
|
2296
|
+
* `readBodyText`'s.
|
|
2297
|
+
*/
|
|
1567
2298
|
declare function readJsonBody(source: Pick<Request, 'body' | 'headers'>, options: {
|
|
1568
2299
|
maxBytes: number;
|
|
1569
2300
|
signal?: AbortSignal;
|
|
1570
2301
|
allowJsonSuffix?: boolean;
|
|
1571
2302
|
}): Promise<Result<unknown, HttpBodyFailure>>;
|
|
1572
|
-
/**
|
|
2303
|
+
/**
|
|
2304
|
+
* Reads a response's JSON body as `readJsonBody` does, accepting any `+json` type: a 204 or 205 reads as
|
|
2305
|
+
* `null`, and a signal already aborted fails as `aborted` without reading. Pass the signal the `fetch` used,
|
|
2306
|
+
* so one deadline covers the request and its body.
|
|
2307
|
+
*/
|
|
1573
2308
|
declare function readJsonResponse(response: Response, options: {
|
|
1574
2309
|
maxBytes: number;
|
|
1575
2310
|
signal: AbortSignal;
|
|
1576
2311
|
}): Promise<Result<unknown, HttpBodyFailure>>;
|
|
1577
|
-
/**
|
|
2312
|
+
/**
|
|
2313
|
+
* The seconds a `Retry-After` value asks a client to wait, as delta seconds or as an HTTP date relative to
|
|
2314
|
+
* `nowMs`, rounded up and held between 0 and `maximum` (an hour by default); undefined when the value is
|
|
2315
|
+
* absent or unreadable. It is a hint: it never makes repeating a write safe.
|
|
2316
|
+
*/
|
|
1578
2317
|
declare function retryAfterSeconds(value: string | null, nowMs: number, maximum?: number): number | undefined;
|
|
1579
2318
|
/**
|
|
1580
2319
|
* The document the origin serves at `/openapi.json`: every public operation that declares an HTTP route,
|
|
1581
|
-
* never an internal one
|
|
1582
|
-
*
|
|
2320
|
+
* never an internal one, under one tag per group. Each request body, success envelope and failure is a named
|
|
2321
|
+
* component, which a generated client names its types after; each operation also carries its scopes,
|
|
2322
|
+
* effect, limits in force, MCP tool hints and native RPC as `x-*` extensions.
|
|
1583
2323
|
*
|
|
1584
2324
|
* Every schema reference in it is a local `#/components/schemas/<name>` pointer: the `$id`-named
|
|
1585
2325
|
* schemas of its paths and components (TypeBox Recursive/Ref) become components, as `bundleSchemas`
|
|
1586
|
-
* describes.
|
|
2326
|
+
* describes. A schema `$id` that takes the name of a component the document writes itself, and a component
|
|
2327
|
+
* named as a generator names an operation's own types, such as `CreateNoteResponse`, throw a TypeError.
|
|
1587
2328
|
*/
|
|
1588
2329
|
declare function createOpenApi<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>, options?: {
|
|
1589
|
-
/**
|
|
2330
|
+
/**
|
|
2331
|
+
* Adds an adapter's `x-` extensions to each documented operation, from its name and declaration; a key
|
|
2332
|
+
* without the `x-` prefix throws a TypeError. Schemas in the extensions are bundled into the document's
|
|
2333
|
+
* components with the rest.
|
|
2334
|
+
*/
|
|
1590
2335
|
operationExtensions?: (name: string, operation: OperationShape) => Record<`x-${string}`, unknown>;
|
|
1591
2336
|
}): Record<string, unknown>;
|
|
1592
2337
|
/**
|
|
1593
|
-
* The
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
2338
|
+
* The document of the operations an application serves over native RPC, which another service binds to:
|
|
2339
|
+
* each operation that declares `rpc`, internal ones and tools included, as `POST /rpc/<name>` whose body is
|
|
2340
|
+
* the operation's whole input, with its answer and failures named as in the HTTP document. No HTTP route
|
|
2341
|
+
* answers these paths: each names a method of the Worker's `Service` entrypoint, which a Service Binding
|
|
2342
|
+
* calls with the caller's principal. `maximus openapi` writes it to `rpc.openapi.json`, and a caller's
|
|
2343
|
+
* `services` option types its binding from it.
|
|
1596
2344
|
*/
|
|
1597
|
-
declare function
|
|
1598
|
-
/** Checks the application, then hands it back unchanged. */
|
|
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.
|
|
1647
|
-
*/
|
|
1648
|
-
type RpcMethods<Ops extends Record<string, OperationShape>> = { [K in keyof Ops as Ops[K] extends {
|
|
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
|
-
}
|
|
2345
|
+
declare function createRpcOpenApi<E, C, O extends Record<string, OperationShape>>(manifest: AppManifest<E, C, O>): Record<string, unknown>;
|
|
1676
2346
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
2347
|
+
* The execution path every transport shares: checks that the caller may run the operation (its scopes when
|
|
2348
|
+
* `authority` is given, its actor kind, and `authority` itself when the operation has conditional scopes),
|
|
2349
|
+
* decodes the input, prepares the context, runs the middleware and the handler, then checks the result
|
|
2350
|
+
* against the catalog, the declared failures, the output schema and the output limit. A refused caller
|
|
2351
|
+
* answers `FORBIDDEN` and a refused input `INVALID_INPUT`. An unexpected error becomes `INTERNAL_ERROR`,
|
|
2352
|
+
* reported while telemetry is on, and is never thrown.
|
|
1679
2353
|
*/
|
|
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
|
-
}
|
|
2354
|
+
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
2355
|
/**
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
2356
|
+
* Checks an application against every rule `.build()` enforces, then hands it back unchanged; a refusal is a
|
|
2357
|
+
* TypeError. Curried, so `Env` and `C` can be given explicitly while the operations' types are inferred from
|
|
2358
|
+
* the argument.
|
|
1701
2359
|
*/
|
|
1702
|
-
declare function
|
|
1703
|
-
export {
|
|
2360
|
+
declare function defineApp<Env, C>(): <const Ops extends Record<string, OperationShape>>(manifest: AppManifest<Env, C, Ops>) => AppManifest<Env, C, Ops>;
|
|
2361
|
+
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 };
|