@arbol-ai/maximus 8.7.2 → 8.9.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 +2 -0
- package/config/oxlint.mjs +3 -0
- package/dist/analytics/analytics.d.ts +1 -1
- package/dist/body.d.ts +1 -1
- package/dist/capture/index.d.ts +1 -1
- package/dist/chunks/{define-app-g0A34g8z.js → define-app-IhSbBWTD.js} +1 -1
- package/dist/chunks/{http-layout-CdFZEF2S.js → http-layout-B-9NbM5M.js} +1 -1
- package/dist/chunks/{meter-BnrQY5rb.js → meter-BpzCC7J3.js} +1 -1
- package/dist/chunks/{openapi-BkR-hcYJ.js → openapi-Ye_Ypx-d.js} +1 -1
- package/dist/chunks/{openapi-file-F5kJS8x-.js → openapi-file-2fUP4JLw.js} +2 -2
- package/dist/chunks/{pages-DLW65kXL.js → pages-BJKV04-G.js} +1 -1
- package/dist/chunks/{prepare-configured-Cithjf80.js → prepare-configured-DjCFAqdH.js} +6 -2
- package/dist/chunks/{prepare-configured-BmRJLg6J.js → prepare-configured-Dw3-u-b3.js} +1 -1
- package/dist/chunks/{runtime-DoyJqzAv.js → runtime-Bg729nOQ.js} +3 -3
- package/dist/chunks/{server-DxifcN7e.js → server-ZGiWOeAp.js} +1 -1
- package/dist/chunks/{src-BNbGseOR.js → src-8mwPVI5H.js} +10 -6
- package/dist/chunks/{tokens-b9dEBUu9.js → tokens-CBQO5lc0.js} +109 -14
- package/dist/chunks/{types-Do00dTUs.d.ts → types-Dmw37bhl.d.ts} +61 -1
- package/dist/chunks/{workers-types-DjWyO_Pu.d.ts → workers-types-CYOvun0Q.d.ts} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/http-paths.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +2 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/tasks.d.ts +1 -1
- package/dist/project/config.d.ts +1 -1
- package/dist/project/index.d.ts +2 -2
- package/dist/project/index.js +2 -2
- package/dist/schemas.d.ts +1 -1
- package/dist/standard-failures.d.ts +1 -1
- package/dist/tooling/cli.js +3 -4
- package/dist/vite/index.d.ts +85 -7
- package/dist/vite/index.js +279 -34
- 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 +1 -1
- package/skills/maximus/SKILL.md +4 -0
- package/skills/maximus/references/deploying.md +9 -0
- package/skills/maximus/references/project.md +47 -4
package/dist/vite/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { a as operationPathParameters } from "../chunks/http-paths-D043DkJv.js";
|
|
2
|
-
import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-
|
|
2
|
+
import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-B-9NbM5M.js";
|
|
3
3
|
import { t as routeName } from "../chunks/names-ncD7A3DV.js";
|
|
4
|
-
import { t as checkPagePaths } from "../chunks/pages-
|
|
4
|
+
import { t as checkPagePaths } from "../chunks/pages-BJKV04-G.js";
|
|
5
5
|
import { a as projectPath, i as projectFiles, o as publicFiles, r as compareNames, s as routeShape, t as PROJECT_DIRECTORIES } from "../chunks/project-files-C0OX7MQQ.js";
|
|
6
|
-
import { t as checkMcpResourceNames } from "../chunks/define-app-
|
|
6
|
+
import { t as checkMcpResourceNames } from "../chunks/define-app-IhSbBWTD.js";
|
|
7
7
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
@@ -11,6 +11,120 @@ import { cloudflare } from "@cloudflare/vite-plugin";
|
|
|
11
11
|
import { bindings, triggers } from "cf/config";
|
|
12
12
|
import { parseSync } from "vite";
|
|
13
13
|
|
|
14
|
+
// src/vite/environments.ts
|
|
15
|
+
/** An environment's name: lowercase letters, digits and single hyphens, 2 to 24 characters. */
|
|
16
|
+
const ENVIRONMENT_NAME = /^(?=.{2,24}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
17
|
+
/** What an environment never states: they are the service's own, the same wherever it runs. */
|
|
18
|
+
const SHARED_ALONE = [
|
|
19
|
+
"name",
|
|
20
|
+
"namespace",
|
|
21
|
+
"environments"
|
|
22
|
+
];
|
|
23
|
+
/** The stores a binding names by the id of one existing store: sharing one shares its data. */
|
|
24
|
+
const STORES_BY_ID = /* @__PURE__ */ new Set([
|
|
25
|
+
"d1",
|
|
26
|
+
"kv",
|
|
27
|
+
"hyperdrive"
|
|
28
|
+
]);
|
|
29
|
+
/** Why an environment apart may not inherit a shared binding, or undefined when it may. */
|
|
30
|
+
function productionOwns(binding) {
|
|
31
|
+
const kind = bindingKind(binding);
|
|
32
|
+
if (kind !== void 0 && STORES_BY_ID.has(kind) && "id" in binding) return `the shared ${kind} store, which holds production's data`;
|
|
33
|
+
if (kind === "queue") return "the shared queue, whose messages production's Worker consumes";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The environment a command builds: `development` under `vp dev`, whatever its mode, and otherwise the Vite
|
|
37
|
+
* mode, which is `production` unless the build names another (`vp build --mode preview`).
|
|
38
|
+
*/
|
|
39
|
+
function environmentName(phase, mode) {
|
|
40
|
+
return phase === "development" ? "development" : mode || "production";
|
|
41
|
+
}
|
|
42
|
+
/** A binding as `cf/config` states it: a plain object whose `type` names its kind. */
|
|
43
|
+
function bindingKind(binding) {
|
|
44
|
+
if (typeof binding !== "object" || binding === null || !("type" in binding)) return;
|
|
45
|
+
return typeof binding.type === "string" ? binding.type : void 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The bindings of an environment apart: its own, and of the shared ones it leaves alone, an R2 bucket under
|
|
49
|
+
* the environment's name (`notes-documents-preview`) and every other binding as it is. A shared store named
|
|
50
|
+
* by its id (D1, KV, Hyperdrive) and a shared queue are refused: the environment declares its own, so nothing
|
|
51
|
+
* it runs reads or writes production's data, or sends production's Worker a message, unless the configuration
|
|
52
|
+
* says so.
|
|
53
|
+
*/
|
|
54
|
+
function bindingsApart(shared, own, environment) {
|
|
55
|
+
const kept = Object.entries(shared ?? {}).filter(([key]) => !Object.hasOwn(own ?? {}, key)).map(([key, binding]) => {
|
|
56
|
+
const owned = productionOwns(binding);
|
|
57
|
+
if (owned !== void 0) throw new TypeError(`environments.${environment}: ${key} is ${owned}. Declare the environment's own ${key} in environments.${environment}.env.`);
|
|
58
|
+
if (bindingKind(binding) === "r2" && "name" in binding && typeof binding.name === "string") return [key, {
|
|
59
|
+
...binding,
|
|
60
|
+
name: `${binding.name}-${environment}`
|
|
61
|
+
}];
|
|
62
|
+
return [key, binding];
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
...Object.fromEntries(kept),
|
|
66
|
+
...own
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The options a build of `name` follows. An environment the configuration does not declare builds the shared
|
|
71
|
+
* options as they are. A declared one states its own over them: `env` and `tokens` key by key, every other
|
|
72
|
+
* option whole. An environment apart from production also leaves the shared `domains`, `workersDev`,
|
|
73
|
+
* `previewUrls` and `triggers` behind, and takes its stores as `bindingsApart` says.
|
|
74
|
+
*
|
|
75
|
+
* Throws a TypeError for an environment name that is not lowercase words, and for an environment that states
|
|
76
|
+
* the service's `name`, its `namespace` or environments of its own.
|
|
77
|
+
*/
|
|
78
|
+
function resolveEnvironment(options, name) {
|
|
79
|
+
const { environments, ...shared } = options;
|
|
80
|
+
for (const declared of Object.keys(environments ?? {})) if (!ENVIRONMENT_NAME.test(declared)) throw new TypeError(`environments.${declared}: name an environment in lowercase letters, digits and single hyphens, such as preview or staging.`);
|
|
81
|
+
const own = environments && Object.hasOwn(environments, name) ? environments[name] : void 0;
|
|
82
|
+
if (own === void 0) return {
|
|
83
|
+
name,
|
|
84
|
+
options: shared,
|
|
85
|
+
apart: false,
|
|
86
|
+
ownOrigin: false
|
|
87
|
+
};
|
|
88
|
+
if (typeof own !== "object" || own === null) throw new TypeError(`environments.${name} states what the environment changes: an object of options.`);
|
|
89
|
+
for (const fixed of SHARED_ALONE) if (fixed in own) throw new TypeError(`environments.${name}.${fixed}: the service keeps its name and its namespace in every environment.`);
|
|
90
|
+
const apart = name !== "production" && name !== "development";
|
|
91
|
+
const { domains: _domains, workersDev: _workersDev, previewUrls: _previewUrls, triggers: _triggers, ...settings } = shared;
|
|
92
|
+
const base = apart ? settings : shared;
|
|
93
|
+
const env = apart ? bindingsApart(shared.env, own.env, name) : {
|
|
94
|
+
...shared.env,
|
|
95
|
+
...own.env
|
|
96
|
+
};
|
|
97
|
+
const tokens = shared.tokens || own.tokens ? {
|
|
98
|
+
...shared.tokens,
|
|
99
|
+
...own.tokens
|
|
100
|
+
} : void 0;
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
options: {
|
|
104
|
+
...base,
|
|
105
|
+
...own,
|
|
106
|
+
env,
|
|
107
|
+
...tokens ? { tokens } : {}
|
|
108
|
+
},
|
|
109
|
+
apart,
|
|
110
|
+
ownOrigin: apart && own.origin !== void 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The clients an environment admits, from `tokens.clients`: the list as it is, or from a record by
|
|
115
|
+
* environment, that environment's client or clients. Under `vp dev`, a record without `development` gives
|
|
116
|
+
* production's. Throws a TypeError for a record that names none for the environment.
|
|
117
|
+
*/
|
|
118
|
+
function environmentClients(clients, environment) {
|
|
119
|
+
if (clients === void 0 || Array.isArray(clients)) return clients;
|
|
120
|
+
if (typeof clients !== "object" || clients === null) throw new TypeError("tokens.clients lists client ids, or names each environment’s: { production, preview }.");
|
|
121
|
+
const byEnvironment = clients;
|
|
122
|
+
const named = [environment, ...environment === "development" ? ["production"] : []].find((key) => Object.hasOwn(byEnvironment, key));
|
|
123
|
+
if (named === void 0) throw new TypeError(`tokens.clients names no client for the environment ${environment}: add ${environment} to it, or list the clients every environment admits.`);
|
|
124
|
+
const chosen = byEnvironment[named];
|
|
125
|
+
return typeof chosen === "string" ? [chosen] : chosen;
|
|
126
|
+
}
|
|
127
|
+
|
|
14
128
|
// src/vite/options.ts
|
|
15
129
|
/**
|
|
16
130
|
* What `vite.config.ts` states and what follows from it: the application the generated modules carry and
|
|
@@ -44,7 +158,7 @@ const SERVICE_NAME = /^(?=.{2,63}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
|
44
158
|
/** The application's options and the Worker's settings, apart. `assets` is maximus()'s own. */
|
|
45
159
|
function split(options) {
|
|
46
160
|
if ("assets" in options) throw new TypeError("maximus() configures the assets: index.html at the root makes the project a web app.");
|
|
47
|
-
const { name, namespace, title, description, groups, roles, version, origin, tokens, rpc, http, maxBodyBytes, maxOutputBytes, rateLimit, meter, env, services, webApp, ...worker } = options;
|
|
161
|
+
const { name, namespace, title, description, groups, roles, version, origin, tokens, rpc, http, maxBodyBytes, maxOutputBytes, rateLimit, meter, env, services, webApp, secretsStore: _secretsStore, environments: _environments, ...worker } = options;
|
|
48
162
|
return {
|
|
49
163
|
application: {
|
|
50
164
|
name,
|
|
@@ -71,6 +185,17 @@ function split(options) {
|
|
|
71
185
|
}
|
|
72
186
|
/** The binding a web app's build is served through. */
|
|
73
187
|
const ASSETS = "ASSETS";
|
|
188
|
+
/** The environment that is the Worker's previews: it keeps the Worker's name and answers at preview URLs. */
|
|
189
|
+
const PREVIEWS = "preview";
|
|
190
|
+
/** How the Worker serves a web app's build: its binding, its headers and the pages its own router declares. */
|
|
191
|
+
function webAppAssets(options, phase) {
|
|
192
|
+
const pages = options.webApp?.pages;
|
|
193
|
+
return {
|
|
194
|
+
binding: ASSETS,
|
|
195
|
+
headers: webAppHeaders(options, phase),
|
|
196
|
+
...pages === void 0 ? {} : { pages: [...pages] }
|
|
197
|
+
};
|
|
198
|
+
}
|
|
74
199
|
/** Whether the project is a web app: `index.html` at its root, which Vite builds for the browser. */
|
|
75
200
|
function servesWebApp(root) {
|
|
76
201
|
return existsSync(join(root, "index.html"));
|
|
@@ -125,12 +250,33 @@ function serviceBindings(root, options) {
|
|
|
125
250
|
}));
|
|
126
251
|
}
|
|
127
252
|
/**
|
|
253
|
+
* A secret of the account's Secrets Store that names no store of its own: read from `secretsStore`, under
|
|
254
|
+
* its binding's name unless it names another. `storeSecret()` writes such a binding.
|
|
255
|
+
*/
|
|
256
|
+
function storeSecret(secretName) {
|
|
257
|
+
return bindings.secretsStoreSecret({
|
|
258
|
+
storeId: "",
|
|
259
|
+
secretName: secretName ?? ""
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** A `storeSecret()` binding with the store and the name it left out; any other binding as it is. */
|
|
263
|
+
function storeSecretBinding(key, binding, secretsStore) {
|
|
264
|
+
if (typeof binding !== "object" || binding === null || !("type" in binding) || binding.type !== "secrets-store-secret" || !("storeId" in binding) || binding.storeId !== "") return binding;
|
|
265
|
+
if (typeof secretsStore !== "string" || !secretsStore) throw new TypeError(`${key}: storeSecret() reads the Secrets Store maximus({ secretsStore }) names by its id.`);
|
|
266
|
+
const named = "secretName" in binding && typeof binding.secretName === "string" ? binding.secretName : "";
|
|
267
|
+
return {
|
|
268
|
+
...binding,
|
|
269
|
+
storeId: secretsStore,
|
|
270
|
+
secretName: named || key
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
128
274
|
* The Worker's bindings in a phase: the declared ones and each service's, a web app's assets and, under
|
|
129
275
|
* `vp dev` alone, the development token. A declared binding cannot take the name of either of those.
|
|
130
276
|
*/
|
|
131
277
|
function workerEnv(root, options, phase) {
|
|
132
278
|
const declared = {
|
|
133
|
-
...Object.fromEntries(Object.entries(options.env ?? {}).filter(([, binding]) => binding)),
|
|
279
|
+
...Object.fromEntries(Object.entries(options.env ?? {}).filter(([, binding]) => binding).map(([key, binding]) => [key, storeSecretBinding(key, binding, options.secretsStore)])),
|
|
134
280
|
...serviceBindings(root, options)
|
|
135
281
|
};
|
|
136
282
|
const development = developmentToken(options);
|
|
@@ -196,10 +342,17 @@ function webAppHeaders(options, phase) {
|
|
|
196
342
|
* token's policy under `vp dev` alone, the Worker's HTTP paths, pinned to the origin in production behind
|
|
197
343
|
* Cloudflare Access, and a web app's binding and headers.
|
|
198
344
|
*/
|
|
199
|
-
function projectOptions(root,
|
|
345
|
+
function projectOptions(root, stated, phase = "production", environment = phase) {
|
|
346
|
+
const { options } = resolveEnvironment(stated, environment);
|
|
200
347
|
const { application } = split(options);
|
|
348
|
+
if (options.webApp?.pages !== void 0 && !servesWebApp(root)) throw new TypeError("webApp.pages lists the pages of a web app: add its index.html at the project root.");
|
|
201
349
|
const { name, version } = identity(root, options);
|
|
202
|
-
const { audience = application.origin, development: _declared, ...
|
|
350
|
+
const { audience = application.origin, development: _declared, clients: declaredClients, ...admission } = application.tokens ?? {};
|
|
351
|
+
const clients = environmentClients(declaredClients, environment);
|
|
352
|
+
const tokens = {
|
|
353
|
+
...admission,
|
|
354
|
+
...clients === void 0 ? {} : { clients }
|
|
355
|
+
};
|
|
203
356
|
const development = developmentToken(options);
|
|
204
357
|
const pinned = phase === "production" && tokens.source === "cloudflare-access";
|
|
205
358
|
return {
|
|
@@ -229,10 +382,7 @@ function projectOptions(root, options, phase = "production") {
|
|
|
229
382
|
healthPath: application.http?.healthPath ?? "/health",
|
|
230
383
|
...pinned ? { origins: [new URL(application.origin).origin] } : {}
|
|
231
384
|
},
|
|
232
|
-
...servesWebApp(root) ? { assets: {
|
|
233
|
-
binding: ASSETS,
|
|
234
|
-
headers: webAppHeaders(options, phase)
|
|
235
|
-
} } : {}
|
|
385
|
+
...servesWebApp(root) ? { assets: webAppAssets(options, phase) } : {}
|
|
236
386
|
},
|
|
237
387
|
...options.services ? { services: options.services } : {},
|
|
238
388
|
env: {
|
|
@@ -243,9 +393,18 @@ function projectOptions(root, options, phase = "production") {
|
|
|
243
393
|
}
|
|
244
394
|
/**
|
|
245
395
|
* Where a deployment serves the Worker unless the options route it themselves: at its `workers.dev`
|
|
246
|
-
* subdomain when the origin is one, and otherwise at the origin's host, as its custom domain alone.
|
|
396
|
+
* subdomain when the origin is one, and otherwise at the origin's host, as its custom domain alone. An
|
|
397
|
+
* environment apart from production without an origin of its own is never served at the shared one: the
|
|
398
|
+
* Worker's previews answer at their preview URLs, and a Worker of its own at its `workers.dev` subdomain.
|
|
247
399
|
*/
|
|
248
|
-
function hosting(options, worker) {
|
|
400
|
+
function hosting(options, worker, environment) {
|
|
401
|
+
if (environment.apart && !environment.ownOrigin) {
|
|
402
|
+
const previews = environment.name === PREVIEWS;
|
|
403
|
+
return {
|
|
404
|
+
workersDev: !previews,
|
|
405
|
+
previewUrls: previews
|
|
406
|
+
};
|
|
407
|
+
}
|
|
249
408
|
const { hostname } = new URL(options.origin);
|
|
250
409
|
const onWorkersDev = hostname.endsWith(".workers.dev");
|
|
251
410
|
const routed = worker.domains !== void 0 || worker.triggers?.some(({ type }) => type === "fetch");
|
|
@@ -255,28 +414,43 @@ function hosting(options, worker) {
|
|
|
255
414
|
};
|
|
256
415
|
}
|
|
257
416
|
/**
|
|
417
|
+
* The Worker an environment deploys to: the service's own, whose previews are the `preview` environment, and
|
|
418
|
+
* for any other environment apart from production a Worker of its own, `<name>-<environment>`, so deploying it
|
|
419
|
+
* never replaces production's.
|
|
420
|
+
*/
|
|
421
|
+
function workerName(root, options, environment) {
|
|
422
|
+
const { name } = identity(root, options);
|
|
423
|
+
if (!environment.apart || environment.name === PREVIEWS) return name;
|
|
424
|
+
const own = `${name}-${environment.name}`;
|
|
425
|
+
if (!SERVICE_NAME.test(own)) throw new TypeError(`environments.${environment.name}: its Worker would be ${own}, longer than the 63 characters a Worker's name takes.`);
|
|
426
|
+
return own;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
258
429
|
* The Worker Cloudflare's plugin builds: the options' settings, the generated entry, `nodejs_compat`, which
|
|
259
430
|
* Maximus needs for its diagnostics, the bindings of the phase, where it is served, its observability, a cron
|
|
260
431
|
* trigger for each schedule the cron modules state, a consumer trigger for each queue module the options do not
|
|
261
432
|
* subscribe themselves and, for a web app, its build as assets every request reaches through the Worker,
|
|
262
|
-
* which decides what they answer.
|
|
433
|
+
* which decides what they answer. A build of an environment follows that environment's options, and one apart
|
|
434
|
+
* from production takes its own name, addresses and triggers.
|
|
263
435
|
*/
|
|
264
|
-
function workerConfig(root, phase,
|
|
436
|
+
function workerConfig(root, phase, stated, { crons, queues }, environmentName = phase) {
|
|
437
|
+
const environment = resolveEnvironment(stated, environmentName);
|
|
438
|
+
const { options } = environment;
|
|
265
439
|
const { worker } = split(options);
|
|
266
440
|
const subscribed = new Set((worker.triggers ?? []).flatMap((trigger) => trigger.type === "queue" ? [trigger.name] : []));
|
|
267
|
-
const consumers = queues.filter((queue) => !subscribed.has(queue)).map((queue) => triggers.queue({ name: queue }));
|
|
441
|
+
const consumers = environment.apart ? [] : queues.filter((queue) => !subscribed.has(queue)).map((queue) => triggers.queue({ name: queue }));
|
|
268
442
|
const declared = new Set((worker.triggers ?? []).flatMap((trigger) => trigger.type === "scheduled" ? [trigger.schedule] : []));
|
|
269
443
|
const schedules = crons.map(({ file, cron }) => {
|
|
270
444
|
if (cron === void 0) throw new TypeError(`${file}: export the schedule as a string literal, export const cron = '0 8 * * *'.`);
|
|
271
445
|
return cron;
|
|
272
446
|
});
|
|
273
|
-
const scheduled = [...new Set(schedules)].filter((schedule) => !declared.has(schedule)).map((schedule) => triggers.scheduled({ schedule }));
|
|
447
|
+
const scheduled = environment.apart ? [] : [...new Set(schedules)].filter((schedule) => !declared.has(schedule)).map((schedule) => triggers.scheduled({ schedule }));
|
|
274
448
|
return {
|
|
275
|
-
...hosting(options, worker),
|
|
276
449
|
previewUrls: false,
|
|
450
|
+
...hosting(options, worker, environment),
|
|
277
451
|
...worker,
|
|
278
452
|
observability: observability(worker.observability),
|
|
279
|
-
name:
|
|
453
|
+
name: workerName(root, options, environment),
|
|
280
454
|
compatibilityFlags: [.../* @__PURE__ */ new Set(["nodejs_compat", ...worker.compatibilityFlags ?? []])],
|
|
281
455
|
entrypoint: "./.maximus/entry.ts",
|
|
282
456
|
...servesWebApp(root) ? { assets: {
|
|
@@ -945,9 +1119,29 @@ function discoverDurableObjects(files, imports) {
|
|
|
945
1119
|
return `export const ${className} = worker.durableObject(${imports.add(`durable_object_${index}`, file)});`;
|
|
946
1120
|
});
|
|
947
1121
|
}
|
|
1122
|
+
/** A declared page's segment: a fixed name, or a parameter as React Router (`:id`) or TanStack Router (`$id`) writes it. */
|
|
1123
|
+
const PAGE_SEGMENT = /^(?:[a-zA-Z0-9._~-]+|[:$][a-zA-Z][a-zA-Z0-9_]*)$/;
|
|
948
1124
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
1125
|
+
* The pages `webApp.pages` declares, as paths with `:parameter` segments: `/` or absolute paths of fixed and
|
|
1126
|
+
* parameter segments, no trailing slash, each shape once.
|
|
1127
|
+
*/
|
|
1128
|
+
function declaredPages(declared) {
|
|
1129
|
+
if (!Array.isArray(declared) || !declared.length) throw new TypeError("webApp.pages lists one or more page paths, such as /patients/:patientId, or is absent.");
|
|
1130
|
+
const shapes = /* @__PURE__ */ new Set();
|
|
1131
|
+
return declared.map((path) => {
|
|
1132
|
+
const segments = typeof path === "string" && path.startsWith("/") ? path.slice(1).split("/") : [];
|
|
1133
|
+
if (!(path === "/" || segments.length > 0 && segments.every((segment) => PAGE_SEGMENT.test(segment) && segment !== "." && segment !== ".."))) throw new TypeError(`webApp.pages takes absolute paths of fixed and :parameter or $parameter segments, such as /patients/:patientId: ${String(path)}`);
|
|
1134
|
+
const route = path === "/" ? "/" : `/${segments.map((segment) => segment.replace(/^\$/, ":")).join("/")}`;
|
|
1135
|
+
const shape = route.replaceAll(/:[^/]+/g, ":");
|
|
1136
|
+
if (shapes.has(shape)) throw new TypeError(`webApp.pages lists the same page twice: ${path}`);
|
|
1137
|
+
shapes.add(shape);
|
|
1138
|
+
return route;
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* A web app: `index.html` at the root, which the plugin found, and the pages `app/routes/` declares, or those
|
|
1143
|
+
* its own router declares in `webApp.pages`. The same files make React Router's routes and the paths the
|
|
1144
|
+
* Worker answers with the app's shell.
|
|
951
1145
|
*/
|
|
952
1146
|
function discoverWebApp(root, output, mode, project, pagePaths) {
|
|
953
1147
|
const web = project.worker.assets;
|
|
@@ -965,10 +1159,18 @@ function discoverWebApp(root, output, mode, project, pagePaths) {
|
|
|
965
1159
|
"js"
|
|
966
1160
|
]);
|
|
967
1161
|
const pages = projectFiles(root, "app/routes", mode);
|
|
1162
|
+
const declared = web.pages === void 0 ? [] : declaredPages(web.pages);
|
|
1163
|
+
if (declared.length && pages.length) throw new TypeError("Declare a web app's pages once: in app/routes/ or in webApp.pages, not both.");
|
|
968
1164
|
const shell = {
|
|
969
|
-
paths: pages.length ? [] : ["/"],
|
|
1165
|
+
paths: pages.length || declared.length ? [] : ["/"],
|
|
970
1166
|
patterns: []
|
|
971
1167
|
};
|
|
1168
|
+
/** Answers a page's path with the shell: exactly, or by a pattern when it carries a parameter. */
|
|
1169
|
+
const servePage = (route) => {
|
|
1170
|
+
if (route.includes(":")) shell.patterns.push(`/^${route.replaceAll(/:[^/]+/g, "[^/]+").replaceAll("/", String.raw`\/`).replaceAll(".", String.raw`\.`)}$/`);
|
|
1171
|
+
else shell.paths.push(route);
|
|
1172
|
+
};
|
|
1173
|
+
for (const route of declared) servePage(route);
|
|
972
1174
|
const claimed = /* @__PURE__ */ new Map();
|
|
973
1175
|
const imports = new Imports(output);
|
|
974
1176
|
const routes = pages.map(({ name, file }) => {
|
|
@@ -977,16 +1179,19 @@ function discoverWebApp(root, output, mode, project, pagePaths) {
|
|
|
977
1179
|
const owner = claimed.get(shape);
|
|
978
1180
|
if (owner) throw new TypeError(`Multiple page files claim ${route}: ${relative(root, owner)} and ${relative(root, file)}.`);
|
|
979
1181
|
claimed.set(shape, file);
|
|
980
|
-
|
|
981
|
-
else shell.paths.push(route);
|
|
1182
|
+
servePage(route);
|
|
982
1183
|
return `{ path: ${JSON.stringify(route)}, caseSensitive: true, lazy: () => import(${imports.source(file)}).then(page) }`;
|
|
983
1184
|
});
|
|
984
|
-
for (const route of [
|
|
1185
|
+
for (const route of [
|
|
1186
|
+
...shell.paths,
|
|
1187
|
+
...declared,
|
|
1188
|
+
...pages.map(({ name }) => projectPath(name, "app"))
|
|
1189
|
+
]) if ([
|
|
985
1190
|
basePath,
|
|
986
1191
|
"/.well-known",
|
|
987
1192
|
"/mcp",
|
|
988
1193
|
"/assets"
|
|
989
|
-
].some((prefix) => ownsPrefix(prefix, route)) || route === healthPath || VERSIONED_PATH.test(route) || pagePaths.has(route)) throw new TypeError(`The page ${route} claims a path the API, discovery, MCP, the build's assets or pages/ answer: move it in app/routes
|
|
1194
|
+
].some((prefix) => ownsPrefix(prefix, route)) || route === healthPath || VERSIONED_PATH.test(route) || pagePaths.has(route)) throw new TypeError(`The page ${route} claims a path the API, discovery, MCP, the build's assets or pages/ answer: move it in ${declared.length ? "webApp.pages" : "app/routes/"}.`);
|
|
990
1195
|
const source = pages.length ? generatedModule(mode, [
|
|
991
1196
|
"import type { ComponentType } from 'react';",
|
|
992
1197
|
"import type { RouteObject } from 'react-router';",
|
|
@@ -1296,13 +1501,14 @@ function workerShape({ webApp, durableObjects, crons, queues }) {
|
|
|
1296
1501
|
* trigger its cron and queue modules state. The project is prepared for `development` under `vp dev` alone;
|
|
1297
1502
|
* every build is `production`.
|
|
1298
1503
|
*/
|
|
1299
|
-
function maximusProject(project) {
|
|
1504
|
+
function maximusProject(project, environments = []) {
|
|
1300
1505
|
let root = process.cwd();
|
|
1301
1506
|
let mode = "production";
|
|
1507
|
+
let building;
|
|
1302
1508
|
let previous;
|
|
1303
|
-
const prepare = (directory, preparing) => prepareProject(directory, preparing, project(resolve(directory), preparing));
|
|
1509
|
+
const prepare = (directory, preparing, environment) => prepareProject(directory, preparing, project(resolve(directory), preparing, environment));
|
|
1304
1510
|
const reconcile = () => {
|
|
1305
|
-
const current = prepare(root, mode);
|
|
1511
|
+
const current = prepare(root, mode, building);
|
|
1306
1512
|
const restart = previous !== void 0 && workerShape(previous) !== workerShape(current);
|
|
1307
1513
|
previous = current;
|
|
1308
1514
|
return {
|
|
@@ -1317,10 +1523,14 @@ function maximusProject(project) {
|
|
|
1317
1523
|
return {
|
|
1318
1524
|
name: "maximus-project",
|
|
1319
1525
|
enforce: "pre",
|
|
1320
|
-
api: {
|
|
1526
|
+
api: {
|
|
1527
|
+
prepare,
|
|
1528
|
+
environments
|
|
1529
|
+
},
|
|
1321
1530
|
config(config, environment) {
|
|
1322
1531
|
root = resolve(config.root ?? root);
|
|
1323
1532
|
mode = environment.command === "serve" && !environment.isPreview ? "development" : "production";
|
|
1533
|
+
building = environmentName(mode, environment.mode);
|
|
1324
1534
|
reconcile();
|
|
1325
1535
|
},
|
|
1326
1536
|
buildStart() {
|
|
@@ -1376,6 +1586,40 @@ function auth0({ domain, audience, algorithms = ["RS256"] }) {
|
|
|
1376
1586
|
algorithms
|
|
1377
1587
|
};
|
|
1378
1588
|
}
|
|
1589
|
+
/** Arbol's Identity in production. */
|
|
1590
|
+
const ARBOL_IDENTITY = "https://id.getarbol.com";
|
|
1591
|
+
/**
|
|
1592
|
+
* The token options of a service whose access tokens Arbol's Identity issues, as its OpenID metadata publishes
|
|
1593
|
+
* it: the issuer, its JWKS (`/api/auth/jwks`), its authorization and token endpoints (`/api/auth/oauth2/…`),
|
|
1594
|
+
* access tokens that say so (`typ: at+jwt`), and machines whose subject is their client id. With `clients`, it
|
|
1595
|
+
* admits only the tokens of those clients, each environment's own when they are named by environment; with
|
|
1596
|
+
* `people: 'all'`, their people may call every public operation:
|
|
1597
|
+
*
|
|
1598
|
+
* tokens: arbolIdentity({ clients: { production: '…', preview: '…' }, people: 'all' })
|
|
1599
|
+
*
|
|
1600
|
+
* Throws a TypeError for an issuer that is not an HTTPS origin.
|
|
1601
|
+
*/
|
|
1602
|
+
function arbolIdentity({ audience, issuer = ARBOL_IDENTITY, clients, people } = {}) {
|
|
1603
|
+
let origin;
|
|
1604
|
+
try {
|
|
1605
|
+
const url = new URL(issuer);
|
|
1606
|
+
origin = url.protocol === "https:" && url.origin === issuer ? url.origin : void 0;
|
|
1607
|
+
} catch {
|
|
1608
|
+
origin = void 0;
|
|
1609
|
+
}
|
|
1610
|
+
if (origin === void 0) throw new TypeError("arbolIdentity() takes Identity's issuer as an HTTPS origin, such as https://id.getarbol.com.");
|
|
1611
|
+
return {
|
|
1612
|
+
issuer: origin,
|
|
1613
|
+
...audience === void 0 ? {} : { audience },
|
|
1614
|
+
jwksUri: "/api/auth/jwks",
|
|
1615
|
+
authorizationEndpoint: "/api/auth/oauth2/authorize",
|
|
1616
|
+
tokenEndpoint: "/api/auth/oauth2/token",
|
|
1617
|
+
requireType: "at+jwt",
|
|
1618
|
+
claims: { machineSubject: "{client}" },
|
|
1619
|
+
...clients === void 0 ? {} : { clients },
|
|
1620
|
+
...people === void 0 ? {} : { people }
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1379
1623
|
/**
|
|
1380
1624
|
* The token options of an application behind Cloudflare Access: the application token Access sets in
|
|
1381
1625
|
* `Cf-Access-Jwt-Assertion`, read from there alone and verified against the team's keys (RS256, issued by
|
|
@@ -1438,17 +1682,18 @@ async function presets(config) {
|
|
|
1438
1682
|
* Cloudflare's Vite plugin.
|
|
1439
1683
|
*/
|
|
1440
1684
|
function maximus(options) {
|
|
1441
|
-
const project = maximusProject((root, phase) => projectOptions(root, options, phase));
|
|
1685
|
+
const project = maximusProject((root, phase, environment) => projectOptions(root, options, phase, environment), Object.keys(options.environments ?? {}));
|
|
1442
1686
|
let worker;
|
|
1443
1687
|
const configure = {
|
|
1444
1688
|
name: "maximus",
|
|
1445
1689
|
enforce: "pre",
|
|
1446
|
-
async config(config, { command, isPreview }) {
|
|
1690
|
+
async config(config, { command, isPreview, mode }) {
|
|
1447
1691
|
const root = resolve(config.root ?? process.cwd());
|
|
1448
1692
|
const phase = command === "serve" && !isPreview ? "development" : "production";
|
|
1693
|
+
const environment = environmentName(phase, mode);
|
|
1449
1694
|
for (const [file, subject] of [["cloudflare.config.ts", "the Worker"], ["maximus.config.ts", "the application"]]) if (existsSync(join(root, file))) throw new TypeError(`maximus() configures ${subject}: move ${file} into maximus()'s options.`);
|
|
1450
1695
|
checkWebAppBuild(root, config);
|
|
1451
|
-
worker = workerConfig(root, phase, options, project.api.prepare(root, phase));
|
|
1696
|
+
worker = workerConfig(root, phase, options, project.api.prepare(root, phase, environment), environment);
|
|
1452
1697
|
return await presets(config);
|
|
1453
1698
|
},
|
|
1454
1699
|
configEnvironment(name, config) {
|
|
@@ -1492,4 +1737,4 @@ function testing() {
|
|
|
1492
1737
|
};
|
|
1493
1738
|
}
|
|
1494
1739
|
|
|
1495
|
-
export { auth0, cloudflareAccess, maximus };
|
|
1740
|
+
export { arbolIdentity, auth0, cloudflareAccess, maximus, storeSecret };
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fr as Result, qr as Failure } from "./chunks/types-Dmw37bhl.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/workers-types-
|
|
1
|
+
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-CYOvun0Q.js";
|
|
2
2
|
export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
|
package/dist/workers/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arbol-ai/maximus",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, configured in vite.config.ts, with its OpenAPI and CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
package/skills/maximus/SKILL.md
CHANGED
|
@@ -90,7 +90,11 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
90
90
|
| A rule for every operation, on every transport | `defineOperationMiddleware` in `middleware/`. |
|
|
91
91
|
| Headers or an early answer around every request | `defineMiddleware` in `middleware/`. It runs before admission and sees no principal. |
|
|
92
92
|
| Access tokens Auth0 issues | `tokens: auth0({ domain, audience })` from `@arbol-ai/maximus/vite`, with RBAC and permissions in the access token turned on. See [references/project.md](references/project.md#tokens). |
|
|
93
|
+
| Access tokens Arbol's Identity issues | `tokens: arbolIdentity({ audience, clients, people })` from `@arbol-ai/maximus/vite`. See [references/project.md](references/project.md#tokens). |
|
|
94
|
+
| Admit only some clients, only people, or every member of the organization | `clients`, `actorKinds` and `people: 'all'` in `tokens`: no `auth.ts`. See [references/project.md](references/project.md#tokens). |
|
|
93
95
|
| An application behind Cloudflare Access | `tokens: cloudflareAccess({ team, aud, organizationId, scopes })` from `@arbol-ai/maximus/vite`. MCP needs `managedOAuth: true` and Managed OAuth at the edge. See [references/project.md](references/project.md#tokens). |
|
|
96
|
+
| Production, previews and other environments | `environments: { preview: { … } }` in `maximus()`, built with `vp build --mode preview`. See [references/project.md](references/project.md#environments). |
|
|
97
|
+
| A web app with its own router | `webApp: { pages: ['/', '/notes/$noteId'] }`. See [references/project.md](references/project.md#the-workers-other-parts). |
|
|
94
98
|
| Tokens your authorization server does not issue | `auth.ts` with `defineAuth({ resolve })`, which verifies cryptographically. |
|
|
95
99
|
| A provider's webhook, without a token | A page named for its method, `pages/webhooks/<provider>.post.ts`, which verifies the signature on the exact bytes with `@arbol-ai/maximus/webhooks`. See [references/project.md](references/project.md). |
|
|
96
100
|
| Many items in one answer | `output: Page(Item, { $id: 'ItemPage' })` with `input: PageQueryFields`. |
|
|
@@ -21,6 +21,13 @@ bun run preview # the production bu
|
|
|
21
21
|
|
|
22
22
|
`vp build` writes the Build Output to `.cloudflare/output/`; `cf deploy --prebuilt` deploys it as it is.
|
|
23
23
|
|
|
24
|
+
An [environment](project.md#environments) is built and deployed by its name:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
vp build --mode preview && bunx cf previews deploy --prebuilt --mode preview --preview-name pr-12 # a preview of the Worker
|
|
28
|
+
vp build --mode staging && bunx cf deploy --prebuilt --mode staging # the Worker <name>-staging
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Secrets
|
|
25
32
|
|
|
26
33
|
- Declare each one as `bindings.secret()` in `env`. Under `vp dev` its value comes from `.dev.vars`.
|
|
@@ -29,6 +36,8 @@ bun run preview # the production bu
|
|
|
29
36
|
`The following required secrets have not been set`.
|
|
30
37
|
- Later deployments keep each value unless their secrets file brings a new one.
|
|
31
38
|
`bunx cf workers secrets update <NAME> --worker <name>` changes one alone, as a new version.
|
|
39
|
+
- A secret of the account's Secrets Store is `storeSecret()` in `env`, with `secretsStore: '<store id>'` in
|
|
40
|
+
`maximus()`; read it with `await env.NAME.get()`.
|
|
32
41
|
- Never put a secret in `bindings.text()`, code, the repository or a log. Never set `DEVELOPMENT_TOKEN` on a
|
|
33
42
|
deployed Worker; `maximus()` refuses to declare it.
|
|
34
43
|
|
|
@@ -25,7 +25,7 @@ export default defineConfig({
|
|
|
25
25
|
| Option | Meaning, and default |
|
|
26
26
|
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
27
|
| `origin` | Required. The public HTTPS URL that OpenAPI, MCP resources and OAuth discovery advertise, and the default token audience. A `workers.dev` origin is served there; any other host becomes the Worker's custom domain unless `domains` or a fetch trigger route it. |
|
|
28
|
-
| `tokens` | `issuer`, the OAuth authorization server; `audience`, the origin by default; `jwksUri`, `algorithms`, `claims`, `scheme`, `authorizationEndpoint`, `tokenEndpoint`; `source` and `access` behind Cloudflare Access; `development`, the development token's binding, `DEVELOPMENT_TOKEN` by default, `false` for none. See [Tokens](#tokens). |
|
|
28
|
+
| `tokens` | `issuer`, the OAuth authorization server; `audience`, the origin by default; `jwksUri`, `algorithms`, `claims`, `scheme`, `authorizationEndpoint`, `tokenEndpoint`; `source` and `access` behind Cloudflare Access; `development`, the development token's binding, `DEVELOPMENT_TOKEN` by default, `false` for none. See [Tokens](#tokens). `additionalIssuers` lists other servers trusted during a move, each with its own JWKS, claims and `requireType`; a token is verified against the one its `iss` names. |
|
|
29
29
|
| `name` | The Worker's name, the MCP server's and the scopes' prefix: lowercase letters, digits and single hyphens. By default, the package's name without its scope. |
|
|
30
30
|
| `namespace`, `title`, `version` | The scopes' prefix (the name), the human name (the name), the version `/health` reports (the package's). |
|
|
31
31
|
| `description`, `groups` | The OpenAPI document's description of the service, and of each group of routes by its name: `{ Notes: "The notes of the caller's organization." }`. |
|
|
@@ -37,7 +37,9 @@ export default defineConfig({
|
|
|
37
37
|
| `rateLimit` | `{ binding, retryAfter }`: a rate limiting binding every HTTP and MCP call passes, per organization and actor. |
|
|
38
38
|
| `meter` | `{ binding }`: the binding of the billing service that routes and tools declaring `meter` report to. Type it with `BillingService<Feature>` from `@arbol-ai/maximus`, whose `Feature` names the facts they may report. See [Metering](https://github.com/getarbol/maximus/blob/main/docs/guides/metering.md). |
|
|
39
39
|
| `env` | The Worker's bindings, from `cf/config`'s `bindings`. |
|
|
40
|
-
| `webApp`
|
|
40
|
+
| `webApp` | `{ headers, pages }`: the headers of a web app's pages and files, and the pages of an app whose own router declares them, `pages: ['/', '/notes/$noteId']`. |
|
|
41
|
+
| `secretsStore` | The account's Secrets Store, by its id: `storeSecret()` from `@arbol-ai/maximus/vite` then binds a secret of it, named as its binding. |
|
|
42
|
+
| `environments` | What each environment changes, by its name, the Vite mode that builds it: `{ preview: { env: { DB: … } } }`. See [Environments](#environments). |
|
|
41
43
|
| Any other key | A Worker setting as Cloudflare names it: `compatibilityDate`, `compatibilityFlags`, `triggers`, `exports`, `observability`, `placement`, `limits`, `domains`, `workersDev`, `previewUrls`. |
|
|
42
44
|
|
|
43
45
|
`maximus()` owns the Worker's entry (`.maximus/entry.ts`) and a web app's assets, always adds
|
|
@@ -51,8 +53,8 @@ cron and queue module, and declares the development token under `vp dev` alone.
|
|
|
51
53
|
## Tokens
|
|
52
54
|
|
|
53
55
|
`tokens` states which tokens the API admits: by default, OAuth access tokens of the `issuer` it names, for
|
|
54
|
-
the `origin` as their audience. `auth0()` and `cloudflareAccess()` from
|
|
55
|
-
options for those providers, as plain data:
|
|
56
|
+
the `origin` as their audience. `auth0()`, `arbolIdentity()` and `cloudflareAccess()` from
|
|
57
|
+
`@arbol-ai/maximus/vite` state the options for those providers, as plain data:
|
|
56
58
|
|
|
57
59
|
```ts
|
|
58
60
|
import { auth0, cloudflareAccess, maximus } from '@arbol-ai/maximus/vite';
|
|
@@ -89,7 +91,15 @@ tokens: cloudflareAccess({
|
|
|
89
91
|
is absent. The Worker serves no OAuth discovery. If Cloudflare Access serves Managed OAuth at the edge,
|
|
90
92
|
set `managedOAuth: true` in `cloudflareAccess()` to serve MCP with the same verified assertions and
|
|
91
93
|
scopes. Under `vp dev` and in tests, the development token still signs in as a bearer token.
|
|
94
|
+
- `arbolIdentity({ audience?, issuer?, clients?, people? })`: a service whose tokens Arbol's Identity
|
|
95
|
+
(`https://id.getarbol.com`) issues. It answers Identity's issuer, JWKS and endpoints, `requireType: 'at+jwt'`
|
|
96
|
+
and machines named by their client id. `clients` admits only those clients' tokens, a list or each
|
|
97
|
+
environment's own, `{ production: '…', preview: '…' }`; `people: 'all'` lets their people call every public
|
|
98
|
+
route when Identity grants none of the service's scopes yet, and needs `clients`.
|
|
92
99
|
- Spread a preset to add what it leaves out: `tokens: { ...auth0({ domain, audience }), development: false }`.
|
|
100
|
+
- Any OAuth policy may state who it admits without an `auth.ts`: `clients` (by client id), `actorKinds`
|
|
101
|
+
(`['user']`, `['service']`) and `people` (`'token'`, the default, or `'all'`). Never write an `auth.ts` only
|
|
102
|
+
to check a client, refuse machines or grant every member the public scopes.
|
|
93
103
|
|
|
94
104
|
Tokens that no issuer signs, such as keys the service issues itself, are verified by `auth.ts`. See
|
|
95
105
|
[Authentication and scopes](https://github.com/getarbol/maximus/blob/main/docs/guides/authentication-and-scopes.md).
|
|
@@ -188,6 +198,37 @@ output. `.maximus/` is in `.gitignore`.
|
|
|
188
198
|
A project is prepared for `development` under `vp dev` and `vp test`, and for `production` in every build and
|
|
189
199
|
preview. A module named `<name>.dev.ts` exists in development alone, `<name>.prod.ts` in production alone.
|
|
190
200
|
|
|
201
|
+
## Environments
|
|
202
|
+
|
|
203
|
+
`environments` states what each place the service runs changes over the shared options, by its name, which
|
|
204
|
+
is the Vite mode of its build: `vp build --mode preview` builds `preview`. State only what differs: `env`
|
|
205
|
+
and `tokens` merge key by key, every other option replaces the shared one.
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
maximus({
|
|
209
|
+
origin: 'https://notes.example.com',
|
|
210
|
+
tokens: arbolIdentity({ clients: { production: '…', preview: '…' }, people: 'all' }),
|
|
211
|
+
env: { DB: bindings.hyperdrive({ id: '<production>' }), DOCUMENTS: bindings.r2({ name: 'notes-documents' }) },
|
|
212
|
+
environments: { preview: { env: { DB: bindings.hyperdrive({ id: '<preview>' }) } } },
|
|
213
|
+
}),
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`production` and `development` only override. Any other environment is apart from production, and Maximus
|
|
217
|
+
keeps production out of it:
|
|
218
|
+
|
|
219
|
+
- `preview` is the Worker's previews (`cf previews deploy --prebuilt --mode preview`), at its preview URLs.
|
|
220
|
+
Any other environment is a Worker of its own, `<name>-<environment>`, at the `origin` it states or at
|
|
221
|
+
`workers.dev`. Neither takes the shared `domains`.
|
|
222
|
+
- It runs only the `triggers` it states: no shared route, no schedule of a cron module, no consumer of a
|
|
223
|
+
queue module.
|
|
224
|
+
- A shared R2 bucket becomes `<bucket>-<environment>`. A shared D1, KV or Hyperdrive bound by its id, and a
|
|
225
|
+
shared queue, are refused until the environment declares its own in its `env`. Never work around the
|
|
226
|
+
refusal by repeating production's id unless the person asks to share that store.
|
|
227
|
+
- `tokens.clients` by environment admits each environment's own clients.
|
|
228
|
+
|
|
229
|
+
Never read `process.env` or the Vite mode in `vite.config.ts` to tell environments apart: declare the
|
|
230
|
+
environment.
|
|
231
|
+
|
|
191
232
|
## The Worker's other parts
|
|
192
233
|
|
|
193
234
|
| Folder | A file |
|
|
@@ -200,6 +241,8 @@ preview. A module named `<name>.dev.ts` exists in development alone, `<name>.pro
|
|
|
200
241
|
|
|
201
242
|
A web app is `index.html` at the root, with its pages in `app/routes/` (React Router), its layout in
|
|
202
243
|
`app/root.tsx` and its static files in `public/`. The same Worker serves it, and the API stays below `/api`.
|
|
244
|
+
An app with another router, such as TanStack Router, lists its pages in `webApp.pages` instead, and the
|
|
245
|
+
Worker answers them with `index.html`: never a middleware that serves the shell.
|
|
203
246
|
|
|
204
247
|
Each topic has a guide: [Project structure](https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md),
|
|
205
248
|
[Bindings](https://github.com/getarbol/maximus/blob/main/docs/guides/bindings.md),
|