@clicktap/state 0.13.7 → 0.13.8

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/index.mjs +3 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -48,4 +48,4 @@ spurious results.`)}}return!1};class dn{constructor(t,n="GraphQL request",s={lin
48
48
  `)),`
49
49
  }`)}function I(e,t,n=""){return t!=null&&t!==""?e+t+n:""}function Ee(e){return I(" ",e.replace(/\n/g,`
50
50
  `))}function Ct(e){var t;return(t=e==null?void 0:e.some(n=>n.includes(`
51
- `)))!==null&&t!==void 0?t:!1}const Dt=e=>{var s,r;let t;const n=e.definitions.filter(i=>i.kind==="OperationDefinition");return n.length===1&&(t=(r=(s=n[0])==null?void 0:s.name)==null?void 0:r.value),t},Le=e=>{if(typeof e=="string"){let n;try{const s=Er(e);n=Dt(s)}catch{}return{query:e,operationName:n}}const t=Dt(e);return{query:hn(e),operationName:t}};class ae extends Error{constructor(t,n){const s=`${ae.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(s),Object.setPrototypeOf(this,ae.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,ae)}static extractMessage(t){var n,s;return((s=(n=t.errors)==null?void 0:n[0])==null?void 0:s.message)??`GraphQL Error (Code: ${t.status})`}}var Nr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function kr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ze={exports:{}};(function(e,t){var n=typeof self<"u"?self:Nr,s=function(){function i(){this.fetch=!1,this.DOMException=n.DOMException}return i.prototype=n,new i}();(function(i){(function(o){var a={searchParams:"URLSearchParams"in i,iterable:"Symbol"in i&&"iterator"in Symbol,blob:"FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in i,arrayBuffer:"ArrayBuffer"in i};function c(d){return d&&DataView.prototype.isPrototypeOf(d)}if(a.arrayBuffer)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],f=ArrayBuffer.isView||function(d){return d&&u.indexOf(Object.prototype.toString.call(d))>-1};function l(d){if(typeof d!="string"&&(d=String(d)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(d))throw new TypeError("Invalid character in header field name");return d.toLowerCase()}function h(d){return typeof d!="string"&&(d=String(d)),d}function m(d){var g={next:function(){var _=d.shift();return{done:_===void 0,value:_}}};return a.iterable&&(g[Symbol.iterator]=function(){return g}),g}function y(d){this.map={},d instanceof y?d.forEach(function(g,_){this.append(_,g)},this):Array.isArray(d)?d.forEach(function(g){this.append(g[0],g[1])},this):d&&Object.getOwnPropertyNames(d).forEach(function(g){this.append(g,d[g])},this)}y.prototype.append=function(d,g){d=l(d),g=h(g);var _=this.map[d];this.map[d]=_?_+", "+g:g},y.prototype.delete=function(d){delete this.map[l(d)]},y.prototype.get=function(d){return d=l(d),this.has(d)?this.map[d]:null},y.prototype.has=function(d){return this.map.hasOwnProperty(l(d))},y.prototype.set=function(d,g){this.map[l(d)]=h(g)},y.prototype.forEach=function(d,g){for(var _ in this.map)this.map.hasOwnProperty(_)&&d.call(g,this.map[_],_,this)},y.prototype.keys=function(){var d=[];return this.forEach(function(g,_){d.push(_)}),m(d)},y.prototype.values=function(){var d=[];return this.forEach(function(g){d.push(g)}),m(d)},y.prototype.entries=function(){var d=[];return this.forEach(function(g,_){d.push([_,g])}),m(d)},a.iterable&&(y.prototype[Symbol.iterator]=y.prototype.entries);function v(d){if(d.bodyUsed)return Promise.reject(new TypeError("Already read"));d.bodyUsed=!0}function S(d){return new Promise(function(g,_){d.onload=function(){g(d.result)},d.onerror=function(){_(d.error)}})}function A(d){var g=new FileReader,_=S(g);return g.readAsArrayBuffer(d),_}function R(d){var g=new FileReader,_=S(g);return g.readAsText(d),_}function D(d){for(var g=new Uint8Array(d),_=new Array(g.length),N=0;N<g.length;N++)_[N]=String.fromCharCode(g[N]);return _.join("")}function L(d){if(d.slice)return d.slice(0);var g=new Uint8Array(d.byteLength);return g.set(new Uint8Array(d)),g.buffer}function J(){return this.bodyUsed=!1,this._initBody=function(d){this._bodyInit=d,d?typeof d=="string"?this._bodyText=d:a.blob&&Blob.prototype.isPrototypeOf(d)?this._bodyBlob=d:a.formData&&FormData.prototype.isPrototypeOf(d)?this._bodyFormData=d:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)?this._bodyText=d.toString():a.arrayBuffer&&a.blob&&c(d)?(this._bodyArrayBuffer=L(d.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(d)||f(d))?this._bodyArrayBuffer=L(d):this._bodyText=d=Object.prototype.toString.call(d):this._bodyText="",this.headers.get("content-type")||(typeof d=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?v(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(A)}),this.text=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return R(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(D(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a.formData&&(this.formData=function(){return this.text().then(yn)}),this.json=function(){return this.text().then(JSON.parse)},this}var le=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function he(d){var g=d.toUpperCase();return le.indexOf(g)>-1?g:d}function $(d,g){g=g||{};var _=g.body;if(d instanceof $){if(d.bodyUsed)throw new TypeError("Already read");this.url=d.url,this.credentials=d.credentials,g.headers||(this.headers=new y(d.headers)),this.method=d.method,this.mode=d.mode,this.signal=d.signal,!_&&d._bodyInit!=null&&(_=d._bodyInit,d.bodyUsed=!0)}else this.url=String(d);if(this.credentials=g.credentials||this.credentials||"same-origin",(g.headers||!this.headers)&&(this.headers=new y(g.headers)),this.method=he(g.method||this.method||"GET"),this.mode=g.mode||this.mode||null,this.signal=g.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&_)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(_)}$.prototype.clone=function(){return new $(this,{body:this._bodyInit})};function yn(d){var g=new FormData;return d.trim().split("&").forEach(function(_){if(_){var N=_.split("="),O=N.shift().replace(/\+/g," "),x=N.join("=").replace(/\+/g," ");g.append(decodeURIComponent(O),decodeURIComponent(x))}}),g}function mn(d){var g=new y,_=d.replace(/\r?\n[\t ]+/g," ");return _.split(/\r?\n/).forEach(function(N){var O=N.split(":"),x=O.shift().trim();if(x){var fe=O.join(":").trim();g.append(x,fe)}}),g}J.call($.prototype);function q(d,g){g||(g={}),this.type="default",this.status=g.status===void 0?200:g.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in g?g.statusText:"OK",this.headers=new y(g.headers),this.url=g.url||"",this._initBody(d)}J.call(q.prototype),q.prototype.clone=function(){return new q(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},q.error=function(){var d=new q(null,{status:0,statusText:""});return d.type="error",d};var gn=[301,302,303,307,308];q.redirect=function(d,g){if(gn.indexOf(g)===-1)throw new RangeError("Invalid status code");return new q(null,{status:g,headers:{location:d}})},o.DOMException=i.DOMException;try{new o.DOMException}catch{o.DOMException=function(g,_){this.message=g,this.name=_;var N=Error(g);this.stack=N.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function Oe(d,g){return new Promise(function(_,N){var O=new $(d,g);if(O.signal&&O.signal.aborted)return N(new o.DOMException("Aborted","AbortError"));var x=new XMLHttpRequest;function fe(){x.abort()}x.onload=function(){var re={status:x.status,statusText:x.statusText,headers:mn(x.getAllResponseHeaders()||"")};re.url="responseURL"in x?x.responseURL:re.headers.get("X-Request-URL");var Ne="response"in x?x.response:x.responseText;_(new q(Ne,re))},x.onerror=function(){N(new TypeError("Network request failed"))},x.ontimeout=function(){N(new TypeError("Network request failed"))},x.onabort=function(){N(new o.DOMException("Aborted","AbortError"))},x.open(O.method,O.url,!0),O.credentials==="include"?x.withCredentials=!0:O.credentials==="omit"&&(x.withCredentials=!1),"responseType"in x&&a.blob&&(x.responseType="blob"),O.headers.forEach(function(re,Ne){x.setRequestHeader(Ne,re)}),O.signal&&(O.signal.addEventListener("abort",fe),x.onreadystatechange=function(){x.readyState===4&&O.signal.removeEventListener("abort",fe)}),x.send(typeof O._bodyInit>"u"?null:O._bodyInit)})}return Oe.polyfill=!0,i.fetch||(i.fetch=Oe,i.Headers=y,i.Request=$,i.Response=q),o.Headers=y,o.Request=$,o.Response=q,o.fetch=Oe,Object.defineProperty(o,"__esModule",{value:!0}),o})({})})(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var r=s;t=r.fetch,t.default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t})(ze,ze.exports);var Se=ze.exports;const ve=kr(Se),Cr=En({__proto__:null,default:ve},[Se]),Q=e=>{let t={};return e&&(typeof Headers<"u"&&e instanceof Headers||Cr&&Se.Headers&&e instanceof Se.Headers?t=qs(e):Array.isArray(e)?e.forEach(([n,s])=>{n&&s!==void 0&&(t[n]=s)}):t=e),t},Rt=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),Dr=e=>{if(!Array.isArray(e.query)){const s=e,r=[`query=${encodeURIComponent(Rt(s.query))}`];return e.variables&&r.push(`variables=${encodeURIComponent(s.jsonSerializer.stringify(s.variables))}`),s.operationName&&r.push(`operationName=${encodeURIComponent(s.operationName)}`),r.join("&")}if(typeof e.variables<"u"&&!Array.isArray(e.variables))throw new Error("Cannot create query with given variable type, array expected");const t=e,n=e.query.reduce((s,r,i)=>(s.push({query:Rt(r),variables:t.variables?t.jsonSerializer.stringify(t.variables[i]):void 0}),s),[]);return`query=${encodeURIComponent(t.jsonSerializer.stringify(n))}`},Rr=e=>async t=>{const{url:n,query:s,variables:r,operationName:i,fetch:o,fetchOptions:a,middleware:c}=t,u={...t.headers};let f="",l;e==="POST"?(l=Lr(s,r,i,a.jsonSerializer),typeof l=="string"&&(u["Content-Type"]="application/json")):f=Dr({query:s,variables:r,operationName:i,jsonSerializer:a.jsonSerializer??at});const h={method:e,headers:u,body:l,...a};let m=n,y=h;if(c){const v=await Promise.resolve(c({...h,url:n,operationName:i,variables:r})),{url:S,...A}=v;m=S,y=A}return f&&(m=`${m}?${f}`),await o(m,y)};class fn{constructor(t,n={}){this.url=t,this.requestConfig=n,this.rawRequest=async(...s)=>{const[r,i,o]=s,a=Us(r,i,o),{headers:c,fetch:u=ve,method:f="POST",requestMiddleware:l,responseMiddleware:h,...m}=this.requestConfig,{url:y}=this;a.signal!==void 0&&(m.signal=a.signal);const{operationName:v}=Le(a.query);return Me({url:y,query:a.query,variables:a.variables,headers:{...Q(Pe(c)),...Q(a.requestHeaders)},operationName:v,fetch:u,method:f,fetchOptions:m,middleware:l}).then(S=>(h&&h(S),S)).catch(S=>{throw h&&h(S),S})}}async request(t,...n){const[s,r]=n,i=Fs(t,s,r),{headers:o,fetch:a=ve,method:c="POST",requestMiddleware:u,responseMiddleware:f,...l}=this.requestConfig,{url:h}=this;i.signal!==void 0&&(l.signal=i.signal);const{query:m,operationName:y}=Le(i.document);return Me({url:h,query:m,variables:i.variables,headers:{...Q(Pe(o)),...Q(i.requestHeaders)},operationName:y,fetch:a,method:c,fetchOptions:l,middleware:u}).then(v=>(f&&f(v),v.data)).catch(v=>{throw f&&f(v),v})}batchRequests(t,n){const s=Bs(t,n),{headers:r,...i}=this.requestConfig;s.signal!==void 0&&(i.signal=s.signal);const o=s.documents.map(({document:c})=>Le(c).query),a=s.documents.map(({variables:c})=>c);return Me({url:this.url,query:o,variables:a,headers:{...Q(Pe(r)),...Q(s.requestHeaders)},operationName:void 0,fetch:this.requestConfig.fetch??ve,method:this.requestConfig.method||"POST",fetchOptions:i,middleware:this.requestConfig.requestMiddleware}).then(c=>(this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c.data)).catch(c=>{throw this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c})}setHeaders(t){return this.requestConfig.headers=t,this}setHeader(t,n){const{headers:s}=this.requestConfig;return s?s[t]=n:this.requestConfig.headers={[t]:n},this}setEndpoint(t){return this.url=t,this}}const Me=async e=>{const{query:t,variables:n,fetchOptions:s}=e,r=Rr(Ps(e.method??"post")),i=Array.isArray(e.query),o=await r(e),a=await Mr(o,s.jsonSerializer??at),c=Array.isArray(a)?!a.some(({data:f})=>!f):!!a.data,u=Array.isArray(a)||!a.errors||Array.isArray(a.errors)&&!a.errors.length||s.errorPolicy==="all"||s.errorPolicy==="ignore";if(o.ok&&u&&c){const{errors:f,...l}=(Array.isArray(a),a),h=s.errorPolicy==="ignore"?l:a;return{...i?{data:h}:h,headers:o.headers,status:o.status}}else{const f=typeof a=="string"?{error:a}:a;throw new ae({...f,status:o.status,headers:o.headers},{query:t,variables:n})}};async function pn(e,t,...n){const s=js(e,t,...n);return new fn(s.url).request({...s})}const Lr=(e,t,n,s)=>{const r=s??at;if(!Array.isArray(e))return r.stringify({query:e,variables:t,operationName:n});if(typeof t<"u"&&!Array.isArray(t))throw new Error("Cannot create request body with given variable type, array expected");const i=e.reduce((o,a,c)=>(o.push({query:a,variables:t?t[c]:void 0}),o),[]);return r.stringify(i)},Mr=async(e,t)=>{let n;return e.headers.forEach((s,r)=>{r.toLowerCase()==="content-type"&&(n=s)}),n&&(n.toLowerCase().startsWith("application/json")||n.toLowerCase().startsWith("application/graphql+json")||n.toLowerCase().startsWith("application/graphql-response+json"))?t.parse(await e.text()):e.text()},Pe=e=>typeof e=="function"?e():e,Pr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");if(!e.document)throw new Error("No request document provided.");if(!e.requestHeaders)throw new Error("No request headers provided.");try{const n=await pn(e.endpoint,e.document,{items:e.items},e.requestHeaders);if(!((t=n.quoteAddItem)!=null&&t.quote))throw new Error("Could not add items to quote.");return{type:"ADD_ITEMS_SUCCESS",quote:n.quoteAddItem.quote}}catch{throw new Error("Request to add item(s) failed.")}}),qr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");try{const n=await pn(e.endpoint,"");if(!((t=n.quoteRemoveItem)!=null&&t.quote))throw new Error("Could not remove items from quote.");return{type:"REMOVE_ITEMS_SUCCESS",quote:n.quoteRemoveItem.quote}}catch{throw new Error("Request to remove item(s) failed.")}}),qe=typeof window>"u",Fr=Z(async({input:e})=>{var n,s,r,i;if(!e.endpoint)throw console.log("no endpoint"),new Error("No endpoint provided.");if(!e.endpointSsr)throw console.log("no endpoint ssr"),new Error("No SSR endpoint provided.");if(!e.locale)throw console.log("no locale"),new Error("No locale provided.");if(!e.document)throw console.log("no request document"),new Error("No request document provided.");if(!e.requestHeaders)throw console.log("no headers"),new Error("No request headers provided.");const t=new fn(qe?e.endpointSsr:e.endpoint,qe?{fetch,method:"POST"}:{credentials:"include",method:"POST",mode:"cors"});try{const{data:o,headers:a,status:c,errors:u,extensions:f}=await t.rawRequest(hn(e.document),{},qe?{...e.requestHeaders,Cookie:`quote_${e.locale}=${e.quoteId??""}`}:e.requestHeaders),l=o;if(!((n=l.refreshQuote)!=null&&n.quote))throw console.log("userError: ",(s=l.refreshQuote)==null?void 0:s.userErrors[0].code,(r=l.refreshQuote)==null?void 0:r.userErrors[0].field,(i=l.refreshQuote)==null?void 0:i.userErrors[0].message),new Error("Could not add items to quote.");return{type:"REFRESH_SUCCESS",quote:l.refreshQuote.quote}}catch(o){throw console.log("refresh error",o),new Error("Request to add item(s) failed.")}}),Ur=({context:e})=>typeof window>"u"&&e.quote.id!==""||typeof window<"u",Br=({context:e})=>!!e.quote.items&&e.quote.items.length>0,Je=Ae({types:{context:{},events:{},input:{}},actions:{addItems:C(Rs),removeItems:C(Ls),refresh:C(Ms)},actors:{addItems:Pr,removeItems:qr,refresh:Fr},guards:{canRefresh:Ur,hasItems:Br}}).createMachine({id:"quote",initial:"initializing",context:({input:e})=>{var t,n,s,r,i,o,a,c,u,f,l,h,m,y;return{quote:{id:"",locale:"",baseCurrency:"USD",currencyConversionRate:1,dateCreated:null,dateLastUpdated:null,currency:"USD",items:[],promotions:[],shippingAddresses:{available:[],selected:null},totals:{discount:0,tax:0,shipping:0,shippingTax:0,subtotal:0,grandTotal:0},appliedPriceRules:[],appliedPromotions:[],shippingMethods:[],paymentMethods:[],storeCredit:[],rewards:[],giftCards:[],...(t=e==null?void 0:e.initialContext)==null?void 0:t.quote},endpoints:{client:"",server:"",...(n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints},graphql:{refresh:{document:((i=(r=(s=e==null?void 0:e.initialContext)==null?void 0:s.graphql)==null?void 0:r.refresh)==null?void 0:i.document)??"",requestHeaders:((c=(a=(o=e==null?void 0:e.initialContext)==null?void 0:o.graphql)==null?void 0:a.refresh)==null?void 0:c.requestHeaders)??void 0},addItems:{document:((l=(f=(u=e==null?void 0:e.initialContext)==null?void 0:u.graphql)==null?void 0:f.addItems)==null?void 0:l.document)??"",requestHeaders:((y=(m=(h=e==null?void 0:e.initialContext)==null?void 0:h.graphql)==null?void 0:m.addItems)==null?void 0:y.requestHeaders)??void 0}},errors:[]}},states:{uninitialized:{on:{REFRESH:"refreshing"}},empty:{on:{ADD_ITEMS:"addingItems"}},active:{on:{ADD_ITEMS:"addingItems",REMOVE_ITEMS:"removingItems",REFRESH:"refreshing"}},initializing:{always:[{target:"refreshing",guard:"canRefresh"},{target:"uninitialized"}]},refreshing:{invoke:{input:({context:e})=>({endpoint:e.endpoints.client,endpointSsr:e.endpoints.server,quoteId:e.quote.id,locale:e.quote.locale,document:e.graphql.refresh.document,requestHeaders:e.graphql.refresh.requestHeaders}),src:"refresh",onDone:[{actions:["refresh"],guard:"hasItems",target:"active"},{actions:["refresh"],target:"empty"}],onError:{target:"empty"}}},addingItems:{invoke:{input:({context:e,event:t})=>{var n,s;return{endpoint:e.endpoints.client,items:t.type==="ADD_ITEMS"?t.items:[],document:(n=e.graphql.addItems)==null?void 0:n.document,requestHeaders:(s=e.graphql.addItems)==null?void 0:s.requestHeaders}},src:"addItems",onDone:[{actions:["addItems"],target:"active"}],onError:[{guard:"hasItems",target:"active"},{target:"empty"}]}},removingItems:{}}}),dt=P.createContext({}),jr=()=>{const e=P.useContext(dt),[t,n]=P.useState(()=>{var r;const s=e.getSnapshot();return{items:s.context.quote.items??[],itemsCount:((r=s.context.quote.items)==null?void 0:r.length)??0,isAddingItems:s.value==="addingItems",isRemovingItems:s.value==="removingItems",isUpdatingItems:s.value==="addingItems"||s.value==="removingItems"}});return P.useEffect(()=>{const s=e.subscribe(r=>{const i=r.context.quote.items??[];n({items:i,itemsCount:i.length,isAddingItems:r.matches("addingItems"),isRemovingItems:r.matches("removingItems"),isUpdatingItems:r.matches("addingItems")||r.matches("removingItems")})});return()=>{s.unsubscribe()}},[e]),{quoteActor:e,isAddingItems:t.isAddingItems,isRemovingItems:t.isRemovingItems,isUpdatingItems:t.isUpdatingItems,items:t.items,itemsCount:t.itemsCount}},$r=async(e={inspect:void 0,quote:{id:"",locale:""},endpoints:{client:"",server:""},graphql:{}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),B(Je,{inspect:e.inspect,input:{initialContext:{endpoints:e.endpoints}}}).start()):B(Je,{input:{initialContext:{endpoints:e.endpoints,graphql:e.graphql,quote:{id:e.quote.id??"",locale:e.quote.locale??""}}},inspect:e.inspect}).start();function Vr({actor:e,children:t}){return Ye.jsx(dt.Provider,{value:e,children:t})}exports.AuthContext=it;exports.AuthProvider=Os;exports.QuoteContext=dt;exports.QuoteProvider=Vr;exports.ToastContext=ot;exports.ToastProvider=Ds;exports.authMachine=$e;exports.getAuth=bs;exports.getQuote=$r;exports.quoteMachine=Je;exports.timerMachine=en;exports.toastMachine=ks;exports.useAuth=ws;exports.useQuote=jr;exports.useToast=Cs;
51
+ `)))!==null&&t!==void 0?t:!1}const Dt=e=>{var s,r;let t;const n=e.definitions.filter(i=>i.kind==="OperationDefinition");return n.length===1&&(t=(r=(s=n[0])==null?void 0:s.name)==null?void 0:r.value),t},Le=e=>{if(typeof e=="string"){let n;try{const s=Er(e);n=Dt(s)}catch{}return{query:e,operationName:n}}const t=Dt(e);return{query:hn(e),operationName:t}};class ae extends Error{constructor(t,n){const s=`${ae.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(s),Object.setPrototypeOf(this,ae.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,ae)}static extractMessage(t){var n,s;return((s=(n=t.errors)==null?void 0:n[0])==null?void 0:s.message)??`GraphQL Error (Code: ${t.status})`}}var Nr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function kr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ze={exports:{}};(function(e,t){var n=typeof self<"u"?self:Nr,s=function(){function i(){this.fetch=!1,this.DOMException=n.DOMException}return i.prototype=n,new i}();(function(i){(function(o){var a={searchParams:"URLSearchParams"in i,iterable:"Symbol"in i&&"iterator"in Symbol,blob:"FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in i,arrayBuffer:"ArrayBuffer"in i};function c(d){return d&&DataView.prototype.isPrototypeOf(d)}if(a.arrayBuffer)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],f=ArrayBuffer.isView||function(d){return d&&u.indexOf(Object.prototype.toString.call(d))>-1};function l(d){if(typeof d!="string"&&(d=String(d)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(d))throw new TypeError("Invalid character in header field name");return d.toLowerCase()}function h(d){return typeof d!="string"&&(d=String(d)),d}function m(d){var g={next:function(){var _=d.shift();return{done:_===void 0,value:_}}};return a.iterable&&(g[Symbol.iterator]=function(){return g}),g}function y(d){this.map={},d instanceof y?d.forEach(function(g,_){this.append(_,g)},this):Array.isArray(d)?d.forEach(function(g){this.append(g[0],g[1])},this):d&&Object.getOwnPropertyNames(d).forEach(function(g){this.append(g,d[g])},this)}y.prototype.append=function(d,g){d=l(d),g=h(g);var _=this.map[d];this.map[d]=_?_+", "+g:g},y.prototype.delete=function(d){delete this.map[l(d)]},y.prototype.get=function(d){return d=l(d),this.has(d)?this.map[d]:null},y.prototype.has=function(d){return this.map.hasOwnProperty(l(d))},y.prototype.set=function(d,g){this.map[l(d)]=h(g)},y.prototype.forEach=function(d,g){for(var _ in this.map)this.map.hasOwnProperty(_)&&d.call(g,this.map[_],_,this)},y.prototype.keys=function(){var d=[];return this.forEach(function(g,_){d.push(_)}),m(d)},y.prototype.values=function(){var d=[];return this.forEach(function(g){d.push(g)}),m(d)},y.prototype.entries=function(){var d=[];return this.forEach(function(g,_){d.push([_,g])}),m(d)},a.iterable&&(y.prototype[Symbol.iterator]=y.prototype.entries);function v(d){if(d.bodyUsed)return Promise.reject(new TypeError("Already read"));d.bodyUsed=!0}function S(d){return new Promise(function(g,_){d.onload=function(){g(d.result)},d.onerror=function(){_(d.error)}})}function A(d){var g=new FileReader,_=S(g);return g.readAsArrayBuffer(d),_}function R(d){var g=new FileReader,_=S(g);return g.readAsText(d),_}function D(d){for(var g=new Uint8Array(d),_=new Array(g.length),N=0;N<g.length;N++)_[N]=String.fromCharCode(g[N]);return _.join("")}function L(d){if(d.slice)return d.slice(0);var g=new Uint8Array(d.byteLength);return g.set(new Uint8Array(d)),g.buffer}function J(){return this.bodyUsed=!1,this._initBody=function(d){this._bodyInit=d,d?typeof d=="string"?this._bodyText=d:a.blob&&Blob.prototype.isPrototypeOf(d)?this._bodyBlob=d:a.formData&&FormData.prototype.isPrototypeOf(d)?this._bodyFormData=d:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)?this._bodyText=d.toString():a.arrayBuffer&&a.blob&&c(d)?(this._bodyArrayBuffer=L(d.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(d)||f(d))?this._bodyArrayBuffer=L(d):this._bodyText=d=Object.prototype.toString.call(d):this._bodyText="",this.headers.get("content-type")||(typeof d=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?v(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(A)}),this.text=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return R(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(D(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a.formData&&(this.formData=function(){return this.text().then(yn)}),this.json=function(){return this.text().then(JSON.parse)},this}var le=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function he(d){var g=d.toUpperCase();return le.indexOf(g)>-1?g:d}function $(d,g){g=g||{};var _=g.body;if(d instanceof $){if(d.bodyUsed)throw new TypeError("Already read");this.url=d.url,this.credentials=d.credentials,g.headers||(this.headers=new y(d.headers)),this.method=d.method,this.mode=d.mode,this.signal=d.signal,!_&&d._bodyInit!=null&&(_=d._bodyInit,d.bodyUsed=!0)}else this.url=String(d);if(this.credentials=g.credentials||this.credentials||"same-origin",(g.headers||!this.headers)&&(this.headers=new y(g.headers)),this.method=he(g.method||this.method||"GET"),this.mode=g.mode||this.mode||null,this.signal=g.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&_)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(_)}$.prototype.clone=function(){return new $(this,{body:this._bodyInit})};function yn(d){var g=new FormData;return d.trim().split("&").forEach(function(_){if(_){var N=_.split("="),O=N.shift().replace(/\+/g," "),x=N.join("=").replace(/\+/g," ");g.append(decodeURIComponent(O),decodeURIComponent(x))}}),g}function mn(d){var g=new y,_=d.replace(/\r?\n[\t ]+/g," ");return _.split(/\r?\n/).forEach(function(N){var O=N.split(":"),x=O.shift().trim();if(x){var fe=O.join(":").trim();g.append(x,fe)}}),g}J.call($.prototype);function q(d,g){g||(g={}),this.type="default",this.status=g.status===void 0?200:g.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in g?g.statusText:"OK",this.headers=new y(g.headers),this.url=g.url||"",this._initBody(d)}J.call(q.prototype),q.prototype.clone=function(){return new q(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},q.error=function(){var d=new q(null,{status:0,statusText:""});return d.type="error",d};var gn=[301,302,303,307,308];q.redirect=function(d,g){if(gn.indexOf(g)===-1)throw new RangeError("Invalid status code");return new q(null,{status:g,headers:{location:d}})},o.DOMException=i.DOMException;try{new o.DOMException}catch{o.DOMException=function(g,_){this.message=g,this.name=_;var N=Error(g);this.stack=N.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function Oe(d,g){return new Promise(function(_,N){var O=new $(d,g);if(O.signal&&O.signal.aborted)return N(new o.DOMException("Aborted","AbortError"));var x=new XMLHttpRequest;function fe(){x.abort()}x.onload=function(){var re={status:x.status,statusText:x.statusText,headers:mn(x.getAllResponseHeaders()||"")};re.url="responseURL"in x?x.responseURL:re.headers.get("X-Request-URL");var Ne="response"in x?x.response:x.responseText;_(new q(Ne,re))},x.onerror=function(){N(new TypeError("Network request failed"))},x.ontimeout=function(){N(new TypeError("Network request failed"))},x.onabort=function(){N(new o.DOMException("Aborted","AbortError"))},x.open(O.method,O.url,!0),O.credentials==="include"?x.withCredentials=!0:O.credentials==="omit"&&(x.withCredentials=!1),"responseType"in x&&a.blob&&(x.responseType="blob"),O.headers.forEach(function(re,Ne){x.setRequestHeader(Ne,re)}),O.signal&&(O.signal.addEventListener("abort",fe),x.onreadystatechange=function(){x.readyState===4&&O.signal.removeEventListener("abort",fe)}),x.send(typeof O._bodyInit>"u"?null:O._bodyInit)})}return Oe.polyfill=!0,i.fetch||(i.fetch=Oe,i.Headers=y,i.Request=$,i.Response=q),o.Headers=y,o.Request=$,o.Response=q,o.fetch=Oe,Object.defineProperty(o,"__esModule",{value:!0}),o})({})})(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var r=s;t=r.fetch,t.default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t})(ze,ze.exports);var Se=ze.exports;const ve=kr(Se),Cr=En({__proto__:null,default:ve},[Se]),Q=e=>{let t={};return e&&(typeof Headers<"u"&&e instanceof Headers||Cr&&Se.Headers&&e instanceof Se.Headers?t=qs(e):Array.isArray(e)?e.forEach(([n,s])=>{n&&s!==void 0&&(t[n]=s)}):t=e),t},Rt=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),Dr=e=>{if(!Array.isArray(e.query)){const s=e,r=[`query=${encodeURIComponent(Rt(s.query))}`];return e.variables&&r.push(`variables=${encodeURIComponent(s.jsonSerializer.stringify(s.variables))}`),s.operationName&&r.push(`operationName=${encodeURIComponent(s.operationName)}`),r.join("&")}if(typeof e.variables<"u"&&!Array.isArray(e.variables))throw new Error("Cannot create query with given variable type, array expected");const t=e,n=e.query.reduce((s,r,i)=>(s.push({query:Rt(r),variables:t.variables?t.jsonSerializer.stringify(t.variables[i]):void 0}),s),[]);return`query=${encodeURIComponent(t.jsonSerializer.stringify(n))}`},Rr=e=>async t=>{const{url:n,query:s,variables:r,operationName:i,fetch:o,fetchOptions:a,middleware:c}=t,u={...t.headers};let f="",l;e==="POST"?(l=Lr(s,r,i,a.jsonSerializer),typeof l=="string"&&(u["Content-Type"]="application/json")):f=Dr({query:s,variables:r,operationName:i,jsonSerializer:a.jsonSerializer??at});const h={method:e,headers:u,body:l,...a};let m=n,y=h;if(c){const v=await Promise.resolve(c({...h,url:n,operationName:i,variables:r})),{url:S,...A}=v;m=S,y=A}return f&&(m=`${m}?${f}`),await o(m,y)};class fn{constructor(t,n={}){this.url=t,this.requestConfig=n,this.rawRequest=async(...s)=>{const[r,i,o]=s,a=Us(r,i,o),{headers:c,fetch:u=ve,method:f="POST",requestMiddleware:l,responseMiddleware:h,...m}=this.requestConfig,{url:y}=this;a.signal!==void 0&&(m.signal=a.signal);const{operationName:v}=Le(a.query);return Me({url:y,query:a.query,variables:a.variables,headers:{...Q(Pe(c)),...Q(a.requestHeaders)},operationName:v,fetch:u,method:f,fetchOptions:m,middleware:l}).then(S=>(h&&h(S),S)).catch(S=>{throw h&&h(S),S})}}async request(t,...n){const[s,r]=n,i=Fs(t,s,r),{headers:o,fetch:a=ve,method:c="POST",requestMiddleware:u,responseMiddleware:f,...l}=this.requestConfig,{url:h}=this;i.signal!==void 0&&(l.signal=i.signal);const{query:m,operationName:y}=Le(i.document);return Me({url:h,query:m,variables:i.variables,headers:{...Q(Pe(o)),...Q(i.requestHeaders)},operationName:y,fetch:a,method:c,fetchOptions:l,middleware:u}).then(v=>(f&&f(v),v.data)).catch(v=>{throw f&&f(v),v})}batchRequests(t,n){const s=Bs(t,n),{headers:r,...i}=this.requestConfig;s.signal!==void 0&&(i.signal=s.signal);const o=s.documents.map(({document:c})=>Le(c).query),a=s.documents.map(({variables:c})=>c);return Me({url:this.url,query:o,variables:a,headers:{...Q(Pe(r)),...Q(s.requestHeaders)},operationName:void 0,fetch:this.requestConfig.fetch??ve,method:this.requestConfig.method||"POST",fetchOptions:i,middleware:this.requestConfig.requestMiddleware}).then(c=>(this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c.data)).catch(c=>{throw this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c})}setHeaders(t){return this.requestConfig.headers=t,this}setHeader(t,n){const{headers:s}=this.requestConfig;return s?s[t]=n:this.requestConfig.headers={[t]:n},this}setEndpoint(t){return this.url=t,this}}const Me=async e=>{const{query:t,variables:n,fetchOptions:s}=e,r=Rr(Ps(e.method??"post")),i=Array.isArray(e.query),o=await r(e),a=await Mr(o,s.jsonSerializer??at),c=Array.isArray(a)?!a.some(({data:f})=>!f):!!a.data,u=Array.isArray(a)||!a.errors||Array.isArray(a.errors)&&!a.errors.length||s.errorPolicy==="all"||s.errorPolicy==="ignore";if(o.ok&&u&&c){const{errors:f,...l}=(Array.isArray(a),a),h=s.errorPolicy==="ignore"?l:a;return{...i?{data:h}:h,headers:o.headers,status:o.status}}else{const f=typeof a=="string"?{error:a}:a;throw new ae({...f,status:o.status,headers:o.headers},{query:t,variables:n})}};async function pn(e,t,...n){const s=js(e,t,...n);return new fn(s.url).request({...s})}const Lr=(e,t,n,s)=>{const r=s??at;if(!Array.isArray(e))return r.stringify({query:e,variables:t,operationName:n});if(typeof t<"u"&&!Array.isArray(t))throw new Error("Cannot create request body with given variable type, array expected");const i=e.reduce((o,a,c)=>(o.push({query:a,variables:t?t[c]:void 0}),o),[]);return r.stringify(i)},Mr=async(e,t)=>{let n;return e.headers.forEach((s,r)=>{r.toLowerCase()==="content-type"&&(n=s)}),n&&(n.toLowerCase().startsWith("application/json")||n.toLowerCase().startsWith("application/graphql+json")||n.toLowerCase().startsWith("application/graphql-response+json"))?t.parse(await e.text()):e.text()},Pe=e=>typeof e=="function"?e():e,Pr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");if(!e.document)throw new Error("No request document provided.");if(!e.requestHeaders)throw new Error("No request headers provided.");try{const n=await pn(e.endpoint,e.document,{items:e.items},e.requestHeaders);if(!((t=n.quoteAddItem)!=null&&t.quote))throw new Error("Could not add items to quote.");return{type:"ADD_ITEMS_SUCCESS",quote:n.quoteAddItem.quote}}catch{throw new Error("Request to add item(s) failed.")}}),qr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");try{const n=await pn(e.endpoint,"");if(!((t=n.quoteRemoveItem)!=null&&t.quote))throw new Error("Could not remove items from quote.");return{type:"REMOVE_ITEMS_SUCCESS",quote:n.quoteRemoveItem.quote}}catch{throw new Error("Request to remove item(s) failed.")}}),qe=typeof window>"u",Fr=Z(async({input:e})=>{var n,s,r,i;if(!e.endpoint)throw console.log("no endpoint"),new Error("No endpoint provided.");if(!e.endpointSsr)throw console.log("no endpoint ssr"),new Error("No SSR endpoint provided.");if(!e.locale)throw console.log("no locale"),new Error("No locale provided.");if(!e.document)throw console.log("no request document"),new Error("No request document provided.");if(!e.requestHeaders)throw console.log("no headers"),new Error("No request headers provided.");const t=new fn(qe?e.endpointSsr:e.endpoint,qe?{fetch,method:"POST"}:{credentials:"include",method:"POST",mode:"cors"});try{const{data:o,headers:a,status:c,errors:u,extensions:f}=await t.rawRequest(hn(e.document),{},qe?{...e.requestHeaders,Cookie:`quote_${e.locale}=${e.quoteId??""}`}:e.requestHeaders),l=o;if(!((n=l.refreshQuote)!=null&&n.quote))throw console.log("userError: ",(s=l.refreshQuote)==null?void 0:s.userErrors[0].code,(r=l.refreshQuote)==null?void 0:r.userErrors[0].field,(i=l.refreshQuote)==null?void 0:i.userErrors[0].message),new Error("Could not add items to quote.");return{type:"REFRESH_SUCCESS",quote:l.refreshQuote.quote}}catch(o){throw console.log("refresh error",o),new Error("Request to add item(s) failed.")}}),Ur=({context:e})=>typeof window>"u"&&e.quote.id!==""||typeof window<"u",Br=({context:e})=>!!e.quote.items&&e.quote.items.length>0,Je=Ae({types:{context:{},events:{},input:{}},actions:{addItems:C(Rs),removeItems:C(Ls),refresh:C(Ms)},actors:{addItems:Pr,removeItems:qr,refresh:Fr},guards:{canRefresh:Ur,hasItems:Br}}).createMachine({id:"quote",initial:"initializing",context:({input:e})=>{var t,n,s,r,i,o,a,c,u,f,l,h,m,y;return{quote:{id:"",locale:"",baseCurrency:"USD",currencyConversionRate:1,dateCreated:null,dateLastUpdated:null,currency:"USD",items:[],promotions:[],shippingAddresses:{available:[],selected:null},totals:{discount:0,tax:0,shipping:0,shippingTax:0,subtotal:0,grandTotal:0},appliedPriceRules:[],appliedPromotions:[],shippingMethods:[],paymentMethods:[],storeCredit:[],rewards:[],giftCards:[],...(t=e==null?void 0:e.initialContext)==null?void 0:t.quote},endpoints:{client:"",server:"",...(n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints},graphql:{refresh:{document:((i=(r=(s=e==null?void 0:e.initialContext)==null?void 0:s.graphql)==null?void 0:r.refresh)==null?void 0:i.document)??"",requestHeaders:((c=(a=(o=e==null?void 0:e.initialContext)==null?void 0:o.graphql)==null?void 0:a.refresh)==null?void 0:c.requestHeaders)??void 0},addItems:{document:((l=(f=(u=e==null?void 0:e.initialContext)==null?void 0:u.graphql)==null?void 0:f.addItems)==null?void 0:l.document)??"",requestHeaders:((y=(m=(h=e==null?void 0:e.initialContext)==null?void 0:h.graphql)==null?void 0:m.addItems)==null?void 0:y.requestHeaders)??void 0}},errors:[]}},states:{uninitialized:{on:{REFRESH:"refreshing"}},empty:{on:{ADD_ITEMS:"addingItems"}},active:{on:{ADD_ITEMS:"addingItems",REMOVE_ITEMS:"removingItems",REFRESH:"refreshing"}},initializing:{always:[{target:"refreshing",guard:"canRefresh"},{target:"uninitialized"}]},refreshing:{invoke:{input:({context:e})=>({endpoint:e.endpoints.client,endpointSsr:e.endpoints.server,quoteId:e.quote.id,locale:e.quote.locale,document:e.graphql.refresh.document,requestHeaders:e.graphql.refresh.requestHeaders}),src:"refresh",onDone:[{actions:["refresh"],guard:"hasItems",target:"active"},{actions:["refresh"],target:"empty"}],onError:{target:"empty"}}},addingItems:{invoke:{input:({context:e,event:t})=>{var n,s;return{endpoint:e.endpoints.client,items:t.type==="ADD_ITEMS"?t.items:[],document:(n=e.graphql.addItems)==null?void 0:n.document,requestHeaders:(s=e.graphql.addItems)==null?void 0:s.requestHeaders}},src:"addItems",onDone:[{actions:["addItems"],target:"active"}],onError:[{guard:"hasItems",target:"active"},{target:"empty"}]}},removingItems:{}}}),dt=P.createContext({}),jr=()=>{const e=P.useContext(dt),[t,n]=P.useState(()=>{var r;const s=e.getSnapshot();return{items:s.context.quote.items??[],itemsCount:((r=s.context.quote.items)==null?void 0:r.length)??0,isAddingItems:s.value==="addingItems",isRemovingItems:s.value==="removingItems",isUpdatingItems:s.value==="addingItems"||s.value==="removingItems"}});return P.useEffect(()=>{const s=e.subscribe(r=>{const i=r.context.quote.items??[];n(o=>({...o,items:i,itemsCount:i.length,isAddingItems:r.matches("addingItems"),isRemovingItems:r.matches("removingItems"),isUpdatingItems:r.matches("addingItems")||r.matches("removingItems")}))});return()=>{s.unsubscribe()}},[e]),{quoteActor:e,isAddingItems:t.isAddingItems,isRemovingItems:t.isRemovingItems,isUpdatingItems:t.isUpdatingItems,items:t.items,itemsCount:t.itemsCount}},$r=async(e={inspect:void 0,quote:{id:"",locale:""},endpoints:{client:"",server:""},graphql:{}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),B(Je,{inspect:e.inspect,input:{initialContext:{endpoints:e.endpoints}}}).start()):B(Je,{input:{initialContext:{endpoints:e.endpoints,graphql:e.graphql,quote:{id:e.quote.id??"",locale:e.quote.locale??""}}},inspect:e.inspect}).start();function Vr({actor:e,children:t}){return Ye.jsx(dt.Provider,{value:e,children:t})}exports.AuthContext=it;exports.AuthProvider=Os;exports.QuoteContext=dt;exports.QuoteProvider=Vr;exports.ToastContext=ot;exports.ToastProvider=Ds;exports.authMachine=$e;exports.getAuth=bs;exports.getQuote=$r;exports.quoteMachine=Je;exports.timerMachine=en;exports.toastMachine=ks;exports.useAuth=ws;exports.useQuote=jr;exports.useToast=Cs;
package/index.mjs CHANGED
@@ -6248,13 +6248,14 @@ const Dr = (e, t, n, s) => {
6248
6248
  return Rt(() => {
6249
6249
  const s = e.subscribe((r) => {
6250
6250
  const i = r.context.quote.items ?? [];
6251
- n({
6251
+ n((o) => ({
6252
+ ...o,
6252
6253
  items: i,
6253
6254
  itemsCount: i.length,
6254
6255
  isAddingItems: r.matches("addingItems"),
6255
6256
  isRemovingItems: r.matches("removingItems"),
6256
6257
  isUpdatingItems: r.matches("addingItems") || r.matches("removingItems")
6257
- });
6258
+ }));
6258
6259
  });
6259
6260
  return () => {
6260
6261
  s.unsubscribe();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clicktap/state",
3
- "version": "0.13.7",
3
+ "version": "0.13.8",
4
4
  "private": false,
5
5
  "author": "Clicktap",
6
6
  "description": "A state management library for Clicktap reference frontend.",