@webex/webex-core 3.11.0-webex-services-ready.1 → 3.12.0-llmrefactor.1

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 (49) hide show
  1. package/README.md +5 -2
  2. package/dist/config.js +15 -0
  3. package/dist/config.js.map +1 -1
  4. package/dist/credentials-config.js +12 -0
  5. package/dist/credentials-config.js.map +1 -1
  6. package/dist/interceptors/redirect.js +1 -1
  7. package/dist/interceptors/redirect.js.map +1 -1
  8. package/dist/lib/batcher.js +23 -7
  9. package/dist/lib/batcher.js.map +1 -1
  10. package/dist/lib/credentials/credentials.js +48 -4
  11. package/dist/lib/credentials/credentials.js.map +1 -1
  12. package/dist/lib/credentials/token.js +1 -1
  13. package/dist/lib/domains.js +90 -0
  14. package/dist/lib/domains.js.map +1 -0
  15. package/dist/lib/services/service-catalog.js +6 -10
  16. package/dist/lib/services/service-catalog.js.map +1 -1
  17. package/dist/lib/services/services.js +208 -51
  18. package/dist/lib/services/services.js.map +1 -1
  19. package/dist/lib/services-v2/service-catalog.js +6 -12
  20. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  21. package/dist/lib/services-v2/services-v2.js +207 -46
  22. package/dist/lib/services-v2/services-v2.js.map +1 -1
  23. package/dist/plugins/logger.js +1 -1
  24. package/dist/webex-core.js +2 -2
  25. package/dist/webex-core.js.map +1 -1
  26. package/package.json +13 -13
  27. package/src/config.js +17 -0
  28. package/src/credentials-config.js +13 -0
  29. package/src/interceptors/redirect.js +4 -1
  30. package/src/lib/batcher.js +25 -10
  31. package/src/lib/credentials/credentials.js +50 -3
  32. package/src/lib/domains.ts +94 -0
  33. package/src/lib/services/service-catalog.js +6 -10
  34. package/src/lib/services/services.js +174 -37
  35. package/src/lib/services-v2/service-catalog.ts +6 -11
  36. package/src/lib/services-v2/services-v2.ts +173 -33
  37. package/test/fixtures/activation-email.ts +22 -0
  38. package/test/integration/spec/services/service-catalog.js +7 -6
  39. package/test/integration/spec/services/services.js +49 -24
  40. package/test/integration/spec/services-v2/services-v2.js +49 -24
  41. package/test/unit/spec/credentials/credentials.js +133 -2
  42. package/test/unit/spec/interceptors/auth.js +56 -0
  43. package/test/unit/spec/lib/batcher.js +56 -0
  44. package/test/unit/spec/services/service-catalog.js +93 -11
  45. package/test/unit/spec/services/services.js +458 -322
  46. package/test/unit/spec/services-v2/service-catalog.ts +93 -11
  47. package/test/unit/spec/services-v2/services-v2.ts +403 -214
  48. package/test/unit/spec/webex-core.js +0 -2
  49. package/test/unit/spec/webex-internal-core.js +0 -2
