@visulima/health-check 2.0.13 → 2.0.15
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/CHANGELOG.md +59 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +60 -0
- package/dist/index.mjs +1 -10
- package/dist/packem_shared/HealthCheck-CypoYHvz.mjs +1 -0
- package/dist/packem_shared/HealthCheck-DQvQhFYY.cjs +1 -0
- package/dist/packem_shared/dnsCheck-CN6R59pd.cjs +1 -0
- package/dist/packem_shared/dnsCheck-G72qe__U.mjs +1 -0
- package/dist/packem_shared/healthCheckHandler-BH0Fcvsh.cjs +1 -0
- package/dist/packem_shared/healthCheckHandler-BdYk897h.mjs +1 -0
- package/dist/packem_shared/healthReadyHandler-D_Z0BVtR.mjs +1 -0
- package/dist/packem_shared/healthReadyHandler-DjRXCune.cjs +1 -0
- package/dist/packem_shared/httpCheck-BNlBtiV7.mjs +1 -0
- package/dist/packem_shared/httpCheck-DT6HrAPG.cjs +1 -0
- package/dist/packem_shared/nodeEnvCheck-BxNJ8ArD.mjs +1 -0
- package/dist/packem_shared/nodeEnvCheck-aT51eSWt.cjs +1 -0
- package/dist/packem_shared/pingCheck-DIrh3Cwy.cjs +1 -0
- package/dist/packem_shared/pingCheck-DWJlRAgo.mjs +1 -0
- package/package.json +157 -137
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
## @visulima/health-check [2.0.15](https://github.com/visulima/visulima/compare/@visulima/health-check@2.0.14...@visulima/health-check@2.0.15) (2024-09-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **health-check:** moved from tsup to packem ([130ccc2](https://github.com/visulima/visulima/commit/130ccc266ee4a5565dfcdb328f5127228cc10216))
|
|
6
|
+
|
|
7
|
+
### Styles
|
|
8
|
+
|
|
9
|
+
* cs fixes found by eslint and prettier ([69ef744](https://github.com/visulima/visulima/commit/69ef7444c0bfbf1c94763623332e06b7fffc0039))
|
|
10
|
+
* **health-check:** cs fixes ([a0ec83b](https://github.com/visulima/visulima/commit/a0ec83bb2213f24b83a0641583f34eca91d6a1ae))
|
|
11
|
+
|
|
12
|
+
### Miscellaneous Chores
|
|
13
|
+
|
|
14
|
+
* changed typescript version back to 5.4.5 ([55d28bb](https://github.com/visulima/visulima/commit/55d28bbdc103718d19f844034b38a0e8e5af798a))
|
|
15
|
+
* **health-check:** improved tests for health-check ([4d24572](https://github.com/visulima/visulima/commit/4d24572ea3a4ad026ca3965002f29871282c6747))
|
|
16
|
+
* update dev dependencies ([0738f98](https://github.com/visulima/visulima/commit/0738f9810478bb215ce4b2571dc8874c4c503089))
|
|
17
|
+
* updated all dev deps ([ef143ce](https://github.com/visulima/visulima/commit/ef143ce2e15952a0910aa5c8bd78d25de9ebd7f3))
|
|
18
|
+
* updated dev dependencies ([28b5ee5](https://github.com/visulima/visulima/commit/28b5ee5c805ca8868536418829cde7ba8c5bb8dd))
|
|
19
|
+
* updated dev dependencies ([45c2a76](https://github.com/visulima/visulima/commit/45c2a76bc974ecb2c6b172c3af03373d4cc6a5ce))
|
|
20
|
+
* updated dev dependencies ([da46d8e](https://github.com/visulima/visulima/commit/da46d8ef8a964c086060944172f1bd931b7bde9a))
|
|
21
|
+
* updated dev dependencies ([ac67ec1](https://github.com/visulima/visulima/commit/ac67ec1bcba16175d225958e318199f60b10d179))
|
|
22
|
+
* updated dev dependencies ([34df456](https://github.com/visulima/visulima/commit/34df4569f2fc074823a406c44a131c8fbae2b147))
|
|
23
|
+
* updated dev dependencies ([de0f8a6](https://github.com/visulima/visulima/commit/de0f8a6b9030acbc044e5bc0f78091fb1ec89a28))
|
|
24
|
+
* updated dev dependencies and sorted the package.json ([9571572](https://github.com/visulima/visulima/commit/95715725a8ed053ca24fd1405a55205c79342ecb))
|
|
25
|
+
|
|
26
|
+
### Build System
|
|
27
|
+
|
|
28
|
+
* fixed found audit error, updated all dev package deps, updated deps in apps and examples ([4c51950](https://github.com/visulima/visulima/commit/4c519500dc5504579d35725572920658999885cb))
|
|
29
|
+
|
|
30
|
+
## @visulima/health-check [2.0.14](https://github.com/visulima/visulima/compare/@visulima/health-check@2.0.13...@visulima/health-check@2.0.14) (2024-06-06)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* allow node v22 ([890d457](https://github.com/visulima/visulima/commit/890d4570f18428e2463944813c0c638b3f142803))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Styles
|
|
39
|
+
|
|
40
|
+
* cs fixes on some package.json files ([12fc0f7](https://github.com/visulima/visulima/commit/12fc0f74e206cef77863b0b89ec41174ca9ff0bd))
|
|
41
|
+
* disabled noPropertyAccessFromIndexSignature ([#386](https://github.com/visulima/visulima/issues/386)) ([2250c02](https://github.com/visulima/visulima/commit/2250c02b870a5b37d78d01365105a0777c5728e2))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Miscellaneous Chores
|
|
45
|
+
|
|
46
|
+
* changed semantic-release-npm to pnpm ([b6d100a](https://github.com/visulima/visulima/commit/b6d100a2bf3fd026577be48726a37754947f0973))
|
|
47
|
+
* **deps:** updated dev deps ([d91ac38](https://github.com/visulima/visulima/commit/d91ac389cea85a6c6bdc8de97905252a6c467abc))
|
|
48
|
+
* downgrade eslint-plugin-vitest ([0162771](https://github.com/visulima/visulima/commit/0162771e6022e4594486a796bc41e91a2d87bcd8))
|
|
49
|
+
* **health-check:** fixed dns tests ([3214e32](https://github.com/visulima/visulima/commit/3214e32291138b039b1d531c9a6818ecc9850af3))
|
|
50
|
+
* update dev dependencies ([09c4854](https://github.com/visulima/visulima/commit/09c4854e221fa8b808dfe66d7196d8db2a39b366))
|
|
51
|
+
* updated dev dependencies ([a2e0504](https://github.com/visulima/visulima/commit/a2e0504dc239049434c2482756ff15bdbaac9b54))
|
|
52
|
+
* updated dev dependencies ([abd319c](https://github.com/visulima/visulima/commit/abd319c23576aa1dc751ac874e806bddbc977d51))
|
|
53
|
+
* updated dev dependencies ([0767afe](https://github.com/visulima/visulima/commit/0767afe9be83da6698c1343724400171f952599e))
|
|
54
|
+
* updated dev dependencies ([d7791e3](https://github.com/visulima/visulima/commit/d7791e327917e438757636573b1e5549a97bba7b))
|
|
55
|
+
* updated dev dependencies ([6005345](https://github.com/visulima/visulima/commit/60053456717a3889fc77b4fb5b05d50a662475b2))
|
|
56
|
+
* updated dev dependencies ([87dee15](https://github.com/visulima/visulima/commit/87dee156e797b5dee2557a09ad32c935d851847c))
|
|
57
|
+
* updated dev dependencies ([bf2c635](https://github.com/visulima/visulima/commit/bf2c635859601cc97858226e70f47219eabc213e))
|
|
58
|
+
* updated dev dependencies ([f67c7f1](https://github.com/visulima/visulima/commit/f67c7f14ecc328ed91d06d01ac6514e8bce72cb4))
|
|
59
|
+
|
|
1
60
|
## @visulima/health-check [2.0.13](https://github.com/visulima/visulima/compare/@visulima/health-check@2.0.12...@visulima/health-check@2.0.13) (2024-03-27)
|
|
2
61
|
|
|
3
62
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./packem_shared/dnsCheck-CN6R59pd.cjs"),h=require("./packem_shared/httpCheck-DT6HrAPG.cjs"),t=require("./packem_shared/nodeEnvCheck-aT51eSWt.cjs"),r=require("./packem_shared/pingCheck-DIrh3Cwy.cjs"),c=require("./packem_shared/healthCheckHandler-BH0Fcvsh.cjs"),n=require("./packem_shared/healthReadyHandler-DjRXCune.cjs"),a=require("./packem_shared/HealthCheck-DQvQhFYY.cjs");exports.dnsCheck=e;exports.httpCheck=h;exports.nodeEnvCheck=t;exports.pingCheck=r;exports.healthCheckHandler=c;exports.healthReadyHandler=n;exports.HealthCheck=a;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Options } from 'cacheable-lookup';
|
|
2
|
+
import { extendedPingOptions } from 'pingman';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
|
|
5
|
+
interface HealthReportEntry {
|
|
6
|
+
displayName: string;
|
|
7
|
+
health: {
|
|
8
|
+
healthy: boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
};
|
|
12
|
+
meta?: any;
|
|
13
|
+
}
|
|
14
|
+
type Checker = () => Promise<HealthReportEntry>;
|
|
15
|
+
type HealthReport = Record<string, HealthReportEntry>;
|
|
16
|
+
interface HealthCheck {
|
|
17
|
+
addChecker: (service: string, checker: Checker) => void;
|
|
18
|
+
getReport: () => Promise<{
|
|
19
|
+
healthy: boolean;
|
|
20
|
+
report: HealthReport;
|
|
21
|
+
}>;
|
|
22
|
+
isLive: () => Promise<boolean>;
|
|
23
|
+
servicesList: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface DnsOptions extends Options {
|
|
27
|
+
family?: "all" | 4 | 6;
|
|
28
|
+
hints?: number;
|
|
29
|
+
}
|
|
30
|
+
declare const dnsCheck: (host: string, expectedAddresses?: string[], options?: DnsOptions) => Checker;
|
|
31
|
+
|
|
32
|
+
declare const httpCheck: (host: RequestInfo | URL, options?: {
|
|
33
|
+
expected?: {
|
|
34
|
+
body?: string;
|
|
35
|
+
status?: number;
|
|
36
|
+
};
|
|
37
|
+
fetchOptions?: RequestInit;
|
|
38
|
+
}) => Checker;
|
|
39
|
+
|
|
40
|
+
declare const nodeEnvironmentCheck: (expectedEnvironment?: string) => Checker;
|
|
41
|
+
|
|
42
|
+
declare const pingCheck: (host: string, options?: extendedPingOptions) => Checker;
|
|
43
|
+
|
|
44
|
+
declare const _default$1: (healthCheck: HealthCheck, sendHeader?: boolean | undefined) => <Request extends IncomingMessage, Response extends ServerResponse<IncomingMessage>>(_: Request, response: Response) => Promise<void>;
|
|
45
|
+
|
|
46
|
+
declare const _default: <Request extends IncomingMessage, Response extends ServerResponse<IncomingMessage>>(healthCheck: HealthCheck) => (_request: Request, response: Response) => Promise<void>;
|
|
47
|
+
|
|
48
|
+
declare class Healthcheck implements HealthCheck {
|
|
49
|
+
private healthCheckers;
|
|
50
|
+
addChecker(service: string, checker: Checker): void;
|
|
51
|
+
getReport(): Promise<{
|
|
52
|
+
healthy: boolean;
|
|
53
|
+
report: HealthReport;
|
|
54
|
+
}>;
|
|
55
|
+
isLive(): Promise<boolean>;
|
|
56
|
+
get servicesList(): string[];
|
|
57
|
+
private invokeChecker;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { type Checker, Healthcheck as HealthCheck, dnsCheck, _default$1 as healthCheckHandler, _default as healthReadyHandler, httpCheck, nodeEnvironmentCheck as nodeEnvCheck, pingCheck };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { deepStrictEqual } from 'node:assert';
|
|
3
|
-
import R from 'pingman';
|
|
4
|
-
import { StatusCodes } from 'http-status-codes';
|
|
5
|
-
|
|
6
|
-
var p="DNS check for",k=(t,e,a)=>async()=>{let{family:r="all",hints:s,...h}=a??{},m=new g(h);try{let i=await m.lookupAsync(t.replace(/^https?:\/\//,""),{hints:s,...r==="all"?{all:!0}:{family:r}});return Array.isArray(e)&&!e.includes(i.address)?{displayName:`${p} ${t}`,health:{healthy:!1,message:`${p} ${t} returned address ${i.address} instead of ${e.join(", ")}.`,timestamp:new Date().toISOString()},meta:{addresses:i,host:t}}:{displayName:`${p} ${t}`,health:{healthy:!0,message:`${p} ${t} were resolved.`,timestamp:new Date().toISOString()},meta:{addresses:i,host:t}}}catch(i){return {displayName:`${p} ${t}`,health:{healthy:!1,message:i.message,timestamp:new Date().toISOString()},meta:{host:t}}}},C=k;var l="HTTP check for",O=(t,e)=>async()=>{try{let a=await fetch(t,e?.fetchOptions??{});if(e?.expected?.status!==void 0&&e.expected.status!==a.status)throw new Error(`${l} ${t} returned status ${a.status} instead of ${e.expected.status}`);if(e?.expected?.body!==void 0){let r=await a.text();try{deepStrictEqual(r,e.expected.body);}catch{throw new Error(`${l} ${t} returned body ${JSON.stringify(r)} instead of ${JSON.stringify(e.expected.body)}`)}}return {displayName:`${l} ${t}`,health:{healthy:!0,message:`${l} ${t} was successful.`,timestamp:new Date().toISOString()},meta:{host:t,method:e?.fetchOptions?.method??"GET",status:a.status}}}catch(a){return {displayName:`${l} ${t}`,health:{healthy:!1,message:a.message,timestamp:new Date().toISOString()},meta:{host:t,method:e?.fetchOptions?.method??"GET"}}}},N=O;var y="Node Environment Check",$=t=>async()=>{let e="production",a;return t!==void 0&&e!==t?a=`NODE_ENV environment variable is set to "${e}" instead of "${t}".`:e,a!==void 0?{displayName:y,health:{healthy:!1,message:a,timestamp:new Date().toISOString()}}:{displayName:y,health:{healthy:!0,timestamp:new Date().toISOString()},meta:{env:e}}},E=$;var c="Ping check for",w=(t,e)=>async()=>{try{let a=await R(t.replace(/^https?:\/\//,""),e);return a.alive?{displayName:`${c} ${t}`,health:{healthy:!0,message:`${c} ${t} was successful.`,timestamp:new Date().toISOString()},meta:a}:{displayName:`${c} ${t}`,health:{healthy:!1,message:`Ping failed for ${t}.`,timestamp:new Date().toISOString()},meta:a}}catch(a){return {displayName:`${c} ${t}`,health:{healthy:!1,message:a.message,timestamp:new Date().toISOString()}}}},I=w;var x=(t,e=!0)=>async(a,r)=>{let{healthy:s,report:h}=await t.getReport(),m={appName:process.env.APP_NAME??"unknown",appVersion:process.env.APP_VERSION??"unknown",message:s?"Health check successful":"Health check failed",reports:h,status:s?"ok":"error",timestamp:new Date().toISOString()};r.statusCode=s?StatusCodes.OK:StatusCodes.SERVICE_UNAVAILABLE,e&&r.setHeader("Content-Type","application/json"),r.end(JSON.stringify(m,null,2));};var b=t=>async(e,a)=>{let{healthy:r}=await t.getReport();a.statusCode=r?StatusCodes.NO_CONTENT:StatusCodes.SERVICE_UNAVAILABLE,a.end();};var d=class{healthCheckers={};addChecker(e,a){this.healthCheckers[e]=a;}async getReport(){let e={};return await Promise.all(Object.keys(this.healthCheckers).map(async r=>await this.invokeChecker(r,e))),{healthy:!Object.keys(e).find(r=>!e[r].health.healthy),report:e}}async isLive(){let{healthy:e}=await this.getReport();return e}get servicesList(){return Object.keys(this.healthCheckers)}async invokeChecker(e,a){let r=this.healthCheckers[e],s;try{s=await r(),s.displayName=s.displayName||e;}catch(h){s={displayName:e,health:{healthy:!1,message:h.message,timestamp:new Date().toISOString()},meta:{fatal:!0}};}return a[e]=s,s.health.healthy}},v=d;
|
|
7
|
-
|
|
8
|
-
export { v as HealthCheck, C as dnsCheck, x as healthCheckHandler, b as healthReadyHandler, N as httpCheck, E as nodeEnvCheck, I as pingCheck };
|
|
9
|
-
//# sourceMappingURL=out.js.map
|
|
10
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{default as t}from"./packem_shared/dnsCheck-G72qe__U.mjs";import{default as o}from"./packem_shared/httpCheck-BNlBtiV7.mjs";import{default as d}from"./packem_shared/nodeEnvCheck-BxNJ8ArD.mjs";import{default as l}from"./packem_shared/pingCheck-DWJlRAgo.mjs";import{default as s}from"./packem_shared/healthCheckHandler-BdYk897h.mjs";import{default as u}from"./packem_shared/healthReadyHandler-D_Z0BVtR.mjs";import{default as c}from"./packem_shared/HealthCheck-CypoYHvz.mjs";export{c as HealthCheck,t as dnsCheck,s as healthCheckHandler,u as healthReadyHandler,o as httpCheck,d as nodeEnvCheck,l as pingCheck};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var s=(h,e)=>i(h,"name",{value:e,configurable:!0});var l=Object.defineProperty,n=s((h,e)=>l(h,"name",{value:e,configurable:!0}),"s");class k{static{s(this,"i")}static{n(this,"Healthcheck")}healthCheckers={};addChecker(e,t){this.healthCheckers[e]=t}async getReport(){const e={};return await Promise.all(Object.keys(this.healthCheckers).map(async t=>await this.invokeChecker(t,e))),{healthy:!Object.keys(e).find(t=>!e[t].health.healthy),report:e}}async isLive(){const{healthy:e}=await this.getReport();return e}get servicesList(){return Object.keys(this.healthCheckers)}async invokeChecker(e,t){const r=this.healthCheckers[e];let a;try{a=await r(),a.displayName=a.displayName||e}catch(c){a={displayName:e,health:{healthy:!1,message:c.message,timestamp:new Date().toISOString()},meta:{fatal:!0}}}return t[e]=a,a.health.healthy}}export{k as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var s=(h,e)=>i(h,"name",{value:e,configurable:!0});var l=Object.defineProperty,n=s((h,e)=>l(h,"name",{value:e,configurable:!0}),"s");class y{static{s(this,"i")}static{n(this,"Healthcheck")}healthCheckers={};addChecker(e,t){this.healthCheckers[e]=t}async getReport(){const e={};return await Promise.all(Object.keys(this.healthCheckers).map(async t=>await this.invokeChecker(t,e))),{healthy:!Object.keys(e).find(t=>!e[t].health.healthy),report:e}}async isLive(){const{healthy:e}=await this.getReport();return e}get servicesList(){return Object.keys(this.healthCheckers)}async invokeChecker(e,t){const r=this.healthCheckers[e];let a;try{a=await r(),a.displayName=a.displayName||e}catch(c){a={displayName:e,health:{healthy:!1,message:c.message,timestamp:new Date().toISOString()},meta:{fatal:!0}}}return t[e]=a,a.health.healthy}}module.exports=y;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var r=(e,a)=>c(e,"name",{value:a,configurable:!0});const h=require("cacheable-lookup"),m=r(e=>e&&typeof e=="object"&&"default"in e?e.default:e,"_interopDefaultCompat"),y=m(h);var p=Object.defineProperty,u=r((e,a)=>p(e,"name",{value:a,configurable:!0}),"n");const s="DNS check for",$=u((e,a,l)=>async()=>{const{family:n="all",hints:o,...i}=l??{},d=new y(i);try{const t=await d.lookupAsync(e.replace(/^https?:\/\//,""),{hints:o,...n==="all"?{all:!0}:{family:n}});return Array.isArray(a)&&!a.includes(t.address)?{displayName:`${s} ${e}`,health:{healthy:!1,message:`${s} ${e} returned address ${t.address} instead of ${a.join(", ")}.`,timestamp:new Date().toISOString()},meta:{addresses:t,host:e}}:{displayName:`${s} ${e}`,health:{healthy:!0,message:`${s} ${e} were resolved.`,timestamp:new Date().toISOString()},meta:{addresses:t,host:e}}}catch(t){return{displayName:`${s} ${e}`,health:{healthy:!1,message:t.message,timestamp:new Date().toISOString()},meta:{host:e}}}},"dnsCheck");module.exports=$;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var l=(a,e)=>o(a,"name",{value:e,configurable:!0});import d from"cacheable-lookup";var c=Object.defineProperty,y=l((a,e)=>c(a,"name",{value:e,configurable:!0}),"n");const t="DNS check for",f=y((a,e,n)=>async()=>{const{family:r="all",hints:m,...h}=n??{},i=new d(h);try{const s=await i.lookupAsync(a.replace(/^https?:\/\//,""),{hints:m,...r==="all"?{all:!0}:{family:r}});return Array.isArray(e)&&!e.includes(s.address)?{displayName:`${t} ${a}`,health:{healthy:!1,message:`${t} ${a} returned address ${s.address} instead of ${e.join(", ")}.`,timestamp:new Date().toISOString()},meta:{addresses:s,host:a}}:{displayName:`${t} ${a}`,health:{healthy:!0,message:`${t} ${a} were resolved.`,timestamp:new Date().toISOString()},meta:{addresses:s,host:a}}}catch(s){return{displayName:`${t} ${a}`,health:{healthy:!1,message:s.message,timestamp:new Date().toISOString()},meta:{host:a}}}},"dnsCheck");export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});const o=require("http-status-codes");var u=Object.defineProperty,i=n((e,t)=>u(e,"name",{value:t,configurable:!0}),"a");const l=i((e,t=!0)=>async(h,s)=>{const{healthy:a,report:r}=await e.getReport(),c={appName:process.env.APP_NAME??"unknown",appVersion:process.env.APP_VERSION??"unknown",message:a?"Health check successful":"Health check failed",reports:r,status:a?"ok":"error",timestamp:new Date().toISOString()};s.statusCode=a?o.StatusCodes.OK:o.StatusCodes.SERVICE_UNAVAILABLE,t&&s.setHeader("Content-Type","application/json"),s.end(JSON.stringify(c,null,2))},"default");module.exports=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var o=(e,t)=>p(e,"name",{value:t,configurable:!0});import{StatusCodes as r}from"http-status-codes";var i=Object.defineProperty,l=o((e,t)=>i(e,"name",{value:t,configurable:!0}),"a");const f=l((e,t=!0)=>async(u,a)=>{const{healthy:n,report:s}=await e.getReport(),c={appName:process.env.APP_NAME??"unknown",appVersion:process.env.APP_VERSION??"unknown",message:n?"Health check successful":"Health check failed",reports:s,status:n?"ok":"error",timestamp:new Date().toISOString()};a.statusCode=n?r.OK:r.SERVICE_UNAVAILABLE,t&&a.setHeader("Content-Type","application/json"),a.end(JSON.stringify(c,null,2))},"default");export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=Object.defineProperty;var r=(e,t)=>n(e,"name",{value:t,configurable:!0});import{StatusCodes as o}from"http-status-codes";var s=Object.defineProperty,l=r((e,t)=>s(e,"name",{value:t,configurable:!0}),"o");const f=l(e=>async(t,a)=>{const{healthy:d}=await e.getReport();a.statusCode=d?o.NO_CONTENT:o.SERVICE_UNAVAILABLE,a.end()},"default");export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var s=(t,e)=>d(t,"name",{value:e,configurable:!0});const r=require("http-status-codes");var n=Object.defineProperty,u=s((t,e)=>n(t,"name",{value:e,configurable:!0}),"o");const c=u(t=>async(e,a)=>{const{healthy:o}=await t.getReport();a.statusCode=o?r.StatusCodes.NO_CONTENT:r.StatusCodes.SERVICE_UNAVAILABLE,a.end()},"default");module.exports=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var o=(e,t)=>c(e,"name",{value:t,configurable:!0});import{deepStrictEqual as d}from"node:assert";var i=Object.defineProperty,h=o((e,t)=>i(e,"name",{value:t,configurable:!0}),"c");const a="HTTP check for",p=h((e,t)=>async()=>{try{const s=await fetch(e,t?.fetchOptions??{});if(t?.expected?.status!==void 0&&t.expected.status!==s.status)throw new Error(`${a} ${e} returned status ${s.status} instead of ${t.expected.status}`);if(t?.expected?.body!==void 0){const r=await s.text();try{d(r,t.expected.body)}catch{throw new Error(`${a} ${e} returned body ${JSON.stringify(r)} instead of ${JSON.stringify(t.expected.body)}`)}}return{displayName:`${a} ${e}`,health:{healthy:!0,message:`${a} ${e} was successful.`,timestamp:new Date().toISOString()},meta:{host:e,method:t?.fetchOptions?.method??"GET",status:s.status}}}catch(s){return{displayName:`${a} ${e}`,health:{healthy:!1,message:s.message,timestamp:new Date().toISOString()},meta:{host:e,method:t?.fetchOptions?.method??"GET"}}}},"httpCheck");export{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var o=(e,t)=>c(e,"name",{value:t,configurable:!0});const i=require("node:assert");var d=Object.defineProperty,n=o((e,t)=>d(e,"name",{value:t,configurable:!0}),"c");const a="HTTP check for",h=n((e,t)=>async()=>{try{const s=await fetch(e,t?.fetchOptions??{});if(t?.expected?.status!==void 0&&t.expected.status!==s.status)throw new Error(`${a} ${e} returned status ${s.status} instead of ${t.expected.status}`);if(t?.expected?.body!==void 0){const r=await s.text();try{i.deepStrictEqual(r,t.expected.body)}catch{throw new Error(`${a} ${e} returned body ${JSON.stringify(r)} instead of ${JSON.stringify(t.expected.body)}`)}}return{displayName:`${a} ${e}`,health:{healthy:!0,message:`${a} ${e} was successful.`,timestamp:new Date().toISOString()},meta:{host:e,method:t?.fetchOptions?.method??"GET",status:s.status}}}catch(s){return{displayName:`${a} ${e}`,health:{healthy:!1,message:s.message,timestamp:new Date().toISOString()},meta:{host:e,method:t?.fetchOptions?.method??"GET"}}}},"httpCheck");module.exports=h;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var n=(t,e)=>o(t,"name",{value:e,configurable:!0});var r=Object.defineProperty,s=n((t,e)=>r(t,"name",{value:e,configurable:!0}),"i");const i="Node Environment Check",l=s(t=>async()=>{const e="production";let a;return t!==void 0&&e!==t&&(a=`NODE_ENV environment variable is set to "${e}" instead of "${t}".`),a!==void 0?{displayName:i,health:{healthy:!1,message:a,timestamp:new Date().toISOString()}}:{displayName:i,health:{healthy:!0,timestamp:new Date().toISOString()},meta:{env:e}}},"nodeEnvironmentCheck");export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var n=(t,e)=>o(t,"name",{value:e,configurable:!0});var r=Object.defineProperty,s=n((t,e)=>r(t,"name",{value:e,configurable:!0}),"i");const i="Node Environment Check",m=s(t=>async()=>{const e="production";let a;return t!==void 0&&e!==t&&(a=`NODE_ENV environment variable is set to "${e}" instead of "${t}".`),a!==void 0?{displayName:i,health:{healthy:!1,message:a,timestamp:new Date().toISOString()}}:{displayName:i,health:{healthy:!0,timestamp:new Date().toISOString()},meta:{env:e}}},"nodeEnvironmentCheck");module.exports=m;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var i=(t,e)=>n(t,"name",{value:e,configurable:!0});const r=require("pingman"),l=i(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),c=l(r);var m=Object.defineProperty,o=i((t,e)=>m(t,"name",{value:e,configurable:!0}),"n");const s="Ping check for",h=o((t,e)=>async()=>{try{const a=await c(t.replace(/^https?:\/\//,""),e);return a.alive?{displayName:`${s} ${t}`,health:{healthy:!0,message:`${s} ${t} was successful.`,timestamp:new Date().toISOString()},meta:a}:{displayName:`${s} ${t}`,health:{healthy:!1,message:`Ping failed for ${t}.`,timestamp:new Date().toISOString()},meta:a}}catch(a){return{displayName:`${s} ${t}`,health:{healthy:!1,message:a.message,timestamp:new Date().toISOString()}}}},"pingCheck");module.exports=h;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var i=(e,a)=>m(e,"name",{value:a,configurable:!0});import r from"pingman";var n=Object.defineProperty,h=i((e,a)=>n(e,"name",{value:a,configurable:!0}),"n");const s="Ping check for",o=h((e,a)=>async()=>{try{const t=await r(e.replace(/^https?:\/\//,""),a);return t.alive?{displayName:`${s} ${e}`,health:{healthy:!0,message:`${s} ${e} was successful.`,timestamp:new Date().toISOString()},meta:t}:{displayName:`${s} ${e}`,health:{healthy:!1,message:`Ping failed for ${e}.`,timestamp:new Date().toISOString()},meta:t}}catch(t){return{displayName:`${s} ${e}`,health:{healthy:!1,message:t.message,timestamp:new Date().toISOString()}}}},"pingCheck");export{o as default};
|
package/package.json
CHANGED
|
@@ -1,141 +1,161 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"name": "@visulima/health-check",
|
|
3
|
+
"version": "2.0.15",
|
|
4
|
+
"description": "A library built to provide support for defining service health for node services. It allows you to register async health checks for your dependencies and the service itself, provides a health endpoint that exposes their status, and health metrics.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"anolilab",
|
|
7
|
+
"visulima",
|
|
8
|
+
"blitz",
|
|
9
|
+
"blitzjs",
|
|
10
|
+
"nextjs",
|
|
11
|
+
"health",
|
|
12
|
+
"check",
|
|
13
|
+
"checks",
|
|
14
|
+
"dns-check",
|
|
15
|
+
"http-check",
|
|
16
|
+
"ping-check"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://www.visulima.com/docs/package/health-check",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/visulima/visulima.git",
|
|
22
|
+
"directory": "packages/health-check"
|
|
23
|
+
},
|
|
24
|
+
"funding": [
|
|
25
|
+
{
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/prisis"
|
|
23
28
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"import": {
|
|
47
|
-
"types": "./dist/index.d.mts",
|
|
48
|
-
"default": "./dist/index.mjs"
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"./package.json": "./package.json"
|
|
52
|
-
},
|
|
53
|
-
"main": "dist/index.js",
|
|
54
|
-
"module": "dist/index.mjs",
|
|
55
|
-
"source": "src/index.ts",
|
|
56
|
-
"types": "dist/index.d.ts",
|
|
57
|
-
"files": [
|
|
58
|
-
"dist/**",
|
|
59
|
-
"README.md",
|
|
60
|
-
"CHANGELOG.md",
|
|
61
|
-
"LICENSE.md"
|
|
62
|
-
],
|
|
63
|
-
"scripts": {
|
|
64
|
-
"build": "cross-env NODE_ENV=development tsup",
|
|
65
|
-
"build:prod": "cross-env NODE_ENV=production tsup",
|
|
66
|
-
"clean": "rimraf node_modules dist .eslintcache",
|
|
67
|
-
"dev": "pnpm run build --watch",
|
|
68
|
-
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js",
|
|
69
|
-
"lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js --fix",
|
|
70
|
-
"lint:packagejson": "publint --strict",
|
|
71
|
-
"lint:prettier": "prettier --config=.prettierrc.js --check .",
|
|
72
|
-
"lint:prettier:fix": "prettier --config=.prettierrc.js --write .",
|
|
73
|
-
"lint:types": "tsc --noEmit",
|
|
74
|
-
"test": "vitest run",
|
|
75
|
-
"test:coverage": "vitest run --coverage",
|
|
76
|
-
"test:ui": "vitest --ui --coverage.enabled=true",
|
|
77
|
-
"test:watch": "vitest"
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"cacheable-lookup": "^7.0.0",
|
|
81
|
-
"http-status-codes": "^2.3.0",
|
|
82
|
-
"pingman": "^2.0.0"
|
|
83
|
-
},
|
|
84
|
-
"devDependencies": {
|
|
85
|
-
"@anolilab/eslint-config": "^15.0.3",
|
|
86
|
-
"@anolilab/prettier-config": "^5.0.14",
|
|
87
|
-
"@anolilab/semantic-release-preset": "^8.0.3",
|
|
88
|
-
"@babel/core": "^7.24.3",
|
|
89
|
-
"@rushstack/eslint-plugin-security": "^0.8.1",
|
|
90
|
-
"@types/node": "18.18.14",
|
|
91
|
-
"@vitest/coverage-v8": "^1.4.0",
|
|
92
|
-
"@vitest/ui": "^1.4.0",
|
|
93
|
-
"cross-env": "^7.0.3",
|
|
94
|
-
"cross-fetch": "^4.0.0",
|
|
95
|
-
"eslint": "^8.57.0",
|
|
96
|
-
"eslint-plugin-deprecation": "^2.0.0",
|
|
97
|
-
"eslint-plugin-etc": "^2.0.3",
|
|
98
|
-
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
|
99
|
-
"eslint-plugin-mdx": "^3.1.5",
|
|
100
|
-
"eslint-plugin-vitest": "^0.3.26",
|
|
101
|
-
"eslint-plugin-vitest-globals": "^1.5.0",
|
|
102
|
-
"next": "^13.5.6",
|
|
103
|
-
"node-mocks-http": "^1.14.1",
|
|
104
|
-
"prettier": "^3.2.5",
|
|
105
|
-
"react": "^18.2.0",
|
|
106
|
-
"react-dom": "^18.2.0",
|
|
107
|
-
"rimraf": "^5.0.5",
|
|
108
|
-
"semantic-release": "^23.0.5",
|
|
109
|
-
"sort-package-json": "^2.8.0",
|
|
110
|
-
"tsup": "^8.0.2",
|
|
111
|
-
"typescript": "^5.4.3",
|
|
112
|
-
"vitest": "^1.4.0"
|
|
113
|
-
},
|
|
114
|
-
"optionalDependencies": {
|
|
115
|
-
"next": "^13.5.6"
|
|
116
|
-
},
|
|
117
|
-
"engines": {
|
|
118
|
-
"node": ">=18.* <=21.*"
|
|
119
|
-
},
|
|
120
|
-
"os": [
|
|
121
|
-
"darwin",
|
|
122
|
-
"linux",
|
|
123
|
-
"win32"
|
|
124
|
-
],
|
|
125
|
-
"publishConfig": {
|
|
126
|
-
"access": "public",
|
|
127
|
-
"provenance": true
|
|
29
|
+
{
|
|
30
|
+
"type": "consulting",
|
|
31
|
+
"url": "https://anolilab.com/support"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"author": {
|
|
36
|
+
"name": "Daniel Bannert",
|
|
37
|
+
"email": "d.bannert@anolilab.de"
|
|
38
|
+
},
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"type": "module",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/index.d.cts",
|
|
45
|
+
"default": "./dist/index.cjs"
|
|
46
|
+
},
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/index.d.mts",
|
|
49
|
+
"default": "./dist/index.mjs"
|
|
50
|
+
}
|
|
128
51
|
},
|
|
129
|
-
"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
54
|
+
"main": "dist/index.cjs",
|
|
55
|
+
"module": "dist/index.mjs",
|
|
56
|
+
"types": "dist/index.d.ts",
|
|
57
|
+
"typesVersions": {
|
|
58
|
+
">=5.0": {
|
|
59
|
+
".": [
|
|
60
|
+
"./dist/index.d.ts"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist/**",
|
|
66
|
+
"README.md",
|
|
67
|
+
"CHANGELOG.md",
|
|
68
|
+
"LICENSE.md"
|
|
69
|
+
],
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"cacheable-lookup": "^7.0.0",
|
|
72
|
+
"http-status-codes": "^2.3.0",
|
|
73
|
+
"pingman": "^2.0.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@anolilab/eslint-config": "^15.0.3",
|
|
77
|
+
"@anolilab/prettier-config": "^5.0.14",
|
|
78
|
+
"@anolilab/semantic-release-pnpm": "^1.1.3",
|
|
79
|
+
"@anolilab/semantic-release-preset": "^9.0.0",
|
|
80
|
+
"@arethetypeswrong/cli": "^0.16.2",
|
|
81
|
+
"@arthurgeron/eslint-plugin-react-usememo": "^2.4.1",
|
|
82
|
+
"@babel/core": "^7.25.2",
|
|
83
|
+
"@rushstack/eslint-plugin-security": "^0.8.2",
|
|
84
|
+
"@testing-library/react": "^16.0.1",
|
|
85
|
+
"@types/node": "18.19.15",
|
|
86
|
+
"@visulima/packem": "^1.0.0-alpha.108",
|
|
87
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
88
|
+
"@vitest/ui": "^2.0.5",
|
|
89
|
+
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
90
|
+
"cross-env": "^7.0.3",
|
|
91
|
+
"cross-fetch": "^4.0.0",
|
|
92
|
+
"esbuild": "^0.23.1",
|
|
93
|
+
"eslint": "8.57.0",
|
|
94
|
+
"eslint-plugin-deprecation": "^3.0.0",
|
|
95
|
+
"eslint-plugin-etc": "^2.0.3",
|
|
96
|
+
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
|
97
|
+
"eslint-plugin-jsx-a11y": "^6.10.0",
|
|
98
|
+
"eslint-plugin-mdx": "^3.1.5",
|
|
99
|
+
"eslint-plugin-react": "^7.35.2",
|
|
100
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
101
|
+
"eslint-plugin-ssr-friendly": "^1.3.0",
|
|
102
|
+
"eslint-plugin-testing-library": "^6.3.0",
|
|
103
|
+
"eslint-plugin-validate-jsx-nesting": "^0.1.1",
|
|
104
|
+
"eslint-plugin-vitest": "^0.4.1",
|
|
105
|
+
"eslint-plugin-vitest-globals": "^1.5.0",
|
|
106
|
+
"msw": "^2.4.5",
|
|
107
|
+
"next": "^14.2.4",
|
|
108
|
+
"node-mocks-http": "^1.16.0",
|
|
109
|
+
"prettier": "^3.3.3",
|
|
110
|
+
"react": "^18.3.1",
|
|
111
|
+
"react-dom": "^18.3.1",
|
|
112
|
+
"rimraf": "5.0.9",
|
|
113
|
+
"semantic-release": "24.0.0",
|
|
114
|
+
"typescript": "5.4.5",
|
|
115
|
+
"vitest": "^2.0.5"
|
|
116
|
+
},
|
|
117
|
+
"optionalDependencies": {
|
|
118
|
+
"next": "^14.2.4"
|
|
119
|
+
},
|
|
120
|
+
"engines": {
|
|
121
|
+
"node": ">=18.* <=22.*"
|
|
122
|
+
},
|
|
123
|
+
"os": [
|
|
124
|
+
"darwin",
|
|
125
|
+
"linux",
|
|
126
|
+
"win32"
|
|
127
|
+
],
|
|
128
|
+
"publishConfig": {
|
|
129
|
+
"access": "public",
|
|
130
|
+
"provenance": true
|
|
131
|
+
},
|
|
132
|
+
"anolilab": {
|
|
133
|
+
"eslint-config": {
|
|
134
|
+
"plugin": {
|
|
135
|
+
"tsdoc": false
|
|
136
|
+
},
|
|
137
|
+
"warn_on_unsupported_typescript_version": false,
|
|
138
|
+
"info_on_disabling_jsx_react_rule": false,
|
|
139
|
+
"info_on_disabling_prettier_conflict_rule": false,
|
|
140
|
+
"info_on_disabling_jsonc_sort_keys_rule": false,
|
|
141
|
+
"info_on_disabling_etc_no_deprecated": false
|
|
140
142
|
}
|
|
141
|
-
}
|
|
143
|
+
},
|
|
144
|
+
"scripts": {
|
|
145
|
+
"build": "cross-env NODE_ENV=development packem build",
|
|
146
|
+
"build:prod": "cross-env NODE_ENV=production packem build",
|
|
147
|
+
"clean": "rimraf node_modules dist .eslintcache",
|
|
148
|
+
"dev": "pnpm run build --watch",
|
|
149
|
+
"lint:attw": "attw --pack",
|
|
150
|
+
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js",
|
|
151
|
+
"lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js --fix",
|
|
152
|
+
"lint:package-json": "publint --strict",
|
|
153
|
+
"lint:prettier": "prettier --config=.prettierrc.js --check .",
|
|
154
|
+
"lint:prettier:fix": "prettier --config=.prettierrc.js --write .",
|
|
155
|
+
"lint:types": "tsc --noEmit",
|
|
156
|
+
"test": "vitest run",
|
|
157
|
+
"test:coverage": "vitest run --coverage",
|
|
158
|
+
"test:ui": "vitest --ui --coverage.enabled=true",
|
|
159
|
+
"test:watch": "vitest"
|
|
160
|
+
}
|
|
161
|
+
}
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var u = require('cacheable-lookup');
|
|
4
|
-
var assert = require('assert');
|
|
5
|
-
var E = require('pingman');
|
|
6
|
-
var httpStatusCodes = require('http-status-codes');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var u__default = /*#__PURE__*/_interopDefault(u);
|
|
11
|
-
var E__default = /*#__PURE__*/_interopDefault(E);
|
|
12
|
-
|
|
13
|
-
var h="DNS check for",g=(t,e,a)=>async()=>{let{family:r="all",hints:s,...i}=a??{},c=new u__default.default(i);try{let o=await c.lookupAsync(t.replace(/^https?:\/\//,""),{hints:s,...r==="all"?{all:!0}:{family:r}});return Array.isArray(e)&&!e.includes(o.address)?{displayName:`${h} ${t}`,health:{healthy:!1,message:`${h} ${t} returned address ${o.address} instead of ${e.join(", ")}.`,timestamp:new Date().toISOString()},meta:{addresses:o,host:t}}:{displayName:`${h} ${t}`,health:{healthy:!0,message:`${h} ${t} were resolved.`,timestamp:new Date().toISOString()},meta:{addresses:o,host:t}}}catch(o){return {displayName:`${h} ${t}`,health:{healthy:!1,message:o.message,timestamp:new Date().toISOString()},meta:{host:t}}}},k=g;var p="HTTP check for",S=(t,e)=>async()=>{try{let a=await fetch(t,e?.fetchOptions??{});if(e?.expected?.status!==void 0&&e.expected.status!==a.status)throw new Error(`${p} ${t} returned status ${a.status} instead of ${e.expected.status}`);if(e?.expected?.body!==void 0){let r=await a.text();try{assert.deepStrictEqual(r,e.expected.body);}catch{throw new Error(`${p} ${t} returned body ${JSON.stringify(r)} instead of ${JSON.stringify(e.expected.body)}`)}}return {displayName:`${p} ${t}`,health:{healthy:!0,message:`${p} ${t} was successful.`,timestamp:new Date().toISOString()},meta:{host:t,method:e?.fetchOptions?.method??"GET",status:a.status}}}catch(a){return {displayName:`${p} ${t}`,health:{healthy:!1,message:a.message,timestamp:new Date().toISOString()},meta:{host:t,method:e?.fetchOptions?.method??"GET"}}}},O=S;var d="Node Environment Check",N=t=>async()=>{let e="production",a;return t!==void 0&&e!==t?a=`NODE_ENV environment variable is set to "${e}" instead of "${t}".`:e,a!==void 0?{displayName:d,health:{healthy:!1,message:a,timestamp:new Date().toISOString()}}:{displayName:d,health:{healthy:!0,timestamp:new Date().toISOString()},meta:{env:e}}},$=N;var l="Ping check for",R=(t,e)=>async()=>{try{let a=await E__default.default(t.replace(/^https?:\/\//,""),e);return a.alive?{displayName:`${l} ${t}`,health:{healthy:!0,message:`${l} ${t} was successful.`,timestamp:new Date().toISOString()},meta:a}:{displayName:`${l} ${t}`,health:{healthy:!1,message:`Ping failed for ${t}.`,timestamp:new Date().toISOString()},meta:a}}catch(a){return {displayName:`${l} ${t}`,health:{healthy:!1,message:a.message,timestamp:new Date().toISOString()}}}},w=R;var I=(t,e=!0)=>async(a,r)=>{let{healthy:s,report:i}=await t.getReport(),c={appName:process.env.APP_NAME??"unknown",appVersion:process.env.APP_VERSION??"unknown",message:s?"Health check successful":"Health check failed",reports:i,status:s?"ok":"error",timestamp:new Date().toISOString()};r.statusCode=s?httpStatusCodes.StatusCodes.OK:httpStatusCodes.StatusCodes.SERVICE_UNAVAILABLE,e&&r.setHeader("Content-Type","application/json"),r.end(JSON.stringify(c,null,2));};var x=t=>async(e,a)=>{let{healthy:r}=await t.getReport();a.statusCode=r?httpStatusCodes.StatusCodes.NO_CONTENT:httpStatusCodes.StatusCodes.SERVICE_UNAVAILABLE,a.end();};var m=class{healthCheckers={};addChecker(e,a){this.healthCheckers[e]=a;}async getReport(){let e={};return await Promise.all(Object.keys(this.healthCheckers).map(async r=>await this.invokeChecker(r,e))),{healthy:!Object.keys(e).find(r=>!e[r].health.healthy),report:e}}async isLive(){let{healthy:e}=await this.getReport();return e}get servicesList(){return Object.keys(this.healthCheckers)}async invokeChecker(e,a){let r=this.healthCheckers[e],s;try{s=await r(),s.displayName=s.displayName||e;}catch(i){s={displayName:e,health:{healthy:!1,message:i.message,timestamp:new Date().toISOString()},meta:{fatal:!0}};}return a[e]=s,s.health.healthy}},b=m;
|
|
14
|
-
|
|
15
|
-
exports.HealthCheck = b;
|
|
16
|
-
exports.dnsCheck = k;
|
|
17
|
-
exports.healthCheckHandler = I;
|
|
18
|
-
exports.healthReadyHandler = x;
|
|
19
|
-
exports.httpCheck = O;
|
|
20
|
-
exports.nodeEnvCheck = $;
|
|
21
|
-
exports.pingCheck = w;
|
|
22
|
-
//# sourceMappingURL=out.js.map
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/checks/dns-check.ts","../src/checks/http-check.ts","../src/checks/node-environment-check.ts","../src/checks/ping-check.ts","../src/handler/healthcheck.ts","../src/handler/readyhandler.ts","../src/healthcheck.ts"],"names":["CacheableLookup","DISPLAY_NAME","dnsCheck","host","expectedAddresses","options","family","hints","config","cacheable","meta","error","dns_check_default","deepStrictEqual","httpCheck","response","textBody","http_check_default","nodeEnvironmentCheck","expectedEnvironment","environment","errorMessage","node_environment_check_default","ping","pingCheck","ping_check_default","StatusCodes","healthcheck_default","healthCheck","sendHeader","_","healthy","report","payload","readyhandler_default","_request","Healthcheck","service","checker","reportSheet"],"mappings":"AACA,OAAOA,MAAqB,mBAI5B,IAAMC,EAAe,gBAUfC,EACF,CAACC,EAAcC,EAA8BC,IAC7C,SAAY,CACR,GAAM,CAAE,OAAAC,EAAS,MAAO,MAAAC,EAAO,GAAGC,CAAO,EAAIH,GAAW,CAAC,EAGnDI,EAAY,IAAIT,EAAgBQ,CAAM,EAE5C,GAAI,CAEA,IAAME,EAAoB,MAAMD,EAAU,YAAYN,EAAK,QAAQ,eAAgB,EAAE,EAAG,CACpF,MAAAI,EACA,GAAID,IAAW,MAAQ,CAAE,IAAK,EAAK,EAAI,CAAE,OAAAA,CAAO,CACpD,CAAkB,EAGlB,OAAI,MAAM,QAAQF,CAAiB,GAAK,CAACA,EAAkB,SAASM,EAAK,OAAO,EACrE,CACH,YAAa,GAAGT,CAAY,IAAIE,CAAI,GACpC,OAAQ,CACJ,QAAS,GAET,QAAS,GAAGF,CAAY,IAAIE,CAAI,qBAAqBO,EAAK,OAAO,eAAeN,EAAkB,KAAK,IAAI,CAAC,IAC5G,UAAW,IAAI,KAAK,EAAE,YAAY,CACtC,EACA,KAAM,CAEF,UAAWM,EACX,KAAAP,CACJ,CACJ,EAGG,CACH,YAAa,GAAGF,CAAY,IAAIE,CAAI,GACpC,OAAQ,CACJ,QAAS,GACT,QAAS,GAAGF,CAAY,IAAIE,CAAI,kBAChC,UAAW,IAAI,KAAK,EAAE,YAAY,CACtC,EACA,KAAM,CAEF,UAAWO,EACX,KAAAP,CACJ,CACJ,CACJ,OAASQ,EAAO,CACZ,MAAO,CACH,YAAa,GAAGV,CAAY,IAAIE,CAAI,GACpC,OAAQ,CAC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IAAW,cAAyB,CAChC,OAAO,OAAO,KAAK,KAAK,cAAc,CAC1C,CAKA,MAAc,cAAcM,EAAiBE,EAA6C,CAEtF,IAAMD,EAAU,KAAK,eAAeD,CAAO,EAEvCL,EAEJ,GAAI,CACAA,EAAS,MAAMM,EAAQ,EAEvBN,EAAO,YAAcA,EAAO,aAAeK,CAC/C,OAAS1B,EAAO,CACZqB,EAAS,CACL,YAAaK,EACb,OAAQ,CAAE,QAAS,GAAO,QAAU1B,EAAgB,QAAS,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EACjG,KAAM,CAAE,MAAO,EAAK,CACxB,CACJ,CAGA,OAAA4B,EAAYF,CAAO,EAAIL,EAEhBA,EAAO,OAAO,OACzB,CACJ,EAEOL,EAAQS","sourcesContent":["import type { EntryObject, LookupOptions, Options } from \"cacheable-lookup\";\nimport CacheableLookup from \"cacheable-lookup\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"DNS check for\";\n\ninterface DnsOptions extends Options {\n family?: \"all\" | 4 | 6;\n hints?: number;\n}\n\n/**\n * Register the `dns` checker to ensure that a domain is reachable.\n */\nconst dnsCheck =\n (host: string, expectedAddresses?: string[], options?: DnsOptions): Checker =>\n async () => {\n const { family = \"all\", hints, ...config } = options ?? {};\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment\n const cacheable = new CacheableLookup(config);\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment\n const meta: EntryObject = await cacheable.lookupAsync(host.replace(/^https?:\\/\\//, \"\"), {\n hints,\n ...(family === \"all\" ? { all: true } : { family }),\n } as LookupOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument\n if (Array.isArray(expectedAddresses) && !expectedAddresses.includes(meta.address)) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n message: `${DISPLAY_NAME} ${host} returned address ${meta.address} instead of ${expectedAddresses.join(\", \")}.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n addresses: meta,\n host,\n },\n };\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host} were resolved.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n addresses: meta,\n host,\n },\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n },\n };\n }\n };\n\nexport default dnsCheck;\n","import { deepStrictEqual } from \"node:assert\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"HTTP check for\";\n\n/**\n * Register the `http` checker to ensure http body and status is correct.\n */\nconst httpCheck =\n (\n host: RequestInfo | URL,\n options?: {\n expected?: { body?: string; status?: number };\n fetchOptions?: RequestInit;\n },\n ): Checker =>\n async () => {\n try {\n // eslint-disable-next-line compat/compat\n const response = await fetch(host, options?.fetchOptions ?? {});\n\n if (options?.expected?.status !== undefined && options.expected.status !== response.status) {\n throw new Error(`${DISPLAY_NAME} ${host as string} returned status ${response.status} instead of ${options.expected.status}`);\n }\n\n if (options?.expected?.body !== undefined) {\n const textBody = await response.text();\n\n try {\n deepStrictEqual(textBody, options.expected.body);\n } catch {\n throw new Error(\n `${DISPLAY_NAME} ${host as string} returned body ${JSON.stringify(textBody)} instead of ${JSON.stringify(options.expected.body)}`,\n );\n }\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host as string}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host as string} was successful.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n method: options?.fetchOptions?.method ?? \"GET\",\n status: response.status,\n },\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host as string}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n method: options?.fetchOptions?.method ?? \"GET\",\n },\n };\n }\n };\n\nexport default httpCheck;\n","import type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"Node Environment Check\";\n\n/**\n * Register the `env` checker to ensure that `NODE_ENV` environment\n * variable is defined.\n */\nconst nodeEnvironmentCheck =\n (expectedEnvironment?: string): Checker =>\n async () => {\n const environment: string | undefined = process.env[\"NODE_ENV\"];\n\n let errorMessage: string | undefined;\n\n if (environment !== undefined && expectedEnvironment !== undefined && environment !== expectedEnvironment) {\n errorMessage = `NODE_ENV environment variable is set to \"${environment}\" instead of \"${expectedEnvironment}\".`;\n } else if (!environment) {\n errorMessage = [\"Missing NODE_ENV environment variable.\", \"It can make some parts of the application misbehave\"].join(\" \");\n }\n\n if (errorMessage !== undefined) {\n return {\n displayName: DISPLAY_NAME,\n health: {\n healthy: false,\n message: errorMessage,\n timestamp: new Date().toISOString(),\n },\n };\n }\n\n return {\n displayName: DISPLAY_NAME,\n health: {\n healthy: true,\n timestamp: new Date().toISOString(),\n },\n meta: {\n env: environment,\n },\n };\n };\n\nexport default nodeEnvironmentCheck;\n","import type { extendedPingOptions } from \"pingman\";\nimport ping from \"pingman\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"Ping check for\";\n\n/**\n * Register the `ping` checker to ensure that a domain is reachable.\n */\nconst pingCheck =\n (host: string, options?: extendedPingOptions): Checker =>\n async () => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call\n const response = await ping(host.replace(/^https?:\\/\\//, \"\"), options);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (!response.alive) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: `Ping failed for ${host}.`,\n timestamp: new Date().toISOString(),\n },\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n meta: response,\n };\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host} was successful.`,\n timestamp: new Date().toISOString(),\n },\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n meta: response,\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n };\n }\n };\n\nexport default pingCheck;\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport { StatusCodes } from \"http-status-codes\";\n\nimport type { HealthCheck, HealthReport } from \"../types\";\n\nexport interface HealthCheckApiPayload {\n appName: string;\n appVersion: string;\n message: string;\n reports: HealthReport;\n status: \"error\" | \"ok\";\n timestamp: string;\n}\n\nexport default (healthCheck: HealthCheck, sendHeader: boolean | undefined = true) =>\n async <Request extends IncomingMessage, Response extends ServerResponse>(_: Request, response: Response): Promise<void> => {\n const { healthy, report } = await healthCheck.getReport();\n\n const payload: HealthCheckApiPayload = {\n appName: process.env[\"APP_NAME\"] ?? \"unknown\",\n appVersion: process.env[\"APP_VERSION\"] ?? \"unknown\",\n message: healthy ? \"Health check successful\" : \"Health check failed\",\n reports: report,\n status: healthy ? \"ok\" : \"error\",\n timestamp: new Date().toISOString(),\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n response.statusCode = healthy ? StatusCodes.OK : StatusCodes.SERVICE_UNAVAILABLE;\n\n if (sendHeader) {\n response.setHeader(\"Content-Type\", \"application/json\");\n }\n\n response.end(JSON.stringify(payload, null, 2));\n };\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport { StatusCodes } from \"http-status-codes\";\n\nimport type { HealthCheck } from \"../types\";\n\nexport default <Request extends IncomingMessage, Response extends ServerResponse>(healthCheck: HealthCheck) =>\n async (_request: Request, response: Response): Promise<void> => {\n const { healthy } = await healthCheck.getReport();\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment\n response.statusCode = healthy ? StatusCodes.NO_CONTENT : StatusCodes.SERVICE_UNAVAILABLE;\n response.end();\n };\n","import type { Checker, HealthCheck as HealthcheckInterface, HealthReport, HealthReportEntry } from \"./types\";\n\nclass Healthcheck implements HealthcheckInterface {\n /**\n * A copy of registered checkers\n */\n private healthCheckers: Record<string, Checker> = {};\n\n public addChecker(service: string, checker: Checker): void {\n // eslint-disable-next-line security/detect-object-injection\n this.healthCheckers[service] = checker;\n }\n\n /**\n * Returns the health check reports. The health checks are performed when\n * this method is invoked.\n */\n public async getReport(): Promise<{ healthy: boolean; report: HealthReport }> {\n const report: HealthReport = {};\n\n // eslint-disable-next-line compat/compat\n await Promise.all(Object.keys(this.healthCheckers).map(async (service) => await this.invokeChecker(service, report)));\n\n /**\n * Finding unhealthy service to know if system is healthy or not\n */\n // eslint-disable-next-line security/detect-object-injection\n const unhealthyService = Object.keys(report).find((service) => !(report[service] as HealthReportEntry).health.healthy);\n\n return { healthy: !unhealthyService, report };\n }\n\n public async isLive(): Promise<boolean> {\n const { healthy } = await this.getReport();\n\n return healthy;\n }\n\n /**\n * Returns an array of registered services names\n */\n public get servicesList(): string[] {\n return Object.keys(this.healthCheckers);\n }\n\n /**\n * Invokes a given checker to collect the report metrics.\n */\n private async invokeChecker(service: string, reportSheet: HealthReport): Promise<boolean> {\n // eslint-disable-next-line security/detect-object-injection\n const checker = this.healthCheckers[service] as Checker;\n\n let report: HealthReportEntry;\n\n try {\n report = await checker();\n\n report.displayName = report.displayName || service;\n } catch (error) {\n report = {\n displayName: service,\n health: { healthy: false, message: (error as Error).message, timestamp: new Date().toISOString() },\n meta: { fatal: true },\n };\n }\n\n // eslint-disable-next-line no-param-reassign,security/detect-object-injection\n reportSheet[service] = report;\n\n return report.health.healthy;\n }\n}\n\nexport default Healthcheck;\n"]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/checks/dns-check.ts","../src/checks/http-check.ts","../src/checks/node-environment-check.ts","../src/checks/ping-check.ts","../src/handler/healthcheck.ts","../src/handler/readyhandler.ts","../src/healthcheck.ts"],"names":["CacheableLookup","DISPLAY_NAME","dnsCheck","host","expectedAddresses","options","family","hints","config","cacheable","meta","error","dns_check_default","deepStrictEqual","httpCheck","response","textBody","http_check_default","nodeEnvironmentCheck","expectedEnvironment","environment","errorMessage","node_environment_check_default","ping","pingCheck","ping_check_default","StatusCodes","healthcheck_default","healthCheck","sendHeader","_","healthy","report","payload","readyhandler_default","_request","Healthcheck","service","checker","reportSheet"],"mappings":"AACA,OAAOA,MAAqB,mBAI5B,IAAMC,EAAe,gBAUfC,EACF,CAACC,EAAcC,EAA8BC,IAC7C,SAAY,CACR,GAAM,CAAE,OAAAC,EAAS,MAAO,MAAAC,EAAO,GAAGC,CAAO,EAAIH,GAAW,CAAC,EAGnDI,EAAY,IAAIT,EAAgBQ,CAAM,EAE5C,GAAI,CAEA,IAAME,EAAoB,MAAMD,EAAU,YAAYN,EAAK,QAAQ,eAAgB,EAAE,EAAG,CACpF,MAAAI,EACA,GAAID,IAAW,MAAQ,CAAE,IAAK,EAAK,EAAI,CAAE,OAAAA,CAAO,CACpD,CAAkB,EAGlB,OAAI,MAAM,QAAQF,CAAiB,GAAK,CAACA,EAAkB,SAASM,EAAK,OAAO,EACrE,CACH,YAAa,GAAGT,CAAY,IAAIE,CAAI,GACpC,OAAQ,CACJ,QAAS,GAET,QAAS,GAAGF,CAAY,IAAIE,CAAI,qBAAqBO,EAAK,OAAO,eAAeN,EAAkB,KAAK,IAAI,CAAC,IAC5G,UAAW,IAAI,KAAK,EAAE,YAAY,CACtC,EACA,KAAM,CAEF,UAAWM,EACX,KAAAP,CACJ,CACJ,EAGG,CACH,YAAa,GAAGF,CAAY,IAAI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M,CAAC,CAAC,EAQ7G,CAAE,QAAS,CAFO,OAAO,KAAKA,CAAM,EAAE,KAAMK,GAAY,CAAEL,EAAOK,CAAO,EAAwB,OAAO,OAAO,EAEhF,OAAAL,CAAO,CAChD,CAEA,MAAa,QAA2B,CACpC,GAAM,CAAE,QAAAD,CAAQ,EAAI,MAAM,KAAK,UAAU,EAEzC,OAAOA,CACX,CAKA,IAAW,cAAyB,CAChC,OAAO,OAAO,KAAK,KAAK,cAAc,CAC1C,CAKA,MAAc,cAAcM,EAAiBE,EAA6C,CAEtF,IAAMD,EAAU,KAAK,eAAeD,CAAO,EAEvCL,EAEJ,GAAI,CACAA,EAAS,MAAMM,EAAQ,EAEvBN,EAAO,YAAcA,EAAO,aAAeK,CAC/C,OAAS1B,EAAO,CACZqB,EAAS,CACL,YAAaK,EACb,OAAQ,CAAE,QAAS,GAAO,QAAU1B,EAAgB,QAAS,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EACjG,KAAM,CAAE,MAAO,EAAK,CACxB,CACJ,CAGA,OAAA4B,EAAYF,CAAO,EAAIL,EAEhBA,EAAO,OAAO,OACzB,CACJ,EAEOL,EAAQS","sourcesContent":["import type { EntryObject, LookupOptions, Options } from \"cacheable-lookup\";\nimport CacheableLookup from \"cacheable-lookup\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"DNS check for\";\n\ninterface DnsOptions extends Options {\n family?: \"all\" | 4 | 6;\n hints?: number;\n}\n\n/**\n * Register the `dns` checker to ensure that a domain is reachable.\n */\nconst dnsCheck =\n (host: string, expectedAddresses?: string[], options?: DnsOptions): Checker =>\n async () => {\n const { family = \"all\", hints, ...config } = options ?? {};\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment\n const cacheable = new CacheableLookup(config);\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment\n const meta: EntryObject = await cacheable.lookupAsync(host.replace(/^https?:\\/\\//, \"\"), {\n hints,\n ...(family === \"all\" ? { all: true } : { family }),\n } as LookupOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument\n if (Array.isArray(expectedAddresses) && !expectedAddresses.includes(meta.address)) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n message: `${DISPLAY_NAME} ${host} returned address ${meta.address} instead of ${expectedAddresses.join(\", \")}.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n addresses: meta,\n host,\n },\n };\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host} were resolved.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n addresses: meta,\n host,\n },\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n },\n };\n }\n };\n\nexport default dnsCheck;\n","import { deepStrictEqual } from \"node:assert\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"HTTP check for\";\n\n/**\n * Register the `http` checker to ensure http body and status is correct.\n */\nconst httpCheck =\n (\n host: RequestInfo | URL,\n options?: {\n expected?: { body?: string; status?: number };\n fetchOptions?: RequestInit;\n },\n ): Checker =>\n async () => {\n try {\n // eslint-disable-next-line compat/compat\n const response = await fetch(host, options?.fetchOptions ?? {});\n\n if (options?.expected?.status !== undefined && options.expected.status !== response.status) {\n throw new Error(`${DISPLAY_NAME} ${host as string} returned status ${response.status} instead of ${options.expected.status}`);\n }\n\n if (options?.expected?.body !== undefined) {\n const textBody = await response.text();\n\n try {\n deepStrictEqual(textBody, options.expected.body);\n } catch {\n throw new Error(\n `${DISPLAY_NAME} ${host as string} returned body ${JSON.stringify(textBody)} instead of ${JSON.stringify(options.expected.body)}`,\n );\n }\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host as string}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host as string} was successful.`,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n method: options?.fetchOptions?.method ?? \"GET\",\n status: response.status,\n },\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host as string}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n meta: {\n host,\n method: options?.fetchOptions?.method ?? \"GET\",\n },\n };\n }\n };\n\nexport default httpCheck;\n","import type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"Node Environment Check\";\n\n/**\n * Register the `env` checker to ensure that `NODE_ENV` environment\n * variable is defined.\n */\nconst nodeEnvironmentCheck =\n (expectedEnvironment?: string): Checker =>\n async () => {\n const environment: string | undefined = process.env[\"NODE_ENV\"];\n\n let errorMessage: string | undefined;\n\n if (environment !== undefined && expectedEnvironment !== undefined && environment !== expectedEnvironment) {\n errorMessage = `NODE_ENV environment variable is set to \"${environment}\" instead of \"${expectedEnvironment}\".`;\n } else if (!environment) {\n errorMessage = [\"Missing NODE_ENV environment variable.\", \"It can make some parts of the application misbehave\"].join(\" \");\n }\n\n if (errorMessage !== undefined) {\n return {\n displayName: DISPLAY_NAME,\n health: {\n healthy: false,\n message: errorMessage,\n timestamp: new Date().toISOString(),\n },\n };\n }\n\n return {\n displayName: DISPLAY_NAME,\n health: {\n healthy: true,\n timestamp: new Date().toISOString(),\n },\n meta: {\n env: environment,\n },\n };\n };\n\nexport default nodeEnvironmentCheck;\n","import type { extendedPingOptions } from \"pingman\";\nimport ping from \"pingman\";\n\nimport type { Checker } from \"../types\";\n\nconst DISPLAY_NAME = \"Ping check for\";\n\n/**\n * Register the `ping` checker to ensure that a domain is reachable.\n */\nconst pingCheck =\n (host: string, options?: extendedPingOptions): Checker =>\n async () => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call\n const response = await ping(host.replace(/^https?:\\/\\//, \"\"), options);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (!response.alive) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: `Ping failed for ${host}.`,\n timestamp: new Date().toISOString(),\n },\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n meta: response,\n };\n }\n\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: true,\n message: `${DISPLAY_NAME} ${host} was successful.`,\n timestamp: new Date().toISOString(),\n },\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n meta: response,\n };\n } catch (error) {\n return {\n displayName: `${DISPLAY_NAME} ${host}`,\n health: {\n healthy: false,\n message: (error as Error).message,\n timestamp: new Date().toISOString(),\n },\n };\n }\n };\n\nexport default pingCheck;\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport { StatusCodes } from \"http-status-codes\";\n\nimport type { HealthCheck, HealthReport } from \"../types\";\n\nexport interface HealthCheckApiPayload {\n appName: string;\n appVersion: string;\n message: string;\n reports: HealthReport;\n status: \"error\" | \"ok\";\n timestamp: string;\n}\n\nexport default (healthCheck: HealthCheck, sendHeader: boolean | undefined = true) =>\n async <Request extends IncomingMessage, Response extends ServerResponse>(_: Request, response: Response): Promise<void> => {\n const { healthy, report } = await healthCheck.getReport();\n\n const payload: HealthCheckApiPayload = {\n appName: process.env[\"APP_NAME\"] ?? \"unknown\",\n appVersion: process.env[\"APP_VERSION\"] ?? \"unknown\",\n message: healthy ? \"Health check successful\" : \"Health check failed\",\n reports: report,\n status: healthy ? \"ok\" : \"error\",\n timestamp: new Date().toISOString(),\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n response.statusCode = healthy ? StatusCodes.OK : StatusCodes.SERVICE_UNAVAILABLE;\n\n if (sendHeader) {\n response.setHeader(\"Content-Type\", \"application/json\");\n }\n\n response.end(JSON.stringify(payload, null, 2));\n };\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport { StatusCodes } from \"http-status-codes\";\n\nimport type { HealthCheck } from \"../types\";\n\nexport default <Request extends IncomingMessage, Response extends ServerResponse>(healthCheck: HealthCheck) =>\n async (_request: Request, response: Response): Promise<void> => {\n const { healthy } = await healthCheck.getReport();\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment\n response.statusCode = healthy ? StatusCodes.NO_CONTENT : StatusCodes.SERVICE_UNAVAILABLE;\n response.end();\n };\n","import type { Checker, HealthCheck as HealthcheckInterface, HealthReport, HealthReportEntry } from \"./types\";\n\nclass Healthcheck implements HealthcheckInterface {\n /**\n * A copy of registered checkers\n */\n private healthCheckers: Record<string, Checker> = {};\n\n public addChecker(service: string, checker: Checker): void {\n // eslint-disable-next-line security/detect-object-injection\n this.healthCheckers[service] = checker;\n }\n\n /**\n * Returns the health check reports. The health checks are performed when\n * this method is invoked.\n */\n public async getReport(): Promise<{ healthy: boolean; report: HealthReport }> {\n const report: HealthReport = {};\n\n // eslint-disable-next-line compat/compat\n await Promise.all(Object.keys(this.healthCheckers).map(async (service) => await this.invokeChecker(service, report)));\n\n /**\n * Finding unhealthy service to know if system is healthy or not\n */\n // eslint-disable-next-line security/detect-object-injection\n const unhealthyService = Object.keys(report).find((service) => !(report[service] as HealthReportEntry).health.healthy);\n\n return { healthy: !unhealthyService, report };\n }\n\n public async isLive(): Promise<boolean> {\n const { healthy } = await this.getReport();\n\n return healthy;\n }\n\n /**\n * Returns an array of registered services names\n */\n public get servicesList(): string[] {\n return Object.keys(this.healthCheckers);\n }\n\n /**\n * Invokes a given checker to collect the report metrics.\n */\n private async invokeChecker(service: string, reportSheet: HealthReport): Promise<boolean> {\n // eslint-disable-next-line security/detect-object-injection\n const checker = this.healthCheckers[service] as Checker;\n\n let report: HealthReportEntry;\n\n try {\n report = await checker();\n\n report.displayName = report.displayName || service;\n } catch (error) {\n report = {\n displayName: service,\n health: { healthy: false, message: (error as Error).message, timestamp: new Date().toISOString() },\n meta: { fatal: true },\n };\n }\n\n // eslint-disable-next-line no-param-reassign,security/detect-object-injection\n reportSheet[service] = report;\n\n return report.health.healthy;\n }\n}\n\nexport default Healthcheck;\n"]}
|