@contrail/cli 1.0.14 → 1.0.15

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 (38) hide show
  1. package/lib/cli.js +39 -6
  2. package/lib/types/interfaces.d.ts +2 -2
  3. package/lib/types/option-set-merger.d.ts +1 -0
  4. package/lib/types/option-set-merger.js +102 -0
  5. package/lib/types/option-set-uploader.d.ts +1 -1
  6. package/lib/types/option-set-uploader.js +17 -1
  7. package/lib/types/parse-types.d.ts +2 -0
  8. package/lib/types/parse-types.js +85 -0
  9. package/lib/types/types-extractor.d.ts +1 -0
  10. package/lib/types/types-extractor.js +10 -6
  11. package/lib/types/types-properties-merger.d.ts +1 -0
  12. package/lib/types/types-properties-merger.js +69 -0
  13. package/lib/types/types-uploader.js +0 -4
  14. package/package.json +2 -2
  15. package/src/cli.ts +40 -6
  16. package/src/types/interfaces.ts +2 -2
  17. package/src/types/option-set-merger.ts +123 -0
  18. package/src/types/option-set-uploader.ts +21 -1
  19. package/src/types/parse-types.ts +104 -0
  20. package/src/types/types-extractor.ts +12 -10
  21. package/src/types/types-properties-merger.ts +85 -0
  22. package/src/types/types-uploader.ts +1 -6
  23. package/.eslint.js +0 -54
  24. package/.eslintrc.js +0 -20
  25. package/lib/types/parse-optionSet.d.ts +0 -2
  26. package/lib/types/parse-optionSet.js +0 -79
  27. package/option_sets.yml +0 -15
  28. package/src/types/parse-optionSet.ts +0 -96
  29. package/test/actions/exampleAction.d.ts +0 -1
  30. package/test/actions/exampleAction.js +0 -40
  31. package/test/actions/exampleAction.ts +0 -39
  32. package/test/app.yml +0 -46
  33. package/test/option_sets.yml +0 -15
  34. package/test/package-lock.json +0 -57
  35. package/test/package.json +0 -26
  36. package/test/tsconfig.json +0 -31
  37. package/test/types.yml +0 -1621
  38. package/types.yml +0 -1621
@@ -2,9 +2,29 @@ import { Entities } from '@contrail/sdk';
2
2
  import { ReducedOptionSet } from './interfaces';
3
3
  import fs from 'fs';
4
4
  import { getSeparatorByPlatform } from '../common';
5
+ import { authUser } from '../auth/login';
6
+ import chalk from 'chalk';
5
7
 
6
8
  const yaml = require('js-yaml');
7
9
 
