Skip to content

Commit 62ef69b

Browse files
authored
feat: Initial GrowthBook OpenFeature provider (open-feature#896)
Signed-off-by: Michael Samper <[email protected]>
1 parent c3b27e5 commit 62ef69b

20 files changed

+687
-2
lines changed

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"libs/providers/ofrep-web": "0.1.3",
1414
"libs/providers/flipt": "0.1.0",
1515
"libs/providers/flagsmith-client": "0.1.2",
16-
"libs/providers/flipt-web": "0.1.0"
16+
"libs/providers/flipt-web": "0.1.0",
17+
"libs/providers/growthbook-client": "0.1.0"
1718
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["*.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nx/dependency-checks": "error"
22+
}
23+
}
24+
]
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# growthbook-client Provider
2+
3+
## Installation
4+
5+
```
6+
$ npm install @openfeature/growthbook-client-provider
7+
```
8+
9+
## Example Setup
10+
11+
```typescript
12+
import { GrowthBook, Context, InitOptions } from '@growthbook/growthbook';
13+
import { GrowthbookClientProvider } from '@openfeature/growthbook-client-provider';
14+
15+
/*
16+
* Configure your GrowthBook instance with GrowthBook context
17+
* @see https://docs.growthbook.io/lib/js#step-1-configure-your-app
18+
*/
19+
const gbContext: Context = {
20+
apiHost: 'https://cdn.growthbook.io',
21+
clientKey: 'sdk-abc123',
22+
// Only required if you have feature encryption enabled in GrowthBook
23+
decryptionKey: 'key_abc123',
24+
};
25+
26+
/*
27+
* optional init options
28+
* @see https://docs.growthbook.io/lib/js#switching-to-init
29+
*/
30+
const initOptions: InitOptions = {
31+
timeout: 2000,
32+
streaming: true,
33+
};
34+
35+
OpenFeature.setProvider(new GrowthbookClientProvider(gbContext, initOptions));
36+
```
37+
38+
## Building
39+
40+
Run `nx package providers-growthbook-client` to build the library.
41+
42+
## Running unit tests
43+
44+
Run `nx test providers-growthbook-client` to execute the unit tests via [Jest](https://jestjs.io).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["minify", { "builtIns": false }]]
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'providers-growthbook-client',
4+
preset: '../../../jest.preset.js',
5+
transform: {
6+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
coverageDirectory: '../../../coverage/libs/providers/growthbook-client',
10+
};

libs/providers/growthbook-client/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@openfeature/growthbook-client-provider",
3+
"version": "0.1.0",
4+
"dependencies": {
5+
"tslib": "^2.3.0"
6+
},
7+
"main": "./src/index.js",
8+
"typings": "./src/index.d.ts",
9+
"scripts": {
10+
"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",
11+
"current-version": "echo $npm_package_version"
12+
},
13+
"peerDependencies": {
14+
"@growthbook/growthbook": "^1.0.0",
15+
"@openfeature/web-sdk": "^1.0.0"
16+
}
17+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"name": "providers-growthbook-client",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/providers/growthbook-client/src",
5+
"projectType": "library",
6+
"targets": {
7+
"publish": {
8+
"executor": "nx:run-commands",
9+
"options": {
10+
"command": "npm run publish-if-not-exists",
11+
"cwd": "dist/libs/providers/growthbook-client"
12+
},
13+
"dependsOn": [
14+
{
15+
"projects": "self",
16+
"target": "package"
17+
}
18+
]
19+
},
20+
"lint": {
21+
"executor": "@nx/linter:eslint",
22+
"outputs": ["{options.outputFile}"],
23+
"options": {
24+
"lintFilePatterns": [
25+
"libs/providers/growthbook-client/**/*.ts",
26+
"libs/providers/growthbook-client/package.json"
27+
]
28+
}
29+
},
30+
"test": {
31+
"executor": "@nx/jest:jest",
32+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
33+
"options": {
34+
"jestConfig": "libs/providers/growthbook-client/jest.config.ts",
35+
"passWithNoTests": true
36+
},
37+
"configurations": {
38+
"ci": {
39+
"ci": true,
40+
"codeCoverage": true
41+
}
42+
}
43+
},
44+
"package": {
45+
"executor": "@nx/rollup:rollup",
46+
"outputs": ["{options.outputPath}"],
47+
"options": {
48+
"project": "libs/providers/growthbook-client/package.json",
49+
"outputPath": "dist/libs/providers/growthbook-client",
50+
"entryFile": "libs/providers/growthbook-client/src/index.ts",
51+
"tsConfig": "libs/providers/growthbook-client/tsconfig.lib.json",
52+
"buildableProjectDepsInPackageJsonType": "dependencies",
53+
"compiler": "tsc",
54+
"generateExportsField": true,
55+
"umdName": "growthbook-client",
56+
"external": "all",
57+
"format": ["cjs", "esm"],
58+
"assets": [
59+
{
60+
"glob": "package.json",
61+
"input": "./assets",
62+
"output": "./src/"
63+
},
64+
{
65+
"glob": "LICENSE",
66+
"input": "./",
67+
"output": "./"
68+
},
69+
{
70+
"glob": "README.md",
71+
"input": "./libs/providers/growthbook-client",
72+
"output": "./"
73+
}
74+
]
75+
}
76+
}
77+
},
78+
"tags": []
79+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/growthbook-client-provider';

0 commit comments

Comments
 (0)