* Mask spans via the Presidio anonymizer service. Omitting `anonymizers` uses the * default `replace` operator, which yields ` `. Throws on failure.
(text: string, spans: AnalyzerSpan[])
| 129 | * default `replace` operator, which yields `<ENTITY_TYPE>`. Throws on failure. |
| 130 | */ |
| 131 | async function anonymize(text: string, spans: AnalyzerSpan[]): Promise<string> { |
| 132 | if (spans.length === 0) return text |
| 133 | |
| 134 | // boundary-raw-fetch: internal call to the Presidio anonymizer service via PII_URL |
| 135 | const response = await fetch(`${PII_URL}/anonymize`, { |
| 136 | method: 'POST', |
| 137 | headers: { 'content-type': 'application/json' }, |
| 138 | body: JSON.stringify({ text, analyzer_results: spans }), |
| 139 | }) |
| 140 | if (!response.ok) { |
| 141 | const detail = await response.text().catch(() => '') |
| 142 | throw new Error(`Presidio anonymize failed (${response.status}): ${detail.slice(0, 200)}`) |
| 143 | } |
| 144 | const data = (await response.json()) as { text: string } |
| 145 | return data.text |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Validate text for PII using the Presidio service. |