@protobase/cli 0.90.0 → 0.91.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.90.0";
2
+ var version = "0.91.0";
3
3
  //#endregion
4
4
  export { version };
@@ -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, checkPushRelayOptions, checkStatusOptions, workflowPlugins } from "@protobase/server/internal";
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, checkPushRelaySchema, 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, 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 { checkPushRelayOptions, checkStatusOptions } from "@protobase/server/internal";
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",
@@ -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, pushRelayMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
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 },
@@ -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, checkPushRelaySchema, 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, 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.90.0",
3
+ "version": "0.91.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.90.0",
47
- "@protobase/layout": "0.90.0",
48
- "@protobase/query": "0.90.0",
49
- "@protobase/schema": "0.90.0",
50
- "@protobase/server": "0.90.0",
51
- "@protobase/ui": "0.90.0",
52
- "@protobase/workflows": "0.90.0",
46
+ "@protobase/config": "0.91.0",
47
+ "@protobase/layout": "0.91.0",
48
+ "@protobase/query": "0.91.0",
49
+ "@protobase/schema": "0.91.0",
50
+ "@protobase/server": "0.91.0",
51
+ "@protobase/ui": "0.91.0",
52
+ "@protobase/workflows": "0.91.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",
@@ -16,6 +16,7 @@ Pages of your own, built from blocks in a JSX layout.
16
16
  - [Row buttons](../reference/blocks.md#row-buttons): A table's rows carry a button to an address their fields name, such as a task's tab, labelled by a field of the row, such as its next step.
17
17
  - [Record rows](../reference/blocks.md#recordrow): A sideways row of cards for a filter, favorites or saved searches, with a count and new-record marks.
18
18
  - [Record cards](../reference/blocks.md#recordcards): Full-width cards with fields and buttons, stacked or in a carousel.
19
+ - [Image block](../reference/blocks.md#image): A picture one of the app's API functions draws for the reader, such as a system map, at the size and theme the client asks, refreshed on a timer; a client that draws no images shows its alt text, or nothing.
19
20
  - [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
20
21
  - [Conversations](../reference/blocks.md#conversation): A chat declared in the layout: a thread of a resource's messages under each sender's name and time, following new ones as they arrive, and a box that sends one as the signed-in user.
21
22
  - [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
@@ -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.
@@ -351,7 +351,7 @@ export default defineUi({
351
351
  })
352
352
  ```
353
353
 
354
- `invoke(name, { method?, body?, path?, query?, headers? })` sends a `GET`, or a `POST` with a JSON `body`. It resolves to the parsed JSON, to text for a `text/*` answer or one without a content type, to a `Blob` of any other type, or to `undefined` for a `204`. A function sends a file, such as a PDF, as a plain `Response` with its type and name: `new Response(bytes, { headers: { 'content-type': 'application/pdf', 'content-disposition': 'attachment; filename="invoice.pdf"' } })`, and `invoke` gives the caller that `Blob`, with its `type`. A problem rejects with an `ApiError`, as any call of the client does. Outside the admin, `createClient` from `@protobase/client` gives the same `invoke`, or you can call the URL with `fetch` and an `Authorization: Bearer` header.
354
+ `invoke(name, { method?, body?, path?, query?, headers?, cache? })` sends a `GET`, or a `POST` with a JSON `body`; `cache` is the browser's fetch cache mode, such as `no-store` for an answer only its caller may see. It resolves to the parsed JSON, to text for a `text/*` answer or one without a content type, to a `Blob` of any other type, or to `undefined` for a `204`. A function sends a file, such as a PDF, as a plain `Response` with its type and name: `new Response(bytes, { headers: { 'content-type': 'application/pdf', 'content-disposition': 'attachment; filename="invoice.pdf"' } })`, and `invoke` gives the caller that `Blob`, with its `type`. A problem rejects with an `ApiError`, as any call of the client does. Outside the admin, `createClient` from `@protobase/client` gives the same `invoke`, or you can call the URL with `fetch` and an `Authorization: Bearer` header.
355
355
 
356
356
  ## Hono apps
357
357
 
@@ -332,6 +332,42 @@ A bar for `value` out of `max`, with both numbers. It turns amber from 90%.
332
332
  <Progress label="Seats" value="seats_used" max="plan.seats" />
333
333
  ```
334
334
 
335
+ ### Image
336
+
337
+ A picture an [API function](../guides/api-functions.md) draws, such as a system map: the block calls `GET /api/functions/<function>` with the reader's token, and draws the image it answers with, such as a PNG. The query says what to draw:
338
+
339
+ | Query | |
340
+ | --- | --- |
341
+ | `width` | The width the client draws it at, in CSS pixels: the block's `width`, else the width of its space, rounded up to a multiple of 100 so resizing the window asks again only now and then. |
342
+ | `height` | The block's `height`, when it has one. Without it the query names no height, and the picture's own proportions decide. |
343
+ | `theme` | `light` or `dark`, the theme the page is drawn in. |
344
+
345
+ | Prop | |
346
+ | --- | --- |
347
+ | `function` | The function's name, as in `functions/<function>.ts`. Required; the server stops at startup when the app has no such function. |
348
+ | `alt` | What the picture shows, for screen readers and for clients that draw no images. |
349
+ | `width`, `height` | The size it is drawn at, in CSS pixels. |
350
+ | `refresh` | Every how many seconds the client asks for the picture again, keeping the last one on screen while the next loads; once when omitted. Regaining window focus never asks again. |
351
+
352
+ ```tsx
353
+ <Image function="system-map" alt="The servers and the links between them" height={320} refresh={60} />
354
+ ```
355
+
356
+ ```ts
357
+ // functions/system-map.ts
358
+ import { defineFunction } from '@protobase/server'
359
+ import { drawSystemMap } from './_shared/system-map'
360
+
361
+ export default defineFunction({ roles: ['admin', 'support'] }, async (request, { records }) => {
362
+ const query = new URL(request.url).searchParams
363
+ const { items } = await records.list('servers')
364
+ const png = await drawSystemMap(items, { width: Number(query.get('width')), height: Number(query.get('height')) || undefined, dark: query.get('theme') === 'dark' })
365
+ return new Response(png, { headers: { 'content-type': 'image/png' } })
366
+ })
367
+ ```
368
+
369
+ The function reads records as the caller, so the picture shows only what they may see. A reader the function's `roles` or `capability` leave out gets the page without the block. So does a visitor without a token, unless the function is public, since only a public function takes a call without one. A client that draws no images, such as one that shows text only, shows `alt` in its place, or nothing without it; the admin app does the same when the function refuses, answers no image or one the browser cannot draw, also when a later request fails after an earlier one drew a picture. <gap>An Image cannot ask for a sharper picture on high-density screens because a scale in its query is not implemented.</gap>
370
+
335
371
  ### Chart
336
372
 
337
373
  Counts, sums or averages of the records that match `filter`, per value of a field or per hour, day, week, month or year of a date field, in a card. It reads [`:aggregate`](api.md#routes), so only what the user may see is counted, and the grouped field needs an index ([scan guard](api.md#safety)).
@@ -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`, `push-relay`, `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`, `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
@@ -17,7 +17,7 @@ const { record, etag } = await api.get(orders, id)
17
17
  await api.update(orders, id, { status: 'shipped' }, etag) // 412 rejects with PreconditionFailedError
18
18
  ```
19
19
 
20
- Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket), `bridges.open(name, target)` (a [TCP bridge](tcp-bridges.md#opening-a-bridge)'s socket, with when the server closes it).
20
+ Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query?, cache? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket), `bridges.open(name, target)` (a [TCP bridge](tcp-bridges.md#opening-a-bridge)'s socket, with when the server closes it).
21
21
 
22
22
  With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/v1`, the `url` of each [file](files.md) in a record the client answers is absolute too, on that API's origin, where the API answers a path on its own origin. `routedClient(own, sourceOf)` is one client over several APIs: each call about a resource goes to the client `sourceOf(resource)` gives, else to `own`, as the admin app does for [remote resources](remote-resources.md), and `sourceMeta(meta, source)` keeps the part of another API's `/meta` an app draws.
23
23
 
@@ -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`, `pushRelay` |
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
@@ -82,9 +82,12 @@ A client that cannot draw a component, such as a native app without React or the
82
82
 
83
83
  ```tsx
84
84
  export const SeatChart = component('SeatChart', { fallback: <Progress label="Seats" value="seats_used" max="plan.seats" /> })
85
+ export const SystemMap = component('SystemMap', { fallback: <Image function="system-map" /> })
85
86
  export const Confetti = component('Confetti', { fallback: [] })
86
87
  ```
87
88
 
89
+ A visual component, such as a map, falls back to the [picture](blocks.md#image) an API function draws of it; with no `alt`, a client that shows text only draws nothing in its place.
90
+
88
91
  The admin app draws the fallback too when the component is missing or throws while drawing; `protobase dev` also shows the warning above it. Without a fallback, the warning stands in the component's place, as above. A [record section](#record-sections) takes `fallback` in `l.custom`.
89
92
 
90
93
  ### Fields and resources in props
@@ -140,5 +140,6 @@ Every block reads the regular API with the user's token, so the access rules app
140
140
  - `Field`, `Progress` and `Stat field` on a field they cannot read are left out, and table columns are narrowed;
141
141
  - `ModalForm` needs create or update permission and keeps only the fields they may write;
142
142
  - an `Action` missing from their view of the resource is left out, and so is a `Show` that names something they cannot see.
143
+ - an `Image` whose function they may not call is left out.
143
144
 
144
145
  Custom components are kept: they get only their props, and fetch through the same API. A custom component's fallback loses what the user cannot use like the rest of the tree, and a fallback left with nothing is sent as `[]`, so a client still draws nothing in the component's place.
@@ -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 mobile app that registers relay handles is coming soon.
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 };