@protobase/cli 0.48.0 → 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 (91) 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/create-db.js +2 -2
  15. package/dist/dev/entry.js +9 -10
  16. package/dist/dev/project.js +23 -47
  17. package/dist/main.js +3 -3
  18. package/dist/migration/load-project.js +34 -34
  19. package/dist/migration/parts.js +2 -2
  20. package/dist/migration/summary.js +2 -2
  21. package/dist/mobile/api-origin.js +4 -4
  22. package/dist/mobile/load-project.js +13 -12
  23. package/dist/mobile/register.js +1 -1
  24. package/dist/mobile/run.js +1 -1
  25. package/dist/organizations/register.js +1 -1
  26. package/dist/project/error-reporter.js +3 -3
  27. package/dist/project/import-project-file.js +4 -2
  28. package/dist/project/load-bundle-project.js +16 -25
  29. package/dist/project/load-data-config.js +1 -1
  30. package/dist/project/pg-db.js +10 -4
  31. package/dist/project/placeholder-secret.js +2 -2
  32. package/dist/project/project-admin.js +12 -11
  33. package/dist/serve/create-admin.js +9 -4
  34. package/dist/serve/host-module-ids.js +1 -0
  35. package/dist/serve/host-modules.js +3 -1
  36. package/dist/serve/lifecycle.js +17 -13
  37. package/dist/serve/load-bundle.js +41 -11
  38. package/dist/serve/mobile-release.js +1 -1
  39. package/dist/serve/serve-bundle.js +3 -3
  40. package/dist/supabase/auth-config.js +33 -28
  41. package/dist/supabase/config-jobs.js +28 -27
  42. package/dist/supabase/config-object.js +25 -0
  43. package/dist/supabase/cron-job-file.js +13 -14
  44. package/dist/supabase/cron-jobs-write.js +6 -12
  45. package/dist/supabase/cron-plan.js +3 -51
  46. package/dist/supabase/project-files.js +4 -9
  47. package/dist/supabase/report.js +3 -3
  48. package/dist/users/load-auth.js +16 -15
  49. package/dist/worker/start-worker.js +18 -15
  50. package/package.json +8 -6
  51. package/skills/protobase/SKILL.md +2 -1
  52. package/skills/protobase/references/features/notifications.md +1 -1
  53. package/skills/protobase/references/features/start-a-project.md +3 -0
  54. package/skills/protobase/references/getting-started.md +2 -2
  55. package/skills/protobase/references/guides/api-functions.md +4 -4
  56. package/skills/protobase/references/guides/deploy.md +7 -7
  57. package/skills/protobase/references/guides/existing-database.md +11 -31
  58. package/skills/protobase/references/guides/first-plugin.md +1 -1
  59. package/skills/protobase/references/guides/mobile-app.md +5 -3
  60. package/skills/protobase/references/guides/plugin-build.md +1 -1
  61. package/skills/protobase/references/guides/push-notifications.md +6 -7
  62. package/skills/protobase/references/guides/remote-resources.md +22 -31
  63. package/skills/protobase/references/reference/access.md +3 -3
  64. package/skills/protobase/references/reference/ai.md +1 -9
  65. package/skills/protobase/references/reference/api.md +15 -15
  66. package/skills/protobase/references/reference/app-identity.md +9 -10
  67. package/skills/protobase/references/reference/assistant.md +6 -6
  68. package/skills/protobase/references/reference/auth.md +112 -86
  69. package/skills/protobase/references/reference/bottom-bar.md +1 -1
  70. package/skills/protobase/references/reference/cli.md +35 -85
  71. package/skills/protobase/references/reference/comments.md +0 -8
  72. package/skills/protobase/references/reference/config.md +152 -0
  73. package/skills/protobase/references/reference/data-config.md +2 -2
  74. package/skills/protobase/references/reference/email.md +36 -37
  75. package/skills/protobase/references/reference/events.md +1 -1
  76. package/skills/protobase/references/reference/files.md +18 -23
  77. package/skills/protobase/references/reference/forms.md +5 -17
  78. package/skills/protobase/references/reference/history.md +2 -3
  79. package/skills/protobase/references/reference/installable-app.md +1 -1
  80. package/skills/protobase/references/reference/jobs.md +53 -56
  81. package/skills/protobase/references/reference/languages.md +4 -2
  82. package/skills/protobase/references/reference/mcp.md +10 -10
  83. package/skills/protobase/references/reference/notifications.md +26 -24
  84. package/skills/protobase/references/reference/plugins.md +11 -14
  85. package/skills/protobase/references/reference/remote-resources.md +18 -24
  86. package/skills/protobase/references/reference/supabase-realtime.md +1 -1
  87. package/skills/protobase/references/reference/supabase-rest.md +1 -1
  88. package/skills/protobase/references/reference/supabase-storage.md +1 -1
  89. package/skills/protobase/references/reference/ui-config.md +15 -17
  90. package/skills/protobase/references/reference/versioning.md +1 -1
  91. package/skills/protobase/references/reference/webhooks.md +6 -7
