@webex/webex-core 3.12.0 → 3.13.0-next.10

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 (92) hide show
  1. package/.repo-context.json +653 -0
  2. package/.sdd/manifest.json +615 -0
  3. package/AGENTS.md +209 -0
  4. package/README.md +6 -3
  5. package/dist/config.js +46 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/credentials-config.js +21 -1
  8. package/dist/credentials-config.js.map +1 -1
  9. package/dist/index.js +14 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/interceptors/auth.js +10 -1
  12. package/dist/interceptors/auth.js.map +1 -1
  13. package/dist/interceptors/catalog-url.js +87 -0
  14. package/dist/interceptors/catalog-url.js.map +1 -0
  15. package/dist/interceptors/payload-transformer.js +25 -4
  16. package/dist/interceptors/payload-transformer.js.map +1 -1
  17. package/dist/lib/batcher.js +23 -7
  18. package/dist/lib/batcher.js.map +1 -1
  19. package/dist/lib/credentials/credentials.js +117 -5
  20. package/dist/lib/credentials/credentials.js.map +1 -1
  21. package/dist/lib/credentials/token.js +23 -9
  22. package/dist/lib/credentials/token.js.map +1 -1
  23. package/dist/lib/domains.js +90 -0
  24. package/dist/lib/domains.js.map +1 -0
  25. package/dist/lib/interceptors/service.js +5 -1
  26. package/dist/lib/interceptors/service.js.map +1 -1
  27. package/dist/lib/services/catalog-auth.js +114 -0
  28. package/dist/lib/services/catalog-auth.js.map +1 -0
  29. package/dist/lib/services/service-catalog.js +108 -18
  30. package/dist/lib/services/service-catalog.js.map +1 -1
  31. package/dist/lib/services/services.js +287 -40
  32. package/dist/lib/services/services.js.map +1 -1
  33. package/dist/lib/services-v2/service-catalog.js +14 -13
  34. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  35. package/dist/lib/services-v2/services-v2.js +294 -44
  36. package/dist/lib/services-v2/services-v2.js.map +1 -1
  37. package/dist/lib/static-asset-loader.js +153 -0
  38. package/dist/lib/static-asset-loader.js.map +1 -0
  39. package/dist/plugins/logger.js +1 -1
  40. package/dist/webex-core.js +11 -3
  41. package/dist/webex-core.js.map +1 -1
  42. package/docs/adr/index.md +32 -0
  43. package/docs/architecture.md +298 -0
  44. package/docs/getting-started.md +96 -0
  45. package/docs/index.md +55 -0
  46. package/docs/specs/README.md +76 -0
  47. package/package.json +13 -13
  48. package/schemas/repo-context.schema.json +796 -0
  49. package/src/config.js +50 -1
  50. package/src/credentials-config.js +22 -0
  51. package/src/docs/README.md +732 -0
  52. package/src/index.js +2 -0
  53. package/src/interceptors/auth.js +14 -1
  54. package/src/interceptors/catalog-url.js +66 -0
  55. package/src/interceptors/docs/README.md +658 -0
  56. package/src/interceptors/payload-transformer.js +23 -1
  57. package/src/lib/batcher.js +25 -10
  58. package/src/lib/credentials/credentials.js +106 -4
  59. package/src/lib/credentials/docs/README.md +847 -0
  60. package/src/lib/credentials/token.js +15 -8
  61. package/src/lib/domains.ts +94 -0
  62. package/src/lib/interceptors/service.js +11 -3
  63. package/src/lib/services/catalog-auth.js +112 -0
  64. package/src/lib/services/docs/README.md +737 -0
  65. package/src/lib/services/service-catalog.js +112 -16
  66. package/src/lib/services/services.js +274 -24
  67. package/src/lib/services-v2/docs/README.md +751 -0
  68. package/src/lib/services-v2/service-catalog.ts +16 -12
  69. package/src/lib/services-v2/services-v2.ts +282 -26
  70. package/src/lib/static-asset-loader.ts +128 -0
  71. package/src/lib/storage/docs/README.md +646 -0
  72. package/src/webex-core.js +8 -0
  73. package/test/fixtures/activation-email.ts +22 -0
  74. package/test/integration/spec/credentials/credentials.js +3 -1
  75. package/test/integration/spec/credentials/token.js +8 -0
  76. package/test/integration/spec/services/service-catalog.js +5 -0
  77. package/test/integration/spec/services/services.js +183 -112
  78. package/test/integration/spec/services-v2/services-v2.js +169 -98
  79. package/test/integration/spec/unit-browser/token.js +7 -2
  80. package/test/unit/spec/credentials/credentials.js +326 -3
  81. package/test/unit/spec/credentials/token.js +259 -6
  82. package/test/unit/spec/interceptors/auth.js +92 -1
  83. package/test/unit/spec/interceptors/catalog-url.js +224 -0
  84. package/test/unit/spec/interceptors/payload-transformer.js +119 -1
  85. package/test/unit/spec/lib/batcher.js +56 -0
  86. package/test/unit/spec/services/interceptors/service.js +35 -1
  87. package/test/unit/spec/services/service-catalog.js +368 -11
  88. package/test/unit/spec/services/services.js +783 -10
  89. package/test/unit/spec/services-v2/service-catalog.ts +134 -11
  90. package/test/unit/spec/services-v2/services-v2.ts +825 -10
  91. package/test/unit/spec/static-asset-loader.ts +224 -0
  92. package/test/unit/spec/webex-core.js +77 -1
