UNPKG

opticks

Version:

FindHotel Toggle Flag JavaScript SDK

2 lines 1.93 kB
import{a as c,b as g,c as A}from"./chunk-2ZGTETJC.mjs";import I from"@optimizely/optimizely-sdk";var h=I.enums.NOTIFICATION_TYPES,x=I,s,y,r={},T,p={},a={},w=e=>{x=e},C=()=>{p={}},M=e=>{Object.keys(e).forEach(t=>{let n=e[t];if(typeof n=="boolean"){a[t]=n?"b":"a";return}n===null?delete a[t]:a[t]=n})},d=()=>{C()},j=e=>{y!==e&&d(),y=e},B=(e={})=>{let t=c(c({},r),e);JSON.stringify(t)!==JSON.stringify(r||{})&&d(),r=t},J=()=>{d(),r={}},v=()=>null,b={dispatchEvent:()=>null},O=(n=>(n.flag="flag",n.mvt="feature-test",n))(O||{}),Y=(e,t=v,n=b)=>(s=x.createInstance({datafile:e,eventDispatcher:n}),E(t),s),E=e=>{let t=n=>{let{variationKey:i}=n.decisionInfo,o=i==="on"?"b":i==="off"?"a":i,f=g(c({},n),{decisionInfo:g(c({},n.decisionInfo),{variationKey:o})});return e(f)};return s.notificationCenter.addNotificationListener(h.DECISION,t)},S=(e,t)=>a.hasOwnProperty(e)||t.hasOwnProperty(e),N=(e,t)=>(a.hasOwnProperty(e)?a:t)[e],P=e=>{if(!e)throw new Error("Opticks: Fatal error: user id is not set")},_=e=>{let t=s.projectConfigManager.getConfig(),n=t.featureKeyMap[e],o=[...t.rolloutIdMap[n.rolloutId].experiments];if(n.experimentIds.length>0){let{experimentIds:u}=n,l=u.map(m=>t.experimentIdMap[m]);o.push(...l)}return o.reduce((u,l)=>s.decisionService.checkIfUserIsInAudience(t,l,"rule",T,r,"").result&&!U(l)?!0:u,!1)},U=e=>{let t=e.trafficAllocation[0];return typeof t=="undefined"||t.endOfRange===1e4},V=e=>{P(y);let t="a";if(S(e,p)){let o=N(e,p);return typeof o=="string"?o:t}T=s.createUserContext(y,r);let n=T.decide(e).variationKey,i=n==="on"?"b":n==="off"?"a":n;return p[e]=i||t,i||t};function H(e,...t){return A(V)(e,...t)}export{O as ExperimentType,h as NOTIFICATION_TYPES,E as addActivateListener,M as forceToggles,Y as initialize,_ as isUserInRolloutAudience,w as registerLibrary,J as resetAudienceSegmentationAttributes,B as setAudienceSegmentationAttributes,j as setUserId,H as toggle}; //# sourceMappingURL=optimizely.mjs.map