@protobase/cli 0.81.0 → 0.81.1
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 +2 -1
- package/dist/dev/entry.js +2 -1
- package/dist/main.js +2 -0
- package/dist/migration/load-project.js +2 -1
- package/dist/migration/parts.js +6 -1
- package/dist/project/project-admin.js +1 -0
- package/dist/push-relay/credentials.js +26 -0
- package/dist/push-relay/load-store.js +19 -0
- package/dist/push-relay/register.js +15 -0
- package/dist/serve/lifecycle.js +2 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/build-and-run.md +1 -0
- package/skills/protobase/references/features/notifications.md +1 -0
- package/skills/protobase/references/guides/mobile-app.md +8 -0
- package/skills/protobase/references/reference/cli.md +11 -1
- package/skills/protobase/references/reference/config/jobs-and-events.md +11 -0
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/notifications.md +37 -2
package/dist/cli/package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { 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, checkStatusOptions, workflowPlugins } from "@protobase/server/internal";
|
|
3
|
+
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkPushRelayOptions, 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
|
|
@@ -84,6 +84,7 @@ const buildProject = async (config, database) => {
|
|
|
84
84
|
...config.realtime && { realtime: config.realtime },
|
|
85
85
|
...notifications && { notifications },
|
|
86
86
|
...config.status && { status: checkStatusOptions(config.status) },
|
|
87
|
+
...config.pushRelay && { pushRelay: checkPushRelayOptions(config.pushRelay) },
|
|
87
88
|
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
88
89
|
...mailer && { mailer },
|
|
89
90
|
...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, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, hasUsers, relayed, sqlSends } from "@protobase/server";
|
|
10
|
+
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkNotificationsSchema, checkPushRelaySchema, 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
|
|
@@ -43,6 +43,7 @@ if (relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
|
43
43
|
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
44
44
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
45
45
|
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
46
|
+
if (project.pushRelay) await checkPushRelaySchema(db);
|
|
46
47
|
if (project.userTables) await checkUserTablesSchema(db);
|
|
47
48
|
setMissing(process.env, supabaseEnv({
|
|
48
49
|
url: process.env.PROTOBASE_DEV_URL,
|
package/dist/main.js
CHANGED
|
@@ -10,6 +10,7 @@ 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";
|
|
13
14
|
import { protobaseVersion } from "./version/version.js";
|
|
14
15
|
import { registerSkill } from "./skill/register.js";
|
|
15
16
|
import { registerImport } from "./supabase/register.js";
|
|
@@ -189,6 +190,7 @@ registerSkill(program);
|
|
|
189
190
|
registerImport(program);
|
|
190
191
|
registerMobile(program);
|
|
191
192
|
registerNotifications(program);
|
|
193
|
+
registerPushRelay(program);
|
|
192
194
|
const run = (argv) => program.parseAsync(argv).catch((error) => {
|
|
193
195
|
if (error instanceof ExitSignal) {
|
|
194
196
|
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 { checkStatusOptions } from "@protobase/server/internal";
|
|
9
|
+
import { checkPushRelayOptions, 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,6 +45,7 @@ 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) },
|
|
48
49
|
jobs,
|
|
49
50
|
userTables: userTablesOn(config),
|
|
50
51
|
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, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
|
|
2
|
+
import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, pushRelayMigration, 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) => {
|
|
@@ -56,6 +56,11 @@ const migrationParts = (project) => {
|
|
|
56
56
|
title: "The statuses table of people's own status",
|
|
57
57
|
sql: () => statusMigration(project.db, project.status, project.auth)
|
|
58
58
|
}] : [],
|
|
59
|
+
...project.pushRelay ? [{
|
|
60
|
+
name: "push_relay",
|
|
61
|
+
title: "The push relay's device handles and workspace credentials",
|
|
62
|
+
sql: () => pushRelayMigration(project.db)
|
|
63
|
+
}] : [],
|
|
59
64
|
...project.calls ? [{
|
|
60
65
|
name: "calls",
|
|
61
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,6 +36,7 @@ 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 },
|
|
39
40
|
...project.calls && { calls: project.calls },
|
|
40
41
|
...project.mobile && { mobile: project.mobile },
|
|
41
42
|
...project.app && { app: project.app },
|
|
@@ -0,0 +1,26 @@
|
|
|
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 };
|
|
@@ -0,0 +1,19 @@
|
|
|
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 };
|
|
@@ -0,0 +1,15 @@
|
|
|
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 };
|
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, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkUserTablesSchema, checkWebhooksSchema, checkWorkflowsSchema, configExports, createFileCleanup, relayed, sqlSends, startJobs } from "@protobase/server";
|
|
12
|
+
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkCalls, checkChanges, checkChannelSends, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkPushRelaySchema, 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) => {
|
|
@@ -49,6 +49,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
49
49
|
if (env.startupChecks && sqlSends(project.realtime)) await checkChannelSends(db);
|
|
50
50
|
if (env.startupChecks && project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
51
51
|
if (env.startupChecks && project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
52
|
+
if (env.startupChecks && project.pushRelay) await checkPushRelaySchema(db);
|
|
52
53
|
if (env.startupChecks && project.userTables) await checkUserTablesSchema(db);
|
|
53
54
|
const { admin, jobs: definitions } = await servedAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
54
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.81.
|
|
3
|
+
"version": "0.81.1",
|
|
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.81.
|
|
47
|
-
"@protobase/layout": "0.81.
|
|
48
|
-
"@protobase/query": "0.81.
|
|
49
|
-
"@protobase/schema": "0.81.
|
|
50
|
-
"@protobase/server": "0.81.
|
|
51
|
-
"@protobase/ui": "0.81.
|
|
52
|
-
"@protobase/workflows": "0.81.
|
|
46
|
+
"@protobase/config": "0.81.1",
|
|
47
|
+
"@protobase/layout": "0.81.1",
|
|
48
|
+
"@protobase/query": "0.81.1",
|
|
49
|
+
"@protobase/schema": "0.81.1",
|
|
50
|
+
"@protobase/server": "0.81.1",
|
|
51
|
+
"@protobase/ui": "0.81.1",
|
|
52
|
+
"@protobase/workflows": "0.81.1",
|
|
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",
|
|
@@ -27,5 +27,6 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
27
27
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
28
28
|
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
29
29
|
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
|
|
30
|
+
- [Files from the phone](../guides/mobile-app.md#files-from-the-phone) (beta): In the iOS and Android app, Import and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives.
|
|
30
31
|
- [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
|
|
31
32
|
- [Live updates](../reference/cli.md#the-live-updater) (in development): The Android and iOS app update themselves in the background to the server's release, downloading only the files that changed, and go back to the files they were built with when a release fails to start.
|
|
@@ -14,5 +14,6 @@ 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.
|
|
17
18
|
- [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.
|
|
18
19
|
- [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.
|
|
@@ -73,6 +73,14 @@ protobase mobile run ios --team ABCDE12345
|
|
|
73
73
|
|
|
74
74
|
Every run signs the app for development with that team, letting Xcode create the profile and register the phone, and installs it on the connected iPhone, or on `--target` when several are connected. The first time, trust your developer certificate on the phone in Settings, General, VPN & Device Management. A free team signs only an `appId` no one else has taken.
|
|
75
75
|
|
|
76
|
+
### Files from the phone
|
|
77
|
+
|
|
78
|
+
:::caution[Beta]
|
|
79
|
+
<gap>In the iOS app, Import cannot read a workbook of 150,000 rows or more because reading one without crashing the app's page is not implemented.</gap>
|
|
80
|
+
:::
|
|
81
|
+
|
|
82
|
+
In the iOS and Android app, [Import](import-records.md) and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives, with nothing to set up. On Android, a CSV that a drive labels as another type, or as a file of no known type, can be picked too; Import reads a file by its name. On the iOS Simulator a workbook of 100,000 rows reads in about 8 seconds.
|
|
83
|
+
|
|
76
84
|
## 4. Live reload
|
|
77
85
|
|
|
78
86
|
```sh
|
|
@@ -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`, `encryption apply`, `files cleanup` and `import supabase`.
|
|
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`, `push-relay`, `encryption apply`, `files cleanup` and `import supabase`.
|
|
45
45
|
|
|
46
46
|
## `scaffold`
|
|
47
47
|
|
|
@@ -548,6 +548,16 @@ 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
|
+
|
|
551
561
|
## `users`
|
|
552
562
|
|
|
553
563
|
```sh
|
|
@@ -342,3 +342,14 @@ The schema of the statuses table.
|
|
|
342
342
|
```ts
|
|
343
343
|
export default defineConfig({ status: { schema: 'presence' } })
|
|
344
344
|
```
|
|
345
|
+
|
|
346
|
+
## pushRelay
|
|
347
|
+
|
|
348
|
+
- **Type:** `{ appId: string }`
|
|
349
|
+
- **Default:** off
|
|
350
|
+
|
|
351
|
+
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).
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
export default defineConfig({ pushRelay: { appId: 'com.example.app' } })
|
|
355
|
+
```
|
|
@@ -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`, `pushRelay` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
35
35
|
|
|
36
36
|
## Config types
|
|
@@ -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
|
-
The
|
|
264
|
+
The mobile app that registers relay handles 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:
|
|
@@ -281,10 +281,45 @@ Each send is `POST <url>/send`, with the credential as a bearer token, never thr
|
|
|
281
281
|
{ "message": { "title": "Task assigned", "url": "https://app.example.com/tasks/42" }, "devices": [{ "handle": "…", "user": "user-1" }] }
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
The relay answers a `2xx` with a result for each handle, `ok`, `gone`, `retry` or `refused`, as [senders](#senders) answer: `{ "results": [{ "handle": "…", "result": "ok" }] }`. A handle the relay answers `gone` removes its device. A handle it does not answer, and every handle of any other answer, such as a wrong credential, a `429` or `5xx` (after its `Retry-After`) or no answer within ten seconds, is retried, so a mistake in the configuration removes no device. A device stored with a token that is not a relay handle is `refused
|
|
284
|
+
The relay answers a `2xx` with a result for each handle, `ok`, `gone`, `retry` or `refused`, as [senders](#senders) answer: `{ "results": [{ "handle": "…", "result": "ok" }] }`. A handle the relay answers `gone` removes its device. A handle it does not answer, and every handle of any other answer, such as a wrong credential, a `429` or `5xx` (after its `Retry-After`) or no answer within ten seconds, is retried, so a mistake in the configuration removes no device. A device stored with a token that is not a relay handle, or whose user id is not 1 to 256 characters without a control character, as a store takes it, is `refused` with no request, and the other devices are sent as usual. <gap>A send cannot keep the notification's text from the relay because content-free or encrypted relay payloads are not implemented.</gap>
|
|
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 clock hour, counting every handle of each send. A send that would go over is a `429` with a `Retry-After` until the next hour, and the workspace retries its devices.
|
|
322
|
+
|
|
288
323
|
## Your own parts
|
|
289
324
|
|
|
290
325
|
:::caution[Beta]
|