@protobase/cli 0.45.13 → 0.45.15

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,7 +1,7 @@
1
1
  import { migrationText, nextMigrationName } from "./migration-file.js";
2
2
  import path from "node:path";
3
- import { mkdir, readdir, writeFile } from "node:fs/promises";
4
3
  import { authSchemaMigration } from "@protobase/server";
4
+ import { mkdir, readdir, writeFile } from "node:fs/promises";
5
5
  //#region src/auth/write-migration.ts
6
6
  /**
7
7
  * Writes the auth schema changes the database still needs as the next migration in `dir`, and returns its path;
@@ -1,8 +1,8 @@
1
1
  import { buildFavicon, faviconFile } from "./favicon.js";
2
2
  import { existsSync } from "node:fs";
3
3
  import path from "node:path";
4
- import { copyFile, readFile } from "node:fs/promises";
5
4
  import { pngIcons } from "@protobase/server";
5
+ import { copyFile, readFile } from "node:fs/promises";
6
6
  //#region src/build/app-icons.ts
7
7
  const pngSignature = Buffer.from([
8
8
  137,
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
- import { readFile } from "node:fs/promises";
3
2
  import { oauthWellKnownPaths, pngIcons } from "@protobase/server";
3
+ import { readFile } from "node:fs/promises";
4
4
  //#region src/bundle/manifest.ts
5
5
  const manifestFile = "protobase.bundle.json";
6
6
  const isApiPath = (api, pathname) => api.some((prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`));
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.45.13";
2
+ var version = "0.45.15";
3
3
  //#endregion
4
4
  export { version };
package/dist/dev/entry.js CHANGED
@@ -4,7 +4,7 @@ import { projectErrorReporter } from "../project/error-reporter.js";
4
4
  import { projectAdmin } from "../project/project-admin.js";
5
5
  import { loadProject, projectDb } from "./project.js";
6
6
  import { setMissing, supabaseEnv } from "./supabase-env.js";
7
- import { apiKeySettings, assistantSettings, authStoreTables, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkQueryRunner, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
7
+ import { apiKeySettings, assistantSettings, authStoreTables, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkNotificationsSchema, checkQueryRunner, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
8
8
  import { upgradeWebSocket } from "@hono/node-server";
9
9
  import { Hono } from "hono";
10
10
  //#region src/dev/entry.ts
@@ -29,6 +29,7 @@ checkAi({
29
29
  env: process.env
30
30
  });
31
31
  if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
32
+ if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
32
33
  setMissing(process.env, supabaseEnv({
33
34
  url: process.env.PROTOBASE_DEV_URL,
34
35
  databaseUrl: process.env.PROTOBASE_DATABASE_URL,
@@ -3,8 +3,8 @@ import { conventionConfig } from "../project/convention.js";
3
3
  import { sharedDb } from "./create-db.js";
4
4
  import { existsSync } from "node:fs";
5
5
  import path from "node:path";
6
- import { readdir } from "node:fs/promises";
7
6
  import { mergeConfig } from "@protobase/server";
7
+ import { readdir } from "node:fs/promises";
8
8
  //#region src/dev/project.ts
9
9
  const load = (file) => import(
10
10
  /* @vite-ignore */
@@ -38,6 +38,7 @@ const migrationProject = (project, url) => {
38
38
  ...project.auth && { auth: project.auth },
39
39
  ...project.events && { events: project.events },
40
40
  ...project.webhooks && { webhooks: project.webhooks },
41
+ ...project.notifications && { notifications: project.notifications },
41
42
  jobs: jobDefinitions(project.jobs ?? {}),
42
43
  readOnlyQueries: assistantSettings(project.options?.assistant, process.env)?.kind === "built-in",
43
44
  authTables: project.auth ? authStoreTables(project.auth) : [],
@@ -1,5 +1,5 @@
1
1
  import { authMigrationTitle } from "../auth/migration-file.js";
2
- import { authSchemaMigration, changesMigration, commentsMigration, computedMigration, isCaptured, jobsSchemaMigration, queryRunnerMigration, webhooksMigration } from "@protobase/server";
2
+ import { authSchemaMigration, changesMigration, commentsMigration, computedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, queryRunnerMigration, webhooksMigration } from "@protobase/server";
3
3
  //#region src/migration/parts.ts
4
4
  /** Every feature the project's config enables, in the order their files are written. */
5
5
  const migrationParts = (project) => {
@@ -40,6 +40,11 @@ const migrationParts = (project) => {
40
40
  name: "webhooks",
41
41
  title: "The webhook subscriptions of webhooks()",
42
42
  sql: () => webhooksMigration(project.db, project.webhooks, project.events)
43
+ }] : [],
44
+ ...project.notifications && !project.notifications.store ? [{
45
+ name: "notifications",
46
+ title: "The devices table of notifications()",
47
+ sql: () => notificationsMigration(project.db, project.notifications, project.auth)
43
48
  }] : []
44
49
  ];
