@openfeature/server-sdk 1.7.0 → 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.
Files changed (2) hide show
  1. package/README.md +29 -9
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -12,12 +12,12 @@
12
12
  <!-- x-hide-in-docs-end -->
13
13
  <!-- The 'github-badges' class is used in the docs -->
14
14
  <p align="center" class="github-badges">
15
- <a href="https://github.com/open-feature/spec/tree/v0.7.0">
15
+ <a href="https://github.com/open-feature/spec/releases/tag/v0.7.0">
16
16
  <img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.7.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.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" />
19
+ <a href="https://github.com/open-feature/js-sdk/releases/tag/server-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/>
@@ -36,7 +36,7 @@
36
36
  </p>
37
37
  <!-- x-hide-in-docs-start -->
38
38
 
39
- [OpenFeature](https://openfeature.dev) is an open standard that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.
39
+ [OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.
40
40
 
41
41
  <!-- x-hide-in-docs-end -->
42
42
 
@@ -57,7 +57,8 @@ npm install --save @openfeature/server-sdk
57
57
  #### yarn
58
58
 
59
59
  ```sh
60
- yarn add @openfeature/server-sdk
60
+ # yarn requires manual installation of the @openfeature/core peer-dependency
61
+ yarn add @openfeature/server-sdk @openfeature/core
61
62
  ```
62
63
 
63
64
  ### Usage
@@ -66,7 +67,7 @@ yarn add @openfeature/server-sdk
66
67
  import { OpenFeature } from '@openfeature/server-sdk';
67
68
 
68
69
  // Register your feature flag provider
69
- OpenFeature.setProvider(new YourProviderOfChoice());
70
+ await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
70
71
 
71
72
  // create a new client
72
73
  const client = OpenFeature.getClient();
@@ -106,10 +107,24 @@ If the provider you're looking for hasn't been created yet, see the [develop a p
106
107
 
107
108
  Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
108
109
 
110
+ #### Awaitable
111
+
112
+ To register a provider and ensure it is ready before further actions are taken, you can use the `setProviderAndWait` method as shown below:
113
+
114
+ ```ts
115
+ await OpenFeature.setProviderAndWait(new MyProvider());
116
+ ```
117
+
118
+ #### Synchronous
119
+
120
+ To register a provider in a synchronous manner, you can use the `setProvider` method as shown below:
121
+
109
122
  ```ts
110
- OpenFeature.setProvider(new MyProvider())
123
+ OpenFeature.setProvider(new MyProvider());
111
124
  ```
112
125
 
126
+ Once the provider has been registered, the status can be tracked using [events](#eventing).
127
+
113
128
  In some situations, it may be beneficial to register multiple providers in the same application.
114
129
  This is possible using [named clients](#named-clients), which is covered in more details below.
115
130
 
@@ -210,6 +225,9 @@ const clientWithDefault = OpenFeature.getClient();
210
225
  const clientForCache = OpenFeature.getClient("otherClient");
211
226
  ```
212
227
 
228
+ Named providers can be set in an awaitable or synchronous way.
229
+ For more details, please refer to the [providers](#providers) section.
230
+
213
231
  ### Eventing
214
232
 
215
233
  Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.
@@ -223,13 +241,13 @@ import { OpenFeature, ProviderEvents } from '@openfeature/server-sdk';
223
241
 
224
242
  // OpenFeature API
225
243
  OpenFeature.addHandler(ProviderEvents.Ready, (eventDetails) => {
226
- console.log(`Ready event from: ${eventDetails?.clientName}:`, eventDetails);
244
+ console.log(`Ready event from: ${eventDetails?.providerName}:`, eventDetails);
227
245
  });
228
246
 
229
247
  // Specific client
230
248
  const client = OpenFeature.getClient();
231
249
  client.addHandler(ProviderEvents.Error, (eventDetails) => {
232
- console.log(`Error event from: ${eventDetails?.clientName}:`, eventDetails);
250
+ console.log(`Error event from: ${eventDetails?.providerName}:`, eventDetails);
233
251
  });
234
252
  ```
235
253
 
@@ -257,6 +275,8 @@ import { JsonValue, Provider, ResolutionDetails } from '@openfeature/server-sdk'
257
275
 
258
276
  // implement the provider interface
259
277
  class MyProvider implements Provider {
278
+ // Adds runtime validation that the provider is used with the expected SDK
279
+ public readonly runsOn = 'server';
260
280
 
261
281
  readonly metadata = {
262
282
  name: 'My Provider',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfeature/server-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "OpenFeature SDK for JavaScript",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "files": [
@@ -48,9 +48,9 @@
48
48
  "node": ">=16"
49
49
  },
50
50
  "peerDependencies": {
51
- "@openfeature/core": "0.0.16"
51
+ "@openfeature/core": "0.0.17"
52
52
  },
53
53
  "devDependencies": {
54
- "@openfeature/core": "0.0.16"
54
+ "@openfeature/core": "0.0.17"
55
55
  }
56
56
  }