UNPKG

@optimizely/optimizely-sdk

Version:
1 lines 61.3 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@optimizely/js-sdk-logging"),r=require("@optimizely/js-sdk-utils"),i=require("@optimizely/js-sdk-datafile-manager"),n=(e=require("murmurhash"))&&"object"==typeof e&&"default"in e?e.default:e,o=require("@optimizely/js-sdk-event-processor"),a={NOTSET:0,DEBUG:1,INFO:2,WARNING:3,ERROR:4},s={CONDITION_EVALUATOR_ERROR:"%s: Error evaluating audience condition of type %s: %s",DATAFILE_AND_SDK_KEY_MISSING:"%s: You must provide at least one of sdkKey or datafile. Cannot start Optimizely",EXPERIMENT_KEY_NOT_IN_DATAFILE:"%s: Experiment key %s is not in datafile.",FEATURE_NOT_IN_DATAFILE:"%s: Feature key %s is not in datafile.",IMPROPERLY_FORMATTED_EXPERIMENT:"%s: Experiment key %s is improperly formatted.",INVALID_ATTRIBUTES:"%s: Provided attributes are in an invalid format.",INVALID_BUCKETING_ID:"%s: Unable to generate hash for bucketing ID %s: %s",INVALID_DATAFILE:"%s: Datafile is invalid - property %s: %s",INVALID_DATAFILE_MALFORMED:"%s: Datafile is invalid because it is malformed.",INVALID_CONFIG:"%s: Provided Optimizely config is in an invalid format.",INVALID_JSON:"%s: JSON object is not valid.",INVALID_ERROR_HANDLER:'%s: Provided "errorHandler" is in an invalid format.',INVALID_EVENT_DISPATCHER:'%s: Provided "eventDispatcher" is in an invalid format.',INVALID_EVENT_TAGS:"%s: Provided event tags are in an invalid format.",INVALID_EXPERIMENT_KEY:"%s: Experiment key %s is not in datafile. It is either invalid, paused, or archived.",INVALID_EXPERIMENT_ID:"%s: Experiment ID %s is not in datafile.",INVALID_GROUP_ID:"%s: Group ID %s is not in datafile.",INVALID_LOGGER:'%s: Provided "logger" is in an invalid format.',INVALID_ROLLOUT_ID:"%s: Invalid rollout ID %s attached to feature %s",INVALID_USER_ID:"%s: Provided user ID is in an invalid format.",INVALID_USER_PROFILE_SERVICE:"%s: Provided user profile service instance is in an invalid format: %s.",NO_DATAFILE_SPECIFIED:"%s: No datafile specified. Cannot start optimizely.",NO_JSON_PROVIDED:"%s: No JSON object to validate against schema.",NO_VARIATION_FOR_EXPERIMENT_KEY:"%s: No variation key %s defined in datafile for experiment %s.",UNDEFINED_ATTRIBUTE:"%s: Provided attribute: %s has an undefined value.",UNRECOGNIZED_ATTRIBUTE:"%s: Unrecognized attribute %s provided. Pruning before sending event to Optimizely.",UNABLE_TO_CAST_VALUE:"%s: Unable to cast value %s to type %s, returning null.",USER_NOT_IN_FORCED_VARIATION:"%s: User %s is not in the forced variation map. Cannot remove their forced variation.",USER_PROFILE_LOOKUP_ERROR:'%s: Error while looking up user profile for user ID "%s": %s.',USER_PROFILE_SAVE_ERROR:'%s: Error while saving user profile for user ID "%s": %s.',VARIABLE_KEY_NOT_IN_DATAFILE:'%s: Variable with key "%s" associated with feature with key "%s" is not in datafile.',VARIATION_ID_NOT_IN_DATAFILE:"%s: No variation ID %s defined in datafile for experiment %s.",VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT:"%s: Variation ID %s is not in the datafile.",INVALID_INPUT_FORMAT:"%s: Provided %s is in an invalid format.",INVALID_DATAFILE_VERSION:"%s: This version of the JavaScript SDK does not support the given datafile version: %s",INVALID_VARIATION_KEY:"%s: Provided variation key is in an invalid format."},l={ACTIVATE_USER:"%s: Activating user %s in experiment %s.",DISPATCH_CONVERSION_EVENT:"%s: Dispatching conversion event to URL %s with params %s.",DISPATCH_IMPRESSION_EVENT:"%s: Dispatching impression event to URL %s with params %s.",DEPRECATED_EVENT_VALUE:"%s: Event value is deprecated in %s call.",EVENT_KEY_NOT_FOUND:"%s: Event key %s is not in datafile.",EXPERIMENT_NOT_RUNNING:"%s: Experiment %s is not running.",FEATURE_ENABLED_FOR_USER:"%s: Feature %s is enabled for user %s.",FEATURE_NOT_ENABLED_FOR_USER:"%s: Feature %s is not enabled for user %s.",FEATURE_HAS_NO_EXPERIMENTS:"%s: Feature %s is not attached to any experiments.",FAILED_TO_PARSE_VALUE:'%s: Failed to parse event value "%s" from event tags.',FAILED_TO_PARSE_REVENUE:'%s: Failed to parse revenue value "%s" from event tags.',FORCED_BUCKETING_FAILED:"%s: Variation key %s is not in datafile. Not activating user %s.",INVALID_OBJECT:"%s: Optimizely object is not valid. Failing %s.",INVALID_CLIENT_ENGINE:"%s: Invalid client engine passed: %s. Defaulting to node-sdk.",INVALID_VARIATION_ID:"%s: Bucketed into an invalid variation ID. Returning null.",NOTIFICATION_LISTENER_EXCEPTION:"%s: Notification listener for (%s) threw exception: %s",NO_ROLLOUT_EXISTS:"%s: There is no rollout of feature %s.",NOT_ACTIVATING_USER:"%s: Not activating user %s for experiment %s.",NOT_TRACKING_USER:"%s: Not tracking user %s.",PARSED_REVENUE_VALUE:'%s: Parsed revenue value "%s" from event tags.',PARSED_NUMERIC_VALUE:'%s: Parsed event value "%s" from event tags.',RETURNING_STORED_VARIATION:'%s: Returning previously activated variation "%s" of experiment "%s" for user "%s" from user profile.',ROLLOUT_HAS_NO_EXPERIMENTS:"%s: Rollout of feature %s has no experiments",SAVED_VARIATION:'%s: Saved variation "%s" of experiment "%s" for user "%s".',SAVED_VARIATION_NOT_FOUND:"%s: User %s was previously bucketed into variation with ID %s for experiment %s, but no matching variation was found.",SHOULD_NOT_DISPATCH_ACTIVATE:'%s: Experiment %s is not in "Running" state. Not activating user.',SKIPPING_JSON_VALIDATION:"%s: Skipping JSON schema validation.",TRACK_EVENT:"%s: Tracking event %s for user %s.",USER_ASSIGNED_TO_EXPERIMENT_BUCKET:"%s: Assigned bucket %s to user with bucketing ID %s.",USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP:"%s: User %s is in experiment %s of group %s.",USER_BUCKETED_INTO_TARGETING_RULE:"%s: User %s bucketed into targeting rule %s.",USER_IN_FEATURE_EXPERIMENT:"%s: User %s is in variation %s of experiment %s on the feature %s.",USER_IN_ROLLOUT:"%s: User %s is in rollout of feature %s.",USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE:"%s: User %s bucketed into everyone targeting rule.",USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE:"%s: User %s not bucketed into everyone targeting rule due to traffic allocation.",USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP:"%s: User %s is not in experiment %s of group %s.",USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP:"%s: User %s is not in any experiment of group %s.",USER_NOT_BUCKETED_INTO_TARGETING_RULE:"%s User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.",USER_NOT_IN_FEATURE_EXPERIMENT:"%s: User %s is not in any experiment on the feature %s.",USER_NOT_IN_ROLLOUT:"%s: User %s is not in rollout of feature %s.",USER_FORCED_IN_VARIATION:"%s: User %s is forced in variation %s.",USER_MAPPED_TO_FORCED_VARIATION:"%s: Set variation %s for experiment %s and user %s in the forced variation map.",USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE:"%s: User %s does not meet conditions for targeting rule %s.",USER_MEETS_CONDITIONS_FOR_TARGETING_RULE:"%s: User %s meets conditions for targeting rule %s.",USER_HAS_VARIATION:"%s: User %s is in variation %s of experiment %s.",USER_HAS_FORCED_VARIATION:"%s: Variation %s is mapped to experiment %s and user %s in the forced variation map.",USER_HAS_NO_VARIATION:"%s: User %s is in no variation of experiment %s.",USER_HAS_NO_FORCED_VARIATION:"%s: User %s is not in the forced variation map.",USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT:"%s: No experiment %s mapped to user %s in the forced variation map.",USER_NOT_IN_ANY_EXPERIMENT:"%s: User %s is not in any experiment of group %s.",USER_NOT_IN_EXPERIMENT:"%s: User %s does not meet conditions to be in experiment %s.",USER_RECEIVED_DEFAULT_VARIABLE_VALUE:'%s: User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".',FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE:'%s: Feature "%s" is not enabled for user %s. Returning the default variable value "%s".',VARIABLE_NOT_USED_RETURN_DEFAULT_VARIABLE_VALUE:'%s: Variable "%s" is not used in variation "%s". Returning default value.',USER_RECEIVED_VARIABLE_VALUE:'%s: Got variable value "%s" for variable "%s" of feature flag "%s"',VALID_DATAFILE:"%s: Datafile is valid.",VALID_USER_PROFILE_SERVICE:"%s: Valid user profile service provided.",VARIATION_REMOVED_FOR_USER:"%s: Variation mapped to experiment %s has been removed for user %s.",VARIABLE_REQUESTED_WITH_WRONG_TYPE:'%s: Requested variable type "%s", but variable is of type "%s". Use correct API to retrieve value. Returning None.',VALID_BUCKETING_ID:'%s: BucketingId is valid: "%s"',BUCKETING_ID_NOT_STRING:"%s: BucketingID attribute is not a string. Defaulted to userId",EVALUATING_AUDIENCE:'%s: Starting to evaluate audience "%s" with conditions: %s.',EVALUATING_AUDIENCES_COMBINED:'%s: Evaluating audiences for %s "%s": %s.',AUDIENCE_EVALUATION_RESULT:'%s: Audience "%s" evaluated to %s.',AUDIENCE_EVALUATION_RESULT_COMBINED:"%s: Audiences for %s %s collectively evaluated to %s.",MISSING_ATTRIBUTE_VALUE:'%s: Audience condition %s evaluated to UNKNOWN because no value was passed for user attribute "%s".',UNEXPECTED_CONDITION_VALUE:"%s: Audience condition %s evaluated to UNKNOWN because the condition value is not supported.",UNEXPECTED_TYPE:'%s: Audience condition %s evaluated to UNKNOWN because a value of type "%s" was passed for user attribute "%s".',UNEXPECTED_TYPE_NULL:'%s: Audience condition %s evaluated to UNKNOWN because a null value was passed for user attribute "%s".',UNKNOWN_CONDITION_TYPE:"%s: Audience condition %s has an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.",UNKNOWN_MATCH_TYPE:"%s: Audience condition %s uses an unknown match type. You may need to upgrade to a newer release of the Optimizely SDK.",UPDATED_OPTIMIZELY_CONFIG:"%s: Updated Optimizely config to revision %s (project id %s)",OUT_OF_BOUNDS:'%s: Audience condition %s evaluated to UNKNOWN because the number value for user attribute "%s" is not in the range [-2^53, +2^53].',UNABLE_TO_ATTACH_UNLOAD:'%s: unable to bind optimizely.close() to page unload event: "%s"'},u={REVENUE:"revenue",VALUE:"value"},E={BOT_FILTERING:"$opt_bot_filtering",BUCKETING_ID:"$opt_bucketing_id",STICKY_BUCKETING_KEY:"$opt_experiment_bucket_map",USER_AGENT:"$opt_user_agent"},_=["node-sdk","react-sdk","javascript-sdk"],f=r.NOTIFICATION_TYPES,I={AB_TEST:"ab-test",FEATURE:"feature",FEATURE_TEST:"feature-test",FEATURE_VARIABLE:"feature-variable",ALL_FEATURE_VARIABLES:"all-feature-variables"},g={FEATURE_TEST:"feature-test",ROLLOUT:"rollout"},c={RULE:"rule",EXPERIMENT:"experiment"},p={BOOLEAN:"boolean",DOUBLE:"double",INTEGER:"integer",STRING:"string",JSON:"json"},d={V2:"2",V3:"3",V4:"4"},N=Object.freeze({__proto__:null,LOG_LEVEL:a,ERROR_MESSAGES:s,LOG_MESSAGES:l,RESERVED_EVENT_KEYWORDS:u,CONTROL_ATTRIBUTES:E,JAVASCRIPT_CLIENT_ENGINE:"javascript-sdk",NODE_CLIENT_ENGINE:"node-sdk",REACT_CLIENT_ENGINE:"react-sdk",NODE_CLIENT_VERSION:"4.3.4",VALID_CLIENT_ENGINES:_,NOTIFICATION_TYPES:f,DECISION_NOTIFICATION_TYPES:I,DECISION_SOURCES:g,AUDIENCE_EVALUATION_TYPES:c,FEATURE_VARIABLE_TYPES:p,DATAFILE_VERSIONS:d}),R=Math.pow(2,53);function O(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(!e)return{};if("function"==typeof Object.assign)return Object.assign.apply(Object,[e].concat(t));for(var i=Object(e),n=0;n<t.length;n++){var o=t[n];if(null!=o)for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(i[a]=o[a])}return i}function T(){return Math.round((new Date).getTime())}function h(e){return"number"==typeof e&&Math.abs(e)<=R}function v(e,t){return e?r.keyBy(e,(function(e){return e[t]})):{}}function A(e){return"number"==typeof e}var y="CONFIG_VALIDATOR",U=[d.V2,d.V3,d.V4],L=function(e){if("object"==typeof e&&null!==e){if(e.errorHandler&&"function"!=typeof e.errorHandler.handleError)throw new Error(r.sprintf(s.INVALID_ERROR_HANDLER,y));if(e.eventDispatcher&&"function"!=typeof e.eventDispatcher.dispatchEvent)throw new Error(r.sprintf(s.INVALID_EVENT_DISPATCHER,y));if(e.logger&&"function"!=typeof e.logger.log)throw new Error(r.sprintf(s.INVALID_LOGGER,y));return!0}throw new Error(r.sprintf(s.INVALID_CONFIG,y))},V=function(e){if(!e)throw new Error(r.sprintf(s.NO_DATAFILE_SPECIFIED,y));if("string"==typeof e)try{e=JSON.parse(e)}catch(e){throw new Error(r.sprintf(s.INVALID_DATAFILE_MALFORMED,y))}if("object"==typeof e&&!Array.isArray(e)&&null!==e&&-1===U.indexOf(e.version))throw new Error(r.sprintf(s.INVALID_DATAFILE_VERSION,y,e.version));return e},D="PROJECT_CONFIG";var m=function(e,t){void 0===t&&(t=null);var i,n,o=((n=O({},i=e)).audiences=(i.audiences||[]).map((function(e){return O({},e)})),n.experiments=(i.experiments||[]).map((function(e){return O({},e)})),n.featureFlags=(i.featureFlags||[]).map((function(e){return O({},e)})),n.groups=(i.groups||[]).map((function(e){var t=O({},e);return t.experiments=(e.experiments||[]).map((function(e){return O({},e)})),t})),n.rollouts=(i.rollouts||[]).map((function(e){var t=O({},e);return t.experiments=(e.experiments||[]).map((function(e){return O({},e)})),t})),n);return o.__datafileStr=null===t?JSON.stringify(e):t,(o.audiences||[]).forEach((function(e){e.conditions=JSON.parse(e.conditions)})),o.audiencesById=v(o.audiences,"id"),O(o.audiencesById,v(o.typedAudiences,"id")),o.attributeKeyMap=v(o.attributes,"key"),o.eventKeyMap=v(o.events,"key"),o.groupIdMap=v(o.groups,"id"),Object.keys(o.groupIdMap||{}).forEach((function(e){(o.groupIdMap[e].experiments||[]).forEach((function(t){o.experiments.push(O(t,{groupId:e}))}))})),o.rolloutIdMap=v(o.rollouts||[],"id"),r.objectValues(o.rolloutIdMap||{}).forEach((function(e){(e.experiments||[]).forEach((function(e){o.experiments.push(e),e.variationKeyMap=v(e.variations,"key")}))})),o.experimentKeyMap=v(o.experiments,"key"),o.experimentIdMap=v(o.experiments,"id"),o.variationIdMap={},o.variationVariableUsageMap={},(o.experiments||[]).forEach((function(e){e.variationKeyMap=v(e.variations,"key"),O(o.variationIdMap,v(e.variations,"id")),r.objectValues(e.variationKeyMap||{}).forEach((function(e){e.variables&&(o.variationVariableUsageMap[e.id]=v(e.variables,"id"))}))})),o.experimentFeatureMap={},o.featureKeyMap=v(o.featureFlags||[],"key"),r.objectValues(o.featureKeyMap||{}).forEach((function(e){e.variables.forEach((function(e){e.type===p.STRING&&e.subType===p.JSON&&(e.type=p.JSON,delete e.subType)})),e.variableKeyMap=v(e.variables,"key"),(e.experimentIds||[]).forEach((function(t){o.experimentFeatureMap[t]?o.experimentFeatureMap[t].push(e.id):o.experimentFeatureMap[t]=[e.id];var r=o.experimentIdMap[t];r.groupId&&!e.groupId&&(e.groupId=r.groupId)}))})),o},S=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_EXPERIMENT_KEY,D,t));return i.id},C=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_EXPERIMENT_KEY,D,t));return i.status},P=function(e,t){return"Running"===C(e,t)},b=function(e,t,r){var i=e.experimentKeyMap[t];return i.variationKeyMap.hasOwnProperty(r)?i.variationKeyMap[r].id:null},F=function(e,t,i){if(e.featureKeyMap.hasOwnProperty(t)){var n=e.featureKeyMap[t];if(n)return n}return i.log(a.ERROR,r.sprintf(s.FEATURE_NOT_IN_DATAFILE,D,t)),null},M=function(e,t,i,n){var o=e.featureKeyMap[t];if(!o)return n.log(a.ERROR,r.sprintf(s.FEATURE_NOT_IN_DATAFILE,D,t)),null;var l=o.variableKeyMap[i];return l||(n.log(a.ERROR,r.sprintf(s.VARIABLE_KEY_NOT_IN_DATAFILE,D,i,t)),null)},k=function(e,t,i,n){if(!t||!i)return null;if(!e.variationVariableUsageMap.hasOwnProperty(i.id))return n.log(a.ERROR,r.sprintf(s.VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT,D,i.id)),null;var o=e.variationVariableUsageMap[i.id][t.id];return o?o.value:null},x=function(e,t,i){var n;switch(t){case p.BOOLEAN:"true"!==e&&"false"!==e?(i.log(a.ERROR,r.sprintf(s.UNABLE_TO_CAST_VALUE,D,e,t)),n=null):n="true"===e;break;case p.INTEGER:n=parseInt(e,10),isNaN(n)&&(i.log(a.ERROR,r.sprintf(s.UNABLE_TO_CAST_VALUE,D,e,t)),n=null);break;case p.DOUBLE:n=parseFloat(e),isNaN(n)&&(i.log(a.ERROR,r.sprintf(s.UNABLE_TO_CAST_VALUE,D,e,t)),n=null);break;case p.JSON:try{n=JSON.parse(e)}catch(o){i.log(a.ERROR,r.sprintf(s.UNABLE_TO_CAST_VALUE,D,e,t)),n=null}break;default:n=e}return n},B=function(e,t){return e.eventKeyMap.hasOwnProperty(t)},G=function(e,t){return e.experimentFeatureMap.hasOwnProperty(t)},K=S,w=function(e,t){var i=e.experimentIdMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_EXPERIMENT_ID,D,t));return i.layerId},j=function(e,t,i){var n=e.attributeKeyMap[t],o=0===t.indexOf("$opt_");return n?(o&&i.log(a.WARN,r.sprintf("Attribute %s unexpectedly has reserved prefix %s; using attribute ID instead of reserved attribute name.",t,"$opt_")),n.id):o?t:(i.log(a.DEBUG,r.sprintf(s.UNRECOGNIZED_ATTRIBUTE,D,t)),null)},Y=function(e,t){var r=e.eventKeyMap[t];return r?r.id:null},H=function(e,t){return"Running"===C(e,t)},X=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_EXPERIMENT_KEY,D,t));return i.audienceConditions||i.audienceIds},J=function(e,t){return e.variationIdMap.hasOwnProperty(t)?e.variationIdMap[t].key:null},z=b,Z=function(e,t){if(e.experimentKeyMap.hasOwnProperty(t)){var i=e.experimentKeyMap[t];if(i)return i}throw new Error(r.sprintf(s.EXPERIMENT_KEY_NOT_IN_DATAFILE,D,t))},W=function(e,t){var i=e.experimentKeyMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_EXPERIMENT_KEY,D,t));return i.trafficAllocation},q=function(e,t,i){if(e.experimentIdMap.hasOwnProperty(t)){var n=e.experimentIdMap[t];if(n)return n}return i.log(a.ERROR,r.sprintf(s.INVALID_EXPERIMENT_ID,D,t)),null},$=function(e){return e.audiencesById},Q=function(e){return e.__datafileStr},ee=function(e){var t;try{t=V(e.datafile)}catch(e){return{configObj:null,error:e}}if(e.jsonSchemaValidator)try{e.jsonSchemaValidator.validate(t),e.logger.log(a.INFO,r.sprintf(l.VALID_DATAFILE,D))}catch(e){return{configObj:null,error:e}}else e.logger.log(a.INFO,r.sprintf(l.SKIPPING_JSON_VALIDATION,D));var i=[t];return"string"==typeof e.datafile&&i.push(e.datafile),{configObj:m.apply(void 0,i),error:null}};function te(e,t,r,i){var n=e.experimentFeatureMap[r],o={};if(n){var a=i[n],s=(t.variables||[]).reduce((function(e,t){return e[t.id]={id:t.id,value:t.value},e}),{});o=(a||[]).reduce((function(e,r){var i=s[r.id],n=t.featureEnabled&&i?i.value:r.defaultValue;return e[r.key]={id:r.id,key:r.key,type:r.type,value:n},e}),{})}return o}function re(e,t){this.experimentsMap=function(e){var t=(e.rollouts||[]).reduce((function(e,t){return t.experiments.forEach((function(t){e[t.id]=!0})),e}),{}),r=(e.featureFlags||[]).reduce((function(e,t){return e[t.id]=t.variables,e}),{});return(e.experiments||[]).reduce((function(i,n){return t[n.id]||(i[n.key]={id:n.id,key:n.key,variationsMap:(n.variations||[]).reduce((function(t,i){return t[i.key]={id:i.id,key:i.key,variablesMap:te(e,i,n.id,r)},G(e,n.id)&&(t[i.key].featureEnabled=i.featureEnabled),t}),{})}),i}),{})}(e),this.featuresMap=function(e,t){return(e.featureFlags||[]).reduce((function(r,i){return r[i.key]={id:i.id,key:i.key,experimentsMap:(i.experimentIds||[]).reduce((function(r,i){var n=e.experimentIdMap[i].key;return r[n]=t[n],r}),{}),variablesMap:(i.variables||[]).reduce((function(e,t){return e[t.key]={id:t.id,key:t.key,type:t.type,value:t.defaultValue},e}),{})},r}),{})}(e,this.experimentsMap),this.revision=e.revision,this.__datafile=t}re.prototype.getDatafile=function(){return this.__datafile};var ie={OptimizelyConfig:re},ne=t.getLogger();function oe(e,t){return e instanceof Error?e.message:t||"Unknown error"}function ae(e){try{this.__initialize(e)}catch(e){ne.error(e),this.__updateListeners=[],this.__configObj=null,this.__optimizelyConfigObj=null,this.__readyPromise=Promise.resolve({success:!1,reason:oe(e,"Error in initialize")})}}ae.prototype.__initialize=function(e){if(this.__updateListeners=[],this.jsonSchemaValidator=e.jsonSchemaValidator,!e.datafile&&!e.sdkKey){this.__configObj=null;var t=new Error(r.sprintf(s.DATAFILE_AND_SDK_KEY_MISSING,"PROJECT_CONFIG_MANAGER"));return this.__readyPromise=Promise.resolve({success:!1,reason:oe(t)}),void ne.error(t)}var n;if(e.datafile?(n=this.__handleNewDatafile(e.datafile))&&(this.__configObj=null):this.__configObj=null,e.sdkKey){var o={sdkKey:e.sdkKey};this.__validateDatafileOptions(e.datafileOptions)&&O(o,e.datafileOptions),this.__configObj&&(o.datafile=Q(this.__configObj)),this.datafileManager=new i.HttpPollingDatafileManager(o),this.datafileManager.start(),this.__readyPromise=this.datafileManager.onReady().then(this.__onDatafileManagerReadyFulfill.bind(this),this.__onDatafileManagerReadyReject.bind(this)),this.datafileManager.on("update",this.__onDatafileManagerUpdate.bind(this))}else this.__configObj?this.__readyPromise=Promise.resolve({success:!0}):this.__readyPromise=Promise.resolve({success:!1,reason:oe(n,"Invalid datafile")})},ae.prototype.__onDatafileManagerReadyFulfill=function(){var e=this.__handleNewDatafile(this.datafileManager.get());return e?{success:!1,reason:oe(e)}:{success:!0}},ae.prototype.__onDatafileManagerReadyReject=function(e){return{success:!1,reason:oe(e,"Failed to become ready")}},ae.prototype.__onDatafileManagerUpdate=function(){this.__handleNewDatafile(this.datafileManager.get())},ae.prototype.__validateDatafileOptions=function(e){return void 0===e||"object"==typeof e&&null!==e},ae.prototype.__handleNewDatafile=function(e){var t=ee({datafile:e,jsonSchemaValidator:this.jsonSchemaValidator,logger:ne}),r=t.configObj,i=t.error;i?ne.error(i):(this.__configObj?this.__configObj.revision:"null")!==r.revision&&(this.__configObj=r,this.__optimizelyConfigObj=new ie.OptimizelyConfig(this.__configObj,Q(this.__configObj)),this.__updateListeners.forEach((function(e){e(r)})));return i},ae.prototype.getConfig=function(){return this.__configObj},ae.prototype.getOptimizelyConfig=function(){return this.__optimizelyConfigObj},ae.prototype.onReady=function(){return this.__readyPromise},ae.prototype.onUpdate=function(e){return this.__updateListeners.push(e),function(){var t=this.__updateListeners.indexOf(e);t>-1&&this.__updateListeners.splice(t,1)}.bind(this)},ae.prototype.stop=function(){this.datafileManager&&this.datafileManager.stop(),this.__updateListeners=[]};function se(e){this.logger=e.logger,this.errorHandler=e.errorHandler,this.__notificationListeners={},r.objectValues(f).forEach(function(e){this.__notificationListeners[e]=[]}.bind(this)),this.__listenerId=1}se.prototype.addNotificationListener=function(e,t){try{if(!(r.objectValues(f).indexOf(e)>-1))return-1;this.__notificationListeners[e]||(this.__notificationListeners[e]=[]);var i=!1;if((this.__notificationListeners[e]||[]).forEach((function(e){if(e.callback===t)return i=!0,!1})),i)return-1;this.__notificationListeners[e].push({id:this.__listenerId,callback:t});var n=this.__listenerId;return this.__listenerId+=1,n}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),-1}},se.prototype.removeNotificationListener=function(e){try{var t,r;if(Object.keys(this.__notificationListeners).some(function(i){if((this.__notificationListeners[i]||[]).every((function(n,o){return n.id!==e||(t=o,r=i,!1)})),void 0!==t&&void 0!==r)return!0}.bind(this)),void 0!==t&&void 0!==r)return this.__notificationListeners[r].splice(t,1),!0}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e)}return!1},se.prototype.clearAllNotificationListeners=function(){try{r.objectValues(f).forEach(function(e){this.__notificationListeners[e]=[]}.bind(this))}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e)}},se.prototype.clearNotificationListeners=function(e){try{this.__notificationListeners[e]=[]}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e)}},se.prototype.sendNotifications=function(e,t){try{(this.__notificationListeners[e]||[]).forEach(function(i){var n=i.callback;try{n(t)}catch(t){this.logger.log(a.ERROR,r.sprintf(l.NOTIFICATION_LISTENER_EXCEPTION,"NOTIFICATION_CENTER",e,t.message))}}.bind(this))}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e)}};var le=Math.pow(2,32),ue={bucket:function(e){var t=e.experimentKeyMap[e.experimentKey].groupId;if(t){var i=e.groupIdMap[t];if(!i)throw new Error(r.sprintf(s.INVALID_GROUP_ID,"BUCKETER",t));if("random"===i.policy){var n=this.bucketUserIntoExperiment(i,e.bucketingId,e.userId,e.logger);if(null===n){var o=r.sprintf(l.USER_NOT_IN_ANY_EXPERIMENT,"BUCKETER",e.userId,t);return e.logger.log(a.INFO,o),null}if(n!==e.experimentId){var u=r.sprintf(l.USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP,"BUCKETER",e.userId,e.experimentKey,t);return e.logger.log(a.INFO,u),null}var E=r.sprintf(l.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP,"BUCKETER",e.userId,e.experimentKey,t);e.logger.log(a.INFO,E)}}var _=r.sprintf("%s%s",e.bucketingId,e.experimentId),f=this._generateBucketValue(_),I=r.sprintf(l.USER_ASSIGNED_TO_EXPERIMENT_BUCKET,"BUCKETER",f,e.userId);e.logger.log(a.DEBUG,I);var g=this._findBucket(f,e.trafficAllocationConfig);if(!e.variationIdMap.hasOwnProperty(g)){if(g){var c=r.sprintf(l.INVALID_VARIATION_ID,"BUCKETER");e.logger.log(a.WARNING,c)}return null}return g},bucketUserIntoExperiment:function(e,t,i,n){var o=r.sprintf("%s%s",t,e.id),s=this._generateBucketValue(o);n.log(a.DEBUG,r.sprintf(l.USER_ASSIGNED_TO_EXPERIMENT_BUCKET,"BUCKETER",s,i));var u=e.trafficAllocation;return this._findBucket(s,u)},_findBucket:function(e,t){for(var r=0;r<t.length;r++)if(e<t[r].endOfRange)return t[r].entityId;return null},_generateBucketValue:function(e){try{var t=n.v3(e,1);return parseInt(1e4*(t/le),10)}catch(t){throw new Error(r.sprintf(s.INVALID_BUCKETING_ID,"BUCKETER",e,t.message))}}},Ee=["and","or","not"];function _e(e,t){if(Array.isArray(e)){var r=e[0],i=e.slice(1);switch("string"==typeof r&&-1===Ee.indexOf(r)&&(r="or",i=e),r){case"and":return function(e,t){var r=!1;if(Array.isArray(e)){for(var i=0;i<e.length;i++){var n=_e(e[i],t);if(!1===n)return!1;null===n&&(r=!0)}return!r||null}return null}(i,t);case"not":return function(e,t){if(Array.isArray(e)&&e.length>0){var r=_e(e[0],t);return null===r?null:!r}return null}(i,t);default:return function(e,t){var r=!1;if(Array.isArray(e)){for(var i=0;i<e.length;i++){var n=_e(e[i],t);if(!0===n)return!0;null===n&&(r=!0)}return!!r&&null}return null}(i,t)}}return t(e)}var fe=t.getLogger();function Ie(e){return/^\d+$/.test(e)}function ge(e){var t=e.indexOf("-"),r=e.indexOf("+");return!(t<0)&&(r<0||t<r)}function ce(e){var t=e.indexOf("-"),r=e.indexOf("+");return!(r<0)&&(t<0||r<t)}function pe(e){var t=e,r="";if(function(e){return/\s/.test(e)}(e))return fe.warn(l.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;if(ge(e)?(t=e.substring(0,e.indexOf("-")),r=e.substring(e.indexOf("-")+1)):ce(e)&&(t=e.substring(0,e.indexOf("+")),r=e.substring(e.indexOf("+")+1)),"string"!=typeof t||"string"!=typeof r)return null;var i=t.split(".").length-1;if(i>2)return fe.warn(l.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;var n=t.split(".");if(n.length!=i+1)return fe.warn(l.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null;for(var o=0,a=n;o<a.length;o++){if(!Ie(a[o]))return fe.warn(l.UNKNOWN_MATCH_TYPE,"SEMANTIC VERSION",e),null}return r&&n.push(r),n}var de="CUSTOM_ATTRIBUTE_CONDITION_EVALUATOR",Ne=t.getLogger(),Re=["exact","exists","gt","ge","lt","le","substring","semver_eq","semver_lt","semver_le","semver_gt","semver_ge"],Oe={};function Te(e){return"string"==typeof e||"boolean"==typeof e||A(e)}function he(e,t){var r=e.value,i=typeof r,n=e.name,o=t[n],a=typeof o;return!Te(r)||A(r)&&!h(r)?(Ne.warn(l.UNEXPECTED_CONDITION_VALUE,de,JSON.stringify(e)),null):null===o?(Ne.debug(l.UNEXPECTED_TYPE_NULL,de,JSON.stringify(e),n),null):Te(o)&&i===a?A(o)&&!h(o)?(Ne.warn(l.OUT_OF_BOUNDS,de,JSON.stringify(e),n),null):r===o:(Ne.warn(l.UNEXPECTED_TYPE,de,JSON.stringify(e),a,n),null)}function ve(e,t){var r=e.name,i=t[r],n=typeof i,o=e.value;return null!==o&&h(o)?null===i?(Ne.debug(l.UNEXPECTED_TYPE_NULL,de,JSON.stringify(e),r),!1):A(i)?!!h(i)||(Ne.warn(l.OUT_OF_BOUNDS,de,JSON.stringify(e),r),!1):(Ne.warn(l.UNEXPECTED_TYPE,de,JSON.stringify(e),n,r),!1):(Ne.warn(l.UNEXPECTED_CONDITION_VALUE,de,JSON.stringify(e)),!1)}function Ae(e,t){var r=e.name,i=t[r],n=typeof i,o=e.value;return"string"!=typeof o?(Ne.warn(l.UNEXPECTED_CONDITION_VALUE,de,JSON.stringify(e)),null):null===i?(Ne.debug(l.UNEXPECTED_TYPE_NULL,de,JSON.stringify(e),r),null):"string"!=typeof i?(Ne.warn(l.UNEXPECTED_TYPE,de,JSON.stringify(e),n,r),null):function(e,t){var r=pe(t),i=pe(e);if(!r||!i)return null;for(var n=r.length,o=0;o<i.length;o++){if(n<=o)return ge(e)||ce(e)?1:-1;if(Ie(r[o])){var a=parseInt(r[o]),s=parseInt(i[o]);if(a>s)return 1;if(a<s)return-1}else{if(r[o]<i[o])return ge(e)&&!ge(t)?1:-1;if(r[o]>i[o])return!ge(e)&&ge(t)?-1:1}}return ge(t)&&!ge(e)?-1:0}(o,i)}Oe.exact=he,Oe.exists=function(e,t){var r=t[e.name];return null!=r},Oe.gt=function(e,t){var r=t[e.name],i=e.value;if(!ve(e,t)||null===i)return null;return r>i},Oe.ge=function(e,t){var r=t[e.name],i=e.value;if(!ve(e,t)||null===i)return null;return r>=i},Oe.lt=function(e,t){var r=t[e.name],i=e.value;if(!ve(e,t)||null===i)return null;return r<i},Oe.le=function(e,t){var r=t[e.name],i=e.value;if(!ve(e,t)||null===i)return null;return r<=i},Oe.substring=function(e,t){var r=e.name,i=t[e.name],n=typeof i,o=e.value;if("string"!=typeof o)return Ne.warn(l.UNEXPECTED_CONDITION_VALUE,de,JSON.stringify(e)),null;if(null===i)return Ne.debug(l.UNEXPECTED_TYPE_NULL,de,JSON.stringify(e),r),null;if("string"!=typeof i)return Ne.warn(l.UNEXPECTED_TYPE,de,JSON.stringify(e),n,r),null;return-1!==i.indexOf(o)},Oe.semver_eq=function(e,t){var r=Ae(e,t);if(null===r)return null;return 0===r},Oe.semver_gt=function(e,t){var r=Ae(e,t);if(null===r)return null;return r>0},Oe.semver_ge=function(e,t){var r=Ae(e,t);if(null===r)return null;return r>=0},Oe.semver_lt=function(e,t){var r=Ae(e,t);if(null===r)return null;return r<0},Oe.semver_le=function(e,t){var r=Ae(e,t);if(null===r)return null;return r<=0};var ye=Object.freeze({__proto__:null,evaluate:function(e,t){var r=e.match;if(void 0!==r&&-1===Re.indexOf(r))return Ne.warn(l.UNKNOWN_MATCH_TYPE,de,JSON.stringify(e)),null;var i=e.name;return t.hasOwnProperty(i)||"exists"==r?(r&&Oe[r]||he)(e,t):(Ne.debug(l.MISSING_ATTRIBUTE_VALUE,de,JSON.stringify(e),i),null)}}),Ue=t.getLogger();function Le(e){this.typeToEvaluatorMap=O({},e,{custom_attribute:ye})}function Ve(e){return"string"==typeof e&&""!==e}Le.prototype.evaluate=function(e,t,i){if(!e||0===e.length)return!0;i||(i={});var n=function(e){var n=t[e];if(n){Ue.log(a.DEBUG,r.sprintf(l.EVALUATING_AUDIENCE,"AUDIENCE_EVALUATOR",e,JSON.stringify(n.conditions)));var o=_e(n.conditions,this.evaluateConditionWithUserAttributes.bind(this,i)),s=null===o?"UNKNOWN":o.toString().toUpperCase();return Ue.log(a.DEBUG,r.sprintf(l.AUDIENCE_EVALUATION_RESULT,"AUDIENCE_EVALUATOR",e,s)),o}return null}.bind(this);return _e(e,n)||!1},Le.prototype.evaluateConditionWithUserAttributes=function(e,t){var i=this.typeToEvaluatorMap[t.type];if(!i)return Ue.log(a.WARNING,r.sprintf(l.UNKNOWN_CONDITION_TYPE,"AUDIENCE_EVALUATOR",JSON.stringify(t))),null;try{return i.evaluate(t,e,Ue)}catch(e){Ue.log(a.ERROR,r.sprintf(s.CONDITION_EVALUATOR_ERROR,"AUDIENCE_EVALUATOR",t.type,e.message))}return null};var De="DECISION_SERVICE",me=s,Se=a,Ce=l,Pe=g,be=c;function Fe(e){this.audienceEvaluator=new Le(e.UNSTABLE_conditionEvaluators),this.forcedVariationMap={},this.logger=e.logger,this.userProfileService=e.userProfileService||null}Fe.prototype.getVariation=function(e,t,i,n){var o=this._getBucketingId(i,n);if(!this.__checkIfExperimentIsActive(e,t))return null;var a=e.experimentKeyMap[t],s=this.getForcedVariation(e,t,i);if(s)return s;var l=this.__getWhitelistedVariation(a,i);if(l)return l.key;var u=this.__resolveExperimentBucketMap(i,n);if(l=this.__getStoredVariation(e,a,i,u))return this.logger.log(Se.INFO,r.sprintf(Ce.RETURNING_STORED_VARIATION,De,l.key,t,i)),l.key;if(!this.__checkIfUserIsInAudience(e,t,be.EXPERIMENT,i,n,"")){var E=r.sprintf(Ce.USER_NOT_IN_EXPERIMENT,De,i,t);return this.logger.log(Se.INFO,E),null}var _=this.__buildBucketerParams(e,t,o,i),f=ue.bucket(_);if(!(l=e.variationIdMap[f])){var I=r.sprintf(Ce.USER_HAS_NO_VARIATION,De,i,t);return this.logger.log(Se.DEBUG,I),null}var g=r.sprintf(Ce.USER_HAS_VARIATION,De,i,l.key,t);return this.logger.log(Se.INFO,g),this.__saveUserProfile(a,l,i,u),l.key},Fe.prototype.__resolveExperimentBucketMap=function(e,t){t=t||{};var r=this.__getUserProfile(e)||{},i=t[E.STICKY_BUCKETING_KEY];return O({},r.experiment_bucket_map,i)},Fe.prototype.__checkIfExperimentIsActive=function(e,t){if(!H(e,t)){var i=r.sprintf(Ce.EXPERIMENT_NOT_RUNNING,De,t);return this.logger.log(Se.INFO,i),!1}return!0},Fe.prototype.__getWhitelistedVariation=function(e,t){if(e.forcedVariations&&e.forcedVariations.hasOwnProperty(t)){var i=e.forcedVariations[t];if(e.variationKeyMap.hasOwnProperty(i)){var n=r.sprintf(Ce.USER_FORCED_IN_VARIATION,De,t,i);return this.logger.log(Se.INFO,n),e.variationKeyMap[i]}var o=r.sprintf(Ce.FORCED_BUCKETING_FAILED,De,i,t);return this.logger.log(Se.ERROR,o),null}return null},Fe.prototype.__checkIfUserIsInAudience=function(e,t,i,n,o,a){var s=X(e,t),l=$(e);this.logger.log(Se.DEBUG,r.sprintf(Ce.EVALUATING_AUDIENCES_COMBINED,De,i,a||t,JSON.stringify(s)));var u=this.audienceEvaluator.evaluate(s,l,o);return this.logger.log(Se.INFO,r.sprintf(Ce.AUDIENCE_EVALUATION_RESULT_COMBINED,De,i,a||t,u.toString().toUpperCase())),u},Fe.prototype.__buildBucketerParams=function(e,t,r,i){var n={};return n.experimentKey=t,n.experimentId=K(e,t),n.userId=i,n.trafficAllocationConfig=W(e,t),n.experimentKeyMap=e.experimentKeyMap,n.groupIdMap=e.groupIdMap,n.variationIdMap=e.variationIdMap,n.logger=this.logger,n.bucketingId=r,n},Fe.prototype.__getStoredVariation=function(e,t,i,n){if(n.hasOwnProperty(t.id)){var o=n[t.id],a=o.variation_id;if(e.variationIdMap.hasOwnProperty(a))return e.variationIdMap[o.variation_id];this.logger.log(Se.INFO,r.sprintf(Ce.SAVED_VARIATION_NOT_FOUND,De,i,a,t.key))}return null},Fe.prototype.__getUserProfile=function(e){var t={user_id:e,experiment_bucket_map:{}};if(!this.userProfileService)return t;try{return this.userProfileService.lookup(e)}catch(t){this.logger.log(Se.ERROR,r.sprintf(me.USER_PROFILE_LOOKUP_ERROR,De,e,t.message))}},Fe.prototype.__saveUserProfile=function(e,t,i,n){if(this.userProfileService)try{n[e.id]={variation_id:t.id},this.userProfileService.save({user_id:i,experiment_bucket_map:n}),this.logger.log(Se.INFO,r.sprintf(Ce.SAVED_VARIATION,De,t.key,e.key,i))}catch(e){this.logger.log(Se.ERROR,r.sprintf(me.USER_PROFILE_SAVE_ERROR,De,i,e.message))}},Fe.prototype.getVariationForFeature=function(e,t,i,n){var o=this._getVariationForFeatureExperiment(e,t,i,n);if(null!==o.variation)return o;var a=this._getVariationForRollout(e,t,i,n);return null!==a.variation?(this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_IN_ROLLOUT,De,i,t.key)),a):(this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_NOT_IN_ROLLOUT,De,i,t.key)),a)},Fe.prototype._getVariationForFeatureExperiment=function(e,t,i,n){var o=null,a=null;if(t.hasOwnProperty("groupId")){var s=e.groupIdMap[t.groupId];s&&(o=this._getExperimentInGroup(e,s,i))&&-1!==t.experimentIds.indexOf(o.id)&&(a=this.getVariation(e,o.key,i,n))}else t.experimentIds.length>0?(o=q(e,t.experimentIds[0],this.logger))&&(a=this.getVariation(e,o.key,i,n)):this.logger.log(Se.DEBUG,r.sprintf(Ce.FEATURE_HAS_NO_EXPERIMENTS,De,t.key));var l=null;return null!==a&&null!==o&&(l=o.variationKeyMap[a]),{experiment:o,variation:l,decisionSource:Pe.FEATURE_TEST}},Fe.prototype._getExperimentInGroup=function(e,t,i){var n=ue.bucketUserIntoExperiment(t,i,i,this.logger);if(n){this.logger.log(Se.INFO,r.sprintf(Ce.USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP,De,i,n,t.id));var o=q(e,n,this.logger);if(o)return o}return this.logger.log(Se.INFO,r.sprintf(Ce.USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP,De,i,t.id)),null},Fe.prototype._getVariationForRollout=function(e,t,i,n){if(!t.rolloutId)return this.logger.log(Se.DEBUG,r.sprintf(Ce.NO_ROLLOUT_EXISTS,De,t.key)),{experiment:null,variation:null,decisionSource:Pe.ROLLOUT};var o=e.rolloutIdMap[t.rolloutId];if(!o)return this.logger.log(Se.ERROR,r.sprintf(me.INVALID_ROLLOUT_ID,De,t.rolloutId,t.key)),{experiment:null,variation:null,decisionSource:Pe.ROLLOUT};if(0===o.experiments.length)return this.logger.log(Se.ERROR,r.sprintf(Ce.ROLLOUT_HAS_NO_EXPERIMENTS,De,t.rolloutId)),{experiment:null,variation:null,decisionSource:Pe.ROLLOUT};var a,s,l,u,E,_,f=this._getBucketingId(i,n),I=o.experiments.length-1;for(a=0;a<I;a++){if(s=e.experimentKeyMap[o.experiments[a].key],_=a+1,this.__checkIfUserIsInAudience(e,s.key,be.RULE,i,n,_)){if(this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE,De,i,_)),l=this.__buildBucketerParams(e,s.key,f,i),u=ue.bucket(l),E=e.variationIdMap[u])return this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_BUCKETED_INTO_TARGETING_RULE,De,i,_)),{experiment:s,variation:E,decisionSource:Pe.ROLLOUT};this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_NOT_BUCKETED_INTO_TARGETING_RULE,De,i,_));break}this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE,De,i,_))}var g=e.experimentKeyMap[o.experiments[I].key];if(this.__checkIfUserIsInAudience(e,g.key,be.RULE,i,n,"Everyone Else")){if(this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_MEETS_CONDITIONS_FOR_TARGETING_RULE,De,i,"Everyone Else")),l=this.__buildBucketerParams(e,g.key,f,i),u=ue.bucket(l),E=e.variationIdMap[u])return this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE,De,i)),{experiment:g,variation:E,decisionSource:Pe.ROLLOUT};this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE,De,i))}return{experiment:null,variation:null,decisionSource:Pe.ROLLOUT}},Fe.prototype._getBucketingId=function(e,t){var i=e;return null!=t&&"object"==typeof t&&t.hasOwnProperty(E.BUCKETING_ID)&&("string"==typeof t[E.BUCKETING_ID]?(i=t[E.BUCKETING_ID],this.logger.log(Se.DEBUG,r.sprintf(Ce.VALID_BUCKETING_ID,De,i))):this.logger.log(Se.WARNING,r.sprintf(Ce.BUCKETING_ID_NOT_STRING,De))),i},Fe.prototype.removeForcedVariation=function(e,t,i){if(!e)throw new Error(r.sprintf(me.INVALID_USER_ID,De));if(!this.forcedVariationMap.hasOwnProperty(e))throw new Error(r.sprintf(me.USER_NOT_IN_FORCED_VARIATION,De,e));delete this.forcedVariationMap[e][t],this.logger.log(Se.DEBUG,r.sprintf(Ce.VARIATION_REMOVED_FOR_USER,De,i,e))},Fe.prototype.__setInForcedVariationMap=function(e,t,i){this.forcedVariationMap.hasOwnProperty(e)||(this.forcedVariationMap[e]={}),this.forcedVariationMap[e][t]=i,this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_MAPPED_TO_FORCED_VARIATION,De,i,t,e))},Fe.prototype.getForcedVariation=function(e,t,i){var n,o=this.forcedVariationMap[i];if(!o)return this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_HAS_NO_FORCED_VARIATION,De,i)),null;try{var a=Z(e,t);if(!a.hasOwnProperty("id"))return this.logger.log(Se.ERROR,r.sprintf(me.IMPROPERLY_FORMATTED_EXPERIMENT,De,t)),null;n=a.id}catch(e){return this.logger.log(Se.ERROR,e.message),null}var s=o[n];if(!s)return this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT,De,t,i)),null;var l=J(e,s);return l?this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_HAS_FORCED_VARIATION,De,l,t,i)):this.logger.log(Se.DEBUG,r.sprintf(Ce.USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT,De,t,i)),l},Fe.prototype.setForcedVariation=function(e,t,i,n){if(null!=n&&!Ve(n))return this.logger.log(Se.ERROR,r.sprintf(me.INVALID_VARIATION_KEY,De)),!1;var o;try{var a=Z(e,t);if(!a.hasOwnProperty("id"))return this.logger.log(Se.ERROR,r.sprintf(me.IMPROPERLY_FORMATTED_EXPERIMENT,De,t)),!1;o=a.id}catch(e){return this.logger.log(Se.ERROR,e.message),!1}if(null==n)try{return this.removeForcedVariation(i,o,t,this.logger),!0}catch(e){return this.logger.log(Se.ERROR,e.message),!1}var s=z(e,t,n);if(!s)return this.logger.log(Se.ERROR,r.sprintf(me.NO_VARIATION_FOR_EXPERIMENT_KEY,De,n,t)),!1;try{return this.__setInForcedVariationMap(i,o,s),!0}catch(e){return this.logger.log(Se.ERROR,e.message),!1}};var Me=u.REVENUE,ke=u.VALUE;function xe(e,t){if(e.hasOwnProperty(Me)){var i=e[Me],n=void 0;return"string"==typeof i?(n=parseInt(i),isNaN(n)?(t.log(a.INFO,r.sprintf(l.FAILED_TO_PARSE_REVENUE,"EVENT_TAG_UTILS",i)),null):(t.log(a.INFO,r.sprintf(l.PARSED_REVENUE_VALUE,"EVENT_TAG_UTILS",n)),n)):"number"==typeof i?(n=i,t.log(a.INFO,r.sprintf(l.PARSED_REVENUE_VALUE,"EVENT_TAG_UTILS",n)),n):null}return null}function Be(e,t){if(e.hasOwnProperty(ke)){var i=e[ke],n=void 0;return"string"==typeof i?(n=parseFloat(i),isNaN(n)?(t.log(a.INFO,r.sprintf(l.FAILED_TO_PARSE_VALUE,"EVENT_TAG_UTILS",i)),null):(t.log(a.INFO,r.sprintf(l.PARSED_NUMERIC_VALUE,"EVENT_TAG_UTILS",n)),n)):"number"==typeof i?(n=i,t.log(a.INFO,r.sprintf(l.PARSED_NUMERIC_VALUE,"EVENT_TAG_UTILS",n)),n):null}return null}function Ge(e,t){return"string"==typeof e&&("string"==typeof t||"boolean"==typeof t||A(t)&&h(t))}var Ke="https://logx.optimizely.com/v1/events";function we(e){var t=e.attributes,r=e.configObj,i=r.anonymizeIP,n=r.botFiltering;null==i&&(i=!1);var o={snapshots:[],visitor_id:e.userId,attributes:[]},a={account_id:r.accountId,project_id:r.projectId,visitors:[o],revision:r.revision,client_name:e.clientEngine,client_version:e.clientVersion,anonymize_ip:i,enrich_decisions:!0};return Object.keys(t||{}).forEach((function(r){if(Ge(r,t[r])){var i=j(e.configObj,r,e.logger);i&&a.visitors[0].attributes.push({entity_id:i,key:r,type:"custom",value:t[r]})}})),"boolean"==typeof n&&a.visitors[0].attributes.push({entity_id:E.BOT_FILTERING,key:E.BOT_FILTERING,type:"custom",value:n}),a}var je=function(e){var t={httpVerb:"POST"},i=we(e);t.url=Ke;var n,o,a,s=(n=e.configObj,o=e.experimentId,a=e.variationId,{decisions:[{campaign_id:w(n,o),experiment_id:o,variation_id:a}],events:[{entity_id:w(n,o),timestamp:T(),key:"campaign_activated",uuid:r.generateUUID()}]});return i.visitors[0].snapshots.push(s),t.params=i,t},Ye=function(e){var t={httpVerb:"POST"},i=we(e);t.url=Ke;var n=function(e,t,i,n){var o={events:[]},a={entity_id:Y(e,t),timestamp:T(),uuid:r.generateUUID(),key:t};if(i){var s=xe(i,n);null!==s&&(a[u.REVENUE]=s);var l=Be(i,n);null!==l&&(a[u.VALUE]=l),a.tags=i}return o.events.push(a),o}(e.configObj,e.eventKey,e.eventTags,e.logger);return i.visitors[0].snapshots=[n],t.params=i,t},He=t.getLogger("EVENT_BUILDER");function Xe(e,t){var r=[];return Object.keys(t||{}).forEach((function(i){if(Ge(i,t[i])){var n=j(e,i,He);n&&r.push({entityId:n,key:i,value:t[i]})}})),r}var Je="USER_PROFILE_SERVICE_VALIDATOR";var ze=function(){function e(e){var t=this,i=e.clientEngine;-1===_.indexOf(i)&&(e.logger.log(a.INFO,r.sprintf(l.INVALID_CLIENT_ENGINE,"OPTIMIZELY",i)),i="node-sdk"),this.clientEngine=i,this.clientVersion=e.clientVersion||"4.3.4",this.errorHandler=e.errorHandler,this.eventDispatcher=e.eventDispatcher,this.isOptimizelyConfigValid=e.isValidInstance,this.logger=e.logger,this.projectConfigManager=function(e){return new ae(e)}({datafile:e.datafile,datafileOptions:e.datafileOptions,jsonSchemaValidator:e.jsonSchemaValidator,sdkKey:e.sdkKey}),this.disposeOnUpdate=this.projectConfigManager.onUpdate((function(e){t.logger.log(a.INFO,r.sprintf(l.UPDATED_OPTIMIZELY_CONFIG,"OPTIMIZELY",e.revision,e.projectId)),t.notificationCenter.sendNotifications(f.OPTIMIZELY_CONFIG_UPDATE)}));var n=this.projectConfigManager.onReady(),u=null;if(e.userProfileService)try{(function(e){if("object"==typeof e&&null!==e){if("function"!=typeof e.lookup)throw new Error(r.sprintf(s.INVALID_USER_PROFILE_SERVICE,Je,"Missing function 'lookup'"));if("function"!=typeof e.save)throw new Error(r.sprintf(s.INVALID_USER_PROFILE_SERVICE,Je,"Missing function 'save'"));return!0}throw new Error(r.sprintf(s.INVALID_USER_PROFILE_SERVICE,Je))})(e.userProfileService)&&(u=e.userProfileService,this.logger.log(a.INFO,r.sprintf(l.VALID_USER_PROFILE_SERVICE,"OPTIMIZELY")))}catch(e){this.logger.log(a.WARNING,e.message)}this.decisionService=new Fe({userProfileService:u,logger:this.logger,UNSTABLE_conditionEvaluators:e.UNSTABLE_conditionEvaluators}),this.notificationCenter=function(e){return new se(e)}({logger:this.logger,errorHandler:this.errorHandler});var E={dispatcher:this.eventDispatcher,flushInterval:e.eventFlushInterval,batchSize:e.eventBatchSize,maxQueueSize:e.eventMaxQueueSize,notificationCenter:this.notificationCenter};this.eventProcessor=new o.LogTierV1EventProcessor(E);var I=this.eventProcessor.start();this.readyPromise=Promise.all([n,I]).then((function(e){return e[0]})),this.readyTimeouts={},this.nextReadyTimeoutId=0}return e.prototype.isValidInstance=function(){return this.isOptimizelyConfigValid&&!!this.projectConfigManager.getConfig()},e.prototype.activate=function(e,t,i){try{if(!this.isValidInstance())return this.logger.log(a.ERROR,r.sprintf(l.INVALID_OBJECT,"OPTIMIZELY","activate")),null;if(!this.validateInputs({experiment_key:e,user_id:t},i))return this.notActivatingExperiment(e,t);var n=this.projectConfigManager.getConfig();if(!n)return null;try{var o=this.getVariation(e,t,i);if(null===o)return this.notActivatingExperiment(e,t);if(!P(n,e)){var s=r.sprintf(l.SHOULD_NOT_DISPATCH_ACTIVATE,"OPTIMIZELY",e);return this.logger.log(a.DEBUG,s),o}return this.sendImpressionEvent(e,o,t,i),o}catch(i){this.logger.log(a.ERROR,i.message);var u=r.sprintf(l.NOT_ACTIVATING_USER,"OPTIMIZELY",t,e);return this.logger.log(a.INFO,u),this.errorHandler.handleError(i),null}}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.sendImpressionEvent=function(e,t,i,n){var o=this.projectConfigManager.getConfig();if(o){var a=function(e){var t=e.configObj,i=e.experimentKey,n=e.variationKey,o=e.userId,a=e.userAttributes,s=e.clientEngine,l=e.clientVersion,u=z(t,i,n),E=K(t,i),_=w(t,E);return{type:"impression",timestamp:T(),uuid:r.generateUUID(),user:{id:o,attributes:Xe(t,a)},context:{accountId:t.accountId,projectId:t.projectId,revision:t.revision,clientName:s,clientVersion:l,anonymizeIP:t.anonymizeIP||!1,botFiltering:t.botFiltering},layer:{id:_},experiment:{id:E,key:i},variation:{id:u,key:n}}}({experimentKey:e,variationKey:t,userId:i,userAttributes:n,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:o});this.eventProcessor.process(a),this.emitNotificationCenterActivate(e,t,i,n)}},e.prototype.emitNotificationCenterActivate=function(e,t,r,i){var n=this.projectConfigManager.getConfig();if(n){var o,a=b(n,e,t),s=S(n,e),l={attributes:i,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:n,experimentId:s,userId:r,variationId:a,logger:this.logger},u=je(l),E=n.experimentKeyMap[e];E&&E.variationKeyMap&&(o=E.variationKeyMap[t]),this.notificationCenter.sendNotifications(f.ACTIVATE,{experiment:E,userId:r,attributes:i,variation:o,logEvent:u})}},e.prototype.track=function(e,t,i,n){try{if(!this.isValidInstance())return void this.logger.log(a.ERROR,r.sprintf(l.INVALID_OBJECT,"OPTIMIZELY","track"));if(!this.validateInputs({user_id:t,event_key:e},i,n))return;var o=this.projectConfigManager.getConfig();if(!o)return;if(!B(o,e))return this.logger.log(a.WARNING,r.sprintf(l.EVENT_KEY_NOT_FOUND,"OPTIMIZELY",e)),void this.logger.log(a.WARNING,r.sprintf(l.NOT_TRACKING_USER,"OPTIMIZELY",t));var s=function(e){var t=e.configObj,i=e.userId,n=e.userAttributes,o=e.clientEngine,a=e.clientVersion,s=e.eventKey,l=e.eventTags,u=Y(t,s),E=null,_=null;return l&&(E=xe(l,He),_=Be(l,He)),{type:"conversion",timestamp:T(),uuid:r.generateUUID(),user:{id:i,attributes:Xe(t,n)},context:{accountId:t.accountId,projectId:t.projectId,revision:t.revision,clientName:o,clientVersion:a,anonymizeIP:t.anonymizeIP||!1,botFiltering:t.botFiltering},event:{id:u,key:s},revenue:E,value:_,tags:l}}({eventKey:e,eventTags:n=this.filterEmptyValues(n),userId:t,userAttributes:i,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:o});this.logger.log(a.INFO,r.sprintf(l.TRACK_EVENT,"OPTIMIZELY",e,t)),this.eventProcessor.process(s),this.emitNotificationCenterTrack(e,t,i,n)}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e);var u=r.sprintf(l.NOT_TRACKING_USER,"OPTIMIZELY",t);this.logger.log(a.ERROR,u)}},e.prototype.emitNotificationCenterTrack=function(e,t,r,i){try{var n=this.projectConfigManager.getConfig();if(!n)return;var o={attributes:r,clientEngine:this.clientEngine,clientVersion:this.clientVersion,configObj:n,eventKey:e,eventTags:i,logger:this.logger,userId:t},s=Ye(o);this.notificationCenter.sendNotifications(f.TRACK,{eventKey:e,userId:t,attributes:r,eventTags:i,logEvent:s})}catch(e){this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e)}},e.prototype.getVariation=function(e,t,i){try{if(!this.isValidInstance())return this.logger.log(a.ERROR,r.sprintf(l.INVALID_OBJECT,"OPTIMIZELY","getVariation")),null;try{if(!this.validateInputs({experiment_key:e,user_id:t},i))return null;var n=this.projectConfigManager.getConfig();if(!n)return null;var o=n.experimentKeyMap[e];if(!o)return this.logger.log(a.DEBUG,r.sprintf(s.INVALID_EXPERIMENT_KEY,"OPTIMIZELY",e)),null;var u=this.decisionService.getVariation(n,e,t,i),E=G(n,o.id)?I.FEATURE_TEST:I.AB_TEST;return this.notificationCenter.sendNotifications(f.DECISION,{type:E,userId:t,attributes:i||{},decisionInfo:{experimentKey:e,variationKey:u}}),u}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),null}}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.setForcedVariation=function(e,t,r){if(!this.validateInputs({experiment_key:e,user_id:t}))return!1;var i=this.projectConfigManager.getConfig();if(!i)return!1;try{return this.decisionService.setForcedVariation(i,e,t,r)}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),!1}},e.prototype.getForcedVariation=function(e,t){if(!this.validateInputs({experiment_key:e,user_id:t}))return null;var r=this.projectConfigManager.getConfig();if(!r)return null;try{return this.decisionService.getForcedVariation(r,e,t)}catch(e){return this.logger.log(a.ERROR,e.message),this.errorHandler.handleError(e),null}},e.prototype.validateInputs=function(e,t,i){try{if(e.hasOwnProperty("user_id")){var n=e.user_id;if("string"!=typeof n||null===n||"undefined"===n)throw new Error(r.sprintf(s.INVALID_IN