@contrail/cli 1.0.67 → 1.0.69
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/.eslintrc.js +53 -53
- package/.vscode/settings.json +5 -5
- package/README.md +5 -5
- package/bin/init +3 -3
- package/lib/api/apps.d.ts +13 -13
- package/lib/api/apps.js +85 -85
- package/lib/api/event-workflow-action-definition.d.ts +1 -1
- package/lib/api/event-workflow-action-definition.js +7 -7
- package/lib/api/event-workflow-template-definition.d.ts +6 -6
- package/lib/api/event-workflow-template-definition.js +20 -20
- package/lib/api/event-workflow-templates.d.ts +7 -7
- package/lib/api/event-workflow-templates.js +25 -25
- package/lib/apps/create-app/create.d.ts +1 -1
- package/lib/apps/create-app/create.js +60 -59
- package/lib/apps/create-app/setup-template.d.ts +1 -1
- package/lib/apps/create-app/setup-template.js +34 -34
- package/lib/apps/deploy-app/actions-deployer.d.ts +11 -11
- package/lib/apps/deploy-app/actions-deployer.js +114 -114
- package/lib/apps/deploy-app/app-deployer.d.ts +8 -8
- package/lib/apps/deploy-app/app-deployer.js +93 -93
- package/lib/apps/deploy-app/app-template-parsers.d.ts +7 -7
- package/lib/apps/deploy-app/app-template-parsers.js +38 -38
- package/lib/apps/deploy-app/deploy.d.ts +2 -2
- package/lib/apps/deploy-app/deploy.js +58 -58
- package/lib/apps/install-app/app-installer.d.ts +2 -2
- package/lib/apps/install-app/app-installer.js +120 -120
- package/lib/apps/upgrade-app/app-upgrader.d.ts +3 -3
- package/lib/apps/upgrade-app/app-upgrader.js +126 -126
- package/lib/auth/auth.d.ts +9 -9
- package/lib/auth/auth.js +2 -2
- package/lib/auth/login.d.ts +2 -2
- package/lib/auth/login.js +141 -141
- package/lib/cli.d.ts +5 -5
- package/lib/cli.js +524 -481
- package/lib/colors/color-loader.d.ts +2 -2
- package/lib/colors/color-loader.js +96 -96
- package/lib/common.d.ts +1 -1
- package/lib/common.js +5 -5
- package/lib/config/config.d.ts +6 -6
- package/lib/config/config.js +70 -70
- package/lib/config/configCommands.d.ts +3 -3
- package/lib/config/configCommands.js +34 -34
- package/lib/interfaces.d.ts +191 -191
- package/lib/interfaces.js +25 -25
- package/lib/loader-process/loader-process.d.ts +2 -2
- package/lib/loader-process/loader-process.js +120 -120
- package/lib/projects/interfaces.d.ts +77 -77
- package/lib/projects/interfaces.js +23 -23
- package/lib/projects/project-exporter.d.ts +2 -2
- package/lib/projects/project-exporter.js +187 -187
- package/lib/projects/project-uploader.d.ts +1 -1
- package/lib/projects/project-uploader.js +105 -105
- package/lib/types/allUploader.d.ts +1 -1
- package/lib/types/allUploader.js +24 -24
- package/lib/types/csv-parser.d.ts +1 -1
- package/lib/types/csv-parser.js +51 -51
- package/lib/types/interfaces.d.ts +55 -55
- package/lib/types/interfaces.js +1 -1
- package/lib/types/option-set-hierarchy-exporter.d.ts +1 -1
- package/lib/types/option-set-hierarchy-exporter.js +113 -113
- package/lib/types/option-set-hierarchy-parser.d.ts +2 -2
- package/lib/types/option-set-hierarchy-parser.js +140 -140
- package/lib/types/option-set-hierarchy-uploader.d.ts +1 -1
- package/lib/types/option-set-hierarchy-uploader.js +113 -113
- package/lib/types/option-set-merger.d.ts +1 -1
- package/lib/types/option-set-merger.js +105 -102
- package/lib/types/option-set-parser.d.ts +3 -1
- package/lib/types/option-set-parser.js +140 -50
- package/lib/types/option-set-uploader.d.ts +1 -1
- package/lib/types/option-set-uploader.js +98 -98
- package/lib/types/parse-types.d.ts +4 -4
- package/lib/types/parse-types.js +189 -189
- package/lib/types/rule-set-uploader.d.ts +1 -1
- package/lib/types/rule-set-uploader.js +172 -172
- package/lib/types/type-property-policy-uploader.d.ts +1 -1
- package/lib/types/type-property-policy-uploader.js +178 -178
- package/lib/types/types-extractor.d.ts +27 -27
- package/lib/types/types-extractor.js +318 -318
- package/lib/types/types-properties-merger.d.ts +1 -1
- package/lib/types/types-properties-merger.js +75 -75
- package/lib/types/types-uploader.d.ts +1 -1
- package/lib/types/types-uploader.js +239 -239
- package/lib/types/usage-info-uploader.d.ts +1 -1
- package/lib/types/usage-info-uploader.js +132 -132
- package/lib/users/user-exporter.d.ts +1 -0
- package/lib/users/user-exporter.js +41 -0
- package/lib/users/user-uploader.d.ts +1 -0
- package/lib/users/user-uploader.js +45 -0
- package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +2 -2
- package/lib/workflow-template-definitions/workflow-template-definition-commands.js +10 -10
- package/lib/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
- package/lib/workflow-template-definitions/workflow-template-definition-deployer.js +151 -151
- package/lib/workflow-templates/local-workflow-template-deployer.d.ts +11 -11
- package/lib/workflow-templates/local-workflow-template-deployer.js +102 -102
- package/lib/workflow-templates/workflow-template-commands.d.ts +4 -4
- package/lib/workflow-templates/workflow-template-commands.js +51 -51
- package/lib/workflow-templates/workflow-template-deployer.d.ts +4 -4
- package/lib/workflow-templates/workflow-template-deployer.js +26 -26
- package/package.json +72 -72
- package/publish.bat +5 -0
- package/publish.sh +4 -4
- package/src/api/apps.ts +96 -96
- package/src/api/event-workflow-action-definition.ts +7 -7
- package/src/api/event-workflow-template-definition.ts +22 -22
- package/src/api/event-workflow-templates.ts +28 -28
- package/src/apps/create-app/create.ts +74 -73
- package/src/apps/create-app/setup-template.ts +37 -37
- package/src/apps/deploy-app/actions-deployer.ts +140 -140
- package/src/apps/deploy-app/app-deployer.ts +105 -105
- package/src/apps/deploy-app/app-template-parsers.ts +43 -43
- package/src/apps/deploy-app/deploy.ts +65 -65
- package/src/apps/install-app/app-installer.ts +125 -125
- package/src/apps/upgrade-app/app-upgrader.ts +131 -131
- package/src/auth/auth.ts +9 -9
- package/src/auth/login.ts +155 -155
- package/src/cli.ts +540 -496
- package/src/colors/color-loader.ts +112 -112
- package/src/colors/colors.csv +866 -866
- package/src/common.ts +4 -4
- package/src/config/config.ts +74 -74
- package/src/config/configCommands.ts +37 -37
- package/src/interfaces.ts +200 -200
- package/src/loader-process/loader-process.ts +151 -151
- package/src/projects/interfaces.ts +72 -72
- package/src/projects/project-exporter.ts +224 -224
- package/src/projects/project-uploader.ts +130 -130
- package/src/types/allUploader.ts +28 -28
- package/src/types/csv-parser.ts +58 -58
- package/src/types/interfaces.ts +58 -58
- package/src/types/option-set-hierarchy-exporter.ts +124 -124
- package/src/types/option-set-hierarchy-parser.ts +168 -168
- package/src/types/option-set-hierarchy-uploader.ts +121 -121
- package/src/types/option-set-merger.ts +123 -122
- package/src/types/option-set-parser.ts +165 -59
- package/src/types/option-set-uploader.ts +107 -107
- package/src/types/parse-types.ts +226 -226
- package/src/types/rule-set-uploader.ts +186 -186
- package/src/types/type-property-policy-uploader.ts +191 -191
- package/src/types/types-extractor.ts +368 -368
- package/src/types/types-properties-merger.ts +89 -89
- package/src/types/types-uploader.ts +271 -271
- package/src/types/usage-info-uploader.ts +138 -138
- package/src/users/user-exporter.ts +52 -0
- package/src/users/user-uploader.ts +58 -0
- package/src/workflow-template-definitions/workflow-template-definition-commands.ts +12 -12
- package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +184 -184
- package/src/workflow-templates/local-workflow-template-deployer.ts +125 -125
- package/src/workflow-templates/workflow-template-commands.ts +59 -59
- package/src/workflow-templates/workflow-template-deployer.ts +29 -29
- package/templates/docker_deploy.bat +1 -0
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/javascript/app.yml +52 -52
- package/templates/javascript/package.json +23 -23
- package/templates/typescript/Dockerfile +15 -14
- package/templates/typescript/README.md +10 -10
- package/templates/typescript/app.yml +50 -54
- package/templates/typescript/package-lock.json +14 -14
- package/templates/typescript/package.json +54 -52
- package/templates/typescript/src/actions/logItem.ts +26 -0
- package/templates/typescript/src/framework/action-dispatcher.ts +86 -0
- package/templates/typescript/src/framework/app-config.ts +27 -0
- package/templates/typescript/src/framework/handler.ts +11 -0
- package/templates/typescript/src/framework/index.ts +3 -0
- package/templates/typescript/src/framework/interfaces.ts +32 -0
- package/templates/typescript/src/framework/logger.ts +21 -0
- package/templates/typescript/{actions → src/framework}/mock-server.ts +7 -0
- package/templates/typescript/tsconfig.json +28 -27
- package/tsconfig.json +31 -30
- package/templates/typescript/actions/handler.ts +0 -62
- package/templates/typescript/actions/utils/logger.ts +0 -15
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { getOptionSets, getTypes, reduceData } from './types-extractor';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { getSeparatorByPlatform } from '../common';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
const yaml = require('js-yaml');
|
|
7
|
-
export async function MergeTypeProperties(args) {
|
|
8
|
-
try {
|
|
9
|
-
if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
|
|
10
|
-
throw new Error('File name must be included along with a type path.');
|
|
11
|
-
}
|
|
12
|
-
console.log('%s Importing local file', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
13
|
-
const fileLocation = args[3];
|
|
14
|
-
console.log('Using File: ', fileLocation);
|
|
15
|
-
const typePaths = args.slice(4);
|
|
16
|
-
console.log('Using TypePaths: ', typePaths);
|
|
17
|
-
await mergeTypeProperties(fileLocation, typePaths);
|
|
18
|
-
console.log('%s Merged', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
|
|
25
|
-
}
|
|
26
|
-
function loadTypeProperties(fileLocation) {
|
|
27
|
-
const TARGET_DIR = process.cwd();
|
|
28
|
-
try {
|
|
29
|
-
const separator = getSeparatorByPlatform();
|
|
30
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
31
|
-
console.log('Getting file from path: ', fullPath);
|
|
32
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
|
|
33
|
-
return doc.typeProperties;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function mergeTypeProperties(fileLocation, typePaths) {
|
|
40
|
-
const uploadedTypeProperties = loadTypeProperties(fileLocation);
|
|
41
|
-
await authUser();
|
|
42
|
-
const data = {
|
|
43
|
-
types: await getTypes(),
|
|
44
|
-
optionSets: await getOptionSets(),
|
|
45
|
-
optionSetHierarchies: [],
|
|
46
|
-
ruleSets: [],
|
|
47
|
-
ruleSetLinks: [],
|
|
48
|
-
usageInfo: [],
|
|
49
|
-
typePropertyPolicies: [],
|
|
50
|
-
typePropertyPolicyLinks: [],
|
|
51
|
-
};
|
|
52
|
-
const reducedData = await reduceData(data);
|
|
53
|
-
for (const typePath of typePaths) {
|
|
54
|
-
const foundType = reducedData.reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
|
|
55
|
-
if (!foundType) {
|
|
56
|
-
console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
|
|
57
|
-
}
|
|
58
|
-
mergeType(foundType, uploadedTypeProperties);
|
|
59
|
-
}
|
|
60
|
-
saveData({ types: reducedData.reducedTypes });
|
|
61
|
-
}
|
|
62
|
-
function mergeType(reducedType, typePropertiesToAdd) {
|
|
63
|
-
for (const typeProperty of typePropertiesToAdd) {
|
|
64
|
-
const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug);
|
|
65
|
-
if (!found) {
|
|
66
|
-
reducedType.typeProperties.push(typeProperty);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function saveData(data) {
|
|
71
|
-
const yamlStr = yaml.dump(data);
|
|
72
|
-
const CURRENT_DIR = process.cwd();
|
|
73
|
-
const separator = getSeparatorByPlatform();
|
|
74
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'merged_types.yml', yamlStr, 'utf8');
|
|
75
|
-
}
|
|
1
|
+
import { getOptionSets, getTypes, reduceData } from './types-extractor';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getSeparatorByPlatform } from '../common';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
export async function MergeTypeProperties(args) {
|
|
8
|
+
try {
|
|
9
|
+
if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
|
|
10
|
+
throw new Error('File name must be included along with a type path.');
|
|
11
|
+
}
|
|
12
|
+
console.log('%s Importing local file', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
13
|
+
const fileLocation = args[3];
|
|
14
|
+
console.log('Using File: ', fileLocation);
|
|
15
|
+
const typePaths = args.slice(4);
|
|
16
|
+
console.log('Using TypePaths: ', typePaths);
|
|
17
|
+
await mergeTypeProperties(fileLocation, typePaths);
|
|
18
|
+
console.log('%s Merged', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
|
|
25
|
+
}
|
|
26
|
+
function loadTypeProperties(fileLocation) {
|
|
27
|
+
const TARGET_DIR = process.cwd();
|
|
28
|
+
try {
|
|
29
|
+
const separator = getSeparatorByPlatform();
|
|
30
|
+
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
31
|
+
console.log('Getting file from path: ', fullPath);
|
|
32
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
|
|
33
|
+
return doc.typeProperties;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function mergeTypeProperties(fileLocation, typePaths) {
|
|
40
|
+
const uploadedTypeProperties = loadTypeProperties(fileLocation);
|
|
41
|
+
await authUser();
|
|
42
|
+
const data = {
|
|
43
|
+
types: await getTypes(),
|
|
44
|
+
optionSets: await getOptionSets(),
|
|
45
|
+
optionSetHierarchies: [],
|
|
46
|
+
ruleSets: [],
|
|
47
|
+
ruleSetLinks: [],
|
|
48
|
+
usageInfo: [],
|
|
49
|
+
typePropertyPolicies: [],
|
|
50
|
+
typePropertyPolicyLinks: [],
|
|
51
|
+
};
|
|
52
|
+
const reducedData = await reduceData(data);
|
|
53
|
+
for (const typePath of typePaths) {
|
|
54
|
+
const foundType = reducedData.reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
|
|
55
|
+
if (!foundType) {
|
|
56
|
+
console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
|
|
57
|
+
}
|
|
58
|
+
mergeType(foundType, uploadedTypeProperties);
|
|
59
|
+
}
|
|
60
|
+
saveData({ types: reducedData.reducedTypes });
|
|
61
|
+
}
|
|
62
|
+
function mergeType(reducedType, typePropertiesToAdd) {
|
|
63
|
+
for (const typeProperty of typePropertiesToAdd) {
|
|
64
|
+
const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug);
|
|
65
|
+
if (!found) {
|
|
66
|
+
reducedType.typeProperties.push(typeProperty);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function saveData(data) {
|
|
71
|
+
const yamlStr = yaml.dump(data);
|
|
72
|
+
const CURRENT_DIR = process.cwd();
|
|
73
|
+
const separator = getSeparatorByPlatform();
|
|
74
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'merged_types.yml', yamlStr, 'utf8');
|
|
75
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function uploadTypes(): Promise<void>;
|
|
1
|
+
export declare function uploadTypes(): Promise<void>;
|
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
import { Entities, Request } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import * as _ from 'lodash';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
|
-
export async function uploadTypes() {
|
|
9
|
-
try {
|
|
10
|
-
const userConfig = await authUser();
|
|
11
|
-
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
12
|
-
console.log('%s Uploading', chalk.yellow.bold('TYPES'));
|
|
13
|
-
await uploadReducedTypes();
|
|
14
|
-
console.log('%s Uploaded', chalk.yellow.bold('TYPES'));
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
21
|
-
}
|
|
22
|
-
function loadReducedTypes() {
|
|
23
|
-
const TARGET_DIR = process.cwd();
|
|
24
|
-
try {
|
|
25
|
-
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
26
|
-
const types = [];
|
|
27
|
-
for (const file of files) {
|
|
28
|
-
types.push(...yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
29
|
-
}
|
|
30
|
-
return types;
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function uploadReducedTypes() {
|
|
37
|
-
const types = loadReducedTypes();
|
|
38
|
-
const currentTypesWithoutProperties = await new Entities().get({
|
|
39
|
-
entityName: 'type',
|
|
40
|
-
});
|
|
41
|
-
const currentTypes = [];
|
|
42
|
-
for (const currentTypeWithoutProperties of currentTypesWithoutProperties) {
|
|
43
|
-
const typeWithProperties = await new Entities().get({
|
|
44
|
-
entityName: 'type',
|
|
45
|
-
id: currentTypeWithoutProperties.id,
|
|
46
|
-
relations: ['typeProperties'],
|
|
47
|
-
});
|
|
48
|
-
currentTypes.push(typeWithProperties);
|
|
49
|
-
}
|
|
50
|
-
const currentTypesBySlug = {};
|
|
51
|
-
for (const currentType of currentTypes) {
|
|
52
|
-
currentTypesBySlug[currentType.slug] = currentType;
|
|
53
|
-
}
|
|
54
|
-
const newTypesBySlug = {};
|
|
55
|
-
for (const type of types) {
|
|
56
|
-
newTypesBySlug[type.slug] = type;
|
|
57
|
-
}
|
|
58
|
-
for (const type of types) {
|
|
59
|
-
try {
|
|
60
|
-
const found = currentTypesBySlug[type.slug];
|
|
61
|
-
if (!found) {
|
|
62
|
-
if (!type.typePath.includes(':')) {
|
|
63
|
-
console.log('Cannot create a base type. Skipping: ', type.slug);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
console.log('Creating Type: ', type.slug);
|
|
67
|
-
const createdType = await new Entities().create({
|
|
68
|
-
entityName: 'type',
|
|
69
|
-
object: {
|
|
70
|
-
slug: type.slug,
|
|
71
|
-
label: type.label,
|
|
72
|
-
typePath: type.typePath,
|
|
73
|
-
isArchived: type.isArchived,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
await uploadReducedTypeProperties(createdType, [], type.typeProperties);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
console.log('Updating Type: ', type.slug);
|
|
80
|
-
const updatedType = await new Entities().update({
|
|
81
|
-
entityName: 'type',
|
|
82
|
-
id: found.id,
|
|
83
|
-
object: {
|
|
84
|
-
slug: type.slug,
|
|
85
|
-
label: type.label,
|
|
86
|
-
typePath: type.typePath,
|
|
87
|
-
isArchived: type.isArchived,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
await uploadReducedTypeProperties(updatedType, found.typeProperties, type.typeProperties);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
console.log('Error Uploading Types: ', err);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (const currentType of currentTypes) {
|
|
98
|
-
try {
|
|
99
|
-
const found = newTypesBySlug[currentType.slug];
|
|
100
|
-
if (!found) {
|
|
101
|
-
console.log('Deleting Type: ', currentType.slug);
|
|
102
|
-
await new Entities().delete({
|
|
103
|
-
entityName: 'type',
|
|
104
|
-
id: currentType.id,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
throw new Error(`Error Deleting Types: ${err}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes) {
|
|
114
|
-
const currentPropertyTypeBySlug = {};
|
|
115
|
-
for (const currentPropertyType of currentPropertyTypes) {
|
|
116
|
-
currentPropertyTypeBySlug[currentPropertyType.slug] = currentPropertyType;
|
|
117
|
-
}
|
|
118
|
-
const newPropertyTypesBySlug = {};
|
|
119
|
-
for (const newPropertyType of newPropertyTypes) {
|
|
120
|
-
newPropertyTypesBySlug[newPropertyType.slug] = newPropertyType;
|
|
121
|
-
}
|
|
122
|
-
const optionSets = await new Entities().get({
|
|
123
|
-
entityName: 'type-property-option-set',
|
|
124
|
-
});
|
|
125
|
-
const optionSetIdByName = {};
|
|
126
|
-
for (const optionSet of optionSets) {
|
|
127
|
-
optionSetIdByName[optionSet.name] = optionSet.id;
|
|
128
|
-
}
|
|
129
|
-
for (const newPropertyType of newPropertyTypes) {
|
|
130
|
-
try {
|
|
131
|
-
const found = currentPropertyTypeBySlug[newPropertyType.slug];
|
|
132
|
-
if (!found && !newPropertyType.inherited) {
|
|
133
|
-
console.log('Creating Type-Property: ', newPropertyType.slug);
|
|
134
|
-
await Request.request(`/types/${type.id}/type-properties`, {
|
|
135
|
-
method: 'POST',
|
|
136
|
-
body: JSON.stringify({
|
|
137
|
-
isArchived: newPropertyType.isArchived,
|
|
138
|
-
propertyType: newPropertyType.propertyType,
|
|
139
|
-
slug: newPropertyType.slug,
|
|
140
|
-
label: newPropertyType.label,
|
|
141
|
-
editable: newPropertyType.editable,
|
|
142
|
-
searchable: newPropertyType.searchable,
|
|
143
|
-
core: newPropertyType.core,
|
|
144
|
-
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
145
|
-
formula: newPropertyType.formula,
|
|
146
|
-
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
147
|
-
defaultValue: newPropertyType.defaultValue,
|
|
148
|
-
propertyLevel: newPropertyType.propertyLevel,
|
|
149
|
-
formulaFunction: newPropertyType.formulaFunction,
|
|
150
|
-
validationFunction: newPropertyType.validationFunction,
|
|
151
|
-
}),
|
|
152
|
-
headers: {
|
|
153
|
-
Accept: 'application/json',
|
|
154
|
-
'Content-Type': 'application/json',
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
else if (found && !newPropertyType.inherited && !typePropertiesEqual(found, newPropertyType, optionSetIdByName)) {
|
|
159
|
-
console.log('Updating Type-Property: ', newPropertyType.slug);
|
|
160
|
-
await new Entities().update({
|
|
161
|
-
entityName: 'type-property',
|
|
162
|
-
id: found.id,
|
|
163
|
-
object: {
|
|
164
|
-
isArchived: newPropertyType.isArchived,
|
|
165
|
-
propertyType: newPropertyType.propertyType,
|
|
166
|
-
slug: newPropertyType.slug,
|
|
167
|
-
label: newPropertyType.label,
|
|
168
|
-
editable: newPropertyType.editable,
|
|
169
|
-
searchable: newPropertyType.searchable,
|
|
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
|
-
formulaFunction: newPropertyType.formulaFunction,
|
|
177
|
-
validationFunction: newPropertyType.validationFunction,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
console.log('Error Creating Properties: ', err);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
for (const currentPropertyType of currentPropertyTypes) {
|
|
187
|
-
try {
|
|
188
|
-
const found = newPropertyTypesBySlug[currentPropertyType.slug];
|
|
189
|
-
if (!found && !currentPropertyType.inherited) {
|
|
190
|
-
console.log('Deleting Type-Property: ', currentPropertyType.slug);
|
|
191
|
-
await Request.request(`/types/${type.id}/type-properties/${currentPropertyType.id}`, {
|
|
192
|
-
method: 'DELETE',
|
|
193
|
-
headers: {
|
|
194
|
-
Accept: 'application/json',
|
|
195
|
-
'Content-Type': 'application/json',
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
throw new Error(`Error Deleting Properties: ${err}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
206
|
-
const reducedProperty1 = {
|
|
207
|
-
isArchived: typeProperty1.isArchived,
|
|
208
|
-
propertyType: typeProperty1.propertyType,
|
|
209
|
-
slug: typeProperty1.slug,
|
|
210
|
-
label: typeProperty1.label,
|
|
211
|
-
editable: typeProperty1.editable,
|
|
212
|
-
searchable: typeProperty1.searchable,
|
|
213
|
-
core: typeProperty1.core,
|
|
214
|
-
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
215
|
-
formula: typeProperty1.formula,
|
|
216
|
-
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
217
|
-
defaultValue: typeProperty1.defaultValue,
|
|
218
|
-
propertyLevel: typeProperty1.propertyLevel,
|
|
219
|
-
formulaFunction: typeProperty1.formulaFunction,
|
|
220
|
-
validationFunction: typeProperty1.validationFunction,
|
|
221
|
-
};
|
|
222
|
-
const reducedProperty2 = {
|
|
223
|
-
isArchived: typeProperty2.isArchived,
|
|
224
|
-
propertyType: typeProperty2.propertyType,
|
|
225
|
-
slug: typeProperty2.slug,
|
|
226
|
-
label: typeProperty2.label,
|
|
227
|
-
editable: typeProperty2.editable,
|
|
228
|
-
searchable: typeProperty2.searchable,
|
|
229
|
-
core: typeProperty2.core,
|
|
230
|
-
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
231
|
-
formula: typeProperty2.formula,
|
|
232
|
-
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
233
|
-
defaultValue: typeProperty2.defaultValue,
|
|
234
|
-
propertyLevel: typeProperty2.propertyLevel,
|
|
235
|
-
formulaFunction: typeProperty2.formulaFunction,
|
|
236
|
-
validationFunction: typeProperty2.validationFunction,
|
|
237
|
-
};
|
|
238
|
-
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
239
|
-
}
|
|
1
|
+
import { Entities, Request } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import * as _ from 'lodash';
|
|
7
|
+
import yaml from 'js-yaml';
|
|
8
|
+
export async function uploadTypes() {
|
|
9
|
+
try {
|
|
10
|
+
const userConfig = await authUser();
|
|
11
|
+
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
12
|
+
console.log('%s Uploading', chalk.yellow.bold('TYPES'));
|
|
13
|
+
await uploadReducedTypes();
|
|
14
|
+
console.log('%s Uploaded', chalk.yellow.bold('TYPES'));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
console.log('%s Types Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
21
|
+
}
|
|
22
|
+
function loadReducedTypes() {
|
|
23
|
+
const TARGET_DIR = process.cwd();
|
|
24
|
+
try {
|
|
25
|
+
const files = fs.readdirSync(path.join(TARGET_DIR, 'types'));
|
|
26
|
+
const types = [];
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
types.push(...yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'types', file), 'utf8')));
|
|
29
|
+
}
|
|
30
|
+
return types;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function uploadReducedTypes() {
|
|
37
|
+
const types = loadReducedTypes();
|
|
38
|
+
const currentTypesWithoutProperties = await new Entities().get({
|
|
39
|
+
entityName: 'type',
|
|
40
|
+
});
|
|
41
|
+
const currentTypes = [];
|
|
42
|
+
for (const currentTypeWithoutProperties of currentTypesWithoutProperties) {
|
|
43
|
+
const typeWithProperties = await new Entities().get({
|
|
44
|
+
entityName: 'type',
|
|
45
|
+
id: currentTypeWithoutProperties.id,
|
|
46
|
+
relations: ['typeProperties'],
|
|
47
|
+
});
|
|
48
|
+
currentTypes.push(typeWithProperties);
|
|
49
|
+
}
|
|
50
|
+
const currentTypesBySlug = {};
|
|
51
|
+
for (const currentType of currentTypes) {
|
|
52
|
+
currentTypesBySlug[currentType.slug] = currentType;
|
|
53
|
+
}
|
|
54
|
+
const newTypesBySlug = {};
|
|
55
|
+
for (const type of types) {
|
|
56
|
+
newTypesBySlug[type.slug] = type;
|
|
57
|
+
}
|
|
58
|
+
for (const type of types) {
|
|
59
|
+
try {
|
|
60
|
+
const found = currentTypesBySlug[type.slug];
|
|
61
|
+
if (!found) {
|
|
62
|
+
if (!type.typePath.includes(':')) {
|
|
63
|
+
console.log('Cannot create a base type. Skipping: ', type.slug);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
console.log('Creating Type: ', type.slug);
|
|
67
|
+
const createdType = await new Entities().create({
|
|
68
|
+
entityName: 'type',
|
|
69
|
+
object: {
|
|
70
|
+
slug: type.slug,
|
|
71
|
+
label: type.label,
|
|
72
|
+
typePath: type.typePath,
|
|
73
|
+
isArchived: type.isArchived,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
await uploadReducedTypeProperties(createdType, [], type.typeProperties);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.log('Updating Type: ', type.slug);
|
|
80
|
+
const updatedType = await new Entities().update({
|
|
81
|
+
entityName: 'type',
|
|
82
|
+
id: found.id,
|
|
83
|
+
object: {
|
|
84
|
+
slug: type.slug,
|
|
85
|
+
label: type.label,
|
|
86
|
+
typePath: type.typePath,
|
|
87
|
+
isArchived: type.isArchived,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
await uploadReducedTypeProperties(updatedType, found.typeProperties, type.typeProperties);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.log('Error Uploading Types: ', err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const currentType of currentTypes) {
|
|
98
|
+
try {
|
|
99
|
+
const found = newTypesBySlug[currentType.slug];
|
|
100
|
+
if (!found) {
|
|
101
|
+
console.log('Deleting Type: ', currentType.slug);
|
|
102
|
+
await new Entities().delete({
|
|
103
|
+
entityName: 'type',
|
|
104
|
+
id: currentType.id,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
throw new Error(`Error Deleting Types: ${err}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function uploadReducedTypeProperties(type, currentPropertyTypes, newPropertyTypes) {
|
|
114
|
+
const currentPropertyTypeBySlug = {};
|
|
115
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
116
|
+
currentPropertyTypeBySlug[currentPropertyType.slug] = currentPropertyType;
|
|
117
|
+
}
|
|
118
|
+
const newPropertyTypesBySlug = {};
|
|
119
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
120
|
+
newPropertyTypesBySlug[newPropertyType.slug] = newPropertyType;
|
|
121
|
+
}
|
|
122
|
+
const optionSets = await new Entities().get({
|
|
123
|
+
entityName: 'type-property-option-set',
|
|
124
|
+
});
|
|
125
|
+
const optionSetIdByName = {};
|
|
126
|
+
for (const optionSet of optionSets) {
|
|
127
|
+
optionSetIdByName[optionSet.name] = optionSet.id;
|
|
128
|
+
}
|
|
129
|
+
for (const newPropertyType of newPropertyTypes) {
|
|
130
|
+
try {
|
|
131
|
+
const found = currentPropertyTypeBySlug[newPropertyType.slug];
|
|
132
|
+
if (!found && !newPropertyType.inherited) {
|
|
133
|
+
console.log('Creating Type-Property: ', newPropertyType.slug);
|
|
134
|
+
await Request.request(`/types/${type.id}/type-properties`, {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
isArchived: newPropertyType.isArchived,
|
|
138
|
+
propertyType: newPropertyType.propertyType,
|
|
139
|
+
slug: newPropertyType.slug,
|
|
140
|
+
label: newPropertyType.label,
|
|
141
|
+
editable: newPropertyType.editable,
|
|
142
|
+
searchable: newPropertyType.searchable,
|
|
143
|
+
core: newPropertyType.core,
|
|
144
|
+
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
145
|
+
formula: newPropertyType.formula,
|
|
146
|
+
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
147
|
+
defaultValue: newPropertyType.defaultValue,
|
|
148
|
+
propertyLevel: newPropertyType.propertyLevel,
|
|
149
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
150
|
+
validationFunction: newPropertyType.validationFunction,
|
|
151
|
+
}),
|
|
152
|
+
headers: {
|
|
153
|
+
Accept: 'application/json',
|
|
154
|
+
'Content-Type': 'application/json',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else if (found && !newPropertyType.inherited && !typePropertiesEqual(found, newPropertyType, optionSetIdByName)) {
|
|
159
|
+
console.log('Updating Type-Property: ', newPropertyType.slug);
|
|
160
|
+
await new Entities().update({
|
|
161
|
+
entityName: 'type-property',
|
|
162
|
+
id: found.id,
|
|
163
|
+
object: {
|
|
164
|
+
isArchived: newPropertyType.isArchived,
|
|
165
|
+
propertyType: newPropertyType.propertyType,
|
|
166
|
+
slug: newPropertyType.slug,
|
|
167
|
+
label: newPropertyType.label,
|
|
168
|
+
editable: newPropertyType.editable,
|
|
169
|
+
searchable: newPropertyType.searchable,
|
|
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
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
177
|
+
validationFunction: newPropertyType.validationFunction,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
console.log('Error Creating Properties: ', err);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const currentPropertyType of currentPropertyTypes) {
|
|
187
|
+
try {
|
|
188
|
+
const found = newPropertyTypesBySlug[currentPropertyType.slug];
|
|
189
|
+
if (!found && !currentPropertyType.inherited) {
|
|
190
|
+
console.log('Deleting Type-Property: ', currentPropertyType.slug);
|
|
191
|
+
await Request.request(`/types/${type.id}/type-properties/${currentPropertyType.id}`, {
|
|
192
|
+
method: 'DELETE',
|
|
193
|
+
headers: {
|
|
194
|
+
Accept: 'application/json',
|
|
195
|
+
'Content-Type': 'application/json',
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
throw new Error(`Error Deleting Properties: ${err}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
206
|
+
const reducedProperty1 = {
|
|
207
|
+
isArchived: typeProperty1.isArchived,
|
|
208
|
+
propertyType: typeProperty1.propertyType,
|
|
209
|
+
slug: typeProperty1.slug,
|
|
210
|
+
label: typeProperty1.label,
|
|
211
|
+
editable: typeProperty1.editable,
|
|
212
|
+
searchable: typeProperty1.searchable,
|
|
213
|
+
core: typeProperty1.core,
|
|
214
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
215
|
+
formula: typeProperty1.formula,
|
|
216
|
+
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
217
|
+
defaultValue: typeProperty1.defaultValue,
|
|
218
|
+
propertyLevel: typeProperty1.propertyLevel,
|
|
219
|
+
formulaFunction: typeProperty1.formulaFunction,
|
|
220
|
+
validationFunction: typeProperty1.validationFunction,
|
|
221
|
+
};
|
|
222
|
+
const reducedProperty2 = {
|
|
223
|
+
isArchived: typeProperty2.isArchived,
|
|
224
|
+
propertyType: typeProperty2.propertyType,
|
|
225
|
+
slug: typeProperty2.slug,
|
|
226
|
+
label: typeProperty2.label,
|
|
227
|
+
editable: typeProperty2.editable,
|
|
228
|
+
searchable: typeProperty2.searchable,
|
|
229
|
+
core: typeProperty2.core,
|
|
230
|
+
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
231
|
+
formula: typeProperty2.formula,
|
|
232
|
+
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
233
|
+
defaultValue: typeProperty2.defaultValue,
|
|
234
|
+
propertyLevel: typeProperty2.propertyLevel,
|
|
235
|
+
formulaFunction: typeProperty2.formulaFunction,
|
|
236
|
+
validationFunction: typeProperty2.validationFunction,
|
|
237
|
+
};
|
|
238
|
+
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
239
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function uploadUsageInfo(args: any): Promise<void>;
|
|
1
|
+
export declare function uploadUsageInfo(args: any): Promise<void>;
|