10
+ export async function UploadOptionSets(args) {
11
+ try {
12
+ const userConfig = await authUser();
13
+ console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
14
+
15
+ console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
16
+ await uploadOptionSets();
17
+ console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
18
+
19
+ }
20
+ catch (e) {
21
+ console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
22
+ return;
23
+ }
24
+
25
+ console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
26
+ }
27
+
8
28
  function loadOptionSets(){
9
29
  const TARGET_DIR = process.cwd();
10
30
  try {
@@ -16,7 +36,7 @@ function loadOptionSets(){
16
36
  }
17
37
  }
18
38
 
19
- export async function uploadOptionSets() {
39
+ async function uploadOptionSets() {
20
40
  const optionSets: ReducedOptionSet[] = loadOptionSets();
21
41
 
22
42
  const currentOptionSets = await new Entities().get({
@@ -0,0 +1,104 @@
1
+ import { TypeProcessor } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import fs from 'fs';
4
+ import { getSeparatorByPlatform } from '../common';
5
+ import * as csvToJson from 'csvtojson';
6
+ import { authUser } from '../auth/login';
7
+
8
+ const yaml = require('js-yaml');
9
+
10
+ export async function ParseTypesFromLocalFiles(args) {
11
+ try {
12
+ if (args?.length < 4) {
13
+ throw new Error('File names must be included.');
14
+ }
15
+ console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
16
+ const fileLocations = (args as Array<string>).slice(3);
17
+ console.log('Using File Location(s): ', fileLocations);
18
+
19
+ await parseTypesFromLocalFiles(fileLocations);
20
+ console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
21
+
22
+ }
23
+ catch (e) {
24
+ console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
25
+ return;
26
+ }
27
+
28
+ console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
29
+ }
30
+
31
+ export async function ParseTypesFromFiles(args) {
32
+ try {
33
+ if (args?.length < 4) {
34
+ throw new Error('File ids must be included.');
35
+ }
36
+ console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
37
+ const fileIds = (args as Array<string>).slice(3);
38
+ console.log('Using FileId(s): ', fileIds);
39
+
40
+ await parseTypesFromFiles(fileIds);
41
+ console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
42
+
43
+ }
44
+ catch (e) {
45
+ console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
46
+ return;
47
+ }
48
+
49
+ console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
50
+ }
51
+
52
+ async function loadDataFromCSV(fileName) {
53
+ const CURRENT_DIR = process.cwd();
54
+ try {
55
+ const separator = getSeparatorByPlatform();
56
+ const fullPath = CURRENT_DIR + separator + fileName;
57
+
58
+ console.log('Getting file from path: ', fullPath);
59
+ const csvData = await csvToJson.default().fromFile(fullPath);
60
+
61
+ return csvData;
62
+ } catch (e) {
63
+ throw new Error(`ERROR PARSING CSV: ${e}`);
64
+ }
65
+ }
66
+
67
+ async function parseTypesFromLocalFiles(fileLocations: string[]) {
68
+
69
+ const csvJSONData: any[] = [];
70
+ for (const fileLocation of fileLocations) {
71
+ try {
72
+ console.log('Getting data for fileLocation: ', fileLocation);
73
+ const csvData = await loadDataFromCSV(fileLocation);
74
+
75
+ console.log(`CSV import was successful. ${csvData?.length} rows found. Adding to total rows.`);
76
+ csvJSONData.push(...csvData);
77
+ }
78
+ catch (e) {
79
+ console.log('Error importing csv data.', e);
80
+ throw e;
81
+ }
82
+ }
83
+
84
+ console.log(`CSV imports were successful. ${csvJSONData?.length} total rows found.`);
85
+ const suggestions = await new TypeProcessor().GetSuggestedTypes(csvJSONData)
86
+ saveData({optionSets: suggestions.OptionSets}, 'parsed_optionSets.yml');
87
+ saveData({typeProperties: suggestions.TypeProperties}, 'parsed_typeProperties.yml');
88
+ }
89
+
90
+ async function parseTypesFromFiles(fileIds: string[]) {
91
+ await authUser();
92
+
93
+ const suggestions = await new TypeProcessor().GetSuggestedTypesFromFiles({loadFileIds: fileIds})
94
+
95
+ saveData({optionSets: suggestions.OptionSets}, 'parsed_optionSets.yml');
96
+ saveData({typeProperties: suggestions.TypeProperties}, 'parsed_typeProperties.yml');
97
+ }
98
+
99
+ function saveData(data, name) {
100
+ const yamlStr = yaml.dump(data);
101
+ const CURRENT_DIR = process.cwd();
102
+ const separator = getSeparatorByPlatform();
103
+ fs.writeFileSync(CURRENT_DIR + separator + name, yamlStr, 'utf8');
104
+ }
@@ -1,5 +1,5 @@
1
1
  import { Entities } from '@contrail/sdk';
2
- import { ReducedType, ReducedOptionSet, ReducedTypeProperties } from './interfaces';
2
+ import { ReducedType, ReducedOptionSet, ReducedTypeProperty } from './interfaces';
3
3
  import chalk from 'chalk';
4
4
  import fs from 'fs';
5
5
  import { authUser } from '../auth/login';
@@ -21,7 +21,11 @@ export async function getTypes(args) {
21
21
  console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
22
22
  console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
23
23
 
24
- await getReducedTypes(optionSets);
24
+ const reducedTypes = await getReducedTypes(optionSets);
25
+ const typesHolder = {
26
+ types: reducedTypes,
27
+ };
28
+ saveData(typesHolder)
25
29
 
26
30
  console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
27
31
 
@@ -59,7 +63,7 @@ async function getOptionSets(optionSets) {
59
63
  fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
60
64
  }
61
65
 
62
- async function getReducedTypes(optionSets) {
66
+ export async function getReducedTypes(optionSets) {
63
67
  const types = await new Entities().get({
64
68
  entityName: 'type',
65
69
  });
@@ -81,7 +85,7 @@ async function getReducedTypes(optionSets) {
81
85
 
82
86
  const reducedTypeProperties = [];
83
87
  for (const typeProperty of typeWithProperties.typeProperties) {
84
- const reducedTypeProperty: ReducedTypeProperties = {
88
+ const reducedTypeProperty: ReducedTypeProperty = {
85
89
  slug: typeProperty.slug,
86
90
  id: typeProperty.id,
87
91
  isArchived: typeProperty.isArchived,
@@ -114,14 +118,12 @@ async function getReducedTypes(optionSets) {
114
118
  }
115
119
 
116
120
  reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
121
+ return reducedTypes;
122
+ }
117
123
 
118
- const typesHolder = {
119
- types: reducedTypes,
120
- };
121
-
124
+ function saveData(data) {
125
+ const yamlStr = yaml.dump(data);
122
126
  const CURRENT_DIR = process.cwd();
123
127
  const separator = getSeparatorByPlatform();
124
-
125
- const yamlStr = yaml.dump(typesHolder);
126
128
  fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
127
129
  }
@@ -0,0 +1,85 @@
1
+ import { Entities } from '@contrail/sdk';
2
+ import { getReducedTypes } from './types-extractor';
3
+ import { ReducedTypeProperty, ReducedType } from './interfaces';
4
+ import fs from 'fs';
5
+ import { getSeparatorByPlatform } from '../common';
6
+ import { authUser } from '../auth/login';
7
+ import chalk from 'chalk';
8
+ const yaml = require('js-yaml');
9
+
10
+ export async function MergeTypeProperties(args) {
11
+ try {
12
+ if (args?.length < 5) {
13
+ throw new Error('File name must be included along with a type path.');
14
+ }
15
+ console.log(`%s Importing local file`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
16
+ const fileLocation = args[3];
17
+ console.log('Using File: ', fileLocation);
18
+
19
+ const typePaths = (args as Array<string>).slice(4);
20
+ console.log('Using TypePaths: ', typePaths);
21
+
22
+ await mergeTypeProperties(fileLocation, typePaths);
23
+ console.log(`%s Merged`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
24
+
25
+ }
26
+ catch (e) {
27
+ console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
28
+ return;
29
+ }
30
+
31
+ console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
32
+ }
33
+
34
+ function loadTypeProperties(fileLocation) {
35
+ const TARGET_DIR = process.cwd();
36
+ try {
37
+ const separator = getSeparatorByPlatform();
38
+
39
+ const fullPath = TARGET_DIR + separator + fileLocation;
40
+ console.log('Getting file from path: ', fullPath);
41
+
42
+ const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
43
+ return doc.typeProperties;
44
+ } catch (e) {
45
+ throw new Error(`ERROR PARSING YAML: ${e}`);
46
+ }
47
+ }
48
+
49
+ async function mergeTypeProperties(fileLocation, typePaths) {
50
+ const uploadedTypeProperties: ReducedTypeProperty[] = loadTypeProperties(fileLocation);
51
+
52
+ await authUser();
53
+
54
+ const optionSets = await new Entities().get({
55
+ entityName: 'type-property-option-set',
56
+ });
57
+
58
+ const reducedTypes = await getReducedTypes(optionSets);
59
+
60
+ for (const typePath of typePaths) {
61
+ const foundType = reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
62
+ if (!foundType){
63
+ console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
64
+ }
65
+ mergeType(foundType, uploadedTypeProperties)
66
+ }
67
+
68
+ saveData({types: reducedTypes})
69
+ }
70
+
71
+ function mergeType(reducedType: ReducedType, typePropertiesToAdd: ReducedTypeProperty[]) {
72
+ for (const typeProperty of typePropertiesToAdd) {
73
+ const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug)
74
+ if (!found) {
75
+ reducedType.typeProperties.push(typeProperty)
76
+ }
77
+ }
78
+ }
79
+
80
+ function saveData(data) {
81
+ const yamlStr = yaml.dump(data);
82
+ const CURRENT_DIR = process.cwd();
83
+ const separator = getSeparatorByPlatform();
84
+ fs.writeFileSync(CURRENT_DIR + separator + 'merged_types.yml', yamlStr, 'utf8');
85
+ }
@@ -1,6 +1,5 @@
1
1
  import { Entities, Request } from '@contrail/sdk';
2
- import { ReducedType, ReducedTypeProperties } from './interfaces';
3
- import { uploadOptionSets } from './option-set-uploader';
2
+ import { ReducedType, ReducedTypeProperty } from './interfaces';
4
3
  import chalk from 'chalk';
5
4
  import fs from 'fs';
6
5
  import { authUser } from '../auth/login';
@@ -14,10 +13,6 @@ export async function uploadTypes(args) {
14
13
  const userConfig = await authUser();
15
14
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
16
15
 
17
- console.log(`%s Uploading`, chalk.yellow.bold('OPTION SETS'));
18
- await uploadOptionSets();
19
- console.log(`%s Uploaded`, chalk.yellow.bold('OPTION SETS'));
20
-
21
16
  console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
22
17
  await uploadReducedTypes();
23
18
  console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
package/.eslint.js DELETED
@@ -1,54 +0,0 @@
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
- };
54
-
package/.eslintrc.js DELETED
@@ -1,20 +0,0 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es2021": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "parser": "@typescript-eslint/parser",
11
- "parserOptions": {
12
- "ecmaVersion": "latest",
13
- "sourceType": "module"
14
- },
15
- "plugins": [
16
- "@typescript-eslint"
17
- ],
18
- "rules": {
19
- }
20
- }
@@ -1,2 +0,0 @@
1
- export declare function parseOptionSet(args: any): Promise<void>;
2
- export declare function parseOptionSets(fileName: any): Promise<void>;
@@ -1,79 +0,0 @@
1
- import { StringUtil } from '@contrail/util';
2
- import chalk from 'chalk';
3
- import fs from 'fs';
4
- import { getSeparatorByPlatform } from '../common';
5
- import * as csvToJson from 'csvtojson';
6
- const yaml = require('js-yaml');
7
- export async function parseOptionSet(args) {
8
- try {
9
- if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
10
- throw new Error('File name must be included.');
11
- }
12
- console.log(`%s Parsing`, chalk.yellow.bold('OPTION SETS'));
13
- await parseOptionSets(args[3]);
14
- console.log(`%s Parsed`, chalk.yellow.bold('OPTION SETS'));
15
- }
16
- catch (e) {
17
- console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
18
- return;
19
- }
20
- console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
21
- }
22
- async function loadDataFromCSV(fileName) {
23
- const CURRENT_DIR = process.cwd();
24
- try {
25
- const separator = getSeparatorByPlatform();
26
- const csvData = await csvToJson.default().fromFile(CURRENT_DIR + separator + fileName);
27
- return csvData;
28
- }
29
- catch (e) {
30
- throw new Error(`ERROR PARSING CSV: ${e}`);
31
- }
32
- }
33
- export async function parseOptionSets(fileName) {
34
- const csvData = await loadDataFromCSV(fileName);
35
- const removedFields = new Set();
36
- const valuesByFieldName = {};
37
- for (const row of csvData) {
38
- for (const [key, value] of Object.entries(row)) {
39
- // Dont parse boolean fields - later log removed fields
40
- if (value.toLowerCase() === 'false' || value.toLowerCase() === 'true') {
41
- removedFields.add(key);
42
- continue;
43
- }
44
- if (!value) {
45
- continue;
46
- }
47
- if (!valuesByFieldName[key]) {
48
- valuesByFieldName[key] = new Set();
49
- }
50
- valuesByFieldName[key].add(value);
51
- }
52
- }
53
- for (const removed of removedFields.values()) {
54
- console.log(`Removed Boolean Field: ${removed}`);
55
- }
56
- const reducedOptionSets = [];
57
- for (const [key, value] of Object.entries(valuesByFieldName)) {
58
- const optionSet = [];
59
- for (const entry of value.values()) {
60
- optionSet.push({
61
- value: StringUtil.convertToCamelCase(entry),
62
- display: isUpperCase(entry) ? entry : StringUtil.convertToTitleCase(entry),
63
- });
64
- }
65
- const reducedOptionSet = {
66
- name: StringUtil.convertToTitleCase(key),
67
- isArchived: false,
68
- optionSet,
69
- };
70
- reducedOptionSets.push(reducedOptionSet);
71
- }
72
- const yamlStr = yaml.dump(reducedOptionSets);
73
- const CURRENT_DIR = process.cwd();
74
- const separator = getSeparatorByPlatform();
75
- fs.writeFileSync(CURRENT_DIR + separator + 'parsed_option_sets.yml', yamlStr, 'utf8');
76
- }
77
- function isUpperCase(str) {
78
- return str === str.toUpperCase();
79
- }
package/option_sets.yml DELETED
@@ -1,15 +0,0 @@
1
- optionSets:
2
- - name: Collection
3
- isArchived: false
4
- optionSet:
5
- - value: collection_1
6
- display: Collection 1
7
- - value: collection_2
8
- display: Collection 2
9
- - name: Gender
10
- isArchived: false
11
- optionSet:
12
- - value: womens
13
- display: Women's
14
- - value: mens
15
- display: Men's
@@ -1,96 +0,0 @@
1
- import { StringUtil } from '@contrail/util';
2
- import { ReducedOptionSet } from './interfaces';
3
- import chalk from 'chalk';
4
- import fs from 'fs';
5
- import { getSeparatorByPlatform } from '../common';
6
- import * as csvToJson from 'csvtojson';
7
-
8
- const yaml = require('js-yaml');
9
-
10
- export async function parseOptionSet(args) {
11
- try {
12
- if (args?.length < 4) {
13
- throw new Error('File name must be included.');
14
- }
15
- console.log(`%s Parsing`, chalk.yellow.bold('OPTION SETS'));
16
- await parseOptionSets(args[3]);
17
- console.log(`%s Parsed`, chalk.yellow.bold('OPTION SETS'));
18
-
19
- }
20
- catch (e) {
21
- console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
22
- return;
23
- }
24
-
25
- console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
26
- }
27
-
28
- async function loadDataFromCSV(fileName) {
29
- const CURRENT_DIR = process.cwd();
30
- try {
31
- const separator = getSeparatorByPlatform();
32
- const csvData = await csvToJson.default().fromFile(CURRENT_DIR + separator + fileName);
33
-
34
- return csvData;
35
- } catch (e) {
36
- throw new Error(`ERROR PARSING CSV: ${e}`);
37
- }
38
- }
39
-
40
- export async function parseOptionSets(fileName) {
41
- const csvData = await loadDataFromCSV(fileName);
42
-
43
- const removedFields = new Set<string>();
44
- const valuesByFieldName = {};
45
- for (const row of csvData) {
46
- for (const [key, value] of Object.entries(row)) {
47
-
48
- // Dont parse boolean fields - later log removed fields
49
- if ((value as string).toLowerCase() === 'false' || (value as string).toLowerCase() === 'true') {
50
- removedFields.add(key);
51
- continue;
52
- }
53
-
54
- if (!value) {
55
- continue;
56
- }
57
-
58
- if (!valuesByFieldName[key]) {
59
- valuesByFieldName[key] = new Set<string>();
60
- }
61
- (valuesByFieldName[key] as Set<string>).add(value as string);
62
- }
63
- }
64
-
65
- for (const removed of removedFields.values()) {
66
- console.log(`Removed Boolean Field: ${removed}`);
67
- }
68
-
69
- const reducedOptionSets = [];
70
- for (const [key, value] of Object.entries(valuesByFieldName)) {
71
- const optionSet = [];
72
- for (const entry of (value as Set<string>).values()) {
73
- optionSet.push({
74
- value: StringUtil.convertToCamelCase(entry),
75
- display: isUpperCase(entry) ? entry : StringUtil.convertToTitleCase(entry), // if all uppercase dont convert
76
- });
77
- }
78
-
79
- const reducedOptionSet: ReducedOptionSet = {
80
- name: StringUtil.convertToTitleCase(key),
81
- isArchived: false,
82
- optionSet,
83
- };
84
-
85
- reducedOptionSets.push(reducedOptionSet);
86
- }
87
-
88
- const yamlStr = yaml.dump(reducedOptionSets);
89
- const CURRENT_DIR = process.cwd();
90
- const separator = getSeparatorByPlatform();
91
- fs.writeFileSync(CURRENT_DIR + separator + 'parsed_option_sets.yml', yamlStr, 'utf8');
92
- }
93
-
94
- function isUpperCase(str) {
95
- return str === str.toUpperCase();
96
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- async function execute(config, event, Functions) {
4
- const getBodyFromEvent = (config, event) => {
5
- let body = Functions.stringUtil.parseVariables(config.message, event);
6
- console.log('body: ', body);
7
- if (config.sendDetails) {
8
- const data = event;
9
- const properties = {};
10
- let addedProperty = false;
11
- for (const property of config.fieldsToForward) {
12
- const variableLevels = property.split('.');
13
- let replacementValue = data;
14
- for (let i = 0; i < variableLevels.length; i++) {
15
- replacementValue = replacementValue[variableLevels[i]];
16
- }
17
- properties[property] = replacementValue;
18
- addedProperty = true;
19
- }
20
- if (addedProperty) {
21
- body = body + ' Properties: ' + JSON.stringify(properties) + '.';
22
- }
23
- }
24
- return JSON.stringify({ text: body });
25
- };
26
- const body = getBodyFromEvent(config, event);
27
- console.log('Sending message: ', body);
28
- const response = await Functions.fetch(config.url, {
29
- method: 'POST',
30
- body: body,
31
- headers: { 'Content-Type': 'application/json' }
32
- });
33
- if (!response.ok) {
34
- console.log('Webhook event failed to publish');
35
- console.log('Response: ', JSON.stringify(response));
36
- }
37
- else {
38
- console.log('Published!');
39
- }
40
- }
@@ -1,39 +0,0 @@
1
- export { } // Leave empty export - This allows for multiple files with a function named execute.
2
- async function execute(config, event, Functions) {
3
- const getBodyFromEvent = (config, event) => {
4
- let body = Functions.stringUtil.parseVariables(config.message, event);
5
- console.log('body: ', body);
6
- if (config.sendDetails) {
7
- const data = event;
8
- const properties = {};
9
- let addedProperty = false;
10
- for (const property of config.fieldsToForward) {
11
- const variableLevels = property.split('.');
12
- let replacementValue = data;
13
- for (let i = 0; i < variableLevels.length; i++) {
14
- replacementValue = replacementValue[variableLevels[i]];
15
- }
16
- properties[property] = replacementValue;
17
- addedProperty = true;
18
- }
19
- if (addedProperty) {
20
- body = body + ' Properties: ' + JSON.stringify(properties) + '.';
21
- }
22
- }
23
- return JSON.stringify({ text: body });
24
- };
25
- const body = getBodyFromEvent(config, event);
26
- console.log('Sending message: ', body);
27
- const response = await Functions.fetch(config.url, {
28
- method: 'POST',
29
- body: body,
30
- headers: { 'Content-Type': 'application/json' }
31
- });
32
- if (!response.ok) {
33
- console.log('Webhook event failed to publish');
34
- console.log('Response: ', JSON.stringify(response));
35
- }
36
- else {
37
- console.log('Published!');
38
- }
39
- }