@arbol-ai/maximus 0.0.0-stage → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/config/oxfmt.d.mts +8 -0
- package/config/oxfmt.mjs +30 -0
- package/config/oxlint-plugin.mjs +41 -0
- package/config/oxlint.d.mts +8 -0
- package/config/oxlint.mjs +118 -0
- package/dist/analytics/analytics.d.ts +34 -0
- package/dist/analytics/analytics.js +62 -0
- package/dist/body.d.ts +2 -0
- package/dist/body.js +4 -0
- package/dist/chunks/body-BcMbreNd.js +106 -0
- package/dist/chunks/correlation-gaiEoMBr.js +45 -0
- package/dist/chunks/execution-qfZuMSIu.js +700 -0
- package/dist/chunks/json-Dwni3u4c.js +63 -0
- package/dist/chunks/record-D2H3cg8S.js +36 -0
- package/dist/chunks/schemas-q-51wBMQ.js +216 -0
- package/dist/chunks/src-Ph5KHCRP.js +1160 -0
- package/dist/chunks/telemetry-DvZgrzZn.js +220 -0
- package/dist/chunks/types-CGwAhnTE.d.ts +1630 -0
- package/dist/chunks/validation-DWxKk1Js.js +382 -0
- package/dist/client/client.d.ts +131 -0
- package/dist/client/client.js +325 -0
- package/dist/diagnostics.d.ts +41 -0
- package/dist/diagnostics.js +4 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +128 -0
- package/dist/http-paths.d.ts +2 -0
- package/dist/http-paths.js +200 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/internals.d.ts +2 -0
- package/dist/internals.js +5 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.js +406 -0
- package/dist/postgres/index.d.ts +81 -0
- package/dist/postgres/index.js +140 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.js +4 -0
- package/dist/standard-failures.d.ts +91 -0
- package/dist/standard-failures.js +75 -0
- package/dist/tooling/cli.js +110 -0
- package/dist/tooling/testing.d.ts +7 -0
- package/dist/tooling/testing.js +21 -0
- package/dist/webhooks.d.ts +69 -0
- package/dist/webhooks.js +162 -0
- package/dist/workers/runtime.d.ts +112 -0
- package/dist/workers/runtime.js +228 -0
- package/package.json +153 -4
- package/skills/maximus/SKILL.md +89 -0
- package/skills/maximus/references/adding-an-operation.md +179 -0
- package/skills/maximus/references/building-a-service.md +158 -0
- package/skills/maximus/references/errors-and-results.md +77 -0
- package/skills/maximus/references/migration-from-v2.md +62 -0
- package/skills/maximus/references/migration-to-v5.md +37 -0
- package/skills/maximus/references/publishing-and-verification.md +39 -0
- package/skills/maximus/references/testing.md +73 -0
- package/skills/maximus/references/transports.md +119 -0
- package/templates/service/.agents/skills/project/SKILL.md.template +10 -0
- package/templates/service/.github/workflows/ci.yml.template +21 -0
- package/templates/service/.gitignore.template +8 -0
- package/templates/service/CLAUDE.md.template +3 -0
- package/templates/service/README.md.template +45 -0
- package/templates/service/cloudflare.config.ts.template +30 -0
- package/templates/service/oxfmt.config.ts.template +1 -0
- package/templates/service/oxlint.config.ts.template +1 -0
- package/templates/service/package.json.template +31 -0
- package/templates/service/src/app.ts.template +30 -0
- package/templates/service/src/index.ts.template +13 -0
- package/templates/service/tests/contract.test.ts.template +12 -0
- package/templates/service/tsconfig.json.template +16 -0
- package/templates/service/vite.config.ts.template +7 -0
- package/templates/service/vitest.config.ts.template +10 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: maximus
|
|
3
|
+
description: Build, extend, test, migrate and release services with the Maximus framework (@arbol-ai/maximus*), which declares schema-first, organization-scoped operations once and serves them over HTTP/OpenAPI, MCP and Cloudflare Worker RPC. Use when code imports @arbol-ai/maximus or a task involves Maximus operations, scopes, error catalogs, derive/use middleware, MCP tools, RPC entrypoints, OpenAPI documents or the maximus CLI.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Maximus
|
|
7
|
+
|
|
8
|
+
Maximus services declare each operation once (schemas, scope, effect, exposure, handler) on one
|
|
9
|
+
fluent application. Each transport admits the caller its own way, then every call runs the same
|
|
10
|
+
pipeline: input decoding, preparation, middleware, handler, output validation. Work with that
|
|
11
|
+
pipeline, never around it.
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
1. **Read the service first.** Find `maximus<Env>(…)` (usually `src/application.ts`), the resource
|
|
16
|
+
modules (`src/api/<resource>/operations.ts`), the composition (`src/app.ts`) and the Worker
|
|
17
|
+
(`src/index.ts`). Keep the project's existing folders and named domain functions.
|
|
18
|
+
2. **Declare, don't wire.** Add an operation to its resource module with strict schemas, a namespaced
|
|
19
|
+
scope, a truthful effect and only the transports it needs (`http`, `mcp`, `rpc`). Mount new
|
|
20
|
+
modules in `app.ts`. See `references/adding-an-operation.md`.
|
|
21
|
+
3. **Return Results.** Expected failures are `err(catalog.x.create())` from the application's own
|
|
22
|
+
catalog; throw only for the unexpected. See `references/errors-and-results.md`.
|
|
23
|
+
4. **Prepare context with `.derive()`** in the group that needs it, and wrap with `.use()` only for
|
|
24
|
+
cross-cutting behavior after authorization.
|
|
25
|
+
5. **Verify** with the project's typecheck, lint and tests, then `cf build` and a dry-run deploy
|
|
26
|
+
(`cf deploy --prebuilt --mode production --dry-run`). See `references/testing.md` and
|
|
27
|
+
`references/publishing-and-verification.md`.
|
|
28
|
+
|
|
29
|
+
## Decisions
|
|
30
|
+
|
|
31
|
+
| Question | Choose |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Who calls it? People or external services over the network | `http` (and `mcp` for agents) with OAuth tokens |
|
|
34
|
+
| Another Worker in the same account, trusted deployment | `rpc` with `rpc.callers`; see `references/transports.md` |
|
|
35
|
+
| Documents that list only the failures it can answer | `failures` (its domain codes); any other becomes `INTERNAL_ERROR`; see `references/adding-an-operation.md` |
|
|
36
|
+
| A gateway in front of the service, forwarding each caller's own token | Nothing special: list its audience in `tokens.audience` after the service's own; it calls the origin's own routes |
|
|
37
|
+
| Staff operations hidden from documents and clients | `visibility: 'internal'`: still routed and decided by scope on the origin |
|
|
38
|
+
| Verifying a provider webhook | `@arbol-ai/maximus/webhooks` on the raw body, in a plain route |
|
|
39
|
+
| Callers without bearer tokens (webhooks, signed links) | A plain route that verifies its own signature |
|
|
40
|
+
| Tokens that are not organization-bound OAuth access tokens | `tokens.resolve`, verifying cryptographically |
|
|
41
|
+
| SDKs or a catalog generated from the contract | The origin's `/openapi.json`, or `createOpenApi(app)` at build time; see `references/transports.md` |
|
|
42
|
+
| A new service from scratch | `references/building-a-service.md` |
|
|
43
|
+
| Upgrading from 4.x | `references/migration-to-v5.md` |
|
|
44
|
+
| Upgrading from 2.x | `references/migration-from-v2.md` |
|
|
45
|
+
|
|
46
|
+
## Rules that are never broken
|
|
47
|
+
|
|
48
|
+
- **Tenancy:** every tenant query uses `context.principal.organizationId`. Never take an
|
|
49
|
+
organization from input, a header or a path.
|
|
50
|
+
- **Strict schemas:** inputs and outputs are `t.Object({...}, { additionalProperties: false })` or
|
|
51
|
+
unions of such objects; a GET input is one object, each field read from the query string as its
|
|
52
|
+
kind (integer, number, boolean, comma-separated string list, otherwise string).
|
|
53
|
+
- **Validation ownership:** the framework validates operation input and output once. Do not re-parse
|
|
54
|
+
inputs in handlers or helpers; do validate provider responses, stored records and model output with
|
|
55
|
+
`checkSchema`/`readSchema`. No casts, trust flags or no-op validators.
|
|
56
|
+
- **Codecs need `inputSchema()`:** an input using `normalizeSchema`, `refineSchema`,
|
|
57
|
+
`transformSchema`, `inspectSchema`, `pipeSchema` or `stripObject` must be wrapped in
|
|
58
|
+
`inputSchema(...)`; `.build()` refuses it otherwise, because a plain decode would skip the codecs.
|
|
59
|
+
- **Authorization is scopes plus your checks:** effects, `visibility: 'internal'`, descriptions and
|
|
60
|
+
MCP annotations never authorize. Ordinary RPC checks no scopes.
|
|
61
|
+
- **Failures are honest:** an outage is a failure, never an empty success. A write whose outcome is
|
|
62
|
+
lost answers `OUTCOME_UNKNOWN` and is reconciled, never retried blindly.
|
|
63
|
+
- **Outbound calls:** in a Worker, `fetch(..., { redirect: 'error' })` throws before any request
|
|
64
|
+
(only `follow` and `manual` exist). Send credentials with `redirect: 'manual'` and refuse a `3xx`.
|
|
65
|
+
- **Privacy:** never log or return request bodies, credentials or submitted values in failure
|
|
66
|
+
`data`, refinement messages, MCP skills or examples. Skills and guides hold no tenant data.
|
|
67
|
+
- **Collections are pages:** an operation that returns many items answers `Page(Item, { $id })` with
|
|
68
|
+
`PageQueryFields`; one that reads, creates or updates an item answers the named entity (the list's
|
|
69
|
+
item); a delete answers `DeletedObjectSchema`. Use the shared schemas (`UuidSchema`,
|
|
70
|
+
`EmailAddressSchema`, …) instead of local copies.
|
|
71
|
+
- **Construction errors are guidance:** `.build()` throws a `TypeError` stating the rule (usually with
|
|
72
|
+
the operation's name); fix the definition rather than loosening checks.
|
|
73
|
+
|
|
74
|
+
## References
|
|
75
|
+
|
|
76
|
+
Load the one that matches the task:
|
|
77
|
+
|
|
78
|
+
- `references/building-a-service.md`: project layout, configuration, tokens, Worker, local run.
|
|
79
|
+
- `references/adding-an-operation.md`: every definition field, routes, schemas, codecs, middleware.
|
|
80
|
+
- `references/transports.md`: HTTP and OpenAPI, MCP, native RPC, plain routes and Worker composition.
|
|
81
|
+
- `references/errors-and-results.md`: catalogs, standard failures, presentation, uncertain outcomes.
|
|
82
|
+
- `references/testing.md`: handler tests, the `verify` seam, MCP, `executeOperation`, RPC types.
|
|
83
|
+
- `references/migration-to-v5.md`: what 5.0 removed and what to change.
|
|
84
|
+
- `references/migration-from-v2.md`: 3.0.0 breaking changes and classifying older services.
|
|
85
|
+
- `references/publishing-and-verification.md`: `maximus init`, deploying, verifying a deployment and
|
|
86
|
+
releasing Maximus itself.
|
|
87
|
+
|
|
88
|
+
The full documentation is in the Maximus repository under `docs/`; this skill ships in
|
|
89
|
+
`@arbol-ai/maximus` at `skills/maximus/`.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Adding an operation
|
|
2
|
+
|
|
3
|
+
## Template
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { err, ok, t, UuidSchema } from '@arbol-ai/maximus';
|
|
7
|
+
|
|
8
|
+
import { base, errors } from '../../application';
|
|
9
|
+
|
|
10
|
+
export const notes = base.operation(
|
|
11
|
+
'getNote', // camelCase, unique; also the OpenAPI operationId and RPC method name
|
|
12
|
+
{
|
|
13
|
+
scope: ['notes:notes:read', 'notes:notes:write'], // any one admits; scopeMatch: 'all' for every one
|
|
14
|
+
effect: 'read', // 'read' | 'write' | 'delete' — truthful; only reads may use GET
|
|
15
|
+
group: 'Notes', // OpenAPI tag
|
|
16
|
+
title: 'Get a note',
|
|
17
|
+
description: 'Read one note by its identifier.', // written for people and models
|
|
18
|
+
input: t.Object({ noteId: UuidSchema }, { additionalProperties: false }),
|
|
19
|
+
output: NoteSchema,
|
|
20
|
+
http: { method: 'GET', path: '/v1/notes/{noteId}' },
|
|
21
|
+
mcp: { name: 'get_note', idempotent: true },
|
|
22
|
+
// rpc: true,
|
|
23
|
+
},
|
|
24
|
+
async ({ env, principal }, input) => {
|
|
25
|
+
const note = await readNote(env.NOTES, principal.organizationId, input.noteId);
|
|
26
|
+
return note ? ok(note) : err(errors.noteNotFound.create());
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Declared failures
|
|
32
|
+
|
|
33
|
+
Declare `failures` (the domain codes it may answer) so its documents list only those and any other
|
|
34
|
+
domain failure it returns becomes `INTERNAL_ERROR`, reported. Omitted, every failure of the catalog is
|
|
35
|
+
listed and allowed; standard failures are always allowed.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
base.operation(
|
|
39
|
+
'archiveNote',
|
|
40
|
+
{
|
|
41
|
+
scope: 'notes:notes:write',
|
|
42
|
+
effect: 'write',
|
|
43
|
+
actorKinds: ['user'],
|
|
44
|
+
title: 'Archive a note',
|
|
45
|
+
description: 'Moves a note out of the active list; it stays readable.',
|
|
46
|
+
input: t.Object({ noteId: UuidSchema }, { additionalProperties: false }),
|
|
47
|
+
output: NoteSchema,
|
|
48
|
+
http: { method: 'POST', path: '/v1/notes/{noteId}/archive' },
|
|
49
|
+
mcp: { name: 'archive_note', idempotent: true },
|
|
50
|
+
failures: ['NOTE_NOT_FOUND'], // the only domain failure it may answer
|
|
51
|
+
},
|
|
52
|
+
async ({ env, principal }, input) => archiveNote(env.NOTES, principal.organizationId, input.noteId)
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Reserved names: `fetch`, `connect`, `constructor`, `then`, `scheduled`, `queue`, `alarm`,
|
|
57
|
+
`__proto__`, `prototype`.
|
|
58
|
+
|
|
59
|
+
## Fields
|
|
60
|
+
|
|
61
|
+
An inline definition with a field no operation has (a misspelling, a retired `api` name) does not
|
|
62
|
+
compile.
|
|
63
|
+
|
|
64
|
+
| Field | Rule |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `scope` | `<namespace>:<resource>:<action>` with the app's namespace; a list is any-of unless `scopeMatch: 'all'`. |
|
|
67
|
+
| `conditionalScopes` | Extra namespaced scopes the handler checks via `context.authority?.scopes`; calls without authority (ordinary RPC) are refused. |
|
|
68
|
+
| `actorKinds` | `['user']`, `['service']` or both; omitted, either is admitted. Required on every documented operation under the `oauth+bearer` token scheme. |
|
|
69
|
+
| `visibility` | `'internal'`: routed and scope-checked, hidden from OpenAPI, `scopes_supported` and the client. Give it a staff-only scope. |
|
|
70
|
+
| `maxBodyBytes` | Per-operation body limit, up to 16 MiB, never on GET. App default 32 KiB. |
|
|
71
|
+
| `maxOutputBytes` | Up to 16 MiB. Default 256 KiB. Over the limit → `INTERNAL_ERROR`. |
|
|
72
|
+
| `http.method`, `http.path` | `/v<n>/…`, static segments `[A-Za-z0-9_-]+`, whole-segment `{param}`; unique `METHOD path`. |
|
|
73
|
+
| `http.successStatus` | `200`, `201` or `202`. |
|
|
74
|
+
| `mcp.name` | `^[a-z][A-Za-z0-9_]{0,63}$`, unique; `idempotent` required; `openWorld` defaults to `true`. Served once the Worker mounts `transports: [mcp()]`. |
|
|
75
|
+
| `rpc` | `true` (all app callers) or `{ callers }` (a subset). |
|
|
76
|
+
|
|
77
|
+
## HTTP input rules
|
|
78
|
+
|
|
79
|
+
- GET input comes from the query string: each declared field is read as its kind (integer, number,
|
|
80
|
+
boolean, comma-separated string list, otherwise string); repeated keys are refused. The typed
|
|
81
|
+
client writes those values the same way.
|
|
82
|
+
- POST, PUT, PATCH and DELETE read a JSON body with `content-type: application/json` (415
|
|
83
|
+
otherwise); a DELETE with no body and no `content-type` is the empty input.
|
|
84
|
+
- A `{param}` must be a required `string` field of the input (of each union member). The query or
|
|
85
|
+
body may not repeat it.
|
|
86
|
+
- Unknown routes and methods are 404 before authentication; no trailing-slash normalization.
|
|
87
|
+
|
|
88
|
+
## Schemas
|
|
89
|
+
|
|
90
|
+
- Strict objects or unions of strict objects (discriminated by a field). A GET input is one object.
|
|
91
|
+
- Shared, each a named component: `OrganizationIdSchema`, `UuidSchema`, `EmailAddressSchema`,
|
|
92
|
+
`PhoneNumberSchema` (E.164), `HttpsUrlSchema`, `HexColorSchema`, `DeletedObjectSchema`,
|
|
93
|
+
`SignedUrlSchema`, `NamedReferenceSchema`, `PostalAddressSchema`; `EmptyInputSchema` (unnamed). Ids
|
|
94
|
+
are strings; use `organizationId` and `requestId`, never aliases. Name your own entities with a
|
|
95
|
+
PascalCase `$id`, one shape per name: it becomes a public SDK type.
|
|
96
|
+
- Lists: `input: inputSchema(t.Object({ ...PageQueryFields, ...filters }, { additionalProperties: false }))`
|
|
97
|
+
(`cursor`, `direction`, `limit`; `limit: pageLimit({ maximum })` to lower it) and
|
|
98
|
+
`output: Page(Item, { $id: 'ItemPage' })`, answering `{ object: 'list', data, pageInfo }`.
|
|
99
|
+
- Formats: `date`, `time`, `date-time` (time zone required), `email`, `uuid`, `uri`.
|
|
100
|
+
- Use `t.Union([X, t.Null()])` for absent values in outputs; present every field.
|
|
101
|
+
|
|
102
|
+
## Codecs (from `@arbol-ai/maximus/schemas`)
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { defaultSchema, inputSchema, normalizeSchema, refineSchema, t } from '@arbol-ai/maximus/schemas';
|
|
106
|
+
|
|
107
|
+
input: inputSchema(
|
|
108
|
+
refineSchema(
|
|
109
|
+
t.Object(
|
|
110
|
+
{
|
|
111
|
+
query: normalizeSchema(t.String({ minLength: 1, maxLength: 100 }), (value) => value.trim()),
|
|
112
|
+
limit: defaultSchema(t.Integer({ minimum: 1, maximum: 50 }), 20),
|
|
113
|
+
from: t.String({ format: 'date' }),
|
|
114
|
+
to: t.String({ format: 'date' }),
|
|
115
|
+
},
|
|
116
|
+
{ additionalProperties: false }
|
|
117
|
+
),
|
|
118
|
+
(value) => value.from <= value.to,
|
|
119
|
+
{ message: 'The range must not end before it starts.', path: ['to'] }
|
|
120
|
+
)
|
|
121
|
+
),
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- Without `inputSchema(...)` around the input, normalizers, transforms, refinements and stripping do
|
|
125
|
+
not run.
|
|
126
|
+
- Handlers receive `StaticDecode<typeof input>`; clients and OpenAPI see `Static<typeof input>`.
|
|
127
|
+
- Refinement messages travel to callers in `INVALID_INPUT` issues: never include input values.
|
|
128
|
+
- Other helpers: `transformSchema`, `inspectSchema` (several issues via `addIssue`), `pipeSchema`,
|
|
129
|
+
`stripObject` / `strictObject` / `looseObject` / `extendObject`, `literalUnion`, `urlSchema`.
|
|
130
|
+
|
|
131
|
+
Numbers in a GET query need a wire schema:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const Query = t.Object(
|
|
135
|
+
{
|
|
136
|
+
limit: t.Optional(
|
|
137
|
+
t.Transform(t.String({ pattern: '^[1-9][0-9]{0,2}$' })).Decode((v) => Number(v)).Encode((v) => String(v))
|
|
138
|
+
),
|
|
139
|
+
},
|
|
140
|
+
{ additionalProperties: false }
|
|
141
|
+
);
|
|
142
|
+
const Canonical = t.Object({ limit: t.Optional(t.Integer({ minimum: 1, maximum: 100 })) }, { additionalProperties: false });
|
|
143
|
+
// input: inputSchema(Canonical, Query)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Context, derive and use
|
|
147
|
+
|
|
148
|
+
Handler context: `env`, `principal` (`actorId`, `actorKind`, `organizationId`, `requestId`),
|
|
149
|
+
`authority` (`{ surface, scopes, client, token? }`, frozen; absent over ordinary RPC), `input`,
|
|
150
|
+
`operation`, `background` (`waitUntil`, best effort), and `body` for byte uploads.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const connected = base.derive(async ({ env, principal }) => {
|
|
154
|
+
const account = await loadAccount(env, principal.organizationId);
|
|
155
|
+
return account ? ok({ account }) : err(errors.accountNotConnected.create());
|
|
156
|
+
});
|
|
157
|
+
export const reports = connected.operation('listReports', definition, async ({ account }, input) => …);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
- `.derive()` must precede `.operation()` on its chain (it throws otherwise); it runs after
|
|
161
|
+
admission and input validation; its failure ends the call.
|
|
162
|
+
- `.use(async (context, proceed) => …)`: call `proceed()` at most once and return its `Result`, or
|
|
163
|
+
return your own. Results are validated. Applies to operations declared after it.
|
|
164
|
+
- Operations that set something up (a connection) must not sit in the group that requires it.
|
|
165
|
+
- `mount` only builders from the same `maximus()` base.
|
|
166
|
+
|
|
167
|
+
## Files
|
|
168
|
+
|
|
169
|
+
Upload: `http: { method: 'PUT', path: '/v1/notes/{noteId}/attachment', body: 'bytes', headers: { contentType: 'content-type' } }`,
|
|
170
|
+
a `maxBodyBytes`, and `const bytes = await context.body.read()` (a `Result`, read once) after checking
|
|
171
|
+
the target resource. Download: `output: AttachmentOutputSchema`, `http: { …, response: 'attachment' }`,
|
|
172
|
+
return `ok({ body, contentType, filename, byteLength })`. Both are HTTP-only.
|
|
173
|
+
|
|
174
|
+
## Before you finish
|
|
175
|
+
|
|
176
|
+
- Scopes namespaced; effect truthful; strict schemas; every failure from the app's catalog.
|
|
177
|
+
- No organization in the input; tenant keys built from `principal.organizationId`.
|
|
178
|
+
- Provider and storage reads go through `checkSchema`/`readSchema`.
|
|
179
|
+
- Typecheck, tests and lint pass; `.build()` raises no `TypeError`.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Building a service
|
|
2
|
+
|
|
3
|
+
## Packages
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add @arbol-ai/maximus # everything: /workers, /mcp, /client, the maximus CLI, …
|
|
7
|
+
bun add -d cf vite @cloudflare/vite-plugin@beta typescript @cloudflare/workers-types
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Layout
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
src/
|
|
14
|
+
application.ts export const base = maximus<Env>({ ... })
|
|
15
|
+
tokens.ts the TokenPolicy (issuer, audience, optional resolve)
|
|
16
|
+
env.ts Env: the bindings, typed by the narrow interfaces the code uses
|
|
17
|
+
api/<resource>/
|
|
18
|
+
schemas.ts TypeBox schemas
|
|
19
|
+
<resource>.ts named domain functions
|
|
20
|
+
operations.ts export const <resource> = base.operation(...)...
|
|
21
|
+
app.ts export const app = base.mount(a).mount(b).build() (no cloudflare:workers import)
|
|
22
|
+
index.ts createWorker(app, ...) and the exports
|
|
23
|
+
cloudflare.config.ts the Worker for cf: name, runtime, entrypoint, bindings, triggers, exports
|
|
24
|
+
vite.config.ts cloudflare() from @cloudflare/vite-plugin, which cf builds and runs with
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`app.ts` must stay importable outside workerd so tests and scripts can load it.
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { defineErrors, maximus } from '@arbol-ai/maximus';
|
|
33
|
+
|
|
34
|
+
export const errors = defineErrors({
|
|
35
|
+
noteNotFound: { code: 'NOTE_NOT_FOUND', status: 404, message: 'The note does not exist.' },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const base = maximus<Env>({
|
|
39
|
+
name: 'notes', // lowercase; health, MCP server name, telemetry
|
|
40
|
+
namespace: 'notes', // ^[a-z][a-z0-9-]{1,63}$, prefixes every scope
|
|
41
|
+
title: 'Notes',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
origin: 'https://notes.example.com', // must be https:, the public URL
|
|
44
|
+
tokens: { issuer: 'https://auth.example.com/', audience: 'https://notes.example.com' },
|
|
45
|
+
errors,
|
|
46
|
+
rpc: { callers: [] }, // deployments allowed over native RPC
|
|
47
|
+
// optional: mcp, telemetry, rateLimit, maxBodyBytes, maxOutputBytes
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- `tokens.issuer` has no default. Without it the app builds, but OAuth tokens are refused and
|
|
52
|
+
`/openapi.json` answers 500.
|
|
53
|
+
- `mcp` configuration requires `transports: [mcp()]` in `createWorker`, or the Worker fails to start.
|
|
54
|
+
|
|
55
|
+
## Tokens
|
|
56
|
+
|
|
57
|
+
Default: OAuth access tokens from any provider, RS256 (or `tokens.algorithms`) from
|
|
58
|
+
`<issuer>.well-known/jwks.json` (or `tokens.jwksUri`), exact issuer and audience (`tokens.audience`
|
|
59
|
+
may list several, any one accepted; the first is the discovery `resource`). Standard claims: `sub`
|
|
60
|
+
(actor; `<client>@clients` is a machine), `org_id` (required; 1-128 letters, digits, `_`, `-`),
|
|
61
|
+
`azp`/`client_id` (optional), `scope`; a person holds only the scopes their `permissions` claim also
|
|
62
|
+
lists, none without it (Auth0 with RBAC and permissions in the token). `tokens.claims` maps providers
|
|
63
|
+
that name them differently: `{ scopes: 'scp', client: 'cid', permissions: false, machineSubject:
|
|
64
|
+
'{client}' }` (Okta), `{ scopes: 'permissions' }` (WorkOS session tokens). Set `permissions: false`
|
|
65
|
+
only when the authorization server grants each person no more than they may hold, and
|
|
66
|
+
`machineSubject: '{client}'` only when it assigns every client id. OpenAPI's OAuth flows use
|
|
67
|
+
`tokens.authorizationEndpoint` and `tokens.tokenEndpoint` (Auth0's `authorize` and `oauth/token` by
|
|
68
|
+
default); for other providers copy them and `jwksUri` from the server's
|
|
69
|
+
`/.well-known/oauth-authorization-server` metadata.
|
|
70
|
+
|
|
71
|
+
Other credentials: `tokens.resolve(token, context)` verifies cryptographically and returns a
|
|
72
|
+
`TokenPrincipal` (`{ actorId, actorKind, organizationId, scopes, client? }`) or a `Result`
|
|
73
|
+
(`FORBIDDEN` → 403, any other failure or a throw → 401). `context` has `env`, `request`, `surface`,
|
|
74
|
+
`applicationScopes`, `background`. Return a `client` so calls carry `authority`.
|
|
75
|
+
|
|
76
|
+
`tokens.scheme`: `{ type: 'bearer', description }` for application-issued tokens (needs `resolve`, no
|
|
77
|
+
OAuth discovery, cannot mount MCP); `{ type: 'oauth+bearer', description }` for OAuth people plus
|
|
78
|
+
resolver-verified workload keys (every operation in the OpenAPI document declares `actorKinds`).
|
|
79
|
+
|
|
80
|
+
Local development (`examples/minimal-http/src/tokens.ts`): `tokens.development: { binding:
|
|
81
|
+
'DEVELOPMENT_TOKEN' }` accepts that token, at least 32 characters, from `.dev.vars` only from
|
|
82
|
+
`localhost`/`127.0.0.1`/`[::1]`, as `local-developer` holding every declared scope; every other token is
|
|
83
|
+
verified as usual. Never write that resolver by hand.
|
|
84
|
+
|
|
85
|
+
## Env
|
|
86
|
+
|
|
87
|
+
Type bindings by what the code uses, so tests can fake them without casts:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
export interface NoteStore {
|
|
91
|
+
get: (key: string) => Promise<string | null>;
|
|
92
|
+
put: (key: string, value: string) => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
export interface Env {
|
|
95
|
+
NOTES: NoteStore; // a KVNamespace satisfies it
|
|
96
|
+
PRICING: Service<typeof PricingService>; // RPC binding typed from the owner's entrypoint
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## The Worker
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { mcp } from '@arbol-ai/maximus/mcp';
|
|
104
|
+
import { createWorker } from '@arbol-ai/maximus/workers';
|
|
105
|
+
|
|
106
|
+
import { app } from './app';
|
|
107
|
+
|
|
108
|
+
const worker = createWorker(app, {
|
|
109
|
+
transports: [mcp()], // serves the MCP tools; required by app mcp configuration
|
|
110
|
+
// routes, http: { basePath, origins, mounts, before, aroundOperation, fallback, healthPath },
|
|
111
|
+
// assets, handlers: { scheduled, queue }
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export default worker.handler;
|
|
115
|
+
export const NotesService = worker.entrypoint; // if any operation declares rpc
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## cloudflare.config.ts
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { bindings, defineConfig } from 'cf/config';
|
|
122
|
+
|
|
123
|
+
import * as entrypoint from './src/index.ts' with { type: 'cf-worker' };
|
|
124
|
+
|
|
125
|
+
export default defineConfig(({ mode }) => ({
|
|
126
|
+
worker: {
|
|
127
|
+
name: 'notes',
|
|
128
|
+
compatibilityDate: '2026-10-12',
|
|
129
|
+
compatibilityFlags: ['nodejs_compat'], // required: node:async_hooks
|
|
130
|
+
entrypoint,
|
|
131
|
+
observability: { enabled: true },
|
|
132
|
+
env: {
|
|
133
|
+
NOTES: bindings.kv(), // no id: cf deploy provisions it
|
|
134
|
+
DEVELOPMENT_TOKEN: mode === 'development' && bindings.secret(), // cf dev only, from .dev.vars
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`cf` is in beta and needs Node 22+. Wrangler files are not read: convert one with `cf migrate`.
|
|
141
|
+
|
|
142
|
+
## Run locally
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
echo "DEVELOPMENT_TOKEN=$(openssl rand -hex 32)" > .dev.vars
|
|
146
|
+
bunx cf dev # Vite on http://localhost:5173
|
|
147
|
+
curl -s http://localhost:5173/health
|
|
148
|
+
curl -s http://localhost:5173/openapi.json
|
|
149
|
+
curl -s http://localhost:5173/v1/notes -H "authorization: Bearer $(sed 's/^DEVELOPMENT_TOKEN=//' .dev.vars)"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Several Workers together: the caller's `vite.config.ts` runs the others as auxiliary Workers,
|
|
153
|
+
`cloudflare({ auxiliaryWorkers: [{ config: otherWorker, devOnly: true }] })`.
|
|
154
|
+
|
|
155
|
+
## Native endpoints (served automatically)
|
|
156
|
+
|
|
157
|
+
`/` (name, OpenAPI path, MCP path), `/health`, `/openapi.json`, `/openapi.yaml`, `/openapi.yml`,
|
|
158
|
+
`/.well-known/oauth-protected-resource` and `…/mcp`. They are reserved paths.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Errors and results
|
|
2
|
+
|
|
3
|
+
## Results
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { err, ok } from '@arbol-ai/maximus';
|
|
7
|
+
|
|
8
|
+
return note ? ok(note) : err(errors.noteNotFound.create());
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
A handler returns exactly `{ ok: true, value }` or `{ ok: false, error }`. Anything else, a throw, an
|
|
12
|
+
output that fails its schema or exceeds its byte limit, or a failure outside the catalog becomes
|
|
13
|
+
`INTERNAL_ERROR`, reported to diagnostics without its message.
|
|
14
|
+
|
|
15
|
+
## Catalog
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
export const errors = defineErrors({
|
|
19
|
+
noteNotFound: { code: 'NOTE_NOT_FOUND', status: 404, message: 'The note does not exist.' },
|
|
20
|
+
quotaExceeded: {
|
|
21
|
+
code: 'QUOTA_EXCEEDED',
|
|
22
|
+
status: 429,
|
|
23
|
+
message: 'The organization has reached its note quota.',
|
|
24
|
+
retryable: true,
|
|
25
|
+
retryAfter: 3600,
|
|
26
|
+
dataSchema: t.Object({ limit: t.Integer() }, { additionalProperties: false }),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
errors.quotaExceeded.create({ limit: 100 }); // data required when dataSchema has required fields
|
|
31
|
+
errors.noteNotFound.is(value);
|
|
32
|
+
errors.status('NOTE_NOT_FOUND'); // 404
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- Codes `UPPER_SNAKE_CASE`, unique including standard codes; status 400–599; messages fixed and
|
|
36
|
+
value-free; `dataSchema` strict.
|
|
37
|
+
- Standard names are reserved keys: `invalidInput`, `unauthorized`, `forbidden`, `notFound`,
|
|
38
|
+
`methodNotAllowed`, `tooLarge`, `unsupportedMedia`, `rateLimited`, `internal`,
|
|
39
|
+
`upstreamUnavailable`, `upstreamTimeout`, `outcomeUnknown`. Every catalog contains them, so use
|
|
40
|
+
`errors.forbidden.create()` etc. `standardErrors` is the catalog with nothing added.
|
|
41
|
+
- The catalog's members are reserved keys too: `schema`, `definitions`, `status`, `retryAfter`,
|
|
42
|
+
`validate`.
|
|
43
|
+
- Return only failures from this application's catalog. A dependency's failure must be translated.
|
|
44
|
+
|
|
45
|
+
## Standard codes
|
|
46
|
+
|
|
47
|
+
| Code | Status | Retryable | Typical cause |
|
|
48
|
+
| --- | --- | --- | --- |
|
|
49
|
+
| `INVALID_INPUT` | 400 | No | Schema refusal with `data.issues` (≤ 10 `{ path, message }`, JSON Pointers); repeated query key; bad JSON |
|
|
50
|
+
| `UNAUTHORIZED` | 401 | No | Missing/invalid token, bad RPC props or principal, invalid proof |
|
|
51
|
+
| `FORBIDDEN` | 403 | No | Missing scope, ineligible actor, absent authority for conditional scopes, proof not admitting the call |
|
|
52
|
+
| `NOT_FOUND` | 404 | No | No route (before authentication), unpinned origin |
|
|
53
|
+
| `HTTP_METHOD_NOT_ALLOWED` | 405 | No | Non-GET on health or a `tokens.resources` path, non-GET/HEAD on assets |
|
|
54
|
+
| `REQUEST_TOO_LARGE` | 413 | No | Body over its limit |
|
|
55
|
+
| `UNSUPPORTED_MEDIA_TYPE` | 415 | No | Non-JSON body; content-encoded byte upload |
|
|
56
|
+
| `RATE_LIMITED` | 429 | Yes (60 s) | The configured rate limit |
|
|
57
|
+
| `INTERNAL_ERROR` | 500 | No | Unexpected error or invalid result |
|
|
58
|
+
| `OUTCOME_UNKNOWN` | 502 | No | Returned by handlers: a write may have happened |
|
|
59
|
+
| `UPSTREAM_UNAVAILABLE` | 503 | Yes | Returned by handlers |
|
|
60
|
+
| `UPSTREAM_TIMEOUT` | 504 | Yes | Returned by handlers |
|
|
61
|
+
|
|
62
|
+
## Presentation
|
|
63
|
+
|
|
64
|
+
HTTP: the catalog status, the envelope, `Retry-After` for `retryAfter`. MCP: a tool result with
|
|
65
|
+
`isError: true` and the failure JSON. RPC: the `Result` itself. The typed client returns the envelope,
|
|
66
|
+
or with `response: 'data'` throws an `Error` whose `cause` is `{ status, failure, requestId }`.
|
|
67
|
+
|
|
68
|
+
## Uncertain outcomes and retries
|
|
69
|
+
|
|
70
|
+
- `retryable: true` only when the same call may succeed later (rate limit, outage, timeout).
|
|
71
|
+
- When a write may have been applied and its answer was lost, return
|
|
72
|
+
`errors.outcomeUnknown.create()`. Callers reconcile (read the resource, poll an operation) before
|
|
73
|
+
repeating anything. Record intent before provider writes and use idempotency keys where possible.
|
|
74
|
+
- Never retry uncertain writes or paid provider calls blindly; never turn an outage into an empty
|
|
75
|
+
success.
|
|
76
|
+
- `data` holds finite codes, counts, positions and field paths. Never submitted values, credentials
|
|
77
|
+
or provider bodies.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Migrating from 2.x
|
|
2
|
+
|
|
3
|
+
Move every `@getarbol/maximus*` dependency to the same 3.x version together.
|
|
4
|
+
(`@getarbol/maximus-postgres` is versioned on its own and unaffected.) Signed admission, unsigned
|
|
5
|
+
delegation and the service artifact below describe 3.x and 4.x; 5.0 removed them (see
|
|
6
|
+
`migration-to-v5.md`).
|
|
7
|
+
|
|
8
|
+
## Breaking changes in 3.0.0
|
|
9
|
+
|
|
10
|
+
| Area | 2.x | 3.x | Do |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| Issuer | `tokens.issuer` had a built-in default | No default | Set `tokens.issuer` everywhere OAuth tokens are verified or documented. Missing → every OAuth token is 401 and `/openapi.json` is 500. |
|
|
13
|
+
| Proof type | `arbol-admission+jwt` | `maximus-admission+jwt` | Release signer and all owners together. |
|
|
14
|
+
| OpenAPI extensions | `x-arbol-service-id`, `-publication`, `-publish`, `-input-schema`, `-actor-kinds` | `x-maximus-…` | Update readers of classified documents. |
|
|
15
|
+
| Security schemes | `arbolToken`, `arbolHuman`, `arbolMachine` | `oauth2`, `bearer` | Update clients and generators. |
|
|
16
|
+
| Service owner | `'arbol'` | `'platform'` | Replace in `service.owner`. |
|
|
17
|
+
| `maximus token` | `ARBOL_CLIENT_ID`, `ARBOL_CLIENT_SECRET`, `ARBOL_ISSUER` | `--issuer` (required), `MAXIMUS_CLIENT_ID`, `MAXIMUS_CLIENT_SECRET` | Removed in 4.0: drop it from operator scripts. |
|
|
18
|
+
|
|
19
|
+
## Notable 3.x additions
|
|
20
|
+
|
|
21
|
+
- 3.1.0: `@getarbol/maximus/projection`, `callAdmitted`, admission service schemas, `OUTCOME_UNKNOWN`.
|
|
22
|
+
- 3.2.0: `checkSchema`, `readSchema`.
|
|
23
|
+
- 3.3.0: `INVALID_INPUT` carries `data.issues` everywhere; clients expecting `data: {}` must accept it.
|
|
24
|
+
- 3.3.1: plain routes beneath a transport path.
|
|
25
|
+
- 3.4.0: `admission.attachments`; `describe` for an internal runtime's agent.
|
|
26
|
+
- 3.4.1: `callAdmitted` fixed for real Service Binding stubs; upgrade dispatchers from 3.4.0.
|
|
27
|
+
- 3.5.0: runtime-free `@getarbol/maximus/admitted` and `@getarbol/maximus/failures`.
|
|
28
|
+
- 3.6.0: `.build()` refuses a missing or non-HTTPS `tokens.issuer` and input codecs outside
|
|
29
|
+
`inputSchema()`.
|
|
30
|
+
|
|
31
|
+
## Classifying an unclassified (pre-2.13) service
|
|
32
|
+
|
|
33
|
+
1. `publication: 'private' | 'selected'`.
|
|
34
|
+
2. `publish: { rest, mcp }` on every operation (`true` only with the transport declared, never for
|
|
35
|
+
internal operations or in a private service).
|
|
36
|
+
3. `actorKinds` on every operation.
|
|
37
|
+
4. `api: { resource, verb, id? }` on every published or admitted operation.
|
|
38
|
+
5. `service: { kind, owner, publicName?, dependencies?, connections?, roles? }`.
|
|
39
|
+
6. `bun --bun maximus check`, then `bun --bun maximus export --allow-dirty --out artifact.json`.
|
|
40
|
+
|
|
41
|
+
`.build()` names the next operation and rule to fix.
|
|
42
|
+
|
|
43
|
+
## Unsigned delegation → signed admission
|
|
44
|
+
|
|
45
|
+
| | Before | After |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| Operation | `delegated: { surfaces, actorKinds, clientClasses }` | `admission: { callers, ingresses }`, `actorKinds` |
|
|
48
|
+
| Application | `delegation: { authorize(env, grant) }` | `admission: { verification, authorize }` |
|
|
49
|
+
| Props | `{ caller: 'gateway', mode: 'delegated' }` | `{ caller: '<dispatcher>', mode: 'admitted' }` |
|
|
50
|
+
|
|
51
|
+
Same `worker.delegatedEntrypoint`. Unsigned grants are refused once `publication` is set.
|
|
52
|
+
|
|
53
|
+
## From 1.x
|
|
54
|
+
|
|
55
|
+
Explicit packages instead of Elysia/Eden; one fluent base with mounted resource modules; opt-in MCP
|
|
56
|
+
and telemetry; remove `Function` test shims; check consumers' RPC types against `Service<T>` with a
|
|
57
|
+
`never` control; keep Durable Object class names, migration tags and durable keys.
|
|
58
|
+
|
|
59
|
+
## Verify
|
|
60
|
+
|
|
61
|
+
Typecheck, tests, dry-run bundle, `maximus check` for classified services, then verify the deployed
|
|
62
|
+
Worker (health, OpenAPI, a 401 without token, a real call).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Migrating to 5.0
|
|
2
|
+
|
|
3
|
+
The platform Gateway is a proxy to each service's own origin; services call each other over native
|
|
4
|
+
RPC. 5.0 removes what nothing calls anymore. TypeScript names each removed option that remains.
|
|
5
|
+
|
|
6
|
+
## Remove from the application
|
|
7
|
+
|
|
8
|
+
- `gateway: { audience, issuer, … }`: list the platform audience in `tokens.audience` instead
|
|
9
|
+
(`[OWN, PLATFORM]`); the origin verifies the forwarded token like any other. Move rules that
|
|
10
|
+
`gateway.authorize` applied into context or middleware.
|
|
11
|
+
- `originRoutes`: a selected service's origin serves and documents every declared route (as
|
|
12
|
+
`'declared'` did). With `'none'` it now also serves `/`, `/openapi.json` and `/health`; a web app
|
|
13
|
+
that needs `/` sets `http.basePath`.
|
|
14
|
+
- `contract`, `admission`, `delegation`.
|
|
15
|
+
- `service.kind`, `service.owner`, `service.dependencies`, `service.connections` (keep
|
|
16
|
+
`publicName`, `permissions`, `roles`).
|
|
17
|
+
- On operations: `admission`, `delegated`, `resourceSlots`, `execution`.
|
|
18
|
+
|
|
19
|
+
## Remove from the Worker
|
|
20
|
+
|
|
21
|
+
- `worker.delegatedEntrypoint` and its export (and the export declared in `cloudflare.config.ts` or
|
|
22
|
+
Wrangler), and bindings with props `mode: 'token' | 'admitted' | 'delegated'`.
|
|
23
|
+
- `maximus publish`, `maximus export`, `maximus permissions` steps in CI.
|
|
24
|
+
|
|
25
|
+
## Imports
|
|
26
|
+
|
|
27
|
+
- `isResult`: from `@getarbol/maximus` (was `/admitted`).
|
|
28
|
+
- Gone: `/admitted` (`callAdmitted`), `/delegation` (everything), `exportServiceContract`,
|
|
29
|
+
`ContractBuild`, `gatewayServes`, `GatewayPolicy`, `GatewayCall`, `OriginRoutes`, and from
|
|
30
|
+
`/projection` `publicName`, `cliCommand`, `restRoute`, `encodeQuery`, `decodeQuery`.
|
|
31
|
+
- `originServes(publication, operation, surface)` lost its `originRoutes` argument.
|
|
32
|
+
- `authority.admission` is gone; `authority.token` remains.
|
|
33
|
+
|
|
34
|
+
## OpenAPI
|
|
35
|
+
|
|
36
|
+
`x-maximus-gateway`, `x-maximus-failures` and `x-maximus-service.kind` are gone; `x-maximus-tokens:
|
|
37
|
+
{ issuer, audiences }` names whose tokens the service verifies. The `artifact` projection is gone.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Deploying and verifying
|
|
2
|
+
|
|
3
|
+
## A new service (`@arbol-ai/maximus`)
|
|
4
|
+
|
|
5
|
+
One command, `bunx @arbol-ai/maximus init <dir> --name <name>`: a starter project on the CLI's own
|
|
6
|
+
release, scripted with `cf`; it passes `bun run verify` as generated. Replace the placeholder origin,
|
|
7
|
+
audience and issuer in `src/app.ts` before deploying. Develop, build and deploy with `cf dev`,
|
|
8
|
+
`cf build`, `cf workers types` and `cf deploy`: Maximus does not wrap them.
|
|
9
|
+
|
|
10
|
+
`createOpenApi(app)` builds the document the origin serves at `/openapi.json`, for SDKs or a contract
|
|
11
|
+
check at build time. Nothing is published from the service: deploying it is the release.
|
|
12
|
+
|
|
13
|
+
## Before deploying
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
bun run typecheck # cf build does not typecheck
|
|
17
|
+
bun run test
|
|
18
|
+
cf build # then read .cloudflare/output/v0/workers/default/worker.config.json: no dev token
|
|
19
|
+
cf deploy --prebuilt --mode production # --dry-run first; cf auth login or CLOUDFLARE_API_TOKEN
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`nodejs_compat` on; secrets as `bindings.secret()`, uploaded with `cf deploy --secrets-file` or kept
|
|
23
|
+
in Secrets Store, never in `bindings.text()`; `.dev.vars` local only, and the development token
|
|
24
|
+
declared for `cf dev` alone; Durable Object class names unchanged and declared as exports; preview
|
|
25
|
+
environments use their own audience, state and credentials.
|
|
26
|
+
|
|
27
|
+
## After deploying
|
|
28
|
+
|
|
29
|
+
Verify the real Worker: `/health` version; `/openapi.json` operations (`verifyContract`); `401`
|
|
30
|
+
without a token; a real token call for a test organization; MCP `tools/list`;
|
|
31
|
+
RPC calls through a real caller. Keep tokens and raw responses in an ignored `.private/`
|
|
32
|
+
(0700/0600) and never print sensitive bodies to shared logs. Mocks are never evidence of a live
|
|
33
|
+
deployment.
|
|
34
|
+
|
|
35
|
+
## Releasing Maximus itself (framework repository)
|
|
36
|
+
|
|
37
|
+
`bun run verify` (build, typecheck, lint, tests, packed-package and isolation checks), packages in
|
|
38
|
+
dependency order from packed tarballs, never with `workspace:` or `file:` dependencies; then install
|
|
39
|
+
from the registry, run consumers' workerd tests and dry bundles, and verify a real deployment.
|