@contrail/cli 1.0.39 → 1.0.40

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.
Files changed (50) hide show
  1. package/lib/api/apps.d.ts +13 -0
  2. package/lib/api/apps.js +85 -0
  3. package/lib/api/event-workflow-action-definition.d.ts +1 -0
  4. package/lib/api/event-workflow-action-definition.js +7 -0
  5. package/lib/api/event-workflow-template-definition.d.ts +5 -0
  6. package/lib/api/event-workflow-template-definition.js +14 -0
  7. package/lib/api/event-workflow-templates.d.ts +7 -0
  8. package/lib/api/event-workflow-templates.js +25 -0
  9. package/lib/apps/deploy-app/app-deployer.js +4 -17
  10. package/lib/apps/deploy-app/workflow-definition-deployer.js +2 -1
  11. package/lib/apps/install-app/app-installer.js +21 -4
  12. package/lib/apps/upgrade-app/app-upgrader.js +1 -1
  13. package/lib/auth/login.js +2 -2
  14. package/lib/cli.js +112 -44
  15. package/lib/config/config.d.ts +2 -2
  16. package/lib/config/configCommands.d.ts +1 -0
  17. package/lib/config/configCommands.js +25 -1
  18. package/lib/interfaces.d.ts +65 -1
  19. package/lib/interfaces.js +21 -0
  20. package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +2 -0
  21. package/lib/workflow-template-definitions/workflow-template-definition-commands.js +10 -0
  22. package/lib/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -0
  23. package/lib/workflow-template-definitions/workflow-template-definition-deployer.js +148 -0
  24. package/lib/workflow-templates/local-workflow-template-deployer.d.ts +11 -0
  25. package/lib/workflow-templates/local-workflow-template-deployer.js +102 -0
  26. package/lib/workflow-templates/workflow-template-commands.d.ts +4 -0
  27. package/lib/workflow-templates/workflow-template-commands.js +51 -0
  28. package/lib/workflow-templates/workflow-template-deployer.d.ts +4 -0
  29. package/lib/workflow-templates/workflow-template-deployer.js +25 -0
  30. package/package.json +1 -1
  31. package/src/api/apps.ts +97 -0
  32. package/src/api/event-workflow-action-definition.ts +8 -0
  33. package/src/api/event-workflow-template-definition.ts +16 -0
  34. package/src/api/event-workflow-templates.ts +29 -0
  35. package/src/apps/deploy-app/app-deployer.ts +4 -19
  36. package/src/apps/install-app/app-installer.ts +34 -13
  37. package/src/apps/upgrade-app/app-upgrader.ts +1 -1
  38. package/src/auth/login.ts +2 -2
  39. package/src/cli.ts +114 -44
  40. package/src/config/config.ts +2 -2
  41. package/src/config/configCommands.ts +26 -1
  42. package/src/interfaces.ts +76 -6
  43. package/src/workflow-template-definitions/workflow-template-definition-commands.ts +13 -0
  44. package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +182 -0
  45. package/src/{workflows/workflow-template-deployer.ts → workflow-templates/local-workflow-template-deployer.ts} +9 -38
  46. package/src/{workflows/workflowCommands.ts → workflow-templates/workflow-template-commands.ts} +10 -4
  47. package/src/workflow-templates/workflow-template-deployer.ts +29 -0
  48. package/src/apps/app-api.ts +0 -66
  49. package/src/apps/deploy-app/workflow-definition-deployer.ts +0 -118
  50. package/tslint.json +0 -57
