@protobase/cli 0.62.5 → 0.63.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.62.5";
2
+ var version = "0.63.1";
3
3
  //#endregion
4
4
  export { version };
@@ -1,6 +1,6 @@
1
1
  import { isAllowedHost } from "./allowed-host.js";
2
2
  //#region src/dev/api-websockets.ts
3
- const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/channels(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url);
3
+ const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/channels(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url) || /^\/api\/calls\/guests\/socket(\?|$)/.test(url);
4
4
  /**
5
5
  * The listener for Vite's `upgrade` event: an API socket goes to `forward` once its Host passes Vite's host check, as
6
6
  * every other dev request does, and is refused with 403 otherwise; any other upgrade is left to Vite.
@@ -53,7 +53,7 @@ const migrationParts = (project) => {
53
53
  }] : [],
54
54
  ...project.calls ? [{
55
55
  name: "calls",
56
- title: "The calls on records, who is in them, whom they ring, and the signals between the processes serving the app",
56
+ title: "The calls on records, who is in them, whom they ring, their guests, and the signals between the processes serving the app",
57
57
  sql: () => callsMigration(project.db, project.events)
58
58
  }] : [],
59
59
  ...relayed(project.realtime) ? [{
@@ -9,15 +9,17 @@ const npmWebSocketServer = () => {
9
9
  return require(path.join(path.dirname(require.resolve("ws/package.json")), "index.js")).WebSocketServer;
10
10
  };
11
11
  const functionsPrefix = "/api/functions/";
12
+ const guestSocketPath = "/api/calls/guests/socket";
12
13
  const functionMaxPayload = 104857600;
13
14
  /**
14
- * The frame cap of a socket upgraded at `url`: ws's default for an api function's socket, and realtime's
15
- * `maxFrameBytes` for any other, so a path this does not recognise as a function's, such as an encoded one, gets the
16
- * smaller cap.
15
+ * The frame cap of a socket upgraded at `url`: ws's default for an api function's socket and the guests' call socket,
16
+ * which lower it to their own, and realtime's `maxFrameBytes` for any other, so a path this does not recognise, such
17
+ * as an encoded one, gets the smaller cap.
17
18
  */
18
19
  const maxPayloadOf = (url) => {
19
20
  if (!URL.canParse(url, "http://localhost")) return realtimeLimits.maxFrameBytes;
20
- return new URL(url, "http://localhost").pathname.startsWith(functionsPrefix) ? functionMaxPayload : realtimeLimits.maxFrameBytes;
21
+ const { pathname } = new URL(url, "http://localhost");
22
+ return pathname.startsWith(functionsPrefix) || pathname === guestSocketPath ? functionMaxPayload : realtimeLimits.maxFrameBytes;
21
23
  };