@@ -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)
@@ -75,8 +75,10 @@ var Services = _webexPlugin.default.extend({
75
75
  },
76
76
  session: {
77
77
  /**
78
- * Becomes `true` once service catalog initialization has completed.
79
- * Blocks `webex.ready` until services are initialized.
78
+ * Becomes `true` once the initial catalog collection has completed
79
+ * (successfully or otherwise) and any in-flight credentials refresh has
80
+ * settled. Blocks `webex.ready` so consumers can rely on `webex.ready`
81
+ * implying "catalogs populated AND credential state stable".
80
82
  * @instance
81
83
  * @memberof Services
82
84
  * @type {boolean}
@@ -256,6 +258,24 @@ var Services = _webexPlugin.default.extend({
256
258
  var hostCatalog = this._hostCatalog || {};
257
259
  return !!((_hostCatalog$host = hostCatalog[host]) !== null && _hostCatalog$host !== void 0 && _hostCatalog$host.length);
258
260
  },
261
+ /**
262
+ * Checks if the current environment is an integration (INT) environment
263
+ * by examining the u2c discovery URL from webex config.
264
+ * INT environments use discovery URLs containing 'intb' (e.g., u2c-intb.ciscospark.com).
265
+ * @returns {boolean} True if INT environment, false otherwise
266
+ */
267
+ isIntegrationEnvironment: function isIntegrationEnvironment() {
268
+ try {
269
+ var _this$webex, _this$webex$config, _this$webex$config$se, _this$webex$config$se2;
270
+ 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) || '';
271
+ var isInt = u2cUrl.includes('intb');
272
+ this.logger.info("services: isIntegrationEnvironment: ".concat(isInt));
273
+ return isInt;
274
+ } catch (error) {
275
+ this.logger.error('services: failed to determine integration environment', error);
276
+ return false;
277
+ }
278
+ },
259
279
  /**
260
280
  * Merge provided active cluster mappings into current state.
261
281
  * @param {Record<string,string>} activeServices
@@ -1284,9 +1304,9 @@ var Services = _webexPlugin.default.extend({
1284
1304
  initConfig: function initConfig() {
1285
1305
  // Get the catalog and destructure the services config.
1286
1306
  var catalog = this._getCatalog();
1287
- var _this$webex$config = this.webex.config,
1288
- services = _this$webex$config.services,
1289
- fedramp = _this$webex$config.fedramp;
1307
+ var _this$webex$config2 = this.webex.config,
1308
+ services = _this$webex$config2.services,
1309
+ fedramp = _this$webex$config2.fedramp;
1290
1310
 
1291
1311
  // Validate that the services configuration exists.
1292
1312
  if (services) {
@@ -1345,6 +1365,7 @@ var Services = _webexPlugin.default.extend({
1345
1365
 
1346
1366
  // Destructure the credentials plugin.
1347
1367
  var credentials = this.webex.credentials;
1368
+ var catalog = this._getCatalog();
1348
1369
 
1349
1370
  // Init a promise chain. Must be done as a Promise.resolve() to allow
1350
1371
  // credentials#getOrgId() to properly throw.
@@ -1361,9 +1382,13 @@ var Services = _webexPlugin.default.extend({
1361
1382
  }).then(function () {
1362
1383
  // Validate if the token is authorized.
1363
1384
  if (credentials.canAuthorize) {
1364
- // Attempt to collect the postauth catalog.
1365
-
1366
- return _this0.updateServices().catch(function () {
1385
+ // Attempt to collect the postauth catalog, then mark the catalog
1386
+ // ready. Setting `isReady` here - rather than only in the init
1387
+ // callers - means a slow postauth fetch that loses the gated-init
1388
+ // timeout race still marks the catalog ready once it completes.
1389
+ return _this0.updateServices().then(function () {
1390
+ catalog.isReady = true;
1391
+ }).catch(function () {
1367
1392
  _this0.initFailed = true;
1368
1393
  _this0.logger.warn('services: cannot retrieve postauth catalog');
1369
1394
  });
@@ -1373,6 +1398,42 @@ var Services = _webexPlugin.default.extend({
1373
1398
  return _promise.default.resolve();
1374
1399
  });
1375
1400
  },
1401
+ /**
1402
+ * Await any in-flight credentials refresh, then flip `services.ready` so
1403
+ * `webex.ready` can fire. Closes the parallel-refresh window: if a credential
1404
+ * refresh is in flight when initial catalog collection settles, we must not
1405
+ * signal ready until the refresh has resolved - otherwise downstream
1406
+ * consumers may observe `canAuthorize`/token state that is about to change
1407
+ * under them.
1408
+ *
1409
+ * @private
1410
+ * @returns {Promise<void>}
1411
+ */
1412
+ _finalizeReady: function _finalizeReady() {
1413
+ var _this1 = this;
1414
+ return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1415
+ var credentials;
1416
+ return _regenerator.default.wrap(function (_context4) {
1417
+ while (1) switch (_context4.prev = _context4.next) {
1418
+ case 0:
1419
+ credentials = _this1.webex.credentials;
1420
+ if (!(credentials && credentials.isRefreshing)) {
1421
+ _context4.next = 1;
1422
+ break;
1423
+ }
1424
+ _context4.next = 1;
1425
+ return new _promise.default(function (resolve) {
1426
+ credentials.once('change:isRefreshing', resolve);
1427
+ });
1428
+ case 1:
1429
+ _this1.ready = true;
1430
+ case 2:
1431
+ case "end":
1432
+ return _context4.stop();
1433
+ }
1434
+ }, _callee4);
1435
+ }))();
1436
+ },
1376
1437
  /**
1377
1438
  * Initializer
1378
1439
  *
@@ -1381,7 +1442,7 @@ var Services = _webexPlugin.default.extend({
1381
1442
  * @returns {Services}
1382
1443
  */
