@openfeature/server-sdk 1.19.0 → 1.20.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 +79 -3
- package/dist/cjs/index.js +582 -37
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +558 -22
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +146 -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/server-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/server-sdk-v1.20.0">
|
|
20
|
+
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.20.0&color=blue&style=for-the-badge" />
|
|
21
21
|
</a>
|
|
22
22
|
<!-- x-release-please-end -->
|
|
23
23
|
<br/>
|
|
@@ -140,7 +140,83 @@ OpenFeature.setProvider(new MyProvider());
|
|
|
140
140
|
Once the provider has been registered, the status can be tracked using [events](#eventing).
|
|
141
141
|
|
|
142
142
|
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
|
|
143
|
+
This is possible using [domains](#domains), which is covered in more detail below.
|
|
144
|
+
|
|
145
|
+
#### Multi-Provider
|
|
146
|
+
|
|
147
|
+
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.
|
|
148
|
+
|
|
149
|
+
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:
|
|
150
|
+
|
|
151
|
+
- **Migration**: Gradually migrate from one provider to another by serving some flags from your old provider and some from your new provider
|
|
152
|
+
- **Backup**: Use one provider as a backup for another in case of failures
|
|
153
|
+
- **Comparison**: Compare results from multiple providers to validate consistency
|
|
154
|
+
- **Hybrid**: Combine multiple providers to leverage different strengths (e.g., one for simple flags, another for complex targeting)
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { OpenFeature, MultiProvider, FirstMatchStrategy } from '@openfeature/server-sdk';
|
|
158
|
+
|
|
159
|
+
// Create providers
|
|
160
|
+
const primaryProvider = new YourPrimaryProvider();
|
|
161
|
+
const backupProvider = new YourBackupProvider();
|
|
162
|
+
|
|
163
|
+
// Create multi-provider with a strategy
|
|
164
|
+
const multiProvider = new MultiProvider(
|
|
165
|
+
[primaryProvider, backupProvider],
|
|
166
|
+
new FirstMatchStrategy()
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// Register the multi-provider
|
|
170
|
+
await OpenFeature.setProviderAndWait(multiProvider);
|
|
171
|
+
|
|
172
|
+
// Use as normal
|
|
173
|
+
const client = OpenFeature.getClient();
|
|
174
|
+
const value = await client.getBooleanValue('my-flag', false);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Strategies:**
|
|
178
|
+
|
|
179
|
+
- `FirstMatchStrategy`: Returns the first successful result from the list of providers
|
|
180
|
+
- `ComparisonStrategy`: Compares results from multiple providers and can handle discrepancies
|
|
181
|
+
|
|
182
|
+
**Migration Example:**
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { OpenFeature, MultiProvider, FirstMatchStrategy } from '@openfeature/server-sdk';
|
|
186
|
+
|
|
187
|
+
// During migration, serve some flags from the new provider and fallback to the old one
|
|
188
|
+
const newProvider = new NewFlagProvider();
|
|
189
|
+
const oldProvider = new OldFlagProvider();
|
|
190
|
+
|
|
191
|
+
const multiProvider = new MultiProvider(
|
|
192
|
+
[newProvider, oldProvider], // New provider is consulted first
|
|
193
|
+
new FirstMatchStrategy()
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
await OpenFeature.setProviderAndWait(multiProvider);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Comparison Example:**
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { OpenFeature, MultiProvider, ComparisonStrategy } from '@openfeature/server-sdk';
|
|
203
|
+
|
|
204
|
+
// Compare results from two providers for validation
|
|
205
|
+
const providerA = new ProviderA();
|
|
206
|
+
const providerB = new ProviderB();
|
|
207
|
+
|
|
208
|
+
const multiProvider = new MultiProvider(
|
|
209
|
+
[
|
|
210
|
+
{ provider: providerA },
|
|
211
|
+
{ provider: providerB }
|
|
212
|
+
],
|
|
213
|
+
new ComparisonStrategy(providerA, (resolutions) => {
|
|
214
|
+
console.warn('Mismatch detected', resolutions);
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
await OpenFeature.setProviderAndWait(multiProvider);
|
|
219
|
+
```
|
|
144
220
|
|
|
145
221
|
### Targeting
|
|
146
222
|
|