PageSourceSearch

https://floky.com/assets/cartStore-D0OXpkQu.js

js floky.com collected 2026-10-07 16:55:29 UTC 13,657 bytes, 72 lines download raw bytes

1import{i as e}from"./jsx-runtime-DUAcabCT.js";import{t}from"./react-6OGjdfot.js";import{t as n}from"./createLucideIcon-CLQ5Hlf7.js";import{l as r,t as i}from"./shopify-CL_remKM.js";import{n as a,t as o}from"./tracker-DngANo7t.js";import{n as s}from"./klaviyo-BYp7jCvP.js";import{t as c}from"./meta-pixel-C5A1C181.js";import{r as l}from"./tiktok-pixel-B3vLCUiT.js";import{n as u,r as d}from"./google-ads-s4GoOmbn.js";var f=n(`shopping-bag`,[[`path`,{d:`M16 10a4 4 0 0 1-8 0`,key:`1ltviw`}],[`path`,{d:`M3.103 6.034h17.794`,key:`awc11p`}],[`path`,{d:`M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z`,key:`o988cm`}]]),p=e(t(),1),m=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},h=(e=>e?m(e):m),g=e=>e;function _(e,t=g){let n=p.useSyncExternalStore(e.subscribe,p.useCallback(()=>t(e.getState()),[e,t]),p.useCallback(()=>t(e.getInitialState()),[e,t]));return p.useDebugValue(n),n}var v=e=>{let t=h(e),n=e=>_(t,e);return Object.assign(n,t),n},y=(e=>e?v(e):v);function b(e,t){let n;try{n=e()}catch{return}return{getItem:e=>{let r=e=>e===null?null:JSON.parse(e,t?.reviver),i=n.getItem(e)??null;return i instanceof Promise?i.then(r):r(i)},setItem:(e,r)=>n.setItem(e,JSON.stringify(r,t?.replacer)),removeItem:e=>n.removeItem(e)}}var x=e=>t=>{try{let n=e(t);return n instanceof Promise?n:{then(e){return x(e)(n)},catch(e){return this}}}catch(e){return{then(e){return this},catch(t){return x(t)(e)}}}},S=(e,t)=>(n,r,i)=>{let a={storage:b(()=>window.localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...t},o=!1,s=0,c=new Set,l=new Set,u=a.storage;if(!u)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),n(...e)},r,i);let d=()=>{let e=a.partialize({...r()});return u.setItem(a.name,{state:e,version:a.version})},f=i.setState;i.setState=(e,t)=>(f(e,t),d());let p=e((...e)=>(n(...e),d()),r,i);i.getInitialState=()=>p;let m,h=()=>{if(!u)return;let e=++s;o=!1,c.forEach(e=>e(r()??p));let t=a.onRehydrateStorage?.call(a,r()??p)||void 0;return x(u.getItem.bind(u))(a.name).then(e=>{if(e)if(typeof e.version==`number`&&e.version!==a.version){if(a.migrate){let t=a.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`)}else return[!1,e.state];return[!1,void 0]}).then(t=>{if(e!==s)return;let[i,o]=t;if(m=a.merge(o,r()??p),n(m,!0),i)return d()}).then(()=>{e===s&&(t?.(r(),void 0),m=r(),o=!0,l.forEach(e=>e(m)))}).catch(n=>{e===s&&t?.(void 0,n)})};return i.persist={setOptions:e=>{a={...a,...e},e.storage&&(u=e.storage)},clearStorage:()=>{u?.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>h(),hasHydrated:()=>o,onHydrate:e=>(c.add(e),()=>{c.delete(e)}),onFinishHydration:e=>(l.add(e),()=>{l.delete(e)})},a.skipHydration||h(),m||p},C=`
2  id
3  totalQuantity
4  checkoutUrl
5  note
6  discountCodes { code applicable }
7  cost {
8    subtotalAmount { amount currencyCode }
9    totalAmount { amount currencyCode }
10  }
11`,w=`
12  query cart($id: ID!) {
13    cart(id: $id) {
14      ${C}
15    }
16  }
17`,T=`
18  mutation cartCreate($input: CartInput!) {
19    cartCreate(input: $input) {
20      cart {
21        ${C}
22        lines(first: 100) { edges { node { id merchandise { ... on ProductVariant { id } } } } }
23      }
24      userErrors { field message }
25    }
26  }
27`,E=`
28  mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
29    cartLinesAdd(cartId: $cartId, lines: $lines) {
30      cart {
31        ${C}
32        lines(first: 100) { edges { node { id merchandise { ... on ProductVariant { id } } } } }
33      }
34      userErrors { field message }
35    }
36  }
37`,D=`
38  mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
39    cartLinesUpdate(cartId: $cartId, lines: $lines) {
40      cart { ${C} }
41      userErrors { field message }
42    }
43  }
44`,O=`
45  mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {
46    cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
47      cart { ${C} }
48      userErrors { field message }
49    }
50  }
51`,k=`
52  mutation cartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]) {
53    cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
54      cart { ${C} }
55      userErrors { field message }
56    }
57  }
58`,A=`
59  mutation cartNoteUpdate($cartId: ID!, $note: String!) {
60    cartNoteUpdate(cartId: $cartId, note: $note) {
61      cart { ${C} }
62      userErrors { field message }
63    }
64  }
65`;function j(e){try{let t=new URL(e);return t.hostname.endsWith(`.myshopify.com`)||(t.hostname=i),t.searchParams.set(`channel`,`online_store`),t.toString()}catch{return e}}function M(e){return e.some(e=>e.message.toLowerCase().includes(`cart not found`)||e.message.toLowerCase().includes(`does not exist`))}function N(e){return e?{checkoutUrl:e.checkoutUrl?j(e.checkoutUrl):void 0,note:e.note??null,discountCodes:e.discountCodes??[],subtotal:e.cost?.subtotalAmount,total:e.cost?.totalAmount}:{}}var P=`
66  mutation cartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {
67    cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
68      cart { id }
69      userErrors { field message }
70    }
71  }
72`;function F(e){let t={_floky_sid:e.session_id,_floky_vid:e.visitor_id,_floky_utm_source:e.utm_source,_floky_utm_medium:e.utm_medium,_floky_utm_campaign:e.utm_campaign,_floky_referrer:e.referrer};return Object.entries(t).filter(([,e])=>!!e).map(([e,t])=>({key:e,value:String(t).slice(0,255)}))}async function I(e,t){if(t.length!==0)try{await r(P,{cartId:e,attributes:t})}catch(e){console.error(`cartAttributesUpdate error:`,e)}}async function L(e,t=[]){let n=await r(T,{input:{lines:[{quantity:e.quantity,merchandiseId:e.variantId}],...t.length>0?{attributes:t}:{}}}),i=n?.data?.cartCreate?.userErrors??[];if(i.length>0)return console.error(`cartCreate errors:`,i),null;let a=n?.data?.cartCreate?.cart;if(!a?.checkoutUrl)return null;let o=a.lines.edges[0]?.node?.id;return o?{cartId:a.id,lineId:o,...N(a)}:null}async function R(e,t){let n=await r(E,{cartId:e,lines:[{quantity:t.quantity,merchandiseId:t.variantId}]}),i=n?.data?.cartLinesAdd?.userErrors??[];if(M(i))return{success:!1,cartNotFound:!0};if(i.length>0)return console.error(`cartLinesAdd errors:`,i),{success:!1};let a=n?.data?.cartLinesAdd?.cart;return{success:!0,lineId:(a?.lines?.edges??[]).find(e=>e.node.merchandise.id===t.variantId)?.node?.id,...N(a)}}async function z(e,t,n){let i=await r(D,{cartId:e,lines:[{id:t,quantity:n}]}),a=i?.data?.cartLinesUpdate?.userErrors??[];return M(a)?{success:!1,cartNotFound:!0}:a.length>0?{success:!1}:{success:!0,...N(i?.data?.cartLinesUpdate?.cart)}}async function B(e,t){let n=await r(O,{cartId:e,lineIds:[t]}),i=n?.data?.cartLinesRemove?.userErrors??[];return M(i)?{success:!1,cartNotFound:!0}:i.length>0?{success:!1}:{success:!0,...N(n?.data?.cartLinesRemove?.cart)}}async function V(e,t){let n=await r(k,{cartId:e,discountCodes:t}),i=n?.data?.cartDiscountCodesUpdate?.userErrors??[];return M(i)?{success:!1,cartNotFound:!0}:i.length>0?{success:!1,error:i[0].message}:{success:!0,...N(n?.data?.cartDiscountCodesUpdate?.cart)}}async function H(e,t){let n=await r(A,{cartId:e,note:t}),i=n?.data?.cartNoteUpdate?.userErrors??[];return M(i)?{success:!1,cartNotFound:!0}:i.length>0?{success:!1}:{success:!0,...N(n?.data?.cartNoteUpdate?.cart)}}async function U(e){return r(w,{id:e})}function W(){if(typeof window>`u`)return null;let e=window;return e.textyess??e.TextYess??null}function G(e,t={}){try{let n=W();if(n?.track){n.track(e,t);return}if(typeof window<`u`){let n=window;n.__tyQueue=n.__tyQueue||[],n.__tyQueue.push([e,t]),window.dispatchEvent(new CustomEvent(`textyess:track`,{detail:{event:e,props:t}}))}}catch{}}function K(e){let t={};return e.checkoutUrl&&(t.checkoutUrl=e.checkoutUrl),e.note!==void 0&&(t.note=e.note??``),e.discountCodes&&(t.discountCodes=e.discountCodes),e.subtotal&&(t.subtotal=e.subtotal),e.total&&(t.total=e.total),t}var q=y()(S((e,t)=>({items:[],cartId:null,checkoutUrl:null,isLoading:!1,isSyncing:!1,isDrawerOpen:!1,note:``,discountCodes:[],subtotal:null,total:null,discountError:null,flags:[],openDrawer:()=>{let{items:n,isDrawerOpen:r}=t();r||a(`cart_opened`,{items:n.length,units:n.reduce((e,t)=>e+t.quantity,0),value:Number(n.reduce((e,t)=>e+parseFloat(t.price.amount)*t.quantity,0).toFixed(2)),currency:n[0]?.price.currencyCode??`EUR`,products:n.map(e=>e.product.node.handle)}),e({isDrawerOpen:!0})},closeDrawer:()=>e({isDrawerOpen:!1}),addItem:async n=>{let{items:r,cartId:i,clearCart:f}=t(),p=r.find(e=>e.variantId===n.variantId);a(`add_to_cart`,{variant_id:n.variantId,handle:n.product?.node?.handle,title:n.product?.node?.title,quantity:n.quantity,price:Number(n.price?.amount??0),currency:n.price?.currencyCode});let m={product_id:n.product?.node?.id,product_handle:n.product?.node?.handle,product_title:n.product?.node?.title,variant_id:n.variantId,variant_title:n.variantTitle,quantity:n.quantity,price:Number(n.price?.amount??0),currency:n.price?.currencyCode,url:typeof window<`u`?window.location.href:void 0};G(`added_to_cart`,m),s(`Added to Cart`,{ProductID:n.product?.node?.id,ProductName:n.product?.node?.title,Handle:n.product?.node?.handle,VariantID:n.variantId,VariantTitle:n.variantTitle,Quantity:n.quantity,ItemPrice:m.price,Currency:m.currency,URL:m.url}),c(`AddToCart`,{content_ids:[n.product?.node?.handle],content_name:n.product?.node?.title,content_type:`product`,value:m.price*n.quantity,currency:m.currency}),l(`AddToCart`,{contents:[{content_id:n.product?.node?.handle,content_name:n.product?.node?.title,content_type:`product`,quantity:n.quantity,price:m.price}],value:m.price*n.quantity,currency:m.currency??`EUR`}),u({handle:n.product?.node?.handle??``,title:n.product?.node?.title??``,variantId:n.variantId,variantTitle:n.variantTitle,price:m.price,currency:m.currency??`EUR`,quantity:n.quantity}),d(`_iHoCL-Ph9ocEMXMjJoC`,{value:m.price*n.quantity,currency:m.currency??`EUR`}),e({isLoading:!0});try{if(!i){let t=await L({variantId:n.variantId,quantity:n.quantity},F(o()));t&&e({cartId:t.cartId,items:[{...n,lineId:t.lineId}],...K(t)})}else if(p){let r=p.quantity+n.quantity;if(!p.lineId)return;let a=await z(i,p.lineId,r);if(a.success){let i=t().items;e({items:i.map(e=>e.variantId===n.variantId?{...e,quantity:r}:e),...K(a)})}else a.cartNotFound&&f()}else{let r=await R(i,{variantId:n.variantId,quantity:n.quantity});if(r.success){let i=t().items;e({items:[...i,{...n,lineId:r.lineId??null}
72],...K(r)})}else r.cartNotFound&&f()}}catch(e){console.error(`Failed to add item:`,e)}finally{e({isLoading:!1})}},updateQuantity:async(n,r)=>{if(r<=0){await t().removeItem(n);return}let{items:i,cartId:o,clearCart:s}=t(),c=i.find(e=>e.variantId===n);if(!(!c?.lineId||!o)){e({isLoading:!0});try{let i=await z(o,c.lineId,r);if(i.success){a(`cart_quantity_changed`,{handle:c.product.node.handle,title:c.product.node.title,variant_id:n,from:c.quantity,to:r,direction:r>c.quantity?`increase`:`decrease`});let o=t().items;e({items:o.map(e=>e.variantId===n?{...e,quantity:r}:e),...K(i)})}else i.cartNotFound&&s()}finally{e({isLoading:!1})}}},removeItem:async n=>{let{items:r,cartId:i,clearCart:o}=t(),s=r.find(e=>e.variantId===n);if(!(!s?.lineId||!i)){a(`remove_from_cart`,{variant_id:n,handle:s.product?.node?.handle,quantity:s.quantity}),e({isLoading:!0});try{let r=await B(i,s.lineId);if(r.success){let i=t().items.filter(e=>e.variantId!==n);i.length===0?o():e({items:i,...K(r)})}else r.cartNotFound&&o()}finally{e({isLoading:!1})}}},addCartFlag:async n=>{let r=t().flags??[];if(r.includes(n))return;let i=[...r,n];e({flags:i});for(let e=0;e<20&&!t().cartId;e++)await new Promise(e=>setTimeout(e,250));let a=t().cartId;a&&await I(a,[{key:`_floky_bundle`,value:i.join(`,`)}])},clearCart:()=>e({flags:[],items:[],cartId:null,checkoutUrl:null,note:``,discountCodes:[],subtotal:null,total:null,discountError:null}),getCheckoutUrl:()=>t().checkoutUrl,applyDiscount:async n=>{let{cartId:r,discountCodes:i}=t();if(!(!r||!n.trim())){e({isLoading:!0,discountError:null});try{let t=await V(r,Array.from(new Set([...i.map(e=>e.code),n.trim()])));t.success?(e(K(t)),(t.discountCodes??[]).find(e=>e.code.toLowerCase()===n.trim().toLowerCase())?.applicable||e({discountError:`Codice sconto non valido o non applicabile`})):t.error&&e({discountError:t.error})}finally{e({isLoading:!1})}}},removeDiscount:async n=>{let{cartId:r,discountCodes:i}=t();if(!r)return;let a=i.filter(e=>e.code.toLowerCase()!==n.toLowerCase()).map(e=>e.code);e({isLoading:!0,discountError:null});try{let t=await V(r,a);t.success&&e(K(t))}finally{e({isLoading:!1})}},setNote:async n=>{let{cartId:r}=t();if(e({note:n}),!r)return;let i=await H(r,n);i.success&&e(K(i))},syncCart:async()=>{let{cartId:n,isSyncing:r,clearCart:i}=t();if(!(!n||r)){e({isSyncing:!0});try{let t=await U(n);if(!t)return;let r=t?.data?.cart;if(!r||r.totalQuantity===0){i();return}e(K({checkoutUrl:r.checkoutUrl?j(r.checkoutUrl):void 0,note:r.note,discountCodes:r.discountCodes,subtotal:r.cost?.subtotalAmount,total:r.cost?.totalAmount}))}catch(e){console.error(`Failed to sync cart:`,e)}finally{e({isSyncing:!1})}}}}),{name:`floky-cart`,storage:b(()=>typeof window<`u`?localStorage:void 0),partialize:e=>({items:e.items,cartId:e.cartId,checkoutUrl:e.checkoutUrl,note:e.note,discountCodes:e.discountCodes,flags:e.flags})}));export{I as a,j as i,G as n,f as o,F as r,q as t};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.