@protobase/cli 0.48.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 (111) hide show
  1. package/dist/build/config-bundle.js +6 -1
  2. package/dist/build/entry-code.js +30 -17
  3. package/dist/cli/package.js +1 -1
  4. package/dist/config/build-project.js +73 -0
  5. package/dist/config/called-config.js +11 -0
  6. package/dist/config/config-defaults.js +33 -0
  7. package/dist/config/env-values.js +20 -0
  8. package/dist/config/lazy-imports.js +18 -0
  9. package/dist/config/merge-config.js +72 -0
  10. package/dist/config/project-files.js +48 -0
  11. package/dist/config/project-parts.js +201 -0
  12. package/dist/config/read-config.js +31 -0
  13. package/dist/config/source-config.js +37 -0
  14. package/dist/dev/create-db.js +2 -2
  15. package/dist/dev/entry.js +9 -10
  16. package/dist/dev/project.js +23 -47
  17. package/dist/main.js +3 -3
  18. package/dist/migration/load-project.js +34 -34
  19. package/dist/migration/parts.js +2 -2
  20. package/dist/migration/summary.js +2 -2
  21. package/dist/mobile/api-origin.js +4 -4
  22. package/dist/mobile/load-project.js +13 -12
  23. package/dist/mobile/register.js +1 -1
  24. package/dist/mobile/run.js +1 -1
  25. package/dist/organizations/register.js +1 -1
  26. package/dist/project/error-reporter.js +3 -3
  27. package/dist/project/import-project-file.js +4 -2
  28. package/dist/project/load-bundle-project.js +16 -25
  29. package/dist/project/load-data-config.js +1 -1
  30. package/dist/project/pg-db.js +10 -4
  31. package/dist/project/placeholder-secret.js +2 -2
  32. package/dist/project/project-admin.js +12 -11
  33. package/dist/serve/create-admin.js +9 -4
  34. package/dist/serve/host-module-ids.js +1 -0
  35. package/dist/serve/host-modules.js +3 -1
  36. package/dist/serve/lifecycle.js +17 -13
  37. package/dist/serve/load-bundle.js +41 -11
  38. package/dist/serve/mobile-release.js +1 -1
  39. package/dist/serve/serve-bundle.js +3 -3
  40. package/dist/supabase/auth-config.js +33 -28
  41. package/dist/supabase/config-jobs.js +28 -27
  42. package/dist/supabase/config-object.js +25 -0
  43. package/dist/supabase/cron-job-file.js +13 -14
  44. package/dist/supabase/cron-jobs-write.js +6 -12
  45. package/dist/supabase/cron-plan.js +3 -51
  46. package/dist/supabase/project-files.js +4 -9
  47. package/dist/supabase/report.js +3 -3
  48. package/dist/users/load-auth.js +16 -15
  49. package/dist/worker/start-worker.js +18 -15
  50. package/package.json +8 -6
  51. package/skills/protobase/SKILL.md +8 -1
  52. package/skills/protobase/references/features/notifications.md +1 -1
  53. package/skills/protobase/references/features/sign-in-and-accounts.md +2 -0
  54. package/skills/protobase/references/features/start-a-project.md +9 -0
  55. package/skills/protobase/references/getting-started.md +14 -14
  56. package/skills/protobase/references/guides/api-functions.md +4 -4
  57. package/skills/protobase/references/guides/deploy.md +8 -8
  58. package/skills/protobase/references/guides/existing-database.md +11 -31
  59. package/skills/protobase/references/guides/export-a-list.md +1 -1
  60. package/skills/protobase/references/guides/field-type.md +1 -1
  61. package/skills/protobase/references/guides/first-composed-page.md +1 -1
  62. package/skills/protobase/references/guides/first-plugin.md +2 -2
  63. package/skills/protobase/references/guides/import-records.md +1 -1
  64. package/skills/protobase/references/guides/mobile-app.md +5 -3
  65. package/skills/protobase/references/guides/personal-setting.md +1 -1
  66. package/skills/protobase/references/guides/plugin-build.md +1 -1
  67. package/skills/protobase/references/guides/push-notifications.md +7 -8
  68. package/skills/protobase/references/guides/record-card.md +1 -1
  69. package/skills/protobase/references/guides/remote-resources.md +23 -32
  70. package/skills/protobase/references/guides/theme-an-app.md +1 -1
  71. package/skills/protobase/references/reference/access.md +3 -3
  72. package/skills/protobase/references/reference/ai.md +1 -9
  73. package/skills/protobase/references/reference/api.md +16 -16
  74. package/skills/protobase/references/reference/app-identity.md +9 -10
  75. package/skills/protobase/references/reference/architecture.md +4 -4
  76. package/skills/protobase/references/reference/assistant.md +6 -6
  77. package/skills/protobase/references/reference/auth.md +139 -86
  78. package/skills/protobase/references/reference/blocks.md +1 -1
  79. package/skills/protobase/references/reference/bottom-bar.md +2 -2
  80. package/skills/protobase/references/reference/cli.md +42 -92
  81. package/skills/protobase/references/reference/client.md +2 -2
  82. package/skills/protobase/references/reference/comments.md +0 -8
  83. package/skills/protobase/references/reference/config/admin-app.md +62 -0
  84. package/skills/protobase/references/reference/config/api.md +164 -0
  85. package/skills/protobase/references/reference/config/app.md +112 -0
  86. package/skills/protobase/references/reference/config/files.md +99 -0
  87. package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
  88. package/skills/protobase/references/reference/config/sign-in.md +396 -0
  89. package/skills/protobase/references/reference/config.md +170 -0
  90. package/skills/protobase/references/reference/custom-components.md +2 -2
  91. package/skills/protobase/references/reference/data-config.md +4 -4
  92. package/skills/protobase/references/reference/email.md +36 -37
  93. package/skills/protobase/references/reference/events.md +1 -1
  94. package/skills/protobase/references/reference/files.md +18 -23
  95. package/skills/protobase/references/reference/forms.md +5 -17
  96. package/skills/protobase/references/reference/history.md +2 -3
  97. package/skills/protobase/references/reference/installable-app.md +1 -1
  98. package/skills/protobase/references/reference/jobs.md +53 -56
  99. package/skills/protobase/references/reference/languages.md +4 -2
  100. package/skills/protobase/references/reference/mcp.md +10 -10
  101. package/skills/protobase/references/reference/notifications.md +26 -24
  102. package/skills/protobase/references/reference/plugins.md +11 -14
  103. package/skills/protobase/references/reference/remote-resources.md +18 -24
  104. package/skills/protobase/references/reference/sidebar.md +2 -2
  105. package/skills/protobase/references/reference/supabase-realtime.md +1 -1
  106. package/skills/protobase/references/reference/supabase-rest.md +1 -1
  107. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  108. package/skills/protobase/references/reference/ui-config.md +20 -22
  109. package/skills/protobase/references/reference/user-menu.md +1 -1
  110. package/skills/protobase/references/reference/versioning.md +1 -1
  111. package/skills/protobase/references/reference/webhooks.md +6 -7
