|
1 | 1 | import type { OFREPProviderBaseOptions } from '@openfeature/ofrep-core'; |
2 | 2 |
|
| 3 | +export type CacheMode = 'local-cache-first' | 'network-first' | 'disabled'; |
| 4 | + |
| 5 | +/** Default cache TTL: 30 days in seconds. */ |
| 6 | +export const DEFAULT_CACHE_TTL_SECONDS = 30 * 24 * 60 * 60; |
| 7 | + |
3 | 8 | export type OFREPWebProviderOptions = OFREPProviderBaseOptions & { |
4 | 9 | /** |
5 | | - * pollInterval is the time in milliseconds to wait between we call the OFREP |
| 10 | + * pollInterval is the time in milliseconds to wait between calls to the OFREP |
6 | 11 | * API to get the latest evaluation of your flags. |
7 | 12 | * |
8 | | - * If a negative number is provided, the provider will not poll the OFREP API. |
| 13 | + * If the value is 0 or negative, polling is disabled. |
9 | 14 | * Default: 30000 |
10 | 15 | */ |
11 | | - pollInterval?: number; // in milliseconds |
| 16 | + pollInterval?: number; |
| 17 | + |
| 18 | + /** |
| 19 | + * cacheMode controls whether and how the provider uses local persistent storage. |
| 20 | + * |
| 21 | + * - `'local-cache-first'` (default): load from the persisted cache immediately on startup |
| 22 | + * so `initialize()` can return right away, then refresh from the network in the background. |
| 23 | + * - `'network-first'`: block `initialize()` on the network request and only fall back to the |
| 24 | + * persisted cache on transient or server errors (network unavailable, 5xx, timeout). |
| 25 | + * Auth and configuration errors (401, 403, 400) are surfaced immediately and never masked |
| 26 | + * by cached values. |
| 27 | + * - `'disabled'`: no persistence at all. `initialize()` always blocks on the network. |
| 28 | + * Persistence-related options have no effect. |
| 29 | + * |
| 30 | + * Default: `'local-cache-first'` |
| 31 | + */ |
| 32 | + cacheMode?: CacheMode; |
| 33 | + |
| 34 | + /** |
| 35 | + * cacheTTL is the maximum age (in seconds) of a persisted cache entry before it is |
| 36 | + * treated as a cache miss. Expired entries are removed from storage on read. |
| 37 | + * |
| 38 | + * Default: 2_592_000 (30 days) |
| 39 | + */ |
| 40 | + cacheTTL?: number; |
| 41 | + |
| 42 | + /** |
| 43 | + * cacheKeyPrefix is included in the cache key hash to prevent collisions when multiple |
| 44 | + * OFREP provider instances share the same storage partition (e.g. the same browser origin). |
| 45 | + * When set, the cache key becomes `hash(cacheKeyPrefix + ":" + targetingKey)`. |
| 46 | + * |
| 47 | + * A sensible value is the OFREP base URL, a project key, or any other string that |
| 48 | + * uniquely identifies this provider instance. |
| 49 | + */ |
| 50 | + cacheKeyPrefix?: string; |
12 | 51 | }; |
0 commit comments