@protobase/cli 0.49.2 → 0.50.1

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 (72) hide show
  1. package/bin/protobase.mjs +3 -2
  2. package/dist/build/config-bundle.js +1 -1
  3. package/dist/build/deploy-bundle.js +3 -4
  4. package/dist/build/plugin-build.js +16 -8
  5. package/dist/build/plugin-fields.js +5 -2
  6. package/dist/build/ui-check.js +5 -0
  7. package/dist/build/view-check.js +1 -1
  8. package/dist/cli/package.js +1 -1
  9. package/dist/config/project-files.js +4 -1
  10. package/dist/config/source-config.js +1 -1
  11. package/dist/dev/api-process.js +1 -1
  12. package/dist/dev/app-server.js +43 -35
  13. package/dist/dev/create-db.js +2 -2
  14. package/dist/dev/project.js +3 -2
  15. package/dist/dev/server-package.js +9 -21
  16. package/dist/doctor/run.js +1 -1
  17. package/dist/hand-over.d.ts +15 -0
  18. package/dist/hand-over.js +32 -0
  19. package/dist/main.js +22 -5
  20. package/dist/project/bundled-imports.js +41 -0
  21. package/dist/project/import-project-file.js +28 -8
  22. package/dist/project/load-data-config.js +4 -3
  23. package/dist/project/project-types.js +66 -0
  24. package/dist/run/preload.d.ts +1 -0
  25. package/dist/run/preload.js +20 -0
  26. package/dist/run/run-script.js +36 -0
  27. package/dist/supabase/dump-phase.js +9 -4
  28. package/dist/supabase/load-phase.js +5 -4
  29. package/dist/supabase/realtime-policies.js +60 -0
  30. package/dist/version/project-packages.js +39 -0
  31. package/dist/version/project-version.js +33 -12
  32. package/package.json +9 -8
  33. package/skills/protobase/SKILL.md +1 -1
  34. package/skills/protobase/references/features/build-and-run.md +3 -0
  35. package/skills/protobase/references/features/compatibility.md +1 -1
  36. package/skills/protobase/references/features/releases.md +2 -1
  37. package/skills/protobase/references/getting-started.md +18 -5
  38. package/skills/protobase/references/guides/api-functions.md +1 -1
  39. package/skills/protobase/references/guides/billing-page.md +4 -4
  40. package/skills/protobase/references/guides/create-page.md +2 -2
  41. package/skills/protobase/references/guides/deploy.md +24 -8
  42. package/skills/protobase/references/guides/field-type.md +1 -1
  43. package/skills/protobase/references/guides/first-plugin.md +1 -1
  44. package/skills/protobase/references/guides/plugin-build.md +1 -1
  45. package/skills/protobase/references/guides/remote-resources.md +1 -1
  46. package/skills/protobase/references/guides/table-to-admin.md +8 -8
  47. package/skills/protobase/references/reference/ai.md +1 -1
  48. package/skills/protobase/references/reference/api.md +4 -4
  49. package/skills/protobase/references/reference/architecture.md +11 -6
  50. package/skills/protobase/references/reference/assistant.md +1 -1
  51. package/skills/protobase/references/reference/auth.md +17 -4
  52. package/skills/protobase/references/reference/blocks.md +1 -1
  53. package/skills/protobase/references/reference/bottom-bar.md +2 -2
  54. package/skills/protobase/references/reference/cli.md +51 -22
  55. package/skills/protobase/references/reference/client.md +3 -1
  56. package/skills/protobase/references/reference/config/api.md +2 -2
  57. package/skills/protobase/references/reference/config/app.md +2 -2
  58. package/skills/protobase/references/reference/config/sign-in.md +2 -3
  59. package/skills/protobase/references/reference/config.md +11 -9
  60. package/skills/protobase/references/reference/custom-components.md +3 -2
  61. package/skills/protobase/references/reference/email.md +4 -4
  62. package/skills/protobase/references/reference/events.md +1 -1
  63. package/skills/protobase/references/reference/jobs.md +6 -5
  64. package/skills/protobase/references/reference/layouts.md +2 -2
  65. package/skills/protobase/references/reference/mcp.md +9 -8
  66. package/skills/protobase/references/reference/notifications.md +10 -8
  67. package/skills/protobase/references/reference/plugins.md +3 -3
  68. package/skills/protobase/references/reference/supabase-realtime.md +36 -2
  69. package/skills/protobase/references/reference/ui-config.md +1 -1
  70. package/skills/protobase/references/reference/user-menu.md +3 -3
  71. package/skills/protobase/references/reference/versioning.md +21 -4
  72. package/skills/protobase/references/reference/webhooks.md +5 -5
@@ -14,7 +14,7 @@ An app can serve an MCP endpoint: a person adds its address to an AI client that
14
14
  export default defineConfig({ auth: { mcp: true } })
