@webex/webex-core 3.8.1 → 3.9.0-multi-llms.2

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 (89) hide show
  1. package/README.md +87 -27
  2. package/dist/index.js +16 -33
  3. package/dist/index.js.map +1 -1
  4. package/dist/{lib/services/interceptors/hostmap.js → interceptors/proxy.js} +58 -25
  5. package/dist/interceptors/proxy.js.map +1 -0
  6. package/dist/lib/batcher.js +1 -1
  7. package/dist/lib/constants.js +10 -1
  8. package/dist/lib/constants.js.map +1 -1
  9. package/dist/lib/credentials/credentials.js +1 -1
  10. package/dist/lib/credentials/token.js +1 -1
  11. package/dist/lib/{services-v2/interceptors → interceptors}/server-error.js +1 -1
  12. package/dist/lib/interceptors/server-error.js.map +1 -0
  13. package/dist/lib/services/index.js +2 -29
  14. package/dist/lib/services/index.js.map +1 -1
  15. package/dist/lib/services/service-host.js +1 -1
  16. package/dist/lib/services/service-host.js.map +1 -1
  17. package/dist/lib/services/service-registry.js +1 -1
  18. package/dist/lib/services/service-registry.js.map +1 -1
  19. package/dist/lib/services/service-state.js +1 -1
  20. package/dist/lib/services/service-state.js.map +1 -1
  21. package/dist/lib/services/services.js +3 -3
  22. package/dist/lib/services/services.js.map +1 -1
  23. package/dist/lib/services-v2/index.js +0 -29
  24. package/dist/lib/services-v2/index.js.map +1 -1
  25. package/dist/lib/services-v2/metrics.js.map +1 -1
  26. package/dist/lib/services-v2/service-catalog.js +15 -11
  27. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  28. package/dist/lib/services-v2/services-v2.js +160 -111
  29. package/dist/lib/services-v2/services-v2.js.map +1 -1
  30. package/dist/lib/services-v2/types.js.map +1 -1
  31. package/dist/plugins/logger.js +1 -1
  32. package/dist/webex-core.js +53 -60
  33. package/dist/webex-core.js.map +1 -1
  34. package/package.json +14 -14
  35. package/src/index.js +6 -14
  36. package/src/interceptors/proxy.js +70 -0
  37. package/src/lib/constants.js +29 -1
  38. package/src/lib/{services/interceptors → interceptors}/server-error.js +1 -1
  39. package/src/lib/services/index.js +2 -7
  40. package/src/lib/services/service-host.js +1 -1
  41. package/src/lib/services/service-registry.js +1 -1
  42. package/src/lib/services/service-state.js +1 -1
  43. package/src/lib/services/services.js +2 -2
  44. package/src/lib/services-v2/index.ts +0 -16
  45. package/src/lib/services-v2/service-catalog.ts +27 -19
  46. package/src/lib/services-v2/{services-v2.js → services-v2.ts} +188 -104
  47. package/src/lib/services-v2/types.ts +62 -2
  48. package/src/webex-core.js +12 -3
  49. package/test/fixtures/host-catalog-v2.ts +30 -122
  50. package/test/integration/spec/services/services.js +11 -0
  51. package/test/integration/spec/services-v2/service-catalog.js +664 -0
  52. package/test/integration/spec/services-v2/services-v2.js +1136 -0
  53. package/test/unit/spec/interceptors/proxy.js +73 -0
  54. package/test/unit/spec/services-v2/service-detail.ts +1 -1
  55. package/test/unit/spec/services-v2/services-v2.ts +579 -442
  56. package/test/unit/spec/webex-core.js +62 -2
  57. package/dist/lib/services/constants.js +0 -17
  58. package/dist/lib/services/constants.js.map +0 -1
  59. package/dist/lib/services/interceptors/hostmap.js.map +0 -1
  60. package/dist/lib/services/interceptors/server-error.js +0 -77
  61. package/dist/lib/services/interceptors/server-error.js.map +0 -1
  62. package/dist/lib/services/interceptors/service.js +0 -137
  63. package/dist/lib/services/interceptors/service.js.map +0 -1
  64. package/dist/lib/services-v2/constants.js +0 -17
  65. package/dist/lib/services-v2/constants.js.map +0 -1
  66. package/dist/lib/services-v2/interceptors/server-error.js.map +0 -1
  67. package/dist/lib/services-v2/service-host.js +0 -300
  68. package/dist/lib/services-v2/service-host.js.map +0 -1
  69. package/dist/lib/services-v2/service-registry.js +0 -534
  70. package/dist/lib/services-v2/service-registry.js.map +0 -1
  71. package/dist/lib/services-v2/service-state.js +0 -97
  72. package/dist/lib/services-v2/service-state.js.map +0 -1
  73. package/dist/lib/services-v2/service-url.js +0 -119
  74. package/dist/lib/services-v2/service-url.js.map +0 -1
  75. package/src/lib/services/constants.js +0 -21
  76. package/src/lib/services/interceptors/hostmap.js +0 -36
  77. package/src/lib/services/interceptors/service.js +0 -101
  78. package/src/lib/services-v2/constants.ts +0 -21
  79. package/src/lib/services-v2/interceptors/server-error.js +0 -48
  80. /package/dist/lib/{services-v2/interceptors → interceptors}/hostmap.js +0 -0
  81. /package/dist/lib/{services-v2/interceptors → interceptors}/hostmap.js.map +0 -0
  82. /package/dist/lib/{services-v2/interceptors → interceptors}/service.js +0 -0
  83. /package/dist/lib/{services-v2/interceptors → interceptors}/service.js.map +0 -0
  84. /package/dist/lib/{services/metrics.js → metrics.js} +0 -0
  85. /package/dist/lib/{services/metrics.js.map → metrics.js.map} +0 -0
  86. /package/src/lib/{services-v2/interceptors → interceptors}/hostmap.js +0 -0
  87. /package/src/lib/{services-v2/interceptors → interceptors}/service.js +0 -0
  88. /package/src/lib/{services-v2/metrics.js → metrics.js} +0 -0
  89. /package/src/lib/{services/metrics.js → services-v2/metrics.ts} +0 -0
@@ -16,13 +16,14 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/he
16
16
  var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
17
17
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
18
18
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
19
+ var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
19
20
  var _sha = _interopRequireDefault(require("crypto-js/sha256"));
20
21
  var _lodash = require("lodash");
21
22
  var _webexPlugin = _interopRequireDefault(require("../webex-plugin"));
22
- var _metrics = _interopRequireDefault(require("./metrics"));
23
+ var _metrics = _interopRequireDefault(require("../metrics"));
23
24
  var _serviceCatalog = _interopRequireDefault(require("./service-catalog"));
24
25
  var _serviceFedRamp = _interopRequireDefault(require("./service-fed-ramp"));
25
- var _constants = require("./constants");
26
+ var _constants = require("../constants");
26
27
  function ownKeys(e, r) { var t = _Object$keys2(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
28
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
28
29
  var trailingSlashes = /(?:^\/)|(?:\/$)/;
@@ -51,7 +52,7 @@ var Services = _webexPlugin.default.extend({
51
52
  * @private
52
53
  * Get the current catalog based on the assocaited
53
54
  * webex instance.
54
- * @returns {ServiceCatalog}
55
+ * @returns {IServiceCatalog}
55
56
  */
56
57
  _getCatalog: function _getCatalog() {
57
58
  return this._catalogs.get(this.webex);
@@ -60,13 +61,20 @@ var Services = _webexPlugin.default.extend({
60
61
  * Get a service url from the current services list by name
61
62
  * from the associated instance catalog.
62
63
  * @param {string} name
63
- * @param {boolean} [priorityHost]
64
- * @param {string} [serviceGroup]
64
+ * @param {ServiceGroup} [serviceGroup]
65
65
  * @returns {string|undefined}
66
66
  */
67
- get: function get(name, priorityHost, serviceGroup) {
67
+ get: function get(name, serviceGroup) {
68
68
  var catalog = this._getCatalog();
69
- return catalog.get(name, priorityHost, serviceGroup);
69
+ var clusterId = this._activeServices[name];
70
+ var urlById = catalog.get(clusterId, serviceGroup);
71
+ var urlByName = catalog.get(name, serviceGroup);
72
+
73
+ // if both are undefined, then we cannot find the service
74
+ if (!urlById && !urlByName) {
75
+ return undefined;
76
+ }
77
+ return urlById || urlByName;
70
78
  },
71
79
  /**
72
80
  * Determine if a whilelist exists in the service catalog.
@@ -77,37 +85,22 @@ var Services = _webexPlugin.default.extend({
77
85
  var catalog = this._getCatalog();
78
86
  return catalog.getAllowedDomains().length > 0;
79
87
  },
80
- /**
81
- * Generate a service catalog as an object from
82
- * the associated instance catalog.
83
- * @param {boolean} [priorityHost] - use highest priority host if set to `true`
84
- * @param {string} [serviceGroup]
85
- * @returns {Record<string, string>}
86
- */
87
- list: function list(priorityHost, serviceGroup) {
88
- var catalog = this._getCatalog();
89
- return catalog.list(priorityHost, serviceGroup);
90
- },
91
88
  /**
92
89
  * Mark a priority host service url as failed.
93
- * This will mark the host associated with the
94
- * `ServiceUrl` to be removed from the its
95
- * respective host array, and then return the next
96
- * viable host from the `ServiceUrls` host array,
97
- * or the `ServiceUrls` default url if no other priority
98
- * hosts are available, or if `noPriorityHosts` is set to
99
- * `true`.
90
+ * This will mark the service url associated with the
91
+ * `ServiceDetail` to be removed from the its
92
+ * respective service url array, and then return the next
93
+ * viable service url from the `ServiceDetail` service url array.
100
94
  * @param {string} url
101
- * @param {boolean} noPriorityHosts
102
95
  * @returns {string}
103
96
  */
104
- markFailedUrl: function markFailedUrl(url, noPriorityHosts) {
97
+ markFailedUrl: function markFailedUrl(url) {
105
98
  var catalog = this._getCatalog();
106
- return catalog.markFailedUrl(url, noPriorityHosts);
99
+ return catalog.markFailedServiceUrl(url);
107
100
  },
108
101
  /**
109
102
  * saves all the services from the pre and post catalog service
110
- * @param {Object} activeServices
103
+ * @param {ActiveServices} activeServices
111
104
  * @returns {void}
112
105
  */
113
106
  _updateActiveServices: function _updateActiveServices(activeServices) {
@@ -115,7 +108,7 @@ var Services = _webexPlugin.default.extend({
115
108
  },
116
109
  /**
117
110
  * saves the hostCatalog object
118
- * @param {Object} services
111
+ * @param {Array<Service>} services
119
112
  * @returns {void}
120
113
  */
121
114
  _updateServices: function _updateServices(services) {
@@ -135,7 +128,9 @@ var Services = _webexPlugin.default.extend({
135
128
  * @returns {Promise<object>}
136
129
  */
137
130
  updateServices: function updateServices() {
138
- var _this = this;
131
+ var _catalog$status,
132
+ _catalog$status$servi,
133
+ _this = this;
139
134
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
140
135
  from = _ref.from,
141
136
  query = _ref.query,
@@ -157,9 +152,8 @@ var Services = _webexPlugin.default.extend({
157
152
  serviceGroup = 'postauth';
158
153
  break;
159
154
  }
160
-
161
155
  // confirm catalog update for group is not in progress.
162
- if (catalog.status[serviceGroup].collecting) {
156
+ if ((_catalog$status = catalog.status) !== null && _catalog$status !== void 0 && (_catalog$status$servi = _catalog$status[serviceGroup]) !== null && _catalog$status$servi !== void 0 && _catalog$status$servi.collecting) {
163
157
  return this.waitForCatalog(serviceGroup);
164
158
  }
165
159
  catalog.status[serviceGroup].collecting = true;
@@ -185,7 +179,7 @@ var Services = _webexPlugin.default.extend({
185
179
  query: formattedQuery,
186
180
  forceRefresh: forceRefresh
187
181
  }).then(function (serviceHostMap) {
188
- catalog.updateServiceGroups(serviceGroup, serviceHostMap);
182
+ catalog.updateServiceGroups(serviceGroup, serviceHostMap === null || serviceHostMap === void 0 ? void 0 : serviceHostMap.services, serviceHostMap === null || serviceHostMap === void 0 ? void 0 : serviceHostMap.timestamp);
189
183
  _this.updateCredentialsConfig();
190
184
  catalog.status[serviceGroup].collecting = false;
191
185
  }).catch(function (error) {
@@ -282,7 +276,7 @@ var Services = _webexPlugin.default.extend({
282
276
  // Retrieve the service url from the updated catalog. This is required
283
277
  // since `WebexCore` is usually not fully initialized at the time this
284
278
  // request completes.
285
- var idbrokerService = _this2.get('idbroker', true);
279
+ var idbrokerService = _this2.get('idbroker');
286
280
 
287
281
  // Collect the client auth token.
288
282
  return _this2.webex.credentials.getClientToken({
@@ -339,22 +333,68 @@ var Services = _webexPlugin.default.extend({
339
333
  return _promise.default.reject(response);
340
334
  });
341
335
  },
336
+ /**
337
+ * Update cluster id via mercury service update. If the cluster id does not exist,
338
+ * fetch new catalog.
339
+ *
340
+ * @param {ActiveServices} newActiveClusters - The new active clusters to switch to.
341
+ * @returns {Promsie<void>}
342
+ * */
343
+ switchActiveClusterIds: function switchActiveClusterIds(newActiveClusters) {
344
+ var _this3 = this;
345
+ this.logger.info('services: switching active cluster ids');
346
+ var newActiveClusterIds = (0, _values.default)(newActiveClusters);
347
+ var missingClusterIds = newActiveClusterIds.some(function (clusterId) {
348
+ // if the clusterId does not exist in the catalog, fetch the catalog
349
+ return !_this3._services.find(function (service) {
350
+ return service.id === clusterId;
351
+ });
352
+ });
353
+ if (missingClusterIds) {
354
+ this.logger.warn('services: some cluster ids do not exist in the catalog, fetching the catalog');
355
+
356
+ // fetch the catalog
357
+ return this.initServiceCatalogs(true);
358
+ }
359
+ // update the active services
360
+ this._updateActiveServices(newActiveClusters);
361
+ this.logger.info('services: active cluster ids updated successfully');
362
+ return _promise.default.resolve();
363
+ },
364
+ /**
365
+ * Invalidate cache via mercury notification. If the timestamp is newer than current,
366
+ * refetch catalog services.
367
+ *
368
+ * @param {string} timestamp - The timestamp of invalidation notification.
369
+ * @returns {Promsie<void>}
370
+ * */
371
+ invalidateCache: function invalidateCache(timestamp) {
372
+ var _this$_getCatalog;
373
+ this.logger.info('services: invalidate cache, timestamp:', timestamp);
374
+ var lastTime = (0, _lodash.toNumber)((_this$_getCatalog = this._getCatalog()) === null || _this$_getCatalog === void 0 ? void 0 : _this$_getCatalog.timestamp) || 0;
375
+ var invalidateTime = (0, _lodash.toNumber)(timestamp) || 0;
376
+ if (invalidateTime > lastTime) {
377
+ this.logger.info('services: invalidateCache, refresh services');
378
+ this.initServiceCatalogs(true);
379
+ }
380
+ return _promise.default.resolve();
381
+ },
342
382
  /**
343
383
  * Get user meeting preferences (preferred webex site).
344
384
  *
345
385
  * @returns {object} - User Information including user preferrences .
346
386
  */
347
387
  getMeetingPreferences: function getMeetingPreferences() {
348
- var _this3 = this;
388
+ var _this4 = this;
349
389
  return this.request({
350
390
  method: 'GET',
351
391
  service: 'hydra',
352
392
  resource: 'meetingPreferences'
353
393
  }).then(function (res) {
354
- _this3.logger.info('services: received user region info');
394
+ _this4.logger.info('services: received user region info');
355
395
  return res.body;
356
396
  }).catch(function (err) {
357
- _this3.logger.info('services: was not able to fetch user login information', err);
397
+ _this4.logger.info('services: was not able to fetch user login information', err);
358
398
  // resolve successfully even if request failed
359
399
  });
360
400
  },
@@ -364,7 +404,7 @@ var Services = _webexPlugin.default.extend({
364
404
  * @returns {object} - The region info object.
365
405
  */
366
406
  fetchClientRegionInfo: function fetchClientRegionInfo() {
367
- var _this4 = this;
407
+ var _this5 = this;
368
408
  var services = this.webex.config.services;
369
409
  return this.request({
370
410
  uri: services.discovery.sqdiscovery,
@@ -374,10 +414,10 @@ var Services = _webexPlugin.default.extend({
374
414
  },
375
415
  timeout: 5000
376
416
  }).then(function (res) {
377
- _this4.logger.info('services: received user region info');
417
+ _this5.logger.info('services: received user region info');
378
418
  return res.body;
379
419
  }).catch(function (err) {
380
- _this4.logger.info('services: was not able to get user region info', err);
420
+ _this5.logger.info('services: was not able to get user region info', err);
381
421
  // resolve successfully even if request failed
382
422
  });
383
423
  },
@@ -397,7 +437,7 @@ var Services = _webexPlugin.default.extend({
397
437
  * @returns {LicenseDTO} - The DTO returned from the **License** service.
398
438
  */
399
439
  sendUserActivation: function sendUserActivation(_ref5) {
400
- var _this5 = this;
440
+ var _this6 = this;
401
441
  var email = _ref5.email,
402
442
  reqId = _ref5.reqId,
403
443
  token = _ref5.token,
@@ -415,7 +455,7 @@ var Services = _webexPlugin.default.extend({
415
455
  }
416
456
 
417
457
  // Send the user activation request to the **License** service.
418
- return _this5.request({
458
+ return _this6.request({
419
459
  service: 'license',
420
460
  resource: 'users/activations',
421
461
  method: 'POST',
@@ -445,14 +485,14 @@ var Services = _webexPlugin.default.extend({
445
485
  },
446
486
  /**
447
487
  * Updates a given service group i.e. preauth, signin, postauth with a new hostmap.
448
- * @param {string} serviceGroup - preauth, signin, postauth
449
- * @param {object} hostMap - The new hostmap to update the service group with.
488
+ * @param {ServiceGroup} serviceGroup - preauth, signin, postauth
489
+ * @param {ServiceHostmap} hostMap - The new hostmap to update the service group with.
450
490
  * @returns {Promise<void>}
451
491
  */
452
492
  updateCatalog: function updateCatalog(serviceGroup, hostMap) {
453
493
  var catalog = this._getCatalog();
454
494
  var serviceHostMap = this._formatReceivedHostmap(hostMap);
455
- return catalog.updateServiceGroups(serviceGroup, serviceHostMap);
495
+ return catalog.updateServiceGroups(serviceGroup, serviceHostMap === null || serviceHostMap === void 0 ? void 0 : serviceHostMap.services, serviceHostMap === null || serviceHostMap === void 0 ? void 0 : serviceHostMap.timestamp);
456
496
  },
457
497
  /**
458
498
  * simplified method to update the preauth catalog via email
@@ -513,25 +553,24 @@ var Services = _webexPlugin.default.extend({
513
553
  * @returns {void}
514
554
  */
515
555
  updateCredentialsConfig: function updateCredentialsConfig() {
516
- var _this$list = this.list(true),
517
- idbroker = _this$list.idbroker,
518
- identity = _this$list.identity;
519
- if (idbroker && identity) {
556
+ var idbrokerUrl = this.get('idbroker');
557
+ var identityUrl = this.get('identity');
558
+ if (idbrokerUrl && identityUrl) {
520
559
  var _this$webex$config$cr = this.webex.config.credentials,
521
560
  authorizationString = _this$webex$config$cr.authorizationString,
522
561
  authorizeUrl = _this$webex$config$cr.authorizeUrl;
523
562
 
524
563
  // This must be set outside of the setConfig method used to assign the
525
564
  // idbroker and identity url values.
526
- this.webex.config.credentials.authorizeUrl = authorizationString ? authorizeUrl : "".concat(idbroker.replace(trailingSlashes, ''), "/idb/oauth2/v1/authorize");
565
+ this.webex.config.credentials.authorizeUrl = authorizationString ? authorizeUrl : "".concat(idbrokerUrl.replace(trailingSlashes, ''), "/idb/oauth2/v1/authorize");
527
566
  this.webex.setConfig({
528
567
  credentials: {
529
568
  idbroker: {
530
- url: idbroker.replace(trailingSlashes, '') // remove trailing slash
569
+ url: idbrokerUrl.replace(trailingSlashes, '') // remove trailing slash
531
570
  },
532
571
 
533
572
  identity: {
534
- url: identity.replace(trailingSlashes, '') // remove trailing slash
573
+ url: identityUrl.replace(trailingSlashes, '') // remove trailing slash
535
574
  }
536
575
  }
537
576
  });
@@ -540,7 +579,7 @@ var Services = _webexPlugin.default.extend({
540
579
  /**
541
580
  * Wait until the service catalog is available,
542
581
  * or reject afte ra timeout of 60 seconds.
543
- * @param {string} serviceGroup
582
+ * @param {ServiceGroup} serviceGroup
544
583
  * @param {number} [timeout] - in seconds
545
584
  * @returns {Promise<void>}
546
585
  */
@@ -571,7 +610,7 @@ var Services = _webexPlugin.default.extend({
571
610
  * @returns {Promise<string>} - Resolves to the priority host of a service.
572
611
  */
573
612
  waitForService: function waitForService(_ref8) {
574
- var _this6 = this;
613
+ var _this7 = this;
575
614
  var name = _ref8.name,
576
615
  _ref8$timeout = _ref8.timeout,
577
616
  timeout = _ref8$timeout === void 0 ? 5 : _ref8$timeout,
@@ -584,9 +623,10 @@ var Services = _webexPlugin.default.extend({
584
623
  return service === name;
585
624
  });
586
625
  if (fetchFromServiceUrl) {
587
- return _promise.default.resolve(this._activeServices[name]);
626
+ var clusterId = this._activeServices[name];
627
+ return _promise.default.resolve(this.get(clusterId));
588
628
  }
589
- var priorityUrl = this.get(name, true);
629
+ var priorityUrl = this.get(name);
590
630
  var priorityUrlObj = this.getServiceFromUrl(url);
591
631
  if (priorityUrl || priorityUrlObj) {
592
632
  return _promise.default.resolve(priorityUrl || priorityUrlObj.priorityUrl);
@@ -606,8 +646,8 @@ var Services = _webexPlugin.default.extend({
606
646
  var groupsToCheck = ['preauth', 'signin', 'postauth'];
607
647
  var checkCatalog = function checkCatalog(catalogGroup) {
608
648
  return catalog.waitForCatalog(catalogGroup, timeout).then(function () {
609
- var scopedPriorityUrl = _this6.get(name, true);
610
- var scopedPrioriryUrlObj = _this6.getServiceFromUrl(url);
649
+ var scopedPriorityUrl = _this7.get(name);
650
+ var scopedPrioriryUrlObj = _this7.getServiceFromUrl(url);
611
651
  if (scopedPriorityUrl || scopedPrioriryUrlObj) {
612
652
  resolve(scopedPriorityUrl || scopedPrioriryUrlObj.priorityUrl);
613
653
  }
@@ -618,7 +658,7 @@ var Services = _webexPlugin.default.extend({
618
658
  _promise.default.all(groupsToCheck.map(function (group) {
619
659
  return checkCatalog(group);
620
660
  })).then(function () {
621
- _this6.webex.internal.metrics.submitClientMetrics(_metrics.default.JS_SDK_SERVICE_NOT_FOUND, {
661
+ _this7.webex.internal.metrics.submitClientMetrics(_metrics.default.JS_SDK_SERVICE_NOT_FOUND, {
622
662
  fields: {
623
663
  service_name: name
624
664
  }
@@ -634,18 +674,11 @@ var Services = _webexPlugin.default.extend({
634
674
  * @returns {string} uri with the host replaced
635
675
  */
636
676
  replaceHostFromHostmap: function replaceHostFromHostmap(uri) {
637
- var url = new URL(uri);
638
- var hostCatalog = this._services;
639
- if (!hostCatalog) {
677
+ try {
678
+ return this.convertUrlToPriorityHostUrl(uri);
679
+ } catch (_unused) {
640
680
  return uri;
641
681
  }
642
- var host = hostCatalog[url.host];
643
- if (host && host[0]) {
644
- var newHost = host[0].host;
645
- url.host = newHost;
646
- return url.toString();
647
- }
648
- return uri;
649
682
  },
650
683
  /**
651
684
  * Formats a host map entry for use in service catalog.
@@ -674,17 +707,26 @@ var Services = _webexPlugin.default.extend({
674
707
  /**
675
708
  * @private
676
709
  * Organize a received hostmap from a service
677
- * @param {object} serviceHostmap
710
+ * @param {ServiceHostmap} serviceHostmap
678
711
  * catalog endpoint.
679
- * @returns {object}
712
+ * @returns {Array<Service>}
680
713
  */
681
714
  _formatReceivedHostmap: function _formatReceivedHostmap(_ref10) {
682
- var _this7 = this;
715
+ var _this8 = this;
683
716
  var services = _ref10.services,
684
- activeServices = _ref10.activeServices;
685
- var formattedHostmap = services.map(function (service) {
686
- return _this7._formatHostMapEntry(service);
687
- });
717
+ activeServices = _ref10.activeServices,
718
+ timestamp = _ref10.timestamp,
719
+ orgId = _ref10.orgId,
720
+ format = _ref10.format;
721
+ var formattedHostmap = {
722
+ activeServices: activeServices,
723
+ services: services.map(function (service) {
724
+ return _this8._formatHostMapEntry(service);
725
+ }),
726
+ timestamp: timestamp,
727
+ orgId: orgId,
728
+ format: format
729
+ };
688
730
  this._updateActiveServices(activeServices);
689
731
  this._updateServices(services);
690
732
  return formattedHostmap;
@@ -692,7 +734,7 @@ var Services = _webexPlugin.default.extend({
692
734
  /**
693
735
  * Get the clusterId associated with a URL string.
694
736
  * @param {string} url
695
- * @returns {string} - Cluster ID of url provided
737
+ * @returns {string | undefined} - Cluster ID of url provided
696
738
  */
697
739
  getClusterId: function getClusterId(url) {
698
740
  var catalog = this._getCatalog();
@@ -703,8 +745,7 @@ var Services = _webexPlugin.default.extend({
703
745
  * return an object containing both the name and url of a found service.
704
746
  * @param {object} params
705
747
  * @param {string} params.clusterId - clusterId of found service
706
- * @param {boolean} [params.priorityHost] - returns priority host url if true
707
- * @param {string} [params.serviceGroup] - specify service group
748
+ * @param {ServiceGroup} [params.serviceGroup] - specify service group
708
749
  * @returns {object} service
709
750
  * @returns {string} service.name
710
751
  * @returns {string} service.url
@@ -746,19 +787,23 @@ var Services = _webexPlugin.default.extend({
746
787
  * @param {string} url - The url to be validated.
747
788
  * @returns {object} - Service object.
748
789
  * @returns {object.name} - The name of the service found.
749
- * @returns {object.priorityUrl} - The priority url of the found service.
790
+ * @returns {object.priorityUrl} - The default url of the found service.
750
791
  * @returns {object.defaultUrl} - The default url of the found service.
751
792
  */
752
793
  getServiceFromUrl: function getServiceFromUrl() {
753
794
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
754
- var service = this._getCatalog().findServiceUrlFromUrl(url);
795
+ var service = this._getCatalog().findServiceDetailFromUrl(url);
755
796
  if (!service) {
756
797
  return undefined;
757
798
  }
799
+ var priorityUrl = service.get();
800
+ var defaultUrl = new URL(service.serviceUrls.find(function (serviceUrl) {
801
+ return url.startsWith(serviceUrl.baseUrl);
802
+ }).baseUrl).href;
758
803
  return {
759
- name: service.name,
760
- priorityUrl: service.get(true),
761
- defaultUrl: service.get()
804
+ name: service.serviceName,
805
+ priorityUrl: priorityUrl,
806
+ defaultUrl: defaultUrl
762
807
  };
763
808
  },
764
809
  /**
@@ -801,7 +846,7 @@ var Services = _webexPlugin.default.extend({
801
846
  * @returns {Promise<object>}
802
847
  */
803
848
  _fetchNewServiceHostmap: function _fetchNewServiceHostmap() {
804
- var _this8 = this;
849
+ var _this9 = this;
805
850
  var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
806
851
  from = _ref13.from,
807
852
  query = _ref13.query,
@@ -810,7 +855,7 @@ var Services = _webexPlugin.default.extend({
810
855
  var service = 'u2c';
811
856
  var resource = from ? "/".concat(from, "/catalog") : '/catalog';
812
857
  var qs = _objectSpread(_objectSpread({}, query || {}), {}, {
813
- format: 'hostmap'
858
+ format: 'U2CV2'
814
859
  });
815
860
  if (forceRefresh) {
816
861
  qs.timestamp = new Date().getTime();
@@ -819,7 +864,8 @@ var Services = _webexPlugin.default.extend({
819
864
  method: 'GET',
820
865
  service: service,
821
866
  resource: resource,
822
- qs: qs
867
+ qs: qs,
868
+ headers: {}
823
869
  };
824
870
  if (token) {
825
871
  requestObject.headers = {
@@ -827,10 +873,10 @@ var Services = _webexPlugin.default.extend({
827
873
  };
828
874
  }
829
875
  return this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(function () {
830
- return _this8.request(requestObject);
876
+ return _this9.request(requestObject);
831
877
  }, 'internal.get.u2c.time').then(function (_ref14) {
832
878
  var body = _ref14.body;
833
- return _this8._formatReceivedHostmap(body);
879
+ return _this9._formatReceivedHostmap(body);
834
880
  });
835
881
  },
836
882
  /**
@@ -839,7 +885,7 @@ var Services = _webexPlugin.default.extend({
839
885
  * @returns {void}
840
886
  */
841
887
  initConfig: function initConfig() {
842
- var _this9 = this;
888
+ var _this10 = this;
843
889
  // Get the catalog and destructure the services config.
844
890
  var catalog = this._getCatalog();
845
891
  var _this$webex$config = this.webex.config,
@@ -855,7 +901,7 @@ var Services = _webexPlugin.default.extend({
855
901
  if (services.discovery) {
856
902
  // Format the discovery configuration into an injectable array.
857
903
  var formattedDiscoveryServices = (0, _keys.default)(services.discovery).map(function (key) {
858
- return _this9._formatHostMapEntry({
904
+ return _this10._formatHostMapEntry({
859
905
  id: key,
860
906
  serviceName: key,
861
907
  serviceUrls: [{
@@ -871,7 +917,7 @@ var Services = _webexPlugin.default.extend({
871
917
  if (services.override) {
872
918
  // Format the override configuration into an injectable array.
873
919
  var formattedOverrideServices = (0, _keys.default)(services.override).map(function (key) {
874
- return _this9._formatHostMapEntry({
920
+ return _this10._formatHostMapEntry({
875
921
  id: key,
876
922
  serviceName: key,
877
923
  serviceUrls: [{
@@ -902,11 +948,12 @@ var Services = _webexPlugin.default.extend({
902
948
  },
903
949
  /**
904
950
  * Make the initial requests to collect the root catalogs.
905
- *
951
+ * @param {boolean} refresh - Is need force update
906
952
  * @returns {Promise<void, Error>} - Errors if the token is unavailable.
907
953
  */
908
954
  initServiceCatalogs: function initServiceCatalogs() {
909
- var _this10 = this;
955
+ var _this11 = this;
956
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
910
957
  this.logger.info('services: initializing initial service catalogs');
911
958
 
912
959
  // Destructure the credentials plugin.
@@ -921,16 +968,18 @@ var Services = _webexPlugin.default.extend({
921
968
  })
922
969
  // Begin collecting the preauth/limited catalog.
923
970
  .then(function (orgId) {
924
- return _this10.collectPreauthCatalog({
971
+ return _this11.collectPreauthCatalog({
925
972
  orgId: orgId
926
- });
973
+ }, refresh);
927
974
  }).then(function () {
928
975
  // Validate if the token is authorized.
929
976
  if (credentials.canAuthorize) {
930
977
  // Attempt to collect the postauth catalog.
931
- return _this10.updateServices().catch(function () {
932
- _this10.initFailed = true;
933
- _this10.logger.warn('services: cannot retrieve postauth catalog');
978
+ return _this11.updateServices({
979
+ forceRefresh: refresh
980
+ }).catch(function () {
981
+ _this11.initFailed = true;
982
+ _this11.logger.warn('services: cannot retrieve postauth catalog');
934
983
  });
935
984
  }
936
985
 
@@ -946,39 +995,39 @@ var Services = _webexPlugin.default.extend({
946
995
  * @returns {Services}
947
996
  */
948
997
  initialize: function initialize() {
949
- var _this11 = this;
998
+ var _this12 = this;
950
999
  var catalog = new _serviceCatalog.default();
951
1000
  this._catalogs.set(this.webex, catalog);
952
1001
 
953
1002
  // Listen for configuration changes once.
954
1003
  this.listenToOnce(this.webex, 'change:config', function () {
955
- _this11.initConfig();
1004
+ _this12.initConfig();
956
1005
  });
957
1006
 
958
1007
  // wait for webex instance to be ready before attempting
959
1008
  // to update the service catalogs
960
1009
  this.listenToOnce(this.webex, 'ready', function () {
961
- var supertoken = _this11.webex.credentials.supertoken;
1010
+ var supertoken = _this12.webex.credentials.supertoken;
962
1011
  // Validate if the supertoken exists.
963
1012
  if (supertoken && supertoken.access_token) {
964
- _this11.initServiceCatalogs().then(function () {
1013
+ _this12.initServiceCatalogs().then(function () {
965
1014
  catalog.isReady = true;
966
1015
  }).catch(function (error) {
967
- _this11.initFailed = true;
968
- _this11.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1016
+ _this12.initFailed = true;
1017
+ _this12.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
969
1018
  });
970
1019
  } else {
971
- var email = _this11.webex.config.email;
972
- _this11.collectPreauthCatalog(email ? {
1020
+ var email = _this12.webex.config.email;
1021
+ _this12.collectPreauthCatalog(email ? {
973
1022
  email: email
974
1023
  } : undefined).catch(function (error) {
975
- _this11.initFailed = true;
976
- _this11.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1024
+ _this12.initFailed = true;
1025
+ _this12.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
977
1026
  });
978
1027
  }
979
1028
  });
980
1029
  },
981
- version: "3.8.1"
1030
+ version: "3.9.0-multi-llms.2"
982
1031
  });
983
1032
  /* eslint-enable no-underscore-dangle */
984
1033
  var _default = exports.default = Services;