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
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVAXUQISI_cjs = require('./chunk-VAXUQISI.cjs');
|
|
4
|
+
|
|
5
|
+
// src/locales/en-US.ts
|
|
6
|
+
var enUS = [
|
|
7
|
+
chunkVAXUQISI_cjs.EmailDetector,
|
|
8
|
+
chunkVAXUQISI_cjs.PhoneDetector,
|
|
9
|
+
chunkVAXUQISI_cjs.SSNDetector,
|
|
10
|
+
chunkVAXUQISI_cjs.CreditCardDetector,
|
|
11
|
+
chunkVAXUQISI_cjs.IPAddressDetector,
|
|
12
|
+
chunkVAXUQISI_cjs.URLDetector,
|
|
13
|
+
chunkVAXUQISI_cjs.DateOfBirthDetector,
|
|
14
|
+
chunkVAXUQISI_cjs.AddressDetector
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
// src/locales/en-GB.ts
|
|
18
|
+
var UK_PHONE_RE = /(?:\+44[\s.-]?|0)(?:\d[\s.-]?){9,10}/g;
|
|
19
|
+
var UKPhoneDetector = {
|
|
20
|
+
name: "uk-phone",
|
|
21
|
+
type: "PHONE",
|
|
22
|
+
confidence: "high",
|
|
23
|
+
detect(text) {
|
|
24
|
+
const matches = [];
|
|
25
|
+
UK_PHONE_RE.lastIndex = 0;
|
|
26
|
+
let match;
|
|
27
|
+
while ((match = UK_PHONE_RE.exec(text)) !== null) {
|
|
28
|
+
const value = match[0];
|
|
29
|
+
const digits = chunkVAXUQISI_cjs.countDigits(value);
|
|
30
|
+
if (digits < 10 || digits > 12) continue;
|
|
31
|
+
matches.push({
|
|
32
|
+
type: "PHONE",
|
|
33
|
+
value,
|
|
34
|
+
start: match.index,
|
|
35
|
+
end: match.index + value.length,
|
|
36
|
+
confidence: 0.9,
|
|
37
|
+
detector: "uk-phone"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return matches;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var NINO_RE = /\b[A-CEGHJ-PR-TW-Z]{2}\s?\d{2}\s?\d{2}\s?\d{2}\s?[A-D]\b/g;
|
|
44
|
+
var NINODetector = {
|
|
45
|
+
name: "nino",
|
|
46
|
+
type: "SSN",
|
|
47
|
+
// Closest equivalent
|
|
48
|
+
confidence: "high",
|
|
49
|
+
detect(text) {
|
|
50
|
+
const matches = [];
|
|
51
|
+
NINO_RE.lastIndex = 0;
|
|
52
|
+
let match;
|
|
53
|
+
while ((match = NINO_RE.exec(text)) !== null) {
|
|
54
|
+
matches.push({
|
|
55
|
+
type: "SSN",
|
|
56
|
+
value: match[0],
|
|
57
|
+
start: match.index,
|
|
58
|
+
end: match.index + match[0].length,
|
|
59
|
+
confidence: 0.85,
|
|
60
|
+
detector: "nino"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return matches;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var UK_POSTCODE_RE = /\b[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}\b/gi;
|
|
67
|
+
var UKPostcodeDetector = {
|
|
68
|
+
name: "uk-postcode",
|
|
69
|
+
type: "ADDRESS",
|
|
70
|
+
confidence: "medium",
|
|
71
|
+
detect(text) {
|
|
72
|
+
const matches = [];
|
|
73
|
+
UK_POSTCODE_RE.lastIndex = 0;
|
|
74
|
+
let match;
|
|
75
|
+
while ((match = UK_POSTCODE_RE.exec(text)) !== null) {
|
|
76
|
+
matches.push({
|
|
77
|
+
type: "ADDRESS",
|
|
78
|
+
value: match[0],
|
|
79
|
+
start: match.index,
|
|
80
|
+
end: match.index + match[0].length,
|
|
81
|
+
confidence: 0.7,
|
|
82
|
+
detector: "uk-postcode"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return matches;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var enGB = [
|
|
89
|
+
chunkVAXUQISI_cjs.EmailDetector,
|
|
90
|
+
UKPhoneDetector,
|
|
91
|
+
NINODetector,
|
|
92
|
+
chunkVAXUQISI_cjs.CreditCardDetector,
|
|
93
|
+
chunkVAXUQISI_cjs.IPAddressDetector,
|
|
94
|
+
chunkVAXUQISI_cjs.URLDetector,
|
|
95
|
+
chunkVAXUQISI_cjs.DateOfBirthDetector,
|
|
96
|
+
UKPostcodeDetector
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
// src/locales/de-DE.ts
|
|
100
|
+
var DE_PHONE_RE = /(?:\+49[\s.-]?|0)(?:\d[\s.-]?){8,12}/g;
|
|
101
|
+
var DEPhoneDetector = {
|
|
102
|
+
name: "de-phone",
|
|
103
|
+
type: "PHONE",
|
|
104
|
+
confidence: "high",
|
|
105
|
+
detect(text) {
|
|
106
|
+
const matches = [];
|
|
107
|
+
DE_PHONE_RE.lastIndex = 0;
|
|
108
|
+
let match;
|
|
109
|
+
while ((match = DE_PHONE_RE.exec(text)) !== null) {
|
|
110
|
+
const value = match[0];
|
|
111
|
+
const digits = chunkVAXUQISI_cjs.countDigits(value);
|
|
112
|
+
if (digits < 9 || digits > 13) continue;
|
|
113
|
+
matches.push({
|
|
114
|
+
type: "PHONE",
|
|
115
|
+
value,
|
|
116
|
+
start: match.index,
|
|
117
|
+
end: match.index + value.length,
|
|
118
|
+
confidence: 0.85,
|
|
119
|
+
detector: "de-phone"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return matches;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var STEUER_ID_RE = /\b\d{2}\s?\d{3}\s?\d{3}\s?\d{3}\b/g;
|
|
126
|
+
var SteuerIDDetector = {
|
|
127
|
+
name: "steuer-id",
|
|
128
|
+
type: "SSN",
|
|
129
|
+
confidence: "medium",
|
|
130
|
+
detect(text) {
|
|
131
|
+
const matches = [];
|
|
132
|
+
const hasContext = /\b(?:Steuer|IdNr|Identifikationsnummer|TIN)\b/i.test(text);
|
|
133
|
+
if (!hasContext) return matches;
|
|
134
|
+
STEUER_ID_RE.lastIndex = 0;
|
|
135
|
+
let match;
|
|
136
|
+
while ((match = STEUER_ID_RE.exec(text)) !== null) {
|
|
137
|
+
const digits = match[0].replace(/\s/g, "");
|
|
138
|
+
if (digits.length !== 11) continue;
|
|
139
|
+
matches.push({
|
|
140
|
+
type: "SSN",
|
|
141
|
+
value: match[0],
|
|
142
|
+
start: match.index,
|
|
143
|
+
end: match.index + match[0].length,
|
|
144
|
+
confidence: 0.7,
|
|
145
|
+
detector: "steuer-id"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return matches;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var DE_PLZ_RE = /\b\d{5}\b/g;
|
|
152
|
+
var DEPostalCodeDetector = {
|
|
153
|
+
name: "de-plz",
|
|
154
|
+
type: "ADDRESS",
|
|
155
|
+
confidence: "low",
|
|
156
|
+
detect(text) {
|
|
157
|
+
const matches = [];
|
|
158
|
+
const hasContext = /\b(?:PLZ|Postleitzahl|Adresse|wohn|Straße|Str\.)\b/i.test(text);
|
|
159
|
+
if (!hasContext) return matches;
|
|
160
|
+
DE_PLZ_RE.lastIndex = 0;
|
|
161
|
+
let match;
|
|
162
|
+
while ((match = DE_PLZ_RE.exec(text)) !== null) {
|
|
163
|
+
const num = parseInt(match[0], 10);
|
|
164
|
+
if (num < 1e3 || num > 99999) continue;
|
|
165
|
+
matches.push({
|
|
166
|
+
type: "ADDRESS",
|
|
167
|
+
value: match[0],
|
|
168
|
+
start: match.index,
|
|
169
|
+
end: match.index + match[0].length,
|
|
170
|
+
confidence: 0.5,
|
|
171
|
+
detector: "de-plz"
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return matches;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var deDE = [
|
|
178
|
+
chunkVAXUQISI_cjs.EmailDetector,
|
|
179
|
+
DEPhoneDetector,
|
|
180
|
+
SteuerIDDetector,
|
|
181
|
+
chunkVAXUQISI_cjs.CreditCardDetector,
|
|
182
|
+
chunkVAXUQISI_cjs.IPAddressDetector,
|
|
183
|
+
chunkVAXUQISI_cjs.URLDetector,
|
|
184
|
+
chunkVAXUQISI_cjs.DateOfBirthDetector,
|
|
185
|
+
DEPostalCodeDetector
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
Object.defineProperty(exports, "AddressDetector", {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () { return chunkVAXUQISI_cjs.AddressDetector; }
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "CreditCardDetector", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () { return chunkVAXUQISI_cjs.CreditCardDetector; }
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(exports, "DateOfBirthDetector", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
get: function () { return chunkVAXUQISI_cjs.DateOfBirthDetector; }
|
|
199
|
+
});
|
|
200
|
+
Object.defineProperty(exports, "EmailDetector", {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
get: function () { return chunkVAXUQISI_cjs.EmailDetector; }
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, "IPAddressDetector", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () { return chunkVAXUQISI_cjs.IPAddressDetector; }
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(exports, "PhoneDetector", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function () { return chunkVAXUQISI_cjs.PhoneDetector; }
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, "RedactionPipeline", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function () { return chunkVAXUQISI_cjs.RedactionPipeline; }
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, "SSNDetector", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () { return chunkVAXUQISI_cjs.SSNDetector; }
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(exports, "URLDetector", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () { return chunkVAXUQISI_cjs.URLDetector; }
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(exports, "Vault", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function () { return chunkVAXUQISI_cjs.Vault; }
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(exports, "aggregate", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function () { return chunkVAXUQISI_cjs.aggregate; }
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(exports, "allDetectors", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get: function () { return chunkVAXUQISI_cjs.allDetectors; }
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, "categoryStrategy", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () { return chunkVAXUQISI_cjs.categoryStrategy; }
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "createPlaceholderStrategy", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function () { return chunkVAXUQISI_cjs.createPlaceholderStrategy; }
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(exports, "hashStrategy", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
get: function () { return chunkVAXUQISI_cjs.hashStrategy; }
|
|
247
|
+
});
|
|
248
|
+
Object.defineProperty(exports, "maskStrategy", {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () { return chunkVAXUQISI_cjs.maskStrategy; }
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(exports, "resolveStrategy", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () { return chunkVAXUQISI_cjs.resolveStrategy; }
|
|
255
|
+
});
|
|
256
|
+
exports.deDE = deDE;
|
|
257
|
+
exports.enGB = enGB;
|
|
258
|
+
exports.enUS = enUS;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { R as RedactionPipeline } from './pipeline-D_6YC4Us.cjs';
|
|
2
|
+
import { P as PIIMatch, A as AggregatorConfig, a as PIIDetector, R as RedactorFn, b as RedactionStrategy } from './vault-CDr54-Ev.cjs';
|
|
3
|
+
export { C as ConfidenceLevel, D as DetectionContext, c as PIIType, d as PipelineConfig, e as RedactionResult, T as TokenMapping, V as Vault, f as VaultEntry } from './vault-CDr54-Ev.cjs';
|
|
4
|
+
|
|
5
|
+
declare function aggregate(matches: PIIMatch[], config?: Partial<AggregatorConfig>): PIIMatch[];
|
|
6
|
+
|
|
7
|
+
declare const EmailDetector: PIIDetector;
|
|
8
|
+
|
|
9
|
+
declare const PhoneDetector: PIIDetector;
|
|
10
|
+
|
|
11
|
+
declare const SSNDetector: PIIDetector;
|
|
12
|
+
|
|
13
|
+
declare const CreditCardDetector: PIIDetector;
|
|
14
|
+
|
|
15
|
+
declare const IPAddressDetector: PIIDetector;
|
|
16
|
+
|
|
17
|
+
declare const URLDetector: PIIDetector;
|
|
18
|
+
|
|
19
|
+
declare const DateOfBirthDetector: PIIDetector;
|
|
20
|
+
|
|
21
|
+
declare const AddressDetector: PIIDetector;
|
|
22
|
+
|
|
23
|
+
/** All built-in detectors. */
|
|
24
|
+
declare const allDetectors: PIIDetector[];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a placeholder strategy that produces numbered tokens: [EMAIL_1], [PHONE_2], etc.
|
|
28
|
+
* Same original value gets the same number across calls.
|
|
29
|
+
*/
|
|
30
|
+
declare function createPlaceholderStrategy(): RedactorFn;
|
|
31
|
+
|
|
32
|
+
declare const hashStrategy: RedactorFn;
|
|
33
|
+
|
|
34
|
+
declare const maskStrategy: RedactorFn;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Category strategy: replaces with type label only. [EMAIL], [PHONE], etc.
|
|
38
|
+
* No counting — simpler output.
|
|
39
|
+
*/
|
|
40
|
+
declare const categoryStrategy: RedactorFn;
|
|
41
|
+
|
|
42
|
+
declare function resolveStrategy(strategy: RedactionStrategy | undefined): RedactorFn;
|
|
43
|
+
|
|
44
|
+
/** Default detector set for en-US locale. */
|
|
45
|
+
declare const enUS: PIIDetector[];
|
|
46
|
+
|
|
47
|
+
declare const enGB: PIIDetector[];
|
|
48
|
+
|
|
49
|
+
declare const deDE: PIIDetector[];
|
|
50
|
+
|
|
51
|
+
export { AddressDetector, AggregatorConfig, CreditCardDetector, DateOfBirthDetector, EmailDetector, IPAddressDetector, PIIDetector, PIIMatch, PhoneDetector, RedactionStrategy, RedactorFn, SSNDetector, URLDetector, aggregate, allDetectors, categoryStrategy, createPlaceholderStrategy, deDE, enGB, enUS, hashStrategy, maskStrategy, resolveStrategy };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { R as RedactionPipeline } from './pipeline-gWjT4cYU.js';
|
|
2
|
+
import { P as PIIMatch, A as AggregatorConfig, a as PIIDetector, R as RedactorFn, b as RedactionStrategy } from './vault-CDr54-Ev.js';
|
|
3
|
+
export { C as ConfidenceLevel, D as DetectionContext, c as PIIType, d as PipelineConfig, e as RedactionResult, T as TokenMapping, V as Vault, f as VaultEntry } from './vault-CDr54-Ev.js';
|
|
4
|
+
|
|
5
|
+
declare function aggregate(matches: PIIMatch[], config?: Partial<AggregatorConfig>): PIIMatch[];
|
|
6
|
+
|
|
7
|
+
declare const EmailDetector: PIIDetector;
|
|
8
|
+
|
|
9
|
+
declare const PhoneDetector: PIIDetector;
|
|
10
|
+
|
|
11
|
+
declare const SSNDetector: PIIDetector;
|
|
12
|
+
|
|
13
|
+
declare const CreditCardDetector: PIIDetector;
|
|
14
|
+
|
|
15
|
+
declare const IPAddressDetector: PIIDetector;
|
|
16
|
+
|
|
17
|
+
declare const URLDetector: PIIDetector;
|
|
18
|
+
|
|
19
|
+
declare const DateOfBirthDetector: PIIDetector;
|
|
20
|
+
|
|
21
|
+
declare const AddressDetector: PIIDetector;
|
|
22
|
+
|
|
23
|
+
/** All built-in detectors. */
|
|
24
|
+
declare const allDetectors: PIIDetector[];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a placeholder strategy that produces numbered tokens: [EMAIL_1], [PHONE_2], etc.
|
|
28
|
+
* Same original value gets the same number across calls.
|
|
29
|
+
*/
|
|
30
|
+
declare function createPlaceholderStrategy(): RedactorFn;
|
|
31
|
+
|
|
32
|
+
declare const hashStrategy: RedactorFn;
|
|
33
|
+
|
|
34
|
+
declare const maskStrategy: RedactorFn;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Category strategy: replaces with type label only. [EMAIL], [PHONE], etc.
|
|
38
|
+
* No counting — simpler output.
|
|
39
|
+
*/
|
|
40
|
+
declare const categoryStrategy: RedactorFn;
|
|
41
|
+
|
|
42
|
+
declare function resolveStrategy(strategy: RedactionStrategy | undefined): RedactorFn;
|
|
43
|
+
|
|
44
|
+
/** Default detector set for en-US locale. */
|
|
45
|
+
declare const enUS: PIIDetector[];
|
|
46
|
+
|
|
47
|
+
declare const enGB: PIIDetector[];
|
|
48
|
+
|
|
49
|
+
declare const deDE: PIIDetector[];
|
|
50
|
+
|
|
51
|
+
export { AddressDetector, AggregatorConfig, CreditCardDetector, DateOfBirthDetector, EmailDetector, IPAddressDetector, PIIDetector, PIIMatch, PhoneDetector, RedactionStrategy, RedactorFn, SSNDetector, URLDetector, aggregate, allDetectors, categoryStrategy, createPlaceholderStrategy, deDE, enGB, enUS, hashStrategy, maskStrategy, resolveStrategy };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { EmailDetector, CreditCardDetector, IPAddressDetector, URLDetector, DateOfBirthDetector, PhoneDetector, SSNDetector, AddressDetector, countDigits } from './chunk-65T2K4W6.js';
|
|
2
|
+
export { AddressDetector, CreditCardDetector, DateOfBirthDetector, EmailDetector, IPAddressDetector, PhoneDetector, RedactionPipeline, SSNDetector, URLDetector, Vault, aggregate, allDetectors, categoryStrategy, createPlaceholderStrategy, hashStrategy, maskStrategy, resolveStrategy } from './chunk-65T2K4W6.js';
|
|
3
|
+
|
|
4
|
+
// src/locales/en-US.ts
|
|
5
|
+
var enUS = [
|
|
6
|
+
EmailDetector,
|
|
7
|
+
PhoneDetector,
|
|
8
|
+
SSNDetector,
|
|
9
|
+
CreditCardDetector,
|
|
10
|
+
IPAddressDetector,
|
|
11
|
+
URLDetector,
|
|
12
|
+
DateOfBirthDetector,
|
|
13
|
+
AddressDetector
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// src/locales/en-GB.ts
|
|
17
|
+
var UK_PHONE_RE = /(?:\+44[\s.-]?|0)(?:\d[\s.-]?){9,10}/g;
|
|
18
|
+
var UKPhoneDetector = {
|
|
19
|
+
name: "uk-phone",
|
|
20
|
+
type: "PHONE",
|
|
21
|
+
confidence: "high",
|
|
22
|
+
detect(text) {
|
|
23
|
+
const matches = [];
|
|
24
|
+
UK_PHONE_RE.lastIndex = 0;
|
|
25
|
+
let match;
|
|
26
|
+
while ((match = UK_PHONE_RE.exec(text)) !== null) {
|
|
27
|
+
const value = match[0];
|
|
28
|
+
const digits = countDigits(value);
|
|
29
|
+
if (digits < 10 || digits > 12) continue;
|
|
30
|
+
matches.push({
|
|
31
|
+
type: "PHONE",
|
|
32
|
+
value,
|
|
33
|
+
start: match.index,
|
|
34
|
+
end: match.index + value.length,
|
|
35
|
+
confidence: 0.9,
|
|
36
|
+
detector: "uk-phone"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return matches;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var NINO_RE = /\b[A-CEGHJ-PR-TW-Z]{2}\s?\d{2}\s?\d{2}\s?\d{2}\s?[A-D]\b/g;
|
|
43
|
+
var NINODetector = {
|
|
44
|
+
name: "nino",
|
|
45
|
+
type: "SSN",
|
|
46
|
+
// Closest equivalent
|
|
47
|
+
confidence: "high",
|
|
48
|
+
detect(text) {
|
|
49
|
+
const matches = [];
|
|
50
|
+
NINO_RE.lastIndex = 0;
|
|
51
|
+
let match;
|
|
52
|
+
while ((match = NINO_RE.exec(text)) !== null) {
|
|
53
|
+
matches.push({
|
|
54
|
+
type: "SSN",
|
|
55
|
+
value: match[0],
|
|
56
|
+
start: match.index,
|
|
57
|
+
end: match.index + match[0].length,
|
|
58
|
+
confidence: 0.85,
|
|
59
|
+
detector: "nino"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return matches;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var UK_POSTCODE_RE = /\b[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}\b/gi;
|
|
66
|
+
var UKPostcodeDetector = {
|
|
67
|
+
name: "uk-postcode",
|
|
68
|
+
type: "ADDRESS",
|
|
69
|
+
confidence: "medium",
|
|
70
|
+
detect(text) {
|
|
71
|
+
const matches = [];
|
|
72
|
+
UK_POSTCODE_RE.lastIndex = 0;
|
|
73
|
+
let match;
|
|
74
|
+
while ((match = UK_POSTCODE_RE.exec(text)) !== null) {
|
|
75
|
+
matches.push({
|
|
76
|
+
type: "ADDRESS",
|
|
77
|
+
value: match[0],
|
|
78
|
+
start: match.index,
|
|
79
|
+
end: match.index + match[0].length,
|
|
80
|
+
confidence: 0.7,
|
|
81
|
+
detector: "uk-postcode"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return matches;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var enGB = [
|
|
88
|
+
EmailDetector,
|
|
89
|
+
UKPhoneDetector,
|
|
90
|
+
NINODetector,
|
|
91
|
+
CreditCardDetector,
|
|
92
|
+
IPAddressDetector,
|
|
93
|
+
URLDetector,
|
|
94
|
+
DateOfBirthDetector,
|
|
95
|
+
UKPostcodeDetector
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
// src/locales/de-DE.ts
|
|
99
|
+
var DE_PHONE_RE = /(?:\+49[\s.-]?|0)(?:\d[\s.-]?){8,12}/g;
|
|
100
|
+
var DEPhoneDetector = {
|
|
101
|
+
name: "de-phone",
|
|
102
|
+
type: "PHONE",
|
|
103
|
+
confidence: "high",
|
|
104
|
+
detect(text) {
|
|
105
|
+
const matches = [];
|
|
106
|
+
DE_PHONE_RE.lastIndex = 0;
|
|
107
|
+
let match;
|
|
108
|
+
while ((match = DE_PHONE_RE.exec(text)) !== null) {
|
|
109
|
+
const value = match[0];
|
|
110
|
+
const digits = countDigits(value);
|
|
111
|
+
if (digits < 9 || digits > 13) continue;
|
|
112
|
+
matches.push({
|
|
113
|
+
type: "PHONE",
|
|
114
|
+
value,
|
|
115
|
+
start: match.index,
|
|
116
|
+
end: match.index + value.length,
|
|
117
|
+
confidence: 0.85,
|
|
118
|
+
detector: "de-phone"
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return matches;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var STEUER_ID_RE = /\b\d{2}\s?\d{3}\s?\d{3}\s?\d{3}\b/g;
|
|
125
|
+
var SteuerIDDetector = {
|
|
126
|
+
name: "steuer-id",
|
|
127
|
+
type: "SSN",
|
|
128
|
+
confidence: "medium",
|
|
129
|
+
detect(text) {
|
|
130
|
+
const matches = [];
|
|
131
|
+
const hasContext = /\b(?:Steuer|IdNr|Identifikationsnummer|TIN)\b/i.test(text);
|
|
132
|
+
if (!hasContext) return matches;
|
|
133
|
+
STEUER_ID_RE.lastIndex = 0;
|
|
134
|
+
let match;
|
|
135
|
+
while ((match = STEUER_ID_RE.exec(text)) !== null) {
|
|
136
|
+
const digits = match[0].replace(/\s/g, "");
|
|
137
|
+
if (digits.length !== 11) continue;
|
|
138
|
+
matches.push({
|
|
139
|
+
type: "SSN",
|
|
140
|
+
value: match[0],
|
|
141
|
+
start: match.index,
|
|
142
|
+
end: match.index + match[0].length,
|
|
143
|
+
confidence: 0.7,
|
|
144
|
+
detector: "steuer-id"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return matches;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var DE_PLZ_RE = /\b\d{5}\b/g;
|
|
151
|
+
var DEPostalCodeDetector = {
|
|
152
|
+
name: "de-plz",
|
|
153
|
+
type: "ADDRESS",
|
|
154
|
+
confidence: "low",
|
|
155
|
+
detect(text) {
|
|
156
|
+
const matches = [];
|
|
157
|
+
const hasContext = /\b(?:PLZ|Postleitzahl|Adresse|wohn|Straße|Str\.)\b/i.test(text);
|
|
158
|
+
if (!hasContext) return matches;
|
|
159
|
+
DE_PLZ_RE.lastIndex = 0;
|
|
160
|
+
let match;
|
|
161
|
+
while ((match = DE_PLZ_RE.exec(text)) !== null) {
|
|
162
|
+
const num = parseInt(match[0], 10);
|
|
163
|
+
if (num < 1e3 || num > 99999) continue;
|
|
164
|
+
matches.push({
|
|
165
|
+
type: "ADDRESS",
|
|
166
|
+
value: match[0],
|
|
167
|
+
start: match.index,
|
|
168
|
+
end: match.index + match[0].length,
|
|
169
|
+
confidence: 0.5,
|
|
170
|
+
detector: "de-plz"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return matches;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var deDE = [
|
|
177
|
+
EmailDetector,
|
|
178
|
+
DEPhoneDetector,
|
|
179
|
+
SteuerIDDetector,
|
|
180
|
+
CreditCardDetector,
|
|
181
|
+
IPAddressDetector,
|
|
182
|
+
URLDetector,
|
|
183
|
+
DateOfBirthDetector,
|
|
184
|
+
DEPostalCodeDetector
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
export { deDE, enGB, enUS };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVAXUQISI_cjs = require('../chunk-VAXUQISI.cjs');
|
|
4
|
+
|
|
5
|
+
// src/integrations/anthropic.ts
|
|
6
|
+
function wrapAnthropic(client, options = {}) {
|
|
7
|
+
const autoRestore = options.autoRestore ?? true;
|
|
8
|
+
const pipeline = new chunkVAXUQISI_cjs.RedactionPipeline({
|
|
9
|
+
...options,
|
|
10
|
+
vault: autoRestore ? true : options.vault ?? false
|
|
11
|
+
});
|
|
12
|
+
const vault = pipeline.getVault();
|
|
13
|
+
const originalCreate = client.messages.create.bind(client.messages);
|
|
14
|
+
const wrappedCreate = async (params) => {
|
|
15
|
+
const redactedMessages = params.messages.map((msg) => {
|
|
16
|
+
if (typeof msg.content === "string") {
|
|
17
|
+
return { ...msg, content: pipeline.redact(msg.content).text };
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(msg.content)) {
|
|
20
|
+
return {
|
|
21
|
+
...msg,
|
|
22
|
+
content: msg.content.map((block) => {
|
|
23
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
24
|
+
return { ...block, text: pipeline.redact(block.text).text };
|
|
25
|
+
}
|
|
26
|
+
return block;
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return msg;
|
|
31
|
+
});
|
|
32
|
+
const response = await originalCreate({
|
|
33
|
+
...params,
|
|
34
|
+
messages: redactedMessages
|
|
35
|
+
});
|
|
36
|
+
if (autoRestore && vault && response.content) {
|
|
37
|
+
for (const block of response.content) {
|
|
38
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
39
|
+
block.text = vault.restore(block.text);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
};
|
|
45
|
+
const proxy = Object.create(client);
|
|
46
|
+
proxy.messages = Object.create(client.messages);
|
|
47
|
+
proxy.messages.create = wrappedCreate;
|
|
48
|
+
proxy.pipeline = pipeline;
|
|
49
|
+
return proxy;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.wrapAnthropic = wrapAnthropic;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { R as RedactionPipeline } from '../pipeline-D_6YC4Us.cjs';
|
|
2
|
+
import { d as PipelineConfig } from '../vault-CDr54-Ev.cjs';
|
|
3
|
+
|
|
4
|
+
interface ContentBlock {
|
|
5
|
+
type: string;
|
|
6
|
+
text?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface Message {
|
|
10
|
+
content: ContentBlock[];
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface MessageCreateParams {
|
|
14
|
+
messages: {
|
|
15
|
+
role: string;
|
|
16
|
+
content: string | ContentBlock[];
|
|
17
|
+
}[];
|
|
18
|
+
model: string;
|
|
19
|
+
max_tokens: number;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface Messages {
|
|
23
|
+
create(params: MessageCreateParams): Promise<Message>;
|
|
24
|
+
}
|
|
25
|
+
interface AnthropicLike {
|
|
26
|
+
messages: Messages;
|
|
27
|
+
}
|
|
28
|
+
interface WrapAnthropicOptions extends Partial<PipelineConfig> {
|
|
29
|
+
autoRestore?: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare function wrapAnthropic<T extends AnthropicLike>(client: T, options?: WrapAnthropicOptions): T & {
|
|
32
|
+
pipeline: RedactionPipeline;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { type WrapAnthropicOptions, wrapAnthropic };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { R as RedactionPipeline } from '../pipeline-gWjT4cYU.js';
|
|
2
|
+
import { d as PipelineConfig } from '../vault-CDr54-Ev.js';
|
|
3
|
+
|
|
4
|
+
interface ContentBlock {
|
|
5
|
+
type: string;
|
|
6
|
+
text?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface Message {
|
|
10
|
+
content: ContentBlock[];
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface MessageCreateParams {
|
|
14
|
+
messages: {
|
|
15
|
+
role: string;
|
|
16
|
+
content: string | ContentBlock[];
|
|
17
|
+
}[];
|
|
18
|
+
model: string;
|
|
19
|
+
max_tokens: number;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface Messages {
|
|
23
|
+
create(params: MessageCreateParams): Promise<Message>;
|
|
24
|
+
}
|
|
25
|
+
interface AnthropicLike {
|
|
26
|
+
messages: Messages;
|
|
27
|
+
}
|
|
28
|
+
interface WrapAnthropicOptions extends Partial<PipelineConfig> {
|
|
29
|
+
autoRestore?: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare function wrapAnthropic<T extends AnthropicLike>(client: T, options?: WrapAnthropicOptions): T & {
|
|
32
|
+
pipeline: RedactionPipeline;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { type WrapAnthropicOptions, wrapAnthropic };
|