@picked/client 0.0.4 → 0.0.5-next.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 CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var T=(t,e,s)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var y=(t,e,s)=>T(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("effector"),h=require("@withease/factories"),b=require("../experience-instance-DwO_yZK0.cjs"),I=require("../logger-BsmHUUw1.cjs"),k=require("../storage-BPJwmlva.cjs"),V=require("../id-BKIWbSTy.cjs"),N=require("../object-BbFTsGh3.cjs"),w=require("../supports-B6KShYPU.cjs"),O=d.createDomain("experience"),z=h.createFactory(({client:t,experience:e})=>{const s=O.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=O.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=b.getTargetElements(s,e.id);o.forEach(({elements:p})=>p.forEach(r=>b.tagTargetElement(r,e.id))),b.createAppHosts(o,e.id).forEach(p=>{t.experienceInstances.spawn(e,p)})},D=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 b.getTargetElements(i,e.id).length<1?!1:s==="funnel"?o?await b.evaluateRuleLogic(t,o)===!0:!1:i.length===0?!1:b.isRulesLogic(o)?await b.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]&&I.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 B=(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]&&I.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 I.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]&&I.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]&&I.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 F=r.get(`${a}:${m}`);if(F){const j=await F;return{id:S.id,bucket:j,storage:S.feature.storage}}const P=g();r.set(`${a}:${m}`,P);const x=await P;return{id:S.id,bucket:x,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 C(t,e){return{id:V.generateId(`history-entry-${Date.now()}-${Math.random()}}`),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,C(n.experienceId,n.node)]})),t.on(s,(r,n)=>({entries:[...r.entries.slice(0,-1),C(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||!b.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"),be=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 F=await b.evaluateRuleLogic(t,S.validation,{$input:l});if(typeof F=="string"){a.push({fieldId:g,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:l});return}if(F===!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 F=S.options.map(x=>x.value),P=Array.isArray(l)?l:[l];Array.isArray(l)&&(P.every(x=>F.includes(x))||a.push({fieldId:g,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.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 Fe(t){return h.invoke(be,t)}const Ie=()=>"0.0.4";function xe(){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",b.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",Fe({client:this}));I.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||xe(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.eventBus({type:"initialized",version:Ie()}),I.logger("info","Picked client initialized.")}start(){oe(this),(async()=>{w.supportsDocument()&&(document.body&&await D(this),await b.domInteractive(),await D(this),this.eventBus({type:"ready"}),this.isReady=!0)})()}registerFramework(e){re(e,this.frameworks)}registerComponent(e,s){B(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&&B(`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){I.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=!0),p==="false"&&(p=!1),this.registerFeature(o,{key:`${p}`,name:o,decide:()=>p,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([s,o])=>{if(typeof o!="function"){I.logger("warn",`Predicate "${s}" is not a function.`);return}this.registerPredicate(s,o)})}getPluginConfig(e){return this.plugins[e]??{}}}y(A,"logger",I.logger);const Pe=t=>{const e=new A(t);return w.bindClient(e),e};exports.isPickedRoot=b.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.supportsWebComponents=w.supportsWebComponents;exports.supportsWindow=w.supportsWindow;exports.Picked=A;exports.createClient=Pe;
1
+ "use strict";var M=Object.defineProperty;var T=(t,e,s)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var y=(t,e,s)=>T(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("effector"),h=require("@withease/factories"),b=require("../experience-instance-DwO_yZK0.cjs"),x=require("../logger-BsmHUUw1.cjs"),k=require("../storage-BPJwmlva.cjs"),V=require("../id-BKIWbSTy.cjs"),N=require("../object-BbFTsGh3.cjs"),w=require("../supports-B6KShYPU.cjs"),O=d.createDomain("experience"),z=h.createFactory(({client:t,experience:e})=>{const s=O.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=O.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=b.getTargetElements(s,e.id);o.forEach(({elements:p})=>p.forEach(r=>b.tagTargetElement(r,e.id))),b.createAppHosts(o,e.id).forEach(p=>{t.experienceInstances.spawn(e,p)})},D=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 b.getTargetElements(i,e.id).length<1?!1:s==="funnel"?o?await b.evaluateRuleLogic(t,o)===!0:!1:i.length===0?!1:b.isRulesLogic(o)?await b.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 B=(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 F=r.get(`${a}:${m}`);if(F){const j=await F;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 C(t,e){return{id:V.generateId(`history-entry-${Date.now()}-${Math.random()}}`),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,C(n.experienceId,n.node)]})),t.on(s,(r,n)=>({entries:[...r.entries.slice(0,-1),C(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||!b.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"),be=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 F=await b.evaluateRuleLogic(t,S.validation,{$input:l});if(typeof F=="string"){a.push({fieldId:g,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:l});return}if(F===!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 F=S.options.map(I=>I.value),P=Array.isArray(l)?l:[l];Array.isArray(l)&&(P.every(I=>F.includes(I))||a.push({fieldId:g,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.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 Fe(t){return h.invoke(be,t)}const xe=()=>"0.0.5-next.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",b.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",Fe({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 D(this),await b.domInteractive(),await D(this),this.eventBus({type:"ready"}),this.isReady=!0)})()}registerFramework(e){re(e,this.frameworks)}registerComponent(e,s){B(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&&B(`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=!0),p==="false"&&(p=!1),this.registerFeature(o,{key:`${p}`,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=b.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.supportsWebComponents=w.supportsWebComponents;exports.supportsWindow=w.supportsWindow;exports.Picked=A;exports.createClient=Pe;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../id-BKIWbSTy.cjs"),o={serialize(i){return JSON.stringify(i)},deserialize(i){return JSON.parse(i)}},N=i=>({name:"create-experience",setup:a=>{i.experiences.forEach(d=>{const s=d.serialize(),l=o.deserialize(s);l.component=d.component,a.registerExperience(l),l.fields.forEach(h=>{a.registerField(h)})})}}),y=(i,a)=>{const d={id:f.generateId("step"),label:i.label,experience:a,fields:[],node:null,nextStep(s){return this.experience.addStep(s,this)},nextConditional(s){return this.experience.addConditional(s,this)},addNextExperience(s){return this.experience.addExperience(s,this)},addField(s){return this.experience.addField(s,this)},serialize(){return o.serialize({id:this.id,label:this.label,fieldIds:this.fields.map(s=>s.id)})}};return u({step:d,type:"step"},a),d},z=()=>[0,0],u=(i,a)=>{const d={id:f.generateId("node"),position:z(),experience:a};if(i.type==="step"){const l={...d,type:"step",connectedStep:i.step,serialize(){return o.serialize({id:this.id,type:this.type,stepId:this.connectedStep.id,position:this.position,label:this.connectedStep.label})}};return l.connectedStep.node=l,l}if(i.type==="conditional"){const l={...d,type:"conditional",connectedConditional:i.conditional,serialize(){return o.serialize({id:this.id,type:this.type,conditionalId:this.connectedConditional.id,position:this.position})}};return l.connectedConditional.node=l,l}return i.type==="experience"?{...d,type:"experience",connectedExperience:i.experience,serialize(){return o.serialize({id:this.id,type:this.type,experienceId:this.connectedExperience.id,position:this.position})}}:{...d,type:"origin",serialize(){return o.serialize({id:this.id,type:this.type,position:this.position})}}},c=(i,a)=>({id:f.generateId("edge"),sourceNode:i.sourceNode,sourceNodeHandle:i.sourceNodeHandle,destinationNode:i.destinationNode,experience:a,serialize(){return o.serialize({id:this.id,sourceNodeHandle:this.sourceNodeHandle??void 0,sourceNodeId:this.sourceNode.id,destinationNodeId:this.destinationNode.id})}}),m=(i,a)=>{const d={id:f.generateId("conditional"),condition:i.condition,node:null,experience:a,addTrue(s){if(!this.node||!s.node)throw new Error("todo no node");const l=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"true"},this.experience);this.experience.edges.push(l)},addFalse(s){if(!this.node||!s.node)throw new Error("todo no node");const l=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"false"},this.experience);this.experience.edges.push(l)},serialize(){return o.serialize({id:this.id,condition:this.condition})}};return u({conditional:d,type:"conditional"},a),d},g=i=>{var d;return{id:i.id,name:i.name,type:i.type,label:i.label,placeholder:i.placeholder,description:i.description,helpText:i.helpText,defaultValue:i.defaultValue,multiple:i.multiple,validation:i.validation,required:i.required,options:((d=i.options)==null?void 0:d.map(s=>({...s})))||null,policies:i.policies,serialize(){const s={id:this.id,name:this.name,label:this.label,placeholder:this.placeholder,required:this.required,description:this.description,helpText:this.helpText,validation:this.validation,policies:this.policies},l=typeof this.defaultValue=="string"?this.defaultValue:null,h=typeof this.defaultValue=="number"?this.defaultValue:null,n=typeof this.defaultValue=="boolean"?this.defaultValue:null;switch(this.type){case"text":if(this.multiple){let e=null;if(Array.isArray(this.defaultValue)){e=[];for(const t of this.defaultValue)typeof t=="string"&&e.push(t);e.length===0&&(e=null)}return o.serialize({...s,type:"text",multiple:!0,defaultValue:e,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:`${t.value}`})):null})}return o.serialize({...s,type:"text",multiple:!1,defaultValue:l,options:this.options?this.options.map(e=>({id:e.id,label:e.label,value:`${e.value}`})):null});case"number":if(this.multiple){let e=null;if(Array.isArray(this.defaultValue)){e=[];for(const t of this.defaultValue)typeof t=="number"&&e.push(t);e.length===0&&(e=null)}return o.serialize({...s,type:"number",multiple:!0,defaultValue:e,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:Number(t.value)})):null})}return o.serialize({...s,type:"number",multiple:!1,defaultValue:h,options:this.options?this.options.map(e=>({id:e.id,label:e.label,value:Number(e.value)})):null});case"boolean":if(this.multiple){let e=null;if(Array.isArray(this.defaultValue)){e=[];for(const t of this.defaultValue)typeof t=="boolean"&&e.push(t);e.length===0&&(e=null)}return o.serialize({...s,type:"boolean",multiple:!0,defaultValue:e,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:!!t.value})):null})}return o.serialize({...s,type:"boolean",multiple:!1,defaultValue:n,options:this.options?this.options.map(e=>({id:e.id,label:e.label,value:!!e.value})):null});default:throw new Error("Unsupported field type")}}}},b=i=>{const a=[],d=[],s=[],l=[],h=[];return{id:i.id,component:i.component,type:i.type,name:i.name,decide:i.decide,targets:i.targets,steps:a,nodes:d,edges:s,fields:h,conditionals:l,addStep(n,e){let t=e==null?void 0:e.node;this.nodes.length===0&&(t=u({type:"origin"},this),this.nodes.push(t));const r="serialize"in n?n:y(n,this);if(t){if(!r.node)throw new Error("todo no node");const p=c({sourceNode:t,destinationNode:r.node,sourceNodeHandle:null},this);this.edges.push(p)}return this.steps.includes(r)||(this.steps.push(r),r.node&&this.nodes.push(r.node)),r},addConditional(n,e){let t=e==null?void 0:e.node;this.nodes.length===0&&(t=u({type:"origin"},this),this.nodes.push(t));const r="serialize"in n?n:m(n,this);if(t){if(!r.node)throw new Error("todo no node");const p=c({sourceNode:t,destinationNode:r.node,sourceNodeHandle:null},this);this.edges.push(p)}return this.conditionals.includes(r)||(this.conditionals.push(r),r.node&&this.nodes.push(r.node)),r},addExperience(n,e){let t=e==null?void 0:e.node;this.nodes.length===0&&(t=u({type:"origin"},this),this.nodes.push(t));const r=u({type:"experience",experience:n},this);if(this.nodes.push(r),t){const p=c({sourceNode:t,destinationNode:r,sourceNodeHandle:null},this);this.edges.push(p)}return n},addField(n,e){const t="serialize"in n?n:g(n);return e&&e.fields.push(t),this.fields.includes(t)||this.fields.push(t),t},serialize(){return o.serialize({id:this.id,type:this.type,component:this.component,name:this.name,decide:this.decide,targets:this.targets,steps:this.steps.map(n=>o.deserialize(n.serialize())),nodes:this.nodes.map(n=>o.deserialize(n.serialize())),edges:this.edges.map(n=>o.deserialize(n.serialize())),conditionals:this.conditionals.map(n=>o.deserialize(n.serialize())),fields:this.fields.map(n=>o.deserialize(n.serialize()))})}}};exports.createConditional=m;exports.createEdge=c;exports.createExperience=b;exports.createExperiencePlugin=N;exports.createField=g;exports.createNode=u;exports.createStep=y;exports.serialization=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../id-BKIWbSTy.cjs"),o={serialize(e){return JSON.stringify(e)},deserialize(e){return JSON.parse(e)}},g=e=>({name:"create-experience",setup:a=>{e.experiences.forEach(l=>{const s=l.serialize(),d=o.deserialize(s);d.component=l.component,a.registerExperience(d),d.fields.forEach(p=>{a.registerField(p)})})}}),z=e=>({id:f.generateId("step"),label:e.label,fields:e.fields??[],addField(a){var s,d;const l="serialize"in a?a:y(a);return(s=this.fields)!=null&&s.includes(l)||(d=this.fields)==null||d.push(l),l}}),N=(e,a)=>{const l={id:f.generateId("step"),label:e.label,experience:a,fields:e.fields??[],node:null,nextStep(s){return this.experience.addStep(s,this)},nextConditional(s){return this.experience.addConditional(s,this)},addNextExperience(s){return this.experience.addExperience(s,this)},addField(s){return this.experience.addField(s,this)},serialize(){return o.serialize({id:this.id,label:this.label,fieldIds:this.fields.map(s=>s.id)})}};return c({step:l,type:"step"},a),l},b=()=>[0,0],c=(e,a)=>{const l={id:f.generateId("node"),position:b(),experience:a};if(e.type==="step"){const d={...l,type:"step",connectedStep:e.step,serialize(){return o.serialize({id:this.id,type:this.type,stepId:this.connectedStep.id,position:this.position,label:this.connectedStep.label})}};return d.connectedStep.node=d,d}if(e.type==="conditional"){const d={...l,type:"conditional",connectedConditional:e.conditional,serialize(){return o.serialize({id:this.id,type:this.type,conditionalId:this.connectedConditional.id,position:this.position})}};return d.connectedConditional.node=d,d}return e.type==="experience"?{...l,type:"experience",connectedExperience:e.experience,serialize(){return o.serialize({id:this.id,type:this.type,experienceId:this.connectedExperience.id,position:this.position})}}:{...l,type:"origin",serialize(){return o.serialize({id:this.id,type:this.type,position:this.position})}}},h=(e,a)=>({id:f.generateId("edge"),sourceNode:e.sourceNode,sourceNodeHandle:e.sourceNodeHandle,destinationNode:e.destinationNode,experience:a,serialize(){return o.serialize({id:this.id,sourceNodeHandle:this.sourceNodeHandle??void 0,sourceNodeId:this.sourceNode.id,destinationNodeId:this.destinationNode.id})}}),m=(e,a)=>{const l={id:f.generateId("conditional"),condition:e.condition,node:null,experience:a,addTrue(s){if(!this.node||!s.node)throw new Error("todo no node");const d=h({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"true"},this.experience);this.experience.edges.push(d)},addFalse(s){if(!this.node||!s.node)throw new Error("todo no node");const d=h({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"false"},this.experience);this.experience.edges.push(d)},serialize(){return o.serialize({id:this.id,condition:this.condition})}};return c({conditional:l,type:"conditional"},a),l},y=e=>{var l;return{id:e.id,name:e.name,type:e.type,label:e.label,placeholder:e.placeholder,description:e.description,helpText:e.helpText,defaultValue:e.defaultValue,multiple:e.multiple,validation:e.validation,required:e.required,options:((l=e.options)==null?void 0:l.map(s=>({...s})))||null,policies:e.policies,serialize(){const s={id:this.id,name:this.name,label:this.label,placeholder:this.placeholder,required:this.required,description:this.description,helpText:this.helpText,validation:this.validation,policies:this.policies},d=typeof this.defaultValue=="string"?this.defaultValue:null,p=typeof this.defaultValue=="number"?this.defaultValue:null,n=typeof this.defaultValue=="boolean"?this.defaultValue:null;switch(this.type){case"text":if(this.multiple){let i=null;if(Array.isArray(this.defaultValue)){i=[];for(const t of this.defaultValue)typeof t=="string"&&i.push(t);i.length===0&&(i=null)}return o.serialize({...s,type:"text",multiple:!0,defaultValue:i,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:`${t.value}`})):null})}return o.serialize({...s,type:"text",multiple:!1,defaultValue:d,options:this.options?this.options.map(i=>({id:i.id,label:i.label,value:`${i.value}`})):null});case"number":if(this.multiple){let i=null;if(Array.isArray(this.defaultValue)){i=[];for(const t of this.defaultValue)typeof t=="number"&&i.push(t);i.length===0&&(i=null)}return o.serialize({...s,type:"number",multiple:!0,defaultValue:i,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:Number(t.value)})):null})}return o.serialize({...s,type:"number",multiple:!1,defaultValue:p,options:this.options?this.options.map(i=>({id:i.id,label:i.label,value:Number(i.value)})):null});case"boolean":if(this.multiple){let i=null;if(Array.isArray(this.defaultValue)){i=[];for(const t of this.defaultValue)typeof t=="boolean"&&i.push(t);i.length===0&&(i=null)}return o.serialize({...s,type:"boolean",multiple:!0,defaultValue:i,options:this.options?this.options.map(t=>({id:t.id,label:t.label,value:!!t.value})):null})}return o.serialize({...s,type:"boolean",multiple:!1,defaultValue:n,options:this.options?this.options.map(i=>({id:i.id,label:i.label,value:!!i.value})):null});default:throw new Error("Unsupported field type")}}}},x=e=>{const a=[],l=[],s=[],d=[],p=[];return{id:e.id,component:e.component,type:e.type,name:e.name,decide:e.decide,targets:e.targets,steps:a,nodes:l,edges:s,fields:p,conditionals:d,addStep(n,i){let t=i==null?void 0:i.node;this.nodes.length===0&&(t=c({type:"origin"},this),this.nodes.push(t));const r="serialize"in n?n:N(n,this);if(t){if(!r.node)throw new Error("todo no node");const u=h({sourceNode:t,destinationNode:r.node,sourceNodeHandle:null},this);this.edges.push(u)}return r.fields.length>0&&r.fields.forEach(u=>{this.fields.includes(u)||this.fields.push(u)}),this.steps.includes(r)||(this.steps.push(r),r.node&&this.nodes.push(r.node)),r},addConditional(n,i){let t=i==null?void 0:i.node;this.nodes.length===0&&(t=c({type:"origin"},this),this.nodes.push(t));const r="serialize"in n?n:m(n,this);if(t){if(!r.node)throw new Error("todo no node");const u=h({sourceNode:t,destinationNode:r.node,sourceNodeHandle:null},this);this.edges.push(u)}return this.conditionals.includes(r)||(this.conditionals.push(r),r.node&&this.nodes.push(r.node)),r},addExperience(n,i){let t=i==null?void 0:i.node;this.nodes.length===0&&(t=c({type:"origin"},this),this.nodes.push(t));const r=c({type:"experience",experience:n},this);if(this.nodes.push(r),t){const u=h({sourceNode:t,destinationNode:r,sourceNodeHandle:null},this);this.edges.push(u)}return n},addField(n,i){const t="serialize"in n?n:y(n);return i&&i.fields.push(t),this.fields.includes(t)||this.fields.push(t),t},serialize(){return o.serialize({id:this.id,type:this.type,component:this.component,name:this.name,decide:this.decide,targets:this.targets,steps:this.steps.map(n=>o.deserialize(n.serialize())),nodes:this.nodes.map(n=>o.deserialize(n.serialize())),edges:this.edges.map(n=>o.deserialize(n.serialize())),conditionals:this.conditionals.map(n=>o.deserialize(n.serialize())),fields:this.fields.map(n=>o.deserialize(n.serialize()))})}}};exports.createConditional=m;exports.createEdge=h;exports.createExperience=x;exports.createExperiencePlugin=g;exports.createField=y;exports.createNode=c;exports.createStep=z;exports.serialization=o;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a={homepage:/^\/$/,productPage:/(?:^|\/)products\/(?<productHandle>[^/]+)\/?$/,collection:/^\/collections\/[^/]+\/?$/,page:/(?:^|\/)pages\/[^/]+$/,blog:/(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,article:/^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,cart:/(?:^|\/)cart\/[^/]+$/,checkout:/^\/checkout\/.+/,appProxy:/^\/(?:a|apps|community|tools)\/(?<proxyTarget>[^/]+)/,accountWildcard:/^\/account\/.+/,accountLogin:/^\/account\/login(?:\/|$)/,accountRegister:/^\/account\/register(?:\/|$)/},n=/^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/,t=(e,c)=>c?!!e.exec(c.pathname):!1,o=(e,c)=>{if(c){const i=e.exec(c.pathname);if(i)return i[1]}},g={"is-page":({location:e})=>t(a.page,e),"get-page-handle":({location:e})=>o(a.page,e),"is-product-page":({location:e})=>t(a.productPage,e),"get-product-handle":({location:e})=>o(a.productPage,e),"is-collection-page":({location:e})=>t(a.collection,e),"get-collection-handle":({location:e})=>o(n,e),"is-blog-page":({location:e})=>t(a.blog,e),"get-blog-handle":({location:e})=>o(a.blog,e),"is-article-page":({location:e})=>t(a.article,e),"get-article-handle":({location:e})=>o(a.article,e),"is-app-proxy-page":({location:e})=>t(a.appProxy,e),"get-app-proxy-handle":({location:e})=>o(a.appProxy,e),"is-account-page":({location:e})=>t(a.accountWildcard,e),"is-login-page":({location:e})=>t(a.accountLogin,e),"is-register-page":({location:e})=>t(a.accountRegister,e),"is-cart-page":({location:e})=>t(a.cart,e),"is-checkout-page":({location:e})=>t(a.checkout,e),"is-homepage":({location:e})=>t(a.homepage,e)},l=()=>({name:"shopify",setup:e=>{Object.entries(g).forEach(([c,i])=>{e.registerPredicate(`shopify-${c}`,i)})}});exports.shopifyPlugin=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../../supports-B6KShYPU.cjs"),t={homepage:/^\/$/,productPage:/(?:^|\/)products\/(?<productHandle>[^/]+)\/?$/,collection:/^\/collections\/[^/]+\/?$/,page:/(?:^|\/)pages\/[^/]+$/,blog:/(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,article:/^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,cart:/(?:^|\/)cart\/[^/]+$/,checkout:/^\/checkout\/.+/,appProxy:/^\/(?:a|apps|community|tools)\/(?<proxyTarget>[^/]+)/,accountWildcard:/^\/account\/.+/,accountLogin:/^\/account\/login(?:\/|$)/,accountRegister:/^\/account\/register(?:\/|$)/},p=/^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/,a=(e,o)=>o?!!e.exec(o.pathname):!1,i=(e,o)=>{if(o){const c=e.exec(o.pathname);if(c)return c[1]}},r={"is-page":({location:e})=>a(t.page,e),"get-page-handle":({location:e})=>i(t.page,e),"is-product-page":({location:e})=>a(t.productPage,e),"get-product-handle":({location:e})=>i(t.productPage,e),"is-collection-page":({location:e})=>a(t.collection,e),"get-collection-handle":({location:e})=>i(p,e),"is-blog-page":({location:e})=>a(t.blog,e),"get-blog-handle":({location:e})=>i(t.blog,e),"is-article-page":({location:e})=>a(t.article,e),"get-article-handle":({location:e})=>i(t.article,e),"is-app-proxy-page":({location:e})=>a(t.appProxy,e),"get-app-proxy-handle":({location:e})=>i(t.appProxy,e),"is-account-page":({location:e})=>a(t.accountWildcard,e),"is-login-page":({location:e})=>a(t.accountLogin,e),"is-register-page":({location:e})=>a(t.accountRegister,e),"is-cart-page":({location:e})=>a(t.cart,e),"is-checkout-page":({location:e})=>a(t.checkout,e),"is-homepage":({location:e})=>a(t.homepage,e)};function s(e){var o,c;return typeof((c=(o=e.Shopify)==null?void 0:o.analytics)==null?void 0:c.publish)=="function"}const l=()=>({name:"shopify",setup:e=>{Object.entries(r).forEach(([o,c])=>{e.registerPredicate(`shopify-${o}`,c)}),n.supportsWindow()&&e.eventBus.watch(o=>{s(window)&&o.type==="initialized"&&window.Shopify.analytics.publish("picked:client_event",{type:"initialized",version:o.version})})}});exports.shopifyPlugin=l;
package/dist/esm/index.js CHANGED
@@ -570,7 +570,7 @@ const Ne = (t, e) => {
570
570
  function ze(t) {
571
571
  return k(Le, t);
572
572
  }
573
- const _e = () => "0.0.4";
573
+ const _e = () => "0.0.5-next.1";
574
574
  function Ue() {
575
575
  if (_()) {
576
576
  const t = [
@@ -1,27 +1,36 @@
1
1
  import { g as f } from "../../../id-BW-g3y32.js";
2
- const l = {
3
- serialize(i) {
4
- return JSON.stringify(i);
2
+ const r = {
3
+ serialize(e) {
4
+ return JSON.stringify(e);
5
5
  },
6
- deserialize(i) {
7
- return JSON.parse(i);
6
+ deserialize(e) {
7
+ return JSON.parse(e);
8
8
  }
9
- }, b = (i) => ({
9
+ }, b = (e) => ({
10
10
  name: "create-experience",
11
11
  setup: (a) => {
12
- i.experiences.forEach((d) => {
13
- const s = d.serialize(), o = l.deserialize(s);
14
- o.component = d.component, a.registerExperience(o), o.fields.forEach((h) => {
15
- a.registerField(h);
12
+ e.experiences.forEach((l) => {
13
+ const s = l.serialize(), o = r.deserialize(s);
14
+ o.component = l.component, a.registerExperience(o), o.fields.forEach((c) => {
15
+ a.registerField(c);
16
16
  });
17
17
  });
18
18
  }
19
- }), m = (i, a) => {
20
- const d = {
19
+ }), x = (e) => ({
20
+ id: f("step"),
21
+ label: e.label,
22
+ fields: e.fields ?? [],
23
+ addField(a) {
24
+ var s, o;
25
+ const l = "serialize" in a ? a : m(a);
26
+ return (s = this.fields) != null && s.includes(l) || (o = this.fields) == null || o.push(l), l;
27
+ }
28
+ }), y = (e, a) => {
29
+ const l = {
21
30
  id: f("step"),
22
- label: i.label,
31
+ label: e.label,
23
32
  experience: a,
24
- fields: [],
33
+ fields: e.fields ?? [],
25
34
  node: null,
26
35
  nextStep(s) {
27
36
  return this.experience.addStep(s, this);
@@ -36,27 +45,27 @@ const l = {
36
45
  return this.experience.addField(s, this);
37
46
  },
38
47
  serialize() {
39
- return l.serialize({
48
+ return r.serialize({
40
49
  id: this.id,
41
50
  label: this.label,
42
51
  fieldIds: this.fields.map((s) => s.id)
43
52
  });
44
53
  }
45
54
  };
46
- return u({ step: d, type: "step" }, a), d;
47
- }, y = () => [0, 0], u = (i, a) => {
48
- const d = {
55
+ return h({ step: l, type: "step" }, a), l;
56
+ }, z = () => [0, 0], h = (e, a) => {
57
+ const l = {
49
58
  id: f("node"),
50
- position: y(),
59
+ position: z(),
51
60
  experience: a
52
61
  };
53
- if (i.type === "step") {
62
+ if (e.type === "step") {
54
63
  const o = {
55
- ...d,
64
+ ...l,
56
65
  type: "step",
57
- connectedStep: i.step,
66
+ connectedStep: e.step,
58
67
  serialize() {
59
- return l.serialize({
68
+ return r.serialize({
60
69
  id: this.id,
61
70
  type: this.type,
62
71
  stepId: this.connectedStep.id,
@@ -67,13 +76,13 @@ const l = {
67
76
  };
68
77
  return o.connectedStep.node = o, o;
69
78
  }
70
- if (i.type === "conditional") {
79
+ if (e.type === "conditional") {
71
80
  const o = {
72
- ...d,
81
+ ...l,
73
82
  type: "conditional",
74
- connectedConditional: i.conditional,
83
+ connectedConditional: e.conditional,
75
84
  serialize() {
76
- return l.serialize({
85
+ return r.serialize({
77
86
  id: this.id,
78
87
  type: this.type,
79
88
  conditionalId: this.connectedConditional.id,
@@ -83,12 +92,12 @@ const l = {
83
92
  };
84
93
  return o.connectedConditional.node = o, o;
85
94
  }
86
- return i.type === "experience" ? {
87
- ...d,
95
+ return e.type === "experience" ? {
96
+ ...l,
88
97
  type: "experience",
89
- connectedExperience: i.experience,
98
+ connectedExperience: e.experience,
90
99
  serialize() {
91
- return l.serialize({
100
+ return r.serialize({
92
101
  id: this.id,
93
102
  type: this.type,
94
103
  experienceId: this.connectedExperience.id,
@@ -96,34 +105,34 @@ const l = {
96
105
  });
97
106
  }
98
107
  } : {
99
- ...d,
108
+ ...l,
100
109
  type: "origin",
101
110
  serialize() {
102
- return l.serialize({
111
+ return r.serialize({
103
112
  id: this.id,
104
113
  type: this.type,
105
114
  position: this.position
106
115
  });
107
116
  }
108
117
  };
109
- }, p = (i, a) => ({
118
+ }, p = (e, a) => ({
110
119
  id: f("edge"),
111
- sourceNode: i.sourceNode,
112
- sourceNodeHandle: i.sourceNodeHandle,
113
- destinationNode: i.destinationNode,
120
+ sourceNode: e.sourceNode,
121
+ sourceNodeHandle: e.sourceNodeHandle,
122
+ destinationNode: e.destinationNode,
114
123
  experience: a,
115
124
  serialize() {
116
- return l.serialize({
125
+ return r.serialize({
117
126
  id: this.id,
118
127
  sourceNodeHandle: this.sourceNodeHandle ?? void 0,
119
128
  sourceNodeId: this.sourceNode.id,
120
129
  destinationNodeId: this.destinationNode.id
121
130
  });
122
131
  }
123
- }), N = (i, a) => {
124
- const d = {
132
+ }), N = (e, a) => {
133
+ const l = {
125
134
  id: f("conditional"),
126
- condition: i.condition,
135
+ condition: e.condition,
127
136
  node: null,
128
137
  experience: a,
129
138
  addTrue(s) {
@@ -145,31 +154,31 @@ const l = {
145
154
  this.experience.edges.push(o);
146
155
  },
147
156
  serialize() {
148
- return l.serialize({
157
+ return r.serialize({
149
158
  id: this.id,
150
159
  condition: this.condition
151
160
  });
152
161
  }
153
162
  };
154
- return u({ conditional: d, type: "conditional" }, a), d;
155
- }, z = (i) => {
156
- var d;
163
+ return h({ conditional: l, type: "conditional" }, a), l;
164
+ }, m = (e) => {
165
+ var l;
157
166
  return {
158
- id: i.id,
159
- name: i.name,
160
- type: i.type,
161
- label: i.label,
162
- placeholder: i.placeholder,
163
- description: i.description,
164
- helpText: i.helpText,
165
- defaultValue: i.defaultValue,
166
- multiple: i.multiple,
167
- validation: i.validation,
168
- required: i.required,
169
- options: ((d = i.options) == null ? void 0 : d.map((s) => ({
167
+ id: e.id,
168
+ name: e.name,
169
+ type: e.type,
170
+ label: e.label,
171
+ placeholder: e.placeholder,
172
+ description: e.description,
173
+ helpText: e.helpText,
174
+ defaultValue: e.defaultValue,
175
+ multiple: e.multiple,
176
+ validation: e.validation,
177
+ required: e.required,
178
+ options: ((l = e.options) == null ? void 0 : l.map((s) => ({
170
179
  ...s
171
180
  }))) || null,
172
- policies: i.policies,
181
+ policies: e.policies,
173
182
  serialize() {
174
183
  const s = {
175
184
  id: this.id,
@@ -181,22 +190,22 @@ const l = {
181
190
  helpText: this.helpText,
182
191
  validation: this.validation,
183
192
  policies: this.policies
184
- }, o = typeof this.defaultValue == "string" ? this.defaultValue : null, h = typeof this.defaultValue == "number" ? this.defaultValue : null, n = typeof this.defaultValue == "boolean" ? this.defaultValue : null;
193
+ }, o = typeof this.defaultValue == "string" ? this.defaultValue : null, c = typeof this.defaultValue == "number" ? this.defaultValue : null, n = typeof this.defaultValue == "boolean" ? this.defaultValue : null;
185
194
  switch (this.type) {
186
195
  case "text":
187
196
  if (this.multiple) {
188
- let e = null;
197
+ let i = null;
189
198
  if (Array.isArray(this.defaultValue)) {
190
- e = [];
199
+ i = [];
191
200
  for (const t of this.defaultValue)
192
- typeof t == "string" && e.push(t);
193
- e.length === 0 && (e = null);
201
+ typeof t == "string" && i.push(t);
202
+ i.length === 0 && (i = null);
194
203
  }
195
- return l.serialize({
204
+ return r.serialize({
196
205
  ...s,
197
206
  type: "text",
198
207
  multiple: !0,
199
- defaultValue: e,
208
+ defaultValue: i,
200
209
  options: this.options ? this.options.map((t) => ({
201
210
  id: t.id,
202
211
  label: t.label,
@@ -204,31 +213,31 @@ const l = {
204
213
  })) : null
205
214
  });
206
215
  }
207
- return l.serialize({
216
+ return r.serialize({
208
217
  ...s,
209
218
  type: "text",
210
219
  multiple: !1,
211
220
  defaultValue: o,
212
- options: this.options ? this.options.map((e) => ({
213
- id: e.id,
214
- label: e.label,
215
- value: `${e.value}`
221
+ options: this.options ? this.options.map((i) => ({
222
+ id: i.id,
223
+ label: i.label,
224
+ value: `${i.value}`
216
225
  })) : null
217
226
  });
218
227
  case "number":
219
228
  if (this.multiple) {
220
- let e = null;
229
+ let i = null;
221
230
  if (Array.isArray(this.defaultValue)) {
222
- e = [];
231
+ i = [];
223
232
  for (const t of this.defaultValue)
224
- typeof t == "number" && e.push(t);
225
- e.length === 0 && (e = null);
233
+ typeof t == "number" && i.push(t);
234
+ i.length === 0 && (i = null);
226
235
  }
227
- return l.serialize({
236
+ return r.serialize({
228
237
  ...s,
229
238
  type: "number",
230
239
  multiple: !0,
231
- defaultValue: e,
240
+ defaultValue: i,
232
241
  options: this.options ? this.options.map((t) => ({
233
242
  id: t.id,
234
243
  label: t.label,
@@ -236,31 +245,31 @@ const l = {
236
245
  })) : null
237
246
  });
238
247
  }
239
- return l.serialize({
248
+ return r.serialize({
240
249
  ...s,
241
250
  type: "number",
242
251
  multiple: !1,
243
- defaultValue: h,
244
- options: this.options ? this.options.map((e) => ({
245
- id: e.id,
246
- label: e.label,
247
- value: Number(e.value)
252
+ defaultValue: c,
253
+ options: this.options ? this.options.map((i) => ({
254
+ id: i.id,
255
+ label: i.label,
256
+ value: Number(i.value)
248
257
  })) : null
249
258
  });
250
259
  case "boolean":
251
260
  if (this.multiple) {
252
- let e = null;
261
+ let i = null;
253
262
  if (Array.isArray(this.defaultValue)) {
254
- e = [];
263
+ i = [];
255
264
  for (const t of this.defaultValue)
256
- typeof t == "boolean" && e.push(t);
257
- e.length === 0 && (e = null);
265
+ typeof t == "boolean" && i.push(t);
266
+ i.length === 0 && (i = null);
258
267
  }
259
- return l.serialize({
268
+ return r.serialize({
260
269
  ...s,
261
270
  type: "boolean",
262
271
  multiple: !0,
263
- defaultValue: e,
272
+ defaultValue: i,
264
273
  options: this.options ? this.options.map((t) => ({
265
274
  id: t.id,
266
275
  label: t.label,
@@ -268,15 +277,15 @@ const l = {
268
277
  })) : null
269
278
  });
270
279
  }
271
- return l.serialize({
280
+ return r.serialize({
272
281
  ...s,
273
282
  type: "boolean",
274
283
  multiple: !1,
275
284
  defaultValue: n,
276
- options: this.options ? this.options.map((e) => ({
277
- id: e.id,
278
- label: e.label,
279
- value: !!e.value
285
+ options: this.options ? this.options.map((i) => ({
286
+ id: i.id,
287
+ label: i.label,
288
+ value: !!i.value
280
289
  })) : null
281
290
  });
282
291
  // todo: support for object type fields
@@ -302,85 +311,87 @@ const l = {
302
311
  }
303
312
  }
304
313
  };
305
- }, x = (i) => {
306
- const a = [], d = [], s = [], o = [], h = [];
314
+ }, V = (e) => {
315
+ const a = [], l = [], s = [], o = [], c = [];
307
316
  return {
308
- id: i.id,
309
- component: i.component,
310
- type: i.type,
311
- name: i.name,
312
- decide: i.decide,
313
- targets: i.targets,
317
+ id: e.id,
318
+ component: e.component,
319
+ type: e.type,
320
+ name: e.name,
321
+ decide: e.decide,
322
+ targets: e.targets,
314
323
  steps: a,
315
- nodes: d,
324
+ nodes: l,
316
325
  edges: s,
317
- fields: h,
326
+ fields: c,
318
327
  conditionals: o,
319
- addStep(n, e) {
320
- let t = e == null ? void 0 : e.node;
321
- this.nodes.length === 0 && (t = u({ type: "origin" }, this), this.nodes.push(t));
322
- const r = "serialize" in n ? n : m(n, this);
328
+ addStep(n, i) {
329
+ let t = i == null ? void 0 : i.node;
330
+ this.nodes.length === 0 && (t = h({ type: "origin" }, this), this.nodes.push(t));
331
+ const d = "serialize" in n ? n : y(n, this);
323
332
  if (t) {
324
- if (!r.node)
333
+ if (!d.node)
325
334
  throw new Error("todo no node");
326
- const c = p(
327
- { sourceNode: t, destinationNode: r.node, sourceNodeHandle: null },
335
+ const u = p(
336
+ { sourceNode: t, destinationNode: d.node, sourceNodeHandle: null },
328
337
  this
329
338
  );
330
- this.edges.push(c);
339
+ this.edges.push(u);
331
340
  }
332
- return this.steps.includes(r) || (this.steps.push(r), r.node && this.nodes.push(r.node)), r;
341
+ return d.fields.length > 0 && d.fields.forEach((u) => {
342
+ this.fields.includes(u) || this.fields.push(u);
343
+ }), this.steps.includes(d) || (this.steps.push(d), d.node && this.nodes.push(d.node)), d;
333
344
  },
334
- addConditional(n, e) {
335
- let t = e == null ? void 0 : e.node;
336
- this.nodes.length === 0 && (t = u({ type: "origin" }, this), this.nodes.push(t));
337
- const r = "serialize" in n ? n : N(n, this);
345
+ addConditional(n, i) {
346
+ let t = i == null ? void 0 : i.node;
347
+ this.nodes.length === 0 && (t = h({ type: "origin" }, this), this.nodes.push(t));
348
+ const d = "serialize" in n ? n : N(n, this);
338
349
  if (t) {
339
- if (!r.node)
350
+ if (!d.node)
340
351
  throw new Error("todo no node");
341
- const c = p(
342
- { sourceNode: t, destinationNode: r.node, sourceNodeHandle: null },
352
+ const u = p(
353
+ { sourceNode: t, destinationNode: d.node, sourceNodeHandle: null },
343
354
  this
344
355
  );
345
- this.edges.push(c);
356
+ this.edges.push(u);
346
357
  }
347
- return this.conditionals.includes(r) || (this.conditionals.push(r), r.node && this.nodes.push(r.node)), r;
358
+ return this.conditionals.includes(d) || (this.conditionals.push(d), d.node && this.nodes.push(d.node)), d;
348
359
  },
349
- addExperience(n, e) {
350
- let t = e == null ? void 0 : e.node;
351
- this.nodes.length === 0 && (t = u({ type: "origin" }, this), this.nodes.push(t));
352
- const r = u(
360
+ addExperience(n, i) {
361
+ let t = i == null ? void 0 : i.node;
362
+ this.nodes.length === 0 && (t = h({ type: "origin" }, this), this.nodes.push(t));
363
+ const d = h(
353
364
  { type: "experience", experience: n },
354
365
  this
355
366
  );
356
- if (this.nodes.push(r), t) {
357
- const c = p(
358
- { sourceNode: t, destinationNode: r, sourceNodeHandle: null },
367
+ if (this.nodes.push(d), t) {
368
+ const u = p(
369
+ { sourceNode: t, destinationNode: d, sourceNodeHandle: null },
359
370
  this
360
371
  );
361
- this.edges.push(c);
372
+ this.edges.push(u);
362
373
  }
363
374
  return n;
364
375
  },
365
- addField(n, e) {
366
- const t = "serialize" in n ? n : z(n);
367
- return e && e.fields.push(t), this.fields.includes(t) || this.fields.push(t), t;
376
+ addField(n, i) {
377
+ const t = "serialize" in n ? n : m(n);
378
+ return i && i.fields.push(t), this.fields.includes(t) || this.fields.push(t), t;
368
379
  },
369
380
  serialize() {
370
- return l.serialize({
381
+ return r.serialize({
371
382
  id: this.id,
372
383
  type: this.type,
373
384
  component: this.component,
374
385
  name: this.name,
375
386
  decide: this.decide,
376
387
  targets: this.targets,
377
- steps: this.steps.map((n) => l.deserialize(n.serialize())),
378
- nodes: this.nodes.map((n) => l.deserialize(n.serialize())),
379
- edges: this.edges.map((n) => l.deserialize(n.serialize())),
388
+ steps: this.steps.map((n) => r.deserialize(n.serialize())),
389
+ nodes: this.nodes.map((n) => r.deserialize(n.serialize())),
390
+ edges: this.edges.map((n) => r.deserialize(n.serialize())),
380
391
  conditionals: this.conditionals.map(
381
- (n) => l.deserialize(n.serialize())
392
+ (n) => r.deserialize(n.serialize())
382
393
  ),
383
- fields: this.fields.map((n) => l.deserialize(n.serialize()))
394
+ fields: this.fields.map((n) => r.deserialize(n.serialize()))
384
395
  });
385
396
  }
386
397
  };
@@ -388,10 +399,10 @@ const l = {
388
399
  export {
389
400
  N as createConditional,
390
401
  p as createEdge,
391
- x as createExperience,
402
+ V as createExperience,
392
403
  b as createExperiencePlugin,
393
- z as createField,
394
- u as createNode,
395
- m as createStep,
396
- l as serialization
404
+ m as createField,
405
+ h as createNode,
406
+ x as createStep,
407
+ r as serialization
397
408
  };
@@ -1,4 +1,5 @@
1
- const a = {
1
+ import { a as n } from "../../../supports-yKVnaaMQ.js";
2
+ const t = {
2
3
  homepage: /^\/$/,
3
4
  productPage: /(?:^|\/)products\/(?<productHandle>[^/]+)\/?$/,
4
5
  collection: /^\/collections\/[^/]+\/?$/,
@@ -11,49 +12,59 @@ const a = {
11
12
  accountWildcard: /^\/account\/.+/,
12
13
  accountLogin: /^\/account\/login(?:\/|$)/,
13
14
  accountRegister: /^\/account\/register(?:\/|$)/
14
- }, n = /^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/, c = (e, t) => t ? !!e.exec(t.pathname) : !1, o = (e, t) => {
15
- if (t) {
16
- const p = e.exec(t.pathname);
17
- if (p)
18
- return p[1];
15
+ }, p = /^\/collections\/(?<collectionHandle>[^/]+)(?:\/|$)/, o = (e, a) => a ? !!e.exec(a.pathname) : !1, i = (e, a) => {
16
+ if (a) {
17
+ const c = e.exec(a.pathname);
18
+ if (c)
19
+ return c[1];
19
20
  }
20
- }, g = {
21
+ }, r = {
21
22
  // Pages
22
- "is-page": ({ location: e }) => c(a.page, e),
23
- "get-page-handle": ({ location: e }) => o(a.page, e),
23
+ "is-page": ({ location: e }) => o(t.page, e),
24
+ "get-page-handle": ({ location: e }) => i(t.page, e),
24
25
  // Products
25
- "is-product-page": ({ location: e }) => c(a.productPage, e),
26
- "get-product-handle": ({ location: e }) => o(a.productPage, e),
26
+ "is-product-page": ({ location: e }) => o(t.productPage, e),
27
+ "get-product-handle": ({ location: e }) => i(t.productPage, e),
27
28
  // Collections
28
- "is-collection-page": ({ location: e }) => c(a.collection, e),
29
- "get-collection-handle": ({ location: e }) => o(n, e),
29
+ "is-collection-page": ({ location: e }) => o(t.collection, e),
30
+ "get-collection-handle": ({ location: e }) => i(p, e),
30
31
  // Blogs
31
- "is-blog-page": ({ location: e }) => c(a.blog, e),
32
- "get-blog-handle": ({ location: e }) => o(a.blog, e),
32
+ "is-blog-page": ({ location: e }) => o(t.blog, e),
33
+ "get-blog-handle": ({ location: e }) => i(t.blog, e),
33
34
  // Blog Articles
34
- "is-article-page": ({ location: e }) => c(a.article, e),
35
- "get-article-handle": ({ location: e }) => o(a.article, e),
35
+ "is-article-page": ({ location: e }) => o(t.article, e),
36
+ "get-article-handle": ({ location: e }) => i(t.article, e),
36
37
  // Apps
37
- "is-app-proxy-page": ({ location: e }) => c(a.appProxy, e),
38
- "get-app-proxy-handle": ({ location: e }) => o(a.appProxy, e),
38
+ "is-app-proxy-page": ({ location: e }) => o(t.appProxy, e),
39
+ "get-app-proxy-handle": ({ location: e }) => i(t.appProxy, e),
39
40
  // Account
40
- "is-account-page": ({ location: e }) => c(a.accountWildcard, e),
41
- "is-login-page": ({ location: e }) => c(a.accountLogin, e),
42
- "is-register-page": ({ location: e }) => c(a.accountRegister, e),
41
+ "is-account-page": ({ location: e }) => o(t.accountWildcard, e),
42
+ "is-login-page": ({ location: e }) => o(t.accountLogin, e),
43
+ "is-register-page": ({ location: e }) => o(t.accountRegister, e),
43
44
  // Cart
44
- "is-cart-page": ({ location: e }) => c(a.cart, e),
45
+ "is-cart-page": ({ location: e }) => o(t.cart, e),
45
46
  // Checkout
46
- "is-checkout-page": ({ location: e }) => c(a.checkout, e),
47
+ "is-checkout-page": ({ location: e }) => o(t.checkout, e),
47
48
  // Homepage
48
- "is-homepage": ({ location: e }) => c(a.homepage, e)
49
- }, r = () => ({
49
+ "is-homepage": ({ location: e }) => o(t.homepage, e)
50
+ };
51
+ function l(e) {
52
+ var a, c;
53
+ return typeof ((c = (a = e.Shopify) == null ? void 0 : a.analytics) == null ? void 0 : c.publish) == "function";
54
+ }
55
+ const g = () => ({
50
56
  name: "shopify",
51
57
  setup: (e) => {
52
- Object.entries(g).forEach(([t, p]) => {
53
- e.registerPredicate(`shopify-${t}`, p);
58
+ Object.entries(r).forEach(([a, c]) => {
59
+ e.registerPredicate(`shopify-${a}`, c);
60
+ }), n() && e.eventBus.watch((a) => {
61
+ l(window) && a.type === "initialized" && window.Shopify.analytics.publish("picked:client_event", {
62
+ type: "initialized",
63
+ version: a.version
64
+ });
54
65
  });
55
66
  }
56
67
  });
57
68
  export {
58
- r as shopifyPlugin
69
+ g as shopifyPlugin
59
70
  };
@@ -19,6 +19,7 @@ export interface SerializableStep extends Nodeable {
19
19
  }
20
20
  export interface CreateStepOptions {
21
21
  label: string;
22
+ fields?: SerializableField[];
22
23
  }
23
24
  export type SerializableNode = SerializableStepNode | SerializableConditionalNode | SerializableLaunchExperienceNode | SerializableOriginNode;
24
25
  export interface SerializableBaseNode {
@@ -117,7 +118,7 @@ export interface SerializableExperience {
117
118
  edges: SerializableEdge[];
118
119
  fields: SerializableField[];
119
120
  conditionals: SerializableConditional[];
120
- addStep: (stepOptions: CreateStepOptions | SerializableStep, after?: {
121
+ addStep: (stepOptions: CreateStepOptions | SerializableStep | OrphanStep, after?: {
121
122
  node: SerializableNode | null;
122
123
  }) => SerializableStep;
123
124
  addConditional: (conditionalOptions: CreateConditionalOptions | SerializableConditional, after?: {
@@ -137,7 +138,11 @@ export interface CreateExperienceOptions {
137
138
  component?: AdaptedComponent;
138
139
  type: string;
139
140
  }
140
- export declare const createStep: (stepOptions: CreateStepOptions, experience: SerializableExperience) => SerializableStep;
141
+ export type OrphanStep = Omit<SerializableStep, 'nextStep' | 'nextConditional' | 'addNextExperience' | 'node' | 'serialize' | 'addField' | 'experience'> & {
142
+ addField: (fieldOrFieldOptions: CreateFieldOptions | SerializableField) => void;
143
+ };
144
+ export declare const createStep: (stepOptions: CreateStepOptions) => OrphanStep;
145
+ export declare const bindExperienceStep: (stepOptions: CreateStepOptions | OrphanStep, experience: SerializableExperience) => SerializableStep;
141
146
  export declare const createNode: (nodeOptions: CreateNodeOptions, experience: SerializableExperience) => SerializableNode;
142
147
  export declare const createEdge: (edgeOptions: CreateEdgeOptions, experience: SerializableExperience) => SerializableEdge;
143
148
  export declare const createConditional: (conditionalOptions: CreateConditionalOptions, experience: SerializableExperience) => SerializableConditional;
@@ -1 +1 @@
1
- {"version":3,"file":"create-experience.d.ts","sourceRoot":"","sources":["../../../../src/plugins/create-experience/create-experience.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAGjB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EACV,KAAK,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB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A;IAC3B,QAAQ,EAAE,CACR,YAAY,EAAE,kBAAkB,GAAG,iBAAiB,EACpD,IAAI,CAAC,EAAE,gBAAgB,KACpB,iBAAiB,CAAA;IACtB,SAAS,EAAE,MAAM,UAAU,CAAC,UAAU,CAAC,CAAA;CACxC;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3B,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,UAAU,GACrB,aAAa,iBAAiB,EAC9B,YAAY,sBAAsB,KACjC,gBA+BF,CAAA;AAID,eAAO,MAAM,UAAU,GACrB,aAAa,iBAAiB,EAC9B,YAAY,sBAAsB,KACjC,gBA+EF,CAAA;AAED,eAAO,MAAM,UAAU,GACrB,aAAa,iBAAiB,EAC9B,YAAY,sBAAsB,KACjC,gBAkBF,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,oBAAoB,wBAAwB,EAC5C,YAAY,sBAAsB,KACjC,uBA0CF,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,cAAc,kBAAkB,KAAG,iBAyM9D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,uBAAuB,KAAG,sBAmJtE,CAAA"}
1
+ {"version":3,"file":"create-experience.d.ts","sourceRoot":"","sources":["../../../../src/plugins/create-experience/create-experience.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAGjB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EACV,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AAI,cAAc,kBAAkB,KAAG,iBAyM9D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,uBAAuB,KAAG,sBA6JtE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAI1D,eAAO,MAAM,aAAa,QAAO,MAShC,CAAA"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAM1D,eAAO,MAAM,aAAa,QAAO,MA6BhC,CAAA"}
@@ -0,0 +1,21 @@
1
+ interface EventPayload {
2
+ [key: string]: string | number | boolean | null | undefined | EventPayload | Array<string | number | boolean | null | undefined | EventPayload>;
3
+ }
4
+ declare global {
5
+ interface Window {
6
+ Shopify?: {
7
+ analytics?: {
8
+ publish?: (event: string, payload: EventPayload) => void;
9
+ };
10
+ };
11
+ }
12
+ }
13
+ export declare function supportsShopifyAnalytics(w: Window): w is Window & {
14
+ Shopify: {
15
+ analytics: {
16
+ publish: (event: string, payload: EventPayload) => void;
17
+ };
18
+ };
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/utils.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IACpB,CAAC,GAAG,EAAE,MAAM,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,YAAY,GACZ,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,CAAC,CAAA;CACvE;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,CAAC,EAAE;YACR,SAAS,CAAC,EAAE;gBACV,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;aACzD,CAAA;SACF,CAAA;KACF;CACF;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG;IACjE,OAAO,EAAE;QAAE,SAAS,EAAE;YAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;SAAE,CAAA;KAAE,CAAA;CACpF,CAEA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-next.1",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },