@webex/webex-core 2.59.2 → 2.59.3-next.1
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/.eslintrc.js +6 -6
- package/README.md +79 -79
- package/babel.config.js +3 -3
- package/dist/config.js +24 -24
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +56 -56
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +28 -28
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js +24 -24
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js +9 -9
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/network-timing.js +19 -19
- package/dist/interceptors/network-timing.js.map +1 -1
- package/dist/interceptors/payload-transformer.js +19 -19
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +40 -40
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js +13 -13
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js +23 -23
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js +13 -13
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/request-timing.js +23 -23
- package/dist/interceptors/request-timing.js.map +1 -1
- package/dist/interceptors/response-logger.js +19 -19
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js +29 -29
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-tracking-id.js +15 -15
- package/dist/interceptors/webex-tracking-id.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js +13 -13
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +83 -83
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +103 -103
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js +17 -17
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/index.js +2 -2
- package/dist/lib/credentials/index.js.map +1 -1
- package/dist/lib/credentials/scope.js +11 -11
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js +2 -2
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +145 -145
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +49 -49
- package/dist/lib/page.js.map +1 -1
- package/dist/lib/services/constants.js.map +1 -1
- package/dist/lib/services/index.js +2 -2
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/server-error.js +9 -9
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +24 -24
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js +104 -104
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +134 -134
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js +175 -175
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js +38 -38
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js +31 -31
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +245 -245
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js +28 -28
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js +27 -27
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/errors.js +4 -4
- package/dist/lib/storage/errors.js.map +1 -1
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js +44 -44
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js +40 -40
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js +9 -9
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js +13 -13
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js +9 -9
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js +13 -13
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js +36 -36
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +9 -9
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +104 -104
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js +12 -12
- package/dist/webex-internal-core.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +20 -19
- package/process +1 -1
- package/src/config.js +90 -90
- package/src/credentials-config.js +212 -212
- package/src/index.js +62 -62
- package/src/interceptors/auth.js +186 -186
- package/src/interceptors/default-options.js +55 -55
- package/src/interceptors/embargo.js +43 -43
- package/src/interceptors/network-timing.js +54 -54
- package/src/interceptors/payload-transformer.js +55 -55
- package/src/interceptors/rate-limit.js +169 -169
- package/src/interceptors/redirect.js +106 -106
- package/src/interceptors/request-event.js +93 -93
- package/src/interceptors/request-logger.js +78 -78
- package/src/interceptors/request-timing.js +65 -65
- package/src/interceptors/response-logger.js +98 -98
- package/src/interceptors/user-agent.js +77 -77
- package/src/interceptors/webex-tracking-id.js +73 -73
- package/src/interceptors/webex-user-agent.js +79 -79
- package/src/lib/batcher.js +307 -307
- package/src/lib/credentials/credentials.js +552 -552
- package/src/lib/credentials/grant-errors.js +92 -92
- package/src/lib/credentials/index.js +16 -16
- package/src/lib/credentials/scope.js +34 -34
- package/src/lib/credentials/token-collection.js +17 -17
- package/src/lib/credentials/token.js +559 -559
- package/src/lib/page.js +159 -159
- package/src/lib/services/constants.js +9 -9
- package/src/lib/services/index.js +26 -26
- package/src/lib/services/interceptors/server-error.js +48 -48
- package/src/lib/services/interceptors/service.js +101 -101
- package/src/lib/services/metrics.js +4 -4
- package/src/lib/services/service-catalog.js +435 -435
- package/src/lib/services/service-fed-ramp.js +4 -4
- package/src/lib/services/service-host.js +267 -267
- package/src/lib/services/service-registry.js +465 -465
- package/src/lib/services/service-state.js +78 -78
- package/src/lib/services/service-url.js +124 -124
- package/src/lib/services/services.js +1018 -1018
- package/src/lib/stateless-webex-plugin.js +98 -98
- package/src/lib/storage/decorators.js +220 -220
- package/src/lib/storage/errors.js +15 -15
- package/src/lib/storage/index.js +10 -10
- package/src/lib/storage/make-webex-plugin-store.js +211 -211
- package/src/lib/storage/make-webex-store.js +140 -140
- package/src/lib/storage/memory-store-adapter.js +79 -79
- package/src/lib/webex-core-plugin-mixin.js +114 -114
- package/src/lib/webex-http-error.js +61 -61
- package/src/lib/webex-internal-core-plugin-mixin.js +107 -107
- package/src/lib/webex-plugin.js +222 -222
- package/src/plugins/logger.js +60 -60
- package/src/webex-core.js +745 -745
- package/src/webex-internal-core.js +46 -46
- package/test/integration/spec/credentials/credentials.js +139 -139
- package/test/integration/spec/credentials/token.js +102 -102
- package/test/integration/spec/services/service-catalog.js +838 -838
- package/test/integration/spec/services/services.js +1221 -1221
- package/test/integration/spec/webex-core.js +178 -178
- package/test/unit/spec/_setup.js +44 -44
- package/test/unit/spec/credentials/credentials.js +1017 -1017
- package/test/unit/spec/credentials/token.js +441 -441
- package/test/unit/spec/interceptors/auth.js +521 -521
- package/test/unit/spec/interceptors/default-options.js +84 -84
- package/test/unit/spec/interceptors/embargo.js +144 -144
- package/test/unit/spec/interceptors/network-timing.js +49 -49
- package/test/unit/spec/interceptors/payload-transformer.js +155 -155
- package/test/unit/spec/interceptors/rate-limit.js +302 -302
- package/test/unit/spec/interceptors/redirect.js +102 -102
- package/test/unit/spec/interceptors/request-timing.js +92 -92
- package/test/unit/spec/interceptors/user-agent.js +76 -76
- package/test/unit/spec/interceptors/webex-tracking-id.js +76 -76
- package/test/unit/spec/interceptors/webex-user-agent.js +159 -159
- package/test/unit/spec/lib/batcher.js +330 -330
- package/test/unit/spec/lib/page.js +148 -148
- package/test/unit/spec/lib/webex-plugin.js +48 -48
- package/test/unit/spec/services/interceptors/server-error.js +204 -204
- package/test/unit/spec/services/interceptors/service.js +188 -188
- package/test/unit/spec/services/service-catalog.js +194 -194
- package/test/unit/spec/services/service-host.js +260 -260
- package/test/unit/spec/services/service-registry.js +747 -747
- package/test/unit/spec/services/service-state.js +60 -60
- package/test/unit/spec/services/service-url.js +258 -258
- package/test/unit/spec/services/services.js +348 -348
- package/test/unit/spec/storage/persist.js +50 -50
- package/test/unit/spec/storage/storage-adapter.js +12 -12
- package/test/unit/spec/storage/wait-for-value.js +81 -81
- package/test/unit/spec/webex-core.js +253 -253
- package/test/unit/spec/webex-internal-core.js +91 -91
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hydra: 'https://api-usgov.webex.com/v1',
|
|
3
|
-
u2c: 'https://u2c.gov.ciscospark.com/u2c/api/v1',
|
|
4
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
hydra: 'https://api-usgov.webex.com/v1',
|
|
3
|
+
u2c: 'https://u2c.gov.ciscospark.com/u2c/api/v1',
|
|
4
|
+
};
|
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
import Url from 'url';
|
|
2
|
-
|
|
3
|
-
import {SERVICE_CATALOGS} from './constants';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The parameter transfer object for {@link ServiceHost#constructor}.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {Object} ServiceHostConstructorPTO
|
|
9
|
-
* @property {string} ServiceHostConstructorPTO.catalog - The host's catalog.
|
|
10
|
-
* @property {string} ServiceHostConstructorPTO.defaultUri - The host's default.
|
|
11
|
-
* @property {string} ServiceHostConstructorPTO.hostGroup - The host's group.
|
|
12
|
-
* @property {string} ServiceHostConstructorPTO.id - The host's clusterId.
|
|
13
|
-
* @property {number} ServiceHostConstructorPTO.priority - The host's priority.
|
|
14
|
-
* @property {string} ServiceHostConstructorPTO.uri - The host's uri.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The parameter transfer object for {@link ServiceHost#polyGenerate}.
|
|
19
|
-
*
|
|
20
|
-
* @typedef {Object} ServiceHostPolyGeneratePTO
|
|
21
|
-
* @property {string} ServiceHostPolyGeneratePTO.catalog - The target catalog.
|
|
22
|
-
* @property {string} ServiceHostPolyGeneratePTO.name - The service name.
|
|
23
|
-
* @property {string} ServiceHostPolyGeneratePTO.url - The service url.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @class
|
|
28
|
-
* @classdesc - Manages a single service host and its associated data.
|
|
29
|
-
*/
|
|
30
|
-
export default class ServiceHost {
|
|
31
|
-
/**
|
|
32
|
-
* Generate a new {@link ServiceHost}.
|
|
33
|
-
*
|
|
34
|
-
* @public
|
|
35
|
-
* @constructor
|
|
36
|
-
* @memberof ServiceHost
|
|
37
|
-
* @param {ServiceHostConstructorPTO} pto
|
|
38
|
-
*/
|
|
39
|
-
constructor(pto) {
|
|
40
|
-
// Validate the parameter transfer object.
|
|
41
|
-
ServiceHost.validate(pto);
|
|
42
|
-
|
|
43
|
-
// Map the parameter transfer object to the class object.
|
|
44
|
-
/**
|
|
45
|
-
* The catalog name that the {@link ServiceHost} is associated with.
|
|
46
|
-
*
|
|
47
|
-
* @instance
|
|
48
|
-
* @type {string}
|
|
49
|
-
* @public
|
|
50
|
-
* @memberof ServiceHost
|
|
51
|
-
*/
|
|
52
|
-
this.catalog = pto.catalog;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The default URI for the {@link ServiceHost}.
|
|
56
|
-
*
|
|
57
|
-
* @instance
|
|
58
|
-
* @type {string}
|
|
59
|
-
* @public
|
|
60
|
-
* @memberof ServiceHost
|
|
61
|
-
*/
|
|
62
|
-
this.default = pto.defaultUri;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The host group that the {@link ServiceHost} is associated with.
|
|
66
|
-
*
|
|
67
|
-
* @instance
|
|
68
|
-
* @type {string}
|
|
69
|
-
* @public
|
|
70
|
-
* @memberof ServiceHost
|
|
71
|
-
*/
|
|
72
|
-
this.hostGroup = pto.hostGroup;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The cluster ID of the {@link ServiceHost}.
|
|
76
|
-
*
|
|
77
|
-
* @instance
|
|
78
|
-
* @type {string}
|
|
79
|
-
* @public
|
|
80
|
-
* @memberof ServiceHost
|
|
81
|
-
*/
|
|
82
|
-
this.id = pto.id;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The priority value of the {@link ServiceHost}. The lower the number, the
|
|
86
|
-
* higher the priority.
|
|
87
|
-
*
|
|
88
|
-
* @instance
|
|
89
|
-
* @type {number}
|
|
90
|
-
* @public
|
|
91
|
-
* @memberof ServiceHost
|
|
92
|
-
*/
|
|
93
|
-
this.priority = pto.priority;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The host uri of the {@link ServiceHost}.
|
|
97
|
-
*
|
|
98
|
-
* @instance
|
|
99
|
-
* @type {string}
|
|
100
|
-
* @public
|
|
101
|
-
* @memberof ServiceHost
|
|
102
|
-
*/
|
|
103
|
-
this.uri = pto.uri;
|
|
104
|
-
|
|
105
|
-
// Generate flags.
|
|
106
|
-
/**
|
|
107
|
-
* If the {@link ServiceHost} is marked as failed.
|
|
108
|
-
*
|
|
109
|
-
* @instance
|
|
110
|
-
* @type {boolean}
|
|
111
|
-
* @protected
|
|
112
|
-
* @memberof ServiceHost
|
|
113
|
-
*/
|
|
114
|
-
this.failed = false;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* If the {@link ServiceHost} is marked as replaced.
|
|
118
|
-
*
|
|
119
|
-
* @instance
|
|
120
|
-
* @type {boolean}
|
|
121
|
-
* @protected
|
|
122
|
-
* @memberof ServiceHost
|
|
123
|
-
*/
|
|
124
|
-
this.replaced = false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* If the {@link ServiceHost} is in an active state.
|
|
129
|
-
*
|
|
130
|
-
* @public
|
|
131
|
-
* @memberof ServiceHost
|
|
132
|
-
* @type {boolean} - `true` if the service is active and usable.
|
|
133
|
-
*/
|
|
134
|
-
get active() {
|
|
135
|
-
// Validate that the `ServiceHost` was not marked as failed or replaced.
|
|
136
|
-
return !this.failed && !this.replaced;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* If the host is local to the user's cluster.
|
|
141
|
-
*
|
|
142
|
-
* @public
|
|
143
|
-
* @memberof ServiceHost
|
|
144
|
-
* @type {boolean} - If the host is local.
|
|
145
|
-
*/
|
|
146
|
-
get local() {
|
|
147
|
-
return this.default.includes(this.hostGroup);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* The service value.
|
|
152
|
-
*
|
|
153
|
-
* @public
|
|
154
|
-
* @memberof ServiceHost
|
|
155
|
-
* @type {string} - The service value.
|
|
156
|
-
*/
|
|
157
|
-
get service() {
|
|
158
|
-
return this.id.split(':')[3];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* The formatted url for the host.
|
|
163
|
-
*
|
|
164
|
-
* @public
|
|
165
|
-
* @memberof ServiceHost
|
|
166
|
-
* @type {string} - The service url.
|
|
167
|
-
*/
|
|
168
|
-
get url() {
|
|
169
|
-
// Generate a url object from the default url.
|
|
170
|
-
const urlObj = Url.parse(this.default);
|
|
171
|
-
|
|
172
|
-
// Format the host of the generated url object.
|
|
173
|
-
urlObj.host = `${this.uri}${urlObj.port ? `:${urlObj.port}` : ''}`;
|
|
174
|
-
|
|
175
|
-
// Assign the formatted url to this.
|
|
176
|
-
return Url.format(urlObj);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Set one or more of the status properties of the class object.
|
|
181
|
-
*
|
|
182
|
-
* @public
|
|
183
|
-
* @memberof ServiceHost
|
|
184
|
-
* @param {Object} pto - The parameter transfer object.
|
|
185
|
-
* @property {boolean} [pto.failed] - The failed status to set.
|
|
186
|
-
* @property {boolean} [pto.replaced] - the replaced status to set.
|
|
187
|
-
* @returns {this}
|
|
188
|
-
*/
|
|
189
|
-
setStatus({failed, replaced}) {
|
|
190
|
-
if (failed !== undefined) {
|
|
191
|
-
this.failed = failed;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (replaced !== undefined) {
|
|
195
|
-
this.replaced = replaced;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Generate a service host using only a catalog, name, and URL.
|
|
203
|
-
*
|
|
204
|
-
* @public
|
|
205
|
-
* @static
|
|
206
|
-
* @memberof ServiceHost
|
|
207
|
-
* @param {ServiceHostPolyGeneratePTO} pto
|
|
208
|
-
* @returns {ServiceHost} - The generated service host.
|
|
209
|
-
*/
|
|
210
|
-
static polyGenerate({catalog, name, url}) {
|
|
211
|
-
return new ServiceHost({
|
|
212
|
-
catalog,
|
|
213
|
-
defaultUri: url,
|
|
214
|
-
hostGroup: Url.parse(url).host,
|
|
215
|
-
id: name ? `poly-head:poly-group:poly-cluster:${name}` : undefined,
|
|
216
|
-
priority: 1,
|
|
217
|
-
uri: Url.parse(url).host,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Validate that a constructor parameter transfer object is valid.
|
|
223
|
-
*
|
|
224
|
-
* @public
|
|
225
|
-
* @static
|
|
226
|
-
* @memberof ServiceHost
|
|
227
|
-
* @param {ServiceHostConstructorPTO} pto
|
|
228
|
-
* @throws - If the parameter transfer object is not valid.
|
|
229
|
-
* @returns {undefined}
|
|
230
|
-
*/
|
|
231
|
-
static validate({catalog, defaultUri, hostGroup, id, priority, uri}) {
|
|
232
|
-
// Generate error-throwing method.
|
|
233
|
-
const throwError = (msg) => {
|
|
234
|
-
throw new Error(`service-host: invalid constructor parameters, ${msg}`);
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// Validate the catalog property.
|
|
238
|
-
if (!SERVICE_CATALOGS.includes(catalog)) {
|
|
239
|
-
throwError("'catalog' must be a string");
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Validate the `defaultUri` property.
|
|
243
|
-
if (typeof defaultUri !== 'string') {
|
|
244
|
-
throwError("'defaultUri' must be a string");
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Validate the `hostGroup` property.
|
|
248
|
-
if (typeof hostGroup !== 'string') {
|
|
249
|
-
throwError("'hostGroup' must be a string");
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Validate the `id` property.
|
|
253
|
-
if (typeof id !== 'string' || id.split(':').length !== 4) {
|
|
254
|
-
throwError("'id' must be a string that contains 3 ':' characters");
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Validate the `priority` property.
|
|
258
|
-
if (typeof priority !== 'number') {
|
|
259
|
-
throwError("'priority' must be a number");
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Validate the `uri` property.
|
|
263
|
-
if (typeof uri !== 'string') {
|
|
264
|
-
throwError("'uri' must be a string");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
1
|
+
import Url from 'url';
|
|
2
|
+
|
|
3
|
+
import {SERVICE_CATALOGS} from './constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The parameter transfer object for {@link ServiceHost#constructor}.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {Object} ServiceHostConstructorPTO
|
|
9
|
+
* @property {string} ServiceHostConstructorPTO.catalog - The host's catalog.
|
|
10
|
+
* @property {string} ServiceHostConstructorPTO.defaultUri - The host's default.
|
|
11
|
+
* @property {string} ServiceHostConstructorPTO.hostGroup - The host's group.
|
|
12
|
+
* @property {string} ServiceHostConstructorPTO.id - The host's clusterId.
|
|
13
|
+
* @property {number} ServiceHostConstructorPTO.priority - The host's priority.
|
|
14
|
+
* @property {string} ServiceHostConstructorPTO.uri - The host's uri.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The parameter transfer object for {@link ServiceHost#polyGenerate}.
|
|
19
|
+
*
|
|
20
|
+
* @typedef {Object} ServiceHostPolyGeneratePTO
|
|
21
|
+
* @property {string} ServiceHostPolyGeneratePTO.catalog - The target catalog.
|
|
22
|
+
* @property {string} ServiceHostPolyGeneratePTO.name - The service name.
|
|
23
|
+
* @property {string} ServiceHostPolyGeneratePTO.url - The service url.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @class
|
|
28
|
+
* @classdesc - Manages a single service host and its associated data.
|
|
29
|
+
*/
|
|
30
|
+
export default class ServiceHost {
|
|
31
|
+
/**
|
|
32
|
+
* Generate a new {@link ServiceHost}.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @constructor
|
|
36
|
+
* @memberof ServiceHost
|
|
37
|
+
* @param {ServiceHostConstructorPTO} pto
|
|
38
|
+
*/
|
|
39
|
+
constructor(pto) {
|
|
40
|
+
// Validate the parameter transfer object.
|
|
41
|
+
ServiceHost.validate(pto);
|
|
42
|
+
|
|
43
|
+
// Map the parameter transfer object to the class object.
|
|
44
|
+
/**
|
|
45
|
+
* The catalog name that the {@link ServiceHost} is associated with.
|
|
46
|
+
*
|
|
47
|
+
* @instance
|
|
48
|
+
* @type {string}
|
|
49
|
+
* @public
|
|
50
|
+
* @memberof ServiceHost
|
|
51
|
+
*/
|
|
52
|
+
this.catalog = pto.catalog;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The default URI for the {@link ServiceHost}.
|
|
56
|
+
*
|
|
57
|
+
* @instance
|
|
58
|
+
* @type {string}
|
|
59
|
+
* @public
|
|
60
|
+
* @memberof ServiceHost
|
|
61
|
+
*/
|
|
62
|
+
this.default = pto.defaultUri;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The host group that the {@link ServiceHost} is associated with.
|
|
66
|
+
*
|
|
67
|
+
* @instance
|
|
68
|
+
* @type {string}
|
|
69
|
+
* @public
|
|
70
|
+
* @memberof ServiceHost
|
|
71
|
+
*/
|
|
72
|
+
this.hostGroup = pto.hostGroup;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The cluster ID of the {@link ServiceHost}.
|
|
76
|
+
*
|
|
77
|
+
* @instance
|
|
78
|
+
* @type {string}
|
|
79
|
+
* @public
|
|
80
|
+
* @memberof ServiceHost
|
|
81
|
+
*/
|
|
82
|
+
this.id = pto.id;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The priority value of the {@link ServiceHost}. The lower the number, the
|
|
86
|
+
* higher the priority.
|
|
87
|
+
*
|
|
88
|
+
* @instance
|
|
89
|
+
* @type {number}
|
|
90
|
+
* @public
|
|
91
|
+
* @memberof ServiceHost
|
|
92
|
+
*/
|
|
93
|
+
this.priority = pto.priority;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The host uri of the {@link ServiceHost}.
|
|
97
|
+
*
|
|
98
|
+
* @instance
|
|
99
|
+
* @type {string}
|
|
100
|
+
* @public
|
|
101
|
+
* @memberof ServiceHost
|
|
102
|
+
*/
|
|
103
|
+
this.uri = pto.uri;
|
|
104
|
+
|
|
105
|
+
// Generate flags.
|
|
106
|
+
/**
|
|
107
|
+
* If the {@link ServiceHost} is marked as failed.
|
|
108
|
+
*
|
|
109
|
+
* @instance
|
|
110
|
+
* @type {boolean}
|
|
111
|
+
* @protected
|
|
112
|
+
* @memberof ServiceHost
|
|
113
|
+
*/
|
|
114
|
+
this.failed = false;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* If the {@link ServiceHost} is marked as replaced.
|
|
118
|
+
*
|
|
119
|
+
* @instance
|
|
120
|
+
* @type {boolean}
|
|
121
|
+
* @protected
|
|
122
|
+
* @memberof ServiceHost
|
|
123
|
+
*/
|
|
124
|
+
this.replaced = false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* If the {@link ServiceHost} is in an active state.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
* @memberof ServiceHost
|
|
132
|
+
* @type {boolean} - `true` if the service is active and usable.
|
|
133
|
+
*/
|
|
134
|
+
get active() {
|
|
135
|
+
// Validate that the `ServiceHost` was not marked as failed or replaced.
|
|
136
|
+
return !this.failed && !this.replaced;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* If the host is local to the user's cluster.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
* @memberof ServiceHost
|
|
144
|
+
* @type {boolean} - If the host is local.
|
|
145
|
+
*/
|
|
146
|
+
get local() {
|
|
147
|
+
return this.default.includes(this.hostGroup);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The service value.
|
|
152
|
+
*
|
|
153
|
+
* @public
|
|
154
|
+
* @memberof ServiceHost
|
|
155
|
+
* @type {string} - The service value.
|
|
156
|
+
*/
|
|
157
|
+
get service() {
|
|
158
|
+
return this.id.split(':')[3];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The formatted url for the host.
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
* @memberof ServiceHost
|
|
166
|
+
* @type {string} - The service url.
|
|
167
|
+
*/
|
|
168
|
+
get url() {
|
|
169
|
+
// Generate a url object from the default url.
|
|
170
|
+
const urlObj = Url.parse(this.default);
|
|
171
|
+
|
|
172
|
+
// Format the host of the generated url object.
|
|
173
|
+
urlObj.host = `${this.uri}${urlObj.port ? `:${urlObj.port}` : ''}`;
|
|
174
|
+
|
|
175
|
+
// Assign the formatted url to this.
|
|
176
|
+
return Url.format(urlObj);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Set one or more of the status properties of the class object.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
* @memberof ServiceHost
|
|
184
|
+
* @param {Object} pto - The parameter transfer object.
|
|
185
|
+
* @property {boolean} [pto.failed] - The failed status to set.
|
|
186
|
+
* @property {boolean} [pto.replaced] - the replaced status to set.
|
|
187
|
+
* @returns {this}
|
|
188
|
+
*/
|
|
189
|
+
setStatus({failed, replaced}) {
|
|
190
|
+
if (failed !== undefined) {
|
|
191
|
+
this.failed = failed;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (replaced !== undefined) {
|
|
195
|
+
this.replaced = replaced;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Generate a service host using only a catalog, name, and URL.
|
|
203
|
+
*
|
|
204
|
+
* @public
|
|
205
|
+
* @static
|
|
206
|
+
* @memberof ServiceHost
|
|
207
|
+
* @param {ServiceHostPolyGeneratePTO} pto
|
|
208
|
+
* @returns {ServiceHost} - The generated service host.
|
|
209
|
+
*/
|
|
210
|
+
static polyGenerate({catalog, name, url}) {
|
|
211
|
+
return new ServiceHost({
|
|
212
|
+
catalog,
|
|
213
|
+
defaultUri: url,
|
|
214
|
+
hostGroup: Url.parse(url).host,
|
|
215
|
+
id: name ? `poly-head:poly-group:poly-cluster:${name}` : undefined,
|
|
216
|
+
priority: 1,
|
|
217
|
+
uri: Url.parse(url).host,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Validate that a constructor parameter transfer object is valid.
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
* @static
|
|
226
|
+
* @memberof ServiceHost
|
|
227
|
+
* @param {ServiceHostConstructorPTO} pto
|
|
228
|
+
* @throws - If the parameter transfer object is not valid.
|
|
229
|
+
* @returns {undefined}
|
|
230
|
+
*/
|
|
231
|
+
static validate({catalog, defaultUri, hostGroup, id, priority, uri}) {
|
|
232
|
+
// Generate error-throwing method.
|
|
233
|
+
const throwError = (msg) => {
|
|
234
|
+
throw new Error(`service-host: invalid constructor parameters, ${msg}`);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Validate the catalog property.
|
|
238
|
+
if (!SERVICE_CATALOGS.includes(catalog)) {
|
|
239
|
+
throwError("'catalog' must be a string");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Validate the `defaultUri` property.
|
|
243
|
+
if (typeof defaultUri !== 'string') {
|
|
244
|
+
throwError("'defaultUri' must be a string");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Validate the `hostGroup` property.
|
|
248
|
+
if (typeof hostGroup !== 'string') {
|
|
249
|
+
throwError("'hostGroup' must be a string");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Validate the `id` property.
|
|
253
|
+
if (typeof id !== 'string' || id.split(':').length !== 4) {
|
|
254
|
+
throwError("'id' must be a string that contains 3 ':' characters");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Validate the `priority` property.
|
|
258
|
+
if (typeof priority !== 'number') {
|
|
259
|
+
throwError("'priority' must be a number");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Validate the `uri` property.
|
|
263
|
+
if (typeof uri !== 'string') {
|
|
264
|
+
throwError("'uri' must be a string");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|