Skip to content

Commit e280014

Browse files
lukas-reiningadams85beeme1mr
authored
feat!: implement config cat web provider (#918)
Signed-off-by: Lukas Reining <[email protected]> Co-authored-by: adams85 <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
1 parent c109248 commit e280014

39 files changed

+1352
-346
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

libs/providers/config-cat-web/CHANGELOG.md

Whitespace-only changes.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# ConfigCat Web Provider
2+
3+
This provider is an implementation for [ConfigCat](https://configcat.com) a managed feature flag service.
4+
5+
## Installation
6+
7+
```
8+
$ npm install @openfeature/config-cat-web-provider
9+
```
10+
11+
#### Required peer dependencies
12+
13+
The OpenFeature SDK is required as peer dependency.
14+
15+
The minimum required version of `@openfeature/web-sdk` currently is `1.0.0`.
16+
17+
The minimum required version of `configcat-js-ssr` currently is `7.1.2`.
18+
19+
```
20+
$ npm install @openfeature/client-sdk configcat-js-ssr
21+
```
22+
23+
## Usage
24+
25+
The ConfigCat provider uses the [ConfigCat JavaScript SSR SDK](https://configcat.com/docs/sdk-reference/js-ssr/).
26+
27+
It can be created by passing the ConfigCat SDK options to ```ConfigCatProvider.create```.
28+
The available options can be found in the [ConfigCat JavaScript SSR SDK](https://configcat.com/docs/sdk-reference/js-ssr/).
29+
30+
The ConfigCat Web Provider only supports the `AutoPolling` mode because it caches all evaluation data to support synchronous evaluation of feature flags.
31+
32+
### Example using the default configuration
33+
34+
```javascript
35+
import { ConfigCatProvider } from '@openfeature/config-cat-web-provider';
36+
37+
const provider = ConfigCatProvider.create('<sdk_key>');
38+
OpenFeature.setProvider(provider);
39+
```
40+
41+
### Example using different polling options and a setupHook
42+
43+
```javascript
44+
import { ConfigCatProvider } from '@openfeature/config-cat-web-provider';
45+
46+
const provider = ConfigCatProvider.create('<sdk_key>', {
47+
setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')),
48+
});
49+
50+
OpenFeature.setProvider(provider);
51+
```
52+
53+
## Evaluation Context
54+
55+
The OpenFeature Evaluation Context is mapped to the [ConfigCat user object](https://configcat.com/docs/advanced/user-object/).
56+
57+
The [ConfigCat user object](https://configcat.com/docs/advanced/user-object/) has three known attributes,
58+
and allows for additional attributes.
59+
The following shows how the attributes are mapped:
60+
61+
| OpenFeature EvaluationContext Field | ConfigCat User Field | Required |
62+
|-------------------------------------|----------------------|----------|
63+
| targetingKey | identifier | yes |
64+
| email | email | no |
65+
| country | country | no |
66+
| _Any Other_ | custom | no |
67+
68+
The custom types are mapped the following way:
69+
70+
| OpenFeature EvaluationContext Field Type | ConfigCat User Field Type |
71+
|------------------------------------------|---------------------------|
72+
| string | string |
73+
| number | number |
74+
| boolean | string |
75+
| Array<string> | Array<string> |
76+
| Array | Array |
77+
| object | string |
78+
79+
The following example shows the conversion between an OpenFeature Evaluation Context and the corresponding ConfigCat
80+
User:
81+
82+
#### OpenFeature
83+
84+
```json
85+
{
86+
"targetingKey": "test",
87+
"email": "email",
88+
"country": "country",
89+
"customString": "customString",
90+
"customNumber": 1,
91+
"customBoolean": true,
92+
"customObject": {
93+
"prop1": "1",
94+
"prop2": 2
95+
},
96+
"customStringArray": [
97+
"one",
98+
"two"
99+
],
100+
"customArray": [
101+
1,
102+
"2",
103+
false
104+
]
105+
}
106+
```
107+
108+
#### ConfigCat
109+
110+
```json
111+
{
112+
"identifier": "test",
113+
"email": "email",
114+
"country": "country",
115+
"custom": {
116+
"customString": "customString",
117+
"customBoolean": "true",
118+
"customNumber": 1,
119+
"customObject": "{\"prop1\":\"1\",\"prop2\":2}",
120+
"customStringArray": [
121+
"one",
122+
"two"
123+
],
124+
"customArray": "[1,\"2\",false]"
125+
}
126+
}
127+
```
128+
129+
## Events
130+
131+
The ConfigCat provider emits the
132+
following [OpenFeature events](https://openfeature.dev/specification/types#provider-events):
133+
134+
- PROVIDER_READY
135+
- PROVIDER_ERROR
136+
- PROVIDER_CONFIGURATION_CHANGED
137+
138+
## Building
139+
140+
Run `nx package providers-config-cat-web` to build the library.
141+
142+
## Running unit tests
143+
144+
Run `nx test providers-config-cat-web` 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-config-cat-web',
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/config-cat',
10+
};

libs/providers/config-cat-web/package-lock.json

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@openfeature/config-cat-web-provider",
3+
"version": "0.6.1",
4+
"scripts": {
5+
"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",
6+
"current-version": "echo $npm_package_version"
7+
},
8+
"peerDependencies": {
9+
"@openfeature/web-sdk": "^1.0.0",
10+
"configcat-js-ssr": "^8.4.1"
11+
}
12+
}

0 commit comments

Comments
 (0)