@protobase/cli 0.49.0 → 0.49.2
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/dist/config/build-project.js +18 -8
- package/dist/config/config-defaults.js +3 -0
- package/dist/config/read-config.js +5 -1
- package/dist/db/read-only-db.js +1 -1
- package/dist/dev/dev-jobs.js +5 -3
- package/dist/dev/entry.js +3 -3
- package/dist/migration/load-project.js +1 -1
- package/dist/project/load-bundle-project.js +1 -1
- package/dist/project-auth.d.ts +2 -0
- package/dist/project-auth.js +2 -0
- package/dist/serve/app.js +1 -1
- package/dist/serve/create-admin.js +1 -1
- package/dist/serve/host-modules.js +3 -3
- package/dist/serve/lifecycle.js +4 -3
- package/dist/supabase/load-phase.js +1 -1
- package/dist/users/load-auth.d.ts +10 -0
- package/dist/users/load-auth.js +1 -1
- package/dist/worker/start-worker.js +3 -2
- package/package.json +8 -7
- package/skills/protobase/SKILL.md +7 -1
- package/skills/protobase/references/features/events-webhooks-and-jobs.md +1 -0
- package/skills/protobase/references/features/files-and-images.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +3 -0
- package/skills/protobase/references/features/start-a-project.md +7 -1
- package/skills/protobase/references/getting-started.md +13 -13
- package/skills/protobase/references/guides/deploy.md +2 -2
- 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 +1 -1
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/personal-setting.md +1 -1
- package/skills/protobase/references/guides/push-notifications.md +1 -1
- package/skills/protobase/references/guides/record-card.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/theme-an-app.md +1 -1
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/architecture.md +4 -4
- package/skills/protobase/references/reference/auth.md +36 -4
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +1 -1
- package/skills/protobase/references/reference/cli.md +10 -10
- package/skills/protobase/references/reference/client.md +2 -2
- 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 +89 -70
- package/skills/protobase/references/reference/custom-components.md +2 -2
- package/skills/protobase/references/reference/data-config.md +2 -2
- package/skills/protobase/references/reference/email.md +2 -2
- package/skills/protobase/references/reference/files.md +6 -3
- package/skills/protobase/references/reference/jobs.md +15 -6
- package/skills/protobase/references/reference/sidebar.md +2 -2
- package/skills/protobase/references/reference/ui-config.md +5 -5
- package/skills/protobase/references/reference/user-menu.md +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Turn notifications on, send one when a record changes, and see it in the bell and as push on the user's browser.
|
|
6
6
|
|
|
7
|
-
You turn notifications on, send one when something happens in your app, and see it in the bell and as push on your browser. This guide uses the ERP example (`
|
|
7
|
+
You turn notifications on, send one when something happens in your app, and see it in the bell and as push on your browser. This guide uses the ERP example (`tests/apps/erp`, set up as its README says, with a user from `protobase users create`): when an order's status changes, its owner hears about it. The [Notifications reference](../reference/notifications.md) has every option.
|
|
8
8
|
|
|
9
9
|
## 1. Turn notifications on
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Draw each card of a cards display with a component of your own, and keep the built-in card as its fallback.
|
|
6
6
|
|
|
7
|
-
A list can show its records as [cards](../reference/ui-config.md#list-displays) beside its table: a title, a subtitle, a badge and a few small fields. Rijnland's sales team wants order cards that lead with the total and the customer, the way they talk about orders. That is a card component: the list page still loads the orders, filters, sorts and links each card to its order; the component only draws what is inside a card. This guide adds one to the ERP example (`
|
|
7
|
+
A list can show its records as [cards](../reference/ui-config.md#list-displays) beside its table: a title, a subtitle, a badge and a few small fields. Rijnland's sales team wants order cards that lead with the total and the customer, the way they talk about orders. That is a card component: the list page still loads the orders, filters, sorts and links each card to its order; the component only draws what is inside a card. This guide adds one to the ERP example (`tests/apps/erp`).
|
|
8
8
|
|
|
9
9
|
## 1. The card
|
|
10
10
|
|
|
@@ -10,7 +10,7 @@ This guide makes the desk's tickets a [remote resource](../reference/remote-reso
|
|
|
10
10
|
|
|
11
11
|
## 1. Two apps
|
|
12
12
|
|
|
13
|
-
You need two Protobase projects, each with its own database, its own [admin store](../reference/auth.md#admin-store) and a user: the from-scratch preset (`
|
|
13
|
+
You need two Protobase projects, each with its own database, its own [admin store](../reference/auth.md#admin-store) and a user: the from-scratch preset (`tests/apps/scratch` in the repository) is enough for both. Each runs on its own origin; this guide runs them side by side on one machine:
|
|
14
14
|
|
|
15
15
|
| | `PROTOBASE_URL` in its `.env` | Started with |
|
|
16
16
|
| --- | --- | --- |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Give an app its own colors, corners and font with protobase.theme.css, in light and dark, and keep them through every release.
|
|
6
6
|
|
|
7
|
-
Rijnland Industrial Supply wants its admin in its own colors: teal instead of blue, rounder corners and its own font. That is one file of values, `protobase.theme.css`, which the app reads on every page, the sign-in page included. This guide writes it for the ERP example (`
|
|
7
|
+
Rijnland Industrial Supply wants its admin in its own colors: teal instead of blue, rounder corners and its own font. That is one file of values, `protobase.theme.css`, which the app reads on every page, the sign-in page included. This guide writes it for the ERP example (`tests/apps/erp`); any project works the same. [Theme](../reference/theme.md) has every token.
|
|
8
8
|
|
|
9
9
|
## 1. The light values
|
|
10
10
|
|
|
@@ -23,7 +23,7 @@ const admin = createAdmin({
|
|
|
23
23
|
})
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Run the ERP example with `bun run --cwd
|
|
26
|
+
Run the ERP example with `bun run --cwd tests/apps/erp serve` (port 8787, Better Auth login, organization 1 as tenant; `REQUEST_LOG=true` logs requests). Interactive reference: `/api/docs`; like `/api/openapi.json` it needs a bearer token, because the document lists what the caller may see and do. Every route answers `401` without a valid token; get one with `protobase token you@example.com`. A project whose roles define [`anonymous`](access.md#anonymous-access) serves the resources API to requests without a token as that role.
|
|
27
27
|
|
|
28
28
|
## Routes
|
|
29
29
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
How the packages are laid out, which package may import which, and where tests and stories live.
|
|
6
6
|
|
|
7
|
-
A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name>`, all released together at one version. `
|
|
7
|
+
A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name>`, all released together at one version. `tests/apps/*`, the example apps the tests run on and the presets are written from, are workspace members that consume the packages; `website` is this documentation site (Astro with Starlight), also a workspace member. The workspace root is private and is not published.
|
|
8
8
|
|
|
9
9
|
## Packages
|
|
10
10
|
|
|
@@ -18,9 +18,9 @@ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name
|
|
|
18
18
|
| `@protobase/server` | `packages/server` | `@protobase/server` | server | `schema`, `layout`, `query` |
|
|
19
19
|
| `@protobase/cli` | `packages/cli` | the `protobase` command (`bin/protobase.mjs`) | Node and Bun | `schema`, `layout`, `query`, `server`, `ui` |
|
|
20
20
|
| `@protobase/presets` | `packages/presets` | none: private, `bun run presets:write` writes a project per preset | Bun | none; each preset depends on the `@protobase` packages of the major it is written at, locked at that version |
|
|
21
|
-
| `
|
|
21
|
+
| `tests/apps/*` | | none | any | `@protobase/*` entry points only |
|
|
22
22
|
|
|
23
|
-
The presets are written from `
|
|
23
|
+
The presets are written from `tests/apps/erp`, `tests/apps/real-estate` and `tests/apps/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
|
|
24
24
|
|
|
25
25
|
The JSX runtime belongs to `@protobase/layout` because a layout file names one package in `@jsxImportSource @protobase/layout`, and TypeScript and Vite look up `jsx-runtime` and `jsx-dev-runtime` under it. Each field type is split along the same lines: its Zod builder is `packages/schema/src/fields/<type>.ts` and its SQL parameter conversion `packages/query/src/fields/<type>.ts`.
|
|
26
26
|
|
|
@@ -37,7 +37,7 @@ In this repository, entry points export TypeScript source directly and the CLI r
|
|
|
37
37
|
## Tests and stories
|
|
38
38
|
|
|
39
39
|
- Unit tests: `*.test.ts` next to the code, run by Vitest in a node environment.
|
|
40
|
-
- Tests that use a database, a subprocess or the network: `packages/<name>/tests/`, mirroring the source path, and the
|
|
40
|
+
- Tests that use a database, a subprocess or the network: `packages/<name>/tests/`, mirroring the source path, and the example apps' in `tests/examples/`. Most database tests are snapshot tests, which replay SQL recorded from Postgres (`<test>.sql.json`); the fixtures, the recording and replay, and the setup they share are in `test-support/` at the root.
|
|
41
41
|
- Stories: `*.stories.tsx` next to the component in `packages/ui/src`; Storybook config lives in `.storybook/`.
|
|
42
42
|
- Packing leaves tests, stories and their fixtures out of a package (`files` in its `package.json`).
|
|
43
43
|
|
|
@@ -70,6 +70,7 @@ The store's migrations make the user table only when it is missing, and add each
|
|
|
70
70
|
| Variable | |
|
|
71
71
|
| --- | --- |
|
|
72
72
|
| `PROTOBASE_SECRET` | the app's secret, the default of `secret`: signs cookies and encrypts the token keys; `openssl rand -base64 32`; never committed (`.env.example` has a placeholder) |
|
|
73
|
+
| `PROTOBASE_PREVIOUS_SECRETS` | the app's secrets before `PROTOBASE_SECRET`, newest first, comma separated, the default of `previousSecrets`; see [Changing the secret](#changing-the-secret) |
|
|
73
74
|
| `PROTOBASE_URL` | the app's public URL, the default of `url` (in `protobase dev`, the dev server's own); issuer and audience of the tokens; when tunnelling, the https tunnel URL |
|
|
74
75
|
| `PROTOBASE_TRUSTED_ORIGINS` | extra comma separated origins, the default of `auth.trustedOrigins`; a dev tunnel needs its exact host here, such as `https://my-tunnel.trycloudflare.com`, since no wildcard is trusted |
|
|
75
76
|
| `PROTOBASE_ORIGINS` | the other origins the app is served on, comma separated, passed by the platform; see [Several origins](#several-origins) |
|
|
@@ -123,11 +124,14 @@ An app served another way than `protobase serve`, such as its own server around
|
|
|
123
124
|
|
|
124
125
|
## First run
|
|
125
126
|
|
|
126
|
-
Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`, or `--no-password` for an account that signs in by emailed code, passkey or a sign-in provider only). The `users` commands call these functions of `@protobase/server`, on the app's sign-in
|
|
127
|
+
Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`, or `--no-password` for an account that signs in by emailed code, passkey or a sign-in provider only). The `users` commands call these functions of `@protobase/server`, on the app's sign-in. A script of the project's own, such as a seed, builds that sign-in as the commands do, from the project's config and `DATABASE_URL`, with `loadProjectAuth` of `@protobase/cli/auth`:
|
|
127
128
|
|
|
128
129
|
```ts
|
|
130
|
+
import { loadProjectAuth } from '@protobase/cli/auth'
|
|
129
131
|
import { createUser, hasUsers, listUsers } from '@protobase/server'
|
|
130
132
|
|
|
133
|
+
const auth = await loadProjectAuth(process.cwd()) // the project's folder; its .env is loaded too
|
|
134
|
+
|
|
131
135
|
await createUser(auth, { email, password?, name?, role? }) // the first user is always an admin; later ones default to `user`
|
|
132
136
|
await hasUsers(auth) // boolean
|
|
133
137
|
await listUsers(auth) // [{ id, email, role, banned, createdAt }], never passwords
|
|
@@ -224,7 +228,7 @@ import type { Mailer } from '@protobase/server'
|
|
|
224
228
|
export default { send: async ({ to, subject, text }) => { /* deliver it */ } } satisfies Mailer
|
|
225
229
|
```
|
|
226
230
|
|
|
227
|
-
[Jobs](jobs.md#mail) send their own mail through the same server, with `mail` in their context, and so do the app's [email templates](email.md).
|
|
231
|
+
[Jobs](jobs.md#mail) send their own mail through the same server, or the same `auth/mailer.ts`, with `mail` in their context, and so do the app's [email templates](email.md) given it.
|
|
228
232
|
|
|
229
233
|
- The email names the app and gives the link, as a button and in its plain-text part, that it works for 1 hour and once, and that it can be ignored (see [Protobase's own mail](email.md#protobases-own-mail)).
|
|
230
234
|
- The SMTP client greets the server with the sender's domain (`admin.example.com` above), not the container's `[127.0.0.1]`; a `?name=` on `PROTOBASE_SMTP_URL` overrides it.
|
|
@@ -581,7 +585,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
|
|
|
581
585
|
|
|
582
586
|
**Deleting** an organization (Better Auth's `delete`, owners only) is refused with `409 ORGANIZATION_HAS_RECORDS` while a `.tenant` resource has rows in it; `deleteRecords: 'cascade'` leaves it to the project's foreign keys. The `beforeOrganizationDeleted` [hook](#hooks) may refuse too.
|
|
583
587
|
|
|
584
|
-
**Ids.** The `generateOrganizationId` [hook](#hooks) makes a new organization's id, by default a UUID; `.tenant` columns hold it, so `text` or `uuid`. An app whose tenant columns are integers takes the next value of its own organizations sequence instead, and adds its own row in `onOrganizationCreated`, as the ERP example does (`
|
|
588
|
+
**Ids.** The `generateOrganizationId` [hook](#hooks) makes a new organization's id, by default a UUID; `.tenant` columns hold it, so `text` or `uuid`. An app whose tenant columns are integers takes the next value of its own organizations sequence instead, and adds its own row in `onOrganizationCreated`, as the ERP example does (`tests/apps/erp/auth/hooks.ts`). An app that ran as one organization keeps its tenant value: `protobase organizations create "Acme" --owner you@example.com --id 1 --members all` makes that organization, with every user in it: superusers as owners, everyone else as a member, their global roles moved onto the membership.
|
|
585
589
|
|
|
586
590
|
The app's own pages are under the profile menu: the switcher, "Manage organizations" (theirs, a new one, and for global roles any one), "Organization" (details, leaving, handing over, deleting), and for owners and admins "Members" and "Invitations". The client has them as `session.organizations` (`list`, `current`, `switchTo`, `members`, `invite`, ...).
|
|
587
591
|
|
|
@@ -609,6 +613,32 @@ A refused token is a `401`, as an expired one is, and the client retries the req
|
|
|
609
613
|
|
|
610
614
|
The cost is two or three lookups by key in the auth store per request: the session by `sid`, the user by `sub`, and with organizations the membership. Nothing is cached, so every server process sees a change at once. An open `/live` stream was admitted when it connected and keeps running until it closes. With `authenticate.jwksUrl` instead of sign-in of its own, the API cannot read the auth store and a token works until it expires, as do tokens of [other apps](#users-of-another-app).
|
|
611
615
|
|
|
616
|
+
### Signing keys
|
|
617
|
+
|
|
618
|
+
The app makes the keys that sign its tokens itself, and keeps them in the auth store, the private half encrypted with the app's `secret`. Every instance of the app signs with the same keys, since they share the database, and nobody supplies one.
|
|
619
|
+
|
|
620
|
+
The keys rotate. A key signs for 30 days (`signingKeyDays`); the first token after that makes a new key, which signs from then on. The replaced key stays in `/api/auth/jwks` for 7 more days (`signingKeyGraceDays`, at least 1), so the tokens it signed keep verifying until they expire, and is then deleted. A month bounds how long a leaked key could sign, and keeps the key set to a few keys. A week is far longer than any token lasts (a day at most, from [`protobase token`](#tokens-for-scripts-and-curl)), so an API that caches the key set, such as another app reading `/api/auth/jwks`, never refuses a token signed just before a rotation. The ES256 key of the [Supabase-compatible tokens](#supabase-js-and-supabasessr) rotates the same way. A key made by a version before rotation expires 30 days after it was made, or at once when it is older.
|
|
621
|
+
|
|
622
|
+
```ts
|
|
623
|
+
export default defineConfig({ signingKeyDays: 90, signingKeyGraceDays: 14 })
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
#### Changing the secret
|
|
627
|
+
|
|
628
|
+
The secret encrypts the signing keys, so with a new `secret` alone the app cannot read them, and making a token fails with `Failed to decrypt private key`. List the old secret in `previousSecrets`, newest first, or in `PROTOBASE_PREVIOUS_SECRETS`, comma separated:
|
|
629
|
+
|
|
630
|
+
```sh
|
|
631
|
+
PROTOBASE_SECRET=<the new secret>
|
|
632
|
+
PROTOBASE_PREVIOUS_SECRETS=<the old secret>
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
The app then encrypts with the new secret and still decrypts what an old one encrypted, so it keeps signing with the same key, and the tokens in flight keep verifying. Keep an old secret listed:
|
|
636
|
+
|
|
637
|
+
- until the keys it encrypted have rotated out, `signingKeyDays` after the change: the next keys are encrypted with the new secret;
|
|
638
|
+
- while people use the [authenticator apps](#two-factor-authentication) they set up before the change, whose secrets it encrypted too, and, with `encryptOAuthTokens`, while the tokens it encrypted for social sign-ins are needed.
|
|
639
|
+
|
|
640
|
+
What the old secret signed stops working: session cookies, so everyone signs in again, and links already sent, such as invitations and download links. Give every instance the same secrets: an instance that knows only the old secret cannot read a key made with the new one.
|
|
641
|
+
|
|
612
642
|
## Users of another app
|
|
613
643
|
|
|
614
644
|
An API can admit the signed-in users of another Protobase app with the tokens that app issues, so that app's admin app can draw its resources as [remote resources](remote-resources.md). `authenticate.apps` lists each such app by its `url`, the issuer of its tokens, with the roles its users' global roles become here:
|
|
@@ -646,8 +676,10 @@ An app moving from Supabase keeps its `supabase.auth` calls and its `@supabase/s
|
|
|
646
676
|
There is no development login. For scripts, mint a token for an existing user on the host (the CLI exposes it as `protobase token you@example.com`):
|
|
647
677
|
|
|
648
678
|
```ts
|
|
679
|
+
import { loadProjectAuth } from '@protobase/cli/auth'
|
|
649
680
|
import { issueToken } from '@protobase/server'
|
|
650
681
|
|
|
682
|
+
const auth = await loadProjectAuth(process.cwd())
|
|
651
683
|
const { token, expiresAt } = await issueToken(auth, { email: 'you@example.com', ttlSeconds: 3600 }) // default 15 minutes, at most 24 hours
|
|
652
684
|
```
|
|
653
685
|
|
|
@@ -697,4 +729,4 @@ Only the Better Auth routes under `/api/auth/*` (sign-in, password reset, [open
|
|
|
697
729
|
|
|
698
730
|
Roles are bundles of capabilities (`defineRoles` in `@protobase/schema`: `orders.read.own`, `costs.read`, `*.read`, ...). Export the result as `roles` from `config/roles.ts`, where Protobase finds it, and every operation without an explicit rule needs the matching capability; a capability may be limited to [fields and rows](access.md#capabilities). The token's `roles` become `ctx.user.roles` in rules; the user id (`sub`) is what `.own` compares with the resource's `.owner(...)` field, so it must be the id that field stores. How the API enforces them (hidden fields, row filters, record permissions) is in [the REST API reference](api.md#access).
|
|
699
731
|
|
|
700
|
-
**User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`
|
|
732
|
+
**User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`tests/apps/erp/auth/hooks.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs sets `auth: { generateUserId: 'uuid' }` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as one in `auth/authenticate.ts` that returns the id of a row in its users table, declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
|
|
@@ -6,7 +6,7 @@ Every built-in layout block, its props and what it does, with examples from the
|
|
|
6
6
|
|
|
7
7
|
Blocks are imported from `@protobase/layout`. "Record" below means the record of the `RecordCard` or `CardRow` card around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort` AIP-132, as in the list API. Every block below but `RecordRow`, which the property portal's home uses, `RecordCards`, `Tabs` and `Tab`, `Settings`, and `Users`, which the [Users page](auth.md#users-page) uses, appears in the ERP example's sales overview:
|
|
8
8
|
|
|
9
|
-
```tsx title="
|
|
9
|
+
```tsx title="tests/apps/erp/config/overview/page.tsx"
|
|
10
10
|
/** @jsxImportSource @protobase/layout */
|
|
11
11
|
import { Action, Card, CardRow, Chart, Field, Grid, ModalForm, Page, RecordCard, Show, Stat, Table, component, page } from '@protobase/layout'
|
|
12
12
|
|
|
@@ -9,7 +9,7 @@ On phones the sidebar is a drawer behind the top bar's menu button. For people w
|
|
|
9
9
|
Export a [`bottomBar(...)`](https://docs.protobase.net/api/schema/functions/bottombar/) from the config module for each group of roles that gets one:
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
//
|
|
12
|
+
// tests/apps/erp/config/bottom-bar.ts, re-exported from config/index.ts
|
|
13
13
|
import { bottomBar } from '@protobase/schema'
|
|
14
14
|
|
|
15
15
|
export const warehouseBar = bottomBar({ label: 'Warehouse', roles: ['warehouse'] }, (m) => [
|
|
@@ -9,7 +9,7 @@ The `protobase` command comes with `@protobase/cli`. Install it in a project nex
|
|
|
9
9
|
```sh
|
|
10
10
|
bun add @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui
|
|
11
11
|
bun run protobase <command> # from the project, config folder defaults to ./config
|
|
12
|
-
bun run --cwd
|
|
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.
|
|
@@ -22,7 +22,7 @@ In this repository nothing needs a build: the packages' `exports` point at `src`
|
|
|
22
22
|
|
|
23
23
|
### In another process
|
|
24
24
|
|
|
25
|
-
A process that runs many commands, such as a deploy, can run them without starting the CLI each time. `@protobase/cli/runner` exports one function,
|
|
25
|
+
A process that runs many commands, such as a deploy, can run them without starting the CLI each time. `@protobase/cli/runner` exports one function for that; `@protobase/cli/auth` exports the other one a script may call, `loadProjectAuth`, which builds the project's sign-in as the `users` commands do (see [Auth](auth.md#first-run)). Nothing else of the CLI is exported:
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
28
|
import { runCommand } from '@protobase/cli/runner'
|
|
@@ -120,7 +120,7 @@ Exit code is 1 when there are errors. Run it after the project's migrations and
|
|
|
120
120
|
## `dev`
|
|
121
121
|
|
|
122
122
|
```sh
|
|
123
|
-
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd
|
|
123
|
+
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd tests/apps/erp dev
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and hands `/api`, supabase-js's `/api/sb` included, to the Hono app from `createAdmin`, which runs in a process of its own; the CLI's process never loads `@protobase/server`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
@@ -148,7 +148,7 @@ One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/a
|
|
|
148
148
|
## `build`
|
|
149
149
|
|
|
150
150
|
```sh
|
|
151
|
-
protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd
|
|
151
|
+
protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd tests/apps/erp protobase build
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
Writes the project's deploy bundle, the folder a deployment ships:
|
|
@@ -342,7 +342,7 @@ bun --no-install protobase-serve.js create-admin <bundle> <email> # --generat
|
|
|
342
342
|
```sh
|
|
343
343
|
bun --no-install protobase-serve.js <bundle>/protobase.config.js # production, under Bun: the API
|
|
344
344
|
protobase serve <bundle>/protobase.config.js # the same, with the CLI on Node or Bun
|
|
345
|
-
protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd
|
|
345
|
+
protobase serve <bundle> # the whole bundle as a host serves it, e.g. bun run --cwd tests/apps/erp serve
|
|
346
346
|
```
|
|
347
347
|
|
|
348
348
|
Serves the API of a bundle from `protobase build` and owns the process around it. Given the bundle folder, `protobase serve` also serves its UI by [the manifest's rules](#the-manifest), so a bundle can be checked locally exactly as the host will serve it.
|
|
@@ -357,7 +357,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
357
357
|
| `REQUEST_LOG` | `true` logs every request; default `false` |
|
|
358
358
|
| `PROTOBASE_SMTP_URL` | the SMTP server for password-reset mail, emailed sign-in and two-factor codes and the app's own [email](email.md), credential included: `smtp://user:password@host:587` (STARTTLS when offered) or `smtps://...:465`; without it they are off ([Password reset](auth.md#password-reset), [Emailed sign-in codes](auth.md#emailed-sign-in-codes)) |
|
|
359
359
|
| `PROTOBASE_MAIL_FROM` | the sender of that mail, a plain address such as `noreply@admin.example.com`; set with `PROTOBASE_SMTP_URL` or not at all |
|
|
360
|
-
| `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config.md#
|
|
360
|
+
| `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config/app.md#name) |
|
|
361
361
|
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME` are optional ([Platform sign-in provider](auth.md#platform-sign-in-provider)) |
|
|
362
362
|
| `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the OpenID Connect provider of the operator's staff, for [staff sign-in](auth.md#staff-sign-in) as people of the app; all three or none. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional ([Operator provider](auth.md#operator-provider)) |
|
|
363
363
|
| `PROTOBASE_ORIGINS`, `PROTOBASE_PASSKEY_DOMAIN` | the other origins the app is served on, comma separated, and the host new passkeys are made for ([Several origins](auth.md#several-origins)) |
|
|
@@ -377,7 +377,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
377
377
|
| `PROTOBASE_MOBILE_SIGNING_KEY` | an RSA private key of at least 2048 bits, PEM, its newlines real or written `\n`, that signs every file of the [mobile release](#mobile-releases) in `X-Signature`, for an app whose updater checks signatures with the matching public key; another kind of key, or a shorter one, stops startup |
|
|
378
378
|
| `PROTOBASE_JOBS_DRAIN_TOKEN` | the operator's bearer token for `POST /api/jobs/drain`, which [runs the due jobs](jobs.md#hosts-that-sleep) of a host that lets the app sleep; without it there is no such endpoint |
|
|
379
379
|
|
|
380
|
-
The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [
|
|
380
|
+
The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless its config sets `url` and `secret` (see [App options](config/app.md)); its other settings are the project's own variables, read by its config, which the runtime reads again at start with the host's environment. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
|
|
381
381
|
|
|
382
382
|
- **Routes:** `createAdmin` (`/api/v1`, `/api/meta`, `/api/functions/*`, `/api/auth/*`, ...) and `GET /health`, which answers `{"status":"ok"}` without a token and without touching the database. The runtime never serves the UI; `protobase serve <bundle>` serves `public/` for every path outside the manifest's `api` and `/.well-known/webauthn`, after `/health`, with `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, so no other site frames its pages.
|
|
383
383
|
- **Plugins:** the runtime reads the manifest's `plugins`: `/api/meta` names them, and a view that shows a field with one of their [field types](plugins.md#field-types) that does not show the field's storage type stops startup, naming the view, the field and what the field type shows.
|
|
@@ -561,10 +561,10 @@ Copies the agent skills of this CLI's version into the current project, or only
|
|
|
561
561
|
## ERP example
|
|
562
562
|
|
|
563
563
|
```sh
|
|
564
|
-
bun run db:up && bun run --cwd
|
|
565
|
-
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 \
|
|
566
566
|
--yes --ui --exclude auth --exclude public.schema_migrations --exclude public.seed_info
|
|
567
|
-
bun run --cwd
|
|
567
|
+
bun run --cwd tests/apps/erp protobase doctor postgres://protobase:protobase@localhost:55432/protobase
|
|
568
568
|
```
|
|
569
569
|
|
|
570
570
|
Always pass `--exclude auth`: the ERP keeps Better Auth's users, sessions and signing keys in the `auth` schema of the same database, and scaffolding them would expose credentials through the admin API.
|
|
@@ -23,7 +23,7 @@ With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/
|
|
|
23
23
|
|
|
24
24
|
## The admin app
|
|
25
25
|
|
|
26
|
-
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `
|
|
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/`.
|
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config/api.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# API options
|
|
4
|
+
|
|
5
|
+
The config keys of the REST API, its path, keys, CORS, access defaults, query limits, error reporting, write hooks, MCP tools, remote resources and runtime updates, and the files of the API's own hooks.
|
|
6
|
+
|
|
7
|
+
The keys of the API, at the top level of [`protobase.config.ts`](../config.md). The API itself is described in [REST API](../api.md).
|
|
8
|
+
|
|
9
|
+
## apiPath
|
|
10
|
+
|
|
11
|
+
- **Type:** `string`
|
|
12
|
+
- **Default:** `/api/v1`
|
|
13
|
+
|
|
14
|
+
The path of the REST API on the app's origin.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
export default defineConfig({ apiPath: '/api/v2' })
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## apiKeys
|
|
21
|
+
|
|
22
|
+
- **Type:** `{ publishable_key?: string; secret_key?: string } | false`
|
|
23
|
+
- **Default:** `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`
|
|
24
|
+
- **Environment variables:** `PROTOBASE_PUBLISHABLE_KEY`, `PROTOBASE_SECRET_KEY`
|
|
25
|
+
|
|
26
|
+
The app's two keys, for clients that call it the way they call Supabase: with one, the app serves the PostgREST-compatible `/api/sb/rest/v1`, the Realtime-compatible `/api/sb/realtime/v1` and the Storage-compatible `/api/sb/storage/v1`. The publishable key is safe in a browser and makes a request anonymous or its signed-in user's; the secret key stays on servers and makes a request the app's own. A publishable key that looks like a secret one, the other way round, or both the same stop the app at start. Without either, or with `false`, the app serves none of them. See [Supabase client API](../supabase-rest.md).
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export default defineConfig(({ env }) => ({
|
|
30
|
+
apiKeys: { publishable_key: env.PUBLISHABLE_KEY, secret_key: env.SECRET_KEY },
|
|
31
|
+
}))
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## cors
|
|
35
|
+
|
|
36
|
+
- **Type:** `'*' | string[]`
|
|
37
|
+
- **Default:** `PROTOBASE_CORS_ORIGINS`, `*` or comma separated, when set
|
|
38
|
+
- **Environment variable:** `PROTOBASE_CORS_ORIGINS`
|
|
39
|
+
|
|
40
|
+
The websites whose browser code may call the API (`/api/*` but `/api/auth/*`) besides the app's own origins: a list of origins, or `*` for any. A [`mobile`](app.md#mobile) section adds the app's Capacitor origins. With none, the API sends no CORS headers for other websites. See [CORS](../api.md#cors).
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
export default defineConfig({ cors: ['https://shop.example.com'] })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## defaultAccess
|
|
47
|
+
|
|
48
|
+
- **Type:** `'allow' | 'deny'`
|
|
49
|
+
- **Default:** without roles, `allow`; with roles, the capability check
|
|
50
|
+
|
|
51
|
+
What an operation without an access rule does, over the capability check of the roles in `config/roles.ts`. `allow` together with roles opens such operations to every user, and the app warns about it at start. See [Access](../access.md).
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export default defineConfig({ defaultAccess: 'deny' })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## rowPermissions
|
|
58
|
+
|
|
59
|
+
- **Type:** `boolean | { except: string[] }`
|
|
60
|
+
- **Default:** `true`
|
|
61
|
+
|
|
62
|
+
Whether list items carry their `permissions` (update, delete), or `{ except: [...] }` for the resources that leave them out. See [Record permissions](../api.md#record-permissions).
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
export default defineConfig({ rowPermissions: { except: ['events'] } })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## statementTimeoutMs
|
|
69
|
+
|
|
70
|
+
- **Type:** `number`
|
|
71
|
+
- **Default:** `1000`
|
|
72
|
+
|
|
73
|
+
How long a query of an API request may run, in milliseconds; a query that runs longer answers `504` and names the request. A query that needs longer wants an index or a simpler filter, or belongs in a function or a job with `longQueries`. See [Safety](../api.md#safety).
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
export default defineConfig({ statementTimeoutMs: 3000 })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## scanGuard
|
|
80
|
+
|
|
81
|
+
- **Type:** `{ mode?: 'reject' | 'warn' | 'off' }`
|
|
82
|
+
- **Default:** `{ mode: 'reject' }`
|
|
83
|
+
|
|
84
|
+
What the API does with reads that filter, sort or count by a column no index serves: refuse them, let them through with a warning, or let them through. See [Safety](../api.md#safety).
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
export default defineConfig({ scanGuard: { mode: 'warn' } })
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## errorReporting
|
|
91
|
+
|
|
92
|
+
- **Type:** `{ dsn?: string; environment?: string } | false`
|
|
93
|
+
- **Default:** the DSN in `PROTOBASE_SENTRY_DSN`, when set
|
|
94
|
+
- **Environment variable:** `PROTOBASE_SENTRY_DSN`
|
|
95
|
+
|
|
96
|
+
Where the app's errors go: the server's `500`s, stopped queries and crashes, and the admin app's errors in the browser. `dsn` is a project's DSN in Sentry or a tracker that speaks its protocol, such as Bugsink or GlitchTip; `environment` names the deployment there. `false` turns it off. A DSN without a public key or a project id stops the app at start. See [Error reporting](../api.md#error-reporting).
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
export default defineConfig(({ command }) => ({
|
|
100
|
+
errorReporting: command === 'dev' ? false : { environment: 'staging' },
|
|
101
|
+
}))
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## writeHooks
|
|
105
|
+
|
|
106
|
+
- **Type:** `string[]`
|
|
107
|
+
- **Default:** none
|
|
108
|
+
|
|
109
|
+
The write hooks by name, run in this order inside each create's, update's and delete's transaction, with that transaction. Each is the default export of `hooks/<name>.ts`, loaded on the first write; a name without its file stops the app at start with an error that names the file. A hook does database work only: while it waits on anything else, such as an HTTP call, the row stays locked, so it enqueues a job for such work. [Enqueueing](../jobs.md#enqueueing) shows a hook that does.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
export default defineConfig({ writeHooks: ['queue-sent-invoice'] })
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## mcpEndpoint
|
|
116
|
+
|
|
117
|
+
- **Type:** `{ sql?: boolean; writes?: boolean | { resources?: string[]; rolesWithoutApproval?: string[] } } | false`
|
|
118
|
+
- **Default:** the read tools only: `list_resources`, `list_records` and `get_record`
|
|
119
|
+
|
|
120
|
+
The MCP endpoint's tools; [`auth.mcp`](sign-in.md#authmcp) turns the endpoint on. `sql: true` also offers admins and the `ai` role `run_read_only_query`, which reads the whole database outside the access rules. `writes: true` offers `create_record` and `update_record` through the REST API's rules, each approved by the person in their client; `writes.resources` limits them to the resources named, and `writes.rolesWithoutApproval` lets holders of those roles, such as a service account, write without the approval. `false` is for a host that serves its own MCP endpoint at `auth.mcp.path`, in front of this app. See [MCP](../mcp.md#the-tools).
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: { resources: ['tasks'] } } })
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## remoteResources
|
|
127
|
+
|
|
128
|
+
- **Type:** `{ url: string; label: string; resources: string[]; roles?: string[] }[] | false`
|
|
129
|
+
- **Default:** those `PROTOBASE_SOURCES` lists
|
|
130
|
+
- **Environment variable:** `PROTOBASE_SOURCES`, a JSON list of the same objects, added after the config's
|
|
131
|
+
|
|
132
|
+
Other Protobase APIs whose resources the admin app draws as its own. `url` is the other API's resources API, such as `https://other.example.com/api/v1`; `label` names it to people when it cannot be reached; `resources` are the ones drawn from it; with `roles`, only callers holding one of them see it. `false` turns off both the config's and the variable's. See [Remote resources](../remote-resources.md#declaring-a-source).
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
export default defineConfig({
|
|
136
|
+
remoteResources: [{ url: 'https://crm.example.com/api/v1', label: 'CRM', resources: ['contacts'] }],
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## runtimeUpdates
|
|
141
|
+
|
|
142
|
+
- **Type:** `{ url?: string } | false`
|
|
143
|
+
- **Default:** `PROTOBASE_RUNTIME_URL`, when set
|
|
144
|
+
- **Environment variable:** `PROTOBASE_RUNTIME_URL`
|
|
145
|
+
|
|
146
|
+
The endpoint that reports the app's runtime version and updates it, such as a hosting platform's; the top bar shows an update button to admins from what it answers. `false` turns it off. See [Runtime updates](../versioning.md#runtime-updates).
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
export default defineConfig({ runtimeUpdates: false })
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Code of the API
|
|
153
|
+
|
|
154
|
+
Two files of the project's own change what the API does, each its default export, with no key in the config:
|
|
155
|
+
|
|
156
|
+
- `hooks/error.ts`: called with every error the API answers `500` for, every query stopped at its statement timeout and every request that found all database connections busy, and the request it failed, so the app can report it. See [Errors](../api.md#errors).
|
|
157
|
+
- `audit/queue.ts`: the `AuditQueue` that receives an event for every reveal of a sensitive field; without it, each is printed to the console and nothing is kept. See [Sensitive fields and audit](../api.md#sensitive-fields-and-audit).
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
// hooks/error.ts
|
|
161
|
+
export default (error: unknown, request?: Request) => {
|
|
162
|
+
console.error(request?.url, error)
|
|
163
|
+
}
|
|
164
|
+
```
|