@webex/webex-core 2.60.1-next.9 → 2.60.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.
Files changed (115) hide show
  1. package/dist/config.js +2 -1
  2. package/dist/config.js.map +1 -1
  3. package/dist/credentials-config.js +2 -1
  4. package/dist/credentials-config.js.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/interceptors/auth.js +3 -4
  8. package/dist/interceptors/auth.js.map +1 -1
  9. package/dist/interceptors/default-options.js +3 -4
  10. package/dist/interceptors/default-options.js.map +1 -1
  11. package/dist/interceptors/embargo.js +3 -4
  12. package/dist/interceptors/embargo.js.map +1 -1
  13. package/dist/interceptors/network-timing.js +3 -4
  14. package/dist/interceptors/network-timing.js.map +1 -1
  15. package/dist/interceptors/payload-transformer.js +3 -4
  16. package/dist/interceptors/payload-transformer.js.map +1 -1
  17. package/dist/interceptors/rate-limit.js +3 -4
  18. package/dist/interceptors/rate-limit.js.map +1 -1
  19. package/dist/interceptors/redirect.js +6 -7
  20. package/dist/interceptors/redirect.js.map +1 -1
  21. package/dist/interceptors/request-event.js +8 -9
  22. package/dist/interceptors/request-event.js.map +1 -1
  23. package/dist/interceptors/request-logger.js +15 -12
  24. package/dist/interceptors/request-logger.js.map +1 -1
  25. package/dist/interceptors/request-timing.js +3 -4
  26. package/dist/interceptors/request-timing.js.map +1 -1
  27. package/dist/interceptors/response-logger.js +10 -10
  28. package/dist/interceptors/response-logger.js.map +1 -1
  29. package/dist/interceptors/user-agent.js +7 -8
  30. package/dist/interceptors/user-agent.js.map +1 -1
  31. package/dist/interceptors/webex-tracking-id.js +3 -4
  32. package/dist/interceptors/webex-tracking-id.js.map +1 -1
  33. package/dist/interceptors/webex-user-agent.js +8 -9
  34. package/dist/interceptors/webex-user-agent.js.map +1 -1
  35. package/dist/lib/batcher.js +5 -8
  36. package/dist/lib/batcher.js.map +1 -1
  37. package/dist/lib/credentials/credentials.js +35 -73
  38. package/dist/lib/credentials/credentials.js.map +1 -1
  39. package/dist/lib/credentials/grant-errors.js +5 -5
  40. package/dist/lib/credentials/grant-errors.js.map +1 -1
  41. package/dist/lib/credentials/scope.js +5 -26
  42. package/dist/lib/credentials/scope.js.map +1 -1
  43. package/dist/lib/credentials/token-collection.js +2 -1
  44. package/dist/lib/credentials/token-collection.js.map +1 -1
  45. package/dist/lib/credentials/token.js +10 -14
  46. package/dist/lib/credentials/token.js.map +1 -1
  47. package/dist/lib/page.js +2 -1
  48. package/dist/lib/page.js.map +1 -1
  49. package/dist/lib/services/constants.js +6 -3
  50. package/dist/lib/services/constants.js.map +1 -1
  51. package/dist/lib/services/index.js +2 -2
  52. package/dist/lib/services/index.js.map +1 -1
  53. package/dist/lib/services/interceptors/server-error.js +3 -4
  54. package/dist/lib/services/interceptors/server-error.js.map +1 -1
  55. package/dist/lib/services/interceptors/service.js +5 -8
  56. package/dist/lib/services/interceptors/service.js.map +1 -1
  57. package/dist/lib/services/metrics.js +2 -1
  58. package/dist/lib/services/metrics.js.map +1 -1
  59. package/dist/lib/services/service-catalog.js +5 -5
  60. package/dist/lib/services/service-catalog.js.map +1 -1
  61. package/dist/lib/services/service-fed-ramp.js +2 -1
  62. package/dist/lib/services/service-fed-ramp.js.map +1 -1
  63. package/dist/lib/services/service-host.js +2 -1
  64. package/dist/lib/services/service-host.js.map +1 -1
  65. package/dist/lib/services/service-registry.js +4 -3
  66. package/dist/lib/services/service-registry.js.map +1 -1
  67. package/dist/lib/services/service-state.js +2 -1
  68. package/dist/lib/services/service-state.js.map +1 -1
  69. package/dist/lib/services/service-url.js +2 -1
  70. package/dist/lib/services/service-url.js.map +1 -1
  71. package/dist/lib/services/services.js +9 -7
  72. package/dist/lib/services/services.js.map +1 -1
  73. package/dist/lib/stateless-webex-plugin.js +2 -1
  74. package/dist/lib/stateless-webex-plugin.js.map +1 -1
  75. package/dist/lib/storage/decorators.js +16 -18
  76. package/dist/lib/storage/decorators.js.map +1 -1
  77. package/dist/lib/storage/errors.js +5 -5
  78. package/dist/lib/storage/errors.js.map +1 -1
  79. package/dist/lib/storage/make-webex-plugin-store.js +10 -8
  80. package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
  81. package/dist/lib/storage/make-webex-store.js.map +1 -1
  82. package/dist/lib/storage/memory-store-adapter.js +2 -1
  83. package/dist/lib/storage/memory-store-adapter.js.map +1 -1
  84. package/dist/lib/webex-core-plugin-mixin.js +14 -13
  85. package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
  86. package/dist/lib/webex-http-error.js +3 -4
  87. package/dist/lib/webex-http-error.js.map +1 -1
  88. package/dist/lib/webex-internal-core-plugin-mixin.js +14 -13
  89. package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
  90. package/dist/lib/webex-plugin.js +8 -5
  91. package/dist/lib/webex-plugin.js.map +1 -1
  92. package/dist/plugins/logger.js +3 -2
  93. package/dist/plugins/logger.js.map +1 -1
  94. package/dist/webex-core.js +38 -37
  95. package/dist/webex-core.js.map +1 -1
  96. package/dist/webex-internal-core.js +2 -1
  97. package/dist/webex-internal-core.js.map +1 -1
  98. package/package.json +20 -21
  99. package/src/lib/credentials/credentials.js +40 -82
  100. package/src/lib/credentials/scope.js +5 -24
  101. package/src/lib/credentials/token.js +1 -9
  102. package/src/lib/services/interceptors/service.js +2 -2
  103. package/src/lib/services/service-catalog.js +1 -3
  104. package/src/lib/services/services.js +0 -1
  105. package/src/webex-core.js +1 -13
  106. package/test/unit/spec/credentials/credentials.js +13 -169
  107. package/test/unit/spec/credentials/token.js +1 -11
  108. package/test/unit/spec/interceptors/auth.js +0 -3
  109. package/test/unit/spec/interceptors/webex-user-agent.js +6 -6
  110. package/test/unit/spec/services/interceptors/service.js +3 -9
  111. package/test/unit/spec/webex-core.js +0 -12
  112. package/dist/lib/constants.js +0 -13
  113. package/dist/lib/constants.js.map +0 -1
  114. package/src/lib/constants.js +0 -6
  115. package/test/unit/spec/credentials/scope.js +0 -80
