Skip to content

Commit

Permalink
feat: Initial GrowthBook OpenFeature provider (#896)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Samper <[email protected]>
  • Loading branch information
msamper authored May 17, 2024
1 parent c3b27e5 commit 62ef69b
Show file tree
Hide file tree
Showing 20 changed files with 687 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"libs/providers/ofrep-web": "0.1.3",
"libs/providers/flipt": "0.1.0",
"libs/providers/flagsmith-client": "0.1.2",
"libs/providers/flipt-web": "0.1.0"
"libs/providers/flipt-web": "0.1.0",
"libs/providers/growthbook-client": "0.1.0"
}
25 changes: 25 additions & 0 deletions libs/providers/growthbook-client/.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"
}
}
]
}
44 changes: 44 additions & 0 deletions libs/providers/growthbook-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# growthbook-client Provider

## Installation

```
$ npm install @openfeature/growthbook-client-provider
```

## Example Setup

```typescript
import { GrowthBook, Context, InitOptions } from '@growthbook/growthbook';
import { GrowthbookClientProvider } from '@openfeature/growthbook-client-provider';

/*
* Configure your GrowthBook instance with GrowthBook context
* @see https://docs.growthbook.io/lib/js#step-1-configure-your-app
*/
const gbContext: Context = {
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-abc123',
// Only required if you have feature encryption enabled in GrowthBook
decryptionKey: 'key_abc123',
};

/*
* optional init options
* @see https://docs.growthbook.io/lib/js#switching-to-init
*/
const initOptions: InitOptions = {
timeout: 2000,
streaming: true,
};

OpenFeature.setProvider(new GrowthbookClientProvider(gbContext, initOptions));
```

## Building

Run `nx package providers-growthbook-client` to build the library.

## Running unit tests

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

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

17 changes: 17 additions & 0 deletions libs/providers/growthbook-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@openfeature/growthbook-client-provider",
"version": "0.1.0",
"dependencies": {
"tslib": "^2.3.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": {
"@growthbook/growthbook": "^1.0.0",
"@openfeature/web-sdk": "^1.0.0"
}
}
79 changes: 79 additions & 0 deletions libs/providers/growthbook-client/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "providers-growthbook-client",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/providers/growthbook-client/src",
"projectType": "library",
"targets": {
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "npm run publish-if-not-exists",
"cwd": "dist/libs/providers/growthbook-client"
},
"dependsOn": [
{
"projects": "self",
"target": "package"
}
]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/providers/growthbook-client/**/*.ts",
"libs/providers/growthbook-client/package.json"
]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/providers/growthbook-client/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"package": {
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"project": "libs/providers/growthbook-client/package.json",
"outputPath": "dist/libs/providers/growthbook-client",
"entryFile": "libs/providers/growthbook-client/src/index.ts",
"tsConfig": "libs/providers/growthbook-client/tsconfig.lib.json",
"buildableProjectDepsInPackageJsonType": "dependencies",
"compiler": "tsc",
"generateExportsField": true,
"umdName": "growthbook-client",
"external": "all",
"format": ["cjs", "esm"],
"assets": [
{
"glob": "package.json",
"input": "./assets",
"output": "./src/"
},
{
"glob": "LICENSE",
"input": "./",
"output": "./"
},
{
"glob": "README.md",
"input": "./libs/providers/growthbook-client",
"output": "./"
}
]
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions libs/providers/growthbook-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/growthbook-client-provider';
Loading

0 comments on commit 62ef69b

Please sign in to comment.