Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unleash server provider #1230

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ components:
- markphelps
libs/providers/flipt-web:
- markphelps
libs/providers/unleash:
- albertilagan
libs/providers/unleash-web:
- jarebudev

Expand Down
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"libs/providers/config-cat-web": "0.1.5",
"libs/shared/config-cat-core": "0.1.1",
"libs/providers/unleash-web": "0.1.1",
"libs/providers/growthbook": "0.1.2"
"libs/providers/growthbook": "0.1.2",
"libs/providers/unleash": "0.1.0"
}
30 changes: 30 additions & 0 deletions libs/providers/unleash/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredFiles": ["{projectRoot}/eslint.config.{js,cjs,mjs}"]
}
]
}
}
]
}
81 changes: 81 additions & 0 deletions libs/providers/unleash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# unleash Provider

## About this provider

This provider is a community-developed implementation for Unleash which uses the official [Node Server-side SDK](https://docs.getunleash.io/reference/sdks/node).

### 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

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

## Usage

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

### Initialization

```ts
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](https://docs.getunleash.io/reference/sdks/node).

### After initialization

After the provider gets initialized, you can start evaluations of feature flags like so:

```ts
// 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

```ts
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](https://jestjs.io).
3 changes: 3 additions & 0 deletions libs/providers/unleash/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["minify", { "builtIns": false }]]
}
9 changes: 9 additions & 0 deletions libs/providers/unleash/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
displayName: 'providers-unleash',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/providers/unleash-web',
};
Loading
Loading