@webex/webex-core 3.12.0-next.8 → 3.12.0-task-refactor.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.
@@ -11,16 +11,12 @@ _Object$defineProperty(exports, "__esModule", {
11
11
  value: true
12
12
  });
13
13
  exports.default = exports.DEFAULT_CLUSTER_SERVICE = exports.DEFAULT_CLUSTER = void 0;
14
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
15
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
16
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
17
15
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
18
16
  var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
19
17
  var _entries = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/entries"));
20
18
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
21
19
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
22
- var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
23
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
24
20
  var _sha = _interopRequireDefault(require("crypto-js/sha256"));
25
21
  var _lodash = require("lodash");
26
22
  var _webexPlugin = _interopRequireDefault(require("../webex-plugin"));
@@ -40,8 +36,6 @@ var DEFAULT_CLUSTER = exports.DEFAULT_CLUSTER = 'urn:TEAM:us-east-2_a';
40
36
  var DEFAULT_CLUSTER_SERVICE = exports.DEFAULT_CLUSTER_SERVICE = 'identityLookup';
41
37
  var CLUSTER_SERVICE = process.env.WEBEX_CONVERSATION_CLUSTER_SERVICE || DEFAULT_CLUSTER_SERVICE;
42
38
  var DEFAULT_CLUSTER_IDENTIFIER = process.env.WEBEX_CONVERSATION_DEFAULT_CLUSTER || "".concat(DEFAULT_CLUSTER, ":").concat(CLUSTER_SERVICE);
43
- var CATALOG_CACHE_KEY_V1 = 'services.v1.u2cHostMap';
44
- var CATALOG_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
45
39
 
46
40
  /* eslint-disable no-underscore-dangle */
47
41
  /**
@@ -107,45 +101,6 @@ var Services = _webexPlugin.default.extend({
107
101
  _getCatalog: function _getCatalog() {
108
102
  return this._catalogs.get(this.webex);
109
103
  },
110
- /**
111
- * Safely access localStorage if available; returns the Storage or null.
112
- * @returns {Storage|null}
113
- */
114
- _getLocalStorageSafe: function _getLocalStorageSafe() {
115
- if (typeof window !== 'undefined' && window.localStorage) {
116
- return window.localStorage;
117
- }
118
- return null;
119
- },
120
- /**
121
- * Determine the intended preauth selection based on the current context.
122
- * @param {string|undefined} currentOrgId
123
- * @returns {{selectionType: string, selectionValue: string}}
124
- */
125
- getIntendedPreauthSelection: function getIntendedPreauthSelection(currentOrgId) {
126
- var _this$webex$credentia;
127
- if ((_this$webex$credentia = this.webex.credentials) !== null && _this$webex$credentia !== void 0 && _this$webex$credentia.canAuthorize) {
128
- if (currentOrgId) {
129
- return {
130
- selectionType: 'orgId',
131
- selectionValue: currentOrgId
132
- };
133
- }
134
- }
135
- var emailConfig = this.webex.config && this.webex.config.email;
136
- if (typeof emailConfig === 'string' && emailConfig.trim()) {
137
- return {
138
- selectionType: 'emailhash',
139
- selectionValue: (0, _sha.default)(emailConfig.toLowerCase()).toString()
140
- };
141
- }
142
-
143
- // fall back to proximity mode when no orgId or email available
144
- return {
145
- selectionType: 'mode',
146
- selectionValue: 'DEFAULT_BY_PROXIMITY'
147
- };
148
- },
149
104
  /**
150
105
  * Get a service url from the current services list by name
151
106
  * from the associated instance catalog.
@@ -206,10 +161,9 @@ var Services = _webexPlugin.default.extend({
206
161
  },
207
162
  /**
208
163
  * Get all Mobius cluster host entries from the legacy host catalog.
209
- * @returns {Array<{host: string, id: string, ttl: number, priority: number}>}
164
+ * @returns {Array<Object>}
210
165
  */
211
166
  getMobiusClusters: function getMobiusClusters() {
212
- this.logger.info('services: fetching mobius clusters');
213
167
  var clusters = [];
214
168
  var hostCatalog = this._hostCatalog || {};
215
169
  (0, _entries.default)(hostCatalog).forEach(function (_ref) {
@@ -243,24 +197,6 @@ var Services = _webexPlugin.default.extend({
243
197
  var hostCatalog = this._hostCatalog || {};
244
198
  return !!((_hostCatalog$host = hostCatalog[host]) !== null && _hostCatalog$host !== void 0 && _hostCatalog$host.length);
245
199
  },
246
- /**
247
- * Checks if the current environment is an integration (INT) environment
248
- * by examining the u2c discovery URL from webex config.
249
- * INT environments use discovery URLs containing 'intb' (e.g., u2c-intb.ciscospark.com).
250
- * @returns {boolean} True if INT environment, false otherwise
251
- */
252
- isIntegrationEnvironment: function isIntegrationEnvironment() {
253
- 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) || '';
256
- var isInt = u2cUrl.includes('intb');
257
- this.logger.info("services: isIntegrationEnvironment: ".concat(isInt));
258
- return isInt;
259
- } catch (error) {
260
- this.logger.error('services: failed to determine integration environment', error);
261
- return false;
262
- }
263
- },
264
200
  /**
265
201
  * Merge provided active cluster mappings into current state.
266
202
  * @param {Record<string,string>} activeServices
@@ -299,88 +235,63 @@ var Services = _webexPlugin.default.extend({
299
235
  * @returns {Promise<object>}
300
236
  */
301
237
  updateServices: function updateServices() {
302
- var _arguments = arguments,
303
- _this = this;
304
- return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
305
- var _ref3, from, query, token, forceRefresh, catalog, formattedQuery, serviceGroup, queryKey, _queryKey, _t;
306
- return _regenerator.default.wrap(function (_context) {
307
- while (1) switch (_context.prev = _context.next) {
308
- case 0:
309
- _ref3 = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {}, from = _ref3.from, query = _ref3.query, token = _ref3.token, forceRefresh = _ref3.forceRefresh;
310
- catalog = _this._getCatalog();
311
- _t = from;
312
- _context.next = _t === 'limited' ? 1 : _t === 'signin' ? 2 : 3;
313
- break;
314
- case 1:
315
- serviceGroup = 'preauth';
316
- return _context.abrupt("continue", 4);
317
- case 2:
318
- serviceGroup = 'signin';
319
- return _context.abrupt("continue", 4);
320
- case 3:
321
- serviceGroup = 'postauth';
322
- return _context.abrupt("continue", 4);
323
- case 4:
324
- if (!catalog.status[serviceGroup].collecting) {
325
- _context.next = 5;
326
- break;
327
- }
328
- return _context.abrupt("return", _this.waitForCatalog(serviceGroup));
329
- case 5:
330
- catalog.status[serviceGroup].collecting = true;
331
- if (!(serviceGroup === 'preauth')) {
332
- _context.next = 6;
333
- break;
334
- }
335
- queryKey = query && (0, _keys.default)(query)[0];
336
- if (['email', 'emailhash', 'userId', 'orgId', 'mode'].includes(queryKey)) {
337
- _context.next = 6;
338
- break;
339
- }
340
- return _context.abrupt("return", _promise.default.reject(new Error('a query param of email, emailhash, userId, orgId, or mode is required')));
341
- case 6:
342
- // encode email when query key is email
343
- if (serviceGroup === 'preauth' || serviceGroup === 'signin') {
344
- _queryKey = (0, _keys.default)(query)[0];
345
- formattedQuery = {};
346
- if (_queryKey === 'email' && query.email) {
347
- formattedQuery.emailhash = (0, _sha.default)(query.email.toLowerCase()).toString();
348
- } else {
349
- formattedQuery[_queryKey] = query[_queryKey];
350
- }
351
- }
352
- return _context.abrupt("return", _this._fetchNewServiceHostmap({
353
- from: from,
354
- token: token,
355
- query: formattedQuery,
356
- forceRefresh: forceRefresh
357
- }).then(function (serviceHostMap) {
358
- var formattedServiceHostMap = _this._formatReceivedHostmap(serviceHostMap);
359
- // Build selection metadata for caching discrimination
360
- var selectionMeta;
361
- if (serviceGroup === 'preauth' || serviceGroup === 'signin') {
362
- var key = formattedQuery && (0, _keys.default)(formattedQuery || {})[0];
363
- if (key) {
364
- selectionMeta = {
365
- selectionType: key,
366
- selectionValue: formattedQuery[key]
367
- };
368
- }
369
- }
370
- _this._cacheCatalog(serviceGroup, serviceHostMap, selectionMeta);
371
- catalog.updateServiceUrls(serviceGroup, formattedServiceHostMap);
372
- _this.updateCredentialsConfig();
373
- catalog.status[serviceGroup].collecting = false;
374
- }).catch(function (error) {
375
- catalog.status[serviceGroup].collecting = false;
376
- return _promise.default.reject(error);
377
- }));
378
- case 7:
379
- case "end":
380
- return _context.stop();
381
- }
382
- }, _callee);
383
- }))();
238
+ var _this = this;
239
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
240
+ from = _ref3.from,
241
+ query = _ref3.query,
242
+ token = _ref3.token,
243
+ forceRefresh = _ref3.forceRefresh;
244
+ var catalog = this._getCatalog();
245
+ var formattedQuery;
246
+ var serviceGroup;
247
+
248
+ // map catalog name to service group name.
249
+ switch (from) {
250
+ case 'limited':
251
+ serviceGroup = 'preauth';
252
+ break;
253
+ case 'signin':
254
+ serviceGroup = 'signin';
255
+ break;
256
+ default:
257
+ serviceGroup = 'postauth';
258
+ break;
259
+ }
260
+
261
+ // confirm catalog update for group is not in progress.
262
+ if (catalog.status[serviceGroup].collecting) {
263
+ return this.waitForCatalog(serviceGroup);
264
+ }
265
+ catalog.status[serviceGroup].collecting = true;
266
+ if (serviceGroup === 'preauth') {
267
+ var queryKey = query && (0, _keys.default)(query)[0];
268
+ if (!['email', 'emailhash', 'userId', 'orgId', 'mode'].includes(queryKey)) {
269
+ return _promise.default.reject(new Error('a query param of email, emailhash, userId, orgId, or mode is required'));
270
+ }
271
+ }
272
+ // encode email when query key is email
273
+ if (serviceGroup === 'preauth' || serviceGroup === 'signin') {
274
+ var _queryKey = (0, _keys.default)(query)[0];
275
+ formattedQuery = {};
276
+ if (_queryKey === 'email' && query.email) {
277
+ formattedQuery.emailhash = (0, _sha.default)(query.email.toLowerCase()).toString();
278
+ } else {
279
+ formattedQuery[_queryKey] = query[_queryKey];
280
+ }
281
+ }
282
+ return this._fetchNewServiceHostmap({
283
+ from: from,
284
+ token: token,
285
+ query: formattedQuery,
286
+ forceRefresh: forceRefresh
287
+ }).then(function (serviceHostMap) {
288
+ catalog.updateServiceUrls(serviceGroup, serviceHostMap);
289
+ _this.updateCredentialsConfig();
290
+ catalog.status[serviceGroup].collecting = false;
291
+ }).catch(function (error) {
292
+ catalog.status[serviceGroup].collecting = false;
293
+ return _promise.default.reject(error);
294
+ });
384
295
  },
