This provider is a community-developed implementation for Unleash which uses the official Unleash Proxy Client for the browser Client Side SDK.
This provider uses a static evaluation context suitable for client-side implementation.
Suitable for connecting to an Unleash instance
- Via the Unleash front-end API.
- Via Unleash Edge.
- Via Unleash Proxy.
Gitlab Feature Flags can also be used with this provider - although note that Unleash Edge is not currently supported by Gitlab.
- Boolean evaluation gets feature enabled status.
- String, Number, and Object evaluation gets feature variant value.
- Object evaluation should be used for JSON/CSV payloads in variants.
$ npm install @openfeature/unleash-web-provider @openfeature/web-sdk
To initialize the OpenFeature client with Unleash, you can use the following code snippets:
import { UnleashWebProvider } from '@openfeature/unleash-web-provider';
const provider = new UnleashWebProvider({
url: 'http://your.upstream.unleash.instance',
clientKey: 'theclientkey',
appName: 'your app',
});
await OpenFeature.setProviderAndWait(provider);
The Unleash context can be set during creation of the provider.
import { UnleashWebProvider } from '@openfeature/unleash-web-provider';
const context = {
userId: '123',
sessionId: '456',
remoteAddress: 'address',
properties: {
property1: 'property1',
property2: 'property2',
},
};
const provider = new UnleashWebProvider({
url: 'http://your.upstream.unleash.instance',
clientKey: 'theclientkey',
appName: 'your app',
context: context,
});
await OpenFeature.setProviderAndWait(provider);
Unleash has a variety of configuration options that can be provided to the UnleashWebProvider
constructor.
Please refer to the options described in the official Unleash Proxy Client for the browser Client Side SDK.
After the provider gets initialized, you can start evaluations of feature flags like so:
// Get the client
const client = await OpenFeature.getClient();
// You can now use the client to evaluate your flags
const details = client.getBooleanValue('my-feature', false);
The static evaluation context can be changed if needed
const evaluationCtx: EvaluationContext = {
usedId: 'theuser',
currentTime: 'time',
sessionId: 'theSessionId',
remoteAddress: 'theRemoteAddress',
environment: 'theEnvironment',
appName: 'theAppName',
aCustomProperty: 'itsValue',
anotherCustomProperty: 'somethingForIt',
};
// changes the static evaluation context for OpenFeature
await OpenFeature.setContext(evaluationCtx);
Run nx package providers-unleash-web
to build the library.
Run nx test providers-unleash-web
to execute the unit tests via Jest.