@diagonal-hq/cli 0.33.5 → 0.33.7

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
@@ -598,7 +598,57 @@ export default defineNotificationTemplate({
598
598
  });
599
599
  ```
600
600
 
601
- A file can use three generators: `date.current` and `time.current`, which take no settings, and `workspace.login_url`, which takes the resource whose members sign in. The template editor also offers `page.url`, `workflow.url`, and `calendar.generate_link`. They need a page, a workflow, or a variable binding that a file cannot hold yet, so the check refuses them.
601
+ A file can use six generators, the same as the template editor:
602
+
603
+ - `date.current` and `time.current` take no settings.
604
+ - `workspace.login_url` takes the resource whose members sign in.
605
+ - `page.url` takes `page: Pages.<Name>.uid` from `@app/generated/pages` and `params`, a value for each route parameter.
606
+ - `workflow.url` takes `workflow: Workflows.<Name>.uid` from `@app/generated/workflows` and `params`. The workflow must have a `request` trigger.
607
+ - `calendar.generate_link` takes `type` (`'google'`, `'apple'`, or `'outlook'`), `resource`, an eventable resource as `Resources.<Name>.slug`, and `record`, the event record.
608
+
609
+ A route parameter and `record` are a string, or `{ variable: '<path>' }`, which reads a value of the send when the notification renders. The path starts with a variable of the type, or with `record`, the recipient, such as `{ variable: 'record.id' }` or `{ variable: 'first_event.id' }`.
610
+
611
+ ```ts
612
+ import { Pages } from '@app/generated/pages';
613
+ import { Resources } from '@app/generated/resources';
614
+ import { Workflows } from '@app/generated/workflows';
615
+ import { defineNotificationTemplate } from '@diagonal-hq/cli';
616
+
617
+ export default defineNotificationTemplate({
618
+ uid: '019a4d6e-6c3d-7e4f-8a5b-8c9d0e1f2a3b',
619
+ name: 'Event invite',
620
+ email: {
621
+ subject: 'You are invited to {{ first_event.title }}',
622
+ fields: {
623
+ content:
624
+ '<p><a href="{{ ref.profile }}">Your profile</a> · <a href="{{ ref.rsvp }}">RSVP</a> · <a href="{{ ref.calendar }}">Add to Google Calendar</a></p>'
625
+ }
626
+ },
627
+ references: {
628
+ profile: {
629
+ label: 'Profile',
630
+ generator: 'page.url',
631
+ settings: { page: Pages.Members_$Id.uid, params: { id: { variable: 'record.id' } } }
632
+ },
633
+ rsvp: {
634
+ label: 'RSVP',
635
+ generator: 'workflow.url',
636
+ settings: { workflow: Workflows.Rsvp.uid, params: { event: { variable: 'first_event.id' } } }
637
+ },
638
+ calendar: {
639
+ label: 'Add to Google Calendar',
640
+ generator: 'calendar.generate_link',
641
+ settings: {
642
+ type: 'google',
643
+ resource: Resources.Events.slug,
644
+ record: { variable: 'first_event.id' }
645
+ }
646
+ }
647
+ }
648
+ });
649
+ ```
650
+
651
+ 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.
602
652
 
603
653
  An email layout is the frame that templates fill in. Each field is a slot that a template fills with Liquid.
604
654
 
@@ -724,7 +774,8 @@ The editor checks the shape of each definition. `diagonal check` and the build a
724
774
  - 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.
725
775
  - A type has at least one template, and its `defaultTemplate` names one of them.
726
776
  - 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.
727
- - 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. The generator is one that a file can deploy.
777
+ - 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.
778
+ - 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`.
728
779
  - 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.
729
780
  - 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.
730
781
  - 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.
