@uniformdev/context 12.2.1-alpha.126 → 12.2.1-alpha.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/api.mjs +1 -1
- package/dist/chunk-TRWANXVF.mjs +1 -0
- package/dist/chunk-WLJXJJSU.mjs +2 -0
- package/dist/cli/cli.js +20 -25
- package/dist/cli/cli.mjs +20 -25
- package/dist/index.esm.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +11 -10
- package/dist/chunk-5ZM3QNMG.mjs +0 -2
- package/dist/chunk-POAQ5JTB.mjs +0 -1
package/dist/index.esm.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import{d as v,e as s,f as d,g as f,h as S,i as a}from"./chunk-POAQ5JTB.mjs";a();a();a();function at(i,t){let e={...i};for(let r in t){let o=ct(i,r,t,new Set([r]));o!==0&&(e[r]=o)}return e}function ct(i,t,e,r){var n;let o=0;for(let c of e[t].inputs){let u=(n=i[c.dim])!=null?n:0;if(!u&&e[c.dim]){if(r.has(c.dim))continue;let g=new Set(r);g.add(c.dim),u=ct(i,c.dim,e,g)}if(u!==0)if(c.sign==="c"){o=0;break}else c.sign==="-"?o-=u:o+=u}return o}a();var $,b,Z=class{constructor(t,e,r){d(this,$,void 0);d(this,b,void 0);v(this,"signal");f(this,b,t),this.signal=e,f(this,$,r)}computeSignals(t,e){if(t.scores[s(this,b)]>=this.signal.cap&&this.signal.dur!=="t")return;let o=s(this,$).evaluate(t,this.signal.crit,e,this.signal,s(this,b)),n=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(o)e.push({type:n,data:{dimension:s(this,b),delta:this.signal.str}});else if(this.signal.dur==="t"){let c=t.visitor.sessionScores[s(this,b)];c&&e.push({type:n,data:{dimension:s(this,b),delta:-c}})}}};$=new WeakMap,b=new WeakMap;var ut="_",x,N,q=class{constructor({manifest:t,evaluator:e=new G({})}){d(this,x,void 0);d(this,N,void 0);var r,o,n;f(this,x,(r=t.project)!=null?r:{}),f(this,N,Object.entries((n=(o=s(this,x).pz)==null?void 0:o.sig)!=null?n:[]).map(([c,u])=>new Z(c,u,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=s(this,x).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=s(this,x).test)==null?void 0:e[t]}computeSignals(t){let e=[];return s(this,N).forEach(r=>{r.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,r;return at(t,(r=(e=s(this,x).pz)==null?void 0:e.agg)!=null?r:{})}getDimensionByKey(t){var r,o,n,c;let e=t.indexOf(ut);return e<=0?(o=(r=s(this,x).pz)==null?void 0:r.sig)==null?void 0:o[t]:(c=(n=s(this,x).pz)==null?void 0:n.enr)==null?void 0:c[t.substring(0,e)]}static getEnrichmentVectorKey(t,e){return`${t}${ut}${e}`}};x=new WeakMap,N=new WeakMap;a();var dt=(i,t)=>{var o;if(t.type!=="CK")return!1;let e=(o=i.state.cookies)==null?void 0:o[t.cookieName];return k(e,t.match)};a();a();function lt(i,t){var r;if(typeof i=="undefined"||i===null)return!1;let e=Number(i);if(isNaN(e))return!1;switch((r=t==null?void 0:t.op)!=null?r:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}var tt=q.getEnrichmentVectorKey("$pvc","v"),pt=(i,t,e)=>{var c,u;if(t.type!=="PVC")return!1;let r=!i.previousState||((c=i.state.url)==null?void 0:c.toString())!==((u=i.previousState.url)==null?void 0:u.toString()),n=(i.visitor.sessionScores[tt]||0)+1;if(lt(n,t.match)){let l=e.some(g=>g.type==="modscoreS"&&g.data.dimension===tt);return r&&!l&&e.push({type:"modscoreS",data:{dimension:tt,delta:1}}),!0}return!1};a();var mt=(i,t)=>{var r;if(t.type!=="QS")return!1;let e=(r=i.state.url)==null?void 0:r.searchParams.get(t.queryName);return k(e,t.match)};a();var ft=(i,t,e,r,o)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&r.dur==="t"&&i.scores[o]>0)return!0;let n=i.visitor.quirks[t.key];return k(n,t.match)};a();var gt=(i,t)=>{var e,r;return t.type!=="EVT"?!1:(r=(e=i.state.events)==null?void 0:e.some(o=>k(o.event,t.event)))!=null?r:!1};a();var ht=(i,t)=>{var e;return t.type!=="PV"?!1:k((e=i.state.url)==null?void 0:e.pathname,t.path)};a();var j,G=class{constructor(t){d(this,j,void 0);f(this,j,t)}evaluate(t,e,r,o,n){let c=!(e.op==="&"||!e.op);for(let u of e.clauses){let l;if(u.type==="G")l=this.evaluate(t,u,r,o,n);else{let g=s(this,j)[u.type];if(!g)throw new Error(`${u.type} signal criteria not registered`);l=g(t,u,r,o,n)}if(l===c)return c}return!c}};j=new WeakMap;a();function k(i,t){var c,u,l,g;let e=(c=t==null?void 0:t.op)!=null?c:"=";if(t.op==="*")return i!==null&&typeof i!="undefined";if(t.op==="!*")return i===null||typeof i=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let r=(u=t.cs)!=null?u:!1,o=r?i!=null?i:"":St(i),n=r?t.rhs:St(t.rhs);switch(e){case"=":return o===n;case"!=":return o!==n;case"~":return(l=o.includes(n))!=null?l:!1;case"!~":return!((g=o.includes(n))!=null?g:!0);case"//":return new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");case"!//":return!new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");default:throw new Error(`Unknown match type ${e}.`)}}function St(i){var t;return(t=i==null?void 0:i.toUpperCase())!=null?t:""}a();var J=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});a();a();import Ut from"mitt";import{dequal as It}from"dequal/lite";var Rt="__UNIFORM_DATA__",w,L,_=class{constructor({initialData:t}){d(this,w,void 0);d(this,L,Ut());v(this,"events",{on:s(this,L).on,off:s(this,L).off});t&&f(this,w,t)}get data(){return s(this,w)}updateData(t,e){return f(this,w,e),this.handleUpdateData(t,e)}async delete(t){f(this,w,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){It(this.data,t)||(f(this,w,t),s(this,L).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(Rt);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};w=new WeakMap,L=new WeakMap;import{ntob as qt,bton as Lt}from"number-to-base64";var yt=typeof window=="undefined",U,I,zt=class extends _{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:yt?At(t.get(e)):void 0});d(this,U,void 0);d(this,I,void 0);f(this,U,e),f(this,I,t)}handleDelete(){return s(this,I).remove(s(this,U)),Promise.resolve()}async handleUpdateData(t,e){yt||(e.consent?s(this,I).set(s(this,U),$t(e)):s(this,I).remove(s(this,U)))}};U=new WeakMap,I=new WeakMap;var vt="~",Dt="!",Vt="-";function At(i){if(!i)return;let t=i.split(vt);if(t.length>3)return;let[e,r,o]=t;return{consent:!0,sessionScores:Ct(et(r)),scores:Ct(et(o)),tests:et(e)}}function et(i){return i.split(Dt).map(e=>e.split(Vt)).reduce((e,r)=>(r.length!==2||(e[r[0]]=r[1]),e),{})}function Ct(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=Lt(r),t),{})}function $t(i){return[rt(i.tests),rt(xt(i.sessionScores)),rt(xt(i.scores))].join(vt)}function xt(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=qt(r),t),{})}function rt(i){return Object.entries(i).map(t=>t.join(Vt)).join(Dt)}a();var B,Gt,Nt=class extends _{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...r}){super(r);d(this,B);r.initialData||S(this,B,Gt).call(this).catch(o=>{console.error(o)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(r=>{setTimeout(()=>{r(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};B=new WeakSet,Gt=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};a();function $e(i){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:r=.95}=i!=null?i:{};return function({now:n,lastUpd:c,scores:u,sessionScores:l}){if(typeof c!="number")return!1;let O=n-c-t;if(O<=0)return!1;let K=O/864e5,X=1-Math.min(r,K*e);return X<=0?!1:(kt(u,X),kt(l,X),!0)}}function kt(i,t){for(let e in i)i[e]*=t}a();import Ft from"mitt";import{dequal as ot}from"dequal/lite";a();var it=class{constructor(){v(this,"inMemoryFallback",{});v(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let r=localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(r){return e}}set(t,e,r){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!r))try{localStorage.setItem(t,JSON.stringify(e))}catch(o){console.warn(o)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(r){}}};a();import jt from"rfdc";var _t=jt();function bt(i,t,e){let r=t?_t(t):J();return i.forEach(o=>{var n,c;switch(o.type){case"consent":r.consent=o.data;break;case"setquirk":r.quirks[o.data.key]=o.data.value;break;case"settest":r.tests[o.data.test]=o.data.variant;break;case"modscore":if(e)break;let u=(n=r.scores[o.data.dimension])!=null?n:0;r.scores[o.data.dimension]=u+o.data.delta;break;case"modscoreS":if(e)break;let l=(c=r.sessionScores[o.data.dimension])!=null?c:0;r.sessionScores[o.data.dimension]=l+o.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),r}var Y="ufvisitor",D,R,A,y,V,P,E,z,H,Qt,W,Kt,F,Et,Q,Tt,st=class{constructor(t){d(this,V);d(this,E);d(this,H);d(this,W);d(this,F);d(this,Q);d(this,D,Ft());d(this,R,new it);d(this,A,void 0);d(this,y,void 0);v(this,"events",{on:s(this,D).on,off:s(this,D).off});if(f(this,y,t),s(this,V,P)||S(this,E,z).call(this,S(this,Q,Tt).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();e&&e.quirks&&this.updateData(Object.entries(e.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.transitionStore.events.on("dataUpdatedAsync",o=>{S(this,E,z).call(this,{...s(this,V,P).visitorData,...o})});let r=t.transitionStore.data;r&&S(this,E,z).call(this,{...s(this,V,P).visitorData,...r},!0)}}get data(){let t=s(this,V,P);if(S(this,W,Kt).call(this,t)){let{sessionScores:e,...r}=t.visitorData;return S(this,E,z).call(this,{...r,sessionScores:{}}),s(this,D).emit("log",["info",120]),s(this,V,P).visitorData}return t.visitorData}async updateData(t){var r,o;if(t.length===0)return;s(this,D).emit("log",["debug",101,t]);let e=bt(t,this.data,(r=s(this,V,P))==null?void 0:r.visitorData.controlGroup);t.some(n=>n.type==="consent"&&!n.data)&&s(this,R).delete(Y,!0),S(this,E,z).call(this,e),await((o=s(this,y).transitionStore)==null?void 0:o.updateData(t,s(this,V,P).visitorData))}async delete(t){var e;s(this,R).delete(Y,!1),await((e=s(this,y).transitionStore)==null?void 0:e.delete(t)),s(this,D).emit("log",["info",103,t]),S(this,E,z).call(this,S(this,Q,Tt).call(this))}};D=new WeakMap,R=new WeakMap,A=new WeakMap,y=new WeakMap,V=new WeakSet,P=function(){return s(this,R).get(Y)},E=new WeakSet,z=function(t,e=!1){var g,O;let r=s(this,V,P),o=Date.now();S(this,F,Et).call(this,t.scores),S(this,F,Et).call(this,t.sessionScores),(O=(g=s(this,y)).decay)==null||O.call(g,{now:o,lastUpd:r==null?void 0:r.updated,scores:t.scores,sessionScores:t.sessionScores});let n=!ot(r==null?void 0:r.visitorData.scores,t.scores),c=!ot(r==null?void 0:r.visitorData.sessionScores,t.sessionScores),u=!ot(r==null?void 0:r.visitorData.quirks,t.quirks),l={updated:o,visitorData:t};S(this,H,Qt).call(this),s(this,R).set(Y,l,!!t.consent),s(this,D).emit("log",["debug",102,t]),e||((n||c)&&s(this,D).emit("scoresUpdated",t),u&&s(this,D).emit("quirksUpdated",t))},H=new WeakSet,Qt=function(){typeof window=="undefined"||!s(this,y).visitLifespan||(s(this,A)&&window.clearTimeout(s(this,A)),f(this,A,window.setTimeout(()=>{this.data},s(this,y).visitLifespan+50)))},W=new WeakSet,Kt=function(t){let e=s(this,y).visitLifespan;return e?t.updated+e<Date.now():!1},F=new WeakSet,Et=function(t){if(!!s(this,y).manifest)for(let e in t){let r=t[e],o=s(this,y).manifest.getDimensionByKey(e);!o||r>o.cap&&(s(this,D).emit("log",["debug",110,{dim:e,score:r,cap:o.cap}]),t[e]=o.cap)}},Q=new WeakSet,Tt=function(){var t,e,r;return{...J(),consent:(t=s(this,y).defaultConsent)!=null?t:!1,controlGroup:(r=(e=s(this,y).manifest)==null?void 0:e.rollForControlGroup())!=null?r:!1}};a();import Bt from"mitt";a();a();function wt({context:i,variations:t,take:e=1}){var u;let r=(u=i.storage.data.controlGroup)!=null?u:!1,o=[],n=!1,c=i.scores;for(let l of t){if(o.length===e)break;if(!l.pz){o.push(l);continue}!r&&Pt(l.pz,c)&&(n=!0,o.push(l))}return{personalized:n,variations:o}}a();function Pt(i,t){return!i.op||i.op==="&"?i.crit.every(e=>Mt(e,t)):i.crit.some(e=>Mt(e,t))}function Mt(i,t){var c;let{op:e,l:r}=i,o=(c=t[r])!=null?c:0;if(e==="+")return Math.max(...Object.values(t))===o&&o>0;if(e==="-")return Math.min(...Object.values(t))===o&&o>0;let n=i.rDim?t[i.rDim]:i.r;if(n===void 0)return!1;if(e===">")return o>n;if(e===">=")return o>=n;if(e==="<")return o<n;if(e==="<=")return o<=n;if(e==="=")return o===n;if(e==="!=")return o!==n;throw new Error(`Unknown op: ${e}`)}a();var Jt=i=>{let{values:t,total:e,missingDistribution:r}=i.reduce((o,n)=>(n.testDistribution?o.total+=n.testDistribution:++o.missingDistribution,o.values.push(n.testDistribution),o),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let n=(100-e)/r;t.forEach((c,u)=>{typeof c=="undefined"&&(t[u]=n)})}return t},nt=({name:i,context:t,variations:e})=>{var n;let r,o=t.getTestVariantId(i);if(o===null)return{result:void 0};if(o&&(r=e.find(c=>c.id===o),r||t.log("warn",401,{test:i,variant:o})),!r){let c=Jt(e),u=Math.floor(Math.random()*100),l=0;r=e.find((g,O)=>{let K=c[O];if(u>l&&u<=l+K)return g;l+=K}),r&&t.setTestVariantId(i,(n=r.id)!=null?n:"Unknown")}return{result:r}};var T,M,C,h,Yt=class{constructor(t){d(this,T,void 0);d(this,M,{});d(this,C,void 0);d(this,h,Bt());v(this,"events",{on:s(this,h).on,off:s(this,h).off});v(this,"storage");let{manifest:e,...r}=t;f(this,C,{}),f(this,T,new q({manifest:e,evaluator:new G({CK:dt,QS:mt,QK:ft,PVC:pt,EVT:gt,PV:ht})})),this.storage=new st({manifest:s(this,T),...r}),this.storage.events.on("log",(...n)=>s(this,h).emit("log",...n));let o=n=>{var u;let c={...n.scores};for(let l in n.sessionScores)c[l]=((u=c[l])!=null?u:0)+n.sessionScores[l];c=s(this,T).computeAggregateDimensions(c),f(this,M,c),s(this,h).emit("scoresUpdated",c),s(this,h).emit("log",["info",3,c])};this.storage.events.on("scoresUpdated",o),o(this.storage.data),this.storage.events.on("quirksUpdated",n=>{let c=s(this,T).computeSignals({scores:s(this,M),state:s(this,C),previousState:s(this,C),visitor:this.storage.data});this.storage.updateData(c),s(this,h).emit("quirksUpdated",n.quirks),s(this,h).emit("log",["info",4,n.quirks])}),s(this,h).emit("log",["debug",1,{options:t,scores:s(this,M)}])}get scores(){return s(this,M)}async update(t){let e=[];s(this,h).emit("log",["info",2,t]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(o=>({type:"modscore",data:{dimension:q.getEnrichmentVectorKey(o.cat,o.key),delta:o.str}}))),t.enrichments=void 0);let r=s(this,C);f(this,C,{...s(this,C),...t}),e.push(...s(this,T).computeSignals({state:s(this,C),previousState:r,visitor:this.storage.data,scores:s(this,M)})),await this.storage.updateData(e)}getTestVariantId(t){var r;let e=s(this,T).getTest(t);return e?(r=e.wv)!=null?r:this.storage.data.tests[t]:(s(this,h).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){s(this,h).emit("log",t)}test(t){var r;let e=nt({...t,context:this});return s(this,h).emit("testResult",{name:t.name,variantId:(r=e.result)==null?void 0:r.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=wt({...t,context:this});return t.name?s(this,h).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(r=>{var o;return(o=r.id)!=null?o:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){f(this,C,{}),await this.storage.delete(t)}};T=new WeakMap,M=new WeakMap,C=new WeakMap,h=new WeakMap;a();var Vr=([i,t,...e])=>{console[i](`\u{1F94B} [${i}] Uniform event ID ${t}
|
2
|
-
`,...e.map(r=>JSON.stringify(r,null,2)))};
|
3
|
-
`,...
|
1
|
+
import{b as y,c as s,d as u,e as m,f as h}from"./chunk-TRWANXVF.mjs";function nt(i,t){let e={...i};for(let r in t){let o=at(i,r,t,new Set([r]));o!==0&&(e[r]=o)}return e}function at(i,t,e,r){var n;let o=0;for(let a of e[t].inputs){let c=(n=i[a.dim])!=null?n:0;if(!c&&e[a.dim]){if(r.has(a.dim))continue;let f=new Set(r);f.add(a.dim),c=at(i,a.dim,e,f)}if(c!==0)if(a.sign==="c"){o=0;break}else a.sign==="-"?o-=c:o+=c}return o}var A,k,X=class{constructor(t,e,r){u(this,A,void 0);u(this,k,void 0);y(this,"signal");m(this,k,t),this.signal=e,m(this,A,r)}computeSignals(t,e){if(t.scores[s(this,k)]>=this.signal.cap&&this.signal.dur!=="t")return;let o=s(this,A).evaluate(t,this.signal.crit,e,this.signal,s(this,k)),n=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(o)e.push({type:n,data:{dimension:s(this,k),delta:this.signal.str}});else if(this.signal.dur==="t"){let a=t.visitor.sessionScores[s(this,k)];a&&e.push({type:n,data:{dimension:s(this,k),delta:-a}})}}};A=new WeakMap,k=new WeakMap;var ct="_",C,$,R=class{constructor({manifest:t,evaluator:e=new N({})}){u(this,C,void 0);u(this,$,void 0);var r,o,n;m(this,C,(r=t.project)!=null?r:{}),m(this,$,Object.entries((n=(o=s(this,C).pz)==null?void 0:o.sig)!=null?n:[]).map(([a,c])=>new X(a,c,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=s(this,C).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=s(this,C).test)==null?void 0:e[t]}computeSignals(t){let e=[];return s(this,$).forEach(r=>{r.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,r;return nt(t,(r=(e=s(this,C).pz)==null?void 0:e.agg)!=null?r:{})}getDimensionByKey(t){var r,o,n,a;let e=t.indexOf(ct);return e<=0?(o=(r=s(this,C).pz)==null?void 0:r.sig)==null?void 0:o[t]:(a=(n=s(this,C).pz)==null?void 0:n.enr)==null?void 0:a[t.substring(0,e)]}static getEnrichmentVectorKey(t,e){return`${t}${ct}${e}`}};C=new WeakMap,$=new WeakMap;var ut=(i,t)=>{var o;if(t.type!=="CK")return!1;let e=(o=i.state.cookies)==null?void 0:o[t.cookieName];return x(e,t.match)};function dt(i,t){var r;if(typeof i=="undefined"||i===null)return!1;let e=Number(i);if(isNaN(e))return!1;switch((r=t==null?void 0:t.op)!=null?r:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}var Z=R.getEnrichmentVectorKey("$pvc","v"),lt=(i,t,e)=>{var a,c;if(t.type!=="PVC")return!1;let r=!i.previousState||((a=i.state.url)==null?void 0:a.toString())!==((c=i.previousState.url)==null?void 0:c.toString()),n=(i.visitor.sessionScores[Z]||0)+1;if(dt(n,t.match)){let d=e.some(f=>f.type==="modscoreS"&&f.data.dimension===Z);return r&&!d&&e.push({type:"modscoreS",data:{dimension:Z,delta:1}}),!0}return!1};var pt=(i,t)=>{var r;if(t.type!=="QS")return!1;let e=(r=i.state.url)==null?void 0:r.searchParams.get(t.queryName);return x(e,t.match)};var mt=(i,t,e,r,o)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&r.dur==="t"&&i.scores[o]>0)return!0;let n=i.visitor.quirks[t.key];return x(n,t.match)};var ft=(i,t)=>{var e,r;return t.type!=="EVT"?!1:(r=(e=i.state.events)==null?void 0:e.some(o=>x(o.event,t.event)))!=null?r:!1};var gt=(i,t)=>{var e;return t.type!=="PV"?!1:x((e=i.state.url)==null?void 0:e.pathname,t.path)};var G,N=class{constructor(t){u(this,G,void 0);m(this,G,t)}evaluate(t,e,r,o,n){let a=!(e.op==="&"||!e.op);for(let c of e.clauses){let d;if(c.type==="G")d=this.evaluate(t,c,r,o,n);else{let f=s(this,G)[c.type];if(!f)throw new Error(`${c.type} signal criteria not registered`);d=f(t,c,r,o,n)}if(d===a)return a}return!a}};G=new WeakMap;function x(i,t){var a,c,d,f;let e=(a=t==null?void 0:t.op)!=null?a:"=";if(t.op==="*")return i!==null&&typeof i!="undefined";if(t.op==="!*")return i===null||typeof i=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let r=(c=t.cs)!=null?c:!1,o=r?i!=null?i:"":ht(i),n=r?t.rhs:ht(t.rhs);switch(e){case"=":return o===n;case"!=":return o!==n;case"~":return(d=o.includes(n))!=null?d:!1;case"!~":return!((f=o.includes(n))!=null?f:!0);case"//":return new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");case"!//":return!new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");default:throw new Error(`Unknown match type ${e}.`)}}function ht(i){var t;return(t=i==null?void 0:i.toUpperCase())!=null?t:""}var K=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});import Ot from"mitt";import{dequal as Ut}from"dequal/lite";var It="__UNIFORM_DATA__",T,q,j=class{constructor({initialData:t}){u(this,T,void 0);u(this,q,Ot());y(this,"events",{on:s(this,q).on,off:s(this,q).off});t&&m(this,T,t)}get data(){return s(this,T)}updateData(t,e){return m(this,T,e),this.handleUpdateData(t,e)}async delete(t){m(this,T,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){Ut(this.data,t)||(m(this,T,t),s(this,q).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(It);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};T=new WeakMap,q=new WeakMap;import{ntob as Rt,bton as qt}from"number-to-base64";var St=typeof window=="undefined",O,U,Lt=class extends j{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:St?zt(t.get(e)):void 0});u(this,O,void 0);u(this,U,void 0);m(this,O,e),m(this,U,t)}handleDelete(){return s(this,U).remove(s(this,O)),Promise.resolve()}async handleUpdateData(t,e){St||(e.consent?s(this,U).set(s(this,O),At(e)):s(this,U).remove(s(this,O)))}};O=new WeakMap,U=new WeakMap;var yt="~",vt="!",Dt="-";function zt(i){if(!i)return;let t=i.split(yt);if(t.length>3)return;let[e,r,o]=t;return{consent:!0,sessionScores:Vt(tt(r)),scores:Vt(tt(o)),tests:tt(e)}}function tt(i){return i.split(vt).map(e=>e.split(Dt)).reduce((e,r)=>(r.length!==2||(e[r[0]]=r[1]),e),{})}function Vt(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=qt(r),t),{})}function At(i){return[et(i.tests),et(Ct(i.sessionScores)),et(Ct(i.scores))].join(yt)}function Ct(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=Rt(r),t),{})}function et(i){return Object.entries(i).map(t=>t.join(Dt)).join(vt)}var J,Nt,$t=class extends j{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...r}){super(r);u(this,J);r.initialData||h(this,J,Nt).call(this).catch(o=>{console.error(o)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(r=>{setTimeout(()=>{r(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};J=new WeakSet,Nt=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};function Ae(i){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:r=.95}=i!=null?i:{};return function({now:n,lastUpd:a,scores:c,sessionScores:d}){if(typeof a!="number")return!1;let M=n-a-t;if(M<=0)return!1;let Q=M/864e5,W=1-Math.min(r,Q*e);return W<=0?!1:(xt(c,W),xt(d,W),!0)}}function xt(i,t){for(let e in i)i[e]*=t}import _t from"mitt";import{dequal as it}from"dequal/lite";var rt=class{constructor(){y(this,"inMemoryFallback",{});y(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let r=localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(r){return e}}set(t,e,r){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!r))try{localStorage.setItem(t,JSON.stringify(e))}catch(o){console.warn(o)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(r){}}};import Gt from"rfdc";var jt=Gt();function kt(i,t,e){let r=t?jt(t):K();return i.forEach(o=>{var n,a;switch(o.type){case"consent":r.consent=o.data;break;case"setquirk":r.quirks[o.data.key]=o.data.value;break;case"settest":r.tests[o.data.test]=o.data.variant;break;case"modscore":if(e)break;let c=(n=r.scores[o.data.dimension])!=null?n:0;r.scores[o.data.dimension]=c+o.data.delta;break;case"modscoreS":if(e)break;let d=(a=r.sessionScores[o.data.dimension])!=null?a:0;r.sessionScores[o.data.dimension]=d+o.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),r}var B="ufvisitor",v,I,z,S,D,w,b,L,Y,Ft,H,Qt,_,bt,F,Et,ot=class{constructor(t){u(this,D);u(this,b);u(this,Y);u(this,H);u(this,_);u(this,F);u(this,v,_t());u(this,I,new rt);u(this,z,void 0);u(this,S,void 0);y(this,"events",{on:s(this,v).on,off:s(this,v).off});if(m(this,S,t),s(this,D,w)||h(this,b,L).call(this,h(this,F,Et).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();e&&e.quirks&&this.updateData(Object.entries(e.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.transitionStore.events.on("dataUpdatedAsync",o=>{h(this,b,L).call(this,{...s(this,D,w).visitorData,...o})});let r=t.transitionStore.data;r&&h(this,b,L).call(this,{...s(this,D,w).visitorData,...r},!0)}}get data(){let t=s(this,D,w);if(h(this,H,Qt).call(this,t)){let{sessionScores:e,...r}=t.visitorData;return h(this,b,L).call(this,{...r,sessionScores:{}}),s(this,v).emit("log",["info",120]),s(this,D,w).visitorData}return t.visitorData}async updateData(t){var r,o;if(t.length===0)return;s(this,v).emit("log",["debug",101,t]);let e=kt(t,this.data,(r=s(this,D,w))==null?void 0:r.visitorData.controlGroup);t.some(n=>n.type==="consent"&&!n.data)&&s(this,I).delete(B,!0),h(this,b,L).call(this,e),await((o=s(this,S).transitionStore)==null?void 0:o.updateData(t,s(this,D,w).visitorData))}async delete(t){var e;s(this,I).delete(B,!1),await((e=s(this,S).transitionStore)==null?void 0:e.delete(t)),s(this,v).emit("log",["info",103,t]),h(this,b,L).call(this,h(this,F,Et).call(this))}};v=new WeakMap,I=new WeakMap,z=new WeakMap,S=new WeakMap,D=new WeakSet,w=function(){return s(this,I).get(B)},b=new WeakSet,L=function(t,e=!1){var f,M;let r=s(this,D,w),o=Date.now();h(this,_,bt).call(this,t.scores),h(this,_,bt).call(this,t.sessionScores),(M=(f=s(this,S)).decay)==null||M.call(f,{now:o,lastUpd:r==null?void 0:r.updated,scores:t.scores,sessionScores:t.sessionScores});let n=!it(r==null?void 0:r.visitorData.scores,t.scores),a=!it(r==null?void 0:r.visitorData.sessionScores,t.sessionScores),c=!it(r==null?void 0:r.visitorData.quirks,t.quirks),d={updated:o,visitorData:t};h(this,Y,Ft).call(this),s(this,I).set(B,d,!!t.consent),s(this,v).emit("log",["debug",102,t]),e||((n||a)&&s(this,v).emit("scoresUpdated",t),c&&s(this,v).emit("quirksUpdated",t))},Y=new WeakSet,Ft=function(){typeof window=="undefined"||!s(this,S).visitLifespan||(s(this,z)&&window.clearTimeout(s(this,z)),m(this,z,window.setTimeout(()=>{this.data},s(this,S).visitLifespan+50)))},H=new WeakSet,Qt=function(t){let e=s(this,S).visitLifespan;return e?t.updated+e<Date.now():!1},_=new WeakSet,bt=function(t){if(!!s(this,S).manifest)for(let e in t){let r=t[e],o=s(this,S).manifest.getDimensionByKey(e);!o||r>o.cap&&(s(this,v).emit("log",["debug",110,{dim:e,score:r,cap:o.cap}]),t[e]=o.cap)}},F=new WeakSet,Et=function(){var t,e,r;return{...K(),consent:(t=s(this,S).defaultConsent)!=null?t:!1,controlGroup:(r=(e=s(this,S).manifest)==null?void 0:e.rollForControlGroup())!=null?r:!1}};import Jt from"mitt";function Tt({context:i,variations:t,take:e=1}){var c;let r=(c=i.storage.data.controlGroup)!=null?c:!1,o=[],n=!1,a=i.scores;for(let d of t){if(o.length===e)break;if(!d.pz){o.push(d);continue}!r&&wt(d.pz,a)&&(n=!0,o.push(d))}return{personalized:n,variations:o}}function wt(i,t){return!i.op||i.op==="&"?i.crit.every(e=>Pt(e,t)):i.crit.some(e=>Pt(e,t))}function Pt(i,t){var a;let{op:e,l:r}=i,o=(a=t[r])!=null?a:0;if(e==="+")return Math.max(...Object.values(t))===o&&o>0;if(e==="-")return Math.min(...Object.values(t))===o&&o>0;let n=i.rDim?t[i.rDim]:i.r;if(n===void 0)return!1;if(e===">")return o>n;if(e===">=")return o>=n;if(e==="<")return o<n;if(e==="<=")return o<=n;if(e==="=")return o===n;if(e==="!=")return o!==n;throw new Error(`Unknown op: ${e}`)}var Kt=i=>{let{values:t,total:e,missingDistribution:r}=i.reduce((o,n)=>(n.testDistribution?o.total+=n.testDistribution:++o.missingDistribution,o.values.push(n.testDistribution),o),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let n=(100-e)/r;t.forEach((a,c)=>{typeof a=="undefined"&&(t[c]=n)})}return t},st=({name:i,context:t,variations:e})=>{var n;let r,o=t.getTestVariantId(i);if(o===null)return{result:void 0};if(o&&(r=e.find(a=>a.id===o),r||t.log("warn",401,{test:i,variant:o})),!r){let a=Kt(e),c=Math.floor(Math.random()*100),d=0;r=e.find((f,M)=>{let Q=a[M];if(c>d&&c<=d+Q)return f;d+=Q}),r&&t.setTestVariantId(i,(n=r.id)!=null?n:"Unknown")}return{result:r}};var E,P,V,g,Bt=class{constructor(t){u(this,E,void 0);u(this,P,{});u(this,V,void 0);u(this,g,Jt());y(this,"events",{on:s(this,g).on,off:s(this,g).off});y(this,"storage");let{manifest:e,...r}=t;m(this,V,{}),m(this,E,new R({manifest:e,evaluator:new N({CK:ut,QS:pt,QK:mt,PVC:lt,EVT:ft,PV:gt})})),this.storage=new ot({manifest:s(this,E),...r}),this.storage.events.on("log",(...n)=>s(this,g).emit("log",...n));let o=n=>{var c;let a={...n.scores};for(let d in n.sessionScores)a[d]=((c=a[d])!=null?c:0)+n.sessionScores[d];a=s(this,E).computeAggregateDimensions(a),m(this,P,a),s(this,g).emit("scoresUpdated",a),s(this,g).emit("log",["info",3,a])};this.storage.events.on("scoresUpdated",o),o(this.storage.data),this.storage.events.on("quirksUpdated",n=>{let a=s(this,E).computeSignals({scores:s(this,P),state:s(this,V),previousState:s(this,V),visitor:this.storage.data});this.storage.updateData(a),s(this,g).emit("quirksUpdated",n.quirks),s(this,g).emit("log",["info",4,n.quirks])}),s(this,g).emit("log",["debug",1,{options:t,scores:s(this,P)}])}get scores(){return s(this,P)}async update(t){let e=[];s(this,g).emit("log",["info",2,t]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(o=>({type:"modscore",data:{dimension:R.getEnrichmentVectorKey(o.cat,o.key),delta:o.str}}))),t.enrichments=void 0);let r=s(this,V);m(this,V,{...s(this,V),...t}),e.push(...s(this,E).computeSignals({state:s(this,V),previousState:r,visitor:this.storage.data,scores:s(this,P)})),await this.storage.updateData(e)}getTestVariantId(t){var r;let e=s(this,E).getTest(t);return e?(r=e.wv)!=null?r:this.storage.data.tests[t]:(s(this,g).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){s(this,g).emit("log",t)}test(t){var r;let e=st({...t,context:this});return s(this,g).emit("testResult",{name:t.name,variantId:(r=e.result)==null?void 0:r.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=Tt({...t,context:this});return t.name?s(this,g).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(r=>{var o;return(o=r.id)!=null?o:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){m(this,V,{}),await this.storage.delete(t)}};E=new WeakMap,P=new WeakMap,V=new WeakMap,g=new WeakMap;var Dr=([i,t,...e])=>{console[i](`\u{1F94B} [${i}] Uniform event ID ${t}
|
2
|
+
`,...e.map(r=>JSON.stringify(r,null,2)))};var Mt={1:({options:i,scores:t})=>["tracker","constructed",i,t],2:i=>["tracker","received data update",i],3:i=>["tracker","new score vector",i],4:i=>["tracker","updated quirks",i],101:i=>["storage","received update commands",i],102:i=>["storage","data was updated",i],103:i=>["storage",`data was deleted ${i?"from all devices":"from this device"}`],110:({dim:i,cap:t,score:e})=>["storage",`${i} score ${e} exceeded cap ${t}. Rounded down.`],120:()=>["storage","visitor data expired and was cleared"],301:()=>["placement","Missing `name` field on personalization. Analytics events will not be triggered."],401:i=>["testing",`${i} was unknown; it will not be run.`],402:({test:i,variant:t})=>["testing",`${i} no longer has visitor's variant ${t}; it will be removed.`],700:()=>["gtag","gtag is not defined, skipping analytics event emission. Ensure you have added the gtag script to your page."],701:()=>["gtag","enabled gtag event signal redirection"]};var kr=([i,t,...e])=>{let r=Mt[t],o=`\u{1F94B} [${new Date().toLocaleTimeString()}][${i}]`;r||console[i](`${o} unknown message ID ${t} - ensure all Uniform packages are the same version`,...e);let[n,a,...c]=r(...e);console[i](`${o}[${n}] ${a} (Event ID: ${t})
|
3
|
+
`,...c.map(d=>JSON.stringify(d,null,2)))};var Yt=(c=>(c.ListStart="nesi-list-start",c.ListEnd="nesi-list-end",c.ListItem="nesi-list-item-html",c.ListItemSettings="nesi-list-item-settings",c.TestStart="nesi-test-start",c.TestEnd="nesi-test-end",c.Unknown="unknown",c))(Yt||{}),Er="nesitag";export{Bt as Context,Lt as CookieTransitionDataStore,Er as EdgeNodeTagName,$t as EdgeTransitionDataStore,N as GroupCriteriaEvaluator,R as ManifestInstance,It as SERVER_STATE_ID,Yt as ScriptType,j as TransitionDataStore,ot as VisitorDataStore,nt as computeAggregateDimensions,Dr as consoleLogDrain,ut as cookieEvaluator,Ae as createLinearDecay,kr as debugConsoleLogDrain,K as emptyVisitorData,wt as evaluateVariantMatch,ft as eventEvaluator,x as isStringMatch,Z as pageViewCountDimension,lt as pageViewCountEvaluator,gt as pageVisitedEvaluator,Tt as personalizeVariations,pt as queryStringEvaluator,mt as quirkEvaluator,st as testVariations};
|
package/dist/index.mjs
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import{d as v,e as s,f as d,g as f,h as S,i as a}from"./chunk-POAQ5JTB.mjs";a();a();a();function at(i,t){let e={...i};for(let r in t){let o=ct(i,r,t,new Set([r]));o!==0&&(e[r]=o)}return e}function ct(i,t,e,r){var n;let o=0;for(let c of e[t].inputs){let u=(n=i[c.dim])!=null?n:0;if(!u&&e[c.dim]){if(r.has(c.dim))continue;let g=new Set(r);g.add(c.dim),u=ct(i,c.dim,e,g)}if(u!==0)if(c.sign==="c"){o=0;break}else c.sign==="-"?o-=u:o+=u}return o}a();var $,b,Z=class{constructor(t,e,r){d(this,$,void 0);d(this,b,void 0);v(this,"signal");f(this,b,t),this.signal=e,f(this,$,r)}computeSignals(t,e){if(t.scores[s(this,b)]>=this.signal.cap&&this.signal.dur!=="t")return;let o=s(this,$).evaluate(t,this.signal.crit,e,this.signal,s(this,b)),n=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(o)e.push({type:n,data:{dimension:s(this,b),delta:this.signal.str}});else if(this.signal.dur==="t"){let c=t.visitor.sessionScores[s(this,b)];c&&e.push({type:n,data:{dimension:s(this,b),delta:-c}})}}};$=new WeakMap,b=new WeakMap;var ut="_",x,N,q=class{constructor({manifest:t,evaluator:e=new G({})}){d(this,x,void 0);d(this,N,void 0);var r,o,n;f(this,x,(r=t.project)!=null?r:{}),f(this,N,Object.entries((n=(o=s(this,x).pz)==null?void 0:o.sig)!=null?n:[]).map(([c,u])=>new Z(c,u,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=s(this,x).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=s(this,x).test)==null?void 0:e[t]}computeSignals(t){let e=[];return s(this,N).forEach(r=>{r.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,r;return at(t,(r=(e=s(this,x).pz)==null?void 0:e.agg)!=null?r:{})}getDimensionByKey(t){var r,o,n,c;let e=t.indexOf(ut);return e<=0?(o=(r=s(this,x).pz)==null?void 0:r.sig)==null?void 0:o[t]:(c=(n=s(this,x).pz)==null?void 0:n.enr)==null?void 0:c[t.substring(0,e)]}static getEnrichmentVectorKey(t,e){return`${t}${ut}${e}`}};x=new WeakMap,N=new WeakMap;a();var dt=(i,t)=>{var o;if(t.type!=="CK")return!1;let e=(o=i.state.cookies)==null?void 0:o[t.cookieName];return k(e,t.match)};a();a();function lt(i,t){var r;if(typeof i=="undefined"||i===null)return!1;let e=Number(i);if(isNaN(e))return!1;switch((r=t==null?void 0:t.op)!=null?r:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}var tt=q.getEnrichmentVectorKey("$pvc","v"),pt=(i,t,e)=>{var c,u;if(t.type!=="PVC")return!1;let r=!i.previousState||((c=i.state.url)==null?void 0:c.toString())!==((u=i.previousState.url)==null?void 0:u.toString()),n=(i.visitor.sessionScores[tt]||0)+1;if(lt(n,t.match)){let l=e.some(g=>g.type==="modscoreS"&&g.data.dimension===tt);return r&&!l&&e.push({type:"modscoreS",data:{dimension:tt,delta:1}}),!0}return!1};a();var mt=(i,t)=>{var r;if(t.type!=="QS")return!1;let e=(r=i.state.url)==null?void 0:r.searchParams.get(t.queryName);return k(e,t.match)};a();var ft=(i,t,e,r,o)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&r.dur==="t"&&i.scores[o]>0)return!0;let n=i.visitor.quirks[t.key];return k(n,t.match)};a();var gt=(i,t)=>{var e,r;return t.type!=="EVT"?!1:(r=(e=i.state.events)==null?void 0:e.some(o=>k(o.event,t.event)))!=null?r:!1};a();var ht=(i,t)=>{var e;return t.type!=="PV"?!1:k((e=i.state.url)==null?void 0:e.pathname,t.path)};a();var j,G=class{constructor(t){d(this,j,void 0);f(this,j,t)}evaluate(t,e,r,o,n){let c=!(e.op==="&"||!e.op);for(let u of e.clauses){let l;if(u.type==="G")l=this.evaluate(t,u,r,o,n);else{let g=s(this,j)[u.type];if(!g)throw new Error(`${u.type} signal criteria not registered`);l=g(t,u,r,o,n)}if(l===c)return c}return!c}};j=new WeakMap;a();function k(i,t){var c,u,l,g;let e=(c=t==null?void 0:t.op)!=null?c:"=";if(t.op==="*")return i!==null&&typeof i!="undefined";if(t.op==="!*")return i===null||typeof i=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let r=(u=t.cs)!=null?u:!1,o=r?i!=null?i:"":St(i),n=r?t.rhs:St(t.rhs);switch(e){case"=":return o===n;case"!=":return o!==n;case"~":return(l=o.includes(n))!=null?l:!1;case"!~":return!((g=o.includes(n))!=null?g:!0);case"//":return new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");case"!//":return!new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");default:throw new Error(`Unknown match type ${e}.`)}}function St(i){var t;return(t=i==null?void 0:i.toUpperCase())!=null?t:""}a();var J=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});a();a();import Ut from"mitt";import{dequal as It}from"dequal/lite";var Rt="__UNIFORM_DATA__",w,L,_=class{constructor({initialData:t}){d(this,w,void 0);d(this,L,Ut());v(this,"events",{on:s(this,L).on,off:s(this,L).off});t&&f(this,w,t)}get data(){return s(this,w)}updateData(t,e){return f(this,w,e),this.handleUpdateData(t,e)}async delete(t){f(this,w,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){It(this.data,t)||(f(this,w,t),s(this,L).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(Rt);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};w=new WeakMap,L=new WeakMap;import{ntob as qt,bton as Lt}from"number-to-base64";var yt=typeof window=="undefined",U,I,zt=class extends _{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:yt?At(t.get(e)):void 0});d(this,U,void 0);d(this,I,void 0);f(this,U,e),f(this,I,t)}handleDelete(){return s(this,I).remove(s(this,U)),Promise.resolve()}async handleUpdateData(t,e){yt||(e.consent?s(this,I).set(s(this,U),$t(e)):s(this,I).remove(s(this,U)))}};U=new WeakMap,I=new WeakMap;var vt="~",Dt="!",Vt="-";function At(i){if(!i)return;let t=i.split(vt);if(t.length>3)return;let[e,r,o]=t;return{consent:!0,sessionScores:Ct(et(r)),scores:Ct(et(o)),tests:et(e)}}function et(i){return i.split(Dt).map(e=>e.split(Vt)).reduce((e,r)=>(r.length!==2||(e[r[0]]=r[1]),e),{})}function Ct(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=Lt(r),t),{})}function $t(i){return[rt(i.tests),rt(xt(i.sessionScores)),rt(xt(i.scores))].join(vt)}function xt(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=qt(r),t),{})}function rt(i){return Object.entries(i).map(t=>t.join(Vt)).join(Dt)}a();var B,Gt,Nt=class extends _{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...r}){super(r);d(this,B);r.initialData||S(this,B,Gt).call(this).catch(o=>{console.error(o)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(r=>{setTimeout(()=>{r(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};B=new WeakSet,Gt=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};a();function $e(i){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:r=.95}=i!=null?i:{};return function({now:n,lastUpd:c,scores:u,sessionScores:l}){if(typeof c!="number")return!1;let O=n-c-t;if(O<=0)return!1;let K=O/864e5,X=1-Math.min(r,K*e);return X<=0?!1:(kt(u,X),kt(l,X),!0)}}function kt(i,t){for(let e in i)i[e]*=t}a();import Ft from"mitt";import{dequal as ot}from"dequal/lite";a();var it=class{constructor(){v(this,"inMemoryFallback",{});v(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let r=localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(r){return e}}set(t,e,r){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!r))try{localStorage.setItem(t,JSON.stringify(e))}catch(o){console.warn(o)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(r){}}};a();import jt from"rfdc";var _t=jt();function bt(i,t,e){let r=t?_t(t):J();return i.forEach(o=>{var n,c;switch(o.type){case"consent":r.consent=o.data;break;case"setquirk":r.quirks[o.data.key]=o.data.value;break;case"settest":r.tests[o.data.test]=o.data.variant;break;case"modscore":if(e)break;let u=(n=r.scores[o.data.dimension])!=null?n:0;r.scores[o.data.dimension]=u+o.data.delta;break;case"modscoreS":if(e)break;let l=(c=r.sessionScores[o.data.dimension])!=null?c:0;r.sessionScores[o.data.dimension]=l+o.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),r}var Y="ufvisitor",D,R,A,y,V,P,E,z,H,Qt,W,Kt,F,Et,Q,Tt,st=class{constructor(t){d(this,V);d(this,E);d(this,H);d(this,W);d(this,F);d(this,Q);d(this,D,Ft());d(this,R,new it);d(this,A,void 0);d(this,y,void 0);v(this,"events",{on:s(this,D).on,off:s(this,D).off});if(f(this,y,t),s(this,V,P)||S(this,E,z).call(this,S(this,Q,Tt).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();e&&e.quirks&&this.updateData(Object.entries(e.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.transitionStore.events.on("dataUpdatedAsync",o=>{S(this,E,z).call(this,{...s(this,V,P).visitorData,...o})});let r=t.transitionStore.data;r&&S(this,E,z).call(this,{...s(this,V,P).visitorData,...r},!0)}}get data(){let t=s(this,V,P);if(S(this,W,Kt).call(this,t)){let{sessionScores:e,...r}=t.visitorData;return S(this,E,z).call(this,{...r,sessionScores:{}}),s(this,D).emit("log",["info",120]),s(this,V,P).visitorData}return t.visitorData}async updateData(t){var r,o;if(t.length===0)return;s(this,D).emit("log",["debug",101,t]);let e=bt(t,this.data,(r=s(this,V,P))==null?void 0:r.visitorData.controlGroup);t.some(n=>n.type==="consent"&&!n.data)&&s(this,R).delete(Y,!0),S(this,E,z).call(this,e),await((o=s(this,y).transitionStore)==null?void 0:o.updateData(t,s(this,V,P).visitorData))}async delete(t){var e;s(this,R).delete(Y,!1),await((e=s(this,y).transitionStore)==null?void 0:e.delete(t)),s(this,D).emit("log",["info",103,t]),S(this,E,z).call(this,S(this,Q,Tt).call(this))}};D=new WeakMap,R=new WeakMap,A=new WeakMap,y=new WeakMap,V=new WeakSet,P=function(){return s(this,R).get(Y)},E=new WeakSet,z=function(t,e=!1){var g,O;let r=s(this,V,P),o=Date.now();S(this,F,Et).call(this,t.scores),S(this,F,Et).call(this,t.sessionScores),(O=(g=s(this,y)).decay)==null||O.call(g,{now:o,lastUpd:r==null?void 0:r.updated,scores:t.scores,sessionScores:t.sessionScores});let n=!ot(r==null?void 0:r.visitorData.scores,t.scores),c=!ot(r==null?void 0:r.visitorData.sessionScores,t.sessionScores),u=!ot(r==null?void 0:r.visitorData.quirks,t.quirks),l={updated:o,visitorData:t};S(this,H,Qt).call(this),s(this,R).set(Y,l,!!t.consent),s(this,D).emit("log",["debug",102,t]),e||((n||c)&&s(this,D).emit("scoresUpdated",t),u&&s(this,D).emit("quirksUpdated",t))},H=new WeakSet,Qt=function(){typeof window=="undefined"||!s(this,y).visitLifespan||(s(this,A)&&window.clearTimeout(s(this,A)),f(this,A,window.setTimeout(()=>{this.data},s(this,y).visitLifespan+50)))},W=new WeakSet,Kt=function(t){let e=s(this,y).visitLifespan;return e?t.updated+e<Date.now():!1},F=new WeakSet,Et=function(t){if(!!s(this,y).manifest)for(let e in t){let r=t[e],o=s(this,y).manifest.getDimensionByKey(e);!o||r>o.cap&&(s(this,D).emit("log",["debug",110,{dim:e,score:r,cap:o.cap}]),t[e]=o.cap)}},Q=new WeakSet,Tt=function(){var t,e,r;return{...J(),consent:(t=s(this,y).defaultConsent)!=null?t:!1,controlGroup:(r=(e=s(this,y).manifest)==null?void 0:e.rollForControlGroup())!=null?r:!1}};a();import Bt from"mitt";a();a();function wt({context:i,variations:t,take:e=1}){var u;let r=(u=i.storage.data.controlGroup)!=null?u:!1,o=[],n=!1,c=i.scores;for(let l of t){if(o.length===e)break;if(!l.pz){o.push(l);continue}!r&&Pt(l.pz,c)&&(n=!0,o.push(l))}return{personalized:n,variations:o}}a();function Pt(i,t){return!i.op||i.op==="&"?i.crit.every(e=>Mt(e,t)):i.crit.some(e=>Mt(e,t))}function Mt(i,t){var c;let{op:e,l:r}=i,o=(c=t[r])!=null?c:0;if(e==="+")return Math.max(...Object.values(t))===o&&o>0;if(e==="-")return Math.min(...Object.values(t))===o&&o>0;let n=i.rDim?t[i.rDim]:i.r;if(n===void 0)return!1;if(e===">")return o>n;if(e===">=")return o>=n;if(e==="<")return o<n;if(e==="<=")return o<=n;if(e==="=")return o===n;if(e==="!=")return o!==n;throw new Error(`Unknown op: ${e}`)}a();var Jt=i=>{let{values:t,total:e,missingDistribution:r}=i.reduce((o,n)=>(n.testDistribution?o.total+=n.testDistribution:++o.missingDistribution,o.values.push(n.testDistribution),o),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let n=(100-e)/r;t.forEach((c,u)=>{typeof c=="undefined"&&(t[u]=n)})}return t},nt=({name:i,context:t,variations:e})=>{var n;let r,o=t.getTestVariantId(i);if(o===null)return{result:void 0};if(o&&(r=e.find(c=>c.id===o),r||t.log("warn",401,{test:i,variant:o})),!r){let c=Jt(e),u=Math.floor(Math.random()*100),l=0;r=e.find((g,O)=>{let K=c[O];if(u>l&&u<=l+K)return g;l+=K}),r&&t.setTestVariantId(i,(n=r.id)!=null?n:"Unknown")}return{result:r}};var T,M,C,h,Yt=class{constructor(t){d(this,T,void 0);d(this,M,{});d(this,C,void 0);d(this,h,Bt());v(this,"events",{on:s(this,h).on,off:s(this,h).off});v(this,"storage");let{manifest:e,...r}=t;f(this,C,{}),f(this,T,new q({manifest:e,evaluator:new G({CK:dt,QS:mt,QK:ft,PVC:pt,EVT:gt,PV:ht})})),this.storage=new st({manifest:s(this,T),...r}),this.storage.events.on("log",(...n)=>s(this,h).emit("log",...n));let o=n=>{var u;let c={...n.scores};for(let l in n.sessionScores)c[l]=((u=c[l])!=null?u:0)+n.sessionScores[l];c=s(this,T).computeAggregateDimensions(c),f(this,M,c),s(this,h).emit("scoresUpdated",c),s(this,h).emit("log",["info",3,c])};this.storage.events.on("scoresUpdated",o),o(this.storage.data),this.storage.events.on("quirksUpdated",n=>{let c=s(this,T).computeSignals({scores:s(this,M),state:s(this,C),previousState:s(this,C),visitor:this.storage.data});this.storage.updateData(c),s(this,h).emit("quirksUpdated",n.quirks),s(this,h).emit("log",["info",4,n.quirks])}),s(this,h).emit("log",["debug",1,{options:t,scores:s(this,M)}])}get scores(){return s(this,M)}async update(t){let e=[];s(this,h).emit("log",["info",2,t]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(o=>({type:"modscore",data:{dimension:q.getEnrichmentVectorKey(o.cat,o.key),delta:o.str}}))),t.enrichments=void 0);let r=s(this,C);f(this,C,{...s(this,C),...t}),e.push(...s(this,T).computeSignals({state:s(this,C),previousState:r,visitor:this.storage.data,scores:s(this,M)})),await this.storage.updateData(e)}getTestVariantId(t){var r;let e=s(this,T).getTest(t);return e?(r=e.wv)!=null?r:this.storage.data.tests[t]:(s(this,h).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){s(this,h).emit("log",t)}test(t){var r;let e=nt({...t,context:this});return s(this,h).emit("testResult",{name:t.name,variantId:(r=e.result)==null?void 0:r.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=wt({...t,context:this});return t.name?s(this,h).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(r=>{var o;return(o=r.id)!=null?o:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){f(this,C,{}),await this.storage.delete(t)}};T=new WeakMap,M=new WeakMap,C=new WeakMap,h=new WeakMap;a();var Vr=([i,t,...e])=>{console[i](`\u{1F94B} [${i}] Uniform event ID ${t}
|
2
|
-
`,...e.map(r=>JSON.stringify(r,null,2)))};
|
3
|
-
`,...
|
1
|
+
import{b as y,c as s,d as u,e as m,f as h}from"./chunk-TRWANXVF.mjs";function nt(i,t){let e={...i};for(let r in t){let o=at(i,r,t,new Set([r]));o!==0&&(e[r]=o)}return e}function at(i,t,e,r){var n;let o=0;for(let a of e[t].inputs){let c=(n=i[a.dim])!=null?n:0;if(!c&&e[a.dim]){if(r.has(a.dim))continue;let f=new Set(r);f.add(a.dim),c=at(i,a.dim,e,f)}if(c!==0)if(a.sign==="c"){o=0;break}else a.sign==="-"?o-=c:o+=c}return o}var A,k,X=class{constructor(t,e,r){u(this,A,void 0);u(this,k,void 0);y(this,"signal");m(this,k,t),this.signal=e,m(this,A,r)}computeSignals(t,e){if(t.scores[s(this,k)]>=this.signal.cap&&this.signal.dur!=="t")return;let o=s(this,A).evaluate(t,this.signal.crit,e,this.signal,s(this,k)),n=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(o)e.push({type:n,data:{dimension:s(this,k),delta:this.signal.str}});else if(this.signal.dur==="t"){let a=t.visitor.sessionScores[s(this,k)];a&&e.push({type:n,data:{dimension:s(this,k),delta:-a}})}}};A=new WeakMap,k=new WeakMap;var ct="_",C,$,R=class{constructor({manifest:t,evaluator:e=new N({})}){u(this,C,void 0);u(this,$,void 0);var r,o,n;m(this,C,(r=t.project)!=null?r:{}),m(this,$,Object.entries((n=(o=s(this,C).pz)==null?void 0:o.sig)!=null?n:[]).map(([a,c])=>new X(a,c,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=s(this,C).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=s(this,C).test)==null?void 0:e[t]}computeSignals(t){let e=[];return s(this,$).forEach(r=>{r.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,r;return nt(t,(r=(e=s(this,C).pz)==null?void 0:e.agg)!=null?r:{})}getDimensionByKey(t){var r,o,n,a;let e=t.indexOf(ct);return e<=0?(o=(r=s(this,C).pz)==null?void 0:r.sig)==null?void 0:o[t]:(a=(n=s(this,C).pz)==null?void 0:n.enr)==null?void 0:a[t.substring(0,e)]}static getEnrichmentVectorKey(t,e){return`${t}${ct}${e}`}};C=new WeakMap,$=new WeakMap;var ut=(i,t)=>{var o;if(t.type!=="CK")return!1;let e=(o=i.state.cookies)==null?void 0:o[t.cookieName];return x(e,t.match)};function dt(i,t){var r;if(typeof i=="undefined"||i===null)return!1;let e=Number(i);if(isNaN(e))return!1;switch((r=t==null?void 0:t.op)!=null?r:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}var Z=R.getEnrichmentVectorKey("$pvc","v"),lt=(i,t,e)=>{var a,c;if(t.type!=="PVC")return!1;let r=!i.previousState||((a=i.state.url)==null?void 0:a.toString())!==((c=i.previousState.url)==null?void 0:c.toString()),n=(i.visitor.sessionScores[Z]||0)+1;if(dt(n,t.match)){let d=e.some(f=>f.type==="modscoreS"&&f.data.dimension===Z);return r&&!d&&e.push({type:"modscoreS",data:{dimension:Z,delta:1}}),!0}return!1};var pt=(i,t)=>{var r;if(t.type!=="QS")return!1;let e=(r=i.state.url)==null?void 0:r.searchParams.get(t.queryName);return x(e,t.match)};var mt=(i,t,e,r,o)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&r.dur==="t"&&i.scores[o]>0)return!0;let n=i.visitor.quirks[t.key];return x(n,t.match)};var ft=(i,t)=>{var e,r;return t.type!=="EVT"?!1:(r=(e=i.state.events)==null?void 0:e.some(o=>x(o.event,t.event)))!=null?r:!1};var gt=(i,t)=>{var e;return t.type!=="PV"?!1:x((e=i.state.url)==null?void 0:e.pathname,t.path)};var G,N=class{constructor(t){u(this,G,void 0);m(this,G,t)}evaluate(t,e,r,o,n){let a=!(e.op==="&"||!e.op);for(let c of e.clauses){let d;if(c.type==="G")d=this.evaluate(t,c,r,o,n);else{let f=s(this,G)[c.type];if(!f)throw new Error(`${c.type} signal criteria not registered`);d=f(t,c,r,o,n)}if(d===a)return a}return!a}};G=new WeakMap;function x(i,t){var a,c,d,f;let e=(a=t==null?void 0:t.op)!=null?a:"=";if(t.op==="*")return i!==null&&typeof i!="undefined";if(t.op==="!*")return i===null||typeof i=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let r=(c=t.cs)!=null?c:!1,o=r?i!=null?i:"":ht(i),n=r?t.rhs:ht(t.rhs);switch(e){case"=":return o===n;case"!=":return o!==n;case"~":return(d=o.includes(n))!=null?d:!1;case"!~":return!((f=o.includes(n))!=null?f:!0);case"//":return new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");case"!//":return!new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");default:throw new Error(`Unknown match type ${e}.`)}}function ht(i){var t;return(t=i==null?void 0:i.toUpperCase())!=null?t:""}var K=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});import Ot from"mitt";import{dequal as Ut}from"dequal/lite";var It="__UNIFORM_DATA__",T,q,j=class{constructor({initialData:t}){u(this,T,void 0);u(this,q,Ot());y(this,"events",{on:s(this,q).on,off:s(this,q).off});t&&m(this,T,t)}get data(){return s(this,T)}updateData(t,e){return m(this,T,e),this.handleUpdateData(t,e)}async delete(t){m(this,T,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){Ut(this.data,t)||(m(this,T,t),s(this,q).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(It);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};T=new WeakMap,q=new WeakMap;import{ntob as Rt,bton as qt}from"number-to-base64";var St=typeof window=="undefined",O,U,Lt=class extends j{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:St?zt(t.get(e)):void 0});u(this,O,void 0);u(this,U,void 0);m(this,O,e),m(this,U,t)}handleDelete(){return s(this,U).remove(s(this,O)),Promise.resolve()}async handleUpdateData(t,e){St||(e.consent?s(this,U).set(s(this,O),At(e)):s(this,U).remove(s(this,O)))}};O=new WeakMap,U=new WeakMap;var yt="~",vt="!",Dt="-";function zt(i){if(!i)return;let t=i.split(yt);if(t.length>3)return;let[e,r,o]=t;return{consent:!0,sessionScores:Vt(tt(r)),scores:Vt(tt(o)),tests:tt(e)}}function tt(i){return i.split(vt).map(e=>e.split(Dt)).reduce((e,r)=>(r.length!==2||(e[r[0]]=r[1]),e),{})}function Vt(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=qt(r),t),{})}function At(i){return[et(i.tests),et(Ct(i.sessionScores)),et(Ct(i.scores))].join(yt)}function Ct(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=Rt(r),t),{})}function et(i){return Object.entries(i).map(t=>t.join(Dt)).join(vt)}var J,Nt,$t=class extends j{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...r}){super(r);u(this,J);r.initialData||h(this,J,Nt).call(this).catch(o=>{console.error(o)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(r=>{setTimeout(()=>{r(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};J=new WeakSet,Nt=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};function Ae(i){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:r=.95}=i!=null?i:{};return function({now:n,lastUpd:a,scores:c,sessionScores:d}){if(typeof a!="number")return!1;let M=n-a-t;if(M<=0)return!1;let Q=M/864e5,W=1-Math.min(r,Q*e);return W<=0?!1:(xt(c,W),xt(d,W),!0)}}function xt(i,t){for(let e in i)i[e]*=t}import _t from"mitt";import{dequal as it}from"dequal/lite";var rt=class{constructor(){y(this,"inMemoryFallback",{});y(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let r=localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(r){return e}}set(t,e,r){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!r))try{localStorage.setItem(t,JSON.stringify(e))}catch(o){console.warn(o)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(r){}}};import Gt from"rfdc";var jt=Gt();function kt(i,t,e){let r=t?jt(t):K();return i.forEach(o=>{var n,a;switch(o.type){case"consent":r.consent=o.data;break;case"setquirk":r.quirks[o.data.key]=o.data.value;break;case"settest":r.tests[o.data.test]=o.data.variant;break;case"modscore":if(e)break;let c=(n=r.scores[o.data.dimension])!=null?n:0;r.scores[o.data.dimension]=c+o.data.delta;break;case"modscoreS":if(e)break;let d=(a=r.sessionScores[o.data.dimension])!=null?a:0;r.sessionScores[o.data.dimension]=d+o.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),r}var B="ufvisitor",v,I,z,S,D,w,b,L,Y,Ft,H,Qt,_,bt,F,Et,ot=class{constructor(t){u(this,D);u(this,b);u(this,Y);u(this,H);u(this,_);u(this,F);u(this,v,_t());u(this,I,new rt);u(this,z,void 0);u(this,S,void 0);y(this,"events",{on:s(this,v).on,off:s(this,v).off});if(m(this,S,t),s(this,D,w)||h(this,b,L).call(this,h(this,F,Et).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();e&&e.quirks&&this.updateData(Object.entries(e.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.transitionStore.events.on("dataUpdatedAsync",o=>{h(this,b,L).call(this,{...s(this,D,w).visitorData,...o})});let r=t.transitionStore.data;r&&h(this,b,L).call(this,{...s(this,D,w).visitorData,...r},!0)}}get data(){let t=s(this,D,w);if(h(this,H,Qt).call(this,t)){let{sessionScores:e,...r}=t.visitorData;return h(this,b,L).call(this,{...r,sessionScores:{}}),s(this,v).emit("log",["info",120]),s(this,D,w).visitorData}return t.visitorData}async updateData(t){var r,o;if(t.length===0)return;s(this,v).emit("log",["debug",101,t]);let e=kt(t,this.data,(r=s(this,D,w))==null?void 0:r.visitorData.controlGroup);t.some(n=>n.type==="consent"&&!n.data)&&s(this,I).delete(B,!0),h(this,b,L).call(this,e),await((o=s(this,S).transitionStore)==null?void 0:o.updateData(t,s(this,D,w).visitorData))}async delete(t){var e;s(this,I).delete(B,!1),await((e=s(this,S).transitionStore)==null?void 0:e.delete(t)),s(this,v).emit("log",["info",103,t]),h(this,b,L).call(this,h(this,F,Et).call(this))}};v=new WeakMap,I=new WeakMap,z=new WeakMap,S=new WeakMap,D=new WeakSet,w=function(){return s(this,I).get(B)},b=new WeakSet,L=function(t,e=!1){var f,M;let r=s(this,D,w),o=Date.now();h(this,_,bt).call(this,t.scores),h(this,_,bt).call(this,t.sessionScores),(M=(f=s(this,S)).decay)==null||M.call(f,{now:o,lastUpd:r==null?void 0:r.updated,scores:t.scores,sessionScores:t.sessionScores});let n=!it(r==null?void 0:r.visitorData.scores,t.scores),a=!it(r==null?void 0:r.visitorData.sessionScores,t.sessionScores),c=!it(r==null?void 0:r.visitorData.quirks,t.quirks),d={updated:o,visitorData:t};h(this,Y,Ft).call(this),s(this,I).set(B,d,!!t.consent),s(this,v).emit("log",["debug",102,t]),e||((n||a)&&s(this,v).emit("scoresUpdated",t),c&&s(this,v).emit("quirksUpdated",t))},Y=new WeakSet,Ft=function(){typeof window=="undefined"||!s(this,S).visitLifespan||(s(this,z)&&window.clearTimeout(s(this,z)),m(this,z,window.setTimeout(()=>{this.data},s(this,S).visitLifespan+50)))},H=new WeakSet,Qt=function(t){let e=s(this,S).visitLifespan;return e?t.updated+e<Date.now():!1},_=new WeakSet,bt=function(t){if(!!s(this,S).manifest)for(let e in t){let r=t[e],o=s(this,S).manifest.getDimensionByKey(e);!o||r>o.cap&&(s(this,v).emit("log",["debug",110,{dim:e,score:r,cap:o.cap}]),t[e]=o.cap)}},F=new WeakSet,Et=function(){var t,e,r;return{...K(),consent:(t=s(this,S).defaultConsent)!=null?t:!1,controlGroup:(r=(e=s(this,S).manifest)==null?void 0:e.rollForControlGroup())!=null?r:!1}};import Jt from"mitt";function Tt({context:i,variations:t,take:e=1}){var c;let r=(c=i.storage.data.controlGroup)!=null?c:!1,o=[],n=!1,a=i.scores;for(let d of t){if(o.length===e)break;if(!d.pz){o.push(d);continue}!r&&wt(d.pz,a)&&(n=!0,o.push(d))}return{personalized:n,variations:o}}function wt(i,t){return!i.op||i.op==="&"?i.crit.every(e=>Pt(e,t)):i.crit.some(e=>Pt(e,t))}function Pt(i,t){var a;let{op:e,l:r}=i,o=(a=t[r])!=null?a:0;if(e==="+")return Math.max(...Object.values(t))===o&&o>0;if(e==="-")return Math.min(...Object.values(t))===o&&o>0;let n=i.rDim?t[i.rDim]:i.r;if(n===void 0)return!1;if(e===">")return o>n;if(e===">=")return o>=n;if(e==="<")return o<n;if(e==="<=")return o<=n;if(e==="=")return o===n;if(e==="!=")return o!==n;throw new Error(`Unknown op: ${e}`)}var Kt=i=>{let{values:t,total:e,missingDistribution:r}=i.reduce((o,n)=>(n.testDistribution?o.total+=n.testDistribution:++o.missingDistribution,o.values.push(n.testDistribution),o),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let n=(100-e)/r;t.forEach((a,c)=>{typeof a=="undefined"&&(t[c]=n)})}return t},st=({name:i,context:t,variations:e})=>{var n;let r,o=t.getTestVariantId(i);if(o===null)return{result:void 0};if(o&&(r=e.find(a=>a.id===o),r||t.log("warn",401,{test:i,variant:o})),!r){let a=Kt(e),c=Math.floor(Math.random()*100),d=0;r=e.find((f,M)=>{let Q=a[M];if(c>d&&c<=d+Q)return f;d+=Q}),r&&t.setTestVariantId(i,(n=r.id)!=null?n:"Unknown")}return{result:r}};var E,P,V,g,Bt=class{constructor(t){u(this,E,void 0);u(this,P,{});u(this,V,void 0);u(this,g,Jt());y(this,"events",{on:s(this,g).on,off:s(this,g).off});y(this,"storage");let{manifest:e,...r}=t;m(this,V,{}),m(this,E,new R({manifest:e,evaluator:new N({CK:ut,QS:pt,QK:mt,PVC:lt,EVT:ft,PV:gt})})),this.storage=new ot({manifest:s(this,E),...r}),this.storage.events.on("log",(...n)=>s(this,g).emit("log",...n));let o=n=>{var c;let a={...n.scores};for(let d in n.sessionScores)a[d]=((c=a[d])!=null?c:0)+n.sessionScores[d];a=s(this,E).computeAggregateDimensions(a),m(this,P,a),s(this,g).emit("scoresUpdated",a),s(this,g).emit("log",["info",3,a])};this.storage.events.on("scoresUpdated",o),o(this.storage.data),this.storage.events.on("quirksUpdated",n=>{let a=s(this,E).computeSignals({scores:s(this,P),state:s(this,V),previousState:s(this,V),visitor:this.storage.data});this.storage.updateData(a),s(this,g).emit("quirksUpdated",n.quirks),s(this,g).emit("log",["info",4,n.quirks])}),s(this,g).emit("log",["debug",1,{options:t,scores:s(this,P)}])}get scores(){return s(this,P)}async update(t){let e=[];s(this,g).emit("log",["info",2,t]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(o=>({type:"modscore",data:{dimension:R.getEnrichmentVectorKey(o.cat,o.key),delta:o.str}}))),t.enrichments=void 0);let r=s(this,V);m(this,V,{...s(this,V),...t}),e.push(...s(this,E).computeSignals({state:s(this,V),previousState:r,visitor:this.storage.data,scores:s(this,P)})),await this.storage.updateData(e)}getTestVariantId(t){var r;let e=s(this,E).getTest(t);return e?(r=e.wv)!=null?r:this.storage.data.tests[t]:(s(this,g).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){s(this,g).emit("log",t)}test(t){var r;let e=st({...t,context:this});return s(this,g).emit("testResult",{name:t.name,variantId:(r=e.result)==null?void 0:r.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=Tt({...t,context:this});return t.name?s(this,g).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(r=>{var o;return(o=r.id)!=null?o:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){m(this,V,{}),await this.storage.delete(t)}};E=new WeakMap,P=new WeakMap,V=new WeakMap,g=new WeakMap;var Dr=([i,t,...e])=>{console[i](`\u{1F94B} [${i}] Uniform event ID ${t}
|
2
|
+
`,...e.map(r=>JSON.stringify(r,null,2)))};var Mt={1:({options:i,scores:t})=>["tracker","constructed",i,t],2:i=>["tracker","received data update",i],3:i=>["tracker","new score vector",i],4:i=>["tracker","updated quirks",i],101:i=>["storage","received update commands",i],102:i=>["storage","data was updated",i],103:i=>["storage",`data was deleted ${i?"from all devices":"from this device"}`],110:({dim:i,cap:t,score:e})=>["storage",`${i} score ${e} exceeded cap ${t}. Rounded down.`],120:()=>["storage","visitor data expired and was cleared"],301:()=>["placement","Missing `name` field on personalization. Analytics events will not be triggered."],401:i=>["testing",`${i} was unknown; it will not be run.`],402:({test:i,variant:t})=>["testing",`${i} no longer has visitor's variant ${t}; it will be removed.`],700:()=>["gtag","gtag is not defined, skipping analytics event emission. Ensure you have added the gtag script to your page."],701:()=>["gtag","enabled gtag event signal redirection"]};var kr=([i,t,...e])=>{let r=Mt[t],o=`\u{1F94B} [${new Date().toLocaleTimeString()}][${i}]`;r||console[i](`${o} unknown message ID ${t} - ensure all Uniform packages are the same version`,...e);let[n,a,...c]=r(...e);console[i](`${o}[${n}] ${a} (Event ID: ${t})
|
3
|
+
`,...c.map(d=>JSON.stringify(d,null,2)))};var Yt=(c=>(c.ListStart="nesi-list-start",c.ListEnd="nesi-list-end",c.ListItem="nesi-list-item-html",c.ListItemSettings="nesi-list-item-settings",c.TestStart="nesi-test-start",c.TestEnd="nesi-test-end",c.Unknown="unknown",c))(Yt||{}),Er="nesitag";export{Bt as Context,Lt as CookieTransitionDataStore,Er as EdgeNodeTagName,$t as EdgeTransitionDataStore,N as GroupCriteriaEvaluator,R as ManifestInstance,It as SERVER_STATE_ID,Yt as ScriptType,j as TransitionDataStore,ot as VisitorDataStore,nt as computeAggregateDimensions,Dr as consoleLogDrain,ut as cookieEvaluator,Ae as createLinearDecay,kr as debugConsoleLogDrain,K as emptyVisitorData,wt as evaluateVariantMatch,ft as eventEvaluator,x as isStringMatch,Z as pageViewCountDimension,lt as pageViewCountEvaluator,gt as pageVisitedEvaluator,Tt as personalizeVariations,pt as queryStringEvaluator,mt as quirkEvaluator,st as testVariations};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/context",
|
3
|
-
"version": "12.2.1-alpha.
|
3
|
+
"version": "12.2.1-alpha.135+7a372e5f",
|
4
4
|
"description": "Uniform Context core package",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -51,24 +51,25 @@
|
|
51
51
|
"benchmark:run": "node ./dist/storage.benchmark.js"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
|
-
"@types/jest": "27.0
|
54
|
+
"@types/jest": "27.4.0",
|
55
55
|
"@types/node": "16.11.12",
|
56
56
|
"@types/yargs": "17.0.8",
|
57
|
-
"@uniformdev/cli": "^12.2.1-alpha.
|
57
|
+
"@uniformdev/cli": "^12.2.1-alpha.135+7a372e5f",
|
58
58
|
"benny": "^3.7.1",
|
59
|
-
"eslint": "8.
|
60
|
-
"eslint-plugin-react": "7.
|
59
|
+
"eslint": "8.7.0",
|
60
|
+
"eslint-plugin-react": "7.28.0",
|
61
61
|
"eslint-plugin-react-hooks": "4.3.0",
|
62
|
-
"jest": "27.4.
|
62
|
+
"jest": "27.4.7",
|
63
63
|
"npm-run-all": "4.1.5",
|
64
64
|
"rimraf": "3.0.2",
|
65
|
-
"ts-jest": "27.1.
|
66
|
-
"tsup": "5.11.
|
67
|
-
"yargs": "17.3.
|
65
|
+
"ts-jest": "27.1.3",
|
66
|
+
"tsup": "5.11.11",
|
67
|
+
"yargs": "17.3.1"
|
68
68
|
},
|
69
69
|
"dependencies": {
|
70
70
|
"chalk": "^4.1.2",
|
71
71
|
"dequal": "^2.0.2",
|
72
|
+
"isomorphic-unfetch": "^3.1.0",
|
72
73
|
"mitt": "^3.0.0",
|
73
74
|
"number-to-base64": "^1.0.5",
|
74
75
|
"rfdc": "^1.3.0"
|
@@ -76,5 +77,5 @@
|
|
76
77
|
"files": [
|
77
78
|
"/dist"
|
78
79
|
],
|
79
|
-
"gitHead": "
|
80
|
+
"gitHead": "7a372e5f5dddf0b615e61d765f5545d0dc642216"
|
80
81
|
}
|
package/dist/chunk-5ZM3QNMG.mjs
DELETED
@@ -1,2 +0,0 @@
|
|
1
|
-
import{d as h,e as m,f as d,i as a}from"./chunk-POAQ5JTB.mjs";a();var x=async f=>await f(),p=class extends Error{constructor(t,e,i,n,r){super(`${t}
|
2
|
-
${n}${r?" "+r:""} (${e} ${i})`);this.errorMessage=t;this.fetchMethod=e;this.fetchUri=i;this.statusCode=n;this.statusText=r;Object.setPrototypeOf(this,p.prototype)}};a();a();var u=class{constructor(t){h(this,"options");var e,i,n,r,s,o;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...t,fetch:(e=t.fetch)!=null?e:fetch,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(r=t.projectId)!=null?r:null,bearerToken:(s=t.bearerToken)!=null?s:null,limitPolicy:(o=t.limitPolicy)!=null?o:x}}async apiClient(t,e){return this.options.limitPolicy(async()=>{var r;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let s="";try{let o=await n.text();try{let c=JSON.parse(o);c.errorMessage?s=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:s=o}catch(c){s=o}}catch(o){s="General error"}throw new p(s,(r=e==null?void 0:e.method)!=null?r:"GET",t.toString(),n.status)}return(e==null?void 0:e.expectNoContent)?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,r])=>{var s;typeof r!==void 0&&r!==null&&i.searchParams.append(n,(s=r==null?void 0:r.toString())!=null?s:"")}),i}};var l,y=class extends u{constructor(t){super(t)}async get(t){let{projectId:e}=this.options,i=this.createUrl(m(y,l),{...t,projectId:e});return await this.apiClient(i)}},P=y;l=new WeakMap,d(P,l,"/api/v2/manifest");export{x as a,p as b,u as c,P as d};
|
package/dist/chunk-POAQ5JTB.mjs
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
var a=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var s=(t,e,o)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var _=t=>i(t,"__esModule",{value:!0});var x=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(e,o)=>(typeof require!="undefined"?require:e)[o]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var d=(t,e)=>()=>(t&&(e=t(t=0)),e);var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var g=(t,e,o,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!l.call(t,r)&&(o||r!=="default")&&i(t,r,{get:()=>e[r],enumerable:!(m=p(e,r))||m.enumerable});return t},D=(t,e)=>g(_(i(t!=null?a(f(t)):{},"default",!e&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var F=(t,e,o)=>(s(t,typeof e!="symbol"?e+"":e,o),o),n=(t,e,o)=>{if(!e.has(t))throw TypeError("Cannot "+o)};var L=(t,e,o)=>(n(t,e,"read from private field"),o?o.call(t):e.get(t)),P=(t,e,o)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,o)},R=(t,e,o,m)=>(n(t,e,"write to private field"),m?m.call(t,o):e.set(t,o),o);var T=(t,e,o)=>(n(t,e,"access private method"),o);var h=d(()=>{});export{x as a,u as b,D as c,F as d,L as e,P as f,R as g,T as h,h as i};
|