@webex/webex-core 3.0.0-beta.2 → 3.0.0-beta.21
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/config.js +1 -11
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +44 -64
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js +0 -76
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +22 -55
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js +0 -20
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js +0 -21
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/network-timing.js +2 -21
- package/dist/interceptors/network-timing.js.map +1 -1
- package/dist/interceptors/payload-transformer.js +2 -22
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +25 -57
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js +4 -33
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js +3 -30
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js +1 -30
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/request-timing.js +3 -22
- package/dist/interceptors/request-timing.js.map +1 -1
- package/dist/interceptors/response-logger.js +2 -31
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js +2 -29
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-tracking-id.js +5 -28
- package/dist/interceptors/webex-tracking-id.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js +5 -38
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +3 -51
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +39 -119
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js +0 -49
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/index.js +1 -13
- package/dist/lib/credentials/index.js.map +1 -1
- package/dist/lib/credentials/scope.js +1 -7
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js +1 -7
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +39 -118
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +13 -26
- package/dist/lib/page.js.map +1 -1
- package/dist/lib/services/constants.js +0 -2
- package/dist/lib/services/constants.js.map +1 -1
- package/dist/lib/services/index.js +1 -28
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/server-error.js +2 -23
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +12 -34
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js +0 -2
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js +10 -90
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js +0 -2
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +47 -62
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js +78 -90
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js +3 -15
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js +4 -25
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +122 -238
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js +5 -28
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js +19 -62
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/errors.js +0 -23
- package/dist/lib/storage/errors.js.map +1 -1
- package/dist/lib/storage/index.js +2 -16
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js +11 -41
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js +8 -30
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js +1 -19
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js +9 -29
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js +1 -31
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js +9 -29
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js +6 -40
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +3 -17
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +79 -203
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js +0 -10
- package/dist/webex-internal-core.js.map +1 -1
- package/package.json +14 -14
- package/src/config.js +9 -11
- package/src/credentials-config.js +110 -72
- package/src/index.js +4 -14
- package/src/interceptors/auth.js +36 -37
- package/src/interceptors/default-options.js +0 -1
- package/src/interceptors/embargo.js +1 -1
- package/src/interceptors/payload-transformer.js +1 -2
- package/src/interceptors/rate-limit.js +8 -5
- package/src/interceptors/redirect.js +14 -8
- package/src/interceptors/request-event.js +4 -8
- package/src/interceptors/request-logger.js +8 -5
- package/src/interceptors/response-logger.js +11 -8
- package/src/interceptors/user-agent.js +1 -2
- package/src/interceptors/webex-user-agent.js +3 -9
- package/src/lib/batcher.js +70 -69
- package/src/lib/credentials/credentials.js +112 -122
- package/src/lib/credentials/grant-errors.js +6 -7
- package/src/lib/credentials/index.js +1 -4
- package/src/lib/credentials/scope.js +1 -4
- package/src/lib/credentials/token-collection.js +1 -1
- package/src/lib/credentials/token.js +86 -80
- package/src/lib/page.js +10 -11
- package/src/lib/services/constants.js +3 -13
- package/src/lib/services/index.js +2 -2
- package/src/lib/services/interceptors/server-error.js +12 -7
- package/src/lib/services/interceptors/service.js +6 -5
- package/src/lib/services/metrics.js +1 -1
- package/src/lib/services/service-catalog.js +110 -100
- package/src/lib/services/service-fed-ramp.js +1 -2
- package/src/lib/services/service-host.js +10 -17
- package/src/lib/services/service-registry.js +69 -96
- package/src/lib/services/service-state.js +4 -6
- package/src/lib/services/service-url.js +24 -23
- package/src/lib/services/services.js +260 -251
- package/src/lib/stateless-webex-plugin.js +4 -2
- package/src/lib/storage/decorators.js +68 -66
- package/src/lib/storage/index.js +4 -6
- package/src/lib/storage/make-webex-plugin-store.js +34 -21
- package/src/lib/storage/make-webex-store.js +6 -7
- package/src/lib/storage/memory-store-adapter.js +3 -3
- package/src/lib/webex-core-plugin-mixin.js +10 -7
- package/src/lib/webex-http-error.js +7 -8
- package/src/lib/webex-internal-core-plugin-mixin.js +9 -6
- package/src/lib/webex-plugin.js +41 -34
- package/src/plugins/logger.js +8 -3
- package/src/webex-core.js +185 -116
- package/src/webex-internal-core.js +15 -9
- package/test/integration/spec/credentials/credentials.js +26 -30
- package/test/integration/spec/credentials/token.js +36 -33
- package/test/integration/spec/services/service-catalog.js +177 -156
- package/test/integration/spec/services/services.js +313 -304
- package/test/integration/spec/webex-core.js +98 -86
- package/test/unit/spec/_setup.js +26 -18
- package/test/unit/spec/credentials/credentials.js +189 -154
- package/test/unit/spec/credentials/token.js +94 -76
- package/test/unit/spec/interceptors/auth.js +291 -243
- package/test/unit/spec/interceptors/default-options.js +36 -24
- package/test/unit/spec/interceptors/embargo.js +32 -27
- package/test/unit/spec/interceptors/network-timing.js +2 -2
- package/test/unit/spec/interceptors/payload-transformer.js +61 -52
- package/test/unit/spec/interceptors/rate-limit.js +104 -75
- package/test/unit/spec/interceptors/redirect.js +22 -20
- package/test/unit/spec/interceptors/request-timing.js +18 -22
- package/test/unit/spec/interceptors/user-agent.js +28 -16
- package/test/unit/spec/interceptors/webex-tracking-id.js +14 -8
- package/test/unit/spec/interceptors/webex-user-agent.js +83 -37
- package/test/unit/spec/lib/batcher.js +36 -32
- package/test/unit/spec/lib/page.js +36 -32
- package/test/unit/spec/lib/webex-plugin.js +1 -1
- package/test/unit/spec/services/interceptors/server-error.js +67 -90
- package/test/unit/spec/services/interceptors/service.js +17 -28
- package/test/unit/spec/services/service-catalog.js +19 -27
- package/test/unit/spec/services/service-host.js +29 -26
- package/test/unit/spec/services/service-registry.js +128 -170
- package/test/unit/spec/services/service-state.js +13 -22
- package/test/unit/spec/services/service-url.js +24 -43
- package/test/unit/spec/services/services.js +85 -41
- package/test/unit/spec/storage/persist.js +6 -9
- package/test/unit/spec/storage/wait-for-value.js +22 -21
- package/test/unit/spec/webex-core.js +78 -57
- package/test/unit/spec/webex-internal-core.js +56 -31
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
14
|
-
|
|
15
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
16
|
-
|
|
17
11
|
var _constants = require("./constants");
|
|
18
|
-
|
|
19
12
|
/**
|
|
20
13
|
* The state of a specific catalog to be used by {@link ServiceState}.
|
|
21
14
|
*
|
|
@@ -23,7 +16,6 @@ var _constants = require("./constants");
|
|
|
23
16
|
* @property {boolean} CatalogState.collecting - If the catalog is collecting.
|
|
24
17
|
* @property {boolean} CatalogState.ready - If the catalog is ready.
|
|
25
18
|
*/
|
|
26
|
-
|
|
27
19
|
/**
|
|
28
20
|
* @class
|
|
29
21
|
* @classdesc - Manages the state of the service catalogs for a webex instance.
|
|
@@ -38,14 +30,13 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
38
30
|
*/
|
|
39
31
|
function ServiceState() {
|
|
40
32
|
var _this = this;
|
|
41
|
-
|
|
42
33
|
(0, _classCallCheck2.default)(this, ServiceState);
|
|
43
|
-
|
|
44
34
|
// Iterate over the possible catalog names and generate their states.
|
|
45
35
|
_constants.SERVICE_CATALOGS.forEach(function (catalog) {
|
|
46
36
|
_this[catalog] = ServiceState.generateCatalogState();
|
|
47
37
|
});
|
|
48
38
|
}
|
|
39
|
+
|
|
49
40
|
/**
|
|
50
41
|
* Set a catalog to be collecting or not.
|
|
51
42
|
*
|
|
@@ -55,8 +46,6 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
55
46
|
* @param {boolean} collecting - If the target is collecting or not.
|
|
56
47
|
* @returns {undefined}
|
|
57
48
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
49
|
(0, _createClass2.default)(ServiceState, [{
|
|
61
50
|
key: "setCollecting",
|
|
62
51
|
value: function setCollecting(catalog, collecting) {
|
|
@@ -66,6 +55,7 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
66
55
|
this[catalog].collecting = collecting;
|
|
67
56
|
}
|
|
68
57
|
}
|
|
58
|
+
|
|
69
59
|
/**
|
|
70
60
|
* Set a catalog to be ready or not.
|
|
71
61
|
*
|
|
@@ -75,7 +65,6 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
75
65
|
* @param {boolean} ready - If the target is ready or not.
|
|
76
66
|
* @returns {undefined}
|
|
77
67
|
*/
|
|
78
|
-
|
|
79
68
|
}, {
|
|
80
69
|
key: "setReady",
|
|
81
70
|
value: function setReady(catalog, ready) {
|
|
@@ -85,6 +74,7 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
85
74
|
this[catalog].ready = ready;
|
|
86
75
|
}
|
|
87
76
|
}
|
|
77
|
+
|
|
88
78
|
/**
|
|
89
79
|
* Generate a {@link CatalogState}.
|
|
90
80
|
*
|
|
@@ -93,7 +83,6 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
93
83
|
* @memberof ServiceState
|
|
94
84
|
* @returns {CatalogState} - The generated {@link CatalogState}.
|
|
95
85
|
*/
|
|
96
|
-
|
|
97
86
|
}], [{
|
|
98
87
|
key: "generateCatalogState",
|
|
99
88
|
value: function generateCatalogState() {
|
|
@@ -105,6 +94,5 @@ var ServiceState = /*#__PURE__*/function () {
|
|
|
105
94
|
}]);
|
|
106
95
|
return ServiceState;
|
|
107
96
|
}();
|
|
108
|
-
|
|
109
97
|
exports.default = ServiceState;
|
|
110
98
|
//# sourceMappingURL=service-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ServiceState","SERVICE_CATALOGS","forEach","catalog","generateCatalogState","collecting","ready"],"sources":["service-state.js"],"sourcesContent":["import {SERVICE_CATALOGS} from './constants';\n\n/**\n * The state of a specific catalog to be used by {@link ServiceState}.\n *\n * @typedef {Record<string, boolean>} CatalogState\n * @property {boolean} CatalogState.collecting - If the catalog is collecting.\n * @property {boolean} CatalogState.ready - If the catalog is ready.\n */\n\n/**\n * @class\n * @classdesc - Manages the state of the service catalogs for a webex instance.\n */\nexport default class ServiceState {\n /**\n * Generate a new {@link ServiceState}.\n *\n * @public\n * @constructor\n * @memberof ServiceState\n */\n constructor() {\n // Iterate over the possible catalog names and generate their states.\n SERVICE_CATALOGS.forEach(
|
|
1
|
+
{"version":3,"names":["ServiceState","SERVICE_CATALOGS","forEach","catalog","generateCatalogState","collecting","ready"],"sources":["service-state.js"],"sourcesContent":["import {SERVICE_CATALOGS} from './constants';\n\n/**\n * The state of a specific catalog to be used by {@link ServiceState}.\n *\n * @typedef {Record<string, boolean>} CatalogState\n * @property {boolean} CatalogState.collecting - If the catalog is collecting.\n * @property {boolean} CatalogState.ready - If the catalog is ready.\n */\n\n/**\n * @class\n * @classdesc - Manages the state of the service catalogs for a webex instance.\n */\nexport default class ServiceState {\n /**\n * Generate a new {@link ServiceState}.\n *\n * @public\n * @constructor\n * @memberof ServiceState\n */\n constructor() {\n // Iterate over the possible catalog names and generate their states.\n SERVICE_CATALOGS.forEach((catalog) => {\n this[catalog] = ServiceState.generateCatalogState();\n });\n }\n\n /**\n * Set a catalog to be collecting or not.\n *\n * @public\n * @memberof ServiceState\n * @param {string} catalog - Catalog to target.\n * @param {boolean} collecting - If the target is collecting or not.\n * @returns {undefined}\n */\n setCollecting(catalog, collecting) {\n // Validate that the catalog state exists.\n if (this[catalog]) {\n // Set the 'collecting' status of the catalog state.\n this[catalog].collecting = collecting;\n }\n }\n\n /**\n * Set a catalog to be ready or not.\n *\n * @public\n * @memberof ServiceState\n * @param {string} catalog - Catalog to target.\n * @param {boolean} ready - If the target is ready or not.\n * @returns {undefined}\n */\n setReady(catalog, ready) {\n // Validate that the catalog state exists.\n if (this[catalog]) {\n // Set the 'ready' status of the catalog state.\n this[catalog].ready = ready;\n }\n }\n\n /**\n * Generate a {@link CatalogState}.\n *\n * @public\n * @static\n * @memberof ServiceState\n * @returns {CatalogState} - The generated {@link CatalogState}.\n */\n static generateCatalogState() {\n return {\n collecting: false,\n ready: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAHA,IAIqBA,YAAY;EAC/B;AACF;AACA;AACA;AACA;AACA;AACA;EACE,wBAAc;IAAA;IAAA;IACZ;IACAC,2BAAgB,CAACC,OAAO,CAAC,UAACC,OAAO,EAAK;MACpC,KAAI,CAACA,OAAO,CAAC,GAAGH,YAAY,CAACI,oBAAoB,EAAE;IACrD,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EARE;IAAA;IAAA,OASA,uBAAcD,OAAO,EAAEE,UAAU,EAAE;MACjC;MACA,IAAI,IAAI,CAACF,OAAO,CAAC,EAAE;QACjB;QACA,IAAI,CAACA,OAAO,CAAC,CAACE,UAAU,GAAGA,UAAU;MACvC;IACF;;IAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EARE;IAAA;IAAA,OASA,kBAASF,OAAO,EAAEG,KAAK,EAAE;MACvB;MACA,IAAI,IAAI,CAACH,OAAO,CAAC,EAAE;QACjB;QACA,IAAI,CAACA,OAAO,CAAC,CAACG,KAAK,GAAGA,KAAK;MAC7B;IACF;;IAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EAPE;IAAA;IAAA,OAQA,gCAA8B;MAC5B,OAAO;QACLD,UAAU,EAAE,KAAK;QACjBC,KAAK,EAAE;MACT,CAAC;IACH;EAAC;EAAA;AAAA;AAAA"}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _url = _interopRequireDefault(require("url"));
|
|
14
|
-
|
|
15
10
|
var _ampersandState = _interopRequireDefault(require("ampersand-state"));
|
|
16
|
-
|
|
17
11
|
/* eslint-disable no-underscore-dangle */
|
|
18
|
-
|
|
19
12
|
/**
|
|
20
13
|
* @class
|
|
21
14
|
*/
|
|
@@ -28,7 +21,6 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
28
21
|
}],
|
|
29
22
|
name: ['string', true, undefined]
|
|
30
23
|
},
|
|
31
|
-
|
|
32
24
|
/**
|
|
33
25
|
* Generate a host url based on the host
|
|
34
26
|
* uri provided.
|
|
@@ -36,14 +28,13 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
36
28
|
* @returns {string}
|
|
37
29
|
*/
|
|
38
30
|
_generateHostUrl: function _generateHostUrl(hostUri) {
|
|
39
|
-
var url = _url.default.parse(this.defaultUrl);
|
|
40
|
-
// a string literal instead.
|
|
41
|
-
|
|
31
|
+
var url = _url.default.parse(this.defaultUrl);
|
|
42
32
|
|
|
33
|
+
// setting url.hostname will not apply during Url.format(), set host via
|
|
34
|
+
// a string literal instead.
|
|
43
35
|
url.host = "".concat(hostUri).concat(url.port ? ":".concat(url.port) : '');
|
|
44
36
|
return _url.default.format(url);
|
|
45
37
|
},
|
|
46
|
-
|
|
47
38
|
/**
|
|
48
39
|
* Generate a list of urls based on this
|
|
49
40
|
* `ServiceUrl`'s known hosts.
|
|
@@ -51,7 +42,6 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
51
42
|
*/
|
|
52
43
|
_getHostUrls: function _getHostUrls() {
|
|
53
44
|
var _this = this;
|
|
54
|
-
|
|
55
45
|
return this.hosts.map(function (host) {
|
|
56
46
|
return {
|
|
57
47
|
url: _this._generateHostUrl(host.host),
|
|
@@ -59,7 +49,6 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
59
49
|
};
|
|
60
50
|
});
|
|
61
51
|
},
|
|
62
|
-
|
|
63
52
|
/**
|
|
64
53
|
* Get the current host url with the highest priority. If a clusterId is not
|
|
65
54
|
* provided, this will only return a URL with a filtered host that has the
|
|
@@ -72,7 +61,6 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
72
61
|
if (this.hosts.length === 0) {
|
|
73
62
|
return this.defaultUrl;
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
var filteredHosts = clusterId ? this.hosts.filter(function (host) {
|
|
77
65
|
return host.id === clusterId;
|
|
78
66
|
}) : this.hosts.filter(function (host) {
|
|
@@ -90,7 +78,6 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
90
78
|
return previous.priority > current.priority || !previous.homeCluster ? current : previous;
|
|
91
79
|
}, {}).host);
|
|
92
80
|
},
|
|
93
|
-
|
|
94
81
|
/**
|
|
95
82
|
* Attempt to mark a host from this `ServiceUrl` as failed and return true
|
|
96
83
|
* if the provided url has a host that could be successfully marked as failed.
|
|
@@ -102,21 +89,16 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
102
89
|
if (url === this.defaultUrl) {
|
|
103
90
|
return true;
|
|
104
91
|
}
|
|
105
|
-
|
|
106
92
|
var _Url$parse = _url.default.parse(url),
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
hostname = _Url$parse.hostname;
|
|
109
94
|
var foundHost = this.hosts.find(function (hostObj) {
|
|
110
95
|
return hostObj.host === hostname;
|
|
111
96
|
});
|
|
112
|
-
|
|
113
97
|
if (foundHost) {
|
|
114
98
|
foundHost.failed = true;
|
|
115
99
|
}
|
|
116
|
-
|
|
117
100
|
return foundHost !== undefined;
|
|
118
101
|
},
|
|
119
|
-
|
|
120
102
|
/**
|
|
121
103
|
* Get the current `defaultUrl` or generate a url using the host with the
|
|
122
104
|
* highest priority via host rendering.
|
|
@@ -129,13 +111,10 @@ var ServiceUrl = _ampersandState.default.extend({
|
|
|
129
111
|
if (!priorityHost) {
|
|
130
112
|
return this.defaultUrl;
|
|
131
113
|
}
|
|
132
|
-
|
|
133
114
|
return this._getPriorityHostUrl(clusterId);
|
|
134
115
|
}
|
|
135
116
|
});
|
|
136
117
|
/* eslint-enable no-underscore-dangle */
|
|
137
|
-
|
|
138
|
-
|
|
139
118
|
var _default = ServiceUrl;
|
|
140
119
|
exports.default = _default;
|
|
141
120
|
//# sourceMappingURL=service-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ServiceUrl","AmpState","extend","namespace","props","defaultUrl","undefined","hosts","name","_generateHostUrl","hostUri","url","Url","parse","host","port","format","_getHostUrls","map","priority","_getPriorityHostUrl","clusterId","length","filteredHosts","filter","id","homeCluster","aliveHosts","failed","reduce","previous","current","failHost","hostname","foundHost","find","hostObj","get","priorityHost"],"sources":["service-url.js"],"sourcesContent":["import Url from 'url';\n\nimport AmpState from 'ampersand-state';\n\n/* eslint-disable no-underscore-dangle */\n/**\n * @class\n */\nconst ServiceUrl = AmpState.extend({\n namespace: 'ServiceUrl',\n\n props: {\n defaultUrl: ['string', true, undefined],\n hosts: ['array', false, () =>
|
|
1
|
+
{"version":3,"names":["ServiceUrl","AmpState","extend","namespace","props","defaultUrl","undefined","hosts","name","_generateHostUrl","hostUri","url","Url","parse","host","port","format","_getHostUrls","map","priority","_getPriorityHostUrl","clusterId","length","filteredHosts","filter","id","homeCluster","aliveHosts","failed","reduce","previous","current","failHost","hostname","foundHost","find","hostObj","get","priorityHost"],"sources":["service-url.js"],"sourcesContent":["import Url from 'url';\n\nimport AmpState from 'ampersand-state';\n\n/* eslint-disable no-underscore-dangle */\n/**\n * @class\n */\nconst ServiceUrl = AmpState.extend({\n namespace: 'ServiceUrl',\n\n props: {\n defaultUrl: ['string', true, undefined],\n hosts: ['array', false, () => []],\n name: ['string', true, undefined],\n },\n\n /**\n * Generate a host url based on the host\n * uri provided.\n * @param {string} hostUri\n * @returns {string}\n */\n _generateHostUrl(hostUri) {\n const url = Url.parse(this.defaultUrl);\n\n // setting url.hostname will not apply during Url.format(), set host via\n // a string literal instead.\n url.host = `${hostUri}${url.port ? `:${url.port}` : ''}`;\n\n return Url.format(url);\n },\n\n /**\n * Generate a list of urls based on this\n * `ServiceUrl`'s known hosts.\n * @returns {string[]}\n */\n _getHostUrls() {\n return this.hosts.map((host) => ({\n url: this._generateHostUrl(host.host),\n priority: host.priority,\n }));\n },\n\n /**\n * Get the current host url with the highest priority. If a clusterId is not\n * provided, this will only return a URL with a filtered host that has the\n * `homeCluster` value set to `true`.\n *\n * @param {string} [clusterId] - The clusterId to filter for a priority host.\n * @returns {string} - The priority host url.\n */\n _getPriorityHostUrl(clusterId) {\n if (this.hosts.length === 0) {\n return this.defaultUrl;\n }\n\n let filteredHosts = clusterId\n ? this.hosts.filter((host) => host.id === clusterId)\n : this.hosts.filter((host) => host.homeCluster);\n\n const aliveHosts = filteredHosts.filter((host) => !host.failed);\n\n filteredHosts =\n aliveHosts.length === 0\n ? filteredHosts.map((host) => {\n /* eslint-disable-next-line no-param-reassign */\n host.failed = false;\n\n return host;\n })\n : aliveHosts;\n\n return this._generateHostUrl(\n filteredHosts.reduce(\n (previous, current) =>\n previous.priority > current.priority || !previous.homeCluster ? current : previous,\n {}\n ).host\n );\n },\n\n /**\n * Attempt to mark a host from this `ServiceUrl` as failed and return true\n * if the provided url has a host that could be successfully marked as failed.\n *\n * @param {string} url\n * @returns {boolean}\n */\n failHost(url) {\n if (url === this.defaultUrl) {\n return true;\n }\n\n const {hostname} = Url.parse(url);\n const foundHost = this.hosts.find((hostObj) => hostObj.host === hostname);\n\n if (foundHost) {\n foundHost.failed = true;\n }\n\n return foundHost !== undefined;\n },\n\n /**\n * Get the current `defaultUrl` or generate a url using the host with the\n * highest priority via host rendering.\n *\n * @param {boolean} [priorityHost] - Retrieve the priority host.\n * @param {string} [clusterId] - Cluster to match a host against.\n * @returns {string} - The full service url.\n */\n get(priorityHost, clusterId) {\n if (!priorityHost) {\n return this.defaultUrl;\n }\n\n return this._getPriorityHostUrl(clusterId);\n },\n});\n/* eslint-enable no-underscore-dangle */\n\nexport default ServiceUrl;\n"],"mappings":";;;;;;;;AAAA;AAEA;AAEA;AACA;AACA;AACA;AACA,IAAMA,UAAU,GAAGC,uBAAQ,CAACC,MAAM,CAAC;EACjCC,SAAS,EAAE,YAAY;EAEvBC,KAAK,EAAE;IACLC,UAAU,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAEC,SAAS,CAAC;IACvCC,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE;MAAA,OAAM,EAAE;IAAA,EAAC;IACjCC,IAAI,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAEF,SAAS;EAClC,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEG,gBAAgB,4BAACC,OAAO,EAAE;IACxB,IAAMC,GAAG,GAAGC,YAAG,CAACC,KAAK,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