(event: any)
| 165 | * @returns Sanitized event data safe for external reporting |
| 166 | */ |
| 167 | export function sanitizeEventData(event: any): any { |
| 168 | if (event === null || event === undefined) { |
| 169 | return event |
| 170 | } |
| 171 | |
| 172 | if (typeof event === 'string') { |
| 173 | return redactSensitiveValues(event) |
| 174 | } |
| 175 | |
| 176 | if (typeof event !== 'object') { |
| 177 | return event |
| 178 | } |
| 179 | |
| 180 | if (Array.isArray(event)) { |
| 181 | return event.map((item) => sanitizeEventData(item)) |
| 182 | } |
| 183 | |
| 184 | const sanitized: Record<string, unknown> = {} |
| 185 | |
| 186 | for (const [key, value] of Object.entries(event)) { |
| 187 | if (isSensitiveKey(key)) { |
| 188 | continue |
| 189 | } |
| 190 | |
| 191 | if (typeof value === 'string') { |
| 192 | sanitized[key] = redactSensitiveValues(value) |
| 193 | } else if (Array.isArray(value)) { |
| 194 | sanitized[key] = value.map((v) => sanitizeEventData(v)) |
| 195 | } else if (value && typeof value === 'object') { |
| 196 | sanitized[key] = sanitizeEventData(value) |
| 197 | } else { |
| 198 | sanitized[key] = value |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return sanitized |
| 203 | } |
no test coverage detected