@occluze/tether 0.6.7 → 0.6.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.
- package/README.md +3 -3
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-C3NP6HFB.js +1 -0
- package/dist/esm/chunks/account-pages-WLK374FO.js +1 -0
- package/dist/esm/chunks/analytics-G3SAWMNL.js +1 -0
- package/dist/esm/chunks/chunk-27PJJZGC.js +1 -0
- package/dist/esm/chunks/chunk-2FSXS55U.js +1 -0
- package/dist/esm/chunks/chunk-FCSWQDVV.js +1 -0
- package/dist/esm/chunks/chunk-FOMSMIAM.js +1 -0
- package/dist/esm/chunks/chunk-GZJTCLLW.js +1 -0
- package/dist/esm/chunks/chunk-HEQILZVR.js +1 -0
- package/dist/esm/chunks/chunk-JOOEXYF3.js +4 -0
- package/dist/esm/chunks/chunk-MPTQYLSM.js +1 -0
- package/dist/esm/chunks/chunk-NEHZ37TU.js +3 -0
- package/dist/esm/chunks/chunk-V74KGEJF.js +1 -0
- package/dist/esm/chunks/chunk-VT4CDUJJ.js +1 -0
- package/dist/esm/chunks/chunk-YJLWX2HK.js +1 -0
- package/dist/esm/chunks/diagnose-6VVGZNTY.js +14 -0
- package/dist/esm/chunks/extras-GJVRDFM3.js +1 -0
- package/dist/esm/chunks/markets-ui-UNB4PTA7.js +1 -0
- package/dist/esm/chunks/search-OU75RNQL.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -1
- package/dist/presets/barba.esm.js +56 -36
- package/dist/tether.account-pages.js +773 -442
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +648 -318
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +318 -191
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +331 -242
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +78 -33
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +3176 -2015
- package/dist/tether.markets.js +231 -126
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +0 -0
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +221 -126
- package/dist/tether.search.min.js +1 -1
- package/package.json +23 -4
- package/src/account/addresses-view.js +92 -0
- package/src/account/browser-session.js +359 -0
- package/src/account/markup.js +48 -0
- package/src/account/operations.js +180 -0
- package/src/account/order-lines.js +96 -0
- package/src/account/order-list.js +91 -0
- package/src/account/order-page.js +192 -0
- package/src/account/page-events.js +288 -0
- package/src/account/server-client.js +172 -0
- package/src/account/shared.js +111 -0
- package/src/account/shopify-auth.js +150 -0
- package/src/account/subscriptions-view.js +158 -0
- package/src/account-api.js +118 -0
- package/src/account-links.js +35 -0
- package/src/account-pages.js +69 -298
- package/src/account.js +280 -323
- package/src/amounts.js +36 -0
- package/src/analytics-shopify.js +241 -0
- package/src/analytics.js +304 -184
- package/src/api-version.js +75 -25
- package/src/astro.js +233 -68
- package/src/cart/checkout.js +97 -0
- package/src/cart/drawer.js +138 -0
- package/src/cart/mutations.js +234 -0
- package/src/cart/render.js +294 -0
- package/src/cart/store.js +326 -0
- package/src/cart.js +320 -488
- package/src/client.js +214 -78
- package/src/collection.js +126 -57
- package/src/config.js +323 -59
- package/src/controls/cart-controls.js +155 -0
- package/src/controls/discount.js +96 -0
- package/src/controls/extras.js +63 -0
- package/src/controls/navigation.js +83 -0
- package/src/diagnose-markup.js +333 -0
- package/src/diagnose.js +251 -202
- package/src/dom.js +219 -220
- package/src/extras.js +119 -37
- package/src/fragments.js +115 -22
- package/src/images.js +104 -0
- package/src/index.js +245 -287
- package/src/initial.js +78 -66
- package/src/lazy-iife.js +92 -22
- package/src/lazy.js +25 -4
- package/src/loader.js +263 -124
- package/src/market-codes.js +35 -0
- package/src/markets-ui.js +169 -55
- package/src/markets.js +286 -85
- package/src/markup.js +64 -0
- package/src/mounting.js +214 -91
- package/src/page-market.js +116 -0
- package/src/parts/account-pages.js +4 -1
- package/src/parts/account.js +4 -1
- package/src/parts/analytics.js +4 -1
- package/src/parts/diagnose.js +4 -1
- package/src/parts/extras.js +4 -1
- package/src/parts/markets.js +4 -1
- package/src/parts/search.js +4 -1
- package/src/presets/barba.js +120 -30
- package/src/product-events.js +130 -0
- package/src/product-render.js +257 -0
- package/src/product-state.js +318 -0
- package/src/product.js +233 -459
- package/src/repeaters.js +173 -0
- package/src/search.js +277 -107
- package/src/selling-plans.js +107 -47
- package/src/server.js +168 -205
- package/src/shopify-values.js +89 -0
- package/src/status.js +99 -39
- package/src/store-html.js +0 -0
- package/src/storefront/catalog.js +199 -0
- package/src/storefront/json-ld.js +167 -0
- package/src/variant-render.js +165 -0
- package/types/astro.d.ts +13 -2
- package/types/index.d.ts +178 -27
- package/types/server.d.ts +89 -17
- package/dist/esm/chunks/account-Q6E2TFEV.js +0 -1
- package/dist/esm/chunks/account-pages-UZXR4R5F.js +0 -1
- package/dist/esm/chunks/analytics-IJBKATUP.js +0 -1
- package/dist/esm/chunks/chunk-4QJKLPYR.js +0 -1
- package/dist/esm/chunks/chunk-64TUD3QR.js +0 -1
- package/dist/esm/chunks/chunk-AJLPU2JC.js +0 -4
- package/dist/esm/chunks/chunk-FIOZPPC5.js +0 -1
- package/dist/esm/chunks/chunk-K2YEQAIH.js +0 -1
- package/dist/esm/chunks/chunk-KIDH76B7.js +0 -1
- package/dist/esm/chunks/chunk-PAYT5ZD7.js +0 -1
- package/dist/esm/chunks/chunk-RREHGH4A.js +0 -1
- package/dist/esm/chunks/chunk-SSJT43CJ.js +0 -1
- package/dist/esm/chunks/chunk-VC46IEJQ.js +0 -1
- package/dist/esm/chunks/diagnose-3WVAWNTX.js +0 -14
- package/dist/esm/chunks/extras-7I7WJX35.js +0 -1
- package/dist/esm/chunks/markets-ui-545XLFTE.js +0 -1
- package/dist/esm/chunks/search-NILMGYXG.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var mt=Object.defineProperty;var ht=(t,e)=>{for(var n in e)mt(t,n,{get:e[n],enumerable:!0})};var X={};ht(X,{addresses:()=>$t,customer:()=>W,deleteAddress:()=>Nt,getToken:()=>E,handleCallback:()=>at,isLoggedIn:()=>V,login:()=>ot,logout:()=>ut,mountAccount:()=>qt,order:()=>Pt,orders:()=>it,query:()=>q,render:()=>N,requestReturn:()=>Dt,saveAddress:()=>vt,subscriptionAction:()=>Ot,subscriptions:()=>Lt,updateProfile:()=>Ct});var wt=window.Tether.__core["config.js"],{DEFAULTS:jt,cfg:r,configure:Jt,isConfigured:Bt,log:Y,reportError:k,warn:Gt}=wt;var gt=window.Tether.__core["client.js"],{TetherError:w,endpoint:Mt,gql:zt,request:Ft,unwrap:Ht,withContext:Vt}=gt;var pt=window.Tether.__core["dom.js"],{attr:Xt,busy:Yt,cdnUrl:Qt,dataKey:Zt,emit:A,formatDate:te,formatMoney:Q,formatPercent:ee,get:_,has:ne,hasTemplate:oe,imageUrl:re,notifyLayoutChanged:se,parseJSONAttr:ae,productUrl:ce,qsa:g,readText:ie,repeat:R,repeatKeyed:ue,sameImage:le,scoped:de,sel:d,setImage:j,setSelected:fe,setText:$,setTextTracked:me,show:b,toAttributes:he,watchImages:we}=pt;var yt=window.Tether.__core["cart.js"],{Cart:f,focusables:pe,toLineInput:ye}=yt;var _t=window.Tether.__core["lazy.js"],{coreModules:Se,loadPart:Z}=_t;var L=()=>`${r.prefix}:account:${r.domain}`,K=()=>`${r.prefix}:account-login:${r.domain}`,O=()=>r.account?.remember?window.localStorage:window.sessionStorage,nt=t=>btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),J=()=>nt(crypto.getRandomValues(new Uint8Array(32))),St=async t=>nt(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t))),U=t=>(r.account?.navigate||(e=>window.location.assign(e)))(t),F=(t,e)=>{try{return JSON.parse(t.getItem(e)||"null")}catch{return null}},D=(t,e,n)=>{try{n?t.setItem(e,JSON.stringify(n)):t.removeItem(e)}catch{}},v=null,i=null,B=null,x=null,m=()=>r.account?.server?new URL(String(r.account.server),window.location.href).href.replace(/\/$/,""):"",M=()=>`${r.prefix}:account-hint:${r.domain}`,I=null;async function P(t,{method:e="GET",body:n}={}){let o=await fetch(`${m()}${t}`,{method:e,credentials:"include",headers:e==="POST"?{"Content-Type":"application/json","X-Tether-Account":"1"}:{},body:n?JSON.stringify(n):void 0}),s=await o.json().catch(()=>({}));if(!o.ok&&o.status!==401)throw new w(`Customer accounts: ${s.error||o.status}`,{status:o.status,userErrors:s.userErrors});return s}async function H(){I||(I=await P("/me"));try{I.loggedIn?window.localStorage.setItem(M(),"1"):window.localStorage.removeItem(M())}catch{}return I}async function C(){if(v)return v;let t=r.account?.shopDomain||r.domain,e=s=>fetch(`https://${t}/.well-known/${s}`).then(a=>{if(!a.ok)throw new w(`Customer accounts: ${s} answered ${a.status}`,{status:a.status});return a.json()}),[n,o]=await Promise.all([e("openid-configuration"),e("customer-account-api")]);return v={...n,graphql:o.graphql_api},v}var Tt=()=>r.account?.callbackUrl||`${window.location.origin}${window.location.pathname}`;function V(){return m()?!!I?.loggedIn:!!(i?.refresh||i?.access&&i.expiresAt>Date.now())}async function ot({returnTo:t=window.location.href,locale:e}={}){if(m()){let h=new URL(`${m()}/login`);h.searchParams.set("returnTo",t);let T=e||r.account.locale||(r.locale||"").split("-")[0];T&&h.searchParams.set("locale",T),r.country&&h.searchParams.set("country",String(r.country).toUpperCase()),U(h.toString());return}if(!r.account?.clientId)throw new w("Customer accounts: set account.clientId",{code:"NOT_CONFIGURED"});let n=await C(),o=J(),s=J(),a=J(),u=Tt();D(window.sessionStorage,K(),{state:o,nonce:s,verifier:a,redirect:u,returnTo:t,at:Date.now()});let c=new URL(n.authorization_endpoint),l={client_id:r.account.clientId,scope:"openid email customer-account-api:full",response_type:"code",redirect_uri:u,state:o,nonce:s,code_challenge:await St(a),code_challenge_method:"S256"},p=e||r.account.locale||(r.locale||"").split("-")[0];p&&(l.locale=p),r.country&&(l.region_country=String(r.country).toUpperCase()),Object.entries(l).forEach(([h,T])=>c.searchParams.set(h,T)),U(c.toString())}async function rt(t){let e=await C(),n=await fetch(r.account.tokenUrl||e.token_endpoint,{method:"POST",body:new URLSearchParams(t)}),o=await n.json().catch(()=>({}));if(!n.ok||!o.access_token)throw new w(`Customer accounts: token ${n.status} ${o.error||""}`.trim(),{status:n.status,code:n.status===400||n.status===401?"SESSION_ENDED":"TOKEN_FAILED"});return o}function kt(t){try{return JSON.parse(atob(t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function st(t,e=i){i={access:t.access_token,expiresAt:Date.now()+Math.max(0,(Number(t.expires_in)||3600)-120)*1e3,refresh:t.refresh_token||e?.refresh,idToken:t.id_token||e?.idToken},D(O(),L(),i)}async function at(){let t=new URLSearchParams(window.location.search),e=F(window.sessionStorage,K());if(!e||!t.has("code")&&!t.has("error")||t.get("state")!==e.state)return!1;D(window.sessionStorage,K(),null);let n=new URL(window.location.href);if(["code","state","iss","error","error_description"].forEach(l=>n.searchParams.delete(l)),window.history.replaceState(window.history.state,"",n),t.has("error"))return A("account-error",{error:t.get("error")}),!1;if(Date.now()-e.at>10*6e4)throw new w("Customer accounts: the login took too long, please try again");let o=await rt({grant_type:"authorization_code",client_id:r.account.clientId,redirect_uri:e.redirect,code:t.get("code"),code_verifier:e.verifier}),s=await C(),a=kt(o.id_token||""),u=[].concat(a?.aud||[]);if(!a||a.nonce!==e.nonce||a.iss!==s.issuer||!u.includes(r.account.clientId)||a.exp*1e3<Date.now())throw new w("Customer accounts: the login answer did not check out (nonce/issuer/audience)");st(o,null),await ct(),A("account-login",{});let c=e.returnTo&&new URL(e.returnTo,window.location.href);return c&&c.origin===window.location.origin&&c.href!==n.href&&U(c.href),!0}async function E(){return m()||(i||(i=F(O(),L())),!i)?null:i.access&&i.expiresAt>Date.now()?i.access:i.refresh?(B||(B=(async()=>{try{st(await rt({grant_type:"refresh_token",client_id:r.account.clientId,refresh_token:i.refresh})),await ct()}catch(t){if(t.code==="SESSION_ENDED")z();else throw t}finally{B=null}})()),await B,i?.access||null):(z(),null)}function z(){i=null,x=null,D(O(),L(),null),f.customerAccessToken=null}async function ct(){f.customerAccessToken=i?.access||null,f.id()&&i?.access&&await f.setBuyerIdentity({customerAccessToken:i.access},{create:!1}).catch(t=>k(t,"account cart"))}async function q(t,e={}){if(m())throw new w("Customer accounts in server mode only answer customer() and orders()",{code:"NOT_ALLOWED"});let n=await E();if(!n)throw new w("Not logged in",{code:"NOT_LOGGED_IN"});let o=await C(),s=c=>fetch(o.graphql,{method:"POST",headers:{"Content-Type":"application/json",Authorization:c},body:JSON.stringify({query:t,variables:e})}),a=await s(n);a.status===401&&i?.refresh&&(i.expiresAt=0,a=await s(await E()));let u=await a.json().catch(()=>({}));if(!a.ok||u.errors?.length)throw new w(u.errors?.map(c=>c.message).join(" | ")||`Customer accounts: ${a.status}`,{status:a.status});return u.data}async function W(){if(m()){let e=await H();return e.loggedIn?{...e.customer,emailAddress:{emailAddress:e.customer.email},defaultAddress:{formatted:e.customer.address}}:null}return x||(x=(await q("query TetherCustomer{customer{id firstName lastName displayName emailAddress{emailAddress}defaultAddress{formatted}}}")).customer,x)}async function it({first:t=10}={}){return m()?(await P(`/orders?first=${t}`)).orders||[]:(await q("query TetherOrders($first:Int!){customer{orders(first:$first,sortKey:PROCESSED_AT,reverse:true){nodes{id name processedAt financialStatus fulfillmentStatus statusPageUrl totalPrice{amount currencyCode}lineItems(first:20){nodes{title variantTitle quantity image{url altText}}}}}}}",{first:t})).customer?.orders?.nodes||[]}async function ut({returnTo:t=r.account?.logoutUrl||`${window.location.origin}/`}={}){if(m()){let s=await P("/logout",{method:"POST",body:{returnTo:t,cartId:f.id()}});I={loggedIn:!1};try{window.localStorage.removeItem(M())}catch{}A("account-logout",{}),s.logoutUrl?U(s.logoutUrl):N(document);return}let e=i?.idToken||F(O(),L())?.idToken;if(f.id()&&await f.setBuyerIdentity({customerAccessToken:null},{create:!1}).catch(()=>{}),z(),A("account-logout",{}),!e){N(document);return}let n=await C(),o=new URL(n.end_session_endpoint);o.searchParams.set("id_token_hint",e),o.searchParams.set("post_logout_redirect_uri",t),U(o.toString())}var At=t=>{try{return new URL(t).protocol==="https:"}catch{return!1}},xt=t=>{try{return new Date(t).toLocaleDateString(r.locale||void 0)}catch{return t}};async function N(t=document){let e=m()?!!(await H().catch(()=>({loggedIn:!1}))).loggedIn:V()||!!await E().catch(()=>null);g(t,d("show")).forEach(n=>{let o=_(n,"show");o==="logged-in"&&b(n,e),o==="logged-out"&&b(n,!e)}),g(t,d("account-link")).forEach(n=>{let o=_(n,"account-link"),s=o==="payment"&&(r.account?.paymentUrl||r.account?.subscriptionsUrl)||o==="subscriptions"&&r.account?.subscriptionsUrl;n.setAttribute("href",s||`https://${r.domain}/account`)}),e&&(await lt(t),await Promise.all([It(t),Et.some(n=>g(t,d(n)).length)?dt().then(n=>n.renderPages(t)):null]))}async function It(t){let e=g(t,d("orders"));if(e.length){let n=(a,u)=>g(t,d("show")).forEach(c=>{let l=_(c,"show");l==="orders-loading"&&b(c,a),l==="orders-empty"&&b(c,u)});n(!0,!1);let o=!1,s=await it({first:parseInt(_(e[0],"limit")||"10",10)}).catch(a=>(k(a,"orders"),o=!0,[]));n(!1,!o&&s.length===0),e.forEach(a=>R(a,s,(u,c)=>{let l=c.lineItems?.nodes||[];g(u,d("order-bind")).forEach(p=>{let h=_(p,"order-bind");if(h==="url"){let y=G(c);y&&p.setAttribute("href",y);return}if(h==="image"){let y=l.find(ft=>ft.image)?.image;y&&j(p,y.url,y.altText||l[0]?.title||"");return}let T={name:c.name,date:xt(c.processedAt),total:Q(c.totalPrice),status:c.financialStatus?.toLowerCase(),fulfillment:c.fulfillmentStatus?.toLowerCase(),items:l.map(y=>`${y.quantity}\xD7 ${y.title}`).join(", ")}[h];T!=null&&$(p,T)}),g(u,d("order-lines")).forEach(p=>Ut(p,l)),_(u,"order-bind")==="url"&&G(c)&&u.setAttribute("href",G(c))}))}}var bt=t=>String(t||"").split("/").pop().split("?")[0];function G(t){let e=r.account?.orderUrl;return e?String(e).replace("{id}",encodeURIComponent(bt(t.id))):At(t.statusPageUrl)?t.statusPageUrl:null}function Ut(t,e){R(t,e,(n,o)=>{g(n,d("order-line")).concat(n.matches(d("order-line"))?[n]:[]).forEach(s=>{let a=_(s,"order-line");if(a==="image"){o.image&&j(s,o.image.url,o.image.altText||o.title);return}let u={title:o.title,"variant-title":o.variantTitle||"",quantity:String(o.quantity)}[a];u!=null&&$(s,u)})})}var Et=["order","addresses","subscriptions","profile-form","address-form"],tt=null;async function lt(t){let e=g(t,d("account-bind"));if(!e.length)return;let n=await W().catch(o=>(k(o,"account"),null));e.forEach(o=>{let s={"first-name":n?.firstName,"last-name":n?.lastName,name:n?.displayName,email:n?.emailAddress?.emailAddress,address:n?.defaultAddress?.formatted?.join(", ")}[_(o,"account-bind")];s!=null&&$(o,s)})}function dt(){return tt||(tt=Z("account-pages").then(t=>(t.setup({server:m,serverFetch:P,query:q,customer:W,bindCustomer:lt,reset:()=>{x=null,I=null}}),t))),tt}var S=t=>(...e)=>dt().then(n=>n[t](...e)),Pt=S("order"),Ct=S("updateProfile"),$t=S("addresses"),vt=S("saveAddress"),Nt=S("deleteAddress"),Lt=S("subscriptions"),Ot=S("subscriptionAction"),Dt=S("requestReturn"),et=!1;async function qt(t=document){if(!et){if(et=!0,document.addEventListener("click",e=>{let n=e.target;n.closest?.(d("account-login"))?(e.preventDefault(),ot().catch(o=>k(o,"login"))):n.closest?.(d("account-logout"))&&(e.preventDefault(),ut().catch(o=>k(o,"logout")))}),m()){let e=new URL(window.location.href);e.searchParams.get("account")&&(e.searchParams.delete("account"),window.history.replaceState(window.history.state,"",e),A("account-login",{})),f.beforeCheckout=async()=>{if(!(await H()).loggedIn||!f.id())return null;let n=await P("/cart",{method:"POST",body:{cartId:f.id()}}).catch(()=>null);return n?.checkoutUrl?`${n.checkoutUrl}${n.checkoutUrl.includes("?")?"&":"?"}logged_in=true`:null}}else{try{await at()}catch(e){k(e,"login")}!f.customerAccessToken&&await E().catch(()=>null)&&(f.customerAccessToken=i.access)}Y("account",V()?"logged in":"logged out")}await N(t)}window.Tether.__parts.account=X;})();
|
|
1
|
+
"use strict";(()=>{var Gt=Object.defineProperty;var Ht=(t,e)=>{for(var r in e)Gt(t,r,{get:e[r],enumerable:!0})};var at={};Ht(at,{addresses:()=>ke,customer:()=>st,deleteAddress:()=>Se,getToken:()=>L,handleCallback:()=>ot,isLoggedIn:()=>jt,login:()=>qt,logout:()=>Jt,mountAccount:()=>Le,order:()=>xe,orders:()=>Bt,query:()=>Mt,render:()=>it,requestReturn:()=>Ce,saveAddress:()=>Ee,subscriptionAction:()=>Ae,subscriptions:()=>_e,updateProfile:()=>Te});var zt=window.Tether.__core["config.js"],{DEFAULTS:Ne,cfg:i,configure:Re,isConfigured:Pe,log:ct,reportError:w,resolveConfig:De,toMetafieldIdentifier:$e,warn:ve}=zt;var Vt=window.Tether.__core["client.js"],{TetherError:m,endpoint:qe,gql:Me,request:Be,unwrap:Je,withContext:Ke}=Vt;var Qt=window.Tether.__core["dom.js"],{attr:Ge,busy:He,cdnUrl:ze,emit:E,formatDate:Ve,formatMoney:R,formatPercent:Qe,get:h,has:Ye,hasTemplate:We,imageUrl:Xe,notifyLayoutChanged:Ze,parseJSONAttr:tr,productUrl:er,qsa:p,repeat:j,repeatKeyed:rr,sameImage:or,scoped:nr,sel:u,setImage:q,setSelected:sr,setStoreHtml:ir,setText:C,setTextTracked:ar,show:P,toAttributes:cr,watchImages:ur}=Qt;var Yt=window.Tether.__core["cart.js"],{Cart:g,trapFocus:dr}=Yt;var Wt=window.Tether.__core["lazy.js"],{coreModules:mr,loadPart:ut}=Wt;var Xt="amount currencyCode",lt="query TetherCustomer { customer { id firstName lastName displayName emailAddress { emailAddress } defaultAddress { formatted } } }",dt=`query TetherOrders($first:Int!){customer{orders(first:$first,sortKey:PROCESSED_AT,reverse:true){nodes{id name processedAt financialStatus fulfillmentStatus statusPageUrl totalPrice{${Xt}}lineItems(first:20){nodes{title variantTitle quantity image{url altText}}}}}}}`;function Q(t){return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function ft(t){let e=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"=");return Uint8Array.from(atob(e),r=>r.charCodeAt(0))}function M(t=32){return Q(crypto.getRandomValues(new Uint8Array(t)))}var B=()=>`${i.prefix}:account:${i.domain}`,J=()=>`${i.prefix}:account-login:${i.domain}`,Zt=()=>`${i.prefix}:account-hint:${i.domain}`,K=()=>i.account?.remember?"local":"session",Y=t=>t==="local"?window.localStorage:window.sessionStorage;function W(t,e){try{return JSON.parse(Y(t).getItem(e)??"null")}catch{return null}}function S(t,e,r){try{r===null?Y(t).removeItem(e):Y(t).setItem(e,JSON.stringify(r))}catch{}}function X(t){S("local",Zt(),t?1:null)}var x=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),l=t=>typeof t=="string"?t:null;async function b(t){let e;try{e=await t.json()}catch{return{}}return x(e)?e:{}}function _(t){let e=i.account?.navigate;e?e(t):window.location.assign(t)}var F=t=>t||i.account?.locale||(i.locale||"").split("-")[0]||"",G=()=>i.country?i.country.toUpperCase():"";var te=3600,H=null;async function mt(t){let e=i.account?.shopDomain||i.domain,r=await fetch(`https://${e}/.well-known/${t}`);if(!r.ok)throw new m(`Customer accounts: ${t} answered ${r.status}`,{status:r.status});let o=await r.json();return x(o)?o:{}}function D(t,e){let r=l(t[e]);if(!r)throw new m(`Customer accounts: Shopify named no ${e}`);return r}async function I(){if(H)return H;let[t,e]=await Promise.all([mt("openid-configuration"),mt("customer-account-api")]);return H={issuer:D(t,"issuer"),authorizationEndpoint:D(t,"authorization_endpoint"),tokenEndpoint:D(t,"token_endpoint"),endSessionEndpoint:D(t,"end_session_endpoint"),graphql:D(e,"graphql_api")},H}async function Z(t){let{tokenEndpoint:e}=await I(),r=await fetch(i.account?.tokenUrl||e,{method:"POST",body:new URLSearchParams(t)}),o=await b(r),n=l(o.access_token);if(!r.ok||!n){let s=r.status===400||r.status===401;throw new m(`Customer accounts: token ${r.status} ${l(o.error)??""}`.trim(),{status:r.status,code:s?"SESSION_ENDED":"TOKEN_FAILED"})}return{access:n,refresh:l(o.refresh_token)||null,idToken:l(o.id_token)||null,expiresInSeconds:Number(o.expires_in)||te}}function ee(t){let e=t.split(".")[1];if(!e)return null;let r;try{r=JSON.parse(new TextDecoder().decode(ft(e)))}catch{return null}return x(r)?r:null}function pt(t,{nonce:e,issuer:r,client:o}){let n=t?ee(t):null;if(!n)return!1;let s=n.aud,a=Array.isArray(s)?s:[s],c=n.exp;return n.nonce===e&&n.iss===r&&a.includes(o)&&typeof c=="number"&&c*1e3>=Date.now()}var re=120,oe=600*1e3,d=null,O=null,tt=null;function ne(t){if(!x(t))return null;let e=t.access,r=t.expiresAt;return typeof e!="string"||typeof r!="number"?null:{access:e,expiresAt:r,refresh:l(t.refresh),idToken:l(t.idToken)}}function se(t){if(!x(t))return null;let{state:e,nonce:r,verifier:o,redirect:n,returnTo:s,at:a}=t;return typeof e!="string"||typeof r!="string"||typeof o!="string"||typeof n!="string"||typeof s!="string"||typeof a!="number"?null:{state:e,nonce:r,verifier:o,redirect:n,returnTo:s,at:a}}var gt=()=>d??ne(W(K(),B())),wt=()=>d?.access??null,et=()=>!!(d&&(d.refresh||d.access&&d.expiresAt>Date.now()));function rt(){let t=i.account?.clientId;if(!t)throw new m("Customer accounts: set account.clientId",{code:"NOT_CONFIGURED"});return t}var ie=async t=>Q(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t)));async function ht({returnTo:t,locale:e}){let r=rt(),o=await I(),n={state:M(),nonce:M(),verifier:M(),redirect:i.account?.callbackUrl||`${window.location.origin}${window.location.pathname}`,returnTo:t,at:Date.now()};S("session",J(),n);let s=new URL(o.authorizationEndpoint),a={client_id:r,scope:"openid email customer-account-api:full",response_type:"code",redirect_uri:n.redirect,state:n.state,nonce:n.nonce,code_challenge:await ie(n.verifier),code_challenge_method:"S256"},c=F(e);c&&(a.locale=c);let f=G();f&&(a.region_country=f),Object.entries(a).forEach(([k,v])=>{s.searchParams.set(k,v)}),_(s.toString())}function yt(t,e){d={access:t.access,expiresAt:Date.now()+Math.max(0,t.expiresInSeconds-re)*1e3,refresh:t.refresh??e?.refresh??null,idToken:t.idToken??e?.idToken??null},S(K(),B(),d)}async function ot(){let t=new URLSearchParams(window.location.search),e=se(W("session",J()));if(!e||!t.has("code")&&!t.has("error")||t.get("state")!==e.state)return!1;S("session",J(),null);let r=new URL(window.location.href);["code","state","iss","error","error_description"].forEach(f=>{r.searchParams.delete(f)}),window.history.replaceState(window.history.state,"",r);let o=t.get("error");if(o!==null)return E("account-error",{error:o}),!1;if(Date.now()-e.at>oe)throw new m("Customer accounts: the login took too long, please try again");let n=rt(),s=await Z({grant_type:"authorization_code",client_id:n,redirect_uri:e.redirect,code:t.get("code")??"",code_verifier:e.verifier}),{issuer:a}=await I();if(!pt(s.idToken,{nonce:e.nonce,issuer:a,client:n}))throw new m("Customer accounts: the login answer did not check out (nonce/issuer/audience)");yt(s,null),await xt(),E("account-login",{});let c=e.returnTo?new URL(e.returnTo,window.location.href):null;return c?.origin===window.location.origin&&c.href!==r.href&&_(c.href),!0}function nt(){d=null,O=null,S(K(),B(),null),g.setCustomer({accessToken:null})}async function ae(t){try{let e=await Z({grant_type:"refresh_token",client_id:rt(),refresh_token:t.refresh??""});yt(e,t),await xt()}catch(e){if(e instanceof m&&e.code==="SESSION_ENDED")nt();else throw e}}async function L(){return d=gt(),d?d.access&&d.expiresAt>Date.now()?d.access:d.refresh?(tt??(tt=ae(d).finally(()=>{tt=null})),await tt,wt()):(nt(),null):null}async function xt(){let t=wt();if(g.setCustomer({accessToken:t}),!(!g.id()||!t))try{await g.setBuyerIdentity({customerAccessToken:t},{create:!1})}catch(e){w(e,"account cart")}}async function ce(){if(g.id())try{await g.setBuyerIdentity({customerAccessToken:null},{create:!1})}catch(t){w(t,"account cart unlink"),S("local",i.storageKey,null)}}async function Tt(t){let e=gt()?.idToken??null;if(await ce(),nt(),E("account-logout",{}),!e)return"stayed";let r=new URL((await I()).endSessionEndpoint);return r.searchParams.set("id_token_hint",e),r.searchParams.set("post_logout_redirect_uri",t),_(r.toString()),"redirected"}async function z(t,e={}){let r=await L();if(!r)throw new m("Not logged in",{code:"NOT_LOGGED_IN"});let{graphql:o}=await I(),n=f=>fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:f},body:JSON.stringify({query:t,variables:e})}),s=await n(r);s.status===401&&d?.refresh&&(d.expiresAt=0,s=await n(await L()??""));let a=await b(s),c=Array.isArray(a.errors)?a.errors:[];if(!s.ok||c.length){let f=c.map(k=>x(k)?l(k.message):null).filter(Boolean);throw new m(f.join(" | ")||`Customer accounts: ${s.status}`,{status:s.status})}return a.data}async function kt(){return O||(O=(await z(lt)).customer,O)}function Et(){O=null}var A=null;function y(){let t=i.account?.server;return t?new URL(t,window.location.href).href.replace(/\/$/,""):""}async function U(t,{method:e="GET",body:r}={}){let o={method:e,credentials:"include"};e==="POST"&&(o.headers={"Content-Type":"application/json","X-Tether-Account":"1"}),r&&(o.body=JSON.stringify(r));let n=await fetch(`${y()}${t}`,o);if(n.status===401)return{kind:"logged-out"};let s=await b(n);if(!n.ok){let a=l(s.error)??String(n.status),c=Array.isArray(s.userErrors)?s.userErrors:void 0;throw new m(`Customer accounts: ${a}`,{status:n.status,...c&&{userErrors:c}})}return{kind:"answer",data:s}}function ue(t){let e=x(t)?t:{},r=e.address;return{firstName:l(e.firstName),lastName:l(e.lastName),displayName:l(e.displayName),email:l(e.email),address:Array.isArray(r)?r.filter(o=>typeof o=="string"):null}}async function V(){if(!A){let t=await U("/me");A=t.kind==="answer"&&t.data.loggedIn===!0?{loggedIn:!0,customer:ue(t.data.customer)}:{loggedIn:!1}}return X(A.loggedIn),A}var St=()=>A?.loggedIn===!0;function _t(){A=null}function At({returnTo:t,locale:e}){let r=new URL(`${y()}/login`);r.searchParams.set("returnTo",t);let o=F(e);o&&r.searchParams.set("locale",o);let n=G();n&&r.searchParams.set("country",n),_(r.toString())}async function Ct(){let t=g.id();if(!(await V()).loggedIn||!t)return null;let e=await U("/cart",{method:"POST",body:{cartId:t}});if(e.kind==="logged-out")return null;let r=l(e.data.checkoutUrl);return r?`${r}${r.includes("?")?"&":"?"}logged_in=true`:null}async function bt(t){let e=await U("/logout",{method:"POST",body:{returnTo:t,cartId:g.id()}});A=null,X(!1),E("account-logout",{});let r=e.kind==="answer"?l(e.data.logoutUrl):null;return r?(_(r),"redirected"):"stayed"}var le=window.Tether.__core["shopify-values.js"],{STORE_ENV_NAMES:qr,formatMoney:Mr,isHttpsUrl:It,isSecretShopifyToken:Br,productKey:Jr,productUrl:Kr}=le;function Ot(t){try{return new Date(t).toLocaleDateString(i.locale)}catch(e){if(e instanceof RangeError)return t;throw e}}function Lt(t){let e=i.account?.orderUrl;if(e){let r=t.id.split("/").pop()?.split("?")[0]??"";return e.replace("{id}",encodeURIComponent(r))}return It(t.statusPageUrl)?t.statusPageUrl??null:null}function $(t,e,r){p(t,u(e)).forEach(o=>{let n=h(o,e)??"";Object.hasOwn(r,n)&&P(o,r[n]===!0)})}var Ut=(t,e)=>p(t,u(e)).concat(t.matches(u(e))?[t]:[]);var N=(t,e)=>Object.hasOwn(t,e)?t[e]:void 0;var de=(t,e)=>({title:t.title||t.name,"variant-title":t.variantTitle||"",quantity:String(t.quantity),price:R(t.price),total:R(t.totalPrice),sku:t.sku||"",returnable:e===null?void 0:String(e)}),fe=t=>t.tagName==="INPUT";function me(t,e,r){$(t,"order-line-show",{returnable:r>0}),p(t,u("return-quantity")).forEach(o=>{fe(o)&&(o.max=String(r),o.min="0",o.value||(o.value="0"),o.disabled=r<1)}),p(t,`select${u("return-reason")}`).forEach(o=>{o.dataset.tetherFilled!==e.id&&(o.dataset.tetherFilled=e.id,(e.suggestedReturnReasonDefinitions?.nodes??[]).forEach(n=>{o.appendChild(new Option(n.name,n.id))}))})}function Nt(t,e,r){j(t,e,(o,n)=>{let s=n.id,a=r&&s?r.get(s)??0:null;s&&(o.dataset.tetherLine=s);let c=de(n,a);Ut(o,"order-line").forEach(f=>{let k=h(f,"order-line")??"";if(k==="image"){n.image&&q(f,n.image.url,n.image.altText||n.title);return}let v=N(c,k);v!==void 0&&C(f,v)}),s&&a!==null&&me(o,{...n,id:s},a)})}var Rt=10,pe=t=>({name:t.name,date:Ot(t.processedAt),total:R(t.totalPrice),status:t.financialStatus?.toLowerCase(),fulfillment:t.fulfillmentStatus?.toLowerCase(),items:t.lineItems.nodes.map(e=>`${e.quantity}\xD7 ${e.title}`).join(", ")});function ge(t,e){let r=e.lineItems.nodes,o=Lt(e),n=pe(e);p(t,u("order-bind")).forEach(s=>{let a=h(s,"order-bind")??"";if(a==="url"){o&&s.setAttribute("href",o);return}if(a==="image"){let f=r.find(k=>k.image)?.image;f&&q(s,f.url,f.altText||r[0]?.title||"");return}let c=N(n,a);c!==void 0&&C(s,c)}),p(t,u("order-lines")).forEach(s=>{Nt(s,r,null)}),h(t,"order-bind")==="url"&&o&&t.setAttribute("href",o)}async function Pt(t,e){let r=p(t,u("orders")),o=r[0];if(!o)return;$(t,"show",{"orders-loading":!0,"orders-empty":!1});let n=Number.parseInt(h(o,"limit")||String(Rt),10)||Rt,s=await e(n).catch(a=>(w(a,"orders"),null));$(t,"show",{"orders-loading":!1,"orders-empty":s?.length===0}),r.forEach(a=>{j(a,s??[],ge)})}var we=["order","addresses","subscriptions","profile-form","address-form"];function jt(){return y()?St():et()}async function qt({returnTo:t=window.location.href,locale:e}={}){y()?At({returnTo:t,locale:e}):await ht({returnTo:t,locale:e})}async function Mt(t,e={}){if(y())throw new m("Customer accounts in server mode only answer customer() and orders()",{code:"NOT_ALLOWED"});return z(t,e)}async function st(){if(!y())return kt();let t=await V();return t.loggedIn?{...t.customer,emailAddress:{emailAddress:t.customer.email},defaultAddress:{formatted:t.customer.address}}:null}async function Bt({first:t=10}={}){if(y()){let r=await U(`/orders?first=${t}`);if(r.kind==="logged-out")return[];let o=r.data.orders;return Array.isArray(o)?o:[]}return(await z(dt,{first:t})).customer?.orders.nodes??[]}async function Jt({returnTo:t=i.account?.logoutUrl||`${window.location.origin}/`}={}){(y()?await bt(t):await Tt(t))==="stayed"&&await it(document)}async function he(){try{return y()?(await V()).loggedIn?{kind:"logged-in"}:{kind:"logged-out"}:et()||await L()?{kind:"logged-in"}:{kind:"logged-out"}}catch(t){return{kind:"unknown",error:t}}}var Dt=t=>we.some(e=>p(t,u(e)).length>0);function ye(t){let e=i.account;p(t,u("account-link")).forEach(r=>{let o=h(r,"account-link"),n=e?.subscriptionsUrl,s=o==="payment"&&(e?.paymentUrl||n)||o==="subscriptions"&&n;r.setAttribute("href",s||`https://${i.domain}/account`)})}async function it(t=document){let e=await he();e.kind==="unknown"&&w(e.error,"account");let r=e.kind==="logged-in";if(p(t,u("show")).forEach(o=>{let n=h(o,"show");n==="logged-in"&&P(o,r),n==="logged-out"&&P(o,!r)}),ye(t),e.kind==="unknown"&&Dt(t)){(await T()).showUnavailable(t);return}r&&(await Kt(t),await Promise.all([Pt(t,o=>Bt({first:o})),Dt(t)?T().then(o=>o.renderPages(t)):null]))}async function Kt(t){let e=p(t,u("account-bind"));if(!e.length)return;let r=await st().catch(n=>(w(n,"account"),null)),o={"first-name":r?.firstName,"last-name":r?.lastName,name:r?.displayName,email:r?.emailAddress?.emailAddress,address:r?.defaultAddress?.formatted?.join(", ")};e.forEach(n=>{let s=N(o,h(n,"account-bind")??"");s!=null&&C(n,s)})}var $t=null;function T(){return $t??($t=ut("account-pages").then(t=>(t.setup({serverBase:y,serverFetch:U,query:Mt,customer:st,bindCustomer:Kt,reset:()=>{Et(),_t()}}),t))),$t}var xe=t=>T().then(e=>e.order(t)),Te=t=>T().then(e=>e.updateProfile(t)),ke=()=>T().then(t=>t.addresses()),Ee=(t,e)=>T().then(r=>r.saveAddress(t,e)),Se=t=>T().then(e=>e.deleteAddress(t)),_e=()=>T().then(t=>t.subscriptions()),Ae=(t,e)=>T().then(r=>r.subscriptionAction(t,e)),Ce=(t,e)=>T().then(r=>r.requestReturn(t,e));function be(t){let e=t.target;e instanceof window.Element&&(e.closest(u("account-login"))?(t.preventDefault(),qt().catch(r=>{w(r,"login")})):e.closest(u("account-logout"))&&(t.preventDefault(),Jt().catch(r=>{w(r,"logout")})))}function Ie(){let t=new URL(window.location.href);t.searchParams.get("account")&&(t.searchParams.delete("account"),window.history.replaceState(window.history.state,"",t),E("account-login",{})),g.setCustomer({beforeCheckout:Ct})}async function Oe(){try{await ot()}catch(t){w(t,"login")}if(!g.customerAccessToken)try{let t=await L();t&&g.setCustomer({accessToken:t})}catch(t){w(t,"account")}}var vt=!1;async function Le(t=document){vt||(vt=!0,document.addEventListener("click",be),y()?Ie():await Oe(),ct("account",jt()?"logged in":"logged out")),await it(t)}var{Tether:Ft}=window;if(!Ft)throw new Error("tether.account.js runs after the Tether script, which loads it");Ft.__parts.account=at;})();
|