@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.
Files changed (48) hide show
  1. package/.eslintrc.js +53 -0
  2. package/lib/apps/deploy-app/actions-deployer.js +12 -3
  3. package/lib/apps/deploy-app/app-deployer.js +2 -3
  4. package/lib/apps/deploy-app/app-template-parsers.js +1 -1
  5. package/lib/apps/deploy-app/docker-action-builder.d.ts +10 -0
  6. package/lib/apps/deploy-app/docker-action-builder.js +97 -0
  7. package/lib/apps/deploy-app/interfaces.d.ts +76 -0
  8. package/lib/apps/deploy-app/interfaces.js +4 -0
  9. package/lib/apps/deploy-app/workflow-definition-deployer.js +1 -1
  10. package/lib/apps/deploy-app/workflow-deployer.d.ts +10 -0
  11. package/lib/apps/deploy-app/workflow-deployer.js +87 -0
  12. package/lib/auth/login.js +5 -5
  13. package/lib/cli.js +2 -1
  14. package/lib/colors/color-loader.js +8 -8
  15. package/lib/config/config.js +2 -2
  16. package/lib/interfaces.d.ts +2 -2
  17. package/lib/types/interfaces.js +1 -0
  18. package/lib/types/option-set-merger.js +2 -2
  19. package/lib/types/option-set-parser.js +2 -2
  20. package/lib/types/option-set-uploader.js +2 -2
  21. package/lib/types/parse-types.js +6 -6
  22. package/lib/types/types-extractor.js +4 -4
  23. package/lib/types/types-properties-merger.js +2 -2
  24. package/lib/types/types-uploader.d.ts +1 -1
  25. package/lib/types/types-uploader.js +6 -6
  26. package/package.json +7 -5
  27. package/src/apps/deploy-app/actions-deployer.ts +17 -10
  28. package/src/apps/deploy-app/app-deployer.ts +3 -4
  29. package/src/apps/deploy-app/workflow-definition-deployer.ts +3 -3
  30. package/src/auth/login.ts +124 -124
  31. package/src/cli.ts +115 -115
  32. package/src/colors/color-loader.ts +16 -16
  33. package/src/config/config.ts +9 -11
  34. package/src/config/configCommands.ts +1 -1
  35. package/src/interfaces.ts +9 -10
  36. package/src/types/csv-parser.ts +1 -1
  37. package/src/types/option-set-merger.ts +9 -9
  38. package/src/types/option-set-parser.ts +5 -6
  39. package/src/types/option-set-uploader.ts +2 -2
  40. package/src/types/parse-types.ts +9 -9
  41. package/src/types/types-extractor.ts +5 -5
  42. package/src/types/types-properties-merger.ts +6 -6
  43. package/src/types/types-uploader.ts +31 -31
  44. package/src/workflows/workflow-template-deployer.ts +2 -4
  45. package/src/workflows/workflowCommands.ts +0 -1
  46. package/templates/javascript/actions/example/action.js +37 -37
  47. package/templates/typescript/actions/exampleAction.ts +1 -1
  48. package/templates/typescript/app.yml +1 -1
