openred 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/chunk-65T2K4W6.js +629 -0
- package/dist/chunk-ABSJVCYK.js +44 -0
- package/dist/chunk-DWYPLA6C.cjs +48 -0
- package/dist/chunk-VAXUQISI.cjs +648 -0
- package/dist/index.cjs +258 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +187 -0
- package/dist/integrations/anthropic.cjs +52 -0
- package/dist/integrations/anthropic.d.cts +35 -0
- package/dist/integrations/anthropic.d.ts +35 -0
- package/dist/integrations/anthropic.js +50 -0
- package/dist/integrations/langchain.cjs +28 -0
- package/dist/integrations/langchain.d.cts +18 -0
- package/dist/integrations/langchain.d.ts +18 -0
- package/dist/integrations/langchain.js +26 -0
- package/dist/integrations/openai.cjs +40 -0
- package/dist/integrations/openai.d.cts +38 -0
- package/dist/integrations/openai.d.ts +38 -0
- package/dist/integrations/openai.js +38 -0
- package/dist/middleware/express.cjs +30 -0
- package/dist/middleware/express.d.cts +16 -0
- package/dist/middleware/express.d.ts +16 -0
- package/dist/middleware/express.js +28 -0
- package/dist/middleware/fastify.cjs +23 -0
- package/dist/middleware/fastify.d.cts +27 -0
- package/dist/middleware/fastify.d.ts +27 -0
- package/dist/middleware/fastify.js +21 -0
- package/dist/pipeline-D_6YC4Us.d.cts +16 -0
- package/dist/pipeline-gWjT4cYU.d.ts +16 -0
- package/dist/vault-CDr54-Ev.d.cts +80 -0
- package/dist/vault-CDr54-Ev.d.ts +80 -0
- package/package.json +112 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
type PIIType = 'EMAIL' | 'PHONE' | 'SSN' | 'CREDIT_CARD' | 'IP_ADDRESS' | 'DATE_OF_BIRTH' | 'ADDRESS' | 'URL' | (string & {});
|
|
2
|
+
type ConfidenceLevel = 'high' | 'medium' | 'low';
|
|
3
|
+
interface PIIMatch {
|
|
4
|
+
type: PIIType;
|
|
5
|
+
value: string;
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
confidence: number;
|
|
9
|
+
detector: string;
|
|
10
|
+
}
|
|
11
|
+
interface PIIDetector {
|
|
12
|
+
name: string;
|
|
13
|
+
type: PIIType;
|
|
14
|
+
confidence: ConfidenceLevel;
|
|
15
|
+
detect(text: string, context?: DetectionContext): PIIMatch[];
|
|
16
|
+
}
|
|
17
|
+
interface DetectionContext {
|
|
18
|
+
locale?: string;
|
|
19
|
+
}
|
|
20
|
+
type RedactorFn = (match: PIIMatch) => string;
|
|
21
|
+
type RedactionStrategy = 'placeholder' | 'hash' | 'mask' | 'category' | RedactorFn;
|
|
22
|
+
interface TokenMapping {
|
|
23
|
+
original: string;
|
|
24
|
+
replacement: string;
|
|
25
|
+
type: PIIType;
|
|
26
|
+
confidence: number;
|
|
27
|
+
}
|
|
28
|
+
interface RedactionResult {
|
|
29
|
+
text: string;
|
|
30
|
+
matches: PIIMatch[];
|
|
31
|
+
tokens: TokenMapping[];
|
|
32
|
+
stats: {
|
|
33
|
+
totalDetected: number;
|
|
34
|
+
byType: Record<string, number>;
|
|
35
|
+
processingTimeMs: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
interface VaultEntry {
|
|
39
|
+
original: string;
|
|
40
|
+
replacement: string;
|
|
41
|
+
type: PIIType;
|
|
42
|
+
}
|
|
43
|
+
interface AggregatorConfig {
|
|
44
|
+
overlapResolution: 'longest' | 'highest-confidence' | 'first';
|
|
45
|
+
minConfidence: number;
|
|
46
|
+
mergeAdjacent: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface PipelineConfig {
|
|
49
|
+
detectors: PIIDetector[];
|
|
50
|
+
locale?: string;
|
|
51
|
+
minConfidence?: number;
|
|
52
|
+
strategy?: RedactionStrategy;
|
|
53
|
+
vault?: boolean;
|
|
54
|
+
vaultTTL?: number;
|
|
55
|
+
allowList?: string[];
|
|
56
|
+
denyList?: string[];
|
|
57
|
+
overlapResolution?: 'longest' | 'highest-confidence' | 'first';
|
|
58
|
+
onDetection?: (match: PIIMatch) => void;
|
|
59
|
+
onRedaction?: (result: RedactionResult) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare class Vault {
|
|
63
|
+
private replacementToOriginal;
|
|
64
|
+
private originalToReplacement;
|
|
65
|
+
private ttl?;
|
|
66
|
+
private timers;
|
|
67
|
+
constructor(options?: {
|
|
68
|
+
ttl?: number;
|
|
69
|
+
});
|
|
70
|
+
store(original: string, replacement: string, type: PIIType): void;
|
|
71
|
+
getReplacementFor(original: string): string | undefined;
|
|
72
|
+
restore(text: string): string;
|
|
73
|
+
getMapping(): Map<string, VaultEntry>;
|
|
74
|
+
getEntries(): VaultEntry[];
|
|
75
|
+
clear(): void;
|
|
76
|
+
export(): string;
|
|
77
|
+
import(data: string): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { type AggregatorConfig as A, type ConfidenceLevel as C, type DetectionContext as D, type PIIMatch as P, type RedactorFn as R, type TokenMapping as T, Vault as V, type PIIDetector as a, type RedactionStrategy as b, type PIIType as c, type PipelineConfig as d, type RedactionResult as e, type VaultEntry as f };
|
package/package.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openred",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Fast, zero-dependency PII redaction for AI pipelines",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./middleware/express": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/middleware/express.d.ts",
|
|
23
|
+
"default": "./dist/middleware/express.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/middleware/express.d.cts",
|
|
27
|
+
"default": "./dist/middleware/express.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./middleware/fastify": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/middleware/fastify.d.ts",
|
|
33
|
+
"default": "./dist/middleware/fastify.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/middleware/fastify.d.cts",
|
|
37
|
+
"default": "./dist/middleware/fastify.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./integrations/openai": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/integrations/openai.d.ts",
|
|
43
|
+
"default": "./dist/integrations/openai.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/integrations/openai.d.cts",
|
|
47
|
+
"default": "./dist/integrations/openai.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./integrations/anthropic": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/integrations/anthropic.d.ts",
|
|
53
|
+
"default": "./dist/integrations/anthropic.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/integrations/anthropic.d.cts",
|
|
57
|
+
"default": "./dist/integrations/anthropic.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./integrations/langchain": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/integrations/langchain.d.ts",
|
|
63
|
+
"default": "./dist/integrations/langchain.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/integrations/langchain.d.cts",
|
|
67
|
+
"default": "./dist/integrations/langchain.cjs"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"dist"
|
|
73
|
+
],
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsup",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"test:watch": "vitest",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"bench": "tsx benchmarks/performance.ts",
|
|
80
|
+
"bench:accuracy": "tsx benchmarks/accuracy.ts"
|
|
81
|
+
},
|
|
82
|
+
"keywords": [
|
|
83
|
+
"pii",
|
|
84
|
+
"redaction",
|
|
85
|
+
"privacy",
|
|
86
|
+
"ai",
|
|
87
|
+
"llm",
|
|
88
|
+
"data-protection",
|
|
89
|
+
"gdpr",
|
|
90
|
+
"ccpa",
|
|
91
|
+
"openai",
|
|
92
|
+
"anthropic",
|
|
93
|
+
"langchain",
|
|
94
|
+
"middleware"
|
|
95
|
+
],
|
|
96
|
+
"repository": {
|
|
97
|
+
"type": "git",
|
|
98
|
+
"url": "git+https://github.com/ErnestCodes/openred.git"
|
|
99
|
+
},
|
|
100
|
+
"homepage": "https://github.com/ErnestCodes/openred#readme",
|
|
101
|
+
"bugs": {
|
|
102
|
+
"url": "https://github.com/ErnestCodes/openred/issues"
|
|
103
|
+
},
|
|
104
|
+
"license": "MIT",
|
|
105
|
+
"devDependencies": {
|
|
106
|
+
"@types/node": "^25.2.1",
|
|
107
|
+
"tsup": "^8.0.0",
|
|
108
|
+
"tsx": "^4.21.0",
|
|
109
|
+
"typescript": "^5.4.0",
|
|
110
|
+
"vitest": "^2.0.0"
|
|
111
|
+
}
|
|
112
|
+
}
|