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!: implement config cat web provider #918

Merged
merged 28 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e103bd6
feat: implement config cat web provider
lukas-reining May 25, 2024
cfb1b61
Update libs/providers/config-cat/package.json
lukas-reining May 27, 2024
45b9fb5
Update libs/providers/config-cat-web/package.json
lukas-reining May 27, 2024
41f2a60
feat: use config cat node for server
lukas-reining May 27, 2024
7554e11
Update libs/shared/config-cat-core/src/lib/result-mapping.ts
lukas-reining May 27, 2024
e3d994f
Update libs/shared/config-cat-core/src/lib/result-mapping.ts
lukas-reining May 27, 2024
ec1dfa9
Update README.md
lukas-reining Jun 5, 2024
9c712ae
feat: only allow AutoPoll for ConfigCat Web and change to new context…
lukas-reining Jul 11, 2024
004062c
chore: update package.lock
lukas-reining Jul 11, 2024
919f1c2
feat: fix typing of provider
lukas-reining Jul 11, 2024
b12f596
Update libs/providers/config-cat/src/lib/config-cat-provider.ts
lukas-reining Jul 15, 2024
9b94ae8
Update libs/providers/config-cat/src/lib/config-cat-provider.ts
lukas-reining Jul 15, 2024
e43a77d
Update libs/providers/config-cat/src/lib/config-cat-provider.ts
lukas-reining Jul 15, 2024
02e2da7
Update libs/providers/config-cat/src/lib/config-cat-provider.ts
lukas-reining Jul 15, 2024
5a51ba3
Update libs/providers/config-cat-web/src/lib/config-cat-web-provider.ts
lukas-reining Jul 15, 2024
bf66b09
Update libs/providers/config-cat-web/src/lib/config-cat-web-provider.ts
lukas-reining Jul 15, 2024
a91a670
Update libs/providers/config-cat-web/src/lib/config-cat-web-provider.ts
lukas-reining Jul 15, 2024
4636a02
feat: do not emit READY event from provider
lukas-reining Jul 15, 2024
66960da
feat: fix formatting
lukas-reining Jul 15, 2024
210f17e
Update config-cat-provider.ts
lukas-reining Jul 15, 2024
87c3476
Update config-cat-web-provider.ts
lukas-reining Jul 15, 2024
a98ad0c
Update config-cat-web-provider.ts
lukas-reining Jul 15, 2024
05f5cb6
feat: emit READY event if provider recovers from error
lukas-reining Jul 16, 2024
f6e4e98
Update README.md
lukas-reining Jul 17, 2024
a6ad386
Update README.md
lukas-reining Jul 17, 2024
bf91148
Update README.md
lukas-reining Jul 17, 2024
1fb34fc
fix: fix README and use updateBuildableProjectDepsInPackageJson
lukas-reining Jul 20, 2024
8ff2466
fix: fix imports
lukas-reining Jul 21, 2024
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
18 changes: 18 additions & 0 deletions libs/providers/config-cat-web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Empty file.
148 changes: 148 additions & 0 deletions libs/providers/config-cat-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# ConfigCat Web Provider

This provider is an implementation for [ConfigCat](https://configcat.com) a managed feature flag service.

## Installation

```
$ npm install @openfeature/config-cat-web-provider
```

#### Required peer dependencies

The OpenFeature SDK is required as peer dependency.

The minimum required version of `@openfeature/web-sdk` currently is `1.0.0`.

The minimum required version of `configcat-js-ssr` currently is `7.1.2`.

```
$ npm install @openfeature/client-sdk configcat-js-ssr
```

## Usage

The ConfigCat provider uses the [ConfigCat JavaScript (SSR) SDK](https://configcat.com/docs/sdk-reference/js-ssr/).

It can either be created by passing the ConfigCat SDK options to ```ConfigCatProvider.create``` or
the ```ConfigCatProvider``` constructor.
lukas-reining marked this conversation as resolved.
Show resolved Hide resolved
The available options can be found in the [ConfigCat JavaScript (SSR) SDK](https://configcat.com/docs/sdk-reference/js-ssr/).

The ConfigCat Web Provider only supports the `AutoPolling` mode because it caches all evaluation data to support synchronous evaluation of feature flags.
lukas-reining marked this conversation as resolved.
Show resolved Hide resolved

### Example using the default configuration

```javascript
import { ConfigCatProvider } from '@openfeature/config-cat-web-provider';

const provider = ConfigCatProvider.create('<sdk_key>');
OpenFeature.setProvider(provider);
```

### Example using different polling options and a setupHook

```javascript
import { ConfigCatProvider } from '@openfeature/config-cat-web-provider';

const provider = ConfigCatProvider.create('<sdk_key>', PollingMode.AutoPoll, {
lukas-reining marked this conversation as resolved.
Show resolved Hide resolved
setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')),
});

OpenFeature.setProvider(provider);
```

## Evaluation Context

ConfigCat only supports string values in its "evaluation
context", [there known as User Object](https://configcat.com/docs/advanced/user-object/).
lukas-reining marked this conversation as resolved.
Show resolved Hide resolved

This means that every value is converted to a string. This is trivial for numbers and booleans. Objects and arrays are
converted to JSON strings that can be interpreted in ConfigCat.

ConfigCat has three known attributes, and allows for additional attributes.
The following shows how the attributes are mapped:

| OpenFeature EvaluationContext Field | ConfigCat User Field | Required |
|-------------------------------------|----------------------|----------|
| targetingKey | identifier | yes |
| email | email | no |
| country | country | no |
| _Any Other_ | custom | no |

The custom types are mapped the following way:

| OpenFeature EvaluationContext Field Type | ConfigCat User Field Type |
|------------------------------------------|---------------------------|
| string | string |
| number | number |
| boolean | string |
| Array<string> | Array<string> |
| Array | Array |
| object | string |

The following example shows the conversion between an OpenFeature Evaluation Context and the corresponding ConfigCat
User:

#### OpenFeature

```json
{
"targetingKey": "test",
"email": "email",
"country": "country",
"customString": "customString",
"customNumber": 1,
"customBoolean": true,
"customObject": {
"prop1": "1",
"prop2": 2
},
"customStringArray": [
"one",
"two"
],
"customArray": [
1,
"2",
false
]
}
```

#### ConfigCat

```json
{
"identifier": "test",
"email": "email",
"country": "country",
"custom": {
"customString": "customString",
"customBoolean": "true",
"customNumber": 1,
"customObject": "{\"prop1\":\"1\",\"prop2\":2}",
"customStringArray": [
"one",
"two"
],
"customArray": "[1,\"2\",false]"
}
}
```

## Events

The ConfigCat provider emits the
following [OpenFeature events](https://openfeature.dev/specification/types#provider-events):

- PROVIDER_READY
- PROVIDER_ERROR
- PROVIDER_CONFIGURATION_CHANGED

## Building

Run `nx package providers-config-cat-web` to build the library.

## Running unit tests

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

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

13 changes: 13 additions & 0 deletions libs/providers/config-cat-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@openfeature/config-cat-web-provider",
"version": "0.6.1",
"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",
"@openfeature/config-cat-core": "0.1.0",
lukas-reining marked this conversation as resolved.
Show resolved Hide resolved
"configcat-js-ssr": "^8.4.1"
}
}
Loading
Loading