Log at warn the first time a stale session is seen; demote repeats to debug.
( cacheKey: string, fields: Record<string, unknown>, message: string, suppressedMessage: string, )
| 47 | |
| 48 | /** Log at warn the first time a stale session is seen; demote repeats to debug. */ |
| 49 | function warnOncePerSession( |
| 50 | cacheKey: string, |
| 51 | fields: Record<string, unknown>, |
| 52 | message: string, |
| 53 | suppressedMessage: string, |
| 54 | ): void { |
| 55 | const now = Date.now(); |
| 56 | const firstSeen = authFailureLog.get(cacheKey); |
| 57 | if (!firstSeen || now - firstSeen > AUTH_FAILURE_LOG_SUPPRESS_MS) { |
| 58 | authFailureLog.set(cacheKey, now); |
| 59 | logger.warn(fields, message); |
| 60 | } else { |
| 61 | logger.debug(fields, suppressedMessage); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Clean up expired cache entries periodically (every 5 minutes) |
| 66 | setInterval(() => { |
no test coverage detected