Skip to content

Commit 190946f

Browse files
adams85Adam Simon
and
Adam Simon
authored
fix!: Allow ConfigCat provider to be used in server applications (#796)
Signed-off-by: Adam Simon <[email protected]> Co-authored-by: Adam Simon <[email protected]>
1 parent 5113e6f commit 190946f

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

libs/providers/config-cat/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ The OpenFeature SDK is required as peer dependency.
1414

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

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

1919
```
20-
$ npm install @openfeature/server-sdk configcat-js
20+
$ npm install @openfeature/server-sdk configcat-js-ssr
2121
```
2222

2323
## Usage
2424

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

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

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

3233
### Example using the default configuration
3334

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

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

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

libs/providers/config-cat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"peerDependencies": {
99
"@openfeature/server-sdk": "^1.8.0",
10-
"configcat-js": "^8.0.0 || ^9.0.0"
10+
"configcat-js-ssr": ">=7.1.2"
1111
}
1212
}

libs/providers/config-cat/src/lib/config-cat-provider.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
LogLevel,
1010
OverrideBehaviour,
1111
PollingMode,
12-
} from 'configcat-js';
12+
} from 'configcat-js-ssr';
1313

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

libs/providers/config-cat/src/lib/config-cat-provider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
StandardResolutionReasons,
1313
TypeMismatchError,
1414
} from '@openfeature/server-sdk';
15-
import { getClient, IConfig, IConfigCatClient, IEvaluationDetails, SettingValue } from 'configcat-js';
15+
import { getClient, IConfig, IConfigCatClient, IEvaluationDetails, SettingValue } from 'configcat-js-ssr';
1616
import { transformContext } from './context-transformer';
1717

1818
export class ConfigCatProvider implements Provider {
@@ -99,7 +99,7 @@ export class ConfigCatProvider implements Provider {
9999
const { value, ...evaluationData } = await this._client.getValueDetailsAsync<SettingValue>(
100100
flagKey,
101101
undefined,
102-
transformContext(context),
102+
context.targetingKey != null ? transformContext(context) : undefined,
103103
);
104104

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

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

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

171171
if (typeof value === 'undefined') {

libs/providers/config-cat/src/lib/context-transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EvaluationContext, EvaluationContextValue, TargetingKeyMissingError } from '@openfeature/server-sdk';
2-
import { User as ConfigCatUser } from 'configcat-js';
2+
import { User as ConfigCatUser } from 'configcat-js-ssr';
33

44
function contextValueToString(contextValue: EvaluationContextValue): string | undefined {
55
if (typeof contextValue === 'string') {

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@swc/helpers": "0.5.3",
2525
"ajv": "^8.12.0",
2626
"axios": "1.6.7",
27-
"configcat-js": "^9.0.0",
27+
"configcat-js-ssr": "^8.3.0",
2828
"copy-anything": "^3.0.5",
2929
"imurmurhash": "^0.1.4",
3030
"json-logic-engine": "1.3.1",

0 commit comments

Comments
 (0)