@contrail/cli 1.0.31 → 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 +10 -0
- package/lib/apps/deploy-app/docker-action-builder.js +97 -0
- package/lib/apps/deploy-app/interfaces.d.ts +76 -0
- package/lib/apps/deploy-app/interfaces.js +4 -0
- package/lib/apps/deploy-app/workflow-definition-deployer.js +1 -1
- package/lib/apps/deploy-app/workflow-deployer.d.ts +10 -0
- package/lib/apps/deploy-app/workflow-deployer.js +87 -0
- package/lib/auth/login.js +5 -5
- package/lib/cli.js +2 -1
- 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.js +6 -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 +7 -5
- 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 +124 -124
- package/src/cli.ts +115 -115
- 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 +9 -9
- 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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App, AppDeclaration, AppActionDeclaration } from '../../interfaces';
|
|
2
|
+
export declare class ActionsDeployer {
|
|
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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
4
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
export class ActionsDeployer {
|
|
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);
|
|
14
|
+
}
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
31
|
+
}
|
|
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);
|
|
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;
|
|
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);
|
|
60
|
+
}
|
|
61
|
+
else if (!(actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) && existingActionDefinition.configProperties) {
|
|
62
|
+
configProperties = null;
|
|
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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Describes the derivative JSON / object represented
|
|
2
|
+
* in app.yml file.
|
|
3
|
+
*/
|
|
4
|
+
export interface AppDeclaration {
|
|
5
|
+
appIdentifier: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
appDescription?: string;
|
|
8
|
+
visibility: 'private' | 'public';
|
|
9
|
+
publisher: string;
|
|
10
|
+
version: string;
|
|
11
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
12
|
+
thumbnail?: string;
|
|
13
|
+
keywords?: Array<string>;
|
|
14
|
+
actions?: {
|
|
15
|
+
[key: string]: AppActionDeclaration;
|
|
16
|
+
};
|
|
17
|
+
appConfiguration: ConfigPropertyElements;
|
|
18
|
+
triggers: {
|
|
19
|
+
[key: string]: AppTriggerDeclaration;
|
|
20
|
+
};
|
|
21
|
+
isDockerBased?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ConfigPropertyElements {
|
|
24
|
+
[key: string]: ConfigPropertyElement;
|
|
25
|
+
}
|
|
26
|
+
export interface ConfigPropertyElement {
|
|
27
|
+
propertyType: string;
|
|
28
|
+
options?: any[];
|
|
29
|
+
label: string;
|
|
30
|
+
}
|
|
31
|
+
export interface AppActionDeclaration {
|
|
32
|
+
handler: string;
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
actionConfiguration?: ConfigPropertyElements;
|
|
36
|
+
}
|
|
37
|
+
export interface AppTriggerDeclaration {
|
|
38
|
+
key: string;
|
|
39
|
+
name: string;
|
|
40
|
+
external?: boolean;
|
|
41
|
+
description?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface App {
|
|
44
|
+
id: string;
|
|
45
|
+
identifier: string;
|
|
46
|
+
name: string;
|
|
47
|
+
public: boolean;
|
|
48
|
+
description?: string;
|
|
49
|
+
publisher: string;
|
|
50
|
+
thumbnail: string;
|
|
51
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
52
|
+
configProperties?: ConfigProperty[];
|
|
53
|
+
triggerKeyDefinitions?: TriggerKeyDefinition[];
|
|
54
|
+
}
|
|
55
|
+
export declare class ConfigProperty {
|
|
56
|
+
slug: string;
|
|
57
|
+
propertyType: string;
|
|
58
|
+
options?: any[];
|
|
59
|
+
label: string;
|
|
60
|
+
}
|
|
61
|
+
export interface EventWorkflowActionDefinition {
|
|
62
|
+
id?: string;
|
|
63
|
+
identifier?: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
executeFunctionString?: string;
|
|
66
|
+
ownerKey?: string;
|
|
67
|
+
public?: boolean;
|
|
68
|
+
configProperties?: ConfigProperty[];
|
|
69
|
+
isDockerBased?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export declare class TriggerKeyDefinition {
|
|
72
|
+
name: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
triggerKey: string;
|
|
75
|
+
external?: boolean;
|
|
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
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App, AppDeclaration, WorkflowTemplateDeclaration } from './interfaces';
|
|
2
|
+
export declare class WorkflowDeployer {
|
|
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
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
}
|
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
|
@@ -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': {
|
|
@@ -204,6 +204,7 @@ const helpSections = [
|
|
|
204
204
|
content: [
|
|
205
205
|
'load Load colors from a CSV. Headers (name, hex, red,',
|
|
206
206
|
'. green, blue) are required.',
|
|
207
|
+
// 'delete Delete all colors.',
|
|
207
208
|
],
|
|
208
209
|
},
|
|
209
210
|
{
|
|
@@ -7,7 +7,7 @@ export async function deleteColors() {
|
|
|
7
7
|
try {
|
|
8
8
|
await authUser();
|
|
9
9
|
const colors = await getExistingColors();
|
|
10
|
-
console.log(
|
|
10
|
+
console.log('Deleting %s colors', colors.length);
|
|
11
11
|
for (const color of colors) {
|
|
12
12
|
await deleteColor(color);
|
|
13
13
|
}
|
|
@@ -21,10 +21,10 @@ export async function deleteColors() {
|
|
|
21
21
|
export async function loadColors() {
|
|
22
22
|
try {
|
|
23
23
|
await authUser();
|
|
24
|
-
console.log(
|
|
25
|
-
console.log(
|
|
24
|
+
console.log('%s Getting Existing Colors', chalk.yellow.bold('COLORS'));
|
|
25
|
+
console.log('%s Uploading', chalk.yellow.bold('COLORS'));
|
|
26
26
|
await uploadColors();
|
|
27
|
-
console.log(
|
|
27
|
+
console.log('%s Uploaded', chalk.yellow.bold('COLORS'));
|
|
28
28
|
}
|
|
29
29
|
catch (e) {
|
|
30
30
|
console.log(`%s Loading Colors Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
@@ -33,7 +33,7 @@ export async function loadColors() {
|
|
|
33
33
|
console.log('%s Loading Colors Complete.', chalk.green.bold('COMPLETE'));
|
|
34
34
|
}
|
|
35
35
|
async function getLocalColors() {
|
|
36
|
-
console.log(
|
|
36
|
+
console.log('loading colors from local file');
|
|
37
37
|
const TARGET_DIR = process.cwd();
|
|
38
38
|
try {
|
|
39
39
|
const separator = getSeparatorByPlatform();
|
|
@@ -45,10 +45,10 @@ async function getLocalColors() {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
async function getExistingColors() {
|
|
48
|
-
console.log(
|
|
48
|
+
console.log('%s Getting Existing Colors', chalk.yellow.bold('COLORS'));
|
|
49
49
|
try {
|
|
50
50
|
const result = await new Entities().get({ entityName: 'color', take: 3000 }); //, useSearch: false }); Not in EntitiesClientGetOptions yet
|
|
51
|
-
console.log(
|
|
51
|
+
console.log('Found %s existing colors', result.length);
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
@@ -69,7 +69,7 @@ async function uploadColors() {
|
|
|
69
69
|
const existingNamesValues = existingColors.filter(x => x.name).map(x => x.name);
|
|
70
70
|
for (const color of colors) {
|
|
71
71
|
if (existingNamesValues.includes(color.name)) {
|
|
72
|
-
console.log(
|
|
72
|
+
console.log('%s SKIPPING %s (%s)', chalk.yellow.bold('COLORS'), color.hex, color.name);
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
if (color.hex.length > 1 && color.hex[0] === '#') {
|
package/lib/config/config.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function initializeVibeIQConfig() {
|
|
|
9
9
|
await fsPromises.mkdir(configDirectoryLocation, { recursive: true });
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
|
-
console.error(
|
|
12
|
+
console.error('could not initialize vibeiq directory');
|
|
13
13
|
throw e;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
@@ -48,7 +48,7 @@ export async function writeVibeIQConfig(config) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
export async function getConfig() {
|
|
51
|
-
console.debug(
|
|
51
|
+
console.debug('getting config from file system');
|
|
52
52
|
return await readVibeIQConfig();
|
|
53
53
|
}
|
|
54
54
|
export async function deleteConfigs(configNames) {
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export interface AppDeclaration {
|
|
|
21
21
|
workflows?: {
|
|
22
22
|
[key: string]: WorkflowDefinition | WorkflowTemplateDeclaration;
|
|
23
23
|
};
|
|
24
|
-
isDockerBased?: boolean;
|
|
25
24
|
dockerImageRef?: string;
|
|
26
25
|
}
|
|
27
26
|
export interface ConfigPropertyElements {
|
|
@@ -38,6 +37,7 @@ export interface AppActionDeclaration {
|
|
|
38
37
|
name: string;
|
|
39
38
|
description?: string;
|
|
40
39
|
actionConfiguration?: ConfigPropertyElements;
|
|
40
|
+
async?: boolean;
|
|
41
41
|
}
|
|
42
42
|
export interface AppTriggerDeclaration {
|
|
43
43
|
key: string;
|
|
@@ -116,7 +116,7 @@ export interface EventWorkflowActionDefinition {
|
|
|
116
116
|
ownerKey?: string;
|
|
117
117
|
public?: boolean;
|
|
118
118
|
configProperties?: ConfigProperty[];
|
|
119
|
-
|
|
119
|
+
async?: boolean;
|
|
120
120
|
}
|
|
121
121
|
export declare class TriggerKeyDefinition {
|
|
122
122
|
name: string;
|
package/lib/types/interfaces.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,11 +9,11 @@ export async function MergeOptionSets(args) {
|
|
|
9
9
|
if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
|
|
10
10
|
throw new Error('File name must be included.');
|
|
11
11
|
}
|
|
12
|
-
console.log(
|
|
12
|
+
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET MERGE'));
|
|
13
13
|
const fileLocation = args[3];
|
|
14
14
|
console.log('Using File: ', fileLocation);
|
|
15
15
|
await mergeOptionSets(fileLocation);
|
|
16
|
-
console.log(
|
|
16
|
+
console.log('%s Merged', chalk.yellow.bold('OPTION SET MERGE'));
|
|
17
17
|
}
|
|
18
18
|
catch (e) {
|
|
19
19
|
console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
@@ -9,11 +9,11 @@ export async function ParseOptionSetsLocalFiles(args) {
|
|
|
9
9
|
if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
|
|
10
10
|
throw new Error('File name must be included.');
|
|
11
11
|
}
|
|
12
|
-
console.log(
|
|
12
|
+
console.log('%s Importing local file', chalk.yellow.bold('OPTION SET PARSE'));
|
|
13
13
|
const fileLocation = args[3];
|
|
14
14
|
console.log('Using File: ', fileLocation);
|
|
15
15
|
await parseOptionSetsLocalFiles(fileLocation);
|
|
16
|
-
console.log(
|
|
16
|
+
console.log('%s Parsed', chalk.yellow.bold('OPTION SET PARSE'));
|
|
17
17
|
}
|
|
18
18
|
catch (e) {
|
|
19
19
|
console.log(`%s PARSE Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
@@ -8,9 +8,9 @@ export async function UploadOptionSets(args) {
|
|
|
8
8
|
try {
|
|
9
9
|
const userConfig = await authUser();
|
|
10
10
|
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
11
|
-
console.log(
|
|
11
|
+
console.log('%s Uploading', chalk.yellow.bold('OPTION SETS'));
|
|
12
12
|
await uploadOptionSets();
|
|
13
|
-
console.log(
|
|
13
|
+
console.log('%s Uploaded', chalk.yellow.bold('OPTION SETS'));
|
|
14
14
|
}
|
|
15
15
|
catch (e) {
|
|
16
16
|
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|