@protobase/cli 0.59.1 → 0.59.3
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 +3 -1
- package/dist/migration/load-project.js +2 -0
- package/dist/migration/parts.js +11 -1
- package/dist/project/project-admin.js +1 -0
- package/dist/serve/lifecycle.js +3 -1
- package/package.json +7 -7
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/history-comments-and-live-updates.md +1 -1
- package/skills/protobase/references/features/navigation.md +1 -1
- package/skills/protobase/references/features/notifications.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/reference/channels.md +23 -7
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/config/api.md +4 -4
- package/skills/protobase/references/reference/config/jobs-and-events.md +23 -1
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/custom-components.md +1 -1
- package/skills/protobase/references/reference/notifications.md +2 -0
- package/skills/protobase/references/reference/status.md +97 -0
- package/skills/protobase/references/reference/user-menu.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { projectFiles, projectFunctions, projectJobs, projectNotifications, projectOptions, projectResources, projectWebhooks } from "./project-parts.js";
|
|
2
|
-
import { buildAppAuth, buildAuthenticator, checkCallsOptions } from "@protobase/server/internal";
|
|
2
|
+
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions } from "@protobase/server/internal";
|
|
3
3
|
//#region src/config/build-project.ts
|
|
4
4
|
/**
|
|
5
5
|
* The app's own mailer, the default export of its auth/mailer.ts: what sign-in and the jobs (`context.mail`) both send
|
|
@@ -70,6 +70,7 @@ const buildProject = async (config, database) => {
|
|
|
70
70
|
...webhooks && { webhooks },
|
|
71
71
|
...config.realtime && { realtime: config.realtime },
|
|
72
72
|
...notifications && { notifications },
|
|
73
|
+
...config.status && { status: checkStatusOptions(config.status) },
|
|
73
74
|
...config.calls && { calls: checkCallsOptions(config.calls) },
|
|
74
75
|
...mailer && { mailer },
|
|
75
76
|
...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, checkChanges, checkComments, checkComputed, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkWebhooksSchema, configExports, hasUsers, relayed } from "@protobase/server";
|
|
10
|
+
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkChanges, checkChannelSends, checkComments, checkComputed, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkWebhooksSchema, 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
|
|
@@ -38,7 +38,9 @@ checkAi({
|
|
|
38
38
|
});
|
|
39
39
|
if (project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
40
40
|
if (relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
41
|
+
if (sqlSends(project.realtime)) await checkChannelSends(db);
|
|
41
42
|
if (project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
43
|
+
if (project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
42
44
|
setMissing(process.env, supabaseEnv({
|
|
43
45
|
url: process.env.PROTOBASE_DEV_URL,
|
|
44
46
|
databaseUrl: process.env.PROTOBASE_DATABASE_URL,
|
|
@@ -5,6 +5,7 @@ import { loadSourceConfig } from "../config/source-config.js";
|
|
|
5
5
|
import { openAppDatabase } from "../project/pg-db.js";
|
|
6
6
|
import pg from "pg";
|
|
7
7
|
import { assistantSettings, authStoreTables, configExports } from "@protobase/server";
|
|
8
|
+
import { checkStatusOptions } from "@protobase/server/internal";
|
|
8
9
|
//#region src/migration/load-project.ts
|
|
9
10
|
/**
|
|
10
11
|
* The project in `dir` as `protobase dev` merges it, for what its database needs: protobase.config.ts, with the
|
|
@@ -40,6 +41,7 @@ const migrationProject = async (config, url) => {
|
|
|
40
41
|
...webhooks && { webhooks },
|
|
41
42
|
...config.realtime && { realtime: config.realtime },
|
|
42
43
|
...notifications && { notifications },
|
|
44
|
+
...config.status && { status: checkStatusOptions(config.status) },
|
|
43
45
|
jobs,
|
|
44
46
|
readOnlyQueries: assistantSettings(config.assistant, process.env)?.kind === "built-in",
|
|
45
47
|
authTables: auth ? authStoreTables(auth) : {
|
package/dist/migration/parts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { authMigrationTitle } from "../auth/migration-file.js";
|
|
2
|
-
import { authSchemaMigration, changesMigration, commentsMigration, computedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, webhooksMigration } from "@protobase/server";
|
|
2
|
+
import { authSchemaMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, webhooksMigration } from "@protobase/server";
|
|
3
3
|
//#region src/migration/parts.ts
|
|
4
4
|
/** Every feature the project's config enables, in the order their files are written. */
|
|
5
5
|
const migrationParts = (project) => {
|
|
@@ -46,10 +46,20 @@ const migrationParts = (project) => {
|
|
|
46
46
|
title: "The tables of notifications",
|
|
47
47
|
sql: () => notificationsMigration(project.db, project.notifications, project.auth)
|
|
48
48
|
}] : [],
|
|
49
|
+
...project.status ? [{
|
|
50
|
+
name: "status",
|
|
51
|
+
title: "The statuses table of people's own status",
|
|
52
|
+
sql: () => statusMigration(project.db, project.status, project.auth)
|
|
53
|
+
}] : [],
|
|
49
54
|
...relayed(project.realtime) ? [{
|
|
50
55
|
name: "realtime_relay",
|
|
51
56
|
title: "The relay of Realtime broadcasts and presence between the processes serving the app",
|
|
52
57
|
sql: () => realtimeRelayMigration(project.db)
|
|
58
|
+
}] : [],
|
|
59
|
+
...sqlSends(project.realtime) ? [{
|
|
60
|
+
name: "channel_sends",
|
|
61
|
+
title: "SQL's broadcasts to the record channels, channels.send()",
|
|
62
|
+
sql: () => channelSendsMigration(project.db)
|
|
53
63
|
}] : []
|
|
54
64
|
];
|
|
55
65
|
};
|
|
@@ -28,6 +28,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket) => {
|
|
|
28
28
|
...project.webhooks && { webhooks: project.webhooks },
|
|
29
29
|
...project.realtime && { realtime: project.realtime },
|
|
30
30
|
...project.notifications && { notifications: project.notifications },
|
|
31
|
+
...project.status && { status: project.status },
|
|
31
32
|
...project.calls && { calls: project.calls },
|
|
32
33
|
...project.mobile && { mobile: project.mobile },
|
|
33
34
|
...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, checkChanges, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkWebhooksSchema, configExports, createFileCleanup, relayed, startJobs } from "@protobase/server";
|
|
12
|
+
import { assistantSettings, authStoreTables, backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkChannelSends, checkComments, checkComputed, checkJobsSchema, checkNotificationsSchema, checkQueryRunner, checkRealtimeRelay, checkResourcesOutsideAuthStore, checkStatusSchema, checkWebhooksSchema, 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) => {
|
|
@@ -44,7 +44,9 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
44
44
|
});
|
|
45
45
|
if (env.startupChecks && project.webhooks) await checkWebhooksSchema(db, project.webhooks);
|
|
46
46
|
if (env.startupChecks && relayed(project.realtime)) await checkRealtimeRelay(db);
|
|
47
|
+
if (env.startupChecks && sqlSends(project.realtime)) await checkChannelSends(db);
|
|
47
48
|
if (env.startupChecks && project.notifications) await checkNotificationsSchema(db, project.notifications, project.auth);
|
|
49
|
+
if (env.startupChecks && project.status) await checkStatusSchema(db, project.status, project.auth);
|
|
48
50
|
const { admin, jobs: definitions } = projectAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
49
51
|
if (env.startupChecks && definitions.length > 0) await checkJobsSchema(db);
|
|
50
52
|
const jobs = definitions.length > 0 ? await startJobs({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.3",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.59.
|
|
46
|
-
"@protobase/layout": "0.59.
|
|
47
|
-
"@protobase/query": "0.59.
|
|
48
|
-
"@protobase/schema": "0.59.
|
|
49
|
-
"@protobase/server": "0.59.
|
|
50
|
-
"@protobase/ui": "0.59.
|
|
45
|
+
"@protobase/config": "0.59.3",
|
|
46
|
+
"@protobase/layout": "0.59.3",
|
|
47
|
+
"@protobase/query": "0.59.3",
|
|
48
|
+
"@protobase/schema": "0.59.3",
|
|
49
|
+
"@protobase/server": "0.59.3",
|
|
50
|
+
"@protobase/ui": "0.59.3",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -89,6 +89,7 @@ Reference:
|
|
|
89
89
|
- When running background jobs → read [Jobs](references/reference/jobs.md)
|
|
90
90
|
- When sending email → read [Email](references/reference/email.md)
|
|
91
91
|
- When registering users' devices for push notifications → read [Notifications](references/reference/notifications.md)
|
|
92
|
+
- When people should set themselves busy, do not disturb or a status text, or see others' beside their names → read [Status](references/reference/status.md)
|
|
92
93
|
- When adding audio and video calls, through LiveKit or peer to peer → read [Calls](references/reference/calls.md)
|
|
93
94
|
- When setting roles, capabilities and row filters → read [Access](references/reference/access.md)
|
|
94
95
|
- When configuring sign-in, tokens and the auth schema → read [Login with Better Auth](references/reference/auth.md)
|
|
@@ -13,4 +13,4 @@ The changes of each record, comments on it, and pages that refresh as records ch
|
|
|
13
13
|
- [Live updates](../reference/live.md#what-a-page-hears): Open lists and record pages refresh within seconds when a record changes, including changes made outside the API.
|
|
14
14
|
- [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
|
|
15
15
|
- [Presence](../reference/channels.md#presence) (beta): Apps see who else has a record open and what each of them tracks, such as online or away, for whoever may read the record.
|
|
16
|
-
- [Broadcasts](../reference/channels.md#broadcasts) (beta): Apps on a record send each other short-lived events, such as typing, which are never stored; the app's own code sends them too.
|
|
16
|
+
- [Broadcasts](../reference/channels.md#broadcasts) (beta): Apps on a record send each other short-lived events, such as typing, which are never stored, as JSON or as bytes, such as a chunk of audio or a drawing stroke; the app's own code sends them too, from an API function, over HTTP or [from SQL](../reference/channels.md#from-sql) with `channels.send()`.
|
|
@@ -8,7 +8,7 @@ The sidebar, the user menu, the bottom bar on phones and the global search.
|
|
|
8
8
|
- [Recent records](../reference/sidebar.md#recent-records): A sidebar entry lists a few records under it, with status dots or as titles alone, and marked per reader, such as unread ones in bold with a count.
|
|
9
9
|
- [Create link](../reference/sidebar.md#create-link): A sidebar entry links to its create form, such as "New message" under Direct messages, for whoever may create.
|
|
10
10
|
- [The current organization](../reference/sidebar.md#the-current-organization): A sidebar entry opens its list on the organization you work in, which you can clear to see every organization you are a member of.
|
|
11
|
-
- [User menu](../reference/user-menu.md): Account pages, help links, security settings, the theme switch and Sign out.
|
|
11
|
+
- [User menu](../reference/user-menu.md): Account pages, help links, security settings, setting a status, the theme switch and Sign out.
|
|
12
12
|
- [Bottom bar](../reference/bottom-bar.md): On phones, tabs along the bottom for each role's main screens.
|
|
13
13
|
- [Global search](../reference/client.md#global-search): A search box, also on Cmd+K or Ctrl+K, finds records in every resource and jumps to pages and New forms.
|
|
14
14
|
- Breadcrumbs: The top bar shows the group, list and record you are on, each a link back.
|
|
@@ -13,4 +13,5 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
13
13
|
- [Web Push](../reference/notifications.md#web-push) (beta): Notifications reach desktop and Android browsers and home-screen web apps on iPhone through Web Push, with keys you generate.
|
|
14
14
|
- Push on Android (coming soon): Notifications reach the Android build of the app on a user's phones.
|
|
15
15
|
- Push on iOS (coming soon): Notifications reach the iOS build of the app on a user's iPhones and iPads.
|
|
16
|
+
- [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.
|
|
16
17
|
- [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.
|
|
@@ -25,6 +25,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
25
25
|
- [Staff sign-in](../reference/auth.md#staff-sign-in): The team that runs an app signs in as a person to help them, with a reason and a log entry.
|
|
26
26
|
- [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
|
|
27
27
|
- [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
|
|
28
|
+
- [Status](../reference/status.md) (beta): People set themselves busy or do not disturb, with a text of their own such as "Having lunch" and a time it clears, from the user menu; the people they share an organization with see it beside their name.
|
|
28
29
|
- [API tokens](../reference/auth.md#tokens-and-roles): A signed-in session gets short-lived tokens for the API.
|
|
29
30
|
- [Immediate revocation](../reference/auth.md#when-a-token-stops-working): A ban, removed role or ended session takes effect on the next request.
|
|
30
31
|
- [Signing key rotation](../reference/auth.md#signing-keys): The keys that sign the tokens are replaced every 30 days on their own, and old ones keep verifying the tokens they signed for a week.
|
|
@@ -7,7 +7,7 @@ Every record has a channel, where the pages that have it open see who else is th
|
|
|
7
7
|
Every record of the app has a channel. The pages on it see who else is there and what each of them tracks, such as online or away (presence), and send each other events that are never stored, such as typing (broadcasts). Whoever may read the record may join its channel; nothing else needs to be set up. A record everyone may read, a visitor of the anonymous role included, makes an open channel.
|
|
8
8
|
|
|
9
9
|
:::caution[Beta]
|
|
10
|
-
SQL
|
|
10
|
+
SQL broadcasts JSON only, not bytes.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
13
|
## From a page
|
|
@@ -24,6 +24,10 @@ room.on('typing', ({ user, payload }) => console.log(user, 'is typing', payload)
|
|
|
24
24
|
await room.track({ status: 'online' })
|
|
25
25
|
await room.send('typing', { on: true })
|
|
26
26
|
|
|
27
|
+
// Bytes, such as a chunk of audio or a drawing stroke: an ArrayBuffer or a typed array.
|
|
28
|
+
room.on('stroke', ({ user, payload }) => draw(user, new Float32Array(payload as ArrayBuffer)))
|
|
29
|
+
await room.send('stroke', new Float32Array([0.1, 0.5, 0.2, 0.7]))
|
|
30
|
+
|
|
27
31
|
room.leave()
|
|
28
32
|
```
|
|
29
33
|
|
|
@@ -32,8 +36,8 @@ room.leave()
|
|
|
32
36
|
| `status()`, `onStatus(listener)` | `joining`, also while the connection is down; `joined`; `refused`, with its `error`, for a record there is none of or the caller may not read; `closed`, with its `error`, when the server left the channel, such as once the caller may no longer read the record. A refused or closed channel is not joined again. |
|
|
33
37
|
| `presence()`, `onPresence(listener)` | Every connection on the channel that tracks a state, this one included, as `{ id, user, state }`; the listener gets the whole presence and, for a change, its `{ joins, updates, leaves }`. |
|
|
34
38
|
| `track(state)`, `untrack()` | Tracks this connection's JSON state on the channel, replaces it, or takes it out. A state tracked before the channel joined is tracked once it does, and again after a reconnect. |
|
|
35
|
-
| `send(event, payload, { self?, ack? })` | Broadcasts a JSON payload to the others on the channel; `self` hears it too, and with `ack` it resolves once the server took it, or rejects with a `ChannelRefusal`. |
|
|
36
|
-
| `on(event, listener)` | Hears the channel's broadcasts of `event`, each `{ event, payload, user }`, and `server: true` for one the app's own code sent. |
|
|
39
|
+
| `send(event, payload, { self?, ack? })` | Broadcasts a JSON payload, or bytes in an `ArrayBuffer` or a typed array, to the others on the channel; `self` hears it too, and with `ack` it resolves once the server took it, or rejects with a `ChannelRefusal`. |
|
|
40
|
+
| `on(event, listener)` | Hears the channel's broadcasts of `event`, each `{ event, payload, user }`, and `server: true` for one the app's own code sent. The payload of bytes is an `ArrayBuffer`. |
|
|
37
41
|
| `leave()` | Lets the channel go. |
|
|
38
42
|
|
|
39
43
|
Every channel of one client shares one WebSocket, opened with the first channel and closed after the last, and connects again by itself after a drop, joining its channels again. With [live updates](live.md#the-stream), a page holds two connections however many live views and channels it has.
|
|
@@ -54,11 +58,11 @@ An entry leaves at once when its connection leaves the channel or closes, as whe
|
|
|
54
58
|
|
|
55
59
|
## Broadcasts
|
|
56
60
|
|
|
57
|
-
A broadcast reaches every other connection on the channel, and the sender's own with `self`, at once. Nothing is stored: a broadcast reaches who is on the channel when it is sent, and nobody else.
|
|
61
|
+
A broadcast reaches every other connection on the channel, and the sender's own with `self`, at once. Nothing is stored: a broadcast reaches who is on the channel when it is sent, and nobody else. A payload is JSON or bytes, which reach the others as they were sent, under the same access rule, limits and refusals: the size limits count the bytes.
|
|
58
62
|
|
|
59
63
|
## From the server
|
|
60
64
|
|
|
61
|
-
An [API function](../guides/api-functions.md) broadcasts with its context's `channels`, as the server: its broadcasts have `user: null` and `server: true`, and it needs no read access. It rejects with a `404` problem for a resource or key the app does not have, `422` for an event over 255 bytes or a payload over 256 KiB, and `429` over the channel's broadcasts.
|
|
65
|
+
An [API function](../guides/api-functions.md) broadcasts with its context's `channels`, as the server: its broadcasts have `user: null` and `server: true`, and it needs no read access. Its payload is JSON, or bytes in an `ArrayBuffer` or a typed array. It rejects with a `404` problem for a resource or key the app does not have, `422` for an event over 255 bytes or a payload over 256 KiB, of JSON or bytes, and `429` over the channel's broadcasts.
|
|
62
66
|
|
|
63
67
|
```ts
|
|
64
68
|
import { defineFunction } from '@protobase/server'
|
|
@@ -69,11 +73,21 @@ export default defineFunction(async (request, { channels }) => {
|
|
|
69
73
|
})
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
`POST /api/channels/<resource>/<key>/broadcast` with `{ "event": "…", "payload": … }` broadcasts as its caller, who must read the record, under the same limits, answered `202`.
|
|
76
|
+
`POST /api/channels/<resource>/<key>/broadcast` with `{ "event": "…", "payload": … }` broadcasts as its caller, who must read the record, under the same limits, answered `202`. Bytes go as the body of `application/octet-stream`, with the event in the query: `POST /api/channels/rooms/42/broadcast?event=stroke`.
|
|
77
|
+
|
|
78
|
+
### From SQL
|
|
79
|
+
|
|
80
|
+
With [`realtime: { sqlSends: true }`](config/api.md#realtime), SQL in the app's database, such as a trigger, broadcasts JSON to a record's channel with `channels.send(resource, key, event, payload)`. <gap>SQL cannot broadcast bytes because a binary payload for `channels.send()` is not implemented.</gap>
|
|
81
|
+
|
|
82
|
+
```sql
|
|
83
|
+
select channels.send('rooms', '42', 'announcement', '{"text": "Standup in 5 minutes"}');
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The call inserts a row into `channels.sends` in the caller's transaction, so a transaction rolled back sends nothing. Within a second of its commit, a serving process with a channel socket open takes the row out of the table and broadcasts it as the server, `user: null` and `server: true`, in the order the transaction sent them, under the checks and limits of `channels.broadcast` in API functions: a send for a resource or key the app does not have, with an event over 255 bytes or a payload over 256 KiB, or over the channel's broadcasts, is dropped. With several processes, one takes the row and the relay carries it to the others. <gap>Sends of transactions that commit between the same two reads cannot go out in commit order, only in the order they were inserted, because reading commit order is not implemented.</gap> A send while no process has a socket open reaches nobody, and the rows no process took are deleted after 48 hours. Only the database role that owns the function, the one the migrations are applied as, which is usually the app's own, may call it, so that no other role, such as those of the [PostgREST-compatible API](supabase-rest.md), sends as the server: a trigger that sends for other roles calls it from a `security definer` function. [`protobase migration`](cli.md#migration) writes the `channels` schema, and the server checks it at start.
|
|
73
87
|
|
|
74
88
|
## The socket
|
|
75
89
|
|
|
76
|
-
`GET /api/channels` is the WebSocket `@protobase/client` opens, with the subprotocol `protobase.channels`. A browser opens it with its session cookie; a client with a bearer token offers it as a second subprotocol, `bearer.<token>`, and hands over a new one with `{ "type": "token", "token": "…" }`, which the next check of the session uses. A page of another origin than the app's is refused with `403`. Each frame is JSON text:
|
|
90
|
+
`GET /api/channels` is the WebSocket `@protobase/client` opens, with the subprotocol `protobase.channels`. A browser opens it with its session cookie; a client with a bearer token offers it as a second subprotocol, `bearer.<token>`, and hands over a new one with `{ "type": "token", "token": "…" }`, which the next check of the session uses. A page of another origin than the app's is refused with `403`. Each frame is JSON text, but for a broadcast of bytes:
|
|
77
91
|
|
|
78
92
|
| The client sends | |
|
|
79
93
|
| --- | --- |
|
|
@@ -84,6 +98,8 @@ export default defineFunction(async (request, { channels }) => {
|
|
|
84
98
|
|
|
85
99
|
The server sends `reply` (`{ ref, ok: true }` or `{ ref, ok: false, error: { code, message } }`), `presence` (`{ channel, entries }`), `presence_diff` (`{ channel, joins, updates, leaves }`), `broadcast` (`{ channel, event, payload, user, server? }`), `closed` (`{ channel, error }`) and `error` for a frame that is no message.
|
|
86
100
|
|
|
101
|
+
A broadcast of bytes, either way, is a binary frame: the byte length of a JSON header as a big-endian 32-bit integer, the header, then the bytes. The header is the message without its `payload`: `{ type: 'send', ref, channel, event, self?, ack? }` from the client, `{ type: 'broadcast', channel, event, user, server? }` from the server.
|
|
102
|
+
|
|
87
103
|
## Limits
|
|
88
104
|
|
|
89
105
|
They are the limits of the [Realtime-compatible socket](supabase-realtime.md#broadcast-and-presence), apart from the shorter idle time. A connection sends at most 100 broadcasts and presence updates a second (`too-many-messages`), joins at most 100 times a second (`too-many-joins`) and holds at most 100 channels (`too-many-channels`); on each channel it tracks or untracks at most 5 times in 30 seconds (`too-many-presence-updates`). A channel takes 100 broadcasts a second, every sender's together (`channel-too-busy`). A channel name, `<resource>/<key>`, is at most 255 bytes (`name-too-long`), an event at most 255 bytes (`event-too-long`) and a tracked state at most 10 000 bytes of JSON (`presence-too-large`). A refused message goes to no one. A frame over 256 KiB closes the socket with `1009`; it closes with `1008` when the client leaves more than 4 MiB unread, or sends more than 300 messages or 4 MiB while earlier ones wait.
|
|
@@ -546,7 +546,7 @@ Applies the project's `db/migrations/*.sql` that the database has not applied ye
|
|
|
546
546
|
protobase migration [--dir db/migrations] [--extend <dir>]
|
|
547
547
|
```
|
|
548
548
|
|
|
549
|
-
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks` or `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`), the [devices and history tables](notifications.md#table-names) of `notifications` (`NNN_notifications.sql`),
|
|
549
|
+
Writes what the database still needs for every feature the config enables, as the project's next migrations in `--dir`, one file per feature: the auth schema when sign-in is on (`NNN_auth.sql`, as [`auth migration`](#auth-migration) writes it), the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks` or `notifications`, or a resource has events, history, comments or an [AI field](ai.md) (`NNN_jobs.sql`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`NNN_changes.sql`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas) and the triggers that keep the rollups (`NNN_computed.sql`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`NNN_query.sql`), the [comments table](comments.md#the-table) (`NNN_comments.sql`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`NNN_webhooks.sql`), the [devices and history tables](notifications.md#table-names) of `notifications` (`NNN_notifications.sql`), the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) (`NNN_realtime_relay.sql`), and the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) (`NNN_channel_sends.sql`). It compares the database, with the project's migrations applied, with the config (for the auth schema, it reads the store's record of the migrations it applied), merged with those of `--extend` as `dev` merges them, and writes nothing when the database is current. Apply the files with the project's other migrations. It reads the `.env` nearest the current directory and needs `DATABASE_URL`.
|
|
550
550
|
|
|
551
551
|
```sh
|
|
552
552
|
bun run db:migrate # the database at the project's current schema
|
|
@@ -151,13 +151,13 @@ export default defineConfig({ runtimeUpdates: false })
|
|
|
151
151
|
|
|
152
152
|
## realtime
|
|
153
153
|
|
|
154
|
-
- **Type:** `{ processes?: 'one' | 'many' }`
|
|
155
|
-
- **Default:** `{ processes: 'one' }`
|
|
154
|
+
- **Type:** `{ processes?: 'one' | 'many', sqlSends?: boolean }`
|
|
155
|
+
- **Default:** `{ processes: 'one', sqlSends: false }`
|
|
156
156
|
|
|
157
|
-
How [channels](../channels.md) and [Supabase Realtime](../supabase-realtime.md) are served. With `'one'`, one process serves the app, and broadcasts and presence go between its channels in memory. Set `'many'` when several processes serve the app behind one address: broadcasts and presence then go between the processes through the `realtime_relay` schema of the app's database, which [`protobase migration`](../cli.md#migration) writes and the server checks at start. See [Several processes](../channels.md#several-processes).
|
|
157
|
+
How [channels](../channels.md) and [Supabase Realtime](../supabase-realtime.md) are served. With `'one'`, one process serves the app, and broadcasts and presence go between its channels in memory. Set `'many'` when several processes serve the app behind one address: broadcasts and presence then go between the processes through the `realtime_relay` schema of the app's database, which [`protobase migration`](../cli.md#migration) writes and the server checks at start. See [Several processes](../channels.md#several-processes). Set `sqlSends: true` to let SQL in the app's database broadcast to channels with `channels.send()`, from the `channels` schema that `protobase migration` writes and the server checks at start. See [From SQL](../channels.md#from-sql).
|
|
158
158
|
|
|
159
159
|
```ts
|
|
160
|
-
export default defineConfig({ realtime: { processes: 'many' } })
|
|
160
|
+
export default defineConfig({ realtime: { processes: 'many', sqlSends: true } })
|
|
161
161
|
```
|
|
162
162
|
|
|
163
163
|
## calls
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Jobs and events options
|
|
4
4
|
|
|
5
|
-
The config keys of what the app does in the background and records as it changes, jobs, events, history, webhooks and
|
|
5
|
+
The config keys of what the app does in the background and records as it changes, jobs, events, history, webhooks, notifications and status, with their types and defaults, and the files where a job's run and the stores of its own go.
|
|
6
6
|
|
|
7
7
|
The keys of the app's background work and of what it keeps as records change, at the top level of [`protobase.config.ts`](../config.md).
|
|
8
8
|
|
|
@@ -265,3 +265,25 @@ The history table, each user's inbox: its name, and its columns named otherwise
|
|
|
265
265
|
```ts
|
|
266
266
|
export default defineConfig({ notifications: { history: { table: 'inbox_items' } } })
|
|
267
267
|
```
|
|
268
|
+
|
|
269
|
+
## status
|
|
270
|
+
|
|
271
|
+
- **Type:** `{ schema?: string }`
|
|
272
|
+
- **Default:** off; `{}` turns it on
|
|
273
|
+
|
|
274
|
+
People set their own status, busy, do not disturb or a text of their own, which the people they share an organization with see, and do not disturb holds their pushes. It needs `auth` with organizations, and its table is written by `protobase migration`. See [Status](../status.md).
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
export default defineConfig({ auth: { organizations: true }, status: {} })
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## status.schema
|
|
281
|
+
|
|
282
|
+
- **Type:** `string`
|
|
283
|
+
- **Default:** `status`
|
|
284
|
+
|
|
285
|
+
The schema of the statuses table.
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
export default defineConfig({ status: { schema: 'presence' } })
|
|
289
|
+
```
|
|
@@ -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` |
|
|
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`, `notifications` |
|
|
33
|
+
| [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `notifications`, `status` |
|
|
34
34
|
| [Files options](config/files.md) | `files` |
|
|
35
35
|
|
|
36
36
|
## Config types
|
|
@@ -335,7 +335,7 @@ export const Channel = ({ messages, sent, members, onSend, onLoadEarlier }: Chan
|
|
|
335
335
|
|
|
336
336
|
### Members' names
|
|
337
337
|
|
|
338
|
-
The author is a user id, and `useMembers()` from `@protobase/ui` turns it into a name: the members of the organization the signed-in person works in, `{ id, name, image? }` by name, with `id` the user id that `.author()` stores and that `onSend`'s mentions hold. Every member reads it, owners, admins and members alike; it holds no email addresses. It is a TanStack Query result (`data`, `isLoading`, `error`) with `member(id)`, which finds one and, for an id it does not know, such as a newcomer's first message, reads the list again once it is 10 seconds old; it is also read again when the window regains focus and the list is 30 seconds old. It needs [organizations](auth.md#organizations): without them, `error` says so.
|
|
338
|
+
The author is a user id, and `useMembers()` from `@protobase/ui` turns it into a name: the members of the organization the signed-in person works in, `{ id, name, image? }` by name, with `id` the user id that `.author()` stores and that `onSend`'s mentions hold. Every member reads it, owners, admins and members alike; it holds no email addresses. It is a TanStack Query result (`data`, `isLoading`, `error`) with `member(id)`, which finds one and, for an id it does not know, such as a newcomer's first message, reads the list again once it is 10 seconds old; it is also read again when the window regains focus and the list is 30 seconds old. It needs [organizations](auth.md#organizations): without them, `error` says so. In an app with [status](status.md#in-the-app), each member carries their `status` too, read again every 15 seconds.
|
|
339
339
|
|
|
340
340
|
```tsx
|
|
341
341
|
import { ChatMessage, Composer, MentionedText, useMembers } from '@protobase/ui'
|
|
@@ -112,6 +112,8 @@ A send checks no permission. A device send reaches the devices whatever user hol
|
|
|
112
112
|
|
|
113
113
|
A user send reaches the user's devices as they are when the job runs. A device that moved to someone else, or was removed, gets nothing. With Protobase's auth, a device whose sign-in session has [ended](#devices) is removed instead; a send whose devices' sessions cannot be read pushes to none of them and is retried. With an app's own authenticator, a device keeps receiving its user's notifications until it is removed. When a push service reports a device gone, the device is removed. A device whose push service asks to try again later is tried once more, on the job's next try, and then given up on without being removed. <gap>A push service's own wait before a retry cannot set when the device is tried again because retries follow the job's backoff and timing them per device is not implemented.</gap> A sender that fails is retried with its devices, up to 5 tries of the job. Devices of a kind without a sender are skipped. Without any sender, a send for the inbox is kept in the history and a send that is not does nothing.
|
|
114
114
|
|
|
115
|
+
In an app with [status](status.md#do-not-disturb), a user on do not disturb when the send's job runs gets nothing pushed, by any sender, built-in or the app's own, and a send to devices holds their devices too; a send for the inbox still keeps the notification in their history, which the bell shows unread. Nothing of the send is pushed to them once do not disturb ends, and the others in the send are pushed as usual.
|
|
116
|
+
|
|
115
117
|
## History
|
|
116
118
|
|
|
117
119
|
:::caution[Beta]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from docs/website/src/content/docs/reference/status.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Status
|
|
4
|
+
|
|
5
|
+
People set their own status, busy, do not disturb or a text such as "Having lunch", which the people they share an organization with see beside their name, and do not disturb holds their push notifications.
|
|
6
|
+
|
|
7
|
+
## Turning it on
|
|
8
|
+
|
|
9
|
+
:::caution[Beta]
|
|
10
|
+
A status is the same in every organization; a status per organization and do-not-disturb schedules are not part of it.
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
A status says whether someone wants to be reached: an availability, busy or do not disturb, and a short text of their own, such as "Having lunch" or "On vacation 🌴". You turn it on in `protobase.config.ts`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from '@protobase/config'
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
auth: { organizations: true },
|
|
20
|
+
status: {},
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then run `protobase migration`, which writes the statuses table, `status.statuses`, as a migration of the project's own, and apply it with the project's migrations. `status: { schema: 'presence' }` puts the table in another schema. `protobase dev` and `protobase serve` refuse to start while the table is missing. Without `status` there is none of it: no menu item, no endpoints, no table and no migration, and notifications go out as before.
|
|
25
|
+
|
|
26
|
+
People see the statuses of those they share an [organization](auth.md#organizations) with, so status needs organizations: an app without them stops at startup, and `protobase migration` says why.
|
|
27
|
+
|
|
28
|
+
## Setting a status
|
|
29
|
+
|
|
30
|
+
Someone signed in as themselves opens "Set a status" in the [user menu](user-menu.md) and picks:
|
|
31
|
+
|
|
32
|
+
- an availability: automatic, the default, which says nothing; busy; or do not disturb;
|
|
33
|
+
- a text of at most 100 characters, one line of plain text; an emoji typed in it is one character;
|
|
34
|
+
- when it clears: never, in 30 minutes, 1 hour or 4 hours, at the end of today or of this week (midnight, Sunday night for the week, in their own time zone), or at a date and time they choose.
|
|
35
|
+
|
|
36
|
+
Their status then shows by their name at the bottom of the sidebar, and the item shows it; they change it or clear it there at any time. Staff [signed in as the person](auth.md#staff-sign-in) see no item.
|
|
37
|
+
|
|
38
|
+
Each person has one status, shown in every organization they are in. Only they set it: the server takes the person from the session, never from the request, and refuses staff signed in as them, visitors and outside apps acting for them, such as an MCP client. A text with control characters, a line break among them, or over 100 characters is refused with a `400` that says why, and so is a clear time that has passed. The text is always shown as text, never as HTML.
|
|
39
|
+
|
|
40
|
+
| Request | |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `GET /api/status` | the caller's own status, `{ status }`, `null` without one |
|
|
43
|
+
| `PUT /api/status` | sets it from `{ availability, text, clearsAt }`, each required, `text` and `clearsAt` `null` for none and never; answers `{ status }` |
|
|
44
|
+
| `DELETE /api/status` | clears it; answers `204` |
|
|
45
|
+
| `GET /api/status/people` | `{ statuses }`, the statuses of everyone who shares an organization with the caller, their own among them |
|
|
46
|
+
|
|
47
|
+
A status is `{ userId, availability, text, clearsAt }`, with `availability` one of `automatic`, `busy` and `do_not_disturb`, and `clearsAt` an ISO time or `null`.
|
|
48
|
+
|
|
49
|
+
## Who sees it
|
|
50
|
+
|
|
51
|
+
The members of every organization the person is in see their status. Someone who shares no organization with them gets nothing, as for a person they cannot see: `GET /api/status/people` leaves them out. A visitor, signed in as no one, is refused with a `401`. <gap>`GET /api/status/people` cannot page because paging statuses is not implemented, so it answers every status set by those who share an organization with the caller, which suits a team, not thousands of people.</gap>
|
|
52
|
+
|
|
53
|
+
## How it clears
|
|
54
|
+
|
|
55
|
+
A status ends at its clear time for everyone, also while the person has no page open: the server reads a status whose time has passed as none, and do not disturb ends with it.
|
|
56
|
+
|
|
57
|
+
A page reads the statuses again every 15 seconds while it is in view, and when it comes back into view, over the connections it already has, so another person's change, or a status whose time has passed, shows within 15 seconds without reloading. It opens no connection of its own: a page near the 6 connections a browser keeps per server under HTTP/1.1 keeps working.
|
|
58
|
+
|
|
59
|
+
## Do not disturb
|
|
60
|
+
|
|
61
|
+
While someone is on do not disturb, when a [send](notifications.md#sending)'s job runs, the send pushes to none of their devices, through any sender, built-in or the app's own. A send for the inbox still keeps the notification in their history, so the bell shows it and counts it unread. Nothing of that send is pushed later, when do not disturb ends. The others in the same send are pushed as usual. A send to devices, `{ deviceIds }`, holds the devices of someone on do not disturb too. Busy is a mark only, and holds nothing.
|
|
62
|
+
|
|
63
|
+
Your own server code asks the same question with `onDoNotDisturb(db, statusNames(options), userIds)` from `@protobase/server`, which answers the set of those on do not disturb now, so whatever else alerts people holds it alike.
|
|
64
|
+
|
|
65
|
+
## In the app
|
|
66
|
+
|
|
67
|
+
The organization's members page shows each member's status beside their name. `useMembers()` from `@protobase/ui` gives each member their `status` when they have one, beside their name and photo, and `useStatuses()` the statuses alone. `StatusMark` draws a status beside a name: a mark for busy, one for do not disturb, and the text, in full or, with `textShown="hover"`, on hover. Who is online or away is each app's own, from its [presence](channels.md#presence); pass its mark as `presence`, and `StatusMark` draws it first, so the two sit side by side:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { StatusMark, useMembers } from '@protobase/ui'
|
|
71
|
+
|
|
72
|
+
export const Person = ({ id, online }: { id: string; online: boolean }) => {
|
|
73
|
+
const person = useMembers().member(id)
|
|
74
|
+
if (!person) return null
|
|
75
|
+
const dot = <span role="img" aria-label={online ? 'Online' : 'Away'} className={online ? 'size-2 rounded-full bg-success' : 'size-2 rounded-full bg-muted'} />
|
|
76
|
+
return (
|
|
77
|
+
<span className="flex items-center gap-1.5">
|
|
78
|
+
{person.name}
|
|
79
|
+
<StatusMark status={person.status} presence={dot} textShown="hover" />
|
|
80
|
+
</span>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`StatusMark` draws nothing of a status whose clear time has passed, even before the page reads the statuses again.
|
|
86
|
+
|
|
87
|
+
## The client
|
|
88
|
+
|
|
89
|
+
`client.status` of `@protobase/client` reads and sets the signed-in person's own status and reads the others':
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const lunch = await client.status.set({ availability: 'busy', text: 'Having lunch', clearsAt: new Date(Date.now() + 3_600_000).toISOString() })
|
|
93
|
+
const everyone = await client.status.people()
|
|
94
|
+
await client.status.clear()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`set` rejects with an `ApiError` whose `slug` is `invalid-status-text`, `invalid-clear-time` or `invalid-status` for what the server refuses, and `own-sign-in-only` for staff signed in as the person.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The user menu at the bottom of the sidebar, with the app's own account pages and links.
|
|
6
6
|
|
|
7
|
-
The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu with their name and email, which link to their account, the app's own pages, the theme switch, and "Sign out". Account pages (organization, billing, users) and help links belong here rather than among the working resources.
|
|
7
|
+
The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu with their name and email, which link to their account, "Set a status" in an app with [status](status.md), the app's own pages, the theme switch, and "Sign out". Account pages (organization, billing, users) and help links belong here rather than among the working resources.
|
|
8
8
|
|
|
9
9
|
Export one [`userMenu(...)`](https://docs.protobase.net/api/schema/functions/usermenu/) from `config/index.ts`:
|
|
10
10
|
|