@picked/client 0.0.28-next.1 → 0.0.28
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,4 +1,4 @@
|
|
|
1
|
-
"use strict";var M=Object.defineProperty;var V=(t,e,r)=>e in t?M(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"),v=require("@withease/factories"),I=require("../experience-instance-DjjpHk0t.cjs"),F=require("../logger-BsmHUUw1.cjs"),w=require("../storage-YlR83AWP.cjs"),N=require("../id-BKIWbSTy.cjs"),_=require("../object-BbFTsGh3.cjs"),S=require("../supports-YvpQZxbh.cjs"),z=f.createDomain("experience"),q=v.createFactory(({client:t,experience:e})=>{const r=z.store(e),n=f.createApi(r,{merge(c,m){return{...c,...m.experience}}}),i=r.map(c=>({name:c.name,decisionLogic:c.condition??c.decide,targetSelectors:c.targets,initializeOpenLogic:e.initializeOpen})),a=t.components.listStore.map(c=>c.find(m=>m.name===`experience:${e.id}`)||c.find(m=>m.name==="experience"),{skipVoid:!1}),s=r.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),o=e.actions??[];return{id:e.id,configStore:i,treeStore:s,componentStore:a,actions:o,merge:n.merge}});function K(t){return v.invoke(q,t)}const W=v.createFactory(({client:t})=>{const e=z.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 c=K({client:t,experience:s});r.register(c)}const i=e.map(s=>Object.values(s));function a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getById:a,listStore:i}});function H(t){return v.invoke(W,t)}const G=(t,e)=>{e.register(t)},U=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=I.getTargetElements(r,e.id);n.forEach(({elements:a})=>a.forEach(s=>I.tagTargetElement(s,e.id))),I.createAppHosts(n,e.id).forEach(a=>{t.experienceInstances.spawn(e,a)})},D=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await Y(t,e)&&U(t,e)}))},Y=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return I.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&I.isRulesLogic(r)?await I.evaluateRuleLogic(t,r)===!0:!0},J=(t,e,r)=>{const n=e.name,i=e.setup(t);if(i){const a=r[n]??{};r[n]=Object.freeze({...a,...i})}},Q=f.createDomain("component"),X=v.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function Z(t){return v.invoke(X,t)}const ee=v.createFactory(({client:t})=>{const e=Q.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o}}});function n(s,o){e.getState()[s]&&F.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const m=Z({client:t,name:s,component:o});r.register(m)}const i=e.map(s=>Object.values(s));function a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function te(t){return v.invoke(ee,t)}const B=(t,e,r)=>{r.register(t,e)},re=f.createDomain("framework"),ne=v.createFactory(({client:t})=>{const e=re.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o.framework}}});function n(s,o){e.getState()[s]&&F.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 a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function se(t){return v.invoke(ne,t)}const ie=(t,e)=>{e.register(t.name,t)},oe=6e3,ae=w.createStorageKey("last_ping","global"),ce=t=>`${t}/api/v1/ping`,ue=async t=>{try{const e=Date.now(),r=w.localStore.get(ae);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<oe)return!0;const i=ce(t.apiUrl),a={projectId:t.projectId,path:window.location.pathname},s=JSON.stringify(a),o={"Content-Type":"application/json"},c=document.getElementById("picked_script"),m=c==null?void 0:c.dataset.verceltoken;m&&(o["x-vercel-protection-bypass"]=m);const l=(await fetch(i,{method:"POST",headers:o,body:s})).ok;return l&&r.set(e),l}catch(e){return F.logger("error",e),!1}};function de(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"),pe=v.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]&&F.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 a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function ge(t){return v.invoke(pe,t)}const fe=(t,e,r)=>{r.register(t,e)},C=f.createDomain("feature"),me=v.createFactory(({client:t})=>{const e=C.store({}),r=C.store([]),n=f.createApi(e,{register(l,d){return{...l,[d.id]:d.feature}}});function i(l,d){e.getState()[l]&&F.logger("warn",`Feature '${l}' already registered. Registering again will override the previous registration.`);const p={id:l,feature:{...d,id:l}};n.register(Object.freeze({id:l,feature:p}))}const a=f.createEffect(async({id:l,key:d,storage:u="local"})=>{const p=w.createStorageKey(`feature:${l}:${d}`,"global"),g=(u==="session"?w.sessionStore:w.localStore).get(p).boolean();return g===null?null:{id:l,key:d,bucket:g,storage:u}}),s=f.createEffect(l=>{if(!l)return null;const d=w.createStorageKey(`feature:${l.id}:${l.key}`,"global");(l.storage==="session"?w.sessionStore:w.localStore).set(d,l.bucket)}),o=new Map,c=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:l,resolvedFeaturesStore:d},{id:u,decide:p,key:h})=>{const g=d.find(P=>P.id===u&&P.key===h);if(g)return g;const k=l[u];if(!k)throw new Error(`Feature with id '${u}' not found`);const E=o.get(`${u}:${h}`);if(E!==void 0){const P=await E;return{id:k.id,bucket:P,key:h,storage:k.feature.storage}}const R=p();o.set(`${u}:${h}`,R);const x=await R;return{id:k.id,bucket:x,key:h,storage:k.feature.storage}}});f.sample({clock:n.register,fn:l=>{const{id:d,feature:u}=l;return{id:d,key:u.feature.key,storage:u.feature.storage}},target:a}),f.sample({source:e,clock:c.doneData,fn:(l,d)=>{var k;const{id:u,bucket:p,storage:h}=d,g=(k=l[u])==null?void 0:k.feature.key;return g?{key:g,id:u,bucket:p,storage:h}:null},target:s});const m=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:l,resolvedFeaturesStore:d})=>Object.values(l).map(u=>{const p=d.find(h=>h.id===u.id&&h.key===u.feature.key);return p?{id:u.id,name:u.feature.name,key:u.feature.key,getBucket:()=>({id:u.id,bucket:p.bucket}),isResolved:!0}:{id:u.id,name:u.feature.name,key:u.feature.key,getBucket:async()=>await c(u.feature),isResolved:!1}}));f.sample({clock:c.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:l},{id:d,key:u})=>!l.some(h=>h.id===d&&h.key===u),fn:(l,d)=>d,target:t.eventBus.prepend(l=>({type:"feature_decide",feature:l}))}),f.sample({clock:[a.doneData,c.doneData],source:r,fn:(l,d)=>!d||l.some(p=>p.id===d.id&&p.key===d.key)?l:[...l,d],target:r});function b(l){return e.map(d=>d[l],{skipVoid:!1})}return{register:i,getByName:b,listStore:m}});function he(t){return v.invoke(me,t)}const ye=(t,e,r)=>{r.register(t,e)},j=f.createDomain("history");function O(t,e){return{id:N.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ve=v.createFactory(()=>{const t=j.store({entries:[]}),e=j.event(),r=j.event(),n=j.event(),i=j.event();t.on(e,(s,o)=>({entries:[...s.entries,O(o.experienceId,o.node)]})),t.on(r,(s,o)=>({entries:[...s.entries.slice(0,-1),O(o.experienceId,o.node)]})),t.on(i,(s,o)=>o);function a(s,o){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let m=s.length-1;m>=0;m--){const b=s[m],l=b==null?void 0:b.node;if(!(!l||!I.isStepNode(l))&&!(o&&(b==null?void 0:b.experienceId)!==o))if(c.lastStepIndex===-1)c.lastStepIndex=m;else{c.secondLastStepIndex=m;break}}return c}return t.on(n,(s,o)=>{const{secondLastStepIndex:c}=a(s.entries,o.experienceId),m=c!==-1?s.entries.slice(0,c+1):s.entries;return{...s,entries:m}}),{push:e,replace:r,back:n,restore:i,entriesStore:t.map(s=>s.entries)}});function Se(){return v.invoke(ve)}const ke=()=>f.createEvent(),we=f.createDomain("field"),Ie=v.createFactory(()=>{const t=we.store({}),e=f.createApi(t,{register(o,c){return{...o,[c.field.id]:c.field}}});function r(o){e.register({field:o})}function n(o,c){const m=a(o).getState();if(!m)return;const b=Object.assign({},m,{...c});e.register({field:{...b}})}const i=t.map(o=>Object.values(o));function a(o){return t.map(c=>c[o]||null)}function s(o){return t.map(c=>Object.values(c).find(m=>m.name===o)||null)}return{register:r,update:n,getById:a,listStore:i,getByName:s}});function be(){return v.invoke(Ie)}const Fe=(t,e)=>{e.register(t)},Ee=f.createDomain("action"),xe=v.createFactory(()=>{const t=Ee.store({}),e=f.createApi(t,{register(a,s){return{...a,[s.name]:{name:s.name,action:s.action}}}});function r(a,s){e.register({name:a,action:s})}const n=t.map(a=>Object.values(a));function i(a){return t.map(s=>s[a],{skipVoid:!1})}return{register:r,getByName:i,listStore:n}});function je(){return v.invoke(xe)}const Re=(t,e,r)=>{r.register(t,e)};function $(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const Pe=f.createDomain("response"),Ae=v.createFactory(({client:t})=>{const e=Pe.store({}),r=f.createEvent(),n=f.createEvent(),i=f.createApi(e,{register(d,u){return{...d,[u.fieldId]:u.response}},registerBatch(d,u){return{...d,...u}},clear(d,u){const{[u]:p,...h}=d;return h},clearAll(){return{}}});function a(d,u){i.register({fieldId:d,response:u})}async function s(d){const u=[];return await Promise.allSettled(Object.entries(d).map(async([p,h])=>{let g=h;const k=t.fields.getById(p).getState();if(!k){u.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(k.multiple&&(typeof g=="string"||typeof g=="number"||typeof g=="boolean")&&(g=[g]),k.validation&&!_.isEmpty(k.validation)&&!$(g)){const E=await I.evaluateRuleLogic(t,k.validation,{$input:g});if(typeof E=="string"){u.push({fieldId:p,userMessage:E,systemMessage:`Field validation resulted in an error: ${E}.`,value:g});return}if(E===!1){u.push({fieldId:p,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(k.required&&$(g)){u.push({fieldId:p,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!k.multiple&&Array.isArray(g)&&g.length>1){u.push({fieldId:p,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(k.options){const E=k.options.map(x=>x.value),R=Array.isArray(g)?g:[g];Array.isArray(g)&&(R.every(x=>E.includes(x))||u.push({fieldId:p,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${E.join(", ")}`,value:g}))}})),{responsesToCommit:d,validationErrors:u}}async function o(d){const{responsesToCommit:u,validationErrors:p}=await s(d);return p.length?{errors:p}:(i.registerBatch(u),{errors:[]})}const c=e.map(d=>d),m=e.map(d=>Object.keys(d).map(p=>({fieldId:p,value:d[p]})));function b(d){const u=t.fields.getById(d),p=e.map(h=>h[d]||null);return f.combine({f:u,r:p},({f:h,r:g})=>g||(h!=null&&h.defaultValue?h.defaultValue:null))}function l(d){const u=t.fields.getByName(d);return f.combine({f:u,s:e},({f:p,s:h})=>{const g=p&&h[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:a,clearAll:r,clear:n,commit:o,getResponsesToCommit:s,listStore:m,getAllStore:c,getByFieldId:b,getByFieldName:l}});function De(t){return v.invoke(Ae,t)}const Be=()=>"0.0.28-next.1";function Ce(){if(S.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 Oe(){if(!S.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 a=i.replace("picked-","");e[a]=t.getAll(i)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const i=w.sessionStore.get(n);if(i)return i.json()||{}}return e}function $e(){if(S.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 ze=w.createStorageKey("session","global"),Ue=()=>{const t=w.localStore.get(ze);let e;t.isSet()&&(e=t.json());const r=i=>t.set({id:i.id,isUser:i.isUser,identifiers:i.identifiers}),n={id:(e==null?void 0:e.id)??$e(),isUser:(e==null?void 0:e.isUser)??void 0,identifiers:(e==null?void 0:e.identifiers)??void 0,setIsUser(i){this.isUser=i,r(this)},setIdentifier(i,a){this.identifiers={...this.identifiers,[i]:a},r(this)},removeIdentifier(i){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([a])=>a!==i)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(n),n},Le=()=>S.supportsLocalStorage()?Ue():null;function L(){if(S.supportsWindow())return globalThis.window.pickedConfig}function Te(){if(!S.supportsWindow())return;const t=L(),e=t==null?void 0:t.organizationId,r=t==null?void 0:t.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function Me(){if(!S.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function Ve(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const n=Te();if(n)return n;const i=Me();if(i)return i;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
1
|
+
"use strict";var N=Object.defineProperty;var V=(t,e,r)=>e in t?N(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"),b=require("../experience-instance-DjjpHk0t.cjs"),F=require("../logger-BsmHUUw1.cjs"),w=require("../storage-YlR83AWP.cjs"),_=require("../id-BKIWbSTy.cjs"),q=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),U=f.createDomain("experience"),K=S.createFactory(({client:t,experience:e})=>{const r=U.store(e),n=f.createApi(r,{merge(c,m){return{...c,...m.experience}}}),i=r.map(c=>({name:c.name,decisionLogic:c.condition??c.decide,targetSelectors:c.targets,initializeOpenLogic:e.initializeOpen})),a=t.components.listStore.map(c=>c.find(m=>m.name===`experience:${e.id}`)||c.find(m=>m.name==="experience"),{skipVoid:!1}),s=r.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),o=e.actions??[];return{id:e.id,configStore:i,treeStore:s,componentStore:a,actions:o,merge:n.merge}});function W(t){return S.invoke(K,t)}const H=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 c=W({client:t,experience:s});r.register(c)}const i=e.map(s=>Object.values(s));function a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getById:a,listStore:i}});function G(t){return S.invoke(H,t)}const Y=(t,e)=>{e.register(t)},L=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=b.getTargetElements(r,e.id);n.forEach(({elements:a})=>a.forEach(s=>b.tagTargetElement(s,e.id))),b.createAppHosts(n,e.id).forEach(a=>{t.experienceInstances.spawn(e,a)})},$=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await J(t,e)&&L(t,e)}))},J=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return b.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&b.isRulesLogic(r)?await b.evaluateRuleLogic(t,r)===!0:!0},Q=(t,e,r)=>{const n=e.name,i=e.setup(t);if(i){const a=r[n]??{};r[n]=Object.freeze({...a,...i})}},X=f.createDomain("component"),Z=S.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function ee(t){return S.invoke(Z,t)}const te=S.createFactory(({client:t})=>{const e=X.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o}}});function n(s,o){e.getState()[s]&&F.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const m=ee({client:t,name:s,component:o});r.register(m)}const i=e.map(s=>Object.values(s));function a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function re(t){return S.invoke(te,t)}const B=(t,e,r)=>{r.register(t,e)},ne=f.createDomain("framework"),se=S.createFactory(({client:t})=>{const e=ne.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o.framework}}});function n(s,o){e.getState()[s]&&F.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 a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function ie(t){return S.invoke(se,t)}const oe=(t,e)=>{e.register(t.name,t)},ae=6e3,ce=w.createStorageKey("last_ping","global"),ue=t=>`${t}/api/v1/ping`,de=async t=>{try{const e=Date.now(),r=w.localStore.get(ce);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<ae)return!0;const i=ue(t.apiUrl),a={projectId:t.projectId,path:window.location.pathname},s=JSON.stringify(a),o={"Content-Type":"application/json"},c=document.getElementById("picked_script"),m=c==null?void 0:c.dataset.verceltoken;m&&(o["x-vercel-protection-bypass"]=m);const l=(await fetch(i,{method:"POST",headers:o,body:s})).ok;return l&&r.set(e),l}catch(e){return F.logger("error",e),!1}};function le(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 pe=f.createDomain("predicate"),ge=S.createFactory(({client:t})=>{const e=pe.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]&&F.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 a(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:a,listStore:i}});function fe(t){return S.invoke(ge,t)}const me=(t,e,r)=>{r.register(t,e)},C=f.createDomain("feature"),ye=S.createFactory(({client:t})=>{const e=C.store({}),r=C.store([]),n=f.createApi(e,{register(l,d){return{...l,[d.id]:d.feature}}});function i(l,d){e.getState()[l]&&F.logger("warn",`Feature '${l}' already registered. Registering again will override the previous registration.`);const p={id:l,feature:{...d,id:l}};n.register(Object.freeze({id:l,feature:p}))}const a=f.createEffect(async({id:l,key:d,storage:u="local"})=>{const p=w.createStorageKey(`feature:${l}:${d}`,"global"),g=(u==="session"?w.sessionStore:w.localStore).get(p).boolean();return g===null?null:{id:l,key:d,bucket:g,storage:u}}),s=f.createEffect(l=>{if(!l)return null;const d=w.createStorageKey(`feature:${l.id}:${l.key}`,"global");(l.storage==="session"?w.sessionStore:w.localStore).set(d,l.bucket)}),o=new Map,c=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:l,resolvedFeaturesStore:d},{id:u,decide:p,key:y})=>{const g=d.find(A=>A.id===u&&A.key===y);if(g)return g;const v=l[u];if(!v)throw new Error(`Feature with id '${u}' not found`);const E=o.get(`${u}:${y}`);if(E!==void 0){const A=await E;return{id:v.id,bucket:A,key:y,storage:v.feature.storage}}const R=p();o.set(`${u}:${y}`,R);const j=await R;return{id:v.id,bucket:j,key:y,storage:v.feature.storage}}});f.sample({clock:n.register,fn:l=>{const{id:d,feature:u}=l;return{id:d,key:u.feature.key,storage:u.feature.storage}},target:a}),f.sample({source:e,clock:c.doneData,fn:(l,d)=>{var v;const{id:u,bucket:p,storage:y}=d,g=(v=l[u])==null?void 0:v.feature.key;return g?{key:g,id:u,bucket:p,storage:y}:null},target:s});const m=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:l,resolvedFeaturesStore:d})=>Object.values(l).map(u=>{const p=d.find(y=>y.id===u.id&&y.key===u.feature.key);return p?{id:u.id,name:u.feature.name,key:u.feature.key,getBucket:()=>({id:u.id,bucket:p.bucket}),isResolved:!0}:{id:u.id,name:u.feature.name,key:u.feature.key,getBucket:async()=>await c(u.feature),isResolved:!1}}));f.sample({clock:c.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:l},{id:d,key:u})=>!l.some(y=>y.id===d&&y.key===u),fn:(l,d)=>d,target:t.eventBus.prepend(l=>({type:"feature_decide",feature:l}))}),f.sample({clock:[a.doneData,c.doneData],source:r,fn:(l,d)=>!d||l.some(p=>p.id===d.id&&p.key===d.key)?l:[...l,d],target:r});function I(l){return e.map(d=>d[l],{skipVoid:!1})}return{register:i,getByName:I,listStore:m}});function he(t){return S.invoke(ye,t)}const Se=(t,e,r)=>{r.register(t,e)},x=f.createDomain("history");function O(t,e){return{id:_.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ke=S.createFactory(()=>{const t=x.store({entries:[]}),e=x.event(),r=x.event(),n=x.event(),i=x.event();t.on(e,(s,o)=>({entries:[...s.entries,O(o.experienceId,o.node)]})),t.on(r,(s,o)=>({entries:[...s.entries.slice(0,-1),O(o.experienceId,o.node)]})),t.on(i,(s,o)=>o);function a(s,o){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let m=s.length-1;m>=0;m--){const I=s[m],l=I==null?void 0:I.node;if(!(!l||!b.isStepNode(l))&&!(o&&(I==null?void 0:I.experienceId)!==o))if(c.lastStepIndex===-1)c.lastStepIndex=m;else{c.secondLastStepIndex=m;break}}return c}return t.on(n,(s,o)=>{const{secondLastStepIndex:c}=a(s.entries,o.experienceId),m=c!==-1?s.entries.slice(0,c+1):s.entries;return{...s,entries:m}}),{push:e,replace:r,back:n,restore:i,entriesStore:t.map(s=>s.entries)}});function ve(){return S.invoke(ke)}const we=()=>f.createEvent(),Ie=f.createDomain("field"),be=S.createFactory(()=>{const t=Ie.store({}),e=f.createApi(t,{register(o,c){return{...o,[c.field.id]:c.field}}});function r(o){e.register({field:o})}function n(o,c){const m=a(o).getState();if(!m)return;const I=Object.assign({},m,{...c});e.register({field:{...I}})}const i=t.map(o=>Object.values(o));function a(o){return t.map(c=>c[o]||null)}function s(o){return t.map(c=>Object.values(c).find(m=>m.name===o)||null)}return{register:r,update:n,getById:a,listStore:i,getByName:s}});function Fe(){return S.invoke(be)}const Ee=(t,e)=>{e.register(t)},je=f.createDomain("action"),xe=S.createFactory(()=>{const t=je.store({}),e=f.createApi(t,{register(a,s){return{...a,[s.name]:{name:s.name,action:s.action}}}});function r(a,s){e.register({name:a,action:s})}const n=t.map(a=>Object.values(a));function i(a){return t.map(s=>s[a],{skipVoid:!1})}return{register:r,getByName:i,listStore:n}});function Re(){return S.invoke(xe)}const Ae=(t,e,r)=>{r.register(t,e)};function z(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}const Pe=f.createDomain("response"),De=S.createFactory(({client:t})=>{const e=Pe.store({}),r=f.createEvent(),n=f.createEvent(),i=f.createApi(e,{register(d,u){return{...d,[u.fieldId]:u.response}},registerBatch(d,u){return{...d,...u}},clear(d,u){const{[u]:p,...y}=d;return y},clearAll(){return{}}});function a(d,u){i.register({fieldId:d,response:u})}async function s(d){const u=[];return await Promise.allSettled(Object.entries(d).map(async([p,y])=>{let g=y;const v=t.fields.getById(p).getState();if(!v){u.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&&!q.isEmpty(v.validation)&&!z(g)){const E=await b.evaluateRuleLogic(t,v.validation,{$input:g});if(typeof E=="string"){u.push({fieldId:p,userMessage:E,systemMessage:`Field validation resulted in an error: ${E}.`,value:g});return}if(E===!1){u.push({fieldId:p,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(v.required&&z(g)){u.push({fieldId:p,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!v.multiple&&Array.isArray(g)&&g.length>1){u.push({fieldId:p,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(v.options){const E=v.options.map(j=>j.value),R=Array.isArray(g)?g:[g];Array.isArray(g)&&(R.every(j=>E.includes(j))||u.push({fieldId:p,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${E.join(", ")}`,value:g}))}})),{responsesToCommit:d,validationErrors:u}}async function o(d){const{responsesToCommit:u,validationErrors:p}=await s(d);return p.length?{errors:p}:(i.registerBatch(u),{errors:[]})}const c=e.map(d=>d),m=e.map(d=>Object.keys(d).map(p=>({fieldId:p,value:d[p]})));function I(d){const u=t.fields.getById(d),p=e.map(y=>y[d]||null);return f.combine({f:u,r:p},({f:y,r:g})=>g||(y!=null&&y.defaultValue?y.defaultValue:null))}function l(d){const u=t.fields.getByName(d);return f.combine({f:u,s:e},({f:p,s:y})=>{const g=p&&y[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:a,clearAll:r,clear:n,commit:o,getResponsesToCommit:s,listStore:m,getAllStore:c,getByFieldId:I,getByFieldName:l}});function $e(t){return S.invoke(De,t)}const Be=()=>"0.0.28";function Ce(){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 Oe(){if(!k.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 a=i.replace("picked-","");e[a]=t.getAll(i)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const i=w.sessionStore.get(n);if(i)return i.json()||{}}return e}function ze(){if(k.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 Ue=w.createStorageKey("session","global"),Le=()=>{const t=w.localStore.get(Ue);let e;t.isSet()&&(e=t.json());const r=i=>t.set({id:i.id,isUser:i.isUser,identifiers:i.identifiers}),n={id:(e==null?void 0:e.id)??ze(),isUser:(e==null?void 0:e.isUser)??void 0,identifiers:(e==null?void 0:e.identifiers)??void 0,setIsUser(i){this.isUser=i,r(this)},setIdentifier(i,a){this.identifiers={...this.identifiers,[i]:a},r(this)},removeIdentifier(i){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([a])=>a!==i)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(n),n},Me=()=>k.supportsLocalStorage()?Le():null;function M(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Te(){if(!k.supportsWindow())return;const t=M(),e=t==null?void 0:t.organizationId,r=t==null?void 0:t.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function Ne(){if(!k.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function Ve(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const n=Te();if(n)return n;const i=Ne();if(i)return i;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
2
2
|
(1) createClient({ organizationId, projectId }) options;
|
|
3
3
|
(2) window.pickedConfig = { organizationId, projectId };
|
|
4
|
-
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`)}class
|
|
4
|
+
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`)}function P(t){return t==null||t===""||Number.isNaN(t)}const _e={default:(t,e)=>P(t)?String(e??""):String(t),append:(t,e)=>e&&!P(t)?`${t} ${e}`:t,prepend:(t,e)=>e&&!P(t)?`${e} ${t}`:t,upper:t=>typeof t=="string"?t.toUpperCase():t,lower:t=>typeof t=="string"?t.toLowerCase():t,capitalize:t=>typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1):t,list:t=>{if(!t||typeof t!="object")return t;const e=new Intl.ListFormat("en",{style:"long",type:"conjunction"});if(Array.isArray(t))return e.format(t.map(String));if(t instanceof Map){const r=Array.from(t.entries()).map(([n,i])=>`${n}: ${i}`);return e.format(r)}return t instanceof Set?e.format(Array.from(t).map(String)):t}};function qe(t){return typeof t=="object"&&t!==null}function Ke(t,e){let r=e;for(const n of t.split("."))if(qe(r)&&n in r)r=r[n];else return;return typeof r=="function"?r():r}function We(t,e){const r=t.split("|").map(a=>a.trim()),n=r.shift()??"";let i=Ke(n,e);for(const a of r){const[s,...o]=a.split(":"),c=(s==null?void 0:s.trim())??"",m=o.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),I=_e[c];I&&(i=I(i,m))}return P(i)?"":typeof i=="object"?JSON.stringify(i):String(i)}function He(t,e){let r="",n=0;for(;n<t.length;)if(t[n]==="{"&&t[n+1]==="{"){n+=2;let i="";for(;n<t.length;){if(t[n]==="}"&&t[n+1]==="}"){n+=2;break}i+=t[n++]}r+=We(i.trim(),e)}else r+=t[n++];return r}class D{constructor(e){h(this,"options");h(this,"isReady",!1);h(this,"project");h(this,"plugins",{});h(this,"eventBus",we());h(this,"organizationId");h(this,"projectId");h(this,"apiUrl");h(this,"session");h(this,"precondition");h(this,"condition");h(this,"searchParams",Oe());h(this,"history",ve());h(this,"components",re({client:this}));h(this,"experienceInstances",b.createExperienceInstanceIndex({client:this}));h(this,"experiences",G({client:this}));h(this,"frameworks",ie({client:this}));h(this,"predicates",fe({client:this}));h(this,"features",he({client:this}));h(this,"responses",$e({client:this}));h(this,"fields",Fe());h(this,"actions",Re());h(this,"renderString",(e,r)=>{const n=this.responses.listStore.getState().reduce((i,a)=>(i[a.fieldId]=a.value,i),{});return He(e,{...r,responses:n})});F.logger("info","Picked client initializing.");const{organizationId:r,projectId:n}=Ve(e);this.organizationId=r,this.projectId=n,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Ce(),this.session=Me(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Be()}),F.logger("info","Picked client initialized.")}start(){de(this),(async()=>{if(!k.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await b.evaluateRuleLogic(this,this.precondition)===!0;let n;r&&(this.condition===void 0?n=!0:typeof this.condition=="boolean"?n=this.condition:n=await b.evaluateRuleLogic(this,this.condition)===!0);const i=r&&n===!0;if(typeof n=="boolean"&&this.session){const a=n;this.session.setIsUser(a),this.eventBus({type:"user_decide",value:a})}this.eventBus({type:"initialize"}),document.body&&i&&$(this),await b.domInteractive(),i&&$(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session})})()}registerFramework(e){oe(e,this.frameworks)}registerComponent(e,r){B(e,r,this.components)}registerPlugin(e){Q(this,e,this.plugins)}registerFeature(e,r){Se(e,r,this.features)}registerPredicate(e,r){me(e,r,this.predicates)}registerField(e){Ee(e,this.fields)}registerAction(e,r){Ae(e,r,this.actions)}registerExperience(e){e.component&&B(`experience:${e.id}`,e.component,this.components),Y(e,this.experiences)}getStateSnapshot(){return le(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){F.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 a=i;a==="true"&&(a=!0),a==="false"&&(a=!1),this.registerFeature(n,{key:`${a}`,name:n,decide:()=>a,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){F.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"){F.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}h(D,"logger",F.logger);function T(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Ge(t){return t.some(e=>e.condition||T(e))}async function Ye(t,e){return e.length===0||!Ge(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await b.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!T(n))return n;const s=(await Promise.all(n.options.map(async c=>c.condition?await b.evaluateRuleLogic(t,c.condition)?c:null:c))).filter(c=>c!==null);return s.length===n.options.length?n:s.length===0?null:{...n,options:s}}))).filter(n=>n!==null)}const Je=t=>{const e=new D(t);return k.bindClient(e),e};exports.evaluateRuleLogic=b.evaluateRuleLogic;exports.isPickedRoot=b.isPickedRoot;exports.createStorageKey=w.createStorageKey;exports.localStore=w.localStore;exports.sessionStore=w.sessionStore;exports.subscribe=w.subscribe;exports.supportsCookies=k.supportsCookies;exports.supportsCryptoRandomUUID=k.supportsCryptoRandomUUID;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.supportsWebComponents=k.supportsWebComponents;exports.supportsWindow=k.supportsWindow;exports.Picked=D;exports.createClient=Je;exports.getPickedConfig=M;exports.getStepFields=Ye;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (t, e, r) =>
|
|
4
|
-
import { createDomain as b, createApi as F, createEffect as
|
|
5
|
-
import { createFactory 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 { h as
|
|
15
|
-
const
|
|
1
|
+
var J = Object.defineProperty;
|
|
2
|
+
var Q = (t, e, r) => e in t ? J(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var h = (t, e, r) => Q(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { createDomain as b, createApi as F, createEffect as N, attach as X, sample as x, combine as z, createEvent as D } from "effector";
|
|
5
|
+
import { createFactory as w, invoke as I } from "@withease/factories";
|
|
6
|
+
import { g as H, t as Z, c as ee, i as te, e as j, a as re, b as ne, d as se } from "../experience-instance-C4INDX6a.js";
|
|
7
|
+
import { f as Pt } from "../experience-instance-C4INDX6a.js";
|
|
8
|
+
import { l as k } from "../logger-C9a75KZn.js";
|
|
9
|
+
import { c as A, l as O, s as C } from "../storage-BLmAhfhl.js";
|
|
10
|
+
import { a as Rt } from "../storage-BLmAhfhl.js";
|
|
11
|
+
import { g as ie } from "../id-BW-g3y32.js";
|
|
12
|
+
import { i as oe } from "../object-JwZ58NOH.js";
|
|
13
|
+
import { s as U, a as M, b as ae, c as ce, d as ue } from "../supports-BjhuLJ8z.js";
|
|
14
|
+
import { h as Bt, f as Ot, j as Ct, e as zt, g as Dt, i as Ut, k as Mt } from "../supports-BjhuLJ8z.js";
|
|
15
|
+
const q = b("experience"), de = w(
|
|
16
16
|
({ client: t, experience: e }) => {
|
|
17
|
-
const r =
|
|
18
|
-
merge(c,
|
|
17
|
+
const r = q.store(e), n = F(r, {
|
|
18
|
+
merge(c, g) {
|
|
19
19
|
return {
|
|
20
20
|
...c,
|
|
21
|
-
...
|
|
21
|
+
...g.experience
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
}), i = r.map((c) => ({
|
|
@@ -27,7 +27,7 @@ const H = b("experience"), ue = k(
|
|
|
27
27
|
targetSelectors: c.targets,
|
|
28
28
|
initializeOpenLogic: e.initializeOpen
|
|
29
29
|
})), a = t.components.listStore.map(
|
|
30
|
-
(c) => c.find((
|
|
30
|
+
(c) => c.find((g) => g.name === `experience:${e.id}`) || c.find((g) => g.name === "experience"),
|
|
31
31
|
{ skipVoid: !1 }
|
|
32
32
|
), s = r.map((c) => ({
|
|
33
33
|
steps: c.steps,
|
|
@@ -45,11 +45,11 @@ const H = b("experience"), ue = k(
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
);
|
|
48
|
-
function
|
|
49
|
-
return
|
|
48
|
+
function le(t) {
|
|
49
|
+
return I(de, t);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
const e =
|
|
51
|
+
const pe = w(({ client: t }) => {
|
|
52
|
+
const e = q.store({}), r = F(e, {
|
|
53
53
|
register(s, o) {
|
|
54
54
|
return {
|
|
55
55
|
...s,
|
|
@@ -63,7 +63,7 @@ const le = k(({ client: t }) => {
|
|
|
63
63
|
o.merge({ experience: s, strategy: "override" });
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const c =
|
|
66
|
+
const c = le({ client: t, experience: s });
|
|
67
67
|
r.register(c);
|
|
68
68
|
}
|
|
69
69
|
const i = e.map((s) => Object.values(s));
|
|
@@ -76,34 +76,34 @@ const le = k(({ client: t }) => {
|
|
|
76
76
|
listStore: i
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
|
-
function
|
|
80
|
-
return
|
|
79
|
+
function fe(t) {
|
|
80
|
+
return I(pe, t);
|
|
81
81
|
}
|
|
82
82
|
const ge = (t, e) => {
|
|
83
83
|
e.register(t);
|
|
84
|
-
},
|
|
85
|
-
const { targetSelectors: r } = e.configStore.getState(), n =
|
|
84
|
+
}, K = (t, e) => {
|
|
85
|
+
const { targetSelectors: r } = e.configStore.getState(), n = H(r, e.id);
|
|
86
86
|
n.forEach(
|
|
87
|
-
({ elements: a }) => a.forEach((s) =>
|
|
88
|
-
),
|
|
87
|
+
({ elements: a }) => a.forEach((s) => Z(s, e.id))
|
|
88
|
+
), ee(n, e.id).forEach((a) => {
|
|
89
89
|
t.experienceInstances.spawn(e, a);
|
|
90
90
|
});
|
|
91
|
-
},
|
|
91
|
+
}, V = async (t) => {
|
|
92
92
|
await Promise.all(
|
|
93
93
|
t.experiences.listStore.getState().map(async (e) => {
|
|
94
|
-
await
|
|
94
|
+
await me(t, e) && K(t, e);
|
|
95
95
|
})
|
|
96
96
|
);
|
|
97
|
-
},
|
|
97
|
+
}, me = async (t, e) => {
|
|
98
98
|
const { decisionLogic: r, targetSelectors: n } = e.configStore.getState();
|
|
99
|
-
return
|
|
100
|
-
},
|
|
99
|
+
return H(n, e.id).length < 1 || n.length === 0 ? !1 : r && te(r) ? await j(t, r) === !0 : !0;
|
|
100
|
+
}, he = (t, e, r) => {
|
|
101
101
|
const n = e.name, i = e.setup(t);
|
|
102
102
|
if (i) {
|
|
103
103
|
const a = r[n] ?? {};
|
|
104
104
|
r[n] = Object.freeze({ ...a, ...i });
|
|
105
105
|
}
|
|
106
|
-
},
|
|
106
|
+
}, ye = b("component"), Se = w(
|
|
107
107
|
({ client: t, component: e, name: r }) => {
|
|
108
108
|
const n = t.frameworks.getByName(e.frameworkName);
|
|
109
109
|
return {
|
|
@@ -113,11 +113,11 @@ const ge = (t, e) => {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
-
function
|
|
117
|
-
return
|
|
116
|
+
function ke(t) {
|
|
117
|
+
return I(Se, t);
|
|
118
118
|
}
|
|
119
|
-
const
|
|
120
|
-
const e =
|
|
119
|
+
const we = w(({ client: t }) => {
|
|
120
|
+
const e = ye.store({}), r = F(e, {
|
|
121
121
|
register(s, o) {
|
|
122
122
|
return {
|
|
123
123
|
...s,
|
|
@@ -126,12 +126,12 @@ const Se = k(({ client: t }) => {
|
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
function n(s, o) {
|
|
129
|
-
e.getState()[s] &&
|
|
129
|
+
e.getState()[s] && k(
|
|
130
130
|
"warn",
|
|
131
131
|
`Component '${s}' already registered. Registering again will override the previous registration.`
|
|
132
132
|
);
|
|
133
|
-
const
|
|
134
|
-
r.register(
|
|
133
|
+
const g = ke({ client: t, name: s, component: o });
|
|
134
|
+
r.register(g);
|
|
135
135
|
}
|
|
136
136
|
const i = e.map((s) => Object.values(s));
|
|
137
137
|
function a(s) {
|
|
@@ -143,13 +143,13 @@ const Se = k(({ client: t }) => {
|
|
|
143
143
|
listStore: i
|
|
144
144
|
};
|
|
145
145
|
});
|
|
146
|
-
function
|
|
147
|
-
return
|
|
146
|
+
function Ie(t) {
|
|
147
|
+
return I(we, t);
|
|
148
148
|
}
|
|
149
|
-
const
|
|
149
|
+
const T = (t, e, r) => {
|
|
150
150
|
r.register(t, e);
|
|
151
|
-
},
|
|
152
|
-
const e =
|
|
151
|
+
}, ve = b("framework"), be = w(({ client: t }) => {
|
|
152
|
+
const e = ve.store({}), r = F(e, {
|
|
153
153
|
register(s, o) {
|
|
154
154
|
return {
|
|
155
155
|
...s,
|
|
@@ -158,7 +158,7 @@ const V = (t, e, r) => {
|
|
|
158
158
|
}
|
|
159
159
|
});
|
|
160
160
|
function n(s, o) {
|
|
161
|
-
e.getState()[s] &&
|
|
161
|
+
e.getState()[s] && k(
|
|
162
162
|
"warn",
|
|
163
163
|
`Framework '${s}' already registered. Registering again will override the previous registration.`
|
|
164
164
|
), r.register({ name: s, framework: o });
|
|
@@ -173,24 +173,24 @@ const V = (t, e, r) => {
|
|
|
173
173
|
listStore: i
|
|
174
174
|
};
|
|
175
175
|
});
|
|
176
|
-
function
|
|
177
|
-
return
|
|
176
|
+
function Fe(t) {
|
|
177
|
+
return I(be, t);
|
|
178
178
|
}
|
|
179
|
-
const
|
|
179
|
+
const xe = (t, e) => {
|
|
180
180
|
e.register(t.name, t);
|
|
181
|
-
},
|
|
181
|
+
}, je = 6e3, Ee = A("last_ping", "global"), Pe = (t) => `${t}/api/v1/ping`, Ae = async (t) => {
|
|
182
182
|
try {
|
|
183
|
-
const e = Date.now(), r =
|
|
183
|
+
const e = Date.now(), r = O.get(Ee);
|
|
184
184
|
let n = 0;
|
|
185
|
-
if (r.isSet() && (n = r.json() ?? 0), n && e - n <
|
|
185
|
+
if (r.isSet() && (n = r.json() ?? 0), n && e - n < je)
|
|
186
186
|
return !0;
|
|
187
|
-
const i =
|
|
187
|
+
const i = Pe(t.apiUrl), a = {
|
|
188
188
|
projectId: t.projectId,
|
|
189
189
|
path: window.location.pathname
|
|
190
190
|
}, s = JSON.stringify(a), o = {
|
|
191
191
|
"Content-Type": "application/json"
|
|
192
|
-
}, c = document.getElementById("picked_script"),
|
|
193
|
-
|
|
192
|
+
}, c = document.getElementById("picked_script"), g = c == null ? void 0 : c.dataset.verceltoken;
|
|
193
|
+
g && (o["x-vercel-protection-bypass"] = g);
|
|
194
194
|
const l = (await fetch(i, {
|
|
195
195
|
method: "POST",
|
|
196
196
|
headers: o,
|
|
@@ -198,7 +198,7 @@ const Fe = (t, e) => {
|
|
|
198
198
|
})).ok;
|
|
199
199
|
return l && r.set(e), l;
|
|
200
200
|
} catch (e) {
|
|
201
|
-
return
|
|
201
|
+
return k("error", e), !1;
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
function Re(t) {
|
|
@@ -213,8 +213,8 @@ function Re(t) {
|
|
|
213
213
|
};
|
|
214
214
|
return Object.freeze(r);
|
|
215
215
|
}
|
|
216
|
-
const
|
|
217
|
-
const e =
|
|
216
|
+
const $e = b("predicate"), Be = w(({ client: t }) => {
|
|
217
|
+
const e = $e.store({}), r = F(e, {
|
|
218
218
|
register(s, o) {
|
|
219
219
|
return {
|
|
220
220
|
...s,
|
|
@@ -226,7 +226,7 @@ const Be = b("predicate"), Ae = k(({ client: t }) => {
|
|
|
226
226
|
}
|
|
227
227
|
});
|
|
228
228
|
function n(s, o) {
|
|
229
|
-
e.getState()[s] &&
|
|
229
|
+
e.getState()[s] && k(
|
|
230
230
|
"warn",
|
|
231
231
|
`Predicate '${s}' already registered. Registering again will override the previous registration.`
|
|
232
232
|
), r.register(Object.freeze({ name: s, predicate: o }));
|
|
@@ -241,13 +241,13 @@ const Be = b("predicate"), Ae = k(({ client: t }) => {
|
|
|
241
241
|
listStore: i
|
|
242
242
|
};
|
|
243
243
|
});
|
|
244
|
-
function
|
|
245
|
-
return
|
|
244
|
+
function Oe(t) {
|
|
245
|
+
return I(Be, t);
|
|
246
246
|
}
|
|
247
|
-
const
|
|
247
|
+
const Ce = (t, e, r) => {
|
|
248
248
|
r.register(t, e);
|
|
249
|
-
},
|
|
250
|
-
const e =
|
|
249
|
+
}, _ = b("feature"), ze = w(({ client: t }) => {
|
|
250
|
+
const e = _.store({}), r = _.store([]), n = F(e, {
|
|
251
251
|
register(l, d) {
|
|
252
252
|
return {
|
|
253
253
|
...l,
|
|
@@ -256,7 +256,7 @@ const Oe = (t, e, r) => {
|
|
|
256
256
|
}
|
|
257
257
|
});
|
|
258
258
|
function i(l, d) {
|
|
259
|
-
e.getState()[l] &&
|
|
259
|
+
e.getState()[l] && k(
|
|
260
260
|
"warn",
|
|
261
261
|
`Feature '${l}' already registered. Registering again will override the previous registration.`
|
|
262
262
|
);
|
|
@@ -274,40 +274,40 @@ const Oe = (t, e, r) => {
|
|
|
274
274
|
})
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
|
-
const a =
|
|
277
|
+
const a = N(
|
|
278
278
|
async ({
|
|
279
279
|
id: l,
|
|
280
280
|
key: d,
|
|
281
281
|
storage: u = "local"
|
|
282
282
|
}) => {
|
|
283
|
-
const p =
|
|
284
|
-
return
|
|
283
|
+
const p = A(`feature:${l}:${d}`, "global"), f = (u === "session" ? C : O).get(p).boolean();
|
|
284
|
+
return f === null ? null : { id: l, key: d, bucket: f, storage: u };
|
|
285
285
|
}
|
|
286
|
-
), s =
|
|
286
|
+
), s = N((l) => {
|
|
287
287
|
if (!l)
|
|
288
288
|
return null;
|
|
289
|
-
const d =
|
|
290
|
-
(l.storage === "session" ?
|
|
291
|
-
}), o = /* @__PURE__ */ new Map(), c =
|
|
289
|
+
const d = A(`feature:${l.id}:${l.key}`, "global");
|
|
290
|
+
(l.storage === "session" ? C : O).set(d, l.bucket);
|
|
291
|
+
}), o = /* @__PURE__ */ new Map(), c = X({
|
|
292
292
|
source: { allFeaturesStore: e, resolvedFeaturesStore: r },
|
|
293
293
|
effect: async ({ allFeaturesStore: l, resolvedFeaturesStore: d }, { id: u, decide: p, key: m }) => {
|
|
294
|
-
const
|
|
295
|
-
(
|
|
294
|
+
const f = d.find(
|
|
295
|
+
($) => $.id === u && $.key === m
|
|
296
296
|
);
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
297
|
+
if (f)
|
|
298
|
+
return f;
|
|
299
299
|
const y = l[u];
|
|
300
300
|
if (!y)
|
|
301
301
|
throw new Error(`Feature with id '${u}' not found`);
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
const
|
|
305
|
-
return { id: y.id, bucket:
|
|
302
|
+
const v = o.get(`${u}:${m}`);
|
|
303
|
+
if (v !== void 0) {
|
|
304
|
+
const $ = await v;
|
|
305
|
+
return { id: y.id, bucket: $, key: m, storage: y.feature.storage };
|
|
306
306
|
}
|
|
307
|
-
const
|
|
308
|
-
o.set(`${u}:${m}`,
|
|
309
|
-
const
|
|
310
|
-
return { id: y.id, bucket:
|
|
307
|
+
const R = p();
|
|
308
|
+
o.set(`${u}:${m}`, R);
|
|
309
|
+
const E = await R;
|
|
310
|
+
return { id: y.id, bucket: E, key: m, storage: y.feature.storage };
|
|
311
311
|
}
|
|
312
312
|
});
|
|
313
313
|
x({
|
|
@@ -322,12 +322,12 @@ const Oe = (t, e, r) => {
|
|
|
322
322
|
clock: c.doneData,
|
|
323
323
|
fn: (l, d) => {
|
|
324
324
|
var y;
|
|
325
|
-
const { id: u, bucket: p, storage: m } = d,
|
|
326
|
-
return
|
|
325
|
+
const { id: u, bucket: p, storage: m } = d, f = (y = l[u]) == null ? void 0 : y.feature.key;
|
|
326
|
+
return f ? { key: f, id: u, bucket: p, storage: m } : null;
|
|
327
327
|
},
|
|
328
328
|
target: s
|
|
329
329
|
});
|
|
330
|
-
const
|
|
330
|
+
const g = z({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
|
|
331
331
|
({
|
|
332
332
|
allFeaturesStore: l,
|
|
333
333
|
resolvedFeaturesStore: d
|
|
@@ -369,59 +369,59 @@ const Oe = (t, e, r) => {
|
|
|
369
369
|
) ? l : [...l, d],
|
|
370
370
|
target: r
|
|
371
371
|
});
|
|
372
|
-
function
|
|
372
|
+
function S(l) {
|
|
373
373
|
return e.map((d) => d[l], { skipVoid: !1 });
|
|
374
374
|
}
|
|
375
375
|
return {
|
|
376
376
|
register: i,
|
|
377
|
-
getByName:
|
|
378
|
-
listStore:
|
|
377
|
+
getByName: S,
|
|
378
|
+
listStore: g
|
|
379
379
|
};
|
|
380
380
|
});
|
|
381
|
-
function
|
|
382
|
-
return
|
|
381
|
+
function De(t) {
|
|
382
|
+
return I(ze, t);
|
|
383
383
|
}
|
|
384
|
-
const
|
|
384
|
+
const Ue = (t, e, r) => {
|
|
385
385
|
r.register(t, e);
|
|
386
386
|
}, P = b("history");
|
|
387
|
-
function
|
|
387
|
+
function L(t, e) {
|
|
388
388
|
return {
|
|
389
389
|
// eslint-disable-next-line sonarjs/pseudo-random
|
|
390
|
-
id:
|
|
390
|
+
id: ie(`history-entry-${Date.now()}-${Math.random()}}`),
|
|
391
391
|
node: e,
|
|
392
392
|
at: Date.now(),
|
|
393
393
|
experienceId: t
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
|
-
const
|
|
396
|
+
const Me = w(() => {
|
|
397
397
|
const t = P.store({ entries: [] }), e = P.event(), r = P.event(), n = P.event(), i = P.event();
|
|
398
398
|
t.on(e, (s, o) => ({
|
|
399
|
-
entries: [...s.entries,
|
|
399
|
+
entries: [...s.entries, L(o.experienceId, o.node)]
|
|
400
400
|
})), t.on(r, (s, o) => ({
|
|
401
401
|
entries: [
|
|
402
402
|
...s.entries.slice(0, -1),
|
|
403
|
-
|
|
403
|
+
L(o.experienceId, o.node)
|
|
404
404
|
]
|
|
405
405
|
})), t.on(i, (s, o) => o);
|
|
406
406
|
function a(s, o) {
|
|
407
407
|
const c = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
408
|
-
for (let
|
|
409
|
-
const
|
|
410
|
-
if (!(!l || !
|
|
408
|
+
for (let g = s.length - 1; g >= 0; g--) {
|
|
409
|
+
const S = s[g], l = S == null ? void 0 : S.node;
|
|
410
|
+
if (!(!l || !re(l)) && !(o && (S == null ? void 0 : S.experienceId) !== o))
|
|
411
411
|
if (c.lastStepIndex === -1)
|
|
412
|
-
c.lastStepIndex =
|
|
412
|
+
c.lastStepIndex = g;
|
|
413
413
|
else {
|
|
414
|
-
c.secondLastStepIndex =
|
|
414
|
+
c.secondLastStepIndex = g;
|
|
415
415
|
break;
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
418
|
return c;
|
|
419
419
|
}
|
|
420
420
|
return t.on(n, (s, o) => {
|
|
421
|
-
const { secondLastStepIndex: c } = a(s.entries, o.experienceId),
|
|
421
|
+
const { secondLastStepIndex: c } = a(s.entries, o.experienceId), g = c !== -1 ? s.entries.slice(0, c + 1) : s.entries;
|
|
422
422
|
return {
|
|
423
423
|
...s,
|
|
424
|
-
entries:
|
|
424
|
+
entries: g
|
|
425
425
|
};
|
|
426
426
|
}), {
|
|
427
427
|
push: e,
|
|
@@ -431,11 +431,11 @@ const Ue = k(() => {
|
|
|
431
431
|
entriesStore: t.map((s) => s.entries)
|
|
432
432
|
};
|
|
433
433
|
});
|
|
434
|
-
function
|
|
435
|
-
return
|
|
434
|
+
function Ne() {
|
|
435
|
+
return I(Me);
|
|
436
436
|
}
|
|
437
|
-
const
|
|
438
|
-
const t =
|
|
437
|
+
const Ve = () => D(), Te = b("field"), _e = w(() => {
|
|
438
|
+
const t = Te.store({}), e = F(t, {
|
|
439
439
|
register(o, c) {
|
|
440
440
|
return {
|
|
441
441
|
...o,
|
|
@@ -447,20 +447,20 @@ const Te = () => C(), Ve = b("field"), Ne = k(() => {
|
|
|
447
447
|
e.register({ field: o });
|
|
448
448
|
}
|
|
449
449
|
function n(o, c) {
|
|
450
|
-
const
|
|
451
|
-
if (!
|
|
450
|
+
const g = a(o).getState();
|
|
451
|
+
if (!g)
|
|
452
452
|
return;
|
|
453
|
-
const
|
|
453
|
+
const S = Object.assign({}, g, {
|
|
454
454
|
...c
|
|
455
455
|
});
|
|
456
|
-
e.register({ field: { ...
|
|
456
|
+
e.register({ field: { ...S } });
|
|
457
457
|
}
|
|
458
458
|
const i = t.map((o) => Object.values(o));
|
|
459
459
|
function a(o) {
|
|
460
460
|
return t.map((c) => c[o] || null);
|
|
461
461
|
}
|
|
462
462
|
function s(o) {
|
|
463
|
-
return t.map((c) => Object.values(c).find((
|
|
463
|
+
return t.map((c) => Object.values(c).find((g) => g.name === o) || null);
|
|
464
464
|
}
|
|
465
465
|
return {
|
|
466
466
|
register: r,
|
|
@@ -470,13 +470,13 @@ const Te = () => C(), Ve = b("field"), Ne = k(() => {
|
|
|
470
470
|
getByName: s
|
|
471
471
|
};
|
|
472
472
|
});
|
|
473
|
-
function
|
|
474
|
-
return
|
|
473
|
+
function Le() {
|
|
474
|
+
return I(_e);
|
|
475
475
|
}
|
|
476
|
-
const
|
|
476
|
+
const Ge = (t, e) => {
|
|
477
477
|
e.register(t);
|
|
478
|
-
},
|
|
479
|
-
const t =
|
|
478
|
+
}, He = b("action"), qe = w(() => {
|
|
479
|
+
const t = He.store({}), e = F(t, {
|
|
480
480
|
register(a, s) {
|
|
481
481
|
return {
|
|
482
482
|
...a,
|
|
@@ -500,17 +500,17 @@ const Le = (t, e) => {
|
|
|
500
500
|
listStore: n
|
|
501
501
|
};
|
|
502
502
|
});
|
|
503
|
-
function
|
|
504
|
-
return
|
|
503
|
+
function Ke() {
|
|
504
|
+
return I(qe);
|
|
505
505
|
}
|
|
506
|
-
const
|
|
506
|
+
const We = (t, e, r) => {
|
|
507
507
|
r.register(t, e);
|
|
508
508
|
};
|
|
509
|
-
function
|
|
509
|
+
function G(t) {
|
|
510
510
|
return typeof t > "u" || t === null || t === "" || Array.isArray(t) && !t.length;
|
|
511
511
|
}
|
|
512
|
-
const
|
|
513
|
-
const e =
|
|
512
|
+
const Ye = b("response"), Je = w(({ client: t }) => {
|
|
513
|
+
const e = Ye.store({}), r = D(), n = D(), i = F(e, {
|
|
514
514
|
register(d, u) {
|
|
515
515
|
return {
|
|
516
516
|
...d,
|
|
@@ -538,65 +538,65 @@ const We = b("response"), Ye = k(({ client: t }) => {
|
|
|
538
538
|
const u = [];
|
|
539
539
|
return await Promise.allSettled(
|
|
540
540
|
Object.entries(d).map(async ([p, m]) => {
|
|
541
|
-
let
|
|
541
|
+
let f = m;
|
|
542
542
|
const y = t.fields.getById(p).getState();
|
|
543
543
|
if (!y) {
|
|
544
544
|
u.push({
|
|
545
545
|
fieldId: p,
|
|
546
546
|
userMessage: `Field '${p}' not found`,
|
|
547
547
|
systemMessage: `No field with ID '${p}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
548
|
-
value:
|
|
548
|
+
value: f
|
|
549
549
|
});
|
|
550
550
|
return;
|
|
551
551
|
}
|
|
552
|
-
if (y.multiple && (typeof
|
|
553
|
-
const
|
|
554
|
-
$input:
|
|
552
|
+
if (y.multiple && (typeof f == "string" || typeof f == "number" || typeof f == "boolean") && (f = [f]), y.validation && !oe(y.validation) && !G(f)) {
|
|
553
|
+
const v = await j(t, y.validation, {
|
|
554
|
+
$input: f
|
|
555
555
|
});
|
|
556
|
-
if (typeof
|
|
556
|
+
if (typeof v == "string") {
|
|
557
557
|
u.push({
|
|
558
558
|
fieldId: p,
|
|
559
|
-
userMessage:
|
|
560
|
-
systemMessage: `Field validation resulted in an error: ${
|
|
561
|
-
value:
|
|
559
|
+
userMessage: v,
|
|
560
|
+
systemMessage: `Field validation resulted in an error: ${v}.`,
|
|
561
|
+
value: f
|
|
562
562
|
});
|
|
563
563
|
return;
|
|
564
564
|
}
|
|
565
|
-
if (
|
|
565
|
+
if (v === !1) {
|
|
566
566
|
u.push({
|
|
567
567
|
fieldId: p,
|
|
568
568
|
userMessage: "This field is invalid",
|
|
569
569
|
systemMessage: "Field validation resulted in an unspecified error.",
|
|
570
|
-
value:
|
|
570
|
+
value: f
|
|
571
571
|
});
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
-
if (y.required &&
|
|
575
|
+
if (y.required && G(f)) {
|
|
576
576
|
u.push({
|
|
577
577
|
fieldId: p,
|
|
578
578
|
userMessage: "This field is required",
|
|
579
579
|
systemMessage: "Field is required.",
|
|
580
|
-
value:
|
|
580
|
+
value: f
|
|
581
581
|
});
|
|
582
582
|
return;
|
|
583
583
|
}
|
|
584
|
-
if (!y.multiple && Array.isArray(
|
|
584
|
+
if (!y.multiple && Array.isArray(f) && f.length > 1) {
|
|
585
585
|
u.push({
|
|
586
586
|
fieldId: p,
|
|
587
587
|
userMessage: "This field expects a single response",
|
|
588
588
|
systemMessage: "Field expects a single response.",
|
|
589
|
-
value:
|
|
589
|
+
value: f
|
|
590
590
|
});
|
|
591
591
|
return;
|
|
592
592
|
}
|
|
593
593
|
if (y.options) {
|
|
594
|
-
const
|
|
595
|
-
Array.isArray(
|
|
594
|
+
const v = y.options.map((E) => E.value), R = Array.isArray(f) ? f : [f];
|
|
595
|
+
Array.isArray(f) && (R.every((E) => v.includes(E)) || u.push({
|
|
596
596
|
fieldId: p,
|
|
597
597
|
userMessage: "This field expects a valid option",
|
|
598
|
-
systemMessage: `Field expects a valid option. Valid options are: ${
|
|
599
|
-
value:
|
|
598
|
+
systemMessage: `Field expects a valid option. Valid options are: ${v.join(", ")}`,
|
|
599
|
+
value: f
|
|
600
600
|
}));
|
|
601
601
|
}
|
|
602
602
|
})
|
|
@@ -606,19 +606,19 @@ const We = b("response"), Ye = k(({ client: t }) => {
|
|
|
606
606
|
const { responsesToCommit: u, validationErrors: p } = await s(d);
|
|
607
607
|
return p.length ? { errors: p } : (i.registerBatch(u), { errors: [] });
|
|
608
608
|
}
|
|
609
|
-
const c = e.map((d) => d),
|
|
609
|
+
const c = e.map((d) => d), g = e.map((d) => Object.keys(d).map((p) => ({
|
|
610
610
|
fieldId: p,
|
|
611
611
|
value: d[p]
|
|
612
612
|
})));
|
|
613
|
-
function
|
|
613
|
+
function S(d) {
|
|
614
614
|
const u = t.fields.getById(d), p = e.map((m) => m[d] || null);
|
|
615
|
-
return z({ f: u, r: p }, ({ f: m, r:
|
|
615
|
+
return z({ f: u, r: p }, ({ f: m, r: f }) => f || (m != null && m.defaultValue ? m.defaultValue : null));
|
|
616
616
|
}
|
|
617
617
|
function l(d) {
|
|
618
618
|
const u = t.fields.getByName(d);
|
|
619
619
|
return z({ f: u, s: e }, ({ f: p, s: m }) => {
|
|
620
|
-
const
|
|
621
|
-
return
|
|
620
|
+
const f = p && m[p.id] || null;
|
|
621
|
+
return f || (p != null && p.defaultValue ? p.defaultValue : null);
|
|
622
622
|
});
|
|
623
623
|
}
|
|
624
624
|
return x({
|
|
@@ -633,18 +633,18 @@ const We = b("response"), Ye = k(({ client: t }) => {
|
|
|
633
633
|
clear: n,
|
|
634
634
|
commit: o,
|
|
635
635
|
getResponsesToCommit: s,
|
|
636
|
-
listStore:
|
|
636
|
+
listStore: g,
|
|
637
637
|
getAllStore: c,
|
|
638
|
-
getByFieldId:
|
|
638
|
+
getByFieldId: S,
|
|
639
639
|
getByFieldName: l
|
|
640
640
|
};
|
|
641
641
|
});
|
|
642
|
-
function
|
|
643
|
-
return
|
|
642
|
+
function Qe(t) {
|
|
643
|
+
return I(Je, t);
|
|
644
644
|
}
|
|
645
|
-
const
|
|
646
|
-
function
|
|
647
|
-
if (
|
|
645
|
+
const Xe = () => "0.0.28";
|
|
646
|
+
function Ze() {
|
|
647
|
+
if (U()) {
|
|
648
648
|
const t = [
|
|
649
649
|
document.currentScript,
|
|
650
650
|
document.getElementById("picked_script"),
|
|
@@ -658,8 +658,8 @@ function Xe() {
|
|
|
658
658
|
}
|
|
659
659
|
return "https://api.picked.app";
|
|
660
660
|
}
|
|
661
|
-
function
|
|
662
|
-
if (!
|
|
661
|
+
function et() {
|
|
662
|
+
if (!M())
|
|
663
663
|
return {};
|
|
664
664
|
const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
|
|
665
665
|
for (const [i] of t.entries())
|
|
@@ -668,24 +668,24 @@ function Ze() {
|
|
|
668
668
|
const a = i.replace("picked-", "");
|
|
669
669
|
e[a] = t.getAll(i);
|
|
670
670
|
}
|
|
671
|
-
const n =
|
|
671
|
+
const n = A("s");
|
|
672
672
|
if (r.size > 0)
|
|
673
|
-
|
|
673
|
+
C.set(n, e);
|
|
674
674
|
else {
|
|
675
|
-
const i =
|
|
675
|
+
const i = C.get(n);
|
|
676
676
|
if (i)
|
|
677
677
|
return i.json() || {};
|
|
678
678
|
}
|
|
679
679
|
return e;
|
|
680
680
|
}
|
|
681
|
-
function
|
|
682
|
-
if (
|
|
681
|
+
function tt() {
|
|
682
|
+
if (ce())
|
|
683
683
|
return crypto.randomUUID();
|
|
684
684
|
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);
|
|
685
685
|
return `${t}-${e}-${r}-${n}`;
|
|
686
686
|
}
|
|
687
|
-
const
|
|
688
|
-
const t =
|
|
687
|
+
const rt = A("session", "global"), nt = () => {
|
|
688
|
+
const t = O.get(rt);
|
|
689
689
|
let e;
|
|
690
690
|
t.isSet() && (e = t.json());
|
|
691
691
|
const r = (i) => t.set({
|
|
@@ -693,7 +693,7 @@ const tt = R("session", "global"), rt = () => {
|
|
|
693
693
|
isUser: i.isUser,
|
|
694
694
|
identifiers: i.identifiers
|
|
695
695
|
}), n = {
|
|
696
|
-
id: (e == null ? void 0 : e.id) ??
|
|
696
|
+
id: (e == null ? void 0 : e.id) ?? tt(),
|
|
697
697
|
isUser: (e == null ? void 0 : e.isUser) ?? void 0,
|
|
698
698
|
identifiers: (e == null ? void 0 : e.identifiers) ?? void 0,
|
|
699
699
|
setIsUser(i) {
|
|
@@ -709,19 +709,19 @@ const tt = R("session", "global"), rt = () => {
|
|
|
709
709
|
}
|
|
710
710
|
};
|
|
711
711
|
return r(n), n;
|
|
712
|
-
},
|
|
713
|
-
function
|
|
714
|
-
if (
|
|
712
|
+
}, st = () => ae() ? nt() : null;
|
|
713
|
+
function it() {
|
|
714
|
+
if (M())
|
|
715
715
|
return globalThis.window.pickedConfig;
|
|
716
716
|
}
|
|
717
|
-
function
|
|
718
|
-
if (!
|
|
717
|
+
function ot() {
|
|
718
|
+
if (!M())
|
|
719
719
|
return;
|
|
720
|
-
const t =
|
|
720
|
+
const t = it(), e = t == null ? void 0 : t.organizationId, r = t == null ? void 0 : t.projectId;
|
|
721
721
|
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
722
722
|
}
|
|
723
|
-
function
|
|
724
|
-
if (!
|
|
723
|
+
function at() {
|
|
724
|
+
if (!U())
|
|
725
725
|
return;
|
|
726
726
|
const t = document.getElementById("picked_script") || document.querySelector("script#picked") || // legacy support for 'cvly' script tag
|
|
727
727
|
document.getElementById("cvly");
|
|
@@ -730,14 +730,14 @@ function ot() {
|
|
|
730
730
|
const e = t.dataset.organizationid || t.getAttribute("organization-id"), r = t.dataset.projectid || t.getAttribute("project-id");
|
|
731
731
|
return e && r ? { organizationId: e, projectId: r } : void 0;
|
|
732
732
|
}
|
|
733
|
-
function
|
|
733
|
+
function ct(t) {
|
|
734
734
|
const { organizationId: e, projectId: r } = t;
|
|
735
735
|
if (e && r)
|
|
736
736
|
return { organizationId: e, projectId: r };
|
|
737
|
-
const n =
|
|
737
|
+
const n = ot();
|
|
738
738
|
if (n)
|
|
739
739
|
return n;
|
|
740
|
-
const i =
|
|
740
|
+
const i = at();
|
|
741
741
|
if (i)
|
|
742
742
|
return i;
|
|
743
743
|
throw new Error(
|
|
@@ -747,73 +747,184 @@ function at(t) {
|
|
|
747
747
|
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`
|
|
748
748
|
);
|
|
749
749
|
}
|
|
750
|
-
|
|
750
|
+
function B(t) {
|
|
751
|
+
return t == null || t === "" || Number.isNaN(t);
|
|
752
|
+
}
|
|
753
|
+
const ut = {
|
|
754
|
+
default: (t, e) => B(t) ? String(e ?? "") : String(t),
|
|
755
|
+
append: (t, e) => e && !B(t) ? `${t} ${e}` : t,
|
|
756
|
+
prepend: (t, e) => e && !B(t) ? `${e} ${t}` : t,
|
|
757
|
+
upper: (t) => typeof t == "string" ? t.toUpperCase() : t,
|
|
758
|
+
lower: (t) => typeof t == "string" ? t.toLowerCase() : t,
|
|
759
|
+
capitalize: (t) => typeof t == "string" ? t.charAt(0).toUpperCase() + t.slice(1) : t,
|
|
760
|
+
list: (t) => {
|
|
761
|
+
if (!t || typeof t != "object")
|
|
762
|
+
return t;
|
|
763
|
+
const e = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
|
|
764
|
+
if (Array.isArray(t))
|
|
765
|
+
return e.format(t.map(String));
|
|
766
|
+
if (t instanceof Map) {
|
|
767
|
+
const r = Array.from(t.entries()).map(([n, i]) => `${n}: ${i}`);
|
|
768
|
+
return e.format(r);
|
|
769
|
+
}
|
|
770
|
+
return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
function dt(t) {
|
|
774
|
+
return typeof t == "object" && t !== null;
|
|
775
|
+
}
|
|
776
|
+
function lt(t, e) {
|
|
777
|
+
let r = e;
|
|
778
|
+
for (const n of t.split("."))
|
|
779
|
+
if (dt(r) && n in r)
|
|
780
|
+
r = r[n];
|
|
781
|
+
else
|
|
782
|
+
return;
|
|
783
|
+
return typeof r == "function" ? r() : r;
|
|
784
|
+
}
|
|
785
|
+
function pt(t, e) {
|
|
786
|
+
const r = t.split("|").map((a) => a.trim()), n = r.shift() ?? "";
|
|
787
|
+
let i = lt(n, e);
|
|
788
|
+
for (const a of r) {
|
|
789
|
+
const [s, ...o] = a.split(":"), c = (s == null ? void 0 : s.trim()) ?? "", g = o.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), S = ut[c];
|
|
790
|
+
S && (i = S(i, g));
|
|
791
|
+
}
|
|
792
|
+
return B(i) ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
|
|
793
|
+
}
|
|
794
|
+
function ft(t, e) {
|
|
795
|
+
let r = "", n = 0;
|
|
796
|
+
for (; n < t.length; )
|
|
797
|
+
if (t[n] === "{" && t[n + 1] === "{") {
|
|
798
|
+
n += 2;
|
|
799
|
+
let i = "";
|
|
800
|
+
for (; n < t.length; ) {
|
|
801
|
+
if (t[n] === "}" && t[n + 1] === "}") {
|
|
802
|
+
n += 2;
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
i += t[n++];
|
|
806
|
+
}
|
|
807
|
+
r += pt(i.trim(), e);
|
|
808
|
+
} else
|
|
809
|
+
r += t[n++];
|
|
810
|
+
return r;
|
|
811
|
+
}
|
|
812
|
+
class W {
|
|
751
813
|
constructor(e) {
|
|
752
814
|
h(this, "options");
|
|
753
815
|
h(this, "isReady", !1);
|
|
754
816
|
h(this, "project");
|
|
755
817
|
h(this, "plugins", {});
|
|
756
|
-
h(this, "eventBus",
|
|
818
|
+
h(this, "eventBus", Ve());
|
|
757
819
|
h(this, "organizationId");
|
|
758
820
|
h(this, "projectId");
|
|
759
821
|
h(this, "apiUrl");
|
|
760
822
|
h(this, "session");
|
|
761
823
|
h(this, "precondition");
|
|
762
824
|
h(this, "condition");
|
|
763
|
-
h(this, "searchParams",
|
|
764
|
-
h(this, "history",
|
|
765
|
-
h(this, "components",
|
|
766
|
-
h(this, "experienceInstances",
|
|
767
|
-
h(this, "experiences",
|
|
768
|
-
h(this, "frameworks",
|
|
769
|
-
h(this, "predicates",
|
|
770
|
-
h(this, "features",
|
|
771
|
-
h(this, "responses",
|
|
772
|
-
h(this, "fields",
|
|
773
|
-
h(this, "actions",
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
825
|
+
h(this, "searchParams", et());
|
|
826
|
+
h(this, "history", Ne());
|
|
827
|
+
h(this, "components", Ie({ client: this }));
|
|
828
|
+
h(this, "experienceInstances", ne({ client: this }));
|
|
829
|
+
h(this, "experiences", fe({ client: this }));
|
|
830
|
+
h(this, "frameworks", Fe({ client: this }));
|
|
831
|
+
h(this, "predicates", Oe({ client: this }));
|
|
832
|
+
h(this, "features", De({ client: this }));
|
|
833
|
+
h(this, "responses", Qe({ client: this }));
|
|
834
|
+
h(this, "fields", Le());
|
|
835
|
+
h(this, "actions", Ke());
|
|
836
|
+
/**
|
|
837
|
+
* Interpolates a template string using values from the client's response store and/or a provided context.
|
|
838
|
+
* Supports dot-notation, modifiers, and executing functions found in the context.
|
|
839
|
+
*
|
|
840
|
+
* Sources:
|
|
841
|
+
* - responses.*: Loaded automatically from the client's internal response store by fieldId (e.g. {{ responses.email }}).
|
|
842
|
+
* - Context: Any non-responses.* key must be supplied in the context; nested dot-notation is supported.
|
|
843
|
+
* - Functions: If a context value is a function, it is invoked and its result is rendered.
|
|
844
|
+
*
|
|
845
|
+
* Placeholders:
|
|
846
|
+
* - {{ key | modifier: arg | modifier2: arg2 }} with modifiers applied left-to-right.
|
|
847
|
+
*
|
|
848
|
+
* Modifiers:
|
|
849
|
+
* - default: Use the argument when the value is null, undefined, NaN, or empty string; otherwise return the value as a string.
|
|
850
|
+
* - append: Append the argument (space-separated) when the value is non-empty.
|
|
851
|
+
* - prepend: Prepend the argument (space-separated) when the value is non-empty.
|
|
852
|
+
* - upper: Uppercase string values.
|
|
853
|
+
* - lower: Lowercase string values.
|
|
854
|
+
* - capitalize: Capitalize the first letter of string values.
|
|
855
|
+
* - list: Format Arrays, Maps, and Sets via Intl.ListFormat (Maps render as key: value pairs).
|
|
856
|
+
*
|
|
857
|
+
* Behavior:
|
|
858
|
+
* - Empty values (null, undefined, empty string, NaN) render as empty. Numeric 0 renders as "0", boolean false renders as "false", and boolean true renders as "true".
|
|
859
|
+
* - Objects and arrays are JSON-stringified; Maps/Sets serialize to {} unless the list modifier is used.
|
|
860
|
+
* - Unknown modifiers are ignored.
|
|
861
|
+
*
|
|
862
|
+
* @param template Template containing placeholders.
|
|
863
|
+
* @param context Optional data for interpolation. Non-responses.* keys belong here; function values are executed.
|
|
864
|
+
* @returns Interpolated string.
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* renderString("Hello {{ name | default: 'Guest' | capitalize }}! Email: {{ responses.email | lower }}.", { name: "ALICE" })
|
|
868
|
+
* // => "Hello Alice! Email: alice@example.com."
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* renderString("User: {{ getName | capitalize }}", { getName: () => "alice" })
|
|
872
|
+
* // => "User: Alice"
|
|
873
|
+
*
|
|
874
|
+
* @example
|
|
875
|
+
* renderString("Fruits: {{ fruits | list }}", { fruits: ["apple", "banana", "cherry"] })
|
|
876
|
+
* // => "Fruits: apple, banana, and cherry"
|
|
877
|
+
*/
|
|
878
|
+
h(this, "renderString", (e, r) => {
|
|
879
|
+
const n = this.responses.listStore.getState().reduce((i, a) => (i[a.fieldId] = a.value, i), {});
|
|
880
|
+
return ft(e, {
|
|
881
|
+
...r,
|
|
882
|
+
responses: n
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
k("info", "Picked client initializing.");
|
|
886
|
+
const { organizationId: r, projectId: n } = ct(e);
|
|
887
|
+
this.organizationId = r, this.projectId = n, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Ze(), this.session = st(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: Xe() }), k("info", "Picked client initialized.");
|
|
777
888
|
}
|
|
778
889
|
start() {
|
|
779
|
-
|
|
780
|
-
if (!
|
|
890
|
+
Ae(this), (async () => {
|
|
891
|
+
if (!U())
|
|
781
892
|
return;
|
|
782
893
|
let r;
|
|
783
|
-
typeof this.precondition > "u" ? r = !0 : typeof this.precondition == "boolean" ? r = this.precondition : r = await
|
|
894
|
+
typeof this.precondition > "u" ? r = !0 : typeof this.precondition == "boolean" ? r = this.precondition : r = await j(this, this.precondition) === !0;
|
|
784
895
|
let n;
|
|
785
|
-
r && (this.condition === void 0 ? n = !0 : typeof this.condition == "boolean" ? n = this.condition : n = await
|
|
896
|
+
r && (this.condition === void 0 ? n = !0 : typeof this.condition == "boolean" ? n = this.condition : n = await j(this, this.condition) === !0);
|
|
786
897
|
const i = r && n === !0;
|
|
787
898
|
if (typeof n == "boolean" && this.session) {
|
|
788
899
|
const a = n;
|
|
789
900
|
this.session.setIsUser(a), this.eventBus({ type: "user_decide", value: a });
|
|
790
901
|
}
|
|
791
|
-
this.eventBus({ type: "initialize" }), document.body && i &&
|
|
902
|
+
this.eventBus({ type: "initialize" }), document.body && i && V(this), await se(), i && V(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session });
|
|
792
903
|
})();
|
|
793
904
|
}
|
|
794
905
|
registerFramework(e) {
|
|
795
|
-
|
|
906
|
+
xe(e, this.frameworks);
|
|
796
907
|
}
|
|
797
908
|
registerComponent(e, r) {
|
|
798
|
-
|
|
909
|
+
T(e, r, this.components);
|
|
799
910
|
}
|
|
800
911
|
registerPlugin(e) {
|
|
801
|
-
|
|
912
|
+
he(this, e, this.plugins);
|
|
802
913
|
}
|
|
803
914
|
registerFeature(e, r) {
|
|
804
|
-
|
|
915
|
+
Ue(e, r, this.features);
|
|
805
916
|
}
|
|
806
917
|
registerPredicate(e, r) {
|
|
807
|
-
|
|
918
|
+
Ce(e, r, this.predicates);
|
|
808
919
|
}
|
|
809
920
|
registerField(e) {
|
|
810
|
-
|
|
921
|
+
Ge(e, this.fields);
|
|
811
922
|
}
|
|
812
923
|
registerAction(e, r) {
|
|
813
|
-
|
|
924
|
+
We(e, r, this.actions);
|
|
814
925
|
}
|
|
815
926
|
registerExperience(e) {
|
|
816
|
-
e.component &&
|
|
927
|
+
e.component && T(`experience:${e.id}`, e.component, this.components), ge(e, this.experiences);
|
|
817
928
|
}
|
|
818
929
|
getStateSnapshot() {
|
|
819
930
|
return Re(this);
|
|
@@ -821,10 +932,10 @@ class K {
|
|
|
821
932
|
async launchExperienceById(e) {
|
|
822
933
|
const r = this.experiences.getById(e).getState();
|
|
823
934
|
if (!r) {
|
|
824
|
-
|
|
935
|
+
k("warn", `Experience with id '${e}' not found.`);
|
|
825
936
|
return;
|
|
826
937
|
}
|
|
827
|
-
|
|
938
|
+
K(this, r);
|
|
828
939
|
}
|
|
829
940
|
// private async fetchProject() {
|
|
830
941
|
// if (this.project) {
|
|
@@ -879,7 +990,7 @@ class K {
|
|
|
879
990
|
const e = this.options.predicates;
|
|
880
991
|
e && Object.entries(e).forEach(([r, n]) => {
|
|
881
992
|
if (typeof n != "function") {
|
|
882
|
-
|
|
993
|
+
k("warn", `Predicate "${r}" is not a function.`);
|
|
883
994
|
return;
|
|
884
995
|
}
|
|
885
996
|
this.registerPredicate(r, n);
|
|
@@ -889,7 +1000,7 @@ class K {
|
|
|
889
1000
|
const e = this.options.actions;
|
|
890
1001
|
e && Object.entries(e).forEach(([r, n]) => {
|
|
891
1002
|
if (typeof n != "function") {
|
|
892
|
-
|
|
1003
|
+
k("warn", `Action "${r}" is not a function.`);
|
|
893
1004
|
return;
|
|
894
1005
|
}
|
|
895
1006
|
this.registerAction(r, n);
|
|
@@ -899,52 +1010,52 @@ class K {
|
|
|
899
1010
|
return this.plugins[e] ?? {};
|
|
900
1011
|
}
|
|
901
1012
|
}
|
|
902
|
-
h(
|
|
903
|
-
function
|
|
1013
|
+
h(W, "logger", k);
|
|
1014
|
+
function Y(t) {
|
|
904
1015
|
var e;
|
|
905
1016
|
return ((e = t.options) == null ? void 0 : e.some((r) => "condition" in r)) ?? !1;
|
|
906
1017
|
}
|
|
907
|
-
function
|
|
908
|
-
return t.some((e) => e.condition ||
|
|
1018
|
+
function gt(t) {
|
|
1019
|
+
return t.some((e) => e.condition || Y(e));
|
|
909
1020
|
}
|
|
910
|
-
async function
|
|
911
|
-
return e.length === 0 || !
|
|
1021
|
+
async function Ft(t, e) {
|
|
1022
|
+
return e.length === 0 || !gt(e) ? e : (await Promise.all(
|
|
912
1023
|
e.map(async (n) => {
|
|
913
|
-
if (!(n.condition ? await
|
|
1024
|
+
if (!(n.condition ? await j(t, n.condition) : !0))
|
|
914
1025
|
return null;
|
|
915
|
-
if (!n.options || !
|
|
1026
|
+
if (!n.options || !Y(n))
|
|
916
1027
|
return n;
|
|
917
1028
|
const s = (await Promise.all(
|
|
918
|
-
n.options.map(async (c) => c.condition ? await
|
|
1029
|
+
n.options.map(async (c) => c.condition ? await j(t, c.condition) ? c : null : c)
|
|
919
1030
|
)).filter((c) => c !== null);
|
|
920
1031
|
return s.length === n.options.length ? n : s.length === 0 ? null : { ...n, options: s };
|
|
921
1032
|
})
|
|
922
1033
|
)).filter((n) => n !== null);
|
|
923
1034
|
}
|
|
924
|
-
const
|
|
925
|
-
const e = new
|
|
926
|
-
return
|
|
1035
|
+
const xt = (t) => {
|
|
1036
|
+
const e = new W(t);
|
|
1037
|
+
return ue(e), e;
|
|
927
1038
|
};
|
|
928
1039
|
export {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1040
|
+
W as Picked,
|
|
1041
|
+
xt as createClient,
|
|
1042
|
+
A as createStorageKey,
|
|
1043
|
+
j as evaluateRuleLogic,
|
|
1044
|
+
it as getPickedConfig,
|
|
1045
|
+
Ft as getStepFields,
|
|
1046
|
+
Pt as isPickedRoot,
|
|
1047
|
+
O as localStore,
|
|
1048
|
+
C as sessionStore,
|
|
1049
|
+
Rt as subscribe,
|
|
1050
|
+
Bt as supportsCookies,
|
|
1051
|
+
ce as supportsCryptoRandomUUID,
|
|
1052
|
+
U as supportsDocument,
|
|
1053
|
+
Ot as supportsHistory,
|
|
1054
|
+
Ct as supportsIntersectionObserver,
|
|
1055
|
+
ae as supportsLocalStorage,
|
|
1056
|
+
zt as supportsLocation,
|
|
1057
|
+
Dt as supportsSessionStorage,
|
|
1058
|
+
Ut as supportsShadowRoot,
|
|
1059
|
+
Mt as supportsWebComponents,
|
|
1060
|
+
M as supportsWindow
|
|
950
1061
|
};
|
package/dist/types/picked.d.ts
CHANGED
|
@@ -254,5 +254,48 @@ export declare class Picked {
|
|
|
254
254
|
private setupPredicates;
|
|
255
255
|
private setupActions;
|
|
256
256
|
getPluginConfig(pluginName: string): PluginConfigIndex[string] | Record<string, unknown>;
|
|
257
|
+
/**
|
|
258
|
+
* Interpolates a template string using values from the client's response store and/or a provided context.
|
|
259
|
+
* Supports dot-notation, modifiers, and executing functions found in the context.
|
|
260
|
+
*
|
|
261
|
+
* Sources:
|
|
262
|
+
* - responses.*: Loaded automatically from the client's internal response store by fieldId (e.g. {{ responses.email }}).
|
|
263
|
+
* - Context: Any non-responses.* key must be supplied in the context; nested dot-notation is supported.
|
|
264
|
+
* - Functions: If a context value is a function, it is invoked and its result is rendered.
|
|
265
|
+
*
|
|
266
|
+
* Placeholders:
|
|
267
|
+
* - {{ key | modifier: arg | modifier2: arg2 }} with modifiers applied left-to-right.
|
|
268
|
+
*
|
|
269
|
+
* Modifiers:
|
|
270
|
+
* - default: Use the argument when the value is null, undefined, NaN, or empty string; otherwise return the value as a string.
|
|
271
|
+
* - append: Append the argument (space-separated) when the value is non-empty.
|
|
272
|
+
* - prepend: Prepend the argument (space-separated) when the value is non-empty.
|
|
273
|
+
* - upper: Uppercase string values.
|
|
274
|
+
* - lower: Lowercase string values.
|
|
275
|
+
* - capitalize: Capitalize the first letter of string values.
|
|
276
|
+
* - list: Format Arrays, Maps, and Sets via Intl.ListFormat (Maps render as key: value pairs).
|
|
277
|
+
*
|
|
278
|
+
* Behavior:
|
|
279
|
+
* - Empty values (null, undefined, empty string, NaN) render as empty. Numeric 0 renders as "0", boolean false renders as "false", and boolean true renders as "true".
|
|
280
|
+
* - Objects and arrays are JSON-stringified; Maps/Sets serialize to {} unless the list modifier is used.
|
|
281
|
+
* - Unknown modifiers are ignored.
|
|
282
|
+
*
|
|
283
|
+
* @param template Template containing placeholders.
|
|
284
|
+
* @param context Optional data for interpolation. Non-responses.* keys belong here; function values are executed.
|
|
285
|
+
* @returns Interpolated string.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* renderString("Hello {{ name | default: 'Guest' | capitalize }}! Email: {{ responses.email | lower }}.", { name: "ALICE" })
|
|
289
|
+
* // => "Hello Alice! Email: alice@example.com."
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* renderString("User: {{ getName | capitalize }}", { getName: () => "alice" })
|
|
293
|
+
* // => "User: Alice"
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* renderString("Fruits: {{ fruits | list }}", { fruits: ["apple", "banana", "cherry"] })
|
|
297
|
+
* // => "Fruits: apple, banana, and cherry"
|
|
298
|
+
*/
|
|
299
|
+
renderString: (template: string, context?: Record<string, unknown>) => string;
|
|
257
300
|
}
|
|
258
301
|
//# sourceMappingURL=picked.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picked.d.ts","sourceRoot":"","sources":["../../src/picked.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAe,MAAM,0BAA0B,CAAA;AAC3F,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAGtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,gCAAgC,CAAA;AAGvC,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAMzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAOtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"picked.d.ts","sourceRoot":"","sources":["../../src/picked.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAe,MAAM,0BAA0B,CAAA;AAC3F,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAGtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,gCAAgC,CAAA;AAGvC,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAMzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAOtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK/C,qBAAa,MAAM;IACjB,MAAM,CAAC,QAAQ,CAAC,MAAM,0FAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,OAAO,UAAQ;IAEf,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAEhD,SAAgB,QAAQ,gEAAmB;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;IAExC,QAAQ,CAAC,YAAY,qDAAoB;IAEzC,QAAQ,CAAC,OAAO;;;;;;;;;;;;;;;;MAAkB;IAElC,QAAQ,CAAC,UAAU;;;;;;;;;;;MAAyC;IAC5D,QAAQ,CAAC,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAkD;IAC9E,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAA0C;IAC9D,QAAQ,CAAC,UAAU;;;;MAAyC;IAC5D,QAAQ,CAAC,UAAU;;;;;;;;;;MAAyC;IAC5D,QAAQ,CAAC,QAAQ;;;;MAAuC;IACxD,QAAQ,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;MAAwC;IAC1D,QAAQ,CAAC,MAAM;;;;;;MAAqB;IACpC,QAAQ,CAAC,OAAO;;;;MAAsB;gBAE1B,OAAO,EAAE,mBAAmB;IA0BxC,KAAK,IAAI,IAAI;IA6Eb,iBAAiB,CAAC,SAAS,EAAE,SAAS;IAItC,iBAAiB,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,SAAS,EAAE,gBAAgB;IAI9E,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAI9C,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;IAIpD,aAAa,CAAC,KAAK,EAAE,KAAK;IAI1B,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI3C,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQhD,gBAAgB,IAAI,aAAa;IAI3B,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB/D,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,aAAa;IA8CrB,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,YAAY;IAgBpB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,YAAY,GAAI,UAAU,MAAM,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,CAY3E;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface InterpolateContext {
|
|
2
|
+
responses?: Record<string, unknown>;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Internal interpolation engine used by Picked.renderString().
|
|
7
|
+
* Renders a template containing {{ ... }} placeholders using the provided context.
|
|
8
|
+
*
|
|
9
|
+
* Notes:
|
|
10
|
+
* - Keys use dot-notation (e.g. user.profile.name).
|
|
11
|
+
* - Function values in context are invoked and their result is rendered.
|
|
12
|
+
* - Empty detection: null, undefined, empty string, and NaN render as empty; 0/false/true render as "0"/"false"/"true".
|
|
13
|
+
* - Modifiers: default, append, prepend, upper, lower, capitalize, list.
|
|
14
|
+
* - Objects/arrays are JSON-stringified; Maps/Sets stringify to {} unless using the list modifier.
|
|
15
|
+
*
|
|
16
|
+
* For consumer-facing usage and examples, see Picked.renderString() in the client.
|
|
17
|
+
*
|
|
18
|
+
* @param template Template with placeholders like {{ key | modifier: arg }}.
|
|
19
|
+
* @param context Data source for interpolation.
|
|
20
|
+
* @returns Interpolated string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderString(template: string, context: InterpolateContext): string;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=render-string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-string.d.ts","sourceRoot":"","sources":["../../../src/utils/render-string.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AA4HD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA0BlF"}
|