@contrail/cli 2.1.11 → 2.1.14

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 CHANGED
@@ -15,7 +15,7 @@ $ npm install -g @contrail/cli
15
15
  $ contrail COMMAND
16
16
  running command...
17
17
  $ contrail (--version)
18
- @contrail/cli/2.1.11 darwin-arm64 node-v18.13.0
18
+ @contrail/cli/2.1.14 darwin-arm64 node-v18.13.0
19
19
  $ contrail --help [COMMAND]
20
20
  USAGE
21
21
  $ contrail COMMAND
@@ -88,6 +88,7 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
88
88
  * [`contrail workflow-template-definitions install`](#contrail-workflow-template-definitions-install)
89
89
  * [`contrail workflow-template-definitions list`](#contrail-workflow-template-definitions-list)
90
90
  * [`contrail workflow-templates delete`](#contrail-workflow-templates-delete)
91
+ * [`contrail workflow-templates export`](#contrail-workflow-templates-export)
91
92
  * [`contrail workflow-templates list`](#contrail-workflow-templates-list)
92
93
  * [`contrail workflow-templates load FILELOCATION`](#contrail-workflow-templates-load-filelocation)
93
94
 
@@ -1288,7 +1289,26 @@ DESCRIPTION
1288
1289
  Delete workflow templates from your org
1289
1290
 
1290
1291
  EXAMPLES
1291
- $ contrail workflow-template delete
1292
+ $ contrail workflow-templates delete
1293
+ ```
1294
+
1295
+ ## `contrail workflow-templates export`
1296
+
1297
+ Export all workflows in the org.
1298
+
1299
+ ```
1300
+ USAGE
1301
+ $ contrail workflow-templates export [-f <value>] [--overwrite]
1302
+
1303
+ FLAGS
1304
+ -f, --outFile=<value> [default: workflows.yml] The location for the file to be saved
1305
+ --overwrite Replaces existing files if they exist
1306
+
1307
+ DESCRIPTION
1308
+ Export all workflows in the org.
1309
+
1310
+ EXAMPLES
1311
+ $ contrail workflow-templates export
1292
1312
  ```
1293
1313
 
1294
1314
  ## `contrail workflow-templates list`
@@ -1303,7 +1323,7 @@ DESCRIPTION
1303
1323
  Lists the workflow templates in the org
1304
1324
 
1305
1325
  EXAMPLES
1306
- $ contrail workflow-template list
1326
+ $ contrail workflow-templates list
1307
1327
  ```
1308
1328
 
1309
1329
  ## `contrail workflow-templates load FILELOCATION`
@@ -1321,6 +1341,6 @@ DESCRIPTION
1321
1341
  Loads your workflow from a local file
1322
1342
 
1323
1343
  EXAMPLES
1324
- $ contrail workflow-template load <FILE_LOCATION>
1344
+ $ contrail workflow-templates load <FILE_LOCATION>
1325
1345
  ```
1326
1346
  <!-- commandsstop -->
@@ -1 +1,3 @@
1
+ import { EventWorkflowActionDefinition } from '../interfaces';
1
2
  export declare function getEventWorkflowActionDefinition(criteria: any): Promise<any>;
3
+ export declare function getEventWorkflowActionDefinitionById(id: string): Promise<EventWorkflowActionDefinition>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEventWorkflowActionDefinition = void 0;
3
+ exports.getEventWorkflowActionDefinitionById = exports.getEventWorkflowActionDefinition = void 0;
4
4
  const sdk_1 = require("@contrail/sdk");
5
5
  async function getEventWorkflowActionDefinition(criteria) {
6
6
  return await new sdk_1.Entities().get({
@@ -9,3 +9,10 @@ async function getEventWorkflowActionDefinition(criteria) {
9
9
  });
10
10
  }
11
11
  exports.getEventWorkflowActionDefinition = getEventWorkflowActionDefinition;
12
+ async function getEventWorkflowActionDefinitionById(id) {
13
+ return await new sdk_1.Entities().get({
14
+ entityName: 'event-workflow-action-definition',
15
+ id,
16
+ });
17
+ }
18
+ exports.getEventWorkflowActionDefinitionById = getEventWorkflowActionDefinitionById;
@@ -145,6 +145,6 @@ async function refreshCurrentUserOrg() {
145
145
  auth_1.Auth.config.orgId = org.orgId || org.id;
146
146
  }
147
147
  // cache config in the fs
148
- (0, config_1.storeConfig)(Object.assign({}, auth_1.Auth.config));
148
+ await (0, config_1.storeConfig)(Object.assign({}, auth_1.Auth.config));
149
149
  return Object.assign({}, auth_1.Auth.config);
150
150
  }
@@ -12,6 +12,6 @@ class DeleteWorkflowTemplates extends core_1.Command {
12
12
  exports.default = DeleteWorkflowTemplates;
13
13
  DeleteWorkflowTemplates.description = 'Delete workflow templates from your org';
14
14
  DeleteWorkflowTemplates.examples = [
15
- `$ contrail workflow-template delete
15
+ `$ contrail workflow-templates delete
16
16
  `,
17
17
  ];
@@ -0,0 +1,12 @@
1
+ import { Command } from "@oclif/core";
2
+ export declare const DEFAULT_FILE_LOCATION = "workflows.yml";
3
+ export default class ExportWorkflows extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ outFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ };
10
+ run(): Promise<void>;
11
+ }
12
+ export declare function exportWorkflows(fileLocation: string, overwrite: boolean): Promise<void>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportWorkflows = exports.DEFAULT_FILE_LOCATION = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
9
+ const login_1 = require("../../auth/login");
10
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
11
+ const core_1 = require("@oclif/core");
12
+ const file_helpers_1 = require("../../helpers/file-helpers");
13
+ const event_workflow_templates_1 = require("../../api/event-workflow-templates");
14
+ const helper_1 = require("../../helpers/workflow-templates/helper");
15
+ exports.DEFAULT_FILE_LOCATION = "workflows.yml";
16
+ class ExportWorkflows extends core_1.Command {
17
+ async run() {
18
+ var _a;
19
+ const { flags } = await this.parse(ExportWorkflows);
20
+ try {
21
+ await (0, login_1.authUser)();
22
+ this.log("%s Getting Workflows.", chalk_1.default.blue.bold("START"));
23
+ await exportWorkflows((_a = flags.outFile) !== null && _a !== void 0 ? _a : exports.DEFAULT_FILE_LOCATION, flags.overwrite);
24
+ this.log("%s Done", chalk_1.default.yellow.bold("WORKFLOWS"));
25
+ }
26
+ catch (e) {
27
+ this.log(`%s Workflows download Failed. ${e}`, chalk_1.default.red.bold("FAIL"));
28
+ return;
29
+ }
30
+ this.log("%s Workflows download Complete.", chalk_1.default.green.bold("COMPLETE"));
31
+ }
32
+ }
33
+ exports.default = ExportWorkflows;
34
+ ExportWorkflows.description = "Export all workflows in the org.";
35
+ ExportWorkflows.examples = [
36
+ `$ contrail workflow-templates export
37
+ `,
38
+ ];
39
+ ExportWorkflows.flags = {
40
+ outFile: core_1.Flags.string({
41
+ char: "f",
42
+ description: "The location for the file to be saved",
43
+ required: false,
44
+ default: exports.DEFAULT_FILE_LOCATION,
45
+ }),
46
+ overwrite: core_1.Flags.boolean({
47
+ description: "Replaces existing files if they exist",
48
+ required: false,
49
+ default: false,
50
+ }),
51
+ };
52
+ async function exportWorkflows(fileLocation, overwrite) {
53
+ const allWorkflowsInOrg = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
54
+ let workflowsObj = { workflows: [] };
55
+ for (const workflow of allWorkflowsInOrg) {
56
+ const exportWorkflow = lodash_1.default.pick(workflow, [
57
+ "triggerKey",
58
+ "workflowDefinition",
59
+ "name",
60
+ "isActive",
61
+ "identifier",
62
+ ]);
63
+ await (0, helper_1.populateActionIdentifiers)(exportWorkflow);
64
+ workflowsObj.workflows.push(exportWorkflow);
65
+ }
66
+ await saveData(workflowsObj, fileLocation, overwrite);
67
+ }
68
+ exports.exportWorkflows = exportWorkflows;
69
+ async function saveData(data, fileLocation, overwrite) {
70
+ const yamlStr = js_yaml_1.default.dump(data);
71
+ const CURRENT_DIR = process.cwd();
72
+ const pathToWrite = path.resolve(path.join(CURRENT_DIR, fileLocation));
73
+ if (fs_1.default.existsSync(pathToWrite)) {
74
+ await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
75
+ }
76
+ fs_1.default.writeFileSync(pathToWrite, yamlStr, "utf8");
77
+ }
@@ -12,6 +12,6 @@ class ListWorkflowTemplates extends core_1.Command {
12
12
  exports.default = ListWorkflowTemplates;
13
13
  ListWorkflowTemplates.description = 'Lists the workflow templates in the org';
14
14
  ListWorkflowTemplates.examples = [
15
- `$ contrail workflow-template list
15
+ `$ contrail workflow-templates list
16
16
  `,
17
17
  ];
@@ -13,7 +13,7 @@ class LoadWorkflowTemplates extends core_1.Command {
13
13
  exports.default = LoadWorkflowTemplates;
14
14
  LoadWorkflowTemplates.description = 'Loads your workflow from a local file';
15
15
  LoadWorkflowTemplates.examples = [
16
- `$ contrail workflow-template load <FILE_LOCATION>
16
+ `$ contrail workflow-templates load <FILE_LOCATION>
17
17
  `,
18
18
  ];
19
19
  LoadWorkflowTemplates.args = {
@@ -86,7 +86,7 @@ class AppDeployer {
86
86
  }
87
87
  async updateExistingApp(appDeclaration, existingApp) {
88
88
  var _a;
89
- let configProperties;
89
+ let configProperties = null;
90
90
  if (appDeclaration === null || appDeclaration === void 0 ? void 0 : appDeclaration.appConfiguration) {
91
91
  configProperties = app_template_parsers_1.ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration);
92
92
  }
@@ -100,21 +100,6 @@ async function uploadReducedTypes(dir) {
100
100
  console.log('Error Uploading Types: ', err);
101
101
  }
102
102
  }
103
- for (const currentType of currentTypes) {
104
- try {
105
- const found = newTypesBySlug[currentType.slug];
106
- if (!found) {
107
- console.log('Deleting Type: ', currentType.slug);
108
- await new sdk_1.Entities().delete({
109
- entityName: 'type',
110
- id: currentType.id,
111
- });
112
- }
113
- }
114
- catch (err) {
115
- throw new Error(`Error Deleting Types: ${err}`);
116
- }
117
- }
118
103
  }
119
104
  async function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes) {
120
105
  const currentPropertyTypeBySlug = {};
@@ -1,7 +1,7 @@
1
1
  import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../../interfaces';
2
2
  export declare class LocalWorkflowTemplateDeployer {
3
3
  deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
4
- deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>): Promise<any>;
4
+ deployWorkflowTemplate(workflow: WorkflowTemplate, existingWorkflows: WorkflowTemplate[]): Promise<any>;
5
5
  private createNewWorkflowTemplate;
6
6
  private populateActionIds;
7
7
  private updateWorkflowTemplate;
@@ -15,3 +15,4 @@ export declare class WorkflowTemplateDeployer {
15
15
  }
16
16
  export declare function deleteWorkflowTemplates(): Promise<void>;
17
17
  export declare function localDeployWorkflowTemplate(saveFileLocation: string): Promise<void>;
18
+ export declare function populateActionIdentifiers(workflowTemplate: WorkflowTemplate): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localDeployWorkflowTemplate = exports.deleteWorkflowTemplates = exports.WorkflowTemplateDeployer = exports.getActionByIdentifier = exports.getWorkflowTemplateIdentifier = exports.LocalWorkflowTemplateDeployer = void 0;
3
+ exports.populateActionIdentifiers = exports.localDeployWorkflowTemplate = exports.deleteWorkflowTemplates = exports.WorkflowTemplateDeployer = exports.getActionByIdentifier = exports.getWorkflowTemplateIdentifier = exports.LocalWorkflowTemplateDeployer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const path = tslib_1.__importStar(require("path"));
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
@@ -17,19 +17,19 @@ class LocalWorkflowTemplateDeployer {
17
17
  const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
18
18
  // UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
19
19
  console.log('%s \tDeploying workflow templates.', chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
20
- for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
21
- await this.deployWorkflowTemplate(workflowKey, wtDeclaration.workflows[workflowKey], existingWorkflows);
20
+ for (const workflow of wtDeclaration.workflows) {
21
+ await this.deployWorkflowTemplate(workflow, existingWorkflows);
22
22
  }
23
23
  }
24
- async deployWorkflowTemplate(workflowKey, workflow, existingWorkflows) {
25
- console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
26
- const identifier = getWorkflowTemplateIdentifier(workflowKey);
24
+ async deployWorkflowTemplate(workflow, existingWorkflows) {
25
+ console.log(`%s \tDeploying workflow: ${workflow.triggerKey}`, chalk_1.default.yellow.bold('WORKFLOW TEMPLATES'));
26
+ const identifier = getWorkflowTemplateIdentifier(workflow.identifier);
27
27
  const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
28
28
  (0, interface_converters_1.convertWorkflow)(workflow);
29
29
  if (existingTemplate) {
30
- return await this.updateWorkflowTemplate(workflowKey, existingTemplate, workflow);
30
+ return await this.updateWorkflowTemplate(identifier, existingTemplate, workflow);
31
31
  }
32
- return await this.createNewWorkflowTemplate(workflowKey, workflow);
32
+ return await this.createNewWorkflowTemplate(identifier, workflow);
33
33
  }
34
34
  async createNewWorkflowTemplate(workflowKey, workflowTemplate) {
35
35
  await this.populateActionIds(workflowTemplate, workflowKey);
@@ -49,7 +49,7 @@ class LocalWorkflowTemplateDeployer {
49
49
  }
50
50
  async populateActionIds(workflowTemplate, workflowKey) {
51
51
  var _a;
52
- console.log('workflow tempalate:', JSON.stringify(workflowTemplate, null, 2));
52
+ console.log('workflow template:', JSON.stringify(workflowTemplate, null, 2));
53
53
  if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
54
54
  return;
55
55
  }
@@ -169,3 +169,29 @@ function loadTemplateConfig(saveFile) {
169
169
  throw new Error(`ERROR PARSING YAML: ${e}`);
170
170
  }
171
171
  }
172
+ async function populateActionIdentifiers(workflowTemplate) {
173
+ var _a;
174
+ if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
175
+ return;
176
+ }
177
+ for (const path of workflowTemplate.workflowDefinition.paths) {
178
+ if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
179
+ continue;
180
+ }
181
+ for (const actionConfiguration of path.actionDefinitionConfigs) {
182
+ const actionId = actionConfiguration.id;
183
+ try {
184
+ const actionEntity = await (0, event_workflow_action_definition_1.getEventWorkflowActionDefinitionById)(actionId);
185
+ actionConfiguration.action = actionEntity.identifier;
186
+ delete actionConfiguration.id;
187
+ }
188
+ catch (e) {
189
+ console.log(e);
190
+ }
191
+ if (!actionConfiguration.action) {
192
+ throw new Error(`Could not find action ${actionId}`);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ exports.populateActionIdentifiers = populateActionIdentifiers;
@@ -65,9 +65,7 @@ export interface WorkflowDefinition {
65
65
  parallelWorkerCount?: number;
66
66
  }
67
67
  export interface WorkflowTemplateDeclaration {
68
- workflows?: {
69
- [key: string]: WorkflowTemplate;
70
- };
68
+ workflows?: WorkflowTemplate[];
71
69
  }
72
70
  export interface WorkflowTemplate {
73
71
  id?: string;
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "scripts": {
14
- "build": "tsc",
14
+ "build": "tsc; npx copyfiles assets/**/* dist/",
15
15
  "start": "nodemon --watch \"src/**/*.ts\" --exec ts-node src/main.ts",
16
16
  "debug": "nodemon -r ts-node/register --inspect=127.0.0.1:60002 --watch 'actions/**/*.ts' --exec node src/main.ts",
17
17
  "lint": "eslint . --fix",
@@ -4,15 +4,15 @@ import { Action, AppAction, AppActionCallBack, AppActionCallbackStatus, Logger }
4
4
  export class LogItemAction implements AppAction {
5
5
 
6
6
  @Action('logItem')
7
- public async execute(event, config: any, logger: Logger): Promise<AppActionCallBack> {
8
- logger.log('Starting Example Action');
9
- logger.log('Getting item from SDK');
7
+ public async execute(event, config: any): Promise<AppActionCallBack> {
8
+ console.log('Starting Example Action');
9
+ console.log('Getting item from SDK');
10
10
 
11
11
  const item = await new Entities().get({
12
12
  entityName: 'item',
13
13
  id: event.id,
14
14
  });
15
- logger.log('Got item: ', item);
15
+ console.log('Got item: ', item);
16
16
 
17
17
  return {
18
18
  output: {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.11",
2
+ "version": "2.1.14",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -1168,11 +1168,42 @@
1168
1168
  "pluginType": "core",
1169
1169
  "aliases": [],
1170
1170
  "examples": [
1171
- "$ contrail workflow-template delete\n"
1171
+ "$ contrail workflow-templates delete\n"
1172
1172
  ],
1173
1173
  "flags": {},
1174
1174
  "args": {}
1175
1175
  },
1176
+ "workflow-templates:export": {
1177
+ "id": "workflow-templates:export",
1178
+ "description": "Export all workflows in the org.",
1179
+ "strict": true,
1180
+ "pluginName": "@contrail/cli",
1181
+ "pluginAlias": "@contrail/cli",
1182
+ "pluginType": "core",
1183
+ "aliases": [],
1184
+ "examples": [
1185
+ "$ contrail workflow-templates export\n"
1186
+ ],
1187
+ "flags": {
1188
+ "outFile": {
1189
+ "name": "outFile",
1190
+ "type": "option",
1191
+ "char": "f",
1192
+ "description": "The location for the file to be saved",
1193
+ "required": false,
1194
+ "multiple": false,
1195
+ "default": "workflows.yml"
1196
+ },
1197
+ "overwrite": {
1198
+ "name": "overwrite",
1199
+ "type": "boolean",
1200
+ "description": "Replaces existing files if they exist",
1201
+ "required": false,
1202
+ "allowNo": false
1203
+ }
1204
+ },
1205
+ "args": {}
1206
+ },
1176
1207
  "workflow-templates:list": {
1177
1208
  "id": "workflow-templates:list",
1178
1209
  "description": "Lists the workflow templates in the org",
@@ -1182,7 +1213,7 @@
1182
1213
  "pluginType": "core",
1183
1214
  "aliases": [],
1184
1215
  "examples": [
1185
- "$ contrail workflow-template list\n"
1216
+ "$ contrail workflow-templates list\n"
1186
1217
  ],
1187
1218
  "flags": {},
1188
1219
  "args": {}
@@ -1196,7 +1227,7 @@
1196
1227
  "pluginType": "core",
1197
1228
  "aliases": [],
1198
1229
  "examples": [
1199
- "$ contrail workflow-template load <FILE_LOCATION>\n"
1230
+ "$ contrail workflow-templates load <FILE_LOCATION>\n"
1200
1231
  ],
1201
1232
  "flags": {},
1202
1233
  "args": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "2.1.11",
3
+ "version": "2.1.14",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",