@contrail/cli 2.0.21 → 2.0.22

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 CHANGED
@@ -15,7 +15,7 @@ $ npm install -g @contrail/cli
15
15
  $ contrail COMMAND
16
16
  running command...
17
17
  $ contrail (--version)
18
- @contrail/cli/2.0.21 darwin-arm64 node-v18.13.0
18
+ @contrail/cli/2.0.22 darwin-arm64 node-v18.13.0
19
19
  $ contrail --help [COMMAND]
20
20
  USAGE
21
21
  $ contrail COMMAND
@@ -764,11 +764,11 @@ Get all Types and associated data for your Org
764
764
 
765
765
  ```
766
766
  USAGE
767
- $ contrail types getAll [-d <value>] [--overwrite]
767
+ $ contrail types getAll [-d <value>] [-f]
768
768
 
769
769
  FLAGS
770
770
  -d, --outDir=<value> [default: .] The directory to which to export the type data. Defaults to the current directory
771
- --overwrite Replaces any existing export files in outDir
771
+ -f, --overwrite Replaces any existing export files in outDir
772
772
 
773
773
  DESCRIPTION
774
774
  Get all Types and associated data for your Org
@@ -1,5 +1,6 @@
1
1
  export declare function getOptionSets(): Promise<any>;
2
2
  export declare function getOptionSetHierarchies(): Promise<any>;
3
+ export declare function getOptionSetHierarchyLinks(): Promise<any>;
3
4
  export declare function getRuleSets(): Promise<any>;
4
5
  export declare function getRuleSetLinks(): Promise<any>;
5
6
  export declare function getUsageInfo(): Promise<any>;
package/dist/api/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypePolicyLinks = exports.getTypePolicies = exports.getTypePropertyPolicyLinks = exports.getTypePropertyPolicies = exports.getUsageInfo = exports.getRuleSetLinks = exports.getRuleSets = exports.getOptionSetHierarchies = exports.getOptionSets = void 0;
3
+ exports.getTypePolicyLinks = exports.getTypePolicies = exports.getTypePropertyPolicyLinks = exports.getTypePropertyPolicies = exports.getUsageInfo = exports.getRuleSetLinks = exports.getRuleSets = exports.getOptionSetHierarchyLinks = exports.getOptionSetHierarchies = exports.getOptionSets = void 0;
4
4
  const sdk_1 = require("@contrail/sdk");
5
5
  async function getOptionSets() {
6
6
  return await new sdk_1.Entities().get({
@@ -15,6 +15,13 @@ async function getOptionSetHierarchies() {
15
15
  });
16
16
  }
17
17
  exports.getOptionSetHierarchies = getOptionSetHierarchies;
18
+ async function getOptionSetHierarchyLinks() {
19
+ const entitiesClient = new sdk_1.Entities();
20
+ return await entitiesClient.get({
21
+ entityName: 'type-option-set-hierarchy-link',
22
+ });
23
+ }
24
+ exports.getOptionSetHierarchyLinks = getOptionSetHierarchyLinks;
18
25
  async function getRuleSets() {
19
26
  const entitiesClient = new sdk_1.Entities();
20
27
  return await entitiesClient.get({
@@ -3,6 +3,7 @@ export interface DataHolder {
3
3
  types: any[];
4
4
  optionSets: any[];
5
5
  optionSetHierarchies: any[];
6
+ optionSetHierarchyLinks: any[];
6
7
  ruleSets: any[];
7
8
  ruleSetLinks: any[];
8
9
  usageInfo: any[];
@@ -15,6 +16,7 @@ export interface ReducedDataHolder {
15
16
  reducedTypes: any[];
16
17
  reducedOptionSets: any[];
17
18
  reducedOptionSetHierarchies: any[];
19
+ reducedOptionSetHierarchyLinks: any[];
18
20
  reducedRuleSets: any[];
19
21
  reducedRuleSetLinks: any[];
20
22
  reducedUsageInfo: any[];
@@ -26,7 +26,7 @@ GetAllTypes.examples = [
26
26
  ];
27
27
  GetAllTypes.flags = {
28
28
  outDir: core_1.Flags.string({ char: 'd', description: 'The directory to which to export the type data. Defaults to the current directory', required: false, default: '.' }),
29
- overwrite: core_1.Flags.boolean({ description: 'Replaces any existing export files in outDir', required: false, default: false })
29
+ overwrite: core_1.Flags.boolean({ char: 'f', description: 'Replaces any existing export files in outDir', required: false, default: false })
30
30
  };
31
31
  async function getAll(outDir, overwrite) {
32
32
  try {
@@ -40,6 +40,7 @@ async function getAll(outDir, overwrite) {
40
40
  types: await (0, type_extractor_1.getTypes)(),
41
41
  optionSets: await (0, types_1.getOptionSets)(),
42
42
  optionSetHierarchies: await (0, types_1.getOptionSetHierarchies)(),
43
+ optionSetHierarchyLinks: await (0, types_1.getOptionSetHierarchyLinks)(),
43
44
  ruleSets: await (0, types_1.getRuleSets)(),
44
45
  ruleSetLinks: await (0, types_1.getRuleSetLinks)(),
45
46
  usageInfo: await (0, types_1.getUsageInfo)(),
@@ -247,6 +248,36 @@ function reduceOptionSetHierarchies(data) {
247
248
  };
248
249
  });
249
250
  }
251
+ function reduceOptionSetHierarchyLinks(data) {
252
+ var _a;
253
+ return (_a = data.optionSetHierarchyLinks) === null || _a === void 0 ? void 0 : _a.map(x => {
254
+ var _a;
255
+ const osh = data.optionSetHierarchies.find(y => y.id === x.optionSetHierarchyId);
256
+ if (!osh) {
257
+ console.log('OSH Link: could not find option set hierarchy', x.optionSetHierarchyId, 'skipping...');
258
+ return null;
259
+ }
260
+ const type = data.types.find(y => y.id === x.typeId);
261
+ if (!type) {
262
+ console.log('OSH Link: could not find type', x.typeId, 'skipping...');
263
+ return null;
264
+ }
265
+ const typePropertySlugs = [];
266
+ for (const tpId of x.hierarchyTypePropertyIds) {
267
+ const typePropertySlug = (_a = type.typeProperties.find(y => y.id === tpId)) === null || _a === void 0 ? void 0 : _a.slug;
268
+ if (!typePropertySlug) {
269
+ console.log('OSH Link: could not find type property', tpId, 'skipping...');
270
+ return null;
271
+ }
272
+ typePropertySlugs.push(typePropertySlug);
273
+ }
274
+ return {
275
+ optionSetHierarchyName: osh.name,
276
+ typeSlug: type.slug,
277
+ typePropertySlugs,
278
+ };
279
+ }).filter(x => !!x);
280
+ }
250
281
  function reduceTypes(dataHolder) {
251
282
  console.log('Found types: ', dataHolder.types.length);
252
283
  let reducedTypes = [];
@@ -269,6 +300,7 @@ function reduceTypes(dataHolder) {
269
300
  typePropertyOptionSetName: optionSetNameById[typeProperty.typePropertyOptionSetId],
270
301
  formula: typeProperty.formula,
271
302
  referencedTypePath: typeProperty.referencedTypePath,
303
+ referencedTypeRootSlug: typeProperty.referencedTypeRootSlug,
272
304
  defaultValue: typeProperty.defaultValue,
273
305
  propertyLevel: typeProperty.propertyLevel,
274
306
  inherited: typeProperty.inherited,
@@ -301,6 +333,7 @@ async function reduceData(data) {
301
333
  reducedTypes: reduceTypes(data),
302
334
  reducedOptionSets: reduceOptionSets(data),
303
335
  reducedOptionSetHierarchies: reduceOptionSetHierarchies(data),
336
+ reducedOptionSetHierarchyLinks: reduceOptionSetHierarchyLinks(data),
304
337
  reducedRuleSets: reduceRuleSets(data),
305
338
  reducedRuleSetLinks: reduceRuleSetLinks(data),
306
339
  reducedUsageInfo: reduceUsageInfo(data),
@@ -349,6 +382,7 @@ async function saveData(reducedData, dir, overwrite) {
349
382
  reducedTypes: { filename: 'types', split: false, fileLabel: 'slug', saveFunction: saveTypesFunction },
350
383
  reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
351
384
  reducedOptionSetHierarchies: { filename: 'option-set-hierarchies', split: true, fileLabel: 'name' },
385
+ reducedOptionSetHierarchyLinks: { filename: 'type-option-set-hierarchy-links', split: false, fileLabel: '' },
352
386
  reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
353
387
  reducedRuleSetLinks: { filename: 'rule-set-links', split: false, fileLabel: '' },
354
388
  reducedUsageInfo: { filename: 'usage-info', split: false, fileLabel: '' },
@@ -31,8 +31,8 @@ async function loadAll(dir, skipPolicies = false) {
31
31
  try {
32
32
  await (0, login_1.authUser)();
33
33
  await (0, uploadOptionSets_1.uploadOptionSets)(dir);
34
- await (0, uploadOptionSetHierarchies_1.uploadOptionSetHierarchies)(dir);
35
34
  await (0, type_uploader_1.uploadTypes)(dir);
35
+ await (0, uploadOptionSetHierarchies_1.uploadOptionSetHierarchies)(dir);
36
36
  await (0, uploadUsageInfo_1.uploadUsageInfo)(dir);
37
37
  await (0, uploadRuleSets_1.uploadRuleSets)(dir);
38
38
  if (!skipPolicies) {
@@ -58,6 +58,7 @@ async function mergeTypeProperties(fileLocation, typePaths) {
58
58
  types: await (0, type_extractor_1.getTypes)(),
59
59
  optionSets: await (0, types_1.getOptionSets)(),
60
60
  optionSetHierarchies: [],
61
+ optionSetHierarchyLinks: [],
61
62
  ruleSets: [],
62
63
  ruleSetLinks: [],
63
64
  usageInfo: [],
@@ -8,6 +8,7 @@ const path = tslib_1.__importStar(require("path"));
8
8
  const login_1 = require("../../auth/login");
9
9
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
10
  const core_1 = require("@oclif/core");
11
+ const type_extractor_1 = require("../../helpers/types/type-extractor");
11
12
  const yaml = require('js-yaml');
12
13
  class UploadOptionSetHierarchies extends core_1.Command {
13
14
  async run() {
@@ -30,6 +31,8 @@ async function uploadOptionSetHierarchies(dir) {
30
31
  console.log('%s Uploading', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
31
32
  const optionSetHierarchies = await loadOptionSetHierarchies(dir);
32
33
  await uploadOSH(optionSetHierarchies);
34
+ const optionSetHierarchyLinks = await loadOptionSetHierarchyLinks(dir);
35
+ await uploadOSHLinks(optionSetHierarchyLinks);
33
36
  console.log('%s Uploaded', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
34
37
  }
35
38
  catch (e) {
@@ -53,6 +56,14 @@ function loadOptionSetHierarchies(fromDir) {
53
56
  throw new Error(`ERROR PARSING YAML: ${e}`);
54
57
  }
55
58
  }
59
+ function loadOptionSetHierarchyLinks(fromDir) {
60
+ try {
61
+ return yaml.load(fs_1.default.readFileSync(path.join(fromDir, 'type-option-set-hierarchy-links.yml'), 'utf8'));
62
+ }
63
+ catch (e) {
64
+ throw new Error(`ERROR PARSING YAML: ${e}`);
65
+ }
66
+ }
56
67
  async function uploadOSH(loadedOSHs) {
57
68
  const optionSets = await new sdk_1.Entities().get({
58
69
  entityName: 'type-property-option-set',
@@ -132,3 +143,96 @@ function transformOSHNameToID(hierarchy, optionSets) {
132
143
  }
133
144
  return true;
134
145
  }
146
+ async function uploadOSHLinks(reducedOSHLinks) {
147
+ const typesWithProperties = await (0, type_extractor_1.getTypes)();
148
+ const typeProperties = [];
149
+ typesWithProperties.forEach(type => {
150
+ if (type.typeProperties) {
151
+ for (const tp of type.typeProperties) {
152
+ tp.typeId = type.id;
153
+ tp.typeSlug = type.slug;
154
+ typeProperties.push(tp);
155
+ }
156
+ }
157
+ });
158
+ const currentOSHs = await new sdk_1.Entities().get({
159
+ entityName: 'option-set-hierarchy',
160
+ });
161
+ const currentOSHLinks = await new sdk_1.Entities().get({
162
+ entityName: 'type-option-set-hierarchy-link',
163
+ });
164
+ const currentOSHLinkHashes = {};
165
+ for (const currentLink of currentOSHLinks) {
166
+ const foundType = typesWithProperties.find(x => x.id === currentLink.typeId);
167
+ const foundOSH = currentOSHs.find(osh => osh.id === currentLink.optionSetHierarchyId);
168
+ const foundTPSlugs = typeProperties.filter(x => { var _a; return (_a = currentLink === null || currentLink === void 0 ? void 0 : currentLink.hierarchyTypePropertyIds) === null || _a === void 0 ? void 0 : _a.includes(x.id); }).map(x => x.slug);
169
+ if (!foundType || !foundOSH || (foundTPSlugs.length !== currentLink.hierarchyTypePropertyIds.length)) {
170
+ console.log('skipping unhashable, invalid type option set hierarchy link:', currentLink);
171
+ }
172
+ const hash = `${foundType.slug}|${foundOSH.name}|${foundTPSlugs.sort().join('|')}`;
173
+ currentOSHLinkHashes[hash] = currentLink;
174
+ }
175
+ const reducedLinksByHashes = {};
176
+ for (const loadedLink of reducedOSHLinks) {
177
+ const hash = `${loadedLink.typeSlug}|${loadedLink.optionSetHierarchyName}|${loadedLink.typePropertySlugs.sort().join('|')}}`;
178
+ reducedLinksByHashes[hash] = loadedLink;
179
+ }
180
+ for (const loadedLink of reducedOSHLinks) {
181
+ try {
182
+ const found = currentOSHLinkHashes[`${loadedLink.typeSlug}|${loadedLink.optionSetHierarchyName}|${loadedLink.typePropertySlugs.sort().join('|')}`];
183
+ if (!found) {
184
+ if (!transformReducedLink(loadedLink, typesWithProperties, currentOSHs)) {
185
+ continue;
186
+ }
187
+ await new sdk_1.Entities().create({
188
+ entityName: 'type-option-set-hierarchy-link',
189
+ object: {
190
+ hierarchyTypePropertyIds: loadedLink.hierarchyTypePropertyIds,
191
+ optionSetHierarchyId: loadedLink.optionSetHierarchyId,
192
+ typeId: loadedLink.typeId,
193
+ },
194
+ });
195
+ }
196
+ }
197
+ catch (err) {
198
+ throw new Error(`Error uploading type option set hierarchy links: ${err}`);
199
+ }
200
+ }
201
+ for (const [currentLinkHash, currentLink] of Object.entries(currentOSHLinkHashes)) {
202
+ try {
203
+ const found = reducedLinksByHashes[currentLinkHash];
204
+ if (!found) {
205
+ console.log('Deleting: ', currentLinkHash);
206
+ await new sdk_1.Entities().delete({
207
+ entityName: 'type-option-set-hierarchy-link',
208
+ id: currentLink['id'],
209
+ });
210
+ }
211
+ }
212
+ catch (err) {
213
+ throw new Error(`Error Deleting rule set link: ${err}`);
214
+ }
215
+ }
216
+ }
217
+ function transformReducedLink(OSHLink, typesWithProperties, OSHs) {
218
+ var _a, _b;
219
+ const foundType = typesWithProperties.find(x => x.slug === OSHLink.typeSlug);
220
+ if (!foundType) {
221
+ console.error('OSH Links: Could not find type with slug', OSHLink.typeSlug);
222
+ return false;
223
+ }
224
+ OSHLink.typeId = foundType.id;
225
+ const foundTPs = (_b = (_a = foundType === null || foundType === void 0 ? void 0 : foundType.typeProperties) === null || _a === void 0 ? void 0 : _a.filter(x => OSHLink.typePropertySlugs.includes(x.slug))) !== null && _b !== void 0 ? _b : [];
226
+ if (foundTPs.length !== OSHLink.typePropertySlugs.length) {
227
+ console.error('OSH Links: Could not find all type properties with slugs', OSHLink.typePropertySlugs);
228
+ return false;
229
+ }
230
+ OSHLink.hierarchyTypePropertyIds = foundTPs.map(x => x.id);
231
+ const foundOSH = OSHs.find(x => x.name === OSHLink.optionSetHierarchyName);
232
+ if (!foundOSH) {
233
+ console.error('OSH Links: Could not find option set hierarchy with name', OSHLink.optionSetHierarchyName);
234
+ return false;
235
+ }
236
+ OSHLink.optionSetHierarchyId = foundOSH.id;
237
+ return true;
238
+ }
@@ -217,7 +217,7 @@ async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
217
217
  }
218
218
  }
219
219
  catch (err) {
220
- throw new Error(`Error Deleting rule set link: ${err}`);
220
+ throw new Error(`Error Deleting type property policy link: ${err}`);
221
221
  }
222
222
  }
223
223
  }
@@ -1 +1 @@
1
- export declare function getTypes(): Promise<any[]>;
1
+ export declare function getTypes(withTypes?: boolean): Promise<any>;
@@ -6,13 +6,16 @@ const sdk_1 = require("@contrail/sdk");
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
7
  const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
8
8
  const limit = (0, p_limit_1.default)(30);
9
- async function getTypes() {
9
+ async function getTypes(withTypes = true) {
10
10
  console.log('%s Retrieving', chalk_1.default.yellow.bold('TYPES'));
11
11
  const entitiesClient = new sdk_1.Entities();
12
12
  const types = await entitiesClient.get({
13
13
  entityName: 'type',
14
14
  });
15
15
  console.log(`${chalk_1.default.yellow.bold('TYPES')} Found ${types.length} types`);
16
+ if (!withTypes) {
17
+ return types;
18
+ }
16
19
  const typesWithProperties = [];
17
20
  const promises = [];
18
21
  for (const type of types) {
@@ -149,10 +149,12 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
149
149
  typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
150
150
  formula: newPropertyType.formula,
151
151
  referencedTypePath: newPropertyType.referencedTypePath,
152
+ referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
152
153
  defaultValue: newPropertyType.defaultValue,
153
154
  propertyLevel: newPropertyType.propertyLevel,
154
155
  formulaFunction: newPropertyType.formulaFunction,
155
156
  validationFunction: newPropertyType.validationFunction,
157
+ numberFormat: newPropertyType.numberFormat,
156
158
  }),
157
159
  headers: {
158
160
  Accept: 'application/json',
@@ -176,10 +178,12 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
176
178
  typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
177
179
  formula: newPropertyType.formula,
178
180
  referencedTypePath: newPropertyType.referencedTypePath,
181
+ referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
179
182
  defaultValue: newPropertyType.defaultValue,
180
183
  propertyLevel: newPropertyType.propertyLevel,
181
184
  formulaFunction: newPropertyType.formulaFunction,
182
185
  validationFunction: newPropertyType.validationFunction,
186
+ numberFormat: newPropertyType.numberFormat,
183
187
  },
184
188
  });
185
189
  }
@@ -219,6 +223,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
219
223
  typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
220
224
  formula: typeProperty1.formula,
221
225
  referencedTypePath: typeProperty1.referencedTypePath,
226
+ referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
222
227
  defaultValue: typeProperty1.defaultValue,
223
228
  propertyLevel: typeProperty1.propertyLevel,
224
229
  formulaFunction: typeProperty1.formulaFunction,
@@ -235,6 +240,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
235
240
  typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
236
241
  formula: typeProperty2.formula,
237
242
  referencedTypePath: typeProperty2.referencedTypePath,
243
+ referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
238
244
  defaultValue: typeProperty2.defaultValue,
239
245
  propertyLevel: typeProperty2.propertyLevel,
240
246
  formulaFunction: typeProperty2.formulaFunction,
@@ -302,6 +302,7 @@ export interface ReducedTypeProperty {
302
302
  typePropertyOptionSetName: string;
303
303
  formula: string;
304
304
  referencedTypePath: string;
305
+ referencedTypeRootSlug: string;
305
306
  defaultValue: string;
306
307
  propertyLevel: string;
307
308
  inherited: boolean;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.21",
2
+ "version": "2.0.22",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -547,6 +547,7 @@
547
547
  "overwrite": {
548
548
  "name": "overwrite",
549
549
  "type": "boolean",
550
+ "char": "f",
550
551
  "description": "Replaces any existing export files in outDir",
551
552
  "required": false,
552
553
  "allowNo": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",