45
50
  };
@@ -3,8 +3,8 @@ import { buildDeployBundle } from "../build/deploy-bundle.js";
3
3
  import { withApiOrigin } from "./api-origin-page.js";
4
4
  import { siteFiles } from "../serve/site-files.js";
5
5
  import path from "node:path";
6
- import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
7
6
  import { releaseManifest } from "@protobase/server";
7
+ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
8
8
  import { releaseManifestFile } from "@protobase/schema/internal";
9
9
  const writeReleaseManifest = async (web) => {
10
10
  const files = await Promise.all((await siteFiles({
@@ -1,8 +1,8 @@
1
1
  import { faviconFile, projectFavicon } from "../build/favicon.js";
2
2
  import { existsSync } from "node:fs";
3
3
  import path from "node:path";
4
- import { readFile } from "node:fs/promises";
5
4
  import { pngIcons } from "@protobase/server";
5
+ import { readFile } from "node:fs/promises";
6
6
  //#region src/project/favicon-link.ts
7
7
  /**
8
8
  * Links the project's favicon at `/protobase.favicon.svg` in the app's page, and its Apple touch icon at
@@ -25,6 +25,7 @@ const projectAdmin = (project, config, db, ui, reporter, upgradeWebSocket) => {
25
25
  ...project.events && { events: project.events },
26
26
  ...project.history && { history: project.history },
27
27
  ...project.webhooks && { webhooks: project.webhooks },
28
+ ...project.notifications && { notifications: project.notifications },
28
29
  ...project.mobile && { mobile: project.mobile },
29
30
  ...project.app && { app: project.app },
30
31
  ...ui?.icons && { icons: ui.icons },
@@ -7,7 +7,7 @@ import { createServeApp } from "./app.js";
7
7
  import { startCleanupTimer } from "./cleanup-timer.js";
8
8
  import { closeSockets } from "./close-sockets.js";
9
9
  import { servedRelease } from "./mobile-release.js";
10
- import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkQueryRunner, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
10
+ import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
11
11
  import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
12
12
  import pg from "pg";
13
13
  //#region src/serve/lifecycle.ts
@@ -37,6 +37,7 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
37
37
  env: process.env
38
38
  });
39
39
  if (env.startupChecks && project.webhooks) await checkWebhooksSchema(db, project.webhooks);
40
+ if (env.startupChecks && project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
40
41
  const { admin, jobs: definitions } = projectAdmin(project, project.config, db, ui, reporter, upgradeWebSocket);
41
42
  if (env.startupChecks && definitions.length > 0) await checkJobsSchema(db);
42
43
  const jobs = definitions.length > 0 ? await startJobs({
@@ -1,8 +1,8 @@
1
1
  import { nativeFingerprint } from "../mobile/fingerprint.js";
2
2
  import { withApiOrigin } from "../mobile/api-origin-page.js";
3
3
  import { siteFiles } from "./site-files.js";
4
- import { readFile } from "node:fs/promises";
5
4
  import { composeRelease } from "@protobase/server";
5
+ import { readFile } from "node:fs/promises";
6
6
  //#region src/serve/mobile-release.ts
7
7
  const loopback = [
8
8
  "localhost",
@@ -17,8 +17,8 @@ import { ensureApiRoles, existingSchemas, existingTables } from "./target-checks
17
17
  import { creatableExtensions } from "./target-extensions.js";
18
18
  import { usersColumnsMigration } from "./users-migrations.js";
19
19
  import path from "node:path";
20
- import { mkdir, readFile, rm } from "node:fs/promises";
21
20
  import { isSchedule } from "@protobase/server";
21
+ import { mkdir, readFile, rm } from "node:fs/promises";
22
22
  import postgres from "postgres";
23
23
  //#region src/supabase/dump-phase.ts
24
24
  /** Fails unless the database at `sql` is Supabase's: its auth and storage schemas, and its own admin role. */
@@ -9,8 +9,8 @@ import { storageObjects } from "./storage-objects.js";
9
9
  import { bucketLines, megabytes, objectCount, overQuota, totalBytes } from "./storage-sizes.js";
10
10
  import { storageReport } from "./storage-report.js";
11
11
  import path from "node:path";
12
- import { writeFile } from "node:fs/promises";
13
12
  import { objectKey, storageProvider, storeUsage } from "@protobase/server";
13
+ import { writeFile } from "node:fs/promises";
14
14
  //#region src/supabase/storage-phase.ts
15
15
  /** Objects copied at once: enough to keep a connection busy, few enough for any host. */
16
16
  const parallel = 4;
@@ -2,13 +2,22 @@ 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
6
  //#region src/users/load-auth.ts
7
+ /**
8
+ * Imports the project's protobase.config.ts directly and returns its Better Auth instance. With a device store of the
9
+ * app's own (`notifications({ store })`), deleting a user removes their devices from it too; the devices table goes
10
+ * with the user by its foreign key.
11
+ */
6
12
  const loadProjectAuth = async (projectDir) => {
7
13
  loadNearestEnvFile(projectDir);
8
14
  const file = path.join(projectDir, "protobase.config.ts");
9
15
  if (!existsSync(file)) throw new Error(`No protobase.config.ts in ${projectDir}; run this inside a project`);
10
- const auth = (await importProjectFile(file)).default?.auth;
16
+ const module = await importProjectFile(file);
17
+ const project = mergeConfig(module.default ?? {});
18
+ const { auth } = project;
11
19
  if (!auth) throw new Error("protobase.config.ts does not export `auth`; users are managed by Better Auth");
20
+ if (project.notifications?.store) removeDevicesWithUsers(auth, project.notifications.store);
12
21
  return auth;
13
22
  };
14
23
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.45.13",
3
+ "version": "0.45.15",
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.13",
40
- "@protobase/query": "0.45.13",
41
- "@protobase/schema": "0.45.13",
42
- "@protobase/server": "0.45.13",
43
- "@protobase/ui": "0.45.13",
39
+ "@protobase/layout": "0.45.15",
40
+ "@protobase/query": "0.45.15",
41
+ "@protobase/schema": "0.45.15",
42
+ "@protobase/server": "0.45.15",
43
+ "@protobase/ui": "0.45.15",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -77,6 +77,7 @@ Reference:
77
77
  - When letting people without an account create records → read [Public forms](references/reference/forms.md)
78
78
  - When running background jobs → read [Jobs](references/reference/jobs.md)
79
79
  - When sending email → read [Email](references/reference/email.md)
80
+ - When registering users' devices for push notifications → read [Notifications](references/reference/notifications.md)
80
81
  - When setting roles, capabilities and row filters → read [Access](references/reference/access.md)
81
82
  - When configuring sign-in, tokens and the auth schema → read [Login with Better Auth](references/reference/auth.md)
82
83
  - When using the typed client and hooks → read [Client and live UI](references/reference/client.md)
@@ -0,0 +1,16 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/features/notifications.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Notifications
4
+
5
+ A bell in the top bar and push to browsers and phones, for what your app tells its users.
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.
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
+ - [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) (in development): The built-in stores' schema, tables and columns can be renamed, as auth's users table can.
11
+ - Sending notifications (coming soon): Your code tells a user, or several, about something in the app, and each gets it in the bell and on their devices.
12
+ - Notification history (coming soon): Every notification a user got is kept, read or unread, for the bell to list.
13
+ - Web Push (coming soon): Notifications reach the browsers a user registered, also while the app is closed.
14
+ - Push on Android (coming soon): Notifications reach the Android build of the app on a user's phones.
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.
@@ -9,7 +9,7 @@ Sign-in methods, users, roles, organizations and tokens.
9
9
  - [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
10
10
  - [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
11
11
  - [Password reset](../reference/auth.md#password-reset): People reset a forgotten password through an emailed link.
12
- - [Emailed sign-in codes](../reference/auth.md#emailed-sign-in-codes): People sign in with a code sent to their email.
12
+ - [Emailed sign-in codes](../reference/auth.md#emailed-sign-in-codes): People sign in with a code sent to their email. An address with no account is emailed that it has none, so the person tries the one they signed up with.
13
13
  - [Open sign-up](../reference/auth.md#open-sign-up): Anyone can create an account after confirming an emailed code.
14
14
  - [Passkeys](../reference/auth.md#passkeys): People sign in with their device's face or fingerprint unlock, or with a security key.
15
15
  - [Two-factor authentication](../reference/auth.md#two-factor-authentication): A second step with an authenticator app, backup codes or emailed codes.
@@ -31,6 +31,7 @@ A feature without a mark is stable. The others say so after their name:
31
31
  - [Files and images](features/files-and-images.md): Uploaded files and images, where they are kept and how they are served.
32
32
  - [History, comments and live updates](features/history-comments-and-live-updates.md): The changes of each record, comments on it, and pages that refresh as records change.
33
33
  - [Events, webhooks and jobs](features/events-webhooks-and-jobs.md): React to changes, deliver them to other systems, and run work in the background.
34
+ - [Notifications](features/notifications.md): A bell in the top bar and push to browsers and phones, for what your app tells its users.
34
35
  - [Email and public forms](features/email-and-public-forms.md): Mail the app sends, and forms for people without an account.
35
36
  - [AI](features/ai.md): Fields and actions filled by a model, the assistant beside the admin, and MCP.
36
37
  - [Compatibility and moving from other systems](features/compatibility.md): Apps written for other systems that keep working on Protobase, and moving their data and code over.
@@ -168,7 +168,7 @@ createAuth({ ..., mailer: false })
168
168
  With mail configured, the sign-in page offers "Email me a sign-in code": the person enters their address, gets a 6-digit code, and signs in with it instead of a password. It is Better Auth's [email OTP](https://www.better-auth.com/docs/plugins/email-otp) plugin: `POST /api/auth/email-otp/send-verification-otp` with `{ email, type: "sign-in" }`, then `POST /api/auth/sign-in/email-otp` with `{ email, otp }`.
169
169
 
170
170
  - A code works for 5 minutes, once, and three wrong tries end it; asking again sends a new one and the old one stops working. Codes are stored hashed.
171
- - It never creates an account: an unknown address gets no mail, and the answer is the same either way.
171
+ - It never creates an account: an address no account uses gets no code but an email saying so, which suggests signing in with the address the person signed up with. The answer is the same either way, so it does not tell who has an account.
172
172
  - Only sign-in codes are mailed. The plugin's own email verification, password reset and address change endpoints are off (`404`), and asking for another type of code answers `400`.
173
173
  - An account with [two-factor authentication](#two-factor-authentication) is asked for its second step after the code too, as after a password.
174
174
  - An account created by Protobase 0.3 or earlier, which has a password, is marked verified the first time it uses a code. Otherwise Better Auth would treat the code as taking over an unverified account and delete its password.
@@ -0,0 +1,121 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/notifications.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Notifications
4
+
5
+ Turn on notifications, let each signed-in user register their browsers and phones, and keep the devices in Postgres or a store of your own.
6
+
7
+ ## Turning them on
8
+
9
+ :::caution[In development]
10
+ Nothing sends notifications yet: sending, the history, Web Push, push on Android and iOS and the bell are coming soon.
11
+ :::
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`:
14
+
15
+ ```ts
16
+ import { defineConfig, notifications } from '@protobase/server'
17
+
18
+ export default defineConfig({
19
+ extends: [notifications()],
20
+ // config, auth, ...
21
+ })
22
+ ```
23
+
24
+ Then run `protobase migration`, which writes the [devices table](#table-names) 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 the table is missing or lacks what notifications need, and name it. Without `notifications()` there is none of it: no endpoints, no table and no migration.
25
+
26
+ The bell and push are coming soon. `notifications({ ui: false })` keeps only the backend, without the bell.
27
+
28
+ ## Devices
29
+
30
+ :::caution[In development]
31
+ A registered device receives nothing yet: Web Push and push on Android and iOS are coming soon.
32
+ :::
33
+
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:
35
+
36
+ | Request | |
37
+ | --- | --- |
38
+ | `POST /api/notifications/devices` | registers the device the request comes from, or refreshes it; answers `{ id, kind, createdAt, lastSeenAt }` |
39
+ | `DELETE /api/notifications/devices/<id>` | removes the caller's device with that id; answers `204` whether or not the caller had it |
40
+
41
+ The body of a register is JSON (`Content-Type: application/json`, at most 8 KB), in one of three shapes:
42
+
43
+ ```jsonc
44
+ // A browser: its PushSubscription as JSON
45
+ { "kind": "web", "endpoint": "https://…", "keys": { "p256dh": "…", "auth": "…" }, "userAgent": "…" }
46
+ // An iOS app: its token in lowercase hex, the build's environment and bundle id
47
+ { "kind": "apns", "token": "…", "environment": "production", "appId": "net.example.app" }
48
+ // An Android app: its token, and optionally its package name
49
+ { "kind": "fcm", "token": "…", "appId": "net.example.app" }
50
+ ```
51
+
52
+ A field that does not belong to the kind, a missing one, an unknown one such as a user id, or a value out of its format is a `400` that names the field and stores nothing. A browser's `endpoint` must be an https URL on one of the browsers' push services. `environment` is `sandbox` or `production`, and `userAgent`, optional for every kind, is at most 512 characters. The stored device keeps `null` in the fields its kind does not have.
53
+
54
+ Who may call them:
55
+
56
+ - Only someone signed in as themselves, with the token of their own sign-in. Visitors are refused with a `401`, and staff signed in as the user, outside apps acting for the user (such as an MCP client) and tokens minted with `issueToken` with a `403`.
57
+ - An app with its own `authenticate` marks a user's own sign-in on the session it returns, `signIn: { staff: false }`; without that mark, its sessions are refused.
58
+
59
+ A device is one token, or one endpoint for a browser. Registering a device someone else had moves it to the caller, as a new device with a new id that keeps nothing of the previous user's, so a shared phone or browser notifies whoever signed in on it last. A user keeps up to 20 devices: registering one more removes their least recently seen. Deleting a user removes their devices. <gap>Signing out cannot remove the session's devices because removing devices when a session ends is not implemented.</gap> Remove the device with `DELETE` before signing out.
60
+
61
+ The path comes from `devicesPath('/api', id)`, and the name of its id parameter from `deviceIdParam`, both exported by `@protobase/server`.
62
+
63
+ ## Your own parts
64
+
65
+ :::caution[In development]
66
+ Only the device store can be replaced yet: senders, the history store and the bell are coming soon.
67
+ :::
68
+
69
+ 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:
70
+
71
+ ```ts
72
+ import { defineConfig, notifications, type DeviceStore } from '@protobase/server'
73
+
74
+ const store: DeviceStore = {
75
+ register: async (userId, device) => { /* add, refresh, or move the token to userId as a new device */ },
76
+ remove: async (userId, id) => { /* only when the device is userId's */ },
77
+ listForUser: async (userId) => [],
78
+ listByIds: async (ids) => [],
79
+ removeGone: async (tokens) => {},
80
+ removeAllForUser: async (userId) => {},
81
+ }
82
+
83
+ export default defineConfig({ extends: [notifications({ store })] })
84
+ ```
85
+
86
+ Every method takes and returns plain data: the user id as text, and devices as `{ id, userId, kind, token, p256dh, auth, environment, appId, userAgent, createdAt, lastSeenAt }`, with `token` the endpoint for a browser. 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.
87
+
88
+ 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()`.
89
+
90
+ Senders, the history store and the bell are coming soon.
91
+
92
+ ## Table names
93
+
94
+ :::caution[In development]
95
+ Only the devices table exists yet: the history table comes with the notification history.
96
+ :::
97
+
98
+ The default store keeps devices in the table `devices` of the schema `notifications`:
99
+
100
+ | Column | |
101
+ | --- | --- |
102
+ | `id` | `uuid`, the id the endpoints answer with |
103
+ | `user_id` | the user's id, of the same type as auth's users table's `id`; with Protobase's auth a foreign key to that table, so a deleted user's devices go with them |
104
+ | `kind` | `web`, `apns` or `fcm` |
105
+ | `token` | the token, or a browser's endpoint; unique |
106
+ | `p256dh`, `auth` | a browser's keys |
107
+ | `environment` | an iOS app's `sandbox` or `production` |
108
+ | `app_id` | the app's bundle id or package name |
109
+ | `user_agent` | what the device said it is |
110
+ | `created_at`, `last_seen_at` | when the user registered it, and last refreshed it |
111
+
112
+ 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:
113
+
114
+ ```ts
115
+ notifications({
116
+ schema: 'push',
117
+ devices: { table: 'targets', columns: { user_id: 'owner_id', token: 'address' } },
118
+ })
119
+ ```
120
+
121
+ A name is lowercase letters, digits and `_`, at most 63 characters. Startup stops, naming what is wrong, while the table lacks a configured column, a unique index on the token column alone, which moving a device relies on, or, with Protobase's auth, the foreign key from the user column to the users table with `on delete cascade`.