@axway/axway-central-cli 2.17.0-rc.5 → 2.17.0

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 (58) hide show
  1. package/dist/cli.js +28 -6
  2. package/dist/commands/apply/index.js +24 -9
  3. package/dist/commands/completion/index.js +9 -3
  4. package/dist/commands/config/common/index.js +11 -2
  5. package/dist/commands/config/index.js +7 -2
  6. package/dist/commands/config/list.js +6 -2
  7. package/dist/commands/config/set.js +31 -4
  8. package/dist/commands/config/unset.js +12 -2
  9. package/dist/commands/create/agentResource.js +32 -12
  10. package/dist/commands/create/environment.js +16 -6
  11. package/dist/commands/create/index.js +26 -9
  12. package/dist/commands/create/serviceAccount.js +6 -2
  13. package/dist/commands/delete/index.js +33 -15
  14. package/dist/commands/edit/environment.js +21 -6
  15. package/dist/commands/edit/index.js +8 -4
  16. package/dist/commands/get/index.js +44 -27
  17. package/dist/commands/install/agents.js +73 -44
  18. package/dist/commands/install/apigeexSaasAgents.js +98 -35
  19. package/dist/commands/install/awsAgents.js +139 -89
  20. package/dist/commands/install/awsSaasAgents.js +142 -50
  21. package/dist/commands/install/azureAgents.js +79 -39
  22. package/dist/commands/install/edgeAgents.js +110 -17
  23. package/dist/commands/install/helpers/creators.js +70 -17
  24. package/dist/commands/install/helpers/deleters.js +11 -2
  25. package/dist/commands/install/helpers/getters.js +30 -4
  26. package/dist/commands/install/helpers/index.js +48 -13
  27. package/dist/commands/install/helpers/inputs.js +98 -26
  28. package/dist/commands/install/helpers/regex.js +34 -29
  29. package/dist/commands/install/helpers/templates/awsTemplates.js +23 -6
  30. package/dist/commands/install/helpers/templates/azureTemplates.js +24 -5
  31. package/dist/commands/install/helpers/templates/edgeTemplates.js +38 -7
  32. package/dist/commands/install/helpers/templates/istioTemplates.js +16 -5
  33. package/dist/commands/install/index.js +10 -4
  34. package/dist/commands/install/istioAgents.js +117 -40
  35. package/dist/commands/install/platform.js +52 -20
  36. package/dist/commands/proxies/create.js +18 -2
  37. package/dist/commands/proxies/index.js +8 -4
  38. package/dist/commands/proxies/promote.js +21 -2
  39. package/dist/common/ApiServerClient.js +173 -64
  40. package/dist/common/CacheController.js +32 -11
  41. package/dist/common/CliConfigManager.js +27 -14
  42. package/dist/common/CompositeError.js +30 -6
  43. package/dist/common/CoreConfigController.js +40 -18
  44. package/dist/common/DefinitionsManager.js +76 -29
  45. package/dist/common/Kubectl.js +25 -2
  46. package/dist/common/PlatformClient.js +63 -19
  47. package/dist/common/Renderer.js +87 -25
  48. package/dist/common/TmpFile.js +28 -11
  49. package/dist/common/bashCommands.js +22 -3
  50. package/dist/common/basicPrompts.js +43 -8
  51. package/dist/common/dataService.js +50 -22
  52. package/dist/common/errorHandler.js +9 -0
  53. package/dist/common/resultsRenderers.js +42 -10
  54. package/dist/common/types.js +341 -116
  55. package/dist/common/utils.js +99 -37
  56. package/dist/main.js +2 -0
  57. package/package.json +2 -2
  58. package/dist/commands/install/gitHubSaasAgents.js +0 -283
@@ -4,30 +4,44 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DefinitionsManager = void 0;
7
+
7
8
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
+
8
10
  var _easyTable = _interopRequireDefault(require("easy-table"));
11
+
9
12
  var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
