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