@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.
@@ -60,8 +60,10 @@ var Services = _webexPlugin.default.extend({
60
60
  },
61
61
  session: {
62
62
  /**
63
- * Becomes `true` once services initialization has completed.
64
- * This blocks `webex.ready` until services are initialized.
63
+ * Becomes `true` once the initial catalog collection has completed
64
+ * (successfully or otherwise) and any in-flight credentials refresh has
65
+ * settled. Blocks `webex.ready` so consumers can rely on `webex.ready`
66
+ * implying "catalogs populated AND credential state stable".
65
67
  * @instance
66
68
  * @memberof Services
67
69
  * @type {boolean}
@@ -1362,7 +1364,6 @@ var Services = _webexPlugin.default.extend({
1362
1364
  });
1363
1365
  case 1:
1364
1366
  _this12.ready = true;
1365
- _this12.trigger('services:initialized');
1366
1367
  case 2:
1367
1368
  case "end":
1368
1369
  return _context3.stop();
@@ -1382,34 +1383,116 @@ var Services = _webexPlugin.default.extend({
1382
1383
  var catalog = new _serviceCatalog.default();
1383
1384
  this._catalogs.set(this.webex, catalog);
1384
1385
 
1385
- // Listen for configuration changes once.
1386
+ // Listen for configuration changes once. The config is not populated on the
1387
+ // webex instance until the `change:config` event fires, so any decision that
1388
+ // depends on config values (such as the gated-vs-ungated init below) must be
1389
+ // made from within this handler rather than synchronously in `initialize()`.
1386
1390
  this.listenToOnce(this.webex, 'change:config', function () {
1391
+ var _this13$webex$config, _this13$webex$config$;
1387
1392
  _this13.initConfig();
1388
- });
1389
1393
 
1390
- // Wait for storage to be loaded before attempting to update the service catalogs.
1391
- // We listen for 'loaded' instead of 'ready' because services.ready is a dependency
1392
- // of webex.ready - listening to 'ready' would cause a deadlock.
1393
- this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1394
- var warmed, supertoken, timeout, email;
1394
+ // Feature flag: when enabled, `webex.ready` is blocked until the initial
1395
+ // catalog collection has settled AND any in-flight credentials refresh has
1396
+ // completed. When disabled (the default), preserves the pre-existing
1397
+ // behavior where `webex.ready` fires as soon as `webex.loaded` does and
1398
+ // the catalog is collected out-of-band.
1399
+ var waitForCatalogInit = ((_this13$webex$config = _this13.webex.config) === null || _this13$webex$config === void 0 ? void 0 : (_this13$webex$config$ = _this13$webex$config.services) === null || _this13$webex$config$ === void 0 ? void 0 : _this13$webex$config$.waitForCatalogInit) === true;
1400
+ if (waitForCatalogInit) {
1401
+ _this13._initializeCatalogsGated(catalog);
1402
+ } else {
1403
+ // Not gating - immediately mark ready so we do not block webex.ready.
1404
+ _this13.ready = true;
1405
+ _this13._initializeCatalogsUngated(catalog);
1406
+ }
1407
+ });
1408
+ },
1409
+ /**
1410
+ * Original (pre-verified-ready) initialization path. Runs on `webex.ready`
1411
+ * and collects catalogs opportunistically without blocking anything.
1412
+ *
1413
+ * @private
1414
+ * @param {ServiceCatalog} catalog
1415
+ * @returns {void}
1416
+ */
1417
+ _initializeCatalogsUngated: function _initializeCatalogsUngated(catalog) {
1418
+ var _this14 = this;
1419
+ // wait for webex instance to be ready before attempting
1420
+ // to update the service catalogs
1421
+ this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1422
+ var warmed, supertoken, email;
1395
1423
  return _regenerator.default.wrap(function (_context4) {
1396
1424
  while (1) switch (_context4.prev = _context4.next) {
1397
1425
  case 0:
1398
1426
  _context4.next = 1;
1399
- return _this13._loadCatalogFromCache();
1427
+ return _this14._loadCatalogFromCache();
1400
1428
  case 1:
1401
1429
  warmed = _context4.sent;
1402
1430
  if (!warmed) {
1403
- _context4.next = 3;
1431
+ _context4.next = 2;
1404
1432
  break;
1405
1433
  }
1406
1434
  catalog.isReady = true;
1407
- _context4.next = 2;
1408
- return _this13._finalizeReady();
1409
- case 2:
1410
1435
  return _context4.abrupt("return");
1436
+ case 2:
1437
+ supertoken = _this14.webex.credentials.supertoken; // Validate if the supertoken exists.
1438
+ if (supertoken && supertoken.access_token) {
1439
+ _this14.initServiceCatalogs().then(function () {
1440
+ catalog.isReady = true;
1441
+ }).catch(function (error) {
1442
+ _this14.initFailed = true;
1443
+ _this14.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1444
+ });
1445
+ } else {
1446
+ email = _this14.webex.config.email;
1447
+ _this14.collectPreauthCatalog(email ? {
1448
+ email: email
1449
+ } : undefined).catch(function (error) {
1450
+ _this14.initFailed = true;
1451
+ _this14.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1452
+ });
1453
+ }
1454
+ case 3:
1455
+ case "end":
1456
+ return _context4.stop();
1457
+ }
1458
+ }, _callee4);
1459
+ })));
1460
+ },
1461
+ /**
1462
+ * Verified-ready initialization path. Blocks `webex.ready` until the initial
1463
+ * catalog fetch has settled (or timed out) AND any in-flight credentials
1464
+ * refresh has completed. Also handles the fresh-login case where OAuth
1465
+ * completes after `loaded` fires.
1466
+ *
1467
+ * @private
1468
+ * @param {ServiceCatalog} catalog
1469
+ * @returns {void}
1470
+ */
1471
+ _initializeCatalogsGated: function _initializeCatalogsGated(catalog) {
1472
+ var _this15 = this;
1473
+ // Wait for storage to be loaded before attempting to update the service
1474
+ // catalogs. We listen for 'loaded' instead of 'ready' because `services.ready`
1475
+ // now blocks `webex.ready` - listening to 'ready' would deadlock.
1476
+ this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1477
+ var warmed, supertoken, timeout, email;
1478
+ return _regenerator.default.wrap(function (_context5) {
1479
+ while (1) switch (_context5.prev = _context5.next) {
1480
+ case 0:
1481
+ _context5.next = 1;
1482
+ return _this15._loadCatalogFromCache();
1483
+ case 1:
1484
+ warmed = _context5.sent;
1485
+ if (!warmed) {
1486
+ _context5.next = 3;
1487
+ break;
1488
+ }
1489
+ catalog.isReady = true;
1490
+ _context5.next = 2;
1491
+ return _this15._finalizeReady();
1492
+ case 2:
1493
+ return _context5.abrupt("return");
1411
1494
  case 3:
1412
- supertoken = _this13.webex.credentials.supertoken; // Race init against a hard timeout so a hung request never leaves
1495
+ supertoken = _this15.webex.credentials.supertoken; // Race init against a hard timeout so a hung request never leaves
1413
1496
  // `services.ready` false forever - that would stall `webex.ready` and
1414
1497
  // leave the app on a permanent spinner.
1415
1498
  timeout = new _promise.default(function (_, reject) {
@@ -1418,44 +1501,43 @@ var Services = _webexPlugin.default.extend({
1418
1501
  }, SERVICES_INIT_TIMEOUT_MS);
1419
1502
  }); // Validate if the supertoken exists.
1420
1503
  if (supertoken && supertoken.access_token) {
1421
- _promise.default.race([_this13.initServiceCatalogs(), timeout]).then(function () {
1504
+ _promise.default.race([_this15.initServiceCatalogs(), timeout]).then(function () {
1422
1505
  catalog.isReady = true;
1423
1506
  }).catch(function (error) {
1424
- _this13.initFailed = true;
1425
- _this13.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1507
+ _this15.initFailed = true;
1508
+ _this15.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1426
1509
  }).finally(function () {
1427
- return _this13._finalizeReady();
1510
+ return _this15._finalizeReady();
1428
1511
  });
1429
1512
  } else {
1430
- email = _this13.webex.config.email;
1431
- _promise.default.race([_this13.collectPreauthCatalog(email ? {
1513
+ email = _this15.webex.config.email;
1514
+ _promise.default.race([_this15.collectPreauthCatalog(email ? {
1432
1515
  email: email
1433
1516
  } : undefined), timeout]).catch(function (error) {
1434
- _this13.initFailed = true;
1435
- _this13.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1517
+ _this15.initFailed = true;
1518
+ _this15.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1436
1519
  }).finally(function () {
1437
- return _this13._finalizeReady();
1520
+ return _this15._finalizeReady();
1438
1521
  });
1439
- // Listen for when credentials become available to fetch the full catalog.
1440
- // This handles fresh login where 'loaded' fires before OAuth completes.
1441
- _this13.listenToOnce(_this13.webex, 'change:canAuthorize', function () {
1442
- if (_this13.webex.canAuthorize && !catalog.status.postauth.ready) {
1443
- _this13.initServiceCatalogs().then(function () {
1444
- catalog.isReady = true;
1445
- }).catch(function (error) {
1446
- _this13.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1522
+
1523
+ // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1524
+ // for `canAuthorize` flipping true and then collect the postauth catalog.
1525
+ _this15.listenToOnce(_this15.webex, 'change:canAuthorize', function () {
1526
+ if (_this15.webex.canAuthorize && !catalog.status.postauth.ready) {
1527
+ _this15.initServiceCatalogs().catch(function (error) {
1528
+ _this15.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1447
1529
  });
1448
1530
  }
1449
1531
  });
1450
1532
  }
1451
1533
  case 4:
1452
1534
  case "end":
1453
- return _context4.stop();
1535
+ return _context5.stop();
1454
1536
  }
1455
- }, _callee4);
1537
+ }, _callee5);
1456
1538
  })));
1457
1539
  },
1458
- version: "3.12.0-webex-services-ready.1"
1540
+ version: "3.12.0-webex-services-ready.2"
1459
1541
  });
1460
1542
  /* eslint-enable no-underscore-dangle */
1461
1543
  var _default = exports.default = Services;