* Detect PII spans for many texts in a single analyzer pass (spaCy `nlp.pipe`), * the batched counterpart to analyze. Returns one span array per input, * in order. An empty `entityTypes` ⇒ detect all. Throws on transport/HTTP failure.
( texts: string[], entityTypes: string[], language: string )
| 77 | * in order. An empty `entityTypes` ⇒ detect all. Throws on transport/HTTP failure. |
| 78 | */ |
| 79 | async function analyzeBatch( |
| 80 | texts: string[], |
| 81 | entityTypes: string[], |
| 82 | language: string |
| 83 | ): Promise<AnalyzerSpan[][]> { |
| 84 | const entities = entityTypes.length > 0 ? entityTypes : undefined |
| 85 | |
| 86 | // boundary-raw-fetch: internal call to the Presidio analyzer service via PII_URL |
| 87 | const response = await fetch(`${PII_URL}/analyze_batch`, { |
| 88 | method: 'POST', |
| 89 | headers: { 'content-type': 'application/json' }, |
| 90 | body: JSON.stringify({ texts, language, ...(entities ? { entities } : {}) }), |
| 91 | }) |
| 92 | if (!response.ok) { |
| 93 | const detail = await response.text().catch(() => '') |
| 94 | throw new Error(`Presidio analyze failed (${response.status}): ${detail.slice(0, 200)}`) |
| 95 | } |
| 96 | return (await response.json()) as AnalyzerSpan[][] |
| 97 | } |
| 98 | |
| 99 | interface AnonymizeBatchItem { |
| 100 | text: string |