@contrail/cli 1.0.3 → 1.0.7
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/lib/{create-app → apps/create-app}/create.d.ts +0 -0
- package/lib/{create-app → apps/create-app}/create.js +1 -5
- package/lib/{create-app → apps/create-app}/setup-template.d.ts +0 -0
- package/lib/{create-app → apps/create-app}/setup-template.js +1 -1
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.js +18 -7
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +1 -1
- package/lib/{deploy-app → apps/deploy-app}/app-template-parsers.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/app-template-parsers.js +0 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.d.ts +0 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.js +4 -2
- package/lib/{deploy-app → apps/deploy-app}/interfaces.d.ts +1 -1
- package/lib/{deploy-app → apps/deploy-app}/interfaces.js +0 -0
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +3 -2
- package/lib/cli.js +105 -15
- package/lib/common.d.ts +1 -0
- package/lib/common.js +5 -0
- package/lib/types/interfaces.d.ts +50 -0
- package/lib/types/interfaces.js +0 -0
- package/lib/types/option-set-uploader.d.ts +1 -0
- package/lib/types/option-set-uploader.js +75 -0
- package/lib/types/parse-optionSet.d.ts +2 -0
- package/lib/types/parse-optionSet.js +79 -0
- package/lib/types/types-extractor.d.ts +1 -0
- package/lib/types/types-extractor.js +98 -0
- package/lib/types/types-uploader.d.ts +1 -0
- package/lib/types/types-uploader.js +228 -0
- package/package.json +8 -3
- package/src/{create-app → apps/create-app}/create.ts +0 -0
- package/src/{create-app → apps/create-app}/setup-template.ts +1 -1
- package/src/{deploy-app → apps/deploy-app}/actions-deployer.ts +22 -9
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +1 -1
- package/src/{deploy-app → apps/deploy-app}/app-template-parsers.ts +0 -0
- package/src/{deploy-app → apps/deploy-app}/deploy.ts +4 -2
- package/src/{deploy-app → apps/deploy-app}/interfaces.ts +1 -1
- package/src/auth/login.ts +7 -5
- package/src/cli.ts +115 -15
- package/src/common.ts +5 -0
- package/src/types/interfaces.ts +53 -0
- package/src/types/option-set-uploader.ts +83 -0
- package/src/types/parse-optionSet.ts +96 -0
- package/src/types/types-extractor.ts +125 -0
- package/src/types/types-uploader.ts +261 -0
- package/templates/javascript/actions/example/action.js +1 -1
- package/templates/typescript/actions/exampleAction.ts +38 -37
- package/tsconfig.json +10 -2
- package/templates/javascript/set_auth.bat +0 -3
- package/templates/javascript/set_auth.sh +0 -3
- package/templates/typescript/set_auth.bat +0 -3
- package/templates/typescript/set_auth.sh +0 -3
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import { ReducedOptionSet } from './interfaces';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { getSeparatorByPlatform } from '../common';
|
|
5
|
+
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
|
|
8
|
+
function loadOptionSets(){
|
|
9
|
+
const TARGET_DIR = process.cwd();
|
|
10
|
+
try {
|
|
11
|
+
const separator = getSeparatorByPlatform();
|
|
12
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'option_sets.yml', 'utf8'));
|
|
13
|
+
return doc.optionSets;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function uploadOptionSets() {
|
|
20
|
+
const optionSets: ReducedOptionSet[] = loadOptionSets();
|
|
21
|
+
|
|
22
|
+
const currentOptionSets = await new Entities().get({
|
|
23
|
+
entityName: 'type-property-option-set',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const currentOptionSetsByName = {};
|
|
27
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
28
|
+
currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const newOptionSetsByName = {};
|
|
32
|
+
for (const optionSet of optionSets) {
|
|
33
|
+
newOptionSetsByName[optionSet.name] = optionSet;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const optionSet of optionSets) {
|
|
37
|
+
try {
|
|
38
|
+
const found = currentOptionSetsByName[optionSet.name];
|
|
39
|
+
if (!found) {
|
|
40
|
+
console.log('Creating: ', optionSet.name);
|
|
41
|
+
await new Entities().create({
|
|
42
|
+
entityName: 'type-property-option-set',
|
|
43
|
+
object: {
|
|
44
|
+
name: optionSet.name,
|
|
45
|
+
optionSet: optionSet.optionSet,
|
|
46
|
+
isArchived: optionSet.isArchived,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
{
|
|
52
|
+
console.log('Updating: ', optionSet.name);
|
|
53
|
+
await new Entities().update({
|
|
54
|
+
entityName: 'type-property-option-set',
|
|
55
|
+
id: found.id,
|
|
56
|
+
object: {
|
|
57
|
+
name: optionSet.name,
|
|
58
|
+
optionSet: optionSet.optionSet,
|
|
59
|
+
isArchived: optionSet.isArchived,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
throw new Error(`Error Uploading OptionSets: ${err}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
69
|
+
try {
|
|
70
|
+
const found = newOptionSetsByName[currentOptionSet.name];
|
|
71
|
+
if (!found) {
|
|
72
|
+
console.log('Deleting: ', currentOptionSet.name);
|
|
73
|
+
await new Entities().delete({
|
|
74
|
+
entityName: 'type-property-option-set',
|
|
75
|
+
id: currentOptionSet.id,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw new Error(`Error Deleting OptionSets: ${err}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import { ReducedType, ReducedOptionSet, ReducedTypeProperties } from './interfaces';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { authUser } from '../auth/login';
|
|
6
|
+
import { getSeparatorByPlatform } from '../common';
|
|
7
|
+
|
|
8
|
+
const yaml = require('js-yaml');
|
|
9
|
+
|
|
10
|
+
export async function getTypes(args) {
|
|
11
|
+
try {
|
|
12
|
+
const userConfig = await authUser();
|
|
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'));
|
|
15
|
+
|
|
16
|
+
const optionSets = await new Entities().get({
|
|
17
|
+
entityName: 'type-property-option-set',
|
|
18
|
+
});
|
|
19
|
+
await getOptionSets(optionSets);
|
|
20
|
+
|
|
21
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
|
|
22
|
+
console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
|
|
23
|
+
|
|
24
|
+
await getReducedTypes(optionSets);
|
|
25
|
+
|
|
26
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.log(`%s Types Retrieval Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log('%s Types Retrieval Complete.', chalk.green.bold('COMPLETE'));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function getOptionSets(optionSets) {
|
|
38
|
+
let reducedOptionSets = [];
|
|
39
|
+
for (const optionSet of optionSets) {
|
|
40
|
+
const reducedOptionSet: ReducedOptionSet = {
|
|
41
|
+
name: optionSet.name,
|
|
42
|
+
isArchived: optionSet.isArchived,
|
|
43
|
+
optionSet: optionSet.optionSet,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
reducedOptionSets.push(reducedOptionSet);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const optionSetsHolder = {
|
|
50
|
+
optionSets: reducedOptionSets,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
reducedOptionSets = reducedOptionSets.sort((one, two) => (one.name < two.name ? -1 : 1));
|
|
54
|
+
|
|
55
|
+
const CURRENT_DIR = process.cwd();
|
|
56
|
+
const separator = getSeparatorByPlatform();
|
|
57
|
+
|
|
58
|
+
const yamlStr = yaml.dump(optionSetsHolder);
|
|
59
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function getReducedTypes(optionSets) {
|
|
63
|
+
const types = await new Entities().get({
|
|
64
|
+
entityName: 'type',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log('Found types: ', types.length);
|
|
68
|
+
|
|
69
|
+
let reducedTypes = [];
|
|
70
|
+
for (const type of types) {
|
|
71
|
+
const typeWithProperties = await new Entities().get({
|
|
72
|
+
entityName: 'type',
|
|
73
|
+
id: type.id,
|
|
74
|
+
relations: ['typeProperties'],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const optionSetNameById = {};
|
|
78
|
+
for (const optionSet of optionSets) {
|
|
79
|
+
optionSetNameById[optionSet.id] = optionSet.name;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const reducedTypeProperties = [];
|
|
83
|
+
for (const typeProperty of typeWithProperties.typeProperties) {
|
|
84
|
+
const reducedTypeProperty: ReducedTypeProperties = {
|
|
85
|
+
slug: typeProperty.slug,
|
|
86
|
+
id: typeProperty.id,
|
|
87
|
+
isArchived: typeProperty.isArchived,
|
|
88
|
+
propertyType: typeProperty.propertyType,
|
|
89
|
+
label: typeProperty.label,
|
|
90
|
+
editable: typeProperty.editable,
|
|
91
|
+
core: typeProperty.core,
|
|
92
|
+
typePropertyOptionSetName: optionSetNameById[typeProperty.typePropertyOptionSetId],
|
|
93
|
+
formula: typeProperty.formula,
|
|
94
|
+
referencedTypeRootSlug: typeProperty.referencedTypeRootSlug,
|
|
95
|
+
defaultValue: typeProperty.defaultValue,
|
|
96
|
+
propertyLevel: typeProperty.propertyLevel,
|
|
97
|
+
inherited: typeProperty.inherited,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
reducedTypeProperties.push(reducedTypeProperty);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const reducedType: ReducedType = {
|
|
104
|
+
typePath: typeWithProperties.typePath,
|
|
105
|
+
slug: typeWithProperties.slug,
|
|
106
|
+
label: typeWithProperties.label,
|
|
107
|
+
isArchived: typeWithProperties.isArchived,
|
|
108
|
+
typeProperties: reducedTypeProperties,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
reducedTypes.push(reducedType);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
reducedTypes = reducedTypes.sort((one, two) => (one.typePath < two.typePath ? -1 : 1));
|
|
115
|
+
|
|
116
|
+
const typesHolder = {
|
|
117
|
+
types: reducedTypes,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const CURRENT_DIR = process.cwd();
|
|
121
|
+
const separator = getSeparatorByPlatform();
|
|
122
|
+
|
|
123
|
+
const yamlStr = yaml.dump(typesHolder);
|
|
124
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
|
|
125
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Entities, Request } from '@contrail/sdk';
|
|
2
|
+
import { ReducedType, ReducedTypeProperties } from './interfaces';
|
|
3
|
+
import { uploadOptionSets } from './option-set-uploader';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { authUser } from '../auth/login';
|
|
7
|
+
import { getSeparatorByPlatform } from '../common';
|
|
8
|
+
import * as _ from 'lodash';
|
|
9
|
+
|
|
10
|
+
const yaml = require('js-yaml');
|
|
11
|
+
|
|
12
|
+
export async function uploadTypes(args) {
|
|
13
|
+
try {
|
|
14
|
+
const userConfig = await authUser();
|
|
15
|
+
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
16
|
+
|
|
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
|
+
console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
|
|
22
|
+
await uploadReducedTypes();
|
|
23
|
+
console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function loadReducedTypes(){
|
|
35
|
+
const TARGET_DIR = process.cwd();
|
|
36
|
+
try {
|
|
37
|
+
const separator = getSeparatorByPlatform();
|
|
38
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'types.yml', 'utf8'));
|
|
39
|
+
return doc.types;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function uploadReducedTypes() {
|
|
46
|
+
const types: ReducedType[] = loadReducedTypes();
|
|
47
|
+
|
|
48
|
+
const currentTypesWithoutProperties = await new Entities().get({
|
|
49
|
+
entityName: 'type',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const currentTypes = [];
|
|
53
|
+
for (const currentTypeWithoutProperties of currentTypesWithoutProperties) {
|
|
54
|
+
const typeWithProperties = await new Entities().get({
|
|
55
|
+
entityName: 'type',
|
|
56
|
+
id: currentTypeWithoutProperties.id,
|
|
57
|
+
relations: ['typeProperties'],
|
|
58
|
+
});
|
|
59
|
+
currentTypes.push(typeWithProperties);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const currentTypesBySlug = {};
|
|
63
|
+
for (const currentType of currentTypes) {
|
|
64
|
+
currentTypesBySlug[currentType.slug] = currentType;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const newTypesBySlug = {};
|
|
68
|
+
for (const type of types) {
|
|
69
|
+
newTypesBySlug[type.slug] = type;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const type of types) {
|
|
73
|
+
try {
|
|
74
|
+
const found = currentTypesBySlug[type.slug];
|
|
75
|
+
if (!found) {
|
|
76
|
+
if (!type.typePath.includes(':')) {
|
|
77
|
+
console.log('Cannot create a base type. Skipping: ', type.slug);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log('Creating Type: ', type.slug);
|
|
82
|
+
|
|
83
|
+
const createdType = await new Entities().create({
|
|
84
|
+
entityName: 'type',
|
|
85
|
+
object: {
|
|
86
|
+
slug: type.slug,
|
|
87
|
+
label: type.label,
|
|
88
|
+
typePath: type.typePath,
|
|
89
|
+
isArchived: type.isArchived,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await uploadReducedTypeProperties(createdType, [], type.typeProperties);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
console.log('Updating Type: ', type.slug);
|
|
98
|
+
const updatedType = await new Entities().update({
|
|
99
|
+
entityName: 'type',
|
|
100
|
+
id: found.id,
|
|
101
|
+
object: {
|
|
102
|
+
slug: type.slug,
|
|
103
|
+
label: type.label,
|
|
104
|
+
typePath: type.typePath,
|
|
105
|
+
isArchived: type.isArchived,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await uploadReducedTypeProperties(updatedType, found.typeProperties, type.typeProperties);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.log('Error Uploading Types: ', err);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const currentType of currentTypes) {
|
|
118
|
+
try {
|
|
119
|
+
const found = newTypesBySlug[currentType.slug];
|
|
120
|
+
if (!found) {
|
|
121
|
+
console.log('Deleting Type: ', currentType.slug);
|
|
122
|
+
await new Entities().delete({
|
|
123
|
+
entityName: 'type',
|
|
124
|
+
id: currentType.id,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw new Error(`Error Deleting Types: ${err}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes) {
|
|
135
|
+
const currentPropertyTypeBySlug = {};
|
|
136
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
137
|
+
currentPropertyTypeBySlug[currentPropertyType.slug] = currentPropertyType;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const newPropertyTypesBySlug = {};
|
|
141
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
142
|
+
newPropertyTypesBySlug[newPropertyType.slug] = newPropertyType;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const optionSets = await new Entities().get({
|
|
146
|
+
entityName: 'type-property-option-set',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const optionSetIdByName = {};
|
|
150
|
+
for (const optionSet of optionSets) {
|
|
151
|
+
optionSetIdByName[optionSet.name] = optionSet.id;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
155
|
+
try {
|
|
156
|
+
const found = currentPropertyTypeBySlug[newPropertyType.slug];
|
|
157
|
+
if (!found && !newPropertyType.inherited) {
|
|
158
|
+
console.log('Creating Type-Property: ', newPropertyType.slug);
|
|
159
|
+
|
|
160
|
+
await Request.request(
|
|
161
|
+
`/types/${type.id}/type-properties`,
|
|
162
|
+
{
|
|
163
|
+
method: 'POST',
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
isArchived: newPropertyType.isArchived,
|
|
166
|
+
propertyType: newPropertyType.propertyType,
|
|
167
|
+
slug: newPropertyType.slug,
|
|
168
|
+
label: newPropertyType.label,
|
|
169
|
+
editable: newPropertyType.editable,
|
|
170
|
+
core: newPropertyType.core,
|
|
171
|
+
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
172
|
+
formula: newPropertyType.formula,
|
|
173
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
174
|
+
defaultValue: newPropertyType.defaultValue,
|
|
175
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
176
|
+
}),
|
|
177
|
+
headers: {
|
|
178
|
+
'Accept': 'application/json',
|
|
179
|
+
'Content-Type': 'application/json',
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else if (found && !newPropertyType.inherited && !typePropertiesEqual(found, newPropertyType, optionSetIdByName)) {
|
|
184
|
+
console.log('Updating Type-Property: ', newPropertyType.slug);
|
|
185
|
+
await new Entities().update({
|
|
186
|
+
entityName: 'type-property',
|
|
187
|
+
id: found.id,
|
|
188
|
+
object: {
|
|
189
|
+
isArchived: newPropertyType.isArchived,
|
|
190
|
+
propertyType: newPropertyType.propertyType,
|
|
191
|
+
slug: newPropertyType.slug,
|
|
192
|
+
label: newPropertyType.label,
|
|
193
|
+
editable: newPropertyType.editable,
|
|
194
|
+
core: newPropertyType.core,
|
|
195
|
+
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
196
|
+
formula: newPropertyType.formula,
|
|
197
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
198
|
+
defaultValue: newPropertyType.defaultValue,
|
|
199
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.log('Error Creating Properties: ', err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
210
|
+
try {
|
|
211
|
+
const found = newPropertyTypesBySlug[currentPropertyType.slug];
|
|
212
|
+
if (!found && !currentPropertyType.inherited) {
|
|
213
|
+
console.log('Deleting Type-Property: ', currentPropertyType.slug);
|
|
214
|
+
await Request.request(
|
|
215
|
+
`/types/${type.id}/type-properties/${currentPropertyType.id}`,
|
|
216
|
+
{
|
|
217
|
+
method: 'DELETE',
|
|
218
|
+
headers: {
|
|
219
|
+
'Accept': 'application/json',
|
|
220
|
+
'Content-Type': 'application/json',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
} catch (err) {
|
|
225
|
+
throw new Error(`Error Deleting Properties: ${err}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): boolean {
|
|
231
|
+
|
|
232
|
+
const reducedProperty1 = {
|
|
233
|
+
isArchived: typeProperty1.isArchived,
|
|
234
|
+
propertyType: typeProperty1.propertyType,
|
|
235
|
+
slug: typeProperty1.slug,
|
|
236
|
+
label: typeProperty1.label,
|
|
237
|
+
editable: typeProperty1.editable,
|
|
238
|
+
core: typeProperty1.core,
|
|
239
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
240
|
+
formula: typeProperty1.formula,
|
|
241
|
+
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
242
|
+
defaultValue: typeProperty1.defaultValue,
|
|
243
|
+
propertyLevel: typeProperty1.propertyLevel,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const reducedProperty2 = {
|
|
247
|
+
isArchived: typeProperty2.isArchived,
|
|
248
|
+
propertyType: typeProperty2.propertyType,
|
|
249
|
+
slug: typeProperty2.slug,
|
|
250
|
+
label: typeProperty2.label,
|
|
251
|
+
editable: typeProperty2.editable,
|
|
252
|
+
core: typeProperty2.core,
|
|
253
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
254
|
+
formula: typeProperty2.formula,
|
|
255
|
+
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
256
|
+
defaultValue: typeProperty2.defaultValue,
|
|
257
|
+
propertyLevel: typeProperty2.propertyLevel,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
261
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function execute(config, event, Functions) {
|
|
2
2
|
const getBodyFromEvent = (config, event) => {
|
|
3
|
-
let body = Functions.
|
|
3
|
+
let body = Functions.stringUtil.parseVariables(config.message, event);
|
|
4
4
|
console.log('body: ', body);
|
|
5
5
|
if (config.sendDetails) {
|
|
6
6
|
const data = event;
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.log('
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
}
|
|
38
39
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "es2017",
|
|
4
4
|
"module": "esnext",
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"esModuleInterop": true,
|
|
@@ -11,7 +11,15 @@
|
|
|
11
11
|
"noImplicitAny": false,
|
|
12
12
|
"emitDecoratorMetadata": true,
|
|
13
13
|
"skipLibCheck": true,
|
|
14
|
-
"moduleResolution": "node"
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"lib": [
|
|
16
|
+
"es5",
|
|
17
|
+
"ES2015",
|
|
18
|
+
"ES2016",
|
|
19
|
+
"ES2017",
|
|
20
|
+
"dom",
|
|
21
|
+
"esnext.asynciterable"
|
|
22
|
+
],
|
|
15
23
|
},
|
|
16
24
|
"include": [
|
|
17
25
|
"src"
|