13
+
10
14
  var _findLastIndex = _interopRequireDefault(require("lodash/findLastIndex"));
15
+
11
16
  var _omit = _interopRequireDefault(require("lodash/omit"));
17
+
12
18
  var _max2 = _interopRequireDefault(require("lodash/max"));
19
+
13
20
  var _min2 = _interopRequireDefault(require("lodash/min"));
21
+
14
22
  var _chalk = require("chalk");
23
+
15
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
25
+
26
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
+
19
28
  const {
20
29
  log
21
30
  } = (0, _snooplogg.default)('central:class.DefinitionsManager');
31
+
22
32
  /**
23
33
  * Get / fetch / set specs.
24
34
  */
25
35
  class DefinitionsManager {
26
36
  constructor(apiServerClient) {
27
37
  _defineProperty(this, "apiServerClient", void 0);
38
+
28
39
  _defineProperty(this, "specs", void 0);
40
+
29
41
  _defineProperty(this, "cli", new Map());
42
+
30
43
  _defineProperty(this, "resources", new Map());
44
+
31
45
  this.apiServerClient = apiServerClient;
32
46
  }
33
47
  /**
@@ -45,68 +59,80 @@ class DefinitionsManager {
45
59
  * @param curr
46
60
  * @param defsFrom
47
61
  */
62
+
63
+
48
64
  reduceByReferenceLinks(curr, defsFrom) {
49
65
  return curr.unsorted.reduce((a, c, _, arr) => {
50
66
  // IF any unsorted reference found, push current definition to unsorted too and skip
51
67
  const unsortedRefs = c.spec.references.toResources.find(ref => {
52
68
  return (0, _findLastIndex.default)(arr, def => {
53
69
  var _def$spec$scope;
70
+
54
71
  return def.spec.kind === ref.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ref.scopeKind;
55
72
  }) !== -1;
56
73
  });
74
+
57
75
  if (!!unsortedRefs) {
58
76
  a.unsorted.push(c);
59
77
  } else {
60
78
  var _max, _min;
79
+
61
80
  // ELSE all refs are in pre populated or in sorted lists, calculate
62
81
  const startIndex = (_max = (0, _max2.default)(c.spec.references.toResources.map(ref => {
63
82
  // find index in current sorted array
64
83
  const sortedListIndex = (0, _findLastIndex.default)(a.sorted, def => {
65
84
  var _def$spec$scope2;
85
+
66
86
  return def.spec.kind === ref.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ref.scopeKind;
67
- });
68
- // find index in "from-only" array
87
+ }); // find index in "from-only" array
88
+
69
89
  const fromListIndex = (0, _findLastIndex.default)(defsFrom, def => {
70
90
  var _def$spec$scope3;
91
+
71
92
  return def.spec.kind === ref.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ref.scopeKind;
72
- });
73
- // this should never happen only if the api-server is missing some corresponding
93
+ }); // this should never happen only if the api-server is missing some corresponding
74
94
  // references so nothing found
95
+
75
96
  if (sortedListIndex === -1 && fromListIndex === -1) {
76
97
  var _c$spec$scope;
98
+
77
99
  log('reduceByReferenceLinks, startIndex error, def: ', JSON.stringify(c, null, 2), '\nref: ', ref);
78
100
  throw Error(`References calculation error, startIndex for kind: ${c.spec.kind} in scope: ${(_c$spec$scope = c.spec.scope) === null || _c$spec$scope === void 0 ? void 0 : _c$spec$scope.kind}`);
79
- }
80
- // if nothing found in sorted and pre return null so it will put it back to unsorted
101
+ } // if nothing found in sorted and pre return null so it will put it back to unsorted
81
102
  else return sortedListIndex === -1 ? 0 : sortedListIndex;
82
103
  }))) !== null && _max !== void 0 ? _max : null;
