@protobase/cli 0.40.8 → 0.40.10

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 (78) hide show
  1. package/dist/cli/package.js +1 -1
  2. package/package.json +6 -6
  3. package/skills/protobase/SKILL.md +1 -0
  4. package/skills/protobase/references/features/access.md +16 -0
  5. package/skills/protobase/references/features/actions.md +11 -0
  6. package/skills/protobase/references/features/ai.md +14 -0
  7. package/skills/protobase/references/features/api-functions.md +13 -0
  8. package/skills/protobase/references/features/build-and-run.md +19 -0
  9. package/skills/protobase/references/features/compatibility.md +14 -0
  10. package/skills/protobase/references/features/composed-pages.md +18 -0
  11. package/skills/protobase/references/features/data-model.md +19 -0
  12. package/skills/protobase/references/features/email-and-public-forms.md +12 -0
  13. package/skills/protobase/references/features/events-webhooks-and-jobs.md +18 -0
  14. package/skills/protobase/references/features/files-and-images.md +16 -0
  15. package/skills/protobase/references/features/history-comments-and-live-updates.md +14 -0
  16. package/skills/protobase/references/features/list-displays.md +18 -0
  17. package/skills/protobase/references/features/lists.md +28 -0
  18. package/skills/protobase/references/features/look-and-language.md +13 -0
  19. package/skills/protobase/references/features/navigation.md +14 -0
  20. package/skills/protobase/references/features/record-pages.md +20 -0
  21. package/skills/protobase/references/features/releases.md +11 -0
  22. package/skills/protobase/references/features/rest-api.md +24 -0
  23. package/skills/protobase/references/features/several-apps.md +8 -0
  24. package/skills/protobase/references/features/sign-in-and-accounts.md +27 -0
  25. package/skills/protobase/references/features/start-a-project.md +14 -0
  26. package/skills/protobase/references/features/your-own-code.md +19 -0
  27. package/skills/protobase/references/features.md +39 -0
  28. package/skills/protobase/references/getting-started.md +8 -8
  29. package/skills/protobase/references/guides/api-functions.md +12 -12
  30. package/skills/protobase/references/guides/billing-page.md +2 -2
  31. package/skills/protobase/references/guides/create-page.md +5 -5
  32. package/skills/protobase/references/guides/deploy.md +6 -6
  33. package/skills/protobase/references/guides/export-a-list.md +2 -2
  34. package/skills/protobase/references/guides/field-type.md +2 -2
  35. package/skills/protobase/references/guides/first-composed-page.md +4 -4
  36. package/skills/protobase/references/guides/first-plugin.md +3 -3
  37. package/skills/protobase/references/guides/import-records.md +1 -1
  38. package/skills/protobase/references/guides/mobile-app.md +14 -3
  39. package/skills/protobase/references/guides/plugin-build.md +5 -5
  40. package/skills/protobase/references/guides/record-card.md +3 -3
  41. package/skills/protobase/references/guides/remote-resources.md +10 -10
  42. package/skills/protobase/references/guides/table-to-admin.md +5 -5
  43. package/skills/protobase/references/guides/theme-an-app.md +4 -4
  44. package/skills/protobase/references/reference/access.md +9 -9
  45. package/skills/protobase/references/reference/ai.md +6 -6
  46. package/skills/protobase/references/reference/api.md +25 -25
  47. package/skills/protobase/references/reference/app-identity.md +4 -4
  48. package/skills/protobase/references/reference/architecture.md +1 -1
  49. package/skills/protobase/references/reference/assistant.md +6 -6
  50. package/skills/protobase/references/reference/auth.md +20 -20
  51. package/skills/protobase/references/reference/blocks.md +13 -13
  52. package/skills/protobase/references/reference/bottom-bar.md +5 -5
  53. package/skills/protobase/references/reference/cli.md +63 -63
  54. package/skills/protobase/references/reference/client.md +5 -5
  55. package/skills/protobase/references/reference/comments.md +8 -8
  56. package/skills/protobase/references/reference/custom-components.md +18 -18
  57. package/skills/protobase/references/reference/data-config.md +30 -26
  58. package/skills/protobase/references/reference/email.md +8 -8
  59. package/skills/protobase/references/reference/events.md +5 -5
  60. package/skills/protobase/references/reference/files.md +11 -7
  61. package/skills/protobase/references/reference/forms.md +6 -6
  62. package/skills/protobase/references/reference/history.md +7 -7
  63. package/skills/protobase/references/reference/installable-app.md +1 -1
  64. package/skills/protobase/references/reference/jobs.md +5 -5
  65. package/skills/protobase/references/reference/layouts.md +11 -11
  66. package/skills/protobase/references/reference/live.md +4 -4
  67. package/skills/protobase/references/reference/mcp.md +15 -7
  68. package/skills/protobase/references/reference/plugins.md +20 -20
  69. package/skills/protobase/references/reference/remote-resources.md +15 -15
  70. package/skills/protobase/references/reference/sidebar.md +1 -1
  71. package/skills/protobase/references/reference/supabase-realtime.md +2 -2
  72. package/skills/protobase/references/reference/supabase-rest.md +2 -2
  73. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  74. package/skills/protobase/references/reference/theme.md +5 -5
  75. package/skills/protobase/references/reference/ui-config.md +60 -60
  76. package/skills/protobase/references/reference/user-menu.md +3 -3
  77. package/skills/protobase/references/reference/versioning.md +5 -5
  78. package/skills/protobase/references/reference/webhooks.md +7 -7
@@ -4,7 +4,7 @@
4
4
 
5
5
  Roles, capabilities with field lists and row filters, field rules, anonymous access, and what they default to.
6
6
 
