@protobase/cli 0.62.4 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/dev/api-websockets.js +1 -1
- package/dist/migration/parts.js +1 -1
- package/dist/project/api-websocket-server.js +6 -4
- package/package.json +7 -7
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/calls.md +1 -1
- package/skills/protobase/references/features/email-and-public-forms.md +2 -0
- package/skills/protobase/references/guides/send-from-gmail.md +68 -0
- package/skills/protobase/references/reference/auth.md +2 -2
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/calls.md +57 -3
- package/skills/protobase/references/reference/config/sign-in.md +13 -0
- package/skills/protobase/references/reference/email.md +55 -0
package/dist/cli/package.js
CHANGED
|
@@ -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.
|
package/dist/migration/parts.js
CHANGED
|
@@ -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
|
|
15
|
-
* `maxFrameBytes` for any other, so a path this does not recognise
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.63.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": {
|
|
@@ -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.
|
|
46
|
-
"@protobase/layout": "0.
|
|
47
|
-
"@protobase/query": "0.
|
|
48
|
-
"@protobase/schema": "0.
|
|
49
|
-
"@protobase/server": "0.
|
|
50
|
-
"@protobase/ui": "0.
|
|
45
|
+
"@protobase/config": "0.63.0",
|
|
46
|
+
"@protobase/layout": "0.63.0",
|
|
47
|
+
"@protobase/query": "0.63.0",
|
|
48
|
+
"@protobase/schema": "0.63.0",
|
|
49
|
+
"@protobase/server": "0.63.0",
|
|
50
|
+
"@protobase/ui": "0.63.0",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -57,6 +57,7 @@ Guides:
|
|
|
57
57
|
- When letting users save a list as Excel or CSV → read [Exporting a list](references/guides/export-a-list.md)
|
|
58
58
|
- When importing records from a spreadsheet → read [Importing records from a spreadsheet](references/guides/import-records.md)
|
|
59
59
|
- When telling users about a change, in the bell and as push on their browsers → read [Send notifications](references/guides/push-notifications.md)
|
|
60
|
+
- When sending mail from a person's own Gmail, such as an invoice with its PDF attached → read [Send mail from Gmail](references/guides/send-from-gmail.md)
|
|
60
61
|
- When replacing a resource's create form with a page of your own → read [A create page of your own](references/guides/create-page.md)
|
|
61
62
|
- When letting each person set a choice of their own, such as which emails they get → read [Add a personal setting](references/guides/personal-setting.md)
|
|
62
63
|
- When running the app on iOS or Android → read [A mobile app](references/guides/mobile-app.md)
|
|
@@ -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.
|
|
@@ -7,6 +7,8 @@ Mail the app sends, and forms for people without an account.
|
|
|
7
7
|
- [Email](../reference/email.md#configuration): The app sends mail through one SMTP server or a mailer you supply.
|
|
8
8
|
- [Built-in emails](../reference/email.md#protobases-own-mail): Sign-in codes, password resets, invitations and mentions are sent in the app's name.
|
|
9
9
|
- [Email templates](../reference/email.md#templates): Your own emails are React components with typed data, sent from jobs, hooks or functions.
|
|
10
|
+
- [Attachments](../reference/email.md#attachments): A message carries files, such as an invoice's PDF, through the app's mail or someone's own mailbox.
|
|
11
|
+
- [Mail from your own mailbox](../reference/email.md#from-someones-own-mailbox) (beta): People link their Gmail on the account page, and the app's functions send mail from it, with a clear error when the link is missing or expired.
|
|
10
12
|
- [Public forms](../reference/forms.md#what-the-visitor-sees): A form at its own address lets people without an account create a record, such as a contact request.
|
|
11
13
|
- [Bot check](../reference/forms.md#bot-check): Each submission passes a check in the browser, without a third-party service or a puzzle.
|
|
12
14
|
- [Form rate limit](../reference/forms.md#rate-limit): Each client sends only a set number of submissions per minute.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from docs/website/src/content/docs/guides/send-from-gmail.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Send mail from Gmail
|
|
4
|
+
|
|
5
|
+
Set up a Google OAuth client so people link their Gmail on the account page, and send mail with attachments from it in an API function.
|
|
6
|
+
|
|
7
|
+
People of your app link their own Gmail once, on the account page, and your [API functions](api-functions.md) send mail from it, such as an invoice with its PDF attached. This guide sets up the Google side, turns it on in the config and sends a first message. [From someone's own mailbox](../reference/email.md#from-someones-own-mailbox) has the details.
|
|
8
|
+
|
|
9
|
+
## 1. Make the Google OAuth client
|
|
10
|
+
|
|
11
|
+
In the Google Cloud console, in a project of your own:
|
|
12
|
+
|
|
13
|
+
1. **Turn on the Gmail API:** APIs & Services → Library → Gmail API → Enable.
|
|
14
|
+
2. **Set up the consent screen** (Google Auth Platform → Branding and Audience): the app's name, support address and home page, and the user type **External**, so any Google account can link, not only those of your Workspace.
|
|
15
|
+
3. **Add the scope** (Data Access): `https://www.googleapis.com/auth/gmail.send`, beside `openid`, `email` and `profile`. It lets the app send mail as the person and nothing else: it cannot read their mailbox.
|
|
16
|
+
4. **Publish the app** (Audience → Publish app), so its publishing status is **In production**. Do not leave it in **Testing**: Google then gives refresh tokens that expire after 7 days, so every link stops working a week after it was made, and sending fails with `link_expired`.
|
|
17
|
+
5. **Make the client** (Clients → Create client): type **Web application**, with the authorized redirect URI `<url>/api/auth/callback/google`, such as `https://invoices.example.com/api/auth/callback/google`, and the same path on each of the app's [other origins](../reference/auth.md#several-origins) people link from. For local development add `http://localhost:<port>/api/auth/callback/google` too.
|
|
18
|
+
|
|
19
|
+
Keep the client ID and secret for the next step.
|
|
20
|
+
|
|
21
|
+
`gmail.send` is a sensitive scope: until Google has verified your app, the consent screen warns that the app is unverified, and at most 100 people can link. Submit the app for verification (Verification Center) before you open it to more.
|
|
22
|
+
|
|
23
|
+
## 2. Turn it on
|
|
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:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
# .env
|
|
29
|
+
GOOGLE_CLIENT_ID=1234567890-abc.apps.googleusercontent.com
|
|
30
|
+
GOOGLE_CLIENT_SECRET=GOCSPX-...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// protobase.config.ts
|
|
35
|
+
export default defineConfig(({ env }) => ({
|
|
36
|
+
auth: {
|
|
37
|
+
socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } },
|
|
38
|
+
personalMail: ['gmail'],
|
|
39
|
+
encryptOAuthTokens: true,
|
|
40
|
+
},
|
|
41
|
+
}))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 3. Link a mailbox
|
|
45
|
+
|
|
46
|
+
Signed in, open the account page (`/-/account`): under **Mailbox** it offers "Connect Gmail". Google asks which account to use and whether the app may send mail as it, then sends you back to the account page, which now says **Connected**. Someone who already signs in with Google still connects here, as their sign-in did not allow sending mail. The Google account may have another address than the one they sign in with.
|
|
47
|
+
|
|
48
|
+
## 4. Send from it
|
|
49
|
+
|
|
50
|
+
A protected function's context has the caller's mailbox as `personalMail`. Send a message with an attachment, and answer a missing or expired link with its own problem, which the function passes on as a `409` with its `code`:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// functions/send-invoice.ts
|
|
54
|
+
import { defineFunction } from '@protobase/server'
|
|
55
|
+
|
|
56
|
+
export default defineFunction(async (request, { personalMail }) => {
|
|
57
|
+
const { to, number, pdfBase64 } = (await request.json()) as { to: string; number: number; pdfBase64: string }
|
|
58
|
+
await personalMail.send({
|
|
59
|
+
to,
|
|
60
|
+
subject: `Invoice ${number}`,
|
|
61
|
+
text: 'Your invoice is attached.',
|
|
62
|
+
attachments: [{ filename: `invoice-${number}.pdf`, content: Buffer.from(pdfBase64, 'base64'), contentType: 'application/pdf' }],
|
|
63
|
+
})
|
|
64
|
+
return new Response(null, { status: 204 })
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The message goes out from the linked Gmail, and shows in its Sent folder. When the person linked nothing the call answers `409` with `code: "not_linked"`, and when Google no longer honours the link, as after they removed the app from their Google account, `code: "link_expired"`: point them to the account page to connect Gmail again.
|
|
@@ -189,12 +189,12 @@ Everyone signed in has an account page at `/-/account`, which "Account" in the u
|
|
|
189
189
|
|
|
190
190
|
| Tab | Address | Blocks |
|
|
191
191
|
| --- | --- | --- |
|
|
192
|
-
| Profile | `/-/account` | `Profile`, `DeleteAccount` |
|
|
192
|
+
| Profile | `/-/account` | `Profile`, `PersonalMail`, `DeleteAccount` |
|
|
193
193
|
| Sign-in & security | `/-/account/security` | `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts` |
|
|
194
194
|
| Devices | `/-/account/devices` | `Devices` |
|
|
195
195
|
| Connected apps | `/-/account/apps` | `ConnectedApps` |
|
|
196
196
|
|
|
197
|
-
A tab whose blocks all leave themselves out is not offered, such as Connected apps in an app without [MCP](#oauth-for-mcp-clients). `DeleteAccount` leaves itself out when the app turns [account deletion](#deleting-the-account) off.
|
|
197
|
+
A tab whose blocks all leave themselves out is not offered, such as Connected apps in an app without [MCP](#oauth-for-mcp-clients). `DeleteAccount` leaves itself out when the app turns [account deletion](#deleting-the-account) off, and `PersonalMail` in an app without [personal mail](email.md#from-someones-own-mailbox).
|
|
198
198
|
|
|
199
199
|
To change it, export a page named `account` of your own: it replaces the standard one at `/-/account`, and is neither at `/account` nor in the sidebar. `accountTabs` holds the standard tabs by name (`profile`, `security`, `devices`, `apps`), so the page lists the ones it keeps beside its own:
|
|
200
200
|
|
|
@@ -390,7 +390,7 @@ Everyone who can sign in, for admins: find them by address, tick their roles, bl
|
|
|
390
390
|
|
|
391
391
|
### Account blocks
|
|
392
392
|
|
|
393
|
-
`Profile`, `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts`, `Devices`, `ConnectedApps` and `DeleteAccount` are the parts of the signed-in person's own account: their name and address (which they can change, the address with an [emailed code](auth.md#changing-the-address)), their [password](auth.md#name-password-and-devices) (changed, or set for the first time), their [passkeys](auth.md#passkeys), [two-factor authentication](auth.md#two-factor-authentication), the sign-in providers they linked, the devices signed in as them (each one but this one to [sign out](auth.md#name-password-and-devices)), the apps such as MCP clients they allowed to act as them, below the app's MCP address to connect one, and the [deletion of their account](auth.md#deleting-the-account). Each takes no props or children, reads its own data, and leaves itself out where it does not apply: `ConnectedAccounts` without an OAuth sign-in provider, `ConnectedApps` without MCP, `DeleteAccount` with `auth.accountDeletion: false`. They act on whoever is signed in, so they are allowed on the page named `account` alone; anywhere else stops the config. That page is the [account page](auth.md#account-page) at `/-/account`, which `accountTabs` helps build from the standard tabs.
|
|
393
|
+
`Profile`, `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts`, `PersonalMail`, `Devices`, `ConnectedApps` and `DeleteAccount` are the parts of the signed-in person's own account: their name and address (which they can change, the address with an [emailed code](auth.md#changing-the-address)), their [password](auth.md#name-password-and-devices) (changed, or set for the first time), their [passkeys](auth.md#passkeys), [two-factor authentication](auth.md#two-factor-authentication), the sign-in providers they linked, the [mailbox](email.md#from-someones-own-mailbox) they linked for the app to send mail from, the devices signed in as them (each one but this one to [sign out](auth.md#name-password-and-devices)), the apps such as MCP clients they allowed to act as them, below the app's MCP address to connect one, and the [deletion of their account](auth.md#deleting-the-account). Each takes no props or children, reads its own data, and leaves itself out where it does not apply: `ConnectedAccounts` without an OAuth sign-in provider, `PersonalMail` without `auth.personalMail`, `ConnectedApps` without MCP, `DeleteAccount` with `auth.accountDeletion: false`. They act on whoever is signed in, so they are allowed on the page named `account` alone; anywhere else stops the config. That page is the [account page](auth.md#account-page) at `/-/account`, which `accountTabs` helps build from the standard tabs.
|
|
394
394
|
|
|
395
395
|
```tsx
|
|
396
396
|
export const account = page('account',
|
|
@@ -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
|
|
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 }]
|
|
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
|
|
|
@@ -128,6 +128,19 @@ export default defineConfig(({ env }) => ({
|
|
|
128
128
|
}))
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
## auth.personalMail
|
|
132
|
+
|
|
133
|
+
- **Type:** `'gmail'[]`
|
|
134
|
+
- **Default:** none
|
|
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).
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
export default defineConfig(({ env }) => ({
|
|
140
|
+
auth: { socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } }, personalMail: ['gmail'] },
|
|
141
|
+
}))
|
|
142
|
+
```
|
|
143
|
+
|
|
131
144
|
## auth.encryptOAuthTokens
|
|
132
145
|
|
|
133
146
|
- **Type:** `boolean`
|
|
@@ -198,6 +198,61 @@ export default defineFunction({ roles: ['desk'] }, async (request, { records })
|
|
|
198
198
|
|
|
199
199
|
A message is sent once per call, so a job try that sends and then fails sends again: record what was sent, and check it first.
|
|
200
200
|
|
|
201
|
+
## Attachments
|
|
202
|
+
|
|
203
|
+
A message takes files beside its body, such as an invoice's PDF: `attachments`, each a `filename`, its bytes as `content` (a `Uint8Array`, such as a `Buffer`) and, optionally, its `contentType`, else the one the name implies. A template's `send` takes them as its fourth argument:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
await invoiceEmail.send(client.email, { number: 7 }, mail, { attachments: [{ filename: 'invoice-7.pdf', content: pdf, contentType: 'application/pdf' }] })
|
|
207
|
+
await mail.send({ to: client.email, subject: 'Invoice 7', text: 'Attached.', attachments: [{ filename: 'invoice-7.pdf', content: pdf }] })
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
An attachment is only the bytes given: a file path or URL is never read in its place. A mailer of the project's own (`auth/mailer.ts`) gets them in `message.attachments`.
|
|
211
|
+
|
|
212
|
+
## From someone's own mailbox
|
|
213
|
+
|
|
214
|
+
:::caution[Beta]
|
|
215
|
+
Gmail is the only mail provider so far, and only API functions send from a mailbox: jobs cannot yet.
|
|
216
|
+
:::
|
|
217
|
+
|
|
218
|
+
An app can send mail from the signed-in person's own mailbox instead of the app's address, such as an invoice from the account holder's Gmail, so replies reach them. They link the mailbox once on the [account page](auth.md#account-page) ("Connect Gmail" under **Mailbox**), which asks the provider for leave to send mail and nothing else; the app's functions then send through it. `auth.personalMail` names the providers people may link, each through the app's sign-in provider of the same company; Gmail links through Google sign-in (see [Send mail from Gmail](../guides/send-from-gmail.md) for the Google setup):
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
export default defineConfig(({ env }) => ({
|
|
222
|
+
auth: {
|
|
223
|
+
socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } },
|
|
224
|
+
personalMail: ['gmail'],
|
|
225
|
+
encryptOAuthTokens: true,
|
|
226
|
+
},
|
|
227
|
+
}))
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
A protected [API function](../guides/api-functions.md) gets the caller's mailbox as `personalMail`, a mailer like any other, so a template sends through it too:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import { defineFunction } from '@protobase/server'
|
|
234
|
+
import { invoiceEmail } from '../emails/invoice'
|
|
235
|
+
|
|
236
|
+
export default defineFunction(async (request, { personalMail }) => {
|
|
237
|
+
const { to, number, pdf } = await readInvoice(request)
|
|
238
|
+
await invoiceEmail.send(to, { number }, personalMail, { attachments: [{ filename: `invoice-${number}.pdf`, content: pdf, contentType: 'application/pdf' }] })
|
|
239
|
+
return new Response(null, { status: 204 })
|
|
240
|
+
})
|
|
241
|
+
```
|
|
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.
|
|
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
|
+
|
|
246
|
+
```json
|
|
247
|
+
{ "type": "urn:protobase:problem:personal-mail-link-expired", "status": 409, "code": "link_expired", "provider": "gmail" }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
- **Sender:** the provider sends as the linked address; Gmail sets the From header to it.
|
|
251
|
+
- **Only the person:** mail goes out from a mailbox only for someone signed in as themselves. Staff [signed in as them](auth.md#staff-sign-in), or an outside app acting for them, is refused with a `403` problem (`own-sign-in-only`), and nothing is sent.
|
|
252
|
+
- **Providers:** Gmail, through Google sign-in. A provider is added to Protobase behind the same `PersonalMailProvider` shape: its sign-in provider, the scopes linking asks for, and how it sends.
|
|
253
|
+
- <gap>Jobs cannot send from someone's own mailbox because a job's context has no personal mailer.</gap>
|
|
254
|
+
- <gap>Mailboxes other than Gmail cannot be linked because no other mail provider is implemented.</gap>
|
|
255
|
+
|
|
201
256
|
## In a bundle
|
|
202
257
|
|
|
203
258
|
A [bundle](cli.md#the-config-module) gets React and React Email's renderer from the serve runtime, as it gets `@protobase/server` and `@protobase/server/email`, so an email's component and the renderer share one React and hooks such as `useContext` work. React Email's other components are inlined, though `@protobase/server` uses them too: it loads them only to send its own mail, so the runtime does not supply them. Its `<Tailwind>` component needs `tailwindcss`, which the runtime does not supply, so a served config cannot use it: style with `style` props instead.
|