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.
Files changed (183) hide show
  1. package/CHANGELOG.md +273 -144
  2. package/README.md +427 -143
  3. package/dist/ai/index.cjs +522 -0
  4. package/dist/ai/index.cjs.map +1 -0
  5. package/dist/ai/index.d.cts +322 -0
  6. package/dist/ai/index.d.ts +322 -0
  7. package/dist/ai/index.js +505 -0
  8. package/dist/ai/index.js.map +1 -0
  9. package/dist/audit/index.cjs +359 -0
  10. package/dist/audit/index.cjs.map +1 -0
  11. package/dist/audit/index.d.cts +287 -0
  12. package/dist/audit/index.d.ts +287 -0
  13. package/dist/audit/index.js +340 -0
  14. package/dist/audit/index.js.map +1 -0
  15. package/dist/chunk-26IHMQHL.cjs +662 -0
  16. package/dist/chunk-26IHMQHL.cjs.map +1 -0
  17. package/dist/chunk-2F2GWGTB.js +174 -0
  18. package/dist/chunk-2F2GWGTB.js.map +1 -0
  19. package/dist/chunk-2NNMJ55L.cjs +45 -0
  20. package/dist/chunk-2NNMJ55L.cjs.map +1 -0
  21. package/dist/chunk-2YG7R4KJ.cjs +114 -0
  22. package/dist/chunk-2YG7R4KJ.cjs.map +1 -0
  23. package/dist/chunk-2ZZHLCEJ.js +237 -0
  24. package/dist/chunk-2ZZHLCEJ.js.map +1 -0
  25. package/dist/chunk-3CY6ATKS.cjs +308 -0
  26. package/dist/chunk-3CY6ATKS.cjs.map +1 -0
  27. package/dist/chunk-3D5ZCJ7R.js +268 -0
  28. package/dist/chunk-3D5ZCJ7R.js.map +1 -0
  29. package/dist/chunk-6LDAIJBL.js +103 -0
  30. package/dist/chunk-6LDAIJBL.js.map +1 -0
  31. package/dist/chunk-7HK2V5Q4.js +111 -0
  32. package/dist/chunk-7HK2V5Q4.js.map +1 -0
  33. package/dist/chunk-AAP472NG.js +177 -0
  34. package/dist/chunk-AAP472NG.js.map +1 -0
  35. package/dist/chunk-AP4JIUNW.js +42 -0
  36. package/dist/chunk-AP4JIUNW.js.map +1 -0
  37. package/dist/chunk-BBJPQPGP.js +457 -0
  38. package/dist/chunk-BBJPQPGP.js.map +1 -0
  39. package/dist/chunk-CRXRJZEV.cjs +82 -0
  40. package/dist/chunk-CRXRJZEV.cjs.map +1 -0
  41. package/dist/chunk-E3PICZYI.js +20 -0
  42. package/dist/chunk-E3PICZYI.js.map +1 -0
  43. package/dist/chunk-F7O2FA3F.cjs +1255 -0
  44. package/dist/chunk-F7O2FA3F.cjs.map +1 -0
  45. package/dist/chunk-FB56NAAH.cjs +243 -0
  46. package/dist/chunk-FB56NAAH.cjs.map +1 -0
  47. package/dist/chunk-G4AN7FND.js +1063 -0
  48. package/dist/chunk-G4AN7FND.js.map +1 -0
  49. package/dist/chunk-GS3FRH4K.js +294 -0
  50. package/dist/chunk-GS3FRH4K.js.map +1 -0
  51. package/dist/chunk-GYMG5OI3.cjs +186 -0
  52. package/dist/chunk-GYMG5OI3.cjs.map +1 -0
  53. package/dist/chunk-IHEIYZPL.cjs +301 -0
  54. package/dist/chunk-IHEIYZPL.cjs.map +1 -0
  55. package/dist/chunk-IJAMLYOT.cjs +1087 -0
  56. package/dist/chunk-IJAMLYOT.cjs.map +1 -0
  57. package/dist/chunk-ISL5B4LU.cjs +181 -0
  58. package/dist/chunk-ISL5B4LU.cjs.map +1 -0
  59. package/dist/chunk-JKW36IPT.js +179 -0
  60. package/dist/chunk-JKW36IPT.js.map +1 -0
  61. package/dist/chunk-KOCQBDI4.cjs +179 -0
  62. package/dist/chunk-KOCQBDI4.cjs.map +1 -0
  63. package/dist/chunk-OGNLB2KA.js +79 -0
  64. package/dist/chunk-OGNLB2KA.js.map +1 -0
  65. package/dist/chunk-PKHZ7CVI.js +28 -0
  66. package/dist/chunk-PKHZ7CVI.js.map +1 -0
  67. package/dist/chunk-QYD4F6T7.cjs +114 -0
  68. package/dist/chunk-QYD4F6T7.cjs.map +1 -0
  69. package/dist/chunk-RCW5IPPR.js +1288 -0
  70. package/dist/chunk-RCW5IPPR.js.map +1 -0
  71. package/dist/chunk-RMMKYHUN.cjs +35 -0
  72. package/dist/chunk-RMMKYHUN.cjs.map +1 -0
  73. package/dist/chunk-S4BJ2ADB.cjs +22 -0
  74. package/dist/chunk-S4BJ2ADB.cjs.map +1 -0
  75. package/dist/chunk-S7NH6CHY.cjs +462 -0
  76. package/dist/chunk-S7NH6CHY.cjs.map +1 -0
  77. package/dist/chunk-SIHPDZXA.js +176 -0
  78. package/dist/chunk-SIHPDZXA.js.map +1 -0
  79. package/dist/chunk-TW7PM3UJ.cjs +30 -0
  80. package/dist/chunk-TW7PM3UJ.cjs.map +1 -0
  81. package/dist/chunk-UA3EOFBS.cjs +1322 -0
  82. package/dist/chunk-UA3EOFBS.cjs.map +1 -0
  83. package/dist/chunk-VE4CCW7W.js +32 -0
  84. package/dist/chunk-VE4CCW7W.js.map +1 -0
  85. package/dist/chunk-W6RBCHYF.js +651 -0
  86. package/dist/chunk-W6RBCHYF.js.map +1 -0
  87. package/dist/chunk-WLJN7GIS.cjs +189 -0
  88. package/dist/chunk-WLJN7GIS.cjs.map +1 -0
  89. package/dist/chunk-YMLR375Z.js +1244 -0
  90. package/dist/chunk-YMLR375Z.js.map +1 -0
  91. package/dist/compliance/index.cjs +88 -0
  92. package/dist/compliance/index.cjs.map +1 -0
  93. package/dist/compliance/index.d.cts +277 -0
  94. package/dist/compliance/index.d.ts +277 -0
  95. package/dist/compliance/index.js +47 -0
  96. package/dist/compliance/index.js.map +1 -0
  97. package/dist/crypto.cjs +12 -136
  98. package/dist/crypto.cjs.map +1 -1
  99. package/dist/crypto.d.cts +4 -3
  100. package/dist/crypto.d.ts +4 -3
  101. package/dist/crypto.js +3 -137
  102. package/dist/crypto.js.map +1 -1
  103. package/dist/detectors/index.cjs +146 -1483
  104. package/dist/detectors/index.cjs.map +1 -1
  105. package/dist/detectors/index.d.cts +1 -1
  106. package/dist/detectors/index.d.ts +1 -1
  107. package/dist/detectors/index.js +3 -1449
  108. package/dist/detectors/index.js.map +1 -1
  109. package/dist/engine/index.cjs +441 -0
  110. package/dist/engine/index.cjs.map +1 -0
  111. package/dist/engine/index.d.cts +728 -0
  112. package/dist/engine/index.d.ts +728 -0
  113. package/dist/engine/index.js +189 -0
  114. package/dist/engine/index.js.map +1 -0
  115. package/dist/hash-2PSYNDMM.cjs +14 -0
  116. package/dist/hash-2PSYNDMM.cjs.map +1 -0
  117. package/dist/hash-CELLDNKN.js +5 -0
  118. package/dist/hash-CELLDNKN.js.map +1 -0
  119. package/dist/index.cjs +153 -2816
  120. package/dist/index.cjs.map +1 -1
  121. package/dist/index.d.cts +93 -11
  122. package/dist/index.d.ts +93 -11
  123. package/dist/index.js +13 -2791
  124. package/dist/index.js.map +1 -1
  125. package/dist/json-CKDvlRtl.d.ts +147 -0
  126. package/dist/json-s8ny-RCo.d.cts +147 -0
  127. package/dist/mcp/index.cjs +751 -0
  128. package/dist/mcp/index.cjs.map +1 -0
  129. package/dist/mcp/index.d.cts +226 -0
  130. package/dist/mcp/index.d.ts +226 -0
  131. package/dist/mcp/index.js +744 -0
  132. package/dist/mcp/index.js.map +1 -0
  133. package/dist/middleware/express.cjs +93 -0
  134. package/dist/middleware/express.cjs.map +1 -0
  135. package/dist/middleware/express.d.cts +90 -0
  136. package/dist/middleware/express.d.ts +90 -0
  137. package/dist/middleware/express.js +91 -0
  138. package/dist/middleware/express.js.map +1 -0
  139. package/dist/middleware/hono.cjs +58 -0
  140. package/dist/middleware/hono.cjs.map +1 -0
  141. package/dist/middleware/hono.d.cts +75 -0
  142. package/dist/middleware/hono.d.ts +75 -0
  143. package/dist/middleware/hono.js +56 -0
  144. package/dist/middleware/hono.js.map +1 -0
  145. package/dist/middleware/index.cjs +24 -0
  146. package/dist/middleware/index.cjs.map +1 -0
  147. package/dist/middleware/index.d.cts +106 -0
  148. package/dist/middleware/index.d.ts +106 -0
  149. package/dist/middleware/index.js +15 -0
  150. package/dist/middleware/index.js.map +1 -0
  151. package/dist/schemas.cjs +5 -5
  152. package/dist/schemas.cjs.map +1 -1
  153. package/dist/schemas.d.cts +20 -10
  154. package/dist/schemas.d.ts +20 -10
  155. package/dist/schemas.js +5 -5
  156. package/dist/schemas.js.map +1 -1
  157. package/dist/session-BdRftyZ5.d.cts +102 -0
  158. package/dist/session-Cs2zlNQp.d.ts +102 -0
  159. package/dist/stream.cjs +13 -2262
  160. package/dist/stream.cjs.map +1 -1
  161. package/dist/stream.d.cts +1 -1
  162. package/dist/stream.d.ts +1 -1
  163. package/dist/stream.js +6 -2255
  164. package/dist/stream.js.map +1 -1
  165. package/dist/types--tPm_AjY.d.ts +199 -0
  166. package/dist/types-0BJH_wqc.d.cts +199 -0
  167. package/dist/types-CPUhjvl8.d.cts +629 -0
  168. package/dist/types-Dtht33aq.d.ts +629 -0
  169. package/dist/{types-D-9HzVuy.d.cts → types-EJTj_BKY.d.cts} +38 -7
  170. package/dist/{types-D-9HzVuy.d.ts → types-EJTj_BKY.d.ts} +38 -7
  171. package/dist/types-Zt_bZvwS.d.cts +182 -0
  172. package/dist/types-Zt_bZvwS.d.ts +182 -0
  173. package/dist/validators.cjs +39 -181
  174. package/dist/validators.cjs.map +1 -1
  175. package/dist/validators.js +1 -174
  176. package/dist/validators.js.map +1 -1
  177. package/dist/vault/index.cjs +688 -0
  178. package/dist/vault/index.cjs.map +1 -0
  179. package/dist/vault/index.d.cts +385 -0
  180. package/dist/vault/index.d.ts +385 -0
  181. package/dist/vault/index.js +669 -0
  182. package/dist/vault/index.js.map +1 -0
  183. package/package.json +128 -11
