od-temp 1.0.4 → 1.0.5

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.
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env node
2
+ const require_index_cli = require('./index.cli.cjs');
3
+
4
+ //#region src/health/HealthCheck.ts
5
+ var HealthChecker = class {
6
+ constructor(detector) {
7
+ this.detector = detector;
8
+ this.initTime = Date.now();
9
+ }
10
+ /**
11
+ * Run complete health check
12
+ */
13
+ async check(options = {}) {
14
+ const result = {
15
+ status: "healthy",
16
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
17
+ checks: {
18
+ detector: {
19
+ status: "pass",
20
+ message: "Detector initialized"
21
+ },
22
+ patterns: {
23
+ status: "pass",
24
+ message: "Patterns loaded"
25
+ },
26
+ performance: {
27
+ status: "pass",
28
+ message: "Performance acceptable"
29
+ },
30
+ memory: {
31
+ status: "pass",
32
+ message: "Memory usage normal"
33
+ }
34
+ },
35
+ metrics: {
36
+ totalPatterns: 0,
37
+ compiledPatterns: 0,
38
+ cacheEnabled: false,
39
+ uptime: Date.now() - this.initTime
40
+ },
41
+ errors: [],
42
+ warnings: []
43
+ };
44
+ try {
45
+ result.checks.detector = await this.checkDetector(options);
46
+ result.checks.patterns = await this.checkPatterns();
47
+ if (options.checkPerformance !== false) result.checks.performance = await this.checkPerformance(options.performanceThreshold);
48
+ result.checks.memory = await this.checkMemory(options.memoryThreshold);
49
+ result.metrics = this.collectMetrics();
50
+ result.status = this.determineOverallStatus(result.checks);
51
+ for (const check of Object.values(result.checks)) if (check.status === "fail") result.errors.push(check.message);
52
+ else if (check.status === "warn") result.warnings.push(check.message);
53
+ } catch (error) {
54
+ result.status = "unhealthy";
55
+ result.errors.push(`Health check failed: ${error.message}`);
56
+ }
57
+ return result;
58
+ }
59
+ /**
60
+ * Check detector functionality
61
+ */
62
+ async checkDetector(options) {
63
+ try {
64
+ if (options.testDetection !== false) {
65
+ const result = await this.detector.detect("Test email: test@example.com");
66
+ if (!result || !result.detections) return {
67
+ status: "fail",
68
+ message: "Detector returned invalid result"
69
+ };
70
+ if (result.detections.length === 0) return {
71
+ status: "warn",
72
+ message: "Test detection found no PII (expected at least 1)"
73
+ };
74
+ }
75
+ return {
76
+ status: "pass",
77
+ message: "Detector functioning correctly"
78
+ };
79
+ } catch (error) {
80
+ return {
81
+ status: "fail",
82
+ message: `Detector check failed: ${error.message}`
83
+ };
84
+ }
85
+ }
86
+ /**
87
+ * Check patterns are loaded
88
+ */
89
+ async checkPatterns() {
90
+ try {
91
+ const patterns = this.detector.getPatterns();
92
+ if (!patterns || patterns.length === 0) return {
93
+ status: "fail",
94
+ message: "No patterns loaded",
95
+ value: 0,
96
+ threshold: 1
97
+ };
98
+ if (patterns.length < 10) return {
99
+ status: "warn",
100
+ message: "Very few patterns loaded (expected more)",
101
+ value: patterns.length,
102
+ threshold: 10
103
+ };
104
+ return {
105
+ status: "pass",
106
+ message: `${patterns.length} patterns loaded`,
107
+ value: patterns.length
108
+ };
109
+ } catch (error) {
110
+ return {
111
+ status: "fail",
112
+ message: `Pattern check failed: ${error.message}`
113
+ };
114
+ }
115
+ }
116
+ /**
117
+ * Check performance
118
+ */
119
+ async checkPerformance(threshold = 100) {
120
+ try {
121
+ const testText = "Test: john@example.com, phone: 555-123-4567, IP: 192.168.1.1";
122
+ const start = performance.now();
123
+ await this.detector.detect(testText);
124
+ const duration = performance.now() - start;
125
+ if (duration > threshold * 2) return {
126
+ status: "fail",
127
+ message: `Performance degraded: ${duration.toFixed(2)}ms`,
128
+ value: duration,
129
+ threshold
130
+ };
131
+ if (duration > threshold) return {
132
+ status: "warn",
133
+ message: `Performance slower than expected: ${duration.toFixed(2)}ms`,
134
+ value: duration,
135
+ threshold
136
+ };
137
+ return {
138
+ status: "pass",
139
+ message: `Performance good: ${duration.toFixed(2)}ms`,
140
+ value: duration,
141
+ threshold
142
+ };
143
+ } catch (error) {
144
+ return {
145
+ status: "fail",
146
+ message: `Performance check failed: ${error.message}`
147
+ };
148
+ }
149
+ }
150
+ /**
151
+ * Check memory usage
152
+ */
153
+ async checkMemory(threshold = 100) {
154
+ try {
155
+ if (typeof process === "undefined" || !process.memoryUsage) return {
156
+ status: "pass",
157
+ message: "Memory check skipped (not in Node.js)"
158
+ };
159
+ const heapUsedMB = process.memoryUsage().heapUsed / 1024 / 1024;
160
+ if (heapUsedMB > threshold * 2) return {
161
+ status: "fail",
162
+ message: `High memory usage: ${heapUsedMB.toFixed(2)}MB`,
163
+ value: heapUsedMB,
164
+ threshold
165
+ };
166
+ if (heapUsedMB > threshold) return {
167
+ status: "warn",
168
+ message: `Elevated memory usage: ${heapUsedMB.toFixed(2)}MB`,
169
+ value: heapUsedMB,
170
+ threshold
171
+ };
172
+ return {
173
+ status: "pass",
174
+ message: `Memory usage normal: ${heapUsedMB.toFixed(2)}MB`,
175
+ value: heapUsedMB,
176
+ threshold
177
+ };
178
+ } catch (error) {
179
+ return {
180
+ status: "warn",
181
+ message: `Memory check skipped: ${error.message}`
182
+ };
183
+ }
184
+ }
185
+ /**
186
+ * Collect metrics
187
+ */
188
+ collectMetrics() {
189
+ const patterns = this.detector.getPatterns();
190
+ const cacheStats = this.detector.getCacheStats();
191
+ return {
192
+ totalPatterns: patterns.length,
193
+ compiledPatterns: patterns.length,
194
+ cacheSize: cacheStats.size,
195
+ cacheEnabled: cacheStats.enabled,
196
+ uptime: Date.now() - this.initTime
197
+ };
198
+ }
199
+ /**
200
+ * Determine overall status
201
+ */
202
+ determineOverallStatus(checks) {
203
+ const statuses = Object.values(checks).map((c) => c.status);
204
+ if (statuses.includes("fail")) return "unhealthy";
205
+ if (statuses.includes("warn")) return "degraded";
206
+ return "healthy";
207
+ }
208
+ /**
209
+ * Quick health check (minimal overhead)
210
+ */
211
+ async quickCheck() {
212
+ try {
213
+ if (this.detector.getPatterns().length === 0) return {
214
+ status: "unhealthy",
215
+ message: "No patterns loaded"
216
+ };
217
+ return {
218
+ status: "healthy",
219
+ message: "OK"
220
+ };
221
+ } catch (error) {
222
+ return {
223
+ status: "unhealthy",
224
+ message: `Error: ${error.message}`
225
+ };
226
+ }
227
+ }
228
+ /**
229
+ * Get system info for debugging
230
+ */
231
+ getSystemInfo() {
232
+ const patterns = this.detector.getPatterns();
233
+ const cacheStats = this.detector.getCacheStats();
234
+ return {
235
+ version: "1.0.0",
236
+ patterns: {
237
+ total: patterns.length,
238
+ types: [...new Set(patterns.map((p) => p.type.split("_")[0]))].length
239
+ },
240
+ cache: {
241
+ enabled: cacheStats.enabled,
242
+ size: cacheStats.size,
243
+ maxSize: cacheStats.maxSize
244
+ },
245
+ uptime: Date.now() - this.initTime,
246
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
247
+ };
248
+ }
249
+ };
250
+
251
+ //#endregion
252
+ exports.HealthChecker = HealthChecker;
@@ -0,0 +1,280 @@
1
+ //#region src/health/HealthCheck.ts
2
+ var HealthChecker = class {
3
+ constructor(detector) {
4
+ this.detector = detector;
5
+ this.initTime = Date.now();
6
+ }
7
+ /**
8
+ * Run complete health check
9
+ */
10
+ async check(options = {}) {
11
+ const result = {
12
+ status: "healthy",
13
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
14
+ checks: {
15
+ detector: {
16
+ status: "pass",
17
+ message: "Detector initialized"
18
+ },
19
+ patterns: {
20
+ status: "pass",
21
+ message: "Patterns loaded"
22
+ },
23
+ performance: {
24
+ status: "pass",
25
+ message: "Performance acceptable"
26
+ },
27
+ memory: {
28
+ status: "pass",
29
+ message: "Memory usage normal"
30
+ }
31
+ },
32
+ metrics: {
33
+ totalPatterns: 0,
34
+ compiledPatterns: 0,
35
+ cacheEnabled: false,
36
+ uptime: Date.now() - this.initTime
37
+ },
38
+ errors: [],
39
+ warnings: []
40
+ };
41
+ try {
42
+ result.checks.detector = await this.checkDetector(options);
43
+ result.checks.patterns = await this.checkPatterns();
44
+ if (options.checkPerformance !== false) result.checks.performance = await this.checkPerformance(options.performanceThreshold);
45
+ result.checks.memory = await this.checkMemory(options.memoryThreshold);
46
+ result.metrics = this.collectMetrics();
47
+ result.status = this.determineOverallStatus(result.checks);
48
+ for (const check of Object.values(result.checks)) if (check.status === "fail") result.errors.push(check.message);
49
+ else if (check.status === "warn") result.warnings.push(check.message);
50
+ } catch (error) {
51
+ result.status = "unhealthy";
52
+ result.errors.push(`Health check failed: ${error.message}`);
53
+ }
54
+ return result;
55
+ }
56
+ /**
57
+ * Check detector functionality
58
+ */
59
+ async checkDetector(options) {
60
+ try {
61
+ if (options.testDetection !== false) {
62
+ const result = await this.detector.detect("Test email: test@example.com");
63
+ if (!result || !result.detections) return {
64
+ status: "fail",
65
+ message: "Detector returned invalid result"
66
+ };
67
+ if (result.detections.length === 0) return {
68
+ status: "warn",
69
+ message: "Test detection found no PII (expected at least 1)"
70
+ };
71
+ }
72
+ return {
73
+ status: "pass",
74
+ message: "Detector functioning correctly"
75
+ };
76
+ } catch (error) {
77
+ return {
78
+ status: "fail",
79
+ message: `Detector check failed: ${error.message}`
80
+ };
81
+ }
82
+ }
83
+ /**
84
+ * Check patterns are loaded
85
+ */
86
+ async checkPatterns() {
87
+ try {
88
+ const patterns = this.detector.getPatterns();
89
+ if (!patterns || patterns.length === 0) return {
90
+ status: "fail",
91
+ message: "No patterns loaded",
92
+ value: 0,
93
+ threshold: 1
94
+ };
95
+ if (patterns.length < 10) return {
96
+ status: "warn",
97
+ message: "Very few patterns loaded (expected more)",
98
+ value: patterns.length,
99
+ threshold: 10
100
+ };
101
+ return {
102
+ status: "pass",
103
+ message: `${patterns.length} patterns loaded`,
104
+ value: patterns.length
105
+ };
106
+ } catch (error) {
107
+ return {
108
+ status: "fail",
109
+ message: `Pattern check failed: ${error.message}`
110
+ };
111
+ }
112
+ }
113
+ /**
114
+ * Check performance
115
+ */
116
+ async checkPerformance(threshold = 100) {
117
+ try {
118
+ const testText = "Test: john@example.com, phone: 555-123-4567, IP: 192.168.1.1";
119
+ const start = performance.now();
120
+ await this.detector.detect(testText);
121
+ const duration = performance.now() - start;
122
+ if (duration > threshold * 2) return {
123
+ status: "fail",
124
+ message: `Performance degraded: ${duration.toFixed(2)}ms`,
125
+ value: duration,
126
+ threshold
127
+ };
128
+ if (duration > threshold) return {
129
+ status: "warn",
130
+ message: `Performance slower than expected: ${duration.toFixed(2)}ms`,
131
+ value: duration,
132
+ threshold
133
+ };
134
+ return {
135
+ status: "pass",
136
+ message: `Performance good: ${duration.toFixed(2)}ms`,
137
+ value: duration,
138
+ threshold
139
+ };
140
+ } catch (error) {
141
+ return {
142
+ status: "fail",
143
+ message: `Performance check failed: ${error.message}`
144
+ };
145
+ }
146
+ }
147
+ /**
148
+ * Check memory usage
149
+ */
150
+ async checkMemory(threshold = 100) {
151
+ try {
152
+ if (typeof process === "undefined" || !process.memoryUsage) return {
153
+ status: "pass",
154
+ message: "Memory check skipped (not in Node.js)"
155
+ };
156
+ const heapUsedMB = process.memoryUsage().heapUsed / 1024 / 1024;
157
+ if (heapUsedMB > threshold * 2) return {
158
+ status: "fail",
159
+ message: `High memory usage: ${heapUsedMB.toFixed(2)}MB`,
160
+ value: heapUsedMB,
161
+ threshold
162
+ };
163
+ if (heapUsedMB > threshold) return {
164
+ status: "warn",
165
+ message: `Elevated memory usage: ${heapUsedMB.toFixed(2)}MB`,
166
+ value: heapUsedMB,
167
+ threshold
168
+ };
169
+ return {
170
+ status: "pass",
171
+ message: `Memory usage normal: ${heapUsedMB.toFixed(2)}MB`,
172
+ value: heapUsedMB,
173
+ threshold
174
+ };
175
+ } catch (error) {
176
+ return {
177
+ status: "warn",
178
+ message: `Memory check skipped: ${error.message}`
179
+ };
180
+ }
181
+ }
182
+ /**
183
+ * Collect metrics
184
+ */
185
+ collectMetrics() {
186
+ const patterns = this.detector.getPatterns();
187
+ const cacheStats = this.detector.getCacheStats();
188
+ return {
189
+ totalPatterns: patterns.length,
190
+ compiledPatterns: patterns.length,
191
+ cacheSize: cacheStats.size,
192
+ cacheEnabled: cacheStats.enabled,
193
+ uptime: Date.now() - this.initTime
194
+ };
195
+ }
196
+ /**
197
+ * Determine overall status
198
+ */
199
+ determineOverallStatus(checks) {
200
+ const statuses = Object.values(checks).map((c) => c.status);
201
+ if (statuses.includes("fail")) return "unhealthy";
202
+ if (statuses.includes("warn")) return "degraded";
203
+ return "healthy";
204
+ }
205
+ /**
206
+ * Quick health check (minimal overhead)
207
+ */
208
+ async quickCheck() {
209
+ try {
210
+ if (this.detector.getPatterns().length === 0) return {
211
+ status: "unhealthy",
212
+ message: "No patterns loaded"
213
+ };
214
+ return {
215
+ status: "healthy",
216
+ message: "OK"
217
+ };
218
+ } catch (error) {
219
+ return {
220
+ status: "unhealthy",
221
+ message: `Error: ${error.message}`
222
+ };
223
+ }
224
+ }
225
+ /**
226
+ * Get system info for debugging
227
+ */
228
+ getSystemInfo() {
229
+ const patterns = this.detector.getPatterns();
230
+ const cacheStats = this.detector.getCacheStats();
231
+ return {
232
+ version: "1.0.0",
233
+ patterns: {
234
+ total: patterns.length,
235
+ types: [...new Set(patterns.map((p) => p.type.split("_")[0]))].length
236
+ },
237
+ cache: {
238
+ enabled: cacheStats.enabled,
239
+ size: cacheStats.size,
240
+ maxSize: cacheStats.maxSize
241
+ },
242
+ uptime: Date.now() - this.initTime,
243
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
244
+ };
245
+ }
246
+ };
247
+ /**
248
+ * Create health checker for a detector
249
+ */
250
+ function createHealthChecker(detector) {
251
+ return new HealthChecker(detector);
252
+ }
253
+ /**
254
+ * Express middleware for health check endpoint
255
+ */
256
+ function healthCheckMiddleware(detector) {
257
+ const checker = new HealthChecker(detector);
258
+ return async (_req, res) => {
259
+ try {
260
+ const result = await checker.check({
261
+ testDetection: true,
262
+ checkPerformance: true,
263
+ performanceThreshold: 100,
264
+ memoryThreshold: 100
265
+ });
266
+ const statusCode = result.status === "healthy" ? 200 : result.status === "degraded" ? 200 : 503;
267
+ res.status(statusCode).json(result);
268
+ } catch (error) {
269
+ res.status(503).json({
270
+ status: "unhealthy",
271
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
272
+ error: error.message
273
+ });
274
+ }
275
+ };
276
+ }
277
+
278
+ //#endregion
279
+ export { createHealthChecker as n, healthCheckMiddleware as r, HealthChecker as t };
280
+ //# sourceMappingURL=HealthCheck-B79o7xg2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HealthCheck-B79o7xg2.mjs","names":[],"sources":["../src/health/HealthCheck.ts"],"sourcesContent":["/**\n * Health check API for production monitoring\n * Verify detector is working correctly and get system status\n */\n\nimport type { OpenRedaction } from '../detector';\n\nexport interface HealthCheckResult {\n status: 'healthy' | 'degraded' | 'unhealthy';\n timestamp: string;\n checks: {\n detector: HealthCheckStatus;\n patterns: HealthCheckStatus;\n performance: HealthCheckStatus;\n memory: HealthCheckStatus;\n };\n metrics: {\n totalPatterns: number;\n compiledPatterns: number;\n cacheSize?: number;\n cacheEnabled: boolean;\n uptime: number; // milliseconds since initialization\n };\n errors: string[];\n warnings: string[];\n}\n\nexport interface HealthCheckStatus {\n status: 'pass' | 'warn' | 'fail';\n message: string;\n value?: any;\n threshold?: any;\n}\n\nexport interface HealthCheckOptions {\n testDetection?: boolean; // Run a test detection\n checkPerformance?: boolean; // Run performance benchmark\n performanceThreshold?: number; // Max acceptable detection time (ms)\n memoryThreshold?: number; // Max acceptable memory usage (MB)\n}\n\nexport class HealthChecker {\n private detector: OpenRedaction;\n private initTime: number;\n\n constructor(detector: OpenRedaction) {\n this.detector = detector;\n this.initTime = Date.now();\n }\n\n /**\n * Run complete health check\n */\n async check(options: HealthCheckOptions = {}): Promise<HealthCheckResult> {\n const result: HealthCheckResult = {\n status: 'healthy',\n timestamp: new Date().toISOString(),\n checks: {\n detector: { status: 'pass', message: 'Detector initialized' },\n patterns: { status: 'pass', message: 'Patterns loaded' },\n performance: { status: 'pass', message: 'Performance acceptable' },\n memory: { status: 'pass', message: 'Memory usage normal' }\n },\n metrics: {\n totalPatterns: 0,\n compiledPatterns: 0,\n cacheEnabled: false,\n uptime: Date.now() - this.initTime\n },\n errors: [],\n warnings: []\n };\n\n try {\n // Check 1: Detector status\n result.checks.detector = await this.checkDetector(options);\n\n // Check 2: Patterns status\n result.checks.patterns = await this.checkPatterns();\n\n // Check 3: Performance\n if (options.checkPerformance !== false) {\n result.checks.performance = await this.checkPerformance(\n options.performanceThreshold\n );\n }\n\n // Check 4: Memory\n result.checks.memory = await this.checkMemory(options.memoryThreshold);\n\n // Collect metrics\n result.metrics = this.collectMetrics();\n\n // Determine overall status\n result.status = this.determineOverallStatus(result.checks);\n\n // Collect errors and warnings\n for (const check of Object.values(result.checks)) {\n if (check.status === 'fail') {\n result.errors.push(check.message);\n } else if (check.status === 'warn') {\n result.warnings.push(check.message);\n }\n }\n } catch (error) {\n result.status = 'unhealthy';\n result.errors.push(`Health check failed: ${(error as Error).message}`);\n }\n\n return result;\n }\n\n /**\n * Check detector functionality\n */\n private async checkDetector(options: HealthCheckOptions): Promise<HealthCheckStatus> {\n try {\n // Run test detection if enabled\n if (options.testDetection !== false) {\n const testText = 'Test email: test@example.com';\n const result = await this.detector.detect(testText);\n\n if (!result || !result.detections) {\n return {\n status: 'fail',\n message: 'Detector returned invalid result'\n };\n }\n\n // Verify detection worked\n if (result.detections.length === 0) {\n return {\n status: 'warn',\n message: 'Test detection found no PII (expected at least 1)'\n };\n }\n }\n\n return {\n status: 'pass',\n message: 'Detector functioning correctly'\n };\n } catch (error) {\n return {\n status: 'fail',\n message: `Detector check failed: ${(error as Error).message}`\n };\n }\n }\n\n /**\n * Check patterns are loaded\n */\n private async checkPatterns(): Promise<HealthCheckStatus> {\n try {\n const patterns = this.detector.getPatterns();\n\n if (!patterns || patterns.length === 0) {\n return {\n status: 'fail',\n message: 'No patterns loaded',\n value: 0,\n threshold: 1\n };\n }\n\n if (patterns.length < 10) {\n return {\n status: 'warn',\n message: 'Very few patterns loaded (expected more)',\n value: patterns.length,\n threshold: 10\n };\n }\n\n return {\n status: 'pass',\n message: `${patterns.length} patterns loaded`,\n value: patterns.length\n };\n } catch (error) {\n return {\n status: 'fail',\n message: `Pattern check failed: ${(error as Error).message}`\n };\n }\n }\n\n /**\n * Check performance\n */\n private async checkPerformance(\n threshold: number = 100\n ): Promise<HealthCheckStatus> {\n try {\n const testText = 'Test: john@example.com, phone: 555-123-4567, IP: 192.168.1.1';\n const start = performance.now();\n await this.detector.detect(testText);\n const duration = performance.now() - start;\n\n if (duration > threshold * 2) {\n return {\n status: 'fail',\n message: `Performance degraded: ${duration.toFixed(2)}ms`,\n value: duration,\n threshold\n };\n }\n\n if (duration > threshold) {\n return {\n status: 'warn',\n message: `Performance slower than expected: ${duration.toFixed(2)}ms`,\n value: duration,\n threshold\n };\n }\n\n return {\n status: 'pass',\n message: `Performance good: ${duration.toFixed(2)}ms`,\n value: duration,\n threshold\n };\n } catch (error) {\n return {\n status: 'fail',\n message: `Performance check failed: ${(error as Error).message}`\n };\n }\n }\n\n /**\n * Check memory usage\n */\n private async checkMemory(threshold: number = 100): Promise<HealthCheckStatus> {\n try {\n if (typeof process === 'undefined' || !process.memoryUsage) {\n return {\n status: 'pass',\n message: 'Memory check skipped (not in Node.js)'\n };\n }\n\n const usage = process.memoryUsage();\n const heapUsedMB = usage.heapUsed / 1024 / 1024;\n\n if (heapUsedMB > threshold * 2) {\n return {\n status: 'fail',\n message: `High memory usage: ${heapUsedMB.toFixed(2)}MB`,\n value: heapUsedMB,\n threshold\n };\n }\n\n if (heapUsedMB > threshold) {\n return {\n status: 'warn',\n message: `Elevated memory usage: ${heapUsedMB.toFixed(2)}MB`,\n value: heapUsedMB,\n threshold\n };\n }\n\n return {\n status: 'pass',\n message: `Memory usage normal: ${heapUsedMB.toFixed(2)}MB`,\n value: heapUsedMB,\n threshold\n };\n } catch (error) {\n return {\n status: 'warn',\n message: `Memory check skipped: ${(error as Error).message}`\n };\n }\n }\n\n /**\n * Collect metrics\n */\n private collectMetrics() {\n const patterns = this.detector.getPatterns();\n const cacheStats = this.detector.getCacheStats();\n\n return {\n totalPatterns: patterns.length,\n compiledPatterns: patterns.length, // All patterns are pre-compiled\n cacheSize: cacheStats.size,\n cacheEnabled: cacheStats.enabled,\n uptime: Date.now() - this.initTime\n };\n }\n\n /**\n * Determine overall status\n */\n private determineOverallStatus(checks: HealthCheckResult['checks']): 'healthy' | 'degraded' | 'unhealthy' {\n const statuses = Object.values(checks).map(c => c.status);\n\n if (statuses.includes('fail')) {\n return 'unhealthy';\n }\n\n if (statuses.includes('warn')) {\n return 'degraded';\n }\n\n return 'healthy';\n }\n\n /**\n * Quick health check (minimal overhead)\n */\n async quickCheck(): Promise<{ status: 'healthy' | 'unhealthy'; message: string }> {\n try {\n // Just verify basic functionality\n const patterns = this.detector.getPatterns();\n if (patterns.length === 0) {\n return { status: 'unhealthy', message: 'No patterns loaded' };\n }\n\n return { status: 'healthy', message: 'OK' };\n } catch (error) {\n return {\n status: 'unhealthy',\n message: `Error: ${(error as Error).message}`\n };\n }\n }\n\n /**\n * Get system info for debugging\n */\n getSystemInfo() {\n const patterns = this.detector.getPatterns();\n const cacheStats = this.detector.getCacheStats();\n\n return {\n version: '1.0.0', // Should come from package.json\n patterns: {\n total: patterns.length,\n types: [...new Set(patterns.map(p => p.type.split('_')[0]))].length\n },\n cache: {\n enabled: cacheStats.enabled,\n size: cacheStats.size,\n maxSize: cacheStats.maxSize\n },\n uptime: Date.now() - this.initTime,\n timestamp: new Date().toISOString()\n };\n }\n}\n\n/**\n * Create health checker for a detector\n */\nexport function createHealthChecker(detector: OpenRedaction): HealthChecker {\n return new HealthChecker(detector);\n}\n\n/**\n * Express middleware for health check endpoint\n */\nexport function healthCheckMiddleware(detector: OpenRedaction) {\n const checker = new HealthChecker(detector);\n\n return async (_req: any, res: any) => {\n try {\n const result = await checker.check({\n testDetection: true,\n checkPerformance: true,\n performanceThreshold: 100,\n memoryThreshold: 100\n });\n\n const statusCode = result.status === 'healthy' ? 200 :\n result.status === 'degraded' ? 200 : 503;\n\n res.status(statusCode).json(result);\n } catch (error)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