@openfeature/web-sdk 1.6.1 → 1.7.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/LICENSE +1 -1
- package/README.md +59 -2
- package/dist/cjs/index.js +542 -24
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +524 -6
- package/dist/esm/index.js.map +4 -4
- package/dist/global/index.js +527 -8
- package/dist/global/index.js.map +4 -4
- package/dist/global/index.min.js +1 -1
- package/dist/global/index.min.js.map +4 -4
- package/dist/types.d.ts +145 -3
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2025 OpenFeature Maintainers
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
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.
|
|
20
|
-
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.
|
|
19
|
+
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v1.7.0">
|
|
20
|
+
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.7.0&color=blue&style=for-the-badge" />
|
|
21
21
|
</a>
|
|
22
22
|
<!-- x-release-please-end -->
|
|
23
23
|
<br/>
|
|
@@ -145,6 +145,63 @@ Once the provider has been registered, the status can be tracked using [events](
|
|
|
145
145
|
In some situations, it may be beneficial to register multiple providers in the same application.
|
|
146
146
|
This is possible using [domains](#domains), which is covered in more detail below.
|
|
147
147
|
|
|
148
|
+
#### Multi-Provider
|
|
149
|
+
|
|
150
|
+
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.
|
|
151
|
+
|
|
152
|
+
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:
|
|
153
|
+
|
|
154
|
+
- **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.
|
|
155
|
+
- **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.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { MultiProvider } from '@openfeature/web-sdk';
|
|
159
|
+
|
|
160
|
+
const multiProvider = new MultiProvider([
|
|
161
|
+
{ provider: new ProviderA() },
|
|
162
|
+
{ provider: new ProviderB() }
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
await OpenFeature.setProviderAndWait(multiProvider);
|
|
166
|
+
|
|
167
|
+
const client = OpenFeature.getClient();
|
|
168
|
+
console.log(client.getBooleanDetails("my-flag", false));
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
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.
|
|
172
|
+
|
|
173
|
+
##### Evaluation Strategies
|
|
174
|
+
|
|
175
|
+
The Multi-Provider comes with three strategies out of the box:
|
|
176
|
+
|
|
177
|
+
- **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.
|
|
178
|
+
- **FirstSuccessfulStrategy**: Evaluates all providers in order and returns the first successful result. Any error will cause that provider to be skipped.
|
|
179
|
+
- **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.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { MultiProvider, FirstSuccessfulStrategy } from '@openfeature/web-sdk';
|
|
183
|
+
|
|
184
|
+
const multiProvider = new MultiProvider(
|
|
185
|
+
[
|
|
186
|
+
{ provider: new ProviderA() },
|
|
187
|
+
{ provider: new ProviderB() }
|
|
188
|
+
],
|
|
189
|
+
new FirstSuccessfulStrategy()
|
|
190
|
+
);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
##### Tracking Support
|
|
194
|
+
|
|
195
|
+
The Multi-Provider supports tracking events across multiple providers, allowing you to send analytics events to all configured providers simultaneously:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
// Tracked events will be sent to all providers by default
|
|
199
|
+
client.track('user-conversion', {
|
|
200
|
+
value: 99.99,
|
|
201
|
+
currency: 'USD'
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
148
205
|
### Flag evaluation flow
|
|
149
206
|
|
|
150
207
|
When a new provider is added to OpenFeature client the following process happens:
|