@protobase/cli 0.47.1 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) 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 +70 -0
  5. package/dist/config/called-config.js +11 -0
  6. package/dist/config/config-defaults.js +30 -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/api-child.js +2 -1
  15. package/dist/dev/api-process.d.ts +1 -0
  16. package/dist/dev/api-process.js +5 -2
  17. package/dist/dev/auth-drift-lines.js +8 -0
  18. package/dist/dev/create-db.js +2 -2
  19. package/dist/dev/entry.d.ts +5 -0
  20. package/dist/dev/entry.js +17 -12
  21. package/dist/dev/project.js +23 -47
  22. package/dist/dev/run.js +3 -2
  23. package/dist/main.js +3 -3
  24. package/dist/migration/load-project.js +34 -34
  25. package/dist/migration/parts.js +2 -2
  26. package/dist/migration/summary.js +2 -2
  27. package/dist/mobile/api-origin.js +4 -4
  28. package/dist/mobile/load-project.js +13 -12
  29. package/dist/mobile/register.js +1 -1
  30. package/dist/mobile/run.js +1 -1
  31. package/dist/organizations/register.js +1 -1
  32. package/dist/project/error-reporter.js +3 -3
  33. package/dist/project/import-project-file.js +4 -2
  34. package/dist/project/load-bundle-project.js +16 -25
  35. package/dist/project/load-data-config.js +2 -2
  36. package/dist/project/pg-db.js +10 -4
  37. package/dist/project/placeholder-secret.js +2 -2
  38. package/dist/project/project-admin.js +12 -11
  39. package/dist/scaffold/plan.js +7 -3
  40. package/dist/scaffold/protobase-tables.js +8 -13
  41. package/dist/scaffold/run.js +1 -1
  42. package/dist/serve/create-admin.js +9 -4
  43. package/dist/serve/host-module-ids.js +1 -0
  44. package/dist/serve/host-modules.js +3 -1
  45. package/dist/serve/lifecycle.js +19 -14
  46. package/dist/serve/load-bundle.js +41 -11
  47. package/dist/serve/mobile-release.js +1 -1
  48. package/dist/serve/serve-bundle.js +3 -3
  49. package/dist/supabase/auth-config.js +33 -28
  50. package/dist/supabase/config-jobs.js +28 -27
  51. package/dist/supabase/config-object.js +25 -0
  52. package/dist/supabase/cron-job-file.js +13 -14
  53. package/dist/supabase/cron-jobs-write.js +6 -12
  54. package/dist/supabase/cron-plan.js +3 -51
  55. package/dist/supabase/project-files.js +4 -9
  56. package/dist/supabase/report.js +3 -3
  57. package/dist/users/load-auth.js +16 -15
  58. package/dist/worker/start-worker.js +18 -15
  59. package/package.json +8 -6
  60. package/skills/protobase/SKILL.md +2 -1
  61. package/skills/protobase/references/features/notifications.md +1 -1
  62. package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
  63. package/skills/protobase/references/features/start-a-project.md +3 -0
  64. package/skills/protobase/references/getting-started.md +2 -2
  65. package/skills/protobase/references/guides/api-functions.md +4 -4
  66. package/skills/protobase/references/guides/deploy.md +8 -8
  67. package/skills/protobase/references/guides/existing-database.md +11 -31
  68. package/skills/protobase/references/guides/first-plugin.md +1 -1
  69. package/skills/protobase/references/guides/mobile-app.md +5 -3
  70. package/skills/protobase/references/guides/plugin-build.md +1 -1
  71. package/skills/protobase/references/guides/push-notifications.md +6 -7
  72. package/skills/protobase/references/guides/remote-resources.md +22 -31
  73. package/skills/protobase/references/reference/access.md +3 -3
  74. package/skills/protobase/references/reference/ai.md +1 -9
  75. package/skills/protobase/references/reference/api.md +15 -15
  76. package/skills/protobase/references/reference/app-identity.md +9 -10
  77. package/skills/protobase/references/reference/assistant.md +6 -6
  78. package/skills/protobase/references/reference/auth.md +126 -96
  79. package/skills/protobase/references/reference/bottom-bar.md +1 -1
  80. package/skills/protobase/references/reference/cli.md +36 -86
  81. package/skills/protobase/references/reference/comments.md +0 -8
  82. package/skills/protobase/references/reference/config.md +152 -0
  83. package/skills/protobase/references/reference/data-config.md +2 -2
  84. package/skills/protobase/references/reference/email.md +36 -37
  85. package/skills/protobase/references/reference/events.md +1 -1
  86. package/skills/protobase/references/reference/files.md +18 -23
  87. package/skills/protobase/references/reference/forms.md +5 -17
  88. package/skills/protobase/references/reference/history.md +2 -3
  89. package/skills/protobase/references/reference/installable-app.md +1 -1
  90. package/skills/protobase/references/reference/jobs.md +53 -56
  91. package/skills/protobase/references/reference/languages.md +4 -2
  92. package/skills/protobase/references/reference/mcp.md +11 -11
  93. package/skills/protobase/references/reference/notifications.md +26 -24
  94. package/skills/protobase/references/reference/plugins.md +11 -14
  95. package/skills/protobase/references/reference/remote-resources.md +18 -24
  96. package/skills/protobase/references/reference/supabase-realtime.md +1 -1
  97. package/skills/protobase/references/reference/supabase-rest.md +1 -1
  98. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  99. package/skills/protobase/references/reference/ui-config.md +15 -17
  100. package/skills/protobase/references/reference/versioning.md +1 -1
  101. package/skills/protobase/references/reference/webhooks.md +6 -7
@@ -34,7 +34,7 @@ Each bar names its roles, and a role belongs to one bar. A caller gets the bar t
34
34
 
35
35
  ## Checks
36
36
 
