@webex/webex-core 3.12.0-webex-services-ready.1 → 3.12.0-webex-services-ready.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.
@@ -302,7 +302,7 @@ var Batcher = _webexPlugin.default.extend({
302
302
  fingerprintResponse: function fingerprintResponse(item) {
303
303
  throw new Error('fingerprintResponse() must be implemented');
304
304
  },
305
- version: "3.12.0-webex-services-ready.1"
305
+ version: "3.12.0-webex-services-ready.2"
306
306
  });
307
307
  var _default2 = exports.default = Batcher;
308
308
  //# sourceMappingURL=batcher.js.map
@@ -600,7 +600,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
600
600
  this.refresh();
601
601
  }
602
602
  },
603
- version: "3.12.0-webex-services-ready.1"
603
+ version: "3.12.0-webex-services-ready.2"
604
604
  }, (0, _applyDecoratedDescriptor2.default)(_obj, "getUserToken", [_dec, _dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "getUserToken"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "invalidate", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "invalidate"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec5, _dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), _obj));
605
605
  var _default = exports.default = Credentials;
606
606
  //# sourceMappingURL=credentials.js.map
@@ -532,7 +532,7 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
532
532
  return res.body;
533
533
  });
534
534
  },
535
- version: "3.12.0-webex-services-ready.1"
535
+ version: "3.12.0-webex-services-ready.2"
536
536
  }, (0, _applyDecoratedDescriptor2.default)(_obj, "downscope", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "downscope"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "revoke", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "revoke"), _obj), _obj));
537
537
  var _default = exports.default = Token;
538
538
  //# sourceMappingURL=token.js.map
@@ -31,7 +31,7 @@ var _serviceState = _interopRequireDefault(require("./service-state"));
31
31
  var _serviceFedRamp = _interopRequireDefault(require("./service-fed-ramp"));
32
32
  var _constants = require("../constants");
33
33
  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; }
34
- 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; } /* eslint-disable no-console */
34
+ 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; }
35
35
  var trailingSlashes = /(?:^\/)|(?:\/$)/;
36
36
 
37
37
  // The default cluster when one is not provided (usually as 'US' from hydra)
