Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FF-2465 Evaluation Reasons #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
172 changes: 51 additions & 121 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,126 +27,6 @@ import { AttributeType, ValueType } from '../types';
import { validateNotBlank } from '../validation';
import { LIB_VERSION } from '../version';

/**
* Client for assigning experiment variations.
* @public
*/
export interface IEppoClient {
/**
* Maps a subject to a 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
* 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 the default value
* @public
*/
getStringAssignment(
flagKey: string,
subjectKey: string,
subjectAttributes: Record<string, AttributeType>,
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,
subjectAttributes: Record<string, AttributeType>,
defaultValue: object,
): object;

setLogger(logger: IAssignmentLogger): void;

useLRUInMemoryAssignmentCache(maxSize: number): void;

useCustomAssignmentCache(cache: AssignmentCache): void;

setConfigurationRequestParameters(
configurationRequestParameters: FlagConfigurationRequestParameters,
): void;

setConfigurationStore(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>): void;

fetchFlagConfigurations(): void;

stopPolling(): void;

setIsGracefulFailureMode(gracefulFailureMode: boolean): void;

getFlagKeys(): string[];

isInitialized(): boolean;
}

export type FlagConfigurationRequestParameters = {
apiKey: string;
sdkVersion: string;
Expand All @@ -161,7 +41,7 @@ export type FlagConfigurationRequestParameters = {
skipInitialPoll?: boolean;
};

export default class EppoClient implements IEppoClient {
export default class EppoClient {
private queuedEvents: IAssignmentEvent[] = [];
private assignmentLogger?: IAssignmentLogger;
private isGracefulFailureMode = true;
Expand Down Expand Up @@ -247,6 +127,17 @@ export default class EppoClient implements IEppoClient {
}
}

/**
* Maps a subject to a 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
* 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 the default value
* @public
*/
public getStringAssignment(
flagKey: string,
subjectKey: string,
Expand All @@ -264,6 +155,9 @@ export default class EppoClient implements IEppoClient {
);
}

/**
* @deprecated use getBooleanAssignment instead.
*/
public getBoolAssignment(
flagKey: string,
subjectKey: string,
Expand All @@ -273,6 +167,15 @@ export default class EppoClient implements IEppoClient {
return this.getBooleanAssignment(flagKey, subjectKey, subjectAttributes, defaultValue);
}

/**
* 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
*/
public getBooleanAssignment(
flagKey: string,
subjectKey: string,
Expand All @@ -290,6 +193,15 @@ export default class EppoClient implements IEppoClient {
);
}

/**
* 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
*/
public getIntegerAssignment(
flagKey: string,
subjectKey: string,
Expand All @@ -307,6 +219,15 @@ export default class EppoClient implements IEppoClient {
);
}

/**
* 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
*/
public getNumericAssignment(
flagKey: string,
subjectKey: string,
Expand All @@ -324,6 +245,15 @@ export default class EppoClient implements IEppoClient {
);
}

/**
* 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
*/
public getJSONAssignment(
flagKey: string,
subjectKey: string,
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
assignmentCacheKeyToString,
assignmentCacheValueToString,
} from './cache/abstract-assignment-cache';
import EppoClient, { FlagConfigurationRequestParameters, IEppoClient } from './client/eppo-client';
import EppoClient, { FlagConfigurationRequestParameters } from './client/eppo-client';
import {
IConfigurationStore,
IAsyncStore,
Expand All @@ -35,7 +35,6 @@ export {
IAssignmentLogger,
IAssignmentEvent,
EppoClient,
IEppoClient,
constants,
FlagConfigRequestor,
HttpClient,
Expand Down
Loading