package/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@webex/webex-core",
3
+ "version": "2.60.2",
3
4
  "description": "Plugin handling for Cisco Webex",
4
5
  "license": "MIT",
5
6
  "contributors": [
@@ -20,7 +21,7 @@
20
21
  "directory": "packages/@webex/webex-core"
21
22
  },
22
23
  "engines": {
23
- "node": ">=16"
24
+ "node": ">=14"
24
25
  },
25
26
  "browserify": {
26
27
  "transform": [
@@ -31,16 +32,16 @@
31
32
  "devDependencies": {
32
33
  "@babel/core": "^7.17.10",
33
34
  "@sinonjs/fake-timers": "^6.0.1",
34
- "@webex/babel-config-legacy": "0.0.0",
35
- "@webex/eslint-config-legacy": "0.0.0",
36
- "@webex/jest-config-legacy": "0.0.0",
37
- "@webex/legacy-tools": "0.0.0",
38
- "@webex/test-helper-chai": "2.60.1-next.9",
39
- "@webex/test-helper-make-local-url": "2.60.1-next.9",
40
- "@webex/test-helper-mocha": "2.60.1-next.9",
41
- "@webex/test-helper-mock-webex": "2.60.1-next.9",
42
- "@webex/test-helper-refresh-callback": "2.60.1-next.9",
43
- "@webex/test-helper-test-users": "2.60.1-next.9",
35
+ "@webex/babel-config-legacy": "2.60.2",
36
+ "@webex/eslint-config-legacy": "2.60.2",
37
+ "@webex/jest-config-legacy": "2.60.2",
38
+ "@webex/legacy-tools": "2.60.2",
39
+ "@webex/test-helper-chai": "2.60.2",
40
+ "@webex/test-helper-make-local-url": "2.60.2",
41
+ "@webex/test-helper-mocha": "2.60.2",
42
+ "@webex/test-helper-mock-webex": "2.60.2",
43
+ "@webex/test-helper-refresh-callback": "2.60.2",
44
+ "@webex/test-helper-test-users": "2.60.2",
44
45
  "chai": "^4.3.4",
45
46
  "chai-as-promised": "^7.1.1",
46
47
  "eslint": "^8.24.0",
@@ -48,12 +49,12 @@
48
49
  "sinon": "^9.2.4"
49
50
  },
50
51
  "dependencies": {
51
- "@webex/common": "2.60.1-next.9",
52
- "@webex/common-timers": "2.60.1-next.9",
53
- "@webex/http-core": "2.60.1-next.9",
54
- "@webex/internal-plugin-device": "2.60.1-next.9",
55
- "@webex/plugin-logger": "2.60.1-next.9",
56
- "@webex/storage-adapter-spec": "2.60.1-next.9",
52
+ "@webex/common": "2.60.2",
53
+ "@webex/common-timers": "2.60.2",
54
+ "@webex/http-core": "2.60.2",
55
+ "@webex/internal-plugin-device": "2.60.2",
56
+ "@webex/plugin-logger": "2.60.2",
57
+ "@webex/storage-adapter-spec": "2.60.2",
57
58
  "ampersand-collection": "^2.0.2",
58
59
  "ampersand-events": "^2.0.2",
59
60
  "ampersand-state": "^5.0.3",
@@ -66,12 +67,10 @@
66
67
  "scripts": {
67
68
  "build": "yarn build:src",
68
69
  "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
69
- "deploy:npm": "yarn npm publish",
70
70
  "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
71
71
  "test:browser:broken": "webex-legacy-tools test --integration --unit --runner karma",
72
72
  "test:integration:broken": "webex-legacy-tools test --integration --runner mocha",
73
73
  "test:style": "eslint ./src/**/*.*",
74
74
  "test:unit": "webex-legacy-tools test --unit --runner jest"
75
- },
76
- "version": "2.60.1-next.9"
77
- }
75
+ }
76
+ }
@@ -13,11 +13,10 @@ import {clone, cloneDeep, isObject, isEmpty} from 'lodash';
13
13
  import WebexPlugin from '../webex-plugin';