@@ -11,23 +11,23 @@ export async function getTypes(args) {
11
11
  try {
12
12
  const userConfig = await authUser();
13
13
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
14
- console.log(`%s Retrieving`, chalk.yellow.bold('OPTION SETS'));
14
+ console.log('%s Retrieving', chalk.yellow.bold('OPTION SETS'));
15
15
 
16
16
  const optionSets = await new Entities().get({
17
17
  entityName: 'type-property-option-set',
18
18
  });
19
19
  await getOptionSets(optionSets);
20
20
 
21
- console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
22
- console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
21
+ console.log('%s Retrieved', chalk.yellow.bold('OPTION SETS'));
22
+ console.log('%s Retrieving', chalk.yellow.bold('TYPES'));
23
23
 
24
24
  const reducedTypes = await getReducedTypes(optionSets);
25
25
  const typesHolder = {
26
26
  types: reducedTypes,
27
27
  };
28
- saveData(typesHolder)
28
+ saveData(typesHolder);
29
29
 
30
- console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
30
+ console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
31
31
 
32
32
  }
33
33
  catch (e) {
@@ -12,7 +12,7 @@ export async function MergeTypeProperties(args) {
12
12
  if (args?.length < 5) {
13
13
  throw new Error('File name must be included along with a type path.');
14
14
  }
15
- console.log(`%s Importing local file`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
15
+ console.log('%s Importing local file', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
16
16
  const fileLocation = args[3];
17
17
  console.log('Using File: ', fileLocation);
18
18
 
@@ -20,7 +20,7 @@ export async function MergeTypeProperties(args) {
20
20
  console.log('Using TypePaths: ', typePaths);
21
21
 
22
22
  await mergeTypeProperties(fileLocation, typePaths);
23
- console.log(`%s Merged`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
23
+ console.log('%s Merged', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
24
24
 
25
25
  }
26
26
  catch (e) {
@@ -62,17 +62,17 @@ async function mergeTypeProperties(fileLocation, typePaths) {
62
62
  if (!foundType){
63
63
  console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
64
64
  }
65
- mergeType(foundType, uploadedTypeProperties)
65
+ mergeType(foundType, uploadedTypeProperties);
66
66
  }
67
67
 
68
- saveData({types: reducedTypes})
68
+ saveData({types: reducedTypes});
69
69
  }
70
70
 
71
71
  function mergeType(reducedType: ReducedType, typePropertiesToAdd: ReducedTypeProperty[]) {
72
72
  for (const typeProperty of typePropertiesToAdd) {
73
- const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug)
73
+ const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug);
74
74
  if (!found) {
75
- reducedType.typeProperties.push(typeProperty)
75
+ reducedType.typeProperties.push(typeProperty);
76
76
  }
77
77
  }
78
78
  }
@@ -1,21 +1,21 @@
1
1
  import { Entities, Request } from '@contrail/sdk';
2
- import { ReducedType, ReducedTypeProperty } from './interfaces';
2
+ import { ReducedType } from './interfaces';
3
3
  import chalk from 'chalk';
4
4
  import fs from 'fs';
5
5
  import { authUser } from '../auth/login';
6
6
  import { getSeparatorByPlatform } from '../common';
7
7
  import * as _ from 'lodash';
8
8
 
9
- const yaml = require('js-yaml');
9
+ import yaml from 'js-yaml';
10
10
 
11
- export async function uploadTypes(args) {
11
+ export async function uploadTypes() {
12
12
  try {
13
13
  const userConfig = await authUser();
14
14
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
15
15
 
16
- console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
16
+ console.log('%s Uploading', chalk.yellow.bold('TYPES'));
17
17
  await uploadReducedTypes();
18
- console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
18
+ console.log('%s Uploaded', chalk.yellow.bold('TYPES'));
19
19
 
20
20
  }
21
21
  catch (e) {
@@ -155,27 +155,27 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
155
155
  await Request.request(
156
156
  `/types/${type.id}/type-properties`,
157
157
  {
158
- method: 'POST',
159
- body: JSON.stringify({
160
- isArchived: newPropertyType.isArchived,
161
- propertyType: newPropertyType.propertyType,
162
- slug: newPropertyType.slug,
163
- label: newPropertyType.label,
164
- editable: newPropertyType.editable,
165
- core: newPropertyType.core,
166
- typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
167
- formula: newPropertyType.formula,
168
- referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
169
- defaultValue: newPropertyType.defaultValue,
170
- propertyLevel: newPropertyType.propertyLevel,
171
- formulaFunction: newPropertyType.formulaFunction,
172
- validationFunction: newPropertyType.validationFunction,
173
- }),
174
- headers: {
175
- 'Accept': 'application/json',
158
+ method: 'POST',
159
+ body: JSON.stringify({
160
+ isArchived: newPropertyType.isArchived,
161
+ propertyType: newPropertyType.propertyType,
162
+ slug: newPropertyType.slug,
163
+ label: newPropertyType.label,
164
+ editable: newPropertyType.editable,
165
+ core: newPropertyType.core,
166
+ typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
167
+ formula: newPropertyType.formula,
168
+ referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
169
+ defaultValue: newPropertyType.defaultValue,
170
+ propertyLevel: newPropertyType.propertyLevel,
171
+ formulaFunction: newPropertyType.formulaFunction,
172
+ validationFunction: newPropertyType.validationFunction,
173
+ }),
174
+ headers: {
175
+ Accept: 'application/json',
176
176
  'Content-Type': 'application/json',
177
- },
178
- });
177
+ },
178
+ });
179
179
  }
180
180
  else if (found && !newPropertyType.inherited && !typePropertiesEqual(found, newPropertyType, optionSetIdByName)) {
181
181
  console.log('Updating Type-Property: ', newPropertyType.slug);
@@ -213,12 +213,12 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
213
213
  await Request.request(
214
214
  `/types/${type.id}/type-properties/${currentPropertyType.id}`,
215
215
  {
216
- method: 'DELETE',
217
- headers: {
218
- 'Accept': 'application/json',
216
+ method: 'DELETE',
217
+ headers: {
218
+ Accept: 'application/json',
219
219
  'Content-Type': 'application/json',
220
- },
221
- });
220
+ },
221
+ });
222
222
  }
223
223
  } catch (err) {
224
224
  throw new Error(`Error Deleting Properties: ${err}`);
@@ -261,4 +261,4 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): b
261
261
  };
262
262
 
263
263
  return _.isEqual(reducedProperty1, reducedProperty2);
264
- }
264
+ }
@@ -1,8 +1,6 @@
1
1
  import { Entities } from '@contrail/sdk';