package/dist/cli.mjs CHANGED
@@ -308518,11 +308518,8 @@ function buildRedirects(ast, domains) {
308518
308518
  const { value, nodes } = staticObject(definition, { domains });
308519
308519
  return Object.entries(value).map(([key, redirect]) => {
308520
308520
  const node = nodes[key];
308521
- if (key.length > KEY_MAX_LENGTH2 || !KEY_PATTERN2.test(key)) {
308522
- throw new SourceError(
308523
- `The redirect key "${key}" must start with a lower-case letter and contain only letters and digits, at most ${KEY_MAX_LENGTH2} characters, such as oldMembers`,
308524
- node.key
308525
- );
308521
+ if (!isRedirectKey(key)) {
308522
+ throw new SourceError(redirectKeyMessage(key), node.key);
308526
308523
  }
308527
308524
  if (!isPlainObject2(redirect)) {
308528
308525
  throw new SourceError(`The redirect "${key}" must be an object with "from", "to", and "status"`, node);
@@ -308626,6 +308623,12 @@ function refuseUnknownOptions(value, options, node, owner) {
308626
308623
  }
308627
308624
  }
308628
308625
  }
308626
+ function isRedirectKey(key) {
308627
+ return key.length <= KEY_MAX_LENGTH2 && KEY_PATTERN2.test(key);
308628
+ }
308629
+ function redirectKeyMessage(key) {
308630
+ return `The redirect key "${key}" must start with a lower-case letter and contain only letters and digits, at most ${KEY_MAX_LENGTH2} characters, such as oldMembers`;
308631
+ }
308629
308632
 
308630
308633
  // scripts/lib/runtime-build/migrations.mjs
308631
308634
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -311278,6 +311281,20 @@ function workflowMetadata(ast) {
311278
311281
  }
311279
311282
  return metadata;
311280
311283
  }
311284
+ function workflowListing(ast) {
311285
+ const read2 = workflowMetadata(ast);
311286
+ const trigger = propertyNodes(
311287
+ propertyNodes(workflowConfigObject(ast) ?? void 0).get("trigger")?.value
311288
+ );
311289
+ const isRequest = read2.trigger === "request";
311290
+ const method = isRequest ? stringLiteral4(trigger.get("method")?.value) ?? "GET" : null;
311291
+ return {
311292
+ name: read2.name ?? null,
311293
+ workflow_type: read2.trigger === void 0 ? null : TRIGGERS[read2.trigger].type,
311294
+ route: isRequest ? stringLiteral4(trigger.get("path")?.value) : null,
311295
+ method: method === null ? null : method.toUpperCase()
311296
+ };
311297
+ }
311281
311298
  function configUid(configObject) {
311282
311299
  try {
311283
311300
  return readUid(configObject);
@@ -315065,6 +315082,13 @@ function isMenuFile(path) {
315065
315082
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
315066
315083
  import { posix as posix3 } from "node:path";
315067
315084
 
315085
+ // scripts/lib/runtime-build/calendar-link-types.json
315086
+ var calendar_link_types_default = [
315087
+ "apple",
315088
+ "google",
315089
+ "outlook"
315090
+ ];
315091
+
315068
315092
  // scripts/lib/runtime-build/notification-generators.json
315069
315093
  var notification_generators_default = [
315070
315094
  "page.url",
@@ -315432,11 +315456,7 @@ function resolveSchedules(schedules, definitions, context, diagnostics) {
315432
315456
 
315433
315457
  // scripts/lib/runtime-build/notification-files.mjs
315434
315458
  var NOTIFICATION_REFERENCE_GENERATORS = notification_generators_default;
315435
- var DEPLOYABLE_REFERENCE_GENERATORS = [
315436
- "date.current",
315437
- "time.current",
315438
- "workspace.login_url"
315439
- ];
315459
+ var CALENDAR_LINK_TYPES = calendar_link_types_default;
315440
315460
  var NOTIFICATION_DIRECTORIES = ["notifications", "email-layouts"];
315441
315461
  var BUILT_IN_LAYOUT_FIELDS = {
315442
315462
  content: { label: "Content", description: null, required: true }
@@ -315453,6 +315473,7 @@ var VARIABLE_KEY_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
315453
315473
  var RESERVED_VARIABLE_KEYS = /* @__PURE__ */ new Set(["record", "ref"]);
315454
315474
  var REFERENCE_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
315455
315475
  var REFERENCE_KEY_MAX_LENGTH = 64;
315476
+ var VARIABLE_PATH_PATTERN2 = /^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_]+)*$/;
315456
315477
  var STORED_FIELD_OPTIONS = [
315457
315478
  "guard",
315458
315479
  "default",
@@ -315949,6 +315970,112 @@ function readSms(file2, sms, node, report, context) {
315949
315970
  checkAssetReferences(body.text, body.origin, { html: false }, context, report);
315950
315971
  return { body: body.text };
315951
315972
  }
315973
+ function readBindable(item, node, report, label) {
315974
+ if (typeof item === "string" && item.trim() !== "") {
315975
+ return item;
315976
+ }
315977
+ if (isPlainObject3(item) && Object.keys(item).join() === "variable" && typeof item.variable === "string" && VARIABLE_PATH_PATTERN2.test(item.variable)) {
315978
+ return { variable: item.variable };
315979
+ }
315980
+ report(node, `${label} must be a non-empty string or { variable: '<variable>.<field>' }`);
315981
+ return null;
315982
+ }
315983
+ function readRouteParams(key, settings, settingsNode, report, { route, target }) {
315984
+ const paramsNode = nodeAt(settingsNode, "params");
315985
+ const params = settings.params ?? /* @__PURE__ */ Object.create(null);
315986
+ if (!isPlainObject3(params)) {
315987
+ report(paramsNode, `"settings.params" of reference "${key}" must be an object of route parameters by name`);
315988
+ return null;
315989
+ }
315990
+ const names2 = route === null ? null : routeParamNames(route);
315991
+ const before = report.count();
315992
+ const values = /* @__PURE__ */ Object.create(null);
315993
+ for (const [name, item] of Object.entries(params)) {
315994
+ if (names2 !== null && !names2.includes(name) && !names2.includes(`${name}?`)) {
315995
+ report(
315996
+ keyNodeAt(paramsNode, name),
315997
+ `${target} has no route parameter "${name}". Its route is "${route}"`
315998
+ );
315999
+ continue;
316000
+ }
316001
+ const value = readBindable(item, nodeAt(paramsNode, name), report, `Route parameter "${name}" of reference "${key}"`);
316002
+ if (value !== null) {
316003
+ values[name] = value;
316004
+ }
316005
+ }
316006
+ for (const name of names2 ?? []) {
316007
+ if (!name.endsWith("?") && !Object.hasOwn(params, name)) {
316008
+ report(
316009
+ settings.params === void 0 ? settingsNode : paramsNode,
316010
+ `Reference "${key}" needs a value for the route parameter "${name}" of ${target}, whose route is "${route}". Add params: { ${name}: { variable: '<variable>.<field>' } }`
316011
+ );
316012
+ }
316013
+ }
316014
+ return report.count() === before ? values : null;
316015
+ }
316016
+ function readPageSettings(key, settings, settingsNode, report, context) {
316017
+ const pageNode = nodeAt(settingsNode, "page");
316018
+ const page = typeof settings.page === "string" ? context.pagesByUid.get(settings.page) : void 0;
316019
+ if (page === void 0) {
316020
+ report(
316021
+ settings.page === void 0 ? settingsNode : pageNode,
316022
+ `Reference "${key}" needs settings.page: Pages.<Name>.uid from ${GENERATED_PAGES_MODULE}`
316023
+ );
316024
+ return null;
316025
+ }
316026
+ const params = readRouteParams(key, settings, settingsNode, report, { route: page.route, target: `Pages.${page.name}` });
316027
+ return params === null ? null : { page: settings.page, params };
316028
+ }
316029
+ function readWorkflowSettings(key, settings, settingsNode, report, context) {
316030
+ const workflowNode = nodeAt(settingsNode, "workflow");
316031
+ const workflow = typeof settings.workflow === "string" ? context.workflowsByUid.get(settings.workflow) : void 0;
316032
+ if (workflow === void 0) {
316033
+ report(
316034
+ settings.workflow === void 0 ? settingsNode : workflowNode,
316035
+ `Reference "${key}" needs settings.workflow: Workflows.<Name>.uid from ${GENERATED_WORKFLOWS_MODULE}`
316036
+ );
316037
+ return null;
316038
+ }
316039
+ if (workflow.trigger !== "request") {
316040
+ report(workflowNode, `Workflows.${workflow.name} is not a request workflow, so it has no URL. Use a workflow with trigger: { type: 'request' }`);
316041
+ return null;
316042
+ }
316043
+ const params = readRouteParams(key, settings, settingsNode, report, { route: workflow.route, target: `Workflows.${workflow.name}` });
316044
+ return params === null ? null : { workflow: settings.workflow, params };
316045
+ }
316046
+ function readCalendarSettings(key, settings, settingsNode, report, context) {
316047
+ if (!CALENDAR_LINK_TYPES.includes(settings.type)) {
316048
+ report(
316049
+ settings.type === void 0 ? settingsNode : nodeAt(settingsNode, "type"),
316050
+ `Reference "${key}" needs settings.type: one of ${CALENDAR_LINK_TYPES.map((type) => `'${type}'`).join(", ")}`
316051
+ );
316052
+ return null;
316053
+ }
316054
+ const resourceNode = nodeAt(settingsNode, "resource");
316055
+ const resource = readResource(settings.resource, resourceNode ?? settingsNode, report, `Reference "${key}" "settings.resource"`, context);
316056
+ if (resource === null) {
316057
+ return null;
316058
+ }
316059
+ const definition = context.resourcesBySlug?.get(resource);
316060
+ if (context.resourcesBySlug !== null && definition?.capabilities.eventable === void 0) {
316061
+ report(
316062
+ resourceNode,
316063
+ `Reference "${key}" "settings.resource": the resource "${resource}" is not eventable. Add capabilities.eventable to ${definition?.path ?? `the resource "${resource}"`}`
316064
+ );
316065
+ return null;
316066
+ }
316067
+ if (settings.record === void 0) {
316068
+ report(settingsNode, `Reference "${key}" needs settings.record: { variable: '<variable>.id' }`);
316069
+ return null;
316070
+ }
316071
+ const record = readBindable(settings.record, nodeAt(settingsNode, "record"), report, `"settings.record" of reference "${key}"`);
316072
+ return record === null ? null : { type: settings.type, resource, resource_uid: resourceUid(resource, context), record };
316073
+ }
316074
+ var REFERENCE_SETTINGS = {
316075
+ "page.url": { properties: ["page", "params"], read: readPageSettings },
316076
+ "workflow.url": { properties: ["workflow", "params"], read: readWorkflowSettings },
316077
+ "calendar.generate_link": { properties: ["type", "resource", "record"], read: readCalendarSettings }
316078
+ };
315952
316079
  function readReferenceSettings(key, reference, node, report, context) {
315953
316080
  const settingsNode = nodeAt(node, "settings");
315954
316081
  const settings = reference.settings ?? {};
@@ -315973,6 +316100,15 @@ function readReferenceSettings(key, reference, node, report, context) {
315973
316100
  );
315974
316101
  return resource === null ? null : { resource, resource_uid: resourceUid(resource, context) };
315975
316102
  }
316103
+ const target = REFERENCE_SETTINGS[reference.generator];
316104
+ if (target !== void 0) {
316105
+ const before = report.count();
316106
+ checkProperties(settings, target.properties, settingsNode ?? node, `${reference.generator} setting`, report);
316107
+ if (report.count() > before) {
316108
+ return null;
316109
+ }
316110
+ return target.read(key, settings, settingsNode ?? node, report, context);
316111
+ }
315976
316112
  if (Object.keys(settings).length > 0) {
315977
316113
  report(settingsNode, `${reference.generator} takes no settings`);
315978
316114
  return null;
@@ -316027,10 +316163,6 @@ function readReferences(value, node, report, context) {
316027
316163
  );
316028
316164
  continue;
316029
316165
  }
316030
- if (!DEPLOYABLE_REFERENCE_GENERATORS.includes(generator)) {
316031
- report(generatorNode, `${generator} cannot be deployed from a file-based workspace yet`);
316032
- continue;
316033
- }
316034
316166
  const settings = readReferenceSettings(key, reference, itemNode, report, context);
316035
316167
  if (report.count() === before && settings !== null) {
316036
316168
  references[key] = { label, generator, settings };
@@ -316051,9 +316183,33 @@ function buildTemplate(file2, value, node, report, context) {
316051
316183
  email: value.email === void 0 ? null : readEmail(file2, value.email, nodeAt(node, "email"), report, context),
316052
316184
  sms: value.sms === void 0 ? null : readSms(file2, value.sms, nodeAt(node, "sms"), report, context),
316053
316185
  references: readReferences(value, node, report, context),
316054
- nodes: { email: nodeAt(node, "email"), sms: nodeAt(node, "sms") }
316186
+ nodes: { email: nodeAt(node, "email"), sms: nodeAt(node, "sms"), references: nodeAt(node, "references") }
316055
316187
  };
316056
316188
  }
316189
+ function variableBindingDiagnostics(template, type) {
316190
+ const roots = type.variables.map((variable) => variable.key);
316191
+ if (type.recipient_resource !== null) {
316192
+ roots.push("record");
316193
+ }
316194
+ const diagnostics = [];
316195
+ for (const [key, reference] of Object.entries(template.references)) {
316196
+ const settingsNode = nodeAt(nodeAt(template.nodes.references, key), "settings");
316197
+ const bindings = reference.generator === "calendar.generate_link" ? [[reference.settings.record, nodeAt(settingsNode, "record")]] : Object.entries(reference.settings.params ?? {}).map(([name, value]) => [value, nodeAt(nodeAt(settingsNode, "params"), name)]);
316198
+ for (const [value, node] of bindings) {
316199
+ if (!isPlainObject3(value) || roots.includes(value.variable.split(".")[0])) {
316200
+ continue;
316201
+ }
316202
+ diagnostics.push(
316203
+ diagnosticAt(
316204
+ template.path,
316205
+ nodeAt(node, "variable") ?? node,
316206
+ roots.length === 0 ? `"${value.variable}" names no variable. The notification type "${type.slug}" has no variables and no recipient` : `"${value.variable}" names no variable of the notification type "${type.slug}". Start the path with one of: ${roots.join(", ")}`
316207
+ )
316208
+ );
316209
+ }
316210
+ }
316211
+ return diagnostics;
316212
+ }
316057
316213
  function readLayoutFields(value, node, report) {
316058
316214
  if (value.fields === void 0) {
316059
316215
  return {};
@@ -316149,9 +316305,12 @@ function readDefinition(file2, context, report) {
316149
316305
  notificationTypesBinding(file2.ast, context.notificationTypes.entries),
316150
316306
  emailLayoutsBinding(file2.ast, context.emailLayouts.entries)
316151
316307
  ].filter((binding) => binding !== null);
316308
+ const template = definitionKind.kind === "template";
316152
316309
  const { value } = staticObject(definition, {
316153
316310
  fieldBuilders: true,
316154
316311
  resources: resourcesBinding(file2.ast, context.names),
316312
+ pages: template ? pagesBinding(file2.ast, context.pages.entries, context.pages.pathsByName) : null,
316313
+ workflows: template ? workflowsBinding(file2.ast, context.workflows.entries, context.workflows.names) : null,
316155
316314
  generatedEntries: [...generatedEntries, ...recordBindingsBinding(file2.ast, context.recordBindingEntries ?? {})]
316156
316315
  });
316157
316316
  if (definitionKind.kind === "template" && value.type !== void 0) {
@@ -316220,6 +316379,8 @@ function checkNotificationFiles(files, {
316220
316379
  unreadFiles = [],
316221
316380
  notificationTypes = { names: /* @__PURE__ */ new Map(), entries: {} },
316222
316381
  emailLayouts = { names: /* @__PURE__ */ new Map(), entries: {} },
316382
+ pages = { entries: {}, pathsByName: /* @__PURE__ */ new Map() },
316383
+ workflows = { entries: {}, names: { pathsByName: /* @__PURE__ */ new Map() }, routesByPath: /* @__PURE__ */ new Map() },
316223
316384
  assets = [],
316224
316385
  assetCatalog = null
316225
316386
  }) {
@@ -316227,6 +316388,15 @@ function checkNotificationFiles(files, {
316227
316388
  const context = {
316228
316389
  recordBindingEntries,
316229
316390
  names: names2,
316391
+ pages,
316392
+ pagesByUid: indexPagesByUid(pages.entries),
316393
+ workflows,
316394
+ workflowsByUid: new Map(
316395
+ Object.entries(workflows.entries).filter(([, workflow]) => workflow.uid !== null).map(([name, workflow]) => [
316396
+ workflow.uid,
316397
+ { name, trigger: workflow.trigger ?? null, route: workflows.routesByPath.get(workflows.names.pathsByName.get(name)) ?? null }
316398
+ ])
316399
+ ),
316230
316400
  resources,
316231
316401
  resourceSlugs: resourcesComplete ? new Set([...resources, ...builtInResources].map((resource) => resource.slug)) : null,
316232
316402
  resourceUids: new Map(resources.map((resource) => [resource.slug, resource.uid ?? null])),
@@ -316305,6 +316475,12 @@ function checkNotificationFiles(files, {
316305
316475
  fail("template", template);
316306
316476
  continue;
316307
316477
  }
316478
+ const bindingDiagnostics = variableBindingDiagnostics(template, type);
316479
+ if (bindingDiagnostics.length > 0) {
316480
+ diagnostics.push(...bindingDiagnostics);
316481
+ fail("template", template);
316482
+ continue;
316483
+ }
316308
316484
  templates.push({
316309
316485
  path: template.path,
316310
316486
  uid: template.uid,
@@ -322513,7 +322689,10 @@ function readWorkflowReferences(root, files, diagnostics) {
322513
322689
  throw error;
322514
322690
  }
322515
322691
  });
322516
- return workflowReferences(workflowFiles, diagnostics);
322692
+ return {
322693
+ ...workflowReferences(workflowFiles, diagnostics),
322694
+ routesByPath: new Map(workflowFiles.map(({ path, ast }) => [path, ast === null ? null : workflowListing(ast).route]))
322695
+ };
322517
322696
  }
322518
322697
  function lintUnits(units, resources, pages, diagnostics, assetsComplete, domainsComplete) {
322519
322698
  const catalogs = {
@@ -322565,7 +322744,7 @@ function buildPageEntries(root, files, write, diagnostics) {
322565
322744
  };
322566
322745
  }
322567
322746
  var NOTIFICATION_KINDS = new Set(Object.keys(NOTIFICATION_DEFINITIONS));
322568
- function buildNotifications(root, files, { writeSource, names: names2, resources, builtInResources, recordBindingEntries, resourcesComplete, assets, assetCatalog, diagnostics }) {
322747
+ function buildNotifications(root, files, { writeSource, names: names2, resources, builtInResources, recordBindingEntries, resourcesComplete, pages, workflows, assets, assetCatalog, diagnostics }) {
322569
322748
  const paths = files.filter((path) => NOTIFICATION_KINDS.has(classify(path)));
322570
322749
  const read2 = [];
322571
322750
  const unreadFiles = [];
@@ -322603,6 +322782,8 @@ function buildNotifications(root, files, { writeSource, names: names2, resources
322603
322782
  builtInResources,
322604
322783
  recordBindingEntries,
322605
322784
  resourcesComplete,
322785
+ pages,
322786
+ workflows,
322606
322787
  assets,
322607
322788
  assetCatalog,
322608
322789
  unreadFiles,
@@ -322741,7 +322922,12 @@ function uidDefinitionNodes(kind, path, ast) {
322741
322922
  case "notification_schedule":
322742
322923
  case "email_layout": {
322743
322924
  const { type, define: define2 } = NOTIFICATION_DEFINITIONS[kind];
322744
- const extraImports = kind === "email_layout" ? [GENERATED_RESOURCES_MODULE] : [GENERATED_RESOURCES_MODULE, GENERATED_NOTIFICATION_TYPES_MODULE, GENERATED_EMAIL_LAYOUTS_MODULE];
322925
+ const extraImports = kind === "email_layout" ? [GENERATED_RESOURCES_MODULE] : [
322926
+ GENERATED_RESOURCES_MODULE,
322927
+ GENERATED_NOTIFICATION_TYPES_MODULE,
322928
+ GENERATED_EMAIL_LAYOUTS_MODULE,
322929
+ ...kind === "notification_template" ? [GENERATED_PAGES_MODULE, GENERATED_WORKFLOWS_MODULE] : []
322930
+ ];
322745
322931
  const { declaration } = defaultExportOf(ast, { extraImports: [...extraImports, GENERATED_RECORD_BINDINGS_MODULE] });
322746
322932
  return [{ type, node: expectDefineCall(declaration, define2, 1)[0] }];
322747
322933
  }
@@ -323179,6 +323365,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323179
323365
  if (files.includes(CONFIG_PATH2)) {
323180
323366
  buildFile(CONFIG_PATH2);
323181
323367
  }
323368
+ const workflows = readWorkflowReferences(root, otherFiles, diagnostics);
323182
323369
  const notifications = buildNotifications(root, files, {
323183
323370
  writeSource,
323184
323371
  names: names2,
@@ -323186,12 +323373,13 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323186
323373
  builtInResources: BUILT_IN_RESOURCES,
323187
323374
  recordBindingEntries: recordBindings.entries,
323188
323375
  resourcesComplete,
323376
+ pages: generatedPages,
323377
+ workflows,
323189
323378
  assets: assetsComplete ? output.assets : null,
323190
323379
  assetCatalog,
323191
323380
  diagnostics
323192
323381
  });
323193
323382
  const notificationCheck = notifications.check;
323194
- const workflows = readWorkflowReferences(root, otherFiles, diagnostics);
323195
323383
  writeGeneratedModule(
323196
323384
  root,
323197
323385
  GENERATED_WORKFLOWS_PATH,
package/dist/index.d.ts CHANGED
@@ -1154,11 +1154,17 @@ export declare function defineNotificationType<const T extends NotificationTypeD
1154
1154
  type: T
1155
1155
  ): T;
1156
1156
 
1157
+ /**
1158
+ * A value that the notification reads when it renders: a string, or
1159
+ * `{ variable: '<path>' }`, a path in the values of the send. The path starts
1160
+ * with a variable of the type, or with `record`, the recipient, such as
1161
+ * `{ variable: 'record.id' }`.
1162
+ */
1163
+ export type NotificationBoundValue = string | { variable: string };
1164
+
1157
1165
  /**
1158
1166
  * A server generator that a template reads as `{{ ref.<key> }}`. A file can
1159
- * deploy `date.current`, `time.current`, and `workspace.login_url`. The
1160
- * `page.url`, `workflow.url`, and `calendar.generate_link` generators of the
1161
- * template editor cannot be deployed from a file yet.
1167
+ * use every generator of the template editor.
1162
1168
  */
1163
1169
  export type NotificationReference =
1164
1170
  | { label: string; generator: 'date.current' | 'time.current' }
@@ -1167,6 +1173,37 @@ export type NotificationReference =
1167
1173
  generator: 'workspace.login_url';
1168
1174
  /** The resource whose members sign in, as `Resources.<Name>.slug`. */
1169
1175
  settings: { resource: ResourceReference };
1176
+ }
1177
+ | {
1178
+ label: string;
1179
+ generator: 'page.url';
1180
+ settings: {
1181
+ /** The page, as `Pages.<Name>.uid` from `@app/generated/pages`. */
1182
+ page: string;
1183
+ /** A value for each required route parameter of the page. */
1184
+ params?: { readonly [param: string]: NotificationBoundValue };
1185
+ };
1186
+ }
1187
+ | {
1188
+ label: string;
1189
+ generator: 'workflow.url';
1190
+ settings: {
1191
+ /** A workflow with a `request` trigger, as `Workflows.<Name>.uid` from `@app/generated/workflows`. */
1192
+ workflow: string;
1193
+ /** A value for each required route parameter of the workflow. */
1194
+ params?: { readonly [param: string]: NotificationBoundValue };
1195
+ };
1196
+ }
1197
+ | {
1198
+ label: string;
1199
+ generator: 'calendar.generate_link';
1200
+ settings: {
1201
+ type: 'apple' | 'google' | 'outlook';
1202
+ /** An eventable resource, as `Resources.<Name>.slug`. */
1203
+ resource: ResourceReference;
1204
+ /** The event record, such as `{ variable: 'first_event.id' }`. */
1205
+ record: NotificationBoundValue;
1206
+ };
1170
1207
  };
1171
1208
 
1172
1209
  export type NotificationTemplateEmail = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.33.5",
3
+ "version": "0.33.7",
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": {