@diagonal-hq/cli 0.33.1 → 0.33.3
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 +5 -3
- package/dist/cli.mjs +74 -3
- package/dist/index.d.ts +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -237,7 +237,7 @@ export default defineConfig({
|
|
|
237
237
|
- `default_timezone` is an IANA timezone name, such as `America/Edmonton`. `default_currency` is a lower-case currency code, such as `cad`. `website` is a URL. `head_html` is at most 50,000 characters.
|
|
238
238
|
- Each `custom_<status>_error_page` setting names a page file by its uid, as `Pages.<Name>.uid` from `@app/generated/pages`. The page route must not have a parameter. The check refuses an unknown page, a page with a route parameter, and a value that is not a page uid, at the line of the setting. The deploy stores the setting as `{ id }` with the page uid, which is the page id. See [Page reference settings](#page-reference-settings).
|
|
239
239
|
- The check refuses `name`, `slug`, and `brand_kit` in `settings`, and any other key, at the line of the key. It also refuses a value that the setting does not accept.
|
|
240
|
-
- Each deploy writes `name` and every setting to the workspace. The file owns them: a setting that the file omits gets its default, for example `America/Chicago` or `usd`, and a setting without a default becomes `null`. A
|
|
240
|
+
- Each deploy writes `name` and every setting to the workspace. The file owns them: a setting that the file omits gets its default, for example `America/Chicago` or `usd`, and a setting without a default becomes `null`. A change to `name` or a setting in the admin settings, the API, the AI assistant, or the Control Panel commits to this file and deploys it.
|
|
241
241
|
- The deploy checks each value again with the rules of the workspace field. A value that fails, such as a timezone that the server does not know, stops the deploy, and the workspace keeps its values. The deploy checks an error page setting against the pages of the build instead, because a file page has no page row.
|
|
242
242
|
- A rollback writes the config of the older deployment. A deployment built before the deploy wrote the config writes nothing.
|
|
243
243
|
- `domains` declares the domains of the workspace, and `primaryDomain` names the one that is primary. See [Domains](#domains).
|
|
@@ -549,7 +549,7 @@ email-layouts/
|
|
|
549
549
|
default.json
|
|
550
550
|
```
|
|
551
551
|
|
|
552
|
-
The type sets the recipient resource, the variables, and the default template. The recipient resource maps the email and phone fields. A type without `recipient` sends to email addresses. A variable uses a `field` builder other than `field.relation`, or `{ resource }` for one record of a resource. Templates read a record variable's fields, for example `{{ first_event.name }}`.
|
|
552
|
+
The type sets the recipient resource, the variables, and the default template. The recipient resource maps the email and phone fields. A type without `recipient` sends to email addresses. `recipient.relations` lists the relation paths from the recipient resource whose records a send loads with the recipient. Templates read them below `record`, for example `{{ record.account.name }}`. A variable uses a `field` builder other than `field.relation`, or `{ resource }` for one record of a resource. Templates read a record variable's fields, for example `{{ first_event.name }}`.
|
|
553
553
|
|
|
554
554
|
```ts
|
|
555
555
|
import { NotificationTypes } from '@app/generated/notification-types';
|
|
@@ -559,7 +559,7 @@ import { defineNotificationType, field } from '@diagonal-hq/cli';
|
|
|
559
559
|
export default defineNotificationType({
|
|
560
560
|
uid: '019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e',
|
|
561
561
|
name: 'Member welcome',
|
|
562
|
-
recipient: { resource: Resources.Members.slug },
|
|
562
|
+
recipient: { resource: Resources.Members.slug, relations: ['account'] },
|
|
563
563
|
variables: {
|
|
564
564
|
joined_on: field.date({ label: 'Joined on', required: true }),
|
|
565
565
|
first_event: { resource: Resources.Events.slug, label: 'First event' }
|
|
@@ -719,6 +719,7 @@ The editor checks the shape of each definition. `diagonal check` and the build a
|
|
|
719
719
|
- Each type, template, and layout has a `uid` and a slug of at most 64 characters: its `slug` option, or the name of its folder or file. Each schedule has a `uid`. No two definitions of one kind have the same uid or the same slug, and no two templates of one type have the same slug. No two layouts have the same name. A `name` has 1 to 255 characters.
|
|
720
720
|
- A `{ file }` Liquid source names a `.liquid` file in the folder of the definition, and the file exists.
|
|
721
721
|
- A type's `recipient` resource and the resource of each record variable are resources of the workspace. A type has at most 100 variables. A variable key starts with a letter or `_` and has only letters, digits, and `_`. A variable cannot be named `record` or `ref`: templates read the recipient as `{{ record.* }}` and the generators as `{{ ref.* }}`. A variable is a value that the sender passes, so a `field` builder cannot have `default`, `unique`, `index`, `guard`, `computed`, `getter`, `setter`, or `setterWhenEmpty`.
|
|
722
|
+
- Each path in a type's `recipient.relations` follows relation fields from the recipient resource, for example `'account'` or `'account.owner'`. 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. A type has at most 100 paths, and no path twice.
|
|
722
723
|
- 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.
|
|
723
724
|
- A type has at least one template, and its `defaultTemplate` names one of them.
|
|
724
725
|
- 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.
|
|
@@ -739,6 +740,7 @@ A deploy writes each type, template, layout, and schedule into the workspace, ma
|
|
|
739
740
|
These rules need server data, so the check does not check them yet:
|
|
740
741
|
|
|
741
742
|
- A built-in `recipient` resource can receive notifications.
|
|
743
|
+
- The relation paths of `recipient.relations` past a built-in resource. A send checks them.
|
|
742
744
|
- The fields of a built-in resource. The deploy checks them.
|
|
743
745
|
- The field paths of a schedule's `filters`. The deploy does not check them either: a filter that names a field that does not exist deploys.
|
|
744
746
|
|
package/dist/cli.mjs
CHANGED
|
@@ -307773,6 +307773,7 @@ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
|
307773
307773
|
|
|
307774
307774
|
// scripts/lib/runtime-build/notification-values.mjs
|
|
307775
307775
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
307776
|
+
var RELATION_PATH_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*$/;
|
|
307776
307777
|
function isPlainObject3(value) {
|
|
307777
307778
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof FieldBuilderValue);
|
|
307778
307779
|
}
|
|
@@ -315078,7 +315079,6 @@ var MAX_VARIABLES = 100;
|
|
|
315078
315079
|
var RECIPIENT_MAX_LENGTH = 255;
|
|
315079
315080
|
var VARIABLE_PATH_MAX_LENGTH = 500;
|
|
315080
315081
|
var VARIABLE_PATH_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_.-]*$/;
|
|
315081
|
-
var RELATION_PATH_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*$/;
|
|
315082
315082
|
var DATE_FIELD_TYPES = ["date", "datetime", "event_schedule"];
|
|
315083
315083
|
var EXACT_TIMING_FIELD_TYPES2 = ["datetime", "event_schedule"];
|
|
315084
315084
|
var SINGULAR_RELATIONS = ["belongs_to", "has_one"];
|
|
@@ -315404,6 +315404,8 @@ var LABEL_MAX_LENGTH = 255;
|
|
|
315404
315404
|
var SUBJECT_MAX_LENGTH = 1e4;
|
|
315405
315405
|
var MAX_VARIABLES2 = 100;
|
|
315406
315406
|
var MAX_REFERENCES = 50;
|
|
315407
|
+
var MAX_RELATIONS = 100;
|
|
315408
|
+
var MAX_RELATION_PATH_DEPTH = 5;
|
|
315407
315409
|
var VARIABLE_KEY_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
315408
315410
|
var RESERVED_VARIABLE_KEYS = /* @__PURE__ */ new Set(["record", "ref"]);
|
|
315409
315411
|
var REFERENCE_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
@@ -315723,13 +315725,79 @@ function readVariables(value, node, report, context) {
|
|
|
315723
315725
|
}
|
|
315724
315726
|
return variables;
|
|
315725
315727
|
}
|
|
315728
|
+
function relationPathProblem2(path, resource, resourcesBySlug) {
|
|
315729
|
+
const segments = path.split(".");
|
|
315730
|
+
if (segments.length > MAX_RELATION_PATH_DEPTH) {
|
|
315731
|
+
return `"${path}" has more than ${MAX_RELATION_PATH_DEPTH} relations`;
|
|
315732
|
+
}
|
|
315733
|
+
const visited = [resource.slug];
|
|
315734
|
+
let current = resource;
|
|
315735
|
+
for (const [position, segment] of segments.entries()) {
|
|
315736
|
+
if (current === void 0) {
|
|
315737
|
+
return null;
|
|
315738
|
+
}
|
|
315739
|
+
const prefix2 = segments.slice(0, position + 1).join(".");
|
|
315740
|
+
const field2 = current.fields.find((item) => item.key === segment);
|
|
315741
|
+
if (field2 === void 0 || field2.type !== "relation") {
|
|
315742
|
+
return `"${prefix2}" is not a relation of "${current.slug}"`;
|
|
315743
|
+
}
|
|
315744
|
+
const next = field2.settings.resource;
|
|
315745
|
+
if (position < segments.length - 1 && visited.includes(next)) {
|
|
315746
|
+
return `"${prefix2}" returns to "${next}". A relation path passes through a resource only once`;
|
|
315747
|
+
}
|
|
315748
|
+
visited.push(next);
|
|
315749
|
+
current = resourcesBySlug.get(next);
|
|
315750
|
+
}
|
|
315751
|
+
return null;
|
|
315752
|
+
}
|
|
315753
|
+
function readRelations(recipient, resource, node, report, context) {
|
|
315754
|
+
if (recipient.relations === void 0) {
|
|
315755
|
+
return [];
|
|
315756
|
+
}
|
|
315757
|
+
const relationsNode = nodeAt(node, "relations");
|
|
315758
|
+
if (!Array.isArray(recipient.relations) || recipient.relations.length > MAX_RELATIONS) {
|
|
315759
|
+
report(
|
|
315760
|
+
relationsNode,
|
|
315761
|
+
`"recipient.relations" must be a list of at most ${MAX_RELATIONS} relation paths, for example ['company']`
|
|
315762
|
+
);
|
|
315763
|
+
return [];
|
|
315764
|
+
}
|
|
315765
|
+
const elements = unwrap(relationsNode)?.elements ?? [];
|
|
315766
|
+
const recipientResource = resource === null || context.resourcesBySlug === null ? void 0 : context.resourcesBySlug.get(resource);
|
|
315767
|
+
const relations = [];
|
|
315768
|
+
for (const [index3, path] of recipient.relations.entries()) {
|
|
315769
|
+
const pathNode = elements[index3] ?? relationsNode;
|
|
315770
|
+
if (typeof path !== "string" || !RELATION_PATH_PATTERN.test(path)) {
|
|
315771
|
+
report(
|
|
315772
|
+
pathNode,
|
|
315773
|
+
`"recipient.relations" holds paths of relation fields from the recipient, for example 'company.owner'`
|
|
315774
|
+
);
|
|
315775
|
+
continue;
|
|
315776
|
+
}
|
|
315777
|
+
if (relations.includes(path)) {
|
|
315778
|
+
report(pathNode, `"recipient.relations" has "${path}" twice`);
|
|
315779
|
+
continue;
|
|
315780
|
+
}
|
|
315781
|
+
const problem2 = recipientResource === void 0 ? null : relationPathProblem2(path, recipientResource, context.resourcesBySlug);
|
|
315782
|
+
if (problem2 !== null) {
|
|
315783
|
+
report(pathNode, `"recipient.relations": ${problem2}`);
|
|
315784
|
+
continue;
|
|
315785
|
+
}
|
|
315786
|
+
relations.push(path);
|
|
315787
|
+
}
|
|
315788
|
+
return relations;
|
|
315789
|
+
}
|
|
315726
315790
|
function buildType(file2, value, node, report, context) {
|
|
315727
315791
|
const identity = readIdentity(file2, "type", value, node, report);
|
|
315728
315792
|
let recipientResource = null;
|
|
315793
|
+
let recipientRelations = [];
|
|
315729
315794
|
if (value.recipient !== void 0) {
|
|
315730
315795
|
const recipientNode = nodeAt(node, "recipient");
|
|
315731
|
-
if (!isPlainObject3(value.recipient) || Object.keys(value.recipient).
|
|
315732
|
-
report(
|
|
315796
|
+
if (!isPlainObject3(value.recipient) || !Object.hasOwn(value.recipient, "resource") || Object.keys(value.recipient).some((key) => key !== "resource" && key !== "relations")) {
|
|
315797
|
+
report(
|
|
315798
|
+
recipientNode,
|
|
315799
|
+
'"recipient" must be { resource: Resources.<Name>.slug, relations?: [<relation path>] }'
|
|
315800
|
+
);
|
|
315733
315801
|
} else {
|
|
315734
315802
|
recipientResource = readResource(
|
|
315735
315803
|
value.recipient.resource,
|
|
@@ -315738,6 +315806,7 @@ function buildType(file2, value, node, report, context) {
|
|
|
315738
315806
|
'"recipient.resource"',
|
|
315739
315807
|
context
|
|
315740
315808
|
);
|
|
315809
|
+
recipientRelations = readRelations(value.recipient, recipientResource, recipientNode, report, context);
|
|
315741
315810
|
}
|
|
315742
315811
|
}
|
|
315743
315812
|
return {
|
|
@@ -315746,6 +315815,7 @@ function buildType(file2, value, node, report, context) {
|
|
|
315746
315815
|
...identity,
|
|
315747
315816
|
recipient_resource: recipientResource,
|
|
315748
315817
|
recipient_resource_uid: recipientResource === null ? null : resourceUid(recipientResource, context),
|
|
315818
|
+
recipient_relations: recipientRelations,
|
|
315749
315819
|
variables: readVariables(value, node, report, context),
|
|
315750
315820
|
defaultTemplate: readNamed(
|
|
315751
315821
|
value,
|
|
@@ -316235,6 +316305,7 @@ function checkNotificationFiles(files, {
|
|
|
316235
316305
|
name: type.name,
|
|
316236
316306
|
recipient_resource: type.recipient_resource,
|
|
316237
316307
|
recipient_resource_uid: type.recipient_resource_uid,
|
|
316308
|
+
recipient_relations: type.recipient_relations,
|
|
316238
316309
|
variables: type.variables,
|
|
316239
316310
|
default_template: defaultTemplate.uid
|
|
316240
316311
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1137,7 +1137,15 @@ export type NotificationTypeDefinition = UidOption & {
|
|
|
1137
1137
|
* The resource that receives the notification. The resource maps the email
|
|
1138
1138
|
* and phone fields. Leave it out to send to email addresses.
|
|
1139
1139
|
*/
|
|
1140
|
-
recipient?: {
|
|
1140
|
+
recipient?: {
|
|
1141
|
+
resource: ResourceReference;
|
|
1142
|
+
/**
|
|
1143
|
+
* The relation paths from the recipient resource whose records a send
|
|
1144
|
+
* loads with the recipient, for example `'company'` or `'company.owner'`.
|
|
1145
|
+
* Templates read them as `{{ record.company.name }}`.
|
|
1146
|
+
*/
|
|
1147
|
+
relations?: readonly string[];
|
|
1148
|
+
};
|
|
1141
1149
|
variables?: { readonly [key: string]: NotificationVariableDefinition };
|
|
1142
1150
|
defaultTemplate: NotificationTemplateReference;
|
|
1143
1151
|
};
|