()
| 81 | * Returns current cached state and cache status |
| 82 | */ |
| 83 | export function checkCachedPassesEligibility(): { |
| 84 | eligible: boolean |
| 85 | needsRefresh: boolean |
| 86 | hasCache: boolean |
| 87 | } { |
| 88 | if (!shouldCheckForPasses()) { |
| 89 | return { |
| 90 | eligible: false, |
| 91 | needsRefresh: false, |
| 92 | hasCache: false, |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | const orgId = getOauthAccountInfo()?.organizationUuid |
| 97 | if (!orgId) { |
| 98 | return { |
| 99 | eligible: false, |
| 100 | needsRefresh: false, |
| 101 | hasCache: false, |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | const config = getGlobalConfig() |
| 106 | const cachedEntry = config.passesEligibilityCache?.[orgId] |
| 107 | |
| 108 | if (!cachedEntry) { |
| 109 | // No cached entry, needs fetch |
| 110 | return { |
| 111 | eligible: false, |
| 112 | needsRefresh: true, |
| 113 | hasCache: false, |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | const { eligible, timestamp } = cachedEntry |
| 118 | const now = Date.now() |
| 119 | const needsRefresh = now - timestamp > CACHE_EXPIRATION_MS |
| 120 | |
| 121 | return { |
| 122 | eligible, |
| 123 | needsRefresh, |
| 124 | hasCache: true, |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | const CURRENCY_SYMBOLS: Record<string, string> = { |
| 129 | USD: '$', |
no test coverage detected