@protobase/cli 0.47.1 → 0.49.0

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 (101) hide show
  1. package/dist/build/config-bundle.js +6 -1
  2. package/dist/build/entry-code.js +30 -17
  3. package/dist/cli/package.js +1 -1
  4. package/dist/config/build-project.js +70 -0
  5. package/dist/config/called-config.js +11 -0
  6. package/dist/config/config-defaults.js +30 -0
  7. package/dist/config/env-values.js +20 -0
  8. package/dist/config/lazy-imports.js +18 -0
  9. package/dist/config/merge-config.js +72 -0
  10. package/dist/config/project-files.js +48 -0
  11. package/dist/config/project-parts.js +201 -0
  12. package/dist/config/read-config.js +31 -0
  13. package/dist/config/source-config.js +37 -0
  14. package/dist/dev/api-child.js +2 -1
  15. package/dist/dev/api-process.d.ts +1 -0
  16. package/dist/dev/api-process.js +5 -2
  17. package/dist/dev/auth-drift-lines.js +8 -0
  18. package/dist/dev/create-db.js +2 -2
  19. package/dist/dev/entry.d.ts +5 -0
  20. package/dist/dev/entry.js +17 -12
  21. package/dist/dev/project.js +23 -47
  22. package/dist/dev/run.js +3 -2
  23. package/dist/main.js +3 -3
  24. package/dist/migration/load-project.js +34 -34
  25. package/dist/migration/parts.js +2 -2
  26. package/dist/migration/summary.js +2 -2
  27. package/dist/mobile/api-origin.js +4 -4
  28. package/dist/mobile/load-project.js +13 -12
  29. package/dist/mobile/register.js +1 -1
  30. package/dist/mobile/run.js +1 -1
  31. package/dist/organizations/register.js +1 -1
  32. package/dist/project/error-reporter.js +3 -3
  33. package/dist/project/import-project-file.js +4 -2
  34. package/dist/project/load-bundle-project.js +16 -25
  35. package/dist/project/load-data-config.js +2 -2
  36. package/dist/project/pg-db.js +10 -4
  37. package/dist/project/placeholder-secret.js +2 -2
  38. package/dist/project/project-admin.js +12 -11
  39. package/dist/scaffold/plan.js +7 -3
  40. package/dist/scaffold/protobase-tables.js +8 -13
  41. package/dist/scaffold/run.js +1 -1
  42. package/dist/serve/create-admin.js +9 -4
  43. package/dist/serve/host-module-ids.js +1 -0
  44. package/dist/serve/host-modules.js +3 -1
  45. package/dist/serve/lifecycle.js +19 -14
  46. package/dist/serve/load-bundle.js +41 -11
  47. package/dist/serve/mobile-release.js +1 -1
  48. package/dist/serve/serve-bundle.js +3 -3
  49. package/dist/supabase/auth-config.js +33 -28
  50. package/dist/supabase/config-jobs.js +28 -27
  51. package/dist/supabase/config-object.js +25 -0
  52. package/dist/supabase/cron-job-file.js +13 -14
  53. package/dist/supabase/cron-jobs-write.js +6 -12
  54. package/dist/supabase/cron-plan.js +3 -51
  55. package/dist/supabase/project-files.js +4 -9
  56. package/dist/supabase/report.js +3 -3
  57. package/dist/users/load-auth.js +16 -15
  58. package/dist/worker/start-worker.js +18 -15
  59. package/package.json +8 -6
  60. package/skills/protobase/SKILL.md +2 -1
  61. package/skills/protobase/references/features/notifications.md +1 -1
  62. package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
  63. package/skills/protobase/references/features/start-a-project.md +3 -0
  64. package/skills/protobase/references/getting-started.md +2 -2
  65. package/skills/protobase/references/guides/api-functions.md +4 -4
  66. package/skills/protobase/references/guides/deploy.md +8 -8
  67. package/skills/protobase/references/guides/existing-database.md +11 -31
  68. package/skills/protobase/references/guides/first-plugin.md +1 -1
  69. package/skills/protobase/references/guides/mobile-app.md +5 -3
  70. package/skills/protobase/references/guides/plugin-build.md +1 -1
  71. package/skills/protobase/references/guides/push-notifications.md +6 -7
  72. package/skills/protobase/references/guides/remote-resources.md +22 -31
  73. package/skills/protobase/references/reference/access.md +3 -3
  74. package/skills/protobase/references/reference/ai.md +1 -9
  75. package/skills/protobase/references/reference/api.md +15 -15
  76. package/skills/protobase/references/reference/app-identity.md +9 -10
  77. package/skills/protobase/references/reference/assistant.md +6 -6
  78. package/skills/protobase/references/reference/auth.md +126 -96
  79. package/skills/protobase/references/reference/bottom-bar.md +1 -1
  80. package/skills/protobase/references/reference/cli.md +36 -86
  81. package/skills/protobase/references/reference/comments.md +0 -8
  82. package/skills/protobase/references/reference/config.md +152 -0
  83. package/skills/protobase/references/reference/data-config.md +2 -2
  84. package/skills/protobase/references/reference/email.md +36 -37
  85. package/skills/protobase/references/reference/events.md +1 -1
  86. package/skills/protobase/references/reference/files.md +18 -23
  87. package/skills/protobase/references/reference/forms.md +5 -17
  88. package/skills/protobase/references/reference/history.md +2 -3
  89. package/skills/protobase/references/reference/installable-app.md +1 -1
  90. package/skills/protobase/references/reference/jobs.md +53 -56
  91. package/skills/protobase/references/reference/languages.md +4 -2
  92. package/skills/protobase/references/reference/mcp.md +11 -11
  93. package/skills/protobase/references/reference/notifications.md +26 -24
  94. package/skills/protobase/references/reference/plugins.md +11 -14
  95. package/skills/protobase/references/reference/remote-resources.md +18 -24
  96. package/skills/protobase/references/reference/supabase-realtime.md +1 -1
  97. package/skills/protobase/references/reference/supabase-rest.md +1 -1
  98. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  99. package/skills/protobase/references/reference/ui-config.md +15 -17
  100. package/skills/protobase/references/reference/versioning.md +1 -1
  101. package/skills/protobase/references/reference/webhooks.md +6 -7
