@protobase/cli 0.40.7 → 0.40.9
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/cli/package.js +1 -1
- package/package.json +6 -6
- package/skills/protobase/references/getting-started.md +8 -8
- package/skills/protobase/references/guides/api-functions.md +12 -12
- package/skills/protobase/references/guides/billing-page.md +2 -2
- package/skills/protobase/references/guides/create-page.md +5 -5
- package/skills/protobase/references/guides/deploy.md +6 -6
- package/skills/protobase/references/guides/export-a-list.md +2 -2
- package/skills/protobase/references/guides/field-type.md +2 -2
- package/skills/protobase/references/guides/first-composed-page.md +4 -4
- package/skills/protobase/references/guides/first-plugin.md +3 -3
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +11 -4
- package/skills/protobase/references/guides/plugin-build.md +5 -5
- package/skills/protobase/references/guides/record-card.md +3 -3
- package/skills/protobase/references/guides/remote-resources.md +10 -10
- package/skills/protobase/references/guides/table-to-admin.md +5 -5
- package/skills/protobase/references/guides/theme-an-app.md +4 -4
- package/skills/protobase/references/reference/access.md +9 -9
- package/skills/protobase/references/reference/ai.md +6 -6
- package/skills/protobase/references/reference/api.md +25 -25
- package/skills/protobase/references/reference/app-identity.md +4 -4
- package/skills/protobase/references/reference/architecture.md +1 -1
- package/skills/protobase/references/reference/assistant.md +6 -6
- package/skills/protobase/references/reference/auth.md +20 -20
- package/skills/protobase/references/reference/blocks.md +18 -13
- package/skills/protobase/references/reference/bottom-bar.md +5 -5
- package/skills/protobase/references/reference/cli.md +63 -63
- package/skills/protobase/references/reference/client.md +5 -5
- package/skills/protobase/references/reference/comments.md +8 -8
- package/skills/protobase/references/reference/custom-components.md +18 -18
- package/skills/protobase/references/reference/data-config.md +26 -26
- package/skills/protobase/references/reference/email.md +8 -8
- package/skills/protobase/references/reference/events.md +5 -5
- package/skills/protobase/references/reference/files.md +7 -7
- package/skills/protobase/references/reference/forms.md +6 -6
- package/skills/protobase/references/reference/history.md +7 -7
- package/skills/protobase/references/reference/installable-app.md +1 -1
- package/skills/protobase/references/reference/jobs.md +5 -5
- package/skills/protobase/references/reference/layouts.md +11 -11
- package/skills/protobase/references/reference/live.md +4 -4
- package/skills/protobase/references/reference/mcp.md +5 -5
- package/skills/protobase/references/reference/plugins.md +20 -20
- package/skills/protobase/references/reference/remote-resources.md +15 -15
- package/skills/protobase/references/reference/sidebar.md +1 -1
- package/skills/protobase/references/reference/supabase-realtime.md +2 -2
- package/skills/protobase/references/reference/supabase-rest.md +2 -2
- package/skills/protobase/references/reference/supabase-storage.md +1 -1
- package/skills/protobase/references/reference/theme.md +5 -5
- package/skills/protobase/references/reference/ui-config.md +60 -60
- package/skills/protobase/references/reference/user-menu.md +3 -3
- package/skills/protobase/references/reference/versioning.md +5 -5
- package/skills/protobase/references/reference/webhooks.md +7 -7
|
@@ -58,7 +58,7 @@ Interactively, each new column shows its proposal: accept, edit (name, type) or
|
|
|
58
58
|
- `NOT NULL` absent: `.optional()`. Literal default: `.default(v)`.
|
|
59
59
|
- Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
|
|
60
60
|
- Leading column of a non-partial index: `.filterable()`; of a btree: also `.sortable()`. Not applied to json.
|
|
61
|
-
- The text field that names a record (`name`, `title`, `number`, `sku`, `email`, `code` or `description`, else the first text field) becomes the resource's `.search(...)` when a non-partial pg_trgm index (`gin_trgm_ops` or `gist_trgm_ops`) serves it, so the [global search](client.md#global-search)
|
|
61
|
+
- The text field that names a record (`name`, `title`, `number`, `sku`, `email`, `code` or `description`, else the first text field) becomes the resource's `.search(...)` when a non-partial pg_trgm index (`gin_trgm_ops` or `gist_trgm_ops`) serves it, so the [global search](client.md#global-search) finds its records by name. Without one the API would refuse the search, so it is left out; add the index and run `protobase scaffold` on a new resource, or add `.search` by hand.
|
|
62
62
|
- Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning.
|
|
63
63
|
- `deleted_at`, `removed_at`, `archived_at` (nullable timestamp/date) become `.softDelete`; `organization_id` and `tenant_id` become `.tenant`.
|
|
64
64
|
- Unique indexes are listed in the doc comment above the resource.
|
|
@@ -82,7 +82,7 @@ protobase doctor <connection string | --env VAR> [--config <dir>]
|
|
|
82
82
|
Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database:
|
|
83
83
|
|
|
84
84
|
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index
|
|
85
|
-
- error: a read the [scan guard](api.md#safety)
|
|
85
|
+
- error: a read the [scan guard](api.md#safety) refuses, because no index serves a column it filters, sorts, searches or counts by. Doctor reads each table's indexes from the catalog, as the server does, and judges with the scan guard's own rule every read the API takes and the app makes: a filter on each `.filterable()` field, a sort by each `.sortable()` one, `search()` over the search fields, a role's own records (`.owner()`) and the names a relation shows; each view's list in its order, its filter widgets and their counts, its map and card photos, its related sections, its recent records and a saved search's new records; and each block of a [composed page](layouts.md) that lists records. Each error is an index to add, with every request that needs it and where it comes from:
|
|
86
86
|
|
|
87
87
|
```
|
|
88
88
|
error agencies: no index serves the column "name", so the API refuses:
|
|
@@ -105,10 +105,10 @@ One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app
|
|
|
105
105
|
|
|
106
106
|
- **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 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`.
|
|
107
107
|
- **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).
|
|
108
|
-
- **Login:** real sign-in only, with the `authenticate` and `auth` exported by `protobase.config.ts` (see [Login with Better Auth](auth.md))
|
|
109
|
-
- **Jobs:** with [jobs](jobs.md)
|
|
108
|
+
- **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. Create the first admin with `protobase users create`.
|
|
109
|
+
- **Jobs:** with [jobs](jobs.md) in the config it runs them in its process, once the jobs schema checks out (see [`migration`](#migration)); an edited job runs its new code from the next job on.
|
|
110
110
|
- **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.
|
|
111
|
-
- **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)
|
|
111
|
+
- **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:
|
|
112
112
|
|
|
113
113
|
```ts
|
|
114
114
|
import * as config from './config'
|
|
@@ -124,8 +124,8 @@ One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app
|
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
`defineConfig` from `@protobase/server` types it, and its `extends` merges other configs in (see [Extending a config](#extending-a-config)).
|
|
127
|
-
- **Project UI:** the app imports `protobase.ui.tsx` from the project root, with hot reload, when it exists (see [Custom components](custom-components.md))
|
|
128
|
-
- **Theme:** the page links `/protobase.theme.css`, which the dev server answers from the project's [theme](theme.md)
|
|
127
|
+
- **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.
|
|
128
|
+
- **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.
|
|
129
129
|
- **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.
|
|
130
130
|
- **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.
|
|
131
131
|
|
|
@@ -190,7 +190,7 @@ dist/
|
|
|
190
190
|
|
|
191
191
|
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.
|
|
192
192
|
|
|
193
|
-
A token the [theme](theme.md)
|
|
193
|
+
A token the [theme](theme.md) sets that the app does not read prints a `warning:` line, a likely typo; the build still succeeds.
|
|
194
194
|
|
|
195
195
|
By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun only, as the Protobase images and the cloud serve it: Bun's bundler writes the config module (see [the config module](#the-config-module)), so the build needs `bun` on `PATH` and fails without it.
|
|
196
196
|
|
|
@@ -198,7 +198,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
198
198
|
|
|
199
199
|
### Extensions
|
|
200
200
|
|
|
201
|
-
`--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)
|
|
201
|
+
`--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.
|
|
202
202
|
|
|
203
203
|
- 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.
|
|
204
204
|
- 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.
|
|
@@ -226,14 +226,14 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
226
226
|
}
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
- `protobase` is the Protobase version that built the bundle. The serve runtime serves only bundles of a compatible version: below 1.0 the same minor, from 1.0 the same major and the runtime's minor or an older one (see [Versioning](versioning.md#bundles-and-runtimes))
|
|
229
|
+
- `protobase` is the Protobase version that built the bundle. The serve runtime serves only bundles of a compatible version: below 1.0 the same minor, from 1.0 the same major and the runtime's minor or an older one (see [Versioning](versioning.md#bundles-and-runtimes)).
|
|
230
230
|
- `server`, `public`, `nodeModules` and `migrations` are relative to the bundle folder; `spa`, `theme` and each plugin's `path` to `public`.
|
|
231
|
-
- `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API and Protobase versions it is built for, and the [field types](plugins.md#field-types)
|
|
231
|
+
- `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API and Protobase versions it is built for, and the [field types](plugins.md#field-types) it registers with the storage types each shows, which the serve runtime checks the views against at startup. `/api/meta` names them to everyone, before any other plugin.
|
|
232
232
|
- `shell` is the admin app `public/` holds a copy of: its Protobase version and plugin API, and its files as URL paths. A host with a shell of its own, of a release every plugin of the bundle loads in, may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
|
|
233
|
-
- `theme` is the project's [theme](theme.md)
|
|
233
|
+
- `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.
|
|
234
234
|
- `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.
|
|
235
|
-
- `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))
|
|
236
|
-
- `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)
|
|
235
|
+
- `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.
|
|
236
|
+
- `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`.
|
|
237
237
|
- 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.
|
|
238
238
|
- 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`.
|
|
239
239
|
- `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`.
|
|
@@ -242,8 +242,8 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
242
242
|
|
|
243
243
|
`public/` holds two parts that are built apart.
|
|
244
244
|
|
|
245
|
-
- **The shell**, `index.html`, `assets/` and `protobase.sw.js`: the admin app, a production build of `@protobase/ui`'s `src/app` with no project code in it, the same for every project on a release. `@protobase/ui`'s package ships it prebuilt in `dist/shell/` and the [protobase image](../guides/deploy.md#images)
|
|
246
|
-
- **The plugins**, `plugins/<name>/`: the project's `protobase.ui.tsx` as the plugin `app`, and each [extension](#extensions)'s, each built as [`build-plugin`](#build-plugin) builds one, against the `@protobase/ui` installed in the project. `/api/meta` names them, and the shell loads them as it loads any [plugin](plugins.md)
|
|
245
|
+
- **The shell**, `index.html`, `assets/` and `protobase.sw.js`: the admin app, a production build of `@protobase/ui`'s `src/app` with no project code in it, the same for every project on a release. `@protobase/ui`'s package ships it prebuilt in `dist/shell/` and the [protobase image](../guides/deploy.md#images) at `/opt/protobase/shell/`; the build copies it. It calls the API on its own origin under `/api`, so the same bundle works under any hostname, and reads everything else at runtime: the resources, views, pages and roles from `/api/meta`, sign-in from `/api/auth`, the project's UI from its plugins and its look from `/protobase.theme.css`, which it links after its own stylesheets, its tab icon from `/protobase.favicon.svg`, and its [web app manifest](installable-app.md) from `/api/manifest.webmanifest`.
|
|
246
|
+
- **The plugins**, `plugins/<name>/`: the project's `protobase.ui.tsx` as the plugin `app`, and each [extension](#extensions)'s, each built as [`build-plugin`](#build-plugin) builds one, against the `@protobase/ui` installed in the project. `/api/meta` names them, and the shell loads them as it loads any [plugin](plugins.md). A component or field type the config declares but no `protobase.ui.tsx` exports fails the build (see [Components](custom-components.md#components)).
|
|
247
247
|
|
|
248
248
|
The modules the app shares with plugins, `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui`, are entries of their own, `/assets/shared-<name>-<hash>.js`, each exporting every name of its module. `index.html` maps the four names to them with an import map, ahead of every script, so a plugin's imports of them run on the app's copies.
|
|
249
249
|
|
|
@@ -257,19 +257,19 @@ The modules the app shares with plugins, `react`, `react/jsx-runtime`, `react-do
|
|
|
257
257
|
|
|
258
258
|
| Modules | |
|
|
259
259
|
| --- | --- |
|
|
260
|
-
| `@protobase/schema`, `@protobase/layout`, `@protobase/layout/jsx-runtime`, `@protobase/query`, `@protobase/server` | the server entry points of the `@protobase` packages, and what [layout files](layouts.md)
|
|
260
|
+
| `@protobase/schema`, `@protobase/layout`, `@protobase/layout/jsx-runtime`, `@protobase/query`, `@protobase/server` | the server entry points of the `@protobase` packages, and what [layout files](layouts.md) compile to |
|
|
261
261
|
| `kysely`, `kysely/helpers/postgres`, `pg`, `postgres` | the database |
|
|
262
262
|
| `better-auth`, `hono`, `jose`, `zod`, `aip-parsers`, `@hono/node-server`, `@scalar/hono-api-reference` | the main entry of each other dependency the `@protobase` packages run on the server |
|
|
263
|
-
| `hono/cors`, `hono/http-exception`, `hono/validator` | Hono middleware for [API functions](../guides/api-functions.md)
|
|
264
|
-
| `react`, `react/jsx-runtime`, `@react-email/render` | what [email templates](email.md#in-a-bundle)
|
|
265
|
-
| `@protobase/server/email` | the [look of Protobase's own mail](email.md#the-look-of-protobases-own-mail)
|
|
263
|
+
| `hono/cors`, `hono/http-exception`, `hono/validator` | Hono middleware for [API functions](../guides/api-functions.md) |
|
|
264
|
+
| `react`, `react/jsx-runtime`, `@react-email/render` | what [email templates](email.md#in-a-bundle) render with, so a template's component and the renderer share one React |
|
|
265
|
+
| `@protobase/server/email` | the [look of Protobase's own mail](email.md#the-look-of-protobases-own-mail), loaded when the bundle first imports it rather than when the runtime starts |
|
|
266
266
|
|
|
267
267
|
`react-email` is a dependency of `@protobase/server` that the runtime does not supply: the server loads it only to send its own mail, or for `@protobase/server/email`, so a config that imports it inlines its own copy, like any other package.
|
|
268
268
|
|
|
269
269
|
Importing any other `@protobase` package or dependency of one (`@protobase/ui`, `react-dom`, `better-auth/plugins`, `zod/v4`, ...) fails the build with this list, also from inside an inlined package, when the finished bundle still imports it: an inlined package may re-export a module that imports one, as `react-email` does with `tailwindcss`, as long as the project leaves that export unused. So does a copy the project installs in another version than the `@protobase` packages use (another major, or another minor below 1.0), which the runtime's would replace. The list is `packages/cli/src/serve/host-module-ids.ts`; the set of packages comes from the `package.json` of `@protobase/cli` and of every `@protobase` package it depends on.
|
|
270
270
|
- 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.
|
|
271
271
|
- Everything else (the project's files and its other packages) is inlined. Nothing is minified.
|
|
272
|
-
- 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))
|
|
272
|
+
- 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)).
|
|
273
273
|
- The default export is the project config merged with the configs it [extends](#extending-a-config), with `config` always set:
|
|
274
274
|
|
|
275
275
|
```ts
|
|
@@ -323,7 +323,7 @@ docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET \
|
|
|
323
323
|
protobase build-plugin [dir] [--out <dir>] [--name <name>] [--source-maps]
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
Builds the [plugin](plugins.md)
|
|
326
|
+
Builds the [plugin](plugins.md) in `dir` (default: the current folder), whose entry is its `protobase.ui.tsx`, into `--out` (default: `dir/dist`):
|
|
327
327
|
|
|
328
328
|
```
|
|
329
329
|
dist/
|
|
@@ -335,10 +335,10 @@ dist/
|
|
|
335
335
|
- The output folder is emptied first, so it must not be the plugin's folder or hold it.
|
|
336
336
|
- The module is `protobase.ui.tsx` with everything it imports bundled, except the four modules the app shares (`react`, `react/jsx-runtime`, `react-dom`, `@protobase/ui`), which stay imports by those names. Any other module of those packages, such as `react-dom/client`, fails the build. React's production build and JSX runtime are used, whatever `NODE_ENV` says, and every export of `protobase.ui.tsx` is kept.
|
|
337
337
|
- The stylesheet is Tailwind's utilities for the classes in the plugin's folder: no reset, no theme values. Each utility reads the theme of the app that loads it, with Tailwind's default as the fallback (`text-sm` is `font-size: var(--text-sm, 0.875rem)`).
|
|
338
|
-
- `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)
|
|
338
|
+
- `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)).
|
|
339
339
|
- `--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.
|
|
340
340
|
|
|
341
|
-
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))
|
|
341
|
+
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)).
|
|
342
342
|
|
|
343
343
|
## `build-serve`
|
|
344
344
|
|
|
@@ -346,7 +346,7 @@ To read its field types, the build loads the plugin's module once in Node, with
|
|
|
346
346
|
protobase build-serve [--out dist/protobase-serve.js] [--bun] # or, in this repository: bun run build:serve
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
Bundles the serve runtime (`@protobase/cli`'s `src/serve/main.ts`) and all its dependencies into one file, about 3 MB. A host needs Bun and this file, nothing else. `--bun` has Bun's bundler write the file, as for [`build`](#build), and needs `bun` on `PATH`; the `protobase` image is built from such a file. The file carries the Protobase version it was built from, which decides [the bundles it serves](versioning.md#bundles-and-runtimes)
|
|
349
|
+
Bundles the serve runtime (`@protobase/cli`'s `src/serve/main.ts`) and all its dependencies into one file, about 3 MB. A host needs Bun and this file, nothing else. `--bun` has Bun's bundler write the file, as for [`build`](#build), and needs `bun` on `PATH`; the `protobase` image is built from such a file. The file carries the Protobase version it was built from, which decides [the bundles it serves](versioning.md#bundles-and-runtimes).
|
|
350
350
|
|
|
351
351
|
```sh
|
|
352
352
|
bun --no-install protobase-serve.js [serve] <bundle> # the folder: the app and the API; the config module: the API
|
|
@@ -354,7 +354,7 @@ bun --no-install protobase-serve.js migrate <bundle> # apply the
|
|
|
354
354
|
bun --no-install protobase-serve.js create-admin <bundle> <email> # --generate-password or --password-stdin
|
|
355
355
|
```
|
|
356
356
|
|
|
357
|
-
`migrate` runs none of the app's code and needs only `DATABASE_URL`; `create-admin` loads the app with its settings and refuses an auth schema that is behind. Given the folder, the runtime serves the bundle's own copy of the app. [Deploy](../guides/deploy.md#a-self-hosted-image)
|
|
357
|
+
`migrate` runs none of the app's code and needs only `DATABASE_URL`; `create-admin` loads the app with its settings and refuses an auth schema that is behind. Given the folder, the runtime serves the bundle's own copy of the app. [Deploy](../guides/deploy.md#a-self-hosted-image) puts the three in a self-hosted image.
|
|
358
358
|
|
|
359
359
|
## `serve`
|
|
360
360
|
|
|
@@ -371,37 +371,37 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
371
371
|
| Variable | |
|
|
372
372
|
| --- | --- |
|
|
373
373
|
| `DATABASE_URL` | the API's pool (Kysely over `pg`, 10 connections); not needed when the config exports `db` |
|
|
374
|
-
| `PROTOBASE_DB_CONNECTIONS` | the connections that pool opens, such as the database's limit for the app; default 10. [API functions](../guides/api-functions.md)
|
|
374
|
+
| `PROTOBASE_DB_CONNECTIONS` | the connections that pool opens, such as the database's limit for the app; default 10. [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 |
|
|
375
375
|
| `PORT` | default 8787 |
|
|
376
376
|
| `REQUEST_LOG` | `true` logs every request; default `false` |
|
|
377
|
-
| `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)
|
|
377
|
+
| `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)) |
|
|
378
378
|
| `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 |
|
|
379
|
-
| `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)
|
|
380
|
-
| `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))
|
|
381
|
-
| `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)
|
|
382
|
-
| `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))
|
|
383
|
-
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins ([CORS](api.md#cors))
|
|
384
|
-
| `PROTOBASE_ASSISTANT_URL`, `PROTOBASE_ASSISTANT_API_KEY`, `PROTOBASE_ASSISTANT_MODEL`, `PROTOBASE_ASSISTANT_BASE_URL` | the [assistant](assistant.md#which-backend)
|
|
385
|
-
| `PROTOBASE_RUNTIME_URL` | the endpoint behind the top bar's [runtime update button](versioning.md#runtime-updates)
|
|
386
|
-
| `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))
|
|
387
|
-
| `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps)
|
|
388
|
-
| `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))
|
|
389
|
-
| `PROTOBASE_FILES_<NAME>`, `PROTOBASE_FILES_RETENTION`, `PROTOBASE_FILES_SECRET` | [file providers](files.md#providers)
|
|
390
|
-
| `PROTOBASE_FILES_CLEANUP_MINUTES` | minutes between runs of the [scheduled file deletes](files.md#deleting-files)
|
|
391
|
-
| `PROTOBASE_ENCRYPTION_KEY`, `PROTOBASE_ENCRYPTION_PREVIOUS_KEYS` | the key [encrypted fields](data-config.md#encrypted-fields)
|
|
392
|
-
| `PROTOBASE_JOBS` | `false` runs none of the app's [jobs](jobs.md)
|
|
379
|
+
| `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) |
|
|
380
|
+
| `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)) |
|
|
381
|
+
| `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)) |
|
|
382
|
+
| `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)) |
|
|
383
|
+
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins ([CORS](api.md#cors)) |
|
|
384
|
+
| `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 |
|
|
385
|
+
| `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 |
|
|
386
|
+
| `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 |
|
|
387
|
+
| `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 |
|
|
388
|
+
| `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)) |
|
|
389
|
+
| `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` |
|
|
390
|
+
| `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 |
|
|
391
|
+
| `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 |
|
|
392
|
+
| `PROTOBASE_JOBS` | `false` runs none of the app's [jobs](jobs.md) in this process, which still enqueues them; default `true` |
|
|
393
393
|
| `PROTOBASE_STARTUP_CHECKS` | `false` skips the startup reads of the auth, changes, computed columns, webhooks and jobs schemas, which make a start slower; default `true`. Set it only to restart a bundle that already started on this database, such as when a platform wakes a sleeping app, never for a new bundle or after its migrations ran |
|
|
394
394
|
| `PROTOBASE_SHELL` | `protobase serve <bundle>` only: a shell folder, such as the `/opt/protobase/shell` of a protobase image or `@protobase/ui`'s `dist/shell`, to serve the bundle's app from (see [its own shell](#serve)) |
|
|
395
|
-
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of the server, addresses or CIDR ranges, comma separated: a request from one of them names its client in `X-Forwarded-For`; without it the client is the connection's address ([Client addresses](auth.md#client-addresses))
|
|
396
|
-
| `PROTOBASE_JOBS_DRAIN_TOKEN` | the operator's bearer token for `POST /api/jobs/drain`, which [runs the due jobs](jobs.md#hosts-that-sleep)
|
|
395
|
+
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of the server, addresses or CIDR ranges, comma separated: a request from one of them names its client in `X-Forwarded-For`; without it the client is the connection's address ([Client addresses](auth.md#client-addresses)) |
|
|
396
|
+
| `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 |
|
|
397
397
|
|
|
398
398
|
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.
|
|
399
399
|
|
|
400
400
|
- **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.
|
|
401
|
-
- **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)
|
|
402
|
-
- **Version:** before loading the config module, the runtime reads `protobase.bundle.json` beside it and refuses a bundle built by a Protobase version it does not serve, or one without a version, with an error naming both versions (see [Versioning](versioning.md#bundles-and-runtimes))
|
|
403
|
-
- **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)
|
|
404
|
-
- **Jobs:** with [jobs](jobs.md)
|
|
401
|
+
- **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.
|
|
402
|
+
- **Version:** before loading the config module, the runtime reads `protobase.bundle.json` beside it and refuses a bundle built by a Protobase version it does not serve, or one without a version, with an error naming both versions (see [Versioning](versioning.md#bundles-and-runtimes)). A config module needs its manifest beside it.
|
|
403
|
+
- **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.
|
|
404
|
+
- **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.
|
|
405
405
|
- **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.
|
|
406
406
|
- **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.
|
|
407
407
|
- **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.
|
|
@@ -412,7 +412,7 @@ Better Auth and other settings are the project's own variables (`BETTER_AUTH_SEC
|
|
|
412
412
|
protobase worker <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
|
|
413
413
|
```
|
|
414
414
|
|
|
415
|
-
Runs the bundle's [jobs](jobs.md)
|
|
415
|
+
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.
|
|
416
416
|
|
|
417
417
|
## `files cleanup`
|
|
418
418
|
|
|
@@ -421,7 +421,7 @@ protobase files cleanup # the project in the current directory
|
|
|
421
421
|
protobase files cleanup <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
|
|
422
422
|
```
|
|
423
423
|
|
|
424
|
-
Runs the [scheduled file deletes](files.md#deleting-files)
|
|
424
|
+
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.
|
|
425
425
|
|
|
426
426
|
## `encryption status`
|
|
427
427
|
|
|
@@ -430,7 +430,7 @@ protobase encryption status # the project in the current directory
|
|
|
430
430
|
protobase encryption status <bundle> # a bundle from `protobase build`: its folder or its protobase.config.js
|
|
431
431
|
```
|
|
432
432
|
|
|
433
|
-
Reads every [encrypted field](data-config.md#encrypted-fields)
|
|
433
|
+
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`.
|
|
434
434
|
|
|
435
435
|
## `encryption apply`
|
|
436
436
|
|
|
@@ -440,7 +440,7 @@ protobase encryption apply --rebind people --from-table persons # after
|
|
|
440
440
|
protobase encryption apply --rebind people.iban --from-column bank_iban # after a column rename
|
|
441
441
|
```
|
|
442
442
|
|
|
443
|
-
Encrypts every plaintext value of the encrypted fields with the current key, encrypts values under a previous key again with it, and removes the fields' old values from the [history](history.md)
|
|
443
|
+
Encrypts every plaintext value of the encrypted fields with the current key, encrypts values under a previous key again with it, and removes the fields' old values from the [history](history.md) and the changes not yet dispatched. Values that do not decrypt are listed and left as they are; it exits with 1 when any remain. Its writes are captured by no event, history or webhook, and a value a write changes while it runs is left to that write. It refuses to run when a column holds values under none of its keys, such as with another key than the app's.
|
|
444
444
|
|
|
445
445
|
`--rebind <resource>[.<field>]` with `--from-table <table>` (as `.table()` wrote it) or `--from-column <column>` also takes values sealed where the field was before a rename, and seals them where it is now; running it again rebinds nothing more. It refuses a former place another resource still encrypts.
|
|
446
446
|
|
|
@@ -458,13 +458,13 @@ protobase users disable <email> # and: enable <email>
|
|
|
458
458
|
protobase users delete <email> [--yes]
|
|
459
459
|
```
|
|
460
460
|
|
|
461
|
-
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)
|
|
461
|
+
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.
|
|
462
462
|
|
|
463
|
-
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)
|
|
463
|
+
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.
|
|
464
464
|
|
|
465
|
-
`delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. With [MCP](auth.md#oauth-for-mcp-clients)
|
|
465
|
+
`delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. With [MCP](auth.md#oauth-for-mcp-clients) on, it also disconnects their MCP clients. `enable` lifts the ban; the clients have to be allowed again. `protobase dev` prints "No users yet. Create the first admin with: protobase users create you@example.com" at startup while the user table is empty.
|
|
466
466
|
|
|
467
|
-
With [organizations](auth.md#organizations)
|
|
467
|
+
With [organizations](auth.md#organizations), `--role` is the user's global role (none by default) and `--organization` adds the new user to an organization, with `--org-role` (`owner`, `admin`, or `member`, the default) and `--app-roles` there.
|
|
468
468
|
|
|
469
469
|
## `organizations`
|
|
470
470
|
|
|
@@ -477,7 +477,7 @@ protobase organizations remove-member <organization> <email>
|
|
|
477
477
|
protobase organizations add-app-role <role> --to owners
|
|
478
478
|
```
|
|
479
479
|
|
|
480
|
-
For a project with [organizations](auth.md#organizations)
|
|
480
|
+
For a project with [organizations](auth.md#organizations); `<organization>` is a slug or an id. The host acts as a superuser, so it may give any role. `create` makes `--owner` the owner with every app role; `--id` keeps an existing tenant value, and `--members all` adds every other user, superusers as owners and everyone else as a member with their global roles moved onto the membership, for an app that ran as one organization. `remove-member` and `set-roles` refuse to leave an organization without an owner. `add-app-role` gives a role the project added later to every owner.
|
|
481
481
|
|
|
482
482
|
## `migration`
|
|
483
483
|
|
|
@@ -485,7 +485,7 @@ For a project with [organizations](auth.md#organizations)); `<organization>` is
|
|
|
485
485
|
protobase migration [--dir db/migrations] [--extend <dir>]
|
|
486
486
|
```
|
|
487
487
|
|
|
488
|
-
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)
|
|
488
|
+
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 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`), and the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks()` (`NNN_webhooks.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`.
|
|
489
489
|
|
|
490
490
|
```sh
|
|
491
491
|
bun run db:migrate # the database at the project's current schema
|
|
@@ -499,7 +499,7 @@ bun run db:migrate # applies them
|
|
|
499
499
|
protobase auth migration [--dir db/migrations] [--name auth]
|
|
500
500
|
```
|
|
501
501
|
|
|
502
|
-
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)
|
|
502
|
+
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).
|
|
503
503
|
|
|
504
504
|
## `import supabase`
|
|
505
505
|
|
|
@@ -510,12 +510,12 @@ protobase import supabase [<connection> | --source-env <variable>] [--env DATABA
|
|
|
510
510
|
|
|
511
511
|
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`).
|
|
512
512
|
|
|
513
|
-
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))
|
|
513
|
+
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.
|
|
514
514
|
2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
|
|
515
|
-
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)
|
|
515
|
+
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, sessions, MFA factors and passkeys do not carry over.
|
|
516
516
|
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.
|
|
517
517
|
|
|
518
|
-
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)
|
|
518
|
+
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.
|
|
519
519
|
|
|
520
520
|
An agent with the `supabase-move` skill of [`skill install`](#skill) finishes what the report leaves: it rewrites each item, checking the project's database for the extensions an item needs, and runs `doctor` and the typecheck until both pass, leaving the values of Vault's secrets for you to enter.
|
|
521
521
|
|
|
@@ -530,7 +530,7 @@ protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [-
|
|
|
530
530
|
[--team <id> [--certificate <name> --profile <name>]]
|
|
531
531
|
```
|
|
532
532
|
|
|
533
|
-
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)
|
|
533
|
+
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).
|
|
534
534
|
|
|
535
535
|
- 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. 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.
|
|
536
536
|
- `--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.
|
|
@@ -17,19 +17,19 @@ const { record, etag } = await api.get(orders, id)
|
|
|
17
17
|
await api.update(orders, id, { status: 'shipped' }, etag) // 412 rejects with PreconditionFailedError
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/))
|
|
20
|
+
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)). Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at). Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself).
|
|
21
21
|
|
|
22
|
-
With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/v1`, the `url` of each [file](files.md)
|
|
22
|
+
With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/v1`, the `url` of each [file](files.md) in a record the client answers is absolute too, on that API's origin, where the API answers a path on its own origin. `routedClient(own, sourceOf)` is one client over several APIs: each call about a resource goes to the client `sourceOf(resource)` gives, else to `own`, as the admin app does for [remote resources](remote-resources.md), and `sourceMeta(meta, source)` keeps the part of another API's `/meta` an app draws.
|
|
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` ([composed pages](layouts.md))
|
|
26
|
+
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` ([composed pages](layouts.md)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first page, or the first resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` (the user's passkeys and two-factor authentication) 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 above the shell. `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: `?filter=` (AIP-160), `?order_by=`, `?layout=panel`, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `examples/*/config/*/ui.ts`. The sidebar's recent-record groups and the user menu are configured there too: see [Sidebar](sidebar.md), [User menu](user-menu.md) and [Bottom bar](bottom-bar.md).
|
|
27
27
|
|
|
28
28
|
## Global search
|
|
29
29
|
|
|
30
|
-
The search box in the top bar looks in every resource the user can read that has search fields (`.search(...)` in its [data config](data-config.md#resource))
|
|
30
|
+
The search box in the top bar looks in every resource the user can read that has search fields (`.search(...)` in its [data config](data-config.md#resource)) and a view in the sidebar or the user menu. Its placeholder names them, such as "Search organizations, services and more"; an app with no page or resource has no box.
|
|
31
31
|
|
|
32
|
-
From two characters on, it asks each of those resources' list API for `search("<text>")` (every word, even part of one, in one of the search fields; the end of a [`digitsEnd`](data-config.md#resource)
|
|
32
|
+
From two characters on, it asks each of those resources' list API for `search("<text>")` (every word, even part of one, in one of the search fields; the end of a [`digitsEnd`](data-config.md#resource) field) with the user's token, five records each, so row filters and hidden fields apply exactly as on the lists and it never offers a record the user could not open. Before the records, under **Go to**, are the sidebar's pages and lists whose names hold the text ("stock" finds Stock levels), and under **Create** a **New ...** for each resource the user may create whose name holds it, with or without "new" before it ("order" or "new ord" finds New order), five of each. The records are grouped by resource, two lines each: a bold title, the view's [`searchResult`](ui-config.md#names-and-columns) title fields joined by spaces (default: the record's title), and a subtitle, the view's `searchResult` subtitle (default: the first search field not in the title). When the text matched a search field that neither line shows, such as a phone number, that field is the subtitle instead.
|
|
33
33
|
|
|
34
34
|
Each result is a link: a click or Enter opens it and closes the list, Enter the first result when none is highlighted, and Cmd or Ctrl click, a middle click or the browser's menu open it in a new tab. The text stays, so focusing the box again shows the same results without asking the server; only changed text searches again. While the box has text, a clear button replaces the ⌘K hint. ⌘K (Ctrl+K) focuses the box, or opens it on a phone; the arrow keys move through the results, and Escape clears the box, then leaves it. A resource whose search fails says so in its group.
|
|
35
35
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Comments on a resource's records by anyone who may read them, with @mentions that email the people named, shown on the record page and listed for admins.
|
|
6
6
|
|
|
7
|
-
A resource with [`.comments()`](https://docs.protobase.net/api/schema/interfaces/resourcebuilder/#comments)
|
|
7
|
+
A resource with [`.comments()`](https://docs.protobase.net/api/schema/interfaces/resourcebuilder/#comments) takes comments on its records: plain text, each with its author and time. Typing `@` in a comment mentions someone, who gets an email with a link to the record. Comments cannot be edited, and there are no replies or reactions.
|
|
8
8
|
|
|
9
9
|
```ts title="config/tickets.ts"
|
|
10
10
|
import { f, l, resource, view } from '@protobase/schema'
|
|
@@ -42,7 +42,7 @@ export default defineConfig({ config })
|
|
|
42
42
|
|
|
43
43
|
## On the record page
|
|
44
44
|
|
|
45
|
-
[`l.comments(title?, { when })`](https://docs.protobase.net/api/schema/variables/l/#comments)
|
|
45
|
+
[`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.
|
|
46
46
|
|
|
47
47
|
## Mentions
|
|
48
48
|
|
|
@@ -50,9 +50,9 @@ Typing `@` and part of a name lists up to 8 people to mention: the arrows move,
|
|
|
50
50
|
|
|
51
51
|
Each person mentioned gets one email from the app's own mail: who mentioned them on which record, the comment, and a button that opens the record. The emails are sent by the job `comments.mention`, enqueued with the comment, so mentions need:
|
|
52
52
|
|
|
53
|
-
- the project's [Better Auth](auth.md)
|
|
54
|
-
- [mail](email.md#configuration)
|
|
55
|
-
- the [`jobs` schema](jobs.md#the-jobs-schema)
|
|
53
|
+
- the project's [Better Auth](auth.md), whose users are the people listed; without it, comments work and nobody can be mentioned;
|
|
54
|
+
- [mail](email.md#configuration); without it, the job sends nothing;
|
|
55
|
+
- the [`jobs` schema](jobs.md#the-jobs-schema) and the app's workers.
|
|
56
56
|
|
|
57
57
|
A person banned or deleted since the comment gets no email, and neither does anyone when an admin has deleted the comment.
|
|
58
58
|
|
|
@@ -62,15 +62,15 @@ Whoever may read the record may read its comments and add one: the same tenant,
|
|
|
62
62
|
|
|
63
63
|
## The endpoints
|
|
64
64
|
|
|
65
|
-
`GET /api/v1/{resource}/{key}:comments` reads them newest first, `POST` to the same path adds one, and `GET /api/v1/{resource}/{key}:mentionable?q=` lists whom a comment may mention. See [REST API](api.md#record-comments)
|
|
65
|
+
`GET /api/v1/{resource}/{key}:comments` reads them newest first, `POST` to the same path adds one, and `GET /api/v1/{resource}/{key}:mentionable?q=` lists whom a comment may mention. See [REST API](api.md#record-comments).
|
|
66
66
|
|
|
67
67
|
## Moderation
|
|
68
68
|
|
|
69
|
-
Once a resource takes comments, admins get **Comments** (the built-in resource `record_comments`): every comment of every resource, newest first, filterable by resource, record, author and time. Only the `admin` role reads it, whatever the project's roles say; deleting a comment there is how a wrong or abusive one goes. When a resource with comments has a [tenant](data-config.md#resource)
|
|
69
|
+
Once a resource takes comments, admins get **Comments** (the built-in resource `record_comments`): every comment of every resource, newest first, filterable by resource, record, author and time. Only the `admin` role reads it, whatever the project's roles say; deleting a comment there is how a wrong or abusive one goes. When a resource with comments has a [tenant](data-config.md#resource), the list is scoped to the caller's tenant.
|
|
70
70
|
|
|
71
71
|
## The table
|
|
72
72
|
|
|
73
|
-
[`protobase migration`](cli.md#migration)
|
|
73
|
+
[`protobase migration`](cli.md#migration) adds the schema `comments` with the table `comments.comments`; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while a resource has comments and the table is missing. A deleted record's comments stay in the table.
|
|
74
74
|
|
|
75
75
|
| Column | |
|
|
76
76
|
| --- | --- |
|