@contrail/cli 2.2.8 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +135 -367
  2. package/dist/api/apps.js +1 -2
  3. package/dist/auth/auth.js +1 -0
  4. package/dist/basecommand.js +16 -19
  5. package/dist/commands/app/create.js +5 -5
  6. package/dist/commands/app/delete.js +7 -7
  7. package/dist/commands/app/getApiKey.js +8 -8
  8. package/dist/commands/app/init.js +5 -5
  9. package/dist/commands/app/install.js +24 -24
  10. package/dist/commands/app/publish.js +24 -24
  11. package/dist/commands/app/uninstall.js +14 -14
  12. package/dist/commands/app/upgrade.js +19 -19
  13. package/dist/commands/app/version/major.js +6 -9
  14. package/dist/commands/app/version/minor.js +6 -9
  15. package/dist/commands/app/version/patch.js +6 -9
  16. package/dist/commands/colors/deleteAll.js +5 -5
  17. package/dist/commands/colors/load.js +5 -5
  18. package/dist/commands/config/environments/list.js +6 -9
  19. package/dist/commands/config/environments/remove.js +12 -15
  20. package/dist/commands/config/environments/set.js +11 -14
  21. package/dist/commands/config/list.js +6 -9
  22. package/dist/commands/config/remove.js +16 -19
  23. package/dist/commands/config/set.js +22 -25
  24. package/dist/commands/groups/export.js +21 -22
  25. package/dist/commands/groups/upload.js +10 -11
  26. package/dist/commands/instance/export.js +19 -19
  27. package/dist/commands/instance/import.js +13 -13
  28. package/dist/commands/loader-process/load.js +12 -12
  29. package/dist/commands/loader-process/upload-and-load.js +17 -17
  30. package/dist/commands/projects/export.js +9 -9
  31. package/dist/commands/projects/list.js +5 -5
  32. package/dist/commands/projects/load.js +16 -17
  33. package/dist/commands/types/exportOptionSetHierarchies.js +5 -5
  34. package/dist/commands/types/getAll.js +73 -72
  35. package/dist/commands/types/loadAll.js +13 -13
  36. package/dist/commands/types/mergeOptionSets.js +9 -10
  37. package/dist/commands/types/mergeTypeProperties.js +11 -11
  38. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +9 -9
  39. package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +9 -9
  40. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +21 -0
  41. package/dist/commands/types/parseOptionSetsLocalFiles.js +97 -17
  42. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +0 -1
  43. package/dist/commands/types/parseOptionSetsToFolderStructure.js +5 -41
  44. package/dist/commands/types/parseTypesFromFiles.js +13 -13
  45. package/dist/commands/types/parseTypesFromLocalFiles.js +10 -10
  46. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +10 -10
  47. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +9 -9
  48. package/dist/commands/types/uploadOptionSetHierarchies.js +15 -16
  49. package/dist/commands/types/uploadOptionSets.js +15 -13
  50. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +13 -13
  51. package/dist/commands/types/uploadRuleSets.js +13 -13
  52. package/dist/commands/types/uploadTypePolicies.js +16 -16
  53. package/dist/commands/types/uploadTypePropertyPolicies.js +16 -16
  54. package/dist/commands/types/uploadTypes.js +13 -13
  55. package/dist/commands/types/uploadUsageInfo.js +13 -13
  56. package/dist/commands/users/export.js +19 -20
  57. package/dist/commands/users/upload.js +8 -8
  58. package/dist/commands/webhooks/create.js +5 -5
  59. package/dist/commands/webhooks/delete.js +11 -11
  60. package/dist/commands/webhooks/getWebhookTrigger.js +5 -5
  61. package/dist/commands/webhooks/list.js +11 -11
  62. package/dist/commands/workflow-template-definitions/install.js +5 -5
  63. package/dist/commands/workflow-template-definitions/list.js +5 -5
  64. package/dist/commands/workflow-templates/delete.js +5 -5
  65. package/dist/commands/workflow-templates/export.js +19 -20
  66. package/dist/commands/workflow-templates/list.js +5 -5
  67. package/dist/commands/workflow-templates/load.js +11 -11
  68. package/dist/helpers/app/actions-deployer.js +4 -4
  69. package/dist/helpers/app/app-deployer.js +9 -9
  70. package/dist/helpers/app/app-template-parsers.js +1 -1
  71. package/dist/helpers/app/extensions-deployer.js +5 -6
  72. package/dist/helpers/app/load-app-config.js +1 -1
  73. package/dist/helpers/loader-process/helpers.js +3 -3
  74. package/dist/helpers/projects/helpers.js +5 -5
  75. package/dist/helpers/types/type-parser.js +8 -8
  76. package/dist/helpers/types/type-uploader.js +19 -20
  77. package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +3 -4
  78. package/dist/helpers/workflow-templates/helper.js +11 -16
  79. package/dist/interface-converters.js +1 -2
  80. package/dist/interfaces.js +79 -0
  81. package/dist/logger.js +7 -6
  82. package/oclif.manifest.json +60 -1422
  83. package/package.json +1 -1
