flagmint-js-sdk 2.0.0 → 2.2.1
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 +16 -16
- package/dist/flagmint.cjs.js +4564 -887
- package/dist/flagmint.cjs.js.map +1 -1
- package/dist/flagmint.es.js +4565 -888
- package/dist/flagmint.es.js.map +1 -1
- package/dist/flagmint.umd.js +4564 -887
- package/dist/flagmint.umd.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/sdk/core/client.d.ts +61 -5
- package/dist/sdk/core/config-sync/aslEcdh.d.ts +32 -0
- package/dist/sdk/core/config-sync/evaluateSdkFlag.d.ts +26 -0
- package/dist/sdk/core/config-sync/flagEvaluator.d.ts +373 -0
- package/dist/sdk/core/config-sync/flattenContext.d.ts +28 -0
- package/dist/sdk/core/config-sync/handshake.d.ts +21 -0
- package/dist/sdk/core/config-sync/index.d.ts +13 -0
- package/dist/sdk/core/config-sync/rulesStore.d.ts +60 -0
- package/dist/sdk/core/config-sync/signPayload.d.ts +17 -0
- package/dist/sdk/core/config-sync/stringHash.d.ts +7 -0
- package/dist/sdk/core/config-sync/types.d.ts +72 -0
- package/dist/sdk/core/helpers/applicationEvents.d.ts +12 -1
- package/dist/sdk/core/helpers/cacheHelper.async.d.ts +4 -0
- package/dist/sdk/core/helpers/cacheHelper.d.ts +5 -0
- package/dist/sdk/core/helpers/connectionShare.d.ts +7 -0
- package/dist/sdk/core/helpers/jsonCloneable.d.ts +2 -0
- package/dist/sdk/core/helpers/types.d.ts +7 -0
- package/dist/sdk/core/transports/LongPollingTransport.d.ts +1 -0
- package/dist/sdk/core/transports/SSETransport.d.ts +62 -3
- package/dist/sdk/core/transports/Transport.d.ts +2 -0
- package/package.json +1 -1
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`
|
|
141
|
-
| `
|
|
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
|
|
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.
|
|
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
|
|