@picked/client 0.0.1-next.1 → 0.0.1
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 +1 -1
- package/dist/esm/index.js +305 -298
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var L=Object.defineProperty;var V=(t,e,s)=>e in t?L(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var h=(t,e,s)=>V(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("effector"),S=require("@withease/factories"),w=require("../experience-instance-6ZKZS7dF.cjs"),b=require("../logger-BsmHUUw1.cjs"),v=require("../storage-BPJwmlva.cjs"),T=require("../id-BKIWbSTy.cjs"),M=require("../object-BbFTsGh3.cjs"),k=require("../supports-C0y3-V5V.cjs"),$=f.createDomain("experience"),N=S.createFactory(({client:t,experience:e})=>{const s=$.store(e),o=f.createApi(s,{merge(n,m){return{...n,...m.experience}}}),i=s.map(n=>({type:n.type,name:n.name,decisionLogic:n.decide,targetSelectors:n.targets})),u=t.components.listStore.map(n=>n.find(m=>m.name===`experience:${e.id}`)||n.find(m=>m.name==="experience"),{skipVoid:!1}),r=s.map(n=>({steps:n.steps,nodes:n.nodes,edges:n.edges,conditionals:n.conditionals}));return{id:e.id,configStore:i,treeStore:r,componentStore:u,merge:o.merge}});function z(t){return S.invoke(N,t)}const K=S.createFactory(({client:t})=>{const e=$.store({}),s=f.createApi(e,{register(r,n){return{...r,[n.id]:n}}});function o(r){const n=e.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const m=z({client:t,experience:r});s.register(m)}const i=e.map(r=>Object.values(r));function u(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getById:u,listStore:i}});function q(t){return S.invoke(K,t)}const _=(t,e)=>{e.register(t)},O=(t,e)=>{const{targetSelectors:s}=e.configStore.getState(),o=w.getTargetElements(s,e.id);o.forEach(({elements:u})=>u.forEach(r=>w.tagTargetElement(r,e.id))),w.createAppHosts(o).forEach(u=>{t.experienceInstances.spawn(e,u)})},j=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await H(t,e)&&O(t,e)}))},H=async(t,e)=>{const{type:s,decisionLogic:o,targetSelectors:i}=e.configStore.getState();return w.getTargetElements(i,e.id).length<1?!1:s==="funnel"?o?await w.evaluateRuleLogic(t,o)===!0:!1:i.length===0?!1:w.isRulesLogic(o)?await w.evaluateRuleLogic(t,o)===!0:!0},U=(t,e,s)=>{const o=e.name,i=e.setup(t);if(i){const u=s[o]??{};s[o]=Object.freeze({...u,...i})}},W=f.createDomain("component"),G=S.createFactory(({client:t,component:e,name:s})=>{const o=t.frameworks.getByName(e.frameworkName);return{name:s,component:e,frameworkStore:o}});function J(t){return S.invoke(G,t)}const Y=S.createFactory(({client:t})=>{const e=W.store({}),s=f.createApi(e,{register(r,n){return{...r,[n.name]:n}}});function o(r,n){e.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const c=J({client:t,name:r,component:n});s.register(c)}const i=e.map(r=>Object.values(r));function u(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:u,listStore:i}});function Q(t){return S.invoke(Y,t)}const A=(t,e,s)=>{s.register(t,e)},X=f.createDomain("framework"),Z=S.createFactory(({client:t})=>{const e=X.store({}),s=f.createApi(e,{register(r,n){return{...r,[n.name]:n.framework}}});function o(r,n){e.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),s.register({name:r,framework:n})}const i=e.map(r=>Object.values(r));function u(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:u,listStore:i}});function ee(t){return S.invoke(Z,t)}const te=(t,e)=>{e.register(t.name,t)},re=6e3,B=v.createStorageKey("last_ping","global"),se=t=>`${t}/api/v1/ping`,ne=async t=>{try{const e=Date.now(),s=localStorage.getItem(B);if(s&&e-parseInt(s)<re)return!0;const o=se(t.apiUrl),i={projectId:t.projectId,path:window.location.pathname},u=JSON.stringify(i),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),m=n==null?void 0:n.dataset.verceltoken;m&&(r["x-vercel-protection-bypass"]=m);const l=(await fetch(o,{method:"POST",headers:r,body:u})).ok;return l&&localStorage.setItem(B,e.toString()),l}catch(e){return b.logger("error",e),!1}};function oe(t){const e=typeof window<"u",s={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(s)}const ie=f.createDomain("predicate"),ae=S.createFactory(({client:t})=>{const e=ie.store({}),s=f.createApi(e,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function o(r,n){e.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),s.register(Object.freeze({name:r,predicate:n}))}const i=e.map(r=>Object.values(r));function u(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:u,listStore:i}});function ce(t){return S.invoke(ae,t)}const ue=(t,e,s)=>{s.register(t,e)},D=f.createDomain("feature"),le=S.createFactory(()=>{const t=D.store({}),e=D.store([]),s=f.createApi(t,{register(c,l){return{...c,[l.id]:l.feature}}});function o(c,l){t.getState()[c]&&b.logger("warn",`Feature '${c}' already registered. Registering again will override the previous registration.`);const d={id:c,feature:{...l,id:c}};s.register(Object.freeze({id:c,feature:d}))}const i=f.createEffect(async({id:c,key:l,storage:a="local"})=>{const d=v.createStorageKey(`feature:${c}:${l}`,"global"),y=(a==="session"?v.sessionStore:v.localStore).get(d).boolean();if(y!==null)return{id:c,bucket:y}}),u=f.createEffect(c=>{if(!c)return null;const l=v.createStorageKey(`feature:${c.id}:${c.key}`,"global");(c.storage==="session"?v.sessionStore:v.localStore).set(l,c.bucket)}),r=f.attach({source:{allFeaturesStore:t,resolvedFeaturesStore:e},effect:async({allFeaturesStore:c,resolvedFeaturesStore:l},{id:a,decide:d})=>{const g=l.find(F=>F.id===a);if(g)return g;const y=c[a];if(!y)throw new Error(`Feature with id '${a}' not found`);const p=await d();return{id:y.id,bucket:p,storage:y.feature.storage}}});f.sample({clock:s.register,fn:c=>{const{id:l,feature:a}=c;return{id:l,key:a.feature.key,storage:a.feature.storage}},target:i}),f.sample({source:e,clock:[i.doneData,r.doneData],fn:(c,l)=>!l||c.some(a=>a.id===l.id)?c:[...c,l],target:e}),f.sample({source:t,clock:r.doneData,fn:(c,l)=>{var p;const{id:a,bucket:d,storage:g}=l,y=(p=c[a])==null?void 0:p.feature.key;return y?{key:y,id:a,bucket:d,storage:g}:null},target:u});const n=f.combine({allFeaturesStore:t,resolvedFeaturesStore:e}).map(({allFeaturesStore:c,resolvedFeaturesStore:l})=>Object.values(c).map(a=>{const d=l.find(g=>g.id===a.id);return d?{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:()=>({id:a.id,bucket:d.bucket}),isResolved:!0}:{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:async()=>await r(a.feature),isResolved:!1}}));function m(c){return t.map(l=>l[c],{skipVoid:!1})}return{register:o,getByName:m,listStore:n}});function pe(){return S.invoke(le)}const ge=(t,e,s)=>{s.register(t,e)},x=f.createDomain("history");function R(t,e){return{id:T.generateId("history-entry"),node:e,at:Date.now(),experienceId:t}}const de=S.createFactory(()=>{const t=x.store({entries:[]}),e=x.event(),s=x.event(),o=x.event(),i=x.event();t.on(e,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),t.on(s,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),t.on(i,(r,n)=>n);function u(r,n){const m={lastStepIndex:-1,secondLastStepIndex:-1};for(let c=r.length-1;c>=0;c--){const l=r[c],a=l==null?void 0:l.node;if(!(!a||!w.isStepNode(a))&&!(n&&(l==null?void 0:l.experienceId)!==n))if(m.lastStepIndex===-1)m.lastStepIndex=c;else{m.secondLastStepIndex=c;break}}return m}return t.on(o,(r,n)=>{const{secondLastStepIndex:m}=u(r.entries,n.experienceId),c=m!==-1?r.entries.slice(0,m+1):r.entries;return{...r,entries:c}}),{push:e,replace:s,back:o,restore:i,entriesStore:t.map(r=>r.entries)}});function fe(){return S.invoke(de)}const me=()=>f.createEvent(),ye=f.createDomain("field"),he=S.createFactory(()=>{const t=ye.store({}),e=f.createApi(t,{register(r,n){return{...r,[n.field.id]:n.field}}});function s(r){e.register({field:r})}const o=t.map(r=>Object.values(r));function i(r){return t.map(n=>n[r]||null)}function u(r){return t.map(n=>Object.values(n).find(m=>m.name===r)||null)}return{register:s,getById:i,listStore:o,getByName:u}});function Se(){return S.invoke(he)}const ve=(t,e)=>{e.register(t)},ke=f.createDomain("response"),we=S.createFactory(({client:t})=>{const e=ke.store({}),s=f.createEvent(),o=f.createEvent(),i=f.createApi(e,{register(a,d){return{...a,[d.fieldId]:d.response}},clear(a,d){const{[d]:g,...y}=a;return y},clearAll(){return{}}});function u(a,d){i.register({fieldId:a,response:d})}async function r(a){const d=[];return await Promise.allSettled(Object.entries(a).map(async([g,y])=>{let p=y;const F=t.fields.getById(g).getState();if(!F){d.push({fieldId:g,userMessage:`Field '${g}' not found`,systemMessage:`No field with ID '${g}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:p});return}if(F.multiple&&(typeof p=="string"||typeof p=="number"||typeof p=="boolean")&&(p=[p]),!M.isEmpty(F.validation)){const I=await w.evaluateRuleLogic(t,F.validation,{$input:p});if(typeof I=="string"){d.push({fieldId:g,userMessage:I,systemMessage:`Field validation resulted in an error: ${I}.`,value:p});return}if(I===!1){d.push({fieldId:g,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:p});return}}if(F.required&&(typeof p>"u"||p===null||p===""||Array.isArray(p)&&!p.length)){d.push({fieldId:g,userMessage:"This field is required",systemMessage:"Field is required.",value:p});return}if(!F.multiple&&Array.isArray(p)&&p.length>1){d.push({fieldId:g,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:p});return}if(F.options){const I=F.options.map(E=>E.value),C=Array.isArray(p)?p:[p];Array.isArray(p)&&(C.every(E=>I.includes(E))||d.push({fieldId:g,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${I.join(", ")}`,value:p}))}})),d.length?{errors:d}:(Object.entries(a).forEach(([g,y])=>{u(g,y)}),{errors:[]})}const n=e.map(a=>a),m=e.map(a=>Object.keys(a).map(g=>({fieldId:g,value:a[g]})));function c(a){const d=t.fields.getById(a),g=e.map(y=>y[a]||null);return f.combine({f:d,r:g},({f:y,r:p})=>p||(y!=null&&y.defaultValue?y.defaultValue:null))}function l(a){const d=t.fields.getByName(a);return f.combine({f:d,s:e},({f:g,s:y})=>{const p=g&&y[g.id]||null;return p||(g!=null&&g.defaultValue?g.defaultValue:null)})}return f.sample({clock:s,target:i.clearAll}),f.sample({clock:o,target:i.clear}),{register:u,clearAll:s,clear:o,commit:r,listStore:m,getAllStore:n,getByFieldId:c,getByFieldName:l}});function Fe(t){return S.invoke(we,t)}const be=()=>"0.0.1-next.1";function Ie(){if(k.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 xe(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},s=new Set;for(const[i]of t.entries())i.startsWith("picked-")&&s.add(i);for(const i of s){const u=i.replace("picked-","");e[u]=t.getAll(i)}const o=v.createStorageKey("s");if(s.size>0)v.sessionStore.set(o,e);else{const i=v.sessionStore.get(o);if(i)return i.json()||{}}return e}class P{constructor(e){h(this,"options");h(this,"isReady",!1);h(this,"project");h(this,"plugins",{});h(this,"eventBus",me());h(this,"organizationId");h(this,"projectId");h(this,"apiUrl");h(this,"searchParams",xe());h(this,"history",fe());h(this,"components",Q({client:this}));h(this,"experienceInstances",w.createExperienceInstanceIndex({client:this}));h(this,"experiences",q({client:this}));h(this,"frameworks",ee({client:this}));h(this,"predicates",ce({client:this}));h(this,"features",pe());h(this,"fields",Se());h(this,"responses",Fe({client:this}));b.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Ie(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.eventBus({type:"initialized",version:be()}),b.logger("info","Picked client initialized.")}start(){ne(this),(async()=>{k.supportsDocument()&&(document.body&&await j(this),await w.domInteractive(),await j(this),this.eventBus({type:"ready"}),this.isReady=!0)})()}registerFramework(e){te(e,this.frameworks)}registerComponent(e,s){A(e,s,this.components)}registerPlugin(e){U(this,e,this.plugins)}registerFeature(e,s){ge(e,s,this.features)}registerPredicate(e,s){ue(e,s,this.predicates)}registerField(e){ve(e,this.fields)}registerExperience(e){e.component&&A(`experience:${e.id}`,e.component,this.components),_(e,this.experiences)}getStateSnapshot(){return oe(this)}async launchExperienceById(e){const s=this.experiences.getById(e).getState();if(!s){b.logger("warn",`Experience with id '${e}' not found.`);return}O(this,s)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(s=>{if(Array.isArray(s)){s.forEach(i=>{this.registerPlugin(i)});return}const o=typeof s=="function"?s():s;if(Array.isArray(o)){o.forEach(i=>this.registerPlugin(i));return}this.registerPlugin(o)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([s,o])=>{const i=typeof o=="function"?o():o;this.registerFeature(s,i)}),this.searchParams.feature&&this.searchParams.feature.forEach(s=>{try{const[o,i]=s.split(":");if(!o||!i)return;let u=i;(u==="true"||u==="false")&&(u=!!u),this.registerFeature(o,{key:"*",name:o,decide:()=>u,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([s,o])=>{if(typeof o!="function"){b.logger("warn",`Predicate "${s}" is not a function.`);return}this.registerPredicate(s,o)})}getPluginConfig(e){return this.plugins[e]??{}}}h(P,"logger",b.logger);const Ee=t=>{const e=new P(t);return k.bindClient(e),e};exports.isPickedRoot=w.isPickedRoot;exports.createStorageKey=v.createStorageKey;exports.localStore=v.localStore;exports.sessionStore=v.sessionStore;exports.subscribe=v.subscribe;exports.supportsCookies=k.supportsCookies;exports.supportsDocument=k.supportsDocument;exports.supportsHistory=k.supportsHistory;exports.supportsIntersectionObserver=k.supportsIntersectionObserver;exports.supportsLocalStorage=k.supportsLocalStorage;exports.supportsLocation=k.supportsLocation;exports.supportsSessionStorage=k.supportsSessionStorage;exports.supportsShadowRoot=k.supportsShadowRoot;exports.supportsWindow=k.supportsWindow;exports.Picked=P;exports.createClient=Ee;
|
|
1
|
+
"use strict";var T=Object.defineProperty;var V=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var y=(t,e,s)=>V(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("effector"),h=require("@withease/factories"),F=require("../experience-instance-6ZKZS7dF.cjs"),x=require("../logger-BsmHUUw1.cjs"),k=require("../storage-BPJwmlva.cjs"),M=require("../id-BKIWbSTy.cjs"),N=require("../object-BbFTsGh3.cjs"),w=require("../supports-C0y3-V5V.cjs"),C=d.createDomain("experience"),z=h.createFactory(({client:t,experience:e})=>{const s=C.store(e),o=d.createApi(s,{merge(n,f){return{...n,...f.experience}}}),i=s.map(n=>({type:n.type,name:n.name,decisionLogic:n.decide,targetSelectors:n.targets})),p=t.components.listStore.map(n=>n.find(f=>f.name===`experience:${e.id}`)||n.find(f=>f.name==="experience"),{skipVoid:!1}),r=s.map(n=>({steps:n.steps,nodes:n.nodes,edges:n.edges,conditionals:n.conditionals}));return{id:e.id,configStore:i,treeStore:r,componentStore:p,merge:o.merge}});function q(t){return h.invoke(z,t)}const K=h.createFactory(({client:t})=>{const e=C.store({}),s=d.createApi(e,{register(r,n){return{...r,[n.id]:n}}});function o(r){const n=e.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const f=q({client:t,experience:r});s.register(f)}const i=e.map(r=>Object.values(r));function p(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getById:p,listStore:i}});function _(t){return h.invoke(K,t)}const H=(t,e)=>{e.register(t)},L=(t,e)=>{const{targetSelectors:s}=e.configStore.getState(),o=F.getTargetElements(s,e.id);o.forEach(({elements:p})=>p.forEach(r=>F.tagTargetElement(r,e.id))),F.createAppHosts(o).forEach(p=>{t.experienceInstances.spawn(e,p)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await U(t,e)&&L(t,e)}))},U=async(t,e)=>{const{type:s,decisionLogic:o,targetSelectors:i}=e.configStore.getState();return F.getTargetElements(i,e.id).length<1?!1:s==="funnel"?o?await F.evaluateRuleLogic(t,o)===!0:!1:i.length===0?!1:F.isRulesLogic(o)?await F.evaluateRuleLogic(t,o)===!0:!0},W=(t,e,s)=>{const o=e.name,i=e.setup(t);if(i){const p=s[o]??{};s[o]=Object.freeze({...p,...i})}},G=d.createDomain("component"),J=h.createFactory(({client:t,component:e,name:s})=>{const o=t.frameworks.getByName(e.frameworkName);return{name:s,component:e,frameworkStore:o}});function Y(t){return h.invoke(J,t)}const Q=h.createFactory(({client:t})=>{const e=G.store({}),s=d.createApi(e,{register(r,n){return{...r,[n.name]:n}}});function o(r,n){e.getState()[r]&&x.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const v=Y({client:t,name:r,component:n});s.register(v)}const i=e.map(r=>Object.values(r));function p(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:p,listStore:i}});function X(t){return h.invoke(Q,t)}const D=(t,e,s)=>{s.register(t,e)},Z=d.createDomain("framework"),ee=h.createFactory(({client:t})=>{const e=Z.store({}),s=d.createApi(e,{register(r,n){return{...r,[n.name]:n.framework}}});function o(r,n){e.getState()[r]&&x.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),s.register({name:r,framework:n})}const i=e.map(r=>Object.values(r));function p(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:p,listStore:i}});function te(t){return h.invoke(ee,t)}const re=(t,e)=>{e.register(t.name,t)},se=6e3,R=k.createStorageKey("last_ping","global"),ne=t=>`${t}/api/v1/ping`,oe=async t=>{try{const e=Date.now(),s=localStorage.getItem(R);if(s&&e-parseInt(s)<se)return!0;const o=ne(t.apiUrl),i={projectId:t.projectId,path:window.location.pathname},p=JSON.stringify(i),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),f=n==null?void 0:n.dataset.verceltoken;f&&(r["x-vercel-protection-bypass"]=f);const u=(await fetch(o,{method:"POST",headers:r,body:p})).ok;return u&&localStorage.setItem(R,e.toString()),u}catch(e){return x.logger("error",e),!1}};function ie(t){const e=typeof window<"u",s={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(s)}const ae=d.createDomain("predicate"),ce=h.createFactory(({client:t})=>{const e=ae.store({}),s=d.createApi(e,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function o(r,n){e.getState()[r]&&x.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),s.register(Object.freeze({name:r,predicate:n}))}const i=e.map(r=>Object.values(r));function p(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:o,getByName:p,listStore:i}});function ue(t){return h.invoke(ce,t)}const le=(t,e,s)=>{s.register(t,e)},$=d.createDomain("feature"),pe=h.createFactory(()=>{const t=$.store({}),e=$.store([]),s=d.createApi(t,{register(u,c){return{...u,[c.id]:c.feature}}});function o(u,c){t.getState()[u]&&x.logger("warn",`Feature '${u}' already registered. Registering again will override the previous registration.`);const g={id:u,feature:{...c,id:u}};s.register(Object.freeze({id:u,feature:g}))}const i=d.createEffect(async({id:u,key:c,storage:a="local"})=>{const g=k.createStorageKey(`feature:${u}:${c}`,"global"),l=(a==="session"?k.sessionStore:k.localStore).get(g).boolean();if(l!==null)return{id:u,bucket:l}}),p=d.createEffect(u=>{if(!u)return null;const c=k.createStorageKey(`feature:${u.id}:${u.key}`,"global");(u.storage==="session"?k.sessionStore:k.localStore).set(c,u.bucket)}),r=new Map,n=d.attach({source:{allFeaturesStore:t,resolvedFeaturesStore:e},effect:async({allFeaturesStore:u,resolvedFeaturesStore:c},{id:a,decide:g,key:m})=>{const l=c.find(j=>j.id===a);if(l)return l;const S=u[a];if(!S)throw new Error(`Feature with id '${a}' not found`);const b=r.get(`${a}:${m}`);if(b){const j=await b;return{id:S.id,bucket:j,storage:S.feature.storage}}const P=g();r.set(`${a}:${m}`,P);const I=await P;return{id:S.id,bucket:I,storage:S.feature.storage}}});d.sample({clock:s.register,fn:u=>{const{id:c,feature:a}=u;return{id:c,key:a.feature.key,storage:a.feature.storage}},target:i}),d.sample({source:e,clock:[i.doneData,n.doneData],fn:(u,c)=>!c||u.some(a=>a.id===c.id)?u:[...u,c],target:e}),d.sample({source:t,clock:n.doneData,fn:(u,c)=>{var S;const{id:a,bucket:g,storage:m}=c,l=(S=u[a])==null?void 0:S.feature.key;return l?{key:l,id:a,bucket:g,storage:m}:null},target:p});const f=d.combine({allFeaturesStore:t,resolvedFeaturesStore:e}).map(({allFeaturesStore:u,resolvedFeaturesStore:c})=>Object.values(u).map(a=>{const g=c.find(m=>m.id===a.id);return g?{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:()=>({id:a.id,bucket:g.bucket}),isResolved:!0}:{id:a.id,name:a.feature.name,key:a.feature.key,getBucket:async()=>await n(a.feature),isResolved:!1}}));function v(u){return t.map(c=>c[u],{skipVoid:!1})}return{register:o,getByName:v,listStore:f}});function ge(){return h.invoke(pe)}const de=(t,e,s)=>{s.register(t,e)},E=d.createDomain("history");function O(t,e){return{id:M.generateId("history-entry"),node:e,at:Date.now(),experienceId:t}}const fe=h.createFactory(()=>{const t=E.store({entries:[]}),e=E.event(),s=E.event(),o=E.event(),i=E.event();t.on(e,(r,n)=>({entries:[...r.entries,O(n.experienceId,n.node)]})),t.on(s,(r,n)=>({entries:[...r.entries.slice(0,-1),O(n.experienceId,n.node)]})),t.on(i,(r,n)=>n);function p(r,n){const f={lastStepIndex:-1,secondLastStepIndex:-1};for(let v=r.length-1;v>=0;v--){const u=r[v],c=u==null?void 0:u.node;if(!(!c||!F.isStepNode(c))&&!(n&&(u==null?void 0:u.experienceId)!==n))if(f.lastStepIndex===-1)f.lastStepIndex=v;else{f.secondLastStepIndex=v;break}}return f}return t.on(o,(r,n)=>{const{secondLastStepIndex:f}=p(r.entries,n.experienceId),v=f!==-1?r.entries.slice(0,f+1):r.entries;return{...r,entries:v}}),{push:e,replace:s,back:o,restore:i,entriesStore:t.map(r=>r.entries)}});function me(){return h.invoke(fe)}const ye=()=>d.createEvent(),he=d.createDomain("field"),Se=h.createFactory(()=>{const t=he.store({}),e=d.createApi(t,{register(r,n){return{...r,[n.field.id]:n.field}}});function s(r){e.register({field:r})}const o=t.map(r=>Object.values(r));function i(r){return t.map(n=>n[r]||null)}function p(r){return t.map(n=>Object.values(n).find(f=>f.name===r)||null)}return{register:s,getById:i,listStore:o,getByName:p}});function ve(){return h.invoke(Se)}const ke=(t,e)=>{e.register(t)},we=d.createDomain("response"),Fe=h.createFactory(({client:t})=>{const e=we.store({}),s=d.createEvent(),o=d.createEvent(),i=d.createApi(e,{register(c,a){return{...c,[a.fieldId]:a.response}},clear(c,a){const{[a]:g,...m}=c;return m},clearAll(){return{}}});function p(c,a){i.register({fieldId:c,response:a})}async function r(c){const a=[];return await Promise.allSettled(Object.entries(c).map(async([g,m])=>{let l=m;const S=t.fields.getById(g).getState();if(!S){a.push({fieldId:g,userMessage:`Field '${g}' not found`,systemMessage:`No field with ID '${g}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:l});return}if(S.multiple&&(typeof l=="string"||typeof l=="number"||typeof l=="boolean")&&(l=[l]),!N.isEmpty(S.validation)){const b=await F.evaluateRuleLogic(t,S.validation,{$input:l});if(typeof b=="string"){a.push({fieldId:g,userMessage:b,systemMessage:`Field validation resulted in an error: ${b}.`,value:l});return}if(b===!1){a.push({fieldId:g,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:l});return}}if(S.required&&(typeof l>"u"||l===null||l===""||Array.isArray(l)&&!l.length)){a.push({fieldId:g,userMessage:"This field is required",systemMessage:"Field is required.",value:l});return}if(!S.multiple&&Array.isArray(l)&&l.length>1){a.push({fieldId:g,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:l});return}if(S.options){const b=S.options.map(I=>I.value),P=Array.isArray(l)?l:[l];Array.isArray(l)&&(P.every(I=>b.includes(I))||a.push({fieldId:g,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${b.join(", ")}`,value:l}))}})),a.length?{errors:a}:(Object.entries(c).forEach(([g,m])=>{p(g,m)}),{errors:[]})}const n=e.map(c=>c),f=e.map(c=>Object.keys(c).map(g=>({fieldId:g,value:c[g]})));function v(c){const a=t.fields.getById(c),g=e.map(m=>m[c]||null);return d.combine({f:a,r:g},({f:m,r:l})=>l||(m!=null&&m.defaultValue?m.defaultValue:null))}function u(c){const a=t.fields.getByName(c);return d.combine({f:a,s:e},({f:g,s:m})=>{const l=g&&m[g.id]||null;return l||(g!=null&&g.defaultValue?g.defaultValue:null)})}return d.sample({clock:s,target:i.clearAll}),d.sample({clock:o,target:i.clear}),{register:p,clearAll:s,clear:o,commit:r,listStore:f,getAllStore:n,getByFieldId:v,getByFieldName:u}});function be(t){return h.invoke(Fe,t)}const xe=()=>"0.0.1";function Ie(){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 Ee(){if(!w.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},s=new Set;for(const[i]of t.entries())i.startsWith("picked-")&&s.add(i);for(const i of s){const p=i.replace("picked-","");e[p]=t.getAll(i)}const o=k.createStorageKey("s");if(s.size>0)k.sessionStore.set(o,e);else{const i=k.sessionStore.get(o);if(i)return i.json()||{}}return e}class A{constructor(e){y(this,"options");y(this,"isReady",!1);y(this,"project");y(this,"plugins",{});y(this,"eventBus",ye());y(this,"organizationId");y(this,"projectId");y(this,"apiUrl");y(this,"searchParams",Ee());y(this,"history",me());y(this,"components",X({client:this}));y(this,"experienceInstances",F.createExperienceInstanceIndex({client:this}));y(this,"experiences",_({client:this}));y(this,"frameworks",te({client:this}));y(this,"predicates",ue({client:this}));y(this,"features",ge());y(this,"fields",ve());y(this,"responses",be({client:this}));x.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Ie(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.eventBus({type:"initialized",version:xe()}),x.logger("info","Picked client initialized.")}start(){oe(this),(async()=>{w.supportsDocument()&&(document.body&&await B(this),await F.domInteractive(),await B(this),this.eventBus({type:"ready"}),this.isReady=!0)})()}registerFramework(e){re(e,this.frameworks)}registerComponent(e,s){D(e,s,this.components)}registerPlugin(e){W(this,e,this.plugins)}registerFeature(e,s){de(e,s,this.features)}registerPredicate(e,s){le(e,s,this.predicates)}registerField(e){ke(e,this.fields)}registerExperience(e){e.component&&D(`experience:${e.id}`,e.component,this.components),H(e,this.experiences)}getStateSnapshot(){return ie(this)}async launchExperienceById(e){const s=this.experiences.getById(e).getState();if(!s){x.logger("warn",`Experience with id '${e}' not found.`);return}L(this,s)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(s=>{if(Array.isArray(s)){s.forEach(i=>{this.registerPlugin(i)});return}const o=typeof s=="function"?s():s;if(Array.isArray(o)){o.forEach(i=>this.registerPlugin(i));return}this.registerPlugin(o)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([s,o])=>{const i=typeof o=="function"?o():o;this.registerFeature(s,i)}),this.searchParams.feature&&this.searchParams.feature.forEach(s=>{try{const[o,i]=s.split(":");if(!o||!i)return;let p=i;(p==="true"||p==="false")&&(p=!!p),this.registerFeature(o,{key:"*",name:o,decide:()=>p,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([s,o])=>{if(typeof o!="function"){x.logger("warn",`Predicate "${s}" is not a function.`);return}this.registerPredicate(s,o)})}getPluginConfig(e){return this.plugins[e]??{}}}y(A,"logger",x.logger);const Pe=t=>{const e=new A(t);return w.bindClient(e),e};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.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.supportsWindow=w.supportsWindow;exports.Picked=A;exports.createClient=Pe;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { createDomain as
|
|
5
|
-
import { createFactory as v, invoke as
|
|
6
|
-
import { g as
|
|
7
|
-
import { f as
|
|
8
|
-
import { l as
|
|
9
|
-
import { c as
|
|
10
|
-
import { a as
|
|
11
|
-
import { g as
|
|
12
|
-
import { i as
|
|
13
|
-
import { s as
|
|
14
|
-
import { g as
|
|
15
|
-
const
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var G = (t, e, s) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var m = (t, e, s) => G(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { createDomain as x, createApi as b, createEffect as O, attach as W, sample as E, combine as R, createEvent as A } from "effector";
|
|
5
|
+
import { createFactory as v, invoke as k } from "@withease/factories";
|
|
6
|
+
import { g as z, t as J, c as Y, e as D, i as Q, a as X, b as Z, d as ee } from "../experience-instance-BA0EXYg5.js";
|
|
7
|
+
import { f as st } from "../experience-instance-BA0EXYg5.js";
|
|
8
|
+
import { l as w } from "../logger-C9a75KZn.js";
|
|
9
|
+
import { c as B, s as j, l as C } from "../storage-D87xFySf.js";
|
|
10
|
+
import { a as ot } from "../storage-D87xFySf.js";
|
|
11
|
+
import { g as te } from "../id-BW-g3y32.js";
|
|
12
|
+
import { i as re } from "../object-JwZ58NOH.js";
|
|
13
|
+
import { s as _, a as se, b as ne } from "../supports-BvrzQAVk.js";
|
|
14
|
+
import { g as at, d as ct, i as ut, e as lt, c as dt, f as pt, h as gt } from "../supports-BvrzQAVk.js";
|
|
15
|
+
const U = x("experience"), oe = v(
|
|
16
16
|
({ client: t, experience: e }) => {
|
|
17
|
-
const s =
|
|
18
|
-
merge(n,
|
|
17
|
+
const s = U.store(e), o = b(s, {
|
|
18
|
+
merge(n, g) {
|
|
19
19
|
return {
|
|
20
20
|
...n,
|
|
21
|
-
...
|
|
21
|
+
...g.experience
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
}), i = s.map((n) => ({
|
|
@@ -26,8 +26,8 @@ const z = k("experience"), ne = v(
|
|
|
26
26
|
name: n.name,
|
|
27
27
|
decisionLogic: n.decide,
|
|
28
28
|
targetSelectors: n.targets
|
|
29
|
-
})),
|
|
30
|
-
(n) => n.find((
|
|
29
|
+
})), d = t.components.listStore.map(
|
|
30
|
+
(n) => n.find((g) => g.name === `experience:${e.id}`) || n.find((g) => g.name === "experience"),
|
|
31
31
|
{ skipVoid: !1 }
|
|
32
32
|
), r = s.map((n) => ({
|
|
33
33
|
steps: n.steps,
|
|
@@ -39,16 +39,16 @@ const z = k("experience"), ne = v(
|
|
|
39
39
|
id: e.id,
|
|
40
40
|
configStore: i,
|
|
41
41
|
treeStore: r,
|
|
42
|
-
componentStore:
|
|
42
|
+
componentStore: d,
|
|
43
43
|
merge: o.merge
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
);
|
|
47
|
-
function
|
|
48
|
-
return
|
|
47
|
+
function ie(t) {
|
|
48
|
+
return k(oe, t);
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
const e =
|
|
50
|
+
const ae = v(({ client: t }) => {
|
|
51
|
+
const e = U.store({}), s = b(e, {
|
|
52
52
|
register(r, n) {
|
|
53
53
|
return {
|
|
54
54
|
...r,
|
|
@@ -62,47 +62,47 @@ const ie = v(({ client: t }) => {
|
|
|
62
62
|
n.merge({ experience: r, strategy: "override" });
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
s.register(
|
|
65
|
+
const g = ie({ client: t, experience: r });
|
|
66
|
+
s.register(g);
|
|
67
67
|
}
|
|
68
68
|
const i = e.map((r) => Object.values(r));
|
|
69
|
-
function
|
|
69
|
+
function d(r) {
|
|
70
70
|
return e.map((n) => n[r], { skipVoid: !1 });
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
73
|
register: o,
|
|
74
|
-
getById:
|
|
74
|
+
getById: d,
|
|
75
75
|
listStore: i
|
|
76
76
|
};
|
|
77
77
|
});
|
|
78
|
-
function
|
|
79
|
-
return
|
|
78
|
+
function ce(t) {
|
|
79
|
+
return k(ae, t);
|
|
80
80
|
}
|
|
81
|
-
const
|
|
81
|
+
const ue = (t, e) => {
|
|
82
82
|
e.register(t);
|
|
83
|
-
},
|
|
84
|
-
const { targetSelectors: s } = e.configStore.getState(), o =
|
|
83
|
+
}, H = (t, e) => {
|
|
84
|
+
const { targetSelectors: s } = e.configStore.getState(), o = z(s, e.id);
|
|
85
85
|
o.forEach(
|
|
86
|
-
({ elements:
|
|
87
|
-
),
|
|
88
|
-
t.experienceInstances.spawn(e,
|
|
86
|
+
({ elements: d }) => d.forEach((r) => J(r, e.id))
|
|
87
|
+
), Y(o).forEach((d) => {
|
|
88
|
+
t.experienceInstances.spawn(e, d);
|
|
89
89
|
});
|
|
90
|
-
},
|
|
90
|
+
}, V = async (t) => {
|
|
91
91
|
await Promise.all(
|
|
92
92
|
t.experiences.listStore.getState().map(async (e) => {
|
|
93
|
-
await
|
|
93
|
+
await le(t, e) && H(t, e);
|
|
94
94
|
})
|
|
95
95
|
);
|
|
96
|
-
},
|
|
96
|
+
}, le = async (t, e) => {
|
|
97
97
|
const { type: s, decisionLogic: o, targetSelectors: i } = e.configStore.getState();
|
|
98
|
-
return
|
|
99
|
-
},
|
|
98
|
+
return z(i, e.id).length < 1 ? !1 : s === "funnel" ? o ? await D(t, o) === !0 : !1 : i.length === 0 ? !1 : Q(o) ? await D(t, o) === !0 : !0;
|
|
99
|
+
}, de = (t, e, s) => {
|
|
100
100
|
const o = e.name, i = e.setup(t);
|
|
101
101
|
if (i) {
|
|
102
|
-
const
|
|
103
|
-
s[o] = Object.freeze({ ...
|
|
102
|
+
const d = s[o] ?? {};
|
|
103
|
+
s[o] = Object.freeze({ ...d, ...i });
|
|
104
104
|
}
|
|
105
|
-
},
|
|
105
|
+
}, pe = x("component"), ge = v(
|
|
106
106
|
({ client: t, component: e, name: s }) => {
|
|
107
107
|
const o = t.frameworks.getByName(e.frameworkName);
|
|
108
108
|
return {
|
|
@@ -112,11 +112,11 @@ const ce = (t, e) => {
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
);
|
|
115
|
-
function
|
|
116
|
-
return
|
|
115
|
+
function fe(t) {
|
|
116
|
+
return k(ge, t);
|
|
117
117
|
}
|
|
118
|
-
const
|
|
119
|
-
const e =
|
|
118
|
+
const me = v(({ client: t }) => {
|
|
119
|
+
const e = pe.store({}), s = b(e, {
|
|
120
120
|
register(r, n) {
|
|
121
121
|
return {
|
|
122
122
|
...r,
|
|
@@ -125,30 +125,30 @@ const fe = v(({ client: t }) => {
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
function o(r, n) {
|
|
128
|
-
e.getState()[r] &&
|
|
128
|
+
e.getState()[r] && w(
|
|
129
129
|
"warn",
|
|
130
130
|
`Component '${r}' already registered. Registering again will override the previous registration.`
|
|
131
131
|
);
|
|
132
|
-
const
|
|
133
|
-
s.register(
|
|
132
|
+
const h = fe({ client: t, name: r, component: n });
|
|
133
|
+
s.register(h);
|
|
134
134
|
}
|
|
135
135
|
const i = e.map((r) => Object.values(r));
|
|
136
|
-
function
|
|
136
|
+
function d(r) {
|
|
137
137
|
return e.map((n) => n[r], { skipVoid: !1 });
|
|
138
138
|
}
|
|
139
139
|
return {
|
|
140
140
|
register: o,
|
|
141
|
-
getByName:
|
|
141
|
+
getByName: d,
|
|
142
142
|
listStore: i
|
|
143
143
|
};
|
|
144
144
|
});
|
|
145
|
-
function
|
|
146
|
-
return
|
|
145
|
+
function ye(t) {
|
|
146
|
+
return k(me, t);
|
|
147
147
|
}
|
|
148
|
-
const
|
|
148
|
+
const M = (t, e, s) => {
|
|
149
149
|
s.register(t, e);
|
|
150
|
-
},
|
|
151
|
-
const e =
|
|
150
|
+
}, he = x("framework"), Se = v(({ client: t }) => {
|
|
151
|
+
const e = he.store({}), s = b(e, {
|
|
152
152
|
register(r, n) {
|
|
153
153
|
return {
|
|
154
154
|
...r,
|
|
@@ -157,49 +157,49 @@ const V = (t, e, s) => {
|
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
function o(r, n) {
|
|
160
|
-
e.getState()[r] &&
|
|
160
|
+
e.getState()[r] && w(
|
|
161
161
|
"warn",
|
|
162
162
|
`Framework '${r}' already registered. Registering again will override the previous registration.`
|
|
163
163
|
), s.register({ name: r, framework: n });
|
|
164
164
|
}
|
|
165
165
|
const i = e.map((r) => Object.values(r));
|
|
166
|
-
function
|
|
166
|
+
function d(r) {
|
|
167
167
|
return e.map((n) => n[r], { skipVoid: !1 });
|
|
168
168
|
}
|
|
169
169
|
return {
|
|
170
170
|
register: o,
|
|
171
|
-
getByName:
|
|
171
|
+
getByName: d,
|
|
172
172
|
listStore: i
|
|
173
173
|
};
|
|
174
174
|
});
|
|
175
|
-
function
|
|
176
|
-
return
|
|
175
|
+
function we(t) {
|
|
176
|
+
return k(Se, t);
|
|
177
177
|
}
|
|
178
178
|
const ve = (t, e) => {
|
|
179
179
|
e.register(t.name, t);
|
|
180
|
-
},
|
|
180
|
+
}, ke = 6e3, N = B("last_ping", "global"), xe = (t) => `${t}/api/v1/ping`, be = async (t) => {
|
|
181
181
|
try {
|
|
182
|
-
const e = Date.now(), s = localStorage.getItem(
|
|
183
|
-
if (s && e - parseInt(s) <
|
|
182
|
+
const e = Date.now(), s = localStorage.getItem(N);
|
|
183
|
+
if (s && e - parseInt(s) < ke)
|
|
184
184
|
return !0;
|
|
185
|
-
const o =
|
|
185
|
+
const o = xe(t.apiUrl), i = {
|
|
186
186
|
projectId: t.projectId,
|
|
187
187
|
path: window.location.pathname
|
|
188
|
-
},
|
|
188
|
+
}, d = JSON.stringify(i), r = {
|
|
189
189
|
"Content-Type": "application/json"
|
|
190
|
-
}, n = document.getElementById("picked_script"),
|
|
191
|
-
|
|
192
|
-
const
|
|
190
|
+
}, n = document.getElementById("picked_script"), g = n == null ? void 0 : n.dataset.verceltoken;
|
|
191
|
+
g && (r["x-vercel-protection-bypass"] = g);
|
|
192
|
+
const u = (await fetch(o, {
|
|
193
193
|
method: "POST",
|
|
194
194
|
headers: r,
|
|
195
|
-
body:
|
|
195
|
+
body: d
|
|
196
196
|
})).ok;
|
|
197
|
-
return
|
|
197
|
+
return u && localStorage.setItem(N, e.toString()), u;
|
|
198
198
|
} catch (e) {
|
|
199
|
-
return
|
|
199
|
+
return w("error", e), !1;
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
|
-
function
|
|
202
|
+
function Fe(t) {
|
|
203
203
|
const e = typeof window < "u", s = {
|
|
204
204
|
client: t,
|
|
205
205
|
responses: t.responses.listStore.getState(),
|
|
@@ -211,8 +211,8 @@ function Ie(t) {
|
|
|
211
211
|
};
|
|
212
212
|
return Object.freeze(s);
|
|
213
213
|
}
|
|
214
|
-
const
|
|
215
|
-
const e =
|
|
214
|
+
const Ie = x("predicate"), Ee = v(({ client: t }) => {
|
|
215
|
+
const e = Ie.store({}), s = b(e, {
|
|
216
216
|
register(r, n) {
|
|
217
217
|
return {
|
|
218
218
|
...r,
|
|
@@ -224,177 +224,184 @@ const Fe = k("predicate"), be = v(({ client: t }) => {
|
|
|
224
224
|
}
|
|
225
225
|
});
|
|
226
226
|
function o(r, n) {
|
|
227
|
-
e.getState()[r] &&
|
|
227
|
+
e.getState()[r] && w(
|
|
228
228
|
"warn",
|
|
229
229
|
`Predicate '${r}' already registered. Registering again will override the previous registration.`
|
|
230
230
|
), s.register(Object.freeze({ name: r, predicate: n }));
|
|
231
231
|
}
|
|
232
232
|
const i = e.map((r) => Object.values(r));
|
|
233
|
-
function
|
|
233
|
+
function d(r) {
|
|
234
234
|
return e.map((n) => n[r], { skipVoid: !1 });
|
|
235
235
|
}
|
|
236
236
|
return {
|
|
237
237
|
register: o,
|
|
238
|
-
getByName:
|
|
238
|
+
getByName: d,
|
|
239
239
|
listStore: i
|
|
240
240
|
};
|
|
241
241
|
});
|
|
242
|
-
function
|
|
243
|
-
return
|
|
242
|
+
function Pe(t) {
|
|
243
|
+
return k(Ee, t);
|
|
244
244
|
}
|
|
245
|
-
const
|
|
245
|
+
const Be = (t, e, s) => {
|
|
246
246
|
s.register(t, e);
|
|
247
|
-
},
|
|
248
|
-
const t =
|
|
249
|
-
register(
|
|
247
|
+
}, T = x("feature"), je = v(() => {
|
|
248
|
+
const t = T.store({}), e = T.store([]), s = b(t, {
|
|
249
|
+
register(u, c) {
|
|
250
250
|
return {
|
|
251
|
-
...
|
|
252
|
-
[
|
|
251
|
+
...u,
|
|
252
|
+
[c.id]: c.feature
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
});
|
|
256
|
-
function o(
|
|
257
|
-
t.getState()[
|
|
256
|
+
function o(u, c) {
|
|
257
|
+
t.getState()[u] && w(
|
|
258
258
|
"warn",
|
|
259
|
-
`Feature '${
|
|
259
|
+
`Feature '${u}' already registered. Registering again will override the previous registration.`
|
|
260
260
|
);
|
|
261
|
-
const
|
|
262
|
-
id:
|
|
261
|
+
const p = {
|
|
262
|
+
id: u,
|
|
263
263
|
feature: {
|
|
264
|
-
...
|
|
265
|
-
id:
|
|
264
|
+
...c,
|
|
265
|
+
id: u
|
|
266
266
|
}
|
|
267
267
|
};
|
|
268
268
|
s.register(
|
|
269
269
|
Object.freeze({
|
|
270
|
-
id:
|
|
271
|
-
feature:
|
|
270
|
+
id: u,
|
|
271
|
+
feature: p
|
|
272
272
|
})
|
|
273
273
|
);
|
|
274
274
|
}
|
|
275
|
-
const i =
|
|
275
|
+
const i = O(
|
|
276
276
|
async ({
|
|
277
|
-
id:
|
|
278
|
-
key:
|
|
277
|
+
id: u,
|
|
278
|
+
key: c,
|
|
279
279
|
storage: a = "local"
|
|
280
280
|
}) => {
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
return { id:
|
|
281
|
+
const p = B(`feature:${u}:${c}`, "global"), l = (a === "session" ? j : C).get(p).boolean();
|
|
282
|
+
if (l !== null)
|
|
283
|
+
return { id: u, bucket: l };
|
|
284
284
|
}
|
|
285
|
-
),
|
|
286
|
-
if (!
|
|
285
|
+
), d = O((u) => {
|
|
286
|
+
if (!u)
|
|
287
287
|
return null;
|
|
288
|
-
const
|
|
289
|
-
(
|
|
290
|
-
}), r =
|
|
288
|
+
const c = B(`feature:${u.id}:${u.key}`, "global");
|
|
289
|
+
(u.storage === "session" ? j : C).set(c, u.bucket);
|
|
290
|
+
}), r = /* @__PURE__ */ new Map(), n = W({
|
|
291
291
|
source: { allFeaturesStore: t, resolvedFeaturesStore: e },
|
|
292
|
-
effect: async ({ allFeaturesStore:
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
return
|
|
296
|
-
const
|
|
297
|
-
if (!
|
|
292
|
+
effect: async ({ allFeaturesStore: u, resolvedFeaturesStore: c }, { id: a, decide: p, key: f }) => {
|
|
293
|
+
const l = c.find(($) => $.id === a);
|
|
294
|
+
if (l)
|
|
295
|
+
return l;
|
|
296
|
+
const y = u[a];
|
|
297
|
+
if (!y)
|
|
298
298
|
throw new Error(`Feature with id '${a}' not found`);
|
|
299
|
-
const
|
|
300
|
-
|
|
299
|
+
const S = r.get(`${a}:${f}`);
|
|
300
|
+
if (S) {
|
|
301
|
+
const $ = await S;
|
|
302
|
+
return { id: y.id, bucket: $, storage: y.feature.storage };
|
|
303
|
+
}
|
|
304
|
+
const P = p();
|
|
305
|
+
r.set(`${a}:${f}`, P);
|
|
306
|
+
const F = await P;
|
|
307
|
+
return { id: y.id, bucket: F, storage: y.feature.storage };
|
|
301
308
|
}
|
|
302
309
|
});
|
|
303
|
-
|
|
310
|
+
E({
|
|
304
311
|
clock: s.register,
|
|
305
|
-
fn: (
|
|
306
|
-
const { id:
|
|
307
|
-
return { id:
|
|
312
|
+
fn: (u) => {
|
|
313
|
+
const { id: c, feature: a } = u;
|
|
314
|
+
return { id: c, key: a.feature.key, storage: a.feature.storage };
|
|
308
315
|
},
|
|
309
316
|
target: i
|
|
310
|
-
}),
|
|
317
|
+
}), E({
|
|
311
318
|
source: e,
|
|
312
|
-
clock: [i.doneData,
|
|
313
|
-
fn: (
|
|
319
|
+
clock: [i.doneData, n.doneData],
|
|
320
|
+
fn: (u, c) => !c || u.some((a) => a.id === c.id) ? u : [...u, c],
|
|
314
321
|
target: e
|
|
315
|
-
}),
|
|
322
|
+
}), E({
|
|
316
323
|
source: t,
|
|
317
|
-
clock:
|
|
318
|
-
fn: (
|
|
319
|
-
var
|
|
320
|
-
const { id: a, bucket:
|
|
321
|
-
return
|
|
324
|
+
clock: n.doneData,
|
|
325
|
+
fn: (u, c) => {
|
|
326
|
+
var y;
|
|
327
|
+
const { id: a, bucket: p, storage: f } = c, l = (y = u[a]) == null ? void 0 : y.feature.key;
|
|
328
|
+
return l ? { key: l, id: a, bucket: p, storage: f } : null;
|
|
322
329
|
},
|
|
323
|
-
target:
|
|
330
|
+
target: d
|
|
324
331
|
});
|
|
325
|
-
const
|
|
332
|
+
const g = R({ allFeaturesStore: t, resolvedFeaturesStore: e }).map(
|
|
326
333
|
({
|
|
327
|
-
allFeaturesStore:
|
|
328
|
-
resolvedFeaturesStore:
|
|
329
|
-
}) => Object.values(
|
|
330
|
-
const
|
|
331
|
-
return
|
|
334
|
+
allFeaturesStore: u,
|
|
335
|
+
resolvedFeaturesStore: c
|
|
336
|
+
}) => Object.values(u).map((a) => {
|
|
337
|
+
const p = c.find((f) => f.id === a.id);
|
|
338
|
+
return p ? {
|
|
332
339
|
id: a.id,
|
|
333
340
|
name: a.feature.name,
|
|
334
341
|
key: a.feature.key,
|
|
335
|
-
getBucket: () => ({ id: a.id, bucket:
|
|
342
|
+
getBucket: () => ({ id: a.id, bucket: p.bucket }),
|
|
336
343
|
isResolved: !0
|
|
337
344
|
} : {
|
|
338
345
|
id: a.id,
|
|
339
346
|
name: a.feature.name,
|
|
340
347
|
key: a.feature.key,
|
|
341
|
-
getBucket: async () => await
|
|
348
|
+
getBucket: async () => await n(a.feature),
|
|
342
349
|
isResolved: !1
|
|
343
350
|
};
|
|
344
351
|
})
|
|
345
352
|
);
|
|
346
|
-
function
|
|
347
|
-
return t.map((
|
|
353
|
+
function h(u) {
|
|
354
|
+
return t.map((c) => c[u], { skipVoid: !1 });
|
|
348
355
|
}
|
|
349
356
|
return {
|
|
350
357
|
register: o,
|
|
351
|
-
getByName:
|
|
352
|
-
listStore:
|
|
358
|
+
getByName: h,
|
|
359
|
+
listStore: g
|
|
353
360
|
};
|
|
354
361
|
});
|
|
355
|
-
function
|
|
356
|
-
return
|
|
362
|
+
function $e() {
|
|
363
|
+
return k(je);
|
|
357
364
|
}
|
|
358
|
-
const
|
|
365
|
+
const Re = (t, e, s) => {
|
|
359
366
|
s.register(t, e);
|
|
360
|
-
},
|
|
361
|
-
function
|
|
367
|
+
}, I = x("history");
|
|
368
|
+
function L(t, e) {
|
|
362
369
|
return {
|
|
363
|
-
id:
|
|
370
|
+
id: te("history-entry"),
|
|
364
371
|
node: e,
|
|
365
372
|
at: Date.now(),
|
|
366
373
|
experienceId: t
|
|
367
374
|
};
|
|
368
375
|
}
|
|
369
|
-
const
|
|
370
|
-
const t =
|
|
376
|
+
const Ae = v(() => {
|
|
377
|
+
const t = I.store({ entries: [] }), e = I.event(), s = I.event(), o = I.event(), i = I.event();
|
|
371
378
|
t.on(e, (r, n) => ({
|
|
372
|
-
entries: [...r.entries,
|
|
379
|
+
entries: [...r.entries, L(n.experienceId, n.node)]
|
|
373
380
|
})), t.on(s, (r, n) => ({
|
|
374
381
|
entries: [
|
|
375
382
|
...r.entries.slice(0, -1),
|
|
376
|
-
|
|
383
|
+
L(n.experienceId, n.node)
|
|
377
384
|
]
|
|
378
385
|
})), t.on(i, (r, n) => n);
|
|
379
|
-
function
|
|
380
|
-
const
|
|
381
|
-
for (let
|
|
382
|
-
const
|
|
383
|
-
if (!(!
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
+
function d(r, n) {
|
|
387
|
+
const g = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
388
|
+
for (let h = r.length - 1; h >= 0; h--) {
|
|
389
|
+
const u = r[h], c = u == null ? void 0 : u.node;
|
|
390
|
+
if (!(!c || !X(c)) && !(n && (u == null ? void 0 : u.experienceId) !== n))
|
|
391
|
+
if (g.lastStepIndex === -1)
|
|
392
|
+
g.lastStepIndex = h;
|
|
386
393
|
else {
|
|
387
|
-
|
|
394
|
+
g.secondLastStepIndex = h;
|
|
388
395
|
break;
|
|
389
396
|
}
|
|
390
397
|
}
|
|
391
|
-
return
|
|
398
|
+
return g;
|
|
392
399
|
}
|
|
393
400
|
return t.on(o, (r, n) => {
|
|
394
|
-
const { secondLastStepIndex:
|
|
401
|
+
const { secondLastStepIndex: g } = d(r.entries, n.experienceId), h = g !== -1 ? r.entries.slice(0, g + 1) : r.entries;
|
|
395
402
|
return {
|
|
396
403
|
...r,
|
|
397
|
-
entries:
|
|
404
|
+
entries: h
|
|
398
405
|
};
|
|
399
406
|
}), {
|
|
400
407
|
push: e,
|
|
@@ -404,11 +411,11 @@ const Re = v(() => {
|
|
|
404
411
|
entriesStore: t.map((r) => r.entries)
|
|
405
412
|
};
|
|
406
413
|
});
|
|
407
|
-
function
|
|
408
|
-
return
|
|
414
|
+
function De() {
|
|
415
|
+
return k(Ae);
|
|
409
416
|
}
|
|
410
|
-
const Oe = () => A(),
|
|
411
|
-
const t =
|
|
417
|
+
const Oe = () => A(), Ce = x("field"), Ve = v(() => {
|
|
418
|
+
const t = Ce.store({}), e = b(t, {
|
|
412
419
|
register(r, n) {
|
|
413
420
|
return {
|
|
414
421
|
...r,
|
|
@@ -423,148 +430,148 @@ const Oe = () => A(), De = k("field"), Ve = v(() => {
|
|
|
423
430
|
function i(r) {
|
|
424
431
|
return t.map((n) => n[r] || null);
|
|
425
432
|
}
|
|
426
|
-
function
|
|
427
|
-
return t.map((n) => Object.values(n).find((
|
|
433
|
+
function d(r) {
|
|
434
|
+
return t.map((n) => Object.values(n).find((g) => g.name === r) || null);
|
|
428
435
|
}
|
|
429
436
|
return {
|
|
430
437
|
register: s,
|
|
431
438
|
getById: i,
|
|
432
439
|
listStore: o,
|
|
433
|
-
getByName:
|
|
440
|
+
getByName: d
|
|
434
441
|
};
|
|
435
442
|
});
|
|
436
|
-
function
|
|
437
|
-
return
|
|
443
|
+
function Me() {
|
|
444
|
+
return k(Ve);
|
|
438
445
|
}
|
|
439
446
|
const Ne = (t, e) => {
|
|
440
447
|
e.register(t);
|
|
441
|
-
}, Te =
|
|
442
|
-
const e = Te.store({}), s = A(), o = A(), i =
|
|
443
|
-
register(
|
|
448
|
+
}, Te = x("response"), Le = v(({ client: t }) => {
|
|
449
|
+
const e = Te.store({}), s = A(), o = A(), i = b(e, {
|
|
450
|
+
register(c, a) {
|
|
444
451
|
return {
|
|
445
|
-
...
|
|
446
|
-
[
|
|
452
|
+
...c,
|
|
453
|
+
[a.fieldId]: a.response
|
|
447
454
|
};
|
|
448
455
|
},
|
|
449
|
-
clear(
|
|
450
|
-
const { [
|
|
451
|
-
return
|
|
456
|
+
clear(c, a) {
|
|
457
|
+
const { [a]: p, ...f } = c;
|
|
458
|
+
return f;
|
|
452
459
|
},
|
|
453
460
|
clearAll() {
|
|
454
461
|
return {};
|
|
455
462
|
}
|
|
456
463
|
});
|
|
457
|
-
function
|
|
458
|
-
i.register({ fieldId:
|
|
464
|
+
function d(c, a) {
|
|
465
|
+
i.register({ fieldId: c, response: a });
|
|
459
466
|
}
|
|
460
|
-
async function r(
|
|
461
|
-
const
|
|
467
|
+
async function r(c) {
|
|
468
|
+
const a = [];
|
|
462
469
|
return await Promise.allSettled(
|
|
463
|
-
Object.entries(
|
|
464
|
-
let
|
|
465
|
-
const
|
|
466
|
-
if (!
|
|
467
|
-
|
|
470
|
+
Object.entries(c).map(async ([p, f]) => {
|
|
471
|
+
let l = f;
|
|
472
|
+
const y = t.fields.getById(p).getState();
|
|
473
|
+
if (!y) {
|
|
474
|
+
a.push({
|
|
468
475
|
fieldId: p,
|
|
469
476
|
userMessage: `Field '${p}' not found`,
|
|
470
477
|
systemMessage: `No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
471
|
-
value:
|
|
478
|
+
value: l
|
|
472
479
|
});
|
|
473
480
|
return;
|
|
474
481
|
}
|
|
475
|
-
if (
|
|
476
|
-
const
|
|
477
|
-
$input:
|
|
482
|
+
if (y.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), !re(y.validation)) {
|
|
483
|
+
const S = await D(t, y.validation, {
|
|
484
|
+
$input: l
|
|
478
485
|
});
|
|
479
|
-
if (typeof
|
|
480
|
-
|
|
486
|
+
if (typeof S == "string") {
|
|
487
|
+
a.push({
|
|
481
488
|
fieldId: p,
|
|
482
|
-
userMessage:
|
|
483
|
-
systemMessage: `Field validation resulted in an error: ${
|
|
484
|
-
value:
|
|
489
|
+
userMessage: S,
|
|
490
|
+
systemMessage: `Field validation resulted in an error: ${S}.`,
|
|
491
|
+
value: l
|
|
485
492
|
});
|
|
486
493
|
return;
|
|
487
494
|
}
|
|
488
|
-
if (
|
|
489
|
-
|
|
495
|
+
if (S === !1) {
|
|
496
|
+
a.push({
|
|
490
497
|
fieldId: p,
|
|
491
498
|
userMessage: "This field is invalid",
|
|
492
499
|
systemMessage: "Field validation resulted in an unspecified error.",
|
|
493
|
-
value:
|
|
500
|
+
value: l
|
|
494
501
|
});
|
|
495
502
|
return;
|
|
496
503
|
}
|
|
497
504
|
}
|
|
498
|
-
if (
|
|
499
|
-
|
|
505
|
+
if (y.required && (typeof l > "u" || l === null || l === "" || Array.isArray(l) && !l.length)) {
|
|
506
|
+
a.push({
|
|
500
507
|
fieldId: p,
|
|
501
508
|
userMessage: "This field is required",
|
|
502
509
|
systemMessage: "Field is required.",
|
|
503
|
-
value:
|
|
510
|
+
value: l
|
|
504
511
|
});
|
|
505
512
|
return;
|
|
506
513
|
}
|
|
507
|
-
if (!
|
|
508
|
-
|
|
514
|
+
if (!y.multiple && Array.isArray(l) && l.length > 1) {
|
|
515
|
+
a.push({
|
|
509
516
|
fieldId: p,
|
|
510
517
|
userMessage: "This field expects a single response",
|
|
511
518
|
systemMessage: "Field expects a single response.",
|
|
512
|
-
value:
|
|
519
|
+
value: l
|
|
513
520
|
});
|
|
514
521
|
return;
|
|
515
522
|
}
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
Array.isArray(
|
|
523
|
+
if (y.options) {
|
|
524
|
+
const S = y.options.map((F) => F.value), P = Array.isArray(l) ? l : [l];
|
|
525
|
+
Array.isArray(l) && (P.every((F) => S.includes(F)) || a.push({
|
|
519
526
|
fieldId: p,
|
|
520
527
|
userMessage: "This field expects a valid option",
|
|
521
|
-
systemMessage: `Field expects a valid option. Valid options are: ${
|
|
522
|
-
value:
|
|
528
|
+
systemMessage: `Field expects a valid option. Valid options are: ${S.join(", ")}`,
|
|
529
|
+
value: l
|
|
523
530
|
}));
|
|
524
531
|
}
|
|
525
532
|
})
|
|
526
|
-
),
|
|
527
|
-
|
|
533
|
+
), a.length ? { errors: a } : (Object.entries(c).forEach(([p, f]) => {
|
|
534
|
+
d(p, f);
|
|
528
535
|
}), { errors: [] });
|
|
529
536
|
}
|
|
530
|
-
const n = e.map((
|
|
537
|
+
const n = e.map((c) => c), g = e.map((c) => Object.keys(c).map((p) => ({
|
|
531
538
|
fieldId: p,
|
|
532
|
-
value:
|
|
539
|
+
value: c[p]
|
|
533
540
|
})));
|
|
534
|
-
function c
|
|
535
|
-
const
|
|
536
|
-
return
|
|
537
|
-
}
|
|
538
|
-
function
|
|
539
|
-
const
|
|
540
|
-
return
|
|
541
|
-
const
|
|
542
|
-
return
|
|
541
|
+
function h(c) {
|
|
542
|
+
const a = t.fields.getById(c), p = e.map((f) => f[c] || null);
|
|
543
|
+
return R({ f: a, r: p }, ({ f, r: l }) => l || (f != null && f.defaultValue ? f.defaultValue : null));
|
|
544
|
+
}
|
|
545
|
+
function u(c) {
|
|
546
|
+
const a = t.fields.getByName(c);
|
|
547
|
+
return R({ f: a, s: e }, ({ f: p, s: f }) => {
|
|
548
|
+
const l = p && f[p.id] || null;
|
|
549
|
+
return l || (p != null && p.defaultValue ? p.defaultValue : null);
|
|
543
550
|
});
|
|
544
551
|
}
|
|
545
|
-
return
|
|
552
|
+
return E({
|
|
546
553
|
clock: s,
|
|
547
554
|
target: i.clearAll
|
|
548
|
-
}),
|
|
555
|
+
}), E({
|
|
549
556
|
clock: o,
|
|
550
557
|
target: i.clear
|
|
551
558
|
}), {
|
|
552
|
-
register:
|
|
559
|
+
register: d,
|
|
553
560
|
clearAll: s,
|
|
554
561
|
clear: o,
|
|
555
562
|
commit: r,
|
|
556
|
-
listStore:
|
|
563
|
+
listStore: g,
|
|
557
564
|
getAllStore: n,
|
|
558
|
-
getByFieldId:
|
|
559
|
-
getByFieldName:
|
|
565
|
+
getByFieldId: h,
|
|
566
|
+
getByFieldName: u
|
|
560
567
|
};
|
|
561
568
|
});
|
|
562
|
-
function
|
|
563
|
-
return
|
|
569
|
+
function ze(t) {
|
|
570
|
+
return k(Le, t);
|
|
564
571
|
}
|
|
565
|
-
const
|
|
566
|
-
function
|
|
567
|
-
if (
|
|
572
|
+
const _e = () => "0.0.1";
|
|
573
|
+
function Ue() {
|
|
574
|
+
if (_()) {
|
|
568
575
|
const t = [
|
|
569
576
|
document.currentScript,
|
|
570
577
|
document.getElementById("picked_script"),
|
|
@@ -578,84 +585,84 @@ function _e() {
|
|
|
578
585
|
}
|
|
579
586
|
return "https://api.picked.app";
|
|
580
587
|
}
|
|
581
|
-
function
|
|
582
|
-
if (!
|
|
588
|
+
function He() {
|
|
589
|
+
if (!se())
|
|
583
590
|
return {};
|
|
584
591
|
const t = new URLSearchParams(window.location.search), e = {}, s = /* @__PURE__ */ new Set();
|
|
585
592
|
for (const [i] of t.entries())
|
|
586
593
|
i.startsWith("picked-") && s.add(i);
|
|
587
594
|
for (const i of s) {
|
|
588
|
-
const
|
|
589
|
-
e[
|
|
595
|
+
const d = i.replace("picked-", "");
|
|
596
|
+
e[d] = t.getAll(i);
|
|
590
597
|
}
|
|
591
|
-
const o =
|
|
598
|
+
const o = B("s");
|
|
592
599
|
if (s.size > 0)
|
|
593
|
-
|
|
600
|
+
j.set(o, e);
|
|
594
601
|
else {
|
|
595
|
-
const i =
|
|
602
|
+
const i = j.get(o);
|
|
596
603
|
if (i)
|
|
597
604
|
return i.json() || {};
|
|
598
605
|
}
|
|
599
606
|
return e;
|
|
600
607
|
}
|
|
601
|
-
class
|
|
608
|
+
class K {
|
|
602
609
|
constructor(e) {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
610
|
+
m(this, "options");
|
|
611
|
+
m(this, "isReady", !1);
|
|
612
|
+
m(this, "project");
|
|
613
|
+
m(this, "plugins", {});
|
|
614
|
+
m(this, "eventBus", Oe());
|
|
615
|
+
m(this, "organizationId");
|
|
616
|
+
m(this, "projectId");
|
|
617
|
+
m(this, "apiUrl");
|
|
618
|
+
m(this, "searchParams", He());
|
|
619
|
+
m(this, "history", De());
|
|
620
|
+
m(this, "components", ye({ client: this }));
|
|
621
|
+
m(this, "experienceInstances", Z({ client: this }));
|
|
622
|
+
m(this, "experiences", ce({ client: this }));
|
|
623
|
+
m(this, "frameworks", we({ client: this }));
|
|
624
|
+
m(this, "predicates", Pe({ client: this }));
|
|
625
|
+
m(this, "features", $e());
|
|
626
|
+
m(this, "fields", Me());
|
|
627
|
+
m(this, "responses", ze({ client: this }));
|
|
628
|
+
w("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Ue(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.eventBus({ type: "initialized", version: _e() }), w("info", "Picked client initialized.");
|
|
622
629
|
}
|
|
623
630
|
start() {
|
|
624
|
-
|
|
625
|
-
|
|
631
|
+
be(this), (async () => {
|
|
632
|
+
_() && (document.body && await V(this), await ee(), await V(this), this.eventBus({ type: "ready" }), this.isReady = !0);
|
|
626
633
|
})();
|
|
627
634
|
}
|
|
628
635
|
registerFramework(e) {
|
|
629
636
|
ve(e, this.frameworks);
|
|
630
637
|
}
|
|
631
638
|
registerComponent(e, s) {
|
|
632
|
-
|
|
639
|
+
M(e, s, this.components);
|
|
633
640
|
}
|
|
634
641
|
registerPlugin(e) {
|
|
635
|
-
|
|
642
|
+
de(this, e, this.plugins);
|
|
636
643
|
}
|
|
637
644
|
registerFeature(e, s) {
|
|
638
|
-
|
|
645
|
+
Re(e, s, this.features);
|
|
639
646
|
}
|
|
640
647
|
registerPredicate(e, s) {
|
|
641
|
-
|
|
648
|
+
Be(e, s, this.predicates);
|
|
642
649
|
}
|
|
643
650
|
registerField(e) {
|
|
644
651
|
Ne(e, this.fields);
|
|
645
652
|
}
|
|
646
653
|
registerExperience(e) {
|
|
647
|
-
e.component &&
|
|
654
|
+
e.component && M(`experience:${e.id}`, e.component, this.components), ue(e, this.experiences);
|
|
648
655
|
}
|
|
649
656
|
getStateSnapshot() {
|
|
650
|
-
return
|
|
657
|
+
return Fe(this);
|
|
651
658
|
}
|
|
652
659
|
async launchExperienceById(e) {
|
|
653
660
|
const s = this.experiences.getById(e).getState();
|
|
654
661
|
if (!s) {
|
|
655
|
-
|
|
662
|
+
w("warn", `Experience with id '${e}' not found.`);
|
|
656
663
|
return;
|
|
657
664
|
}
|
|
658
|
-
|
|
665
|
+
H(this, s);
|
|
659
666
|
}
|
|
660
667
|
// private async fetchProject() {
|
|
661
668
|
// if (this.project) {
|
|
@@ -693,12 +700,12 @@ class U {
|
|
|
693
700
|
const [o, i] = s.split(":");
|
|
694
701
|
if (!o || !i)
|
|
695
702
|
return;
|
|
696
|
-
let
|
|
697
|
-
(
|
|
703
|
+
let d = i;
|
|
704
|
+
(d === "true" || d === "false") && (d = !!d), this.registerFeature(o, {
|
|
698
705
|
key: "*",
|
|
699
706
|
name: o,
|
|
700
707
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
701
|
-
decide: () =>
|
|
708
|
+
decide: () => d,
|
|
702
709
|
storage: "session"
|
|
703
710
|
});
|
|
704
711
|
} catch {
|
|
@@ -709,7 +716,7 @@ class U {
|
|
|
709
716
|
const e = this.options.predicates;
|
|
710
717
|
e && Object.entries(e).forEach(([s, o]) => {
|
|
711
718
|
if (typeof o != "function") {
|
|
712
|
-
|
|
719
|
+
w("warn", `Predicate "${s}" is not a function.`);
|
|
713
720
|
return;
|
|
714
721
|
}
|
|
715
722
|
this.registerPredicate(s, o);
|
|
@@ -719,26 +726,26 @@ class U {
|
|
|
719
726
|
return this.plugins[e] ?? {};
|
|
720
727
|
}
|
|
721
728
|
}
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
const e = new
|
|
725
|
-
return
|
|
729
|
+
m(K, "logger", w);
|
|
730
|
+
const et = (t) => {
|
|
731
|
+
const e = new K(t);
|
|
732
|
+
return ne(e), e;
|
|
726
733
|
};
|
|
727
734
|
export {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
735
|
+
K as Picked,
|
|
736
|
+
et as createClient,
|
|
737
|
+
B as createStorageKey,
|
|
738
|
+
st as isPickedRoot,
|
|
739
|
+
C as localStore,
|
|
740
|
+
j as sessionStore,
|
|
741
|
+
ot as subscribe,
|
|
742
|
+
at as supportsCookies,
|
|
743
|
+
_ as supportsDocument,
|
|
744
|
+
ct as supportsHistory,
|
|
745
|
+
ut as supportsIntersectionObserver,
|
|
746
|
+
lt as supportsLocalStorage,
|
|
747
|
+
dt as supportsLocation,
|
|
748
|
+
pt as supportsSessionStorage,
|
|
749
|
+
gt as supportsShadowRoot,
|
|
750
|
+
se as supportsWindow
|
|
744
751
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../../src/entities/feature/feature.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACnE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEjE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,OAAO,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,UAAU,EAAE,KAAK,CAAA;IACjB,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAA;CACnE;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,MAAM;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CAC1D;AAED,MAAM,MAAM,aAAa,GAAG,uBAAuB,GAAG,qBAAqB,CAAA;AAK3E,QAAA,MAAM,yBAAyB;mBAkBP,MAAM,WAAW,OAAO,KAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../../src/entities/feature/feature.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACnE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEjE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,OAAO,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,UAAU,EAAE,KAAK,CAAA;IACjB,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAA;CACnE;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS,EAAE,MAAM;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CAC1D;AAED,MAAM,MAAM,aAAa,GAAG,uBAAuB,GAAG,qBAAqB,CAAA;AAK3E,QAAA,MAAM,yBAAyB;mBAkBP,MAAM,WAAW,OAAO,KAAG,IAAI;sBA0K5B,MAAM;;CAS/B,CAAA;AAEF,wBAAgB,kBAAkB,IAAI,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAEjF;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,SAAS,OAAO,EAAE,UAAU,aAAa,SAEnF,CAAA"}
|