@openstatus/health-nats 0.1.4-dev.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/README.md +70 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/mod.cjs +31 -0
- package/dist/mod.d.cts +24 -0
- package/dist/mod.d.cts.map +1 -0
- package/dist/mod.d.ts +24 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +30 -0
- package/dist/mod.js.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @openstatus/health-nats
|
|
2
|
+
|
|
3
|
+
[NATS](https://nats.io/) probe for
|
|
4
|
+
[`@openstatus/health`](https://jsr.io/@openstatus/health). Flushes a
|
|
5
|
+
`NatsConnection` — one `PING` / `PONG` round trip with the server — and
|
|
6
|
+
fails the check when the server does not answer or the connection has been
|
|
7
|
+
closed.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
deno add jsr:@openstatus/health jsr:@openstatus/health-nats
|
|
11
|
+
npm install @openstatus/health @openstatus/health-nats
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { connect } from "@nats-io/transport-node";
|
|
16
|
+
import { createHealthHandler } from "@openstatus/health";
|
|
17
|
+
import { natsProbe } from "@openstatus/health-nats";
|
|
18
|
+
|
|
19
|
+
const nc = await connect({ servers: env.NATS_URL });
|
|
20
|
+
|
|
21
|
+
Deno.serve(
|
|
22
|
+
createHealthHandler({ probes: [natsProbe({ connection: nc })] }),
|
|
23
|
+
);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Reuse the connection your application already holds: NATS clients keep one
|
|
27
|
+
multiplexed connection per process and reconnect on their own, so the probe
|
|
28
|
+
reports what your publishers and subscribers actually see. While the client
|
|
29
|
+
is reconnecting, `flush()` waits until the server is back — set `timeoutMs`
|
|
30
|
+
to bound that. Any of the official clients works: `@nats-io/transport-node`,
|
|
31
|
+
`@nats-io/transport-deno`, the websocket transport and the legacy `nats`
|
|
32
|
+
package all expose the same `flush()` and `isClosed()`.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
natsProbe({
|
|
36
|
+
connection: nc,
|
|
37
|
+
// optional overrides from the Probe contract
|
|
38
|
+
name: "events",
|
|
39
|
+
critical: true,
|
|
40
|
+
timeoutMs: 1000,
|
|
41
|
+
skip: () => env.NATS_URL == null,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Non-critical by default: messaging usually carries background work, so an
|
|
46
|
+
outage degrades the report instead of taking the service out of rotation.
|
|
47
|
+
Set `critical: true` when requests cannot complete without publishing.
|
|
48
|
+
|
|
49
|
+
The connection is typed structurally as `{ flush(), isClosed?() }`, so the
|
|
50
|
+
NATS packages are optional peer dependencies for their types only and the
|
|
51
|
+
probe adds no runtime import of them. The factory throws `ProbeConfigError`
|
|
52
|
+
at construction when the connection has no `flush()`.
|
|
53
|
+
|
|
54
|
+
## About openstatus
|
|
55
|
+
|
|
56
|
+
[openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
|
|
57
|
+
and status page platform. This package is part of
|
|
58
|
+
[`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
|
|
59
|
+
endpoints behind openstatus's own services, extracted so any JavaScript server
|
|
60
|
+
can expose one. Point an
|
|
61
|
+
[openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
|
|
62
|
+
at the endpoint and assert on `status` in the body to be alerted on
|
|
63
|
+
`degraded` before it becomes `unhealthy`.
|
|
64
|
+
|
|
65
|
+
Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
|
|
66
|
+
Issues and PRs welcome.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
[MIT](https://github.com/openstatusHQ/health/blob/main/LICENSE)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __openstatus_health = require_rolldown_runtime.__toESM(require("@openstatus/health"));
|
|
3
|
+
|
|
4
|
+
//#region src/mod.ts
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
const natsDefaultName = "nats";
|
|
7
|
+
/** A probe that flushes the connection; non-critical by default. Throws `ProbeConfigError` without `flush()`. */
|
|
8
|
+
function natsProbe(options) {
|
|
9
|
+
const connection = options.connection;
|
|
10
|
+
if (typeof connection?.flush !== "function") throw new __openstatus_health.ProbeConfigError("natsProbe", "connection", `must expose flush(), got ${describe(connection)}`);
|
|
11
|
+
return {
|
|
12
|
+
name: options.name ?? natsDefaultName,
|
|
13
|
+
critical: options.critical ?? false,
|
|
14
|
+
timeoutMs: options.timeoutMs,
|
|
15
|
+
skip: options.skip,
|
|
16
|
+
run: async () => {
|
|
17
|
+
if (typeof connection.isClosed === "function" && connection.isClosed()) throw new Error("connection closed");
|
|
18
|
+
await connection.flush();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function describe(connection) {
|
|
23
|
+
if (connection == null) return String(connection);
|
|
24
|
+
if (typeof connection !== "object") return typeof connection;
|
|
25
|
+
const keys = Object.keys(connection);
|
|
26
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.natsDefaultName = natsDefaultName;
|
|
31
|
+
exports.natsProbe = natsProbe;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Probe, ProbeOverrides } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
declare const natsDefaultName = "nats";
|
|
7
|
+
/** The subset of a `NatsConnection` the probe uses. */
|
|
8
|
+
interface NatsLikeConnection {
|
|
9
|
+
/** Resolve once the server has acknowledged everything sent so far. */
|
|
10
|
+
flush(): PromiseLike<void>;
|
|
11
|
+
/** Whether the connection has been closed. */
|
|
12
|
+
isClosed?(): boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Options for `natsProbe()`. */
|
|
15
|
+
interface NatsProbeOptions extends ProbeOverrides {
|
|
16
|
+
/** An open `NatsConnection`. */
|
|
17
|
+
readonly connection: NatsLikeConnection;
|
|
18
|
+
}
|
|
19
|
+
/** A probe that flushes the connection; non-critical by default. Throws `ProbeConfigError` without `flush()`. */
|
|
20
|
+
declare function natsProbe(options: NatsProbeOptions): Probe;
|
|
21
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NatsLikeConnection, NatsProbeOptions, natsDefaultName, natsProbe };
|
|
24
|
+
//# sourceMappingURL=mod.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;cAsBa,eAAA;;UAGI,kBAAA;;WAEN;;;;;UAMM,gBAAA,SAAyB;;uBAEnB;;;iBAIP,SAAA,UAAmB,mBAAmB"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Probe, ProbeOverrides } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
/** Probe name when `name` is unset. */
|
|
6
|
+
declare const natsDefaultName = "nats";
|
|
7
|
+
/** The subset of a `NatsConnection` the probe uses. */
|
|
8
|
+
interface NatsLikeConnection {
|
|
9
|
+
/** Resolve once the server has acknowledged everything sent so far. */
|
|
10
|
+
flush(): PromiseLike<void>;
|
|
11
|
+
/** Whether the connection has been closed. */
|
|
12
|
+
isClosed?(): boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Options for `natsProbe()`. */
|
|
15
|
+
interface NatsProbeOptions extends ProbeOverrides {
|
|
16
|
+
/** An open `NatsConnection`. */
|
|
17
|
+
readonly connection: NatsLikeConnection;
|
|
18
|
+
}
|
|
19
|
+
/** A probe that flushes the connection; non-critical by default. Throws `ProbeConfigError` without `flush()`. */
|
|
20
|
+
declare function natsProbe(options: NatsProbeOptions): Probe;
|
|
21
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NatsLikeConnection, NatsProbeOptions, natsDefaultName, natsProbe };
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;cAsBa,eAAA;;UAGI,kBAAA;;WAEN;;;;;UAMM,gBAAA,SAAyB;;uBAEnB;;;iBAIP,SAAA,UAAmB,mBAAmB"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ProbeConfigError } from "@openstatus/health";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.ts
|
|
4
|
+
/** Probe name when `name` is unset. */
|
|
5
|
+
const natsDefaultName = "nats";
|
|
6
|
+
/** A probe that flushes the connection; non-critical by default. Throws `ProbeConfigError` without `flush()`. */
|
|
7
|
+
function natsProbe(options) {
|
|
8
|
+
const connection = options.connection;
|
|
9
|
+
if (typeof connection?.flush !== "function") throw new ProbeConfigError("natsProbe", "connection", `must expose flush(), got ${describe(connection)}`);
|
|
10
|
+
return {
|
|
11
|
+
name: options.name ?? natsDefaultName,
|
|
12
|
+
critical: options.critical ?? false,
|
|
13
|
+
timeoutMs: options.timeoutMs,
|
|
14
|
+
skip: options.skip,
|
|
15
|
+
run: async () => {
|
|
16
|
+
if (typeof connection.isClosed === "function" && connection.isClosed()) throw new Error("connection closed");
|
|
17
|
+
await connection.flush();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function describe(connection) {
|
|
22
|
+
if (connection == null) return String(connection);
|
|
23
|
+
if (typeof connection !== "object") return typeof connection;
|
|
24
|
+
const keys = Object.keys(connection);
|
|
25
|
+
return keys.length === 0 ? "an object with no keys" : `an object with keys ${keys.slice(0, 8).join(", ")}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { natsDefaultName, natsProbe };
|
|
30
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","names":["options: NatsProbeOptions","connection: NatsLikeConnection"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * NATS probe for `@openstatus/health`: flushes a `NatsConnection`, which\n * round-trips a `PING` / `PONG` with the server.\n *\n * ```ts\n * import { connect } from \"@nats-io/transport-node\";\n * import { natsProbe } from \"@openstatus/health-nats\";\n *\n * const nc = await connect({ servers: env.NATS_URL });\n * const probe = natsProbe({ connection: nc });\n * ```\n *\n * @module\n */\n\nimport {\n type Probe,\n ProbeConfigError,\n type ProbeOverrides,\n} from \"@openstatus/health\";\n\n/** Probe name when `name` is unset. */\nexport const natsDefaultName = \"nats\";\n\n/** The subset of a `NatsConnection` the probe uses. */\nexport interface NatsLikeConnection {\n /** Resolve once the server has acknowledged everything sent so far. */\n flush(): PromiseLike<void>;\n /** Whether the connection has been closed. */\n isClosed?(): boolean;\n}\n\n/** Options for `natsProbe()`. */\nexport interface NatsProbeOptions extends ProbeOverrides {\n /** An open `NatsConnection`. */\n readonly connection: NatsLikeConnection;\n}\n\n/** A probe that flushes the connection; non-critical by default. Throws `ProbeConfigError` without `flush()`. */\nexport function natsProbe(options: NatsProbeOptions): Probe {\n const connection = options.connection;\n if (typeof connection?.flush !== \"function\") {\n throw new ProbeConfigError(\n \"natsProbe\",\n \"connection\",\n `must expose flush(), got ${describe(connection)}`,\n );\n }\n return {\n name: options.name ?? natsDefaultName,\n critical: options.critical ?? false,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: async () => {\n if (typeof connection.isClosed === \"function\" && connection.isClosed()) {\n throw new Error(\"connection closed\");\n }\n await connection.flush();\n },\n };\n}\n\nfunction describe(connection: NatsLikeConnection): string {\n if (connection == null) return String(connection);\n if (typeof connection !== \"object\") return typeof connection;\n const keys = Object.keys(connection);\n return keys.length === 0\n ? \"an object with no keys\"\n : `an object with keys ${keys.slice(0, 8).join(\", \")}`;\n}\n"],"mappings":";;;;AAsBA,MAAa,kBAAkB;;AAiB/B,SAAgB,UAAUA,SAAkC;CAC1D,MAAM,aAAa,QAAQ;AAC3B,YAAW,YAAY,UAAU,WAC/B,OAAM,IAAI,iBACR,aACA,eACC,2BAA2B,SAAS,WAAW,CAAC;AAGrD,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,YAAY;AACf,cAAW,WAAW,aAAa,cAAc,WAAW,UAAU,CACpE,OAAM,IAAI,MAAM;AAElB,SAAM,WAAW,OAAO;EACzB;CACF;AACF;AAED,SAAS,SAASC,YAAwC;AACxD,KAAI,cAAc,KAAM,QAAO,OAAO,WAAW;AACjD,YAAW,eAAe,SAAU,eAAc;CAClD,MAAM,OAAO,OAAO,KAAK,WAAW;AACpC,QAAO,KAAK,WAAW,IACnB,4BACC,sBAAsB,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,CAAC;AACxD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openstatus/health-nats",
|
|
3
|
+
"version": "0.1.4-dev.0",
|
|
4
|
+
"description": "NATS probe for @openstatus/health",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openstatus",
|
|
7
|
+
"health",
|
|
8
|
+
"healthcheck",
|
|
9
|
+
"nats",
|
|
10
|
+
"messaging",
|
|
11
|
+
"pubsub",
|
|
12
|
+
"jetstream"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "openstatus",
|
|
17
|
+
"url": "https://www.openstatus.dev/"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/openstatusHQ/health",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/openstatusHQ/health.git",
|
|
23
|
+
"directory": "packages/nats/"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/openstatusHQ/health/issues"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"module": "./dist/mod.js",
|
|
30
|
+
"main": "./dist/mod.cjs",
|
|
31
|
+
"types": "./dist/mod.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": {
|
|
35
|
+
"import": "./dist/mod.d.ts",
|
|
36
|
+
"require": "./dist/mod.d.cts"
|
|
37
|
+
},
|
|
38
|
+
"import": "./dist/mod.js",
|
|
39
|
+
"require": "./dist/mod.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@openstatus/health": "^0.1.4-dev.0",
|
|
52
|
+
"@nats-io/nats-core": ">=3.0.0",
|
|
53
|
+
"nats": ">=2.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@nats-io/nats-core": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"nats": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"tsdown": "^0.12.7",
|
|
65
|
+
"typescript": "^5.8.3"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsdown",
|
|
69
|
+
"prepack": "tsdown",
|
|
70
|
+
"test": "node --experimental-transform-types --test"
|
|
71
|
+
}
|
|
72
|
+
}
|