@diagonal-hq/cli 0.5.0 → 0.6.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This package is the authoring SDK for file-based workspaces. A workspace repository installs it as a dev dependency. It gives these things:
4
4
 
5
- - The configuration helpers: `defineConfig`, `defineResource`, `definePage`, `defineNavigation`, `defineAssets`, `asset.version`, `defineNotificationType`, `defineNotificationTemplate`, `defineEmailLayout`, and the `field` builders. Each `define*` function returns its first argument. Each `field.<type>(options)` call returns `{ $field, ...options }`, where `$field` is the stored field type. The package root exports them as ESM JavaScript with declarations, so a Vite build or a Node script can import a configuration file.
5
+ - The configuration helpers: `defineConfig`, `defineResource`, `definePage`, `defineNavigation`, `defineAssets`, `asset.version`, `defineNotificationType`, `defineNotificationTemplate`, `defineEmailLayout`, `defineNotificationSchedule`, and the `field` builders. Each `define*` function returns its first argument. Each `field.<type>(options)` call returns `{ $field, ...options }`, where `$field` is the stored field type. The package root exports them as ESM JavaScript with declarations, so a Vite build or a Node script can import a configuration file.
6
6
  - Types for the helpers, `WorkflowConfig`, and the `Sdk` and `React` globals.
7
7
  - Editor types for the workflow script SDK: `@diagonal/workflow`, `@diagonal/workflow/testing`, and `@diagonal/workflow/workspace`.
8
8
  - The `diagonal check` command. It runs the same build and checks that a platform deploy runs, including the workflow tests.
