@picked/client 0.0.1-dev.1764952778408 → 0.0.1-dev.1765227621508

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/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var T=Object.defineProperty;var V=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var h=(t,e,r)=>V(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("effector"),S=require("@withease/factories"),F=require("../experience-instance-DjjpHk0t.cjs"),I=require("../logger-BsmHUUw1.cjs"),k=require("../storage-YlR83AWP.cjs"),N=require("../id-BKIWbSTy.cjs"),z=require("../object-BbFTsGh3.cjs"),w=require("../supports-YvpQZxbh.cjs"),U=f.createDomain("experience"),_=S.createFactory(({client:t,experience:e})=>{const r=U.store(e),n=f.createApi(r,{merge(l,y){return{...l,...y.experience}}}),o=r.map(l=>({name:l.name,decisionLogic:l.condition??l.decide,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),c=t.components.listStore.map(l=>l.find(y=>y.name===`experience:${e.id}`)||l.find(y=>y.name==="experience"),{skipVoid:!1}),s=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),i=e.actions??[];return{id:e.id,configStore:o,treeStore:s,componentStore:c,actions:i,merge:n.merge}});function q(t){return S.invoke(_,t)}const K=S.createFactory(({client:t})=>{const e=U.store({}),r=f.createApi(e,{register(s,i){return{...s,[i.id]:i}}});function n(s){const i=e.getState()[s.id];if(i){i.merge({experience:s,strategy:"override"});return}const l=q({client:t,experience:s});r.register(l)}const o=e.map(s=>Object.values(s));function c(s){return e.map(i=>i[s],{skipVoid:!1})}return{register:n,getById:c,listStore:o}});function H(t){return S.invoke(K,t)}const W=(t,e)=>{e.register(t)},L=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=F.getTargetElements(r,e.id);n.forEach(({elements:c})=>c.forEach(s=>F.tagTargetElement(s,e.id))),F.createAppHosts(n,e.id).forEach(c=>{t.experienceInstances.spawn(e,c)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await G(t,e)&&L(t,e)}))},G=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return F.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&F.isRulesLogic(r)?await F.evaluateRuleLogic(t,r)===!0:!0},Y=(t,e,r)=>{const n=e.name,o=e.setup(t);if(o){const c=r[n]??{};r[n]=Object.freeze({...c,...o})}},J=f.createDomain("component"),Q=S.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function X(t){return S.invoke(Q,t)}const Z=S.createFactory(({client:t})=>{const e=J.store({}),r=f.createApi(e,{register(s,i){return{...s,[i.name]:i}}});function n(s,i){e.getState()[s]&&I.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const y=X({client:t,name:s,component:i});r.register(y)}const o=e.map(s=>Object.values(s));function c(s){return e.map(i=>i[s],{skipVoid:!1})}return{register:n,getByName:c,listStore:o}});function ee(t){return S.invoke(Z,t)}const j=(t,e,r)=>{r.register(t,e)},te=f.createDomain("framework"),re=S.createFactory(({client:t})=>{const e=te.store({}),r=f.createApi(e,{register(s,i){return{...s,[i.name]:i.framework}}});function n(s,i){e.getState()[s]&&I.logger("warn",`Framework '${s}' already registered. Registering again will override the previous registration.`),r.register({name:s,framework:i})}const o=e.map(s=>Object.values(s));function c(s){return e.map(i=>i[s],{skipVoid:!1})}return{register:n,getByName:c,listStore:o}});function se(t){return S.invoke(re,t)}const ne=(t,e)=>{e.register(t.name,t)},oe=6e3,ie=k.createStorageKey("last_ping","global"),ae=t=>`${t}/api/v1/ping`,ce=async t=>{try{const e=Date.now(),r=k.localStore.get(ie);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<oe)return!0;const o=ae(t.apiUrl),c={projectId:t.projectId,path:window.location.pathname},s=JSON.stringify(c),i={"Content-Type":"application/json"},l=document.getElementById("picked_script"),y=l==null?void 0:l.dataset.verceltoken;y&&(i["x-vercel-protection-bypass"]=y);const d=(await fetch(o,{method:"POST",headers:i,body:s})).ok;return d&&r.set(e),d}catch(e){return I.logger("error",e),!1}};function ue(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(r)}const le=f.createDomain("predicate"),de=S.createFactory(({client:t})=>{const e=le.store({}),r=f.createApi(e,{register(s,i){return{...s,[i.name]:{name:i.name,predicate:i.predicate}}}});function n(s,i){e.getState()[s]&&I.logger("warn",`Predicate '${s}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:s,predicate:i}))}const o=e.map(s=>Object.values(s));function c(s){return e.map(i=>i[s],{skipVoid:!1})}return{register:n,getByName:c,listStore:o}});function pe(t){return S.invoke(de,t)}const ge=(t,e,r)=>{r.register(t,e)},$=f.createDomain("feature"),fe=S.createFactory(({client:t})=>{const e=$.store({}),r=$.store([]),n=f.createApi(e,{register(d,u){return{...d,[u.id]:u.feature}}});function o(d,u){e.getState()[d]&&I.logger("warn",`Feature '${d}' already registered. Registering again will override the previous registration.`);const p={id:d,feature:{...u,id:d}};n.register(Object.freeze({id:d,feature:p}))}const c=f.createEffect(async({id:d,key:u,storage:a="local"})=>{const p=k.createStorageKey(`feature:${d}:${u}`,"global"),g=(a==="session"?k.sessionStore:k.localStore).get(p).boolean();return g===null?null:{id:d,key:u,bucket:g,storage:a}}),s=f.createEffect(d=>{if(!d)return null;const u=k.createStorageKey(`feature:${d.id}:${d.key}`,"global");(d.storage==="session"?k.sessionStore:k.localStore).set(u,d.bucket)}),i=new Map,l=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:d,resolvedFeaturesStore:u},{id:a,decide:p,key:m})=>{const g=u.find(A=>A.id===a&&A.key===m);if(g)return g;const v=d[a];if(!v)throw new Error(`Feature with id '${a}' not found`);const x=i.get(`${a}:${m}`);if(x!==void 0){const A=await x;return{id:v.id,bucket:A,key:m,storage:v.feature.storage}}const P=p();i.set(`${a}:${m}`,P);const E=await P;return{id:v.id,bucket:E,key:m,storage:v.feature.storage}}});f.sample({clock:n.register,fn:d=>{const{id:u,feature:a}=d;return{id:u,key:a.feature.key,storage:a.feature.storage}},target:c}),f.sample({source:e,clock:l.doneData,fn:(d,u)=>{var v;const{id:a,bucket:p,storage:m}=u,g=(v=d[a])==null?void 0:v.feature.key;return g?{key:g,id:a,bucket:p,storage:m}:null},target:s});const y=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:d,resolvedFeaturesStore:u})=>Object.values(d).map(a=>{const p=u.find(m=>m.id===a.id&&m.key===a.feature.key);return p?{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:()=>({id:a.id,bucket:p.bucket}),isResolved:!0}:{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:async()=>await l(a.feature),isResolved:!1}}));f.sample({clock:l.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:d},{id:u,key:a})=>!d.some(m=>m.id===u&&m.key===a),fn:(d,u)=>u,target:t.eventBus.prepend(d=>({type:"feature_decide",feature:d}))}),f.sample({clock:[c.doneData,l.doneData],source:r,fn:(d,u)=>!u||d.some(p=>p.id===u.id&&p.key===u.key)?d:[...d,u],target:r});function b(d){return e.map(u=>u[d],{skipVoid:!1})}return{register:o,getByName:b,listStore:y}});function me(t){return S.invoke(fe,t)}const he=(t,e,r)=>{r.register(t,e)},R=f.createDomain("history");function C(t,e){return{id:N.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ye=S.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),o=R.event();t.on(e,(s,i)=>({entries:[...s.entries,C(i.experienceId,i.node)]})),t.on(r,(s,i)=>({entries:[...s.entries.slice(0,-1),C(i.experienceId,i.node)]})),t.on(o,(s,i)=>i);function c(s,i){const l={lastStepIndex:-1,secondLastStepIndex:-1};for(let y=s.length-1;y>=0;y--){const b=s[y],d=b==null?void 0:b.node;if(!(!d||!F.isStepNode(d))&&!(i&&(b==null?void 0:b.experienceId)!==i))if(l.lastStepIndex===-1)l.lastStepIndex=y;else{l.secondLastStepIndex=y;break}}return l}return t.on(n,(s,i)=>{const{secondLastStepIndex:l}=c(s.entries,i.experienceId),y=l!==-1?s.entries.slice(0,l+1):s.entries;return{...s,entries:y}}),{push:e,replace:r,back:n,restore:o,entriesStore:t.map(s=>s.entries)}});function Se(){return S.invoke(ye)}const ve=()=>f.createEvent(),ke=f.createDomain("field"),we=S.createFactory(()=>{const t=ke.store({}),e=f.createApi(t,{register(s,i){return{...s,[i.field.id]:i.field}}});function r(s){e.register({field:s})}const n=t.map(s=>Object.values(s));function o(s){return t.map(i=>i[s]||null)}function c(s){return t.map(i=>Object.values(i).find(l=>l.name===s)||null)}return{register:r,getById:o,listStore:n,getByName:c}});function Fe(){return S.invoke(we)}const be=(t,e)=>{e.register(t)},Ie=f.createDomain("action"),xe=S.createFactory(()=>{const t=Ie.store({}),e=f.createApi(t,{register(c,s){return{...c,[s.name]:{name:s.name,action:s.action}}}});function r(c,s){e.register({name:c,action:s})}const n=t.map(c=>Object.values(c));function o(c){return t.map(s=>s[c],{skipVoid:!1})}return{register:r,getByName:o,listStore:n}});function Ee(){return S.invoke(xe)}const Re=(t,e,r)=>{r.register(t,e)};function O(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const Pe=f.createDomain("response"),Ae=S.createFactory(({client:t})=>{const e=Pe.store({}),r=f.createEvent(),n=f.createEvent(),o=f.createApi(e,{register(u,a){return{...u,[a.fieldId]:a.response}},registerBatch(u,a){return{...u,...a}},clear(u,a){const{[a]:p,...m}=u;return m},clearAll(){return{}}});function c(u,a){o.register({fieldId:u,response:a})}async function s(u){const a=[];return await Promise.allSettled(Object.entries(u).map(async([p,m])=>{let g=m;const v=t.fields.getById(p).getState();if(!v){a.push({fieldId:p,userMessage:`Field '${p}' not found`,systemMessage:`No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:g});return}if(v.multiple&&(typeof g=="string"||typeof g=="number"||typeof g=="boolean")&&(g=[g]),v.validation&&!z.isEmpty(v.validation)&&!O(g)){const x=await F.evaluateRuleLogic(t,v.validation,{$input:g});if(typeof x=="string"){a.push({fieldId:p,userMessage:x,systemMessage:`Field validation resulted in an error: ${x}.`,value:g});return}if(x===!1){a.push({fieldId:p,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(v.required&&O(g)){a.push({fieldId:p,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!v.multiple&&Array.isArray(g)&&g.length>1){a.push({fieldId:p,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(v.options){const x=v.options.map(E=>E.value),P=Array.isArray(g)?g:[g];Array.isArray(g)&&(P.every(E=>x.includes(E))||a.push({fieldId:p,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${x.join(", ")}`,value:g}))}})),{responsesToCommit:u,validationErrors:a}}async function i(u){const{responsesToCommit:a,validationErrors:p}=await s(u);return p.length?{errors:p}:(o.registerBatch(a),{errors:[]})}const l=e.map(u=>u),y=e.map(u=>Object.keys(u).map(p=>({fieldId:p,value:u[p]})));function b(u){const a=t.fields.getById(u),p=e.map(m=>m[u]||null);return f.combine({f:a,r:p},({f:m,r:g})=>g||(m!=null&&m.defaultValue?m.defaultValue:null))}function d(u){const a=t.fields.getByName(u);return f.combine({f:a,s:e},({f:p,s:m})=>{const g=p&&m[p.id]||null;return g||(p!=null&&p.defaultValue?p.defaultValue:null)})}return f.sample({clock:r,target:o.clearAll}),f.sample({clock:n,target:o.clear}),{register:c,clearAll:r,clear:n,commit:i,getResponsesToCommit:s,listStore:y,getAllStore:l,getByFieldId:b,getByFieldName:d}});function De(t){return S.invoke(Ae,t)}const Be=()=>"0.0.1-dev.1764952778408";function je(){if(w.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function $e(){if(!w.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[o]of t.entries())o.startsWith("picked-")&&r.add(o);for(const o of r){const c=o.replace("picked-","");e[c]=t.getAll(o)}const n=k.createStorageKey("s");if(r.size>0)k.sessionStore.set(n,e);else{const o=k.sessionStore.get(n);if(o)return o.json()||{}}return e}function Ce(){if(w.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${n}`}const Oe=k.createStorageKey("session","global"),Ue=()=>{const t=k.localStore.get(Oe);let e;t.isSet()&&(e=t.json());const r=o=>t.set({id:o.id,isUser:o.isUser,identifiers:o.identifiers}),n={id:(e==null?void 0:e.id)??Ce(),isUser:(e==null?void 0:e.isUser)??void 0,identifiers:(e==null?void 0:e.identifiers)??void 0,setIsUser(o){this.isUser=o,r(this)},setIdentifier(o,c){this.identifiers={...this.identifiers??{},[o]:c},r(this)},removeIdentifier(o){if(!this.identifiers)return;const{[o]:c,...s}=this.identifiers;this.identifiers=Object.keys(s).length?s:void 0,r(this)}};return r(n),n},Le=()=>w.supportsLocalStorage()?Ue():null;class D{constructor(e){h(this,"options");h(this,"isReady",!1);h(this,"project");h(this,"plugins",{});h(this,"eventBus",ve());h(this,"organizationId");h(this,"projectId");h(this,"apiUrl");h(this,"session");h(this,"precondition");h(this,"condition");h(this,"searchParams",$e());h(this,"history",Se());h(this,"components",ee({client:this}));h(this,"experienceInstances",F.createExperienceInstanceIndex({client:this}));h(this,"experiences",H({client:this}));h(this,"frameworks",se({client:this}));h(this,"predicates",pe({client:this}));h(this,"features",me({client:this}));h(this,"responses",De({client:this}));h(this,"fields",Fe());h(this,"actions",Ee());I.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||je(),this.session=Le(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Be()}),I.logger("info","Picked client initialized.")}start(){ce(this),(async()=>{if(!w.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await F.evaluateRuleLogic(this,this.precondition)===!0;let n;r&&(this.condition===void 0?n=!0:typeof this.condition=="boolean"?n=this.condition:n=await F.evaluateRuleLogic(this,this.condition)===!0);const o=r&&n===!0;if(typeof n=="boolean"&&this.session){const c=n;this.session.setIsUser(c),this.eventBus({type:"user_decide",value:c})}this.eventBus({type:"initialize"}),document.body&&o&&B(this),await F.domInteractive(),o&&B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session})})()}registerFramework(e){ne(e,this.frameworks)}registerComponent(e,r){j(e,r,this.components)}registerPlugin(e){Y(this,e,this.plugins)}registerFeature(e,r){he(e,r,this.features)}registerPredicate(e,r){ge(e,r,this.predicates)}registerField(e){be(e,this.fields)}registerAction(e,r){Re(e,r,this.actions)}registerExperience(e){e.component&&j(`experience:${e.id}`,e.component,this.components),W(e,this.experiences)}getStateSnapshot(){return ue(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){I.logger("warn",`Experience with id '${e}' not found.`);return}L(this,r)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(r=>{if(Array.isArray(r)){r.forEach(o=>{this.registerPlugin(o)});return}const n=typeof r=="function"?r():r;if(Array.isArray(n)){n.forEach(o=>this.registerPlugin(o));return}this.registerPlugin(n)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const o=typeof n=="function"?n():n;this.registerFeature(r,o)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,o]=r.split(":");if(!n||!o)return;let c=o;c==="true"&&(c=!0),c==="false"&&(c=!1),this.registerFeature(n,{key:`${c}`,name:n,decide:()=>c,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}h(D,"logger",I.logger);function M(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Me(t){return t.some(e=>e.condition||M(e))}async function Te(t,e){return e.length===0||!Me(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await F.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!M(n))return n;const s=(await Promise.all(n.options.map(async l=>l.condition?await F.evaluateRuleLogic(t,l.condition)?l:null:l))).filter(l=>l!==null);return s.length===n.options.length?n:s.length===0?null:{...n,options:s}}))).filter(n=>n!==null)}const Ve=t=>{const e=new D(t);return w.bindClient(e),e};exports.evaluateRuleLogic=F.evaluateRuleLogic;exports.isPickedRoot=F.isPickedRoot;exports.createStorageKey=k.createStorageKey;exports.localStore=k.localStore;exports.sessionStore=k.sessionStore;exports.subscribe=k.subscribe;exports.supportsCookies=w.supportsCookies;exports.supportsCryptoRandomUUID=w.supportsCryptoRandomUUID;exports.supportsDocument=w.supportsDocument;exports.supportsHistory=w.supportsHistory;exports.supportsIntersectionObserver=w.supportsIntersectionObserver;exports.supportsLocalStorage=w.supportsLocalStorage;exports.supportsLocation=w.supportsLocation;exports.supportsSessionStorage=w.supportsSessionStorage;exports.supportsShadowRoot=w.supportsShadowRoot;exports.supportsWebComponents=w.supportsWebComponents;exports.supportsWindow=w.supportsWindow;exports.Picked=D;exports.createClient=Ve;exports.getStepFields=Te;
1
+ "use strict";var T=Object.defineProperty;var V=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var y=(t,e,r)=>V(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("effector"),S=require("@withease/factories"),F=require("../experience-instance-DjjpHk0t.cjs"),I=require("../logger-BsmHUUw1.cjs"),k=require("../storage-YlR83AWP.cjs"),N=require("../id-BKIWbSTy.cjs"),z=require("../object-BbFTsGh3.cjs"),w=require("../supports-YvpQZxbh.cjs"),U=f.createDomain("experience"),_=S.createFactory(({client:t,experience:e})=>{const r=U.store(e),n=f.createApi(r,{merge(l,h){return{...l,...h.experience}}}),i=r.map(l=>({name:l.name,decisionLogic:l.condition??l.decide,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),u=t.components.listStore.map(l=>l.find(h=>h.name===`experience:${e.id}`)||l.find(h=>h.name==="experience"),{skipVoid:!1}),s=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),o=e.actions??[];return{id:e.id,configStore:i,treeStore:s,componentStore:u,actions:o,merge:n.merge}});function q(t){return S.invoke(_,t)}const K=S.createFactory(({client:t})=>{const e=U.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.id]:o}}});function n(s){const o=e.getState()[s.id];if(o){o.merge({experience:s,strategy:"override"});return}const l=q({client:t,experience:s});r.register(l)}const i=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getById:u,listStore:i}});function H(t){return S.invoke(K,t)}const W=(t,e)=>{e.register(t)},L=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=F.getTargetElements(r,e.id);n.forEach(({elements:u})=>u.forEach(s=>F.tagTargetElement(s,e.id))),F.createAppHosts(n,e.id).forEach(u=>{t.experienceInstances.spawn(e,u)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await G(t,e)&&L(t,e)}))},G=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return F.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&F.isRulesLogic(r)?await F.evaluateRuleLogic(t,r)===!0:!0},Y=(t,e,r)=>{const n=e.name,i=e.setup(t);if(i){const u=r[n]??{};r[n]=Object.freeze({...u,...i})}},J=f.createDomain("component"),Q=S.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function X(t){return S.invoke(Q,t)}const Z=S.createFactory(({client:t})=>{const e=J.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const h=X({client:t,name:s,component:o});r.register(h)}const i=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:i}});function ee(t){return S.invoke(Z,t)}const j=(t,e,r)=>{r.register(t,e)},te=f.createDomain("framework"),re=S.createFactory(({client:t})=>{const e=te.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o.framework}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Framework '${s}' already registered. Registering again will override the previous registration.`),r.register({name:s,framework:o})}const i=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:i}});function se(t){return S.invoke(re,t)}const ne=(t,e)=>{e.register(t.name,t)},oe=6e3,ie=k.createStorageKey("last_ping","global"),ae=t=>`${t}/api/v1/ping`,ce=async t=>{try{const e=Date.now(),r=k.localStore.get(ie);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<oe)return!0;const i=ae(t.apiUrl),u={projectId:t.projectId,path:window.location.pathname},s=JSON.stringify(u),o={"Content-Type":"application/json"},l=document.getElementById("picked_script"),h=l==null?void 0:l.dataset.verceltoken;h&&(o["x-vercel-protection-bypass"]=h);const d=(await fetch(i,{method:"POST",headers:o,body:s})).ok;return d&&r.set(e),d}catch(e){return I.logger("error",e),!1}};function ue(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(r)}const le=f.createDomain("predicate"),de=S.createFactory(({client:t})=>{const e=le.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:{name:o.name,predicate:o.predicate}}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Predicate '${s}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:s,predicate:o}))}const i=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:i}});function pe(t){return S.invoke(de,t)}const ge=(t,e,r)=>{r.register(t,e)},$=f.createDomain("feature"),fe=S.createFactory(({client:t})=>{const e=$.store({}),r=$.store([]),n=f.createApi(e,{register(d,c){return{...d,[c.id]:c.feature}}});function i(d,c){e.getState()[d]&&I.logger("warn",`Feature '${d}' already registered. Registering again will override the previous registration.`);const p={id:d,feature:{...c,id:d}};n.register(Object.freeze({id:d,feature:p}))}const u=f.createEffect(async({id:d,key:c,storage:a="local"})=>{const p=k.createStorageKey(`feature:${d}:${c}`,"global"),g=(a==="session"?k.sessionStore:k.localStore).get(p).boolean();return g===null?null:{id:d,key:c,bucket:g,storage:a}}),s=f.createEffect(d=>{if(!d)return null;const c=k.createStorageKey(`feature:${d.id}:${d.key}`,"global");(d.storage==="session"?k.sessionStore:k.localStore).set(c,d.bucket)}),o=new Map,l=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:d,resolvedFeaturesStore:c},{id:a,decide:p,key:m})=>{const g=c.find(A=>A.id===a&&A.key===m);if(g)return g;const v=d[a];if(!v)throw new Error(`Feature with id '${a}' not found`);const x=o.get(`${a}:${m}`);if(x!==void 0){const A=await x;return{id:v.id,bucket:A,key:m,storage:v.feature.storage}}const P=p();o.set(`${a}:${m}`,P);const E=await P;return{id:v.id,bucket:E,key:m,storage:v.feature.storage}}});f.sample({clock:n.register,fn:d=>{const{id:c,feature:a}=d;return{id:c,key:a.feature.key,storage:a.feature.storage}},target:u}),f.sample({source:e,clock:l.doneData,fn:(d,c)=>{var v;const{id:a,bucket:p,storage:m}=c,g=(v=d[a])==null?void 0:v.feature.key;return g?{key:g,id:a,bucket:p,storage:m}:null},target:s});const h=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:d,resolvedFeaturesStore:c})=>Object.values(d).map(a=>{const p=c.find(m=>m.id===a.id&&m.key===a.feature.key);return p?{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:()=>({id:a.id,bucket:p.bucket}),isResolved:!0}:{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:async()=>await l(a.feature),isResolved:!1}}));f.sample({clock:l.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:d},{id:c,key:a})=>!d.some(m=>m.id===c&&m.key===a),fn:(d,c)=>c,target:t.eventBus.prepend(d=>({type:"feature_decide",feature:d}))}),f.sample({clock:[u.doneData,l.doneData],source:r,fn:(d,c)=>!c||d.some(p=>p.id===c.id&&p.key===c.key)?d:[...d,c],target:r});function b(d){return e.map(c=>c[d],{skipVoid:!1})}return{register:i,getByName:b,listStore:h}});function me(t){return S.invoke(fe,t)}const ye=(t,e,r)=>{r.register(t,e)},R=f.createDomain("history");function C(t,e){return{id:N.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const he=S.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),i=R.event();t.on(e,(s,o)=>({entries:[...s.entries,C(o.experienceId,o.node)]})),t.on(r,(s,o)=>({entries:[...s.entries.slice(0,-1),C(o.experienceId,o.node)]})),t.on(i,(s,o)=>o);function u(s,o){const l={lastStepIndex:-1,secondLastStepIndex:-1};for(let h=s.length-1;h>=0;h--){const b=s[h],d=b==null?void 0:b.node;if(!(!d||!F.isStepNode(d))&&!(o&&(b==null?void 0:b.experienceId)!==o))if(l.lastStepIndex===-1)l.lastStepIndex=h;else{l.secondLastStepIndex=h;break}}return l}return t.on(n,(s,o)=>{const{secondLastStepIndex:l}=u(s.entries,o.experienceId),h=l!==-1?s.entries.slice(0,l+1):s.entries;return{...s,entries:h}}),{push:e,replace:r,back:n,restore:i,entriesStore:t.map(s=>s.entries)}});function Se(){return S.invoke(he)}const ve=()=>f.createEvent(),ke=f.createDomain("field"),we=S.createFactory(()=>{const t=ke.store({}),e=f.createApi(t,{register(s,o){return{...s,[o.field.id]:o.field}}});function r(s){e.register({field:s})}const n=t.map(s=>Object.values(s));function i(s){return t.map(o=>o[s]||null)}function u(s){return t.map(o=>Object.values(o).find(l=>l.name===s)||null)}return{register:r,getById:i,listStore:n,getByName:u}});function Fe(){return S.invoke(we)}const be=(t,e)=>{e.register(t)},Ie=f.createDomain("action"),xe=S.createFactory(()=>{const t=Ie.store({}),e=f.createApi(t,{register(u,s){return{...u,[s.name]:{name:s.name,action:s.action}}}});function r(u,s){e.register({name:u,action:s})}const n=t.map(u=>Object.values(u));function i(u){return t.map(s=>s[u],{skipVoid:!1})}return{register:r,getByName:i,listStore:n}});function Ee(){return S.invoke(xe)}const Re=(t,e,r)=>{r.register(t,e)};function O(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const Pe=f.createDomain("response"),Ae=S.createFactory(({client:t})=>{const e=Pe.store({}),r=f.createEvent(),n=f.createEvent(),i=f.createApi(e,{register(c,a){return{...c,[a.fieldId]:a.response}},registerBatch(c,a){return{...c,...a}},clear(c,a){const{[a]:p,...m}=c;return m},clearAll(){return{}}});function u(c,a){i.register({fieldId:c,response:a})}async function s(c){const a=[];return await Promise.allSettled(Object.entries(c).map(async([p,m])=>{let g=m;const v=t.fields.getById(p).getState();if(!v){a.push({fieldId:p,userMessage:`Field '${p}' not found`,systemMessage:`No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:g});return}if(v.multiple&&(typeof g=="string"||typeof g=="number"||typeof g=="boolean")&&(g=[g]),v.validation&&!z.isEmpty(v.validation)&&!O(g)){const x=await F.evaluateRuleLogic(t,v.validation,{$input:g});if(typeof x=="string"){a.push({fieldId:p,userMessage:x,systemMessage:`Field validation resulted in an error: ${x}.`,value:g});return}if(x===!1){a.push({fieldId:p,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(v.required&&O(g)){a.push({fieldId:p,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!v.multiple&&Array.isArray(g)&&g.length>1){a.push({fieldId:p,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(v.options){const x=v.options.map(E=>E.value),P=Array.isArray(g)?g:[g];Array.isArray(g)&&(P.every(E=>x.includes(E))||a.push({fieldId:p,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${x.join(", ")}`,value:g}))}})),{responsesToCommit:c,validationErrors:a}}async function o(c){const{responsesToCommit:a,validationErrors:p}=await s(c);return p.length?{errors:p}:(i.registerBatch(a),{errors:[]})}const l=e.map(c=>c),h=e.map(c=>Object.keys(c).map(p=>({fieldId:p,value:c[p]})));function b(c){const a=t.fields.getById(c),p=e.map(m=>m[c]||null);return f.combine({f:a,r:p},({f:m,r:g})=>g||(m!=null&&m.defaultValue?m.defaultValue:null))}function d(c){const a=t.fields.getByName(c);return f.combine({f:a,s:e},({f:p,s:m})=>{const g=p&&m[p.id]||null;return g||(p!=null&&p.defaultValue?p.defaultValue:null)})}return f.sample({clock:r,target:i.clearAll}),f.sample({clock:n,target:i.clear}),{register:u,clearAll:r,clear:n,commit:o,getResponsesToCommit:s,listStore:h,getAllStore:l,getByFieldId:b,getByFieldName:d}});function De(t){return S.invoke(Ae,t)}const Be=()=>"0.0.1-dev.1765227621508";function je(){if(w.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function $e(){if(!w.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[i]of t.entries())i.startsWith("picked-")&&r.add(i);for(const i of r){const u=i.replace("picked-","");e[u]=t.getAll(i)}const n=k.createStorageKey("s");if(r.size>0)k.sessionStore.set(n,e);else{const i=k.sessionStore.get(n);if(i)return i.json()||{}}return e}function Ce(){if(w.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${n}`}const Oe=k.createStorageKey("session","global"),Ue=()=>{const t=k.localStore.get(Oe);let e;t.isSet()&&(e=t.json());const r=i=>t.set({id:i.id,isUser:i.isUser}),n={id:(e==null?void 0:e.id)??Ce(),isUser:(e==null?void 0:e.isUser)??void 0,setIsUser(i){this.isUser=i,r(this)}};return r(n),n},Le=()=>w.supportsLocalStorage()?Ue():null;class D{constructor(e){y(this,"options");y(this,"isReady",!1);y(this,"project");y(this,"plugins",{});y(this,"eventBus",ve());y(this,"organizationId");y(this,"projectId");y(this,"apiUrl");y(this,"session");y(this,"precondition");y(this,"condition");y(this,"searchParams",$e());y(this,"history",Se());y(this,"components",ee({client:this}));y(this,"experienceInstances",F.createExperienceInstanceIndex({client:this}));y(this,"experiences",H({client:this}));y(this,"frameworks",se({client:this}));y(this,"predicates",pe({client:this}));y(this,"features",me({client:this}));y(this,"responses",De({client:this}));y(this,"fields",Fe());y(this,"actions",Ee());I.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||je(),this.session=Le(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Be()}),I.logger("info","Picked client initialized.")}start(){ce(this),(async()=>{if(!w.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await F.evaluateRuleLogic(this,this.precondition)===!0;let n;r&&(this.condition===void 0?n=!0:typeof this.condition=="boolean"?n=this.condition:n=await F.evaluateRuleLogic(this,this.condition)===!0);const i=r&&n===!0;if(typeof n=="boolean"&&this.session){const u=n;this.session.setIsUser(u),this.eventBus({type:"user_decide",value:u})}this.eventBus({type:"initialize"}),document.body&&i&&B(this),await F.domInteractive(),i&&B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session})})()}registerFramework(e){ne(e,this.frameworks)}registerComponent(e,r){j(e,r,this.components)}registerPlugin(e){Y(this,e,this.plugins)}registerFeature(e,r){ye(e,r,this.features)}registerPredicate(e,r){ge(e,r,this.predicates)}registerField(e){be(e,this.fields)}registerAction(e,r){Re(e,r,this.actions)}registerExperience(e){e.component&&j(`experience:${e.id}`,e.component,this.components),W(e,this.experiences)}getStateSnapshot(){return ue(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){I.logger("warn",`Experience with id '${e}' not found.`);return}L(this,r)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(r=>{if(Array.isArray(r)){r.forEach(i=>{this.registerPlugin(i)});return}const n=typeof r=="function"?r():r;if(Array.isArray(n)){n.forEach(i=>this.registerPlugin(i));return}this.registerPlugin(n)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const i=typeof n=="function"?n():n;this.registerFeature(r,i)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,i]=r.split(":");if(!n||!i)return;let u=i;u==="true"&&(u=!0),u==="false"&&(u=!1),this.registerFeature(n,{key:`${u}`,name:n,decide:()=>u,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}y(D,"logger",I.logger);function M(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Me(t){return t.some(e=>e.condition||M(e))}async function Te(t,e){return e.length===0||!Me(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await F.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!M(n))return n;const s=(await Promise.all(n.options.map(async l=>l.condition?await F.evaluateRuleLogic(t,l.condition)?l:null:l))).filter(l=>l!==null);return s.length===n.options.length?n:s.length===0?null:{...n,options:s}}))).filter(n=>n!==null)}const Ve=t=>{const e=new D(t);return w.bindClient(e),e};exports.evaluateRuleLogic=F.evaluateRuleLogic;exports.isPickedRoot=F.isPickedRoot;exports.createStorageKey=k.createStorageKey;exports.localStore=k.localStore;exports.sessionStore=k.sessionStore;exports.subscribe=k.subscribe;exports.supportsCookies=w.supportsCookies;exports.supportsCryptoRandomUUID=w.supportsCryptoRandomUUID;exports.supportsDocument=w.supportsDocument;exports.supportsHistory=w.supportsHistory;exports.supportsIntersectionObserver=w.supportsIntersectionObserver;exports.supportsLocalStorage=w.supportsLocalStorage;exports.supportsLocation=w.supportsLocation;exports.supportsSessionStorage=w.supportsSessionStorage;exports.supportsShadowRoot=w.supportsShadowRoot;exports.supportsWebComponents=w.supportsWebComponents;exports.supportsWindow=w.supportsWindow;exports.Picked=D;exports.createClient=Ve;exports.getStepFields=Te;
package/dist/esm/index.js CHANGED
@@ -1,32 +1,32 @@
1
1
  var W = Object.defineProperty;
2
2
  var Y = (t, e, s) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
3
  var m = (t, e, s) => Y(t, typeof e != "symbol" ? e + "" : e, s);
4
- import { createDomain as I, createApi as F, createEffect as U, attach as J, sample as x, combine as C, createEvent as D } from "effector";
4
+ import { createDomain as F, createApi as I, createEffect as U, attach as J, sample as x, combine as C, createEvent as D } from "effector";
5
5
  import { createFactory as k, invoke as w } from "@withease/factories";
6
6
  import { g as _, t as Q, c as X, i as Z, e as E, a as ee, b as te, d as se } from "../experience-instance-C4INDX6a.js";
7
- import { f as vt } from "../experience-instance-C4INDX6a.js";
8
- import { l as S } from "../logger-C9a75KZn.js";
9
- import { c as B, l as $, s as O } from "../storage-BLmAhfhl.js";
7
+ import { f as St } from "../experience-instance-C4INDX6a.js";
8
+ import { l as v } from "../logger-C9a75KZn.js";
9
+ import { c as B, l as j, s as O } from "../storage-BLmAhfhl.js";
10
10
  import { a as kt } from "../storage-BLmAhfhl.js";
11
11
  import { g as re } from "../id-BW-g3y32.js";
12
12
  import { i as ne } from "../object-JwZ58NOH.js";
13
13
  import { s as L, a as ie, b as oe, c as ae, d as ce } from "../supports-BjhuLJ8z.js";
14
- import { h as bt, f as It, j as Ft, e as xt, g as Et, i as Pt, k as Rt } from "../supports-BjhuLJ8z.js";
15
- const H = I("experience"), ue = k(
14
+ import { h as bt, f as Ft, j as It, e as xt, g as Et, i as Pt, k as Rt } from "../supports-BjhuLJ8z.js";
15
+ const H = F("experience"), ue = k(
16
16
  ({ client: t, experience: e }) => {
17
- const s = H.store(e), n = F(s, {
17
+ const s = H.store(e), n = I(s, {
18
18
  merge(l, h) {
19
19
  return {
20
20
  ...l,
21
21
  ...h.experience
22
22
  };
23
23
  }
24
- }), i = s.map((l) => ({
24
+ }), o = s.map((l) => ({
25
25
  name: l.name,
26
26
  decisionLogic: l.condition ?? l.decide,
27
27
  targetSelectors: l.targets,
28
28
  initializeOpenLogic: e.initializeOpen
29
- })), c = t.components.listStore.map(
29
+ })), u = t.components.listStore.map(
30
30
  (l) => l.find((h) => h.name === `experience:${e.id}`) || l.find((h) => h.name === "experience"),
31
31
  { skipVoid: !1 }
32
32
  ), r = s.map((l) => ({
@@ -34,13 +34,13 @@ const H = I("experience"), ue = k(
34
34
  nodes: l.nodes,
35
35
  edges: l.edges,
36
36
  conditionals: l.conditionals
37
- })), o = e.actions ?? [];
37
+ })), i = e.actions ?? [];
38
38
  return {
39
39
  id: e.id,
40
- configStore: i,
40
+ configStore: o,
41
41
  treeStore: r,
42
- componentStore: c,
43
- actions: o,
42
+ componentStore: u,
43
+ actions: i,
44
44
  merge: n.merge
45
45
  };
46
46
  }
@@ -49,61 +49,61 @@ function le(t) {
49
49
  return w(ue, t);
50
50
  }
51
51
  const de = k(({ client: t }) => {
52
- const e = H.store({}), s = F(e, {
53
- register(r, o) {
52
+ const e = H.store({}), s = I(e, {
53
+ register(r, i) {
54
54
  return {
55
55
  ...r,
56
- [o.id]: o
56
+ [i.id]: i
57
57
  };
58
58
  }
59
59
  });
60
60
  function n(r) {
61
- const o = e.getState()[r.id];
62
- if (o) {
63
- o.merge({ experience: r, strategy: "override" });
61
+ const i = e.getState()[r.id];
62
+ if (i) {
63
+ i.merge({ experience: r, strategy: "override" });
64
64
  return;
65
65
  }
66
66
  const l = le({ client: t, experience: r });
67
67
  s.register(l);
68
68
  }
69
- const i = e.map((r) => Object.values(r));
70
- function c(r) {
71
- return e.map((o) => o[r], { skipVoid: !1 });
69
+ const o = e.map((r) => Object.values(r));
70
+ function u(r) {
71
+ return e.map((i) => i[r], { skipVoid: !1 });
72
72
  }
73
73
  return {
74
74
  register: n,
75
- getById: c,
76
- listStore: i
75
+ getById: u,
76
+ listStore: o
77
77
  };
78
78
  });
79
79
  function pe(t) {
80
80
  return w(de, t);
81
81
  }
82
- const fe = (t, e) => {
82
+ const ge = (t, e) => {
83
83
  e.register(t);
84
84
  }, G = (t, e) => {
85
85
  const { targetSelectors: s } = e.configStore.getState(), n = _(s, e.id);
86
86
  n.forEach(
87
- ({ elements: c }) => c.forEach((r) => Q(r, e.id))
88
- ), X(n, e.id).forEach((c) => {
89
- t.experienceInstances.spawn(e, c);
87
+ ({ elements: u }) => u.forEach((r) => Q(r, e.id))
88
+ ), X(n, e.id).forEach((u) => {
89
+ t.experienceInstances.spawn(e, u);
90
90
  });
91
91
  }, M = async (t) => {
92
92
  await Promise.all(
93
93
  t.experiences.listStore.getState().map(async (e) => {
94
- await ge(t, e) && G(t, e);
94
+ await fe(t, e) && G(t, e);
95
95
  })
96
96
  );
97
- }, ge = async (t, e) => {
97
+ }, fe = async (t, e) => {
98
98
  const { decisionLogic: s, targetSelectors: n } = e.configStore.getState();
99
99
  return _(n, e.id).length < 1 || n.length === 0 ? !1 : s && Z(s) ? await E(t, s) === !0 : !0;
100
100
  }, me = (t, e, s) => {
101
- const n = e.name, i = e.setup(t);
102
- if (i) {
103
- const c = s[n] ?? {};
104
- s[n] = Object.freeze({ ...c, ...i });
101
+ const n = e.name, o = e.setup(t);
102
+ if (o) {
103
+ const u = s[n] ?? {};
104
+ s[n] = Object.freeze({ ...u, ...o });
105
105
  }
106
- }, he = I("component"), ye = k(
106
+ }, he = F("component"), ye = k(
107
107
  ({ client: t, component: e, name: s }) => {
108
108
  const n = t.frameworks.getByName(e.frameworkName);
109
109
  return {
@@ -113,92 +113,92 @@ const fe = (t, e) => {
113
113
  };
114
114
  }
115
115
  );
116
- function ve(t) {
116
+ function Se(t) {
117
117
  return w(ye, t);
118
118
  }
119
- const Se = k(({ client: t }) => {
120
- const e = he.store({}), s = F(e, {
121
- register(r, o) {
119
+ const ve = k(({ client: t }) => {
120
+ const e = he.store({}), s = I(e, {
121
+ register(r, i) {
122
122
  return {
123
123
  ...r,
124
- [o.name]: o
124
+ [i.name]: i
125
125
  };
126
126
  }
127
127
  });
128
- function n(r, o) {
129
- e.getState()[r] && S(
128
+ function n(r, i) {
129
+ e.getState()[r] && v(
130
130
  "warn",
131
131
  `Component '${r}' already registered. Registering again will override the previous registration.`
132
132
  );
133
- const h = ve({ client: t, name: r, component: o });
133
+ const h = Se({ client: t, name: r, component: i });
134
134
  s.register(h);
135
135
  }
136
- const i = e.map((r) => Object.values(r));
137
- function c(r) {
138
- return e.map((o) => o[r], { skipVoid: !1 });
136
+ const o = e.map((r) => Object.values(r));
137
+ function u(r) {
138
+ return e.map((i) => i[r], { skipVoid: !1 });
139
139
  }
140
140
  return {
141
141
  register: n,
142
- getByName: c,
143
- listStore: i
142
+ getByName: u,
143
+ listStore: o
144
144
  };
145
145
  });
146
146
  function ke(t) {
147
- return w(Se, t);
147
+ return w(ve, t);
148
148
  }
149
149
  const V = (t, e, s) => {
150
150
  s.register(t, e);
151
- }, we = I("framework"), be = k(({ client: t }) => {
152
- const e = we.store({}), s = F(e, {
153
- register(r, o) {
151
+ }, we = F("framework"), be = k(({ client: t }) => {
152
+ const e = we.store({}), s = I(e, {
153
+ register(r, i) {
154
154
  return {
155
155
  ...r,
156
- [o.name]: o.framework
156
+ [i.name]: i.framework
157
157
  };
158
158
  }
159
159
  });
160
- function n(r, o) {
161
- e.getState()[r] && S(
160
+ function n(r, i) {
161
+ e.getState()[r] && v(
162
162
  "warn",
163
163
  `Framework '${r}' already registered. Registering again will override the previous registration.`
164
- ), s.register({ name: r, framework: o });
164
+ ), s.register({ name: r, framework: i });
165
165
  }
166
- const i = e.map((r) => Object.values(r));
167
- function c(r) {
168
- return e.map((o) => o[r], { skipVoid: !1 });
166
+ const o = e.map((r) => Object.values(r));
167
+ function u(r) {
168
+ return e.map((i) => i[r], { skipVoid: !1 });
169
169
  }
170
170
  return {
171
171
  register: n,
172
- getByName: c,
173
- listStore: i
172
+ getByName: u,
173
+ listStore: o
174
174
  };
175
175
  });
176
- function Ie(t) {
176
+ function Fe(t) {
177
177
  return w(be, t);
178
178
  }
179
- const Fe = (t, e) => {
179
+ const Ie = (t, e) => {
180
180
  e.register(t.name, t);
181
181
  }, xe = 6e3, Ee = B("last_ping", "global"), Pe = (t) => `${t}/api/v1/ping`, Re = async (t) => {
182
182
  try {
183
- const e = Date.now(), s = $.get(Ee);
183
+ const e = Date.now(), s = j.get(Ee);
184
184
  let n = 0;
185
185
  if (s.isSet() && (n = s.json() ?? 0), n && e - n < xe)
186
186
  return !0;
187
- const i = Pe(t.apiUrl), c = {
187
+ const o = Pe(t.apiUrl), u = {
188
188
  projectId: t.projectId,
189
189
  path: window.location.pathname
190
- }, r = JSON.stringify(c), o = {
190
+ }, r = JSON.stringify(u), i = {
191
191
  "Content-Type": "application/json"
192
192
  }, l = document.getElementById("picked_script"), h = l == null ? void 0 : l.dataset.verceltoken;
193
- h && (o["x-vercel-protection-bypass"] = h);
194
- const d = (await fetch(i, {
193
+ h && (i["x-vercel-protection-bypass"] = h);
194
+ const d = (await fetch(o, {
195
195
  method: "POST",
196
- headers: o,
196
+ headers: i,
197
197
  body: r
198
198
  })).ok;
199
199
  return d && s.set(e), d;
200
200
  } catch (e) {
201
- return S("error", e), !1;
201
+ return v("error", e), !1;
202
202
  }
203
203
  };
204
204
  function Be(t) {
@@ -213,57 +213,57 @@ function Be(t) {
213
213
  };
214
214
  return Object.freeze(s);
215
215
  }
216
- const je = I("predicate"), Ae = k(({ client: t }) => {
217
- const e = je.store({}), s = F(e, {
218
- register(r, o) {
216
+ const Ae = F("predicate"), $e = k(({ client: t }) => {
217
+ const e = Ae.store({}), s = I(e, {
218
+ register(r, i) {
219
219
  return {
220
220
  ...r,
221
- [o.name]: {
222
- name: o.name,
223
- predicate: o.predicate
221
+ [i.name]: {
222
+ name: i.name,
223
+ predicate: i.predicate
224
224
  }
225
225
  };
226
226
  }
227
227
  });
228
- function n(r, o) {
229
- e.getState()[r] && S(
228
+ function n(r, i) {
229
+ e.getState()[r] && v(
230
230
  "warn",
231
231
  `Predicate '${r}' already registered. Registering again will override the previous registration.`
232
- ), s.register(Object.freeze({ name: r, predicate: o }));
232
+ ), s.register(Object.freeze({ name: r, predicate: i }));
233
233
  }
234
- const i = e.map((r) => Object.values(r));
235
- function c(r) {
236
- return e.map((o) => o[r], { skipVoid: !1 });
234
+ const o = e.map((r) => Object.values(r));
235
+ function u(r) {
236
+ return e.map((i) => i[r], { skipVoid: !1 });
237
237
  }
238
238
  return {
239
239
  register: n,
240
- getByName: c,
241
- listStore: i
240
+ getByName: u,
241
+ listStore: o
242
242
  };
243
243
  });
244
- function $e(t) {
245
- return w(Ae, t);
244
+ function je(t) {
245
+ return w($e, t);
246
246
  }
247
247
  const Oe = (t, e, s) => {
248
248
  s.register(t, e);
249
- }, T = I("feature"), Ce = k(({ client: t }) => {
250
- const e = T.store({}), s = T.store([]), n = F(e, {
251
- register(d, u) {
249
+ }, T = F("feature"), Ce = k(({ client: t }) => {
250
+ const e = T.store({}), s = T.store([]), n = I(e, {
251
+ register(d, c) {
252
252
  return {
253
253
  ...d,
254
- [u.id]: u.feature
254
+ [c.id]: c.feature
255
255
  };
256
256
  }
257
257
  });
258
- function i(d, u) {
259
- e.getState()[d] && S(
258
+ function o(d, c) {
259
+ e.getState()[d] && v(
260
260
  "warn",
261
261
  `Feature '${d}' already registered. Registering again will override the previous registration.`
262
262
  );
263
263
  const p = {
264
264
  id: d,
265
265
  feature: {
266
- ...u,
266
+ ...c,
267
267
  id: d
268
268
  }
269
269
  };
@@ -274,66 +274,66 @@ const Oe = (t, e, s) => {
274
274
  })
275
275
  );
276
276
  }
277
- const c = U(
277
+ const u = U(
278
278
  async ({
279
279
  id: d,
280
- key: u,
280
+ key: c,
281
281
  storage: a = "local"
282
282
  }) => {
283
- const p = B(`feature:${d}:${u}`, "global"), f = (a === "session" ? O : $).get(p).boolean();
284
- return f === null ? null : { id: d, key: u, bucket: f, storage: a };
283
+ const p = B(`feature:${d}:${c}`, "global"), g = (a === "session" ? O : j).get(p).boolean();
284
+ return g === null ? null : { id: d, key: c, bucket: g, storage: a };
285
285
  }
286
286
  ), r = U((d) => {
287
287
  if (!d)
288
288
  return null;
289
- const u = B(`feature:${d.id}:${d.key}`, "global");
290
- (d.storage === "session" ? O : $).set(u, d.bucket);
291
- }), o = /* @__PURE__ */ new Map(), l = J({
289
+ const c = B(`feature:${d.id}:${d.key}`, "global");
290
+ (d.storage === "session" ? O : j).set(c, d.bucket);
291
+ }), i = /* @__PURE__ */ new Map(), l = J({
292
292
  source: { allFeaturesStore: e, resolvedFeaturesStore: s },
293
- effect: async ({ allFeaturesStore: d, resolvedFeaturesStore: u }, { id: a, decide: p, key: g }) => {
294
- const f = u.find(
295
- (A) => A.id === a && A.key === g
293
+ effect: async ({ allFeaturesStore: d, resolvedFeaturesStore: c }, { id: a, decide: p, key: f }) => {
294
+ const g = c.find(
295
+ ($) => $.id === a && $.key === f
296
296
  );
297
- if (f)
298
- return f;
297
+ if (g)
298
+ return g;
299
299
  const y = d[a];
300
300
  if (!y)
301
301
  throw new Error(`Feature with id '${a}' not found`);
302
- const b = o.get(`${a}:${g}`);
302
+ const b = i.get(`${a}:${f}`);
303
303
  if (b !== void 0) {
304
- const A = await b;
305
- return { id: y.id, bucket: A, key: g, storage: y.feature.storage };
304
+ const $ = await b;
305
+ return { id: y.id, bucket: $, key: f, storage: y.feature.storage };
306
306
  }
307
- const j = p();
308
- o.set(`${a}:${g}`, j);
309
- const P = await j;
310
- return { id: y.id, bucket: P, key: g, storage: y.feature.storage };
307
+ const A = p();
308
+ i.set(`${a}:${f}`, A);
309
+ const P = await A;
310
+ return { id: y.id, bucket: P, key: f, storage: y.feature.storage };
311
311
  }
312
312
  });
313
313
  x({
314
314
  clock: n.register,
315
315
  fn: (d) => {
316
- const { id: u, feature: a } = d;
317
- return { id: u, key: a.feature.key, storage: a.feature.storage };
316
+ const { id: c, feature: a } = d;
317
+ return { id: c, key: a.feature.key, storage: a.feature.storage };
318
318
  },
319
- target: c
319
+ target: u
320
320
  }), x({
321
321
  source: e,
322
322
  clock: l.doneData,
323
- fn: (d, u) => {
323
+ fn: (d, c) => {
324
324
  var y;
325
- const { id: a, bucket: p, storage: g } = u, f = (y = d[a]) == null ? void 0 : y.feature.key;
326
- return f ? { key: f, id: a, bucket: p, storage: g } : null;
325
+ const { id: a, bucket: p, storage: f } = c, g = (y = d[a]) == null ? void 0 : y.feature.key;
326
+ return g ? { key: g, id: a, bucket: p, storage: f } : null;
327
327
  },
328
328
  target: r
329
329
  });
330
330
  const h = C({ allFeaturesStore: e, resolvedFeaturesStore: s }).map(
331
331
  ({
332
332
  allFeaturesStore: d,
333
- resolvedFeaturesStore: u
333
+ resolvedFeaturesStore: c
334
334
  }) => Object.values(d).map((a) => {
335
- const p = u.find(
336
- (g) => g.id === a.id && g.key === a.feature.key
335
+ const p = c.find(
336
+ (f) => f.id === a.id && f.key === a.feature.key
337
337
  );
338
338
  return p ? {
339
339
  id: a.id,
@@ -353,28 +353,28 @@ const Oe = (t, e, s) => {
353
353
  x({
354
354
  clock: l.doneData,
355
355
  source: { resolvedFeatures: s },
356
- filter: ({ resolvedFeatures: d }, { id: u, key: a }) => !d.some(
357
- (g) => g.id === u && g.key === a
356
+ filter: ({ resolvedFeatures: d }, { id: c, key: a }) => !d.some(
357
+ (f) => f.id === c && f.key === a
358
358
  ),
359
- fn: (d, u) => u,
359
+ fn: (d, c) => c,
360
360
  target: t.eventBus.prepend((d) => ({
361
361
  type: "feature_decide",
362
362
  feature: d
363
363
  }))
364
364
  }), x({
365
- clock: [c.doneData, l.doneData],
365
+ clock: [u.doneData, l.doneData],
366
366
  source: s,
367
- fn: (d, u) => !u || d.some(
368
- (p) => p.id === u.id && p.key === u.key
369
- ) ? d : [...d, u],
367
+ fn: (d, c) => !c || d.some(
368
+ (p) => p.id === c.id && p.key === c.key
369
+ ) ? d : [...d, c],
370
370
  target: s
371
371
  });
372
- function v(d) {
373
- return e.map((u) => u[d], { skipVoid: !1 });
372
+ function S(d) {
373
+ return e.map((c) => c[d], { skipVoid: !1 });
374
374
  }
375
375
  return {
376
- register: i,
377
- getByName: v,
376
+ register: o,
377
+ getByName: S,
378
378
  listStore: h
379
379
  };
380
380
  });
@@ -383,7 +383,7 @@ function De(t) {
383
383
  }
384
384
  const Ue = (t, e, s) => {
385
385
  s.register(t, e);
386
- }, R = I("history");
386
+ }, R = F("history");
387
387
  function N(t, e) {
388
388
  return {
389
389
  // eslint-disable-next-line sonarjs/pseudo-random
@@ -394,20 +394,20 @@ function N(t, e) {
394
394
  };
395
395
  }
396
396
  const Me = k(() => {
397
- const t = R.store({ entries: [] }), e = R.event(), s = R.event(), n = R.event(), i = R.event();
398
- t.on(e, (r, o) => ({
399
- entries: [...r.entries, N(o.experienceId, o.node)]
400
- })), t.on(s, (r, o) => ({
397
+ const t = R.store({ entries: [] }), e = R.event(), s = R.event(), n = R.event(), o = R.event();
398
+ t.on(e, (r, i) => ({
399
+ entries: [...r.entries, N(i.experienceId, i.node)]
400
+ })), t.on(s, (r, i) => ({
401
401
  entries: [
402
402
  ...r.entries.slice(0, -1),
403
- N(o.experienceId, o.node)
403
+ N(i.experienceId, i.node)
404
404
  ]
405
- })), t.on(i, (r, o) => o);
406
- function c(r, o) {
405
+ })), t.on(o, (r, i) => i);
406
+ function u(r, i) {
407
407
  const l = { lastStepIndex: -1, secondLastStepIndex: -1 };
408
408
  for (let h = r.length - 1; h >= 0; h--) {
409
- const v = r[h], d = v == null ? void 0 : v.node;
410
- if (!(!d || !ee(d)) && !(o && (v == null ? void 0 : v.experienceId) !== o))
409
+ const S = r[h], d = S == null ? void 0 : S.node;
410
+ if (!(!d || !ee(d)) && !(i && (S == null ? void 0 : S.experienceId) !== i))
411
411
  if (l.lastStepIndex === -1)
412
412
  l.lastStepIndex = h;
413
413
  else {
@@ -417,8 +417,8 @@ const Me = k(() => {
417
417
  }
418
418
  return l;
419
419
  }
420
- return t.on(n, (r, o) => {
421
- const { secondLastStepIndex: l } = c(r.entries, o.experienceId), h = l !== -1 ? r.entries.slice(0, l + 1) : r.entries;
420
+ return t.on(n, (r, i) => {
421
+ const { secondLastStepIndex: l } = u(r.entries, i.experienceId), h = l !== -1 ? r.entries.slice(0, l + 1) : r.entries;
422
422
  return {
423
423
  ...r,
424
424
  entries: h
@@ -427,19 +427,19 @@ const Me = k(() => {
427
427
  push: e,
428
428
  replace: s,
429
429
  back: n,
430
- restore: i,
430
+ restore: o,
431
431
  entriesStore: t.map((r) => r.entries)
432
432
  };
433
433
  });
434
434
  function Ve() {
435
435
  return w(Me);
436
436
  }
437
- const Te = () => D(), Ne = I("field"), ze = k(() => {
438
- const t = Ne.store({}), e = F(t, {
439
- register(r, o) {
437
+ const Te = () => D(), Ne = F("field"), ze = k(() => {
438
+ const t = Ne.store({}), e = I(t, {
439
+ register(r, i) {
440
440
  return {
441
441
  ...r,
442
- [o.field.id]: o.field
442
+ [i.field.id]: i.field
443
443
  };
444
444
  }
445
445
  });
@@ -447,17 +447,17 @@ const Te = () => D(), Ne = I("field"), ze = k(() => {
447
447
  e.register({ field: r });
448
448
  }
449
449
  const n = t.map((r) => Object.values(r));
450
- function i(r) {
451
- return t.map((o) => o[r] || null);
450
+ function o(r) {
451
+ return t.map((i) => i[r] || null);
452
452
  }
453
- function c(r) {
454
- return t.map((o) => Object.values(o).find((l) => l.name === r) || null);
453
+ function u(r) {
454
+ return t.map((i) => Object.values(i).find((l) => l.name === r) || null);
455
455
  }
456
456
  return {
457
457
  register: s,
458
- getById: i,
458
+ getById: o,
459
459
  listStore: n,
460
- getByName: c
460
+ getByName: u
461
461
  };
462
462
  });
463
463
  function _e() {
@@ -465,11 +465,11 @@ function _e() {
465
465
  }
466
466
  const Le = (t, e) => {
467
467
  e.register(t);
468
- }, He = I("action"), Ge = k(() => {
469
- const t = He.store({}), e = F(t, {
470
- register(c, r) {
468
+ }, He = F("action"), Ge = k(() => {
469
+ const t = He.store({}), e = I(t, {
470
+ register(u, r) {
471
471
  return {
472
- ...c,
472
+ ...u,
473
473
  [r.name]: {
474
474
  name: r.name,
475
475
  action: r.action
@@ -477,16 +477,16 @@ const Le = (t, e) => {
477
477
  };
478
478
  }
479
479
  });
480
- function s(c, r) {
481
- e.register({ name: c, action: r });
480
+ function s(u, r) {
481
+ e.register({ name: u, action: r });
482
482
  }
483
- const n = t.map((c) => Object.values(c));
484
- function i(c) {
485
- return t.map((r) => r[c], { skipVoid: !1 });
483
+ const n = t.map((u) => Object.values(u));
484
+ function o(u) {
485
+ return t.map((r) => r[u], { skipVoid: !1 });
486
486
  }
487
487
  return {
488
488
  register: s,
489
- getByName: i,
489
+ getByName: o,
490
490
  listStore: n
491
491
  };
492
492
  });
@@ -499,56 +499,56 @@ const qe = (t, e, s) => {
499
499
  function z(t) {
500
500
  return typeof t > "u" || t === null || t === "" || Array.isArray(t) && !t.length;
501
501
  }
502
- const We = I("response"), Ye = k(({ client: t }) => {
503
- const e = We.store({}), s = D(), n = D(), i = F(e, {
504
- register(u, a) {
502
+ const We = F("response"), Ye = k(({ client: t }) => {
503
+ const e = We.store({}), s = D(), n = D(), o = I(e, {
504
+ register(c, a) {
505
505
  return {
506
- ...u,
506
+ ...c,
507
507
  [a.fieldId]: a.response
508
508
  };
509
509
  },
510
- registerBatch(u, a) {
510
+ registerBatch(c, a) {
511
511
  return {
512
- ...u,
512
+ ...c,
513
513
  ...a
514
514
  };
515
515
  },
516
- clear(u, a) {
517
- const { [a]: p, ...g } = u;
518
- return g;
516
+ clear(c, a) {
517
+ const { [a]: p, ...f } = c;
518
+ return f;
519
519
  },
520
520
  clearAll() {
521
521
  return {};
522
522
  }
523
523
  });
524
- function c(u, a) {
525
- i.register({ fieldId: u, response: a });
524
+ function u(c, a) {
525
+ o.register({ fieldId: c, response: a });
526
526
  }
527
- async function r(u) {
527
+ async function r(c) {
528
528
  const a = [];
529
529
  return await Promise.allSettled(
530
- Object.entries(u).map(async ([p, g]) => {
531
- let f = g;
530
+ Object.entries(c).map(async ([p, f]) => {
531
+ let g = f;
532
532
  const y = t.fields.getById(p).getState();
533
533
  if (!y) {
534
534
  a.push({
535
535
  fieldId: p,
536
536
  userMessage: `Field '${p}' not found`,
537
537
  systemMessage: `No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
538
- value: f
538
+ value: g
539
539
  });
540
540
  return;
541
541
  }
542
- if (y.multiple && (typeof f == "string" || typeof f == "number" || typeof f == "boolean") && (f = [f]), y.validation && !ne(y.validation) && !z(f)) {
542
+ if (y.multiple && (typeof g == "string" || typeof g == "number" || typeof g == "boolean") && (g = [g]), y.validation && !ne(y.validation) && !z(g)) {
543
543
  const b = await E(t, y.validation, {
544
- $input: f
544
+ $input: g
545
545
  });
546
546
  if (typeof b == "string") {
547
547
  a.push({
548
548
  fieldId: p,
549
549
  userMessage: b,
550
550
  systemMessage: `Field validation resulted in an error: ${b}.`,
551
- value: f
551
+ value: g
552
552
  });
553
553
  return;
554
554
  }
@@ -557,82 +557,82 @@ const We = I("response"), Ye = k(({ client: t }) => {
557
557
  fieldId: p,
558
558
  userMessage: "This field is invalid",
559
559
  systemMessage: "Field validation resulted in an unspecified error.",
560
- value: f
560
+ value: g
561
561
  });
562
562
  return;
563
563
  }
564
564
  }
565
- if (y.required && z(f)) {
565
+ if (y.required && z(g)) {
566
566
  a.push({
567
567
  fieldId: p,
568
568
  userMessage: "This field is required",
569
569
  systemMessage: "Field is required.",
570
- value: f
570
+ value: g
571
571
  });
572
572
  return;
573
573
  }
574
- if (!y.multiple && Array.isArray(f) && f.length > 1) {
574
+ if (!y.multiple && Array.isArray(g) && g.length > 1) {
575
575
  a.push({
576
576
  fieldId: p,
577
577
  userMessage: "This field expects a single response",
578
578
  systemMessage: "Field expects a single response.",
579
- value: f
579
+ value: g
580
580
  });
581
581
  return;
582
582
  }
583
583
  if (y.options) {
584
- const b = y.options.map((P) => P.value), j = Array.isArray(f) ? f : [f];
585
- Array.isArray(f) && (j.every((P) => b.includes(P)) || a.push({
584
+ const b = y.options.map((P) => P.value), A = Array.isArray(g) ? g : [g];
585
+ Array.isArray(g) && (A.every((P) => b.includes(P)) || a.push({
586
586
  fieldId: p,
587
587
  userMessage: "This field expects a valid option",
588
588
  systemMessage: `Field expects a valid option. Valid options are: ${b.join(", ")}`,
589
- value: f
589
+ value: g
590
590
  }));
591
591
  }
592
592
  })
593
- ), { responsesToCommit: u, validationErrors: a };
593
+ ), { responsesToCommit: c, validationErrors: a };
594
594
  }
595
- async function o(u) {
596
- const { responsesToCommit: a, validationErrors: p } = await r(u);
597
- return p.length ? { errors: p } : (i.registerBatch(a), { errors: [] });
595
+ async function i(c) {
596
+ const { responsesToCommit: a, validationErrors: p } = await r(c);
597
+ return p.length ? { errors: p } : (o.registerBatch(a), { errors: [] });
598
598
  }
599
- const l = e.map((u) => u), h = e.map((u) => Object.keys(u).map((p) => ({
599
+ const l = e.map((c) => c), h = e.map((c) => Object.keys(c).map((p) => ({
600
600
  fieldId: p,
601
- value: u[p]
601
+ value: c[p]
602
602
  })));
603
- function v(u) {
604
- const a = t.fields.getById(u), p = e.map((g) => g[u] || null);
605
- return C({ f: a, r: p }, ({ f: g, r: f }) => f || (g != null && g.defaultValue ? g.defaultValue : null));
606
- }
607
- function d(u) {
608
- const a = t.fields.getByName(u);
609
- return C({ f: a, s: e }, ({ f: p, s: g }) => {
610
- const f = p && g[p.id] || null;
611
- return f || (p != null && p.defaultValue ? p.defaultValue : null);
603
+ function S(c) {
604
+ const a = t.fields.getById(c), p = e.map((f) => f[c] || null);
605
+ return C({ f: a, r: p }, ({ f, r: g }) => g || (f != null && f.defaultValue ? f.defaultValue : null));
606
+ }
607
+ function d(c) {
608
+ const a = t.fields.getByName(c);
609
+ return C({ f: a, s: e }, ({ f: p, s: f }) => {
610
+ const g = p && f[p.id] || null;
611
+ return g || (p != null && p.defaultValue ? p.defaultValue : null);
612
612
  });
613
613
  }
614
614
  return x({
615
615
  clock: s,
616
- target: i.clearAll
616
+ target: o.clearAll
617
617
  }), x({
618
618
  clock: n,
619
- target: i.clear
619
+ target: o.clear
620
620
  }), {
621
- register: c,
621
+ register: u,
622
622
  clearAll: s,
623
623
  clear: n,
624
- commit: o,
624
+ commit: i,
625
625
  getResponsesToCommit: r,
626
626
  listStore: h,
627
627
  getAllStore: l,
628
- getByFieldId: v,
628
+ getByFieldId: S,
629
629
  getByFieldName: d
630
630
  };
631
631
  });
632
632
  function Je(t) {
633
633
  return w(Ye, t);
634
634
  }
635
- const Qe = () => "0.0.1-dev.1764952778408";
635
+ const Qe = () => "0.0.1-dev.1765227621508";
636
636
  function Xe() {
637
637
  if (L()) {
638
638
  const t = [
@@ -652,19 +652,19 @@ function Ze() {
652
652
  if (!ie())
653
653
  return {};
654
654
  const t = new URLSearchParams(window.location.search), e = {}, s = /* @__PURE__ */ new Set();
655
- for (const [i] of t.entries())
656
- i.startsWith("picked-") && s.add(i);
657
- for (const i of s) {
658
- const c = i.replace("picked-", "");
659
- e[c] = t.getAll(i);
655
+ for (const [o] of t.entries())
656
+ o.startsWith("picked-") && s.add(o);
657
+ for (const o of s) {
658
+ const u = o.replace("picked-", "");
659
+ e[u] = t.getAll(o);
660
660
  }
661
661
  const n = B("s");
662
662
  if (s.size > 0)
663
663
  O.set(n, e);
664
664
  else {
665
- const i = O.get(n);
666
- if (i)
667
- return i.json() || {};
665
+ const o = O.get(n);
666
+ if (o)
667
+ return o.json() || {};
668
668
  }
669
669
  return e;
670
670
  }
@@ -675,27 +675,14 @@ function et() {
675
675
  return `${t}-${e}-${s}-${n}`;
676
676
  }
677
677
  const tt = B("session", "global"), st = () => {
678
- const t = $.get(tt);
678
+ const t = j.get(tt);
679
679
  let e;
680
680
  t.isSet() && (e = t.json());
681
- const s = (i) => t.set({
682
- id: i.id,
683
- isUser: i.isUser,
684
- identifiers: i.identifiers
685
- }), n = {
681
+ const s = (o) => t.set({ id: o.id, isUser: o.isUser }), n = {
686
682
  id: (e == null ? void 0 : e.id) ?? et(),
687
683
  isUser: (e == null ? void 0 : e.isUser) ?? void 0,
688
- identifiers: (e == null ? void 0 : e.identifiers) ?? void 0,
689
- setIsUser(i) {
690
- this.isUser = i, s(this);
691
- },
692
- setIdentifier(i, c) {
693
- this.identifiers = { ...this.identifiers ?? {}, [i]: c }, s(this);
694
- },
695
- removeIdentifier(i) {
696
- if (!this.identifiers) return;
697
- const { [i]: c, ...r } = this.identifiers;
698
- this.identifiers = Object.keys(r).length ? r : void 0, s(this);
684
+ setIsUser(o) {
685
+ this.isUser = o, s(this);
699
686
  }
700
687
  };
701
688
  return s(n), n;
@@ -718,13 +705,13 @@ class K {
718
705
  m(this, "components", ke({ client: this }));
719
706
  m(this, "experienceInstances", te({ client: this }));
720
707
  m(this, "experiences", pe({ client: this }));
721
- m(this, "frameworks", Ie({ client: this }));
722
- m(this, "predicates", $e({ client: this }));
708
+ m(this, "frameworks", Fe({ client: this }));
709
+ m(this, "predicates", je({ client: this }));
723
710
  m(this, "features", De({ client: this }));
724
711
  m(this, "responses", Je({ client: this }));
725
712
  m(this, "fields", _e());
726
713
  m(this, "actions", Ke());
727
- S("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Xe(), this.session = rt(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: Qe() }), S("info", "Picked client initialized.");
714
+ v("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Xe(), this.session = rt(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: Qe() }), v("info", "Picked client initialized.");
728
715
  }
729
716
  start() {
730
717
  Re(this), (async () => {
@@ -734,16 +721,16 @@ class K {
734
721
  typeof this.precondition > "u" ? s = !0 : typeof this.precondition == "boolean" ? s = this.precondition : s = await E(this, this.precondition) === !0;
735
722
  let n;
736
723
  s && (this.condition === void 0 ? n = !0 : typeof this.condition == "boolean" ? n = this.condition : n = await E(this, this.condition) === !0);
737
- const i = s && n === !0;
724
+ const o = s && n === !0;
738
725
  if (typeof n == "boolean" && this.session) {
739
- const c = n;
740
- this.session.setIsUser(c), this.eventBus({ type: "user_decide", value: c });
726
+ const u = n;
727
+ this.session.setIsUser(u), this.eventBus({ type: "user_decide", value: u });
741
728
  }
742
- this.eventBus({ type: "initialize" }), document.body && i && M(this), await se(), i && M(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session });
729
+ this.eventBus({ type: "initialize" }), document.body && o && M(this), await se(), o && M(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session });
743
730
  })();
744
731
  }
745
732
  registerFramework(e) {
746
- Fe(e, this.frameworks);
733
+ Ie(e, this.frameworks);
747
734
  }
748
735
  registerComponent(e, s) {
749
736
  V(e, s, this.components);
@@ -764,7 +751,7 @@ class K {
764
751
  qe(e, s, this.actions);
765
752
  }
766
753
  registerExperience(e) {
767
- e.component && V(`experience:${e.id}`, e.component, this.components), fe(e, this.experiences);
754
+ e.component && V(`experience:${e.id}`, e.component, this.components), ge(e, this.experiences);
768
755
  }
769
756
  getStateSnapshot() {
770
757
  return Be(this);
@@ -772,7 +759,7 @@ class K {
772
759
  async launchExperienceById(e) {
773
760
  const s = this.experiences.getById(e).getState();
774
761
  if (!s) {
775
- S("warn", `Experience with id '${e}' not found.`);
762
+ v("warn", `Experience with id '${e}' not found.`);
776
763
  return;
777
764
  }
778
765
  G(this, s);
@@ -790,14 +777,14 @@ class K {
790
777
  var e;
791
778
  (e = this.options.plugins) == null || e.forEach((s) => {
792
779
  if (Array.isArray(s)) {
793
- s.forEach((i) => {
794
- this.registerPlugin(i);
780
+ s.forEach((o) => {
781
+ this.registerPlugin(o);
795
782
  });
796
783
  return;
797
784
  }
798
785
  const n = typeof s == "function" ? s() : s;
799
786
  if (Array.isArray(n)) {
800
- n.forEach((i) => this.registerPlugin(i));
787
+ n.forEach((o) => this.registerPlugin(o));
801
788
  return;
802
789
  }
803
790
  this.registerPlugin(n);
@@ -806,20 +793,20 @@ class K {
806
793
  setupFeatures() {
807
794
  const e = this.options.features;
808
795
  e && (Object.entries(e).forEach(([s, n]) => {
809
- const i = typeof n == "function" ? n() : n;
810
- this.registerFeature(s, i);
796
+ const o = typeof n == "function" ? n() : n;
797
+ this.registerFeature(s, o);
811
798
  }), this.searchParams.feature && this.searchParams.feature.forEach((s) => {
812
799
  try {
813
- const [n, i] = s.split(":");
814
- if (!n || !i)
800
+ const [n, o] = s.split(":");
801
+ if (!n || !o)
815
802
  return;
816
- let c = i;
817
- c === "true" && (c = !0), c === "false" && (c = !1), this.registerFeature(n, {
818
- key: `${c}`,
803
+ let u = o;
804
+ u === "true" && (u = !0), u === "false" && (u = !1), this.registerFeature(n, {
805
+ key: `${u}`,
819
806
  // use the assigned bucket value as the key
820
807
  name: n,
821
808
  // eslint-disable-next-line sonarjs/function-return-type
822
- decide: () => c,
809
+ decide: () => u,
823
810
  storage: "session"
824
811
  });
825
812
  } catch {
@@ -830,7 +817,7 @@ class K {
830
817
  const e = this.options.predicates;
831
818
  e && Object.entries(e).forEach(([s, n]) => {
832
819
  if (typeof n != "function") {
833
- S("warn", `Predicate "${s}" is not a function.`);
820
+ v("warn", `Predicate "${s}" is not a function.`);
834
821
  return;
835
822
  }
836
823
  this.registerPredicate(s, n);
@@ -840,7 +827,7 @@ class K {
840
827
  const e = this.options.actions;
841
828
  e && Object.entries(e).forEach(([s, n]) => {
842
829
  if (typeof n != "function") {
843
- S("warn", `Action "${s}" is not a function.`);
830
+ v("warn", `Action "${s}" is not a function.`);
844
831
  return;
845
832
  }
846
833
  this.registerAction(s, n);
@@ -850,7 +837,7 @@ class K {
850
837
  return this.plugins[e] ?? {};
851
838
  }
852
839
  }
853
- m(K, "logger", S);
840
+ m(K, "logger", v);
854
841
  function q(t) {
855
842
  var e;
856
843
  return ((e = t.options) == null ? void 0 : e.some((s) => "condition" in s)) ?? !1;
@@ -858,7 +845,7 @@ function q(t) {
858
845
  function nt(t) {
859
846
  return t.some((e) => e.condition || q(e));
860
847
  }
861
- async function gt(t, e) {
848
+ async function ft(t, e) {
862
849
  return e.length === 0 || !nt(e) ? e : (await Promise.all(
863
850
  e.map(async (n) => {
864
851
  if (!(n.condition ? await E(t, n.condition) : !0))
@@ -881,16 +868,16 @@ export {
881
868
  mt as createClient,
882
869
  B as createStorageKey,
883
870
  E as evaluateRuleLogic,
884
- gt as getStepFields,
885
- vt as isPickedRoot,
886
- $ as localStore,
871
+ ft as getStepFields,
872
+ St as isPickedRoot,
873
+ j as localStore,
887
874
  O as sessionStore,
888
875
  kt as subscribe,
889
876
  bt as supportsCookies,
890
877
  ae as supportsCryptoRandomUUID,
891
878
  L as supportsDocument,
892
- It as supportsHistory,
893
- Ft as supportsIntersectionObserver,
879
+ Ft as supportsHistory,
880
+ It as supportsIntersectionObserver,
894
881
  oe as supportsLocalStorage,
895
882
  xt as supportsLocation,
896
883
  Et as supportsSessionStorage,
@@ -1,12 +1,9 @@
1
1
  export interface Session {
2
2
  id: string;
3
3
  isUser?: boolean;
4
- identifiers?: Record<string, string>;
5
4
  }
6
5
  export interface SessionStore extends Session {
7
6
  setIsUser: (value: boolean) => void;
8
- setIdentifier: (key: string, value: string) => void;
9
- removeIdentifier: (key: string) => void;
10
7
  }
11
8
  export declare const initialiseSession: () => SessionStore | null;
12
9
  //# sourceMappingURL=user-session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-session.d.ts","sourceRoot":"","sources":["../../../src/utils/user-session.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACnC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACnD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AA4DD,eAAO,MAAM,iBAAiB,2BAI7B,CAAA"}
1
+ {"version":3,"file":"user-session.d.ts","sourceRoot":"","sources":["../../../src/utils/user-session.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACpC;AA6CD,eAAO,MAAM,iBAAiB,2BAI7B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.1-dev.1764952778408",
3
+ "version": "0.0.1-dev.1765227621508",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },