openredaction 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -51
- package/dist/cli/test-pattern.cjs +378 -0
- package/dist/index.cli.cjs +17479 -0
- package/dist/index.d.mts +3932 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +2897 -3166
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19629 -18149
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +19512 -15800
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +1124 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.d.ts +1124 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +17548 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +17532 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +31 -19
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Core types for PII Shield
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* PII pattern definition with validation
|
|
9
|
+
*/
|
|
10
|
+
interface PIIPattern {
|
|
11
|
+
/** Pattern type identifier (e.g., "EMAIL", "PHONE_UK_MOBILE") */
|
|
12
|
+
type: string;
|
|
13
|
+
/** Regular expression for matching */
|
|
14
|
+
regex: RegExp;
|
|
15
|
+
/** Priority for detection order (higher = checked first) */
|
|
16
|
+
priority: number;
|
|
17
|
+
/** Optional validator function for false positive reduction */
|
|
18
|
+
validator?: (match: string, context: string) => boolean;
|
|
19
|
+
/** Placeholder template (e.g., "[EMAIL_{n}]") */
|
|
20
|
+
placeholder: string;
|
|
21
|
+
/** Optional description */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Severity level */
|
|
24
|
+
severity?: 'critical' | 'high' | 'medium' | 'low';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Detected PII instance
|
|
28
|
+
*/
|
|
29
|
+
interface PIIDetection {
|
|
30
|
+
/** Type of PII detected */
|
|
31
|
+
type: string;
|
|
32
|
+
/** Original detected value */
|
|
33
|
+
value: string;
|
|
34
|
+
/** Placeholder used for redaction */
|
|
35
|
+
placeholder: string;
|
|
36
|
+
/** Position in text [start, end] */
|
|
37
|
+
position: [number, number];
|
|
38
|
+
/** Severity level */
|
|
39
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
40
|
+
/** Confidence score (0-1) based on context analysis */
|
|
41
|
+
confidence?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Detection result
|
|
45
|
+
*/
|
|
46
|
+
interface DetectionResult {
|
|
47
|
+
/** Original text */
|
|
48
|
+
original: string;
|
|
49
|
+
/** Redacted text */
|
|
50
|
+
redacted: string;
|
|
51
|
+
/** Array of detections */
|
|
52
|
+
detections: PIIDetection[];
|
|
53
|
+
/** Map of placeholders to original values for restoration */
|
|
54
|
+
redactionMap: Record<string, string>;
|
|
55
|
+
/** Statistics */
|
|
56
|
+
stats?: {
|
|
57
|
+
/** Processing time in milliseconds */processingTime?: number; /** Total PII count */
|
|
58
|
+
piiCount: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Redaction mode - controls how PII is replaced
|
|
63
|
+
*/
|
|
64
|
+
type RedactionMode = 'placeholder' | 'mask-middle' | 'mask-all' | 'format-preserving' | 'token-replace';
|
|
65
|
+
/**
|
|
66
|
+
* Configuration options for OpenRedaction
|
|
67
|
+
*/
|
|
68
|
+
type PresetName = 'gdpr' | 'hipaa' | 'ccpa' | 'healthcare' | 'healthcare-provider' | 'healthcare-research' | 'finance' | 'financial-services' | 'education' | 'transport-logistics' | 'transportation' | 'logistics';
|
|
69
|
+
interface OpenRedactionOptions {
|
|
70
|
+
/** Include name detection (default: true) */
|
|
71
|
+
includeNames?: boolean;
|
|
72
|
+
/** Include address detection (default: true) */
|
|
73
|
+
includeAddresses?: boolean;
|
|
74
|
+
/** Include phone detection (default: true) */
|
|
75
|
+
includePhones?: boolean;
|
|
76
|
+
/** Include email detection (default: true) */
|
|
77
|
+
includeEmails?: boolean;
|
|
78
|
+
/** Pattern categories to include (e.g., ['personal', 'financial']) */
|
|
79
|
+
categories?: string[];
|
|
80
|
+
/** Whitelist specific patterns only */
|
|
81
|
+
patterns?: string[];
|
|
82
|
+
/** Add custom patterns */
|
|
83
|
+
customPatterns?: PIIPattern[];
|
|
84
|
+
/** Whitelist of terms to ignore (e.g., company names) */
|
|
85
|
+
whitelist?: string[];
|
|
86
|
+
/** Enable deterministic placeholders (default: true) */
|
|
87
|
+
deterministic?: boolean;
|
|
88
|
+
/** Redaction mode (default: 'placeholder') */
|
|
89
|
+
redactionMode?: RedactionMode;
|
|
90
|
+
/** Compliance preset */
|
|
91
|
+
preset?: PresetName;
|
|
92
|
+
/** Enable context-aware detection (default: true) */
|
|
93
|
+
enableContextAnalysis?: boolean;
|
|
94
|
+
/** Minimum confidence threshold for detections (0-1, default: 0.5) */
|
|
95
|
+
confidenceThreshold?: number;
|
|
96
|
+
/** Enable false positive filtering (default: false, experimental) */
|
|
97
|
+
enableFalsePositiveFilter?: boolean;
|
|
98
|
+
/** False positive confidence threshold (0-1, default: 0.7) */
|
|
99
|
+
falsePositiveThreshold?: number;
|
|
100
|
+
/** Enable multi-pass detection for better accuracy (default: false, experimental) */
|
|
101
|
+
enableMultiPass?: boolean;
|
|
102
|
+
/** Number of detection passes (2-5, default: 3) */
|
|
103
|
+
multiPassCount?: number;
|
|
104
|
+
/** Enable result caching for repeated inputs (default: false) */
|
|
105
|
+
enableCache?: boolean;
|
|
106
|
+
/** Maximum cache size (default: 100) */
|
|
107
|
+
cacheSize?: number;
|
|
108
|
+
/** Enable debug logging (default: false) */
|
|
109
|
+
debug?: boolean;
|
|
110
|
+
/** Enable audit logging (default: false) */
|
|
111
|
+
enableAuditLog?: boolean;
|
|
112
|
+
/** Audit logger instance (optional, default: in-memory logger) */
|
|
113
|
+
auditLogger?: IAuditLogger;
|
|
114
|
+
/** User context for audit logs */
|
|
115
|
+
auditUser?: string;
|
|
116
|
+
/** Session ID for audit logs */
|
|
117
|
+
auditSessionId?: string;
|
|
118
|
+
/** Additional metadata for audit logs */
|
|
119
|
+
auditMetadata?: Record<string, unknown>;
|
|
120
|
+
/** Enable metrics collection (default: false) */
|
|
121
|
+
enableMetrics?: boolean;
|
|
122
|
+
/** Metrics collector instance (optional, default: in-memory collector) */
|
|
123
|
+
metricsCollector?: IMetricsCollector;
|
|
124
|
+
/** Enable RBAC (Role-Based Access Control) (default: false) */
|
|
125
|
+
enableRBAC?: boolean;
|
|
126
|
+
/** RBAC manager instance (optional, default: admin role) */
|
|
127
|
+
rbacManager?: IRBACManager;
|
|
128
|
+
/** Predefined role name (admin, analyst, operator, viewer) */
|
|
129
|
+
role?: RoleName;
|
|
130
|
+
/** Optional AI assist configuration */
|
|
131
|
+
ai?: AIOptions;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* AI assist configuration options
|
|
135
|
+
*/
|
|
136
|
+
interface AIOptions {
|
|
137
|
+
/** Enable AI assist mode (default: false) */
|
|
138
|
+
enabled?: boolean;
|
|
139
|
+
/** AI endpoint URL (defaults to OPENREDACTION_AI_ENDPOINT env var if available) */
|
|
140
|
+
endpoint?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Audit log entry for tracking redaction operations
|
|
144
|
+
*/
|
|
145
|
+
interface AuditLogEntry {
|
|
146
|
+
/** Unique identifier for this audit entry */
|
|
147
|
+
id: string;
|
|
148
|
+
/** Timestamp of the operation (ISO 8601) */
|
|
149
|
+
timestamp: string;
|
|
150
|
+
/** Operation type */
|
|
151
|
+
operation: 'redact' | 'detect' | 'restore';
|
|
152
|
+
/** Number of PII items found/processed */
|
|
153
|
+
piiCount: number;
|
|
154
|
+
/** Types of PII detected (e.g., ["EMAIL", "SSN", "PHONE"]) */
|
|
155
|
+
piiTypes: string[];
|
|
156
|
+
/** Text length processed */
|
|
157
|
+
textLength: number;
|
|
158
|
+
/** Processing time in milliseconds */
|
|
159
|
+
processingTimeMs: number;
|
|
160
|
+
/** Redaction mode used */
|
|
161
|
+
redactionMode?: RedactionMode;
|
|
162
|
+
/** Success status */
|
|
163
|
+
success: boolean;
|
|
164
|
+
/** Error message if operation failed */
|
|
165
|
+
error?: string;
|
|
166
|
+
/** Optional user context */
|
|
167
|
+
user?: string;
|
|
168
|
+
/** Optional session/request identifier */
|
|
169
|
+
sessionId?: string;
|
|
170
|
+
/** Optional metadata */
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Audit logger interface
|
|
175
|
+
*/
|
|
176
|
+
interface IAuditLogger {
|
|
177
|
+
/** Log an audit entry */
|
|
178
|
+
log(entry: Omit<AuditLogEntry, 'id' | 'timestamp'>): void;
|
|
179
|
+
/** Get all audit logs */
|
|
180
|
+
getLogs(): AuditLogEntry[];
|
|
181
|
+
/** Get audit logs filtered by operation type */
|
|
182
|
+
getLogsByOperation(operation: AuditLogEntry['operation']): AuditLogEntry[];
|
|
183
|
+
/** Get audit logs filtered by date range */
|
|
184
|
+
getLogsByDateRange(startDate: Date, endDate: Date): AuditLogEntry[];
|
|
185
|
+
/** Export audit logs as JSON */
|
|
186
|
+
exportAsJson(): string;
|
|
187
|
+
/** Export audit logs as CSV */
|
|
188
|
+
exportAsCsv(): string;
|
|
189
|
+
/** Clear all audit logs */
|
|
190
|
+
clear(): void;
|
|
191
|
+
/** Get audit statistics */
|
|
192
|
+
getStats(): AuditStats;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Audit statistics
|
|
196
|
+
*/
|
|
197
|
+
interface AuditStats {
|
|
198
|
+
/** Total number of operations */
|
|
199
|
+
totalOperations: number;
|
|
200
|
+
/** Total PII items detected */
|
|
201
|
+
totalPiiDetected: number;
|
|
202
|
+
/** Average processing time in milliseconds */
|
|
203
|
+
averageProcessingTime: number;
|
|
204
|
+
/** Most common PII types */
|
|
205
|
+
topPiiTypes: Array<{
|
|
206
|
+
type: string;
|
|
207
|
+
count: number;
|
|
208
|
+
}>;
|
|
209
|
+
/** Operations by type */
|
|
210
|
+
operationsByType: Record<string, number>;
|
|
211
|
+
/** Success rate (0-1) */
|
|
212
|
+
successRate: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Metrics for monitoring redaction operations
|
|
216
|
+
*/
|
|
217
|
+
interface RedactionMetrics {
|
|
218
|
+
/** Total number of redaction operations */
|
|
219
|
+
totalRedactions: number;
|
|
220
|
+
/** Total number of PII items detected */
|
|
221
|
+
totalPiiDetected: number;
|
|
222
|
+
/** Total processing time in milliseconds */
|
|
223
|
+
totalProcessingTime: number;
|
|
224
|
+
/** Average processing time in milliseconds */
|
|
225
|
+
averageProcessingTime: number;
|
|
226
|
+
/** Total text length processed (characters) */
|
|
227
|
+
totalTextLength: number;
|
|
228
|
+
/** PII detection counts by type */
|
|
229
|
+
piiByType: Record<string, number>;
|
|
230
|
+
/** Operation counts by redaction mode */
|
|
231
|
+
byRedactionMode: Record<string, number>;
|
|
232
|
+
/** Error count */
|
|
233
|
+
totalErrors: number;
|
|
234
|
+
/** Timestamp of last update */
|
|
235
|
+
lastUpdated: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Metrics exporter interface
|
|
239
|
+
*/
|
|
240
|
+
interface IMetricsExporter {
|
|
241
|
+
/** Export metrics in Prometheus format */
|
|
242
|
+
exportPrometheus(metrics: RedactionMetrics, prefix?: string): string;
|
|
243
|
+
/** Export metrics in StatsD format */
|
|
244
|
+
exportStatsD(metrics: RedactionMetrics, prefix?: string): string[];
|
|
245
|
+
/** Get current metrics snapshot */
|
|
246
|
+
getMetrics(): RedactionMetrics;
|
|
247
|
+
/** Reset all metrics */
|
|
248
|
+
reset(): void;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Metrics collector interface
|
|
252
|
+
*/
|
|
253
|
+
interface IMetricsCollector {
|
|
254
|
+
/** Record a redaction operation */
|
|
255
|
+
recordRedaction(result: DetectionResult, processingTimeMs: number, redactionMode: RedactionMode): void;
|
|
256
|
+
/** Record an error */
|
|
257
|
+
recordError(): void;
|
|
258
|
+
/** Get metrics exporter */
|
|
259
|
+
getExporter(): IMetricsExporter;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* RBAC Permission - granular access control
|
|
263
|
+
*/
|
|
264
|
+
type Permission = 'pattern:read' | 'pattern:write' | 'pattern:delete' | 'detection:detect' | 'detection:redact' | 'detection:restore' | 'audit:read' | 'audit:export' | 'audit:delete' | 'metrics:read' | 'metrics:export' | 'metrics:reset' | 'config:read' | 'config:write';
|
|
265
|
+
/**
|
|
266
|
+
* RBAC Role - collection of permissions
|
|
267
|
+
*/
|
|
268
|
+
interface Role {
|
|
269
|
+
/** Role identifier */
|
|
270
|
+
name: string;
|
|
271
|
+
/** Role description */
|
|
272
|
+
description?: string;
|
|
273
|
+
/** Permissions granted to this role */
|
|
274
|
+
permissions: Permission[];
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Predefined role names
|
|
278
|
+
*/
|
|
279
|
+
type RoleName = 'admin' | 'analyst' | 'operator' | 'viewer' | 'custom';
|
|
280
|
+
/**
|
|
281
|
+
* RBAC manager interface for access control
|
|
282
|
+
*/
|
|
283
|
+
interface IRBACManager {
|
|
284
|
+
/** Check if user has specific permission */
|
|
285
|
+
hasPermission(permission: Permission): boolean;
|
|
286
|
+
/** Check if user has all specified permissions */
|
|
287
|
+
hasAllPermissions(permissions: Permission[]): boolean;
|
|
288
|
+
/** Check if user has any of the specified permissions */
|
|
289
|
+
hasAnyPermission(permissions: Permission[]): boolean;
|
|
290
|
+
/** Get current role */
|
|
291
|
+
getRole(): Role;
|
|
292
|
+
/** Set role */
|
|
293
|
+
setRole(role: Role): void;
|
|
294
|
+
/** Get all permissions for current role */
|
|
295
|
+
getPermissions(): Permission[];
|
|
296
|
+
/** Filter patterns based on read permissions */
|
|
297
|
+
filterPatterns(patterns: PIIPattern[]): PIIPattern[];
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/learning/LocalLearningStore.d.ts
|
|
301
|
+
interface WhitelistEntry {
|
|
302
|
+
pattern: string;
|
|
303
|
+
confidence: number;
|
|
304
|
+
occurrences: number;
|
|
305
|
+
firstSeen: number;
|
|
306
|
+
lastSeen: number;
|
|
307
|
+
contexts: string[];
|
|
308
|
+
}
|
|
309
|
+
interface PatternAdjustment {
|
|
310
|
+
type: string;
|
|
311
|
+
issue: string;
|
|
312
|
+
suggestion: string;
|
|
313
|
+
confidence: number;
|
|
314
|
+
examples: string[];
|
|
315
|
+
occurrences: number;
|
|
316
|
+
}
|
|
317
|
+
interface LearningStats {
|
|
318
|
+
totalDetections: number;
|
|
319
|
+
falsePositives: number;
|
|
320
|
+
falseNegatives: number;
|
|
321
|
+
accuracy: number;
|
|
322
|
+
lastUpdated: number;
|
|
323
|
+
}
|
|
324
|
+
interface LearningData {
|
|
325
|
+
version: string;
|
|
326
|
+
whitelist: WhitelistEntry[];
|
|
327
|
+
patternAdjustments: PatternAdjustment[];
|
|
328
|
+
stats: LearningStats;
|
|
329
|
+
}
|
|
330
|
+
declare class LocalLearningStore {
|
|
331
|
+
private filePath;
|
|
332
|
+
private data;
|
|
333
|
+
private autoSave;
|
|
334
|
+
private confidenceThreshold;
|
|
335
|
+
constructor(filePath?: string, options?: {
|
|
336
|
+
autoSave?: boolean;
|
|
337
|
+
confidenceThreshold?: number;
|
|
338
|
+
});
|
|
339
|
+
/**
|
|
340
|
+
* Load learning data from file
|
|
341
|
+
*/
|
|
342
|
+
private load;
|
|
343
|
+
/**
|
|
344
|
+
* Save learning data to file
|
|
345
|
+
*/
|
|
346
|
+
private save;
|
|
347
|
+
/**
|
|
348
|
+
* Record a false positive detection
|
|
349
|
+
*/
|
|
350
|
+
recordFalsePositive(text: string, _type: string, context: string): void;
|
|
351
|
+
/**
|
|
352
|
+
* Record a false negative (missed detection)
|
|
353
|
+
*/
|
|
354
|
+
recordFalseNegative(text: string, type: string, _context: string): void;
|
|
355
|
+
/**
|
|
356
|
+
* Record a correct detection
|
|
357
|
+
*/
|
|
358
|
+
recordCorrectDetection(): void;
|
|
359
|
+
/**
|
|
360
|
+
* Update accuracy calculation
|
|
361
|
+
*/
|
|
362
|
+
private updateAccuracy;
|
|
363
|
+
/**
|
|
364
|
+
* Get whitelist entries above confidence threshold
|
|
365
|
+
*/
|
|
366
|
+
getWhitelist(): string[];
|
|
367
|
+
/**
|
|
368
|
+
* Get all whitelist entries with metadata
|
|
369
|
+
*/
|
|
370
|
+
getWhitelistEntries(): WhitelistEntry[];
|
|
371
|
+
/**
|
|
372
|
+
* Get pattern adjustments above confidence threshold
|
|
373
|
+
*/
|
|
374
|
+
getPatternAdjustments(): PatternAdjustment[];
|
|
375
|
+
/**
|
|
376
|
+
* Get all pattern adjustments
|
|
377
|
+
*/
|
|
378
|
+
getAllPatternAdjustments(): PatternAdjustment[];
|
|
379
|
+
/**
|
|
380
|
+
* Get learning statistics
|
|
381
|
+
*/
|
|
382
|
+
getStats(): LearningStats;
|
|
383
|
+
/**
|
|
384
|
+
* Get confidence score for a specific pattern
|
|
385
|
+
*/
|
|
386
|
+
getConfidence(pattern: string): number;
|
|
387
|
+
/**
|
|
388
|
+
* Get occurrences count for a specific pattern
|
|
389
|
+
*/
|
|
390
|
+
getOccurrences(pattern: string): number;
|
|
391
|
+
/**
|
|
392
|
+
* Manually add pattern to whitelist
|
|
393
|
+
*/
|
|
394
|
+
addToWhitelist(pattern: string, confidence?: number): void;
|
|
395
|
+
/**
|
|
396
|
+
* Remove pattern from whitelist
|
|
397
|
+
*/
|
|
398
|
+
removeFromWhitelist(pattern: string): void;
|
|
399
|
+
/**
|
|
400
|
+
* Clear all learning data
|
|
401
|
+
*/
|
|
402
|
+
clear(): void;
|
|
403
|
+
/**
|
|
404
|
+
* Export learning data (for sharing)
|
|
405
|
+
*/
|
|
406
|
+
export(options?: {
|
|
407
|
+
includeContexts?: boolean;
|
|
408
|
+
minConfidence?: number;
|
|
409
|
+
}): LearningData;
|
|
410
|
+
/**
|
|
411
|
+
* Import learning data (merge with existing)
|
|
412
|
+
*/
|
|
413
|
+
import(data: LearningData, merge?: boolean): void;
|
|
414
|
+
/**
|
|
415
|
+
* Manually save data
|
|
416
|
+
*/
|
|
417
|
+
flush(): void;
|
|
418
|
+
}
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/optimizer/PriorityOptimizer.d.ts
|
|
421
|
+
interface PatternStats {
|
|
422
|
+
type: string;
|
|
423
|
+
totalDetections: number;
|
|
424
|
+
falsePositives: number;
|
|
425
|
+
falseNegatives: number;
|
|
426
|
+
accuracy: number;
|
|
427
|
+
priority: number;
|
|
428
|
+
adjustedPriority: number;
|
|
429
|
+
}
|
|
430
|
+
interface OptimizerOptions {
|
|
431
|
+
learningWeight: number;
|
|
432
|
+
minSampleSize: number;
|
|
433
|
+
maxPriorityAdjustment: number;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Priority Optimizer - Dynamically adjusts pattern priorities based on learning data
|
|
437
|
+
*/
|
|
438
|
+
declare class PriorityOptimizer {
|
|
439
|
+
private learningStore;
|
|
440
|
+
private options;
|
|
441
|
+
constructor(learningStore: LocalLearningStore, options?: Partial<OptimizerOptions>);
|
|
442
|
+
/**
|
|
443
|
+
* Optimize pattern priorities based on learning data
|
|
444
|
+
*/
|
|
445
|
+
optimizePatterns(patterns: PIIPattern[]): PIIPattern[];
|
|
446
|
+
/**
|
|
447
|
+
* Get pattern statistics with learning data
|
|
448
|
+
*/
|
|
449
|
+
getPatternStats(patterns: PIIPattern[]): PatternStats[];
|
|
450
|
+
/**
|
|
451
|
+
* Infer pattern type from a whitelisted value
|
|
452
|
+
* This is a heuristic - in production we'd track this explicitly
|
|
453
|
+
*/
|
|
454
|
+
private inferPatternType;
|
|
455
|
+
/**
|
|
456
|
+
* Reset all priority adjustments
|
|
457
|
+
*/
|
|
458
|
+
resetPriorities(patterns: PIIPattern[]): PIIPattern[];
|
|
459
|
+
/**
|
|
460
|
+
* Get optimizer configuration
|
|
461
|
+
*/
|
|
462
|
+
getOptions(): OptimizerOptions;
|
|
463
|
+
/**
|
|
464
|
+
* Update optimizer configuration
|
|
465
|
+
*/
|
|
466
|
+
setOptions(options: Partial<OptimizerOptions>): void;
|
|
467
|
+
}
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/document/types.d.ts
|
|
470
|
+
/**
|
|
471
|
+
* Supported document formats
|
|
472
|
+
*/
|
|
473
|
+
type DocumentFormat = 'pdf' | 'docx' | 'txt' | 'image' | 'json' | 'csv' | 'xlsx';
|
|
474
|
+
/**
|
|
475
|
+
* OCR language codes (Tesseract format)
|
|
476
|
+
*/
|
|
477
|
+
type OCRLanguage = 'eng' | 'spa' | 'fra' | 'deu' | 'por' | 'ita' | 'rus' | 'chi_sim' | 'chi_tra' | 'jpn' | 'kor';
|
|
478
|
+
/**
|
|
479
|
+
* OCR options
|
|
480
|
+
*/
|
|
481
|
+
interface OCROptions {
|
|
482
|
+
/** OCR language (default: 'eng' for English) */
|
|
483
|
+
language?: OCRLanguage | OCRLanguage[];
|
|
484
|
+
/** OCR engine mode (0-3, default: 3 for best accuracy) */
|
|
485
|
+
oem?: 0 | 1 | 2 | 3;
|
|
486
|
+
/** Page segmentation mode (0-13, default: 3 for automatic) */
|
|
487
|
+
psm?: number;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Document processing options
|
|
491
|
+
*/
|
|
492
|
+
interface DocumentOptions {
|
|
493
|
+
/** Document format (auto-detected if not specified) */
|
|
494
|
+
format?: DocumentFormat;
|
|
495
|
+
/** Extract text from specific pages (PDF only, 1-indexed) */
|
|
496
|
+
pages?: number[];
|
|
497
|
+
/** Password for encrypted PDFs */
|
|
498
|
+
password?: string;
|
|
499
|
+
/** Maximum document size in bytes (default: 50MB) */
|
|
500
|
+
maxSize?: number;
|
|
501
|
+
/** Enable OCR for image-based content (default: false) */
|
|
502
|
+
enableOCR?: boolean;
|
|
503
|
+
/** OCR configuration options */
|
|
504
|
+
ocrOptions?: OCROptions;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Document processing result
|
|
508
|
+
*/
|
|
509
|
+
interface DocumentResult {
|
|
510
|
+
/** Extracted text from document */
|
|
511
|
+
text: string;
|
|
512
|
+
/** Document metadata */
|
|
513
|
+
metadata: DocumentMetadata;
|
|
514
|
+
/** Detection result with PII findings */
|
|
515
|
+
detection: DetectionResult;
|
|
516
|
+
/** Original file size in bytes */
|
|
517
|
+
fileSize: number;
|
|
518
|
+
/** Text extraction time in milliseconds */
|
|
519
|
+
extractionTime: number;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Document metadata
|
|
523
|
+
*/
|
|
524
|
+
interface DocumentMetadata {
|
|
525
|
+
/** Document format */
|
|
526
|
+
format: DocumentFormat;
|
|
527
|
+
/** Number of pages (if applicable) */
|
|
528
|
+
pages?: number;
|
|
529
|
+
/** Document title */
|
|
530
|
+
title?: string;
|
|
531
|
+
/** Document author */
|
|
532
|
+
author?: string;
|
|
533
|
+
/** Creation date */
|
|
534
|
+
creationDate?: Date;
|
|
535
|
+
/** Last modified date */
|
|
536
|
+
modifiedDate?: Date;
|
|
537
|
+
/** OCR confidence (0-100) if OCR was used */
|
|
538
|
+
ocrConfidence?: number;
|
|
539
|
+
/** Whether OCR was used for extraction */
|
|
540
|
+
usedOCR?: boolean;
|
|
541
|
+
/** Additional custom metadata */
|
|
542
|
+
custom?: Record<string, unknown>;
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/context/ContextRules.d.ts
|
|
546
|
+
/**
|
|
547
|
+
* Proximity rule for context-based confidence adjustment
|
|
548
|
+
*/
|
|
549
|
+
interface ProximityRule {
|
|
550
|
+
/** Pattern type this rule applies to (e.g., 'EMAIL', 'PHONE', 'SSN') */
|
|
551
|
+
patternType: string | string[];
|
|
552
|
+
/** Keywords to look for near the match */
|
|
553
|
+
keywords: string[];
|
|
554
|
+
/** Maximum word distance from match (default: 10) */
|
|
555
|
+
proximityWindow?: number;
|
|
556
|
+
/** Confidence boost if keyword found (0-1) */
|
|
557
|
+
confidenceBoost?: number;
|
|
558
|
+
/** Confidence penalty if keyword found (0-1) */
|
|
559
|
+
confidencePenalty?: number;
|
|
560
|
+
/** Whether match must come AFTER keyword (default: both directions) */
|
|
561
|
+
keywordBefore?: boolean;
|
|
562
|
+
/** Whether match must come BEFORE keyword (default: both directions) */
|
|
563
|
+
keywordAfter?: boolean;
|
|
564
|
+
/** Rule description */
|
|
565
|
+
description?: string;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Domain-specific vocabulary for context detection
|
|
569
|
+
*/
|
|
570
|
+
interface DomainVocabulary {
|
|
571
|
+
/** Domain name */
|
|
572
|
+
domain: 'medical' | 'legal' | 'financial' | 'technical' | 'hr' | 'custom';
|
|
573
|
+
/** Domain-specific terms */
|
|
574
|
+
terms: string[];
|
|
575
|
+
/** Pattern types to boost in this domain */
|
|
576
|
+
boostPatterns?: string[];
|
|
577
|
+
/** Confidence boost amount (default: 0.15) */
|
|
578
|
+
boostAmount?: number;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Contextual rules configuration
|
|
582
|
+
*/
|
|
583
|
+
interface ContextRulesConfig {
|
|
584
|
+
/** Proximity rules */
|
|
585
|
+
proximityRules?: ProximityRule[];
|
|
586
|
+
/** Domain vocabularies */
|
|
587
|
+
domainVocabularies?: DomainVocabulary[];
|
|
588
|
+
/** Enable default rules (default: true) */
|
|
589
|
+
useDefaultRules?: boolean;
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/context/ContextAnalyzer.d.ts
|
|
593
|
+
/**
|
|
594
|
+
* Context Analysis for PII Detection
|
|
595
|
+
* Provides NLP-lite features to reduce false positives
|
|
596
|
+
*/
|
|
597
|
+
interface ContextAnalysis {
|
|
598
|
+
/** 5 words before detection */
|
|
599
|
+
beforeWords: string[];
|
|
600
|
+
/** 5 words after detection */
|
|
601
|
+
afterWords: string[];
|
|
602
|
+
/** Full sentence containing detection */
|
|
603
|
+
sentence: string;
|
|
604
|
+
/** Inferred document type */
|
|
605
|
+
documentType: 'email' | 'document' | 'code' | 'chat' | 'unknown';
|
|
606
|
+
/** Confidence that this is actual PII (0-1) */
|
|
607
|
+
confidence: number;
|
|
608
|
+
}
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/explain/ExplainAPI.d.ts
|
|
611
|
+
/**
|
|
612
|
+
* Pattern match result for explain
|
|
613
|
+
*/
|
|
614
|
+
interface PatternMatchResult {
|
|
615
|
+
/** Pattern that was tested */
|
|
616
|
+
pattern: PIIPattern;
|
|
617
|
+
/** Whether the pattern matched */
|
|
618
|
+
matched: boolean;
|
|
619
|
+
/** Matched value (if matched) */
|
|
620
|
+
matchedValue?: string;
|
|
621
|
+
/** Position of match (if matched) */
|
|
622
|
+
position?: [number, number];
|
|
623
|
+
/** Why it didn't match or was filtered */
|
|
624
|
+
reason?: string;
|
|
625
|
+
/** Validator result (if validator exists) */
|
|
626
|
+
validatorPassed?: boolean;
|
|
627
|
+
/** Context analysis (if enabled) */
|
|
628
|
+
contextAnalysis?: ContextAnalysis;
|
|
629
|
+
/** False positive check (if enabled) */
|
|
630
|
+
falsePositiveCheck?: {
|
|
631
|
+
isFalsePositive: boolean;
|
|
632
|
+
confidence: number;
|
|
633
|
+
reason?: string;
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Explanation for a specific text
|
|
638
|
+
*/
|
|
639
|
+
interface TextExplanation {
|
|
640
|
+
/** Original text */
|
|
641
|
+
text: string;
|
|
642
|
+
/** All pattern match results */
|
|
643
|
+
patternResults: PatternMatchResult[];
|
|
644
|
+
/** Patterns that matched */
|
|
645
|
+
matchedPatterns: PatternMatchResult[];
|
|
646
|
+
/** Patterns that didn't match */
|
|
647
|
+
unmatchedPatterns: PatternMatchResult[];
|
|
648
|
+
/** Patterns that matched but were filtered */
|
|
649
|
+
filteredPatterns: PatternMatchResult[];
|
|
650
|
+
/** Final detections */
|
|
651
|
+
detections: PIIDetection[];
|
|
652
|
+
/** Summary statistics */
|
|
653
|
+
summary: {
|
|
654
|
+
totalPatternsChecked: number;
|
|
655
|
+
patternsMatched: number;
|
|
656
|
+
patternsFiltered: number;
|
|
657
|
+
finalDetections: number;
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Explain API for debugging
|
|
662
|
+
*/
|
|
663
|
+
declare class ExplainAPI {
|
|
664
|
+
private detector;
|
|
665
|
+
private patterns;
|
|
666
|
+
private options;
|
|
667
|
+
constructor(detector: OpenRedaction);
|
|
668
|
+
/**
|
|
669
|
+
* Explain why text was or wasn't detected as PII
|
|
670
|
+
*/
|
|
671
|
+
explain(text: string): Promise<TextExplanation>;
|
|
672
|
+
/**
|
|
673
|
+
* Explain a specific detection
|
|
674
|
+
*/
|
|
675
|
+
explainDetection(detection: PIIDetection, text: string): Promise<{
|
|
676
|
+
detection: PIIDetection;
|
|
677
|
+
pattern?: PIIPattern;
|
|
678
|
+
contextAnalysis?: ContextAnalysis;
|
|
679
|
+
reasoning: string[];
|
|
680
|
+
suggestions: string[];
|
|
681
|
+
}>;
|
|
682
|
+
/**
|
|
683
|
+
* Suggest why text wasn't detected
|
|
684
|
+
*/
|
|
685
|
+
suggestWhy(text: string, expectedType: string): Promise<{
|
|
686
|
+
text: string;
|
|
687
|
+
expectedType: string;
|
|
688
|
+
suggestions: string[];
|
|
689
|
+
similarPatterns: PIIPattern[];
|
|
690
|
+
}>;
|
|
691
|
+
/**
|
|
692
|
+
* Get debugging information for entire detection process
|
|
693
|
+
*/
|
|
694
|
+
debug(text: string): Promise<{
|
|
695
|
+
text: string;
|
|
696
|
+
textLength: number;
|
|
697
|
+
enabledFeatures: string[];
|
|
698
|
+
patternCount: number;
|
|
699
|
+
explanation: TextExplanation;
|
|
700
|
+
performance: {
|
|
701
|
+
estimatedTime: string;
|
|
702
|
+
};
|
|
703
|
+
}>;
|
|
704
|
+
}
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/reports/ReportGenerator.d.ts
|
|
707
|
+
/**
|
|
708
|
+
* Report format options
|
|
709
|
+
*/
|
|
710
|
+
type ReportFormat = 'html' | 'markdown';
|
|
711
|
+
/**
|
|
712
|
+
* Report type options
|
|
713
|
+
*/
|
|
714
|
+
type ReportType = 'summary' | 'detailed' | 'compliance';
|
|
715
|
+
/**
|
|
716
|
+
* Report generation options
|
|
717
|
+
*/
|
|
718
|
+
interface ReportOptions {
|
|
719
|
+
/** Report format */
|
|
720
|
+
format: ReportFormat;
|
|
721
|
+
/** Report type */
|
|
722
|
+
type?: ReportType;
|
|
723
|
+
/** Report title */
|
|
724
|
+
title?: string;
|
|
725
|
+
/** Include original text (default: false for privacy) */
|
|
726
|
+
includeOriginalText?: boolean;
|
|
727
|
+
/** Include redacted text (default: true) */
|
|
728
|
+
includeRedactedText?: boolean;
|
|
729
|
+
/** Include detection details (default: true) */
|
|
730
|
+
includeDetectionDetails?: boolean;
|
|
731
|
+
/** Include statistics (default: true) */
|
|
732
|
+
includeStatistics?: boolean;
|
|
733
|
+
/** Include explanation (requires ExplainAPI, default: false) */
|
|
734
|
+
includeExplanation?: boolean;
|
|
735
|
+
/** Company/project name for compliance reports */
|
|
736
|
+
organizationName?: string;
|
|
737
|
+
/** Additional metadata */
|
|
738
|
+
metadata?: Record<string, string>;
|
|
739
|
+
}
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/detector.d.ts
|
|
742
|
+
declare class OpenRedaction {
|
|
743
|
+
private patterns;
|
|
744
|
+
private compiledPatterns;
|
|
745
|
+
private options;
|
|
746
|
+
private multiPassConfig?;
|
|
747
|
+
private resultCache?;
|
|
748
|
+
private valueToPlaceholder;
|
|
749
|
+
private placeholderCounter;
|
|
750
|
+
private learningStore?;
|
|
751
|
+
private priorityOptimizer?;
|
|
752
|
+
private enableLearning;
|
|
753
|
+
private auditLogger?;
|
|
754
|
+
private auditUser?;
|
|
755
|
+
private auditSessionId?;
|
|
756
|
+
private auditMetadata?;
|
|
757
|
+
private metricsCollector?;
|
|
758
|
+
private rbacManager?;
|
|
759
|
+
private nerDetector?;
|
|
760
|
+
private contextRulesEngine?;
|
|
761
|
+
private severityClassifier;
|
|
762
|
+
constructor(options?: OpenRedactionOptions & {
|
|
763
|
+
configPath?: string;
|
|
764
|
+
enableLearning?: boolean;
|
|
765
|
+
learningStorePath?: string;
|
|
766
|
+
enablePriorityOptimization?: boolean;
|
|
767
|
+
optimizerOptions?: Partial<OptimizerOptions>;
|
|
768
|
+
enableNER?: boolean;
|
|
769
|
+
enableContextRules?: boolean;
|
|
770
|
+
contextRulesConfig?: ContextRulesConfig;
|
|
771
|
+
maxInputSize?: number;
|
|
772
|
+
regexTimeout?: number;
|
|
773
|
+
});
|
|
774
|
+
/**
|
|
775
|
+
* Create OpenRedaction instance from config file
|
|
776
|
+
*/
|
|
777
|
+
static fromConfig(configPath?: string): Promise<OpenRedaction>;
|
|
778
|
+
/**
|
|
779
|
+
* Build the list of patterns based on options
|
|
780
|
+
* Supports three filtering modes (in order of priority):
|
|
781
|
+
* 1. Specific pattern types (patterns option)
|
|
782
|
+
* 2. Pattern categories (categories option) - NEW!
|
|
783
|
+
* 3. All patterns with type-specific filters (includeNames, etc.)
|
|
784
|
+
*/
|
|
785
|
+
private buildPatternList;
|
|
786
|
+
/**
|
|
787
|
+
* Validate all patterns to prevent malicious regex injection
|
|
788
|
+
* ONLY validates custom patterns - built-in patterns are already vetted
|
|
789
|
+
* Timeout protection in safeExec() is the primary defense against ReDoS
|
|
790
|
+
*/
|
|
791
|
+
private validatePatterns;
|
|
792
|
+
/**
|
|
793
|
+
* Pre-compile all regex patterns for performance
|
|
794
|
+
* Avoids creating new RegExp objects on every detect() call
|
|
795
|
+
*/
|
|
796
|
+
private precompilePatterns;
|
|
797
|
+
/**
|
|
798
|
+
* Process patterns and detect PII
|
|
799
|
+
* Used by both single-pass and multi-pass detection
|
|
800
|
+
*/
|
|
801
|
+
private processPatterns;
|
|
802
|
+
/**
|
|
803
|
+
* Detect PII in text
|
|
804
|
+
* Now async to support optional AI assist
|
|
805
|
+
*/
|
|
806
|
+
detect(text: string): Promise<DetectionResult>;
|
|
807
|
+
/**
|
|
808
|
+
* Restore redacted text using redaction map
|
|
809
|
+
*/
|
|
810
|
+
restore(redactedText: string, redactionMap: Record<string, string>): string;
|
|
811
|
+
/**
|
|
812
|
+
* Generate placeholder for a detected value
|
|
813
|
+
*/
|
|
814
|
+
private generatePlaceholder;
|
|
815
|
+
/**
|
|
816
|
+
* Check if a range overlaps with existing detections
|
|
817
|
+
*/
|
|
818
|
+
private overlapsWithExisting;
|
|
819
|
+
/**
|
|
820
|
+
* Escape special regex characters
|
|
821
|
+
*/
|
|
822
|
+
private escapeRegex;
|
|
823
|
+
/**
|
|
824
|
+
* Get the list of active patterns
|
|
825
|
+
*/
|
|
826
|
+
getPatterns(): PIIPattern[];
|
|
827
|
+
/**
|
|
828
|
+
* Get severity-based scan results
|
|
829
|
+
*/
|
|
830
|
+
scan(text: string): Promise<{
|
|
831
|
+
high: PIIDetection[];
|
|
832
|
+
medium: PIIDetection[];
|
|
833
|
+
low: PIIDetection[];
|
|
834
|
+
total: number;
|
|
835
|
+
}>;
|
|
836
|
+
/**
|
|
837
|
+
* Record a false positive (incorrectly detected as PII)
|
|
838
|
+
*/
|
|
839
|
+
recordFalsePositive(detection: PIIDetection, context?: string): void;
|
|
840
|
+
/**
|
|
841
|
+
* Record a false negative (missed PII that should have been detected)
|
|
842
|
+
*/
|
|
843
|
+
recordFalseNegative(text: string, expectedType: string, context?: string): void;
|
|
844
|
+
/**
|
|
845
|
+
* Record a correct detection (for accuracy tracking)
|
|
846
|
+
*/
|
|
847
|
+
recordCorrectDetection(): void;
|
|
848
|
+
/**
|
|
849
|
+
* Get learning statistics
|
|
850
|
+
*/
|
|
851
|
+
getLearningStats(): LearningStats | null;
|
|
852
|
+
/**
|
|
853
|
+
* Get learned whitelist entries
|
|
854
|
+
*/
|
|
855
|
+
getLearnedWhitelist(): WhitelistEntry[];
|
|
856
|
+
/**
|
|
857
|
+
* Get pattern adjustment suggestions
|
|
858
|
+
*/
|
|
859
|
+
getPatternAdjustments(): PatternAdjustment[];
|
|
860
|
+
/**
|
|
861
|
+
* Export learned patterns for sharing
|
|
862
|
+
*/
|
|
863
|
+
exportLearnings(options?: {
|
|
864
|
+
includeContexts?: boolean;
|
|
865
|
+
minConfidence?: number;
|
|
866
|
+
}): LearningData | null;
|
|
867
|
+
/**
|
|
868
|
+
* Import learned patterns from another source
|
|
869
|
+
*/
|
|
870
|
+
importLearnings(data: any, merge?: boolean): void;
|
|
871
|
+
/**
|
|
872
|
+
* Manually add a term to the whitelist
|
|
873
|
+
*/
|
|
874
|
+
addToWhitelist(pattern: string, confidence?: number): void;
|
|
875
|
+
/**
|
|
876
|
+
* Remove a term from the whitelist
|
|
877
|
+
*/
|
|
878
|
+
removeFromWhitelist(pattern: string): void;
|
|
879
|
+
/**
|
|
880
|
+
* Get the learning store instance
|
|
881
|
+
*/
|
|
882
|
+
getLearningStore(): LocalLearningStore | undefined;
|
|
883
|
+
/**
|
|
884
|
+
* Get the priority optimizer instance
|
|
885
|
+
*/
|
|
886
|
+
getPriorityOptimizer(): PriorityOptimizer | undefined;
|
|
887
|
+
/**
|
|
888
|
+
* Optimize pattern priorities based on learning data
|
|
889
|
+
* Call this to re-optimize priorities after accumulating new learning data
|
|
890
|
+
*/
|
|
891
|
+
optimizePriorities(): void;
|
|
892
|
+
/**
|
|
893
|
+
* Get pattern statistics with learning data
|
|
894
|
+
*/
|
|
895
|
+
getPatternStats(): PatternStats[] | null;
|
|
896
|
+
/**
|
|
897
|
+
* Clear the result cache (if caching is enabled)
|
|
898
|
+
*/
|
|
899
|
+
clearCache(): void;
|
|
900
|
+
/**
|
|
901
|
+
* Get cache statistics
|
|
902
|
+
*/
|
|
903
|
+
getCacheStats(): {
|
|
904
|
+
size: number;
|
|
905
|
+
maxSize: number;
|
|
906
|
+
enabled: boolean;
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* Get the audit logger instance (if audit logging is enabled)
|
|
910
|
+
*/
|
|
911
|
+
getAuditLogger(): IAuditLogger | undefined;
|
|
912
|
+
/**
|
|
913
|
+
* Get the metrics collector instance (if metrics collection is enabled)
|
|
914
|
+
*/
|
|
915
|
+
getMetricsCollector(): IMetricsCollector | undefined;
|
|
916
|
+
/**
|
|
917
|
+
* Get the RBAC manager instance (if RBAC is enabled)
|
|
918
|
+
*/
|
|
919
|
+
getRBACManager(): IRBACManager | undefined;
|
|
920
|
+
/**
|
|
921
|
+
* Create an explain API for debugging detections
|
|
922
|
+
*/
|
|
923
|
+
explain(): ExplainAPI;
|
|
924
|
+
/**
|
|
925
|
+
* Generate a report from detection results
|
|
926
|
+
*/
|
|
927
|
+
generateReport(result: DetectionResult, options: ReportOptions): string;
|
|
928
|
+
/**
|
|
929
|
+
* Export current configuration
|
|
930
|
+
*/
|
|
931
|
+
exportConfig(metadata?: {
|
|
932
|
+
description?: string;
|
|
933
|
+
author?: string;
|
|
934
|
+
tags?: string[];
|
|
935
|
+
}): string;
|
|
936
|
+
/**
|
|
937
|
+
* Run health check
|
|
938
|
+
*/
|
|
939
|
+
healthCheck(options?: {
|
|
940
|
+
testDetection?: boolean;
|
|
941
|
+
checkPerformance?: boolean;
|
|
942
|
+
performanceThreshold?: number;
|
|
943
|
+
memoryThreshold?: number;
|
|
944
|
+
}): Promise<any>;
|
|
945
|
+
/**
|
|
946
|
+
* Quick health check (minimal overhead)
|
|
947
|
+
*/
|
|
948
|
+
quickHealthCheck(): Promise<{
|
|
949
|
+
status: 'healthy' | 'unhealthy';
|
|
950
|
+
message: string;
|
|
951
|
+
}>;
|
|
952
|
+
/**
|
|
953
|
+
* Detect PII in a document (PDF, DOCX, TXT)
|
|
954
|
+
* Requires optional peer dependencies:
|
|
955
|
+
* - pdf-parse for PDF support
|
|
956
|
+
* - mammoth for DOCX support
|
|
957
|
+
*/
|
|
958
|
+
detectDocument(buffer: Buffer, options?: DocumentOptions): Promise<DocumentResult>;
|
|
959
|
+
/**
|
|
960
|
+
* Detect PII in a document file from filesystem
|
|
961
|
+
* Convenience method that reads file and calls detectDocument
|
|
962
|
+
*/
|
|
963
|
+
detectDocumentFile(filePath: string, options?: DocumentOptions): Promise<DocumentResult>;
|
|
964
|
+
/**
|
|
965
|
+
* Batch detect PII in multiple texts using worker threads (parallel)
|
|
966
|
+
* Significantly faster for processing many texts
|
|
967
|
+
*/
|
|
968
|
+
static detectBatch(texts: string[], options?: OpenRedactionOptions & {
|
|
969
|
+
numWorkers?: number;
|
|
970
|
+
}): Promise<DetectionResult[]>;
|
|
971
|
+
/**
|
|
972
|
+
* Batch process multiple documents using worker threads (parallel)
|
|
973
|
+
* Efficient for processing many documents at once
|
|
974
|
+
*/
|
|
975
|
+
static detectDocumentsBatch(buffers: Buffer[], options?: DocumentOptions & {
|
|
976
|
+
numWorkers?: number;
|
|
977
|
+
}): Promise<DocumentResult[]>;
|
|
978
|
+
}
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region src/integrations/react.d.ts
|
|
981
|
+
/**
|
|
982
|
+
* Hook for PII detection in React components
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```tsx
|
|
986
|
+
* function MyForm() {
|
|
987
|
+
* const { detect, result, isDetecting } = useOpenRedaction();
|
|
988
|
+
*
|
|
989
|
+
* const handleSubmit = (text: string) => {
|
|
990
|
+
* const detection = detect(text);
|
|
991
|
+
* if (detection.detections.length > 0) {
|
|
992
|
+
* alert('PII detected!');
|
|
993
|
+
* }
|
|
994
|
+
* };
|
|
995
|
+
* }
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
declare function useOpenRedaction(options?: OpenRedactionOptions): {
|
|
999
|
+
detect: (text: string) => Promise<DetectionResult>;
|
|
1000
|
+
result: DetectionResult | null;
|
|
1001
|
+
isDetecting: boolean;
|
|
1002
|
+
hasPII: boolean;
|
|
1003
|
+
count: number;
|
|
1004
|
+
clear: () => void;
|
|
1005
|
+
detector: OpenRedaction;
|
|
1006
|
+
};
|
|
1007
|
+
/**
|
|
1008
|
+
* Hook for real-time PII detection with debouncing
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* ```tsx
|
|
1012
|
+
* function EmailInput() {
|
|
1013
|
+
* const [email, setEmail] = useState('');
|
|
1014
|
+
* const { result, hasPII } = usePIIDetector(email, { debounce: 500 });
|
|
1015
|
+
*
|
|
1016
|
+
* return (
|
|
1017
|
+
* <div>
|
|
1018
|
+
* <input value={email} onChange={e => setEmail(e.target.value)} />
|
|
1019
|
+
* {hasPII && <Warning>PII detected!</Warning>}
|
|
1020
|
+
* </div>
|
|
1021
|
+
* );
|
|
1022
|
+
* }
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
declare function usePIIDetector(text: string, options?: OpenRedactionOptions & {
|
|
1026
|
+
debounce?: number;
|
|
1027
|
+
}): {
|
|
1028
|
+
result: DetectionResult | null;
|
|
1029
|
+
isDetecting: boolean;
|
|
1030
|
+
hasPII: boolean;
|
|
1031
|
+
count: number;
|
|
1032
|
+
detections: PIIDetection[];
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* Hook for form field PII validation
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```tsx
|
|
1039
|
+
* function UserForm() {
|
|
1040
|
+
* const emailValidation = useFormFieldValidator({
|
|
1041
|
+
* failOnPII: true,
|
|
1042
|
+
* types: ['EMAIL', 'PHONE']
|
|
1043
|
+
* });
|
|
1044
|
+
*
|
|
1045
|
+
* return (
|
|
1046
|
+
* <input
|
|
1047
|
+
* {...emailValidation.getFieldProps()}
|
|
1048
|
+
* onChange={e => emailValidation.validate(e.target.value)}
|
|
1049
|
+
* />
|
|
1050
|
+
* );
|
|
1051
|
+
* }
|
|
1052
|
+
* ```
|
|
1053
|
+
*/
|
|
1054
|
+
declare function useFormFieldValidator(options?: OpenRedactionOptions & {
|
|
1055
|
+
failOnPII?: boolean;
|
|
1056
|
+
types?: string[];
|
|
1057
|
+
onPIIDetected?: (result: DetectionResult) => void;
|
|
1058
|
+
}): {
|
|
1059
|
+
value: string;
|
|
1060
|
+
error: string | null;
|
|
1061
|
+
result: DetectionResult | null;
|
|
1062
|
+
validate: (inputValue: string) => Promise<boolean>;
|
|
1063
|
+
getFieldProps: () => {
|
|
1064
|
+
value: string;
|
|
1065
|
+
'aria-invalid': string;
|
|
1066
|
+
'aria-describedby': string | undefined;
|
|
1067
|
+
};
|
|
1068
|
+
isValid: boolean;
|
|
1069
|
+
hasPII: boolean;
|
|
1070
|
+
};
|
|
1071
|
+
/**
|
|
1072
|
+
* Hook for batch PII detection
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```tsx
|
|
1076
|
+
* function BatchProcessor() {
|
|
1077
|
+
* const { processAll, results, isProcessing } = useBatchDetector();
|
|
1078
|
+
*
|
|
1079
|
+
* const handleProcess = async () => {
|
|
1080
|
+
* const documents = ['text1', 'text2', 'text3'];
|
|
1081
|
+
* await processAll(documents);
|
|
1082
|
+
* };
|
|
1083
|
+
* }
|
|
1084
|
+
* ```
|
|
1085
|
+
*/
|
|
1086
|
+
declare function useBatchDetector(options?: OpenRedactionOptions): {
|
|
1087
|
+
processAll: (texts: string[]) => Promise<DetectionResult[]>;
|
|
1088
|
+
results: DetectionResult[];
|
|
1089
|
+
isProcessing: boolean;
|
|
1090
|
+
progress: number;
|
|
1091
|
+
totalDetections: number;
|
|
1092
|
+
clear: () => void;
|
|
1093
|
+
};
|
|
1094
|
+
/**
|
|
1095
|
+
* Hook for PII detection with auto-redaction
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```tsx
|
|
1099
|
+
* function SecureTextArea() {
|
|
1100
|
+
* const { text, setText, redactedText, hasPII } = useAutoRedact();
|
|
1101
|
+
*
|
|
1102
|
+
* return (
|
|
1103
|
+
* <div>
|
|
1104
|
+
* <textarea value={text} onChange={e => setText(e.target.value)} />
|
|
1105
|
+
* {hasPII && <div>Redacted: {redactedText}</div>}
|
|
1106
|
+
* </div>
|
|
1107
|
+
* );
|
|
1108
|
+
* }
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
declare function useAutoRedact(options?: OpenRedactionOptions & {
|
|
1112
|
+
debounce?: number;
|
|
1113
|
+
}): {
|
|
1114
|
+
text: string;
|
|
1115
|
+
setText: react0.Dispatch<react0.SetStateAction<string>>;
|
|
1116
|
+
result: DetectionResult | null;
|
|
1117
|
+
redactedText: string;
|
|
1118
|
+
hasPII: boolean;
|
|
1119
|
+
detections: PIIDetection[];
|
|
1120
|
+
count: number;
|
|
1121
|
+
};
|
|
1122
|
+
//#endregion
|
|
1123
|
+
export { useAutoRedact, useBatchDetector, useFormFieldValidator, useOpenRedaction, usePIIDetector };
|
|
1124
|
+
//# sourceMappingURL=react.d.ts.map
|