@protobase/cli 0.121.4 → 0.121.5

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.121.4";
2
+ var version = "0.121.5";
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.121.4",
3
+ "version": "0.121.5",
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.121.4",
47
- "@protobase/layout": "0.121.4",
48
- "@protobase/query": "0.121.4",
49
- "@protobase/schema": "0.121.4",
50
- "@protobase/server": "0.121.4",
51
- "@protobase/ui": "0.121.4",
52
- "@protobase/workflows": "0.121.4",
46
+ "@protobase/config": "0.121.5",
47
+ "@protobase/layout": "0.121.5",
48
+ "@protobase/query": "0.121.5",
49
+ "@protobase/schema": "0.121.5",
50
+ "@protobase/server": "0.121.5",
51
+ "@protobase/ui": "0.121.5",
52
+ "@protobase/workflows": "0.121.5",
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",
@@ -23,6 +23,7 @@ Graphs of steps the server runs along their edges, written in a language a model
23
23
  - [Records steps](../reference/workflows.md#apprecords) (beta): Create, update, get and list records as the workflow's last editor, with the roles they hold now.
24
24
  - [Mail step](../reference/workflows.md#appmailsend) (beta): Sends mail, with files the run downloaded attached, from the app's own sender.
25
25
  - [Send email step](../reference/workflows.md#appmailtemplate) (beta): Sends one of the app's email templates in a language of its own, with a pin for each field of the template's data, checked before it is sent.
26
+ - [Email series](../reference/workflows.md#email-series) (beta): Mail steps that share a series' name, with waits between them, send each person a timed series, such as after sign-up; the series is a mail category of its own with one-click unsubscribe in every mail, and an unsubscribe stops the rest of the series for that person.
26
27
  - [Storing files](../reference/workflows.md#storing-files) (beta): The HTTP request step streams an answer of any size into a named storage configuration, an S3-compatible bucket, a file share or a local directory, past its 10 MiB read limit; later steps pass the stored file on or read it back, up to 10 MiB. Changing where a configuration points leaves the workflows that use it unchanged.
27
28
  - [Runs and their traces](../reference/workflows.md#traces) (beta): Each run started by hand through the API, from the app's code or by a trigger keeps every step's input, output, logs, timing, tries and error as a JSONL trace in the app's private file storage, whole by the time the run is marked ended, secrets blanked out; every run, only failing ones, or none, set by the app, the workflow or the run.
28
29
  - [Run debugger](../reference/workflows.md#following-and-debugging-a-run) (beta): Each workflow lists its runs with their status, who started them, when and for how long; a run chosen there marks every step's status on the graph of the version it ran on from its trace, and a run's own address shows it on the latest version, with the way to the one it ran on, live while it runs, with each step's input, output, logs, timing, tries and error, secrets blanked out.
@@ -305,6 +305,7 @@ await mail.send({ to: member.email, subject: 'News', text: '...', bulk: true, to
305
305
  - **The click:** the mail client's `POST` with `List-Unsubscribe=One-Click` records the opt-out and answers `200`; doing it again changes nothing. Opening the link in a browser shows a page with an **Unsubscribe** button that sends that `POST`, so a scanner that follows links in mail unsubscribes no one. A link the app did not sign answers `400` and records nothing.
306
306
  - **Skipped sends:** whoever unsubscribed from the topic is left out, found in one query, and the send resolves to them as `skipped` beside `sent`, each recipient it went to with its message id: `{ skipped: ['bob@example.com'], sent: [{ to: 'ada@example.com', messageId: '<…>' }], messageId: '<…>' }`, with `messageId` only when it went to exactly one. Other topics still reach them. Who unsubscribed is read once, before the first message goes out; one who unsubscribes while a send to several is going out is skipped from the next send on.
307
307
  - **A refused message:** when the server refuses one recipient's message, the send rejects with a `BulkMailError` (exported by `@protobase/server`, its `code` `BULK_MAIL_FAILED`) after the messages before it went out. It fails the try, which is retried, and names the recipient it failed on as `to`, those it went to as `sent`, those skipped as `skipped`, and the server's error as `cause`. A retried try sends to everyone again, so catch it, record `error.sent`, rethrow, and leave those addresses out of the next try; or send to one recipient per call.
308
+ - **From a workflow:** a workflow's mail steps send bulk mail as an [email series](workflows.md#email-series), whose name is the topic.
308
309
  - **Who unsubscribed:** admins see each recipient, topic and time under **Unsubscribes** in the admin app, and the app's code reads them as the `mail_unsubscribes` resource, `GET /api/v1/mail_unsubscribes?filter=topic = "newsletter"`. Nobody changes them but the link.
309
310
  - **Refused:** `bulk` without a `topic` is refused, as the email is defined or the message sent. Bulk mail without `unsubscribe: true`, or sent another way than a job's `mail`, such as through `PROTOBASE_SMTP_URL` directly or from someone's own mailbox, is refused before anything is sent. A mailer of the project's own (`auth/mailer.ts`) that is handed bulk mail directly, outside a job's `mail`, gets it without its unsubscribe: send it through the job's `mail` instead.
310
311
  - <gap>Bulk mail cannot be sent from an API function because only a job's `mail` adds the unsubscribe; enqueue a job instead.</gap>
@@ -475,8 +475,9 @@ A get and a list only read; a create and an update are recorded. They go through
475
475
  | `subject` | One line of text. |
476
476
  | `text`, `html` | The body as text, and optionally as HTML. |
477
477
  | `attachments` | A list of file values the run keeps, at most 10 MiB together. |
478
+ | `series` | Optional: the [email series](#email-series) the mail belongs to, such as `welcome`. |
478
479
 
479
- The mail goes from the app's own sender with the app's mailer; a workflow cannot set the sender. The result is `{ message_id }`, the Message-ID the step sets, the same for each try of the step. Without mail the step fails.
480
+ The mail goes from the app's own sender with the app's mailer; a workflow cannot set the sender. The result is `{ message_id }`, the Message-ID the step sets, the same for each try of the step; with a `series`, `{ message_id, sent, skipped }`, as [Email series](#email-series) says. Without mail the step fails.
480
481
 
481
482
  ### app:mail.template
482
483
 
@@ -488,6 +489,7 @@ The mail goes from the app's own sender with the app's mailer; a workflow cannot
488
489
  | `to` | One address. |
489
490
  | `locale` | Optional: a BCP 47 language tag, such as `nl` or `en-GB`. The mail is in the template's language closest to it, so `nl-BE` picks `nl`. Without it, the mail is in the app's `locale` when the template has that language. Otherwise it is in English when the template has it, else in the template's first language. |
490
491
  | `data` | The template's data, as its schema takes it. |
492
+ | `series` | Optional: the [email series](#email-series) the mail belongs to, such as `welcome`. |
491
493
 
492
494
  ```json
493
495
  {
@@ -505,7 +507,72 @@ The mail goes from the app's own sender with the app's mailer; a workflow cannot
505
507
 
506
508
  The editor draws one input pin for each field of the chosen template's data, and offers the template's languages for `locale`. A save checks each value read by name in `data` against the type of that field, as it checks a record's fields. `list_workflow_types` lists the app's template names in the step's `template` argument, and each template's languages and data schema under `templates`.
507
509
 
508
- The mail goes from the app's own sender, as `app:mail.send`'s does. The result is `{ message_id, locale }`: the Message-ID the step sets, the same for each try of the step, and the language the mail was sent in. Data the template's schema refuses fails the step with `Mail.InvalidData`, its cause naming each path, such as `data.name: Invalid input`. A template the app does not have fails it with `Mail.UnknownTemplate`, and a `to` or `locale` of the wrong kind, such as a locale that is no language tag, with `Mail.InvalidArguments`. Without mail the step fails.
510
+ The mail goes from the app's own sender, as `app:mail.send`'s does. The result is `{ message_id, locale }`: the Message-ID the step sets, the same for each try of the step, and the language the mail was sent in; with a `series`, `sent` and `skipped` too, as [Email series](#email-series) says. Data the template's schema refuses fails the step with `Mail.InvalidData`, its cause naming each path, such as `data.name: Invalid input`. A template the app does not have fails it with `Mail.UnknownTemplate`, and a `to` or `locale` of the wrong kind, such as a locale that is no language tag, with `Mail.InvalidArguments`. Without mail the step fails.
511
+
512
+ ### Email series
513
+
514
+ :::caution[Beta]
515
+ A run goes on to its end after an unsubscribe, sending nothing more in the series: a series has no step that ends the run by itself.
516
+ :::
517
+
518
+ An email series is mail a workflow sends over time, such as a welcome mail on sign-up, tips three days later and a check-in after two weeks. Give each mail step of the series the same `series`, a name such as `welcome`: a lowercase letter, then lowercase letters, digits, `_` and `-`, at most 63 characters. The `Wait` states between them set the timing. A trigger such as [`app:record`](#apprecord) starts one run per person, so each person has a series of their own.
519
+
520
+ The series is a mail category of its own, with nothing else to set up: each mail in it is bulk mail whose topic is the series' name, and carries its recipient's own [one-click unsubscribe](email.md#unsubscribe) from that series. It needs `unsubscribe: true` in the config; without it, the step fails before it sends anything.
521
+
522
+ - **After an unsubscribe:** every later mail step of the series sends that person nothing, so the rest of the series stops for them, in this run and any other. Their other series, and other people's runs of this one, go on. The step does not fail: its result is `{ sent: [], skipped: ['ada@example.com'] }`, and the run passes its remaining waits and ends as succeeded.
523
+ - **The result:** `sent` lists the addresses the mail went to and `skipped` those that unsubscribed from the series, with `message_id` when the mail went to anyone.
524
+ - **Other steps go on:** an unsubscribe stops the series' mail only. To stop the run's other steps too, follow a mail step with a `Choice` that ends the run when nobody got it, `{% $count($states.input.sent) = 0 %}`, with the mail step's result as its input.
525
+ - **Who unsubscribed:** they are listed under **Unsubscribes** in the admin app, with the series' name as the topic.
526
+ - <gap>A series cannot end its run when its recipient unsubscribes because a step that ends the run it is in is not implemented; the run's later mail steps send nothing instead.</gap>
527
+
528
+ A sign-up series, started for each new record of the app's `members` resource:
529
+
530
+ ```json
531
+ {
532
+ "trigger": { "app:record": { "resource": "members" } },
533
+ "stateMachine": {
534
+ "QueryLanguage": "JSONata",
535
+ "StartAt": "Welcome",
536
+ "States": {
537
+ "Welcome": {
538
+ "Type": "Task",
539
+ "Resource": "app:mail.send",
540
+ "Arguments": {
541
+ "to": "{% $states.context.Execution.Input.record.email %}",
542
+ "subject": "{% 'Welcome, ' & $states.context.Execution.Input.record.name %}",
543
+ "text": "Thanks for signing up. Here is how to get started.",
544
+ "series": "welcome"
545
+ },
546
+ "Next": "Three days"
547
+ },
548
+ "Three days": { "Type": "Wait", "Seconds": 259200, "Next": "Tips" },
549
+ "Tips": {
550
+ "Type": "Task",
551
+ "Resource": "app:mail.send",
552
+ "Arguments": {
553
+ "to": "{% $states.context.Execution.Input.record.email %}",
554
+ "subject": "Three tips for your first week",
555
+ "text": "Here are three things most people set up first.",
556
+ "series": "welcome"
557
+ },
558
+ "Next": "Two weeks"
559
+ },
560
+ "Two weeks": { "Type": "Wait", "Seconds": 950400, "Next": "Check-in" },
561
+ "Check-in": {
562
+ "Type": "Task",
563
+ "Resource": "app:mail.send",
564
+ "Arguments": {
565
+ "to": "{% $states.context.Execution.Input.record.email %}",
566
+ "subject": "How is it going?",
567
+ "text": "You signed up two weeks ago. Reply to this mail and tell us how it is going.",
568
+ "series": "welcome"
569
+ },
570
+ "End": true
571
+ }
572
+ }
573
+ }
574
+ }
575
+ ```
509
576
 
510
577
  ### app:piece
511
578