1383
1444
  initialize: function initialize() {
1384
- var _this1 = this;
1445
+ var _this10 = this;
1385
1446
  var catalog = new _serviceCatalog.default();
1386
1447
  var registry = new _serviceRegistry.default();
1387
1448
  var state = new _serviceState.default();
@@ -1389,72 +1450,168 @@ var Services = _webexPlugin.default.extend({
1389
1450
  this.registries.set(this.webex, registry);
1390
1451
  this.states.set(this.webex, state);
1391
1452
 
1392
- // Listen for configuration changes once.
1453
+ // Listen for configuration changes once. The config is not populated on the
1454
+ // webex instance until the `change:config` event fires, so any decision that
1455
+ // depends on config values (such as the gated-vs-ungated init below) must be
1456
+ // made from within this handler rather than synchronously in `initialize()`.
1393
1457
  this.listenToOnce(this.webex, 'change:config', function () {
1394
- _this1.initConfig();
1395
- });
1458
+ var _this10$webex$config, _this10$webex$config$;
1459
+ _this10.initConfig();
1396
1460
 
1397
- // Wait for storage to be loaded before attempting to update the service catalogs.
1398
- // We listen for 'loaded' instead of 'ready' because services.ready is a dependency
1399
- // of webex.ready - listening to 'ready' would cause a deadlock.
1400
- this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1461
+ // Feature flag: when enabled, `webex.ready` is blocked until the initial
1462
+ // catalog collection has settled AND any in-flight credentials refresh has
1463
+ // completed. When disabled (the default), preserves the pre-existing
1464
+ // behavior where `webex.ready` fires as soon as `webex.loaded` does and
1465
+ // the catalog is collected out-of-band.
1466
+ 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;
1467
+ if (waitForCatalogInit) {
1468
+ _this10._initializeCatalogsGated(catalog);
1469
+ } else {
1470
+ // Not gating - immediately mark ready so we do not block webex.ready.
1471
+ _this10.ready = true;
1472
+ _this10._initializeCatalogsUngated(catalog);
1473
+ }
1474
+ });
1475
+ },
1476
+ /**
1477
+ * Original (pre-verified-ready) initialization path. Runs on `webex.ready`
1478
+ * and collects catalogs opportunistically without blocking anything.
1479
+ *
1480
+ * @private
1481
+ * @param {ServiceCatalog} catalog
1482
+ * @returns {void}
1483
+ */
1484
+ _initializeCatalogsUngated: function _initializeCatalogsUngated(catalog) {
1485
+ var _this11 = this;
1486
+ // wait for webex instance to be ready before attempting
1487
+ // to update the service catalogs
1488
+ // this can cause a race condition because credentials may
1489
+ // not be valid when services is initialized
1490
+ this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1401
1491
  var cachedCatalog, supertoken, email;
1402
- return _regenerator.default.wrap(function (_context4) {
1403
- while (1) switch (_context4.prev = _context4.next) {
1492
+ return _regenerator.default.wrap(function (_context5) {
1493
+ while (1) switch (_context5.prev = _context5.next) {
1404
1494
  case 0:
1405
- _context4.next = 1;
1406
- return _this1._loadCatalogFromCache();
1495
+ _context5.next = 1;
1496
+ return _this11._loadCatalogFromCache();
1407
1497
  case 1:
1408
- cachedCatalog = _context4.sent;
1498
+ cachedCatalog = _context5.sent;
1409
1499
  if (!cachedCatalog) {
1410
- _context4.next = 2;
1500
+ _context5.next = 2;
1411
1501
  break;
1412
1502
  }
1413
1503
  catalog.isReady = true;
1414
- return _context4.abrupt("return");
1504
+ return _context5.abrupt("return");
1415
1505
  case 2:
1416
- supertoken = _this1.webex.credentials.supertoken; // Validate if the supertoken exists.
1506
+ supertoken = _this11.webex.credentials.supertoken; // Validate if the supertoken exists.
1417
1507
  if (supertoken && supertoken.access_token) {
1418
- _this1.initServiceCatalogs().then(function () {
1419
- catalog.isReady = true;
1420
- }).catch(function (error) {
1421
- _this1.initFailed = true;
1422
- _this1.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1423
- }).finally(function () {
1424
- _this1.ready = true;
1425
- _this1.trigger('services:initialized');
1508
+ // `initServiceCatalogs` marks the catalog ready internally once the
1509
+ // postauth catalog is collected.
1510
+ _this11.initServiceCatalogs().catch(function (error) {
1511
+ _this11.initFailed = true;
1512
+ _this11.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1426
1513
  });
1427
1514
  } else {
1428
- email = _this1.webex.config.email;
1429
- _this1.collectPreauthCatalog(email ? {
1515
+ email = _this11.webex.config.email;
1516
+ _this11.collectPreauthCatalog(email ? {
1430
1517
  email: email
1431
1518
  } : undefined).catch(function (error) {
1432
- _this1.initFailed = true;
1433
- _this1.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1519
+ _this11.initFailed = true;
1520
+ _this11.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1521
+ });
1522
+ }
1523
+ case 3:
1524
+ case "end":
1525
+ return _context5.stop();
1526
+ }
1527
+ }, _callee5);
1528
+ })));
1529
+ },
1530
+ /**
1531
+ * Verified-ready initialization path. Blocks `webex.ready` until the initial
1532
+ * catalog fetch has settled (or timed out) AND any in-flight credentials
1533
+ * refresh has completed. Also handles the fresh-login case where OAuth
1534
+ * completes after `loaded` fires.
1535
+ *
1536
+ * @private
1537
+ * @param {ServiceCatalog} catalog
1538
+ * @returns {void}
1539
+ */
1540
+ _initializeCatalogsGated: function _initializeCatalogsGated(catalog) {
1541
+ var _this12 = this;
1542
+ // Wait for storage to be loaded before attempting to update the service
1543
+ // catalogs. We listen for 'loaded' instead of 'ready' because `services.ready`
1544
+ // now blocks `webex.ready` - listening to 'ready' would deadlock.
1545
+ this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
1546
+ var _this12$webex$config, _this12$webex$config$;
1547
+ var cachedCatalog, supertoken, initTimeoutMs, initServiceCatalogsTimeout, 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
1566
+ // `services.ready` false forever - that would stall `webex.ready` and
1567
+ // leave consumers waiting on it indefinitely. Timeout is configurable via
1568
+ // `config.services.catalogInitTimeout` (defaults to 15s in config).
1569
+ initTimeoutMs = (_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$.catalogInitTimeout;
1570
+ initServiceCatalogsTimeout = new _promise.default(function (_, reject) {
1571
+ setTimeout(function () {
1572
+ return reject(new Error("services: init timed out after ".concat(initTimeoutMs, "ms")));
1573
+ }, initTimeoutMs);
1574
+ }); // Validate if the supertoken exists.
1575
+ if (supertoken && supertoken.access_token) {
1576
+ // `initServiceCatalogs` marks the catalog ready internally once the
1577
+ // postauth catalog is collected - even if it loses the timeout race
1578
+ // above, so a slow fetch still eventually flips `catalog.isReady`.
1579
+ _promise.default.race([_this12.initServiceCatalogs(), initServiceCatalogsTimeout]).catch(function (error) {
1580
+ _this12.initFailed = true;
1581
+ _this12.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1434
1582
  }).finally(function () {
1435
- _this1.ready = true;
1436
- _this1.trigger('services:initialized');
1583
+ return _this12._finalizeReady();
1437
1584
  });
1438
- // Listen for when credentials become available to fetch the full catalog.
1439
- // This handles fresh login where 'loaded' fires before OAuth completes.
1440
- _this1.listenToOnce(_this1.webex, 'change:canAuthorize', function () {
1441
- if (_this1.webex.canAuthorize && !catalog.status.postauth.ready) {
1442
- _this1.initServiceCatalogs().then(function () {
1443
- catalog.isReady = true;
1444
- }).catch(function (error) {
1445
- _this1.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1585
+ } else {
1586
+ email = _this12.webex.config.email;
1587
+ _promise.default.race([_this12.collectPreauthCatalog(email ? {
1588
+ email: email
1589
+ } : undefined), initServiceCatalogsTimeout]).catch(function (error) {
1590
+ _this12.initFailed = true;
1591
+ _this12.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1592
+ }).finally(function () {
1593
+ return _this12._finalizeReady();
1594
+ });
1595
+
1596
+ // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1597
+ // for `canAuthorize` flipping true and then collect the postauth catalog.
1598
+ _this12.listenToOnce(_this12.webex, 'change:canAuthorize', function () {
1599
+ if (_this12.webex.canAuthorize && !catalog.status.postauth.ready) {
1600
+ // `initServiceCatalogs` marks the catalog ready internally.
1601
+ _this12.initServiceCatalogs().catch(function (error) {
1602
+ _this12.logger.error("services: failed to init service catalogs after auth, ".concat(error === null || error === void 0 ? void 0 : error.message));
1446
1603
  });
1447
1604
  }
1448
1605
  });
1449
1606
  }
1450
- case 3:
1607
+ case 4:
1451
1608
  case "end":
1452
- return _context4.stop();
1609
+ return _context6.stop();
1453
1610
  }
1454
- }, _callee4);
1611
+ }, _callee6);
1455
1612
  })));
1456
1613
  },
1457
- version: "3.11.0-webex-services-ready.1"
1614
+ version: "3.12.0-llmrefactor.1"
1458
1615
  });
1459
1616
  /* eslint-enable no-underscore-dangle */
1460
1617
  var _default = exports.default = Services;