@protobase/cli 0.85.1 → 0.86.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/email-and-public-forms.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/guides/send-from-gmail.md +10 -0
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/auth.md +19 -1
- package/skills/protobase/references/reference/config/sign-in.md +11 -0
- package/skills/protobase/references/reference/email.md +35 -1
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.1",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.86.1",
|
|
47
|
+
"@protobase/layout": "0.86.1",
|
|
48
|
+
"@protobase/query": "0.86.1",
|
|
49
|
+
"@protobase/schema": "0.86.1",
|
|
50
|
+
"@protobase/server": "0.86.1",
|
|
51
|
+
"@protobase/ui": "0.86.1",
|
|
52
|
+
"@protobase/workflows": "0.86.1",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -12,6 +12,7 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
|
|
|
12
12
|
- [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.
|
|
13
13
|
- [PDF documents](../reference/pdf.md#documents): PDF files such as invoices and quotes are React components with typed data, rendered from jobs, hooks or functions and attached to mail as they are.
|
|
14
14
|
- [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; an action offers to connect the mailbox right there when the link is missing or expired.
|
|
15
|
+
- [From addresses](../reference/email.md#from-addresses) (beta): People enter their mailbox's other send-as addresses once on the account page, each with a signature of its own, and the app sends from the one it names or their default.
|
|
15
16
|
- [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.
|
|
16
17
|
- [Bot check](../reference/forms.md#bot-check): Each submission passes a check in the browser, without a third-party service or a puzzle.
|
|
17
18
|
- [Form rate limit](../reference/forms.md#rate-limit): Each client sends only a set number of submissions per minute.
|
|
@@ -39,5 +39,6 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
39
39
|
- [Changing the secret](../reference/auth.md#changing-the-secret): The app's secret can change while the signing keys keep signing, by listing the old secret beside the new one.
|
|
40
40
|
- [Tokens for scripts](../reference/auth.md#tokens-for-scripts-and-curl): A token for an existing user, for scripts and curl, in any organization they work in.
|
|
41
41
|
- [Personal access tokens](../reference/personal-access-tokens.md): People make long-lived tokens on their account page for a script to call the API as them, see when each was last used, and revoke any of them. The app keeps only each token's hash.
|
|
42
|
+
- [OAuth tokens for the API](../reference/auth.md#oauth-tokens-for-the-api) (beta): A phone, watch or other app of your own signs people in through the app's own sign-in and calls the API as them with a bearer token, until they disconnect it.
|
|
42
43
|
- [Several origins](../reference/auth.md#several-origins): One app works on several domains, such as its own address and a custom domain.
|
|
43
44
|
- [Sign-in rate limits](../reference/auth.md#client-addresses): Sign-in and code requests are limited per client address, also behind a proxy.
|
|
@@ -66,3 +66,13 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
66
66
|
```
|
|
67
67
|
|
|
68
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"`. An action whose handler calls the function offers to connect Gmail right in its dialog then; mark it `mailbox: true` and it offers that before it runs, while nothing is linked ([Actions that send from someone's mailbox](../reference/ui-config.md#actions-that-send-from-someones-mailbox)).
|
|
69
|
+
|
|
70
|
+
## 5. Send from another address
|
|
71
|
+
|
|
72
|
+
A Gmail account may send as other addresses of yours, such as a company address beside your own. To have the app send from one:
|
|
73
|
+
|
|
74
|
+
1. **Set it up in Gmail first:** Gmail's settings → Accounts → **Send mail as** → Add another email address, and confirm it as Gmail asks. An alias of a Google Workspace domain is there already.
|
|
75
|
+
2. **Enter it once in the app:** on the account page, under **Mailbox** → **From addresses**, choose **Add a From address** and type it. Give it a signature of its own if you like, and make it the default to send from it whenever the app names no address.
|
|
76
|
+
3. **Name it when sending:** `personalMail.send({ from: 'billing@shop.example', to, subject, text })`.
|
|
77
|
+
|
|
78
|
+
Gmail sends from your primary address instead, without an error, when the address is not verified under **Send mail as**, so check the first message's From in the Sent folder. The app sends only from addresses entered this way: any other `from` is refused with a `403` before anything is sent. [From addresses](../reference/email.md#from-addresses) has the details.
|
|
@@ -222,7 +222,7 @@ The rules behind these steps are described under [Access](#access).
|
|
|
222
222
|
|
|
223
223
|
Real login is the app's [sign-in](auth.md). Lower level:
|
|
224
224
|
|
|
225
|
-
`authenticate(request)` returns `{ user: { id, roles }, tenant? }` or throws `unauthorized(...)` (a `401` problem), or `new MissingCredentials(...)` (also a `401`) when the request carries no credential at all. Shipped: `jwtAuthenticator({ jwksUrl | keys, issuer?, audience?, rolesClaim?, tenantClaim?, tenant? })`, which verifies a bearer token with `jose` (`sub` is the user id; `tenant` fixes the tenant instead of reading a claim), and the authenticator of the app's sign-in on top of it, which `authenticate` in the config sets ([Tokens and roles](auth.md#tokens-and-roles)); an authenticator of the project's own is the default export of `auth/authenticate.ts`. No code path treats a request as a user without verifying a credential; the one exception is the [anonymous role](access.md#anonymous-access), which the resources API gives a request that has none, when the project defines it.
|
|
225
|
+
`authenticate(request)` returns `{ user: { id, roles }, tenant? }` or throws `unauthorized(...)` (a `401` problem), or `new MissingCredentials(...)` (also a `401`) when the request carries no credential at all. Shipped: `jwtAuthenticator({ jwksUrl | keys, issuer?, audience?, rolesClaim?, tenantClaim?, tenant? })`, which verifies a bearer token with `jose` (`sub` is the user id; `tenant` fixes the tenant instead of reading a claim) and refuses a token bound to a key (`cnf`), which only a proof of that key may use, and the authenticator of the app's sign-in on top of it, which `authenticate` in the config sets ([Tokens and roles](auth.md#tokens-and-roles)) and which also takes [OAuth access tokens for the API](auth.md#oauth-tokens-for-the-api); an authenticator of the project's own is the default export of `auth/authenticate.ts`. No code path treats a request as a user without verifying a credential; the one exception is the [anonymous role](access.md#anonymous-access), which the resources API gives a request that has none, when the project defines it.
|
|
226
226
|
|
|
227
227
|
## CORS
|
|
228
228
|
|
|
@@ -780,7 +780,7 @@ auth: { mcp: { path: '/api/mcp', connectPage: '/-/connect' } }
|
|
|
780
780
|
- `path` is the MCP endpoint's path on the origin of the app's `url`, its OAuth resource (default `/api/mcp`); `connectPage` is the connect page's path (default `/-/connect`, for a UI at the root). A client's metadata document is fetched through a transport that refuses private and reserved addresses.
|
|
781
781
|
- It needs an https `url`, or localhost. Every store has the OAuth tables (see [migrations](#migrations)), so turning MCP on or off needs no migration. Turning it off drops nothing: the clients and grants stay, and work again once MCP is on, so disconnect the clients first to forget them. While MCP is off, ending a person's sessions, banning them or setting their password disconnects none of their clients. Clients connect through the origin of `url` only, whatever [other origins](#several-origins) the app has. Changing `path` makes every client connect again.
|
|
782
782
|
- Clients find the provider at `/.well-known/oauth-protected-resource` and `/.well-known/oauth-authorization-server`, register at `/api/auth/oauth2/register` (dynamic registration) or are known by an https client id that names their metadata document (CIMD), and are asked for nothing per client. Back-channel logout, a key set URL at registration (`jwks_uri`) and the client credentials grant are refused, though a client with a metadata document may publish its keys on its own origin, and the provider's client management, userinfo, logout and consent endpoints are closed.
|
|
783
|
-
- The scopes are `mcp` and `offline_access`, which is added when a client leaves it out. Access tokens last 15 minutes, carry the MCP resource as their audience and `typ: at+jwt`, and work for MCP only: the app's API refuses them, and the MCP endpoint refuses the app's own tokens. Refresh tokens roll for 30 days. The MCP endpoint verifies them, and checks on every request that the person still allows the client, still exists unbanned and still holds each role the token carries, so a disconnected client, a ban, a lowered role or a deleted user stops its access tokens at the next request rather than at their expiry; a lookup that fails refuses the request. A client that binds its tokens to a key (DPoP) sends a proof with each, checked against the resource's URL.
|
|
783
|
+
- The scopes are `mcp` and `offline_access`, which is added when a client leaves it out. Access tokens last 15 minutes, carry the MCP resource as their audience and `typ: at+jwt`, and work for MCP only: the app's API refuses them, and the MCP endpoint refuses the app's own tokens. Tokens for the API are [another resource](#oauth-tokens-for-the-api). Refresh tokens roll for 30 days. The MCP endpoint verifies them, and checks on every request that the person still allows the client, still exists unbanned and still holds each role the token carries, so a disconnected client, a ban, a lowered role or a deleted user stops its access tokens at the next request rather than at their expiry; a lookup that fails refuses the request. A client that binds its tokens to a key (DPoP) sends a proof with each, checked against the resource's URL.
|
|
784
784
|
- A grant keeps the role and organization the person worked in when they allowed the client. A refresh is refused once they no longer hold that role or may no longer enter that organization, once the [sign-in policy](#sign-in-policy) requires something they have not set up, and while they are banned; access tokens already issued last out their 15 minutes. A grant made without a role is refused.
|
|
785
785
|
- Someone who has not set up what the sign-in policy requires is sent to the setup page first. Staff signed in as a person cannot allow a client, nor disconnect one. An account whose address is not verified cannot connect a client until it signs in once with an emailed code: a provider sign-up whose provider did not vouch for the address, or a password account created before Protobase created accounts verified. With password-only sign-in, or without mail, it cannot.
|
|
786
786
|
- The connect page shows the client's name as the client's own claim, who published it for a client with an https id, where the code goes (a website by its host, an app on this computer by its port, or an app on the device by its whole address), and the signed-in address. It cannot be used inside another site's frame, and Allow takes a click only once the page has been in front for half a second. `protobase serve` and `protobase dev` send `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'` with every page of the UI; a host that serves `public/` itself should send them too. A host's own consent screen arms its Allow button the same way with the guard `@protobase/ui` exports (see [the plugin API](plugins.md#api)).
|
|
@@ -788,6 +788,24 @@ auth: { mcp: { path: '/api/mcp', connectPage: '/-/connect' } }
|
|
|
788
788
|
- Signing out everywhere, signing out the other devices, a password change, a password reset, an admin ending the person's sessions, banning them, setting their password or marking their address unverified, and `protobase users disable` disconnect every client and forget which were allowed, so each has to ask again; enabling a disabled user brings none back. Through the [endpoints for supabase-js](#supabase-js-and-supabasessr) the same holds for signing out with the `global` or `others` scope and for every new password set with `PUT /user`, since a password reset ends there too. Signing out of one browser, or a session expiring, disconnects nothing.
|
|
789
789
|
- A refresh token presented again after it was rotated, outside the provider's 30-second window for a retried request, is taken for stolen: that client is disconnected for the person, its access tokens stop at the next request, and it has to ask again. Their other clients keep working.
|
|
790
790
|
|
|
791
|
+
### OAuth tokens for the API
|
|
792
|
+
|
|
793
|
+
:::caution[Beta]
|
|
794
|
+
It needs `mcp` on, so the app serves its MCP endpoint too, and the API takes these tokens as bearer tokens only.
|
|
795
|
+
:::
|
|
796
|
+
|
|
797
|
+
With `oauth.api`, the same provider gives clients access tokens for the app's API, so an app of your own, such as a phone or watch app, signs people in through the app's own sign-in and calls the API as them with `Authorization: Bearer <token>`.
|
|
798
|
+
|
|
799
|
+
```ts
|
|
800
|
+
auth: { mcp: true, oauth: { api: true } }
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
- The API is the resource `/api` on the origin of the app's `url`, such as `https://app.example.com/api`. A client asks for it with that `resource` parameter (RFC 8707) at authorize; without one, its token is for MCP as before. A client registered before `oauth.api` was on cannot ask for it, and registers again.
|
|
804
|
+
- The person signs in and allows the client on the connect page, as for an MCP client. The token acts as them, with the role and organization they worked in when they allowed it, under the same access rules as their own token. MCP's write approval does not apply to the API, so the API refuses MCP's tokens and the MCP endpoint refuses the API's.
|
|
805
|
+
- Access tokens last 15 minutes and refresh for 30 days. On every request the API checks what the MCP endpoint checks: that the person still allows the client, still exists unbanned and still holds the token's role, so disconnecting the client on the account page, a ban, a lowered role or a deletion stops its tokens at the next request. Turning `oauth.api` off makes the API refuse them at once.
|
|
806
|
+
- Notifications and calls refuse these tokens, as they refuse an MCP client's.
|
|
807
|
+
- <gap>The app's API cannot take DPoP-bound access tokens because checking a proof against the API's URLs is not implemented.</gap> A token bound to a key is refused when it is sent as a bearer token.
|
|
808
|
+
|
|
791
809
|
## Several origins
|
|
792
810
|
|
|
793
811
|
An app can be served on more than one origin, such as its platform address and the customer's own domain. `auth.origins` lists the others; it defaults to `PROTOBASE_ORIGINS`, which a platform sets:
|
|
@@ -306,6 +306,17 @@ Turns on the OAuth provider for MCP clients, and with it the MCP endpoint: a cli
|
|
|
306
306
|
export default defineConfig({ auth: { mcp: true } })
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
+
## auth.oauth
|
|
310
|
+
|
|
311
|
+
- **Type:** `{ api?: boolean }`
|
|
312
|
+
- **Default:** off
|
|
313
|
+
|
|
314
|
+
What the OAuth provider of [`auth.mcp`](#authmcp) serves besides MCP. `api: true` lets clients get access tokens for the app's API, such as a phone or watch app that signs people in on the connect page, which the API takes as `Authorization: Bearer <token>`. Needs `auth.mcp`; the server refuses to start without it. See [OAuth tokens for the API](../auth.md#oauth-tokens-for-the-api).
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
export default defineConfig({ auth: { mcp: true, oauth: { api: true } } })
|
|
318
|
+
```
|
|
319
|
+
|
|
309
320
|
## auth.personalAccessTokens
|
|
310
321
|
|
|
311
322
|
- **Type:** `{ prefix: string }`
|
|
@@ -253,7 +253,7 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
253
253
|
{ "type": "urn:protobase:problem:personal-mail-link-expired", "status": 409, "code": "link_expired", "provider": "gmail" }
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
- **Sender:** the provider sends as the linked address; Gmail sets the From header to it.
|
|
256
|
+
- **Sender:** without a [From address](#from-addresses), the provider sends as the linked address; Gmail sets the From header to it.
|
|
257
257
|
- **Which account:** mail goes out through the account the person connected for mail last. Connecting Gmail with another Google account takes the mail scopes off the earlier one in the app's store, and signing in with the earlier one does not take the mail back; connecting it again does. When the chosen account's link fails, sending fails: it never falls back to another account. Of two accounts that both still hold the mail scopes, as when both connected before this rule came in, mail goes through the one linked to the person last, until they connect one again.
|
|
258
258
|
- **Only the person:** mail goes out from a mailbox only for someone signed in as themselves, or from a [workflow step's `mailbox`](workflow-plugins.md#step-types) in a version that person turned on while signed in as themselves, and only while they may still change the workflow. Staff [signed in as them](auth.md#staff-sign-in), an outside app acting for them, and a job's own code cannot send from it; a request is refused with a `403` problem (`own-sign-in-only`), a step fails with `not_linked`, and nothing is sent. Turning the workflow off, or someone else turning a new version on, ends the first person's consent.
|
|
259
259
|
- **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.
|
|
@@ -261,6 +261,40 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
261
261
|
- <gap>The account page cannot show which account a mailbox is linked through or disconnect it because unlinking a mailbox is not implemented.</gap>
|
|
262
262
|
- <gap>Mailboxes other than Gmail cannot be linked because no other mail provider is implemented.</gap>
|
|
263
263
|
|
|
264
|
+
### From addresses
|
|
265
|
+
|
|
266
|
+
A mailbox may send as more than its own address, such as Gmail's send-as addresses (Gmail's settings → Accounts → **Send mail as**). The person enters each such address once on the account page, under **Mailbox** → **From addresses**; only they can send from it. For each they choose:
|
|
267
|
+
|
|
268
|
+
- **Signature:** an address may carry its own signature, which takes the place of the app's generic one; left empty, the generic one applies.
|
|
269
|
+
- **Default:** one address, theirs or their mailbox's own, is the one mail goes out from when the app names none.
|
|
270
|
+
|
|
271
|
+
A function then names the From address with `from`, matched without regard to case. To send a template from it, render it and send the result:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
export default defineFunction(async (request, { personalMail }) => {
|
|
275
|
+
const { to, number, pdf } = await readInvoice(request)
|
|
276
|
+
const sender = await personalMail.sender('billing@shop.example')
|
|
277
|
+
const email = await invoiceEmail.render({ number, signature: sender.signature ?? defaultSignature })
|
|
278
|
+
await personalMail.send({ from: sender.address, to, ...email, attachments: [{ filename: `invoice-${number}.pdf`, content: pdf, contentType: 'application/pdf' }] })
|
|
279
|
+
return new Response(null, { status: 204 })
|
|
280
|
+
})
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
- **`send({ from, ... })`:** sends from `from`, else the person's default address, else their mailbox's own. Gmail keeps the From header when the address is one of the account's verified send-as addresses; when it is not, Gmail sends from the account's own address instead, without an error.
|
|
284
|
+
- **`sender(from?)`:** the address a send with `from` goes out as: `address`, `signature` when it has its own, and `ownerId`, whose mailbox it goes through. It refuses as `send` does.
|
|
285
|
+
- **`senders()`:** every address the caller may choose, such as for a send dialog: their mailbox's own, then those they entered.
|
|
286
|
+
- **Refused addresses:** a From address that is not the mailbox's own and not one the caller entered is refused before anything is sent, with a `MailSenderRefusedError` that answers as a `403` problem naming it; so is an address someone else entered, in the same words:
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
{ "type": "urn:protobase:problem:mail-sender-refused", "status": 403, "address": "ceo@shop.example", "detail": "You may not send mail from ceo@shop.example: add it to the Mailbox section of your account page first" }
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
- **The mailbox's own address** is the one its provider's ID token names; Google gives it with the `email` scope sign-in asks for.
|
|
293
|
+
- **The account page's calls:** `GET /api/auth/account/mail-senders` lists the person's addresses with their mailbox's own `address`; `POST .../mail-senders/add { address, signature? }`, `POST .../mail-senders/update { id, signature?, isDefault? }` (`signature: null` drops its own) and `POST .../mail-senders/remove { id }` change them. Each acts on the signed-in person's own addresses only.
|
|
294
|
+
- <gap>An entered address cannot be checked to work before mail goes out from it because the test mail through the mailbox is not implemented.</gap>
|
|
295
|
+
- <gap>An address cannot be shared with others who send mail because proving that the person owns the address is not implemented.</gap>
|
|
296
|
+
- <gap>A From address cannot carry a display name, so its mail shows the bare address, because names per address are not implemented.</gap>
|
|
297
|
+
|
|
264
298
|
## In a bundle
|
|
265
299
|
|
|
266
300
|
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.
|