385
296
  /**
386
297
  * User validation parameter transfer object for {@link validateUser}.
@@ -451,9 +362,9 @@ var Services = _webexPlugin.default.extend({
451
362
 
452
363
  // Destructure the client authorization details.
453
364
  /* eslint-disable camelcase */
454
- var _this$webex$credentia2 = this.webex.credentials.config,
455
- client_id = _this$webex$credentia2.client_id,
456
- client_secret = _this$webex$credentia2.client_secret;
365
+ var _this$webex$credentia = this.webex.credentials.config,
366
+ client_id = _this$webex$credentia.client_id,
367
+ client_secret = _this$webex$credentia.client_secret;
457
368
 
458
369
  // Validate that client authentication details exist.
459
370
  if (!client_id || !client_secret) {
@@ -1064,223 +975,9 @@ var Services = _webexPlugin.default.extend({
1064
975
  return _this7.request(requestObject);
1065
976
  }, 'internal.get.u2c.time').then(function (_ref12) {
1066
977
  var body = _ref12.body;
1067
- return body;
978
+ return _this7._formatReceivedHostmap(body);
1068
979
  });
1069
980
  },
1070
- /**
1071
- * Cache the catalog in the bounded storage.
1072
- * @param {string} serviceGroup - preauth, signin, postauth
1073
- * @param {object} hostMap - The hostmap to cache
1074
- * @param {object} [meta] - Optional selection metadata used to validate cache reuse
1075
- * @returns {Promise<void>}
1076
- *
1077
- */
1078
- _cacheCatalog: function _cacheCatalog(serviceGroup, hostMap, meta) {
1079
- var _this8 = this;
1080
- return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
1081
- var current, orgId, _this8$webex$config, _this8$webex$config$c, _this8$webex, _this8$webex$config2, _this8$webex2, _this8$webex2$config, _this8$webex2$config$, _this8$webex2$config$2, _ls, cachedJson, credentials, _current, env, fedramp, u2cDiscoveryUrl, updated, ls, _t2;
1082
- return _regenerator.default.wrap(function (_context2) {
1083
- while (1) switch (_context2.prev = _context2.next) {
1084
- case 0:
1085
- current = {};
1086
- _context2.prev = 1;
1087
- if ((_this8$webex$config = _this8.webex.config) !== null && _this8$webex$config !== void 0 && (_this8$webex$config$c = _this8$webex$config.calling) !== null && _this8$webex$config$c !== void 0 && _this8$webex$config$c.cacheU2C) {
1088
- _context2.next = 2;
1089
- break;
1090
- }
1091
- _this8.logger.info("services: skipping cache write for ".concat(serviceGroup, " as per the config"));
1092
- return _context2.abrupt("return");
1093
- case 2:
1094
- // Persist to localStorage to survive browser refresh
1095
- try {
1096
- _ls = _this8._getLocalStorageSafe();
1097
- cachedJson = _ls ? _ls.getItem(CATALOG_CACHE_KEY_V1) : null;
1098
- current = cachedJson ? JSON.parse(cachedJson) : {};
1099
- } catch (e) {
1100
- current = {};
1101
- }
1102
- try {
1103
- credentials = _this8.webex.credentials;
1104
- orgId = credentials.getOrgId();
1105
- } catch (e) {
1106
- orgId = current.orgId;
1107
- }
1108
-
1109
- // Capture environment fingerprint to invalidate cache across env changes
1110
- _current = current, env = _current.env;
1111
- fedramp = !!((_this8$webex = _this8.webex) !== null && _this8$webex !== void 0 && (_this8$webex$config2 = _this8$webex.config) !== null && _this8$webex$config2 !== void 0 && _this8$webex$config2.fedramp);
1112
- u2cDiscoveryUrl = (_this8$webex2 = _this8.webex) === null || _this8$webex2 === void 0 ? void 0 : (_this8$webex2$config = _this8$webex2.config) === null || _this8$webex2$config === void 0 ? void 0 : (_this8$webex2$config$ = _this8$webex2$config.services) === null || _this8$webex2$config$ === void 0 ? void 0 : (_this8$webex2$config$2 = _this8$webex2$config$.discovery) === null || _this8$webex2$config$2 === void 0 ? void 0 : _this8$webex2$config$2.u2c;
1113
- env = {
1114
- fedramp: fedramp,
1115
- u2cDiscoveryUrl: u2cDiscoveryUrl
1116
- };
1117
- updated = _objectSpread(_objectSpread({}, current), {}, (0, _defineProperty2.default)((0, _defineProperty2.default)({
1118
- orgId: orgId || current.orgId,
1119
- env: env || current.env
1120
- }, serviceGroup, meta ? {
1121
- hostMap: hostMap,
1122
- meta: meta
1123
- } : hostMap), "cachedAt", (0, _now.default)()));
1124
- ls = _this8._getLocalStorageSafe();
1125
- if (ls) {
1126
- ls.setItem(CATALOG_CACHE_KEY_V1, (0, _stringify.default)(updated));
1127
- }
1128
- _context2.next = 4;
1129
- break;
1130
- case 3:
1131
- _context2.prev = 3;
1132
- _t2 = _context2["catch"](1);
1133
- _this8.logger.warn('services: error caching catalog', _t2);
1134
- case 4:
1135
- case "end":
1136
- return _context2.stop();
1137
- }
1138
- }, _callee2, null, [[1, 3]]);
1139
- }))();
1140
- },
1141
- /**
1142
- * Load the catalog from cache and hydrate the in-memory ServiceCatalog.
1143
- * @returns {Promise<boolean>} true if cache was loaded, false otherwise
1144
- */
1145
- _loadCatalogFromCache: function _loadCatalogFromCache() {
1146
- var _this9 = this;
1147
- return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
1148
- var currentOrgId, _this9$webex$config, _this9$webex$config$c, _this9$webex$config2, _this9$webex$config3, _this9$webex$config3$, _this9$webex$config3$2, ls, cachedJson, cached, cachedAt, _this9$webex$credenti, credentials, fedramp, u2cDiscoveryUrl, currentEnv, sameEnv, catalog, groups, _t3, _t4;
1149
- return _regenerator.default.wrap(function (_context3) {
1150
- while (1) switch (_context3.prev = _context3.next) {
1151
- case 0:
1152
- _context3.prev = 0;
1153
- if ((_this9$webex$config = _this9.webex.config) !== null && _this9$webex$config !== void 0 && (_this9$webex$config$c = _this9$webex$config.calling) !== null && _this9$webex$config$c !== void 0 && _this9$webex$config$c.cacheU2C) {
1154
- _context3.next = 1;
1155
- break;
1156
- }
1157
- _this9.logger.info('services: skipping cache warm-up as per the cache config');
1158
- return _context3.abrupt("return", false);
1159
- case 1:
1160
- ls = _this9._getLocalStorageSafe();
1161
- if (ls) {
1162
- _context3.next = 2;
1163
- break;
1164
- }
1165
- _this9.logger.info('services: skipping cache warm-up as no localStorage is available');
1166
- return _context3.abrupt("return", false);
1167
- case 2:
1168
- cachedJson = ls.getItem(CATALOG_CACHE_KEY_V1);
1169
- cached = cachedJson ? JSON.parse(cachedJson) : undefined;
1170
- if (cached) {
1171
- _context3.next = 3;
1172
- break;
1173
- }
1174
- return _context3.abrupt("return", false);
1175
- case 3:
1176
- // TTL enforcement: clear if older than 24 hours
1177
- cachedAt = Number(cached.cachedAt) || 0;
1178
- if (!(!cachedAt || (0, _now.default)() - cachedAt > CATALOG_TTL_MS)) {
1179
- _context3.next = 4;
1180
- break;
1181
- }
1182
- _this9.clearCatalogCache();
1183
- return _context3.abrupt("return", false);
1184
- case 4:
1185
- _context3.prev = 4;
1186
- if (!((_this9$webex$credenti = _this9.webex.credentials) !== null && _this9$webex$credenti !== void 0 && _this9$webex$credenti.canAuthorize)) {
1187
- _context3.next = 5;
1188
- break;
1189
- }
1190
- credentials = _this9.webex.credentials;
1191
- currentOrgId = credentials.getOrgId();
1192
- if (!(cached.orgId && cached.orgId !== currentOrgId)) {
1193
- _context3.next = 5;
1194
- break;
1195
- }
1196
- return _context3.abrupt("return", false);
1197
- case 5:
1198
- _context3.next = 7;
1199
- break;
1200
- case 6:
1201
- _context3.prev = 6;
1202
- _t3 = _context3["catch"](4);
1203
- _this9.logger.warn('services: error checking orgId', _t3);
1204
- case 7:
1205
- // Ensure cached environment matches current environment
1206
- fedramp = !!((_this9$webex$config2 = _this9.webex.config) !== null && _this9$webex$config2 !== void 0 && _this9$webex$config2.fedramp);
1207
- u2cDiscoveryUrl = (_this9$webex$config3 = _this9.webex.config) === null || _this9$webex$config3 === void 0 ? void 0 : (_this9$webex$config3$ = _this9$webex$config3.services) === null || _this9$webex$config3$ === void 0 ? void 0 : (_this9$webex$config3$2 = _this9$webex$config3$.discovery) === null || _this9$webex$config3$2 === void 0 ? void 0 : _this9$webex$config3$2.u2c;
1208
- currentEnv = {
1209
- fedramp: fedramp,
1210
- u2cDiscoveryUrl: u2cDiscoveryUrl
1211
- };
1212
- if (!cached.env) {
1213
- _context3.next = 8;
1214
- break;
1215
- }
1216
- sameEnv = cached.env.fedramp === currentEnv.fedramp && cached.env.u2cDiscoveryUrl === currentEnv.u2cDiscoveryUrl;
1217
- if (sameEnv) {
1218
- _context3.next = 8;
1219
- break;
1220
- }
1221
- _this9.logger.info('services: skipping cache warm due to environment mismatch');
1222
- return _context3.abrupt("return", false);
1223
- case 8:
1224
- catalog = _this9._getCatalog(); // Apply any cached groups (with preauth selection validation if available)
1225
- groups = ['preauth', 'signin', 'postauth'];
1226
- groups.forEach(function (serviceGroup) {
1227
- var cachedGroup = cached[serviceGroup];
1228
- if (!cachedGroup) {
1229
- return;
1230
- }
1231
-
1232
- // Support legacy (hostMap) and new ({hostMap, meta}) shapes
1233
- var hostMap = cachedGroup && cachedGroup.hostMap ? cachedGroup.hostMap : cachedGroup;
1234
- var meta = cachedGroup === null || cachedGroup === void 0 ? void 0 : cachedGroup.meta;
1235
- if (serviceGroup === 'preauth' && meta) {
1236
- // For proximity-based selection, always fetch fresh to respect IP/region changes
1237
- if (meta.selectionType === 'mode') {
1238
- _this9.logger.info('services: skipping preauth cache warm for proximity mode');
1239
- return;
1240
- }
1241
- var intended = _this9.getIntendedPreauthSelection(currentOrgId);
1242
- var matches = intended && intended.selectionType === meta.selectionType && intended.selectionValue === meta.selectionValue;
1243
- if (!matches) {
1244
- _this9.logger.info('services: skipping preauth cache warm due to selection mismatch');
1245
- return;
1246
- }
1247
- }
1248
- if (hostMap) {
1249
- var formatted = _this9._formatReceivedHostmap(hostMap);
1250
- catalog.updateServiceUrls(serviceGroup, formatted);
1251
- }
1252
- });
1253
-
1254
- // Align credentials against warmed catalog
1255
- _this9.updateCredentialsConfig();
1256
- return _context3.abrupt("return", true);
1257
- case 9:
1258
- _context3.prev = 9;
1259
- _t4 = _context3["catch"](0);
1260
- _this9.logger.warn('services: error loading catalog from cache', _t4);
1261
- return _context3.abrupt("return", false);
1262
- case 10:
1263
- case "end":
1264
- return _context3.stop();
1265
- }
1266
- }, _callee3, null, [[0, 9], [4, 6]]);
1267
- }))();
1268
- },
1269
- /**
1270
- * Clear the catalog cache from the bounded storage.
1271
- * @returns {Promise<void>}
1272
- */
1273
- clearCatalogCache: function clearCatalogCache() {
1274
- try {
1275
- var ls = this._getLocalStorageSafe();
1276
- if (ls) {
1277
- ls.removeItem(CATALOG_CACHE_KEY_V1);
1278
- }
1279
- } catch (e) {
1280
- this.logger.warn('services: error clearing catalog cache', e);
1281
- }
1282
- return _promise.default.resolve();
1283
- },
1284
981
  /**
1285
982
  * Initialize the discovery services and the whitelisted services.
1286
983
  *
@@ -1289,9 +986,9 @@ var Services = _webexPlugin.default.extend({
1289
986
  initConfig: function initConfig() {
1290
987
  // Get the catalog and destructure the services config.
1291
988
  var catalog = this._getCatalog();
1292
- var _this$webex$config2 = this.webex.config,
1293
- services = _this$webex$config2.services,
1294
- fedramp = _this$webex$config2.fedramp;
989
+ var _this$webex$config = this.webex.config,
990
+ services = _this$webex$config.services,
991
+ fedramp = _this$webex$config.fedramp;
1295
992
 
1296
993
  // Validate that the services configuration exists.
1297
994
  if (services) {
@@ -1345,7 +1042,7 @@ var Services = _webexPlugin.default.extend({
1345
1042
  * @returns {Promise<void, Error>} - Errors if the token is unavailable.
1346
1043
  */
