|
1 | 1 | # unleash Provider
|
2 | 2 |
|
| 3 | +## About this provider |
| 4 | + |
| 5 | +This provider is a community-developed implementation for Unleash which uses the official [Node Server-side SDK](https://docs.getunleash.io/reference/sdks/node). |
| 6 | + |
| 7 | +### Concepts |
| 8 | + |
| 9 | +- Boolean evaluation gets feature enabled status. |
| 10 | +- String, Number, and Object evaluation gets feature variant value. |
| 11 | +- Object evaluation should be used for JSON/CSV payloads in variants. |
| 12 | + |
3 | 13 | ## Installation
|
4 | 14 |
|
| 15 | +```shell |
| 16 | +$ npm install @openfeature/unleash-provider @openfeature/server-sdk |
5 | 17 | ```
|
6 |
| -$ npm install @openfeature/unleash-provider |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +To initialize the OpenFeature client with Unleash, you can use the following code snippets: |
| 22 | + |
| 23 | +### Initialization |
| 24 | + |
| 25 | +```ts |
| 26 | +import { UnleashProvider } from '@openfeature/unleash-provider'; |
| 27 | + |
| 28 | +const provider = new UnleashProvider({ |
| 29 | + url: 'https://YOUR-API-URL', |
| 30 | + appName: 'your app', |
| 31 | + customHeaders: { Authorization: 'your api key' }, |
| 32 | +}); |
| 33 | + |
| 34 | +await OpenFeature.setProviderAndWait(provider); |
7 | 35 | ```
|
8 | 36 |
|
9 |
| -## Building |
| 37 | +### Available Constructor Configuration Options |
| 38 | + |
| 39 | +Unleash has a variety of configuration options that can be provided to the `UnleashProvider` constructor. |
| 40 | + |
| 41 | +Please refer to the options described in the official [Node Server-side SDK](https://docs.getunleash.io/reference/sdks/node). |
| 42 | + |
| 43 | +### After initialization |
| 44 | + |
| 45 | +After the provider gets initialized, you can start evaluations of feature flags like so: |
| 46 | + |
| 47 | +```ts |
| 48 | +// Get the client |
| 49 | +const client = await OpenFeature.getClient(); |
| 50 | + |
| 51 | +// You can now use the client to evaluate your flags |
| 52 | +const details = client.getBooleanValue('my-feature', false); |
| 53 | +``` |
| 54 | + |
| 55 | +The static evaluation context can be changed if needed |
| 56 | + |
| 57 | +```ts |
| 58 | +const evaluationCtx: EvaluationContext = { |
| 59 | + usedId: 'theuser', |
| 60 | + currentTime: 'time', |
| 61 | + sessionId: 'theSessionId', |
| 62 | + remoteAddress: 'theRemoteAddress', |
| 63 | + environment: 'theEnvironment', |
| 64 | + appName: 'theAppName', |
| 65 | + aCustomProperty: 'itsValue', |
| 66 | + anotherCustomProperty: 'somethingForIt', |
| 67 | +}; |
| 68 | + |
| 69 | +// changes the static evaluation context for OpenFeature |
| 70 | +await OpenFeature.setContext(evaluationCtx); |
| 71 | +``` |
| 72 | + |
| 73 | +## Contribute |
| 74 | + |
| 75 | +### Building |
10 | 76 |
|
11 | 77 | Run `nx package providers-unleash` to build the library.
|
12 | 78 |
|
13 |
| -## Running unit tests |
| 79 | +### Running unit tests |
14 | 80 |
|
15 | 81 | Run `nx test providers-unleash` to execute the unit tests via [Jest](https://jestjs.io).
|
0 commit comments