@sebspark/health-check 3.0.9 → 3.0.11
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 +427 -0
- package/dist/index.d.mts +35 -33
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -13
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
# @sebspark/health-check
|
|
2
|
+
|
|
3
|
+
## 3.0.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 66ac832: * Upgraded to TypeScript 7
|
|
8
|
+
- Replaced tsup with tsdown for package builds
|
|
9
|
+
- Fixed cli-tester stdout parsing, resolving flaky e2e tests across the repo
|
|
10
|
+
- Patched vulnerable transitive dependencies (uuid, socket.io-parser, and others)
|
|
11
|
+
- Updated dependencies [66ac832]
|
|
12
|
+
- @sebspark/hyper-media@0.1.5
|
|
13
|
+
- @sebspark/promise-cache@8.1.6
|
|
14
|
+
|
|
15
|
+
## 3.0.10
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- eefb531: Updated dependencies
|
|
20
|
+
- Updated dependencies [eefb531]
|
|
21
|
+
- @sebspark/promise-cache@8.1.5
|
|
22
|
+
|
|
23
|
+
## 3.0.9
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 5e9fc45: Bump dependencies. Security fixes:
|
|
28
|
+
|
|
29
|
+
- **form-data** 2.5.6 / 4.0.6 — CRLF injection via unescaped multipart field names and filenames (High)
|
|
30
|
+
- **vite** 8.1.2 — `server.fs.deny` bypass on Windows alternate paths; NTLMv2 hash disclosure via launch-editor (High/Moderate)
|
|
31
|
+
- **ws** 8.21.0 — Memory exhaustion DoS from tiny fragments; uninitialized memory disclosure (High/Moderate)
|
|
32
|
+
- **undici** 8.5.0 — Multiple DoS and information disclosure CVEs (High/Moderate/Low)
|
|
33
|
+
- **tar** 7.5.19 — PAX size override causes tar parser differential / file smuggling (Moderate)
|
|
34
|
+
- **qs** 6.15.3 — DoS via `qs.stringify` crash on null/undefined entries (Moderate)
|
|
35
|
+
- **@opentelemetry/core** 2.8.0 — Unbounded memory allocation in W3C Baggage propagation (Moderate)
|
|
36
|
+
- **@babel/core** 7.29.7 — Arbitrary file read via sourceMappingURL comment (Low)
|
|
37
|
+
- **protobufjs** 8.6.5
|
|
38
|
+
|
|
39
|
+
Other dependency updates:
|
|
40
|
+
|
|
41
|
+
- `@google-cloud/spanner` 8.8.0
|
|
42
|
+
- `@testcontainers/*` 12.0.4
|
|
43
|
+
- `google-auth-library` 10.9.0
|
|
44
|
+
- `mockserver-client` 7.3.0
|
|
45
|
+
- `nock` 14.0.16
|
|
46
|
+
- `prettier` 3.9.4
|
|
47
|
+
- `redis` 6.1.0
|
|
48
|
+
- `webpack` 5.108.3 / `webpack-cli` 7.1.0
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [5e9fc45]
|
|
51
|
+
- @sebspark/promise-cache@8.1.4
|
|
52
|
+
|
|
53
|
+
## 3.0.8
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- e0eda57: Updated dependencies
|
|
58
|
+
- Updated dependencies [e0eda57]
|
|
59
|
+
- @sebspark/promise-cache@8.1.3
|
|
60
|
+
|
|
61
|
+
## 3.0.7
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- 26d55f0: Fix `@sebspark/memredis` so Redis clients are assignable to `IPersistor` by widening the pub/sub subscription return types to accept both MemRedis and node-redis implementations.
|
|
66
|
+
|
|
67
|
+
Also update supporting dependencies across the affected packages.
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [26d55f0]
|
|
70
|
+
- @sebspark/promise-cache@8.1.2
|
|
71
|
+
|
|
72
|
+
## 3.0.6
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- a6c27f3: Updated dependencies
|
|
77
|
+
- Updated dependencies [a6c27f3]
|
|
78
|
+
- @sebspark/promise-cache@8.1.1
|
|
79
|
+
|
|
80
|
+
## 3.0.5
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- Updated dependencies [0fad123]
|
|
85
|
+
- @sebspark/promise-cache@8.1.0
|
|
86
|
+
|
|
87
|
+
## 3.0.4
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- 97fe7da: Updated dependencies
|
|
92
|
+
- @sebspark/promise-cache@8.0.2
|
|
93
|
+
|
|
94
|
+
## 3.0.3
|
|
95
|
+
|
|
96
|
+
### Patch Changes
|
|
97
|
+
|
|
98
|
+
- Updated dependencies [494f9b3]
|
|
99
|
+
- @sebspark/promise-cache@8.0.1
|
|
100
|
+
|
|
101
|
+
## 3.0.2
|
|
102
|
+
|
|
103
|
+
### Patch Changes
|
|
104
|
+
|
|
105
|
+
- 264e665: Upgrade `redis` to v6 in `@sebspark/promise-cache` and bump minor dependencies across the workspace.
|
|
106
|
+
|
|
107
|
+
**Breaking change (`@sebspark/promise-cache`):**
|
|
108
|
+
`redis` upgraded from `5.12.1` → `6.0.0`. Redis v6 contains breaking changes in its API — see the [redis v6 migration guide](https://github.com/redis/node-redis/blob/master/docs/v4-to-v6.md) if your code uses the client directly.
|
|
109
|
+
|
|
110
|
+
**Dependency updates across packages:**
|
|
111
|
+
- `testcontainers` / `@testcontainers/*`: `12.0.0` → `12.0.1` (health-check, opensearch, opentelemetry-instrumentation-opensearch, otel, promise-cache, socket.io-gcp-pubsub-emitter, spanner-migrate, test-iap)
|
|
112
|
+
- `redis`: `5.12.1` → `6.0.0` (otel, promise-cache)
|
|
113
|
+
- `tsdown`: `0.22.0` → `0.22.1` (tsconfig)
|
|
114
|
+
- `turbo` / `@turbo/gen`: `2.9.15` → `2.9.16`
|
|
115
|
+
- `webpack-cli`: `7.0.2` → `7.0.3` (avsc-isometric)
|
|
116
|
+
|
|
117
|
+
**Test fix (`@sebspark/promise-cache`):**
|
|
118
|
+
Pinned Redis container image tag to `redis:8.8-alpine` (was `redis:8-alpine`) to prevent floating-tag drift in e2e tests.
|
|
119
|
+
|
|
120
|
+
- Updated dependencies [264e665]
|
|
121
|
+
- @sebspark/promise-cache@8.0.0
|
|
122
|
+
|
|
123
|
+
## 3.0.1
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- 242eb33: This release primarily updates dependencies across the listed packages, including:
|
|
128
|
+
- Testcontainers v12 upgrades in packages that run integration/e2e tests.
|
|
129
|
+
- Vitest/Biome/Turbo and related tooling updates.
|
|
130
|
+
- Runtime dependency updates such as `date-fns`, `@inquirer/*`, `socket.io-adapter`, and `ws`.
|
|
131
|
+
|
|
132
|
+
It also includes two targeted fixes:
|
|
133
|
+
- `@sebspark/opensearch`: fixed TypeScript compatibility so strict `SearchRequest<T>` / `SearchRequestBody<T>` can be assigned to OpenSearch API request types, and added a compile-time compatibility test.
|
|
134
|
+
- `@sebspark/health-check`: updated the e2e readiness payload assertions and type-only import usage to match current runtime output and TypeScript expectations.
|
|
135
|
+
|
|
136
|
+
- Updated dependencies [242eb33]
|
|
137
|
+
- @sebspark/promise-cache@7.0.4
|
|
138
|
+
|
|
139
|
+
## 3.0.0
|
|
140
|
+
|
|
141
|
+
### Major Changes
|
|
142
|
+
|
|
143
|
+
- 48ffa3b: **Breaking:** The `System` and `Process` types returned by the `/health/live` endpoint no longer include fingerprinting fields that could be exploited by an attacker.
|
|
144
|
+
|
|
145
|
+
Removed from `system`: `hostname`, `platform`, `release`, `arch`, `cpus.model`, `cpus.speedMHz`.
|
|
146
|
+
|
|
147
|
+
Removed from `process`: `pid`, `node`.
|
|
148
|
+
|
|
149
|
+
These fields were accessible without authentication and disclosed OS version, kernel release, CPU model, Node.js version, and process ID — all useful for targeted exploitation. The endpoint now only exposes load metrics: `uptime`, `loadavg`, `totalmem`, `freemem`, `memUsedRatio`, `cpus.count`, `process.uptime`, and `process.memory`.
|
|
150
|
+
|
|
151
|
+
## 2.3.12
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- c5e9c99: Resolve protobufjs CVE by pinning to `8.3.0` across all affected packages via root resolutions. Upgraded OpenTelemetry packages to `0.218.0` (which also eliminates the previous hardpin on `protobufjs@8.0.1`), `axios` to `1.16.1`, `ws` to `8.20.1`, `qs` to `6.15.2`, and `@opentelemetry/semantic-conventions` to `1.41.1`.
|
|
156
|
+
- Updated dependencies [c5e9c99]
|
|
157
|
+
- @sebspark/promise-cache@7.0.3
|
|
158
|
+
|
|
159
|
+
## 2.3.11
|
|
160
|
+
|
|
161
|
+
### Patch Changes
|
|
162
|
+
|
|
163
|
+
- @sebspark/promise-cache@7.0.2
|
|
164
|
+
|
|
165
|
+
## 2.3.10
|
|
166
|
+
|
|
167
|
+
### Patch Changes
|
|
168
|
+
|
|
169
|
+
- @sebspark/promise-cache@7.0.1
|
|
170
|
+
|
|
171
|
+
## 2.3.9
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- Updated dependencies [55e3708]
|
|
176
|
+
- @sebspark/promise-cache@7.0.0
|
|
177
|
+
|
|
178
|
+
## 2.3.8
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
181
|
+
|
|
182
|
+
- Updated dependencies [5ed6ece]
|
|
183
|
+
- @sebspark/promise-cache@6.6.0
|
|
184
|
+
|
|
185
|
+
## 2.3.7
|
|
186
|
+
|
|
187
|
+
### Patch Changes
|
|
188
|
+
|
|
189
|
+
- Updated dependencies [2cff3d4]
|
|
190
|
+
- @sebspark/promise-cache@6.5.0
|
|
191
|
+
|
|
192
|
+
## 2.3.6
|
|
193
|
+
|
|
194
|
+
### Patch Changes
|
|
195
|
+
|
|
196
|
+
- @sebspark/promise-cache@6.4.29
|
|
197
|
+
|
|
198
|
+
## 2.3.5
|
|
199
|
+
|
|
200
|
+
### Patch Changes
|
|
201
|
+
|
|
202
|
+
- 7d8cc98: Dependabot dependency updates
|
|
203
|
+
- Updated dependencies [7d8cc98]
|
|
204
|
+
- @sebspark/hyper-media@0.1.4
|
|
205
|
+
- @sebspark/promise-cache@6.4.28
|
|
206
|
+
|
|
207
|
+
## 2.3.4
|
|
208
|
+
|
|
209
|
+
### Patch Changes
|
|
210
|
+
|
|
211
|
+
- @sebspark/promise-cache@6.4.27
|
|
212
|
+
|
|
213
|
+
## 2.3.3
|
|
214
|
+
|
|
215
|
+
### Patch Changes
|
|
216
|
+
|
|
217
|
+
- Updated dependencies [764bac9]
|
|
218
|
+
- @sebspark/promise-cache@6.4.26
|
|
219
|
+
|
|
220
|
+
## 2.3.2
|
|
221
|
+
|
|
222
|
+
### Patch Changes
|
|
223
|
+
|
|
224
|
+
- e9a7a28: Updated dependencies
|
|
225
|
+
- @sebspark/promise-cache@6.4.25
|
|
226
|
+
|
|
227
|
+
## 2.3.1
|
|
228
|
+
|
|
229
|
+
### Patch Changes
|
|
230
|
+
|
|
231
|
+
- @sebspark/promise-cache@6.4.24
|
|
232
|
+
|
|
233
|
+
## 2.3.0
|
|
234
|
+
|
|
235
|
+
### Minor Changes
|
|
236
|
+
|
|
237
|
+
- 6399280: Health check now has ddos protection. Type fix in promise-cache.
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- Updated dependencies [6399280]
|
|
242
|
+
- @sebspark/promise-cache@6.4.23
|
|
243
|
+
|
|
244
|
+
## 2.2.4
|
|
245
|
+
|
|
246
|
+
### Patch Changes
|
|
247
|
+
|
|
248
|
+
- 4e12590: Updated dependencies
|
|
249
|
+
|
|
250
|
+
## 2.2.3
|
|
251
|
+
|
|
252
|
+
### Patch Changes
|
|
253
|
+
|
|
254
|
+
- 6db0b94: fix: do not count degraded as failing for critical dependencies
|
|
255
|
+
|
|
256
|
+
## 2.2.2
|
|
257
|
+
|
|
258
|
+
### Patch Changes
|
|
259
|
+
|
|
260
|
+
- 574264d: Updated dependencies
|
|
261
|
+
|
|
262
|
+
## 2.2.1
|
|
263
|
+
|
|
264
|
+
### Patch Changes
|
|
265
|
+
|
|
266
|
+
- acb0290: Changed import to type
|
|
267
|
+
|
|
268
|
+
## 2.2.0
|
|
269
|
+
|
|
270
|
+
### Minor Changes
|
|
271
|
+
|
|
272
|
+
- 6d72f97: Dependency monitors can now report status details
|
|
273
|
+
|
|
274
|
+
## 2.1.1
|
|
275
|
+
|
|
276
|
+
### Patch Changes
|
|
277
|
+
|
|
278
|
+
- 736a0b3: No bundling of packages in packages
|
|
279
|
+
- Updated dependencies [736a0b3]
|
|
280
|
+
- @sebspark/hyper-media@0.1.3
|
|
281
|
+
|
|
282
|
+
## 2.1.0
|
|
283
|
+
|
|
284
|
+
### Minor Changes
|
|
285
|
+
|
|
286
|
+
- 903a0fb: chore: /ready should not return 200 if not ready
|
|
287
|
+
|
|
288
|
+
## 2.0.3
|
|
289
|
+
|
|
290
|
+
### Patch Changes
|
|
291
|
+
|
|
292
|
+
- 112a381: Updated dependencies
|
|
293
|
+
|
|
294
|
+
## 2.0.2
|
|
295
|
+
|
|
296
|
+
### Patch Changes
|
|
297
|
+
|
|
298
|
+
- Updated dependencies [695837c]
|
|
299
|
+
- @sebspark/hyper-media@0.1.2
|
|
300
|
+
|
|
301
|
+
## 2.0.1
|
|
302
|
+
|
|
303
|
+
### Patch Changes
|
|
304
|
+
|
|
305
|
+
- aaa50ea: Healthcheck now uses Hypermedia. Hypermedia got better jsdocs.
|
|
306
|
+
- Updated dependencies [aaa50ea]
|
|
307
|
+
- @sebspark/hyper-media@0.1.1
|
|
308
|
+
|
|
309
|
+
## 2.0.0
|
|
310
|
+
|
|
311
|
+
### Major Changes
|
|
312
|
+
|
|
313
|
+
- 6037a11: Links changed to entities with hypermedia links
|
|
314
|
+
|
|
315
|
+
## 1.0.14
|
|
316
|
+
|
|
317
|
+
### Patch Changes
|
|
318
|
+
|
|
319
|
+
- 35ec1a0: Updated dependencies
|
|
320
|
+
|
|
321
|
+
## 1.0.13
|
|
322
|
+
|
|
323
|
+
### Patch Changes
|
|
324
|
+
|
|
325
|
+
- c8dcadb: Updated dependencies
|
|
326
|
+
|
|
327
|
+
## 1.0.12
|
|
328
|
+
|
|
329
|
+
### Patch Changes
|
|
330
|
+
|
|
331
|
+
- 11a11ce: Updated dependencies
|
|
332
|
+
|
|
333
|
+
## 1.0.10
|
|
334
|
+
|
|
335
|
+
### Patch Changes
|
|
336
|
+
|
|
337
|
+
- 48ab717: Updated dependencies
|
|
338
|
+
|
|
339
|
+
## 1.0.9
|
|
340
|
+
|
|
341
|
+
### Patch Changes
|
|
342
|
+
|
|
343
|
+
- 87c769d: Updated dependencies
|
|
344
|
+
|
|
345
|
+
## 1.0.8
|
|
346
|
+
|
|
347
|
+
### Patch Changes
|
|
348
|
+
|
|
349
|
+
- e0cb5ee: Updated build from tsup to tsdown
|
|
350
|
+
|
|
351
|
+
## 1.0.7
|
|
352
|
+
|
|
353
|
+
### Patch Changes
|
|
354
|
+
|
|
355
|
+
- 8626deb: Updated vulnerable, transitive jws dependency
|
|
356
|
+
|
|
357
|
+
## 1.0.6
|
|
358
|
+
|
|
359
|
+
### Patch Changes
|
|
360
|
+
|
|
361
|
+
- 7df8217: Updated dependencies
|
|
362
|
+
|
|
363
|
+
## 1.0.5
|
|
364
|
+
|
|
365
|
+
### Patch Changes
|
|
366
|
+
|
|
367
|
+
- ef9ccdc: Updated to latest express version
|
|
368
|
+
|
|
369
|
+
## 1.0.4
|
|
370
|
+
|
|
371
|
+
### Patch Changes
|
|
372
|
+
|
|
373
|
+
- 5bf3ac7: chore: update dependencies for express-serve-static-core
|
|
374
|
+
|
|
375
|
+
## 1.0.3
|
|
376
|
+
|
|
377
|
+
### Patch Changes
|
|
378
|
+
|
|
379
|
+
- 4b210c2: Standardized on a common build script
|
|
380
|
+
|
|
381
|
+
## 1.0.2
|
|
382
|
+
|
|
383
|
+
### Patch Changes
|
|
384
|
+
|
|
385
|
+
- 7e5c2e9: Switched to new tsconfig with moduleResolution=bundler
|
|
386
|
+
|
|
387
|
+
## 1.0.1
|
|
388
|
+
|
|
389
|
+
### Patch Changes
|
|
390
|
+
|
|
391
|
+
- 512cdc5: DependencyMonitor is now exposed
|
|
392
|
+
|
|
393
|
+
## 1.0.0
|
|
394
|
+
|
|
395
|
+
### Major Changes
|
|
396
|
+
|
|
397
|
+
- 0864ec2: Minimum node version 22
|
|
398
|
+
|
|
399
|
+
## 0.1.4
|
|
400
|
+
|
|
401
|
+
### Patch Changes
|
|
402
|
+
|
|
403
|
+
- 3a40e49: Cleaned up dependencies
|
|
404
|
+
|
|
405
|
+
## 0.1.3
|
|
406
|
+
|
|
407
|
+
### Patch Changes
|
|
408
|
+
|
|
409
|
+
- 604c94a: Updated dependencies
|
|
410
|
+
|
|
411
|
+
## 0.1.2
|
|
412
|
+
|
|
413
|
+
### Patch Changes
|
|
414
|
+
|
|
415
|
+
- 29b9b20: Updated dependencies
|
|
416
|
+
|
|
417
|
+
## 0.1.1
|
|
418
|
+
|
|
419
|
+
### Patch Changes
|
|
420
|
+
|
|
421
|
+
- 5c6e183: Updated dependencies
|
|
422
|
+
|
|
423
|
+
## 0.1.0
|
|
424
|
+
|
|
425
|
+
### Minor Changes
|
|
426
|
+
|
|
427
|
+
- d6970ac: A health check handler for your API
|
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
|
-
|
|
3
2
|
//#region src/types.d.ts
|
|
4
|
-
type DependencyStatusValue = 'ok' | 'degraded' | 'error';
|
|
5
|
-
type DependencyStatus = {
|
|
3
|
+
export type DependencyStatusValue = 'ok' | 'degraded' | 'error';
|
|
4
|
+
export type DependencyStatus = {
|
|
6
5
|
status: DependencyStatusValue;
|
|
7
6
|
details?: Record<string, unknown> | undefined;
|
|
8
7
|
};
|
|
9
|
-
type StatusValue = DependencyStatusValue | 'unknown' | 'draining';
|
|
10
|
-
type Impact = 'critical' | 'non_critical';
|
|
11
|
-
type Mode = 'inline' | 'polled' | 'async';
|
|
12
|
-
type Verb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
13
|
-
type Link = {
|
|
8
|
+
export type StatusValue = DependencyStatusValue | 'unknown' | 'draining';
|
|
9
|
+
export type Impact = 'critical' | 'non_critical';
|
|
10
|
+
export type Mode = 'inline' | 'polled' | 'async';
|
|
11
|
+
export type Verb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
12
|
+
export type Link = {
|
|
14
13
|
method: Verb;
|
|
15
14
|
href: string;
|
|
16
15
|
};
|
|
17
|
-
interface Entity<T> {
|
|
16
|
+
export interface Entity<T> {
|
|
18
17
|
data: T;
|
|
19
18
|
links: Record<string, Link>;
|
|
20
19
|
}
|
|
21
|
-
type Status = {
|
|
20
|
+
export type Status = {
|
|
22
21
|
status: StatusValue;
|
|
23
22
|
};
|
|
24
|
-
type System = {
|
|
23
|
+
export type System = {
|
|
25
24
|
uptime: number;
|
|
26
25
|
loadavg: [number, number, number];
|
|
27
26
|
totalmem: number;
|
|
@@ -31,28 +30,28 @@ type System = {
|
|
|
31
30
|
count: number;
|
|
32
31
|
};
|
|
33
32
|
};
|
|
34
|
-
type Process = {
|
|
33
|
+
export type Process = {
|
|
35
34
|
uptime: number;
|
|
36
35
|
memory: NodeJS.MemoryUsage;
|
|
37
36
|
};
|
|
38
|
-
type Liveness = Status & {
|
|
37
|
+
export type Liveness = Status & {
|
|
39
38
|
timestamp: string;
|
|
40
39
|
system: System;
|
|
41
40
|
process: Process;
|
|
42
41
|
};
|
|
43
|
-
type Freshness = {
|
|
42
|
+
export type Freshness = {
|
|
44
43
|
lastChecked: string;
|
|
45
44
|
lastSuccess: string | null;
|
|
46
45
|
};
|
|
47
|
-
type Observed = {
|
|
46
|
+
export type Observed = {
|
|
48
47
|
latencyMs: number | null;
|
|
49
48
|
[k: string]: unknown;
|
|
50
49
|
};
|
|
51
|
-
type CheckError = {
|
|
50
|
+
export type CheckError = {
|
|
52
51
|
code: string;
|
|
53
52
|
message: string;
|
|
54
53
|
};
|
|
55
|
-
type DependencyCheck = Status & {
|
|
54
|
+
export type DependencyCheck = Status & {
|
|
56
55
|
impact: Impact;
|
|
57
56
|
mode: Mode;
|
|
58
57
|
freshness: Freshness;
|
|
@@ -61,7 +60,7 @@ type DependencyCheck = Status & {
|
|
|
61
60
|
error?: CheckError | null;
|
|
62
61
|
since?: string | null;
|
|
63
62
|
};
|
|
64
|
-
type ReadinessSummary = {
|
|
63
|
+
export type ReadinessSummary = {
|
|
65
64
|
critical: {
|
|
66
65
|
ok: number;
|
|
67
66
|
degraded: number;
|
|
@@ -74,7 +73,7 @@ type ReadinessSummary = {
|
|
|
74
73
|
};
|
|
75
74
|
degradedReasons: string[];
|
|
76
75
|
};
|
|
77
|
-
type ReadinessPayload = Status & {
|
|
76
|
+
export type ReadinessPayload = Status & {
|
|
78
77
|
timestamp: string;
|
|
79
78
|
service?: {
|
|
80
79
|
name?: string;
|
|
@@ -84,13 +83,13 @@ type ReadinessPayload = Status & {
|
|
|
84
83
|
summary: ReadinessSummary;
|
|
85
84
|
checks: Record<string, DependencyCheck>;
|
|
86
85
|
};
|
|
87
|
-
type HealthSummary = Status & Pick<ReadinessPayload, 'summary' | 'checks'> & Pick<Liveness, 'system' | 'process'> & {
|
|
86
|
+
export type HealthSummary = Status & Pick<ReadinessPayload, 'summary' | 'checks'> & Pick<Liveness, 'system' | 'process'> & {
|
|
88
87
|
timestamp: string;
|
|
89
88
|
};
|
|
90
|
-
declare class TimeoutError extends Error {
|
|
89
|
+
export declare class TimeoutError extends Error {
|
|
91
90
|
constructor();
|
|
92
91
|
}
|
|
93
|
-
declare class UnknownError extends Error {
|
|
92
|
+
export declare class UnknownError extends Error {
|
|
94
93
|
constructor();
|
|
95
94
|
}
|
|
96
95
|
//#endregion
|
|
@@ -135,8 +134,9 @@ type BaseConfig = {
|
|
|
135
134
|
* Inline mode configuration (no polling).
|
|
136
135
|
* `syncCall` runs **only** when {@link DependencyMonitor.check} is invoked.
|
|
137
136
|
*/
|
|
138
|
-
type SyncInlineConfig = BaseConfig & {
|
|
139
|
-
/** Performs the check immediately when {@link DependencyMonitor.check} is called. */
|
|
137
|
+
export type SyncInlineConfig = BaseConfig & {
|
|
138
|
+
/** Performs the check immediately when {@link DependencyMonitor.check} is called. */
|
|
139
|
+
syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>;
|
|
140
140
|
asyncCall?: never;
|
|
141
141
|
pollRate?: undefined;
|
|
142
142
|
retryRate?: undefined;
|
|
@@ -145,8 +145,10 @@ type SyncInlineConfig = BaseConfig & {
|
|
|
145
145
|
* Polled mode configuration.
|
|
146
146
|
* `syncCall` runs on an interval (`pollRate`) and results are cached.
|
|
147
147
|
*/
|
|
148
|
-
type SyncPolledConfig = BaseConfig & {
|
|
149
|
-
/** Performs the check at each poll interval. */
|
|
148
|
+
export type SyncPolledConfig = BaseConfig & {
|
|
149
|
+
/** Performs the check at each poll interval. */
|
|
150
|
+
syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>;
|
|
151
|
+
/** Polling interval in milliseconds. */
|
|
150
152
|
pollRate: number;
|
|
151
153
|
asyncCall?: never;
|
|
152
154
|
};
|
|
@@ -154,12 +156,13 @@ type SyncPolledConfig = BaseConfig & {
|
|
|
154
156
|
* Async mode configuration.
|
|
155
157
|
* `asyncCall` starts a check and must report via the provided callback.
|
|
156
158
|
*/
|
|
157
|
-
type AsyncConfig = BaseConfig & {
|
|
159
|
+
export type AsyncConfig = BaseConfig & {
|
|
158
160
|
/**
|
|
159
161
|
* Starts an asynchronous check. Must call `reportResponse` once a result is available.
|
|
160
162
|
* The callback may be invoked with a `DependencyStatus | DependencyStatusValue` or an `Error`.
|
|
161
163
|
*/
|
|
162
|
-
asyncCall: (reportResponse: (status: DependencyStatus | DependencyStatusValue | Error) => void | Promise<void>) => void | Promise<void>;
|
|
164
|
+
asyncCall: (reportResponse: (status: DependencyStatus | DependencyStatusValue | Error) => void | Promise<void>) => void | Promise<void>;
|
|
165
|
+
/** Polling interval in milliseconds. */
|
|
163
166
|
pollRate: number;
|
|
164
167
|
syncCall?: never;
|
|
165
168
|
};
|
|
@@ -169,7 +172,7 @@ type AsyncConfig = BaseConfig & {
|
|
|
169
172
|
* - {@link SyncPolledConfig} → synchronous checks on a fixed interval
|
|
170
173
|
* - {@link AsyncConfig} → asynchronous checks that report back via callback
|
|
171
174
|
*/
|
|
172
|
-
type DependencyMonitorConfig = SyncInlineConfig | SyncPolledConfig | AsyncConfig;
|
|
175
|
+
export type DependencyMonitorConfig = SyncInlineConfig | SyncPolledConfig | AsyncConfig;
|
|
173
176
|
/**
|
|
174
177
|
* Tracks the health of a single dependency in one of three modes:
|
|
175
178
|
*
|
|
@@ -188,7 +191,7 @@ type DependencyMonitorConfig = SyncInlineConfig | SyncPolledConfig | AsyncConfig
|
|
|
188
191
|
* - `"error"` if returned `"error"`, an `Error`, or exceeded `timeoutLimitMs`
|
|
189
192
|
* - `"unknown"` is the initial state before first successful/failed result (polled/async)
|
|
190
193
|
*/
|
|
191
|
-
declare class DependencyMonitor {
|
|
194
|
+
export declare class DependencyMonitor {
|
|
192
195
|
/** Immutable configuration for this monitor. */
|
|
193
196
|
private readonly config;
|
|
194
197
|
/** Operational mode determined from the configuration. */
|
|
@@ -264,7 +267,7 @@ declare class DependencyMonitor {
|
|
|
264
267
|
}
|
|
265
268
|
//#endregion
|
|
266
269
|
//#region src/health-monitor.d.ts
|
|
267
|
-
interface HealthMonitorConfig {
|
|
270
|
+
export interface HealthMonitorConfig {
|
|
268
271
|
throttle: number;
|
|
269
272
|
}
|
|
270
273
|
/**
|
|
@@ -299,7 +302,7 @@ interface HealthMonitorConfig {
|
|
|
299
302
|
* app.listen(3000)
|
|
300
303
|
* ```
|
|
301
304
|
*/
|
|
302
|
-
declare class HealthMonitor {
|
|
305
|
+
export declare class HealthMonitor {
|
|
303
306
|
private readonly _router;
|
|
304
307
|
private readonly dependencies;
|
|
305
308
|
private isDisposed;
|
|
@@ -383,5 +386,4 @@ declare class HealthMonitor {
|
|
|
383
386
|
dispose(): void;
|
|
384
387
|
}
|
|
385
388
|
//#endregion
|
|
386
|
-
export { AsyncConfig, CheckError, DependencyCheck, DependencyMonitor, DependencyMonitorConfig, DependencyStatus, DependencyStatusValue, Entity, Freshness, HealthMonitor, HealthMonitorConfig, HealthSummary, Impact, Link, Liveness, Mode, Observed, Process, ReadinessPayload, ReadinessSummary, Status, StatusValue, SyncInlineConfig, SyncPolledConfig, System, TimeoutError, UnknownError, Verb };
|
|
387
389
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/dependency-monitor.ts","../src/health-monitor.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/dependency-monitor.ts","../src/health-monitor.ts"],"mappings":";;YAAY;YACA;EACV,QAAQ;EACR,UAAU;;YAEA,cAAc;YACd;YACA;YAEA;YAEA;EACV,QAAQ;EACR;;iBAGe,OAAO;EACtB,MAAM;EACN,OAAO,eAAe;;YAGZ;EACV,QAAQ;;YAGE;EACV;EACA;EACA;EACA;EACA;EACA;IACE;;;YAIQ;EACV;EACA,QAAQ,OAAO;;YAGL,WAAW;EACrB;EACA,QAAQ;EACR,SAAS;;YAGC;EACV;EACA;;YAGU;EACV;GACC;;YAGS;EACV;EACA;;YAGU,kBAAkB;EAC5B,QAAQ;EACR,MAAM;EACN,WAAW;EACX,WAAW;EACX,UAAU;EACV,QAAQ;EACR;;YAGU;EACV;IAAY;IAAY;IAAkB;;EAC1C;IAAe;IAAY;IAAkB;;EAC7C;;YAGU,mBAAmB;EAC7B;EACA;IAAY;IAAe;IAAkB;;EAC7C,SAAS;EACT,QAAQ,eAAe;;YAGb,gBAAgB,SAC1B,KAAK,0CACL,KAAK;EAAoC;;qBAE9B,qBAAqB;EAChC;;qBAMW,qBAAqB;EAChC;;;;;;;KC9EG;;;;;;EAMH,QAAQ;;;;;;EAOR;;;;;;EAOA;;;;;;EAOA;;;;;;;EAQA;;;;;;YAOU,mBAAmB;;EAE7B,gBAAgB,QAAQ,mBAAmB,wBAAwB;EACnE;EACA;EACA;;;;;;YAOU,mBAAmB;;EAE7B,gBAAgB,QAAQ,mBAAmB,wBAAwB;;EAEnE;EACA;;;;;;YAOU,cAAc;;;;;EAKxB,YACE,iBACE,QAAQ,mBAAmB,wBAAwB,iBACzC,yBACF;;EAEZ;EACA;;;;;;;;YASU,0BACR,mBACA,mBACA;;;;;;;;;;;;;;;;;;;qBAoBS;;mBAEM;;mBAEA;;UAGT;;UAEA;;UAEA;;UAEA;;UAEA;;UAGA;;UAEA;;;;;EAMR,YAAY,QAAQ;;MAuBT,UAAM;;;;;;UASH;;;;;;;;UAsBA;;;;;;;UAqBA;;;;;;UAsCN;;;;;UAyCA;;;;;;;EA4BK,SAAS,QAAQ;;GAuBtB,OAAO;;;;;;EASR;;;;iBC/VQ;EACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmCW;mBACM;mBACA;UACT;;;;EAKR,YAAY,SAAS;;;;;;;;;;;;;;;;;EA0Bd,cAAc,cAAc,YAAY;;;;UAQvC;;;;EAmGD,QA3GwC;;;;EAkHxC,QAPI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCE,SAAS,QAAQ;EAkHjB,UAAM,QAAA;;;;MAiBR,UAAM;;;;GAOT,OAAO;;;;;;EASR"}
|
package/dist/index.mjs
CHANGED
|
@@ -360,7 +360,8 @@ var HealthMonitor = class {
|
|
|
360
360
|
*/
|
|
361
361
|
createRouter() {
|
|
362
362
|
const router = Router();
|
|
363
|
-
const
|
|
363
|
+
const persistor = new InMemoryPersistor();
|
|
364
|
+
const cache = createCache(persistor);
|
|
364
365
|
const cachedHealth = cache.wrap(() => this.health(), {
|
|
365
366
|
key: "/health",
|
|
366
367
|
expiry: 1e3
|
|
@@ -500,9 +501,10 @@ var HealthMonitor = class {
|
|
|
500
501
|
const degradedReasons = [];
|
|
501
502
|
for (const [name, c] of Object.entries(checks)) {
|
|
502
503
|
const isCritical = c.impact === "critical";
|
|
503
|
-
if (c.status === "unknown") {} else if (c.status === "ok")
|
|
504
|
-
|
|
505
|
-
|
|
504
|
+
if (c.status === "unknown") {} else if (c.status === "ok") {
|
|
505
|
+
if (isCritical) criticalOk++;
|
|
506
|
+
else nonCritOk++;
|
|
507
|
+
} else if (c.status === "degraded") {
|
|
506
508
|
if (isCritical) criticalDegraded++;
|
|
507
509
|
else nonCritDegraded++;
|
|
508
510
|
degradedReasons.push(`${name}:degraded`);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/types.ts","../src/timing.ts","../src/dependency-monitor.ts","../src/static-checks.ts","../src/health-monitor.ts"],"sourcesContent":["export type DependencyStatusValue = 'ok' | 'degraded' | 'error'\nexport type DependencyStatus = {\n status: DependencyStatusValue\n details?: Record<string, unknown> | undefined\n}\nexport type StatusValue = DependencyStatusValue | 'unknown' | 'draining'\nexport type Impact = 'critical' | 'non_critical'\nexport type Mode = 'inline' | 'polled' | 'async'\n\nexport type Verb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'\n\nexport type Link = {\n method: Verb\n href: string\n}\n\nexport interface Entity<T> {\n data: T\n links: Record<string, Link>\n}\n\nexport type Status = {\n status: StatusValue\n}\n\nexport type System = {\n uptime: number\n loadavg: [number, number, number] // 1, 5, 15 min\n totalmem: number\n freemem: number\n memUsedRatio: number // 0..1\n cpus: {\n count: number\n }\n}\n\nexport type Process = {\n uptime: number\n memory: NodeJS.MemoryUsage\n}\n\nexport type Liveness = Status & {\n timestamp: string\n system: System\n process: Process\n}\n\nexport type Freshness = {\n lastChecked: string\n lastSuccess: string | null\n}\n\nexport type Observed = {\n latencyMs: number | null\n [k: string]: unknown\n}\n\nexport type CheckError = {\n code: string\n message: string\n}\n\nexport type DependencyCheck = Status & {\n impact: Impact\n mode: Mode\n freshness: Freshness\n observed?: Observed\n details?: Record<string, unknown>\n error?: CheckError | null\n since?: string | null\n}\n\nexport type ReadinessSummary = {\n critical: { ok: number; degraded: number; failing: number }\n nonCritical: { ok: number; degraded: number; failing: number }\n degradedReasons: string[]\n}\n\nexport type ReadinessPayload = Status & {\n timestamp: string\n service?: { name?: string; version?: string; instanceId?: string }\n summary: ReadinessSummary\n checks: Record<string, DependencyCheck>\n}\n\nexport type HealthSummary = Status &\n Pick<ReadinessPayload, 'summary' | 'checks'> &\n Pick<Liveness, 'system' | 'process'> & { timestamp: string }\n\nexport class TimeoutError extends Error {\n constructor() {\n super('timeout')\n this.name = 'TimeoutError'\n }\n}\n\nexport class UnknownError extends Error {\n constructor() {\n super('unknown')\n this.name = 'UnknownError'\n }\n}\n","import { TimeoutError } from './types'\n\nexport const wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(resolve, ms))\n\nexport const runTimeoutTimer = async (ms: number) => {\n await wait(ms)\n throw new TimeoutError()\n}\n\nexport const runAgainstTimeout = <T>(\n promise: Promise<T>,\n ms?: number | undefined\n): Promise<T> => {\n if ((ms as number) > 0) {\n return Promise.race([promise, runTimeoutTimer(ms as number)])\n }\n\n return promise\n}\n\n/**\n * Throttles an async function:\n * - coalesces concurrent calls into a single in-flight Promise,\n * - after it settles, reuses that settled Promise for `ms` ms,\n * - then clears so the next call invokes `fn` again.\n *\n * Fully preserves the original function signature.\n */\nexport const throttle = <F extends (...args: unknown[]) => Promise<unknown>>(\n fn: F,\n ms: number\n) => {\n type R = ReturnType<F> // a Promise<T>\n\n let current: R | null = null\n let clearHandle: NodeJS.Timeout | null = null\n\n const wrapped = (...args: Parameters<F>): R => {\n if (!current) {\n current = fn(...args) as R\n\n /* istanbul ignore next */\n if (clearHandle) {\n clearTimeout(clearHandle)\n clearHandle = null\n }\n\n const schedule = () => {\n if (ms > 0) {\n clearHandle = setTimeout(\n /* istanbul ignore next */ () => {\n current = null\n clearHandle = null\n },\n ms\n )\n } else {\n current = null\n }\n }\n current.then(schedule, schedule)\n }\n\n return current\n }\n\n // Cast to F so the returned function has the *identical* callable type\n return wrapped as unknown as F\n}\n\n/**\n * Wraps an async function so that concurrent invocations share the same in-flight Promise.\n * After the Promise settles (resolve or reject), the next call will invoke the function again.\n * Essentially just throttled with timeout 0\n */\nexport const singleFlight = <\n F extends (...args: unknown[]) => Promise<unknown>,\n>(\n fn: F\n) => throttle<F>(fn, 0)\n","import { performance } from 'node:perf_hooks'\nimport { runAgainstTimeout, singleFlight } from './timing'\nimport {\n type CheckError,\n type DependencyCheck,\n type DependencyStatus,\n type DependencyStatusValue,\n type Freshness,\n type Impact,\n type Mode,\n type Observed,\n type StatusValue,\n TimeoutError,\n UnknownError,\n} from './types'\n\n/**\n * Base configuration shared by all dependency monitor modes.\n */\ntype BaseConfig = {\n /**\n * Importance of the dependency:\n * - `'critical'` → service cannot run without it\n * - `'non_critical'` → service is degraded but still functional if it fails\n */\n impact: Impact\n\n /**\n * Polling interval in milliseconds.\n * - Required for polled and async modes\n * - Must not be set for inline mode\n */\n pollRate?: number\n\n /**\n * Polling interval in milliseconds for failed calls.\n * - Defaults to pollRate for polled and async modes\n * - Must not be set for inline mode\n */\n retryRate?: number\n\n /**\n * Maximum response time in milliseconds considered healthy.\n * - A call resolving within this time window **and** returning `\"ok\"` → status `\"ok\"`\n * - A call resolving after this but **before** `timeoutLimitMs` → status `\"degraded\"`\n */\n healthyLimitMs: number\n\n /**\n * Absolute upper bound in milliseconds; beyond this a call is considered `\"error\"`.\n * - Inline: the awaited call is raced with a timeout and rejected past this limit\n * - Polled/Async: escalate `unknown` → `degraded` at `healthyLimitMs`, then `\"error\"` at `timeoutLimitMs`\n * - Any late `\"ok\"` result after this limit is ignored\n */\n timeoutLimitMs: number\n}\n\n/**\n * Inline mode configuration (no polling).\n * `syncCall` runs **only** when {@link DependencyMonitor.check} is invoked.\n */\nexport type SyncInlineConfig = BaseConfig & {\n /** Performs the check immediately when {@link DependencyMonitor.check} is called. */\n syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>\n asyncCall?: never\n pollRate?: undefined\n retryRate?: undefined\n}\n\n/**\n * Polled mode configuration.\n * `syncCall` runs on an interval (`pollRate`) and results are cached.\n */\nexport type SyncPolledConfig = BaseConfig & {\n /** Performs the check at each poll interval. */\n syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>\n /** Polling interval in milliseconds. */\n pollRate: number\n asyncCall?: never\n}\n\n/**\n * Async mode configuration.\n * `asyncCall` starts a check and must report via the provided callback.\n */\nexport type AsyncConfig = BaseConfig & {\n /**\n * Starts an asynchronous check. Must call `reportResponse` once a result is available.\n * The callback may be invoked with a `DependencyStatus | DependencyStatusValue` or an `Error`.\n */\n asyncCall: (\n reportResponse: (\n status: DependencyStatus | DependencyStatusValue | Error\n ) => void | Promise<void>\n ) => void | Promise<void>\n /** Polling interval in milliseconds. */\n pollRate: number\n syncCall?: never\n}\n\n/**\n * Discriminated configuration for a dependency monitor.\n * - {@link SyncInlineConfig} → inline checks on demand\n * - {@link SyncPolledConfig} → synchronous checks on a fixed interval\n * - {@link AsyncConfig} → asynchronous checks that report back via callback\n */\nexport type DependencyMonitorConfig =\n | SyncInlineConfig\n | SyncPolledConfig\n | AsyncConfig\n\n/**\n * Tracks the health of a single dependency in one of three modes:\n *\n * - **inline**: `syncCall` executed only when {@link check} is called\n * - **polled**: `syncCall` executed on `pollRate`; latest result cached\n * - **async**: `asyncCall` executed on `pollRate`, result returned via callback\n *\n * The monitor:\n * - classifies results using `healthyLimitMs` and `timeoutLimitMs`\n * - records freshness (`lastChecked`, `lastSuccess`)\n * - records observed latency (ms) when applicable\n *\n * Status interpretation:\n * - `\"ok\"` only if returned `\"ok\"` **and** latency ≤ `healthyLimitMs`\n * - `\"degraded\"` if returned `\"degraded\"` **or** latency > `healthyLimitMs` but ≤ `timeoutLimitMs`\n * - `\"error\"` if returned `\"error\"`, an `Error`, or exceeded `timeoutLimitMs`\n * - `\"unknown\"` is the initial state before first successful/failed result (polled/async)\n */\nexport class DependencyMonitor {\n /** Immutable configuration for this monitor. */\n private readonly config: DependencyMonitorConfig\n /** Operational mode determined from the configuration. */\n private readonly mode: Mode\n\n /** Last computed status (starts as `\"unknown\"` until first result). */\n private status: StatusValue\n /** Optional error details from the last failure. */\n private error?: CheckError\n /** Last observed metrics (e.g., latency). */\n private observed?: Observed\n /** Freshness timestamps for last check/success. */\n private freshness?: Freshness\n /** Optional details returned by the helth check call. */\n private details?: Record<string, unknown>\n\n /** Indicates whether this monitor has been disposed. */\n private isDisposed = false\n /** Internal timer handle for polling/retry. */\n private timeout?: NodeJS.Timeout\n\n /**\n * Create a new {@link DependencyMonitor}.\n * @param config Monitor configuration (inline, polled, or async).\n */\n constructor(config: DependencyMonitorConfig) {\n this.config = config\n\n this.mode = config.asyncCall\n ? 'async'\n : config.pollRate\n ? 'polled'\n : 'inline'\n\n this.status = 'unknown'\n\n // Deduplicate concurrent inline checks (single-flight).\n if (this.mode === 'inline') {\n this.check = singleFlight(this.check.bind(this))\n }\n\n // Kick off the first cycle for polled/async.\n if (this.mode !== 'inline') {\n this.doCheck()\n }\n }\n\n /** Impact of this dependency (critical/non_critical). */\n public get impact() {\n return this.config.impact\n }\n\n /**\n * Run one check cycle depending on the configured mode.\n * - Inline: no-op here (runs in {@link check})\n * - Polled/Async: invoked automatically and re-scheduled as needed\n */\n private async doCheck() {\n if (this.timeout) {\n clearTimeout(this.timeout)\n }\n if (this.isDisposed) {\n return\n }\n\n if (this.config.syncCall) {\n await this.doSyncCheck()\n } else {\n this.doAsyncCheck()\n }\n }\n\n /**\n * Execute a synchronous (inline/polled) check and update internal state.\n * Classification:\n * - OK if `\"ok\"` and latency ≤ `healthyLimitMs`\n * - Degraded if `\"degraded\"` or latency between `(healthyLimitMs, timeoutLimitMs]`\n * - Error if `\"error\"`, `Error`, or timeout exceeded\n */\n private async doSyncCheck() {\n const start = performance.now()\n\n const { syncCall, timeoutLimitMs } = this.config as SyncInlineConfig\n\n try {\n const response = await runAgainstTimeout(syncCall(), timeoutLimitMs)\n const duration = performance.now() - start\n\n this.handleDependencyResponse(response, duration)\n } catch (err) {\n this.handleDependencyError(err as Error)\n }\n }\n\n /**\n * Execute an asynchronous check (async mode).\n * - Initializes timers to escalate `unknown` → `degraded` → `error`\n * if no callback result arrives within the thresholds.\n * - On callback, clears timers and classifies the result with latency.\n */\n private async doAsyncCheck() {\n const { asyncCall, healthyLimitMs, timeoutLimitMs } = this\n .config as AsyncConfig\n\n const start = performance.now()\n let callActive = true\n let healthTimeout: NodeJS.Timeout | undefined\n let serviceTimeout: NodeJS.Timeout | undefined\n\n asyncCall((response) => {\n if (!callActive) return\n callActive = false\n clearTimeout(healthTimeout)\n clearTimeout(serviceTimeout)\n\n const duration = performance.now() - start\n this.handleDependencyResponse(response, duration)\n })\n\n // Escalate to degraded after healthy limit if still waiting.\n healthTimeout = setTimeout(() => {\n if (callActive) this.status = 'degraded'\n }, healthyLimitMs)\n\n // Escalate to error after timeout limit if still waiting.\n serviceTimeout = setTimeout(() => {\n if (!callActive) return\n callActive = false\n clearTimeout(healthTimeout)\n this.handleDependencyError(new TimeoutError())\n }, timeoutLimitMs)\n }\n\n /**\n * Normalize a successful dependency response into status + metadata.\n * @param response Returned status value or Error from the dependency\n * @param duration Measured latency in milliseconds\n */\n private handleDependencyResponse(\n response: DependencyStatus | DependencyStatusValue | Error,\n duration: number\n ) {\n if (response instanceof Error) {\n return this.handleDependencyError(response)\n }\n\n const normalized: DependencyStatus =\n typeof response === 'string' ? { status: response } : response\n\n if (normalized.status === 'error') {\n return this.handleDependencyError(new UnknownError())\n }\n\n this.error = undefined\n this.details = normalized.details\n this.status =\n normalized.status === 'ok' && duration <= this.config.healthyLimitMs\n ? 'ok'\n : 'degraded'\n\n const end = new Date()\n this.freshness = {\n lastChecked: end.toISOString(),\n lastSuccess: end.toISOString(),\n }\n\n this.observed = { latencyMs: duration }\n\n // Schedule next poll if applicable.\n if (this.config.pollRate && !this.isDisposed) {\n const delay = this.config.pollRate\n this.timeout = setTimeout(() => this.doCheck(), delay)\n }\n }\n\n /**\n * Normalize a failed dependency result into `\"error\"` and update metadata.\n * @param error Error thrown/returned or synthesized (e.g., timeout)\n */\n private handleDependencyError(error: Error & { code?: string }) {\n this.status = 'error'\n this.observed = undefined\n this.error = {\n code: error.code || 'UNKNOWN',\n message: error.message,\n }\n\n const end = new Date()\n if (this.freshness) {\n this.freshness.lastChecked = end.toISOString()\n } else {\n this.freshness = { lastChecked: end.toISOString(), lastSuccess: null }\n }\n\n // Schedule retry/poll if configured.\n if ((this.config.retryRate || this.config.pollRate) && !this.isDisposed) {\n const delay = this.config.retryRate || this.config.pollRate\n this.timeout = setTimeout(() => this.doCheck(), delay)\n }\n }\n\n /**\n * Get a snapshot of the dependency’s current health.\n * - Inline mode: executes the `syncCall` (single-flight guarded)\n * - Polled/Async: returns the cached result\n * @throws if the monitor has been disposed\n */\n public async check(): Promise<DependencyCheck> {\n if (this.isDisposed) {\n throw new Error('DependencyMonitor has been disposed')\n }\n\n if (this.mode === 'inline') {\n await this.doCheck()\n }\n\n const result: DependencyCheck = {\n status: this.status as StatusValue,\n impact: this.config.impact,\n mode: this.mode,\n freshness: this.freshness as Freshness,\n details: this.details,\n observed: this.observed,\n error: this.error,\n }\n\n return result\n }\n\n /** Symbol-based disposer for use with `using`. */\n public [Symbol.dispose]() {\n this.dispose()\n }\n\n /**\n * Dispose the monitor:\n * - Clears any scheduled timers\n * - Prevents further checks from running\n */\n public dispose() {\n this.isDisposed = true\n if (this.timeout) {\n clearTimeout(this.timeout)\n }\n }\n}\n","import os from 'node:os'\nimport type { Liveness, Status } from './types'\n\nexport const ping = (): Status => ({ status: 'ok' })\nexport const liveness = (): Liveness => {\n const cpus = os.cpus()\n const total = os.totalmem()\n const free = os.freemem()\n let memUsedRatio: number\n /* istanbul ignore else */\n if (total > 0) {\n memUsedRatio = (total - free) / total\n } else {\n memUsedRatio = 0\n }\n\n return {\n status: 'ok',\n timestamp: new Date().toISOString(),\n system: {\n uptime: os.uptime(),\n loadavg: os.loadavg() as [number, number, number],\n totalmem: total,\n freemem: free,\n memUsedRatio,\n cpus: {\n count: cpus.length,\n },\n },\n process: {\n uptime: process.uptime(),\n memory: process.memoryUsage(),\n },\n }\n}\n","import { toEntity } from '@sebspark/hyper-media'\nimport { createCache, InMemoryPersistor } from '@sebspark/promise-cache'\nimport { type ErrorRequestHandler, type RequestHandler, Router } from 'express'\nimport type {\n DependencyMonitor,\n DependencyMonitorConfig,\n} from './dependency-monitor'\nimport { liveness, ping } from './static-checks'\nimport { throttle } from './timing'\nimport type {\n DependencyCheck,\n HealthSummary,\n Impact,\n ReadinessPayload,\n ReadinessSummary,\n StatusValue,\n} from './types'\n\nexport interface HealthMonitorConfig {\n throttle: number\n}\n\n/**\n * HealthMonitor wires up standard health check endpoints for an Express app.\n *\n * It provides three endpoints under `/health`:\n * - /ping → lightweight always-OK response (`{ status: \"ok\" }`)\n * - /live → liveness probe (`{ status, uptime, timestamp }`)\n * - /ready → readiness probe with dependency checks (`{ status, checks }`)\n *\n * Dependencies can be added via {@link addDependency} with a {@link DependencyMonitorConfig}.\n * Each dependency is wrapped in a {@link DependencyMonitor} and tracked for readiness.\n *\n * ### Example\n *\n * ```ts\n * import express from 'express'\n * import { HealthMonitor } from './health-monitor'\n *\n * const app = express()\n * const monitor = new HealthMonitor()\n *\n * monitor.addDependency('db', {\n * impact: 'critical',\n * syncCall: async () => {\n * await db.ping()\n * return 'ok'\n * }\n * })\n *\n * app.use(monitor.router)\n * app.listen(3000)\n * ```\n */\nexport class HealthMonitor {\n private readonly _router: Router\n private readonly dependencies: Map<string, DependencyMonitor>\n private isDisposed = false\n\n /**\n * Create a new HealthMonitor instance with its own router and dependency map.\n */\n constructor(config?: HealthMonitorConfig) {\n this._router = this.createRouter()\n this.dependencies = new Map()\n\n const thr = config ? config.throttle : 10\n if (thr > 0) {\n this.ready = throttle(this.ready.bind(this), thr)\n }\n }\n\n /**\n * Register a named dependency to be checked as part of readiness.\n *\n * @param name - Identifier for the dependency (e.g. \"postgres\", \"redis\").\n * @param dependency - DependencyMonitor\n * @returns this for chaining\n *\n * @example\n * ```ts\n * monitor.addDependency('redis', new DependencyMonitor({\n * impact: 'critical',\n * pollRate: 5000,\n * syncCall: async () => redis.ping() ? 'ok' : 'error'\n * }))\n * ```\n */\n public addDependency(name: string, dependency: DependencyMonitor) {\n this.dependencies.set(name, dependency)\n return this\n }\n\n /**\n * Internal: create the Express router with /health routes.\n */\n private createRouter() {\n const router = Router()\n const persistor = new InMemoryPersistor()\n const cache = createCache(persistor)\n\n // Health\n const cachedHealth = cache.wrap(() => this.health(), {\n key: '/health',\n expiry: 1000,\n })\n const healthHandler: RequestHandler = async (\n req,\n res,\n next\n ): Promise<void> => {\n try {\n const health = await cachedHealth()\n res.status(200).json(\n toEntity(req, health, {\n ping: '/health/ping',\n live: '/health/live',\n ready: '/health/ready',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health', healthHandler)\n\n // Ping (no cache handler for ping since that woul actually increase the cost of the call)\n const pingHandler: RequestHandler = (req, res, next) => {\n try {\n res.status(200).json(\n toEntity(req, this.ping(), {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/ping', pingHandler)\n\n // Liveness\n const cachedLiveness = cache.wrap(() => this.live(), {\n key: 'health/live',\n expiry: 1000,\n })\n const livenessHandler: RequestHandler = async (req, res, next) => {\n try {\n const liveness = await cachedLiveness()\n res.status(200).json(\n toEntity(req, liveness, {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/live', livenessHandler)\n\n // Readiness\n const cachedReadiness = cache.wrap(() => this.ready(), {\n key: '/health/ready',\n expiry: 1000,\n })\n const readinessHandler: RequestHandler = async (req, res, next) => {\n try {\n const readiness = await cachedReadiness()\n const status = readiness.summary.critical.failing > 0 ? 503 : 200\n res.status(status).json(\n toEntity(req, readiness, {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/ready', readinessHandler)\n\n // Error handler\n const errorHandler: ErrorRequestHandler = (err, _req, res, _next) => {\n const message = err instanceof Error ? err.message : String(err)\n res.status(500).json({\n status: 'error',\n error: { message },\n })\n }\n router.use(errorHandler)\n\n return router\n }\n\n /**\n * Static ping check — always returns `{ status: \"ok\" }`.\n */\n public ping() {\n return ping()\n }\n\n /**\n * Liveness probe: reports uptime and current timestamp.\n */\n public live() {\n return liveness()\n }\n\n /**\n * Readiness probe: runs all registered dependencies in parallel\n * and aggregates their results into an overall status.\n *\n * - Any **critical error** → `\"error\"`\n * - Else any **critical degraded** or any non-critical degraded/error → `\"degraded\"`\n * - Else → `\"ok\"`\n *\n * @returns Object with overall `status` and per-dependency `checks`\n *\n * @example\n * ```json\n * {\n * \"status\": \"ok\",\n * \"checks\": {\n * \"postgres\": {\n * \"status\": \"ok\",\n * \"impact\": \"critical\",\n * \"mode\": \"inline\",\n * \"freshness\": {\n * \"lastChecked\": \"2025-08-19T12:00:00Z\",\n * \"lastSuccess\": \"2025-08-19T12:00:00Z\"\n * },\n * \"observed\": { \"latencyMs\": 12 }\n * }\n * }\n * }\n * ```\n */\n public async ready(): Promise<ReadinessPayload> {\n const entries = Array.from(this.dependencies.entries())\n\n const settled = await Promise.allSettled(\n entries.map(async ([name, monitor]) => {\n const check = await monitor.check()\n return [name, check] as const\n })\n )\n\n const checks: Record<string, DependencyCheck> = {}\n\n for (let i = 0; i < settled.length; i++) {\n const s = settled[i]\n const [name] = entries[i]\n\n if (s.status === 'fulfilled') {\n const [, check] = s.value\n checks[name] = check\n } else {\n checks[name] = {\n status: 'error',\n impact: this.dependencies.get(name)?.impact as Impact,\n mode: 'polled',\n freshness: {\n lastChecked: new Date().toISOString(),\n lastSuccess: null,\n },\n observed: undefined,\n error: {\n code: 'CHECK_FAILED',\n message: String(s.reason ?? 'unknown error'),\n },\n }\n }\n }\n\n // ----- summary -------------------------------------------------------------\n let criticalOk = 0\n let criticalDegraded = 0\n let criticalFailing = 0\n\n let nonCritOk = 0\n let nonCritDegraded = 0\n let nonCritFailing = 0 // non-critical with status === 'error'\n\n const degradedReasons: string[] = []\n\n for (const [name, c] of Object.entries(checks)) {\n const isCritical = c.impact === 'critical'\n if (c.status === 'unknown') {\n // not yet checked — don't count as ok or failing\n } else if (c.status === 'ok') {\n if (isCritical) criticalOk++\n else nonCritOk++\n } else if (c.status === 'degraded') {\n if (isCritical) criticalDegraded++\n else nonCritDegraded++\n degradedReasons.push(`${name}:degraded`)\n } else {\n // 'error'\n if (isCritical) criticalFailing++\n else nonCritFailing++\n /* istanbul ignore else */\n if (c.error?.code) {\n degradedReasons.push(`${name}:${c.error.code}`)\n } else {\n degradedReasons.push(`${name}:error`)\n }\n }\n }\n\n const summary: ReadinessSummary = {\n critical: {\n ok: criticalOk,\n degraded: criticalDegraded,\n failing: criticalFailing,\n },\n nonCritical: {\n ok: nonCritOk,\n degraded: nonCritDegraded,\n failing: nonCritFailing,\n },\n degradedReasons,\n }\n\n // ----- overall status (same rules as before) -------------------------------\n let status: StatusValue = 'ok'\n const values = Object.values(checks)\n const anyCriticalError = values.some(\n (c) => c.impact === 'critical' && c.status === 'error'\n )\n const anyDegradedOrError = values.some(\n (c) => c.status === 'degraded' || c.status === 'error'\n )\n const anyCriticalDegraded = values.some(\n (c) => c.impact === 'critical' && c.status === 'degraded'\n )\n\n if (anyCriticalError) status = 'error'\n else if (anyCriticalDegraded || anyDegradedOrError) status = 'degraded'\n\n // ----- payload -------------------------------------------------------------\n const payload: ReadinessPayload = {\n status,\n timestamp: new Date().toISOString(),\n // service: { name, version, instanceId } // (optional; if you add config later)\n summary,\n checks,\n }\n\n return payload\n }\n\n public async health() {\n const { status, checks, summary } = await this.ready()\n const { timestamp, system, process } = this.live()\n\n return {\n status,\n timestamp,\n system,\n process,\n checks,\n summary,\n } as HealthSummary\n }\n\n /**\n * Accessor for the Express router that exposes /health endpoints.\n */\n public get router() {\n return this._router\n }\n\n /**\n * Symbol-based disposer for use with `using`.\n */\n public [Symbol.dispose]() {\n this.dispose()\n }\n\n /**\n * Dispose of the monitor:\n * - marks as disposed\n * - (future: could also stop all dependency monitors)\n */\n public dispose() {\n if (this.isDisposed) {\n return\n }\n this.isDisposed = true\n for (const dependency of this.dependencies.values()) {\n dependency.dispose()\n }\n }\n}\n"],"mappings":";;;;;;AAyFA,IAAa,eAAb,cAAkC,MAAM;CACtC,cAAc;EACZ,MAAM,SAAS;EACf,KAAK,OAAO;CACd;AACF;AAEA,IAAa,eAAb,cAAkC,MAAM;CACtC,cAAc;EACZ,MAAM,SAAS;EACf,KAAK,OAAO;CACd;AACF;;;ACnGA,MAAa,QAAQ,OACnB,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;AAExD,MAAa,kBAAkB,OAAO,OAAe;CACnD,MAAM,KAAK,EAAE;CACb,MAAM,IAAI,aAAa;AACzB;AAEA,MAAa,qBACX,SACA,OACe;CACf,IAAK,KAAgB,GACnB,OAAO,QAAQ,KAAK,CAAC,SAAS,gBAAgB,EAAY,CAAC,CAAC;CAG9D,OAAO;AACT;;;;;;;;;AAUA,MAAa,YACX,IACA,OACG;CAGH,IAAI,UAAoB;CACxB,IAAI,cAAqC;CAEzC,MAAM,WAAW,GAAG,SAA2B;EAC7C,IAAI,CAAC,SAAS;GACZ,UAAU,GAAG,GAAG,IAAI;;GAGpB,IAAI,aAAa;IACf,aAAa,WAAW;IACxB,cAAc;GAChB;GAEA,MAAM,iBAAiB;IACrB,IAAI,KAAK,GACP,cAAc;;WACqB;MAC/B,UAAU;MACV,cAAc;KAChB;KACA;IACF;SAEA,UAAU;GAEd;GACA,QAAQ,KAAK,UAAU,QAAQ;EACjC;EAEA,OAAO;CACT;CAGA,OAAO;AACT;;;;;;AAOA,MAAa,gBA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;GACA;EAGW;CACf;CAEA,MAAa,SAAS;EACpB,MAAM,EAAE,QAAQ,QAAQ,YAAY,MAAM,KAAK,MAAM;EACrD,MAAM,EAAE,WAAW,QAAQ,YAAY,KAAK,KAAK;EAEjD,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;EACF;CACF;;;;CAKA,IAAW,SAAS;EAClB,OAAO,KAAK;CACd;;;;CAKA,CAAQ,OAAO,WAAW;EACxB,KAAK,QAAQ;CACf;;;;;;CAOA,UAAiB;EACf,IAAI,KAAK,YACP;EAEF,KAAK,aAAa;EAClB,KAAK,MAAM,cAAc,KAAK,aAAa,OAAO,GAChD,WAAW,QAAQ;CAEvB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/types.ts","../src/timing.ts","../src/dependency-monitor.ts","../src/static-checks.ts","../src/health-monitor.ts"],"sourcesContent":["export type DependencyStatusValue = 'ok' | 'degraded' | 'error'\nexport type DependencyStatus = {\n status: DependencyStatusValue\n details?: Record<string, unknown> | undefined\n}\nexport type StatusValue = DependencyStatusValue | 'unknown' | 'draining'\nexport type Impact = 'critical' | 'non_critical'\nexport type Mode = 'inline' | 'polled' | 'async'\n\nexport type Verb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'\n\nexport type Link = {\n method: Verb\n href: string\n}\n\nexport interface Entity<T> {\n data: T\n links: Record<string, Link>\n}\n\nexport type Status = {\n status: StatusValue\n}\n\nexport type System = {\n uptime: number\n loadavg: [number, number, number] // 1, 5, 15 min\n totalmem: number\n freemem: number\n memUsedRatio: number // 0..1\n cpus: {\n count: number\n }\n}\n\nexport type Process = {\n uptime: number\n memory: NodeJS.MemoryUsage\n}\n\nexport type Liveness = Status & {\n timestamp: string\n system: System\n process: Process\n}\n\nexport type Freshness = {\n lastChecked: string\n lastSuccess: string | null\n}\n\nexport type Observed = {\n latencyMs: number | null\n [k: string]: unknown\n}\n\nexport type CheckError = {\n code: string\n message: string\n}\n\nexport type DependencyCheck = Status & {\n impact: Impact\n mode: Mode\n freshness: Freshness\n observed?: Observed\n details?: Record<string, unknown>\n error?: CheckError | null\n since?: string | null\n}\n\nexport type ReadinessSummary = {\n critical: { ok: number; degraded: number; failing: number }\n nonCritical: { ok: number; degraded: number; failing: number }\n degradedReasons: string[]\n}\n\nexport type ReadinessPayload = Status & {\n timestamp: string\n service?: { name?: string; version?: string; instanceId?: string }\n summary: ReadinessSummary\n checks: Record<string, DependencyCheck>\n}\n\nexport type HealthSummary = Status &\n Pick<ReadinessPayload, 'summary' | 'checks'> &\n Pick<Liveness, 'system' | 'process'> & { timestamp: string }\n\nexport class TimeoutError extends Error {\n constructor() {\n super('timeout')\n this.name = 'TimeoutError'\n }\n}\n\nexport class UnknownError extends Error {\n constructor() {\n super('unknown')\n this.name = 'UnknownError'\n }\n}\n","import { TimeoutError } from './types'\n\nexport const wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(resolve, ms))\n\nexport const runTimeoutTimer = async (ms: number) => {\n await wait(ms)\n throw new TimeoutError()\n}\n\nexport const runAgainstTimeout = <T>(\n promise: Promise<T>,\n ms?: number | undefined\n): Promise<T> => {\n if ((ms as number) > 0) {\n return Promise.race([promise, runTimeoutTimer(ms as number)])\n }\n\n return promise\n}\n\n/**\n * Throttles an async function:\n * - coalesces concurrent calls into a single in-flight Promise,\n * - after it settles, reuses that settled Promise for `ms` ms,\n * - then clears so the next call invokes `fn` again.\n *\n * Fully preserves the original function signature.\n */\nexport const throttle = <F extends (...args: unknown[]) => Promise<unknown>>(\n fn: F,\n ms: number\n) => {\n type R = ReturnType<F> // a Promise<T>\n\n let current: R | null = null\n let clearHandle: NodeJS.Timeout | null = null\n\n const wrapped = (...args: Parameters<F>): R => {\n if (!current) {\n current = fn(...args) as R\n\n /* istanbul ignore next */\n if (clearHandle) {\n clearTimeout(clearHandle)\n clearHandle = null\n }\n\n const schedule = () => {\n if (ms > 0) {\n clearHandle = setTimeout(\n /* istanbul ignore next */ () => {\n current = null\n clearHandle = null\n },\n ms\n )\n } else {\n current = null\n }\n }\n current.then(schedule, schedule)\n }\n\n return current\n }\n\n // Cast to F so the returned function has the *identical* callable type\n return wrapped as unknown as F\n}\n\n/**\n * Wraps an async function so that concurrent invocations share the same in-flight Promise.\n * After the Promise settles (resolve or reject), the next call will invoke the function again.\n * Essentially just throttled with timeout 0\n */\nexport const singleFlight = <\n F extends (...args: unknown[]) => Promise<unknown>,\n>(\n fn: F\n) => throttle<F>(fn, 0)\n","import { performance } from 'node:perf_hooks'\nimport { runAgainstTimeout, singleFlight } from './timing'\nimport {\n type CheckError,\n type DependencyCheck,\n type DependencyStatus,\n type DependencyStatusValue,\n type Freshness,\n type Impact,\n type Mode,\n type Observed,\n type StatusValue,\n TimeoutError,\n UnknownError,\n} from './types'\n\n/**\n * Base configuration shared by all dependency monitor modes.\n */\ntype BaseConfig = {\n /**\n * Importance of the dependency:\n * - `'critical'` → service cannot run without it\n * - `'non_critical'` → service is degraded but still functional if it fails\n */\n impact: Impact\n\n /**\n * Polling interval in milliseconds.\n * - Required for polled and async modes\n * - Must not be set for inline mode\n */\n pollRate?: number\n\n /**\n * Polling interval in milliseconds for failed calls.\n * - Defaults to pollRate for polled and async modes\n * - Must not be set for inline mode\n */\n retryRate?: number\n\n /**\n * Maximum response time in milliseconds considered healthy.\n * - A call resolving within this time window **and** returning `\"ok\"` → status `\"ok\"`\n * - A call resolving after this but **before** `timeoutLimitMs` → status `\"degraded\"`\n */\n healthyLimitMs: number\n\n /**\n * Absolute upper bound in milliseconds; beyond this a call is considered `\"error\"`.\n * - Inline: the awaited call is raced with a timeout and rejected past this limit\n * - Polled/Async: escalate `unknown` → `degraded` at `healthyLimitMs`, then `\"error\"` at `timeoutLimitMs`\n * - Any late `\"ok\"` result after this limit is ignored\n */\n timeoutLimitMs: number\n}\n\n/**\n * Inline mode configuration (no polling).\n * `syncCall` runs **only** when {@link DependencyMonitor.check} is invoked.\n */\nexport type SyncInlineConfig = BaseConfig & {\n /** Performs the check immediately when {@link DependencyMonitor.check} is called. */\n syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>\n asyncCall?: never\n pollRate?: undefined\n retryRate?: undefined\n}\n\n/**\n * Polled mode configuration.\n * `syncCall` runs on an interval (`pollRate`) and results are cached.\n */\nexport type SyncPolledConfig = BaseConfig & {\n /** Performs the check at each poll interval. */\n syncCall: () => Promise<DependencyStatus | DependencyStatusValue | Error>\n /** Polling interval in milliseconds. */\n pollRate: number\n asyncCall?: never\n}\n\n/**\n * Async mode configuration.\n * `asyncCall` starts a check and must report via the provided callback.\n */\nexport type AsyncConfig = BaseConfig & {\n /**\n * Starts an asynchronous check. Must call `reportResponse` once a result is available.\n * The callback may be invoked with a `DependencyStatus | DependencyStatusValue` or an `Error`.\n */\n asyncCall: (\n reportResponse: (\n status: DependencyStatus | DependencyStatusValue | Error\n ) => void | Promise<void>\n ) => void | Promise<void>\n /** Polling interval in milliseconds. */\n pollRate: number\n syncCall?: never\n}\n\n/**\n * Discriminated configuration for a dependency monitor.\n * - {@link SyncInlineConfig} → inline checks on demand\n * - {@link SyncPolledConfig} → synchronous checks on a fixed interval\n * - {@link AsyncConfig} → asynchronous checks that report back via callback\n */\nexport type DependencyMonitorConfig =\n | SyncInlineConfig\n | SyncPolledConfig\n | AsyncConfig\n\n/**\n * Tracks the health of a single dependency in one of three modes:\n *\n * - **inline**: `syncCall` executed only when {@link check} is called\n * - **polled**: `syncCall` executed on `pollRate`; latest result cached\n * - **async**: `asyncCall` executed on `pollRate`, result returned via callback\n *\n * The monitor:\n * - classifies results using `healthyLimitMs` and `timeoutLimitMs`\n * - records freshness (`lastChecked`, `lastSuccess`)\n * - records observed latency (ms) when applicable\n *\n * Status interpretation:\n * - `\"ok\"` only if returned `\"ok\"` **and** latency ≤ `healthyLimitMs`\n * - `\"degraded\"` if returned `\"degraded\"` **or** latency > `healthyLimitMs` but ≤ `timeoutLimitMs`\n * - `\"error\"` if returned `\"error\"`, an `Error`, or exceeded `timeoutLimitMs`\n * - `\"unknown\"` is the initial state before first successful/failed result (polled/async)\n */\nexport class DependencyMonitor {\n /** Immutable configuration for this monitor. */\n private readonly config: DependencyMonitorConfig\n /** Operational mode determined from the configuration. */\n private readonly mode: Mode\n\n /** Last computed status (starts as `\"unknown\"` until first result). */\n private status: StatusValue\n /** Optional error details from the last failure. */\n private error?: CheckError\n /** Last observed metrics (e.g., latency). */\n private observed?: Observed\n /** Freshness timestamps for last check/success. */\n private freshness?: Freshness\n /** Optional details returned by the helth check call. */\n private details?: Record<string, unknown>\n\n /** Indicates whether this monitor has been disposed. */\n private isDisposed = false\n /** Internal timer handle for polling/retry. */\n private timeout?: NodeJS.Timeout\n\n /**\n * Create a new {@link DependencyMonitor}.\n * @param config Monitor configuration (inline, polled, or async).\n */\n constructor(config: DependencyMonitorConfig) {\n this.config = config\n\n this.mode = config.asyncCall\n ? 'async'\n : config.pollRate\n ? 'polled'\n : 'inline'\n\n this.status = 'unknown'\n\n // Deduplicate concurrent inline checks (single-flight).\n if (this.mode === 'inline') {\n this.check = singleFlight(this.check.bind(this))\n }\n\n // Kick off the first cycle for polled/async.\n if (this.mode !== 'inline') {\n this.doCheck()\n }\n }\n\n /** Impact of this dependency (critical/non_critical). */\n public get impact() {\n return this.config.impact\n }\n\n /**\n * Run one check cycle depending on the configured mode.\n * - Inline: no-op here (runs in {@link check})\n * - Polled/Async: invoked automatically and re-scheduled as needed\n */\n private async doCheck() {\n if (this.timeout) {\n clearTimeout(this.timeout)\n }\n if (this.isDisposed) {\n return\n }\n\n if (this.config.syncCall) {\n await this.doSyncCheck()\n } else {\n this.doAsyncCheck()\n }\n }\n\n /**\n * Execute a synchronous (inline/polled) check and update internal state.\n * Classification:\n * - OK if `\"ok\"` and latency ≤ `healthyLimitMs`\n * - Degraded if `\"degraded\"` or latency between `(healthyLimitMs, timeoutLimitMs]`\n * - Error if `\"error\"`, `Error`, or timeout exceeded\n */\n private async doSyncCheck() {\n const start = performance.now()\n\n const { syncCall, timeoutLimitMs } = this.config as SyncInlineConfig\n\n try {\n const response = await runAgainstTimeout(syncCall(), timeoutLimitMs)\n const duration = performance.now() - start\n\n this.handleDependencyResponse(response, duration)\n } catch (err) {\n this.handleDependencyError(err as Error)\n }\n }\n\n /**\n * Execute an asynchronous check (async mode).\n * - Initializes timers to escalate `unknown` → `degraded` → `error`\n * if no callback result arrives within the thresholds.\n * - On callback, clears timers and classifies the result with latency.\n */\n private async doAsyncCheck() {\n const { asyncCall, healthyLimitMs, timeoutLimitMs } = this\n .config as AsyncConfig\n\n const start = performance.now()\n let callActive = true\n let healthTimeout: NodeJS.Timeout | undefined\n let serviceTimeout: NodeJS.Timeout | undefined\n\n asyncCall((response) => {\n if (!callActive) return\n callActive = false\n clearTimeout(healthTimeout)\n clearTimeout(serviceTimeout)\n\n const duration = performance.now() - start\n this.handleDependencyResponse(response, duration)\n })\n\n // Escalate to degraded after healthy limit if still waiting.\n healthTimeout = setTimeout(() => {\n if (callActive) this.status = 'degraded'\n }, healthyLimitMs)\n\n // Escalate to error after timeout limit if still waiting.\n serviceTimeout = setTimeout(() => {\n if (!callActive) return\n callActive = false\n clearTimeout(healthTimeout)\n this.handleDependencyError(new TimeoutError())\n }, timeoutLimitMs)\n }\n\n /**\n * Normalize a successful dependency response into status + metadata.\n * @param response Returned status value or Error from the dependency\n * @param duration Measured latency in milliseconds\n */\n private handleDependencyResponse(\n response: DependencyStatus | DependencyStatusValue | Error,\n duration: number\n ) {\n if (response instanceof Error) {\n return this.handleDependencyError(response)\n }\n\n const normalized: DependencyStatus =\n typeof response === 'string' ? { status: response } : response\n\n if (normalized.status === 'error') {\n return this.handleDependencyError(new UnknownError())\n }\n\n this.error = undefined\n this.details = normalized.details\n this.status =\n normalized.status === 'ok' && duration <= this.config.healthyLimitMs\n ? 'ok'\n : 'degraded'\n\n const end = new Date()\n this.freshness = {\n lastChecked: end.toISOString(),\n lastSuccess: end.toISOString(),\n }\n\n this.observed = { latencyMs: duration }\n\n // Schedule next poll if applicable.\n if (this.config.pollRate && !this.isDisposed) {\n const delay = this.config.pollRate\n this.timeout = setTimeout(() => this.doCheck(), delay)\n }\n }\n\n /**\n * Normalize a failed dependency result into `\"error\"` and update metadata.\n * @param error Error thrown/returned or synthesized (e.g., timeout)\n */\n private handleDependencyError(error: Error & { code?: string }) {\n this.status = 'error'\n this.observed = undefined\n this.error = {\n code: error.code || 'UNKNOWN',\n message: error.message,\n }\n\n const end = new Date()\n if (this.freshness) {\n this.freshness.lastChecked = end.toISOString()\n } else {\n this.freshness = { lastChecked: end.toISOString(), lastSuccess: null }\n }\n\n // Schedule retry/poll if configured.\n if ((this.config.retryRate || this.config.pollRate) && !this.isDisposed) {\n const delay = this.config.retryRate || this.config.pollRate\n this.timeout = setTimeout(() => this.doCheck(), delay)\n }\n }\n\n /**\n * Get a snapshot of the dependency’s current health.\n * - Inline mode: executes the `syncCall` (single-flight guarded)\n * - Polled/Async: returns the cached result\n * @throws if the monitor has been disposed\n */\n public async check(): Promise<DependencyCheck> {\n if (this.isDisposed) {\n throw new Error('DependencyMonitor has been disposed')\n }\n\n if (this.mode === 'inline') {\n await this.doCheck()\n }\n\n const result: DependencyCheck = {\n status: this.status as StatusValue,\n impact: this.config.impact,\n mode: this.mode,\n freshness: this.freshness as Freshness,\n details: this.details,\n observed: this.observed,\n error: this.error,\n }\n\n return result\n }\n\n /** Symbol-based disposer for use with `using`. */\n public [Symbol.dispose]() {\n this.dispose()\n }\n\n /**\n * Dispose the monitor:\n * - Clears any scheduled timers\n * - Prevents further checks from running\n */\n public dispose() {\n this.isDisposed = true\n if (this.timeout) {\n clearTimeout(this.timeout)\n }\n }\n}\n","import os from 'node:os'\nimport type { Liveness, Status } from './types'\n\nexport const ping = (): Status => ({ status: 'ok' })\nexport const liveness = (): Liveness => {\n const cpus = os.cpus()\n const total = os.totalmem()\n const free = os.freemem()\n let memUsedRatio: number\n /* istanbul ignore else */\n if (total > 0) {\n memUsedRatio = (total - free) / total\n } else {\n memUsedRatio = 0\n }\n\n return {\n status: 'ok',\n timestamp: new Date().toISOString(),\n system: {\n uptime: os.uptime(),\n loadavg: os.loadavg() as [number, number, number],\n totalmem: total,\n freemem: free,\n memUsedRatio,\n cpus: {\n count: cpus.length,\n },\n },\n process: {\n uptime: process.uptime(),\n memory: process.memoryUsage(),\n },\n }\n}\n","import { toEntity } from '@sebspark/hyper-media'\nimport { createCache, InMemoryPersistor } from '@sebspark/promise-cache'\nimport { type ErrorRequestHandler, type RequestHandler, Router } from 'express'\nimport type {\n DependencyMonitor,\n DependencyMonitorConfig,\n} from './dependency-monitor'\nimport { liveness, ping } from './static-checks'\nimport { throttle } from './timing'\nimport type {\n DependencyCheck,\n HealthSummary,\n Impact,\n ReadinessPayload,\n ReadinessSummary,\n StatusValue,\n} from './types'\n\nexport interface HealthMonitorConfig {\n throttle: number\n}\n\n/**\n * HealthMonitor wires up standard health check endpoints for an Express app.\n *\n * It provides three endpoints under `/health`:\n * - /ping → lightweight always-OK response (`{ status: \"ok\" }`)\n * - /live → liveness probe (`{ status, uptime, timestamp }`)\n * - /ready → readiness probe with dependency checks (`{ status, checks }`)\n *\n * Dependencies can be added via {@link addDependency} with a {@link DependencyMonitorConfig}.\n * Each dependency is wrapped in a {@link DependencyMonitor} and tracked for readiness.\n *\n * ### Example\n *\n * ```ts\n * import express from 'express'\n * import { HealthMonitor } from './health-monitor'\n *\n * const app = express()\n * const monitor = new HealthMonitor()\n *\n * monitor.addDependency('db', {\n * impact: 'critical',\n * syncCall: async () => {\n * await db.ping()\n * return 'ok'\n * }\n * })\n *\n * app.use(monitor.router)\n * app.listen(3000)\n * ```\n */\nexport class HealthMonitor {\n private readonly _router: Router\n private readonly dependencies: Map<string, DependencyMonitor>\n private isDisposed = false\n\n /**\n * Create a new HealthMonitor instance with its own router and dependency map.\n */\n constructor(config?: HealthMonitorConfig) {\n this._router = this.createRouter()\n this.dependencies = new Map()\n\n const thr = config ? config.throttle : 10\n if (thr > 0) {\n this.ready = throttle(this.ready.bind(this), thr)\n }\n }\n\n /**\n * Register a named dependency to be checked as part of readiness.\n *\n * @param name - Identifier for the dependency (e.g. \"postgres\", \"redis\").\n * @param dependency - DependencyMonitor\n * @returns this for chaining\n *\n * @example\n * ```ts\n * monitor.addDependency('redis', new DependencyMonitor({\n * impact: 'critical',\n * pollRate: 5000,\n * syncCall: async () => redis.ping() ? 'ok' : 'error'\n * }))\n * ```\n */\n public addDependency(name: string, dependency: DependencyMonitor) {\n this.dependencies.set(name, dependency)\n return this\n }\n\n /**\n * Internal: create the Express router with /health routes.\n */\n private createRouter() {\n const router = Router()\n const persistor = new InMemoryPersistor()\n const cache = createCache(persistor)\n\n // Health\n const cachedHealth = cache.wrap(() => this.health(), {\n key: '/health',\n expiry: 1000,\n })\n const healthHandler: RequestHandler = async (\n req,\n res,\n next\n ): Promise<void> => {\n try {\n const health = await cachedHealth()\n res.status(200).json(\n toEntity(req, health, {\n ping: '/health/ping',\n live: '/health/live',\n ready: '/health/ready',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health', healthHandler)\n\n // Ping (no cache handler for ping since that woul actually increase the cost of the call)\n const pingHandler: RequestHandler = (req, res, next) => {\n try {\n res.status(200).json(\n toEntity(req, this.ping(), {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/ping', pingHandler)\n\n // Liveness\n const cachedLiveness = cache.wrap(() => this.live(), {\n key: 'health/live',\n expiry: 1000,\n })\n const livenessHandler: RequestHandler = async (req, res, next) => {\n try {\n const liveness = await cachedLiveness()\n res.status(200).json(\n toEntity(req, liveness, {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/live', livenessHandler)\n\n // Readiness\n const cachedReadiness = cache.wrap(() => this.ready(), {\n key: '/health/ready',\n expiry: 1000,\n })\n const readinessHandler: RequestHandler = async (req, res, next) => {\n try {\n const readiness = await cachedReadiness()\n const status = readiness.summary.critical.failing > 0 ? 503 : 200\n res.status(status).json(\n toEntity(req, readiness, {\n health: '/health',\n })\n )\n } catch (err) {\n next?.(err)\n }\n }\n router.get('/health/ready', readinessHandler)\n\n // Error handler\n const errorHandler: ErrorRequestHandler = (err, _req, res, _next) => {\n const message = err instanceof Error ? err.message : String(err)\n res.status(500).json({\n status: 'error',\n error: { message },\n })\n }\n router.use(errorHandler)\n\n return router\n }\n\n /**\n * Static ping check — always returns `{ status: \"ok\" }`.\n */\n public ping() {\n return ping()\n }\n\n /**\n * Liveness probe: reports uptime and current timestamp.\n */\n public live() {\n return liveness()\n }\n\n /**\n * Readiness probe: runs all registered dependencies in parallel\n * and aggregates their results into an overall status.\n *\n * - Any **critical error** → `\"error\"`\n * - Else any **critical degraded** or any non-critical degraded/error → `\"degraded\"`\n * - Else → `\"ok\"`\n *\n * @returns Object with overall `status` and per-dependency `checks`\n *\n * @example\n * ```json\n * {\n * \"status\": \"ok\",\n * \"checks\": {\n * \"postgres\": {\n * \"status\": \"ok\",\n * \"impact\": \"critical\",\n * \"mode\": \"inline\",\n * \"freshness\": {\n * \"lastChecked\": \"2025-08-19T12:00:00Z\",\n * \"lastSuccess\": \"2025-08-19T12:00:00Z\"\n * },\n * \"observed\": { \"latencyMs\": 12 }\n * }\n * }\n * }\n * ```\n */\n public async ready(): Promise<ReadinessPayload> {\n const entries = Array.from(this.dependencies.entries())\n\n const settled = await Promise.allSettled(\n entries.map(async ([name, monitor]) => {\n const check = await monitor.check()\n return [name, check] as const\n })\n )\n\n const checks: Record<string, DependencyCheck> = {}\n\n for (let i = 0; i < settled.length; i++) {\n const s = settled[i]\n const [name] = entries[i]\n\n if (s.status === 'fulfilled') {\n const [, check] = s.value\n checks[name] = check\n } else {\n checks[name] = {\n status: 'error',\n impact: this.dependencies.get(name)?.impact as Impact,\n mode: 'polled',\n freshness: {\n lastChecked: new Date().toISOString(),\n lastSuccess: null,\n },\n observed: undefined,\n error: {\n code: 'CHECK_FAILED',\n message: String(s.reason ?? 'unknown error'),\n },\n }\n }\n }\n\n // ----- summary -------------------------------------------------------------\n let criticalOk = 0\n let criticalDegraded = 0\n let criticalFailing = 0\n\n let nonCritOk = 0\n let nonCritDegraded = 0\n let nonCritFailing = 0 // non-critical with status === 'error'\n\n const degradedReasons: string[] = []\n\n for (const [name, c] of Object.entries(checks)) {\n const isCritical = c.impact === 'critical'\n if (c.status === 'unknown') {\n // not yet checked — don't count as ok or failing\n } else if (c.status === 'ok') {\n if (isCritical) criticalOk++\n else nonCritOk++\n } else if (c.status === 'degraded') {\n if (isCritical) criticalDegraded++\n else nonCritDegraded++\n degradedReasons.push(`${name}:degraded`)\n } else {\n // 'error'\n if (isCritical) criticalFailing++\n else nonCritFailing++\n /* istanbul ignore else */\n if (c.error?.code) {\n degradedReasons.push(`${name}:${c.error.code}`)\n } else {\n degradedReasons.push(`${name}:error`)\n }\n }\n }\n\n const summary: ReadinessSummary = {\n critical: {\n ok: criticalOk,\n degraded: criticalDegraded,\n failing: criticalFailing,\n },\n nonCritical: {\n ok: nonCritOk,\n degraded: nonCritDegraded,\n failing: nonCritFailing,\n },\n degradedReasons,\n }\n\n // ----- overall status (same rules as before) -------------------------------\n let status: StatusValue = 'ok'\n const values = Object.values(checks)\n const anyCriticalError = values.some(\n (c) => c.impact === 'critical' && c.status === 'error'\n )\n const anyDegradedOrError = values.some(\n (c) => c.status === 'degraded' || c.status === 'error'\n )\n const anyCriticalDegraded = values.some(\n (c) => c.impact === 'critical' && c.status === 'degraded'\n )\n\n if (anyCriticalError) status = 'error'\n else if (anyCriticalDegraded || anyDegradedOrError) status = 'degraded'\n\n // ----- payload -------------------------------------------------------------\n const payload: ReadinessPayload = {\n status,\n timestamp: new Date().toISOString(),\n // service: { name, version, instanceId } // (optional; if you add config later)\n summary,\n checks,\n }\n\n return payload\n }\n\n public async health() {\n const { status, checks, summary } = await this.ready()\n const { timestamp, system, process } = this.live()\n\n return {\n status,\n timestamp,\n system,\n process,\n checks,\n summary,\n } as HealthSummary\n }\n\n /**\n * Accessor for the Express router that exposes /health endpoints.\n */\n public get router() {\n return this._router\n }\n\n /**\n * Symbol-based disposer for use with `using`.\n */\n public [Symbol.dispose]() {\n this.dispose()\n }\n\n /**\n * Dispose of the monitor:\n * - marks as disposed\n * - (future: could also stop all dependency monitors)\n */\n public dispose() {\n if (this.isDisposed) {\n return\n }\n this.isDisposed = true\n for (const dependency of this.dependencies.values()) {\n dependency.dispose()\n }\n }\n}\n"],"mappings":";;;;;;AAyFA,IAAa,eAAb,cAAkC,MAAM;CACtC,cAAc;EACZ,MAAM,SAAS;EACf,KAAK,OAAO;CACd;AACF;AAEA,IAAa,eAAb,cAAkC,MAAM;CACtC,cAAc;EACZ,MAAM,SAAS;EACf,KAAK,OAAO;CACd;AACF;;;ACnGA,MAAa,QAAQ,OACnB,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;AAExD,MAAa,kBAAkB,OAAO,OAAe;CACnD,MAAM,KAAK,EAAE;CACb,MAAM,IAAI,aAAa;AACzB;AAEA,MAAa,qBACX,SACA,OACe;CACf,IAAK,KAAgB,GACnB,OAAO,QAAQ,KAAK,CAAC,SAAS,gBAAgB,EAAY,CAAC,CAAC;CAG9D,OAAO;AACT;;;;;;;;;AAUA,MAAa,YACX,IACA,OACG;CAGH,IAAI,UAAoB;CACxB,IAAI,cAAqC;CAEzC,MAAM,WAAW,GAAG,SAA2B;EAC7C,IAAI,CAAC,SAAS;GACZ,UAAU,GAAG,GAAG,IAAI;;GAGpB,IAAI,aAAa;IACf,aAAa,WAAW;IACxB,cAAc;GAChB;GAEA,MAAM,iBAAiB;IACrB,IAAI,KAAK,GACP,cAAc;;WACqB;MAC/B,UAAU;MACV,cAAc;KAChB;KACA;IACF;SAEA,UAAU;GAEd;GACA,QAAQ,KAAK,UAAU,QAAQ;EACjC;EAEA,OAAO;CACT;CAGA,OAAO;AACT;;;;;;AAOA,MAAa,gBAGX,OACG,SAAY,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;ACiDtB,IAAa,oBAAb,MAA+B;;CAE7B;;CAEA;;CAGA;;CAEA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AM,KAAK,MAAM;EACrD,MAAM,EAAE,WAAW,QAAQ,YAAY,KAAK,KAAK;EAEjD,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;EACF;CACF;;;;CAKA,IAAW,SAAS;EAClB,OAAO,KAAK;CACd;;;;CAKA,CAAQ,OAAO,WAAW;EACxB,KAAK,QAAQ;CACf;;;;;;CAOA,UAAiB;EACf,IAAI,KAAK,YACP;EAEF,KAAK,aAAa;EAClB,KAAK,MAAM,cAAc,KAAK,aAAa,OAAO,GAChD,WAAW,QAAQ;CAEvB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/health-check",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -19,27 +19,32 @@
|
|
|
19
19
|
"dev": "tsc --watch --noEmit",
|
|
20
20
|
"lint": "biome check .",
|
|
21
21
|
"test": "vitest run --passWithNoTests --coverage",
|
|
22
|
-
"test:e2e": "vitest run --config ../../vitest.e2e.config.
|
|
23
|
-
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
22
|
+
"test:e2e": "vitest run --config ../../vitest.e2e.config.mts",
|
|
23
|
+
"typecheck": "vitest --typecheck.only --passWithNoTests --run"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@sebspark/hyper-media": "0.1.
|
|
27
|
-
"@sebspark/promise-cache": "8.1.
|
|
26
|
+
"@sebspark/hyper-media": "0.1.5",
|
|
27
|
+
"@sebspark/promise-cache": "8.1.6",
|
|
28
28
|
"express": "5.2.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@testcontainers/
|
|
35
|
-
"mockserver
|
|
36
|
-
"
|
|
31
|
+
"@biomejs/biome": "2.5.12",
|
|
32
|
+
"@google-cloud/pubsub": "6.0.1",
|
|
33
|
+
"@sebspark/tsconfig": "*",
|
|
34
|
+
"@testcontainers/gcloud": "12.1.0",
|
|
35
|
+
"@testcontainers/mockserver": "12.1.0",
|
|
36
|
+
"@testcontainers/redis": "12.1.0",
|
|
37
|
+
"mockserver-client": "7.6.0",
|
|
38
|
+
"supertest": "7.2.2",
|
|
39
|
+
"typescript": "7.0.2",
|
|
40
|
+
"vite": "8.2.2",
|
|
41
|
+
"vitest": "5.0.0"
|
|
37
42
|
},
|
|
38
43
|
"resolutions": {
|
|
39
|
-
"protobufjs": "8.
|
|
44
|
+
"protobufjs": "8.8.0"
|
|
40
45
|
},
|
|
41
46
|
"repository": {
|
|
42
47
|
"type": "git",
|
|
43
48
|
"url": "https://github.com/seb-oss/Spark-packages.git"
|
|
44
49
|
}
|
|
45
|
-
}
|
|
50
|
+
}
|