@webex/webex-core 3.0.0-beta.13 → 3.0.0-beta.131

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 (184) hide show
  1. package/dist/config.js +1 -11
  2. package/dist/config.js.map +1 -1
  3. package/dist/credentials-config.js +44 -64
  4. package/dist/credentials-config.js.map +1 -1
  5. package/dist/index.js +0 -76
  6. package/dist/index.js.map +1 -1
  7. package/dist/interceptors/auth.js +22 -55
  8. package/dist/interceptors/auth.js.map +1 -1
  9. package/dist/interceptors/default-options.js +0 -20
  10. package/dist/interceptors/default-options.js.map +1 -1
  11. package/dist/interceptors/embargo.js +0 -21
  12. package/dist/interceptors/embargo.js.map +1 -1
  13. package/dist/interceptors/network-timing.js +2 -21
  14. package/dist/interceptors/network-timing.js.map +1 -1
  15. package/dist/interceptors/payload-transformer.js +2 -22
  16. package/dist/interceptors/payload-transformer.js.map +1 -1
  17. package/dist/interceptors/rate-limit.js +25 -57
  18. package/dist/interceptors/rate-limit.js.map +1 -1
  19. package/dist/interceptors/redirect.js +4 -33
  20. package/dist/interceptors/redirect.js.map +1 -1
  21. package/dist/interceptors/request-event.js +3 -30
  22. package/dist/interceptors/request-event.js.map +1 -1
  23. package/dist/interceptors/request-logger.js +1 -30
  24. package/dist/interceptors/request-logger.js.map +1 -1
  25. package/dist/interceptors/request-timing.js +3 -22
  26. package/dist/interceptors/request-timing.js.map +1 -1
  27. package/dist/interceptors/response-logger.js +2 -31
  28. package/dist/interceptors/response-logger.js.map +1 -1
  29. package/dist/interceptors/user-agent.js +2 -29
  30. package/dist/interceptors/user-agent.js.map +1 -1
  31. package/dist/interceptors/webex-tracking-id.js +5 -28
  32. package/dist/interceptors/webex-tracking-id.js.map +1 -1
  33. package/dist/interceptors/webex-user-agent.js +5 -38
  34. package/dist/interceptors/webex-user-agent.js.map +1 -1
  35. package/dist/lib/batcher.js +3 -51
  36. package/dist/lib/batcher.js.map +1 -1
  37. package/dist/lib/credentials/credentials.js +55 -119
  38. package/dist/lib/credentials/credentials.js.map +1 -1
  39. package/dist/lib/credentials/grant-errors.js +0 -49
  40. package/dist/lib/credentials/grant-errors.js.map +1 -1
  41. package/dist/lib/credentials/index.js +1 -13
  42. package/dist/lib/credentials/index.js.map +1 -1
  43. package/dist/lib/credentials/scope.js +1 -7
  44. package/dist/lib/credentials/scope.js.map +1 -1
  45. package/dist/lib/credentials/token-collection.js +1 -7
  46. package/dist/lib/credentials/token-collection.js.map +1 -1
  47. package/dist/lib/credentials/token.js +39 -118
  48. package/dist/lib/credentials/token.js.map +1 -1
  49. package/dist/lib/page.js +13 -26
  50. package/dist/lib/page.js.map +1 -1
  51. package/dist/lib/services/constants.js +0 -2
  52. package/dist/lib/services/constants.js.map +1 -1
  53. package/dist/lib/services/index.js +1 -28
  54. package/dist/lib/services/index.js.map +1 -1
  55. package/dist/lib/services/interceptors/server-error.js +2 -23
  56. package/dist/lib/services/interceptors/server-error.js.map +1 -1
  57. package/dist/lib/services/interceptors/service.js +12 -34
  58. package/dist/lib/services/interceptors/service.js.map +1 -1
  59. package/dist/lib/services/metrics.js +0 -2
  60. package/dist/lib/services/metrics.js.map +1 -1
  61. package/dist/lib/services/service-catalog.js +10 -90
  62. package/dist/lib/services/service-catalog.js.map +1 -1
  63. package/dist/lib/services/service-fed-ramp.js +0 -2
  64. package/dist/lib/services/service-fed-ramp.js.map +1 -1
  65. package/dist/lib/services/service-host.js +47 -62
  66. package/dist/lib/services/service-host.js.map +1 -1
  67. package/dist/lib/services/service-registry.js +78 -90
  68. package/dist/lib/services/service-registry.js.map +1 -1
  69. package/dist/lib/services/service-state.js +3 -15
  70. package/dist/lib/services/service-state.js.map +1 -1
  71. package/dist/lib/services/service-url.js +4 -25
  72. package/dist/lib/services/service-url.js.map +1 -1
  73. package/dist/lib/services/services.js +122 -238
  74. package/dist/lib/services/services.js.map +1 -1
  75. package/dist/lib/stateless-webex-plugin.js +5 -28
  76. package/dist/lib/stateless-webex-plugin.js.map +1 -1
  77. package/dist/lib/storage/decorators.js +19 -62
  78. package/dist/lib/storage/decorators.js.map +1 -1
  79. package/dist/lib/storage/errors.js +0 -23
  80. package/dist/lib/storage/errors.js.map +1 -1
  81. package/dist/lib/storage/index.js +2 -16
  82. package/dist/lib/storage/index.js.map +1 -1
  83. package/dist/lib/storage/make-webex-plugin-store.js +11 -41
  84. package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
  85. package/dist/lib/storage/make-webex-store.js +8 -30
  86. package/dist/lib/storage/make-webex-store.js.map +1 -1
  87. package/dist/lib/storage/memory-store-adapter.js +1 -19
  88. package/dist/lib/storage/memory-store-adapter.js.map +1 -1
  89. package/dist/lib/webex-core-plugin-mixin.js +9 -29
  90. package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
  91. package/dist/lib/webex-http-error.js +1 -31
  92. package/dist/lib/webex-http-error.js.map +1 -1
  93. package/dist/lib/webex-internal-core-plugin-mixin.js +9 -29
  94. package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
  95. package/dist/lib/webex-plugin.js +6 -40
  96. package/dist/lib/webex-plugin.js.map +1 -1
  97. package/dist/plugins/logger.js +3 -17
  98. package/dist/plugins/logger.js.map +1 -1
  99. package/dist/webex-core.js +79 -203
  100. package/dist/webex-core.js.map +1 -1
  101. package/dist/webex-internal-core.js +0 -10
  102. package/dist/webex-internal-core.js.map +1 -1
  103. package/package.json +14 -14
  104. package/src/config.js +9 -11
  105. package/src/credentials-config.js +110 -72
  106. package/src/index.js +4 -14
  107. package/src/interceptors/auth.js +36 -37
  108. package/src/interceptors/default-options.js +0 -1
  109. package/src/interceptors/embargo.js +1 -1
  110. package/src/interceptors/payload-transformer.js +1 -2
  111. package/src/interceptors/rate-limit.js +8 -5
  112. package/src/interceptors/redirect.js +14 -8
  113. package/src/interceptors/request-event.js +4 -8
  114. package/src/interceptors/request-logger.js +8 -5
  115. package/src/interceptors/response-logger.js +11 -8
  116. package/src/interceptors/user-agent.js +1 -2
  117. package/src/interceptors/webex-user-agent.js +3 -9
  118. package/src/lib/batcher.js +70 -69
  119. package/src/lib/credentials/credentials.js +131 -122
  120. package/src/lib/credentials/grant-errors.js +6 -7
  121. package/src/lib/credentials/index.js +1 -4
  122. package/src/lib/credentials/scope.js +1 -4
  123. package/src/lib/credentials/token-collection.js +1 -1
  124. package/src/lib/credentials/token.js +86 -80
  125. package/src/lib/page.js +10 -11
  126. package/src/lib/services/constants.js +3 -13
  127. package/src/lib/services/index.js +2 -2
  128. package/src/lib/services/interceptors/server-error.js +12 -7
  129. package/src/lib/services/interceptors/service.js +6 -5
  130. package/src/lib/services/metrics.js +1 -1
  131. package/src/lib/services/service-catalog.js +110 -100
  132. package/src/lib/services/service-fed-ramp.js +1 -2
  133. package/src/lib/services/service-host.js +10 -17
  134. package/src/lib/services/service-registry.js +69 -96
  135. package/src/lib/services/service-state.js +4 -6
  136. package/src/lib/services/service-url.js +24 -23
  137. package/src/lib/services/services.js +260 -251
  138. package/src/lib/stateless-webex-plugin.js +4 -2
  139. package/src/lib/storage/decorators.js +68 -66
  140. package/src/lib/storage/index.js +4 -6
  141. package/src/lib/storage/make-webex-plugin-store.js +34 -21
  142. package/src/lib/storage/make-webex-store.js +6 -7
  143. package/src/lib/storage/memory-store-adapter.js +3 -3
  144. package/src/lib/webex-core-plugin-mixin.js +10 -7
  145. package/src/lib/webex-http-error.js +7 -8
  146. package/src/lib/webex-internal-core-plugin-mixin.js +9 -6
  147. package/src/lib/webex-plugin.js +41 -34
  148. package/src/plugins/logger.js +8 -3
  149. package/src/webex-core.js +185 -116
  150. package/src/webex-internal-core.js +15 -9
  151. package/test/integration/spec/credentials/credentials.js +26 -30
  152. package/test/integration/spec/credentials/token.js +36 -33
  153. package/test/integration/spec/services/service-catalog.js +177 -156
  154. package/test/integration/spec/services/services.js +313 -304
  155. package/test/integration/spec/webex-core.js +98 -86
  156. package/test/unit/spec/_setup.js +26 -18
  157. package/test/unit/spec/credentials/credentials.js +217 -154
  158. package/test/unit/spec/credentials/token.js +94 -76
  159. package/test/unit/spec/interceptors/auth.js +291 -243
  160. package/test/unit/spec/interceptors/default-options.js +36 -24
  161. package/test/unit/spec/interceptors/embargo.js +32 -27
  162. package/test/unit/spec/interceptors/network-timing.js +2 -2
  163. package/test/unit/spec/interceptors/payload-transformer.js +61 -52
  164. package/test/unit/spec/interceptors/rate-limit.js +104 -75
  165. package/test/unit/spec/interceptors/redirect.js +22 -20
  166. package/test/unit/spec/interceptors/request-timing.js +18 -22
  167. package/test/unit/spec/interceptors/user-agent.js +28 -16
  168. package/test/unit/spec/interceptors/webex-tracking-id.js +14 -8
  169. package/test/unit/spec/interceptors/webex-user-agent.js +83 -37
  170. package/test/unit/spec/lib/batcher.js +36 -32
  171. package/test/unit/spec/lib/page.js +36 -32
  172. package/test/unit/spec/lib/webex-plugin.js +1 -1
  173. package/test/unit/spec/services/interceptors/server-error.js +67 -90
  174. package/test/unit/spec/services/interceptors/service.js +17 -28
  175. package/test/unit/spec/services/service-catalog.js +19 -27
  176. package/test/unit/spec/services/service-host.js +29 -26
  177. package/test/unit/spec/services/service-registry.js +128 -170
  178. package/test/unit/spec/services/service-state.js +13 -22
  179. package/test/unit/spec/services/service-url.js +24 -43
  180. package/test/unit/spec/services/services.js +85 -41
  181. package/test/unit/spec/storage/persist.js +6 -9
  182. package/test/unit/spec/storage/wait-for-value.js +22 -21
  183. package/test/unit/spec/webex-core.js +78 -57
  184. package/test/unit/spec/webex-internal-core.js +56 -31
