@contrail/cli 2.1.20 → 2.1.22
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/README.md +311 -105
- package/dist/api/apps.js +15 -15
- package/dist/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +1 -1
- package/dist/api/event-workflow-template-definition.d.ts +4 -3
- package/dist/api/event-workflow-templates.d.ts +5 -4
- package/dist/api/event-workflow-templates.js +2 -2
- package/dist/api/types.d.ts +10 -10
- package/dist/api/users.js +4 -2
- package/dist/auth/login.js +12 -14
- package/dist/commands/app/create.d.ts +2 -2
- package/dist/commands/app/create.js +15 -10
- package/dist/commands/app/delete.d.ts +2 -2
- package/dist/commands/app/delete.js +4 -2
- package/dist/commands/app/getApiKey.d.ts +2 -2
- package/dist/commands/app/getApiKey.js +17 -11
- package/dist/commands/app/install.d.ts +2 -2
- package/dist/commands/app/install.js +42 -25
- package/dist/commands/app/publish.d.ts +2 -2
- package/dist/commands/app/publish.js +26 -11
- package/dist/commands/app/uninstall.d.ts +2 -2
- package/dist/commands/app/uninstall.js +20 -11
- package/dist/commands/app/upgrade.d.ts +2 -2
- package/dist/commands/app/upgrade.js +46 -23
- package/dist/commands/basecommand.d.ts +7 -0
- package/dist/commands/basecommand.js +29 -0
- package/dist/commands/colors/deleteAll.d.ts +2 -2
- package/dist/commands/colors/deleteAll.js +8 -5
- package/dist/commands/colors/load.d.ts +2 -2
- package/dist/commands/colors/load.js +10 -7
- package/dist/commands/config/list.d.ts +2 -2
- package/dist/commands/config/list.js +4 -2
- package/dist/commands/config/remove.d.ts +2 -2
- package/dist/commands/config/remove.js +4 -2
- package/dist/commands/config/set.d.ts +3 -2
- package/dist/commands/config/set.js +21 -7
- package/dist/commands/groups/export.d.ts +2 -2
- package/dist/commands/groups/export.js +20 -8
- package/dist/commands/groups/upload.d.ts +3 -3
- package/dist/commands/groups/upload.js +44 -32
- package/dist/commands/instance/export.d.ts +2 -2
- package/dist/commands/instance/export.js +15 -3
- package/dist/commands/instance/import.d.ts +2 -2
- package/dist/commands/instance/import.js +9 -2
- package/dist/commands/loader-process/load.d.ts +2 -2
- package/dist/commands/loader-process/load.js +13 -6
- package/dist/commands/loader-process/upload-and-load.d.ts +2 -2
- package/dist/commands/loader-process/upload-and-load.js +18 -7
- package/dist/commands/projects/export.d.ts +2 -2
- package/dist/commands/projects/export.js +4 -2
- package/dist/commands/projects/list.d.ts +2 -2
- package/dist/commands/projects/list.js +6 -4
- package/dist/commands/projects/load.d.ts +2 -2
- package/dist/commands/projects/load.js +16 -8
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/exportOptionSetHierarchies.js +15 -12
- package/dist/commands/types/getAll.d.ts +2 -2
- package/dist/commands/types/getAll.js +107 -76
- package/dist/commands/types/loadAll.d.ts +2 -2
- package/dist/commands/types/loadAll.js +12 -4
- package/dist/commands/types/mergeOptionSets.d.ts +2 -2
- package/dist/commands/types/mergeOptionSets.js +13 -10
- package/dist/commands/types/mergeTypeProperties.d.ts +2 -2
- package/dist/commands/types/mergeTypeProperties.js +12 -9
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +19 -15
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +102 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsLocalFiles.js +21 -21
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +17 -18
- package/dist/commands/types/parseTypesFromFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromFiles.js +14 -8
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromLocalFiles.js +10 -7
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +11 -8
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +11 -8
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetHierarchies.js +44 -32
- package/dist/commands/types/uploadOptionSets.d.ts +2 -2
- package/dist/commands/types/uploadOptionSets.js +21 -13
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +26 -19
- package/dist/commands/types/uploadRuleSets.d.ts +2 -2
- package/dist/commands/types/uploadRuleSets.js +34 -26
- package/dist/commands/types/uploadTypePolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePolicies.js +37 -29
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePropertyPolicies.js +38 -30
- package/dist/commands/types/uploadTypes.d.ts +2 -2
- package/dist/commands/types/uploadTypes.js +10 -4
- package/dist/commands/types/uploadUsageInfo.d.ts +2 -2
- package/dist/commands/types/uploadUsageInfo.js +32 -24
- package/dist/commands/users/export.d.ts +2 -2
- package/dist/commands/users/export.js +15 -4
- package/dist/commands/users/upload.d.ts +2 -2
- package/dist/commands/users/upload.js +6 -4
- package/dist/commands/webhooks/create.d.ts +2 -2
- package/dist/commands/webhooks/create.js +8 -6
- package/dist/commands/webhooks/delete.d.ts +2 -2
- package/dist/commands/webhooks/delete.js +8 -5
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +2 -2
- package/dist/commands/webhooks/getWebhookTrigger.js +10 -9
- package/dist/commands/webhooks/list.d.ts +2 -2
- package/dist/commands/webhooks/list.js +8 -6
- package/dist/commands/workflow-template-definitions/install.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/install.js +4 -2
- package/dist/commands/workflow-template-definitions/list.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/list.js +4 -2
- package/dist/commands/workflow-templates/delete.d.ts +2 -2
- package/dist/commands/workflow-templates/delete.js +4 -2
- package/dist/commands/workflow-templates/export.d.ts +2 -2
- package/dist/commands/workflow-templates/export.js +19 -17
- package/dist/commands/workflow-templates/list.d.ts +2 -2
- package/dist/commands/workflow-templates/list.js +4 -2
- package/dist/commands/workflow-templates/load.d.ts +2 -2
- package/dist/commands/workflow-templates/load.js +8 -3
- package/dist/common.d.ts +4 -1
- package/dist/common.js +10 -1
- package/dist/helpers/app/actions-deployer.d.ts +2 -2
- package/dist/helpers/app/actions-deployer.js +12 -7
- package/dist/helpers/app/app-deployer.d.ts +1 -1
- package/dist/helpers/app/app-deployer.js +70 -52
- package/dist/helpers/app/app-template-parsers.js +3 -1
- package/dist/helpers/app/load-app-config.d.ts +2 -1
- package/dist/helpers/app/load-app-config.js +2 -2
- package/dist/helpers/app/setup-template.js +4 -3
- package/dist/helpers/colors/helpers.d.ts +10 -2
- package/dist/helpers/colors/helpers.js +11 -10
- package/dist/helpers/config/config.js +15 -10
- package/dist/helpers/file-helpers.js +7 -4
- package/dist/helpers/loader-process/helpers.js +14 -13
- package/dist/helpers/projects/helpers.d.ts +2 -1
- package/dist/helpers/projects/helpers.js +16 -15
- package/dist/helpers/types/csv-parser.js +17 -14
- package/dist/helpers/types/type-extractor.d.ts +1 -1
- package/dist/helpers/types/type-extractor.js +3 -2
- package/dist/helpers/types/type-parser.js +22 -21
- package/dist/helpers/types/type-uploader.js +19 -15
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.d.ts +1 -1
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +47 -28
- package/dist/helpers/workflow-templates/helper.d.ts +3 -3
- package/dist/helpers/workflow-templates/helper.js +33 -23
- package/dist/interface-converters.spec.js +15 -15
- package/dist/interfaces.d.ts +6 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +32 -0
- package/dist/templates/typescript/src/actions/logItem.ts +9 -4
- package/dist/templates/typescript/src/main.ts +13 -8
- package/oclif.manifest.json +861 -31
- package/package.json +10 -7
|
@@ -10,21 +10,22 @@ const event_workflow_action_definition_1 = require("../../api/event-workflow-act
|
|
|
10
10
|
const event_workflow_templates_1 = require("../../api/event-workflow-templates");
|
|
11
11
|
const login_1 = require("../../auth/login");
|
|
12
12
|
const interface_converters_1 = require("../../interface-converters");
|
|
13
|
-
const
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
14
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
14
15
|
class LocalWorkflowTemplateDeployer {
|
|
15
16
|
async deployWorkflows(wtDeclaration) {
|
|
16
17
|
// FETCH ALL WORKFLOWS FROM THE API.
|
|
17
18
|
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
18
19
|
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
19
|
-
|
|
20
|
+
logger_1.default.info('%s \tDeploying workflow templates.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
|
|
20
21
|
for (const workflow of wtDeclaration.workflows) {
|
|
21
22
|
await this.deployWorkflowTemplate(workflow, existingWorkflows);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
async deployWorkflowTemplate(workflow, existingWorkflows) {
|
|
25
|
-
|
|
26
|
+
logger_1.default.info(`%s \tDeploying workflow: ${workflow.triggerKey}`, chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
|
|
26
27
|
const identifier = getWorkflowTemplateIdentifier(workflow.identifier);
|
|
27
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
28
|
+
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
28
29
|
(0, interface_converters_1.convertWorkflow)(workflow);
|
|
29
30
|
if (existingTemplate) {
|
|
30
31
|
return await this.updateWorkflowTemplate(identifier, existingTemplate, workflow);
|
|
@@ -44,12 +45,12 @@ class LocalWorkflowTemplateDeployer {
|
|
|
44
45
|
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
45
46
|
};
|
|
46
47
|
const newWorkflowTemplate = await (0, event_workflow_templates_1.createWorkflowTemplate)(newObject);
|
|
47
|
-
|
|
48
|
+
logger_1.default.info(`%s Created new workflow definition: ${workflowKey}`, chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
|
|
48
49
|
return newWorkflowTemplate;
|
|
49
50
|
}
|
|
50
51
|
async populateActionIds(workflowTemplate, workflowKey) {
|
|
51
52
|
var _a;
|
|
52
|
-
|
|
53
|
+
logger_1.default.info('workflow template:', JSON.stringify(workflowTemplate, null, 2));
|
|
53
54
|
if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
@@ -64,7 +65,7 @@ class LocalWorkflowTemplateDeployer {
|
|
|
64
65
|
actionConfiguration.id = actionEntity.id;
|
|
65
66
|
}
|
|
66
67
|
catch (e) {
|
|
67
|
-
|
|
68
|
+
logger_1.default.info(e);
|
|
68
69
|
}
|
|
69
70
|
if (!actionConfiguration.id) {
|
|
70
71
|
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
@@ -83,28 +84,31 @@ class LocalWorkflowTemplateDeployer {
|
|
|
83
84
|
messageGroupId: (_a = workflowTemplate.messageGroupId) !== null && _a !== void 0 ? _a : existingWorkflowTemplate.messageGroupId,
|
|
84
85
|
parallelWorkerCount: (_b = workflowTemplate.parallelWorkerCount) !== null && _b !== void 0 ? _b : existingWorkflowTemplate.parallelWorkerCount,
|
|
85
86
|
});
|
|
86
|
-
const updatedWorkflowTemplate = await (0, event_workflow_templates_1.updateWorkflowTemplate)({
|
|
87
|
-
|
|
87
|
+
const updatedWorkflowTemplate = await (0, event_workflow_templates_1.updateWorkflowTemplate)({
|
|
88
|
+
id: existingWorkflowTemplate.id,
|
|
89
|
+
updates,
|
|
90
|
+
});
|
|
91
|
+
logger_1.default.info(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
|
|
88
92
|
return updatedWorkflowTemplate;
|
|
89
93
|
}
|
|
90
94
|
async deleteWorkflowTemplates(wtDeclaration) {
|
|
91
95
|
// FETCH ALL WORKFLOWS FROM THE API.
|
|
92
96
|
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
93
97
|
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
94
|
-
|
|
98
|
+
logger_1.default.info('%s \tDELETING workflow templates.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
|
|
95
99
|
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
96
100
|
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
97
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
101
|
+
const existingTemplate = existingWorkflows.find((ad) => ad.identifier === identifier);
|
|
98
102
|
if (existingTemplate) {
|
|
99
103
|
try {
|
|
100
104
|
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(identifier);
|
|
101
105
|
}
|
|
102
106
|
catch (e) {
|
|
103
|
-
|
|
107
|
+
logger_1.default.info('%s \tFAILED to delete workflow template %s.', chalk_1.default.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
else {
|
|
107
|
-
|
|
111
|
+
logger_1.default.info('%s \tUnable to locate workflow template %s.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
}
|
|
@@ -123,22 +127,28 @@ class WorkflowTemplateDeployer {
|
|
|
123
127
|
async deleteWorkflowTemplates() {
|
|
124
128
|
// FETCH ALL WORKFLOWS FROM THE API.
|
|
125
129
|
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
126
|
-
const answers = await inquirer_1.default.prompt([
|
|
130
|
+
const answers = await inquirer_1.default.prompt([
|
|
131
|
+
{
|
|
127
132
|
type: 'checkbox',
|
|
128
133
|
name: 'wfTemplatesToDelete',
|
|
129
134
|
message: 'Which templates would you like to delete (one or more)?',
|
|
130
|
-
choices: existingWorkflows.map(x => {
|
|
131
|
-
|
|
135
|
+
choices: existingWorkflows.map((x) => {
|
|
136
|
+
return { value: x.id, name: `(${x.createdOn}) ${x.name}` };
|
|
137
|
+
}),
|
|
138
|
+
},
|
|
139
|
+
]);
|
|
132
140
|
for (const idToDelete of answers.wfTemplatesToDelete) {
|
|
133
141
|
await (0, event_workflow_templates_1.deleteWorkflowTemplate)(idToDelete);
|
|
134
142
|
}
|
|
135
|
-
|
|
143
|
+
logger_1.default.info('%s \tDeleted workflow templates!', chalk_1.default.green.bold('WORKFLOW TEMPLATES'));
|
|
136
144
|
}
|
|
137
145
|
async listExistingWorkflowTemplates() {
|
|
138
146
|
const templates = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
logger_1.default.info('(Date Created) (active) workflow name');
|
|
148
|
+
logger_1.default.info('------------------------');
|
|
149
|
+
logger_1.default.info(chalk_1.default.green.bold(templates
|
|
150
|
+
.map((x) => `(${x.createdOn}) (${x.isActive ? 'active' : 'inactive'}) ${x.name} `)
|
|
151
|
+
.join('\n')));
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
154
|
exports.WorkflowTemplateDeployer = WorkflowTemplateDeployer;
|
|
@@ -153,7 +163,7 @@ async function localDeployWorkflowTemplate(saveFileLocation) {
|
|
|
153
163
|
wtDeclaration = loadTemplateConfig(saveFileLocation);
|
|
154
164
|
}
|
|
155
165
|
catch (e) {
|
|
156
|
-
|
|
166
|
+
logger_1.default.info(`%s Workflow Deletion Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
157
167
|
return;
|
|
158
168
|
}
|
|
159
169
|
await (0, login_1.authUser)();
|
|
@@ -163,7 +173,7 @@ exports.localDeployWorkflowTemplate = localDeployWorkflowTemplate;
|
|
|
163
173
|
function loadTemplateConfig(saveFile) {
|
|
164
174
|
const TARGET_DIR = process.cwd();
|
|
165
175
|
try {
|
|
166
|
-
const doc =
|
|
176
|
+
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.resolve(path.join(TARGET_DIR, saveFile)), 'utf8'));
|
|
167
177
|
return doc;
|
|
168
178
|
}
|
|
169
179
|
catch (e) {
|
|
@@ -187,7 +197,7 @@ async function populateActionIdentifiers(workflowTemplate) {
|
|
|
187
197
|
delete actionConfiguration.id;
|
|
188
198
|
}
|
|
189
199
|
catch (e) {
|
|
190
|
-
|
|
200
|
+
logger_1.default.info(e);
|
|
191
201
|
}
|
|
192
202
|
if (!actionConfiguration.action) {
|
|
193
203
|
throw new Error(`Could not find action ${actionId}`);
|
|
@@ -14,11 +14,11 @@ describe('Workflow Template converter tests', () => {
|
|
|
14
14
|
actionDefinitionConfigs: [
|
|
15
15
|
{
|
|
16
16
|
action: 'logItem',
|
|
17
|
-
name: 'Log Item'
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
]
|
|
17
|
+
name: 'Log Item',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
22
|
},
|
|
23
23
|
ownerKey: 'app:123',
|
|
24
24
|
isActive: true,
|
|
@@ -42,11 +42,11 @@ describe('Workflow Template converter tests', () => {
|
|
|
42
42
|
actionDefinitionConfigs: [
|
|
43
43
|
{
|
|
44
44
|
action: 'logItem',
|
|
45
|
-
name: 'Log Item'
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
]
|
|
45
|
+
name: 'Log Item',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
50
|
},
|
|
51
51
|
ownerKey: 'app:123',
|
|
52
52
|
isActive: true,
|
|
@@ -70,11 +70,11 @@ describe('Workflow Template converter tests', () => {
|
|
|
70
70
|
actionDefinitionConfigs: [
|
|
71
71
|
{
|
|
72
72
|
action: 'logItem',
|
|
73
|
-
name: 'Log Item'
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
]
|
|
73
|
+
name: 'Log Item',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
78
|
},
|
|
79
79
|
ownerKey: 'app:123',
|
|
80
80
|
isActive: true,
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ export interface WorkflowTemplate {
|
|
|
83
83
|
groupId?: string;
|
|
84
84
|
messageGroupId?: string;
|
|
85
85
|
parallelWorkerCount?: number;
|
|
86
|
+
createdOn?: Date;
|
|
87
|
+
updatedOn?: Date;
|
|
88
|
+
createdById?: string;
|
|
89
|
+
updatedById?: string;
|
|
90
|
+
createdBy?: any;
|
|
91
|
+
updatedBy?: any;
|
|
86
92
|
}
|
|
87
93
|
export interface WorkflowDefinitionPaths {
|
|
88
94
|
paths: WorkflowConditional[];
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const winston_1 = tslib_1.__importStar(require("winston"));
|
|
5
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
+
class Logger {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.colors = {
|
|
9
|
+
error: 'red',
|
|
10
|
+
warn: 'yellow',
|
|
11
|
+
info: 'green',
|
|
12
|
+
debug: 'blue',
|
|
13
|
+
};
|
|
14
|
+
const transport = new winston_1.transports.Console();
|
|
15
|
+
winston_1.default.addColors(this.colors);
|
|
16
|
+
this.logger = (0, winston_1.createLogger)({
|
|
17
|
+
level: 'info',
|
|
18
|
+
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp(), winston_1.default.format.printf(({ timestamp, level, message }) => {
|
|
19
|
+
if (lodash_1.default.isObject(message)) {
|
|
20
|
+
return `${timestamp} ${level}: ${JSON.stringify(message, null, 2)}`;
|
|
21
|
+
}
|
|
22
|
+
return `${timestamp} ${level}: ${message}`;
|
|
23
|
+
})),
|
|
24
|
+
transports: [transport],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
static getInstance() {
|
|
28
|
+
return new Logger().logger;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const logger = Logger.getInstance();
|
|
32
|
+
exports.default = logger;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Action,
|
|
4
|
+
AppAction,
|
|
5
|
+
AppActionCallBack,
|
|
6
|
+
AppActionCallbackStatus,
|
|
7
|
+
Logger,
|
|
8
|
+
} from '@contrail/app-framework';
|
|
3
9
|
|
|
4
10
|
export class LogItemAction implements AppAction {
|
|
5
|
-
|
|
6
11
|
@Action('logItem')
|
|
7
12
|
public async execute(event, config: any): Promise<AppActionCallBack> {
|
|
8
13
|
console.log('Starting Example Action');
|
|
@@ -18,7 +23,7 @@ export class LogItemAction implements AppAction {
|
|
|
18
23
|
output: {
|
|
19
24
|
item,
|
|
20
25
|
},
|
|
21
|
-
status: AppActionCallbackStatus.SUCCESS
|
|
26
|
+
status: AppActionCallbackStatus.SUCCESS,
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
|
-
}
|
|
29
|
+
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ContrailAppModule,
|
|
3
|
+
loadAppConfig,
|
|
4
|
+
registerAppInfo,
|
|
5
|
+
runMockServer,
|
|
6
|
+
AppActionRequest,
|
|
7
|
+
AppActionResponse,
|
|
8
|
+
ActionDispatcher,
|
|
9
|
+
GLOBAL_ACTION_REGISTRY,
|
|
10
|
+
} from '@contrail/app-framework';
|
|
2
11
|
|
|
3
12
|
// we can't use static import here. Require only
|
|
4
13
|
import fs from 'fs';
|
|
@@ -7,28 +16,24 @@ const pJson = require('../package.json');
|
|
|
7
16
|
|
|
8
17
|
const APP_YML_LOCATION = path.resolve(path.join(__dirname, '..', 'app.yml'));
|
|
9
18
|
export class AppModule extends ContrailAppModule {
|
|
10
|
-
|
|
11
19
|
initModule() {
|
|
12
20
|
// register the app info
|
|
13
21
|
const appConfig = loadAppConfig(APP_YML_LOCATION);
|
|
14
22
|
registerAppInfo({
|
|
15
23
|
appName: appConfig.appIdentifier, //appName is required
|
|
16
|
-
packageVersion: pJson.version
|
|
24
|
+
packageVersion: pJson.version,
|
|
17
25
|
});
|
|
18
26
|
|
|
19
27
|
// register app's actions
|
|
20
28
|
for (const file of fs.readdirSync(path.join(__dirname, 'actions'))) {
|
|
21
29
|
// only parse js and ts file, avoid property files
|
|
22
|
-
if (
|
|
23
|
-
file.endsWith('.js') ||
|
|
24
|
-
(file.endsWith('.ts') && !file.endsWith('.d.ts'))
|
|
25
|
-
) {
|
|
30
|
+
if (file.endsWith('.js') || (file.endsWith('.ts') && !file.endsWith('.d.ts'))) {
|
|
26
31
|
require(path.join(__dirname, 'actions', file));
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
console.log(`Registered ${Object.keys(GLOBAL_ACTION_REGISTRY).length} action(s):`);
|
|
31
|
-
for(const key of Object.keys(GLOBAL_ACTION_REGISTRY)) {
|
|
36
|
+
for (const key of Object.keys(GLOBAL_ACTION_REGISTRY)) {
|
|
32
37
|
console.log(`\t- ${appConfig.appIdentifier}:${key}`);
|
|
33
38
|
}
|
|
34
39
|
}
|