2
2
  import chalk from 'chalk';
3
- import { App, AppDeclaration, WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
4
- import { getActionDeclarationIdentifier, getActionsForApp } from '../apps/deploy-app/actions-deployer'
5
- import { deleteWorkflowTemplate } from './workflowCommands';
3
+ import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
6
4
 
7
5
  export class WorkflowTemplateDeployer {
8
6
  async deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration) {
@@ -77,7 +75,7 @@ export class WorkflowTemplateDeployer {
77
75
  const actionEntity: any = await getActionByIdentifier(actionKey);
78
76
  actionConfiguration.id = actionEntity.id;
79
77
  } catch (e) {
80
- console.log(e)
78
+ console.log(e);
81
79
  }
82
80
  if(!actionConfiguration.id) {
83
81
  throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
@@ -35,7 +35,6 @@ export async function deployWorkflowTemplate() {
35
35
  await new WorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
36
36
  }
37
37
 
38
-
39
38
  export async function listWorkflowTemplate() {
40
39
  await authUser();
41
40
  return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
@@ -1,38 +1,38 @@
1
- async function execute(config, event, Functions) {
2
- const getBodyFromEvent = (config, event) => {
3
- let body = Functions.stringUtil.parseVariables(config.message, event);
4
- console.log('body: ', body);
5
- if (config.sendDetails) {
6
- const data = event;
7
- const properties = {};
8
- let addedProperty = false;
9
- for (const property of config.fieldsToForward) {
10
- const variableLevels = property.split('.');
11
- let replacementValue = data;
12
- for (let i = 0; i < variableLevels.length; i++) {
13
- replacementValue = replacementValue[variableLevels[i]];
14
- }
15
- properties[property] = replacementValue;
16
- addedProperty = true;
17
- }
18
- if (addedProperty) {
19
- body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
- }
21
- }
22
- return JSON.stringify({ text: body });
23
- };
24
- const body = getBodyFromEvent(config, event);
25
- console.log('Sending message: ', body);
26
- const response = await Functions.fetch(config.url, {
27
- method: 'POST',
28
- body: body,
29
- headers: { 'Content-Type': 'application/json' }
30
- });
31
- if (!response.ok) {
32
- console.log('Webhook event failed to publish');
33
- console.log('Response: ', JSON.stringify(response));
34
- }
35
- else {
36
- console.log('Published!');
37
- }
1
+ async function execute(config, event, Functions) {
2
+ const getBodyFromEvent = (config, event) => {
3
+ let body = Functions.stringUtil.parseVariables(config.message, event);
4
+ console.log('body: ', body);
5
+ if (config.sendDetails) {
6
+ const data = event;
7
+ const properties = {};
8
+ let addedProperty = false;
9
+ for (const property of config.fieldsToForward) {
10
+ const variableLevels = property.split('.');
11
+ let replacementValue = data;
12
+ for (let i = 0; i < variableLevels.length; i++) {
13
+ replacementValue = replacementValue[variableLevels[i]];
14
+ }
15
+ properties[property] = replacementValue;
16
+ addedProperty = true;
17
+ }
18
+ if (addedProperty) {
19
+ body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
+ }
21
+ }
22
+ return JSON.stringify({ text: body });
23
+ };
24
+ const body = getBodyFromEvent(config, event);
25
+ console.log('Sending message: ', body);
26
+ const response = await Functions.fetch(config.url, {
27
+ method: 'POST',
28
+ body: body,
29
+ headers: { 'Content-Type': 'application/json' }
30
+ });
31
+ if (!response.ok) {
32
+ console.log('Webhook event failed to publish');
33
+ console.log('Response: ', JSON.stringify(response));
34
+ }
35
+ else {
36
+ console.log('Published!');
37
+ }
38
38
  }
@@ -1,4 +1,4 @@
1
- export { } // Leave empty export - This allows for multiple files with a function named execute.
1
+ export { }; // Leave empty export - This allows for multiple files with a function named execute.
2
2
  async function execute(config, event, Functions) {
3
3
  const getBodyFromEvent = (config, event) => {
4
4
  let body = Functions.stringUtil.parseVariables(config.message, event);
@@ -4,7 +4,7 @@ appDescription: "Your app description."
4
4
  visibility: public
5
5
  publisher: "Your company name"
6
6
  version: 1.0
7
- isDockerBased: true # this flag should be deprecated since all apps should be docker-based anyway
7
+ # dockerImageRef: repo/name:tag
8
8
 
9
9
  # eventWorkflowTriggerKeyMapping will be used to parse an incoming event into a key that can trigger workflows
10
10
  # {} indicates a field on the event. You can use nested fields by separating the levels with a '.'