83
104
  const stopIndex = (_min = (0, _min2.default)(c.spec.references.fromResources.map(ref => {
84
105
  const i = (0, _findIndex.default)(a.sorted, def => {
85
106
  var _def$spec$scope4;
107
+
86
108
  return def.spec.kind === ref.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ref.scopeKind;
87
109
  });
88
110
  return i === -1 ? null : i;
89
111
  }))) !== null && _min !== void 0 ? _min : null;
112
+
90
113
  if (startIndex && stopIndex && startIndex >= stopIndex || startIndex === null) {
91
114
  var _c$spec$scope2;
115
+
92
116
  log('reduceByReferenceLinks, indexes error, definition: ', JSON.stringify(c, null, 2));
93
117
  throw Error(`References calculation error, indexes for kind: ${c.spec.kind} in scope: ${(_c$spec$scope2 = c.spec.scope) === null || _c$spec$scope2 === void 0 ? void 0 : _c$spec$scope2.kind}`);
94
118
  } else {
95
119
  a.sorted.splice(startIndex + 1, 0, c);
96
120
  }
97
121
  }
122
+
98
123
  return a;
99
124
  }, {
100
125
  sorted: curr.sorted,
101
126
  unsorted: []
102
127
  });
103
128
  }
104
-
105
129
  /**
106
130
  * Utility for sorting ResourceDefinition by refs. Its grouping resources into 4 arrays and
107
131
  * iterates over the "fromTo" list with "reduceByReferenceLinks" reducer until its completely sorted.
108
132
  * @param defs list of resources to sort
109
133
  */
134
+
135
+
110
136
  sortByReferences(defs) {
111
137
  // 1. Sort by references into 4 arrays
112
138
  const groupedDefs = defs.reduce((a, c) => {
@@ -119,24 +145,24 @@ class DefinitionsManager {
119
145
  from: [],
120
146
  fromTo: [],
121
147
  to: []
122
- });
148
+ }); // 2. Iterate over "fromTo" defs until its completely sorted
123
149
 
124
- // 2. Iterate over "fromTo" defs until its completely sorted
125
150
  let result = this.reduceByReferenceLinks({
126
151
  sorted: [],
127
152
  unsorted: groupedDefs.fromTo
128
153
  }, groupedDefs.from);
129
154
  let loopCount = 0; // just in case, circuit breaker;
155
+
130
156
  while (result.unsorted.length > 0 && loopCount <= 1000) {
131
157
  result = this.reduceByReferenceLinks(result, groupedDefs.from);
132
158
  loopCount += 1;
133
- }
134
- // On average function should not take more than 5 loops currently.
159
+ } // On average function should not take more than 5 loops currently.
135
160
  // Lets signal that something is wrong here.
161
+
162
+
136
163
  if (loopCount === 1000) throw Error('Definition references calculation error, max loop count reached');
137
164
  return [...groupedDefs.noRefs, ...groupedDefs.from, ...result.sorted, ...groupedDefs.to];
138
165
  }
139
-
140
166
  /**
141
167
  * Public
142
168
  * Constructs two maps per resource group(e.g. management, catalog)
@@ -144,20 +170,25 @@ class DefinitionsManager {
144
170
  * Created by stripping the 'definitions' group from the specs object, leaving only the 'management' and 'catalog' groups as of 6/7(this will dynamically update in case new groups are added on api-server)
145
171
  * Then iterating over that specs object and pushing the cli and resource objects for each group into arrays, which are used to initialize the final maps
146
172
  */
173
+
174
+
147
175
  async init() {
148
176
  log('init');
149
177
  this.specs = await this.apiServerClient.getSpecs();
150
178
  const filteredSpecs = (0, _omit.default)(this.specs, 'definitions');
151
179
  const cliArray = [];
152
180
  const resourcesArray = [];
181
+
153
182
  for (const [key] of Object.entries(filteredSpecs)) {
154
183
  resourcesArray.push(...filteredSpecs[key].resources);
155
184
  cliArray.push(...filteredSpecs[key].cli);
156
185
  }
186
+
157
187
  this.cli = new Map(cliArray);
158
188
  this.resources = new Map(resourcesArray);
159
189
  return this;
160
190
  }