@@ -1,11 +1,12 @@
1
1
  import { projectAdmin } from "../project/project-admin.js";
2
- import { createPgDb } from "../project/pg-db.js";
2
+ import { buildProject } from "../config/build-project.js";
3
+ import { openAppDatabase } from "../project/pg-db.js";
3
4
  import { readManifest } from "../bundle/manifest.js";
4
5
  import { checkBundleManifest } from "../serve/bundle-manifest.js";
5
6
  import { loadBundle } from "../serve/load-bundle.js";
6
7
  import { statSync } from "node:fs";
7
8
  import path from "node:path";
8
- import { checkJobsSchema, configExports, isCaptured, jobDefinitions, startJobs } from "@protobase/server";
9
+ import { checkJobsSchema, configExports, isCaptured, startJobs } from "@protobase/server";
9
10
  import pg from "pg";
10
11
  //#region src/worker/start-worker.ts
11
12
  const bundleConfigFile = async (bundle) => {
@@ -14,19 +15,21 @@ const bundleConfigFile = async (bundle) => {
14
15
  };
15
16
  /**
16
17
  * Runs the project's jobs, and nothing else, until `stop`: the same handlers `protobase serve` runs, in a process of
17
- * their own. It reads the jobs schema at start and refuses one that is missing or behind, like `serve`.
18
+ * their own, built from the config the same way. It reads the jobs schema at start and refuses one that is missing or
19
+ * behind, like `serve`.
18
20
  */
19
- const startWorker = async ({ project, databaseUrl, createDb = (url) => createPgDb(pg, url) }) => {
20
- const builtIn = configExports(project.config).resources.some((resource) => {
21
- const model = resource.toModel();
22
- return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
23
- });
24
- if (jobDefinitions(project.jobs ?? {}).length === 0 && !builtIn) throw new Error("The bundle has no jobs: export them from protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
25
- if (!project.db && !databaseUrl) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
26
- const ownDb = project.db ? void 0 : createDb(databaseUrl);
27
- const db = project.db ?? ownDb;
21
+ const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatabase(pg, url) }) => {
22
+ if (!databaseUrl) throw new Error("No database: set DATABASE_URL");
23
+ const database = openDb(databaseUrl);
24
+ const { db } = database;
28
25
  const start = async () => {
29
- const { jobs: definitions } = projectAdmin(project, project.config, db);
26
+ const project = await buildProject(config, database);
27
+ const builtIn = configExports(project.config).resources.some((resource) => {
28
+ const model = resource.toModel();
29
+ return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
30
+ });
31
+ if (project.jobs.length === 0 && !builtIn) throw new Error("The bundle has no jobs: name their module in protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
32
+ const { jobs: definitions } = projectAdmin(project, db);
30
33
  await checkJobsSchema(db);
31
34
  return {
32
35
  definitions,
@@ -38,14 +41,14 @@ const startWorker = async ({ project, databaseUrl, createDb = (url) => createPgD
38
41
  };
39
42
  };
40
43
  const { definitions, runtime: jobs } = await start().catch(async (error) => {
41
- await ownDb?.destroy();
44
+ await db.destroy();
42
45
  throw error;
43
46
  });
44
47
  return {
45
48
  jobs: definitions.length,
46
49
  stop: async () => {
47
50
  await jobs.stop();
48
- await ownDb?.destroy();
51
+ await db.destroy();
49
52
  }
50
53
  };
51
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.48.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,11 +39,12 @@
39
39
  "dependencies": {
40
40
  "@better-auth/core": "^1.7.12",
41
41
  "@hono/node-server": "^2.1.3",
42
- "@protobase/layout": "0.48.0",
43
- "@protobase/query": "0.48.0",
44
- "@protobase/schema": "0.48.0",
45
- "@protobase/server": "0.48.0",
46
- "@protobase/ui": "0.48.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",
47
48
  "@react-email/render": "^2.1.0",
48
49
  "@scalar/hono-api-reference": "^0.12.10",
49
50
  "@tailwindcss/vite": "^4.3.3",
@@ -60,6 +61,7 @@
60
61
  "postcss": "^8.5.29",
61
62
  "postgres": "^3.4.9",
62
63
  "react": "^19.3.0",
64
+ "rolldown": "~1.2.11",
63
65
  "semver": "^7.8.5",
64
66
  "ts-morph": "^28.0.0",
65
67
  "vite": "^8.3.3",
@@ -5,7 +5,7 @@ description: Build, check and ship a Protobase admin app on Postgres (data.ts, u
5
5
 
6
6
  # Protobase
7
7
 
8
- Protobase is a config-driven admin on an existing Postgres database. `config/index.ts` exports the resources, `config/<resource>/data.ts` describes a table and `ui.ts` its views, `functions/` holds the app's API functions, and `protobase.config.ts` in the project root replaces the conventions when it exists. The app's own React code (components, field types, actions) is a plugin in `protobase.ui.tsx`.
8
+ Protobase is a config-driven admin on an existing Postgres database. `config/index.ts` exports the resources, `config/<resource>/data.ts` describes a table and `ui.ts` its views, `functions/` holds the app's API functions, and `protobase.config.ts` in the project root describes the rest of the app as one object of data (sign-in, jobs, files, the API's settings), whose code Protobase finds by its path, such as `jobs/<name>.ts`. The app's own React code (components, field types, actions) is a plugin in `protobase.ui.tsx`.
9
9
 
10
10
  Run the CLI as the project does: `npx protobase <command>`, or `bun run protobase <command>`. These pages describe the Protobase version installed in the project.
11
11
 
@@ -63,6 +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 [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)
66
73
  - When defining resources, fields, keys, relations, rollups, formulas and validation → read [Data config](references/reference/data-config.md)
67
74
  - When defining views, columns, filters, charts, related records and actions → read [UI config](references/reference/ui-config.md)
68
75
  - When asking how the packages fit together → read [Architecture](references/reference/architecture.md)
@@ -4,7 +4,7 @@
4
4
 
5
5
  A bell in the top bar and push to browsers and phones, for what your app tells its users.
6
6
 
7
- - [Notifications](../reference/notifications.md#turning-them-on) (beta): `extends: [notifications()]` gives every signed-in user a bell in the top bar and push to their browsers and phones; `ui: false` keeps only the backend.
7
+ - [Notifications](../reference/notifications.md#turning-them-on) (beta): `notifications: {}` in the config gives every signed-in user a bell in the top bar and push to their browsers and phones; `ui: false` keeps only the backend.
8
8
  - [Devices](../reference/notifications.md#devices) (beta): Each signed-in user registers their own browsers and phones to receive push, and a device gets it only while the sign-in it was registered in lasts.
9
9
  - [Your own parts](../reference/notifications.md#your-own-parts) (beta): Senders, the device store, the history store and the bell can each be replaced by your own, such as a store outside the database.
10
10
  - [Table names](../reference/notifications.md#table-names) (beta): The built-in stores' schema, tables and columns can be renamed, as auth's users table can.
@@ -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.
@@ -6,6 +6,15 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
6
6
 
7
7
  - [Project starter](../getting-started.md#start-an-app): `npm create protobase` (also `bun create` and `pnpm create`) starts a new app from the scratch, ERP or real estate preset, with its own Postgres in Docker for development, and prints the next steps. Each preset has an `AGENTS.md` with rules for coding agents.
8
8
  - [Example apps](../getting-started.md#run-the-erp-example): Seeded example apps on Postgres: an ERP, real estate property management and a public property portal.
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
+ - [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
+ - [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.
9
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.
10
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.
11
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.
@@ -17,7 +17,7 @@ npm create protobase my-app
17
17
  npm create protobase my-app -- --preset real-estate
18
18
  ```
19
19
 
20
- The project comes with its own Postgres for development: a `docker-compose.yml` with Postgres 18, started by `bun run db:up` and stopped by `bun run db:down`, on port 55432 or, when something listens there already, the next free one. Its `.env` points at that database and has a `BETTER_AUTH_SECRET` of its own. Without Docker, set `DATABASE_URL` in `.env` to a Postgres database of yours. The next steps install it with Bun, which runs the project's scripts, start the database, migrate it, load the preset's base data, if it has any, create a user and run `bun run dev`. For scratch:
20
+ The project comes with its own Postgres for development: a `docker-compose.yml` with Postgres 18, started by `bun run db:up` and stopped by `bun run db:down`, on port 55432 or, when something listens there already, the next free one. Its `.env` points at that database and has a `PROTOBASE_SECRET` of its own. Without Docker, set `DATABASE_URL` in `.env` to a Postgres database of yours. The next steps install it with Bun, which runs the project's scripts, start the database, migrate it, load the preset's base data, if it has any, create a user and run `bun run dev`. For scratch:
21
21
 
22
22
  ```sh
23
23
  cd my-app
@@ -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
- `BETTER_AUTH_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
@@ -38,7 +38,7 @@ The app's own `authenticate` checks the token, the same one that guards the REST
38
38
  - **Not functions:** files and folders starting with `_` (shared code, such as `functions/_shared/`), dotfiles, `*.test.ts`, `*.spec.ts` and `*.d.ts`. A folder without an `index.ts` is an error that says so.
39
39
  - **The default export** is `defineFunction(...)` from `@protobase/server`, a bare `(request, context)` handler, or a Hono app. The last two need a signed-in caller.
40
40
  - **Any method** reaches the function, and so does any path below its name. The request's path is the part after `/api/functions/<name>`: `/` for the function itself, `/42/advance` for `/api/functions/workshop/42/advance`. The query string and the body are passed through unchanged.
41
- - **In `protobase.config.ts`,** `functions: { name: fn }` replaces the folder, the same way `config` replaces `config/index.ts`. The functions of [extended configs](../reference/cli.md#extending-a-config) are kept, and a name used by two configs is an error that names both.
41
+ - **Only the folder:** `protobase.config.ts` names no functions; they are found in `functions/`. The functions of an [extension](../reference/config.md#extensions)'s `functions/` folder are kept, and a name used by two folders is an error that names both.
42
42
 
43
43
  ## The context
44
44
 
@@ -100,7 +100,7 @@ A refusal or a missing record rejects with the problem the REST API would answer
100
100
 
101
101
  `defineFunction({ roles: ['mechanic', 'desk'] }, handler)` lets in callers with at least one of those roles. `defineFunction({ capability: 'vms.update' }, handler)` lets in callers whose roles hold all of that capability ([`roles.holds`](../reference/access.md#wildcards-in-has-can-and-holds)): `*`, `vms.*` or a plain `vms.update`, but not `vms.update.own` or a `vms.update` limited to fields or rows. A wildcard means all of it, so `vms.*` needs a role that holds `vms.*` or `*`. Anyone else gets a `403 function-forbidden` problem before the handler runs. Finer rules belong in the resources' [access rules](../reference/access.md), which `records` already applies.
102
102
 
103
- In an app with [roles](../reference/access.md) (`options: { roles }`), a function with neither is closed like a resource without a rule: only callers whose roles hold `*`, such as `admin: ['*']`, may call it, unless `defaultAccess` is `allow`. A function for everyone signed in says so with its roles. In an app without roles, every signed-in caller may call it. A `capability` needs the app's roles, and a function takes `roles` or `capability`, not both: the server refuses to start otherwise.
103
+ In an app with [roles](../reference/access.md) (`config/roles.ts`), a function with neither is closed like a resource without a rule: only callers whose roles hold `*`, such as `admin: ['*']`, may call it, unless `defaultAccess` is `allow`. A function for everyone signed in says so with its roles. In an app without roles, every signed-in caller may call it. A `capability` needs the app's roles, and a function takes `roles` or `capability`, not both: the server refuses to start otherwise.
104
104
 
105
105
  ## Public functions and webhooks
106
106
 
@@ -404,13 +404,13 @@ export default defineFunction({ longQueries: true }, async (request, { db }) =>
404
404
  - **Up to 30 seconds** per query, the most any query of an app may run. Work longer than that belongs in steps, such as a [job](../reference/jobs.md) per batch, which takes `longQueries` too.
405
405
  - **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does. With a `db` the project exports itself, the option changes nothing.
406
406
  - **`records` keep the API's limit,** [`statementTimeoutMs`](../reference/api.md#safety).
407
- - **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to `options.onUnhandledError` and the [error tracker](../reference/api.md#error-reporting).
407
+ - **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
408
408
 
409
409
  ## Errors
410
410
 
411
411
  - **Problems:** throw an `HttpProblem` (or `badRequest`, `unauthorized`, `forbidden`, `notFound` from `@protobase/server`) to answer with an [RFC 9457 problem](../reference/api.md#errors). Hono's `HTTPException` works too.
412
412
  - **A query the database stopped** is a `504 statement-timeout` that names the call; see [Long queries](#long-queries).
413
- - **Everything else:** any other error, or a handler that returns something other than a `Response`, becomes a `500 internal-error` problem without its message. The error goes to `options.onUnhandledError`, which `protobase dev` and `serve` print.
413
+ - **Everything else:** any other error, or a handler that returns something other than a `Response`, becomes a `500 internal-error` problem without its message. The error goes to the app's error hook, `hooks/error.ts`; without one, `protobase dev` and `serve` print it.
414
414
 
415
415
  ## Functions moved from Supabase
416
416
 
@@ -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)), plus the project's own settings (`BETTER_AUTH_SECRET`, ...). 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
 
@@ -44,7 +44,7 @@ Every release pushes two public images to GitHub's registry, for `linux/amd64` a
44
44
  | `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
45
45
 
46
46
  ```sh
47
- docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET ghcr.io/prototeamhq/protobase:0.2.0
47
+ docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:0.2.0
48
48
  ```
49
49
 
50
50
  In `protobase-dev`, copy a preset into `/workspace` and `bun install --frozen-lockfile` has nothing to do; installed anywhere else, it comes from the cache, without the network.
@@ -87,12 +87,12 @@ APP_DB_PASSWORD=... # openssl rand -hex 24
87
87
  `app.env`, the app's own settings:
88
88
 
89
89
  ```sh
90
- BETTER_AUTH_SECRET=... # openssl rand -base64 32
91
- BETTER_AUTH_URL=http://localhost:8787
90
+ PROTOBASE_SECRET=... # openssl rand -base64 32
91
+ PROTOBASE_URL=http://localhost:8787
92
92
  PROTOBASE_TRUSTED_PROXIES=172.30.87.1
93
93
  ```
94
94
 
95
- `BETTER_AUTH_URL` is the address the browser opens, exactly: sign-in from `http://127.0.0.1:8787` is refused as another origin. `PROTOBASE_TRUSTED_PROXIES` is the compose network's gateway, which every connection through the published port comes from, a reverse proxy's included; trusting it lets the sign-in limits count each client by the proxy's `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)). Add the app's other variables to `app.env` too.
95
+ `PROTOBASE_URL` is the address the browser opens, exactly: sign-in from `http://127.0.0.1:8787` is refused as another origin. `PROTOBASE_TRUSTED_PROXIES` is the compose network's gateway, which every connection through the published port comes from, a reverse proxy's included; trusting it lets the sign-in limits count each client by the proxy's `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)). Add the app's other variables to `app.env` too.
96
96
 
97
97
  ```yaml
98
98
  services:
@@ -165,7 +165,7 @@ app.example.com {
165
165
  }
166
166
  ```
167
167
 
168
- Then set `BETTER_AUTH_URL=https://app.example.com` in `app.env` and run `docker compose up -d` to apply it. Only then are the session cookies `Secure` and passwords and codes encrypted on the way. Another proxy must also append the client's address to `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)), or every visitor shares one sign-in limit. Do not change the port to `8787:8787`: that publishes plain HTTP on every interface, ahead of host firewall rules such as ufw. On Docker Engine older than 28.0, hosts on the same local network can still reach a port published to `127.0.0.1`, so use 28.0 or newer.
168
+ Then set `PROTOBASE_URL=https://app.example.com` in `app.env` and run `docker compose up -d` to apply it. Only then are the session cookies `Secure` and passwords and codes encrypted on the way. Another proxy must also append the client's address to `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses)), or every visitor shares one sign-in limit. Do not change the port to `8787:8787`: that publishes plain HTTP on every interface, ahead of host firewall rules such as ufw. On Docker Engine older than 28.0, hosts on the same local network can still reach a port published to `127.0.0.1`, so use 28.0 or newer.
169
169
 
170
170
  ### First admin
171
171
 
@@ -173,7 +173,7 @@ Then set `BETTER_AUTH_URL=https://app.example.com` in `app.env` and run `docker
173
173
  docker compose run --rm --no-deps app create-admin /app you@example.com --generate-password
174
174
  ```
175
175
 
176
- Then open the address in `BETTER_AUTH_URL` and sign in with that email and the printed password: `https://app.example.com` once the proxy is in front, `http://localhost:8787` (or the SSH tunnel) only while `BETTER_AUTH_URL` is still `http://localhost:8787`, since sign-in from any other address is refused as another origin. `--no-deps` keeps compose from running `migrate` first, which during an upgrade would migrate under the old version while it serves; use it with every `docker compose run … app`. Where container logs leave the host, pass the password on stdin instead: `docker compose run --rm --no-deps -T app create-admin /app you@example.com --password-stdin < password.txt`.
176
+ Then open the address in `PROTOBASE_URL` and sign in with that email and the printed password: `https://app.example.com` once the proxy is in front, `http://localhost:8787` (or the SSH tunnel) only while `PROTOBASE_URL` is still `http://localhost:8787`, since sign-in from any other address is refused as another origin. `--no-deps` keeps compose from running `migrate` first, which during an upgrade would migrate under the old version while it serves; use it with every `docker compose run … app`. Where container logs leave the host, pass the password on stdin instead: `docker compose run --rm --no-deps -T app create-admin /app you@example.com --password-stdin < password.txt`.
177
177
 
178
178
  ### Upgrade
179
179
 
@@ -13,16 +13,16 @@ Protobase never changes your tables. Sign-in is the one thing it adds to the dat
13
13
  In a new folder, next to the database's own code or anywhere else:
14
14
 
15
15
  ```sh
16
- npm install @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui pg kysely
16
+ npm install @protobase/cli @protobase/config @protobase/schema @protobase/layout @protobase/server @protobase/ui pg kysely
17
17
  ```
18
18
 
19
19
  Then a `.env` beside it, which every `protobase` command reads:
20
20
 
21
21
  ```sh
22
22
  DATABASE_URL=postgres://user:password@localhost:5432/shop
23
- # Signs session cookies: generate your own with openssl rand -base64 32
24
- BETTER_AUTH_SECRET=
25
- BETTER_AUTH_URL=http://localhost:5173
23
+ # The app's secret, which signs session cookies: generate your own with openssl rand -base64 32
24
+ PROTOBASE_SECRET=
25
+ PROTOBASE_URL=http://localhost:5173
26
26
  ```
27
27
 
28
28
  Keep `.env` out of version control.
@@ -45,39 +45,19 @@ It checks the config against the database: each table and column exists, each ty
45
45
 
46
46
  ## 4. Add sign-in
47
47
 
48
- Two files. `protobase.config.ts` is the project:
48
+ Sign-in is on by default: it takes the app's address and secret from `PROTOBASE_URL` and `PROTOBASE_SECRET` in `.env`, and keeps users, sessions and signing keys in an `auth` schema of their own, next to your tables. `protobase.config.ts` says the rest; the resources in `config/` are found by that path:
49
49
 
50
50
  ```ts
51
- import * as config from './config'
52
- import { auth, authenticate } from './auth/auth'
51
+ import { defineConfig } from '@protobase/config'
53
52
 
54
- export default { config, auth, authenticate }
55
- ```
56
-
57
- `auth/auth.ts` sets up sign-in with [Better Auth](../reference/auth.md), with its tables in the `auth` schema:
58
-
59
- ```ts
60
- import { PostgresDialect } from 'kysely'
61
- import pg from 'pg'
62
- import { appPool, betterAuthAuthenticator, createAuth } from '@protobase/server'
63
-
64
- const secret = process.env.BETTER_AUTH_SECRET
65
- if (!secret) throw new Error('BETTER_AUTH_SECRET is not set: put the output of `openssl rand -base64 32` in .env')
66
-
67
- // The app's one pool on DATABASE_URL, which `protobase dev` and `serve` share.
68
- const pool = appPool(pg, process.env.DATABASE_URL!)
69
-
70
- export const auth = createAuth({
71
- // Users, sessions and signing keys live in a schema of their own, next to your tables.
72
- database: { dialect: new PostgresDialect({ pool }), type: 'postgres', schemaName: 'auth', transaction: true },
73
- baseURL: process.env.BETTER_AUTH_URL ?? 'http://localhost:5173',
74
- secret,
53
+ export default defineConfig({
54
+ auth: { roles: ['admin'] },
55
+ // Everyone works in tenant 1.
56
+ authenticate: { tenant: 1 },
75
57
  })
76
-
77
- export const authenticate = betterAuthAuthenticator({ auth, tenant: 1 })
78
58
  ```
79
59
 
80
- The [auth reference](../reference/auth.md) has the rest: emailed codes, passkeys, two-factor, roles, and a users table the database already has.
60
+ The [config reference](../reference/config.md) has every key, and the [auth reference](../reference/auth.md) the rest of sign-in: emailed codes, passkeys, two-factor, roles, and a users table the database already has.
81
61
 
82
62
  ## 5. Write and apply the auth tables
83
63
 
@@ -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
 
@@ -157,7 +157,7 @@ Reload the app. The card shows three orders, and the app was neither rebuilt nor
157
157
 
158
158
  ## 7. Ship it
159
159
 
160
- Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `PROTOBASE_PLUGINS`, or in `options.plugins` of its `protobase.config.ts`, which can also give the plugin settings and limit it to some roles (see [loading](../reference/plugins.md#loading)). Serve `plugin.json` without caching, so a new build reaches the apps on their next load, and the files in `assets/`, whose names change with their content, as long as you like.
160
+ Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `PROTOBASE_PLUGINS`, or in the `plugins` of its `protobase.config.ts`, which can also give the plugin settings and limit it to some roles (see [loading](../reference/plugins.md#loading)). Serve `plugin.json` without caching, so a new build reaches the apps on their next load, and the files in `assets/`, whose names change with their content, as long as you like.
161
161
 
162
162
  ## When the app moves on
163
163
 
@@ -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
 
@@ -21,6 +21,8 @@ Set their variables, such as `ANDROID_HOME` and `JAVA_HOME`, in your shell, not
21
21
 
22
22
  ```ts
23
23
  // protobase.config.ts
24
+ import { defineConfig } from '@protobase/config'
25
+
24
26
  export default defineConfig({
25
27
  // ...
26
28
  mobile: {
@@ -33,7 +35,7 @@ export default defineConfig({
33
35
  - `appId` is the app's id in reverse-DNS form, the same on iOS and Android: at least two parts separated by dots, each starting with a letter and holding only letters and digits. Underscores and hyphens are refused, as iOS rejects underscores and Android rejects hyphens; `protobase mobile` stops early on such an id and suggests one without them.
34
36
  - `plugins`, optional, are extra native [Capacitor plugins](https://capacitorjs.com/docs/plugins), npm name to version. Capacitor itself, `@capacitor/app`, `@capacitor/keyboard`, `@capacitor/splash-screen` and `@capawesome/capacitor-live-update` come with Protobase at fixed versions and cannot be listed. A plugin runs native code with the app's rights, and one that writes files, such as `@capacitor/filesystem`, lets a script that got into the page point the iOS app at files it wrote (with Capacitor's own `WebView.setServerBasePath`), so list only plugins the app needs. On Android a plugin's JavaScript cannot call `CapacitorHttp`, `CapacitorCookies` or `WebView`, and `Capacitor.convertFileSrc` URLs do not load: call those from the plugin's native code.
35
37
 
36
- The app is installed under the name it shows in its upper left, on iOS and Android alike: `protobase mobile` reads it from the server the app calls (its web manifest), so a `PROTOBASE_APP_NAME` the server runs with names the app on the phone too. When that server cannot be reached, `run` and `open` warn and take the project's own name, `appName` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
38
+ The app is installed under the name it shows in its upper left, on iOS and Android alike: `protobase mobile` reads it from the server the app calls (its web manifest), so a `PROTOBASE_APP_NAME` the server runs with names the app on the phone too. When that server cannot be reached, `run` and `open` warn and take the project's own name, the config's `name` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
37
39
 
38
40
  On the home screen the app shows Protobase's icon, on iOS and Android alike. <gap>An app cannot show its own icon on the phone because setting the mobile app's icon is not implemented.</gap>
39
41
 
@@ -59,7 +61,7 @@ The first run installs Capacitor into `.protobase/mobile/`, which ignores itself
59
61
 
60
62
  In the app, the admin keeps clear of the status bar, the notch, the home indicator and Android's system bars, and it does not zoom: a focused input leaves the page at its scale, and so does a pinch. <gap>The status bar's text cannot follow the theme chosen in the app, only the phone's light or dark mode, because setting the status bar's style is not implemented.</gap>
61
63
 
62
- The app calls the server at the project's auth `baseURL`; pass `--api https://shop.example.com` for another one. Plain http is only for a server on this machine (`localhost`) or, on the Android emulator, its host `10.0.2.2`; any other server needs https. An Android phone on USB reaches a server on `localhost` through a forwarded port; an iPhone needs an https server. The app's UI plugins load from the device only when the server serves a built bundle (`protobase serve dist`): against `protobase dev`, use `--live`.
64
+ The app calls the server at the app's `url` (`PROTOBASE_URL` by default); pass `--api https://shop.example.com` for another one. Plain http is only for a server on this machine (`localhost`) or, on the Android emulator, its host `10.0.2.2`; any other server needs https. An Android phone on USB reaches a server on `localhost` through a forwarded port; an iPhone needs an https server. The app's UI plugins load from the device only when the server serves a built bundle (`protobase serve dist`): against `protobase dev`, use `--live`.
63
65
 
64
66
  `--target <id>` picks the simulator, emulator or device; without it Capacitor asks.
65
67
 
@@ -98,7 +100,7 @@ protobase mobile build ios --app-version 1.2.3 --build-number 7 --api https://sh
98
100
  makes a signed release binary: an `.aab` to upload to Google Play, an `.ipa` to upload to App Store Connect. It goes to `mobile-release/`, which ignores itself in git, named `<appId>-<version>-<build number>`; `--out <dir>` picks another folder.
99
101
 
100
102
  - The binary carries the app's files, so it opens without a network and never downloads anything on its first launch; offline it says it cannot reach the server, as the web app does.
101
- - A release calls its server over https, at `--api` or the project's auth `baseURL`: plain http, `localhost` and `10.0.2.2` are refused.
103
+ - A release calls its server over https, at `--api` or the app's `url`: plain http, `localhost` and `10.0.2.2` are refused.
102
104
  - `--app-version` is the version the stores show, one to three numbers such as `1.2.3`. `--build-number` is a whole number that must rise with every upload, such as your CI's run number.
103
105
  - Extra plugins run at build time with access to your signing key, so add only plugins you trust.
104
106
 
@@ -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
 
@@ -47,7 +47,7 @@ The project's Tailwind classes are built into the plugin's own stylesheet, `plug
47
47
 
48
48
  ## 4. Extensions
49
49
 
50
- Each `--extend` folder's `protobase.ui.tsx` becomes a plugin of its own, `plugins/<name>/`, named by its `package.json`, else its folder, and merged before the project's, as before. Its `protobase.config.ts` is merged into the config module as before. Two extensions that would be plugins of one name fail the build: give one's `package.json` another `name`.
50
+ Each `--extend` folder's `protobase.ui.tsx` becomes a plugin of its own, `plugins/<name>/`, named by its `package.json`, else its folder, and merged before the project's, as before. Its config, with the code its paths find, goes into the config module and is merged before the project's when the bundle is served (see [Extensions](../reference/config.md#extensions)). Two extensions that would be plugins of one name fail the build: give one's `package.json` another `name`.
51
51
 
52
52
  ## 5. Hosts
53
53
 
@@ -4,19 +4,18 @@
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
 
11
- Add `notifications()` to `protobase.config.ts`:
11
+ Add `notifications` to `protobase.config.ts`:
12
12
 
13
13
  ```ts
14
- import { defineConfig, notifications } from '@protobase/server'
14
+ import { defineConfig } from '@protobase/config'
15
15
 
16
16
  export default defineConfig({
17
- config,
18
- extends: [notifications()],
19
- // auth, authenticate, jobs, ...
17
+ notifications: {},
18
+ // auth, jobs, ...
20
19
  })
21
20
  ```
22
21
 
@@ -62,7 +61,7 @@ import { appPath } from '@protobase/schema'
62
61
  import { sendNotification, subscription } from '@protobase/server'
63
62
 
64
63
  // The app's public origin: the address its sign-in runs on, from its own configuration.
65
- const appOrigin = process.env.BETTER_AUTH_URL ?? 'http://localhost:5173'
64
+ const appOrigin = process.env.PROTOBASE_URL ?? 'http://localhost:5173'
66
65
 
67
66
  /** Tells an order's owner when its status changes, in their inbox and as push, with a link to the order. */
68
67
  export const orderStatusToOwner = subscription('orderStatusToOwner', {
@@ -107,7 +106,7 @@ On an iPhone or iPad, push reaches the app once it is added to the Home Screen,
107
106
 
108
107
  ## 6. Turn the bell off or replace a part
109
108
 
110
- - `notifications({ ui: false })` keeps sending, the history and devices, and draws no bell: your own UI reads the history and turns push on with [the browser helper](../reference/notifications.md#in-the-browser) ([without the bell](../reference/notifications.md#without-the-bell)).
109
+ - `notifications: { ui: false }` keeps sending, the history and devices, and draws no bell: your own UI reads the history and turns push on with [the browser helper](../reference/notifications.md#in-the-browser) ([without the bell](../reference/notifications.md#without-the-bell)).
111
110
  - `shell.bell` in `protobase.ui.tsx` draws your own bell in its place ([the bell's slot](../reference/notifications.md#the-bells-slot)).
112
111
  - Your own device store, history store or senders replace the built-in ones, such as a store outside the database ([your own parts](../reference/notifications.md#your-own-parts)).
113
112
  - The tables' schema, names and columns can be renamed ([table names](../reference/notifications.md#table-names)).
@@ -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