@extrahorizon/exh-cli 1.5.0
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/CHANGELOG.md +53 -0
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/build/commands/completion.d.ts +5 -0
- package/build/commands/completion.js +38 -0
- package/build/commands/data/schemas/delete.d.ts +10 -0
- package/build/commands/data/schemas/delete.js +29 -0
- package/build/commands/data/schemas/list.d.ts +8 -0
- package/build/commands/data/schemas/list.js +20 -0
- package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -0
- package/build/commands/data/schemas/sync/statusHelpers.js +49 -0
- package/build/commands/data/schemas/sync.d.ts +35 -0
- package/build/commands/data/schemas/sync.js +72 -0
- package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -0
- package/build/commands/data/schemas/util/listFilesInDir.js +25 -0
- package/build/commands/data/schemas/util/metaschema.json +455 -0
- package/build/commands/data/schemas/util/readJson.d.ts +1 -0
- package/build/commands/data/schemas/util/readJson.js +11 -0
- package/build/commands/data/schemas/util/schemaverify.d.ts +28 -0
- package/build/commands/data/schemas/util/schemaverify.js +202 -0
- package/build/commands/data/schemas/util/syncSchema.d.ts +20 -0
- package/build/commands/data/schemas/util/syncSchema.js +276 -0
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -0
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -0
- package/build/commands/data/schemas/verify.d.ts +18 -0
- package/build/commands/data/schemas/verify.js +82 -0
- package/build/commands/data/schemas.d.ts +5 -0
- package/build/commands/data/schemas.js +10 -0
- package/build/commands/data.d.ts +5 -0
- package/build/commands/data.js +10 -0
- package/build/commands/dispatchers/sync.d.ts +21 -0
- package/build/commands/dispatchers/sync.js +24 -0
- package/build/commands/dispatchers.d.ts +5 -0
- package/build/commands/dispatchers.js +10 -0
- package/build/commands/login.d.ts +37 -0
- package/build/commands/login.js +59 -0
- package/build/commands/sync.d.ts +55 -0
- package/build/commands/sync.js +107 -0
- package/build/commands/tasks/createrepo.d.ts +22 -0
- package/build/commands/tasks/createrepo.js +70 -0
- package/build/commands/tasks/delete.d.ts +10 -0
- package/build/commands/tasks/delete.js +29 -0
- package/build/commands/tasks/list.d.ts +8 -0
- package/build/commands/tasks/list.js +27 -0
- package/build/commands/tasks/sync.d.ts +56 -0
- package/build/commands/tasks/sync.js +122 -0
- package/build/commands/tasks/taskConfig.d.ts +24 -0
- package/build/commands/tasks/taskConfig.js +169 -0
- package/build/commands/tasks/util.d.ts +1 -0
- package/build/commands/tasks/util.js +27 -0
- package/build/commands/tasks.d.ts +5 -0
- package/build/commands/tasks.js +10 -0
- package/build/commands/templates/delete.d.ts +19 -0
- package/build/commands/templates/delete.js +48 -0
- package/build/commands/templates/get.d.ts +19 -0
- package/build/commands/templates/get.js +37 -0
- package/build/commands/templates/list.d.ts +9 -0
- package/build/commands/templates/list.js +25 -0
- package/build/commands/templates/sync.d.ts +22 -0
- package/build/commands/templates/sync.js +65 -0
- package/build/commands/templates/util/buildTemplates.d.ts +2 -0
- package/build/commands/templates/util/buildTemplates.js +50 -0
- package/build/commands/templates/util/readTemplateFiles.d.ts +3 -0
- package/build/commands/templates/util/readTemplateFiles.js +52 -0
- package/build/commands/templates/util/templateService.d.ts +8 -0
- package/build/commands/templates/util/templateService.js +18 -0
- package/build/commands/templates/util/uploadTemplate.d.ts +2 -0
- package/build/commands/templates/util/uploadTemplate.js +20 -0
- package/build/commands/templates/util/utils.d.ts +4 -0
- package/build/commands/templates/util/utils.js +22 -0
- package/build/commands/templates.d.ts +5 -0
- package/build/commands/templates.js +10 -0
- package/build/constants.d.ts +13 -0
- package/build/constants.js +37 -0
- package/build/exh.d.ts +3 -0
- package/build/exh.js +65 -0
- package/build/helpers/error.d.ts +2 -0
- package/build/helpers/error.js +6 -0
- package/build/helpers/repoConfig.d.ts +2 -0
- package/build/helpers/repoConfig.js +60 -0
- package/build/helpers/util.d.ts +3 -0
- package/build/helpers/util.js +36 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +33 -0
- package/build/repositories/dispatchers.d.ts +8 -0
- package/build/repositories/dispatchers.js +31 -0
- package/build/repositories/functions.d.ts +24 -0
- package/build/repositories/functions.js +28 -0
- package/build/repositories/schemas.d.ts +44 -0
- package/build/repositories/schemas.js +86 -0
- package/build/services/dispatchers.d.ts +3 -0
- package/build/services/dispatchers.js +132 -0
- package/package.json +53 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteIndex = exports.createIndex = exports.deleteTransition = exports.updateTransition = exports.createTransition = exports.updateCreationTransition = exports.deleteStatus = exports.updateStatus = exports.createStatus = exports.deleteProperty = exports.updateProperty = exports.createProperty = exports.updateSchema = exports.createSchema = exports.fetchSchemaByName = exports.disable = exports.remove = void 0;
|
|
4
|
+
async function remove(sdk, schemaId) {
|
|
5
|
+
return await sdk.data.schemas.remove(schemaId);
|
|
6
|
+
}
|
|
7
|
+
exports.remove = remove;
|
|
8
|
+
async function disable(sdk, schemaId) {
|
|
9
|
+
return await sdk.data.schemas.disable(schemaId);
|
|
10
|
+
}
|
|
11
|
+
exports.disable = disable;
|
|
12
|
+
async function fetchSchemaByName(sdk, name) {
|
|
13
|
+
return await sdk.data.schemas.findByName(name);
|
|
14
|
+
}
|
|
15
|
+
exports.fetchSchemaByName = fetchSchemaByName;
|
|
16
|
+
async function createSchema(sdk, name, description) {
|
|
17
|
+
return await sdk.data.schemas.create({
|
|
18
|
+
name,
|
|
19
|
+
description,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.createSchema = createSchema;
|
|
23
|
+
async function updateSchema(sdk, id, data) {
|
|
24
|
+
return await sdk.data.schemas.update(id, data);
|
|
25
|
+
}
|
|
26
|
+
exports.updateSchema = updateSchema;
|
|
27
|
+
async function createProperty(sdk, id, data) {
|
|
28
|
+
const response = await sdk.raw.post(`/data/v1/${id}/properties`, data);
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
31
|
+
exports.createProperty = createProperty;
|
|
32
|
+
async function updateProperty(sdk, id, path, data) {
|
|
33
|
+
const response = await sdk.raw.put(`/data/v1/${id}/properties/${path}`, data);
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
|
+
exports.updateProperty = updateProperty;
|
|
37
|
+
async function deleteProperty(sdk, id, path) {
|
|
38
|
+
const response = await sdk.raw.delete(`/data/v1/${id}/properties/${path}`);
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
exports.deleteProperty = deleteProperty;
|
|
42
|
+
async function createStatus(sdk, id, name, data) {
|
|
43
|
+
const response = await sdk.raw.post(`/data/v1/${id}/statuses`, { name, data });
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
exports.createStatus = createStatus;
|
|
47
|
+
async function updateStatus(sdk, id, name, data) {
|
|
48
|
+
const response = await sdk.raw.put(`/data/v1/${id}/statuses/${name}`, { data });
|
|
49
|
+
return response.data;
|
|
50
|
+
}
|
|
51
|
+
exports.updateStatus = updateStatus;
|
|
52
|
+
async function deleteStatus(sdk, id, name) {
|
|
53
|
+
const response = await sdk.raw.delete(`/data/v1/${id}/statuses/${name}`);
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
exports.deleteStatus = deleteStatus;
|
|
57
|
+
async function updateCreationTransition(sdk, id, data) {
|
|
58
|
+
const response = await sdk.raw.put(`/data/v1/${id}/creationTransition`, data);
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
exports.updateCreationTransition = updateCreationTransition;
|
|
62
|
+
async function createTransition(sdk, id, data) {
|
|
63
|
+
const response = await sdk.raw.post(`/data/v1/${id}/transitions`, data);
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
exports.createTransition = createTransition;
|
|
67
|
+
async function updateTransition(sdk, schemaId, transitionId, data) {
|
|
68
|
+
const response = await sdk.raw.put(`/data/v1/${schemaId}/transitions/${transitionId}`, data);
|
|
69
|
+
return response.data;
|
|
70
|
+
}
|
|
71
|
+
exports.updateTransition = updateTransition;
|
|
72
|
+
async function deleteTransition(sdk, schemaId, transitionId) {
|
|
73
|
+
const response = await sdk.raw.delete(`/data/v1/${schemaId}/transitions/${transitionId}`);
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
exports.deleteTransition = deleteTransition;
|
|
77
|
+
async function createIndex(sdk, schemaId, index) {
|
|
78
|
+
const response = await sdk.raw.post(`/data/v1/${schemaId}/indexes`, index);
|
|
79
|
+
return response.data;
|
|
80
|
+
}
|
|
81
|
+
exports.createIndex = createIndex;
|
|
82
|
+
async function deleteIndex(sdk, schemaId, indexId) {
|
|
83
|
+
const response = await sdk.raw.delete(`/data/v1/${schemaId}/indexes/${indexId}`);
|
|
84
|
+
return response.data;
|
|
85
|
+
}
|
|
86
|
+
exports.deleteIndex = deleteIndex;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = exports.cliManagedTag = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
6
|
+
const chalk_1 = require("chalk");
|
|
7
|
+
const dispatcherRepository = require("../repositories/dispatchers");
|
|
8
|
+
exports.cliManagedTag = 'EXH_CLI_MANAGED';
|
|
9
|
+
async function sync(sdk, path, clean = false) {
|
|
10
|
+
console.log((0, chalk_1.yellow)(`Synchronizing Dispatchers from ${path}`));
|
|
11
|
+
const localDispatchers = await extractDispatchersFromFile(path);
|
|
12
|
+
const rql = (0, javascript_sdk_1.rqlBuilder)().eq('tags', exports.cliManagedTag).build();
|
|
13
|
+
const exhDispatchers = await dispatcherRepository.findAll(sdk, rql);
|
|
14
|
+
validateDispatchers(localDispatchers);
|
|
15
|
+
console.group((0, chalk_1.blue)('Synchronizing Dispatchers:'));
|
|
16
|
+
for (const localDispatcher of localDispatchers) {
|
|
17
|
+
const exhDispatcher = exhDispatchers.find(({ name }) => name === localDispatcher.name);
|
|
18
|
+
await synchronizeDispatcher(sdk, localDispatcher, exhDispatcher);
|
|
19
|
+
}
|
|
20
|
+
if (clean) {
|
|
21
|
+
await removeDispatchers(sdk, localDispatchers, exhDispatchers);
|
|
22
|
+
}
|
|
23
|
+
console.groupEnd();
|
|
24
|
+
}
|
|
25
|
+
exports.sync = sync;
|
|
26
|
+
async function synchronizeDispatcher(sdk, localDispatcher, exhDispatcher) {
|
|
27
|
+
localDispatcher.tags = localDispatcher.tags || [];
|
|
28
|
+
const hasCliManagedTag = localDispatcher.tags.includes(exports.cliManagedTag);
|
|
29
|
+
if (!hasCliManagedTag) {
|
|
30
|
+
localDispatcher.tags.push(exports.cliManagedTag);
|
|
31
|
+
}
|
|
32
|
+
if (!exhDispatcher) {
|
|
33
|
+
await createDispatcher(sdk, localDispatcher);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await updateDispatcher(sdk, localDispatcher, exhDispatcher);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function createDispatcher(sdk, dispatcher) {
|
|
40
|
+
console.group((0, chalk_1.blue)(`Creating Dispatcher: ${dispatcher.name}`));
|
|
41
|
+
await dispatcherRepository.create(sdk, dispatcher);
|
|
42
|
+
for (const action of dispatcher.actions) {
|
|
43
|
+
console.log((0, chalk_1.green)(`✓ Action: ${action.name}`));
|
|
44
|
+
}
|
|
45
|
+
console.groupEnd();
|
|
46
|
+
console.log((0, chalk_1.green)(`✓ Created Dispatcher: ${dispatcher.name}`));
|
|
47
|
+
}
|
|
48
|
+
async function updateDispatcher(sdk, localDispatcher, exhDispatcher) {
|
|
49
|
+
console.group((0, chalk_1.blue)(`Updating Dispatcher: ${localDispatcher.name}`));
|
|
50
|
+
await dispatcherRepository.update(sdk, exhDispatcher.id, localDispatcher);
|
|
51
|
+
await synchronizeActions(sdk, localDispatcher, exhDispatcher);
|
|
52
|
+
console.groupEnd();
|
|
53
|
+
console.log((0, chalk_1.green)(`✓ Updated Dispatcher: ${localDispatcher.name}`));
|
|
54
|
+
}
|
|
55
|
+
async function removeDispatchers(sdk, localDispatchers, exhDispatchers) {
|
|
56
|
+
for (const exhDispatcher of exhDispatchers) {
|
|
57
|
+
const localDispatcher = localDispatchers.find(({ name }) => name === exhDispatcher.name);
|
|
58
|
+
if (!localDispatcher) {
|
|
59
|
+
console.log((0, chalk_1.blue)(`Deleting Dispatcher: ${exhDispatcher.name}`));
|
|
60
|
+
await dispatcherRepository.remove(sdk, exhDispatcher.id);
|
|
61
|
+
console.log((0, chalk_1.green)(`✓ Deleted Dispatcher: ${exhDispatcher.name}`));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function synchronizeActions(sdk, localDispatcher, exhDispatcher) {
|
|
66
|
+
for (const localAction of localDispatcher.actions) {
|
|
67
|
+
const exhAction = exhDispatcher.actions.find(({ name }) => name === localAction.name);
|
|
68
|
+
if (!exhAction) {
|
|
69
|
+
console.log((0, chalk_1.yellow)(`Creating Action: ${localAction.name}`));
|
|
70
|
+
await dispatcherRepository.createAction(sdk, exhDispatcher.id, localAction);
|
|
71
|
+
console.log((0, chalk_1.green)(`✓ Created Action: ${localAction.name}`));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log((0, chalk_1.yellow)(`Updating Action: ${localAction.name}`));
|
|
75
|
+
await dispatcherRepository.updateAction(sdk, exhDispatcher.id, exhAction.id, localAction);
|
|
76
|
+
console.log((0, chalk_1.green)(`✓ Updated Action: ${localAction.name}`));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const exhAction of exhDispatcher.actions) {
|
|
80
|
+
const actionExistsLocally = localDispatcher.actions.find(({ name }) => name === exhAction.name);
|
|
81
|
+
if (!actionExistsLocally) {
|
|
82
|
+
console.group((0, chalk_1.blue)(`Deleting Action: ${exhAction.name}`));
|
|
83
|
+
await dispatcherRepository.removeAction(sdk, exhDispatcher.id, exhAction.id);
|
|
84
|
+
console.log((0, chalk_1.green)(`✓ Deleted Action: ${exhAction.name}`));
|
|
85
|
+
console.groupEnd();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function extractDispatchersFromFile(path) {
|
|
90
|
+
try {
|
|
91
|
+
const data = await (0, promises_1.readFile)(path);
|
|
92
|
+
return JSON.parse(data.toString());
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new Error(`Failed to read Dispatchers from ${path}: ${error.message}`);
|
|
96
|
+
}
|
|
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');
|
|
131
|
+
}
|
|
132
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@extrahorizon/exh-cli",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"main": "build/index.js",
|
|
5
|
+
"exports": "./build/index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "ExtraHorizon",
|
|
8
|
+
"homepage": "https://docs.extrahorizon.com/cli/",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ExtraHorizon/exh-cli.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "yarn test",
|
|
15
|
+
"clean": "rimraf build",
|
|
16
|
+
"build": "yarn clean && tsc",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"lint": "eslint src tests --ext .ts"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"exh": "./build/index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"build/"
|
|
25
|
+
],
|
|
26
|
+
"preferGlobal": true,
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@extrahorizon/eslint-config-node": "1.6.0",
|
|
29
|
+
"@types/dotenv-safe": "^8.1.2",
|
|
30
|
+
"@types/jest": "^29.5.11",
|
|
31
|
+
"@types/lodash": "^4.14.182",
|
|
32
|
+
"@types/node": "^18.0.0",
|
|
33
|
+
"@types/yargs": "^17.0.10",
|
|
34
|
+
"dotenv-safe": "^8.2.0",
|
|
35
|
+
"eslint": "^8.18.0",
|
|
36
|
+
"jest": "^29.7.0",
|
|
37
|
+
"mock-fs": "^5.1.2",
|
|
38
|
+
"rimraf": "^3.0.2",
|
|
39
|
+
"ts-jest": "^29.1.1",
|
|
40
|
+
"typescript": "4.5.5"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@extrahorizon/javascript-sdk": "^8.2.0",
|
|
44
|
+
"ajv": "^8.11.0",
|
|
45
|
+
"archiver": "^5.3.1",
|
|
46
|
+
"chalk": "^4.0.0",
|
|
47
|
+
"joi": "^17.6.0",
|
|
48
|
+
"lodash": "^4.17.21",
|
|
49
|
+
"update-notifier": "^5.1.0",
|
|
50
|
+
"uuid": "^8.3.2",
|
|
51
|
+
"yargs": "^17.5.1"
|
|
52
|
+
}
|
|
53
|
+
}
|