@@ -16,31 +16,31 @@ const logger_1 = tslib_1.__importDefault(require("../../logger"));
16
16
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
17
17
  const common_1 = require("../../common");
18
18
  class GetAllTypes extends basecommand_1.BaseCommand {
19
+ static description = 'Get all Types and associated data for your Org';
20
+ static examples = [
21
+ `$ contrail types getAll
22
+ `,
23
+ ];
24
+ static flags = {
25
+ outDir: core_1.Flags.string({
26
+ char: 'd',
27
+ description: 'The directory to which to export the type data. Defaults to the current directory',
28
+ required: false,
29
+ default: '.',
30
+ }),
31
+ overwrite: core_1.Flags.boolean({
32
+ char: 'f',
33
+ description: 'Replaces any existing export files in outDir',
34
+ required: false,
35
+ default: false,
36
+ }),
37
+ };
19
38
  async run() {
20
39
  const { flags } = await this.parse(GetAllTypes);
21
40
  await getAll(flags.outDir, flags.overwrite);
22
41
  }
23
42
  }
24
43
  exports.default = GetAllTypes;
25
- GetAllTypes.description = 'Get all Types and associated data for your Org';
26
- GetAllTypes.examples = [
27
- `$ contrail types getAll
28
- `,
29
- ];
30
- GetAllTypes.flags = {
31
- outDir: core_1.Flags.string({
32
- char: 'd',
33
- description: 'The directory to which to export the type data. Defaults to the current directory',
34
- required: false,
35
- default: '.',
36
- }),
37
- overwrite: core_1.Flags.boolean({
38
- char: 'f',
39
- description: 'Replaces any existing export files in outDir',
40
- required: false,
41
- default: false,
42
- }),
43
- };
44
44
  async function getAll(outDir, overwrite) {
45
45
  try {
46
46
  const userConfig = await (0, login_1.authUser)();
@@ -74,12 +74,10 @@ async function getAll(outDir, overwrite) {
74
74
  }
75
75
  exports.getAll = getAll;
76
76
  async function reduceTypePropertyPolicies(data) {
77
- var _a;
78
77
  const orgUsers = await (0, users_1.getUserOrgs)();
79
78
  const groups = await (0, users_1.getGroups)();
80
79
  function reducePrincipal(statement) {
81
- var _a, _b;
82
- if (!(statement === null || statement === void 0 ? void 0 : statement.principal)) {
80
+ if (!statement?.principal) {
83
81
  return statement;
84
82
  }
85
83
  const [type, id] = statement.principal.split(':');
@@ -87,7 +85,7 @@ async function reduceTypePropertyPolicies(data) {
87
85
  return statement;
88
86
  }
89
87
  if (type === 'group') {
90
- const groupName = (_a = groups.find((x) => x.id === id)) === null || _a === void 0 ? void 0 : _a.name;
88
+ const groupName = groups.find((x) => x.id === id)?.name;
91
89
  if (!groupName) {
92
90
  logger_1.default.info(`Could not find group for statement. skipping invalid policy conversion ${id}`);
93
91
  return statement;
@@ -95,7 +93,7 @@ async function reduceTypePropertyPolicies(data) {
95
93
  statement.principal = `group:${groupName}`;
96
94
  }
97
95
  else if (type === 'user') {
98
- const userEmail = (_b = orgUsers.find((x) => x.user.id === id)) === null || _b === void 0 ? void 0 : _b.email;
96
+ const userEmail = orgUsers.find((x) => x.user.id === id)?.email;
99
97
  if (!userEmail) {
100
98
  logger_1.default.info(`Could not find group for statement. skipping invalid policy conversion ${id}`);
101
99
  return statement;
@@ -104,7 +102,8 @@ async function reduceTypePropertyPolicies(data) {
104
102
  }
105
103
  return statement;
106
104
  }
107
- return (_a = data === null || data === void 0 ? void 0 : data.typePropertyPolicies) === null || _a === void 0 ? void 0 : _a.map((x) => {
105
+ return data?.typePropertyPolicies
106
+ ?.map((x) => {
108
107
  return {
109
108
  label: x.label,
110
109
  identifier: x.identifier,
@@ -113,11 +112,11 @@ async function reduceTypePropertyPolicies(data) {
113
112
  statements: x.policy.statements.map((x) => reducePrincipal(x)),
114
113
  },
115
114
  };
116
- }).sort((one, two) => (one.label < two.label ? -1 : 1));
115
+ })
116
+ .sort((one, two) => (one.label < two.label ? -1 : 1));
117
117
  }
118
118
  function reduceTypePropertyPolicyLinks(data) {
119
- var _a, _b;
120
- const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map((x) => x.typeProperties).reduce((x, y) => x.concat(y));
119
+ const typeProperties = data?.types?.map((x) => x.typeProperties).reduce((x, y) => x.concat(y));
121
120
  // make a map of all type properties to their type ids
122
121
  const typePropertyIdToTypeSlugMap = data.types.reduce((map, obj) => {
123
122
  for (const tp of obj.typeProperties) {
@@ -125,11 +124,11 @@ function reduceTypePropertyPolicyLinks(data) {
125
124
  }
126
125
  return map;
127
126
  }, {});
128
- return (_b = data === null || data === void 0 ? void 0 : data.typePropertyPolicyLinks) === null || _b === void 0 ? void 0 : _b.map((x) => {
129
- var _a, _b;
127
+ return data?.typePropertyPolicyLinks
128
+ ?.map((x) => {
130
129
  const typeSlug = typePropertyIdToTypeSlugMap[x.typePropertyId];
131
- const typePropertySlug = (_a = typeProperties.find((y) => y.id === x.typePropertyId)) === null || _a === void 0 ? void 0 : _a.slug;
132
- const typePropertyPolicyIdentifier = (_b = data.typePropertyPolicies.find((y) => y.id === x.typePropertyPolicyId)) === null || _b === void 0 ? void 0 : _b.identifier;
130
+ const typePropertySlug = typeProperties.find((y) => y.id === x.typePropertyId)?.slug;
131
+ const typePropertyPolicyIdentifier = data.typePropertyPolicies.find((y) => y.id === x.typePropertyPolicyId)?.identifier;
133
132
  if (!typeSlug || !typePropertySlug || !typePropertyPolicyIdentifier) {
134
133
  logger_1.default.debug(`typeSlug: ${typeSlug} typePropertySlug: ${typePropertySlug}, typePropertyPolicyIdentifier: ${typePropertyPolicyIdentifier} `);
135
134
  logger_1.default.warn(`Could not reduce bad type property policy link... skipping ${JSON.stringify(x, null, 2)}`);
@@ -140,15 +139,14 @@ function reduceTypePropertyPolicyLinks(data) {
140
139
  typePropertySlug,
141
140
  typePropertyPolicyIdentifier,
142
141
  };
143
- }).filter((x) => !!x);
142
+ })
143
+ .filter((x) => !!x);
144
144
  }
145
145
  async function reduceTypePolicies(data) {
146
- var _a;
147
146
  const orgUsers = await (0, users_1.getUserOrgs)();
148
147
  const groups = await (0, users_1.getGroups)();
149
148
  function reducePrincipal(statement) {
150
- var _a, _b;
151
- if (!(statement === null || statement === void 0 ? void 0 : statement.principal)) {
149
+ if (!statement?.principal) {
152
150
  return statement;
153
151
  }
154
152
  const [type, id] = statement.principal.split(':');
@@ -156,7 +154,7 @@ async function reduceTypePolicies(data) {
156
154
  return statement;
157
155
  }
158
156
  if (type === 'group') {
159
- const groupName = (_a = groups.find((x) => x.id === id)) === null || _a === void 0 ? void 0 : _a.name;
157
+ const groupName = groups.find((x) => x.id === id)?.name;
160
158
  if (!groupName) {
161
159
  logger_1.default.info(`Could not find group for statement. skipping invalid policy conversion ${id}`);
162
160
  return statement;
@@ -164,7 +162,7 @@ async function reduceTypePolicies(data) {
164
162
  statement.principal = `group:${groupName}`;
165
163
  }
166
164
  else if (type === 'user') {
167
- const userEmail = (_b = orgUsers.find((x) => x.user.id === id)) === null || _b === void 0 ? void 0 : _b.email;
165
+ const userEmail = orgUsers.find((x) => x.user.id === id)?.email;
168
166
  if (!userEmail) {
169
167
  logger_1.default.info(`Could not find group for statement. skipping invalid policy conversion ${id}`);
170
168
  return statement;
@@ -173,7 +171,8 @@ async function reduceTypePolicies(data) {
173
171
  }
174
172
  return statement;
175
173
  }
176
- return (_a = data === null || data === void 0 ? void 0 : data.typePolicies) === null || _a === void 0 ? void 0 : _a.map((x) => {
174
+ return data?.typePolicies
175
+ ?.map((x) => {
177
176
  return {
178
177
  label: x.label,
179
178
  identifier: x.identifier,
@@ -182,24 +181,22 @@ async function reduceTypePolicies(data) {
182
181
  statements: x.policy.statements.map((x) => reducePrincipal(x)),
183
182
  },
184
183
  };
185
- }).sort((one, two) => (one.label < two.label ? -1 : 1));
184
+ })
185
+ .sort((one, two) => (one.label < two.label ? -1 : 1));
186
186
  }
187
187
  function reduceTypePolicyLinks(data) {
188
- var _a;
189
- const types = data === null || data === void 0 ? void 0 : data.types;
190
- return (_a = data === null || data === void 0 ? void 0 : data.typePolicyLinks) === null || _a === void 0 ? void 0 : _a.map((x) => {
191
- var _a, _b;
188
+ const types = data?.types;
189
+ return data?.typePolicyLinks?.map((x) => {
192
190
  return {
193
- typeSlug: (_a = types.find((y) => y.id === x.typeId)) === null || _a === void 0 ? void 0 : _a.slug,
194
- typePolicyIdentifier: (_b = data.typePolicies.find((y) => y.id === x.typePolicyId)) === null || _b === void 0 ? void 0 : _b.identifier,
191
+ typeSlug: types.find((y) => y.id === x.typeId)?.slug,
192
+ typePolicyIdentifier: data.typePolicies.find((y) => y.id === x.typePolicyId)?.identifier,
195
193
  };
196
194
  });
197
195
  }
198
196
  function reduceUsageInfo(data) {
199
- var _a, _b;
200
- const typeProperties = (_a = data === null || data === void 0 ? void 0 : data.types) === null || _a === void 0 ? void 0 : _a.map((x) => x.typeProperties).reduce((x, y) => x.concat(y));
201
- return (_b = data === null || data === void 0 ? void 0 : data.usageInfo) === null || _b === void 0 ? void 0 : _b.map((x) => {
202
- var _a, _b;
197
+ const typeProperties = data?.types?.map((x) => x.typeProperties).reduce((x, y) => x.concat(y));
198
+ return data?.usageInfo
199
+ ?.map((x) => {
203
200
  return {
204
201
  used: x.used,
205
202
  editable: x.editable,
@@ -208,20 +205,20 @@ function reduceUsageInfo(data) {
208
205
  numberFormat: x.numberFormat,
209
206
  defaultValue: x.defaultValue,
210
207
  label: x.label,
211
- typeSlug: (_a = data.types.find((y) => y.id === x.typeId)) === null || _a === void 0 ? void 0 : _a.slug,
212
- typePropertySlug: (_b = typeProperties.find((y) => y.id === x.typePropertyId)) === null || _b === void 0 ? void 0 : _b.slug,
208
+ typeSlug: data.types.find((y) => y.id === x.typeId)?.slug,
209
+ typePropertySlug: typeProperties.find((y) => y.id === x.typePropertyId)?.slug,
213
210
  };
214
- }).sort((one, two) => (one.label < two.label ? -1 : 1));
211
+ })
212
+ .sort((one, two) => (one.label < two.label ? -1 : 1));
215
213
  }
216
214
  function reduceRuleSetLinks(data) {
217
- var _a, _b;
218
215
  const reducedRuleSetLinks = [];
219
- if (!(data === null || data === void 0 ? void 0 : data.ruleSetLinks.length)) {
216
+ if (!data?.ruleSetLinks.length) {
220
217
  return [];
221
218
  }
222
219
  for (const ruleSetLink of data.ruleSetLinks) {
223
- const ruleSet = (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.find((x) => x.id === ruleSetLink.typeRuleSetId);
224
- const type = (_b = data === null || data === void 0 ? void 0 : data.types) === null || _b === void 0 ? void 0 : _b.find((x) => x.id === ruleSetLink.typeId);
220
+ const ruleSet = data?.ruleSets?.find((x) => x.id === ruleSetLink.typeRuleSetId);
221
+ const type = data?.types?.find((x) => x.id === ruleSetLink.typeId);
225
222
  if (!ruleSet || !type) {
226
223
  logger_1.default.info(`${chalk_1.default.red.bold('TYPES')} Skipping bad rule set link ${ruleSetLink.id}`);
227
224
  }
@@ -238,42 +235,44 @@ function reduceRuleSetLinks(data) {
238
235
  });
239
236
  }
240
237
  function reduceRuleSets(data) {
241
- var _a;
242
- return (_a = data === null || data === void 0 ? void 0 : data.ruleSets) === null || _a === void 0 ? void 0 : _a.map((x) => {
238
+ return data?.ruleSets
239
+ ?.map((x) => {
243
240
  return {
244
241
  ruleSet: x.ruleSet,
245
242
  name: x.name,
246
243
  identifier: x.identifier,
247
244
  };
248
- }).sort((one, two) => (one.name < two.name ? -1 : 1));
245
+ })
246
+ .sort((one, two) => (one.name < two.name ? -1 : 1));
249
247
  }
250
248
  function reduceOptionSets(data) {
251
- var _a;
252
- return (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.map((optionSet) => {
249
+ return data.optionSets
250
+ ?.map((optionSet) => {
253
251
  return {
254
252
  name: optionSet.name,
255
253
  slug: optionSet.slug,
256
254
  isArchived: optionSet.isArchived,
257
255
  optionSet: optionSet.optionSet,
258
256
  };
259
- }).sort((one, two) => (one.name < two.name ? -1 : 1));
257
+ })
258
+ .sort((one, two) => (one.name < two.name ? -1 : 1));
260
259
  }
261
260
  function reduceOptionSetHierarchies(data) {
262
- var _a;
263
- return (_a = data.optionSetHierarchies) === null || _a === void 0 ? void 0 : _a.map((x) => {
264
- const hierarchyBySlug = x.hierarchy.map((optionSetId) => { var _a, _b; return (_b = (_a = data.optionSets) === null || _a === void 0 ? void 0 : _a.find((x) => x.id === optionSetId)) === null || _b === void 0 ? void 0 : _b.slug; });
261
+ return data.optionSetHierarchies
262
+ ?.map((x) => {
263
+ const hierarchyBySlug = x.hierarchy.map((optionSetId) => data.optionSets?.find((x) => x.id === optionSetId)?.slug);
265
264
  return {
266
265
  hierarchy: hierarchyBySlug,
267
266
  options: x.options,
268
267
  name: x.name,
269
268
  identifier: x.identifier,
270
269
  };
271
- }).sort((one, two) => (one.name < two.name ? -1 : 1));
270
+ })
271
+ .sort((one, two) => (one.name < two.name ? -1 : 1));
272
272
  }
273
273
  function reduceOptionSetHierarchyLinks(data) {
274
- var _a;
275
- return (_a = data.optionSetHierarchyLinks) === null || _a === void 0 ? void 0 : _a.map((x) => {
276
- var _a;
274
+ return data.optionSetHierarchyLinks
275
+ ?.map((x) => {
277
276
  const osh = data.optionSetHierarchies.find((y) => y.id === x.optionSetHierarchyId);
278
277
  if (!osh) {
279
278
  logger_1.default.info(`OSH Link: could not find option set hierarchy ${x.optionSetHierarchyId} skipping...`);
@@ -286,7 +285,7 @@ function reduceOptionSetHierarchyLinks(data) {
286
285
  }
287
286
  const typePropertySlugs = [];
288
287
  for (const tpId of x.hierarchyTypePropertyIds) {
289
- const typePropertySlug = (_a = type.typeProperties.find((y) => y.id === tpId)) === null || _a === void 0 ? void 0 : _a.slug;
288
+ const typePropertySlug = type.typeProperties.find((y) => y.id === tpId)?.slug;
290
289
  if (!typePropertySlug) {
291
290
  logger_1.default.info(`OSH Link: could not find type property ${tpId} skipping...`);
292
291
  return null;
@@ -298,7 +297,9 @@ function reduceOptionSetHierarchyLinks(data) {
298
297
  typeSlug: type.slug,
299
298
  typePropertySlugs,
300
299
  };
301
- }).filter((x) => !!x).sort((one, two) => (one.typeSlug < two.typeSlug ? -1 : 1));
300
+ })
301
+ .filter((x) => !!x)
302
+ .sort((one, two) => (one.typeSlug < two.typeSlug ? -1 : 1));
302
303
  }
303
304
  function reduceTypes(dataHolder) {
304
305
  logger_1.default.info(`Found types: ${dataHolder.types.length}`);
@@ -15,25 +15,25 @@ const uploadTypePolicies_1 = require("./uploadTypePolicies");
15
15
  const basecommand_1 = require("../../basecommand");
16
16
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
17
17
  class LoadAllTypes extends basecommand_1.BaseCommand {
18
+ static description = 'loads all the type data that has been exported by getAll';
19
+ static examples = [
20
+ `$ contrail types loadAll
21
+ `,
22
+ ];
23
+ static flags = {
24
+ dir: core_1.Flags.string({
25
+ char: 'd',
26
+ description: 'The directory from which to load the types data. Defaults to the current directory.',
27
+ required: false,
28
+ default: '.',
29
+ }),
30
+ };
18
31
  async run() {
19
32
  const { flags } = await this.parse(LoadAllTypes);
20
33
  await loadAll(flags.dir);
21
34
  }
22
35
  }
23
36
  exports.default = LoadAllTypes;
24
- LoadAllTypes.description = 'loads all the type data that has been exported by getAll';
25
- LoadAllTypes.examples = [
26
- `$ contrail types loadAll
27
- `,
28
- ];
29
- LoadAllTypes.flags = {
30
- dir: core_1.Flags.string({
31
- char: 'd',
32
- description: 'The directory from which to load the types data. Defaults to the current directory.',
33
- required: false,
34
- default: '.',
35
- }),
36
- };
37
37
  async function loadAll(dir, skipPolicies = false) {
38
38
  try {
39
39
  await (0, login_1.authUser)();
@@ -11,6 +11,14 @@ const basecommand_1 = require("../../basecommand");
11
11
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
12
12
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
13
13
  class MergeOptionSets extends basecommand_1.BaseCommand {
14
+ static description = 'Merge the OptionSets from an existing org and the OptionSets passed in. OptionSets File must be .yml.';
15
+ static examples = [
16
+ `$ contrail types mergeOptionSets <File Path>
17
+ `,
18
+ ];
19
+ static args = {
20
+ file: core_1.Args.string({ description: 'File to merge with the cloud option sets', required: true }),
21
+ };
14
22
  async run() {
15
23
  const { args } = await this.parse(MergeOptionSets);
16
24
  try {
@@ -27,14 +35,6 @@ class MergeOptionSets extends basecommand_1.BaseCommand {
27
35
  }
28
36
  }
29
37
  exports.default = MergeOptionSets;
30
- MergeOptionSets.description = 'Merge the OptionSets from an existing org and the OptionSets passed in. OptionSets File must be .yml.';
31
- MergeOptionSets.examples = [
32
- `$ contrail types mergeOptionSets <File Path>
33
- `,
34
- ];
35
- MergeOptionSets.args = {
36
- file: core_1.Args.string({ description: 'File to merge with the cloud option sets', required: true }),
37
- };
38
38
  function loadOptionSets(fileLocation) {
39
39
  const TARGET_DIR = process.cwd();
40
40
  try {
@@ -91,14 +91,13 @@ async function mergeOptionSets(fileLocation) {
91
91
  saveData(mergedOptionSets);
92
92
  }
93
93
  function mergeOptionSet(existingOptionSet, uploadedOptionSet) {
94
- var _a;
95
94
  const merged = {
96
95
  name: uploadedOptionSet.name,
97
96
  slug: uploadedOptionSet.slug,
98
97
  optionSet: uploadedOptionSet.optionSet,
99
98
  isArchived: uploadedOptionSet.isArchived,
100
99
  };
101
- if (((_a = existingOptionSet === null || existingOptionSet === void 0 ? void 0 : existingOptionSet.optionSet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
100
+ if (existingOptionSet?.optionSet?.length > 0) {
102
101
  for (const keyVal of existingOptionSet.optionSet) {
103
102
  const value = keyVal.value;
104
103
  const display = keyVal.display;
@@ -13,6 +13,17 @@ const basecommand_1 = require("../../basecommand");
13
13
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
14
14
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
15
15
  class MergeTypeProperties extends basecommand_1.BaseCommand {
16
+ static description = 'Merge the TypeProperties from an existing org and the TypeProperties passed in. Add to Types via TypePath File must be .yml';
17
+ static examples = [
18
+ `$ contrail types mergeTypeProperties <File Path> <TypePaths>
19
+ `,
20
+ ];
21
+ // variable argument length
22
+ static strict = false;
23
+ static args = {
24
+ file: core_1.Args.string({ description: 'File to parse', required: true }),
25
+ typePaths: core_1.Args.string({ description: 'A list of the type paths to merge', required: true }),
26
+ };
16
27
  async run() {
17
28
  const { args, argv } = await this.parse(MergeTypeProperties);
18
29
  try {
@@ -32,17 +43,6 @@ class MergeTypeProperties extends basecommand_1.BaseCommand {
32
43
  }
33
44
  }
34
45
  exports.default = MergeTypeProperties;
35
- MergeTypeProperties.description = 'Merge the TypeProperties from an existing org and the TypeProperties passed in. Add to Types via TypePath File must be .yml';
36
- MergeTypeProperties.examples = [
37
- `$ contrail types mergeTypeProperties <File Path> <TypePaths>
38
- `,
39
- ];
40
- // variable argument length
41
- MergeTypeProperties.strict = false;
42
- MergeTypeProperties.args = {
43
- file: core_1.Args.string({ description: 'File to parse', required: true }),
44
- typePaths: core_1.Args.string({ description: 'A list of the type paths to merge', required: true }),
45
- };
46
46
  function loadTypeProperties(fileLocation) {
47
47
  const TARGET_DIR = process.cwd();
48
48
  try {
@@ -14,20 +14,20 @@ const basecommand_1 = require("../../basecommand");
14
14
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
15
15
  const _ = tslib_1.__importStar(require("lodash"));
16
16
  class ParseOptionSetsHierarchyLocalFile extends basecommand_1.BaseCommand {
17
+ static description = 'Parse CSV file into OptionSetHierarchy';
18
+ static examples = [
19
+ `$ contrail types parseOptionSetsHierarchyLocalFile <File Paths>
20
+ `,
21
+ ];
22
+ static args = {
23
+ file: core_1.Args.string({ description: 'File to parse', required: true }),
24
+ };
17
25
  async run() {
18
26
  const { args } = await this.parse(ParseOptionSetsHierarchyLocalFile);
19
27
  await parseOptionSetsHierarchyLocalFile(args.file);
20
28
  }
21
29
  }
22
30
  exports.default = ParseOptionSetsHierarchyLocalFile;
23
- ParseOptionSetsHierarchyLocalFile.description = 'Parse CSV file into OptionSetHierarchy';
24
- ParseOptionSetsHierarchyLocalFile.examples = [
25
- `$ contrail types parseOptionSetsHierarchyLocalFile <File Paths>
26
- `,
27
- ];
28
- ParseOptionSetsHierarchyLocalFile.args = {
29
- file: core_1.Args.string({ description: 'File to parse', required: true }),
30
- };
31
31
  async function parseOptionSetsHierarchyLocalFile(fileLocation) {
32
32
  try {
33
33
  await (0, login_1.authUser)();
@@ -62,7 +62,7 @@ async function parseOptionSetHierarchiesLocalFile(fileLocation) {
62
62
  name: 'No Name',
63
63
  options: [],
64
64
  };
65
- if (!((uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length) > 0)) {
65
+ if (!(uploadedOptionHierarchyData?.length > 0)) {
66
66
  return optionSetHierarchy;
67
67
  }
68
68
  const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
@@ -14,20 +14,20 @@ const logger_1 = tslib_1.__importDefault(require("../../logger"));
14
14
  const json2csv_1 = require("json2csv");
15
15
  const util_1 = require("@contrail/util");
16
16
  class ParseOptionSetsHierarchyValuesToKeysLocalFile extends basecommand_1.BaseCommand {
17
+ static description = 'Parse CSV file into OptionSetHierarchy';
18
+ static examples = [
19
+ `$ contrail types parseOptionSetsHierarchyValuesToKeysLocalFile <File Paths>
20
+ `,
21
+ ];
22
+ static args = {
23
+ file: core_1.Args.string({ description: 'File to parse', required: true }),
24
+ };
17
25
  async run() {
18
26
  const { args } = await this.parse(ParseOptionSetsHierarchyValuesToKeysLocalFile);
19
27
  await parseOptionSetsHierarchyValuesToKeysLocalFile(args.file);
20
28
  }
21
29
  }
22
30
  exports.default = ParseOptionSetsHierarchyValuesToKeysLocalFile;
23
- ParseOptionSetsHierarchyValuesToKeysLocalFile.description = 'Parse CSV file into OptionSetHierarchy';
24
- ParseOptionSetsHierarchyValuesToKeysLocalFile.examples = [
25
- `$ contrail types parseOptionSetsHierarchyValuesToKeysLocalFile <File Paths>
26
- `,
27
- ];
28
- ParseOptionSetsHierarchyValuesToKeysLocalFile.args = {
29
- file: core_1.Args.string({ description: 'File to parse', required: true }),
30
- };
31
31
  async function parseOptionSetsHierarchyValuesToKeysLocalFile(fileLocation) {
32
32
  try {
33
33
  await (0, login_1.authUser)();
@@ -59,7 +59,7 @@ async function loadOptionSetHierarchyCSV(fileLocation) {
59
59
  }
60
60
  async function parseOptionSetHierarchiesLocalFile(fileLocation) {
61
61
  const uploadedOptionHierarchyData = await loadOptionSetHierarchyCSV(fileLocation);
62
- if (!((uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length) > 0)) {
62
+ if (!(uploadedOptionHierarchyData?.length > 0)) {
63
63
  return [];
64
64
  }
65
65
  const keysInOrder = Object.keys(uploadedOptionHierarchyData[0]);
@@ -11,4 +11,25 @@ export default class ParseOptionSetsLocalFiles extends BaseCommand {
11
11
  run(): Promise<void>;
12
12
  }
13
13
  export declare function ParseOptionSetsToFolderStructure(args: any): Promise<void>;
14
+ /**
15
+ * Expects
16
+ * @param uploadedOptionData
17
+ * @returns
18
+ */
14
19
  export declare function parseLabelsInColumn(uploadedOptionData: any): any[];
20
+ /**
21
+ * Expects a CSV file with an ignored header file and 3 columns:
22
+ * The first column contains the option set name (e.g. Gender)
23
+ * The second column contains the option keys (e.g. ge_men)
24
+ * The second column contains the option display label (e.g. Men)
25
+ *
26
+ * Sample file
27
+ * ignored header 1, ignored header 2, ignored header 3
28
+ * Gender, ge_men, Men
29
+ * Gender, ge_women, Women
30
+ * Brand, b_prada, Prada
31
+ * Brand, b_coach, Coach
32
+ * @param uploadedOptionData
33
+ * @returns
34
+ */
35
+ export declare function parseNameAndLabelAndKey(uploadedOptionData: any[]): any[];