@webex/webex-core 3.8.1 → 3.9.0

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 (85) hide show
  1. package/README.md +87 -27
  2. package/dist/index.js +9 -33
  3. package/dist/index.js.map +1 -1
  4. package/dist/lib/batcher.js +1 -1
  5. package/dist/lib/constants.js +10 -1
  6. package/dist/lib/constants.js.map +1 -1
  7. package/dist/lib/credentials/credentials.js +1 -1
  8. package/dist/lib/credentials/token.js +1 -1
  9. package/dist/lib/{services-v2/interceptors → interceptors}/server-error.js +1 -1
  10. package/dist/lib/interceptors/server-error.js.map +1 -0
  11. package/dist/lib/services/index.js +2 -29
  12. package/dist/lib/services/index.js.map +1 -1
  13. package/dist/lib/services/service-host.js +1 -1
  14. package/dist/lib/services/service-host.js.map +1 -1
  15. package/dist/lib/services/service-registry.js +1 -1
  16. package/dist/lib/services/service-registry.js.map +1 -1
  17. package/dist/lib/services/service-state.js +1 -1
  18. package/dist/lib/services/service-state.js.map +1 -1
  19. package/dist/lib/services/services.js +3 -3
  20. package/dist/lib/services/services.js.map +1 -1
  21. package/dist/lib/services-v2/index.js +0 -29
  22. package/dist/lib/services-v2/index.js.map +1 -1
  23. package/dist/lib/services-v2/metrics.js.map +1 -1
  24. package/dist/lib/services-v2/service-catalog.js +11 -10
  25. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  26. package/dist/lib/services-v2/services-v2.js +56 -67
  27. package/dist/lib/services-v2/services-v2.js.map +1 -1
  28. package/dist/lib/services-v2/types.js.map +1 -1
  29. package/dist/plugins/logger.js +1 -1
  30. package/dist/webex-core.js +3 -3
  31. package/dist/webex-core.js.map +1 -1
  32. package/package.json +13 -13
  33. package/src/index.js +5 -14
  34. package/src/lib/constants.js +29 -1
  35. package/src/lib/{services/interceptors → interceptors}/server-error.js +1 -1
  36. package/src/lib/services/index.js +2 -7
  37. package/src/lib/services/service-host.js +1 -1
  38. package/src/lib/services/service-registry.js +1 -1
  39. package/src/lib/services/service-state.js +1 -1
  40. package/src/lib/services/services.js +2 -2
  41. package/src/lib/services-v2/index.ts +0 -16
  42. package/src/lib/services-v2/service-catalog.ts +20 -19
  43. package/src/lib/services-v2/{services-v2.js → services-v2.ts} +116 -94
  44. package/src/lib/services-v2/types.ts +62 -2
  45. package/src/webex-core.js +1 -1
  46. package/test/fixtures/host-catalog-v2.ts +30 -122
  47. package/test/integration/spec/services/services.js +11 -0
  48. package/test/integration/spec/services-v2/service-catalog.js +664 -0
  49. package/test/integration/spec/services-v2/services-v2.js +1061 -0
  50. package/test/unit/spec/services-v2/service-detail.ts +1 -1
  51. package/test/unit/spec/services-v2/services-v2.ts +390 -436
  52. package/dist/lib/services/constants.js +0 -17
  53. package/dist/lib/services/constants.js.map +0 -1
  54. package/dist/lib/services/interceptors/hostmap.js +0 -64
  55. package/dist/lib/services/interceptors/hostmap.js.map +0 -1
  56. package/dist/lib/services/interceptors/server-error.js +0 -77
  57. package/dist/lib/services/interceptors/server-error.js.map +0 -1
  58. package/dist/lib/services/interceptors/service.js +0 -137
  59. package/dist/lib/services/interceptors/service.js.map +0 -1
  60. package/dist/lib/services-v2/constants.js +0 -17
  61. package/dist/lib/services-v2/constants.js.map +0 -1
  62. package/dist/lib/services-v2/interceptors/server-error.js.map +0 -1
  63. package/dist/lib/services-v2/service-host.js +0 -300
  64. package/dist/lib/services-v2/service-host.js.map +0 -1
  65. package/dist/lib/services-v2/service-registry.js +0 -534
  66. package/dist/lib/services-v2/service-registry.js.map +0 -1
  67. package/dist/lib/services-v2/service-state.js +0 -97
  68. package/dist/lib/services-v2/service-state.js.map +0 -1
  69. package/dist/lib/services-v2/service-url.js +0 -119
  70. package/dist/lib/services-v2/service-url.js.map +0 -1
  71. package/src/lib/services/constants.js +0 -21
  72. package/src/lib/services/interceptors/hostmap.js +0 -36
  73. package/src/lib/services/interceptors/service.js +0 -101
  74. package/src/lib/services-v2/constants.ts +0 -21
  75. package/src/lib/services-v2/interceptors/server-error.js +0 -48
  76. /package/dist/lib/{services-v2/interceptors → interceptors}/hostmap.js +0 -0
  77. /package/dist/lib/{services-v2/interceptors → interceptors}/hostmap.js.map +0 -0
  78. /package/dist/lib/{services-v2/interceptors → interceptors}/service.js +0 -0
  79. /package/dist/lib/{services-v2/interceptors → interceptors}/service.js.map +0 -0
  80. /package/dist/lib/{services/metrics.js → metrics.js} +0 -0
  81. /package/dist/lib/{services/metrics.js.map → metrics.js.map} +0 -0
  82. /package/src/lib/{services-v2/interceptors → interceptors}/hostmap.js +0 -0
  83. /package/src/lib/{services-v2/interceptors → interceptors}/service.js +0 -0
  84. /package/src/lib/{services-v2/metrics.js → metrics.js} +0 -0
  85. /package/src/lib/{services/metrics.js → services-v2/metrics.ts} +0 -0
@@ -3,10 +3,18 @@ import sha256 from 'crypto-js/sha256';
3
3
  import {union, unionBy} from 'lodash';
4
4
  import WebexPlugin from '../webex-plugin';
5
5
 
6
- import METRICS from './metrics';
6
+ import METRICS from '../metrics';
7
7
  import ServiceCatalog from './service-catalog';
8
8
  import fedRampServices from './service-fed-ramp';
9
- import {COMMERCIAL_ALLOWED_DOMAINS} from './constants';
9
+ import {COMMERCIAL_ALLOWED_DOMAINS} from '../constants';
10
+ import {
11
+ ActiveServices,
12
+ IServiceCatalog,
13
+ QueryOptions,
14
+ Service,
15
+ ServiceHostmap,
16
+ ServiceGroup,
17
+ } from './types';
10
18
 
11
19
  const trailingSlashes = /(?:^\/)|(?:\/$)/;
12
20
 
@@ -41,9 +49,9 @@ const Services = WebexPlugin.extend({
41
49
  * @private
42
50
  * Get the current catalog based on the assocaited
43
51
  * webex instance.
44
- * @returns {ServiceCatalog}
52
+ * @returns {IServiceCatalog}
45
53
  */
46
- _getCatalog() {
54
+ _getCatalog(): IServiceCatalog {
47
55
  return this._catalogs.get(this.webex);
48
56
  },
49
57
 
@@ -51,14 +59,23 @@ const Services = WebexPlugin.extend({
51
59
  * Get a service url from the current services list by name
52
60
  * from the associated instance catalog.
53
61
  * @param {string} name
54
- * @param {boolean} [priorityHost]
55
- * @param {string} [serviceGroup]
62
+ * @param {ServiceGroup} [serviceGroup]
56
63
  * @returns {string|undefined}
57
64
  */
58
- get(name, priorityHost, serviceGroup) {
65
+ get(name: string, serviceGroup?: ServiceGroup): string | undefined {
59
66
  const catalog = this._getCatalog();
60
67
 
61
- return catalog.get(name, priorityHost, serviceGroup);
68
+ const clusterId = this._activeServices[name];
69
+
70
+ const urlById = catalog.get(clusterId, serviceGroup);
71
+ const urlByName = catalog.get(name, serviceGroup);
72
+
73
+ // if both are undefined, then we cannot find the service
74
+ if (!urlById && !urlByName) {
75
+ return undefined;
76
+ }
77
+
78
+ return urlById || urlByName;
62
79
  },
63
80
 
64
81
  /**
@@ -66,59 +83,42 @@ const Services = WebexPlugin.extend({
66
83
  *
67
84
  * @returns {boolean} - True if a allowed domains list exists.
68
85
  */
69
- hasAllowedDomains() {
86
+ hasAllowedDomains(): boolean {
70
87
  const catalog = this._getCatalog();
71
88
 
72
89
  return catalog.getAllowedDomains().length > 0;
73
90
  },
74
91
 
75
- /**
76
- * Generate a service catalog as an object from
77
- * the associated instance catalog.
78
- * @param {boolean} [priorityHost] - use highest priority host if set to `true`
79
- * @param {string} [serviceGroup]
80
- * @returns {Record<string, string>}
81
- */
82
- list(priorityHost, serviceGroup) {
83
- const catalog = this._getCatalog();
84
-
85
- return catalog.list(priorityHost, serviceGroup);
86
- },
87
-
88
92
  /**
89
93
  * Mark a priority host service url as failed.
90
- * This will mark the host associated with the
91
- * `ServiceUrl` to be removed from the its
92
- * respective host array, and then return the next
93
- * viable host from the `ServiceUrls` host array,
94
- * or the `ServiceUrls` default url if no other priority
95
- * hosts are available, or if `noPriorityHosts` is set to
96
- * `true`.
94
+ * This will mark the service url associated with the
95
+ * `ServiceDetail` to be removed from the its
96
+ * respective service url array, and then return the next
97
+ * viable service url from the `ServiceDetail` service url array.
97
98
  * @param {string} url
98
- * @param {boolean} noPriorityHosts
99
99
  * @returns {string}
100
100
  */
101
- markFailedUrl(url, noPriorityHosts) {
101
+ markFailedUrl(url: string): string | undefined {
102
102
  const catalog = this._getCatalog();
103
103
 
104
- return catalog.markFailedUrl(url, noPriorityHosts);
104
+ return catalog.markFailedServiceUrl(url);
105
105
  },
106
106
 
107
107
  /**
108
108
  * saves all the services from the pre and post catalog service
109
- * @param {Object} activeServices
109
+ * @param {ActiveServices} activeServices
110
110
  * @returns {void}
111
111
  */
112
- _updateActiveServices(activeServices) {
112
+ _updateActiveServices(activeServices: ActiveServices): void {
113
113
  this._activeServices = {...this._activeServices, ...activeServices};
114
114
  },
115
115
 
116
116
  /**
117
117
  * saves the hostCatalog object
118
- * @param {Object} services
118
+ * @param {Array<Service>} services
119
119
  * @returns {void}
120
120
  */
121
- _updateServices(services) {
121
+ _updateServices(services: Array<Service>): void {
122
122
  this._services = unionBy(services, this._services, 'id');
123
123
  },
124
124
 
@@ -135,7 +135,14 @@ const Services = WebexPlugin.extend({
135
135
  * @param {string} [param.token] - used for signin catalog
136
136
  * @returns {Promise<object>}
137
137
  */
138
- updateServices({from, query, token, forceRefresh} = {}) {
138
+ updateServices(
139
+ {from, query, token, forceRefresh} = {} as {
140
+ from: string;
141
+ query: QueryOptions;
142
+ token: string;
143
+ forceRefresh: boolean;
144
+ }
145
+ ): Promise<object> {
139
146
  const catalog = this._getCatalog();
140
147
  let formattedQuery;
141
148
  let serviceGroup;
@@ -188,7 +195,7 @@ const Services = WebexPlugin.extend({
188
195
  query: formattedQuery,
189
196
  forceRefresh,
190
197
  })
191
- .then((serviceHostMap) => {
198
+ .then((serviceHostMap: ServiceHostmap) => {
192
199
  catalog.updateServiceGroups(serviceGroup, serviceHostMap);
193
200
  this.updateCredentialsConfig();
194
201
  catalog.status[serviceGroup].collecting = false;
@@ -283,7 +290,7 @@ const Services = WebexPlugin.extend({
283
290
  // Retrieve the service url from the updated catalog. This is required
284
291
  // since `WebexCore` is usually not fully initialized at the time this
285
292
  // request completes.
286
- const idbrokerService = this.get('idbroker', true);
293
+ const idbrokerService = this.get('idbroker');
287
294
 
288
295
  // Collect the client auth token.
289
296
  return this.webex.credentials.getClientToken({
@@ -446,11 +453,11 @@ const Services = WebexPlugin.extend({
446
453
 
447
454
  /**
448
455
  * Updates a given service group i.e. preauth, signin, postauth with a new hostmap.
449
- * @param {string} serviceGroup - preauth, signin, postauth
450
- * @param {object} hostMap - The new hostmap to update the service group with.
456
+ * @param {ServiceGroup} serviceGroup - preauth, signin, postauth
457
+ * @param {ServiceHostmap} hostMap - The new hostmap to update the service group with.
451
458
  * @returns {Promise<void>}
452
459
  */
453
- updateCatalog(serviceGroup, hostMap) {
460
+ updateCatalog(serviceGroup: ServiceGroup, hostMap: ServiceHostmap): Promise<void> {
454
461
  const catalog = this._getCatalog();
455
462
 
456
463
  const serviceHostMap = this._formatReceivedHostmap(hostMap);
@@ -467,7 +474,7 @@ const Services = WebexPlugin.extend({
467
474
  * @param {boolean} forceRefresh - Boolean to bypass u2c cache control header
468
475
  * @returns {Promise<void>}
469
476
  */
470
- collectPreauthCatalog(query, forceRefresh = false) {
477
+ collectPreauthCatalog(query: QueryOptions, forceRefresh = false) {
471
478
  if (!query) {
472
479
  return this.updateServices({
473
480
  from: 'limited',
@@ -486,7 +493,9 @@ const Services = WebexPlugin.extend({
486
493
  * @param {string} param.token - must be a client token
487
494
  * @returns {Promise<void>}
488
495
  */
489
- collectSigninCatalog({email, token, forceRefresh} = {}) {
496
+ collectSigninCatalog(
497
+ {email, token, forceRefresh} = {} as {email: string; token: string; forceRefresh: boolean}
498
+ ): Promise<void> {
490
499
  if (!email) {
491
500
  return Promise.reject(new Error('`email` is required'));
492
501
  }
@@ -507,25 +516,26 @@ const Services = WebexPlugin.extend({
507
516
  * urls.
508
517
  * @returns {void}
509
518
  */
510
- updateCredentialsConfig() {
511
- const {idbroker, identity} = this.list(true);
519
+ updateCredentialsConfig(): void {
520
+ const idbrokerUrl = this.get('idbroker');
521
+ const identityUrl = this.get('identity');
512
522
 
513
- if (idbroker && identity) {
523
+ if (idbrokerUrl && identityUrl) {
514
524
  const {authorizationString, authorizeUrl} = this.webex.config.credentials;
515
525
 
516
526
  // This must be set outside of the setConfig method used to assign the
517
527
  // idbroker and identity url values.
518
528
  this.webex.config.credentials.authorizeUrl = authorizationString
519
529
  ? authorizeUrl
520
- : `${idbroker.replace(trailingSlashes, '')}/idb/oauth2/v1/authorize`;
530
+ : `${idbrokerUrl.replace(trailingSlashes, '')}/idb/oauth2/v1/authorize`;
521
531
 
522
532
  this.webex.setConfig({
523
533
  credentials: {
524
534
  idbroker: {
525
- url: idbroker.replace(trailingSlashes, ''), // remove trailing slash
535
+ url: idbrokerUrl.replace(trailingSlashes, ''), // remove trailing slash
526
536
  },
527
537
  identity: {
528
- url: identity.replace(trailingSlashes, ''), // remove trailing slash
538
+ url: identityUrl.replace(trailingSlashes, ''), // remove trailing slash
529
539
  },
530
540
  },
531
541
  });
@@ -535,11 +545,11 @@ const Services = WebexPlugin.extend({
535
545
  /**
536
546
  * Wait until the service catalog is available,
537
547
  * or reject afte ra timeout of 60 seconds.
538
- * @param {string} serviceGroup
548
+ * @param {ServiceGroup} serviceGroup
539
549
  * @param {number} [timeout] - in seconds
540
550
  * @returns {Promise<void>}
541
551
  */
542
- waitForCatalog(serviceGroup, timeout) {
552
+ waitForCatalog(serviceGroup: ServiceGroup, timeout: number): Promise<void> {
543
553
  const catalog = this._getCatalog();
544
554
  const {supertoken} = this.webex.credentials;
545
555
 
@@ -576,7 +586,15 @@ const Services = WebexPlugin.extend({
576
586
  * @param {WaitForServicePTO} - The parameter transfer object.
577
587
  * @returns {Promise<string>} - Resolves to the priority host of a service.
578
588
  */
579
- waitForService({name, timeout = 5, url}) {
589
+ waitForService({
590
+ name,
591
+ timeout = 5,
592
+ url,
593
+ }: {
594
+ name: string;
595
+ timeout: number;
596
+ url: string;
597
+ }): Promise<string> {
580
598
  const {services} = this.webex.config;
581
599
 
582
600
  // Save memory by grabbing the catalog after there isn't a priortyURL
@@ -587,10 +605,12 @@ const Services = WebexPlugin.extend({
587
605
  );
588
606
 
589
607
  if (fetchFromServiceUrl) {
590
- return Promise.resolve(this._activeServices[name]);
608
+ const clusterId = this._activeServices[name];
609
+
610
+ return Promise.resolve(this.get(clusterId));
591
611
  }
592
612
 
593
- const priorityUrl = this.get(name, true);
613
+ const priorityUrl = this.get(name);
594
614
  const priorityUrlObj = this.getServiceFromUrl(url);
595
615
 
596
616
  if (priorityUrl || priorityUrlObj) {
@@ -617,7 +637,7 @@ const Services = WebexPlugin.extend({
617
637
  catalog
618
638
  .waitForCatalog(catalogGroup, timeout)
619
639
  .then(() => {
620
- const scopedPriorityUrl = this.get(name, true);
640
+ const scopedPriorityUrl = this.get(name);
621
641
  const scopedPrioriryUrlObj = this.getServiceFromUrl(url);
622
642
 
623
643
  if (scopedPriorityUrl || scopedPrioriryUrlObj) {
@@ -641,25 +661,12 @@ const Services = WebexPlugin.extend({
641
661
  * @param {string} uri
642
662
  * @returns {string} uri with the host replaced
643
663
  */
644
- replaceHostFromHostmap(uri) {
645
- const url = new URL(uri);
646
- const hostCatalog = this._services;
647
-
648
- if (!hostCatalog) {
664
+ replaceHostFromHostmap(uri: string): string {
665
+ try {
666
+ return this.convertUrlToPriorityHostUrl(uri);
667
+ } catch {
649
668
  return uri;
650
669
  }
651
-
652
- const host = hostCatalog[url.host];
653
-
654
- if (host && host[0]) {
655
- const newHost = host[0].host;
656
-
657
- url.host = newHost;
658
-
659
- return url.toString();
660
- }
661
-
662
- return uri;
663
670
  },
664
671
 
665
672
  /**
@@ -687,9 +694,9 @@ const Services = WebexPlugin.extend({
687
694
  /**
688
695
  * @private
689
696
  * Organize a received hostmap from a service
690
- * @param {object} serviceHostmap
697
+ * @param {ServiceHostmap} serviceHostmap
691
698
  * catalog endpoint.
692
- * @returns {object}
699
+ * @returns {Array<Service>}
693
700
  */
694
701
  _formatReceivedHostmap({services, activeServices}) {
695
702
  const formattedHostmap = services.map((service) => this._formatHostMapEntry(service));
@@ -702,9 +709,9 @@ const Services = WebexPlugin.extend({
702
709
  /**
703
710
  * Get the clusterId associated with a URL string.
704
711
  * @param {string} url
705
- * @returns {string} - Cluster ID of url provided
712
+ * @returns {string | undefined} - Cluster ID of url provided
706
713
  */
707
- getClusterId(url) {
714
+ getClusterId(url: string): string | undefined {
708
715
  const catalog = this._getCatalog();
709
716
 
710
717
  return catalog.findClusterId(url);
@@ -715,13 +722,15 @@ const Services = WebexPlugin.extend({
715
722
  * return an object containing both the name and url of a found service.
716
723
  * @param {object} params
717
724
  * @param {string} params.clusterId - clusterId of found service
718
- * @param {boolean} [params.priorityHost] - returns priority host url if true
719
- * @param {string} [params.serviceGroup] - specify service group
725
+ * @param {ServiceGroup} [params.serviceGroup] - specify service group
720
726
  * @returns {object} service
721
727
  * @returns {string} service.name
722
728
  * @returns {string} service.url
723
729
  */
724
- getServiceFromClusterId(params) {
730
+ getServiceFromClusterId(params: {
731
+ clusterId: string;
732
+ serviceGroup?: ServiceGroup;
733
+ }): {name: string; url: string} | undefined {
725
734
  const catalog = this._getCatalog();
726
735
 
727
736
  return catalog.findServiceFromClusterId(params);
@@ -733,7 +742,7 @@ const Services = WebexPlugin.extend({
733
742
  * If empty, just return the base URL.
734
743
  * @returns {String} url of the service
735
744
  */
736
- getServiceUrlFromClusterId({cluster = 'us'} = {}) {
745
+ getServiceUrlFromClusterId({cluster = 'us'}: {cluster?: string} = {}): string {
737
746
  let clusterId = cluster === 'us' ? DEFAULT_CLUSTER_IDENTIFIER : cluster;
738
747
 
739
748
  // Determine if cluster has service name (non-US clusters from hydra do not)
@@ -758,20 +767,25 @@ const Services = WebexPlugin.extend({
758
767
  * @param {string} url - The url to be validated.
759
768
  * @returns {object} - Service object.
760
769
  * @returns {object.name} - The name of the service found.
761
- * @returns {object.priorityUrl} - The priority url of the found service.
770
+ * @returns {object.priorityUrl} - The default url of the found service.
762
771
  * @returns {object.defaultUrl} - The default url of the found service.
763
772
  */
764
- getServiceFromUrl(url = '') {
765
- const service = this._getCatalog().findServiceUrlFromUrl(url);
773
+ getServiceFromUrl(url = ''): {name: string; priorityUrl: string; defaultUrl: string} | undefined {
774
+ const service = this._getCatalog().findServiceDetailFromUrl(url);
766
775
 
767
776
  if (!service) {
768
777
  return undefined;
769
778
  }
770
779
 
780
+ const priorityUrl = service.get();
781
+ const defaultUrl = new URL(
782
+ service.serviceUrls.find((serviceUrl) => url.startsWith(serviceUrl.baseUrl)).baseUrl
783
+ ).href;
784
+
771
785
  return {
772
- name: service.name,
773
- priorityUrl: service.get(true),
774
- defaultUrl: service.get(),
786
+ name: service.serviceName,
787
+ priorityUrl,
788
+ defaultUrl,
775
789
  };
776
790
  },
777
791
 
@@ -781,7 +795,7 @@ const Services = WebexPlugin.extend({
781
795
  * @param {string} url - The url to match allowed domains against.
782
796
  * @returns {boolean} - True if the url provided is allowed.
783
797
  */
784
- isAllowedDomainUrl(url) {
798
+ isAllowedDomainUrl(url: string): boolean {
785
799
  const catalog = this._getCatalog();
786
800
 
787
801
  return !!catalog.findAllowedDomain(url);
@@ -795,7 +809,7 @@ const Services = WebexPlugin.extend({
795
809
  * @returns {string} a service url that contains the top priority host.
796
810
  * @throws if url isn't a service url
797
811
  */
798
- convertUrlToPriorityHostUrl(url = '') {
812
+ convertUrlToPriorityHostUrl(url = '' as string): string {
799
813
  const data = this.getServiceFromUrl(url);
800
814
 
801
815
  if (!data) {
@@ -818,10 +832,17 @@ const Services = WebexPlugin.extend({
818
832
  * @param {string} [param.token] - used for signin catalog
819
833
  * @returns {Promise<object>}
820
834
  */
821
- _fetchNewServiceHostmap({from, query, token, forceRefresh} = {}) {
835
+ _fetchNewServiceHostmap(
836
+ {from, query, token, forceRefresh} = {} as {
837
+ from: string;
838
+ query: QueryOptions;
839
+ token: string;
840
+ forceRefresh: boolean;
841
+ }
842
+ ): Promise<object> {
822
843
  const service = 'u2c';
823
844
  const resource = from ? `/${from}/catalog` : '/catalog';
824
- const qs = {...(query || {}), format: 'hostmap'};
845
+ const qs = {...(query || {}), format: 'U2CV2'};
825
846
 
826
847
  if (forceRefresh) {
827
848
  qs.timestamp = new Date().getTime();
@@ -832,6 +853,7 @@ const Services = WebexPlugin.extend({
832
853
  service,
833
854
  resource,
834
855
  qs,
856
+ headers: {},
835
857
  };
836
858
 
837
859
  if (token) {
@@ -848,7 +870,7 @@ const Services = WebexPlugin.extend({
848
870
  *
849
871
  * @returns {void}
850
872
  */
851
- initConfig() {
873
+ initConfig(): void {
852
874
  // Get the catalog and destructure the services config.
853
875
  const catalog = this._getCatalog();
854
876
  const {services, fedramp} = this.webex.config;
@@ -908,7 +930,7 @@ const Services = WebexPlugin.extend({
908
930
  *
909
931
  * @returns {Promise<void, Error>} - Errors if the token is unavailable.
910
932
  */
911
- initServiceCatalogs() {
933
+ initServiceCatalogs(): Promise<void> {
912
934
  this.logger.info('services: initializing initial service catalogs');
913
935
 
914
936
  // Destructure the credentials plugin.
@@ -945,7 +967,7 @@ const Services = WebexPlugin.extend({
945
967
  * @memberof Services
946
968
  * @returns {Services}
947
969
  */
948
- initialize() {
970
+ initialize(): typeof Services {
949
971
  const catalog = new ServiceCatalog();
950
972
  this._catalogs.set(this.webex, catalog);
951
973
 
@@ -1,3 +1,7 @@
1
+ type ServiceName = string;
2
+ type ClusterId = string;
3
+ export type ServiceGroup = 'discovery' | 'override' | 'preauth' | 'postauth' | 'signin';
4
+
1
5
  export type ServiceUrl = {
2
6
  baseUrl: string;
3
7
  host: string;
@@ -5,9 +9,65 @@ export type ServiceUrl = {
5
9
  failed?: boolean;
6
10
  };
7
11
 
12
+ export type ActiveServices = Record<ServiceName, ClusterId>;
13
+ export type Service = {
14
+ id: ClusterId;
15
+ serviceName: ServiceName;
16
+ serviceUrls: Array<ServiceUrl>;
17
+ };
18
+ export type QueryOptions = {
19
+ email?: string;
20
+ orgId?: string;
21
+ userId?: string;
22
+ timestamp?: number;
23
+ };
24
+
25
+ export interface ServiceHostmap {
26
+ activeServices: ActiveServices;
27
+ services: Array<Service>;
28
+ timeStamp: string;
29
+ orgId: string;
30
+ format: string;
31
+ }
32
+
8
33
  export interface IServiceDetail {
9
- id: string;
10
- serviceName: string;
34
+ id: ClusterId;
35
+ serviceName: ServiceName;
11
36
  serviceUrls: Array<ServiceUrl>;
12
37
  failHost(url: string): boolean;
38
+ get(): string;
39
+ }
40
+
41
+ export interface IServiceCatalog {
42
+ serviceGroups: {
43
+ discovery: Array<IServiceDetail>;
44
+ override: Array<IServiceDetail>;
45
+ preauth: Array<IServiceDetail>;
46
+ postauth: Array<IServiceDetail>;
47
+ signin: Array<IServiceDetail>;
48
+ };
49
+ status: {
50
+ discovery: {ready: boolean; collecting: boolean};
51
+ override: {ready: boolean; collecting: boolean};
52
+ preauth: {ready: boolean; collecting: boolean};
53
+ postauth: {ready: boolean; collecting: boolean};
54
+ signin: {ready: boolean; collecting: boolean};
55
+ };
56
+ isReady: boolean;
57
+ allowedDomains: string[];
58
+ clean(): void;
59
+ findClusterId(url: string): string | undefined;
60
+ findServiceFromClusterId(params: {
61
+ clusterId: ClusterId;
62
+ serviceGroup?: ServiceGroup;
63
+ }): {name: string; url: string} | undefined;
64
+ findServiceDetailFromUrl(url: string): IServiceDetail | undefined;
65
+ findAllowedDomain(url: string): string | undefined;
66
+ get(clusterId: ClusterId, serviceGroup?: ServiceGroup): string | undefined;
67
+ getAllowedDomains(): string[];
68
+ markFailedServiceUrl(url: string): string | undefined;
69
+ setAllowedDomains(allowedDomains: string[]): void;
70
+ addAllowedDomains(newAllowedDomains: string[]): void;
71
+ updateServiceGroups(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void;
72
+ waitForCatalog(serviceGroup: ServiceGroup, timeout?: number): Promise<void>;
13
73
  }
package/src/webex-core.js CHANGED
@@ -31,7 +31,7 @@ import WebexUserAgentInterceptor from './interceptors/webex-user-agent';
31
31
  import RateLimitInterceptor from './interceptors/rate-limit';
32
32
  import EmbargoInterceptor from './interceptors/embargo';
33
33
  import DefaultOptionsInterceptor from './interceptors/default-options';
34
- import HostMapInterceptor from './lib/services/interceptors/hostmap';
34
+ import HostMapInterceptor from './lib/interceptors/hostmap';
35
35
  import config from './config';
36
36
  import {makeWebexStore} from './lib/storage';
37
37
  import mixinWebexCorePlugins from './lib/webex-core-plugin-mixin';