Skip to content

Commit dba2a28

Browse files
markphelpsadams85github-actions[bot]aepflitoddbaert
authored
chore(flipt): swap underlying flipt web sdk (#1244)
Signed-off-by: Mark Phelps <[email protected]> Signed-off-by: Simon Schrottner <[email protected]> Co-authored-by: adams85 <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Simon Schrottner <[email protected]> Co-authored-by: Todd Baert <[email protected]>
1 parent 4180281 commit dba2a28

File tree

7 files changed

+309
-596
lines changed

7 files changed

+309
-596
lines changed

libs/providers/flipt-web/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[Flipt](https://www.flipt.io/) is an open source developer friendly feature flagging solution, that allows for easy management and fast feature evaluation.
44

5-
This provider is an implementation on top of the official [Flipt Browser Client Side SDK](https://www.npmjs.com/package/@flipt-io/flipt-client-browser).
5+
This provider is an implementation on top of the official [Flipt JavaScript Client Side SDK](https://www.npmjs.com/package/@flipt-io/flipt-client-js).
66

77
The main difference between this provider and [`@openfeature/flipt-provider`](https://www.npmjs.com/package/@openfeature/flipt-provider) is that it uses a **static evaluation context**.
88
This provider is more sustainable for client-side implementation.

libs/providers/flipt-web/package-lock.json

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

libs/providers/flipt-web/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99
"current-version": "echo $npm_package_version"
1010
},
1111
"peerDependencies": {
12-
"@openfeature/web-sdk": "^1.0.0"
13-
},
14-
"devDependencies": {
15-
"undici": "^6.13.0"
16-
},
17-
"dependencies": {
18-
"@flipt-io/flipt-client-browser": "^0.3.1",
12+
"@openfeature/web-sdk": "^1.0.0",
13+
"@flipt-io/flipt-client-js": "^0.0.1",
1914
"undici": "^5.0.0"
2015
}
2116
}

libs/providers/flipt-web/src/lib/flipt-web-provider.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ describe('FliptWebProvider', () => {
2828
describe('method resolveStringEvaluation', () => {
2929
it('should throw general error for non-existent flag', () => {
3030
expect(() => {
31-
provider.resolveStringEvaluation('nonExistent', 'default', { fizz: 'buzz' });
31+
provider.resolveStringEvaluation('nonExistent', 'default', { targetingKey: '1234', fizz: 'buzz' });
3232
}).toThrow(GeneralError);
3333
});
3434

3535
it('should return right value if key exists', () => {
36-
const value = provider.resolveStringEvaluation('flag_string', 'default', { fizz: 'buzz' });
36+
const value = provider.resolveStringEvaluation('flag_string', 'default', { targetingKey: '1234', fizz: 'buzz' });
3737
expect(value).toHaveProperty('value', 'variant1');
3838
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
3939
});
@@ -42,12 +42,12 @@ describe('FliptWebProvider', () => {
4242
describe('method resolveNumberEvaluation', () => {
4343
it('should throw general error for non-existent flag', () => {
4444
expect(() => {
45-
provider.resolveNumberEvaluation('nonExistent', 1, { fizz: 'buzz' });
45+
provider.resolveNumberEvaluation('nonExistent', 1, { targetingKey: '1234', fizz: 'buzz' });
4646
}).toThrow(GeneralError);
4747
});
4848

4949
it('should return right value if key exists', () => {
50-
const value = provider.resolveNumberEvaluation('flag_number', 0, { fizz: 'buzz' });
50+
const value = provider.resolveNumberEvaluation('flag_number', 0, { targetingKey: '1234', fizz: 'buzz' });
5151
expect(value).toHaveProperty('value', 5);
5252
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
5353
});
@@ -56,12 +56,12 @@ describe('FliptWebProvider', () => {
5656
describe('method resolveBooleanEvaluation', () => {
5757
it('should throw general error for non-existent flag', () => {
5858
expect(() => {
59-
provider.resolveBooleanEvaluation('nonExistent', false, { fizz: 'buzz' });
59+
provider.resolveBooleanEvaluation('nonExistent', false, { targetingKey: '1234', fizz: 'buzz' });
6060
}).toThrow(GeneralError);
6161
});
6262

6363
it('should return right value if key exists', () => {
64-
const value = provider.resolveBooleanEvaluation('flag_boolean', false, { fizz: 'buzz' });
64+
const value = provider.resolveBooleanEvaluation('flag_boolean', false, { targetingKey: '1234', fizz: 'buzz' });
6565
expect(value).toHaveProperty('value', true);
6666
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
6767
});
@@ -70,20 +70,24 @@ describe('FliptWebProvider', () => {
7070
describe('method resolveObjectEvaluation', () => {
7171
it('should throw general error for non-existent flag', () => {
7272
expect(() => {
73-
provider.resolveObjectEvaluation('nonExistent', {}, { fizz: 'buzz' });
73+
provider.resolveObjectEvaluation('nonExistent', {}, { targetingKey: '1234', fizz: 'buzz' });
7474
}).toThrow(GeneralError);
7575
});
7676

7777
it('should return right value if key exists', () => {
78-
const value = provider.resolveObjectEvaluation('flag_object', { fizz: 'buzz' }, { fizz: 'buzz' });
78+
const value = provider.resolveObjectEvaluation(
79+
'flag_object',
80+
{ fizz: 'buzz' },
81+
{ targetingKey: '1234', fizz: 'buzz' },
82+
);
7983
expect(value).toHaveProperty('value', { foo: 'bar' });
8084
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
8185
});
8286
});
8387

8488
it('should throw TypeMismatchError on non-number value', () => {
8589
expect(() => {
86-
provider.resolveNumberEvaluation('flag_string', 0, { fizz: 'buzz' });
90+
provider.resolveNumberEvaluation('flag_string', 0, { targetingKey: '1234', fizz: 'buzz' });
8791
}).toThrow(TypeMismatchError);
8892
});
8993
});

libs/providers/flipt-web/src/lib/flipt-web-provider.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
GeneralError,
1010
ProviderFatalError,
1111
} from '@openfeature/web-sdk';
12-
import { FliptEvaluationClient } from '@flipt-io/flipt-client-browser';
12+
import { FliptClient } from '@flipt-io/flipt-client-js/browser';
1313
import { EvaluationReason, FliptWebProviderOptions } from './models';
1414
import { transformContext } from './context-transformer';
1515

@@ -28,7 +28,7 @@ export class FliptWebProvider implements Provider {
2828
private _options?: FliptWebProviderOptions;
2929

3030
// client is the Flipt client reference
31-
private _client?: FliptEvaluationClient;
31+
private _client?: FliptClient;
3232

3333
readonly runsOn = 'client';
3434

@@ -48,7 +48,8 @@ export class FliptWebProvider implements Provider {
4848

4949
async initializeClient() {
5050
try {
51-
this._client = await FliptEvaluationClient.init(this._namespace || 'default', {
51+
this._client = await FliptClient.init({
52+
namespace: this._namespace || 'default',
5253
url: this._options?.url || 'http://localhost:8080',
5354
fetcher: this._options?.fetcher,
5455
authentication: this._options?.authentication,
@@ -70,7 +71,11 @@ export class FliptWebProvider implements Provider {
7071
const evalContext: Record<string, string> = transformContext(context);
7172

7273
try {
73-
const result = this._client?.evaluateBoolean(flagKey, context.targetingKey ?? '', evalContext);
74+
const result = this._client?.evaluateBoolean({
75+
flagKey,
76+
entityId: context.targetingKey ?? '',
77+
context: evalContext,
78+
});
7479

7580
switch (result?.reason) {
7681
case EvaluationReason.DEFAULT:
@@ -135,7 +140,11 @@ export class FliptWebProvider implements Provider {
135140
const evalContext: Record<string, string> = transformContext(context);
136141

137142
try {
138-
const result = this._client?.evaluateVariant(flagKey, context.targetingKey ?? '', evalContext);
143+
const result = this._client?.evaluateVariant({
144+
flagKey,
145+
entityId: context.targetingKey ?? '',
146+
context: evalContext,
147+
});
139148

140149
if (result?.reason === EvaluationReason.FLAG_DISABLED) {
141150
return {

0 commit comments

Comments
 (0)