@runflow-ai/sdk 1.0.94 → 1.0.96
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/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +11 -3
- package/dist/core/agent.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/llm/llm-manager.d.ts +21 -1
- package/dist/llm/llm-manager.d.ts.map +1 -1
- package/dist/llm/llm-manager.js +39 -0
- package/dist/llm/llm-manager.js.map +1 -1
- package/dist/privacy/index.d.ts +31 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +45 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/patterns.d.ts +38 -0
- package/dist/privacy/patterns.d.ts.map +1 -0
- package/dist/privacy/patterns.js +388 -0
- package/dist/privacy/patterns.js.map +1 -0
- package/dist/privacy/pii-sanitizer.d.ts +122 -0
- package/dist/privacy/pii-sanitizer.d.ts.map +1 -0
- package/dist/privacy/pii-sanitizer.js +574 -0
- package/dist/privacy/pii-sanitizer.js.map +1 -0
- package/dist/privacy/types.d.ts +158 -0
- package/dist/privacy/types.d.ts.map +1 -0
- package/dist/privacy/types.js +11 -0
- package/dist/privacy/types.js.map +1 -0
- package/dist/types/all-types.d.ts +17 -0
- package/dist/types/all-types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +4 -0
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/dist/workflows/workflow.js +15 -2
- package/dist/workflows/workflow.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* RUNFLOW SDK - PII DETECTION PATTERNS
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Region-specific and universal PII detection patterns.
|
|
7
|
+
* Each pattern includes validation to reduce false positives.
|
|
8
|
+
*/
|
|
9
|
+
import type { PIIPattern, PIILocale } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Field names that indicate PII content regardless of value format.
|
|
12
|
+
* Case-insensitive matching is applied.
|
|
13
|
+
* These are matched EXACTLY (after normalization).
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_SENSITIVE_FIELDS: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Tokens that indicate PII when they appear in a field name.
|
|
18
|
+
* Split into two groups:
|
|
19
|
+
*
|
|
20
|
+
* ALWAYS_SENSITIVE: tokens that indicate PII even as standalone field names.
|
|
21
|
+
* e.g., field named 'cpf', 'email', 'phone' → always redact.
|
|
22
|
+
*
|
|
23
|
+
* COMPOUND_ONLY: tokens that indicate PII only when part of a compound name.
|
|
24
|
+
* e.g., 'name' alone could be a tool name or agent name (not PII),
|
|
25
|
+
* but 'contactName' or 'nome_contato' → PII.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SENSITIVE_TOKENS_ALWAYS: Set<string>;
|
|
28
|
+
export declare const SENSITIVE_TOKENS_COMPOUND: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Get all patterns for specified locales.
|
|
31
|
+
* 'common' patterns are always included.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getPatterns(locales: PIILocale[]): PIIPattern[];
|
|
34
|
+
/**
|
|
35
|
+
* Get all available patterns across all locales
|
|
36
|
+
*/
|
|
37
|
+
export declare function getAllPatterns(): PIIPattern[];
|
|
38
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/privacy/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AA4RrD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAiC5C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAe9C,CAAC;AAEH,eAAO,MAAM,yBAAyB,EAAE,GAAG,CAAC,MAAM,CAIhD,CAAC;AAaH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,CAmB9D;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,UAAU,EAAE,CAE7C"}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* RUNFLOW SDK - PII DETECTION PATTERNS
|
|
5
|
+
* ============================================================================
|
|
6
|
+
*
|
|
7
|
+
* Region-specific and universal PII detection patterns.
|
|
8
|
+
* Each pattern includes validation to reduce false positives.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.SENSITIVE_TOKENS_COMPOUND = exports.SENSITIVE_TOKENS_ALWAYS = exports.DEFAULT_SENSITIVE_FIELDS = void 0;
|
|
12
|
+
exports.getPatterns = getPatterns;
|
|
13
|
+
exports.getAllPatterns = getAllPatterns;
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// VALIDATION HELPERS
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Validate CPF using check digits algorithm
|
|
19
|
+
*/
|
|
20
|
+
function isValidCPF(cpf) {
|
|
21
|
+
const digits = cpf.replace(/\D/g, '');
|
|
22
|
+
if (digits.length !== 11)
|
|
23
|
+
return false;
|
|
24
|
+
if (/^(\d)\1{10}$/.test(digits))
|
|
25
|
+
return false;
|
|
26
|
+
let sum = 0;
|
|
27
|
+
for (let i = 0; i < 9; i++)
|
|
28
|
+
sum += parseInt(digits[i]) * (10 - i);
|
|
29
|
+
let check = 11 - (sum % 11);
|
|
30
|
+
if (check >= 10)
|
|
31
|
+
check = 0;
|
|
32
|
+
if (parseInt(digits[9]) !== check)
|
|
33
|
+
return false;
|
|
34
|
+
sum = 0;
|
|
35
|
+
for (let i = 0; i < 10; i++)
|
|
36
|
+
sum += parseInt(digits[i]) * (11 - i);
|
|
37
|
+
check = 11 - (sum % 11);
|
|
38
|
+
if (check >= 10)
|
|
39
|
+
check = 0;
|
|
40
|
+
return parseInt(digits[10]) === check;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validate CNPJ using check digits algorithm
|
|
44
|
+
*/
|
|
45
|
+
function isValidCNPJ(cnpj) {
|
|
46
|
+
const digits = cnpj.replace(/\D/g, '');
|
|
47
|
+
if (digits.length !== 14)
|
|
48
|
+
return false;
|
|
49
|
+
if (/^(\d)\1{13}$/.test(digits))
|
|
50
|
+
return false;
|
|
51
|
+
const weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
52
|
+
const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
53
|
+
let sum = 0;
|
|
54
|
+
for (let i = 0; i < 12; i++)
|
|
55
|
+
sum += parseInt(digits[i]) * weights1[i];
|
|
56
|
+
let check = sum % 11 < 2 ? 0 : 11 - (sum % 11);
|
|
57
|
+
if (parseInt(digits[12]) !== check)
|
|
58
|
+
return false;
|
|
59
|
+
sum = 0;
|
|
60
|
+
for (let i = 0; i < 13; i++)
|
|
61
|
+
sum += parseInt(digits[i]) * weights2[i];
|
|
62
|
+
check = sum % 11 < 2 ? 0 : 11 - (sum % 11);
|
|
63
|
+
return parseInt(digits[13]) === check;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Luhn algorithm for credit card validation
|
|
67
|
+
*/
|
|
68
|
+
function isValidLuhn(number) {
|
|
69
|
+
const digits = number.replace(/\D/g, '');
|
|
70
|
+
if (digits.length < 13 || digits.length > 19)
|
|
71
|
+
return false;
|
|
72
|
+
let sum = 0;
|
|
73
|
+
let isEven = false;
|
|
74
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
75
|
+
let digit = parseInt(digits[i]);
|
|
76
|
+
if (isEven) {
|
|
77
|
+
digit *= 2;
|
|
78
|
+
if (digit > 9)
|
|
79
|
+
digit -= 9;
|
|
80
|
+
}
|
|
81
|
+
sum += digit;
|
|
82
|
+
isEven = !isEven;
|
|
83
|
+
}
|
|
84
|
+
return sum % 10 === 0;
|
|
85
|
+
}
|
|
86
|
+
// ============================================================================
|
|
87
|
+
// BRAZILIAN PATTERNS
|
|
88
|
+
// ============================================================================
|
|
89
|
+
const BR_PATTERNS = [
|
|
90
|
+
{
|
|
91
|
+
id: 'br_cpf',
|
|
92
|
+
label: 'CPF',
|
|
93
|
+
category: 'document',
|
|
94
|
+
pattern: /\b\d{3}\.?\d{3}\.?\d{3}-?\d{2}\b/g,
|
|
95
|
+
validate: isValidCPF,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'br_cnpj',
|
|
99
|
+
label: 'CNPJ',
|
|
100
|
+
category: 'document',
|
|
101
|
+
pattern: /\b\d{2}\.?\d{3}\.?\d{3}\/?\d{4}-?\d{2}\b/g,
|
|
102
|
+
validate: isValidCNPJ,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'br_rg',
|
|
106
|
+
label: 'RG',
|
|
107
|
+
category: 'document',
|
|
108
|
+
pattern: /\b\d{2}\.?\d{3}\.?\d{3}-?[\dxX]\b/g,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'br_phone',
|
|
112
|
+
label: 'Telefone BR',
|
|
113
|
+
category: 'contact',
|
|
114
|
+
pattern: /(?:\+55\s?)?(?:\(?\d{2}\)?\s?)?\d{4,5}[-.\s]?\d{4}\b/g,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'br_cep',
|
|
118
|
+
label: 'CEP',
|
|
119
|
+
category: 'location',
|
|
120
|
+
pattern: /\b\d{5}-?\d{3}\b/g,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'br_pis_pasep',
|
|
124
|
+
label: 'PIS/PASEP',
|
|
125
|
+
category: 'document',
|
|
126
|
+
pattern: /\b\d{3}\.?\d{5}\.?\d{2}-?\d\b/g,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'br_cns',
|
|
130
|
+
label: 'Cartao Nacional de Saude',
|
|
131
|
+
category: 'health',
|
|
132
|
+
pattern: /\b[12]\d{2}\s?\d{4}\s?\d{4}\s?\d{4}\b/g,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 'br_titulo_eleitor',
|
|
136
|
+
label: 'Titulo de Eleitor',
|
|
137
|
+
category: 'document',
|
|
138
|
+
pattern: /\b\d{4}\s?\d{4}\s?\d{4}\b/g,
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// US PATTERNS
|
|
143
|
+
// ============================================================================
|
|
144
|
+
const US_PATTERNS = [
|
|
145
|
+
{
|
|
146
|
+
id: 'us_ssn',
|
|
147
|
+
label: 'SSN',
|
|
148
|
+
category: 'document',
|
|
149
|
+
pattern: /\b\d{3}-?\d{2}-?\d{4}\b/g,
|
|
150
|
+
validate: (match) => {
|
|
151
|
+
const digits = match.replace(/\D/g, '');
|
|
152
|
+
if (digits.length !== 9)
|
|
153
|
+
return false;
|
|
154
|
+
// SSN cannot start with 000, 666, or 9xx
|
|
155
|
+
const area = parseInt(digits.substring(0, 3));
|
|
156
|
+
return area !== 0 && area !== 666 && area < 900;
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'us_phone',
|
|
161
|
+
label: 'US Phone',
|
|
162
|
+
category: 'contact',
|
|
163
|
+
pattern: /(?:\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: 'us_zip',
|
|
167
|
+
label: 'ZIP Code',
|
|
168
|
+
category: 'location',
|
|
169
|
+
pattern: /\b\d{5}(?:-\d{4})?\b/g,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'us_drivers_license',
|
|
173
|
+
label: 'Drivers License',
|
|
174
|
+
category: 'document',
|
|
175
|
+
pattern: /\b[A-Z]\d{7,8}\b/g,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: 'us_passport',
|
|
179
|
+
label: 'US Passport',
|
|
180
|
+
category: 'document',
|
|
181
|
+
pattern: /\b[A-Z]\d{8}\b/g,
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// EUROPEAN PATTERNS
|
|
186
|
+
// ============================================================================
|
|
187
|
+
const EU_PATTERNS = [
|
|
188
|
+
{
|
|
189
|
+
id: 'eu_iban',
|
|
190
|
+
label: 'IBAN',
|
|
191
|
+
category: 'financial',
|
|
192
|
+
pattern: /\b[A-Z]{2}\d{2}\s?[\dA-Z]{4}\s?[\dA-Z]{4}\s?[\dA-Z]{4}(?:\s?[\dA-Z]{4}){0,6}(?:\s?[\dA-Z]{1,4})?\b/g,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: 'eu_phone',
|
|
196
|
+
label: 'EU Phone',
|
|
197
|
+
category: 'contact',
|
|
198
|
+
pattern: /\+(?:3[0-9]|4[0-9]|[1-2]\d)\s?\d{2,4}[\s.-]?\d{3,4}[\s.-]?\d{3,4}\b/g,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'eu_vat',
|
|
202
|
+
label: 'VAT Number',
|
|
203
|
+
category: 'document',
|
|
204
|
+
pattern: /\b[A-Z]{2}\d{8,12}\b/g,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: 'eu_nif_pt',
|
|
208
|
+
label: 'NIF Portugal',
|
|
209
|
+
category: 'document',
|
|
210
|
+
pattern: /\b[125689]\d{8}\b/g,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 'eu_nie_es',
|
|
214
|
+
label: 'NIE Spain',
|
|
215
|
+
category: 'document',
|
|
216
|
+
pattern: /\b[XYZ]\d{7}[A-Z]\b/g,
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// COMMON/UNIVERSAL PATTERNS
|
|
221
|
+
// ============================================================================
|
|
222
|
+
const COMMON_PATTERNS = [
|
|
223
|
+
{
|
|
224
|
+
id: 'email',
|
|
225
|
+
label: 'Email',
|
|
226
|
+
category: 'contact',
|
|
227
|
+
pattern: /\b[\w.+-]+@[\w-]+(?:\.[\w-]+)+\b/g,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: 'credit_card',
|
|
231
|
+
label: 'Credit Card',
|
|
232
|
+
category: 'financial',
|
|
233
|
+
pattern: /\b(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2}|6(?:011|5\d{2}))[- ]?\d{4}[- ]?\d{4}[- ]?\d{3,4}\b/g,
|
|
234
|
+
validate: isValidLuhn,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
id: 'ipv4',
|
|
238
|
+
label: 'IPv4 Address',
|
|
239
|
+
category: 'network',
|
|
240
|
+
pattern: /\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g,
|
|
241
|
+
validate: (match) => {
|
|
242
|
+
// Exclude common non-PII IPs
|
|
243
|
+
return !['0.0.0.0', '127.0.0.1', '255.255.255.255', '192.168.0.1', '10.0.0.1'].includes(match);
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: 'ipv6',
|
|
248
|
+
label: 'IPv6 Address',
|
|
249
|
+
category: 'network',
|
|
250
|
+
pattern: /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
id: 'mac_address',
|
|
254
|
+
label: 'MAC Address',
|
|
255
|
+
category: 'network',
|
|
256
|
+
pattern: /\b(?:[0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}\b/g,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'bearer_token',
|
|
260
|
+
label: 'Bearer Token',
|
|
261
|
+
category: 'credential',
|
|
262
|
+
pattern: /Bearer\s+[A-Za-z0-9\-._~+/]+=*/g,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'api_key_generic',
|
|
266
|
+
label: 'API Key',
|
|
267
|
+
category: 'credential',
|
|
268
|
+
pattern: /(?:api[_-]?key|apikey|api[_-]?secret|access[_-]?token|auth[_-]?token)["\s:=]+["']?([A-Za-z0-9\-._~+/]{20,})["']?/gi,
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
id: 'jwt_token',
|
|
272
|
+
label: 'JWT Token',
|
|
273
|
+
category: 'credential',
|
|
274
|
+
pattern: /\beyJ[A-Za-z0-9-_]+\.eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\b/g,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
id: 'aws_key',
|
|
278
|
+
label: 'AWS Access Key',
|
|
279
|
+
category: 'credential',
|
|
280
|
+
pattern: /\b(?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}\b/g,
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'date_of_birth',
|
|
284
|
+
label: 'Date of Birth',
|
|
285
|
+
category: 'personal',
|
|
286
|
+
pattern: /\b(?:0[1-9]|[12]\d|3[01])[/.-](?:0[1-9]|1[0-2])[/.-](?:19|20)\d{2}\b/g,
|
|
287
|
+
},
|
|
288
|
+
];
|
|
289
|
+
// ============================================================================
|
|
290
|
+
// DEFAULT SENSITIVE FIELD NAMES
|
|
291
|
+
// ============================================================================
|
|
292
|
+
/**
|
|
293
|
+
* Field names that indicate PII content regardless of value format.
|
|
294
|
+
* Case-insensitive matching is applied.
|
|
295
|
+
* These are matched EXACTLY (after normalization).
|
|
296
|
+
*/
|
|
297
|
+
exports.DEFAULT_SENSITIVE_FIELDS = [
|
|
298
|
+
// Personal identifiers
|
|
299
|
+
'cpf', 'cnpj', 'rg', 'ssn', 'passport', 'passport_number',
|
|
300
|
+
'national_id', 'identity_number', 'document_number',
|
|
301
|
+
'drivers_license', 'cnh', 'titulo_eleitor', 'pis', 'nis',
|
|
302
|
+
// Contact information
|
|
303
|
+
'email', 'e_mail', 'phone', 'phone_number', 'telefone', 'celular',
|
|
304
|
+
'mobile', 'whatsapp', 'fax',
|
|
305
|
+
// Names
|
|
306
|
+
'full_name', 'nome', 'nome_completo', 'first_name', 'last_name',
|
|
307
|
+
'sobrenome', 'nome_mae', 'mothers_name', 'nome_pai',
|
|
308
|
+
// Address
|
|
309
|
+
'address', 'endereco', 'street', 'rua', 'logradouro', 'cep',
|
|
310
|
+
'zip', 'zip_code', 'postal_code',
|
|
311
|
+
// Financial
|
|
312
|
+
'credit_card', 'card_number', 'numero_cartao', 'bank_account',
|
|
313
|
+
'conta_bancaria', 'agencia', 'iban', 'swift',
|
|
314
|
+
// Health
|
|
315
|
+
'cns', 'cartao_sus', 'health_plan', 'plano_saude',
|
|
316
|
+
'medical_record', 'prontuario',
|
|
317
|
+
// Credentials
|
|
318
|
+
'password', 'senha', 'secret', 'token', 'api_key', 'access_key',
|
|
319
|
+
'private_key', 'secret_key',
|
|
320
|
+
// Date of birth
|
|
321
|
+
'birth_date', 'data_nascimento', 'dob', 'date_of_birth',
|
|
322
|
+
'nascimento', 'birthday',
|
|
323
|
+
];
|
|
324
|
+
/**
|
|
325
|
+
* Tokens that indicate PII when they appear in a field name.
|
|
326
|
+
* Split into two groups:
|
|
327
|
+
*
|
|
328
|
+
* ALWAYS_SENSITIVE: tokens that indicate PII even as standalone field names.
|
|
329
|
+
* e.g., field named 'cpf', 'email', 'phone' → always redact.
|
|
330
|
+
*
|
|
331
|
+
* COMPOUND_ONLY: tokens that indicate PII only when part of a compound name.
|
|
332
|
+
* e.g., 'name' alone could be a tool name or agent name (not PII),
|
|
333
|
+
* but 'contactName' or 'nome_contato' → PII.
|
|
334
|
+
*/
|
|
335
|
+
exports.SENSITIVE_TOKENS_ALWAYS = new Set([
|
|
336
|
+
// Document identifiers
|
|
337
|
+
'cpf', 'cnpj', 'rg', 'ssn', 'passport', 'cnh',
|
|
338
|
+
// Contact
|
|
339
|
+
'email', 'phone', 'telefone', 'celular', 'whatsapp', 'mobile', 'fax',
|
|
340
|
+
// Names (unambiguous standalone - always PII)
|
|
341
|
+
'nome', 'sobrenome',
|
|
342
|
+
// Address
|
|
343
|
+
'endereco', 'cep', 'logradouro',
|
|
344
|
+
// Credentials
|
|
345
|
+
'password', 'senha', 'secret',
|
|
346
|
+
]);
|
|
347
|
+
exports.SENSITIVE_TOKENS_COMPOUND = new Set([
|
|
348
|
+
// Only PII in compound names (e.g., 'contactName', 'user_address')
|
|
349
|
+
'name', // 'name' alone = tool/agent name; 'contactName' = PII
|
|
350
|
+
'address', // 'address' alone = ambiguous; 'email_address', 'home_address' = PII
|
|
351
|
+
]);
|
|
352
|
+
// ============================================================================
|
|
353
|
+
// PATTERN REGISTRY
|
|
354
|
+
// ============================================================================
|
|
355
|
+
const LOCALE_PATTERNS = {
|
|
356
|
+
br: BR_PATTERNS,
|
|
357
|
+
us: US_PATTERNS,
|
|
358
|
+
eu: EU_PATTERNS,
|
|
359
|
+
common: COMMON_PATTERNS,
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Get all patterns for specified locales.
|
|
363
|
+
* 'common' patterns are always included.
|
|
364
|
+
*/
|
|
365
|
+
function getPatterns(locales) {
|
|
366
|
+
const patternSet = new Map();
|
|
367
|
+
// Always include common patterns
|
|
368
|
+
for (const pattern of COMMON_PATTERNS) {
|
|
369
|
+
patternSet.set(pattern.id, pattern);
|
|
370
|
+
}
|
|
371
|
+
// Add locale-specific patterns
|
|
372
|
+
for (const locale of locales) {
|
|
373
|
+
const patterns = LOCALE_PATTERNS[locale];
|
|
374
|
+
if (patterns) {
|
|
375
|
+
for (const pattern of patterns) {
|
|
376
|
+
patternSet.set(pattern.id, pattern);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return Array.from(patternSet.values());
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get all available patterns across all locales
|
|
384
|
+
*/
|
|
385
|
+
function getAllPatterns() {
|
|
386
|
+
return getPatterns(['br', 'us', 'eu', 'common']);
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/privacy/patterns.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAuXH,kCAmBC;AAKD,wCAEC;AA7YD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACtC,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAE9C,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAClE,IAAI,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IAC5B,IAAI,KAAK,IAAI,EAAE;QAAE,KAAK,GAAG,CAAC,CAAC;IAC3B,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,C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B,WAAW,CAAC,OAAoB;IAC9C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEjD,iCAAiC;IACjC,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,+BAA+B;IAC/B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* RUNFLOW SDK - PII SANITIZER
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* High-performance, configurable PII sanitization engine.
|
|
7
|
+
* Integrates with the observability pipeline via onTrace callback.
|
|
8
|
+
*
|
|
9
|
+
* Safety guarantees:
|
|
10
|
+
* - Never crashes on unexpected input (circular refs, Dates, Buffers, etc.)
|
|
11
|
+
* - Never loses non-PII data (preserves structure and special types)
|
|
12
|
+
* - Never leaks PII on internal error (fails closed)
|
|
13
|
+
* - Handles any input type: string, JSON, nested objects, arrays, mixed
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* const agent = new Agent({
|
|
17
|
+
* privacy: { locales: ['br'], strategy: 'redact' },
|
|
18
|
+
* ...
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* Or standalone:
|
|
22
|
+
* const sanitizer = new PIISanitizer({ locales: ['br'] });
|
|
23
|
+
* const clean = sanitizer.sanitize("Meu CPF 123.456.789-09");
|
|
24
|
+
*/
|
|
25
|
+
import type { TraceData } from '../types';
|
|
26
|
+
import type { PrivacyConfig } from './types';
|
|
27
|
+
export declare class PIISanitizer {
|
|
28
|
+
private patterns;
|
|
29
|
+
private sensitiveFields;
|
|
30
|
+
private allowFields;
|
|
31
|
+
private activeCategories;
|
|
32
|
+
private config;
|
|
33
|
+
private redactionCount;
|
|
34
|
+
constructor(config?: PrivacyConfig);
|
|
35
|
+
/**
|
|
36
|
+
* Sanitize a string value by applying all active PII patterns.
|
|
37
|
+
*/
|
|
38
|
+
sanitize(value: string, path?: string, field?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Deep-sanitize any value (string, object, array).
|
|
41
|
+
* Traverses nested structures and applies both pattern and field-name detection.
|
|
42
|
+
*
|
|
43
|
+
* Safety:
|
|
44
|
+
* - Handles circular references (via seen set)
|
|
45
|
+
* - Preserves Date, Buffer, RegExp, Map, Set, Error (converts to safe representation)
|
|
46
|
+
* - Caps recursion depth to prevent stack overflow
|
|
47
|
+
* - Never throws - returns data as-is on unexpected types
|
|
48
|
+
*/
|
|
49
|
+
sanitizeDeep(data: any, path?: string, field?: string): any;
|
|
50
|
+
private _sanitizeDeep;
|
|
51
|
+
/**
|
|
52
|
+
* Redact all string values in a structure (used for sensitive field objects).
|
|
53
|
+
* When a sensitive field name contains an object, ALL nested strings get redacted.
|
|
54
|
+
*/
|
|
55
|
+
private _redactDeep;
|
|
56
|
+
/**
|
|
57
|
+
* Create an onTrace callback for use with ObservabilityConfig.
|
|
58
|
+
* This is the primary integration point with the RunFlow trace system.
|
|
59
|
+
*
|
|
60
|
+
* Safety: wraps everything in try/catch. On any error, returns null
|
|
61
|
+
* (cancels the trace) to prevent PII leakage. Privacy fails closed.
|
|
62
|
+
*/
|
|
63
|
+
createTraceInterceptor(): (trace: TraceData) => TraceData | null | void;
|
|
64
|
+
/**
|
|
65
|
+
* Get the total number of redactions performed.
|
|
66
|
+
*/
|
|
67
|
+
getRedactionCount(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Reset the redaction counter.
|
|
70
|
+
*/
|
|
71
|
+
resetStats(): void;
|
|
72
|
+
private applyReplacement;
|
|
73
|
+
private applyFieldRedaction;
|
|
74
|
+
/**
|
|
75
|
+
* Mask a value based on its pattern type.
|
|
76
|
+
* Shows partial data for usability while hiding the full value.
|
|
77
|
+
*/
|
|
78
|
+
private maskValue;
|
|
79
|
+
/**
|
|
80
|
+
* Generic masking: show first and last char, mask the rest.
|
|
81
|
+
*/
|
|
82
|
+
private maskGeneric;
|
|
83
|
+
/**
|
|
84
|
+
* Hash a value using SHA-256 (truncated).
|
|
85
|
+
* Same input always produces same output, enabling correlation without exposing data.
|
|
86
|
+
*/
|
|
87
|
+
private hashValue;
|
|
88
|
+
private isSensitiveField;
|
|
89
|
+
private recordRedaction;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a PII sanitizer instance with the given configuration.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* const sanitizer = createPIISanitizer({
|
|
96
|
+
* locales: ['br'],
|
|
97
|
+
* strategy: 'mask',
|
|
98
|
+
* audit: true,
|
|
99
|
+
* onRedaction: (event) => console.log('PII found:', event.patternId),
|
|
100
|
+
* });
|
|
101
|
+
*/
|
|
102
|
+
export declare function createPIISanitizer(config?: PrivacyConfig): PIISanitizer;
|
|
103
|
+
/**
|
|
104
|
+
* Normalize shorthand privacy config into full PrivacyConfig.
|
|
105
|
+
*
|
|
106
|
+
* true → { enabled: true } (all locales)
|
|
107
|
+
* 'br' → { locales: ['br'] }
|
|
108
|
+
* ['br', 'us'] → { locales: ['br', 'us'] }
|
|
109
|
+
* { ... } → passthrough
|
|
110
|
+
*/
|
|
111
|
+
export declare function normalizePrivacyConfig(config: boolean | string | string[] | PrivacyConfig): PrivacyConfig | null;
|
|
112
|
+
/**
|
|
113
|
+
* Build the onTrace callback from a PrivacyConfig.
|
|
114
|
+
* Used internally by Agent to wire privacy into the observability pipeline.
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildPrivacyInterceptor(config: PrivacyConfig): (trace: TraceData) => TraceData | null | void;
|
|
117
|
+
/**
|
|
118
|
+
* Compose multiple onTrace callbacks into a single callback.
|
|
119
|
+
* Handles the full onTrace contract: TraceData → continue, null → cancel, void → use original.
|
|
120
|
+
*/
|
|
121
|
+
export declare function composeTraceInterceptors(...interceptors: Array<((trace: TraceData) => TraceData | null | void) | undefined>): (trace: TraceData) => TraceData | null | void;
|
|
122
|
+
//# sourceMappingURL=pii-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-sanitizer.d.ts","sourceRoot":"","sources":["../../src/privacy/pii-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EACV,aAAa,EAMd,MAAM,SAAS,CAAC;AAuBjB,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,MAAM,CASZ;IACF,OAAO,CAAC,cAAc,CAAK;gBAEf,MAAM,GAAE,aAAkB;IA8DtC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,EAAE,KAAK,SAAK,GAAG,MAAM;IAsBtD;;;;;;;;;OASG;IACH,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,SAAK,EAAE,KAAK,SAAK,G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