Skip to content

Commit c3795e3

Browse files
authored
fix(sdk): [EPD-2310] 💀 getBoolAssignment -> 👶 getBooleanAssignment (#72)
* fix(sdk): [EPD-2310] 💀 `getBoolAssignment` -> 👶 `getBooleanAssignment` * code review nits * bump minor version
1 parent 073ac24 commit c3795e3

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "3.0.9",
3+
"version": "3.1.0",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [

‎src/client/eppo-client.spec.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ describe('EppoClient E2E test', () => {
104104

105105
expect(client.getBoolAssignment(flagKey, 'subject-identifer', {}, true)).toBe(true);
106106
expect(client.getBoolAssignment(flagKey, 'subject-identifer', {}, false)).toBe(false);
107+
expect(client.getBooleanAssignment(flagKey, 'subject-identifer', {}, true)).toBe(true);
108+
expect(client.getBooleanAssignment(flagKey, 'subject-identifer', {}, false)).toBe(false);
107109
expect(client.getNumericAssignment(flagKey, 'subject-identifer', {}, 1)).toBe(1);
108110
expect(client.getNumericAssignment(flagKey, 'subject-identifer', {}, 0)).toBe(0);
109111
expect(client.getJSONAssignment(flagKey, 'subject-identifer', {}, {})).toEqual({});
@@ -122,6 +124,7 @@ describe('EppoClient E2E test', () => {
122124

123125
expect(() => {
124126
client.getBoolAssignment(flagKey, 'subject-identifer', {}, true);
127+
client.getBooleanAssignment(flagKey, 'subject-identifer', {}, true);
125128
}).toThrow();
126129

127130
expect(() => {
@@ -217,7 +220,7 @@ describe('EppoClient E2E test', () => {
217220
}[] = [];
218221

219222
const typeAssignmentFunctions = {
220-
[VariationType.BOOLEAN]: client.getBoolAssignment.bind(client),
223+
[VariationType.BOOLEAN]: client.getBooleanAssignment.bind(client),
221224
[VariationType.NUMERIC]: client.getNumericAssignment.bind(client),
222225
[VariationType.INTEGER]: client.getIntegerAssignment.bind(client),
223226
[VariationType.STRING]: client.getStringAssignment.bind(client),
@@ -264,7 +267,7 @@ describe('EppoClient E2E test', () => {
264267
client.setIsGracefulFailureMode(false);
265268

266269
const typeAssignmentFunctions = {
267-
[VariationType.BOOLEAN]: client.getBoolAssignment.bind(client),
270+
[VariationType.BOOLEAN]: client.getBooleanAssignment.bind(client),
268271
[VariationType.NUMERIC]: client.getNumericAssignment.bind(client),
269272
[VariationType.INTEGER]: client.getIntegerAssignment.bind(client),
270273
[VariationType.STRING]: client.getStringAssignment.bind(client),
@@ -301,6 +304,7 @@ describe('EppoClient E2E test', () => {
301304
const nonExistentFlag = 'non-existent-flag';
302305

303306
expect(client.getBoolAssignment(nonExistentFlag, 'subject-identifer', {}, true)).toBe(true);
307+
expect(client.getBooleanAssignment(nonExistentFlag, 'subject-identifer', {}, true)).toBe(true);
304308
expect(client.getNumericAssignment(nonExistentFlag, 'subject-identifer', {}, 1)).toBe(1);
305309
expect(client.getJSONAssignment(nonExistentFlag, 'subject-identifer', {}, {})).toEqual({});
306310
expect(client.getStringAssignment(nonExistentFlag, 'subject-identifer', {}, 'default')).toBe(

‎src/client/eppo-client.ts‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ export interface IEppoClient {
3535
/**
3636
* Maps a subject to a variation for a given experiment.
3737
*
38-
* @param subjectKey an identifier of the experiment subject, for example a user ID.
3938
* @param flagKey feature flag identifier
39+
* @param subjectKey an identifier of the experiment subject, for example a user ID.
4040
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
41+
* @param defaultValue default value to return if the subject is not part of the experiment sample
4142
* The subject attributes are used for evaluating any targeting rules tied to the experiment.
42-
* @returns a variation value if the subject is part of the experiment sample, otherwise null
43+
* @returns a variation value if the subject is part of the experiment sample, otherwise the default value
4344
* @public
4445
*/
4546
getStringAssignment(
@@ -49,27 +50,73 @@ export interface IEppoClient {
4950
defaultValue: string,
5051
): string;
5152

53+
/**
54+
* @deprecated use getBooleanAssignment instead.
55+
*/
5256
getBoolAssignment(
5357
flagKey: string,
5458
subjectKey: string,
5559
subjectAttributes: Record<string, AttributeType>,
5660
defaultValue: boolean,
5761
): boolean;
5862

63+
/**
64+
* Maps a subject to a boolean variation for a given experiment.
65+
*
66+
* @param flagKey feature flag identifier
67+
* @param subjectKey an identifier of the experiment subject, for example a user ID.
68+
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
69+
* @param defaultValue default value to return if the subject is not part of the experiment sample
70+
* @returns a boolean variation value if the subject is part of the experiment sample, otherwise the default value
71+
*/
72+
getBooleanAssignment(
73+
flagKey: string,
74+
subjectKey: string,
75+
subjectAttributes: Record<string, AttributeType>,
76+
defaultValue: boolean,
77+
): boolean;
78+
79+
/**
80+
* Maps a subject to an Integer variation for a given experiment.
81+
*
82+
* @param flagKey feature flag identifier
83+
* @param subjectKey an identifier of the experiment subject, for example a user ID.
84+
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
85+
* @param defaultValue default value to return if the subject is not part of the experiment sample
86+
* @returns a number variation value if the subject is part of the experiment sample, otherwise the default value
87+
*/
5988
getIntegerAssignment(
6089
flagKey: string,
6190
subjectKey: string,
6291
subjectAttributes: Record<string, AttributeType>,
6392
defaultValue: number,
6493
): number;
6594

95+
/**
96+
* Maps a subject to a Numeric variation for a given experiment.
97+
*
98+
* @param flagKey feature flag identifier
99+
* @param subjectKey an identifier of the experiment subject, for example a user ID.
100+
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
101+
* @param defaultValue default value to return if the subject is not part of the experiment sample
102+
* @returns a number variation value if the subject is part of the experiment sample, otherwise the default value
103+
*/
66104
getNumericAssignment(
67105
flagKey: string,
68106
subjectKey: string,
69107
subjectAttributes: Record<string, AttributeType>,
70108
defaultValue: number,
71109
): number;
72110

111+
/**
112+
* Maps a subject to a JSON variation for a given experiment.
113+
*
114+
* @param flagKey feature flag identifier
115+
* @param subjectKey an identifier of the experiment subject, for example a user ID.
116+
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
117+
* @param defaultValue default value to return if the subject is not part of the experiment sample
118+
* @returns a JSON object variation value if the subject is part of the experiment sample, otherwise the default value
119+
*/
73120
getJSONAssignment(
74121
flagKey: string,
75122
subjectKey: string,
@@ -232,6 +279,15 @@ export default class EppoClient implements IEppoClient {
232279
subjectKey: string,
233280
subjectAttributes: Record<string, AttributeType>,
234281
defaultValue: boolean,
282+
): boolean {
283+
return this.getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue);
284+
}
285+
286+
public getBooleanAssignment(
287+
flagKey: string,
288+
subjectKey: string,
289+
subjectAttributes: Record<string, AttributeType>,
290+
defaultValue: boolean,
235291
): boolean {
236292
return (
237293
this.getAssignmentVariation(

0 commit comments

Comments
 (0)