@@ -7,7 +7,7 @@ import {assert} from '@webex/test-helper-chai';
7
7
  import sinon from 'sinon';
8
8
  import MockWebex from '@webex/test-helper-mock-webex';
9
9
  import {Credentials, Token, grantErrors} from '@webex/webex-core';
10
- import {inBrowser} from '@webex/common';
10
+ import {inBrowser, base64} from '@webex/common';
11
11
  import FakeTimers from '@sinonjs/fake-timers';
12
12
  import {skipInBrowser} from '@webex/test-helper-mocha';
13
13
  import Logger from '@webex/plugin-logger';
@@ -183,6 +183,10 @@ describe('webex-core', () => {
183
183
  webex.credentials.buildLoginUrl({state: 'state'});
184
184
  }, /if specified, `options.state` must be an object/);
185
185
 
186
+ assert.throws(() => {
187
+ webex.credentials.buildLoginUrl({state: null});
188
+ }, /if specified, `options.state` must be an object/);
189
+
186
190
  assert.doesNotThrow(() => {
187
191
  webex.credentials.buildLoginUrl({state: {}});
188
192
  }, /if specified, `options.state` must be an object/);
@@ -232,6 +236,132 @@ describe('webex-core', () => {
232
236
  });
233
237
  });
234
238
 
