@diagonal-hq/cli 0.38.4 → 0.39.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.
package/README.md
CHANGED
|
@@ -666,7 +666,7 @@ export default defineNotificationTemplate({
|
|
|
666
666
|
|
|
667
667
|
The deploy stores each reference as the template editor stores it, so a send renders the same link. The page id of a page file is its uid, and the workflow id comes from the active deployment.
|
|
668
668
|
|
|
669
|
-
An email layout is the frame that templates fill in. Each field is a slot that a template fills with Liquid.
|
|
669
|
+
An email layout is the frame that templates fill in. Each field is a slot that a template fills with Liquid. A field with a `type` (`'text'`, `'url'`, `'email'`, or `'phone'`) holds a value of that type. A template fills it with Liquid text, or binds it to a value of the send with `{ variable: '<path>' }`.
|
|
670
670
|
|
|
671
671
|
```ts
|
|
672
672
|
import { defineEmailLayout } from '@diagonal-hq/cli';
|
|
@@ -677,11 +677,26 @@ export default defineEmailLayout({
|
|
|
677
677
|
body: { file: './body.liquid' },
|
|
678
678
|
fields: {
|
|
679
679
|
heading: { label: 'Heading', required: true },
|
|
680
|
-
body: { label: 'Body', required: true }
|
|
680
|
+
body: { label: 'Body', required: true },
|
|
681
|
+
action_url: { label: 'Action URL', type: 'url' }
|
|
681
682
|
}
|
|
682
683
|
});
|
|
683
684
|
```
|
|
684
685
|
|
|
686
|
+
A template binds a typed field to a variable. The send reads the value at the path and checks it against the type of the field. It does not render the value as Liquid.
|
|
687
|
+
|
|
688
|
+
```ts
|
|
689
|
+
email: {
|
|
690
|
+
subject: 'Your invoice',
|
|
691
|
+
layout: EmailLayouts.Standard.uid,
|
|
692
|
+
fields: {
|
|
693
|
+
heading: 'Thank you for your payment',
|
|
694
|
+
body: { file: './receipt.email.liquid' },
|
|
695
|
+
action_url: { variable: 'invoice_url' }
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
```
|
|
699
|
+
|
|
685
700
|
### NotificationTypes and EmailLayouts
|
|
686
701
|
|
|
687
702
|
The build writes `generated/notification-types.ts`, which exports `NotificationTypes`, and `generated/email-layouts.ts`, which exports `EmailLayouts`. `diagonal check` writes them too. Import them from `@app/generated/notification-types` and `@app/generated/email-layouts`.
|
|
@@ -690,7 +705,7 @@ Each name comes from a path, not from the file, as `Workflows` and `Skills` do:
|
|
|
690
705
|
|
|
691
706
|
- `notifications/member-welcome/type.ts` is `NotificationTypes.MemberWelcome`, the studly case of the folder name. An entry holds `uid`, `slug`, `name`, `variables` (by key, with the same metadata as a resource field), and `templates`.
|
|
692
707
|
- `notifications/member-welcome/standard.template.ts` is `NotificationTypes.MemberWelcome.templates.Standard`, the studly case of the file name. An entry holds `uid`, `slug`, `name`, and `channels: { email, sms }`.
|
|
693
|
-
- `email-layouts/standard/layout.ts` is `EmailLayouts.Standard`, the studly case of the folder name. An entry holds `uid`, `slug`, `name`, and `fields` (by key, each with `key`, `label`, `description`, and `required`).
|
|
708
|
+
- `email-layouts/standard/layout.ts` is `EmailLayouts.Standard`, the studly case of the folder name. An entry holds `uid`, `slug`, `name`, and `fields` (by key, each with `key`, `label`, `description`, and `required`, and `type` for a typed field).
|
|
694
709
|
|
|
695
710
|
The modules hold no subject, Liquid, or layout body, because a page that reads an entry ships it to every viewer. A folder or file name whose studly case is not an identifier, such as `2nd-reminder`, and two names with the same studly case, are errors. The built-in layout `'default'` has no entry: write `'default'`, or leave `layout` out.
|
|
696
711
|
|
|
@@ -789,10 +804,10 @@ The editor checks the shape of each definition. `diagonal check` and the build a
|
|
|
789
804
|
- Each path in a type's `recipient.relations` follows relation fields from the recipient resource, for example `'account'` or `'account.owner'`. Each path in a record variable's `relations` follows relation fields from the variable's resource in the same way. A path has at most 5 relations and passes through a resource only once; only its last relation can return to a resource that the path already reached. Each list has at most 100 paths, and no path twice.
|
|
790
805
|
- A type's `recipient` resource declares the Notifiable capability. When a template of the type has an email, the resource maps `email_field`. When a template has an SMS, the resource maps `phone_field`. The resource check makes sure that `email_field` names an `email` field and `phone_field` names a `phone` or `text` field.
|
|
791
806
|
- A type has at least one template, and its `defaultTemplate` names one of them.
|
|
792
|
-
- A template's folder has a `type.ts`. A template has no `type`. A template has an email, an SMS, or both. An email `subject` has 1 to 10,000 characters. `email.layout` names a layout of the workspace files, or `'default'`. An email's `fields` match the fields of its layout and fill each required field. A layout field key differs from `record` and from each variable key of the template's type. The built-in layout has the field `content`. An SMS `body` is not empty.
|
|
807
|
+
- A template's folder has a `type.ts`. A template has no `type`. A template has an email, an SMS, or both. An email `subject` has 1 to 10,000 characters. `email.layout` names a layout of the workspace files, or `'default'`. An email's `fields` match the fields of its layout and fill each required field. Only a field with a `type` takes `{ variable }`, and the first segment of its path is a variable of the type, `record` when the type has a `recipient`, or `workspace`. A `text` or `url` field can also read `ref.<key>` of a `page.url` reference of the template. A layout field key differs from `record` and from each variable key of the template's type. The built-in layout has the field `content`. An SMS `body` is not empty.
|
|
793
808
|
- A template has at most 50 references. A reference key starts with a lowercase letter, has only a-z, 0-9, and `_`, and has at most 64 characters. A label has at most 255 characters.
|
|
794
809
|
- A `page.url` or `workflow.url` reference names a page or a workflow of the workspace. An unknown `Pages` or `Workflows` name is an error at its line and column. `params` has a value for each required route parameter of the page or workflow and no other name. A `workflow.url` workflow has a `request` trigger. A `calendar.generate_link` resource has the `eventable` capability. The first segment of a `{ variable }` path is a variable of the type, or `record` when the type has a `recipient`.
|
|
795
|
-
- A layout's slug and its folder name are not `default`, and its `body` is not empty. A layout field key starts with a letter or `_` and has only letters, digits, and `_`. Each field has a `label` of at most 255 characters.
|
|
810
|
+
- A layout's slug and its folder name are not `default`, and its `body` is not empty. A layout field key starts with a letter or `_` and has only letters, digits, and `_`. Each field has a `label` of at most 255 characters. A field `type` is `'text'`, `'url'`, `'email'`, or `'phone'`. Leave it out for a Liquid field.
|
|
796
811
|
- A schedule has a `name` of 1 to 255 characters. Its `type` names a type of the workspace files that has a `recipient`, and its `template` names a template of that type that has an email. `source.resource` is a resource of the workspace. A schedule's `filters` is a filter tree with a known operator in each condition.
|
|
797
812
|
- A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs a datetime or event schedule field. `offsets` holds 1 to 30 distinct durations.
|
|
798
813
|
- A schedule's `recipient` path reaches the type's recipient resource through relations that each hold one record. Without `recipient`, the source resource is the recipient resource.
|