191
+
161
192
  getAllWordsList() {
162
193
  if (!this.specs) return [];
163
194
  const result = [];
@@ -166,6 +197,7 @@ class DefinitionsManager {
166
197
  });
167
198
  return result;
168
199
  }
200
+
169
201
  getAllKindsList() {
170
202
  if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
171
203
  const result = new Set([]);
@@ -174,33 +206,37 @@ class DefinitionsManager {
174
206
  });
175
207
  return result;
176
208
  }
177
-
178
209
  /**
179
210
  * Get the map with resources definitions sorted by references.
180
211
  * Used to identify the correct order in which resources should be created / removed.
181
212
  * @returns {Map<string,ResourceDefinition>} map where key is ResourceDefinition.name, value is ResourceDefinition
182
213
  */
214
+
215
+
183
216
  getSortedKindsMap() {
184
- if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
185
- // For each spec modify the references:
217
+ if (!this.specs) throw Error('DefinitionManager.specs is not initialized.'); // For each spec modify the references:
186
218
  // 1. since cli do not support creating or updating sub-resources we are ignoring references and removing them atm.
187
219
  // 2. if it is a scoped resource, add a manual "to" reference to the scope resource and a corresponding "from"
188
220
  // reference in the scope resource
221
+
189
222
  this.resources.forEach(definition => {
190
223
  // 1. remove the references from the sub-resources and circular references (to self)
191
224
  // TODO: circular references support: https://jira.axway.com/browse/APIGOV-20808
192
225
  definition.spec.references.toResources = definition.spec.references.toResources.filter(ref => {
193
226
  var _definition$spec$scop;
227
+
194
228
  return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop = definition.spec.scope) === null || _definition$spec$scop === void 0 ? void 0 : _definition$spec$scop.kind));
195
229
  });
196
230
  definition.spec.references.fromResources = definition.spec.references.fromResources.filter(ref => {
197
231
  var _definition$spec$scop2;
232
+
198
233
  return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop2 = definition.spec.scope) === null || _definition$spec$scop2 === void 0 ? void 0 : _definition$spec$scop2.kind));
199
- });
200
- // 2. add references between scope and scoped resources
234
+ }); // 2. add references between scope and scoped resources
235
+
201
236
  if (!!definition.spec.scope) {
202
237
  const scopeDef = [...this.resources.values()].find(res => res.spec.kind === definition.spec.scope.kind); // mind the non-null assertion here
203
238
  // modify current definition by adding "toResources" link to scopeDef
239
+
204
240
  if (!definition.spec.references.toResources.find(ref => ref.kind === scopeDef.spec.kind)) {
205
241
  definition.spec.references.toResources.push({
206
242
  kind: scopeDef.spec.kind,
@@ -208,8 +244,9 @@ class DefinitionsManager {
208
244
  // NOTE: not used value, adding just to indicate it's manual nature.
209
245
  types: ['CALCULATED']
210
246
  });
211
- }
212
- // modify related "scope" definition by adding "fromResources" link to current definition
247
+ } // modify related "scope" definition by adding "fromResources" link to current definition
248
+
249
+
213
250
  if (!scopeDef.spec.references.fromResources.find(ref => ref.kind === definition.spec.kind)) {
214
251
  scopeDef.spec.references.fromResources.push({
215
252
  kind: definition.spec.kind,
@@ -220,18 +257,19 @@ class DefinitionsManager {
220
257
  });
221
258
  }
222
259
  }
223
- });
224
- // execute the sorting, note that the returning map is using the "name" field as keys.
260
+ }); // execute the sorting, note that the returning map is using the "name" field as keys.
261
+
225
262
  const res = this.sortByReferences([...this.resources.values()]);
