( url: string, texts: string[], entityTypes: string[], language: string | undefined )
| 54 | } |
| 55 | |
| 56 | async function postChunk( |
| 57 | url: string, |
| 58 | texts: string[], |
| 59 | entityTypes: string[], |
| 60 | language: string | undefined |
| 61 | ): Promise<string[]> { |
| 62 | // Mint per request: a single token (5min TTL) can expire mid-batch when a |
| 63 | // large execution fans out into many sequential chunk requests. |
| 64 | const token = await generateInternalToken() |
| 65 | |
| 66 | // boundary-raw-fetch: internal server-to-server call to the app container (internal JWT auth, configurable base URL) |
| 67 | const response = await fetch(url, { |
| 68 | method: 'POST', |
| 69 | headers: { |
| 70 | 'content-type': 'application/json', |
| 71 | authorization: `Bearer ${token}`, |
| 72 | }, |
| 73 | body: JSON.stringify({ texts, entityTypes, language }), |
| 74 | }) |
| 75 | |
| 76 | if (!response.ok) { |
| 77 | const detail = await response.text().catch(() => '') |
| 78 | throw new Error(`PII mask-batch request failed (${response.status}): ${detail.slice(0, 200)}`) |
| 79 | } |
| 80 | |
| 81 | const data = (await response.json()) as GuardrailsMaskBatchResult |
| 82 | if (!Array.isArray(data.masked)) { |
| 83 | throw new Error('PII mask-batch returned an unexpected result') |
| 84 | } |
| 85 | return data.masked |
| 86 | } |
no test coverage detected