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

Function fetchAndStoreGroveConfig

src/services/api/grove.ts:219–246  ·  view source on GitHub ↗

* Fetch Grove config from API and store in cache

(accountId: string)

Source from the content-addressed store, hash-verified

217 * Fetch Grove config from API and store in cache
218 */
219async function fetchAndStoreGroveConfig(accountId: string): Promise<void> {
220 try {
221 const result = await getGroveNoticeConfig()
222 if (!result.success) {
223 return
224 }
225 const groveEnabled = result.data.grove_enabled
226 const cachedEntry = getGlobalConfig().groveConfigCache?.[accountId]
227 if (
228 cachedEntry?.grove_enabled === groveEnabled &&
229 Date.now() - cachedEntry.timestamp <= GROVE_CACHE_EXPIRATION_MS
230 ) {
231 return
232 }
233 saveGlobalConfig(current => ({
234 ...current,
235 groveConfigCache: {
236 ...current.groveConfigCache,
237 [accountId]: {
238 grove_enabled: groveEnabled,
239 timestamp: Date.now(),
240 },
241 },
242 }))
243 } catch (err) {
244 logForDebugging(`Grove: Failed to fetch and store config: ${err}`)
245 }
246}
247
248/**
249 * Get Grove Statsig configuration from the API.

Callers 1

isQualifiedForGroveFunction · 0.85

Calls 3

getGlobalConfigFunction · 0.50
saveGlobalConfigFunction · 0.50
logForDebuggingFunction · 0.50

Tested by

no test coverage detected