(email: string)
| 47 | * "" -> "***" |
| 48 | */ |
| 49 | export const maskEmailForLogging = (email: string): string => { |
| 50 | if (email === "") { |
| 51 | return "***"; |
| 52 | } |
| 53 | |
| 54 | const atIndex = email.indexOf("@"); |
| 55 | |
| 56 | if (atIndex === -1) { |
| 57 | return "***"; |
| 58 | } |
| 59 | |
| 60 | const localPart = email.slice(0, atIndex); |
| 61 | const domain = email.slice(atIndex + 1); |
| 62 | |
| 63 | if (localPart.length <= 2) { |
| 64 | return `***@${domain}`; |
| 65 | } |
| 66 | |
| 67 | const first = localPart[0] ?? ""; |
| 68 | const last = localPart[localPart.length - 1] ?? ""; |
| 69 | |
| 70 | return `${first}***${last}@${domain}`; |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * Boundary validator for outbound email payloads. Throws an `ApiError` |
no outgoing calls
no test coverage detected