@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.
Files changed (53) hide show
  1. package/dist/cli/package.js +1 -1
  2. package/package.json +6 -6
  3. package/skills/protobase/references/getting-started.md +8 -8
  4. package/skills/protobase/references/guides/api-functions.md +12 -12
  5. package/skills/protobase/references/guides/billing-page.md +2 -2
  6. package/skills/protobase/references/guides/create-page.md +5 -5
  7. package/skills/protobase/references/guides/deploy.md +6 -6
  8. package/skills/protobase/references/guides/export-a-list.md +2 -2
  9. package/skills/protobase/references/guides/field-type.md +2 -2
  10. package/skills/protobase/references/guides/first-composed-page.md +4 -4
  11. package/skills/protobase/references/guides/first-plugin.md +3 -3
  12. package/skills/protobase/references/guides/import-records.md +1 -1
  13. package/skills/protobase/references/guides/mobile-app.md +11 -4
  14. package/skills/protobase/references/guides/plugin-build.md +5 -5
  15. package/skills/protobase/references/guides/record-card.md +3 -3
  16. package/skills/protobase/references/guides/remote-resources.md +10 -10
  17. package/skills/protobase/references/guides/table-to-admin.md +5 -5
  18. package/skills/protobase/references/guides/theme-an-app.md +4 -4
  19. package/skills/protobase/references/reference/access.md +9 -9
  20. package/skills/protobase/references/reference/ai.md +6 -6
  21. package/skills/protobase/references/reference/api.md +25 -25
  22. package/skills/protobase/references/reference/app-identity.md +4 -4
  23. package/skills/protobase/references/reference/architecture.md +1 -1
  24. package/skills/protobase/references/reference/assistant.md +6 -6
  25. package/skills/protobase/references/reference/auth.md +20 -20
  26. package/skills/protobase/references/reference/blocks.md +18 -13
  27. package/skills/protobase/references/reference/bottom-bar.md +5 -5
  28. package/skills/protobase/references/reference/cli.md +63 -63
  29. package/skills/protobase/references/reference/client.md +5 -5
  30. package/skills/protobase/references/reference/comments.md +8 -8
  31. package/skills/protobase/references/reference/custom-components.md +18 -18
  32. package/skills/protobase/references/reference/data-config.md +26 -26
  33. package/skills/protobase/references/reference/email.md +8 -8
  34. package/skills/protobase/references/reference/events.md +5 -5
  35. package/skills/protobase/references/reference/files.md +7 -7
  36. package/skills/protobase/references/reference/forms.md +6 -6
  37. package/skills/protobase/references/reference/history.md +7 -7
  38. package/skills/protobase/references/reference/installable-app.md +1 -1
  39. package/skills/protobase/references/reference/jobs.md +5 -5
  40. package/skills/protobase/references/reference/layouts.md +11 -11
  41. package/skills/protobase/references/reference/live.md +4 -4
  42. package/skills/protobase/references/reference/mcp.md +5 -5
  43. package/skills/protobase/references/reference/plugins.md +20 -20
  44. package/skills/protobase/references/reference/remote-resources.md +15 -15
  45. package/skills/protobase/references/reference/sidebar.md +1 -1
  46. package/skills/protobase/references/reference/supabase-realtime.md +2 -2
  47. package/skills/protobase/references/reference/supabase-rest.md +2 -2
  48. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  49. package/skills/protobase/references/reference/theme.md +5 -5
  50. package/skills/protobase/references/reference/ui-config.md +60 -60
  51. package/skills/protobase/references/reference/user-menu.md +3 -3
  52. package/skills/protobase/references/reference/versioning.md +5 -5
  53. package/skills/protobase/references/reference/webhooks.md +7 -7
@@ -84,7 +84,7 @@ A job runs **at least once**: a worker that dies mid-job, or a try cut off by a
84
84
  await sendInvoice.enqueue(db, { invoiceId: 7 }, { delay: '5 minutes', key: 'invoice:7', priority: 10 })
