@protobase/cli 0.45.20 → 0.45.22

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.45.20";
2
+ var version = "0.45.22";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.45.20",
3
+ "version": "0.45.22",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.12",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.45.20",
40
- "@protobase/query": "0.45.20",
41
- "@protobase/schema": "0.45.20",
42
- "@protobase/server": "0.45.20",
43
- "@protobase/ui": "0.45.20",
39
+ "@protobase/layout": "0.45.22",
40
+ "@protobase/query": "0.45.22",
41
+ "@protobase/schema": "0.45.22",
42
+ "@protobase/server": "0.45.22",
43
+ "@protobase/ui": "0.45.22",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -55,6 +55,7 @@ Guides:
55
55
  - When showing another Protobase app's records → read [Showing another app's records](references/guides/remote-resources.md)
56
56
  - When letting users save a list as Excel or CSV → read [Exporting a list](references/guides/export-a-list.md)
57
57
  - When importing records from a spreadsheet → read [Importing records from a spreadsheet](references/guides/import-records.md)
58
+ - When telling users about a change, in the bell and as push on their browsers → read [Send notifications](references/guides/push-notifications.md)
58
59
  - When replacing a resource's create form with a page of your own → read [A create page of your own](references/guides/create-page.md)
59
60
  - When running the app on iOS or Android → read [A mobile app](references/guides/mobile-app.md)
60
61
 
@@ -4,13 +4,13 @@
4
4
 
5
5
  A bell in the top bar and push to browsers and phones, for what your app tells its users.
6
6
 