@@ -6,13 +6,7 @@ import querystring from 'querystring';
6
6
  import url from 'url';
7
7
 
8
8
  import jwt from 'jsonwebtoken';
9
- import {
10
- base64,
11
- makeStateDataType,
12
- oneFlight,
13
- tap,
14
- whileInFlight
15
- } from '@webex/common';
9
+ import {base64, makeStateDataType, oneFlight, tap, whileInFlight} from '@webex/common';
16
10
  import {safeSetTimeout} from '@webex/common-timers';
17
11
  import {clone, cloneDeep, isObject, isEmpty} from 'lodash';
18
12
 
@@ -29,29 +23,22 @@ import TokenCollection from './token-collection';
29
23
  */
30
24
  const Credentials = WebexPlugin.extend({
31
25
  collections: {
32
- userTokens: TokenCollection
26
+ userTokens: TokenCollection,
33
27
  },
34
28
 
35
29
  dataTypes: {
36
- token: makeStateDataType(Token, 'token').dataType
30
+ token: makeStateDataType(Token, 'token').dataType,
37
31
  },
38
32
 
39
33
  derived: {
40
34
  canAuthorize: {
41
- deps: [
42
- 'supertoken',
43
- 'supertoken.canAuthorize',
44
- 'canRefresh'
45
- ],
35
+ deps: ['supertoken', 'supertoken.canAuthorize', 'canRefresh'],
46
36
  fn() {
47
- return Boolean(this.supertoken && this.supertoken.canAuthorize || this.canRefresh);
48
- }
37
+ return Boolean((this.supertoken && this.supertoken.canAuthorize) || this.canRefresh);
38
+ },
49
39
  },
50
40
  canRefresh: {
51
- deps: [
52
- 'supertoken',
53
- 'supertoken.canRefresh'
54
- ],
41
+ deps: ['supertoken', 'supertoken.canRefresh'],
55
42
  fn() {
56
43
  // If we're operating in JWT mode, we have to delegate to the consumer
57
44
  if (this.config.jwtRefreshCallback) {
@@ -59,12 +46,31 @@ const Credentials = WebexPlugin.extend({
59
46
  }
60
47
 
61
48
  return Boolean(this.supertoken && this.supertoken.canRefresh);
62
- }
63
- }
49
+ },
50
+ },
51
+ isUnverifiedGuest: {
52
+ deps: ['supertoken'],
53
+ /**
54
+ * Returns true if the user is an unverified guest
55
+ * @returns {boolean}
56
+ */
57
+ fn() {
58
+ let isGuest = false;
59
+ try {
60
+ isGuest =
61
+ JSON.parse(base64.decode(this.supertoken.access_token.split('.')[1])).user_type ===
62
+ 'guest';
63
+ } catch {
64
+ /* the non-guest token is formatted differently so catch is expected */
65
+ }
66
+
67
+ return isGuest;
68
+ },
69
+ },
64
70
  },
65
71
 
66
72
  props: {
67
- supertoken: makeStateDataType(Token, 'token').prop
73
+ supertoken: makeStateDataType(Token, 'token').prop,
68
74
  },
69
75
 
70
76
  namespace: 'Credentials',
@@ -72,7 +78,7 @@ const Credentials = WebexPlugin.extend({
72
78
  session: {
73
79
  isRefreshing: {
74
80
  default: false,
75
- type: 'boolean'
81
+ type: 'boolean',
76
82
  },
77
83
  /**
78
84
  * Becomes `true` once the {@link loaded} event fires.
@@ -83,12 +89,12 @@ const Credentials = WebexPlugin.extend({
83
89
  */
84
90
  ready: {
85
91
  default: false,
86
- type: 'boolean'
92
+ type: 'boolean',
87
93
  },
88
94
  refreshTimer: {
89
95
  default: undefined,
90
- type: 'any'
91
- }
96
+ type: 'any',
97
+ },
92
98
  },
93
99
 
94
100
  /**
@@ -120,8 +126,7 @@ const Credentials = WebexPlugin.extend({
120
126
  if (options.state) {
121
127
  if (!isEmpty(options.state)) {
122
128
  options.state = base64.toBase64Url(JSON.stringify(options.state));
123
- }
124
- else {
129
+ } else {
125
130
  delete options.state;
126
131
  }
127
132
  }
@@ -137,27 +142,21 @@ const Credentials = WebexPlugin.extend({
137
142
  * @returns {string} - The OrgId.
138
143
  */
139
144
  getOrgId() {
140
- this.logger.info(
141
- 'credentials: attempting to retrieve the OrgId from token'
142
- );
145
+ this.logger.info('credentials: attempting to retrieve the OrgId from token');
143
146
 
144
147
  try {
145
148
  // Attempt to extract a client-authenticated token's OrgId.
146
149
  this.logger.info('credentials: trying to extract OrgId from JWT');
147
150
 
148
151
  return this.extractOrgIdFromJWT(this.supertoken.access_token);
149
- }
150
- catch (e) {
152
+ } catch (e) {
151
153
  // Attempt to extract a user token's OrgId.
152
154
  this.logger.info('credentials: could not extract OrgId from JWT');
153
- this.logger.info(
154
- 'credentials: attempting to extract OrgId from user token'
155
- );
155
+ this.logger.info('credentials: attempting to extract OrgId from user token');
156
156
 
157
157
  try {
158
158
  return this.extractOrgIdFromUserToken(this.supertoken?.access_token);
159
- }
160
- catch (f) {
159
+ } catch (f) {
161
160
  this.logger.info('credentials: could not extract OrgId from user token');
162
161
  throw f;
163
162
  }
@@ -218,10 +217,11 @@ const Credentials = WebexPlugin.extend({
218
217
  * @returns {[type]}
219
218
  */
220
219
  buildLogoutUrl(options = {}) {
221
- return `${this.config.logoutUrl}?${querystring.stringify(Object.assign({
220
+ return `${this.config.logoutUrl}?${querystring.stringify({
222
221
  cisService: this.config.service,
223
- goto: this.config.redirect_uri
224
- }, options))}`;
222
+ goto: this.config.redirect_uri,
223
+ ...options,
224
+ })}`;
225
225
  },
226
226
 
227
227
  /**
@@ -233,7 +233,7 @@ const Credentials = WebexPlugin.extend({
233
233
  * @returns {number}
234
234
  */
235
235
  calcRefreshTimeout(expiration) {
236
- return Math.floor((Math.floor(Math.random() * 4) + 6) / 10 * expiration);
236
+ return Math.floor(((Math.floor(Math.random() * 4) + 6) / 10) * expiration);
237
237
  },
238
238
 
239
239
  constructor(...args) {
@@ -258,13 +258,14 @@ const Credentials = WebexPlugin.extend({
258
258
  * @returns {Promise<Token>}
259
259
  */
260
260
  downscope(scope) {
261
- return this.supertoken.downscope(scope)
262
- .catch((reason) => {
263
- this.logger.trace(`credentials: failed to downscope supertoken to ${scope}`, reason);
264
- this.logger.trace(`credentials: falling back to supertoken for ${scope}`);
261
+ return this.supertoken.downscope(scope).catch((reason) => {
262
+ this.logger.trace(`credentials: failed to downscope supertoken to ${scope}`, reason);
263
+ this.logger.trace(`credentials: falling back to supertoken for ${scope}`);
265
264
 
266
- return Promise.resolve(new Token(Object.assign({scope}, this.supertoken.serialize())), {parent: this});
265
+ return Promise.resolve(new Token({scope, ...this.supertoken.serialize()}), {
266
+ parent: this,
267
267
  });
268
+ });
268
269
  },
269
270
 
270
271
  /**
@@ -279,23 +280,24 @@ const Credentials = WebexPlugin.extend({
279
280
  getClientToken(options = {}) {
280
281
  this.logger.info('credentials: requesting client credentials grant');
281
282
 
282
- return this.webex.request({
283
- /* eslint-disable camelcase */
284
- method: 'POST',
285
- uri: options.uri || this.config.tokenUrl,
286
- form: {
287
- grant_type: 'client_credentials',
288
- scope: options.scope || 'webexsquare:admin',
289
- self_contained_token: true
290
- },
291
- auth: {
292
- user: this.config.client_id,
293
- pass: this.config.client_secret,
294
- sendImmediately: true
295
- },
296
- shouldRefreshAccessToken: false
297
- /* eslint-enable camelcase */
298
- })
283
+ return this.webex
284
+ .request({
285
+ /* eslint-disable camelcase */
286
+ method: 'POST',
287
+ uri: options.uri || this.config.tokenUrl,
288
+ form: {
289
+ grant_type: 'client_credentials',
290
+ scope: options.scope || 'webexsquare:admin',
291
+ self_contained_token: true,
292
+ },
293
+ auth: {
294
+ user: this.config.client_id,
295
+ pass: this.config.client_secret,
296
+ sendImmediately: true,
297
+ },
298
+ shouldRefreshAccessToken: false,
299
+ /* eslint-enable camelcase */
300
+ })
299
301
  .then((res) => new Token(res.body, {parent: this}))
300
302
  .catch((res) => {
301
303
  if (res.statusCode !== 400) {
@@ -320,41 +322,44 @@ const Credentials = WebexPlugin.extend({
320
322
  * @returns {Promise<Token>}
321
323
  */
322
324
  getUserToken(scope) {
323
- return Promise.resolve(!this.isRefreshing || new Promise((resolve) => {
324
- this.logger.info('credentials: token refresh inflight; delaying getUserToken until refresh completes');
325
- this.once('change:isRefreshing', () => {
326
- this.logger.info('credentials: token refresh complete; reinvoking getUserToken');
327
- resolve();
328
- });
329
- }))
330
- .then(() => {
331
- if (!this.canAuthorize) {
332
- this.logger.info('credentials: cannot produce an access token from current state');
333
-
334
- return Promise.reject(new Error('Current state cannot produce an access token'));
335
- }
325
+ return Promise.resolve(
326
+ !this.isRefreshing ||
327
+ new Promise((resolve) => {
328
+ this.logger.info(
329
+ 'credentials: token refresh inflight; delaying getUserToken until refresh completes'
330
+ );
331
+ this.once('change:isRefreshing', () => {
332
+ this.logger.info('credentials: token refresh complete; reinvoking getUserToken');
333
+ resolve();
334
+ });
335
+ })
336
+ ).then(() => {
337
+ if (!this.canAuthorize) {
338
+ this.logger.info('credentials: cannot produce an access token from current state');
339
+
340
+ return Promise.reject(new Error('Current state cannot produce an access token'));
341
+ }
336
342
 
337
- if (!scope) {
338
- scope = filterScope('spark:kms', this.config.scope);
339
- }
343
+ if (!scope) {
344
+ scope = filterScope('spark:kms', this.config.scope);
345
+ }
340
346
 
341
- scope = sortScope(scope);
347
+ scope = sortScope(scope);
342
348
 
343
- if (scope === sortScope(this.config.scope)) {
344
- return Promise.resolve(this.supertoken);
345
- }
349
+ if (scope === sortScope(this.config.scope)) {
350
+ return Promise.resolve(this.supertoken);
351
+ }
346
352
 
347
- const token = this.userTokens.get(scope);
353
+ const token = this.userTokens.get(scope);
348
354
 
349
- // we should also check for the token.access_token since token object does
350
- // not get cleared on unsetting while logging out.
351
- if (!token || !token.access_token) {
352
- return this.downscope(scope)
353
- .then(tap((t) => this.userTokens.add(t)));
354
- }
355
+ // we should also check for the token.access_token since token object does
356
+ // not get cleared on unsetting while logging out.
357
+ if (!token || !token.access_token) {
358
+ return this.downscope(scope).then(tap((t) => this.userTokens.add(t)));
359
+ }
355
360
 
356
- return Promise.resolve(token);
357
- });
361
+ return Promise.resolve(token);
362
+ });
358
363
  },
359
364
 
360
365
  @persist('@')
@@ -380,8 +385,7 @@ const Credentials = WebexPlugin.extend({
380
385
  if (attrs.authorization) {
381
386
  if (attrs.authorization.supertoken) {
382
387
  this.supertoken = attrs.authorization.supertoken;
383
- }
384
- else {
388
+ } else {
385
389
  this.supertoken = attrs.authorization;
386
390
  }
387
391
  }
@@ -434,16 +438,14 @@ const Credentials = WebexPlugin.extend({
434
438
 
435
439
  try {
436
440
  this.unset('supertoken');
437
- }
438
- catch (err) {
441
+ } catch (err) {
439
442
  this.logger.warn('credentials: failed to clear supertoken', err);
440
443
  }
441
444
 
442
445
  while (this.userTokens.models.length) {
443
446
  try {
444
447
  this.userTokens.remove(this.userTokens.models[0]);
445
- }
446
- catch (err) {
448
+ } catch (err) {
447
449
  this.logger.warn('credentials: failed to remove user token', err);
448
450
  }
449
451
  }
@@ -480,15 +482,20 @@ const Credentials = WebexPlugin.extend({
480
482
  // while I like #2 from a code simplicity standpoint, the third-party DX
481
483
  // isn't great
482
484
  if (this.config.jwtRefreshCallback) {
483
- return this.config.jwtRefreshCallback(this.webex)
484
- .then((jwt) => this.webex.authorization.requestAccessTokenFromJwt({jwt}));
485
+ return (
486
+ this.config
487
+ .jwtRefreshCallback(this.webex)
488
+ // eslint-disable-next-line no-shadow
489
+ .then((jwt) => this.webex.authorization.requestAccessTokenFromJwt({jwt}))
490
+ );
485
491
  }
486
492
 
487
493
  if (this.webex.internal.services) {
488
494
  this.webex.internal.services.updateCredentialsConfig();
489
495
  }
490
496
 
491
- return supertoken.refresh()
497
+ return supertoken
498
+ .refresh()
492
499
  .then((st) => {
493
500
  // clear refresh timer
494
501
  if (this.refreshTimer) {
@@ -497,20 +504,25 @@ const Credentials = WebexPlugin.extend({
497
504
  }
498
505
  this.supertoken = st;
499
506
 
500
- return Promise.all(tokens.map((token) => this.downscope(token.scope)
501
- // eslint-disable-next-line max-nested-callbacks
502
- .then((t) => {
503
- this.logger.info(`credentials: revoking token for ${token.scope}`);
504
-
505
- return token.revoke()
506
- .catch((err) => {
507
- this.logger.warn('credentials: failed to revoke user token', err);
507
+ return Promise.all(
508
+ tokens.map((token) =>
509
+ this.downscope(token.scope)
510
+ // eslint-disable-next-line max-nested-callbacks
511
+ .then((t) => {
512
+ this.logger.info(`credentials: revoking token for ${token.scope}`);
513
+
514
+ return token
515
+ .revoke()
516
+ .catch((err) => {
517
+ this.logger.warn('credentials: failed to revoke user token', err);
518
+ })
519
+ .then(() => {
520
+ this.userTokens.remove(token.scope);
521
+ this.userTokens.add(t);
522
+ });
508
523
  })
509
- .then(() => {
510
- this.userTokens.remove(token.scope);
511
- this.userTokens.add(t);
512
- });
513
- })));
524
+ )
525
+ );
514
526
  })
515
527
  .then(() => {
516
528
  this.scheduleRefresh(this.supertoken.expires);
@@ -524,8 +536,7 @@ const Credentials = WebexPlugin.extend({
524
536
  while (this.userTokens.models.length) {
525
537
  try {
526
538
  this.userTokens.remove(this.userTokens.models[0]);
527
- }
528
- catch (err) {
539
+ } catch (err) {
529
540
  this.logger.warn('credentials: failed to remove user token', err);
530
541
  }
531
542
  }
@@ -551,12 +562,10 @@ const Credentials = WebexPlugin.extend({
551
562
  const timeoutLength = this.calcRefreshTimeout(expiresIn);
552
563
 
553
564
  this.refreshTimer = safeSetTimeout(() => this.refresh(), timeoutLength);
554
- }
555
- else {
565
+ } else {
556
566
  this.refresh();
557
567
  }
558
- }
559
-
568
+ },
560
569
  });
561
570
 
562
571
  export default Credentials;
@@ -21,20 +21,20 @@ export class OAuthError extends Exception {
21
21
  Object.defineProperties(this, {
22
22
  error: {
23
23
  enumerable: true,
24
- value: body.error
24
+ value: body.error,
25
25
  },
26
26
  errorDescription: {
27
27
  enumerable: true,
28
- value: body.error_description
28
+ value: body.error_description,
29
29
  },
30
30
  errorUri: {
31
31
  enumerable: true,
32
- value: body.error_uri
32
+ value: body.error_uri,
33
33
  },
34
34
  res: {
35
35
  enumerable: false,
36
- value: res
37
- }
36
+ value: res,
37
+ },
38
38
  });
39
39
 
40
40
  return this.errorDescription;
@@ -70,7 +70,6 @@ class UnsupportGrantTypeError extends OAuthError {}
70
70
  */
71
71
  class InvalidScopeError extends OAuthError {}
72
72
 
73
-
74
73
  const errors = {
75
74
  OAuthError,
76
75
  InvalidRequestError,
@@ -87,7 +86,7 @@ const errors = {
87
86
  invalid_scope: InvalidScopeError,
88
87
  select(errorString) {
89
88
  return errors[errorString] || OAuthError;
90
- }
89
+ },
91
90
  };
92
91
 
93
92
  export default errors;
@@ -7,10 +7,7 @@ import {registerPlugin} from '../../webex-core';
7
7
  import Credentials from './credentials';
8
8
 
9
9
  registerPlugin('credentials', Credentials, {
10
- proxies: [
11
- 'canAuthorize',
12
- 'canRefresh'
13
- ]
10
+ proxies: ['canAuthorize', 'canRefresh'],
14
11
  });
15
12
 
16
13
  export {default as Credentials} from './credentials';
@@ -12,10 +12,7 @@ export function sortScope(scope) {
12
12
  return '';
13
13
  }
14
14
 
15
- return scope
16
- .split(' ')
17
- .sort()
18
- .join(' ');
15
+ return scope.split(' ').sort().join(' ');
19
16
  }
20
17
 
21
18
  /**
@@ -11,7 +11,7 @@ const TokenCollection = AmpCollection.extend({
11
11
 
12
12
  model: Token,
13
13
 
14
- namespace: 'Credentials'
14
+ namespace: 'Credentials',
15
15
  });
16
16
 
17
17
  export default TokenCollection;