Skip to content

Commit

Permalink
fix(sdk): [EPD-2310] 💀 getBoolAssignment -> 👶 getBooleanAssignment (
Browse files Browse the repository at this point in the history
#72)

* fix(sdk): [EPD-2310] 💀 `getBoolAssignment` -> 👶 `getBooleanAssignment`

* code review nits

* bump minor version
  • Loading branch information
felipecsl authored Jun 5, 2024
1 parent 073ac24 commit c3795e3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
8 changes: 6 additions & 2 deletions src/client/eppo-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand All @@ -122,6 +124,7 @@ describe('EppoClient E2E test', () => {

expect(() => {
client.getBoolAssignment(flagKey, 'subject-identifer', {}, true);
client.getBooleanAssignment(flagKey, 'subject-identifer', {}, true);
}).toThrow();

expect(() => {
Expand Down Expand Up @@ -217,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),
Expand Down Expand Up @@ -264,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),
Expand Down Expand Up @@ -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(
Expand Down
60 changes: 58 additions & 2 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -49,27 +50,73 @@ export interface IEppoClient {
defaultValue: string,
): string;

/**
* @deprecated use getBooleanAssignment instead.
*/
getBoolAssignment(
flagKey: string,
subjectKey: string,
subjectAttributes: Record<string, AttributeType>,
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<string, AttributeType>,
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,
subjectAttributes: Record<string, AttributeType>,
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,
subjectAttributes: Record<string, AttributeType>,
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,
Expand Down Expand Up @@ -232,6 +279,15 @@ export default class EppoClient implements IEppoClient {
subjectKey: string,
subjectAttributes: Record<string, AttributeType>,
defaultValue: boolean,
): boolean {
return this.getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue);
}

public getBooleanAssignment(
flagKey: string,
subjectKey: string,
subjectAttributes: Record<string, AttributeType>,
defaultValue: boolean,
): boolean {
return (
this.getAssignmentVariation(
Expand Down

0 comments on commit c3795e3

Please sign in to comment.