@contrail/cli 1.0.39 → 1.0.41

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 (60) hide show
  1. package/lib/api/apps.d.ts +13 -0
  2. package/lib/{apps/app-api.js → api/apps.js} +27 -1
  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/install-app/app-installer.js +21 -4
  11. package/lib/apps/upgrade-app/app-upgrader.js +1 -1
  12. package/lib/cli.js +121 -45
  13. package/lib/config/config.d.ts +2 -2
  14. package/lib/config/configCommands.d.ts +1 -0
  15. package/lib/config/configCommands.js +25 -1
  16. package/lib/interfaces.d.ts +65 -1
  17. package/lib/interfaces.js +21 -0
  18. package/lib/types/parse-types.d.ts +1 -0
  19. package/lib/types/parse-types.js +48 -1
  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/{workflows/workflow-template-deployer.d.ts → workflow-templates/local-workflow-template-deployer.d.ts} +1 -4
  25. package/lib/{workflows/workflow-template-deployer.js → workflow-templates/local-workflow-template-deployer.js} +9 -34
  26. package/lib/workflow-templates/workflow-template-commands.d.ts +4 -0
  27. package/lib/{workflows/workflowCommands.js → workflow-templates/workflow-template-commands.js} +9 -4
  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 +2 -2
  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/cli.ts +123 -45
  39. package/src/config/config.ts +2 -2
  40. package/src/config/configCommands.ts +26 -1
  41. package/src/interfaces.ts +76 -6
  42. package/src/types/parse-types.ts +58 -1
  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/lib/apps/app-api.d.ts +0 -6
  49. package/lib/apps/deploy-app/docker-action-builder.d.ts +0 -10
  50. package/lib/apps/deploy-app/docker-action-builder.js +0 -97
  51. package/lib/apps/deploy-app/interfaces.d.ts +0 -76
  52. package/lib/apps/deploy-app/interfaces.js +0 -4
  53. package/lib/apps/deploy-app/workflow-definition-deployer.d.ts +0 -10
  54. package/lib/apps/deploy-app/workflow-definition-deployer.js +0 -94
  55. package/lib/apps/deploy-app/workflow-deployer.d.ts +0 -10
  56. package/lib/apps/deploy-app/workflow-deployer.js +0 -87
  57. package/lib/workflows/workflowCommands.d.ts +0 -3
  58. package/src/apps/app-api.ts +0 -66
  59. package/src/apps/deploy-app/workflow-definition-deployer.ts +0 -118
  60. package/tslint.json +0 -57
@@ -1,87 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
4
- export class WorkflowDeployer {
5
- async deployWorkflows(appDeclaration, app) {
6
- // FETCH ALL WORKFLOWS FROM THE API.
7
- const existingWorkflows = await this.getWorkflowsForApp(app);
8
- // UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
9
- console.log('%s \tDeploying workflows.', chalk.yellow.bold('WORKFLOW'));
10
- for (const workflowKey of Object.keys(appDeclaration.workflows)) {
11
- await this.deployWorkflow(workflowKey, appDeclaration.workflows[workflowKey], app, existingWorkflows, appDeclaration);
12
- }
13
- }
14
- async getWorkflowsForApp(app) {
15
- return await new Entities().get({
16
- entityName: 'event-workflow-template',
17
- criteria: { ownerKey: `app:${app.id}` },
18
- });
19
- }
20
- async deployWorkflow(workflowKey, workflow, app, existingWorkflows, appDeclaration) {
21
- console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
22
- const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
23
- const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
24
- if (existingDefinition) {
25
- return await this.updateWorkflowDefinition(existingDefinition, workflow, app, appDeclaration);
26
- }
27
- return await this.createNewWorkflowDefinition(workflowKey, workflow, app, appDeclaration);
28
- }
29
- async createNewWorkflowDefinition(workflowKey, workflowDeclaration, app, appDeclaration) {
30
- await this.populateActionIds(workflowDeclaration, appDeclaration, app);
31
- const newObject = {
32
- identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
33
- name: workflowDeclaration.name,
34
- ownerKey: `app:${app.id}`,
35
- triggerKey: workflowDeclaration.triggerKey,
36
- workflowDefinition: workflowDeclaration.workflowDefinition,
37
- isActive: workflowDeclaration.isActive,
38
- supportingAppId: workflowDeclaration.supportingAppId,
39
- messageGroupId: workflowDeclaration.messageGroupId,
40
- parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
41
- };
42
- const workflowTemplate = await new Entities().create({
43
- entityName: 'event-workflow-template',
44
- object: newObject,
45
- });
46
- console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
47
- return workflowTemplate;
48
- }
49
- async populateActionIds(workflowDeclaration, appDeclaration, app) {
50
- var _a;
51
- let availableAppActions = await getActionsForApp(app);
52
- if (!((_a = workflowDeclaration.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
53
- return;
54
- }
55
- for (const path of workflowDeclaration.workflowDefinition.paths) {
56
- if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
57
- continue;
58
- }
59
- for (const actionConfiguration of path.actionDefinitionConfigs) {
60
- const actionKey = actionConfiguration.action;
61
- const action = availableAppActions.find(action => action.identifier === getActionDeclarationIdentifier(actionKey, app));
62
- if (!action) {
63
- throw new Error(`Could not find action ${actionKey} declared in ${workflowDeclaration.name}`);
64
- }
65
- actionConfiguration.id = action.id;
66
- }
67
- }
68
- }
69
- async updateWorkflowDefinition(existingWorkflowDefinition, workflowDeclaration, app, appDeclaration) {
70
- await this.populateActionIds(workflowDeclaration, appDeclaration, app);
71
- const updates = Object.assign(new Object(), {
72
- name: workflowDeclaration.name,
73
- triggerKey: workflowDeclaration.triggerKey,
74
- workflowDefinition: workflowDeclaration.workflowDefinition
75
- });
76
- const updatedWorkflowDefinition = await new Entities().update({
77
- entityName: 'event-workflow-template',
78
- id: existingWorkflowDefinition.id,
79
- object: updates,
80
- });
81
- console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW'));
82
- return updatedWorkflowDefinition;
83
- }
84
- getWorkflowDeclarationIdentifier(actionKey, app) {
85
- return app.identifier + ':' + actionKey;
86
- }
87
- }
@@ -1,3 +0,0 @@
1
- export declare function deleteWorkflowTemplate(): Promise<void>;
2
- export declare function deployWorkflowTemplate(): Promise<void>;
3
- export declare function listWorkflowTemplate(): Promise<any>;
@@ -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
- }