@extrahorizon/exh-cli 1.12.0-dev-146-310460f → 1.12.0-dev-148-901fb95

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.
@@ -0,0 +1,120 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "allOf": [
4
+ {
5
+ "oneOf": [
6
+ { "type": "array" },
7
+ { "type": "object" }
8
+ ]
9
+ },
10
+ {
11
+ "if": { "type": "object" },
12
+ "then": { "$ref": "#/definitions/Wrapper" }
13
+ },
14
+ {
15
+ "if": { "type": "array" },
16
+ "then": {
17
+ "type": "array",
18
+ "items": { "$ref": "#/definitions/Dispatcher" }
19
+ }
20
+ }
21
+ ],
22
+ "definitions": {
23
+ "Wrapper": {
24
+ "type": "object",
25
+ "required": ["dispatchers"],
26
+ "properties": {
27
+ "dispatchers": {
28
+ "type": "array",
29
+ "items": { "$ref": "#/definitions/Dispatcher" }
30
+ },
31
+ "$schema": { "type": "string" }
32
+ }
33
+ },
34
+ "Dispatcher": {
35
+ "type": "object",
36
+ "required": ["eventType", "name", "actions"],
37
+ "properties": {
38
+ "eventType": { "type": "string" },
39
+ "name": { "type": "string" },
40
+ "description": { "type": "string" },
41
+ "actions": {
42
+ "type": "array",
43
+ "minItems": 1,
44
+ "items": { "$ref": "#/definitions/Action" }
45
+ },
46
+ "tags": {
47
+ "type": "array",
48
+ "items": { "type": "string" }
49
+ }
50
+ }
51
+ },
52
+ "Action": {
53
+ "type": "object",
54
+ "required": ["type"],
55
+ "properties": {
56
+ "type": {
57
+ "type": "string",
58
+ "enum": ["mail", "task"]
59
+ }
60
+ },
61
+ "allOf": [
62
+ {
63
+ "if": { "properties": { "type": { "const": "mail" } } },
64
+ "then": { "$ref": "#/definitions/MailAction" }
65
+ },
66
+ {
67
+ "if": { "properties": { "type": { "const": "task" } } },
68
+ "then": { "$ref": "#/definitions/TaskAction" }
69
+ }
70
+ ]
71
+ },
72
+ "MailAction": {
73
+ "type": "object",
74
+ "required": ["type", "name", "recipients", "templateId"],
75
+ "properties": {
76
+ "type": { "const": "mail" },
77
+ "name": { "type": "string" },
78
+ "description": { "type": "string" },
79
+ "recipients": {
80
+ "type": "object",
81
+ "required": ["to"],
82
+ "properties": {
83
+ "to": {
84
+ "type": "array",
85
+ "items": { "type": "string" }
86
+ },
87
+ "cc": {
88
+ "type": "array",
89
+ "items": { "type": "string" }
90
+ },
91
+ "bcc": {
92
+ "type": "array",
93
+ "items": { "type": "string" }
94
+ }
95
+ }
96
+ },
97
+ "templateId": { "type": "string" }
98
+ }
99
+ },
100
+ "TaskAction": {
101
+ "type": "object",
102
+ "required": ["type", "name", "functionName"],
103
+ "properties": {
104
+ "type": { "const": "task" },
105
+ "name": { "type": "string" },
106
+ "description": { "type": "string" },
107
+ "functionName": { "type": "string" },
108
+ "data": {
109
+ "type": "object",
110
+ "additionalProperties": true
111
+ },
112
+ "tags": {
113
+ "type": "array",
114
+ "items": { "type": "string" }
115
+ },
116
+ "startTimestamp": { "type": "string" }
117
+ }
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,261 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "if": {
4
+ "description": "Try to determine if we have V1 schema",
5
+ "anyOf": [
6
+ {
7
+ "type": "object",
8
+ "required": ["version"],
9
+ "properties": { "version": { "const": 1 } }
10
+ },
11
+ {
12
+ "type": "object",
13
+ "required": ["schema"],
14
+ "properties": {
15
+ "version": { "const": 1 },
16
+ "schema": true
17
+ }
18
+ },
19
+ {
20
+ "type": "object",
21
+ "required": ["fields"],
22
+ "properties": {
23
+ "version": { "const": 1 },
24
+ "fields": true
25
+ }
26
+ }
27
+ ]
28
+ },
29
+ "then": { "$ref": "#/definitions/TemplateV1" },
30
+ "else": { "$ref": "#/definitions/TemplateV2" },
31
+ "definitions": {
32
+ "TemplateV2": {
33
+ "type": "object",
34
+ "additionalProperties": false,
35
+ "properties": {
36
+ "version": { "const": 2 },
37
+ "$schema": { "type": "string" },
38
+ "description": { "type": "string" },
39
+ "extendsTemplate": { "type": "string" },
40
+ "properties": {
41
+ "type": "object",
42
+ "additionalProperties": { "$ref": "#/definitions/TypeConfigurationV2" }
43
+ },
44
+ "outputs": {
45
+ "type": "object",
46
+ "additionalProperties": { "type": "string" }
47
+ }
48
+ }
49
+ },
50
+ "TypeConfigurationV2": {
51
+ "type": "object",
52
+ "required": ["type"],
53
+ "properties": {
54
+ "type": { "enum": ["object", "array", "string", "number", "boolean"] }
55
+ },
56
+ "allOf": [
57
+ {
58
+ "if": {
59
+ "type": "object",
60
+ "properties": {
61
+ "type": { "const": "object" }
62
+ }
63
+ },
64
+ "then": { "$ref": "#/definitions/ObjectConfigurationV2" }
65
+ },
66
+ {
67
+ "if": {
68
+ "type": "object",
69
+ "properties": {
70
+ "type": { "const": "array" }
71
+ }
72
+ },
73
+ "then": { "$ref": "#/definitions/ArrayConfigurationV2" }
74
+ },
75
+ {
76
+ "if": {
77
+ "type": "object",
78
+ "properties": {
79
+ "type": { "const": "string" }
80
+ }
81
+ },
82
+ "then": { "$ref": "#/definitions/StringConfigurationV2" }
83
+ },
84
+ {
85
+ "if": {
86
+ "type": "object",
87
+ "properties": {
88
+ "type": { "const": "number" }
89
+ }
90
+ },
91
+ "then": { "$ref": "#/definitions/NumberConfigurationV2" }
92
+ },
93
+ {
94
+ "if": {
95
+ "type": "object",
96
+ "properties": {
97
+ "type": { "const": "boolean" }
98
+ }
99
+ },
100
+ "then": { "$ref": "#/definitions/BooleanConfigurationV2" }
101
+ }
102
+ ]
103
+ },
104
+ "ObjectConfigurationV2": {
105
+ "type": "object",
106
+ "additionalProperties": false,
107
+ "required": ["type", "properties"],
108
+ "properties": {
109
+ "type": { "const": "object" },
110
+ "properties": {
111
+ "type": "object",
112
+ "additionalProperties": { "$ref": "#/definitions/TypeConfigurationV2" }
113
+ }
114
+ }
115
+ },
116
+ "ArrayConfigurationV2": {
117
+ "type": "object",
118
+ "additionalProperties": false,
119
+ "required": ["type", "items"],
120
+ "properties": {
121
+ "type": { "const": "array" },
122
+ "items": { "$ref": "#/definitions/TypeConfigurationV2" }
123
+ }
124
+ },
125
+ "StringConfigurationV2": {
126
+ "type": "object",
127
+ "additionalProperties": false,
128
+ "required": ["type"],
129
+ "properties": {
130
+ "type": { "const": "string" }
131
+ }
132
+ },
133
+ "NumberConfigurationV2": {
134
+ "type": "object",
135
+ "additionalProperties": false,
136
+ "required": ["type"],
137
+ "properties": {
138
+ "type": { "const": "number" }
139
+ }
140
+ },
141
+ "BooleanConfigurationV2": {
142
+ "type": "object",
143
+ "additionalProperties": false,
144
+ "required": ["type"],
145
+ "properties": {
146
+ "type": { "const": "boolean" }
147
+ }
148
+ },
149
+ "TemplateV1": {
150
+ "type": "object",
151
+ "required": ["description", "schema", "fields"],
152
+ "properties": {
153
+ "version": { "const": 1 },
154
+ "$schema": { "type": "string" },
155
+ "extends_template": { "type": "string" },
156
+ "description": { "type": "string" },
157
+ "schema": { "$ref": "#/definitions/ObjectConfiguration" },
158
+ "fields": {
159
+ "type": "object",
160
+ "additionalProperties": { "type": "string" }
161
+ }
162
+ }
163
+ },
164
+ "TypeConfiguration": {
165
+ "type": "object",
166
+ "required": ["type"],
167
+ "properties": {
168
+ "type": { "enum": ["object", "array", "string", "number", "boolean"] }
169
+ },
170
+ "allOf": [
171
+ {
172
+ "if": {
173
+ "type": "object",
174
+ "properties": {
175
+ "type": { "const": "object" }
176
+ }
177
+ },
178
+ "then": { "$ref": "#/definitions/ObjectConfiguration" }
179
+ },
180
+ {
181
+ "if": {
182
+ "type": "object",
183
+ "properties": {
184
+ "type": { "const": "array" }
185
+ }
186
+ },
187
+ "then": { "$ref": "#/definitions/ArrayConfiguration" }
188
+ },
189
+ {
190
+ "if": {
191
+ "type": "object",
192
+ "properties": {
193
+ "type": { "const": "string" }
194
+ }
195
+ },
196
+ "then": { "$ref": "#/definitions/StringConfiguration" }
197
+ },
198
+ {
199
+ "if": {
200
+ "type": "object",
201
+ "properties": {
202
+ "type": { "const": "number" }
203
+ }
204
+ },
205
+ "then": { "$ref": "#/definitions/NumberConfiguration" }
206
+ },
207
+ {
208
+ "if": {
209
+ "type": "object",
210
+ "properties": {
211
+ "type": { "const": "boolean" }
212
+ }
213
+ },
214
+ "then": { "$ref": "#/definitions/BooleanConfiguration" }
215
+ }
216
+ ]
217
+ },
218
+ "ObjectConfiguration": {
219
+ "type": "object",
220
+ "required": ["type"],
221
+ "properties": {
222
+ "type": { "const": "object" },
223
+ "fields": {
224
+ "type": "object",
225
+ "additionalProperties": {
226
+ "$ref": "#/definitions/TypeConfiguration"
227
+ }
228
+ }
229
+ }
230
+ },
231
+ "ArrayConfiguration": {
232
+ "type": "object",
233
+ "required": ["type", "type_configuration"],
234
+ "properties": {
235
+ "type": { "const": "array" },
236
+ "type_configuration": { "$ref": "#/definitions/TypeConfiguration" }
237
+ }
238
+ },
239
+ "StringConfiguration": {
240
+ "type": "object",
241
+ "required": ["type"],
242
+ "properties": {
243
+ "type": { "const": "string" }
244
+ }
245
+ },
246
+ "NumberConfiguration": {
247
+ "type": "object",
248
+ "required": ["type"],
249
+ "properties": {
250
+ "type": { "const": "number" }
251
+ }
252
+ },
253
+ "BooleanConfiguration": {
254
+ "type": "object",
255
+ "required": ["type"],
256
+ "properties": {
257
+ "type": { "const": "boolean" }
258
+ }
259
+ }
260
+ }
261
+ }
@@ -4,14 +4,15 @@ exports.sync = exports.cliManagedTag = void 0;
4
4
  const promises_1 = require("fs/promises");
5
5
  const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
6
6
  const chalk_1 = require("chalk");
7
+ const dispatcherSchema = require("../config-json-schemas/Dispatchers.json");
8
+ const util_1 = require("../helpers/util");
7
9
  const dispatcherRepository = require("../repositories/dispatchers");
8
10
  exports.cliManagedTag = 'EXH_CLI_MANAGED';
9
11
  async function sync(path, clean = false) {
10
12
  console.log((0, chalk_1.yellow)(`Synchronizing Dispatchers from ${path}`));
11
- const localDispatchers = await extractDispatchersFromFile(path);
13
+ const localDispatchers = await readAndValidateDispatcherConfig(path);
12
14
  const rql = (0, javascript_sdk_1.rqlBuilder)().eq('tags', exports.cliManagedTag).build();
13
15
  const exhDispatchers = await dispatcherRepository.findAll(rql);
14
- validateDispatchers(localDispatchers);
15
16
  console.group((0, chalk_1.blue)('Synchronizing Dispatchers:'));
16
17
  for (const localDispatcher of localDispatchers) {
17
18
  const exhDispatcher = exhDispatchers.find(({ name }) => name === localDispatcher.name);
@@ -86,47 +87,18 @@ async function synchronizeActions(localDispatcher, exhDispatcher) {
86
87
  }
87
88
  }
88
89
  }
89
- async function extractDispatchersFromFile(path) {
90
+ async function readAndValidateDispatcherConfig(path) {
91
+ let config;
90
92
  try {
91
- const data = await (0, promises_1.readFile)(path);
92
- return JSON.parse(data.toString());
93
+ const buffer = await (0, promises_1.readFile)(path);
94
+ config = JSON.parse(buffer.toString());
93
95
  }
94
96
  catch (error) {
95
97
  throw new Error(`Failed to read Dispatchers from ${path}: ${error.message}`);
96
98
  }
97
- }
98
- function validateDispatchers(dispatchers) {
99
- let hasErrors = false;
100
- console.group((0, chalk_1.blue)('Validating Dispatchers:'));
101
- dispatchers.forEach((dispatcher, index) => {
102
- const displayName = dispatcher.name ? `[${index}]: ${dispatcher.name}` : `[${index}]: NO_NAME`;
103
- const errors = [];
104
- if (!dispatcher.name) {
105
- errors.push('No name');
106
- }
107
- const hasActions = Array.isArray(dispatcher.actions) && dispatcher.actions.length > 0;
108
- if (!hasActions) {
109
- errors.push('The actions value need to be an array with at least one object in it');
110
- }
111
- else {
112
- dispatcher.actions.forEach((action, actionIndex) => {
113
- if (!action.name) {
114
- errors.push(`Action [${actionIndex}] does not have a name`);
115
- }
116
- });
117
- }
118
- if (errors.length === 0) {
119
- console.log((0, chalk_1.green)(`✓ Valid Dispatcher: ${displayName}`));
120
- }
121
- else {
122
- hasErrors = true;
123
- console.group((0, chalk_1.red)(`𝖷 Invalid Dispatcher: ${displayName}`));
124
- errors.forEach(error => console.log((0, chalk_1.red)(`- ${error}`)));
125
- console.groupEnd();
126
- }
127
- });
128
- console.groupEnd();
129
- if (hasErrors) {
130
- throw new Error('\nThe dispatchers file is invalid');
99
+ (0, util_1.ajvValidate)(dispatcherSchema, config);
100
+ if (Array.isArray(config)) {
101
+ return config;
131
102
  }
103
+ return config.dispatchers;
132
104
  }
@@ -14,7 +14,7 @@ async function sync(path, template) {
14
14
  }
15
15
  let templ = null;
16
16
  if (fs.statSync(ospath.join(process.cwd(), template)).isFile()) {
17
- templ = await (0, readTemplateFiles_1.readTemplateJson)(template);
17
+ templ = await (0, readTemplateFiles_1.readAndValidateTemplateJson)(template);
18
18
  }
19
19
  else {
20
20
  templ = await (0, readTemplateFiles_1.readTemplateFolder)(template);
@@ -0,0 +1,12 @@
1
+ import type { TemplateCreation, TemplateV2Creation } from '@extrahorizon/javascript-sdk';
2
+ export declare type TemplateConfig = TemplateV1Config | TemplateV2Config;
3
+ export interface TemplateV1Config extends TemplateCreation {
4
+ version?: 1;
5
+ $schema?: string;
6
+ extends_template?: string;
7
+ }
8
+ export interface TemplateV2Config extends TemplateV2Creation {
9
+ version?: 2;
10
+ $schema?: string;
11
+ extendsTemplate?: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ import type { TemplateConfig } from './models';
1
2
  export declare function readTemplateFiles(targetFolder: string): Promise<{}>;
2
- export declare function readTemplateJson(fileName: string): Promise<any>;
3
- export declare function readTemplateFolder(subFolder: string): Promise<any>;
3
+ export declare function readAndValidateTemplateJson(fileName: string): Promise<TemplateConfig>;
4
+ export declare function readTemplateFolder(subFolder: string): Promise<TemplateConfig>;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readTemplateFolder = exports.readTemplateJson = exports.readTemplateFiles = void 0;
3
+ exports.readTemplateFolder = exports.readAndValidateTemplateJson = exports.readTemplateFiles = void 0;
4
4
  const fs = require("fs/promises");
5
5
  const path = require("path");
6
+ const templateConfigSchema = require("../../../config-json-schemas/Template.json");
7
+ const util_1 = require("../../../helpers/util");
6
8
  const utils_1 = require("./utils");
7
9
  async function readTemplateFiles(targetFolder) {
8
10
  const fileNames = await (0, utils_1.listFolderContent)(targetFolder);
@@ -14,18 +16,25 @@ async function readTemplateFiles(targetFolder) {
14
16
  }
15
17
  else if (fileName.endsWith('.json')) {
16
18
  const templateName = (0, utils_1.removeFileNameExtension)(fileName);
17
- templateFilesByName[templateName] = await readTemplateJson(filePath);
19
+ templateFilesByName[templateName] = await readAndValidateTemplateJson(filePath);
18
20
  }
19
21
  }
20
22
  return templateFilesByName;
21
23
  }
22
24
  exports.readTemplateFiles = readTemplateFiles;
23
- async function readTemplateJson(fileName) {
24
- return (0, utils_1.readJsonFile)(fileName);
25
+ async function readAndValidateTemplateJson(fileName) {
26
+ try {
27
+ const content = await (0, utils_1.readJsonFile)(fileName);
28
+ (0, util_1.ajvValidate)(templateConfigSchema, content);
29
+ return content;
30
+ }
31
+ catch (error) {
32
+ throw new Error(`Error while reading template file ${fileName}: ${error.message}`);
33
+ }
25
34
  }
26
- exports.readTemplateJson = readTemplateJson;
35
+ exports.readAndValidateTemplateJson = readAndValidateTemplateJson;
27
36
  async function readTemplateFolder(subFolder) {
28
- const templateFile = await readTemplateJson(path.join(subFolder, 'template.json'));
37
+ const templateFile = await readAndValidateTemplateJson(path.join(subFolder, 'template.json'));
29
38
  const extraFiles = await readExtraTemplateFolderFiles(subFolder);
30
39
  if ((0, utils_1.isV1Template)(templateFile)) {
31
40
  templateFile.fields = {
@@ -1,5 +1,6 @@
1
+ import type { TemplateV1Config } from './models';
1
2
  export declare function listFolderContent(path: string): Promise<string[]>;
2
3
  export declare function readJsonFile(path: string): Promise<any>;
3
4
  export declare function readTextFile(path: string): Promise<string>;
4
5
  export declare function removeFileNameExtension(fileName: string): string;
5
- export declare function isV1Template(template: any): boolean;
6
+ export declare function isV1Template(template: any): template is TemplateV1Config;
@@ -21,6 +21,8 @@ function removeFileNameExtension(fileName) {
21
21
  }
22
22
  exports.removeFileNameExtension = removeFileNameExtension;
23
23
  function isV1Template(template) {
24
- return !!template.schema || !!template.fields;
24
+ return (template.version === 1 ||
25
+ !!template.schema ||
26
+ !!template.fields);
25
27
  }
26
28
  exports.isV1Template = isV1Template;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.12.0-dev-146-310460f",
3
+ "version": "1.12.0-dev-148-901fb95",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",