@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
package/package.json CHANGED
@@ -33,14 +33,16 @@
33
33
  "@sinonjs/fake-timers": "^6.0.1",
34
34
  "@webex/babel-config-legacy": "0.0.0",
35
35
  "@webex/eslint-config-legacy": "0.0.0",
36
+ "@webex/internal-plugin-device": "3.9.0",
36
37
  "@webex/jest-config-legacy": "0.0.0",
37
38
  "@webex/legacy-tools": "0.0.0",
38
- "@webex/test-helper-chai": "3.8.1",
39
- "@webex/test-helper-make-local-url": "3.8.1",
40
- "@webex/test-helper-mocha": "3.8.1",
41
- "@webex/test-helper-mock-webex": "3.8.1",
42
- "@webex/test-helper-refresh-callback": "3.8.1",
43
- "@webex/test-helper-test-users": "3.8.1",
39
+ "@webex/plugin-logger": "3.9.0",
40
+ "@webex/test-helper-chai": "3.9.0",
41
+ "@webex/test-helper-make-local-url": "3.9.0",
42
+ "@webex/test-helper-mocha": "3.9.0",
43
+ "@webex/test-helper-mock-webex": "3.9.0",
44
+ "@webex/test-helper-refresh-callback": "3.9.0",
45
+ "@webex/test-helper-test-users": "3.9.0",
44
46
  "chai": "^4.3.4",
45
47
  "chai-as-promised": "^7.1.1",
46
48
  "eslint": "^8.24.0",
@@ -48,12 +50,10 @@
48
50
  "sinon": "^9.2.4"
49
51
  },
50
52
  "dependencies": {
51
- "@webex/common": "3.8.1",
52
- "@webex/common-timers": "3.8.1",
53
- "@webex/http-core": "3.8.1",
54
- "@webex/internal-plugin-device": "3.8.1",
55
- "@webex/plugin-logger": "3.8.1",
56
- "@webex/storage-adapter-spec": "3.8.1",
53
+ "@webex/common": "3.9.0",
54
+ "@webex/common-timers": "3.9.0",
55
+ "@webex/http-core": "3.9.0",
56
+ "@webex/storage-adapter-spec": "3.9.0",
57
57
  "ampersand-collection": "^2.0.2",
58
58
  "ampersand-events": "^2.0.2",
59
59
  "ampersand-state": "^5.0.3",
@@ -73,5 +73,5 @@
73
73
  "test:style": "eslint ./src/**/*.*",
74
74
  "test:unit": "webex-legacy-tools test --unit --runner jest"
75
75
  },
76
- "version": "3.8.1"
76
+ "version": "3.9.0"
77
77
  }
package/src/index.js CHANGED
@@ -16,28 +16,16 @@ import './lib/services';
16
16
  export {Credentials, filterScope, grantErrors, sortScope, Token} from './lib/credentials';
17
17
 
18
18
  export {
19
- constants as serviceConstants,
20
19
  ServiceCatalog,
21
20
  ServiceRegistry,
22
21
  ServiceState,
23
- ServiceInterceptor,
24
- ServerErrorInterceptor,
25
22
  Services,
26
23
  ServiceHost,
27
24
  ServiceUrl,
28
- HostMapInterceptor,
29
25
  } from './lib/services';
30
26
 