1347
1044
  initServiceCatalogs: function initServiceCatalogs() {
1348
- var _this0 = this;
1045
+ var _this8 = this;
1349
1046
  this.logger.info('services: initializing initial service catalogs');
1350
1047
 
1351
1048
  // Destructure the credentials plugin.
@@ -1360,17 +1057,16 @@ var Services = _webexPlugin.default.extend({
1360
1057
  })
1361
1058
  // Begin collecting the preauth/limited catalog.
1362
1059
  .then(function (orgId) {
1363
- return _this0.collectPreauthCatalog({
1060
+ return _this8.collectPreauthCatalog({
1364
1061
  orgId: orgId
1365
1062
  });
1366
1063
  }).then(function () {
1367
1064
  // Validate if the token is authorized.
1368
1065
  if (credentials.canAuthorize) {
1369
1066
  // Attempt to collect the postauth catalog.
1370
-
1371
- return _this0.updateServices().catch(function () {
1372
- _this0.initFailed = true;
1373
- _this0.logger.warn('services: cannot retrieve postauth catalog');
1067
+ return _this8.updateServices().catch(function () {
1068
+ _this8.initFailed = true;
1069
+ _this8.logger.warn('services: cannot retrieve postauth catalog');
1374
1070
  });
1375
1071
  }
1376
1072
 
@@ -1386,7 +1082,7 @@ var Services = _webexPlugin.default.extend({
1386
1082
  * @returns {Services}
1387
1083
  */
1388
1084
  initialize: function initialize() {
1389
- var _this1 = this;
1085
+ var _this9 = this;
1390
1086
  var catalog = new _serviceCatalog.default();
1391
1087
  var registry = new _serviceRegistry.default();
1392
1088
  var state = new _serviceState.default();
@@ -1396,54 +1092,33 @@ var Services = _webexPlugin.default.extend({
1396
1092
 
1397
1093
  // Listen for configuration changes once.
1398
1094
  this.listenToOnce(this.webex, 'change:config', function () {
1399
- _this1.initConfig();
1095
+ _this9.initConfig();
1400
1096
  });
1401
1097
 
1402
1098
  // wait for webex instance to be ready before attempting
1403
1099
  // to update the service catalogs
1404
- // this can cause a race condition because credentials may
1405
- // 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) {
1410
- case 0:
1411
- _context4.next = 1;
1412
- return _this1._loadCatalogFromCache();
1413
- case 1:
1414
- cachedCatalog = _context4.sent;
1415
- if (!cachedCatalog) {
1416
- _context4.next = 2;
1417
- break;
1418
- }
1419
- catalog.isReady = true;
1420
- return _context4.abrupt("return");
1421
- case 2:
1422
- supertoken = _this1.webex.credentials.supertoken; // Validate if the supertoken exists.
1423
- 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));
1429
- });
1430
- } 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));
1437
- });
1438
- }
1439
- case 3:
1440
- case "end":
1441
- return _context4.stop();
1442
- }
1443
- }, _callee4);
1444
- })));
1100
+ this.listenToOnce(this.webex, 'ready', function () {
1101
+ var supertoken = _this9.webex.credentials.supertoken;
1102
+ // Validate if the supertoken exists.
1103
+ if (supertoken && supertoken.access_token) {
1104
+ _this9.initServiceCatalogs().then(function () {
1105
+ catalog.isReady = true;
1106
+ }).catch(function (error) {
1107
+ _this9.initFailed = true;
1108
+ _this9.logger.error("services: failed to init initial services when credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1109
+ });
1110
+ } else {
1111
+ var email = _this9.webex.config.email;
1112
+ _this9.collectPreauthCatalog(email ? {
1113
+ email: email
1114
+ } : undefined).catch(function (error) {
1115
+ _this9.initFailed = true;
1116
+ _this9.logger.error("services: failed to init initial services when no credentials available, ".concat(error === null || error === void 0 ? void 0 : error.message));
1117
+ });
1118
+ }
1119
+ });
1445
1120
  },
1446
- version: "3.12.0-next.8"
1121
+ version: "3.12.0-task-refactor.1"
1447
1122
  });
1448
1123
  /* eslint-enable no-underscore-dangle */
1449
1124
  var _default = exports.default = Services;