Skip to content

Latest commit

 

History

History
81 lines (54 loc) · 2.1 KB

README.md

File metadata and controls

81 lines (54 loc) · 2.1 KB

unleash Provider

About this provider

This provider is a community-developed implementation for Unleash which uses the official Node Server-side SDK.

Concepts

  • 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.

Installation

$ npm install @openfeature/unleash-provider @openfeature/server-sdk

Usage

To initialize the OpenFeature client with Unleash, you can use the following code snippets:

Initialization

import { UnleashProvider } from '@openfeature/unleash-provider';

const provider = new UnleashProvider({
  url: 'https://YOUR-API-URL',
  appName: 'your app',
  customHeaders: { Authorization: 'your api key' },
});

await OpenFeature.setProviderAndWait(provider);

Available Constructor Configuration Options

Unleash has a variety of configuration options that can be provided to the UnleashProvider constructor.

Please refer to the options described in the official Node Server-side SDK.

After initialization

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);

Contribute

Building

Run nx package providers-unleash to build the library.

Running unit tests

Run nx test providers-unleash to execute the unit tests via Jest.