|
| 1 | +# Flipt Provider |
| 2 | + |
| 3 | +[Flipt](https://www.flipt.io/) is an open source developer friendly feature flagging solution, that allows for easy management and fast feature evaluation. |
| 4 | + |
| 5 | +This provider is an implementation on top of the official [Flipt Node Server Side SDK](https://www.npmjs.com/package/@flipt-io/flipt). |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +``` |
| 10 | +$ npm install @openfeature/flipt-provider |
| 11 | +``` |
| 12 | + |
| 13 | +### Peer Dependencies |
| 14 | + |
| 15 | +Both the OpenFeature SDK and the Flipt Node Server SDK are required as peer dependencies. |
| 16 | + |
| 17 | +Please make sure to install `@flipt/flipt-io` at versions >= `1.0.0`, as the client API is different in earlier versions. |
| 18 | + |
| 19 | +The peer dependency will also enforce the above version. |
| 20 | + |
| 21 | +## Example initialization and usage |
| 22 | + |
| 23 | +To initialize the OpenFeature client with Flipt, you can use the following code snippet: |
| 24 | + |
| 25 | +```ts |
| 26 | +import { FliptProvider } from '@openfeature/flipt'; |
| 27 | + |
| 28 | +const provider = new FliptProvider('namespace-of-choice', { url: 'http://your.upstream.flipt.host' }); |
| 29 | +OpenFeature.setProvider(provider); |
| 30 | +``` |
| 31 | + |
| 32 | +After the provider gets initialized, you can start evaluations of feature flags like so: |
| 33 | + |
| 34 | +```ts |
| 35 | +const client = OpenFeature.getClient(); |
| 36 | +const details = await client.getStringDetails('nonExistent', 'default', { |
| 37 | + targetingKey: 'myentity', |
| 38 | + |
| 39 | +}); |
| 40 | +``` |
| 41 | + |
| 42 | +## Evaluation Context Transformation |
| 43 | + |
| 44 | +OpenFeature standardizes the evaluation context to include a `targetingKey`, and some other additional arbitrary properties that each provider can use fit for their use case. |
| 45 | + |
| 46 | +For Flipt, we translate the `targetingKey` as the `entityId`, and the rest of the OpenFeature evaluation context as the `context` in Flipt vernacular. You can find the meaning of those two words [here](https://www.flipt.io/docs/reference/evaluation/variant-evaluation) in our API docs. |
| 47 | + |
| 48 | +For example, an OpenFeature Evaluation context that has this structure: |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "targetingKey": "my-targeting-id", |
| 53 | + |
| 54 | + "userId": "this-very-long-user-id" |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +will get transformed to the following for Flipt: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "entityId": "my-targeting-id", |
| 63 | + "context": { |
| 64 | + |
| 65 | + "userId": "this-very-long-user-id" |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Building |
| 71 | + |
| 72 | +Run `nx package providers-flipt` to build the library. |
| 73 | + |
| 74 | +## Running unit tests |
| 75 | + |
| 76 | +Run `nx test providers-flipt` to execute the unit tests via [Jest](https://jestjs.io). |
0 commit comments