@openfeature/web-sdk 1.6.2 → 1.7.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 CHANGED
@@ -16,8 +16,8 @@
16
16
  <img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.8.0&color=yellow&style=for-the-badge" />
17
17
  </a>
18
18
  <!-- x-release-please-start-version -->
19
- <a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v1.6.2">
20
- <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.6.2&color=blue&style=for-the-badge" />
19
+ <a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v1.7.1">
20
+ <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.7.1&color=blue&style=for-the-badge" />
21
21
  </a>
22
22
  <!-- x-release-please-end -->
23
23
  <br/>
@@ -109,6 +109,7 @@ See [here](https://open-feature.github.io/js-sdk/modules/_openfeature_web_sdk.ht
109
109
  | ✅ | [Tracking](#tracking) | Associate user actions with feature flag evaluations, particularly for A/B testing. |
110
110
  | ✅ | [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. |
111
111
  | ✅ | [Extending](#extending) | Extend OpenFeature with custom providers and hooks. |
112
+ | ✅ | [Multi-Provider](#multi-provider) | Combine multiple providers with configurable evaluation strategies. |
112
113
 
113
114
  <sub>Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub>
114
115
 
@@ -145,6 +146,63 @@ Once the provider has been registered, the status can be tracked using [events](
145
146
  In some situations, it may be beneficial to register multiple providers in the same application.
146
147
  This is possible using [domains](#domains), which is covered in more detail below.
147
148
 
149
+ #### Multi-Provider
150
+
151
+ The Multi-Provider allows you to use multiple underlying providers as sources of flag data for the OpenFeature web SDK. When a flag is being evaluated, the Multi-Provider will consult each underlying provider it is managing in order to determine the final result. Different evaluation strategies can be defined to control which providers get evaluated and which result is used.
152
+
153
+ The Multi-Provider is a powerful tool for performing migrations between flag providers, or combining multiple providers into a single feature flagging interface. For example:
154
+
155
+ - **Migration**: When migrating between two providers, you can run both in parallel under a unified flagging interface. As flags are added to the new provider, the Multi-Provider will automatically find and return them, falling back to the old provider if the new provider does not have the flag.
156
+ - **Multiple Data Sources**: The Multi-Provider allows you to seamlessly combine many sources of flagging data, such as environment variables, local files, database values and SaaS hosted feature management systems.
157
+
158
+ ```ts
159
+ import { MultiProvider } from '@openfeature/web-sdk';
160
+
161
+ const multiProvider = new MultiProvider([
162
+ { provider: new ProviderA() },
163
+ { provider: new ProviderB() }
164
+ ]);
165
+
166
+ await OpenFeature.setProviderAndWait(multiProvider);
167
+
168
+ const client = OpenFeature.getClient();
169
+ console.log(client.getBooleanDetails("my-flag", false));
170
+ ```
171
+
172
+ By default, the Multi-Provider will evaluate all underlying providers in order and return the first successful result. If a provider indicates it does not have a flag (FLAG_NOT_FOUND error code), then it will be skipped and the next provider will be evaluated.
173
+
174
+ ##### Evaluation Strategies
175
+
176
+ The Multi-Provider comes with three strategies out of the box:
177
+
178
+ - **FirstMatchStrategy** (default): Evaluates all providers in order and returns the first successful result. Providers that indicate FLAG_NOT_FOUND error will be skipped and the next provider will be evaluated.
179
+ - **FirstSuccessfulStrategy**: Evaluates all providers in order and returns the first successful result. Any error will cause that provider to be skipped.
180
+ - **ComparisonStrategy**: Evaluates all providers sequentially. If every provider returns a successful result with the same value, then that result is returned. Otherwise, the result returned by the configured "fallback provider" will be used.
181
+
182
+ ```ts
183
+ import { MultiProvider, FirstSuccessfulStrategy } from '@openfeature/web-sdk';
184
+
185
+ const multiProvider = new MultiProvider(
186
+ [
187
+ { provider: new ProviderA() },
188
+ { provider: new ProviderB() }
189
+ ],
190
+ new FirstSuccessfulStrategy()
191
+ );
192
+ ```
193
+
194
+ ##### Tracking Support
195
+
196
+ The Multi-Provider supports tracking events across multiple providers, allowing you to send analytics events to all configured providers simultaneously:
197
+
198
+ ```ts
199
+ // Tracked events will be sent to all providers by default
200
+ client.track('user-conversion', {
201
+ value: 99.99,
202
+ currency: 'USD'
203
+ });
204
+ ```
205
+
148
206
  ### Flag evaluation flow
149
207
 
150
208
  When a new provider is added to OpenFeature client the following process happens: