@webex/webex-core 3.12.0 → 3.13.0-next.10

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 (92) hide show
  1. package/.repo-context.json +653 -0
  2. package/.sdd/manifest.json +615 -0
  3. package/AGENTS.md +209 -0
  4. package/README.md +6 -3
  5. package/dist/config.js +46 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/credentials-config.js +21 -1
  8. package/dist/credentials-config.js.map +1 -1
  9. package/dist/index.js +14 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/interceptors/auth.js +10 -1
  12. package/dist/interceptors/auth.js.map +1 -1
  13. package/dist/interceptors/catalog-url.js +87 -0
  14. package/dist/interceptors/catalog-url.js.map +1 -0
  15. package/dist/interceptors/payload-transformer.js +25 -4
  16. package/dist/interceptors/payload-transformer.js.map +1 -1
  17. package/dist/lib/batcher.js +23 -7
  18. package/dist/lib/batcher.js.map +1 -1
  19. package/dist/lib/credentials/credentials.js +117 -5
  20. package/dist/lib/credentials/credentials.js.map +1 -1
  21. package/dist/lib/credentials/token.js +23 -9
  22. package/dist/lib/credentials/token.js.map +1 -1
  23. package/dist/lib/domains.js +90 -0
  24. package/dist/lib/domains.js.map +1 -0
  25. package/dist/lib/interceptors/service.js +5 -1
  26. package/dist/lib/interceptors/service.js.map +1 -1
  27. package/dist/lib/services/catalog-auth.js +114 -0
  28. package/dist/lib/services/catalog-auth.js.map +1 -0
  29. package/dist/lib/services/service-catalog.js +108 -18
  30. package/dist/lib/services/service-catalog.js.map +1 -1
  31. package/dist/lib/services/services.js +287 -40
  32. package/dist/lib/services/services.js.map +1 -1
  33. package/dist/lib/services-v2/service-catalog.js +14 -13
  34. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  35. package/dist/lib/services-v2/services-v2.js +294 -44
  36. package/dist/lib/services-v2/services-v2.js.map +1 -1
  37. package/dist/lib/static-asset-loader.js +153 -0
  38. package/dist/lib/static-asset-loader.js.map +1 -0
  39. package/dist/plugins/logger.js +1 -1
  40. package/dist/webex-core.js +11 -3
  41. package/dist/webex-core.js.map +1 -1
  42. package/docs/adr/index.md +32 -0
  43. package/docs/architecture.md +298 -0
  44. package/docs/getting-started.md +96 -0
  45. package/docs/index.md +55 -0
  46. package/docs/specs/README.md +76 -0
  47. package/package.json +13 -13
  48. package/schemas/repo-context.schema.json +796 -0
  49. package/src/config.js +50 -1
  50. package/src/credentials-config.js +22 -0
  51. package/src/docs/README.md +732 -0
  52. package/src/index.js +2 -0
  53. package/src/interceptors/auth.js +14 -1
  54. package/src/interceptors/catalog-url.js +66 -0
  55. package/src/interceptors/docs/README.md +658 -0
  56. package/src/interceptors/payload-transformer.js +23 -1
  57. package/src/lib/batcher.js +25 -10
  58. package/src/lib/credentials/credentials.js +106 -4
  59. package/src/lib/credentials/docs/README.md +847 -0
  60. package/src/lib/credentials/token.js +15 -8
  61. package/src/lib/domains.ts +94 -0
  62. package/src/lib/interceptors/service.js +11 -3
  63. package/src/lib/services/catalog-auth.js +112 -0
  64. package/src/lib/services/docs/README.md +737 -0
  65. package/src/lib/services/service-catalog.js +112 -16
  66. package/src/lib/services/services.js +274 -24
  67. package/src/lib/services-v2/docs/README.md +751 -0
  68. package/src/lib/services-v2/service-catalog.ts +16 -12
  69. package/src/lib/services-v2/services-v2.ts +282 -26
  70. package/src/lib/static-asset-loader.ts +128 -0
  71. package/src/lib/storage/docs/README.md +646 -0
  72. package/src/webex-core.js +8 -0
  73. package/test/fixtures/activation-email.ts +22 -0
  74. package/test/integration/spec/credentials/credentials.js +3 -1
  75. package/test/integration/spec/credentials/token.js +8 -0
  76. package/test/integration/spec/services/service-catalog.js +5 -0
  77. package/test/integration/spec/services/services.js +183 -112
  78. package/test/integration/spec/services-v2/services-v2.js +169 -98
  79. package/test/integration/spec/unit-browser/token.js +7 -2
  80. package/test/unit/spec/credentials/credentials.js +326 -3
  81. package/test/unit/spec/credentials/token.js +259 -6
  82. package/test/unit/spec/interceptors/auth.js +92 -1
  83. package/test/unit/spec/interceptors/catalog-url.js +224 -0
  84. package/test/unit/spec/interceptors/payload-transformer.js +119 -1
  85. package/test/unit/spec/lib/batcher.js +56 -0
  86. package/test/unit/spec/services/interceptors/service.js +35 -1
  87. package/test/unit/spec/services/service-catalog.js +368 -11
  88. package/test/unit/spec/services/services.js +783 -10
  89. package/test/unit/spec/services-v2/service-catalog.ts +134 -11
  90. package/test/unit/spec/services-v2/services-v2.ts +825 -10
  91. package/test/unit/spec/static-asset-loader.ts +224 -0
  92. package/test/unit/spec/webex-core.js +77 -1
@@ -25,6 +25,7 @@ var _sha = _interopRequireDefault(require("crypto-js/sha256"));
25
25
  var _lodash = require("lodash");
26
26
  var _webexPlugin = _interopRequireDefault(require("../webex-plugin"));
27
27
  var _metrics = _interopRequireDefault(require("../metrics"));
28
+ var _catalogAuth = require("./catalog-auth");
28
29
  var _serviceCatalog = _interopRequireDefault(require("./service-catalog"));
29
30
  var _serviceRegistry = _interopRequireDefault(require("./service-registry"));
30
31
  var _serviceState = _interopRequireDefault(require("./service-state"));
@@ -73,6 +74,21 @@ var Services = _webexPlugin.default.extend({
73
74
  validateDomains: ['boolean', false, true],
74
75
  initFailed: ['boolean', false, false]
75
76
  },
77
+ session: {
78
+ /**
79
+ * Becomes `true` once the initial catalog collection has completed
80
+ * (successfully or otherwise) and any in-flight credentials refresh has
81
+ * settled. Blocks `webex.ready` so consumers can rely on `webex.ready`
82
+ * implying "catalogs populated AND credential state stable".
83
+ * @instance
84
+ * @memberof Services
85
+ * @type {boolean}
86
+ */
87
+ ready: {
88
+ default: false,
89
+ type: 'boolean'
90
+ }
91
+ },
76
92
  _catalogs: new _weakMap.default(),
77
93
  _serviceUrls: null,
78
94
  _hostCatalog: null,
@@ -107,6 +123,39 @@ var Services = _webexPlugin.default.extend({
107
123
  _getCatalog: function _getCatalog() {
108
124
  return this._catalogs.get(this.webex);
109
125
  },
126
+ /**
127
+ * Remember a postauth catalog failure caused by HTTP 401 or 403.
128
+ * 401 means the access token was rejected. 403 means the token can be
129
+ * valid and the caller still has no access. A refresh or replay failure
130
+ * that replaced a catalog 401 is recorded as invalid_access_token.
131
+ * A refresh 403 keeps that original 401 on error.catalogAuthStatus.
132
+ * Other failures clear any previously stored auth failure.
133
+ *
134
+ * @private
135
+ * @param {Error} error
136
+ * @returns {void}
137
+ */
138
+ _recordCatalogAuthFailure: function _recordCatalogAuthFailure(error) {
139
+ (0, _catalogAuth.recordCatalogAuthFailure)(this, error);
140
+ },
141
+ /**
142
+ * @private
143
+ * @returns {{status: number, reason: string}|null}
144
+ */
145
+ _getCatalogAuthFailure: function _getCatalogAuthFailure() {
146
+ return (0, _catalogAuth.getCatalogAuthFailure)(this);
147
+ },
148
+ /**
149
+ * Build the rejection for a service that could not be resolved.
150
+ * A stored catalog auth failure replaces the generic not-found text.
151
+ *
152
+ * @private
153
+ * @param {string} fallbackMessage
154
+ * @returns {Error}
155
+ */
156
+ _serviceLookupError: function _serviceLookupError(fallbackMessage) {
157
+ return (0, _catalogAuth.serviceLookupError)(this, fallbackMessage);
158
+ },
110
159
  /**
111
160
  * Safely access localStorage if available; returns the Storage or null.
112
161
  * @returns {Storage|null}
@@ -244,15 +293,21 @@ var Services = _webexPlugin.default.extend({
244
293
  return !!((_hostCatalog$host = hostCatalog[host]) !== null && _hostCatalog$host !== void 0 && _hostCatalog$host.length);
245
294
  },
246
295
  /**
247
- * Checks if the current environment is an integration (INT) environment
248
- * by examining the u2c discovery URL from webex config.
296
+ * Checks if the current environment is an integration (INT) environment.
297
+ * Uses the explicit environment config when set, otherwise examines the u2c discovery URL.
249
298
  * INT environments use discovery URLs containing 'intb' (e.g., u2c-intb.ciscospark.com).
250
299
  * @returns {boolean} True if INT environment, false otherwise
251
300
  */
252
301
  isIntegrationEnvironment: function isIntegrationEnvironment() {
253
302
  try {
254
- var _this$webex, _this$webex$config, _this$webex$config$se, _this$webex$config$se2;
255
- var u2cUrl = ((_this$webex = this.webex) === null || _this$webex === void 0 ? void 0 : (_this$webex$config = _this$webex.config) === null || _this$webex$config === void 0 ? void 0 : (_this$webex$config$se = _this$webex$config.services) === null || _this$webex$config$se === void 0 ? void 0 : (_this$webex$config$se2 = _this$webex$config$se.discovery) === null || _this$webex$config$se2 === void 0 ? void 0 : _this$webex$config$se2.u2c) || '';
303
+ var _this$webex, _this$webex$config, _this$webex2, _this$webex2$config, _this$webex2$config$s, _this$webex2$config$s2;
304
+ var configuredEnvironment = (_this$webex = this.webex) === null || _this$webex === void 0 ? void 0 : (_this$webex$config = _this$webex.config) === null || _this$webex$config === void 0 ? void 0 : _this$webex$config.environment;
305
+ if (configuredEnvironment !== undefined) {
306
+ var isIntFromConfig = configuredEnvironment === 'integration';
307
+ this.logger.info("services: isIntegrationEnvironment: ".concat(isIntFromConfig, " (config)"));
308
+ return isIntFromConfig;
309
+ }
310
+ var u2cUrl = ((_this$webex2 = this.webex) === null || _this$webex2 === void 0 ? void 0 : (_this$webex2$config = _this$webex2.config) === null || _this$webex2$config === void 0 ? void 0 : (_this$webex2$config$s = _this$webex2$config.services) === null || _this$webex2$config$s === void 0 ? void 0 : (_this$webex2$config$s2 = _this$webex2$config$s.discovery) === null || _this$webex2$config$s2 === void 0 ? void 0 : _this$webex2$config$s2.u2c) || '';
256
311
  var isInt = u2cUrl.includes('intb');
257
312
  this.logger.info("services: isIntegrationEnvironment: ".concat(isInt));
258
313
  return isInt;
@@ -371,8 +426,17 @@ var Services = _webexPlugin.default.extend({
371
426
  catalog.updateServiceUrls(serviceGroup, formattedServiceHostMap);
372
427
  _this.updateCredentialsConfig();
373
428
  catalog.status[serviceGroup].collecting = false;
429
+
430
+ // A successful postauth catalog replaces any remembered 401/403.
431
+ // Preauth and signin updates leave that marker alone.
432
+ if (serviceGroup === 'postauth') {
433
+ (0, _catalogAuth.clearCatalogAuthFailure)(_this);
434
+ }
374
435
  }).catch(function (error) {
375
436
  catalog.status[serviceGroup].collecting = false;
437
+ if (serviceGroup === 'postauth') {
438
+ _this._recordCatalogAuthFailure(error);
439
+ }
376
440
  return _promise.default.reject(error);
377
441
  }));
378
442
  case 7:
@@ -791,7 +855,7 @@ var Services = _webexPlugin.default.extend({
791
855
  service_name: name
792
856
  }
793
857
  });
794
- return _promise.default.reject(new Error("services: service '".concat(name, "' was not found in any of the catalogs")));
858
+ return _promise.default.reject(this._serviceLookupError("services: service '".concat(name, "' was not found in any of the catalogs")));
795
859
  }
796
860
  return new _promise.default(function (resolve, reject) {
797
861
  var groupsToCheck = ['preauth', 'signin', 'postauth'];
@@ -814,7 +878,7 @@ var Services = _webexPlugin.default.extend({
814
878
  service_name: name
815
879
  }
816
880
  });
817
- reject(new Error("services: service '".concat(name, "' was not found after waiting")));
881
+ reject(_this6._serviceLookupError("services: service '".concat(name, "' was not found after waiting")));
818
882
  });
819
883
  });
820
884
  },
@@ -1060,9 +1124,11 @@ var Services = _webexPlugin.default.extend({
1060
1124
  authorization: token
1061
1125
  };
1062
1126
  }
1063
- return this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(function () {
1127
+ var sendRequest = function sendRequest() {
1064
1128
  return _this7.request(requestObject);
1065
- }, 'internal.get.u2c.time').then(function (_ref12) {
1129
+ };
1130
+ var responsePromise = this.webex.internal.newMetrics ? this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(sendRequest, 'internal.get.u2c.time') : sendRequest();
1131
+ return responsePromise.then(function (_ref12) {
1066
1132
  var body = _ref12.body;
1067
1133
  return body;
1068
1134
  });
@@ -1350,6 +1416,7 @@ var Services = _webexPlugin.default.extend({
1350
1416
 
1351
1417
  // Destructure the credentials plugin.
1352
1418
  var credentials = this.webex.credentials;
1419
+ var catalog = this._getCatalog();
1353
1420
 
1354
1421
  // Init a promise chain. Must be done as a Promise.resolve() to allow
1355
1422
  // credentials#getOrgId() to properly throw.
@@ -1366,9 +1433,13 @@ var Services = _webexPlugin.default.extend({
1366
1433
  }).then(function () {
1367
1434
  // Validate if the token is authorized.
1368
1435
  if (credentials.canAuthorize) {
1369
- // Attempt to collect the postauth catalog.
1370
-
1371
- return _this0.updateServices().catch(function () {
1436
+ // Attempt to collect the postauth catalog, then mark the catalog
1437
+ // ready. Setting `isReady` here - rather than only in the init
1438
+ // callers - means a slow postauth fetch that loses the gated-init
1439
+ // timeout race still marks the catalog ready once it completes.
1440
+ return _this0.updateServices().then(function () {
1441
+ catalog.isReady = true;
1442
+ }).catch(function () {
1372
1443
  _this0.initFailed = true;
1373
1444
  _this0.logger.warn('services: cannot retrieve postauth catalog');
1374
1445
  });
@@ -1378,6 +1449,62 @@ var Services = _webexPlugin.default.extend({
1378
1449
  return _promise.default.resolve();
1379
1450
  });
1380
1451
  },
1452
+ /**
1453
+ * Await any in-flight credentials refresh, then flip `services.ready` so
1454
+ * `webex.ready` can fire. Closes the parallel-refresh window: if a credential
1455
+ * refresh is in flight when initial catalog collection settles, we must not
1456
+ * signal ready until the refresh has resolved - otherwise downstream
1457
+ * consumers may observe `canAuthorize`/token state that is about to change
1458
+ * under them.
1459
+ *
1460
+ * @private
1461
+ * @returns {Promise<void>}
1462
+ */
1463
+ _finalizeReady: function _finalizeReady() {
1464
+ var _this1 = this;
1465
+ return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1466
+ var credentials;
1467
+ return _regenerator.default.wrap(function (_context4) {
1468
+ while (1) switch (_context4.prev = _context4.next) {
1469
+ case 0:
1470
+ credentials = _this1.webex.credentials;
1471
+ if (!(credentials && credentials.isRefreshing)) {
1472
+ _context4.next = 1;
1473
+ break;
1474
+ }
1475
+ _context4.next = 1;
1476
+ return new _promise.default(function (resolve) {
1477
+ credentials.once('change:isRefreshing', resolve);
1478
+ });
1479
+ case 1:
1480
+ _this1.ready = true;
1481
+ case 2:
1482
+ case "end":
1483
+ return _context4.stop();
1484
+ }
1485
+ }, _callee4);
1486
+ }))();
1487
+ },
1488
+ /**
1489
+ * Build a promise that rejects once the catalog init timeout elapses. Race
1490
+ * this against catalog collection so a hung request never leaves
1491
+ * `services.ready` false forever - that would stall `webex.ready` and leave
1492
+ * consumers waiting on it indefinitely. Timeout is configurable via
1493
+ * `config.services.catalogInitTimeout` (defaults to 15s in config). Created
1494
+ * lazily so paths that skip catalog collection never schedule a stray timer.
1495
+ *
1496
+ * @private
1497
+ * @returns {Promise<never>}
1498
+ */
1499
+ _makeInitTimeout: function _makeInitTimeout() {
1500
+ var _this$webex$config3, _this$webex$config3$s;
1501
+ var initTimeoutMs = (_this$webex$config3 = this.webex.config) === null || _this$webex$config3 === void 0 ? void 0 : (_this$webex$config3$s = _this$webex$config3.services) === null || _this$webex$config3$s === void 0 ? void 0 : _this$webex$config3$s.catalogInitTimeout;
1502
+ return new _promise.default(function (_, reject) {
1503
+ setTimeout(function () {
1504
+ return reject(new Error("services: init timed out after ".concat(initTimeoutMs, "ms")));
1505
+ }, initTimeoutMs);
1506
+ });
1507
+ },
1381
1508
  /**
1382
1509
  * Initializer
1383
1510
  *
@@ -1386,7 +1513,7 @@ var Services = _webexPlugin.default.extend({
1386
1513
  * @returns {Services}
1387
1514
  */
1388
1515
  initialize: function initialize() {
1389
- var _this1 = this;
1516
+ var _this10 = this;
1390
1517
  var catalog = new _serviceCatalog.default();
1391
1518
  var registry = new _serviceRegistry.default();
1392
1519
  var state = new _serviceState.default();
@@ -1394,56 +1521,176 @@ var Services = _webexPlugin.default.extend({
1394
1521
  this.registries.set(this.webex, registry);
1395
1522
  this.states.set(this.webex, state);
1396
1523
 
1397
- // Listen for configuration changes once.
1524
+ // Listen for configuration changes once. The config is not populated on the
1525
+ // webex instance until the `change:config` event fires, so any decision that
1526
+ // depends on config values (such as the gated-vs-ungated init below) must be
1527
+ // made from within this handler rather than synchronously in `initialize()`.
1398
1528
  this.listenToOnce(this.webex, 'change:config', function () {
1399
- _this1.initConfig();
1400
- });
1529
+ var _this10$webex$config, _this10$webex$config$;
1530
+ _this10.initConfig();
1401
1531
 
1532
+ // Feature flag: when enabled, `webex.ready` is blocked until the initial
1533
+ // catalog collection has settled AND any in-flight credentials refresh has
1534
+ // completed. When disabled (the default), preserves the pre-existing
1535
+ // behavior where `webex.ready` fires as soon as `webex.loaded` does and
1536
+ // the catalog is collected out-of-band.
1537
+ 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;
1538
+ if (waitForCatalogInit) {
1539
+ _this10._initializeCatalogsGated(catalog);
1540
+ } else {
1541
+ // Not gating - immediately mark ready so we do not block webex.ready.
1542
+ _this10.ready = true;
1543
+ _this10._initializeCatalogsUngated(catalog);
1544
+ }
1545
+ });
1546
+ },
1547
+ /**
1548
+ * Original (pre-verified-ready) initialization path. Runs on `webex.ready`
1549
+ * and collects catalogs opportunistically without blocking anything.
1550
+ *
1551
+ * @private
1552
+ * @param {ServiceCatalog} catalog
1553
+ * @returns {void}
1554
+ */
1555
+ _initializeCatalogsUngated: function _initializeCatalogsUngated(catalog) {
1556
+ var _this11 = this;
1402
1557
  // wait for webex instance to be ready before attempting
1403
1558
  // to update the service catalogs
1404
1559
  // this can cause a race condition because credentials may
1405
1560
  // not be valid when services is initialized
1406
- this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1407
- var cachedCatalog, supertoken, email;
1408
- return _regenerator.default.wrap(function (_context4) {
1409
- while (1) switch (_context4.prev = _context4.next) {
1561
+ this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1562
+ var cachedCatalog, supertoken, _this11$webex$config, _this11$webex$config$, email;
1563
+ return _regenerator.default.wrap(function (_context5) {
1564
+ while (1) switch (_context5.prev = _context5.next) {
1410
1565
  case 0:
1411
- _context4.next = 1;
1412
- return _this1._loadCatalogFromCache();
1566
+ _context5.next = 1;
1567
+ return _this11._loadCatalogFromCache();
1413
1568
  case 1:
1414
- cachedCatalog = _context4.sent;
1569
+ cachedCatalog = _context5.sent;
1415
1570
  if (!cachedCatalog) {
1416
- _context4.next = 2;
1571
+ _context5.next = 2;
1417
1572
  break;
1418
1573
  }
1419
1574
  catalog.isReady = true;
1420
- return _context4.abrupt("return");
1575
+ return _context5.abrupt("return");
1421
1576
  case 2:
1422
- supertoken = _this1.webex.credentials.supertoken; // Validate if the supertoken exists.
1577
+ supertoken = _this11.webex.credentials.supertoken; // Validate if the supertoken exists.
1578
+ if (!(supertoken && supertoken.access_token)) {
1579
+ _context5.next = 3;
1580
+ break;
1581
+ }
1582
+ // `initServiceCatalogs` marks the catalog ready internally once the
1583
+ // postauth catalog is collected.
1584
+ _this11.initServiceCatalogs().catch(function (error) {
1585
+ _this11.initFailed = true;
1586
+ _this11.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1587
+ });
1588
+ _context5.next = 5;
1589
+ break;
1590
+ case 3:
1591
+ email = _this11.webex.config.email;
1592
+ if (!(((_this11$webex$config = _this11.webex.config) === null || _this11$webex$config === void 0 ? void 0 : (_this11$webex$config$ = _this11$webex$config.services) === null || _this11$webex$config$ === void 0 ? void 0 : _this11$webex$config$.skipPreauthCatalogOnUnauthenticated) === true)) {
1593
+ _context5.next = 4;
1594
+ break;
1595
+ }
1596
+ _this11.logger.info('services: skipping preauth catalog collection while unauthenticated as per the config');
1597
+ return _context5.abrupt("return");
1598
+ case 4:
1599
+ _this11.collectPreauthCatalog(email ? {
1600
+ email: email
1601
+ } : undefined).catch(function (error) {
1602
+ _this11.initFailed = true;
1603
+ _this11.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1604
+ });
1605
+ case 5:
1606
+ case "end":
1607
+ return _context5.stop();
1608
+ }
1609
+ }, _callee5);
1610
+ })));
1611
+ },
1612
+ /**
1613
+ * Verified-ready initialization path. Blocks `webex.ready` until the initial
1614
+ * catalog fetch has settled (or timed out) AND any in-flight credentials
1615
+ * refresh has completed. Also handles the fresh-login case where OAuth
1616
+ * completes after `loaded` fires.
1617
+ *
1618
+ * @private
1619
+ * @param {ServiceCatalog} catalog
1620
+ * @returns {void}
1621
+ */
1622
+ _initializeCatalogsGated: function _initializeCatalogsGated(catalog) {
1623
+ var _this12 = this;
1624
+ // Wait for storage to be loaded before attempting to update the service
1625
+ // catalogs. We listen for 'loaded' instead of 'ready' because `services.ready`
1626
+ // now blocks `webex.ready` - listening to 'ready' would deadlock.
1627
+ this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
1628
+ var cachedCatalog, supertoken, _this12$webex$config, _this12$webex$config$, email;
1629
+ return _regenerator.default.wrap(function (_context6) {
1630
+ while (1) switch (_context6.prev = _context6.next) {
1631
+ case 0:
1632
+ _context6.next = 1;
1633
+ return _this12._loadCatalogFromCache();
1634
+ case 1:
1635
+ cachedCatalog = _context6.sent;
1636
+ if (!cachedCatalog) {
1637
+ _context6.next = 3;
1638
+ break;
1639
+ }
1640
+ catalog.isReady = true;
1641
+ _context6.next = 2;
1642
+ return _this12._finalizeReady();
1643
+ case 2:
1644
+ return _context6.abrupt("return");
1645
+ case 3:
1646
+ supertoken = _this12.webex.credentials.supertoken; // Validate if the supertoken exists.
1423
1647
  if (supertoken && supertoken.access_token) {
1424
- _this1.initServiceCatalogs().then(function () {
1425
- catalog.isReady = true;
1426
- }).catch(function (error) {
1427
- _this1.initFailed = true;
1428
- _this1.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1648
+ // `initServiceCatalogs` marks the catalog ready internally once the
1649
+ // postauth catalog is collected - even if it loses the timeout race
1650
+ // below, so a slow fetch still eventually flips `catalog.isReady`.
1651
+ _promise.default.race([_this12.initServiceCatalogs(), _this12._makeInitTimeout()]).catch(function (error) {
1652
+ _this12.initFailed = true;
1653
+ _this12.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1654
+ }).finally(function () {
1655
+ return _this12._finalizeReady();
1429
1656
  });
1430
1657
  } else {
1431
- email = _this1.webex.config.email;
1432
- _this1.collectPreauthCatalog(email ? {
1433
- email: email
1434
- } : undefined).catch(function (error) {
1435
- _this1.initFailed = true;
1436
- _this1.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1658
+ email = _this12.webex.config.email; // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1659
+ // for `canAuthorize` flipping true and then collect the postauth catalog.
1660
+ _this12.listenToOnce(_this12.webex, 'change:canAuthorize', function () {
1661
+ if (_this12.webex.canAuthorize && !catalog.status.postauth.ready) {
1662
+ // `initServiceCatalogs` marks the catalog ready internally.
1663
+ _this12.initServiceCatalogs().catch(function (error) {
1664
+ _this12.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1665
+ });
1666
+ }
1437
1667
  });
1668
+ if (((_this12$webex$config = _this12.webex.config) === null || _this12$webex$config === void 0 ? void 0 : (_this12$webex$config$ = _this12$webex$config.services) === null || _this12$webex$config$ === void 0 ? void 0 : _this12$webex$config$.skipPreauthCatalogOnUnauthenticated) === true) {
1669
+ // Skip the preauth catalog fetch (it will be collected manually
1670
+ // later), but still finalize `services.ready` so `webex.ready` is not
1671
+ // stalled while unauthenticated. No timeout is created here so there
1672
+ // is no stray timer or unhandled rejection.
1673
+ _this12.logger.info('services: skipping preauth catalog collection while unauthenticated as per the config');
1674
+ _this12._finalizeReady();
1675
+ } else {
1676
+ _promise.default.race([_this12.collectPreauthCatalog(email ? {
1677
+ email: email
1678
+ } : undefined), _this12._makeInitTimeout()]).catch(function (error) {
1679
+ _this12.initFailed = true;
1680
+ _this12.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1681
+ }).finally(function () {
1682
+ return _this12._finalizeReady();
1683
+ });
1684
+ }
1438
1685
  }
1439
- case 3:
1686
+ case 4:
1440
1687
  case "end":
1441
- return _context4.stop();
1688
+ return _context6.stop();
1442
1689
  }
1443
- }, _callee4);
1690
+ }, _callee6);
1444
1691
  })));
1445
1692
  },
1446
- version: "3.12.0"
1693
+ version: "3.13.0-next.10"
1447
1694
  });
1448
1695
  /* eslint-enable no-underscore-dangle */
1449
1696
  var _default = exports.default = Services;