@terreno/api-health 0.31.0 → 56.0.0-beta.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 +2 -47
- package/package.json +4 -4
- package/tsconfig.json +4 -2
- package/LICENSE +0 -21
- package/dist/healthApp.test.d.ts +0 -1
- package/dist/healthApp.test.js +0 -219
package/README.md
CHANGED
|
@@ -1,50 +1,5 @@
|
|
|
1
1
|
# @terreno/api-health
|
|
2
2
|
|
|
3
|
-
Health check
|
|
3
|
+
Health check plugin for `@terreno/api`. Adds a `/health` endpoint to your Express server with configurable checks.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @terreno/api-health @terreno/api
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick start
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import {TerrenoApp} from "@terreno/api";
|
|
15
|
-
import {HealthApp} from "@terreno/api-health";
|
|
16
|
-
import mongoose from "mongoose";
|
|
17
|
-
import {User} from "./models/user";
|
|
18
|
-
|
|
19
|
-
const healthApp = new HealthApp({
|
|
20
|
-
path: "/health",
|
|
21
|
-
check: async () => {
|
|
22
|
-
try {
|
|
23
|
-
await mongoose.connection.db!.admin().ping();
|
|
24
|
-
return {healthy: true, details: {database: "connected"}};
|
|
25
|
-
} catch {
|
|
26
|
-
return {healthy: false, details: {database: "disconnected"}};
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
new TerrenoApp({userModel: User}).register(healthApp).start();
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Returns `200` with `{healthy: true, ...}` when healthy, `503` when `healthy: false`.
|
|
35
|
-
|
|
36
|
-
## What's included
|
|
37
|
-
|
|
38
|
-
- `HealthApp` — `TerrenoPlugin` registering a health endpoint
|
|
39
|
-
- `HealthOptions` — `enabled`, `path`, and optional async `check` function
|
|
40
|
-
- `HealthCheckResult` — `{healthy: boolean, details?: Record<string, unknown>}`
|
|
41
|
-
- Default behavior: `GET /health` returns `{healthy: true}` when no custom check is provided
|
|
42
|
-
- Supports load balancer probes, Kubernetes liveness/readiness, and database connectivity checks
|
|
43
|
-
|
|
44
|
-
## Documentation
|
|
45
|
-
|
|
46
|
-
Full API reference: [docs/reference/api-health.md](https://github.com/flourishhealth/terreno/blob/master/docs/reference/api-health.md)
|
|
47
|
-
|
|
48
|
-
## License and Contributing
|
|
49
|
-
|
|
50
|
-
Licensed under the [MIT License](https://github.com/flourishhealth/terreno/blob/master/LICENSE). See [CONTRIBUTING.md](https://github.com/flourishhealth/terreno/blob/master/CONTRIBUTING.md) for contribution guidelines.
|
|
5
|
+
See the package source for usage and configuration details.
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/FlourishHealth/terreno/issues"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@terreno/api": "0.
|
|
7
|
+
"@terreno/api": "56.0.0-beta.0",
|
|
8
8
|
"express": "^5.2.1"
|
|
9
9
|
},
|
|
10
10
|
"description": "Health check plugin for @terreno/api",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/express": "^5.0.6",
|
|
15
15
|
"@types/supertest": "^7.2.0",
|
|
16
16
|
"supertest": "^7.2.2",
|
|
17
|
-
"typescript": "~
|
|
17
|
+
"typescript": "~6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/FlourishHealth/terreno#readme",
|
|
20
20
|
"keywords": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"express",
|
|
24
24
|
"terreno"
|
|
25
25
|
],
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
27
|
"main": "dist/index.js",
|
|
28
28
|
"name": "@terreno/api-health",
|
|
29
29
|
"publishConfig": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
45
45
|
},
|
|
46
46
|
"types": "dist/index.d.ts",
|
|
47
|
-
"version": "0.
|
|
47
|
+
"version": "56.0.0-beta.0"
|
|
48
48
|
}
|
package/tsconfig.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"downlevelIteration": true,
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"ignoreDeprecations": "6.0",
|
|
10
11
|
"jsx": "react",
|
|
11
12
|
"lib": ["es2017", "dom", "es2017.object"],
|
|
12
13
|
"module": "commonjs",
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
"noUnusedLocals": false,
|
|
19
20
|
"noUnusedParameters": false,
|
|
20
21
|
"outDir": "./dist",
|
|
22
|
+
"rootDir": "./src",
|
|
21
23
|
"preserveConstEnums": true,
|
|
22
24
|
"removeComments": false,
|
|
23
25
|
"skipLibCheck": true,
|
|
@@ -26,6 +28,6 @@
|
|
|
26
28
|
"strictNullChecks": true,
|
|
27
29
|
"target": "es5"
|
|
28
30
|
},
|
|
29
|
-
"exclude": ["node_modules"],
|
|
30
|
-
"include": ["src/**/*.ts*", "src/*.ts"]
|
|
31
|
+
"exclude": ["node_modules", "**/*.test.ts"],
|
|
32
|
+
"include": ["src/**/*.ts*", "src/*.ts", "src/**/*.d.ts"]
|
|
31
33
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Flourish Health, Inc.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/healthApp.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/healthApp.test.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var bun_test_1 = require("bun:test");
|
|
43
|
-
var express_1 = __importDefault(require("express"));
|
|
44
|
-
var supertest_1 = __importDefault(require("supertest"));
|
|
45
|
-
var healthApp_1 = require("./healthApp");
|
|
46
|
-
var createApp = function (healthApp) {
|
|
47
|
-
var app = (0, express_1.default)();
|
|
48
|
-
healthApp.register(app);
|
|
49
|
-
return app;
|
|
50
|
-
};
|
|
51
|
-
(0, bun_test_1.describe)("HealthApp", function () {
|
|
52
|
-
(0, bun_test_1.it)("returns healthy: true by default", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
-
var app, res;
|
|
54
|
-
return __generator(this, function (_a) {
|
|
55
|
-
switch (_a.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
app = createApp(new healthApp_1.HealthApp());
|
|
58
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(200)];
|
|
59
|
-
case 1:
|
|
60
|
-
res = _a.sent();
|
|
61
|
-
(0, bun_test_1.expect)(res.body).toEqual({ healthy: true });
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}); });
|
|
66
|
-
(0, bun_test_1.it)("uses custom path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
-
var app, res;
|
|
68
|
-
return __generator(this, function (_a) {
|
|
69
|
-
switch (_a.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
app = createApp(new healthApp_1.HealthApp({ path: "/status" }));
|
|
72
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(404)];
|
|
73
|
-
case 1:
|
|
74
|
-
_a.sent();
|
|
75
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/status").expect(200)];
|
|
76
|
-
case 2:
|
|
77
|
-
res = _a.sent();
|
|
78
|
-
(0, bun_test_1.expect)(res.body).toEqual({ healthy: true });
|
|
79
|
-
return [2 /*return*/];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}); });
|
|
83
|
-
(0, bun_test_1.it)("does not register route when enabled is false", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
-
var app;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0:
|
|
88
|
-
app = createApp(new healthApp_1.HealthApp({ enabled: false }));
|
|
89
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(404)];
|
|
90
|
-
case 1:
|
|
91
|
-
_a.sent();
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}); });
|
|
96
|
-
(0, bun_test_1.it)("calls custom check function returning healthy", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var app, res;
|
|
98
|
-
return __generator(this, function (_a) {
|
|
99
|
-
switch (_a.label) {
|
|
100
|
-
case 0:
|
|
101
|
-
app = createApp(new healthApp_1.HealthApp({
|
|
102
|
-
check: function () { return ({
|
|
103
|
-
details: { db: "connected" },
|
|
104
|
-
healthy: true,
|
|
105
|
-
}); },
|
|
106
|
-
}));
|
|
107
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(200)];
|
|
108
|
-
case 1:
|
|
109
|
-
res = _a.sent();
|
|
110
|
-
(0, bun_test_1.expect)(res.body).toEqual({
|
|
111
|
-
details: { db: "connected" },
|
|
112
|
-
healthy: true,
|
|
113
|
-
});
|
|
114
|
-
return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); });
|
|
118
|
-
(0, bun_test_1.it)("returns 503 when check function returns unhealthy", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
119
|
-
var app, res;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
app = createApp(new healthApp_1.HealthApp({
|
|
124
|
-
check: function () { return ({
|
|
125
|
-
details: { db: "disconnected" },
|
|
126
|
-
healthy: false,
|
|
127
|
-
}); },
|
|
128
|
-
}));
|
|
129
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(503)];
|
|
130
|
-
case 1:
|
|
131
|
-
res = _a.sent();
|
|
132
|
-
(0, bun_test_1.expect)(res.body.healthy).toBe(false);
|
|
133
|
-
return [2 /*return*/];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}); });
|
|
137
|
-
(0, bun_test_1.it)("returns 503 when check function throws", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
138
|
-
var app, res;
|
|
139
|
-
return __generator(this, function (_a) {
|
|
140
|
-
switch (_a.label) {
|
|
141
|
-
case 0:
|
|
142
|
-
app = createApp(new healthApp_1.HealthApp({
|
|
143
|
-
check: function () {
|
|
144
|
-
throw new Error("DB connection failed");
|
|
145
|
-
},
|
|
146
|
-
}));
|
|
147
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(503)];
|
|
148
|
-
case 1:
|
|
149
|
-
res = _a.sent();
|
|
150
|
-
(0, bun_test_1.expect)(res.body).toEqual({
|
|
151
|
-
details: { error: "DB connection failed" },
|
|
152
|
-
healthy: false,
|
|
153
|
-
});
|
|
154
|
-
return [2 /*return*/];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}); });
|
|
158
|
-
(0, bun_test_1.it)("handles async check function", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
159
|
-
var app, res;
|
|
160
|
-
return __generator(this, function (_a) {
|
|
161
|
-
switch (_a.label) {
|
|
162
|
-
case 0:
|
|
163
|
-
app = createApp(new healthApp_1.HealthApp({
|
|
164
|
-
check: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
165
|
-
return __generator(this, function (_a) {
|
|
166
|
-
return [2 /*return*/, ({
|
|
167
|
-
details: { uptime: 100 },
|
|
168
|
-
healthy: true,
|
|
169
|
-
})];
|
|
170
|
-
});
|
|
171
|
-
}); },
|
|
172
|
-
}));
|
|
173
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(200)];
|
|
174
|
-
case 1:
|
|
175
|
-
res = _a.sent();
|
|
176
|
-
(0, bun_test_1.expect)(res.body.healthy).toBe(true);
|
|
177
|
-
(0, bun_test_1.expect)(res.body.details.uptime).toBe(100);
|
|
178
|
-
return [2 /*return*/];
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}); });
|
|
182
|
-
(0, bun_test_1.it)("handles async check function that rejects", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
-
var app, res;
|
|
184
|
-
return __generator(this, function (_a) {
|
|
185
|
-
switch (_a.label) {
|
|
186
|
-
case 0:
|
|
187
|
-
app = createApp(new healthApp_1.HealthApp({
|
|
188
|
-
check: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
189
|
-
return __generator(this, function (_a) {
|
|
190
|
-
throw new Error("Async failure");
|
|
191
|
-
});
|
|
192
|
-
}); },
|
|
193
|
-
}));
|
|
194
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(503)];
|
|
195
|
-
case 1:
|
|
196
|
-
res = _a.sent();
|
|
197
|
-
(0, bun_test_1.expect)(res.body).toEqual({
|
|
198
|
-
details: { error: "Async failure" },
|
|
199
|
-
healthy: false,
|
|
200
|
-
});
|
|
201
|
-
return [2 /*return*/];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}); });
|
|
205
|
-
(0, bun_test_1.it)("defaults to empty options when none provided", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
206
|
-
var app, res;
|
|
207
|
-
return __generator(this, function (_a) {
|
|
208
|
-
switch (_a.label) {
|
|
209
|
-
case 0:
|
|
210
|
-
app = createApp(new healthApp_1.HealthApp());
|
|
211
|
-
return [4 /*yield*/, (0, supertest_1.default)(app).get("/health").expect(200)];
|
|
212
|
-
case 1:
|
|
213
|
-
res = _a.sent();
|
|
214
|
-
(0, bun_test_1.expect)(res.body).toEqual({ healthy: true });
|
|
215
|
-
return [2 /*return*/];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}); });
|
|
219
|
-
});
|