flagmint-js-sdk 2.2.2-rc.0 → 2.2.3-rc-2
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 +21 -7
- package/dist/flagmint.cjs.js +319 -50
- package/dist/flagmint.cjs.js.map +1 -1
- package/dist/flagmint.es.js +319 -50
- package/dist/flagmint.es.js.map +1 -1
- package/dist/flagmint.umd.js +319 -50
- package/dist/flagmint.umd.js.map +1 -1
- package/dist/sdk/core/client.d.ts +17 -1
- package/dist/sdk/core/config-sync/index.d.ts +2 -2
- package/dist/sdk/core/config-sync/piiHash.d.ts +86 -6
- package/dist/sdk/core/config-sync/rulesStore.d.ts +7 -1
- package/dist/sdk/core/config-sync/types.d.ts +5 -0
- package/dist/sdk/core/helpers/connectionShare.d.ts +73 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,9 @@ await client.ready();
|
|
|
72
72
|
const enabled = client.getFlag('new_dashboard', false);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Same-origin iframes that use this API key share one SSE connection by default **in browsers that provide `BroadcastChannel`**. Without it (older browsers, Node), each client opens its own stream. Set `shareConnection: false` if
|
|
75
|
+
Same-origin iframes that use this API key share one SSE connection by default **in browsers that provide `BroadcastChannel`**. Without it (older browsers, Node), each client opens its own stream. Set `shareConnection: false` if the origin hosts untrusted documents that should not share that stream.
|
|
76
|
+
|
|
77
|
+
With **`configSync: true`**, sharing still uses one stream, but only **rules** are broadcast — each tab keeps its own context and evaluates locally (so agent A and agent B in sibling tabs stay independent). Classic server eval still shares evaluated flag maps (last context write wins on that path).
|
|
76
78
|
|
|
77
79
|
## Node.js
|
|
78
80
|
|
|
@@ -132,7 +134,7 @@ After `ready()`:
|
|
|
132
134
|
| `context` | object | `{}` | Initial evaluation context. Do not put secrets or PII here — the stream URL serializes this object in the query string |
|
|
133
135
|
| `transportMode` | `'auto' \| 'sse' \| 'long-polling'` | `'auto'` | `auto` tries SSE, then long-polling |
|
|
134
136
|
| `EventSourceImpl` | EventSource | browser global | Required in Node |
|
|
135
|
-
| `shareConnection` | boolean | `true` in browsers with `BroadcastChannel`, `false` in Node | One stream per API key across same-origin documents |
|
|
137
|
+
| `shareConnection` | boolean | `true` in browsers with `BroadcastChannel`, `false` in Node | One stream per API key across same-origin documents. With `configSync`, shares **rules** only (per-tab local eval). |
|
|
136
138
|
| `enableOfflineCache` | boolean | `true` | Load/save flags via the cache adapter |
|
|
137
139
|
| `persistContext` | boolean | `false` | Persist context in the cache adapter |
|
|
138
140
|
| `cacheAdapter` | CacheAdapter | localStorage helpers | Custom cache (Redis, files, …) |
|
|
@@ -162,23 +164,35 @@ transportMode: 'long-polling' // POST evaluate on an interval
|
|
|
162
164
|
|
|
163
165
|
# Connection sharing
|
|
164
166
|
|
|
165
|
-
Used when the same app is embedded twice on one origin (for example two
|
|
167
|
+
Used when the same app is embedded twice on one origin (for example two iframes in a host page).
|
|
166
168
|
|
|
167
169
|
- **Leader** performs handshake and holds EventSource.
|
|
168
|
-
- **Followers**
|
|
169
|
-
-
|
|
170
|
-
-
|
|
170
|
+
- **Followers** skip handshake/EventSource. Leadership is a `localStorage` lock.
|
|
171
|
+
- **Server eval:** followers receive evaluated maps on `flagmint-share:<apiKey>`; `updateContext` is forwarded to the leader (last write wins).
|
|
172
|
+
- **Config sync:** followers receive rules on `flagmint-share-rules:<apiKey>` and evaluate locally; context stays per tab.
|
|
173
|
+
- If the leader iframe unloads, it posts `bye` so another member can take over immediately. If the tab is killed without `pagehide`, followers wait for the lock TTL. Turn sharing off if you host untrusted content on this origin.
|
|
171
174
|
|
|
172
175
|
```ts
|
|
173
176
|
// Default in browsers with BroadcastChannel — one stream for this API key
|
|
174
177
|
shareConnection: true
|
|
175
178
|
|
|
176
|
-
// Two
|
|
179
|
+
// Two independent streams (e.g. untrusted same-origin frames)
|
|
177
180
|
shareConnection: false
|
|
181
|
+
|
|
182
|
+
// configSync + share: one SSE for rules; each tab evaluates with its own context
|
|
183
|
+
configSync: true
|
|
184
|
+
shareConnection: true // default when BroadcastChannel exists
|
|
178
185
|
```
|
|
179
186
|
|
|
180
187
|
Node cluster workers do not share. Each worker process opens its own stream.
|
|
181
188
|
|
|
189
|
+
**Server eval vs config sync**
|
|
190
|
+
|
|
191
|
+
| Mode | What is shared | Context |
|
|
192
|
+
|------|----------------|---------|
|
|
193
|
+
| Server eval (`configSync` off) | Evaluated flag maps | Follower `updateContext` goes through the leader (last write wins) |
|
|
194
|
+
| Config sync | Verified **rules** snapshots only | Each tab’s own context; local `getFlag` / `updateContext` |
|
|
195
|
+
|
|
182
196
|
---
|
|
183
197
|
|
|
184
198
|
# Updating context
|