22
24
  /**
23
25
  * The server of npm `ws` that upgrades the API's sockets, realtime's and the app's functions', on Node and Bun: a frame
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.62.5",
3
+ "version": "0.63.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": {
@@ -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.62.5",
46
- "@protobase/layout": "0.62.5",
47
- "@protobase/query": "0.62.5",
48
- "@protobase/schema": "0.62.5",
49
- "@protobase/server": "0.62.5",
50
- "@protobase/ui": "0.62.5",
45
+ "@protobase/config": "0.63.1",
46
+ "@protobase/layout": "0.63.1",
47
+ "@protobase/query": "0.63.1",
48
+ "@protobase/schema": "0.63.1",
49
+ "@protobase/server": "0.63.1",
50
+ "@protobase/ui": "0.63.1",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -4,7 +4,7 @@
4
4
 
5
5
  Audio and video calls between an app's users, through LiveKit or peer to peer, with Protobase deciding who is in a call and who hears whom.
6
6
 
7
- - [Calls](../reference/calls.md) (beta): Voice and video calls on any record, with screen sharing, a ready-made call view and ringing on any open page.
7
+ - [Calls](../reference/calls.md) (beta): Voice and video calls on any record, with screen sharing, a ready-made call view and ringing on any open page, and guest links that let someone from outside join one call.
8
8
  - [LiveKit](../reference/calls.md#livekit) (in development): The media goes through a LiveKit server, self-hosted or LiveKit Cloud, which Protobase speaks to for each member.
9
9
  - [Peer to peer](../reference/calls.md#peer-to-peer) (in development): With no media server, the members' browsers send their media straight to each other, for small calls.
10
10
  - [Admitting members](../reference/calls.md#admitting-members) (in development): A function of your own admits the caller to a call with what they may send and whose tracks they hear.
@@ -22,7 +22,7 @@ Keep the client ID and secret for the next step.
22
22
 
23
23
  ## 2. Turn it on
24
24
 
25
- Put the client's ID and secret in the app's environment, and name Gmail in `auth.personalMail`. Gmail links through Google sign-in, so `socialProviders` has `google`; it also offers "Continue with Google" on the sign-in page. `encryptOAuthTokens` stores the tokens encrypted with the app's secret:
25
+ Put the client's ID and secret in the app's environment, and name Gmail in `auth.personalMail`. Gmail links through Google sign-in, so `socialProviders` has `google`; it also offers "Continue with Google" on the sign-in page. `encryptOAuthTokens` stores the tokens encrypted with the app's secret, and personal mail needs it:
26
26
 
27
27
  ```sh
28
28
  # .env
@@ -480,7 +480,8 @@ export default defineConfig(({ env }) => ({
480
480
  - The callback URL to register with GitHub is `<url>/api/auth/callback/github`, and the same path on each of the app's [other origins](#several-origins) it should sign in on. A GitHub OAuth App takes one callback URL, so it covers one origin; a GitHub App takes several. A GitHub App needs the Email addresses (read-only) account permission, or sign-in fails with `email_not_found`.
481
481
  - A provider is also a public sign-up: someone without an account gets one with the [default role](#roles). Without a default role the sign-up is refused.
482
482
  - `GET /api/auth/status` lists the provider ids as `socialProviders`.
483
- - `encryptOAuthTokens: true` stores the provider's access, refresh and ID tokens encrypted with the secret.
483
+ - `encryptOAuthTokens: true` stores the provider's access and refresh tokens encrypted with the secret. <gap>`encryptOAuthTokens` cannot protect the provider's ID token, which is stored as the provider gave it, because encrypting or dropping it is not implemented.</gap>
484
+ - The provider's tokens stay on the server: Better Auth's `/api/auth/get-access-token` and `/api/auth/refresh-token`, which would answer the browser with them, are turned off.
484
485
  - The `onUserCreated` [hook](#hooks) runs after any user is created, a social sign-up included (Better Auth's `databaseHooks.user.create.after`).
485
486
 
486
487
  ### Sign-in links and connected accounts
@@ -5,7 +5,7 @@
5
5
  Audio and video calls on any record of an app, through a LiveKit server or straight between browsers, with Protobase deciding who is in a call, who may send and who hears whom.
6
6
 
7
7
  :::caution[Beta]
8
- Calls live on records, with who is in them, removal and their end, a ready-made call view and ringing. The view is made for small peer-to-peer calls, and there are no host controls yet. A lobby, stage mode, recording and guests are not built yet, and calls have been tested in Chromium and Firefox only.
8
+ Calls live on records, with who is in them, removal and their end, a ready-made call view, ringing and guest links. The view is made for small peer-to-peer calls, and there are no host controls yet. Stage mode and recording are not built yet, and calls have been tested in Chromium and Firefox only.
9
9
  :::
10
10
 
11
11
  ## Turning them on
@@ -69,12 +69,14 @@ export default defineFunction(async (request, { session, records, acceptWebSocke
69
69
  | `publish` | `true` to send any source, a list of `'camera'`, `'microphone'`, `'screen'` and `'screen-audio'`, or `false` to only listen. |
70
70
  | `hears` | Optional: which of the others' tracks the member hears, as `(track) => boolean` of `{ member, kind, source }`; every track by default. |
71
71
  | `recheck` | Optional: the function's own checks, such as whether the caller is still invited, repeated every minute. Throw a 401, 403 or 404 problem to take the member out. |
72
+ | `name` | Optional: the name the others in the call see, such as the user's name. [Guests](#guests) see members by it alone. |
73
+ | `invites` | Optional: `true` lets the member share [guest links](#guests) to the call and let its guests in; `false` by default. |
72
74
 
73
75
  The socket is checked again every minute, like any function's, and so is the caller's read of the record, then `recheck`: a member who can no longer read the record, or whom `recheck` refuses, is out of the call within the minute, and so is one whose check fails or takes longer than a minute. Pass your own check as `recheck` to `calls.join`, not on the events it returns, which would replace the record's check. A member who joins the same call again, from another tab, takes the place of their first socket.
74
76
 
75
77
  ### Who is in it
76
78
 
77
- Each member's browser gets everyone in the call, themselves too, members who send nothing included, whenever that changes: `onMembers` of `joinCall`, and `call.members()`, as `[{ member, joined_at }]`. A change made on the process that serves a member reaches them at once; one made on another process, within a second.
79
+ Each member's browser gets everyone in the call, themselves too, members who send nothing included, whenever that changes: `onMembers` of `joinCall`, and `call.members()`, as `[{ member, joined_at, name? }]`, with `name` for a member your function named and for every guest. A change made on the process that serves a member reaches them at once; one made on another process, within a second.
78
80
 
79
81
  The record's readers get its calls, each with who is in it now, at `GET /api/{resource}/{key}:calls`, the one going on first, then the newest, 20 at most:
80
82
 
@@ -195,6 +197,58 @@ With [notifications](notifications.md), each person rung also gets the call in t
195
197
 
196
198
  `client.rings.list()` and `client.rings.decline(call)` of `@protobase/client` read and decline the calls ringing the signed-in user, for a ring of your own.
197
199
 
200
+ ## Guests
201
+
202
+ Share a link to one call with someone from outside, such as a candidate for a job interview: the guest gives a name, checks their microphone and camera, and waits in a lobby until someone in the call admits them. A guest has no account and reaches nothing but that call: not the record, its chat, its readers' list of calls, or anything else in the app.
203
+
204
+ ### Sharing a link
205
+
206
+ A member your function joins with `invites: true` gets Guests in the call view: a link to share, with what its guests may send (camera, microphone and screen; camera and microphone; or microphone only, never more than the member may send themselves), the links that are live, with Revoke, and who waits in the lobby, with Let in and Turn away. Someone who waits also shows above the call, to let in without opening Guests.
207
+
208
+ ```ts
209
+ // The name the others see, from the app's own records of its people.
210
+ const { record: me } = await records.get('people', String(session.user.id))
211
+ return acceptWebSocket(
212
+ await calls.join({
213
+ record: { resource: 'interviews', key: id },
214
+ member: String(session.user.id),
215
+ name: String(me.name),
216
+ publish: true,
217
+ invites: true,
218
+ }),
219
+ )
220
+ ```
221
+
222
+ A link opens `/-/call-guest` with its token after `#`, which the browser sends to no server. It lets guests in until the call ends, or for an hour when made so, or until the time `call.guests.link({ publish, expiresAt })` gives it, unless a member revokes it first. At most 10 wait on a link at once, and once its members turned away 3 guests, it lets nobody else wait: make a new link.
223
+
224
+ ### What a guest gets
225
+
226
+ The page a link opens asks the guest's name, then shows the call view's check of their microphone and camera, with Ask to join, then "Waiting for someone in the call to let you in" until a member lets them in or turns them away. Once in, the guest is `guest:<id>` in the call, shown by the name they gave with "(guest)", and sends only what their link allows. They see the members by the `name` your function gave, or as "Someone in the call".
227
+
228
+ The guest's token opens their lobby wait and the guest call socket, and nothing else: no other route takes it, it is no session, and no cookie is set. Members' functions never take a member of the form `guest:…`.
229
+
230
+ ### Taking a guest out
231
+
232
+ Revoking a link takes its guests out of the call, and Remove in Guests, or `calls.remove(call, 'guest:<id>')` in a function, takes out one. Their sockets close, and their joins and resumes are refused. Every guest's socket is checked again every minute too, and is closed once their link is revoked or past its time, they were removed, or guest links were turned off.
233
+
234
+ A call left with only guests in it ends 2 minutes after the last member left, and the guests see "The call ended". A member who comes back before then keeps it going.
235
+
236
+ ### Organizations
237
+
238
+ In an app with [organizations](auth.md#organizations), a link is for the organization of the call's record, and the organization's owner or an admin can turn guest links off on the organization's page, or with `PUT /api/calls/guests/organization` and `{ "allowed": false }`. That revokes every live link of its calls and takes their guests out at once, and no member can make a new link until it is on again. A call on a record of a resource without a tenant gets no guest links in an app with organizations, since no organization's switch could stop them.
239
+
240
+ ### Safety
241
+
242
+ The lobby is rate limited like the sign-in routes, by the address the sign-in routes use: 5 lobby entries a minute per address, and an address that sends 10 unknown or refused tokens in a minute is refused for the rest of that minute. <gap>The lobby's limits cannot hold across several processes because they are counted in each process's memory, as the sign-in routes' are.</gap>
243
+
244
+ In a peer-to-peer call, a guest and the members can see each other's network addresses, as their browsers connect to each other. A guest who waits, or was turned away, gets nothing of the call: no members, no tracks and no addresses. Protobase refuses what a guest may not send, but in a peer-to-peer call the media goes between the browsers, so a guest's browser that was changed to send more is only held back by the members' own browsers.
245
+
246
+ With `calls`, [`protobase migration`](cli.md#migration) adds the guests' tables to the `calls` schema, a calls schema made before them too.
247
+
248
+ ### From your own page
249
+
250
+ `guestLobby` from `@protobase/client/calls` is the guest's side, for a page of your own: `enter(link, name)` gives the guest's token, `wait(token)` says `waiting`, `admitted`, `denied` or `ended`, asked about once a second, and `leave(token)` leaves the lobby. Once admitted, `joinCall({ url: lobby.socketUrl, guest: token })` joins the call. A member's `call.guests` has `link({ publish, expiresAt })`, which resolves with the link and its token once, `revoke(link)`, `admit(guest)`, `deny(guest)` and `remove(guest)`, each rejecting with `GuestRefused` and its reason when the server did not; `onLobby` of `joinCall` gets who waits and the live links.
251
+
198
252
  ## Reconnecting
199
253
 
200
254
  When the socket to Protobase closes, such as during a deploy, media keeps flowing and the browser opens a new socket that resumes the member from its own state, through the function again, so a member who can no longer read the record, or was removed, is refused. Any process serving the app can take it; when LiveKit no longer knows the member, the browser joins again and sends the same tracks. After `maxRetries` tries in a row, 8 by default, the call is left.
@@ -207,7 +261,7 @@ When the socket to Protobase closes, such as during a deploy, media keeps flowin
207
261
 
208
262
  `kind: 'peer'`. Each member's browser keeps a peer connection to every other member's and sends them its media directly; Protobase passes their descriptions and candidates between the members of the same call only, and tells each member who else is in the call and which tracks they hear. `hears` decides which tracks a member is told of; the media itself goes between the browsers, which Protobase cannot stop.
209
263
 
210
- A peer-to-peer call holds a small group only: a browser uploads its media once per other member, so `maxMembers`, 8 by default, bounds it. Members of a peer-to-peer call can see each other's network addresses, as their browsers connect to each other; readers of the record who are not in the call cannot.
264
+ A peer-to-peer call holds a small group only: a browser uploads its media once per other member, so `maxMembers`, 8 by default, bounds it. Members of a peer-to-peer call, and its [guests](#guests), can see each other's network addresses, as their browsers connect to each other; readers of the record who are not in the call cannot.
211
265
 
212
266
  With `calls: { processes: 'many' }`, members that different processes serve meet in one call: a description or candidate for a member another process serves goes through the `calls` schema, which each process with a member in a call reads ten times a second.
213
267
 
@@ -133,11 +133,11 @@ export default defineConfig(({ env }) => ({
133
133
  - **Type:** `'gmail'[]`
134
134
  - **Default:** none
135
135
 
136
- The mail providers people may link their own mailbox with, for the app's functions to send mail from it; each links through its sign-in provider in `socialProviders`, Gmail through `google`. See [From someone's own mailbox](../email.md#from-someones-own-mailbox).
136
+ The mail providers people may link their own mailbox with, for the app's functions to send mail from it; each links through its sign-in provider in `socialProviders`, Gmail through `google`. It needs [`auth.encryptOAuthTokens`](#authencryptoauthtokens): without it, startup stops, since the linked mailboxes' tokens would be stored in plain text. See [From someone's own mailbox](../email.md#from-someones-own-mailbox).
137
137
 
138
138
  ```ts
139
139
  export default defineConfig(({ env }) => ({
140
- auth: { socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } }, personalMail: ['gmail'] },
140
+ auth: { socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } }, personalMail: ['gmail'], encryptOAuthTokens: true },
141
141
  }))
142
142
  ```
143
143
 
@@ -146,7 +146,7 @@ export default defineConfig(({ env }) => ({
146
146
  - **Type:** `boolean`
147
147
  - **Default:** `false`
148
148
 
149
- Encrypts the OAuth access, refresh and ID tokens kept for social sign-ins, with the app's secret.
149
+ Encrypts the OAuth access and refresh tokens kept for social sign-ins, with the app's secret. [`auth.personalMail`](#authpersonalmail) needs it.
150
150
 
151
151
  ```ts
152
152
  export default defineConfig({ auth: { encryptOAuthTokens: true } })
@@ -240,7 +240,7 @@ export default defineFunction(async (request, { personalMail }) => {
240
240
  })
241
241
  ```
242
242
 
243
- - **Tokens:** the link is the sign-in provider's account Better Auth keeps for the person, with its access and refresh tokens (encrypted with `encryptOAuthTokens: true`). An access token that has expired is refreshed before the message goes out, and the new one is stored.
243
+ - **Tokens:** the link is the sign-in provider's account Better Auth keeps for the person, with its access and refresh tokens, encrypted: `auth.personalMail` needs `encryptOAuthTokens: true`, and startup stops without it. The tokens never leave the server. An access token that has expired is refreshed before the message goes out, and the new one is stored.
244
244
  - **When it cannot send:** `send` rejects with a `PersonalMailError` and sends nothing. Its `code` is `not_linked` when the person linked no mailbox, or signed in with Google without allowing it to send mail, and `link_expired` when the provider no longer honours the link, as when they revoked it or its refresh token expired: they connect it again. Thrown on, it answers the function's caller as a `409` problem with that `code` (`urn:protobase:problem:personal-mail-not-linked` or `-link-expired`), so the page can offer to link the mailbox:
245
245
 
246
246
  ```json