UNPKG

opticks

Version:

FindHotel Toggle Flag JavaScript SDK

109 lines (105 loc) 4.62 kB
import * as _optimizely_optimizely_sdk_dist_utils_enums from '@optimizely/optimizely-sdk/dist/utils/enums'; import { ListenerPayload, NotificationListener, EventDispatcher, Client } from '@optimizely/optimizely-sdk'; import { T as ToggleIdType, V as VariantType, a as ToggleFuncReturnType } from './types-800f549e.js'; type UserIdType = string; type AudienceSegmentationAttributeKeyType = string; type AudienceSegmentationAttributeValueType = string | boolean; type AudienceSegmentationAttributesType = { [key in AudienceSegmentationAttributeKeyType]?: AudienceSegmentationAttributeValueType; }; type ExperimentToggleValueType = string | boolean; type OptimizelyDatafileType = object; declare const NOTIFICATION_TYPES: typeof _optimizely_optimizely_sdk_dist_utils_enums.NOTIFICATION_TYPES; /** * Registers an externally passed in OptimizelySDK library to use. * This is meant to give flexibility in which SDK to use, but since Opticks * now relies on a specific version this will be bundled in future versions. * * @param lib OptimizelySDK */ declare const registerLibrary: (lib: any) => void; /** * Adds / removes Toggles to force from the forcedToggles list * * @param toggleKeyValues */ declare const forceToggles: (toggleKeyValues: { [x: string]: ExperimentToggleValueType; }) => void; /** * Sets the userId and invalidates caches so each toggle will * be re-evaluated in the next call. * * @param id */ declare const setUserId: (id: UserIdType) => void; /** * Sets audience segmentation attributes and invalidates caches * so each toggle will be re-evaluated in the next call. * * @param attributes */ declare const setAudienceSegmentationAttributes: (attributes?: AudienceSegmentationAttributesType) => void; /** * Clears all audience segmentation attributes and invalidates caches * so each toggle will be re-evaluated in the next call. */ declare const resetAudienceSegmentationAttributes: () => void; declare enum ExperimentType { flag = "flag", mvt = "feature-test" } /** * REVIEW: This decisionInfo payload cannot be found anywhere in the types in the SDK. * However the information typed here is sent, the payload changes based on whether it is a feature flag or MVT, so typing it here. * https://github.com/optimizely/javascript-sdk/blob/625cb7c3835e31e25b16fa34b5f25a2bda42ed57/packages/optimizely-sdk/lib/optimizely/index.ts#L1577 * * It would be best if Opticks abstracts this difference from the client in future versions. */ interface ActivateNotificationPayload extends ListenerPayload { type: ExperimentType; decisionInfo: { flagKey: ToggleIdType; variationKey: VariantType; }; } /** * Initializes Opticks with the supplied Optimizely datafile, * and allows for registering experimentDecision handlers and custom * event dispatcher. * * @param datafile Optimizely Rollouts JSON datafile * @param onExperimentDecision Experiment decision listener * @param eventDispatcher Custom event dispatcher * @returns Optimizely Instance */ declare const initialize: (datafile: OptimizelyDatafileType, onExperimentDecision?: NotificationListener<ActivateNotificationPayload>, eventDispatcher?: EventDispatcher) => Client; /** * Registers custom decision listener * * @param listener * @returns void */ declare const addActivateListener: (listener: NotificationListener<ActivateNotificationPayload>) => number; /** * Determines whether a user satisfies the audience requirements for a toggle. * Since it uses an internal method of the SDK this unfortunately ties Opticks to * the specific Optimizely SDK version. * * @param toggleId */ declare const isUserInRolloutAudience: (toggleId: ToggleIdType) => any; /** * Returns the active value, or executes the active function if an arrow function is passed. * * Variants can be either values, in which case they both should be of the same type, * or arrow functions which will be executed for the winning side, the return type is unknown * on purpose since it's expected the return value will likely be implicit. * * When mixing values and function variants, the return type is unknown and needs to be cast. * * @param toggleId * @param variants */ declare function toggle<A extends any[]>(toggleId: ToggleIdType, ...variants: A): ToggleFuncReturnType<A>; export { ActivateNotificationPayload, ExperimentType, NOTIFICATION_TYPES, OptimizelyDatafileType, ToggleIdType, VariantType, addActivateListener, forceToggles, initialize, isUserInRolloutAudience, registerLibrary, resetAudienceSegmentationAttributes, setAudienceSegmentationAttributes, setUserId, toggle };