@webex/webex-core 3.12.0-next.41 → 3.12.0-next.43

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.
@@ -1375,6 +1375,26 @@ var Services = _webexPlugin.default.extend({
1375
1375
  }, _callee3);
1376
1376
  }))();
1377
1377
  },
1378
+ /**
1379
+ * Build a promise that rejects once the catalog init timeout elapses. Race
1380
+ * this against catalog collection so a hung request never leaves
1381
+ * `services.ready` false forever - that would stall `webex.ready` and leave
1382
+ * consumers waiting on it indefinitely. Timeout is configurable via
1383
+ * `config.services.catalogInitTimeout` (defaults to 15s in config). Created
1384
+ * lazily so paths that skip catalog collection never schedule a stray timer.
1385
+ *
1386
+ * @private
1387
+ * @returns {Promise<never>}
1388
+ */
1389
+ _makeInitTimeout: function _makeInitTimeout() {
1390
+ var _this$webex$config4, _this$webex$config4$s;
1391
+ var initTimeoutMs = (_this$webex$config4 = this.webex.config) === null || _this$webex$config4 === void 0 ? void 0 : (_this$webex$config4$s = _this$webex$config4.services) === null || _this$webex$config4$s === void 0 ? void 0 : _this$webex$config4$s.catalogInitTimeout;
1392
+ return new _promise.default(function (_, reject) {
1393
+ setTimeout(function () {
1394
+ return reject(new Error("services: init timed out after ".concat(initTimeoutMs, "ms")));
1395
+ }, initTimeoutMs);
1396
+ });
1397
+ },
1378
1398
  /**
1379
1399
  * Initializer
1380
1400
  *
@@ -1423,7 +1443,7 @@ var Services = _webexPlugin.default.extend({
1423
1443
  // wait for webex instance to be ready before attempting
1424
1444
  // to update the service catalogs
1425
1445
  this.listenToOnce(this.webex, 'ready', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
1426
- var warmed, supertoken, email;
1446
+ var warmed, supertoken, _this14$webex$config, _this14$webex$config$, email;
1427
1447
  return _regenerator.default.wrap(function (_context4) {
1428
1448
  while (1) switch (_context4.prev = _context4.next) {
1429
1449
  case 0:
@@ -1439,23 +1459,34 @@ var Services = _webexPlugin.default.extend({
1439
1459
  return _context4.abrupt("return");
1440
1460
  case 2:
1441
1461
  supertoken = _this14.webex.credentials.supertoken; // Validate if the supertoken exists.
1442
- if (supertoken && supertoken.access_token) {
1443
- // `initServiceCatalogs` marks the catalog ready internally once the
1444
- // postauth catalog is collected.
1445
- _this14.initServiceCatalogs().catch(function (error) {
1446
- _this14.initFailed = true;
1447
- _this14.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1448
- });
1449
- } else {
1450
- email = _this14.webex.config.email;
1451
- _this14.collectPreauthCatalog(email ? {
1452
- email: email
1453
- } : undefined).catch(function (error) {
1454
- _this14.initFailed = true;
1455
- _this14.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1456
- });
1462
+ if (!(supertoken && supertoken.access_token)) {
1463
+ _context4.next = 3;
1464
+ break;
1457
1465
  }
1466
+ // `initServiceCatalogs` marks the catalog ready internally once the
1467
+ // postauth catalog is collected.
1468
+ _this14.initServiceCatalogs().catch(function (error) {
1469
+ _this14.initFailed = true;
1470
+ _this14.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1471
+ });
1472
+ _context4.next = 5;
1473
+ break;
1458
1474
  case 3:
1475
+ email = _this14.webex.config.email;
1476
+ if (!(((_this14$webex$config = _this14.webex.config) === null || _this14$webex$config === void 0 ? void 0 : (_this14$webex$config$ = _this14$webex$config.services) === null || _this14$webex$config$ === void 0 ? void 0 : _this14$webex$config$.skipPreauthCatalogOnUnauthenticated) === true)) {
1477
+ _context4.next = 4;
1478
+ break;
1479
+ }
1480
+ _this14.logger.info('services: skipping preauth catalog collection while unauthenticated as per the config');
1481
+ return _context4.abrupt("return");
1482
+ case 4:
1483
+ _this14.collectPreauthCatalog(email ? {
1484
+ email: email
1485
+ } : undefined).catch(function (error) {
1486
+ _this14.initFailed = true;
1487
+ _this14.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1488
+ });
1489
+ case 5:
1459
1490
  case "end":
1460
1491
  return _context4.stop();
1461
1492
  }
@@ -1478,8 +1509,7 @@ var Services = _webexPlugin.default.extend({
1478
1509
  // catalogs. We listen for 'loaded' instead of 'ready' because `services.ready`
1479
1510
  // now blocks `webex.ready` - listening to 'ready' would deadlock.
1480
1511
  this.listenToOnce(this.webex, 'loaded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
1481
- var _this15$webex$config, _this15$webex$config$;
1482
- var warmed, supertoken, initTimeoutMs, initServiceCatalogsTimeout, email;
1512
+ var warmed, supertoken, _this15$webex$config, _this15$webex$config$, email;
1483
1513
  return _regenerator.default.wrap(function (_context5) {
1484
1514
  while (1) switch (_context5.prev = _context5.next) {
1485
1515
  case 0:
@@ -1497,38 +1527,19 @@ var Services = _webexPlugin.default.extend({
1497
1527
  case 2:
1498
1528
  return _context5.abrupt("return");
1499
1529
  case 3:
1500
- supertoken = _this15.webex.credentials.supertoken; // Race init against a hard timeout so a hung request never leaves
1501
- // `services.ready` false forever - that would stall `webex.ready` and
1502
- // leave consumers waiting on it indefinitely. Timeout is configurable via
1503
- // `config.services.catalogInitTimeout` (defaults to 15s in config).
1504
- initTimeoutMs = (_this15$webex$config = _this15.webex.config) === null || _this15$webex$config === void 0 ? void 0 : (_this15$webex$config$ = _this15$webex$config.services) === null || _this15$webex$config$ === void 0 ? void 0 : _this15$webex$config$.catalogInitTimeout;
1505
- initServiceCatalogsTimeout = new _promise.default(function (_, reject) {
1506
- setTimeout(function () {
1507
- return reject(new Error("services: init timed out after ".concat(initTimeoutMs, "ms")));
1508
- }, initTimeoutMs);
1509
- }); // Validate if the supertoken exists.
1530
+ supertoken = _this15.webex.credentials.supertoken; // Validate if the supertoken exists.
1510
1531
  if (supertoken && supertoken.access_token) {
1511
1532
  // `initServiceCatalogs` marks the catalog ready internally once the
1512
1533
  // postauth catalog is collected - even if it loses the timeout race
1513
- // above, so a slow fetch still eventually flips `catalog.isReady`.
1514
- _promise.default.race([_this15.initServiceCatalogs(), initServiceCatalogsTimeout]).catch(function (error) {
1534
+ // below, so a slow fetch still eventually flips `catalog.isReady`.
1535
+ _promise.default.race([_this15.initServiceCatalogs(), _this15._makeInitTimeout()]).catch(function (error) {
1515
1536
  _this15.initFailed = true;
1516
1537
  _this15.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1517
1538
  }).finally(function () {
1518
1539
  return _this15._finalizeReady();
1519
1540
  });
1520
1541
  } else {
1521
- email = _this15.webex.config.email;
1522
- _promise.default.race([_this15.collectPreauthCatalog(email ? {
1523
- email: email
1524
- } : undefined), initServiceCatalogsTimeout]).catch(function (error) {
1525
- _this15.initFailed = true;
1526
- _this15.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1527
- }).finally(function () {
1528
- return _this15._finalizeReady();
1529
- });
1530
-
1531
- // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1542
+ email = _this15.webex.config.email; // Handle fresh login: 'loaded' fires before OAuth completes, so listen
1532
1543
  // for `canAuthorize` flipping true and then collect the postauth catalog.
1533
1544
  _this15.listenToOnce(_this15.webex, 'change:canAuthorize', function () {
1534
1545
  if (_this15.webex.canAuthorize && !catalog.status.postauth.ready) {
@@ -1538,6 +1549,23 @@ var Services = _webexPlugin.default.extend({
1538
1549
  });
1539
1550
  }
1540
1551
  });
1552
+ if (((_this15$webex$config = _this15.webex.config) === null || _this15$webex$config === void 0 ? void 0 : (_this15$webex$config$ = _this15$webex$config.services) === null || _this15$webex$config$ === void 0 ? void 0 : _this15$webex$config$.skipPreauthCatalogOnUnauthenticated) === true) {
1553
+ // Skip the preauth catalog fetch (it will be collected manually
1554
+ // later), but still finalize `services.ready` so `webex.ready` is not
1555
+ // stalled while unauthenticated. No timeout is created here so there
1556
+ // is no stray timer or unhandled rejection.
1557
+ _this15.logger.info('services: skipping preauth catalog collection while unauthenticated as per the config');
1558
+ _this15._finalizeReady();
1559
+ } else {
1560
+ _promise.default.race([_this15.collectPreauthCatalog(email ? {
1561
+ email: email
1562
+ } : undefined), _this15._makeInitTimeout()]).catch(function (error) {
1563
+ _this15.initFailed = true;
1564
+ _this15.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1565
+ }).finally(function () {
1566
+ return _this15._finalizeReady();
1567
+ });
1568
+ }
1541
1569
  }
1542
1570
  case 4:
1543
1571
  case "end":
@@ -1546,7 +1574,7 @@ var Services = _webexPlugin.default.extend({
1546
1574
  }, _callee5);
1547
1575
  })));
1548
1576
  },
1549
- version: "3.12.0-next.41"
1577
+ version: "3.12.0-next.43"
1550
1578
  });
1551
1579
  /* eslint-enable no-underscore-dangle */
1552
1580
  var _default = exports.default = Services;