@protobase/cli 0.45.20 → 0.45.21
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.
- package/dist/cli/package.js +1 -1
- package/package.json +6 -6
- package/skills/protobase/references/features/notifications.md +2 -2
- package/skills/protobase/references/reference/custom-components.md +2 -0
- package/skills/protobase/references/reference/languages.md +1 -1
- package/skills/protobase/references/reference/notifications.md +64 -11
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.21",
|
|
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.
|
|
40
|
-
"@protobase/query": "0.45.
|
|
41
|
-
"@protobase/schema": "0.45.
|
|
42
|
-
"@protobase/server": "0.45.
|
|
43
|
-
"@protobase/ui": "0.45.
|
|
39
|
+
"@protobase/layout": "0.45.21",
|
|
40
|
+
"@protobase/query": "0.45.21",
|
|
41
|
+
"@protobase/schema": "0.45.21",
|
|
42
|
+
"@protobase/server": "0.45.21",
|
|
43
|
+
"@protobase/ui": "0.45.21",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -6,11 +6,11 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
6
6
|
|
|
7
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.
|
|
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) (
|
|
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 (
|
|
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.
|
|
@@ -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,13 +1,13 @@
|
|
|
1
|
-
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/notifications.
|
|
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,
|
|
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
9
|
:::caution[In development]
|
|
10
|
-
Sending keeps notifications in the history and pushes them to browsers; push on Android and iOS
|
|
10
|
+
Sending keeps notifications in the history, which the bell shows, and pushes them to browsers; push on Android and iOS is coming soon.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
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`:
|
|
@@ -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
|
-
|
|
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
|
|
|
@@ -75,7 +75,7 @@ You send a notification from your server code, such as a job, a hook, an event s
|
|
|
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
|
|
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
|
|
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.
|
|
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[
|
|
192
|
-
The
|
|
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,7 +299,36 @@ 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
|
|
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
|
|