@magnet.me/consultant 1.4.0 → 1.5.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.
- package/out/health.js +42 -0
- package/out/health.js.map +1 -0
- package/out/index.js +8 -0
- package/out/index.js.map +1 -1
- package/package.json +1 -1
package/out/health.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = health;
|
|
7
|
+
|
|
8
|
+
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
9
|
+
|
|
10
|
+
var _properties = _interopRequireDefault(require("./properties"));
|
|
11
|
+
|
|
12
|
+
var _consultantError = _interopRequireDefault(require("./consultant-error"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
async function health({
|
|
17
|
+
service,
|
|
18
|
+
consulHost
|
|
19
|
+
}) {
|
|
20
|
+
consulHost = consulHost || process.env.CONSUL_HOST || _properties.default.defaultHost;
|
|
21
|
+
const uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`;
|
|
22
|
+
let result;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
result = await (0, _nodeFetch.default)(uri, {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
headers: {
|
|
28
|
+
'user-agent': _properties.default.userAgent
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
} catch (e) {
|
|
32
|
+
throw new _consultantError.default(`Could not get health for ${service}: ${e}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (result.ok) {
|
|
36
|
+
return result.json();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const body = result.text();
|
|
40
|
+
throw new _consultantError.default(`Could not get health for ${service}: ${body} (status ${result.status})`);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/health.js"],"names":["health","service","consulHost","process","env","CONSUL_HOST","props","defaultHost","uri","result","method","headers","properties","userAgent","e","ConsultantError","ok","json","body","text","status"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;AAEe,eAAeA,MAAf,CAAsB;AAAEC,EAAAA,OAAF;AAAWC,EAAAA;AAAX,CAAtB,EAA+C;AAC7DA,EAAAA,UAAU,GAAGA,UAAU,IAAIC,OAAO,CAACC,GAAR,CAAYC,WAA1B,IAAyCC,oBAAMC,WAA5D;AACA,QAAMC,GAAG,GAAI,GAAEN,UAAW,sBAAqBD,OAAQ,2BAAvD;AAEA,MAAIQ,MAAJ;;AACA,MAAI;AACHA,IAAAA,MAAM,GAAG,MAAM,wBAAMD,GAAN,EAAW;AACzBE,MAAAA,MAAM,EAAG,KADgB;AAEzBC,MAAAA,OAAO,EAAG;AACT,sBAAeC,oBAAWC;AADjB;AAFe,KAAX,CAAf;AAMA,GAPD,CAQA,OAAOC,CAAP,EAAU;AACT,UAAM,IAAIC,wBAAJ,CAAqB,4BAA2Bd,OAAQ,KAAIa,CAAE,EAA9D,CAAN;AACA;;AAED,MAAIL,MAAM,CAACO,EAAX,EAAe;AACd,WAAOP,MAAM,CAACQ,IAAP,EAAP;AACA;;AACD,QAAMC,IAAI,GAAGT,MAAM,CAACU,IAAP,EAAb;AACA,QAAM,IAAIJ,wBAAJ,CAAqB,4BAA2Bd,OAAQ,KAAIiB,IAAK,YAAWT,MAAM,CAACW,MAAO,GAA1F,CAAN;AACA","sourcesContent":["import fetch from 'node-fetch';\nimport props from './properties';\nimport properties from './properties';\nimport ConsultantError from './consultant-error';\n\nexport default async function health({ service, consulHost }) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || props.defaultHost;\n\tconst uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`;\n\n\tlet result;\n\ttry {\n\t\tresult = await fetch(uri, {\n\t\t\tmethod : 'GET',\n\t\t\theaders : {\n\t\t\t\t'user-agent' : properties.userAgent\n\t\t\t}\n\t\t});\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not get health for ${service}: ${e}`);\n\t}\n\n\tif (result.ok) {\n\t\treturn result.json();\n\t}\n\tconst body = result.text();\n\tthrow new ConsultantError(`Could not get health for ${service}: ${body} (status ${result.status})`);\n}"],"file":"health.js"}
|
package/out/index.js
CHANGED
|
@@ -15,10 +15,18 @@ Object.defineProperty(exports, "config", {
|
|
|
15
15
|
return _config.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "health", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _health.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
|
|
19
25
|
var _service = _interopRequireDefault(require("./service"));
|
|
20
26
|
|
|
21
27
|
var _config = _interopRequireDefault(require("./config"));
|
|
22
28
|
|
|
29
|
+
var _health = _interopRequireDefault(require("./health"));
|
|
30
|
+
|
|
23
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
32
|
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["import service from './service';\nimport config from './config';\nimport health from './health';\n\nexport {\n\t/**\n\t * Registers a service with Consul\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service - The service specific configuration\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {Number} configuration.service.port - The port on which this service runs\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.healthCheckPath] - An optional http path where the health check can be found\n\t * @param {Number} [configuration.healthCheckInterval] - The interval (in seconds) at which the health check is polled. If 0 no health check is done\n\t * @param {string} [configuration.consulHost] - Where Consultant can find a Consul agent\n\t * @return {Promise} An Promise containing the identifier as well as a deregister function\n\t * @return {Object} identifier - The specified service identifier\n\t * @return {function} deregister - Function to deregister the service with its health check from Consul\n\t */\n\tservice,\n\t/**\n\t * Set up the key/value retrieval and polling\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service The service identifier used to validate properties against\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.prefix] - The prefix path that should be before the service name in the key/value store\n\t * @param {Number} [configuration.interval] - The interval (in milliseconds) at which to poll the store. If set to 0, no polling will be done\n\t * @return {Promise} A promise containing the configuration Object\n\t * @return {function} getProperties - Getter to retrieve a copy of the current properties\n\t * @return {function} register - Register a callback that receives the latest properties object any time a change is detected\n\t * @return {function} deregister - Remove a registered callback\n\t * @return {function} stop - Stop the store polling\n\t */\n\tconfig,\n\t/**\n\t * Get the health information for a service\n\t * @function\n\t * @param {Object} configuration\n\t * @param {string} configuration.service The service name to search\n\t * @param {string} configuration.consulHost Where Consultant can find a Consul agent\n\t */\n\thealth\n};\n"],"file":"index.js"}
|