flagmint-js-sdk 2.0.0 → 2.2.0

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
@@ -137,8 +137,10 @@ After `ready()`:
137
137
  | `persistContext` | boolean | `false` | Persist context in the cache adapter |
138
138
  | `cacheAdapter` | CacheAdapter | localStorage helpers | Custom cache (Redis, files, …) |
139
139
  | `restEndpoint` | string | env default | Override the long-polling / evaluate URL |
140
- | `sseEndpoint` | string | env default | Override the SSE base URL (`/stream` and `/context`) |
141
- | `handshakeEndpoint` | string | env default | Override the ASL handshake URL. Use with `sseEndpoint` for self-hosted gateways |
140
+ | `sseEndpoint` | string | env default | Override the SSE stream base URL (`/stream` only). Defaults to `stream.flagmint.com` / `staging-stream…` |
141
+ | `flagsEndpoint` | string | from `restEndpoint` | Override the API base for `POST /context`. Needed when stream and API hosts differ |
142
+ | `handshakeEndpoint` | string | env default | Override the ASL handshake URL. Use with `restEndpoint` / `sseEndpoint` for self-hosted gateways |
143
+ | `restEndpoint` | string | env default | Override REST evaluate URL (also drives events + default context host) |
142
144
  | `env` | string | `NODE_ENV` | `development` \| `staging` \| `production` |
143
145
  | `wrapperInfo` | `{ name, version }` | native-js | Framework wrapper telemetry on the stream URL |
144
146
  | `previewMode` / `rawFlags` | | | Local-only evaluation, no network |
@@ -197,7 +199,9 @@ SSE `/context` changes **that connection’s** context. It is the right tool for
197
199
 
198
200
  # Tracking application errors
199
201
 
200
- `getFlag()` tells you what was served. `trackError()` tells Flagmint whether that variation hurt the user. Errors are attributed to the **currently served value** of the flag, batched, and posted to `POST /evaluator/events`. The call never throws.
202
+ `getFlag()` tells you what was served and, when Analytics Tracking is on for that flag, queues a **debounced call-site evaluation** report (dashboard Evaluations). That report is not a billing meter.
203
+
204
+ `trackError()` tells Flagmint whether that variation hurt the user. Errors are attributed to the **currently served value** of the flag, batched, and posted to `POST /evaluator/events`. The call never throws.
201
205
 
202
206
  Analytics must be enabled on the flag in the dashboard. The SDK skips `trackError` / `track` locally once the SSE `flags` packet includes `analytics` for that key. Older servers without the map still accept the POST and drop it at ingest.
203
207
 
@@ -214,17 +218,7 @@ try {
214
218
 
215
219
  `track(flagKey, eventName)` uses the same pipe for custom metrics (conversions, etc.). Only `kind: 'error'` is counted in app error rate today.
216
220
 
217
- ### Manual verification
218
-
219
- The Flagmint dashboard evaluates its own flags with `flagmint-react-sdk` (`useFlag('homepage_variant')`). Boom that path, don't curl:
220
-
221
- 1. Enable Analytics Tracking on `homepage_variant`.
222
- 2. Run FF-EU on `:3000` and the dashboard (`npm run dev` in `flagmint`, port **5200**).
223
- 3. Open [http://localhost:5200/?flagmint_boom=1](http://localhost:5200/?flagmint_boom=1).
224
221
 
225
- The homepage reads the served variant, then `trackError('homepage_variant', …)` (or POSTs `/evaluator/events` if this app still has js-sdk 1.x). Expect a **Flag error sent** toast. Metrics **App error rate** moves after the 5-minute flush.
226
-
227
- Other SDK flags: `?flagmint_boom=show_google_login` on `/login`. Production ignores the query param.
228
222
 
229
223
  ```tsx
230
224
  const enabled = useFlag('checkout_redesign', false);
@@ -283,18 +277,24 @@ The callback runs immediately with the current snapshot, then on every push. `de
283
277
 
284
278
  # Offline cache
285
279
 
286
- Enabled by default. On boot the SDK loads `flagmint_<apiKey>_flags` from localStorage (24h TTL). If the stream fails, those values stay in memory and `onError` fires.
280
+ Enabled by default.
281
+
282
+ - **Browser:** loads `flagmint_<apiKey>_flags` from localStorage (24h TTL). With `configSync`, also hydrates/persists `flagmint_<apiKey>_rules` (lease `expiresAt`, not wall-clock TTL).
283
+ - **Node with no adapter:** config-sync rules still work **in memory** for that process (`RulesStore`). Helper persist is a no-op — restart → cold `fullConfig`. Plug in `setCacheStorage` / `setAsyncCacheStorage` or a custom `cacheAdapter` to survive restarts.
284
+ - If the stream fails, the last in-memory snapshot stays and `onError` fires.
287
285
 
288
286
  ```ts
289
287
  cacheAdapter: {
290
288
  loadFlags(apiKey, ttl) { /* ... */ },
291
289
  saveFlags(apiKey, data) { /* ... */ },
292
290
  loadContext(apiKey) { /* ... */ },
293
- saveContext(apiKey, ctx) { /* ... */ }
291
+ saveContext(apiKey, ctx) { /* ... */ },
292
+ loadRulesSnapshot(apiKey) { /* ... */ }, // configSync
293
+ saveRulesSnapshot(apiKey, snap) { /* ... */ },
294
294
  }
295
295
  ```
296
296
 
297
- Use `syncCache` in the browser and `asyncCache` (or your own) in Node / React Native.
297
+ Use `syncCache` in the browser and `asyncCache` (or your own) in Node / React Native. See `sdk/core/helpers/Readme.md`.
298
298
 
299
299
  ---
300
300