@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
@@ -28,7 +28,8 @@ function promiseTick(count) {
28
28
  return promise;
29
29
  }
30
30
 
31
- const AUTHORIZATION_STRING = 'https://api.ciscospark.com/v1/authorize?client_id=MOCK_CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000&scope=spark%3Arooms_read%20spark%3Ateams_read&state=set_state_here';
31
+ const AUTHORIZATION_STRING =
32
+ 'https://api.ciscospark.com/v1/authorize?client_id=MOCK_CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000&scope=spark%3Arooms_read%20spark%3Ateams_read&state=set_state_here';
32
33
 
33
34
  describe('webex-core', () => {
34
35
  describe('Credentials', () => {
@@ -69,7 +70,7 @@ describe('webex-core', () => {
69
70
  assert.isFalse(credentials.canAuthorize);
70
71
 
71
72
  credentials.supertoken = makeToken(webex, {
72
- access_token: 'AT'
73
+ access_token: 'AT',
73
74
  });
74
75
  assert.isTrue(credentials.canAuthorize);
75
76
 
@@ -77,13 +78,13 @@ describe('webex-core', () => {
77
78
  assert.isFalse(credentials.canAuthorize);
78
79
 
79
80
  credentials.supertoken = makeToken(webex, {
80
- access_token: 'AT'
81
+ access_token: 'AT',
81
82
  });
82
83
  assert.isTrue(credentials.canAuthorize);
83
84
 
84
85
  credentials.supertoken = makeToken(webex, {
85
86
  access_token: 'AT',
86
- expires: Date.now() - 10000
87
+ expires: Date.now() - 10000,
87
88
  });
88
89
  assert.isFalse(credentials.supertoken.canAuthorize);
89
90
  assert.isFalse(credentials.canRefresh);
@@ -95,7 +96,7 @@ describe('webex-core', () => {
95
96
  assert.isFalse(credentials.canAuthorize);
96
97
  credentials.supertoken = makeToken(webex, {
97
98
  access_token: 'AT',
98
- refresh_token: 'RT'
99
+ refresh_token: 'RT',
99
100
  });
100
101
  credentials.supertoken.unset('access_token');
101
102
  assert.isTrue(credentials.canAuthorize);
@@ -109,9 +110,13 @@ describe('webex-core', () => {
109
110
 
110
111
  webex.trigger('change:config');
111
112
  assert.isFalse(credentials.canRefresh);
112
- credentials.supertoken = makeToken(webex, {
113
- access_token: 'AT'
114
- }, {parent: true});
113
+ credentials.supertoken = makeToken(
114
+ webex,
115
+ {
116
+ access_token: 'AT',
117
+ },
118
+ {parent: true}
119
+ );
115
120
  assert.isFalse(credentials.canRefresh);
116
121
 
117
122
  webex.config.credentials.refreshCallback = inBrowser && noop;
@@ -120,7 +125,7 @@ describe('webex-core', () => {
120
125
  assert.isFalse(credentials.canRefresh);
121
126
  credentials.supertoken = makeToken(webex, {
122
127
  access_token: 'AT',
123
- refresh_token: 'RT'
128
+ refresh_token: 'RT',
124
129
  });
125
130
  assert.isTrue(credentials.supertoken.canRefresh);
126
131
  assert.isTrue(credentials.canRefresh);
@@ -131,8 +136,8 @@ describe('webex-core', () => {
131
136
  it('requires `state` to be an object', () => {
132
137
  const webex = new MockWebex({
133
138
  children: {
134
- credentials: Credentials
135
- }
139
+ credentials: Credentials,
140
+ },
136
141
  });
137
142
 
138
143
  webex.trigger('change:config)');
@@ -161,7 +166,7 @@ describe('webex-core', () => {
161
166
 
162
167
  assert.match(credentials.buildLoginUrl({state: {}}), /idbroker/);
163
168
  webex.config.credentials = {
164
- authorizationString: AUTHORIZATION_STRING
169
+ authorizationString: AUTHORIZATION_STRING,
165
170
  };
166
171
  credentials = new Credentials({}, {parent: webex});
167
172
  webex.trigger('change:config');
@@ -174,7 +179,12 @@ describe('webex-core', () => {
174
179
 
175
180
  webex.trigger('change:config');
176
181
 
177
- assert.equal(credentials.buildLoginUrl({state: {page: 'front'}}), `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/authorize?state=eyJwYWdlIjoiZnJvbnQifQ&client_id=fake&redirect_uri=http%3A%2F%2Fexample.com&scope=scope%3Aone&response_type=code`);
182
+ assert.equal(
183
+ credentials.buildLoginUrl({state: {page: 'front'}}),
184
+ `${
185
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
186
+ }/idb/oauth2/v1/authorize?state=eyJwYWdlIjoiZnJvbnQifQ&client_id=fake&redirect_uri=http%3A%2F%2Fexample.com&scope=scope%3Aone&response_type=code`
187
+ );
178
188
  });
179
189
 
180
190
  skipInBrowser(it)('generates the login url with empty state param', () => {
@@ -183,11 +193,15 @@ describe('webex-core', () => {
183
193
 
184
194
  webex.trigger('change:config');
185
195
 
186
- assert.equal(credentials.buildLoginUrl({state: {}}), `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/authorize?client_id=fake&redirect_uri=http%3A%2F%2Fexample.com&scope=scope%3Aone&response_type=code`);
196
+ assert.equal(
197
+ credentials.buildLoginUrl({state: {}}),
198
+ `${
199
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
200
+ }/idb/oauth2/v1/authorize?client_id=fake&redirect_uri=http%3A%2F%2Fexample.com&scope=scope%3Aone&response_type=code`
201
+ );
187
202
  });
188
203
  });
189
204
 
190
-
191
205
  describe('#buildLogoutUrl()', () => {
192
206
  skipInBrowser(it)('generates the logout url', () => {
193
207
  const webex = new MockWebex();
@@ -196,7 +210,12 @@ describe('webex-core', () => {
196
210
  const credentials = new Credentials(undefined, {parent: webex});
197
211
 
198
212
  webex.trigger('change:config');
199
- assert.equal(credentials.buildLogoutUrl(), `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/logout?cisService=webex&goto=ru`);
213
+ assert.equal(
214
+ credentials.buildLogoutUrl(),
215
+ `${
216
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
217
+ }/idb/oauth2/v1/logout?cisService=webex&goto=ru`
218
+ );
200
219
  });
201
220
 
202
221
  skipInBrowser(it)('includes a token param if passed', () => {
@@ -206,7 +225,12 @@ describe('webex-core', () => {
206
225
  const credentials = new Credentials(undefined, {parent: webex});
207
226
 
208
227
  webex.trigger('change:config');
209
- assert.equal(credentials.buildLogoutUrl({token: 't'}), `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/logout?cisService=webex&goto=ru&token=t`);
228
+ assert.equal(
229
+ credentials.buildLogoutUrl({token: 't'}),
230
+ `${
231
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
232
+ }/idb/oauth2/v1/logout?cisService=webex&goto=ru&token=t`
233
+ );
210
234
  });
211
235
 
212
236
  it('always fallsback to idbroker', () => {
@@ -224,7 +248,10 @@ describe('webex-core', () => {
224
248
  const credentials = new Credentials(undefined, {parent: webex});
225
249
 
226
250
  webex.trigger('change:config');
227
- assert.match(credentials.buildLogoutUrl({goto: 'http://example.com/'}), /goto=http%3A%2F%2Fexample.com%2F/);
251
+ assert.match(
252
+ credentials.buildLogoutUrl({goto: 'http://example.com/'}),
253
+ /goto=http%3A%2F%2Fexample.com%2F/
254
+ );
228
255
  });
229
256
  });
230
257
 
@@ -240,7 +267,8 @@ describe('webex-core', () => {
240
267
 
241
268
  it('should return the OrgId of JWT-authenticated user', () => {
242
269
  credentials.supertoken = {
243
- access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZWFsbSI6Im15LXJlYWxtIn0.U16gzUsaRW1VVikJA2VeXRHPX716tG1_B42oxzy1UMk'
270
+ access_token:
271
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZWFsbSI6Im15LXJlYWxtIn0.U16gzUsaRW1VVikJA2VeXRHPX716tG1_B42oxzy1UMk',
244
272
  };
245
273
 
246
274
  orgId = 'my-realm';
@@ -252,17 +280,14 @@ describe('webex-core', () => {
252
280
  orgId = 'this-is-an-org-id';
253
281
 
254
282
  credentials.supertoken = {
255
- access_token: `000_000_${orgId}`
283
+ access_token: `000_000_${orgId}`,
256
284
  };
257
285
 
258
286
  assert.equal(credentials.getOrgId(), orgId);
259
287
  });
260
288
 
261
289
  it('should throw if the OrgId was not determined', () =>
262
- assert.throws(
263
- () => credentials.getOrgId(),
264
- 'the provided token is not a valid format'
265
- ));
290
+ assert.throws(() => credentials.getOrgId(), 'the provided token is not a valid format'));
266
291
  });
267
292
 
268
293
  describe('#extractOrgIdFromJWT()', () => {
@@ -275,7 +300,8 @@ describe('webex-core', () => {
275
300
  });
276
301
 
277
302
  it('should return the OrgId of a provided JWT', () => {
278
- const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZWFsbSI6Im15LXJlYWxtIn0.U16gzUsaRW1VVikJA2VeXRHPX716tG1_B42oxzy1UMk';
303
+ const jwt =
304
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyZWFsbSI6Im15LXJlYWxtIn0.U16gzUsaRW1VVikJA2VeXRHPX716tG1_B42oxzy1UMk';
279
305
  const realm = 'my-realm';
280
306
 
281
307
  assert.equal(credentials.extractOrgIdFromJWT(jwt), realm);
@@ -285,7 +311,8 @@ describe('webex-core', () => {
285
311
  assert.throws(() => credentials.extractOrgIdFromJWT('not-valid')));
286
312
 
287
313
  it('should throw if the provided JWT does not contain an OrgId', () => {
288
- const jwtNoOrg = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
314
+ const jwtNoOrg =
315
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
289
316
 
290
317
  assert.throws(() => credentials.extractOrgIdFromJWT(jwtNoOrg));
291
318
  });
@@ -324,7 +351,7 @@ describe('webex-core', () => {
324
351
  webex.config.credentials = {
325
352
  client_id: 'ci',
326
353
  redirect_uri: 'ru',
327
- scope: 's'
354
+ scope: 's',
328
355
  };
329
356
 
330
357
  let credentials = new Credentials(undefined, {parent: webex});
@@ -358,16 +385,26 @@ describe('webex-core', () => {
358
385
  'data.supertoken.access_token',
359
386
  'data.authorization',
360
387
  'data.authorization.supertoken',
361
- 'data.authorization.supertoken.access_token'
362
- ].reduce((acc, path) => acc.concat(['ST', 'Bearer ST'].map((str) => {
363
- const obj = {
364
- msg: `accepts token string "${str}" at path "${path.split('.').slice(1).join('.')}"`
365
- };
366
-
367
- set(obj, path, str);
368
-
369
- return obj;
370
- })), [])
388
+ 'data.authorization.supertoken.access_token',
389
+ ]
390
+ .reduce(
391
+ (acc, path) =>
392
+ acc.concat(
393
+ ['ST', 'Bearer ST'].map((str) => {
394
+ const obj = {
395
+ msg: `accepts token string "${str}" at path "${path
396
+ .split('.')
397
+ .slice(1)
398
+ .join('.')}"`,
399
+ };
400
+
401
+ set(obj, path, str);
402
+
403
+ return obj;
404
+ })
405
+ ),
406
+ []
407
+ )
371
408
  .forEach(({msg, data}) => {
372
409
  it(msg, () => {
373
410
  const webex = new MockWebex();
@@ -384,12 +421,12 @@ describe('webex-core', () => {
384
421
  const supertoken = makeToken(webex, {
385
422
  access_token: 'ST',
386
423
  refresh_token: 'RT',
387
- expires: Date.now() + 10000
424
+ expires: Date.now() + 10000,
388
425
  });
389
426
  const supertoken2 = makeToken(webex, {
390
427
  access_token: 'ST2',
391
428
  refresh_token: 'RT2',
392
- expires: Date.now() + 20000
429
+ expires: Date.now() + 20000,
393
430
  });
394
431
 
395
432
  sinon.stub(supertoken, 'refresh').returns(Promise.resolve(supertoken2));
@@ -414,7 +451,7 @@ describe('webex-core', () => {
414
451
  const supertoken = makeToken(webex, {
415
452
  access_token: 'ST',
416
453
  refresh_token: 'RT',
417
- expires: Date.now() - 10000
454
+ expires: Date.now() - 10000,
418
455
  });
419
456
 
420
457
  sinon.stub(supertoken, 'refresh').returns(Promise.reject());
@@ -437,25 +474,21 @@ describe('webex-core', () => {
437
474
  const st = makeToken(webex, {access_token: 'ST'});
438
475
  const t1 = makeToken(webex, {
439
476
  access_token: 'AT1',
440
- scope: 'scope1'
477
+ scope: 'scope1',
441
478
  });
442
479
  const t2 = makeToken(webex, {
443
480
  access_token: 'AT2',
444
- scope: 'scope2'
481
+ scope: 'scope2',
445
482
  });
446
483
 
447
484
  credentials.set({
448
485
  supertoken: st,
449
- userTokens: [
450
- t1, t2
451
- ]
486
+ userTokens: [t1, t2],
452
487
  });
453
488
 
454
489
  return Promise.all([
455
- credentials.getUserToken('scope1')
456
- .then((result) => assert.deepEqual(result, t1)),
457
- credentials.getUserToken('scope2')
458
- .then((result) => assert.deepEqual(result, t2))
490
+ credentials.getUserToken('scope1').then((result) => assert.deepEqual(result, t1)),
491
+ credentials.getUserToken('scope2').then((result) => assert.deepEqual(result, t2)),
459
492
  ]);
460
493
  });
461
494
 
@@ -467,31 +500,31 @@ describe('webex-core', () => {
467
500
  webex.trigger('change:config');
468
501
 
469
502
  credentials.supertoken = makeToken(webex, {
470
- access_token: 'ST'
503
+ access_token: 'ST',
471
504
  });
472
505
 
473
506
  const t2 = makeToken(webex, {
474
- access_token: 'AT2'
507
+ access_token: 'AT2',
475
508
  });
476
509
 
477
510
  sinon.stub(credentials.supertoken, 'downscope').returns(Promise.resolve(t2));
478
511
 
479
512
  const t1 = makeToken(webex, {
480
513
  access_token: 'AT1',
481
- scope: 'scope1'
514
+ scope: 'scope1',
482
515
  });
483
516
 
484
517
  credentials.set({
485
- userTokens: [t1]
518
+ userTokens: [t1],
486
519
  });
487
520
 
488
- return credentials.getUserToken('scope2')
521
+ return credentials
522
+ .getUserToken('scope2')
489
523
  .then((result) => assert.deepEqual(result, t2))
490
524
  .then(() => assert.calledWith(credentials.supertoken.downscope, 'scope2'));
491
525
  });
492
526
  });
493
527
 
494
-
495
528
  describe('when no scope is specified', () => {
496
529
  it('resolves with a token containing all but the kms scopes', () => {
497
530
  const webex = new MockWebex();
@@ -502,7 +535,7 @@ describe('webex-core', () => {
502
535
  webex.trigger('change:config');
503
536
 
504
537
  credentials.supertoken = makeToken(webex, {
505
- access_token: 'ST'
538
+ access_token: 'ST',
506
539
  });
507
540
 
508
541
  // const t2 = makeToken(webex, {
@@ -513,15 +546,14 @@ describe('webex-core', () => {
513
546
 
514
547
  const t1 = makeToken(webex, {
515
548
  access_token: 'AT1',
516
- scope: 'scope1'
549
+ scope: 'scope1',
517
550
  });
518
551
 
519
552
  credentials.set({
520
- userTokens: [t1]
553
+ userTokens: [t1],
521
554
  });
522
555
 
523
- return credentials.getUserToken()
524
- .then((result) => assert.deepEqual(result, t1));
556
+ return credentials.getUserToken().then((result) => assert.deepEqual(result, t1));
525
557
  });
526
558
  });
527
559
 
@@ -529,8 +561,8 @@ describe('webex-core', () => {
529
561
  it('falls back to the supertoken', () => {
530
562
  const webex = new MockWebex({
531
563
  children: {
532
- logger: Logger
533
- }
564
+ logger: Logger,
565
+ },
534
566
  });
535
567
 
536
568
  webex.config.credentials.scope = 'scope1 spark:kms';
@@ -539,21 +571,24 @@ describe('webex-core', () => {
539
571
  webex.trigger('change:config');
540
572
 
541
573
  credentials.supertoken = makeToken(webex, {
542
- access_token: 'ST'
574
+ access_token: 'ST',
543
575
  });
544
576
 
545
- sinon.stub(credentials.supertoken, 'downscope').returns(Promise.reject(new Error('downscope failed')));
577
+ sinon
578
+ .stub(credentials.supertoken, 'downscope')
579
+ .returns(Promise.reject(new Error('downscope failed')));
546
580
 
547
581
  const t1 = makeToken(webex, {
548
582
  access_token: 'AT1',
549
- scope: 'scope1'
583
+ scope: 'scope1',
550
584
  });
551
585
 
552
586
  credentials.set({
553
- userTokens: [t1]
587
+ userTokens: [t1],
554
588
  });
555
589
 
556
- return credentials.getUserToken('scope2')
590
+ return credentials
591
+ .getUserToken('scope2')
557
592
  .then((t) => assert.equal(t.access_token, credentials.supertoken.access_token));
558
593
  });
559
594
  });
@@ -568,14 +603,16 @@ describe('webex-core', () => {
568
603
 
569
604
  const supertoken1 = makeToken(webex, {
570
605
  access_token: 'ST1',
571
- refresh_token: 'RT1'
606
+ refresh_token: 'RT1',
572
607
  });
573
608
 
574
609
  credentials.set({supertoken: supertoken1});
575
610
 
576
- sinon.stub(supertoken1, 'downscope').returns(Promise.resolve(new Token({access_token: 'ST1ATD'})));
611
+ sinon
612
+ .stub(supertoken1, 'downscope')
613
+ .returns(Promise.resolve(new Token({access_token: 'ST1ATD'})));
577
614
  const supertoken2 = makeToken(webex, {
578
- access_token: 'ST2'
615
+ access_token: 'ST2',
579
616
  });
580
617
 
581
618
  sinon.stub(supertoken1, 'refresh').returns(Promise.resolve(supertoken2));
@@ -586,8 +623,7 @@ describe('webex-core', () => {
586
623
 
587
624
  return Promise.all([
588
625
  credentials.refresh(),
589
- credentials.getUserToken('scope2')
590
- .then((result) => assert.deepEqual(result, at2))
626
+ credentials.getUserToken('scope2').then((result) => assert.deepEqual(result, at2)),
591
627
  ]);
592
628
  });
593
629
  });
@@ -600,16 +636,16 @@ describe('webex-core', () => {
600
636
  webex.trigger('change:config');
601
637
  const st = makeToken(webex, {
602
638
  access_token: 'ST',
603
- refresh_token: 'RT'
639
+ refresh_token: 'RT',
604
640
  });
605
641
 
606
642
  const st2 = makeToken(webex, {
607
643
  access_token: 'ST2',
608
- refresh_token: 'RT2'
644
+ refresh_token: 'RT2',
609
645
  });
610
646
 
611
647
  credentials.set({
612
- supertoken: st
648
+ supertoken: st,
613
649
  });
614
650
 
615
651
  sinon.stub(credentials, 'refresh').returns(Promise.resolve(st2));
@@ -618,12 +654,11 @@ describe('webex-core', () => {
618
654
  assert.isDefined(credentials.refreshTimer);
619
655
  assert.notCalled(credentials.refresh);
620
656
 
621
- return credentials.invalidate()
622
- .then(() => {
623
- clock.tick(10000);
624
- assert.isUndefined(credentials.refreshTimer);
625
- assert.notCalled(credentials.refresh);
626
- });
657
+ return credentials.invalidate().then(() => {
658
+ clock.tick(10000);
659
+ assert.isUndefined(credentials.refreshTimer);
660
+ assert.notCalled(credentials.refresh);
661
+ });
627
662
  });
628
663
 
629
664
  it('clears the tokens from boundedStorage', () => {
@@ -632,25 +667,22 @@ describe('webex-core', () => {
632
667
 
633
668
  webex.trigger('change:config');
634
669
  const st = makeToken(webex, {
635
- access_token: 'ST'
670
+ access_token: 'ST',
636
671
  });
637
672
 
638
673
  const t1 = makeToken(webex, {
639
674
  access_token: 'AT1',
640
- scope: 'scope1'
675
+ scope: 'scope1',
641
676
  });
642
677
 
643
678
  const t2 = makeToken(webex, {
644
679
  access_token: 'AT2',
645
- scope: 'scope2'
680
+ scope: 'scope2',
646
681
  });
647
682
 
648
683
  credentials.set({
649
684
  supertoken: st,
650
- userTokens: [
651
- t1,
652
- t2
653
- ]
685
+ userTokens: [t1, t2],
654
686
  });
655
687
 
656
688
  return new Promise((resolve) => {
@@ -665,19 +697,24 @@ describe('webex-core', () => {
665
697
  return credentials.invalidate();
666
698
  })
667
699
  .then(() => promiseTick(500))
668
- .then(() => new Promise((resolve) => {
669
- setTimeout(resolve, 1);
670
- clock.tick(1000);
671
- }))
700
+ .then(
701
+ () =>
702
+ new Promise((resolve) => {
703
+ setTimeout(resolve, 1);
704
+ clock.tick(1000);
705
+ })
706
+ )
672
707
  .then(() => promiseTick(500))
673
- .then(() => new Promise((resolve) => {
674
- setTimeout(resolve, 1);
675
- clock.tick(1000);
676
- }))
708
+ .then(
709
+ () =>
710
+ new Promise((resolve) => {
711
+ setTimeout(resolve, 1);
712
+ clock.tick(1000);
713
+ })
714
+ )
677
715
  .then(() => assert.isRejected(webex.boundedStorage.get('Credentials', '@'), /NotFound/));
678
716
  });
679
717
 
680
-
681
718
  it('does not induce any token refreshes');
682
719
 
683
720
  it('prevents #getUserToken() from being invoked', () => {
@@ -687,23 +724,27 @@ describe('webex-core', () => {
687
724
  webex.trigger('change:config');
688
725
  const st = makeToken(webex, {
689
726
  access_token: 'ST',
690
- refresh_token: 'RT'
727
+ refresh_token: 'RT',
691
728
  });
692
729
 
693
730
  const t1 = makeToken(webex, {
694
731
  access_token: 'AT1',
695
- scope: 'scope1'
732
+ scope: 'scope1',
696
733
  });
697
734
 
698
735
  credentials.set({
699
736
  supertoken: st,
700
- userTokens: [
701
- t1
702
- ]
737
+ userTokens: [t1],
703
738
  });
704
739
 
705
- return credentials.invalidate()
706
- .then(() => assert.isRejected(credentials.getUserToken(), /Current state cannot produce an access token/));
740
+ return credentials
741
+ .invalidate()
742
+ .then(() =>
743
+ assert.isRejected(
744
+ credentials.getUserToken(),
745
+ /Current state cannot produce an access token/
746
+ )
747
+ );
707
748
  });
708
749
  });
709
750
 
@@ -715,22 +756,22 @@ describe('webex-core', () => {
715
756
  webex.trigger('change:config');
716
757
  const st = makeToken(webex, {
717
758
  access_token: 'ST',
718
- refresh_token: 'RT'
759
+ refresh_token: 'RT',
719
760
  });
720
761
 
721
762
  const st2 = makeToken(webex, {
722
763
  access_token: 'ST2',
723
- refresh_token: 'RT2'
764
+ refresh_token: 'RT2',
724
765
  });
725
766
 
726
767
  const t1 = makeToken(webex, {
727
768
  access_token: 'AT1',
728
- scope: 'scope1'
769
+ scope: 'scope1',
729
770
  });
730
771
 
731
772
  const t2 = makeToken(webex, {
732
773
  access_token: 'AT2',
733
- scope: 'scope2'
774
+ scope: 'scope2',
734
775
  });
735
776
 
736
777
  sinon.stub(st2, 'downscope').returns(Promise.resolve(t2));
@@ -740,14 +781,13 @@ describe('webex-core', () => {
740
781
 
741
782
  credentials.set({
742
783
  supertoken: st,
743
- userTokens: [
744
- t1
745
- ]
784
+ userTokens: [t1],
746
785
  });
747
786
 
748
787
  assert.equal(credentials.userTokens.get(t1.scope), t1);
749
788
 
750
- return credentials.refresh()
789
+ return credentials
790
+ .refresh()
751
791
  .then(() => assert.called(st.refresh))
752
792
  .then(() => assert.calledWith(st2.downscope, 'scope1'))
753
793
  .then(() => assert.called(t1.revoke))
@@ -763,22 +803,22 @@ describe('webex-core', () => {
763
803
  webex.trigger('change:config');
764
804
  const st = makeToken(webex, {
765
805
  access_token: 'ST',
766
- refresh_token: 'RT'
806
+ refresh_token: 'RT',
767
807
  });
768
808
 
769
809
  const st2 = makeToken(webex, {
770
810
  access_token: 'ST2',
771
- refresh_token: 'RT2'
811
+ refresh_token: 'RT2',
772
812
  });
773
813
 
774
814
  const t1 = makeToken(webex, {
775
815
  access_token: 'AT1',
776
- scope: 'scope1'
816
+ scope: 'scope1',
777
817
  });
778
818
 
779
819
  const t2 = makeToken(webex, {
780
820
  access_token: 'AT2',
781
- scope: 'scope2'
821
+ scope: 'scope2',
782
822
  });
783
823
 
784
824
  sinon.stub(st2, 'downscope').returns(Promise.resolve(t2));
@@ -788,14 +828,13 @@ describe('webex-core', () => {
788
828
 
789
829
  credentials.set({
790
830
  supertoken: st,
791
- userTokens: [
792
- t1
793
- ]
831
+ userTokens: [t1],
794
832
  });
795
833
 
796
834
  assert.equal(credentials.userTokens.get(t1.scope), t1);
797
835
 
798
- return credentials.refresh()
836
+ return credentials
837
+ .refresh()
799
838
  .then(() => assert.called(st.refresh))
800
839
  .then(() => assert.calledWith(st2.downscope, 'scope1'))
801
840
  .then(() => assert.called(t1.revoke))
@@ -807,33 +846,30 @@ describe('webex-core', () => {
807
846
  it('removes and revokes all child tokens', () => {
808
847
  const webex = new MockWebex({
809
848
  children: {
810
- logger: Logger
811
- }
849
+ logger: Logger,
850
+ },
812
851
  });
813
852
  const credentials = new Credentials(undefined, {parent: webex});
814
853
 
815
854
  webex.trigger('change:config');
816
855
  const st = makeToken(webex, {
817
856
  access_token: 'ST',
818
- refresh_token: 'RT'
857
+ refresh_token: 'RT',
819
858
  });
820
859
 
821
860
  sinon.stub(st, 'refresh').returns(Promise.resolve(makeToken(webex, {access_token: 'ST2'})));
822
861
 
823
862
  const t1 = makeToken(webex, {
824
863
  access_token: 'AT1',
825
- scope: 'scope1'
864
+ scope: 'scope1',
826
865
  });
827
866
 
828
867
  credentials.set({
829
868
  supertoken: st,
830
- userTokens: [
831
- t1
832
- ]
869
+ userTokens: [t1],
833
870
  });
834
871
 
835
- return credentials.refresh()
836
- .then(() => assert.called(st.refresh));
872
+ return credentials.refresh().then(() => assert.called(st.refresh));
837
873
  });
838
874
 
839
875
  it('allows #getUserToken() to be revoked, but #getUserToken() promises will not resolve until the suport token has been refreshed', () => {
@@ -843,22 +879,22 @@ describe('webex-core', () => {
843
879
  webex.trigger('change:config');
844
880
  const st1 = makeToken(webex, {
845
881
  access_token: 'ST1',
846
- refresh_token: 'RT1'
882
+ refresh_token: 'RT1',
847
883
  });
848
884
 
849
885
  const st2 = makeToken(webex, {
850
886
  access_token: 'ST2',
851
- refresh_token: 'RT1'
887
+ refresh_token: 'RT1',
852
888
  });
853
889
 
854
890
  const t1 = makeToken(webex, {
855
891
  access_token: 'AT1',
856
- scope: 'scope1'
892
+ scope: 'scope1',
857
893
  });
858
894
 
859
895
  const t2 = makeToken(webex, {
860
896
  access_token: 'AT2',
861
- scope: 'scope1'
897
+ scope: 'scope1',
862
898
  });
863
899
 
864
900
  sinon.stub(st1, 'refresh').returns(Promise.resolve(st2));
@@ -866,15 +902,12 @@ describe('webex-core', () => {
866
902
 
867
903
  credentials.set({
868
904
  supertoken: st1,
869
- userTokens: [
870
- t1
871
- ]
905
+ userTokens: [t1],
872
906
  });
873
907
 
874
908
  credentials.refresh();
875
909
 
876
- return credentials.getUserToken('scope1')
877
- .then((result) => assert.deepEqual(result, t2));
910
+ return credentials.getUserToken('scope1').then((result) => assert.deepEqual(result, t2));
878
911
  });
879
912
 
880
913
  it('emits InvalidRequestError when the refresh token and access token expire', () => {
@@ -884,36 +917,38 @@ describe('webex-core', () => {
884
917
  webex.trigger('change:config');
885
918
  const st = makeToken(webex, {
886
919
  access_token: 'ST',
887
- refresh_token: 'RT'
920
+ refresh_token: 'RT',
888
921
  });
889
922
 
890
923
  const t1 = makeToken(webex, {
891
924
  access_token: 'AT1',
892
- scope: 'scope1'
925
+ scope: 'scope1',
893
926
  });
894
927
 
895
928
  const res = {
896
929
  body: {
897
930
  error: 'invalid_request',
898
- error_description: 'The refresh token provided is expired, revoked, malformed, or invalid.',
899
- trackingID: 'test123'
900
- }
931
+ error_description:
932
+ 'The refresh token provided is expired, revoked, malformed, or invalid.',
933
+ trackingID: 'test123',
934
+ },
901
935
  };
902
936
 
903
937
  const ErrorConstructor = grantErrors.select(res.body.error);
904
938
 
905
- sinon.stub(st, 'refresh').returns(Promise.reject(new ErrorConstructor('InvalidRequestError')));
939
+ sinon
940
+ .stub(st, 'refresh')
941
+ .returns(Promise.reject(new ErrorConstructor('InvalidRequestError')));
906
942
  sinon.stub(credentials, 'unset').returns(Promise.resolve());
907
943
  const triggerSpy = sinon.spy(webex, 'trigger');
908
944
 
909
945
  credentials.set({
910
946
  supertoken: st,
911
- userTokens: [
912
- t1
913
- ]
947
+ userTokens: [t1],
914
948
  });
915
949
 
916
- return credentials.refresh()
950
+ return credentials
951
+ .refresh()
917
952
  .then(() => assert.called(st.refresh))
918
953
  .catch(() => {
919
954
  assert.called(credentials.unset);
@@ -930,16 +965,16 @@ describe('webex-core', () => {
930
965
  webex.trigger('change:config');
931
966
  const st = makeToken(webex, {
932
967
  access_token: 'ST',
933
- refresh_token: 'RT'
968
+ refresh_token: 'RT',
934
969
  });
935
970
 
936
971
  const st2 = makeToken(webex, {
937
972
  access_token: 'ST2',
938
- refresh_token: 'RT2'
973
+ refresh_token: 'RT2',
939
974
  });
940
975
 
941
976
  credentials.set({
942
- supertoken: st
977
+ supertoken: st,
943
978
  });
944
979
 
945
980
  sinon.stub(credentials, 'refresh').returns(Promise.resolve(st2));
@@ -956,16 +991,16 @@ describe('webex-core', () => {
956
991
  webex.trigger('change:config');
957
992
  const st = makeToken(webex, {
958
993
  access_token: 'ST',
959
- refresh_token: 'RT'
994
+ refresh_token: 'RT',
960
995
  });
961
996
 
962
997
  const st2 = makeToken(webex, {
963
998
  access_token: 'ST2',
964
- refresh_token: 'RT2'
999
+ refresh_token: 'RT2',
965
1000
  });
966
1001
 
967
1002
  credentials.set({
968
- supertoken: st
1003
+ supertoken: st,
969
1004
  });
970
1005
 
971
1006
  sinon.stub(credentials, 'refresh').returns(Promise.resolve(st2));