Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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-web:
- jarebudev

ignored-authors:
- renovate-bot
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"libs/providers/growthbook-client": "0.1.2",
"libs/providers/config-cat-web": "0.1.3",
"libs/shared/config-cat-core": "0.1.0",
"libs/providers/unleash-web": "0.1.0",
"libs/providers/growthbook": "0.1.1"
}
25 changes: 25 additions & 0 deletions libs/providers/unleash-web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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"
}
}
]
}
123 changes: 123 additions & 0 deletions libs/providers/unleash-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# unleash-web Provider

## About this provider

This provider is a community-developed implementation for Unleash which uses the official [Unleash Proxy Client for the browser Client Side SDK](https://docs.getunleash.io/reference/sdks/javascript-browser).

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](https://docs.getunleash.io/reference/front-end-api).
* Via [Unleash Edge](https://docs.getunleash.io/reference/unleash-edge).
* Via [Unleash Proxy](https://docs.getunleash.io/reference/unleash-proxy).

[Gitlab Feature Flags](https://docs.gitlab.com/ee/operations/feature_flags.html) can also be used with this provider - although note that Unleash Edge is not currently supported by Gitlab.

### 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-web-provider @openfeature/web-sdk
```

## Usage

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

### Initialization - without context

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

### Initialization - with context

The [Unleash context](https://docs.getunleash.io/reference/unleash-context) can be set during creation of the provider.

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


### Available Constructor Configuration Options

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](https://docs.getunleash.io/reference/sdks/javascript-browser#available-options).




### 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-web` to build the library.

### Running unit tests

Run `nx test providers-unleash-web` to execute the unit tests via [Jest](https://jestjs.io).
3 changes: 3 additions & 0 deletions libs/providers/unleash-web/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["minify", { "builtIns": false }]]
}
10 changes: 10 additions & 0 deletions libs/providers/unleash-web/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'providers-unleash-web',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/providers/unleash-web',
};
104 changes: 104 additions & 0 deletions libs/providers/unleash-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions libs/providers/unleash-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@openfeature/unleash-web-provider",
"version": "0.1.0",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"scripts": {
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi",
"current-version": "echo $npm_package_version"
},
"peerDependencies": {
"@openfeature/web-sdk": "^1.0.0",
"tslib": "^2.3.0",
"unleash-proxy-client": "^3.6.0"
}
}
77 changes: 77 additions & 0 deletions libs/providers/unleash-web/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "providers-unleash-web",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/providers/unleash-web/src",
"projectType": "library",
"targets": {
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "npm run publish-if-not-exists",
"cwd": "dist/libs/providers/unleash-web"
},
"dependsOn": [
{
"projects": "self",
"target": "package"
}
]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/providers/unleash-web/**/*.ts", "libs/providers/unleash-web/package.json"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/providers/unleash-web/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"package": {
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"project": "libs/providers/unleash-web/package.json",
"outputPath": "dist/libs/providers/unleash-web",
"entryFile": "libs/providers/unleash-web/src/index.ts",
"tsConfig": "libs/providers/unleash-web/tsconfig.lib.json",
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true,
"compiler": "tsc",
"generateExportsField": true,
"umdName": "unleash-web",
"external": "all",
"format": ["cjs", "esm"],
"assets": [
{
"glob": "package.json",
"input": "./assets",
"output": "./src/"
},
{
"glob": "LICENSE",
"input": "./",
"output": "./"
},
{
"glob": "README.md",
"input": "./libs/providers/unleash-web",
"output": "./"
}
]
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions libs/providers/unleash-web/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/unleash-web-provider';
Loading
Loading