pompelmi 0.34.10 → 0.35.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 (112) hide show
  1. package/README.md +26 -15
  2. package/dist/pompelmi.audit.cjs +13 -15
  3. package/dist/pompelmi.audit.cjs.map +1 -1
  4. package/dist/pompelmi.audit.esm.js +13 -15
  5. package/dist/pompelmi.audit.esm.js.map +1 -1
  6. package/dist/pompelmi.browser.cjs +585 -534
  7. package/dist/pompelmi.browser.cjs.map +1 -1
  8. package/dist/pompelmi.browser.esm.js +585 -534
  9. package/dist/pompelmi.browser.esm.js.map +1 -1
  10. package/dist/pompelmi.cjs +2066 -2016
  11. package/dist/pompelmi.cjs.map +1 -1
  12. package/dist/pompelmi.esm.js +2066 -2016
  13. package/dist/pompelmi.esm.js.map +1 -1
  14. package/dist/pompelmi.hooks.cjs +2 -2
  15. package/dist/pompelmi.hooks.cjs.map +1 -1
  16. package/dist/pompelmi.hooks.esm.js +2 -2
  17. package/dist/pompelmi.hooks.esm.js.map +1 -1
  18. package/dist/pompelmi.policy-packs.cjs +74 -73
  19. package/dist/pompelmi.policy-packs.cjs.map +1 -1
  20. package/dist/pompelmi.policy-packs.esm.js +74 -73
  21. package/dist/pompelmi.policy-packs.esm.js.map +1 -1
  22. package/dist/pompelmi.quarantine.cjs +135 -133
  23. package/dist/pompelmi.quarantine.cjs.map +1 -1
  24. package/dist/pompelmi.quarantine.esm.js +135 -133
  25. package/dist/pompelmi.quarantine.esm.js.map +1 -1
  26. package/dist/pompelmi.react.cjs +585 -534
  27. package/dist/pompelmi.react.cjs.map +1 -1
  28. package/dist/pompelmi.react.esm.js +585 -534
  29. package/dist/pompelmi.react.esm.js.map +1 -1
  30. package/dist/types/audit.d.ts +12 -12
  31. package/dist/types/browser-index.d.ts +12 -12
  32. package/dist/types/config.d.ts +4 -4
  33. package/dist/types/engines/dynamic-taint.d.ts +1 -1
  34. package/dist/types/engines/hybrid-orchestrator.d.ts +1 -1
  35. package/dist/types/engines/hybrid-taint-integration.d.ts +6 -6
  36. package/dist/types/engines/taint-policies.d.ts +4 -4
  37. package/dist/types/hipaa-compliance.d.ts +2 -2
  38. package/dist/types/hooks.d.ts +2 -2
  39. package/dist/types/index.d.ts +20 -20
  40. package/dist/types/node/scanDir.d.ts +5 -5
  41. package/dist/types/policy-packs.d.ts +2 -2
  42. package/dist/types/presets.d.ts +3 -3
  43. package/dist/types/quarantine/index.d.ts +3 -3
  44. package/dist/types/quarantine/storage.d.ts +1 -1
  45. package/dist/types/quarantine/types.d.ts +3 -3
  46. package/dist/types/quarantine/workflow.d.ts +4 -4
  47. package/dist/types/react-index.d.ts +2 -2
  48. package/dist/types/risk.d.ts +1 -1
  49. package/dist/types/scan/remote.d.ts +2 -2
  50. package/dist/types/scan.d.ts +5 -5
  51. package/dist/types/scanners/common-heuristics.d.ts +1 -1
  52. package/dist/types/scanners/zip-bomb-guard.d.ts +1 -1
  53. package/dist/types/src/audit.d.ts +84 -0
  54. package/dist/types/src/browser-index.d.ts +29 -0
  55. package/dist/types/src/config.d.ts +143 -0
  56. package/dist/types/src/engines/dynamic-taint.d.ts +102 -0
  57. package/dist/types/src/engines/hybrid-orchestrator.d.ts +65 -0
  58. package/dist/types/src/engines/hybrid-taint-integration.d.ts +129 -0
  59. package/dist/types/src/engines/taint-policies.d.ts +84 -0
  60. package/dist/types/src/hipaa-compliance.d.ts +110 -0
  61. package/dist/types/src/hooks.d.ts +89 -0
  62. package/dist/types/src/index.d.ts +29 -0
  63. package/dist/types/src/magic.d.ts +7 -0
  64. package/dist/types/src/node/scanDir.d.ts +30 -0
  65. package/dist/types/src/policy-packs.d.ts +98 -0
  66. package/dist/types/src/policy.d.ts +12 -0
  67. package/dist/types/src/presets.d.ts +72 -0
  68. package/dist/types/src/quarantine/index.d.ts +18 -0
  69. package/dist/types/src/quarantine/storage.d.ts +77 -0
  70. package/dist/types/src/quarantine/types.d.ts +78 -0
  71. package/dist/types/src/quarantine/workflow.d.ts +97 -0
  72. package/dist/types/src/react-index.d.ts +13 -0
  73. package/dist/types/src/risk.d.ts +18 -0
  74. package/dist/types/src/scan/remote.d.ts +12 -0
  75. package/dist/types/src/scan.d.ts +17 -0
  76. package/dist/types/src/scanners/common-heuristics.d.ts +14 -0
  77. package/dist/types/src/scanners/zip-bomb-guard.d.ts +9 -0
  78. package/dist/types/src/scanners/zipTraversalGuard.d.ts +19 -0
  79. package/dist/types/src/stream.d.ts +10 -0
  80. package/dist/types/src/types/decompilation.d.ts +96 -0
  81. package/dist/types/src/types/taint-tracking.d.ts +495 -0
  82. package/dist/types/src/types.d.ts +48 -0
  83. package/dist/types/src/useFileScanner.d.ts +15 -0
  84. package/dist/types/src/utils/advanced-detection.d.ts +21 -0
  85. package/dist/types/src/utils/batch-scanner.d.ts +62 -0
  86. package/dist/types/src/utils/cache-manager.d.ts +95 -0
  87. package/dist/types/src/utils/export.d.ts +51 -0
  88. package/dist/types/src/utils/performance-metrics.d.ts +68 -0
  89. package/dist/types/src/utils/threat-intelligence.d.ts +96 -0
  90. package/dist/types/src/validate.d.ts +7 -0
  91. package/dist/types/src/verdict.d.ts +2 -0
  92. package/dist/types/src/yara/browser.d.ts +7 -0
  93. package/dist/types/src/yara/index.d.ts +17 -0
  94. package/dist/types/src/yara/node.d.ts +2 -0
  95. package/dist/types/src/yara/remote.d.ts +10 -0
  96. package/dist/types/src/yara-bridge.d.ts +3 -0
  97. package/dist/types/src/zip.d.ts +13 -0
  98. package/dist/types/types/decompilation.d.ts +4 -4
  99. package/dist/types/types/taint-tracking.d.ts +19 -19
  100. package/dist/types/types.d.ts +3 -3
  101. package/dist/types/useFileScanner.d.ts +1 -1
  102. package/dist/types/utils/advanced-detection.d.ts +1 -1
  103. package/dist/types/utils/batch-scanner.d.ts +3 -3
  104. package/dist/types/utils/cache-manager.d.ts +1 -1
  105. package/dist/types/utils/export.d.ts +2 -2
  106. package/dist/types/utils/threat-intelligence.d.ts +4 -4
  107. package/dist/types/verdict.d.ts +1 -1
  108. package/dist/types/yara/browser.d.ts +1 -1
  109. package/dist/types/yara/index.d.ts +1 -1
  110. package/dist/types/yara/node.d.ts +1 -1
  111. package/dist/types/yara/remote.d.ts +2 -2
  112. package/package.json +6 -6