85
85
  ```
86
86
 
87
- `db` is the app's database, or the transaction of a write hook or an [API function](../guides/api-functions.md)): there, the job commits with the caller's writes, or not at all. It returns the job's id.
87
+ `db` is the app's database, or the transaction of a write hook or an [API function](../guides/api-functions.md): there, the job commits with the caller's writes, or not at all. It returns the job's id.
88
88
 
89
89
  | Option | |
90
90
  | --- | --- |
@@ -111,7 +111,7 @@ select jobs.enqueue('sync-customer', '{"customerId": 3, "fields": ["email"]}', g
111
111
 
112
112
  ## Mail
113
113
 
114
- `mail.send({ to, subject, text, html })` sends one message, with an optional HTML part beside the plain text, through the app's SMTP server, the one that also sends password resets and sign-in codes: `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (see [Email](email.md#configuration))). An [email template](email.md#templates)) sends through it with `template.send(to, data, mail)`. It rejects when the server refuses the message, so the try fails and is retried. Without those variables `mail` is `undefined`: a job that must send fails for good with `FatalJobError`, and one that may skip mail leaves it out.
114
+ `mail.send({ to, subject, text, html })` sends one message, with an optional HTML part beside the plain text, through the app's SMTP server, the one that also sends password resets and sign-in codes: `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (see [Email](email.md#configuration)). An [email template](email.md#templates) sends through it with `template.send(to, data, mail)`. It rejects when the server refuses the message, so the try fails and is retried. Without those variables `mail` is `undefined`: a job that must send fails for good with `FatalJobError`, and one that may skip mail leaves it out.
115
115
 
116
116
  ```ts
117
117
  run: async ({ invoiceId }, { db, mail }) => {
@@ -152,7 +152,7 @@ With jobs, the admin app has a **Failed jobs** page, for admins only: each job t
152
152
 
153
153
  - **`protobase dev`** runs them in its process. An edited job runs its new code from the next job on.
154
154
  - **`protobase serve`** runs them in its process, beside the API, unless `PROTOBASE_JOBS=false`; it enqueues them either way. On SIGTERM it stops taking jobs and gives running ones 30 seconds to finish. A job still running then is failed, to be retried.
155
- - **[`protobase worker <bundle>`](cli.md#worker))** runs the same jobs from the same bundle in a process of its own, with the same shutdown, for a `serve` with `PROTOBASE_JOBS=false`.
155
+ - **[`protobase worker <bundle>`](cli.md#worker)** runs the same jobs from the same bundle in a process of its own, with the same shutdown, for a `serve` with `PROTOBASE_JOBS=false`.
156
156
  - Each worker checks every job name for due jobs every 2 seconds: one indexed query per job name and interval. Once a minute, one of the workers also counts the queues and retries the jobs whose worker died (their `timeout` passed); once a day it deletes completed and failed jobs older than 7 days.
157
157
 
158
158
  ### Hosts that sleep
@@ -164,13 +164,13 @@ A host that stops an idle app needs to know when a job is due, and to have it ru
164
164
 
165
165
  ## The `jobs` schema
166
166
 
167
- The schema is pg-boss's tables at its pinned schema version, plus Protobase's `jobs.enqueue`, `jobs.next_due` and `jobs.failed`. It is created and upgraded like the [auth schema](auth.md#migrations)), by the project's migrations:
167
+ The schema is pg-boss's tables at its pinned schema version, plus Protobase's `jobs.enqueue`, `jobs.next_due` and `jobs.failed`. It is created and upgraded like the [auth schema](auth.md#migrations), by the project's migrations:
168
168
 
169
169
  ```sh
170
170
  bun run protobase migration # writes db/migrations/NNN_jobs.sql when the jobs schema is missing or behind
171
171
  bun run db:migrate
172
172
  ```
173
173
 
174
- [`protobase migration`](cli.md#migration)) writes what the database lacks, taken from pg-boss's own construction and migration plans for the pinned version, without their `BEGIN` and `COMMIT` and with any `CONCURRENTLY` index build made a plain one, so the file runs in the project's migration transaction. The server never creates or migrates it: `protobase dev` and `protobase serve` read its version at startup and refuse to start while it is missing or behind, naming the command. A database whose jobs schema is newer than the running Protobase is refused too.
174
+ [`protobase migration`](cli.md#migration) writes what the database lacks, taken from pg-boss's own construction and migration plans for the pinned version, without their `BEGIN` and `COMMIT` and with any `CONCURRENTLY` index build made a plain one, so the file runs in the project's migration transaction. The server never creates or migrates it: `protobase dev` and `protobase serve` read its version at startup and refuse to start while it is missing or behind, naming the command. A database whose jobs schema is newer than the running Protobase is refused too.
175
175
 
176
176
  pg-boss runs here without what needs a session of its own: no `LISTEN`/`NOTIFY` (a job enqueued in the same process wakes its worker directly, the rest is polled), only transaction-scoped advisory locks, unnamed prepared statements, no index rebuilds and no instance registry. It works through PgBouncer in transaction mode and on PGlite, over the app's own connection pool.
@@ -4,7 +4,7 @@
4
4
 
5
5
  Composed pages from JSX layouts, the element tree they compile to, what they may hold, and how data, conditions, actions and access work in them.
6
6
 
7
- A composed page is a layout file in the config, written in JSX and compiled to plain data. The server checks it against the resources, serves it to each user in `/api/meta` without what they may not see, and the admin renders it from blocks that read the regular API. [Your first composed page](../guides/first-composed-page.md)) builds one step by step; this page is the reference.
7
+ A composed page is a layout file in the config, written in JSX and compiled to plain data. The server checks it against the resources, serves it to each user in `/api/meta` without what they may not see, and the admin renders it from blocks that read the regular API. [Your first composed page](../guides/first-composed-page.md) builds one step by step; this page is the reference.
8
8
 
9
9
  ## Setup
10
10
 
@@ -26,10 +26,10 @@ The comment makes `@protobase/layout/jsx-runtime` compile the file instead of Re
26
26
  | `name` | The address: the page is at `/<name>`, beside the resources, so a resource may not have the same name. Lowercase first letter, then letters, digits and dashes. |
27
27
  | `tree` | One `<Page>` element. |
28
28
  | `options.nav` | `{ group, order, hidden }`, as for views. A page without a group is in "Pages"; groups that hold pages come first in the sidebar. |
29
- | `options.icon` | One of the [user menu icons](user-menu.md)), or `layout-dashboard` (the default). |
29
+ | `options.icon` | One of the [user menu icons](user-menu.md), or `layout-dashboard` (the default). |
30
30
  | `options.roles` | Only users with one of these roles get the page. Without it, everyone who can sign in does. |
31
31
 
32
- A page can also sit in the [user menu](user-menu.md)) with `m.page(name)`; it then leaves the sidebar. The first page is where the admin opens.
32
+ A page can also sit in the [user menu](user-menu.md) with `m.page(name)`; it then leaves the sidebar. The first page is where the admin opens.
33
33
 
34
34
  ## The element tree
35
35
 
@@ -52,7 +52,7 @@ A prop is a string, a finite number, a boolean, `null`, or an array or plain obj
52
52
  - **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. No project code runs for this.
53
53
  - **When the config loads.** The JSX runtime refuses anything else that is not plain data (a function in a variable, a `Date`, a `Map`, `NaN`), `page()` checks every element's props against its block (unknown, missing and mistyped props, children where none are allowed, elements that need a record outside one), and `createAdmin` checks every resource, field, filter, sort, action and condition against the models. Each problem names its place, such as `Page "overview": <Page> › <Table resource="invoices">: unknown column "amount" on invoices`.
54
54
 
55
- Behaviour comes from [named actions](#named-actions); React code from [custom components](custom-components.md)).
55
+ Behaviour comes from [named actions](#named-actions); React code from [custom components](custom-components.md).
56
56
 
57
57
  ## Data
58
58
 
@@ -71,7 +71,7 @@ A `RecordCard` (its first match) and each card of a `CardRow` hold a **record**.
71
71
 
72
72
  Comparisons, `AND`, `OR`, `NOT` and parentheses work; functions such as `now()` do not. A field that is missing or that the user cannot read makes the comparison false, and a `Show` that names a resource or field the user cannot see is left out of their page.
73
73
 
74
- Record pages take the same conditions in the `when` of `l.section`, `l.related` and `l.sidebar`; see [Form and read view](ui-config.md#form-and-read-view)).
74
+ Record pages take the same conditions in the `when` of `l.section`, `l.related` and `l.sidebar`; see [Form and read view](ui-config.md#form-and-read-view).
75
75
 
76
76
  ## Named actions
77
77
 
@@ -83,10 +83,10 @@ Record pages take the same conditions in the `when` of `l.section`, `l.related`
83
83
  | `a.remove(name, { label, confirm?, icon? })` | Deletes the record (soft delete when the resource has one). |
84
84
  | `a.link(name, { label, to, icon? })` | Goes `to` an [address](#addresses) in the app, with `{field}` in its key, filter, order or create values replaced by the record's value. |
85
85
  | `a.link(name, { label, href, icon? })` | Opens an `href` that leaves the app (`https:`, `mailto:`), with `{field}` replaced by the record's value (percent-encoded); an `https:` or `http:` link opens in a new tab without the referrer. An `href` that is only a field, `'{website}'`, opens the URL the record holds, as it is: see [links to a record's URL](#links-to-a-records-url). A path in the app is refused when the config loads: give it as `to`. |
86
- | `a.ai(name, { label, prompt, writes, confirm?, icon? })` | Has the model write the field `writes` of the record from `prompt`, `{field}` replaced by the record's values, as the user, on the server; see [AI fields and actions](ai.md#ai-actions)). |
87
- | `a.action(name, { label, confirm?, icon?, bulk?, inputs? })` | Runs the handler the app registers under `name` in [`protobase.ui.tsx`](custom-components.md#action-handlers)), after asking for its [`inputs`](ui-config.md#actions-that-ask-for-input)) in a dialog when it has some. |
86
+ | `a.ai(name, { label, prompt, writes, confirm?, icon? })` | Has the model write the field `writes` of the record from `prompt`, `{field}` replaced by the record's values, as the user, on the server; see [AI fields and actions](ai.md#ai-actions). |
87
+ | `a.action(name, { label, confirm?, icon?, bulk?, inputs? })` | Runs the handler the app registers under `name` in [`protobase.ui.tsx`](custom-components.md#action-handlers), after asking for its [`inputs`](ui-config.md#actions-that-ask-for-input) in a dialog when it has some. |
88
88
 
89
- `icon` is one of `archive`, `arrow-right-left`, `ban`, `bath`, `bed`, `bell`, `bookmark`, `calendar`, `camera`, `copy`, `cpu`, `door-open`, `download`, `external-link`, `file-text`, `hard-drive`, `heart`, `house`, `key`, `land-plot`, `leaf`, `memory`, `network`, `play`, `plug`, `power`, `restart`, `ruler`, `send`, `server`, `stop`, `tag`, `terminal`, `upload`, `wallet` or `wrench`; another name shows a lightning bolt. With `confirm` the button asks first. Every builder also takes `when`, `otherwise` and `reason`, which limit the action to the records it [applies to](ui-config.md#where-an-action-applies)), and `variant: 'danger'`, which draws it in red. The button is disabled, with the reason as its tooltip, when the user may not update or delete the record (or, for an AI action, the field it writes), when an `a.action` has no handler, or when an update, delete or AI action has no record. After an action, everything shown of that resource reloads. The record page's action rail runs the same actions the same way.
89
+ `icon` is one of `archive`, `arrow-right-left`, `ban`, `bath`, `bed`, `bell`, `bookmark`, `calendar`, `camera`, `copy`, `cpu`, `door-open`, `download`, `external-link`, `file-text`, `hard-drive`, `heart`, `house`, `key`, `land-plot`, `leaf`, `memory`, `network`, `play`, `plug`, `power`, `restart`, `ruler`, `send`, `server`, `stop`, `tag`, `terminal`, `upload`, `wallet` or `wrench`; another name shows a lightning bolt. With `confirm` the button asks first. Every builder also takes `when`, `otherwise` and `reason`, which limit the action to the records it [applies to](ui-config.md#where-an-action-applies), and `variant: 'danger'`, which draws it in red. The button is disabled, with the reason as its tooltip, when the user may not update or delete the record (or, for an AI action, the field it writes), when an `a.action` has no handler, or when an update, delete or AI action has no record. After an action, everything shown of that resource reloads. The record page's action rail runs the same actions the same way.
90
90
 
91
91
  ### Links to a record's URL
92
92
 
@@ -104,9 +104,9 @@ Every place in the app has an address, and the app writes and reads them in one
104
104
 
105
105
  | Address | Is |
106
106
  | --- | --- |
107
- | `{ kind: 'list', resource, filter?, orderBy?, display? }` | A resource's list, with the filter, order and [display](ui-config.md#list-displays)) the list page would show. |
108
- | `{ kind: 'record', resource, key, edit?, open? }` | One record; `key` is its value, or its parts for a composite key. `edit: true` is its form (`?edit=true`), on a view whose record page opens as a [read view or locked](ui-config.md#read-view-and-edit)). `open` lists the titles of the record page's collapsed [groups](ui-config.md#groups)) that are open (`?open=<title>`, once per group). |
109
- | `{ kind: 'create', resource, values? }` | The form for a new record, with `values` filled in by field name, as text: `{ kind: 'create', resource: 'notes', values: { listing_id: '{id}' } }` on a listing's page starts a note about that listing. A relation shows the name of the record it points at. The values are a start the person can change, not a rule: what they may write is still up to the access rules. A view with a [create page](ui-config.md#create-pages)) shows that page here instead, with the values in the address. |
107
+ | `{ kind: 'list', resource, filter?, orderBy?, display? }` | A resource's list, with the filter, order and [display](ui-config.md#list-displays) the list page would show. |
108
+ | `{ kind: 'record', resource, key, edit?, open? }` | One record; `key` is its value, or its parts for a composite key. `edit: true` is its form (`?edit=true`), on a view whose record page opens as a [read view or locked](ui-config.md#read-view-and-edit). `open` lists the titles of the record page's collapsed [groups](ui-config.md#groups) that are open (`?open=<title>`, once per group). |
109
+ | `{ kind: 'create', resource, values? }` | The form for a new record, with `values` filled in by field name, as text: `{ kind: 'create', resource: 'notes', values: { listing_id: '{id}' } }` on a listing's page starts a note about that listing. A relation shows the name of the record it points at. The values are a start the person can change, not a rule: what they may write is still up to the access rules. A view with a [create page](ui-config.md#create-pages) shows that page here instead, with the values in the address. |
110
110
  | `{ kind: 'page', page }` | A composed page. |
111
111
 
112
112
  The resources, pages and fields an address names are checked when the server starts, like every other name.
@@ -4,7 +4,7 @@
4
4
 
5
5
  Open lists and record pages refresh as soon as a record of a live resource changes, through the API or not, each reader seeing only what they may read.
6
6
 
7
- A resource with [`.live()`](https://docs.protobase.net/api/schema/interfaces/resourcebuilder/#live)) keeps the pages people have open on its records current: when a record changes, every open list, record page, count and chart of the resource reads it again within a second or two, without a reload. The changes are captured by the same database triggers as [events](events.md)), so writes from psql, other services and cron SQL show up too, not only those through the API.
7
+ A resource with [`.live()`](https://docs.protobase.net/api/schema/interfaces/resourcebuilder/#live) keeps the pages people have open on its records current: when a record changes, every open list, record page, count and chart of the resource reads it again within a second or two, without a reload. The changes are captured by the same database triggers as [events](events.md), so writes from psql, other services and cron SQL show up too, not only those through the API.
8
8
 
9
9
  ```ts title="config/tasks.ts"
10
10
  import { f, resource } from '@protobase/schema'
@@ -41,10 +41,10 @@ It is live data, not multiplayer editing: two people editing the same record sti
41
41
  | `changes` | `changes`: `[{ resource, key, operation }]` in commit order, `operation` being `create`, `update`, `delete` or `undelete`. |
42
42
  | `resync` | Changes went by that are no longer kept: read everything shown again. |
43
43
 
44
- Connecting again with `?after=<cursor>` catches up on what was missed while disconnected. [`client.live({ onChanges, onResync })`](client.md)) of `@protobase/client` follows the stream and connects again by itself, as the app does.
44
+ Connecting again with `?after=<cursor>` catches up on what was missed while disconnected. [`client.live({ onChanges, onResync })`](client.md) of `@protobase/client` follows the stream and connects again by itself, as the app does.
45
45
 
46
46
  ## The table
47
47
 
48
- [`protobase migration`](cli.md#migration)) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
48
+ [`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
49
49
 
50
- A notice is a resource, a record key, the record's tenant and the operation, written by the `changes.dispatch` job in the transaction that removes the change from the outbox; a live resource therefore needs the [`jobs` schema](jobs.md#the-jobs-schema)) and the app's workers. Notices are kept for 10 minutes. Each serving process with at least one page open reads the table once a second, however many pages it serves, so live updates work with several serving processes, with `PROTOBASE_JOBS=false` and through a pooler in transaction mode.
50
+ A notice is a resource, a record key, the record's tenant and the operation, written by the `changes.dispatch` job in the transaction that removes the change from the outbox; a live resource therefore needs the [`jobs` schema](jobs.md#the-jobs-schema) and the app's workers. Notices are kept for 10 minutes. Each serving process with at least one page open reads the table once a second, however many pages it serves, so live updates work with several serving processes, with `PROTOBASE_JOBS=false` and through a pooler in transaction mode.
@@ -14,7 +14,7 @@ One option of `createAuth` turns it on:
14
14
  createAuth({ ..., mcp: true })
15
15
  ```
16
16
 
17
- Run `protobase auth migration` after turning it on, for the OAuth tables. The endpoint is `https://<app>/api/mcp`, or the path `mcp.path` names. How clients register, how people sign in and allow them, and how they disconnect them is in [OAuth for MCP clients](auth.md#oauth-for-mcp-clients)).
17
+ Run `protobase auth migration` after turning it on, for the OAuth tables. The endpoint is `https://<app>/api/mcp`, or the path `mcp.path` names. How clients register, how people sign in and allow them, and how they disconnect them is in [OAuth for MCP clients](auth.md#oauth-for-mcp-clients).
18
18
 
19
19
  ## Connecting a client
20
20
 
@@ -31,19 +31,19 @@ Give the client the endpoint's address. It finds the app's sign-in from there, o
31
31
 
32
32
  ## The tools
33
33
 
34
- Each tool reads as the signed-in person: their role's access rules, row filters, tenant and hidden fields apply as in the [REST API](api.md#access)).
34
+ Each tool reads as the signed-in person: their role's access rules, row filters, tenant and hidden fields apply as in the [REST API](api.md#access).
35
35
 
36
36
  | Tool | What it does |
37
37
  | --- | --- |
38
38
  | `list_resources` | The resources the person may read, with their labels, key and fields: each field's type, label, enum values, the resource a relation links to, and whether filters and sorts take it. |
39
- | `list_records` | A page of a resource's records: `filter` in the API's [filter syntax](api.md#filters)), `order_by`, `page_size` (20 by default, at most 100) and `page_token`, with `next_page_token` for the next page. |
39
+ | `list_records` | A page of a resource's records: `filter` in the API's [filter syntax](api.md#filters), `order_by`, `page_size` (20 by default, at most 100) and `page_token`, with `next_page_token` for the next page. |
40
40
  | `get_record` | One record by its key, with its ETag. A composite key is passed as the values of its fields, in order. |
41
41
 
42
42
  A refusal, such as a resource the person may not read or a bad filter, comes back to the client as text it can act on, `{ "error": ..., "message": ... }`.
43
43
 
44
44
  ### SQL for admins
45
45
 
46
- `createAdmin`'s `options.mcp.sql` also offers `run_read_only_query`, as in the [assistant](assistant.md#the-built-in-backend)), to people with the `admin` or `ai` role:
46
+ `createAdmin`'s `options.mcp.sql` also offers `run_read_only_query`, as in the [assistant](assistant.md#the-built-in-backend), to people with the `admin` or `ai` role:
47
47
 
48
48
  ```ts
49
49
  createAdmin({ ..., auth, options: { mcp: { sql: true } } })
@@ -81,7 +81,7 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
81
81
  `@protobase/server` exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:
82
82
 
83
83
  - `mcpHandler({ authenticate, resource, scope, server })`: the endpoint as a fetch handler. It checks the host, admits a valid token (`mcpGate`) and serves the request with the server that `server(session)` builds for its caller.
84
- - `mcpServer({ info, tools, context, report })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools)), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`: each call gets its own, which asks the client's user.
84
+ - `mcpServer({ info, tools, context, report })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`: each call gets its own, which asks the client's user.
85
85
  - `mcpTools({ db, sql, writes })`: the default tools for a session.
86
86
  - `writeRecordTools()`, or `createRecordTool()` and `updateRecordTool()`: the write tools alone.
87
87
  - `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
@@ -4,19 +4,19 @@
4
4
 
5
5
  React code the admin app loads when it starts instead of building it in, so it keeps working while Protobase moves on.
6
6
 
7
- A plugin is a `protobase.ui.tsx` that the admin app loads at runtime instead of building it in. It provides what a project's own `protobase.ui.tsx` provides: [custom components](custom-components.md)) for list displays, record sections, page elements, record cards and the assistant's widget parts, [field types](#field-types), action handlers and shell slots. It is built once, on its own, and served from any URL; the app lists it, and every app on a version that fits loads it.
7
+ A plugin is a `protobase.ui.tsx` that the admin app loads at runtime instead of building it in. It provides what a project's own `protobase.ui.tsx` provides: [custom components](custom-components.md) for list displays, record sections, page elements, record cards and the assistant's widget parts, [field types](#field-types), action handlers and shell slots. It is built once, on its own, and served from any URL; the app lists it, and every app on a version that fits loads it.
8
8
 
9
9
  A project's own `protobase.ui.tsx` is a plugin too: `protobase build` builds it as the plugin `app` beside a prebuilt admin app, and builds each `--extend` folder's the same way. So everything below holds for the code an app's own developers write, for code shared across apps, and for code Protobase adds.
10
10
 
11
11
  Plugins are written by an app's developers and by Protobase itself, and they run in the app with the signed-in user's rights, like the app's own code, so load only plugins you trust.
12
12
 
13
- [Your first plugin](../guides/first-plugin.md)) builds one, step by step. [Adding a field type](../guides/field-type.md)), [A custom record card](../guides/record-card.md)) and [Theming an app](../guides/theme-an-app.md)) add to an app, and [Moving onto the plugin build](../guides/plugin-build.md)) moves an existing project's `protobase.ui.tsx` onto it.
13
+ [Your first plugin](../guides/first-plugin.md) builds one, step by step. [Adding a field type](../guides/field-type.md), [A custom record card](../guides/record-card.md) and [Theming an app](../guides/theme-an-app.md) add to an app, and [Moving onto the plugin build](../guides/plugin-build.md) moves an existing project's `protobase.ui.tsx` onto it.
14
14
 
15
15
  ## Who maintains what
16
16
 
17
17
  Plugins split the work of keeping an app current. Protobase maintains the admin app, the API and the server; an app's developers maintain their plugins, and those seldom need work. A plugin is built against the plugin API, which releases add to but never break, so the same build keeps loading as the app moves to newer releases, and gets their fixes and new features on the way. Nobody ports it, rebuilds it or tests it again for each release; it needs a new build only when Protobase starts a new plugin API (see [Versions](#versions)).
18
18
 
19
- What still follows Protobase's releases is the rest of the bundle. Below 1.0 a new minor version may change how `data.ts`, `ui.ts` and the server config are written, and a runtime serves only bundles built by its own minor, so moving to a new minor means running `protobase build` again with that version, after any change the release notes ask of the config (see [Bundles and runtimes](versioning.md#bundles-and-runtimes))). The plugins' code stays as it is. Within a minor, where features ship as patches below 1.0, a host that serves the newer release's [shell](#the-shell) gives the app its fixes with nothing rebuilt.
19
+ What still follows Protobase's releases is the rest of the bundle. Below 1.0 a new minor version may change how `data.ts`, `ui.ts` and the server config are written, and a runtime serves only bundles built by its own minor, so moving to a new minor means running `protobase build` again with that version, after any change the release notes ask of the config (see [Bundles and runtimes](versioning.md#bundles-and-runtimes)). The plugins' code stays as it is. Within a minor, where features ship as patches below 1.0, a host that serves the newer release's [shell](#the-shell) gives the app its fixes with nothing rebuilt.
20
20
 
21
21
  ## How a plugin stays working
22
22
 
@@ -27,7 +27,7 @@ Code built together with the app is frozen at the app it was built with: a newer
27
27
  3. **The plugin API is a promise.** What a plugin can import, the four modules and every export of `@protobase/ui`, is the plugin API, numbered: `pluginApi` is 1. Releases add to it but never remove or change what is in it; only a new plugin API does, as for a new major version of React. So a plugin keeps working on every release of the plugin API it was built for, with no rebuild. Below 1.0 a minor release may change how a project's config is written, but not the plugin API.
28
28
  4. **The app checks before it loads.** A plugin's `plugin.json` says which plugin API and which Protobase versions it is built for. The app loads a plugin only when it has that plugin API and its own version is in the plugin's range; it never runs the code of one that does not fit.
29
29
  5. **A plugin that does not fit is turned off, not the app.** Each place it would fill draws a fallback, the app's admins see why it is off, and everything else works as before. A component that throws while drawing shows its fallback in its own place.
30
- 6. **The look is values, not rules.** A project themes the app with a [`protobase.theme.css`](theme.md)) that holds only values of the app's tokens, and a plugin's stylesheet holds only utilities that read those tokens. Neither reaches into the app's markup, so neither breaks when the app's markup changes.
30
+ 6. **The look is values, not rules.** A project themes the app with a [`protobase.theme.css`](theme.md) that holds only values of the app's tokens, and a plugin's stylesheet holds only utilities that read those tokens. Neither reaches into the app's markup, so neither breaks when the app's markup changes.
31
31
 
32
32
  ## Extension points
33
33
 
@@ -35,12 +35,12 @@ Each place a plugin can fill is an extension point. The config names it, or a pl
35
35
 
36
36
  | Extension point | Named by | Registered as | Gets | Missing, off or throwing |
37
37
  | --- | --- | --- | --- | --- |
38
- | View: [list display](custom-components.md#list-displays)), [record section](custom-components.md#record-sections)), [page element](custom-components.md#components)) | `component('Name')` in `d.custom`, `l.custom` or a layout | A PascalCase export of `protobase.ui.tsx` | Its props, field references as names; `useListDisplay()`, `useLayoutRecord()` | A warning in its place: "No component is registered as *Name*" or "*Name* could not be drawn." |
39
- | [Record card](custom-components.md#record-cards)) | `d.cards(fields, { card: component('Name') })` | A PascalCase export | `{ row }` | The built-in card: title, subtitle, badge, meta fields |
38
+ | View: [list display](custom-components.md#list-displays), [record section](custom-components.md#record-sections), [page element](custom-components.md#components) | `component('Name')` in `d.custom`, `l.custom` or a layout | A PascalCase export of `protobase.ui.tsx` | Its props, field references as names; `useListDisplay()`, `useLayoutRecord()` | A warning in its place: "No component is registered as *Name*" or "*Name* could not be drawn." |
39
+ | [Record card](custom-components.md#record-cards) | `d.cards(fields, { card: component('Name') })` | A PascalCase export | `{ row }` | The built-in card: title, subtitle, badge, meta fields |
40
40
  | [Field type](#field-types) | `r.field.widget('name', props)` in a view's `fields` | `fields: { name: { of, display, editor?, cell? } }` | `{ field, value, props }`, and `onChange`, `invalid` for the editor | The field as it shows without one |
41
- | Widget part (the [assistant](assistant.md#widget-parts))) | A widget part's name | A PascalCase export | The part's props | The part's fallback card |
42
- | [Action handler](custom-components.md#action-handlers)) | `a.action('name')` in a view | `actions: { name }` | `ActionContext` | The button is disabled |
43
- | [Shell slot](custom-components.md#shell-slots)) | Nothing: drawn on every page | `shell: { actions, rightPanel, logo }` | Nothing; `logo` gets `compact` and `workspace` | Not drawn; Protobase's logo for `logo` |
41
+ | Widget part (the [assistant](assistant.md#widget-parts)) | A widget part's name | A PascalCase export | The part's props | The part's fallback card |
42
+ | [Action handler](custom-components.md#action-handlers) | `a.action('name')` in a view | `actions: { name }` | `ActionContext` | The button is disabled |
43
+ | [Shell slot](custom-components.md#shell-slots) | Nothing: drawn on every page | `shell: { actions, rightPanel, logo }` | Nothing; `logo` gets `compact` and `workspace` | Not drawn; Protobase's logo for `logo` |
44
44
  | [Before sign-in](#before-sign-in) | `beforeSignIn: true` where the plugin is listed | `beforeSignIn` | `children`, `params`, `removeParams`, `signedIn` | The pages as they are without it |
45
45
 
46
46
  Components and cards share one namespace of names, which `component('Name')` joins to the export; field types and action handlers each have their own. Props that name fields go through the same walker as everything else in `/api/meta`, so a user who may not read a field never gets it in a component's props; a field type's `props` are plain data, and a field the user may not read is left out of the view, field type and all.
@@ -71,7 +71,7 @@ It is written as a project's `protobase.ui.tsx` is: each component exported unde
71
71
 
72
72
  **Imports.** `react`, `react/jsx-runtime` (the JSX), `react-dom` and `@protobase/ui`, by those names, come from the app. Everything else a plugin imports, its own files, icons or a chart library, is built into it. Other modules of those packages, such as `react-dom/client` or a file inside `@protobase/ui`, fail the build: a copy of its own would not work with the app's. Read data with `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache: a data library of the plugin's own keeps a cache of its own.
73
73
 
74
- **Styling.** Use Tailwind classes, as the app's own code does. The plugin's stylesheet holds the utilities its files use and nothing else, no reset and no global style, and each reads the app's [tokens](theme.md)): `bg-primary` is the app's primary color and `rounded-md` its radius, whatever the app's version and whatever its theme, and a token the app does not set falls back to Tailwind's default.
74
+ **Styling.** Use Tailwind classes, as the app's own code does. The plugin's stylesheet holds the utilities its files use and nothing else, no reset and no global style, and each reads the app's [tokens](theme.md): `bg-primary` is the app's primary color and `rounded-md` its radius, whatever the app's version and whatever its theme, and a token the app does not set falls back to Tailwind's default.
75
75
 
76
76
  **Top-level code.** The build loads `protobase.ui.tsx` once in Node to read its field types, so code at the top level of its modules runs there. Keep browser-only work (`window`, `document`, `localStorage`) inside components and handlers.
77
77
 
@@ -103,7 +103,7 @@ A layout or view declares a plugin's component as it declares any custom compone
103
103
  export const DraftOrders = component('DraftOrders', { plugin: 'sales-tools' })
104
104
  ```
105
105
 
106
- The name is what joins the two, as for a project's component. `plugin` tells `protobase build` that the project's `protobase.ui.tsx` does not have it, so the build does not fail on it (see [Components](custom-components.md#components))). Without the plugin, the app draws the component's fallback in its place.
106
+ The name is what joins the two, as for a project's component. `plugin` tells `protobase build` that the project's `protobase.ui.tsx` does not have it, so the build does not fail on it (see [Components](custom-components.md#components)). Without the plugin, the app draws the component's fallback in its place.
107
107
 
108
108
  ## Field types
109
109
 
@@ -145,7 +145,7 @@ Each part gets:
145
145
 
146
146
  **Fallbacks.** Each part draws inside an error boundary whose fallback is the field's built-in rendering, so a field type that throws costs only its own field, which still shows its value. A plugin that is off leaves every field it would draw as it shows without it.
147
147
 
148
- [Adding a field type](../guides/field-type.md)) builds one step by step.
148
+ [Adding a field type](../guides/field-type.md) builds one step by step.
149
149
 
150
150
  ## Building
151
151
 
@@ -162,7 +162,7 @@ dist/
162
162
  assets/styles-<hash>.css the utilities its files use
163
163
  ```
164
164
 
165
- The output folder is emptied first, so it must not hold the plugin's own files. The module may come with chunks of its own (`import()` in the plugin), beside it in `assets/`. See [build-plugin](cli.md#build-plugin)) for the details. `protobase build` builds the project's own `protobase.ui.tsx` and each extension's the same way, into the bundle's `public/plugins/<name>/`.
165
+ The output folder is emptied first, so it must not hold the plugin's own files. The module may come with chunks of its own (`import()` in the plugin), beside it in `assets/`. See [build-plugin](cli.md#build-plugin) for the details. `protobase build` builds the project's own `protobase.ui.tsx` and each extension's the same way, into the bundle's `public/plugins/<name>/`.
166
166
 
167
167
  `plugin.json` tells the app what it loads:
168
168
 
@@ -228,7 +228,7 @@ The plugins are merged in the order listed. Two of them cannot define one name:
228
228
 
229
229
  `protobase dev` loads plugins the same way, its page sharing the same four modules. The project's own `protobase.ui.tsx` is built into the dev page with hot reload instead, merged after the plugins, and keeps its names over theirs.
230
230
 
231
- The components a [remote resource](remote-resources.md#custom-components))'s view names are drawn from the same plugins, by name, so whoever runs a source lists the plugin that provides them with it. Inside one, `useList` and `useRecord` read the source for its resources, and `useResourceClient(resource)` gives the client of the API that serves a resource.
231
+ The components a [remote resource](remote-resources.md#custom-components)'s view names are drawn from the same plugins, by name, so whoever runs a source lists the plugin that provides them with it. Inside one, `useList` and `useRecord` read the source for its resources, and `useResourceClient(resource)` gives the client of the API that serves a resource.
232
232
 
233
233
  ## Before sign-in
234
234
 
@@ -265,16 +265,16 @@ export default definePlugin({ name: 'guest', beforeSignIn: GuestAccess })
265
265
  | --- | --- |
266
266
  | `children` | What the app shows someone signed out: the sign-in page, or the app a visitor browses. Draw it when the plugin has nothing to do. |
267
267
  | `params` | The query parameters of the page's address. |
268
- | `removeParams(names)` | Takes those query parameters out of the address, in place of it in the tab's history, as the app does with a used [sign-in link](auth.md#sign-in-links-and-connected-accounts)). |
268
+ | `removeParams(names)` | Takes those query parameters out of the address, in place of it in the tab's history, as the app does with a used [sign-in link](auth.md#sign-in-links-and-connected-accounts). |
269
269
  | `signedIn()` | Enters the app with a session something other than the sign-in page started: it reads the session cookie again and shows the app signed in, as the sign-in page does, with no reload. Resolves `false`, and changes nothing, when there is no session. |
270
270
 
271
271
  The plugin starts the session itself, with a request that sets the app's session cookie on the app's origin; `signedIn()` only tells the app. Several plugins' `beforeSignIn` are drawn one around the other, the first listed outermost, and one that throws leaves the pages as they are. Like every plugin, one loaded before sign-in runs with the rights of whoever opens the app, here someone not signed in, and its `plugin.json` and files are served to them, so list only plugins you trust there.
272
272
 
273
273
  ## The shell
274
274
 
275
- The shell is the admin app: `index.html` and its `assets/`, the same for every project on a release. Each release ships it prebuilt in `@protobase/ui`'s `dist/shell/` and in the [protobase image](../guides/deploy.md#images)) at `/opt/protobase/shell/`, with a `protobase.shell.json` naming its Protobase version and plugin API. A bundle carries a copy, so any static host can serve it, and its manifest names that copy's version and paths (`shell` in [the manifest](cli.md#the-manifest))).
275
+ The shell is the admin app: `index.html` and its `assets/`, the same for every project on a release. Each release ships it prebuilt in `@protobase/ui`'s `dist/shell/` and in the [protobase image](../guides/deploy.md#images) at `/opt/protobase/shell/`, with a `protobase.shell.json` naming its Protobase version and plugin API. A bundle carries a copy, so any static host can serve it, and its manifest names that copy's version and paths (`shell` in [the manifest](cli.md#the-manifest)).
276
276
 
277
- A host that keeps the shells of its releases can serve the shell of a newer one for those paths, when every plugin of the bundle loads in it; the plugins, the theme and the API stay the bundle's. `protobase serve` does this with its own shell (see [serve](cli.md#serve))). The app then has the newer release's fixes with nothing rebuilt; only a change of the server config's format, a new minor below 1.0, still needs a [rebuild](versioning.md#bundles-and-runtimes)).
277
+ A host that keeps the shells of its releases can serve the shell of a newer one for those paths, when every plugin of the bundle loads in it; the plugins, the theme and the API stay the bundle's. `protobase serve` does this with its own shell (see [serve](cli.md#serve)). The app then has the newer release's fixes with nothing rebuilt; only a change of the server config's format, a new minor below 1.0, still needs a [rebuild](versioning.md#bundles-and-runtimes).
278
278
 
279
279
  ## Versions
280
280
 
@@ -318,12 +318,12 @@ From `@protobase/ui`:
318
318
  | `definePlugin(config)` | Typed identity for a plugin's default export: `name`, `actions`, `fields`, `shell`, `beforeSignIn`, `extends`, as `defineUi`. |
319
319
  | `BeforeSignInProps` | The props of a plugin's [`beforeSignIn`](#before-sign-in) component. |
320
320
  | `usePlugin()` | The plugin the calling component belongs to (see [above](#writing-a-plugin)). |
321
- | `useResourceClient(resource)` | The client of the API that serves a resource: the app's own, or a source's for a [remote resource](remote-resources.md)). |
321
+ | `useResourceClient(resource)` | The client of the API that serves a resource: the app's own, or a source's for a [remote resource](remote-resources.md). |
322
322
  | `FieldWidget`, `FieldWidgetProps`, `FieldWidgetEditorProps` | The types of a [field type](#field-types) and of its parts' props. |
323
- | `RecordCardProps` | The props of a [record card](custom-components.md#record-cards)), `{ row }`. |
323
+ | `RecordCardProps` | The props of a [record card](custom-components.md#record-cards), `{ row }`. |
324
324
  | `AuthLayout`, `CodeForm`, `ResendCodeButton`, `Button`, `buttonClass`, `Input`, `Spinner`, `LogoMark` | The pieces of the app's sign-in pages, for a page of a plugin or a host's own that looks like them. Outside the app, `@protobase/ui/styles.css` is the stylesheet that draws them, for a Vite build with Tailwind. |
325
325
  | `isFramed`, `useArmedAfterFocus`, `useGuardedPress`, `allowDelayMs` | The connect page's guard against clickjacking and click-through, for a host's own consent screen: it refuses to render when `isFramed()`, and its Allow button spreads `useGuardedPress(armed, onAllow)`, so a press counts only once the page has been in front for `allowDelayMs`. |
326
326
  | `pluginApi` | The plugin API of the app's `@protobase/ui`. |
327
327
  | `protobaseVersion` | The Protobase version of the app's `@protobase/ui`. |
328
328
 
329
- From `@protobase/layout`: `component(name, { plugin })` (see [above](#declaring-its-components-in-the-config)). From `@protobase/schema`: `.widget(name, props)` on a view's fields and `d.cards(fields, { card })` (see [Views](ui-config.md))). From `@protobase/server`: `options.plugins` of `createAdmin`, `PROTOBASE_PLUGINS` and `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` (see [loading](#loading)). The tokens a plugin's utilities read are in [Theme](theme.md)).
329
+ From `@protobase/layout`: `component(name, { plugin })` (see [above](#declaring-its-components-in-the-config)). From `@protobase/schema`: `.widget(name, props)` on a view's fields and `d.cards(fields, { card })` (see [Views](ui-config.md)). From `@protobase/server`: `options.plugins` of `createAdmin`, `PROTOBASE_PLUGINS` and `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` (see [loading](#loading)). The tokens a plugin's utilities read are in [Theme](theme.md).
@@ -6,7 +6,7 @@ Resources another Protobase API serves, drawn in an app with its own list pages,
6
6
 
7
7
  An app can draw resources that another Protobase API serves, as if they were its own: the same list page, record page, create form, breadcrumbs, sidebar entry with its recent records, global search, links and actions, at the same `/<resource>/<key>` addresses. The other API is a **source**. Its config, its data, its access rules and its views stay where they are; the app lists which of its resources it draws, and the signed-in person works with them under the source's rules.
8
8
 
9
- A shop's admin app can show the tickets of the company's service desk this way, next to its orders, and a hosting platform can show each app the tasks it keeps for that app. [Showing another app's records](../guides/remote-resources.md)) builds the first, step by step.
9
+ A shop's admin app can show the tickets of the company's service desk this way, next to its orders, and a hosting platform can show each app the tasks it keeps for that app. [Showing another app's records](../guides/remote-resources.md) builds the first, step by step.
10
10
 
11
11
  ## How it works
12
12
 
@@ -59,16 +59,16 @@ PROTOBASE_SOURCES='[{"url":"https://desk.example.com/api/v1","label":"Service de
59
59
 
60
60
  The sources of `options.sources` come first, then those of `PROTOBASE_SOURCES`; `options.sources: false` turns both off.
61
61
 
62
- **Checks at startup.** The server refuses to start, naming the source, when a source cannot work: a `url` that is no http(s) URL or names no path, a missing `label` or `resources`, a key a source does not take (such as `resource` for `resources`), the same `url` listed twice, or one resource drawn from two sources. It refuses to start too when a source draws a resource under a name the app already has, for one of its own resources or a [composed page](layouts.md)): the address `/<name>` would mean two things. Rename one of them, or leave it out of the source's resources.
62
+ **Checks at startup.** The server refuses to start, naming the source, when a source cannot work: a `url` that is no http(s) URL or names no path, a missing `label` or `resources`, a key a source does not take (such as `resource` for `resources`), the same `url` listed twice, or one resource drawn from two sources. It refuses to start too when a source draws a resource under a name the app already has, for one of its own resources or a [composed page](layouts.md): the address `/<name>` would mean two things. Rename one of them, or leave it out of the source's resources.
63
63
 
64
64
  ## Who sees what
65
65
 
66
66
  Two places decide, each about what it knows:
67
67
 
68
68
  - **The app** decides who is told about a source, with its `roles`. A caller without one of them gets no `sources` in `/api/meta`, and their browser never calls that source.
69
- - **The source** decides everything else, as for its own users. Its `/meta` names only the resources the person may see there, each without the fields they may not read and with the view for their role; its API applies its [access rules](access.md)), row filters and record checks to every call. A resource the app draws but the person may not see there is not in their app.
69
+ - **The source** decides everything else, as for its own users. Its `/meta` names only the resources the person may see there, each without the fields they may not read and with the view for their role; its API applies its [access rules](access.md), row filters and record checks to every call. A resource the app draws but the person may not see there is not in their app.
70
70
 
71
- A source's view can be written for the people of another app: views are picked [per role](ui-config.md#actions-and-views-per-role)) with `.forRoles([...])`, and the role the source gives the app's users (see below) can have a view of its own, with its own `nav` group, columns and layout.
71
+ A source's view can be written for the people of another app: views are picked [per role](ui-config.md#actions-and-views-per-role) with `.forRoles([...])`, and the role the source gives the app's users (see below) can have a view of its own, with its own `nav` group, columns and layout.
72
72
 
73
73
  ## Signing in at the source
74
74
 
@@ -87,23 +87,23 @@ export const authenticate = betterAuthAuthenticator({
87
87
  | Trusted app | |
88
88
  | --- | --- |
89
89
  | `issuer` | The other app's Better Auth `baseURL`, its `BETTER_AUTH_URL`, with or without a trailing slash: the issuer and audience of its tokens. Its keys are read from `<issuer>/api/auth/jwks`. |
90
- | `roles` | Its global roles as they are here: `{ admin: 'shop' }` makes its admins `shop` here. A role it does not list is dropped, and a user left with none is refused with `403`. A role someone holds in one of its [organizations](auth.md#organizations)) is never mapped, since that organization's owners hand it out; with organizations there, only a global role counts. |
91
- | `tenant` | The tenant its users work in here, for resources with a [tenant](data-config.md#resource)). Nothing in its tokens names a tenant here. |
90
+ | `roles` | Its global roles as they are here: `{ admin: 'shop' }` makes its admins `shop` here. A role it does not list is dropped, and a user left with none is refused with `403`. A role someone holds in one of its [organizations](auth.md#organizations) is never mapped, since that organization's owners hand it out; with organizations there, only a global role counts. |
91
+ | `tenant` | The tenant its users work in here, for resources with a [tenant](data-config.md#resource). Nothing in its tokens names a tenant here. |
92
92
  | `keys` | Its key set, instead of reading it from its `/api/auth/jwks`: for tests, or keys at hand. |
93
93
 
94
94
  - A token whose issuer is a trusted app's is verified against that app's keys, with that issuer as issuer and audience; every other token goes to the app's own check. The key set is kept for 10 minutes and read again for an unknown key, as jose's remote key sets do.
95
- - The user's id here is `<sub>@<that app's host>`, such as `x81kd2@shop.example.com`, so it never equals an id of this app's own users: an [owner field](access.md)) or an audit entry tells them apart.
96
- - Give the other app's users roles of their own (`shop`, not `admin`) and open to those roles exactly what you share. A role that is only in `apps` needs no place in `createAuth`'s `roles`, which are the roles of this app's own users; with [`defineRoles`](access.md)), define what it may do like any role.
97
- - An app without `defineRoles` [allows](access.md#defaults)) every operation without a rule to everyone signed in, the other app's users included. Give the resources you do not share an access rule that leaves their role out, or define roles.
95
+ - The user's id here is `<sub>@<that app's host>`, such as `x81kd2@shop.example.com`, so it never equals an id of this app's own users: an [owner field](access.md) or an audit entry tells them apart.
96
+ - Give the other app's users roles of their own (`shop`, not `admin`) and open to those roles exactly what you share. A role that is only in `apps` needs no place in `createAuth`'s `roles`, which are the roles of this app's own users; with [`defineRoles`](access.md), define what it may do like any role.
97
+ - An app without `defineRoles` [allows](access.md#defaults) every operation without a rule to everyone signed in, the other app's users included. Give the resources you do not share an access rule that leaves their role out, or define roles.
98
98
  - A trusted app cannot be this app itself.
99
99
 
100
- A source that is not a Protobase app accepts the app's tokens its own way: they are EdDSA JWTs whose issuer and audience are the app's `BETTER_AUTH_URL`, whose keys are at `<that URL>/api/auth/jwks`, which carry the user's id in `sub`, their active role in `role` and live for 15 minutes (see [Tokens and roles](auth.md#tokens-and-roles))).
100
+ A source that is not a Protobase app accepts the app's tokens its own way: they are EdDSA JWTs whose issuer and audience are the app's `BETTER_AUTH_URL`, whose keys are at `<that URL>/api/auth/jwks`, which carry the user's id in `sub`, their active role in `role` and live for 15 minutes (see [Tokens and roles](auth.md#tokens-and-roles)).
101
101
 
102
- **What it trusts.** A source sees the person's token, which the app's own API also accepts until it expires, within 15 minutes. List as a source only an API you trust as much as a [plugin](plugins.md)), whose code runs in the app with the same rights.
102
+ **What it trusts.** A source sees the person's token, which the app's own API also accepts until it expires, within 15 minutes. List as a source only an API you trust as much as a [plugin](plugins.md), whose code runs in the app with the same rights.
103
103
 
104
104
  ## CORS
105
105
 
106
- The browser calls the source from the app's origin, so the source answers [CORS](api.md#cors)) for it: it lists the app's origin in `options.cors` or `PROTOBASE_CORS_ORIGINS`:
106
+ The browser calls the source from the app's origin, so the source answers [CORS](api.md#cors) for it: it lists the app's origin in `options.cors` or `PROTOBASE_CORS_ORIGINS`:
107
107
 
108
108
  ```ts
109
109
  // the source's protobase.config.ts
@@ -118,7 +118,7 @@ Everything the app draws for a resource of its own, for a remote resource too:
118
118
 
119
119
  | Part | For a remote resource |
120
120
  | --- | --- |
121
- | Sidebar | An entry where the source's view places it (`nav.group`, `nav.order`), with its [recent records](sidebar.md#recent-records)), read from the source. `nav.hidden` keeps it out. |
121
+ | Sidebar | An entry where the source's view places it (`nav.group`, `nav.order`), with its [recent records](sidebar.md#recent-records), read from the source. `nav.hidden` keeps it out. |
122
122
  | List page | Its columns, sort, filters, search, displays and chart, at `/<resource>`, with every list state in the address. |
123
123
  | Record page | Its sections, related records, sidebar, actions and custom sections, at `/<resource>/<key>`, saved back to the source with its ETag. |
124
124
  | Create form | At `/<resource>/new`, when the person may create there. |
@@ -139,7 +139,7 @@ A batch write goes to the one API its writes are for. One that writes to the app
139
139
 
140
140
  ## Custom components
141
141
 
142
- A source's view can name [custom components](custom-components.md)) like any view: a record section with `l.custom(TicketTimeline)`, a list display, a record card or a field type. The app draws them by name from its [plugins](plugins.md)), as it draws its own: a component no loaded plugin provides draws its fallback in its place.
142
+ A source's view can name [custom components](custom-components.md) like any view: a record section with `l.custom(TicketTimeline)`, a list display, a record card or a field type. The app draws them by name from its [plugins](plugins.md), as it draws its own: a component no loaded plugin provides draws its fallback in its place.
143
143
 
144
144
  So whoever runs a source ships its components as a plugin, and the app lists the plugin with the source:
145
145
 
@@ -153,7 +153,7 @@ PROTOBASE_PLUGINS='https://desk.example.com/plugins/desk/plugin.json'
153
153
  export const TicketTimeline = component('TicketTimeline', { plugin: 'desk' })
154
154
  ```
155
155
 
156
- Inside, the component reads its record with `useLayoutRecord()`, and its data with `useList` and `useRecord`, which go to the source for a remote resource like every other call. `useMeta()` gives the app's `/meta` with the sources' resources in it, and how far each source has loaded in `sources`. `useResourceClient(resource)` gives the client of the API that serves a resource, the source's for a remote one, whose `invoke` calls that API's [functions](../guides/api-functions.md)); `useClient()` sends resource calls where they belong, and `invoke` to the app's own functions. An action handler gets the client of the resource's API as `client`.
156
+ Inside, the component reads its record with `useLayoutRecord()`, and its data with `useList` and `useRecord`, which go to the source for a remote resource like every other call. `useMeta()` gives the app's `/meta` with the sources' resources in it, and how far each source has loaded in `sources`. `useResourceClient(resource)` gives the client of the API that serves a resource, the source's for a remote one, whose `invoke` calls that API's [functions](../guides/api-functions.md); `useClient()` sends resource calls where they belong, and `invoke` to the app's own functions. An action handler gets the client of the resource's API as `client`.
157
157
 
158
158
  ## When a source cannot be reached
159
159
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  How sidebar entries are grouped, and how an entry lists recent records with status dots.
6
6
 
7
- The admin's sidebar has one entry per resource view, grouped by `nav.group` (default: the database schema) and sorted by `nav.order`. A view's [named lists](ui-config.md#more-than-one-list)) are entries of their own, placed by their own `nav`. `nav({ hidden: true })` leaves a resource out, for line and link tables; a resource in the [user menu](user-menu.md)) is left out too. [Composed pages](layouts.md#setup)) have entries of their own, and groups that hold pages come first. A [remote resource](remote-resources.md)) has its entry where its source's view places it; while its source cannot be reached, it sits under the source's label, marked "Cannot reach" with the source's name.
7
+ The admin's sidebar has one entry per resource view, grouped by `nav.group` (default: the database schema) and sorted by `nav.order`. A view's [named lists](ui-config.md#more-than-one-list) are entries of their own, placed by their own `nav`. `nav({ hidden: true })` leaves a resource out, for line and link tables; a resource in the [user menu](user-menu.md) is left out too. [Composed pages](layouts.md#setup) have entries of their own, and groups that hold pages come first. A [remote resource](remote-resources.md) has its entry where its source's view places it; while its source cannot be reached, it sits under the source's label, marked "Cannot reach" with the source's name.
8
8
 
9
9
  ## Recent records
10
10
 
@@ -24,7 +24,7 @@ The server serves the socket when the host gives `createAdmin` its WebSocket upg
24
24
 
25
25
  ## Which tables
26
26
 
27
- A channel may listen to the tables of the resources with [`.live()`](live.md)), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase)) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. `select` of columns is not supported yet; private channels neither.
27
+ A channel may listen to the tables of the resources with [`.live()`](live.md), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. `select` of columns is not supported yet; private channels neither.
28
28
 
29
29
  ## Broadcast and presence
30
30
 
@@ -52,7 +52,7 @@ Broadcasts and presence go between the channels of one serving process, which is
52
52
 
53
53
  Each change is checked for each subscriber before it is sent. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them. In one transaction per batch of changes, the server sets the subscriber's role with `SET LOCAL ROLE` and its claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()` and `auth.jwt()` work, reads the changed rows by key, and sends an insert or update only when the table's RLS policies let the subscriber select the row, with the columns its role may select. Subscribers with the same role and claims, such as one user's tabs, are checked once. The check holds one pooled connection per serving process, and only while it runs, never one per socket.
54
54
 
55
- Unlike Supabase, which reads changes from the write-ahead log, the server reads them from the [live updates' notices](live.md#the-table)), which keep record keys only. So:
55
+ Unlike Supabase, which reads changes from the write-ahead log, the server reads them from the [live updates' notices](live.md#the-table), which keep record keys only. So:
56
56
 
57
57
  - An insert or update carries the row as it is when it is checked. Several changes of a row between two checks each carry its latest state, and a row deleted or no longer visible by then is not sent. `old_record` holds the primary key alone, as on Supabase without `replica identity full`.
58
58
  - A delete carries the primary key alone and is not checked against RLS, as on Supabase. A filter on a column other than the key does not match a delete.
@@ -42,11 +42,11 @@ Not yet: many-to-many embeds through a junction table, spreads (`...profiles(nam
42
42
 
43
43
  ## Scan guard
44
44
 
45
- As on the [REST API](api.md#safety)), a filter or a sort reads only columns an index serves: a btree index for comparisons, `in`, `is` and sorts, a pg_trgm index for patterns and regular expressions, a GIN index for text search and `cs`, `cd` and `ov` (or GiST), and a GiST index for the range operators. A JSON path needs an index on that expression. An embed's filters and order are judged on the embedded table, and so are the columns it joins on, so a one-to-many embed needs an index on the foreign key's columns. Any other read is `400` with code `expensive-query` and the statement that adds the index as its `hint`. Functions are not judged.
45
+ As on the [REST API](api.md#safety), a filter or a sort reads only columns an index serves: a btree index for comparisons, `in`, `is` and sorts, a pg_trgm index for patterns and regular expressions, a GIN index for text search and `cs`, `cd` and `ov` (or GiST), and a GiST index for the range operators. A JSON path needs an index on that expression. An embed's filters and order are judged on the embedded table, and so are the columns it joins on, so a one-to-many embed needs an index on the foreign key's columns. Any other read is `400` with code `expensive-query` and the statement that adds the index as its `hint`. Functions are not judged.
46
46
 
47
47
  ## Encrypted fields
48
48
 
49
- The column of an [encrypted field](data-config.md#encrypted-fields)) holds ciphertext, which this API can neither write nor compare. A read returns it as stored. Writing the column, an `on_conflict` on it, a filter, sort or embed join on it, and, on a table with encrypted fields, a write that changes a row's key or tenant are `400` with code `encrypted-column`, writing nothing, whichever resource over the table declares the field. A view this API serves cannot be checked, so it must not show an encrypted column. Write such fields and reveal them through the [REST API](api.md)).
49
+ The column of an [encrypted field](data-config.md#encrypted-fields) holds ciphertext, which this API can neither write nor compare. A read returns it as stored. Writing the column, an `on_conflict` on it, a filter, sort or embed join on it, and, on a table with encrypted fields, a write that changes a row's key or tenant are `400` with code `encrypted-column`, writing nothing, whichever resource over the table declares the field. A view this API serves cannot be checked, so it must not show an encrypted column. Write such fields and reveal them through the [REST API](api.md).
50
50
 
51
51
  ## Errors
52
52
 
@@ -15,7 +15,7 @@ const { data, error } = await supabase.storage.from('avatars').upload(`${userId}
15
15
 
16
16
  ## Where things are kept
17
17
 
18
- The buckets and objects are the rows of `storage.buckets` and `storage.objects`, the schema that `protobase import supabase` restores with its policies. The bytes go to one of the app's [file providers](files.md)): `files.storage.provider` in `protobase.config.ts`, `private` by default, so a local folder or an S3-compatible bucket, with that provider's `max_bytes` and `max_files` quota. An object's bytes are kept at `storage/<SHA-256 of bucket and name>/<version>` in the provider, where [`protobase import supabase --storage-url`](cli.md#import-supabase)) copies a Supabase project's. `files.storage.maxFileSize` caps every upload, `50 MB` by default, and a bucket's `file_size_limit` can only lower it. `files: { storage: false }` serves no `/api/sb/storage/v1`.
18
+ The buckets and objects are the rows of `storage.buckets` and `storage.objects`, the schema that `protobase import supabase` restores with its policies. The bytes go to one of the app's [file providers](files.md): `files.storage.provider` in `protobase.config.ts`, `private` by default, so a local folder or an S3-compatible bucket, with that provider's `max_bytes` and `max_files` quota. An object's bytes are kept at `storage/<SHA-256 of bucket and name>/<version>` in the provider, where [`protobase import supabase --storage-url`](cli.md#import-supabase) copies a Supabase project's. `files.storage.maxFileSize` caps every upload, `50 MB` by default, and a bucket's `file_size_limit` can only lower it. `files: { storage: false }` serves no `/api/sb/storage/v1`.
19
19
 
20
20
  ## Keys and roles
21
21
 
@@ -25,17 +25,17 @@ A project themes its admin app with one file, `protobase.theme.css` at its root,
25
25
  }
26
26
  ```
27
27
 
28
- [Theming an app](../guides/theme-an-app.md)) walks through one.
28
+ [Theming an app](../guides/theme-an-app.md) walks through one.
29
29
 
30
30
  ## Why values only
31
31
 
32
- A stylesheet that reaches into the app with selectors, `.sidebar a` or `button.primary`, depends on the app's markup, which every release may change; it breaks quietly, and only on the screens it touched. A theme that sets token values depends on nothing but the token names, which are a promise like the [plugin API](plugins.md#how-a-plugin-stays-working)):
32
+ A stylesheet that reaches into the app with selectors, `.sidebar a` or `button.primary`, depends on the app's markup, which every release may change; it breaks quietly, and only on the screens it touched. A theme that sets token values depends on nothing but the token names, which are a promise like the [plugin API](plugins.md#how-a-plugin-stays-working):
33
33
 
34
34
  - The app reads every color, its radii and its fonts from these tokens, and so do plugins, whose utilities read them too (`bg-primary` is `background-color: var(--primary)`).
35
35
  - Tokens are only added. A token that is renamed keeps its old name as well, so a theme never stops applying.
36
36
  - A token the theme leaves out keeps the app's value, and a value the app no longer reads is ignored, so a theme written for one release works on the next with nothing rebuilt.
37
37
 
38
- Changing how one part of the app looks, beyond its tokens, is not a theme's job: replace that part with a [plugin](plugins.md#extension-points)) instead, such as a record card or a field type.
38
+ Changing how one part of the app looks, beyond its tokens, is not a theme's job: replace that part with a [plugin](plugins.md#extension-points) instead, such as a record card or a field type.
39
39
 
40
40
  ## The file
41
41
 
@@ -123,9 +123,9 @@ The list is `packages/ui/src/tokens.css`, and a test fails when one of its token
123
123
 
124
124
  ## Logo and favicon
125
125
 
126
- The sidebar shows Protobase's logo, its mark alone when the sidebar shows only icons, or, for a project with its own favicon, that icon and the app's name ([App identity](app-identity.md))). A project draws something else with `shell.logo` in `protobase.ui.tsx`, a component drawn in its place ([Shell slots](custom-components.md#shell-slots))); it draws with these tokens like the rest of the app.
126
+ The sidebar shows Protobase's logo, its mark alone when the sidebar shows only icons, or, for a project with its own favicon, that icon and the app's name ([App identity](app-identity.md)). A project draws something else with `shell.logo` in `protobase.ui.tsx`, a component drawn in its place ([Shell slots](custom-components.md#shell-slots)); it draws with these tokens like the rest of the app.
127
127
 
128
- The browser tab shows Protobase's mark. A project shows its own with a `protobase.favicon.svg` at its root, beside `protobase.theme.css`: the app's `index.html` links `/protobase.favicon.svg`, which `protobase build` writes to the bundle's `public/`, the project's file or Protobase's without one, and which `protobase dev` serves the same way. An SVG can follow the system's light or dark with a `prefers-color-scheme` media query inside it, as Protobase's does. PNGs beside it serve the platforms that take no SVG, such as an iPhone's home screen ([App identity](app-identity.md#the-icons))).
128
+ The browser tab shows Protobase's mark. A project shows its own with a `protobase.favicon.svg` at its root, beside `protobase.theme.css`: the app's `index.html` links `/protobase.favicon.svg`, which `protobase build` writes to the bundle's `public/`, the project's file or Protobase's without one, and which `protobase dev` serves the same way. An SVG can follow the system's light or dark with a `prefers-color-scheme` media query inside it, as Protobase's does. PNGs beside it serve the platforms that take no SVG, such as an iPhone's home screen ([App identity](app-identity.md#the-icons)).
129
129
 
130
130
  ## In a plugin
131
131