@protobase/cli 0.90.1 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +1 -2
- package/dist/dev/entry.js +1 -2
- package/dist/main.js +0 -2
- package/dist/migration/load-project.js +1 -2
- package/dist/migration/parts.js +1 -6
- package/dist/project/project-admin.js +0 -1
- package/dist/serve/lifecycle.js +1 -2
- package/package.json +8 -8
- package/skills/protobase/references/features/notifications.md +0 -1
- package/skills/protobase/references/reference/blocks.md +2 -2
- package/skills/protobase/references/reference/cli.md +1 -11
- package/skills/protobase/references/reference/config/jobs-and-events.md +0 -11
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/derived.md +1 -1
- package/skills/protobase/references/reference/layouts.md +1 -1
- package/skills/protobase/references/reference/notifications.md +1 -36
- package/dist/push-relay/credentials.js +0 -26
- package/dist/push-relay/load-store.js +0 -19
- package/dist/push-relay/register.js +0 -15
package/dist/cli/package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { projectDerived, projectFiles, projectFunctions, projectJobs, projectNotifications, projectOptions, projectResources, projectWebhooks, projectWorkflows } from "./project-parts.js";
|
|
2
2
|
import { userTablesOn } from "./user-tables-config.js";
|
|
3
|
-
import { buildAppAuth, buildAuthenticator, checkCallsOptions,
|
|
3
|
+
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions, workflowPlugins } from "@protobase/server/internal";
|
|
4
4
|
//#region src/config/build-project.ts
|
|
5
5
|
/**
|
|
6
6
|
* The app's own mailer, the default export of its auth/mailer.ts: what sign-in and the jobs (`context.mail`) both send
|
|
@@ -86,7 +86,6 @@ const buildProject = async (config, database) => {
|
|
|
86
86
|
...config.realtime && { realtime: config.realtime },
|
|
87
87
|
...notifications && { notifications },
|
|
88
88
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
89
|
-
...config.pushRelay && { pushRelay: checkPushRelayOptions(config.pushRelay) },
|
|
90
89
|
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
91
90
|
...mailer && { mailer },
|
|
92
91
|
...config.mobile && { mobile: config.mobile },
|
package/dist/dev/entry.js
CHANGED
|
@@ -7,7 +7,7 @@ import { devRealtimePrune } from "./dev-prune.js";
|
|
|
7
7
|
import { devDatabase, loadDevConfig } from "./project.js";
|
|
8
8
|
import { withDevServiceWorker } from "./service-worker-route.js";
|
|
9
9
|
import { setMissing, supabaseEnv } from "./supabase-env.js";
|
|
10
|
-
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema,
|
|
10
|
+
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, hasUsers, relayed, sqlSends } from "@protobase/server";
|
|
11
11
|
import { upgradeWebSocket } from "@hono/node-server";
|
|
12
12
|
import { Hono } from "hono";
|
|
13
13
|
//#region src/dev/entry.ts
|
|
@@ -44,7 +44,6 @@ if (relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
|
44
44
|
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
45
45
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
46
46
|
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
47
|
-
if (project.pushRelay) await checkPushRelaySchema(db);
|
|
48
47
|
if (project.userTables) await checkUserTablesSchema(db);
|
|
49
48
|
setMissing(process.env, supabaseEnv({
|
|
50
49
|
url: process.env.PROTOBASE_DEV_URL,
|
package/dist/main.js
CHANGED
|
@@ -10,7 +10,6 @@ import { registerEncryption } from "./encryption/register.js";
|
|
|
10
10
|
import { registerMigration } from "./migration/register.js";
|
|
11
11
|
import { registerMobile } from "./mobile/register.js";
|
|
12
12
|
import { registerNotifications } from "./notifications/register.js";
|
|
13
|
-
import { registerPushRelay } from "./push-relay/register.js";
|
|
14
13
|
import { protobaseVersion } from "./version/version.js";
|
|
15
14
|
import { registerSkill } from "./skill/register.js";
|
|
16
15
|
import { registerImport } from "./supabase/register.js";
|
|
@@ -190,7 +189,6 @@ registerSkill(program);
|
|
|
190
189
|
registerImport(program);
|
|
191
190
|
registerMobile(program);
|
|
192
191
|
registerNotifications(program);
|
|
193
|
-
registerPushRelay(program);
|
|
194
192
|
const run = (argv) => program.parseAsync(argv).catch((error) => {
|
|
195
193
|
if (error instanceof ExitSignal) {
|
|
196
194
|
process.exitCode = error.code;
|
|
@@ -6,7 +6,7 @@ import { loadSourceConfig } from "../config/source-config.js";
|
|
|
6
6
|
import { openAppDatabase } from "../project/pg-db.js";
|
|
7
7
|
import pg from "pg";
|
|
8
8
|
import { assistantSettings, authStoreTables, configExports } from "@protobase/server";
|
|
9
|
-
import {
|
|
9
|
+
import { checkStatusOptions } from "@protobase/server/internal";
|
|
10
10
|
//#region src/migration/load-project.ts
|
|
11
11
|
/**
|
|
12
12
|
* The project in `dir` as `protobase dev` merges it, for what its database needs: protobase.config.ts, with the
|
|
@@ -45,7 +45,6 @@ const migrationProject = async (config, url) => {
|
|
|
45
45
|
...config.calls && { calls: config.calls },
|
|
46
46
|
...notifications && { notifications },
|
|
47
47
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
48
|
-
...config.pushRelay && { pushRelay: checkPushRelayOptions(config.pushRelay) },
|
|
49
48
|
jobs,
|
|
50
49
|
userTables: userTablesOn(config),
|
|
51
50
|
readOnlyQueries: assistantSettings(config.assistant, process.env)?.kind === "built-in",
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { authMigrationTitle } from "../auth/migration-file.js";
|
|
2
|
-
import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration,
|
|
2
|
+
import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } 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) => {
|
|
@@ -61,11 +61,6 @@ const migrationParts = (project) => {
|
|
|
61
61
|
title: "The statuses table of people's own status",
|
|
62
62
|
sql: () => statusMigration(project.db, project.status, project.auth)
|
|
63
63
|
}] : [],
|
|
64
|
-
...project.pushRelay ? [{
|
|
65
|
-
name: "push_relay",
|
|
66
|
-
title: "The push relay's device handles and workspace credentials",
|
|
67
|
-
sql: () => pushRelayMigration(project.db)
|
|
68
|
-
}] : [],
|
|
69
64
|
...project.calls ? [{
|
|
70
65
|
name: "calls",
|
|
71
66
|
title: "The calls on records, who is in them, whom they ring, their guests, and the signals between the processes serving the app",
|
|
@@ -36,7 +36,6 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
|
|
|
36
36
|
...project.realtime && { realtime: project.realtime },
|
|
37
37
|
...project.notifications && { notifications: project.notifications },
|
|
38
38
|
...project.status && { status: project.status },
|
|
39
|
-
...project.pushRelay && { pushRelay: project.pushRelay },
|
|
40
39
|
...project.calls && { calls: project.calls },
|
|
41
40
|
...project.mobile && { mobile: project.mobile },
|
|
42
41
|
...project.app && { app: project.app },
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -9,7 +9,7 @@ import { startCleanupTimer } from "./cleanup-timer.js";
|
|
|
9
9
|
import { closeSockets } from "./close-sockets.js";
|
|
10
10
|
import { servedRelease } from "./mobile-release.js";
|
|
11
11
|
import pg from "pg";
|
|
12
|
-
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkJobsSchema, checkNotificationsSchema,
|
|
12
|
+
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkDerived, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, createFileCleanup, relayed, sqlSends, startJobs } from "@protobase/server";
|
|
13
13
|
import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
|
|
14
14
|
//#region src/serve/lifecycle.ts
|
|
15
15
|
const listen = (server, port) => new Promise((resolve, reject) => {
|
|
@@ -50,7 +50,6 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
50
50
|
if (env.startupChecks && sqlSends(project.realtime)) await checkChannelSends(db);
|
|
51
51
|
if (env.startupChecks && project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
52
52
|
if (env.startupChecks && project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
53
|
-
if (env.startupChecks && project.pushRelay) await checkPushRelaySchema(db);
|
|
54
53
|
if (env.startupChecks && project.userTables) await checkUserTablesSchema(db);
|
|
55
54
|
const { admin, jobs: definitions } = await servedAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
56
55
|
if (env.startupChecks && definitions.length > 0) await checkJobsSchema(db);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.92.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.92.0",
|
|
47
|
+
"@protobase/layout": "0.92.0",
|
|
48
|
+
"@protobase/query": "0.92.0",
|
|
49
|
+
"@protobase/schema": "0.92.0",
|
|
50
|
+
"@protobase/server": "0.92.0",
|
|
51
|
+
"@protobase/ui": "0.92.0",
|
|
52
|
+
"@protobase/workflows": "0.92.0",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -14,6 +14,5 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
14
14
|
- [Push on Android](../reference/notifications.md#android) (beta): The server sends notifications to Android devices through Firebase Cloud Messaging with the service account key in `PROTOBASE_FCM_SERVICE_ACCOUNT`, and the mobile app receives them, set up by `protobase mobile` from a `google-services.json` in the project.
|
|
15
15
|
- [Push on iOS](../reference/notifications.md#ios) (in development): The server sends notifications to iPhone and iPad through the Apple Push Notification service with the APNs key in `PROTOBASE_APNS_KEY`, `PROTOBASE_APNS_KEY_ID` and `PROTOBASE_APNS_TEAM_ID`; the mobile app registering for them and receiving them on iOS is coming soon.
|
|
16
16
|
- [Push relay](../reference/notifications.md#push-relay) (beta): Send push notifications through a relay that holds the mobile app's push keys, so your app needs only its own relay credential.
|
|
17
|
-
- [Push relay service](../reference/notifications.md#push-relay-service) (beta): Run a relay that holds a mobile app's push keys and delivers each workspace's notifications only to the phones registered for that workspace.
|
|
18
17
|
- [Do not disturb](../reference/status.md#do-not-disturb) (beta): While someone is on do not disturb, sends push nothing to their devices and keep inbox notifications in the bell for later.
|
|
19
18
|
- [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.
|
|
@@ -407,7 +407,7 @@ A message resource marks its sender with [`.author()`](data-config.md#resource),
|
|
|
407
407
|
|
|
408
408
|
### Thread
|
|
409
409
|
|
|
410
|
-
The latest messages that match `filter`, oldest first, each under its sender's name and the time it was sent, with a line between days and a sender's next message that day drawn under the first. **Load earlier messages** at the top reads the ones before. The thread opens at the newest message and scrolls in a box of its own, so it follows what arrives while the reader is at the end and keeps their place when they scrolled back, until their own message arrives; new messages
|
|
410
|
+
The latest messages that match `filter`, oldest first, each under its sender's name and the time it was sent, with a line between days and a sender's next message that day drawn under the first. **Load earlier messages** at the top reads the ones before. The thread opens at the newest message and scrolls in a box of its own, so it follows what arrives while the reader is at the end and keeps their place when they scrolled back, until their own message arrives; new messages arrive by themselves only when the message resource is [`.live()`](live.md), otherwise when the page reads the thread again, and screen readers announce them politely. It is left out of the page of a user who cannot read its sender, time or text.
|
|
411
411
|
|
|
412
412
|
| Prop | |
|
|
413
413
|
| --- | --- |
|
|
@@ -428,7 +428,7 @@ A text box that grows with its text: Enter or the send button creates a record o
|
|
|
428
428
|
| --- | --- |
|
|
429
429
|
| `resource` | Where a message is created. Required. |
|
|
430
430
|
| `field` | The writable text field the message goes in. Required. |
|
|
431
|
-
| `values` | Sent with every message, such as the room or the parent record's key. |
|
|
431
|
+
| `values` | Sent with every message, such as the room or the parent record's key. Only writable fields: a read-only field, the [tenant](data-config.md#resource) or the author stops the server at startup, since the server sets those itself. Before 0.92 these were accepted; remove them from `values`. |
|
|
432
432
|
| `placeholder` | The box's text while empty. |
|
|
433
433
|
| `span` | Width in a grid. |
|
|
434
434
|
|
|
@@ -41,7 +41,7 @@ const { exitCode, stdout, stderr } = await runCommand(['doctor', '--env', 'DATAB
|
|
|
41
41
|
|
|
42
42
|
The serve runtime is bundled by `protobase build-serve` into one JavaScript file for Bun, so production needs neither `node_modules` nor the CLI (see [serve](#serve)).
|
|
43
43
|
|
|
44
|
-
`scaffold` and `doctor` read the database with `default_transaction_read_only = on`, so they can never write, and so does `dev`'s check of the connection. The commands that manage the app's data do write: `users`, `organizations`, `
|
|
44
|
+
`scaffold` and `doctor` read the database with `default_transaction_read_only = on`, so they can never write, and so does `dev`'s check of the connection. The commands that manage the app's data do write: `users`, `organizations`, `encryption apply`, `files cleanup` and `import supabase`.
|
|
45
45
|
|
|
46
46
|
## `scaffold`
|
|
47
47
|
|
|
@@ -548,16 +548,6 @@ protobase notifications vapid-keys
|
|
|
548
548
|
|
|
549
549
|
Prints a fresh key pair for [Web Push](notifications.md#web-push) as `PROTOBASE_VAPID_PUBLIC_KEY` and `PROTOBASE_VAPID_PRIVATE_KEY` lines to paste into the environment or `.env`, and says to set `PROTOBASE_VAPID_SUBJECT` too. It reads no project, writes no file and makes no request.
|
|
550
550
|
|
|
551
|
-
## `push-relay`
|
|
552
|
-
|
|
553
|
-
```sh
|
|
554
|
-
protobase push-relay add-credential <origin>
|
|
555
|
-
protobase push-relay list-credentials
|
|
556
|
-
protobase push-relay remove-credential <id>
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
Manages the workspace credentials of a [push relay](notifications.md#push-relay-service), over the project's `DATABASE_URL`; a project without `pushRelay` in its config is refused. `add-credential` takes the workspace's `https` origin, such as `https://app.example.com`, and prints a new credential bound to it, once, for the workspace's `PROTOBASE_PUSH_RELAY_CREDENTIAL`; the relay keeps only its hash, and its id goes to stderr. `list-credentials` prints each credential's id, origin and when it was added. `remove-credential` removes one by its id, after which its sends are refused.
|
|
560
|
-
|
|
561
551
|
## `users`
|
|
562
552
|
|
|
563
553
|
```sh
|
|
@@ -353,14 +353,3 @@ The schema of the statuses table.
|
|
|
353
353
|
```ts
|
|
354
354
|
export default defineConfig({ status: { schema: 'presence' } })
|
|
355
355
|
```
|
|
356
|
-
|
|
357
|
-
## pushRelay
|
|
358
|
-
|
|
359
|
-
- **Type:** `{ appId: string }`
|
|
360
|
-
- **Default:** off
|
|
361
|
-
|
|
362
|
-
Makes the app a push relay for the mobile app `appId`, with that app's APNs key or FCM service account: it delivers the notifications of the workspaces it holds credentials for, each only to the phones registered for that workspace. Its tables are written by `protobase migration`. See [Push relay service](../notifications.md#push-relay-service).
|
|
363
|
-
|
|
364
|
-
```ts
|
|
365
|
-
export default defineConfig({ pushRelay: { appId: 'com.example.app' } })
|
|
366
|
-
```
|
|
@@ -30,7 +30,7 @@ Each key is described with its type and default in the option pages:
|
|
|
30
30
|
| [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
|
|
31
31
|
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime`, `calls`, `userTables` |
|
|
32
32
|
| [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
|
|
33
|
-
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `workflows`, `notifications`, `status
|
|
33
|
+
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `workflows`, `notifications`, `status` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
35
35
|
|
|
36
36
|
## Config types
|
|
@@ -61,7 +61,7 @@ The function gets the record's key as its URL has it, and returns the value as J
|
|
|
61
61
|
|
|
62
62
|
Each query the function sends is parsed with Postgres's own parser, however it was built. For each table it reads, Protobase keeps the query's conditions on that table: comparisons of its columns with constants and parameters, `IN`, `= ANY`, `BETWEEN` and null tests, joined with `AND`, `OR` and `NOT`, with the conditions of inner joins, and of an outer join's `ON` for its optional side. The condition is the dependency, so a new row that comes to match is caught as well as a row that leaves it. A part it cannot work out, such as a function call or a column of another table, counts as matching every row: a query it cannot read at all reads the whole table. Nested queries, `WITH` queries and both sides of a `UNION` count too. An update counts only when it changes a column the query used.
|
|
63
63
|
|
|
64
|
-
A table that is no resource of `reads` or the record's own stops the run with an error naming it: add its resource to `reads`. `depends()`
|
|
64
|
+
A table that is no resource of `reads` or the record's own stops the run with an error naming it: add its resource to `reads`. List every resource the function reads there, those it names with `depends()` included: only their changes are captured, and `depends()` on any other stops the run too. `depends()` adds a dependency by hand to a listed resource and never stands in for `reads`; with `track: false`, the dependencies it names are the only ones, for a function whose queries say less than it knows.
|
|
65
65
|
|
|
66
66
|
## The clock
|
|
67
67
|
|
|
@@ -64,7 +64,7 @@ Behaviour comes from [named actions](#named-actions); React code from [custom co
|
|
|
64
64
|
|
|
65
65
|
## Data
|
|
66
66
|
|
|
67
|
-
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160 and `sort` AIP-132, exactly as the list API's `filter` and `order_by`, so a filter that works in the list's URL works here.
|
|
67
|
+
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160 and `sort` AIP-132, exactly as the list API's `filter` and `order_by`, so a filter that works in the list's URL works here. `Thread` takes no `sort`: it orders its messages by its `time` field, newest first.
|
|
68
68
|
|
|
69
69
|
A `RecordCard` (its first match) and each card of a `CardRow` hold a **record**. Inside one, `Field`, `Progress`, `Stat field`, `Show`, `Action` and `ModalForm mode="edit"` work on that record, and a `RecordCard`'s header `actions` do too. A field name may follow relations: `company_id.city` is the city of the record's company, fetched like the record page fetches it and cached.
|
|
70
70
|
|
|
@@ -261,7 +261,7 @@ Any other field is refused, such as `token`, `topic`, `webpush` or `click_action
|
|
|
261
261
|
## Push relay
|
|
262
262
|
|
|
263
263
|
:::caution[Beta]
|
|
264
|
-
|
|
264
|
+
Protobase Cloud provides the relay for the official Protobase app, which registers relay handles and is coming soon.
|
|
265
265
|
:::
|
|
266
266
|
|
|
267
267
|
An app can deliver mobile push through a relay instead of holding APNs or FCM keys itself. The relay holds the mobile app's push keys, and your app sends to it with a relay credential of its own. You set the relay's URL and your app's credential in two environment variables:
|
|
@@ -285,41 +285,6 @@ The relay answers a `2xx` with a result for each handle, `ok`, `gone`, `retry` o
|
|
|
285
285
|
|
|
286
286
|
`relaySender(readRelaySettings(process.env)!)` from `@protobase/server` is the built-in sender, to list beside [your own senders](#senders). `relaySendRequest` and `relaySendAnswer` check the request and answer shapes.
|
|
287
287
|
|
|
288
|
-
### Push relay service
|
|
289
|
-
|
|
290
|
-
:::caution[Beta]
|
|
291
|
-
Issuing credentials on Protobase Cloud, and the official app's native push, are coming soon.
|
|
292
|
-
:::
|
|
293
|
-
|
|
294
|
-
A Protobase app can be the relay itself: it holds a mobile app's APNs key and FCM service account, and delivers the notifications of many workspaces, each only to the phones that turned push on in that workspace. Turn it on with the mobile app's id, the bundle id or package its pushes go to:
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
// protobase.config.ts
|
|
298
|
-
export default defineConfig({ pushRelay: { appId: 'com.example.app' } })
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
It reads the app's push keys from the same variables as the [iOS](#ios) and [Android](#android) senders, `PROTOBASE_APNS_KEY`, `PROTOBASE_APNS_KEY_ID` and `PROTOBASE_APNS_TEAM_ID`, and `PROTOBASE_FCM_SERVICE_ACCOUNT`; with neither set, it does not start. [`protobase migration`](cli.md#migration) writes its tables, in the `push_relay` schema, and the server checks them at start. Its endpoints take no sign-in, under `/api/push-relay`, which is the URL workspaces set as `PROTOBASE_PUSH_RELAY_URL`, such as `https://relay.example.com/api/push-relay`.
|
|
302
|
-
|
|
303
|
-
A phone registers for one workspace with `POST /api/push-relay/register`, sending its own push token, never through page script:
|
|
304
|
-
|
|
305
|
-
```json
|
|
306
|
-
{ "kind": "apns", "token": "…", "environment": "production", "origin": "https://app.example.com" }
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
`kind` is `apns`, with the token in lowercase hex and its `environment`, `sandbox` or `production`, or `fcm`, with the FCM token and no environment. `origin` is the workspace's `https` origin, with no path. The answer is `{ "handle": "…" }`, the handle the workspace registers as the phone's [relay device](#push-relay). The same token and origin always get the same handle, and a phone that uses several workspaces gets a handle for each. One client address registers at most 30 times a minute, then gets a `429` with `Retry-After`. <gap>A handle no workspace sends to cannot be removed because expiring unused handles is not implemented.</gap>
|
|
310
|
-
|
|
311
|
-
Each workspace sends with a credential of its own, bound to its origin. You add one on the relay with [`protobase push-relay add-credential`](cli.md#push-relay), which prints it once; the relay keeps only its hash, and compares it in constant time.
|
|
312
|
-
|
|
313
|
-
A send, as [above](#push-relay), with a credential that is not one of the relay's is a `401`. Each handle is answered:
|
|
314
|
-
|
|
315
|
-
- `refused` when the relay does not know it, or it was registered for another workspace, so that a workspace's credential reaches only the phones registered for its own origin. A handle of a kind the relay has no key for is `refused` too.
|
|
316
|
-
- `gone`, once APNs or FCM reports its token gone: the relay forgets the handle, and the workspace removes its device. The same phone's handles for other workspaces stay until their own sends find the token gone.
|
|
317
|
-
- Otherwise what APNs or FCM answered, `ok`, `retry` or `refused`.
|
|
318
|
-
|
|
319
|
-
The relay writes the credential's origin into every notification, over anything the send held: `origin` in the APNs payload, beside `url` and `user`, and in FCM's data. The mobile app opens a notification in the workspace of that origin, so one workspace cannot make a notification open another.
|
|
320
|
-
|
|
321
|
-
A credential sends to at most 20,000 devices in each UTC clock hour, counting every handle of each send. A send that would go over is a `429` with a `Retry-After` until the next UTC hour, when the count starts again, and the workspace retries its devices.
|
|
322
|
-
|
|
323
288
|
## Your own parts
|
|
324
289
|
|
|
325
290
|
:::caution[Beta]
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { newCredential, workspaceOrigin } from "@protobase/server";
|
|
2
|
-
//#region src/push-relay/credentials.ts
|
|
3
|
-
/**
|
|
4
|
-
* Adds a credential bound to the workspace `origin`, keeping only its hash, and prints it once on `out`: the value the
|
|
5
|
-
* workspace sets as its relay credential. Its id, which removes it, goes to `note`.
|
|
6
|
-
*/
|
|
7
|
-
const addCredentialCommand = async (store, given, out, note) => {
|
|
8
|
-
const origin = workspaceOrigin(given);
|
|
9
|
-
if (!origin) throw new Error("The workspace origin is not an https origin, such as https://app.example.com, with no path");
|
|
10
|
-
const { text, stored } = newCredential(origin);
|
|
11
|
-
await store.addCredential(stored);
|
|
12
|
-
out(`${text}\n`);
|
|
13
|
-
note(`Credential ${stored.id} sends to the phones registered for ${origin}. Set it as the workspace's PROTOBASE_PUSH_RELAY_CREDENTIAL; it is not shown again.\n`);
|
|
14
|
-
};
|
|
15
|
-
/** Prints each credential's id, origin and creation time, never anything of its secret. */
|
|
16
|
-
const listCredentialsCommand = async (store, out) => {
|
|
17
|
-
for (const credential of await store.listCredentials()) out(`${credential.id} ${credential.origin} ${credential.createdAt.toISOString()}\n`);
|
|
18
|
-
};
|
|
19
|
-
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
20
|
-
/** Removes the credential `id`, after which its sends are refused; an unknown id is an error. */
|
|
21
|
-
const removeCredentialCommand = async (store, id, out) => {
|
|
22
|
-
if (!uuid.test(id) || !await store.removeCredential(id)) throw new Error(`There is no credential ${id}`);
|
|
23
|
-
out(`Removed credential ${id}\n`);
|
|
24
|
-
};
|
|
25
|
-
//#endregion
|
|
26
|
-
export { addCredentialCommand, listCredentialsCommand, removeCredentialCommand };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { loadNearestEnvFile } from "../dev/env.js";
|
|
2
|
-
import { loadSourceConfig } from "../config/source-config.js";
|
|
3
|
-
import { openAppDatabase } from "../project/pg-db.js";
|
|
4
|
-
import pg from "pg";
|
|
5
|
-
import { postgresRelayStore } from "@protobase/server";
|
|
6
|
-
//#region src/push-relay/load-store.ts
|
|
7
|
-
/** The relay store of the project in `projectDir`, over DATABASE_URL; refused when its config has no `pushRelay`. */
|
|
8
|
-
const loadRelayStore = async (projectDir) => {
|
|
9
|
-
loadNearestEnvFile(projectDir);
|
|
10
|
-
if (!(await loadSourceConfig(projectDir, { command: "tool" })).pushRelay) throw new Error("The project is no push relay: add pushRelay: { appId } to protobase.config.ts");
|
|
11
|
-
if (!process.env.DATABASE_URL) throw new Error("No database: set DATABASE_URL");
|
|
12
|
-
const database = openAppDatabase(pg, process.env.DATABASE_URL);
|
|
13
|
-
return {
|
|
14
|
-
store: postgresRelayStore(database.db),
|
|
15
|
-
close: () => database.db.destroy()
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
export { loadRelayStore };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/push-relay/register.ts
|
|
2
|
-
const out = (text) => void process.stdout.write(text);
|
|
3
|
-
const note = (text) => void process.stderr.write(text);
|
|
4
|
-
const withStore = async (work) => {
|
|
5
|
-
const { store, close } = await (await import("./load-store.js")).loadRelayStore(process.cwd());
|
|
6
|
-
await work(store).finally(close);
|
|
7
|
-
};
|
|
8
|
-
const registerPushRelay = (program) => {
|
|
9
|
-
const relay = program.command("push-relay").description("Manage the workspace credentials of the push relay in the current directory");
|
|
10
|
-
relay.command("add-credential").description("Add a credential bound to a workspace origin and print it once").argument("<origin>", "the workspace origin, such as https://app.example.com").action(async (origin) => withStore(async (store) => (await import("./credentials.js")).addCredentialCommand(store, origin, out, note)));
|
|
11
|
-
relay.command("list-credentials").description("List the credentials: id, origin and when each was added").action(async () => withStore(async (store) => (await import("./credentials.js")).listCredentialsCommand(store, out)));
|
|
12
|
-
relay.command("remove-credential").description("Remove a credential, so its sends are refused").argument("<id>").action(async (id) => withStore(async (store) => (await import("./credentials.js")).removeCredentialCommand(store, id, out)));
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
15
|
-
export { registerPushRelay };
|