226
263
  return new Map(res.map(v => [v.name, v]));
227
264
  }
265
+
228
266
  getDefsTableForHelpMsg() {
229
267
  if (!this.specs) return 'No resources found.';
230
- const t = new _easyTable.default();
268
+ const t = new _easyTable.default(); // create the 'axway central get' table
231
269
 
232
- // create the 'axway central get' table
233
270
  this.cli.forEach(v => {
234
271
  var _this$resources$get, _this$resources$get2, _this$resources, _this$resources$get3, _this$resources$get3$;
272
+
235
273
  // grab the resource group
236
274
  const group = v.metadata.scope.name;
237
275
  t.cell('RESOURCE', `${v.spec.names.plural}`, () => (0, _chalk.cyan)(v.spec.names.plural));
@@ -244,6 +282,7 @@ class DefinitionsManager {
244
282
  });
245
283
  return t.sort(['RESOURCE']).toString();
246
284
  }
285
+
247
286
  findDefsByKind(kind) {
248
287
  log('findDefsByKind: ', kind);
249
288
  const res = [...this.resources].reduce((a, [_, def]) => {
@@ -254,11 +293,11 @@ class DefinitionsManager {
254
293
  scope: def.spec.scope ? [...this.resources].find(([_, resDef]) => resDef.spec.kind === def.spec.scope.kind)[1] : undefined
255
294
  });
256
295
  }
296
+
257
297
  return a;
258
298
  }, []);
259
299
  return res.length ? res : null;
260
300
  }
261
-
262
301
  /**
263
302
  * Returns set of related definitions if word is known.
264
303
  * @param word word to search for
@@ -268,19 +307,24 @@ class DefinitionsManager {
268
307
  * scope: scope resource definition, can support multiple scopes (only for scoped resources, otherwise it is undefined)
269
308
  * } or null if no definitions found for this word.
270
309
  */
310
+
311
+
271
312
  findDefsByWord(word) {
272
313
  log('findDefsByWord: ', word);
273
314
  if (!this.specs) return null;
274
315
  const cliKv = [...this.cli].filter(([_, v]) => {
275
316
  var _v$spec$names$shortNa;
317
+
276
318
  return v.spec.names.plural === word || v.spec.names.singular === word || v.spec.names.shortNames.includes(word) || ((_v$spec$names$shortNa = v.spec.names.shortNamesAlias) === null || _v$spec$names$shortNa === void 0 ? void 0 : _v$spec$names$shortNa.includes(word));
277
- });
278
- // no match found returning null
319
+ }); // no match found returning null
320
+
279
321
  if (!cliKv.length) return null;
280
322
  const result = [...this.cli].reduce((a, [_, cliDef]) => {
281
323
  var _cliDef$spec$names$sh;
324
+
282
325
  if (cliDef.spec.names.plural === word || cliDef.spec.names.singular === word || cliDef.spec.names.shortNames.includes(word) || (_cliDef$spec$names$sh = cliDef.spec.names.shortNamesAlias) !== null && _cliDef$spec$names$sh !== void 0 && _cliDef$spec$names$sh.includes(word)) {
283
326
  var _this$findDefsByKind;
327
+
284
328
  // note: mind non-null assertion
285
329
  const resource = this.resources.get(cliDef.spec.resourceDefinition);
286
330
  const scope = resource.spec.scope ? (_this$findDefsByKind = this.findDefsByKind(resource.spec.scope.kind)) === null || _this$findDefsByKind === void 0 ? void 0 : _this$findDefsByKind[0].resource : null;
@@ -290,9 +334,12 @@ class DefinitionsManager {
290
334
  scope: !!scope ? scope : undefined
291
335
  });
292
336
  }
337
+
293
338
  return a;
294
339
  }, []);
295
340
  return result;
296
341
  }
342
+
297
343
  }
344
+
298
345
  exports.DefinitionsManager = DefinitionsManager;
