@arbol-ai/maximus 7.3.0 → 7.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 +1 -1
- package/dist/body.d.ts +1 -1
- package/dist/chunks/builder-BiXv7d2v.js +100 -0
- package/dist/chunks/{execution-B-yy4C7N.js → define-app-DvD_1jUE.js} +5 -71
- package/dist/chunks/errors-D7zG9kx9.js +126 -0
- package/dist/chunks/execution-kVUJPy1A.js +71 -0
- package/dist/chunks/http-paths-yKD6TSNJ.js +199 -0
- package/dist/chunks/prepare-project-CMyGSEtI.js +236 -0
- package/dist/chunks/prepare-project-MtS0-W_n.js +3 -0
- package/dist/chunks/{runtime-BPnaa-NK.js → runtime-DlqA7J38.js} +4 -3
- package/dist/chunks/{src-DPSpGNnT.js → src-N3oyx5QF.js} +31 -104
- package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
- package/dist/chunks/{types-BWxDd3tY.d.ts → types-DQdfRF3f.d.ts} +13 -4
- package/dist/client/client.d.ts +1 -1
- package/dist/client/client.js +2 -2
- package/dist/diagnostics.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -124
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -197
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +3 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +3 -3
- package/dist/project/config.d.ts +101 -0
- package/dist/project/config.js +80 -0
- package/dist/project/index.d.ts +1 -1
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +1 -1
- package/dist/standard-failures.js +1 -72
- package/dist/tooling/cli.js +10 -10
- package/dist/tooling/vite.d.ts +1 -1
- package/dist/tooling/vite.js +38 -25
- package/dist/webhooks.d.ts +1 -1
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +5 -1
- package/skills/maximus/SKILL.md +4 -5
- package/skills/maximus/references/building-a-service.md +8 -8
- package/skills/maximus/references/publishing-and-verification.md +14 -11
- package/templates/project/.agents/skills/project/SKILL.md.template +7 -7
- package/templates/project/CLAUDE.md.template +10 -7
- package/templates/project/README.md.template +9 -8
- package/templates/project/cloudflare.config.ts.template +1 -1
- package/templates/project/{src/application.ts.template → maximus.config.ts.template} +4 -10
- package/templates/project/middleware/10-response.ts.template +13 -0
- package/templates/project/package.json.template +4 -0
- package/templates/project/routes/v1/greeting.ts.template +33 -17
- package/templates/project/tsconfig.json.template +1 -0
- package/templates/service/README.md.template +1 -1
- package/dist/chunks/prepare-project-zi106pWF.js +0 -146
- package/templates/project/src/app.ts.template +0 -2
- package/templates/project/src/index.ts.template +0 -3
- package/templates/project/src/worker.ts.template +0 -6
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/** The framework's own failures, by the name `standardErrors` gives each. */
|
|
3
|
-
const STANDARD_FAILURES = {
|
|
4
|
-
invalidInput: {
|
|
5
|
-
code: "INVALID_INPUT",
|
|
6
|
-
status: 400,
|
|
7
|
-
message: "The request does not match the published schema."
|
|
8
|
-
},
|
|
9
|
-
unauthorized: {
|
|
10
|
-
code: "UNAUTHORIZED",
|
|
11
|
-
status: 401,
|
|
12
|
-
message: "A valid access token is required."
|
|
13
|
-
},
|
|
14
|
-
forbidden: {
|
|
15
|
-
code: "FORBIDDEN",
|
|
16
|
-
status: 403,
|
|
17
|
-
message: "The token does not authorize this operation."
|
|
18
|
-
},
|
|
19
|
-
notFound: {
|
|
20
|
-
code: "NOT_FOUND",
|
|
21
|
-
status: 404,
|
|
22
|
-
message: "The requested operation does not exist."
|
|
23
|
-
},
|
|
24
|
-
methodNotAllowed: {
|
|
25
|
-
code: "HTTP_METHOD_NOT_ALLOWED",
|
|
26
|
-
status: 405,
|
|
27
|
-
message: "The HTTP method is not supported for this resource."
|
|
28
|
-
},
|
|
29
|
-
tooLarge: {
|
|
30
|
-
code: "REQUEST_TOO_LARGE",
|
|
31
|
-
status: 413,
|
|
32
|
-
message: "The request exceeds the allowed size."
|
|
33
|
-
},
|
|
34
|
-
unsupportedMedia: {
|
|
35
|
-
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
36
|
-
status: 415,
|
|
37
|
-
message: "The request content type is not supported."
|
|
38
|
-
},
|
|
39
|
-
rateLimited: {
|
|
40
|
-
code: "RATE_LIMITED",
|
|
41
|
-
status: 429,
|
|
42
|
-
message: "The request rate limit was exceeded. Try again later.",
|
|
43
|
-
retryable: true,
|
|
44
|
-
retryAfter: 60
|
|
45
|
-
},
|
|
46
|
-
internal: {
|
|
47
|
-
code: "INTERNAL_ERROR",
|
|
48
|
-
status: 500,
|
|
49
|
-
message: "The service could not complete the operation."
|
|
50
|
-
},
|
|
51
|
-
upstreamUnavailable: {
|
|
52
|
-
code: "UPSTREAM_UNAVAILABLE",
|
|
53
|
-
status: 503,
|
|
54
|
-
message: "The upstream service could not complete the request.",
|
|
55
|
-
retryable: true
|
|
56
|
-
},
|
|
57
|
-
upstreamTimeout: {
|
|
58
|
-
code: "UPSTREAM_TIMEOUT",
|
|
59
|
-
status: 504,
|
|
60
|
-
message: "The upstream service did not respond before its deadline.",
|
|
61
|
-
retryable: true
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* A write may have been applied and its answer was lost. Never retried: the caller reconciles (reads
|
|
65
|
-
* the resource or polls the operation) before deciding to repeat anything.
|
|
66
|
-
*/
|
|
67
|
-
outcomeUnknown: {
|
|
68
|
-
code: "OUTCOME_UNKNOWN",
|
|
69
|
-
status: 502,
|
|
70
|
-
message: "The operation may have been applied; check its result before repeating it."
|
|
71
|
-
}
|
|
72
|
-
};
|
|
1
|
+
import { t as STANDARD_FAILURES } from "./chunks/standard-failures-CLjxS2ea.js";
|
|
73
2
|
|
|
74
3
|
export { STANDARD_FAILURES };
|
package/dist/tooling/cli.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as prepareProject } from "../chunks/prepare-project-zi106pWF.js";
|
|
3
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
4
2
|
import { existsSync, mkdirSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
5
4
|
import { parseArgs } from "node:util";
|
|
6
5
|
import { randomBytes } from "node:crypto";
|
|
7
6
|
|
|
@@ -45,7 +44,7 @@ function scaffold(directory, name, layout = "service") {
|
|
|
45
44
|
})) {
|
|
46
45
|
if (!file.isFile() || !file.name.endsWith(".template")) continue;
|
|
47
46
|
const source = resolve(file.parentPath, file.name);
|
|
48
|
-
if (layout === "project" && templateName === "service" && (relative(template, source).startsWith("tests/") || file.name === "vitest.config.ts.template")) continue;
|
|
47
|
+
if (layout === "project" && templateName === "service" && (relative(template, source).startsWith("tests/") || relative(template, source).startsWith("src/") || file.name === "vitest.config.ts.template")) continue;
|
|
49
48
|
const target = resolve(root, relative(template, source).replace(/\.template$/, ""));
|
|
50
49
|
mkdirSync(dirname(target), { recursive: true });
|
|
51
50
|
let text = readFileSync(source, "utf-8");
|
|
@@ -65,14 +64,14 @@ function scaffold(directory, name, layout = "service") {
|
|
|
65
64
|
return {
|
|
66
65
|
directory: root,
|
|
67
66
|
layout,
|
|
68
|
-
next: layout === "project" ? "Run bun install and bun run dev. The public home page says Hello World. Configure the origin and token policy in
|
|
67
|
+
next: layout === "project" ? "Run bun install and bun run dev. The public home page says Hello World. Configure the origin and token policy in maximus.config.ts before adding production callers. Use bun run verify for types, lint and build, then bun run deploy." : "Run bun install and bun run dev, and call it with the DEVELOPMENT_TOKEN in .dev.vars. Before the first deployment, set origin, audience and issuer in src/app.ts, run bun run verify, sign in with cf auth login and run bun run deploy."
|
|
69
68
|
};
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
// src/tooling/cli.ts
|
|
73
72
|
/**
|
|
74
|
-
* The `maximus` command
|
|
75
|
-
*
|
|
73
|
+
* The `maximus` command scaffolds services and reconciles project entries. Vite+ owns development and
|
|
74
|
+
* builds; Cloudflare owns type generation and deployment.
|
|
76
75
|
*/
|
|
77
76
|
const { values, positionals } = parseArgs({
|
|
78
77
|
allowPositionals: true,
|
|
@@ -97,16 +96,17 @@ const [command, target] = positionals;
|
|
|
97
96
|
const USAGE = [
|
|
98
97
|
"Usage: maximus init <new-directory> --name <name> [--layout service|project]",
|
|
99
98
|
" maximus prepare [directory] [--mode production|development]",
|
|
100
|
-
"Creates a
|
|
101
|
-
"
|
|
99
|
+
"Creates a Vite+ service. Use its dev, build, verify and deploy package scripts.",
|
|
100
|
+
"Project layout generates entries from maximus.config.ts, routes/ and middleware/."
|
|
102
101
|
].join("\n");
|
|
103
102
|
if (values.help) {
|
|
104
103
|
console.info(USAGE);
|
|
105
104
|
process.exit(0);
|
|
106
105
|
}
|
|
107
106
|
/** Runs the command the arguments name. */
|
|
108
|
-
function run() {
|
|
107
|
+
async function run() {
|
|
109
108
|
if (command === "prepare") {
|
|
109
|
+
const { prepareProject } = await import("../chunks/prepare-project-MtS0-W_n.js");
|
|
110
110
|
console.info(JSON.stringify(prepareProject(target ?? ".", values.mode)));
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
@@ -120,7 +120,7 @@ function run() {
|
|
|
120
120
|
console.info(JSON.stringify(scaffold(target, values.name, values.layout)));
|
|
121
121
|
}
|
|
122
122
|
try {
|
|
123
|
-
run();
|
|
123
|
+
await run();
|
|
124
124
|
} catch (error) {
|
|
125
125
|
console.error(error instanceof Error && !process.env.MAXIMUS_DEBUG ? `maximus: ${error.message}` : error);
|
|
126
126
|
process.exitCode = 1;
|
package/dist/tooling/vite.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
|
-
/** Prepare
|
|
2
|
+
/** Prepare before every build and before Vite invalidates source modules during development. */
|
|
3
3
|
export declare function maximusProject(): Plugin;
|
package/dist/tooling/vite.js
CHANGED
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import { n as PROJECT_DIRECTORIES, t as prepareProject } from "../chunks/prepare-project-
|
|
1
|
+
import { n as PROJECT_DIRECTORIES, t as prepareProject } from "../chunks/prepare-project-CMyGSEtI.js";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { relative, resolve } from "node:path";
|
|
3
4
|
|
|
4
5
|
// src/tooling/vite.ts
|
|
5
|
-
/** Optional Vite integration. It
|
|
6
|
-
/** Prepare
|
|
6
|
+
/** Optional Vite integration. It reconciles static imports before Cloudflare reads the Worker. */
|
|
7
|
+
/** Prepare before every build and before Vite invalidates source modules during development. */
|
|
7
8
|
function maximusProject() {
|
|
8
9
|
let root = process.cwd();
|
|
9
10
|
let mode = "production";
|
|
11
|
+
let previous;
|
|
12
|
+
const reconcile = () => {
|
|
13
|
+
const current = prepareProject(root, mode);
|
|
14
|
+
const restart = previous !== void 0 && (previous.config !== current.config || previous.durableObjects.join("\n") !== current.durableObjects.join("\n"));
|
|
15
|
+
previous = current;
|
|
16
|
+
return {
|
|
17
|
+
...current,
|
|
18
|
+
restart
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const isProjectFile = (file) => {
|
|
22
|
+
const path = relative(root, file).split(/[\\/]/);
|
|
23
|
+
return PROJECT_DIRECTORIES.some((name) => name === path[0]) || path.length === 1 && /^maximus\.config\.(?:ts|mts|js|mjs)$/.test(path[0] ?? "") || path[0] === "src" && ["application.ts", "worker.ts"].includes(path[1] ?? "");
|
|
24
|
+
};
|
|
10
25
|
return {
|
|
11
26
|
name: "maximus-project",
|
|
12
27
|
enforce: "pre",
|
|
13
28
|
config(config, environment) {
|
|
14
29
|
root = resolve(config.root ?? root);
|
|
15
30
|
({mode} = environment);
|
|
16
|
-
|
|
31
|
+
reconcile();
|
|
32
|
+
},
|
|
33
|
+
buildStart() {
|
|
34
|
+
const current = reconcile();
|
|
35
|
+
for (const file of current.files) this.addWatchFile(file);
|
|
36
|
+
if (current.config) this.addWatchFile(resolve(root, current.config));
|
|
37
|
+
for (const directory of PROJECT_DIRECTORIES) {
|
|
38
|
+
const path = resolve(root, directory);
|
|
39
|
+
if (existsSync(path)) this.addWatchFile(path);
|
|
40
|
+
}
|
|
17
41
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
server.
|
|
25
|
-
|
|
26
|
-
server.config.logger.error(error instanceof Error ? error.message : String(error));
|
|
27
|
-
server.ws.send({
|
|
28
|
-
type: "error",
|
|
29
|
-
err: {
|
|
30
|
-
message: error instanceof Error ? error.message : String(error),
|
|
31
|
-
stack: ""
|
|
32
|
-
}
|
|
33
|
-
});
|
|
42
|
+
hotUpdate: {
|
|
43
|
+
order: "pre",
|
|
44
|
+
async handler({ file, server }) {
|
|
45
|
+
if (!isProjectFile(file)) return;
|
|
46
|
+
const current = reconcile();
|
|
47
|
+
if (current.restart) {
|
|
48
|
+
await server.restart();
|
|
49
|
+
return [];
|
|
34
50
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
server.httpServer?.once("close", () => {
|
|
38
|
-
server.watcher.off("add", update).off("unlink", update);
|
|
39
|
-
});
|
|
51
|
+
if (current.changed) this.environment.hot.send({ type: "full-reload" });
|
|
52
|
+
}
|
|
40
53
|
}
|
|
41
54
|
};
|
|
42
55
|
}
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Rn as Failure, kn as Result } from "./chunks/types-DQdfRF3f.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. */
|
|
@@ -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/types-
|
|
1
|
+
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/types-DQdfRF3f.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": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, with its OpenAPI, typed client and CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -118,6 +118,10 @@
|
|
|
118
118
|
"./vite": {
|
|
119
119
|
"types": "./dist/tooling/vite.d.ts",
|
|
120
120
|
"import": "./dist/tooling/vite.js"
|
|
121
|
+
},
|
|
122
|
+
"./config": {
|
|
123
|
+
"types": "./dist/project/config.d.ts",
|
|
124
|
+
"import": "./dist/project/config.js"
|
|
121
125
|
}
|
|
122
126
|
},
|
|
123
127
|
"publishConfig": {
|
package/skills/maximus/SKILL.md
CHANGED
|
@@ -12,18 +12,17 @@ pipeline, never around it.
|
|
|
12
12
|
|
|
13
13
|
## Workflow
|
|
14
14
|
|
|
15
|
-
1. **Read the service first.**
|
|
15
|
+
1. **Read the service first.** For a project layout, start with `maximus.config.ts` and the project-structure guide; `src/` is optional and routes/middleware are discovered. For explicit composition, find `maximus<Env>(…)` (usually `src/application.ts`), the resource
|
|
16
16
|
modules (`src/api/<resource>/operations.ts`), the composition (`src/app.ts`) and the Worker
|
|
17
17
|
(`src/index.ts`). Keep the project's existing folders and named domain functions.
|
|
18
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`).
|
|
20
|
-
modules in `app.ts`. See `references/adding-an-operation.md`.
|
|
19
|
+
scope, a truthful effect and only the transports it needs (`http`, `mcp`, `rpc`). Project routes are discovered; explicit service layouts mount modules in `app.ts`. See `references/adding-an-operation.md`.
|
|
21
20
|
3. **Return Results.** Expected failures are `err(catalog.x.create())` from the application's own
|
|
22
21
|
catalog; throw only for the unexpected. See `references/errors-and-results.md`.
|
|
23
22
|
4. **Prepare context with `.derive()`** in the group that needs it, and wrap with `.use()` only for
|
|
24
23
|
cross-cutting behavior after authorization.
|
|
25
|
-
5. **Verify** with the project's typecheck, lint and
|
|
26
|
-
|
|
24
|
+
5. **Verify** with the project's typecheck, lint and Vite+ build, then a dry-run deploy. Run tests only on an explicit human request. Use
|
|
25
|
+
`cf deploy --prebuilt --mode production --dry-run`. See `references/testing.md` and
|
|
27
26
|
`references/publishing-and-verification.md`.
|
|
28
27
|
|
|
29
28
|
## Decisions
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Building a service
|
|
2
2
|
|
|
3
|
-
For
|
|
4
|
-
|
|
5
|
-
`
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
explicitly in `cloudflare.config.ts
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
For the API-first project layout, use `maximus init <directory> --name <name> --layout project`.
|
|
4
|
+
Configure the application in `maximus.config.ts`; `src/` is optional domain code. Routes export
|
|
5
|
+
`GET`, `POST`, `PUT`, `PATCH` or `DELETE` through `defineRoute` from the generated `#maximus/routes` alias.
|
|
6
|
+
`defineMiddleware` (also named `defineRequestMiddleware`) wraps HTTP requests; `defineOperationMiddleware` runs after native admission on
|
|
7
|
+
HTTP, MCP and RPC. Middleware files run in filename order. The Vite+ plugin reconciles entries on
|
|
8
|
+
builds and source changes. Configure infrastructure explicitly in `cloudflare.config.ts`, importing
|
|
9
|
+
`.maximus/entry.ts` as its entrypoint. Legacy route factories and explicit service composition below
|
|
10
|
+
remain supported. Read `docs/guides/project-structure.md` for configuration, migration and conventions.
|
|
11
11
|
|
|
12
12
|
## Packages
|
|
13
13
|
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## A new service (`@arbol-ai/maximus`)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
release
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Run `bunx @arbol-ai/maximus init <dir> --name <name> --layout project` for a Vite+ project on the CLI's
|
|
6
|
+
own release. Configure its origin and token policy in `maximus.config.ts`. The compatible service
|
|
7
|
+
layout is still available and keeps `src/app.ts`. Use the generated package scripts: Vite+ owns
|
|
8
|
+
development, builds and checks; Cloudflare owns types and deployment. Maximus prepares the source
|
|
9
|
+
graph before Vite loads the generated Worker.
|
|
9
10
|
|
|
10
11
|
`createOpenApi(app)` builds the document the origin serves at `/openapi.json`, for SDKs or a contract
|
|
11
12
|
check at build time. Nothing is published from the service: deploying it is the release.
|
|
@@ -13,15 +14,15 @@ check at build time. Nothing is published from the service: deploying it is the
|
|
|
13
14
|
## Before deploying
|
|
14
15
|
|
|
15
16
|
```sh
|
|
16
|
-
bun run
|
|
17
|
-
|
|
18
|
-
cf
|
|
17
|
+
bun run verify # preparation, types, lint/format and build; no tests
|
|
18
|
+
# Read .cloudflare/output/v0/workers/default/worker.config.json: no development token.
|
|
19
|
+
cf deploy --prebuilt --mode production --dry-run
|
|
19
20
|
cf deploy --prebuilt --mode production # --dry-run first; cf auth login or CLOUDFLARE_API_TOKEN
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
`nodejs_compat` on; secrets as `bindings.secret()`, uploaded with `cf deploy --secrets-file` or kept
|
|
23
24
|
in Secrets Store, never in `bindings.text()`; `.dev.vars` local only, and the development token
|
|
24
|
-
declared for
|
|
25
|
+
declared for development mode alone; Durable Object class names unchanged and declared as exports; preview
|
|
25
26
|
environments use their own audience, state and credentials.
|
|
26
27
|
|
|
27
28
|
## After deploying
|
|
@@ -34,6 +35,8 @@ deployment.
|
|
|
34
35
|
|
|
35
36
|
## Releasing Maximus itself (framework repository)
|
|
36
37
|
|
|
37
|
-
`bun run verify`
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
Run `bun run verify` for builds, workspace types, lint and format. Inspect a packed tarball and build
|
|
39
|
+
consumers from it; never publish `workspace:` or `file:` dependencies. After publication, install from
|
|
40
|
+
the registry, produce the consumer's dry bundle and verify the deployed service. Test suites and
|
|
41
|
+
package smoke tests are separate: run them only after an explicit human request. Neither release
|
|
42
|
+
authorization nor a successful build is evidence that tests were authorized or passed.
|
|
@@ -3,13 +3,13 @@ name: __PROJECT_NAME__-development
|
|
|
3
3
|
description: Extend the __PROJECT_NAME__ Maximus backend using its optional file conventions.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Read CLAUDE.md and the installed Maximus skill.
|
|
7
|
-
|
|
8
|
-
Declare strict input/output schemas, scope and
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
Read CLAUDE.md and the installed Maximus skill. Configure the application in maximus.config.ts.
|
|
7
|
+
Add named GET/POST/PUT/PATCH/DELETE declarations to routes/v1/, importing defineRoute from #maximus/routes.
|
|
8
|
+
Declare strict input/output schemas, scope, effect and explicit MCP/RPC exposure. Use optional src/ for
|
|
9
|
+
named domain functions. Middleware is discovered in filename order: defineMiddleware wraps requests;
|
|
10
|
+
defineOperationMiddleware applies policy after authentication across transports. Keep principal-based
|
|
11
|
+
policy in the operation phase. Read the Maximus project-structure guide before adding another module kind.
|
|
12
|
+
Build reconciliation owns .maximus/; never edit generated entries. Cloud resources and SQL remain explicit.
|
|
13
13
|
Run bun run verify for non-test validation. Tests require a human request.
|
|
14
14
|
|
|
15
15
|
Vite+ owns the root toolchain: `vite.config.ts` configures lint/format, `vp check` checks them,
|
|
@@ -5,13 +5,16 @@ Read .agents/skills/project/SKILL.md and node_modules/@arbol-ai/maximus/skills/m
|
|
|
5
5
|
|
|
6
6
|
## Structure
|
|
7
7
|
|
|
8
|
-
This is
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
This is an API-first Maximus project. Application and transport policy live in maximus.config.ts.
|
|
9
|
+
Routes export GET/POST/PUT/PATCH/DELETE declarations through defineRoute from #maximus/routes. Keep
|
|
10
|
+
operation names, schemas, scopes and effects explicit; MCP and RPC exposure use the same contracts.
|
|
11
|
+
The Vite plugin and maximus prepare reconcile generated .maximus/ entries before builds. Never edit them.
|
|
12
|
+
src/ is optional shared domain code. Root configuration never imports generated modules or routes.
|
|
13
|
+
Middleware files are ordered by name: defineMiddleware wraps HTTP before token admission and has no
|
|
14
|
+
principal; defineOperationMiddleware runs after native admission across HTTP, MCP and RPC. Middleware
|
|
15
|
+
imports configuration types only. Pages return native public Responses and never contain tenant data.
|
|
16
|
+
Bindings, triggers and Durable Object migrations belong in cloudflare.config.ts. Database migrations
|
|
17
|
+
and public asset admission remain explicit; adding files never provisions infrastructure.
|
|
15
18
|
|
|
16
19
|
## Boundaries
|
|
17
20
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `__PROJECT_NAME__`
|
|
2
2
|
|
|
3
3
|
A Maximus backend on Cloudflare Workers, with Vite+ as its default toolchain. `GET /` returns **Hello World**, `/health` reports liveness,
|
|
4
4
|
and `/api/openapi.json` describes the API. `GET /api/v1/greeting` is authenticated. The starter refuses
|
|
5
|
-
production tokens until an identity provider or verified resolver is configured in
|
|
5
|
+
production tokens until an identity provider or verified resolver is configured in maximus.config.ts.
|
|
6
6
|
|
|
7
7
|
## Development
|
|
8
8
|
|
|
@@ -17,27 +17,28 @@ uses optional directories. Add only the modules the service needs:
|
|
|
17
17
|
|
|
18
18
|
| Directory | Convention |
|
|
19
19
|
| ---------------- | ------------------------------------------------------------------------------------- |
|
|
20
|
-
| routes/ | Versioned
|
|
20
|
+
| routes/ | Versioned named GET/POST declarations; paths and methods are discovered. |
|
|
21
21
|
| pages/ | Fixed-path public response handlers; index.ts serves `/`. |
|
|
22
|
-
| middleware/ |
|
|
22
|
+
| middleware/ | Ordered HTTP wrappers or post-admission operation policy. |
|
|
23
23
|
| crons/ | A `cron` export and a default native scheduled handler. |
|
|
24
24
|
| queues/ | Default queue handlers named after the physical queue. |
|
|
25
25
|
| email/ | Default email handlers named after the full recipient; `_default.ts` is the fallback. |
|
|
26
26
|
| durable-objects/ | Default classes re-exported in PascalCase from kebab-case filenames. |
|
|
27
27
|
| db/ | Application-owned schemas and SQL migrations, applied explicitly. |
|
|
28
|
-
| src/ |
|
|
28
|
+
| src/ | Optional shared domain code; application configuration lives at the root. |
|
|
29
29
|
| public/ | Optional static assets; configure the binding and admitted files before using it. |
|
|
30
30
|
| .maximus/ | Generated imports; ignored and never edited by hand. |
|
|
31
31
|
|
|
32
|
-
The Vite plugin
|
|
33
|
-
|
|
32
|
+
The Vite plugin reconciles modules and named method exports on every build and source change.
|
|
33
|
+
Root maximus.config.ts owns application and transport policy; the Cloudflare config imports the
|
|
34
|
+
generated .maximus/entry.ts entry. No src/ directory or manual route registration is required. `bun run prepare:project` generates the same imports for editors. Files starting
|
|
34
35
|
with `_` are ignored except `email/_default.ts`; `.dev.ts` and `.prod.ts` select their matching mode.
|
|
35
36
|
Platform bindings, cron triggers, queue subscriptions, email routing and Durable Object migrations
|
|
36
37
|
remain explicit Cloudflare configuration. Adding a handler never provisions infrastructure.
|
|
37
38
|
|
|
38
39
|
## Deployment
|
|
39
40
|
|
|
40
|
-
Before deploying, replace the origin and audience in
|
|
41
|
+
Before deploying, replace the origin and audience in maximus.config.ts with the deployed HTTPS URL.
|
|
41
42
|
The GitHub workflow checks pull requests and deploys pushes to `main`. Configure repository or
|
|
42
43
|
organization secrets `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The token needs permission to
|
|
43
44
|
deploy this Worker. `bun run deploy` performs the same non-test validation and deployment locally.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bindings, defineConfig } from 'cf/config';
|
|
2
2
|
|
|
3
|
-
import * as entrypoint from '
|
|
3
|
+
import * as entrypoint from './.maximus/entry.ts' with { type: 'cf-worker' };
|
|
4
4
|
|
|
5
5
|
export default defineConfig(({ mode }) => ({
|
|
6
6
|
worker: {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { defineErrors, err,
|
|
1
|
+
import { defineErrors, err, standardErrors } from '@arbol-ai/maximus';
|
|
2
|
+
import { defineConfig } from '@arbol-ai/maximus/config';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let application = maximus<Env>({
|
|
4
|
+
export default defineConfig<Env>({
|
|
6
5
|
name: '__PROJECT_NAME__',
|
|
7
6
|
namespace: '__PROJECT_NAME__',
|
|
8
7
|
title: '__PROJECT_NAME__',
|
|
@@ -17,10 +16,5 @@ let application = maximus<Env>({
|
|
|
17
16
|
},
|
|
18
17
|
errors: defineErrors({}),
|
|
19
18
|
rpc: { callers: [] },
|
|
19
|
+
worker: { http: { basePath: '/api', healthPath: '/health' } },
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
/** All discovered operations share middleware that runs after native authentication and scope checks. */
|
|
23
|
-
for (const handler of middleware) {
|
|
24
|
-
application = application.use(handler);
|
|
25
|
-
}
|
|
26
|
-
export const base = application;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineMiddleware } from '@arbol-ai/maximus/config';
|
|
2
|
+
|
|
3
|
+
/** Global HTTP policy; protected operations still pass through native token and scope admission. */
|
|
4
|
+
export default defineMiddleware<Env>(async (_request, _env, _context, proceed) => {
|
|
5
|
+
const response = await proceed();
|
|
6
|
+
// Reconstructing a WebSocket upgrade would lose its attached socket.
|
|
7
|
+
if (response.status === 101) {
|
|
8
|
+
return response;
|
|
9
|
+
}
|
|
10
|
+
const headers = new Headers(response.headers);
|
|
11
|
+
headers.set('referrer-policy', 'no-referrer');
|
|
12
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
13
|
+
});
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
|
+
"imports": {
|
|
7
|
+
"#maximus/*": "./.maximus/*.ts"
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
10
|
+
"prepare": "maximus prepare",
|
|
7
11
|
"prepare:project": "maximus prepare",
|
|
8
12
|
"dev": "vp dev",
|
|
9
13
|
"typecheck": "maximus prepare && cf workers types && tsc",
|
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
import { EmptyInputSchema, ok, t } from '@arbol-ai/maximus';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { defineRoute } from '#maximus/routes';
|
|
4
4
|
|
|
5
5
|
const GreetingSchema = t.Object({ message: t.String() }, { $id: 'Greeting', additionalProperties: false });
|
|
6
6
|
|
|
7
|
-
/** The filename supplies the
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
7
|
+
/** The filename supplies the path and this export supplies the method. */
|
|
8
|
+
export const GET = defineRoute(
|
|
9
|
+
'getGreeting',
|
|
10
|
+
{
|
|
11
|
+
title: 'Get a greeting',
|
|
12
|
+
description: 'Return a greeting to an authenticated caller.',
|
|
13
|
+
scope: '__PROJECT_NAME__:greeting:read',
|
|
14
|
+
effect: 'read',
|
|
15
|
+
input: EmptyInputSchema,
|
|
16
|
+
output: GreetingSchema,
|
|
17
|
+
},
|
|
18
|
+
() => Promise.resolve(ok({ message: 'Hello World' }))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const EchoInputSchema = t.Object(
|
|
22
|
+
{ message: t.String({ minLength: 1, maxLength: 200 }) },
|
|
23
|
+
{ additionalProperties: false }
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/** A POST can expose a read operation; its effect remains truthful because no state changes. */
|
|
27
|
+
export const POST = defineRoute(
|
|
28
|
+
'echoGreeting',
|
|
29
|
+
{
|
|
30
|
+
title: 'Echo a greeting',
|
|
31
|
+
description: 'Return the authenticated caller’s greeting without storing it.',
|
|
32
|
+
scope: '__PROJECT_NAME__:greeting:read',
|
|
33
|
+
effect: 'read',
|
|
34
|
+
input: EchoInputSchema,
|
|
35
|
+
output: GreetingSchema,
|
|
36
|
+
},
|
|
37
|
+
(_context, input) => Promise.resolve(ok(input))
|
|
38
|
+
);
|