@protobase/cli 0.100.25 → 0.101.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/layout-check.js +15 -4
- package/dist/cli/package.js +1 -1
- package/dist/project/project-admin.js +3 -1
- package/dist/project/project-types.js +29 -6
- package/package.json +8 -8
- package/skills/protobase/references/features/compatibility.md +1 -1
- package/skills/protobase/references/features/composed-pages.md +3 -1
- package/skills/protobase/references/features/email-and-public-forms.md +4 -3
- package/skills/protobase/references/features/look-and-language.md +1 -0
- package/skills/protobase/references/features/workflows.md +1 -0
- package/skills/protobase/references/guides/billing-page.md +5 -5
- package/skills/protobase/references/guides/first-composed-page.md +10 -10
- package/skills/protobase/references/reference/blocks.md +27 -13
- package/skills/protobase/references/reference/cli.md +3 -1
- package/skills/protobase/references/reference/email.md +65 -5
- package/skills/protobase/references/reference/languages.md +38 -2
- package/skills/protobase/references/reference/layouts.md +71 -6
- package/skills/protobase/references/reference/workflow-plugins.md +2 -1
- package/skills/protobase/references/reference/workflows.md +30 -1
- package/skills/protobase/workflows.md +6 -0
|
@@ -12,6 +12,17 @@ const what = (expression) => {
|
|
|
12
12
|
if (ts.isClassExpression(inner)) return "a class";
|
|
13
13
|
if (ts.isNewExpression(inner)) return `a new ${inner.expression.getText()}`;
|
|
14
14
|
};
|
|
15
|
+
const recordChildBlocks = /* @__PURE__ */ new Set([
|
|
16
|
+
"RecordCard",
|
|
17
|
+
"CardRow",
|
|
18
|
+
"ReferenceField",
|
|
19
|
+
"RecordsIterator"
|
|
20
|
+
]);
|
|
21
|
+
const unwrapped = (expression) => ts.isParenthesizedExpression(expression) ? expression.expression : expression;
|
|
22
|
+
const isExpressionArrow = (expression) => {
|
|
23
|
+
const inner = unwrapped(expression);
|
|
24
|
+
return ts.isArrowFunction(inner) && !ts.isBlock(inner.body);
|
|
25
|
+
};
|
|
15
26
|
const isHookCall = (node) => ts.isCallExpression(node) && /^use[A-Z]/.test(ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : node.expression.getText());
|
|
16
27
|
/** Every place in a layout file where JSX gets a value that cannot be static, and every hook call. */
|
|
17
28
|
const layoutProblems = (code, file) => {
|
|
@@ -23,12 +34,12 @@ const layoutProblems = (code, file) => {
|
|
|
23
34
|
};
|
|
24
35
|
const visit = (node) => {
|
|
25
36
|
if (ts.isJsxAttribute(node) && node.initializer && ts.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
26
|
-
const kind = what(node.initializer.expression);
|
|
27
|
-
if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data. Use <Action name="..."> for behaviour, or a custom component for React code.`);
|
|
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.`);
|
|
28
39
|
}
|
|
29
40
|
if (ts.isJsxExpression(node) && node.expression && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) {
|
|
30
|
-
const kind = what(node.expression);
|
|
31
|
-
if (kind) problems.push(`${at(node)}: a child of <${ts.isJsxElement(node.parent) ? node.parent.openingElement.tagName.getText() : ""}> is ${kind}; layout children must be elements or text.`);
|
|
41
|
+
const kind = ts.isJsxElement(node.parent) && recordChildBlocks.has(node.parent.openingElement.tagName.getText().replace(/<.*$/, "")) && isExpressionArrow(node.expression) ? void 0 : what(node.expression);
|
|
42
|
+
if (kind) problems.push(`${at(node)}: a child of <${ts.isJsxElement(node.parent) ? node.parent.openingElement.tagName.getText() : ""}> is ${kind}; layout children must be elements or text, or for a ${[...recordChildBlocks].join(", ")} one arrow of its record.`);
|
|
32
43
|
}
|
|
33
44
|
if (isHookCall(node)) problems.push(`${at(node)}: ${node.expression.getText()}() is a hook; layouts have no state. Put stateful UI in a custom component.`);
|
|
34
45
|
ts.forEachChild(node, visit);
|
package/dist/cli/package.js
CHANGED
|
@@ -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, 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);
|
|
@@ -21,6 +21,8 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
|
|
|
21
21
|
views,
|
|
22
22
|
...userTables && { userTables },
|
|
23
23
|
pages,
|
|
24
|
+
...translations && { translations },
|
|
25
|
+
templates,
|
|
24
26
|
...userMenu && { userMenu },
|
|
25
27
|
bottomBars,
|
|
26
28
|
db,
|
|
@@ -48,10 +48,30 @@ const cliTypePaths = (ownDir = cliDir) => Object.fromEntries(typedPackages.flatM
|
|
|
48
48
|
const dir = findPackageDirSync(name, ownDir) ?? findPackageDirSync(name, uiPackageDir);
|
|
49
49
|
return dir ? packagePaths(name, dir).map(([id, file]) => [id, [file]]) : [];
|
|
50
50
|
}));
|
|
51
|
+
/** The declarations that register the project's config module, which typed layouts read their resources and texts from. */
|
|
52
|
+
const registerFile = path.join(protobaseFolder, "register.d.ts");
|
|
53
|
+
const register = [
|
|
54
|
+
"// Written by protobase: the project's config module, which layout(), recordLayout() and <Trans> read the app's",
|
|
55
|
+
"// resources, fields and texts from. Wrap a typed layout in page() or a view; a layout exported bare refers to itself.",
|
|
56
|
+
"import type * as app from '../config/index'",
|
|
57
|
+
"",
|
|
58
|
+
"declare module '@protobase/layout' {",
|
|
59
|
+
" interface Register {",
|
|
60
|
+
" app: typeof app",
|
|
61
|
+
" }",
|
|
62
|
+
"}",
|
|
63
|
+
""
|
|
64
|
+
].join("\n");
|
|
65
|
+
const writeChanged = async (file, content) => {
|
|
66
|
+
if (existsSync(file) && readFileSync(file, "utf8") === content) return;
|
|
67
|
+
await writeFile(file, content);
|
|
68
|
+
};
|
|
51
69
|
/**
|
|
52
70
|
* Writes `.protobase/tsconfig.json` in `projectDir`, which the project's tsconfig.json extends: in a bundled project
|
|
53
71
|
* its `paths` give the @protobase packages and those the serve runtime supplies the types of the CLI that builds the
|
|
54
|
-
* app, with nothing installed; a locked project's installed packages type themselves, so it holds no paths.
|
|
72
|
+
* app, with nothing installed; a locked project's installed packages type themselves, so it holds no paths. With a
|
|
73
|
+
* `config/index.ts` it also writes `.protobase/register.d.ts`, which types the layouts by the app's resources and texts,
|
|
74
|
+
* and includes it beside the project's files; a project tsconfig.json with an `include` of its own lists it there. The
|
|
55
75
|
* folder ignores itself in git, since the paths are this machine's. An unchanged file is left alone: Vite reloads every
|
|
56
76
|
* module on any write to a tsconfig.json, so another command rewriting it would rebuild a running dev server's API.
|
|
57
77
|
*/
|
|
@@ -61,10 +81,13 @@ const writeProjectTypes = async (projectDir) => {
|
|
|
61
81
|
const ignore = path.join(folder, ".gitignore");
|
|
62
82
|
if (!existsSync(ignore)) await writeFile(ignore, "*\n");
|
|
63
83
|
const compilerOptions = projectPackages(projectDir).mode === "bundled" ? { paths: cliTypePaths() } : {};
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await
|
|
84
|
+
const registered = existsSync(path.join(projectDir, "config", "index.ts"));
|
|
85
|
+
if (registered) await writeChanged(path.join(projectDir, registerFile), register);
|
|
86
|
+
const include = registered ? { include: ["../**/*", "register.d.ts"] } : {};
|
|
87
|
+
await writeChanged(path.join(projectDir, typesFile), `${JSON.stringify({
|
|
88
|
+
compilerOptions,
|
|
89
|
+
...include
|
|
90
|
+
}, null, 2)}\n`);
|
|
68
91
|
};
|
|
69
92
|
//#endregion
|
|
70
|
-
export { cliTypePaths, typesFile, writeProjectTypes };
|
|
93
|
+
export { cliTypePaths, registerFile, typesFile, writeProjectTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.1",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.101.1",
|
|
47
|
+
"@protobase/layout": "0.101.1",
|
|
48
|
+
"@protobase/query": "0.101.1",
|
|
49
|
+
"@protobase/schema": "0.101.1",
|
|
50
|
+
"@protobase/server": "0.101.1",
|
|
51
|
+
"@protobase/ui": "0.101.1",
|
|
52
|
+
"@protobase/workflows": "0.101.1",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -26,7 +26,7 @@ Apps written for other systems that keep working on Protobase, and moving their
|
|
|
26
26
|
## react-admin
|
|
27
27
|
|
|
28
28
|
- [Related records](../reference/layouts.md#related-records) (beta): Layouts take react-admin's `ReferenceManyField`, `ReferenceArrayField`, `ArrayField`, `RecordsIterator` and `ReferenceField` with their names, props and defaults: `sort` is the key descending, and a `ReferenceManyField`'s `source` is `id` and its `perPage` 25.
|
|
29
|
-
- [
|
|
29
|
+
- [Filters and sorts on related records](../reference/layouts.md#related-records) (beta): `filter` is AIP-160 text or the condition builder's arrow, since an object cannot say `OR`, and `sort` a list of fields, `['claimed_at desc']`; react-admin's `{ field: value }` and `{ field, order }` objects are not taken.
|
|
30
30
|
- [Page size of related records](../reference/layouts.md#related-records) (beta): A list reads at most 500 records, the API's largest page, which is also a `ReferenceArrayField`'s `perPage` where react-admin's is 1000.
|
|
31
31
|
- [Items of an ArrayField](../reference/layouts.md#related-records) (beta): A text item of an `ArrayField` is read as `this`. An `ArrayField` takes no `filter`, `sort` or `perPage` yet.
|
|
32
32
|
- [RecordsIterator without functions](../reference/layouts.md#related-records) (beta): `RecordsIterator` takes no `render`, `data`, `total` or `isPending`, as a layout holds no functions and the list around it gives the rest.
|
|
@@ -7,7 +7,9 @@ Pages of your own, built from blocks in a JSX layout.
|
|
|
7
7
|
- [Composed pages](../reference/layouts.md#setup): Pages built from a JSX layout, with their own address, sidebar entry and role limits, reading the API under the same access rules as the lists.
|
|
8
8
|
- [Layout checks](../reference/layouts.md#what-a-layout-may-hold): The build refuses a layout with code, unknown props or unknown fields, and names the file and place.
|
|
9
9
|
- [Page parameters](../reference/layouts.md#page-parameters) (beta): A page holds a choice in its address with `SelectInput`, reads it in its layout, and shows the details of a row chosen in a table.
|
|
10
|
-
- [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record
|
|
10
|
+
- [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record, a count or the time, `now() + 7d`, holds.
|
|
11
|
+
- [Typed layouts](../reference/layouts.md#typed-layouts) (beta): `layout()` and `recordLayout()` write a page's tree with the record and the app's tables in hand, so TypeScript checks every resource, column, sort and field against the app, and record blocks take a function of their record.
|
|
12
|
+
- [The condition builder](../reference/layouts.md#the-condition-builder) (beta): A filter is an arrow, `(f) => f.status.eq('open').and(f.due_at.lt(now().plus('7d')))`, and a condition the same builder's, written as AIP-160 for you.
|
|
11
13
|
- [Paths and scopes](../reference/layouts.md#paths-and-scopes) (beta): Layout values resolve through the records around them with paths relative to those records, such as `../name`, `this.name` and `@index`; typos and reads that would wait on other reads fail the build, and `Show`, `Switch` and `Match` choose what is drawn.
|
|
12
14
|
- [Field values and expanding lines](../reference/layouts.md#field-values) (beta): Layouts show a record's values inline in text and links with react-admin's field components, such as `DateField` and `NumberField`, and a line that opens to show more with `Details` and `Summary`.
|
|
13
15
|
- [App addresses](../reference/layouts.md#addresses): Links to lists, records, create forms and pages are typed addresses that can carry filters and prefilled values.
|
|
@@ -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
|
|
10
|
-
- [
|
|
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.
|
|
@@ -11,6 +11,7 @@ The app's colours, name, icon, language and installation.
|
|
|
11
11
|
- [Logo and favicon](../reference/theme.md#logo-and-favicon): Your own favicon or logo replaces Protobase's.
|
|
12
12
|
- [Named icons](../reference/layouts.md#named-actions): Actions, key facts and card meta show an icon picked by name from a set, such as `play`, `bed` or `cpu`.
|
|
13
13
|
- [English and Dutch](../reference/languages.md): The built-in screens come in English and Dutch, with numbers and dates written to match.
|
|
14
|
+
- [The app's own texts](../reference/languages.md#your-own-texts) (beta): Pages and labels come in each language the app has translations for, ICU messages shown with `<Trans>`, in the reader's language, and the server refuses to start on a missing text.
|
|
14
15
|
- [Installable app](../reference/installable-app.md): The admin installs as an app on phones and computers, and says when the server cannot be reached.
|
|
15
16
|
- [Start from the last pages seen](../reference/installable-app.md#starting-from-the-last-pages-seen): Someone signed in opens the app on what it showed last time, muted with a spinner by the title until it is refreshed in the background.
|
|
16
17
|
|
|
@@ -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.
|
|
@@ -161,7 +161,7 @@ export const billing = page(
|
|
|
161
161
|
<CardRow
|
|
162
162
|
title="Payment methods"
|
|
163
163
|
resource="payment_methods"
|
|
164
|
-
sort=
|
|
164
|
+
sort={['is_default desc', 'id']}
|
|
165
165
|
actions={<ModalForm mode="create" label="Add card" resource="payment_methods" fields={['brand', 'last4', 'expires']} />}
|
|
166
166
|
>
|
|
167
167
|
<Field source="brand" label={false} />
|
|
@@ -178,7 +178,7 @@ export const billing = page(
|
|
|
178
178
|
)
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
The cards sit side by side in a `CardRow`, the default card first (`sort=
|
|
181
|
+
The cards sit side by side in a `CardRow`, the default card first (`sort={['is_default desc', 'id']}`). Two `Show` blocks split the card on its own `is_default` field: the default card says so, the others get "Make default" and "Remove". Those are again view actions, `a.update('makeDefault', ...)` and `a.remove('remove', ...)` in the views above.
|
|
182
182
|
|
|
183
183
|
Making a card the default unsets the others in the database (a trigger or a write hook); the row reloads after every action, so the order follows. "Add card" is a `ModalForm mode="create"` in the row's header. In the story, make the Mastercard the default, remove the Visa and add a card.
|
|
184
184
|
|
|
@@ -226,7 +226,7 @@ export const billing = page(
|
|
|
226
226
|
<CardRow
|
|
227
227
|
title="Payment methods"
|
|
228
228
|
resource="payment_methods"
|
|
229
|
-
sort=
|
|
229
|
+
sort={['is_default desc', 'id']}
|
|
230
230
|
actions={<ModalForm mode="create" label="Add card" resource="payment_methods" fields={['brand', 'last4', 'expires']} />}
|
|
231
231
|
>
|
|
232
232
|
<Field source="brand" label={false} />
|
|
@@ -239,10 +239,10 @@ export const billing = page(
|
|
|
239
239
|
</Show>
|
|
240
240
|
</CardRow>
|
|
241
241
|
<Grid columns={3}>
|
|
242
|
-
<Table title="Invoices" resource="invoices" sort=
|
|
242
|
+
<Table title="Invoices" resource="invoices" sort={['issued_at desc']} limit={5} span={2} />
|
|
243
243
|
<Grid columns={1}>
|
|
244
244
|
<Stat label="Open invoices" resource="invoices" filter="status = 'open'" />
|
|
245
|
-
<RecordCard title="Latest invoice" resource="invoices" sort=
|
|
245
|
+
<RecordCard title="Latest invoice" resource="invoices" sort={['issued_at desc']} actions={<Action name="download" />}>
|
|
246
246
|
<Grid columns={2}>
|
|
247
247
|
<Field source="number" />
|
|
248
248
|
<Field source="total" />
|
|
@@ -59,15 +59,15 @@ export const overview = page(
|
|
|
59
59
|
<Stat label="Open leads" resource="companies" filter="status = 'lead'" />
|
|
60
60
|
</Grid>
|
|
61
61
|
<Grid columns={2}>
|
|
62
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
63
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
62
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
63
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
64
64
|
</Grid>
|
|
65
65
|
</Page>,
|
|
66
66
|
{ nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
|
|
67
67
|
)
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
A `Table` takes the same `resource`, `filter` and `sort` (
|
|
70
|
+
A `Table` takes the same `resource`, `filter` and `sort` (a list of fields, like `?order_by=` one entry at a time), plus the `columns` to show and a `limit`. Relations such as `company_id` show the company's name, a row opens the record, and **View all** opens the list with the same filter and order. Try it on the overdue invoices: there are three, and the table shows two.
|
|
71
71
|
|
|
72
72
|
## 3. One order to chase
|
|
73
73
|
|
|
@@ -90,7 +90,7 @@ export const overview = page(
|
|
|
90
90
|
title="Biggest unpaid delivery"
|
|
91
91
|
resource="orders"
|
|
92
92
|
filter="status = 'delivered' AND paid = false"
|
|
93
|
-
sort=
|
|
93
|
+
sort={['total desc']}
|
|
94
94
|
empty="Every delivered order is paid."
|
|
95
95
|
actions={<Action name="markPaid" variant="primary" />}
|
|
96
96
|
>
|
|
@@ -103,8 +103,8 @@ export const overview = page(
|
|
|
103
103
|
<Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
|
|
104
104
|
</RecordCard>
|
|
105
105
|
<Grid columns={2}>
|
|
106
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
107
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
106
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
107
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
108
108
|
</Grid>
|
|
109
109
|
</Page>,
|
|
110
110
|
{ nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
|
|
@@ -187,7 +187,7 @@ export const overview = page(
|
|
|
187
187
|
title="Biggest unpaid delivery"
|
|
188
188
|
resource="orders"
|
|
189
189
|
filter="status = 'delivered' AND paid = false"
|
|
190
|
-
sort=
|
|
190
|
+
sort={['total desc']}
|
|
191
191
|
empty="Every delivered order is paid."
|
|
192
192
|
actions={<Action name="markPaid" variant="primary" />}
|
|
193
193
|
>
|
|
@@ -200,15 +200,15 @@ export const overview = page(
|
|
|
200
200
|
<Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
|
|
201
201
|
</RecordCard>
|
|
202
202
|
<Grid columns={2}>
|
|
203
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
204
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
203
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
204
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
205
205
|
</Grid>
|
|
206
206
|
<CardRow
|
|
207
207
|
title="New leads"
|
|
208
208
|
description="Companies that have not ordered yet."
|
|
209
209
|
resource="companies"
|
|
210
210
|
filter="status = 'lead'"
|
|
211
|
-
sort=
|
|
211
|
+
sort={['created_at desc']}
|
|
212
212
|
actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'email']} values={{ status: 'lead' }} />}
|
|
213
213
|
>
|
|
214
214
|
<Field source="name" label={false} />
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Every built-in layout block, its props and what it does, with examples from the ERP's sales overview.
|
|
6
6
|
|
|
7
|
-
Blocks are imported from `@protobase/layout`. Every block also takes [`className`](layouts.md#tailwind-classes), Tailwind classes for its outer element. "Record" below means the record of the `RecordCard`, `CardRow` card or `RecordsIterator` entry around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort`
|
|
7
|
+
Blocks are imported from `@protobase/layout`. Every block also takes [`className`](layouts.md#tailwind-classes), Tailwind classes for its outer element. "Record" below means the record of the `RecordCard`, `CardRow` card or `RecordsIterator` entry around a block (see [Data](layouts.md#data)); `filter` is AIP-160, as in the list API, or the [builder's arrow](layouts.md#the-condition-builder), and `sort` a list of fields, each with `asc` or `desc` if it likes, as the list API's `order_by`. The ERP example's sales overview uses `Page`, `Grid`, `Card`, `Stat`, `Table`, `RecordCard`, `CardRow`, `Field`, `Chart`, `Action`, `ModalForm` and `Show`; of the others, the property portal's home uses `RecordRow`, and the [Users page](auth.md#users-page) `Users`:
|
|
8
8
|
|
|
9
9
|
```tsx title="tests/apps/erp/config/overview/page.tsx"
|
|
10
10
|
/** @jsxImportSource @protobase/layout */
|
|
@@ -31,7 +31,7 @@ export const salesOverview = page(
|
|
|
31
31
|
title="Biggest unpaid delivery"
|
|
32
32
|
resource="orders"
|
|
33
33
|
filter="status = 'delivered' AND paid = false"
|
|
34
|
-
sort=
|
|
34
|
+
sort={['total desc']}
|
|
35
35
|
empty="Every delivered order is paid."
|
|
36
36
|
actions={<Action name="markPaid" variant="primary" />}
|
|
37
37
|
>
|
|
@@ -47,7 +47,7 @@ export const salesOverview = page(
|
|
|
47
47
|
title="Oldest overdue invoice"
|
|
48
48
|
resource="invoices"
|
|
49
49
|
filter="status = 'overdue'"
|
|
50
|
-
sort=
|
|
50
|
+
sort={['issued_at']}
|
|
51
51
|
empty="Nothing is overdue."
|
|
52
52
|
actions={[<Action name="send" label="Send reminder" />, <Action name="recordPayment" variant="primary" />]}
|
|
53
53
|
>
|
|
@@ -67,15 +67,15 @@ export const salesOverview = page(
|
|
|
67
67
|
<Chart title="Revenue by customer" description="Orders not cancelled." resource="orders" groupBy="company_id" sum="total" filter="status != 'cancelled'" limit={5} />
|
|
68
68
|
</Grid>
|
|
69
69
|
<Grid columns={2}>
|
|
70
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
71
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
70
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={5} empty="Nothing is overdue." />
|
|
71
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
72
72
|
</Grid>
|
|
73
73
|
<CardRow
|
|
74
74
|
title="New leads"
|
|
75
75
|
description="Companies that have not ordered yet."
|
|
76
76
|
resource="companies"
|
|
77
77
|
filter="status = 'lead'"
|
|
78
|
-
sort=
|
|
78
|
+
sort={['created_at desc']}
|
|
79
79
|
limit={8}
|
|
80
80
|
actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'country_code', 'email']} values={{ status: 'lead' }} />}
|
|
81
81
|
>
|
|
@@ -165,7 +165,7 @@ Plain elements for a page too custom for the blocks, drawn by their [Tailwind cl
|
|
|
165
165
|
| `Box` | An element of its own, such as a panel or a banner. No look of its own. |
|
|
166
166
|
| `Row` | Its children side by side: `flex`. |
|
|
167
167
|
| `Column` | Its children one under another: `flex flex-col`. |
|
|
168
|
-
| `Text` | Text, `Link`s, `
|
|
168
|
+
| `Text` | Text, `Link`s, `Trans`es, inline `Text`s and [field components](#field-components) in it, nothing else, run as one line. `as` makes it `p` (the default), `span`, `strong`, `em`, or a heading `h1` to `h4`; `span`, `strong` and `em` run inline. |
|
|
169
169
|
|
|
170
170
|
```tsx
|
|
171
171
|
<Row className="items-center gap-3">
|
|
@@ -174,6 +174,20 @@ Plain elements for a page too custom for the blocks, drawn by their [Tailwind cl
|
|
|
174
174
|
</Row>
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
+
### Trans
|
|
178
|
+
|
|
179
|
+
One of the app's own texts in the reader's language, as react-i18next's `<Trans>`: as a child, it runs inline as text does, and as a `title`, `description`, `label` or `empty` it reads as that prop's text. See [Texts in the reader's language](layouts.md#texts-in-the-readers-language).
|
|
180
|
+
|
|
181
|
+
| Prop | |
|
|
182
|
+
| --- | --- |
|
|
183
|
+
| `i18nKey` | The message's key in the app's [translations](languages.md#your-own-texts), such as `today.open`. Required. |
|
|
184
|
+
| `values` | What the message formats by name, `{ count: 2, name: '{{owner}}' }`: text, numbers, booleans and placeholders. |
|
|
185
|
+
| `components` | The element each tag of the message draws, `{ b: <Text as="strong" /> }`, with the tag's text inside it. As a prop's text, tags read as their text alone. |
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
<Trans i18nKey="today.owner" values={{ name: '{{owner}}' }} components={{ b: <Text as="strong" /> }} />
|
|
189
|
+
```
|
|
190
|
+
|
|
177
191
|
### Details and Summary
|
|
178
192
|
|
|
179
193
|
A line that opens to show the rest and closes again, drawn as HTML's [`<details>` and `<summary>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details), so the browser opens and closes it with no script. A `Details` takes one `Summary`, as its first child; the `Summary` is one line, holding what a `Text` holds. See [Field values](layouts.md#field-values).
|
|
@@ -251,7 +265,7 @@ The first records of a list, drawn the way the resource's list page draws them:
|
|
|
251
265
|
| `span` | Width in a grid. |
|
|
252
266
|
|
|
253
267
|
```tsx
|
|
254
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
268
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={5} empty="Nothing is overdue." />
|
|
255
269
|
```
|
|
256
270
|
|
|
257
271
|
#### Columns on a phone
|
|
@@ -349,7 +363,7 @@ One record and what is inside it: the one `recordKey` names (the key as the reco
|
|
|
349
363
|
| `span` | Width in a grid. |
|
|
350
364
|
|
|
351
365
|
```tsx
|
|
352
|
-
<RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort=
|
|
366
|
+
<RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort={['total desc']} actions={<Action name="markPaid" variant="primary" />}>
|
|
353
367
|
<Field source="number" />
|
|
354
368
|
<Field source="company_id.city" label="City" />
|
|
355
369
|
</RecordCard>
|
|
@@ -383,7 +397,7 @@ It follows the resource's view as its list page does. Of a resource whose view h
|
|
|
383
397
|
| `span` | Width in a grid. |
|
|
384
398
|
|
|
385
399
|
```tsx
|
|
386
|
-
<RecordRow title="For rent" resource="listings" filter="for_rent = true AND status = 'available'" sort=
|
|
400
|
+
<RecordRow title="For rent" resource="listings" filter="for_rent = true AND status = 'available'" sort={['published_at desc']} />
|
|
387
401
|
```
|
|
388
402
|
|
|
389
403
|
### RecordCards
|
|
@@ -582,14 +596,14 @@ The records of `reference` whose `target` holds the record's `source`, as [react
|
|
|
582
596
|
| `reference` | The resource it reads. Required. |
|
|
583
597
|
| `target` | The field of `reference` that points at the record. Required. |
|
|
584
598
|
| `source` | The field of the record it matches; default `id`, of the nearest record. A [path](layouts.md#paths-and-scopes), such as `../id`. |
|
|
585
|
-
| `filter` | More conditions, as AIP-160 text or
|
|
586
|
-
| `sort` |
|
|
599
|
+
| `filter` | More conditions, as AIP-160 text or the [builder's arrow](layouts.md#the-condition-builder), ANDed with the target's. |
|
|
600
|
+
| `sort` | A list of fields, each with `asc` or `desc` if it likes, `['claimed_at desc']`; default the key, descending. |
|
|
587
601
|
| `perPage` | How many records it reads, at most 500; default 25. |
|
|
588
602
|
| `pagination` | `more`: a **Load more** button reads the next `perPage` records into the same list. |
|
|
589
603
|
| `empty` | Text instead of the children when no record matches. |
|
|
590
604
|
|
|
591
605
|
```tsx
|
|
592
|
-
<ReferenceManyField reference="task_claims" target="task_id" filter=
|
|
606
|
+
<ReferenceManyField reference="task_claims" target="task_id" filter="status = 'open'" sort={['claimed_at desc']} pagination="more">
|
|
593
607
|
<Table title="Open claims" columns={['worker_id', 'claimed_at']} />
|
|
594
608
|
</ReferenceManyField>
|
|
595
609
|
```
|
|
@@ -359,11 +359,13 @@ docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTO
|
|
|
359
359
|
## `types`
|
|
360
360
|
|
|
361
361
|
```sh
|
|
362
|
-
protobase types # writes .protobase/tsconfig.json; dev, build and every command that loads the config write
|
|
362
|
+
protobase types # writes .protobase/tsconfig.json and register.d.ts; dev, build and every command that loads the config write them too
|
|
363
363
|
```
|
|
364
364
|
|
|
365
365
|
Writes `.protobase/tsconfig.json`, which the project's `tsconfig.json` extends (`"extends": "./.protobase/tsconfig.json"`). In a bundled project its `paths` point each `@protobase` package and each package the serve runtime supplies, by name and by each of its exports (`@protobase/layout/jsx-runtime`, `kysely`, `zod`, ...), at the declarations of the CLI that builds the app, so the editor and `tsc` see the version that runs with nothing installed. There is no catch-all, so a package the project imports and lacks still fails as missing. React carries no types of its own, so the project keeps `@types/react`, as it keeps `@types/node`. A locked project's installed packages type themselves, so its file holds no `paths`. A `paths` of the project's own `tsconfig.json` replaces the generated one, as `extends` does with any option.
|
|
366
366
|
|
|
367
|
+
With a `config/index.ts`, it also writes `.protobase/register.d.ts`, which registers that module's type with `@protobase/layout`, so [typed layouts](layouts.md#typed-layouts) and `<Trans>` check the app's resource names, fields and text keys, and the generated `tsconfig.json` includes it beside the project's own files (`"include": ["../**/*", "register.d.ts"]`). A project `tsconfig.json` with an `include` of its own replaces that one, so it lists `.protobase/register.d.ts` there too.
|
|
368
|
+
|
|
367
369
|
`.protobase/` ignores itself in git: the paths are this machine's. Write the file again after installing another CLI; `dev` and `build` do it on every run.
|
|
368
370
|
|
|
369
371
|
## `run`
|
|
@@ -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.
|
|
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
|
|
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 `
|
|
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
|
|
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
|
| --- | --- |
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Languages
|
|
4
4
|
|
|
5
|
-
The admin app's built-in screens come in English and Dutch, chosen by the app or by each user's browser, with numbers and dates written to match.
|
|
5
|
+
The admin app's built-in screens come in English and Dutch, chosen by the app or by each user's browser, with numbers and dates written to match, and the app's own texts in any language it has translations for.
|
|
6
6
|
|
|
7
|
-
The admin app's own texts and its numbers and dates come in English and Dutch. The texts you write yourself, such as resource names, labels and enum value labels, show as you write them, in any language.
|
|
7
|
+
The admin app's own texts and its numbers and dates come in English and Dutch. The texts you write yourself, such as resource names, labels and enum value labels, show as you write them, in any language, unless the app's [translations](#your-own-texts) give them in the reader's.
|
|
8
8
|
|
|
9
9
|
## Choosing the language
|
|
10
10
|
|
|
@@ -22,12 +22,48 @@ The value is `'en'` or `'nl'`, and the server refuses to start with any other va
|
|
|
22
22
|
|
|
23
23
|
Numbers, amounts and dates use the conventions of the language: English as written in Britain (`6 Oct 2026`, `€1,234.56`), and Dutch as written in the Netherlands (`6 okt 2026`, `€ 1.234,56`). Typing a decimal number in a form uses the same decimal mark. Times show in the viewer's time zone in both languages.
|
|
24
24
|
|
|
25
|
+
## Your own texts
|
|
26
|
+
|
|
27
|
+
The app's own texts, its pages' and its labels, come in every language it has translations for: one JSON file per language, its messages ICU, as `intl-messageformat` reads them, exported from `config/index.ts` with `translations`:
|
|
28
|
+
|
|
29
|
+
```ts title="config/index.ts"
|
|
30
|
+
import { translations } from '@protobase/layout'
|
|
31
|
+
import en from './texts/en.json'
|
|
32
|
+
import nl from './texts/nl.json'
|
|
33
|
+
|
|
34
|
+
export const texts = translations({ en, nl })
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```json title="config/texts/nl.json"
|
|
38
|
+
{
|
|
39
|
+
"today": {
|
|
40
|
+
"title": "Vandaag",
|
|
41
|
+
"open": "{count, plural, one {# open taak} other {# open taken}}",
|
|
42
|
+
"owner": "Van <b>{name}</b>"
|
|
43
|
+
},
|
|
44
|
+
"resources": {
|
|
45
|
+
"tasks": {
|
|
46
|
+
"names": { "singular": "Taak", "plural": "Taken" },
|
|
47
|
+
"fields": { "status": { "label": "Staat", "values": { "done": "Klaar" } } }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A layout shows a message with [`<Trans i18nKey="today.open" values={{ count: 2 }} />`](layouts.md#texts-in-the-readers-language), and a page whose `title` is one is named by it in the sidebar too. A view's labels take their key from where they sit, under `resources.<resource>`: `names.singular` and `names.plural`, `help`, `fields.<field>.label`, `.help` and `.values.<value>`, `layout.<index>.title`, `.help` and `.empty` (a tab's items under `layout.<index>.items.<index>`), and `actions.<action>.label` and `.confirm`. A label the translations leave out shows as the view writes it.
|
|
54
|
+
|
|
55
|
+
Each reader gets the app's own `locale` when it sets one the translations have, else the first of their browser's languages the translations have, by its tag or its language (`nl-BE` reads `nl`), else English, else the first language. A language is any BCP 47 tag, such as `de` or `pt-BR`, while the built-in screens stay in English or Dutch. `/meta` serves the reader's language and only the messages their pages name, as `texts: { locale, messages }`, with the page titles and labels already in it.
|
|
56
|
+
|
|
57
|
+
The config fails to load when a message is not ICU or a language lacks a key another has, and the server refuses to start when a layout names a key no language has, leaves out a value its message formats in some language, or has a tag with no element in `components`, naming the page or view.
|
|
58
|
+
|
|
25
59
|
## What is translated
|
|
26
60
|
|
|
27
61
|
Every built-in screen is translated: the shell with its sidebar, top bar, search, notification bell, profile menu and bottom bar; the list page with all its displays (table, cards, board, calendar, timeline and map), filters, search, sort, imports and exports; the record page with its actions, related lists, history, comments, gallery, saving, conflicts and deleting; the create page and composed pages; saved searches and favorites; the sign-in, sign-up and two-factor screens, the account and sign-in policy pages, and the organization, people and invitation pages; public forms; the assistant's dock and a record's [lines](ui-config.md#record-lines); the notice naming a plugin that is off and why; and the messages, toasts and confirmations around them. The parts `@protobase/ui` gives your own components, such as the [form parts](custom-components.md#form-parts), the [chat parts](custom-components.md#chat-parts) and the markdown editor, come in the app's language too. So are counts, relative times ("5 minutes ago"), yes, no and the other values the app writes itself, and the notices shown while the app loads.
|
|
28
62
|
|
|
29
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.
|
|
30
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
|
+
|
|
31
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.
|
|
32
68
|
|
|
33
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.
|
|
@@ -119,14 +119,14 @@ 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. 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 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.
|
|
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).
|
|
126
126
|
|
|
127
127
|
## Data
|
|
128
128
|
|
|
129
|
-
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160
|
|
129
|
+
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160, exactly as the list API's `filter`, so a filter that works in the list's URL works here, or [the builder's arrow](#the-condition-builder), `filter={(f) => f.status.eq('open')}`, which writes that text. `sort` is a list of fields, each with `asc` or `desc` if it likes, `sort={['due_at', 'total desc']}`, the list API's `order_by` one entry at a time. `Thread` takes no `sort`: it orders its messages by its `time` field, newest first. `ReferenceManyField`, `ReferenceArrayField` and `ReferenceField` read records of their `reference` that the record around them points to or is pointed at by: see [related records](#related-records).
|
|
130
130
|
|
|
131
131
|
A `RecordCard` (its first match), a `ReferenceField`, each card of a `CardRow` and each entry of a `RecordsIterator` hold a **record**. Inside one, `Field`, `Diff`, `Progress`, `Stat field`, `Show`, `Action` and `ModalForm mode="edit"` work on that record, and a `RecordCard`'s header `actions` do too. A field name may follow relations: `company_id.city` is the city of the record's company, fetched like the record page fetches it and cached.
|
|
132
132
|
|
|
@@ -143,7 +143,7 @@ A record's related records repeat under it as a list: a `ReferenceManyField` hol
|
|
|
143
143
|
<ArrayField source="labels">
|
|
144
144
|
<RecordsIterator><Field source="this" label={false} /></RecordsIterator>
|
|
145
145
|
</ArrayField>
|
|
146
|
-
<ReferenceManyField reference="task_claims" target="task_id" sort={
|
|
146
|
+
<ReferenceManyField reference="task_claims" target="task_id" sort={['claimed_at desc']}>
|
|
147
147
|
<RecordsIterator>
|
|
148
148
|
<Card title="Claim {{@index}}">
|
|
149
149
|
<ReferenceField source="worker_id" reference="workers" />
|
|
@@ -156,7 +156,70 @@ A record's related records repeat under it as a list: a `ReferenceManyField` hol
|
|
|
156
156
|
</RecordCard>
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record, its `source`; a `ReferenceManyField`'s is `id` of the nearest record by default. A `ReferenceManyField`'s and a `ReferenceArrayField`'s `filter` and `sort`
|
|
159
|
+
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record, its `source`; a `ReferenceManyField`'s is `id` of the nearest record by default. A `ReferenceManyField`'s and a `ReferenceArrayField`'s `filter` and `sort` are a data block's: AIP-160 text or the builder's arrow, and a list of fields. react-admin's objects are not taken: write `filter={{ status: 'open' }}` as `filter="status = 'open'"` and `sort={{ field: 'claimed_at', order: 'DESC' }}` as `sort={['claimed_at desc']}`. Without `sort`, such a list is in its key's order, descending, as react-admin's is. A `ReferenceManyField`'s `pagination="more"` adds a button that reads the next `perPage` records into the same list. The [blocks reference](blocks.md#related-records) lists every prop.
|
|
160
|
+
|
|
161
|
+
## Typed layouts
|
|
162
|
+
|
|
163
|
+
A layout written as a function of what it reads is typed by the app's resources: `layout()` draws a composed page's tree, and `recordLayout(resource, ...)` a record page's. Each runs its function once, as the config loads, and gives the same tree the JSX would, so the server checks, plans and serves it as any other.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
/** @jsxImportSource @protobase/layout */
|
|
167
|
+
import { Card, Page, Show, Table, Text, layout, now, page, recordLayout, RecordsIterator, ReferenceManyField } from '@protobase/layout'
|
|
168
|
+
import { l, view } from '@protobase/schema'
|
|
169
|
+
|
|
170
|
+
export const today = page('today', layout(({ resources }) => (
|
|
171
|
+
<Page title="Today">
|
|
172
|
+
<Show when={resources.invoices.count.gt(0)}>
|
|
173
|
+
<Table resource="invoices" filter={(f) => f.status.eq('open').and(f.due_at.lt(now().plus('7d')))} sort={['due_at asc']} columns={['number', 'due_at', 'total']} />
|
|
174
|
+
</Show>
|
|
175
|
+
</Page>
|
|
176
|
+
)))
|
|
177
|
+
|
|
178
|
+
export const tasksView = view<typeof tasks>('tasks').layout(() => [
|
|
179
|
+
l.blocks(recordLayout('tasks', ({ data }) => (
|
|
180
|
+
<ReferenceManyField reference="task_runs" target="task_id">
|
|
181
|
+
<RecordsIterator<'task_runs'>>{(run) => <Card title={`${run.outcome} of ${data.title}`} />}</RecordsIterator>
|
|
182
|
+
</ReferenceManyField>
|
|
183
|
+
))),
|
|
184
|
+
])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| | |
|
|
188
|
+
| --- | --- |
|
|
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
|
+
| `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}}`. |
|
|
192
|
+
|
|
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
|
+
|
|
195
|
+
### The condition builder
|
|
196
|
+
|
|
197
|
+
A filter's arrow and a typed layout's `when` write AIP-160 with one builder. A field compares with `eq`, `ne`, `lt`, `le`, `gt`, `ge`, `in([...])`, `contains(value)` and `isNull()`, and conditions join with `.and(...)`, `.or(...)` and `not(...)`, bracketed where AND and OR mix:
|
|
198
|
+
|
|
199
|
+
| Builder | AIP-160 |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `f.status.eq('open')` | `status = "open"` |
|
|
202
|
+
| `f.total.gt(100).and(f.paid.eq(false))` | `total > 100 AND paid = false` |
|
|
203
|
+
| `f.a.eq(1).and(f.b.eq(2).or(f.c.eq(3)))` | `a = 1 AND (b = 2 OR c = 3)` |
|
|
204
|
+
| `not(f.status.in(['done', 'held']))` | `NOT in(status, "done", "held")` |
|
|
205
|
+
| `f.owner.eq(null)`, `f.owner.isNull()` | `isNull(owner)` |
|
|
206
|
+
| `f.plan.name.ne('Pro')` | `plan.name != "Pro"` |
|
|
207
|
+
| `f.due_at.lt(now().plus('7d'))` | `due_at < now() + 7d` |
|
|
208
|
+
| `f.task_id.eq(data.id)` | `task_id = {{id}}` |
|
|
209
|
+
|
|
210
|
+
`now().plus(...)` and `now().minus(...)` take a duration, a number and one of `s`, `m`, `h`, `d` or `w`. A filter's arrow gives one condition, or the layout fails as it loads; AIP-160 text stays for what the builder does not write, such as `related()`.
|
|
211
|
+
|
|
212
|
+
## Texts in the reader's language
|
|
213
|
+
|
|
214
|
+
A `<Trans i18nKey="..." />` shows one of the app's own texts in the reader's language, as react-i18next's `<Trans>` does, wherever text goes: as a child, or as a `title`, `description`, `label` or `empty`. Its message is ICU, `values` gives what it formats, from a record with `{{path}}` or `data.title`, and `components` the element each of its tags draws:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
<Card title={<Trans i18nKey="today.open" values={{ count: 2 }} />}>
|
|
218
|
+
<Trans i18nKey="today.owner" values={{ name: '{{owner}}' }} components={{ b: <Text as="strong" /> }} />
|
|
219
|
+
</Card>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The texts are the app's `translations({ en, nl })`; see [Your own texts](languages.md#your-own-texts).
|
|
160
223
|
|
|
161
224
|
## How a page reads its data
|
|
162
225
|
|
|
@@ -271,7 +334,7 @@ export const tasksView = view<typeof tasks>('tasks').layout((r) => [
|
|
|
271
334
|
])
|
|
272
335
|
```
|
|
273
336
|
|
|
274
|
-
The view's file is then `.tsx` and starts with the JSX import source, as a [layout file](#setup) does, or it imports the tree from a layout file of its own.
|
|
337
|
+
The view's file is then `.tsx` and starts with the JSX import source, as a [layout file](#setup) does, or it imports the tree from a layout file of its own. [`recordLayout('tasks', ({ data }) => ...)`](#typed-layouts) writes the same tree typed by the record, `data.title` for `{{title}}`.
|
|
275
338
|
|
|
276
339
|
| | |
|
|
277
340
|
| --- | --- |
|
|
@@ -319,7 +382,9 @@ A [`Timeline`](blocks.md#timeline) takes `select` too: a bar links to the page w
|
|
|
319
382
|
| `status`, `plan.name` | A field of the records around it, through relations, by the [lookup of paths](#paths-and-scopes). |
|
|
320
383
|
| `invoices.count` | How many `invoices` the user can see (an exact count from the list API). |
|
|
321
384
|
|
|
322
|
-
Comparisons, `AND`, `OR`, `NOT`, parentheses, `isNull(field)
|
|
385
|
+
Comparisons, `AND`, `OR`, `NOT`, parentheses, `isNull(field)`, `in(field, "a", "b")`, `now()` and `now() + 7d` or `now() - 1h` work; a time compares with a timestamp field as the list API compares it. Any other function, such as `regex()` or `related()`, works only in a list's `filter`, which the API reads, and a condition that calls one fails as the config loads. A field that is missing or that the user cannot read makes the comparison false, and a `Show` that names a resource or field the user cannot see is left out of their page.
|
|
386
|
+
|
|
387
|
+
In a [typed layout](#typed-layouts), `when` takes [the builder's](#the-condition-builder) condition too: `when={data.status.eq('done')}` or `when={resources.invoices.count.gt(0)}`.
|
|
323
388
|
|
|
324
389
|
Record pages take the same conditions in the `when` of `l.section`, `l.related` and `l.sidebar`; see [Form and read view](ui-config.md#form-and-read-view).
|
|
325
390
|
|
|
@@ -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
|
|