* Fetch Grove config from API and store in cache
(accountId: string)
| 196 | * Fetch Grove config from API and store in cache |
| 197 | */ |
| 198 | async function fetchAndStoreGroveConfig(accountId: string): Promise<void> { |
| 199 | try { |
| 200 | const result = await getGroveNoticeConfig() |
| 201 | if (!result.success) { |
| 202 | return |
| 203 | } |
| 204 | const groveEnabled = result.data.grove_enabled |
| 205 | const cachedEntry = getGlobalConfig().groveConfigCache?.[accountId] |
| 206 | if ( |
| 207 | cachedEntry?.grove_enabled === groveEnabled && |
| 208 | Date.now() - cachedEntry.timestamp <= GROVE_CACHE_EXPIRATION_MS |
| 209 | ) { |
| 210 | return |
| 211 | } |
| 212 | saveGlobalConfig(current => ({ |
| 213 | ...current, |
| 214 | groveConfigCache: { |
| 215 | ...current.groveConfigCache, |
| 216 | [accountId]: { |
| 217 | grove_enabled: groveEnabled, |
| 218 | timestamp: Date.now(), |
| 219 | }, |
| 220 | }, |
| 221 | })) |
| 222 | } catch (err) { |
| 223 | logForDebugging(`Grove: Failed to fetch and store config: ${err}`) |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Get Grove Statsig configuration from the API. |
no test coverage detected