@extrahorizon/exh-cli 1.13.0-dev-178-60ea982 → 1.13.0-dev-180-80916a9
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/build/config-json-schemas/Dispatchers.json +14 -2
- package/build/exh.d.ts +1 -0
- package/build/exh.js +9 -1
- package/build/repositories/auth.d.ts +1 -1
- package/build/repositories/auth.js +1 -2
- package/build/services/dispatchers/sync.js +32 -7
- package/build/services/tasks/util.d.ts +2 -2
- package/package.json +1 -1
|
@@ -71,7 +71,11 @@
|
|
|
71
71
|
},
|
|
72
72
|
"MailAction": {
|
|
73
73
|
"type": "object",
|
|
74
|
-
"required": ["type", "name", "recipients"
|
|
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": {
|
|
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": {
|
package/build/exh.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
|
2
2
|
export declare function sdkInitOnly(apiHost: string, consumerKey: string, consumerSecret: string): OAuth1Client;
|
|
3
3
|
export declare function sdkAuth(): Promise<OAuth1Client>;
|
|
4
4
|
export declare function getSdk(): OAuth1Client;
|
|
5
|
+
export declare function getNewSdkInstance(): OAuth1Client;
|
package/build/exh.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSdk = exports.sdkAuth = exports.sdkInitOnly = void 0;
|
|
3
|
+
exports.getNewSdkInstance = exports.getSdk = exports.sdkAuth = exports.sdkInitOnly = void 0;
|
|
4
4
|
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
5
5
|
const util_1 = require("./helpers/util");
|
|
6
6
|
let sdk = null;
|
|
@@ -39,3 +39,11 @@ function getSdk() {
|
|
|
39
39
|
return sdk;
|
|
40
40
|
}
|
|
41
41
|
exports.getSdk = getSdk;
|
|
42
|
+
function getNewSdkInstance() {
|
|
43
|
+
return (0, javascript_sdk_1.createOAuth1Client)({
|
|
44
|
+
host: process.env.API_HOST,
|
|
45
|
+
consumerKey: process.env.API_OAUTH_CONSUMER_KEY,
|
|
46
|
+
consumerSecret: process.env.API_OAUTH_CONSUMER_SECRET,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.getNewSdkInstance = getNewSdkInstance;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function getHost(): string;
|
|
2
|
-
export declare function createOAuth1Tokens(email: string, password: string): Promise<
|
|
2
|
+
export declare function createOAuth1Tokens(email: string, password: string): Promise<import("@extrahorizon/javascript-sdk").TokenDataOauth1>;
|
|
3
3
|
export declare function fetchMe(): Promise<import("@extrahorizon/javascript-sdk").UserData>;
|
|
@@ -7,8 +7,7 @@ function getHost() {
|
|
|
7
7
|
}
|
|
8
8
|
exports.getHost = getHost;
|
|
9
9
|
async function createOAuth1Tokens(email, password) {
|
|
10
|
-
|
|
11
|
-
return response.data;
|
|
10
|
+
return (0, exh_1.getNewSdkInstance)().auth.authenticate({ email, password });
|
|
12
11
|
}
|
|
13
12
|
exports.createOAuth1Tokens = createOAuth1Tokens;
|
|
14
13
|
async function fetchMe() {
|
|
@@ -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
|
-
|
|
27
|
-
const
|
|
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(
|
|
30
|
+
await createDispatcher(dispatcherWithResolvedTemplateIds);
|
|
33
31
|
}
|
|
34
32
|
else {
|
|
35
|
-
await updateDispatcher(
|
|
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}`));
|