@@ -4,29 +4,43 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.kubectl = exports.exec = void 0;
7
+
7
8
  var _child_process = require("child_process");
9
+
8
10
  var _cliKit = require("cli-kit");
11
+
9
12
  var _util = _interopRequireDefault(require("util"));
13
+
10
14
  var _utils = require("./utils");
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  const quotes = _utils.isWindows ? '"' : "'";
13
19
  const {
14
20
  log
15
21
  } = (0, _cliKit.snooplogg)('central: kubectl');
16
- const exec = exports.exec = _util.default.promisify(_child_process.exec);
22
+
23
+ const exec = _util.default.promisify(_child_process.exec);
24
+
25
+ exports.exec = exec;
26
+
17
27
  class Kubectl {
18
28
  async get(resource, args) {
19
29
  return await this.invoke('get', resource, args);
20
30
  }
31
+
21
32
  async create(resource, args) {
22
33
  return await this.invoke('create', resource, args);
23
34
  }
35
+
24
36
  async delete(resource, args) {
25
37
  return await this.invoke('delete', resource, args);
26
38
  }
39
+
27
40
  async isInstalled() {
28
41
  return await this.execKubectl('version', 'version');
29
42
  }
43
+
30
44
  async invoke(action, resource, args) {
31
45
  const obj = {
32
46
  error: null,
@@ -36,23 +50,28 @@ class Kubectl {
36
50
  logMsg = args ? logMsg += ` ${args}` : logMsg;
37
51
  log(logMsg);
38
52
  const res = await this.execKubectl(`${action} ${resource} ${args || ''}`, resource);
53
+
39
54
  if (res.error) {
40
55
  obj.error = res.error;
41
56
  log(`command failed: ${res.error}`);
42
57
  return obj;
43
58
  }
59
+
44
60
  obj.data = this.cleanResponse(res.data);
45
61
  log('command success');
46
62
  return obj;
47
63
  }
64
+
48
65
  async execKubectl(action, resource) {
49
66
  let {
50
67
  stdout,
51
68
  stderr
52
69
  } = await exec(`kubectl ${action} | awk ${quotes}{print $1}${quotes}`);
70
+
53
71
  if (stderr.includes('WARNING')) {
54
72
  stderr = '';
55
73
  }
74
+
56
75
  return stderr ? {
57
76
  data: null,
58
77
  error: `K8S ${resource}: ${stderr}`
@@ -61,8 +80,12 @@ class Kubectl {
61
80
  error: null
62
81
  };
63
82
  }
83
+
64
84
  cleanResponse(res) {
65
85
  return res.split('\n').filter(str => str !== 'NAME' && str != '').sort();
66
86
  }
87
+
67
88
  }
68
- const kubectl = exports.kubectl = new Kubectl();
89
+
90
+ const kubectl = new Kubectl();
91
+ exports.kubectl = kubectl;
@@ -4,25 +4,42 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PlatformTeamMemberRole = exports.PlatformServiceAccountRole = exports.PlatformClient = exports.PlatformAuthMethod = void 0;
7
+
7
8
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
+
8
10
  var _amplifyCliUtils = require("@axway/amplify-cli-utils");
11
+
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
15
+
11
16
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
17
+
12
18
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
19
+
13
20
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
21
+
14
22
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
23
+
15
24
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
25
+
16
26
  function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
27
+
17
28
  const {
18
29
  log
19
30
  } = (0, _snooplogg.default)('central:class.PlatformClient');
20
- let PlatformAuthMethod = exports.PlatformAuthMethod = /*#__PURE__*/function (PlatformAuthMethod) {
31
+ let PlatformAuthMethod;
32
+ exports.PlatformAuthMethod = PlatformAuthMethod;
33
+
34
+ (function (PlatformAuthMethod) {
21
35
  PlatformAuthMethod["Certificate"] = "certificate";
22
36
  PlatformAuthMethod["Secret"] = "secret";
23
- return PlatformAuthMethod;
24
- }({});
25
- let PlatformServiceAccountRole = exports.PlatformServiceAccountRole = /*#__PURE__*/function (PlatformServiceAccountRole) {
37
+ })(PlatformAuthMethod || (exports.PlatformAuthMethod = PlatformAuthMethod = {}));
38
+
39
+ let PlatformServiceAccountRole;
40
+ exports.PlatformServiceAccountRole = PlatformServiceAccountRole;
41
+
42
+ (function (PlatformServiceAccountRole) {
26
43
  PlatformServiceAccountRole["ApiCentralAdmin"] = "api_central_admin";
27
44
  PlatformServiceAccountRole["FlowCentralAccessManager"] = "fc_access_manager";
28
45
  PlatformServiceAccountRole["FlowCentralIntegration"] = "fc_integration";
@@ -33,21 +50,26 @@ let PlatformServiceAccountRole = exports.PlatformServiceAccountRole = /*#__PURE_
33
50
  PlatformServiceAccountRole["FlowCentralSubscriptionSpecialist"] = "fc_subscriptionspecialist";
34
51
  PlatformServiceAccountRole["FlowCentralTemplatePublisher"] = "fc_templatepublisher";
35
52
  PlatformServiceAccountRole["FlowCentralCftAdmin"] = "fc_cft_admin";
36
- return PlatformServiceAccountRole;
37
- }({});
38
- let PlatformTeamMemberRole = exports.PlatformTeamMemberRole = /*#__PURE__*/function (PlatformTeamMemberRole) {
53
+ })(PlatformServiceAccountRole || (exports.PlatformServiceAccountRole = PlatformServiceAccountRole = {}));
54
+
55
+ let PlatformTeamMemberRole;
56
+ exports.PlatformTeamMemberRole = PlatformTeamMemberRole;
57
+
58
+ (function (PlatformTeamMemberRole) {
39
59
  PlatformTeamMemberRole["Admin"] = "administrator";
40
60
  PlatformTeamMemberRole["Developer"] = "developer";
41
61
  PlatformTeamMemberRole["Consumer"] = "consumer";
42
62
  PlatformTeamMemberRole["CatalogManager"] = "catalog_manager";
43
- return PlatformTeamMemberRole;
44
- }({});
45
- /** Options used to create a service account via the PlatformClient.createServiceAccount() method. */
46
- /** Provides information for a platform service account. */
63
+ })(PlatformTeamMemberRole || (exports.PlatformTeamMemberRole = PlatformTeamMemberRole = {}));
64
+
47
65
  var _baseUrl = /*#__PURE__*/new WeakMap();
66
+
48
67
  var _accountName = /*#__PURE__*/new WeakMap();
68
+
49
69
  var _amplifyConfig = /*#__PURE__*/new WeakMap();
70
+
50
71
  var _amplifySdk = /*#__PURE__*/new WeakMap();
72
+
51
73
  class PlatformClient {
52
74
  constructor({
53
75
  baseUrl,
@@ -58,85 +80,107 @@ class PlatformClient {
58
80
  writable: true,
59
81
  value: void 0
60
82
  });
83
+
61
84
  _classPrivateFieldInitSpec(this, _accountName, {
62
85
  writable: true,
63
86
  value: void 0
64
87
  });
88
+
65
89
  _classPrivateFieldInitSpec(this, _amplifyConfig, {
66
90
  writable: true,
67
91
  value: void 0
68
92
  });
93
+
69
94
  _classPrivateFieldInitSpec(this, _amplifySdk, {
70
95
  writable: true,
71
96
  value: void 0
72
97
  });
98
+
73
99
  log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
100
+
74
101
  _classPrivateFieldSet(this, _baseUrl, baseUrl);
102
+
75
103
  _classPrivateFieldSet(this, _accountName, account);
104
+
76
105
  const initResult = (0, _amplifyCliUtils.initSDK)({
77
106
  baseUrl: _classPrivateFieldGet(this, _baseUrl),
78
107
  username: _classPrivateFieldGet(this, _accountName)
79
108
  });
109
+
80
110
  _classPrivateFieldSet(this, _amplifyConfig, initResult.config);
111
+
81
112
  _classPrivateFieldSet(this, _amplifySdk, initResult.sdk);
82
113
  }
114
+
83
115
  async getAccountInfo() {
84
116
  var _classPrivateFieldGet2;
117
+
85
118
  // Get default teams from config.
86
- const defaultTeams = _classPrivateFieldGet(this, _amplifyConfig).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _amplifySdk).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`);
119
+ const defaultTeams = _classPrivateFieldGet(this, _amplifyConfig).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _amplifySdk).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`); // Fetch specified account or default account currently logged in.
120
+
87
121
 
88
- // Fetch specified account or default account currently logged in.
89
122
  let accountInfo;
123
+
90
124
  if (_classPrivateFieldGet(this, _accountName)) {
91
125
  accountInfo = await _classPrivateFieldGet(this, _amplifySdk).auth.find(_classPrivateFieldGet(this, _accountName), defaultTeams);
126
+
92
127
  if (!accountInfo) {
93
128
  throw new Error(`Account "${_classPrivateFieldGet(this, _accountName)}" not found`);
94
129
  }
95
130
  }
131
+
96
132
  if (!accountInfo) {
97
133
  const accountArray = await _classPrivateFieldGet(this, _amplifySdk).auth.list({
98
134
  defaultTeams,
99
135
  validate: true
100
136
  });
137
+
101
138
  if (accountArray) {
102
139
  accountInfo = accountArray.find(nextAccount => nextAccount.default) || accountArray[0];
103
140
  }
104
- }
141
+ } // Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
142
+
105
143
 
106
- // Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
107
144
  if (accountInfo && accountInfo.org && !accountInfo.org.subscriptions) {
108
145
  accountInfo.org.subscriptions = [];
109
- }
146
+ } // Return account info if found.
147
+
110
148
 
111
- // Return account info if found.
112
149
  return accountInfo;
113
150
  }
151
+
114
152
  async createServiceAccount(options) {
115
153
  const accountInfo = await this.getAccountInfo();
116
154
  const result = await _classPrivateFieldGet(this, _amplifySdk).client.create(accountInfo, accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.org, options);
117
155
  return result.client;
118
156
  }
157
+
119
158
  async getServiceAccounts(filterRole) {
120
159
  const result = await _classPrivateFieldGet(this, _amplifySdk).client.list(await this.getAccountInfo());
121
160
  let clients = result.clients || [];
161
+
122
162
  if (filterRole) {
123
163
  log('filter clients by ', filterRole);
124
164
  clients = clients.filter(client => client === null || client === void 0 ? void 0 : client.roles.find(r => r === filterRole));
125
165
  }
166
+
126
167
  return clients;
127
168
  }
169
+
128
170
  async getTeams() {
129
171
  var _account$team, _teams$find;
172
+
130
173
  log(`getTeams`);
131
174
  const account = await this.getAccountInfo();
132
175
  const {
133
176
  teams
134
177
  } = await _classPrivateFieldGet(this, _amplifySdk).team.list(account);
135
178
  const teamGuid = ((_account$team = account.team) === null || _account$team === void 0 ? void 0 : _account$team.guid) && ((_teams$find = teams.find(team => team.guid === account.team.guid)) === null || _teams$find === void 0 ? void 0 : _teams$find.guid);
136
- return teams.map(team => ({
137
- ...team,
179
+ return teams.map(team => ({ ...team,
138
180
  default: teamGuid && team.guid === teamGuid || !teamGuid && team.default
139
181
  }));
140
182
  }
183
+
141
184
  }
185
+
142
186
  exports.PlatformClient = PlatformClient;