( payload: RedactablePayload, options: PiiRedactionOptions )
| 203 | * the failure path. |
| 204 | */ |
| 205 | export async function redactPIIFromExecution( |
| 206 | payload: RedactablePayload, |
| 207 | options: PiiRedactionOptions |
| 208 | ): Promise<RedactablePayload> { |
| 209 | const startedAt = performance.now() |
| 210 | |
| 211 | const units = REDACTABLE_KEYS.filter((key) => payload[key] !== undefined).map((key) => ({ |
| 212 | key, |
| 213 | value: payload[key], |
| 214 | })) |
| 215 | |
| 216 | const collected: string[] = [] |
| 217 | let totalBytes = 0 |
| 218 | for (const unit of units) { |
| 219 | transformUnit(unit.key, unit.value, (s) => { |
| 220 | collected.push(s) |
| 221 | totalBytes += Buffer.byteLength(s, 'utf8') |
| 222 | return s |
| 223 | }) |
| 224 | } |
| 225 | |
| 226 | if (collected.length === 0) return payload |
| 227 | |
| 228 | const { masked, scrubbed } = await maskCollected(collected, options) |
| 229 | |
| 230 | let index = 0 |
| 231 | const result: RedactablePayload = { ...payload } |
| 232 | for (const unit of units) { |
| 233 | result[unit.key] = transformUnit(unit.key, unit.value, () => masked[index++]) |
| 234 | } |
| 235 | |
| 236 | logger.info('PII redaction completed', { |
| 237 | stringCount: collected.length, |
| 238 | totalBytes, |
| 239 | durationMs: Math.round(performance.now() - startedAt), |
| 240 | scrubbed, |
| 241 | }) |
| 242 | return result |
| 243 | } |
no test coverage detected