MCPcopy
hub / github.com/codeaashu/claude-code / getCachedOrFetchPassesEligibility

Function getCachedOrFetchPassesEligibility

src/services/api/referral.ts:231–269  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

229 * null and the passes command won't be available until the next session.
230 */
231export async function getCachedOrFetchPassesEligibility(): Promise<ReferralEligibilityResponse | null> {
232 if (!shouldCheckForPasses()) {
233 return null
234 }
235
236 const orgId = getOauthAccountInfo()?.organizationUuid
237 if (!orgId) {
238 return null
239 }
240
241 const config = getGlobalConfig()
242 const cachedEntry = config.passesEligibilityCache?.[orgId]
243 const now = Date.now()
244
245 // No cache - trigger background fetch and return null (non-blocking)
246 // The passes command won't be available this session, but will be next time
247 if (!cachedEntry) {
248 logForDebugging(
249 'Passes: No cache, fetching eligibility in background (command unavailable this session)',
250 )
251 void fetchAndStorePassesEligibility()
252 return null
253 }
254
255 // Cache exists but is stale - return stale cache and trigger background refresh
256 if (now - cachedEntry.timestamp > CACHE_EXPIRATION_MS) {
257 logForDebugging(
258 'Passes: Cache stale, returning cached data and refreshing in background',
259 )
260 void fetchAndStorePassesEligibility() // Background refresh
261 const { timestamp, ...response } = cachedEntry
262 return response as ReferralEligibilityResponse
263 }
264
265 // Cache is fresh - return it immediately
266 logForDebugging('Passes: Using fresh cached eligibility data')
267 const { timestamp, ...response } = cachedEntry
268 return response as ReferralEligibilityResponse
269}
270
271/**
272 * Prefetch passes eligibility on startup

Callers 2

loadPassesDataFunction · 0.85

Calls 5

shouldCheckForPassesFunction · 0.85
getGlobalConfigFunction · 0.85
logForDebuggingFunction · 0.85
getOauthAccountInfoFunction · 0.50

Tested by

no test coverage detected