@@ -0,0 +1,182 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import { App, AppDeclaration, WorkflowDefinition, WorkflowTemplate } from '../interfaces';
4
+ import { getInstalledApps, getWorkflowTemplateDefinitionsForApp } from '../api/apps';
5
+ import { createWorkflowTemplate } from '../api/event-workflow-templates';
6
+ import { createWorkflowTemplateDefinition, updateWorkflowTemplateDefinition as apiUpdateWorkflowTemplateDefinition } from '../api/event-workflow-template-definition';
7
+ import { getActionDeclarationIdentifier, getActionsForApp } from '../apps/deploy-app/actions-deployer';
8
+
9
+ export class WorkflowTemplateDefinitionDeployer {
10
+
11
+ async cliInstallWorkflowTemplateDefinitions() {
12
+ const installedApps = await getInstalledApps();
13
+ if (!installedApps.length) {
14
+ console.log('%s \nNo apps are currently installed. You must install an app before installing its associated workflow template definitions.', chalk.red.bold('WORKFLOW DEFINITION'));
15
+ return;
16
+ }
17
+
18
+ let answers = await inquirer.prompt([{
19
+ type: 'list',
20
+ name: 'appIdentifier',
21
+ message: 'Which app\'s workflow would you like to install?',
22
+ choices: installedApps.map(x => x.app.identifier)
23
+ }]);
24
+ const app = installedApps.find(x => x.app.identifier === answers.appIdentifier).app;
25
+ const workflowTemplateDefinitions = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
26
+ for (const definition of workflowTemplateDefinitions) {
27
+ console.log(chalk.yellow.bold(`- ${definition.name}`));
28
+ }
29
+ answers = await inquirer.prompt([{
30
+ type: 'confirm',
31
+ name: 'shouldInstall',
32
+ message: 'Confirmation: would you like to install these workflows? (yes)',
33
+ default: true,
34
+ }]);
35
+
36
+ if (!answers.shouldInstall) {
37
+ console.log('%s Canceling installing workflows template definitions.', chalk.yellow.bold('WORKFLOW DEFINITION TEMPLATE'));
38
+ return;
39
+ }
40
+
41
+ await this.installWorkflowTemplateDefinitions(workflowTemplateDefinitions);
42
+ }
43
+
44
+ async installWorkflowTemplateDefinitions(workflowTemplateDefinitions: WorkflowTemplate[]) {
45
+
46
+ const answers = await inquirer.prompt([{
47
+ type: 'confirm',
48
+ name: 'makeActive',
49
+ message: 'Should the workflows be active ?(yes)',
50
+ default: true,
51
+ }]);
52
+ const makeActive = answers.makeActive;
53
+ for (const definition of workflowTemplateDefinitions) {
54
+ const newObject: WorkflowTemplate = {
55
+ name: definition.name,
56
+ triggerKey: definition.triggerKey,
57
+ workflowDefinition: definition.workflowDefinition,
58
+ isActive: makeActive,
59
+ supportingAppId: definition.supportingAppId,
60
+ };
61
+ await createWorkflowTemplate(newObject);
62
+ }
63
+ console.log('%s \nInstalled workflows', chalk.green.bold('WORKFLOW DEFINITION'));
64
+ }
65
+
66
+ async listWorkflowTemplateDefinitions() {
67
+ const installedApps = await getInstalledApps();
68
+ const workflowTemplateDefinitions = [];
69
+ for (const appOrg of installedApps) {
70
+ workflowTemplateDefinitions.push(...await (await getWorkflowTemplateDefinitionsForApp({ appId: appOrg.appId })).map(
71
+ x => {
72
+ return {
73
+ appName: appOrg.app.name,
74
+ workflowName: x.name,
75
+ };
76
+ }
77
+ ));
78
+ }
79
+ console.log('(app name) workflow name');
80
+ console.log('------------------------');
81
+ console.log(chalk.green.bold(workflowTemplateDefinitions.map(x => `(${x.appName}) ${x.workflowName} `).join('\n')));
82
+ }
83
+
84
+ async deployWorkflowTemplateDefinitions(appDeclaration: AppDeclaration, app: App) {
85
+
86
+ // FETCH ALL WORKFLOWS FROM THE API.
87
+ const existingWorkflows = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
88
+
89
+ // UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
90
+ console.log('%s \tDeploying workflow definitions.', chalk.yellow.bold('WORKFLOW DEFINITION'));
91
+
92
+ if (appDeclaration.workflows) {
93
+ const localWorkflows = Object.keys(appDeclaration.workflows);
94
+ if (localWorkflows?.length > 0) {
95
+ for (const workflowKey of localWorkflows) {
96
+ await this.deployWorkflow(
97
+ workflowKey, appDeclaration.workflows[workflowKey] as WorkflowDefinition,
98
+ app,
99
+ existingWorkflows,
100
+ );
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ async deployWorkflow(workflowKey: string, workflow: WorkflowDefinition, app: App, existingWorkflows: Array<any>) {
107
+ console.log(`%s \tDeploying workflow definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
108
+
109
+ const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
110
+ const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
111
+
112
+ if (existingDefinition) {
113
+ return await this.updateWorkflowTemplateDefinition(existingDefinition, workflow, app);
114
+ }
115
+ return await this.createNewWorkflowDefinition(workflowKey, workflow, app);
116
+ }
117
+
118
+ private async createNewWorkflowDefinition(workflowKey: string, workflowDeclaration: WorkflowDefinition, app: App) {
119
+ await this.populateActionIds(workflowDeclaration, app);
120
+ const newObject: WorkflowDefinition = {
121
+ identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
122
+ name: workflowDeclaration.name,
123
+ ownerKey: `app:${app.id}`,
124
+ triggerKey: workflowDeclaration.triggerKey,
125
+ workflowDefinition: workflowDeclaration.workflowDefinition,
126
+ public: workflowDeclaration.public,
127
+ isActive: workflowDeclaration.isActive,
128
+ messageGroupId: workflowDeclaration.messageGroupId,
129
+ parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
130
+ };
131
+
132
+ const workflowTemplate = await createWorkflowTemplateDefinition(newObject);
133
+
134
+ console.log(`%s Created new workflow definition definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
135
+
136
+ return workflowTemplate;
137
+ }
138
+
139
+ private async populateActionIds(workflowDefinition: WorkflowDefinition, app: App) {
140
+ const availableAppActions = await getActionsForApp(app);
141
+ if (!workflowDefinition.workflowDefinition?.paths) {
142
+ return;
143
+ }
144
+ for (const path of workflowDefinition.workflowDefinition.paths) {
145
+ if (!path?.actionDefinitionConfigs) {
146
+ continue;
147
+ }
148
+ for (const actionConfiguration of path.actionDefinitionConfigs) {
149
+ const actionKey = actionConfiguration.action;
150
+ const action = availableAppActions.find(
151
+ action => action.identifier === getActionDeclarationIdentifier(actionKey, app)
152
+ );
153
+ if (!action) {
154
+ throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
155
+ }
156
+ actionConfiguration.id = action.id;
157
+ }
158
+ }
159
+ }
160
+
161
+ private async updateWorkflowTemplateDefinition(existingWorkflowDefinition: WorkflowDefinition, workflowDefinition: WorkflowDefinition, app: App) {
162
+ await this.populateActionIds(workflowDefinition, app);
163
+ const updates = Object.assign(new Object(), {
164
+ name: workflowDefinition.name,
165
+ triggerKey: workflowDefinition.triggerKey,
166
+ workflowDefinition: workflowDefinition.workflowDefinition,
167
+ messageGroupId: workflowDefinition.messageGroupId,
168
+ parallelWorkerCount: workflowDefinition.parallelWorkerCount,
169
+ });
170
+
171
+ const updatedWorkflowDefinition = await apiUpdateWorkflowTemplateDefinition({ id: existingWorkflowDefinition.id, updates });
172
+
173
+ console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
174
+
175
+ return updatedWorkflowDefinition;
176
+ }
177
+
178
+ getWorkflowDeclarationIdentifier(actionKey, app: App) {
179
+ return app.identifier + ':' + actionKey;
180
+ }
181
+
182
+ }
@@ -1,12 +1,13 @@
1
- import { Entities } from '@contrail/sdk';
2
1
  import chalk from 'chalk';
2
+ import { getEventWorkflowActionDefinition } from '../api/event-workflow-action-definition';
3
+ import { createWorkflowTemplate, deleteWorkflowTemplate, getExistingWorkflowTemplates, updateWorkflowTemplate as apiUpdateWorkflowTemplate } from '../api/event-workflow-templates';
3
4
  import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
4
5
 
5
- export class WorkflowTemplateDeployer {
6
+ export class LocalWorkflowTemplateDeployer {
6
7
  async deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration) {
7
8
 
8
9
  // FETCH ALL WORKFLOWS FROM THE API.
9
- const existingWorkflows = await this.getExistingWorkflowTemplates();
10
+ const existingWorkflows = await getExistingWorkflowTemplates();
10
11
 
11
12
  // UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
12
13
  console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
@@ -20,12 +21,6 @@ export class WorkflowTemplateDeployer {
20
21
  }
21
22
  }
22
23
 
23
- async getExistingWorkflowTemplates() {
24
- return await new Entities().get({
25
- entityName: 'event-workflow-template'
26
- });
27
- }
28
-
29
24
  async deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>) {
30
25
  console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
31
26
 
@@ -51,11 +46,7 @@ export class WorkflowTemplateDeployer {
51
46
  parallelWorkerCount: workflowTemplate.parallelWorkerCount,
52
47
  };
53
48
 
54
- const newWorkflowTemplate = await new Entities().create({
55
- entityName: 'event-workflow-template',
56
- object: newObject,
57
- });
58
-
49
+ const newWorkflowTemplate = await createWorkflowTemplate(newObject);
59
50
  console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
60
51
 
61
52
  return newWorkflowTemplate;
@@ -92,11 +83,7 @@ export class WorkflowTemplateDeployer {
92
83
  workflowDefinition: workflowTemplate.workflowDefinition
93
84
  });
94
85
 
95
- const updatedWorkflowTemplate = await new Entities().update({
96
- entityName: 'event-workflow-template',
97
- id: existingWorkflowTemplate.id,
98
- object: updates,
99
- });
86
+ const updatedWorkflowTemplate = await apiUpdateWorkflowTemplate({id: existingWorkflowTemplate.id, updates});
100
87
 
101
88
  console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
102
89
 
@@ -105,7 +92,7 @@ export class WorkflowTemplateDeployer {
105
92
 
106
93
  public async deleteWorkflowTemplates(wtDeclaration: WorkflowTemplateDeclaration) {
107
94
  // FETCH ALL WORKFLOWS FROM THE API.
108
- const existingWorkflows = await this.getExistingWorkflowTemplates();
95
+ const existingWorkflows = await getExistingWorkflowTemplates();
109
96
 
110
97
  // UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
111
98
  console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
@@ -116,7 +103,7 @@ export class WorkflowTemplateDeployer {
116
103
 
117
104
  if (existingTemplate) {
118
105
  try {
119
- await this.deleteWorkflowTemplate(identifier);
106
+ await deleteWorkflowTemplate(identifier);
120
107
  } catch (e) {
121
108
  console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
122
109
  }
@@ -127,19 +114,6 @@ export class WorkflowTemplateDeployer {
127
114
  }
128
115
 
129
116
  }
130
-
131
- private async deleteWorkflowTemplate(identifier: string) {
132
- return await new Entities().delete({
133
- entityName: 'event-workflow-template',
134
- id: identifier,
135
- });
136
- }
137
-
138
- public async listExistingWorkflowTemplates() {
139
- const templates = await this.getExistingWorkflowTemplates();
140
- console.log(templates);
141
- return templates;
142
- }
143
117
  }
144
118
 
145
119
  export function getWorkflowTemplateIdentifier(workflowKey: string) {
@@ -147,9 +121,6 @@ export function getWorkflowTemplateIdentifier(workflowKey: string) {
147
121
  }
148
122
 
149
123
  export async function getActionByIdentifier(identifier: string) {
150
- const result = await new Entities().get({
151
- entityName: 'event-workflow-action-definition',
152
- criteria: { identifier },
153
- });
124
+ const result = await getEventWorkflowActionDefinition({identifier});
154
125
  return result.length > 0? result[0]: {};
155
126
  }
@@ -5,9 +5,15 @@ import { authUser } from '../auth/login';
5
5
  import { WorkflowTemplateDeclaration } from '../interfaces';
6
6
  import { getSeparatorByPlatform } from '../common';
7
7
  const yaml = require('js-yaml');
8
+ import { LocalWorkflowTemplateDeployer } from './local-workflow-template-deployer';
8
9
  import { WorkflowTemplateDeployer } from './workflow-template-deployer';
9
10
 
10
- export async function deleteWorkflowTemplate() {
11
+ export async function deleteWorkflowTemplates() {
12
+ await authUser();
13
+ await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
14
+ }
15
+
16
+ export async function localDeleteWorkflowTemplate() {
11
17
  let wtDeclaration: WorkflowTemplateDeclaration;
12
18
  try {
13
19
  wtDeclaration = loadTemplateConfig();
@@ -18,10 +24,10 @@ export async function deleteWorkflowTemplate() {
18
24
  }
19
25
 
20
26
  await authUser();
21
- await new WorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
27
+ await new LocalWorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
22
28
  }
23
29
 
24
- export async function deployWorkflowTemplate() {
30
+ export async function localDeployWorkflowTemplate() {
25
31
  let wtDeclaration: WorkflowTemplateDeclaration;
26
32
  try {
27
33
  wtDeclaration = loadTemplateConfig();
@@ -32,7 +38,7 @@ export async function deployWorkflowTemplate() {
32
38
  }
33
39
 
34
40
  await authUser();
35
- await new WorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
41
+ await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
36
42
  }
37
43
 
38
44
  export async function listWorkflowTemplate() {
@@ -0,0 +1,29 @@
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import { deleteWorkflowTemplate as apiDeleteWorkflowTemplate } from '../api/event-workflow-templates';
4
+ import { getExistingWorkflowTemplates } from '../api/event-workflow-templates';
5
+
6
+ export class WorkflowTemplateDeployer {
7
+
8
+ async deleteWorkflowTemplates() {
9
+
10
+ // FETCH ALL WORKFLOWS FROM THE API.
11
+ const existingWorkflows = await getExistingWorkflowTemplates();
12
+ const answers = await inquirer.prompt([{
13
+ type: 'checkbox',
14
+ name: 'wfTemplatesToDelete',
15
+ message: 'Which templates would you like to delete (one or more)?',
16
+ choices: existingWorkflows.map(x => { return { value: x.id, name: `(${x.createdOn}) ${x.name}` }; })
17
+ }]);
18
+ for (const idToDelete of answers.wfTemplatesToDelete) {
19
+ await apiDeleteWorkflowTemplate(idToDelete);
20
+ }
21
+ console.log('%s \tDeleted workflow templates!', chalk.green.bold('WORKFLOW TEMPLATES'));
22
+ }
23
+
24
+ public async listExistingWorkflowTemplates() {
25
+ const templates = await getExistingWorkflowTemplates();
26
+ console.log(templates);
27
+ return templates;
28
+ }
29
+ }
@@ -1,66 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import { Auth } from '../auth/auth';
3
-
4
- export async function getAppVersions(app) {
5
- return await new Entities().get({
6
- entityName: 'app-version',
7
- criteria: {
8
- appId: app.id
9
- }
10
- });
11
- }
12
-
13
- export async function upgradeAppVersion(appOrg, appVersionId) {
14
- return await new Entities().update({
15
- entityName: 'app-org',
16
- id: appOrg.id,
17
- object: {
18
- appVersionId: appVersionId
19
- }
20
- });
21
- }
22
-
23
- export async function deleteAppOrg(appOrgId: string) {
24
- return await new Entities().delete({
25
- entityName: 'app-org',
26
- id: appOrgId
27
- });
28
- }
29
-
30
- export async function getInstalledApps() {
31
- return await new Entities().get({
32
- entityName: 'app-org',
33
- relations: ['app']
34
- });
35
- }
36
-
37
- export async function installAppToOrg(app, configProperties) {
38
- return await new Entities().create({
39
- entityName: 'app-org',
40
- object: {
41
- appId: app.id,
42
- appConfig: configProperties
43
- }
44
- });
45
- }
46
-
47
- export async function getAvailableApps() {
48
- const orgId = Auth.config.orgId;
49
- const apps = [];
50
- apps.push(...await new Entities().get({
51
- entityName: 'app',
52
- criteria: {
53
- orgId,
54
- private: true,
55
- },
56
- }));
57
- apps.push(...await new Entities().get({
58
- entityName: 'app',
59
- criteria: {
60
- orgId,
61
- private: false,
62
- },
63
- }));
64
-
65
- return apps;
66
- }
@@ -1,118 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { App, AppDeclaration, WorkflowDefinition } from '../../interfaces';
4
- import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
5
-
6
- export class WorkflowDefinitionDeployer {
7
- async deployWorkflowDefinitions(appDeclaration: AppDeclaration, app: App) {
8
-
9
- // FETCH ALL WORKFLOWS FROM THE API.
10
- const existingWorkflows = await this.getWorkflowDefinitionsForApp(app);
11
-
12
- // UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
13
- console.log('%s \tDeploying workflow definitions.', chalk.yellow.bold('WORKFLOW DEFINITION'));
14
-
15
- if (appDeclaration.workflows) {
16
- const localWorkflows = Object.keys(appDeclaration.workflows);
17
- if (localWorkflows?.length > 0) {
18
- for (const workflowKey of localWorkflows) {
19
- await this.deployWorkflow(
20
- workflowKey, appDeclaration.workflows[workflowKey] as WorkflowDefinition,
21
- app,
22
- existingWorkflows,
23
- );
24
- }
25
- }
26
- }
27
- }
28
-
29
- async getWorkflowDefinitionsForApp(app: App) {
30
- return await new Entities().get({
31
- entityName: 'event-workflow-template-definition',
32
- criteria: { ownerKey: `app:${app.id}` },
33
- });
34
- }
35
-
36
- async deployWorkflow(workflowKey: string, workflow: WorkflowDefinition, app: App, existingWorkflows: Array<any>) {
37
- console.log(`%s \tDeploying workflow definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
38
-
39
- const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
40
- const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
41
-
42
- if (existingDefinition) {
43
- return await this.updateWorkflowDefinition(existingDefinition, workflow, app);
44
- }
45
- return await this.createNewWorkflowDefinition(workflowKey, workflow, app);
46
- }
47
-
48
- private async createNewWorkflowDefinition(workflowKey: string, workflowDeclaration: WorkflowDefinition, app: App) {
49
- await this.populateActionIds(workflowDeclaration, app);
50
- const newObject: WorkflowDefinition = {
51
- identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
52
- name: workflowDeclaration.name,
53
- ownerKey: `app:${app.id}`,
54
- triggerKey: workflowDeclaration.triggerKey,
55
- workflowDefinition: workflowDeclaration.workflowDefinition,
56
- public: workflowDeclaration.public,
57
- isActive: workflowDeclaration.isActive,
58
- messageGroupId: workflowDeclaration.messageGroupId,
59
- parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
60
- };
61
-
62
- const workflowTemplate = await new Entities().create({
63
- entityName: 'event-workflow-template-definition',
64
- object: newObject,
65
- });
66
-
67
- console.log(`%s Created new workflow definition definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
68
-
69
- return workflowTemplate;
70
- }
71
-
72
- private async populateActionIds(workflowDefinition: WorkflowDefinition, app: App) {
73
- const availableAppActions = await getActionsForApp(app);
74
- if (!workflowDefinition.workflowDefinition?.paths) {
75
- return;
76
- }
77
- for (const path of workflowDefinition.workflowDefinition.paths) {
78
- if (!path?.actionDefinitionConfigs) {
79
- continue;
80
- }
81
- for (const actionConfiguration of path.actionDefinitionConfigs) {
82
- const actionKey = actionConfiguration.action;
83
- const action = availableAppActions.find(
84
- action => action.identifier === getActionDeclarationIdentifier(actionKey, app)
85
- );
86
- if (!action) {
87
- throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
88
- }
89
- actionConfiguration.id = action.id;
90
- }
91
- }
92
- }
93
-
94
- private async updateWorkflowDefinition(existingWorkflowDefinition: WorkflowDefinition, workflowDefinition: WorkflowDefinition, app: App) {
95
- await this.populateActionIds(workflowDefinition, app);
96
- const updates = Object.assign(new Object(), {
97
- name: workflowDefinition.name,
98
- triggerKey: workflowDefinition.triggerKey,
99
- workflowDefinition: workflowDefinition.workflowDefinition,
100
- messageGroupId: workflowDefinition.messageGroupId,
101
- parallelWorkerCount: workflowDefinition.parallelWorkerCount,
102
- });
103
-
104
- const updatedWorkflowDefinition = await new Entities().update({
105
- entityName: 'event-workflow-template-definition',
106
- id: existingWorkflowDefinition.id,
107
- object: updates,
108
- });
109
-
110
- console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
111
-
112
- return updatedWorkflowDefinition;
113
- }
114
-
115
- getWorkflowDeclarationIdentifier(actionKey, app: App) {
116
- return app.identifier + ':' + actionKey;
117
- }
118
- }
package/tslint.json DELETED
@@ -1,57 +0,0 @@
1
- {
2
- "defaultSeverity": "error",
3
- "extends": [
4
- "tslint:recommended"
5
- ],
6
- "jsRules": {
7
- "no-unused-expression": true
8
- },
9
- "rules": {
10
- "eofline": false,
11
- "quotemark": [
12
- true,
13
- "single"
14
- ],
15
- "no-shadowed-variable": false,
16
- "indent": false,
17
- "member-access": [
18
- false
19
- ],
20
- "no-string-literal": false,
21
- "ordered-imports": [
22
- false
23
- ],
24
- "max-line-length": [
25
- false,
26
- 150
27
- ],
28
- "member-ordering": [
29
- false
30
- ],
31
- "curly": false,
32
- "interface-name": [
33
- false
34
- ],
35
- "array-type": [
36
- false
37
- ],
38
- "no-empty-interface": false,
39
- "no-empty": false,
40
- "arrow-parens": false,
41
- "object-literal-sort-keys": false,
42
- "no-unused-expression": false,
43
- "max-classes-per-file": [
44
- false
45
- ],
46
- "variable-name": [
47
- false
48
- ],
49
- "one-line": [
50
- false
51
- ],
52
- "one-variable-per-declaration": [
53
- false
54
- ]
55
- },
56
- "rulesDirectory": []
57
- }