@protobase/cli 0.101.0 → 0.102.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.
@@ -18,6 +18,17 @@ const recordChildBlocks = /* @__PURE__ */ new Set([
18
18
  "ReferenceField",
19
19
  "RecordsIterator"
20
20
  ]);
21
+ const conditionProps = /* @__PURE__ */ new Set([
22
+ "filter",
23
+ "edgeFilter",
24
+ "animated",
25
+ "dashed",
26
+ "dotted"
27
+ ]);
28
+ const isArrowProp = (attribute) => {
29
+ const name = attribute.name.getText();
30
+ return conditionProps.has(name) || name === "node" && elementName(attribute).replace(/<.*$/, "") === "Graph";
31
+ };
21
32
  const unwrapped = (expression) => ts.isParenthesizedExpression(expression) ? expression.expression : expression;
22
33
  const isExpressionArrow = (expression) => {
23
34
  const inner = unwrapped(expression);
@@ -34,8 +45,8 @@ const layoutProblems = (code, file) => {
34
45
  };
35
46
  const visit = (node) => {
36
47
  if (ts.isJsxAttribute(node) && node.initializer && ts.isJsxExpression(node.initializer) && node.initializer.expression) {
37
- const kind = node.name.getText() === "filter" && isExpressionArrow(node.initializer.expression) ? void 0 : what(node.initializer.expression);
38
- if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data, a filter may be one arrow of the builder. Use <Action name="..."> for behaviour, or a custom component for React code.`);
48
+ const kind = isArrowProp(node) && isExpressionArrow(node.initializer.expression) ? void 0 : what(node.initializer.expression);
49
+ if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data, a filter or condition may be one arrow of the builder, the node of a Graph one arrow of its record. Use <Action name="..."> for behaviour, or a custom component for React code.`);
39
50
  }
40
51
  if (ts.isJsxExpression(node) && node.expression && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) {
41
52
  const kind = ts.isJsxElement(node.parent) && recordChildBlocks.has(node.parent.openingElement.tagName.getText().replace(/<.*$/, "")) && isExpressionArrow(node.expression) ? void 0 : what(node.expression);
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.101.0";
2
+ var version = "0.102.0";
3
3
  //#endregion
4
4
  export { version };
@@ -10,7 +10,7 @@ import { configExports, createAdmin } from "@protobase/server";
10
10
  * beside the config's resources (see `readUserTables`). `report` is what the admin does with an unhandled error.
11
11
  */
12
12
  const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) => {
13
- const { resources, views, pages, translations, userMenu, bottomBars, subscriptions } = configExports(project.config);
13
+ const { resources, views, pages, translations, templates, userMenu, bottomBars, subscriptions } = configExports(project.config);
14
14
  const unhandled = project.options?.onUnhandledError ?? ((error) => console.error(error));
15
15
  const report = (error, request) => {
16
16
  reporter?.report(error, request);
@@ -22,6 +22,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
22
22
  ...userTables && { userTables },
23
23
  pages,
24
24
  ...translations && { translations },
25
+ templates,
25
26
  ...userMenu && { userMenu },
26
27
  bottomBars,
27
28
  db,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.101.0",
3
+ "version": "0.102.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.101.0",
47
- "@protobase/layout": "0.101.0",
48
- "@protobase/query": "0.101.0",
49
- "@protobase/schema": "0.101.0",
50
- "@protobase/server": "0.101.0",
51
- "@protobase/ui": "0.101.0",
52
- "@protobase/workflows": "0.101.0",
46
+ "@protobase/config": "0.102.0",
47
+ "@protobase/layout": "0.102.0",
48
+ "@protobase/query": "0.102.0",
49
+ "@protobase/schema": "0.102.0",
50
+ "@protobase/server": "0.102.0",
51
+ "@protobase/ui": "0.102.0",
52
+ "@protobase/workflows": "0.102.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",
@@ -31,7 +31,7 @@ Pages of your own, built from blocks in a JSX layout.
31
31
  - [Image block](../reference/blocks.md#image): A picture one of the app's API functions draws for the reader, such as a system map, at the size and theme the client asks, refreshed on a timer; a client that draws no images shows its alt text, or nothing.
32
32
  - [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
33
33
  - [Timeline block](../reference/blocks.md#timeline) (beta): A `Timeline` block draws records as bars in lanes over time, each bar's parts coloured by a status field and its waits striped, with the chosen bar's details under it.
34
- - [Graph plugin](../reference/plugins.md#graph) (beta): The graph plugin draws records as nodes and the records that link them as edges, grouped by a field and coloured by status, with the chosen node's details beside it.
34
+ - [Graph block](../reference/blocks.md#graph) (beta): A `Graph` block draws records as nodes and the records that link them as edges, laid out in layers or by force or at stored positions, each node in the region of its group, coloured by its status and drawing contents of the layout's own, each edge with a label, a status colour and a moving, dashed or dotted line, with the chosen node's details beside it.
35
35
  - [Conversations](../reference/blocks.md#conversation): A chat declared in the layout: a thread of a resource's messages under each sender's name and time, following new ones as they arrive, and a box that sends one as the signed-in user.
36
36
  - [Tool calls in threads](../reference/blocks.md#tool-calls): Conversation threads show tool calls in time order, with a status and an expandable input and result.
37
37
  - [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
@@ -5,9 +5,10 @@
5
5
  Mail the app sends, the PDF documents it makes, and forms for people without an account.
6
6
 
7
7
  - [Email](../reference/email.md#configuration): The app sends mail through one SMTP server or a mailer you supply.
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
- - [Email templates](../reference/email.md#templates): Your own emails are React components with typed data, sent from jobs, hooks or functions.
10
- - [Protobase's mail look](../reference/email.md#the-look-of-protobases-own-mail): Your emails use the layout, button, code and note that Protobase's own mail is built from.
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, in English or Dutch.
9
+ - [Email templates](../reference/email.md#templates) (beta): Your own emails are templates with typed data, written in mail blocks with their texts in each language they are sent in, checked by a schema of yours or the data they read, and sent from jobs, hooks, functions or a workflow's Send email step.
10
+ - [Emails in React](../reference/email.md#emails-in-react): An email can be a React component with typed data instead, for a layout the mail blocks cannot draw.
11
+ - [Protobase's mail look](../reference/email.md#the-look-of-protobases-own-mail): Your emails use a layout, button, code and note with the look of Protobase's own mail.
11
12
  - [Unsubscribe headers](../reference/email.md#templates): Your emails carry header fields of their own, such as a one-click unsubscribe link for bulk mail.
12
13
  - [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
14
  - [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.
@@ -22,6 +22,7 @@ Graphs of steps the server runs along their edges, written in a language a model
22
22
  - [HTTP request step](../reference/workflows.md#apphttp) (beta): Calls a URL built at run time through the outgoing-address guard, only at public addresses unless the config allows private ones, reading at most 10 MiB of the answer as JSON, text or a file, by its Content-Type unless the step says which. It can send its body as JSON whatever it holds, and check the answer's body against a JSON Schema, whose fields the editor then offers.
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
+ - [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.
25
26
  - [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.
26
27
  - [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.
27
28
  - [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.
@@ -583,6 +583,63 @@ view<typeof phases>('phases').fields((r) => ({
583
583
 
584
584
  Its [text form](layouts.md#text-form) is a Markdown table with a row per segment: its lane, bar, value, start and end under the fields' labels. A timeline whose fields the user cannot read is left out of their page, and a field it cannot draw, such as a `start` that is no date, stops the server at startup.
585
585
 
586
+ ### Graph
587
+
588
+ :::caution[Beta]
589
+ A graph is read-only: you cannot move, add or connect nodes in it, and it reads at most 500 nodes and 500 edges.
590
+ :::
591
+
592
+ The records of `nodes` as boxes and the records of `edges` as arrows between them, from the node an edge's `source` holds the key of to the one its `target` holds, such as services and the links between them, or tasks and what blocks them. Each node sits in the region of its `group`, coloured by its `status`, and draws its label and status, or contents of the layout's own; each edge can carry a label, a status colour and a moving, dashed or dotted line. With `select`, the chosen node's details draw beside the graph. Its drawing code loads only on a page with a graph, and it is laid out in a worker of its own, so a large graph never holds up the page.
593
+
594
+ | Prop | |
595
+ | --- | --- |
596
+ | `nodes`, `edges` | The resources whose records are the nodes and the edges. A node is found by its key, which must be one field: a resource with a key of several fields stops the server at startup. An edge whose `source` or `target` is not among the nodes is left out. Required. |
597
+ | `source`, `target` | The fields of an edge that hold the keys of the nodes it runs from and to. Required. |
598
+ | `label` | The field of a node that names it: its text where it draws no `node`, the name of its link and its line in the text form. Required. |
599
+ | `group` | The field of a node whose value puts it in a region with the nodes that hold the same, the value at the region's top; a node without one stands outside every region. |
600
+ | `status` | An enum field of a node, shown under its label and colouring its left edge, as the view's [`valueColors`](ui-config.md#value-tones-and-currencies) give each value. |
601
+ | `node` | What each node draws, inside its record: [placeholders](layouts.md#data), `Field`s, `Show`s and the other blocks that show a record, but no block that reads records of its own, which would read once per node. In a [typed layout](layouts.md#typed-layouts) it is a function of the node's record, `(service) => <Text>{service.owner}</Text>`. A node that draws one is 224 pixels wide and as tall as it draws. |
602
+ | `filter`, `edgeFilter` | Which nodes and which edges it shows, AIP-160 or the [builder's arrow](layouts.md#the-condition-builder). |
603
+ | `edgeLabel` | A field of an edge shown on its middle, by its value label if the edges' view gives one. |
604
+ | `edgeStatus` | An enum field of an edge that colours its line and arrow, as the edges' view's `valueColors` give each value. |
605
+ | `animated`, `dashed`, `dotted` | Conditions on an edge, AIP-160 or the builder's arrow of the edge's fields, `(link) => link.state.eq('busy')`, under which its line moves, as for work running along it, is dashed or is dotted; dotted wins over dashed. Each is evaluated for each edge as the graph draws, `now()` included. |
606
+ | `layout` | `layered` (the default), the nodes in layers along their edges, or `force`, linked nodes pulled near each other and the others pushed apart, for a graph that has no direction. |
607
+ | `direction` | Which way a layered graph's edges run: `down` (the default), which keeps it narrow on a phone, or `right`. |
608
+ | `x`, `y` | Two number fields of a node that place its top left corner, in pixels at the graph's normal size. A node with both stands there, and the nodes without are laid out under the placed ones; when every node has them, nothing is laid out. |
609
+ | `select` | The [page parameter](layouts.md#page-parameters) that holds the chosen node's key: each node links to the page with it chosen, a node that draws its own `node` as a whole, and the `Graph`'s children draw beside the graph, inside that node's record, or under it on a narrow screen. |
610
+ | `empty` | What it shows without nodes. |
611
+ | `fallback` | What draws in its place where it cannot draw, as when its records cannot be read, such as the [picture](#image) one of the app's API functions draws of the same graph. Without one, it shows the error. |
612
+
613
+ ```tsx
614
+ export const serviceMap = page('service-map', layout(() => (
615
+ <Page title="Services" width="full">
616
+ <Card title="Service map">
617
+ <Graph
618
+ nodes="services" edges="links" source="from_id" target="to_id"
619
+ label="name" group="area" status="health" select="service"
620
+ node={(service) => (
621
+ <>
622
+ <Text as="strong">{service.name}</Text>
623
+ <Text>{`Owned by ${service.owner}`}</Text>
624
+ </>
625
+ )}
626
+ edgeLabel="protocol" edgeStatus="state"
627
+ animated={(link) => link.state.eq('busy')}
628
+ dashed={(link) => link.optional.eq(true)}
629
+ fallback={<Image function="service_map" alt="The services and the links between them" />}
630
+ >
631
+ <Field source="owner" />
632
+ <Field source="health" />
633
+ </Graph>
634
+ </Card>
635
+ </Page>
636
+ )))
637
+ ```
638
+
639
+ The page's [read plan](layouts.md#how-a-page-reads-its-data) reads the nodes, with the fields they and their `node` draw, and the edges, with the fields their label, colour and conditions read, with the rest of the page as it opens. The same records always make the same picture: groups, nodes and edges are laid out in the order of their keys, and a force layout from a fixed seed. The graph is as wide as its place and as tall as its shape asks, up to most of the screen; it fits in that box unless that would make it too small to read, as on a phone, where you drag to pan. Pinch or the zoom buttons zoom it, the fit button shows all of it, and the mouse wheel scrolls the page past it. <gap>A group cannot show the title of the record its field points at, because reading related records' titles in the graph is not implemented, so a relation groups by its key.</gap> <gap>Nodes cannot be dragged to store their positions, because writing `x` and `y` from the graph is not implemented; store them from elsewhere, such as an action.</gap>
640
+
641
+ Its [text form](layouts.md#text-form) lists each group with its nodes and their status, the nodes in no group, then each edge as `a → b` with its label, from the records of the page's plan, or its fallback without them. A graph whose resources, label or ends the user cannot read is left out of their page, and its other props that name fields they cannot read are dropped.
642
+
586
643
  ## Related records
587
644
 
588
645
  The blocks that repeat over a record's related records, as [related records](layouts.md#related-records) explains, with the names, props and defaults of react-admin's components. `ReferenceManyField`, `ReferenceArrayField` and `ArrayField` hold a list and draw nothing of their own; a `RecordsIterator` or a `Table` without `resource` inside one draws it. Each sits inside a record, whose field it reads.
@@ -4,7 +4,7 @@
4
4
 
5
5
  The SMTP server and sender an app's mail goes out through, and emails of the app's own, written as React components with typed data and sent from jobs, hooks and API functions.
6
6
 
7
- An app sends mail through one SMTP server: Protobase's own mail ([password reset](auth.md#password-reset), [emailed sign-in codes](auth.md#emailed-sign-in-codes), [invitations](auth.md#organizations), staff sign-in notices and [mentions in comments](comments.md#mentions)) and the emails the app defines itself. Both are React components, rendered to HTML with a plain-text part beside it.
7
+ An app sends mail through one SMTP server: Protobase's own mail ([password reset](auth.md#password-reset), [emailed sign-in codes](auth.md#emailed-sign-in-codes), [invitations](auth.md#organizations), staff sign-in notices and [mentions in comments](comments.md#mentions)) and the emails the app defines itself. Each is rendered to HTML with a plain-text part beside it.
8
8
 
9
9
  ## Configuration
10
10
 
@@ -36,15 +36,75 @@ A send through `PROTOBASE_SMTP_URL` gets 30 seconds in all: looking up the serve
36
36
 
37
37
  ## Protobase's own mail
38
38
 
39
- The auth emails (sign-in, two-factor and sign-up codes, the note to an address that asked to sign up while it has an account, password reset, invitations and staff sign-in notices) and the email to someone a [comment mentions](comments.md#mentions) are built with React Email's components: a heading, the message, one code or button, and a footer naming the app.
39
+ The auth emails (sign-in, two-factor and sign-up codes, the note to an address that asked to sign up while it has an account, password reset, invitations and staff sign-in notices) and the email to someone a [comment mentions](comments.md#mentions) are email templates: a heading, the message, one code or button, and a footer naming the app.
40
40
 
41
+ - They come in English and Dutch. An auth email is in the app's [`locale`](languages.md#choosing-the-language) when the app sets one, else in the language of the browser that asked for it, such as the one that asked for a sign-in code, else in English. The mention email is in the app's `locale`, else in English: it is sent by a job, after the request.
41
42
  - They name the app by its [`name`](config/app.md#name), and link it on the origin the request came to: the footer links its home page, and the note to an address that has an account links its sign-in page.
42
- - The plain-text part has each code on a line of its own and each link in full.
43
+ - The plain-text part has each code on a line of its own and each link in full. A date, such as when an invitation's link stops working, is written in the email's language, in UTC: `October 15, 2026 at 12:00 PM UTC`, `15 oktober 2026 om 12:00 UTC`.
43
44
  - React Email and the templates are loaded when the first auth email is sent, so an app that sends none never loads them and the server starts as fast without them.
44
45
 
45
46
  ## Templates
46
47
 
47
- An email of the app's own is `defineEmail`: a name, a subject, and a React component whose props are the email's data. The components of [React Email](https://react.email) render the tables and inline styles email clients need. `@protobase/server` brings React's renderer; the project adds the components, and React for its JSX, which a project with a UI has already:
48
+ An email of the app's own is a template: `defineTemplate`, with its data typed, its text in each language it is sent in, and its body written in mail blocks, as a [typed layout](layouts.md#typed-layouts) is. The body is built once, as the config loads, into a static tree: `data.name` is the placeholder `{{name}}`, `<Show when>` and `<Switch>` choose by the data, and an `ArrayField` repeats a list of it. Export the template from `config/index.ts`, so the workflow step [Send email](workflows.md#appmailtemplate) lists it.
49
+
50
+ ```tsx title="config/emails/contact-reply.tsx"
51
+ /** @jsxImportSource @protobase/layout */
52
+ import { Button, Show, Text, Trans, translations } from '@protobase/layout'
53
+ import { defineTemplate } from '@protobase/server'
54
+ import { z } from 'zod'
55
+ import en from './contact-reply.en.json'
56
+ import nl from './contact-reply.nl.json'
57
+
58
+ export const contactReply = defineTemplate({
59
+ name: 'contact-reply',
60
+ texts: translations({ en, nl }),
61
+ schema: z.object({ name: z.string(), topic: z.enum(['sales', 'support']), days: z.number(), id: z.string() }),
62
+ subject: ({ data }) => <Trans i18nKey="subject" values={{ name: data.name }} />,
63
+ body: ({ data, app }) => (
64
+ <>
65
+ <Text as="h1"><Trans i18nKey="greeting" values={{ name: data.name }} /></Text>
66
+ <Text><Trans i18nKey="thanks" values={{ days: data.days }} /></Text>
67
+ <Show when={data.topic.eq('sales')}>
68
+ <Text><Trans i18nKey="sales" components={{ b: <Text as="strong" /> }} /></Text>
69
+ </Show>
70
+ <Button href={`${app.url}/contact/${data.id}`}><Trans i18nKey="cta" /></Button>
71
+ </>
72
+ ),
73
+ })
74
+ ```
75
+
76
+ ```json title="config/emails/contact-reply.nl.json"
77
+ {
78
+ "subject": "We hebben je bericht ontvangen, {name}",
79
+ "greeting": "Hoi {name},",
80
+ "thanks": "{days, plural, one {We antwoorden binnen # werkdag.} other {We antwoorden binnen # werkdagen.}}",
81
+ "sales": "Een collega van sales <b>belt je</b>.",
82
+ "cta": "Bekijk je bericht"
83
+ }
84
+ ```
85
+
86
+ | `defineTemplate` option | |
87
+ | --- | --- |
88
+ | `name` | Names the template, in errors and in the step's list: a lowercase letter, then lowercase letters, digits and dashes. Each template of the app has its own. |
89
+ | `texts` | Its texts in each language it is sent in, `translations({ en, nl })` of ICU messages, which its `<Trans>` elements show, as the app's own [texts](languages.md#your-own-texts) are. Without it, the template is in one language, as written. |
90
+ | `subject` | The subject line: text, or a function of `{ data, app }` that gives text or a `<Trans>`. |
91
+ | `preview` | Optional: the line inboxes show after the subject, as `subject` is written. |
92
+ | `schema` | Optional: a [Standard Schema](https://standardschema.dev), such as a zod 4 schema, or Valibot's with `toStandardJsonSchema`, which checks the data before each send and types it. |
93
+ | `headers` | Optional: more header fields, or a function of `{ data, app }` that gives them, each one line. |
94
+ | `body` | A function of `{ data, app }` that gives the mail's blocks. `app.name` and `app.url` are the app the mail comes from. |
95
+
96
+ The body takes the mail blocks: `Text` (a paragraph, `as="h1"` to `h4` for a heading, `strong`, `em` or `span` in a line), `Trans`, `Link` with an `href`, `Button` with an `href`, `Image`, `Divider`, `Box`, `Row` and `Column`, `Show`, `Switch` and `Match`, `ArrayField` with `RecordsIterator`, and `Field`. Any other block, such as a `Table`, fails as the config loads, as does a `<Trans>` key the texts lack.
97
+
98
+ The template that comes back has two methods, both typed by the data:
99
+
100
+ - `render(data, { locale, app })` gives `{ subject, html, text, headers, locale }` without sending anything: for a test, or to look at the result.
101
+ - `send(to, data, { locale, mailer, app, attachments })` renders and sends it, through `mailer` when given (a job's `mail`), otherwise through `PROTOBASE_SMTP_URL`, and gives what it rendered. It rejects when mail is off or the server refuses the message.
102
+
103
+ A send is in the language of its texts closest to `locale`, by its tag (`nl-BE`) or its language (`nl`), else the app's `locale` when the texts have it, else English, else the first; `locale` says which it was. With a `schema`, data the schema refuses rejects with `TemplateDataError`, naming each path, before anything is sent. The data's JSON Schema, which the step draws its pins from, is the schema's own, or without one each path the template reads, such as `name` and a list `items` with its `title`.
104
+
105
+ ### Emails in React
106
+
107
+ An email can also be `defineEmail`: a name, a subject, and a React component whose props are the email's data, for a layout the mail blocks cannot draw. The components of [React Email](https://react.email) render the tables and inline styles email clients need. `@protobase/server` brings React's renderer; the project adds the components, and React for its JSX, which a project with a UI has already:
48
108
 
49
109
  ```sh
50
110
  bun add react-email react
@@ -103,7 +163,7 @@ headers: ({ unsubscribeUrl }: Digest) => ({ 'List-Unsubscribe': `<${unsubscribeU
103
163
 
104
164
  ### The look of Protobase's own mail
105
165
 
106
- `@protobase/server/email` exports the components Protobase's own mail is built from, so an app's emails can look the same: a white card on grey with a teal action.
166
+ `@protobase/server/email` exports React Email components with the look of Protobase's own mail, so an app's `defineEmail` emails can look the same: a white card on grey with a teal action.
107
167
 
108
168
  | Component | |
109
169
  | --- | --- |
@@ -62,6 +62,8 @@ Every built-in screen is translated: the shell with its sidebar, top bar, search
62
62
 
63
63
  The screens where people add [tables of their own](user-tables.md#in-the-admin-app) are translated too: the tables list, a table's page with its fields, and the forms that make a table and a field, with the names of the field types. So are the other lists Protobase adds beside your resources, failed jobs, activity and comments, with their record pages, sections and actions.
64
64
 
65
+ Protobase's [own emails](email.md#protobases-own-mail) are translated too: the sign-in, two-factor, sign-up and confirmation codes, the notes to an address that has an account or has none, password reset and the note that a password changed, invitations, staff sign-in notices and the email to someone a comment mentions. An auth email is in the app's `locale`, or else in the language of the browser that asked for it; the mention email is in the app's `locale`, or else in English.
66
+
65
67
  The approvals an AI client asks for over [MCP](mcp.md#writes) are translated too, with their buttons and the refusal for a client that cannot ask: in the app's `locale`, or else in the language the client's request accepts.
66
68
 
67
69
  The other texts a plugin or the server writes itself, such as an error message the API sends back, show as they are written.
@@ -79,7 +79,7 @@ renderText(<Page title="Order"><Field source="status" /></Page>, {
79
79
  | `locale` | The reader's locale, such as `nl-NL`, in which [field components](#field-values) without `locales` format numbers and dates; the runtime's default when omitted. |
80
80
  | `basePath` | What links start with, such as `https://example.com/admin`. |
81
81
  | `forms` | Text forms by block type, over the built-in ones. |
82
- | `models`, `labels` | The app's resources by name, and per resource its fields' labels and value labels, which a custom component's text form reads its records with, such as the graph plugin's [`graphText`](plugins.md#graph). |
82
+ | `models`, `labels` | The app's resources by name, and per resource its fields' labels and value labels, which a [`Graph`](blocks.md#graph)'s text form and a custom component's read its records with. |
83
83
  | `planned` | Per read of the page's plan, by its block's place in the tree with `#<part>` for a block's other reads (`/children/0#edges`), and the record around it, the records it holds; `pageText` gives it, so a custom component's text form reads its own reads' records. |
84
84
 
85
85
  A heading reads at its level: a `Page` title as `#`, a `Tab` label as `##`, and the title of a `Card` and of a data block as `###`, the data block's linked to its records' list as it filters them. A field's value reads as its enum label, a list as its items, and JSON as a code block. A table's records read as a Markdown table: a header row of labels, a separator row and a row per record, its columns most important first by the same rule a [phone](blocks.md#columns-on-a-phone) uses, each cell on one line with its pipes escaped. `tableMarkdown` gives the same table for records you hold yourself.
@@ -119,7 +119,7 @@ It takes the options of `renderText` but `records`, `tables` and `planned`, and
119
119
 
120
120
  A prop is a string, a finite number, a boolean, `null`, or an array or plain object of those (elements included). It is JSON in the end, so the rules are checked twice:
121
121
 
122
- - **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. Two arrows are data and pass: a [filter's arrow](#the-condition-builder) and a record block's child arrow in a [typed layout](#typed-layouts), each one expression, never a body of statements. No project code runs for this.
122
+ - **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. Two kinds of arrow are data and pass: a [filter's arrow](#the-condition-builder), and a [`Graph`](blocks.md#graph)'s `edgeFilter`, `animated`, `dashed` and `dotted`, and a record block's child arrow or a `Graph`'s `node` in a [typed layout](#typed-layouts), each one expression, never a body of statements. No project code runs for this.
123
123
  - **When the config loads.** The JSX runtime refuses anything else that is not plain data (a function in a variable, a `Date`, a `Map`, `NaN`), `page()` checks every element's props against its block (unknown, missing and mistyped props, children where none are allowed, elements that need a record outside one), and `createAdmin` checks every resource, field, filter, sort, action and condition against the models. Each problem names its place, such as `Page "overview": <Page> › <Table resource="invoices">: unknown column "amount" on invoices`.
124
124
 
125
125
  Behaviour comes from [named actions](#named-actions); React code from [custom components](custom-components.md).
@@ -188,7 +188,7 @@ export const tasksView = view<typeof tasks>('tasks').layout(() => [
188
188
  | --- | --- |
189
189
  | `data` | The record page's record, in `recordLayout` only: `data.title` is the placeholder `{{title}}`, so `` `Runs of ${data.title}` `` is `Runs of {{title}}`. |
190
190
  | `resources` | `resources.invoices.count` is how many `invoices` the user can see, for a [condition](#conditions). |
191
- | A record block's child | A `RecordCard`, a `CardRow`, a `ReferenceField` or a `RecordsIterator` takes a function of its record as its children, `(run) => ...`. Inside it `run.outcome` is `{{outcome}}`, the page's record is `{{@root.title}}`, and a record further out is `{{../outcome}}`. |
191
+ | A record block's child | A `RecordCard`, a `CardRow`, a `ReferenceField` or a `RecordsIterator` takes a function of its record as its children, `(run) => ...`, and a [`Graph`](blocks.md#graph) one of its node's record as its `node`. Inside it `run.outcome` is `{{outcome}}`, the page's record is `{{@root.title}}`, and a record further out is `{{../outcome}}`. |
192
192
 
193
193
  With `.protobase/register.d.ts`, which `protobase types`, `dev` and `build` write from `config/index.ts` (see [`types`](cli.md#types)), TypeScript checks the names against the app: `resource` against its resources, `columns`, `fields`, `sort` and the filter's fields against the resource's fields, `data` against the record's fields, and a [`<Trans>`](#texts-in-the-readers-language)'s key against its texts. Without the file, any name type-checks and the server checks them as it starts. Export a typed layout inside `page()` or a view, as above: a tree exported bare, `export const tree = layout(...)`, refers to its own type through the register, and TypeScript gives up on it.
194
194
 
@@ -209,70 +209,6 @@ export default definePlugin({ fileViewers: { 'application/vnd.example.report+jso
209
209
 
210
210
  `useFileText(file)` reads the file's text once, as a TanStack Query result kept while the file stays the same. It reads through the API that serves the record, whatever store holds the file and wherever its link points, up to 10 MB. The viewer draws on the page below the file's bar, which scrolls as the page does. The file's link is a download link served with a sandboxing CSP, so a viewer reads the file and draws it itself rather than framing it; a page of HTML it draws in an [`HtmlFrame`](files.md#html-files).
211
211
 
212
- ## Graph
213
-
214
- :::caution[Beta]
215
- A graph is read-only, and its positions are laid out automatically: you cannot move, add or connect nodes in it.
216
- :::
217
-
218
- `@protobase/graph` is a plugin with a `Graph` layout block: it draws the records of one resource as nodes and the records of another as edges between them, each node in the box of its group and coloured by its status, and with `select` the chosen node's details beside the graph. It draws with the `@xyflow/react` package and lays the graph out with the `@dagrejs/dagre` package, so an app that does not attach it carries neither. An app installs it and extends its `protobase.ui.tsx` with it:
219
-
220
- ```sh
221
- npm install @protobase/graph
222
- ```
223
-
224
- ```tsx
225
- // protobase.ui.tsx
226
- import { defineUi } from '@protobase/ui'
227
- import graph from '@protobase/graph'
228
-
229
- export default defineUi({ extends: [graph] })
230
- ```
231
-
232
- Its layout uses the block from `@protobase/graph/layout`, which carries no drawing code:
233
-
234
- ```tsx
235
- /** @jsxImportSource @protobase/layout */
236
- import { Card, Field, page, Page } from '@protobase/layout'
237
- import { Graph } from '@protobase/graph/layout'
238
-
239
- export const serviceMap = page(
240
- 'service-map',
241
- <Page title="Services" width="full">
242
- <Card title="Service map">
243
- <Graph nodes="services" edges="links" label="name" group="area" status="health" source="from_id" target="to_id" select="service">
244
- <Field source="name" />
245
- <Field source="health" />
246
- </Graph>
247
- </Card>
248
- </Page>,
249
- )
250
- ```
251
-
252
- | Prop | |
253
- | --- | --- |
254
- | `nodes` | The resource whose records are the nodes, each by its key, which is one field: a resource with a key of several fields draws the fallback. |
255
- | `edges` | The resource whose records are the edges. An edge whose `source` or `target` is not among the nodes is left out. |
256
- | `label` | The field of a node that labels it. |
257
- | `group` | The field of a node whose value puts it in a box with the nodes that hold the same; a node without one stands outside every box. |
258
- | `status` | The enum field of a node shown under its label, and colouring its left edge, as the view's `valueColors` give each value. |
259
- | `source`, `target` | The fields of an edge that hold the keys of the nodes it runs from and to. |
260
- | `select` | The [page parameter](layouts.md#page-parameters) that holds the chosen node's key: each node's label links to the page with it chosen, and the `Graph`'s children draw beside the graph, inside that node's record, or under it on a narrow screen. |
261
- | `empty` | What it shows without nodes. |
262
-
263
- The block declares its [reads](custom-components.md#reads): the page's [read plan](layouts.md#how-a-page-reads-its-data) reads the nodes and the edges, up to 500 of each, with the rest of the page as it opens, and the plugin only draws them. The same records always make the same picture: edges run top to bottom, and groups, nodes and edges are laid out in the order of their keys. The graph is as wide as its place and as tall as its shape asks, up to most of the screen; it fits in that box unless that would make it too small to read, as on a phone, where you drag to pan. Pinch or the zoom buttons zoom it, the fit button shows all of it, and the mouse wheel scrolls the page past it. <gap>A group cannot show the title of the record its field points at because reading related records' titles in the graph is not implemented, so a relation groups by its key.</gap>
264
-
265
- Where it cannot be drawn, a client draws its fallback. `graph({ fallback })` declares the block with one, such as the [picture](blocks.md#image) one of the app's API functions draws of the same graph:
266
-
267
- ```tsx
268
- import { Image } from '@protobase/layout'
269
- import { graph } from '@protobase/graph/layout'
270
-
271
- export const Graph = graph({ fallback: <Image function="service_map" alt="The services and the links between them" /> })
272
- ```
273
-
274
- Its [text form](layouts.md#text-form), `graphText` from `@protobase/graph/layout`, lists each group with its nodes and their status, then each edge as `a → b`, from the records of the page's plan: pass it as `forms: { Graph: graphText }` to `pageText`, with the app's `models` and `labels`.
275
-
276
212
  ## Building
277
213
 
278
214
  ```sh
@@ -8,7 +8,7 @@ Add trigger and step types to workflows from a file of the app or a package, thr
8
8
  Plugins add step types and record triggers. They also add polling and webhook triggers, which run within the limits named in their section, and connections that sign in to other services as an account a person connected, within the limits named under [Connections](#connections).
9
9
  :::
10
10
 
11
- A **workflow plugin** adds trigger and step types to an app's [workflows](workflows.md). Its types are named `<plugin>:<key>`, such as `acme:create_invoice`: a Task names a step type as its `Resource`, and a definition's `trigger` holds a trigger type with its input. The built-in types, `app:http`, `app:records.*`, `app:mail.send` and `app:record`, are a plugin like any other, written on this interface alone, so a plugin's types run, are checked and are listed exactly as they are. So is every [default plugin](#default-plugins), such as [incoming Gmail mail](#incoming-gmail-mail).
11
+ A **workflow plugin** adds trigger and step types to an app's [workflows](workflows.md). Its types are named `<plugin>:<key>`, such as `acme:create_invoice`: a Task names a step type as its `Resource`, and a definition's `trigger` holds a trigger type with its input. The built-in types, `app:http`, `app:records.*`, `app:mail.send`, `app:mail.template` and `app:record`, are a plugin like any other, written on this interface alone, so a plugin's types run, are checked and are listed exactly as they are. So is every [default plugin](#default-plugins), such as [incoming Gmail mail](#incoming-gmail-mail).
12
12
 
13
13
  ## Writing a plugin
14
14
 
@@ -80,6 +80,7 @@ What `run` gets, and nothing more:
80
80
  | `files` | `keep(bytes, name, type)` stores a file of the run and returns its file value; `read(value, field)` reads one the run kept. No other file of the app is reachable. |
81
81
  | `storage` | `put(configuration, path, stream, { name, type })` streams a file into a [storage configuration](workflows.md#storing-files) and returns the stored file, cancelling the stream when it fails; `open(configuration, path)` checks both before there is a stream, and its `put(stream, { name, type })` stores one there, for a step that should not fetch a file it cannot store; `read(file, field)` gives a stored file's bytes as a stream. Both read the configuration as the user who saved the version, and fail with `Storage.NotFound` for one they may not read, a file that is gone, or an app with storage off. |
82
82
  | `mail` | `send(message)` from the app's own sender; `undefined` when the app sends no mail. |
83
+ | `templates` | `list`, the app's [email templates](email.md), each with its `name`, `languages`, `dataSchema` and `send(to, data, { locale, mailer, app })`, which rejects data its schema refuses with an error whose `issues` name each path; and `app`, the `{ name, url }` the mail names as the one it comes from. `list` is empty when the app exports no templates. |
83
84
  | `connection` | `accessToken()` of the connection the step declares, or `undefined`. |
84
85
  | `mailbox` | `send(message)` from the [own mailbox](email.md#from-someones-own-mailbox) of the person who turned on the version the run runs, signed in as themselves, while they may still change the workflow; otherwise it fails `not_linked` and sends nothing. `undefined` when the app links no mailboxes. |
85
86
  | `runId`, `idempotencyKey` | The run, and a key that every retry of this visit of the step shares, while a later visit of the same state, such as in a loop, gets a new one: send it where the receiver deduplicates. A step that [waits for an outside result](workflows.md#waiting-for-an-outside-result) gets a new one with each token it hands off, so a receiver never drops the only token that can still answer. |
@@ -395,7 +395,7 @@ A user who may read a workflow but not change it gets the same page, its fields
395
395
 
396
396
  - **The graph lays itself out.** The trigger is on the left, each state is a box, a Map is a box around the states it runs for each item, and each edge is drawn from the field that names it: a state's `Next`, a Choice's rules (labelled with their condition) and its `Default` ("Otherwise"), and a Task's or Map's catchers ("On error", dashed). The graph is laid out in layers, from left to right, each time a state, an edge, a pin or a wire is added, removed or renamed; the document keeps no positions, so the graph a person sees is the one a model or the API wrote, and the one they edit is what a model reads back. The canvas zooms with the wheel, a pinch and its buttons, and pans by dragging the empty canvas.
397
397
  - **Moving nodes by hand.** Dragging a node, a step, the trigger, a Break, a Make or a condition node, puts it where it is let go, as do the arrow keys on the chosen node. Shift-click adds a node to the choice or takes it out, and Shift-drag on the empty canvas chooses every node its box covers; the nodes chosen move together, and Delete removes them all. A step's form opens only on a plain click on it, never while a choice is made with Shift or a box. It stays there, marked with a pin, and the nodes not moved are laid out around it, also as steps and connections change: one the layout would put under it goes below it, and a Map or Block grows around a node moved inside it. *Pins* and *Simple* each keep their own places, so a node moved in one view stays where the layout puts it in the other. The pin's *Unpin* hands the node back to the layout, and *Tidy up*, above the graph, lays the view shown out again, forgetting every node moved in it and leaving the other view's. Where nodes were moved is the workflow's [layout](#layout), shared with everyone who edits it and saved by *Save*; it makes no new version and needs no publish. An older version opens with the layout it was saved with, which cannot be changed. <gap>A step renamed in the editor cannot keep the place it was moved to because carrying its layout key over to its new name is not implemented.</gap>
398
- - **Adding a step.** *Add step* opens a searchable picker in the panel: every step type the app can run, its plugins' included, each with what it does, then Choice, For each item, Wait, Set values, Succeed and Fail. Search finds other words too, such as *email* for Send mail. It says where the step lands, and choosing a step on the graph changes that. Clicking or tapping one of a step's handles, which grows into a plus under the pointer, opens the same picker for a step right there: at the bottom handle after the step, at a Choice's *When* as a new rule and at its *Otherwise* as its `Default`, at *On error* on the path of every error, and at the trigger's as the first step. Where the handle led to a step already, the new one goes in between and goes on to that step, such as between the trigger and the first step; a Succeed or Fail there stays unconnected. A new step is named `Step 1`, `Step 2` and so on, and goes after the chosen step, taking over where it went on to, or after the last step; into the Map chosen; or first, with the trigger chosen. After a Choice or a step that ends the run it stays unconnected, and so does a Succeed or Fail that would cut off the steps after it, such as one added between two steps or first in a workflow that has steps.
398
+ - **Adding a step.** *Add step* opens a searchable picker in the panel: every step type the app can run, its plugins' included, each with what it does, then Choice, For each item, Wait, Set values, Succeed and Fail. Search finds other words too, such as *email* for Send plain mail. It says where the step lands, and choosing a step on the graph changes that. Clicking or tapping one of a step's handles, which grows into a plus under the pointer, opens the same picker for a step right there: at the bottom handle after the step, at a Choice's *When* as a new rule and at its *Otherwise* as its `Default`, at *On error* on the path of every error, and at the trigger's as the first step. Where the handle led to a step already, the new one goes in between and goes on to that step, such as between the trigger and the first step; a Succeed or Fail there stays unconnected. A new step is named `Step 1`, `Step 2` and so on, and goes after the chosen step, taking over where it went on to, or after the last step; into the Map chosen; or first, with the trigger chosen. After a Choice or a step that ends the run it stays unconnected, and so does a Succeed or Fail that would cut off the steps after it, such as one added between two steps or first in a workflow that has steps.
399
399
  - **Pins and wires.** Execution runs along the square handles in a box's header, and data along round pins below it, coloured by type: each argument of a Task's step type is a pin on the left, with its type on hover, and each value a step returns, or the trigger gives the run, is a pin on the right, such as an HTTP request's *Status*, *Headers* and *Body* and a record trigger's *Record*. A record, an HTTP body with a `body_schema`, headers and any other object with a title are one pin each. Dragging an output pin to an input pin wires them: the input reads that value by name, the step it comes from gets a variable keeping its result when it has none, and taking the wire away empties the input. A wire is refused over a pin that does not take it, saying why, such as *Whole number does not fit Text*, or that the step does not run before. An input no wire reads shows its value on its row, to type there where it is text, a number, true or false or a choice; an expression shows as ƒ and an object as {…}, both edited in the step's form. Inputs a type does not need and that hold nothing fold away behind *N more inputs*. The layout orders the nodes by where their wires meet their pins, so wires cross as little as they can, and in data order puts each node just before what reads it, so a Break, a condition node or a Select stands beside its step.
400
400
  - **Break and Make.** Letting go of a wire from an object pin on the empty canvas offers *Break <Type>*, a node with a pin for each field of the object, such as a record's fields; from an object input, *Make <Type>*, which builds it from a pin per field, such as the fields a records step writes. They are the editor's own: they run no step and leave no trace, the inputs that use them read `$fetch.body.ip` and hold `{ "name": "{% $fetch.body.ip %}" }`, and opening a workflow draws a Break for each object a read goes into and a Make for each argument written as an object whose fields read values. One that nothing reads yet goes with a reload. A Break shows only the fields something reads, through a wire or an expression, and *N more fields* opens the rest; one that nothing reads yet shows them all.
401
401
  - **Select.** An argument chosen by another value is drawn as a *Select* node between them: its one input is the value it looks at, a row per case gives a value of its own when that value is one of its own, and *Otherwise* gives one for any other, all typed on the node; *Add case* adds one. It is the editor's own: it writes a chain of conditionals, `{% $states.context.Execution.Input.body.topic = 'sales' ? 'sales@example.com' : 'support@example.com' %}`, and one written that way, spaced as the node writes it, opens as the node, as it was saved. Letting go of a wire from an input of a value, empty or holding one of its own, on the empty canvas offers *Select*, whose one case and Otherwise give what the input held. Its position is kept under `Notify.#select.to`. Removing it removes the argument.
@@ -478,6 +478,35 @@ A get and a list only read; a create and an update are recorded. They go through
478
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
480
 
481
+ ### app:mail.template
482
+
483
+ **Send email** sends one of the app's [email templates](email.md), the `defineTemplate(...)` templates its config exports:
484
+
485
+ | Argument | |
486
+ | --- | --- |
487
+ | `template` | The template's name, one of the app's templates. |
488
+ | `to` | One address. |
489
+ | `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
+ | `data` | The template's data, as its schema takes it. |
491
+
492
+ ```json
493
+ {
494
+ "Type": "Task",
495
+ "Resource": "app:mail.template",
496
+ "Arguments": {
497
+ "template": "order-confirmation",
498
+ "to": "{% $states.context.Execution.Input.record.email %}",
499
+ "locale": "{% $states.context.Execution.Input.record.language %}",
500
+ "data": { "name": "{% $states.context.Execution.Input.record.name %}", "order": "{% $states.context.Execution.Input.record.number %}" }
501
+ },
502
+ "End": true
503
+ }
504
+ ```
505
+
506
+ 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
+
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.
509
+
481
510
  ### app:piece
482
511
 
483
512
  `piece`, `action`, `connection` and `props` name an action of a connector and its arguments. A save takes it, and a run fails it with `Piece.Error`. <gap>A piece step cannot run an action because its handler is not implemented.</gap>
@@ -13,6 +13,12 @@ state, step type and trigger, is in [the workflows reference](references/referen
13
13
  not check a resource's name or its fields: `"resource": "contact_messages"` saves and fails when it runs.
14
14
  3. Records steps act as the user who saved the workflow, with that user's roles now; mail always goes from the app's
15
15
  own sender.
16
+ 4. For a mail the app has a template for, use `app:mail.template` (Send email), not `app:mail.send`. Its
17
+ `template` argument in `list_workflow_types` names the app's templates, and the list's `templates` gives each one's
18
+ languages and the JSON Schema of its data. Pass `template`, `to`, an optional `locale` such as `nl`, and `data`
19
+ shaped as that schema: `{ "template": "welcome", "to": "{% $contact.email %}", "data": { "name": "{% $contact.name %}" } }`.
20
+ Data the schema refuses fails the step with `Mail.InvalidData`, naming each path. Use `app:mail.send` for a plain
21
+ mail whose subject and text the workflow writes itself.
16
22
 
17
23
  ## Sequence or data order
18
24