@terreno/api-health 0.31.0 → 56.0.0-beta.2
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/package.json +3 -3
- package/tsconfig.json +4 -2
- package/dist/healthApp.test.d.ts +0 -1
- package/dist/healthApp.test.js +0 -219
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.2",
|
|
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": [
|
|
@@ -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.2"
|
|
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/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
|
-
});
|