@@ -8,15 +8,14 @@ You turn notifications on, send one when something happens in your app, and see
8
8
 
9
9
  ## 1. Turn notifications on
10
10
 
11
- Add `notifications()` to `protobase.config.ts`:
11
+ Add `notifications` to `protobase.config.ts`:
12
12
 
13
13
  ```ts
14
- import { defineConfig, notifications } from '@protobase/server'
14
+ import { defineConfig } from '@protobase/config'
15
15
 
16
16
  export default defineConfig({
17
- config,
18
- extends: [notifications()],
19
- // auth, authenticate, jobs, ...
17
+ notifications: {},
18
+ // auth, jobs, ...
20
19
  })
21
20
  ```
22
21
 
@@ -62,7 +61,7 @@ import { appPath } from '@protobase/schema'
62
61
  import { sendNotification, subscription } from '@protobase/server'
63
62
 
64
63
  // The app's public origin: the address its sign-in runs on, from its own configuration.
65
- const appOrigin = process.env.BETTER_AUTH_URL ?? 'http://localhost:5173'
64
+ const appOrigin = process.env.PROTOBASE_URL ?? 'http://localhost:5173'
66
65
 
67
66
  /** Tells an order's owner when its status changes, in their inbox and as push, with a link to the order. */
68
67
  export const orderStatusToOwner = subscription('orderStatusToOwner', {
@@ -107,7 +106,7 @@ On an iPhone or iPad, push reaches the app once it is added to the Home Screen,
107
106
 
108
107
  ## 6. Turn the bell off or replace a part
109
108
 
110
- - `notifications({ ui: false })` keeps sending, the history and devices, and draws no bell: your own UI reads the history and turns push on with [the browser helper](../reference/notifications.md#in-the-browser) ([without the bell](../reference/notifications.md#without-the-bell)).
109
+ - `notifications: { ui: false }` keeps sending, the history and devices, and draws no bell: your own UI reads the history and turns push on with [the browser helper](../reference/notifications.md#in-the-browser) ([without the bell](../reference/notifications.md#without-the-bell)).
111
110
  - `shell.bell` in `protobase.ui.tsx` draws your own bell in its place ([the bell's slot](../reference/notifications.md#the-bells-slot)).
112
111
  - Your own device store, history store or senders replace the built-in ones, such as a store outside the database ([your own parts](../reference/notifications.md#your-own-parts)).
113
112
  - The tables' schema, names and columns can be renamed ([table names](../reference/notifications.md#table-names)).
@@ -12,12 +12,12 @@ This guide makes the desk's tickets a [remote resource](../reference/remote-reso
12
12
 
13
13
  You need two Protobase projects, each with its own database, its own [admin store](../reference/auth.md#admin-store) and a user: the from-scratch preset (`examples/scratch` in the repository) is enough for both. Each runs on its own origin; this guide runs them side by side on one machine:
14
14
 
15
- | | `BETTER_AUTH_URL` in its `.env` | Started with |
15
+ | | `PROTOBASE_URL` in its `.env` | Started with |
16
16
  | --- | --- | --- |
17
17
  | The service desk | `http://localhost:4720` | `protobase dev --port 4720` |
18
18
  | The shop | `http://localhost:4710` | `protobase dev --port 4710` |
19
19
 
20
- `BETTER_AUTH_URL` matters here: it is the issuer of each app's tokens, and the desk will recognise the shop's tokens by it.
20
+ `PROTOBASE_URL` matters here: it is the issuer of each app's tokens, and the desk will recognise the shop's tokens by it.
21
21
 
22
22
  The shop has its orders. The desk has tickets and their notes:
23
23
 
@@ -83,31 +83,26 @@ That is the desk's admin app as its agents use it. Nothing in it knows about the
83
83
 
84
84
  The shop's admin app will call the desk's API from the browser, with the token the shop gave the signed-in person. The desk needs to accept two things: that token, and calls from the shop's origin.
85
85
 
86
- The token: list the shop as a trusted app in the desk's authenticator, and say what the shop's roles are at the desk:
86
+ The token: list the shop as a trusted app in the desk's `authenticate`, and say what the shop's roles are at the desk. The origin: the shop's admin app runs on `http://localhost:4710`, so the desk answers [CORS](../reference/api.md#cors) for it:
87
87
 
88
88
  ```ts
89
- // desk: auth/auth.ts
90
- export const authenticate = betterAuthAuthenticator({
91
- auth,
92
- tenant: 1,
93
- // The shop's admins sign in at the shop; the desk takes the shop's tokens and calls them `shop` here.
94
- apps: [{ issuer: 'http://localhost:4710', roles: { admin: 'shop' }, tenant: 1 }],
89
+ // desk: protobase.config.ts
90
+ import { defineConfig } from '@protobase/config'
91
+
92
+ export default defineConfig({
93
+ auth: { roles: ['admin'] },
94
+ authenticate: {
95
+ tenant: 1,
96
+ // The shop's admins sign in at the shop; the desk takes the shop's tokens and calls them `shop` here.
97
+ apps: [{ issuer: 'http://localhost:4710', roles: { admin: 'shop' }, tenant: 1 }],
98
+ },
99
+ // The shop's admin app, on its own origin, calls this API from the browser.
100
+ cors: ['http://localhost:4710'],
95
101
  })
96
102
  ```
97
103
 
98
104
  The desk now checks a token from the shop against the shop's keys, at `http://localhost:4710/api/auth/jwks`. Its holder is `shop` at the desk, never the desk's `admin`, so the `deskOnly` rule keeps tickets from being deleted from the shop; a shop user with any other role is refused. The [reference](../reference/remote-resources.md#signing-in-at-the-source) has the details, such as the ids those users get.
99
105
 
100
- The origin: the shop's admin app runs on `http://localhost:4710`, so the desk answers [CORS](../reference/api.md#cors) for it:
101
-
102
- ```ts
103
- // desk: protobase.config.ts
104
- import * as config from './config'
105
- import { auth, authenticate } from './auth/auth'
106
-
107
- // The shop's admin app, on its own origin, calls this API from the browser.
108
- export default { config, auth, authenticate, options: { cors: ['http://localhost:4710'] } }
109
- ```
110
-
111
106
  `protobase dev` reloads the desk.
112
107
 
113
108
  ## 3. The shop draws the tickets
@@ -116,17 +111,13 @@ The shop lists the desk as a source, with the resources it draws from it:
116
111
 
117
112
  ```ts
118
113
  // shop: protobase.config.ts
119
- import * as config from './config'
120
- import { auth, authenticate } from './auth/auth'
121
-
122
- export default {
123
- config,
124
- auth,
125
- authenticate,
126
- options: {
127
- sources: [{ url: 'http://localhost:4720/api/v1', label: 'Service desk', resources: ['tickets', 'ticket_notes'] }],
128
- },
129
- }
114
+ import { defineConfig } from '@protobase/config'
115
+
116
+ export default defineConfig({
117
+ auth: { roles: ['admin'] },
118
+ authenticate: { tenant: 1 },
119
+ remoteResources: [{ url: 'http://localhost:4720/api/v1', label: 'Service desk', resources: ['tickets', 'ticket_notes'] }],
120
+ })
130
121
  ```
131
122
 
132
123
  `url` is the desk's resources API, and `label` its name when the shop's people cannot reach it. The notes are there because a ticket's page lists them: what the shop does not draw, it does not show. A platform that runs the shop can set the same list in `PROTOBASE_SOURCES`, without touching the shop's code:
@@ -31,7 +31,7 @@ defineRoles<'orders' | 'products'>({
31
31
  - **Filter** is AIP-160 text, like a filter an access rule returns. It narrows the rows of the capability, together with `.own` or `.team` when the capability has one.
32
32
  - A limit names one resource, never `*`, and fields go with `read`, `create` or `update` only; `defineRoles` refuses anything else. At startup the server refuses a field the resource does not have, a filter that does not fit it, and a limit on a name that is not a resource.
33
33
 
34
- 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
+ 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 (the `roles` export of `config/roles.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(...)`.
35
35
 
36
36
  **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.
37
37
 
@@ -51,7 +51,7 @@ anonymous: [{ 'products.read': { fields: ['name', 'slug', 'price', 'image'], fil
51
51
  ```
52
52
 
53
53
  - **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.
54
- - **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
+ - **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 the authenticator of the app's sign-in tell the two apart; an authenticator of your own throws `MissingCredentials` (from `@protobase/server`) for a request without a credential to do the same.
55
55
  - **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.
56
56
  - **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.
57
57
  - A tenant-scoped resource (`.tenant`) cannot be in it, since an anonymous caller works in no organization; the server refuses to start.
@@ -188,7 +188,7 @@ export const apps = resource('apps')
188
188
  - **Members only.** An organization someone enters with a global role, without being a member, is not read across; the session's own organization always is. An outside app's token, such as an MCP client's, reads its own organization alone.
189
189
  - **The tenant field is a filter.** The list has it as any other field, so `organization_id = "..."`, a facet or a column picks organizations. A caller who cannot read the tenant field lists their own organization alone. To open the sidebar entry on the current organization, which the person can then clear, see [The current organization](sidebar.md#the-current-organization).
190
190
  - **Rows of another organization are read-only in the list.** Their `permissions` say `update: false` and `delete: false`. The admin app opens one by switching the session to its organization first: a record page the session's organization does not have looks the record up across the lists, for a resource with a key of one filterable field, so the page and everything on it are read in the record's own organization.
191
- - **Where the memberships come from.** `betterAuthAuthenticator` with `auth` reads them from the store, once per request that lists across organizations. An [authenticator](auth.md#tokens-and-roles) of your own gives them as the session's `memberships`, a function answering `[{ tenant, roles }]`, and must answer only organizations the person is a member of. Without it, as with `jwksUrl` instead of `auth`, a list reads the session's organization alone.
191
+ - **Where the memberships come from.** The authenticator of the app's sign-in (`auth`) reads them from the store, once per request that lists across organizations. An [authenticator](auth.md#tokens-and-roles) of your own gives them as the session's `memberships`, a function answering `[{ tenant, roles }]`, and must answer only organizations the person is a member of. Without it, as with `authenticate: { jwksUrl }` instead of `auth`, a list reads the session's organization alone.
192
192
 
193
193
  ## Restricted model and row filters
194
194
 
@@ -39,14 +39,6 @@ export const ticketsView = view<typeof tickets>('tickets')
39
39
  ])
40
40
  ```
41
41
 
42
- ```ts title="protobase.config.ts"
43
- import { defineConfig } from '@protobase/server'
44
- import * as config from './tickets'
45
-
46
- // The model comes from PROTOBASE_ASSISTANT_API_KEY; the summaries are filled by the app's workers.
47
- export default defineConfig({ config })
48
- ```
49
-
50
42
  ## Prompts
51
43
 
52
44
  A prompt names fields of the record as `{field}`, at least one. The model gets a fixed instruction to answer with the value only, and the prompt with each `{field}` replaced by the record's value as text: text as it is, numbers and booleans written out, json as JSON, an empty value as nothing. For an enum field, the prompt ends with the values the answer must be one of. Nothing else of the record or the app is sent. The answer is trimmed, and validated as any write is, so an enum value the field does not have, or text over its `.max()`, is refused.
@@ -95,7 +87,7 @@ Every check is made before the model is asked.
95
87
 
96
88
  ## The model
97
89
 
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.
90
+ 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 the config's `assistant`. They use them also when `PROTOBASE_ASSISTANT_URL` names a chat backend elsewhere, which replaces the chat, not the model, and when `assistant` is `false`, which turns off the chat only. On OpenRouter they ask for little reasoning.
99
91
 
100
92
  `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
93
 
@@ -6,9 +6,10 @@ The REST API that @protobase/server generates, with its routes, access, filters,
6
6
 
7
7
  `@protobase/server` turns resource definitions into a Hono app that follows Google's API design conventions ([AIP-131 to 136](https://google.aip.dev/131), [158](https://google.aip.dev/158), [160](https://google.aip.dev/160)). It uses Web APIs only and runs on Node and Workers; the Node adapter lives in the example.
8
8
 
9
+ `protobase dev` and `serve` build it from the project: the resources of `config/`, the functions of `functions/`, sign-in from `auth`, and the API's settings from the top-level keys of [`protobase.config.ts`](config.md), such as `statementTimeoutMs` and `scanGuard`. In code of its own, an app builds it with `createAdmin`, whose `options` take the same settings:
10
+
9
11
  ```ts
10
- import { configExports, createAdmin } from '@protobase/server'
11
- import { auth, authenticate } from './auth/auth' // Better Auth, see /reference/auth/
12
+ import { configExports, createAdmin, jwtAuthenticator } from '@protobase/server'
12
13
  import * as config from './config'
13
14
 
14
15
  const { resources, views } = configExports(config) // splits a config's index.ts exports
@@ -16,8 +17,7 @@ const admin = createAdmin({
16
17
  resources,
17
18
  views, // optional, served by /meta
18
19
  db, // Kysely<any> on Postgres
19
- authenticate, // required: no development mode; anonymous only with that role
20
- auth, // optional: mounts login at /api/auth/*
20
+ authenticate: jwtAuthenticator({ jwksUrl, issuer }), // required: no development mode; anonymous only with that role
21
21
  functions, // optional: your own endpoints at /api/functions/<name>, see /guides/api-functions/
22
22
  options: { statementTimeoutMs: 1_000, scanGuard: { mode: 'reject' } },
23
23
  })
@@ -27,7 +27,7 @@ Run the ERP example with `bun run --cwd examples/erp serve` (port 8787, Better A
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 `apiPath` (default `/api/v1`) is where the system endpoints go.
31
31
 
32
32
  Under `/api/v1`:
33
33
 
@@ -100,11 +100,11 @@ 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
+ The roles (the `roles` export of `config/roles.ts`, from `defineRoles`) make 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; `defaultAccess: 'allow' | 'deny'` in the config overrides the capability check. Without either, operations without a rule are allowed (single-admin projects).
104
104
 
105
105
  ### Record permissions
106
106
 
107
- Get responses carry `permissions: { update, delete, fields }`, where `fields` maps each readable field to `edit` or `read` for this record (hidden fields are not listed). List items carry `permissions: { update, delete }` too, decided in the database in one extra query per page; turn it off for a resource with `options.rowPermissions: { except: ['resource'] }` (or `false` for all). They only inform the UI: every write is checked again. A resource cannot have a field named `permissions` or `etag`.
107
+ Get responses carry `permissions: { update, delete, fields }`, where `fields` maps each readable field to `edit` or `read` for this record (hidden fields are not listed). List items carry `permissions: { update, delete }` too, decided in the database in one extra query per page; turn it off for a resource with `rowPermissions: { except: ['resource'] }` in the config (or `false` for all). They only inform the UI: every write is checked again. A resource cannot have a field named `permissions` or `etag`.
108
108
 
109
109
  ### `/meta` and OpenAPI per caller
110
110
 
@@ -116,7 +116,7 @@ A field declared [`.sensitive()`](data-config.md#sensitive-fields) is in `/meta`
116
116
 
117
117
  A field with [`.strongSignIn()`](data-config.md#recent-strong-sign-in) is a `403` `strong-sign-in-required`, whose problem carries `minutes`, until the caller's sign-in proved a passkey or a second step that recently. The same request reveals a resource's [computed reveals](data-config.md#computed-reveals) by name, whose value the server makes when asked.
118
118
 
119
- 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:
119
+ Before answering, the server publishes an audit event to the app's audit queue, and when publishing fails the reveal fails (`500`), so no value leaves without its event. The event never holds the value:
120
120
 
121
121
  ```ts
122
122
  type AuditEvent = {
@@ -135,7 +135,7 @@ With [organizations](auth.md#organizations), someone with a global role switchin
135
135
 
136
136
  ### Audit events
137
137
 
138
- `options.audit` is an `AuditQueue`, `{ publish(event): Promise<void> }`, set in `protobase.config.ts` (`options: { roles, audit }`). The default, `consoleAuditQueue()`, prints each event to the console as one `[audit] {...}` JSON line and keeps nothing; a queue that stores or forwards events replaces it there.
138
+ The queue is an `AuditQueue`, `{ publish(event): Promise<void> }`, the default export of the project's `audit/queue.ts`. The default, `consoleAuditQueue()`, prints each event to the console as one `[audit] {...}` JSON line and keeps nothing; a queue that stores or forwards events replaces it there.
139
139
 
140
140
  ## Filters
141
141
 
@@ -181,13 +181,13 @@ The rules behind these steps are described under [Access](#access).
181
181
 
182
182
  ## Authentication
183
183
 
184
- Real login is [Better Auth](auth.md). Lower level:
184
+ Real login is the app's [sign-in](auth.md). Lower level:
185
185
 
186
- `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.
186
+ `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 the authenticator of the app's sign-in on top of it, which `authenticate` in the config sets ([Tokens and roles](auth.md#tokens-and-roles)); an authenticator of the project's own is the default export of `auth/authenticate.ts`. 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.
187
187
 
188
188
  ## CORS
189
189
 
190
- 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.
190
+ The API sends no CORS headers until it has something to allow: other websites in `cors` in the config (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.
191
191
 
192
192
  - 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.
193
193
  - 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.
@@ -222,15 +222,15 @@ Every error is `application/problem+json` (RFC 9457) with `type` (`urn:protobase
222
222
 
223
223
  ### Error reporting
224
224
 
225
- An app can send its errors to an error tracker of its own: [Sentry](https://sentry.io) or one that speaks its protocol, such as [Bugsink](https://www.bugsink.com) or [GlitchTip](https://glitchtip.com). It is off until a DSN, the address the tracker gives a project, is set in `options.errorReporting` or `PROTOBASE_SENTRY_DSN`; without one nothing is loaded or sent.
225
+ An app can send its errors to an error tracker of its own: [Sentry](https://sentry.io) or one that speaks its protocol, such as [Bugsink](https://www.bugsink.com) or [GlitchTip](https://glitchtip.com). It is off until a DSN, the address the tracker gives a project, is set in `errorReporting` or `PROTOBASE_SENTRY_DSN`; without one nothing is loaded or sent.
226
226
 
227
227
  ```ts
228
228
  export default defineConfig({
229
- options: { errorReporting: { dsn: 'https://<key>@errors.example.com/42', environment: 'staging' } },
229
+ errorReporting: { dsn: 'https://<key>@errors.example.com/42', environment: 'staging' },
230
230
  })
231
231
  ```
232
232
 
233
- - **Server:** every `500` with the request it failed, and every `504 statement-timeout` and `503 connections-busy` with the request it names, under `dev`, `serve` and the runtime, besides `options.onUnhandledError` or the console. Under `serve`, the runtime and `worker`, an uncaught exception or unhandled rejection too, which then still ends the process with exit code 1.
233
+ - **Server:** every `500` with the request it failed, and every `504 statement-timeout` and `503 connections-busy` with the request it names, under `dev`, `serve` and the runtime, besides the default export of `hooks/error.ts` or the console. Under `serve`, the runtime and `worker`, an uncaught exception or unhandled rejection too, which then still ends the process with exit code 1.
234
234
  - **Admin app:** uncaught errors and the errors of components that fail to draw. `/api/meta` names the DSN to every signed-in caller, as a browser app always shows its own.
235
235
  - Errors only, with no performance tracing. Before an event leaves, the values of authorization headers, cookies, passwords, tokens and other credentials, in fields and in URLs, are replaced by `[Filtered]`.
236
236
  - `environment` names the deployment in the tracker; without it the tracker's default, `production`. `errorReporting: false` turns reporting off whatever the environment says. A DSN that is no `http(s)` URL with a key and a project id stops startup.
@@ -8,26 +8,25 @@ An app looks like its own everywhere from three things in its project: its name,
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, the [mobile app](../guides/mobile-app.md)'s name on the phone, passkey and authenticator prompts, auth mail and its sender's name |
11
+ | Name | `name` in `protobase.config.ts` ([config](config.md)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the end of every tab title, the installed app's name, the [mobile app](../guides/mobile-app.md)'s name on the phone, 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; the [mobile app](../guides/mobile-app.md) shows Protobase's icon instead |
13
13
  | Raster icons | optional PNGs beside the SVG, below | the iPhone home screen and Android launchers, which take no SVG |
14
- | Colours | `app` in `protobase.config.ts` | the installed app's title bar and its start screen |
14
+ | Colours | `themeColor` and `backgroundColor` in `protobase.config.ts` | the installed app's title bar and its start screen |
15
15
 
16
16
  ```ts
17
17
  // protobase.config.ts
18
+ import { defineConfig } from '@protobase/config'
19
+
18
20
  export default defineConfig({
19
- config,
20
- auth,
21
- authenticate,
22
- app: { themeColor: '#0d9488', backgroundColor: '#ffffff' },
21
+ name: 'Acme Admin',
22
+ themeColor: '#0d9488',
23
+ backgroundColor: '#ffffff',
23
24
  })
24
25
  ```
25
26
 
26
- `createAuth` takes the name because the sign-in it builds needs it, so keep the name in a constant both `auth/auth.ts` and anything else that shows it import, if you want it written once.
27
-
28
27
  ## The name
29
28
 
30
- `appName` names the app; `PROTOBASE_APP_NAME`, when a deployment sets it, overrides it, so a deployment can rename an app without a new build. Without either the app is called `Protobase`.
29
+ `name` names the app; `PROTOBASE_APP_NAME`, when a deployment sets it, overrides it, so a deployment can rename an app without a new build. Without either the app is called `Protobase`.
31
30
 
32
31
  ## The icons
33
32
 
@@ -46,7 +45,7 @@ Each is optional, and none is made from the SVG: without the touch icon an iPhon
46
45
 
47
46
  ## The colours
48
47
 
49
- `app` takes any CSS colour for each, and the web manifest carries the ones set:
48
+ Each takes any CSS colour, and the web manifest carries the ones set:
50
49
 
51
50
  - `themeColor`: the installed app's title bar and the browser's toolbar around it (`theme_color`).
52
51
  - `backgroundColor`: the screen the installed app shows while it starts (`background_color`).
@@ -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 (`auth: { roles: ['admin', 'ai', ...] }` in `protobase.config.ts`, 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 `assistant` of `protobase.config.ts` (`assistant: { model: '...' }`), 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
  | --- | --- | --- |
@@ -62,18 +62,18 @@ It lives at `/api/assistant` on the app's own origin and answers with the user's
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.
64
64
 
65
- Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role only when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `options.assistant.apiKey`, so run it with the key set even when only production has the real one. The server does not start while the role or its function is missing, while the role can read an auth table, or while it may call a `SECURITY DEFINER` function, other than a trigger function, whose owner can read one: the statement would read the auth store through it, so revoke `execute` on such a function from `PUBLIC`, or keep it in a schema without a resource. A resource added since the last migration is refused by Postgres until the next one grants its table.
65
+ Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role only when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `assistant.apiKey` of the config, so run it with the key set even when only production has the real one. The server does not start while the role or its function is missing, while the role can read an auth table, or while it may call a `SECURITY DEFINER` function, other than a trigger function, whose owner can read one: the statement would read the auth store through it, so revoke `execute` on such a function from `PUBLIC`, or keep it in a schema without a resource. A resource added since the last migration is refused by Postgres until the next one grants its table.
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
+ `assistant/tools.ts` adds tools of the app's own, which the built-in backend offers after its two: its default export is an array of tools, found by that path when the app starts. 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 file does nothing there, nor with `assistant: false`. 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)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) 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 }`. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
72
72
 
73
73
  A tool with a [widget](#widget-parts) creates or finds what it is about, shows a widget with its id, and returns the id and the state at that moment:
74
74
 
75
75
  ```ts
76
- // config/assistant/propose-task.ts
76
+ // assistant/propose-task.ts
77
77
  import { defineTool, widget } from '@protobase/server'
78
78
 
79
79
  export const proposeTask = defineTool({
@@ -87,7 +87,7 @@ export const proposeTask = defineTool({
87
87
  },
88
88
  })
89
89
 
90
- // protobase.config.ts: export default { ..., options: { assistant: { tools: [proposeTask] } } }
90
+ // assistant/tools.ts: import { proposeTask } from './propose-task'; export default [proposeTask]
91
91
  ```
92
92
 
93
93
  ```tsx