@@ -81,8 +81,10 @@ var Services = _webexPlugin.default.extend({
81
81
  },
82
82
  session: {
83
83
  /**
84
- * Becomes `true` once service catalog initialization has completed.
85
- * Blocks `webex.ready` until services are initialized.
84
+ * Becomes `true` once the initial catalog collection has completed
85
+ * (successfully or otherwise) and any in-flight credentials refresh has
86
+ * settled. Blocks `webex.ready` so consumers can rely on `webex.ready`
87
+ * implying "catalogs populated AND credential state stable".
86
88
  * @instance
87
89
  * @memberof Services
88
90
  * @type {boolean}
@@ -1426,7 +1428,6 @@ var Services = _webexPlugin.default.extend({
1426
1428
  });
1427
1429
  case 1:
1428
1430
  _this1.ready = true;
1429
- _this1.trigger('services:initialized');
1430
1431
  case 2:
1431
1432
  case "end":
1432
1433
  return _context4.stop();
@@ -1450,34 +1451,118 @@ var Services = _webexPlugin.default.extend({
1450
1451
  this.registries.set(this.webex, registry);
1451
1452
  this.states.set(this.webex, state);
1452
1453
 
1453
- // Listen for configuration changes once.
1454
+ // Listen for configuration changes once. The config is not populated on the
1455
+ // webex instance until the `change:config` event fires, so any decision that
1456
+ // depends on config values (such as the gated-vs-ungated init below) must be
1457
+ // made from within this handler rather than synchronously in `initialize()`.
1454
1458
  this.listenToOnce(this.webex, 'change:config', function () {
1459
+ var _this10$webex$config, _this10$webex$config$;
1455
1460
  _this10.initConfig();
1456
- });
1457
1461
 
1458
- // Wait for storage to be loaded before attempting to update the service catalogs.
1459
- // We listen for 'loaded' instead of 'ready' because services.ready is a dependency
1460
- // of webex.ready - listening to 'ready' would cause a deadlock.
1461
- this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1462
- var cachedCatalog, supertoken, timeout, email;
1462
+ // Feature flag: when enabled, `webex.ready` is blocked until the initial
1463
+ // catalog collection has settled AND any in-flight credentials refresh has
1464
+ // completed. When disabled (the default), preserves the pre-existing
1465
+ // behavior where `webex.ready` fires as soon as `webex.loaded` does and
1466
+ // the catalog is collected out-of-band.
1467
+ var waitForCatalogInit = ((_this10$webex$config = _this10.webex.config) === null || _this10$webex$config === void 0 ? void 0 : (_this10$webex$config$ = _this10$webex$config.services) === null || _this10$webex$config$ === void 0 ? void 0 : _this10$webex$config$.waitForCatalogInit) === true;
1468
+ if (waitForCatalogInit) {
1469
+ _this10._initializeCatalogsGated(catalog);
1470
+ } else {
1471
+ // Not gating - immediately mark ready so we do not block webex.ready.
1472
+ _this10.ready = true;
1473
+ _this10._initializeCatalogsUngated(catalog);
1474
+ }
1475
+ });
1476
+ },
1477
+ /**
1478
+ * Original (pre-verified-ready) initialization path. Runs on `webex.ready`
1479
+ * and collects catalogs opportunistically without blocking anything.
1480
+ *
1481
+ * @private
1482
+ * @param {ServiceCatalog} catalog
1483
+ * @returns {void}
1484
+ */
1485
+ _initializeCatalogsUngated: function _initializeCatalogsUngated(catalog) {
1486
+ var _this11 = this;
1487
+ // wait for webex instance to be ready before attempting
1488
+ // to update the service catalogs
1489
+ // this can cause a race condition because credentials may
1490
+ // not be valid when services is initialized
1491
+ this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1492
+ var cachedCatalog, supertoken, email;
1463
1493
  return _regenerator.default.wrap(function (_context5) {
1464
1494
  while (1) switch (_context5.prev = _context5.next) {
1465
1495
  case 0:
1466
1496
  _context5.next = 1;
1467
- return _this10._loadCatalogFromCache();
1497
+ return _this11._loadCatalogFromCache();
1468
1498
  case 1:
1469
1499
  cachedCatalog = _context5.sent;
1470
1500
  if (!cachedCatalog) {
1471
- _context5.next = 3;
1501
+ _context5.next = 2;
1472
1502
  break;
1473
1503
  }
1474
1504
  catalog.isReady = true;
1475
- _context5.next = 2;
1476
- return _this10._finalizeReady();
1477
- case 2:
1478
1505
  return _context5.abrupt("return");
1506
+ case 2:
1507
+ supertoken = _this11.webex.credentials.supertoken; // Validate if the supertoken exists.
1508
+ if (supertoken && supertoken.access_token) {
1509
+ _this11.initServiceCatalogs().then(function () {
1510
+ catalog.isReady = true;
1511
+ }).catch(function (error) {
1512
+ _this11.initFailed = true;
1513
+ _this11.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1514
+ });
1515
+ } else {
1516
+ email = _this11.webex.config.email;
1517
+ _this11.collectPreauthCatalog(email ? {
1518
+ email: email
1519
+ } : undefined).catch(function (error) {
1520
+ _this11.initFailed = true;
1521
+ _this11.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1522
+ });
1523
+ }
1479
1524
  case 3:
1480
- supertoken = _this10.webex.credentials.supertoken; // Race init against a hard timeout so a hung request never leaves
1525
+ case "end":
1526
+ return _context5.stop();
1527
+ }
1528
+ }, _callee5);
1529
+ })));
1530
+ },
1531
+ /**
1532
+ * Verified-ready initialization path. Blocks `webex.ready` until the initial
1533
+ * catalog fetch has settled (or timed out) AND any in-flight credentials
1534
+ * refresh has completed. Also handles the fresh-login case where OAuth
1535
+ * completes after `loaded` fires.
1536
+ *
1537
+ * @private
1538
+ * @param {ServiceCatalog} catalog
1539
+ * @returns {void}
1540
+ */
1541
+ _initializeCatalogsGated: function _initializeCatalogsGated(catalog) {
1542
+ var _this12 = this;
1543
+ // Wait for storage to be loaded before attempting to update the service
1544
+ // catalogs. We listen for 'loaded' instead of 'ready' because `services.ready`
1545
+ // now blocks `webex.ready` - listening to 'ready' would deadlock.
1546
+ this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
1547
+ var cachedCatalog, supertoken, timeout, email;
1548
+ return _regenerator.default.wrap(function (_context6) {
1549
+ while (1) switch (_context6.prev = _context6.next) {
1550
+ case 0:
1551
+ _context6.next = 1;
1552
+ return _this12._loadCatalogFromCache();
1553
+ case 1:
1554
+ cachedCatalog = _context6.sent;
1555
+ if (!cachedCatalog) {
1556
+ _context6.next = 3;
1557
+ break;
1558
+ }
1559
+ catalog.isReady = true;
1560
+ _context6.next = 2;
1561
+ return _this12._finalizeReady();
1562
+ case 2:
1563
+ return _context6.abrupt("return");
1564
+ case 3:
1565
+ supertoken = _this12.webex.credentials.supertoken; // Race init against a hard timeout so a hung request never leaves
1481
1566
  // `services.ready` false forever - that would stall `webex.ready` and
1482
1567
  // leave the app on a permanent spinner.
1483
1568
  timeout = new _promise.default(function (_, reject) {
@@ -1486,44 +1571,43 @@ var Services = _webexPlugin.default.extend({
1486
1571
  }, SERVICES_INIT_TIMEOUT_MS);
1487
1572
  }); // Validate if the supertoken exists.
1488
1573
  if (supertoken && supertoken.access_token) {
1489
- _promise.default.race([_this10.initServiceCatalogs(), timeout]).then(function () {
1574
+ _promise.default.race([_this12.initServiceCatalogs(), timeout]).then(function () {
1490
1575
  catalog.isReady = true;
1491
1576
  }).catch(function (error) {
1492
- _this10.initFailed = true;
1493
- _this10.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1577
+ _this12.initFailed = true;
1578
+ _this12.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1494
1579
  }).finally(function () {
1495
- return _this10._finalizeReady();
1580
+ return _this12._finalizeReady();
1496
1581
  });
1497
1582
  } else {
1498
- email = _this10.webex.config.email;
1499
- _promise.default.race([_this10.collectPreauthCatalog(email ? {
1583
+ email = _this12.webex.config.email;
1584
+ _promise.default.race([_this12.collectPreauthCatalog(email ? {
1500
1585
  email: email
1501
1586
  } : undefined), timeout]).catch(function (error) {
1502
- _this10.initFailed = true;
1503
- _this10.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1587
+ _this12.initFailed = true;
1588
+ _this12.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1504
1589
  }).finally(function () {
1505
- return _this10._finalizeReady();
1590
+ return _this12._finalizeReady();
1506
1591
  });
1507
- // Listen for when credentials become available to fetch the full catalog.
1508
- // This handles fresh login where 'loaded' fires before OAuth completes.
1509
- _this10.listenToOnce(_this10.webex, 'change:canAuthorize', function () {
1510
- if (_this10.webex.canAuthorize && !catalog.status.postauth.ready) {
1511
- _this10.initServiceCatalogs().then(function () {
1512
- catalog.isReady = true;
1513
- }).catch(function (error) {
1514
- _this10.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1592
+
1593
+ // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1594
+ // for `canAuthorize` flipping true and then collect the postauth catalog.
1595
+ _this12.listenToOnce(_this12.webex, 'change:canAuthorize', function () {
1596
+ if (_this12.webex.canAuthorize && !catalog.status.postauth.ready) {
1597
+ _this12.initServiceCatalogs().catch(function (error) {
1598
+ _this12.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1515
1599
  });
1516
1600
  }
1517
1601
  });
1518
1602
  }
1519
1603
  case 4:
1520
1604
  case "end":
1521
- return _context5.stop();
1605
+ return _context6.stop();
1522
1606
  }
1523
- }, _callee5);
1607
+ }, _callee6);
1524
1608
  })));
1525
1609
  },
1526
- version: "3.12.0-webex-services-ready.1"
1610
+ version: "3.12.0-webex-services-ready.2"
1527
1611
  });
1528
1612
  /* eslint-enable no-underscore-dangle */
1529
1613
  var _default = exports.default = Services;