@protobase/cli 0.48.0 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/config-bundle.js +6 -1
- package/dist/build/entry-code.js +30 -17
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +73 -0
- package/dist/config/called-config.js +11 -0
- package/dist/config/config-defaults.js +33 -0
- package/dist/config/env-values.js +20 -0
- package/dist/config/lazy-imports.js +18 -0
- package/dist/config/merge-config.js +72 -0
- package/dist/config/project-files.js +48 -0
- package/dist/config/project-parts.js +201 -0
- package/dist/config/read-config.js +31 -0
- package/dist/config/source-config.js +37 -0
- package/dist/dev/create-db.js +2 -2
- package/dist/dev/entry.js +9 -10
- package/dist/dev/project.js +23 -47
- package/dist/main.js +3 -3
- package/dist/migration/load-project.js +34 -34
- package/dist/migration/parts.js +2 -2
- package/dist/migration/summary.js +2 -2
- package/dist/mobile/api-origin.js +4 -4
- package/dist/mobile/load-project.js +13 -12
- package/dist/mobile/register.js +1 -1
- package/dist/mobile/run.js +1 -1
- package/dist/organizations/register.js +1 -1
- package/dist/project/error-reporter.js +3 -3
- package/dist/project/import-project-file.js +4 -2
- package/dist/project/load-bundle-project.js +16 -25
- package/dist/project/load-data-config.js +1 -1
- package/dist/project/pg-db.js +10 -4
- package/dist/project/placeholder-secret.js +2 -2
- package/dist/project/project-admin.js +12 -11
- package/dist/serve/create-admin.js +9 -4
- package/dist/serve/host-module-ids.js +1 -0
- package/dist/serve/host-modules.js +3 -1
- package/dist/serve/lifecycle.js +17 -13
- package/dist/serve/load-bundle.js +41 -11
- package/dist/serve/mobile-release.js +1 -1
- package/dist/serve/serve-bundle.js +3 -3
- package/dist/supabase/auth-config.js +33 -28
- package/dist/supabase/config-jobs.js +28 -27
- package/dist/supabase/config-object.js +25 -0
- package/dist/supabase/cron-job-file.js +13 -14
- package/dist/supabase/cron-jobs-write.js +6 -12
- package/dist/supabase/cron-plan.js +3 -51
- package/dist/supabase/project-files.js +4 -9
- package/dist/supabase/report.js +3 -3
- package/dist/users/load-auth.js +16 -15
- package/dist/worker/start-worker.js +18 -15
- package/package.json +8 -6
- package/skills/protobase/SKILL.md +8 -1
- package/skills/protobase/references/features/notifications.md +1 -1
- package/skills/protobase/references/features/sign-in-and-accounts.md +2 -0
- package/skills/protobase/references/features/start-a-project.md +9 -0
- package/skills/protobase/references/getting-started.md +14 -14
- package/skills/protobase/references/guides/api-functions.md +4 -4
- package/skills/protobase/references/guides/deploy.md +8 -8
- package/skills/protobase/references/guides/existing-database.md +11 -31
- package/skills/protobase/references/guides/export-a-list.md +1 -1
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-composed-page.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +2 -2
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +5 -3
- package/skills/protobase/references/guides/personal-setting.md +1 -1
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/guides/push-notifications.md +7 -8
- package/skills/protobase/references/guides/record-card.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +23 -32
- package/skills/protobase/references/guides/theme-an-app.md +1 -1
- package/skills/protobase/references/reference/access.md +3 -3
- package/skills/protobase/references/reference/ai.md +1 -9
- package/skills/protobase/references/reference/api.md +16 -16
- package/skills/protobase/references/reference/app-identity.md +9 -10
- package/skills/protobase/references/reference/architecture.md +4 -4
- package/skills/protobase/references/reference/assistant.md +6 -6
- package/skills/protobase/references/reference/auth.md +139 -86
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +2 -2
- package/skills/protobase/references/reference/cli.md +42 -92
- package/skills/protobase/references/reference/client.md +2 -2
- package/skills/protobase/references/reference/comments.md +0 -8
- package/skills/protobase/references/reference/config/admin-app.md +62 -0
- package/skills/protobase/references/reference/config/api.md +164 -0
- package/skills/protobase/references/reference/config/app.md +112 -0
- package/skills/protobase/references/reference/config/files.md +99 -0
- package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
- package/skills/protobase/references/reference/config/sign-in.md +396 -0
- package/skills/protobase/references/reference/config.md +170 -0
- package/skills/protobase/references/reference/custom-components.md +2 -2
- package/skills/protobase/references/reference/data-config.md +4 -4
- package/skills/protobase/references/reference/email.md +36 -37
- package/skills/protobase/references/reference/events.md +1 -1
- package/skills/protobase/references/reference/files.md +18 -23
- package/skills/protobase/references/reference/forms.md +5 -17
- package/skills/protobase/references/reference/history.md +2 -3
- package/skills/protobase/references/reference/installable-app.md +1 -1
- package/skills/protobase/references/reference/jobs.md +53 -56
- package/skills/protobase/references/reference/languages.md +4 -2
- package/skills/protobase/references/reference/mcp.md +10 -10
- package/skills/protobase/references/reference/notifications.md +26 -24
- package/skills/protobase/references/reference/plugins.md +11 -14
- package/skills/protobase/references/reference/remote-resources.md +18 -24
- package/skills/protobase/references/reference/sidebar.md +2 -2
- package/skills/protobase/references/reference/supabase-realtime.md +1 -1
- package/skills/protobase/references/reference/supabase-rest.md +1 -1
- package/skills/protobase/references/reference/supabase-storage.md +1 -1
- package/skills/protobase/references/reference/ui-config.md +20 -22
- package/skills/protobase/references/reference/user-menu.md +1 -1
- package/skills/protobase/references/reference/versioning.md +1 -1
- package/skills/protobase/references/reference/webhooks.md +6 -7
|
@@ -9,7 +9,7 @@ On phones the sidebar is a drawer behind the top bar's menu button. For people w
|
|
|
9
9
|
Export a [`bottomBar(...)`](https://docs.protobase.net/api/schema/functions/bottombar/) from the config module for each group of roles that gets one:
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
//
|
|
12
|
+
// tests/apps/erp/config/bottom-bar.ts, re-exported from config/index.ts
|
|
13
13
|
import { bottomBar } from '@protobase/schema'
|
|
14
14
|
|
|
15
15
|
export const warehouseBar = bottomBar({ label: 'Warehouse', roles: ['warehouse'] }, (m) => [
|
|
@@ -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 [`
|
|
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
|
|
|
@@ -9,7 +9,7 @@ The `protobase` command comes with `@protobase/cli`. Install it in a project nex
|
|
|
9
9
|
```sh
|
|
10
10
|
bun add @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui
|
|
11
11
|
bun run protobase <command> # from the project, config folder defaults to ./config
|
|
12
|
-
bun run --cwd
|
|
12
|
+
bun run --cwd tests/apps/erp protobase <command> # in this repository, for an example
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does. `protobase --version` (or `-v`) prints the Protobase version. Before any command runs, the CLI checks that the project in the current directory, by the `@protobase` packages installed there, is of its own major version, and stops with an error naming both versions when it is not: within a major a CLI runs every project, whatever its minor. That is the CLI's one version check. Outside a project, or before its install, there is nothing to check.
|
|
@@ -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
|
|
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
|
|
|
@@ -120,81 +120,35 @@ Exit code is 1 when there are errors. Run it after the project's migrations and
|
|
|
120
120
|
## `dev`
|
|
121
121
|
|
|
122
122
|
```sh
|
|
123
|
-
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd
|
|
123
|
+
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd tests/apps/erp dev
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and hands `/api`, supabase-js's `/api/sb` included, to the Hono app from `createAdmin`, which runs in a process of its own; the CLI's process never loads `@protobase/server`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
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 `
|
|
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`
|
|
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>`.
|
|
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
|
|
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
|
-
|
|
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
|
|
|
196
150
|
```sh
|
|
197
|
-
protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd
|
|
151
|
+
protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd tests/apps/erp protobase build
|
|
198
152
|
```
|
|
199
153
|
|
|
200
154
|
Writes the project's deploy bundle, the folder a deployment ships:
|
|
@@ -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
|
|
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
|
|
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.
|
|
234
|
-
- An error names
|
|
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 `
|
|
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
|
|
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
|
-
-
|
|
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
|
|
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 `
|
|
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
|
|
|
@@ -392,7 +342,7 @@ bun --no-install protobase-serve.js create-admin <bundle> <email> # --generat
|
|
|
392
342
|
```sh
|
|
393
343
|
bun --no-install protobase-serve.js <bundle>/protobase.config.js # production, under Bun: the API
|
|
394
344
|
protobase serve <bundle>/protobase.config.js # the same, with the CLI on Node or Bun
|
|
395
|
-
protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd
|
|
345
|
+
protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd tests/apps/erp serve
|
|
396
346
|
```
|
|
397
347
|
|
|
398
348
|
Serves the API of a bundle from `protobase build` and owns the process around it. Given the bundle folder, `protobase serve` also serves its UI by [the manifest's rules](#the-manifest), so a bundle can be checked locally exactly as the host will serve it.
|
|
@@ -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)
|
|
405
|
-
| `PROTOBASE_DB_CONNECTIONS` | the connections that pool opens, such as the database's limit for the app; default 10.
|
|
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 [`
|
|
360
|
+
| `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config/app.md#name) |
|
|
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 `
|
|
418
|
-
| `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after `
|
|
419
|
-
| `PROTOBASE_SOURCES` | other Protobase APIs whose resources the app draws as its own, a JSON list of `{ "url", "label", "resources", "roles"? }` after `
|
|
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
|
-
|
|
380
|
+
The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [App options](config/app.md)); its other settings are the project's own variables, read by its config, which the runtime reads again at start with the host's environment. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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.
|
|
@@ -611,10 +561,10 @@ Copies the agent skills of this CLI's version into the current project, or only
|
|
|
611
561
|
## ERP example
|
|
612
562
|
|
|
613
563
|
```sh
|
|
614
|
-
bun run db:up && bun run --cwd
|
|
615
|
-
bun run --cwd
|
|
564
|
+
bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small
|
|
565
|
+
bun run --cwd tests/apps/erp protobase scaffold postgres://protobase:protobase@localhost:55432/protobase \
|
|
616
566
|
--yes --ui --exclude auth --exclude public.schema_migrations --exclude public.seed_info
|
|
617
|
-
bun run --cwd
|
|
567
|
+
bun run --cwd tests/apps/erp protobase doctor postgres://protobase:protobase@localhost:55432/protobase
|
|
618
568
|
```
|
|
619
569
|
|
|
620
570
|
Always pass `--exclude auth`: the ERP keeps Better Auth's users, sessions and signing keys in the `auth` schema of the same database, and scaffolding them would expose credentials through the admin API.
|
|
@@ -23,7 +23,7 @@ With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/
|
|
|
23
23
|
|
|
24
24
|
## The admin app
|
|
25
25
|
|
|
26
|
-
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `
|
|
26
|
+
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `tests/apps/*/config/*/ui.ts`. The sidebar's recent-record groups and the user menu are configured there too: see [Sidebar](sidebar.md), [User menu](user-menu.md) and [Bottom bar](bottom-bar.md).
|
|
27
27
|
|
|
28
28
|
## Global search
|
|
29
29
|
|
|
@@ -35,4 +35,4 @@ Each result is a link: a click or Enter opens it and closes the list, Enter the
|
|
|
35
35
|
|
|
36
36
|
## Live stories
|
|
37
37
|
|
|
38
|
-
`bun run db:up && bun run --cwd
|
|
38
|
+
`bun run db:up && bun run --cwd tests/apps/erp serve`, then `bun run storybook`. Storybook proxies `/api` to `PROTOBASE_API` (default `http://localhost:8787`); pick another API in the toolbar. Without a server the stories say so. `bun run screenshots:live` writes `screenshots/live/`.
|
|
@@ -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,62 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config/admin-app.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Admin app options
|
|
4
|
+
|
|
5
|
+
The config keys of what the admin app draws besides the resources, the assistant, the maps and the plugins, with their types, defaults and environment variables, and the file of the assistant's own tools.
|
|
6
|
+
|
|
7
|
+
The keys of what the admin app draws besides the resources, at the top level of [`protobase.config.ts`](../config.md). The app's language is [`locale`](app.md#locale).
|
|
8
|
+
|
|
9
|
+
## assistant
|
|
10
|
+
|
|
11
|
+
- **Type:** `{ url?: string; apiKey?: string; model?: string; baseUrl?: string; chats?: string } | false`
|
|
12
|
+
- **Default:** the backend of `PROTOBASE_ASSISTANT_URL`; otherwise the built-in one, when `PROTOBASE_ASSISTANT_API_KEY` is set; otherwise none
|
|
13
|
+
- **Environment variables:** `PROTOBASE_ASSISTANT_URL`, `PROTOBASE_ASSISTANT_API_KEY`, `PROTOBASE_ASSISTANT_MODEL`, `PROTOBASE_ASSISTANT_BASE_URL`, `PROTOBASE_ASSISTANT_CHATS`
|
|
14
|
+
|
|
15
|
+
The assistant in the admin app's dock, which admins and the `ai` role see. Each key falls back to its variable:
|
|
16
|
+
|
|
17
|
+
- `url`: an assistant backend elsewhere, which the dock talks to instead of the built-in one.
|
|
18
|
+
- `apiKey`: turns on the built-in assistant, which answers with a chat model.
|
|
19
|
+
- `baseUrl`: the model's OpenAI-compatible endpoint; default OpenRouter's, `https://openrouter.ai/api/v1`.
|
|
20
|
+
- `model`: the model; default `openrouter/auto` with OpenRouter, and required with any other endpoint.
|
|
21
|
+
- `chats`: the folder the built-in assistant keeps conversations in, one file each; default `.protobase/chats`.
|
|
22
|
+
|
|
23
|
+
`false` turns the assistant off. A value that cannot work stops the app at start. See [Assistant](../assistant.md#which-backend).
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export default defineConfig(({ env }) => ({
|
|
27
|
+
assistant: { apiKey: env.OPENROUTER_API_KEY, model: 'anthropic/claude-sonnet-5.5' },
|
|
28
|
+
}))
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The built-in assistant's own tools are the default export of `assistant/tools.ts`, an array of `defineTool(...)`, offered after its own; with [extensions](../config.md#extensions), the extensions' come first. See [The app's own tools](../assistant.md#the-apps-own-tools).
|
|
32
|
+
|
|
33
|
+
## maps
|
|
34
|
+
|
|
35
|
+
- **Type:** `{ style?: string; layers?: { id: string; label: string; tiles: string; attribution: string; bounds?: [number, number, number, number]; maxzoom?: number }[] } | false`
|
|
36
|
+
- **Default:** the style of `PROTOBASE_MAP_STYLE_URL`, when set
|
|
37
|
+
- **Environment variable:** `PROTOBASE_MAP_STYLE_URL`
|
|
38
|
+
|
|
39
|
+
The map style the app's maps (`l.map`, `d.map`) are drawn with, and the layers they may switch to. `style` is the URL of a MapLibre style, such as one of self-hosted PMTiles. Each of `layers` is another map of raster tiles, such as aerial photos: `tiles` is its tile URL with `{z}`, `{x}` and `{y}`, `attribution` the credit its licence asks for, `bounds` where its tiles are (`[west, south, east, north]`), and `maxzoom` the deepest zoom they go to (default 22). Without a style, or with `false`, the app draws no maps. See [Map layers](../ui-config.md#map-layers).
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
maps: {
|
|
44
|
+
style: 'https://tiles.example.com/style.json',
|
|
45
|
+
layers: [{ id: 'aerial', label: 'Aerial', tiles: 'https://tiles.example.com/aerial/{z}/{x}/{y}.jpg', attribution: '© Example' }],
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## plugins
|
|
51
|
+
|
|
52
|
+
- **Type:** `{ url: string; settings?: Record<string, JsonValue>; roles?: string[]; beforeSignIn?: boolean }[] | false`
|
|
53
|
+
- **Default:** none, and those the environment variables list
|
|
54
|
+
- **Environment variables:** `PROTOBASE_PLUGINS` and `PROTOBASE_PLUGINS_BEFORE_SIGN_IN`, plugin.json URLs separated by commas, loaded after the config's
|
|
55
|
+
|
|
56
|
+
The plugins the admin app loads at runtime. `url` names a plugin's `plugin.json`, on another origin or this one (`/plugins/...`); the plugin reads `settings` with `usePlugin()`; with `roles`, only callers holding one of them load it; with `beforeSignIn`, the app loads it before anyone signs in, which cannot go with `roles`. `false` turns off all but the plugins the app's own bundle carries. See [Loading](../plugins.md#loading).
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
export default defineConfig({
|
|
60
|
+
plugins: [{ url: 'https://plugins.example.com/maps/plugin.json', settings: { zoom: 12 }, roles: ['admin'] }],
|
|
61
|
+
})
|
|
62
|
+
```
|