* Mask many texts in a single anonymizer pass, the batched counterpart to * anonymize. Each item carries its own detected spans; callers must omit * items with no spans (those texts pass through unchanged). Returns masked text * per item, in order. Throws on failure.
(items: AnonymizeBatchItem[])
| 108 | * per item, in order. Throws on failure. |
| 109 | */ |
| 110 | async function anonymizeBatch(items: AnonymizeBatchItem[]): Promise<string[]> { |
| 111 | if (items.length === 0) return [] |
| 112 | |
| 113 | // boundary-raw-fetch: internal call to the Presidio anonymizer service via PII_URL |
| 114 | const response = await fetch(`${PII_URL}/anonymize_batch`, { |
| 115 | method: 'POST', |
| 116 | headers: { 'content-type': 'application/json' }, |
| 117 | body: JSON.stringify({ items }), |
| 118 | }) |
| 119 | if (!response.ok) { |
| 120 | const detail = await response.text().catch(() => '') |
| 121 | throw new Error(`Presidio anonymize failed (${response.status}): ${detail.slice(0, 200)}`) |
| 122 | } |
| 123 | const data = (await response.json()) as { texts: string[] } |
| 124 | return data.texts |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Mask spans via the Presidio anonymizer service. Omitting `anonymizers` uses the |