superposition-provider 0.85.1 → 0.87.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 ADDED
@@ -0,0 +1,66 @@
1
+ # Superposition Provider
2
+
3
+ Superposition provider is an openfeature provider that works with [Superposition](https://juspay.io/open-source/superposition) to fetch feature flags, configurations, and experiment variants from a Superposition server, store it in-memory and do configuration resolutions based on dynamic contexts. Read the [docs](https://juspay.io/open-source/superposition/docs) for more details.
4
+
5
+ ## Getting started
6
+
7
+ Install the provider
8
+ ```
9
+ npm install superposition-provider
10
+ ```
11
+
12
+ > **Note:** You will need to boot up Superposition before running the client code. Check the docs on how to get started with Superposition.
13
+
14
+ ## Initialization
15
+
16
+ To initialize the Superposition provider, you need to create a configuration. Create the provider object and then, you can set the provider using OpenFeature's API.
17
+
18
+ ```javascript
19
+ import { OpenFeature } from '@openfeature/server-sdk';
20
+ import { SuperpositionProvider } from 'superposition-provider';
21
+
22
+ // create a simple configuration object, for all options check the provider documentation
23
+ const config = {
24
+ endpoint: "http://localhost:8080",
25
+ token: "your-token-here",
26
+ org_id: "localorg",
27
+ workspace_id: "test",
28
+ };
29
+ const provider = new SuperpositionProvider(config);
30
+ console.log("Provider created successfully");
31
+
32
+ // Initialize the provider
33
+ await OpenFeature.setProviderAndWait(provider);
34
+ console.log("Provider initialized successfully");
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ Once the provider is initialized, you can evaluate feature flags and configurations using the OpenFeature client.
40
+
41
+ ```javascript
42
+ const client = OpenFeature.getClient();
43
+ const context = {
44
+ d1: "d1",
45
+ };
46
+
47
+ console.log("Testing feature flags...");
48
+
49
+ const boolValue = await client.getBooleanValue("bool", false, context);
50
+ console.log("Boolean flag 'bool':", boolValue);
51
+
52
+ const stringValue = await client.getStringValue(
53
+ "string",
54
+ "default",
55
+ context,
56
+ );
57
+ console.log("String flag 'string':", stringValue);
58
+
59
+ const numberValue = await client.getNumberValue("number_key", 0, context);
60
+ console.log("Number flag 'number_key':", numberValue);
61
+
62
+ // Test resolving all config
63
+ const allConfig = await provider.resolveAllConfigDetails({}, context);
64
+ console.log("All config:", allConfig);
65
+ ```
66
+