flagmint-js-sdk 1.2.21 → 1.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,7 +60,7 @@ await client.updateContext({
60
60
  | `persistContext` | `boolean` | `false` | Persist evaluation context across sessions. | |
61
61
  | `cacheAdapter` | `CacheAdapter<C>` | Sync `cacheHelper` | Custom cache implementation (see examples). |
62
62
  | `transportMode` | `'auto' \| 'websocket' \| 'long-polling'` | `'auto'` | How to fetch flags: prefer WebSocket, or use long-polling transport. |
63
- | `onError` | `(error: Error) => void` | — | Callback for transport or initialization errors. Still throws on `ready()` if connection fails. |
63
+ | `onError` | `(error: Error) => void` | — | Callback for transport or initialization errors. Called when operating in degraded mode with cached flags. |
64
64
  | `previewMode` | `boolean` | `false` | Evaluate using `rawFlags` only, bypassing remote fetch. |
65
65
  | `rawFlags` | `Record<string, FlagValue>` | — | Local-only flag definitions used when `previewMode: true`. |
66
66
  | `deferInitialization` | `boolean` | `false` | If `true`, client initialization is deferred until you call `ready()`. |
@@ -327,31 +327,39 @@ const client = new FlagClient({
327
327
  });
328
328
  ```
329
329
 
330
- **Important: Error Handling with Cache**
330
+ **Important: Offline Fallback & Cache Behavior**
331
331
 
332
- When the server is unreachable but cached flags exist:
333
- - ✅ Cached flags ARE loaded and accessible via `getFlag()`
334
- - ⚠️ `onError` callback is called with the connection error
335
- - ❌ `ready()` promise still **rejects** with the error
332
+ The SDK gracefully handles connection failures using cached flags as a fallback:
336
333
 
337
- This means you should handle both:
334
+ **When the server is unreachable:**
335
+
336
+ | Scenario | `ready()` Promise | Behavior |
337
+ |----------|-------------------|----------|
338
+ | ✅ Cached flags available | Resolves | Operates in degraded mode with cached flags |
339
+ | ❌ No cached flags | Rejects | Initialization fails |
340
+ | ✅ Connected successfully | Resolves | Normal operation with live updates |
341
+
342
+ **Degraded Mode:** When `ready()` resolves but the connection failed, the `onError` callback is triggered to notify you:
338
343
 
339
344
  ```ts
340
345
  const client = new FlagClient({
341
346
  apiKey: '...',
342
347
  enableOfflineCache: true,
343
348
  onError: (error) => {
344
- console.warn('Flagmint connection failed, using cached flags:', error);
349
+ // Called when operating in degraded mode with cached flags
350
+ console.warn('⚠️ Degraded mode - using cached flags:', error.message);
351
+ // Optionally report to monitoring service
345
352
  }
346
353
  });
347
354
 
348
355
  try {
349
356
  await client.ready();
350
- console.log('Connected to Flagmint');
357
+ // ✅ Resolves successfully even if server is down (when cached flags exist)
358
+ console.log('Client ready');
359
+ const feature = client.getFlag('my_feature', false); // Always works
351
360
  } catch (error) {
352
- console.error('Flagmint unreachable:', error);
353
- // Cached flags are still available!
354
- const feature = client.getFlag('my_feature', false); // Works!
361
+ // ❌ Only throws if NO cached flags AND server is unreachable
362
+ console.error('Completely offline:', error);
355
363
  }
356
364
  ```
357
365