Skip to content

Commit 6fdf552

Browse files
fix(deps): update dependency configcat-js to v9 (#664)
Signed-off-by: Lukas Reining <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Lukas Reining <[email protected]>
1 parent a2a6171 commit 6fdf552

7 files changed

+35
-23
lines changed

libs/providers/config-cat/package.json

+1-1
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"
10+
"configcat-js": "^8.0.0 || ^9.0.0"
1111
}
1212
}

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ConfigCatProvider } from './config-cat-provider';
22
import { ParseError, ProviderEvents, ProviderStatus, TypeMismatchError } from '@openfeature/server-sdk';
33
import {
4+
ClientCacheState,
45
createConsoleLogger,
56
createFlagOverridesFromMap,
67
HookEvents,
7-
ISetting,
8+
ISettingUnion,
89
LogLevel,
910
OverrideBehaviour,
1011
PollingMode,
@@ -72,9 +73,10 @@ describe('ConfigCatProvider', () => {
7273

7374
describe('status', () => {
7475
it('should be NOT_READY before initialization and READY after successful initialization', async () => {
75-
const newProvider = ConfigCatProvider.create('key', PollingMode.ManualPoll, {
76+
const newProvider = ConfigCatProvider.create('wrong_key', PollingMode.ManualPoll, {
7677
logger: createConsoleLogger(LogLevel.Off),
7778
offline: true,
79+
flagOverrides: createFlagOverridesFromMap(values, OverrideBehaviour.LocalOnly),
7880
});
7981

8082
expect(newProvider.status).toEqual(ProviderStatus.NOT_READY);
@@ -90,7 +92,7 @@ describe('ConfigCatProvider', () => {
9092
it('should set status back to READY if client switches back to ready after an error occured', async () => {
9193
configCatEmitter.emit('clientError', 'Error');
9294
expect(provider.status).toEqual(ProviderStatus.ERROR);
93-
configCatEmitter.emit('clientReady');
95+
configCatEmitter.emit('clientReady', ClientCacheState.HasCachedFlagDataOnly);
9496
expect(provider.status).toEqual(ProviderStatus.READY);
9597
});
9698
});
@@ -99,7 +101,7 @@ describe('ConfigCatProvider', () => {
99101
it('should emit PROVIDER_READY event', () => {
100102
const handler = jest.fn();
101103
provider.events.addHandler(ProviderEvents.Ready, handler);
102-
configCatEmitter.emit('clientReady');
104+
configCatEmitter.emit('clientReady', ClientCacheState.HasCachedFlagDataOnly);
103105
expect(handler).toHaveBeenCalled();
104106
});
105107

@@ -118,7 +120,9 @@ describe('ConfigCatProvider', () => {
118120
});
119121

120122
it('should emit PROVIDER_READY event without options', async () => {
121-
const newProvider = ConfigCatProvider.create('__yet_another_key__', PollingMode.ManualPoll);
123+
const newProvider = ConfigCatProvider.create('__yet_another_key__', PollingMode.ManualPoll, {
124+
flagOverrides: createFlagOverridesFromMap(values, OverrideBehaviour.LocalOnly),
125+
});
122126

123127
const handler = jest.fn();
124128
newProvider.events.addHandler(ProviderEvents.Ready, handler);
@@ -129,7 +133,7 @@ describe('ConfigCatProvider', () => {
129133

130134
it('should emit PROVIDER_CONFIGURATION_CHANGED event', () => {
131135
const handler = jest.fn();
132-
const eventData = { settings: { myFlag: {} as ISetting } };
136+
const eventData = { settings: { myFlag: {} as ISettingUnion }, salt: undefined, segments: [] };
133137

134138
provider.events.addHandler(ProviderEvents.ConfigurationChanged, handler);
135139
configCatEmitter.emit('configChanged', eventData);

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class ConfigCatProvider implements Provider {
8484
}
8585

8686
public async onClose(): Promise<void> {
87-
await this._client?.dispose();
87+
this._client?.dispose();
8888
}
8989

9090
async resolveBooleanEvaluation(
@@ -199,7 +199,11 @@ function toResolutionDetails<U extends JsonValue>(
199199
data: Omit<IEvaluationDetails, 'value'>,
200200
reason?: ResolutionReason,
201201
): ResolutionDetails<U> {
202-
const matchedRule = Boolean(data.matchedEvaluationRule || data.matchedEvaluationPercentageRule);
202+
const matchedTargeting = 'matchedEvaluationRule' in data ? data.matchedEvaluationRule : data.matchedTargetingRule;
203+
const matchedPercentage =
204+
'matchedEvaluationPercentageRule' in data ? data.matchedEvaluationPercentageRule : data.matchedPercentageOption;
205+
206+
const matchedRule = Boolean(matchedTargeting || matchedPercentage);
203207
const evaluatedReason = matchedRule ? StandardResolutionReasons.TARGETING_MATCH : StandardResolutionReasons.STATIC;
204208

205209
return {

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

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ describe('context-transformer', () => {
1818

1919
const user = {
2020
identifier: context['targetingKey'],
21+
country: undefined,
22+
custom: {},
23+
email: undefined,
2124
};
2225

2326
expect(transformContext(context)).toEqual(user);
@@ -34,6 +37,7 @@ describe('context-transformer', () => {
3437
identifier: context['targetingKey'],
3538
email: context['email'],
3639
country: context['country'],
40+
custom: {},
3741
};
3842

3943
expect(transformContext(context)).toEqual(user);

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

+5-5
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-common/lib/RolloutEvaluator';
2+
import { User as ConfigCatUser } from 'configcat-js';
33

44
function contextValueToString(contextValue: EvaluationContextValue): string | undefined {
55
if (typeof contextValue === 'string') {
@@ -21,14 +21,14 @@ function contextValueToString(contextValue: EvaluationContextValue): string | un
2121
return JSON.stringify(contextValue);
2222
}
2323

24-
function transformContextValues(contextValue: EvaluationContextValue): ConfigCatUser['custom'] | undefined {
24+
function transformContextValues(contextValue: EvaluationContextValue): ConfigCatUser['custom'] {
2525
if (contextValue === null) {
26-
return undefined;
26+
return {};
2727
}
2828

2929
if (typeof contextValue !== 'object' || Array.isArray(contextValue)) {
3030
const value = contextValueToString(contextValue);
31-
return value ? { value } : undefined;
31+
return value ? { value } : {};
3232
}
3333

3434
if (contextValue instanceof Date) {
@@ -38,7 +38,7 @@ function transformContextValues(contextValue: EvaluationContextValue): ConfigCat
3838
return Object.entries(contextValue).reduce<ConfigCatUser['custom']>((context, [key, value]) => {
3939
const transformedValue = contextValueToString(value);
4040
return transformedValue ? { ...context, [key]: transformedValue } : context;
41-
}, undefined);
41+
}, {});
4242
}
4343

4444
function stringOrUndefined(param?: unknown): string | undefined {

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
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": "^8.0.0",
27+
"configcat-js": "^9.0.0",
2828
"copy-anything": "^3.0.5",
2929
"imurmurhash": "^0.1.4",
3030
"json-logic-engine": "1.3.1",

0 commit comments

Comments
 (0)