15
15
  ```
16
16
 
17
- Every auth store has the OAuth tables, so turning it on needs no migration. The endpoint is `https://<app>/api/mcp`, or the path `mcp.path` names. How clients register, how people sign in and allow them, and how they disconnect them is in [OAuth for MCP clients](auth.md#oauth-for-mcp-clients).
17
+ Every auth store has the OAuth tables, so turning it on needs no migration. The endpoint is `https://<app>/api/mcp`, or the path `auth.mcp.path` names. How clients register, how people sign in and allow them, and how they disconnect them is in [OAuth for MCP clients](auth.md#oauth-for-mcp-clients).
18
18
 
19
19
  ## Connecting a client
20
20
 
@@ -55,7 +55,7 @@ It runs one `SELECT` in a read-only transaction, as the app's database role, **o
55
55
 
56
56
  ### Writes
57
57
 
58
- `mcpEndpoint.writes` also offers three tools that change records, to everyone signed in:
58
+ `mcpEndpoint.writes` also offers four tools that change records, to everyone signed in:
59
59
 
60
60
  ```ts
61
61
  export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: true } })
@@ -117,7 +117,7 @@ A batch is checked before the person is asked: an operation other than a create,
117
117
 
118
118
  ## Browsers and hosts
119
119
 
120
- A client in a browser may call the endpoint from any origin: it sends its token, never cookies. A request addressed to another host than the app's `baseURL` is refused, against DNS rebinding.
120
+ A client in a browser may call the endpoint from any origin: it sends its token, never cookies. A request addressed to another host than that of the app's [`url`](config/app.md#url) is refused, against DNS rebinding.
121
121
 
122
122
  The endpoint serves each request on its own, without an MCP session: a `GET` or `DELETE` answers 405.
123
123
 
@@ -128,13 +128,14 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
128
128
  - `mcpHandler({ authenticate, resource, scope, server })`: the endpoint as a fetch handler. It checks the host, admits a valid token (`mcpGate`) and serves the request with the server that `server(session)` builds for its caller.
129
129
  - `mcpServer({ info, tools, context, report, rolesWithoutApproval, approvals })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`: each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`. `approvals` is `mcpApprovals()`, built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire.
130
130
  - `mcpTools({ db, sql, writes })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }`.
131
+ - `readRecordTools()`, or `listResourcesTool()`, `listRecordsTool()` and `getRecordTool()`: the read tools alone; `readOnlyQueryTool(db)` is `run_read_only_query`, and `readWriteQueryTool(db)` proposes one write statement that the user approves before it runs.
131
132
  - `writeRecordTools({ resources })`, or `createRecordTool(...)`, `updateRecordTool(...)` and `deleteRecordTool(...)`: the single write tools alone, on the listed resources or, without `resources`, on any; `batchWriteTool({ resources })` is `batch_write` alone.
132
133
  - `mcpGate({ authenticate, resource, scope })`: the token check alone, answering 401 or 403 with a challenge that names the resource's metadata.
133
134
  - `mcpToolContext(...)`, `mcpRoutes(app, { path, handler })` and `sessionOf(authInfo)`: the tools' context as the app builds it, the routes with open CORS, and the session a request was admitted with.
134
135
 
135
- To serve your own endpoint at `mcp.path` instead, set `mcpEndpoint: false` (`createAdmin`'s `options.mcp`) and mount yours in front of `createAdmin`'s app. The OAuth provider and its discovery stay, `createAdmin` answers 404 at the path and under it, and its `authenticate` needs no `forAudience`.
136
+ A host that builds its own server around `createAdmin`, rather than running the project with `protobase dev` or `protobase serve`, can serve its own endpoint at `auth.mcp.path` instead: `mcpEndpoint: false` (`createAdmin`'s `options.mcp`) turns Protobase's off, and the host mounts its own in front of `createAdmin`'s app. The OAuth provider and its discovery stay, and `createAdmin` answers 404 at the path and under it. `protobase dev` and `protobase serve` have no place to mount another endpoint, so in a project served by them `mcpEndpoint: false` only turns the endpoint off.
136
137
 
137
- A tool of your own goes on the server `server` returns, with the context its tools get:
138
+ A tool of your own goes on the server `server` returns, with the context its tools get. `authenticate` is the host's own `Authenticator`: it verifies the client's access token for the endpoint's address, its audience, and returns a session with the `client` the token was issued to:
138
139
 
139
140
  ```ts
140
141
  import { defineTool, mcpApprovals, mcpHandler, mcpServer, type Session, type ToolContext } from '@protobase/server'
@@ -157,9 +158,9 @@ const context = (session: Session): Omit<ToolContext, 'approve'> => ({
157
158
  const approvals = mcpApprovals()
158
159
 
159
160
  const handler = mcpHandler({
160
- authenticate: authenticate.forAudience(auth.mcp.resource),
161
- resource: auth.mcp.resource,
162
- scope: auth.mcp.scope,
161
+ authenticate: verifyMcpToken,
162
+ resource: 'https://admin.example.com/api/mcp',
163
+ scope: 'mcp',
163
164
  server: (session) => mcpServer({ info: { name: 'My app', version: '1.0.0' }, tools: [ping], context: context(session), report: console.error, approvals }),
164
165
  })
165
166
  ```
@@ -55,12 +55,12 @@ A field that does not belong to the kind, a missing one, an unknown one such as
55
55
  Who may call them:
56
56
 
57
57
  - Only someone signed in as themselves, with the token of their own sign-in. Visitors are refused with a `401`, and staff signed in as the user, outside apps acting for the user (such as an MCP client) and tokens minted with `issueToken` with a `403`.
58
- - An app with its own `authenticate` marks a user's own sign-in on the session it returns, `signIn: { staff: false }`; without that mark, its sessions are refused.
58
+ - An app with its own authenticator ([`auth/authenticate.ts`](config/sign-in.md#authenticate)) marks a user's own sign-in on the session it returns, `signIn: { staff: false }`; without that mark, its sessions are refused.
59
59
  - With Protobase's auth, every token the endpoints take names its sign-in session; one that names none is refused with a `403`.
60
60
 
61
61
  A device is one token, or one endpoint for a browser. An Android or iOS token someone else had moves to the caller, as a new device with a new id that keeps nothing of the previous user's, so a shared phone notifies whoever signed in on it last. A browser's endpoint never moves: registering one another user holds is a `409` of type `device-held` that stores nothing, and the browser subscribes again for a new endpoint, as [the browser helper](#in-the-browser) does. A user keeps up to 20 devices: registering one more removes their least recently seen. Deleting a user removes their devices.
62
62
 
63
- With Protobase's auth, a device belongs to the sign-in session it was registered in. Once that session ends, the device gets no more push and is removed at the next send: when the user signs out, someone signs in on the same browser, the user signs out everywhere, a password change signs out their other devices, an admin ends their sessions or bans them, or the session expires. Registering the device again ties it to the session of that request, which the browser helper does on its own for the same user. With an app's own `authenticate`, a device stays its user's until it is removed with `DELETE`.
63
+ With Protobase's auth, a device belongs to the sign-in session it was registered in. Once that session ends, the device gets no more push and is removed at the next send: when the user signs out, someone signs in on the same browser, the user signs out everywhere, a password change signs out their other devices, an admin ends their sessions or bans them, or the session expires. Registering the device again ties it to the session of that request, which the browser helper does on its own for the same user. With an app's own authenticator, a device stays its user's until it is removed with `DELETE`.
64
64
 
65
65
  The path comes from `devicesPath('/api', id)`, and the name of its id parameter from `deviceIdParam`, both exported by `@protobase/server`.
66
66
 
@@ -110,7 +110,7 @@ The text you send shows on lock screens, where anyone holding the device can rea
110
110
 
111
111
  A send checks no permission. A device send reaches the devices whatever user holds them. So check ids taken from a request against the caller first, such as a device id against the caller's own devices.
112
112
 
113
- A user send reaches the user's devices as they are when the job runs. A device that moved to someone else, or was removed, gets nothing. With Protobase's auth, a device whose sign-in session has [ended](#devices) is removed instead; a send whose devices' sessions cannot be read pushes to none of them and is retried. With an app's own `authenticate`, a device keeps receiving its user's notifications until it is removed. When a push service reports a device gone, the device is removed. A device whose push service asks to try again later is tried once more, on the job's next try, and then given up on without being removed. <gap>A push service's own wait before a retry cannot set when the device is tried again because retries follow the job's backoff and timing them per device is not implemented.</gap> A sender that fails is retried with its devices, up to 5 tries of the job. Devices of a kind without a sender are skipped. Without any sender, a send for the inbox is kept in the history and a send that is not does nothing.
113
+ A user send reaches the user's devices as they are when the job runs. A device that moved to someone else, or was removed, gets nothing. With Protobase's auth, a device whose sign-in session has [ended](#devices) is removed instead; a send whose devices' sessions cannot be read pushes to none of them and is retried. With an app's own authenticator, a device keeps receiving its user's notifications until it is removed. When a push service reports a device gone, the device is removed. A device whose push service asks to try again later is tried once more, on the job's next try, and then given up on without being removed. <gap>A push service's own wait before a retry cannot set when the device is tried again because retries follow the job's backoff and timing them per device is not implemented.</gap> A sender that fails is retried with its devices, up to 5 tries of the job. Devices of a kind without a sender are skipped. Without any sender, a send for the inbox is kept in the history and a send that is not does nothing.
114
114
 
115
115
  ## History
116
116
 
@@ -133,7 +133,7 @@ The list gives 20 at a time, or as many as `?limit=` says, up to 50. A full page
133
133
 
134
134
  `title` and `body` are plain text: show them as text, never as HTML. `url` is a path on the app, such as `/tasks/42`, or an absolute URL on one of the app's own origins; anything else, another site, `javascript:` or `data:`, is answered as `null`. A notification's `url` and `data` are kept until its user is removed, so leave one-time links and secrets out of inbox notifications.
135
135
 
136
- The same people may call them as may [register devices](#devices): only someone signed in as themselves. With Protobase's auth, deleting a user removes their history; an app that deletes users otherwise calls `historyStore(db, options).removeAllForUser(userId)` as it deletes one, with the config's `notifications`.
136
+ The same people may call them as may [register devices](#devices): only someone signed in as themselves. With Protobase's auth, deleting a user removes their history; an app that deletes users otherwise calls `historyStore(db, notifications).removeAllForUser(userId)` as it deletes one, with the config's `notifications` (the history table's names), or the `removeAllForUser` of its own `notifications/history-store.ts`.
137
137
 
138
138
  The paths come from `historyPath('/api')`, `historyPath('/api', 'unread')`, `historyPath('/api', 'read')` and `historyPath('/api', { read: id })`, and the name of the id parameter from `historyIdParam`, all exported by `@protobase/server`.
139
139
 
@@ -148,7 +148,7 @@ With notifications on, every signed-in user sees a bell in the top bar with how
148
148
  The panel also offers to turn push on for this device, where the device can receive it: a browser with Web Push, when the app has [its keys](#web-push). The browser asks for permission only once the user clicks "Turn on", never when a page loads. Once push is on, the panel says so with a way to turn it off. When the browser blocks notifications, the panel says so and how to allow them again, and offers to turn push on once they are allowed.
149
149
 
150
150
  - The count is read again every half minute while the page shows, on a return to it and when the panel opens, and shows `99+` above 99.
151
- - Visitors and staff signed in as a user see no bell, since the history is the user's own. Neither does a user of an app with its own `authenticate` that does not mark their [own sign-in](#devices).
151
+ - Visitors and staff signed in as a user see no bell, since the history is the user's own. Neither does a user of an app with its own authenticator that does not mark their [own sign-in](#devices).
152
152
  - The panel's text comes in the app's [language](languages.md).
153
153
 
154
154
  ## Without the bell
@@ -235,7 +235,9 @@ export default store
235
235
 
236
236
  Every method takes and returns plain data: the user id as text, and devices as `{ id, userId, kind, token, p256dh, auth, environment, appId, userAgent, sessionId, createdAt, lastSeenAt }`, with `token` the endpoint for a browser and `sessionId` the sign-in session it was registered in. A method given an empty user id, id or token throws. `listByIds` and `removeGone` act on any user's devices, for the code that sends; the endpoints never call them. A store missing a method stops startup, naming it.
237
237
 
238
- When Protobase's auth deletes a user, by an admin or with `protobase users delete`, it calls the store's `removeAllForUser` before anything is deleted, so a store that throws stops the deletion, and once more afterwards. An app that deletes users otherwise calls `deviceStore(db, options).removeAllForUser(userId)` as it deletes one, with the config's `notifications`.
238
+ When Protobase's auth deletes a user, by an admin or with `protobase users delete`, it calls the store's `removeAllForUser` before anything is deleted, so a store that throws stops the deletion, and once more afterwards. An app that deletes users otherwise calls `deviceStore(db, notifications).removeAllForUser(userId)` as it deletes one, with the config's `notifications` (the devices table's names), or the `removeAllForUser` of its own `notifications/store.ts`.
239
+
240
+ The built-in stores are `postgresDeviceStore(db, notifications)` and `postgresHistoryStore(db, notifications)` of `@protobase/server`, for a store of your own that wraps one of them.
239
241
 
240
242
  The history store is an interface with a Postgres default too, the [history table](#table-names), and your own is the default export of `notifications/history-store.ts`:
241
243
 
@@ -255,11 +257,11 @@ const historyStore: HistoryStore = {
255
257
  export default historyStore
256
258
  ```
257
259
 
258
- A notification is `{ id, userId, title, body, url, data, createdAt, readAt }`, and `before` is the `{ createdAt, id }` of the last one of the page before. Each method touches only the given user's notifications, and throws on an empty user id or id. An id is letters, digits, `-` and `_`, at most 64 characters, as it goes into a path. `record` keeps only what `historyLimits` allows: a title of up to 256 characters, a body and a url of up to 2048, and `data` of up to 4096 bytes of JSON. The endpoints answer with an error, showing nothing of it, when a store gives back another user's notification. A store missing a method stops startup, naming it. Deleting a user calls its `removeAllForUser` as it does the device store's; an app that deletes users otherwise calls `historyStore(db, options).removeAllForUser(userId)`.
260
+ A notification is `{ id, userId, title, body, url, data, createdAt, readAt }`, and `before` is the `{ createdAt, id }` of the last one of the page before. Each method touches only the given user's notifications, and throws on an empty user id or id. An id is letters, digits, `-` and `_`, at most 64 characters, as it goes into a path. `record` keeps only what `historyLimits` allows: a title of up to 256 characters, a body and a url of up to 2048, and `data` of up to 4096 bytes of JSON. The endpoints answer with an error, showing nothing of it, when a store gives back another user's notification. A store missing a method stops startup, naming it. Deleting a user calls its `removeAllForUser` as it does the device store's; an app that deletes users otherwise calls its `removeAllForUser` itself.
259
261
 
260
262
  ### Senders
261
263
 
262
- A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push is built in; your own senders, such as from a package, are the default export of `notifications/senders.ts`, an array, and they replace the built-in ones, at most one for each kind:
264
+ A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push is built in; your own senders, such as from a package, are the default export of `notifications/senders.ts`, an array, and they replace the built-in ones, at most one for each kind. To keep Web Push beside them, list it too: `webPushSender(readVapidSettings(process.env)!)` from `@protobase/server` is the built-in sender, and `readVapidSettings` reads the [VAPID variables](#web-push), `undefined` when none is set:
263
265
 
264
266
  ```ts
265
267
  // notifications/senders.ts
@@ -40,7 +40,7 @@ Each place a plugin can fill is an extension point. The config names it, or a pl
40
40
  | [Field type](#field-types) | `r.field.widget('name', props)` in a view's `fields` | `fields: { name: { of, display, editor?, cell? } }` | `{ field, value, props }`, and `onChange`, `invalid` for the editor | The field as it shows without one |
41
41
  | Widget part (the [assistant](assistant.md#widget-parts)) | A widget part's name | A PascalCase export | The part's props | The part's fallback card |
42
42
  | [Action handler](custom-components.md#action-handlers) | `a.action('name')` in a view | `actions: { name }` | `ActionContext` | The button is disabled |
43
- | [Shell slot](custom-components.md#shell-slots) | Nothing: drawn on every page | `shell: { actions, rightPanel, logo }` | Nothing; `logo` gets `compact` and `workspace` | Not drawn; Protobase's logo for `logo` |
43
+ | [Shell slot](custom-components.md#shell-slots) | Nothing: drawn on every page | `shell: { actions, rightPanel, logo, bell }` | Nothing; `logo` gets `compact`, `workspace`, `appName` and `appIcon` | Not drawn; Protobase's logo for `logo`, its notification bell for `bell` |
44
44
  | [Before sign-in](#before-sign-in) | `beforeSignIn: true` where the plugin is listed | `beforeSignIn` | `children`, `params`, `removeParams`, `signedIn` | The pages as they are without it |
45
45
 
46
46
  Components and cards share one namespace of names, which `component('Name')` joins to the export; field types and action handlers each have their own. Props that name fields go through the same walker as everything else in `/api/meta`, so a user who may not read a field never gets it in a component's props; a field type's `props` are plain data, and a field the user may not read is left out of the view, field type and all.
@@ -150,7 +150,7 @@ Each part gets:
150
150
  ## Building
151
151
 
152
152
  ```sh
153
- protobase build-plugin [dir] [--out <dir>] [--name <name>]
153
+ protobase build-plugin [dir] [--out <dir>] [--name <name>] [--source-maps]
154
154
  ```
155
155
 
156
156
  Builds the plugin in `dir` (default: the current folder) into `--out` (default: `dist` in it):
@@ -277,7 +277,7 @@ A host that keeps the shells of its releases can serve the shell of a newer one
277
277
 
278
278
  A plugin is built for one plugin API and a range of Protobase versions, both written by `build-plugin` into `plugin.json`:
279
279
 
280
- - `api` is the plugin API of the `@protobase/ui` installed for the plugin.
280
+ - `api` is the plugin API of the `@protobase/ui` installed for the plugin, else the CLI's own (always the CLI's for the UI of a bundled project).
281
281
  - `protobase` is `>=` that `@protobase/ui`'s version: the plugin may use anything that version has. To run on older releases too, name the range in the plugin's `package.json`:
282
282
 
283
283
  ```json
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Supabase Realtime
4
4
 
5
- The Realtime-compatible /api/sb/realtime/v1 that supabase-js's channel() joins, for postgres_changes checked under the subscriber's RLS policies, broadcasts and presence.
5
+ The Realtime-compatible /api/sb/realtime/v1 that supabase-js's channel() joins, for postgres_changes checked under the subscriber's RLS policies, broadcasts and presence, on public and private channels.
6
6
 
7
7
  An app with API keys also serves `/api/sb/realtime/v1/websocket`, the socket that supabase-js's `channel()` joins. An app moved from Supabase keeps its `postgres_changes` listeners, broadcasts and presence: point the client at the app's `/api/sb` and give it the publishable key.
8
8
 
@@ -24,7 +24,7 @@ The server serves the socket when the host gives `createAdmin` its WebSocket upg
24
24
 
25
25
  ## Which tables
26
26
 
27
- A channel may listen to the tables of the resources with [`.live()`](live.md), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. <gap>A channel cannot `select` columns because that is not supported yet.</gap> <gap>A channel cannot be private because private channels are not supported yet.</gap>
27
+ A channel may listen to the tables of the resources with [`.live()`](live.md), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. <gap>A channel cannot `select` columns because that is not supported yet.</gap>
28
28
 
29
29
  ## Broadcast and presence
30
30
 
@@ -48,6 +48,40 @@ Limits, near Supabase's Free plan, apply per socket and per topic. A socket send
48
48
 
49
49
  Broadcasts and presence go between the channels of one serving process, which is how a cloud app runs; <gap>Several processes behind one address do not reach each other's channels, because broadcasts and presence are not shared between processes.</gap> <gap>Sending without a joined channel, which supabase-js does over `POST /api/sb/realtime/v1/api/broadcast`, is not supported.</gap>
50
50
 
51
+ ## Private channels
52
+
53
+ A channel joined with `private: true` is authorized as Supabase Realtime Authorization does it: by the row security policies on `realtime.messages`, which say who may receive and who may send each extension's messages, `broadcast` or `presence`, and `realtime.topic()`, the channel's topic without its `realtime:` prefix:
54
+
55
+ ```sql
56
+ create policy "members hear their rooms" on realtime.messages for select to authenticated
57
+ using (realtime.messages.extension in ('broadcast', 'presence') and exists (
58
+ select 1 from public.room_members m where m.user_id = (select auth.uid()) and 'room:' || m.room_id = (select realtime.topic())));
59
+
60
+ create policy "members send to their rooms" on realtime.messages for insert to authenticated
61
+ with check (exists (
62
+ select 1 from public.room_members m where m.user_id = (select auth.uid()) and 'room:' || m.room_id = (select realtime.topic())));
63
+ ```
64
+
65
+ ```ts
66
+ const room = supabase.channel('room:42', { config: { private: true } })
67
+ ```
68
+
69
+ When a channel joins, the server checks, under the subscriber's role and claims, whether it may select a `broadcast` message of the topic, and a `presence` one when the channel listens to presence. A channel that may receive neither is refused with Supabase's `Unauthorized: You do not have permissions to read from this Channel topic: room:42`; one that may receive only one of them does not hear the other. The first broadcast and the first presence track a channel sends check whether it may insert such a message; one it may not is answered with an error and goes to no one. What a check finds holds until the channel's next token, which checks again, and a new token that takes away what the old one allowed ends the channel, with `You no longer have permission to read from this Channel topic: room:42`. A policy that fails, such as one calling a function that raises, allows nothing. <gap>A policy cannot read the socket's headers in `request.headers` because passing them to the checks is not implemented.</gap>
70
+
71
+ [`import supabase`](cli.md#import-supabase) carries a project's policies on `realtime.messages` over. A project that writes its own makes the table first, with Supabase's columns, in a migration:
72
+
73
+ ```sql
74
+ create schema realtime;
75
+ create table realtime.messages (topic text not null, extension text not null, payload jsonb, event text, private boolean,
76
+ updated_at timestamp not null default now(), inserted_at timestamp not null default now(), id uuid not null default gen_random_uuid() primary key);
77
+ create function realtime.topic() returns text language sql stable as $$ select nullif(current_setting('realtime.topic', true), '')::text $$;
78
+ alter table realtime.messages enable row level security;
79
+ grant usage on schema realtime to anon, authenticated;
80
+ grant select, insert on realtime.messages to anon, authenticated;
81
+ ```
82
+
83
+ Each check inserts its messages in a transaction it rolls back, so the table stays empty: the app's database role must own it, or bypass row security, to insert the message a join checks. Without `realtime.messages`, every private channel is refused.
84
+
51
85
  ## What a subscriber receives
52
86
 
53
87
  Each change is checked for each subscriber before it is sent. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them. In one transaction per batch of changes, the server sets the subscriber's role with `SET LOCAL ROLE` and its claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()` and `auth.jwt()` work, reads the changed rows by key, and sends an insert or update only when the table's RLS policies let the subscriber select the row, with the columns its role may select. Subscribers with the same role and claims, such as one user's tabs, are checked once. The check holds one pooled connection per serving process, and only while it runs, never one per socket.
@@ -59,7 +59,7 @@ export const repairsView = view<typeof repairs>('repairs')
59
59
  | `.signIn({ title, description, benefits?, icon?, signUp? })` | What a visitor who is not signed in is told about the resource, in place of its list and by a card's favorite button. See [Sign-in prompts](#sign-in-prompts). |
60
60
  | `.form((r) => ({ name, fields, thanks, title?, perMinute? }))` | A public form at `/-/forms/<name>` that creates a record for anyone, signed in or not, behind a rate limit and a bot check. See [Public forms](forms.md). |
61
61
 
62
- A browser tab names what it shows, then the app's name ([`appName`](auth.md#configuration)): `Nordlicht GmbH · Companies · Protobase` on a record page, the plural on a list, `New company · Companies · Protobase` on the create form, and a composed page's title on that page.
62
+ A browser tab names what it shows, then the app's name ([`name`](config/app.md#name)): `Nordlicht GmbH · Companies · Protobase` on a record page, the plural on a list, `New company · Companies · Protobase` on the create form, and a composed page's title on that page.
63
63
 
64
64
  A click on a row of a list's table opens its record. Its title cell, the `.title` column or else the first, is a link to the record, so Cmd- or Ctrl-click, a middle click and the browser's link menu open it in a new tab or copy its address; embedded lists and the table of a list sorted by hand do the same.
65
65
 
@@ -6,7 +6,7 @@ The user menu at the bottom of the sidebar, with the app's own account pages and
6
6
 
7
7
  The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu with their name and email, which link to their account, the app's own pages, the theme switch, and "Sign out". Account pages (organization, billing, users) and help links belong here rather than among the working resources.
8
8
 
9
- Export one [`userMenu(...)`](https://docs.protobase.net/api/schema/functions/usermenu/) from the config module:
9
+ Export one [`userMenu(...)`](https://docs.protobase.net/api/schema/functions/usermenu/) from `config/index.ts`:
10
10
 
11
11
  ```ts
12
12
  // tests/apps/erp/config/user-menu.ts, re-exported from config/index.ts
@@ -28,9 +28,9 @@ export const accountMenu = userMenu((m) => [
28
28
 
29
29
  `accounts` is the built-in [Users page](auth.md#users-page), which the config exports as `usersPage` from `@protobase/layout`; without the export, `createAdmin` refuses the item. Items keep their order. A line splits the menu into groups: these items, then the [organization](auth.md#organizations) pages when the app has organizations, then the person's own: "Account" for everyone (their [account page](auth.md#account-page): profile, [passkeys](auth.md#passkeys) and [two-factor authentication](auth.md#two-factor-authentication)) and "Sign-in policy" for admins (the [sign-in policy](auth.md#sign-in-policy), and the log of [staff sign-ins](auth.md#staff-sign-in)); then the [theme switch](theme.md#light-dark-or-the-system), and "Sign out" always comes last. `icon` is one of `bell`, `book-open`, `bookmark`, `building`, `credit-card`, `external-link`, `file-text`, `heart`, `key`, `layout-dashboard`, `life-buoy`, `mail`, `receipt`, `settings`, `shield`, `users`. A resource item without one uses the resource's sidebar icon, and a link item uses `external-link`.
30
30
 
31
- Every caller gets the menu through `/meta`, without the resources and pages they cannot see, so a user who cannot read `organizations` has no "Organization" item. Links are shown to everyone. `createAdmin` refuses to start when an item names a resource or page that does not exist, and `configExports` refuses a config module that exports two menus.
31
+ Every caller gets the menu through `/meta`, without the resources and pages they cannot see, so a user who cannot read `organizations` has no "Organization" item. Links are shown to everyone. `createAdmin` refuses to start when an item names a resource or page that does not exist, and `configExports` refuses a config that exports two menus.
32
32
 
33
- `protobase dev`, `protobase build` and `protobase serve` pick the menu up from the config module. With `createAdmin` directly, pass it as `userMenu`:
33
+ `protobase dev`, `protobase build` and `protobase serve` pick the menu up from `config/index.ts`. With `createAdmin` directly, pass it as `userMenu`:
34
34
 
35
35
  ```ts
36
36
  const { resources, views, userMenu } = configExports(config)
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Versioning
4
4
 
5
- How Protobase is versioned and released, the commit convention behind it, and which bundles a serve runtime runs.
5
+ How Protobase is versioned and released, the commit convention behind it, bundled and locked projects, and which bundles a serve runtime runs.
6
6
 
7
7
  Protobase follows [semantic versioning](https://semver.org). Every push to `main` that holds a fix, a feature or a breaking change is released: the pushed commit is tagged `v<version>`, and a [GitHub release](https://github.com/PrototeamHQ/protobase/releases) of that tag holds the release's changes. Every `@protobase` package is then published to npm at that version. A release adds no commit to `main`: a release's version is its tag, not a `package.json` field, so the version in the repository's `package.json` files is not bumped. `CHANGELOG.md` lists only the releases from before releases stopped committing.
8
8
 
@@ -54,15 +54,32 @@ When `main` moved on while the checks ran, the run of the newer push releases bo
54
54
 
55
55
  Running the workflow by hand with a tag (`gh workflow run release.yml -f tag=v0.1.0`) only publishes: the packages at that tag and its version, skipping every version npm already has, and the images, which repeats a missed or half-done publish. `node scripts/publish.mjs --dry-run` packs the packages and shows what `npm publish` would send, and `node scripts/publish.mjs --pack`, which CI runs, packs every package without asking npm or publishing. Each package on npm trusts `release.yml` of `PrototeamHQ/protobase` as its publisher; a new package has to be published once by hand before that can be set up. The workflow pushes the images with its own token; a new image on GitHub's registry starts out private and is made public once in its package settings.
56
56
 
57
+ ## Bundled and locked projects
58
+
59
+ Where a project's `package.json` lists the `@protobase` packages decides whose copies dev, the build and its scripts use:
60
+
61
+ | `package.json` | Mode | Copies used by `dev`, `build` and `protobase run` | The bundle's `protobase` |
62
+ | --- | --- | --- | --- |
63
+ | `@protobase/*` in `devDependencies` | bundled (what the presets write) | the CLI's own | the CLI's version |
64
+ | `@protobase/*` in `dependencies` | locked | the project's installed copies | the installed version |
65
+ | no `@protobase/*`, or no `package.json` | bundled | the CLI's own | the CLI's version |
66
+
67
+ - **Bundled.** Nothing of Protobase has to be installed: a `protobase.config.ts` alone is a project. The CLI that runs, installed globally or as the project's dev dependency, supplies every `@protobase` package and every package the serve runtime supplies to a bundle (`kysely`, `pg`, `react`, ...), whatever the project installed: to `dev`'s API and page, to the build, to [`protobase run`](cli.md#run) and, through [`protobase types`](cli.md#types), to the editor. Installing a newer CLI that the specifier holds updates the app with no change to its files or lockfile: dev and the next build use it, and the bundle names its version. `@types/react` and `@types/node` stay the project's own dev dependencies, since the CLI carries no types for them.
68
+ - **Locked.** Move every `@protobase` package to `dependencies` at one exact version, and install. Dev, the build and scripts use the installed copies, and the bundle names that version, so a host serves exactly it. A CLI installed elsewhere hands a locked project over to the `@protobase/cli` it installed (see [CLI](cli.md)). The version moves only when the specifier and the lockfile do.
69
+
70
+ Packages the runtime supplies, such as React, may be listed for their types, in either mode: in a bundle the runtime's copy runs, whichever the project installed. `dependencies` holds the packages the project's own code uses at runtime.
71
+
57
72
  ## Bundles and runtimes
58
73
 
59
- The CLI makes one version check, when it starts: its own version must be in the caret range of the project's, the version of the `@protobase` packages installed in the current directory, which semver calls compatible with it. From 1.0 on that is the same major, and below 1.0, where a minor may break, the same minor, never older than the project's. A 0.14.2 CLI runs a 0.14.0 project and refuses a 0.15.0 or a 1.2.0 one before any command runs:
74
+ The CLI makes one version check, when it starts. The project's `package.json` lists its `@protobase` packages at one version specifier, the same for every one of them, and semver must say the CLI's version satisfies it. A `^0.14.0` project runs on a 0.14.2 CLI and is refused by a 0.15.0 or a 1.2.0 one before any command runs:
60
75
 
61
76
  ```
62
- error: This project is on Protobase 1.2.0, and this CLI is Protobase 0.14.2: run it with a Protobase ^1.2.0 CLI
77
+ error: This project asks for Protobase ^0.14.0, and this CLI is Protobase 0.15.0: run it with a CLI whose version ^0.14.0 holds
63
78
  ```
64
79
 
65
- Within its caret range the CLI stays backwards compatible, so a platform builds every app with the newest CLI in the caret range of the app's version. Nothing else compares versions: not the build, not the serve runtime. `protobase build` writes the version the project is pinned to, the `@protobase/cli` its lockfile installed, into [the manifest](cli.md#the-manifest) as `protobase`, whichever CLI built the bundle, and a host serves the bundle on the runtime of that version. The check is `checkProjectVersion` in `packages/cli/src/version/project-version.ts`.
80
+ In a locked project the installed copies must also be ones the CLI runs: its version in their caret range, which from 1.0 on is the same major and below 1.0, where a minor may break, the same minor, never older. A specifier that is no range, such as `workspace:*`, says no version, so the installed copies are checked instead. A project that lists no `@protobase` package, or has no `package.json`, has nothing to check.
81
+
82
+ Nothing else compares versions: not the build, not the serve runtime. `protobase build` writes the version of the copies it used into [the manifest](cli.md#the-manifest) as `protobase`: the building CLI's own in a bundled project, the `@protobase` packages its lockfile installed in a locked one, and a host serves the bundle on the runtime of that version. The check is `checkProjectVersion` in `packages/cli/src/version/project-version.ts`.
66
83
 
67
84
  ## Plugins
68
85
 
@@ -4,12 +4,12 @@
4
4
 
5
5
  Subscriptions that deliver resource events to URLs, API functions and code, signed with Standard Webhooks, retried and shaped for who receives them.
6
6
 
7
- A **subscription** delivers the [events](events.md) of resources as they happen: to a URL, to one of the app's [API functions](../guides/api-functions.md), or to code of its own. Subscriptions are config: export them from the config module like resources, so the server has them and the admin UI never does. A URL or secret usually comes from the environment.
7
+ A **subscription** delivers the [events](events.md) of resources as they happen: to a URL, to one of the app's [API functions](../guides/api-functions.md), or to code of its own. Subscriptions are config: export them from `config/index.ts` like resources, so the server has them and the admin UI never does. A URL or secret usually comes from the environment.
8
8
 
9
9
  ```ts title="docs-examples/events/subscriptions.ts"
10
10
  import { subscription } from '@protobase/server'
11
11
 
12
- // Where the events of docs-examples/events/orders.ts go: exported from the config module, like the resource.
12
+ // Where the events of docs-examples/events/orders.ts go: exported from config/index.ts, like the resource.
13
13
 
14
14
  /** A Slack message per order, to an incoming webhook whose URL is in the environment; off without it. */
15
15
  export const newOrdersToSlack = subscription('newOrdersToSlack', {
@@ -42,7 +42,7 @@ export const rushOrders = subscription('rushOrders', {
42
42
 
43
43
  ## subscription()
44
44
 
45
- `subscription(name, options)`: the name is unique across the app and its [extensions](config.md#extensions), letters, digits, `_` and `-`. Each has one target:
45
+ `subscription(name, options)`: the name is unique across the app and its [extensions](config.md#extensions), and starts with a letter followed by letters, digits, `_` and `-`. Each has one target:
46
46
 
47
47
  | Target | |
48
48
  | --- | --- |
@@ -59,7 +59,7 @@ export const rushOrders = subscription('rushOrders', {
59
59
  | `payload` | `thin` leaves `after` and `before` out, for a receiver that reads the record through the API. Default `full`. |
60
60
  | `ordered` | One delivery at a time per record, in commit order. Default false. |
61
61
  | `enabled` | Default true; `false` keeps the subscription in the config without delivering. |
62
- | `secret` | `whsec_` and base64: signs the requests of a URL or function target. Without it they are unsigned. `newWebhookSecret()` makes one. |
62
+ | `secret` | `whsec_` and base64: signs the requests of a URL or function target. Without it they are unsigned. `newWebhookSecret()` makes one. An array of secrets signs with each of them, for a rotation. |
63
63
  | `headers` | Extra request headers, such as an API key the receiver wants. |
64
64
  | `body` | `(event) => ...`: what is sent instead of the event, such as Slack's `{ text }`. |
65
65
 
@@ -131,5 +131,5 @@ A subscription is **disabled by itself** when its receiver answers `410 Gone`, o
131
131
  | `webhooks` | |
132
132
  | --- | --- |
133
133
  | `schema` | The schema of its tables, for a database that has a `webhooks` schema already. Default `webhooks`. |
134
- | `deliveryLog` | Also keeps every try, successes too, for 30 days, listed as Webhook delivery log: status, try, status code, the first 2 KB of the answer and how long it took. Default false. |
134
+ | `deliveryLog` | Also keeps every try, successes too, for 30 days, listed as Webhook delivery log: status, try, status code, for a failed try the error with up to 200 characters of the answer, and how long it took. Default false. |
135
135
  | `allowPrivateAddresses` | Lets URLs reach private addresses, for development and tests. Default false. |