From 5c519b1aabdd2f9e848ea864e2e6472d78ccd304 Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 4 Jun 2024 16:54:43 -0700 Subject: [PATCH 1/3] =?UTF-8?q?fix(sdk):=20[EPD-2310]=20=F0=9F=92=80=20`ge?= =?UTF-8?q?tBoolAssignment`=20->=20=F0=9F=91=B6=20`getBooleanAssignment`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/eppo-client.spec.ts | 4 +++ src/client/eppo-client.ts | 60 ++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/client/eppo-client.spec.ts b/src/client/eppo-client.spec.ts index aaf1f10..05c0fcb 100644 --- a/src/client/eppo-client.spec.ts +++ b/src/client/eppo-client.spec.ts @@ -104,6 +104,8 @@ describe('EppoClient E2E test', () => { expect(client.getBoolAssignment(flagKey, 'subject-identifer', {}, true)).toBe(true); expect(client.getBoolAssignment(flagKey, 'subject-identifer', {}, false)).toBe(false); + expect(client.getBooleanAssignment(flagKey, 'subject-identifer', {}, true)).toBe(true); + expect(client.getBooleanAssignment(flagKey, 'subject-identifer', {}, false)).toBe(false); expect(client.getNumericAssignment(flagKey, 'subject-identifer', {}, 1)).toBe(1); expect(client.getNumericAssignment(flagKey, 'subject-identifer', {}, 0)).toBe(0); expect(client.getJSONAssignment(flagKey, 'subject-identifer', {}, {})).toEqual({}); @@ -122,6 +124,7 @@ describe('EppoClient E2E test', () => { expect(() => { client.getBoolAssignment(flagKey, 'subject-identifer', {}, true); + client.getBooleanAssignment(flagKey, 'subject-identifer', {}, true); }).toThrow(); expect(() => { @@ -301,6 +304,7 @@ describe('EppoClient E2E test', () => { const nonExistentFlag = 'non-existent-flag'; expect(client.getBoolAssignment(nonExistentFlag, 'subject-identifer', {}, true)).toBe(true); + expect(client.getBooleanAssignment(nonExistentFlag, 'subject-identifer', {}, true)).toBe(true); expect(client.getNumericAssignment(nonExistentFlag, 'subject-identifer', {}, 1)).toBe(1); expect(client.getJSONAssignment(nonExistentFlag, 'subject-identifer', {}, {})).toEqual({}); expect(client.getStringAssignment(nonExistentFlag, 'subject-identifer', {}, 'default')).toBe( diff --git a/src/client/eppo-client.ts b/src/client/eppo-client.ts index 4e940f0..c8b3389 100644 --- a/src/client/eppo-client.ts +++ b/src/client/eppo-client.ts @@ -35,11 +35,12 @@ export interface IEppoClient { /** * Maps a subject to a variation for a given experiment. * - * @param subjectKey an identifier of the experiment subject, for example a user ID. * @param flagKey feature flag identifier + * @param subjectKey an identifier of the experiment subject, for example a user ID. * @param subjectAttributes optional attributes associated with the subject, for example name and email. + * @param defaultValue default value to return if the subject is not part of the experiment sample * The subject attributes are used for evaluating any targeting rules tied to the experiment. - * @returns a variation value if the subject is part of the experiment sample, otherwise null + * @returns a variation value if the subject is part of the experiment sample, otherwise the default value * @public */ getStringAssignment( @@ -49,6 +50,9 @@ export interface IEppoClient { defaultValue: string, ): string; + /** + * @deprecated use getBooleanAssignment instead. + */ getBoolAssignment( flagKey: string, subjectKey: string, @@ -56,6 +60,31 @@ export interface IEppoClient { defaultValue: boolean, ): boolean; + /** + * Maps a subject to a boolean variation for a given experiment. + * + * @param flagKey feature flag identifier + * @param subjectKey an identifier of the experiment subject, for example a user ID. + * @param subjectAttributes optional attributes associated with the subject, for example name and email. + * @param defaultValue default value to return if the subject is not part of the experiment sample + * @returns a boolean variation value if the subject is part of the experiment sample, otherwise the default value + */ + getBooleanAssignment( + flagKey: string, + subjectKey: string, + subjectAttributes: Record, + defaultValue: boolean, + ): boolean; + + /** + * Maps a subject to an Integer variation for a given experiment. + * + * @param flagKey feature flag identifier + * @param subjectKey an identifier of the experiment subject, for example a user ID. + * @param subjectAttributes optional attributes associated with the subject, for example name and email. + * @param defaultValue default value to return if the subject is not part of the experiment sample + * @returns a number variation value if the subject is part of the experiment sample, otherwise the default value + */ getIntegerAssignment( flagKey: string, subjectKey: string, @@ -63,6 +92,15 @@ export interface IEppoClient { defaultValue: number, ): number; + /** + * Maps a subject to a Numeric variation for a given experiment. + * + * @param flagKey feature flag identifier + * @param subjectKey an identifier of the experiment subject, for example a user ID. + * @param subjectAttributes optional attributes associated with the subject, for example name and email. + * @param defaultValue default value to return if the subject is not part of the experiment sample + * @returns a number variation value if the subject is part of the experiment sample, otherwise the default value + */ getNumericAssignment( flagKey: string, subjectKey: string, @@ -70,6 +108,15 @@ export interface IEppoClient { defaultValue: number, ): number; + /** + * Maps a subject to a JSON variation for a given experiment. + * + * @param flagKey feature flag identifier + * @param subjectKey an identifier of the experiment subject, for example a user ID. + * @param subjectAttributes optional attributes associated with the subject, for example name and email. + * @param defaultValue default value to return if the subject is not part of the experiment sample + * @returns a JSON object variation value if the subject is part of the experiment sample, otherwise the default value + */ getJSONAssignment( flagKey: string, subjectKey: string, @@ -232,6 +279,15 @@ export default class EppoClient implements IEppoClient { subjectKey: string, subjectAttributes: Record, defaultValue: boolean, + ): boolean { + return this.getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue); + } + + public getBooleanAssignment( + flagKey: string, + subjectKey: string, + subjectAttributes: Record, + defaultValue: boolean, ): boolean { return ( this.getAssignmentVariation( From 1b39b0b95de260b785f04726f84b7b012391f8a9 Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 4 Jun 2024 17:07:50 -0700 Subject: [PATCH 2/3] code review nits --- src/client/eppo-client.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/eppo-client.spec.ts b/src/client/eppo-client.spec.ts index 05c0fcb..17cca50 100644 --- a/src/client/eppo-client.spec.ts +++ b/src/client/eppo-client.spec.ts @@ -220,7 +220,7 @@ describe('EppoClient E2E test', () => { }[] = []; const typeAssignmentFunctions = { - [VariationType.BOOLEAN]: client.getBoolAssignment.bind(client), + [VariationType.BOOLEAN]: client.getBooleanAssignment.bind(client), [VariationType.NUMERIC]: client.getNumericAssignment.bind(client), [VariationType.INTEGER]: client.getIntegerAssignment.bind(client), [VariationType.STRING]: client.getStringAssignment.bind(client), @@ -267,7 +267,7 @@ describe('EppoClient E2E test', () => { client.setIsGracefulFailureMode(false); const typeAssignmentFunctions = { - [VariationType.BOOLEAN]: client.getBoolAssignment.bind(client), + [VariationType.BOOLEAN]: client.getBooleanAssignment.bind(client), [VariationType.NUMERIC]: client.getNumericAssignment.bind(client), [VariationType.INTEGER]: client.getIntegerAssignment.bind(client), [VariationType.STRING]: client.getStringAssignment.bind(client), From f5a063a91d891097beb099dcfda68deaa1b51d2a Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 4 Jun 2024 17:13:53 -0700 Subject: [PATCH 3/3] bump minor version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6540486..3667365 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eppo/js-client-sdk-common", - "version": "3.0.9", + "version": "3.1.0", "description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)", "main": "dist/index.js", "files": [