@arbol-ai/maximus 7.1.0 → 7.3.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/config/oxfmt.mjs +1 -0
- package/config/oxlint.mjs +1 -0
- package/dist/analytics/analytics.d.ts +2 -4
- package/dist/analytics/analytics.js +3 -4
- package/dist/body.d.ts +1 -1
- package/dist/body.js +2 -2
- package/dist/chunks/{body-BcMbreNd.js → body-6LichrQm.js} +1 -2
- package/dist/chunks/{correlation-gaiEoMBr.js → correlation-BEkcFFGT.js} +1 -2
- package/dist/chunks/{execution-qfZuMSIu.js → execution-B-yy4C7N.js} +14 -23
- package/dist/chunks/{json-Dwni3u4c.js → json-Bu4BLT25.js} +2 -3
- package/dist/chunks/prepare-project-zi106pWF.js +146 -0
- package/dist/chunks/{record-D2H3cg8S.js → record-DY-lX9w1.js} +2 -4
- package/dist/chunks/runtime-BPnaa-NK.js +223 -0
- package/dist/chunks/{schemas-q-51wBMQ.js → schemas-CzTvbXb6.js} +6 -11
- package/dist/chunks/{src-Ph5KHCRP.js → src-DPSpGNnT.js} +25 -21
- package/dist/chunks/{telemetry-DvZgrzZn.js → telemetry-BTwB68m5.js} +2 -4
- package/dist/chunks/{types-CGwAhnTE.d.ts → types-BWxDd3tY.d.ts} +128 -64
- package/dist/chunks/{validation-DWxKk1Js.js → validation-r-sgmsqb.js} +3 -6
- package/dist/client/client.d.ts +1 -3
- package/dist/client/client.js +7 -11
- package/dist/diagnostics.d.ts +1 -3
- package/dist/diagnostics.js +2 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +3 -4
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +2 -2
- package/dist/mcp/index.d.ts +2 -4
- package/dist/mcp/index.js +5 -7
- package/dist/postgres/index.d.ts +0 -4
- package/dist/postgres/index.js +2 -4
- package/dist/project/index.d.ts +24 -0
- package/dist/project/index.js +82 -0
- package/dist/projection.d.ts +1 -3
- package/dist/projection.js +1 -2
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +2 -2
- package/dist/standard-failures.d.ts +1 -3
- package/dist/standard-failures.js +1 -2
- package/dist/tooling/cli.js +41 -24
- package/dist/tooling/testing.d.ts +1 -3
- package/dist/tooling/testing.js +1 -2
- package/dist/tooling/vite.d.ts +3 -0
- package/dist/tooling/vite.js +44 -0
- package/dist/webhooks.d.ts +2 -4
- package/dist/webhooks.js +1 -2
- package/dist/workers/runtime.d.ts +2 -112
- package/dist/workers/runtime.js +1 -226
- package/package.json +19 -6
- package/skills/maximus/SKILL.md +1 -1
- package/skills/maximus/references/building-a-service.md +9 -0
- package/templates/project/.agents/skills/project/SKILL.md.template +17 -0
- package/templates/project/.github/workflows/ci.yml.template +36 -0
- package/templates/project/.gitignore.template +10 -0
- package/templates/project/CLAUDE.md.template +34 -0
- package/templates/project/README.md.template +47 -0
- package/templates/project/cloudflare.config.ts.template +24 -0
- package/templates/project/package.json.template +38 -0
- package/templates/project/pages/index.ts.template +11 -0
- package/templates/project/routes/v1/greeting.ts.template +22 -0
- package/templates/project/src/app.ts.template +2 -0
- package/templates/project/src/application.ts.template +26 -0
- package/templates/project/src/index.ts.template +3 -0
- package/templates/project/src/worker.ts.template +6 -0
- package/templates/project/tsconfig.json.template +30 -0
- package/templates/project/vite.config.ts.template +11 -0
- package/templates/service/.github/workflows/ci.yml.template +1 -1
- package/templates/service/.gitignore.template +1 -0
- package/templates/service/CLAUDE.md.template +2 -0
- package/templates/service/README.md.template +7 -7
- package/templates/service/package.json.template +14 -9
- package/templates/service/tests/contract.test.ts.template +1 -1
- package/templates/service/vite.config.ts.template +8 -2
- package/templates/service/vitest.config.ts.template +1 -1
- package/templates/service/oxfmt.config.ts.template +0 -1
- package/templates/service/oxlint.config.ts.template +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { n as PROJECT_DIRECTORIES, t as prepareProject } from "../chunks/prepare-project-zi106pWF.js";
|
|
2
|
+
import { relative, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
// src/tooling/vite.ts
|
|
5
|
+
/** Optional Vite integration. It generates static imports before Cloudflare reads the Worker. */
|
|
6
|
+
/** Prepare on startup/build and refresh discovery when convention files are added or removed. */
|
|
7
|
+
function maximusProject() {
|
|
8
|
+
let root = process.cwd();
|
|
9
|
+
let mode = "production";
|
|
10
|
+
return {
|
|
11
|
+
name: "maximus-project",
|
|
12
|
+
enforce: "pre",
|
|
13
|
+
config(config, environment) {
|
|
14
|
+
root = resolve(config.root ?? root);
|
|
15
|
+
({mode} = environment);
|
|
16
|
+
prepareProject(root, mode);
|
|
17
|
+
},
|
|
18
|
+
configureServer(server) {
|
|
19
|
+
const update = (file) => {
|
|
20
|
+
const [directory] = relative(root, file).split(/[\\/]/);
|
|
21
|
+
if (!PROJECT_DIRECTORIES.some((name) => name === directory)) return;
|
|
22
|
+
try {
|
|
23
|
+
prepareProject(root, mode);
|
|
24
|
+
server.ws.send({ type: "full-reload" });
|
|
25
|
+
} catch (error) {
|
|
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
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
server.watcher.on("add", update).on("unlink", update);
|
|
37
|
+
server.httpServer?.once("close", () => {
|
|
38
|
+
server.watcher.off("add", update).off("unlink", update);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { maximusProject };
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/webhooks.d.ts
|
|
1
|
+
import { En as Result, Fn as Failure } from "./chunks/types-BWxDd3tY.js";
|
|
3
2
|
/** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
|
|
4
3
|
export declare const WEBHOOK_SIGNATURE_FAILURES: readonly ['missing', 'malformed', 'expired', 'mismatch'];
|
|
5
4
|
/** Why a webhook signature was refused. */
|
|
@@ -65,5 +64,4 @@ export declare function verifyStandardWebhook(options: {
|
|
|
65
64
|
}): Promise<Result<{
|
|
66
65
|
id: string;
|
|
67
66
|
timestamp: number;
|
|
68
|
-
}, WebhookSignatureFailure>>;
|
|
69
|
-
//#endregion
|
|
67
|
+
}, WebhookSignatureFailure>>;
|
package/dist/webhooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/webhooks.ts
|
|
2
2
|
/** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
|
|
3
3
|
const WEBHOOK_SIGNATURE_FAILURES = [
|
|
4
4
|
"missing",
|
|
@@ -158,5 +158,4 @@ async function verifyStandardWebhook(options) {
|
|
|
158
158
|
return failure("mismatch");
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
//#endregion
|
|
162
161
|
export { DEFAULT_TOLERANCE_SECONDS, MAX_SIGNATURES, WEBHOOK_SIGNATURE_FAILURES, verifyHmacSignature, verifyStandardWebhook, verifyTimestampedSignature, webhookSignatureFailure };
|
|
@@ -1,112 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/workers/assets.d.ts
|
|
4
|
-
/** A Workers static-assets binding; product stores and secrets never satisfy this capability. */
|
|
5
|
-
interface AssetBinding {
|
|
6
|
-
/** Answers a request with the uploaded build file at its URL path. */
|
|
7
|
-
fetch: (request: Request) => Promise<Response>;
|
|
8
|
-
}
|
|
9
|
-
/** The names of the env bindings that are asset bindings. */
|
|
10
|
-
type AssetBindingName<E> = { [K in keyof E]-?: E[K] extends AssetBinding ? K : never; }[keyof E] & string;
|
|
11
|
-
/** Explicit assets policy. Unknown paths never receive the SPA shell. */
|
|
12
|
-
interface WorkerAssetsOptions<E> {
|
|
13
|
-
/** Environment binding whose fetch method serves the uploaded build files. */
|
|
14
|
-
binding: AssetBindingName<E>;
|
|
15
|
-
/** Known SPA routes. Stateless expressions may admit product-owned detail routes. */
|
|
16
|
-
pages?: {
|
|
17
|
-
paths: readonly string[];
|
|
18
|
-
patterns?: readonly RegExp[];
|
|
19
|
-
/** Build shell fetched for admitted pages; defaults to /index.html. */
|
|
20
|
-
shell?: string;
|
|
21
|
-
};
|
|
22
|
-
/** Named build files that must revalidate, such as manifests and service workers. */
|
|
23
|
-
files?: readonly string[];
|
|
24
|
-
/** Slash-delimited namespaces containing content-hashed, immutable build files. */
|
|
25
|
-
immutablePrefixes?: readonly string[];
|
|
26
|
-
/** Product browser policy, including CSP. Native content type and cache policy remain authoritative. */
|
|
27
|
-
headers?: HeadersInit | ((request: Request, env: E) => HeadersInit);
|
|
28
|
-
/**
|
|
29
|
-
* Development under Vite (the Cloudflare Vite plugin), whose dev server stands behind the binding:
|
|
30
|
-
* a GET the Worker does not serve as a page, file or immutable asset (Vite's client, modules and
|
|
31
|
-
* sources) is forwarded to it as it came. Pass `import.meta.env.DEV`, which a production build sets to
|
|
32
|
-
* false: a deployed Worker must never forward unknown paths.
|
|
33
|
-
*/
|
|
34
|
-
development?: boolean;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/workers/credentials.d.ts
|
|
38
|
-
/** Typed organization credential preparation for one derived operation group. */
|
|
39
|
-
export declare function credentials<Schema extends TSchema>(options: {
|
|
40
|
-
principal: Principal;
|
|
41
|
-
accounts: {
|
|
42
|
-
getByName: (name: string) => {
|
|
43
|
-
readCredential: (organizationId: string) => Promise<Result<unknown, Failure>>;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
schema: Schema;
|
|
47
|
-
}): Promise<Result<{
|
|
48
|
-
credential: Static<Schema>;
|
|
49
|
-
}, Failure>>;
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/workers/runtime.d.ts
|
|
52
|
-
/**
|
|
53
|
-
* The RPC methods of a Worker's entrypoint: one per operation that declares `rpc`, taking the caller's
|
|
54
|
-
* principal and the input and answering a Result.
|
|
55
|
-
*/
|
|
56
|
-
export type RpcMethods<Ops extends Record<string, OperationShape>> = { [K in keyof Ops as Ops[K] extends {
|
|
57
|
-
rpc: true | {
|
|
58
|
-
callers: readonly string[];
|
|
59
|
-
};
|
|
60
|
-
} ? K : never]: (principal: Principal, input: Static<Ops[K]['input']>) => Promise<Result<Static<Ops[K]['output']>, Failure>>; };
|
|
61
|
-
/**
|
|
62
|
-
* What `createWorker` returns: the default export's handler, the named entrypoint for Worker RPC, and
|
|
63
|
-
* wrappers that run your own entrypoints and Durable Objects inside the application's diagnostics.
|
|
64
|
-
*/
|
|
65
|
-
export interface WorkerRuntime<E, O extends Record<string, OperationShape>> {
|
|
66
|
-
/** The Worker's default export: `fetch` for HTTP, plus the other `handlers` given to `createWorker`. */
|
|
67
|
-
handler: ExportedHandler<E>;
|
|
68
|
-
/**
|
|
69
|
-
* A `WorkerEntrypoint` class with one method per operation that declares `rpc`; export it by name for
|
|
70
|
-
* Service Bindings to call.
|
|
71
|
-
*/
|
|
72
|
-
entrypoint: new (ctx: ExecutionContext, env: E) => WorkerEntrypoint<E> & RpcMethods<O>;
|
|
73
|
-
/**
|
|
74
|
-
* Wraps your own `WorkerEntrypoint` class so its methods run inside the application's diagnostics; it keeps
|
|
75
|
-
* its methods and type.
|
|
76
|
-
*/
|
|
77
|
-
service: <D extends new (ctx: ExecutionContext, env: E) => WorkerEntrypoint<E>>(implementation: D) => D;
|
|
78
|
-
/**
|
|
79
|
-
* Wraps a Durable Object class so its methods run inside the application's diagnostics; it keeps its
|
|
80
|
-
* methods and type.
|
|
81
|
-
*/
|
|
82
|
-
durableObject: <T extends DurableObject<E>, D extends new (state: DurableObject['ctx'], env: E) => T>(implementation: D) => D;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* What `createWorker` takes besides the application: the Worker's other handlers, its transports, the HTTP
|
|
86
|
-
* handler's options, its static assets and its plain routes.
|
|
87
|
-
*/
|
|
88
|
-
export interface WorkerOptions<E> {
|
|
89
|
-
/** The Worker's other handlers (`scheduled`, `queue`, …), merged into the default export. */
|
|
90
|
-
handlers?: Omit<ExportedHandler<E>, 'fetch'>;
|
|
91
|
-
/** Protocol transports served beside the operations, such as `mcp()`. */
|
|
92
|
-
transports?: HttpOptions<E>['transports'];
|
|
93
|
-
/** Native HTTP mounting, product admission and static/protocol composition. */
|
|
94
|
-
http?: Omit<HttpOptions<E>, 'transports' | 'routes' | 'annotate'>;
|
|
95
|
-
/** Explicit build files and SPA page admission, served through the native HTTP fallback. */
|
|
96
|
-
assets?: WorkerAssetsOptions<E>;
|
|
97
|
-
/**
|
|
98
|
-
* Plain routes outside token admission (provider webhooks, signed links,
|
|
99
|
-
* OAuth callbacks), by exact path. Each handler verifies its own signature
|
|
100
|
-
* or token before reading the request. They run inside the same handler,
|
|
101
|
-
* so diagnostics cover them too.
|
|
102
|
-
*/
|
|
103
|
-
routes?: Readonly<Record<string, HttpRoute<E>>>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Turns an application into a Cloudflare Worker: `handler` (export it as default) serves HTTP and the other
|
|
107
|
-
* handlers you pass; `entrypoint` (export it by name) serves every operation that declares `rpc` to the
|
|
108
|
-
* Workers whose Service Binding names an allowed `caller`.
|
|
109
|
-
*/
|
|
110
|
-
export declare function createWorker<E, C, O extends Record<string, OperationShape>>(application: AppManifest<E, C, O>, options?: WorkerOptions<E>): WorkerRuntime<E, O>;
|
|
111
|
-
//#endregion
|
|
112
|
-
export type { WorkerAssetsOptions };
|
|
1
|
+
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/types-BWxDd3tY.js";
|
|
2
|
+
export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
|
package/dist/workers/runtime.js
CHANGED
|
@@ -1,228 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as isRequestId } from "../chunks/correlation-gaiEoMBr.js";
|
|
3
|
-
import { standardErrors } from "../errors.js";
|
|
4
|
-
import { d as err, p as ok, r as PrincipalSchema, t as executeOperation } from "../chunks/execution-qfZuMSIu.js";
|
|
5
|
-
import { r as createHttpHandler } from "../chunks/src-Ph5KHCRP.js";
|
|
6
|
-
import { a as telemetryEnabled, r as recordExecution, s as withTelemetry } from "../chunks/telemetry-DvZgrzZn.js";
|
|
7
|
-
import { DurableObject, WorkerEntrypoint, tracing } from "cloudflare:workers";
|
|
1
|
+
import { n as credentials, t as createWorker } from "../chunks/runtime-BPnaa-NK.js";
|
|
8
2
|
|
|
9
|
-
//#region src/workers/assets.ts
|
|
10
|
-
/**
|
|
11
|
-
* Serves a web app's build through a Workers static-assets binding: known pages get the app shell, named
|
|
12
|
-
* files revalidate, content-hashed files are immutable, and every other path is refused.
|
|
13
|
-
*/
|
|
14
|
-
/** An absolute asset path of unreserved characters, without a query or a fragment. */
|
|
15
|
-
const ASSET_PATH = /^\/(?:[a-zA-Z0-9._~-]+(?:\/[a-zA-Z0-9._~-]+)*)?$/;
|
|
16
|
-
/** The path, refused at construction when it is not an absolute asset path or has dot segments. */
|
|
17
|
-
function requireAssetPath(path) {
|
|
18
|
-
if (!ASSET_PATH.test(path) || path.split("/").some((segment) => segment === "." || segment === "..")) throw new TypeError(`Asset path must be absolute without query, fragments or dot segments: ${path}`);
|
|
19
|
-
return path;
|
|
20
|
-
}
|
|
21
|
-
/** Whether a binding can fetch assets. */
|
|
22
|
-
function isAssetBinding(value) {
|
|
23
|
-
return typeof value === "object" && value !== null && "fetch" in value && typeof value.fetch === "function";
|
|
24
|
-
}
|
|
25
|
-
/** Compile the explicit build policy once; core HTTP retains ownership of API and transport misses. */
|
|
26
|
-
function createAssetHandler(options) {
|
|
27
|
-
const bindingName = options.binding;
|
|
28
|
-
const pages = new Set(options.pages?.paths.map(requireAssetPath));
|
|
29
|
-
const files = new Set(options.files?.map(requireAssetPath));
|
|
30
|
-
const shell = requireAssetPath(options.pages?.shell ?? "/index.html");
|
|
31
|
-
const patterns = options.pages?.patterns?.map((pattern) => {
|
|
32
|
-
if (!(pattern instanceof RegExp) || pattern.global || pattern.sticky) throw new TypeError("Asset page patterns must be stateless regular expressions without global or sticky flags.");
|
|
33
|
-
return new RegExp(pattern.source, pattern.flags);
|
|
34
|
-
}) ?? [];
|
|
35
|
-
const immutablePrefixes = options.immutablePrefixes?.map((path) => {
|
|
36
|
-
const prefix = requireAssetPath(path.endsWith("/") ? path.slice(0, -1) : path);
|
|
37
|
-
if (prefix === "/") throw new TypeError("An immutable assets prefix must not claim the entire origin.");
|
|
38
|
-
return prefix;
|
|
39
|
-
}) ?? [];
|
|
40
|
-
const configuredHeaders = typeof options.headers === "function" ? options.headers : new Headers(options.headers);
|
|
41
|
-
return async (request, env, context) => {
|
|
42
|
-
if (request.method !== "GET" && request.method !== "HEAD") return context.fail(standardErrors.methodNotAllowed.create(), { Allow: "GET, HEAD" });
|
|
43
|
-
const url = new URL(request.url);
|
|
44
|
-
const isPage = pages.has(url.pathname) || patterns.some((pattern) => pattern.test(url.pathname));
|
|
45
|
-
const isFile = files.has(url.pathname);
|
|
46
|
-
const isImmutable = immutablePrefixes.some((prefix) => url.pathname === prefix || url.pathname.startsWith(`${prefix}/`));
|
|
47
|
-
const binding = env[bindingName];
|
|
48
|
-
if (!(isPage || isFile || isImmutable)) {
|
|
49
|
-
if (options.development && isAssetBinding(binding)) return binding.fetch(request);
|
|
50
|
-
return context.fail(standardErrors.notFound.create());
|
|
51
|
-
}
|
|
52
|
-
if (!isAssetBinding(binding)) throw new TypeError("The configured Worker assets binding does not implement fetch.");
|
|
53
|
-
const assetUrl = new URL(isPage ? shell : url.pathname, url.origin);
|
|
54
|
-
const asset = await binding.fetch(new Request(assetUrl, { method: request.method }));
|
|
55
|
-
const headers = new Headers(asset.headers);
|
|
56
|
-
const policy = typeof configuredHeaders === "function" ? new Headers(configuredHeaders(request, env)) : configuredHeaders;
|
|
57
|
-
for (const [name, value] of policy) if (name !== "content-type" && name !== "cache-control") headers.set(name, value);
|
|
58
|
-
headers.set("x-content-type-options", "nosniff");
|
|
59
|
-
let cache = "public, max-age=31536000, immutable";
|
|
60
|
-
if (isPage || asset.status !== 200) cache = "no-store";
|
|
61
|
-
else if (isFile) cache = "no-cache";
|
|
62
|
-
headers.set("cache-control", cache);
|
|
63
|
-
if (request.method === "HEAD" && asset.body) await asset.body.cancel();
|
|
64
|
-
return new Response(request.method === "HEAD" ? null : asset.body, {
|
|
65
|
-
status: asset.status,
|
|
66
|
-
statusText: asset.statusText,
|
|
67
|
-
headers
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/workers/internal/instrumentation.ts
|
|
74
|
-
/**
|
|
75
|
-
* Runs the methods of a Worker's own entrypoints and Durable Objects inside the application's diagnostics.
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* A subclass of `implementation` whose every method, its own and those it inherits up to the Workers
|
|
79
|
-
* base class `runtime`, runs inside the application's diagnostics for the instance's `env`.
|
|
80
|
-
*/
|
|
81
|
-
function instrumentMethods(implementation, runtime, telemetry) {
|
|
82
|
-
const Base = implementation;
|
|
83
|
-
const environments = /* @__PURE__ */ new WeakMap();
|
|
84
|
-
class Observed extends Base {
|
|
85
|
-
constructor(context, env) {
|
|
86
|
-
super(context, env);
|
|
87
|
-
environments.set(this, env);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
let { prototype } = implementation;
|
|
91
|
-
const methods = /* @__PURE__ */ new Set();
|
|
92
|
-
while (prototype && prototype !== runtime.prototype) {
|
|
93
|
-
for (const name of Object.getOwnPropertyNames(prototype)) {
|
|
94
|
-
const method = Object.getOwnPropertyDescriptor(prototype, name)?.value;
|
|
95
|
-
if (name === "constructor" || methods.has(name) || typeof method !== "function") continue;
|
|
96
|
-
methods.add(name);
|
|
97
|
-
Object.defineProperty(Observed.prototype, name, {
|
|
98
|
-
configurable: true,
|
|
99
|
-
value(...args) {
|
|
100
|
-
return withTelemetry(telemetry, environments.get(this), () => Reflect.apply(method, this, args));
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
105
|
-
}
|
|
106
|
-
return Observed;
|
|
107
|
-
}
|
|
108
|
-
/** A named entrypoint whose RPC methods run inside the application's diagnostics. */
|
|
109
|
-
function instrumentService(implementation, telemetry) {
|
|
110
|
-
return instrumentMethods(implementation, WorkerEntrypoint, telemetry);
|
|
111
|
-
}
|
|
112
|
-
/** A Durable Object whose methods run inside the application's diagnostics. */
|
|
113
|
-
function instrumentDurableObject(implementation, telemetry) {
|
|
114
|
-
return instrumentMethods(implementation, DurableObject, telemetry);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/workers/internal/worker-tracing.ts
|
|
119
|
-
/**
|
|
120
|
-
* Annotates the active Workers trace span with the service, the operation and the request id.
|
|
121
|
-
*/
|
|
122
|
-
/**
|
|
123
|
-
* Call inside the invocation, after authenticating the native principal. Service
|
|
124
|
-
* and operation are developer constants. Adds correlation to the existing native
|
|
125
|
-
* span; does not mint/fake trace ids or enable exporters. No raw exception is
|
|
126
|
-
* recorded on the native span.
|
|
127
|
-
* Older workerd versions do not expose getActiveSpan. Annotation is best effort:
|
|
128
|
-
* an unavailable or failing telemetry API must never change the business result.
|
|
129
|
-
*/
|
|
130
|
-
function annotateInvocation(service, operation, requestId, attributeNames = {
|
|
131
|
-
service: "service.name",
|
|
132
|
-
operation: "operation.name",
|
|
133
|
-
requestId: "request.id"
|
|
134
|
-
}) {
|
|
135
|
-
try {
|
|
136
|
-
if (typeof tracing.getActiveSpan === "function") tracing.getActiveSpan()?.setAttributes({
|
|
137
|
-
[attributeNames.service]: service,
|
|
138
|
-
[attributeNames.operation]: operation,
|
|
139
|
-
...isRequestId(requestId) ? { [attributeNames.requestId]: requestId } : {}
|
|
140
|
-
});
|
|
141
|
-
} catch {}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/workers/credentials.ts
|
|
146
|
-
/**
|
|
147
|
-
* Reads one organization's credential from its own store, such as a Durable Object per organization, and
|
|
148
|
-
* checks that it belongs to that organization.
|
|
149
|
-
*/
|
|
150
|
-
/** Typed organization credential preparation for one derived operation group. */
|
|
151
|
-
async function credentials(options) {
|
|
152
|
-
const { organizationId } = options.principal;
|
|
153
|
-
const result = await options.accounts.getByName(organizationId).readCredential(organizationId);
|
|
154
|
-
if (!result.ok) return result;
|
|
155
|
-
const parsed = parseInput(options.schema, result.value);
|
|
156
|
-
if (!parsed.ok || !parsed.value || typeof parsed.value !== "object" || !("organizationId" in parsed.value) || parsed.value.organizationId !== organizationId) return err(standardErrors.internal.create());
|
|
157
|
-
return ok({ credential: parsed.value });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/workers/runtime.ts
|
|
162
|
-
/**
|
|
163
|
-
* `@arbol-ai/maximus/workers`: turns an application into a Cloudflare Worker: its fetch handler, its RPC
|
|
164
|
-
* entrypoint, and the instrumentation of the Worker's other classes.
|
|
165
|
-
*/
|
|
166
|
-
/**
|
|
167
|
-
* Turns an application into a Cloudflare Worker: `handler` (export it as default) serves HTTP and the other
|
|
168
|
-
* handlers you pass; `entrypoint` (export it by name) serves every operation that declares `rpc` to the
|
|
169
|
-
* Workers whose Service Binding names an allowed `caller`.
|
|
170
|
-
*/
|
|
171
|
-
function createWorker(application, options = {}) {
|
|
172
|
-
if (options.assets && options.http?.fallback) throw new TypeError("Worker assets and an HTTP fallback cannot both own unmatched paths.");
|
|
173
|
-
const assets = options.assets ? createAssetHandler(options.assets) : void 0;
|
|
174
|
-
const manifest = application;
|
|
175
|
-
const fetch = createHttpHandler(manifest, {
|
|
176
|
-
...options.http,
|
|
177
|
-
fallback: assets ?? options.http?.fallback,
|
|
178
|
-
transports: options.transports,
|
|
179
|
-
routes: options.routes,
|
|
180
|
-
annotate: (operation, id) => annotateInvocation(manifest.name, operation, id)
|
|
181
|
-
});
|
|
182
|
-
class Entrypoint extends WorkerEntrypoint {}
|
|
183
|
-
for (const [name, op] of Object.entries(manifest.operations)) {
|
|
184
|
-
if (!op.rpc) continue;
|
|
185
|
-
const callers = op.rpc === true ? manifest.rpc.callers : op.rpc.callers;
|
|
186
|
-
Object.defineProperty(Entrypoint.prototype, name, {
|
|
187
|
-
configurable: true,
|
|
188
|
-
async value(principal, input) {
|
|
189
|
-
const props = this.ctx.props;
|
|
190
|
-
if (!props || Object.keys(props).length !== 1 || typeof props.caller !== "string" || !callers.includes(props.caller)) return err(standardErrors.unauthorized.create());
|
|
191
|
-
const parsed = parseInput(PrincipalSchema, principal);
|
|
192
|
-
if (!parsed.ok) return err(standardErrors.unauthorized.create());
|
|
193
|
-
if (telemetryEnabled(manifest.telemetry, this.env)) annotateInvocation(manifest.name, name, parsed.value.requestId);
|
|
194
|
-
const started = performance.now();
|
|
195
|
-
const result = await withTelemetry(manifest.telemetry, this.env, () => executeOperation(manifest, op, this.env, parsed.value, input, void 0, this.ctx));
|
|
196
|
-
recordExecution(manifest, this.env, this.ctx, {
|
|
197
|
-
principal: parsed.value,
|
|
198
|
-
operation: name,
|
|
199
|
-
surface: "rpc",
|
|
200
|
-
started,
|
|
201
|
-
result
|
|
202
|
-
});
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
const service = (implementation) => instrumentService(implementation, manifest.telemetry);
|
|
208
|
-
const entrypoint = service(Entrypoint);
|
|
209
|
-
const handler = {
|
|
210
|
-
...options.handlers,
|
|
211
|
-
fetch
|
|
212
|
-
};
|
|
213
|
-
const scheduledHandler = options.handlers?.scheduled;
|
|
214
|
-
if (scheduledHandler) handler.scheduled = function scheduled(controller, env, ctx) {
|
|
215
|
-
return withTelemetry(manifest.telemetry, env, () => scheduledHandler.call(this, controller, env, ctx));
|
|
216
|
-
};
|
|
217
|
-
return {
|
|
218
|
-
handler,
|
|
219
|
-
entrypoint,
|
|
220
|
-
service,
|
|
221
|
-
durableObject(implementation) {
|
|
222
|
-
return instrumentDurableObject(implementation, manifest.telemetry);
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
//#endregion
|
|
228
3
|
export { createWorker, credentials };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arbol-ai/maximus",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.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",
|
|
@@ -110,6 +110,14 @@
|
|
|
110
110
|
"./oxlint": {
|
|
111
111
|
"types": "./config/oxlint.d.mts",
|
|
112
112
|
"import": "./config/oxlint.mjs"
|
|
113
|
+
},
|
|
114
|
+
"./project": {
|
|
115
|
+
"types": "./dist/project/index.d.ts",
|
|
116
|
+
"import": "./dist/project/index.js"
|
|
117
|
+
},
|
|
118
|
+
"./vite": {
|
|
119
|
+
"types": "./dist/tooling/vite.d.ts",
|
|
120
|
+
"import": "./dist/tooling/vite.js"
|
|
113
121
|
}
|
|
114
122
|
},
|
|
115
123
|
"publishConfig": {
|
|
@@ -118,9 +126,9 @@
|
|
|
118
126
|
},
|
|
119
127
|
"scripts": {
|
|
120
128
|
"typecheck": "tsc --noEmit",
|
|
121
|
-
"build": "
|
|
122
|
-
"test": "
|
|
123
|
-
"test:integration": "
|
|
129
|
+
"build": "vp pack",
|
|
130
|
+
"test": "vp test run --exclude \"**/*.integration.test.ts\"",
|
|
131
|
+
"test:integration": "vp test run --config vitest.integration.config.ts"
|
|
124
132
|
},
|
|
125
133
|
"dependencies": {
|
|
126
134
|
"@modelcontextprotocol/server": "2.3.1",
|
|
@@ -134,13 +142,15 @@
|
|
|
134
142
|
"ajv": "8.20.0",
|
|
135
143
|
"miniflare": "5.20261012.1-beta",
|
|
136
144
|
"pg": "8.23.1",
|
|
137
|
-
"
|
|
145
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
146
|
+
"vite-plus": "1.4.0"
|
|
138
147
|
},
|
|
139
148
|
"peerDependencies": {
|
|
140
149
|
"oxfmt": ">=0.71.0 <1",
|
|
141
150
|
"oxlint": "^1.86.0",
|
|
142
151
|
"pg": "^8.23.1",
|
|
143
|
-
"ultracite": "^8.0.0"
|
|
152
|
+
"ultracite": "^8.0.0",
|
|
153
|
+
"vite": "^8.3.4"
|
|
144
154
|
},
|
|
145
155
|
"peerDependenciesMeta": {
|
|
146
156
|
"oxfmt": {
|
|
@@ -154,6 +164,9 @@
|
|
|
154
164
|
},
|
|
155
165
|
"ultracite": {
|
|
156
166
|
"optional": true
|
|
167
|
+
},
|
|
168
|
+
"vite": {
|
|
169
|
+
"optional": true
|
|
157
170
|
}
|
|
158
171
|
}
|
|
159
172
|
}
|
package/skills/maximus/SKILL.md
CHANGED
|
@@ -39,7 +39,7 @@ pipeline, never around it.
|
|
|
39
39
|
| Callers without bearer tokens (webhooks, signed links) | A plain route that verifies its own signature |
|
|
40
40
|
| Tokens that are not organization-bound OAuth access tokens | `tokens.resolve`, verifying cryptographically |
|
|
41
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` |
|
|
42
|
+
| A new service from scratch | `references/building-a-service.md`; `maximus init --layout project` adds optional file conventions |
|
|
43
43
|
| Upgrading from 4.x | `references/migration-to-v5.md` |
|
|
44
44
|
| Upgrading from 2.x | `references/migration-from-v2.md` |
|
|
45
45
|
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Building a service
|
|
2
2
|
|
|
3
|
+
For optional file conventions, use `maximus init <directory> --name <name> --layout project`.
|
|
4
|
+
`routes/` factories receive their versioned file path and return builders derived from
|
|
5
|
+
`src/application.ts`; `pages/` returns public native Responses. Middleware runs after authorization.
|
|
6
|
+
Cron, queue, email and Durable Object modules are discovered into ignored `.maximus/` imports by
|
|
7
|
+
`maximus prepare` and `maximusProject()` from `@arbol-ai/maximus/vite`. Configure infrastructure
|
|
8
|
+
explicitly in `cloudflare.config.ts`. Read `docs/guides/project-structure.md` in the Maximus repository
|
|
9
|
+
for conventions and boundaries. The generated project uses non-test validation and automatic
|
|
10
|
+
deployment on main; production API authentication initially refuses every token.
|
|
11
|
+
|
|
3
12
|
## Packages
|
|
4
13
|
|
|
5
14
|
```sh
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: __PROJECT_NAME__-development
|
|
3
|
+
description: Extend the __PROJECT_NAME__ Maximus backend using its optional file conventions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Read CLAUDE.md and the installed Maximus skill. Add authenticated route factories in routes/v1/;
|
|
7
|
+
their default export receives the path and returns operations derived from src/application.ts's base.
|
|
8
|
+
Declare strict input/output schemas, scope and effect. Use src/ for named domain functions.
|
|
9
|
+
Pages return native Responses. Middleware modules default-export an OperationMiddleware<Invocation<Env>>.
|
|
10
|
+
Crons export a cron expression and a default scheduled handler; queues and email export native handlers.
|
|
11
|
+
Durable Object files default-export their class. Infrastructure declarations remain explicit in
|
|
12
|
+
cloudflare.config.ts. Read the Maximus project-structure guide before adding another module kind.
|
|
13
|
+
Run bun run verify for non-test validation. Tests require a human request.
|
|
14
|
+
|
|
15
|
+
Vite+ owns the root toolchain: `vite.config.ts` configures lint/format, `vp check` checks them,
|
|
16
|
+
`vp build` bundles the Worker and `vp dev` runs it locally. TypeScript and Cloudflare type generation
|
|
17
|
+
remain part of `bun run verify`. Tests are never part of automatic deployment.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Verify and deploy
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
concurrency:
|
|
10
|
+
group: deploy-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: false
|
|
12
|
+
jobs:
|
|
13
|
+
deploy:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
timeout-minutes: 15
|
|
16
|
+
env:
|
|
17
|
+
CF_SEND_TELEMETRY: 'false'
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
20
|
+
with:
|
|
21
|
+
persist-credentials: false
|
|
22
|
+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
|
|
23
|
+
with:
|
|
24
|
+
bun-version: 1.4.3
|
|
25
|
+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
26
|
+
with:
|
|
27
|
+
node-version: '24'
|
|
28
|
+
- run: bun install --frozen-lockfile --ignore-scripts
|
|
29
|
+
- run: bun run verify
|
|
30
|
+
- run: bunx cf deploy --prebuilt --mode production --dry-run
|
|
31
|
+
- name: Deploy main
|
|
32
|
+
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
|
33
|
+
run: bunx cf deploy --prebuilt --mode production
|
|
34
|
+
env:
|
|
35
|
+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
36
|
+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# __PROJECT_NAME__ agent guide
|
|
2
|
+
|
|
3
|
+
AGENTS.md is a symlink to this file. Keep code, documentation, comments and agent instructions in English.
|
|
4
|
+
Read .agents/skills/project/SKILL.md and node_modules/@arbol-ai/maximus/skills/maximus/SKILL.md.
|
|
5
|
+
|
|
6
|
+
## Structure
|
|
7
|
+
|
|
8
|
+
This is a Maximus project layout. The Vite plugin and `maximus prepare` generate `.maximus/` from
|
|
9
|
+
optional directories. Never edit generated files. Routes are factories that receive their inferred
|
|
10
|
+
versioned path and return a builder derived from `base` in src/application.ts. Pages return native
|
|
11
|
+
Responses; public pages never contain tenant data. Middleware runs after authentication and scopes.
|
|
12
|
+
Configure platform bindings, triggers and Durable Object migrations in cloudflare.config.ts.
|
|
13
|
+
Keep domain logic in src/, schemas and migrations in db/, and uploaded files in public/ only after
|
|
14
|
+
configuring an assets binding and explicit file admission. Never apply migrations implicitly.
|
|
15
|
+
|
|
16
|
+
## Boundaries
|
|
17
|
+
|
|
18
|
+
Tenant authority is context.principal.organizationId, never caller input. Declare strict schemas,
|
|
19
|
+
scopes, effects and the required transports once. Use the shared Result pipeline. Never put provider
|
|
20
|
+
credentials, customer data or request bodies in logs, examples, errors or agent instructions.
|
|
21
|
+
Secrets belong in bindings; .dev.vars is local and ignored. Production tokens are refused until the
|
|
22
|
+
application configures a real identity provider or cryptographically verified resolver.
|
|
23
|
+
|
|
24
|
+
## Workflows
|
|
25
|
+
|
|
26
|
+
Use `bun run verify` for type generation, TypeScript, lint, format and build. Tests require an explicit
|
|
27
|
+
human request, including tests in scripts, hooks or CI. Never start them implicitly.
|
|
28
|
+
Use `cf` for Cloudflare; discover account/resource commands with anonymous `cf cli search` queries
|
|
29
|
+
and inspect their schema before execution. Deploy with the project's script or its GitHub workflow.
|
|
30
|
+
Preserve unrelated work and Git identity configuration. Do not add assistant attribution to commits.
|
|
31
|
+
|
|
32
|
+
Vite+ owns the root toolchain: `vite.config.ts` configures lint/format, `vp check` checks them,
|
|
33
|
+
`vp build` bundles the Worker and `vp dev` runs it locally. TypeScript and Cloudflare type generation
|
|
34
|
+
remain part of `bun run verify`. Tests are never part of automatic deployment.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# **PROJECT_NAME**
|
|
2
|
+
|
|
3
|
+
A Maximus backend on Cloudflare Workers, with Vite+ as its default toolchain. `GET /` returns **Hello World**, `/health` reports liveness,
|
|
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 src/application.ts.
|
|
6
|
+
|
|
7
|
+
## Development
|
|
8
|
+
|
|
9
|
+
Install dependencies with `bun install`, then run `bun run dev`. The local development token is in
|
|
10
|
+
the ignored `.dev.vars` file. It is accepted only on localhost and is excluded from production builds.
|
|
11
|
+
`bun run verify` generates types, checks TypeScript, lint and formatting, and builds. It runs no tests.
|
|
12
|
+
|
|
13
|
+
## Structure
|
|
14
|
+
|
|
15
|
+
The [Maximus project layout](https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md)
|
|
16
|
+
uses optional directories. Add only the modules the service needs:
|
|
17
|
+
|
|
18
|
+
| Directory | Convention |
|
|
19
|
+
| ---------------- | ------------------------------------------------------------------------------------- |
|
|
20
|
+
| routes/ | Versioned API route factories, automatically mounted with their file path. |
|
|
21
|
+
| pages/ | Fixed-path public response handlers; index.ts serves `/`. |
|
|
22
|
+
| middleware/ | Operation middleware, sorted by filename and run after authorization. |
|
|
23
|
+
| crons/ | A `cron` export and a default native scheduled handler. |
|
|
24
|
+
| queues/ | Default queue handlers named after the physical queue. |
|
|
25
|
+
| email/ | Default email handlers named after the full recipient; `_default.ts` is the fallback. |
|
|
26
|
+
| durable-objects/ | Default classes re-exported in PascalCase from kebab-case filenames. |
|
|
27
|
+
| db/ | Application-owned schemas and SQL migrations, applied explicitly. |
|
|
28
|
+
| src/ | Shared domain code, application configuration and Worker options. |
|
|
29
|
+
| public/ | Optional static assets; configure the binding and admitted files before using it. |
|
|
30
|
+
| .maximus/ | Generated imports; ignored and never edited by hand. |
|
|
31
|
+
|
|
32
|
+
The Vite plugin prepares the project before development/build and discovers added/removed modules
|
|
33
|
+
during development. `bun run prepare:project` generates the same imports for editors. Files starting
|
|
34
|
+
with `_` are ignored except `email/_default.ts`; `.dev.ts` and `.prod.ts` select their matching mode.
|
|
35
|
+
Platform bindings, cron triggers, queue subscriptions, email routing and Durable Object migrations
|
|
36
|
+
remain explicit Cloudflare configuration. Adding a handler never provisions infrastructure.
|
|
37
|
+
|
|
38
|
+
## Deployment
|
|
39
|
+
|
|
40
|
+
Before deploying, replace the origin and audience in src/application.ts with the deployed HTTPS URL.
|
|
41
|
+
The GitHub workflow checks pull requests and deploys pushes to `main`. Configure repository or
|
|
42
|
+
organization secrets `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The token needs permission to
|
|
43
|
+
deploy this Worker. `bun run deploy` performs the same non-test validation and deployment locally.
|
|
44
|
+
|
|
45
|
+
Vite+ owns the root toolchain: `vite.config.ts` configures lint/format, `vp check` checks them,
|
|
46
|
+
`vp build` bundles the Worker and `vp dev` runs it locally. TypeScript and Cloudflare type generation
|
|
47
|
+
remain part of `bun run verify`. Tests are never part of automatic deployment.
|