@webex/webex-core 3.0.0-beta.2 → 3.0.0-beta.21

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 +39 -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 +112 -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 +189 -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,12 @@ const Credentials = WebexPlugin.extend({
59
46
  }
60
47
 
61
48
  return Boolean(this.supertoken && this.supertoken.canRefresh);
62
- }
63
- }
49
+ },
50
+ },
64
51
  },
65
52
 
66
53
  props: {
67
- supertoken: makeStateDataType(Token, 'token').prop
54
+ supertoken: makeStateDataType(Token, 'token').prop,
68
55
  },
69
56
 
70
57
  namespace: 'Credentials',
@@ -72,7 +59,7 @@ const Credentials = WebexPlugin.extend({
72
59
  session: {
73
60
  isRefreshing: {
74
61
  default: false,
75
- type: 'boolean'
62
+ type: 'boolean',
76
63
  },
77
64
  /**
78
65
  * Becomes `true` once the {@link loaded} event fires.
@@ -83,12 +70,12 @@ const Credentials = WebexPlugin.extend({
83
70
  */
84
71
  ready: {
85
72
  default: false,
86
- type: 'boolean'
73
+ type: 'boolean',
87
74
  },
88
75
  refreshTimer: {
89
76
  default: undefined,
90
- type: 'any'
91
- }
77
+ type: 'any',
78
+ },
92
79
  },
93
80
 
94
81
  /**
@@ -120,8 +107,7 @@ const Credentials = WebexPlugin.extend({
120
107
  if (options.state) {
121
108
  if (!isEmpty(options.state)) {
122
109
  options.state = base64.toBase64Url(JSON.stringify(options.state));
123
- }
124
- else {
110
+ } else {
125
111
  delete options.state;
126
112
  }
127
113
  }
@@ -137,27 +123,21 @@ const Credentials = WebexPlugin.extend({
137
123
  * @returns {string} - The OrgId.
138
124
  */
139
125
  getOrgId() {
140
- this.logger.info(
141
- 'credentials: attempting to retrieve the OrgId from token'
142
- );
126
+ this.logger.info('credentials: attempting to retrieve the OrgId from token');
143
127
 
144
128
  try {
145
129
  // Attempt to extract a client-authenticated token's OrgId.
146
130
  this.logger.info('credentials: trying to extract OrgId from JWT');
147
131
 
148
132
  return this.extractOrgIdFromJWT(this.supertoken.access_token);
149
- }
150
- catch (e) {
133
+ } catch (e) {
151
134
  // Attempt to extract a user token's OrgId.
152
135
  this.logger.info('credentials: could not extract OrgId from JWT');
153
- this.logger.info(
154
- 'credentials: attempting to extract OrgId from user token'
155
- );
136
+ this.logger.info('credentials: attempting to extract OrgId from user token');
156
137
 
157
138
  try {
158
139
  return this.extractOrgIdFromUserToken(this.supertoken?.access_token);
159
- }
160
- catch (f) {
140
+ } catch (f) {
161
141
  this.logger.info('credentials: could not extract OrgId from user token');
162
142
  throw f;
163
143
  }
@@ -218,10 +198,11 @@ const Credentials = WebexPlugin.extend({
218
198
  * @returns {[type]}
219
199
  */
220
200
  buildLogoutUrl(options = {}) {
221
- return `${this.config.logoutUrl}?${querystring.stringify(Object.assign({
201
+ return `${this.config.logoutUrl}?${querystring.stringify({
222
202
  cisService: this.config.service,
223
- goto: this.config.redirect_uri
224
- }, options))}`;
203
+ goto: this.config.redirect_uri,
204
+ ...options,
205
+ })}`;
225
206
  },
226
207
 
227
208
  /**
@@ -233,7 +214,7 @@ const Credentials = WebexPlugin.extend({
233
214
  * @returns {number}
234
215
  */
235
216
  calcRefreshTimeout(expiration) {
236
- return Math.floor((Math.floor(Math.random() * 4) + 6) / 10 * expiration);
217
+ return Math.floor(((Math.floor(Math.random() * 4) + 6) / 10) * expiration);
237
218
  },
238
219
 
239
220
  constructor(...args) {
@@ -258,13 +239,14 @@ const Credentials = WebexPlugin.extend({
258
239
  * @returns {Promise<Token>}
259
240
  */
260
241
  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}`);
242
+ return this.supertoken.downscope(scope).catch((reason) => {
243
+ this.logger.trace(`credentials: failed to downscope supertoken to ${scope}`, reason);
244
+ this.logger.trace(`credentials: falling back to supertoken for ${scope}`);
265
245
 
266
- return Promise.resolve(new Token(Object.assign({scope}, this.supertoken.serialize())), {parent: this});
246
+ return Promise.resolve(new Token({scope, ...this.supertoken.serialize()}), {
247
+ parent: this,
267
248
  });
249
+ });
268
250
  },
269
251
 
270
252
  /**
@@ -279,23 +261,24 @@ const Credentials = WebexPlugin.extend({
279
261
  getClientToken(options = {}) {
280
262
  this.logger.info('credentials: requesting client credentials grant');
281
263
 
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
- })
264
+ return this.webex
265
+ .request({
266
+ /* eslint-disable camelcase */
267
+ method: 'POST',
268
+ uri: options.uri || this.config.tokenUrl,
269
+ form: {
270
+ grant_type: 'client_credentials',
271
+ scope: options.scope || 'webexsquare:admin',
272
+ self_contained_token: true,
273
+ },
274
+ auth: {
275
+ user: this.config.client_id,
276
+ pass: this.config.client_secret,
277
+ sendImmediately: true,
278
+ },
279
+ shouldRefreshAccessToken: false,
280
+ /* eslint-enable camelcase */
281
+ })
299
282
  .then((res) => new Token(res.body, {parent: this}))
300
283
  .catch((res) => {
301
284
  if (res.statusCode !== 400) {
@@ -320,41 +303,44 @@ const Credentials = WebexPlugin.extend({
320
303
  * @returns {Promise<Token>}
321
304
  */
322
305
  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
- }
306
+ return Promise.resolve(
307
+ !this.isRefreshing ||
308
+ new Promise((resolve) => {
309
+ this.logger.info(
310
+ 'credentials: token refresh inflight; delaying getUserToken until refresh completes'
311
+ );
312
+ this.once('change:isRefreshing', () => {
313
+ this.logger.info('credentials: token refresh complete; reinvoking getUserToken');
314
+ resolve();
315
+ });
316
+ })
317
+ ).then(() => {
318
+ if (!this.canAuthorize) {
319
+ this.logger.info('credentials: cannot produce an access token from current state');
320
+
321
+ return Promise.reject(new Error('Current state cannot produce an access token'));
322
+ }
336
323
 
337
- if (!scope) {
338
- scope = filterScope('spark:kms', this.config.scope);
339
- }
324
+ if (!scope) {
325
+ scope = filterScope('spark:kms', this.config.scope);
326
+ }
340
327
 
341
- scope = sortScope(scope);
328
+ scope = sortScope(scope);
342
329
 
343
- if (scope === sortScope(this.config.scope)) {
344
- return Promise.resolve(this.supertoken);
345
- }
330
+ if (scope === sortScope(this.config.scope)) {
331
+ return Promise.resolve(this.supertoken);
332
+ }
346
333
 
347
- const token = this.userTokens.get(scope);
334
+ const token = this.userTokens.get(scope);
348
335
 
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
- }
336
+ // we should also check for the token.access_token since token object does
337
+ // not get cleared on unsetting while logging out.
338
+ if (!token || !token.access_token) {
339
+ return this.downscope(scope).then(tap((t) => this.userTokens.add(t)));
340
+ }
355
341
 
356
- return Promise.resolve(token);
357
- });
342
+ return Promise.resolve(token);
343
+ });
358
344
  },
359
345
 
360
346
  @persist('@')
@@ -380,8 +366,7 @@ const Credentials = WebexPlugin.extend({
380
366
  if (attrs.authorization) {
381
367
  if (attrs.authorization.supertoken) {
382
368
  this.supertoken = attrs.authorization.supertoken;
383
- }
384
- else {
369
+ } else {
385
370
  this.supertoken = attrs.authorization;
386
371
  }
387
372
  }
@@ -434,16 +419,14 @@ const Credentials = WebexPlugin.extend({
434
419
 
435
420
  try {
436
421
  this.unset('supertoken');
437
- }
438
- catch (err) {
422
+ } catch (err) {
439
423
  this.logger.warn('credentials: failed to clear supertoken', err);
440
424
  }
441
425
 
442
426
  while (this.userTokens.models.length) {
443
427
  try {
444
428
  this.userTokens.remove(this.userTokens.models[0]);
445
- }
446
- catch (err) {
429
+ } catch (err) {
447
430
  this.logger.warn('credentials: failed to remove user token', err);
448
431
  }
449
432
  }
@@ -480,15 +463,20 @@ const Credentials = WebexPlugin.extend({
480
463
  // while I like #2 from a code simplicity standpoint, the third-party DX
481
464
  // isn't great
482
465
  if (this.config.jwtRefreshCallback) {
483
- return this.config.jwtRefreshCallback(this.webex)
484
- .then((jwt) => this.webex.authorization.requestAccessTokenFromJwt({jwt}));
466
+ return (
467
+ this.config
468
+ .jwtRefreshCallback(this.webex)
469
+ // eslint-disable-next-line no-shadow
470
+ .then((jwt) => this.webex.authorization.requestAccessTokenFromJwt({jwt}))
471
+ );
485
472
  }
486
473
 
487
474
  if (this.webex.internal.services) {
488
475
  this.webex.internal.services.updateCredentialsConfig();
489
476
  }
490
477
 
491
- return supertoken.refresh()
478
+ return supertoken
479
+ .refresh()
492
480
  .then((st) => {
493
481
  // clear refresh timer
494
482
  if (this.refreshTimer) {
@@ -497,20 +485,25 @@ const Credentials = WebexPlugin.extend({
497
485
  }
498
486
  this.supertoken = st;
499
487
 
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);
488
+ return Promise.all(
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
+ });
508
504
  })
509
- .then(() => {
510
- this.userTokens.remove(token.scope);
511
- this.userTokens.add(t);
512
- });
513
- })));
505
+ )
506
+ );
514
507
  })
515
508
  .then(() => {
516
509
  this.scheduleRefresh(this.supertoken.expires);
@@ -524,8 +517,7 @@ const Credentials = WebexPlugin.extend({
524
517
  while (this.userTokens.models.length) {
525
518
  try {
526
519
  this.userTokens.remove(this.userTokens.models[0]);
527
- }
528
- catch (err) {
520
+ } catch (err) {
529
521
  this.logger.warn('credentials: failed to remove user token', err);
530
522
  }
531
523
  }
@@ -551,12 +543,10 @@ const Credentials = WebexPlugin.extend({
551
543
  const timeoutLength = this.calcRefreshTimeout(expiresIn);
552
544
 
553
545
  this.refreshTimer = safeSetTimeout(() => this.refresh(), timeoutLength);
554
- }
555
- else {
546
+ } else {
556
547
  this.refresh();
557
548
  }
558
- }
559
-
549
+ },
560
550
  });
561
551
 
562
552
  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;