@arbol-ai/maximus 8.0.1 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics/analytics.d.ts +16 -16
- package/dist/analytics/analytics.js +4 -4
- package/dist/body.d.ts +2 -2
- package/dist/body.js +2 -2
- package/dist/capture/index.d.ts +37 -0
- package/dist/capture/index.js +181 -0
- package/dist/chunks/{define-app-x7uY70_1.js → define-app-CQpWqqqE.js} +44 -14
- package/dist/chunks/delay-BsKQP_lF.js +12 -0
- package/dist/chunks/{json-B14evE6-.js → destination-DIkn8W6K.js} +65 -1
- package/dist/chunks/digest-C51F1bhA.js +12 -0
- package/dist/chunks/{errors-C5w9WY1l.js → errors-BoutSmiy.js} +2 -3
- package/dist/chunks/execution-Bpq6s4nA.js +265 -0
- package/dist/chunks/{generate-C-9FKW0o.js → generate-Dg88LzLU.js} +1 -1
- package/dist/chunks/{handler-iebR-urt.js → handler-DSpyrWc-.js} +6 -2
- package/dist/chunks/{http-layout-DS8DnPyu.js → http-layout-BcYH4I2w.js} +1 -1
- package/dist/chunks/{http-paths-DMBxwpp6.js → http-paths-D043DkJv.js} +50 -81
- package/dist/chunks/http-routes-B6tCsnxB.js +29 -0
- package/dist/chunks/{openapi-CeolxIqa.js → openapi-D2rds7vy.js} +32 -130
- package/dist/chunks/{openapi-file-Bz9FRaE6.js → openapi-file-BK8zET5U.js} +24 -6
- package/dist/chunks/{pages-iZTvFs5a.js → pages-B7ysoFAM.js} +1 -1
- package/dist/chunks/result-CF4OzG9O.js +29 -0
- package/dist/chunks/{runtime-D94vx21X.js → runtime-CGtS2rOb.js} +165 -11
- package/dist/chunks/schemas-_UJcx_uY.js +813 -0
- package/dist/chunks/{server-Bzf1Q1_4.js → server-CVhTLNj2.js} +38 -101
- package/dist/chunks/{src-CPrJpbOM.js → src-D67OfW9B.js} +94 -27
- package/dist/chunks/tasks-C873C3le.js +100 -0
- package/dist/chunks/tasks-DYdY-dBI.js +267 -0
- package/dist/chunks/{telemetry-C3LfZcOB.js → telemetry-BtxJh69Q.js} +4 -4
- package/dist/chunks/{types-DTIuIEJ-.d.ts → types-BfGa2aJT.d.ts} +537 -124
- package/dist/chunks/validation-CpzAxj2_.js +201 -0
- package/dist/chunks/{workers-types-BRk_Xa_5.d.ts → workers-types-Cxf-5cH7.d.ts} +6 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- 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 +2 -2
- package/dist/internals.js +6 -6
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/tasks.d.ts +33 -0
- package/dist/mcp/tasks.js +3 -0
- package/dist/project/config.d.ts +2 -2
- package/dist/project/config.js +3 -2
- package/dist/project/index.d.ts +2 -2
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.js +3 -3
- package/dist/standard-failures.d.ts +1 -1
- package/dist/tooling/cli.js +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +15 -9
- package/dist/webhooks.d.ts +13 -2
- package/dist/webhooks.js +38 -1
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +15 -3
- package/skills/maximus/SKILL.md +14 -4
- package/skills/maximus/references/project.md +4 -0
- package/skills/maximus/references/routes-and-tools.md +11 -1
- package/templates/project/CLAUDE.md.template +3 -3
- package/templates/project/README.md.template +1 -0
- package/templates/project/tsconfig.json.template +1 -0
- package/dist/chunks/execution-rOiLo8VG.js +0 -84
- package/dist/chunks/result-CKgZHrnj.js +0 -56
- package/dist/chunks/schemas-p_aRcMC1.js +0 -227
- package/dist/chunks/validation-fTohBT6R.js +0 -420
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jr as Failure, yr as Result } from "./chunks/types-BfGa2aJT.js";
|
|
2
2
|
/** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
|
|
3
3
|
export declare const WEBHOOK_SIGNATURE_FAILURES: readonly ['missing', 'malformed', 'expired', 'mismatch'];
|
|
4
4
|
/** Why a webhook signature was refused. */
|
|
@@ -66,4 +66,15 @@ export declare function verifyStandardWebhook(options: {
|
|
|
66
66
|
}): Promise<Result<{
|
|
67
67
|
id: string;
|
|
68
68
|
timestamp: number;
|
|
69
|
-
}, WebhookSignatureFailure>>;
|
|
69
|
+
}, WebhookSignatureFailure>>;
|
|
70
|
+
/**
|
|
71
|
+
* Signs a Standard Webhooks delivery with the specification's own `standardwebhooks` package: the headers to
|
|
72
|
+
* send with `payload`, exactly as given. The secret is the `whsec_<base64>` value the receiver verifies with,
|
|
73
|
+
* and `id` names the delivery, which the receiver keeps as its idempotency key.
|
|
74
|
+
*/
|
|
75
|
+
export declare function signStandardWebhook(options: {
|
|
76
|
+
id: string;
|
|
77
|
+
now?: () => number;
|
|
78
|
+
payload: string;
|
|
79
|
+
secret: string;
|
|
80
|
+
}): Record<'webhook-id' | 'webhook-signature' | 'webhook-timestamp', string>;
|
package/dist/webhooks.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
+
import { Webhook } from "standardwebhooks";
|
|
2
|
+
|
|
1
3
|
// src/webhooks.ts
|
|
4
|
+
/**
|
|
5
|
+
* `@arbol-ai/maximus/webhooks`: webhook signature verification for the three schemes providers use, and
|
|
6
|
+
* {@link signStandardWebhook}, which signs a delivery as the Standard Webhooks specification does.
|
|
7
|
+
*
|
|
8
|
+
* - {@link verifyHmacSignature}: an HMAC-SHA256 of the raw body, hex or base64,
|
|
9
|
+
* in one header (the common `X-…-Signature` / `X-Hub-Signature-256` scheme).
|
|
10
|
+
* - {@link verifyTimestampedSignature}: `t=<unix>,v1=<hex>` headers signing
|
|
11
|
+
* `<t>.<body>` (the Stripe-style scheme; some providers label it `v0`).
|
|
12
|
+
* - {@link verifyStandardWebhook}: the Standard Webhooks specification
|
|
13
|
+
* (`webhook-id`, `webhook-timestamp`, `webhook-signature: v1,<base64> …`),
|
|
14
|
+
* used by many webhook platforms; `svix-*` header names are accepted too.
|
|
15
|
+
*
|
|
16
|
+
* Every comparison runs through `crypto.subtle.verify`, so there is no userland
|
|
17
|
+
* timing leak. Timestamps are checked in both directions (a signed request
|
|
18
|
+
* from the future is as suspicious as a replayed one). Call these on the raw
|
|
19
|
+
* body, before parsing it; a failure carries only a closed reason, never the
|
|
20
|
+
* body, a header value or the secret. A missing or empty secret throws a
|
|
21
|
+
* TypeError: it is the deployment's mistake, not the sender's.
|
|
22
|
+
*
|
|
23
|
+
* Sources: https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md,
|
|
24
|
+
* https://docs.stripe.com/webhooks#verify-manually.
|
|
25
|
+
*/
|
|
2
26
|
/** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
|
|
3
27
|
const WEBHOOK_SIGNATURE_FAILURES = [
|
|
4
28
|
"missing",
|
|
@@ -171,5 +195,18 @@ async function verifyStandardWebhook(options) {
|
|
|
171
195
|
};
|
|
172
196
|
return failure("mismatch");
|
|
173
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Signs a Standard Webhooks delivery with the specification's own `standardwebhooks` package: the headers to
|
|
200
|
+
* send with `payload`, exactly as given. The secret is the `whsec_<base64>` value the receiver verifies with,
|
|
201
|
+
* and `id` names the delivery, which the receiver keeps as its idempotency key.
|
|
202
|
+
*/
|
|
203
|
+
function signStandardWebhook(options) {
|
|
204
|
+
const timestamp = new Date(options.now?.() ?? Date.now());
|
|
205
|
+
return {
|
|
206
|
+
"webhook-id": options.id,
|
|
207
|
+
"webhook-timestamp": String(Math.floor(timestamp.getTime() / 1e3)),
|
|
208
|
+
"webhook-signature": new Webhook(requireSecret(options.secret)).sign(options.id, timestamp, options.payload)
|
|
209
|
+
};
|
|
210
|
+
}
|
|
174
211
|
|
|
175
|
-
export { DEFAULT_TOLERANCE_SECONDS, MAX_SIGNATURES, WEBHOOK_SIGNATURE_FAILURES, verifyHmacSignature, verifyStandardWebhook, verifyTimestampedSignature, webhookSignatureFailure };
|
|
212
|
+
export { DEFAULT_TOLERANCE_SECONDS, MAX_SIGNATURES, WEBHOOK_SIGNATURE_FAILURES, signStandardWebhook, verifyHmacSignature, verifyStandardWebhook, verifyTimestampedSignature, webhookSignatureFailure };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-
|
|
1
|
+
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-Cxf-5cH7.js";
|
|
2
2
|
export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
|
package/dist/workers/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arbol-ai/maximus",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, configured in vite.config.ts, with its OpenAPI and CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -91,10 +91,18 @@
|
|
|
91
91
|
"types": "./dist/mcp/index.d.ts",
|
|
92
92
|
"import": "./dist/mcp/index.js"
|
|
93
93
|
},
|
|
94
|
+
"./mcp/tasks": {
|
|
95
|
+
"types": "./dist/mcp/tasks.d.ts",
|
|
96
|
+
"import": "./dist/mcp/tasks.js"
|
|
97
|
+
},
|
|
94
98
|
"./analytics": {
|
|
95
99
|
"types": "./dist/analytics/analytics.d.ts",
|
|
96
100
|
"import": "./dist/analytics/analytics.js"
|
|
97
101
|
},
|
|
102
|
+
"./capture": {
|
|
103
|
+
"types": "./dist/capture/index.d.ts",
|
|
104
|
+
"import": "./dist/capture/index.js"
|
|
105
|
+
},
|
|
98
106
|
"./postgres": {
|
|
99
107
|
"types": "./dist/postgres/index.d.ts",
|
|
100
108
|
"import": "./dist/postgres/index.js"
|
|
@@ -130,12 +138,16 @@
|
|
|
130
138
|
},
|
|
131
139
|
"dependencies": {
|
|
132
140
|
"@modelcontextprotocol/server": "2.4.0",
|
|
133
|
-
"@
|
|
141
|
+
"@scalar/openapi-parser": "0.29.20",
|
|
134
142
|
"ajv-formats": "3.0.1",
|
|
135
|
-
"jose": "6.2.13"
|
|
143
|
+
"jose": "6.2.13",
|
|
144
|
+
"rou3": "1.0.0",
|
|
145
|
+
"standardwebhooks": "1.1.1",
|
|
146
|
+
"typebox": "1.4.5"
|
|
136
147
|
},
|
|
137
148
|
"devDependencies": {
|
|
138
149
|
"@cloudflare/vite-plugin": "2.0.0-beta.v.5",
|
|
150
|
+
"@modelcontextprotocol/ext-tasks": "0.2.3",
|
|
139
151
|
"@types/pg": "8.23.1",
|
|
140
152
|
"ajv": "8.20.0",
|
|
141
153
|
"cf": "1.0.0-beta.23",
|
package/skills/maximus/SKILL.md
CHANGED
|
@@ -23,6 +23,7 @@ context.ts export default defineContext(({ env, principa
|
|
|
23
23
|
errors.ts export default defineErrors({ … }): the service's own failure codes
|
|
24
24
|
auth.ts export default defineAuth({ resolve }): tokens the service verifies itself
|
|
25
25
|
telemetry.ts export default defineTelemetry({ observers }): observers such as analytics()
|
|
26
|
+
capture.ts export default defineCapture({ sink, payloads, dimensions }): a record of every call
|
|
26
27
|
middleware/ defineMiddleware (before admission) or defineOperationMiddleware (after it)
|
|
27
28
|
pages/ crons/ queues/ email/ Public pages and webhooks (pages/webhooks/x.post.ts), event handlers
|
|
28
29
|
durable-objects/ Durable Object classes, one per file
|
|
@@ -65,7 +66,7 @@ each one.
|
|
|
65
66
|
| `bunx maximus gen route get /v1/notes/{noteId} --tool get_note` | Writes `routes/v1/notes/[noteId].get.ts`, which is also the MCP tool `get_note`. |
|
|
66
67
|
| `bunx maximus gen tool summarize-notes` | Writes `mcp/tools/summarize-notes.ts`, the tool `summarize_notes`. |
|
|
67
68
|
| `bunx maximus prepare` | Writes `.maximus/` for production, or with `--mode development` as `vp dev` does. `vp dev`, `vp build` and `vp test` prepare by themselves. |
|
|
68
|
-
| `bunx maximus openapi` | Writes `openapi.json`, and `openapi.rpc.json` when a route declares `rpc`; `--check` fails
|
|
69
|
+
| `bunx maximus openapi` | Writes `openapi.json`, and `openapi.rpc.json` when a route declares `rpc`; `--check` fails on a stale or invalid file. |
|
|
69
70
|
| `bun run test` | `vp test run`: the tests, in Node. |
|
|
70
71
|
| `bun run typecheck` | `maximus prepare`, then `tsc`, which also checks type tests. |
|
|
71
72
|
| `bun run check`, `bun run fix` | Lint and format; with fixes. |
|
|
@@ -95,8 +96,10 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
95
96
|
| Many items in one answer | `output: Page(Item, { $id: 'ItemPage' })` with `input: PageQueryFields`. |
|
|
96
97
|
| A file upload or download | `http: { body: 'bytes' }` with `body.read()`; `output: AttachmentOutputSchema` with `http: { response: 'attachment' }`. |
|
|
97
98
|
| Data in Postgres | `withTenantTransaction` from `@arbol-ai/maximus/postgres`. |
|
|
99
|
+
| A record of every call, for audit or a lake | `capture.ts` with `defineCapture` from `@arbol-ai/maximus/capture`; mark credential fields `secret: true`. See [Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md). |
|
|
98
100
|
| Guidance agents read over MCP | `mcp/instructions.md`, `mcp/guides/<name>.md`, `mcp/skills/<name>.md`: static text for every caller, never tenant data. |
|
|
99
|
-
| A
|
|
101
|
+
| A service on 8.2 or earlier | [Upgrading to 8.3](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.3.md): TypeBox 1.x. |
|
|
102
|
+
| A 7.x service | [Upgrading to 8.0](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.md), then to 8.3. |
|
|
100
103
|
|
|
101
104
|
## Rules that are never broken
|
|
102
105
|
|
|
@@ -104,7 +107,8 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
104
107
|
`principal.organizationId`. Never take an organization from input, a header or a path.
|
|
105
108
|
- **Schemas are strict.** Inputs and outputs are strict objects or unions of strict objects: fields given as
|
|
106
109
|
`input: { … }` make one; a `t.Object` needs `{ additionalProperties: false }`. A shared entity has a
|
|
107
|
-
PascalCase `$id`. Use the shared schemas (`UuidSchema`, `EmailAddressSchema`, …) rather than copies
|
|
110
|
+
PascalCase `$id`. Use the shared schemas (`UuidSchema`, `EmailAddressSchema`, …) rather than copies, and
|
|
111
|
+
describe a use with TypeBox's `t.With(schema, { description })`, never by spreading the schema.
|
|
108
112
|
- **Each value is checked once, where it enters.** Maximus checks an operation's input and output; a handler
|
|
109
113
|
never parses its input again. Data from outside the pipeline, such as a stored record, a provider's
|
|
110
114
|
answer or a model's output, goes through `readSchema` or `checkSchema`. No casts, trust flags or no-op
|
|
@@ -118,10 +122,15 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
118
122
|
clinical data never go in a log line, a failure's `data` or message, a refinement message, an MCP guide or
|
|
119
123
|
skill, or an example. Report a caught error with `reportUnexpected(error, surface)`, which keeps its name
|
|
120
124
|
and drops its message.
|
|
125
|
+
- **Content leaves only through capture.** Observers still receive metadata alone, never input, output or
|
|
126
|
+
credentials. Capture (`capture.ts`) is a separate, declared destination, which the owner authorized on 3
|
|
127
|
+
November 2026: content reaches a store through it, never through a log line, an observer or a failure. Mark
|
|
128
|
+
every credential field `secret: true`, where the wire carries it, before turning capture on.
|
|
121
129
|
- **Worker code reads `env`, never `process.env`.** A secret is `bindings.secret()`. The development token is
|
|
122
130
|
never declared in `env` and never set on a deployed Worker.
|
|
123
131
|
- **Outbound calls:** a Worker's `fetch(…, { redirect: 'error' })` throws before it sends anything. Send with
|
|
124
|
-
`redirect: 'manual'` and refuse a `3xx`.
|
|
132
|
+
`redirect: 'manual'` and refuse a `3xx`. A URL someone else gave you, such as a customer's server, passes
|
|
133
|
+
`publicDestination(url)` from `@arbol-ai/maximus/body` first.
|
|
125
134
|
- **Generated code stays generated.** Never edit `.maximus/`: change the source files or `vite.config.ts`.
|
|
126
135
|
- **Refusals are guidance.** `maximus prepare`, `maximus()` and the application's `.build()` refuse a broken
|
|
127
136
|
project with a message that names the rule and the file or operation. Fix the declaration; never loosen
|
|
@@ -171,6 +180,7 @@ The documentation is in the Maximus repository, indexed by
|
|
|
171
180
|
[Postgres transactions](https://github.com/getarbol/maximus/blob/main/docs/guides/postgres.md).
|
|
172
181
|
- Ship it: [Testing](https://github.com/getarbol/maximus/blob/main/docs/guides/testing.md),
|
|
173
182
|
[Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md),
|
|
183
|
+
[Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md),
|
|
174
184
|
[Deploying](https://github.com/getarbol/maximus/blob/main/docs/guides/deploying.md),
|
|
175
185
|
[Lint and format](https://github.com/getarbol/maximus/blob/main/docs/guides/lint-and-format.md).
|
|
176
186
|
- Reference: [Configuration](https://github.com/getarbol/maximus/blob/main/docs/reference/configuration.md),
|
|
@@ -109,6 +109,10 @@ Each is optional and default-exports one declaration:
|
|
|
109
109
|
the observers of every call, such as `analytics({ record })` from `@arbol-ai/maximus/analytics`. Observers
|
|
110
110
|
receive safe metadata alone, never input, output or credentials. See
|
|
111
111
|
[Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md).
|
|
112
|
+
- `capture.ts`: `defineCapture({ enabled, sink, payloads, dimensions })`, from `@arbol-ai/maximus/capture`: one
|
|
113
|
+
complete record of every call and refusal for a store the service declares, such as `pipeline({ binding })`.
|
|
114
|
+
It is apart from telemetry, and it never carries what a schema marks `secret: true`, a token or raw bytes. See
|
|
115
|
+
[Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md).
|
|
112
116
|
|
|
113
117
|
Root modules never import a route or a generated module.
|
|
114
118
|
|
|
@@ -101,6 +101,7 @@ object, and its handler may return nothing.
|
|
|
101
101
|
| `http` | `successStatus` (200, 201 or 202), `body: 'bytes'`, `headers`, `response: 'attachment'`. |
|
|
102
102
|
| `mcp` | `{ name, idempotent?, openWorld? }`: also an MCP tool. `openWorld` is `true` unless declared. |
|
|
103
103
|
| `rpc` | `true` for every caller in `rpc.callers`, or `{ callers }` for some of them. |
|
|
104
|
+
| `task` | `true` or `{ ttlMs }`: a call that outlasts one second answers a task (MCP Tasks, or `Prefer: respond-async`); needs `MAXIMUS_TASKS`. |
|
|
104
105
|
| `maxBodyBytes`, `maxOutputBytes` | Its own limits, up to 16 MiB; the application's (32 KiB and 256 KiB) otherwise. |
|
|
105
106
|
|
|
106
107
|
A field no operation has does not compile, and `.build()` refuses it. A contract kept in a `const` keeps
|
|
@@ -128,6 +129,13 @@ browsers can import):
|
|
|
128
129
|
`HttpsUrlSchema`, `HexColorSchema`, `PostalAddressSchema`, `NamedReferenceSchema`, `SignedUrlSchema`,
|
|
129
130
|
`DeletedObjectSchema`, `EmptyInputSchema`.
|
|
130
131
|
- Absent values in an output are `t.Union([X, t.Null()])`: answer every field.
|
|
132
|
+
- `t` is TypeBox 1.x, which keeps what makes a schema optional, a codec (`t.Codec`) or a refinement
|
|
133
|
+
(`t.Refine`) in properties a spread drops: give a schema a description with
|
|
134
|
+
`t.With(schema, { description })`, never `{ ...schema, description }`. Spreading a record of fields
|
|
135
|
+
(`{ ...PageQueryFields, done: t.Boolean() }`) is safe. A recursive schema is
|
|
136
|
+
`t.Cyclic({ Node: … t.Ref('Node') … }, 'Node')`.
|
|
137
|
+
- `secret: true` on a schema marks a value capture never records, such as `t.String({ secret: true })`. It
|
|
138
|
+
changes nothing a caller or a handler sees.
|
|
131
139
|
- Codecs from `@arbol-ai/maximus/schemas` (`normalizeSchema`, `transformSchema`, `refineSchema`,
|
|
132
140
|
`inspectSchema`, `pipeSchema`, `stripObject`) run only inside `inputSchema(…)`; `.build()` refuses an input
|
|
133
141
|
that uses them outside it. `defaultSchema` gives a field its default. A refinement's message reaches the
|
|
@@ -170,7 +178,9 @@ export default defineHandler(
|
|
|
170
178
|
`PageQueryFields` are `cursor`, `direction` (`forward` or `backward`) and `limit` (25 by default, at most
|
|
171
179
|
100; `pageLimit({ maximum })` lowers it). The answer is `{ object: 'list', data, pageInfo }`, whose
|
|
172
180
|
`pageInfo` holds `hasNextPage`, `hasPreviousPage`, `nextCursor` and `previousCursor`. Spread the fields
|
|
173
|
-
beside a list's own filters: `{ ...PageQueryFields, text: t.String() }`.
|
|
181
|
+
beside a list's own filters: `{ ...PageQueryFields, text: t.String() }`. A list the service holds whole is
|
|
182
|
+
cut with `cutPage(items, { key: (item) => [item.createdAt, item.id], order: 'desc' }, input)`: never write
|
|
183
|
+
cursors or offsets by hand. It answers `undefined` for a cursor it did not make; answer your own failure.
|
|
174
184
|
|
|
175
185
|
## Byte bodies and attachments
|
|
176
186
|
|
|
@@ -7,8 +7,8 @@ node_modules/@arbol-ai/maximus that `bun install` fills.
|
|
|
7
7
|
## Structure
|
|
8
8
|
|
|
9
9
|
This is a Maximus project on Cloudflare Workers. vite.config.ts is its only configuration: maximus() states
|
|
10
|
-
the application, its bindings and its Worker, and errors.ts, context.ts, auth.ts and
|
|
11
|
-
it in code when present.
|
|
10
|
+
the application, its bindings and its Worker, and errors.ts, context.ts, auth.ts, telemetry.ts and capture.ts
|
|
11
|
+
complete it in code when present.
|
|
12
12
|
|
|
13
13
|
- routes/: one defineHandler(handler, contract) per file, named by its path and method:
|
|
14
14
|
routes/v1/tasks/[taskId].delete.ts answers DELETE /api/v1/tasks/{taskId}. Its operation name, effect and
|
|
@@ -29,7 +29,7 @@ it in code when present.
|
|
|
29
29
|
- src/: the domain, in modules named after it, which any folder imports as #src/<module>.ts. tests/:
|
|
30
30
|
tests that call `handler` from #maximus/http in Node.
|
|
31
31
|
- .maximus/: generated by `maximus prepare`, vp dev, vp build and vp test. Never edit it, and never import
|
|
32
|
-
it at runtime from errors.ts, context.ts, auth.ts or
|
|
32
|
+
it at runtime from errors.ts, context.ts, auth.ts, telemetry.ts or capture.ts.
|
|
33
33
|
|
|
34
34
|
The project-structure guide maps every file:
|
|
35
35
|
https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md. Bindings and triggers
|
|
@@ -30,6 +30,7 @@ curl -H "authorization: Bearer $(cut -d= -f2 .dev.vars)" http://localhost:5173/a
|
|
|
30
30
|
| Your own failures | `errors.ts` default-exports `defineErrors({ … })` |
|
|
31
31
|
| A provider's webhook | `pages/webhooks/<provider>.post.ts`, which verifies the delivery's signature |
|
|
32
32
|
| Observers or analytics | `telemetry.ts` default-exports `defineTelemetry({ observers })` |
|
|
33
|
+
| A record of every call | `capture.ts` default-exports `defineCapture({ sink, payloads })` |
|
|
33
34
|
| What every handler receives | `context.ts` default-exports `defineContext(…)` |
|
|
34
35
|
| Domain logic and stores | A module of `src/` named after its domain, imported as `#src/tasks.ts` |
|
|
35
36
|
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { t as decodeInput } from "./validation-fTohBT6R.js";
|
|
2
|
-
import { i as standardErrors } from "./errors-C5w9WY1l.js";
|
|
3
|
-
import { a as isAttachmentSchema, o as validAttachment } from "./define-app-x7uY70_1.js";
|
|
4
|
-
import { t as err } from "./result-CKgZHrnj.js";
|
|
5
|
-
import { A as operationOutputLimit, b as ADMISSION_CODES, k as operationMatchesScopes, w as STANDARD_CODES, x as BODY_CODES } from "./openapi-CeolxIqa.js";
|
|
6
|
-
import { a as telemetryEnabled, i as reportUnexpected } from "./telemetry-C3LfZcOB.js";
|
|
7
|
-
import { Value } from "@sinclair/typebox/value";
|
|
8
|
-
|
|
9
|
-
// src/execution.ts
|
|
10
|
-
/**
|
|
11
|
-
* The one execution path every transport calls: the caller's eligibility, input decoding, context
|
|
12
|
-
* preparation, middleware, the handler, and the checks on what it returns.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* The execution path every transport shares: checks that the caller may run the operation (its scopes when
|
|
16
|
-
* `authority` is given, its actor kind, and `authority` itself when the operation has conditional scopes),
|
|
17
|
-
* decodes the input, prepares the context, runs the middleware and the handler, then checks the result
|
|
18
|
-
* against the catalog, the declared failures, the output schema and the output limit. A refused caller
|
|
19
|
-
* answers `FORBIDDEN` and a refused input `INVALID_INPUT`. An unexpected error becomes `INTERNAL_ERROR`,
|
|
20
|
-
* reported while telemetry is on, and is never thrown.
|
|
21
|
-
*/
|
|
22
|
-
async function executeOperation(manifest, operation, env, principal, input, authority, background, body) {
|
|
23
|
-
if (operation.conditionalScopes?.length && !authority || authority && !operationMatchesScopes(operation, authority.scopes) || operation.actorKinds && !operation.actorKinds.includes(principal.actorKind)) return err(standardErrors.forbidden.create());
|
|
24
|
-
try {
|
|
25
|
-
const admitted = decodeInput(operation.input, input);
|
|
26
|
-
if (!admitted.ok) return err(standardErrors.invalidInput.create(admitted.error.data));
|
|
27
|
-
const trustedAuthority = authority ? Object.freeze({
|
|
28
|
-
surface: authority.surface,
|
|
29
|
-
scopes: Object.freeze([...authority.scopes]),
|
|
30
|
-
client: Object.freeze({ ...authority.client }),
|
|
31
|
-
...authority.token ? { token: authority.token } : {}
|
|
32
|
-
}) : void 0;
|
|
33
|
-
const invocation = {
|
|
34
|
-
env,
|
|
35
|
-
principal,
|
|
36
|
-
input: admitted.value,
|
|
37
|
-
...body ? { body } : {},
|
|
38
|
-
...background ? { background } : {},
|
|
39
|
-
...trustedAuthority ? { authority: trustedAuthority } : {}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A failure the call answers, from its context, middleware or handler: one of the catalog and, when the
|
|
43
|
-
* operation declares its failures, a declared or standard one. A failure only admission answers, or a
|
|
44
|
-
* body's for an operation that reads no byte body, is never the operation's. Any other is the server's
|
|
45
|
-
* error.
|
|
46
|
-
*/
|
|
47
|
-
const declared = (answered) => {
|
|
48
|
-
const failure = manifest.errors.validate(answered);
|
|
49
|
-
if (ADMISSION_CODES.has(failure.code) || BODY_CODES.has(failure.code) && operation.http?.body !== "bytes") throw new TypeError(`Failure ${failure.code} is answered before an operation runs, never by it`);
|
|
50
|
-
if (operation.failures && !STANDARD_CODES.has(failure.code) && !operation.failures.includes(failure.code)) throw new TypeError(`Undeclared failure ${failure.code}`);
|
|
51
|
-
return failure;
|
|
52
|
-
};
|
|
53
|
-
const context = operation.pipeline ? await operation.pipeline.context(invocation) : await manifest.context(invocation);
|
|
54
|
-
if (!context.ok) return err(declared(context.error));
|
|
55
|
-
const chain = operation.pipeline?.middleware ?? manifest.middleware ?? [];
|
|
56
|
-
let latest = -1;
|
|
57
|
-
/**
|
|
58
|
-
* Runs the middleware at `index`, whose `next` runs the following one, until the handler; each `next`
|
|
59
|
-
* runs once.
|
|
60
|
-
*/
|
|
61
|
-
const dispatch = async (index) => {
|
|
62
|
-
if (index <= latest) throw new Error("Middleware next() may be called only once.");
|
|
63
|
-
latest = index;
|
|
64
|
-
const middleware = chain[index];
|
|
65
|
-
return await (middleware ? middleware(context.value, () => dispatch(index + 1)) : operation.execute(context.value, admitted.value));
|
|
66
|
-
};
|
|
67
|
-
const result = await dispatch(0);
|
|
68
|
-
if (!result || typeof result.ok !== "boolean" || !Object.hasOwn(result, "ok") || Object.keys(result).length !== 2 || !Object.hasOwn(result, result.ok ? "value" : "error")) throw new TypeError("Invalid operation result");
|
|
69
|
-
if (!result.ok) return err(declared(result.error));
|
|
70
|
-
const maxOutputBytes = operationOutputLimit(manifest, operation);
|
|
71
|
-
if (isAttachmentSchema(operation.output)) {
|
|
72
|
-
if (!validAttachment(result.value, maxOutputBytes)) throw new TypeError("Invalid attachment output");
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
if (!Value.Check(operation.output, result.value)) throw new TypeError("Invalid operation output");
|
|
76
|
-
if (new TextEncoder().encode(JSON.stringify(result.value)).byteLength > maxOutputBytes) throw new TypeError("Operation output exceeds its limit");
|
|
77
|
-
return result;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (telemetryEnabled(manifest.telemetry, env)) reportUnexpected(error, "operation", principal.requestId);
|
|
80
|
-
return err(standardErrors.internal.create());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { executeOperation as t };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { t as isRecord } from "./record-DQUDTpEA.js";
|
|
2
|
-
|
|
3
|
-
// src/internal/http-routes.ts
|
|
4
|
-
/**
|
|
5
|
-
* The parameter's schema in an object input, or in each member of a union. Every one must declare the
|
|
6
|
-
* parameter as a required string field, or this throws a TypeError.
|
|
7
|
-
*/
|
|
8
|
-
function pathParameterSchemas(input, parameter) {
|
|
9
|
-
if (input.type === "object") {
|
|
10
|
-
const schema = input.properties?.[parameter];
|
|
11
|
-
if (!schema || schema.type !== "string" || !input.required?.includes(parameter)) throw new TypeError(`Path parameter "${parameter}" must be a required string input field.`);
|
|
12
|
-
return [schema];
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(input.anyOf) && input.anyOf.length > 0) return input.anyOf.flatMap((schema) => pathParameterSchemas(schema, parameter));
|
|
15
|
-
throw new TypeError("Path parameters require object input contracts.");
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* The group a route's path names, which OpenAPI publishes as its tag: its first fixed segment after the
|
|
19
|
-
* version, in words, such as `Notes` for `/v1/notes/{noteId}` and `Task lists` for `/v1/task-lists`;
|
|
20
|
-
* undefined when only parameters follow the version.
|
|
21
|
-
*/
|
|
22
|
-
function routeGroup(path) {
|
|
23
|
-
const segments = path.split("/").filter(Boolean);
|
|
24
|
-
const segment = (/^v[1-9][0-9]*$/.test(segments[0] ?? "") ? segments.slice(1) : segments).find((part) => !part.startsWith("{"));
|
|
25
|
-
if (segment === void 0) return;
|
|
26
|
-
const words = segment.replaceAll(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_-]+/).filter(Boolean).join(" ").toLowerCase();
|
|
27
|
-
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/result.ts
|
|
31
|
-
/** A success carrying `value`. */
|
|
32
|
-
function ok(value) {
|
|
33
|
-
return {
|
|
34
|
-
ok: true,
|
|
35
|
-
value
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/** A failure carrying `error`, usually `catalog.someFailure.create()`. */
|
|
39
|
-
function err(error) {
|
|
40
|
-
return {
|
|
41
|
-
ok: false,
|
|
42
|
-
error
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Whether an untrusted answer (a Service Binding's, a stored one) is a Maximus Result: a success with
|
|
47
|
-
* its value, or a failure with a well-formed error. Anything else is not an answer at all.
|
|
48
|
-
*/
|
|
49
|
-
function isResult(value) {
|
|
50
|
-
if (!isRecord(value)) return false;
|
|
51
|
-
if (value.ok === true) return "value" in value;
|
|
52
|
-
const { error } = value;
|
|
53
|
-
return value.ok === false && isRecord(error) && typeof error.code === "string" && typeof error.message === "string" && typeof error.retryable === "boolean" && isRecord(error.data);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { routeGroup as a, pathParameterSchemas as i, isResult as n, ok as r, err as t };
|