14
14
  import {persist, waitForValue} from '../storage/decorators';
15
15
 
16
- import grantErrors, {OAuthError} from './grant-errors';
17
- import {filterScope, diffScopes, sortScope} from './scope';
16
+ import grantErrors from './grant-errors';
17
+ import {filterScope, sortScope} from './scope';
18
18
  import Token from './token';
19
19
  import TokenCollection from './token-collection';
20
- import {METRICS} from '../constants';
21
20
 
22
21
  /**
23
22
  * @class
@@ -49,25 +48,6 @@ const Credentials = WebexPlugin.extend({
49
48
  return Boolean(this.supertoken && this.supertoken.canRefresh);
50
49
  },
51
50
  },
52
- isUnverifiedGuest: {
53
- deps: ['supertoken'],
54
- /**
55
- * Returns true if the user is an unverified guest
56
- * @returns {boolean}
57
- */
58
- fn() {
59
- let isGuest = false;
60
- try {
61
- isGuest =
62
- JSON.parse(base64.decode(this.supertoken.access_token.split('.')[1])).user_type ===
63
- 'guest';
64
- } catch {
65
- /* the non-guest token is formatted differently so catch is expected */
66
- }
67
-
68
- return isGuest;
69
- },
70
- },
71
51
  },
72
52
 
