@protobase/cli 0.124.2 → 0.125.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.124.2";
2
+ var version = "0.125.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.124.2",
3
+ "version": "0.125.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.124.2",
47
- "@protobase/layout": "0.124.2",
48
- "@protobase/query": "0.124.2",
49
- "@protobase/schema": "0.124.2",
50
- "@protobase/server": "0.124.2",
51
- "@protobase/ui": "0.124.2",
52
- "@protobase/workflows": "0.124.2",
46
+ "@protobase/config": "0.125.0",
47
+ "@protobase/layout": "0.125.0",
48
+ "@protobase/query": "0.125.0",
49
+ "@protobase/schema": "0.125.0",
50
+ "@protobase/server": "0.125.0",
51
+ "@protobase/ui": "0.125.0",
52
+ "@protobase/workflows": "0.125.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",
@@ -16,7 +16,7 @@ Mail the app sends, the PDF documents it makes, and forms for people without an
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
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
- - [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.
19
+ - [Verifying a From address](../reference/email.md#verifying-a-from-address) (beta): The app plugs in its own way to prove a From address its mailbox provider cannot vouch for, such as a hosting platform's test-mail check: a verifier sends one test message through the person's mailbox, and its proof makes the address verified until it runs out. Verifications wait, survive a restart and settle once, by the app's own check each minute or by a report carrying the verification's secret.
20
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.
@@ -157,6 +157,7 @@ export const generateUserId: AuthHooks['generateUserId'] = async ({ db }) => {
157
157
  | `onOrganizationCreated` | `({ organization, member }, { db })`, after an organization is created, with its owner's membership |
158
158
  | `beforeOrganizationDeleted` | `(organization, { db })`, before an organization is deleted; throwing refuses it |
159
159
  | `organizationHooks` | Better Auth's organization hooks by name, each with `{ db }` last, run after Protobase's own |
160
+ | `senderVerifiers` | `(add_verifier)`, once as the app starts: adds the app's ways to prove a From address; see [Verifying a From address](email.md#verifying-a-from-address) |
160
161
 
161
162
  A mailer of the project's own, for sign-in's mail, is the default export of `auth/mailer.ts` (see [Password reset](#password-reset)). An authenticator of its own, in place of the one `authenticate` describes, is the default export of `auth/authenticate.ts` (see [Tokens and roles](#tokens-and-roles)).
162
163
 
@@ -481,7 +481,6 @@ Serves the API of a bundle from `protobase build` and owns the process around it
481
481
  | `PROTOBASE_FIRST_ADMIN_URL` | the hosting platform's page where the app's first user is added, such as its console's; while the app has no users, the sign-in page links there in place of the `protobase users create` command ([the first admin](auth.md#first-run)) |
482
482
  | `PROTOBASE_RUNS_ON_NOTE` | `true` ends the sign-in page on the [Runs on Protobase note](app-identity.md#runs-on-protobase-note), for a hosting platform; default `false`, and any value but `true` or `false` stops startup |
483
483
  | `PROTOBASE_RUNTIME_URL` | the endpoint behind the top bar's [runtime update button](versioning.md#runtime-updates), such as a hosting platform's; without it there is no button |
484
- | `PROTOBASE_MAIL_CHECK_URL` | the hosting platform's service that [checks a From address](email.md#checking-a-from-address), signed with a key derived from `PROTOBASE_SECRET`; without it the account page says addresses cannot be checked |
485
484
  | `PROTOBASE_SENTRY_DSN` | the DSN of a Sentry-compatible error tracker the app's server and admin app send their errors to, after the config's `errorReporting` ([Error reporting](api.md#error-reporting)); without it nothing is sent |
486
485
  | `PROTOBASE_RELAY_URL`, `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY`, `PROTOBASE_RELAY_TICKET_KEY` | the address, the app's id and its API and ticket keys of the [realtime relay](realtime-relay.md#from-the-platform), each where the config's `realtime.relay` leaves it out; without `realtime.relay` the relay stays off |
487
486
  | `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after the config's `maps`; without it there are no maps |
@@ -414,6 +414,8 @@ A mailbox may send as more than its own address, such as Gmail's send-as address
414
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
415
  - `unverified`: nothing says either way.
416
416
 
417
+ Where the provider says nothing, a [verifier](#verifying-a-from-address) of the app may prove the address `verified`.
418
+
417
419
  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
420
  - **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
421
  - **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.
@@ -458,24 +460,59 @@ export default defineFunction(async (request, { personalMail }) => {
458
460
 
459
461
  Each acts on the signed-in person's own addresses and connections only: any other id answers `404` before anything is done.
460
462
  - **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>
463
+ - <gap>An address on a mailbox linked without `gmail.settings.basic` cannot be checked before each send because only a [verification](#verifying-a-from-address) started from the account page is implemented for it.</gap>
462
464
  - <gap>An address cannot be shared with others who send mail because proving that the person owns the address is not implemented.</gap>
463
465
 
464
- ### Checking a From address
466
+ ### Verifying a From address
465
467
 
466
- :::note[Coming soon]
467
- The app's side is built; the hosting platform's service that receives the test messages is not live yet.
468
+ :::caution[Beta]
469
+ Protobase ships no verifier: an app, or the platform it runs on, plugs in its own.
468
470
  :::
469
471
 
470
- Gmail sends from the account's own address, without an error, when a From address is not one of its verified send-as addresses. So the account page checks an address by sending one test message from it through the person's mailbox, to a one-time address of a mail check service, and showing the From it arrived with:
472
+ Gmail sends from the account's own address, without an error, when a From address is not one of its verified send-as addresses, and a mailbox that cannot list its send-as addresses leaves an address `unverified`. A verifier proves such an address another way, such as by sending one test message from it and reading how it arrives. The app's trusted code adds verifiers with `add_verifier`, from the project's `auth/hooks.ts`:
473
+
474
+ ```ts
475
+ import type { AuthHooks } from '@protobase/server'
476
+
477
+ export const senderVerifiers: AuthHooks['senderVerifiers'] = (add_verifier) => add_verifier(testMailVerifier)
478
+ ```
479
+
480
+ A host's runtime can pass its own in `createAuth`'s `senderVerifiers`. A verifier is a `SenderAddressVerifier`:
471
481
 
472
- - **When:** adding an address checks it at once; its dialog, under **Edit**, checks it again with **Check address**, and after a result with **Check again**.
473
- - **Waiting:** the dialog asks every 3 seconds whether the message arrived, for up to 2 minutes, then says it did not arrive in time. Closing the dialog stops asking.
474
- - **The result:** a From equal to the address, without regard to case, confirms it; any other shows the address the mailbox used instead, with how to set the address up in Gmail. The message also shows in the person's Sent folder.
475
- - **The service:** the hosting platform names it in `PROTOBASE_MAIL_CHECK_URL`, a URL the app treats as opaque. The app makes two signed JSON `POST`s under it: `/alias-checks` answers `{ token, address }`, a one-time address and its token, and `/alias-checks/result { token }` answers `{ received: false }`, or `{ received: true, from }` with the address in the message's From header. Each carries [Standard Webhooks](https://www.standardwebhooks.com) headers under a key derived from `PROTOBASE_SECRET` by HKDF (`mailCheckSecret` and `mailCheckHeaders` of `@protobase/server`), which the service checks with `verifyStandardWebhook`. `PROTOBASE_MAIL_CHECK_URL` without `PROTOBASE_SECRET` stops startup.
476
- - **Unchecked:** without the service, the dialog says the app cannot check From addresses, and how to check one by hand.
477
- - **The account page's calls:** `GET /api/auth/account/mail-senders` says `checks: true` where the app can check; `POST .../mail-senders/check { id }` sends the test message and answers `{ status: 'waiting', check }`, or `{ status: 'unchecked' }`; `POST .../mail-senders/check-result { id, check }` answers `waiting`, `confirmed` or `mismatch` with `from`. Each acts on the signed-in person's own addresses only, and staff signed in as them cannot send a check.
478
- - <gap>Self-hosted apps cannot check a From address because no mail check service that receives the test messages is implemented outside Protobase Cloud.</gap>
482
+ ```ts
483
+ const testMailVerifier: SenderAddressVerifier = {
484
+ id: 'test-mail',
485
+ verify: async ({ verification_id, address, secret, locale }, { send }) => {
486
+ const to = await checkService.issue({ verification_id, secret })
487
+ await send({ to, subject: `Test message for ${address}`, text: 'This message checks that your mailbox sends from this address.' })
488
+ return { state: 'pending', expires_at: new Date(Date.now() + 10 * 60_000) }
489
+ },
490
+ check: async ({ verification_id }) => checkService.result(verification_id),
491
+ }
492
+ ```
493
+
494
+ - **`id`:** stored on each verification, so it stays the same across releases: lowercase letters, digits, `_`, `.` and `-`, starting with a letter, at most 64 characters. Two verifiers with one id, or a verifier without `auth.personalMail`, stop startup.
495
+ - **`verify(input, tools)`:** starts a verification of `address`. `tools.send({ to, subject, text, html? })` sends one test message through the address's own mailbox, From that address, to one recipient: a From, copies, headers or attachments it is given are left out, and a second send is refused.
496
+ - **`check(input)`:** optional. The app's sweep calls it each minute a pending verification is due, until it settles or expires.
497
+ - **Outcomes:** `verify` and `check` answer one of these.
498
+ - `{ state: 'pending', expires_at, check_after? }`: `verify` must name `expires_at`, which the app caps at 24 hours after the verification started. `check` cannot move it. The next check comes at `check_after`, else a minute on, and never sooner than a minute on.
499
+ - `{ state: 'verified', valid_until }`: `valid_until` is required, lies ahead, and is capped at 28 days.
500
+ - `{ state: 'failed', error_code, error? }`: `error_code` is a lowercase name, such as `from_rewritten`. `error` is plain text of at most 500 characters, with no control characters but line breaks and tabs, shown as text and never as markup.
501
+
502
+ An outcome that breaks these rules, or a `verify` that throws, fails the verification as `verifier_error`. The address's state does not change.
503
+ - **One at a time:** an address has at most one pending verification per verifier. It is stored before `verify` runs, so starting it again sends nothing while it is pending. A verification whose `verify` never returned expires after 5 minutes, and the next start takes its place.
504
+ - **Expiry:** a verification still pending at `expires_at` fails as `verification_expired`, from the sweep, `auth.mail-sender-verifications`, which runs each minute on the app's jobs.
505
+ - **Reports:** an outside service settles a verification with `POST /api/auth/mail-sender-verifications/report`, with this JSON body: `{ verifier, secret, state: 'verified', valid_until }` or `{ verifier, secret, state: 'failed', error_code, error? }`.
506
+ - `secret` is the one `verify` was given: 256 random bits, made for that verification alone. The app keeps only its SHA-256, so it is never handed out again. The verification's id is not a secret.
507
+ - The secret is read from the body only. Keep it out of URLs and logs.
508
+ - A report settles the verification only for the verifier that started it, while it is pending and before it expires, and once only. Whichever comes first wins: the report, the sweep or `verify`'s own outcome.
509
+ - Any report that settles nothing answers the same `403` with `code: "VERIFICATION_REFUSED"`, whatever the reason. A malformed outcome answers `400` before anything is looked up.
510
+ - **The address's state:** a verified verification makes an address the provider says nothing of `verified`, until its `valid_until`. It never outweighs what the provider says, such as a `failed` listing. It counts only while its verifier is registered, and only if it settled after the address was last removed. A failed verification shows on the account page and leaves the state as it was.
511
+ - **The account page:** adding an address verifies it at once. Its dialog, under **Edit**, verifies it again with **Verify address**, and after a result with **Verify again**. While a verification is pending, the dialog reads it again every 3 seconds for up to 2 minutes. Without a verifier, the dialog says the app cannot verify From addresses, and how to check one by hand.
512
+ - **The account page's calls:**
513
+ - `GET /api/auth/account/mail-senders` says `verifiers: true` when the app has any, and gives each address its latest `verifications`, one per verifier: `verifier`, `state`, `expiresAt` while pending, `settledAt`, `validUntil`, `errorCode` and `error`.
514
+ - `POST .../mail-senders/verify { id }` starts each verifier on one of the person's addresses on a connection they can send through, and answers its `verifications`.
515
+ - Staff signed in as the person cannot start one.
479
516
 
480
517
  ### A From address on a record
481
518