(value: unknown, keyPath: string[] = [])
| 244 | } |
| 245 | |
| 246 | export function sanitizeConfigValue(value: unknown, keyPath: string[] = []): unknown { |
| 247 | const key = keyPath.at(-1) ?? ""; |
| 248 | if (key && isSecretKey(key)) { |
| 249 | return `<REDACTED:${redactionTypeForKey(key)}>`; |
| 250 | } |
| 251 | if (typeof value === "string") return sanitizeDiagnosticText(value); |
| 252 | if (Array.isArray(value)) { |
| 253 | return value.map((entry, index) => sanitizeConfigValue(entry, [...keyPath, String(index)])); |
| 254 | } |
| 255 | if (value && typeof value === "object") { |
| 256 | return Object.fromEntries( |
| 257 | Object.entries(value).map(([entryKey, entry]) => [ |
| 258 | entryKey, |
| 259 | sanitizeConfigValue(entry, [...keyPath, entryKey]), |
| 260 | ]), |
| 261 | ); |
| 262 | } |
| 263 | return value; |
| 264 | } |
no test coverage detected