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