@magnet.me/consultant
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = health; | ||
| var _nodeFetch = _interopRequireDefault(require("node-fetch")); | ||
| var _properties = _interopRequireDefault(require("./properties")); | ||
| var _consultantError = _interopRequireDefault(require("./consultant-error")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| async function health({ | ||
| service, | ||
| consulHost | ||
| }) { | ||
| consulHost = consulHost || process.env.CONSUL_HOST || _properties.default.defaultHost; | ||
| const uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`; | ||
| let result; | ||
| try { | ||
| result = await (0, _nodeFetch.default)(uri, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'user-agent': _properties.default.userAgent | ||
| } | ||
| }); | ||
| } catch (e) { | ||
| throw new _consultantError.default(`Could not get health for ${service}: ${e}`); | ||
| } | ||
| if (result.ok) { | ||
| return result.json(); | ||
| } | ||
| const body = result.text(); | ||
| throw new _consultantError.default(`Could not get health for ${service}: ${body} (status ${result.status})`); | ||
| } | ||
| //# sourceMappingURL=health.js.map |
| {"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"} |
+1
-1
@@ -27,3 +27,3 @@ declare module "@magnet.me/consultant" { | ||
| consulHost?: string; | ||
| service: ServiceIdentifier; | ||
| service: Service; | ||
| prefix?: string; | ||
@@ -30,0 +30,0 @@ } |
+8
-0
@@ -18,2 +18,8 @@ "use strict"; | ||
| }); | ||
| Object.defineProperty(exports, "health", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _health.default; | ||
| } | ||
| }); | ||
@@ -24,3 +30,5 @@ var _service = _interopRequireDefault(require("./service")); | ||
| var _health = _interopRequireDefault(require("./health")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["import service from './service';\nimport config from './config';\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};\n"],"file":"index.js"} | ||
| {"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"} |
+1
-1
| { | ||
| "name": "@magnet.me/consultant", | ||
| "version": "1.4.1", | ||
| "version": "1.5.0", | ||
| "description": "A library to register services to Consul and listen for property changes.", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = promisify; | ||
| function promisify(func) { | ||
| return new Promise((resolve, reject) => { | ||
| func((err, res) => { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(res); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| //# sourceMappingURL=promisify.js.map |
| {"version":3,"sources":["../src/promisify.js"],"names":["promisify","func","Promise","resolve","reject","err","res"],"mappings":";;;;;;;AAAe,SAASA,SAAT,CAAmBC,IAAnB,EAAyB;AACvC,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACvCH,IAAAA,IAAI,CAAC,CAACI,GAAD,EAAMC,GAAN,KAAc;AAClB,UAAID,GAAJ,EAAS;AACRD,QAAAA,MAAM,CAACC,GAAD,CAAN;AACA,OAFD,MAEO;AACNF,QAAAA,OAAO,CAACG,GAAD,CAAP;AACA;AACD,KANG,CAAJ;AAOA,GARM,CAAP;AASA","sourcesContent":["export default function promisify(func) {\n\treturn new Promise((resolve, reject) => {\n\t\tfunc((err, res) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t});\n\t});\n}\n"],"file":"promisify.js"} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
44745
5.86%417
5.84%8
14.29%4
33.33%