239
+ describe('#buildThirdPartyLoginUrl()', () => {
240
+ it('throws if both `oauth2provider` and `returnURL` are missing', () => {
241
+ const webex = new MockWebex();
242
+ const credentials = new Credentials(undefined, {parent: webex});
243
+
244
+ webex.trigger('change:config');
245
+
246
+ assert.throws(() => {
247
+ credentials.buildThirdPartyLoginUrl({});
248
+ }, /`options.oauth2provider` is required/);
249
+ });
250
+
251
+ it('throws if `oauth2provider` is missing', () => {
252
+ const webex = new MockWebex();
253
+ const credentials = new Credentials(undefined, {parent: webex});
254
+
255
+ webex.trigger('change:config');
256
+
257
+ assert.throws(() => {
258
+ credentials.buildThirdPartyLoginUrl({returnURL: 'https://web.webex.com'});
259
+ }, /`options.oauth2provider` is required/);
260
+ });
261
+
262
+ it('throws if `returnURL` is missing', () => {
263
+ const webex = new MockWebex();
264
+ const credentials = new Credentials(undefined, {parent: webex});
265
+
266
+ webex.trigger('change:config');
267
+
268
+ assert.throws(() => {
269
+ credentials.buildThirdPartyLoginUrl({oauth2provider: 'google'});
270
+ }, /`options.returnURL` is required/);
271
+ });
272
+
273
+ skipInBrowser(it)('generates the third-party login url', () => {
274
+ const webex = new MockWebex();
275
+ const credentials = new Credentials(undefined, {parent: webex});
276
+
277
+ webex.trigger('change:config');
278
+
279
+ assert.equal(
280
+ credentials.buildThirdPartyLoginUrl({
281
+ oauth2provider: 'google',
282
+ returnURL: 'https://web.webex.com',
283
+ }),
284
+ `${
285
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
286
+ }/idb/ThirdPartyLogin?oauth2provider=google&returnURL=https%3A%2F%2Fweb.webex.com`
287
+ );
288
+ });
289
+
290
+ skipInBrowser(it)('generates the url with different parameter values', () => {
291
+ const webex = new MockWebex();
292
+ const credentials = new Credentials(undefined, {parent: webex});
293
+
294
+ webex.trigger('change:config');
295
+
296
+ assert.equal(
297
+ credentials.buildThirdPartyLoginUrl({
298
+ oauth2provider: 'apple',
299
+ returnURL: 'https://example.com/callback',
300
+ }),
301
+ `${
302
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
303
+ }/idb/ThirdPartyLogin?oauth2provider=apple&returnURL=https%3A%2F%2Fexample.com%2Fcallback`
304
+ );
305
+ });
306
+
307
+ it('throws if `state` is not an object', () => {
308
+ const webex = new MockWebex();
309
+ const credentials = new Credentials(undefined, {parent: webex});
310
+
311
+ webex.trigger('change:config');
312
+
313
+ assert.throws(() => {
314
+ credentials.buildThirdPartyLoginUrl({
315
+ oauth2provider: 'google',
316
+ returnURL: 'https://web.webex.com',
317
+ state: 'not-an-object',
318
+ });
319
+ }, /`options.state` must be an object/);
320
+ });
321
+
322
+ skipInBrowser(it)('omits `state` when an empty object is provided', () => {
323
+ const webex = new MockWebex();
324
+ const credentials = new Credentials(undefined, {parent: webex});
325
+
326
+ webex.trigger('change:config');
327
+
328
+ const result = credentials.buildThirdPartyLoginUrl({
329
+ oauth2provider: 'google',
330
+ returnURL: 'https://web.webex.com',
331
+ state: {},
332
+ });
333
+
334
+ const parsed = new URL(result);
335
+
336
+ assert.isFalse(parsed.searchParams.has('state'));
337
+ });
338
+
339
+ skipInBrowser(it)('base64url-encodes a non-empty `state` and emits it as a top-level query param', () => {
340
+ const webex = new MockWebex();
341
+ const credentials = new Credentials(undefined, {parent: webex});
342
+
343
+ webex.trigger('change:config');
344
+
345
+ const result = credentials.buildThirdPartyLoginUrl({
346
+ oauth2provider: 'google',
347
+ returnURL: 'https://web.webex.com',
348
+ state: {csrf_token: 'abc', popUpSignIn: true},
349
+ });
350
+
351
+ // Literal base64url of '{"csrf_token":"abc","popUpSignIn":true}'
352
+ const expectedState = 'eyJjc3JmX3Rva2VuIjoiYWJjIiwicG9wVXBTaWduSW4iOnRydWV9';
353
+
354
+ assert.equal(
355
+ result,
356
+ `${
357
+ process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
358
+ }/idb/ThirdPartyLogin?oauth2provider=google&returnURL=${encodeURIComponent(
359
+ 'https://web.webex.com'
360
+ )}&state=${expectedState}`
361
+ );
362
+ });
363
+ });
364
+
235
365
  describe('#buildLogoutUrl()', () => {
236
366
  skipInBrowser(it)('generates the logout url', () => {
237
367
  const webex = new MockWebex();
@@ -368,12 +498,96 @@ describe('webex-core', () => {
368
498
  });
369
499
 
370
500
  it('should throw when provided an invalid token', () =>
371
- expect(() => credentials.extractOrgIdFromUserToken()).toThrow('the provided token is not a valid format, token has 1 sections'));
501
+ expect(() => credentials.extractOrgIdFromUserToken()).toThrow(
502
+ 'the provided token is not a valid format, token has 1 sections'
503
+ ));
372
504
 
373
505
  it('should throw when no token is provided', () =>
374
506
  expect(() => credentials.extractOrgIdFromUserToken()).toThrow());
375
507
  });
376
508
 
509
+ describe('#extractUserIdFromToken()', () => {
510
+ let credentials;
511
+ let webex;
512
+
513
+ beforeEach(() => {
514
+ webex = new MockWebex();
515
+ credentials = new Credentials(undefined, {parent: webex});
516
+ });
517
+
518
+ const buildToken = (payload) =>
519
+ `header.${base64.toBase64Url(JSON.stringify(payload))}.signature`;
520
+
521
+ it('should return the cis_uuid from the provided token', () => {
522
+ const token = buildToken({cis_uuid: 'my-user-id'});
523
+
524
+ assert.equal(credentials.extractUserIdFromToken(token), 'my-user-id');
525
+ });
526
+
527
+ it('should throw if the token does not contain a cis_uuid', () => {
528
+ const token = buildToken({foo: 'bar'});
529
+
530
+ expect(() => credentials.extractUserIdFromToken(token)).toThrow(
531
+ 'the provided token does not contain a user ID'
532
+ );
533
+ });
534
+
535
+ it('should throw when provided an unparseable token', () =>
536
+ expect(() => credentials.extractUserIdFromToken('not-a-valid-token')).toThrow());
537
+
538
+ it('should throw when no token is provided', () =>
539
+ expect(() => credentials.extractUserIdFromToken()).toThrow());
540
+ });
541
+
542
+ describe('#getUserId()', () => {
543
+ let credentials;
544
+ let webex;
545
+
546
+ const buildToken = (userId) =>
547
+ `header.${base64.toBase64Url(JSON.stringify({cis_uuid: userId}))}.signature`;
548
+
549
+ beforeEach(() => {
550
+ webex = new MockWebex();
551
+ credentials = new Credentials(undefined, {parent: webex});
552
+ });
553
+
554
+ it('should return the userId from the supertoken', () => {
555
+ credentials.supertoken = makeToken(webex, {
556
+ access_token: buildToken('supertoken-user-id'),
557
+ });
558
+
559
+ assert.equal(credentials.getUserId(), 'supertoken-user-id');
560
+ });
561
+
562
+ it('should fall back to a user token when the supertoken has no userId', () => {
563
+ credentials.supertoken = makeToken(webex, {access_token: 'AT'});
564
+ credentials.userTokens.add(
565
+ makeToken(webex, {access_token: buildToken('user-token-user-id'), scope: 'scope1'})
566
+ );
567
+
568
+ assert.equal(credentials.getUserId(), 'user-token-user-id');
569
+ });
570
+
571
+ it('should prefer the supertoken over the user tokens', () => {
572
+ credentials.supertoken = makeToken(webex, {
573
+ access_token: buildToken('supertoken-user-id'),
574
+ });
575
+ credentials.userTokens.add(
576
+ makeToken(webex, {access_token: buildToken('user-token-user-id'), scope: 'scope1'})
577
+ );
578
+
579
+ assert.equal(credentials.getUserId(), 'supertoken-user-id');
580
+ });
581
+
582
+ it('should throw if no available token contains a userId', () => {
583
+ credentials.supertoken = makeToken(webex, {access_token: 'AT'});
584
+
585
+ expect(() => credentials.getUserId()).toThrow(
586
+ 'could not extract the user ID from any available token'
587
+ );
588
+ });
589
+ });
590
+
377
591
  describe('#initialize()', () => {
378
592
  it('turns a portal auth string into a configuration object', () => {
379
593
  const webex = new MockWebex();
@@ -498,6 +712,37 @@ describe('webex-core', () => {
498
712
  });
499
713
  });
500
714
 
715
+ describe('#getClientToken()', () => {
716
+ it('requests a client token without bypassing catalog URL validation', async () => {
717
+ const webex = new MockWebex();
718
+ const credentials = new Credentials(undefined, {parent: webex});
719
+ const uri = 'https://idbroker.webex.com/idb/oauth2/v1/access_token';
720
+ const scope = 'spark:all';
721
+
722
+ webex.request.resolves({body: {access_token: 'AT', token_type: 'Bearer'}});
723
+
724
+ const token = await credentials.getClientToken({uri, scope});
725
+
726
+ assert.calledOnceWithExactly(webex.request, {
727
+ method: 'POST',
728
+ uri,
729
+ form: {
730
+ grant_type: 'client_credentials',
731
+ scope,
732
+ self_contained_token: true,
733
+ },
734
+ auth: {
735
+ user: 'fake',
736
+ pass: 'fake',
737
+ sendImmediately: true,
738
+ },
739
+ shouldRefreshAccessToken: false,
740
+ });
741
+ assert.instanceOf(token, Token);
742
+ assert.equal(token.access_token, 'AT');
743
+ });
744
+ });
745
+
501
746
  describe('#getUserToken()', () => {
502
747
  it('resolves with the supertoken if the supertoken matches the requested scopes', () => {
503
748
  const webex = new MockWebex();
@@ -799,7 +1044,6 @@ describe('webex-core', () => {
799
1044
  .then(() => assert.isRejected(webex.boundedStorage.get('Credentials', '@'), /NotFound/));
800
1045
  });
801
1046
 
802
-
803
1047
  // it('does not induce any token refreshes');
804
1048
 
805
1049
  it('prevents #getUserToken() from being invoked', () => {
@@ -834,6 +1078,85 @@ describe('webex-core', () => {
834
1078
  });
835
1079
 
836
1080
  describe('#refresh()', () => {
1081
+ [
1082
+ {
1083
+ description: 'requests configured scopes missing from the supertoken',
1084
+ canUpgradeScope: true,
1085
+ configuredScope: 'scope1 scope2',
1086
+ tokenScope: 'scope1',
1087
+ expectedOptions: {scope: undefined, upgradeScope: 'scope1 scope2'},
1088
+ },
1089
+ {
1090
+ description: 'narrows a broader supertoken to the configured scope',
1091
+ canUpgradeScope: true,
1092
+ configuredScope: 'scope1',
1093
+ tokenScope: 'scope1 scope2',
1094
+ expectedOptions: {scope: 'scope1', upgradeScope: undefined},
1095
+ },
1096
+ {
1097
+ description:
1098
+ 'sends scope when the configured and granted scopes match in a different order',
1099
+ canUpgradeScope: true,
1100
+ configuredScope: 'scope2 scope1',
1101
+ tokenScope: 'scope1 scope2',
1102
+ expectedOptions: {scope: 'scope2 scope1', upgradeScope: undefined},
1103
+ },
1104
+ {
1105
+ description: 'omits scope and upgrade scope when scope upgrading is disabled',
1106
+ canUpgradeScope: false,
1107
+ configuredScope: 'scope1 scope2',
1108
+ tokenScope: 'scope1',
1109
+ expectedOptions: {scope: undefined, upgradeScope: undefined},
1110
+ },
1111
+ {
1112
+ description: 'does not narrow scope when scope upgrading is disabled',
1113
+ canUpgradeScope: false,
1114
+ configuredScope: 'scope1',
1115
+ tokenScope: 'scope1 scope2',
1116
+ expectedOptions: {scope: undefined, upgradeScope: undefined},
1117
+ },
1118
+ {
1119
+ description: 'omits scope and upgrade scope when no scope is configured',
1120
+ canUpgradeScope: true,
1121
+ configuredScope: undefined,
1122
+ tokenScope: 'scope1 scope2',
1123
+ expectedOptions: {scope: undefined, upgradeScope: undefined},
1124
+ },
1125
+ ].forEach(({description, canUpgradeScope, configuredScope, tokenScope, expectedOptions}) => {
1126
+ it(description, () => {
1127
+ const webex = new MockWebex({
1128
+ children: {
1129
+ metrics: Metrics,
1130
+ },
1131
+ });
1132
+ const credentials = new Credentials(undefined, {parent: webex});
1133
+
1134
+ webex.trigger('change:config');
1135
+ credentials.config.canUpgradeScope = canUpgradeScope;
1136
+ credentials.config.scope = configuredScope;
1137
+
1138
+ const st = makeToken(webex, {
1139
+ access_token: 'ST',
1140
+ refresh_token: 'RT',
1141
+ scope: tokenScope,
1142
+ });
1143
+ const st2 = makeToken(webex, {
1144
+ access_token: 'ST2',
1145
+ refresh_token: 'RT2',
1146
+ scope: configuredScope || tokenScope,
1147
+ });
1148
+
1149
+ sinon.stub(st, 'refresh').resolves(st2);
1150
+ sinon.stub(credentials, 'scheduleRefresh');
1151
+ sinon.stub(webex.internal.metrics, 'submitClientMetrics');
1152
+ credentials.supertoken = st;
1153
+
1154
+ return credentials.refresh().then(() => {
1155
+ assert.calledOnceWithExactly(st.refresh, expectedOptions);
1156
+ });
1157
+ });
1158
+ });
1159
+
837
1160
  it('refreshes and downscopes the supertoken, and revokes previous tokens', () => {
838
1161
  const webex = new MockWebex({
839
1162
  children: {