import { IAssignmentLogger } from '../assignment-logger'; import { IBanditLogger } from '../bandit-logger'; import { AssignmentCache } from '../cache/abstract-assignment-cache'; import { IConfigurationStore, ISyncStore } from '../configuration-store/configuration-store'; import { FlagEvaluation } from '../evaluator'; import EventDispatcher from '../events/event-dispatcher'; import { IFlagEvaluationDetails } from '../flag-evaluation-details-builder'; import { BanditParameters, BanditVariation, Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces'; import { Attributes, AttributeType, BanditActions, BanditSubjectAttributes, ContextAttributes, FlagKey, ValueType } from '../types'; export interface IAssignmentDetails { variation: T; action: string | null; evaluationDetails: IFlagEvaluationDetails; } export type FlagConfigurationRequestParameters = { apiKey: string; sdkVersion: string; sdkName: string; baseUrl?: string; requestTimeoutMs?: number; pollingIntervalMs?: number; numInitialRequestRetries?: number; numPollRequestRetries?: number; pollAfterSuccessfulInitialization?: boolean; pollAfterFailedInitialization?: boolean; throwOnFailedInitialization?: boolean; skipInitialPoll?: boolean; }; export interface IContainerExperiment { flagKey: string; controlVariationEntry: T; treatmentVariationEntries: Array; } export type EppoClientParameters = { eventDispatcher?: EventDispatcher; flagConfigurationStore: IConfigurationStore; banditVariationConfigurationStore?: IConfigurationStore; banditModelConfigurationStore?: IConfigurationStore; overrideStore?: ISyncStore; configurationRequestParameters?: FlagConfigurationRequestParameters; /** * Setting this value will have no side effects other than triggering a warning when the actual * configuration's obfuscated does not match the value set here. * * @deprecated obfuscation is determined by inspecting the `format` field of the UFC response. */ isObfuscated?: boolean; }; export default class EppoClient { private eventDispatcher; private readonly assignmentEventsQueue; private readonly banditEventsQueue; private readonly banditEvaluator; private banditLogger?; private banditAssignmentCache?; private configurationRequestParameters?; private banditModelConfigurationStore?; private banditVariationConfigurationStore?; private overrideStore?; private flagConfigurationStore; private assignmentLogger?; private assignmentCache?; private isGracefulFailureMode; private requestPoller?; private readonly evaluator; private configurationRequestor?; private readonly overrideValidator; constructor({ eventDispatcher, isObfuscated, flagConfigurationStore, banditVariationConfigurationStore, banditModelConfigurationStore, overrideStore, configurationRequestParameters, }: EppoClientParameters); private getConfiguration; /** * Validates and parses x-eppo-overrides header sent by Eppo's Chrome extension */ parseOverrides(overridePayload: string | undefined): Promise | undefined>; /** * Creates an EppoClient instance that has the specified overrides applied * to it without affecting the original EppoClient singleton. Useful for * applying overrides in a shared Node instance, such as a web server. */ withOverrides(overrides: Record | undefined): EppoClient; setConfigurationRequestParameters(configurationRequestParameters: FlagConfigurationRequestParameters): void; setFlagConfigurationStore(flagConfigurationStore: IConfigurationStore): void; setBanditVariationConfigurationStore(banditVariationConfigurationStore: IConfigurationStore): void; /** Sets the EventDispatcher instance to use when tracking events with {@link track}. */ setEventDispatcher(eventDispatcher: EventDispatcher): void; /** * Attaches a context to be included with all events dispatched by the EventDispatcher. * The context is delivered as a top-level object in the ingestion request payload. * An existing key can be removed by providing a `null` value. * Calling this method with same key multiple times causes only the last value to be used for the * given key. * * @param key - The context entry key. * @param value - The context entry value, must be a string, number, boolean, or null. If value is * an object or an array, will throw an ArgumentError. */ setContext(key: string, value: string | number | boolean | null): void; setBanditModelConfigurationStore(banditModelConfigurationStore: IConfigurationStore): void; private updateConfigRequestorIfExists; /** * Setting this value will have no side effects other than triggering a warning when the actual * configuration's obfuscated does not match the value set here. * * @deprecated The client determines whether the configuration is obfuscated by inspection * @param isObfuscated */ setIsObfuscated(isObfuscated: boolean): void; setOverrideStore(store: ISyncStore): void; unsetOverrideStore(): void; getOverrideVariationKeys(): Record; fetchFlagConfigurations(): Promise; stopPolling(): void; /** * Maps a subject to a string 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: Attributes, defaultValue: string): string; /** * Maps a subject to a string variation for a given experiment and provides additional details about the * variation assigned and the reason for the assignment. * * @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 an object that includes the variation value along with additional metadata about the assignment * @public */ getStringAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record, defaultValue: string): IAssignmentDetails; /** * @deprecated use getBooleanAssignment instead. */ getBoolAssignment(flagKey: string, subjectKey: string, subjectAttributes: Attributes, 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: Attributes, defaultValue: boolean): boolean; /** * Maps a subject to a boolean variation for a given experiment and provides additional details about the * variation assigned and the reason for the assignment. * * @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 an object that includes the variation value along with additional metadata about the assignment * @public */ getBooleanAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record, defaultValue: boolean): IAssignmentDetails; /** * 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 an integer variation value if the subject is part of the experiment sample, otherwise the default value */ getIntegerAssignment(flagKey: string, subjectKey: string, subjectAttributes: Attributes, defaultValue: number): number; /** * Maps a subject to an Integer variation for a given experiment and provides additional details about the * variation assigned and the reason for the assignment. * * @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 an object that includes the variation value along with additional metadata about the assignment * @public */ getIntegerAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record, defaultValue: number): IAssignmentDetails; /** * 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: Attributes, defaultValue: number): number; /** * Maps a subject to a numeric variation for a given experiment and provides additional details about the * variation assigned and the reason for the assignment. * * @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 an object that includes the variation value along with additional metadata about the assignment * @public */ getNumericAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record, defaultValue: number): IAssignmentDetails; /** * 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: Attributes, defaultValue: object): object; getJSONAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record, defaultValue: object): IAssignmentDetails; getBanditAction(flagKey: string, subjectKey: string, subjectAttributes: BanditSubjectAttributes, actions: BanditActions, defaultValue: string): Omit, 'evaluationDetails'>; /** * Evaluates the supplied actions using the first bandit associated with `flagKey` and returns the best ranked action. * * This method should be considered **preview** and is subject to change as requirements mature. * * NOTE: This method does not do any logging or assignment computation and so calling this method will have * NO IMPACT on bandit and experiment training. * * Only use this method under certain circumstances (i.e. where the impact of the choice of bandit cannot be measured, * but you want to put the "best foot forward", for example, when being web-crawled). * */ getBestAction(flagKey: string, subjectAttributes: BanditSubjectAttributes, actions: BanditActions, defaultAction: string): string; getBanditActionDetails(flagKey: string, subjectKey: string, subjectAttributes: BanditSubjectAttributes, actions: BanditActions, defaultValue: string): IAssignmentDetails; /** * For use with 3rd party CMS tooling, such as the Contentful Eppo plugin. * * CMS plugins that integrate with Eppo will follow a common format for * creating a feature flag. The flag created by the CMS plugin will have * variations with values 'control', 'treatment-1', 'treatment-2', etc. * This function allows users to easily return the CMS container entry * for the assigned variation. * * @param flagExperiment the flag key, control container entry and treatment container entries. * @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. * @returns The container entry associated with the experiment. */ getExperimentContainerEntry(flagExperiment: IContainerExperiment, subjectKey: string, subjectAttributes: Attributes): T; private evaluateBanditAction; private logBanditAction; private getAssignmentVariation; private parseVariationWithDetails; private rethrowIfNotGraceful; private getAllAssignments; /** * Computes and returns assignments and bandits for a subject from all loaded flags. * * @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 banditActions optional attributes associated with the bandit actions * @param salt a salt to use for obfuscation */ getPrecomputedConfiguration(subjectKey: string, subjectAttributes?: Attributes | ContextAttributes, banditActions?: Record, salt?: string): string; /** * [Experimental] Get a detailed return of assignment for a particular subject and flag. * * Note: This method is experimental and may change in future versions. * Please only use for debugging purposes, and not in production. * * @param flagKey The flag key * @param subjectKey The subject key * @param subjectAttributes The subject attributes * @param expectedVariationType The expected variation type * @returns A detailed return of assignment for a particular subject and flag */ getAssignmentDetail(flagKey: string, subjectKey: string, subjectAttributes?: Attributes, expectedVariationType?: VariationType): FlagEvaluation; /** * Enqueues an arbitrary event. Events must have a type and a payload. */ track(type: string, payload: Record): void; private newFlagEvaluationDetailsBuilder; private getNormalizedFlag; private getObfuscatedFlag; getFlagKeys(): string[]; isInitialized(): boolean; /** @deprecated Use `setAssignmentLogger` */ setLogger(logger: IAssignmentLogger): void; setAssignmentLogger(logger: IAssignmentLogger): void; setBanditLogger(logger: IBanditLogger): void; /** * Assignment cache methods. */ disableAssignmentCache(): void; useNonExpiringInMemoryAssignmentCache(): void; useLRUInMemoryAssignmentCache(maxSize: number): void; useCustomAssignmentCache(cache: AssignmentCache): void; disableBanditAssignmentCache(): void; useNonExpiringInMemoryBanditAssignmentCache(): void; /** * @param {number} maxSize - Maximum cache size * @param {number} timeout - TTL of cache entries */ useExpiringInMemoryBanditAssignmentCache(maxSize: number, timeout?: number): void; useCustomBanditAssignmentCache(cache: AssignmentCache): void; setIsGracefulFailureMode(gracefulFailureMode: boolean): void; getFlagConfigurations(): Record; private flushQueuedEvents; private maybeLogAssignment; private buildLoggerMetadata; private computeBanditsForFlags; private getPrecomputedBandit; } export declare function checkTypeMatch(expectedType?: VariationType, actualType?: VariationType): boolean; export declare function checkValueTypeMatch(expectedType: VariationType | undefined, value: ValueType): boolean; //# sourceMappingURL=eppo-client.d.ts.map