@picked/client 0.0.12-next.12 → 0.0.12-next.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/shopify/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugins/shopify/index.js +46 -38
- package/dist/types/plugins/shopify/shopify.d.ts +19 -5
- package/dist/types/plugins/shopify/shopify.d.ts.map +1 -1
- package/dist/types/plugins/shopify/utils.d.ts +56 -0
- package/dist/types/plugins/shopify/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var V=(t,e,r)=>e in t?U(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"),h=require("@withease/factories"),F=require("../experience-instance-B2l_MG7I.cjs"),I=require("../logger-BsmHUUw1.cjs"),w=require("../storage-DuRlyFaY.cjs"),N=require("../id-BKIWbSTy.cjs"),z=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),L=f.createDomain("experience"),_=h.createFactory(({client:t,experience:e})=>{const r=L.store(e),n=f.createApi(r,{merge(l,S){return{...l,...S.experience}}}),c=r.map(l=>({name:l.name,decisionLogic:l.decide,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),u=t.components.listStore.map(l=>l.find(S=>S.name===`experience:${e.id}`)||l.find(S=>S.name==="experience"),{skipVoid:!1}),s=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),o=e.actions??[];return{id:e.id,configStore:c,treeStore:s,componentStore:u,actions:o,merge:n.merge}});function q(t){return h.invoke(_,t)}const K=h.createFactory(({client:t})=>{const e=L.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.id]:o}}});function n(s){const o=e.getState()[s.id];if(o){o.merge({experience:s,strategy:"override"});return}const l=q({client:t,experience:s});r.register(l)}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getById:u,listStore:c}});function H(t){return h.invoke(K,t)}const W=(t,e)=>{e.register(t)},M=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=F.getTargetElements(r,e.id);n.forEach(({elements:u})=>u.forEach(s=>F.tagTargetElement(s,e.id))),F.createAppHosts(n,e.id).forEach(u=>{t.experienceInstances.spawn(e,u)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await G(t,e)&&M(t,e)}))},G=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return F.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&F.isRulesLogic(r)?await F.evaluateRuleLogic(t,r)===!0:!0},Y=(t,e,r)=>{const n=e.name,c=e.setup(t);if(c){const u=r[n]??{};r[n]=Object.freeze({...u,...c})}},J=f.createDomain("component"),Q=h.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function X(t){return h.invoke(Q,t)}const Z=h.createFactory(({client:t})=>{const e=J.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const S=X({client:t,name:s,component:o});r.register(S)}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function ee(t){return h.invoke(Z,t)}const $=(t,e,r)=>{r.register(t,e)},te=f.createDomain("framework"),re=h.createFactory(({client:t})=>{const e=te.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o.framework}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Framework '${s}' already registered. Registering again will override the previous registration.`),r.register({name:s,framework:o})}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function se(t){return h.invoke(re,t)}const ne=(t,e)=>{e.register(t.name,t)},oe=6e3,j=w.createStorageKey("last_ping","global"),ie=t=>`${t}/api/v1/ping`,ae=async t=>{try{const e=Date.now(),r=localStorage.getItem(j);if(r&&e-parseInt(r)<oe)return!0;const n=ie(t.apiUrl),c={projectId:t.projectId,path:window.location.pathname},u=JSON.stringify(c),s={"Content-Type":"application/json"},o=document.getElementById("picked_script"),l=o==null?void 0:o.dataset.verceltoken;l&&(s["x-vercel-protection-bypass"]=l);const b=(await fetch(n,{method:"POST",headers:s,body:u})).ok;return b&&localStorage.setItem(j,e.toString()),b}catch(e){return I.logger("error",e),!1}};function ce(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 ue=f.createDomain("predicate"),le=h.createFactory(({client:t})=>{const e=ue.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:{name:o.name,predicate:o.predicate}}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Predicate '${s}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:s,predicate:o}))}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function pe(t){return h.invoke(le,t)}const ge=(t,e,r)=>{r.register(t,e)},C=f.createDomain("feature"),de=h.createFactory(({client:t})=>{const e=C.store({}),r=C.store([]),n=f.createApi(e,{register(p,a){return{...p,[a.id]:a.feature}}});function c(p,a){e.getState()[p]&&I.logger("warn",`Feature '${p}' already registered. Registering again will override the previous registration.`);const d={id:p,feature:{...a,id:p}};n.register(Object.freeze({id:p,feature:d}))}const u=f.createEffect(async({id:p,key:a,storage:i="local"})=>{const d=w.createStorageKey(`feature:${p}:${a}`,"global"),g=(i==="session"?w.sessionStore:w.localStore).get(d).boolean();return g===null?null:{id:p,key:a,bucket:g}}),s=f.createEffect(p=>{if(!p)return null;const a=w.createStorageKey(`feature:${p.id}:${p.key}`,"global");(p.storage==="session"?w.sessionStore:w.localStore).set(a,p.bucket)}),o=new Map,l=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:p,resolvedFeaturesStore:a},{id:i,decide:d,key:m})=>{const g=a.find(A=>A.id===i);if(g)return g;const v=p[i];if(!v)throw new Error(`Feature with id '${i}' not found`);const x=o.get(`${i}:${m}`);if(x!==void 0){const A=await x;return{id:v.id,bucket:A,key:m,storage:v.feature.storage}}const P=d();o.set(`${i}:${m}`,P);const E=await P;return{id:v.id,bucket:E,key:m,storage:v.feature.storage}}});f.sample({clock:n.register,fn:p=>{const{id:a,feature:i}=p;return{id:a,key:i.feature.key,storage:i.feature.storage}},target:u}),f.sample({source:e,clock:l.doneData,fn:(p,a)=>{var v;const{id:i,bucket:d,storage:m}=a,g=(v=p[i])==null?void 0:v.feature.key;return g?{key:g,id:i,bucket:d,storage:m}:null},target:s});const S=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:p,resolvedFeaturesStore:a})=>Object.values(p).map(i=>{const d=a.find(m=>m.id===i.id);return d?{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:()=>({id:i.id,bucket:d.bucket}),isResolved:!0}:{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:async()=>await l(i.feature),isResolved:!1}}));f.sample({clock:l.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:p},{id:a})=>!p.some(i=>i.id===a),fn:(p,a)=>a,target:t.eventBus.prepend(p=>({type:"feature_decide",feature:p}))}),f.sample({clock:[u.doneData,l.doneData],source:r,fn:(p,a)=>!a||p.some(i=>i.id===a.id)?p:[...p,a],target:r});function b(p){return e.map(a=>a[p],{skipVoid:!1})}return{register:c,getByName:b,listStore:S}});function fe(t){return h.invoke(de,t)}const me=(t,e,r)=>{r.register(t,e)},R=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 ye=h.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),c=R.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(c,(s,o)=>o);function u(s,o){const l={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=s.length-1;S>=0;S--){const b=s[S],p=b==null?void 0:b.node;if(!(!p||!F.isStepNode(p))&&!(o&&(b==null?void 0:b.experienceId)!==o))if(l.lastStepIndex===-1)l.lastStepIndex=S;else{l.secondLastStepIndex=S;break}}return l}return t.on(n,(s,o)=>{const{secondLastStepIndex:l}=u(s.entries,o.experienceId),S=l!==-1?s.entries.slice(0,l+1):s.entries;return{...s,entries:S}}),{push:e,replace:r,back:n,restore:c,entriesStore:t.map(s=>s.entries)}});function he(){return h.invoke(ye)}const Se=()=>f.createEvent(),ve=f.createDomain("field"),ke=h.createFactory(()=>{const t=ve.store({}),e=f.createApi(t,{register(s,o){return{...s,[o.field.id]:o.field}}});function r(s){e.register({field:s})}const n=t.map(s=>Object.values(s));function c(s){return t.map(o=>o[s]||null)}function u(s){return t.map(o=>Object.values(o).find(l=>l.name===s)||null)}return{register:r,getById:c,listStore:n,getByName:u}});function we(){return h.invoke(ke)}const Fe=(t,e)=>{e.register(t)},be=f.createDomain("action"),Ie=h.createFactory(()=>{const t=be.store({}),e=f.createApi(t,{register(u,s){return{...u,[s.name]:{name:s.name,action:s.action}}}});function r(u,s){e.register({name:u,action:s})}const n=t.map(u=>Object.values(u));function c(u){return t.map(s=>s[u],{skipVoid:!1})}return{register:r,getByName:c,listStore:n}});function xe(){return h.invoke(Ie)}const Ee=(t,e,r)=>{r.register(t,e)},Re=f.createDomain("response"),Pe=h.createFactory(({client:t})=>{const e=Re.store({}),r=f.createEvent(),n=f.createEvent(),c=f.createApi(e,{register(a,i){return{...a,[i.fieldId]:i.response}},registerBatch(a,i){return{...a,...i}},clear(a,i){const{[i]:d,...m}=a;return m},clearAll(){return{}}});function u(a,i){c.register({fieldId:a,response:i})}async function s(a){const i=[];return await Promise.allSettled(Object.entries(a).map(async([d,m])=>{let g=m;const v=t.fields.getById(d).getState();if(!v){i.push({fieldId:d,userMessage:`Field '${d}' not found`,systemMessage:`No field with ID '${d}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:g});return}if(v.multiple&&(typeof g=="string"||typeof g=="number"||typeof g=="boolean")&&(g=[g]),v.validation&&!z.isEmpty(v.validation)){const x=await F.evaluateRuleLogic(t,v.validation,{$input:g});if(typeof x=="string"){i.push({fieldId:d,userMessage:x,systemMessage:`Field validation resulted in an error: ${x}.`,value:g});return}if(x===!1){i.push({fieldId:d,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(v.required&&(typeof g>"u"||g===null||g===""||Array.isArray(g)&&!g.length)){i.push({fieldId:d,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!v.multiple&&Array.isArray(g)&&g.length>1){i.push({fieldId:d,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(v.options){const x=v.options.map(E=>E.value),P=Array.isArray(g)?g:[g];Array.isArray(g)&&(P.every(E=>x.includes(E))||i.push({fieldId:d,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${x.join(", ")}`,value:g}))}})),{responsesToCommit:a,validationErrors:i}}async function o(a){const{responsesToCommit:i,validationErrors:d}=await s(a);return d.length?{errors:d}:(c.registerBatch(i),{errors:[]})}const l=e.map(a=>a),S=e.map(a=>Object.keys(a).map(d=>({fieldId:d,value:a[d]})));function b(a){const i=t.fields.getById(a),d=e.map(m=>m[a]||null);return f.combine({f:i,r:d},({f:m,r:g})=>g||(m!=null&&m.defaultValue?m.defaultValue:null))}function p(a){const i=t.fields.getByName(a);return f.combine({f:i,s:e},({f:d,s:m})=>{const g=d&&m[d.id]||null;return g||(d!=null&&d.defaultValue?d.defaultValue:null)})}return f.sample({clock:r,target:c.clearAll}),f.sample({clock:n,target:c.clear}),{register:u,clearAll:r,clear:n,commit:o,getResponsesToCommit:s,listStore:S,getAllStore:l,getByFieldId:b,getByFieldName:p}});function Ae(t){return h.invoke(Pe,t)}const De=()=>"0.0.12-next.12";function Be(){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 $e(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[c]of t.entries())c.startsWith("picked-")&&r.add(c);for(const c of r){const u=c.replace("picked-","");e[u]=t.getAll(c)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const c=w.sessionStore.get(n);if(c)return c.json()||{}}return e}function je(){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 Ce=()=>({id:je()}),Oe=w.createStorageKey("session","global"),Le=()=>{if(!k.supportsLocalStorage())return null;const t=w.localStore.get(Oe);let e=t.isSet()?t.json():null;return e||(e=Ce(),t.set(e)),e},Me=()=>Le();class D{constructor(e){y(this,"options");y(this,"isReady",!1);y(this,"project");y(this,"plugins",{});y(this,"eventBus",Se());y(this,"organizationId");y(this,"projectId");y(this,"apiUrl");y(this,"session");y(this,"searchParams",$e());y(this,"history",he());y(this,"components",ee({client:this}));y(this,"experienceInstances",F.createExperienceInstanceIndex({client:this}));y(this,"experiences",H({client:this}));y(this,"frameworks",se({client:this}));y(this,"predicates",pe({client:this}));y(this,"features",fe({client:this}));y(this,"responses",Ae({client:this}));y(this,"fields",we());y(this,"actions",xe());I.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Be(),this.session=Me(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.eventBus({type:"initialized",version:De()}),I.logger("info","Picked client initialized.")}start(){ae(this),(async()=>{k.supportsDocument()&&(document.body&&B(this),await F.domInteractive(),await B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session}))})()}registerFramework(e){ne(e,this.frameworks)}registerComponent(e,r){$(e,r,this.components)}registerPlugin(e){Y(this,e,this.plugins)}registerFeature(e,r){me(e,r,this.features)}registerPredicate(e,r){ge(e,r,this.predicates)}registerField(e){Fe(e,this.fields)}registerAction(e,r){Ee(e,r,this.actions)}registerExperience(e){e.component&&$(`experience:${e.id}`,e.component,this.components),W(e,this.experiences)}getStateSnapshot(){return ce(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){I.logger("warn",`Experience with id '${e}' not found.`);return}M(this,r)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(r=>{if(Array.isArray(r)){r.forEach(c=>{this.registerPlugin(c)});return}const n=typeof r=="function"?r():r;if(Array.isArray(n)){n.forEach(c=>this.registerPlugin(c));return}this.registerPlugin(n)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const c=typeof n=="function"?n():n;this.registerFeature(r,c)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,c]=r.split(":");if(!n||!c)return;let u=c;u==="true"&&(u=!0),u==="false"&&(u=!1),this.registerFeature(n,{key:`${u}`,name:n,decide:()=>u,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}y(D,"logger",I.logger);function T(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Te(t){return t.some(e=>e.condition||T(e))}async function Ue(t,e){return e.length===0||!Te(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await F.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!T(n))return n;const s=(await Promise.all(n.options.map(async l=>l.condition?await F.evaluateRuleLogic(t,l.condition)?l:null:l))).filter(l=>l!==null);return s.length===n.options.length?n:s.length===0?null:{...n,options:s}}))).filter(n=>n!==null)}const Ve=t=>{const e=new D(t);return k.bindClient(e),e};exports.evaluateRuleLogic=F.evaluateRuleLogic;exports.isPickedRoot=F.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=Ve;exports.getStepFields=Ue;
|
|
1
|
+
"use strict";var U=Object.defineProperty;var V=(t,e,r)=>e in t?U(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"),h=require("@withease/factories"),F=require("../experience-instance-B2l_MG7I.cjs"),I=require("../logger-BsmHUUw1.cjs"),w=require("../storage-DuRlyFaY.cjs"),N=require("../id-BKIWbSTy.cjs"),z=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),L=f.createDomain("experience"),_=h.createFactory(({client:t,experience:e})=>{const r=L.store(e),n=f.createApi(r,{merge(l,S){return{...l,...S.experience}}}),c=r.map(l=>({name:l.name,decisionLogic:l.decide,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),u=t.components.listStore.map(l=>l.find(S=>S.name===`experience:${e.id}`)||l.find(S=>S.name==="experience"),{skipVoid:!1}),s=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),o=e.actions??[];return{id:e.id,configStore:c,treeStore:s,componentStore:u,actions:o,merge:n.merge}});function q(t){return h.invoke(_,t)}const K=h.createFactory(({client:t})=>{const e=L.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.id]:o}}});function n(s){const o=e.getState()[s.id];if(o){o.merge({experience:s,strategy:"override"});return}const l=q({client:t,experience:s});r.register(l)}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getById:u,listStore:c}});function H(t){return h.invoke(K,t)}const W=(t,e)=>{e.register(t)},M=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),n=F.getTargetElements(r,e.id);n.forEach(({elements:u})=>u.forEach(s=>F.tagTargetElement(s,e.id))),F.createAppHosts(n,e.id).forEach(u=>{t.experienceInstances.spawn(e,u)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await G(t,e)&&M(t,e)}))},G=async(t,e)=>{const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return F.getTargetElements(n,e.id).length<1||n.length===0?!1:r&&F.isRulesLogic(r)?await F.evaluateRuleLogic(t,r)===!0:!0},Y=(t,e,r)=>{const n=e.name,c=e.setup(t);if(c){const u=r[n]??{};r[n]=Object.freeze({...u,...c})}},J=f.createDomain("component"),Q=h.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function X(t){return h.invoke(Q,t)}const Z=h.createFactory(({client:t})=>{const e=J.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Component '${s}' already registered. Registering again will override the previous registration.`);const S=X({client:t,name:s,component:o});r.register(S)}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function ee(t){return h.invoke(Z,t)}const $=(t,e,r)=>{r.register(t,e)},te=f.createDomain("framework"),re=h.createFactory(({client:t})=>{const e=te.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:o.framework}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Framework '${s}' already registered. Registering again will override the previous registration.`),r.register({name:s,framework:o})}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function se(t){return h.invoke(re,t)}const ne=(t,e)=>{e.register(t.name,t)},oe=6e3,j=w.createStorageKey("last_ping","global"),ie=t=>`${t}/api/v1/ping`,ae=async t=>{try{const e=Date.now(),r=localStorage.getItem(j);if(r&&e-parseInt(r)<oe)return!0;const n=ie(t.apiUrl),c={projectId:t.projectId,path:window.location.pathname},u=JSON.stringify(c),s={"Content-Type":"application/json"},o=document.getElementById("picked_script"),l=o==null?void 0:o.dataset.verceltoken;l&&(s["x-vercel-protection-bypass"]=l);const b=(await fetch(n,{method:"POST",headers:s,body:u})).ok;return b&&localStorage.setItem(j,e.toString()),b}catch(e){return I.logger("error",e),!1}};function ce(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 ue=f.createDomain("predicate"),le=h.createFactory(({client:t})=>{const e=ue.store({}),r=f.createApi(e,{register(s,o){return{...s,[o.name]:{name:o.name,predicate:o.predicate}}}});function n(s,o){e.getState()[s]&&I.logger("warn",`Predicate '${s}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:s,predicate:o}))}const c=e.map(s=>Object.values(s));function u(s){return e.map(o=>o[s],{skipVoid:!1})}return{register:n,getByName:u,listStore:c}});function pe(t){return h.invoke(le,t)}const ge=(t,e,r)=>{r.register(t,e)},C=f.createDomain("feature"),de=h.createFactory(({client:t})=>{const e=C.store({}),r=C.store([]),n=f.createApi(e,{register(p,a){return{...p,[a.id]:a.feature}}});function c(p,a){e.getState()[p]&&I.logger("warn",`Feature '${p}' already registered. Registering again will override the previous registration.`);const d={id:p,feature:{...a,id:p}};n.register(Object.freeze({id:p,feature:d}))}const u=f.createEffect(async({id:p,key:a,storage:i="local"})=>{const d=w.createStorageKey(`feature:${p}:${a}`,"global"),g=(i==="session"?w.sessionStore:w.localStore).get(d).boolean();return g===null?null:{id:p,key:a,bucket:g}}),s=f.createEffect(p=>{if(!p)return null;const a=w.createStorageKey(`feature:${p.id}:${p.key}`,"global");(p.storage==="session"?w.sessionStore:w.localStore).set(a,p.bucket)}),o=new Map,l=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:p,resolvedFeaturesStore:a},{id:i,decide:d,key:m})=>{const g=a.find(A=>A.id===i);if(g)return g;const v=p[i];if(!v)throw new Error(`Feature with id '${i}' not found`);const x=o.get(`${i}:${m}`);if(x!==void 0){const A=await x;return{id:v.id,bucket:A,key:m,storage:v.feature.storage}}const P=d();o.set(`${i}:${m}`,P);const E=await P;return{id:v.id,bucket:E,key:m,storage:v.feature.storage}}});f.sample({clock:n.register,fn:p=>{const{id:a,feature:i}=p;return{id:a,key:i.feature.key,storage:i.feature.storage}},target:u}),f.sample({source:e,clock:l.doneData,fn:(p,a)=>{var v;const{id:i,bucket:d,storage:m}=a,g=(v=p[i])==null?void 0:v.feature.key;return g?{key:g,id:i,bucket:d,storage:m}:null},target:s});const S=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:p,resolvedFeaturesStore:a})=>Object.values(p).map(i=>{const d=a.find(m=>m.id===i.id);return d?{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:()=>({id:i.id,bucket:d.bucket}),isResolved:!0}:{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:async()=>await l(i.feature),isResolved:!1}}));f.sample({clock:l.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:p},{id:a})=>!p.some(i=>i.id===a),fn:(p,a)=>a,target:t.eventBus.prepend(p=>({type:"feature_decide",feature:p}))}),f.sample({clock:[u.doneData,l.doneData],source:r,fn:(p,a)=>!a||p.some(i=>i.id===a.id)?p:[...p,a],target:r});function b(p){return e.map(a=>a[p],{skipVoid:!1})}return{register:c,getByName:b,listStore:S}});function fe(t){return h.invoke(de,t)}const me=(t,e,r)=>{r.register(t,e)},R=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 ye=h.createFactory(()=>{const t=R.store({entries:[]}),e=R.event(),r=R.event(),n=R.event(),c=R.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(c,(s,o)=>o);function u(s,o){const l={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=s.length-1;S>=0;S--){const b=s[S],p=b==null?void 0:b.node;if(!(!p||!F.isStepNode(p))&&!(o&&(b==null?void 0:b.experienceId)!==o))if(l.lastStepIndex===-1)l.lastStepIndex=S;else{l.secondLastStepIndex=S;break}}return l}return t.on(n,(s,o)=>{const{secondLastStepIndex:l}=u(s.entries,o.experienceId),S=l!==-1?s.entries.slice(0,l+1):s.entries;return{...s,entries:S}}),{push:e,replace:r,back:n,restore:c,entriesStore:t.map(s=>s.entries)}});function he(){return h.invoke(ye)}const Se=()=>f.createEvent(),ve=f.createDomain("field"),ke=h.createFactory(()=>{const t=ve.store({}),e=f.createApi(t,{register(s,o){return{...s,[o.field.id]:o.field}}});function r(s){e.register({field:s})}const n=t.map(s=>Object.values(s));function c(s){return t.map(o=>o[s]||null)}function u(s){return t.map(o=>Object.values(o).find(l=>l.name===s)||null)}return{register:r,getById:c,listStore:n,getByName:u}});function we(){return h.invoke(ke)}const Fe=(t,e)=>{e.register(t)},be=f.createDomain("action"),Ie=h.createFactory(()=>{const t=be.store({}),e=f.createApi(t,{register(u,s){return{...u,[s.name]:{name:s.name,action:s.action}}}});function r(u,s){e.register({name:u,action:s})}const n=t.map(u=>Object.values(u));function c(u){return t.map(s=>s[u],{skipVoid:!1})}return{register:r,getByName:c,listStore:n}});function xe(){return h.invoke(Ie)}const Ee=(t,e,r)=>{r.register(t,e)},Re=f.createDomain("response"),Pe=h.createFactory(({client:t})=>{const e=Re.store({}),r=f.createEvent(),n=f.createEvent(),c=f.createApi(e,{register(a,i){return{...a,[i.fieldId]:i.response}},registerBatch(a,i){return{...a,...i}},clear(a,i){const{[i]:d,...m}=a;return m},clearAll(){return{}}});function u(a,i){c.register({fieldId:a,response:i})}async function s(a){const i=[];return await Promise.allSettled(Object.entries(a).map(async([d,m])=>{let g=m;const v=t.fields.getById(d).getState();if(!v){i.push({fieldId:d,userMessage:`Field '${d}' not found`,systemMessage:`No field with ID '${d}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:g});return}if(v.multiple&&(typeof g=="string"||typeof g=="number"||typeof g=="boolean")&&(g=[g]),v.validation&&!z.isEmpty(v.validation)){const x=await F.evaluateRuleLogic(t,v.validation,{$input:g});if(typeof x=="string"){i.push({fieldId:d,userMessage:x,systemMessage:`Field validation resulted in an error: ${x}.`,value:g});return}if(x===!1){i.push({fieldId:d,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:g});return}}if(v.required&&(typeof g>"u"||g===null||g===""||Array.isArray(g)&&!g.length)){i.push({fieldId:d,userMessage:"This field is required",systemMessage:"Field is required.",value:g});return}if(!v.multiple&&Array.isArray(g)&&g.length>1){i.push({fieldId:d,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:g});return}if(v.options){const x=v.options.map(E=>E.value),P=Array.isArray(g)?g:[g];Array.isArray(g)&&(P.every(E=>x.includes(E))||i.push({fieldId:d,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${x.join(", ")}`,value:g}))}})),{responsesToCommit:a,validationErrors:i}}async function o(a){const{responsesToCommit:i,validationErrors:d}=await s(a);return d.length?{errors:d}:(c.registerBatch(i),{errors:[]})}const l=e.map(a=>a),S=e.map(a=>Object.keys(a).map(d=>({fieldId:d,value:a[d]})));function b(a){const i=t.fields.getById(a),d=e.map(m=>m[a]||null);return f.combine({f:i,r:d},({f:m,r:g})=>g||(m!=null&&m.defaultValue?m.defaultValue:null))}function p(a){const i=t.fields.getByName(a);return f.combine({f:i,s:e},({f:d,s:m})=>{const g=d&&m[d.id]||null;return g||(d!=null&&d.defaultValue?d.defaultValue:null)})}return f.sample({clock:r,target:c.clearAll}),f.sample({clock:n,target:c.clear}),{register:u,clearAll:r,clear:n,commit:o,getResponsesToCommit:s,listStore:S,getAllStore:l,getByFieldId:b,getByFieldName:p}});function Ae(t){return h.invoke(Pe,t)}const De=()=>"0.0.12-next.13";function Be(){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 $e(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[c]of t.entries())c.startsWith("picked-")&&r.add(c);for(const c of r){const u=c.replace("picked-","");e[u]=t.getAll(c)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const c=w.sessionStore.get(n);if(c)return c.json()||{}}return e}function je(){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 Ce=()=>({id:je()}),Oe=w.createStorageKey("session","global"),Le=()=>{if(!k.supportsLocalStorage())return null;const t=w.localStore.get(Oe);let e=t.isSet()?t.json():null;return e||(e=Ce(),t.set(e)),e},Me=()=>Le();class D{constructor(e){y(this,"options");y(this,"isReady",!1);y(this,"project");y(this,"plugins",{});y(this,"eventBus",Se());y(this,"organizationId");y(this,"projectId");y(this,"apiUrl");y(this,"session");y(this,"searchParams",$e());y(this,"history",he());y(this,"components",ee({client:this}));y(this,"experienceInstances",F.createExperienceInstanceIndex({client:this}));y(this,"experiences",H({client:this}));y(this,"frameworks",se({client:this}));y(this,"predicates",pe({client:this}));y(this,"features",fe({client:this}));y(this,"responses",Ae({client:this}));y(this,"fields",we());y(this,"actions",xe());I.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Be(),this.session=Me(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.eventBus({type:"initialized",version:De()}),I.logger("info","Picked client initialized.")}start(){ae(this),(async()=>{k.supportsDocument()&&(document.body&&B(this),await F.domInteractive(),await B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session}))})()}registerFramework(e){ne(e,this.frameworks)}registerComponent(e,r){$(e,r,this.components)}registerPlugin(e){Y(this,e,this.plugins)}registerFeature(e,r){me(e,r,this.features)}registerPredicate(e,r){ge(e,r,this.predicates)}registerField(e){Fe(e,this.fields)}registerAction(e,r){Ee(e,r,this.actions)}registerExperience(e){e.component&&$(`experience:${e.id}`,e.component,this.components),W(e,this.experiences)}getStateSnapshot(){return ce(this)}async launchExperienceById(e){const r=this.experiences.getById(e).getState();if(!r){I.logger("warn",`Experience with id '${e}' not found.`);return}M(this,r)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(r=>{if(Array.isArray(r)){r.forEach(c=>{this.registerPlugin(c)});return}const n=typeof r=="function"?r():r;if(Array.isArray(n)){n.forEach(c=>this.registerPlugin(c));return}this.registerPlugin(n)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const c=typeof n=="function"?n():n;this.registerFeature(r,c)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,c]=r.split(":");if(!n||!c)return;let u=c;u==="true"&&(u=!0),u==="false"&&(u=!1),this.registerFeature(n,{key:`${u}`,name:n,decide:()=>u,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){I.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}getPluginConfig(e){return this.plugins[e]??{}}}y(D,"logger",I.logger);function T(t){var e;return((e=t.options)==null?void 0:e.some(r=>"condition"in r))??!1}function Te(t){return t.some(e=>e.condition||T(e))}async function Ue(t,e){return e.length===0||!Te(e)?e:(await Promise.all(e.map(async n=>{if(!(n.condition?await F.evaluateRuleLogic(t,n.condition):!0))return null;if(!n.options||!T(n))return n;const s=(await Promise.all(n.options.map(async l=>l.condition?await F.evaluateRuleLogic(t,l.condition)?l:null:l))).filter(l=>l!==null);return s.length===n.options.length?n:s.length===0?null:{...n,options:s}}))).filter(n=>n!==null)}const Ve=t=>{const e=new D(t);return k.bindClient(e),e};exports.evaluateRuleLogic=F.evaluateRuleLogic;exports.isPickedRoot=F.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=Ve;exports.getStepFields=Ue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../../supports-YvpQZxbh.cjs"),o={homepage:/^\/$/,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(?:\/|$)/},c=(e,a)=>a?!!e.exec(a.pathname):!1,i=(e,a)=>{if(a){const t=e.exec(a.pathname);if(t)return t[1]}},n=e=>{var a,t,s,p;switch(e){case"product":return((t=(a=globalThis.window.pickedConfig)==null?void 0:a.product)==null?void 0:t.handle)??!1;case"collection":return((p=(s=globalThis.window.pickedConfig)==null?void 0:s.collection)==null?void 0:p.handle)??!1;default:return!1}},r={"is-page":({location:e})=>c(o.page,e),"get-page-handle":({location:e})=>i(o.page,e),"is-product-page":()=>!!n("product"),"get-product-handle":()=>n("product"),"is-collection-page":()=>!!n("collection"),"get-collection-handle":()=>n("collection"),"is-blog-page":({location:e})=>c(o.blog,e),"get-blog-handle":({location:e})=>i(o.blog,e),"is-article-page":({location:e})=>c(o.article,e),"get-article-handle":({location:e})=>i(o.article,e),"is-app-proxy-page":({location:e})=>c(o.appProxy,e),"get-app-proxy-handle":({location:e})=>i(o.appProxy,e),"is-account-page":({location:e})=>c(o.accountWildcard,e),"is-login-page":({location:e})=>c(o.accountLogin,e),"is-register-page":({location:e})=>c(o.accountRegister,e),"is-cart-page":({location:e})=>c(o.cart,e),"is-checkout-page":({location:e})=>c(o.checkout,e),"is-homepage":({location:e})=>c(o.homepage,e)};function g(e){var a,t;return typeof((t=(a=e.Shopify)==null?void 0:a.analytics)==null?void 0:t.publish)=="function"}const u=()=>({name:"shopify",setup:e=>{Object.entries(r).forEach(([a,t])=>{e.registerPredicate(`shopify-${a}`,t)}),l.supportsWindow()&&e.eventBus.watch(a=>{g(window)&&a.type==="session"&&window.Shopify.analytics.publish("picked:session",{id:a.id})})}});exports.shopifyPlugin=u;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
const
|
|
1
|
+
import { a as l } from "../../../supports-BjhuLJ8z.js";
|
|
2
|
+
const o = {
|
|
3
3
|
homepage: /^\/$/,
|
|
4
|
-
productPage: /(?:^|\/)products\/(?<productHandle>[^/]+)\/?$/,
|
|
5
|
-
collection: /^\/collections\/[^/]+\/?$/,
|
|
6
4
|
page: /(?:^|\/)pages\/[^/]+$/,
|
|
7
5
|
blog: /(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,
|
|
8
6
|
article: /^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,
|
|
@@ -12,58 +10,68 @@ const a = {
|
|
|
12
10
|
accountWildcard: /^\/account\/.+/,
|
|
13
11
|
accountLogin: /^\/account\/login(?:\/|$)/,
|
|
14
12
|
accountRegister: /^\/account\/register(?:\/|$)/
|
|
15
|
-
},
|
|
16
|
-
if (
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
return
|
|
13
|
+
}, c = (e, a) => a ? !!e.exec(a.pathname) : !1, i = (e, a) => {
|
|
14
|
+
if (a) {
|
|
15
|
+
const t = e.exec(a.pathname);
|
|
16
|
+
if (t)
|
|
17
|
+
return t[1];
|
|
20
18
|
}
|
|
21
|
-
},
|
|
19
|
+
}, n = (e) => {
|
|
20
|
+
var a, t, p, s;
|
|
21
|
+
switch (e) {
|
|
22
|
+
case "product":
|
|
23
|
+
return ((t = (a = globalThis.window.pickedConfig) == null ? void 0 : a.product) == null ? void 0 : t.handle) ?? !1;
|
|
24
|
+
case "collection":
|
|
25
|
+
return ((s = (p = globalThis.window.pickedConfig) == null ? void 0 : p.collection) == null ? void 0 : s.handle) ?? !1;
|
|
26
|
+
default:
|
|
27
|
+
return !1;
|
|
28
|
+
}
|
|
29
|
+
}, r = {
|
|
22
30
|
// Pages
|
|
23
|
-
"is-page": ({ location: e }) =>
|
|
24
|
-
"get-page-handle": ({ location: e }) => i(
|
|
31
|
+
"is-page": ({ location: e }) => c(o.page, e),
|
|
32
|
+
"get-page-handle": ({ location: e }) => i(o.page, e),
|
|
25
33
|
// Products
|
|
26
|
-
"is-product-page": (
|
|
27
|
-
"get-product-handle": (
|
|
34
|
+
"is-product-page": () => !!n("product"),
|
|
35
|
+
"get-product-handle": () => n("product"),
|
|
28
36
|
// Collections
|
|
29
|
-
"is-collection-page": (
|
|
30
|
-
"get-collection-handle": (
|
|
37
|
+
"is-collection-page": () => !!n("collection"),
|
|
38
|
+
"get-collection-handle": () => n("collection"),
|
|
31
39
|
// Blogs
|
|
32
|
-
"is-blog-page": ({ location: e }) =>
|
|
33
|
-
"get-blog-handle": ({ location: e }) => i(
|
|
40
|
+
"is-blog-page": ({ location: e }) => c(o.blog, e),
|
|
41
|
+
"get-blog-handle": ({ location: e }) => i(o.blog, e),
|
|
34
42
|
// Blog Articles
|
|
35
|
-
"is-article-page": ({ location: e }) =>
|
|
36
|
-
"get-article-handle": ({ location: e }) => i(
|
|
43
|
+
"is-article-page": ({ location: e }) => c(o.article, e),
|
|
44
|
+
"get-article-handle": ({ location: e }) => i(o.article, e),
|
|
37
45
|
// Apps
|
|
38
|
-
"is-app-proxy-page": ({ location: e }) =>
|
|
39
|
-
"get-app-proxy-handle": ({ location: e }) => i(
|
|
46
|
+
"is-app-proxy-page": ({ location: e }) => c(o.appProxy, e),
|
|
47
|
+
"get-app-proxy-handle": ({ location: e }) => i(o.appProxy, e),
|
|
40
48
|
// Account
|
|
41
|
-
"is-account-page": ({ location: e }) =>
|
|
42
|
-
"is-login-page": ({ location: e }) =>
|
|
43
|
-
"is-register-page": ({ location: e }) =>
|
|
49
|
+
"is-account-page": ({ location: e }) => c(o.accountWildcard, e),
|
|
50
|
+
"is-login-page": ({ location: e }) => c(o.accountLogin, e),
|
|
51
|
+
"is-register-page": ({ location: e }) => c(o.accountRegister, e),
|
|
44
52
|
// Cart
|
|
45
|
-
"is-cart-page": ({ location: e }) =>
|
|
53
|
+
"is-cart-page": ({ location: e }) => c(o.cart, e),
|
|
46
54
|
// Checkout
|
|
47
|
-
"is-checkout-page": ({ location: e }) =>
|
|
55
|
+
"is-checkout-page": ({ location: e }) => c(o.checkout, e),
|
|
48
56
|
// Homepage
|
|
49
|
-
"is-homepage": ({ location: e }) =>
|
|
57
|
+
"is-homepage": ({ location: e }) => c(o.homepage, e)
|
|
50
58
|
};
|
|
51
|
-
function
|
|
52
|
-
var
|
|
53
|
-
return typeof ((
|
|
59
|
+
function g(e) {
|
|
60
|
+
var a, t;
|
|
61
|
+
return typeof ((t = (a = e.Shopify) == null ? void 0 : a.analytics) == null ? void 0 : t.publish) == "function";
|
|
54
62
|
}
|
|
55
|
-
const
|
|
63
|
+
const d = () => ({
|
|
56
64
|
name: "shopify",
|
|
57
65
|
setup: (e) => {
|
|
58
|
-
Object.entries(
|
|
59
|
-
e.registerPredicate(`shopify-${
|
|
60
|
-
}),
|
|
61
|
-
|
|
62
|
-
id:
|
|
66
|
+
Object.entries(r).forEach(([a, t]) => {
|
|
67
|
+
e.registerPredicate(`shopify-${a}`, t);
|
|
68
|
+
}), l() && e.eventBus.watch((a) => {
|
|
69
|
+
g(window) && a.type === "session" && window.Shopify.analytics.publish("picked:session", {
|
|
70
|
+
id: a.id
|
|
63
71
|
});
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
});
|
|
67
75
|
export {
|
|
68
|
-
|
|
76
|
+
d as shopifyPlugin
|
|
69
77
|
};
|
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import { StateSnapshot } from '../../utils/state-snaphot';
|
|
2
2
|
export declare const evaluatePathname: (regexPattern: RegExp, location?: StateSnapshot["location"]) => boolean;
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Evaluate handle from path using regex pattern
|
|
5
|
+
*
|
|
6
|
+
* @param regexPattern Regex pattern to extract handle
|
|
7
|
+
* @param location Location object containing pathname
|
|
8
|
+
* @returns handle string or undefined
|
|
9
|
+
*/
|
|
10
|
+
export declare const evaluateHandleByPath: (regexPattern: RegExp, location?: StateSnapshot["location"]) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Evaluate handle from pickedConfig based on type
|
|
13
|
+
*
|
|
14
|
+
* @param type page type: 'product' | 'collection'
|
|
15
|
+
* @returns handle string or undefined
|
|
16
|
+
*/
|
|
17
|
+
export declare const evaluateHandleByType: (type: "product" | "collection") => string | false;
|
|
4
18
|
interface PredicateArgs {
|
|
5
19
|
location?: StateSnapshot['location'];
|
|
6
20
|
}
|
|
7
21
|
export declare const shopifyPredicates: {
|
|
8
22
|
'is-page': ({ location }: PredicateArgs) => boolean;
|
|
9
23
|
'get-page-handle': ({ location }: PredicateArgs) => string | undefined;
|
|
10
|
-
'is-product-page': (
|
|
11
|
-
'get-product-handle': (
|
|
12
|
-
'is-collection-page': (
|
|
13
|
-
'get-collection-handle': (
|
|
24
|
+
'is-product-page': () => boolean;
|
|
25
|
+
'get-product-handle': () => string | false;
|
|
26
|
+
'is-collection-page': () => boolean;
|
|
27
|
+
'get-collection-handle': () => string | false;
|
|
14
28
|
'is-blog-page': ({ location }: PredicateArgs) => boolean;
|
|
15
29
|
'get-blog-handle': ({ location }: PredicateArgs) => string | undefined;
|
|
16
30
|
'is-article-page': ({ location }: PredicateArgs) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shopify.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/shopify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"shopify.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/shopify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAkB9D,eAAO,MAAM,gBAAgB,GAC3B,cAAc,MAAM,EACpB,WAAW,aAAa,CAAC,UAAU,CAAC,KACnC,OAMF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,EACpB,WAAW,aAAa,CAAC,UAAU,CAAC,uBAQrC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,SAAS,GAAG,YAAY,mBASlE,CAAA;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CACrC;AAED,eAAO,MAAM,iBAAiB;8BAEF,aAAa;sCACL,aAAa;;;;;mCAQhB,aAAa;sCACV,aAAa;sCAEb,aAAa;yCACV,aAAa;wCAGd,aAAa;2CACV,aAAa;sCAGlB,aAAa;oCAEf,aAAa;uCACV,aAAa;mCAGjB,aAAa;uCAET,aAAa;kCAElB,aAAa;CAC5C,CAAA"}
|
|
@@ -1,6 +1,61 @@
|
|
|
1
|
+
import { CreateClientOptions } from '../../index';
|
|
1
2
|
interface EventPayload {
|
|
2
3
|
[key: string]: string | number | boolean | null | undefined | EventPayload | Array<string | number | boolean | null | undefined | EventPayload>;
|
|
3
4
|
}
|
|
5
|
+
export interface PickedConfigExperiment {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
version: number;
|
|
10
|
+
weight: number;
|
|
11
|
+
}
|
|
12
|
+
export type PickedConfigCollection = Partial<{
|
|
13
|
+
title: string;
|
|
14
|
+
id: number;
|
|
15
|
+
handle: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type PickedConfigProductVariant = Partial<{
|
|
18
|
+
available: boolean;
|
|
19
|
+
title: string;
|
|
20
|
+
id: number;
|
|
21
|
+
price: number;
|
|
22
|
+
inventory_quantity: number;
|
|
23
|
+
option1: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type PickedConfigProductCollection = Partial<{
|
|
26
|
+
id: number;
|
|
27
|
+
}>;
|
|
28
|
+
export type PickedConfigProduct = Partial<{
|
|
29
|
+
available: boolean;
|
|
30
|
+
collections: PickedConfigProductCollection[];
|
|
31
|
+
title: string;
|
|
32
|
+
id: number;
|
|
33
|
+
handle: string;
|
|
34
|
+
featured_image: string;
|
|
35
|
+
vendor: string;
|
|
36
|
+
url: string;
|
|
37
|
+
price: number;
|
|
38
|
+
tags: string[];
|
|
39
|
+
variants: PickedConfigProductVariant[];
|
|
40
|
+
metafields: Record<string, unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
export type PickedConfigCustomer = Partial<{
|
|
43
|
+
accepts_marketing: boolean;
|
|
44
|
+
email: string;
|
|
45
|
+
first_name: string | null;
|
|
46
|
+
has_account: boolean;
|
|
47
|
+
id: number;
|
|
48
|
+
last_name: string | null;
|
|
49
|
+
orders_count: number;
|
|
50
|
+
phone: string | null;
|
|
51
|
+
tax_exempt: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
export interface ShopifyPickedConfig {
|
|
54
|
+
customer?: PickedConfigCustomer;
|
|
55
|
+
product?: PickedConfigProduct;
|
|
56
|
+
collection?: PickedConfigCollection;
|
|
57
|
+
experiments: PickedConfigExperiment[];
|
|
58
|
+
}
|
|
4
59
|
declare global {
|
|
5
60
|
interface Window {
|
|
6
61
|
Shopify?: {
|
|
@@ -8,6 +63,7 @@ declare global {
|
|
|
8
63
|
publish?: (event: string, payload: EventPayload) => void;
|
|
9
64
|
};
|
|
10
65
|
};
|
|
66
|
+
pickedConfig?: Readonly<Partial<CreateClientOptions> & ShopifyPickedConfig>;
|
|
11
67
|
}
|
|
12
68
|
}
|
|
13
69
|
export declare function supportsShopifyAnalytics(w: Window): w is Window & {
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,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,MAAM,WAAW,sBAAsB;IAErC,OAAO,EAAE,OAAO,CAAA;IAGhB,EAAE,EAAE,MAAM,CAAA;IAGV,IAAI,EAAE,MAAM,CAAA;IAGZ,OAAO,EAAE,MAAM,CAAA;IAGf,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA;AAEF,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC;IAC/C,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,kBAAkB,EAAE,MAAM,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AAEF,MAAM,MAAM,6BAA6B,GAAG,OAAO,CAAC;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAC,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;IACxC,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,6BAA6B,EAAE,CAAA;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,EAAE,0BAA0B,EAAE,CAAA;IACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;IACzC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,WAAW,EAAE,sBAAsB,EAAE,CAAA;CACtC;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;QACD,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC,CAAA;KAC5E;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"}
|