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

fix!: Allow ConfigCat provider to be used in server applications #796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions libs/providers/config-cat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ The OpenFeature SDK is required as peer dependency.

The minimum required version of `@openfeature/server-sdk` currently is `1.6.0`.

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

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

## Usage

The ConfigCat provider uses the [ConfigCat Javascript SDK](https://configcat.com/docs/sdk-reference/js/).
The ConfigCat provider uses the [ConfigCat JavaScript (SSR) SDK](https://configcat.com/docs/sdk-reference/js-ssr/).
This means that the provider can be used in both server (e.g. Node.js) and client (browser) applications.

It can either be created by passing the ConfigCat SDK options to ```ConfigCatProvider.create``` or
the ```ConfigCatProvider``` constructor.

The available options can be found in the [ConfigCat Javascript SDK docs](https://configcat.com/docs/sdk-reference/js/).
The available options can be found in the [ConfigCat JavaScript (SSR) SDK](https://configcat.com/docs/sdk-reference/js-ssr/).

### Example using the default configuration

Expand All @@ -53,7 +54,7 @@ OpenFeature.setProvider(provider);
## Evaluation Context

ConfigCat only supports string values in its "evaluation
context", [there known as user](https://configcat.com/docs/advanced/user-object/).
context", [there known as User Object](https://configcat.com/docs/advanced/user-object/).

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.
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/config-cat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"peerDependencies": {
"@openfeature/server-sdk": "^1.8.0",
"configcat-js": "^8.0.0 || ^9.0.0"
"configcat-js-ssr": ">=7.1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
LogLevel,
OverrideBehaviour,
PollingMode,
} from 'configcat-js';
} from 'configcat-js-ssr';

import { IEventEmitter } from 'configcat-common/lib/EventEmitter';

Expand Down
10 changes: 5 additions & 5 deletions libs/providers/config-cat/src/lib/config-cat-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
StandardResolutionReasons,
TypeMismatchError,
} from '@openfeature/server-sdk';
import { getClient, IConfig, IConfigCatClient, IEvaluationDetails, SettingValue } from 'configcat-js';
import { getClient, IConfig, IConfigCatClient, IEvaluationDetails, SettingValue } from 'configcat-js-ssr';
import { transformContext } from './context-transformer';

export class ConfigCatProvider implements Provider {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context),
context.targetingKey != null ? transformContext(context) : undefined,
);

const validatedValue = validateFlagType('boolean', value);
Expand All @@ -121,7 +121,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context),
context.targetingKey != null ? transformContext(context) : undefined,
);

const validatedValue = validateFlagType('string', value);
Expand All @@ -143,7 +143,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
flagKey,
undefined,
transformContext(context),
context.targetingKey != null ? transformContext(context) : undefined,
);

const validatedValue = validateFlagType('number', value);
Expand All @@ -165,7 +165,7 @@ export class ConfigCatProvider implements Provider {
const { value, ...evaluationData } = await this._client.getValueDetailsAsync(
flagKey,
undefined,
transformContext(context),
context.targetingKey != null ? transformContext(context) : undefined,
);

if (typeof value === 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/config-cat/src/lib/context-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EvaluationContext, EvaluationContextValue, TargetingKeyMissingError } from '@openfeature/server-sdk';
import { User as ConfigCatUser } from 'configcat-js';
import { User as ConfigCatUser } from 'configcat-js-ssr';

function contextValueToString(contextValue: EvaluationContextValue): string | undefined {
if (typeof contextValue === 'string') {
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@swc/helpers": "0.5.3",
"ajv": "^8.12.0",
"axios": "1.6.7",
"configcat-js": "^9.0.0",
"configcat-js-ssr": "^8.3.0",
"copy-anything": "^3.0.5",
"imurmurhash": "^0.1.4",
"json-logic-engine": "1.3.1",
Expand Down
Loading