@@ -2,6 +2,132 @@ import * as crypto from 'crypto';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
 
5
+ /**
6
+ * Quarantine storage adapter interface and filesystem reference implementation.
7
+ *
8
+ * The `QuarantineStorage` interface decouples the quarantine workflow from any
9
+ * specific persistence layer. You can implement it for S3, GCS, a database,
10
+ * or any other backend.
11
+ *
12
+ * The built-in `FilesystemQuarantineStorage` stores files and metadata as JSON
13
+ * in a local directory — suitable for development, self-hosted, and on-premise
14
+ * deployments where data must not leave the machine.
15
+ *
16
+ * @module quarantine/storage
17
+ */
18
+ /**
19
+ * Reference implementation of `QuarantineStorage` backed by the local filesystem.
20
+ *
21
+ * File layout:
22
+ * <dir>/files/<storageKey> — raw file bytes
23
+ * <dir>/meta/<id>.json — QuarantineEntry JSON
24
+ *
25
+ * Suitable for single-process servers. For multi-process or distributed
26
+ * deployments, implement `QuarantineStorage` against a shared backend.
27
+ */
28
+ class FilesystemQuarantineStorage {
29
+ constructor(options) {
30
+ this.filesDir = path.join(options.dir, "files");
31
+ this.metaDir = path.join(options.dir, "meta");
32
+ if (options.createIfMissing !== false) {
33
+ fs.mkdirSync(this.filesDir, { recursive: true });
34
+ fs.mkdirSync(this.metaDir, { recursive: true });
35
+ }
36
+ }
37
+ async saveFile(id, bytes) {
38
+ // Use a safe, collision-resistant filename derived from the entry id.
39
+ const storageKey = `${id}-${crypto.randomBytes(4).toString("hex")}`;
40
+ const filePath = path.join(this.filesDir, storageKey);
41
+ await fs.promises.writeFile(filePath, bytes);
42
+ return storageKey;
43
+ }
44
+ async getFile(storageKey) {
45
+ const filePath = path.join(this.filesDir, safeBasename(storageKey));
46
+ try {
47
+ const buf = await fs.promises.readFile(filePath);
48
+ return new Uint8Array(buf);
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ async deleteFile(storageKey) {
55
+ const filePath = path.join(this.filesDir, safeBasename(storageKey));
56
+ await fs.promises.unlink(filePath).catch(() => {
57
+ /* already gone */
58
+ });
59
+ }
60
+ async saveEntry(entry) {
61
+ const metaPath = path.join(this.metaDir, `${safeBasename(entry.id)}.json`);
62
+ await fs.promises.writeFile(metaPath, JSON.stringify(entry, null, 2), "utf8");
63
+ }
64
+ async getEntry(id) {
65
+ const metaPath = path.join(this.metaDir, `${safeBasename(id)}.json`);
66
+ try {
67
+ const raw = await fs.promises.readFile(metaPath, "utf8");
68
+ return JSON.parse(raw);
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ }
74
+ async updateEntry(id, patch) {
75
+ const existing = await this.getEntry(id);
76
+ if (!existing)
77
+ throw new Error(`Quarantine entry not found: ${id}`);
78
+ const updated = { ...existing, ...patch };
79
+ await this.saveEntry(updated);
80
+ return updated;
81
+ }
82
+ async listEntries(filter) {
83
+ const files = await fs.promises.readdir(this.metaDir).catch(() => []);
84
+ const entries = [];
85
+ for (const file of files) {
86
+ if (!file.endsWith(".json"))
87
+ continue;
88
+ try {
89
+ const raw = await fs.promises.readFile(path.join(this.metaDir, file), "utf8");
90
+ entries.push(JSON.parse(raw));
91
+ }
92
+ catch {
93
+ // Skip unreadable entries.
94
+ }
95
+ }
96
+ return applyFilter(entries, filter);
97
+ }
98
+ async countEntries(filter) {
99
+ const entries = await this.listEntries(filter);
100
+ return entries.length;
101
+ }
102
+ }
103
+ // ── Helpers ───────────────────────────────────────────────────────────────────
104
+ /**
105
+ * Strip directory separators to prevent path-traversal attacks when using
106
+ * user-supplied or derived keys as filenames.
107
+ */
108
+ function safeBasename(key) {
109
+ return path.basename(key).replace(/[^a-zA-Z0-9._-]/g, "_");
110
+ }
111
+ function applyFilter(entries, filter) {
112
+ if (!filter)
113
+ return entries;
114
+ let result = entries;
115
+ if (filter.status !== undefined) {
116
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
117
+ result = result.filter((e) => statuses.includes(e.status));
118
+ }
119
+ if (filter.after) {
120
+ result = result.filter((e) => e.quarantinedAt >= filter.after);
121
+ }
122
+ if (filter.before) {
123
+ result = result.filter((e) => e.quarantinedAt <= filter.before);
124
+ }
125
+ if (filter.limit !== undefined) {
126
+ result = result.slice(0, filter.limit);
127
+ }
128
+ return result;
129
+ }
130
+
5
131
  /**
6
132
  * Quarantine workflow — core API for the quarantine/review/resolve lifecycle.
7
133
  *
@@ -45,9 +171,9 @@ class QuarantineManager {
45
171
  * configured policy.
46
172
  */
47
173
  shouldQuarantine(report) {
48
- if (report.verdict === 'malicious')
174
+ if (report.verdict === "malicious")
49
175
  return this.quarantineMalicious;
50
- if (report.verdict === 'suspicious')
176
+ if (report.verdict === "suspicious")
51
177
  return this.quarantineSuspicious;
52
178
  return false;
53
179
  }
@@ -70,7 +196,7 @@ class QuarantineManager {
70
196
  file: { ...fileInfo, sha256 },
71
197
  scanReport: report,
72
198
  quarantinedAt: now,
73
- status: 'pending',
199
+ status: "pending",
74
200
  updatedAt: now,
75
201
  };
76
202
  await this.storage.saveEntry(entry);
@@ -81,7 +207,7 @@ class QuarantineManager {
81
207
  */
82
208
  async startReview(id, reviewedBy) {
83
209
  return this.storage.updateEntry(id, {
84
- status: 'reviewing',
210
+ status: "reviewing",
85
211
  reviewedBy,
86
212
  updatedAt: new Date().toISOString(),
87
213
  });
@@ -97,12 +223,12 @@ class QuarantineManager {
97
223
  const entry = await this.storage.getEntry(id);
98
224
  if (!entry)
99
225
  throw new Error(`Quarantine entry not found: ${id}`);
100
- if (entry.status === 'promoted' || entry.status === 'deleted') {
226
+ if (entry.status === "promoted" || entry.status === "deleted") {
101
227
  throw new Error(`Quarantine entry ${id} is already resolved (${entry.status}).`);
102
228
  }
103
229
  const now = new Date().toISOString();
104
- const newStatus = review.decision === 'promote' ? 'promoted' : 'deleted';
105
- if (review.decision === 'delete') {
230
+ const newStatus = review.decision === "promote" ? "promoted" : "deleted";
231
+ if (review.decision === "delete") {
106
232
  await this.storage.deleteFile(entry.storageKey);
107
233
  }
108
234
  return this.storage.updateEntry(id, {
@@ -132,7 +258,7 @@ class QuarantineManager {
132
258
  return this.storage.listEntries(filter);
133
259
  }
134
260
  listPending() {
135
- return this.storage.listEntries({ status: 'pending' });
261
+ return this.storage.listEntries({ status: "pending" });
136
262
  }
137
263
  countEntries(filter) {
138
264
  return this.storage.countEntries(filter);
@@ -160,131 +286,7 @@ function generateId() {
160
286
  return crypto.randomUUID();
161
287
  }
162
288
  function computeSha256(bytes) {
163
- return crypto.createHash('sha256').update(bytes).digest('hex');
164
- }
165
-
166
- /**
167
- * Quarantine storage adapter interface and filesystem reference implementation.
168
- *
169
- * The `QuarantineStorage` interface decouples the quarantine workflow from any
170
- * specific persistence layer. You can implement it for S3, GCS, a database,
171
- * or any other backend.
172
- *
173
- * The built-in `FilesystemQuarantineStorage` stores files and metadata as JSON
174
- * in a local directory — suitable for development, self-hosted, and on-premise
175
- * deployments where data must not leave the machine.
176
- *
177
- * @module quarantine/storage
178
- */
179
- /**
180
- * Reference implementation of `QuarantineStorage` backed by the local filesystem.
181
- *
182
- * File layout:
183
- * <dir>/files/<storageKey> — raw file bytes
184
- * <dir>/meta/<id>.json — QuarantineEntry JSON
185
- *
186
- * Suitable for single-process servers. For multi-process or distributed
187
- * deployments, implement `QuarantineStorage` against a shared backend.
188
- */
189
- class FilesystemQuarantineStorage {
190
- constructor(options) {
191
- this.filesDir = path.join(options.dir, 'files');
192
- this.metaDir = path.join(options.dir, 'meta');
193
- if (options.createIfMissing !== false) {
194
- fs.mkdirSync(this.filesDir, { recursive: true });
195
- fs.mkdirSync(this.metaDir, { recursive: true });
196
- }
197
- }
198
- async saveFile(id, bytes) {
199
- // Use a safe, collision-resistant filename derived from the entry id.
200
- const storageKey = `${id}-${crypto.randomBytes(4).toString('hex')}`;
201
- const filePath = path.join(this.filesDir, storageKey);
202
- await fs.promises.writeFile(filePath, bytes);
203
- return storageKey;
204
- }
205
- async getFile(storageKey) {
206
- const filePath = path.join(this.filesDir, safeBasename(storageKey));
207
- try {
208
- const buf = await fs.promises.readFile(filePath);
209
- return new Uint8Array(buf);
210
- }
211
- catch {
212
- return null;
213
- }
214
- }
215
- async deleteFile(storageKey) {
216
- const filePath = path.join(this.filesDir, safeBasename(storageKey));
217
- await fs.promises.unlink(filePath).catch(() => { });
218
- }
219
- async saveEntry(entry) {
220
- const metaPath = path.join(this.metaDir, `${safeBasename(entry.id)}.json`);
221
- await fs.promises.writeFile(metaPath, JSON.stringify(entry, null, 2), 'utf8');
222
- }
223
- async getEntry(id) {
224
- const metaPath = path.join(this.metaDir, `${safeBasename(id)}.json`);
225
- try {
226
- const raw = await fs.promises.readFile(metaPath, 'utf8');
227
- return JSON.parse(raw);
228
- }
229
- catch {
230
- return null;
231
- }
232
- }
233
- async updateEntry(id, patch) {
234
- const existing = await this.getEntry(id);
235
- if (!existing)
236
- throw new Error(`Quarantine entry not found: ${id}`);
237
- const updated = { ...existing, ...patch };
238
- await this.saveEntry(updated);
239
- return updated;
240
- }
241
- async listEntries(filter) {
242
- const files = await fs.promises.readdir(this.metaDir).catch(() => []);
243
- const entries = [];
244
- for (const file of files) {
245
- if (!file.endsWith('.json'))
246
- continue;
247
- try {
248
- const raw = await fs.promises.readFile(path.join(this.metaDir, file), 'utf8');
249
- entries.push(JSON.parse(raw));
250
- }
251
- catch {
252
- // Skip unreadable entries.
253
- }
254
- }
255
- return applyFilter(entries, filter);
256
- }
257
- async countEntries(filter) {
258
- const entries = await this.listEntries(filter);
259
- return entries.length;
260
- }
261
- }
262
- // ── Helpers ───────────────────────────────────────────────────────────────────
263
- /**
264
- * Strip directory separators to prevent path-traversal attacks when using
265
- * user-supplied or derived keys as filenames.
266
- */
267
- function safeBasename(key) {
268
- return path.basename(key).replace(/[^a-zA-Z0-9._-]/g, '_');
269
- }
270
- function applyFilter(entries, filter) {
271
- if (!filter)
272
- return entries;
273
- let result = entries;
274
- if (filter.status !== undefined) {
275
- const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
276
- result = result.filter((e) => statuses.includes(e.status));
277
- }
278
- if (filter.after) {
279
- result = result.filter((e) => e.quarantinedAt >= filter.after);
280
- }
281
- if (filter.before) {
282
- result = result.filter((e) => e.quarantinedAt <= filter.before);
283
- }
284
- if (filter.limit !== undefined) {
285
- result = result.slice(0, filter.limit);
286
- }
287
- return result;
289
+ return crypto.createHash("sha256").update(bytes).digest("hex");
288
290
  }
289
291
 
290
292
  export { FilesystemQuarantineStorage, QuarantineManager };
@@ -1 +1 @@
1
- {"version":3,"file":"pompelmi.quarantine.esm.js","sources":["../src/quarantine/workflow.ts","../src/quarantine/storage.ts"],"sourcesContent":["/**\n * Quarantine workflow — core API for the quarantine/review/resolve lifecycle.\n *\n * Usage (Node.js):\n *\n * ```ts\n * import { scanBytes } from 'pompelmi';\n * import { QuarantineManager, FilesystemQuarantineStorage } from 'pompelmi/quarantine';\n *\n * const quarantine = new QuarantineManager({\n * storage: new FilesystemQuarantineStorage({ dir: './quarantine' }),\n * });\n *\n * const report = await scanBytes(fileBytes, { ctx: { filename: file.name } });\n *\n * if (report.verdict !== 'clean') {\n * const entry = await quarantine.quarantine(fileBytes, report, {\n * originalName: file.name,\n * sizeBytes: fileBytes.length,\n * uploadedBy: req.user?.id,\n * });\n * console.log('Quarantined:', entry.id);\n * }\n * ```\n *\n * @module quarantine/workflow\n */\n\nimport * as crypto from 'crypto';\nimport type { ScanReport } from '../types';\nimport type {\n QuarantineEntry,\n QuarantineFilter,\n QuarantineReport,\n QuarantineReview,\n QuarantineStatus,\n QuarantinedFileInfo,\n} from './types';\nimport type { QuarantineStorage } from './storage';\n\n// ── Options ───────────────────────────────────────────────────────────────────\n\nexport interface QuarantineManagerOptions {\n /** Storage adapter — use `FilesystemQuarantineStorage` for local deployments. */\n storage: QuarantineStorage;\n\n /**\n * If true, files with a 'suspicious' verdict are also quarantined.\n * Default: true.\n */\n quarantineSuspicious?: boolean;\n\n /**\n * If true, files with a 'malicious' verdict are also quarantined.\n * Default: true.\n */\n quarantineMalicious?: boolean;\n}\n\n// ── Manager ───────────────────────────────────────────────────────────────────\n\n/**\n * Manages the full lifecycle of quarantined files:\n * scan → quarantine → review → promote | delete\n */\nexport class QuarantineManager {\n private readonly storage: QuarantineStorage;\n private readonly quarantineSuspicious: boolean;\n private readonly quarantineMalicious: boolean;\n\n constructor(options: QuarantineManagerOptions) {\n this.storage = options.storage;\n this.quarantineSuspicious = options.quarantineSuspicious ?? true;\n this.quarantineMalicious = options.quarantineMalicious ?? true;\n }\n\n /**\n * Determine whether a scan report should trigger quarantine per the\n * configured policy.\n */\n shouldQuarantine(report: ScanReport): boolean {\n if (report.verdict === 'malicious') return this.quarantineMalicious;\n if (report.verdict === 'suspicious') return this.quarantineSuspicious;\n return false;\n }\n\n /**\n * Quarantine a file: save the bytes in storage, create the metadata entry,\n * and return the entry.\n *\n * @param bytes Raw file bytes.\n * @param report The scan report that triggered quarantine.\n * @param fileInfo Partial metadata; `sha256` is derived from `bytes` if omitted.\n */\n async quarantine(\n bytes: Uint8Array,\n report: ScanReport,\n fileInfo: Omit<QuarantinedFileInfo, 'sha256'> & { sha256?: string },\n ): Promise<QuarantineEntry> {\n const id = generateId();\n const sha256 = fileInfo.sha256 ?? computeSha256(bytes);\n const now = new Date().toISOString();\n\n const storageKey = await this.storage.saveFile(id, bytes);\n\n const entry: QuarantineEntry = {\n id,\n storageKey,\n file: { ...fileInfo, sha256 },\n scanReport: report,\n quarantinedAt: now,\n status: 'pending',\n updatedAt: now,\n };\n\n await this.storage.saveEntry(entry);\n return entry;\n }\n\n /**\n * Mark an entry as being actively reviewed.\n */\n async startReview(id: string, reviewedBy?: string): Promise<QuarantineEntry> {\n return this.storage.updateEntry(id, {\n status: 'reviewing',\n reviewedBy,\n updatedAt: new Date().toISOString(),\n });\n }\n\n /**\n * Resolve a quarantine entry with a final decision.\n *\n * - `promote`: the file is cleared — bytes remain in storage for the caller\n * to move to its final destination.\n * - `delete`: the bytes are permanently removed from quarantine storage.\n */\n async resolve(id: string, review: QuarantineReview): Promise<QuarantineEntry> {\n const entry = await this.storage.getEntry(id);\n if (!entry) throw new Error(`Quarantine entry not found: ${id}`);\n if (entry.status === 'promoted' || entry.status === 'deleted') {\n throw new Error(`Quarantine entry ${id} is already resolved (${entry.status}).`);\n }\n\n const now = new Date().toISOString();\n const newStatus: QuarantineStatus = review.decision === 'promote' ? 'promoted' : 'deleted';\n\n if (review.decision === 'delete') {\n await this.storage.deleteFile(entry.storageKey);\n }\n\n return this.storage.updateEntry(id, {\n status: newStatus,\n reviewedBy: review.reviewedBy,\n reviewNote: review.reviewNote,\n resolvedAt: now,\n updatedAt: now,\n });\n }\n\n /**\n * Retrieve the raw bytes of a promoted file so the caller can move it to\n * permanent storage. Returns `null` if the entry is not found or has been\n * deleted.\n */\n async getFile(id: string): Promise<Uint8Array | null> {\n const entry = await this.storage.getEntry(id);\n if (!entry) return null;\n return this.storage.getFile(entry.storageKey);\n }\n\n // ── Query helpers ───────────────────────────────────────────────────────────\n\n getEntry(id: string): Promise<QuarantineEntry | null> {\n return this.storage.getEntry(id);\n }\n\n listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]> {\n return this.storage.listEntries(filter);\n }\n\n listPending(): Promise<QuarantineEntry[]> {\n return this.storage.listEntries({ status: 'pending' });\n }\n\n countEntries(filter?: QuarantineFilter): Promise<number> {\n return this.storage.countEntries(filter);\n }\n\n // ── Reporting ───────────────────────────────────────────────────────────────\n\n /**\n * Generate a structured JSON report of all quarantine entries matching the\n * filter — suitable for audit logs and dashboards.\n */\n async report(filter?: QuarantineFilter): Promise<QuarantineReport> {\n const entries = await this.storage.listEntries(filter);\n const byStatus = { pending: 0, reviewing: 0, promoted: 0, deleted: 0 };\n for (const e of entries) byStatus[e.status]++;\n return {\n generatedAt: new Date().toISOString(),\n totalEntries: entries.length,\n byStatus,\n entries,\n };\n }\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\nfunction generateId(): string {\n return crypto.randomUUID();\n}\n\nfunction computeSha256(bytes: Uint8Array): string {\n return crypto.createHash('sha256').update(bytes).digest('hex');\n}\n","/**\n * Quarantine storage adapter interface and filesystem reference implementation.\n *\n * The `QuarantineStorage` interface decouples the quarantine workflow from any\n * specific persistence layer. You can implement it for S3, GCS, a database,\n * or any other backend.\n *\n * The built-in `FilesystemQuarantineStorage` stores files and metadata as JSON\n * in a local directory — suitable for development, self-hosted, and on-premise\n * deployments where data must not leave the machine.\n *\n * @module quarantine/storage\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as crypto from 'crypto';\nimport type { QuarantineEntry, QuarantineFilter } from './types';\n\n// ── Adapter interface ─────────────────────────────────────────────────────────\n\n/**\n * Storage adapter for the quarantine workflow.\n * Implement this interface to support any backend (S3, GCS, DB, etc.).\n */\nexport interface QuarantineStorage {\n /**\n * Persist the raw bytes of a quarantined file.\n * Returns a `storageKey` that can later be used to retrieve or delete the bytes.\n */\n saveFile(id: string, bytes: Uint8Array): Promise<string>;\n\n /**\n * Retrieve the raw bytes of a quarantined file.\n * Returns `null` if the file is not found.\n */\n getFile(storageKey: string): Promise<Uint8Array | null>;\n\n /**\n * Permanently remove the raw bytes of a quarantined file.\n * No-op if already removed.\n */\n deleteFile(storageKey: string): Promise<void>;\n\n /** Persist a quarantine entry (metadata + scan report). */\n saveEntry(entry: QuarantineEntry): Promise<void>;\n\n /** Load a quarantine entry by id. Returns `null` if not found. */\n getEntry(id: string): Promise<QuarantineEntry | null>;\n\n /** Update an existing quarantine entry (partial update). */\n updateEntry(id: string, patch: Partial<QuarantineEntry>): Promise<QuarantineEntry>;\n\n /** List quarantine entries matching the given filter. */\n listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]>;\n\n /** Return the total count of quarantine entries matching the filter. */\n countEntries(filter?: QuarantineFilter): Promise<number>;\n}\n\n// ── Filesystem implementation ─────────────────────────────────────────────────\n\nexport interface FilesystemQuarantineStorageOptions {\n /**\n * Root directory for quarantine storage.\n * Two subdirectories are created: `files/` (raw bytes) and `meta/` (JSON).\n */\n dir: string;\n /** Create the directory if it does not exist (default: true). */\n createIfMissing?: boolean;\n}\n\n/**\n * Reference implementation of `QuarantineStorage` backed by the local filesystem.\n *\n * File layout:\n * <dir>/files/<storageKey> — raw file bytes\n * <dir>/meta/<id>.json — QuarantineEntry JSON\n *\n * Suitable for single-process servers. For multi-process or distributed\n * deployments, implement `QuarantineStorage` against a shared backend.\n */\nexport class FilesystemQuarantineStorage implements QuarantineStorage {\n private readonly filesDir: string;\n private readonly metaDir: string;\n\n constructor(options: FilesystemQuarantineStorageOptions) {\n this.filesDir = path.join(options.dir, 'files');\n this.metaDir = path.join(options.dir, 'meta');\n if (options.createIfMissing !== false) {\n fs.mkdirSync(this.filesDir, { recursive: true });\n fs.mkdirSync(this.metaDir, { recursive: true });\n }\n }\n\n async saveFile(id: string, bytes: Uint8Array): Promise<string> {\n // Use a safe, collision-resistant filename derived from the entry id.\n const storageKey = `${id}-${crypto.randomBytes(4).toString('hex')}`;\n const filePath = path.join(this.filesDir, storageKey);\n await fs.promises.writeFile(filePath, bytes);\n return storageKey;\n }\n\n async getFile(storageKey: string): Promise<Uint8Array | null> {\n const filePath = path.join(this.filesDir, safeBasename(storageKey));\n try {\n const buf = await fs.promises.readFile(filePath);\n return new Uint8Array(buf);\n } catch {\n return null;\n }\n }\n\n async deleteFile(storageKey: string): Promise<void> {\n const filePath = path.join(this.filesDir, safeBasename(storageKey));\n await fs.promises.unlink(filePath).catch(() => {/* already gone */});\n }\n\n async saveEntry(entry: QuarantineEntry): Promise<void> {\n const metaPath = path.join(this.metaDir, `${safeBasename(entry.id)}.json`);\n await fs.promises.writeFile(metaPath, JSON.stringify(entry, null, 2), 'utf8');\n }\n\n async getEntry(id: string): Promise<QuarantineEntry | null> {\n const metaPath = path.join(this.metaDir, `${safeBasename(id)}.json`);\n try {\n const raw = await fs.promises.readFile(metaPath, 'utf8');\n return JSON.parse(raw) as QuarantineEntry;\n } catch {\n return null;\n }\n }\n\n async updateEntry(id: string, patch: Partial<QuarantineEntry>): Promise<QuarantineEntry> {\n const existing = await this.getEntry(id);\n if (!existing) throw new Error(`Quarantine entry not found: ${id}`);\n const updated: QuarantineEntry = { ...existing, ...patch };\n await this.saveEntry(updated);\n return updated;\n }\n\n async listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]> {\n const files = await fs.promises.readdir(this.metaDir).catch(() => [] as string[]);\n const entries: QuarantineEntry[] = [];\n\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n try {\n const raw = await fs.promises.readFile(path.join(this.metaDir, file), 'utf8');\n entries.push(JSON.parse(raw) as QuarantineEntry);\n } catch {\n // Skip unreadable entries.\n }\n }\n\n return applyFilter(entries, filter);\n }\n\n async countEntries(filter?: QuarantineFilter): Promise<number> {\n const entries = await this.listEntries(filter);\n return entries.length;\n }\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\n/**\n * Strip directory separators to prevent path-traversal attacks when using\n * user-supplied or derived keys as filenames.\n */\nfunction safeBasename(key: string): string {\n return path.basename(key).replace(/[^a-zA-Z0-9._-]/g, '_');\n}\n\nfunction applyFilter(entries: QuarantineEntry[], filter?: QuarantineFilter): QuarantineEntry[] {\n if (!filter) return entries;\n\n let result = entries;\n\n if (filter.status !== undefined) {\n const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];\n result = result.filter((e) => statuses.includes(e.status));\n }\n if (filter.after) {\n result = result.filter((e) => e.quarantinedAt >= filter.after!);\n }\n if (filter.before) {\n result = result.filter((e) => e.quarantinedAt <= filter.before!);\n }\n if (filter.limit !== undefined) {\n result = result.slice(0, filter.limit);\n }\n\n return result;\n}\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AAiCH;AAEA;;;AAGG;MACU,iBAAiB,CAAA;AAK5B,IAAA,WAAA,CAAY,OAAiC,EAAA;AAC3C,QAAA,I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Q,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;AAC5D;AAEA,SAAS,WAAW,CAAC,OAA0B,EAAE,MAAyB,EAAA;AACxE,IAAA,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,OAAO;IAE3B,IAAI,MAAM,GAAG,OAAO;AAEpB,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAC/B,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;AAC/E,QAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5D;AACA,IAAA,IAAI,MAAM,CAAC,KAAK,EAAE;AAChB,QAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,KAAM,CAAC;IACjE;AACA,IAAA,IAAI,MAAM,CAAC,MAAM,EAAE;AACjB,QAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,MAAO,CAAC;IAClE;AACA,IAAA,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;QAC9B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC;IACxC;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
1
+ {"version":3,"file":"pompelmi.quarantine.esm.js","sources":["../../src/quarantine/storage.ts","../../src/quarantine/workflow.ts"],"sourcesContent":["/**\n * Quarantine storage adapter interface and filesystem reference implementation.\n *\n * The `QuarantineStorage` interface decouples the quarantine workflow from any\n * specific persistence layer. You can implement it for S3, GCS, a database,\n * or any other backend.\n *\n * The built-in `FilesystemQuarantineStorage` stores files and metadata as JSON\n * in a local directory — suitable for development, self-hosted, and on-premise\n * deployments where data must not leave the machine.\n *\n * @module quarantine/storage\n */\n\nimport * as crypto from \"crypto\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport type { QuarantineEntry, QuarantineFilter } from \"./types\";\n\n// ── Adapter interface ─────────────────────────────────────────────────────────\n\n/**\n * Storage adapter for the quarantine workflow.\n * Implement this interface to support any backend (S3, GCS, DB, etc.).\n */\nexport interface QuarantineStorage {\n /**\n * Persist the raw bytes of a quarantined file.\n * Returns a `storageKey` that can later be used to retrieve or delete the bytes.\n */\n saveFile(id: string, bytes: Uint8Array): Promise<string>;\n\n /**\n * Retrieve the raw bytes of a quarantined file.\n * Returns `null` if the file is not found.\n */\n getFile(storageKey: string): Promise<Uint8Array | null>;\n\n /**\n * Permanently remove the raw bytes of a quarantined file.\n * No-op if already removed.\n */\n deleteFile(storageKey: string): Promise<void>;\n\n /** Persist a quarantine entry (metadata + scan report). */\n saveEntry(entry: QuarantineEntry): Promise<void>;\n\n /** Load a quarantine entry by id. Returns `null` if not found. */\n getEntry(id: string): Promise<QuarantineEntry | null>;\n\n /** Update an existing quarantine entry (partial update). */\n updateEntry(id: string, patch: Partial<QuarantineEntry>): Promise<QuarantineEntry>;\n\n /** List quarantine entries matching the given filter. */\n listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]>;\n\n /** Return the total count of quarantine entries matching the filter. */\n countEntries(filter?: QuarantineFilter): Promise<number>;\n}\n\n// ── Filesystem implementation ─────────────────────────────────────────────────\n\nexport interface FilesystemQuarantineStorageOptions {\n /**\n * Root directory for quarantine storage.\n * Two subdirectories are created: `files/` (raw bytes) and `meta/` (JSON).\n */\n dir: string;\n /** Create the directory if it does not exist (default: true). */\n createIfMissing?: boolean;\n}\n\n/**\n * Reference implementation of `QuarantineStorage` backed by the local filesystem.\n *\n * File layout:\n * <dir>/files/<storageKey> — raw file bytes\n * <dir>/meta/<id>.json — QuarantineEntry JSON\n *\n * Suitable for single-process servers. For multi-process or distributed\n * deployments, implement `QuarantineStorage` against a shared backend.\n */\nexport class FilesystemQuarantineStorage implements QuarantineStorage {\n private readonly filesDir: string;\n private readonly metaDir: string;\n\n constructor(options: FilesystemQuarantineStorageOptions) {\n this.filesDir = path.join(options.dir, \"files\");\n this.metaDir = path.join(options.dir, \"meta\");\n if (options.createIfMissing !== false) {\n fs.mkdirSync(this.filesDir, { recursive: true });\n fs.mkdirSync(this.metaDir, { recursive: true });\n }\n }\n\n async saveFile(id: string, bytes: Uint8Array): Promise<string> {\n // Use a safe, collision-resistant filename derived from the entry id.\n const storageKey = `${id}-${crypto.randomBytes(4).toString(\"hex\")}`;\n const filePath = path.join(this.filesDir, storageKey);\n await fs.promises.writeFile(filePath, bytes);\n return storageKey;\n }\n\n async getFile(storageKey: string): Promise<Uint8Array | null> {\n const filePath = path.join(this.filesDir, safeBasename(storageKey));\n try {\n const buf = await fs.promises.readFile(filePath);\n return new Uint8Array(buf);\n } catch {\n return null;\n }\n }\n\n async deleteFile(storageKey: string): Promise<void> {\n const filePath = path.join(this.filesDir, safeBasename(storageKey));\n await fs.promises.unlink(filePath).catch(() => {\n /* already gone */\n });\n }\n\n async saveEntry(entry: QuarantineEntry): Promise<void> {\n const metaPath = path.join(this.metaDir, `${safeBasename(entry.id)}.json`);\n await fs.promises.writeFile(metaPath, JSON.stringify(entry, null, 2), \"utf8\");\n }\n\n async getEntry(id: string): Promise<QuarantineEntry | null> {\n const metaPath = path.join(this.metaDir, `${safeBasename(id)}.json`);\n try {\n const raw = await fs.promises.readFile(metaPath, \"utf8\");\n return JSON.parse(raw) as QuarantineEntry;\n } catch {\n return null;\n }\n }\n\n async updateEntry(id: string, patch: Partial<QuarantineEntry>): Promise<QuarantineEntry> {\n const existing = await this.getEntry(id);\n if (!existing) throw new Error(`Quarantine entry not found: ${id}`);\n const updated: QuarantineEntry = { ...existing, ...patch };\n await this.saveEntry(updated);\n return updated;\n }\n\n async listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]> {\n const files = await fs.promises.readdir(this.metaDir).catch(() => [] as string[]);\n const entries: QuarantineEntry[] = [];\n\n for (const file of files) {\n if (!file.endsWith(\".json\")) continue;\n try {\n const raw = await fs.promises.readFile(path.join(this.metaDir, file), \"utf8\");\n entries.push(JSON.parse(raw) as QuarantineEntry);\n } catch {\n // Skip unreadable entries.\n }\n }\n\n return applyFilter(entries, filter);\n }\n\n async countEntries(filter?: QuarantineFilter): Promise<number> {\n const entries = await this.listEntries(filter);\n return entries.length;\n }\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\n/**\n * Strip directory separators to prevent path-traversal attacks when using\n * user-supplied or derived keys as filenames.\n */\nfunction safeBasename(key: string): string {\n return path.basename(key).replace(/[^a-zA-Z0-9._-]/g, \"_\");\n}\n\nfunction applyFilter(entries: QuarantineEntry[], filter?: QuarantineFilter): QuarantineEntry[] {\n if (!filter) return entries;\n\n let result = entries;\n\n if (filter.status !== undefined) {\n const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];\n result = result.filter((e) => statuses.includes(e.status));\n }\n if (filter.after) {\n result = result.filter((e) => e.quarantinedAt >= filter.after!);\n }\n if (filter.before) {\n result = result.filter((e) => e.quarantinedAt <= filter.before!);\n }\n if (filter.limit !== undefined) {\n result = result.slice(0, filter.limit);\n }\n\n return result;\n}\n","/**\n * Quarantine workflow — core API for the quarantine/review/resolve lifecycle.\n *\n * Usage (Node.js):\n *\n * ```ts\n * import { scanBytes } from 'pompelmi';\n * import { QuarantineManager, FilesystemQuarantineStorage } from 'pompelmi/quarantine';\n *\n * const quarantine = new QuarantineManager({\n * storage: new FilesystemQuarantineStorage({ dir: './quarantine' }),\n * });\n *\n * const report = await scanBytes(fileBytes, { ctx: { filename: file.name } });\n *\n * if (report.verdict !== 'clean') {\n * const entry = await quarantine.quarantine(fileBytes, report, {\n * originalName: file.name,\n * sizeBytes: fileBytes.length,\n * uploadedBy: req.user?.id,\n * });\n * console.log('Quarantined:', entry.id);\n * }\n * ```\n *\n * @module quarantine/workflow\n */\n\nimport * as crypto from \"crypto\";\nimport type { ScanReport } from \"../types\";\nimport type { QuarantineStorage } from \"./storage\";\nimport type {\n QuarantinedFileInfo,\n QuarantineEntry,\n QuarantineFilter,\n QuarantineReport,\n QuarantineReview,\n QuarantineStatus,\n} from \"./types\";\n\n// ── Options ───────────────────────────────────────────────────────────────────\n\nexport interface QuarantineManagerOptions {\n /** Storage adapter — use `FilesystemQuarantineStorage` for local deployments. */\n storage: QuarantineStorage;\n\n /**\n * If true, files with a 'suspicious' verdict are also quarantined.\n * Default: true.\n */\n quarantineSuspicious?: boolean;\n\n /**\n * If true, files with a 'malicious' verdict are also quarantined.\n * Default: true.\n */\n quarantineMalicious?: boolean;\n}\n\n// ── Manager ───────────────────────────────────────────────────────────────────\n\n/**\n * Manages the full lifecycle of quarantined files:\n * scan → quarantine → review → promote | delete\n */\nexport class QuarantineManager {\n private readonly storage: QuarantineStorage;\n private readonly quarantineSuspicious: boolean;\n private readonly quarantineMalicious: boolean;\n\n constructor(options: QuarantineManagerOptions) {\n this.storage = options.storage;\n this.quarantineSuspicious = options.quarantineSuspicious ?? true;\n this.quarantineMalicious = options.quarantineMalicious ?? true;\n }\n\n /**\n * Determine whether a scan report should trigger quarantine per the\n * configured policy.\n */\n shouldQuarantine(report: ScanReport): boolean {\n if (report.verdict === \"malicious\") return this.quarantineMalicious;\n if (report.verdict === \"suspicious\") return this.quarantineSuspicious;\n return false;\n }\n\n /**\n * Quarantine a file: save the bytes in storage, create the metadata entry,\n * and return the entry.\n *\n * @param bytes Raw file bytes.\n * @param report The scan report that triggered quarantine.\n * @param fileInfo Partial metadata; `sha256` is derived from `bytes` if omitted.\n */\n async quarantine(\n bytes: Uint8Array,\n report: ScanReport,\n fileInfo: Omit<QuarantinedFileInfo, \"sha256\"> & { sha256?: string },\n ): Promise<QuarantineEntry> {\n const id = generateId();\n const sha256 = fileInfo.sha256 ?? computeSha256(bytes);\n const now = new Date().toISOString();\n\n const storageKey = await this.storage.saveFile(id, bytes);\n\n const entry: QuarantineEntry = {\n id,\n storageKey,\n file: { ...fileInfo, sha256 },\n scanReport: report,\n quarantinedAt: now,\n status: \"pending\",\n updatedAt: now,\n };\n\n await this.storage.saveEntry(entry);\n return entry;\n }\n\n /**\n * Mark an entry as being actively reviewed.\n */\n async startReview(id: string, reviewedBy?: string): Promise<QuarantineEntry> {\n return this.storage.updateEntry(id, {\n status: \"reviewing\",\n reviewedBy,\n updatedAt: new Date().toISOString(),\n });\n }\n\n /**\n * Resolve a quarantine entry with a final decision.\n *\n * - `promote`: the file is cleared — bytes remain in storage for the caller\n * to move to its final destination.\n * - `delete`: the bytes are permanently removed from quarantine storage.\n */\n async resolve(id: string, review: QuarantineReview): Promise<QuarantineEntry> {\n const entry = await this.storage.getEntry(id);\n if (!entry) throw new Error(`Quarantine entry not found: ${id}`);\n if (entry.status === \"promoted\" || entry.status === \"deleted\") {\n throw new Error(`Quarantine entry ${id} is already resolved (${entry.status}).`);\n }\n\n const now = new Date().toISOString();\n const newStatus: QuarantineStatus = review.decision === \"promote\" ? \"promoted\" : \"deleted\";\n\n if (review.decision === \"delete\") {\n await this.storage.deleteFile(entry.storageKey);\n }\n\n return this.storage.updateEntry(id, {\n status: newStatus,\n reviewedBy: review.reviewedBy,\n reviewNote: review.reviewNote,\n resolvedAt: now,\n updatedAt: now,\n });\n }\n\n /**\n * Retrieve the raw bytes of a promoted file so the caller can move it to\n * permanent storage. Returns `null` if the entry is not found or has been\n * deleted.\n */\n async getFile(id: string): Promise<Uint8Array | null> {\n const entry = await this.storage.getEntry(id);\n if (!entry) return null;\n return this.storage.getFile(entry.storageKey);\n }\n\n // ── Query helpers ───────────────────────────────────────────────────────────\n\n getEntry(id: string): Promise<QuarantineEntry | null> {\n return this.storage.getEntry(id);\n }\n\n listEntries(filter?: QuarantineFilter): Promise<QuarantineEntry[]> {\n return this.storage.listEntries(filter);\n }\n\n listPending(): Promise<QuarantineEntry[]> {\n return this.storage.listEntries({ status: \"pending\" });\n }\n\n countEntries(filter?: QuarantineFilter): Promise<number> {\n return this.storage.countEntries(filter);\n }\n\n // ── Reporting ───────────────────────────────────────────────────────────────\n\n /**\n * Generate a structured JSON report of all quarantine entries matching the\n * filter — suitable for audit logs and dashboards.\n */\n async report(filter?: QuarantineFilter): Promise<QuarantineReport> {\n const entries = await this.storage.listEntries(filter);\n const byStatus = { pending: 0, reviewing: 0, promoted: 0, deleted: 0 };\n for (const e of entries) byStatus[e.status]++;\n return {\n generatedAt: new Date().toISOString(),\n totalEntries: entries.length,\n byStatus,\n entries,\n };\n }\n}\n\n// ── Helpers ───────────────────────────────────────────────────────────────────\n\nfunction generateId(): string {\n return crypto.randomUUID();\n}\n\nfunction computeSha256(bytes: Uint8Array): string {\n return crypto.createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;AAYG;AA4DH;;;;;;;;;AASG;MACU,2BAA2B,CAAA;AAItC,IAAA,WAAA,CAAY,OAA2C,EAAA;AACrD,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;AAC/C,QAAA,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC;AAC7C,QAAA,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE;AACrC,YAAA,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAChD,YAAA,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QACjD;IACF;AAEA,IAAA,MAAM,QAAQ,CAAC,EAAU,EAAE,KAAiB,EAAA;;AAE1C,QAAA,MAAM,UAAU,GAAG,CAAA,EA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