@openfeature/web-sdk 1.0.3 → 1.2.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/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.0.3">
20
- <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.0.3&color=blue&style=for-the-badge" />
19
+ <a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v1.2.0">
20
+ <img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.2.0&color=blue&style=for-the-badge" />
21
21
  </a>
22
22
  <!-- x-release-please-end -->
23
23
  <br/>
@@ -44,7 +44,7 @@
44
44
 
45
45
  ### Requirements
46
46
 
47
- - ES2022-compatible web browser (Chrome, Edge, Firefox, etc)
47
+ - ES2015-compatible web browser (Chrome, Edge, Firefox, etc)
48
48
 
49
49
  ### Install
50
50
 
@@ -54,6 +54,9 @@
54
54
  npm install --save @openfeature/web-sdk
55
55
  ```
56
56
 
57
+ > [!TIP]
58
+ > This SDK is designed to run in the browser. If you're interested in server support, check out the [Node.js SDK](https://openfeature.dev/docs/reference/technologies/server/javascript/).
59
+
57
60
  #### yarn
58
61
 
59
62
  ```sh
@@ -118,7 +121,7 @@ To register a provider and ensure it is ready before further actions are taken,
118
121
 
119
122
  ```ts
120
123
  await OpenFeature.setProviderAndWait(new MyProvider());
121
- ```
124
+ ```
122
125
 
123
126
  #### Synchronous
124
127
 
@@ -155,9 +158,16 @@ Sometimes, the value of a flag must consider some dynamic criteria about the app
155
158
  In OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).
156
159
  If the flag management system you're using supports targeting, you can provide the input data using the [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context).
157
160
 
161
+ ```ts
162
+ // Sets global context during provider registration
163
+ await OpenFeature.setProvider(new MyProvider(), { origin: document.location.host });
164
+ ```
165
+
166
+ Change context after the provider has been registered using `setContext`.
167
+
158
168
  ```ts
159
169
  // Set a value to the global context
160
- await OpenFeature.setContext({ origin: document.location.host });
170
+ await OpenFeature.setContext({ targetingKey: localStorage.getItem("targetingKey") });
161
171
  ```
162
172
 
163
173
  Context is global and setting it is `async`.
@@ -230,6 +240,24 @@ const domainScopedClient = OpenFeature.getClient("my-domain");
230
240
  Domains can be defined on a provider during registration.
231
241
  For more details, please refer to the [providers](#providers) section.
232
242
 
243
+ #### Manage evaluation context for domains
244
+
245
+ By default, domain-scoped clients use the global context.
246
+ This can be overridden by explicitly setting context when registering the provider or by references the domain when updating context:
247
+
248
+ ```ts
249
+ OpenFeature.setProvider("my-domain", new NewCachedProvider(), { targetingKey: localStorage.getItem("targetingKey") });
250
+ ```
251
+
252
+ To change context after the provider has been registered, use `setContext` with a name:
253
+
254
+ ```ts
255
+ await OpenFeature.setContext("my-domain", { targetingKey: localStorage.getItem("targetingKey") })
256
+ ```
257
+
258
+ Once context has been defined for a named client, it will override the global context for all clients using the associated provider.
259
+ Context can be cleared using for a named provider using `OpenFeature.clearContext("my-domain")` or call `OpenFeature.clearContexts()` to reset all context.
260
+
233
261
  ### Eventing
234
262
 
235
263
  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.