import { ParameterConfig, EmptyParameterConfiguration, ParameterConfiguration, } from './ParameterConfig'; import type { VariationKey } from './Common'; import type { ReactNativeDecision } from '../client'; export class Decision implements ParameterConfig { variation: VariationKey; reason: DecisionReason; config: ParameterConfig; constructor( variation: VariationKey, reason: DecisionReason, config: ParameterConfig ) { this.variation = variation; this.reason = reason; this.config = config; } static of( variation: VariationKey, reason: DecisionReason, config: ParameterConfig = new EmptyParameterConfiguration() ) { return new Decision(variation, reason, config); } static withReactNativeDecision(decision: ReactNativeDecision): Decision { return new Decision( decision.variation, decision.reason, new ParameterConfiguration(decision.parameters) ); } getSync( key: string, defaultValue: string | number | boolean ): string | number | boolean { return this.config.getSync(key, defaultValue); } } /** * Describes the reason for the [Variation] decision. */ export enum DecisionReason { /** * Indicates that the sdk is not ready to use. e.g., invalid SDK key. */ SDK_NOT_READY = 'SDK_NOT_READY', /** * Indicates that the variation could not be decided due to an unexpected exception. */ EXCEPTION = 'EXCEPTION', /** * Indicates that the input value is invalid. */ INVALID_INPUT = 'INVALID_INPUT', /** * Indicates that no experiment was found for the experiment key provided by the caller. */ EXPERIMENT_NOT_FOUND = 'EXPERIMENT_NOT_FOUND', /** * Indicates that the experiment is in draft. */ EXPERIMENT_DRAFT = 'EXPERIMENT_DRAFT', /** * Indicates that the experiment was paused. */ EXPERIMENT_PAUSED = 'EXPERIMENT_PAUSED', /** * Indicates that the experiment was completed. */ EXPERIMENT_COMPLETED = 'EXPERIMENT_COMPLETED', /** * Indicates that the user has been overridden as a specific variation. */ OVERRIDDEN = 'OVERRIDDEN', /** * Indicates that the experiment is running, but the user is not allocated to the experiment. */ TRAFFIC_NOT_ALLOCATED = 'TRAFFIC_NOT_ALLOCATED', /** * Indicates that the user does not qualify as the target user for the A/B test. */ NOT_IN_MUTUAL_EXCLUSION_EXPERIMENT = 'NOT_IN_MUTUAL_EXCLUSION_EXPERIMENT', /** * Indicates that the user identifier information required for A/B test assignment is missing. */ IDENTIFIER_NOT_FOUND = 'IDENTIFIER_NOT_FOUND', /** * Indicates that the original decided variation has been dropped. */ VARIATION_DROPPED = 'VARIATION_DROPPED', /** * Indicates that the user has been allocated to the experiment. */ TRAFFIC_ALLOCATED = 'TRAFFIC_ALLOCATED', /** * Indicates that traffic was allocated by targeting from another experiment. */ TRAFFIC_ALLOCATED_BY_TARGETING = 'TRAFFIC_ALLOCATED_BY_TARGETING', /** * Indicates that the user is not the target of the experiment. */ NOT_IN_EXPERIMENT_TARGET = 'NOT_IN_EXPERIMENT_TARGET', /** * Indicates that no feature flag was found for the feature key provided by the caller. */ FEATURE_FLAG_NOT_FOUND = 'FEATURE_FLAG_NOT_FOUND', /** * Indicates that the feature flag is inactive. */ FEATURE_FLAG_INACTIVE = 'FEATURE_FLAG_INACTIVE', /** * Indicates that the user is matched to the individual target of the feature flag. */ INDIVIDUAL_TARGET_MATCH = 'INDIVIDUAL_TARGET_MATCH', /** * Indicates that the user is matched to the target rule of the feature flag. */ TARGET_RULE_MATCH = 'TARGET_RULE_MATCH', /** * Indicates that the user did not match any individual targets or target rules. */ DEFAULT_RULE = 'DEFAULT_RULE', /** * Indicates that no remote config parameter was found for the parameter key provided by the caller. */ REMOTE_CONFIG_PARAMETER_NOT_FOUND = 'REMOTE_CONFIG_PARAMETER_NOT_FOUND', /** * Indicates a mismatch between the result type and request type. */ TYPE_MISMATCH = 'TYPE_MISMATCH', /** * Indicates that the inapp message unsupported this platform. */ UNSUPPORTED_PLATFORM = 'UNSUPPORTED_PLATFORM', /** * Indicates that the inapp message is not found. */ IN_APP_MESSAGE_NOT_FOUND = 'IN_APP_MESSAGE_NOT_FOUND', /** * Indicates that the inapp message is in draft. */ IN_APP_MESSAGE_DRAFT = 'IN_APP_MESSAGE_DRAFT', /** * Indicates that the inapp message is paused. */ IN_APP_MESSAGE_PAUSED = 'IN_APP_MESSAGE_PAUSED', /** * Indicates that the in-app message is hidden because the user selected to hide it for one day. */ IN_APP_MESSAGE_HIDDEN = 'IN_APP_MESSAGE_HIDDEN', /** * Indicates that the inapp message is show */ IN_APP_MESSAGE_TARGET = 'IN_APP_MESSAGE_TARGET', /** * Indicates that the in-app message is not within the display period. */ NOT_IN_IN_APP_MESSAGE_PERIOD = 'NOT_IN_IN_APP_MESSAGE_PERIOD', /** * Indicates that the user is not a target for the in-app message. */ NOT_IN_IN_APP_MESSAGE_TARGET = 'NOT_IN_IN_APP_MESSAGE_TARGET', /** * Indicates that the in-app message display frequency cap has been reached. */ IN_APP_MESSAGE_FREQUENCY_CAPPED = 'IN_APP_MESSAGE_FREQUENCY_CAPPED', /** * Indicates that the user is in the experiment control group. */ EXPERIMENT_CONTROL_GROUP = 'EXPERIMENT_CONTROL_GROUP', }