MCPcopy Create free account
hub / github.com/Noumena-Network/code / isQualifiedForGrove

Function isQualifiedForGrove

src/services/api/grove.ts:177–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175 * false and the Grove dialog won't show until the next session.
176 */
177export async function isQualifiedForGrove(): Promise<boolean> {
178 const session = getAuthRuntime().getCurrentSession()
179 if (!canUseGroveForSession(session)) {
180 return false
181 }
182
183 const accountId = session.identity.accountUuid
184 if (!accountId) {
185 return false
186 }
187
188 const globalConfig = getGlobalConfig()
189 const cachedEntry = globalConfig.groveConfigCache?.[accountId]
190 const now = Date.now()
191
192 // No cache - trigger background fetch and return false (non-blocking)
193 // The Grove dialog won't show this session, but will next time if eligible
194 if (!cachedEntry) {
195 logForDebugging(
196 'Grove: No cache, fetching config in background (dialog skipped this session)',
197 )
198 void fetchAndStoreGroveConfig(accountId)
199 return false
200 }
201
202 // Cache exists but is stale - return cached value and refresh in background
203 if (now - cachedEntry.timestamp > GROVE_CACHE_EXPIRATION_MS) {
204 logForDebugging(
205 'Grove: Cache stale, returning cached data and refreshing in background',
206 )
207 void fetchAndStoreGroveConfig(accountId)
208 return cachedEntry.grove_enabled
209 }
210
211 // Cache is fresh - return it immediately
212 logForDebugging('Grove: Using fresh cached config')
213 return cachedEntry.grove_enabled
214}
215
216/**
217 * Fetch Grove config from API and store in cache

Callers 4

showSetupScreensFunction · 0.85
callFunction · 0.85
runHeadlessFunction · 0.85
grove.test.tsFile · 0.85

Calls 6

getAuthRuntimeFunction · 0.85
canUseGroveForSessionFunction · 0.85
fetchAndStoreGroveConfigFunction · 0.85
getCurrentSessionMethod · 0.65
getGlobalConfigFunction · 0.50
logForDebuggingFunction · 0.50

Tested by

no test coverage detected