@diagonal-hq/cli 0.33.4 → 0.33.6
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 +53 -2
- package/dist/cli.mjs +214 -21
- package/dist/index.d.ts +40 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -598,7 +598,57 @@ export default defineNotificationTemplate({
|
|
|
598
598
|
});
|
|
599
599
|
```
|
|
600
600
|
|
|
601
|
-
A file can use
|
|
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.
|
|
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
|
@@ -311278,6 +311278,20 @@ function workflowMetadata(ast) {
|
|
|
311278
311278
|
}
|
|
311279
311279
|
return metadata;
|
|
311280
311280
|
}
|
|
311281
|
+
function workflowListing(ast) {
|
|
311282
|
+
const read2 = workflowMetadata(ast);
|
|
311283
|
+
const trigger = propertyNodes(
|
|
311284
|
+
propertyNodes(workflowConfigObject(ast) ?? void 0).get("trigger")?.value
|
|
311285
|
+
);
|
|
311286
|
+
const isRequest = read2.trigger === "request";
|
|
311287
|
+
const method = isRequest ? stringLiteral4(trigger.get("method")?.value) ?? "GET" : null;
|
|
311288
|
+
return {
|
|
311289
|
+
name: read2.name ?? null,
|
|
311290
|
+
workflow_type: read2.trigger === void 0 ? null : TRIGGERS[read2.trigger].type,
|
|
311291
|
+
route: isRequest ? stringLiteral4(trigger.get("path")?.value) : null,
|
|
311292
|
+
method: method === null ? null : method.toUpperCase()
|
|
311293
|
+
};
|
|
311294
|
+
}
|
|
311281
311295
|
function configUid(configObject) {
|
|
311282
311296
|
try {
|
|
311283
311297
|
return readUid(configObject);
|
|
@@ -315047,10 +315061,31 @@ function buildMigrations({ migrations, ...input }) {
|
|
|
315047
315061
|
};
|
|
315048
315062
|
}
|
|
315049
315063
|
|
|
315064
|
+
// scripts/lib/runtime-build/navigation-menu-file.mjs
|
|
315065
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
315066
|
+
|
|
315067
|
+
// scripts/lib/runtime-build/source-literal.mjs
|
|
315068
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
315069
|
+
function quotedLiteral(value) {
|
|
315070
|
+
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029")}'`;
|
|
315071
|
+
}
|
|
315072
|
+
|
|
315073
|
+
// scripts/lib/runtime-build/navigation-menu-file.mjs
|
|
315074
|
+
function isMenuFile(path) {
|
|
315075
|
+
return /^navigation\/[^/]+\.ts$/.test(path) && !/\.(test|spec|d)\.ts$/.test(path);
|
|
315076
|
+
}
|
|
315077
|
+
|
|
315050
315078
|
// scripts/lib/runtime-build/notification-files.mjs
|
|
315051
315079
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
315052
315080
|
import { posix as posix3 } from "node:path";
|
|
315053
315081
|
|
|
315082
|
+
// scripts/lib/runtime-build/calendar-link-types.json
|
|
315083
|
+
var calendar_link_types_default = [
|
|
315084
|
+
"apple",
|
|
315085
|
+
"google",
|
|
315086
|
+
"outlook"
|
|
315087
|
+
];
|
|
315088
|
+
|
|
315054
315089
|
// scripts/lib/runtime-build/notification-generators.json
|
|
315055
315090
|
var notification_generators_default = [
|
|
315056
315091
|
"page.url",
|
|
@@ -315418,11 +315453,7 @@ function resolveSchedules(schedules, definitions, context, diagnostics) {
|
|
|
315418
315453
|
|
|
315419
315454
|
// scripts/lib/runtime-build/notification-files.mjs
|
|
315420
315455
|
var NOTIFICATION_REFERENCE_GENERATORS = notification_generators_default;
|
|
315421
|
-
var
|
|
315422
|
-
"date.current",
|
|
315423
|
-
"time.current",
|
|
315424
|
-
"workspace.login_url"
|
|
315425
|
-
];
|
|
315456
|
+
var CALENDAR_LINK_TYPES = calendar_link_types_default;
|
|
315426
315457
|
var NOTIFICATION_DIRECTORIES = ["notifications", "email-layouts"];
|
|
315427
315458
|
var BUILT_IN_LAYOUT_FIELDS = {
|
|
315428
315459
|
content: { label: "Content", description: null, required: true }
|
|
@@ -315439,6 +315470,7 @@ var VARIABLE_KEY_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
|
315439
315470
|
var RESERVED_VARIABLE_KEYS = /* @__PURE__ */ new Set(["record", "ref"]);
|
|
315440
315471
|
var REFERENCE_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
315441
315472
|
var REFERENCE_KEY_MAX_LENGTH = 64;
|
|
315473
|
+
var VARIABLE_PATH_PATTERN2 = /^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_]+)*$/;
|
|
315442
315474
|
var STORED_FIELD_OPTIONS = [
|
|
315443
315475
|
"guard",
|
|
315444
315476
|
"default",
|
|
@@ -315935,6 +315967,112 @@ function readSms(file2, sms, node, report, context) {
|
|
|
315935
315967
|
checkAssetReferences(body.text, body.origin, { html: false }, context, report);
|
|
315936
315968
|
return { body: body.text };
|
|
315937
315969
|
}
|
|
315970
|
+
function readBindable(item, node, report, label) {
|
|
315971
|
+
if (typeof item === "string" && item.trim() !== "") {
|
|
315972
|
+
return item;
|
|
315973
|
+
}
|
|
315974
|
+
if (isPlainObject3(item) && Object.keys(item).join() === "variable" && typeof item.variable === "string" && VARIABLE_PATH_PATTERN2.test(item.variable)) {
|
|
315975
|
+
return { variable: item.variable };
|
|
315976
|
+
}
|
|
315977
|
+
report(node, `${label} must be a non-empty string or { variable: '<variable>.<field>' }`);
|
|
315978
|
+
return null;
|
|
315979
|
+
}
|
|
315980
|
+
function readRouteParams(key, settings, settingsNode, report, { route, target }) {
|
|
315981
|
+
const paramsNode = nodeAt(settingsNode, "params");
|
|
315982
|
+
const params = settings.params ?? /* @__PURE__ */ Object.create(null);
|
|
315983
|
+
if (!isPlainObject3(params)) {
|
|
315984
|
+
report(paramsNode, `"settings.params" of reference "${key}" must be an object of route parameters by name`);
|
|
315985
|
+
return null;
|
|
315986
|
+
}
|
|
315987
|
+
const names2 = route === null ? null : routeParamNames(route);
|
|
315988
|
+
const before = report.count();
|
|
315989
|
+
const values = /* @__PURE__ */ Object.create(null);
|
|
315990
|
+
for (const [name, item] of Object.entries(params)) {
|
|
315991
|
+
if (names2 !== null && !names2.includes(name) && !names2.includes(`${name}?`)) {
|
|
315992
|
+
report(
|
|
315993
|
+
keyNodeAt(paramsNode, name),
|
|
315994
|
+
`${target} has no route parameter "${name}". Its route is "${route}"`
|
|
315995
|
+
);
|
|
315996
|
+
continue;
|
|
315997
|
+
}
|
|
315998
|
+
const value = readBindable(item, nodeAt(paramsNode, name), report, `Route parameter "${name}" of reference "${key}"`);
|
|
315999
|
+
if (value !== null) {
|
|
316000
|
+
values[name] = value;
|
|
316001
|
+
}
|
|
316002
|
+
}
|
|
316003
|
+
for (const name of names2 ?? []) {
|
|
316004
|
+
if (!name.endsWith("?") && !Object.hasOwn(params, name)) {
|
|
316005
|
+
report(
|
|
316006
|
+
settings.params === void 0 ? settingsNode : paramsNode,
|
|
316007
|
+
`Reference "${key}" needs a value for the route parameter "${name}" of ${target}, whose route is "${route}". Add params: { ${name}: { variable: '<variable>.<field>' } }`
|
|
316008
|
+
);
|
|
316009
|
+
}
|
|
316010
|
+
}
|
|
316011
|
+
return report.count() === before ? values : null;
|
|
316012
|
+
}
|
|
316013
|
+
function readPageSettings(key, settings, settingsNode, report, context) {
|
|
316014
|
+
const pageNode = nodeAt(settingsNode, "page");
|
|
316015
|
+
const page = typeof settings.page === "string" ? context.pagesByUid.get(settings.page) : void 0;
|
|
316016
|
+
if (page === void 0) {
|
|
316017
|
+
report(
|
|
316018
|
+
settings.page === void 0 ? settingsNode : pageNode,
|
|
316019
|
+
`Reference "${key}" needs settings.page: Pages.<Name>.uid from ${GENERATED_PAGES_MODULE}`
|
|
316020
|
+
);
|
|
316021
|
+
return null;
|
|
316022
|
+
}
|
|
316023
|
+
const params = readRouteParams(key, settings, settingsNode, report, { route: page.route, target: `Pages.${page.name}` });
|
|
316024
|
+
return params === null ? null : { page: settings.page, params };
|
|
316025
|
+
}
|
|
316026
|
+
function readWorkflowSettings(key, settings, settingsNode, report, context) {
|
|
316027
|
+
const workflowNode = nodeAt(settingsNode, "workflow");
|
|
316028
|
+
const workflow = typeof settings.workflow === "string" ? context.workflowsByUid.get(settings.workflow) : void 0;
|
|
316029
|
+
if (workflow === void 0) {
|
|
316030
|
+
report(
|
|
316031
|
+
settings.workflow === void 0 ? settingsNode : workflowNode,
|
|
316032
|
+
`Reference "${key}" needs settings.workflow: Workflows.<Name>.uid from ${GENERATED_WORKFLOWS_MODULE}`
|
|
316033
|
+
);
|
|
316034
|
+
return null;
|
|
316035
|
+
}
|
|
316036
|
+
if (workflow.trigger !== "request") {
|
|
316037
|
+
report(workflowNode, `Workflows.${workflow.name} is not a request workflow, so it has no URL. Use a workflow with trigger: { type: 'request' }`);
|
|
316038
|
+
return null;
|
|
316039
|
+
}
|
|
316040
|
+
const params = readRouteParams(key, settings, settingsNode, report, { route: workflow.route, target: `Workflows.${workflow.name}` });
|
|
316041
|
+
return params === null ? null : { workflow: settings.workflow, params };
|
|
316042
|
+
}
|
|
316043
|
+
function readCalendarSettings(key, settings, settingsNode, report, context) {
|
|
316044
|
+
if (!CALENDAR_LINK_TYPES.includes(settings.type)) {
|
|
316045
|
+
report(
|
|
316046
|
+
settings.type === void 0 ? settingsNode : nodeAt(settingsNode, "type"),
|
|
316047
|
+
`Reference "${key}" needs settings.type: one of ${CALENDAR_LINK_TYPES.map((type) => `'${type}'`).join(", ")}`
|
|
316048
|
+
);
|
|
316049
|
+
return null;
|
|
316050
|
+
}
|
|
316051
|
+
const resourceNode = nodeAt(settingsNode, "resource");
|
|
316052
|
+
const resource = readResource(settings.resource, resourceNode ?? settingsNode, report, `Reference "${key}" "settings.resource"`, context);
|
|
316053
|
+
if (resource === null) {
|
|
316054
|
+
return null;
|
|
316055
|
+
}
|
|
316056
|
+
const definition = context.resourcesBySlug?.get(resource);
|
|
316057
|
+
if (context.resourcesBySlug !== null && definition?.capabilities.eventable === void 0) {
|
|
316058
|
+
report(
|
|
316059
|
+
resourceNode,
|
|
316060
|
+
`Reference "${key}" "settings.resource": the resource "${resource}" is not eventable. Add capabilities.eventable to ${definition?.path ?? `the resource "${resource}"`}`
|
|
316061
|
+
);
|
|
316062
|
+
return null;
|
|
316063
|
+
}
|
|
316064
|
+
if (settings.record === void 0) {
|
|
316065
|
+
report(settingsNode, `Reference "${key}" needs settings.record: { variable: '<variable>.id' }`);
|
|
316066
|
+
return null;
|
|
316067
|
+
}
|
|
316068
|
+
const record = readBindable(settings.record, nodeAt(settingsNode, "record"), report, `"settings.record" of reference "${key}"`);
|
|
316069
|
+
return record === null ? null : { type: settings.type, resource, resource_uid: resourceUid(resource, context), record };
|
|
316070
|
+
}
|
|
316071
|
+
var REFERENCE_SETTINGS = {
|
|
316072
|
+
"page.url": { properties: ["page", "params"], read: readPageSettings },
|
|
316073
|
+
"workflow.url": { properties: ["workflow", "params"], read: readWorkflowSettings },
|
|
316074
|
+
"calendar.generate_link": { properties: ["type", "resource", "record"], read: readCalendarSettings }
|
|
316075
|
+
};
|
|
315938
316076
|
function readReferenceSettings(key, reference, node, report, context) {
|
|
315939
316077
|
const settingsNode = nodeAt(node, "settings");
|
|
315940
316078
|
const settings = reference.settings ?? {};
|
|
@@ -315959,6 +316097,15 @@ function readReferenceSettings(key, reference, node, report, context) {
|
|
|
315959
316097
|
);
|
|
315960
316098
|
return resource === null ? null : { resource, resource_uid: resourceUid(resource, context) };
|
|
315961
316099
|
}
|
|
316100
|
+
const target = REFERENCE_SETTINGS[reference.generator];
|
|
316101
|
+
if (target !== void 0) {
|
|
316102
|
+
const before = report.count();
|
|
316103
|
+
checkProperties(settings, target.properties, settingsNode ?? node, `${reference.generator} setting`, report);
|
|
316104
|
+
if (report.count() > before) {
|
|
316105
|
+
return null;
|
|
316106
|
+
}
|
|
316107
|
+
return target.read(key, settings, settingsNode ?? node, report, context);
|
|
316108
|
+
}
|
|
315962
316109
|
if (Object.keys(settings).length > 0) {
|
|
315963
316110
|
report(settingsNode, `${reference.generator} takes no settings`);
|
|
315964
316111
|
return null;
|
|
@@ -316013,10 +316160,6 @@ function readReferences(value, node, report, context) {
|
|
|
316013
316160
|
);
|
|
316014
316161
|
continue;
|
|
316015
316162
|
}
|
|
316016
|
-
if (!DEPLOYABLE_REFERENCE_GENERATORS.includes(generator)) {
|
|
316017
|
-
report(generatorNode, `${generator} cannot be deployed from a file-based workspace yet`);
|
|
316018
|
-
continue;
|
|
316019
|
-
}
|
|
316020
316163
|
const settings = readReferenceSettings(key, reference, itemNode, report, context);
|
|
316021
316164
|
if (report.count() === before && settings !== null) {
|
|
316022
316165
|
references[key] = { label, generator, settings };
|
|
@@ -316037,9 +316180,33 @@ function buildTemplate(file2, value, node, report, context) {
|
|
|
316037
316180
|
email: value.email === void 0 ? null : readEmail(file2, value.email, nodeAt(node, "email"), report, context),
|
|
316038
316181
|
sms: value.sms === void 0 ? null : readSms(file2, value.sms, nodeAt(node, "sms"), report, context),
|
|
316039
316182
|
references: readReferences(value, node, report, context),
|
|
316040
|
-
nodes: { email: nodeAt(node, "email"), sms: nodeAt(node, "sms") }
|
|
316183
|
+
nodes: { email: nodeAt(node, "email"), sms: nodeAt(node, "sms"), references: nodeAt(node, "references") }
|
|
316041
316184
|
};
|
|
316042
316185
|
}
|
|
316186
|
+
function variableBindingDiagnostics(template, type) {
|
|
316187
|
+
const roots = type.variables.map((variable) => variable.key);
|
|
316188
|
+
if (type.recipient_resource !== null) {
|
|
316189
|
+
roots.push("record");
|
|
316190
|
+
}
|
|
316191
|
+
const diagnostics = [];
|
|
316192
|
+
for (const [key, reference] of Object.entries(template.references)) {
|
|
316193
|
+
const settingsNode = nodeAt(nodeAt(template.nodes.references, key), "settings");
|
|
316194
|
+
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)]);
|
|
316195
|
+
for (const [value, node] of bindings) {
|
|
316196
|
+
if (!isPlainObject3(value) || roots.includes(value.variable.split(".")[0])) {
|
|
316197
|
+
continue;
|
|
316198
|
+
}
|
|
316199
|
+
diagnostics.push(
|
|
316200
|
+
diagnosticAt(
|
|
316201
|
+
template.path,
|
|
316202
|
+
nodeAt(node, "variable") ?? node,
|
|
316203
|
+
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(", ")}`
|
|
316204
|
+
)
|
|
316205
|
+
);
|
|
316206
|
+
}
|
|
316207
|
+
}
|
|
316208
|
+
return diagnostics;
|
|
316209
|
+
}
|
|
316043
316210
|
function readLayoutFields(value, node, report) {
|
|
316044
316211
|
if (value.fields === void 0) {
|
|
316045
316212
|
return {};
|
|
@@ -316135,9 +316302,12 @@ function readDefinition(file2, context, report) {
|
|
|
316135
316302
|
notificationTypesBinding(file2.ast, context.notificationTypes.entries),
|
|
316136
316303
|
emailLayoutsBinding(file2.ast, context.emailLayouts.entries)
|
|
316137
316304
|
].filter((binding) => binding !== null);
|
|
316305
|
+
const template = definitionKind.kind === "template";
|
|
316138
316306
|
const { value } = staticObject(definition, {
|
|
316139
316307
|
fieldBuilders: true,
|
|
316140
316308
|
resources: resourcesBinding(file2.ast, context.names),
|
|
316309
|
+
pages: template ? pagesBinding(file2.ast, context.pages.entries, context.pages.pathsByName) : null,
|
|
316310
|
+
workflows: template ? workflowsBinding(file2.ast, context.workflows.entries, context.workflows.names) : null,
|
|
316141
316311
|
generatedEntries: [...generatedEntries, ...recordBindingsBinding(file2.ast, context.recordBindingEntries ?? {})]
|
|
316142
316312
|
});
|
|
316143
316313
|
if (definitionKind.kind === "template" && value.type !== void 0) {
|
|
@@ -316206,6 +316376,8 @@ function checkNotificationFiles(files, {
|
|
|
316206
316376
|
unreadFiles = [],
|
|
316207
316377
|
notificationTypes = { names: /* @__PURE__ */ new Map(), entries: {} },
|
|
316208
316378
|
emailLayouts = { names: /* @__PURE__ */ new Map(), entries: {} },
|
|
316379
|
+
pages = { entries: {}, pathsByName: /* @__PURE__ */ new Map() },
|
|
316380
|
+
workflows = { entries: {}, names: { pathsByName: /* @__PURE__ */ new Map() }, routesByPath: /* @__PURE__ */ new Map() },
|
|
316209
316381
|
assets = [],
|
|
316210
316382
|
assetCatalog = null
|
|
316211
316383
|
}) {
|
|
@@ -316213,6 +316385,15 @@ function checkNotificationFiles(files, {
|
|
|
316213
316385
|
const context = {
|
|
316214
316386
|
recordBindingEntries,
|
|
316215
316387
|
names: names2,
|
|
316388
|
+
pages,
|
|
316389
|
+
pagesByUid: indexPagesByUid(pages.entries),
|
|
316390
|
+
workflows,
|
|
316391
|
+
workflowsByUid: new Map(
|
|
316392
|
+
Object.entries(workflows.entries).filter(([, workflow]) => workflow.uid !== null).map(([name, workflow]) => [
|
|
316393
|
+
workflow.uid,
|
|
316394
|
+
{ name, trigger: workflow.trigger ?? null, route: workflows.routesByPath.get(workflows.names.pathsByName.get(name)) ?? null }
|
|
316395
|
+
])
|
|
316396
|
+
),
|
|
316216
316397
|
resources,
|
|
316217
316398
|
resourceSlugs: resourcesComplete ? new Set([...resources, ...builtInResources].map((resource) => resource.slug)) : null,
|
|
316218
316399
|
resourceUids: new Map(resources.map((resource) => [resource.slug, resource.uid ?? null])),
|
|
@@ -316291,6 +316472,12 @@ function checkNotificationFiles(files, {
|
|
|
316291
316472
|
fail("template", template);
|
|
316292
316473
|
continue;
|
|
316293
316474
|
}
|
|
316475
|
+
const bindingDiagnostics = variableBindingDiagnostics(template, type);
|
|
316476
|
+
if (bindingDiagnostics.length > 0) {
|
|
316477
|
+
diagnostics.push(...bindingDiagnostics);
|
|
316478
|
+
fail("template", template);
|
|
316479
|
+
continue;
|
|
316480
|
+
}
|
|
316294
316481
|
templates.push({
|
|
316295
316482
|
path: template.path,
|
|
316296
316483
|
uid: template.uid,
|
|
@@ -319416,12 +319603,6 @@ function seoReadProblem({ key, read: read2, inTemplate }, bindings, resourcesByS
|
|
|
319416
319603
|
return null;
|
|
319417
319604
|
}
|
|
319418
319605
|
|
|
319419
|
-
// scripts/lib/runtime-build/source-literal.mjs
|
|
319420
|
-
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
319421
|
-
function quotedLiteral(value) {
|
|
319422
|
-
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029")}'`;
|
|
319423
|
-
}
|
|
319424
|
-
|
|
319425
319606
|
// scripts/lib/runtime-build/page-options-migration.mjs
|
|
319426
319607
|
function movableMetaValue(value) {
|
|
319427
319608
|
if (value !== null && typeof value !== "string" && !isPlainObject2(value)) {
|
|
@@ -322505,7 +322686,10 @@ function readWorkflowReferences(root, files, diagnostics) {
|
|
|
322505
322686
|
throw error;
|
|
322506
322687
|
}
|
|
322507
322688
|
});
|
|
322508
|
-
return
|
|
322689
|
+
return {
|
|
322690
|
+
...workflowReferences(workflowFiles, diagnostics),
|
|
322691
|
+
routesByPath: new Map(workflowFiles.map(({ path, ast }) => [path, ast === null ? null : workflowListing(ast).route]))
|
|
322692
|
+
};
|
|
322509
322693
|
}
|
|
322510
322694
|
function lintUnits(units, resources, pages, diagnostics, assetsComplete, domainsComplete) {
|
|
322511
322695
|
const catalogs = {
|
|
@@ -322557,7 +322741,7 @@ function buildPageEntries(root, files, write, diagnostics) {
|
|
|
322557
322741
|
};
|
|
322558
322742
|
}
|
|
322559
322743
|
var NOTIFICATION_KINDS = new Set(Object.keys(NOTIFICATION_DEFINITIONS));
|
|
322560
|
-
function buildNotifications(root, files, { writeSource, names: names2, resources, builtInResources, recordBindingEntries, resourcesComplete, assets, assetCatalog, diagnostics }) {
|
|
322744
|
+
function buildNotifications(root, files, { writeSource, names: names2, resources, builtInResources, recordBindingEntries, resourcesComplete, pages, workflows, assets, assetCatalog, diagnostics }) {
|
|
322561
322745
|
const paths = files.filter((path) => NOTIFICATION_KINDS.has(classify(path)));
|
|
322562
322746
|
const read2 = [];
|
|
322563
322747
|
const unreadFiles = [];
|
|
@@ -322595,6 +322779,8 @@ function buildNotifications(root, files, { writeSource, names: names2, resources
|
|
|
322595
322779
|
builtInResources,
|
|
322596
322780
|
recordBindingEntries,
|
|
322597
322781
|
resourcesComplete,
|
|
322782
|
+
pages,
|
|
322783
|
+
workflows,
|
|
322598
322784
|
assets,
|
|
322599
322785
|
assetCatalog,
|
|
322600
322786
|
unreadFiles,
|
|
@@ -322733,7 +322919,12 @@ function uidDefinitionNodes(kind, path, ast) {
|
|
|
322733
322919
|
case "notification_schedule":
|
|
322734
322920
|
case "email_layout": {
|
|
322735
322921
|
const { type, define: define2 } = NOTIFICATION_DEFINITIONS[kind];
|
|
322736
|
-
const extraImports = kind === "email_layout" ? [GENERATED_RESOURCES_MODULE] : [
|
|
322922
|
+
const extraImports = kind === "email_layout" ? [GENERATED_RESOURCES_MODULE] : [
|
|
322923
|
+
GENERATED_RESOURCES_MODULE,
|
|
322924
|
+
GENERATED_NOTIFICATION_TYPES_MODULE,
|
|
322925
|
+
GENERATED_EMAIL_LAYOUTS_MODULE,
|
|
322926
|
+
...kind === "notification_template" ? [GENERATED_PAGES_MODULE, GENERATED_WORKFLOWS_MODULE] : []
|
|
322927
|
+
];
|
|
322737
322928
|
const { declaration } = defaultExportOf(ast, { extraImports: [...extraImports, GENERATED_RECORD_BINDINGS_MODULE] });
|
|
322738
322929
|
return [{ type, node: expectDefineCall(declaration, define2, 1)[0] }];
|
|
322739
322930
|
}
|
|
@@ -322796,7 +322987,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
|
|
|
322796
322987
|
const files = listCheckoutFiles(root, IGNORED_DIRECTORIES);
|
|
322797
322988
|
const moduleUidDefinitions = [];
|
|
322798
322989
|
for (const path of files) {
|
|
322799
|
-
const type = moduleEntityType(path);
|
|
322990
|
+
const type = moduleEntityType(path) ?? (isMenuFile(path) ? "menu" : null);
|
|
322800
322991
|
const definition = type === null ? null : moduleUidDefinition(type, path, readFileSync13(join17(root, path), "utf8"));
|
|
322801
322992
|
if (definition !== null) {
|
|
322802
322993
|
moduleUidDefinitions.push(definition);
|
|
@@ -323171,6 +323362,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
|
|
|
323171
323362
|
if (files.includes(CONFIG_PATH2)) {
|
|
323172
323363
|
buildFile(CONFIG_PATH2);
|
|
323173
323364
|
}
|
|
323365
|
+
const workflows = readWorkflowReferences(root, otherFiles, diagnostics);
|
|
323174
323366
|
const notifications = buildNotifications(root, files, {
|
|
323175
323367
|
writeSource,
|
|
323176
323368
|
names: names2,
|
|
@@ -323178,12 +323370,13 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
|
|
|
323178
323370
|
builtInResources: BUILT_IN_RESOURCES,
|
|
323179
323371
|
recordBindingEntries: recordBindings.entries,
|
|
323180
323372
|
resourcesComplete,
|
|
323373
|
+
pages: generatedPages,
|
|
323374
|
+
workflows,
|
|
323181
323375
|
assets: assetsComplete ? output.assets : null,
|
|
323182
323376
|
assetCatalog,
|
|
323183
323377
|
diagnostics
|
|
323184
323378
|
});
|
|
323185
323379
|
const notificationCheck = notifications.check;
|
|
323186
|
-
const workflows = readWorkflowReferences(root, otherFiles, diagnostics);
|
|
323187
323380
|
writeGeneratedModule(
|
|
323188
323381
|
root,
|
|
323189
323382
|
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
|
-
*
|
|
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 = {
|