7
- Roles are defined in code ([`defineRoles`](https://docs.protobase.net/api/schema/functions/defineroles/))) and assigned through the auth user's `roles`; with [organizations](auth.md#organizations)), also per membership, and `ctx.user.roles` holds both, while `ctx.organization.id` is the organization the request works in. Rules decide per operation (`list`, `read`, `create`, `update`, `delete`), per field (role-based, never per record) and per row (filters, like RLS).
7
+ Roles are defined in code ([`defineRoles`](https://docs.protobase.net/api/schema/functions/defineroles/)) and assigned through the auth user's `roles`; with [organizations](auth.md#organizations), also per membership, and `ctx.user.roles` holds both, while `ctx.organization.id` is the organization the request works in. Rules decide per operation (`list`, `read`, `create`, `update`, `delete`), per field (role-based, never per record) and per row (filters, like RLS).
8
8
 
9
9
  ## Defaults
10
10
 
@@ -12,7 +12,7 @@ Roles are defined in code ([`defineRoles`](https://docs.protobase.net/api/schema
12
12
  - A project without roles (the single-admin case) is **default allow**.
13
13
  - `defaultAccess: 'allow'` together with `roles` is an explicit opt-in. Print `accessWarnings(options)` at startup.
14
14
  - Every request needs a token, unless the roles define [`anonymous`](#anonymous-access).
15
- - An [API function](../guides/api-functions.md#roles)) without `roles` or a `capability` is closed the same way: with roles, only a caller holding `*` may call it.
15
+ - An [API function](../guides/api-functions.md#roles) without `roles` or a `capability` is closed the same way: with roles, only a caller holding `*` may call it.
16
16
 
17
17
  ## Capabilities
18
18
 
@@ -32,7 +32,7 @@ defineRoles<'orders' | 'products'>({
32
32
 
33
33
  A field is readable when the role's list allows it and the field's own [rule](#field-rules-or-field-lists) passes. Field lists take effect through the roles the server gets (`options: { roles }` in `protobase.config.ts`, `resolveAccess(source, ctx, { roles })`), for every resource whatever its rules. A filter is the capability's row filter, so like `.own` it applies where the capability decides: an operation without a rule, or a rule built with `roles.can(...)`.
34
34
 
35
- **Several roles add up.** A user gets every field one of their roles lists (all of them when a role holds the plain capability) and the rows any of their roles allows. Fields and rows add up separately: someone holding both `erp_sync` and `reseller` above reads `name` on unpublished products too. With Better Auth a session acts with one [active role](auth.md#active-role)) at a time, so this only comes up with an authenticator that hands out several.
35
+ **Several roles add up.** A user gets every field one of their roles lists (all of them when a role holds the plain capability) and the rows any of their roles allows. Fields and rows add up separately: someone holding both `erp_sync` and `reseller` above reads `name` on unpublished products too. With Better Auth a session acts with one [active role](auth.md#active-role) at a time, so this only comes up with an authenticator that hands out several.
36
36
 
37
37
  ### Wildcards in has, can and holds
38
38
 
@@ -49,12 +49,12 @@ The role `anonymous` is what a request without a token acts as. A project withou
49
49
  anonymous: [{ 'products.read': { fields: ['name', 'slug', 'price', 'image'], filter: 'published = true' } }],
50
50
  ```
51
51
 
52
- - **It reads listed fields, and creates them through a public form only.** Each entry names one resource, `read` or `create` without a scope, and its fields; `defineRoles` refuses other capabilities, wildcards, `.own` and `.team`, and a capability without a field list, so nothing becomes public by accident, a new column included. A `create` is used by the resource's [public forms](forms.md)) alone, behind their rate limit and bot check: everywhere else it does not exist.
52
+ - **It reads listed fields, and creates them through a public form only.** Each entry names one resource, `read` or `create` without a scope, and its fields; `defineRoles` refuses other capabilities, wildcards, `.own` and `.team`, and a capability without a field list, so nothing becomes public by accident, a new column included. A `create` is used by the resource's [public forms](forms.md) alone, behind their rate limit and bot check: everywhere else it does not exist.
53
53
  - **No token, not a bad one.** A request without an `Authorization` header is served as a caller holding only this role, in no organization. A header with anything but a valid, unexpired token is still a `401`. `jwtAuthenticator` and `betterAuthAuthenticator` tell the two apart; an authenticator of your own throws `MissingCredentials` (from `@protobase/server`) for a request without a credential to do the same.
54
54
  - **Only its capabilities open anything.** The capability is ANDed into a resource's access rule, so a rule that allows everyone (`read: () => true`) or `defaultAccess: 'allow'` never lets an anonymous caller in on its own.
55
- - **The resources API and `/api/meta` only.** Lists, records, `:search`, `:seek` and the aggregates of what the role reads, with filters, sorts and `fields` checked as for everyone: an unlisted field is refused like an unknown one. A resource it cannot read is a `404`; a write, or another operation it may not do on a resource it reads, is a `401` that asks for a token, a `create` it holds for a form included. `/api/meta` describes what it reads, for the [admin app](#browsing-the-admin-app). `/api/openapi.json`, `/api/docs`, batch writes, [API functions](../guides/api-functions.md)), the assistant and the file cleanup still need a token. A [file field](files.md#downloads)) it reads comes with its link, as for anyone.
55
+ - **The resources API and `/api/meta` only.** Lists, records, `:search`, `:seek` and the aggregates of what the role reads, with filters, sorts and `fields` checked as for everyone: an unlisted field is refused like an unknown one. A resource it cannot read is a `404`; a write, or another operation it may not do on a resource it reads, is a `401` that asks for a token, a `create` it holds for a form included. `/api/meta` describes what it reads, for the [admin app](#browsing-the-admin-app). `/api/openapi.json`, `/api/docs`, batch writes, [API functions](../guides/api-functions.md), the assistant and the file cleanup still need a token. A [file field](files.md#downloads) it reads comes with its link, as for anyone.
56
56
  - A tenant-scoped resource (`.tenant`) cannot be in it, since an anonymous caller works in no organization; the server refuses to start.
57
- - Reading has no rate limit of its own: put a proxy or CDN in front of a public API to limit and cache requests. [Public forms](forms.md#rate-limit)) limit their submissions.
57
+ - Reading has no rate limit of its own: put a proxy or CDN in front of a public API to limit and cache requests. [Public forms](forms.md#rate-limit) limit their submissions.
58
58
 
59
59
  ### Browsing the admin app
60
60
 
@@ -110,7 +110,7 @@ Each item has `id`, `name`, `slug`, `price` and `image`, of published products o
110
110
 
111
111
  ### An integration limited to some columns
112
112
 
113
- `erp_sync` is a role for a system: a user with that role, and a token for it ([`issueToken`](auth.md#tokens-for-scripts-and-curl))). It reads `sku`, `price` and `stock` of every product and writes only `stock`; a `PATCH` with `price` is a `400`, as for a field it cannot see, and `cost_price` is not in its responses. A role that only uses the API needs no view: views shape the admin app, while what a caller may see and do is decided here.
113
+ `erp_sync` is a role for a system: a user with that role, and a token for it ([`issueToken`](auth.md#tokens-for-scripts-and-curl)). It reads `sku`, `price` and `stock` of every product and writes only `stock`; a `PATCH` with `price` is a `400`, as for a field it cannot see, and `cost_price` is not in its responses. A role that only uses the API needs no view: views shape the admin app, while what a caller may see and do is decided here.
114
114
 
115
115
  ### Field rules or field lists
116
116
 
@@ -157,7 +157,7 @@ export const operations = resource('operations')
157
157
  .parent((r) => r.vm_id, 'update')
158
158
  ```
159
159
 
160
- - **Every write is checked.** Creating a record checks the parent it names; changing it, the parent it points at and the one it moves to; deleting and undeleting it, the parent it points at. So a record cannot be created under an allowed parent and then moved under another. It holds for `/api/v1` and its batches, and for everything that writes through them: forms, [API functions](../guides/api-functions.md)) and the assistant.
160
+ - **Every write is checked.** Creating a record checks the parent it names; changing it, the parent it points at and the one it moves to; deleting and undeleting it, the parent it points at. So a record cannot be created under an allowed parent and then moved under another. It holds for `/api/v1` and its batches, and for everything that writes through them: forms, [API functions](../guides/api-functions.md) and the assistant.
161
161
  - **The caller's own rules decide.** The parent is read as the caller would read it, with its tenant, row filters, soft delete and record-level rules; for `update`, also its update row filter and record-level update rule, given an empty input. A parent the caller cannot see, may not update, that is soft deleted or does not exist gets the same `403` as a refused create (`You may not create this operations record`), and nothing is written: the answer does not tell which VM ids exist.
162
162
  - **A null relation checks nothing.** A relation set by a column default or a trigger is checked from the record as written.
163
163
  - **`update` follows the parent's own parents**, so with VMs under `.parent((r) => r.folder_id, 'update')` an operation needs update on the VM's folder too. A write that would put a record under itself, or under a cycle already in the data, is refused. A `read` parent is not followed further.
@@ -167,6 +167,6 @@ export const operations = resource('operations')
167
167
 
168
168
  ## Restricted model and row filters
169
169
 
170
- [`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/)) returns everything a request may do. Use [`restrictModel(model, access)`](https://docs.protobase.net/api/schema/functions/restrictmodel/)) for everything user-facing (checking filters and sorts, queries, OpenAPI, `/meta`): hidden fields are gone, so they cannot be referenced, searched, sorted or leaked. Key columns always stay, because records are addressed by them.
170
+ [`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/) returns everything a request may do. Use [`restrictModel(model, access)`](https://docs.protobase.net/api/schema/functions/restrictmodel/) for everything user-facing (checking filters and sorts, queries, OpenAPI, `/meta`): hidden fields are gone, so they cannot be referenced, searched, sorted or leaked. Key columns always stay, because records are addressed by them.
171
171
 
172
172
  Row filters (`access.rowFilter`) are a separate thing. They come from the access rules (`.own`, `.team`, filters of capabilities, returned filters), are checked against the **full** model because they may use hidden or non-filterable columns, and are ANDed into queries by the server.
@@ -61,20 +61,20 @@ The job `ai.fill` fills it:
61
61
 
62
62
  - after a create, when the field is empty and a field the prompt reads holds something;
63
63
  - after an update that changes a field the prompt reads, unless the same write changed the AI field itself: a person's own edit wins, and the job's own write never sets off another;
64
- - as the user who wrote, with the roles they had then, in their tenant; a writer who may not update the AI field, or read the fields its prompt reads, gets no fill, and neither does a visitor sending a [public form](forms.md)).
64
+ - as the user who wrote, with the roles they had then, in their tenant; a writer who may not update the AI field, or read the fields its prompt reads, gets no fill, and neither does a visitor sending a [public form](forms.md).
65
65
 
66
- Quick edits in a row leave one waiting job per record and field, with the latest writer. When a field the prompt reads changes while the model answers, the job writes nothing and the newer job fills it; a record deleted since is skipped. A model that fails is retried, up to five tries, the first retry after 30 seconds and each later one twice as long; then the job shows on the [failed jobs page](jobs.md#failed-jobs-page)). Four fills run at once per worker.
66
+ Quick edits in a row leave one waiting job per record and field, with the latest writer. When a field the prompt reads changes while the model answers, the job writes nothing and the newer job fills it; a record deleted since is skipped. A model that fails is retried, up to five tries, the first retry after 30 seconds and each later one twice as long; then the job shows on the [failed jobs page](jobs.md#failed-jobs-page). Four fills run at once per worker.
67
67
 
68
68
  Only writes through the API fill a field: a row written with SQL, or an import that goes around the API, gets no fill.
69
69
 
70
70
  ## AI actions
71
71
 
72
- `a.ai(name, { label, prompt, writes, icon?, confirm? })` names an action of the view, shown in the record page's action rail and runnable from a composed page's `<Action name="..." />` like any [named action](layouts.md#named-actions)). `writes` is a text or enum field of the resource that is not read-only, and the prompt may read that field too, to rewrite or translate it in place. With `confirm` the button asks first. While the model answers the button shows that it is busy; then the record reloads and a toast says it is done, or why it failed.
72
+ `a.ai(name, { label, prompt, writes, icon?, confirm? })` names an action of the view, shown in the record page's action rail and runnable from a composed page's `<Action name="..." />` like any [named action](layouts.md#named-actions). `writes` is a text or enum field of the resource that is not read-only, and the prompt may read that field too, to rewrite or translate it in place. With `confirm` the button asks first. While the model answers the button shows that it is busy; then the record reloads and a toast says it is done, or why it failed.
73
73
 
74
74
  Who may run one:
75
75
 
76
76
  - a signed-in user; a visitor never spends model calls;
77
- - whose view of the resource has the action, so [views per role](ui-config.md#actions-and-views-per-role)) decide who has which;
77
+ - whose view of the resource has the action, so [views per role](ui-config.md#actions-and-views-per-role) decide who has which;
78
78
  - who may read the fields the prompt reads, and update the field it writes on this record; otherwise the button is not offered or is disabled.
79
79
 
80
80
  `/api/meta` sends the action without its prompt, which stays on the server.
@@ -95,7 +95,7 @@ Every check is made before the model is asked.
95
95
 
96
96
  ## The model
97
97
 
98
- AI fields and actions use the [assistant's model settings](assistant.md#which-backend)): `PROTOBASE_ASSISTANT_API_KEY`, with `PROTOBASE_ASSISTANT_BASE_URL` and `PROTOBASE_ASSISTANT_MODEL`, or the same keys of `options.assistant`. They use them also when `PROTOBASE_ASSISTANT_URL` names a chat backend elsewhere, which replaces the chat, not the model, and when `options.assistant` is `false`, which turns off the chat only. On OpenRouter they ask for little reasoning.
98
+ AI fields and actions use the [assistant's model settings](assistant.md#which-backend): `PROTOBASE_ASSISTANT_API_KEY`, with `PROTOBASE_ASSISTANT_BASE_URL` and `PROTOBASE_ASSISTANT_MODEL`, or the same keys of `options.assistant`. They use them also when `PROTOBASE_ASSISTANT_URL` names a chat backend elsewhere, which replaces the chat, not the model, and when `options.assistant` is `false`, which turns off the chat only. On OpenRouter they ask for little reasoning.
99
99
 
100
100
  `protobase dev` and `protobase serve` do not start when a resource has an AI field or a view an AI action and no key is set; `PROTOBASE_STARTUP_CHECKS=false` skips that check, as it does the others. Other commands, such as `protobase migration`, run without a key.
101
101
 
@@ -103,4 +103,4 @@ Every click and every write that calls for a fill is one model call on that key,
103
103
 
104
104
  ## The jobs schema
105
105
 
106
- AI fields are filled by jobs, so a project with one needs the [`jobs` schema](jobs.md#the-jobs-schema)), which [`protobase migration`](cli.md#migration)) writes, and the app's workers. AI actions run in the request and need neither.
106
+ AI fields are filled by jobs, so a project with one needs the [`jobs` schema](jobs.md#the-jobs-schema), which [`protobase migration`](cli.md#migration) writes, and the app's workers. AI actions run in the request and need neither.
@@ -23,11 +23,11 @@ const admin = createAdmin({
23
23
  })
24
24
  ```
25
25
 
26
- Run the ERP example with `bun run --cwd examples/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.
26
+ Run the ERP example with `bun run --cwd examples/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
 
30
- `/api/v1/*` is resources only, so a table may be called `meta` or `docs`. The system endpoints (`/api/meta`, `/api/openapi.json`, `/api/docs`), the app's own [API functions](../guides/api-functions.md)) (`/api/functions/<name>`), [file downloads](files.md#downloads)) (`/api/files/<provider>/<path>`), [public forms](forms.md#routes)) (`/api/forms/<name>`) and login (`/api/auth/*`) live beside it; the parent of `options.basePath` is where the system endpoints go.
30
+ `/api/v1/*` is resources only, so a table may be called `meta` or `docs`. The system endpoints (`/api/meta`, `/api/openapi.json`, `/api/docs`), the app's own [API functions](../guides/api-functions.md) (`/api/functions/<name>`), [file downloads](files.md#downloads) (`/api/files/<provider>/<path>`), [public forms](forms.md#routes) (`/api/forms/<name>`) and login (`/api/auth/*`) live beside it; the parent of `options.basePath` is where the system endpoints go.
31
31
 
32
32
  Under `/api/v1`:
33
33
 
@@ -39,11 +39,11 @@ Under `/api/v1`:
39
39
  | `POST /{resource}` | create, `201` with `Location` and `ETag` |
40
40
  | `PATCH /{resource}/{key}` | partial update, `If-Match` required |
41
41
  | `DELETE /{resource}/{key}` | soft delete when the resource has one ([AIP-135](https://google.aip.dev/135)); `If-Match` optional |
42
- | `POST /{resource}:upload?field=&name=` | one file for a [file field](files.md#uploading)), as the raw body or one multipart file part; `201 { value, file, derived, corrected? }`, where `value` is the ticket a write sends as the field's value; `413` over the field's `maxSize`, `415` for a type it does not take |
42
+ | `POST /{resource}:upload?field=&name=` | one file for a [file field](files.md#uploading), as the raw body or one multipart file part; `201 { value, file, derived, corrected? }`, where `value` is the ticket a write sends as the field's value; `413` over the field's `maxSize`, `415` for a type it does not take |
43
43
  | `POST /{resource}/{key}:reveal` | `{ "field": "iban" }` gives `{ field, value }` of one [sensitive field](#sensitive-fields-and-audit), with `Cache-Control: no-store`, and publishes an audit event |
44
- | `GET /{resource}/{key}:history` | the record's changes, newest first, for a resource with [history](history.md)): `page_size` (20, max 100), `page_token`; see [Record history](#record-history) |
45
- | `GET`, `POST /{resource}/{key}:comments`, `GET /{resource}/{key}:mentionable?q=` | the record's comments, newest first, adding one, and whom it may mention, for a resource with [comments](comments.md)); see [Record comments](#record-comments) |
46
- | `POST /{resource}/{key}:generate` | `{ "action": "<name>" }` runs an [AI action](ai.md#ai-actions)) of the caller's view: the model writes its field, with the ETag the record was read with, and it answers the record as an update does |
44
+ | `GET /{resource}/{key}:history` | the record's changes, newest first, for a resource with [history](history.md): `page_size` (20, max 100), `page_token`; see [Record history](#record-history) |
45
+ | `GET`, `POST /{resource}/{key}:comments`, `GET /{resource}/{key}:mentionable?q=` | the record's comments, newest first, adding one, and whom it may mention, for a resource with [comments](comments.md); see [Record comments](#record-comments) |
46
+ | `POST /{resource}/{key}:generate` | `{ "action": "<name>" }` runs an [AI action](ai.md#ai-actions) of the caller's view: the model writes its field, with the ETag the record was read with, and it answers the record as an update does |
47
47
  | `POST /{resource}/{key}:undelete` | restores a soft-deleted record ([AIP-164](https://google.aip.dev/164)); `If-Match` optional; `409` when not deleted, `400` on hard-delete resources |
48
48
  | `POST /api/v1:batchWrite` | many writes in one transaction, see [Batch writes](#batch-writes) |
49
49
  | `GET /{resource}:facets?field=&filter=&limit=&label=` | `{ field, facets: [{ value, count }] }`, the `limit` most frequent values (100 by default, at most 1,000), never all of them; with `label`, a relation's facets carry the related record's name as `label`, as in [Related names](#related-names) |
@@ -53,8 +53,8 @@ Under `/api/v1`:
53
53
  | `GET /{resource}:map?latitude=&longitude=&zoom=&filter=&order_by=&fields=&labels=&photos=&photos_order_by=` | the records in a map's view, the bounding box being in `filter` (`lat >= 51.9 AND lat <= 52.1 AND lng >= 4.2 AND lng <= 4.5`), as `{ items, buckets, total_size }`; see [Maps](#maps) |
54
54
  | `GET /{resource}:seek?position=&order_by=&filter=&page_size=&fields=&labels=&photos=&photos_order_by=` | the page at a row position (scrollbar jumps), with `next_page_token` and `prev_page_token`; same items as a list |
55
55
  | `GET /api/meta` | resource, view and page models (fields carry `default`: `{ value }` or `{ db: true }`) and the caller's `permissions`; the `ETag` hashes both, so it differs per user; `If-None-Match` gives `304` |
56
- | `GET /api/live?after=` | a `text/event-stream` of which records of the [live](live.md)) resources the caller may read change, keys only; see [The stream](live.md#the-stream)) |
57
- | `POST /api/files:cleanup` | runs the [scheduled file deletes](files.md#deleting-files)) that are due, for an admin; `{ deleted, kept }` |
56
+ | `GET /api/live?after=` | a `text/event-stream` of which records of the [live](live.md) resources the caller may read change, keys only; see [The stream](live.md#the-stream) |
57
+ | `POST /api/files:cleanup` | runs the [scheduled file deletes](files.md#deleting-files) that are due, for an admin; `{ deleted, kept }` |
58
58
  | `GET /api/openapi.json`, `GET /api/docs` | OpenAPI 3.1 for the caller (only the resources, fields and operations their roles allow), and the Scalar reference |
59
59
 
60
60
  Every response carries `X-Meta-Version`, the hash of the models, the Protobase version and the caller's roles; a client that sees it change (a model edit, an upgrade, a role change) refetches `/meta`.
@@ -65,11 +65,11 @@ A list returns `{ items, next_page_token, total_size_estimate }`, the estimate b
65
65
 
66
66
  ### Record history
67
67
 
68
- `GET /{resource}/{key}:history` answers `{ items, next_page_token }` for a resource with `.history()`, and `404` for one without. It needs what a get needs, a soft-deleted record included. Each item is `{ id, at, operation, changed, before?, after?, actor, database_role }`: `before` and `after` hold only the fields the caller may read, never a sensitive or file field, `changed` names the changed fields the caller may read, and an update of only other fields is left out. `actor` is `{ id, name? }` for a write through the API, the name when the project's Better Auth knows the user, and `null` otherwise; `database_role` is the role that wrote. See [Record history](history.md)).
68
+ `GET /{resource}/{key}:history` answers `{ items, next_page_token }` for a resource with `.history()`, and `404` for one without. It needs what a get needs, a soft-deleted record included. Each item is `{ id, at, operation, changed, before?, after?, actor, database_role }`: `before` and `after` hold only the fields the caller may read, never a sensitive or file field, `changed` names the changed fields the caller may read, and an update of only other fields is left out. `actor` is `{ id, name? }` for a write through the API, the name when the project's Better Auth knows the user, and `null` otherwise; `database_role` is the role that wrote. See [Record history](history.md).
69
69
 
70
70
  ### Record comments
71
71
 
72
- For a resource with `.comments()`, and `404` for one without; each needs what a get needs. `GET /{resource}/{key}:comments` answers `{ items, next_page_token }`, newest first, a soft-deleted record included, with `page_size` (20, max 100) and `page_token`. Each item is `{ id, created_at, body, author, mentions }`, where `author` and each of `mentions` is `{ id, name? }`, the name when the project's Better Auth knows the user. `POST` with `{ "body": "...", "mentions": ["<user id>"] }` adds the caller's comment to a record that is not deleted and answers `201` with it: `body` is trimmed, `mentions` names at most 20 users, the caller dropped, and each is emailed. `GET /{resource}/{key}:mentionable?q=` answers `{ items: [{ id, name }] }`: at most 8 users whose name contains `q`, by name, who may read the record, without the caller. Its problems: `403 comment-needs-user` to a caller who is not signed in, on the `POST` and on `:mentionable`; `400 invalid-comment` for an empty body or one over 10,000 characters; `400 invalid-mention` for a mention of someone who may not read the record, which keeps nothing. See [Record comments](comments.md)).
72
+ For a resource with `.comments()`, and `404` for one without; each needs what a get needs. `GET /{resource}/{key}:comments` answers `{ items, next_page_token }`, newest first, a soft-deleted record included, with `page_size` (20, max 100) and `page_token`. Each item is `{ id, created_at, body, author, mentions }`, where `author` and each of `mentions` is `{ id, name? }`, the name when the project's Better Auth knows the user. `POST` with `{ "body": "...", "mentions": ["<user id>"] }` adds the caller's comment to a record that is not deleted and answers `201` with it: `body` is trimmed, `mentions` names at most 20 users, the caller dropped, and each is emailed. `GET /{resource}/{key}:mentionable?q=` answers `{ items: [{ id, name }] }`: at most 8 users whose name contains `q`, by name, who may read the record, without the caller. Its problems: `403 comment-needs-user` to a caller who is not signed in, on the `POST` and on `:mentionable`; `400 invalid-comment` for an empty body or one over 10,000 characters; `400 invalid-mention` for a mention of someone who may not read the record, which keeps nothing. See [Record comments](comments.md).
73
73
 
74
74
  ### Related names
75
75
 
@@ -77,7 +77,7 @@ A list holds a relation as the key of the record it points at. `labels` names th
77
77
 
78
78
  ### Card photos
79
79
 
80
- A list can bring each record's first photos in the same answer, as a cards display's [`photos`](ui-config.md#card-photos)) shows them: `photos=listing_photos.listing_id.photo&photos_order_by=position` on a list, `:search`, `:seek` or `:map` adds `photos: { "12": [{ "uri": "public:…", "url": "…", "placeholder": "…" }, …] }`, the `photo` files of the first ten records of `listing_photos` whose relation `listing_id` points at each item, by its key as text, in `photos_order_by` order (their primary key breaking ties). An item without photos is not in `photos`. The entry names a resource, its relation to the listed one and its file field; a malformed entry, or `photos_order_by` without it, is a `400`.
80
+ A list can bring each record's first photos in the same answer, as a cards display's [`photos`](ui-config.md#card-photos) shows them: `photos=listing_photos.listing_id.photo&photos_order_by=position` on a list, `:search`, `:seek` or `:map` adds `photos: { "12": [{ "uri": "public:…", "url": "…", "placeholder": "…" }, …] }`, the `photo` files of the first ten records of `listing_photos` whose relation `listing_id` points at each item, by its key as text, in `photos_order_by` order (their primary key breaking ties). An item without photos is not in `photos`. The entry names a resource, its relation to the listed one and its file field; a malformed entry, or `photos_order_by` without it, is a `400`.
81
81
 
82
82
  The photos are read as the caller lists that resource, in one query for the whole page: its tenant, row filter, soft delete and readable fields apply, each file comes as that resource's list returns it, with its placeholder when the caller may read that field, and the [scan guard](#safety) checks the lookup like a list. A caller who cannot list the resource, or read and use the relation, the file field or the sorted fields, gets `photos: {}`, as they would for a resource or field that does not exist, so `photos` never tells it exists; so does a list of a resource with a composite key.
83
83
 
@@ -87,12 +87,12 @@ The photos are read as the caller lists that resource, in one query for the whol
87
87
 
88
88
  ## Access
89
89
 
90
- Access is resolved once per request and resource ([`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/)), see [Login with Better Auth](auth.md)) for roles and capabilities), and everything downstream uses the result:
90
+ Access is resolved once per request and resource ([`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/), see [Login with Better Auth](auth.md) for roles and capabilities), and everything downstream uses the result:
91
91
 
92
92
  - **Operations**: a denied operation is `403`; a resource the caller can do nothing with does not exist for them (`404` everywhere, absent from `/meta` and the OpenAPI document).
93
93
  - **Readable fields**: the caller works with a restricted model that has only the fields they may read. `filter`, `order_by`, `fields`, `search(...)`, `:facets`, `:aggregate`, `:histogram`, `:series`, `:map`, `:seek` and `:search` bodies are checked against it, so a hidden field is refused exactly like an unknown one (same status, same message and hint, nothing that says it exists). List, get, create, update and delete responses contain readable fields only, and queries select only those columns.
94
94
  - **Sensitive fields** are readable fields that no response carries and no request may name, except `:reveal`; they can be written. See [Sensitive fields and audit](#sensitive-fields-and-audit).
95
- - **Writable fields**: only fields the caller may write and read are accepted, and [write-only](access.md#write-only-fields)) ones; any other is `400`, worded as unknown (hidden) or read-only.
95
+ - **Writable fields**: only fields the caller may write and read are accepted, and [write-only](access.md#write-only-fields) ones; any other is `400`, worded as unknown (hidden) or read-only.
96
96
  - **Row filters**: a rule that returns a filter (`.own`, `.team`) narrows every read (list, get, aggregates) and the rows a write may target; the database applies it, so it may use columns the caller cannot see. A row outside it is a `404`.
97
97
  - **Record-level rules** (a rule that needs the record, such as `status != 'locked'`) run in the write transaction with the stored record; a filter they return is checked in the database against the row as written, and a miss rolls the write back with `403`.
98
98
  - **`.own` on create**: when the create rule is limited to rows, the owner field is set to the caller unless given, and a row owned by someone else is refused with `403`.
@@ -100,7 +100,7 @@ Access is resolved once per request and resource ([`resolveAccess`](https://docs
100
100
  - **ETags**: with a read-only `version` or `updated_at` column the ETag is a hash of that column's exact text, so it never shows a hidden value yet moves on every change. Without one it is a hash of the fields the caller may read, sensitive ones excluded: a change to a field they cannot read, or to a sensitive field, does not change their ETag.
101
101
  - **Errors** never contain values of fields the caller cannot read; database errors leave out constraint and column names.
102
102
 
103
- `options.roles` (from `defineRoles`) makes an operation without an explicit rule need the matching capability (`orders.update`), and limits each role to the [fields and rows](access.md#capabilities)) its capabilities list; `options.defaultAccess: 'allow' | 'deny'` overrides the capability check. Without either, operations without a rule are allowed (single-admin projects).
103
+ `options.roles` (from `defineRoles`) makes an operation without an explicit rule need the matching capability (`orders.update`), and limits each role to the [fields and rows](access.md#capabilities) its capabilities list; `options.defaultAccess: 'allow' | 'deny'` overrides the capability check. Without either, operations without a rule are allowed (single-admin projects).
104
104
 
105
105
  ### Record permissions
106
106
 
@@ -108,11 +108,11 @@ Get responses carry `permissions: { update, delete, fields }`, where `fields` ma
108
108
 
109
109
  ### `/meta` and OpenAPI per caller
110
110
 
111
- `/meta` returns, per caller: the resources they can do anything with as restricted models (hidden fields absent, `readOnly` unless writable), the view for their roles ([`pickView`](https://docs.protobase.net/api/schema/functions/pickview/))) with every reference to a hidden field removed (columns, sort, search, filters, layout, chart, title, search result) and the [related sections](ui-config.md#related-records)) they cannot use, `permissions[resource]` as `{ read, create, update, delete, conditional }`, the [user menu](user-menu.md)) as `userMenu` and the [bottom bar](bottom-bar.md)) of their active role as `bottomBar`, each without the resources and pages they cannot see, and the [composed pages](layouts.md#access)) as `pages`, each without the elements that name what they cannot see or do, and, for a caller with the `admin` or `ai` role, the [assistant](assistant.md#who-sees-it)) backend as `assistant: { url }` when the app has one, and, for a caller with the `admin` role, the [runtime updates](versioning.md#runtime-updates)) endpoint as `runtime: { url }` when the app has one, and, for everyone, the style of the record page's [maps](ui-config.md#maps)) as `maps: { style }` when the app has one, the [language](languages.md)) of its screens as `locale` when it sets one, and the Protobase version the server runs as `protobaseVersion`. When that version changes under an open page, the admin app keeps what the page shows, stops reading `/meta`, and offers to reload the page, asking first while a form holds unsaved changes or a save is under way. `conditional` lists the operations allowed only for some records (a row filter or a record-level rule decides). A view's sidebar group ([`nav.recent`](sidebar.md#recent-records))) is dropped when it uses a field they cannot read. The ETag hashes all of it, so it differs per user and per roles. The OpenAPI document is generated the same way: record and body schemas have only the readable and writable fields, and methods the caller may not use are left out. Its `servers` are relative to the document (`v1` for the resources, `.` for the system endpoints), and `/api/docs` loads `openapi.json` beside it, so both are right on any host and under any prefix the API is reached at.
111
+ `/meta` returns, per caller: the resources they can do anything with as restricted models (hidden fields absent, `readOnly` unless writable), the view for their roles ([`pickView`](https://docs.protobase.net/api/schema/functions/pickview/)) with every reference to a hidden field removed (columns, sort, search, filters, layout, chart, title, search result) and the [related sections](ui-config.md#related-records) they cannot use, `permissions[resource]` as `{ read, create, update, delete, conditional }`, the [user menu](user-menu.md) as `userMenu` and the [bottom bar](bottom-bar.md) of their active role as `bottomBar`, each without the resources and pages they cannot see, and the [composed pages](layouts.md#access) as `pages`, each without the elements that name what they cannot see or do, and, for a caller with the `admin` or `ai` role, the [assistant](assistant.md#who-sees-it) backend as `assistant: { url }` when the app has one, and, for a caller with the `admin` role, the [runtime updates](versioning.md#runtime-updates) endpoint as `runtime: { url }` when the app has one, and, for everyone, the style of the record page's [maps](ui-config.md#maps) as `maps: { style }` when the app has one, the [language](languages.md) of its screens as `locale` when it sets one, and the Protobase version the server runs as `protobaseVersion`. When that version changes under an open page, the admin app keeps what the page shows, stops reading `/meta`, and offers to reload the page, asking first while a form holds unsaved changes or a save is under way. `conditional` lists the operations allowed only for some records (a row filter or a record-level rule decides). A view's sidebar group ([`nav.recent`](sidebar.md#recent-records)) is dropped when it uses a field they cannot read. The ETag hashes all of it, so it differs per user and per roles. The OpenAPI document is generated the same way: record and body schemas have only the readable and writable fields, and methods the caller may not use are left out. Its `servers` are relative to the document (`v1` for the resources, `.` for the system endpoints), and `/api/docs` loads `openapi.json` beside it, so both are right on any host and under any prefix the API is reached at.
112
112
 
113
113
  ## Sensitive fields and audit
114
114
 
115
- A field declared [`.sensitive()`](data-config.md#sensitive-fields)) is in `/meta` (marked `sensitive: true`), in record `permissions.fields` and in create and update bodies, but in no list, get, `:search`, `:seek`, write or batch response, and `filter`, `order_by`, `fields` and the aggregates refuse it like an unknown field. `POST /{resource}/{key}:reveal` with `{ "field": "<name>" }` returns one record's value. It needs read access to the record and the field: another tenant's record, a row outside the caller's row filter or a key that does not exist is a `404`, a field the caller cannot read or that is not sensitive a `400`. An [encrypted field](data-config.md#encrypted-fields))'s reveal decrypts its value, and an empty one reveals `null`; a value that does not decrypt is a `500` reported to the operator, without an audit event. An update that changes the key of a record with encrypted fields is a `400` `key-change-unsupported`.
115
+ A field declared [`.sensitive()`](data-config.md#sensitive-fields) is in `/meta` (marked `sensitive: true`), in record `permissions.fields` and in create and update bodies, but in no list, get, `:search`, `:seek`, write or batch response, and `filter`, `order_by`, `fields` and the aggregates refuse it like an unknown field. `POST /{resource}/{key}:reveal` with `{ "field": "<name>" }` returns one record's value. It needs read access to the record and the field: another tenant's record, a row outside the caller's row filter or a key that does not exist is a `404`, a field the caller cannot read or that is not sensitive a `400`. An [encrypted field](data-config.md#encrypted-fields)'s reveal decrypts its value, and an empty one reveals `null`; a value that does not decrypt is a `500` reported to the operator, without an audit event. An update that changes the key of a record with encrypted fields is a `400` `key-change-unsupported`.
116
116
 
117
117
  Before answering, the server publishes an audit event to `options.audit`, and when publishing fails the reveal fails (`500`), so no value leaves without its event. The event never holds the value:
118
118
 
@@ -129,7 +129,7 @@ type AuditEvent = {
129
129
  }
130
130
  ```
131
131
 
132
- With [organizations](auth.md#organizations)), someone with a global role switching into an organization they are not a member of publishes `{ type: 'organization.entered', at, actor, organization, origin }` first, where `actor.roles` are their global roles; a failed publish refuses the switch. `AuditEvent` is the union of the two.
132
+ With [organizations](auth.md#organizations), someone with a global role switching into an organization they are not a member of publishes `{ type: 'organization.entered', at, actor, organization, origin }` first, where `actor.roles` are their global roles; a failed publish refuses the switch. `AuditEvent` is the union of the two.
133
133
 
134
134
  ### Audit events
135
135
 
@@ -137,7 +137,7 @@ With [organizations](auth.md#organizations)), someone with a global role switchi
137
137
 
138
138
  ## Filters
139
139
 
140
- `filter` and `order_by` are AIP-160 and AIP-132 text, checked against the model (filterable and sortable fields only). Functions: `in(field, v, ...)`, `search("text")` and bare words (every word, ignoring case, anywhere inside one of the resource's search fields, so `port` finds "Portfolio"; `%`, `_` and `\` are literal; a [`digitsEnd`](data-config.md#resource)) field matches only the end of its digits), `similar(field, "text")`, `regex(field, "pattern")`, `isNull(field)`, `now()` with offsets such as `now() - 7d`. A filter is capped at 10,000 characters in a query string and 200,000 in a `:search` body.
140
+ `filter` and `order_by` are AIP-160 and AIP-132 text, checked against the model (filterable and sortable fields only). Functions: `in(field, v, ...)`, `search("text")` and bare words (every word, ignoring case, anywhere inside one of the resource's search fields, so `port` finds "Portfolio"; `%`, `_` and `\` are literal; a [`digitsEnd`](data-config.md#resource) field matches only the end of its digits), `similar(field, "text")`, `regex(field, "pattern")`, `isNull(field)`, `now()` with offsets such as `now() - 7d`. A filter is capped at 10,000 characters in a query string and 200,000 in a `:search` body.
141
141
 
142
142
  ## Writes
143
143
 
@@ -172,24 +172,24 @@ The rules behind these steps are described under [Access](#access).
172
172
 
173
173
  - **Keys** are the URL text (`a,b` when composite), a number, a list of parts, or a reference.
174
174
  - **`$ref`**: `ref: 'invoice'` on a create names the record; later operations use `{ "$ref": "invoice" }` as a key, a key part, or a value in `data` (it stands for that record's key, or with `{ "$ref": "invoice", "field": "number" }` a readable field's value). A ref must come after its create.
175
- - **`reorder`** sets `field` to `start`, `start` + 1, ... in the order of `keys`, so a long list sends only the stretch that moved, and writes only the records whose value changes, each as an ordinary update (so each needs its `etags` entry, and hooks see each). To work with a non-deferrable unique index such as `(invoice_id, position)`, the changing records are first moved out of the range in use, in the same transaction and without touching their ETags: above the highest value of the column, or, when a check constraint refuses that (checked with a savepoint), below the lowest one. Then they get their final values, which collide with nothing. The field must be an integer the caller may write; the keys must all exist and be visible to the caller. When it is the resource's [position with `after`](ui-config.md#ranked-after-what-they-depend-on)), a reorder that puts a record at or above a record it depends on, or one of those at or below it, fails with `409` and the type `ranks-above-dependency`, naming both keys in `record` and `dependsOn`; pairs out of order before it do not count.
175
+ - **`reorder`** sets `field` to `start`, `start` + 1, ... in the order of `keys`, so a long list sends only the stretch that moved, and writes only the records whose value changes, each as an ordinary update (so each needs its `etags` entry, and hooks see each). To work with a non-deferrable unique index such as `(invoice_id, position)`, the changing records are first moved out of the range in use, in the same transaction and without touching their ETags: above the highest value of the column, or, when a check constraint refuses that (checked with a savepoint), below the lowest one. Then they get their final values, which collide with nothing. The field must be an integer the caller may write; the keys must all exist and be visible to the caller. When it is the resource's [position with `after`](ui-config.md#ranked-after-what-they-depend-on), a reorder that puts a record at or above a record it depends on, or one of those at or below it, fails with `409` and the type `ranks-above-dependency`, naming both keys in `record` and `dependsOn`; pairs out of order before it do not count.
176
176
  - **Result**: `{ results: [...] }`, one entry per operation in order: `create` and `update` give `record` and `etag`, `delete` gives `deleted: true`, `reorder` gives `records` (every key in order, with its etag).
177
177
  - **Failure**: nothing is written. The problem is the failing operation's own (`400`, `403`, `404`, `409`, `412`, `428`, ...) with `operation` (its index), `op` and `resource` added. A stale ETag anywhere is a `412` for the whole batch.
178
178
 
179
179
  ## Authentication
180
180
 
181
- Real login is [Better Auth](auth.md)). Lower level:
181
+ Real login is [Better Auth](auth.md). Lower level:
182
182
 
183
- `authenticate(request)` returns `{ user: { id, roles }, tenant? }` or throws `unauthorized(...)` (a `401` problem), or `new MissingCredentials(...)` (also a `401`) when the request carries no credential at all. Shipped: `jwtAuthenticator({ jwksUrl | keys, issuer?, audience?, rolesClaim?, tenantClaim?, tenant? })`, which verifies a bearer token with `jose` (`sub` is the user id; `tenant` fixes the tenant instead of reading a claim), and `betterAuthAuthenticator` on top of it ([Login with Better Auth](auth.md))). No code path treats a request as a user without verifying a credential; the one exception is the [anonymous role](access.md#anonymous-access)), which the resources API gives a request that has none, when the project defines it.
183
+ `authenticate(request)` returns `{ user: { id, roles }, tenant? }` or throws `unauthorized(...)` (a `401` problem), or `new MissingCredentials(...)` (also a `401`) when the request carries no credential at all. Shipped: `jwtAuthenticator({ jwksUrl | keys, issuer?, audience?, rolesClaim?, tenantClaim?, tenant? })`, which verifies a bearer token with `jose` (`sub` is the user id; `tenant` fixes the tenant instead of reading a claim), and `betterAuthAuthenticator` on top of it ([Login with Better Auth](auth.md)). No code path treats a request as a user without verifying a credential; the one exception is the [anonymous role](access.md#anonymous-access), which the resources API gives a request that has none, when the project defines it.
184
184
 
185
185
  ## CORS
186
186
 
187
- The API sends no CORS headers until it has something to allow: other websites in `options.cors` (a list of origins, or `'*'` for any), which defaults to `PROTOBASE_CORS_ORIGINS` (`*` or comma separated http and https origins), other [origins of the app](auth.md#several-origins)), which are always allowed, or a [mobile section](../guides/mobile-app.md)), which allows the app's Capacitor origins, `capacitor://localhost` and `https://localhost`. `PROTOBASE_CORS_ORIGINS` refuses other schemes at startup.
187
+ The API sends no CORS headers until it has something to allow: other websites in `options.cors` (a list of origins, or `'*'` for any), which defaults to `PROTOBASE_CORS_ORIGINS` (`*` or comma separated http and https origins), other [origins of the app](auth.md#several-origins), which are always allowed, or a [mobile section](../guides/mobile-app.md), which allows the app's Capacitor origins, `capacitor://localhost` and `https://localhost`. `PROTOBASE_CORS_ORIGINS` refuses other schemes at startup.
188
188
 
189
- - It covers `/api/*` but Better Auth's `/api/auth/*`, which checks origins itself, and [API functions](../guides/api-functions.md)) with a `cors` of their own; supabase-js's [`/api/sb`](auth.md#supabase-js-and-supabasessr)) is under it too.
189
+ - It covers `/api/*` but Better Auth's `/api/auth/*`, which checks origins itself (the mobile app [signs in](../guides/mobile-app.md) through native HTTP, outside CORS), and [API functions](../guides/api-functions.md) with a `cors` of their own; supabase-js's [`/api/sb`](auth.md#supabase-js-and-supabasessr) is under it too.
190
190
  - An allowed origin gets `Access-Control-Allow-Origin` with its name and `Vary: Origin`, or `*` with `'*'`. No credentials: browser code calls the API with a bearer token.
191
191
  - Preflights are answered before authentication, for `authorization`, `content-type`, `if-match`, `if-none-match` and supabase-js's `apikey`, `x-client-info` and `x-supabase-api-version`, and kept for 10 minutes. `Location`, `ETag`, `X-Meta-Version` and `X-Protobase-Warning` are exposed.
192
- - An API whose resources another app draws as [remote resources](remote-resources.md#cors)) lists that app's origin here.
192
+ - An API whose resources another app draws as [remote resources](remote-resources.md#cors) lists that app's origin here.
193
193
 
194
194
  ## Safety
195
195
 
@@ -199,7 +199,7 @@ The API sends no CORS headers until it has something to allow: other websites in
199
199
  - Patterns (`name = "*port*"`), `regex()`, `similar()` and `search()` need a pg_trgm (GIN or GiST) index on each column they read, a `digitsEnd` search field one on its digits; JSON `field:value` needs a GIN index.
200
200
  - A partial index counts for nothing, and a resource on a plain view or a foreign table, which has no indexes of its own, is not checked.
201
201
 
202
- A column without one is a `400` `expensive-query` problem that names it, with `columns` (each `{ field, column, use, need, suggestion }`) and a `create index` `suggestion`; `scanGuard: { mode: 'warn' }` answers with an `X-Protobase-Warning` header instead, `'off'` disables it. The indexes are read when a table is first queried and kept for the process lifetime, so restart the server after adding one. [`protobase doctor`](cli.md#doctor)) judges every read the config makes by the same rule against the database's indexes, so a missing index fails it before a deploy instead of a page after.
202
+ A column without one is a `400` `expensive-query` problem that names it, with `columns` (each `{ field, column, use, need, suggestion }`) and a `create index` `suggestion`; `scanGuard: { mode: 'warn' }` answers with an `X-Protobase-Warning` header instead, `'off'` disables it. The indexes are read when a table is first queried and kept for the process lifetime, so restart the server after adding one. [`protobase doctor`](cli.md#doctor) judges every read the config makes by the same rule against the database's indexes, so a missing index fails it before a deploy instead of a page after.
203
203
 
204
204
  ## Errors
205
205
 
@@ -4,11 +4,11 @@
4
4
 
5
5
  The app's name, icon and colours, which its sidebar logo, browser tabs, home-screen icon, web manifest and mail all follow.
6
6
 
7
- An app looks like its own everywhere from three things in its project: its name, its icon and its colours. The sidebar's logo, the browser tab, the icon on a phone's home screen, the [installed app](installable-app.md)) and the auth mail all follow them, with no component to write.
7
+ An app looks like its own everywhere from three things in its project: its name, its icon and its colours. The sidebar's logo, the browser tab, the icon on a phone's home screen, the [installed app](installable-app.md) and the auth mail all follow them, with no component to write.
8
8
 
9
9
  | What | Where | Used by |
10
10
  | --- | --- | --- |
11
- | Name | `appName` of `createAuth` ([auth configuration](auth.md#configuration))), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, passkey and authenticator prompts, auth mail and its sender's name |
11
+ | Name | `appName` of `createAuth` ([auth configuration](auth.md#configuration)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, passkey and authenticator prompts, auth mail and its sender's name |
12
12
  | Icon | `protobase.favicon.svg` at the project's root | the browser tab, the sidebar's logo, the installed app's icon |
13
13
  | Raster icons | optional PNGs beside the SVG, below | the iPhone home screen and Android launchers, which take no SVG |
14
14
  | Colours | `app` in `protobase.config.ts` | the installed app's title bar and its start screen |
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
 
32
32
  ## The icons
33
33
 
34
- `protobase.favicon.svg` is the one source of the app's icon: the tab shows it, the [web manifest](installable-app.md#the-manifest)) names it, and with it the sidebar's logo draws it beside the app's name in place of Protobase's mark and wordmark. A project's own [`shell.logo`](custom-components.md#shell-slots)) still wins.
34
+ `protobase.favicon.svg` is the one source of the app's icon: the tab shows it, the [web manifest](installable-app.md#the-manifest) names it, and with it the sidebar's logo draws it beside the app's name in place of Protobase's mark and wordmark. A project's own [`shell.logo`](custom-components.md#shell-slots) still wins.
35
35
 
36
36
  Some platforms take no SVG, so a project may put PNGs of the same icon beside it, each square at its size:
37
37
 
@@ -51,4 +51,4 @@ Each is optional, and none is made from the SVG: without the touch icon an iPhon
51
51
  - `themeColor`: the installed app's title bar and the browser's toolbar around it (`theme_color`).
52
52
  - `backgroundColor`: the screen the installed app shows while it starts (`background_color`).
53
53
 
54
- The app's own colours, its buttons and surfaces, are the [theme](theme.md))'s.
54
+ The app's own colours, its buttons and surfaces, are the [theme](theme.md)'s.
@@ -32,7 +32,7 @@ Every package lists the packages it imports in its `package.json` (`workspace:*`
32
32
  - Examples, their tests and `test-support/` import the packages by name, never by path.
33
33
  - No circular dependencies.
34
34
 
35
- In this repository, entry points export TypeScript source directly and the CLI runs its source on Bun, or on Node through [tsx](https://tsx.is), so nothing needs a build. The published packages are built to JavaScript in `dist` by `bun run build` and `bun pm pack` (`scripts/publish.mjs`) (see [CLI](cli.md#how-it-runs))). The other builds are for deployment: the serve runtime, `packages/cli/src/serve/main.ts` bundled with its dependencies into `dist/protobase-serve.js` by `protobase build-serve`, the shell, a production build of the admin app (`packages/ui/src/app`) shipped in `@protobase/ui`'s `dist/shell` and the protobase image, and a project's bundle, its config module plus a copy of the shell and the project's `protobase.ui.tsx` built as a [plugin](plugins.md)), by `protobase build` (see [CLI](cli.md#build))).
35
+ In this repository, entry points export TypeScript source directly and the CLI runs its source on Bun, or on Node through [tsx](https://tsx.is), so nothing needs a build. The published packages are built to JavaScript in `dist` by `bun run build` and `bun pm pack` (`scripts/publish.mjs`) (see [CLI](cli.md#how-it-runs)). The other builds are for deployment: the serve runtime, `packages/cli/src/serve/main.ts` bundled with its dependencies into `dist/protobase-serve.js` by `protobase build-serve`, the shell, a production build of the admin app (`packages/ui/src/app`) shipped in `@protobase/ui`'s `dist/shell` and the protobase image, and a project's bundle, its config module plus a copy of the shell and the project's `protobase.ui.tsx` built as a [plugin](plugins.md), by `protobase build` (see [CLI](cli.md#build)).
36
36
 
37
37
  ## Tests and stories
38
38
 
@@ -8,7 +8,7 @@ The admin app can show an assistant: an **Assistant** button at the end of the t
8
8
 
9
9
  ## Who sees it
10
10
 
11
- `/api/meta` names the backend as `assistant: { url }`, and only for a caller with the `admin` or `ai` role. The app shows the button when `/meta` has it, so without a backend, or for anyone else, nothing shows. Give someone the assistant without making them an admin by adding `ai` to the project's roles (`createAuth({ roles: ['admin', 'ai', ...] })`, see [Roles](auth.md#roles))) and to their user (`protobase users set-role me@example.com sales,ai`).
11
+ `/api/meta` names the backend as `assistant: { url }`, and only for a caller with the `admin` or `ai` role. The app shows the button when `/meta` has it, so without a backend, or for anyone else, nothing shows. Give someone the assistant without making them an admin by adding `ai` to the project's roles (`createAuth({ roles: ['admin', 'ai', ...] })`, see [Roles](auth.md#roles)) and to their user (`protobase users set-role me@example.com sales,ai`).
12
12
 
13
13
  The built-in backend checks the role again on every request.
14
14
 
@@ -20,7 +20,7 @@ The built-in backend checks the role again on every request.
20
20
  | otherwise `PROTOBASE_ASSISTANT_API_KEY` | `/api/assistant`, the built-in backend |
21
21
  | neither | no assistant |
22
22
 
23
- Each variable can also be set in code, as `options.assistant` of `createAdmin` (in `protobase.config.ts`, `export default { ..., options: { assistant: { ... } } }`), which wins over the variable. `assistant: false` turns the assistant off whatever the environment says. A value that is no `http(s)` URL stops the server at startup. The model settings also serve [AI fields and actions](ai.md#the-model)), even with a backend elsewhere or `assistant: false`.
23
+ Each variable can also be set in code, as `options.assistant` of `createAdmin` (in `protobase.config.ts`, `export default { ..., options: { assistant: { ... } } }`), which wins over the variable. `assistant: false` turns the assistant off whatever the environment says. A value that is no `http(s)` URL stops the server at startup. The model settings also serve [AI fields and actions](ai.md#the-model), even with a backend elsewhere or `assistant: false`.
24
24
 
25
25
  | Variable | Option | |
26
26
  | --- | --- | --- |
@@ -57,7 +57,7 @@ The model needs tool calling for the queries. A refused key, an exhausted accoun
57
57
 
58
58
  It lives at `/api/assistant` on the app's own origin and answers with the user's token like the rest of the API. Its system prompt describes the resources, tables and fields the user can see in `/meta`. It has two tools of its own, and [the app's](#the-apps-own-tools):
59
59
 
60
- - **`run_read_only_query`** runs one `SELECT` (or `VALUES`, or a `WITH` query) and shows its rows as a table in the chat. It runs in a `READ ONLY` transaction that is always rolled back, with a statement timeout of 5 seconds and at most 200 rows. Postgres refuses every write inside (`SET TRANSACTION READ WRITE`, writable CTEs, `nextval`, `DO` blocks, functions that write), and settings it changes go with the rollback. The statement runs through the function `query.run_read_only` as the role `<database>_query`, which [`protobase migration`](cli.md#migration)) makes: that role may read every column of the resources' tables, `.sensitive()` fields and the [webhook subscriptions'](webhooks.md)) signing secrets included, and nothing else: not the auth store, nor a table without a resource. The function opens the statement as a cursor, so only one statement runs, and Postgres refuses a change of role inside it. Numbers other than integers of up to 15 digits come back as their exact text, such as `"12.50"`.
60
+ - **`run_read_only_query`** runs one `SELECT` (or `VALUES`, or a `WITH` query) and shows its rows as a table in the chat. It runs in a `READ ONLY` transaction that is always rolled back, with a statement timeout of 5 seconds and at most 200 rows. Postgres refuses every write inside (`SET TRANSACTION READ WRITE`, writable CTEs, `nextval`, `DO` blocks, functions that write), and settings it changes go with the rollback. The statement runs through the function `query.run_read_only` as the role `<database>_query`, which [`protobase migration`](cli.md#migration) makes: that role may read every column of the resources' tables, `.sensitive()` fields and the [webhook subscriptions'](webhooks.md) signing secrets included, and nothing else: not the auth store, nor a table without a resource. The function opens the statement as a cursor, so only one statement runs, and Postgres refuses a change of role inside it. Numbers other than integers of up to 15 digits come back as their exact text, such as `"12.50"`.
61
61
  - **`propose_write_query`** never runs on its own. It shows the statement and a summary on a card with **Approve** and **Reject**. Only Approve runs it, as one statement in a read-write transaction; Reject, or no answer within 10 minutes, runs nothing. The model gets the returned rows, or that nothing ran. Statements are `INSERT`, `UPDATE` or `DELETE` with a `RETURNING` clause.
62
62
 
63
63
  Both run **outside Protobase's access rules and tenant scoping**: whoever has the `admin` or `ai` role can read every resource's table, and with approval change everything the app's database role can, since `propose_write_query` still runs as that role. Give the app a database role without superuser rights, and those roles only to people who may see all of the data.
@@ -66,7 +66,7 @@ Making the query role needs `CREATEROLE` once, for the role that applies the mig
66
66
 
67
67
  ### The app's own tools
68
68
 
69
- `options.assistant.tools` adds tools of the app's own, which the built-in backend offers after its two. A tool is `defineTool({ name, description, parameters, run })` from `@protobase/server`: `parameters` is the JSON Schema of its arguments, and `run(args, context)` returns the text the model reads. A name must be 1 to 64 letters, digits, `_` or `-`, and a name taken twice stops the server at startup. A backend elsewhere has its own tools, so the option does nothing there. A tool's `annotations` are MCP's tool hints (`readOnlyHint`, `destructiveHint`, ...), which the dock ignores; the same tools can be offered over the app's [MCP endpoint](mcp.md#building-on-it)).
69
+ `options.assistant.tools` adds tools of the app's own, which the built-in backend offers after its two. A tool is `defineTool({ name, description, parameters, run })` from `@protobase/server`: `parameters` is the JSON Schema of its arguments, and `run(args, context)` returns the text the model reads. A name must be 1 to 64 letters, digits, `_` or `-`, and a name taken twice stops the server at startup. A backend elsewhere has its own tools, so the option does nothing there. A tool's `annotations` are MCP's tool hints (`readOnlyHint`, `destructiveHint`, ...), which the dock ignores; the same tools can be offered over the app's [MCP endpoint](mcp.md#building-on-it).
70
70
 
71
71
  `context` holds the user's `session`, `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)` and `update(resource, key, data, { etag? })` (without an ETag it updates any version) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. Each answers `{ record, etag }`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
72
72
 
@@ -130,7 +130,7 @@ show(widget('TaskProposal', { taskId: record.id }, { fallback: { title: `Task pr
130
130
 
131
131
  ### How the dock draws them
132
132
 
133
- The dock draws a widget part with the component the app's `protobase.ui.tsx` exports under that name, the same components [composed pages](custom-components.md#components)) use, giving it the part's props. The component reads what it shows when it is drawn, as the signed-in user: the dock is mounted only while it is open, so each opening, and each page load, reads it again. Its buttons call the app's API or the backend directly; they need no turn of the chat, so they work after a restart, from any tab and for any user who may make the call.
133
+ The dock draws a widget part with the component the app's `protobase.ui.tsx` exports under that name, the same components [composed pages](custom-components.md#components) use, giving it the part's props. The component reads what it shows when it is drawn, as the signed-in user: the dock is mounted only while it is open, so each opening, and each page load, reads it again. Its buttons call the app's API or the backend directly; they need no turn of the chat, so they work after a restart, from any tab and for any user who may make the call.
134
134
 
135
135
  - **No component by that name**, such as in an app built before the component was added: the dock draws the fallback as a plain card noting "This version of the app cannot show it live", or, without a fallback, a muted line naming the component.
136
136
  - **A component that throws** is caught on its own: the dock draws the fallback noting "It could not be drawn", without the error, and the rest of the chat stays.
@@ -156,4 +156,4 @@ Breaking change: `AssistantPart` now includes `AssistantWidgetPart`, so code tha
156
156
 
157
157
  ## In the UI
158
158
 
159
- The dock is `AssistantDock` from `@protobase/ui`, built from primitives that custom components and [shell slots](custom-components.md#shell-slots)) can use too: `SidePanel`, `ChatThread`, `ChatMessage`, `Composer`, `ActionCard`, `FieldList`, `StepList`, `DiffView` and `CompactTable`. `ActionCard` takes `frameless` to draw its content, note, buttons, hints and confirm dialog without the bordered card and title row, for a page that is already framed; the title still labels the section for screen readers. `useApiToken()` returns the signed-in user's API token, renewed before it expires, for calling another service as them.
159
+ The dock is `AssistantDock` from `@protobase/ui`, built from primitives that custom components and [shell slots](custom-components.md#shell-slots) can use too: `SidePanel`, `ChatThread`, `ChatMessage`, `Composer`, `ActionCard`, `FieldList`, `StepList`, `DiffView` and `CompactTable`. `ActionCard` takes `frameless` to draw its content, note, buttons, hints and confirm dialog without the bordered card and title row, for a page that is already framed; the title still labels the section for screen readers. `useApiToken()` returns the signed-in user's API token, renewed before it expires, for calling another service as them.