anonyma 1.0.0 → 1.1.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/CHANGELOG.md +273 -144
- package/README.md +427 -143
- package/dist/ai/index.cjs +522 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +322 -0
- package/dist/ai/index.d.ts +322 -0
- package/dist/ai/index.js +505 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/audit/index.cjs +359 -0
- package/dist/audit/index.cjs.map +1 -0
- package/dist/audit/index.d.cts +287 -0
- package/dist/audit/index.d.ts +287 -0
- package/dist/audit/index.js +340 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/chunk-26IHMQHL.cjs +662 -0
- package/dist/chunk-26IHMQHL.cjs.map +1 -0
- package/dist/chunk-2F2GWGTB.js +174 -0
- package/dist/chunk-2F2GWGTB.js.map +1 -0
- package/dist/chunk-2NNMJ55L.cjs +45 -0
- package/dist/chunk-2NNMJ55L.cjs.map +1 -0
- package/dist/chunk-2YG7R4KJ.cjs +114 -0
- package/dist/chunk-2YG7R4KJ.cjs.map +1 -0
- package/dist/chunk-2ZZHLCEJ.js +237 -0
- package/dist/chunk-2ZZHLCEJ.js.map +1 -0
- package/dist/chunk-3CY6ATKS.cjs +308 -0
- package/dist/chunk-3CY6ATKS.cjs.map +1 -0
- package/dist/chunk-3D5ZCJ7R.js +268 -0
- package/dist/chunk-3D5ZCJ7R.js.map +1 -0
- package/dist/chunk-6LDAIJBL.js +103 -0
- package/dist/chunk-6LDAIJBL.js.map +1 -0
- package/dist/chunk-7HK2V5Q4.js +111 -0
- package/dist/chunk-7HK2V5Q4.js.map +1 -0
- package/dist/chunk-AAP472NG.js +177 -0
- package/dist/chunk-AAP472NG.js.map +1 -0
- package/dist/chunk-AP4JIUNW.js +42 -0
- package/dist/chunk-AP4JIUNW.js.map +1 -0
- package/dist/chunk-BBJPQPGP.js +457 -0
- package/dist/chunk-BBJPQPGP.js.map +1 -0
- package/dist/chunk-CRXRJZEV.cjs +82 -0
- package/dist/chunk-CRXRJZEV.cjs.map +1 -0
- package/dist/chunk-E3PICZYI.js +20 -0
- package/dist/chunk-E3PICZYI.js.map +1 -0
- package/dist/chunk-F7O2FA3F.cjs +1255 -0
- package/dist/chunk-F7O2FA3F.cjs.map +1 -0
- package/dist/chunk-FB56NAAH.cjs +243 -0
- package/dist/chunk-FB56NAAH.cjs.map +1 -0
- package/dist/chunk-G4AN7FND.js +1063 -0
- package/dist/chunk-G4AN7FND.js.map +1 -0
- package/dist/chunk-GS3FRH4K.js +294 -0
- package/dist/chunk-GS3FRH4K.js.map +1 -0
- package/dist/chunk-GYMG5OI3.cjs +186 -0
- package/dist/chunk-GYMG5OI3.cjs.map +1 -0
- package/dist/chunk-IHEIYZPL.cjs +301 -0
- package/dist/chunk-IHEIYZPL.cjs.map +1 -0
- package/dist/chunk-IJAMLYOT.cjs +1087 -0
- package/dist/chunk-IJAMLYOT.cjs.map +1 -0
- package/dist/chunk-ISL5B4LU.cjs +181 -0
- package/dist/chunk-ISL5B4LU.cjs.map +1 -0
- package/dist/chunk-JKW36IPT.js +179 -0
- package/dist/chunk-JKW36IPT.js.map +1 -0
- package/dist/chunk-KOCQBDI4.cjs +179 -0
- package/dist/chunk-KOCQBDI4.cjs.map +1 -0
- package/dist/chunk-OGNLB2KA.js +79 -0
- package/dist/chunk-OGNLB2KA.js.map +1 -0
- package/dist/chunk-PKHZ7CVI.js +28 -0
- package/dist/chunk-PKHZ7CVI.js.map +1 -0
- package/dist/chunk-QYD4F6T7.cjs +114 -0
- package/dist/chunk-QYD4F6T7.cjs.map +1 -0
- package/dist/chunk-RCW5IPPR.js +1288 -0
- package/dist/chunk-RCW5IPPR.js.map +1 -0
- package/dist/chunk-RMMKYHUN.cjs +35 -0
- package/dist/chunk-RMMKYHUN.cjs.map +1 -0
- package/dist/chunk-S4BJ2ADB.cjs +22 -0
- package/dist/chunk-S4BJ2ADB.cjs.map +1 -0
- package/dist/chunk-S7NH6CHY.cjs +462 -0
- package/dist/chunk-S7NH6CHY.cjs.map +1 -0
- package/dist/chunk-SIHPDZXA.js +176 -0
- package/dist/chunk-SIHPDZXA.js.map +1 -0
- package/dist/chunk-TW7PM3UJ.cjs +30 -0
- package/dist/chunk-TW7PM3UJ.cjs.map +1 -0
- package/dist/chunk-UA3EOFBS.cjs +1322 -0
- package/dist/chunk-UA3EOFBS.cjs.map +1 -0
- package/dist/chunk-VE4CCW7W.js +32 -0
- package/dist/chunk-VE4CCW7W.js.map +1 -0
- package/dist/chunk-W6RBCHYF.js +651 -0
- package/dist/chunk-W6RBCHYF.js.map +1 -0
- package/dist/chunk-WLJN7GIS.cjs +189 -0
- package/dist/chunk-WLJN7GIS.cjs.map +1 -0
- package/dist/chunk-YMLR375Z.js +1244 -0
- package/dist/chunk-YMLR375Z.js.map +1 -0
- package/dist/compliance/index.cjs +88 -0
- package/dist/compliance/index.cjs.map +1 -0
- package/dist/compliance/index.d.cts +277 -0
- package/dist/compliance/index.d.ts +277 -0
- package/dist/compliance/index.js +47 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/crypto.cjs +12 -136
- package/dist/crypto.cjs.map +1 -1
- package/dist/crypto.d.cts +4 -3
- package/dist/crypto.d.ts +4 -3
- package/dist/crypto.js +3 -137
- package/dist/crypto.js.map +1 -1
- package/dist/detectors/index.cjs +146 -1483
- package/dist/detectors/index.cjs.map +1 -1
- package/dist/detectors/index.d.cts +1 -1
- package/dist/detectors/index.d.ts +1 -1
- package/dist/detectors/index.js +3 -1449
- package/dist/detectors/index.js.map +1 -1
- package/dist/engine/index.cjs +441 -0
- package/dist/engine/index.cjs.map +1 -0
- package/dist/engine/index.d.cts +728 -0
- package/dist/engine/index.d.ts +728 -0
- package/dist/engine/index.js +189 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/hash-2PSYNDMM.cjs +14 -0
- package/dist/hash-2PSYNDMM.cjs.map +1 -0
- package/dist/hash-CELLDNKN.js +5 -0
- package/dist/hash-CELLDNKN.js.map +1 -0
- package/dist/index.cjs +153 -2816
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -11
- package/dist/index.d.ts +93 -11
- package/dist/index.js +13 -2791
- package/dist/index.js.map +1 -1
- package/dist/json-CKDvlRtl.d.ts +147 -0
- package/dist/json-s8ny-RCo.d.cts +147 -0
- package/dist/mcp/index.cjs +751 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +226 -0
- package/dist/mcp/index.d.ts +226 -0
- package/dist/mcp/index.js +744 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/middleware/express.cjs +93 -0
- package/dist/middleware/express.cjs.map +1 -0
- package/dist/middleware/express.d.cts +90 -0
- package/dist/middleware/express.d.ts +90 -0
- package/dist/middleware/express.js +91 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/hono.cjs +58 -0
- package/dist/middleware/hono.cjs.map +1 -0
- package/dist/middleware/hono.d.cts +75 -0
- package/dist/middleware/hono.d.ts +75 -0
- package/dist/middleware/hono.js +56 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/index.cjs +24 -0
- package/dist/middleware/index.cjs.map +1 -0
- package/dist/middleware/index.d.cts +106 -0
- package/dist/middleware/index.d.ts +106 -0
- package/dist/middleware/index.js +15 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/schemas.cjs +5 -5
- package/dist/schemas.cjs.map +1 -1
- package/dist/schemas.d.cts +20 -10
- package/dist/schemas.d.ts +20 -10
- package/dist/schemas.js +5 -5
- package/dist/schemas.js.map +1 -1
- package/dist/session-BdRftyZ5.d.cts +102 -0
- package/dist/session-Cs2zlNQp.d.ts +102 -0
- package/dist/stream.cjs +13 -2262
- package/dist/stream.cjs.map +1 -1
- package/dist/stream.d.cts +1 -1
- package/dist/stream.d.ts +1 -1
- package/dist/stream.js +6 -2255
- package/dist/stream.js.map +1 -1
- package/dist/types--tPm_AjY.d.ts +199 -0
- package/dist/types-0BJH_wqc.d.cts +199 -0
- package/dist/types-CPUhjvl8.d.cts +629 -0
- package/dist/types-Dtht33aq.d.ts +629 -0
- package/dist/{types-D-9HzVuy.d.cts → types-EJTj_BKY.d.cts} +38 -7
- package/dist/{types-D-9HzVuy.d.ts → types-EJTj_BKY.d.ts} +38 -7
- package/dist/types-Zt_bZvwS.d.cts +182 -0
- package/dist/types-Zt_bZvwS.d.ts +182 -0
- package/dist/validators.cjs +39 -181
- package/dist/validators.cjs.map +1 -1
- package/dist/validators.js +1 -174
- package/dist/validators.js.map +1 -1
- package/dist/vault/index.cjs +688 -0
- package/dist/vault/index.cjs.map +1 -0
- package/dist/vault/index.d.cts +385 -0
- package/dist/vault/index.d.ts +385 -0
- package/dist/vault/index.js +669 -0
- package/dist/vault/index.js.map +1 -0
- package/package.json +128 -11
|
@@ -0,0 +1,1087 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3CY6ATKS_cjs = require('./chunk-3CY6ATKS.cjs');
|
|
4
|
+
var chunkKOCQBDI4_cjs = require('./chunk-KOCQBDI4.cjs');
|
|
5
|
+
var chunkS4BJ2ADB_cjs = require('./chunk-S4BJ2ADB.cjs');
|
|
6
|
+
var chunk2YG7R4KJ_cjs = require('./chunk-2YG7R4KJ.cjs');
|
|
7
|
+
var chunkIHEIYZPL_cjs = require('./chunk-IHEIYZPL.cjs');
|
|
8
|
+
var chunkGYMG5OI3_cjs = require('./chunk-GYMG5OI3.cjs');
|
|
9
|
+
var chunkWLJN7GIS_cjs = require('./chunk-WLJN7GIS.cjs');
|
|
10
|
+
|
|
11
|
+
// src/engine/resolve.ts
|
|
12
|
+
var WHITESPACE = /\s/;
|
|
13
|
+
function resolveLegacy(candidates) {
|
|
14
|
+
const sorted = [...candidates].sort((a, b) => a.start - b.start || b.confidence - a.confidence);
|
|
15
|
+
const out = [];
|
|
16
|
+
let cursor = 0;
|
|
17
|
+
for (const candidate of sorted) {
|
|
18
|
+
if (candidate.start < cursor) continue;
|
|
19
|
+
cursor = candidate.end;
|
|
20
|
+
if (candidate.allowed) continue;
|
|
21
|
+
out.push({
|
|
22
|
+
start: candidate.start,
|
|
23
|
+
end: candidate.end,
|
|
24
|
+
confidence: candidate.confidence,
|
|
25
|
+
detector: candidate.detector,
|
|
26
|
+
residual: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function byPriority(a, b) {
|
|
32
|
+
return b.confidence - a.confidence || b.end - b.start - (a.end - a.start) || a.start - b.start || a.detector - b.detector;
|
|
33
|
+
}
|
|
34
|
+
function resolveCluster(text, cluster, base, end, out) {
|
|
35
|
+
const [only] = cluster;
|
|
36
|
+
if (cluster.length === 1 && only !== void 0) {
|
|
37
|
+
if (!only.allowed) out.push({ ...stripAllowed(only), residual: false });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
cluster.sort(byPriority);
|
|
41
|
+
const claimed = new Uint8Array(end - base);
|
|
42
|
+
for (const candidate of cluster) {
|
|
43
|
+
const gaps = [];
|
|
44
|
+
let open = -1;
|
|
45
|
+
for (let at = candidate.start; at < candidate.end; at++) {
|
|
46
|
+
if (claimed[at - base] === 0) {
|
|
47
|
+
if (open < 0) open = at;
|
|
48
|
+
} else if (open >= 0) {
|
|
49
|
+
gaps.push({ start: open, end: at });
|
|
50
|
+
open = -1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (open >= 0) gaps.push({ start: open, end: candidate.end });
|
|
54
|
+
const [first] = gaps;
|
|
55
|
+
const untouched = gaps.length === 1 && first?.start === candidate.start && first.end === candidate.end;
|
|
56
|
+
if (untouched) {
|
|
57
|
+
claimed.fill(1, candidate.start - base, candidate.end - base);
|
|
58
|
+
if (!candidate.allowed) out.push({ ...stripAllowed(candidate), residual: false });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (candidate.allowed) continue;
|
|
62
|
+
for (const gap of gaps) {
|
|
63
|
+
let { start, end: stop } = gap;
|
|
64
|
+
while (start < stop && WHITESPACE.test(text.charAt(start))) start++;
|
|
65
|
+
while (stop > start && WHITESPACE.test(text.charAt(stop - 1))) stop--;
|
|
66
|
+
if (start === stop) continue;
|
|
67
|
+
claimed.fill(1, start - base, stop - base);
|
|
68
|
+
out.push({
|
|
69
|
+
start,
|
|
70
|
+
end: stop,
|
|
71
|
+
confidence: candidate.confidence,
|
|
72
|
+
detector: candidate.detector,
|
|
73
|
+
residual: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function stripAllowed(candidate) {
|
|
79
|
+
return {
|
|
80
|
+
start: candidate.start,
|
|
81
|
+
end: candidate.end,
|
|
82
|
+
confidence: candidate.confidence,
|
|
83
|
+
detector: candidate.detector
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function resolveCover(text, candidates) {
|
|
87
|
+
const sorted = [...candidates].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
88
|
+
const out = [];
|
|
89
|
+
let cluster = [];
|
|
90
|
+
let clusterStart = 0;
|
|
91
|
+
let clusterEnd = -1;
|
|
92
|
+
for (const candidate of sorted) {
|
|
93
|
+
if (cluster.length > 0 && candidate.start >= clusterEnd) {
|
|
94
|
+
resolveCluster(text, cluster, clusterStart, clusterEnd, out);
|
|
95
|
+
cluster = [];
|
|
96
|
+
}
|
|
97
|
+
if (cluster.length === 0) clusterStart = candidate.start;
|
|
98
|
+
cluster.push(candidate);
|
|
99
|
+
clusterEnd = Math.max(clusterEnd, candidate.end);
|
|
100
|
+
}
|
|
101
|
+
if (cluster.length > 0) resolveCluster(text, cluster, clusterStart, clusterEnd, out);
|
|
102
|
+
return out.sort((a, b) => a.start - b.start);
|
|
103
|
+
}
|
|
104
|
+
function resolveSpans(text, candidates, policy) {
|
|
105
|
+
if (candidates.length === 0) return [];
|
|
106
|
+
return policy === "legacy" ? resolveLegacy(candidates) : resolveCover(text, candidates);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/engine/pipeline.ts
|
|
110
|
+
var NO_SPANS = Object.freeze([]);
|
|
111
|
+
var OVERLAP_POLICIES = /* @__PURE__ */ new Set(["cover", "legacy"]);
|
|
112
|
+
var STOP = /* @__PURE__ */ Symbol("stop");
|
|
113
|
+
function isThenable(value) {
|
|
114
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
115
|
+
}
|
|
116
|
+
function compileAllow(rules, caseSensitive) {
|
|
117
|
+
if (rules.length === 0) return void 0;
|
|
118
|
+
const exact = /* @__PURE__ */ new Set();
|
|
119
|
+
const patterns = [];
|
|
120
|
+
const predicates = [];
|
|
121
|
+
for (const rule of rules) {
|
|
122
|
+
if (typeof rule === "string") {
|
|
123
|
+
exact.add(caseSensitive ? rule : rule.toLowerCase());
|
|
124
|
+
} else if (rule instanceof RegExp) {
|
|
125
|
+
patterns.push(new RegExp(rule.source, rule.flags.replace(/[gy]/g, "")));
|
|
126
|
+
} else if (typeof rule === "function") {
|
|
127
|
+
predicates.push(rule);
|
|
128
|
+
} else {
|
|
129
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("allow", "entries must be strings, RegExp instances or functions");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return (value, start, end, owner, confidence) => {
|
|
133
|
+
if (exact.has(caseSensitive ? value : value.toLowerCase())) return true;
|
|
134
|
+
for (const pattern of patterns) if (pattern.test(value)) return true;
|
|
135
|
+
if (predicates.length === 0) return false;
|
|
136
|
+
const span = {
|
|
137
|
+
start,
|
|
138
|
+
end,
|
|
139
|
+
category: owner.category,
|
|
140
|
+
confidence,
|
|
141
|
+
detector: owner.id,
|
|
142
|
+
residual: false
|
|
143
|
+
};
|
|
144
|
+
return predicates.some((predicate) => predicate(value, span));
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function createPipeline(options) {
|
|
148
|
+
const detectors = Object.freeze([...options.detectors]);
|
|
149
|
+
const { minConfidence = 0, overlap = "cover", allowCaseSensitive = false } = options;
|
|
150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
151
|
+
for (const detector of detectors) {
|
|
152
|
+
if (seen.has(detector.id)) {
|
|
153
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("detectors", `contains the id "${detector.id}" more than once`);
|
|
154
|
+
}
|
|
155
|
+
seen.add(detector.id);
|
|
156
|
+
}
|
|
157
|
+
if (typeof minConfidence !== "number" || !(minConfidence >= 0 && minConfidence <= 1)) {
|
|
158
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("minConfidence", "must be a number between 0 and 1");
|
|
159
|
+
}
|
|
160
|
+
if (!OVERLAP_POLICIES.has(overlap)) {
|
|
161
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("overlap", 'must be "cover" or "legacy"');
|
|
162
|
+
}
|
|
163
|
+
if (typeof options.replace.fallback !== "function") {
|
|
164
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("replace.fallback", "must be a function");
|
|
165
|
+
}
|
|
166
|
+
const fallback = options.replace.fallback;
|
|
167
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const [category, replacer] of Object.entries(options.replace.byCategory ?? {})) {
|
|
169
|
+
if (typeof replacer !== "function") {
|
|
170
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(`replace.byCategory.${category}`, "must be a function");
|
|
171
|
+
}
|
|
172
|
+
byCategory.set(category, replacer);
|
|
173
|
+
}
|
|
174
|
+
const allow = compileAllow(options.allow ?? [], allowCaseSensitive);
|
|
175
|
+
function owner(index) {
|
|
176
|
+
const detector = detectors[index];
|
|
177
|
+
if (detector === void 0) {
|
|
178
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("detector", "index out of range");
|
|
179
|
+
}
|
|
180
|
+
return detector;
|
|
181
|
+
}
|
|
182
|
+
function collect(text, first) {
|
|
183
|
+
if (typeof text !== "string") {
|
|
184
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("text", "must be a string");
|
|
185
|
+
}
|
|
186
|
+
const candidates = [];
|
|
187
|
+
const state = { index: 0, found: false };
|
|
188
|
+
const emit = (start, end, confidence) => {
|
|
189
|
+
if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end <= start || end > text.length || !(confidence >= 0 && confidence <= 1)) {
|
|
190
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
191
|
+
"detector",
|
|
192
|
+
`"${owner(state.index).id}" reported an invalid span`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (confidence < minConfidence) return;
|
|
196
|
+
const allowed = allow?.(text.slice(start, end), start, end, owner(state.index), confidence) === true;
|
|
197
|
+
if (!allowed) state.found = true;
|
|
198
|
+
candidates.push({ start, end, confidence, detector: state.index, allowed });
|
|
199
|
+
};
|
|
200
|
+
for (const [index, detector] of detectors.entries()) {
|
|
201
|
+
if (detector.prefilter?.(text) === false) continue;
|
|
202
|
+
state.index = index;
|
|
203
|
+
detector.scan(text, emit);
|
|
204
|
+
if (first && state.found) return STOP;
|
|
205
|
+
}
|
|
206
|
+
return candidates;
|
|
207
|
+
}
|
|
208
|
+
function describe(resolved) {
|
|
209
|
+
const detector = owner(resolved.detector);
|
|
210
|
+
return {
|
|
211
|
+
start: resolved.start,
|
|
212
|
+
end: resolved.end,
|
|
213
|
+
category: detector.category,
|
|
214
|
+
confidence: resolved.confidence,
|
|
215
|
+
detector: detector.id,
|
|
216
|
+
residual: resolved.residual
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function scan(text) {
|
|
220
|
+
const candidates = collect(text, false);
|
|
221
|
+
if (candidates === STOP) return [];
|
|
222
|
+
return resolveSpans(text, candidates, overlap).map(describe);
|
|
223
|
+
}
|
|
224
|
+
function test(text) {
|
|
225
|
+
if (allow === void 0) return collect(text, true) === STOP;
|
|
226
|
+
return scan(text).length > 0;
|
|
227
|
+
}
|
|
228
|
+
function context(span, ordinal) {
|
|
229
|
+
return {
|
|
230
|
+
category: span.category,
|
|
231
|
+
detector: span.detector,
|
|
232
|
+
confidence: span.confidence,
|
|
233
|
+
start: span.start,
|
|
234
|
+
end: span.end,
|
|
235
|
+
ordinal,
|
|
236
|
+
residual: span.residual
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function replace(value, replaceContext) {
|
|
240
|
+
return (byCategory.get(replaceContext.category) ?? fallback)(value, replaceContext);
|
|
241
|
+
}
|
|
242
|
+
function checked(replacement, category) {
|
|
243
|
+
if (typeof replacement !== "string") {
|
|
244
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
245
|
+
"replace",
|
|
246
|
+
`the replacer for category "${category}" must return a string`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return replacement;
|
|
250
|
+
}
|
|
251
|
+
function transform(text) {
|
|
252
|
+
const spans = scan(text);
|
|
253
|
+
if (spans.length === 0) return { text, spans: NO_SPANS };
|
|
254
|
+
const parts = [];
|
|
255
|
+
const applied = [];
|
|
256
|
+
let cursor = 0;
|
|
257
|
+
let outLength = 0;
|
|
258
|
+
for (const [i, span] of spans.entries()) {
|
|
259
|
+
const replacement = replace(text.slice(span.start, span.end), context(span, i));
|
|
260
|
+
if (isThenable(replacement)) {
|
|
261
|
+
void Promise.resolve(replacement).catch(() => void 0);
|
|
262
|
+
throw new chunkWLJN7GIS_cjs.AsyncStrategyError(span.category);
|
|
263
|
+
}
|
|
264
|
+
const value = checked(replacement, span.category);
|
|
265
|
+
parts.push(text.slice(cursor, span.start), value);
|
|
266
|
+
outLength += span.start - cursor;
|
|
267
|
+
applied.push({ ...span, outStart: outLength, outEnd: outLength + value.length });
|
|
268
|
+
outLength += value.length;
|
|
269
|
+
cursor = span.end;
|
|
270
|
+
}
|
|
271
|
+
parts.push(text.slice(cursor));
|
|
272
|
+
return { text: parts.join(""), spans: applied };
|
|
273
|
+
}
|
|
274
|
+
async function transformAsync(text) {
|
|
275
|
+
const spans = scan(text);
|
|
276
|
+
if (spans.length === 0) return { text, spans: NO_SPANS };
|
|
277
|
+
const parts = [];
|
|
278
|
+
const applied = [];
|
|
279
|
+
let cursor = 0;
|
|
280
|
+
let outLength = 0;
|
|
281
|
+
for (const [i, span] of spans.entries()) {
|
|
282
|
+
const value = checked(
|
|
283
|
+
await replace(text.slice(span.start, span.end), context(span, i)),
|
|
284
|
+
span.category
|
|
285
|
+
);
|
|
286
|
+
parts.push(text.slice(cursor, span.start), value);
|
|
287
|
+
outLength += span.start - cursor;
|
|
288
|
+
applied.push({ ...span, outStart: outLength, outEnd: outLength + value.length });
|
|
289
|
+
outLength += value.length;
|
|
290
|
+
cursor = span.end;
|
|
291
|
+
}
|
|
292
|
+
parts.push(text.slice(cursor));
|
|
293
|
+
return { text: parts.join(""), spans: applied };
|
|
294
|
+
}
|
|
295
|
+
return Object.freeze({ detectors, scan, test, replace, transform, transformAsync });
|
|
296
|
+
}
|
|
297
|
+
function spanText(text, span) {
|
|
298
|
+
return text.slice(span.start, span.end);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// src/engine/replacers.ts
|
|
302
|
+
var FAIL_CLOSED_LABEL = "[REDACTED]";
|
|
303
|
+
var MAX_REVEALED_DIGITS = 3;
|
|
304
|
+
function failClosed(value, replacement) {
|
|
305
|
+
return replacement === value && value.length > 0 ? FAIL_CLOSED_LABEL : replacement;
|
|
306
|
+
}
|
|
307
|
+
function constant(replacement) {
|
|
308
|
+
if (typeof replacement !== "string" || replacement.trim().length === 0) {
|
|
309
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("replacement", "must be a non-empty string");
|
|
310
|
+
}
|
|
311
|
+
return () => replacement;
|
|
312
|
+
}
|
|
313
|
+
function redactWith(options = {}) {
|
|
314
|
+
const label = chunkIHEIYZPL_cjs.redact("", options);
|
|
315
|
+
return () => label;
|
|
316
|
+
}
|
|
317
|
+
function maskWith(options = {}) {
|
|
318
|
+
chunkIHEIYZPL_cjs.mask("", options);
|
|
319
|
+
return (value) => failClosed(value, chunkIHEIYZPL_cjs.mask(value, options));
|
|
320
|
+
}
|
|
321
|
+
function pseudonymizeWith(options = {}) {
|
|
322
|
+
chunkIHEIYZPL_cjs.pseudonymize("", options);
|
|
323
|
+
return (value) => failClosed(value, chunkIHEIYZPL_cjs.pseudonymize(value, options));
|
|
324
|
+
}
|
|
325
|
+
function generalizeWith(options = {}) {
|
|
326
|
+
chunkIHEIYZPL_cjs.generalize("0", options);
|
|
327
|
+
const bucketSize = options.bucketSize ?? 10;
|
|
328
|
+
if (bucketSize < 2) {
|
|
329
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
330
|
+
"bucketSize",
|
|
331
|
+
"must be at least 2: a range of one value hides nothing"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const hiddenDigits = Math.floor(Math.log10(bucketSize));
|
|
335
|
+
return (value) => {
|
|
336
|
+
const parsed = Number(value);
|
|
337
|
+
if (value.trim().length === 0 || !Number.isFinite(parsed)) return FAIL_CLOSED_LABEL;
|
|
338
|
+
const digits = String(Math.abs(Math.trunc(parsed))).length;
|
|
339
|
+
if (digits - hiddenDigits > MAX_REVEALED_DIGITS) return FAIL_CLOSED_LABEL;
|
|
340
|
+
return failClosed(value, chunkIHEIYZPL_cjs.generalize(value, options));
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function synthesizeWith(options = {}) {
|
|
344
|
+
return (value, context) => failClosed(value, chunkKOCQBDI4_cjs.synthesize(value, context.category, options));
|
|
345
|
+
}
|
|
346
|
+
function hashWith(options = {}) {
|
|
347
|
+
const { truncate = 16 } = options;
|
|
348
|
+
if (!Number.isInteger(truncate) || truncate < 1 || truncate > 64) {
|
|
349
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("truncate", "must be an integer between 1 and 64 (inclusive)");
|
|
350
|
+
}
|
|
351
|
+
return (value) => chunkS4BJ2ADB_cjs.hash(value, options);
|
|
352
|
+
}
|
|
353
|
+
function encryptWith(options) {
|
|
354
|
+
if (options.keyBytes === void 0 && (options.passphrase ?? "") === "") {
|
|
355
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("encryption", "requires `passphrase` or `keyBytes`");
|
|
356
|
+
}
|
|
357
|
+
if (options.keyBytes !== void 0 && options.keyBytes.length !== 16 && options.keyBytes.length !== 32) {
|
|
358
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("encryption.keyBytes", "must be 16 or 32 bytes long");
|
|
359
|
+
}
|
|
360
|
+
const encoding = options.encoding;
|
|
361
|
+
if (encoding !== void 0 && encoding !== "base64" && encoding !== "hex") {
|
|
362
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("encryption.encoding", 'must be "base64" or "hex"');
|
|
363
|
+
}
|
|
364
|
+
return (value) => chunk2YG7R4KJ_cjs.encrypt(value, options);
|
|
365
|
+
}
|
|
366
|
+
function strategyReplacer(spec, dependencies = {}) {
|
|
367
|
+
const secrets = dependencies.secrets ?? {};
|
|
368
|
+
switch (spec.strategy) {
|
|
369
|
+
case "redact":
|
|
370
|
+
return redactWith(spec);
|
|
371
|
+
case "mask":
|
|
372
|
+
return maskWith(spec);
|
|
373
|
+
case "generalize":
|
|
374
|
+
return generalizeWith(spec);
|
|
375
|
+
case "pseudonymize":
|
|
376
|
+
return pseudonymizeWith(
|
|
377
|
+
spec.seed === void 0 && secrets.pseudonymizeSeed !== void 0 ? { ...spec, seed: secrets.pseudonymizeSeed } : spec
|
|
378
|
+
);
|
|
379
|
+
case "synthesize":
|
|
380
|
+
return synthesizeWith(
|
|
381
|
+
spec.seed === void 0 && secrets.synthesizeSeed !== void 0 ? { ...spec, seed: secrets.synthesizeSeed } : spec
|
|
382
|
+
);
|
|
383
|
+
case "hash":
|
|
384
|
+
return hashWith(
|
|
385
|
+
spec.pepper === void 0 && secrets.hashPepper !== void 0 ? { ...spec, pepper: secrets.hashPepper } : spec
|
|
386
|
+
);
|
|
387
|
+
case "encrypt": {
|
|
388
|
+
if (dependencies.encryption === void 0) {
|
|
389
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("encryption", "is required by the `encrypt` strategy");
|
|
390
|
+
}
|
|
391
|
+
return encryptWith(dependencies.encryption);
|
|
392
|
+
}
|
|
393
|
+
case "tokenize": {
|
|
394
|
+
const provider = dependencies.tokenization;
|
|
395
|
+
if (provider === void 0) {
|
|
396
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("tokenization", "is required by the `tokenize` strategy");
|
|
397
|
+
}
|
|
398
|
+
return (value, context) => provider.tokenize(value, { category: context.category });
|
|
399
|
+
}
|
|
400
|
+
default: {
|
|
401
|
+
const unknown = spec;
|
|
402
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
403
|
+
"strategy",
|
|
404
|
+
`"${String(unknown.strategy)}" is not a known strategy`
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/engine/precise.ts
|
|
411
|
+
var EMAIL_PATTERN = /(?<![\p{L}\p{N}_%+-])[\p{L}\p{N}_%+-](?:[\p{L}\p{N}._%+'-]{0,62}[\p{L}\p{N}_%+-])?@((?:[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?\.)+)(xn--[a-z0-9-]{1,59}|\p{L}{2,24})(?!\p{L})/giu;
|
|
412
|
+
var NOT_A_TLD = /* @__PURE__ */ new Set([
|
|
413
|
+
"png",
|
|
414
|
+
"jpg",
|
|
415
|
+
"jpeg",
|
|
416
|
+
"gif",
|
|
417
|
+
"svg",
|
|
418
|
+
"webp",
|
|
419
|
+
"ico",
|
|
420
|
+
"bmp",
|
|
421
|
+
"css",
|
|
422
|
+
"js",
|
|
423
|
+
"json",
|
|
424
|
+
"map",
|
|
425
|
+
"service",
|
|
426
|
+
"socket",
|
|
427
|
+
"timer",
|
|
428
|
+
"mount",
|
|
429
|
+
"target",
|
|
430
|
+
"slice",
|
|
431
|
+
"scope"
|
|
432
|
+
]);
|
|
433
|
+
var COMMON_TLD = /* @__PURE__ */ new Set([
|
|
434
|
+
"com",
|
|
435
|
+
"org",
|
|
436
|
+
"net",
|
|
437
|
+
"edu",
|
|
438
|
+
"gov",
|
|
439
|
+
"mil",
|
|
440
|
+
"int",
|
|
441
|
+
"info",
|
|
442
|
+
"biz",
|
|
443
|
+
"name",
|
|
444
|
+
"pro",
|
|
445
|
+
"io",
|
|
446
|
+
"co",
|
|
447
|
+
"me",
|
|
448
|
+
"dev",
|
|
449
|
+
"app",
|
|
450
|
+
"ai"
|
|
451
|
+
]);
|
|
452
|
+
var URL_USERINFO_BEFORE = /[a-z][a-z0-9+.-]*:\/\/[a-z0-9._~%!$*+:-]*$/i;
|
|
453
|
+
var MESSAGE_ID_BEFORE = /\b(?:message-id|in-reply-to|references)\s*:\s*(?:<[^\s<>]*>\s*)*<[^\s<>@]*$/i;
|
|
454
|
+
function scanEmail(text, emit) {
|
|
455
|
+
EMAIL_PATTERN.lastIndex = 0;
|
|
456
|
+
let match;
|
|
457
|
+
while ((match = EMAIL_PATTERN.exec(text)) !== null) {
|
|
458
|
+
const start = match.index;
|
|
459
|
+
const end = start + match[0].length;
|
|
460
|
+
const domain = match[1] ?? "";
|
|
461
|
+
const tld = (match[2] ?? "").toLowerCase();
|
|
462
|
+
if (NOT_A_TLD.has(tld)) continue;
|
|
463
|
+
if (/^\d+\.\d+\./.test(domain)) continue;
|
|
464
|
+
if (text.charCodeAt(end) === 40 && match[0].indexOf("@") <= 2 && tld.length > 2 && !COMMON_TLD.has(tld)) {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (match[0].startsWith("git@")) continue;
|
|
468
|
+
const before = text.slice(Math.max(0, start - 96), start);
|
|
469
|
+
if (URL_USERINFO_BEFORE.test(before) || MESSAGE_ID_BEFORE.test(before)) continue;
|
|
470
|
+
emit(start, end, 0.99);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
var emailDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
474
|
+
id: "email",
|
|
475
|
+
category: "email",
|
|
476
|
+
prefilter: (text) => text.includes("@"),
|
|
477
|
+
scan: scanEmail,
|
|
478
|
+
maxMatchLength: 320
|
|
479
|
+
});
|
|
480
|
+
var OBFUSCATED_EMAIL_PATTERN = /(?<![\p{L}\p{N}._%+-])[\p{L}\p{N}_%+-][\p{L}\p{N}._%+-]{0,63}(?:\s*(?:\[at\]|\(at\)|\{at\}|\[@\])\s*|[ \t]+@[ \t]*|@[ \t]+)[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?(?:\s*(?:\[dot\]|\(dot\)|\{dot\}|\[\.\]|\.)\s*[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?)*\s*(?:\[dot\]|\(dot\)|\{dot\}|\[\.\]|\.)\s*\p{L}{2,24}(?![\p{L}\p{N}])/giu;
|
|
481
|
+
var obfuscatedEmailDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
482
|
+
id: "email/obfuscated",
|
|
483
|
+
category: "email",
|
|
484
|
+
prefilter: (text) => /\[at\]|\(at\)|\{at\}|@/i.test(text),
|
|
485
|
+
scan(text, emit) {
|
|
486
|
+
OBFUSCATED_EMAIL_PATTERN.lastIndex = 0;
|
|
487
|
+
let match;
|
|
488
|
+
while ((match = OBFUSCATED_EMAIL_PATTERN.exec(text)) !== null) {
|
|
489
|
+
emit(match.index, match.index + match[0].length, 0.75);
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
maxMatchLength: 320
|
|
493
|
+
});
|
|
494
|
+
var SSN_SEPARATOR = String.raw`(?:\s?[-\u2010-\u2015\u2212.]\s?|\s{1,2})`;
|
|
495
|
+
var SSN_SEPARATED_PATTERN = new RegExp(
|
|
496
|
+
String.raw`(?<!\d)(?<!\d[-\u2010-\u2015\u2212./])(\d{3})${SSN_SEPARATOR}(\d{2})${SSN_SEPARATOR}(\d{4})(?![-\u2010-\u2015\u2212.]?\d)`,
|
|
497
|
+
"g"
|
|
498
|
+
);
|
|
499
|
+
var SSN_LABELLED_PATTERN = /(?:\bssn|\bss#|\bsocial\s+security)(?:\s*(?:number|num\.?|no\.?|#))?[^\d\n.;!?]{0,24}(\d{9})(?!\d)/dgi;
|
|
500
|
+
function isAssignableSsn(area, group, serial) {
|
|
501
|
+
return area !== "000" && area !== "666" && !area.startsWith("9") && group !== "00" && serial !== "0000";
|
|
502
|
+
}
|
|
503
|
+
function scanSsn(text, emit) {
|
|
504
|
+
SSN_SEPARATED_PATTERN.lastIndex = 0;
|
|
505
|
+
let match;
|
|
506
|
+
while ((match = SSN_SEPARATED_PATTERN.exec(text)) !== null) {
|
|
507
|
+
if (isAssignableSsn(match[1] ?? "", match[2] ?? "", match[3] ?? "")) {
|
|
508
|
+
emit(match.index, match.index + match[0].length, 0.95);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
SSN_LABELLED_PATTERN.lastIndex = 0;
|
|
512
|
+
while ((match = SSN_LABELLED_PATTERN.exec(text)) !== null) {
|
|
513
|
+
const digits = match[1] ?? "";
|
|
514
|
+
const bounds = match.indices?.[1];
|
|
515
|
+
if (bounds !== void 0 && isAssignableSsn(digits.slice(0, 3), digits.slice(3, 5), digits.slice(5))) {
|
|
516
|
+
emit(bounds[0], bounds[1], 0.9);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
var ssnDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
521
|
+
id: "ssn",
|
|
522
|
+
category: "ssn",
|
|
523
|
+
prefilter: (text) => /\d{4}/.test(text),
|
|
524
|
+
scan: scanSsn,
|
|
525
|
+
maxMatchLength: 48
|
|
526
|
+
});
|
|
527
|
+
var SSN_BARE_PATTERN = /(?<![\d.,])(\d{3})(\d{2})(\d{4})(?![\d.,]?\d)/g;
|
|
528
|
+
var bareSsnDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
529
|
+
id: "ssn/bare",
|
|
530
|
+
category: "ssn",
|
|
531
|
+
prefilter: (text) => /\d{9}/.test(text),
|
|
532
|
+
scan(text, emit) {
|
|
533
|
+
SSN_BARE_PATTERN.lastIndex = 0;
|
|
534
|
+
let match;
|
|
535
|
+
while ((match = SSN_BARE_PATTERN.exec(text)) !== null) {
|
|
536
|
+
if (isAssignableSsn(match[1] ?? "", match[2] ?? "", match[3] ?? "")) {
|
|
537
|
+
emit(match.index, match.index + 9, 0.5);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
maxMatchLength: 12
|
|
542
|
+
});
|
|
543
|
+
var IBAN_LENGTHS = {
|
|
544
|
+
AD: 24,
|
|
545
|
+
AE: 23,
|
|
546
|
+
AL: 28,
|
|
547
|
+
AT: 20,
|
|
548
|
+
AZ: 28,
|
|
549
|
+
BA: 20,
|
|
550
|
+
BE: 16,
|
|
551
|
+
BG: 22,
|
|
552
|
+
BH: 22,
|
|
553
|
+
BI: 27,
|
|
554
|
+
BR: 29,
|
|
555
|
+
BY: 28,
|
|
556
|
+
CH: 21,
|
|
557
|
+
CR: 22,
|
|
558
|
+
CY: 28,
|
|
559
|
+
CZ: 24,
|
|
560
|
+
DE: 22,
|
|
561
|
+
DJ: 27,
|
|
562
|
+
DK: 18,
|
|
563
|
+
DO: 28,
|
|
564
|
+
EE: 20,
|
|
565
|
+
EG: 29,
|
|
566
|
+
ES: 24,
|
|
567
|
+
FI: 18,
|
|
568
|
+
FK: 18,
|
|
569
|
+
FO: 18,
|
|
570
|
+
FR: 27,
|
|
571
|
+
GB: 22,
|
|
572
|
+
GE: 22,
|
|
573
|
+
GI: 23,
|
|
574
|
+
GL: 18,
|
|
575
|
+
GR: 27,
|
|
576
|
+
GT: 28,
|
|
577
|
+
HN: 28,
|
|
578
|
+
HR: 21,
|
|
579
|
+
HU: 28,
|
|
580
|
+
IE: 22,
|
|
581
|
+
IL: 23,
|
|
582
|
+
IQ: 23,
|
|
583
|
+
IS: 26,
|
|
584
|
+
IT: 27,
|
|
585
|
+
JO: 30,
|
|
586
|
+
KW: 30,
|
|
587
|
+
KZ: 20,
|
|
588
|
+
LB: 28,
|
|
589
|
+
LC: 32,
|
|
590
|
+
LI: 21,
|
|
591
|
+
LT: 20,
|
|
592
|
+
LU: 20,
|
|
593
|
+
LV: 21,
|
|
594
|
+
LY: 25,
|
|
595
|
+
MC: 27,
|
|
596
|
+
MD: 24,
|
|
597
|
+
ME: 22,
|
|
598
|
+
MK: 19,
|
|
599
|
+
MN: 20,
|
|
600
|
+
MR: 27,
|
|
601
|
+
MT: 31,
|
|
602
|
+
MU: 30,
|
|
603
|
+
NI: 28,
|
|
604
|
+
NL: 18,
|
|
605
|
+
NO: 15,
|
|
606
|
+
OM: 23,
|
|
607
|
+
PK: 24,
|
|
608
|
+
PL: 28,
|
|
609
|
+
PS: 29,
|
|
610
|
+
PT: 25,
|
|
611
|
+
QA: 29,
|
|
612
|
+
RO: 24,
|
|
613
|
+
RS: 22,
|
|
614
|
+
RU: 33,
|
|
615
|
+
SA: 24,
|
|
616
|
+
SC: 31,
|
|
617
|
+
SD: 18,
|
|
618
|
+
SE: 24,
|
|
619
|
+
SI: 19,
|
|
620
|
+
SK: 24,
|
|
621
|
+
SM: 27,
|
|
622
|
+
SO: 23,
|
|
623
|
+
ST: 25,
|
|
624
|
+
SV: 28,
|
|
625
|
+
TL: 23,
|
|
626
|
+
TN: 24,
|
|
627
|
+
TR: 26,
|
|
628
|
+
UA: 29,
|
|
629
|
+
VA: 22,
|
|
630
|
+
VG: 24,
|
|
631
|
+
XK: 20,
|
|
632
|
+
YE: 30,
|
|
633
|
+
// Not in the registry.
|
|
634
|
+
AO: 25,
|
|
635
|
+
BF: 28,
|
|
636
|
+
BJ: 28,
|
|
637
|
+
CF: 27,
|
|
638
|
+
CG: 27,
|
|
639
|
+
CI: 28,
|
|
640
|
+
CM: 27,
|
|
641
|
+
CV: 25,
|
|
642
|
+
DZ: 26,
|
|
643
|
+
GA: 27,
|
|
644
|
+
GQ: 27,
|
|
645
|
+
GW: 25,
|
|
646
|
+
IR: 26,
|
|
647
|
+
KM: 27,
|
|
648
|
+
MA: 28,
|
|
649
|
+
MG: 27,
|
|
650
|
+
ML: 28,
|
|
651
|
+
MZ: 25,
|
|
652
|
+
NE: 28,
|
|
653
|
+
SN: 28,
|
|
654
|
+
TD: 27,
|
|
655
|
+
TG: 28
|
|
656
|
+
};
|
|
657
|
+
var IBAN_START_PATTERN = /(?<![A-Za-z0-9])[A-Za-z]{2}\d{2}/g;
|
|
658
|
+
function isAlphanumeric(code) {
|
|
659
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
660
|
+
}
|
|
661
|
+
function isIbanSeparator(code) {
|
|
662
|
+
return code === 32 || code === 160 || code === 45 || code === 9 || code === 10 || code === 13;
|
|
663
|
+
}
|
|
664
|
+
function isValidIban(collected) {
|
|
665
|
+
const normalised = collected.toUpperCase();
|
|
666
|
+
const checkDigits = Number(normalised.slice(2, 4));
|
|
667
|
+
return checkDigits >= 2 && checkDigits <= 98 && chunkGYMG5OI3_cjs.ibanMod97(normalised);
|
|
668
|
+
}
|
|
669
|
+
function endOfIban(text, start, length) {
|
|
670
|
+
let collected = "";
|
|
671
|
+
let at = start;
|
|
672
|
+
let end = start;
|
|
673
|
+
let separators = 2;
|
|
674
|
+
while (collected.length < length && at < text.length) {
|
|
675
|
+
const code = text.charCodeAt(at);
|
|
676
|
+
if (isAlphanumeric(code)) {
|
|
677
|
+
collected += text.charAt(at);
|
|
678
|
+
separators = 0;
|
|
679
|
+
end = at + 1;
|
|
680
|
+
} else if (separators < 2 && isIbanSeparator(code)) {
|
|
681
|
+
separators++;
|
|
682
|
+
} else {
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
at++;
|
|
686
|
+
}
|
|
687
|
+
if (collected.length !== length || isAlphanumeric(text.charCodeAt(end))) return -1;
|
|
688
|
+
return isValidIban(collected) ? end : -1;
|
|
689
|
+
}
|
|
690
|
+
function scanIban(text, emit) {
|
|
691
|
+
IBAN_START_PATTERN.lastIndex = 0;
|
|
692
|
+
let match;
|
|
693
|
+
while ((match = IBAN_START_PATTERN.exec(text)) !== null) {
|
|
694
|
+
const start = match.index;
|
|
695
|
+
const country = match[0].slice(0, 2).toUpperCase();
|
|
696
|
+
if (!Object.hasOwn(IBAN_LENGTHS, country)) continue;
|
|
697
|
+
const end = endOfIban(text, start, IBAN_LENGTHS[country] ?? 0);
|
|
698
|
+
if (end < 0) continue;
|
|
699
|
+
emit(start, end, 0.99);
|
|
700
|
+
IBAN_START_PATTERN.lastIndex = end;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
var ibanDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
704
|
+
id: "iban",
|
|
705
|
+
category: "iban",
|
|
706
|
+
prefilter: (text) => /[A-Za-z]{2}\d{2}/.test(text),
|
|
707
|
+
scan: scanIban,
|
|
708
|
+
maxMatchLength: 72
|
|
709
|
+
});
|
|
710
|
+
var IPV4_PATTERN = /(?<![\d.])((?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.)((?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d))(\/(?:3[0-2]|[12]?\d)(?![\w/.]))?(?!\.?\d)/g;
|
|
711
|
+
var VERSION_BEFORE = /(?:\bv|version|\bver\.?|\bfirmware|\brev\.?)\s*[:=#("']{0,3}\s*$/i;
|
|
712
|
+
var PRODUCT_BEFORE = /(?<![/\w.+-])(?!(?:tcp|udp|sctp|icmp|ip|ipv4|inet|ssh|dns|peer|host|addr|src|dst)\/)[a-z][\w.+-]*\/\s*$/i;
|
|
713
|
+
var NUMBERING_BEFORE = /(?:\bsection|\bsec\.|\bchapter|\bclause|\bappendix|\bannex|\boid|\u00a7)\s*[:=#("']{0,3}\s*$/i;
|
|
714
|
+
var WEAK_VERSION_BEFORE = /(?:\brelease|\bbuild)\s*[:=#("']{0,3}\s*$/i;
|
|
715
|
+
var REFERENCE_BEFORE = /(?:\bTable|\bFigure|\bFig\.|\b[A-Z]{2,6}-\d+)\s*[:=#("']{0,3}\s*$/;
|
|
716
|
+
var VERSION_SUFFIX_AFTER = /^(?:[-.][A-Za-z]|-\d+[A-Za-z])/;
|
|
717
|
+
function isReservedIpv4(octets) {
|
|
718
|
+
const first = Number(octets[0]);
|
|
719
|
+
const second = Number(octets[1]);
|
|
720
|
+
const third = Number(octets[2]);
|
|
721
|
+
return first === 10 || first === 127 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 168 || first === 169 && second === 254 || first === 100 && second >= 64 && second <= 127 || first === 192 && second === 0 && third === 2 || first === 198 && second === 51 && third === 100 || first === 203 && second === 0 && third === 113;
|
|
722
|
+
}
|
|
723
|
+
function scanIpv4(text, emit) {
|
|
724
|
+
IPV4_PATTERN.lastIndex = 0;
|
|
725
|
+
let match;
|
|
726
|
+
while ((match = IPV4_PATTERN.exec(text)) !== null) {
|
|
727
|
+
const start = match.index;
|
|
728
|
+
let value = match[0];
|
|
729
|
+
if (match[1] === "255." || value.startsWith("0.0.0.0")) continue;
|
|
730
|
+
const octets = value.split("/", 1).join("").split(".");
|
|
731
|
+
if (octets.some((octet) => octet.length === 2 && octet.startsWith("0"))) continue;
|
|
732
|
+
if (octets.includes("000") && octets.some((octet) => octet.length !== 3)) continue;
|
|
733
|
+
const before = text.slice(Math.max(0, start - 48), start);
|
|
734
|
+
if (VERSION_BEFORE.test(before) || PRODUCT_BEFORE.test(before)) continue;
|
|
735
|
+
const small = octets.every((octet) => octet.length <= 2);
|
|
736
|
+
if (small && NUMBERING_BEFORE.test(before)) continue;
|
|
737
|
+
if (!isReservedIpv4(octets)) {
|
|
738
|
+
if (WEAK_VERSION_BEFORE.test(before) || small && REFERENCE_BEFORE.test(before)) continue;
|
|
739
|
+
const end = start + value.length;
|
|
740
|
+
if (VERSION_SUFFIX_AFTER.test(text.slice(end, end + 8))) continue;
|
|
741
|
+
}
|
|
742
|
+
if (match[3] !== void 0 && before.endsWith("//")) {
|
|
743
|
+
value = value.slice(0, -match[3].length);
|
|
744
|
+
}
|
|
745
|
+
emit(start, start + value.length, 0.95);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
var ipv4Detector = chunk3CY6ATKS_cjs.defineDetector({
|
|
749
|
+
id: "ipv4",
|
|
750
|
+
category: "ipv4",
|
|
751
|
+
prefilter: (text) => /\d\.\d/.test(text),
|
|
752
|
+
scan: scanIpv4,
|
|
753
|
+
maxMatchLength: 40
|
|
754
|
+
});
|
|
755
|
+
var IPV6_RUN_PATTERN = /[0-9A-Fa-f:.]{2,}/g;
|
|
756
|
+
var HEX_GROUP = /^[0-9A-Fa-f]{1,4}$/;
|
|
757
|
+
var DOTTED_QUAD = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
|
758
|
+
function countGroups(side, allowIpv4Tail) {
|
|
759
|
+
if (side === "") return 0;
|
|
760
|
+
const groups = side.split(":");
|
|
761
|
+
let count = 0;
|
|
762
|
+
for (const [index, group] of groups.entries()) {
|
|
763
|
+
if (HEX_GROUP.test(group)) count += 1;
|
|
764
|
+
else if (allowIpv4Tail && index === groups.length - 1 && DOTTED_QUAD.test(group)) count += 2;
|
|
765
|
+
else return -1;
|
|
766
|
+
}
|
|
767
|
+
return count;
|
|
768
|
+
}
|
|
769
|
+
function isIpv6(candidate) {
|
|
770
|
+
const compression = candidate.indexOf("::");
|
|
771
|
+
if (compression < 0) {
|
|
772
|
+
const groups = candidate.split(":");
|
|
773
|
+
if (groups.length === 8 && groups.every((group) => group.length === 2)) return false;
|
|
774
|
+
return countGroups(candidate, true) === 8;
|
|
775
|
+
}
|
|
776
|
+
if (candidate.includes("::", compression + 1)) return false;
|
|
777
|
+
const head = countGroups(candidate.slice(0, compression), false);
|
|
778
|
+
const tail = countGroups(candidate.slice(compression + 2), true);
|
|
779
|
+
return head >= 0 && tail >= 0 && head + tail <= 7 && head + tail > 0;
|
|
780
|
+
}
|
|
781
|
+
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
782
|
+
function scanIpv6(text, emit) {
|
|
783
|
+
IPV6_RUN_PATTERN.lastIndex = 0;
|
|
784
|
+
let match;
|
|
785
|
+
while ((match = IPV6_RUN_PATTERN.exec(text)) !== null) {
|
|
786
|
+
let start = match.index;
|
|
787
|
+
let value = match[0];
|
|
788
|
+
const glued = start > 0 && WORD_CHARACTER.test(text.charAt(start - 1));
|
|
789
|
+
const colon = value.indexOf(":");
|
|
790
|
+
if (!value.startsWith("::") && (colon === 0 || glued && colon > 0 && colon <= 2)) {
|
|
791
|
+
start += colon + 1;
|
|
792
|
+
value = value.slice(colon + 1);
|
|
793
|
+
} else if (glued) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
while (value.endsWith(".")) value = value.slice(0, -1);
|
|
797
|
+
if (value.endsWith(":") && !value.endsWith("::")) value = value.slice(0, -1);
|
|
798
|
+
if (value.length < 3 || value.length > 45) continue;
|
|
799
|
+
if (value.indexOf(":") === value.lastIndexOf(":")) continue;
|
|
800
|
+
const end = start + value.length;
|
|
801
|
+
if (WORD_CHARACTER.test(text.charAt(end))) continue;
|
|
802
|
+
if (!/\d/.test(value) && value.split(":").filter((group) => group !== "").length < 3) continue;
|
|
803
|
+
if (!isIpv6(value)) continue;
|
|
804
|
+
emit(start, end, 0.95);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
var ipv6Detector = chunk3CY6ATKS_cjs.defineDetector({
|
|
808
|
+
id: "ipv6",
|
|
809
|
+
category: "ipv6",
|
|
810
|
+
prefilter: (text) => text.includes(":"),
|
|
811
|
+
scan: scanIpv6,
|
|
812
|
+
maxMatchLength: 64
|
|
813
|
+
});
|
|
814
|
+
function isDigit(code) {
|
|
815
|
+
return code >= 48 && code <= 57;
|
|
816
|
+
}
|
|
817
|
+
var CARD_GROUPINGS = [
|
|
818
|
+
[4, 4, 4, 4, 3],
|
|
819
|
+
[4, 4, 4, 4],
|
|
820
|
+
[4, 4, 4, 3],
|
|
821
|
+
[4, 4, 4, 2],
|
|
822
|
+
[4, 4, 4, 1],
|
|
823
|
+
[4, 6, 5],
|
|
824
|
+
[4, 6, 4],
|
|
825
|
+
[8, 8],
|
|
826
|
+
[6, 13]
|
|
827
|
+
];
|
|
828
|
+
var SEPARATOR_NONE = 0;
|
|
829
|
+
var SEPARATOR_SPACE = 1;
|
|
830
|
+
var SEPARATOR_HYPHEN = 2;
|
|
831
|
+
var SEPARATOR_DOT = 3;
|
|
832
|
+
var SEPARATOR_NEWLINE = 4;
|
|
833
|
+
function separatorKind(text, from, to) {
|
|
834
|
+
const first = text.charCodeAt(from);
|
|
835
|
+
if (to - from === 1) {
|
|
836
|
+
if (first === 32 || first === 160) return SEPARATOR_SPACE;
|
|
837
|
+
if (first === 45) return SEPARATOR_HYPHEN;
|
|
838
|
+
if (first === 46) return SEPARATOR_DOT;
|
|
839
|
+
if (first === 10) return SEPARATOR_NEWLINE;
|
|
840
|
+
return SEPARATOR_NONE;
|
|
841
|
+
}
|
|
842
|
+
if (to - from !== 2) return SEPARATOR_NONE;
|
|
843
|
+
const second = text.charCodeAt(from + 1);
|
|
844
|
+
if ((first === 32 || first === 160) && (second === 32 || second === 160)) return SEPARATOR_SPACE;
|
|
845
|
+
if (first === 13 && second === 10) return SEPARATOR_NEWLINE;
|
|
846
|
+
return SEPARATOR_NONE;
|
|
847
|
+
}
|
|
848
|
+
function inRange(digits, length, low, high) {
|
|
849
|
+
const prefix = Number(digits.slice(0, length));
|
|
850
|
+
return prefix >= low && prefix <= high;
|
|
851
|
+
}
|
|
852
|
+
function isIssuedRange(digits, grouped) {
|
|
853
|
+
const length = digits.length;
|
|
854
|
+
if (digits.startsWith("4")) return length === 13 || length === 16 || length === 19;
|
|
855
|
+
if (inRange(digits, 2, 51, 55) || inRange(digits, 4, 2221, 2720)) return length === 16;
|
|
856
|
+
if (digits.startsWith("34") || digits.startsWith("37")) return length === 15;
|
|
857
|
+
if (digits.startsWith("1")) return grouped && length === 15;
|
|
858
|
+
if (length === 14) return inRange(digits, 3, 300, 305) || /^3(?:095|6|8|9)/.test(digits);
|
|
859
|
+
if (length < 16) return false;
|
|
860
|
+
return digits.startsWith("6011") || inRange(digits, 3, 644, 649) || digits.startsWith("65") || digits.startsWith("62") || inRange(digits, 4, 3528, 3589) || inRange(digits, 3, 300, 305) || /^3(?:095|6|8|9)/.test(digits) || inRange(digits, 4, 2200, 2205) || digits.startsWith("50") || inRange(digits, 2, 56, 69) || // RuPay, UzCard, Humo, Troy, NAPAS, T-Union.
|
|
861
|
+
inRange(digits, 2, 81, 82) || digits.startsWith("8600") || digits.startsWith("9860") || digits.startsWith("9792") || digits.startsWith("9704") || digits.startsWith("31");
|
|
862
|
+
}
|
|
863
|
+
function scanCard(text, emit) {
|
|
864
|
+
const starts = [];
|
|
865
|
+
const ends = [];
|
|
866
|
+
for (let at = 0; at < text.length; at++) {
|
|
867
|
+
if (!isDigit(text.charCodeAt(at))) continue;
|
|
868
|
+
starts.push(at);
|
|
869
|
+
while (at < text.length && isDigit(text.charCodeAt(at))) at++;
|
|
870
|
+
ends.push(at);
|
|
871
|
+
}
|
|
872
|
+
const candidates = [];
|
|
873
|
+
const reach = /* @__PURE__ */ new Map();
|
|
874
|
+
const add = (run, end, confidence) => {
|
|
875
|
+
candidates.push({ run, start: starts[run] ?? 0, end, confidence });
|
|
876
|
+
reach.set(run, Math.max(reach.get(run) ?? 0, end));
|
|
877
|
+
};
|
|
878
|
+
for (const [run, start] of starts.entries()) {
|
|
879
|
+
const length = (ends[run] ?? start) - start;
|
|
880
|
+
if (length >= 13 && length <= 19) {
|
|
881
|
+
const digits = text.slice(start, start + length);
|
|
882
|
+
if (isIssuedRange(digits, false) && chunkGYMG5OI3_cjs.luhn(digits)) add(run, start + length, 0.92);
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
for (const grouping of CARD_GROUPINGS) {
|
|
886
|
+
if (grouping[0] !== length) continue;
|
|
887
|
+
let digits = "";
|
|
888
|
+
let uniform = true;
|
|
889
|
+
let kind = SEPARATOR_NONE;
|
|
890
|
+
let fits = true;
|
|
891
|
+
for (const [offset, size] of grouping.entries()) {
|
|
892
|
+
const from = starts[run + offset];
|
|
893
|
+
const to = ends[run + offset];
|
|
894
|
+
if (from === void 0 || to === void 0 || to - from !== size) {
|
|
895
|
+
fits = false;
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
if (offset > 0) {
|
|
899
|
+
const between = separatorKind(text, ends[run + offset - 1] ?? from, from);
|
|
900
|
+
if (between === SEPARATOR_NONE) {
|
|
901
|
+
fits = false;
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
904
|
+
if (kind !== SEPARATOR_NONE && between !== kind) uniform = false;
|
|
905
|
+
kind = between;
|
|
906
|
+
}
|
|
907
|
+
digits += text.slice(from, to);
|
|
908
|
+
}
|
|
909
|
+
if (!fits || !chunkGYMG5OI3_cjs.luhn(digits)) continue;
|
|
910
|
+
const end = ends[run + grouping.length - 1] ?? start;
|
|
911
|
+
if (isIssuedRange(digits, true)) {
|
|
912
|
+
add(run, end, uniform ? 0.97 : 0.85);
|
|
913
|
+
} else if (uniform && digits.length === 16 && grouping.length === 4 && !/^(\d)\1+$/.test(digits)) {
|
|
914
|
+
add(run, end, 0.6);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
let covered = -1;
|
|
919
|
+
for (const candidate of candidates) {
|
|
920
|
+
if (candidate.end <= covered) continue;
|
|
921
|
+
if (candidate.start < covered) {
|
|
922
|
+
let next = candidate.run;
|
|
923
|
+
while ((starts[next] ?? Infinity) < covered) next++;
|
|
924
|
+
if ((reach.get(next) ?? 0) >= candidate.end) continue;
|
|
925
|
+
}
|
|
926
|
+
emit(candidate.start, candidate.end, candidate.confidence);
|
|
927
|
+
covered = Math.max(covered, candidate.end);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
var creditCardDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
931
|
+
id: "credit-card",
|
|
932
|
+
category: "credit-card",
|
|
933
|
+
prefilter: (text) => /\d{4}/.test(text),
|
|
934
|
+
scan: scanCard,
|
|
935
|
+
maxMatchLength: 48
|
|
936
|
+
});
|
|
937
|
+
var MASKED_CARD_PATTERN = /(?<![\w*])(?:[*Xx\u2022]{4}[ -]?){2,3}(?:[*Xx\u2022]{2}\d{2}|\d{4})(?!\d)/g;
|
|
938
|
+
var maskedCardDetector = chunk3CY6ATKS_cjs.defineDetector({
|
|
939
|
+
id: "credit-card/masked",
|
|
940
|
+
category: "credit-card",
|
|
941
|
+
prefilter: (text) => /[*Xx\u2022]{4}/.test(text),
|
|
942
|
+
scan(text, emit) {
|
|
943
|
+
MASKED_CARD_PATTERN.lastIndex = 0;
|
|
944
|
+
let match;
|
|
945
|
+
while ((match = MASKED_CARD_PATTERN.exec(text)) !== null) {
|
|
946
|
+
emit(match.index, match.index + match[0].length, 0.8);
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
maxMatchLength: 24
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
// src/engine/compile.ts
|
|
953
|
+
var PRECISE = {
|
|
954
|
+
email: [emailDetector, obfuscatedEmailDetector],
|
|
955
|
+
ssn: [ssnDetector, bareSsnDetector],
|
|
956
|
+
iban: [ibanDetector],
|
|
957
|
+
ipv4: [ipv4Detector],
|
|
958
|
+
ipv6: [ipv6Detector],
|
|
959
|
+
"credit-card": [creditCardDetector, maskedCardDetector]
|
|
960
|
+
};
|
|
961
|
+
var DEFAULT_STRATEGY = { strategy: "redact" };
|
|
962
|
+
function isBuiltinCategory(category) {
|
|
963
|
+
return chunk3CY6ATKS_cjs.BUILTIN_CATEGORIES.includes(category);
|
|
964
|
+
}
|
|
965
|
+
function builtinDetectors(categories = chunk3CY6ATKS_cjs.BUILTIN_CATEGORIES, options = {}) {
|
|
966
|
+
const { detection = "precise", aggressive = false } = options;
|
|
967
|
+
const out = [];
|
|
968
|
+
const seen = /* @__PURE__ */ new Set();
|
|
969
|
+
for (const category of categories) {
|
|
970
|
+
if (!isBuiltinCategory(category)) throw new chunkWLJN7GIS_cjs.UnknownCategoryError(category);
|
|
971
|
+
if (seen.has(category)) continue;
|
|
972
|
+
seen.add(category);
|
|
973
|
+
const precise = detection === "precise" ? PRECISE[category] : void 0;
|
|
974
|
+
if (precise !== void 0) {
|
|
975
|
+
out.push(...aggressive ? precise : [precise[0]]);
|
|
976
|
+
} else {
|
|
977
|
+
out.push((aggressive ? chunk3CY6ATKS_cjs.LEGACY_AGGRESSIVE_DETECTORS : chunk3CY6ATKS_cjs.LEGACY_DETECTORS)[category]);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
return out;
|
|
981
|
+
}
|
|
982
|
+
function compilePipeline(spec = {}, dependencies = {}) {
|
|
983
|
+
const input = spec;
|
|
984
|
+
if (typeof input !== "object" || input === null) {
|
|
985
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("spec", "must be an object");
|
|
986
|
+
}
|
|
987
|
+
const preset = spec.preset === void 0 ? void 0 : chunkIHEIYZPL_cjs.getPreset(spec.preset);
|
|
988
|
+
const detection = spec.detection;
|
|
989
|
+
if (detection !== void 0 && detection !== "precise" && detection !== "legacy") {
|
|
990
|
+
throw new chunkWLJN7GIS_cjs.ValidationError("detection", 'must be "precise" or "legacy"');
|
|
991
|
+
}
|
|
992
|
+
const detectors = builtinDetectors(spec.categories ?? preset?.categories ?? chunk3CY6ATKS_cjs.BUILTIN_CATEGORIES, {
|
|
993
|
+
...spec.detection !== void 0 ? { detection: spec.detection } : {},
|
|
994
|
+
...spec.aggressive !== void 0 ? { aggressive: spec.aggressive } : {}
|
|
995
|
+
});
|
|
996
|
+
for (const [index, pattern] of (spec.patterns ?? []).entries()) {
|
|
997
|
+
if (typeof pattern.category !== "string" || pattern.category.length === 0) {
|
|
998
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
999
|
+
`patterns[${String(index)}].category`,
|
|
1000
|
+
"must be a non-empty string"
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
const { confidence } = pattern;
|
|
1004
|
+
if (confidence !== void 0 && !(typeof confidence === "number" && confidence >= 0 && confidence <= 1)) {
|
|
1005
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(
|
|
1006
|
+
`patterns[${String(index)}].confidence`,
|
|
1007
|
+
"must be a number between 0 and 1"
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
let compiled;
|
|
1011
|
+
try {
|
|
1012
|
+
compiled = new RegExp(pattern.source, pattern.flags ?? "");
|
|
1013
|
+
} catch {
|
|
1014
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(`patterns[${String(index)}]`, "is not a valid regular expression");
|
|
1015
|
+
}
|
|
1016
|
+
detectors.push(
|
|
1017
|
+
chunk3CY6ATKS_cjs.defineRegexDetector({
|
|
1018
|
+
id: `pattern/${String(index)}`,
|
|
1019
|
+
category: pattern.category,
|
|
1020
|
+
pattern: compiled,
|
|
1021
|
+
...pattern.confidence !== void 0 ? { confidence: pattern.confidence } : {}
|
|
1022
|
+
})
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
const strategies = /* @__PURE__ */ new Map();
|
|
1026
|
+
for (const rule of preset?.rules ?? []) {
|
|
1027
|
+
strategies.set(rule.category, rule.strategy);
|
|
1028
|
+
}
|
|
1029
|
+
for (const [category, strategy] of Object.entries(spec.rules ?? {})) {
|
|
1030
|
+
const rule = strategy;
|
|
1031
|
+
if (typeof rule !== "object" || rule === null) {
|
|
1032
|
+
throw new chunkWLJN7GIS_cjs.ValidationError(`rules.${category}`, "must be a strategy object");
|
|
1033
|
+
}
|
|
1034
|
+
strategies.set(category, strategy);
|
|
1035
|
+
}
|
|
1036
|
+
const byCategory = {};
|
|
1037
|
+
for (const [category, strategy] of strategies) {
|
|
1038
|
+
Object.defineProperty(byCategory, category, {
|
|
1039
|
+
value: strategyReplacer(strategy, dependencies),
|
|
1040
|
+
enumerable: true
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
const defaultStrategy = spec.defaultStrategy ?? preset?.defaultStrategy ?? DEFAULT_STRATEGY;
|
|
1044
|
+
const labels = /* @__PURE__ */ new Set();
|
|
1045
|
+
for (const strategy of [defaultStrategy, ...strategies.values()]) {
|
|
1046
|
+
if (strategy.strategy === "tokenize" || strategy.strategy === "hash") continue;
|
|
1047
|
+
if (strategy.strategy === "encrypt") continue;
|
|
1048
|
+
const label = strategy.strategy === "redact" ? strategy.label ?? "[REDACTED]" : FAIL_CLOSED_LABEL;
|
|
1049
|
+
labels.add(label);
|
|
1050
|
+
labels.add(label.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, ""));
|
|
1051
|
+
}
|
|
1052
|
+
labels.delete("");
|
|
1053
|
+
return createPipeline({
|
|
1054
|
+
detectors,
|
|
1055
|
+
replace: { fallback: strategyReplacer(defaultStrategy, dependencies), byCategory },
|
|
1056
|
+
...spec.minConfidence !== void 0 ? { minConfidence: spec.minConfidence } : {},
|
|
1057
|
+
allow: [...spec.allow ?? [], ...labels],
|
|
1058
|
+
...spec.allowCaseSensitive !== void 0 ? { allowCaseSensitive: spec.allowCaseSensitive } : {},
|
|
1059
|
+
...spec.overlap !== void 0 ? { overlap: spec.overlap } : {}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
exports.bareSsnDetector = bareSsnDetector;
|
|
1064
|
+
exports.builtinDetectors = builtinDetectors;
|
|
1065
|
+
exports.compilePipeline = compilePipeline;
|
|
1066
|
+
exports.constant = constant;
|
|
1067
|
+
exports.createPipeline = createPipeline;
|
|
1068
|
+
exports.creditCardDetector = creditCardDetector;
|
|
1069
|
+
exports.emailDetector = emailDetector;
|
|
1070
|
+
exports.encryptWith = encryptWith;
|
|
1071
|
+
exports.generalizeWith = generalizeWith;
|
|
1072
|
+
exports.hashWith = hashWith;
|
|
1073
|
+
exports.ibanDetector = ibanDetector;
|
|
1074
|
+
exports.ipv4Detector = ipv4Detector;
|
|
1075
|
+
exports.ipv6Detector = ipv6Detector;
|
|
1076
|
+
exports.maskWith = maskWith;
|
|
1077
|
+
exports.maskedCardDetector = maskedCardDetector;
|
|
1078
|
+
exports.obfuscatedEmailDetector = obfuscatedEmailDetector;
|
|
1079
|
+
exports.pseudonymizeWith = pseudonymizeWith;
|
|
1080
|
+
exports.redactWith = redactWith;
|
|
1081
|
+
exports.resolveSpans = resolveSpans;
|
|
1082
|
+
exports.spanText = spanText;
|
|
1083
|
+
exports.ssnDetector = ssnDetector;
|
|
1084
|
+
exports.strategyReplacer = strategyReplacer;
|
|
1085
|
+
exports.synthesizeWith = synthesizeWith;
|
|
1086
|
+
//# sourceMappingURL=chunk-IJAMLYOT.cjs.map
|
|
1087
|
+
//# sourceMappingURL=chunk-IJAMLYOT.cjs.map
|