37
- `createAdmin` refuses to start when a bar names a resource or page that does not exist, has no roles, no items or more than four, names a role the app does not have (the roles of [`createAuth`](auth.md) and [`defineRoles`](access.md); without either, any role is accepted), shares a role with another bar, or has the label of another bar. The checks are [`bottomBarErrors`](https://docs.protobase.net/api/schema/functions/bottombarerrors/) from `@protobase/schema`, a pure function of the bars and the app's names.
37
+ `createAdmin` refuses to start when a bar names a resource or page that does not exist, has no roles, no items or more than four, names a role the app does not have (the roles of [`auth.roles`](auth.md#roles) and [`defineRoles`](access.md); without either, any role is accepted), shares a role with another bar, or has the label of another bar. The checks are [`bottomBarErrors`](https://docs.protobase.net/api/schema/functions/bottombarerrors/) from `@protobase/schema`, a pure function of the bars and the app's names.
38
38
 
39
39
  `protobase dev`, `protobase build` and `protobase serve` pick the bars up from the config module. With `createAdmin` directly, pass them as `bottomBars`:
40
40
 
@@ -34,7 +34,7 @@ const { exitCode, stdout, stderr } = await runCommand(['doctor', '--env', 'DATAB
34
34
  - Commands run one at a time, since they share the process's working folder, environment and output. Each puts them back when it ends.
35
35
  - The CLI and its packages stay loaded, so only the first command pays for loading them. On Bun the project's own files are loaded again for each command, so a command sees them as they are when it starts.
36
36
  - `dev`, `serve`, `worker` and `mobile` run until a signal, so the runner refuses them; start them as a process.
37
- - A command that ends with an exit code returns it rather than ending the process. Database pools the project's config opens close once idle.
37
+ - A command that ends with an exit code returns it rather than ending the process. Database pools a command opens for the project close once idle.
38
38
 
39
39
  The serve runtime is bundled by `protobase build-serve` into one JavaScript file for Bun, so production needs neither `node_modules` nor the CLI (see [serve](#serve)).
40
40
 
@@ -48,7 +48,7 @@ protobase scaffold [connection string | --env VAR] [target] [options]
48
48
 
49
49
  Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
50
50
 
51
- Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the `auth` schema, another schema holding Better Auth's `user`, `session`, `account` and `verification` tables (in `public`, only the auth store's tables), and pg-boss's `jobs` schema. A line names each one skipped; a target naming the schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it.
51
+ Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the auth store, which is the `auth` schema or another schema with the store's `auth_migrations` table, or with Better Auth's `session`, `account` and `verification` tables whose sessions point at a user table (in `public`, only the tables of the store's [migrations](auth.md#migrations) and that user table, whatever it is called), and pg-boss's `jobs` schema. A line names each one skipped. The auth store is left out whatever the target names; a target naming the `jobs` schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it, and `dev` and `serve` refuse to start with a resource over the auth store.
52
52
 
53
53
  | Option | Effect |
54
54
  | --- | --- |
@@ -127,69 +127,23 @@ One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/a
127
127
 
128
128
  - **Server package:** the API's process loads `@protobase/server` from the project's `node_modules` when its `package.json` lists it, in any of its dependency fields; a project that lists it without installing it fails as with any missing package. Without a `package.json`, or with one that does not list it, it uses the copy the CLI ships, with the CLI's `@protobase/schema`, `@protobase/query` and `@protobase/layout`.
129
129
 
130
- - **Secret:** a `BETTER_AUTH_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
130
+ - **Secret:** a `PROTOBASE_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
131
131
  - **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and, when nothing listens there, points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
132
132
  - **Port:** the app listens on `--port` at both `127.0.0.1` and `::1`, since `localhost` is either one depending on the runtime and the browser. When another process holds the port on either address the command stops before it starts and names that address; stop the other server or pass another `--port`.
133
133
  - **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
134
- - **Login:** real sign-in only, with the `authenticate` and `auth` exported by `protobase.config.ts` (see [Login with Better Auth](auth.md)). A project without an authenticator fails at startup with a message pointing there, one whose auth schema is behind with the tables and columns it lacks (see [`auth migration`](#auth-migration)), and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. The `login` line of the startup message says how to sign in: while the auth store has no users, it prints the exact command that creates the first admin, such as `bun run protobase users create you@example.com --generate-password` (the package manager that started `dev`, `npx` otherwise). Against a database that has users already, such as an app's hosted one, sign in as one of them or add one with a new email; its own password is set there.
134
+ - **Login:** real sign-in only, with the config's `auth`, on by default, or its `authenticate` for tokens of an auth server elsewhere (see [protobase.config.ts](config.md) and [Login with Better Auth](auth.md)). A project with sign-in off and no authenticator fails at startup with a message pointing there, as does one with sign-in on and no `PROTOBASE_SECRET`, one whose auth store has not applied every migration of this version, naming them (see [`auth migration`](#auth-migration)), one with a resource over a table of the auth store, and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. The `login` line of the startup message says how to sign in: while the auth store has no users, it prints the exact command that creates the first admin, such as `bun run protobase users create you@example.com --generate-password` (the package manager that started `dev`, `npx` otherwise). Against a database that has users already, such as an app's hosted one, sign in as one of them or add one with a new email; its own password is set there. A `warning` line follows for each way the auth store's tables differ from what the app's sign-in needs, such as a column dropped by hand: the one place Protobase compares them, since `serve` reads the store's record of [migrations](auth.md#migrations) alone.
135
135
  - **Mobile releases:** see [below](#mobile-releases).
136
136
  - **Jobs:** with [jobs](jobs.md) in the config it runs them in the API's process, once the jobs schema checks out (see [`migration`](#migration)); an edited job runs its new code from the next job on.
137
137
  - **Tunnels and other hosts:** Vite only answers `localhost` by default. `--allowed-hosts .trycloudflare.com,app.example.com` adds Host headers (a leading dot matches all subdomains). Hot reload needs no extra setting: the Vite client takes protocol, host and port from the page, so behind an HTTPS tunnel it connects over `wss` on 443 as long as the tunnel forwards WebSockets.
138
- - **Project discovery**, by convention: `config/index.ts` exports the resources (and views), and every `config/*/ui.ts` export that is not already exported by the index is added as a view. Each `functions/<name>.ts` (or `functions/<name>/index.ts`) is an [API function](../guides/api-functions.md) at `/api/functions/<name>`. A `protobase.config.ts` in the project root replaces the convention; its default export may contain any of:
139
-
140
- ```ts
141
- import * as config from './config'
142
- export default {
143
- config, // module whose exports are resources and views
144
- db, // Kysely instance, instead of DATABASE_URL
145
- authenticate, // Authenticator, required
146
- auth, // Better Auth (AdminAuth); its routes are mounted under /api/auth
147
- functions, // API functions by name, instead of ./functions
148
- jobs, // module whose exports are jobs (defineJob), see Jobs
149
- options, // AdminOptions (scan guard, write hooks, ...)
150
- }
151
- ```
152
-
153
- `defineConfig` from `@protobase/server` types it, and its `extends` merges other configs in (see [Extending a config](#extending-a-config)).
138
+ - **Project discovery**, by convention: `config/index.ts` exports the resources (and views), and every `config/*/ui.ts` export that is not already exported by the index is added as a view. Each `functions/<name>.ts` (or `functions/<name>/index.ts`) is an [API function](../guides/api-functions.md) at `/api/functions/<name>`. `protobase.config.ts` (or `protobase.config.json`) in the project root describes the rest as data, and the jobs, hooks and other code it names are found by their paths; see [protobase.config.ts](config.md). Without it, the app runs on the defaults.
154
139
  - **Project UI:** the app imports `protobase.ui.tsx` from the project root, with hot reload, when it exists (see [Custom components](custom-components.md)): the same contract as the plugin `protobase build` makes of it, built into the dev page instead. Layout files are checked as they load, as `protobase build` checks them.
155
140
  - **Theme:** the page links `/protobase.theme.css`, which the dev server answers from the project's [theme](theme.md), checked as the build checks it, on every request, so an edit shows on the next reload. It links `/protobase.favicon.svg` too, the project's [favicon](theme.md#logo-and-favicon) or Protobase's, and `/protobase.apple-touch-icon.png`, which it answers with the PNG [icons](app-identity.md#the-icons) the project has.
156
141
  - **Extensions:** `--extend <dir>` merges an extension in, its UI built into the dev page beside the project's, to try one out; its files reload like the project's.
157
- - **Hot reload:** server code, data configs, `ui.ts` views, layouts and `protobase.config.ts` are loaded through Vite's SSR module graph. A change inside the project (or, in this repository, in `packages/server`, `packages/query`, `packages/schema`) rebuilds the API on the next request without a restart; `/meta` and `X-Meta-Version` change, so open tabs refetch. The database pool survives reloads. Newly added `ui.ts` files appear after the next change inside the project.
142
+ - **Hot reload:** server code, data configs, `ui.ts` views, layouts and the config are loaded through Vite's SSR module graph, and the config is read again with each rebuild. A change inside the project (or, in this repository, in `packages/server`, `packages/query`, `packages/schema`) rebuilds the API on the next request without a restart; `/meta` and `X-Meta-Version` change, so open tabs refetch. The database pool survives reloads. Newly added `ui.ts` files appear after the next change inside the project.
158
143
 
159
144
  ### Extending a config
160
145
 
161
- A config can extend others by importing them, like Vite's `defineConfig`. `extends` lists configs merged in order, each after the ones it extends itself, and the extending config last:
162
-
163
- ```ts
164
- // protobase.config.ts
165
- import { defineConfig } from '@protobase/server'
166
- import tasks from 'some-extension/protobase.config'
167
-
168
- export default defineConfig({ extends: [tasks], config, auth, authenticate, options: { roles } })
169
- ```
170
-
171
- ```tsx
172
- // protobase.ui.tsx
173
- import { defineUi } from '@protobase/ui'
174
- import * as tasksUi from 'some-extension/protobase.ui'
175
-
176
- export { UsageChart } from './components/usage-chart'
177
- export default defineUi({ extends: [tasksUi] })
178
- ```
179
-
180
- | What | How it merges | The same name twice |
181
- | --- | --- | --- |
182
- | `config` exports: resources, views, pages | all kept | an error naming both configs |
183
- | user menu | at most one among all configs | an error |
184
- | `options.assistant.tools` | the extended configs' first, in order, then the app's | an error naming the tool and both configs |
185
- | `jobs` | all kept, by job name | an error naming the job and both configs |
186
- | `options.writeHooks` | all run, in the same order | |
187
- | every other value (`db`, `auth`, `authenticate`, `roles`, `assistant.url`, ...) | the app's own; otherwise the last config that sets it | |
188
- | UI components (exported by name or in `components`), `actions` | all kept | an error naming the name and both configs |
189
- | UI `shell.actions`, `shell.rightPanel` | all drawn, the extended configs' first | |
190
- | UI `shell.logo` | the app's own; otherwise the last config that sets it | |
191
-
192
- A config's `name` names it in these errors; an extension should set one. Nothing is namespaced, so a collision is always an error, never a silent override. Names starting with `Protobase` (components) and `protobase_` (tools) belong to Protobase's own extensions, such as `ProtobaseCloudTask` and `protobase_cloud_create_proposal`; give yours other names. `mergeConfig(...configs)` from `@protobase/server` and `mergeUi(...configs)` from `@protobase/ui` merge the same way in code.
146
+ `--extend <dir>` (repeatable) merges an extension's folder into the app before the project: its config and the code its paths find, the same as the project's. How each part merges, and what a name defined twice does, is in [Extensions](config.md#extensions).
193
147
 
194
148
  ## `build`
195
149
 
@@ -215,7 +169,7 @@ dist/
215
169
  protobase.bundle.json the manifest
216
170
  ```
217
171
 
218
- The output folder is not emptied; `public/`, `migrations/` and `node_modules/` are replaced on every build. `migrations/` and `node_modules/` are deleted only when the previous build's manifest names them, so a build into a folder with a project's own `node_modules` fails instead. Of the project's server config only the config folder runs at build time, `config/index.ts` and `config/*/ui.ts` with what they import, never `protobase.config.ts`, so the build needs no secrets and no database. It is loaded once in Node to check each view against its resource: a filter widget or the chart on a field that is not `.filterable()`, a list sorted by one that is not `.sortable()`, or a list search on a field outside the resource's `.search(...)` fails the build, naming the view and the field, since the API would refuse it once a page asked. Whether an index serves those reads needs the database, which [`doctor`](#doctor) checks. Its browser code is loaded once in Node too: to check its component names (see [The UI](#the-ui)) and to read the field types each plugin registers.
172
+ The output folder is not emptied; `public/`, `migrations/` and `node_modules/` are replaced on every build. `migrations/` and `node_modules/` are deleted only when the previous build's manifest names them, so a build into a folder with a project's own `node_modules` fails instead. Of the project's server code only the config folder runs at build time, `config/index.ts` and `config/*/ui.ts` with what they import; the build reads `protobase.config.ts` (with `command: 'build'`) but builds nothing it describes, so it needs no secrets and no database. It is loaded once in Node to check each view against its resource: a filter widget or the chart on a field that is not `.filterable()`, a list sorted by one that is not `.sortable()`, or a list search on a field outside the resource's `.search(...)` fails the build, naming the view and the field, since the API would refuse it once a page asked. Whether an index serves those reads needs the database, which [`doctor`](#doctor) checks. Its browser code is loaded once in Node too: to check its component names (see [The UI](#the-ui)) and to read the field types each plugin registers.
219
173
 
220
174
  A token the [theme](theme.md) sets that the app does not read prints a `warning:` line, a likely typo; the build still succeeds.
221
175
 
@@ -227,11 +181,11 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
227
181
 
228
182
  ### Extensions
229
183
 
230
- `--extend <dir>` (repeatable) adds an extension to the bundle without touching the project's files: a folder with a `protobase.config.ts`, a `protobase.ui.tsx` or both. Its `protobase.config.ts` is merged into the config module before the project's own, as if the project [extended](#extending-a-config) it, in the order given. Its `protobase.ui.tsx` becomes one more [plugin](plugins.md) of the bundle, in `public/plugins/<name>/`, named by its `package.json`'s `name`, else its folder's. A host adds its own assistant tools and widgets to every app it builds this way; to add React code to apps without building them, serve a plugin instead.
184
+ `--extend <dir>` (repeatable) adds an extension to the bundle without touching the project's files: a folder with a `protobase.config.ts`, a `protobase.ui.tsx` or both. Its config and the code its paths find go into the config module beside the project's, merged before the project's own when the bundle is served, in the order given (see [Extensions](config.md#extensions)). Its `protobase.ui.tsx` becomes one more [plugin](plugins.md) of the bundle, in `public/plugins/<name>/`, named by its `package.json`'s `name`, else its folder's. A host adds its own assistant tools and widgets to every app it builds this way; to add React code to apps without building them, serve a plugin instead.
231
185
 
232
186
  - The extension's imports of `@protobase/*` resolve from the project, so it runs on the app's own versions; `react`, `react-dom` and `@protobase/ui` are the app's at runtime, as for every plugin. Everything else it imports resolves from its own folder and is built into its plugin, with a stylesheet of the classes its files use.
233
- - A component, action handler or field type that the extension and the project both define fails the build, naming both. To find them, the build loads the merged UI configs once in Node: only browser code, which needs no secrets. The server config still does not run at build time, so a tool both define fails when the bundle is served, naming both.
234
- - An error names a config by its `name`, otherwise by its file. Two extensions whose plugins would have one name fail the build.
187
+ - A component, action handler or field type that the extension and the project both define fails the build, naming both. To find them, the build loads the merged UI configs once in Node: only browser code, which needs no secrets. Its server code does not run at build time, so an assistant tool both define fails when the bundle is served, naming both.
188
+ - An error names an extension by its folder. Two extensions whose plugins would have one name fail the build.
235
189
 
236
190
  ### The manifest
237
191
 
@@ -264,7 +218,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
264
218
  - `theme` is the project's [theme](theme.md), which the app links at `/protobase.theme.css`. It is always there, empty when the project has none.
265
219
  - `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
266
220
  - `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
267
- - `api` lists the path prefixes the server answers. A path is under a prefix when it equals it or continues it with `/` (`/api` covers `/api/meta` and `/api/v1:batchWrite`, not `/apiary`). It is always `/api` and the two OAuth discovery documents [MCP clients](auth.md#oauth-for-mcp-clients) read, which answer 404 without MCP: a bundle assumes the API lives under `/api`, with the resources at the default `basePath` `/api/v1`, `/api/meta`, the docs, the API functions and the built-in assistant beside them and Better Auth at `/api/auth`. A bundle built before them sends them to the UI: rebuild it. The serve runtime refuses a config that sets another `options.basePath`.
221
+ - `api` lists the path prefixes the server answers. A path is under a prefix when it equals it or continues it with `/` (`/api` covers `/api/meta` and `/api/v1:batchWrite`, not `/apiary`). It is always `/api` and the two OAuth discovery documents [MCP clients](auth.md#oauth-for-mcp-clients) read, which answer 404 without MCP: a bundle assumes the API lives under `/api`, with the resources at the default `apiPath` `/api/v1`, `/api/meta`, the docs, the API functions and the built-in assistant beside them and Better Auth at `/api/auth`. A bundle built before them sends them to the UI: rebuild it. The serve runtime refuses a config that sets another `apiPath`.
268
222
  - Every other path is the UI's. A `GET` or `HEAD` for a file in `public` gets that file; a folder gets its `index.html`. Otherwise a request whose `Accept` header contains `text/html` (a navigation) gets `spa` with status 200, so deep links such as `/orders/42` load the app; anything else gets 404. Other methods get 405.
269
223
  - Files under an `assets/` folder, `public/assets/` and each plugin's, are named by their content hash and never change: serve them with `Cache-Control: public, max-age=31536000, immutable`, and everything else, `index.html`, each `plugin.json` and the theme, with `no-cache`.
270
224
  - `version` is the format of the manifest, not a Protobase version. A host that does not know it must refuse the bundle. Version 3 replaced version 2 when the project's UI became a plugin beside a prebuilt app, and gained `plugins`, `theme` and `shell`; version 2 replaced version 1 when the config module started to import [every module the runtime supplies](#the-config-module), and gained `nodeModules`. `protobase serve` refuses an older bundle; rebuild it with `protobase build`.
@@ -280,7 +234,7 @@ The modules the app shares with plugins, `react`, `react/jsx-runtime`, `react-do
280
234
 
281
235
  ### The config module
282
236
 
283
- `protobase.config.js` is one ES module. The entry is found as `protobase dev` finds it: the default export of `protobase.config.ts`, with `config` taken from the convention (`config/index.ts` plus `config/*/ui.ts`) and `functions` from `functions/` when it exports none.
237
+ `protobase.config.js` is one ES module: the project's config as written, `protobase.config.ts` or `protobase.config.json`, the extensions' configs, and the code their paths find (`config/`, `functions/`, `jobs/`, `hooks/`, `auth/` and the other files of [Where the code is](config.md#where-the-code-is)), each imported only when the app first needs it. A package the config names, such as `files.images: 'sharp'`, is imported the same way.
284
238
 
285
239
  - Vite bundles the config into plain ES modules in UTF-8, which Node and Bun both load as they are.
286
240
  - With `--bun`, Vite writes to a scratch folder and `bun build --target bun` writes the final module. Bun's output starts with `// @bun`, which tells Bun the file is already plain JavaScript: Bun neither transpiles it nor writes its transpiler cache. Bun reads such a file as Latin-1, so only Bun's own output can carry that line: its bundler writes non-ASCII text as escapes (`€` as `\u20AC`). Raw UTF-8 with that line would load as `â¬`.
@@ -301,11 +255,7 @@ The modules the app shares with plugins, `react`, `react/jsx-runtime`, `react-do
301
255
  - Packages with a native add-on stay imports too, and the bundle carries them in `node_modules/` (see [Native packages](#native-packages)). Node's built-in modules stay imports.
302
256
  - Everything else (the project's files and its other packages) is inlined. Nothing is minified.
303
257
  - Layout files (`@jsxImportSource @protobase/layout`) compile to calls of `@protobase/layout/jsx-runtime`, for production whatever `NODE_ENV` says. The build refuses one with a function, class, `new` value or hook in its JSX, naming the file, line and column ([what a layout may hold](layouts.md#what-a-layout-may-hold)).
304
- - The default export is the project config merged with the configs it [extends](#extending-a-config), with `config` always set:
305
-
306
- ```ts
307
- export default { config, authenticate, auth?, functions?, options?, db? } // as protobase.config.ts exports it
308
- ```
258
+ - It exports the configs as they are, not called: `own` (the project's), `extensions` and `packages`. The serve runtime reads the configs again, a config function called with `command: 'serve'` and the host's environment, merges them as `protobase dev` does and builds the app from them.
309
259
 
310
260
  The serve runtime reads the environment when it imports the module, on the host.
311
261
 
@@ -343,7 +293,7 @@ COPY --from=libs /out/ /
343
293
  ```
344
294
 
345
295
  ```sh
346
- docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET \
296
+ docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET \
347
297
  -v "$PWD/dist:/app:ro" -v "$PWD/protobase-serve.js:/opt/protobase/protobase-serve.js:ro" \
348
298
  protobase-run --no-install /opt/protobase/protobase-serve.js /app/protobase.config.js
349
299
  ```
@@ -369,7 +319,7 @@ dist/
369
319
  - `plugin.json` names the plugin (`--name`, else its `package.json`'s `name`, else its folder's), its own `version`, the plugin API (`api`) and the Protobase versions (`protobase`) it is built for, the module (`entry`) and stylesheet (`css`), relative to it, and the [field types](plugins.md#field-types) it registers (`fields`), each with the storage types it shows. Both versions come from the `@protobase/ui` installed for the plugin, which the build needs: `api` is its plugin API, and `protobase` is `>=` its version unless the plugin's `package.json` names a range in `engines.protobase` (see [Plugins](plugins.md#versions)).
370
320
  - `--source-maps` ends each script with a `//# debugId=<uuid>` comment, naming no map, and writes its source map, `<script>.js.map` carrying the same `debugId`, beside it, for an error tracker to read the browser's stack frames with.
371
321
 
372
- To read its field types, the build loads the plugin's module once in Node, with everything bundled; nothing is rendered, but code at the top level of its modules runs, so keep browser-only work (`window`, `document`) inside components and handlers. The app loads it from wherever `plugin.json` is served, listed in `PROTOBASE_PLUGINS` or `options.plugins` (see [loading](plugins.md#loading)).
322
+ To read its field types, the build loads the plugin's module once in Node, with everything bundled; nothing is rendered, but code at the top level of its modules runs, so keep browser-only work (`window`, `document`) inside components and handlers. The app loads it from wherever `plugin.json` is served, listed in `PROTOBASE_PLUGINS` or the config's `plugins` (see [loading](plugins.md#loading)).
373
323
 
374
324
  ## `build-serve`
375
325
 
@@ -401,22 +351,22 @@ Serves the API of a bundle from `protobase build` and owns the process around it
401
351
 
402
352
  | Variable | |
403
353
  | --- | --- |
404
- | `DATABASE_URL` | the API's pool (Kysely over `pg`, 10 connections); not needed when the config exports `db` |
405
- | `PROTOBASE_DB_CONNECTIONS` | the connections that pool opens, such as the database's limit for the app; default 10. The app's own code shares them through [`appPool`](auth.md#admin-store), as the presets' Better Auth store does. [API functions](../guides/api-functions.md) and [jobs](jobs.md) hold at most one less, so a long import leaves a connection to page and API requests; those with [`longQueries`](../guides/api-functions.md#long-queries) take theirs from one more connection, kept for them. A query waits at most 2 seconds for a free connection, then fails with `503 connections-busy` ([Safety](api.md#safety)) |
354
+ | `DATABASE_URL` | the API's pool (Kysely over `pg`, 10 connections) |
355
+ | `PROTOBASE_DB_CONNECTIONS` | the connections that pool opens, such as the database's limit for the app; default 10. Sign-in's store shares them. [API functions](../guides/api-functions.md) and [jobs](jobs.md) hold at most one less, so a long import leaves a connection to page and API requests; those with [`longQueries`](../guides/api-functions.md#long-queries) take theirs from one more connection, kept for them. A query waits at most 2 seconds for a free connection, then fails with `503 connections-busy` ([Safety](api.md#safety)) |
406
356
  | `PORT` | default 8787 |
407
357
  | `REQUEST_LOG` | `true` logs every request; default `false` |
408
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)) |
409
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 |
410
- | `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 [`appName`](auth.md#configuration) |
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) |
411
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)) |
412
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)) |
413
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)) |
414
364
  | `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins ([CORS](api.md#cors)) |
415
365
  | `PROTOBASE_ASSISTANT_URL`, `PROTOBASE_ASSISTANT_API_KEY`, `PROTOBASE_ASSISTANT_MODEL`, `PROTOBASE_ASSISTANT_BASE_URL` | the [assistant](assistant.md#which-backend): a backend elsewhere, or the built-in one on OpenRouter or another OpenAI-compatible endpoint; without them there is none |
416
366
  | `PROTOBASE_RUNTIME_URL` | the endpoint behind the top bar's [runtime update button](versioning.md#runtime-updates), such as a hosting platform's; without it there is no button |
417
- | `PROTOBASE_SENTRY_DSN` | the DSN of a Sentry-compatible error tracker the app's server and admin app send their errors to, after `options.errorReporting` ([Error reporting](api.md#error-reporting)); without it nothing is sent |
418
- | `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after `options.maps`; without it there are no maps |
419
- | `PROTOBASE_SOURCES` | other Protobase APIs whose resources the app draws as its own, a JSON list of `{ "url", "label", "resources", "roles"? }` after `options.sources` ([Remote resources](remote-resources.md#declaring-a-source)) |
367
+ | `PROTOBASE_SENTRY_DSN` | the DSN of a Sentry-compatible error tracker the app's server and admin app send their errors to, after the config's `errorReporting` ([Error reporting](api.md#error-reporting)); without it nothing is sent |
368
+ | `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after the config's `maps`; without it there are no maps |
369
+ | `PROTOBASE_SOURCES` | other Protobase APIs whose resources the app draws as its own, a JSON list of `{ "url", "label", "resources", "roles"? }` after the config's `remoteResources` ([Remote resources](remote-resources.md#declaring-a-source)) |
420
370
  | `PROTOBASE_FILES_<NAME>`, `PROTOBASE_FILES_RETENTION`, `PROTOBASE_FILES_SECRET` | [file providers](files.md#providers) and their settings, over `files` in the config; a bucket's credentials in `PROTOBASE_FILES_<NAME>_ACCESS_KEY_ID` and `_SECRET_ACCESS_KEY` |
421
371
  | `PROTOBASE_FILES_CLEANUP_MINUTES` | minutes between runs of the [scheduled file deletes](files.md#deleting-files), default 60; 0 leaves them to `protobase files cleanup` or the platform |
422
372
  | `PROTOBASE_ENCRYPTION_KEY`, `PROTOBASE_ENCRYPTION_PREVIOUS_KEYS` | the key [encrypted fields](data-config.md#encrypted-fields) are sealed with, 32 random bytes in base64 (`openssl rand -base64 32`), and the comma separated keys they were sealed with before, which still open them |
@@ -427,20 +377,20 @@ Serves the API of a bundle from `protobase build` and owns the process around it
427
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 |
428
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 |
429
379
 
430
- Better Auth and other settings are the project's own variables (`BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, ...), read by its config. `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 [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.
431
381
 
432
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.
433
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.
434
384
  - **Manifest:** a config module needs its `protobase.bundle.json` beside it. The runtime checks no version: the host picks the runtime from the manifest's `protobase` (see [Versioning](versioning.md#bundles-and-runtimes)).
435
- - **Startup:** a bundle without a default export, `config` or `authenticate`, or with an `options.basePath` other than `/api/v1`, stops startup with a one-line error and exit code 1, as does a missing `DATABASE_URL`, an auth schema that lacks a table or column, or still has the OAuth tables of [MCP](auth.md#oauth-for-mcp-clients) with `mcp` off (see [`auth migration`](#auth-migration)), a resource whose [events](events.md) or [history](history.md) lack their triggers or have out-of-date ones, or a missing history or [comments](comments.md#the-table) table, a [rollup or formula field](data-config.md#rollups-and-formulas) whose column or trigger is missing or out of date, a jobs schema that is missing or behind for a config with [jobs](jobs.md#the-jobs-schema) (see [`migration`](#migration)), an [AI field or action](ai.md#the-model) without a model key, [encrypted fields](data-config.md#encrypted-fields) without a key, or another resource over their column, or a taken port; `PROTOBASE_STARTUP_CHECKS=false` skips the checks of those schemas and the key. `protobase serve listening on port <port>` means it is ready.
385
+ - **Startup:** a config module that `protobase build` did not write, a config with an `apiPath` other than `/api/v1`, or one with sign-in on and no secret or URL, stops startup with a one-line error and exit code 1, as does a missing `DATABASE_URL`, an auth store that has not applied every migration of this version, or has a newer one (see [`auth migration`](#auth-migration)), a resource over a table of the auth store, a resource whose [events](events.md) or [history](history.md) lack their triggers or have out-of-date ones, or a missing history or [comments](comments.md#the-table) table, a [rollup or formula field](data-config.md#rollups-and-formulas) whose column or trigger is missing or out of date, a jobs schema that is missing or behind for a config with [jobs](jobs.md#the-jobs-schema) (see [`migration`](#migration)), an [AI field or action](ai.md#the-model) without a model key, [encrypted fields](data-config.md#encrypted-fields) without a key, or another resource over their column, or a taken port; `PROTOBASE_STARTUP_CHECKS=false` skips the checks of those schemas and the key. `protobase serve listening on port <port>` means it is ready.
436
386
  - **Jobs:** with [jobs](jobs.md) in the config it runs them beside the API, unless `PROTOBASE_JOBS=false`, and with `PROTOBASE_JOBS_DRAIN_TOKEN` it answers `POST /api/jobs/drain` for the operator.
437
- - **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, closes open WebSockets with 1001 (dropping any still open after 5 seconds), waits for open requests, gives running jobs 30 seconds to finish, drains the pool `serve` created (a `db` the config exports is the project's to close) and exits with 0.
387
+ - **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, closes open WebSockets with 1001 (dropping any still open after 5 seconds), waits for open requests, gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
438
388
  - **Host modules:** under Bun, the runtime registers [the modules it supplies](#the-config-module) as virtual modules, so the bundle needs no `node_modules` for them. `protobase serve`, on Node or Bun, resolves them from the `node_modules` next to the bundle, so keep the bundle inside the project. Native packages load from the bundle's own `node_modules/` under both.
439
389
  - **Read-only hosts:** nothing is written: no install (`--no-install`), and for a bundle built with `--bun` no transpiling and so no transpiler cache. A bundle with `node_modules/` needs its folder mounted without `noexec`, since its add-ons are mapped as executable code.
440
390
 
441
391
  ### Mobile releases
442
392
 
443
- With a `mobile` section, the server serves the [mobile app](../guides/mobile-app.md) a newer copy of its files, for its live updater, so the app gets UI changes without a store release. The release is what the server serves the web, composed at startup: every file of `public/`, with the server's own shell where `protobase serve` uses it, and `index.html` naming the API origin, the auth `baseURL` (https, or plain http to `localhost`, `127.0.0.1` or `[::1]`). There is none when the server serves the API alone, has no such `baseURL`, or the bundle names no `native`.
393
+ With a `mobile` section, the server serves the [mobile app](../guides/mobile-app.md) a newer copy of its files, for its live updater, so the app gets UI changes without a store release. The release is what the server serves the web, composed at startup: every file of `public/`, with the server's own shell where `protobase serve` uses it, and `index.html` naming the API origin, the app's `url` (https, or plain http to `localhost`, `127.0.0.1` or `[::1]`). There is none when the server serves the API alone, has no such `url`, or the bundle names no `native`.
444
394
 
445
395
  - `GET /api/mobile/release?fingerprint=<native fingerprint>&shell_version=<x.y.z>` answers `{ "bundleId", "url", "required" }`: the release's id, a hash of its files, and its absolute base URL, both `null` when the release does not run on the asking binary, whose native fingerprint must equal the release's. `required` is true when the shell the app runs no longer works with the server's API: below 1.0 another minor, from 1.0 another major. A missing fingerprint or a shell version that is no x.y.z version gets 400.
446
396
  - `GET /api/mobile/releases/<bundleId>?href=<file>` serves the release's file `<file>`, such as `assets/index-abc123.js`, and with `href=capawesome-live-update-manifest.json` its manifest, a JSON array of `{ "href", "checksum", "sizeInBytes" }`. Each comes with its sha256 in hex in `X-Checksum` and, with `PROTOBASE_MOBILE_SIGNING_KEY`, its signature in `X-Signature`. Any other file, or another release's id, gets 404.
@@ -451,7 +401,7 @@ With a `mobile` section, the server serves the [mobile app](../guides/mobile-app
451
401
  protobase worker <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
452
402
  ```
453
403
 
454
- Runs the bundle's [jobs](jobs.md), and the delivery of its [events](webhooks.md#delivery-and-retries), and nothing else, until SIGTERM or SIGINT, which let running jobs finish for 30 seconds as `serve` does. It checks the bundle's version and the jobs schema at start like `serve`, reads the `.env` nearest the current directory and needs `DATABASE_URL` unless the config exports `db`. Run it beside a `serve` with `PROTOBASE_JOBS=false`, from the same bundle. `protobase worker running <n> jobs` means it is ready.
404
+ Runs the bundle's [jobs](jobs.md), and the delivery of its [events](webhooks.md#delivery-and-retries), and nothing else, until SIGTERM or SIGINT, which let running jobs finish for 30 seconds as `serve` does. It checks the bundle's version and the jobs schema at start like `serve`, reads the `.env` nearest the current directory and needs `DATABASE_URL`. Run it beside a `serve` with `PROTOBASE_JOBS=false`, from the same bundle. `protobase worker running <n> jobs` means it is ready.
455
405
 
456
406
  ## `files cleanup`
457
407
 
@@ -460,7 +410,7 @@ protobase files cleanup # the project in the current directory
460
410
  protobase files cleanup <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
461
411
  ```
462
412
 
463
- Runs the [scheduled file deletes](files.md#deleting-files) that are due: replaced and cleared files past their retention, and uploads nobody saved. A file a row references again is kept. It prints each file it deleted or kept. It reads the `.env` nearest the current directory and needs `DATABASE_URL` unless the config exports `db`. `protobase serve` runs the same every hour; this is for cron, or a host that turns that off.
413
+ Runs the [scheduled file deletes](files.md#deleting-files) that are due: replaced and cleared files past their retention, and uploads nobody saved. A file a row references again is kept. It prints each file it deleted or kept. It reads the `.env` nearest the current directory and needs `DATABASE_URL`. `protobase serve` runs the same every hour; this is for cron, or a host that turns that off.
464
414
 
465
415
  ## `encryption status`
466
416
 
@@ -469,7 +419,7 @@ protobase encryption status # the project in the current directory
469
419
  protobase encryption status <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
470
420
  ```
471
421
 
472
- Reads every [encrypted field](data-config.md#encrypted-fields)'s column and prints its values per key id, the current one marked, its plaintext values, and each value that does not decrypt by record key, with why (`not-encrypted`, `malformed`, `unknown-key`, `failed-authentication`) and never the value. It also prints the history rows and undispatched changes that still hold a field's old values, encrypted values in fields that are not encrypted, and foreign keys `on update cascade` that change a record's key. It writes nothing, so it shows what `apply` would do. It exits with 1 when anything is plaintext, under a previous key, unreadable, misplaced or left in history, so a script can gate on it. It takes the keys from the environment and the `.env` nearest the current directory, like `serve`, and needs `DATABASE_URL` unless the config exports `db`.
422
+ Reads every [encrypted field](data-config.md#encrypted-fields)'s column and prints its values per key id, the current one marked, its plaintext values, and each value that does not decrypt by record key, with why (`not-encrypted`, `malformed`, `unknown-key`, `failed-authentication`) and never the value. It also prints the history rows and undispatched changes that still hold a field's old values, encrypted values in fields that are not encrypted, and foreign keys `on update cascade` that change a record's key. It writes nothing, so it shows what `apply` would do. It exits with 1 when anything is plaintext, under a previous key, unreadable, misplaced or left in history, so a script can gate on it. It takes the keys from the environment and the `.env` nearest the current directory, like `serve`, and needs `DATABASE_URL`.
473
423
 
474
424
  ## `encryption apply`
475
425
 
@@ -505,7 +455,7 @@ protobase users disable <email> # and: enable <email>
505
455
  protobase users delete <email> [--yes]
506
456
  ```
507
457
 
508
- Run inside a project whose `protobase.config.ts` exports `auth` (Better Auth). There is no web setup page, and [open sign-up](auth.md#open-sign-up), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`createAuth({ roles, defaultRole })`). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-provider), finds them whatever address GitHub reports; an id that signs in another user already is refused. `createUser(auth, { ..., accounts: [{ providerId, accountId }] })` does the same from code.
458
+ Run inside a project with sign-in on (its config's `auth`, on unless `false`). There is no web setup page, and [open sign-up](auth.md#open-sign-up), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`auth: { roles, defaultRole }` in its config). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-provider), finds them whatever address GitHub reports; an id that signs in another user already is refused. `createUser(auth, { ..., accounts: [{ providerId, accountId }] })` does the same from code.
509
459
 
510
460
  The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once; it must be 12 to 128 characters, the length the app requires of every new password. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
511
461
 
@@ -532,7 +482,7 @@ For a project with [organizations](auth.md#organizations); `<organization>` is a
532
482
  protobase migration [--dir db/migrations] [--extend <dir>]
533
483
  ```
534
484
 
535
- Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when `protobase.config.ts` exports `auth` (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks()` or `notifications()`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks()` (`NNN_webhooks.sql`), and the [devices and history tables](notifications.md#table-names) of `notifications()` (`NNN_notifications.sql`). It compares the database, with the project's migrations applied, with the config, merged with the configs it extends and those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL` unless the config exports `db`.
485
+ Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks` or `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`), and the [devices and history tables](notifications.md#table-names) of `notifications` (`NNN_notifications.sql`). It compares the database, with the project's migrations applied, with the config (for the auth schema, it reads the store's record of the migrations it applied), merged with those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL`.
536
486
 
537
487
  ```sh
538
488
  bun run db:migrate # the database at the project's current schema
@@ -546,7 +496,7 @@ bun run db:migrate # applies them
546
496
  protobase auth migration [--dir db/migrations] [--name auth]
547
497
  ```
548
498
 
549
- Run inside a project whose `protobase.config.ts` exports `auth`, against its database with the project's migrations applied. It compares the database with the tables, columns and indexes Better Auth needs (with Protobase's plugins and the project's own) and writes what is missing as the next migration in `--dir`: `009_auth.sql` after `008_...`. Nothing is written when the schema is current. The file only adds, never drops, except the OAuth tables of MCP once `mcp` is off; apply it with the project's other migrations. For a store with the camelCase names of Protobase 0.6 it writes their rename to snake_case instead, and the startup check asks for that. See [migrations](auth.md#migrations).
499
+ Run inside a project with sign-in on, against its database with the project's migrations applied. It reads the versions the store applied from its `auth_migrations` table and writes the auth migrations of this Protobase it has not, each followed by its row there, as the next migration in `--dir`: `009_auth.sql` after `008_...`, with the store's schema, user table, columns and id type as the config's `auth` names them. Nothing is written when the store is current. The file only adds, never drops; apply it with the project's other migrations. For a store made before 0.48, without `auth_migrations`, it writes the step that adopts it once, and refuses one that matches no version, naming what differs. See [migrations](auth.md#migrations).
550
500
 
551
501
  ## `import supabase`
552
502
 
@@ -557,10 +507,10 @@ protobase import supabase [<connection> | --source-env <variable>] [--env DATABA
557
507
 
558
508
  Turns a Supabase project's database into the project in the current directory, in two runs with the project's migrations between them. It needs PostgreSQL's `pg_dump` and `psql` on `PATH`, of the Supabase database's major version or newer, and reads the `.env` nearest the current directory for the project's database (`--env`).
559
509
 
560
- 1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email: merge or delete them in Supabase first. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It points the app at `auth.users`: `auth/auth.ts` gets `...supabaseUsers` in its one `createAuth({` call, from the new `auth/supabase-users.ts` (the table, `role` in `app_role`, `raw_user_meta_data` as the metadata, bcrypt hashes and UUID ids; see [an existing users table](auth.md#an-existing-users-table)). It removes the migrations `protobase auth migration` or `protobase migration` wrote for Protobase's own user table, since `auth.users` replaces it, and stops before writing anything when `auth/auth.ts` is missing or calls `createAuth({` other than once, or when the project's database has a schema the dump creates already, such as the `auth` schema those migrations made. The project's database needs the roles `anon`, `authenticated` and `service_role` that the dump's grants and policies name; the command makes them when its role may, and otherwise stops, naming them. The data dump goes to `supabase-import/`, which it adds to `.gitignore`, since it holds every row and the users' password hashes. Where the project's database can create Vault, pgmq and pg_cron, `supabase-import/replay.sql` holds what a dump cannot carry: Vault's secrets with their values, read decrypted since only Supabase's key opens their ciphertext, pgmq's queues with their messages, since pgmq owns their tables, and pg_cron's jobs, which live in its own schema.
510
+ 1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email: merge or delete them in Supabase first. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It points the app at `auth.users`: the `auth` of `protobase.config.ts` gets `users: { table: 'users', columns: { role: 'app_role' }, metadata: 'raw_user_meta_data' }`, `passwordHashes: ['bcrypt']` and `generateUserId: 'uuid'`, or the config gets an `auth` of them when it has none (see [an existing users table](auth.md#an-existing-users-table)). It removes the migrations `protobase auth migration` or `protobase migration` wrote for Protobase's own user table, since `auth.users` replaces it, and stops before writing anything when the project has no `protobase.config.ts`, or one whose `auth` is not an object it can see, or when the project's database has a schema the dump creates already, such as the `auth` schema those migrations made. The project's database needs the roles `anon`, `authenticated` and `service_role` that the dump's grants and policies name; the command makes them when its role may, and otherwise stops, naming them. The data dump goes to `supabase-import/`, which it adds to `.gitignore`, since it holds every row and the users' password hashes. Where the project's database can create Vault, pgmq and pg_cron, `supabase-import/replay.sql` holds what a dump cannot carry: Vault's secrets with their values, read decrypted since only Supabase's key opens their ciphertext, pgmq's queues with their messages, since pgmq owns their tables, and pg_cron's jobs, which live in its own schema.
561
511
  2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
562
- 3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, exports it from `jobs/index.ts` and adds `jobs` to `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
563
- 4. **Apply the migrations** again. Supabase's users then sign in with their own passwords, and with a social provider once it is in `createAuth`'s `socialProviders`; new users get a UUID in `auth.users`, so the app's triggers there run for them.
512
+ 3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
513
+ 4. **Apply the migrations** again. Supabase's users then sign in with their own passwords, and with a social provider once it is in the `socialProviders` of the config's `auth`; new users get a UUID in `auth.users`, so the app's triggers there run for them.
564
514
 
565
515
  5. **Storage's files**: with `--storage-url https://<ref>.supabase.co` and the project's secret key in the variable `--storage-key-env` names, `SUPABASE_SERVICE_ROLE_KEY` by default, the second run, or any run after it, copies the bytes of every object in `storage.objects` from the Supabase project's Storage API into the app's [Storage file provider](supabase-storage.md#where-things-are-kept), where [`/api/sb/storage/v1`](supabase-storage.md) serves them, with the type and cache control the rows recorded. It streams each object, checks its byte count against the size Supabase recorded and its MD5 against the ETag where that is one, and deletes a copy that does not match. It first prints each bucket's size and stops when what is left to copy and what the provider holds exceed the provider's `max_bytes`, unless `--yes`. An object that fails does not stop the rest; the run then fails, listing them in `supabase-import/storage.md`, and a rerun copies only what the provider does not hold yet. The key goes only in the requests' headers, never in a file.
566
516
 
@@ -580,7 +530,7 @@ protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [-
580
530
  Builds the project in the current directory as an iOS or Android app with Capacitor, from the `mobile` section of its `protobase.config.ts`; without one it stops and says what to add. See [A mobile app](../guides/mobile-app.md).
581
531
 
582
532
  - It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed, and on every run for a package from a local folder, given as `file:` or a path such as `../my-plugin`, which npm copies. When such a folder's dependencies are not the versions installed, it removes the workspace's `node_modules` and `package-lock.json` so npm resolves them again, and stops when a pin is still not met, as when two packages pin one dependency at different versions. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
583
- - `--api` is the server the app calls, the project's auth `baseURL` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
533
+ - `--api` is the server the app calls, the app's `url` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
584
534
  - `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
585
535
  - `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS runs Capacitor's build with `--team`, and `--certificate` with `--profile` for manual signing.
586
536
  - A release calls an https server that is not this machine, and `--app-version` (one to three numbers) and `--build-number` (1 to 2100000000) are required.
@@ -32,14 +32,6 @@ export const ticketsView = view<typeof tickets>('tickets')
32
32
  ])
33
33
  ```
34
34
 
35
- ```ts title="protobase.config.ts"
36
- import { defineConfig } from '@protobase/server'
37
- import * as config from './tickets'
38
-
39
- // Mentions are emailed by the app's workers, to the users of its Better Auth (`auth`, left out here).
40
- export default defineConfig({ config })
41
- ```
42
-
43
35
  ## On the record page
44
36
 
45
37
  [`l.comments(title?, { when })`](https://docs.protobase.net/api/schema/variables/l/#comments) shows the record's comments oldest first, the newest just above the box to write one; Show earlier comments loads those before. ⌘/Ctrl+Enter or the Comment button posts. A view without a layout shows Comments last by itself. A view that names `l.comments()` for a resource without `.comments()` stops startup. A visitor who is not signed in sees the comments but no box.
@@ -0,0 +1,152 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # protobase.config.ts
4
+
5
+ The project's config as one object of data, the files where Protobase finds the project's code, the defaults, the JSON form and every key.
6
+
7
+ `protobase.config.ts`, in the project's root, describes the whole app as one object of data: its address and secret, sign-in, the jobs, the file providers and the API's settings. It default-exports `defineConfig(...)` from `@protobase/config`, which types every key and returns its argument as it is. Every key is optional; Protobase has a default for each.
8
+
9
+ ```ts
10
+ // protobase.config.ts
11
+ import { defineConfig } from '@protobase/config'
12
+
13
+ export default defineConfig({
14
+ timezone: 'Europe/Amsterdam',
15
+ auth: { roles: ['admin', 'sales'], organizations: true },
16
+ jobs: {
17
+ 'send-invoice': { description: 'Mails an invoice to its customer.', arguments: { invoiceId: 'bigint' }, maxAttempts: 5 },
18
+ },
19
+ writeHooks: ['queue-sent-invoice'],
20
+ })
21
+ ```
22
+
23
+ The config names things; it never holds or imports their code. Protobase finds the code by its path, so the job above runs `jobs/send-invoice.ts` and the write hook is `hooks/queue-sent-invoice.ts`. A project without a config file is a config of defaults.
24
+
25
+ ## Where the code is
26
+
27
+ Each file below is loaded only when the app needs it, never while the config is read.
28
+
29
+ | File | What it holds | Used for |
30
+ | --- | --- | --- |
31
+ | `config/index.ts`, `config/<dir>/ui.ts` | the resources, views and pages, as exports | [Data config](data-config.md) |
32
+ | `config/roles.ts` | the `roles` export, made with `defineRoles` | [Access](access.md) |
33
+ | `functions/<name>.ts` | an API function, as its default export | [API functions](../guides/api-functions.md) |
34
+ | `jobs/<name>.ts` | what the job `<name>` of `jobs` does, as its default export (`JobRun`) | [Jobs](jobs.md) |
35
+ | `hooks/<name>.ts` | a write hook named in `writeHooks`, as its default export | [Jobs](jobs.md#enqueueing) |
36
+ | `hooks/error.ts` | called with every error the API answers `500` for, and the request (`onUnhandledError`) | [REST API](api.md#errors) |
37
+ | `auth/hooks.ts` | sign-in's hooks, as named exports: `generateUserId`, `onUserCreated`, the organization hooks | [Login](auth.md#hooks) |
38
+ | `auth/mailer.ts` | a mailer of the app's own for sign-in mail, as its default export | [Email](email.md) |
39
+ | `auth/authenticate.ts` | an `Authenticator` of the app's own, such as `jwtAuthenticator(...)`, in place of `authenticate` | [Tokens and roles](auth.md#tokens-and-roles) |
40
+ | `assistant/tools.ts` | the assistant's own tools, an array of `defineTool(...)` | [Assistant](assistant.md) |
41
+ | `audit/queue.ts` | the `AuditQueue` reveals of sensitive fields publish to | [REST API](api.md#sensitive-fields-and-audit) |
42
+ | `files/<name>.ts` | the file provider `<name>`, declared `{ kind: 'custom' }` in `files.providers` | [Files](files.md) |
43
+ | `webhooks/owner-roles.ts` | the roles a webhook subscription's owner holds, when the app signs people in another way | [Webhooks](webhooks.md) |
44
+ | `notifications/store.ts`, `notifications/history-store.ts`, `notifications/senders.ts` | a device store, a history store and push senders in place of the built-in ones | [Notifications](notifications.md) |
45
+ | `emails/` | the templates of sign-in's mail | [Email](email.md#templates) |
46
+
47
+ Hooks of the project's own get the app's database, `{ db }` (Kysely, as jobs get it), as their last argument. A job named in the config without its `jobs/<name>.ts`, or a write hook without its `hooks/<name>.ts`, stops the app at start with an error that names the file.
48
+
49
+ ## Defaults
50
+
51
+ | Key | Default |
52
+ | --- | --- |
53
+ | `url` | `PROTOBASE_URL`; in `protobase dev`, the dev server's own address |
54
+ | `secret` | `PROTOBASE_SECRET` |
55
+ | `name` | `Protobase`; `PROTOBASE_APP_NAME` overrides it |
56
+ | `auth` | on, with its own defaults; `false` turns it off, as does an `authenticate.jwksUrl` that trusts an auth server elsewhere |
57
+ | `auth.trustedOrigins` | `PROTOBASE_TRUSTED_ORIGINS`, comma separated |
58
+ | `timezone` | `UTC` |
59
+ | `apiPath` | `/api/v1` |
60
+
61
+ The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONNECTIONS`. With sign-in on, `protobase dev`, `serve` and the commands that sign people in stop with a clear message when the URL or the secret is missing.
62
+
63
+ ## A config, or a function
64
+
65
+ `defineConfig` takes a config, or a function, plain or async, that returns one. The function gets:
66
+
67
+ | | |
68
+ | --- | --- |
69
+ | `command` | `dev`, `build`, `serve` (also `protobase worker` and the serve runtime's `migrate` and `create-admin`), or `tool`, any other command over the project, such as `migration`, `users` or `encryption` |
70
+ | `env` | `process.env`, with the project's `.env` loaded |
71
+ | `root` | the project's folder |
72
+
73
+ ```ts
74
+ export default defineConfig(({ command, env }) => ({
75
+ auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined },
76
+ errorReporting: command === 'dev' ? false : undefined,
77
+ }))
78
+ ```
79
+
80
+ A config may branch on them, read files of its own with Node's `fs`, and import values from other files, such as a list of map layers, as any module can. Secrets are values like any other, read from the environment. `protobase serve` reads a bundle's config again where it runs, with that environment, so a bundle built once serves with each host's own variables.
81
+
82
+ ## Reading it
83
+
84
+ Every command reads the config, in a few milliseconds: reading it runs the config's file and what that file imports, and none of the files above. A config may not load part of itself later: an `import()` in `protobase.config.ts` stops every command with an error that names it. Code belongs in the files above.
85
+
86
+ ## The same config as JSON
87
+
88
+ `protobase.config.json` holds the same object as JSON. A value read from the environment is written `{ "$env": "NAME" }`, with `"default"` for when the variable is unset or empty, and `"split": ","` for a list of its non-empty parts:
89
+
90
+ ```json
91
+ {
92
+ "url": { "$env": "PROTOBASE_URL", "default": "http://localhost:5173" },
93
+ "timezone": "Europe/Amsterdam",
94
+ "auth": { "roles": ["admin", "sales"], "trustedOrigins": { "$env": "TUNNEL_URLS", "split": "," } },
95
+ "jobs": { "send-invoice": { "arguments": { "invoiceId": "bigint" }, "maxAttempts": 5 } },
96
+ "writeHooks": ["queue-sent-invoice"]
97
+ }
98
+ ```
99
+
100
+ A TypeScript config may use `$env` values too. A project has one config file: one with both `protobase.config.ts` and `protobase.config.json` stops every command with an error that names both.
101
+
102
+ JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. There is no JSON Schema for the file yet, so a JSON config is checked when the app starts rather than in the editor.
103
+
104
+ ## Keys
105
+
106
+ | Key | What | See |
107
+ | --- | --- | --- |
108
+ | `name`, `url`, `secret` | the app's name, public URL and secret, which sign-in, mail and signed links use | [Login](auth.md#configuration) |
109
+ | `locale`, `timezone` | the admin app's language for every user, and the time zone of the jobs' schedules | [Languages](languages.md), [Jobs](jobs.md#recurring-jobs) |
110
+ | `themeColor`, `backgroundColor` | the installed app's colours | [App identity](app-identity.md) |
111
+ | `auth` | sign-in: roles, organizations, sign-up, providers, passkeys, MCP clients; `false` turns it off | [Login](auth.md#configuration) |
112
+ | `authenticate` | how the API verifies tokens: `{ tenant }`, `{ jwksUrl, issuer }` for an auth server elsewhere, or `apps` whose tokens it admits; default the tokens of `auth` | [Tokens and roles](auth.md#tokens-and-roles) |
113
+ | `jobs` | the jobs by name: `description`, `arguments`, `schedule` and the run options | [Jobs](jobs.md) |
114
+ | `writeHooks` | the write hooks by name, run in this order in each write's transaction | [Jobs](jobs.md#enqueueing) |
115
+ | `files` | providers by name (`{ kind: 'local', dir }`, `{ kind: 's3', bucket }` or `{ kind: 'custom' }`), `retention`, `trustedHosts` and `images: 'sharp'` | [Files](files.md) |
116
+ | `events`, `history` | where changes are captured, and how long history is kept | [Events](events.md), [History](history.md) |
117
+ | `webhooks` | webhook subscriptions made in the app; `{}` turns them on | [Webhooks](webhooks.md) |
118
+ | `notifications` | each user's devices and inbox; `{}` turns them on | [Notifications](notifications.md) |
119
+ | `mobile` | the iOS and Android build | [Mobile app](../guides/mobile-app.md) |
120
+ | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting` | the REST API's settings | [REST API](api.md) |
121
+ | `assistant` | the assistant's model and limits; `false` turns it off | [Assistant](assistant.md) |
122
+ | `mcpEndpoint` | the MCP endpoint's tools, or `false` | [MCP](mcp.md) |
123
+ | `maps`, `plugins` | the maps' layers, and the admin app's plugins | [UI config](ui-config.md), [Plugins](plugins.md) |
124
+ | `remoteResources`, `runtimeUpdates` | other Protobase APIs whose resources the app draws, and the runtime's update endpoint | [Remote resources](remote-resources.md), [Versioning](versioning.md) |
125
+
126
+ ## Extensions
127
+
128
+ `protobase dev --extend <dir>` and `protobase build --extend <dir>` merge an extension's folder into the app, before the project. The extension's folder has a config and code of its own, found by the same paths in that folder. A config cannot extend another itself.
129
+
130
+ ```tsx
131
+ // protobase.ui.tsx
132
+ import { defineUi } from '@protobase/ui'
133
+ import * as tasksUi from 'some-extension/protobase.ui'
134
+
135
+ export default defineUi({ extends: [tasksUi] })
136
+ ```
137
+
138
+ | What | How it merges | The same name twice |
139
+ | --- | --- | --- |
140
+ | resources, views and pages of `config/` | all kept | an error naming both folders |
141
+ | user menu | at most one among all folders | an error |
142
+ | assistant tools of `assistant/tools.ts` | the extensions' first, in order, then the app's | an error naming the tool and both folders |
143
+ | `jobs`, functions, file providers | all kept, by name | an error naming the name and both folders |
144
+ | `writeHooks` | all run, in the same order | |
145
+ | `config/roles.ts`, `auth/authenticate.ts`, `audit/queue.ts`, `hooks/error.ts`, `webhooks/owner-roles.ts`, `notifications/*.ts` | the app's own; otherwise the last extension's | |
146
+ | `auth/hooks.ts`, `auth/mailer.ts` | those of the last folder whose config sets `auth`; otherwise the app's | |
147
+ | every other key (`auth`, `authenticate`, `assistant`, ...) | the app's own; otherwise the last config that sets it | |
148
+ | UI components (exported by name or in `components`), `actions` | all kept | an error naming the name and both configs |
149
+ | UI `shell.actions`, `shell.rightPanel` | all drawn, the extended configs' first | |
150
+ | UI `shell.logo` | the app's own; otherwise the last config that sets it | |
151
+
152
+ Errors name an extension by its folder. Nothing is namespaced, so a collision is always an error, never a silent override. Names starting with `Protobase` (components) and `protobase_` (tools) belong to Protobase's own extensions, such as `ProtobaseCloudTask` and `protobase_cloud_create_proposal`; give yours other names.