@@ -0,0 +1,1244 @@
1
+ import { BUILTIN_CATEGORIES } from './chunk-3D5ZCJ7R.js';
2
+ import { ValidationError, PolicyError } from './chunk-2F2GWGTB.js';
3
+
4
+ // src/compliance/regulations.ts
5
+ function ref(citation, summary, url) {
6
+ return Object.freeze({ citation, summary, url });
7
+ }
8
+ function rules(categories, references, requirement, recommended, rationale) {
9
+ return categories.map(
10
+ (category) => Object.freeze({
11
+ category,
12
+ references,
13
+ requirement: Object.freeze(requirement),
14
+ recommended,
15
+ rationale
16
+ })
17
+ );
18
+ }
19
+ var REDACT = Object.freeze({ strategy: "redact" });
20
+ var GDPR_URL = "https://eur-lex.europa.eu/eli/reg/2016/679/oj";
21
+ var GDPR_PERSONAL_DATA = ref(
22
+ "GDPR Art. 4(1)",
23
+ "Personal data is any information relating to an identified or identifiable natural person, including a name, an identification number, location data and an online identifier.",
24
+ GDPR_URL
25
+ );
26
+ var GDPR_PSEUDONYMISATION = ref(
27
+ "GDPR Art. 4(5)",
28
+ "Pseudonymisation: the data can no longer be attributed to a data subject without additional information that is kept separately and protected.",
29
+ GDPR_URL
30
+ );
31
+ var GDPR_NATIONAL_ID = ref(
32
+ "GDPR Art. 87",
33
+ "Member States may set specific conditions for processing a national identification number.",
34
+ GDPR_URL
35
+ );
36
+ var GDPR_SPECIAL = ref(
37
+ "GDPR Art. 9(1)",
38
+ "Processing of special categories of personal data, including data concerning health, is prohibited unless an exception applies.",
39
+ GDPR_URL
40
+ );
41
+ var GDPR_ONLINE = ref(
42
+ "GDPR Recital 30",
43
+ "Online identifiers such as IP addresses and cookie identifiers may be used to identify natural persons.",
44
+ GDPR_URL
45
+ );
46
+ var KEYED_IF_DERIVED = { keyed: true };
47
+ var GDPR_DEFAULT = Object.freeze({ strategy: "pseudonymize" });
48
+ var GDPR_RATIONALE = "A replacement that is computed from the value without a secret can be recomputed by anyone, so the data stays attributable and is not pseudonymised in the sense of Art. 4(5).";
49
+ var GDPR = {
50
+ id: "gdpr",
51
+ name: "General Data Protection Regulation",
52
+ jurisdiction: "European Union / EEA",
53
+ edition: "Regulation (EU) 2016/679",
54
+ references: [
55
+ ref(
56
+ "GDPR Art. 5(1)(c)",
57
+ "Data minimisation: adequate, relevant and limited to what is necessary.",
58
+ GDPR_URL
59
+ ),
60
+ ref(
61
+ "GDPR Art. 5(1)(e)",
62
+ "Storage limitation: identifiable form for no longer than necessary.",
63
+ GDPR_URL
64
+ ),
65
+ ref(
66
+ "GDPR Art. 25(1)",
67
+ "Data protection by design and by default, such as pseudonymisation.",
68
+ GDPR_URL
69
+ ),
70
+ ref(
71
+ "GDPR Art. 32(1)(a)",
72
+ "Security of processing includes the pseudonymisation and encryption of personal data.",
73
+ GDPR_URL
74
+ ),
75
+ ref(
76
+ "GDPR Recital 26",
77
+ "The principles of data protection do not apply to anonymous information.",
78
+ GDPR_URL
79
+ ),
80
+ GDPR_PSEUDONYMISATION
81
+ ],
82
+ rules: [
83
+ ...rules(
84
+ ["name", "email", "phone", "address", "date-of-birth"],
85
+ [GDPR_PERSONAL_DATA],
86
+ KEYED_IF_DERIVED,
87
+ GDPR_DEFAULT,
88
+ GDPR_RATIONALE
89
+ ),
90
+ ...rules(
91
+ ["national-id", "ssn", "passport", "drivers-license", "tax-id"],
92
+ [GDPR_PERSONAL_DATA, GDPR_NATIONAL_ID],
93
+ KEYED_IF_DERIVED,
94
+ GDPR_DEFAULT,
95
+ GDPR_RATIONALE
96
+ ),
97
+ ...rules(
98
+ ["iban", "bank-account", "credit-card", "cryptocurrency"],
99
+ [GDPR_PERSONAL_DATA],
100
+ KEYED_IF_DERIVED,
101
+ GDPR_DEFAULT,
102
+ GDPR_RATIONALE
103
+ ),
104
+ ...rules(
105
+ ["ipv4", "ipv6", "url", "social-media"],
106
+ [GDPR_PERSONAL_DATA, GDPR_ONLINE],
107
+ KEYED_IF_DERIVED,
108
+ GDPR_DEFAULT,
109
+ GDPR_RATIONALE
110
+ ),
111
+ ...rules(
112
+ ["medical-record", "health-insurance", "prescription"],
113
+ [GDPR_SPECIAL, GDPR_PERSONAL_DATA],
114
+ KEYED_IF_DERIVED,
115
+ GDPR_DEFAULT,
116
+ "Identifiers of health records lead to data concerning health, a special category."
117
+ )
118
+ ],
119
+ gaps: [
120
+ {
121
+ element: "Location data (coordinates, postal codes, city names)",
122
+ reference: GDPR_PERSONAL_DATA,
123
+ mitigation: "Add custom patterns for the formats in your data, or drop the fields that carry location."
124
+ },
125
+ {
126
+ element: "Device, advertising and cookie identifiers",
127
+ reference: GDPR_ONLINE,
128
+ mitigation: "Add custom patterns for the identifiers your systems emit."
129
+ },
130
+ {
131
+ element: "Special categories expressed in free text (health conditions, beliefs, union membership)",
132
+ reference: GDPR_SPECIAL,
133
+ mitigation: "Pattern matching cannot find these. Redact the fields that may contain them, by key."
134
+ },
135
+ {
136
+ element: "Names that are not introduced by a title, greeting or label",
137
+ reference: GDPR_PERSONAL_DATA,
138
+ mitigation: "Redact name fields by key; the name detector is a heuristic."
139
+ }
140
+ ],
141
+ auditTrail: ref(
142
+ "GDPR Art. 30",
143
+ "Controllers and processors maintain records of processing activities.",
144
+ GDPR_URL
145
+ ),
146
+ erasure: ref("GDPR Art. 17", "Right to erasure ('right to be forgotten').", GDPR_URL)
147
+ };
148
+ var LGPD_URL = "https://www.planalto.gov.br/ccivil_03/_ato2015-2018/2018/lei/l13709.htm";
149
+ var LGPD_PERSONAL_DATA = ref(
150
+ "LGPD Art. 5, I",
151
+ "Dado pessoal: information relating to an identified or identifiable natural person.",
152
+ LGPD_URL
153
+ );
154
+ var LGPD_SENSITIVE = ref(
155
+ "LGPD Art. 5, II",
156
+ "Dado pessoal sens\xEDvel includes data concerning health, and genetic or biometric data linked to a natural person.",
157
+ LGPD_URL
158
+ );
159
+ var LGPD_RATIONALE = "Data is anonymised only if it can no longer be associated with an individual by reasonable technical means (Art. 5, XI and Art. 12); a keyless transformation of the value can be reversed.";
160
+ var LGPD = {
161
+ id: "lgpd",
162
+ name: "Lei Geral de Prote\xE7\xE3o de Dados Pessoais",
163
+ jurisdiction: "Brazil",
164
+ edition: "Lei n\xBA 13.709/2018, as amended",
165
+ references: [
166
+ ref(
167
+ "LGPD Art. 5, III",
168
+ "Dado anonimizado: data whose subject cannot be identified by reasonable technical means.",
169
+ LGPD_URL
170
+ ),
171
+ ref(
172
+ "LGPD Art. 5, XI",
173
+ "Anonimiza\xE7\xE3o: means by which data loses the possibility of association with an individual.",
174
+ LGPD_URL
175
+ ),
176
+ ref(
177
+ "LGPD Art. 6, III",
178
+ "Necessidade: processing limited to the minimum necessary for its purposes.",
179
+ LGPD_URL
180
+ ),
181
+ ref(
182
+ "LGPD Art. 12",
183
+ "Anonymised data is not personal data unless the process can be reversed with reasonable effort.",
184
+ LGPD_URL
185
+ ),
186
+ ref(
187
+ "LGPD Art. 13, \xA7 4\xBA",
188
+ "Pseudonimiza\xE7\xE3o: association is only possible with additional information kept separately by the controller.",
189
+ LGPD_URL
190
+ ),
191
+ ref(
192
+ "LGPD Art. 46",
193
+ "Processing agents adopt technical and administrative security measures to protect personal data.",
194
+ LGPD_URL
195
+ )
196
+ ],
197
+ rules: [
198
+ ...rules(
199
+ [
200
+ "name",
201
+ "email",
202
+ "phone",
203
+ "address",
204
+ "date-of-birth",
205
+ "national-id",
206
+ "tax-id",
207
+ "passport",
208
+ "drivers-license"
209
+ ],
210
+ [LGPD_PERSONAL_DATA],
211
+ KEYED_IF_DERIVED,
212
+ REDACT,
213
+ LGPD_RATIONALE
214
+ ),
215
+ ...rules(
216
+ [
217
+ "bank-account",
218
+ "iban",
219
+ "credit-card",
220
+ "cryptocurrency",
221
+ "ipv4",
222
+ "ipv6",
223
+ "url",
224
+ "social-media",
225
+ "license-plate"
226
+ ],
227
+ [LGPD_PERSONAL_DATA],
228
+ KEYED_IF_DERIVED,
229
+ REDACT,
230
+ LGPD_RATIONALE
231
+ ),
232
+ ...rules(
233
+ ["medical-record", "health-insurance", "prescription"],
234
+ [LGPD_SENSITIVE, LGPD_PERSONAL_DATA],
235
+ KEYED_IF_DERIVED,
236
+ REDACT,
237
+ "Identifiers of health records lead to dado pessoal sens\xEDvel."
238
+ )
239
+ ],
240
+ gaps: [
241
+ {
242
+ element: "CPF without punctuation, CNPJ, RG, CNH, t\xEDtulo de eleitor, PIS/PASEP and Cart\xE3o Nacional de Sa\xFAde numbers",
243
+ reference: LGPD_PERSONAL_DATA,
244
+ mitigation: "Only the punctuated CPF format is detected. Add custom patterns with the checksum validators for the others."
245
+ },
246
+ {
247
+ element: "Brazilian phone numbers in national format, CEP postal codes and addresses written in Portuguese",
248
+ reference: LGPD_PERSONAL_DATA,
249
+ mitigation: "Add custom patterns, or redact the fields that carry them by key."
250
+ },
251
+ {
252
+ element: "Sensitive data in free text (health, religion, political opinion, union membership)",
253
+ reference: LGPD_SENSITIVE,
254
+ mitigation: "Pattern matching cannot find these. Redact the fields that may contain them, by key."
255
+ }
256
+ ],
257
+ auditTrail: ref(
258
+ "LGPD Art. 37",
259
+ "Controller and operator keep a record of the processing operations they carry out.",
260
+ LGPD_URL
261
+ ),
262
+ erasure: ref(
263
+ "LGPD Art. 18, IV and VI",
264
+ "The data subject may obtain anonymisation, blocking or deletion of unnecessary or excessive data, and deletion of data processed with consent.",
265
+ LGPD_URL
266
+ )
267
+ };
268
+ var PIPEDA_URL = "https://laws-lois.justice.gc.ca/eng/acts/P-8.6/";
269
+ var PIPEDA_PERSONAL = ref(
270
+ "PIPEDA s. 2(1)",
271
+ "Personal information means information about an identifiable individual.",
272
+ PIPEDA_URL
273
+ );
274
+ var PIPEDA_SAFEGUARDS = ref(
275
+ "PIPEDA Schedule 1, cl. 4.7",
276
+ "Personal information is protected by security safeguards appropriate to its sensitivity; technological measures include passwords and encryption (cl. 4.7.3).",
277
+ PIPEDA_URL
278
+ );
279
+ var PIPEDA = {
280
+ id: "pipeda",
281
+ name: "Personal Information Protection and Electronic Documents Act",
282
+ jurisdiction: "Canada (federal, private sector)",
283
+ edition: "S.C. 2000, c. 5, as amended",
284
+ references: [
285
+ ref(
286
+ "PIPEDA Schedule 1, cl. 4.4",
287
+ "Limiting collection to what is necessary for the identified purposes.",
288
+ PIPEDA_URL
289
+ ),
290
+ PIPEDA_SAFEGUARDS,
291
+ ref(
292
+ "PIPEDA s. 10.1",
293
+ "Breaches of security safeguards that create a real risk of significant harm are reported and notified.",
294
+ PIPEDA_URL
295
+ )
296
+ ],
297
+ rules: [
298
+ ...rules(
299
+ [
300
+ "name",
301
+ "email",
302
+ "phone",
303
+ "address",
304
+ "date-of-birth",
305
+ "national-id",
306
+ "ssn",
307
+ "passport",
308
+ "drivers-license",
309
+ "tax-id",
310
+ "bank-account",
311
+ "iban",
312
+ "credit-card",
313
+ "ipv4",
314
+ "ipv6",
315
+ "social-media"
316
+ ],
317
+ [PIPEDA_PERSONAL, PIPEDA_SAFEGUARDS],
318
+ {},
319
+ REDACT,
320
+ "The Act prescribes no transformation; the safeguard has to match the sensitivity of the information."
321
+ ),
322
+ ...rules(
323
+ ["medical-record", "health-insurance", "prescription"],
324
+ [PIPEDA_PERSONAL, PIPEDA_SAFEGUARDS],
325
+ KEYED_IF_DERIVED,
326
+ REDACT,
327
+ "Health information is sensitive, so a replacement that anyone can recompute from the value is not an appropriate safeguard."
328
+ )
329
+ ],
330
+ gaps: [
331
+ {
332
+ element: "Provincial health card numbers, postal codes, and bank transit and institution numbers",
333
+ reference: PIPEDA_PERSONAL,
334
+ mitigation: "Add custom patterns. The Social Insurance Number is detected as national-id."
335
+ },
336
+ {
337
+ element: "Names and addresses written in French",
338
+ reference: PIPEDA_PERSONAL,
339
+ mitigation: "Redact name and address fields by key; the detectors are tuned to English forms."
340
+ }
341
+ ],
342
+ auditTrail: ref(
343
+ "PIPEDA s. 10.3",
344
+ "Organizations keep a record of every breach of security safeguards.",
345
+ PIPEDA_URL
346
+ ),
347
+ erasure: ref(
348
+ "PIPEDA Schedule 1, cl. 4.5.3",
349
+ "Personal information that is no longer required should be destroyed, erased or made anonymous. This is a retention principle, not an individual right to erasure.",
350
+ PIPEDA_URL
351
+ )
352
+ };
353
+ var CCPA_URL = "https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?lawCode=CIV&sectionNum=1798.140";
354
+ var CCPA_IDENTIFIERS = ref(
355
+ "Cal. Civ. Code \xA7 1798.140(v)(1)(A)",
356
+ "Personal information includes identifiers such as a real name, postal address, online identifier, IP address, email address, social security number, driver's license number and passport number.",
357
+ CCPA_URL
358
+ );
359
+ var CCPA_RECORDS = ref(
360
+ "Cal. Civ. Code \xA7 1798.140(v)(1)(B)",
361
+ "Personal information includes the categories of \xA7 1798.80(e): telephone number, bank account and card numbers, medical information and health insurance information, among others.",
362
+ CCPA_URL
363
+ );
364
+ var CCPA_SENSITIVE = ref(
365
+ "Cal. Civ. Code \xA7 1798.140(ae)",
366
+ "Sensitive personal information includes social security, driver's license, state identification card and passport numbers; account log-in and financial account or card numbers with their credentials; and health information.",
367
+ CCPA_URL
368
+ );
369
+ var CCPA_SENSITIVE_RATIONALE = "Pseudonymized information must not be attributable without separately kept information (\xA7 1798.140(aa)); a keyless transformation of sensitive personal information does not meet that.";
370
+ var CCPA = {
371
+ id: "ccpa",
372
+ name: "California Consumer Privacy Act, as amended by the California Privacy Rights Act",
373
+ jurisdiction: "California, United States",
374
+ edition: "Cal. Civ. Code \xA7\xA7 1798.100\u20131798.199.100",
375
+ references: [
376
+ ref(
377
+ "Cal. Civ. Code \xA7 1798.100(e)",
378
+ "A business implements reasonable security procedures and practices appropriate to the nature of the personal information.",
379
+ CCPA_URL
380
+ ),
381
+ ref(
382
+ "Cal. Civ. Code \xA7 1798.121",
383
+ "A consumer may direct a business to limit its use of sensitive personal information.",
384
+ CCPA_URL
385
+ ),
386
+ ref(
387
+ "Cal. Civ. Code \xA7 1798.140(m)",
388
+ "Deidentified information cannot reasonably be used to infer information about, or be linked to, a particular consumer.",
389
+ CCPA_URL
390
+ ),
391
+ ref(
392
+ "Cal. Civ. Code \xA7 1798.140(aa)",
393
+ "Pseudonymization renders personal information no longer attributable without additional information that is kept separately.",
394
+ CCPA_URL
395
+ ),
396
+ ref(
397
+ "Cal. Civ. Code \xA7 1798.150",
398
+ "Private right of action after a breach of nonencrypted and nonredacted personal information.",
399
+ CCPA_URL
400
+ )
401
+ ],
402
+ rules: [
403
+ ...rules(
404
+ ["name", "email", "address", "ipv4", "ipv6", "url", "social-media"],
405
+ [CCPA_IDENTIFIERS],
406
+ {},
407
+ REDACT,
408
+ "Redaction removes the identifier; the statute prescribes no particular transformation for non-sensitive identifiers."
409
+ ),
410
+ ...rules(
411
+ ["phone", "date-of-birth", "tax-id"],
412
+ [CCPA_RECORDS],
413
+ {},
414
+ REDACT,
415
+ "Covered through \xA7 1798.80(e) or as information linkable to a consumer."
416
+ ),
417
+ ...rules(
418
+ ["ssn", "national-id", "passport", "drivers-license"],
419
+ [CCPA_SENSITIVE, CCPA_IDENTIFIERS],
420
+ KEYED_IF_DERIVED,
421
+ REDACT,
422
+ CCPA_SENSITIVE_RATIONALE
423
+ ),
424
+ ...rules(
425
+ ["bank-account", "credit-card", "api-key"],
426
+ [CCPA_SENSITIVE, CCPA_RECORDS],
427
+ KEYED_IF_DERIVED,
428
+ REDACT,
429
+ CCPA_SENSITIVE_RATIONALE
430
+ ),
431
+ ...rules(
432
+ ["medical-record", "health-insurance"],
433
+ [CCPA_SENSITIVE, CCPA_RECORDS],
434
+ KEYED_IF_DERIVED,
435
+ REDACT,
436
+ CCPA_SENSITIVE_RATIONALE
437
+ )
438
+ ],
439
+ gaps: [
440
+ {
441
+ element: "Precise geolocation",
442
+ reference: ref(
443
+ "Cal. Civ. Code \xA7 1798.140(w)",
444
+ "Precise geolocation locates a consumer within a small geographic area.",
445
+ CCPA_URL
446
+ ),
447
+ mitigation: "Add custom patterns for coordinates, or drop the fields that carry them."
448
+ },
449
+ {
450
+ element: "Passwords, security codes and other account credentials",
451
+ reference: CCPA_SENSITIVE,
452
+ mitigation: "Redact credential fields by key. Only API-key shaped secrets are detected."
453
+ },
454
+ {
455
+ element: "Device, cookie and advertising identifiers",
456
+ reference: ref(
457
+ "Cal. Civ. Code \xA7 1798.140(aj)",
458
+ "A unique identifier is a persistent identifier that can recognise a consumer or a device over time.",
459
+ CCPA_URL
460
+ ),
461
+ mitigation: "Add custom patterns for the identifiers your systems emit."
462
+ },
463
+ {
464
+ element: "Biometric information, and inferences drawn about a consumer",
465
+ reference: ref(
466
+ "Cal. Civ. Code \xA7 1798.140(c)",
467
+ "Biometric information: physiological, biological or behavioural characteristics.",
468
+ CCPA_URL
469
+ ),
470
+ mitigation: "Pattern matching cannot find these. Redact the fields that may contain them, by key."
471
+ }
472
+ ],
473
+ erasure: ref(
474
+ "Cal. Civ. Code \xA7 1798.105",
475
+ "A consumer may request deletion of personal information the business collected from the consumer.",
476
+ CCPA_URL
477
+ )
478
+ };
479
+ var HIPAA_URL = "https://www.ecfr.gov/current/title-45/section-164.514";
480
+ var safeHarbor = (letter, summary) => ref(`45 CFR \xA7 164.514(b)(2)(i)(${letter})`, summary, HIPAA_URL);
481
+ var HIPAA_REIDENTIFICATION = ref(
482
+ "45 CFR \xA7 164.514(c)",
483
+ "A re-identification code must not be derived from or related to information about the individual, and the mechanism must not be disclosed.",
484
+ HIPAA_URL
485
+ );
486
+ var REMOVED = {
487
+ notDerived: true,
488
+ maxRevealed: { leading: 0, trailing: 0 }
489
+ };
490
+ var HIPAA_RATIONALE = "Safe Harbor requires the identifier to be removed. A hash, keyed hash, ciphertext or partial mask of it is derived from information about the individual, which \xA7 164.514(c) forbids for re-identification codes.";
491
+ var hipaa = (categories, letter, summary) => rules(
492
+ categories,
493
+ [safeHarbor(letter, summary), HIPAA_REIDENTIFICATION],
494
+ REMOVED,
495
+ REDACT,
496
+ HIPAA_RATIONALE
497
+ );
498
+ var HIPAA = {
499
+ id: "hipaa",
500
+ name: "HIPAA Privacy Rule \u2014 de-identification by Safe Harbor",
501
+ jurisdiction: "United States",
502
+ edition: "45 CFR Part 164, Subpart E",
503
+ references: [
504
+ ref(
505
+ "45 CFR \xA7 164.514(a)",
506
+ "Health information that does not identify an individual is not individually identifiable health information.",
507
+ HIPAA_URL
508
+ ),
509
+ ref(
510
+ "45 CFR \xA7 164.514(b)(1)",
511
+ "Expert Determination: the alternative to Safe Harbor.",
512
+ HIPAA_URL
513
+ ),
514
+ ref(
515
+ "45 CFR \xA7 164.514(b)(2)(ii)",
516
+ "The covered entity has no actual knowledge that the remaining information could identify the individual.",
517
+ HIPAA_URL
518
+ ),
519
+ HIPAA_REIDENTIFICATION
520
+ ],
521
+ rules: [
522
+ ...hipaa(["name"], "A", "Names."),
523
+ ...hipaa(
524
+ ["address"],
525
+ "B",
526
+ "All geographic subdivisions smaller than a State, including street address."
527
+ ),
528
+ ...hipaa(
529
+ ["date-of-birth"],
530
+ "C",
531
+ "All elements of dates (except year) directly related to an individual, including birth date."
532
+ ),
533
+ ...hipaa(["phone"], "D", "Telephone numbers (and, under (E), fax numbers)."),
534
+ ...hipaa(["email"], "F", "Electronic mail addresses."),
535
+ ...hipaa(["ssn"], "G", "Social security numbers."),
536
+ ...hipaa(["medical-record"], "H", "Medical record numbers."),
537
+ ...hipaa(["health-insurance"], "I", "Health plan beneficiary numbers."),
538
+ ...hipaa(["bank-account", "credit-card", "iban"], "J", "Account numbers."),
539
+ ...hipaa(["drivers-license", "passport", "prescription"], "K", "Certificate/license numbers."),
540
+ ...hipaa(
541
+ ["vin", "license-plate"],
542
+ "L",
543
+ "Vehicle identifiers and serial numbers, including license plate numbers."
544
+ ),
545
+ ...hipaa(["url"], "N", "Web Universal Resource Locators (URLs)."),
546
+ ...hipaa(["ipv4", "ipv6"], "O", "Internet Protocol (IP) address numbers."),
547
+ ...hipaa(
548
+ ["national-id", "tax-id", "social-media"],
549
+ "R",
550
+ "Any other unique identifying number, characteristic, or code."
551
+ )
552
+ ],
553
+ gaps: [
554
+ {
555
+ element: "City, county, precinct and ZIP code",
556
+ reference: safeHarbor("B", "All geographic subdivisions smaller than a State."),
557
+ mitigation: "Only street addresses are detected. Redact or generalise location fields by key."
558
+ },
559
+ {
560
+ element: "Admission, discharge and death dates, and ages over 89",
561
+ reference: safeHarbor("C", "All elements of dates (except year), and all ages over 89."),
562
+ mitigation: "Only dates that look like a date of birth are detected. Redact date and age fields by key."
563
+ },
564
+ {
565
+ element: "Device identifiers and serial numbers",
566
+ reference: safeHarbor("M", "Device identifiers and serial numbers."),
567
+ mitigation: "Add custom patterns for the device identifiers in your records."
568
+ },
569
+ {
570
+ element: "Biometric identifiers and full-face photographs",
571
+ reference: safeHarbor("P", "Biometric identifiers; (Q) full-face photographic images."),
572
+ mitigation: "Out of reach of text processing. Remove these attachments and fields."
573
+ },
574
+ {
575
+ element: "Names that are not introduced by a title, greeting or label",
576
+ reference: safeHarbor("A", "Names."),
577
+ mitigation: "Redact name fields by key; the name detector is a heuristic."
578
+ }
579
+ ],
580
+ auditTrail: ref(
581
+ "45 CFR \xA7 164.312(b)",
582
+ "Audit controls: mechanisms that record and examine activity in systems that contain electronic protected health information.",
583
+ "https://www.ecfr.gov/current/title-45/section-164.312"
584
+ )
585
+ };
586
+ var PCI_URL = "https://www.pcisecuritystandards.org/document_library/";
587
+ var PCI_DISPLAY = ref(
588
+ "PCI DSS v4.0.1 Req. 3.4.1",
589
+ "PAN is masked when displayed; the BIN and last four digits are the maximum number of digits to be displayed.",
590
+ PCI_URL
591
+ );
592
+ var PCI_STORAGE = ref(
593
+ "PCI DSS v4.0.1 Req. 3.5.1",
594
+ "PAN is rendered unreadable anywhere it is stored: one-way hashes of the entire PAN, truncation, index tokens, or strong cryptography.",
595
+ PCI_URL
596
+ );
597
+ var PCI_KEYED_HASH = ref(
598
+ "PCI DSS v4.0.1 Req. 3.5.1.1",
599
+ "Hashes used to render PAN unreadable are keyed cryptographic hashes of the entire PAN.",
600
+ PCI_URL
601
+ );
602
+ var PCI_SAD = ref(
603
+ "PCI DSS v4.0.1 Req. 3.3.1",
604
+ "Sensitive authentication data is not retained after authorization.",
605
+ PCI_URL
606
+ );
607
+ var PCI_ADJACENT = ref(
608
+ "PCI DSS v4.0.1 Req. 3, account data",
609
+ "Not account data; commonly stored next to it.",
610
+ PCI_URL
611
+ );
612
+ var PCI_DSS = {
613
+ id: "pci-dss",
614
+ name: "Payment Card Industry Data Security Standard",
615
+ jurisdiction: "Global (contractual, card brands)",
616
+ edition: "PCI DSS v4.0.1",
617
+ references: [
618
+ PCI_SAD,
619
+ PCI_DISPLAY,
620
+ PCI_STORAGE,
621
+ PCI_KEYED_HASH,
622
+ ref(
623
+ "PCI DSS v4.0.1 Req. 3.7.5",
624
+ "Key management covers the retirement, replacement or destruction of keys.",
625
+ PCI_URL
626
+ ),
627
+ ref(
628
+ "PCI DSS v4.0.1 Req. 10.5.1",
629
+ "Audit log history is retained for at least 12 months.",
630
+ PCI_URL
631
+ )
632
+ ],
633
+ rules: [
634
+ ...rules(
635
+ ["credit-card"],
636
+ [PCI_DISPLAY, PCI_STORAGE, PCI_KEYED_HASH],
637
+ { keyed: true, maxRevealed: { leading: 6, trailing: 4 } },
638
+ { strategy: "mask", keepTrailing: 4 },
639
+ "At most the BIN and the last four digits may stay visible, and a hash of the PAN has to be keyed."
640
+ ),
641
+ ...rules(
642
+ ["name"],
643
+ [
644
+ ref(
645
+ "PCI DSS v4.0.1 Req. 3, account data",
646
+ "Cardholder name is cardholder data and is protected when stored with the PAN.",
647
+ PCI_URL
648
+ )
649
+ ],
650
+ {},
651
+ REDACT,
652
+ "Cardholder name is part of cardholder data."
653
+ ),
654
+ ...rules(
655
+ ["bank-account"],
656
+ [PCI_ADJACENT],
657
+ {},
658
+ { strategy: "mask", keepTrailing: 4 },
659
+ "Outside the standard's definition of account data; masked like a PAN because it accompanies card data in payment records."
660
+ ),
661
+ ...rules(
662
+ ["address", "email", "phone"],
663
+ [PCI_ADJACENT],
664
+ {},
665
+ REDACT,
666
+ "Outside the standard's definition of account data; included because these fields accompany card data in payment records."
667
+ )
668
+ ],
669
+ gaps: [
670
+ {
671
+ element: "Card verification codes, full track data and PINs or PIN blocks (sensitive authentication data)",
672
+ reference: PCI_SAD,
673
+ mitigation: "These must not be stored at all. Redact the fields that carry them by key; no detector finds them."
674
+ },
675
+ {
676
+ element: "Expiration date and service code",
677
+ reference: ref(
678
+ "PCI DSS v4.0.1 Req. 3, account data",
679
+ "Expiration date and service code are cardholder data.",
680
+ PCI_URL
681
+ ),
682
+ mitigation: "Redact the fields that carry them by key."
683
+ }
684
+ ],
685
+ auditTrail: ref(
686
+ "PCI DSS v4.0.1 Req. 10.2.1 and 10.3.2",
687
+ "Audit logs are enabled for all system components and cardholder data, and protected from modification.",
688
+ PCI_URL
689
+ )
690
+ };
691
+ function freezeProfile(profile) {
692
+ return Object.freeze({
693
+ ...profile,
694
+ references: Object.freeze([...profile.references]),
695
+ rules: Object.freeze([...profile.rules]),
696
+ gaps: Object.freeze(profile.gaps.map((gap) => Object.freeze({ ...gap })))
697
+ });
698
+ }
699
+ var REGULATIONS = Object.freeze({
700
+ gdpr: freezeProfile(GDPR),
701
+ lgpd: freezeProfile(LGPD),
702
+ pipeda: freezeProfile(PIPEDA),
703
+ ccpa: freezeProfile(CCPA),
704
+ hipaa: freezeProfile(HIPAA),
705
+ "pci-dss": freezeProfile(PCI_DSS)
706
+ });
707
+ function isRegulationId(id) {
708
+ return typeof id === "string" && Object.hasOwn(REGULATIONS, id);
709
+ }
710
+ function getRegulation(id) {
711
+ if (!isRegulationId(id)) throw new ValidationError("regulation", "is not a known regulation");
712
+ return REGULATIONS[id];
713
+ }
714
+ function describeRequirement(requirement) {
715
+ const parts = [];
716
+ if (requirement.irreversible === true) parts.push("irreversible");
717
+ if (requirement.notDerived === true) parts.push("not derived from the value");
718
+ if (requirement.keyed === true) parts.push("keyed if derived from the value");
719
+ if (requirement.maxRevealed !== void 0) {
720
+ const { leading, trailing } = requirement.maxRevealed;
721
+ parts.push(
722
+ leading + trailing === 0 ? "nothing left visible" : `at most ${String(leading)} leading and ${String(trailing)} trailing characters visible`
723
+ );
724
+ }
725
+ return parts.length === 0 ? "clear value removed" : parts.join("; ");
726
+ }
727
+ function complianceMatrix() {
728
+ const rows = [];
729
+ for (const profile of Object.values(REGULATIONS)) {
730
+ for (const rule of profile.rules) {
731
+ const { strategy, ...optionsOf } = rule.recommended;
732
+ const optionText = Object.entries(optionsOf).map(([name, value]) => `${name}: ${String(value)}`).join(", ");
733
+ rows.push({
734
+ regulation: profile.id,
735
+ category: rule.category,
736
+ citations: rule.references.map((reference) => reference.citation),
737
+ requirement: describeRequirement(rule.requirement),
738
+ recommended: optionText === "" ? strategy : `${strategy} (${optionText})`
739
+ });
740
+ }
741
+ }
742
+ return rows;
743
+ }
744
+
745
+ // src/compliance/traits.ts
746
+ var NOTHING_REVEALED = Object.freeze({ leading: 0, trailing: 0 });
747
+ function describeStrategy(spec, tokenization) {
748
+ switch (spec.strategy) {
749
+ case "redact":
750
+ return {
751
+ reversible: false,
752
+ derived: false,
753
+ keyed: false,
754
+ linkable: false,
755
+ revealed: NOTHING_REVEALED
756
+ };
757
+ case "mask":
758
+ return {
759
+ reversible: false,
760
+ derived: false,
761
+ keyed: false,
762
+ linkable: false,
763
+ revealed: { leading: spec.keepLeading ?? 0, trailing: spec.keepTrailing ?? 0 }
764
+ };
765
+ case "generalize":
766
+ return { reversible: false, derived: true, keyed: false, linkable: true, revealed: "all" };
767
+ case "pseudonymize":
768
+ return spec.seed === void 0 ? {
769
+ reversible: false,
770
+ derived: false,
771
+ keyed: false,
772
+ linkable: false,
773
+ revealed: NOTHING_REVEALED
774
+ } : {
775
+ reversible: false,
776
+ derived: true,
777
+ keyed: false,
778
+ linkable: true,
779
+ revealed: NOTHING_REVEALED
780
+ };
781
+ case "synthesize":
782
+ return {
783
+ reversible: false,
784
+ derived: true,
785
+ keyed: false,
786
+ linkable: true,
787
+ revealed: NOTHING_REVEALED
788
+ };
789
+ case "hash":
790
+ return {
791
+ reversible: false,
792
+ derived: true,
793
+ keyed: spec.pepper !== void 0,
794
+ linkable: true,
795
+ revealed: NOTHING_REVEALED
796
+ };
797
+ case "encrypt":
798
+ return {
799
+ reversible: true,
800
+ derived: true,
801
+ keyed: true,
802
+ linkable: false,
803
+ revealed: NOTHING_REVEALED
804
+ };
805
+ case "tokenize": {
806
+ const derived = tokenization?.scheme !== "session";
807
+ return {
808
+ reversible: tokenization?.reversible ?? true,
809
+ derived,
810
+ keyed: derived,
811
+ linkable: true,
812
+ revealed: NOTHING_REVEALED
813
+ };
814
+ }
815
+ }
816
+ }
817
+ function checkRequirement(traits, requirement) {
818
+ const reasons = [];
819
+ if (requirement.irreversible === true && traits.reversible) {
820
+ reasons.push("the value can be restored by whoever holds the key or vault");
821
+ }
822
+ if (requirement.notDerived === true && traits.derived) {
823
+ reasons.push("the output is computed from the value");
824
+ }
825
+ if (requirement.keyed === true && traits.derived && !traits.keyed) {
826
+ reasons.push("the output is computed from the value without a secret key");
827
+ }
828
+ if (requirement.maxRevealed !== void 0) {
829
+ const { leading, trailing } = requirement.maxRevealed;
830
+ if (traits.revealed === "all") {
831
+ reasons.push("the value can pass through unchanged");
832
+ } else if (traits.revealed.leading > leading || traits.revealed.trailing > trailing) {
833
+ reasons.push(
834
+ `more than ${String(leading)} leading and ${String(trailing)} trailing characters stay visible`
835
+ );
836
+ }
837
+ }
838
+ return reasons;
839
+ }
840
+
841
+ // src/compliance/policy.ts
842
+ var REDACT2 = Object.freeze({ strategy: "redact" });
843
+ var TOP_LEVEL = /* @__PURE__ */ new Set([
844
+ "version",
845
+ "id",
846
+ "description",
847
+ "extends",
848
+ "categories",
849
+ "defaultStrategy",
850
+ "rules",
851
+ "patterns",
852
+ "minConfidence",
853
+ "allow",
854
+ "aggressive",
855
+ "overlap"
856
+ ]);
857
+ var STRATEGY_OPTIONS = {
858
+ redact: { label: "string" },
859
+ mask: {
860
+ maskChar: "string",
861
+ keepLeading: "count",
862
+ keepTrailing: "count",
863
+ preserveFormat: "boolean"
864
+ },
865
+ pseudonymize: { seed: "string", prefix: "string" },
866
+ hash: { truncate: "count", pepper: "string" },
867
+ generalize: { bucketSize: "count" },
868
+ synthesize: { seed: "string", locale: "string", category: "string" },
869
+ tokenize: {},
870
+ encrypt: {}
871
+ };
872
+ function isObject(value) {
873
+ return typeof value === "object" && value !== null && !Array.isArray(value);
874
+ }
875
+ function isCategory(value) {
876
+ return typeof value === "string" && BUILTIN_CATEGORIES.includes(value);
877
+ }
878
+ function escapePointer(segment) {
879
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
880
+ }
881
+ function checkPolicy(input, options = {}) {
882
+ const issues = [];
883
+ const error = (path, code, message, reference) => {
884
+ issues.push({
885
+ severity: "error",
886
+ path,
887
+ code,
888
+ message,
889
+ ...reference !== void 0 ? { reference } : {}
890
+ });
891
+ };
892
+ const warning = (path, code, message, reference) => {
893
+ issues.push({
894
+ severity: "warning",
895
+ path,
896
+ code,
897
+ message,
898
+ ...{}
899
+ });
900
+ };
901
+ if (!isObject(input)) {
902
+ error("", "not-an-object", "A policy document must be a JSON object.");
903
+ return { issues };
904
+ }
905
+ for (const key of Object.keys(input)) {
906
+ if (!TOP_LEVEL.has(key))
907
+ error(
908
+ `/${escapePointer(key)}`,
909
+ "unknown-member",
910
+ "This member is not part of the policy format."
911
+ );
912
+ }
913
+ if (input["version"] !== 1)
914
+ error("/version", "unsupported-version", "The only supported policy version is 1.");
915
+ const id = input["id"];
916
+ if (typeof id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(id)) {
917
+ error(
918
+ "/id",
919
+ "invalid-id",
920
+ "The id must be 1-64 characters of letters, digits, '.', '_' and '-'."
921
+ );
922
+ }
923
+ const description = input["description"];
924
+ if (description !== void 0 && typeof description !== "string") {
925
+ error("/description", "invalid-type", "The description must be a string.");
926
+ }
927
+ const regulations = [];
928
+ const extended = input["extends"];
929
+ if (extended !== void 0) {
930
+ if (!Array.isArray(extended)) {
931
+ error("/extends", "invalid-type", "extends must be an array of regulation identifiers.");
932
+ } else {
933
+ for (const [index, entry] of extended.entries()) {
934
+ if (!isRegulationId(entry)) {
935
+ error(
936
+ `/extends/${String(index)}`,
937
+ "unknown-regulation",
938
+ `Known regulations are: ${Object.keys(REGULATIONS).join(", ")}.`
939
+ );
940
+ } else if (!regulations.includes(entry)) {
941
+ regulations.push(entry);
942
+ }
943
+ }
944
+ }
945
+ }
946
+ const readCategories = (value, path) => {
947
+ const out = [];
948
+ if (value === void 0) return out;
949
+ if (!Array.isArray(value)) {
950
+ error(path, "invalid-type", "This member must be an array of category names.");
951
+ return out;
952
+ }
953
+ for (const [index, entry] of value.entries()) {
954
+ if (isCategory(entry)) out.push(entry);
955
+ else
956
+ error(`${path}/${String(index)}`, "unknown-category", "This is not a built-in category.");
957
+ }
958
+ return out;
959
+ };
960
+ let include = [];
961
+ let exclude = [];
962
+ const categoriesMember = input["categories"];
963
+ if (categoriesMember !== void 0) {
964
+ if (!isObject(categoriesMember)) {
965
+ error(
966
+ "/categories",
967
+ "invalid-type",
968
+ "categories must be an object with include and/or exclude."
969
+ );
970
+ } else {
971
+ for (const key of Object.keys(categoriesMember)) {
972
+ if (key !== "include" && key !== "exclude") {
973
+ error(
974
+ `/categories/${escapePointer(key)}`,
975
+ "unknown-member",
976
+ "This member is not part of the policy format."
977
+ );
978
+ }
979
+ }
980
+ include = readCategories(categoriesMember["include"], "/categories/include");
981
+ exclude = readCategories(categoriesMember["exclude"], "/categories/exclude");
982
+ }
983
+ }
984
+ const readStrategy = (value, path) => {
985
+ if (!isObject(value)) {
986
+ error(path, "invalid-type", "A strategy must be an object with a strategy name.");
987
+ return void 0;
988
+ }
989
+ const name = value["strategy"];
990
+ const allowed = typeof name === "string" && Object.hasOwn(STRATEGY_OPTIONS, name) ? STRATEGY_OPTIONS[name] : void 0;
991
+ if (allowed === void 0) {
992
+ error(
993
+ `${path}/strategy`,
994
+ "unknown-strategy",
995
+ `Known strategies are: ${Object.keys(STRATEGY_OPTIONS).join(", ")}.`
996
+ );
997
+ return void 0;
998
+ }
999
+ let valid = true;
1000
+ for (const [option, optionValue] of Object.entries(value)) {
1001
+ if (option === "strategy") continue;
1002
+ const expected = Object.hasOwn(allowed, option) ? allowed[option] : void 0;
1003
+ const fits = expected === "count" ? Number.isInteger(optionValue) && optionValue >= 0 : expected !== void 0 && typeof optionValue === expected;
1004
+ if (!fits) {
1005
+ valid = false;
1006
+ error(
1007
+ `${path}/${escapePointer(option)}`,
1008
+ expected === void 0 ? "unknown-option" : "invalid-option",
1009
+ expected === void 0 ? `The ${String(name)} strategy has no such option.` : `This option must be a ${expected === "count" ? "non-negative integer" : expected}.`
1010
+ );
1011
+ }
1012
+ }
1013
+ return valid ? Object.freeze({ ...value }) : void 0;
1014
+ };
1015
+ const defaultMember = input["defaultStrategy"];
1016
+ const explicitDefault = defaultMember === void 0 ? void 0 : readStrategy(defaultMember, "/defaultStrategy");
1017
+ const explicitRules = /* @__PURE__ */ new Map();
1018
+ const rulesMember = input["rules"];
1019
+ if (rulesMember !== void 0) {
1020
+ if (!isObject(rulesMember)) {
1021
+ error("/rules", "invalid-type", "rules must be an object keyed by category.");
1022
+ } else {
1023
+ for (const [category, value] of Object.entries(rulesMember)) {
1024
+ const strategy = readStrategy(value, `/rules/${escapePointer(category)}`);
1025
+ if (strategy !== void 0) explicitRules.set(category, strategy);
1026
+ }
1027
+ }
1028
+ }
1029
+ const patterns = [];
1030
+ const patternsMember = input["patterns"];
1031
+ if (patternsMember !== void 0) {
1032
+ if (!Array.isArray(patternsMember)) {
1033
+ error("/patterns", "invalid-type", "patterns must be an array.");
1034
+ } else {
1035
+ for (const [index, entry] of patternsMember.entries()) {
1036
+ const path = `/patterns/${String(index)}`;
1037
+ if (!isObject(entry) || typeof entry["source"] !== "string" || typeof entry["category"] !== "string" || entry["category"] === "") {
1038
+ error(
1039
+ path,
1040
+ "invalid-pattern",
1041
+ "A pattern needs a source string and a non-empty category."
1042
+ );
1043
+ continue;
1044
+ }
1045
+ const flags = entry["flags"];
1046
+ const confidence = entry["confidence"];
1047
+ if (flags !== void 0 && typeof flags !== "string") {
1048
+ error(`${path}/flags`, "invalid-type", "flags must be a string.");
1049
+ continue;
1050
+ }
1051
+ if (confidence !== void 0 && !(typeof confidence === "number" && confidence >= 0 && confidence <= 1)) {
1052
+ error(
1053
+ `${path}/confidence`,
1054
+ "invalid-type",
1055
+ "confidence must be a number between 0 and 1."
1056
+ );
1057
+ continue;
1058
+ }
1059
+ try {
1060
+ new RegExp(entry["source"], flags ?? "");
1061
+ } catch {
1062
+ error(
1063
+ path,
1064
+ "invalid-pattern",
1065
+ "The source and flags do not form a valid regular expression."
1066
+ );
1067
+ continue;
1068
+ }
1069
+ patterns.push(
1070
+ Object.freeze({
1071
+ source: entry["source"],
1072
+ category: entry["category"],
1073
+ ...flags !== void 0 ? { flags } : {},
1074
+ ...confidence !== void 0 ? { confidence } : {}
1075
+ })
1076
+ );
1077
+ }
1078
+ }
1079
+ }
1080
+ const minConfidence = input["minConfidence"];
1081
+ if (minConfidence !== void 0 && !(typeof minConfidence === "number" && minConfidence >= 0 && minConfidence <= 1)) {
1082
+ error("/minConfidence", "invalid-type", "minConfidence must be a number between 0 and 1.");
1083
+ }
1084
+ const allow = input["allow"];
1085
+ if (allow !== void 0 && !(Array.isArray(allow) && allow.every((entry) => typeof entry === "string"))) {
1086
+ error("/allow", "invalid-type", "allow must be an array of strings.");
1087
+ }
1088
+ const aggressive = input["aggressive"];
1089
+ if (aggressive !== void 0 && typeof aggressive !== "boolean") {
1090
+ error("/aggressive", "invalid-type", "aggressive must be a boolean.");
1091
+ }
1092
+ const overlap = input["overlap"];
1093
+ if (overlap !== void 0 && overlap !== "cover" && overlap !== "legacy") {
1094
+ error("/overlap", "invalid-type", 'overlap must be "cover" or "legacy".');
1095
+ }
1096
+ const required = /* @__PURE__ */ new Map();
1097
+ for (const regulation of regulations) {
1098
+ for (const rule of REGULATIONS[regulation].rules) {
1099
+ if (!required.has(rule.category)) required.set(rule.category, regulation);
1100
+ }
1101
+ }
1102
+ for (const [index, category] of exclude.entries()) {
1103
+ const regulation = required.get(category);
1104
+ if (regulation !== void 0) {
1105
+ const rule = REGULATIONS[regulation].rules.find(
1106
+ (candidate) => candidate.category === category
1107
+ );
1108
+ error(
1109
+ `/categories/exclude/${String(index)}`,
1110
+ "required-category-excluded",
1111
+ `${REGULATIONS[regulation].name} brings "${category}" into scope; it cannot be excluded.`,
1112
+ rule?.references[0]
1113
+ );
1114
+ }
1115
+ }
1116
+ const wanted = regulations.length === 0 && include.length === 0 ? new Set(BUILTIN_CATEGORIES) : /* @__PURE__ */ new Set([...required.keys(), ...include]);
1117
+ for (const category of exclude) wanted.delete(category);
1118
+ const categories = BUILTIN_CATEGORIES.filter((category) => wanted.has(category));
1119
+ for (const category of explicitRules.keys()) {
1120
+ const known = isCategory(category) ? wanted.has(category) : patterns.some((pattern) => pattern.category === category);
1121
+ if (!known) {
1122
+ warning(
1123
+ `/rules/${escapePointer(category)}`,
1124
+ "unused-rule",
1125
+ "No detector of this policy produces this category, so the rule never applies."
1126
+ );
1127
+ }
1128
+ }
1129
+ const defaultStrategy = explicitDefault ?? REDACT2;
1130
+ const strategies = {};
1131
+ for (const category of categories) {
1132
+ const explicit = explicitRules.get(category) ?? explicitDefault;
1133
+ const inherited = regulations.map(
1134
+ (regulation) => REGULATIONS[regulation].rules.find((rule) => rule.category === category)?.recommended
1135
+ ).find((recommended) => recommended !== void 0);
1136
+ const strategy = explicit ?? inherited ?? REDACT2;
1137
+ Object.defineProperty(strategies, category, { value: strategy, enumerable: true });
1138
+ const path = explicitRules.has(category) ? `/rules/${escapePointer(category)}` : "/defaultStrategy";
1139
+ const traits = describeStrategy(strategy, options.tokenization);
1140
+ for (const regulation of regulations) {
1141
+ const rule = REGULATIONS[regulation].rules.find(
1142
+ (candidate) => candidate.category === category
1143
+ );
1144
+ if (rule === void 0) continue;
1145
+ for (const reason of checkRequirement(traits, rule.requirement)) {
1146
+ error(
1147
+ path,
1148
+ "requirement-violated",
1149
+ `"${strategy.strategy}" is not sufficient for "${category}" under ${REGULATIONS[regulation].name}: ${reason}.`,
1150
+ rule.references[0]
1151
+ );
1152
+ }
1153
+ }
1154
+ if (strategy.strategy === "generalize") {
1155
+ warning(
1156
+ path,
1157
+ "generalize-non-numeric",
1158
+ `"generalize" only shortens numbers; "${category}" values are redacted instead.`
1159
+ );
1160
+ }
1161
+ if (strategy.strategy === "hash" && strategy.pepper === void 0) {
1162
+ warning(
1163
+ path,
1164
+ "unkeyed-hash",
1165
+ "A hash without a pepper can be reversed by enumerating likely values."
1166
+ );
1167
+ }
1168
+ }
1169
+ for (const [category, strategy] of explicitRules) {
1170
+ if (!Object.hasOwn(strategies, category)) {
1171
+ Object.defineProperty(strategies, category, { value: strategy, enumerable: true });
1172
+ }
1173
+ }
1174
+ const seen = /* @__PURE__ */ new Set();
1175
+ const unique = issues.filter((issue) => {
1176
+ const key = `${issue.severity}\0${issue.path}\0${issue.code}\0${issue.message}`;
1177
+ if (seen.has(key)) return false;
1178
+ seen.add(key);
1179
+ return true;
1180
+ });
1181
+ unique.sort((a, b) => Number(a.severity === "warning") - Number(b.severity === "warning"));
1182
+ if (unique.some((issue) => issue.severity === "error")) return { issues: unique };
1183
+ const document = Object.freeze({
1184
+ version: 1,
1185
+ id,
1186
+ ...typeof description === "string" ? { description } : {},
1187
+ ...regulations.length > 0 ? { extends: Object.freeze([...regulations]) } : {},
1188
+ ...include.length > 0 || exclude.length > 0 ? {
1189
+ categories: Object.freeze({
1190
+ ...include.length > 0 ? { include: Object.freeze([...include]) } : {},
1191
+ ...exclude.length > 0 ? { exclude: Object.freeze([...exclude]) } : {}
1192
+ })
1193
+ } : {},
1194
+ ...explicitDefault !== void 0 ? { defaultStrategy: explicitDefault } : {},
1195
+ ...explicitRules.size > 0 ? { rules: Object.freeze(Object.fromEntries(explicitRules)) } : {},
1196
+ ...patterns.length > 0 ? { patterns: Object.freeze(patterns) } : {},
1197
+ ...typeof minConfidence === "number" ? { minConfidence } : {},
1198
+ ...Array.isArray(allow) ? { allow: Object.freeze([...allow]) } : {},
1199
+ ...typeof aggressive === "boolean" ? { aggressive } : {},
1200
+ ...overlap === "cover" || overlap === "legacy" ? { overlap } : {}
1201
+ });
1202
+ return {
1203
+ policy: Object.freeze({
1204
+ id: document.id,
1205
+ regulations: Object.freeze([...regulations]),
1206
+ categories: Object.freeze(categories),
1207
+ strategies: Object.freeze(strategies),
1208
+ defaultStrategy,
1209
+ document,
1210
+ warnings: Object.freeze(unique)
1211
+ }),
1212
+ issues: unique
1213
+ };
1214
+ }
1215
+ function parsePolicy(input, options = {}) {
1216
+ const { policy, issues } = checkPolicy(input, options);
1217
+ if (policy === void 0) throw new PolicyError(issues);
1218
+ return policy;
1219
+ }
1220
+ function policyToSpec(policy) {
1221
+ const { document } = policy;
1222
+ return {
1223
+ categories: policy.categories,
1224
+ defaultStrategy: policy.defaultStrategy,
1225
+ rules: policy.strategies,
1226
+ ...document.patterns !== void 0 ? { patterns: document.patterns } : {},
1227
+ ...document.minConfidence !== void 0 ? { minConfidence: document.minConfidence } : {},
1228
+ ...document.allow !== void 0 ? { allow: document.allow } : {},
1229
+ ...document.aggressive !== void 0 ? { aggressive: document.aggressive } : {},
1230
+ ...document.overlap !== void 0 ? { overlap: document.overlap } : {}
1231
+ };
1232
+ }
1233
+ function regulationPolicy(regulation) {
1234
+ return {
1235
+ version: 1,
1236
+ id: regulation,
1237
+ description: REGULATIONS[regulation].name,
1238
+ extends: [regulation]
1239
+ };
1240
+ }
1241
+
1242
+ export { REGULATIONS, checkPolicy, checkRequirement, complianceMatrix, describeStrategy, getRegulation, isRegulationId, parsePolicy, policyToSpec, regulationPolicy };
1243
+ //# sourceMappingURL=chunk-YMLR375Z.js.map
1244
+ //# sourceMappingURL=chunk-YMLR375Z.js.map