@diagonal-hq/cli 0.6.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.
@@ -93,7 +93,7 @@ The file gives the resource its `Resources` entry, so source names it like any o
93
93
 
94
94
  ## Notifications
95
95
 
96
- 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' }`.
97
97
 
98
98
  ```text
99
99
  notifications/
@@ -102,6 +102,7 @@ notifications/
102
102
  standard.template.ts
103
103
  standard.email.liquid
104
104
  standard.sms.liquid
105
+ week-one.schedule.ts
105
106
  fixtures/
106
107
  default.json
107
108
  email-layouts/
@@ -171,6 +172,37 @@ export default defineEmailLayout({
171
172
  });
172
173
  ```
173
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
+
174
206
  ### Rules
175
207
 
176
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:
@@ -181,6 +213,10 @@ The editor checks the shape of each definition. These rules need other files or
181
213
  - A layout cannot use the key `default`.
182
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.
183
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.
184
220
 
185
221
  ### Fixtures
186
222
 
@@ -188,6 +224,7 @@ Fixtures are sample data for previews. They are not tests, and they are never se
188
224
 
189
225
  - A layout fixture holds a value for each layout field, for example `{ "heading": "Welcome aboard", "body": "<p>Hi Avery.</p>" }`.
190
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.
191
228
 
192
229
  ## Resources and fields
193
230
 
package/dist/cli.mjs CHANGED
@@ -298444,6 +298444,7 @@ __export(cli_exports, {
298444
298444
  defineConfig: () => defineConfig,
298445
298445
  defineEmailLayout: () => defineEmailLayout,
298446
298446
  defineNavigation: () => defineNavigation,
298447
+ defineNotificationSchedule: () => defineNotificationSchedule,
298447
298448
  defineNotificationTemplate: () => defineNotificationTemplate,
298448
298449
  defineNotificationType: () => defineNotificationType,
298449
298450
  definePage: () => definePage,
@@ -298500,6 +298501,7 @@ var defineNavigation = (navigation) => navigation;
298500
298501
  var defineNotificationType = (type) => type;
298501
298502
  var defineNotificationTemplate = (template) => template;
298502
298503
  var defineEmailLayout = (layout) => layout;
298504
+ var defineNotificationSchedule = (schedule) => schedule;
298503
298505
 
298504
298506
  // scripts/lib/runtime-build/app-modules.mjs
298505
298507
  var APP_IMPORT = "__appImport";
package/dist/index.d.ts CHANGED
@@ -394,3 +394,60 @@ export type EmailLayoutDefinition = {
394
394
  };
395
395
 
396
396
  export declare function defineEmailLayout<const T extends EmailLayoutDefinition>(layout: T): T;
397
+
398
+ /**
399
+ * When a schedule sends. `'day'` sends at 8 a.m. in the workspace timezone on
400
+ * the day. `'exact'` sends at the event start plus the offset, and needs an
401
+ * event schedule field.
402
+ */
403
+ export type NotificationScheduleTiming = 'day' | 'exact';
404
+
405
+ /**
406
+ * A `notifications/<type key>/<key>.schedule.ts` file. A schedule sends one
407
+ * template of its type on dates of a resource, for example 7 days after each
408
+ * member's `joined_on`. The deployed schedule is a System Notification: it
409
+ * sends with no staff identity, and `filters` decides who gets it. The file
410
+ * holds the rule. The workspace keeps the generated notifications, their edits
411
+ * and holds, and the pause state.
412
+ */
413
+ export type NotificationScheduleDefinition = {
414
+ /**
415
+ * Lowercase letters, digits, and hyphens, for example `'week-one'`. Unique
416
+ * within the type. Moving the file keeps it.
417
+ */
418
+ key: string;
419
+ name: string;
420
+ /** The type whose folder holds the file. */
421
+ type: NotificationTypeReference;
422
+ /** A template of that type. The template must have an email. */
423
+ template: NotificationTemplateReference;
424
+ /** The resource whose records get the notification, as `Resources.<Name>`. */
425
+ source: { resource: ResourceReference };
426
+ /** The key of a date, datetime, or event schedule field of the source resource. */
427
+ dateField: string;
428
+ /** Defaults to `'day'`. */
429
+ timing?: NotificationScheduleTiming;
430
+ /**
431
+ * One to 30 distinct signed ISO 8601 durations from the date, for example
432
+ * `'-P30D'` (30 days before), `'P0D'` (the day), or `'-PT2H'` (2 hours before).
433
+ */
434
+ offsets: readonly string[];
435
+ /** Only the source records that match. The same filter object as a `recordEvent` trigger. */
436
+ filters?: StaticValue;
437
+ /**
438
+ * The path of single-record relations from the source record to the type's
439
+ * recipient, for example `'member'` on a `memberships` source. Leave it out
440
+ * when the source resource is the recipient resource.
441
+ */
442
+ recipient?: string;
443
+ /**
444
+ * A field path on the source record for each variable of the type, for
445
+ * example `'joined_on'` or `'member.name'`. A record variable maps to the id
446
+ * of a record of its resource, for example `'first_event.id'`.
447
+ */
448
+ variables?: { readonly [key: string]: string };
449
+ };
450
+
451
+ export declare function defineNotificationSchedule<const T extends NotificationScheduleDefinition>(
452
+ schedule: T
453
+ ): T;
package/dist/index.js CHANGED
@@ -29,4 +29,6 @@ export const defineNotificationTemplate = (template) => template;
29
29
 
30
30
  export const defineEmailLayout = (layout) => layout;
31
31
 
32
+ export const defineNotificationSchedule = (schedule) => schedule;
33
+
32
34
  export { field } from './fields.generated.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {