@webex/webex-core 3.9.0 → 3.10.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.
@@ -16,6 +16,7 @@ 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"));
@@ -127,7 +128,9 @@ var Services = _webexPlugin.default.extend({
127
128
  * @returns {Promise<object>}
128
129
  */
129
130
  updateServices: function updateServices() {
130
- var _this = this;
131
+ var _catalog$status,
132
+ _catalog$status$servi,
133
+ _this = this;
131
134
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
132
135
  from = _ref.from,
133
136
  query = _ref.query,
@@ -149,9 +152,8 @@ var Services = _webexPlugin.default.extend({
149
152
  serviceGroup = 'postauth';
150
153
  break;
151
154
  }
152
-
153
155
  // confirm catalog update for group is not in progress.
154
- 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) {
155
157
  return this.waitForCatalog(serviceGroup);
156
158
  }
157
159
  catalog.status[serviceGroup].collecting = true;
@@ -177,7 +179,7 @@ var Services = _webexPlugin.default.extend({
177
179
  query: formattedQuery,
178
180
  forceRefresh: forceRefresh
179
181
  }).then(function (serviceHostMap) {
180
- 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);
181
183
  _this.updateCredentialsConfig();
182
184
  catalog.status[serviceGroup].collecting = false;
183
185
  }).catch(function (error) {
@@ -331,22 +333,68 @@ var Services = _webexPlugin.default.extend({
331
333
  return _promise.default.reject(response);
332
334
  });
333
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
+ },
334
382
  /**
335
383
  * Get user meeting preferences (preferred webex site).
336
384
  *
337
385
  * @returns {object} - User Information including user preferrences .
338
386
  */
339
387
  getMeetingPreferences: function getMeetingPreferences() {
340
- var _this3 = this;
388
+ var _this4 = this;
341
389
  return this.request({
342
390
  method: 'GET',
343
391
  service: 'hydra',
344
392
  resource: 'meetingPreferences'
345
393
  }).then(function (res) {
346
- _this3.logger.info('services: received user region info');
394
+ _this4.logger.info('services: received user region info');
347
395
  return res.body;
348
396
  }).catch(function (err) {
349
- _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);
350
398
  // resolve successfully even if request failed
351
399
  });
352
400
  },
@@ -356,7 +404,7 @@ var Services = _webexPlugin.default.extend({
356
404
  * @returns {object} - The region info object.
357
405
  */
358
406
  fetchClientRegionInfo: function fetchClientRegionInfo() {
359
- var _this4 = this;
407
+ var _this5 = this;
360
408
  var services = this.webex.config.services;
361
409
  return this.request({
362
410
  uri: services.discovery.sqdiscovery,
@@ -366,10 +414,10 @@ var Services = _webexPlugin.default.extend({
366
414
  },
367
415
  timeout: 5000
368
416
  }).then(function (res) {
369
- _this4.logger.info('services: received user region info');
417
+ _this5.logger.info('services: received user region info');
370
418
  return res.body;
371
419
  }).catch(function (err) {
372
- _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);
373
421
  // resolve successfully even if request failed
374
422
  });
375
423
  },
@@ -389,7 +437,7 @@ var Services = _webexPlugin.default.extend({
389
437
  * @returns {LicenseDTO} - The DTO returned from the **License** service.
390
438
  */
391
439
  sendUserActivation: function sendUserActivation(_ref5) {
392
- var _this5 = this;
440
+ var _this6 = this;
393
441
  var email = _ref5.email,
394
442
  reqId = _ref5.reqId,
395
443
  token = _ref5.token,
@@ -407,7 +455,7 @@ var Services = _webexPlugin.default.extend({
407
455
  }
408
456
 
409
457
  // Send the user activation request to the **License** service.
410
- return _this5.request({
458
+ return _this6.request({
411
459
  service: 'license',
412
460
  resource: 'users/activations',
413
461
  method: 'POST',
@@ -444,7 +492,7 @@ var Services = _webexPlugin.default.extend({
444
492
  updateCatalog: function updateCatalog(serviceGroup, hostMap) {
445
493
  var catalog = this._getCatalog();
446
494
  var serviceHostMap = this._formatReceivedHostmap(hostMap);
447
- 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);
448
496
  },
449
497
  /**
450
498
  * simplified method to update the preauth catalog via email
@@ -562,7 +610,7 @@ var Services = _webexPlugin.default.extend({
562
610
  * @returns {Promise<string>} - Resolves to the priority host of a service.
563
611
  */
564
612
  waitForService: function waitForService(_ref8) {
565
- var _this6 = this;
613
+ var _this7 = this;
566
614
  var name = _ref8.name,
567
615
  _ref8$timeout = _ref8.timeout,
568
616
  timeout = _ref8$timeout === void 0 ? 5 : _ref8$timeout,
@@ -598,8 +646,8 @@ var Services = _webexPlugin.default.extend({
598
646
  var groupsToCheck = ['preauth', 'signin', 'postauth'];
599
647
  var checkCatalog = function checkCatalog(catalogGroup) {
600
648
  return catalog.waitForCatalog(catalogGroup, timeout).then(function () {
601
- var scopedPriorityUrl = _this6.get(name);
602
- var scopedPrioriryUrlObj = _this6.getServiceFromUrl(url);
649
+ var scopedPriorityUrl = _this7.get(name);
650
+ var scopedPrioriryUrlObj = _this7.getServiceFromUrl(url);
603
651
  if (scopedPriorityUrl || scopedPrioriryUrlObj) {
604
652
  resolve(scopedPriorityUrl || scopedPrioriryUrlObj.priorityUrl);
605
653
  }
@@ -610,7 +658,7 @@ var Services = _webexPlugin.default.extend({
610
658
  _promise.default.all(groupsToCheck.map(function (group) {
611
659
  return checkCatalog(group);
612
660
  })).then(function () {
613
- _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, {
614
662
  fields: {
615
663
  service_name: name
616
664
  }
@@ -664,12 +712,21 @@ var Services = _webexPlugin.default.extend({
664
712
  * @returns {Array<Service>}
665
713
  */
666
714
  _formatReceivedHostmap: function _formatReceivedHostmap(_ref10) {
667
- var _this7 = this;
715
+ var _this8 = this;
668
716
  var services = _ref10.services,
669
- activeServices = _ref10.activeServices;
670
- var formattedHostmap = services.map(function (service) {
671
- return _this7._formatHostMapEntry(service);
672
- });
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
+ };
673
730
  this._updateActiveServices(activeServices);
674
731
  this._updateServices(services);
675
732
  return formattedHostmap;
@@ -789,7 +846,7 @@ var Services = _webexPlugin.default.extend({
789
846
  * @returns {Promise<object>}
790
847
  */
791
848
  _fetchNewServiceHostmap: function _fetchNewServiceHostmap() {
792
- var _this8 = this;
849
+ var _this9 = this;
793
850
  var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
794
851
  from = _ref13.from,
795
852
  query = _ref13.query,
@@ -816,10 +873,10 @@ var Services = _webexPlugin.default.extend({
816
873
  };
817
874
  }
818
875
  return this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(function () {
819
- return _this8.request(requestObject);
876
+ return _this9.request(requestObject);
820
877
  }, 'internal.get.u2c.time').then(function (_ref14) {
821
878
  var body = _ref14.body;
822
- return _this8._formatReceivedHostmap(body);
879
+ return _this9._formatReceivedHostmap(body);
823
880
  });
824
881
  },
825
882
  /**
@@ -828,7 +885,7 @@ var Services = _webexPlugin.default.extend({
828
885
  * @returns {void}
829
886
  */
830
887
  initConfig: function initConfig() {
831
- var _this9 = this;
888
+ var _this10 = this;
832
889
  // Get the catalog and destructure the services config.
833
890
  var catalog = this._getCatalog();
834
891
  var _this$webex$config = this.webex.config,
@@ -844,7 +901,7 @@ var Services = _webexPlugin.default.extend({
844
901
  if (services.discovery) {
845
902
  // Format the discovery configuration into an injectable array.
846
903
  var formattedDiscoveryServices = (0, _keys.default)(services.discovery).map(function (key) {
847
- return _this9._formatHostMapEntry({
904
+ return _this10._formatHostMapEntry({
848
905
  id: key,
849
906
  serviceName: key,
850
907
  serviceUrls: [{
@@ -860,7 +917,7 @@ var Services = _webexPlugin.default.extend({
860
917
  if (services.override) {
861
918
  // Format the override configuration into an injectable array.
862
919
  var formattedOverrideServices = (0, _keys.default)(services.override).map(function (key) {
863
- return _this9._formatHostMapEntry({
920
+ return _this10._formatHostMapEntry({
864
921
  id: key,
865
922
  serviceName: key,
866
923
  serviceUrls: [{
@@ -891,11 +948,12 @@ var Services = _webexPlugin.default.extend({
891
948
  },
892
949
  /**
893
950
  * Make the initial requests to collect the root catalogs.
894
- *
951
+ * @param {boolean} refresh - Is need force update
895
952
  * @returns {Promise<void, Error>} - Errors if the token is unavailable.
896
953
  */
897
954
  initServiceCatalogs: function initServiceCatalogs() {
898
- var _this10 = this;
955
+ var _this11 = this;
956
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
899
957
  this.logger.info('services: initializing initial service catalogs');
900
958
 
901
959
  // Destructure the credentials plugin.
@@ -910,16 +968,18 @@ var Services = _webexPlugin.default.extend({
910
968
  })
911
969
  // Begin collecting the preauth/limited catalog.
912
970
  .then(function (orgId) {
913
- return _this10.collectPreauthCatalog({
971
+ return _this11.collectPreauthCatalog({
914
972
  orgId: orgId
915
- });
973
+ }, refresh);
916
974
  }).then(function () {
917
975
  // Validate if the token is authorized.
918
976
  if (credentials.canAuthorize) {
919
977
  // Attempt to collect the postauth catalog.
920
- return _this10.updateServices().catch(function () {
921
- _this10.initFailed = true;
922
- _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');
923
983
  });
924
984
  }
925
985
 
@@ -935,39 +995,39 @@ var Services = _webexPlugin.default.extend({
935
995
  * @returns {Services}
936
996
  */
937
997
  initialize: function initialize() {
938
- var _this11 = this;
998
+ var _this12 = this;
939
999
  var catalog = new _serviceCatalog.default();
940
1000
  this._catalogs.set(this.webex, catalog);
941
1001
 
942
1002
  // Listen for configuration changes once.
943
1003
  this.listenToOnce(this.webex, 'change:config', function () {
944
- _this11.initConfig();
1004
+ _this12.initConfig();
945
1005
  });
946
1006
 
947
1007
  // wait for webex instance to be ready before attempting
948
1008
  // to update the service catalogs
949
1009
  this.listenToOnce(this.webex, 'ready', function () {
950
- var supertoken = _this11.webex.credentials.supertoken;
1010
+ var supertoken = _this12.webex.credentials.supertoken;
951
1011
  // Validate if the supertoken exists.
952
1012
  if (supertoken && supertoken.access_token) {
953
- _this11.initServiceCatalogs().then(function () {
1013
+ _this12.initServiceCatalogs().then(function () {
954
1014
  catalog.isReady = true;
955
1015
  }).catch(function (error) {
956
- _this11.initFailed = true;
957
- _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));
958
1018
  });
959
1019
  } else {
960
- var email = _this11.webex.config.email;
961
- _this11.collectPreauthCatalog(email ? {
1020
+ var email = _this12.webex.config.email;
1021
+ _this12.collectPreauthCatalog(email ? {
962
1022
  email: email
963
1023
  } : undefined).catch(function (error) {
964
- _this11.initFailed = true;
965
- _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));
966
1026
  });
967
1027
  }
968
1028
  });
969
1029
  },
970
- version: "3.9.0"
1030
+ version: "3.10.0"
971
1031
  });
972
1032
  /* eslint-enable no-underscore-dangle */
973
1033
  var _default = exports.default = Services;