@protobase/cli 0.49.0 → 0.49.1

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.
Files changed (39) hide show
  1. package/dist/cli/package.js +1 -1
  2. package/dist/config/build-project.js +6 -3
  3. package/dist/config/config-defaults.js +3 -0
  4. package/package.json +7 -7
  5. package/skills/protobase/SKILL.md +7 -1
  6. package/skills/protobase/references/features/sign-in-and-accounts.md +2 -0
  7. package/skills/protobase/references/features/start-a-project.md +6 -0
  8. package/skills/protobase/references/getting-started.md +13 -13
  9. package/skills/protobase/references/guides/deploy.md +2 -2
  10. package/skills/protobase/references/guides/export-a-list.md +1 -1
  11. package/skills/protobase/references/guides/field-type.md +1 -1
  12. package/skills/protobase/references/guides/first-composed-page.md +1 -1
  13. package/skills/protobase/references/guides/first-plugin.md +1 -1
  14. package/skills/protobase/references/guides/import-records.md +1 -1
  15. package/skills/protobase/references/guides/personal-setting.md +1 -1
  16. package/skills/protobase/references/guides/push-notifications.md +1 -1
  17. package/skills/protobase/references/guides/record-card.md +1 -1
  18. package/skills/protobase/references/guides/remote-resources.md +1 -1
  19. package/skills/protobase/references/guides/theme-an-app.md +1 -1
  20. package/skills/protobase/references/reference/api.md +1 -1
  21. package/skills/protobase/references/reference/architecture.md +4 -4
  22. package/skills/protobase/references/reference/auth.md +29 -2
  23. package/skills/protobase/references/reference/blocks.md +1 -1
  24. package/skills/protobase/references/reference/bottom-bar.md +1 -1
  25. package/skills/protobase/references/reference/cli.md +9 -9
  26. package/skills/protobase/references/reference/client.md +2 -2
  27. package/skills/protobase/references/reference/config/admin-app.md +62 -0
  28. package/skills/protobase/references/reference/config/api.md +164 -0
  29. package/skills/protobase/references/reference/config/app.md +112 -0
  30. package/skills/protobase/references/reference/config/files.md +99 -0
  31. package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
  32. package/skills/protobase/references/reference/config/sign-in.md +396 -0
  33. package/skills/protobase/references/reference/config.md +88 -70
  34. package/skills/protobase/references/reference/custom-components.md +2 -2
  35. package/skills/protobase/references/reference/data-config.md +2 -2
  36. package/skills/protobase/references/reference/email.md +1 -1
  37. package/skills/protobase/references/reference/sidebar.md +2 -2
  38. package/skills/protobase/references/reference/ui-config.md +5 -5
  39. package/skills/protobase/references/reference/user-menu.md +1 -1
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.49.0";
2
+ var version = "0.49.1";
3
3
  //#endregion
4
4
  export { version };
