@contrail/cli 3.4.1 → 3.4.2
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 -4
- package/bin/dev +0 -0
- package/bin/run +0 -0
- package/dist/__mocks__/@contrail/sdk.d.ts +123 -123
- package/dist/__mocks__/@contrail/sdk.js +716 -716
- package/dist/api/app-extension-deployments.d.ts +2 -2
- package/dist/api/app-extension-deployments.js +11 -11
- package/dist/api/app-extension-packages.d.ts +2 -2
- package/dist/api/app-extension-packages.js +11 -11
- package/dist/api/apps.d.ts +10 -10
- package/dist/api/apps.js +63 -63
- package/dist/api/event-workflow-action-definition.d.ts +3 -3
- package/dist/api/event-workflow-action-definition.js +18 -18
- package/dist/api/event-workflow-template-definition.d.ts +7 -7
- package/dist/api/event-workflow-template-definition.js +26 -26
- package/dist/api/event-workflow-templates.d.ts +8 -8
- package/dist/api/event-workflow-templates.js +32 -32
- package/dist/api/schedules.d.ts +7 -7
- package/dist/api/schedules.js +32 -32
- package/dist/api/types.d.ts +11 -11
- package/dist/api/types.js +79 -79
- package/dist/api/users.d.ts +2 -2
- package/dist/api/users.js +18 -18
- package/dist/api/webhooks.d.ts +4 -4
- package/dist/api/webhooks.js +16 -16
- package/dist/auth/login.d.ts +3 -3
- package/dist/auth/login.js +221 -221
- package/dist/auth/login.spec.d.ts +1 -1
- package/dist/auth/login.spec.js +10 -10
- package/dist/baseFlags.d.ts +10 -10
- package/dist/baseFlags.js +25 -25
- package/dist/basecommand.d.ts +15 -15
- package/dist/basecommand.js +83 -83
- package/dist/commands/app/create.d.ts +10 -10
- package/dist/commands/app/create.js +96 -96
- package/dist/commands/app/delete.d.ts +11 -11
- package/dist/commands/app/delete.js +40 -40
- package/dist/commands/app/extension/deploy.d.ts +18 -18
- package/dist/commands/app/extension/deploy.js +127 -127
- package/dist/commands/app/extension/deployment/list.d.ts +14 -14
- package/dist/commands/app/extension/deployment/list.js +82 -82
- package/dist/commands/app/getApiKey.d.ts +11 -11
- package/dist/commands/app/getApiKey.js +49 -49
- package/dist/commands/app/init.d.ts +10 -10
- package/dist/commands/app/init.js +67 -67
- package/dist/commands/app/install.d.ts +13 -13
- package/dist/commands/app/install.js +135 -135
- package/dist/commands/app/publish.d.ts +14 -14
- package/dist/commands/app/publish.js +69 -69
- package/dist/commands/app/uninstall.d.ts +12 -12
- package/dist/commands/app/uninstall.js +68 -68
- package/dist/commands/app/upgrade.d.ts +14 -14
- package/dist/commands/app/upgrade.js +108 -108
- package/dist/commands/app/version/major.d.ts +11 -11
- package/dist/commands/app/version/major.js +39 -39
- package/dist/commands/app/version/minor.d.ts +11 -11
- package/dist/commands/app/version/minor.js +39 -39
- package/dist/commands/app/version/patch.d.ts +11 -11
- package/dist/commands/app/version/patch.js +39 -39
- package/dist/commands/config/create.d.ts +12 -12
- package/dist/commands/config/create.js +27 -27
- package/dist/commands/config/describe.d.ts +14 -14
- package/dist/commands/config/describe.js +46 -46
- package/dist/commands/config/list.d.ts +11 -11
- package/dist/commands/config/list.js +38 -38
- package/dist/commands/config/set.d.ts +16 -16
- package/dist/commands/config/set.js +46 -46
- package/dist/commands/config/use.d.ts +14 -14
- package/dist/commands/config/use.js +47 -47
- package/dist/commands/file/upload.d.ts +15 -15
- package/dist/commands/file/upload.js +69 -69
- package/dist/commands/groups/export.d.ts +14 -14
- package/dist/commands/groups/export.js +103 -103
- package/dist/commands/groups/import.d.ts +14 -14
- package/dist/commands/groups/import.js +190 -190
- package/dist/commands/instance/export.d.ts +12 -12
- package/dist/commands/instance/export.js +36 -36
- package/dist/commands/instance/import.d.ts +11 -11
- package/dist/commands/instance/import.js +34 -34
- package/dist/commands/load/colors.d.ts +14 -14
- package/dist/commands/load/colors.js +53 -53
- package/dist/commands/load/custom-entity.d.ts +14 -14
- package/dist/commands/load/custom-entity.js +55 -55
- package/dist/commands/load/line-sheet.d.ts +14 -14
- package/dist/commands/load/line-sheet.js +55 -55
- package/dist/commands/load/upload-and-load.d.ts +14 -14
- package/dist/commands/load/upload-and-load.js +46 -46
- package/dist/commands/projects/export.d.ts +13 -13
- package/dist/commands/projects/export.js +35 -35
- package/dist/commands/projects/list.d.ts +10 -10
- package/dist/commands/projects/list.js +36 -36
- package/dist/commands/projects/load.d.ts +25 -25
- package/dist/commands/projects/load.js +198 -198
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +11 -11
- package/dist/commands/types/exportOptionSetHierarchies.js +133 -133
- package/dist/commands/types/getAll.d.ts +21 -21
- package/dist/commands/types/getAll.js +180 -180
- package/dist/commands/types/getOptionSets.d.ts +16 -16
- package/dist/commands/types/getOptionSets.js +170 -170
- package/dist/commands/types/loadAll.d.ts +12 -12
- package/dist/commands/types/loadAll.js +55 -55
- package/dist/commands/types/mergeOptionSets.d.ts +13 -13
- package/dist/commands/types/mergeOptionSets.js +116 -119
- package/dist/commands/types/mergeTypeProperties.d.ts +15 -15
- package/dist/commands/types/mergeTypeProperties.js +95 -95
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +14 -14
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +133 -133
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +14 -14
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +102 -102
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +39 -39
- package/dist/commands/types/parseOptionSetsLocalFiles.js +229 -229
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +13 -13
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +68 -68
- package/dist/commands/types/parseTypesFromFiles.d.ts +14 -14
- package/dist/commands/types/parseTypesFromFiles.js +40 -40
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +14 -14
- package/dist/commands/types/parseTypesFromLocalFiles.js +37 -37
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +15 -15
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +39 -39
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +14 -14
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +38 -38
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +12 -12
- package/dist/commands/types/uploadOptionSetHierarchies.js +257 -257
- package/dist/commands/types/uploadOptionSets.d.ts +13 -13
- package/dist/commands/types/uploadOptionSets.js +155 -155
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +15 -15
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +135 -135
- package/dist/commands/types/uploadRuleSets.d.ts +12 -12
- package/dist/commands/types/uploadRuleSets.js +197 -197
- package/dist/commands/types/uploadTypePolicies.d.ts +12 -12
- package/dist/commands/types/uploadTypePolicies.js +233 -233
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +13 -13
- package/dist/commands/types/uploadTypePropertyPolicies.js +286 -286
- package/dist/commands/types/uploadTypes.d.ts +13 -13
- package/dist/commands/types/uploadTypes.js +35 -35
- package/dist/commands/types/uploadUsageInfo.d.ts +12 -12
- package/dist/commands/types/uploadUsageInfo.js +172 -172
- package/dist/commands/users/export.d.ts +14 -14
- package/dist/commands/users/export.js +76 -76
- package/dist/commands/users/import.d.ts +14 -14
- package/dist/commands/users/import.js +68 -68
- package/dist/commands/webhooks/create.d.ts +11 -11
- package/dist/commands/webhooks/create.js +25 -25
- package/dist/commands/webhooks/delete.d.ts +14 -14
- package/dist/commands/webhooks/delete.js +53 -53
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +13 -13
- package/dist/commands/webhooks/getWebhookTrigger.js +40 -40
- package/dist/commands/webhooks/list.d.ts +12 -12
- package/dist/commands/webhooks/list.js +31 -31
- package/dist/commands/workflow-template-definitions/install.d.ts +10 -10
- package/dist/commands/workflow-template-definitions/install.js +19 -19
- package/dist/commands/workflow-template-definitions/list.d.ts +10 -10
- package/dist/commands/workflow-template-definitions/list.js +19 -19
- package/dist/commands/workflow-templates/delete.d.ts +10 -10
- package/dist/commands/workflow-templates/delete.js +19 -19
- package/dist/commands/workflow-templates/export.d.ts +14 -14
- package/dist/commands/workflow-templates/export.js +78 -78
- package/dist/commands/workflow-templates/list.d.ts +10 -10
- package/dist/commands/workflow-templates/list.js +19 -19
- package/dist/commands/workflow-templates/load.d.ts +13 -13
- package/dist/commands/workflow-templates/load.js +26 -26
- package/dist/common.d.ts +4 -4
- package/dist/common.js +18 -18
- package/dist/helpers/app/actions-deployer.d.ts +11 -11
- package/dist/helpers/app/actions-deployer.js +123 -123
- package/dist/helpers/app/app-config-validators.d.ts +22 -22
- package/dist/helpers/app/app-config-validators.js +100 -100
- package/dist/helpers/app/app-config-validators.spec.d.ts +1 -1
- package/dist/helpers/app/app-config-validators.spec.js +310 -310
- package/dist/helpers/app/app-deployer.d.ts +12 -12
- package/dist/helpers/app/app-deployer.js +278 -278
- package/dist/helpers/app/app-template-parsers.d.ts +14 -14
- package/dist/helpers/app/app-template-parsers.js +106 -106
- package/dist/helpers/app/extension-package-deployer.d.ts +7 -7
- package/dist/helpers/app/extension-package-deployer.js +175 -175
- package/dist/helpers/app/extensions-deployer.d.ts +9 -9
- package/dist/helpers/app/extensions-deployer.js +95 -93
- package/dist/helpers/app/load-app-config.d.ts +4 -4
- package/dist/helpers/app/load-app-config.js +22 -22
- package/dist/helpers/app/metadata-extractor.d.ts +1 -1
- package/dist/helpers/app/metadata-extractor.js +100 -100
- package/dist/helpers/app/setup-template.d.ts +8 -8
- package/dist/helpers/app/setup-template.js +48 -48
- package/dist/helpers/app/update-app-config.d.ts +2 -2
- package/dist/helpers/app/update-app-config.js +20 -20
- package/dist/helpers/app/upgrade-version.d.ts +16 -16
- package/dist/helpers/app/upgrade-version.js +37 -37
- package/dist/helpers/app/upgrade-version.spec.d.ts +1 -1
- package/dist/helpers/app/upgrade-version.spec.js +33 -33
- package/dist/helpers/colors/helpers.d.ts +12 -12
- package/dist/helpers/colors/helpers.js +84 -84
- package/dist/helpers/config/config.d.ts +16 -16
- package/dist/helpers/config/config.js +223 -223
- package/dist/helpers/file-helpers.d.ts +2 -2
- package/dist/helpers/file-helpers.js +36 -36
- package/dist/helpers/load/helpers.d.ts +20 -20
- package/dist/helpers/load/helpers.js +141 -141
- package/dist/helpers/load/helpers.spec.d.ts +1 -1
- package/dist/helpers/load/helpers.spec.js +62 -62
- package/dist/helpers/load/validators.d.ts +14 -14
- package/dist/helpers/load/validators.js +182 -182
- package/dist/helpers/load/validators.spec.d.ts +1 -1
- package/dist/helpers/load/validators.spec.js +450 -450
- package/dist/helpers/projects/helpers.d.ts +3 -3
- package/dist/helpers/projects/helpers.js +167 -167
- package/dist/helpers/types/csv-parser.d.ts +1 -1
- package/dist/helpers/types/csv-parser.js +59 -59
- package/dist/helpers/types/option-set-helper.d.ts +9 -0
- package/dist/helpers/types/option-set-helper.js +48 -0
- package/dist/helpers/types/option-set-helper.spec.d.ts +1 -0
- package/dist/helpers/types/option-set-helper.spec.js +69 -0
- package/dist/helpers/types/parseOptionSetsLocalFiles.spec.d.ts +1 -1
- package/dist/helpers/types/parseOptionSetsLocalFiles.spec.js +285 -285
- package/dist/helpers/types/type-extractor.d.ts +1 -1
- package/dist/helpers/types/type-extractor.js +36 -36
- package/dist/helpers/types/type-parser.d.ts +4 -4
- package/dist/helpers/types/type-parser.js +119 -119
- package/dist/helpers/types/type-uploader.d.ts +20 -20
- package/dist/helpers/types/type-uploader.js +336 -336
- package/dist/helpers/types/type-uploader.spec.d.ts +1 -1
- package/dist/helpers/types/type-uploader.spec.js +266 -266
- package/dist/helpers/types/uploadOptionSets.spec.d.ts +1 -1
- package/dist/helpers/types/uploadOptionSets.spec.js +19 -19
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +158 -158
- package/dist/helpers/workflow-templates/helper.d.ts +20 -20
- package/dist/helpers/workflow-templates/helper.js +285 -285
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/interfaces.d.ts +445 -444
- package/dist/interfaces.js +163 -163
- package/dist/logger.d.ts +3 -3
- package/dist/logger.js +33 -33
- package/oclif.manifest.json +3 -3
- package/package.json +1 -1
|
@@ -1,285 +1,285 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.populateActionIdentifiers = exports.localDeployWorkflowTemplate = exports.deleteWorkflowTemplates = exports.WorkflowTemplateDeployer = exports.getActionByIdentifier = exports.getWorkflowTemplateIdentifier = exports.LocalWorkflowTemplateDeployer = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const util_1 = require("@contrail/util");
|
|
6
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
9
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
10
|
-
const path = tslib_1.__importStar(require("path"));
|
|
11
|
-
const apps_1 = require("../../api/apps");
|
|
12
|
-
const event_workflow_action_definition_1 = require("../../api/event-workflow-action-definition");
|
|
13
|
-
const event_workflow_templates_1 = require("../../api/event-workflow-templates");
|
|
14
|
-
const schedules_1 = require("../../api/schedules");
|
|
15
|
-
const login_1 = require("../../auth/login");
|
|
16
|
-
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
17
|
-
class LocalWorkflowTemplateDeployer {
|
|
18
|
-
async deployWorkflows(wtDeclaration) {
|
|
19
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
20
|
-
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
21
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
22
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Deploying workflow templates.`);
|
|
23
|
-
logger_1.default.info(wtDeclaration);
|
|
24
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
25
|
-
await this.deployWorkflowTemplate(wtDeclaration.workflows[workflowKey], existingWorkflows, wtDeclaration.appIdentifier);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async deployWorkflowTemplate(workflow, existingWorkflows, appIdentifier) {
|
|
29
|
-
logger_1.default.info(`WORKFLOW TEMPLATES \tDeploying workflow: ${workflow.triggerKey}`);
|
|
30
|
-
const identifier = getWorkflowTemplateIdentifier(workflow);
|
|
31
|
-
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
32
|
-
if (existingTemplate) {
|
|
33
|
-
return await this.updateWorkflowTemplate(identifier, existingTemplate, workflow, appIdentifier);
|
|
34
|
-
}
|
|
35
|
-
return await this.createNewWorkflowTemplate(identifier, workflow, appIdentifier);
|
|
36
|
-
}
|
|
37
|
-
async createNewWorkflowTemplate(workflowKey, workflowTemplate, appIdentifier) {
|
|
38
|
-
await this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
39
|
-
const newObject = {
|
|
40
|
-
identifier: getWorkflowTemplateIdentifier(workflowTemplate),
|
|
41
|
-
name: workflowTemplate.name,
|
|
42
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
43
|
-
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
44
|
-
isActive: workflowTemplate.isActive,
|
|
45
|
-
supportingAppId: workflowTemplate.supportingAppId,
|
|
46
|
-
messageGroupId: workflowTemplate.messageGroupId,
|
|
47
|
-
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
48
|
-
};
|
|
49
|
-
const newWorkflowTemplate = await (0, event_workflow_templates_1.createWorkflowTemplate)(newObject);
|
|
50
|
-
if (workflowTemplate.crons) {
|
|
51
|
-
await this.createWorkflowSchedule(workflowTemplate, newWorkflowTemplate.id);
|
|
52
|
-
}
|
|
53
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Creating new workflow template: ${workflowKey}`);
|
|
54
|
-
return newWorkflowTemplate;
|
|
55
|
-
}
|
|
56
|
-
async populateActionIds(workflowTemplate, workflowKey, appIdentifier) {
|
|
57
|
-
const installedApps = await (0, apps_1.getInstalledApps)();
|
|
58
|
-
const appOrg = installedApps.find((x) => x.app.identifier === appIdentifier);
|
|
59
|
-
logger_1.default.info('workflow template:', JSON.stringify(workflowTemplate, null, 2));
|
|
60
|
-
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
64
|
-
if (!path?.actionDefinitionConfigs) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
68
|
-
const actionKey = actionConfiguration.action;
|
|
69
|
-
try {
|
|
70
|
-
const actionIdentifier = util_1.AppUtil.createActionIdentifier({
|
|
71
|
-
actionNameIdentifier: actionKey,
|
|
72
|
-
appIdentifier,
|
|
73
|
-
versionId: appOrg.appVersionId,
|
|
74
|
-
});
|
|
75
|
-
const actionEntity = await getActionByIdentifier(actionIdentifier);
|
|
76
|
-
actionConfiguration.id = actionEntity.id;
|
|
77
|
-
actionConfiguration.identifier = actionEntity.identifier;
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
logger_1.default.info(e);
|
|
81
|
-
}
|
|
82
|
-
if (!actionConfiguration.id) {
|
|
83
|
-
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async createWorkflowSchedule(workflowTemplate, workflowId) {
|
|
89
|
-
if (!workflowTemplate?.crons?.length || !workflowTemplate.id) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const crons = [];
|
|
93
|
-
for (const cron of workflowTemplate.crons) {
|
|
94
|
-
crons.push(await (0, schedules_1.createSchedule)({
|
|
95
|
-
cron: cron.cron,
|
|
96
|
-
entityReference: `event-workflow-template:${workflowId}`,
|
|
97
|
-
name: cron.name,
|
|
98
|
-
requestMethod: 'POST',
|
|
99
|
-
entityName: 'event-workflow-request',
|
|
100
|
-
isActive: true,
|
|
101
|
-
payload: {
|
|
102
|
-
event: {},
|
|
103
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
104
|
-
},
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
return crons;
|
|
108
|
-
}
|
|
109
|
-
async updateWorkflowSchedule(workflowTemplate, workflowId) {
|
|
110
|
-
const existingSchedules = (await (0, schedules_1.getExistingSchedules)()).filter((x) => x?.ownerReference === `event-workflow-template:${workflowId}`) ?? [];
|
|
111
|
-
const newSchedules = workflowTemplate?.crons ?? [];
|
|
112
|
-
const existingCronNames = existingSchedules.map((x) => x.name) ?? [];
|
|
113
|
-
const newCronNames = newSchedules.map((x) => x.name) ?? [];
|
|
114
|
-
const cronsToAdd = newSchedules.filter((x) => !existingCronNames.includes(x.name));
|
|
115
|
-
const cronsToRemove = existingSchedules.filter((x) => !newCronNames.includes(x.name));
|
|
116
|
-
const cronsToEdit = existingSchedules.filter((x) => newCronNames.includes(x.name));
|
|
117
|
-
for (const cron of cronsToAdd) {
|
|
118
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Adding new schedule: ${cron.name}`);
|
|
119
|
-
await (0, schedules_1.createSchedule)({
|
|
120
|
-
cron: cron.cron,
|
|
121
|
-
entityReference: `event-workflow-template:${workflowId}`,
|
|
122
|
-
name: cron.name,
|
|
123
|
-
requestMethod: 'POST',
|
|
124
|
-
entityName: 'event-workflow-request',
|
|
125
|
-
isActive: true,
|
|
126
|
-
payload: {
|
|
127
|
-
event: {},
|
|
128
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
for (const cron of cronsToRemove) {
|
|
133
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Removing schedule: ${cron.name}`);
|
|
134
|
-
await (0, schedules_1.deleteSchedule)(cron.id);
|
|
135
|
-
}
|
|
136
|
-
for (const cron of cronsToEdit) {
|
|
137
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Updating schedule: ${cron.name}`);
|
|
138
|
-
const newCron = workflowTemplate.crons.find((x) => x.name === cron.name);
|
|
139
|
-
await (0, schedules_1.updateSchedule)({
|
|
140
|
-
id: cron.id,
|
|
141
|
-
updates: {
|
|
142
|
-
cron: newCron.cron,
|
|
143
|
-
requestMethod: 'POST',
|
|
144
|
-
entityName: 'event-workflow-request',
|
|
145
|
-
isActive: true,
|
|
146
|
-
payload: {
|
|
147
|
-
event: {},
|
|
148
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async updateWorkflowTemplate(workflowKey, existingWorkflowTemplate, workflowTemplate, appIdentifier) {
|
|
155
|
-
await this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
156
|
-
const updates = Object.assign(new Object(), {
|
|
157
|
-
name: workflowTemplate.name,
|
|
158
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
159
|
-
builtIn: workflowTemplate.builtIn,
|
|
160
|
-
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
161
|
-
dynamicMessageGroupId: workflowTemplate.dynamicMessageGroupId ?? existingWorkflowTemplate.dynamicMessageGroupId,
|
|
162
|
-
parallelWorkerCount: workflowTemplate.parallelWorkerCount ?? existingWorkflowTemplate.parallelWorkerCount,
|
|
163
|
-
});
|
|
164
|
-
const updatedWorkflowTemplate = await (0, event_workflow_templates_1.updateWorkflowTemplate)({
|
|
165
|
-
id: existingWorkflowTemplate.id,
|
|
166
|
-
updates,
|
|
167
|
-
});
|
|
168
|
-
await this.updateWorkflowSchedule(workflowTemplate, updatedWorkflowTemplate.id);
|
|
169
|
-
logger_1.default.info(`WORKFLOW TEMPLATES Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`);
|
|
170
|
-
return updatedWorkflowTemplate;
|
|
171
|
-
}
|
|
172
|
-
async deleteWorkflowTemplates(wtDeclaration) {
|
|
173
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
174
|
-
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
175
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
176
|
-
logger_1.default.info('WORKFLOW TEMPLATES \tDELETING workflow templates.');
|
|
177
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
178
|
-
const identifier = getWorkflowTemplateIdentifier(wtDeclaration.workflows[workflowKey]);
|
|
179
|
-
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
180
|
-
if (existingTemplate) {
|
|
181
|
-
try {
|
|
182
|
-
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(identifier);
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
logger_1.default.warn('WORKFLOW TEMPLATES \tFAILED to delete workflow template WORKFLOW TEMPLATES.', chalk_1.default.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
logger_1.default.info('WORKFLOW TEMPLATES \tUnable to locate workflow template WORKFLOW TEMPLATES.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.LocalWorkflowTemplateDeployer = LocalWorkflowTemplateDeployer;
|
|
195
|
-
function getWorkflowTemplateIdentifier(workflowTemplate) {
|
|
196
|
-
return workflowTemplate.identifier;
|
|
197
|
-
}
|
|
198
|
-
exports.getWorkflowTemplateIdentifier = getWorkflowTemplateIdentifier;
|
|
199
|
-
async function getActionByIdentifier(identifier) {
|
|
200
|
-
const result = await (0, event_workflow_action_definition_1.getEventWorkflowActionDefinition)({ identifier });
|
|
201
|
-
return result.length > 0 ? result[0] : {};
|
|
202
|
-
}
|
|
203
|
-
exports.getActionByIdentifier = getActionByIdentifier;
|
|
204
|
-
class WorkflowTemplateDeployer {
|
|
205
|
-
async deleteWorkflowTemplates() {
|
|
206
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
207
|
-
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
208
|
-
const answers = await inquirer_1.default.prompt([
|
|
209
|
-
{
|
|
210
|
-
type: 'checkbox',
|
|
211
|
-
name: 'wfTemplatesToDelete',
|
|
212
|
-
message: 'Which templates would you like to delete (one or more)?',
|
|
213
|
-
choices: existingWorkflows.map((x) => {
|
|
214
|
-
return { value: x.id, name: `(${x.createdOn}) ${x.name}` };
|
|
215
|
-
}),
|
|
216
|
-
},
|
|
217
|
-
]);
|
|
218
|
-
for (const idToDelete of answers.wfTemplatesToDelete) {
|
|
219
|
-
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(idToDelete);
|
|
220
|
-
}
|
|
221
|
-
logger_1.default.info('WORKFLOW TEMPLATES \tDeleted workflow templates!');
|
|
222
|
-
}
|
|
223
|
-
async listExistingWorkflowTemplates() {
|
|
224
|
-
const templates = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
225
|
-
logger_1.default.info('(Date Created) (active) workflow name');
|
|
226
|
-
logger_1.default.info('------------------------');
|
|
227
|
-
logger_1.default.info(chalk_1.default.green.bold(templates
|
|
228
|
-
.map((x) => `(${x.createdOn}) (${x.isActive ? 'active' : 'inactive'}) ${x.name} `)
|
|
229
|
-
.join('\n')));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.WorkflowTemplateDeployer = WorkflowTemplateDeployer;
|
|
233
|
-
async function deleteWorkflowTemplates() {
|
|
234
|
-
await (0, login_1.authUser)();
|
|
235
|
-
await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
|
|
236
|
-
}
|
|
237
|
-
exports.deleteWorkflowTemplates = deleteWorkflowTemplates;
|
|
238
|
-
async function localDeployWorkflowTemplate(saveFileLocation) {
|
|
239
|
-
let wtDeclaration;
|
|
240
|
-
try {
|
|
241
|
-
wtDeclaration = loadTemplateConfig(saveFileLocation);
|
|
242
|
-
}
|
|
243
|
-
catch (e) {
|
|
244
|
-
logger_1.default.error(`FAIL Workflow Deletion Failed . ${e}`);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
await (0, login_1.authUser)();
|
|
248
|
-
await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
249
|
-
}
|
|
250
|
-
exports.localDeployWorkflowTemplate = localDeployWorkflowTemplate;
|
|
251
|
-
function loadTemplateConfig(saveFile) {
|
|
252
|
-
const TARGET_DIR = process.cwd();
|
|
253
|
-
try {
|
|
254
|
-
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.resolve(path.join(TARGET_DIR, saveFile)), 'utf8'));
|
|
255
|
-
return doc;
|
|
256
|
-
}
|
|
257
|
-
catch (e) {
|
|
258
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function populateActionIdentifiers(workflowTemplate) {
|
|
262
|
-
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
266
|
-
if (!path?.actionDefinitionConfigs) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
270
|
-
const actionId = actionConfiguration.id;
|
|
271
|
-
try {
|
|
272
|
-
const actionEntity = await (0, event_workflow_action_definition_1.getEventWorkflowActionDefinitionById)(actionId);
|
|
273
|
-
actionConfiguration.action = actionEntity.identifier;
|
|
274
|
-
delete actionConfiguration.id;
|
|
275
|
-
}
|
|
276
|
-
catch (e) {
|
|
277
|
-
logger_1.default.info(e);
|
|
278
|
-
}
|
|
279
|
-
if (!actionConfiguration.action) {
|
|
280
|
-
throw new Error(`Could not find action ${actionId}`);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
exports.populateActionIdentifiers = populateActionIdentifiers;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.populateActionIdentifiers = exports.localDeployWorkflowTemplate = exports.deleteWorkflowTemplates = exports.WorkflowTemplateDeployer = exports.getActionByIdentifier = exports.getWorkflowTemplateIdentifier = exports.LocalWorkflowTemplateDeployer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const util_1 = require("@contrail/util");
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
9
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const apps_1 = require("../../api/apps");
|
|
12
|
+
const event_workflow_action_definition_1 = require("../../api/event-workflow-action-definition");
|
|
13
|
+
const event_workflow_templates_1 = require("../../api/event-workflow-templates");
|
|
14
|
+
const schedules_1 = require("../../api/schedules");
|
|
15
|
+
const login_1 = require("../../auth/login");
|
|
16
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
17
|
+
class LocalWorkflowTemplateDeployer {
|
|
18
|
+
async deployWorkflows(wtDeclaration) {
|
|
19
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
20
|
+
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
21
|
+
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
22
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Deploying workflow templates.`);
|
|
23
|
+
logger_1.default.info(wtDeclaration);
|
|
24
|
+
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
25
|
+
await this.deployWorkflowTemplate(wtDeclaration.workflows[workflowKey], existingWorkflows, wtDeclaration.appIdentifier);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async deployWorkflowTemplate(workflow, existingWorkflows, appIdentifier) {
|
|
29
|
+
logger_1.default.info(`WORKFLOW TEMPLATES \tDeploying workflow: ${workflow.triggerKey}`);
|
|
30
|
+
const identifier = getWorkflowTemplateIdentifier(workflow);
|
|
31
|
+
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
32
|
+
if (existingTemplate) {
|
|
33
|
+
return await this.updateWorkflowTemplate(identifier, existingTemplate, workflow, appIdentifier);
|
|
34
|
+
}
|
|
35
|
+
return await this.createNewWorkflowTemplate(identifier, workflow, appIdentifier);
|
|
36
|
+
}
|
|
37
|
+
async createNewWorkflowTemplate(workflowKey, workflowTemplate, appIdentifier) {
|
|
38
|
+
await this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
39
|
+
const newObject = {
|
|
40
|
+
identifier: getWorkflowTemplateIdentifier(workflowTemplate),
|
|
41
|
+
name: workflowTemplate.name,
|
|
42
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
43
|
+
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
44
|
+
isActive: workflowTemplate.isActive,
|
|
45
|
+
supportingAppId: workflowTemplate.supportingAppId,
|
|
46
|
+
messageGroupId: workflowTemplate.messageGroupId,
|
|
47
|
+
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
48
|
+
};
|
|
49
|
+
const newWorkflowTemplate = await (0, event_workflow_templates_1.createWorkflowTemplate)(newObject);
|
|
50
|
+
if (workflowTemplate.crons) {
|
|
51
|
+
await this.createWorkflowSchedule(workflowTemplate, newWorkflowTemplate.id);
|
|
52
|
+
}
|
|
53
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Creating new workflow template: ${workflowKey}`);
|
|
54
|
+
return newWorkflowTemplate;
|
|
55
|
+
}
|
|
56
|
+
async populateActionIds(workflowTemplate, workflowKey, appIdentifier) {
|
|
57
|
+
const installedApps = await (0, apps_1.getInstalledApps)();
|
|
58
|
+
const appOrg = installedApps.find((x) => x.app.identifier === appIdentifier);
|
|
59
|
+
logger_1.default.info('workflow template:', JSON.stringify(workflowTemplate, null, 2));
|
|
60
|
+
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
64
|
+
if (!path?.actionDefinitionConfigs) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
68
|
+
const actionKey = actionConfiguration.action;
|
|
69
|
+
try {
|
|
70
|
+
const actionIdentifier = util_1.AppUtil.createActionIdentifier({
|
|
71
|
+
actionNameIdentifier: actionKey,
|
|
72
|
+
appIdentifier,
|
|
73
|
+
versionId: appOrg.appVersionId,
|
|
74
|
+
});
|
|
75
|
+
const actionEntity = await getActionByIdentifier(actionIdentifier);
|
|
76
|
+
actionConfiguration.id = actionEntity.id;
|
|
77
|
+
actionConfiguration.identifier = actionEntity.identifier;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
logger_1.default.info(e);
|
|
81
|
+
}
|
|
82
|
+
if (!actionConfiguration.id) {
|
|
83
|
+
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async createWorkflowSchedule(workflowTemplate, workflowId) {
|
|
89
|
+
if (!workflowTemplate?.crons?.length || !workflowTemplate.id) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const crons = [];
|
|
93
|
+
for (const cron of workflowTemplate.crons) {
|
|
94
|
+
crons.push(await (0, schedules_1.createSchedule)({
|
|
95
|
+
cron: cron.cron,
|
|
96
|
+
entityReference: `event-workflow-template:${workflowId}`,
|
|
97
|
+
name: cron.name,
|
|
98
|
+
requestMethod: 'POST',
|
|
99
|
+
entityName: 'event-workflow-request',
|
|
100
|
+
isActive: true,
|
|
101
|
+
payload: {
|
|
102
|
+
event: {},
|
|
103
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
104
|
+
},
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
return crons;
|
|
108
|
+
}
|
|
109
|
+
async updateWorkflowSchedule(workflowTemplate, workflowId) {
|
|
110
|
+
const existingSchedules = (await (0, schedules_1.getExistingSchedules)()).filter((x) => x?.ownerReference === `event-workflow-template:${workflowId}`) ?? [];
|
|
111
|
+
const newSchedules = workflowTemplate?.crons ?? [];
|
|
112
|
+
const existingCronNames = existingSchedules.map((x) => x.name) ?? [];
|
|
113
|
+
const newCronNames = newSchedules.map((x) => x.name) ?? [];
|
|
114
|
+
const cronsToAdd = newSchedules.filter((x) => !existingCronNames.includes(x.name));
|
|
115
|
+
const cronsToRemove = existingSchedules.filter((x) => !newCronNames.includes(x.name));
|
|
116
|
+
const cronsToEdit = existingSchedules.filter((x) => newCronNames.includes(x.name));
|
|
117
|
+
for (const cron of cronsToAdd) {
|
|
118
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Adding new schedule: ${cron.name}`);
|
|
119
|
+
await (0, schedules_1.createSchedule)({
|
|
120
|
+
cron: cron.cron,
|
|
121
|
+
entityReference: `event-workflow-template:${workflowId}`,
|
|
122
|
+
name: cron.name,
|
|
123
|
+
requestMethod: 'POST',
|
|
124
|
+
entityName: 'event-workflow-request',
|
|
125
|
+
isActive: true,
|
|
126
|
+
payload: {
|
|
127
|
+
event: {},
|
|
128
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
for (const cron of cronsToRemove) {
|
|
133
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Removing schedule: ${cron.name}`);
|
|
134
|
+
await (0, schedules_1.deleteSchedule)(cron.id);
|
|
135
|
+
}
|
|
136
|
+
for (const cron of cronsToEdit) {
|
|
137
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Updating schedule: ${cron.name}`);
|
|
138
|
+
const newCron = workflowTemplate.crons.find((x) => x.name === cron.name);
|
|
139
|
+
await (0, schedules_1.updateSchedule)({
|
|
140
|
+
id: cron.id,
|
|
141
|
+
updates: {
|
|
142
|
+
cron: newCron.cron,
|
|
143
|
+
requestMethod: 'POST',
|
|
144
|
+
entityName: 'event-workflow-request',
|
|
145
|
+
isActive: true,
|
|
146
|
+
payload: {
|
|
147
|
+
event: {},
|
|
148
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async updateWorkflowTemplate(workflowKey, existingWorkflowTemplate, workflowTemplate, appIdentifier) {
|
|
155
|
+
await this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
156
|
+
const updates = Object.assign(new Object(), {
|
|
157
|
+
name: workflowTemplate.name,
|
|
158
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
159
|
+
builtIn: workflowTemplate.builtIn,
|
|
160
|
+
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
161
|
+
dynamicMessageGroupId: workflowTemplate.dynamicMessageGroupId ?? existingWorkflowTemplate.dynamicMessageGroupId,
|
|
162
|
+
parallelWorkerCount: workflowTemplate.parallelWorkerCount ?? existingWorkflowTemplate.parallelWorkerCount,
|
|
163
|
+
});
|
|
164
|
+
const updatedWorkflowTemplate = await (0, event_workflow_templates_1.updateWorkflowTemplate)({
|
|
165
|
+
id: existingWorkflowTemplate.id,
|
|
166
|
+
updates,
|
|
167
|
+
});
|
|
168
|
+
await this.updateWorkflowSchedule(workflowTemplate, updatedWorkflowTemplate.id);
|
|
169
|
+
logger_1.default.info(`WORKFLOW TEMPLATES Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`);
|
|
170
|
+
return updatedWorkflowTemplate;
|
|
171
|
+
}
|
|
172
|
+
async deleteWorkflowTemplates(wtDeclaration) {
|
|
173
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
174
|
+
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
175
|
+
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
176
|
+
logger_1.default.info('WORKFLOW TEMPLATES \tDELETING workflow templates.');
|
|
177
|
+
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
178
|
+
const identifier = getWorkflowTemplateIdentifier(wtDeclaration.workflows[workflowKey]);
|
|
179
|
+
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
180
|
+
if (existingTemplate) {
|
|
181
|
+
try {
|
|
182
|
+
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(identifier);
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
logger_1.default.warn('WORKFLOW TEMPLATES \tFAILED to delete workflow template WORKFLOW TEMPLATES.', chalk_1.default.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
logger_1.default.info('WORKFLOW TEMPLATES \tUnable to locate workflow template WORKFLOW TEMPLATES.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.LocalWorkflowTemplateDeployer = LocalWorkflowTemplateDeployer;
|
|
195
|
+
function getWorkflowTemplateIdentifier(workflowTemplate) {
|
|
196
|
+
return workflowTemplate.identifier;
|
|
197
|
+
}
|
|
198
|
+
exports.getWorkflowTemplateIdentifier = getWorkflowTemplateIdentifier;
|
|
199
|
+
async function getActionByIdentifier(identifier) {
|
|
200
|
+
const result = await (0, event_workflow_action_definition_1.getEventWorkflowActionDefinition)({ identifier });
|
|
201
|
+
return result.length > 0 ? result[0] : {};
|
|
202
|
+
}
|
|
203
|
+
exports.getActionByIdentifier = getActionByIdentifier;
|
|
204
|
+
class WorkflowTemplateDeployer {
|
|
205
|
+
async deleteWorkflowTemplates() {
|
|
206
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
207
|
+
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
208
|
+
const answers = await inquirer_1.default.prompt([
|
|
209
|
+
{
|
|
210
|
+
type: 'checkbox',
|
|
211
|
+
name: 'wfTemplatesToDelete',
|
|
212
|
+
message: 'Which templates would you like to delete (one or more)?',
|
|
213
|
+
choices: existingWorkflows.map((x) => {
|
|
214
|
+
return { value: x.id, name: `(${x.createdOn}) ${x.name}` };
|
|
215
|
+
}),
|
|
216
|
+
},
|
|
217
|
+
]);
|
|
218
|
+
for (const idToDelete of answers.wfTemplatesToDelete) {
|
|
219
|
+
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(idToDelete);
|
|
220
|
+
}
|
|
221
|
+
logger_1.default.info('WORKFLOW TEMPLATES \tDeleted workflow templates!');
|
|
222
|
+
}
|
|
223
|
+
async listExistingWorkflowTemplates() {
|
|
224
|
+
const templates = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
225
|
+
logger_1.default.info('(Date Created) (active) workflow name');
|
|
226
|
+
logger_1.default.info('------------------------');
|
|
227
|
+
logger_1.default.info(chalk_1.default.green.bold(templates
|
|
228
|
+
.map((x) => `(${x.createdOn}) (${x.isActive ? 'active' : 'inactive'}) ${x.name} `)
|
|
229
|
+
.join('\n')));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.WorkflowTemplateDeployer = WorkflowTemplateDeployer;
|
|
233
|
+
async function deleteWorkflowTemplates() {
|
|
234
|
+
await (0, login_1.authUser)();
|
|
235
|
+
await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
|
|
236
|
+
}
|
|
237
|
+
exports.deleteWorkflowTemplates = deleteWorkflowTemplates;
|
|
238
|
+
async function localDeployWorkflowTemplate(saveFileLocation) {
|
|
239
|
+
let wtDeclaration;
|
|
240
|
+
try {
|
|
241
|
+
wtDeclaration = loadTemplateConfig(saveFileLocation);
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
logger_1.default.error(`FAIL Workflow Deletion Failed . ${e}`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
await (0, login_1.authUser)();
|
|
248
|
+
await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
249
|
+
}
|
|
250
|
+
exports.localDeployWorkflowTemplate = localDeployWorkflowTemplate;
|
|
251
|
+
function loadTemplateConfig(saveFile) {
|
|
252
|
+
const TARGET_DIR = process.cwd();
|
|
253
|
+
try {
|
|
254
|
+
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.resolve(path.join(TARGET_DIR, saveFile)), 'utf8'));
|
|
255
|
+
return doc;
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function populateActionIdentifiers(workflowTemplate) {
|
|
262
|
+
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
266
|
+
if (!path?.actionDefinitionConfigs) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
270
|
+
const actionId = actionConfiguration.id;
|
|
271
|
+
try {
|
|
272
|
+
const actionEntity = await (0, event_workflow_action_definition_1.getEventWorkflowActionDefinitionById)(actionId);
|
|
273
|
+
actionConfiguration.action = actionEntity.identifier;
|
|
274
|
+
delete actionConfiguration.id;
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
logger_1.default.info(e);
|
|
278
|
+
}
|
|
279
|
+
if (!actionConfiguration.action) {
|
|
280
|
+
throw new Error(`Could not find action ${actionId}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.populateActionIdentifiers = populateActionIdentifiers;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { run } from '@oclif/core';
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.run = void 0;
|
|
4
|
-
var core_1 = require("@oclif/core");
|
|
5
|
-
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
var core_1 = require("@oclif/core");
|
|
5
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
|