@openfeature/server-sdk 1.19.0 → 1.20.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/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 [yyyy] [name of copyright owner]
189
+ Copyright 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/server-sdk-v1.19.0">
20
- <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.19.0&color=blue&style=for-the-badge" />
19
+ <a href="https://github.com/open-feature/js-sdk/releases/tag/server-sdk-v1.20.1">
20
+ <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.20.1&color=blue&style=for-the-badge" />
21
21
  </a>
22
22
  <!-- x-release-please-end -->
23
23
  <br/>
@@ -110,6 +110,7 @@ See [here](https://open-feature.github.io/js-sdk/modules/_openfeature_server_sdk
110
110
  | ✅ | [Tracking](#tracking) | Associate user actions with feature flag evaluations, particularly for A/B testing. |
111
111
  | ✅ | [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. |
112
112
  | ✅ | [Extending](#extending) | Extend OpenFeature with custom providers and hooks. |
113
+ | ✅ | [Multi-Provider](#multi-provider) | Combine multiple providers with configurable evaluation strategies. |
113
114
 
114
115
  <sub>Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub>
115
116
 
@@ -140,7 +141,83 @@ OpenFeature.setProvider(new MyProvider());
140
141
  Once the provider has been registered, the status can be tracked using [events](#eventing).
141
142
 
142
143
  In some situations, it may be beneficial to register multiple providers in the same application.
143
- This is possible using [domains](#domains), which is covered in more details below.
144
+ This is possible using [domains](#domains), which is covered in more detail below.
145
+
146
+ #### Multi-Provider
147
+
148
+ The Multi-Provider allows you to use multiple underlying providers as sources of flag data for the OpenFeature server 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.
149
+
150
+ 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:
151
+
152
+ - **Migration**: Gradually migrate from one provider to another by serving some flags from your old provider and some from your new provider
153
+ - **Backup**: Use one provider as a backup for another in case of failures
154
+ - **Comparison**: Compare results from multiple providers to validate consistency
155
+ - **Hybrid**: Combine multiple providers to leverage different strengths (e.g., one for simple flags, another for complex targeting)
156
+
157
+ ```ts
158
+ import { OpenFeature, MultiProvider, FirstMatchStrategy } from '@openfeature/server-sdk';
159
+
160
+ // Create providers
161
+ const primaryProvider = new YourPrimaryProvider();
162
+ const backupProvider = new YourBackupProvider();
163
+
164
+ // Create multi-provider with a strategy
165
+ const multiProvider = new MultiProvider(
166
+ [primaryProvider, backupProvider],
167
+ new FirstMatchStrategy()
168
+ );
169
+
170
+ // Register the multi-provider
171
+ await OpenFeature.setProviderAndWait(multiProvider);
172
+
173
+ // Use as normal
174
+ const client = OpenFeature.getClient();
175
+ const value = await client.getBooleanValue('my-flag', false);
176
+ ```
177
+
178
+ **Available Strategies:**
179
+
180
+ - `FirstMatchStrategy`: Returns the first successful result from the list of providers
181
+ - `ComparisonStrategy`: Compares results from multiple providers and can handle discrepancies
182
+
183
+ **Migration Example:**
184
+
185
+ ```ts
186
+ import { OpenFeature, MultiProvider, FirstMatchStrategy } from '@openfeature/server-sdk';
187
+
188
+ // During migration, serve some flags from the new provider and fallback to the old one
189
+ const newProvider = new NewFlagProvider();
190
+ const oldProvider = new OldFlagProvider();
191
+
192
+ const multiProvider = new MultiProvider(
193
+ [newProvider, oldProvider], // New provider is consulted first
194
+ new FirstMatchStrategy()
195
+ );
196
+
197
+ await OpenFeature.setProviderAndWait(multiProvider);
198
+ ```
199
+
200
+ **Comparison Example:**
201
+
202
+ ```ts
203
+ import { OpenFeature, MultiProvider, ComparisonStrategy } from '@openfeature/server-sdk';
204
+
205
+ // Compare results from two providers for validation
206
+ const providerA = new ProviderA();
207
+ const providerB = new ProviderB();
208
+
209
+ const multiProvider = new MultiProvider(
210
+ [
211
+ { provider: providerA },
212
+ { provider: providerB }
213
+ ],
214
+ new ComparisonStrategy(providerA, (resolutions) => {
215
+ console.warn('Mismatch detected', resolutions);
216
+ })
217
+ );
218
+
219
+ await OpenFeature.setProviderAndWait(multiProvider);
220
+ ```
144
221
 
145
222
  ### Targeting
146
223