31
- export {
32
- constants as serviceConstantsV2,
33
- ServiceCatalogV2,
34
- ServiceInterceptorV2,
35
- ServerErrorInterceptorV2,
36
- ServicesV2,
37
- ServiceDetail,
38
- HostMapInterceptorV2,
39
- } from './lib/services-v2';
40
-
27
+ export {ServiceCatalogV2, ServicesV2, ServiceDetail} from './lib/services-v2';
28
+ export * as serviceConstants from './lib/constants';
41
29
  export {
42
30
  makeWebexStore,
43
31
  makeWebexPluginStore,
@@ -68,6 +56,9 @@ export {default as WebexUserAgentInterceptor} from './interceptors/webex-user-ag
68
56
  export {default as RateLimitInterceptor} from './interceptors/rate-limit';
69
57
  export {default as EmbargoInterceptor} from './interceptors/embargo';
70
58
  export {default as DefaultOptionsInterceptor} from './interceptors/default-options';
59
+ export {default as HostMapInterceptor} from './lib/interceptors/hostmap';
60
+ export {default as ServiceInterceptor} from './lib/interceptors/service';
61
+ export {default as ServerErrorInterceptor} from './lib/interceptors/server-error';
71
62
 
72
63
  export {default as Batcher} from './lib/batcher';
73
64
  export {default as Page} from './lib/page';
@@ -1,6 +1,34 @@
1
1
  // Metric to do with WDM registration
2
- export const METRICS = {
2
+ const METRICS = {
3
3
  JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED: 'JS_SDK_CREDENTIALS_DOWNSCOPE_FAILED',
4
4
  JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH:
5
5
  'JS_SDK_CREDENTIALS_TOKEN_REFRESH_SCOPE_MISMATCH',
6
6
  };
7
+
8
+ const NAMESPACE = 'services';
9
+ const SERVICE_CATALOGS = ['discovery', 'limited', 'signin', 'postauth', 'custom'];
10
+
11
+ const SERVICE_CATALOGS_ENUM_TYPES = {
12
+ STRING: 'SERVICE_CATALOGS_ENUM_TYPES_STRING',
13
+ NUMBER: 'SERVICE_CATALOGS_ENUM_TYPES_NUMBER',
14
+ };
15
+
16
+ // The default allowed domains that SDK can make requests to outside of service catalog
17
+ const COMMERCIAL_ALLOWED_DOMAINS = [
18
+ 'wbx2.com',
19
+ 'ciscospark.com',
20
+ 'webex.com',
21
+ 'webexapis.com',
22
+ 'broadcloudpbx.com',
23
+ 'broadcloud.eu',
24
+ 'broadcloud.com.au',
25
+ 'broadcloudpbx.net',
26
+ ];
27
+
28
+ export {
29
+ SERVICE_CATALOGS_ENUM_TYPES,
30
+ NAMESPACE,
31
+ SERVICE_CATALOGS,
32
+ COMMERCIAL_ALLOWED_DOMAINS,
33
+ METRICS,
34
+ };
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import {Interceptor} from '@webex/http-core';
6
- import WebexHttpError from '../../webex-http-error';
6
+ import WebexHttpError from '../webex-http-error';
7
7
  /**
8
8
  * Changes server url when it fails
9
9
  */
@@ -3,10 +3,9 @@
3
3
  */
4
4
  import {registerInternalPlugin} from '../../webex-core';
5
5
 
6
- import * as constants from './constants';
7
6
  import Services from './services';
8
- import ServerErrorInterceptor from './interceptors/server-error';
9
- import ServiceInterceptor from './interceptors/service';
7
+ import ServerErrorInterceptor from '../interceptors/server-error';
8
+ import ServiceInterceptor from '../interceptors/service';
10
9
 
11
10
  registerInternalPlugin('services', Services, {
12
11
  interceptors: {
@@ -15,10 +14,6 @@ registerInternalPlugin('services', Services, {
15
14
  },
16
15
  });
17
16
 
18
- export {constants};
19
- export {default as ServiceInterceptor} from './interceptors/service';
20
- export {default as ServerErrorInterceptor} from './interceptors/server-error';
21
- export {default as HostMapInterceptor} from './interceptors/hostmap';
22
17
  export {default as Services} from './services';
23
18
  export {default as ServiceCatalog} from './service-catalog';
24
19
  export {default as ServiceRegistry} from './service-registry';
@@ -1,6 +1,6 @@
1
1
  import Url from 'url';
2
2
 
3
- import {SERVICE_CATALOGS} from './constants';
3
+ import {SERVICE_CATALOGS} from '../constants';
4
4
 
5
5
  /**
6
6
  * The parameter transfer object for {@link ServiceHost#constructor}.
@@ -1,4 +1,4 @@
1
- import {SERVICE_CATALOGS, SERVICE_CATALOGS_ENUM_TYPES} from './constants';
1
+ import {SERVICE_CATALOGS, SERVICE_CATALOGS_ENUM_TYPES} from '../constants';
2
2
  import ServiceHost from './service-host';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import {SERVICE_CATALOGS} from './constants';
1
+ import {SERVICE_CATALOGS} from '../constants';
2
2
 
3
3
  /**
4
4
  * The state of a specific catalog to be used by {@link ServiceState}.
@@ -3,12 +3,12 @@ import sha256 from 'crypto-js/sha256';
3
3
  import {union, forEach} 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 ServiceRegistry from './service-registry';
9
9
  import ServiceState from './service-state';
10
10
  import fedRampServices from './service-fed-ramp';
11
- import {COMMERCIAL_ALLOWED_DOMAINS} from './constants';
11
+ import {COMMERCIAL_ALLOWED_DOMAINS} from '../constants';
12
12
 
13
13
  const trailingSlashes = /(?:^\/)|(?:\/$)/;
14
14
 
@@ -1,23 +1,7 @@
1
1
  /*!
2
2
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
- // import {registerInternalPlugin} from '../../webex-core';
5
4
 
6
- import * as constants from './constants';
7
- // import ServerErrorInterceptor from './interceptors/server-error';
8
- // import ServiceInterceptor from './interceptors/service';
9
5
  export {default as ServicesV2} from './services-v2';
10
-
11
- // registerInternalPlugin('services', ServicesV2, {
12
- // interceptors: {
13
- // ServiceInterceptor: ServiceInterceptor.create,
14
- // ServerErrorInterceptor: ServerErrorInterceptor.create,
15
- // },
16
- // });
17
-
18
- export {constants};
19
- export {default as ServiceInterceptorV2} from './interceptors/service';
20
- export {default as ServerErrorInterceptorV2} from './interceptors/server-error';
21
- export {default as HostMapInterceptorV2} from './interceptors/hostmap';
22
6
  export {default as ServiceCatalogV2} from './service-catalog';
23
7
  export {default as ServiceDetail} from './service-detail';
@@ -2,7 +2,7 @@ import AmpState from 'ampersand-state';
2
2
 
3
3
  import {union} from 'lodash';
4
4
  import ServiceDetail from './service-detail';
5
- import {IServiceDetail} from './types';
5
+ import {IServiceDetail, ServiceGroup} from './types';
6
6
 
7
7
  /**
8
8
  * @class
@@ -55,10 +55,10 @@ const ServiceCatalog = AmpState.extend({
55
55
  /**
56
56
  * @private
57
57
  * Get all service details for a given service group or return all details if no group is specified.
58
- * @param {string} serviceGroup - The name of the service group to retrieve details for.
58
+ * @param {ServiceGroup} serviceGroup - The name of the service group to retrieve details for.
59
59
  * @returns {Array<IServiceDetail>} - An array of service details.
60
60
  */
61
- _getAllServiceDetails(serviceGroup: string): Array<IServiceDetail> {
61
+ _getAllServiceDetails(serviceGroup?: ServiceGroup): Array<IServiceDetail> {
62
62
  const serviceDetails =
63
63
  typeof serviceGroup === 'string'
64
64
  ? this.serviceGroups[serviceGroup] || []
@@ -78,10 +78,10 @@ const ServiceCatalog = AmpState.extend({
78
78
  * Search the service details array to locate a `ServiceDetails`
79
79
  * class object based on its id.
80
80
  * @param {string} clusterId
81
- * @param {string} [serviceGroup]
81
+ * @param {ServiceGroup} [serviceGroup]
82
82
  * @returns {IServiceDetail}
83
83
  */
84
- _getServiceDetail(clusterId: string, serviceGroup: string): IServiceDetail | undefined {
84
+ _getServiceDetail(clusterId: string, serviceGroup?: ServiceGroup): IServiceDetail | undefined {
85
85
  const serviceDetails = this._getAllServiceDetails(serviceGroup);
86
86
 
87
87
  return serviceDetails.find((serviceDetail: IServiceDetail) => serviceDetail.id === clusterId);
@@ -90,11 +90,11 @@ const ServiceCatalog = AmpState.extend({
90
90
  /**
91
91
  * @private
92
92
  * Safely load one or more `ServiceDetail`s into this `ServiceCatalog` instance.
93
- * @param {string} serviceGroup
93
+ * @param {ServiceGroup} serviceGroup
94
94
  * @param {Array<ServiceDetail>} serviceDetails
95
95
  * @returns {void}
96
96
  */
97
- _loadServiceDetails(serviceGroup: string, serviceDetails: Array<IServiceDetail>): void {
97
+ _loadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {
98
98
  // declare namespaces outside of loop
99
99
  let existingService: IServiceDetail | undefined;
100
100
 
@@ -110,11 +110,11 @@ const ServiceCatalog = AmpState.extend({
110
110
  /**
111
111
  * @private
112
112
  * Safely unload one or more `ServiceDetail`s into this `Services` instance
113
- * @param {string} serviceGroup
113
+ * @param {ServiceGroup} serviceGroup
114
114
  * @param {Array<ServiceDetail>} serviceDetails
115
115
  * @returns {void}
116
116
  */
117
- _unloadServiceDetails(serviceGroup: string, serviceDetails: Array<IServiceDetail>): void {
117
+ _unloadServiceDetails(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>): void {
118
118
  // declare namespaces outside of loop
119
119
  let existingService: IServiceDetail | undefined;
120
120
 
@@ -169,13 +169,13 @@ const ServiceCatalog = AmpState.extend({
169
169
  * clusterId.
170
170
  * @param {object} params
171
171
  * @param {string} params.clusterId - clusterId of found service
172
- * @param {string} [params.serviceGroup] - specify service group
172
+ * @param {ServiceGroup} [params.serviceGroup] - specify service group
173
173
  * @returns {object} service
174
174
  * @returns {string} service.name
175
175
  * @returns {string} service.url
176
176
  */
177
177
  findServiceFromClusterId(
178
- {clusterId, serviceGroup} = {} as {clusterId: string; serviceGroup: string}
178
+ {clusterId, serviceGroup} = {} as {clusterId: string; serviceGroup?: ServiceGroup}
179
179
  ): {name: string; url: string} | undefined {
180
180
  const serviceDetails = this._getServiceDetail(clusterId, serviceGroup);
181
181
 
@@ -226,12 +226,13 @@ const ServiceCatalog = AmpState.extend({
226
226
  },
227
227
 
228
228
  /**
229
- * Get a service url from the current services list by name.
229
+ * Get a service url from the current services list by name. Return undefined
230
+ * if the service is not found.
230
231
  * @param {string} clusterId
231
- * @param {string} serviceGroup
232
- * @returns {string}
232
+ * @param {ServiceGroup} serviceGroup
233
+ * @returns {string | undefined}
233
234
  */
234
- get(clusterId: string, serviceGroup: string): string | undefined {
235
+ get(clusterId: string, serviceGroup?: ServiceGroup): string | undefined {
235
236
  const serviceDetail = this._getServiceDetail(clusterId, serviceGroup);
236
237
 
237
238
  return serviceDetail ? serviceDetail.get() : undefined;
@@ -297,11 +298,11 @@ const ServiceCatalog = AmpState.extend({
297
298
  * service hostmap.
298
299
  * @emits ServiceCatalog#preauthorized
299
300
  * @emits ServiceCatalog#postauthorized
300
- * @param {string} serviceGroup
301
+ * @param {ServiceGroup} serviceGroup
301
302
  * @param {Array<IServiceDetail>} serviceDetails
302
303
  * @returns {void}
303
304
  */
304
- updateServiceGroups(serviceGroup: string, serviceDetails: Array<IServiceDetail>) {
305
+ updateServiceGroups(serviceGroup: ServiceGroup, serviceDetails: Array<IServiceDetail>) {
305
306
  const currentServiceDetails = this.serviceGroups[serviceGroup];
306
307
 
307
308
  const unusedServicesDetails = currentServiceDetails.filter((serviceDetail) =>
@@ -327,11 +328,11 @@ const ServiceCatalog = AmpState.extend({
327
328
  /**
328
329
  * Wait until the service catalog is available,
329
330
  * or reject after a timeout of 60 seconds.
330
- * @param {string} serviceGroup
331
+ * @param {ServiceGroup} serviceGroup
331
332
  * @param {number} [timeout] - in seconds
332
333
  * @returns {Promise<void>}
333
334
  */
334
- waitForCatalog(serviceGroup: string, timeout: number): Promise<void> {
335
+ waitForCatalog(serviceGroup: ServiceGroup, timeout?: number): Promise<void> {
335
336
  return new Promise<void>((resolve, reject) => {
336
337
  if (this.status[serviceGroup].ready) {
337
338
  resolve();