@extrahorizon/exh-cli 1.13.0-dev-177-a0805f5 → 1.13.0-dev-179-ccdd0de

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.
@@ -71,7 +71,11 @@
71
71
  },
72
72
  "MailAction": {
73
73
  "type": "object",
74
- "required": ["type", "name", "recipients", "templateId"],
74
+ "required": ["type", "name", "recipients"],
75
+ "anyOf": [
76
+ { "required": ["templateId"] },
77
+ { "required": ["templateName"] }
78
+ ],
75
79
  "properties": {
76
80
  "type": { "const": "mail" },
77
81
  "name": { "type": "string" },
@@ -94,7 +98,15 @@
94
98
  }
95
99
  }
96
100
  },
97
- "templateId": { "type": "string" }
101
+ "templateId": {
102
+ "deprecated": true,
103
+ "description": "Deprecated, use templateName instead to target a V2 template by its name.",
104
+ "type": "string"
105
+ },
106
+ "templateName": {
107
+ "description": "The name of a V2 template",
108
+ "type": "string"
109
+ }
98
110
  }
99
111
  },
100
112
  "TaskAction": {
@@ -4,6 +4,7 @@ exports.sync = exports.cliManagedTag = void 0;
4
4
  const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
5
5
  const chalk_1 = require("chalk");
6
6
  const dispatcherRepository = require("../../repositories/dispatchers");
7
+ const templateRepository = require("../../repositories/templatesV2");
7
8
  const readDispatcherFile_1 = require("./util/readDispatcherFile");
8
9
  exports.cliManagedTag = 'EXH_CLI_MANAGED';
9
10
  async function sync(path, clean = false) {
@@ -23,17 +24,41 @@ async function sync(path, clean = false) {
23
24
  }
24
25
  exports.sync = sync;
25
26
  async function synchronizeDispatcher(localDispatcher, exhDispatcher) {
26
- localDispatcher.tags = localDispatcher.tags || [];
27
- const hasCliManagedTag = localDispatcher.tags.includes(exports.cliManagedTag);
28
- if (!hasCliManagedTag) {
29
- localDispatcher.tags.push(exports.cliManagedTag);
30
- }
27
+ const dispatcherWithTag = ensureCliManagedTag(localDispatcher);
28
+ const dispatcherWithResolvedTemplateIds = await resolveTemplateIds(dispatcherWithTag);
31
29
  if (!exhDispatcher) {
32
- await createDispatcher(localDispatcher);
30
+ await createDispatcher(dispatcherWithResolvedTemplateIds);
33
31
  }
34
32
  else {
35
- await updateDispatcher(localDispatcher, exhDispatcher);
33
+ await updateDispatcher(dispatcherWithResolvedTemplateIds, exhDispatcher);
34
+ }
35
+ }
36
+ function ensureCliManagedTag(dispatcher) {
37
+ const tags = dispatcher.tags ?? [];
38
+ if (tags.includes(exports.cliManagedTag)) {
39
+ return dispatcher;
40
+ }
41
+ return { ...dispatcher, tags: [...tags, exports.cliManagedTag] };
42
+ }
43
+ async function resolveTemplateIds(dispatcher) {
44
+ const resolvedActions = [];
45
+ for (const action of dispatcher.actions) {
46
+ if (action.type !== 'mail') {
47
+ resolvedActions.push(action);
48
+ continue;
49
+ }
50
+ const mailAction = action;
51
+ if (!mailAction.templateName) {
52
+ resolvedActions.push(action);
53
+ continue;
54
+ }
55
+ const template = await templateRepository.findByName(mailAction.templateName);
56
+ if (!template) {
57
+ throw new Error(`Template "${mailAction.templateName}" not found for Action "${action.name}"`);
58
+ }
59
+ resolvedActions.push({ ...action, templateId: template.id });
36
60
  }
61
+ return { ...dispatcher, actions: resolvedActions };
37
62
  }
38
63
  async function createDispatcher(dispatcher) {
39
64
  console.group((0, chalk_1.blue)(`Creating Dispatcher: ${dispatcher.name}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.13.0-dev-177-a0805f5",
3
+ "version": "1.13.0-dev-179-ccdd0de",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",