@contrail/cli 1.0.71 → 2.0.1

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 (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1034 -5
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +5 -0
  6. package/bin/run.cmd +3 -0
  7. package/{lib → dist}/api/apps.d.ts +13 -13
  8. package/dist/api/apps.js +96 -0
  9. package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
  10. package/dist/api/event-workflow-action-definition.js +11 -0
  11. package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
  12. package/dist/api/event-workflow-template-definition.js +26 -0
  13. package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
  14. package/dist/api/event-workflow-templates.js +32 -0
  15. package/dist/api/types.d.ts +7 -0
  16. package/dist/api/types.js +52 -0
  17. package/{lib → dist}/auth/auth.d.ts +9 -9
  18. package/dist/auth/auth.js +6 -0
  19. package/{lib → dist}/auth/login.d.ts +2 -2
  20. package/{lib → dist}/auth/login.js +146 -141
  21. package/dist/commands/app/create.d.ts +6 -0
  22. package/dist/commands/app/create.js +15 -0
  23. package/dist/commands/app/delete.d.ts +7 -0
  24. package/dist/commands/app/delete.js +38 -0
  25. package/dist/commands/app/install.d.ts +11 -0
  26. package/dist/commands/app/install.js +117 -0
  27. package/dist/commands/app/publish.d.ts +7 -0
  28. package/dist/commands/app/publish.js +45 -0
  29. package/dist/commands/app/uninstall.d.ts +10 -0
  30. package/dist/commands/app/uninstall.js +58 -0
  31. package/dist/commands/app/upgrade.d.ts +11 -0
  32. package/dist/commands/app/upgrade.js +79 -0
  33. package/dist/commands/colors/deleteAll.d.ts +6 -0
  34. package/dist/commands/colors/deleteAll.js +30 -0
  35. package/dist/commands/colors/load.d.ts +6 -0
  36. package/dist/commands/colors/load.js +29 -0
  37. package/dist/commands/config/list.d.ts +6 -0
  38. package/dist/commands/config/list.js +15 -0
  39. package/dist/commands/config/remove.d.ts +14 -0
  40. package/dist/commands/config/remove.js +26 -0
  41. package/dist/commands/config/set.d.ts +13 -0
  42. package/dist/commands/config/set.js +29 -0
  43. package/dist/commands/loader-process/load.d.ts +9 -0
  44. package/dist/commands/loader-process/load.js +33 -0
  45. package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
  46. package/dist/commands/loader-process/upload-and-load.js +35 -0
  47. package/dist/commands/projects/export.d.ts +10 -0
  48. package/dist/commands/projects/export.js +34 -0
  49. package/dist/commands/projects/list.d.ts +6 -0
  50. package/dist/commands/projects/list.js +34 -0
  51. package/dist/commands/projects/load.d.ts +9 -0
  52. package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
  53. package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
  54. package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
  55. package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
  56. package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
  57. package/dist/commands/types/loadAll.d.ts +7 -0
  58. package/dist/commands/types/loadAll.js +41 -0
  59. package/dist/commands/types/mergeOptionSets.d.ts +9 -0
  60. package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
  61. package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
  62. package/dist/commands/types/mergeTypeProperties.js +89 -0
  63. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
  64. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
  65. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
  66. package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
  67. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
  68. package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
  69. package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
  70. package/dist/commands/types/parseTypesFromFiles.js +34 -0
  71. package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
  72. package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
  73. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
  74. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
  75. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
  76. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
  77. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
  78. package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
  79. package/dist/commands/types/uploadOptionSets.d.ts +7 -0
  80. package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
  81. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
  82. package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
  83. package/dist/commands/types/uploadRuleSets.d.ts +7 -0
  84. package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
  85. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
  86. package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
  87. package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
  88. package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
  89. package/dist/commands/users/export.d.ts +9 -0
  90. package/dist/commands/users/export.js +60 -0
  91. package/dist/commands/users/upload.d.ts +9 -0
  92. package/dist/commands/users/upload.js +65 -0
  93. package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
  94. package/dist/commands/workflow-template-definitions/install.js +17 -0
  95. package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
  96. package/dist/commands/workflow-template-definitions/list.js +17 -0
  97. package/dist/commands/workflow-templates/delete.d.ts +6 -0
  98. package/dist/commands/workflow-templates/delete.js +17 -0
  99. package/dist/commands/workflow-templates/list.d.ts +6 -0
  100. package/dist/commands/workflow-templates/list.js +17 -0
  101. package/dist/commands/workflow-templates/load.d.ts +9 -0
  102. package/dist/commands/workflow-templates/load.js +21 -0
  103. package/{lib → dist}/common.d.ts +1 -1
  104. package/dist/common.js +9 -0
  105. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
  106. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
  107. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
  108. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
  109. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
  110. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
  111. package/dist/helpers/app/load-app-config.d.ts +1 -0
  112. package/dist/helpers/app/load-app-config.js +18 -0
  113. package/dist/helpers/app/setup-template.d.ts +1 -0
  114. package/dist/helpers/app/setup-template.js +38 -0
  115. package/dist/helpers/colors/helpers.d.ts +4 -0
  116. package/dist/helpers/colors/helpers.js +74 -0
  117. package/{lib → dist/helpers}/config/config.d.ts +6 -6
  118. package/dist/helpers/config/config.js +76 -0
  119. package/dist/helpers/loader-process/helpers.d.ts +2 -0
  120. package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
  121. package/dist/helpers/projects/helpers.d.ts +2 -0
  122. package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
  123. package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
  124. package/{lib → dist/helpers}/types/csv-parser.js +56 -51
  125. package/dist/helpers/types/type-extractor.d.ts +1 -0
  126. package/dist/helpers/types/type-extractor.js +32 -0
  127. package/dist/helpers/types/type-parser.d.ts +4 -0
  128. package/dist/helpers/types/type-parser.js +118 -0
  129. package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
  130. package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
  131. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
  132. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
  133. package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
  134. package/dist/helpers/workflow-templates/helper.js +166 -0
  135. package/dist/index.d.ts +1 -0
  136. package/dist/index.js +5 -0
  137. package/{lib → dist}/interfaces.d.ts +323 -191
  138. package/dist/interfaces.js +63 -0
  139. package/{templates → dist/templates}/typescript/Dockerfile +15 -15
  140. package/{templates → dist/templates}/typescript/README.md +10 -10
  141. package/{templates → dist/templates}/typescript/app.yml +49 -49
  142. package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
  143. package/{templates → dist/templates}/typescript/package.json +54 -54
  144. package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
  145. package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
  146. package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
  147. package/{templates → dist/templates}/typescript/src/framework/handler.ts +11 -11
  148. package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
  149. package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
  150. package/{templates → dist/templates}/typescript/src/framework/logger.ts +21 -21
  151. package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +31 -31
  152. package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
  153. package/oclif.manifest.json +821 -0
  154. package/package.json +116 -72
  155. package/.eslintrc.js +0 -53
  156. package/.vscode/settings.json +0 -6
  157. package/bin/init +0 -4
  158. package/lib/api/apps.js +0 -85
  159. package/lib/api/event-workflow-action-definition.js +0 -7
  160. package/lib/api/event-workflow-template-definition.js +0 -20
  161. package/lib/api/event-workflow-templates.js +0 -25
  162. package/lib/apps/create-app/create.d.ts +0 -1
  163. package/lib/apps/create-app/create.js +0 -60
  164. package/lib/apps/create-app/setup-template.d.ts +0 -1
  165. package/lib/apps/create-app/setup-template.js +0 -34
  166. package/lib/apps/deploy-app/deploy.d.ts +0 -2
  167. package/lib/apps/deploy-app/deploy.js +0 -58
  168. package/lib/apps/install-app/app-installer.d.ts +0 -2
  169. package/lib/apps/install-app/app-installer.js +0 -120
  170. package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
  171. package/lib/apps/upgrade-app/app-upgrader.js +0 -126
  172. package/lib/auth/auth.js +0 -2
  173. package/lib/cli.d.ts +0 -5
  174. package/lib/cli.js +0 -524
  175. package/lib/colors/color-loader.d.ts +0 -2
  176. package/lib/colors/color-loader.js +0 -96
  177. package/lib/common.js +0 -5
  178. package/lib/config/config.js +0 -70
  179. package/lib/config/configCommands.d.ts +0 -3
  180. package/lib/config/configCommands.js +0 -34
  181. package/lib/interfaces.js +0 -25
  182. package/lib/loader-process/loader-process.d.ts +0 -2
  183. package/lib/projects/interfaces.d.ts +0 -77
  184. package/lib/projects/interfaces.js +0 -23
  185. package/lib/projects/project-exporter.d.ts +0 -2
  186. package/lib/projects/project-uploader.d.ts +0 -1
  187. package/lib/types/allUploader.d.ts +0 -1
  188. package/lib/types/allUploader.js +0 -24
  189. package/lib/types/interfaces.d.ts +0 -55
  190. package/lib/types/interfaces.js +0 -1
  191. package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
  192. package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
  193. package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
  194. package/lib/types/option-set-merger.d.ts +0 -1
  195. package/lib/types/option-set-parser.d.ts +0 -3
  196. package/lib/types/option-set-parser.js +0 -140
  197. package/lib/types/option-set-uploader.d.ts +0 -1
  198. package/lib/types/parse-types.d.ts +0 -4
  199. package/lib/types/parse-types.js +0 -189
  200. package/lib/types/rule-set-uploader.d.ts +0 -1
  201. package/lib/types/type-property-policy-uploader.d.ts +0 -1
  202. package/lib/types/types-properties-merger.d.ts +0 -1
  203. package/lib/types/types-properties-merger.js +0 -75
  204. package/lib/types/usage-info-uploader.d.ts +0 -1
  205. package/lib/users/user-exporter.d.ts +0 -1
  206. package/lib/users/user-exporter.js +0 -41
  207. package/lib/users/user-uploader.d.ts +0 -1
  208. package/lib/users/user-uploader.js +0 -45
  209. package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
  210. package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
  211. package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
  212. package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
  213. package/lib/workflow-templates/workflow-template-commands.js +0 -51
  214. package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
  215. package/lib/workflow-templates/workflow-template-deployer.js +0 -26
  216. package/publish.bat +0 -5
  217. package/publish.sh +0 -5
  218. package/src/api/apps.ts +0 -97
  219. package/src/api/event-workflow-action-definition.ts +0 -8
  220. package/src/api/event-workflow-template-definition.ts +0 -23
  221. package/src/api/event-workflow-templates.ts +0 -29
  222. package/src/apps/create-app/create.ts +0 -74
  223. package/src/apps/create-app/setup-template.ts +0 -38
  224. package/src/apps/deploy-app/actions-deployer.ts +0 -140
  225. package/src/apps/deploy-app/app-deployer.ts +0 -105
  226. package/src/apps/deploy-app/app-template-parsers.ts +0 -44
  227. package/src/apps/deploy-app/deploy.ts +0 -66
  228. package/src/apps/install-app/app-installer.ts +0 -126
  229. package/src/apps/upgrade-app/app-upgrader.ts +0 -132
  230. package/src/auth/auth.ts +0 -10
  231. package/src/auth/login.ts +0 -155
  232. package/src/cli.ts +0 -540
  233. package/src/colors/color-loader.ts +0 -112
  234. package/src/colors/colors.csv +0 -866
  235. package/src/common.ts +0 -5
  236. package/src/config/config.ts +0 -74
  237. package/src/config/configCommands.ts +0 -38
  238. package/src/interfaces.ts +0 -200
  239. package/src/loader-process/loader-process.ts +0 -152
  240. package/src/projects/interfaces.ts +0 -73
  241. package/src/projects/project-exporter.ts +0 -225
  242. package/src/projects/project-uploader.ts +0 -131
  243. package/src/types/allUploader.ts +0 -28
  244. package/src/types/csv-parser.ts +0 -59
  245. package/src/types/interfaces.ts +0 -58
  246. package/src/types/option-set-hierarchy-exporter.ts +0 -125
  247. package/src/types/option-set-hierarchy-parser.ts +0 -169
  248. package/src/types/option-set-hierarchy-uploader.ts +0 -122
  249. package/src/types/option-set-merger.ts +0 -124
  250. package/src/types/option-set-parser.ts +0 -166
  251. package/src/types/option-set-uploader.ts +0 -108
  252. package/src/types/parse-types.ts +0 -227
  253. package/src/types/rule-set-uploader.ts +0 -187
  254. package/src/types/type-property-policy-uploader.ts +0 -192
  255. package/src/types/types-extractor.ts +0 -369
  256. package/src/types/types-properties-merger.ts +0 -90
  257. package/src/types/types-uploader.ts +0 -271
  258. package/src/types/usage-info-uploader.ts +0 -139
  259. package/src/users/user-exporter.ts +0 -52
  260. package/src/users/user-uploader.ts +0 -58
  261. package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
  262. package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
  263. package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
  264. package/src/workflow-templates/workflow-template-commands.ts +0 -59
  265. package/src/workflow-templates/workflow-template-deployer.ts +0 -30
  266. package/templates/javascript/actions/example/action.js +0 -38
  267. package/templates/javascript/app.yml +0 -53
  268. package/templates/javascript/package.json +0 -23
  269. package/templates/typescript/package-lock.json +0 -14
  270. package/tsconfig.json +0 -32
@@ -1,184 +0,0 @@
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, deleteWorkflowTemplateDefinition, 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
- const 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
- await this.installWorkflowTemplateDefinitions(workflowTemplateDefinitions);
30
- }
31
-
32
- async installWorkflowTemplateDefinitions(workflowTemplateDefinitions: WorkflowTemplate[]) {
33
- let answers = await inquirer.prompt([{
34
- type: 'checkbox',
35
- name: 'workflowTemplateDefinitionsToInstall',
36
- message: 'Which workflow templates would you like to install?',
37
- choices: workflowTemplateDefinitions.map(x => {return {value: x.identifier, name: x.name};}),
38
- }]);
39
-
40
- const workflowTemplateDefinitionsToInstall = workflowTemplateDefinitions.filter(x => answers.workflowTemplateDefinitionsToInstall.includes(x.identifier));
41
- answers = await inquirer.prompt([{
42
- type: 'confirm',
43
- name: 'makeActive',
44
- message: 'Should the workflows be active ?(yes)',
45
- default: true,
46
- }]);
47
- const makeActive = answers.makeActive;
48
- for (const definition of workflowTemplateDefinitionsToInstall) {
49
- const newObject: WorkflowTemplate = {
50
- name: definition.name,
51
- triggerKey: definition.triggerKey,
52
- workflowDefinition: definition.workflowDefinition,
53
- isActive: makeActive,
54
- supportingAppId: definition.supportingAppId,
55
- };
56
- await createWorkflowTemplate(newObject);
57
- }
58
- console.log('%s \nInstalled workflows', chalk.green.bold('WORKFLOW DEFINITION'));
59
- }
60
-
61
- async listWorkflowTemplateDefinitions() {
62
- const installedApps = await getInstalledApps();
63
- const workflowTemplateDefinitions = [];
64
- for (const appOrg of installedApps) {
65
- workflowTemplateDefinitions.push(...await (await getWorkflowTemplateDefinitionsForApp({ appId: appOrg.appId })).map(
66
- x => {
67
- return {
68
- appName: appOrg.app.name,
69
- workflowName: x.name,
70
- };
71
- }
72
- ));
73
- }
74
- console.log('(app name) workflow name');
75
- console.log('------------------------');
76
- console.log(chalk.green.bold(workflowTemplateDefinitions.map(x => `(${x.appName}) ${x.workflowName} `).join('\n')));
77
- }
78
-
79
- async deployWorkflowTemplateDefinitions(appDeclaration: AppDeclaration, app: App) {
80
-
81
- // FETCH ALL WORKFLOWS FROM THE API.
82
- const existingWorkflows = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
83
-
84
- // UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
85
- console.log('%s \tDeploying workflow definitions.', chalk.yellow.bold('WORKFLOW DEFINITION'));
86
-
87
- if (appDeclaration.workflows) {
88
- const localWorkflows = Object.keys(appDeclaration.workflows);
89
- if (localWorkflows?.length > 0) {
90
- for (const workflowKey of localWorkflows) {
91
- await this.deployWorkflow(
92
- workflowKey, appDeclaration.workflows[workflowKey] as WorkflowDefinition,
93
- app,
94
- existingWorkflows,
95
- );
96
- }
97
- }
98
-
99
- // remove old templates that were removed by the app publisher
100
- const localIdentifiers = localWorkflows.map(x=> this.getWorkflowDeclarationIdentifier(x, app));
101
- const workflowTemplateDefinitionsToDelete = existingWorkflows.filter(x=> !localIdentifiers.includes(x.identifier));
102
- for(const templateToDelete of workflowTemplateDefinitionsToDelete) {
103
- await deleteWorkflowTemplateDefinition(templateToDelete.id);
104
- }
105
- }
106
- }
107
-
108
- async deployWorkflow(workflowKey: string, workflow: WorkflowDefinition, app: App, existingWorkflows: Array<any>) {
109
- console.log(`%s \tDeploying workflow definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
110
-
111
- const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
112
- const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
113
-
114
- if (existingDefinition) {
115
- return await this.updateWorkflowTemplateDefinition(existingDefinition, workflow, app);
116
- }
117
- return await this.createNewWorkflowDefinition(workflowKey, workflow, app);
118
- }
119
-
120
- private async createNewWorkflowDefinition(workflowKey: string, workflowDeclaration: WorkflowDefinition, app: App) {
121
- await this.populateActionIds(workflowDeclaration, app);
122
- const newObject: WorkflowDefinition = {
123
- identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
124
- name: workflowDeclaration.name,
125
- ownerKey: `app:${app.id}`,
126
- triggerKey: workflowDeclaration.triggerKey,
127
- workflowDefinition: workflowDeclaration.workflowDefinition,
128
- public: workflowDeclaration.public,
129
- isActive: workflowDeclaration.isActive,
130
- messageGroupId: workflowDeclaration.messageGroupId,
131
- parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
132
- };
133
-
134
- const workflowTemplate = await createWorkflowTemplateDefinition(newObject);
135
-
136
- console.log(`%s Created new workflow definition definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
137
-
138
- return workflowTemplate;
139
- }
140
-
141
- private async populateActionIds(workflowDefinition: WorkflowDefinition, app: App) {
142
- const availableAppActions = await getActionsForApp(app);
143
- if (!workflowDefinition.workflowDefinition?.paths) {
144
- return;
145
- }
146
- for (const path of workflowDefinition.workflowDefinition.paths) {
147
- if (!path?.actionDefinitionConfigs) {
148
- continue;
149
- }
150
- for (const actionConfiguration of path.actionDefinitionConfigs) {
151
- const actionKey = actionConfiguration.action;
152
- const action = availableAppActions.find(
153
- action => action.identifier === getActionDeclarationIdentifier(actionKey, app)
154
- );
155
- if (!action) {
156
- throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
157
- }
158
- actionConfiguration.id = action.id;
159
- }
160
- }
161
- }
162
-
163
- private async updateWorkflowTemplateDefinition(existingWorkflowDefinition: WorkflowDefinition, workflowDefinition: WorkflowDefinition, app: App) {
164
- await this.populateActionIds(workflowDefinition, app);
165
- const updates = Object.assign(new Object(), {
166
- name: workflowDefinition.name,
167
- triggerKey: workflowDefinition.triggerKey,
168
- workflowDefinition: workflowDefinition.workflowDefinition,
169
- messageGroupId: workflowDefinition.messageGroupId,
170
- parallelWorkerCount: workflowDefinition.parallelWorkerCount,
171
- });
172
-
173
- const updatedWorkflowDefinition = await apiUpdateWorkflowTemplateDefinition({ id: existingWorkflowDefinition.id, updates });
174
-
175
- console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
176
-
177
- return updatedWorkflowDefinition;
178
- }
179
-
180
- getWorkflowDeclarationIdentifier(actionKey, app: App) {
181
- return app.identifier + ':' + actionKey;
182
- }
183
-
184
- }
@@ -1,126 +0,0 @@
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';
4
- import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
5
-
6
- export class LocalWorkflowTemplateDeployer {
7
- async deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration) {
8
-
9
- // FETCH ALL WORKFLOWS FROM THE API.
10
- const existingWorkflows = await getExistingWorkflowTemplates();
11
-
12
- // UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
13
- console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
14
-
15
- for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
16
- await this.deployWorkflowTemplate(
17
- workflowKey,
18
- wtDeclaration.workflows[workflowKey] as WorkflowTemplate,
19
- existingWorkflows,
20
- );
21
- }
22
- }
23
-
24
- async deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>) {
25
- console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
26
-
27
- const identifier = getWorkflowTemplateIdentifier(workflowKey);
28
- const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
29
-
30
- if (existingTemplate) {
31
- return await this.updateWorkflowTemplate(workflowKey, existingTemplate, workflow);
32
- }
33
- return await this.createNewWorkflowTemplate(workflowKey, workflow);
34
- }
35
-
36
- private async createNewWorkflowTemplate(workflowKey: string, workflowTemplate: WorkflowTemplate) {
37
- await this.populateActionIds(workflowTemplate, workflowKey);
38
- const newObject: WorkflowTemplate = {
39
- identifier: getWorkflowTemplateIdentifier(workflowKey),
40
- name: workflowTemplate.name,
41
- triggerKey: workflowTemplate.triggerKey,
42
- workflowDefinition: workflowTemplate.workflowDefinition,
43
- isActive: workflowTemplate.isActive,
44
- supportingAppId: workflowTemplate.supportingAppId,
45
- messageGroupId: workflowTemplate.messageGroupId,
46
- parallelWorkerCount: workflowTemplate.parallelWorkerCount,
47
- };
48
-
49
- const newWorkflowTemplate = await createWorkflowTemplate(newObject);
50
- console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
51
-
52
- return newWorkflowTemplate;
53
- }
54
-
55
- private async populateActionIds(workflowTemplate: WorkflowTemplate, workflowKey: string) {
56
- if (!workflowTemplate?.workflowDefinition?.paths) {
57
- return;
58
- }
59
- for (const path of workflowTemplate.workflowDefinition.paths) {
60
- if (!path?.actionDefinitionConfigs) {
61
- continue;
62
- }
63
- for (const actionConfiguration of path.actionDefinitionConfigs) {
64
- const actionKey = actionConfiguration.action;
65
- try {
66
- const actionEntity: any = await getActionByIdentifier(actionKey);
67
- actionConfiguration.id = actionEntity.id;
68
- } catch (e) {
69
- console.log(e);
70
- }
71
- if(!actionConfiguration.id) {
72
- throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
73
- }
74
- }
75
- }
76
- }
77
-
78
- private async updateWorkflowTemplate(workflowKey: string, existingWorkflowTemplate: WorkflowTemplate, workflowTemplate: WorkflowTemplate) {
79
- await this.populateActionIds(workflowTemplate, workflowKey);
80
- const updates = Object.assign(new Object(), {
81
- name: workflowTemplate.name,
82
- triggerKey: workflowTemplate.triggerKey,
83
- workflowDefinition: workflowTemplate.workflowDefinition
84
- });
85
-
86
- const updatedWorkflowTemplate = await apiUpdateWorkflowTemplate({id: existingWorkflowTemplate.id, updates});
87
-
88
- console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
89
-
90
- return updatedWorkflowTemplate;
91
- }
92
-
93
- public async deleteWorkflowTemplates(wtDeclaration: WorkflowTemplateDeclaration) {
94
- // FETCH ALL WORKFLOWS FROM THE API.
95
- const existingWorkflows = await getExistingWorkflowTemplates();
96
-
97
- // UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
98
- console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
99
-
100
- for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
101
- const identifier = getWorkflowTemplateIdentifier(workflowKey);
102
- const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
103
-
104
- if (existingTemplate) {
105
- try {
106
- await deleteWorkflowTemplate(identifier);
107
- } catch (e) {
108
- console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
109
- }
110
- } else {
111
- console.log('%s \tUnable to locate workflow template %s.', chalk.yellow.bold('WORKFLOW TEMPLATES'), identifier);
112
-
113
- }
114
- }
115
-
116
- }
117
- }
118
-
119
- export function getWorkflowTemplateIdentifier(workflowKey: string) {
120
- return workflowKey;
121
- }
122
-
123
- export async function getActionByIdentifier(identifier: string) {
124
- const result = await getEventWorkflowActionDefinition({identifier});
125
- return result.length > 0? result[0]: {};
126
- }
@@ -1,59 +0,0 @@
1
-
2
- import chalk from 'chalk';
3
- import fs from 'fs';
4
- import { authUser } from '../auth/login';
5
- import { WorkflowTemplateDeclaration } from '../interfaces';
6
- import { getSeparatorByPlatform } from '../common';
7
- const yaml = require('js-yaml');
8
- import { LocalWorkflowTemplateDeployer } from './local-workflow-template-deployer';
9
- import { WorkflowTemplateDeployer } from './workflow-template-deployer';
10
-
11
- export async function deleteWorkflowTemplates() {
12
- await authUser();
13
- await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
14
- }
15
-
16
- export async function localDeleteWorkflowTemplate() {
17
- let wtDeclaration: WorkflowTemplateDeclaration;
18
- try {
19
- wtDeclaration = loadTemplateConfig();
20
- }
21
- catch (e) {
22
- console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
23
- return;
24
- }
25
-
26
- await authUser();
27
- await new LocalWorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
28
- }
29
-
30
- export async function localDeployWorkflowTemplate() {
31
- let wtDeclaration: WorkflowTemplateDeclaration;
32
- try {
33
- wtDeclaration = loadTemplateConfig();
34
- }
35
- catch (e) {
36
- console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
37
- return;
38
- }
39
-
40
- await authUser();
41
- await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
42
- }
43
-
44
- export async function listWorkflowTemplate() {
45
- await authUser();
46
- return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
47
- }
48
-
49
- function loadTemplateConfig() {
50
- const TARGET_DIR = process.cwd();
51
- try {
52
- const separator = getSeparatorByPlatform();
53
- const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'workflow.yml', 'utf8'));
54
- console.log(doc);
55
- return doc;
56
- } catch (e) {
57
- throw new Error(`ERROR PARSING YAML: ${e}`);
58
- }
59
- }
@@ -1,30 +0,0 @@
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('(Date Created) (active) workflow name');
27
- console.log('------------------------');
28
- console.log(chalk.green.bold(templates.map(x => `(${x.createdOn}) (${x.isActive? 'active': 'inactive'}) ${x.name} `).join('\n')));
29
- }
30
- }
@@ -1,38 +0,0 @@
1
- async function execute(config, event, Functions) {
2
- const getBodyFromEvent = (config, event) => {
3
- let body = Functions.stringUtil.parseVariables(config.message, event);
4
- console.log('body: ', body);
5
- if (config.sendDetails) {
6
- const data = event;
7
- const properties = {};
8
- let addedProperty = false;
9
- for (const property of config.fieldsToForward) {
10
- const variableLevels = property.split('.');
11
- let replacementValue = data;
12
- for (let i = 0; i < variableLevels.length; i++) {
13
- replacementValue = replacementValue[variableLevels[i]];
14
- }
15
- properties[property] = replacementValue;
16
- addedProperty = true;
17
- }
18
- if (addedProperty) {
19
- body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
- }
21
- }
22
- return JSON.stringify({ text: body });
23
- };
24
- const body = getBodyFromEvent(config, event);
25
- console.log('Sending message: ', body);
26
- const response = await Functions.fetch(config.url, {
27
- method: 'POST',
28
- body: body,
29
- headers: { 'Content-Type': 'application/json' }
30
- });
31
- if (!response.ok) {
32
- console.log('Webhook event failed to publish');
33
- console.log('Response: ', JSON.stringify(response));
34
- }
35
- else {
36
- console.log('Published!');
37
- }
38
- }
@@ -1,53 +0,0 @@
1
- appIdentifier: "@your-co/app-name"
2
- appName: "Your App Name"
3
- appDescription: "Your app description."
4
- visibility: public
5
- publisher: "Your company name"
6
- version: 1.0
7
-
8
- # eventWorkflowTriggerKeyMapping will be used to parse an incoming event into a key that can trigger workflows
9
- # {} indicates a field on the event. You can use nested fields by separating the levels with a '.'
10
- # i.e. an event {details: {eventType: 'apparel'}, actionType: 'create'} can be parsed to apparel|create with the following
11
- eventWorkflowTriggerKeyMapping: "{details.eventType}|{actionType}"
12
-
13
- appConfiguration:
14
- apiHost:
15
- label: "API Host"
16
- propertyType: "string"
17
- userName:
18
- label: "User Name"
19
- propertyType: "string"
20
- password:
21
- label: "Password"
22
- propertyType: "string"
23
-
24
- actions:
25
- updateProduct:
26
- handler: actions/example/action.js
27
- name: "Update Product"
28
- description: "Updates a product in the destination system."
29
- actionConfiguration:
30
- email:
31
- label: "Email Address"
32
- propertyType: "string"
33
-
34
- triggers:
35
- trigger1:
36
- key: product|create
37
- name: "External Product Created"
38
- external: true
39
- description: "Triggers on externally created products"
40
-
41
- # workflows:
42
- # workflow1:
43
- # triggerKey: item|update
44
- # isActive: true
45
- # name: test wf from cli
46
- # workflowDefinition:
47
- # paths:
48
- # - conditional: "true"
49
- # actionDefinitionConfigs:
50
- # - action: updateProduct
51
- # name: handle product update
52
- # config:
53
- # message: "hello world"
@@ -1,23 +0,0 @@
1
- {
2
- "name": "test-app",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "bin": {
7
- "@contrail/contrail-cli": "bin/init",
8
- "contrail": "bin/init"
9
- },
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1"
15
- },
16
- "keywords": [
17
- ],
18
- "author": "",
19
- "license": "ISC",
20
- "dependencies": {
21
- "chalk": "^4.0.0"
22
- }
23
- }
@@ -1,14 +0,0 @@
1
- {
2
- "name": "test-app",
3
- "version": "1.0.0",
4
- "lockfileVersion": 1,
5
- "requires": true,
6
- "dependencies": {
7
- "typescript": {
8
- "version": "4.7.4",
9
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
10
- "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
11
- "dev": true
12
- }
13
- }
14
- }
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2017",
4
- "module": "esnext",
5
- "declaration": true,
6
- "esModuleInterop": true,
7
- "outDir": "./lib",
8
- "strict": false,
9
- "experimentalDecorators": true,
10
- "strictPropertyInitialization": false,
11
- "noImplicitAny": false,
12
- "emitDecoratorMetadata": true,
13
- "skipLibCheck": true,
14
- "moduleResolution": "node",
15
- "lib": [
16
- "es5",
17
- "ES2015",
18
- "ES2016",
19
- "ES2017",
20
- "ES2020",
21
- "dom",
22
- "esnext.asynciterable"
23
- ]
24
- },
25
- "include": [
26
- "src"
27
- ],
28
- "exclude": [
29
- "node_modules",
30
- "**/__tests__/*"
31
- ]
32
- }