7
- - [Notifications](../reference/notifications.md#turning-them-on) (in development): `extends: [notifications()]` gives every signed-in user a bell in the top bar and push to their browsers and phones; `ui: false` keeps only the backend.
7
+ - [Notifications](../reference/notifications.md#turning-them-on) (beta): `extends: [notifications()]` gives every signed-in user a bell in the top bar and push to their browsers and phones; `ui: false` keeps only the backend.
8
8
  - [Devices](../reference/notifications.md#devices) (beta): Each signed-in user registers their own browsers and phones to receive push, and a device gets it only while the sign-in it was registered in lasts.
9
- - [Your own parts](../reference/notifications.md#your-own-parts) (in development): Senders, the device store, the history store and the bell can each be replaced by your own, such as a store outside the database.
9
+ - [Your own parts](../reference/notifications.md#your-own-parts) (beta): Senders, the device store, the history store and the bell can each be replaced by your own, such as a store outside the database.
10
10
  - [Table names](../reference/notifications.md#table-names) (beta): The built-in stores' schema, tables and columns can be renamed, as auth's users table can.
11
11
  - [Sending notifications](../reference/notifications.md#sending) (beta): Your code sends a notification to users or to devices as a background job, queued in the same transaction as a write, and says on each one whether it shows in the inbox.
12
12
  - [Notification history](../reference/notifications.md#history) (beta): Each user's inbox notifications are kept with when they were read, and the API lists them, counts the unread ones and marks them read.
13
13
  - [Web Push](../reference/notifications.md#web-push) (beta): Notifications reach desktop and Android browsers and home-screen web apps on iPhone through Web Push, with keys you generate.
14
14
  - Push on Android (coming soon): Notifications reach the Android build of the app on a user's phones.
15
15
  - Push on iOS (coming soon): Notifications reach the iOS build of the app on a user's iPhones and iPads.
16
- - Notification bell (coming soon): A bell in the top bar shows a user's unread notifications and lists the latest.
16
+ - [Notification bell](../reference/notifications.md#the-bell) (beta): The top bar shows how many inbox notifications are unread; its panel opens each one, marks them read and turns push on or off for this device.
@@ -0,0 +1,113 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/push-notifications.mdx: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Send notifications
4
+
5
+ Turn notifications on, send one when a record changes, and see it in the bell and as push on the user's browser.
6
+
7
+ You turn notifications on, send one when something happens in your app, and see it in the bell and as push on your browser. This guide uses the ERP example (`examples/erp`, set up as its README says, with a user from `protobase users create`): when an order's status changes, its owner hears about it. The [Notifications reference](../reference/notifications.md) has every option.
8
+
9
+ ## 1. Turn notifications on
10
+
11
+ Add `notifications()` to `protobase.config.ts`:
12
+
13
+ ```ts
14
+ import { defineConfig, notifications } from '@protobase/server'
15
+
16
+ export default defineConfig({
17
+ config,
18
+ extends: [notifications()],
19
+ // auth, authenticate, jobs, ...
20
+ })
21
+ ```
22
+
23
+ Then write the tables it needs as a migration of your own, and apply it:
24
+
25
+ ```sh
26
+ bun run protobase migration # writes db/migrations/NNN_notifications.sql
27
+ bun run db:migrate
28
+ ```
29
+
30
+ `protobase dev` refuses to start until the [devices and history tables](../reference/notifications.md#table-names) are there.
31
+
32
+ ## 2. Generate the Web Push keys
33
+
34
+ Browsers receive push through [Web Push](../reference/notifications.md#web-push), which needs a key pair of your own:
35
+
36
+ ```sh
37
+ bun run protobase notifications vapid-keys
38
+ ```
39
+
40
+ Paste the two lines it prints into `.env`, and add how push services can reach you:
41
+
42
+ ```sh
43
+ PROTOBASE_VAPID_PUBLIC_KEY=...
44
+ PROTOBASE_VAPID_PRIVATE_KEY=...
45
+ PROTOBASE_VAPID_SUBJECT=mailto:you@example.com
46
+ ```
47
+
48
+ Keep the private key out of the repository. Without the keys, notifications still reach the bell, and browsers get no push.
49
+
50
+ ## 3. Send one when a record changes
51
+
52
+ Declare the [event](../reference/events.md#declaring-events) on the orders, in `config/orders/data.ts`:
53
+
54
+ ```ts
55
+ .events((e, r) => [e.updated('statusChanged', { changed: [r.status] })])
56
+ ```
57
+
58
+ Then add a [subscription](../reference/webhooks.md#subscription) that [sends a notification](../reference/notifications.md#sending) to the order's owner, with a link to the order, and export it from `config/index.ts` beside the resources:
59
+
60
+ ```ts title="config/orders/notifications.ts"
61
+ import { appPath } from '@protobase/schema'
62
+ import { sendNotification, subscription } from '@protobase/server'
63
+
64
+ // The app's public origin: the address its sign-in runs on, from its own configuration.
65
+ const appOrigin = process.env.BETTER_AUTH_URL ?? 'http://localhost:5173'
66
+
67
+ /** Tells an order's owner when its status changes, in their inbox and as push, with a link to the order. */
68
+ export const orderStatusToOwner = subscription('orderStatusToOwner', {
69
+ events: ['orders.statusChanged'],
70
+ run: async ({ data }, { db }) => {
71
+ const owner = data.after?.owner_id
72
+ if (owner == null) return
73
+ const url = new URL(appPath({ kind: 'record', resource: 'orders', key: data.key }), appOrigin).href
74
+ await sendNotification(db, { userIds: [String(owner)], inbox: true }, { title: `Order ${data.after?.number} changed status`, url })
75
+ },
76
+ })
77
+ ```
78
+
79
+ ```ts
80
+ // config/index.ts
81
+ export { orderStatusToOwner } from './orders/notifications'
82
+ ```
83
+
84
+ `inbox: true` keeps it in the owner's [history](../reference/notifications.md#history), which the bell shows, besides pushing it; `inbox: false` only pushes it. The same `sendNotification` works from a [job](../reference/jobs.md), a write hook or an [API function](api-functions.md).
85
+
86
+ The event needs triggers on the orders table, so write and apply the migration again:
87
+
88
+ ```sh
89
+ bun run protobase migration # writes db/migrations/NNN_changes.sql
90
+ bun run db:migrate
91
+ ```
92
+
93
+ ## 4. Turn push on from the bell
94
+
95
+ Run `bun run protobase dev`, open `http://localhost:5173` in a desktop browser and sign in. The [bell](../reference/notifications.md#the-bell) in the top bar opens your notifications; at its foot, **Turn on** asks the browser for permission and registers this browser as one of your [devices](../reference/notifications.md#devices). The panel then says that notifications are on for this device.
96
+
97
+ ## 5. See it arrive
98
+
99
+ Make yourself the owner of an order, then change its status, in the app or with SQL: both count, since the change is captured in the database. Within a few seconds:
100
+
101
+ - the browser shows a notification such as "Order SO-2024-000245 changed status", and a click on it opens the order;
102
+ - the bell shows one unread notification, and opening it marks it read.
103
+
104
+ Every send is a background job: a failed one is on the [failed jobs page](../reference/jobs.md#failed-jobs-page), and the server log has a line per delivery of the subscription.
105
+
106
+ On an iPhone or iPad, push reaches the app once it is added to the Home Screen, not a browser tab. Push to the Android and iOS builds of your app is coming soon; the [mobile guide](mobile-app.md) builds them.
107
+
108
+ ## 6. Turn the bell off or replace a part
109
+
110
+ - `notifications({ ui: false })` keeps sending, the history and devices, and draws no bell: your own UI reads the history and turns push on with [the browser helper](../reference/notifications.md#in-the-browser) ([without the bell](../reference/notifications.md#without-the-bell)).
111
+ - `shell.bell` in `protobase.ui.tsx` draws your own bell in its place ([the bell's slot](../reference/notifications.md#the-bells-slot)).
112
+ - Your own device store, history store or senders replace the built-in ones, such as a store outside the database ([your own parts](../reference/notifications.md#your-own-parts)).
113
+ - The tables' schema, names and columns can be renamed ([table names](../reference/notifications.md#table-names)).
@@ -506,7 +506,7 @@ For a project with [organizations](auth.md#organizations); `<organization>` is a
506
506
  protobase migration [--dir db/migrations] [--extend <dir>]
507
507
  ```
508
508
 
509
- Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when `protobase.config.ts` exports `auth` (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), and the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks()` (`NNN_webhooks.sql`). It compares the database, with the project's migrations applied, with the config, merged with the configs it extends and those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL` unless the config exports `db`.
509
+ Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when `protobase.config.ts` exports `auth` (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks()` or `notifications()`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks()` (`NNN_webhooks.sql`), and the [devices and history tables](notifications.md#table-names) of `notifications()` (`NNN_notifications.sql`). It compares the database, with the project's migrations applied, with the config, merged with the configs it extends and those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL` unless the config exports `db`.
510
510
 
511
511
  ```sh
512
512
  bun run db:migrate # the database at the project's current schema
@@ -268,6 +268,8 @@ export default defineUi({ shell: { actions: NotesButton, rightPanel: Notes } })
268
268
 
269
269
  When the app has an [assistant](assistant.md), its button follows the project's actions and its dock the project's panel.
270
270
 
271
+ `bell` replaces the [notification bell](notifications.md#the-bell) of the top bar with your own, drawn where it would be, and takes no props either; [the bell's slot](notifications.md#the-bells-slot) lists the hooks it reads the user's notifications with. With a bell from a plugin and one from the project, the project's shows.
272
+
271
273
  `logo` replaces Protobase's logo at the top of the sidebar with the app's own. It gets `compact`, true when the sidebar shows only icons, so it draws a mark alone, `workspace`, the name of the user's organization that Protobase's logo shows under it, `appName`, the app's [name](auth.md#configuration), which Protobase's logo shows beside its mark, and `appIcon`, the path of the project's own [icon](app-identity.md#the-icons) when it has one (`ShellLogoProps`). Its colors follow the [theme](theme.md), and a `dark:` class gives dark its own. When it throws, Protobase's logo shows instead. The tab's icon is [the favicon](theme.md#logo-and-favicon).
272
274
 
273
275
  ```tsx
@@ -22,6 +22,6 @@ Numbers, amounts and dates use the conventions of the language: English as writt
22
22
 
23
23
  ## What is translated
24
24
 
25
- Every built-in screen is translated: the shell with its sidebar, top bar, search, profile menu and bottom bar; the list page with all its displays (table, cards, board, calendar, timeline and map), filters, search, sort, imports and exports; the record page with its actions, related lists, history, comments, gallery, saving, conflicts and deleting; the create page and composed pages; saved searches and favorites; the sign-in, sign-up and two-factor screens, the account and sign-in policy pages, and the organization, people and invitation pages; public forms; and the messages, toasts and confirmations around them. So are counts, relative times ("5 minutes ago"), yes, no and the other values the app writes itself, and the notices shown while the app loads.
25
+ Every built-in screen is translated: the shell with its sidebar, top bar, search, notification bell, profile menu and bottom bar; the list page with all its displays (table, cards, board, calendar, timeline and map), filters, search, sort, imports and exports; the record page with its actions, related lists, history, comments, gallery, saving, conflicts and deleting; the create page and composed pages; saved searches and favorites; the sign-in, sign-up and two-factor screens, the account and sign-in policy pages, and the organization, people and invitation pages; public forms; and the messages, toasts and confirmations around them. So are counts, relative times ("5 minutes ago"), yes, no and the other values the app writes itself, and the notices shown while the app loads.
26
26
 
27
27
  The texts a plugin or the server writes itself, such as an error message the API sends back or why a plugin could not be loaded, show as they are written.
@@ -1,16 +1,16 @@
1
- <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/notifications.md: run `bun run docs:skill`, do not edit. -->
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/notifications.mdx: run `bun run docs:skill`, do not edit. -->
2
2
 
3
3
  # Notifications
4
4
 
5
- Turn on notifications, send them to users or devices, let each signed-in user register their browsers and phones and read their notification history, deliver to browsers with Web Push, and keep devices and history in Postgres or stores of your own.
5
+ Turn on notifications, send them to users or devices, show each signed-in user their inbox in the bell, let them register their browsers and phones, deliver to browsers with Web Push, and keep devices and history in Postgres or stores of your own.
6
6
 
7
7
  ## Turning them on
8
8
 
9
- :::caution[In development]
10
- Sending keeps notifications in the history and pushes them to browsers; push on Android and iOS and the bell are coming soon.
9
+ :::caution[Beta]
10
+ Push reaches browsers; push on Android and iOS is coming soon.
11
11
  :::
12
12
 
13
- Notifications tell a user about something in the app, in a bell in the top bar and as push on their devices. You turn them on in `protobase.config.ts`:
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
16
  import { defineConfig, notifications } from '@protobase/server'
@@ -23,7 +23,7 @@ export default defineConfig({
23
23
 
24
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.
25
25
 
26
- Browsers receive push through [Web Push](#web-push); the bell, and push on Android and iOS, are coming soon. `notifications({ ui: false })` keeps only the backend, without the bell.
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).
27
27
 
28
28
  ## Devices
29
29
 
@@ -71,11 +71,11 @@ The path comes from `devicesPath('/api', id)`, and the name of its id parameter
71
71
  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
72
  :::
73
73
 
74
- 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()`.
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()`.
75
75
 
76
76
  Every send to users says whether it shows in their inbox:
77
77
 
78
- - With `inbox: true` it is kept in each user's [history](#history), which the bell will show, and is pushed to their devices, such as a notice that the app has a new version.
78
+ - With `inbox: true` it is kept in each user's [history](#history), which [the bell](#the-bell) shows, and is pushed to their devices, such as a notice that the app has a new version.
79
79
  - With `inbox: false` it is only pushed, such as a chat message that links to its chat.
80
80
  - A send to devices, `{ deviceIds }`, is only pushed, and takes no inbox flag.
81
81
 
@@ -116,7 +116,7 @@ A user send reaches the user's devices as they are when the job runs. A device t
116
116
  ## History
117
117
 
118
118
  :::caution[Beta]
119
- The bell that shows the history is coming soon.
119
+ The [bell](#the-bell) lists the history only in its panel; there is no page of all notifications.
120
120
  :::
121
121
 
122
122
  The history is each user's inbox: every notification [sent](#sending) to a user with the inbox flag on is kept for them, and one sent without it is only pushed. Each signed-in user reaches only their own, through the API:
@@ -138,10 +138,34 @@ The same people may call them as may [register devices](#devices): only someone
138
138
 
139
139
  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
140
 
141
+ ## The bell
142
+
143
+ :::caution[Beta]
144
+ The bell lists notifications only in its panel; there is no page of all notifications.
145
+ :::
146
+
147
+ With notifications on, every signed-in user sees a bell in the top bar with how many of their notifications are unread. Its panel is their inbox: the newest notifications [sent](#sending) with the inbox flag on, never those sent without it, the unread ones in bold, each with how long ago it came. Opening one marks it read and goes to its page: in the app for your own pages, in a new tab for other sites. A notification without a `url` is not a link. "Mark all as read" marks those the panel shows read, and "Show more" brings older ones.
148
+
149
+ 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.
150
+
151
+ - 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.
152
+ - 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).
153
+ - The panel's text comes in the app's [language](languages.md).
154
+
155
+ ## Without the bell
156
+
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:
158
+
159
+ ```ts
160
+ export default defineConfig({ extends: [notifications({ ui: false })] })
161
+ ```
162
+
163
+ 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).
164
+
141
165
  ## Web Push
142
166
 
143
167
  :::caution[Beta]
144
- On iPhone and iPad, a browser tab gets no push; the app added to the Home Screen does. The ready-made button is coming soon with the bell.
168
+ On iPhone and iPad, a browser tab gets no push; the app added to the Home Screen does.
145
169
  :::
146
170
 
147
171
  Browsers receive push through the Web Push protocol: desktop and Android browsers, and web apps added to the home screen on iPhone. You generate a key pair with the CLI and set it, with a contact address, in three environment variables:
@@ -178,7 +202,7 @@ export const PushButton = () => {
178
202
  }
179
203
  ```
180
204
 
181
- - Call `turnOn` straight from a click. The browser asks for permission then, and only then: without a click nothing happens, and push is never turned on when a page loads. Once the user said no, `turnOn` does not ask again and answers `blocked`.
205
+ - Call `turnOn` straight from a click. The browser asks for permission then, and only then: without a click nothing happens, and push is never turned on when a page loads. Once the user said no, `turnOn` does not ask again and answers `blocked`. `state` is read again on a return to the page and when the browser says the permission changed, so it turns from `blocked` to `off` once the user allows notifications.
182
206
  - Only someone signed in as themselves can turn push on: a visitor's click and staff signed in as the user do nothing.
183
207
  - On iPhone and iPad, push works in the app added to the Home Screen; a browser tab answers `unsupported`.
184
208
  - 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.
@@ -188,8 +212,8 @@ export const PushButton = () => {
188
212
 
189
213
  ## Your own parts
190
214
 
191
- :::caution[In development]
192
- The device store, the history store and the senders can be replaced; the bell is coming soon.
215
+ :::caution[Beta]
216
+ The stores, the senders and the bell's slot may still change.
193
217
  :::
194
218
 
195
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:
@@ -275,12 +299,41 @@ A message is plain data:
275
299
 
276
300
  `pushMessage(message)` checks a message and answers it as senders get it, or throws a `PushMessageError` that names the field at fault, never its value. Every sender gets a checked message: a `url` with any other scheme, such as `javascript:` or `data:`, or a relative one, is refused, and so is a field that is not one of the message's, a key `__proto__`, `constructor` or `prototype` anywhere in it, or text with control characters. A sender for `web` devices names the VAPID `publicKey` browsers subscribe with, which `/meta` gives every caller; it must be a P-256 public key in base64url. Its JSON carries the device's `userId` as `user`, as the built-in sender's does: the service worker shows nothing of a push for another user, or for none.
277
301
 
278
- The bell is coming soon.
302
+ ### The bell's slot
303
+
304
+ `shell.bell` in `protobase.ui.tsx` draws your own bell in place of the built-in one, from the project or a plugin; with both, the project's. It is drawn where the built-in bell would be: with notifications on and `ui` not false, for someone signed in as themselves (see [Shell slots](custom-components.md#shell-slots)). It takes no props and uses these hooks from `@protobase/ui`:
305
+
306
+ | Hook | |
307
+ | --- | --- |
308
+ | `useUnreadNotifications()` | the unread count as `data`, at most 100, kept current as the bell's is |
309
+ | `useInbox({ enabled })` | the notifications loaded so far as `items`, newest first, `fetchNextPage` for older ones while `hasNextPage`; read only while `enabled` |
310
+ | `useMarkNotificationsRead()` | `markRead(item)` for one, and `markAllRead(newest)` for all up to the newest one shown; the count and the list show it at once |
311
+ | `usePushNotifications()` | push on this device, as [the browser helper](#in-the-browser) says |
312
+
313
+ ```tsx
314
+ import { defineUi, useInbox, useMarkNotificationsRead, useUnreadNotifications } from '@protobase/ui'
315
+ import { useState } from 'react'
316
+
317
+ const Bell = () => {
318
+ const [open, setOpen] = useState(false)
319
+ const unread = useUnreadNotifications()
320
+ const inbox = useInbox({ enabled: open })
321
+ const { markRead } = useMarkNotificationsRead()
322
+ return (
323
+ <div>
324
+ <button type="button" onClick={() => setOpen(!open)}>Inbox ({unread.data ?? 0})</button>
325
+ {open && inbox.items.map((item) => (item.url ? <a key={item.id} href={item.url} onClick={() => markRead(item)}>{item.title}</a> : <p key={item.id}>{item.title}</p>))}
326
+ </div>
327
+ )
328
+ }
329
+
330
+ export default defineUi({ shell: { bell: Bell } })
331
+ ```
279
332
 
280
333
  ## Table names
281
334
 
282
335
  :::caution[Beta]
283
- Both tables are written and checked; nothing writes to the history table until sending lands.
336
+ The names and the checks at startup may still change.
284
337
  :::
285
338
 
286
339
  The default store keeps devices in the table `devices` of the schema `notifications`: