@protobase/cli 0.45.17 → 0.45.19
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/dist/migration/parts.js +3 -3
- package/dist/users/load-auth.js +5 -4
- package/package.json +6 -6
- package/skills/protobase/references/features/notifications.md +3 -3
- package/skills/protobase/references/reference/jobs.md +1 -1
- package/skills/protobase/references/reference/notifications.md +123 -10
package/dist/cli/package.js
CHANGED
package/dist/migration/parts.js
CHANGED
|
@@ -11,7 +11,7 @@ const migrationParts = (project) => {
|
|
|
11
11
|
title: authMigrationTitle,
|
|
12
12
|
sql: () => authSchemaMigration(project.auth)
|
|
13
13
|
}] : [],
|
|
14
|
-
...project.jobs.length > 0 || project.models.some(isCaptured) || comments || aiFields || project.webhooks ? [{
|
|
14
|
+
...project.jobs.length > 0 || project.models.some(isCaptured) || comments || aiFields || project.webhooks || project.notifications ? [{
|
|
15
15
|
name: "jobs",
|
|
16
16
|
title: "The jobs schema this version of Protobase needs",
|
|
17
17
|
sql: () => jobsSchemaMigration(project.db)
|
|
@@ -41,9 +41,9 @@ const migrationParts = (project) => {
|
|
|
41
41
|
title: "The webhook subscriptions of webhooks()",
|
|
42
42
|
sql: () => webhooksMigration(project.db, project.webhooks, project.events)
|
|
43
43
|
}] : [],
|
|
44
|
-
...project.notifications && !project.notifications.store ? [{
|
|
44
|
+
...project.notifications && !(project.notifications.store && project.notifications.historyStore) ? [{
|
|
45
45
|
name: "notifications",
|
|
46
|
-
title: "The
|
|
46
|
+
title: "The tables of notifications()",
|
|
47
47
|
sql: () => notificationsMigration(project.db, project.notifications, project.auth)
|
|
48
48
|
}] : []
|
|
49
49
|
];
|
package/dist/users/load-auth.js
CHANGED
|
@@ -2,12 +2,12 @@ import { loadNearestEnvFile } from "../dev/env.js";
|
|
|
2
2
|
import { importProjectFile } from "../project/import-project-file.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { mergeConfig, removeDevicesWithUsers } from "@protobase/server";
|
|
5
|
+
import { mergeConfig, removeDevicesWithUsers, removeHistoryWithUsers } from "@protobase/server";
|
|
6
6
|
//#region src/users/load-auth.ts
|
|
7
7
|
/**
|
|
8
|
-
* Imports the project's protobase.config.ts directly and returns its Better Auth instance. With a device
|
|
9
|
-
* app's own (`notifications({ store })`), deleting a user removes their devices
|
|
10
|
-
* with the user by
|
|
8
|
+
* Imports the project's protobase.config.ts directly and returns its Better Auth instance. With a device or history
|
|
9
|
+
* store of the app's own (`notifications({ store, historyStore })`), deleting a user removes their devices or history
|
|
10
|
+
* from it too; the built-in tables go with the user by their foreign keys.
|
|
11
11
|
*/
|
|
12
12
|
const loadProjectAuth = async (projectDir) => {
|
|
13
13
|
loadNearestEnvFile(projectDir);
|
|
@@ -18,6 +18,7 @@ const loadProjectAuth = async (projectDir) => {
|
|
|
18
18
|
const { auth } = project;
|
|
19
19
|
if (!auth) throw new Error("protobase.config.ts does not export `auth`; users are managed by Better Auth");
|
|
20
20
|
if (project.notifications?.store) removeDevicesWithUsers(auth, project.notifications.store);
|
|
21
|
+
if (project.notifications?.historyStore) removeHistoryWithUsers(auth, project.notifications.historyStore);
|
|
21
22
|
return auth;
|
|
22
23
|
};
|
|
23
24
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.19",
|
|
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.19",
|
|
40
|
+
"@protobase/query": "0.45.19",
|
|
41
|
+
"@protobase/schema": "0.45.19",
|
|
42
|
+
"@protobase/server": "0.45.19",
|
|
43
|
+
"@protobase/ui": "0.45.19",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -7,9 +7,9 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
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) (in development): Each signed-in user registers their own browsers and phones to receive push, and a device moves to whoever registers it next.
|
|
9
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.
|
|
10
|
-
- [Table names](../reference/notifications.md#table-names) (
|
|
11
|
-
- Sending notifications (
|
|
12
|
-
- Notification history (
|
|
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
|
+
- [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
|
+
- [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) (in development): 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.
|
|
@@ -68,7 +68,7 @@ export default defineConfig({
|
|
|
68
68
|
| --- | --- |
|
|
69
69
|
| `name` | Letters, digits, `_`, `-`, `.` and `/`. Two jobs may not share a name. |
|
|
70
70
|
| `payload` | A [Standard Schema](https://standardschema.dev) such as a zod schema, checked when the job is enqueued and again before it runs. A payload it refuses at run time fails the job for good. |
|
|
71
|
-
| `run(payload, { db, job, signal, mail })` | The work. `db` is the app's pool: the enqueuer's transaction has committed by then. `job` holds its `id`, `name`, `attempt` and `
|
|
71
|
+
| `run(payload, { db, job, signal, mail, sendNotification })` | The work. `db` is the app's pool: the enqueuer's transaction has committed by then. `job` holds its `id`, `name`, `attempt`, `maxAttempts` and `startedOn`, when this try took it. `signal` aborts when the try times out or the worker shuts down. `mail` sends mail, see [Mail](#mail). `sendNotification` sends a notification, see [Sending](notifications.md#sending); inside a transaction of `db`, a try that throws in it queues nothing. |
|
|
72
72
|
| `maxAttempts` | Tries before the job is kept as failed; default 10. |
|
|
73
73
|
| `retryDelay`, `maxRetryDelay` | The wait before the first retry, doubling with each one (with some jitter), and its ceiling; default `2s` and `1 hour`. Milliseconds or text such as `30 seconds`. |
|
|
74
74
|
| `timeout` | How long one try may run before it counts as failed; default `15 minutes`. |
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# Notifications
|
|
4
4
|
|
|
5
|
-
Turn on notifications, let each signed-in user register their browsers and phones, deliver to browsers with Web Push, and keep
|
|
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.
|
|
6
6
|
|
|
7
7
|
## Turning them on
|
|
8
8
|
|
|
9
9
|
:::caution[In development]
|
|
10
|
-
|
|
10
|
+
Sending keeps notifications in the history and pushes them to browsers, but browsers cannot register for push yet: registering a browser, push on Android and iOS and the bell are 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`:
|
|
@@ -21,14 +21,14 @@ export default defineConfig({
|
|
|
21
21
|
})
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Then run `protobase migration`, which writes the [devices
|
|
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
|
The bell and push are coming soon. `notifications({ ui: false })` keeps only the backend, without the bell.
|
|
27
27
|
|
|
28
28
|
## Devices
|
|
29
29
|
|
|
30
30
|
:::caution[In development]
|
|
31
|
-
|
|
31
|
+
Only browsers receive push yet, through [Web Push](#web-push): push on Android and iOS is coming soon.
|
|
32
32
|
:::
|
|
33
33
|
|
|
34
34
|
A device is where a user receives push: a browser's push subscription, or an Android or iOS app's push token. Each signed-in user registers and removes only their own, through the API:
|
|
@@ -60,6 +60,79 @@ A device is one token, or one endpoint for a browser. Registering a device someo
|
|
|
60
60
|
|
|
61
61
|
The path comes from `devicesPath('/api', id)`, and the name of its id parameter from `deviceIdParam`, both exported by `@protobase/server`.
|
|
62
62
|
|
|
63
|
+
## Sending
|
|
64
|
+
|
|
65
|
+
:::caution[Beta]
|
|
66
|
+
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>
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
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()`.
|
|
70
|
+
|
|
71
|
+
Every send to users says whether it shows in their inbox:
|
|
72
|
+
|
|
73
|
+
- 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.
|
|
74
|
+
- With `inbox: false` it is only pushed, such as a chat message that links to its chat.
|
|
75
|
+
- A send to devices, `{ deviceIds }`, is only pushed, and takes no inbox flag.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { appPath } from '@protobase/schema'
|
|
79
|
+
import { sendNotification, subscription } from '@protobase/server'
|
|
80
|
+
|
|
81
|
+
// The app's public origin, from its own configuration.
|
|
82
|
+
const appOrigin = 'https://tasks.example.com'
|
|
83
|
+
|
|
84
|
+
/** Tells a task's owner when someone changes it. */
|
|
85
|
+
export const taskChanged = subscription('taskChanged', {
|
|
86
|
+
events: ['tasks.updated'],
|
|
87
|
+
run: async ({ data }, { db }) => {
|
|
88
|
+
const owner = data.after?.owner_id
|
|
89
|
+
if (owner == null) return
|
|
90
|
+
const url = new URL(appPath({ kind: 'record', resource: 'tasks', key: data.key }), appOrigin).href
|
|
91
|
+
await sendNotification(db, { userIds: [String(owner)], inbox: true }, { title: `${data.after?.title} changed`, url })
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The message is the one [senders](#senders) take. Its `url` opens on tap: a URL on your app's origin opens inside the app, and any other `http` or `https` URL opens outside it. Any other scheme, such as `javascript:` or `data:`, is refused. Build the URL on your app's configured origin, never on one a request names in `Host`, `X-Forwarded-Host`, `Origin` or its own URL, so nobody can make a notification lead to their site.
|
|
97
|
+
|
|
98
|
+
A send is checked before anything is queued, and a send that is not valid throws a `NotificationSendError` that names the field at fault, never its value. A valid send:
|
|
99
|
+
|
|
100
|
+
- names 1 to 1000 users or devices;
|
|
101
|
+
- has a user send's `inbox` as `true` or `false`;
|
|
102
|
+
- has a message of at most 16 KB as JSON, without a field that is not one of the message's;
|
|
103
|
+
- for the inbox, has a message the history keeps.
|
|
104
|
+
|
|
105
|
+
The text you send shows on lock screens, where anyone holding the device can read it, so keep anything the recipient may not see out of it. It stays in the jobs table until the send is delivered, and in a failed send until it is retried or deleted in the admin app.
|
|
106
|
+
|
|
107
|
+
A send checks no permission. A device send reaches the devices whatever user holds them. So check ids taken from a request against the caller first, such as a device id against the caller's own devices.
|
|
108
|
+
|
|
109
|
+
A user send reaches the user's devices as they are when the job runs. A device that moved to someone else, or was removed, gets nothing. A device stays its user's when a session ends, until it is [removed](#devices), and keeps receiving their notifications until then. When a push service reports a device gone, the device is removed. A device whose push service asks to try again later is tried once more, on the job's next try, and then given up on without being removed. <gap>A push service's own wait before a retry cannot set when the device is tried again because retries follow the job's backoff and timing them per device is not implemented.</gap> A sender that fails is retried with its devices, up to 5 tries of the job. Devices of a kind without a sender are skipped. Without any sender, a send for the inbox is kept in the history and a send that is not does nothing.
|
|
110
|
+
|
|
111
|
+
## History
|
|
112
|
+
|
|
113
|
+
:::caution[Beta]
|
|
114
|
+
The bell that shows the history is coming soon.
|
|
115
|
+
:::
|
|
116
|
+
|
|
117
|
+
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:
|
|
118
|
+
|
|
119
|
+
| Request | |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| `GET /api/notifications/history` | the caller's notifications, newest first: `{ items, next }` |
|
|
122
|
+
| `GET /api/notifications/history/unread` | how many are unread: `{ count }`, at most 100, so show `99+` from there |
|
|
123
|
+
| `POST /api/notifications/history/<id>/read` | marks the caller's notification with that id read; answers `204` whether or not the caller had it |
|
|
124
|
+
| `POST /api/notifications/history/read` | marks all read up to the newest one the caller was shown: `{ "upTo": "<its createdAt>" }`, then `204` |
|
|
125
|
+
|
|
126
|
+
Each item is `{ id, title, body, url, data, createdAt, readAt }`, with `readAt` `null` while unread. A notification read once keeps its first `readAt`, and marking all read leaves those read earlier as they were. Marking all read takes the `createdAt` of the newest notification the user saw, so one that arrives meanwhile stays unread.
|
|
127
|
+
|
|
128
|
+
The list gives 20 at a time, or as many as `?limit=` says, up to 50. A full page's `next` is a cursor: pass it as `?cursor=` for the page after it, until `next` is `null`. A limit or cursor out of its format, and a parameter or body field the request does not take, such as a user, is a `400` that changes nothing. Both marks take JSON (`Content-Type: application/json`): marking one takes an empty body or `{}`. Answers about the history are never cached.
|
|
129
|
+
|
|
130
|
+
`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.
|
|
131
|
+
|
|
132
|
+
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()`.
|
|
133
|
+
|
|
134
|
+
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`.
|
|
135
|
+
|
|
63
136
|
## Web Push
|
|
64
137
|
|
|
65
138
|
:::caution[In development]
|
|
@@ -82,12 +155,12 @@ Without them Web Push is off and the app has no sender for browsers. One or two
|
|
|
82
155
|
|
|
83
156
|
The private key is a secret: keep it out of client code, `VITE_` variables and the repository. Anyone holding it and the stored subscriptions can push to every subscribed browser. Browsers subscribe with the public key, which `/meta` gives every caller as `notifications.webPushKey`, so a new key pair breaks every subscription until its browser registers again.
|
|
84
157
|
|
|
85
|
-
Each message is encrypted for its browser and signed with the key. It goes only to an endpoint on one of the browsers' push services, never through a redirect
|
|
158
|
+
Each message is encrypted for its browser and signed with the key. It goes only to an endpoint on one of the browsers' push services, never through a redirect; a device stored with any other endpoint, or with keys that are not a subscription's, is `refused`. <gap>Web Push cannot deliver to a push service outside the browsers' own because adding one to the list is not implemented.</gap> A message's `platform.web` sets the request's `ttl`, `urgency` and `topic` and fields merged into the JSON the browser receives (`payload`), in place of those built from the message; every URL in that JSON is checked as the message's `url` is. The JSON carries at most 3993 bytes.
|
|
86
159
|
|
|
87
160
|
## Your own parts
|
|
88
161
|
|
|
89
162
|
:::caution[In development]
|
|
90
|
-
The device store and the senders can be replaced; the
|
|
163
|
+
The device store, the history store and the senders can be replaced; the bell is coming soon.
|
|
91
164
|
:::
|
|
92
165
|
|
|
93
166
|
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:
|
|
@@ -111,6 +184,25 @@ Every method takes and returns plain data: the user id as text, and devices as `
|
|
|
111
184
|
|
|
112
185
|
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()`.
|
|
113
186
|
|
|
187
|
+
The history store is an interface with a Postgres default too, the [history table](#table-names), and you pass your own as `historyStore`:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import { defineConfig, notifications, type HistoryStore } from '@protobase/server'
|
|
191
|
+
|
|
192
|
+
const historyStore: HistoryStore = {
|
|
193
|
+
record: async (userId, notification) => { /* keep it unread, created now, under a new id */ },
|
|
194
|
+
list: async (userId, { before, limit }) => [], // newest first, after `before`
|
|
195
|
+
countUnread: async (userId) => 0, // counting up to 100
|
|
196
|
+
markRead: async (userId, id) => false, // true when userId has it
|
|
197
|
+
markAllRead: async (userId, upTo) => {}, // the unread ones created up to `upTo`
|
|
198
|
+
removeAllForUser: async (userId) => {},
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default defineConfig({ extends: [notifications({ historyStore })] })
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
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)`.
|
|
205
|
+
|
|
114
206
|
### Senders
|
|
115
207
|
|
|
116
208
|
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:
|
|
@@ -133,6 +225,7 @@ export default defineConfig({ extends: [notifications({ senders: [sender] })] })
|
|
|
133
225
|
| `ok` | the push service took the message |
|
|
134
226
|
| `gone` | the device no longer exists there, and should be removed |
|
|
135
227
|
| `retry` | the push service may take it later; `retryAfterSeconds` says when, if the service does |
|
|
228
|
+
| `refused` | the sender never delivers to the device as it is stored, so it is neither retried nor removed |
|
|
136
229
|
|
|
137
230
|
A device with no answer, or an answer that is none of these, counts as `retry`, and answers for devices outside the batch are ignored. What a sender throws becomes an error that names only the sender's place in the list, since its own error may name devices.
|
|
138
231
|
|
|
@@ -153,12 +246,12 @@ A message is plain data:
|
|
|
153
246
|
|
|
154
247
|
`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.
|
|
155
248
|
|
|
156
|
-
The
|
|
249
|
+
The bell is coming soon.
|
|
157
250
|
|
|
158
251
|
## Table names
|
|
159
252
|
|
|
160
|
-
:::caution[
|
|
161
|
-
|
|
253
|
+
:::caution[Beta]
|
|
254
|
+
Both tables are written and checked; nothing writes to the history table until sending lands.
|
|
162
255
|
:::
|
|
163
256
|
|
|
164
257
|
The default store keeps devices in the table `devices` of the schema `notifications`:
|
|
@@ -184,4 +277,24 @@ notifications({
|
|
|
184
277
|
})
|
|
185
278
|
```
|
|
186
279
|
|
|
187
|
-
|
|
280
|
+
The history is kept in the table `history` of the same schema:
|
|
281
|
+
|
|
282
|
+
| Column | |
|
|
283
|
+
| --- | --- |
|
|
284
|
+
| `id` | `uuid`, the id the endpoints answer with |
|
|
285
|
+
| `user_id` | the user's id, as in the devices table; with Protobase's auth a foreign key to auth's users table, so a deleted user's history goes with them |
|
|
286
|
+
| `title`, `body` | the text it shows |
|
|
287
|
+
| `url` | where it leads |
|
|
288
|
+
| `data` | `jsonb`, the app's own |
|
|
289
|
+
| `created_at` | when it was kept |
|
|
290
|
+
| `read_at` | when its user read it, `NULL` while unread |
|
|
291
|
+
|
|
292
|
+
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`:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
notifications({
|
|
296
|
+
history: { table: 'inbox', columns: { user_id: 'owner_id', read_at: 'seen_at' } },
|
|
297
|
+
})
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
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`.
|