@diagonal-hq/cli 0.41.4 → 0.41.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -667,10 +667,14 @@ export default defineNotificationTemplate({
|
|
|
667
667
|
|
|
668
668
|
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.
|
|
669
669
|
|
|
670
|
-
An email layout is the frame that templates fill in. Each field is a slot that a template fills
|
|
670
|
+
An email layout is the frame that templates fill in. Each field is a slot that a template fills.
|
|
671
|
+
|
|
672
|
+
- An object, `{ label, description?, required? }`, declares a Liquid field. A template fills it with Liquid.
|
|
673
|
+
- A `field.<type>({...})` call declares a field with a type and the settings of the type, as a variable of a notification type does. It takes `label`, `description`, `required`, and the settings of the type. It cannot be a `field.relation` or a `field.liquid`, and it has none of the options of a stored field: `default`, `guard`, `unique`, `index`, `computed`, `getter`, `setter`, and `setterWhenEmpty`.
|
|
674
|
+
- An object with a `type` of `'text'`, `'url'`, `'email'`, or `'phone'` declares the same field as the call of that type without settings.
|
|
671
675
|
|
|
672
676
|
```ts
|
|
673
|
-
import { defineEmailLayout } from '@diagonal-hq/cli';
|
|
677
|
+
import { defineEmailLayout, field } from '@diagonal-hq/cli';
|
|
674
678
|
|
|
675
679
|
export default defineEmailLayout({
|
|
676
680
|
uid: '019a4d6e-5b2c-7d3e-9f4a-7b8c9d0e1f2a',
|
|
@@ -679,12 +683,26 @@ export default defineEmailLayout({
|
|
|
679
683
|
fields: {
|
|
680
684
|
heading: { label: 'Heading', required: true },
|
|
681
685
|
body: { label: 'Body', required: true },
|
|
682
|
-
action_url: { label: 'Action URL'
|
|
686
|
+
action_url: field.url({ label: 'Action URL' }),
|
|
687
|
+
show_banner: field.boolean({ label: 'Show banner' }),
|
|
688
|
+
button_style: field.select({
|
|
689
|
+
label: 'Button style',
|
|
690
|
+
options: [
|
|
691
|
+
{ label: 'Primary', value: 'primary' },
|
|
692
|
+
{ label: 'Outline', value: 'outline' }
|
|
693
|
+
]
|
|
694
|
+
})
|
|
683
695
|
}
|
|
684
696
|
});
|
|
685
697
|
```
|
|
686
698
|
|
|
687
|
-
|
|
699
|
+
The layout body reads each field by its key. A typed value keeps its type, so the body can test it, such as `{% if show_banner %}`.
|
|
700
|
+
|
|
701
|
+
A template gives each field a value in one of three forms:
|
|
702
|
+
|
|
703
|
+
- **Liquid text**, for a Liquid field and for a `text`, `url`, `email`, or `phone` field. The send renders the text. It checks the result of a typed field against the type.
|
|
704
|
+
- **`{ value: <value> }`**, for a field of any other type. Such a field renders no Liquid, so the value is a literal: a string, a number, `true`, `false`, `null`, a list, or an object. The hosted build checks the value against the type, the required rule, and the settings of the field, and fails the build at the template file when the value is not valid. For example, a value that is not an option of a select field fails the build. `diagonal check` checks only the form.
|
|
705
|
+
- **`{ variable: '<path>' }`**, for any field with a type. 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.
|
|
688
706
|
|
|
689
707
|
```ts
|
|
690
708
|
email: {
|
|
@@ -693,7 +711,9 @@ email: {
|
|
|
693
711
|
fields: {
|
|
694
712
|
heading: 'Thank you for your payment',
|
|
695
713
|
body: { file: './receipt.email.liquid' },
|
|
696
|
-
action_url: { variable: 'invoice_url' }
|
|
714
|
+
action_url: { variable: 'invoice_url' },
|
|
715
|
+
show_banner: { value: true },
|
|
716
|
+
button_style: { value: 'outline' }
|
|
697
717
|
}
|
|
698
718
|
}
|
|
699
719
|
```
|
|
@@ -805,7 +825,7 @@ The editor checks the shape of each definition. `diagonal check` and the build a
|
|
|
805
825
|
- 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.
|
|
806
826
|
- 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.
|
|
807
827
|
- A type has at least one template, and its `defaultTemplate` names one of them.
|
|
808
|
-
- 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
|
|
828
|
+
- 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 `{ value: null }` does not fill a required field. A Liquid, `text`, `url`, `email`, or `phone` field takes Liquid text, and a field of another type takes `{ value }`. 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.
|
|
809
829
|
- 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.
|
|
810
830
|
- 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`.
|
|
811
831
|
- 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.
|