73
53
  props: {
@@ -260,15 +240,8 @@ const Credentials = WebexPlugin.extend({
260
240
  */
261
241
  downscope(scope) {
262
242
  return this.supertoken.downscope(scope).catch((reason) => {
263
- const failReason = reason?.body ?? reason;
264
- this.logger.warn(`credentials: failed to downscope supertoken to "${scope}"`, failReason);
243
+ this.logger.trace(`credentials: failed to downscope supertoken to ${scope}`, reason);
265
244
  this.logger.trace(`credentials: falling back to supertoken for ${scope}`);
266
- this.webex.internal.metrics.submitClientMetrics(METRICS.JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED, {
267
- fields: {
268
- requestedScope: scope,
269
- failReason,
270
- },
271
- });
272
245
 
273
246
  return Promise.resolve(new Token({scope, ...this.supertoken.serialize()}), {
274
247
  parent: this,
@@ -349,12 +322,12 @@ const Credentials = WebexPlugin.extend({
349
322
  }
350
323
 
351
324
  if (!scope) {
352
- scope = filterScope('spark:kms', this.supertoken.scope);
325
+ scope = filterScope('spark:kms', this.config.scope);
353
326
  }
354
327
 
355
328
  scope = sortScope(scope);
356
329
 
357
- if (scope === sortScope(this.supertoken.scope)) {
330
+ if (scope === sortScope(this.config.scope)) {
358
331
  return Promise.resolve(this.supertoken);
359
332
  }
360
333
 
@@ -504,23 +477,6 @@ const Credentials = WebexPlugin.extend({
504
477
 
505
478
  return supertoken
506
479
  .refresh()
507
- .catch((error) => {
508
- if (error instanceof OAuthError) {
509
- // Error: super token refresh failed with 400 status code.
510
- // Hence emit an event to the client, an opportunity to logout.
511
- this.unset('supertoken');
512
- while (this.userTokens.models.length) {
513
- try {
514
- this.userTokens.remove(this.userTokens.models[0]);
515
- } catch (err) {
516
- this.logger.warn('credentials: failed to remove user token', err);
517
- }
518
- }
519
- this.webex.trigger('client:InvalidRequestError');
520
- }
521
-
522
- return Promise.reject(error);
523
- })
524
480
  .then((st) => {
525
481
  // clear refresh timer
526
482
  if (this.refreshTimer) {
@@ -529,44 +485,46 @@ const Credentials = WebexPlugin.extend({
529
485
  }
530
486
  this.supertoken = st;
531
487
 
532
- const invalidScopes = diffScopes(this.config.scope, st.scope);
533
-
534
- if (invalidScopes !== '') {
535
- this.logger.warn(
536
- `credentials: "${invalidScopes}" scope(s) are invalid because not listed in the supertoken, they will be excluded from user token requests.`
537
- );
538
- this.webex.internal.metrics.submitClientMetrics(
539
- METRICS.JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH,
540
- {fields: {invalidScopes}}
541
- );
542
- }
543
-
544
488
  return Promise.all(
545
- tokens.map((token) => {
546
- const tokenScope = filterScope(diffScopes(token.scope, st.scope), token.scope);
547
-
548
- return (
549
- this.downscope(tokenScope)
550
- // eslint-disable-next-line max-nested-callbacks
551
- .then((t) => {
552
- this.logger.info(`credentials: revoking token for ${token.scope}`);
553
-
554
- return token
555
- .revoke()
556
- .catch((err) => {
557
- this.logger.warn('credentials: failed to revoke user token', err);
558
- })
559
- .then(() => {
560
- this.userTokens.remove(token.scope);
561
- this.userTokens.add(t);
562
- });
563
- })
564
- );
565
- })
489
+ tokens.map((token) =>
490
+ this.downscope(token.scope)
491
+ // eslint-disable-next-line max-nested-callbacks
492
+ .then((t) => {
493
+ this.logger.info(`credentials: revoking token for ${token.scope}`);
494
+
495
+ return token
496
+ .revoke()
497
+ .catch((err) => {
498
+ this.logger.warn('credentials: failed to revoke user token', err);
499
+ })
500
+ .then(() => {
501
+ this.userTokens.remove(token.scope);
502
+ this.userTokens.add(t);
503
+ });
504
+ })
505
+ )
566
506
  );
567
507
  })
568
508
  .then(() => {
569
509
  this.scheduleRefresh(this.supertoken.expires);
510
+ })
511
+ .catch((error) => {
512
+ const {InvalidRequestError} = grantErrors;
513
+
514
+ if (error instanceof InvalidRequestError) {
515
+ // Error: The refresh token provided is expired, revoked, malformed, or invalid. Hence emit an event to the client, an opportunity to logout.
516
+ this.unset('supertoken');
517
+ while (this.userTokens.models.length) {
518
+ try {
519
+ this.userTokens.remove(this.userTokens.models[0]);
520
+ } catch (err) {
521
+ this.logger.warn('credentials: failed to remove user token', err);
522
+ }
523
+ }
524
+ this.webex.trigger('client:InvalidRequestError');
525
+ }
526
+
527
+ return Promise.reject(error);
570
528
  });
571
529
  },
572
530
 
@@ -2,10 +2,6 @@
2
2
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
4
 
5
- import {difference} from 'lodash';
6
-
7
- const SCOPE_SEPARATOR = ' ';
8
-
9
5
  /**
10
6
  * sorts a list of scopes
11
7
  * @param {string} scope
@@ -16,12 +12,12 @@ export function sortScope(scope) {
16
12
  return '';
17
13
  }
18
14
 
19
- return scope.split(SCOPE_SEPARATOR).sort().join(SCOPE_SEPARATOR);
15
+ return scope.split(' ').sort().join(' ');
20
16
  }
21
17
 
22
18
  /**
23
19
  * sorts a list of scopes and filters the specified scope
24
- * @param {string|string[]} toFilter
20
+ * @param {string} toFilter
25
21
  * @param {string} scope
26
22
  * @returns {string}
27
23
  */
@@ -29,25 +25,10 @@ export function filterScope(toFilter, scope) {
29
25
  if (!scope) {
30
26
  return '';
31
27
  }
32
- const toFilterArr = Array.isArray(toFilter) ? toFilter : [toFilter];
33
28
 
34
29
  return scope
35
- .split(SCOPE_SEPARATOR)
36
- .filter((item) => !toFilterArr.includes(item))
30
+ .split(' ')
31
+ .filter((item) => item !== toFilter)
37
32
  .sort()
38
- .join(SCOPE_SEPARATOR);
39
- }
40
-
41
- /**
42
- * Returns a string containing all items in scopeA that are not in scopeB, or an empty string if there are none.
43
- *
44
- * @param {string} scopeA
45
- * @param {string} scopeB
46
- * @returns {string}
47
- */
48
- export function diffScopes(scopeA, scopeB) {
49
- const a = scopeA?.split(SCOPE_SEPARATOR) ?? [];
50
- const b = scopeB?.split(SCOPE_SEPARATOR) ?? [];
51
-
52
- return difference(a, b).sort().join(SCOPE_SEPARATOR);
33
+ .join(' ');
53
34
  }
@@ -9,7 +9,7 @@ import {safeSetTimeout} from '@webex/common-timers';
9
9
  import WebexHttpError from '../webex-http-error';
10
10
  import WebexPlugin from '../webex-plugin';
11
11
 
12
- import {sortScope, diffScopes} from './scope';
12
+ import {sortScope} from './scope';
13
13
  import grantErrors, {OAuthError} from './grant-errors';
14
14
 
15
15
  /* eslint-disable camelcase */
@@ -259,14 +259,6 @@ const Token = WebexPlugin.extend({
259
259
  return Promise.reject(new Error('cannot downscope access token'));
260
260
  }
261
261
 
262
- if (diffScopes(scope, this.config.scope) !== '') {
263
- return Promise.reject(
264
- new Error(
265
- `new scope (${scope}) is not subset of the available scopes (${this.config.scope})`
266
- )
267
- );
268
- }
269
-
270
262
  // Since we're going to use scope as the index in our token collection, it's
271
263
  // important scopes are always deterministically specified.
272
264
  if (scope) {
@@ -36,11 +36,11 @@ export default class ServiceInterceptor extends Interceptor {
36
36
 
37
37
  // Destructure commonly referenced namespaces.
38
38
  const {services} = this.webex.internal;
39
- const {service, resource, waitForServiceTimeout} = options;
39
+ const {service, resource} = options;
40
40
 
41
41
  // Attempt to collect the service url.
42
42
  return services
43
- .waitForService({name: service, timeout: waitForServiceTimeout})
43
+ .waitForService({name: service})
44
44
  .then((serviceUrl) => {
45
45
  // Generate the combined service url and resource.
46
46
  options.uri = this.generateUri(serviceUrl, resource);
@@ -413,8 +413,6 @@ const ServiceCatalog = AmpState.extend({
413
413
  resolve();
414
414
  }
415
415
 
416
- const validatedTimeout = typeof timeout === 'number' && timeout >= 0 ? timeout : 60;
417
-
418
416
  const timeoutTimer = setTimeout(
419
417
  () =>
420
418
  reject(
@@ -422,7 +420,7 @@ const ServiceCatalog = AmpState.extend({
422
420
  `services: timeout occured while waiting for '${serviceGroup}' catalog to populate`
423
421
  )
424
422
  ),
425
- validatedTimeout * 1000
423
+ timeout ? timeout * 1000 : 60000
426
424
  );
427
425
 
428
426
  this.once(serviceGroup, () => {
@@ -682,7 +682,6 @@ const Services = WebexPlugin.extend({
682
682
  * @returns {object}
683
683
  */
684
684
  _formatReceivedHostmap(serviceHostmap) {
685
- this._updateHostCatalog(serviceHostmap.hostCatalog);
686
685
  // map the host catalog items to a formatted hostmap
687
686
  const formattedHostmap = Object.keys(serviceHostmap.hostCatalog).reduce((accumulator, key) => {
688
687
  if (serviceHostmap.hostCatalog[key].length === 0) {
package/src/webex-core.js CHANGED
@@ -6,12 +6,7 @@ import {EventEmitter} from 'events';
6
6
  import util from 'util';
7
7
 
8
8
  import {proxyEvents, retry, transferEvents} from '@webex/common';
9
- import {
10
- HttpStatusInterceptor,
11
- defaults as requestDefaults,
12
- protoprepareFetchOptions as prepareFetchOptions,
13
- setTimingsAndFetch as _setTimingsAndFetch,
14
- } from '@webex/http-core';
9
+ import {HttpStatusInterceptor, defaults as requestDefaults} from '@webex/http-core';
15
10
  import {defaultsDeep, get, isFunction, isString, last, merge, omit, set, unset} from 'lodash';
16
11
  import AmpState from 'ampersand-state';
17
12
  import uuid from 'uuid';
@@ -407,13 +402,6 @@ const WebexCore = AmpState.extend({
407
402
  interceptors: ints,
408
403
  });
409
404
 
410
- this.prepareFetchOptions = prepareFetchOptions({
411
- json: true,
412
- interceptors: ints,
413
- });
414
-
415
- this.setTimingsAndFetch = _setTimingsAndFetch;
416
-
417
405
  let sessionId = `${get(this, 'config.trackingIdPrefix', 'webex-js-sdk')}_${get(
418
406
  this,
419
407
  'config.trackingIdBase',