@@ -51,6 +51,8 @@ The build reads each file with a parser. It runs only the workflow tests.
51
51
  - Each `resources/*.ts` file goes through the resource checks in [Resources and fields](#resources-and-fields).
52
52
  - The build removes imports from `@diagonal-hq/cli`. Pages, layouts, components, and workflow scripts can import workspace files through `@app/`. A resource file can import only `@app/generated/resources`. Workflow scripts can also import `@diagonal/workflow` and `@diagonal/workflow/workspace`. Other external imports in these source files are rejected.
53
53
  - The second argument of `definePage`, and the default export of a layout or component file, must be one function.
54
+ - Each `definePage` needs a `key` that is unique in the workspace: a camelCase name of at most 64 letters and digits, such as `members`. The page's id comes from the key, so a file move keeps it. A missing key fails with a suggested key.
55
+ - Pages, layouts, and components link to a page with `Pages.<key>`: `Pages.members.url()`, `Pages.member.url({ id })`, and `Pages.members.navigate()`. `Pages` needs no import, and `import { Pages } from '@diagonal/pages'` also works. The check fails at an unknown key and at a call without the route parameters of the page.
54
56
  - Pages, layouts, and components go through the page lint gate: syntax, scope, the component return shape, and a type check against the page Sdk contract and the workspace resources. A page names a resource by slug, for example `Sdk.resource(Resources.Members)`.
55
57
  - Each `workflows/<name>.ts` is a script workflow. It has one `export const config = { title, trigger, runAs? } satisfies WorkflowConfig` and one `export default defineWorkflow(...)`. The config must be a static literal. The build validates it: the trigger fields, the resources (see [Resource references](#resource-references)), the workflow paths of `workflowEvent` triggers, and the run-as rules. A `recordEvent`, `recordSchedule`, `scheduled`, or `workflowEvent` workflow needs `runAs`.
56
58
  - The build removes the config and the `@diagonal-hq/cli` imports from the workflow, with spaces in their place, and compiles the rest with the workflow script compiler against the workspace resources. A compiler error has the line and column of the workflow file.
@@ -91,7 +93,7 @@ The file gives the resource its `Resources` entry, so source names it like any o
91
93
 
92
94
  ## Notifications
93
95
 
94
- A notification has a type, one or more templates, and optionally an email layout. Each definition is a static literal. Its Liquid is inline text or a `.liquid` file next to it, written as `{ file: './standard.email.liquid' }`.
96
+ A notification has a type, one or more templates, and optionally an email layout. A schedule sends a template on dates of a resource, for example 7 days after each member's `joined_on`. Each definition is a static literal. Its Liquid is inline text or a `.liquid` file next to it, written as `{ file: './standard.email.liquid' }`.
95
97
 
96
98
  ```text
97
99
  notifications/
@@ -100,6 +102,7 @@ notifications/
100
102
  standard.template.ts
101
103
  standard.email.liquid
102
104
  standard.sms.liquid
105
+ week-one.schedule.ts
103
106
  fixtures/
104
107
  default.json
105
108
  email-layouts/
@@ -169,6 +172,37 @@ export default defineEmailLayout({
169
172
  });
170
173
  ```
171
174
 
175
+ ### Schedules
176
+
177
+ A schedule sends one template of its type on dates of a resource. It is a `<key>.schedule.ts` file in the type's folder. The file holds the rule. The workspace keeps the generated notifications, their edits and holds, and the pause state.
178
+
179
+ ```ts
180
+ import { Resources } from '@app/generated/resources';
181
+ import { defineNotificationSchedule } from '@diagonal-hq/cli';
182
+
183
+ export default defineNotificationSchedule({
184
+ key: 'week-one',
185
+ name: 'Week one check-in',
186
+ type: 'member-welcome',
187
+ template: 'standard',
188
+ source: { resource: Resources.Members },
189
+ dateField: 'joined_on',
190
+ offsets: ['P7D'],
191
+ filters: { operator: 'and', conditions: [{ field: 'status', operator: '=', value: 'active' }] },
192
+ variables: { joined_on: 'joined_on', first_event: 'first_event.id' }
193
+ });
194
+ ```
195
+
196
+ This sends the Standard welcome 7 days after each active member's `joined_on`.
197
+
198
+ - `offsets` holds one to 30 distinct signed ISO 8601 durations: `'-P30D'` is 30 days before, `'P0D'` is the day, `'-PT2H'` is 2 hours before.
199
+ - `timing` defaults to `'day'`, which sends at 8 a.m. in the workspace timezone. `'exact'` sends at the event start plus the offset and needs an event schedule field.
200
+ - `filters` is optional. It is the same filter object a workflow `recordEvent` trigger takes.
201
+ - `recipient` is the path of single-record relations from the source record to the type's recipient, for example `'member'` on a `memberships` source. Leave it out when the source resource is the recipient, as here.
202
+ - `variables` maps each variable of the type to a field path on the source record. A record variable maps to a record's `id`.
203
+
204
+ A deployed schedule is a System Notification. It sends with no staff identity, and `filters` decides who gets it. A file cannot name a person to send as. Staff actions on one generated notification, such as **Send now** or an edit, still act as the person who clicks.
205
+
172
206
  ### Rules
173
207
 
174
208
  The editor checks the shape of each definition. These rules need other files or server data, so the editor does not check them yet:
@@ -179,6 +213,10 @@ The editor checks the shape of each definition. These rules need other files or
179
213
  - A layout cannot use the key `default`.
180
214
  - Each reference key starts with a lowercase letter. A template has at most 50 references, and each one names a generator that the server has.
181
215
  - The `recipient` resource can receive notifications.
216
+ - A schedule's `type` is the type of its folder, and its `template` names a template of that type that has an email.
217
+ - A schedule's `dateField` is a date, datetime, or event schedule field of the source resource. Exact timing needs an event schedule field.
218
+ - A schedule's type has a `recipient`, and the schedule's `recipient` path reaches that resource through single-record relations.
219
+ - Each key of a schedule's `variables` is a variable of the type, each path reaches a field of the source record or a related record, a record variable maps to the id of a record of its resource, and every required variable is mapped.
182
220
 
183
221
  ### Fixtures
184
222
 
@@ -186,6 +224,7 @@ Fixtures are sample data for previews. They are not tests, and they are never se
186
224
 
187
225
  - A layout fixture holds a value for each layout field, for example `{ "heading": "Welcome aboard", "body": "<p>Hi Avery.</p>" }`.
188
226
  - A notification fixture holds a template key, a sample recipient, and sample variables, for example `{ "template": "standard", "recipient": { "name": "Avery Shaw", "email": "avery@example.com", "phone": null }, "variables": { "joined_on": "2026-11-02", "first_event": { "name": "Open house" } } }`. A record variable holds the record's fields.
227
+ - A schedule has no fixtures. The type's fixture already holds the sample recipient and variables.
189
228
 
190
229
  ## Resources and fields
191
230