@@ -2,13 +2,13 @@ import { projectFiles, projectFunctions, projectJobs, projectNotifications, proj
2
2
  import { buildAppAuth, buildAuthenticator } from "@protobase/server/internal";
3
3
  //#region src/config/build-project.ts
4
4
  /**
5
- * The app's sign-in, built from `auth` with the app's URL, secret and name, the hooks of its auth/hooks.ts and the
6
- * mailer of its auth/mailer.ts when it has them; none without `auth`.
5
+ * The app's sign-in, built from `auth` with the app's URL, secrets, signing key rotation and name, the hooks of its
6
+ * auth/hooks.ts and the mailer of its auth/mailer.ts when it has them; none without `auth`.
7
7
  */
8
8
  const projectAuth = async (config, { db, pool }) => {
9
9
  if (!config.auth) return void 0;
10
10
  if (!pool) throw new Error("auth needs the app's pool, which its store shares");
11
- const { url, secret, name } = config;
11
+ const { url, secret, previousSecrets, signingKeyDays, signingKeyGraceDays, name } = config;
12
12
  if (!url) throw new Error("Sign-in needs the app's public URL: set PROTOBASE_URL, such as https://admin.example.com, or url in protobase.config.ts");
13
13
  if (!secret) throw new Error("Sign-in needs the app's secret: set PROTOBASE_SECRET to the output of `openssl rand -base64 32`, or secret in protobase.config.ts");
14
14
  const [hooks, mailer] = await Promise.all(["auth/hooks.ts", "auth/mailer.ts"].map((file) => config.authFiles?.module(file)?.()));
@@ -16,6 +16,9 @@ const projectAuth = async (config, { db, pool }) => {
16
16
  ...config.auth || {},
17
17
  baseURL: url,
18
18
  secret,
19
+ ...previousSecrets && { previousSecrets },
20
+ ...signingKeyDays !== void 0 && { signingKeyDays },
21
+ ...signingKeyGraceDays !== void 0 && { signingKeyGraceDays },
19
22
  ...name && { appName: name }
20
23
  }, {
21
24
  pool,
@@ -5,6 +5,7 @@ const listOf = (text) => text?.split(",").map((part) => part.trim()).filter(Bool
5
5
  *
6
6
  * - `url`: `PROTOBASE_URL`, or in `protobase dev` the dev server's own address;
7
7
  * - `secret`: `PROTOBASE_SECRET`;
8
+ * - `previousSecrets`: `PROTOBASE_PREVIOUS_SECRETS`, comma separated;
8
9
  * - `auth`: on, with its own defaults, unless it is `false` or `authenticate.jwksUrl` trusts an auth server elsewhere;
9
10
  * - `auth.trustedOrigins`: `PROTOBASE_TRUSTED_ORIGINS`, comma separated.
10
11
  *
@@ -13,6 +14,7 @@ const listOf = (text) => text?.split(",").map((part) => part.trim()).filter(Bool
13
14
  const withDefaults = (config, command, env) => {
14
15
  const url = config.url ?? (env.PROTOBASE_URL?.trim() || void 0) ?? (command === "dev" ? env.PROTOBASE_DEV_URL : void 0);
15
16
  const secret = config.secret ?? (env.PROTOBASE_SECRET?.trim() || void 0);
17
+ const previousSecrets = config.previousSecrets ?? listOf(env.PROTOBASE_PREVIOUS_SECRETS);
16
18
  const authOn = config.auth !== false && (config.auth !== void 0 || !config.authenticate?.jwksUrl);
17
19
  const trustedOrigins = listOf(env.PROTOBASE_TRUSTED_ORIGINS);
18
20
  const { auth: _, ...rest } = config;
@@ -20,6 +22,7 @@ const withDefaults = (config, command, env) => {
20
22
  ...rest,
21
23
  ...url && { url },
22
24
  ...secret && { secret },
25
+ ...previousSecrets?.length && { previousSecrets },
23
26
  ...authOn && { auth: {
24
27
  ...trustedOrigins && { trustedOrigins },
25
28
  ...config.auth || {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.49.0",
3
+ "version": "0.49.1",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -39,12 +39,12 @@
39
39
  "dependencies": {
40
40
  "@better-auth/core": "^1.7.12",
41
41
  "@hono/node-server": "^2.1.3",
42
- "@protobase/config": "0.49.0",
43
- "@protobase/layout": "0.49.0",
44
- "@protobase/query": "0.49.0",
45
- "@protobase/schema": "0.49.0",
46
- "@protobase/server": "0.49.0",
47
- "@protobase/ui": "0.49.0",
42
+ "@protobase/config": "0.49.1",
43
+ "@protobase/layout": "0.49.1",
44
+ "@protobase/query": "0.49.1",
45
+ "@protobase/schema": "0.49.1",
46
+ "@protobase/server": "0.49.1",
47
+ "@protobase/ui": "0.49.1",
48
48
  "@react-email/render": "^2.1.0",
49
49
  "@scalar/hono-api-reference": "^0.12.10",
50
50
  "@tailwindcss/vite": "^4.3.3",
@@ -63,7 +63,13 @@ Guides:
63
63
 
64
64
  Reference:
65
65
 
66
- - When writing `protobase.config.ts`, or looking for where a job's, hook's or other piece of the app's code goes → read [protobase.config.ts](references/reference/config.md)
66
+ - When writing `protobase.config.ts`, or looking for where a job's, hook's or other piece of the app's code goes → read [Configuring Protobase](references/reference/config.md)
67
+ - When setting the app's name, URL, secret, language, time zone or mobile build in the config → read [App options](references/reference/config/app.md)
68
+ - When setting `auth` or `authenticate` in the config → read [Sign-in options](references/reference/config/sign-in.md)
69
+ - When setting the API's keys, CORS, limits, write hooks, MCP tools or remote resources in the config → read [API options](references/reference/config/api.md)
70
+ - When setting the assistant, maps or plugins in the config → read [Admin app options](references/reference/config/admin-app.md)
71
+ - When setting `jobs`, `events`, `history`, `webhooks` or `notifications` in the config → read [Jobs and events options](references/reference/config/jobs-and-events.md)
72
+ - When setting `files` in the config → read [Files options](references/reference/config/files.md)
67
73
  - When defining resources, fields, keys, relations, rollups, formulas and validation → read [Data config](references/reference/data-config.md)
68
74
  - When defining views, columns, filters, charts, related records and actions → read [UI config](references/reference/ui-config.md)
69
75
  - When asking how the packages fit together → read [Architecture](references/reference/architecture.md)
@@ -25,6 +25,8 @@ Sign-in methods, users, roles, organizations and tokens.
25
25
  - [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
26
26
  - [API tokens](../reference/auth.md#tokens-and-roles): A signed-in session gets short-lived tokens for the API.
27
27
  - [Immediate revocation](../reference/auth.md#when-a-token-stops-working): A ban, removed role or ended session takes effect on the next request.
28
+ - [Signing key rotation](../reference/auth.md#signing-keys): The keys that sign the tokens are replaced every 30 days on their own, and old ones keep verifying the tokens they signed for a week.
29
+ - [Changing the secret](../reference/auth.md#changing-the-secret): The app's secret can change while the signing keys keep signing, by listing the old secret beside the new one.
28
30
  - [Tokens for scripts](../reference/auth.md#tokens-for-scripts-and-curl): A token for an existing user, for scripts and curl.
29
31
  - [Several origins](../reference/auth.md#several-origins): One app works on several domains, such as its own address and a custom domain.
30
32
  - [Sign-in rate limits](../reference/auth.md#client-addresses): Sign-in and code requests are limited per client address, also behind a proxy.
@@ -9,6 +9,12 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
9
9
  - [One config](../reference/config.md): The whole app is one object of data in `protobase.config.ts`, typed with `defineConfig`, with a sensible default for every key.
10
10
  - [Code found by path](../reference/config.md#where-the-code-is): The config names jobs, hooks and providers, and Protobase finds their code by its path, such as `jobs/<name>.ts`.
11
11
  - [JSON config](../reference/config.md#the-same-config-as-json): The same config works as `protobase.config.json`, with values from the environment written as `$env`.
12
+ - [App options](../reference/config/app.md): The app's name, public URL, secret, language, time zone, install colours and mobile build, each with its type, default and environment variable.
13
+ - [Sign-in options](../reference/config/sign-in.md): Every key of `auth` and `authenticate`, from roles and organizations to sign-in providers and tokens of an auth server elsewhere.
14
+ - [API options](../reference/config/api.md): The REST API's path, keys, CORS, access defaults, query limits, error reporting, write hooks and MCP tools.
15
+ - [Admin app options](../reference/config/admin-app.md): The assistant, the maps and the plugins the admin app loads.
16
+ - [Jobs and events options](../reference/config/jobs-and-events.md): Each job's retries, timeout and schedule, and the settings of events, history, webhooks and notifications.
17
+ - [Files options](../reference/config/files.md): The file providers, retention, signing, the Storage API and the image library.
12
18
  - [Scaffold from a database](../reference/cli.md#scaffold): Reads your Postgres tables and writes the data config for them, with field types, keys, relations, enums, soft delete, tenants and search filled in, and with `--ui` a first view of each.
13
19
  - [Safe re-scaffolding](../reference/cli.md#re-running): Running scaffold again adds only the columns that are not declared yet and leaves your own config code as it is.
14
20
  - [Schema drift report](../reference/cli.md#drift-report): After each scaffold, lists declared fields whose column is gone, whose type changed or whose enum values differ, with a suggested fix.
@@ -36,7 +36,7 @@ For a Postgres database you already have, [Admin over an existing database](guid
36
36
 
37
37
  Every page of these docs is also Markdown at its address plus `.md`: `https://docs.protobase.net/reference/cli/` is also `https://docs.protobase.net/reference/cli.md`. The code a page shows from example files is written out in it, and its live demos are left out, so a coding agent or a chat assistant reads the page whole. In a project, [`protobase skill install`](reference/cli.md#skill) gives coding agents the docs of the installed version.
38
38
 
39
- The rest of this page works in a clone of this repository, on its examples.
39
+ The rest of this page works in a clone of this repository, on its example apps in `tests/apps`.
40
40
 
41
41
  ## Setup
42
42
 
@@ -48,33 +48,33 @@ bun install
48
48
 
49
49
  ## Run the ERP example
50
50
 
51
- `examples/erp` is a sample ERP on a real Postgres database, seeded with three years of history. It needs Docker for the database: `bun run db:up` starts the Postgres container and gives each example its database and a `.env` from its `.env.example`.
51
+ `tests/apps/erp` is a sample ERP on a real Postgres database, seeded with three years of history. It needs Docker for the database: `bun run db:up` starts the Postgres container and gives each example its database and a `.env` from its `.env.example`.
52
52
 
53
53
  ```sh
54
- bun run db:up && bun run --cwd examples/erp db:migrate && bun run --cwd examples/erp db:seed --scale small # the ERP's tables and Better Auth's
55
- bun run --cwd examples/erp protobase users create you@example.com --generate-password
56
- bun run --cwd examples/erp dev # http://localhost:5173
54
+ bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small # the ERP's tables and Better Auth's
55
+ bun run --cwd tests/apps/erp protobase users create you@example.com --generate-password
56
+ bun run --cwd tests/apps/erp dev # http://localhost:5173
57
57
  ```
58
58
 
59
- `PROTOBASE_SECRET` in `examples/erp/.env` signs the session cookies; see [Login with Better Auth](reference/auth.md). `protobase dev` serves the admin app and the API on one port and reloads both on every change ([CLI](reference/cli.md#dev)). Its startup message says how to sign in: while the database has no users, it prints the exact `users create` command for the first admin. It stops with a clear message when another server holds its port; pass `--port 5174` to run a second app beside it.
59
+ `PROTOBASE_SECRET` in `tests/apps/erp/.env` signs the session cookies; see [Login with Better Auth](reference/auth.md). `protobase dev` serves the admin app and the API on one port and reloads both on every change ([CLI](reference/cli.md#dev)). Its startup message says how to sign in: while the database has no users, it prints the exact `users create` command for the first admin. It stops with a clear message when another server holds its port; pass `--port 5174` to run a second app beside it.
60
60
 
61
61
  ## Run the real estate example
62
62
 
63
- `examples/real-estate` is a rental and property management firm: owners, properties and units, leases and tenants, monthly rent, payments and arrears, and maintenance. Its database sits beside the ERP's in the same Postgres container, and it keeps its own `.env`.
63
+ `tests/apps/real-estate` is a rental and property management firm: owners, properties and units, leases and tenants, monthly rent, payments and arrears, and maintenance. Its database sits beside the ERP's in the same Postgres container, and it keeps its own `.env`.
64
64
 
65
65
  ```sh
66
- bun run db:up && bun run --cwd examples/real-estate db:migrate && bun run --cwd examples/real-estate db:seed --scale small
67
- bun run --cwd examples/real-estate protobase users create you@example.com --role admin --generate-password
68
- bun run --cwd examples/real-estate dev # http://localhost:5173
66
+ bun run db:up && bun run --cwd tests/apps/real-estate db:migrate && bun run --cwd tests/apps/real-estate db:seed --scale small
67
+ bun run --cwd tests/apps/real-estate protobase users create you@example.com --role admin --generate-password
68
+ bun run --cwd tests/apps/real-estate dev # http://localhost:5173
69
69
  ```
70
70
 
71
71
  ## Run the property portal example
72
72
 
73
- `examples/property-portal` is a public portal of homes for sale and for rent in the Netherlands and Spain. Visitors browse and filter the listings without signing in, through the [anonymous role](reference/access.md#anonymous-access); members save searches of the listings that mail them new homes, and keep favorites and notes that only they see. The seed makes two members, `anna@portal.example` and `bram@portal.example`, and an admin, `admin@portal.example`, all with the password `property-portal-demo`.
73
+ `tests/apps/property-portal` is a public portal of homes for sale and for rent in the Netherlands and Spain. Visitors browse and filter the listings without signing in, through the [anonymous role](reference/access.md#anonymous-access); members save searches of the listings that mail them new homes, and keep favorites and notes that only they see. The seed makes two members, `anna@portal.example` and `bram@portal.example`, and an admin, `admin@portal.example`, all with the password `property-portal-demo`.
74
74
 
75
75
  ```sh
76
- bun run db:up && bun run --cwd examples/property-portal db:migrate && bun run --cwd examples/property-portal db:seed --scale small
77
- bun run --cwd examples/property-portal dev # http://localhost:5173
76
+ bun run db:up && bun run --cwd tests/apps/property-portal db:migrate && bun run --cwd tests/apps/property-portal db:seed --scale small
77
+ bun run --cwd tests/apps/property-portal dev # http://localhost:5173
78
78
  ```
79
79
 
80
80
  ## Commands
@@ -7,7 +7,7 @@ Ship a project as one bundle folder and run it with the serve runtime.
7
7
  A project ships as one bundle folder; the host runs protobase around it.
8
8
 
9
9
  ```sh
10
- bun run --cwd examples/erp protobase build # the bundle to ship: examples/erp/dist/
10
+ bun run --cwd tests/apps/erp protobase build # the bundle to ship: tests/apps/erp/dist/
11
11
  bun run build:serve # the runtime the host carries: dist/protobase-serve.js
12
12
  bun --no-install /opt/protobase/protobase-serve.js /app/protobase.config.js # on the host: the API
13
13
  ```
@@ -28,7 +28,7 @@ dist/
28
28
  plugins and the app's version
29
29
  ```
30
30
 
31
- The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins)), so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config.md#defaults)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The manifest's `protobase` is the version the project is pinned to, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
31
+ The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins)), so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config/app.md)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The manifest's `protobase` is the version the project is pinned to, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
32
32
 
33
33
  ## Migrations
34
34
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Let users save a list as an Excel or CSV file, limit how many rows a file holds, or take Export off a list.
6
6
 
7
- Every list in the admin can be saved as a file: Rijnland's finance team wants this month's invoices in Excel, and the warehouse wants a CSV of the stock moves for a supplier. Nothing needs setting up for that; this guide shows what users get, and how a view limits it or takes it away. It uses the ERP example (`examples/erp`).
7
+ Every list in the admin can be saved as a file: Rijnland's finance team wants this month's invoices in Excel, and the warehouse wants a CSV of the stock moves for a supplier. Nothing needs setting up for that; this guide shows what users get, and how a view limits it or takes it away. It uses the ERP example (`tests/apps/erp`).
8
8
 
9
9
  ## 1. Export a list
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Show and edit a field your own way everywhere the app shows it, with a field type a plugin registers and a view picks.
6
6
 
7
- An order's status is one of six values, and each order moves through them in turn: draft, confirmed, picking, shipped, delivered. The app shows it as a badge and edits it with a select. Rijnland's warehouse wants to see at a glance how far along an order is, and to move it with one click. That is a field type: a component that shows the value, one that edits it, and the storage types it works for. This guide adds one, `steps`, to the ERP example (`examples/erp`). [Field types](../reference/plugins.md#field-types) has the contract.
7
+ An order's status is one of six values, and each order moves through them in turn: draft, confirmed, picking, shipped, delivered. The app shows it as a badge and edits it with a select. Rijnland's warehouse wants to see at a glance how far along an order is, and to move it with one click. That is a field type: a component that shows the value, one that edits it, and the storage types it works for. This guide adds one, `steps`, to the ERP example (`tests/apps/erp`). [Field types](../reference/plugins.md#field-types) has the contract.
8
8
 
9
9
  ## 1. Show the value
10
10
 
@@ -224,7 +224,7 @@ A `CardRow` shows a few records side by side, and its children are the template
224
224
 
225
225
  There is no endpoint for "biggest unpaid delivery" and no component for "lead card". Every block reads the regular API with Sam's token, so the access rules apply exactly as on the lists. A sales rep with `orders.read.own` sees only their own orders in every count, table and card, and a field they may not read is not on their page at all (see [Access](../reference/layouts.md#access)).
226
226
 
227
- The ERP example carries this page, with a few more blocks, in `examples/erp/config/overview/page.tsx`. Next:
227
+ The ERP example carries this page, with a few more blocks, in `tests/apps/erp/config/overview/page.tsx`. Next:
228
228
 
229
229
  - [A billing page](billing-page.md) adds forms, delete and link actions, and a React component of your own.
230
230
  - [Blocks](../reference/blocks.md) lists every block and its props.
@@ -6,7 +6,7 @@ Build a plugin, serve it, load it into an app and change it without rebuilding t
6
6
 
7
7
  Sam's sales team wants the newest draft orders on their start page, each a link to the order. That is a few lines of React. Written in the app's `protobase.ui.tsx`, it would be that app's alone, shipped with each of its builds. Written as a [plugin](../reference/plugins.md) of its own, it is built once, served on its own, and loaded by every app that lists it when it starts, whatever release the app runs.
8
8
 
9
- This guide builds that plugin, serves it, loads it into an app and changes it without touching the app. It uses the orders of the ERP example (`examples/erp`); any resource of yours works the same.
9
+ This guide builds that plugin, serves it, loads it into an app and changes it without touching the app. It uses the orders of the ERP example (`tests/apps/erp`); any resource of yours works the same.
10
10
 
11
11
  ## 1. A folder for the plugin
12
12
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Bring a spreadsheet of companies into the admin app with the list's Import, update them from another, and turn Import off where it does not belong.
6
6
 
7
- Rijnland's sales team keeps a spreadsheet of companies they met at a trade fair, and wants them in the ERP example (`examples/erp`) without typing each one. Every list offers **Import** to a user who may create its records, so there is nothing to build: this guide walks through an import, an update from a second file, and turning Import off. The [reference](../reference/ui-config.md#importing-records) has every rule.
7
+ Rijnland's sales team keeps a spreadsheet of companies they met at a trade fair, and wants them in the ERP example (`tests/apps/erp`) without typing each one. Every list offers **Import** to a user who may create its records, so there is nothing to build: this guide walks through an import, an update from a second file, and turning Import off. The [reference](../reference/ui-config.md#importing-records) has every rule.
8
8
 
9
9
  ## 1. Import new records
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  A choice each person makes for themselves, such as which emails they get, in a tab of the account page, from a table, a resource and roles, with no UI code.
6
6
 
7
- Rijnland's accountants want an email for each invoice that passes its due date; the warehouse would rather get none. That is a choice each person makes for themselves, so it belongs on their [account page](../reference/auth.md#account-page), and the fields the page shows come from a resource like any other. This guide adds it to the ERP example (`examples/erp`) in four steps: a table, a resource, roles and a tab.
7
+ Rijnland's accountants want an email for each invoice that passes its due date; the warehouse would rather get none. That is a choice each person makes for themselves, so it belongs on their [account page](../reference/auth.md#account-page), and the fields the page shows come from a resource like any other. This guide adds it to the ERP example (`tests/apps/erp`) in four steps: a table, a resource, roles and a tab.
8
8
 
9
9
  ## 1. A table with one row per person
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Turn notifications on, send one when a record changes, and see it in the bell and as push on the user's browser.
6
6
 
7
- You turn notifications on, send one when something happens in your app, and see it in the bell and as push on your browser. This guide uses the ERP example (`examples/erp`, set up as its README says, with a user from `protobase users create`): when an order's status changes, its owner hears about it. The [Notifications reference](../reference/notifications.md) has every option.
7
+ You turn notifications on, send one when something happens in your app, and see it in the bell and as push on your browser. This guide uses the ERP example (`tests/apps/erp`, set up as its README says, with a user from `protobase users create`): when an order's status changes, its owner hears about it. The [Notifications reference](../reference/notifications.md) has every option.
8
8
 
9
9
  ## 1. Turn notifications on
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  Draw each card of a cards display with a component of your own, and keep the built-in card as its fallback.
6
6
 
7
- A list can show its records as [cards](../reference/ui-config.md#list-displays) beside its table: a title, a subtitle, a badge and a few small fields. Rijnland's sales team wants order cards that lead with the total and the customer, the way they talk about orders. That is a card component: the list page still loads the orders, filters, sorts and links each card to its order; the component only draws what is inside a card. This guide adds one to the ERP example (`examples/erp`).
7
+ A list can show its records as [cards](../reference/ui-config.md#list-displays) beside its table: a title, a subtitle, a badge and a few small fields. Rijnland's sales team wants order cards that lead with the total and the customer, the way they talk about orders. That is a card component: the list page still loads the orders, filters, sorts and links each card to its order; the component only draws what is inside a card. This guide adds one to the ERP example (`tests/apps/erp`).
8
8
 
9
9
  ## 1. The card
10
10
 
@@ -10,7 +10,7 @@ This guide makes the desk's tickets a [remote resource](../reference/remote-reso
10
10
 
11
11
  ## 1. Two apps
12
12
 
13
- You need two Protobase projects, each with its own database, its own [admin store](../reference/auth.md#admin-store) and a user: the from-scratch preset (`examples/scratch` in the repository) is enough for both. Each runs on its own origin; this guide runs them side by side on one machine:
13
+ You need two Protobase projects, each with its own database, its own [admin store](../reference/auth.md#admin-store) and a user: the from-scratch preset (`tests/apps/scratch` in the repository) is enough for both. Each runs on its own origin; this guide runs them side by side on one machine:
14
14
 
15
15
  | | `PROTOBASE_URL` in its `.env` | Started with |
16
16
  | --- | --- | --- |
@@ -4,7 +4,7 @@
4
4
 
5
5
  Give an app its own colors, corners and font with protobase.theme.css, in light and dark, and keep them through every release.
6
6
 
7
- Rijnland Industrial Supply wants its admin in its own colors: teal instead of blue, rounder corners and its own font. That is one file of values, `protobase.theme.css`, which the app reads on every page, the sign-in page included. This guide writes it for the ERP example (`examples/erp`); any project works the same. [Theme](../reference/theme.md) has every token.
7
+ Rijnland Industrial Supply wants its admin in its own colors: teal instead of blue, rounder corners and its own font. That is one file of values, `protobase.theme.css`, which the app reads on every page, the sign-in page included. This guide writes it for the ERP example (`tests/apps/erp`); any project works the same. [Theme](../reference/theme.md) has every token.
8
8
 
9
9
  ## 1. The light values
10
10
 
@@ -23,7 +23,7 @@ const admin = createAdmin({
23
23
  })
24
24
  ```
25
25
 
26
- Run the ERP example with `bun run --cwd examples/erp serve` (port 8787, Better Auth login, organization 1 as tenant; `REQUEST_LOG=true` logs requests). Interactive reference: `/api/docs`; like `/api/openapi.json` it needs a bearer token, because the document lists what the caller may see and do. Every route answers `401` without a valid token; get one with `protobase token you@example.com`. A project whose roles define [`anonymous`](access.md#anonymous-access) serves the resources API to requests without a token as that role.
26
+ Run the ERP example with `bun run --cwd tests/apps/erp serve` (port 8787, Better Auth login, organization 1 as tenant; `REQUEST_LOG=true` logs requests). Interactive reference: `/api/docs`; like `/api/openapi.json` it needs a bearer token, because the document lists what the caller may see and do. Every route answers `401` without a valid token; get one with `protobase token you@example.com`. A project whose roles define [`anonymous`](access.md#anonymous-access) serves the resources API to requests without a token as that role.
27
27
 
28
28
  ## Routes
29
29
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  How the packages are laid out, which package may import which, and where tests and stories live.
6
6
 
7
- A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name>`, all released together at one version. `examples/*` are workspace members that consume the packages; `website` is this documentation site (Astro with Starlight), also a workspace member. The workspace root is private and is not published.
7
+ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name>`, all released together at one version. `tests/apps/*`, the example apps the tests run on and the presets are written from, are workspace members that consume the packages; `website` is this documentation site (Astro with Starlight), also a workspace member. The workspace root is private and is not published.
8
8
 
9
9
  ## Packages
10
10
 
@@ -18,9 +18,9 @@ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name
18
18
  | `@protobase/server` | `packages/server` | `@protobase/server` | server | `schema`, `layout`, `query` |
19
19
  | `@protobase/cli` | `packages/cli` | the `protobase` command (`bin/protobase.mjs`) | Node and Bun | `schema`, `layout`, `query`, `server`, `ui` |
20
20
  | `@protobase/presets` | `packages/presets` | none: private, `bun run presets:write` writes a project per preset | Bun | none; each preset depends on the `@protobase` packages of the major it is written at, locked at that version |
21
- | `examples/*` | | none | any | `@protobase/*` entry points only |
21
+ | `tests/apps/*` | | none | any | `@protobase/*` entry points only |
22
22
 
23
- The presets are written from `examples/erp`, `examples/real-estate` and `examples/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
23
+ The presets are written from `tests/apps/erp`, `tests/apps/real-estate` and `tests/apps/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
24
24
 
25
25
  The JSX runtime belongs to `@protobase/layout` because a layout file names one package in `@jsxImportSource @protobase/layout`, and TypeScript and Vite look up `jsx-runtime` and `jsx-dev-runtime` under it. Each field type is split along the same lines: its Zod builder is `packages/schema/src/fields/<type>.ts` and its SQL parameter conversion `packages/query/src/fields/<type>.ts`.
26
26
 
@@ -37,7 +37,7 @@ In this repository, entry points export TypeScript source directly and the CLI r
37
37
  ## Tests and stories
38
38
 
39
39
  - Unit tests: `*.test.ts` next to the code, run by Vitest in a node environment.
40
- - Tests that use a database, a subprocess or the network: `packages/<name>/tests/`, mirroring the source path, and the examples' in `tests/examples/`. Most database tests are snapshot tests, which replay SQL recorded from Postgres (`<test>.sql.json`); the fixtures, the recording and replay, and the setup they share are in `test-support/` at the root.
40
+ - Tests that use a database, a subprocess or the network: `packages/<name>/tests/`, mirroring the source path, and the example apps' in `tests/examples/`. Most database tests are snapshot tests, which replay SQL recorded from Postgres (`<test>.sql.json`); the fixtures, the recording and replay, and the setup they share are in `test-support/` at the root.
41
41
  - Stories: `*.stories.tsx` next to the component in `packages/ui/src`; Storybook config lives in `.storybook/`.
42
42
  - Packing leaves tests, stories and their fixtures out of a package (`files` in its `package.json`).
43
43
 
@@ -70,6 +70,7 @@ The store's migrations make the user table only when it is missing, and add each
70
70
  | Variable | |
71
71
  | --- | --- |
72
72
  | `PROTOBASE_SECRET` | the app's secret, the default of `secret`: signs cookies and encrypts the token keys; `openssl rand -base64 32`; never committed (`.env.example` has a placeholder) |
73
+ | `PROTOBASE_PREVIOUS_SECRETS` | the app's secrets before `PROTOBASE_SECRET`, newest first, comma separated, the default of `previousSecrets`; see [Changing the secret](#changing-the-secret) |
73
74
  | `PROTOBASE_URL` | the app's public URL, the default of `url` (in `protobase dev`, the dev server's own); issuer and audience of the tokens; when tunnelling, the https tunnel URL |
74
75
  | `PROTOBASE_TRUSTED_ORIGINS` | extra comma separated origins, the default of `auth.trustedOrigins`; a dev tunnel needs its exact host here, such as `https://my-tunnel.trycloudflare.com`, since no wildcard is trusted |
75
76
  | `PROTOBASE_ORIGINS` | the other origins the app is served on, comma separated, passed by the platform; see [Several origins](#several-origins) |
@@ -581,7 +582,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
581
582
 
582
583
  **Deleting** an organization (Better Auth's `delete`, owners only) is refused with `409 ORGANIZATION_HAS_RECORDS` while a `.tenant` resource has rows in it; `deleteRecords: 'cascade'` leaves it to the project's foreign keys. The `beforeOrganizationDeleted` [hook](#hooks) may refuse too.
583
584
 
584
- **Ids.** The `generateOrganizationId` [hook](#hooks) makes a new organization's id, by default a UUID; `.tenant` columns hold it, so `text` or `uuid`. An app whose tenant columns are integers takes the next value of its own organizations sequence instead, and adds its own row in `onOrganizationCreated`, as the ERP example does (`examples/erp/auth/hooks.ts`). An app that ran as one organization keeps its tenant value: `protobase organizations create "Acme" --owner you@example.com --id 1 --members all` makes that organization, with every user in it: superusers as owners, everyone else as a member, their global roles moved onto the membership.
585
+ **Ids.** The `generateOrganizationId` [hook](#hooks) makes a new organization's id, by default a UUID; `.tenant` columns hold it, so `text` or `uuid`. An app whose tenant columns are integers takes the next value of its own organizations sequence instead, and adds its own row in `onOrganizationCreated`, as the ERP example does (`tests/apps/erp/auth/hooks.ts`). An app that ran as one organization keeps its tenant value: `protobase organizations create "Acme" --owner you@example.com --id 1 --members all` makes that organization, with every user in it: superusers as owners, everyone else as a member, their global roles moved onto the membership.
585
586
 
586
587
  The app's own pages are under the profile menu: the switcher, "Manage organizations" (theirs, a new one, and for global roles any one), "Organization" (details, leaving, handing over, deleting), and for owners and admins "Members" and "Invitations". The client has them as `session.organizations` (`list`, `current`, `switchTo`, `members`, `invite`, ...).
587
588
 
@@ -609,6 +610,32 @@ A refused token is a `401`, as an expired one is, and the client retries the req
609
610
 
610
611
  The cost is two or three lookups by key in the auth store per request: the session by `sid`, the user by `sub`, and with organizations the membership. Nothing is cached, so every server process sees a change at once. An open `/live` stream was admitted when it connected and keeps running until it closes. With `authenticate.jwksUrl` instead of sign-in of its own, the API cannot read the auth store and a token works until it expires, as do tokens of [other apps](#users-of-another-app).
611
612
 
613
+ ### Signing keys
614
+
615
+ The app makes the keys that sign its tokens itself, and keeps them in the auth store, the private half encrypted with the app's `secret`. Every instance of the app signs with the same keys, since they share the database, and nobody supplies one.
616
+
617
+ The keys rotate. A key signs for 30 days (`signingKeyDays`); the first token after that makes a new key, which signs from then on. The replaced key stays in `/api/auth/jwks` for 7 more days (`signingKeyGraceDays`, at least 1), so the tokens it signed keep verifying until they expire, and is then deleted. A month bounds how long a leaked key could sign, and keeps the key set to a few keys. A week is far longer than any token lasts (a day at most, from [`protobase token`](#tokens-for-scripts-and-curl)), so an API that caches the key set, such as another app reading `/api/auth/jwks`, never refuses a token signed just before a rotation. The ES256 key of the [Supabase-compatible tokens](#supabase-js-and-supabasessr) rotates the same way. A key made by a version before rotation expires 30 days after it was made, or at once when it is older.
618
+
619
+ ```ts
620
+ export default defineConfig({ signingKeyDays: 90, signingKeyGraceDays: 14 })
621
+ ```
622
+
623
+ #### Changing the secret
624
+
625
+ The secret encrypts the signing keys, so with a new `secret` alone the app cannot read them, and making a token fails with `Failed to decrypt private key`. List the old secret in `previousSecrets`, newest first, or in `PROTOBASE_PREVIOUS_SECRETS`, comma separated:
626
+
627
+ ```sh
628
+ PROTOBASE_SECRET=<the new secret>
629
+ PROTOBASE_PREVIOUS_SECRETS=<the old secret>
630
+ ```
631
+
632
+ The app then encrypts with the new secret and still decrypts what an old one encrypted, so it keeps signing with the same key, and the tokens in flight keep verifying. Keep an old secret listed:
633
+
634
+ - until the keys it encrypted have rotated out, `signingKeyDays` after the change: the next keys are encrypted with the new secret;
635
+ - while people use the [authenticator apps](#two-factor-authentication) they set up before the change, whose secrets it encrypted too, and, with `encryptOAuthTokens`, while the tokens it encrypted for social sign-ins are needed.
636
+
637
+ What the old secret signed stops working: session cookies, so everyone signs in again, and links already sent, such as invitations and download links. Give every instance the same secrets: an instance that knows only the old secret cannot read a key made with the new one.
638
+
612
639
  ## Users of another app
613
640
 
614
641
  An API can admit the signed-in users of another Protobase app with the tokens that app issues, so that app's admin app can draw its resources as [remote resources](remote-resources.md). `authenticate.apps` lists each such app by its `url`, the issuer of its tokens, with the roles its users' global roles become here:
@@ -697,4 +724,4 @@ Only the Better Auth routes under `/api/auth/*` (sign-in, password reset, [open
697
724
 
698
725
  Roles are bundles of capabilities (`defineRoles` in `@protobase/schema`: `orders.read.own`, `costs.read`, `*.read`, ...). Export the result as `roles` from `config/roles.ts`, where Protobase finds it, and every operation without an explicit rule needs the matching capability; a capability may be limited to [fields and rows](access.md#capabilities). The token's `roles` become `ctx.user.roles` in rules; the user id (`sub`) is what `.own` compares with the resource's `.owner(...)` field, so it must be the id that field stores. How the API enforces them (hidden fields, row filters, record permissions) is in [the REST API reference](api.md#access).
699
726
 
700
- **User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`examples/erp/auth/hooks.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs sets `auth: { generateUserId: 'uuid' }` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as one in `auth/authenticate.ts` that returns the id of a row in its users table, declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
727
+ **User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`tests/apps/erp/auth/hooks.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs sets `auth: { generateUserId: 'uuid' }` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as one in `auth/authenticate.ts` that returns the id of a row in its users table, declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
@@ -6,7 +6,7 @@ Every built-in layout block, its props and what it does, with examples from the
6
6
 
7
7
  Blocks are imported from `@protobase/layout`. "Record" below means the record of the `RecordCard` or `CardRow` card around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort` AIP-132, as in the list API. Every block below but `RecordRow`, which the property portal's home uses, `RecordCards`, `Tabs` and `Tab`, `Settings`, and `Users`, which the [Users page](auth.md#users-page) uses, appears in the ERP example's sales overview:
8
8
 
9
- ```tsx title="examples/erp/config/overview/page.tsx"
9
+ ```tsx title="tests/apps/erp/config/overview/page.tsx"
10
10
  /** @jsxImportSource @protobase/layout */
11
11
  import { Action, Card, CardRow, Chart, Field, Grid, ModalForm, Page, RecordCard, Show, Stat, Table, component, page } from '@protobase/layout'
12
12
 
@@ -9,7 +9,7 @@ On phones the sidebar is a drawer behind the top bar's menu button. For people w
9
9
  Export a [`bottomBar(...)`](https://docs.protobase.net/api/schema/functions/bottombar/) from the config module for each group of roles that gets one:
10
10
 
11
11
  ```ts
12
- // examples/erp/config/bottom-bar.ts, re-exported from config/index.ts
12
+ // tests/apps/erp/config/bottom-bar.ts, re-exported from config/index.ts
13
13
  import { bottomBar } from '@protobase/schema'
14
14
 
15
15
  export const warehouseBar = bottomBar({ label: 'Warehouse', roles: ['warehouse'] }, (m) => [
@@ -9,7 +9,7 @@ The `protobase` command comes with `@protobase/cli`. Install it in a project nex
9
9
  ```sh
10
10
  bun add @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui
11
11
  bun run protobase <command> # from the project, config folder defaults to ./config
12
- bun run --cwd examples/erp protobase <command> # in this repository, for an example
12
+ bun run --cwd tests/apps/erp protobase <command> # in this repository, for an example
13
13
  ```
14
14
 
15
15
  Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does. `protobase --version` (or `-v`) prints the Protobase version. Before any command runs, the CLI checks that the project in the current directory, by the `@protobase` packages installed there, is of its own major version, and stops with an error naming both versions when it is not: within a major a CLI runs every project, whatever its minor. That is the CLI's one version check. Outside a project, or before its install, there is nothing to check.
@@ -120,7 +120,7 @@ Exit code is 1 when there are errors. Run it after the project's migrations and
120
120
  ## `dev`
121
121
 
122
122
  ```sh
123
- protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd examples/erp dev
123
+ protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd tests/apps/erp dev
124
124
  ```
125
125
 
126
126
  One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and hands `/api`, supabase-js's `/api/sb` included, to the Hono app from `createAdmin`, which runs in a process of its own; the CLI's process never loads `@protobase/server`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
@@ -148,7 +148,7 @@ One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/a
148
148
  ## `build`
149
149
 
150
150
  ```sh
151
- protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd examples/erp protobase build
151
+ protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd tests/apps/erp protobase build
152
152
  ```
153
153
 
154
154
  Writes the project's deploy bundle, the folder a deployment ships:
@@ -342,7 +342,7 @@ bun --no-install protobase-serve.js create-admin <bundle> <email> # --generat
342
342
  ```sh
343
343
  bun --no-install protobase-serve.js <bundle>/protobase.config.js # production, under Bun: the API
344
344
  protobase serve <bundle>/protobase.config.js # the same, with the CLI on Node or Bun
345
- protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd examples/erp serve
345
+ protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd tests/apps/erp serve
346
346
  ```
347
347
 
348
348
  Serves the API of a bundle from `protobase build` and owns the process around it. Given the bundle folder, `protobase serve` also serves its UI by [the manifest's rules](#the-manifest), so a bundle can be checked locally exactly as the host will serve it.
@@ -357,7 +357,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
357
357
  | `REQUEST_LOG` | `true` logs every request; default `false` |
358
358
  | `PROTOBASE_SMTP_URL` | the SMTP server for password-reset mail, emailed sign-in and two-factor codes and the app's own [email](email.md), credential included: `smtp://user:password@host:587` (STARTTLS when offered) or `smtps://...:465`; without it they are off ([Password reset](auth.md#password-reset), [Emailed sign-in codes](auth.md#emailed-sign-in-codes)) |
359
359
  | `PROTOBASE_MAIL_FROM` | the sender of that mail, a plain address such as `noreply@admin.example.com`; set with `PROTOBASE_SMTP_URL` or not at all |
360
- | `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config.md#keys) |
360
+ | `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config/app.md#name) |
361
361
  | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME` are optional ([Platform sign-in provider](auth.md#platform-sign-in-provider)) |
362
362
  | `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the OpenID Connect provider of the operator's staff, for [staff sign-in](auth.md#staff-sign-in) as people of the app; all three or none. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional ([Operator provider](auth.md#operator-provider)) |
363
363
  | `PROTOBASE_ORIGINS`, `PROTOBASE_PASSKEY_DOMAIN` | the other origins the app is served on, comma separated, and the host new passkeys are made for ([Several origins](auth.md#several-origins)) |
@@ -377,7 +377,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
377
377
  | `PROTOBASE_MOBILE_SIGNING_KEY` | an RSA private key of at least 2048 bits, PEM, its newlines real or written `\n`, that signs every file of the [mobile release](#mobile-releases) in `X-Signature`, for an app whose updater checks signatures with the matching public key; another kind of key, or a shorter one, stops startup |
378
378
  | `PROTOBASE_JOBS_DRAIN_TOKEN` | the operator's bearer token for `POST /api/jobs/drain`, which [runs the due jobs](jobs.md#hosts-that-sleep) of a host that lets the app sleep; without it there is no such endpoint |
379
379
 
380
- The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [Defaults](config.md#defaults)); its other settings are the project's own variables, read by its config, which the runtime reads again at start with the host's environment. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
380
+ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [App options](config/app.md)); its other settings are the project's own variables, read by its config, which the runtime reads again at start with the host's environment. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
381
381
 
382
382
  - **Routes:** `createAdmin` (`/api/v1`, `/api/meta`, `/api/functions/*`, `/api/auth/*`, ...) and `GET /health`, which answers `{"status":"ok"}` without a token and without touching the database. The runtime never serves the UI; `protobase serve <bundle>` serves `public/` for every path outside the manifest's `api` and `/.well-known/webauthn`, after `/health`, with `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, so no other site frames its pages.
383
383
  - **Plugins:** the runtime reads the manifest's `plugins`: `/api/meta` names them, and a view that shows a field with one of their [field types](plugins.md#field-types) that does not show the field's storage type stops startup, naming the view, the field and what the field type shows.
@@ -561,10 +561,10 @@ Copies the agent skills of this CLI's version into the current project, or only
561
561
  ## ERP example
562
562
 
563
563
  ```sh
564
- bun run db:up && bun run --cwd examples/erp db:migrate && bun run --cwd examples/erp db:seed --scale small
565
- bun run --cwd examples/erp protobase scaffold postgres://protobase:protobase@localhost:55432/protobase \
564
+ bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small
565
+ bun run --cwd tests/apps/erp protobase scaffold postgres://protobase:protobase@localhost:55432/protobase \
566
566
  --yes --ui --exclude auth --exclude public.schema_migrations --exclude public.seed_info
567
- bun run --cwd examples/erp protobase doctor postgres://protobase:protobase@localhost:55432/protobase
567
+ bun run --cwd tests/apps/erp protobase doctor postgres://protobase:protobase@localhost:55432/protobase
568
568
  ```
569
569
 
570
570
  Always pass `--exclude auth`: the ERP keeps Better Auth's users, sessions and signing keys in the `auth` schema of the same database, and scaffolding them would expose credentials through the admin API.
@@ -23,7 +23,7 @@ With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/
23
23
 
24
24
  ## The admin app
25
25
 
26
- `<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `examples/*/config/*/ui.ts`. The sidebar's recent-record groups and the user menu are configured there too: see [Sidebar](sidebar.md), [User menu](user-menu.md) and [Bottom bar](bottom-bar.md).
26
+ `<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `tests/apps/*/config/*/ui.ts`. The sidebar's recent-record groups and the user menu are configured there too: see [Sidebar](sidebar.md), [User menu](user-menu.md) and [Bottom bar](bottom-bar.md).
27
27
 
28
28
  ## Global search
29
29
 
@@ -35,4 +35,4 @@ Each result is a link: a click or Enter opens it and closes the list, Enter the
35
35
 
36
36
  ## Live stories
37
37
 
38
- `bun run db:up && bun run --cwd examples/erp serve`, then `bun run storybook`. Storybook proxies `/api` to `PROTOBASE_API` (default `http://localhost:8787`); pick another API in the toolbar. Without a server the stories say so. `bun run screenshots:live` writes `screenshots/live/`.
38
+ `bun run db:up && bun run --cwd tests/apps/erp serve`, then `bun run storybook`. Storybook proxies `/api` to `PROTOBASE_API` (default `http://localhost:8787`); pick another API in the toolbar. Without a server the stories say so. `bun run screenshots:live` writes `screenshots/live/`.