UNPKG

@flagship.io/js-sdk

Version:
1 lines 131 kB
var t={7:t=>{var i,e="object"==typeof Reflect?Reflect:null,s=e&&"function"==typeof e.apply?e.apply:function(t,i,e){return Function.prototype.apply.call(t,i,e)};i=e&&"function"==typeof e.ownKeys?e.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var a=Number.isNaN||function(t){return t!=t};function n(){n.init.call(this)}t.exports=n,t.exports.once=function(t,i){return new Promise((function(e,s){function a(e){t.removeListener(i,n),s(e)}function n(){"function"==typeof t.removeListener&&t.removeListener("error",a),e([].slice.call(arguments))}p(t,i,n,{once:!0}),"error"!==i&&function(t,i){"function"==typeof t.on&&p(t,"error",i,{once:!0})}(t,a)}))},n.EventEmitter=n,n.prototype._events=void 0,n.prototype._eventsCount=0,n.prototype._maxListeners=void 0;var o=10;function r(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function h(t){return void 0===t._maxListeners?n.defaultMaxListeners:t._maxListeners}function c(t,i,e,s){var a,n,o,c;if(r(e),void 0===(n=t._events)?(n=t._events=Object.create(null),t._eventsCount=0):(void 0!==n.newListener&&(t.emit("newListener",i,e.listener?e.listener:e),n=t._events),o=n[i]),void 0===o)o=n[i]=e,++t._eventsCount;else if("function"==typeof o?o=n[i]=s?[e,o]:[o,e]:s?o.unshift(e):o.push(e),(a=h(t))>0&&o.length>a&&!o.warned){o.warned=!0;var g=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(i)+" listeners added. Use emitter.setMaxListeners() to increase limit");g.name="MaxListenersExceededWarning",g.emitter=t,g.type=i,g.count=o.length,c=g,console&&console.warn&&console.warn(c)}return t}function g(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(t,i,e){var s={fired:!1,wrapFn:void 0,target:t,type:i,listener:e},a=g.bind(s);return a.listener=e,s.wrapFn=a,a}function u(t,i,e){var s=t._events;if(void 0===s)return[];var a=s[i];return void 0===a?[]:"function"==typeof a?e?[a.listener||a]:[a]:e?function(t){for(var i=new Array(t.length),e=0;e<i.length;++e)i[e]=t[e].listener||t[e];return i}(a):f(a,a.length)}function l(t){var i=this._events;if(void 0!==i){var e=i[t];if("function"==typeof e)return 1;if(void 0!==e)return e.length}return 0}function f(t,i){for(var e=new Array(i),s=0;s<i;++s)e[s]=t[s];return e}function p(t,i,e,s){if("function"==typeof t.on)s.once?t.once(i,e):t.on(i,e);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(i,(function a(n){s.once&&t.removeEventListener(i,a),e(n)}))}}Object.defineProperty(n,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(t){if("number"!=typeof t||t<0||a(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");o=t}}),n.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},n.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||a(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},n.prototype.getMaxListeners=function(){return h(this)},n.prototype.emit=function(t){for(var i=[],e=1;e<arguments.length;e++)i.push(arguments[e]);var a="error"===t,n=this._events;if(void 0!==n)a=a&&void 0===n.error;else if(!a)return!1;if(a){var o;if(i.length>0&&(o=i[0]),o instanceof Error)throw o;var r=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw r.context=o,r}var h=n[t];if(void 0===h)return!1;if("function"==typeof h)s(h,this,i);else{var c=h.length,g=f(h,c);for(e=0;e<c;++e)s(g[e],this,i)}return!0},n.prototype.addListener=function(t,i){return c(this,t,i,!1)},n.prototype.on=n.prototype.addListener,n.prototype.prependListener=function(t,i){return c(this,t,i,!0)},n.prototype.once=function(t,i){return r(i),this.on(t,d(this,t,i)),this},n.prototype.prependOnceListener=function(t,i){return r(i),this.prependListener(t,d(this,t,i)),this},n.prototype.removeListener=function(t,i){var e,s,a,n,o;if(r(i),void 0===(s=this._events))return this;if(void 0===(e=s[t]))return this;if(e===i||e.listener===i)0==--this._eventsCount?this._events=Object.create(null):(delete s[t],s.removeListener&&this.emit("removeListener",t,e.listener||i));else if("function"!=typeof e){for(a=-1,n=e.length-1;n>=0;n--)if(e[n]===i||e[n].listener===i){o=e[n].listener,a=n;break}if(a<0)return this;0===a?e.shift():function(t,i){for(;i+1<t.length;i++)t[i]=t[i+1];t.pop()}(e,a),1===e.length&&(s[t]=e[0]),void 0!==s.removeListener&&this.emit("removeListener",t,o||i)}return this},n.prototype.off=n.prototype.removeListener,n.prototype.removeAllListeners=function(t){var i,e,s;if(void 0===(e=this._events))return this;if(void 0===e.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==e[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete e[t]),this;if(0===arguments.length){var a,n=Object.keys(e);for(s=0;s<n.length;++s)"removeListener"!==(a=n[s])&&this.removeAllListeners(a);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(i=e[t]))this.removeListener(t,i);else if(void 0!==i)for(s=i.length-1;s>=0;s--)this.removeListener(t,i[s]);return this},n.prototype.listeners=function(t){return u(this,t,!0)},n.prototype.rawListeners=function(t){return u(this,t,!1)},n.listenerCount=function(t,i){return"function"==typeof t.listenerCount?t.listenerCount(i):l.call(t,i)},n.prototype.listenerCount=l,n.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}}},i={};function e(s){var a=i[s];if(void 0!==a)return a.exports;var n=i[s]={exports:{}};return t[s](n,n.exports,e),n.exports}e.d=(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},e.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i);var s={};e.d(s,{ABTastyWebSDKPostMessageType:()=>Tt,APP_VERSION_CODE:()=>Hi,APP_VERSION_NAME:()=>Mi,CARRIER_NAME:()=>Di,CacheStrategy:()=>Ct,DEVICE_LOCALE:()=>_i,DEVICE_MODEL:()=>mi,DEVICE_TYPE:()=>Ci,DecisionApiConfig:()=>$t,DecisionMode:()=>It,EventCategory:()=>St,FLAGSHIP_CLIENT:()=>wi,FLAGSHIP_CONTEXT:()=>xi,FLAGSHIP_VERSION:()=>Vi,FLAGSHIP_VISITOR:()=>Li,FSFetchReasons:()=>_t,FSFetchStatus:()=>Gi,FSFlag:()=>zi,FSFlagCollection:()=>Wi,FSFlagMetadata:()=>Pi,FSFlagStatus:()=>Ui,FSSdkStatus:()=>pt,Flagship:()=>ce,HitType:()=>At,INTERFACE_NAME:()=>Fi,INTERNET_CONNECTION:()=>Oi,IP:()=>Ni,LOCATION_CITY:()=>yi,LOCATION_COUNTRY:()=>Ei,LOCATION_LAT:()=>Ai,LOCATION_LONG:()=>Si,LOCATION_REGION:()=>Ti,LogLevel:()=>vt,OS_NAME:()=>ki,OS_VERSION_CODE:()=>bi,OS_VERSION_NAME:()=>Ri,TroubleshootingLabel:()=>mt,Visitor:()=>ft,VisitorCacheStatus:()=>yt,default:()=>ge});var a=e(7);const n="5.1.2",o={name:"TypeScript",version:n},r=25e5,h="https://decision.flagship.io/v2/",c="https://events.flagship.io",g="https://events.flagship.io/troubleshooting",d="https://events.flagship.io/analytics",u="activate",l="fs_consent",f=144e5,p="ready",I="https://docs.developers.flagship.io/docs/js-v3",v=`Params 'envId' and 'apiKey' must not be null or empty.\n Learn more: ${I}#initialization`,_="{0} must be a {1}",C="Visitor {0}, method {1} is deactivated while SDK status is: {2}.",m="SEND BATCH",y="without calling `fetchFlags` method afterwards. So, the value of the flag `{1}` might be outdated",T=`You can't create a new visitor without first calling the "Flagship.start" method.\nLearn more: ${I}#initialization\n`,E="INITIALIZATION",A="UPDATE CONTEXT",S="NEW VISITOR",N="ADD HIT",k="batch",R="cid",b="cid",D="cuid",O="aid",M="vid",H="caid",F="vaid",w="ds",V="t",L="qt",x="APP",P="x-api-key",G="Content-Type",U="x-sdk-client",B="x-sdk-version",K="application/json",q="BUCKETING",Q=`Visitor {0}, the key '{1}' must be a non null String.\nLearn more: ${I}#updating-the-visitor-context`,$=`Visitor {0}, 'value' for key '{1}[], must be one of the following types : String, Number, Boolean\nLearn more: ${I}#updating-the-visitor-context`,j=`visitor {0}, Predefined Context {0} must be of type {1}\nLearn more: ${I}#predefined-user-context-keys-`,z="FETCH_FLAGS",W="FLAG_VALUE",J="GET_FLAG",Y="FLAG_VISITOR_EXPOSED",Z="FLAG_METADATA",X="Visitor {0}, No Flags found for key {1}: Empty metadata object is returned",tt=`Visitor {0}, Flag for key {1} Method Flag.metadata is deactivated while SDK status is NOT_READY: Empty metadata object is returned {2}\nLearn more: ${I}#getting-flags-campaigns-metadata`,it="AUTHENTICATE",et=`Visitor {0}, visitorId must not be null or empty\nLearn more: ${I}#authenticate`,st="UNAUTHENTICATE",at="ALLOCATION",nt=`lookupVisitor method has loaded a bad format version ({0}) for visitor {1}.\nLearn more: ${I}#managing-visitor-cache`,ot="CACHE",rt="visitor {0}. {1} threw an exception {2}",ht="{0} threw an exception {1}",ct="TRACKING_MANAGER",gt="{0} Unexpected Error occurred {1}",dt="{0} has been sent : {1}",ut="ACTIVATE HIT",lt="BATCH HIT";class ft extends a.EventEmitter{visitorDelegate;_onReady;constructor(t){super(),this.visitorDelegate=t,this._onReady=t=>{this.emit(p,t)},this.visitorDelegate.on(p,this._onReady);const i=this;i.sendEaiVisitorEvent=t=>{this.visitorDelegate.sendEaiVisitorEvent(t)},i.sendEaiPageView=t=>{this.visitorDelegate.sendEaiPageView(t)},i.onEAICollectStatusChange=t=>{this.visitorDelegate.onEAICollectStatusChange(t)}}get visitorId(){return this.visitorDelegate.visitorId}set visitorId(t){this.visitorDelegate.visitorId=t}get anonymousId(){return this.visitorDelegate.anonymousId}get config(){return this.visitorDelegate.config}get context(){return this.visitorDelegate.context}get flagsStatus(){return this.visitorDelegate.flagsStatus}get hasConsented(){return this.visitorDelegate.hasConsented}setConsent(t){this.visitorDelegate.setConsent(t)}updateContext(t,i){this.visitorDelegate.updateContext(t,i)}clearContext(){this.visitorDelegate.clearContext()}getFlag(t){return this.visitorDelegate.getFlag(t)}getFlags(){return this.visitorDelegate.getFlags()}fetchFlags(){return this.visitorDelegate.fetchFlags()}sendHit(t){return this.visitorDelegate.sendHit(t)}sendHits(t){return this.visitorDelegate.sendHits(t)}authenticate(t){this.visitorDelegate.authenticate(t)}unauthenticate(){this.visitorDelegate.unauthenticate()}collectEAIEventsAsync(...t){let i;return t.length>0&&(i=t[0]),this.visitorDelegate.collectEAIEventsAsync(i)}cleanup(){this.visitorDelegate.cleanup(),this.visitorDelegate.off(p,this._onReady)}}var pt,It,vt,_t,Ct,mt,yt,Tt,Et,At,St;function Nt(t,...i){let e=t;for(let t=0;t<i.length;t++){const s=i[t],a="string"==typeof s?s:JSON.stringify(s instanceof Map?Array.from(s.values()):s);e=e.replace(new RegExp(`\\{${t}\\}`,"g"),a)}return e}function kt(t,i,e,...s){!t||!t.logLevel||t.logLevel<vt.ERROR||Rt(t,Nt(e,...s),i)}function Rt(t,i,e){!t||!t.logLevel||t.logLevel<vt.ERROR||("function"==typeof t.onLog&&t.onLog(vt.ERROR,e,i),t.logManager&&"function"==typeof t.logManager.error&&t.logManager.error(i,e))}function bt(t,i,e,...s){!t||!t.logLevel||t.logLevel<vt.WARNING||Dt(t,Nt(e,...s),i)}function Dt(t,i,e){!t||!t.logLevel||t.logLevel<vt.WARNING||("function"==typeof t.onLog&&t.onLog(vt.WARNING,e,i),t.logManager&&"function"==typeof t.logManager.warning&&t.logManager.warning(i,e))}function Ot(t,i,e,...s){!t||!t.logLevel||t.logLevel<vt.INFO||Mt(t,Nt(e,...s),i)}function Mt(t,i,e){!t||!t.logLevel||t.logLevel<vt.INFO||("function"==typeof t.onLog&&t.onLog(vt.INFO,e,i),t.logManager&&"function"==typeof t.logManager.info&&t.logManager.info(i,e))}function Ht(t,i,e,...s){!t||!t.logLevel||t.logLevel<vt.DEBUG||Ft(t,Nt(e,...s),i)}function Ft(t,i,e){!t||!t.logLevel||t.logLevel<vt.DEBUG||("function"==typeof t.onLog&&t.onLog(vt.DEBUG,e,i),t.logManager&&"function"==typeof t.logManager.debug&&t.logManager.debug(i,e))}function wt(){return"undefined"!=typeof window&&void 0!==window.document}function Vt(t,i){return typeof t==typeof i&&("object"!=typeof t||"object"!=typeof i||Array.isArray(t)===Array.isArray(i))}function Lt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const i=16*Math.random()|0;return("x"===t?i:3&i|8).toString(16)}))}function xt(t,i){return JSON.stringify({message:t,data:i})}function Pt(t){const i=JSON.stringify(t);return Array.from(i,(t=>t.charCodeAt(0).toString(16))).join("")}function Gt(t,i){if("string"!=typeof t)return kt(i,"hexToValue","Invalid hex string: {0}",t),null;let e="";for(let s=0;s<t.length;s+=2){const a=t.slice(s,s+2),n=parseInt(a,16);if(isNaN(n))return kt(i,"hexToValue","Invalid hex character: {0}",a),null;e+=String.fromCharCode(n)}try{return JSON.parse(e)}catch(t){return kt(i,"hexToValue","Error while parsing JSON: {0}",t),null}}function Ut(t,i){if(t===i)return!0;if("object"!=typeof t||"object"!=typeof i||null==t||null==i)return!1;const e=Object.keys(t),s=Object.keys(i);if(e.length!==s.length)return!1;for(const a of e)if(!s.includes(a)||!Ut(t[a],i[a]))return!1;return!0}function Bt(t,i,e){const s=new Date,a=t=>t.toString().padStart(2,"0");return`${{[vt.EMERGENCY]:"",[vt.ALERT]:"",[vt.CRITICAL]:"",[vt.ERROR]:"",[vt.WARNING]:"",[vt.NOTICE]:"",[vt.INFO]:"",[vt.DEBUG]:"",[vt.NONE]:"",[vt.ALL]:""}[t]||""}[${s.getFullYear()}-${a(s.getMonth()+1)}-${a(s.getDate())} ${a(s.getHours())}:${a(s.getMinutes())}:${a(s.getSeconds())}.${s.getMilliseconds().toString().padStart(3,"0")}] [Flagship SDK] [${vt[t].padEnd(2)}] [${e}] ${i}`}!function(t){t[t.SDK_NOT_INITIALIZED=0]="SDK_NOT_INITIALIZED",t[t.SDK_INITIALIZING=1]="SDK_INITIALIZING",t[t.SDK_PANIC=2]="SDK_PANIC",t[t.SDK_INITIALIZED=3]="SDK_INITIALIZED"}(pt||(pt={})),function(t){t.DECISION_API="DECISION-API",t.BUCKETING="BUCKETING",t.BUCKETING_EDGE="BUCKETING_EDGE"}(It||(It={})),function(t){t[t.NONE=0]="NONE",t[t.EMERGENCY=1]="EMERGENCY",t[t.ALERT=2]="ALERT",t[t.CRITICAL=3]="CRITICAL",t[t.ERROR=4]="ERROR",t[t.WARNING=5]="WARNING",t[t.NOTICE=6]="NOTICE",t[t.INFO=7]="INFO",t[t.DEBUG=8]="DEBUG",t[t.ALL=9]="ALL"}(vt||(vt={})),function(t){t.UPDATE_CONTEXT="UPDATE_CONTEXT",t.AUTHENTICATE="AUTHENTICATE",t.UNAUTHENTICATE="UNAUTHENTICATE",t.FLAGS_FETCHING_ERROR="FLAGS_FETCHING_ERROR",t.FLAGS_FETCHED_FROM_CACHE="FLAGS_FETCHED_FROM_CACHE",t.FLAGS_NEVER_FETCHED="FLAGS_NEVER_FETCHED",t.NONE="NONE"}(_t||(_t={})),function(t){t[t.CONTINUOUS_CACHING=0]="CONTINUOUS_CACHING",t[t.PERIODIC_CACHING=1]="PERIODIC_CACHING"}(Ct||(Ct={}));class Kt{_batchIntervals;_poolMaxSize;_batchStrategy;constructor(t){this.batchIntervals=t?.batchIntervals,this.poolMaxSize=t?.poolMaxSize,this._batchStrategy=this.getCacheStrategy(t?.cacheStrategy)}getCacheStrategy(t){return"number"==typeof t?t:wt()?Ct.CONTINUOUS_CACHING:Ct.PERIODIC_CACHING}get batchIntervals(){return this._batchIntervals}set batchIntervals(t){("number"!=typeof t||t<1||t>10800)&&(t=wt()?5:10),this._batchIntervals=t}get poolMaxSize(){return this._poolMaxSize}set poolMaxSize(t){("number"!=typeof t||t<5)&&(t=wt()?10:100),this._poolMaxSize=t}get cacheStrategy(){return this._batchStrategy}}class qt{_envId;_apiKey;_decisionMode;_timeout;_logLevel;_onSdkStatusChanged;_logManager;_fetchNow;_pollingInterval;_onBucketingUpdated;_reuseVisitorIds;_initialBucketing;_decisionApiUrl;_hitDeduplicationTime;_visitorCacheImplementation;_hitCacheImplementation;_disableCache;_trackingManagerConfig;_onVisitorExposed;_fetchThirdPartyData;_nextFetchConfig;_fetchFlagsBufferingTime;_disableDeveloperUsageTracking;_onLog;_isQAModeEnabled;get isQAModeEnabled(){return this._isQAModeEnabled}set isQAModeEnabled(t){this._isQAModeEnabled=t}_enableAnalytics;get disableDeveloperUsageTracking(){return this._disableDeveloperUsageTracking}set disableDeveloperUsageTracking(t){this._disableDeveloperUsageTracking=t}get fetchFlagsBufferingTime(){return this._fetchFlagsBufferingTime}set fetchFlagsBufferingTime(t){this._fetchFlagsBufferingTime=t}get nextFetchConfig(){return this._nextFetchConfig}set nextFetchConfig(t){this._nextFetchConfig=t}get fetchThirdPartyData(){return this._fetchThirdPartyData}set fetchThirdPartyData(t){this._fetchThirdPartyData=t}get trackingManagerConfig(){return this._trackingManagerConfig}get onLog(){return this._onLog}set onLog(t){this._onLog=t}get onVisitorExposed(){return this._onVisitorExposed}constructor(t){const{envId:i,apiKey:e,timeout:s,logLevel:a,logManager:n,onSdkStatusChanged:o,fetchNow:r,decisionMode:c,reuseVisitorIds:g,initialBucketing:d,decisionApiUrl:u,hitDeduplicationTime:l,visitorCacheImplementation:f,hitCacheImplementation:p,disableCache:I,language:v,sdkVersion:_,trackingManagerConfig:C,onLog:m,onVisitorExposed:y,nextFetchConfig:T,fetchFlagsBufferingTime:E,disableDeveloperUsageTracking:A}=t;this.initQaMode(),this.initSDKInfo(v,_),n&&(this.logManager=n),this.fetchFlagsBufferingTime=E??2,this.nextFetchConfig=T||{revalidate:20},this._trackingManagerConfig=new Kt(C||{}),this.onLog=m,this.decisionApiUrl=u||h,this._envId=i,this._apiKey=e,this.logLevel=a??vt.INFO,this.timeout=s||2,this.fetchNow=void 0===r||r,this.reuseVisitorIds=void 0===g||g,this._decisionMode=c||It.DECISION_API,this._initialBucketing=d,this.hitDeduplicationTime=l??2.5,this.disableCache=!!I,this.disableDeveloperUsageTracking=A||!1,f&&(this.visitorCacheImplementation=f),p&&(this.hitCacheImplementation=p),this.onSdkStatusChanged=o,this._onVisitorExposed=y}initQaMode(){}initSDKInfo(t,i){switch(t){case 1:o.name="ReactJS",o.version=i??n;break;case 2:o.name="React-Native",o.version=i??n;break;default:o.name="undefined"!=typeof window&&"Deno"in window?"Deno":"TypeScript",o.version=n}}get initialBucketing(){return this._initialBucketing}set initialBucketing(t){this._initialBucketing=t}get reuseVisitorIds(){return this._reuseVisitorIds}set reuseVisitorIds(t){this._reuseVisitorIds=t}get onBucketingUpdated(){return this._onBucketingUpdated}set onBucketingUpdated(t){this._onBucketingUpdated=t}set envId(t){this._envId=t}get envId(){return this._envId}set apiKey(t){this._apiKey=t}get apiKey(){return this._apiKey}get decisionMode(){return this._decisionMode}get timeout(){return this._timeout}set timeout(t){this._timeout=t}get logLevel(){return this._logLevel}set logLevel(t){this._logLevel=t}get fetchNow(){return this._fetchNow}set fetchNow(t){this._fetchNow=t}get pollingInterval(){return this._pollingInterval}set pollingInterval(t){this._pollingInterval=t}get hitDeduplicationTime(){return this._hitDeduplicationTime}set hitDeduplicationTime(t){"number"==typeof t?this._hitDeduplicationTime=t:Rt(this,Nt(_,"hitDeduplicationTime","number"),"hitDeduplicationTime")}get visitorCacheImplementation(){return this._visitorCacheImplementation}set visitorCacheImplementation(t){this._visitorCacheImplementation=t}get hitCacheImplementation(){return this._hitCacheImplementation}set hitCacheImplementation(t){this._hitCacheImplementation=t}get disableCache(){return this._disableCache}set disableCache(t){this._disableCache=t}get onSdkStatusChanged(){return this._onSdkStatusChanged}set onSdkStatusChanged(t){t&&"function"!=typeof t?Rt(this,"statusChangedCallback must be a function","onSdkStatusChanged"):this._onSdkStatusChanged=t}get logManager(){return this._logManager}set logManager(t){this._logManager=t}get decisionApiUrl(){return this._decisionApiUrl}set decisionApiUrl(t){"string"==typeof t?this._decisionApiUrl=t:Rt(this,Nt(_,"decisionApiUrl","string"),"decisionApiUrl")}}class Qt extends qt{constructor(t){super({...t,decisionMode:It.BUCKETING}),this.pollingInterval=t?.pollingInterval??5,this.onBucketingUpdated=t?.onBucketingUpdated,this.fetchThirdPartyData=t?.fetchThirdPartyData}}class $t extends qt{constructor(t){super({...t,decisionMode:It.DECISION_API})}}class jt{_config;_decisionManager;_trackingManager;_sharedActionTracking;constructor(t,i,e,s){this._config=t,this._decisionManager=i,this._trackingManager=e,this._sharedActionTracking=s}get config(){return this._config}set config(t){this._config=t}get decisionManager(){return this._decisionManager}set decisionManager(t){this._decisionManager=t}get trackingManager(){return this._trackingManager}set trackingManager(t){this._trackingManager=t}get sharedActionTracking(){return this._sharedActionTracking}}!function(t){t.VISITOR_SEND_HIT="VISITOR_SEND_HIT",t.VISITOR_FETCH_CAMPAIGNS_ERROR="VISITOR_FETCH_CAMPAIGNS_ERROR",t.VISITOR_FETCH_CAMPAIGNS="VISITOR_FETCH_CAMPAIGNS",t.VISITOR_AUTHENTICATE="VISITOR_AUTHENTICATE",t.VISITOR_UNAUTHENTICATE="VISITOR_UNAUTHENTICATE",t.VISITOR_EXPOSED_FLAG_NOT_FOUND="VISITOR_EXPOSED_FLAG_NOT_FOUND",t.FLAG_VALUE_NOT_CALLED="FLAG_VALUE_NOT_CALLED",t.GET_FLAG_VALUE_FLAG_NOT_FOUND="GET_FLAG_VALUE_FLAG_NOT_FOUND",t.GET_FLAG_METADATA_TYPE_WARNING="GET_FLAG_METADATA_TYPE_WARNING",t.GET_FLAG_VALUE_TYPE_WARNING="GET_FLAG_VALUE_TYPE_WARNING",t.VISITOR_EXPOSED_TYPE_WARNING="VISITOR_EXPOSED_TYPE_WARNING",t.VISITOR_SEND_ACTIVATE="VISITOR_SEND_ACTIVATE",t.GET_CAMPAIGNS_ROUTE_RESPONSE_ERROR="GET_CAMPAIGNS_ROUTE_RESPONSE_ERROR",t.GET_CAMPAIGNS_ROUTE_RESPONSE="GET_CAMPAIGNS_ROUTE_RESPONSE",t.SDK_BUCKETING_FILE="SDK_BUCKETING_FILE",t.SEND_ACTIVATE_HIT_ROUTE_ERROR="SEND_ACTIVATE_HIT_ROUTE_ERROR",t.SEND_BATCH_HIT_ROUTE_RESPONSE_ERROR="SEND_BATCH_HIT_ROUTE_RESPONSE_ERROR",t.SEND_HIT_ROUTE_ERROR="SEND_HIT_ROUTE_ERROR",t.SDK_BUCKETING_FILE_ERROR="SDK_BUCKETING_FILE_ERROR",t.SDK_CONFIG="SDK_CONFIG",t.ACCOUNT_SETTINGS="ACCOUNT_SETTINGS",t.ACCOUNT_SETTINGS_ERROR="ACCOUNT_SETTINGS_ERROR",t.EMOTION_AI_SCORE="EMOTION_EAI_SCORE",t.EMOTION_AI_SCORE_FROM_LOCAL_CACHE="EMOTION_AI_SCORE_FROM_LOCAL_CACHE",t.EMOTION_AI_SCORE_ERROR="EMOTION_EAI_SCORE_ERROR",t.EMOTION_AI_VISITOR_EVENT="EMOTION_AI_VISITOR_EVENT",t.EMOTION_AI_VISITOR_EVENT_ERROR="EMOTION_AI_VISITOR_EVENT_ERROR",t.EMOTION_AI_PAGE_VIEW="EMOTION_AI_PAGE_VIEW",t.EMOTION_AI_PAGE_VIEW_ERROR="EMOTION_AI_PAGE_VIEW_ERROR",t.EMOTION_AI_START_COLLECTING="EMOTION_AI_START_COLLECTING",t.EMOTION_AI_STOP_COLLECTING="EMOTION_AI_STOP_COLLECTING",t.EMOTION_AI_START_SCORING="EMOTION_AI_START_SCORING",t.EMOTION_AI_SCORING_FAILED="EMOTION_AI_SCORING_FAILED",t.EMOTION_AI_SCORING_SUCCESS="EMOTION_AI_SCORING_SUCCESS"}(mt||(mt={})),function(t){t.NONE="NONE",t.ANONYMOUS_ID_CACHE="ANONYMOUS_ID_CACHE",t.VISITOR_ID_CACHE="VISITOR_ID_CACHE",t.VISITOR_ID_CACHE_WITH_ANONYMOUS_ID_CACHE="VISITOR_ID_CACHE_WITH_ANONYMOUS_ID_CACHE"}(yt||(yt={})),function(t){t.AB_TASTY_WEB_SDK_INITIALIZED="AB_TASTY_WEB_SDK_INITIALIZED"}(Tt||(Tt={}));class zt{_visitorId;_config;_type;_ds;_anonymousId;_userIp;_screenResolution;_locale;_sessionNumber;_key;_createdAt;_qaMode;_isActionTrackingHit;get isActionTrackingHit(){return this._isActionTrackingHit}set isActionTrackingHit(t){this._isActionTrackingHit=t}get key(){return this._key}set key(t){this._key=t}get sessionNumber(){return this._sessionNumber}set sessionNumber(t){this._sessionNumber=t}get locale(){return this._locale}set locale(t){this._locale=t}get screenResolution(){return this._screenResolution}set screenResolution(t){this._screenResolution=t}get userIp(){return this._userIp}set userIp(t){this._userIp=t}get anonymousId(){return this._anonymousId}set anonymousId(t){this._anonymousId=t}get visitorId(){return this._visitorId}set visitorId(t){this._visitorId=t}get ds(){return this._ds}set ds(t){this._ds=t}get type(){return this._type}get config(){return this._config}set config(t){this._config=t}get createdAt(){return this._createdAt}set createdAt(t){this._createdAt=t}get qaMode(){return this._qaMode}set qaMode(t){this._qaMode=t}constructor(t){const{type:i,userIp:e,screenResolution:s,locale:a,sessionNumber:n,visitorId:o,anonymousId:r,ds:h,qaMode:c,isActionTrackingHit:g}=t;this._type=i,e&&(this.userIp=e),s&&(this.screenResolution=s),a&&(this.locale=a),n&&(this.sessionNumber=n),this.visitorId=o,this._anonymousId=r||null,this.createdAt=Date.now(),this.ds=h||x,this.qaMode=c,this.isActionTrackingHit=g}isNotEmptyString(t,i){return!(!t||"string"!=typeof t)||(Rt(this.config,Nt(_,i,"string"),i),!1)}isNumeric(t,i){return!(!t||"number"!=typeof t)||(Rt(this.config,Nt(_,i,"number"),i),!1)}isInteger(t,i){return!!Number.isInteger(t)||(Rt(this.config,Nt(_,i,"integer"),i),!1)}toApiKeys(){const t={[M]:this.visitorId,[w]:this.ds,[R]:`${this.config?.envId}`,[V]:this.type,[D]:null,[L]:Date.now()-this._createdAt};return this.qaMode&&(t.qa=!0),this.userIp&&(t.uip=this.userIp),this.screenResolution&&(t.sr=this.screenResolution),this.locale&&(t.ul=this.locale),this.sessionNumber&&(t.sn=this.sessionNumber),this.visitorId&&this.anonymousId&&(t[M]=this.anonymousId,t[D]=this.visitorId),t}toObject(){return{key:this.key,visitorId:this.visitorId,ds:this.ds,type:this.type,userIp:this.userIp,screenResolution:this.screenResolution,locale:this.locale,sessionNumber:this.sessionNumber,anonymousId:this.anonymousId,createdAt:this.createdAt,qaMode:this.qaMode}}isReady(t=!0){return!!(this.visitorId&&this.ds&&this.config&&this.config.envId&&this.type)}}!function(t){t[t.Timer=0]="Timer",t[t.BatchLength=1]="BatchLength",t[t.Flush=2]="Flush",t[t.ActivateLength=3]="ActivateLength",t[t.DirectHit=4]="DirectHit",t[t.DirectActivate=5]="DirectActivate"}(Et||(Et={}));class Wt extends zt{data;_traffic;get traffic(){return this._traffic}set traffic(t){this._traffic=t}constructor(t){super({type:t.type,userIp:t.userIp,screenResolution:t.screenResolution,locale:t.locale,sessionNumber:t.sessionNumber,visitorId:t.visitorId,anonymousId:t.anonymousId}),this.data={...t,version:t.version||"1",stackType:t.stackType||"SDK",stackName:t.stackName||o.name,stackVersion:t.stackVersion||o.version,label:t.label,logLevel:t.logLevel,timestamp:t.timestamp||new Date(Date.now()).toISOString(),timeZone:this.getTimezone(),ds:x,envId:t.envId||t.config.envId},this._traffic=t.traffic,this.config=t.config}getTimezone(){return("object"==typeof Intl?Intl.DateTimeFormat()?.resolvedOptions()?.timeZone:void 0)||""+(new Date).getTimezoneOffset()/60}toApiKeys(){const t={[M]:this.visitorId,[w]:this.data.ds,[R]:`${this.data.config?.envId}`,[V]:this.type,cv:{}},i={version:`${this.data.version}`,logLevel:`${vt[this.data.logLevel]}`,timestamp:`${this.data.timestamp}`,timeZone:`${this.data.timeZone}`,label:`${this.data.label}`,"stack.type":`${this.data.stackType}`,"stack.name":`${this.data.stackName}`,"stack.version":`${this.data.stackVersion}`};if(void 0!==this.data.lastBucketingTimestamp&&(i.lastBucketingTimestamp=`${this.data.lastBucketingTimestamp}`),void 0!==this.data.lastInitializationTimestamp&&(i.lastInitializationTimestamp=`${this.data.lastInitializationTimestamp}`),void 0!==this.data.flagshipInstanceId&&(i.flagshipInstanceId=`${this.data.flagshipInstanceId}`),this.data.accountId&&(i.accountId=`${this.data.accountId}`),this.data.envId&&(i.envId=`${this.data.envId}`),void 0!==this.data.sdkBucketingFile&&(i.sdkBucketingFile=JSON.stringify(this.data.sdkBucketingFile)),void 0!==this.data.stackOriginName&&(i["stack.origin.name"]=`${this.data.stackOriginName}`),void 0!==this.data.stackOriginVersion&&(i["stack.origin.version"]=`${this.data.stackOriginVersion}`),void 0!==this.data.sdkStatus&&(i["sdk.status"]=`${pt[this.data.sdkStatus]}`),void 0!==this.data.sdkConfigLogLevel&&(i["sdk.config.logLevel"]=`${vt[this.data.sdkConfigLogLevel]}`),void 0!==this.data.sdkConfigMode&&(i["sdk.config.mode"]=`${this.data.sdkConfigMode}`),void 0!==this.data.sdkConfigCustomLogManager&&(i["sdk.config.customLogManager"]=`${this.data.sdkConfigCustomLogManager}`),void 0!==this.data.sdkConfigCustomCacheManager&&(i["sdk.config.customCacheManager"]=`${this.data.sdkConfigCustomCacheManager}`),void 0!==this.data.sdkConfigStatusListener&&(i["sdk.config.custom.StatusListener"]=`${this.data.sdkConfigStatusListener}`),void 0!==this.data.sdkConfigTimeout&&(i["sdk.config.timeout"]=""+1e3*this.data.sdkConfigTimeout),void 0!==this.data.sdkConfigPollingInterval&&(i["sdk.config.pollingTime"]=""+1e3*this.data.sdkConfigPollingInterval),void 0!==this.data.sdkConfigTrackingManagerStrategy&&(i["sdk.config.trackingManager.strategy"]=`${Ct[this.data.sdkConfigTrackingManagerStrategy]}`),void 0!==this.data.sdkConfigTrackingManagerBatchIntervals&&(i["sdk.config.trackingManager.batchIntervals"]=""+1e3*this.data.sdkConfigTrackingManagerBatchIntervals),void 0!==this.data.sdkConfigTrackingManagerPoolMaxSize&&(i["sdk.config.trackingManager.poolMaxSize"]=`${this.data.sdkConfigTrackingManagerPoolMaxSize}`),void 0!==this.data.sdkConfigFetchNow&&(i["sdk.config.fetchNow"]=`${this.data.sdkConfigFetchNow}`),void 0!==this.data.sdkConfigReuseVisitorIds&&(i["sdk.config.reuseVisitorIds"]=`${this.data.sdkConfigReuseVisitorIds}`),void 0!==this.data.sdkConfigInitialBucketing&&(i["sdk.config.initialBucketing"]=JSON.stringify(this.data.sdkConfigInitialBucketing)),void 0!==this.data.sdkConfigDecisionApiUrl&&(i["sdk.config.decisionApiUrl"]=`${this.data.sdkConfigDecisionApiUrl}`),void 0!==this.data.sdkConfigHitDeduplicationTime&&(i["sdk.config.hitDeduplicationTime"]=""+1e3*this.data.sdkConfigHitDeduplicationTime),void 0!==this.data.sdkConfigUsingCustomHitCache&&(i["sdk.config.usingCustomHitCache"]=JSON.stringify(this.data.sdkConfigUsingCustomHitCache)),void 0!==this.data.sdkConfigUsingCustomVisitorCache&&(i["sdk.config.usingCustomVisitorCache"]=JSON.stringify(this.data.sdkConfigUsingCustomVisitorCache)),void 0!==this.data.sdkConfigUsingOnVisitorExposed&&(i["sdk.config.usingOnVisitorExposed"]=JSON.stringify(this.data.sdkConfigUsingOnVisitorExposed)),void 0!==this.data.sdkConfigFetchThirdPartyData&&(i["sdk.config.fetchThirdPartyData"]=JSON.stringify(this.data.sdkConfigFetchThirdPartyData)),void 0!==this.data.sdkConfigFetchFlagsBufferingTime&&(i["sdk.config.fetchFlagsBufferingTime"]=JSON.stringify(1e3*this.data.sdkConfigFetchFlagsBufferingTime)),void 0!==this.data.sdkConfigNextFetchConfig&&(i["sdk.config.nextFetchConfig"]=JSON.stringify(this.data.sdkConfigNextFetchConfig)),void 0!==this.data.sdkConfigDisableDeveloperUsageTracking&&(i["sdk.config.disableDeveloperUsageTracking"]=JSON.stringify(this.data.sdkConfigDisableDeveloperUsageTracking)),void 0!==this.data.sdkConfigDisableCache&&(i["sdk.config.disableCache"]=JSON.stringify(this.data.sdkConfigDisableCache)),void 0!==this.data.httpRequestUrl&&(i["http.request.url"]=`${this.data.httpRequestUrl}`),void 0!==this.data.httpRequestMethod&&(i["http.request.method"]=`${this.data.httpRequestMethod}`),void 0!==this.data.httpRequestHeaders&&(i["http.request.headers"]=JSON.stringify(this.data.httpRequestHeaders)),void 0!==this.data.httpRequestBody&&(i["http.request.body"]=JSON.stringify(this.data.httpRequestBody)),void 0!==this.data.httpResponseUrl&&(i["http.response.url"]=`${this.data.httpResponseUrl}`),void 0!==this.data.httpResponseMethod&&(i["http.response.method"]=`${this.data.httpResponseMethod}`),void 0!==this.data.httpResponseHeaders&&(i["http.response.headers"]=JSON.stringify(this.data.httpResponseHeaders)),void 0!==this.data.httpResponseCode&&(i["http.response.code"]=`${this.data.httpResponseCode}`),void 0!==this.data.httpResponseBody&&(i["http.response.body"]=JSON.stringify(this.data.httpResponseBody)),void 0!==this.data.httpResponseTime&&(i["http.response.time"]=`${this.data.httpResponseTime}`),void 0!==this.visitorId&&(i["visitor.visitorId"]=`${this.visitorId}`),void 0!==this.anonymousId&&(i["visitor.anonymousId"]=`${this.anonymousId}`),void 0!==this.data.visitorSessionId&&(i["visitor.sessionId"]=`${this.data.visitorSessionId}`),void 0!==this.data.visitorStatus&&(i["visitor.status"]=`${this.data.visitorStatus}`),void 0!==this.data.visitorInstanceType&&(i["visitor.instanceType"]=`${this.data.visitorInstanceType}`),void 0!==this.data.visitorContext)for(const t in this.data.visitorContext){const e=this.data.visitorContext[t];i[`visitor.context.[${t}]`]=`${e}`}if(void 0!==this.data.visitorConsent&&(i["visitor.consent"]=`${this.data.visitorConsent}`),void 0!==this.data.visitorAssignmentHistory)for(const t in this.data.visitorAssignmentHistory){const e=this.data.visitorAssignmentHistory[t];i[`visitor.assignments.[${t}]`]=e}if(void 0!==this.data.visitorFlags&&this.data.visitorFlags.forEach(((t,e)=>{for(const s in t){const a=t[s],n="value"===s||"key"===s,o="string"==typeof a?a:JSON.stringify(a);i[`visitor.flags.[${e}]${n?"":".metadata"}.${s}`]=o}})),void 0!==this.data.visitorIsAuthenticated&&(i["visitor.isAuthenticated"]=`${this.data.visitorIsAuthenticated}`),void 0!==this.data.visitorInitialCampaigns&&(i["visitor.initialCampaigns"]=JSON.stringify(this.data.visitorInitialCampaigns)),void 0!==this.data.visitorInitialFlagsData&&(i["visitor.initialFlagsData"]=JSON.stringify(Array.isArray(this.data.visitorInitialFlagsData)?this.data.visitorInitialFlagsData:Array.from(this.data.visitorInitialFlagsData))),void 0!==this.data.visitorCampaigns&&(i["visitor.campaigns"]=JSON.stringify(this.data.visitorCampaigns)),void 0!==this.data.visitorCampaignFromCache&&(i["visitor.campaignFromCache"]=JSON.stringify(this.data.visitorCampaignFromCache)),void 0!==this.data.contextKey&&(i.contextKey=`${this.data.contextKey}`),void 0!==this.data.contextValue&&(i.contextValue=`${this.data.contextValue}`),void 0!==this.data.flagKey&&(i["flag.key"]=`${this.data.flagKey}`),void 0!==this.data.flagValue&&(i["flag.value"]=`${this.data.flagValue}`),void 0!==this.data.flagDefault&&(i["flag.default"]=JSON.stringify(this.data.flagDefault)),void 0!==this.data.flagMetadataCampaignId&&(i["flag.metadata.campaignId"]=`${this.data.flagMetadataCampaignId}`),void 0!==this.data.flagMetadataCampaignName&&(i["flag.metadata.campaignName"]=`${this.data.flagMetadataCampaignName}`),void 0!==this.data.flagMetadataVariationGroupId&&(i["flag.metadata.variationGroupId"]=`${this.data.flagMetadataVariationGroupId}`),void 0!==this.data.flagMetadataVariationGroupName&&(i["flag.metadata.variationGroupName"]=`${this.data.flagMetadataVariationGroupName}`),void 0!==this.data.flagMetadataVariationId&&(i["flag.metadata.variationId"]=`${this.data.flagMetadataVariationId}`),void 0!==this.data.flagMetadataVariationName&&(i["flag.metadata.variationName"]=`${this.data.flagMetadataVariationName}`),void 0!==this.data.flagMetadataCampaignSlug&&(i["flag.metadata.campaignSlug"]=`${this.data.flagMetadataCampaignSlug}`),void 0!==this.data.flagMetadataCampaignType&&(i["flag.metadata.campaignType"]=`${this.data.flagMetadataCampaignType}`),void 0!==this.data.flagMetadataCampaignIsReference&&(i["flag.metadata.isReference"]=`${this.data.flagMetadataCampaignIsReference}`),void 0!==this.data.hitContent)for(const t in this.data.hitContent){const e=this.data.hitContent[t];i[`hit.${t}`]="string"==typeof e?e:JSON.stringify(e)}if(void 0!==this.data.batchTriggeredBy&&(i.batchTriggeredBy=`${Et[this.data.batchTriggeredBy]}`),void 0!==this.data.accountSettings)for(const t in this.data.accountSettings){const e=this.data.accountSettings[t];i[`accountSettings.${t}`]="string"==typeof e?e:JSON.stringify(e)}return void 0!==this.data.eAIScore&&(i["eAIScore.eai.eas"]=this.data.eAIScore.eai.eas),void 0!==this.data.isEAIScoreFromLocalCache&&(i.isEAIScoreFromLocalCache=`${this.data.isEAIScoreFromLocalCache}`),void 0!==this.data.eAIDataTimestamp&&(i.eAIDataTimestamp=`${this.data.eAIDataTimestamp}`),t.cv=i,t}isReady(t=!0){return!(t&&!super.isReady())}getErrorMessage(){return"event category and event action are required"}}class Jt extends Wt{constructor(t){super({...t,type:"TROUBLESHOOTING"})}}class Yt{_config;_panic=!1;_httpClient;_statusChangedCallback;_troubleshooting;_lastBucketingTimestamp;_trackingManager;_flagshipInstanceId;get trackingManager(){return this._trackingManager}set trackingManager(t){this._trackingManager=t}get flagshipInstanceId(){return this._flagshipInstanceId}set flagshipInstanceId(t){this._flagshipInstanceId=t}get lastBucketingTimestamp(){return this._lastBucketingTimestamp}get troubleshooting(){return this._troubleshooting}set troubleshooting(t){this._troubleshooting=t}get config(){return this._config}set panic(t){this.updateFlagshipStatus(t?pt.SDK_PANIC:pt.SDK_INITIALIZED),this._panic=t,t&&Ft(this.config,"Panic mode is enabled : all feature are disabled except fetchFlags.",z)}statusChangedCallback(t){this._statusChangedCallback=t}constructor({httpClient:t,config:i,trackingManager:e,flagshipInstanceId:s}){this._config=i,this._httpClient=t,this._trackingManager=e,this._flagshipInstanceId=s||""}updateFlagshipStatus(t){"function"==typeof this._statusChangedCallback&&this._statusChangedCallback&&this._statusChangedCallback(t)}getModifications(t){const i=new Map;return t.forEach((t=>{const e=t.variation.modifications.value;for(const s in e){const a=e[s];i.set(s,{key:s,campaignId:t.id,campaignName:t.name||"",variationGroupId:t.variationGroupId,variationGroupName:t.variationGroupName||"",variationId:t.variation.id,variationName:t.variation.name||"",isReference:!!t.variation.reference,campaignType:t.type,slug:t.slug,value:a})}})),i}isPanic(){return this._panic}handleTroubleshootingError(t){const{error:i,visitor:e,requestBody:s,headers:a,url:n,now:o}=t,r=new Jt({label:mt.GET_CAMPAIGNS_ROUTE_RESPONSE_ERROR,logLevel:vt.ERROR,visitorId:e.visitorId,flagshipInstanceId:this.flagshipInstanceId,anonymousId:e.anonymousId,visitorSessionId:e.instanceId,traffic:100,config:this.config,visitorContext:e.context,httpRequestBody:s,httpRequestHeaders:a,httpRequestMethod:"POST",httpRequestUrl:n,httpResponseBody:i?.message,httpResponseHeaders:i?.headers,httpResponseCode:i?.statusCode,httpResponseTime:Date.now()-o});this.trackingManager?.addTroubleshootingHit(r);const h=xt(i.message||i,{url:n,headers:a,body:s,duration:Date.now()-o});throw new Error(h)}async getDecisionApiCampaignsAsync(t){const i={[P]:`${this.config.apiKey}`,[U]:o.name,[B]:o.version,[G]:K},e={visitorId:t.visitorId,anonymousId:t.anonymousId,trigger_hit:!1,context:t.context,visitor_consent:t.hasConsented},s=`${this.config.decisionApiUrl||h}${this.config.envId}/campaigns?exposeAllKeys=true&extras[]=accountSettings`,a=Date.now();try{const t=await this._httpClient.postAsync(s,{headers:i,timeout:this.config.timeout,body:e,nextFetchConfig:this.config.nextFetchConfig});this.panic=!!t?.body?.panic;let a=null;t?.body?.campaigns&&(a=t.body.campaigns);const n=t?.body?.extras?.accountSettings?.troubleshooting;return n&&(this.troubleshooting={startDate:new Date(n.startDate),endDate:new Date(n.endDate),timezone:n.timezone,traffic:n.traffic}),a}catch(n){this.handleTroubleshootingError({error:n,visitor:t,requestBody:e,headers:i,url:s,now:a})}}}class Zt extends Yt{async getCampaignsAsync(t){return this.getDecisionApiCampaignsAsync(t)}}!function(t){t.PAGE_VIEW="PAGEVIEW",t.PAGE="PAGEVIEW",t.SCREEN_VIEW="SCREENVIEW",t.SCREEN="SCREENVIEW",t.TRANSACTION="TRANSACTION",t.ITEM="ITEM",t.EVENT="EVENT"}(At||(At={}));class Xt extends zt{_context;get context(){return this._context}set context(t){this._context=t}constructor(t){super({type:"SEGMENT",userIp:t.userIp,screenResolution:t.screenResolution,locale:t.locale,sessionNumber:t.sessionNumber,visitorId:t.visitorId,anonymousId:t.anonymousId,qaMode:t.qaMode,isActionTrackingHit:t.isActionTrackingHit}),this.context=t.context}isReady(t=!0){return!(t&&!super.isReady()||!this.context)}toApiKeys(){const t=super.toApiKeys();return t.s=this.context,t}toObject(){return{...super.toObject(),context:this.context}}getErrorMessage(){return"data property is required"}}!function(t){t.ACTION_TRACKING="Action Tracking",t.USER_ENGAGEMENT="User Engagement"}(St||(St={}));class ti extends zt{_category;_action;_label;_value;get category(){return this._category}set category(t){Object.values(St).includes(t)?this._category=t:Rt(this.config,"The category value must be either EventCategory::ACTION_TRACKING or EventCategory::ACTION_TRACKING","category")}get action(){return this._action}set action(t){this.isNotEmptyString(t,"action")&&(this._action=t)}get label(){return this._label}set label(t){this.isNotEmptyString(t,"label")&&(this._label=t)}get value(){return this._value}set value(t){!Number.isInteger(t)||t<0?Rt(this.config,"value must be an integer and be >= 0","value"):this._value=t}constructor(t){super({type:At.EVENT,userIp:t.userIp,screenResolution:t.screenResolution,locale:t.locale,sessionNumber:t.sessionNumber,visitorId:t.visitorId,anonymousId:t.anonymousId,qaMode:t.qaMode,isActionTrackingHit:t.isActionTrackingHit});const{category:i,action:e,label:s,value:a}=t;this.category=i,this.action=e,s&&(this.label=s),a&&(this.value=a)}toApiKeys(){const t=super.toApiKeys();return t.ec=this.category,t.ea=this.action,this.label&&(t.el=this.label),this.value&&(t.ev=this.value),t}toObject(){return{...super.toObject(),category:this.category,action:this.action,label:this.label,value:this.value}}isReady(t=!0){return!(t&&!super.isReady()||!this.category||!this.action)}getErrorMessage(){return"event category and event action are required"}}class ii extends zt{_documentLocation;get documentLocation(){return this._documentLocation}set documentLocation(t){this.isNotEmptyString(t,"documentLocation")&&(this._documentLocation=t)}constructor(t){super({type:At.SCREEN_VIEW,userIp:t.userIp,screenResolution:t.screenResolution,locale:t.locale,sessionNumber:t.sessionNumber,visitorId:t.visitorId,anonymousId:t.anonymousId,qaMode:t.qaMode,isActionTrackingHit:t.isActionTrackingHit}),this.documentLocation=t.documentLocation}isReady(t=!0){return!(t&&!super.isReady()||!this.documentLocation)}toApiKeys(){const t=super.toApiKeys();return t.dl=this.documentLocation,t}toObject(){return{...super.toObject(),documentLocation:this.documentLocation}}getErrorMessage(){return"Screen name is required"}}class ei{_hits;_config;get hits(){return this._hits}get config(){return this._config}constructor(t,i){this._config=i,this._hits=t}toApiKeys(){return{[R]:`${this.config?.envId}`,[k]:this.hits.map((t=>{const i=t.toApiKeys();return delete i[R],i}))}}}class si extends zt{_variationGroupId;_variationId;_flagKey;_flagValue;_flagDefaultValue;_flagMetadata;_visitorContext;constructor(t){super({type:"ACTIVATE",userIp:t.userIp,screenResolution:t.screenResolution,locale:t.locale,sessionNumber:t.sessionNumber,visitorId:t.visitorId,anonymousId:t.anonymousId,qaMode:t.qaMode});const{variationGroupId:i,variationId:e,flagKey:s,flagValue:a,flagDefaultValue:n,flagMetadata:o,visitorContext:r}=t;this.variationGroupId=i,this.variationId=e,this.flagKey=s,this.flagValue=a,this.flagDefaultValue=n,this.flagMetadata=o,this.visitorContext=r}get variationGroupId(){return this._variationGroupId}set variationGroupId(t){this._variationGroupId=t}get variationId(){return this._variationId}set variationId(t){this._variationId=t}get flagKey(){return this._flagKey}set flagKey(t){this._flagKey=t}get flagValue(){return this._flagValue}set flagValue(t){this._flagValue=t}get flagDefaultValue(){return this._flagDefaultValue}set flagDefaultValue(t){this._flagDefaultValue=t}get flagMetadata(){return this._flagMetadata}set flagMetadata(t){this._flagMetadata=t}get visitorContext(){return this._visitorContext}set visitorContext(t){this._visitorContext=t}isReady(t=!0){return!(t&&!super.isReady()||!this.variationGroupId||!this.variationId)}toApiKeys(){const t={[M]:this.anonymousId||this.visitorId,[F]:this.variationId,[H]:this.variationGroupId,[b]:this.config.envId,[O]:null,[L]:Date.now()-this.createdAt};return this.visitorId&&this.anonymousId&&(t[M]=this.visitorId,t.aid=this.anonymousId),this.qaMode&&(t.qa=this.qaMode),t}toObject(){return{...super.toObject(),variationGroupId:this.variationGroupId,variationId:this.variationId}}getErrorMessage(){return"variationGroupId and variationId are required"}}class ai extends zt{_hits;get hits(){return this._hits}set hits(t){this._hits=t}constructor(t){super({...t,visitorId:"",anonymousId:"",type:"BATCH"}),this.hits=t.hits}isReady(){return!!(super.isReady()&&this.hits&&this.hits.length>0&&this.hits.every((t=>t.isReady(!1))))}toApiKeys(){const t={[w]:this.ds,[R]:`${this.config?.envId}`,[V]:this.type,[L]:Date.now()-this.createdAt};return t.h=this.hits.map((t=>{const i=t.toApiKeys();return delete i[w],delete i[R],i})),t}getErrorMessage(){return"Please check required fields"}}class ni{_config;_hitsPoolQueue;_activatePoolQueue;_httpClient;_troubleshootingQueue;_usageHitQueue;_flagshipInstanceId;_isUsageHitQueueSending;_isTroubleshootingQueueSending;_HitsToFsQa;_sendFsHitToQATimeoutId;_troubleshootingData;_initTroubleshootingHit;_hasInitTroubleshootingHitSent;_sharedActionTracking;get flagshipInstanceId(){return this._flagshipInstanceId}get troubleshootingData(){return this._troubleshootingData}set troubleshootingData(t){this._troubleshootingData=t}get config(){return this._config}get initTroubleshootingHit(){return this._initTroubleshootingHit}set initTroubleshootingHit(t){this._initTroubleshootingHit=t}constructor(t){const{config:i,hitsPoolQueue:e,httpClient:s,activatePoolQueue:a,troubleshootingQueue:n,flagshipInstanceId:o,analyticHitQueue:r,initTroubleshootingHit:h,sharedActionTracking:c}=t;this._HitsToFsQa=[],this._hasInitTroubleshootingHitSent=!1,this._config=i,this._hitsPoolQueue=e,this._httpClient=s,this._activatePoolQueue=a,this._troubleshootingQueue=n,this._flagshipInstanceId=o,this._usageHitQueue=r,this._isUsageHitQueueSending=!1,this._isTroubleshootingQueueSending=!1,this._initTroubleshootingHit=h,this._sharedActionTracking=c}dispatchHitsToTag(t){}sendHitsToFsQa(t){}async addHit(t){const i=`${t.visitorId}:${Lt()}`;t.key=i,await this.addHitInPoolQueue(t),t.type===At.EVENT&&t.action===l&&t.label===`${o.name}:false`&&await this.notConsent(t.visitorId),Ht(this.config,ct,"The HIT has been added into the pool queue : {0}",t.toApiKeys()),this.config.trackingManagerConfig?.poolMaxSize&&this._hitsPoolQueue.size>=this.config.trackingManagerConfig.poolMaxSize&&this.config.decisionMode!==It.BUCKETING_EDGE&&this.sendBatch()}async activateFlag(t){const i=new si(t);i.config=this.config;const e=`${i.visitorId}:${Lt()}`;if(i.key=e,this.config.decisionMode===It.BUCKETING_EDGE)return await this.activateFlagEdgeMode(i),void Ft(this.config,Nt("The ACTIVATE has been added to the pool queue : {0}",JSON.stringify(i.toApiKeys())),"ADD ACTIVATE");let s=[];this._activatePoolQueue.size&&(s=Array.from(this._activatePoolQueue.values())),this._activatePoolQueue.clear(),await this.sendActivate({activateHitsPool:s,currentActivate:i,batchTriggeredBy:Et.ActivateLength})}async activateFlagEdgeMode(t){this._activatePoolQueue.set(t.key,t),await this.cacheHit(new Map([[t.key,t]]))}onVisitorExposed(t){const i=this.config.onVisitorExposed;if("function"!=typeof i)return;const e={key:t.flagKey,value:t.flagValue,defaultValue:t.flagDefaultValue,metadata:t.flagMetadata};i({exposedVisitor:{id:t.visitorId,anonymousId:t.anonymousId,context:t.visitorContext},fromFlag:e})}async sendBatch(t=Et.BatchLength){if(this._activatePoolQueue.size){const i=Array.from(this._activatePoolQueue.values());this._activatePoolQueue.clear(),await this.sendActivate({activateHitsPool:i,batchTriggeredBy:t})}const i=new ai({hits:[],ds:x});i.config=this.config;const e=[];for(const[t,s]of this._hitsPoolQueue)if(Date.now()-s.createdAt>=f)e.push(t);else{if(JSON.stringify(i).length>r)break;i.hits.push(s),e.push(t)}if(e.forEach((t=>{this._hitsPoolQueue.delete(t)})),!i.hits.length)return;const s={[G]:K},a=i.toApiKeys(),n=Date.now();try{await this._httpClient.postAsync(c,{headers:s,body:a,timeout:this.config.timeout,nextFetchConfig:this.config.nextFetchConfig}),Ht(this.config,ct,dt,lt,{url:c,body:a,headers:s,nextFetchConfig:this.config.nextFetchConfig,duration:Date.now()-n,batchTriggeredBy:Et[t]}),await this.flushHits(e),this.sendHitsToFsQa(i.hits),this.dispatchHitsToTag(i.hits)}catch(e){i.hits.forEach((t=>{this._hitsPoolQueue.set(t.key,t)})),kt(this.config,ct,gt,lt,{httpRequestBody:a,httpRequestHeaders:s,httpRequestMethod:"POST",httpRequestUrl:c,httpResponseBody:e?.message,httpResponseHeaders:e?.headers,httpResponseCode:e?.statusCode,duration:Date.now()-n,batchTriggeredBy:Et[t]});const o=new Jt({label:mt.SEND_BATCH_HIT_ROUTE_RESPONSE_ERROR,logLevel:vt.ERROR,visitorId:`${this._flagshipInstanceId}`,flagshipInstanceId:this._flagshipInstanceId,traffic:0,config:this.config,httpRequestBody:i.hits,httpRequestHeaders:s,httpResponseBody:e?.message,httpResponseHeaders:e?.headers,httpResponseMethod:"POST",httpResponseUrl:c,httpResponseCode:e?.statusCode,httpResponseTime:Date.now()-n,batchTriggeredBy:t});this.sendTroubleshootingHit(o)}}async notConsent(t){const i=Array.from(this._hitsPoolQueue).filter((([,i])=>!(i?.type===At.EVENT&&i?.action===l||i.visitorId!==t&&i.anonymousId!==t))),e=Array.from(this._activatePoolQueue).filter((([,i])=>i.visitorId===t||i.anonymousId===t)),s=[];i.forEach((([t])=>{this._hitsPoolQueue.delete(t),s.push(t)})),e.forEach((([t])=>{this._activatePoolQueue.delete(t),s.push(t)})),s.length&&await this.flushHits(s)}async cacheHit(t){try{const i=this.config.hitCacheImplementation;if(this.config.disableCache||!i||"function"!=typeof i.cacheHit)return;const e={};t.forEach(((t,i)=>{const s={version:1,data:{visitorId:t.visitorId,anonymousId:t.anonymousId,type:t.type,content:t.toObject(),time:Date.now()}};e[i]=s})),await i.cacheHit(e),Ht(this.config,"CACHE HIT","Hit cache has been saved into database : {0}",e)}catch(t){kt(this.config,ot,ht,"cacheHit",t.message||t)}}async flushHits(t){try{const i=this.config.hitCacheImplementation;if(this.config.disableCache||!i||"function"!=typeof i.flushHits)return;await i.flushHits(t),Ht(this.config,ot,"The following hit keys have been flushed from database : {0}",t)}catch(t){kt(this.config,ot,ht,"flushHits",t.message||t)}}async flushAllHits(){try{const t=this.config.hitCacheImplementation;if(this.config.disableCache||!t||"function"!=typeof t.flushAllHits)return;await t.flushAllHits(),Ft(this.config,"All hits cache has been flushed from database","FLUSH HIT")}catch(t){kt(this.config,ot,ht,"flushAllHits",t.message||t)}}isTroubleshootingActivated(){if(!this.troubleshootingData)return!1;const t=new Date;return t>=this.troubleshootingData.startDate&&!(t>this.t