import LRU from "lru-cache" ; const emailShortCache = new LRU < string , number > ( { max : 10000 , maxAge : 1000 * 60 , } ) ; const emailLongCache = new LRU < string , number > ( { max : 20000 , maxAge : 1000 * 60 * 60 , } ) ; const ipShortCache = new LRU < string , number > ( { max : 10000 , maxAge : 1000 * 60 } ) ; const ipLongCache = new LRU < string , number > ( { max : 20000 , maxAge : 1000 * 60 * 60 , } ) ; export function signInCheck ( email , ip ? ) { if ( ( emailShortCache . get ( email ) ?? 0 ) > 5 ) { return `Too many attempts per minute to sign in as "${ email }". Wait one minute, then try again.` ; } if ( ( emailLongCache . get ( email ) ?? 0 ) > 50 ) { return `Too many attempts per hour to sign in as "${ email }". Wait about an hour, then try again.` ; } if ( ip != null && ( ipShortCache . get ( ip ) ?? 0 ) > 30 ) { return `Too many attempts per minute to sign in from your computer. Wait one minute, then try again.` ; } if ( ip != null && ( ipLongCache . get ( ip ) ?? 0 ) > 200 ) { return `Too many attempts per hour to sign in from your computer. Wait about an hour, then try again.` ; } } export function recordFail ( email , ip ? ) { emailShortCache . set ( email , ( emailShortCache . get ( email ) ?? 0 ) + 1 ) ; emailLongCache . set ( email , ( emailLongCache . get ( email ) ?? 0 ) + 1 ) ; if ( ip != null ) { ipShortCache . set ( ip , ( ipShortCache . get ( ip ) ?? 0 ) + 1 ) ; ipLongCache . set ( ip , ( ipLongCache . get ( ip ) ?? 0 ) + 1 ) ; } }