@@ -13,17 +13,16 @@ Push reaches browsers; push on Android and iOS is coming soon.
13
13
  Notifications tell a user about something in the app, in a bell in the top bar and as push on their devices. [Send notifications](../guides/push-notifications.md) walks through turning them on and sending the first one. You turn them on in `protobase.config.ts`:
14
14
 
15
15
  ```ts
16
- import { defineConfig, notifications } from '@protobase/server'
16
+ import { defineConfig } from '@protobase/config'
17
17
 
18
18
  export default defineConfig({
19
- extends: [notifications()],
20
- // config, auth, ...
19
+ notifications: {},
21
20
  })
22
21
  ```
23
22
 
24
- Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while a table is missing or lacks what notifications need, and name it. Without `notifications()` there is none of it: no endpoints, no tables and no migration.
23
+ Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while a table is missing or lacks what notifications need, and name it. Without `notifications` there is none of it: no endpoints, no tables and no migration.
25
24
 
26
- Every signed-in user gets [the bell](#the-bell), and browsers receive push through [Web Push](#web-push); push on Android and iOS is coming soon. `notifications({ ui: false })` keeps only the backend, [without the bell](#without-the-bell).
25
+ Every signed-in user gets [the bell](#the-bell), and browsers receive push through [Web Push](#web-push); push on Android and iOS is coming soon. `notifications: { ui: false }` keeps only the backend, [without the bell](#without-the-bell).
27
26
 
28
27
  ## Devices
29
28
 
@@ -71,7 +70,7 @@ The path comes from `devicesPath('/api', id)`, and the name of its id parameter
71
70
  Only browsers receive push yet; push on Android and iOS is coming soon. <gap>A send can reach a device twice, or keep an entry twice in a history store of your own, when a worker stops mid-send because saving the send's progress in the same step as the push is not implemented.</gap>
72
71
  :::
73
72
 
74
- [Send notifications](../guides/push-notifications.md) sends one from a record change, step by step. You send a notification from your server code, such as a job, a hook, an event subscription or an API function, with `sendNotification(db, to, message)` from `@protobase/server`. It is queued as a background job in `db`'s transaction when `db` is one, so it goes out only once your write commits, and nothing goes out when the transaction rolls back. A running job also has it as `sendNotification` in its context, beside `mail`, when the app has `notifications()`.
73
+ [Send notifications](../guides/push-notifications.md) sends one from a record change, step by step. You send a notification from your server code, such as a job, a hook, an event subscription or an API function, with `sendNotification(db, to, message)` from `@protobase/server`. It is queued as a background job in `db`'s transaction when `db` is one, so it goes out only once your write commits, and nothing goes out when the transaction rolls back. A running job also has it as `sendNotification` in its context, beside `mail`, when the app has `notifications`.
75
74
 
76
75
  Every send to users says whether it shows in their inbox:
77
76
 
@@ -134,7 +133,7 @@ The list gives 20 at a time, or as many as `?limit=` says, up to 50. A full page
134
133
 
135
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.
136
135
 
137
- 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 options it gave `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, options).removeAllForUser(userId)` as it deletes one, with the config's `notifications`.
138
137
 
139
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`.
140
139
 
@@ -154,10 +153,10 @@ The panel also offers to turn push on for this device, where the device can rece
154
153
 
155
154
  ## Without the bell
156
155
 
157
- `notifications({ ui: false })` keeps sending, the history and devices, and the top bar draws no bell, so the app reads no notifications for it:
156
+ `notifications: { ui: false }` keeps sending, the history and devices, and the top bar draws no bell, so the app reads no notifications for it:
158
157
 
159
158
  ```ts
160
- export default defineConfig({ extends: [notifications({ ui: false })] })
159
+ export default defineConfig({ notifications: { ui: false } })
161
160
  ```
162
161
 
163
162
  Your own UI then reads the [history endpoints](#history), through `client.notifications` of `@protobase/client` (`list`, `unread`, `markRead` and `markAllRead`) or the [hooks](#the-bells-slot), and turns push on with [the browser helper](#in-the-browser), such as in a button of the top bar's [actions](custom-components.md#shell-slots).
@@ -208,7 +207,7 @@ export const PushButton = () => {
208
207
  - Signing out turns push off in this browser, and so does someone else signing in on it: what the browser showed is closed, the app's badge cleared, and the device removed. Signing in again as the same user keeps it on.
209
208
  - A tap on a notification whose url is on your app's origin opens that page in the app, in an open window of it or a new one; any other url opens in a new tab.
210
209
 
211
- `protobase serve` and `protobase dev` both serve the service worker that shows notifications, `protobase dev` only when the app has `notifications()`.
210
+ `protobase serve` and `protobase dev` both serve the service worker that shows notifications, `protobase dev` only when the app has `notifications`.
212
211
 
213
212
  ## Your own parts
214
213
 
@@ -216,10 +215,11 @@ export const PushButton = () => {
216
215
  The stores, the senders and the bell's slot may still change.
217
216
  :::
218
217
 
219
- The device store is an interface with a Postgres default, the [devices table](#table-names). You pass your own store to `notifications()`, such as one from a package that keeps devices elsewhere, and then no table is needed and `protobase migration` writes none:
218
+ The device store is an interface with a Postgres default, the [devices table](#table-names). Your own store, such as one from a package that keeps devices elsewhere, is the default export of `notifications/store.ts`, and then no table is needed and `protobase migration` writes none:
220
219
 
221
220
  ```ts
222
- import { defineConfig, notifications, type DeviceStore } from '@protobase/server'
221
+ // notifications/store.ts
222
+ import type { DeviceStore } from '@protobase/server'
223
223
 
224
224
  const store: DeviceStore = {
225
225
  register: async (userId, device) => { /* add or refresh it, or move a phone's token to userId as a new device; undefined for a browser's endpoint another user holds */ },
@@ -230,17 +230,18 @@ const store: DeviceStore = {
230
230
  removeAllForUser: async (userId) => {},
231
231
  }
232
232
 
233
- export default defineConfig({ extends: [notifications({ store })] })
233
+ export default store
234
234
  ```
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 options it gave `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, options).removeAllForUser(userId)` as it deletes one, with the config's `notifications`.
239
239
 
240
- The history store is an interface with a Postgres default too, the [history table](#table-names), and you pass your own as `historyStore`:
240
+ 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
241
 
242
242
  ```ts
243
- import { defineConfig, notifications, type HistoryStore } from '@protobase/server'
243
+ // notifications/history-store.ts
244
+ import type { HistoryStore } from '@protobase/server'
244
245
 
245
246
  const historyStore: HistoryStore = {
246
247
  record: async (userId, notification) => { /* keep it unread, created now, under a new id */ },
@@ -251,24 +252,25 @@ const historyStore: HistoryStore = {
251
252
  removeAllForUser: async (userId) => {},
252
253
  }
253
254
 
254
- export default defineConfig({ extends: [notifications({ historyStore })] })
255
+ export default historyStore
255
256
  ```
256
257
 
257
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)`.
258
259
 
259
260
  ### Senders
260
261
 
261
- A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push is built in; you pass your own senders to `notifications()`, such as from a package, and they replace the built-in ones, at most one for each kind:
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:
262
263
 
263
264
  ```ts
264
- import { defineConfig, notifications, type PushSender } from '@protobase/server'
265
+ // notifications/senders.ts
266
+ import type { PushSender } from '@protobase/server'
265
267
 
266
268
  const sender: PushSender = {
267
269
  kinds: ['fcm'],
268
270
  send: async (message, devices) => devices.map((device) => ({ id: device.id, result: 'ok' })),
269
271
  }
270
272
 
271
- export default defineConfig({ extends: [notifications({ senders: [sender] })] })
273
+ export default [sender]
272
274
  ```
273
275
 
274
276
  `send` takes a message and a batch of devices of those kinds, and answers each device by its id with a result:
@@ -356,10 +358,10 @@ The default store keeps devices in the table `devices` of the schema `notificati
356
358
  You rename the schema, the table and each column, as auth takes `users.table` and `users.columns`, such as to keep devices in a table you already have:
357
359
 
358
360
  ```ts
359
- notifications({
361
+ notifications: {
360
362
  schema: 'push',
361
363
  devices: { table: 'targets', columns: { user_id: 'owner_id', token: 'address' } },
362
- })
364
+ },
363
365
  ```
364
366
 
365
367
  The history is kept in the table `history` of the same schema:
@@ -377,9 +379,9 @@ The history is kept in the table `history` of the same schema:
377
379
  Two indexes keep a user's newest-first pages and unread count cheap. You rename its table and columns as `history.table` and `history.columns`:
378
380
 
379
381
  ```ts
380
- notifications({
382
+ notifications: {
381
383
  history: { table: 'inbox', columns: { user_id: 'owner_id', read_at: 'seen_at' } },
382
- })
384
+ },
383
385
  ```
384
386
 
385
387
  A name is lowercase letters, digits and `_`, at most 63 characters. Startup stops, naming what is wrong, while a table lacks a configured column, while the devices table lacks a unique index on the token column alone, which moving a device relies on, or, with Protobase's auth, while either table lacks the foreign key from its user column to the users table with `on delete cascade`.
@@ -91,7 +91,7 @@ export const Greeting = () => {
91
91
  | `name` | The plugin's name, from its `plugin.json`. |
92
92
  | `version` | Its own version, from its `package.json`, when it has one. |
93
93
  | `url` | Its `plugin.json`: `new URL('./data.json', url)` finds a file served beside it. |
94
- | `settings` | What the app gives it in `options.plugins` (see [loading](#loading)), `{}` otherwise. |
94
+ | `settings` | What the app gives it in `plugins` (see [loading](#loading)), `{}` otherwise. |
95
95
 
96
96
  It works in the components, field types, shell slots and `beforeSignIn` a plugin registers and everything they render, and throws anywhere else.
97
97
 
@@ -192,31 +192,28 @@ The output folder is emptied first, so it must not hold the plugin's own files.
192
192
  The app loads the plugins `/api/meta` names to the signed-in user, in this order:
193
193
 
194
194
  1. the bundle's own, from its manifest: each `--extend` folder's, then the project's (`app`), for everyone;
195
- 2. those `createAdmin`'s `options.plugins` lists, in `protobase.config.ts`;
195
+ 2. those `plugins` in `protobase.config.ts` lists;
196
196
  3. those `PROTOBASE_PLUGINS` lists: URLs separated by commas, which a hosting platform sets for the plugins it adds to its apps;
197
197
  4. those `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` lists, the same way, which also load [before sign-in](#before-sign-in).
198
198
 
199
199
  ```ts
200
200
  // protobase.config.ts
201
- export default {
202
- config,
203
- options: {
204
- plugins: [
205
- { url: 'https://plugins.example.com/sales-tools/plugin.json' },
206
- { url: '/plugins/board/plugin.json', settings: { columns: 3 }, roles: ['admin', 'sales'] },
207
- ],
208
- },
209
- }
201
+ export default defineConfig({
202
+ plugins: [
203
+ { url: 'https://plugins.example.com/sales-tools/plugin.json' },
204
+ { url: '/plugins/board/plugin.json', settings: { columns: 3 }, roles: ['admin', 'sales'] },
205
+ ],
206
+ })
210
207
  ```
211
208
 
212
- | `options.plugins[]` | |
209
+ | `plugins[]` | |
213
210
  | --- | --- |
214
211
  | `url` | The plugin's `plugin.json`: an `https://` or `http://` URL, or a path on the app's own origin. |
215
212
  | `settings` | Data the plugin reads with `usePlugin()`. |
216
213
  | `roles` | When set, only callers with one of these roles load it; without, everyone does. This decides what the app loads, not what anyone may do: the API's access rules still decide that. |
217
214
  | `beforeSignIn` | `true` loads it [before sign-in](#before-sign-in) too, for everyone; it cannot have `roles`. Off by default. |
218
215
 
219
- `options.plugins: false` turns off all but the first; the bundle's own plugins are the app's own UI and always load. A URL that is not one stops the server at startup, naming where it came from, and so does a plugin with both `roles` and `beforeSignIn`. Each URL is loaded once, where it is first listed; one `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` lists loads before sign-in wherever it is listed.
216
+ `plugins: false` turns off all but the first; the bundle's own plugins are the app's own UI and always load. A URL that is not one stops the server at startup, naming where it came from, and so does a plugin with both `roles` and `beforeSignIn`. Each URL is loaded once, where it is first listed; one `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` lists loads before sign-in wherever it is listed.
220
217
 
221
218
  When the user signs in, or before for a plugin that loads [before sign-in](#before-sign-in), the app reads each `plugin.json`, then loads the module and the stylesheet of each plugin that fits, and draws once they have loaded, or after ten seconds at most: a slower plugin comes in when it arrives. So a host serves them like this:
222
219
 
@@ -326,4 +323,4 @@ From `@protobase/ui`:
326
323
  | `pluginApi` | The plugin API of the app's `@protobase/ui`. |
327
324
  | `protobaseVersion` | The Protobase version of the app's `@protobase/ui`. |
328
325
 
329
- From `@protobase/layout`: `component(name, { plugin })` (see [above](#declaring-its-components-in-the-config)). From `@protobase/schema`: `.widget(name, props)` on a view's fields and `d.cards(fields, { card })` (see [Views](ui-config.md)). From `@protobase/server`: `options.plugins` of `createAdmin`, `PROTOBASE_PLUGINS` and `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` (see [loading](#loading)). The tokens a plugin's utilities read are in [Theme](theme.md).
326
+ From `@protobase/layout`: `component(name, { plugin })` (see [above](#declaring-its-components-in-the-config)). From `@protobase/schema`: `.widget(name, props)` on a view's fields and `d.cards(fields, { card })` (see [Views](ui-config.md)). From the config: `plugins`; from the environment: `PROTOBASE_PLUGINS` and `PROTOBASE_PLUGINS_BEFORE_SIGN_IN` (see [loading](#loading)). The tokens a plugin's utilities read are in [Theme](theme.md).
@@ -32,18 +32,13 @@ So the source decides what a person sees and may do, exactly as in its own admin
32
32
 
33
33
  ## Declaring a source
34
34
 
35
- A source is declared on the app's server, in `options.sources` of its config, or by the platform that runs the app in `PROTOBASE_SOURCES`, without the app's own code:
35
+ A source is declared on the app's server, in `remoteResources` of its config, or by the platform that runs the app in `PROTOBASE_SOURCES`, without the app's own code:
36
36
 
37
37
  ```ts
38
38
  // protobase.config.ts
39
- export default {
40
- config,
41
- auth,
42
- authenticate,
43
- options: {
44
- sources: [{ url: 'https://desk.example.com/api/v1', label: 'Service desk', resources: ['tickets', 'ticket_notes'] }],
45
- },
46
- }
39
+ export default defineConfig({
40
+ remoteResources: [{ url: 'https://desk.example.com/api/v1', label: 'Service desk', resources: ['tickets', 'ticket_notes'] }],
41
+ })
47
42
  ```
48
43
 
49
44
  ```sh
@@ -57,7 +52,7 @@ PROTOBASE_SOURCES='[{"url":"https://desk.example.com/api/v1","label":"Service de
57
52
  | `resources` | The resources the app draws from it, by their names there. Its other resources stay out of the app. |
58
53
  | `roles` | Optional: only callers holding one of these roles are told about the source. Without, everyone is. |
59
54
 
60
- The sources of `options.sources` come first, then those of `PROTOBASE_SOURCES`; `options.sources: false` turns both off.
55
+ The sources of `remoteResources` come first, then those of `PROTOBASE_SOURCES`; `remoteResources: false` turns both off.
61
56
 
62
57
  **Checks at startup.** The server refuses to start, naming the source, when a source cannot work: a `url` that is no http(s) URL or names no path, a missing `label` or `resources`, a key a source does not take (such as `resource` for `resources`), the same `url` listed twice, or one resource drawn from two sources. It refuses to start too when a source draws a resource under a name the app already has, for one of its own resources or a [composed page](layouts.md): the address `/<name>` would mean two things. Rename one of them, or leave it out of the source's resources.
63
58
 
@@ -74,40 +69,39 @@ A source's view can be written for the people of another app: views are picked [
74
69
 
75
70
  The browser sends the source the token the app issued to the signed-in person, as it sends it to the app's own API (`Authorization: Bearer`). The source accepts it or not: there is no second sign-in, and the app never sees a password or key of the source.
76
71
 
77
- A Protobase API accepts the tokens of another Protobase app when it lists that app in `betterAuthAuthenticator`'s `apps`:
72
+ A Protobase API accepts the tokens of another Protobase app when it lists that app in `authenticate.apps`:
78
73
 
79
74
  ```ts
80
- // the source's auth.ts
81
- export const authenticate = betterAuthAuthenticator({
82
- auth,
83
- apps: [{ issuer: 'https://shop.example.com', roles: { admin: 'shop' } }],
75
+ // the source's protobase.config.ts
76
+ export default defineConfig({
77
+ authenticate: { apps: [{ issuer: 'https://shop.example.com', roles: { admin: 'shop' } }] },
84
78
  })
85
79
  ```
86
80
 
87
81
  | Trusted app | |
88
82
  | --- | --- |
89
- | `issuer` | The other app's Better Auth `baseURL`, its `BETTER_AUTH_URL`, with or without a trailing slash: the issuer and audience of its tokens. Its keys are read from `<issuer>/api/auth/jwks`. |
83
+ | `issuer` | The other app's `url`, its `PROTOBASE_URL`, with or without a trailing slash: the issuer and audience of its tokens. Its keys are read from `<issuer>/api/auth/jwks`. |
90
84
  | `roles` | Its global roles as they are here: `{ admin: 'shop' }` makes its admins `shop` here. A role it does not list is dropped, and a user left with none is refused with `403`. A role someone holds in one of its [organizations](auth.md#organizations) is never mapped, since that organization's owners hand it out; with organizations there, only a global role counts. |
91
85
  | `tenant` | The tenant its users work in here, for resources with a [tenant](data-config.md#resource). Nothing in its tokens names a tenant here. |
92
86
  | `keys` | Its key set, instead of reading it from its `/api/auth/jwks`: for tests, or keys at hand. |
93
87
 
94
88
  - A token whose issuer is a trusted app's is verified against that app's keys, with that issuer as issuer and audience; every other token goes to the app's own check. The key set is kept for 10 minutes and read again for an unknown key, as jose's remote key sets do.
95
89
  - The user's id here is `<sub>@<that app's host>`, such as `x81kd2@shop.example.com`, so it never equals an id of this app's own users: an [owner field](access.md) or an audit entry tells them apart.
96
- - Give the other app's users roles of their own (`shop`, not `admin`) and open to those roles exactly what you share. A role that is only in `apps` needs no place in `createAuth`'s `roles`, which are the roles of this app's own users; with [`defineRoles`](access.md), define what it may do like any role.
90
+ - Give the other app's users roles of their own (`shop`, not `admin`) and open to those roles exactly what you share. A role that is only in `apps` needs no place in `auth.roles`, which are the roles of this app's own users; with [`defineRoles`](access.md), define what it may do like any role.
97
91
  - An app without `defineRoles` [allows](access.md#defaults) every operation without a rule to everyone signed in, the other app's users included. Give the resources you do not share an access rule that leaves their role out, or define roles.
98
92
  - A trusted app cannot be this app itself.
99
93
 
100
- A source that is not a Protobase app accepts the app's tokens its own way: they are EdDSA JWTs whose issuer and audience are the app's `BETTER_AUTH_URL`, whose keys are at `<that URL>/api/auth/jwks`, which carry the user's id in `sub`, their active role in `role` and live for 15 minutes (see [Tokens and roles](auth.md#tokens-and-roles)).
94
+ A source that is not a Protobase app accepts the app's tokens its own way: they are EdDSA JWTs whose issuer and audience are the app's `url` (`PROTOBASE_URL`), whose keys are at `<that URL>/api/auth/jwks`, which carry the user's id in `sub`, their active role in `role` and live for 15 minutes (see [Tokens and roles](auth.md#tokens-and-roles)).
101
95
 
102
96
  **What it trusts.** A source sees the person's token, which the app's own API also accepts until it expires, within 15 minutes. List as a source only an API you trust as much as a [plugin](plugins.md), whose code runs in the app with the same rights.
103
97
 
104
98
  ## CORS
105
99
 
106
- The browser calls the source from the app's origin, so the source answers [CORS](api.md#cors) for it: it lists the app's origin in `options.cors` or `PROTOBASE_CORS_ORIGINS`:
100
+ The browser calls the source from the app's origin, so the source answers [CORS](api.md#cors) for it: it lists the app's origin in `cors` or `PROTOBASE_CORS_ORIGINS`:
107
101
 
108
102
  ```ts
109
103
  // the source's protobase.config.ts
110
- export default { config, auth, authenticate, options: { cors: ['https://shop.example.com'] } }
104
+ export default defineConfig({ cors: ['https://shop.example.com'] })
111
105
  ```
112
106
 
113
107
  A Protobase API then answers preflights for the bearer token and the `If-Match` and `If-None-Match` headers, and exposes `ETag`, `Location` and `X-Meta-Version`, which the app uses. Without it the browser refuses every answer of the source, and the app shows its resources as unavailable.
@@ -169,13 +163,13 @@ Each source's `/meta` is read again when the window regains focus, with `If-None
169
163
 
170
164
  **`/api/meta`** names the caller's sources in `sources`: `[{ url, label, resources }]`, without `roles`; none without sources.
171
165
 
172
- **`@protobase/server`**
166
+ **Config and `@protobase/server`**
173
167
 
174
168
  | | |
175
169
  | --- | --- |
176
- | `options.sources` | `SourceOption[]` (`{ url, label, resources, roles? }`) or `false`. |
177
- | `PROTOBASE_SOURCES` | A JSON list of the same, after `options.sources`. |
178
- | `betterAuthAuthenticator({ apps })` | `TrustedApp[]` (`{ issuer, roles, tenant?, keys? }`): other apps whose tokens the API admits. |
170
+ | `remoteResources` | `SourceOption[]` (`{ url, label, resources, roles? }`) or `false`. |
171
+ | `PROTOBASE_SOURCES` | A JSON list of the same, after `remoteResources`. |
172
+ | `authenticate.apps` | `TrustedApp[]` (`{ issuer, roles, tenant?, keys? }`): other apps whose tokens the API admits. |
179
173
  | `withTrustedApps(own, ownIssuer, apps)` | The same around any authenticator. |
180
174
  | `sourceOptions`, `checkSourceNames`, `sourcesFor` | What `createAdmin` reads, checks and names, for hosts that read sources themselves. |
181
175
 
@@ -18,7 +18,7 @@ supabase
18
18
 
19
19
  ## Keys, roles and tokens
20
20
 
21
- The keys are `options.apiKeys` of `createAdmin`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. The socket sends the key in its URL and is refused with `401` without a key of the app. Each channel joins with the client's access token: a signed-in user's token makes it `authenticated` with the token's claims, the publishable key alone `anon`, the secret key alone the app's own role. A token the client refreshes on an open socket replaces the channel's; a channel whose token expires is closed with a `Token has expired` system message, as on Supabase.
21
+ The keys are `apiKeys` in `protobase.config.ts`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. The socket sends the key in its URL and is refused with `401` without a key of the app. Each channel joins with the client's access token: a signed-in user's token makes it `authenticated` with the token's claims, the publishable key alone `anon`, the secret key alone the app's own role. A token the client refreshes on an open socket replaces the channel's; a channel whose token expires is closed with a `Token has expired` system message, as on Supabase.
22
22
 
23
23
  The server serves the socket when the host gives `createAdmin` its WebSocket upgrade: `protobase serve` does, on Bun and Node, and so does `protobase dev`, beside Vite's hot reload socket. An edit to the project under `protobase dev` closes the open sockets with code `1012`, and supabase-js reconnects to the rebuilt API.
24
24
 
@@ -15,7 +15,7 @@ const { data, error } = await supabase.from('todos').select('id, title').eq('don
15
15
 
16
16
  ## Keys and roles
17
17
 
18
- The keys are `options.apiKeys` of `createAdmin`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. Without either, or with `apiKeys: false`, the app serves no `/api/sb/rest/v1`. Each request sends a key in the `apikey` header, and runs in one transaction as:
18
+ The keys are `apiKeys` in `protobase.config.ts`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. Without either, or with `apiKeys: false`, the app serves no `/api/sb/rest/v1`. Each request sends a key in the `apikey` header, and runs in one transaction as:
19
19
 
20
20
  | The request sends | It runs as |
21
21
  | --- | --- |
@@ -19,7 +19,7 @@ The buckets and objects are the rows of `storage.buckets` and `storage.objects`,
19
19
 
20
20
  ## Keys and roles
21
21
 
22
- The keys are `options.apiKeys` of `createAdmin`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. Without either, or with `apiKeys: false`, the app serves no `/api/sb/storage/v1`. A request sends a key in the `apikey` header and runs as:
22
+ The keys are `apiKeys` in `protobase.config.ts`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. Without either, or with `apiKeys: false`, the app serves no `/api/sb/storage/v1`. A request sends a key in the `apikey` header and runs as:
23
23
 
24
24
  | The request sends | It runs as |
25
25
  | --- | --- |
@@ -744,7 +744,7 @@ The photos are read with the list API under the user's own access, up to 500, so
744
744
  ])
745
745
  ```
746
746
 
747
- The map is drawn with [MapLibre](https://maplibre.org) from the style the server names: `createAdmin`'s `options.maps.style`, else `PROTOBASE_MAP_STYLE_URL`, an http(s) URL of a MapLibre style; `options.maps: false` turns maps off whatever the variable says, and a style that is no http(s) URL stops the server at startup. The style's sources may be [PMTiles](https://docs.protomaps.com/pmtiles/) archives (`pmtiles://https://...`), so the tiles can be one file on a bucket of your own. The tiles, sprites and fonts are fetched by the browser, so their host must answer the app's origins with CORS, and an archive with range requests. Without a style there is no map, nor is there one for a record whose fields hold no position or for a user who may not read them. MapLibre loads with the first map drawn, so a page without one does not load it.
747
+ The map is drawn with [MapLibre](https://maplibre.org) from the style the server names: `maps.style` in `protobase.config.ts`, else `PROTOBASE_MAP_STYLE_URL`, an http(s) URL of a MapLibre style; `maps: false` turns maps off whatever the variable says, and a style that is no http(s) URL stops the server at startup. The style's sources may be [PMTiles](https://docs.protomaps.com/pmtiles/) archives (`pmtiles://https://...`), so the tiles can be one file on a bucket of your own. The tiles, sprites and fonts are fetched by the browser, so their host must answer the app's origins with CORS, and an archive with range requests. Without a style there is no map, nor is there one for a record whose fields hold no position or for a user who may not read them. MapLibre loads with the first map drawn, so a page without one does not load it.
748
748
 
749
749
  A map display takes two number fields that are `.filterable()`, since it asks for the records inside its view with a filter on them, and the server refuses to start otherwise; an index on them, such as `(latitude, longitude)`, lets Postgres find those records. The filter and search of the list narrow what it shows. Where it looks is in the address, `/listings?display=map&map=52.37,4.89,12` (latitude, longitude, zoom), so Back, a reload or a shared link opens the same view; without one it fits every matching record. When none is in view, **Show all** fits them again.
750
750
 
@@ -767,24 +767,22 @@ d.map(
767
767
 
768
768
  #### Map layers
769
769
 
770
- `options.maps.layers` adds other maps of raster tiles, such as aerial photos, next to the style. With layers, every map (`l.map` and `d.map`) has a switch in its top left corner between **Map**, the style's map and the default, and each layer by its `label`. The choice is remembered in the browser for every map, and a layer the app no longer offers falls back to the default. The chosen layer is drawn over the style's map, under the areas and markers, and its `attribution` shows in the map's corner while it is.
770
+ `maps.layers` in the config adds other maps of raster tiles, such as aerial photos, next to the style. With layers, every map (`l.map` and `d.map`) has a switch in its top left corner between **Map**, the style's map and the default, and each layer by its `label`. The choice is remembered in the browser for every map, and a layer the app no longer offers falls back to the default. The chosen layer is drawn over the style's map, under the areas and markers, and its `attribution` shows in the map's corner while it is.
771
771
 
772
772
  ```ts
773
- createAdmin({
774
- // ...
775
- options: {
776
- maps: {
777
- layers: [
778
- {
779
- id: 'aerial_nl',
780
- label: 'Aerial (NL)',
781
- tiles: 'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg',
782
- attribution: 'Luchtfoto <a href="https://www.beeldmateriaal.nl/">Beeldmateriaal Nederland</a>, CC BY 4.0, via <a href="https://www.pdok.nl/">PDOK</a>',
783
- bounds: [3.2, 50.7, 7.3, 53.7],
784
- maxzoom: 21,
785
- },
786
- ],
787
- },
773
+ // protobase.config.ts
774
+ export default defineConfig({
775
+ maps: {
776
+ layers: [
777
+ {
778
+ id: 'aerial_nl',
779
+ label: 'Aerial (NL)',
780
+ tiles: 'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg',
781
+ attribution: 'Luchtfoto <a href="https://www.beeldmateriaal.nl/">Beeldmateriaal Nederland</a>, CC BY 4.0, via <a href="https://www.pdok.nl/">PDOK</a>',
782
+ bounds: [3.2, 50.7, 7.3, 53.7],
783
+ maxzoom: 21,
784
+ },
785
+ ],
788
786
  },
789
787
  })
790
788
  ```
@@ -74,7 +74,7 @@ Releases keep the plugin API, below 1.0 too, where a minor version may change th
74
74
 
75
75
  ## Runtime updates
76
76
 
77
- An app whose host can update its runtime, such as a hosting platform, can show admins an **Update** button in the top bar. `PROTOBASE_RUNTIME_URL` (or `createAdmin`'s `options.runtime.url`) names the host's endpoint, and `/api/meta` passes it on as `runtime: { url }` to callers with the `admin` role only. Without it, or for anyone else, the app shows nothing and asks nothing.
77
+ An app whose host can update its runtime, such as a hosting platform, can show admins an **Update** button in the top bar. `PROTOBASE_RUNTIME_URL` (or `runtimeUpdates.url` in `protobase.config.ts`) names the host's endpoint, and `/api/meta` passes it on as `runtime: { url }` to callers with the `admin` role only. Without it, or for anyone else, the app shows nothing and asks nothing.
78
78
 
79
79
  The app sends the signed-in user's API token as `Authorization: Bearer <token>` (verified like an [assistant backend](assistant.md#another-backend) does) and expects:
80
80
 
@@ -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 config and the configs it extends, letters, digits, `_` and `-`. Each has one target:
45
+ `subscription(name, options)`: the name is unique across the app and its [extensions](config.md#extensions), letters, digits, `_` and `-`. Each has one target:
46
46
 
47
47
  | Target | |
48
48
  | --- | --- |
@@ -102,12 +102,12 @@ Every outcome is a line in the server log, such as `webhook newOrdersToSlack ord
102
102
 
103
103
  ## Subscriptions in the admin app
104
104
 
105
- A subscription in the config suits a developer. For people who make their own at runtime, such as a tenant admin wiring their organization to a tool they use, extend the config with `webhooks()`:
105
+ A subscription in the config suits a developer. For people who make their own at runtime, such as a tenant admin wiring their organization to a tool they use, turn them on with `webhooks` in `protobase.config.ts`:
106
106
 
107
107
  ```ts
108
- import { defineConfig, webhooks } from '@protobase/server'
108
+ import { defineConfig } from '@protobase/config'
109
109
 
110
- export default defineConfig({ extends: [webhooks()], config, auth, authenticate })
110
+ export default defineConfig({ webhooks: {} })
111
111
  ```
112
112
 
113
113
  It adds two pages, over a `webhooks` schema that [`protobase migration`](cli.md#migration) writes (`NNN_webhooks.sql`):
@@ -117,7 +117,7 @@ It adds two pages, over a `webhooks` schema that [`protobase migration`](cli.md#
117
117
 
118
118
  Both are scoped to the tenant like any resource with `.tenant()`, and their access decides who may do what: `webhook_subscriptions.create`, `webhook_deliveries.update` and so on, as for the app's own resources.
119
119
 
120
- A subscription made here **delivers as its owner**, with the role they act with now in its tenant (the [active role](auth.md#active-role) they last chose, else their first): only records and fields it may read. Letting people make subscriptions therefore grants them nothing they could not read already. The roles are read from the project's Better Auth; a project that signs people in otherwise passes `webhooks({ ownerRoles: async ({ id, tenant }) => [...] })`.
120
+ A subscription made here **delivers as its owner**, with the role they act with now in its tenant (the [active role](auth.md#active-role) they last chose, else their first): only records and fields it may read. Letting people make subscriptions therefore grants them nothing they could not read already. The roles are read from the app's sign-in; a project that signs people in otherwise exports its own, `async ({ id, tenant }) => [...]`, as the default of `webhooks/owner-roles.ts`.
121
121
 
122
122
  | Action | |
123
123
  | --- | --- |
@@ -128,9 +128,8 @@ A subscription made here **delivers as its owner**, with the role they act with
128
128
 
129
129
  A subscription is **disabled by itself** when its receiver answers `410 Gone`, or when no delivery succeeded for three days; the page says why.
130
130
 
131
- | `webhooks(options)` | |
131
+ | `webhooks` | |
132
132
  | --- | --- |
133
133
  | `schema` | The schema of its tables, for a database that has a `webhooks` schema already. Default `webhooks`. |
134
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. |
135
- | `ownerRoles` | The roles an owner holds now in a tenant, for a project without Better Auth. |
136
135
  | `allowPrivateAddresses` | Lets URLs reach private addresses, for development and tests. Default false. |