@protobase/cli 0.123.7 → 0.124.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.123.7";
2
+ var version = "0.124.0";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.123.7",
3
+ "version": "0.124.0",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.123.7",
47
- "@protobase/layout": "0.123.7",
48
- "@protobase/query": "0.123.7",
49
- "@protobase/schema": "0.123.7",
50
- "@protobase/server": "0.123.7",
51
- "@protobase/ui": "0.123.7",
52
- "@protobase/workflows": "0.123.7",
46
+ "@protobase/config": "0.124.0",
47
+ "@protobase/layout": "0.124.0",
48
+ "@protobase/query": "0.124.0",
49
+ "@protobase/schema": "0.124.0",
50
+ "@protobase/server": "0.124.0",
51
+ "@protobase/ui": "0.124.0",
52
+ "@protobase/workflows": "0.124.0",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -15,9 +15,9 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
15
15
  - [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.
16
16
  - [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.
17
17
  - [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.
18
- - [From addresses](../reference/email.md#from-addresses): People enter their mailbox's other send-as addresses once on the account page, each with a display name and a signature of its own, and the app sends from the one it names or their default.
18
+ - [From addresses](../reference/email.md#from-addresses): Each send-as address is a record on the person's mailbox, with a display name, a signature of its own and a state. With the optional `gmail.settings.basic` scope, Gmail lists them and says which it really sends from, and the app refuses to send from an address Gmail would replace. The app sends from the record it names, or the person's default.
19
19
  - [Checking a From address](../reference/email.md#checking-a-from-address) (coming soon): The app sends one test message from a send-as address through the person's Gmail and shows on the account page the From it arrived with. That catches Gmail sending from the person's own address, with no error, when a send-as address is not set up or verified. Works only on apps hosted on Protobase Cloud; self-hosted apps show the address as unchecked.
20
- - [A From address on a record](../reference/email.md#a-from-address-on-a-record) (beta): A field such as a client's "Send from" is a dropdown of the person's addresses, and an address a record holds cannot be removed.
20
+ - [A From address on a record](../reference/email.md#a-from-address-on-a-record) (beta): A field such as a client's "Send from" is a dropdown of the person's addresses with their states, and an address a record holds cannot be removed.
21
21
  - [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.
22
22
  - [Bot check](../reference/forms.md#bot-check): Each submission passes a check in the browser, without a third-party service or a puzzle.
23
23
  - [Form rate limit](../reference/forms.md#rate-limit): Each client sends only a set number of submissions per minute.
@@ -12,7 +12,7 @@ In the Google Cloud console, in a project of your own:
12
12
 
13
13
  1. **Turn on the Gmail API:** APIs & Services → Library → Gmail API → Enable.
14
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.
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. Optionally add `https://www.googleapis.com/auth/gmail.settings.basic` too, so the app can read which addresses Gmail sends as ([step 5](#5-send-from-another-address)): it reads the mailbox's settings, not its mail.
16
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
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
18
 
@@ -69,10 +69,24 @@ The message goes out from the linked Gmail, and shows in its Sent folder. When t
69
69
 
70
70
  ## 5. Send from another address
71
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:
72
+ A Gmail account may send as other addresses of yours, such as a company address beside your own. Gmail sends from your primary address instead, without an error, when an address is not set up under **Send mail as**, so the app keeps each From address with what Gmail says of it.
73
73
 
74
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 the name Gmail shows for it, so mail from the app carries the same name, and 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 })`.
75
+ 2. **Let the app read the list (optional):** add the `gmail.settings.basic` scope to the link, in the config and on the consent screen ([step 1](#1-make-the-google-oauth-client)):
77
76
 
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.
77
+ ```ts
78
+ import { gmailSettingsScope } from '@protobase/server'
79
+
80
+ personalMail: [{ provider: 'gmail', scopes: [gmailSettingsScope] }],
81
+ ```
82
+
83
+ People who linked Gmail before see **Allow address checks** under **From addresses**, which connects Gmail again with the scope. From then on the account page lists Gmail's send-as addresses as **Verified**, **Awaiting confirmation** or **Can't send**. The app refuses to send from an address Gmail would replace. Without the scope, the app cannot tell, and an address stays **Not checked**.
84
+ 3. **Add it in the app, if Gmail does not list it:** on the account page, under **Mailbox** → **From addresses**, choose **Add a From address** and type it. Give it the name Gmail shows for it, so mail from the app carries the same name, and a signature of its own if you like, and make it the default to send from it whenever the app names no address.
85
+ 4. **Name it when sending:** look the address up, then send with its record's id:
86
+
87
+ ```ts
88
+ const sender = await personalMail.sender('billing@shop.example')
89
+ await personalMail.send({ sender_address_id: sender.id, to, subject, text })
90
+ ```
91
+
92
+ The app sends only from the caller's own From addresses: any other is refused before anything is sent. [From addresses](../reference/email.md#from-addresses) has the details.
@@ -392,7 +392,7 @@ export default defineFunction(async (request, { personalMail }) => {
392
392
  { "type": "urn:protobase:problem:personal-mail-link-expired", "status": 409, "code": "link_expired", "provider": "gmail" }
393
393
  ```
394
394
 
395
- - **Sender:** without a [From address](#from-addresses), the provider sends as the linked address; Gmail sets the From header to it.
395
+ - **Sender:** without a [From address](#from-addresses), the provider sends as the linked address; Gmail sets the From header to it. A From address goes out through the connection its record is on, never through another.
396
396
  - **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.
397
397
  - **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.
398
398
  - **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.
@@ -404,35 +404,61 @@ export default defineFunction(async (request, { personalMail }) => {
404
404
 
405
405
  ### From addresses
406
406
 
407
- 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:
407
+ A mailbox may send as more than its own address, such as Gmail's send-as addresses (Gmail's settings → Accounts → **Send mail as**). Each From address is a record on one of the person's mailbox connections, theirs alone, with a state that says whether the mailbox really sends as it. The account page lists them under **Mailbox** → **From addresses**.
408
408
 
409
- - **Name:** an address may carry a display name, which the From header shows beside it, such as `From: Shop billing <billing@shop.example>`, as mail sent by hand from a send-as address shows the name set up for it; a name that is not ASCII is encoded. Left empty, the header holds the bare address. To give the mailbox's own address a name, enter it as well.
409
+ - **Typed:** the person adds an address with **Add a From address**, on the mailbox mail goes through. Until the provider lists it, it is **Not checked** (`unverified`).
410
+ - **Listed:** a provider that can list the mailbox's send-as addresses fills them in, with its own word on each. Gmail does this when the app adds the optional `gmail.settings.basic` scope to the link: it reads the list and nothing else of the mailbox. The account page reads the list again each time it opens, and with **Check with Gmail**.
411
+ - **States:**
412
+ - `verified`: the provider sends as it; for Gmail, an accepted send-as address, or the account's own.
413
+ - `pending`: the owner still has to confirm it with the provider.
414
+ - `failed`: a complete listing since the address was added did not hold it, so Gmail would send from the account's own address instead.
415
+ - `unverified`: nothing says either way.
416
+
417
+ The state is worked out each time it is read, from what typed the address and what the provider last listed. An address the listing leaves out keeps its record and its id: only its listed state goes.
418
+ - **Without the scope:** a Gmail link without `gmail.settings.basic` is told which scope it lacks. The account page then offers **Allow address checks**, which connects Gmail again asking for it, and sends the person back to the account page.
419
+ - **Name:** an address may carry a display name, which the From header shows beside it, such as `From: Shop billing <billing@shop.example>`, as mail sent by hand from a send-as address shows the name set up for it; a name that is not ASCII is encoded. Left empty, the header holds the bare address.
410
420
  - **Signature:** an address may carry its own signature, which takes the place of the app's generic one; left empty, the generic one applies.
411
421
  - **Default:** one address, theirs or their mailbox's own, is the one mail goes out from when the app names none.
422
+ - **Removing:** removing an address hides it and keeps its record. Adding it again brings back the same record, and only a new listing counts for it after that.
423
+
424
+ To let Gmail list the send-as addresses, add the scope in the config, and add it to the Google client's consent screen (Data Access) as well:
425
+
426
+ ```ts
427
+ personalMail: [{ provider: 'gmail', scopes: [gmailSettingsScope] }], // import { gmailSettingsScope } from '@protobase/server'
428
+ ```
412
429
 
413
- 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:
430
+ A function sends from a From address by naming its record. To send a template from it, render it and send the result:
414
431
 
415
432
  ```ts
416
433
  export default defineFunction(async (request, { personalMail }) => {
417
434
  const { to, number, pdf } = await readInvoice(request)
418
435
  const sender = await personalMail.sender('billing@shop.example')
419
436
  const email = await invoiceEmail.render({ number, signature: sender.signature ?? defaultSignature })
420
- await personalMail.send({ from: sender.address, to, ...email, attachments: [{ filename: `invoice-${number}.pdf`, content: pdf, contentType: 'application/pdf' }] })
437
+ await personalMail.send({ sender_address_id: sender.id, to, ...email, attachments: [{ filename: `invoice-${number}.pdf`, content: pdf, contentType: 'application/pdf' }] })
421
438
  return new Response(null, { status: 204 })
422
439
  })
423
440
  ```
424
441
 
425
- - **`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.
426
- - **`sender(from?)`:** the address a send with `from` goes out as: `address`, `name` when it has one, `signature` when it has its own, and `ownerId`, whose mailbox it goes through. It refuses as `send` does.
427
- - **`senders()`:** every address the caller may choose, such as for a send dialog: their mailbox's own, then those they entered.
428
- - **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:
429
-
430
- ```json
431
- { "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" }
432
- ```
433
-
442
+ - **`send({ sender_address_id, ... })`:** sends from that record's address, with its display name, through that record's own mailbox connection, so From and mailbox cannot disagree. `null` sends from the mailbox's own address with no From header, and leaving it out sends from the default address, else the mailbox's own. A message that names its own `from` or `sender`, or a `From` or `Sender` header, is a mistake that rejects. An address no listing has read yet is listed first, when its provider can list.
443
+ - **Refusals,** each sending nothing:
444
+ - An id that is not one of the caller's, unknown or removed alike, answers `404` (`sender-address-not-found`).
445
+ - A `failed` address answers `409` with `code: "sender_address_failed"`, and a `pending` one `sender_address_pending`.
446
+ - An address on no connection the person can send through answers `sender_address_detached`.
447
+ - An `unverified` one is sent.
448
+ - **`sender(address?)`:** the record an address stands for, matched without regard to case: `id` (null for the mailbox's own address), `address`, `name` when it has one, `signature` when it has its own, `state`, and `ownerId`, whose mailbox it goes through. Without an address, the default. An address that is not the caller's is refused with a `MailSenderRefusedError` (`403`); one on two of their connections with `sender_address_ambiguous`.
449
+ - **`senders()`:** every address the caller may choose, such as for a send dialog: their mailbox's own, then their records, each with its id and state.
450
+ - **`refresh()`:** reads the send-as addresses of each of the caller's mailboxes whose provider can list them, and answers how each went: `listed`, `not_permitted` with `missing_scopes`, or `error` with `link_expired` or `listing_failed`. A connection that fails changes nothing and stops none of the others.
434
451
  - **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.
435
- - **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, name?, signature? }`, `POST .../mail-senders/update { id, name?, signature?, isDefault? }` (`name: null` drops the name, `signature: null` drops its own) and `POST .../mail-senders/remove { id }` change them. Each acts on the signed-in person's own addresses only.
452
+ - **The account page's calls:**
453
+ - `GET /api/auth/account/mail-senders` lists the person's addresses with their `state` and `connection`, their mailbox's own `address`, and their `connections`, each with `canList` and the `missingScopes` the app adds that its link lacks.
454
+ - `POST .../mail-senders/add { address, name?, signature?, connection? }` types an address, on `connection` or else the mailbox mail goes through.
455
+ - `POST .../mail-senders/update { id, name?, signature?, isDefault? }` changes one: `name: null` drops the name and `signature: null` its own signature.
456
+ - `POST .../mail-senders/remove { id }` removes one.
457
+ - `POST .../mail-senders/refresh` reads the send-as addresses, as `refresh()` does.
458
+
459
+ Each acts on the signed-in person's own addresses and connections only: any other id answers `404` before anything is done.
460
+ - **Upgrading:** an address entered before From addresses were records goes on its owner's Gmail connection when they had exactly one. With none or several it shows **No mailbox**, and the person removes it and adds it again.
461
+ - <gap>An address on a mailbox linked without `gmail.settings.basic` cannot be checked before each send because only the account page's one-off test message is implemented for it.</gap>
436
462
  - <gap>An address cannot be shared with others who send mail because proving that the person owns the address is not implemented.</gap>
437
463
 
438
464
  ### Checking a From address
@@ -457,13 +483,13 @@ Gmail sends from the account's own address, without an error, when a From addres
457
483
  A removal refused over records does not say which records hold the address; and since addresses cannot be shared yet, everyone else sees an address on a shared record as not available.
458
484
  :::
459
485
 
460
- A record can hold the address its mail goes out from, such as a client's or the seller's "Send from": declare the field with `f.mailSender()`, on a `text` column, and pass its value to `send({ from })`.
486
+ A record can hold the address its mail goes out from, such as a client's or the seller's "Send from": declare the field with `f.mailSender()`, on a `text` column, and send from it with `send({ sender_address_id: (await personalMail.sender(value)).id })`.
461
487
 
462
488
  ```ts
463
489
  send_from: f.mailSender().optional(),
464
490
  ```
465
491
 
466
- - **The form:** a dropdown of the signed-in person's addresses, their mailbox's own first, then those they entered, each as `Name <address>` when it has a name. The empty choice, **Sender's default address**, stores `null`: mail goes out from the default address of whoever sends it.
492
+ - **The form:** a dropdown of the signed-in person's addresses, their mailbox's own first, then their records, each as `Name <address>` when it has a name, followed by its state unless it is verified. An address mail cannot go out from, one `failed` or `pending`, shows but cannot be chosen, unless the record holds it already. The empty choice, **Sender's default address**, stores `null`: mail goes out from the default address of whoever sends it.
467
493
  - **Saving:** a create or update may only set an address the saving person may send from, by the rule `send` uses; the address is stored as their sender spells it. Any other is refused with a `400` naming the field and the address. A visitor, and anyone on an app without personal mail, can set none.
468
494
  - **An address no longer offered,** such as one another person entered, still shows, marked **not available**, with a link to the account page. Saving other fields, or giving the same address again, leaves it as it is.
469
495
  - **Read views** show the address, with its name when it is one of the reader's.