@webex/webex-core 3.8.0-next.2 → 3.8.0-next.20
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.
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/services/service-catalog.js +23 -68
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +1 -1
- package/dist/lib/services-v2/constants.js +17 -0
- package/dist/lib/services-v2/constants.js.map +1 -0
- package/dist/lib/services-v2/index.js +58 -0
- package/dist/lib/services-v2/index.js.map +1 -0
- package/dist/lib/services-v2/interceptors/hostmap.js +64 -0
- package/dist/lib/services-v2/interceptors/hostmap.js.map +1 -0
- package/dist/lib/services-v2/interceptors/server-error.js +77 -0
- package/dist/lib/services-v2/interceptors/server-error.js.map +1 -0
- package/dist/lib/services-v2/interceptors/service.js +137 -0
- package/dist/lib/services-v2/interceptors/service.js.map +1 -0
- package/dist/lib/services-v2/metrics.js +12 -0
- package/dist/lib/services-v2/metrics.js.map +1 -0
- package/dist/lib/services-v2/service-catalog.js +433 -0
- package/dist/lib/services-v2/service-catalog.js.map +1 -0
- package/dist/lib/services-v2/service-fed-ramp.js +13 -0
- package/dist/lib/services-v2/service-fed-ramp.js.map +1 -0
- package/dist/lib/services-v2/service-url.js +119 -0
- package/dist/lib/services-v2/service-url.js.map +1 -0
- package/dist/lib/services-v2/services-v2.js +963 -0
- package/dist/lib/services-v2/services-v2.js.map +1 -0
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/dist/webex-core.js.map +1 -1
- package/package.json +13 -13
- package/src/index.js +10 -0
- package/src/lib/services/service-catalog.js +14 -54
- package/src/lib/services-v2/README.md +3 -0
- package/src/lib/services-v2/constants.js +21 -0
- package/src/lib/services-v2/index.js +23 -0
- package/src/lib/services-v2/interceptors/hostmap.js +36 -0
- package/src/lib/services-v2/interceptors/server-error.js +48 -0
- package/src/lib/services-v2/interceptors/service.js +101 -0
- package/src/lib/services-v2/metrics.js +4 -0
- package/src/lib/services-v2/service-catalog.js +455 -0
- package/src/lib/services-v2/service-fed-ramp.js +5 -0
- package/src/lib/services-v2/service-url.js +124 -0
- package/src/lib/services-v2/services-v2.js +971 -0
- package/test/fixtures/host-catalog-v2.js +247 -0
- package/test/unit/spec/services/service-catalog.js +30 -90
- package/test/unit/spec/services-v2/services-v2.js +564 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import Url from 'url';
|
|
2
|
+
|
|
3
|
+
import AmpState from 'ampersand-state';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-underscore-dangle */
|
|
6
|
+
/**
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
const ServiceUrl = AmpState.extend({
|
|
10
|
+
namespace: 'ServiceUrl',
|
|
11
|
+
|
|
12
|
+
props: {
|
|
13
|
+
defaultUrl: ['string', true, undefined],
|
|
14
|
+
hosts: ['array', false, () => []],
|
|
15
|
+
name: ['string', true, undefined],
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate a host url based on the host
|
|
20
|
+
* uri provided.
|
|
21
|
+
* @param {string} hostUri
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
_generateHostUrl(hostUri) {
|
|
25
|
+
const url = Url.parse(this.defaultUrl);
|
|
26
|
+
|
|
27
|
+
// setting url.hostname will not apply during Url.format(), set host via
|
|
28
|
+
// a string literal instead.
|
|
29
|
+
url.host = `${hostUri}${url.port ? `:${url.port}` : ''}`;
|
|
30
|
+
|
|
31
|
+
return Url.format(url);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate a list of urls based on this
|
|
36
|
+
* `ServiceUrl`'s known hosts.
|
|
37
|
+
* @returns {string[]}
|
|
38
|
+
*/
|
|
39
|
+
_getHostUrls() {
|
|
40
|
+
return this.hosts.map((host) => ({
|
|
41
|
+
url: this._generateHostUrl(host.host),
|
|
42
|
+
priority: host.priority,
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the current host url with the highest priority. If a clusterId is not
|
|
48
|
+
* provided, this will only return a URL with a filtered host that has the
|
|
49
|
+
* `homeCluster` value set to `true`.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} [clusterId] - The clusterId to filter for a priority host.
|
|
52
|
+
* @returns {string} - The priority host url.
|
|
53
|
+
*/
|
|
54
|
+
_getPriorityHostUrl(clusterId) {
|
|
55
|
+
if (this.hosts.length === 0) {
|
|
56
|
+
return this.defaultUrl;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let filteredHosts = clusterId
|
|
60
|
+
? this.hosts.filter((host) => host.id === clusterId)
|
|
61
|
+
: this.hosts.filter((host) => host.homeCluster);
|
|
62
|
+
|
|
63
|
+
const aliveHosts = filteredHosts.filter((host) => !host.failed);
|
|
64
|
+
|
|
65
|
+
filteredHosts =
|
|
66
|
+
aliveHosts.length === 0
|
|
67
|
+
? filteredHosts.map((host) => {
|
|
68
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
69
|
+
host.failed = false;
|
|
70
|
+
|
|
71
|
+
return host;
|
|
72
|
+
})
|
|
73
|
+
: aliveHosts;
|
|
74
|
+
|
|
75
|
+
return this._generateHostUrl(
|
|
76
|
+
filteredHosts.reduce(
|
|
77
|
+
(previous, current) =>
|
|
78
|
+
previous.priority > current.priority || !previous.homeCluster ? current : previous,
|
|
79
|
+
{}
|
|
80
|
+
).host
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Attempt to mark a host from this `ServiceUrl` as failed and return true
|
|
86
|
+
* if the provided url has a host that could be successfully marked as failed.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} url
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
failHost(url) {
|
|
92
|
+
if (url === this.defaultUrl) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const {hostname} = Url.parse(url);
|
|
97
|
+
const foundHost = this.hosts.find((hostObj) => hostObj.host === hostname);
|
|
98
|
+
|
|
99
|
+
if (foundHost) {
|
|
100
|
+
foundHost.failed = true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return foundHost !== undefined;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the current `defaultUrl` or generate a url using the host with the
|
|
108
|
+
* highest priority via host rendering.
|
|
109
|
+
*
|
|
110
|
+
* @param {boolean} [priorityHost] - Retrieve the priority host.
|
|
111
|
+
* @param {string} [clusterId] - Cluster to match a host against.
|
|
112
|
+
* @returns {string} - The full service url.
|
|
113
|
+
*/
|
|
114
|
+
get(priorityHost, clusterId) {
|
|
115
|
+
if (!priorityHost) {
|
|
116
|
+
return this.defaultUrl;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this._getPriorityHostUrl(clusterId);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
/* eslint-enable no-underscore-dangle */
|
|
123
|
+
|
|
124
|
+
export default ServiceUrl;
|