@contrail/cli 1.0.30 → 1.0.32
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/.eslintrc.js +53 -0
- package/lib/apps/deploy-app/actions-deployer.js +12 -3
- package/lib/apps/deploy-app/app-deployer.js +2 -3
- package/lib/apps/deploy-app/app-template-parsers.js +1 -1
- package/lib/apps/deploy-app/docker-action-builder.d.ts +7 -7
- package/lib/apps/deploy-app/docker-action-builder.js +83 -83
- package/lib/apps/deploy-app/interfaces.d.ts +8 -8
- package/lib/apps/deploy-app/workflow-definition-deployer.js +1 -1
- package/lib/apps/deploy-app/workflow-deployer.d.ts +7 -7
- package/lib/apps/deploy-app/workflow-deployer.js +77 -77
- package/lib/auth/login.js +5 -5
- package/lib/cli.js +9 -2
- package/lib/colors/color-loader.js +8 -8
- package/lib/config/config.js +2 -2
- package/lib/interfaces.d.ts +2 -2
- package/lib/types/interfaces.js +1 -0
- package/lib/types/option-set-merger.js +2 -2
- package/lib/types/option-set-parser.js +2 -2
- package/lib/types/option-set-uploader.js +2 -2
- package/lib/types/parse-types.d.ts +1 -0
- package/lib/types/parse-types.js +47 -6
- package/lib/types/types-extractor.js +4 -4
- package/lib/types/types-properties-merger.js +2 -2
- package/lib/types/types-uploader.d.ts +1 -1
- package/lib/types/types-uploader.js +6 -6
- package/package.json +8 -6
- package/src/apps/deploy-app/actions-deployer.ts +17 -10
- package/src/apps/deploy-app/app-deployer.ts +3 -4
- package/src/apps/deploy-app/workflow-definition-deployer.ts +3 -3
- package/src/auth/login.ts +125 -125
- package/src/cli.ts +126 -120
- package/src/colors/color-loader.ts +16 -16
- package/src/config/config.ts +9 -11
- package/src/config/configCommands.ts +1 -1
- package/src/interfaces.ts +9 -10
- package/src/types/csv-parser.ts +1 -1
- package/src/types/option-set-merger.ts +9 -9
- package/src/types/option-set-parser.ts +5 -6
- package/src/types/option-set-uploader.ts +2 -2
- package/src/types/parse-types.ts +61 -12
- package/src/types/types-extractor.ts +5 -5
- package/src/types/types-properties-merger.ts +6 -6
- package/src/types/types-uploader.ts +31 -31
- package/src/workflows/workflow-template-deployer.ts +2 -4
- package/src/workflows/workflowCommands.ts +0 -1
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/typescript/actions/exampleAction.ts +1 -1
- package/templates/typescript/app.yml +1 -1
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
node: true
|
|
6
|
+
|
|
7
|
+
},
|
|
8
|
+
extends: [
|
|
9
|
+
'eslint:recommended',
|
|
10
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
11
|
+
'plugin:@typescript-eslint/recommended'
|
|
12
|
+
],
|
|
13
|
+
parser: '@typescript-eslint/parser',
|
|
14
|
+
parserOptions: {
|
|
15
|
+
ecmaVersion: 'latest',
|
|
16
|
+
sourceType: 'module'
|
|
17
|
+
},
|
|
18
|
+
plugins: [
|
|
19
|
+
'@typescript-eslint',
|
|
20
|
+
'unused-imports'
|
|
21
|
+
],
|
|
22
|
+
rules: {
|
|
23
|
+
indent: [
|
|
24
|
+
'error',
|
|
25
|
+
2
|
|
26
|
+
],
|
|
27
|
+
'linebreak-style': [
|
|
28
|
+
'error',
|
|
29
|
+
'unix'
|
|
30
|
+
],
|
|
31
|
+
'quote-props': ['error', 'as-needed'],
|
|
32
|
+
quotes: [
|
|
33
|
+
'error',
|
|
34
|
+
'single'
|
|
35
|
+
],
|
|
36
|
+
semi: [
|
|
37
|
+
'error',
|
|
38
|
+
'always'
|
|
39
|
+
],
|
|
40
|
+
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
|
|
41
|
+
'no-trailing-spaces': 'error',
|
|
42
|
+
'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'],
|
|
43
|
+
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
|
|
44
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
45
|
+
'@typescript-eslint/no-var-requires': 'warn',
|
|
46
|
+
'no-unused-vars': 'off',
|
|
47
|
+
'unused-imports/no-unused-imports': 'error',
|
|
48
|
+
'unused-imports/no-unused-vars': [
|
|
49
|
+
'warn',
|
|
50
|
+
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -21,14 +21,21 @@ export class ActionsDeployer {
|
|
|
21
21
|
const existingActions = await getActionsForApp(app);
|
|
22
22
|
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
23
23
|
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
24
|
+
let appActionIdentifiers = [];
|
|
24
25
|
if (appDeclaration.actions) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const localActionKeys = Object.keys(appDeclaration.actions);
|
|
27
|
+
appActionIdentifiers = localActionKeys.map(x => getActionDeclarationIdentifier(x, app));
|
|
28
|
+
if ((localActionKeys === null || localActionKeys === void 0 ? void 0 : localActionKeys.length) > 0) {
|
|
29
|
+
for (const actionKey of localActionKeys) {
|
|
28
30
|
await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
const toDelete = existingActions.filter(x => !appActionIdentifiers.includes(x.identifier));
|
|
35
|
+
for (const action of toDelete) {
|
|
36
|
+
console.log(`%s \tDeleting action: ${action.identifier}`, chalk.yellow.bold('ACTION'));
|
|
37
|
+
await deleteAction(action.id);
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
async deployAction(actionKey, actionDeclaration, app, existingActions) {
|
|
34
41
|
console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
|
|
@@ -52,6 +59,7 @@ export class ActionsDeployer {
|
|
|
52
59
|
ownerKey: `app:${app.id}`,
|
|
53
60
|
public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
|
|
54
61
|
configProperties,
|
|
62
|
+
async: actionDeclaration.async,
|
|
55
63
|
};
|
|
56
64
|
const functionString = await this.getFunction(actionDeclaration);
|
|
57
65
|
if (functionString) {
|
|
@@ -76,6 +84,7 @@ export class ActionsDeployer {
|
|
|
76
84
|
name: actionDeclaration.name,
|
|
77
85
|
public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
|
|
78
86
|
configProperties,
|
|
87
|
+
async: actionDeclaration.async,
|
|
79
88
|
};
|
|
80
89
|
const functionString = await this.getFunction(actionDeclaration);
|
|
81
90
|
if (functionString) {
|
|
@@ -8,11 +8,11 @@ export class AppDeployer {
|
|
|
8
8
|
async deploy(appDeclaration) {
|
|
9
9
|
let app = await this.getExistingApp(appDeclaration);
|
|
10
10
|
if (!app) {
|
|
11
|
-
console.log(
|
|
11
|
+
console.log('%s Creating new app.', chalk.yellow.bold('APP'));
|
|
12
12
|
app = await this.createNewApp(appDeclaration);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
console.log(
|
|
15
|
+
console.log('%s Updating existing app.', chalk.yellow.bold('APP'));
|
|
16
16
|
app = await this.updateExistingApp(appDeclaration, app);
|
|
17
17
|
}
|
|
18
18
|
await new ActionsDeployer().deployActions(appDeclaration, app);
|
|
@@ -57,7 +57,6 @@ export class AppDeployer {
|
|
|
57
57
|
keywords: appDeclaration.keywords,
|
|
58
58
|
configProperties,
|
|
59
59
|
triggerKeyDefinitions,
|
|
60
|
-
isDockerBased: appDeclaration.isDockerBased,
|
|
61
60
|
dockerImageRef: appDeclaration.dockerImageRef,
|
|
62
61
|
};
|
|
63
62
|
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
@@ -25,7 +25,7 @@ export class ConfigPropertiesParser {
|
|
|
25
25
|
const config = {
|
|
26
26
|
label: declaration.label,
|
|
27
27
|
slug: configKey,
|
|
28
|
-
propertyType: declaration.propertyType,
|
|
28
|
+
propertyType: declaration.propertyType, // TODO should support options
|
|
29
29
|
};
|
|
30
30
|
if (declaration.options) {
|
|
31
31
|
config.options = declaration.options;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { App, AppDeclaration, AppActionDeclaration } from '../../interfaces';
|
|
2
2
|
export declare class ActionsDeployer {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
deployActions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
+
getActionsForApp(app: App): Promise<any>;
|
|
5
|
+
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
+
private createNewActionDefinition;
|
|
7
|
+
private updateActionDefinition;
|
|
8
|
+
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
+
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
10
|
}
|
|
@@ -4,94 +4,94 @@ import { ConfigPropertiesParser } from './app-template-parsers';
|
|
|
4
4
|
import { getSeparatorByPlatform } from '../../common';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
export class ActionsDeployer {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
7
|
+
async deployActions(appDeclaration, app) {
|
|
8
|
+
// FETCH ALL ACTIONS FROM THE API.
|
|
9
|
+
const existingActions = await this.getActionsForApp(app);
|
|
10
|
+
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
11
|
+
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
12
|
+
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
13
|
+
await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
}
|
|
16
|
+
async getActionsForApp(app) {
|
|
17
|
+
return await new Entities().get({
|
|
18
|
+
entityName: 'event-workflow-action-definition',
|
|
19
|
+
criteria: { ownerKey: `app:${app.id}` },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async deployAction(actionKey, actionDeclaration, app, existingActions) {
|
|
23
|
+
console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
|
|
24
|
+
const identifier = this.getActionDeclarationIdentifier(actionKey, app);
|
|
25
|
+
const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
|
|
26
|
+
if (!existingDefinition) {
|
|
27
|
+
await this.createNewActionDefinition(actionKey, actionDeclaration, app);
|
|
21
28
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const identifier = this.getActionDeclarationIdentifier(actionKey, app);
|
|
25
|
-
const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
|
|
26
|
-
if (!existingDefinition) {
|
|
27
|
-
await this.createNewActionDefinition(actionKey, actionDeclaration, app);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
31
|
-
}
|
|
29
|
+
else {
|
|
30
|
+
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const newObject = {
|
|
39
|
-
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
40
|
-
name: actionDeclaration.name,
|
|
41
|
-
ownerKey: `app:${app.id}`,
|
|
42
|
-
public: app.public,
|
|
43
|
-
configProperties,
|
|
44
|
-
};
|
|
45
|
-
const functionString = await this.getFunction(actionDeclaration);
|
|
46
|
-
if (functionString) {
|
|
47
|
-
newObject.executeFunctionString = functionString;
|
|
48
|
-
}
|
|
49
|
-
const actionDefinition = await new Entities().create({
|
|
50
|
-
entityName: 'event-workflow-action-definition',
|
|
51
|
-
object: newObject,
|
|
52
|
-
});
|
|
53
|
-
console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
|
|
54
|
-
return actionDefinition;
|
|
32
|
+
}
|
|
33
|
+
async createNewActionDefinition(actionKey, actionDeclaration, app) {
|
|
34
|
+
let configProperties;
|
|
35
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
36
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
55
37
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
67
|
-
configProperties,
|
|
68
|
-
};
|
|
69
|
-
const functionString = await this.getFunction(actionDeclaration);
|
|
70
|
-
if (functionString) {
|
|
71
|
-
updates.executeFunctionString = functionString;
|
|
72
|
-
}
|
|
73
|
-
const actionDefinition = await new Entities().update({
|
|
74
|
-
entityName: 'event-workflow-action-definition',
|
|
75
|
-
id: existingActionDefinition.id,
|
|
76
|
-
object: updates,
|
|
77
|
-
});
|
|
78
|
-
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
79
|
-
return actionDefinition;
|
|
38
|
+
const newObject = {
|
|
39
|
+
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
40
|
+
name: actionDeclaration.name,
|
|
41
|
+
ownerKey: `app:${app.id}`,
|
|
42
|
+
public: app.public,
|
|
43
|
+
configProperties,
|
|
44
|
+
};
|
|
45
|
+
const functionString = await this.getFunction(actionDeclaration);
|
|
46
|
+
if (functionString) {
|
|
47
|
+
newObject.executeFunctionString = functionString;
|
|
80
48
|
}
|
|
81
|
-
|
|
82
|
-
|
|
49
|
+
const actionDefinition = await new Entities().create({
|
|
50
|
+
entityName: 'event-workflow-action-definition',
|
|
51
|
+
object: newObject,
|
|
52
|
+
});
|
|
53
|
+
console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
|
|
54
|
+
return actionDefinition;
|
|
55
|
+
}
|
|
56
|
+
async updateActionDefinition(existingActionDefinition, actionDeclaration) {
|
|
57
|
+
let configProperties;
|
|
58
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
59
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
83
60
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!actionDeclaration.handler.endsWith('.js')) {
|
|
89
|
-
throw new Error('Action handler must be a .js file.');
|
|
90
|
-
}
|
|
91
|
-
const CURRENT_DIR = process.cwd();
|
|
92
|
-
const separator = getSeparatorByPlatform();
|
|
93
|
-
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
-
const content = fs.readFileSync(functionLocation);
|
|
95
|
-
return content.toString();
|
|
61
|
+
else if (!(actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) && existingActionDefinition.configProperties) {
|
|
62
|
+
configProperties = null;
|
|
96
63
|
}
|
|
64
|
+
const updates = {
|
|
65
|
+
name: actionDeclaration.name,
|
|
66
|
+
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
67
|
+
configProperties,
|
|
68
|
+
};
|
|
69
|
+
const functionString = await this.getFunction(actionDeclaration);
|
|
70
|
+
if (functionString) {
|
|
71
|
+
updates.executeFunctionString = functionString;
|
|
72
|
+
}
|
|
73
|
+
const actionDefinition = await new Entities().update({
|
|
74
|
+
entityName: 'event-workflow-action-definition',
|
|
75
|
+
id: existingActionDefinition.id,
|
|
76
|
+
object: updates,
|
|
77
|
+
});
|
|
78
|
+
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
79
|
+
return actionDefinition;
|
|
80
|
+
}
|
|
81
|
+
getActionDeclarationIdentifier(actionKey, app) {
|
|
82
|
+
return app.identifier + ':' + actionKey;
|
|
83
|
+
}
|
|
84
|
+
async getFunction(actionDeclaration) {
|
|
85
|
+
if (!actionDeclaration.handler) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!actionDeclaration.handler.endsWith('.js')) {
|
|
89
|
+
throw new Error('Action handler must be a .js file.');
|
|
90
|
+
}
|
|
91
|
+
const CURRENT_DIR = process.cwd();
|
|
92
|
+
const separator = getSeparatorByPlatform();
|
|
93
|
+
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
+
const content = fs.readFileSync(functionLocation);
|
|
95
|
+
return content.toString();
|
|
96
|
+
}
|
|
97
97
|
}
|
|
@@ -53,10 +53,10 @@ export interface App {
|
|
|
53
53
|
triggerKeyDefinitions?: TriggerKeyDefinition[];
|
|
54
54
|
}
|
|
55
55
|
export declare class ConfigProperty {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
slug: string;
|
|
57
|
+
propertyType: string;
|
|
58
|
+
options?: any[];
|
|
59
|
+
label: string;
|
|
60
60
|
}
|
|
61
61
|
export interface EventWorkflowActionDefinition {
|
|
62
62
|
id?: string;
|
|
@@ -69,8 +69,8 @@ export interface EventWorkflowActionDefinition {
|
|
|
69
69
|
isDockerBased?: boolean;
|
|
70
70
|
}
|
|
71
71
|
export declare class TriggerKeyDefinition {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
name: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
triggerKey: string;
|
|
75
|
+
external?: boolean;
|
|
76
76
|
}
|
|
@@ -53,7 +53,7 @@ export class WorkflowDefinitionDeployer {
|
|
|
53
53
|
}
|
|
54
54
|
async populateActionIds(workflowDefinition, app) {
|
|
55
55
|
var _a;
|
|
56
|
-
|
|
56
|
+
const availableAppActions = await getActionsForApp(app);
|
|
57
57
|
if (!((_a = workflowDefinition.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { App, AppDeclaration, WorkflowTemplateDeclaration } from './interfaces';
|
|
2
2
|
export declare class WorkflowDeployer {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
deployWorkflows(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
+
getWorkflowsForApp(app: App): Promise<any>;
|
|
5
|
+
deployWorkflow(workflowKey: string, workflow: WorkflowTemplateDeclaration, app: App, existingWorkflows: Array<any>, appDeclaration: AppDeclaration): Promise<any>;
|
|
6
|
+
private createNewWorkflowDefinition;
|
|
7
|
+
private populateActionIds;
|
|
8
|
+
private updateWorkflowDefinition;
|
|
9
|
+
getWorkflowDeclarationIdentifier(actionKey: any, app: App): string;
|
|
10
10
|
}
|
|
@@ -2,86 +2,86 @@ import { Entities } from '@contrail/sdk';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
|
|
4
4
|
export class WorkflowDeployer {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
async getWorkflowsForApp(app) {
|
|
15
|
-
return await new Entities().get({
|
|
16
|
-
entityName: 'event-workflow-template',
|
|
17
|
-
criteria: { ownerKey: `app:${app.id}` },
|
|
18
|
-
});
|
|
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);
|
|
19
12
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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;
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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}`);
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
65
|
+
actionConfiguration.id = action.id;
|
|
66
|
+
}
|
|
86
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
87
|
}
|
package/lib/auth/login.js
CHANGED
|
@@ -8,13 +8,13 @@ const CONFIGURATION = {
|
|
|
8
8
|
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
9
|
};
|
|
10
10
|
export async function authUser() {
|
|
11
|
-
console.debug(
|
|
11
|
+
console.debug('authorizing user');
|
|
12
12
|
const config = await getConfig();
|
|
13
13
|
if (config &&
|
|
14
14
|
config.apiUserToken &&
|
|
15
15
|
config.apiGateway &&
|
|
16
16
|
config.orgSlug) {
|
|
17
|
-
console.debug(
|
|
17
|
+
console.debug('populating auth config from fs config');
|
|
18
18
|
Auth.config = {
|
|
19
19
|
apiUserToken: config.apiUserToken,
|
|
20
20
|
apiGateway: config.apiGateway,
|
|
@@ -25,7 +25,7 @@ export async function authUser() {
|
|
|
25
25
|
return await refreshCurrentUserOrg();
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
|
-
console.log(
|
|
28
|
+
console.log('Token expired. Requesting auth credentials...');
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
const questions = [];
|
|
@@ -120,11 +120,11 @@ async function setAuthContext(user, params) {
|
|
|
120
120
|
return refreshCurrentUserOrg();
|
|
121
121
|
}
|
|
122
122
|
async function refreshCurrentUserOrg() {
|
|
123
|
-
console.debug(
|
|
123
|
+
console.debug('refreshing current user org');
|
|
124
124
|
const currentUser = await Request.request('/users/current', {
|
|
125
125
|
method: 'GET',
|
|
126
126
|
headers: {
|
|
127
|
-
|
|
127
|
+
Accept: 'application/json',
|
|
128
128
|
'Content-Type': 'application/json',
|
|
129
129
|
},
|
|
130
130
|
});
|
package/lib/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { UploadOptionSets } from './types/option-set-uploader';
|
|
|
6
6
|
import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
|
|
7
7
|
import { MergeOptionSets } from './types/option-set-merger';
|
|
8
8
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
9
|
-
import { ParseTypesFromFiles, ParseTypesFromLocalFiles } from './types/parse-types';
|
|
9
|
+
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles } from './types/parse-types';
|
|
10
10
|
import { loadColors, deleteColors } from './colors/color-loader';
|
|
11
11
|
import { listConfig, removeConfig } from './config/configCommands';
|
|
12
12
|
import { deleteWorkflowTemplate, deployWorkflowTemplate, listWorkflowTemplate } from './workflows/workflowCommands';
|
|
@@ -62,7 +62,7 @@ export async function cli(args) {
|
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
64
|
case 'uploadTypes': {
|
|
65
|
-
uploadTypes(
|
|
65
|
+
uploadTypes();
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
68
|
case 'uploadOptionSets': {
|
|
@@ -77,6 +77,10 @@ export async function cli(args) {
|
|
|
77
77
|
ParseTypesFromLocalFiles(args);
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
|
+
case 'parseTypesFromTemplateFromLocalFiles': {
|
|
81
|
+
ParseTypesFromTemplateFromLocalFiles(args);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
80
84
|
case 'parseTypesFromFiles': {
|
|
81
85
|
ParseTypesFromFiles(args);
|
|
82
86
|
break;
|
|
@@ -200,6 +204,7 @@ const helpSections = [
|
|
|
200
204
|
content: [
|
|
201
205
|
'load Load colors from a CSV. Headers (name, hex, red,',
|
|
202
206
|
'. green, blue) are required.',
|
|
207
|
+
// 'delete Delete all colors.',
|
|
203
208
|
],
|
|
204
209
|
},
|
|
205
210
|
{
|
|
@@ -221,6 +226,8 @@ const helpSections = [
|
|
|
221
226
|
'parseOptionSetsLocalFiles <File Paths> Parse CSV files into OptionSets',
|
|
222
227
|
'parseTypesFromLocalFiles <File Paths> Parse CSV files into Types and ',
|
|
223
228
|
'. OptionSets from local files.\n',
|
|
229
|
+
'parseTypesFromTemplateFromLocalFiles <File Paths> Parse CSV files into ',
|
|
230
|
+
'. Types and OptionSets from local files.\n',
|
|
224
231
|
'parseTypesFromFiles <fileIds> Parse CSV files into Types and ',
|
|
225
232
|
'. OptionSets from VibeIQ Files.\n',
|
|
226
233
|
'mergeOptionSets <File Path> Merge the OptionSets from an existing',
|