@contrail/cli 3.5.3-alpha.73bd011 → 3.5.3-alpha.b5668f4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/commands/workflow-templates/export.d.ts +3 -1
- package/dist/commands/workflow-templates/export.js +99 -28
- package/dist/helpers/workflow-templates/helper.d.ts +1 -0
- package/dist/helpers/workflow-templates/helper.js +32 -9
- package/node_modules/@contrail/org-config-migration/.github/workflows/publish-to-npm.yml +117 -0
- package/node_modules/@contrail/org-config-migration/.husky/pre-commit +0 -0
- package/node_modules/@contrail/org-config-migration/lib/index.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/index.js +19 -19
- package/node_modules/@contrail/org-config-migration/lib/interfaces.d.ts +87 -97
- package/node_modules/@contrail/org-config-migration/lib/interfaces.js +2 -2
- package/node_modules/@contrail/org-config-migration/lib/services/index.d.ts +1 -1
- package/node_modules/@contrail/org-config-migration/lib/services/index.js +17 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.d.ts +12 -17
- package/node_modules/@contrail/org-config-migration/lib/services/types.js +115 -155
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportAll.js +34 -40
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSet.js +20 -20
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportOptionSetHierarchies.js +16 -47
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportOverrides.js +8 -8
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportRuleSets.js +14 -39
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePolicies.js +44 -56
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.d.ts +2 -3
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypePropertyPolicies.js +44 -71
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportTypes.js +85 -85
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/importAll.js +386 -451
- package/node_modules/@contrail/org-config-migration/lib/types/index.d.ts +8 -9
- package/node_modules/@contrail/org-config-migration/lib/types/index.js +24 -25
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.d.ts +3 -3
- package/node_modules/@contrail/org-config-migration/lib/types/parseOptionSetHierarchy.js +210 -210
- package/node_modules/@contrail/org-config-migration/lib/users/export.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/export.js +40 -40
- package/node_modules/@contrail/org-config-migration/lib/users/import.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/import.js +41 -41
- package/node_modules/@contrail/org-config-migration/lib/users/index.d.ts +2 -2
- package/node_modules/@contrail/org-config-migration/lib/users/index.js +18 -18
- package/node_modules/@contrail/org-config-migration/package.json +1 -1
- package/oclif.manifest.json +15 -5
- package/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/lib/types/exportUsageInfo.js +0 -39
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export * from './exportAll';
|
|
2
|
-
export * from './exportOptionSet';
|
|
3
|
-
export * from './exportOptionSetHierarchies';
|
|
4
|
-
export * from './exportRuleSets';
|
|
5
|
-
export * from './exportTypePolicies';
|
|
6
|
-
export * from './exportTypePropertyPolicies';
|
|
7
|
-
export * from './exportTypes';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './parseOptionSetHierarchy';
|
|
1
|
+
export * from './exportAll';
|
|
2
|
+
export * from './exportOptionSet';
|
|
3
|
+
export * from './exportOptionSetHierarchies';
|
|
4
|
+
export * from './exportRuleSets';
|
|
5
|
+
export * from './exportTypePolicies';
|
|
6
|
+
export * from './exportTypePropertyPolicies';
|
|
7
|
+
export * from './exportTypes';
|
|
8
|
+
export * from './parseOptionSetHierarchy';
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./exportAll"), exports);
|
|
18
|
-
__exportStar(require("./exportOptionSet"), exports);
|
|
19
|
-
__exportStar(require("./exportOptionSetHierarchies"), exports);
|
|
20
|
-
__exportStar(require("./exportRuleSets"), exports);
|
|
21
|
-
__exportStar(require("./exportTypePolicies"), exports);
|
|
22
|
-
__exportStar(require("./exportTypePropertyPolicies"), exports);
|
|
23
|
-
__exportStar(require("./exportTypes"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./parseOptionSetHierarchy"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./exportAll"), exports);
|
|
18
|
+
__exportStar(require("./exportOptionSet"), exports);
|
|
19
|
+
__exportStar(require("./exportOptionSetHierarchies"), exports);
|
|
20
|
+
__exportStar(require("./exportRuleSets"), exports);
|
|
21
|
+
__exportStar(require("./exportTypePolicies"), exports);
|
|
22
|
+
__exportStar(require("./exportTypePropertyPolicies"), exports);
|
|
23
|
+
__exportStar(require("./exportTypes"), exports);
|
|
24
|
+
__exportStar(require("./parseOptionSetHierarchy"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function parseOptionSetHierarchies(uploadedOptionHierarchyData: any): Promise<any>;
|
|
2
|
-
export declare function parseOptionSetHierarchiesValuesToKeys(uploadedOptionHierarchyData: any): Promise<any>;
|
|
3
|
-
export declare function convertHierarchyToCSV(optionSetHierarchy: any): Promise<string>;
|
|
1
|
+
export declare function parseOptionSetHierarchies(uploadedOptionHierarchyData: any): Promise<any>;
|
|
2
|
+
export declare function parseOptionSetHierarchiesValuesToKeys(uploadedOptionHierarchyData: any): Promise<any>;
|
|
3
|
+
export declare function convertHierarchyToCSV(optionSetHierarchy: any): Promise<string>;
|
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.convertHierarchyToCSV = exports.parseOptionSetHierarchiesValuesToKeys = exports.parseOptionSetHierarchies = void 0;
|
|
36
|
-
const sdk_1 = require("@contrail/sdk");
|
|
37
|
-
const util_1 = require("@contrail/util");
|
|
38
|
-
const _ = __importStar(require("lodash"));
|
|
39
|
-
const json2csv_1 = require("json2csv");
|
|
40
|
-
function parseOptionSetHierarchies(uploadedOptionHierarchyData) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const optionSetHierarchy = {
|
|
43
|
-
hierarchy: [],
|
|
44
|
-
maxDepth: 0,
|
|
45
|
-
name: 'No Name',
|
|
46
|
-
options: [],
|
|
47
|
-
};
|
|
48
|
-
if (!(uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length)) {
|
|
49
|
-
return optionSetHierarchy;
|
|
50
|
-
}
|
|
51
|
-
const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
|
|
52
|
-
const currentOptionSets = yield new sdk_1.Entities().get({
|
|
53
|
-
entityName: 'type-property-option-set',
|
|
54
|
-
});
|
|
55
|
-
const currentOptionSetsByName = {};
|
|
56
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
57
|
-
currentOptionSetsByName[util_1.StringUtil.convertToCamelCase(currentOptionSet.name)] = currentOptionSet;
|
|
58
|
-
}
|
|
59
|
-
const optionSetIds = [];
|
|
60
|
-
const optionSetErrors = [];
|
|
61
|
-
for (const key of keysInOrder) {
|
|
62
|
-
if (currentOptionSetsByName[key]) {
|
|
63
|
-
optionSetIds.push(currentOptionSetsByName[key].id);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
if (key.startsWith('field')) {
|
|
67
|
-
optionSetErrors.push(`No OptionSet found for ${key} (try to remove empty columns if any)`);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
optionSetErrors.push(`No OptionSet found for ${key}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (optionSetErrors.length) {
|
|
75
|
-
throw new Error(JSON.stringify(optionSetErrors));
|
|
76
|
-
}
|
|
77
|
-
optionSetHierarchy.maxDepth = keysInOrder.length;
|
|
78
|
-
optionSetHierarchy.hierarchy = optionSetIds;
|
|
79
|
-
const hierarchy = {};
|
|
80
|
-
const duplicate = [];
|
|
81
|
-
for (const row of uploadedOptionHierarchyData) {
|
|
82
|
-
const key = Object.values(row).join('.');
|
|
83
|
-
const result = _.get(hierarchy, key);
|
|
84
|
-
if (!result) {
|
|
85
|
-
_.set(hierarchy, key, {});
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
duplicate.push(key);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (duplicate.length) {
|
|
92
|
-
const errors = duplicate.map((key) => `Duplicate keys found in the hierarchy: ${key}`);
|
|
93
|
-
throw new Error(JSON.stringify(errors));
|
|
94
|
-
}
|
|
95
|
-
optionSetHierarchy.options = buildOptionSetHierarchy(hierarchy, []);
|
|
96
|
-
return optionSetHierarchy;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
exports.parseOptionSetHierarchies = parseOptionSetHierarchies;
|
|
100
|
-
function parseOptionSetHierarchiesValuesToKeys(uploadedOptionHierarchyData) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
if (!(uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length)) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
|
|
107
|
-
const currentOptionSets = yield new sdk_1.Entities().get({
|
|
108
|
-
entityName: 'type-property-option-set',
|
|
109
|
-
});
|
|
110
|
-
for (const currentOptionSet of currentOptionSets) {
|
|
111
|
-
currentOptionSet.name = util_1.StringUtil.convertToCamelCase(currentOptionSet.name);
|
|
112
|
-
}
|
|
113
|
-
const mapOptionSet = filterAndMapOptionSetData(currentOptionSets, keysInOrder);
|
|
114
|
-
for (const row of uploadedOptionHierarchyData) {
|
|
115
|
-
for (const key in row) {
|
|
116
|
-
const value = mapOptionSet[key][row[key]];
|
|
117
|
-
row[key] = value;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const parser = new json2csv_1.Parser(keysInOrder);
|
|
121
|
-
const csv = parser.parse(uploadedOptionHierarchyData);
|
|
122
|
-
return csv;
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
console.error(e);
|
|
126
|
-
const errors = [`Error while parsing Option Set Hierarchy values to keys: ${e.message}`];
|
|
127
|
-
throw new Error(JSON.stringify(errors));
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
exports.parseOptionSetHierarchiesValuesToKeys = parseOptionSetHierarchiesValuesToKeys;
|
|
132
|
-
function buildOptionSetHierarchy(hierarchy, result) {
|
|
133
|
-
const keys = Object.keys(hierarchy);
|
|
134
|
-
if (!keys.length)
|
|
135
|
-
return result;
|
|
136
|
-
keys.forEach((k) => {
|
|
137
|
-
if (k.trim()) {
|
|
138
|
-
const optionSet = {
|
|
139
|
-
value: k,
|
|
140
|
-
options: [],
|
|
141
|
-
};
|
|
142
|
-
optionSet.options = buildOptionSetHierarchy(hierarchy[k], optionSet.options);
|
|
143
|
-
if (!optionSet.options.length) {
|
|
144
|
-
delete optionSet.options;
|
|
145
|
-
}
|
|
146
|
-
result.push(optionSet);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
function filterAndMapOptionSetData(optionSets, headersMap) {
|
|
152
|
-
console.log(`Headers from CSV: ${headersMap}`);
|
|
153
|
-
console.log(`Option sets in system: ${optionSets.map((value) => value.name)}`);
|
|
154
|
-
const requiredOptionSets = optionSets.filter((x) => headersMap.includes(x.name));
|
|
155
|
-
if (requiredOptionSets.length !== headersMap.length) {
|
|
156
|
-
throw new Error('Headers from csv not matching with Option Set Hierarchy names.');
|
|
157
|
-
}
|
|
158
|
-
const mapOptionSet = {};
|
|
159
|
-
requiredOptionSets.forEach((element) => {
|
|
160
|
-
const objOptionSet = {};
|
|
161
|
-
element.optionSet.forEach((data) => {
|
|
162
|
-
objOptionSet[data.display] = data.value;
|
|
163
|
-
});
|
|
164
|
-
mapOptionSet[element.name] = objOptionSet;
|
|
165
|
-
});
|
|
166
|
-
return mapOptionSet;
|
|
167
|
-
}
|
|
168
|
-
function convertHierarchyToCSV(optionSetHierarchy) {
|
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
const optionSetIds = optionSetHierarchy.hierarchy;
|
|
171
|
-
const optionSetsData = [];
|
|
172
|
-
try {
|
|
173
|
-
for (const optionSetId of optionSetIds) {
|
|
174
|
-
const currentOptionSet = yield new sdk_1.Entities().get({
|
|
175
|
-
entityName: 'type-property-option-set',
|
|
176
|
-
id: optionSetId,
|
|
177
|
-
});
|
|
178
|
-
currentOptionSet.name = util_1.StringUtil.convertToCamelCase(currentOptionSet.name);
|
|
179
|
-
optionSetsData.push(currentOptionSet);
|
|
180
|
-
}
|
|
181
|
-
const traverseHierarchy = (options, depth, row, result) => {
|
|
182
|
-
if (depth >= optionSetIds.length) {
|
|
183
|
-
result.push(row);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const optionSet = optionSetsData[depth];
|
|
187
|
-
for (const option of options) {
|
|
188
|
-
const newRow = Object.assign(Object.assign({}, row), { [optionSet.name]: option.value });
|
|
189
|
-
if (option.options) {
|
|
190
|
-
traverseHierarchy(option.options, depth + 1, newRow, result);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
result.push(newRow);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const result = [];
|
|
198
|
-
traverseHierarchy(optionSetHierarchy.options, 0, {}, result);
|
|
199
|
-
const keysInOrder = optionSetsData.map((os) => os.name);
|
|
200
|
-
const parser = new json2csv_1.Parser({ fields: keysInOrder, quote: '' });
|
|
201
|
-
const csv = parser.parse(result);
|
|
202
|
-
return csv;
|
|
203
|
-
}
|
|
204
|
-
catch (e) {
|
|
205
|
-
console.error(e);
|
|
206
|
-
throw new Error('Error converting Option set hierarchy to CSV: ' + e.message);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
exports.convertHierarchyToCSV = convertHierarchyToCSV;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.convertHierarchyToCSV = exports.parseOptionSetHierarchiesValuesToKeys = exports.parseOptionSetHierarchies = void 0;
|
|
36
|
+
const sdk_1 = require("@contrail/sdk");
|
|
37
|
+
const util_1 = require("@contrail/util");
|
|
38
|
+
const _ = __importStar(require("lodash"));
|
|
39
|
+
const json2csv_1 = require("json2csv");
|
|
40
|
+
function parseOptionSetHierarchies(uploadedOptionHierarchyData) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const optionSetHierarchy = {
|
|
43
|
+
hierarchy: [],
|
|
44
|
+
maxDepth: 0,
|
|
45
|
+
name: 'No Name',
|
|
46
|
+
options: [],
|
|
47
|
+
};
|
|
48
|
+
if (!(uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length)) {
|
|
49
|
+
return optionSetHierarchy;
|
|
50
|
+
}
|
|
51
|
+
const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
|
|
52
|
+
const currentOptionSets = yield new sdk_1.Entities().get({
|
|
53
|
+
entityName: 'type-property-option-set',
|
|
54
|
+
});
|
|
55
|
+
const currentOptionSetsByName = {};
|
|
56
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
57
|
+
currentOptionSetsByName[util_1.StringUtil.convertToCamelCase(currentOptionSet.name)] = currentOptionSet;
|
|
58
|
+
}
|
|
59
|
+
const optionSetIds = [];
|
|
60
|
+
const optionSetErrors = [];
|
|
61
|
+
for (const key of keysInOrder) {
|
|
62
|
+
if (currentOptionSetsByName[key]) {
|
|
63
|
+
optionSetIds.push(currentOptionSetsByName[key].id);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (key.startsWith('field')) {
|
|
67
|
+
optionSetErrors.push(`No OptionSet found for ${key} (try to remove empty columns if any)`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
optionSetErrors.push(`No OptionSet found for ${key}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (optionSetErrors.length) {
|
|
75
|
+
throw new Error(JSON.stringify(optionSetErrors));
|
|
76
|
+
}
|
|
77
|
+
optionSetHierarchy.maxDepth = keysInOrder.length;
|
|
78
|
+
optionSetHierarchy.hierarchy = optionSetIds;
|
|
79
|
+
const hierarchy = {};
|
|
80
|
+
const duplicate = [];
|
|
81
|
+
for (const row of uploadedOptionHierarchyData) {
|
|
82
|
+
const key = Object.values(row).join('.');
|
|
83
|
+
const result = _.get(hierarchy, key);
|
|
84
|
+
if (!result) {
|
|
85
|
+
_.set(hierarchy, key, {});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
duplicate.push(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (duplicate.length) {
|
|
92
|
+
const errors = duplicate.map((key) => `Duplicate keys found in the hierarchy: ${key}`);
|
|
93
|
+
throw new Error(JSON.stringify(errors));
|
|
94
|
+
}
|
|
95
|
+
optionSetHierarchy.options = buildOptionSetHierarchy(hierarchy, []);
|
|
96
|
+
return optionSetHierarchy;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.parseOptionSetHierarchies = parseOptionSetHierarchies;
|
|
100
|
+
function parseOptionSetHierarchiesValuesToKeys(uploadedOptionHierarchyData) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
if (!(uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length)) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
|
|
107
|
+
const currentOptionSets = yield new sdk_1.Entities().get({
|
|
108
|
+
entityName: 'type-property-option-set',
|
|
109
|
+
});
|
|
110
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
111
|
+
currentOptionSet.name = util_1.StringUtil.convertToCamelCase(currentOptionSet.name);
|
|
112
|
+
}
|
|
113
|
+
const mapOptionSet = filterAndMapOptionSetData(currentOptionSets, keysInOrder);
|
|
114
|
+
for (const row of uploadedOptionHierarchyData) {
|
|
115
|
+
for (const key in row) {
|
|
116
|
+
const value = mapOptionSet[key][row[key]];
|
|
117
|
+
row[key] = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const parser = new json2csv_1.Parser(keysInOrder);
|
|
121
|
+
const csv = parser.parse(uploadedOptionHierarchyData);
|
|
122
|
+
return csv;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error(e);
|
|
126
|
+
const errors = [`Error while parsing Option Set Hierarchy values to keys: ${e.message}`];
|
|
127
|
+
throw new Error(JSON.stringify(errors));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.parseOptionSetHierarchiesValuesToKeys = parseOptionSetHierarchiesValuesToKeys;
|
|
132
|
+
function buildOptionSetHierarchy(hierarchy, result) {
|
|
133
|
+
const keys = Object.keys(hierarchy);
|
|
134
|
+
if (!keys.length)
|
|
135
|
+
return result;
|
|
136
|
+
keys.forEach((k) => {
|
|
137
|
+
if (k.trim()) {
|
|
138
|
+
const optionSet = {
|
|
139
|
+
value: k,
|
|
140
|
+
options: [],
|
|
141
|
+
};
|
|
142
|
+
optionSet.options = buildOptionSetHierarchy(hierarchy[k], optionSet.options);
|
|
143
|
+
if (!optionSet.options.length) {
|
|
144
|
+
delete optionSet.options;
|
|
145
|
+
}
|
|
146
|
+
result.push(optionSet);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function filterAndMapOptionSetData(optionSets, headersMap) {
|
|
152
|
+
console.log(`Headers from CSV: ${headersMap}`);
|
|
153
|
+
console.log(`Option sets in system: ${optionSets.map((value) => value.name)}`);
|
|
154
|
+
const requiredOptionSets = optionSets.filter((x) => headersMap.includes(x.name));
|
|
155
|
+
if (requiredOptionSets.length !== headersMap.length) {
|
|
156
|
+
throw new Error('Headers from csv not matching with Option Set Hierarchy names.');
|
|
157
|
+
}
|
|
158
|
+
const mapOptionSet = {};
|
|
159
|
+
requiredOptionSets.forEach((element) => {
|
|
160
|
+
const objOptionSet = {};
|
|
161
|
+
element.optionSet.forEach((data) => {
|
|
162
|
+
objOptionSet[data.display] = data.value;
|
|
163
|
+
});
|
|
164
|
+
mapOptionSet[element.name] = objOptionSet;
|
|
165
|
+
});
|
|
166
|
+
return mapOptionSet;
|
|
167
|
+
}
|
|
168
|
+
function convertHierarchyToCSV(optionSetHierarchy) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const optionSetIds = optionSetHierarchy.hierarchy;
|
|
171
|
+
const optionSetsData = [];
|
|
172
|
+
try {
|
|
173
|
+
for (const optionSetId of optionSetIds) {
|
|
174
|
+
const currentOptionSet = yield new sdk_1.Entities().get({
|
|
175
|
+
entityName: 'type-property-option-set',
|
|
176
|
+
id: optionSetId,
|
|
177
|
+
});
|
|
178
|
+
currentOptionSet.name = util_1.StringUtil.convertToCamelCase(currentOptionSet.name);
|
|
179
|
+
optionSetsData.push(currentOptionSet);
|
|
180
|
+
}
|
|
181
|
+
const traverseHierarchy = (options, depth, row, result) => {
|
|
182
|
+
if (depth >= optionSetIds.length) {
|
|
183
|
+
result.push(row);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const optionSet = optionSetsData[depth];
|
|
187
|
+
for (const option of options) {
|
|
188
|
+
const newRow = Object.assign(Object.assign({}, row), { [optionSet.name]: option.value });
|
|
189
|
+
if (option.options) {
|
|
190
|
+
traverseHierarchy(option.options, depth + 1, newRow, result);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
result.push(newRow);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const result = [];
|
|
198
|
+
traverseHierarchy(optionSetHierarchy.options, 0, {}, result);
|
|
199
|
+
const keysInOrder = optionSetsData.map((os) => os.name);
|
|
200
|
+
const parser = new json2csv_1.Parser({ fields: keysInOrder, quote: '' });
|
|
201
|
+
const csv = parser.parse(result);
|
|
202
|
+
return csv;
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
console.error(e);
|
|
206
|
+
throw new Error('Error converting Option set hierarchy to CSV: ' + e.message);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
exports.convertHierarchyToCSV = convertHierarchyToCSV;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntitiesClient } from '@contrail/entity-types';
|
|
2
|
-
export declare function exportUsers(client: EntitiesClient): Promise<any[]>;
|
|
1
|
+
import { EntitiesClient } from '@contrail/entity-types';
|
|
2
|
+
export declare function exportUsers(client: EntitiesClient): Promise<any[]>;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.exportUsers = void 0;
|
|
24
|
-
const types_1 = require("../services/types");
|
|
25
|
-
function exportUsers(client) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const allUsersInOrg = yield (0, types_1.getOrgUsers)(client);
|
|
28
|
-
const filteredUsers = allUsersInOrg.filter((userInOrg) => {
|
|
29
|
-
const { isAppUser } = userInOrg.user;
|
|
30
|
-
return !isAppUser;
|
|
31
|
-
});
|
|
32
|
-
const transformedUsers = filteredUsers.map((userInOrg) => {
|
|
33
|
-
const _a = userInOrg.user, { id, updatedBy, createdBy } = _a, user = __rest(_a, ["id", "updatedBy", "createdBy"]);
|
|
34
|
-
return Object.assign({ role: userInOrg.role }, user);
|
|
35
|
-
});
|
|
36
|
-
const sortedUsers = transformedUsers.sort((one, two) => (one.email < two.email ? -1 : 1));
|
|
37
|
-
return sortedUsers;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
exports.exportUsers = exportUsers;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.exportUsers = void 0;
|
|
24
|
+
const types_1 = require("../services/types");
|
|
25
|
+
function exportUsers(client) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const allUsersInOrg = yield (0, types_1.getOrgUsers)(client);
|
|
28
|
+
const filteredUsers = allUsersInOrg.filter((userInOrg) => {
|
|
29
|
+
const { isAppUser } = userInOrg.user;
|
|
30
|
+
return !isAppUser;
|
|
31
|
+
});
|
|
32
|
+
const transformedUsers = filteredUsers.map((userInOrg) => {
|
|
33
|
+
const _a = userInOrg.user, { id, updatedBy, createdBy } = _a, user = __rest(_a, ["id", "updatedBy", "createdBy"]);
|
|
34
|
+
return Object.assign({ role: userInOrg.role }, user);
|
|
35
|
+
});
|
|
36
|
+
const sortedUsers = transformedUsers.sort((one, two) => (one.email < two.email ? -1 : 1));
|
|
37
|
+
return sortedUsers;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.exportUsers = exportUsers;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
export declare function uploadUsers(users: any[], entitiesInstance?: Entities): Promise<void>;
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
export declare function uploadUsers(users: any[], entitiesInstance?: Entities): Promise<void>;
|