@occluze/tether 0.9.3 → 0.9.5
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 +1 -1
- package/dist/esm/astro.js +1 -1
- package/dist/esm/chunks/account-3CDDXYNB.js +1 -0
- package/dist/esm/chunks/{account-pages-OZHK5HHY.js → account-pages-OWJGEQ4R.js} +1 -1
- package/dist/esm/chunks/{analytics-QHX2YHZS.js → analytics-HOGB5FTF.js} +1 -1
- package/dist/esm/chunks/{chunk-NF5H2Q7V.js → chunk-646NGAEM.js} +1 -1
- package/dist/esm/chunks/chunk-7BUJ3442.js +1 -0
- package/dist/esm/chunks/{chunk-ZB4FBE6W.js → chunk-DO7NXPVP.js} +1 -1
- package/dist/esm/chunks/{chunk-SOLTIZAI.js → chunk-F3OXGENC.js} +1 -1
- package/dist/esm/chunks/{chunk-A3GZFAB3.js → chunk-FRJ3O7I3.js} +1 -1
- package/dist/esm/chunks/{chunk-WHNUPECA.js → chunk-GZIUGZVZ.js} +1 -1
- package/dist/esm/chunks/{chunk-74SGIWQE.js → chunk-HMSUZ3KF.js} +1 -1
- package/dist/esm/chunks/chunk-P2CFLEGO.js +1 -0
- package/dist/esm/chunks/chunk-RBXZXOSD.js +1 -0
- package/dist/esm/chunks/{chunk-GCGRUVYO.js → chunk-RGDDFRKU.js} +1 -1
- package/dist/esm/chunks/{chunk-LSB7RVRZ.js → chunk-RULKN77R.js} +1 -1
- package/dist/esm/chunks/chunk-SKYDS3DT.js +1 -0
- package/dist/esm/chunks/chunk-TMPLGTXB.js +1 -0
- package/dist/esm/chunks/{chunk-RVWHBZAF.js → chunk-YLQXC6QC.js} +1 -1
- package/dist/esm/chunks/chunk-YW3ZIFWB.js +1 -0
- package/dist/esm/chunks/chunk-YYWS6QKJ.js +1 -0
- package/dist/esm/chunks/{diagnose-O3QCZTHT.js → diagnose-ULHFOMN5.js} +1 -1
- package/dist/esm/chunks/extras-FTL2WPUG.js +1 -0
- package/dist/esm/chunks/lists-OFICUJ4T.js +1 -0
- package/dist/esm/chunks/{markets-ui-V2ROBFZP.js → markets-ui-CZ6DAHEE.js} +1 -1
- package/dist/esm/chunks/search-U2KQ54KS.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/tether.account-pages.js +1 -1
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +16 -13
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +1 -1
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +1 -1
- package/dist/tether.diagnose.min.js +1 -1
- package/dist/tether.extras.js +32 -10
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +165 -88
- package/dist/tether.lists.js +1 -1
- package/dist/tether.lists.min.js +1 -1
- package/dist/tether.markets.js +1 -1
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +1 -1
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +56 -17
- package/dist/tether.search.min.js +1 -1
- package/dist/types/src/account/server-client.d.ts +2 -1
- package/dist/types/src/analytics-queue.d.ts +9 -0
- package/dist/types/src/cart/checkout.d.ts +2 -2
- package/dist/types/src/cart/drawer.d.ts +9 -4
- package/dist/types/src/cart/store.d.ts +2 -0
- package/dist/types/src/cart.d.ts +1 -1
- package/dist/types/src/client.d.ts +6 -0
- package/dist/types/src/dom.d.ts +14 -1
- package/dist/types/src/extras.d.ts +2 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/search.d.ts +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/chunks/account-3MYRPPTR.js +0 -1
- package/dist/esm/chunks/chunk-24KD36UC.js +0 -1
- package/dist/esm/chunks/chunk-2G6U6ZYV.js +0 -1
- package/dist/esm/chunks/chunk-A6BZFYZY.js +0 -1
- package/dist/esm/chunks/chunk-EYG7QGPA.js +0 -1
- package/dist/esm/chunks/chunk-FX7EJ6RB.js +0 -1
- package/dist/esm/chunks/chunk-PZERNTCD.js +0 -1
- package/dist/esm/chunks/chunk-SJNNEEDX.js +0 -1
- package/dist/esm/chunks/extras-O6ZRL5FK.js +0 -1
- package/dist/esm/chunks/lists-XF33XENI.js +0 -1
- package/dist/esm/chunks/search-ZLKIFARH.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as E,c as P,d as k,e as T,f as p,g as A}from"./chunk-
|
|
1
|
+
import{a as E,c as P,d as k,e as T,f as p,g as A}from"./chunk-TMPLGTXB.js";import{a as I}from"./chunk-YYWS6QKJ.js";import{d as F,e as x}from"./chunk-DO7NXPVP.js";import"./chunk-SKYDS3DT.js";import{h as u}from"./chunk-7BUJ3442.js";import"./chunk-F3OXGENC.js";import"./chunk-646NGAEM.js";import"./chunk-RBXZXOSD.js";import"./chunk-RULKN77R.js";import{e as w}from"./chunk-YLQXC6QC.js";import"./chunk-GZIUGZVZ.js";import{a as L,d as h,i as b,m as s,n as C,o as v,u as z}from"./chunk-P2CFLEGO.js";import{F as y,o as f,p as g,x as a}from"./chunk-YW3ZIFWB.js";var _="{name} ({currency})",j="name",d=null;function B(){d=null}var D="query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}",O={isoCode:"string",name:"string",currency:"object"},H=h({localization:{country:O,availableCountries:[O]}});function R(){return d??(d=b(D,{},H).then(e=>e.localization,e=>{throw d=null,e})),d}function U(e,n){switch(n){case"name":return e.name;case"code":return e.isoCode;case"currency":return e.currency.isoCode;case"symbol":return e.currency.symbol;default:return""}}var Y=(e,n)=>e.replace(/\{(name|code|currency|symbol)\}/g,(o,i)=>U(n,i));function q(e,n,o){let i=e.getAttribute(s("country-label"))||_,r=(e.getAttribute(s("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),c=r.length?r.map(t=>n.find(l=>l.isoCode===t)).filter(t=>t!==void 0):n;e.replaceChildren(...c.map(t=>new Option(Y(i,t),t.isoCode))),e.value=o,e.value!==o&&(e.selectedIndex=-1),e.disabled=c.length<2&&!e.hasAttribute(s("always-enabled"))}function $(e,n,o){let i=(a.country||o.country.isoCode).toUpperCase(),r=[...o.availableCountries].sort((t,l)=>t.name.localeCompare(l.name,a.locale||void 0)),c=r.find(t=>t.isoCode===i)??o.country;e.forEach(t=>{q(t,r,i)}),n.forEach(t=>{t.textContent=U(c,v(t,"country-bind")||j)})}function S(e=document){let n=p(e,`select${C("country-select")}`),o=p(e,C("country-bind"));return!n.length&&!o.length?Promise.resolve():R().then(i=>{$(n,o,i)}).catch(i=>{y(i,"country select")})}var Q=e=>Object.values(a.markets?.locales??{}).find(n=>f(n.country)===e);function V(e,n){return e!==void 0?g(e):n?n.language?g(n.language):void 0:a.language}function Z(e){w();let n=[];return u.id()&&n.push(u.setBuyerIdentity({countryCode:e},{create:!1}).catch(o=>{y(o,"cart country")})),T(),k.forEach(o=>n.push(o.load())),P.forEach(o=>{o.closest(I())||(E.delete(o),A(o))}),n}async function re(e,{language:n,locale:o,remember:i=!0}={}){let r=f(e);if(!r)throw new L(`Not a country code: ${e}`,{code:"INVALID_COUNTRY"});let c=Q(r),t=o||c?.locale,l=t||a.locale,m=V(n,c),M=r!==a.country||m!==a.language||l!==a.locale;if(a.country=r,a.language=m||void 0,a.locale=l,i&&x({country:r,language:m,locale:t}),!M)return S(),u.state;n!==void 0&&B();let N=Z(r);return S(),z("country-changed",{country:r,language:a.language}),await Promise.all(N),u.state}export{F as detectMarket,R as getLocalization,S as renderCountrySelects,re as setCountry};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as k}from"./chunk-TMPLGTXB.js";import"./chunk-YYWS6QKJ.js";import"./chunk-SKYDS3DT.js";import"./chunk-7BUJ3442.js";import"./chunk-F3OXGENC.js";import"./chunk-646NGAEM.js";import"./chunk-RBXZXOSD.js";import"./chunk-RULKN77R.js";import"./chunk-YLQXC6QC.js";import"./chunk-GZIUGZVZ.js";import{B as q,D as v,G as R,I as d,R as p,c as T,d as I,i as L,m as w,n as o,o as m,q as h,u as x,x as C,z as M}from"./chunk-P2CFLEGO.js";import{D as E,F as A,b as s,x as u}from"./chunk-YW3ZIFWB.js";var U=I({predictiveSearch:T({products:[{priceRange:"object"}],collections:["object"],queries:[{text:"string"}]})}),D="query TetherPredictive($q:String!,$limit:Int!){predictiveSearch(query:$q,limit:$limit,limitScope:EACH,types:[PRODUCT,COLLECTION,QUERY]){products{id handle title availableForSale featuredImage{url altText}priceRange{minVariantPrice{amount currencyCode}}}collections{handle title image{url altText}}queries{text}}}",V=6,F=10,O=2,_="/search",g=new WeakSet,$=0,b=new Set,P=a=>a.tagName==="A"?a:a.querySelector("a");function f(a,t){h(a,o("search-bind")).forEach(e=>{let i=m(e,"search-bind");i==="image"?C(e,t.image?.url,t.image?.altText||t.title):(i==="title"||i==="price"||i==="text")&&t[i]!=null&&R(e,t[i])})}function H(a,t){let e=P(a);e&&(t&&e.setAttribute("href",t),e.setAttribute("role","option"))}var y=class{constructor(t,e,i){s(this,"root");s(this,"input");s(this,"results");s(this,"limit");s(this,"minCharacters");s(this,"resultsId");s(this,"searchNumber",0);s(this,"timer");s(this,"lastTerm","");s(this,"cache",new Map);s(this,"listening",new window.AbortController);this.root=t,this.input=e,this.results=i,this.limit=p(t,"search-limit",{min:1,max:F,fallback:V}),this.minCharacters=p(t,"search-min",{min:1,fallback:O}),i.id||($+=1,i.id=`${u.prefix}-search-${$}`),this.resultsId=i.id,this.setUpAria(),this.listen(),b.add(this)}stop(){this.listening.abort(),clearTimeout(this.timer),b.delete(this),g.delete(this.root)}setUpAria(){this.input.setAttribute("role","combobox"),this.input.setAttribute("aria-autocomplete","list"),this.input.setAttribute("aria-controls",this.resultsId),this.input.setAttribute("aria-expanded","false"),this.input.setAttribute("autocomplete","off"),this.results.hasAttribute("role")||this.results.setAttribute("role","listbox"),this.results.hidden=!0}listen(){let{signal:t}=this.listening;this.input.addEventListener("input",()=>{let e=this.input.value.trim();e!==this.lastTerm&&(this.lastTerm=e,clearTimeout(this.timer),this.timer=setTimeout(()=>void this.search(e),u.searchDelay))},{signal:t}),this.input.addEventListener("focus",()=>{this.input.value.trim().length>=this.minCharacters&&this.options().length&&this.open(!0)},{signal:t}),this.input.addEventListener("keydown",e=>{this.onKeydown(e)},{signal:t}),document.addEventListener("click",e=>{if(!this.root.isConnected){this.stop();return}this.root.contains(e.target)||this.open(!1)},{signal:t})}setState(t){this.root.setAttribute(w("search-state"),t)}open(t){this.root.classList.toggle("is-open",t),this.results.hidden=!t,this.input.setAttribute("aria-expanded",String(t)),t||this.input.removeAttribute("aria-activedescendant")}options(){return h(this.results,'[role="option"]')}async fetchResults(t){let e=this.cache.get(t);if(e)return e;let i=await L(D,{q:t,limit:this.limit},U);return this.cache.set(t,i.predictiveSearch),i.predictiveSearch}async search(t){this.searchNumber+=1;let e=this.searchNumber;if(t.length<this.minCharacters){this.open(!1),this.setState("idle");return}this.setState("loading");try{let i=await this.fetchResults(t);e===this.searchNumber&&this.render(i,t)}catch(i){if(e!==this.searchNumber){E("a superseded search failed",i);return}this.setState("error"),A(i,"search")}}fillList(t,e,i){h(this.results,o(t)).forEach(l=>{M(l,e,i),d(l,e.length>0)})}queryUrl(t){let e=this.root.getAttribute("action")||_,i=e.includes("?")?"&":"?";return`${e}${i}${this.input.name||"q"}=${encodeURIComponent(t)}`}render(t,e){let i=t?.products??[],l=t?.collections??[],c=(t?.queries??[]).filter(n=>n.text.toLowerCase()!==e.toLowerCase());this.fillList("search-products",i,(n,r)=>{let N=v(r.priceRange.minVariantPrice);f(n,{title:r.title,price:N,image:r.featuredImage}),H(n,q(r.handle,r.id)),n.classList.toggle("is-sold-out",!r.availableForSale)}),this.fillList("search-collections",l,(n,r)=>{f(n,{title:r.title,image:r.image}),H(n,`${(u.collectionPath||"/collection").replace(/\/$/,"")}/${r.handle}`)}),this.fillList("search-queries",c,(n,r)=>{f(n,{text:r.text}),P(n)?.setAttribute("href",this.queryUrl(r.text))});let S=i.length+l.length+c.length;this.showCount(S),this.setState(S?"ready":"empty"),this.open(!0),x("search",{term:e,products:i,collections:l,queries:c},this.root)}showCount(t){h(this.root,o("show")).forEach(e=>{let i=m(e,"show");i==="search-empty"&&d(e,t===0),i==="search-results"&&d(e,t>0)}),this.options().forEach((e,i)=>{e.id||(e.id=`${this.resultsId}-${i}`),e.setAttribute("aria-selected","false")}),this.input.removeAttribute("aria-activedescendant")}highlight(t,e){t.forEach((l,c)=>{l.setAttribute("aria-selected",String(c===e))});let i=t[e];i&&(this.input.setAttribute("aria-activedescendant",i.id),i.scrollIntoView?.({block:"nearest"}))}onKeydown(t){let e=this.options(),i=e.findIndex(l=>l.getAttribute("aria-selected")==="true");t.key==="ArrowDown"&&e.length?(t.preventDefault(),this.open(!0),this.highlight(e,(i+1)%e.length)):t.key==="ArrowUp"&&e.length?(t.preventDefault(),this.highlight(e,i<=0?e.length-1:i-1)):t.key==="Enter"&&i>=0?(t.preventDefault(),e[i]?.click()):t.key==="Escape"&&this.open(!1)}};function Y(a=document){b.forEach(t=>{t.root.isConnected||t.stop()});for(let t of k(a,o("search"))){if(g.has(t))continue;g.add(t);let e=t.querySelector(o("search-input"))??t.querySelector("input"),i=t.querySelector(o("search-results"));e&&i&&new y(t,e,i)}}export{Y as mountSearch};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as st,b as at,c as ct}from"./chunks/chunk-74SGIWQE.js";import{b as C,d as w,e as T,f as p,g as et,h as nt,i as ot,j as k,k as S}from"./chunks/chunk-EYG7QGPA.js";import{a as lt,b as dt}from"./chunks/chunk-24KD36UC.js";import{a as rt,b as it,c as h}from"./chunks/chunk-A3GZFAB3.js";import"./chunks/chunk-ZB4FBE6W.js";import{a as tt}from"./chunks/chunk-2G6U6ZYV.js";import{a as z,e as X,h as s}from"./chunks/chunk-FX7EJ6RB.js";import"./chunks/chunk-SOLTIZAI.js";import{l as Q}from"./chunks/chunk-NF5H2Q7V.js";import{a as u,b as ut}from"./chunks/chunk-SJNNEEDX.js";import{b as Z}from"./chunks/chunk-LSB7RVRZ.js";import{a as K,b as W,c as Y,e as J}from"./chunks/chunk-RVWHBZAF.js";import"./chunks/chunk-WHNUPECA.js";import{C as q,J as P,M as f,a as v,f as G,j as U,l as d,m as r,r as B,s as g,t as y,u as j}from"./chunks/chunk-A6BZFYZY.js";import{B as F,C as E,D as L,E as _,F as a,e as $,x as c,y as V}from"./chunks/chunk-PZERNTCD.js";var x="0.9.3";var Mt=["account-login","account-bind","account-link","orders","order","addresses","subscriptions","profile-form","address-form"],It=()=>[...Mt.map(t=>`[${d(t)}]`),`[${d("show")}^="logged-"]`].join(",");function Nt(){return!!X(st())}function mt(t){!c.account||!(p(t,It()).length>0||ct(new URLSearchParams(window.location.search).get("account"))||Nt())||u("account").then(n=>n.mountAccount(t)).catch(n=>{a(n,"account")})}function l(t){return(...e)=>u("account").then(n=>{let o=n[t];return o(...e)})}var ft={login:l("login"),logout:l("logout"),isLoggedIn:l("isLoggedIn"),customer:l("customer"),orders:l("orders"),order:l("order"),updateProfile:l("updateProfile"),addresses:l("addresses"),saveAddress:l("saveAddress"),deleteAddress:l("deleteAddress"),subscriptions:l("subscriptions"),subscriptionAction:l("subscriptionAction"),requestReturn:l("requestReturn"),render:l("render"),mountAccount:l("mountAccount")};var pt=()=>`data-${c.prefix}-key`,yt=t=>t instanceof window.Element;function ht(t){let e=t.closest(`[${pt()}]`),n=e?.getAttribute(pt());return e&&n?{line:e,id:n}:null}function A(t,e){t.catch(n=>{a(n,e)})}function Ot(t,e){let n=ht(e);if(!n?.line.closest(r("cart-lines")))return;let{line:o,id:i}=n;if(e.closest(r("line-remove"))){t.preventDefault(),o.classList.add("is-busy"),A(s.removeLine(i),"cart line");return}let H=Dt(e);!H||!s.lines.some(xt=>xt.id===i)||(t.preventDefault(),A(s.changeQuantity(i,H),"cart line"))}function Dt(t){return t.closest(r("line-plus"))?1:t.closest(r("line-minus"))?-1:0}function Rt(t){let{target:e}=t;if(!yt(e))return;if(e.closest(r("cart-open"))){t.preventDefault(),s.toggle();return}if(e.closest(r("cart-close"))){t.preventDefault(),s.close();return}let n=e.closest(r("cart-clear"));if(n){t.preventDefault(),f(n,()=>s.clear().catch(i=>{a(i,"cart clear")}));return}let o=e.closest(r("checkout"));if(o){t.preventDefault(),f(o,()=>s.checkout());return}Ot(t,e)}function gt(t,e,n){t.classList.add("is-busy"),t.setAttribute("aria-busy","true"),A(e,n)}function Ht(t){let{target:e}=t;if(!yt(e))return;let n=ht(e);n&&e instanceof window.HTMLInputElement&&e.matches(r("line","quantity"))?gt(n.line,s.updateLine(n.id,parseInt(e.value,10)||0),"cart line"):n&&e instanceof window.HTMLSelectElement&&e.matches(r("line-plan"))?gt(n.line,s.updateLine(n.id,{sellingPlanId:e.value||null}),"cart line plan"):$t(e)&&e.matches(r("cart-note"))&&A(s.setNote(e.value),"cart note")}var $t=t=>t instanceof window.HTMLInputElement||t instanceof window.HTMLTextAreaElement||t instanceof window.HTMLSelectElement;function Vt(t){if(s.isOpen()){if(t.key==="Escape"){s.close();return}z(t)}}function Et(){document.addEventListener("click",Rt),document.addEventListener("change",Ht),document.addEventListener("keydown",Vt)}var M=t=>t instanceof window.Element;function Ft(t){let e=t.querySelector(r("discount-input"))??t.querySelector("input");return e instanceof window.HTMLInputElement?e:null}function vt(t,e,n){t.classList.toggle("is-invalid",n),n?e?.setAttribute("aria-invalid","true"):e?.removeAttribute("aria-invalid")}async function _t(t,e,n){try{await s.applyDiscount(n),vt(t,e,!1),y("discount-applied",{code:n},t),e&&(e.value="")}catch(o){vt(t,e,!0),o instanceof v&&o.code==="INVALID_DISCOUNT"?y("discount-invalid",{code:n},t):a(o,"discount")}}function Gt(t){let{target:e}=t,n=M(e)?e.closest(r("discount-form")):null;if(!n)return;t.preventDefault();let o=Ft(n),i=o?.value.trim();i&&f(n,()=>_t(n,o,i))}function Ut(t){let{target:e}=t;if(!M(e))return;let n=e.closest(r("discount-form"));n&&(n.classList.remove("is-invalid"),e.removeAttribute("aria-invalid"))}function Bt(t){let{target:e}=t,n=M(e)?e.closest(r("discount-remove")):null;if(!n)return;t.preventDefault();let o=n.closest(r("discount-code"))?.getAttribute(d("discount-code"));o&&s.removeDiscount(o).catch(i=>{a(i,"discount")})}function Pt(){document.addEventListener("submit",Gt,!0),document.addEventListener("input",Ut),document.addEventListener("click",Bt)}var I=t=>u("extras").then(e=>e.addGroup(t)),N=t=>{a(t,"extras")};function jt(t){let{target:e}=t,n=e instanceof window.Element?e.closest(r("group-add")):null;n&&(t.preventDefault(),f(n,()=>I(n)).catch(N))}function qt(t){!c.domain||!t.key?.startsWith(`${c.prefix}:`)||u("extras").then(e=>{e.onStorage(t)}).catch(N)}function Qt(t){if(!g(t,"variant-changed"))return;let{target:e}=t;e instanceof window.Element&&(!c.variantUrl&&!e.hasAttribute(d("variant-url"))||u("extras").then(n=>{n.writeVariantUrl(e,t.detail)}).catch(N))}function wt(){document.addEventListener("click",jt),window.addEventListener("storage",qt),document.addEventListener(`${c.prefix}:variant-changed`,Qt)}var O=null;function At(){O=document.body}async function zt(t){await t.ready();let e=it();if(!e){O!==document.body&&t.mount(document);return}try{await h(e.country,{language:e.language??null,locale:e.locale,remember:!1})}catch(n){a(n,"country")}t.mount(document)}function Kt(t){document.addEventListener("astro:page-load",()=>{zt(t).catch(e=>{a(e,"page mount")})}),document.addEventListener("astro:before-swap",()=>{O=null,t.unmount()})}function Wt(t){let{target:e}=t;!(e instanceof window.HTMLSelectElement)||!e.matches(r("country-select"))||e.value&&h(e.value).catch(n=>{a(n,"country")})}function Yt(){nt(),w.forEach(t=>{t.root.getAttribute(d("state"))==="error"&&t.load()})}function bt(t){c.astro&&Kt(t),document.addEventListener("change",Wt),window.addEventListener("online",Yt)}var Jt=50;function Xt(){let t=P("TETHER_CONFIG");return typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t)):{}}var m=null,D=null,Ct=null,Lt=!1;function Zt(t){let e=0;return p(t,lt()).forEach(n=>{if(C.has(n))return;C.add(n),e++;let o=dt(n);w.add(o),n.addEventListener(`${c.prefix}:list-rendered`,i=>{g(i,"list-rendered")&&b(i.detail.container)}),ot(o.load())}),e}function te(t){p(t,`${r("country-select")},${r("country-bind")}`).length&&u("markets").then(e=>e.renderCountrySelects(t)).catch(e=>{a(e,"markets")}),mt(t),p(t,r("search")).length&&u("search").then(e=>{e.mountSearch(t)}).catch(e=>{a(e,"search")})}function Tt(t){let e=Zt(t);return p(t,r("product")).forEach(n=>{et(n)&&e++}),te(t),e}function b(t=document){if(!E())return 0;t===document&&At(),T(),S(t.ownerDocument??document);let e=Tt(t);return k(),s.render(),L(`mounted ${e} scope(s)`,t),e}function ee(t){let e=t.filter(o=>o.isConnected&&!t.some(i=>i!==o&&i.contains(o)));if(!e.length||!E())return;T(),e.forEach(o=>{S(o)});let n=e.reduce((o,i)=>o+Tt(i),0);k(),s.render(),L(`mounted ${n} scope(s) in ${e.length} added element(s)`)}function kt(){s.close()}function ne(t){let e=t?.closest(r("product"));return e?tt.get(e)??null:null}function oe(){Lt||(Lt=!0,Et(),Pt(),wt(),bt({ready:()=>m??Promise.resolve(null),mount:b,unmount:kt}))}function re(){let t=[];Ct=t,B.forEach(e=>{document.addEventListener(`${c.prefix}:${e}`,n=>t.push(n))}),document.addEventListener("astro:page-load",e=>t.push(e)),u("analytics").then(e=>e.startAnalytics(t)).catch(e=>{a(e,"analytics")})}async function ie(t){let e=c.country,n=t?.buyerIdentity.countryCode;if(!t||!e||!n||n===e)return t;try{return await s.setBuyerIdentity({countryCode:e},{create:!1})}catch(o){return a(o,"cart country"),t}}function St(t={}){return m&&!Object.keys(t).length?m:(F({...Xt(),...t}),E()?(at(),oe(),c.observe&&se(),c.analytics&&!Ct&&re(),m=rt(t).then(()=>s.init()).then(ie).then(e=>(y("ready",{cart:e}),R)),m):(_("TETHER_CONFIG is missing domain or token. Tether is idle."),m=Promise.resolve(null),m))}function se(){if(D||typeof MutationObserver>"u")return;let t,e=new Set;D=new MutationObserver(n=>{n.forEach(o=>{o.addedNodes.forEach(i=>{i instanceof window.Element&&e.add(i)})}),clearTimeout(t),t=setTimeout(()=>{let o=[...e];e.clear(),ee(o)},Jt)}),D.observe(document.body,{childList:!0,subtree:!0})}var ae=t=>u("markets").then(e=>e.detectMarket(t??c.markets)),ce=t=>u("lists").then(e=>e.getProducts(t)),ue=(t,e)=>u("lists").then(n=>n.getRecommendations(t,e)),le=()=>u("markets").then(t=>t.getLocalization()),de=t=>u("diagnose").then(e=>e.diagnose({...t,version:x}));function me(t,e){let n=`${c.prefix}:${t}`,o=i=>{g(i,t)&&e(i.detail,i)};return document.addEventListener(n,o),()=>{document.removeEventListener(n,o)}}var fe={VERSION:x,init:St,mount:b,unmount:kt,get config(){return V},get ready(){return m??Promise.resolve(null)},query:U,withContext:G,cart:s,getProduct:Y,getProducts:ce,getRecommendations:ue,getScope:ne,addGroup:I,account:ft,primeProduct:W,normalizeProductKey:K,clearProductCache:J,formatMoney:q,imageUrl:j,plans:Q,TetherError:v,resolveProductKey:Z,setCountry:h,detectMarket:ae,getLocalization:le,diagnose:de,on:me},pe={__core:ut,__parts:{}},R=Object.assign(fe,pe),cn=R;function ge(){Reflect.set(window,"Tether",R);let t=P("TETHER_CONFIG");if(!t||$(t,"autoMount")===!1||P("TETHER_INTEGRATION"))return;let e=()=>{St().then(()=>b(document)).catch(n=>{a(n,"init")})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}typeof window<"u"&&typeof document<"u"&&ge();export{x as VERSION,I as addGroup,R as api,cn as default,ne as getScope,St as init,b as mount,h as setCountry,kt as unmount};
|
|
1
|
+
import{a as at,b as ct,c as ut}from"./chunks/chunk-HMSUZ3KF.js";import{b as C,d as P,e as T,f as g,g as nt,h as ot,i as rt,j as L,k}from"./chunks/chunk-TMPLGTXB.js";import{a as dt,b as mt}from"./chunks/chunk-YYWS6QKJ.js";import{a as it,b as st,c as h}from"./chunks/chunk-FRJ3O7I3.js";import"./chunks/chunk-DO7NXPVP.js";import{a as et}from"./chunks/chunk-SKYDS3DT.js";import{a as K,e as Z,h as s}from"./chunks/chunk-7BUJ3442.js";import"./chunks/chunk-F3OXGENC.js";import{l as Q}from"./chunks/chunk-646NGAEM.js";import{a as u,b as lt}from"./chunks/chunk-RBXZXOSD.js";import{b as tt}from"./chunks/chunk-RULKN77R.js";import{a as W,b as X,c as Y,e as J}from"./chunks/chunk-YLQXC6QC.js";import"./chunks/chunk-GZIUGZVZ.js";import{D as j,L as v,O as p,Q as z,a as F,f as G,k as _,m,n as i,s as q,t as y,u as U,v as B}from"./chunks/chunk-P2CFLEGO.js";import{B as $,C as E,D as b,E as V,F as a,e as D,x as c,y as H}from"./chunks/chunk-YW3ZIFWB.js";function ft(t){let e=[],n=new window.AbortController,o={signal:n.signal};return q.forEach(r=>{document.addEventListener(`${c.prefix}:${r}`,d=>e.push(d),o)}),document.addEventListener("astro:page-load",r=>e.push(r),o),t().then(r=>r.startAnalytics(e)).catch(r=>{n.abort(),e.length=0,a(r,"analytics")}),e}var S="0.9.5";var Mt=["account-login","account-bind","account-link","orders","order","addresses","subscriptions","profile-form","address-form"],Nt=()=>[...Mt.map(t=>`[${m(t)}]`),`[${m("show")}^="logged-"]`].join(",");function Ot(){return!!Z(at())}function pt(t){!c.account||!(g(t,Nt()).length>0||ut(new URLSearchParams(window.location.search).get("account"))||Ot())||u("account").then(n=>n.mountAccount(t)).catch(n=>{a(n,"account")})}function l(t){return(...e)=>u("account").then(n=>{let o=n[t];return o(...e)})}var gt={login:l("login"),logout:l("logout"),isLoggedIn:l("isLoggedIn"),customer:l("customer"),orders:l("orders"),order:l("order"),updateProfile:l("updateProfile"),addresses:l("addresses"),saveAddress:l("saveAddress"),deleteAddress:l("deleteAddress"),subscriptions:l("subscriptions"),subscriptionAction:l("subscriptionAction"),requestReturn:l("requestReturn"),render:l("render"),mountAccount:l("mountAccount")};var yt=()=>`data-${c.prefix}-key`,ht=t=>t instanceof window.Element;function Et(t){let e=t.closest(`[${yt()}]`),n=e?.getAttribute(yt());return e&&n?{line:e,id:n}:null}function w(t,e){t.catch(n=>{a(n,e)})}function It(t,e){let n=Et(e);if(!n?.line.closest(i("cart-lines")))return;let{line:o,id:r}=n;if(e.closest(i("line-remove"))){t.preventDefault(),o.classList.add("is-busy"),w(s.removeLine(r),"cart line");return}let d=Rt(e);!d||!s.lines.some(xt=>xt.id===r)||(t.preventDefault(),w(s.changeQuantity(r,d),"cart line"))}function Rt(t){return t.closest(i("line-plus"))?1:t.closest(i("line-minus"))?-1:0}function Dt(t){let{target:e}=t;if(!ht(e))return;if(e.closest(i("cart-open"))){t.preventDefault(),s.toggle();return}if(e.closest(i("cart-close"))){t.preventDefault(),s.close();return}let n=e.closest(i("cart-clear"));if(n){t.preventDefault(),p(n,()=>s.clear().catch(r=>{a(r,"cart clear")}));return}let o=e.closest(i("checkout"));if(o){t.preventDefault(),p(o,()=>s.checkout());return}It(t,e)}function vt(t,e,n){t.classList.add("is-busy"),t.setAttribute("aria-busy","true"),w(e,n)}function Ht(t,{line:e,id:n}){let o=t.value.trim();if(z.test(o)){vt(e,s.updateLine(n,Number(o)),"cart line");return}let r=s.lines.find(d=>d.id===n);r&&(t.value=String(s.quantityOf(r)))}function $t(t){let{target:e}=t;if(!ht(e))return;let n=Et(e);n&&e instanceof window.HTMLInputElement&&e.matches(i("line","quantity"))?Ht(e,n):n&&e instanceof window.HTMLSelectElement&&e.matches(i("line-plan"))?vt(n.line,s.updateLine(n.id,{sellingPlanId:e.value||null}),"cart line plan"):Vt(e)&&e.matches(i("cart-note"))&&w(s.setNote(e.value),"cart note")}var Vt=t=>t instanceof window.HTMLInputElement||t instanceof window.HTMLTextAreaElement||t instanceof window.HTMLSelectElement;function Ft(t){if(s.isOpen()){if(t.key==="Escape"){s.close();return}K(t)}}function Pt(){document.addEventListener("click",Dt),document.addEventListener("change",$t),document.addEventListener("keydown",Ft)}var x=t=>t instanceof window.Element;function Gt(t){let e=t.querySelector(i("discount-input"))??t.querySelector("input");return e instanceof window.HTMLInputElement?e:null}function _t(t){let{target:e}=t,n=x(e)?e.closest(i("discount-form")):null;if(!n)return;t.preventDefault();let o=Gt(n),r=o?.value.trim();r&&p(n,()=>u("extras").then(d=>d.applyDiscountCode(n,o,r))).catch(d=>{a(d,"discount")})}function qt(t){let{target:e}=t;if(!x(e))return;let n=e.closest(i("discount-form"));n&&(n.classList.remove("is-invalid"),e.removeAttribute("aria-invalid"))}function Ut(t){let{target:e}=t,n=x(e)?e.closest(i("discount-remove")):null;if(!n)return;t.preventDefault();let o=n.closest(i("discount-code"))?.getAttribute(m("discount-code"));o&&s.removeDiscount(o).catch(r=>{a(r,"discount")})}function wt(){document.addEventListener("submit",_t,!0),document.addEventListener("input",qt),document.addEventListener("click",Ut)}var M=t=>u("extras").then(e=>e.addGroup(t)),N=t=>{a(t,"extras")};function Bt(t){let{target:e}=t,n=e instanceof window.Element?e.closest(i("group-add")):null;n&&(t.preventDefault(),p(n,()=>M(n)).catch(N))}function jt(t){!c.domain||!t.key?.startsWith(`${c.prefix}:`)||u("extras").then(e=>{e.onStorage(t)}).catch(N)}function zt(t){if(!y(t,"variant-changed"))return;let{target:e}=t;e instanceof window.Element&&(!c.variantUrl&&!e.hasAttribute(m("variant-url"))||u("extras").then(n=>{n.writeVariantUrl(e,t.detail)}).catch(N))}function At(){document.addEventListener("click",Bt),window.addEventListener("storage",jt),document.addEventListener(`${c.prefix}:variant-changed`,zt)}var O=null;function bt(){O=document.body}async function Qt(t){await t.ready();let e=st();if(!e){O!==document.body&&t.mount(document);return}try{await h(e.country,{language:e.language??null,locale:e.locale,remember:!1})}catch(n){a(n,"country")}t.mount(document)}function Kt(t){document.addEventListener("astro:page-load",()=>{Qt(t).catch(e=>{a(e,"page mount")})}),document.addEventListener("astro:before-swap",()=>{O=null,t.unmount()})}function Wt(t){let{target:e}=t;!(e instanceof window.HTMLSelectElement)||!e.matches(i("country-select"))||e.value&&h(e.value).catch(n=>{a(n,"country")})}function Xt(){ot(),P.forEach(t=>{t.root.getAttribute(m("state"))==="error"&&t.load()})}function Ct(t){c.astro&&Kt(t),document.addEventListener("change",Wt),window.addEventListener("online",Xt)}var Yt=50;function Jt(){let t=v("TETHER_CONFIG");return typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t)):{}}var f=null,I=null,Zt=null,Tt=!1;function te(t){let e=0;return g(t,dt()).forEach(n=>{if(C.has(n))return;C.add(n),e++;let o=mt(n);P.add(o),n.addEventListener(`${c.prefix}:list-rendered`,r=>{y(r,"list-rendered")&&A(r.detail.container)}),rt(o.load())}),e}function ee(t){g(t,`${i("country-select")},${i("country-bind")}`).length&&u("markets").then(e=>e.renderCountrySelects(t)).catch(e=>{a(e,"markets")}),pt(t),g(t,i("search")).length&&u("search").then(e=>{e.mountSearch(t)}).catch(e=>{a(e,"search")})}function Lt(t){let e=te(t);return g(t,i("product")).forEach(n=>{nt(n)&&e++}),ee(t),e}function A(t=document){if(!E())return 0;t===document&&bt(),T(),k(t.ownerDocument??document);let e=Lt(t);return L(),s.render(),b(`mounted ${e} scope(s)`,t),e}function ne(t){let e=t.filter(o=>o.isConnected&&!t.some(r=>r!==o&&r.contains(o)));if(!e.length||!E())return;T(),e.forEach(o=>{k(o)});let n=e.reduce((o,r)=>o+Lt(r),0);L(),s.render(),b(`mounted ${n} scope(s) in ${e.length} added element(s)`)}function kt(){s.close()}function oe(t){let e=t?.closest(i("product"));return e?et.get(e)??null:null}function re(){Tt||(Tt=!0,Pt(),wt(),At(),Ct({ready:()=>f??Promise.resolve(null),mount:A,unmount:kt}))}async function ie(t){let e=c.country,n=t?.buyerIdentity.countryCode;if(!t||!e||!n||n===e)return t;try{return await s.setBuyerIdentity({countryCode:e},{create:!1})}catch(o){return a(o,"cart country"),t}}function St(t={}){return f&&!Object.keys(t).length?f:($({...Jt(),...t}),E()?(ct(),re(),c.observe&&se(),c.analytics&&(Zt??(Zt=ft(()=>u("analytics")))),f=it(t).then(()=>s.init()).then(ie).then(e=>(U("ready",{cart:e}),R)),f):(V("TETHER_CONFIG is missing domain or token. Tether is idle."),f=Promise.resolve(null),f))}function se(){if(I||typeof MutationObserver>"u")return;let t,e=new Set;I=new MutationObserver(n=>{n.forEach(o=>{o.addedNodes.forEach(r=>{r instanceof window.Element&&e.add(r)})}),clearTimeout(t),t=setTimeout(()=>{let o=[...e];e.clear(),ne(o)},Yt)}),I.observe(document.body,{childList:!0,subtree:!0})}var ae=t=>u("markets").then(e=>e.detectMarket(t??c.markets)),ce=t=>u("lists").then(e=>e.getProducts(t)),ue=(t,e)=>u("lists").then(n=>n.getRecommendations(t,e)),le=()=>u("markets").then(t=>t.getLocalization()),de=t=>u("diagnose").then(e=>e.diagnose({...t,version:S}));function me(t,e){let n=`${c.prefix}:${t}`,o=r=>{y(r,t)&&e(r.detail,r)};return document.addEventListener(n,o),()=>{document.removeEventListener(n,o)}}var fe={VERSION:S,init:St,mount:A,unmount:kt,get config(){return H},get ready(){return f??Promise.resolve(null)},query:_,withContext:G,cart:s,getProduct:Y,getProducts:ce,getRecommendations:ue,getScope:oe,addGroup:M,account:gt,primeProduct:X,normalizeProductKey:W,clearProductCache:J,formatMoney:j,imageUrl:B,plans:Q,TetherError:F,resolveProductKey:tt,setCountry:h,detectMarket:ae,getLocalization:le,diagnose:de,on:me},pe={__core:lt,__parts:{}},R=Object.assign(fe,pe),mn=R;function ge(){Reflect.set(window,"Tether",R);let t=v("TETHER_CONFIG");if(!t||D(t,"autoMount")===!1||v("TETHER_INTEGRATION"))return;let e=()=>{St().then(()=>A(document)).catch(n=>{a(n,"init")})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}typeof window<"u"&&typeof document<"u"&&ge();export{S as VERSION,M as addGroup,R as api,mn as default,oe as getScope,St as init,A as mount,h as setCountry,kt as unmount};
|
package/dist/esm/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as Q,f as G,g as H}from"./chunks/chunk-
|
|
1
|
+
import{b as Q,f as G,g as H}from"./chunks/chunk-F3OXGENC.js";import{e as O,f as v,g as w,i as F,l as q}from"./chunks/chunk-646NGAEM.js";import{a as M,c as T,e as V,g as J,h as B,i as K,j}from"./chunks/chunk-GZIUGZVZ.js";import{C as D,a as y,c as k,d as I,f as ot,h as E,j as _,v as L}from"./chunks/chunk-P2CFLEGO.js";import{E as U,q as $,t as x,u as S,v as C,w as g,z as A}from"./chunks/chunk-YW3ZIFWB.js";function z(t,e={}){if(!t)return null;let{variant:r,sellingPlan:a,defaultPurchase:c=g.defaultPurchase,lowStock:u=g.lowStock}=e,d=G(t,{variant:r,sellingPlan:a,defaultPurchase:c}),n=H(t,{...d,quantity:1},u);if(!n)throw new y(`Product ${t.handle} has no variants`);let{selected:l,line:p}=n,i=(o,s)=>!Q(t,l,o,s);return{variant:n.variant,selected:l,purchase:n.purchase.kind,plan:p.kind==="subscription"?n.plan:null,plans:O(t).map(o=>({id:o.id,name:o.name,price:w(n.variant,o.id),savings:F(n.variant,o.id).percentage,selected:p.kind==="subscription"&&o.id===p.planId,available:!!v(n.variant,o.id)})),savings:n.savings.percentage,price:n.price,compareAtPrice:n.compareAtPrice,available:n.variant.availableForSale,show:n.show,unavailable:Object.fromEntries(t.options.map(o=>[o.name,o.optionValues.map(s=>s.name).filter(s=>i(o.name,s))])),isUnavailable:i}}var it=500,at=100,st=100,lt="query TetherServerProductById($id:ID!){node(id:$id){... on Product{...TetherProduct}}}",ct="query TetherServerProduct($handle:String!){product(handle:$handle){...TetherProduct}}",ut=()=>`query TetherServerCollection($handle:String!,$first:Int!,$after:String,$sortKey:ProductCollectionSortKeys,$reverse:Boolean,$filters:[ProductFilter!]){collection(handle:$handle){${T()} products(first:$first,after:$after,sortKey:$sortKey,reverse:$reverse,filters:$filters){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}}`,dt="query TetherServerProducts($first:Int!,$after:String,$query:String,$sortKey:ProductSortKeys,$reverse:Boolean){products(first:$first,after:$after,query:$query,sortKey:$sortKey,reverse:$reverse){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}",ft=()=>`query TetherServerCollections($first:Int!,$after:String){collections(first:$first,after:$after){nodes{${T()}}pageInfo{hasNextPage endCursor}}}`,pt=t=>`query TetherServerRecs(${t?"$id: ID!":"$handle: String!"},$intent:ProductRecommendationIntent){productRecommendations(${t?"productId: $id":"productHandle: $handle"},intent:$intent){...TetherProduct}}`,mt=I({product:k(V)}),gt=I({node:k(J)}),yt=I({collections:{nodes:[{handle:"string"}],pageInfo:{hasNextPage:"boolean"}}});async function Pt(t){let e=[],r=null;for(let a=0;a<st;a++){let c=await E(t,ft(),{first:at,after:r},yt);if(e.push(...c.collections.nodes),!c.collections.pageInfo.hasNextPage)break;r=c.collections.pageInfo.endCursor}return e}function Y(t,e){let r=(i,o,s)=>E(t,f=>`${i}
|
|
2
2
|
${M(t,f)}`,o,s);async function a(i){let o=C(i);if(!o)return null;if(o.startsWith("gid://")){let{node:f}=await r(lt,{id:o},gt);return f?.id?f:null}return(await r(ct,{handle:o},mt)).product}async function c(i,{first:o=e,after:s=null,sortKey:f,reverse:m=!1,filters:b}){let h=await r(ut(),{handle:i,first:o,after:s,sortKey:f||void 0,reverse:m,filters:b??void 0},B);if(!h.collection)return{collection:null,products:[],pageInfo:{hasNextPage:!1,endCursor:null}};let{products:P,...rt}=h.collection;return{collection:rt,products:P.nodes,pageInfo:P.pageInfo}}async function u(i={}){let{collection:o,query:s,first:f=e,after:m=null,sortKey:b,reverse:h=!1}=i;if(o)return c(o,i);let P=await r(dt,{first:f,after:m,query:s||void 0,sortKey:b||void 0,reverse:h},K);return{collection:null,products:P.products.nodes,pageInfo:P.products.pageInfo}}async function d(i={}){let o=[],s=null;for(let f=0;f<it;f++){let m=await u({...i,first:e,after:s});if(o.push(...m.products),!m.pageInfo.hasNextPage)break;s=m.pageInfo.endCursor}return o}async function n(i,o={}){let s=await u({...o,collection:i});return s.collection?{...s.collection,products:s.products,pageInfo:s.pageInfo}:null}async function l(i,o="RELATED"){let s=C(typeof i=="object"?i?.id:i);if(!s)throw new y("No product for recommendations",{code:"NOT_FOUND"});let f=s.startsWith("gid://");return(await r(pt(f),f?{id:s,intent:o}:{handle:s,intent:o},j)).productRecommendations??[]}return{getProduct:a,getProducts:u,allProducts:d,getCollection:n,allCollections:()=>Pt(t),getRecommendations:l}}var X={size:"https://schema.org/size",color:"https://schema.org/color",colour:"https://schema.org/color",material:"https://schema.org/material"},R=t=>JSON.stringify(t).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");function W(t){return JSON.parse(JSON.stringify(t))}var Z=t=>t.split("/").pop()??t;function ht(t){return t.availableForSale?t.currentlyNotInStock?"https://schema.org/BackOrder":"https://schema.org/InStock":"https://schema.org/OutOfStock"}function St(t,e){if(!t.requiresSellingPlan)return e.price;let r=O(t).find(a=>v(e,a.id));return(r&&w(e,r.id))??e.price}function tt(t,e,r){let a=St(t,e),c=r?.includes("?")?"&":"?";return{"@type":"Offer",price:a.amount,priceCurrency:a.currencyCode,availability:ht(e),url:r?`${r}${c}variant=${Z(e.id)}`:void 0}}function Ct(t,e,r,a){let c=e.selectedOptions.flatMap(u=>{let d=X[u.name.toLowerCase()];return d?[[d.split("/").pop()??d,u.value]]:[]});return{"@type":"Product",name:`${t.title} - ${e.title}`,sku:e.sku||void 0,image:e.image?.url||a[0],...Object.fromEntries(c),offers:tt(t,e,r)}}function It(t,{url:e},r){if(e)return e;let a=S(r.productPath,t.handle,t.id);if(!(!r.siteUrl||!a))return new URL(a,r.siteUrl).toString()}function N(t,e,r){if(!t)return null;let a=It(t,e,r),c=t.images.nodes.map(i=>i.url).filter(Boolean),u=e.brand||t.vendor,d=u?{"@type":"Brand",name:u}:void 0,n=t.description.trim()||void 0,l=t.variants.nodes;if(l.length<=1){let[i]=l;return W({"@context":"https://schema.org","@type":"Product",name:t.title,description:n,url:a,image:c,sku:i?.sku||void 0,brand:d,offers:i?tt(t,i,a):void 0})}let p=t.options.map(i=>X[i.name.toLowerCase()]).filter(Boolean);return W({"@context":"https://schema.org","@type":"ProductGroup",name:t.title,description:n,url:a,productGroupID:Z(t.id),image:c,brand:d,variesBy:[...new Set(p)],hasVariant:l.map(i=>Ct(t,i,a,c))})}var et=25,vt=2,wt=1;function bt(t,{productPath:e=g.productPath,id:r}={}){return S(e,t,r)}function nt(t,e){for(let r of e){let a=t[r];if(typeof a=="string"&&a)return a}return""}function $t(t){let e={};for(let[u,d]of Object.entries(t))Object.hasOwn(g,u)&&(e[u]=d);let r=typeof t.domain=="string"&&t.domain?t.domain:"",a=typeof t.token=="string"&&t.token?t.token:"",c={...A({...e,domain:r||nt(t,$.domain),token:a||nt(t,$.token)}),pageSize:kt(t.pageSize)};return t.fetch&&(c.fetch=t.fetch),t.siteUrl!==void 0&&(c.siteUrl=t.siteUrl),c}function kt(t){return typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=250?t:(t!==void 0&&U(`invalid pageSize ${JSON.stringify(t)}: using ${String(et)}`),et)}function Et(t,e){return{...t,description:"",descriptionHtml:"",images:{nodes:t.images.nodes.slice(0,Math.max(1,e))},variants:{nodes:t.variants.nodes.map(r=>({...r,image:null}))}}}function zt(t={}){let e=$t(t);if(!e.domain||!e.token)throw new y("createStorefront needs domain and token: pass them, or import.meta.env with PUBLIC_SHOPIFY_DOMAIN and PUBLIC_SHOPIFY_STOREFRONT_TOKEN",{code:"NOT_CONFIGURED"});let r=Y(e,e.pageSize),a={productPath:e.productPath,siteUrl:e.siteUrl};function c(n,{card:l=!1,images:p=vt}={}){let i=(Array.isArray(n)?n:[n]).filter(s=>s!=null),o={v:wt,at:new Date().toISOString(),country:e.country||null,language:e.language||null,products:l?i.map(s=>Et(s,p)):i};return`<script type="application/json" data-tether-hydrate>${R(o)}<\/script>`}function u(n,l={}){return n?`<script type="application/ld+json">${R(N(n,l,a))}<\/script>`:""}function d(n,l={}){return z(n,{defaultPurchase:e.defaultPurchase,lowStock:e.lowStock,...l})}return{config:e,query:(n,l,p)=>_(e,n,l,p),...r,hydrate:c,formatMoney:(n,l=e.locale)=>x(n,l),formatPercent:(n,l=e.locale)=>D(n,l),imageUrl:L,jsonLd:u,jsonLdData:(n,l={})=>N(n,l,a),initialState:d,productUrl:(n,l={})=>bt(n,{productPath:e.productPath,...l}),plans:q}}export{y as TetherError,zt as createStorefront,x as formatMoney,D as formatPercent,L as imageUrl,z as initialState,q as plans,C as productKey,bt as productUrl,ot as withContext};
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
// tether-core:client.ts
|
|
33
33
|
var m3 = window.Tether.__core["client.ts"];
|
|
34
|
-
var [endpoint, gql, matches, orNull, shaped, TetherError] = m3;
|
|
34
|
+
var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m3;
|
|
35
35
|
|
|
36
36
|
// server/src/shared/account-routes.ts
|
|
37
37
|
var OPERATION_ROUTES = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var De=Object.defineProperty;var Me=(e,t)=>{for(var n in t)De(e,n,{get:t[n],enumerable:!0})};var oe={};Me(oe,{addresses:()=>G,deleteAddress:()=>V,order:()=>j,renderPages:()=>bt,requestReturn:()=>K,saveAddress:()=>H,setup:()=>Te,showUnavailable:()=>wt,subscriptionAction:()=>J,subscriptions:()=>Z,updateProfile:()=>z});var qe=window.Tether.__core["config.ts"],[Tt,Ot,Et,St,Lt,T,Pt]=qe;var ve=window.Tether.__core["dom.ts"],[It,h,Ct,Rt,ue,P,b,p,Nt,Dt,Mt,qt,vt,Ht,Ft,l,A,Ut,u,_,_t,y,B]=ve;var He=window.Tether.__core["client.ts"],[$t,jt,zt,Gt,Vt,R]=He;var de={order:{name:"order",method:"GET",path:"/order",fields:{id:!0}},addresses:{name:"addresses",method:"GET",path:"/addresses",fields:{}},subscriptions:{name:"subscriptions",method:"GET",path:"/subscriptions",fields:{}},profile:{name:"profile",method:"POST",path:"/profile",fields:{firstName:!0,lastName:!0}},saveAddress:{name:"saveAddress",method:"POST",path:"/address",fields:{id:!0,address:!0,isDefault:!0}},deleteAddress:{name:"deleteAddress",method:"POST",path:"/address/delete",fields:{id:!0}},subscription:{name:"subscription",method:"POST",path:"/subscription",fields:{id:!0,action:!0}},requestReturn:{name:"requestReturn",method:"POST",path:"/return",fields:{orderId:!0,lines:!0}}},Jt=new Map(Object.values(de).map(e=>[`${e.method} ${e.path}`,{...e,fields:Object.keys(e.fields)}]));function le(e,t){let n=de[e];if(n.method==="POST")return{method:"POST",path:n.path};let r=t,s=new URLSearchParams;for(let d of Object.keys(n.fields)){let c=r[d];(typeof c=="string"||typeof c=="number")&&s.set(d,String(c))}let o=s.toString();return{method:"GET",path:o?`${n.path}?${o}`:n.path}}function g(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function i(e,t){return g(e)?e[t]:void 0}function ce(e){return Array.isArray(e)?e:[]}function a(e){return typeof e=="string"&&e!==""?e:null}var $=e=>typeof e=="number"&&Number.isFinite(e)?e:null,N=e=>$(e)??0,k=(e,t)=>ce(e).map(n=>t(n)),x=(e,t)=>({nodes:k(i(e,"nodes"),t)}),Q=e=>k(e,a).filter(t=>t!==null);function I(e){let t=a(i(e,"amount")),n=a(i(e,"currencyCode"));return t===null||n===null?null:{amount:t,currencyCode:n}}function W(e){let t=a(i(e,"url"));return t===null?null:{url:t,altText:a(i(e,"altText"))}}var me=e=>({title:a(i(e,"title")),variantTitle:a(i(e,"variantTitle")),quantity:N(i(e,"quantity")),image:W(i(e,"image"))});var ee=e=>new R(`Customer accounts: the answer has no ${e}`);function O(e,t){let n=a(e);if(!n)throw ee(t);return n}function fe(e){let t=n=>a(i(e,n));return{id:t("id"),firstName:t("firstName"),lastName:t("lastName"),company:t("company"),address1:t("address1"),address2:t("address2"),city:t("city"),province:t("province"),zoneCode:t("zoneCode"),zip:t("zip"),country:t("country"),countryCode:t("countryCode"),phoneNumber:t("phoneNumber"),formatted:Q(i(e,"formatted"))}}var pe=e=>g(e)?fe(e):null,te=e=>({...fe(e),id:O(i(e,"id"),"address id")}),ge=e=>k(e,t=>({...te(t),isDefault:i(t,"isDefault")===!0})),Fe=e=>({...me(e),id:O(i(e,"id"),"line item id"),name:a(i(e,"name")),sku:a(i(e,"sku")),price:I(i(e,"price")),totalPrice:I(i(e,"totalPrice")),suggestedReturnReasonDefinitions:x(i(e,"suggestedReturnReasonDefinitions"),t=>({id:O(i(t,"id"),"return reason id"),name:a(i(t,"name")),handle:a(i(t,"handle"))}))}),Ue=e=>({id:a(i(e,"id")),status:a(i(e,"status")),createdAt:a(i(e,"createdAt")),estimatedDeliveryAt:a(i(e,"estimatedDeliveryAt")),latestShipmentStatus:a(i(e,"latestShipmentStatus")),trackingInformation:k(i(e,"trackingInformation"),t=>({company:a(i(t,"company")),number:a(i(t,"number")),url:a(i(t,"url"))}))});function _e(e){let t=a(i(i(e,"lineItem"),"id"));return{quantity:N(i(e,"quantity")),lineItem:t===null?null:{id:t}}}function Be(e){return g(e)?{returnableLineItems:x(e.returnableLineItems,_e)}:null}function ye(e){if(!g(e))return null;let t=s=>a(e[s]),n=s=>I(e[s]),r=e.requiresShipping;return{id:O(e.id,"order id"),name:t("name"),number:$(e.number),processedAt:t("processedAt"),cancelledAt:t("cancelledAt"),financialStatus:t("financialStatus"),fulfillmentStatus:t("fulfillmentStatus"),statusPageUrl:t("statusPageUrl"),requiresShipping:typeof r=="boolean"?r:null,totalPrice:n("totalPrice"),subtotal:n("subtotal"),totalShipping:n("totalShipping"),totalTax:n("totalTax"),shippingAddress:pe(e.shippingAddress),billingAddress:pe(e.billingAddress),lineItems:x(e.lineItems,Fe),fulfillments:x(e.fulfillments,Ue),returnInformation:Be(e.returnInformation),returns:x(e.returns,ne)}}var $e=e=>({id:a(i(e,"id")),name:a(i(e,"name")),title:a(i(e,"title")),variantTitle:a(i(e,"variantTitle")),quantity:N(i(e,"quantity")),sku:a(i(e,"sku")),currentPrice:I(i(e,"currentPrice")),lineDiscountedPrice:I(i(e,"lineDiscountedPrice")),image:W(i(e,"image"))}),he=e=>({cycleIndex:$(i(e,"cycleIndex")),skipped:i(e,"skipped")===!0,billingAttemptExpectedDate:a(i(e,"billingAttemptExpectedDate"))});function je(e){if(!g(e))return null;let t=e.intervalCount;return{interval:a(e.interval),intervalCount:g(t)?{count:N(t.count)}:null}}var ze=e=>({id:O(i(e,"id"),"subscription id"),status:a(i(e,"status")),nextBillingDate:a(i(e,"nextBillingDate")),currencyCode:a(i(e,"currencyCode")),deliveryPrice:I(i(e,"deliveryPrice")),deliveryPolicy:je(i(e,"deliveryPolicy")),lines:x(i(e,"lines"),$e),upcomingBillingCycles:x(i(e,"upcomingBillingCycles"),he)}),be=e=>k(e,ze);function we(e){let{contract:t,billingCycle:n}=e;if(g(t))return{contract:{id:a(t.id),status:a(t.status)}};if(g(n)){let{cycleIndex:r,skipped:s}=he(n);return{billingCycle:{cycleIndex:r,skipped:s}}}throw ee("changed subscription")}function ne(e){return{id:O(i(e,"id"),"return id"),status:a(i(e,"status"))}}var Ae=e=>O(e,"deleted address id"),xe=e=>({firstName:a(i(e,"firstName")),lastName:a(i(e,"lastName"))});var re=null;function Te(e){re=e}function D(){if(!re)throw new Error("account-pages: loaded without the account part");return re}async function E(e,t){let{serverFetch:n}=D(),{method:r,path:s}=le(e,t),o=await n(s,r==="POST"?{method:r,body:t}:{});if(o.kind==="logged-out")throw new R("Not logged in",{code:"NOT_LOGGED_IN",status:401});return o.data}function v(e){D().reset(),ue("account-updated",{what:e})}async function j(e){let t=await E("order",{id:e});return ye(t.order)}async function z({firstName:e,lastName:t}={}){let n=await E("profile",{firstName:e,lastName:t});return v("profile"),xe(n.customer)}async function G(){let e=await E("addresses",{});return ge(e.addresses)}async function H(e,{id:t,isDefault:n}={}){let r=await E("saveAddress",{id:t,address:e,isDefault:n});return v("addresses"),te(r.address)}async function V(e){let t=await E("deleteAddress",{id:e});return v("addresses"),Ae(t.deleted)}async function Z(){let e=await E("subscriptions",{});return be(e.subscriptions)}async function J(e,t){let n=await E("subscription",{id:e,action:t});return v("subscriptions"),we(n)}async function K(e,t){let n=await E("requestReturn",{orderId:e,lines:t});return v("orders"),ne(n.return)}var Ge=window.Tether.__core["shopify-values.ts"],[se,fn]=Ge;function m(e,t,n){l(e,u(t)).forEach(r=>{let s=p(r,t)??"";Object.hasOwn(n,s)&&B(r,n[s]===!0)})}var S=(e,t)=>l(e,u(t)).concat(e.matches(u(t))?[e]:[]),L=e=>e?e.toLowerCase().replace(/_/g," "):"",F=e=>(e?.formatted??[]).join(", "),w=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;var Ve=(e,t)=>({title:e.title||e.name||"","variant-title":e.variantTitle||"",quantity:String(e.quantity),price:b(e.price),total:b(e.totalPrice),sku:e.sku||"",returnable:t===null?void 0:String(t)}),Ze=e=>e.tagName==="INPUT";function Je(e,t,n){m(e,"order-line-show",{returnable:n>0}),l(e,u("return-quantity")).forEach(r=>{Ze(r)&&(r.max=String(n),r.min="0",r.value||(r.value="0"),r.disabled=n<1)}),l(e,`select${u("return-reason")}`).forEach(r=>{r.dataset.tetherFilled!==t.id&&(r.dataset.tetherFilled=t.id,(t.suggestedReturnReasonDefinitions?.nodes??[]).forEach(s=>{r.appendChild(new Option(s.name??"",s.id))}))})}function Oe(e,t,n){A(e,t,(r,s)=>{let o=s.id,d=n&&o?n.get(o)??0:null;o&&(r.dataset.tetherLine=o);let c=Ve(s,d);S(r,"order-line").forEach(f=>{let C=p(f,"order-line")??"";if(C==="image"){s.image&&_(f,s.image.url,s.image.altText||s.title||"");return}let ae=w(c,C);ae!==void 0&&y(f,ae)}),o&&d!==null&&Je(r,{...s,id:o},d)})}function Ke(e){let t=p(e,"order")||"";return t.startsWith("url:")?new URL(window.location.href).searchParams.get(t.slice(4)||"id"):t}function U(e,t){e.setAttribute(h("order-state"),t),m(e,"order-show",{loading:t==="loading",ready:!1,"not-found":t==="not-found",error:t==="error"})}var Xe=e=>({name:e.name??"",date:P(e.processedAt),total:b(e.totalPrice),subtotal:b(e.subtotal),shipping:b(e.totalShipping),tax:b(e.totalTax),status:L(e.financialStatus),fulfillment:L(e.fulfillmentStatus),"shipping-address":F(e.shippingAddress),"billing-address":F(e.billingAddress),items:e.lineItems.nodes.map(t=>`${String(t.quantity)}\xD7 ${t.title||t.name||""}`).join(", "),cancelled:P(e.cancelledAt)});function Ye(e,t){let n=t.trackingInformation[0],r={status:L(t.latestShipmentStatus||t.status),date:P(t.createdAt),eta:P(t.estimatedDeliveryAt),company:n?.company||"",number:n?.number||""};S(e,"fulfillment-bind").forEach(s=>{let o=p(s,"fulfillment-bind")??"";if(o==="url"){let c=n?.url??null,f=c!==null&&se(c);f&&s.setAttribute("href",c),B(s,f);return}let d=w(r,o);d!==void 0&&y(s,d)})}function Qe(e,t){let n=new Map((t.returnInformation?.returnableLineItems.nodes??[]).map(d=>[d.lineItem?.id??"",d.quantity])),r=t.fulfillments.nodes,s=Xe(t);l(e,u("order-bind")).forEach(d=>{let c=p(d,"order-bind")??"";if(c==="url"){let C=t.statusPageUrl;C!==null&&se(C)&&d.setAttribute("href",C);return}let f=w(s,c);f!==void 0&&y(d,f)}),l(e,u("order-lines")).forEach(d=>{Oe(d,t.lineItems.nodes,n)}),l(e,u("order-fulfillments")).forEach(d=>{A(d,r,Ye)});let o=e.dataset.tetherReturned==="1";m(e,"order-show",{loading:!1,ready:!0,error:!1,"not-found":!1,cancelled:!!t.cancelledAt,shipped:r.length>0,returnable:[...n.values()].some(d=>d>0),"has-returns":!o&&t.returns.nodes.length>0,"return-requested":o}),e.setAttribute(h("order-state"),"ready")}async function X(e){let t=Ke(e);if(!t){e.setAttribute(h("order-state"),"not-found"),m(e,"order-show",{"not-found":!0});return}U(e,"loading");let n;try{n=await j(t)}catch(r){T(r,"order"),U(e,"error");return}if(!n){U(e,"not-found");return}e.dataset.tetherOrderId=n.id,Qe(e,n)}var Ee=[],Se=e=>Ee.find(t=>t.id===e),We=e=>({formatted:F(e),name:[e.firstName,e.lastName].filter(Boolean).join(" "),company:e.company||"",address1:e.address1||"",address2:e.address2||"",city:e.city||"",zip:e.zip||"",province:e.province||"",country:e.country||"",phone:e.phoneNumber||""});function et(e,t){e.dataset.tetherAddress=t.id;let n=We(t);S(e,"address-bind").forEach(r=>{let s=w(n,p(r,"address-bind")??"");s!==void 0&&y(r,s)}),m(e,"address-show",{default:t.isDefault,"not-default":!t.isDefault})}async function M(e){let t=l(e,u("addresses"));if(!t.length)return;m(e,"show",{"addresses-loading":!0,"addresses-empty":!1});let n;try{n=await G()}catch(r){T(r,"addresses"),m(e,"show",{"addresses-loading":!1,"addresses-error":!0});return}Ee=n,m(e,"show",{"addresses-loading":!1,"addresses-empty":n.length===0,"addresses-error":!1}),t.forEach(r=>{A(r,n,et)})}function tt(e){let t=e.upcomingBillingCycles.nodes[0],n=e.status,r=n==="ACTIVE";return{active:r,paused:n==="PAUSED",cancelled:n==="CANCELLED",expired:n==="EXPIRED",failed:n==="FAILED",skipped:!!t?.skipped,"can-pause":r,"can-resume":n==="PAUSED"||n==="FAILED","can-skip":r&&t!==void 0&&!t.skipped,"can-unskip":r&&!!t?.skipped,"can-cancel":r||n==="PAUSED"||n==="FAILED"}}function nt(e){let t=L(e.deliveryPolicy?.interval);if(!t)return"";let n=e.deliveryPolicy?.intervalCount?.count??1;return n<=1?t:`${String(n)} ${t}s`}function rt(e){let t=e.lines.nodes,n=t.reduce((r,s)=>r+Number.parseFloat(s.lineDiscountedPrice?.amount??"0"),0);return{status:L(e.status),next:P(e.nextBillingDate),interval:nt(e),products:t.map(r=>`${String(r.quantity)}\xD7 ${r.title??""}`).join(", "),total:b(t.length&&e.currencyCode?{amount:String(n),currencyCode:e.currencyCode}:null),delivery:b(e.deliveryPrice)}}function st(e,t){let n={title:t.title??"","variant-title":t.variantTitle||"",quantity:String(t.quantity),price:b(t.currentPrice)};S(e,"subscription-line").forEach(r=>{let s=p(r,"subscription-line")??"";if(s==="image"){t.image&&_(r,t.image.url,t.image.altText||t.title||"");return}let o=w(n,s);o!==void 0&&y(r,o)})}function it(e,t){e.dataset.tetherSubscription=t.id,e.setAttribute(h("subscription-status"),L(t.status));let n=rt(t);l(e,u("subscription-bind")).forEach(s=>{let o=w(n,p(s,"subscription-bind")??"");o!==void 0&&y(s,o)}),l(e,u("subscription-lines")).forEach(s=>{A(s,t.lines.nodes,st)});let r=tt(t);m(e,"subscription-show",r),l(e,u("subscription-action")).forEach(s=>{let o=w(r,`can-${p(s,"subscription-action")??""}`)===!0;"disabled"in s&&(s.disabled=!o),s.classList.toggle("is-disabled",!o)})}async function Y(e){let t=l(e,u("subscriptions"));if(!t.length)return;m(e,"show",{"subscriptions-loading":!0,"subscriptions-empty":!1});let n;try{n=await Z()}catch(r){T(r,"subscriptions"),m(e,"show",{"subscriptions-loading":!1,"subscriptions-error":!0});return}m(e,"show",{"subscriptions-loading":!1,"subscriptions-empty":n.length===0,"subscriptions-error":!1}),t.forEach(r=>{A(r,n,it)})}var ot=["pause","resume","skip","unskip","cancel"],at=e=>ot.some(t=>t===e),Pe=e=>e instanceof window.HTMLInputElement||e instanceof window.HTMLSelectElement||e instanceof window.HTMLTextAreaElement,ke=e=>e instanceof window.HTMLFormElement;function Le(e){let t={};for(let n of e.elements)Pe(n)&&(!n.name||n.type==="submit"||n.type==="button"||n.type==="checkbox"||(t[n.name]=n.value));return t}function ut(e){let n=(e instanceof R?e.userErrors??[]:[]).map(s=>s.message).join(" ");return n||(e instanceof Error&&e.message?e.message:"Something went wrong").replace(/^Customer accounts: /,"")}async function q(e,t){if(e.getAttribute("aria-busy")==="true")return"busy";e.classList.add("is-busy"),e.setAttribute("aria-busy","true"),e.setAttribute(h("form-state"),"pending");let n=l(e,u("form-error"));n.forEach(r=>{y(r,"")});try{return await t(),e.setAttribute(h("form-state"),"saved"),"saved"}catch(r){return e.setAttribute(h("form-state"),"error"),n.forEach(s=>{y(s,ut(r))}),"error"}finally{e.classList.remove("is-busy"),e.removeAttribute("aria-busy")}}var ie=e=>{let t=p(e,"confirm");return!t||window.confirm(t)},Ie=e=>{e.reset(),delete e.dataset.tetherAddressId};function dt(e){let t=e.target;if(t instanceof window.HTMLFormElement){if(t.matches(u("profile-form")))e.preventDefault(),q(t,async()=>{await z(Le(t)),await D().bindCustomer(document)});else if(t.matches(u("address-form"))){e.preventDefault();let n=t.dataset.tetherAddressId,r=t.elements.namedItem("isDefault"),s=r instanceof window.HTMLInputElement&&r.checked;q(t,async()=>{await H(Le(t),{id:n,isDefault:s}),Ie(t),await M(document)})}}}function lt(e){let t=Se(e),n=document.querySelector(u("address-form"));if(!t||!n||!ke(n))return;n.dataset.tetherAddressId=t.id;let r={...t};for(let s of n.elements)if(Pe(s)){if(s.name==="isDefault")s instanceof window.HTMLInputElement&&(s.checked=t.isDefault);else if(s.name&&Object.hasOwn(r,s.name)){let o=r[s.name];s.value=typeof o=="string"?o:""}}n.scrollIntoView({block:"nearest"})}function ct(e,t){let n=t.closest("[data-tether-address]"),r=n instanceof window.HTMLElement?n.dataset.tetherAddress:void 0;if(t.closest(u("address-new"))){let o=document.querySelector(u("address-form"));return o&&ke(o)&&Ie(o),!0}if(!(n instanceof window.HTMLElement)||!r)return!1;let s=t.closest(u("address-delete"));if(s){if(e.preventDefault(),!ie(s))return!0;q(n,async()=>{await V(r),await M(document)})}else if(t.closest(u("address-default")))e.preventDefault(),q(n,async()=>{await H(null,{id:r,isDefault:!0}),await M(document)});else if(t.closest(u("address-edit")))e.preventDefault(),lt(r);else return!1;return!0}function mt(e){let t=e.closest("[data-tether-subscription]"),n=p(e,"subscription-action"),r="disabled"in e&&e.disabled===!0||e.classList.contains("is-disabled");if(!(t instanceof window.HTMLElement)||!at(n)||r||!ie(e))return;let s=t.dataset.tetherSubscription??"";t.setAttribute(h("subscription-state"),"pending"),q(t,async()=>{await J(s,n),await Y(document)}).then(o=>{let d=o==="error"?"error":"done";l(document,"[data-tether-subscription]").filter(c=>c===t||c.dataset.tetherSubscription===s).forEach(c=>{c.setAttribute(h("subscription-state"),d)})})}function pt(e){let t=e.querySelector(u("return-quantity")),n=e.querySelector(u("return-reason")),r=e.querySelector(u("return-note")),s=f=>f&&"value"in f&&typeof f.value=="string"?f.value:"",o={lineItemId:e.dataset.tetherLine??"",quantity:Number.parseInt(s(t)||"0",10)},d=s(n);d&&(o.reasonId=d);let c=s(r);return c&&(o.note=c),o}function ft(e){let t=e.closest(u("order"));if(!(t instanceof window.HTMLElement))return;let n=t.dataset.tetherOrderId;if(!n)return;let r=l(t,"[data-tether-line]").map(pt).filter(s=>s.quantity>0);!r.length||!ie(e)||q(t,async()=>{await K(n,r),t.dataset.tetherReturned="1",await X(t)})}function gt(e){let t=e.target;if(!(t instanceof window.Element)||ct(e,t))return;let n=t.closest(u("subscription-action"));if(n instanceof window.HTMLElement){e.preventDefault(),mt(n);return}let r=t.closest(u("order-return"));r instanceof window.HTMLElement&&(e.preventDefault(),ft(r))}function Ce(){document.addEventListener("submit",dt,!0),document.addEventListener("input",e=>{let t=e.target;t instanceof window.HTMLElement&&t.closest(u("profile-form"))&&(t.dataset.tetherTouched="1")}),document.addEventListener("click",gt)}var yt=["firstName","lastName"];async function ht(e){if(!(e instanceof window.HTMLFormElement))return;let t;try{t=await D().customer()}catch(r){T(r,"account");return}if(!t)return;let n=e.elements;yt.forEach(r=>{let s=n.namedItem(r);(s instanceof window.HTMLInputElement||s instanceof window.HTMLTextAreaElement)&&!s.dataset.tetherTouched&&(s.value=t[r]??"")})}var Re=!1;async function bt(e=document){Re||(Re=!0,Ce()),await Promise.all([...l(e,u("order")).map(t=>X(t)),...l(e,u("profile-form")).map(t=>ht(t)),M(e),Y(e)])}function wt(e){l(e,u("order")).forEach(t=>{U(t,"error")}),m(e,"show",{"addresses-loading":!1,"addresses-error":!0,"subscriptions-loading":!1,"subscriptions-error":!0})}function At(e){return g(e)&&g(e.__core)&&g(e.__parts)}function Ne(e,t){let n=Reflect.get(window,"Tether");if(!At(n))throw new Error(`tether.${e}.js runs after the Tether script, which loads it, and needs its window.Tether`);n.__parts[e]=t}Ne("account-pages",oe);})();
|
|
1
|
+
(()=>{var De=Object.defineProperty;var Me=(e,t)=>{for(var n in t)De(e,n,{get:t[n],enumerable:!0})};var oe={};Me(oe,{addresses:()=>G,deleteAddress:()=>V,order:()=>j,renderPages:()=>bt,requestReturn:()=>K,saveAddress:()=>H,setup:()=>Te,showUnavailable:()=>wt,subscriptionAction:()=>J,subscriptions:()=>Z,updateProfile:()=>z});var qe=window.Tether.__core["config.ts"],[Tt,Ot,Et,St,Lt,T,Pt]=qe;var ve=window.Tether.__core["dom.ts"],[It,h,Ct,Rt,ue,P,b,p,Nt,Dt,Mt,qt,vt,Ht,Ft,l,A,Ut,u,_,_t,y,B]=ve;var He=window.Tether.__core["client.ts"],[$t,jt,zt,Gt,Vt,R,Zt]=He;var de={order:{name:"order",method:"GET",path:"/order",fields:{id:!0}},addresses:{name:"addresses",method:"GET",path:"/addresses",fields:{}},subscriptions:{name:"subscriptions",method:"GET",path:"/subscriptions",fields:{}},profile:{name:"profile",method:"POST",path:"/profile",fields:{firstName:!0,lastName:!0}},saveAddress:{name:"saveAddress",method:"POST",path:"/address",fields:{id:!0,address:!0,isDefault:!0}},deleteAddress:{name:"deleteAddress",method:"POST",path:"/address/delete",fields:{id:!0}},subscription:{name:"subscription",method:"POST",path:"/subscription",fields:{id:!0,action:!0}},requestReturn:{name:"requestReturn",method:"POST",path:"/return",fields:{orderId:!0,lines:!0}}},Kt=new Map(Object.values(de).map(e=>[`${e.method} ${e.path}`,{...e,fields:Object.keys(e.fields)}]));function le(e,t){let n=de[e];if(n.method==="POST")return{method:"POST",path:n.path};let r=t,s=new URLSearchParams;for(let d of Object.keys(n.fields)){let c=r[d];(typeof c=="string"||typeof c=="number")&&s.set(d,String(c))}let o=s.toString();return{method:"GET",path:o?`${n.path}?${o}`:n.path}}function g(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function i(e,t){return g(e)?e[t]:void 0}function ce(e){return Array.isArray(e)?e:[]}function a(e){return typeof e=="string"&&e!==""?e:null}var $=e=>typeof e=="number"&&Number.isFinite(e)?e:null,N=e=>$(e)??0,k=(e,t)=>ce(e).map(n=>t(n)),x=(e,t)=>({nodes:k(i(e,"nodes"),t)}),Q=e=>k(e,a).filter(t=>t!==null);function I(e){let t=a(i(e,"amount")),n=a(i(e,"currencyCode"));return t===null||n===null?null:{amount:t,currencyCode:n}}function W(e){let t=a(i(e,"url"));return t===null?null:{url:t,altText:a(i(e,"altText"))}}var me=e=>({title:a(i(e,"title")),variantTitle:a(i(e,"variantTitle")),quantity:N(i(e,"quantity")),image:W(i(e,"image"))});var ee=e=>new R(`Customer accounts: the answer has no ${e}`);function O(e,t){let n=a(e);if(!n)throw ee(t);return n}function fe(e){let t=n=>a(i(e,n));return{id:t("id"),firstName:t("firstName"),lastName:t("lastName"),company:t("company"),address1:t("address1"),address2:t("address2"),city:t("city"),province:t("province"),zoneCode:t("zoneCode"),zip:t("zip"),country:t("country"),countryCode:t("countryCode"),phoneNumber:t("phoneNumber"),formatted:Q(i(e,"formatted"))}}var pe=e=>g(e)?fe(e):null,te=e=>({...fe(e),id:O(i(e,"id"),"address id")}),ge=e=>k(e,t=>({...te(t),isDefault:i(t,"isDefault")===!0})),Fe=e=>({...me(e),id:O(i(e,"id"),"line item id"),name:a(i(e,"name")),sku:a(i(e,"sku")),price:I(i(e,"price")),totalPrice:I(i(e,"totalPrice")),suggestedReturnReasonDefinitions:x(i(e,"suggestedReturnReasonDefinitions"),t=>({id:O(i(t,"id"),"return reason id"),name:a(i(t,"name")),handle:a(i(t,"handle"))}))}),Ue=e=>({id:a(i(e,"id")),status:a(i(e,"status")),createdAt:a(i(e,"createdAt")),estimatedDeliveryAt:a(i(e,"estimatedDeliveryAt")),latestShipmentStatus:a(i(e,"latestShipmentStatus")),trackingInformation:k(i(e,"trackingInformation"),t=>({company:a(i(t,"company")),number:a(i(t,"number")),url:a(i(t,"url"))}))});function _e(e){let t=a(i(i(e,"lineItem"),"id"));return{quantity:N(i(e,"quantity")),lineItem:t===null?null:{id:t}}}function Be(e){return g(e)?{returnableLineItems:x(e.returnableLineItems,_e)}:null}function ye(e){if(!g(e))return null;let t=s=>a(e[s]),n=s=>I(e[s]),r=e.requiresShipping;return{id:O(e.id,"order id"),name:t("name"),number:$(e.number),processedAt:t("processedAt"),cancelledAt:t("cancelledAt"),financialStatus:t("financialStatus"),fulfillmentStatus:t("fulfillmentStatus"),statusPageUrl:t("statusPageUrl"),requiresShipping:typeof r=="boolean"?r:null,totalPrice:n("totalPrice"),subtotal:n("subtotal"),totalShipping:n("totalShipping"),totalTax:n("totalTax"),shippingAddress:pe(e.shippingAddress),billingAddress:pe(e.billingAddress),lineItems:x(e.lineItems,Fe),fulfillments:x(e.fulfillments,Ue),returnInformation:Be(e.returnInformation),returns:x(e.returns,ne)}}var $e=e=>({id:a(i(e,"id")),name:a(i(e,"name")),title:a(i(e,"title")),variantTitle:a(i(e,"variantTitle")),quantity:N(i(e,"quantity")),sku:a(i(e,"sku")),currentPrice:I(i(e,"currentPrice")),lineDiscountedPrice:I(i(e,"lineDiscountedPrice")),image:W(i(e,"image"))}),he=e=>({cycleIndex:$(i(e,"cycleIndex")),skipped:i(e,"skipped")===!0,billingAttemptExpectedDate:a(i(e,"billingAttemptExpectedDate"))});function je(e){if(!g(e))return null;let t=e.intervalCount;return{interval:a(e.interval),intervalCount:g(t)?{count:N(t.count)}:null}}var ze=e=>({id:O(i(e,"id"),"subscription id"),status:a(i(e,"status")),nextBillingDate:a(i(e,"nextBillingDate")),currencyCode:a(i(e,"currencyCode")),deliveryPrice:I(i(e,"deliveryPrice")),deliveryPolicy:je(i(e,"deliveryPolicy")),lines:x(i(e,"lines"),$e),upcomingBillingCycles:x(i(e,"upcomingBillingCycles"),he)}),be=e=>k(e,ze);function we(e){let{contract:t,billingCycle:n}=e;if(g(t))return{contract:{id:a(t.id),status:a(t.status)}};if(g(n)){let{cycleIndex:r,skipped:s}=he(n);return{billingCycle:{cycleIndex:r,skipped:s}}}throw ee("changed subscription")}function ne(e){return{id:O(i(e,"id"),"return id"),status:a(i(e,"status"))}}var Ae=e=>O(e,"deleted address id"),xe=e=>({firstName:a(i(e,"firstName")),lastName:a(i(e,"lastName"))});var re=null;function Te(e){re=e}function D(){if(!re)throw new Error("account-pages: loaded without the account part");return re}async function E(e,t){let{serverFetch:n}=D(),{method:r,path:s}=le(e,t),o=await n(s,r==="POST"?{method:r,body:t}:{});if(o.kind==="logged-out")throw new R("Not logged in",{code:"NOT_LOGGED_IN",status:401});return o.data}function v(e){D().reset(),ue("account-updated",{what:e})}async function j(e){let t=await E("order",{id:e});return ye(t.order)}async function z({firstName:e,lastName:t}={}){let n=await E("profile",{firstName:e,lastName:t});return v("profile"),xe(n.customer)}async function G(){let e=await E("addresses",{});return ge(e.addresses)}async function H(e,{id:t,isDefault:n}={}){let r=await E("saveAddress",{id:t,address:e,isDefault:n});return v("addresses"),te(r.address)}async function V(e){let t=await E("deleteAddress",{id:e});return v("addresses"),Ae(t.deleted)}async function Z(){let e=await E("subscriptions",{});return be(e.subscriptions)}async function J(e,t){let n=await E("subscription",{id:e,action:t});return v("subscriptions"),we(n)}async function K(e,t){let n=await E("requestReturn",{orderId:e,lines:t});return v("orders"),ne(n.return)}var Ge=window.Tether.__core["shopify-values.ts"],[se,gn]=Ge;function m(e,t,n){l(e,u(t)).forEach(r=>{let s=p(r,t)??"";Object.hasOwn(n,s)&&B(r,n[s]===!0)})}var S=(e,t)=>l(e,u(t)).concat(e.matches(u(t))?[e]:[]),L=e=>e?e.toLowerCase().replace(/_/g," "):"",F=e=>(e?.formatted??[]).join(", "),w=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;var Ve=(e,t)=>({title:e.title||e.name||"","variant-title":e.variantTitle||"",quantity:String(e.quantity),price:b(e.price),total:b(e.totalPrice),sku:e.sku||"",returnable:t===null?void 0:String(t)}),Ze=e=>e.tagName==="INPUT";function Je(e,t,n){m(e,"order-line-show",{returnable:n>0}),l(e,u("return-quantity")).forEach(r=>{Ze(r)&&(r.max=String(n),r.min="0",r.value||(r.value="0"),r.disabled=n<1)}),l(e,`select${u("return-reason")}`).forEach(r=>{r.dataset.tetherFilled!==t.id&&(r.dataset.tetherFilled=t.id,(t.suggestedReturnReasonDefinitions?.nodes??[]).forEach(s=>{r.appendChild(new Option(s.name??"",s.id))}))})}function Oe(e,t,n){A(e,t,(r,s)=>{let o=s.id,d=n&&o?n.get(o)??0:null;o&&(r.dataset.tetherLine=o);let c=Ve(s,d);S(r,"order-line").forEach(f=>{let C=p(f,"order-line")??"";if(C==="image"){s.image&&_(f,s.image.url,s.image.altText||s.title||"");return}let ae=w(c,C);ae!==void 0&&y(f,ae)}),o&&d!==null&&Je(r,{...s,id:o},d)})}function Ke(e){let t=p(e,"order")||"";return t.startsWith("url:")?new URL(window.location.href).searchParams.get(t.slice(4)||"id"):t}function U(e,t){e.setAttribute(h("order-state"),t),m(e,"order-show",{loading:t==="loading",ready:!1,"not-found":t==="not-found",error:t==="error"})}var Xe=e=>({name:e.name??"",date:P(e.processedAt),total:b(e.totalPrice),subtotal:b(e.subtotal),shipping:b(e.totalShipping),tax:b(e.totalTax),status:L(e.financialStatus),fulfillment:L(e.fulfillmentStatus),"shipping-address":F(e.shippingAddress),"billing-address":F(e.billingAddress),items:e.lineItems.nodes.map(t=>`${String(t.quantity)}\xD7 ${t.title||t.name||""}`).join(", "),cancelled:P(e.cancelledAt)});function Ye(e,t){let n=t.trackingInformation[0],r={status:L(t.latestShipmentStatus||t.status),date:P(t.createdAt),eta:P(t.estimatedDeliveryAt),company:n?.company||"",number:n?.number||""};S(e,"fulfillment-bind").forEach(s=>{let o=p(s,"fulfillment-bind")??"";if(o==="url"){let c=n?.url??null,f=c!==null&&se(c);f&&s.setAttribute("href",c),B(s,f);return}let d=w(r,o);d!==void 0&&y(s,d)})}function Qe(e,t){let n=new Map((t.returnInformation?.returnableLineItems.nodes??[]).map(d=>[d.lineItem?.id??"",d.quantity])),r=t.fulfillments.nodes,s=Xe(t);l(e,u("order-bind")).forEach(d=>{let c=p(d,"order-bind")??"";if(c==="url"){let C=t.statusPageUrl;C!==null&&se(C)&&d.setAttribute("href",C);return}let f=w(s,c);f!==void 0&&y(d,f)}),l(e,u("order-lines")).forEach(d=>{Oe(d,t.lineItems.nodes,n)}),l(e,u("order-fulfillments")).forEach(d=>{A(d,r,Ye)});let o=e.dataset.tetherReturned==="1";m(e,"order-show",{loading:!1,ready:!0,error:!1,"not-found":!1,cancelled:!!t.cancelledAt,shipped:r.length>0,returnable:[...n.values()].some(d=>d>0),"has-returns":!o&&t.returns.nodes.length>0,"return-requested":o}),e.setAttribute(h("order-state"),"ready")}async function X(e){let t=Ke(e);if(!t){e.setAttribute(h("order-state"),"not-found"),m(e,"order-show",{"not-found":!0});return}U(e,"loading");let n;try{n=await j(t)}catch(r){T(r,"order"),U(e,"error");return}if(!n){U(e,"not-found");return}e.dataset.tetherOrderId=n.id,Qe(e,n)}var Ee=[],Se=e=>Ee.find(t=>t.id===e),We=e=>({formatted:F(e),name:[e.firstName,e.lastName].filter(Boolean).join(" "),company:e.company||"",address1:e.address1||"",address2:e.address2||"",city:e.city||"",zip:e.zip||"",province:e.province||"",country:e.country||"",phone:e.phoneNumber||""});function et(e,t){e.dataset.tetherAddress=t.id;let n=We(t);S(e,"address-bind").forEach(r=>{let s=w(n,p(r,"address-bind")??"");s!==void 0&&y(r,s)}),m(e,"address-show",{default:t.isDefault,"not-default":!t.isDefault})}async function M(e){let t=l(e,u("addresses"));if(!t.length)return;m(e,"show",{"addresses-loading":!0,"addresses-empty":!1});let n;try{n=await G()}catch(r){T(r,"addresses"),m(e,"show",{"addresses-loading":!1,"addresses-error":!0});return}Ee=n,m(e,"show",{"addresses-loading":!1,"addresses-empty":n.length===0,"addresses-error":!1}),t.forEach(r=>{A(r,n,et)})}function tt(e){let t=e.upcomingBillingCycles.nodes[0],n=e.status,r=n==="ACTIVE";return{active:r,paused:n==="PAUSED",cancelled:n==="CANCELLED",expired:n==="EXPIRED",failed:n==="FAILED",skipped:!!t?.skipped,"can-pause":r,"can-resume":n==="PAUSED"||n==="FAILED","can-skip":r&&t!==void 0&&!t.skipped,"can-unskip":r&&!!t?.skipped,"can-cancel":r||n==="PAUSED"||n==="FAILED"}}function nt(e){let t=L(e.deliveryPolicy?.interval);if(!t)return"";let n=e.deliveryPolicy?.intervalCount?.count??1;return n<=1?t:`${String(n)} ${t}s`}function rt(e){let t=e.lines.nodes,n=t.reduce((r,s)=>r+Number.parseFloat(s.lineDiscountedPrice?.amount??"0"),0);return{status:L(e.status),next:P(e.nextBillingDate),interval:nt(e),products:t.map(r=>`${String(r.quantity)}\xD7 ${r.title??""}`).join(", "),total:b(t.length&&e.currencyCode?{amount:String(n),currencyCode:e.currencyCode}:null),delivery:b(e.deliveryPrice)}}function st(e,t){let n={title:t.title??"","variant-title":t.variantTitle||"",quantity:String(t.quantity),price:b(t.currentPrice)};S(e,"subscription-line").forEach(r=>{let s=p(r,"subscription-line")??"";if(s==="image"){t.image&&_(r,t.image.url,t.image.altText||t.title||"");return}let o=w(n,s);o!==void 0&&y(r,o)})}function it(e,t){e.dataset.tetherSubscription=t.id,e.setAttribute(h("subscription-status"),L(t.status));let n=rt(t);l(e,u("subscription-bind")).forEach(s=>{let o=w(n,p(s,"subscription-bind")??"");o!==void 0&&y(s,o)}),l(e,u("subscription-lines")).forEach(s=>{A(s,t.lines.nodes,st)});let r=tt(t);m(e,"subscription-show",r),l(e,u("subscription-action")).forEach(s=>{let o=w(r,`can-${p(s,"subscription-action")??""}`)===!0;"disabled"in s&&(s.disabled=!o),s.classList.toggle("is-disabled",!o)})}async function Y(e){let t=l(e,u("subscriptions"));if(!t.length)return;m(e,"show",{"subscriptions-loading":!0,"subscriptions-empty":!1});let n;try{n=await Z()}catch(r){T(r,"subscriptions"),m(e,"show",{"subscriptions-loading":!1,"subscriptions-error":!0});return}m(e,"show",{"subscriptions-loading":!1,"subscriptions-empty":n.length===0,"subscriptions-error":!1}),t.forEach(r=>{A(r,n,it)})}var ot=["pause","resume","skip","unskip","cancel"],at=e=>ot.some(t=>t===e),Pe=e=>e instanceof window.HTMLInputElement||e instanceof window.HTMLSelectElement||e instanceof window.HTMLTextAreaElement,ke=e=>e instanceof window.HTMLFormElement;function Le(e){let t={};for(let n of e.elements)Pe(n)&&(!n.name||n.type==="submit"||n.type==="button"||n.type==="checkbox"||(t[n.name]=n.value));return t}function ut(e){let n=(e instanceof R?e.userErrors??[]:[]).map(s=>s.message).join(" ");return n||(e instanceof Error&&e.message?e.message:"Something went wrong").replace(/^Customer accounts: /,"")}async function q(e,t){if(e.getAttribute("aria-busy")==="true")return"busy";e.classList.add("is-busy"),e.setAttribute("aria-busy","true"),e.setAttribute(h("form-state"),"pending");let n=l(e,u("form-error"));n.forEach(r=>{y(r,"")});try{return await t(),e.setAttribute(h("form-state"),"saved"),"saved"}catch(r){return e.setAttribute(h("form-state"),"error"),n.forEach(s=>{y(s,ut(r))}),"error"}finally{e.classList.remove("is-busy"),e.removeAttribute("aria-busy")}}var ie=e=>{let t=p(e,"confirm");return!t||window.confirm(t)},Ie=e=>{e.reset(),delete e.dataset.tetherAddressId};function dt(e){let t=e.target;if(t instanceof window.HTMLFormElement){if(t.matches(u("profile-form")))e.preventDefault(),q(t,async()=>{await z(Le(t)),await D().bindCustomer(document)});else if(t.matches(u("address-form"))){e.preventDefault();let n=t.dataset.tetherAddressId,r=t.elements.namedItem("isDefault"),s=r instanceof window.HTMLInputElement&&r.checked;q(t,async()=>{await H(Le(t),{id:n,isDefault:s}),Ie(t),await M(document)})}}}function lt(e){let t=Se(e),n=document.querySelector(u("address-form"));if(!t||!n||!ke(n))return;n.dataset.tetherAddressId=t.id;let r={...t};for(let s of n.elements)if(Pe(s)){if(s.name==="isDefault")s instanceof window.HTMLInputElement&&(s.checked=t.isDefault);else if(s.name&&Object.hasOwn(r,s.name)){let o=r[s.name];s.value=typeof o=="string"?o:""}}n.scrollIntoView({block:"nearest"})}function ct(e,t){let n=t.closest("[data-tether-address]"),r=n instanceof window.HTMLElement?n.dataset.tetherAddress:void 0;if(t.closest(u("address-new"))){let o=document.querySelector(u("address-form"));return o&&ke(o)&&Ie(o),!0}if(!(n instanceof window.HTMLElement)||!r)return!1;let s=t.closest(u("address-delete"));if(s){if(e.preventDefault(),!ie(s))return!0;q(n,async()=>{await V(r),await M(document)})}else if(t.closest(u("address-default")))e.preventDefault(),q(n,async()=>{await H(null,{id:r,isDefault:!0}),await M(document)});else if(t.closest(u("address-edit")))e.preventDefault(),lt(r);else return!1;return!0}function mt(e){let t=e.closest("[data-tether-subscription]"),n=p(e,"subscription-action"),r="disabled"in e&&e.disabled===!0||e.classList.contains("is-disabled");if(!(t instanceof window.HTMLElement)||!at(n)||r||!ie(e))return;let s=t.dataset.tetherSubscription??"";t.setAttribute(h("subscription-state"),"pending"),q(t,async()=>{await J(s,n),await Y(document)}).then(o=>{let d=o==="error"?"error":"done";l(document,"[data-tether-subscription]").filter(c=>c===t||c.dataset.tetherSubscription===s).forEach(c=>{c.setAttribute(h("subscription-state"),d)})})}function pt(e){let t=e.querySelector(u("return-quantity")),n=e.querySelector(u("return-reason")),r=e.querySelector(u("return-note")),s=f=>f&&"value"in f&&typeof f.value=="string"?f.value:"",o={lineItemId:e.dataset.tetherLine??"",quantity:Number.parseInt(s(t)||"0",10)},d=s(n);d&&(o.reasonId=d);let c=s(r);return c&&(o.note=c),o}function ft(e){let t=e.closest(u("order"));if(!(t instanceof window.HTMLElement))return;let n=t.dataset.tetherOrderId;if(!n)return;let r=l(t,"[data-tether-line]").map(pt).filter(s=>s.quantity>0);!r.length||!ie(e)||q(t,async()=>{await K(n,r),t.dataset.tetherReturned="1",await X(t)})}function gt(e){let t=e.target;if(!(t instanceof window.Element)||ct(e,t))return;let n=t.closest(u("subscription-action"));if(n instanceof window.HTMLElement){e.preventDefault(),mt(n);return}let r=t.closest(u("order-return"));r instanceof window.HTMLElement&&(e.preventDefault(),ft(r))}function Ce(){document.addEventListener("submit",dt,!0),document.addEventListener("input",e=>{let t=e.target;t instanceof window.HTMLElement&&t.closest(u("profile-form"))&&(t.dataset.tetherTouched="1")}),document.addEventListener("click",gt)}var yt=["firstName","lastName"];async function ht(e){if(!(e instanceof window.HTMLFormElement))return;let t;try{t=await D().customer()}catch(r){T(r,"account");return}if(!t)return;let n=e.elements;yt.forEach(r=>{let s=n.namedItem(r);(s instanceof window.HTMLInputElement||s instanceof window.HTMLTextAreaElement)&&!s.dataset.tetherTouched&&(s.value=t[r]??"")})}var Re=!1;async function bt(e=document){Re||(Re=!0,Ce()),await Promise.all([...l(e,u("order")).map(t=>X(t)),...l(e,u("profile-form")).map(t=>ht(t)),M(e),Y(e)])}function wt(e){l(e,u("order")).forEach(t=>{U(t,"error")}),m(e,"show",{"addresses-loading":!1,"addresses-error":!0,"subscriptions-loading":!1,"subscriptions-error":!0})}function At(e){return g(e)&&g(e.__core)&&g(e.__parts)}function Ne(e,t){let n=Reflect.get(window,"Tether");if(!At(n))throw new Error(`tether.${e}.js runs after the Tether script, which loads it, and needs its window.Tether`);n.__parts[e]=t}Ne("account-pages",oe);})();
|
package/dist/tether.account.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
// tether-core:client.ts
|
|
33
33
|
var m2 = window.Tether.__core["client.ts"];
|
|
34
|
-
var [endpoint, gql, matches, orNull, shaped, TetherError] = m2;
|
|
34
|
+
var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m2;
|
|
35
35
|
|
|
36
36
|
// tether-core:dom.ts
|
|
37
37
|
var m3 = window.Tether.__core["dom.ts"];
|
|
@@ -171,31 +171,34 @@
|
|
|
171
171
|
if (loggedIn) setStored(hintKey(), "1");
|
|
172
172
|
else removeStored(hintKey());
|
|
173
173
|
}
|
|
174
|
+
async function readJsonObjectOrEmpty(response) {
|
|
175
|
+
let json;
|
|
176
|
+
try {
|
|
177
|
+
json = await response.json();
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error instanceof SyntaxError) return {};
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
return isRecord(json) ? json : {};
|
|
183
|
+
}
|
|
174
184
|
async function fetchFromWorker(url, init) {
|
|
175
185
|
try {
|
|
176
|
-
return await
|
|
186
|
+
return await withTimeout(cfg.requestTimeout, async (signal) => {
|
|
187
|
+
const response = await fetch(url, { ...init, signal });
|
|
188
|
+
return { response, data: await readJsonObjectOrEmpty(response) };
|
|
189
|
+
});
|
|
177
190
|
} catch (error) {
|
|
178
191
|
throw new TetherError(`Network error: ${messageOf(error)}`, {
|
|
179
192
|
code: "NETWORK"
|
|
180
193
|
});
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
|
-
async function readJsonObjectOrEmpty(response) {
|
|
184
|
-
let json;
|
|
185
|
-
try {
|
|
186
|
-
json = await response.json();
|
|
187
|
-
} catch {
|
|
188
|
-
return {};
|
|
189
|
-
}
|
|
190
|
-
return isRecord(json) ? json : {};
|
|
191
|
-
}
|
|
192
196
|
async function serverFetch(path, { method = "GET", body } = {}) {
|
|
193
197
|
const init = { method, credentials: "include" };
|
|
194
198
|
if (method === "POST") init.headers = { "Content-Type": "application/json", "X-Tether-Account": "1" };
|
|
195
199
|
if (body) init.body = JSON.stringify(body);
|
|
196
|
-
const response = await fetchFromWorker(`${serverBase()}${path}`, init);
|
|
200
|
+
const { response, data } = await fetchFromWorker(`${serverBase()}${path}`, init);
|
|
197
201
|
if (response.status === 401) return { kind: "logged-out" };
|
|
198
|
-
const data = await readJsonObjectOrEmpty(response);
|
|
199
202
|
if (!response.ok) {
|
|
200
203
|
const reason = textOrNull(data["error"]) ?? String(response.status);
|
|
201
204
|
const userErrors = toUserErrors(data["userErrors"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var Tt=Object.defineProperty;var St=(t,e)=>{for(var r in e)Tt(t,r,{get:e[r],enumerable:!0})};var j={};St(j,{addresses:()=>re,customer:()=>F,deleteAddress:()=>oe,isLoggedIn:()=>yt,login:()=>xt,logout:()=>Ot,mountAccount:()=>de,order:()=>te,orders:()=>At,render:()=>U,requestReturn:()=>ae,saveAddress:()=>ne,subscriptionAction:()=>ie,subscriptions:()=>se,updateProfile:()=>ee});var Lt=window.Tether.__core["config.ts"],[u,fe,V,ge,pe,y,we]=Lt;var bt=window.Tether.__core["client.ts"],[ye,xe,Ae,Oe,ke,p]=bt;var Et=window.Tether.__core["dom.ts"],[Te,Se,Le,be,P,B,T,m,Ee,Re,G,Ie,Ne,Ce,ve,d,R,Ue,c,I,_e,A,S]=Et;var Rt=window.Tether.__core["cart.ts"],[L]=Rt;var It=window.Tether.__core["lazy.ts"],[J]=It;function g(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function a(t,e){return g(t)?t[e]:void 0}function _(t){return Array.isArray(t)?t:[]}function i(t){return typeof t=="string"&&t!==""?t:null}var Nt=t=>typeof t=="number"&&Number.isFinite(t)?t:null,K=t=>Nt(t)??0,N=(t,e)=>_(t).map(r=>e(r)),X=(t,e)=>({nodes:N(a(t,"nodes"),e)}),$=t=>N(t,i).filter(e=>e!==null);function z(t){return t instanceof Error?t.message:String(t)}function W(t,e,r="localStorage"){try{window[r].setItem(t,e)}catch{}}function D(t,e="localStorage"){try{window[e].removeItem(t)}catch{}}var M=()=>`${u.prefix}:account-hint:${u.domain}`;var Z=t=>t==="in"||t==="expired"||t==="error";function Ct(t){let e=i(a(t,"amount")),r=i(a(t,"currencyCode"));return e===null||r===null?null:{amount:e,currencyCode:r}}function vt(t){let e=i(a(t,"url"));return e===null?null:{url:e,altText:i(a(t,"altText"))}}var Ut=t=>({title:i(a(t,"title")),variantTitle:i(a(t,"variantTitle")),quantity:K(a(t,"quantity")),image:vt(a(t,"image"))}),_t=(t,e)=>({id:e,name:i(a(t,"name")),processedAt:i(a(t,"processedAt")),financialStatus:i(a(t,"financialStatus")),fulfillmentStatus:i(a(t,"fulfillmentStatus")),statusPageUrl:i(a(t,"statusPageUrl")),totalPrice:Ct(a(t,"totalPrice")),lineItems:X(a(t,"lineItems"),Ut)});function Y(t){let e=[];for(let r of _(t)){let n=i(a(r,"id"));if(n===null)return{kind:"missing-id"};e.push(_t(r,n))}return{kind:"read",orders:e}}var $t=t=>new p(`Customer accounts: the answer has no ${t}`);function Q(t){let e=g(t)?t:{},r=i(e.id),n=i(e.email),o=e.address;return{...r===null?{}:{id:r},firstName:i(e.firstName),lastName:i(e.lastName),displayName:i(e.displayName),emailAddress:n===null?null:{emailAddress:n},defaultAddress:Array.isArray(o)?{formatted:$(o)}:null}}function tt(t){let e=Y(t);if(e.kind==="missing-id")throw $t("order id");return e.orders}function Dt(t){let e=i(a(t,"message"));if(e===null)return null;let r=a(t,"field");return{message:e,field:Array.isArray(r)?$(r):null,code:i(a(t,"code"))}}var et=t=>N(t,Dt).filter(e=>e!==null);var x=null;function rt(){let t=u.account?.server;if(!t)throw new p("Customer accounts need the Worker: set account.server",{code:"NOT_CONFIGURED"});return new URL(t,window.location.href).href.replace(/\/$/,"")}function nt(t){t?W(M(),"1"):D(M())}async function Mt(t,e){try{return await fetch(t,e)}catch(r){throw new p(`Network error: ${z(r)}`,{code:"NETWORK"})}}async function qt(t){let e;try{e=await t.json()}catch{return{}}return g(e)?e:{}}async function O(t,{method:e="GET",body:r}={}){let n={method:e,credentials:"include"};e==="POST"&&(n.headers={"Content-Type":"application/json","X-Tether-Account":"1"}),r&&(n.body=JSON.stringify(r));let o=await Mt(`${rt()}${t}`,n);if(o.status===401)return{kind:"logged-out"};let s=await qt(o);if(!o.ok){let l=i(s.error)??String(o.status),w=et(s.userErrors);throw new p(`Customer accounts: ${l}`,{status:o.status,...w.length>0&&{userErrors:w},...s.code==="INVALID"&&{code:"INVALID"}})}return{kind:"answer",data:s}}async function C(){if(!x){let t=await O("/me");x=t.kind==="answer"&&t.data.loggedIn===!0?{loggedIn:!0,customer:Q(t.data.customer)}:{loggedIn:!1}}return nt(x.loggedIn),x}var ot=()=>x?.loggedIn===!0;function st(){x=null}function it(t){let e=u.account?.navigate;e?e(t):window.location.assign(t)}var Ft=t=>t||u.account?.locale||(u.locale||"").split("-")[0]||"";function at({returnTo:t,locale:e}){let r=new URL(`${rt()}/login`);r.searchParams.set("returnTo",t);let n=Ft(e);n&&r.searchParams.set("locale",n),u.country&&r.searchParams.set("country",u.country.toUpperCase()),it(r.toString())}async function ct(){let t=L.id();if(!(await C()).loggedIn||!t)return null;let e=await O("/cart",{method:"POST",body:{cartId:t}});return e.kind==="logged-out"?null:i(e.data.checkoutUrl)}async function ut(t){let e=await O("/logout",{method:"POST",body:{returnTo:t,cartId:L.id()}});x=null,nt(!1),P("account-logout",{});let r=e.kind==="answer"?i(e.data.logoutUrl):null;return r?(it(r),"redirected"):"stayed"}var jt=window.Tether.__core["shopify-values.ts"],[dt,ar]=jt;function b(t,e,r){d(t,c(e)).forEach(n=>{let o=m(n,e)??"";Object.hasOwn(r,o)&&S(n,r[o]===!0)})}var lt=(t,e)=>d(t,c(e)).concat(t.matches(c(e))?[t]:[]);var k=(t,e)=>Object.hasOwn(t,e)?t[e]:void 0;var Ht=(t,e)=>({title:t.title||t.name||"","variant-title":t.variantTitle||"",quantity:String(t.quantity),price:T(t.price),total:T(t.totalPrice),sku:t.sku||"",returnable:e===null?void 0:String(e)}),Vt=t=>t.tagName==="INPUT";function Bt(t,e,r){b(t,"order-line-show",{returnable:r>0}),d(t,c("return-quantity")).forEach(n=>{Vt(n)&&(n.max=String(r),n.min="0",n.value||(n.value="0"),n.disabled=r<1)}),d(t,`select${c("return-reason")}`).forEach(n=>{n.dataset.tetherFilled!==e.id&&(n.dataset.tetherFilled=e.id,(e.suggestedReturnReasonDefinitions?.nodes??[]).forEach(o=>{n.appendChild(new Option(o.name??"",o.id))}))})}function mt(t,e,r){R(t,e,(n,o)=>{let s=o.id,l=r&&s?r.get(s)??0:null;s&&(n.dataset.tetherLine=s);let w=Ht(o,l);lt(n,"order-line").forEach(h=>{let E=m(h,"order-line")??"";if(E==="image"){o.image&&I(h,o.image.url,o.image.altText||o.title||"");return}let H=k(w,E);H!==void 0&&A(h,H)}),s&&l!==null&&Bt(n,{...o,id:s},l)})}var q=10,v=50,ft=t=>typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=v,Gt=t=>G(t,"limit",{min:1,max:v,fallback:q}),Jt=t=>t.replace(/\?.*$/,"").replace(/^.*\//,"");function Kt(t){let e=u.account?.orderUrl;if(e)return e.replaceAll("{id}",encodeURIComponent(Jt(t.id)));let r=t.statusPageUrl;return r!==null&&dt(r)?r:null}var Xt=t=>({name:t.name??"",date:B(t.processedAt),total:T(t.totalPrice),status:t.financialStatus?.toLowerCase(),fulfillment:t.fulfillmentStatus?.toLowerCase(),items:t.lineItems.nodes.map(e=>`${String(e.quantity)}\xD7 ${e.title??""}`).join(", ")});function zt(t,e){let r=e.lineItems.nodes,n=Kt(e),o=Xt(e);d(t,c("order-bind")).forEach(s=>{let l=m(s,"order-bind")??"";if(l==="url"){n&&s.setAttribute("href",n);return}if(l==="image"){let h=r.find(E=>E.image)?.image;h&&I(s,h.url,h.altText||r[0]?.title||"");return}let w=k(o,l);w!==void 0&&A(s,w)}),d(t,c("order-lines")).forEach(s=>{mt(s,r,null)}),m(t,"order-bind")==="url"&&n&&t.setAttribute("href",n)}async function gt(t,e){let r=d(t,c("orders")),n=r[0];if(!n)return;b(t,"show",{"orders-loading":!0,"orders-empty":!1});let o=Gt(n),s;try{s=await e(o)}catch(l){y(l,"orders"),s=null}b(t,"show",{"orders-loading":!1,"orders-empty":s?.length===0}),r.forEach(l=>{R(l,s??[],zt)})}var Wt=["order","addresses","subscriptions","profile-form","address-form"],yt=ot;function xt({returnTo:t=window.location.href,locale:e}={}){return new Promise(r=>{at({returnTo:t,locale:e}),r()})}async function F(){let t=await C();return t.loggedIn?t.customer:null}async function At({first:t=q}={}){if(!ft(t))throw new p(`Customer accounts: orders() takes first from 1 to ${String(v)}`,{code:"INVALID"});let e=await O(`/orders?${new URLSearchParams({first:String(t)}).toString()}`);return e.kind==="logged-out"?[]:tt(e.data.orders)}async function Ot({returnTo:t=u.account?.logoutUrl||`${window.location.origin}/`}={}){await ut(t)==="stayed"&&await U(document)}async function Zt(){try{return(await C()).loggedIn?{kind:"logged-in"}:{kind:"logged-out"}}catch(t){return{kind:"unknown",error:t}}}var pt=t=>Wt.some(e=>d(t,c(e)).length>0);function Yt(t){d(t,c("account-link")).forEach(e=>{e.setAttribute("href",Qt(m(e,"account-link")))})}function Qt(t){let e=u.account,r=`https://${u.domain}/account`;return t==="payment"?e?.paymentUrl||e?.subscriptionsUrl||r:t==="subscriptions"&&e?.subscriptionsUrl||r}async function U(t=document){let e=await Zt();e.kind==="unknown"&&y(e.error,"account");let r=e.kind==="logged-in";if(d(t,c("show")).forEach(n=>{let o=m(n,"show");o==="logged-in"&&S(n,r),o==="logged-out"&&S(n,!r)}),Yt(t),e.kind==="unknown"&&pt(t)){(await f()).showUnavailable(t);return}r&&(await kt(t),await Promise.all([gt(t,n=>At({first:n})),pt(t)?f().then(n=>n.renderPages(t)):null]))}async function kt(t){let e=d(t,c("account-bind"));if(!e.length)return;let r;try{r=await F()}catch(o){y(o,"account");return}if(!r)return;let n={"first-name":r.firstName,"last-name":r.lastName,name:r.displayName,email:r.emailAddress?.emailAddress,address:r.defaultAddress?.formatted.join(", ")};e.forEach(o=>{let s=k(n,m(o,"account-bind")??"");s!=null&&A(o,s)})}var wt=null;function f(){return wt??(wt=J("account-pages").then(t=>(t.setup({serverFetch:O,customer:F,bindCustomer:kt,reset:st}),t))),wt}var te=t=>f().then(e=>e.order(t)),ee=t=>f().then(e=>e.updateProfile(t)),re=()=>f().then(t=>t.addresses()),ne=(t,e)=>f().then(r=>r.saveAddress(t,e)),oe=t=>f().then(e=>e.deleteAddress(t)),se=()=>f().then(t=>t.subscriptions()),ie=(t,e)=>f().then(r=>r.subscriptionAction(t,e)),ae=(t,e)=>f().then(r=>r.requestReturn(t,e));function ce(t){let e=t.target;e instanceof window.Element&&(e.closest(c("account-login"))?(t.preventDefault(),xt().catch(r=>{y(r,"login")})):e.closest(c("account-logout"))&&(t.preventDefault(),Ot().catch(r=>{y(r,"logout")})))}function ue(){let t=new URL(window.location.href),e=t.searchParams.get("account");if(Z(e))switch(t.searchParams.delete("account"),window.history.replaceState(window.history.state,"",t),e){case"in":P("account-login",{});break;case"expired":case"error":P("account-error",{error:e});break}}var ht=!1;async function de(t=document){if(ht){await U(t);return}ht=!0,document.addEventListener("click",ce),ue(),L.setCheckoutResolver(ct),await U(t),V("account",yt()?"logged in":"logged out")}function le(t){return g(t)&&g(t.__core)&&g(t.__parts)}function Pt(t,e){let r=Reflect.get(window,"Tether");if(!le(r))throw new Error(`tether.${t}.js runs after the Tether script, which loads it, and needs its window.Tether`);r.__parts[t]=e}Pt("account",j);})();
|
|
1
|
+
(()=>{var St=Object.defineProperty;var Lt=(t,e)=>{for(var r in e)St(t,r,{get:e[r],enumerable:!0})};var j={};Lt(j,{addresses:()=>ne,customer:()=>F,deleteAddress:()=>se,isLoggedIn:()=>xt,login:()=>At,logout:()=>kt,mountAccount:()=>le,order:()=>ee,orders:()=>Ot,render:()=>U,requestReturn:()=>ce,saveAddress:()=>oe,subscriptionAction:()=>ae,subscriptions:()=>ie,updateProfile:()=>re});var bt=window.Tether.__core["config.ts"],[u,ge,V,pe,we,y,he]=bt;var Et=window.Tether.__core["client.ts"],[xe,Ae,Oe,ke,Te,p,B]=Et;var Rt=window.Tether.__core["dom.ts"],[Se,Le,be,Ee,T,G,P,m,Re,Ie,J,Ne,Ce,ve,Ue,d,R,_e,c,I,$e,A,S]=Rt;var It=window.Tether.__core["cart.ts"],[L]=It;var Nt=window.Tether.__core["lazy.ts"],[K]=Nt;function g(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function a(t,e){return g(t)?t[e]:void 0}function _(t){return Array.isArray(t)?t:[]}function i(t){return typeof t=="string"&&t!==""?t:null}var Ct=t=>typeof t=="number"&&Number.isFinite(t)?t:null,X=t=>Ct(t)??0,N=(t,e)=>_(t).map(r=>e(r)),z=(t,e)=>({nodes:N(a(t,"nodes"),e)}),$=t=>N(t,i).filter(e=>e!==null);function W(t){return t instanceof Error?t.message:String(t)}function Z(t,e,r="localStorage"){try{window[r].setItem(t,e)}catch{}}function q(t,e="localStorage"){try{window[e].removeItem(t)}catch{}}var D=()=>`${u.prefix}:account-hint:${u.domain}`;var Y=t=>t==="in"||t==="expired"||t==="error";function vt(t){let e=i(a(t,"amount")),r=i(a(t,"currencyCode"));return e===null||r===null?null:{amount:e,currencyCode:r}}function Ut(t){let e=i(a(t,"url"));return e===null?null:{url:e,altText:i(a(t,"altText"))}}var _t=t=>({title:i(a(t,"title")),variantTitle:i(a(t,"variantTitle")),quantity:X(a(t,"quantity")),image:Ut(a(t,"image"))}),$t=(t,e)=>({id:e,name:i(a(t,"name")),processedAt:i(a(t,"processedAt")),financialStatus:i(a(t,"financialStatus")),fulfillmentStatus:i(a(t,"fulfillmentStatus")),statusPageUrl:i(a(t,"statusPageUrl")),totalPrice:vt(a(t,"totalPrice")),lineItems:z(a(t,"lineItems"),_t)});function Q(t){let e=[];for(let r of _(t)){let n=i(a(r,"id"));if(n===null)return{kind:"missing-id"};e.push($t(r,n))}return{kind:"read",orders:e}}var qt=t=>new p(`Customer accounts: the answer has no ${t}`);function tt(t){let e=g(t)?t:{},r=i(e.id),n=i(e.email),o=e.address;return{...r===null?{}:{id:r},firstName:i(e.firstName),lastName:i(e.lastName),displayName:i(e.displayName),emailAddress:n===null?null:{emailAddress:n},defaultAddress:Array.isArray(o)?{formatted:$(o)}:null}}function et(t){let e=Q(t);if(e.kind==="missing-id")throw qt("order id");return e.orders}function Dt(t){let e=i(a(t,"message"));if(e===null)return null;let r=a(t,"field");return{message:e,field:Array.isArray(r)?$(r):null,code:i(a(t,"code"))}}var rt=t=>N(t,Dt).filter(e=>e!==null);var x=null;function nt(){let t=u.account?.server;if(!t)throw new p("Customer accounts need the Worker: set account.server",{code:"NOT_CONFIGURED"});return new URL(t,window.location.href).href.replace(/\/$/,"")}function ot(t){t?Z(D(),"1"):q(D())}async function Mt(t){let e;try{e=await t.json()}catch(r){if(r instanceof SyntaxError)return{};throw r}return g(e)?e:{}}async function Ft(t,e){try{return await B(u.requestTimeout,async r=>{let n=await fetch(t,{...e,signal:r});return{response:n,data:await Mt(n)}})}catch(r){throw new p(`Network error: ${W(r)}`,{code:"NETWORK"})}}async function O(t,{method:e="GET",body:r}={}){let n={method:e,credentials:"include"};e==="POST"&&(n.headers={"Content-Type":"application/json","X-Tether-Account":"1"}),r&&(n.body=JSON.stringify(r));let{response:o,data:s}=await Ft(`${nt()}${t}`,n);if(o.status===401)return{kind:"logged-out"};if(!o.ok){let l=i(s.error)??String(o.status),w=rt(s.userErrors);throw new p(`Customer accounts: ${l}`,{status:o.status,...w.length>0&&{userErrors:w},...s.code==="INVALID"&&{code:"INVALID"}})}return{kind:"answer",data:s}}async function C(){if(!x){let t=await O("/me");x=t.kind==="answer"&&t.data.loggedIn===!0?{loggedIn:!0,customer:tt(t.data.customer)}:{loggedIn:!1}}return ot(x.loggedIn),x}var st=()=>x?.loggedIn===!0;function it(){x=null}function at(t){let e=u.account?.navigate;e?e(t):window.location.assign(t)}var jt=t=>t||u.account?.locale||(u.locale||"").split("-")[0]||"";function ct({returnTo:t,locale:e}){let r=new URL(`${nt()}/login`);r.searchParams.set("returnTo",t);let n=jt(e);n&&r.searchParams.set("locale",n),u.country&&r.searchParams.set("country",u.country.toUpperCase()),at(r.toString())}async function ut(){let t=L.id();if(!(await C()).loggedIn||!t)return null;let e=await O("/cart",{method:"POST",body:{cartId:t}});return e.kind==="logged-out"?null:i(e.data.checkoutUrl)}async function dt(t){let e=await O("/logout",{method:"POST",body:{returnTo:t,cartId:L.id()}});x=null,ot(!1),T("account-logout",{});let r=e.kind==="answer"?i(e.data.logoutUrl):null;return r?(at(r),"redirected"):"stayed"}var Ht=window.Tether.__core["shopify-values.ts"],[lt,cr]=Ht;function b(t,e,r){d(t,c(e)).forEach(n=>{let o=m(n,e)??"";Object.hasOwn(r,o)&&S(n,r[o]===!0)})}var mt=(t,e)=>d(t,c(e)).concat(t.matches(c(e))?[t]:[]);var k=(t,e)=>Object.hasOwn(t,e)?t[e]:void 0;var Vt=(t,e)=>({title:t.title||t.name||"","variant-title":t.variantTitle||"",quantity:String(t.quantity),price:P(t.price),total:P(t.totalPrice),sku:t.sku||"",returnable:e===null?void 0:String(e)}),Bt=t=>t.tagName==="INPUT";function Gt(t,e,r){b(t,"order-line-show",{returnable:r>0}),d(t,c("return-quantity")).forEach(n=>{Bt(n)&&(n.max=String(r),n.min="0",n.value||(n.value="0"),n.disabled=r<1)}),d(t,`select${c("return-reason")}`).forEach(n=>{n.dataset.tetherFilled!==e.id&&(n.dataset.tetherFilled=e.id,(e.suggestedReturnReasonDefinitions?.nodes??[]).forEach(o=>{n.appendChild(new Option(o.name??"",o.id))}))})}function ft(t,e,r){R(t,e,(n,o)=>{let s=o.id,l=r&&s?r.get(s)??0:null;s&&(n.dataset.tetherLine=s);let w=Vt(o,l);mt(n,"order-line").forEach(h=>{let E=m(h,"order-line")??"";if(E==="image"){o.image&&I(h,o.image.url,o.image.altText||o.title||"");return}let H=k(w,E);H!==void 0&&A(h,H)}),s&&l!==null&&Gt(n,{...o,id:s},l)})}var M=10,v=50,gt=t=>typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=v,Jt=t=>J(t,"limit",{min:1,max:v,fallback:M}),Kt=t=>t.replace(/\?.*$/,"").replace(/^.*\//,"");function Xt(t){let e=u.account?.orderUrl;if(e)return e.replaceAll("{id}",encodeURIComponent(Kt(t.id)));let r=t.statusPageUrl;return r!==null&<(r)?r:null}var zt=t=>({name:t.name??"",date:G(t.processedAt),total:P(t.totalPrice),status:t.financialStatus?.toLowerCase(),fulfillment:t.fulfillmentStatus?.toLowerCase(),items:t.lineItems.nodes.map(e=>`${String(e.quantity)}\xD7 ${e.title??""}`).join(", ")});function Wt(t,e){let r=e.lineItems.nodes,n=Xt(e),o=zt(e);d(t,c("order-bind")).forEach(s=>{let l=m(s,"order-bind")??"";if(l==="url"){n&&s.setAttribute("href",n);return}if(l==="image"){let h=r.find(E=>E.image)?.image;h&&I(s,h.url,h.altText||r[0]?.title||"");return}let w=k(o,l);w!==void 0&&A(s,w)}),d(t,c("order-lines")).forEach(s=>{ft(s,r,null)}),m(t,"order-bind")==="url"&&n&&t.setAttribute("href",n)}async function pt(t,e){let r=d(t,c("orders")),n=r[0];if(!n)return;b(t,"show",{"orders-loading":!0,"orders-empty":!1});let o=Jt(n),s;try{s=await e(o)}catch(l){y(l,"orders"),s=null}b(t,"show",{"orders-loading":!1,"orders-empty":s?.length===0}),r.forEach(l=>{R(l,s??[],Wt)})}var Zt=["order","addresses","subscriptions","profile-form","address-form"],xt=st;function At({returnTo:t=window.location.href,locale:e}={}){return new Promise(r=>{ct({returnTo:t,locale:e}),r()})}async function F(){let t=await C();return t.loggedIn?t.customer:null}async function Ot({first:t=M}={}){if(!gt(t))throw new p(`Customer accounts: orders() takes first from 1 to ${String(v)}`,{code:"INVALID"});let e=await O(`/orders?${new URLSearchParams({first:String(t)}).toString()}`);return e.kind==="logged-out"?[]:et(e.data.orders)}async function kt({returnTo:t=u.account?.logoutUrl||`${window.location.origin}/`}={}){await dt(t)==="stayed"&&await U(document)}async function Yt(){try{return(await C()).loggedIn?{kind:"logged-in"}:{kind:"logged-out"}}catch(t){return{kind:"unknown",error:t}}}var wt=t=>Zt.some(e=>d(t,c(e)).length>0);function Qt(t){d(t,c("account-link")).forEach(e=>{e.setAttribute("href",te(m(e,"account-link")))})}function te(t){let e=u.account,r=`https://${u.domain}/account`;return t==="payment"?e?.paymentUrl||e?.subscriptionsUrl||r:t==="subscriptions"&&e?.subscriptionsUrl||r}async function U(t=document){let e=await Yt();e.kind==="unknown"&&y(e.error,"account");let r=e.kind==="logged-in";if(d(t,c("show")).forEach(n=>{let o=m(n,"show");o==="logged-in"&&S(n,r),o==="logged-out"&&S(n,!r)}),Qt(t),e.kind==="unknown"&&wt(t)){(await f()).showUnavailable(t);return}r&&(await Tt(t),await Promise.all([pt(t,n=>Ot({first:n})),wt(t)?f().then(n=>n.renderPages(t)):null]))}async function Tt(t){let e=d(t,c("account-bind"));if(!e.length)return;let r;try{r=await F()}catch(o){y(o,"account");return}if(!r)return;let n={"first-name":r.firstName,"last-name":r.lastName,name:r.displayName,email:r.emailAddress?.emailAddress,address:r.defaultAddress?.formatted.join(", ")};e.forEach(o=>{let s=k(n,m(o,"account-bind")??"");s!=null&&A(o,s)})}var ht=null;function f(){return ht??(ht=K("account-pages").then(t=>(t.setup({serverFetch:O,customer:F,bindCustomer:Tt,reset:it}),t))),ht}var ee=t=>f().then(e=>e.order(t)),re=t=>f().then(e=>e.updateProfile(t)),ne=()=>f().then(t=>t.addresses()),oe=(t,e)=>f().then(r=>r.saveAddress(t,e)),se=t=>f().then(e=>e.deleteAddress(t)),ie=()=>f().then(t=>t.subscriptions()),ae=(t,e)=>f().then(r=>r.subscriptionAction(t,e)),ce=(t,e)=>f().then(r=>r.requestReturn(t,e));function ue(t){let e=t.target;e instanceof window.Element&&(e.closest(c("account-login"))?(t.preventDefault(),At().catch(r=>{y(r,"login")})):e.closest(c("account-logout"))&&(t.preventDefault(),kt().catch(r=>{y(r,"logout")})))}function de(){let t=new URL(window.location.href),e=t.searchParams.get("account");if(Y(e))switch(t.searchParams.delete("account"),window.history.replaceState(window.history.state,"",t),e){case"in":T("account-login",{});break;case"expired":case"error":T("account-error",{error:e});break}}var yt=!1;async function le(t=document){if(yt){await U(t);return}yt=!0,document.addEventListener("click",ue),de(),L.setCheckoutResolver(ut),await U(t),V("account",xt()?"logged in":"logged out")}function me(t){return g(t)&&g(t.__core)&&g(t.__parts)}function Pt(t,e){let r=Reflect.get(window,"Tether");if(!me(r))throw new Error(`tether.${t}.js runs after the Tether script, which loads it, and needs its window.Tether`);r.__parts[t]=e}Pt("account",j);})();
|
package/dist/tether.analytics.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
// tether-core:client.ts
|
|
31
31
|
var m5 = window.Tether.__core["client.ts"];
|
|
32
|
-
var [endpoint, gql, matches, orNull, shaped, TetherError] = m5;
|
|
32
|
+
var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m5;
|
|
33
33
|
|
|
34
34
|
// src/analytics-shopify.ts
|
|
35
35
|
var BUFFER_SIZE = 500;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var U=Object.defineProperty;var $=(t,n)=>{for(var e in n)U(t,e,{get:n[e],enumerable:!0})};var k={};$(k,{startAnalytics:()=>yt});var G=window.Tether.__core["config.ts"],[a,bt,_,vt,wt,l,Tt]=G;var H=window.Tether.__core["dom.ts"],[C,_t,Ct,Et,xt,At,St,Pt,Lt,Nt,It,E,Rt,Vt,Dt,Mt,qt,Bt,p,Ot,Ft,jt,Ut]=H;var W=window.Tether.__core["cart.ts"],[b]=W;var Y=window.Tether.__core["product.ts"],[x]=Y;var J=window.Tether.__core["client.ts"],[Wt,A,Yt,Jt,S,Zt]=J;var Z=500,P={"default-banner":"https://cdn.shopify.com/shopifycloud/privacy-banner/storefront-banner.js",other:"https://cdn.shopify.com/shopifycloud/consent-tracking-api/v0.2/consent-tracking-api.js"},z="https://cdn.shopify.com/storefront/analytics/shopify.js",N=()=>window,y=()=>N().Shopify;function I(){let t=a.analytics?.shopify;return typeof t=="object"?t:{}}function R(){try{let t=y()?.customerPrivacy;return t?.consentStatus==="loaded"&&t.currentVisitorConsent?.()?.analytics!=="no"&&!!t.analyticsProcessingAllowed?.()}catch{return!1}}function K(t){let n=`hydrogen:${t}`;return{getTrackingValues:()=>{let e=R()?y()?.customerPrivacy?.__internal:void 0;return{uniqueToken:e?.uniqueToken?.({generateFallback:!0,tag:n})??"",visitToken:e?.visitToken?.({generateFallback:!0,tag:n})??""}}}}var X=t=>(n,e)=>{let o=t.subscribers.get(n)??new Set;return t.subscribers.set(n,o),o.add(e),()=>t.subscribers.get(n)?.delete(e)};function Q(t){let n=[],e=[],o={shop:{shopId:t,channel:"headless"},consent:{mode:I().consent||"no-banner"}},r=()=>{if(R())for(let i of n)for(;i.next<e.length;i.next+=1){let s=e[i.next];s&&tt(i,s)}},c={getConfig:()=>o,publish(i,s={}){if(e.push({event:i,payload:{shop:o.shop,url:window.location.href,...s}}),e.length>Z){e.shift();for(let u of n)u.next=Math.max(0,u.next-1)}r()},addDestination(i){let s={name:i.name,next:0,subscribers:new Map,context:K(i.name)};return Promise.resolve(i.setup?.({subscribe:X(s),getConfig:c.getConfig})).then(()=>{n.push(s),r()}).catch(u=>{l(u,`analytics ${i.name}`)}),()=>{let u=n.indexOf(s);u>=0&&n.splice(u,1)}}};return document.addEventListener("consentTrackingApiLoaded",r),document.addEventListener("visitorConsentCollected",r),c}function tt(t,{event:n,payload:e}){t.subscribers.get(n)?.forEach(o=>{try{o(e,t.context)}catch(r){l(r,`analytics ${t.name}`)}})}function L(t){let n=document.createElement("script");n.src=t,n.async=!0,document.head.appendChild(n)}async function V(t){let n=y();if(n?.analytics)return n.analytics;let e=await A("query TetherShopId { shop { id } }",{},S({shop:{id:"string"}}),{context:!1}),o=y()??{};N().Shopify=o,o.country=a.country??"US";let[r="en"]=(a.locale||"en").split("-");o.locale=r.toLowerCase(),o.shop=a.domain,o.routes={root:"/",match:()=>({pageTemplateName:t()?"product":"page"}),...o.routes};let{proxy:c,consent:i}=I();o.customerPrivacy={...o.customerPrivacy,config:c?{isHeadless:!0,asyncConsent:!0,asyncVisitorState:!0,consentDomain:window.location.host}:{isHeadless:!0,storefrontAccessToken:a.token,checkoutRootDomain:a.domain}};let s=Q(e.shop.id);return o.analytics=s,L(i==="default-banner"?P["default-banner"]:P.other),L(z),_("shopify analytics ready",e.shop.id),s}var nt="Default Title",D=100,et=200,ot=t=>t?parseFloat(t.amount):0,M=t=>(t??"").split("/").pop()??"";function T(t,n,e=1,o){let r={item_id:n?.sku||M(n?.id)||M(t.id),item_name:t.title,item_variant:n?.title===nt?void 0:n?.title,item_brand:t.vendor||void 0,item_category:t.productType||void 0,price:ot(n?.price??t.priceRange?.minVariantPrice),quantity:e};return o!=null&&(r.index=o),r}var h=(t,n=t.quantity)=>T(t.merchandise.product,t.merchandise,n);function f(t){let n=t.reduce((e,o)=>e+o.price*(o.quantity||1),0);return Math.round(n*D)/D}var rt=(t,n,e=1)=>({id:t.id,title:t.title,price:n.price,vendor:t.vendor||"",variantId:n.id,variantTitle:n.title,quantity:e,sku:n.sku||void 0,productType:t.productType||void 0}),q=t=>({id:t.id,quantity:t.quantity,merchandise:{id:t.merchandise.id,title:t.merchandise.title,price:t.merchandise.price,sku:t.merchandise.sku,product:{id:t.merchandise.product.id,title:t.merchandise.product.title,vendor:t.merchandise.product.vendor||"",handle:t.merchandise.product.handle}}});function it(){let{dataLayer:t}=a.analytics??{},n=typeof t=="string"?t:"dataLayer",e=Reflect.get(window,n);if(Array.isArray(e))return e;let o=[];return Reflect.set(window,n,o),o}function st(t,n){let e=it();if(!n){e.push({event:t});return}e.push({ecommerce:null}),e.push({event:t,ecommerce:n})}var m=null,v=null,O=null,w=new WeakSet;function d(t,n,e,o){a.analytics?.dataLayer&&st(t,n),m&&e&&m.publish(e,o);try{a.analytics?.onEvent?.(t,n)}catch(r){l(r,"analytics onEvent")}}function F(){let t=document.querySelector(p("product"));return!t||t.closest(`${p("collection")},${p("products")},${p("recommendations")}`)?null:x.get(t)??null}function at({product:t,scope:n}){if(w.has(n.root)||F()!==n)return;w.add(n.root);let e=n.variant??t.variants.nodes[0],o=[T(t,e)],r=e?[rt(t,e)]:[];d("view_item",{currency:e?.price.currencyCode,value:f(o),items:o},"product_viewed",{products:r})}function ct({products:t,collection:n}){let e=t.slice(0,et).map((r,c)=>T(r,r.variants.nodes[0],1,c)),o={item_list_id:n?.handle||"products",item_list_name:n?.title||"Products"};if(!n){d("view_item_list",{...o,items:e});return}d("view_item_list",{...o,items:e},"collection_viewed",{collection:{id:n.id,handle:n.handle}})}function ut(t,n,e){let o=t?.cost.totalAmount.currencyCode;n.forEach((r,c)=>{let i=e.get(c),s=r.quantity-(i?.quantity??0);if(s<=0)return;let u=[h(r,s)];d("add_to_cart",{currency:o,value:f(u),items:u},"product_added_to_cart",{cart:t,prevCart:O,currentLine:q(r),prevLine:i?q(i):void 0})}),e.forEach((r,c)=>{let i=r.quantity-(n.get(c)?.quantity??0);if(i<=0)return;let s=[h(r,i)];d("remove_from_cart",{currency:o,value:f(s),items:s})})}function dt({cart:t,reason:n}){let e=new Map((t?.lines.nodes??[]).map(o=>[o.merchandise.id,o]));v&&n!=="load"&&n!=="pending"&&ut(t,e,v),v=e,O=t}function lt(){let t=b.lines.map(n=>h(n));d("view_cart",{currency:b.state?.cost.totalAmount.currencyCode,value:f(t),items:t})}function pt({cart:t}){if(!t)return;let n=t.lines.nodes.map(o=>h(o)),e=t.discountCodes.filter(o=>o.applicable).map(o=>o.code);d("begin_checkout",{currency:t.cost.totalAmount.currencyCode,value:f(n),coupon:e.join(",")||void 0,items:n})}var ft={"product-ready":at,"list-ready":ct,"cart-updated":dt,"cart-toggled":({open:t})=>{t&<()},checkout:pt,search:({term:t})=>{t&&d("search",{search_term:t},"search_viewed",{searchTerm:t})}};function mt(t,n){ft[n](t.detail)}function B(t){if(t.type==="astro:page-load"){w=new WeakSet,m?.publish("page_viewed",{});return}C.forEach(n=>{E(t,n)&&mt(t,n)})}async function yt(t){a.analytics?.shopify&&(m=await V(()=>F()!=null).catch(n=>(l(n,"shopify analytics"),null))),m?.publish("page_viewed",{}),t.splice(0).forEach(B),t.push=(...n)=>(n.forEach(B),t.length)}function g(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ht(t){return g(t)&&g(t.__core)&&g(t.__parts)}function j(t,n){let e=Reflect.get(window,"Tether");if(!ht(e))throw new Error(`tether.${t}.js runs after the Tether script, which loads it, and needs its window.Tether`);e.__parts[t]=n}j("analytics",k);})();
|
|
1
|
+
(()=>{var U=Object.defineProperty;var $=(t,n)=>{for(var e in n)U(t,e,{get:n[e],enumerable:!0})};var k={};$(k,{startAnalytics:()=>yt});var G=window.Tether.__core["config.ts"],[a,bt,_,vt,wt,l,Tt]=G;var H=window.Tether.__core["dom.ts"],[C,_t,Ct,Et,xt,At,St,Pt,Lt,Nt,It,E,Rt,Vt,Dt,Mt,qt,Bt,p,Ot,Ft,jt,Ut]=H;var W=window.Tether.__core["cart.ts"],[b]=W;var Y=window.Tether.__core["product.ts"],[x]=Y;var J=window.Tether.__core["client.ts"],[Wt,A,Yt,Jt,S,Zt,zt]=J;var Z=500,P={"default-banner":"https://cdn.shopify.com/shopifycloud/privacy-banner/storefront-banner.js",other:"https://cdn.shopify.com/shopifycloud/consent-tracking-api/v0.2/consent-tracking-api.js"},z="https://cdn.shopify.com/storefront/analytics/shopify.js",N=()=>window,y=()=>N().Shopify;function I(){let t=a.analytics?.shopify;return typeof t=="object"?t:{}}function R(){try{let t=y()?.customerPrivacy;return t?.consentStatus==="loaded"&&t.currentVisitorConsent?.()?.analytics!=="no"&&!!t.analyticsProcessingAllowed?.()}catch{return!1}}function K(t){let n=`hydrogen:${t}`;return{getTrackingValues:()=>{let e=R()?y()?.customerPrivacy?.__internal:void 0;return{uniqueToken:e?.uniqueToken?.({generateFallback:!0,tag:n})??"",visitToken:e?.visitToken?.({generateFallback:!0,tag:n})??""}}}}var X=t=>(n,e)=>{let o=t.subscribers.get(n)??new Set;return t.subscribers.set(n,o),o.add(e),()=>t.subscribers.get(n)?.delete(e)};function Q(t){let n=[],e=[],o={shop:{shopId:t,channel:"headless"},consent:{mode:I().consent||"no-banner"}},r=()=>{if(R())for(let i of n)for(;i.next<e.length;i.next+=1){let s=e[i.next];s&&tt(i,s)}},c={getConfig:()=>o,publish(i,s={}){if(e.push({event:i,payload:{shop:o.shop,url:window.location.href,...s}}),e.length>Z){e.shift();for(let u of n)u.next=Math.max(0,u.next-1)}r()},addDestination(i){let s={name:i.name,next:0,subscribers:new Map,context:K(i.name)};return Promise.resolve(i.setup?.({subscribe:X(s),getConfig:c.getConfig})).then(()=>{n.push(s),r()}).catch(u=>{l(u,`analytics ${i.name}`)}),()=>{let u=n.indexOf(s);u>=0&&n.splice(u,1)}}};return document.addEventListener("consentTrackingApiLoaded",r),document.addEventListener("visitorConsentCollected",r),c}function tt(t,{event:n,payload:e}){t.subscribers.get(n)?.forEach(o=>{try{o(e,t.context)}catch(r){l(r,`analytics ${t.name}`)}})}function L(t){let n=document.createElement("script");n.src=t,n.async=!0,document.head.appendChild(n)}async function V(t){let n=y();if(n?.analytics)return n.analytics;let e=await A("query TetherShopId { shop { id } }",{},S({shop:{id:"string"}}),{context:!1}),o=y()??{};N().Shopify=o,o.country=a.country??"US";let[r="en"]=(a.locale||"en").split("-");o.locale=r.toLowerCase(),o.shop=a.domain,o.routes={root:"/",match:()=>({pageTemplateName:t()?"product":"page"}),...o.routes};let{proxy:c,consent:i}=I();o.customerPrivacy={...o.customerPrivacy,config:c?{isHeadless:!0,asyncConsent:!0,asyncVisitorState:!0,consentDomain:window.location.host}:{isHeadless:!0,storefrontAccessToken:a.token,checkoutRootDomain:a.domain}};let s=Q(e.shop.id);return o.analytics=s,L(i==="default-banner"?P["default-banner"]:P.other),L(z),_("shopify analytics ready",e.shop.id),s}var nt="Default Title",D=100,et=200,ot=t=>t?parseFloat(t.amount):0,M=t=>(t??"").split("/").pop()??"";function T(t,n,e=1,o){let r={item_id:n?.sku||M(n?.id)||M(t.id),item_name:t.title,item_variant:n?.title===nt?void 0:n?.title,item_brand:t.vendor||void 0,item_category:t.productType||void 0,price:ot(n?.price??t.priceRange?.minVariantPrice),quantity:e};return o!=null&&(r.index=o),r}var h=(t,n=t.quantity)=>T(t.merchandise.product,t.merchandise,n);function f(t){let n=t.reduce((e,o)=>e+o.price*(o.quantity||1),0);return Math.round(n*D)/D}var rt=(t,n,e=1)=>({id:t.id,title:t.title,price:n.price,vendor:t.vendor||"",variantId:n.id,variantTitle:n.title,quantity:e,sku:n.sku||void 0,productType:t.productType||void 0}),q=t=>({id:t.id,quantity:t.quantity,merchandise:{id:t.merchandise.id,title:t.merchandise.title,price:t.merchandise.price,sku:t.merchandise.sku,product:{id:t.merchandise.product.id,title:t.merchandise.product.title,vendor:t.merchandise.product.vendor||"",handle:t.merchandise.product.handle}}});function it(){let{dataLayer:t}=a.analytics??{},n=typeof t=="string"?t:"dataLayer",e=Reflect.get(window,n);if(Array.isArray(e))return e;let o=[];return Reflect.set(window,n,o),o}function st(t,n){let e=it();if(!n){e.push({event:t});return}e.push({ecommerce:null}),e.push({event:t,ecommerce:n})}var m=null,v=null,O=null,w=new WeakSet;function d(t,n,e,o){a.analytics?.dataLayer&&st(t,n),m&&e&&m.publish(e,o);try{a.analytics?.onEvent?.(t,n)}catch(r){l(r,"analytics onEvent")}}function F(){let t=document.querySelector(p("product"));return!t||t.closest(`${p("collection")},${p("products")},${p("recommendations")}`)?null:x.get(t)??null}function at({product:t,scope:n}){if(w.has(n.root)||F()!==n)return;w.add(n.root);let e=n.variant??t.variants.nodes[0],o=[T(t,e)],r=e?[rt(t,e)]:[];d("view_item",{currency:e?.price.currencyCode,value:f(o),items:o},"product_viewed",{products:r})}function ct({products:t,collection:n}){let e=t.slice(0,et).map((r,c)=>T(r,r.variants.nodes[0],1,c)),o={item_list_id:n?.handle||"products",item_list_name:n?.title||"Products"};if(!n){d("view_item_list",{...o,items:e});return}d("view_item_list",{...o,items:e},"collection_viewed",{collection:{id:n.id,handle:n.handle}})}function ut(t,n,e){let o=t?.cost.totalAmount.currencyCode;n.forEach((r,c)=>{let i=e.get(c),s=r.quantity-(i?.quantity??0);if(s<=0)return;let u=[h(r,s)];d("add_to_cart",{currency:o,value:f(u),items:u},"product_added_to_cart",{cart:t,prevCart:O,currentLine:q(r),prevLine:i?q(i):void 0})}),e.forEach((r,c)=>{let i=r.quantity-(n.get(c)?.quantity??0);if(i<=0)return;let s=[h(r,i)];d("remove_from_cart",{currency:o,value:f(s),items:s})})}function dt({cart:t,reason:n}){let e=new Map((t?.lines.nodes??[]).map(o=>[o.merchandise.id,o]));v&&n!=="load"&&n!=="pending"&&ut(t,e,v),v=e,O=t}function lt(){let t=b.lines.map(n=>h(n));d("view_cart",{currency:b.state?.cost.totalAmount.currencyCode,value:f(t),items:t})}function pt({cart:t}){if(!t)return;let n=t.lines.nodes.map(o=>h(o)),e=t.discountCodes.filter(o=>o.applicable).map(o=>o.code);d("begin_checkout",{currency:t.cost.totalAmount.currencyCode,value:f(n),coupon:e.join(",")||void 0,items:n})}var ft={"product-ready":at,"list-ready":ct,"cart-updated":dt,"cart-toggled":({open:t})=>{t&<()},checkout:pt,search:({term:t})=>{t&&d("search",{search_term:t},"search_viewed",{searchTerm:t})}};function mt(t,n){ft[n](t.detail)}function B(t){if(t.type==="astro:page-load"){w=new WeakSet,m?.publish("page_viewed",{});return}C.forEach(n=>{E(t,n)&&mt(t,n)})}async function yt(t){a.analytics?.shopify&&(m=await V(()=>F()!=null).catch(n=>(l(n,"shopify analytics"),null))),m?.publish("page_viewed",{}),t.splice(0).forEach(B),t.push=(...n)=>(n.forEach(B),t.length)}function g(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ht(t){return g(t)&&g(t.__core)&&g(t.__parts)}function j(t,n){let e=Reflect.get(window,"Tether");if(!ht(e))throw new Error(`tether.${t}.js runs after the Tether script, which loads it, and needs its window.Tether`);e.__parts[t]=n}j("analytics",k);})();
|
package/dist/tether.diagnose.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// tether-core:client.ts
|
|
22
22
|
var m2 = window.Tether.__core["client.ts"];
|
|
23
|
-
var [endpoint, gql, matches, orNull, shaped, TetherError] = m2;
|
|
23
|
+
var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m2;
|
|
24
24
|
|
|
25
25
|
// tether-core:dom.ts
|
|
26
26
|
var m3 = window.Tether.__core["dom.ts"];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var L=Object.defineProperty;var Y=(e,n)=>{for(var t in n)L(e,t,{get:n[t],enumerable:!0})};var P={};Y(P,{apiVersionStatus:()=>y,checkMarkup:()=>k,diagnose:()=>ke,didYouMean:()=>f});var G=window.Tether.__core["config.ts"],[a,E,$e,Re,Te,Ae,_e]=G;var B=window.Tether.__core["client.ts"],[$,R,Ne,xe,T,Me]=B;var K=window.Tether.__core["dom.ts"],[
|
|
1
|
+
(()=>{var L=Object.defineProperty;var Y=(e,n)=>{for(var t in n)L(e,t,{get:n[t],enumerable:!0})};var P={};Y(P,{apiVersionStatus:()=>y,checkMarkup:()=>k,diagnose:()=>ke,didYouMean:()=>f});var G=window.Tether.__core["config.ts"],[a,E,$e,Re,Te,Ae,_e]=G;var B=window.Tether.__core["client.ts"],[$,R,Ne,xe,T,Me,De]=B;var K=window.Tether.__core["dom.ts"],[Ve,p,Ue,Ce,Ie,qe,He,m,Le,A,Ye,Ge,Be,Ke,Qe,d,je,We,l,Fe,ze,Je,Xe]=K;var Q=window.Tether.__core["loader.ts"],[et,_,tt,nt,rt]=Q;var j=window.Tether.__core["selling-plans.ts"],[v]=j;var W=window.Tether.__core["status.ts"],[N,it,h,at]=W;var F=/^(\d{4})-(01|04|07|10)$/;function M(e){let n=F.exec(typeof e=="string"?e:"");return n?{year:Number(n[1]),month:Number(n[2])}:null}var z=(e,n)=>`${e}-${String(n).padStart(2,"0")}`;function x(e,n=1){let t=M(e);if(!t)throw new Error(`not a quarterly Shopify API version: ${e}`);let r=t.year*4+(t.month-1)/3+n;return z(Math.floor(r/4),r%4*3+1)}function y(e,n=new Date){if(e==="unstable")return{version:e,ok:!1,note:'"unstable" changes without notice: pin a dated version such as 2026-07'};let t=M(e);if(!t)return{version:e,ok:!1,note:"not a quarterly version (YYYY-01, -04, -07 or -10)"};let r=new Date(Date.UTC(t.year,t.month-1,1)),s=new Date(Date.UTC(t.year,t.month-1+12,1)),o=(s.getTime()-n.getTime())/2630016e3,i=r<=n,c=`supported until about ${s.toISOString().slice(0,7)}`;return i?o<=0?c="no longer supported: Shopify falls back to the oldest supported version. Upgrade (see docs/reference.md)":o<3&&(c=`${c}: plan the upgrade to ${x(e)} or later (see docs/reference.md)`):c="not released yet (release candidate at best)",{version:e,ok:i&&o>0,monthsLeft:Math.round(o),next:x(e),note:c}}var J=window.Tether.__core["lazy.ts"],[D]=J;var O=new Set(["in-stock","out-of-stock","backorder","low-stock","plenty-in-stock","on-sale","not-on-sale","has-variants","single-variant","subscription-available","subscription-unavailable","subscription-only","one-time-available","subscription-selected","one-time-selected","has-savings","loading","ready","error","not-found","cart-empty","cart-filled","cart-has-subscription","cart-no-subscription","cart-has-discount","cart-error","cart-warning","list-empty","list-filled","search-empty","search-results","logged-in","logged-out","orders-empty","orders-loading","addresses-loading","addresses-empty","addresses-error","subscriptions-loading","subscriptions-empty","subscriptions-error"]),V=new Set(["title","description","description-text","vendor","type","handle","published-at","price","total-price","compare-at-price","unit-price","min-price","max-price","discount-percentage","discount-amount","variant-title","variant-id","sku","barcode","stock","quantity","featured-image","variant-image","images","tags","link","url","one-time-price","subscription-price","subscription-savings","subscription-savings-amount","checkout-charge","plan-name","plan-description","plan-group","option-value","swatch","image"]),U=new Set(`account account-bind account-link account-login account-logout add-label add-to-cart adding-text
|
|
2
2
|
always-enabled bind cart-checkout-charge cart-clear cart-close cart-count cart-discounts cart-drawer cart-label cart-lines
|
|
3
3
|
cart-note cart-open cart-subtotal cart-total cart-warning checkout code collection collection-bind countries country
|
|
4
4
|
country-bind country-label country-select default-plan default-purchase discount discount-code discount-form discount-input
|
package/dist/tether.extras.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var extras_exports = {};
|
|
10
10
|
__export(extras_exports, {
|
|
11
11
|
addGroup: () => addGroup,
|
|
12
|
+
applyDiscountCode: () => applyDiscountCode,
|
|
12
13
|
onStorage: () => onStorage,
|
|
13
14
|
writeVariantUrl: () => writeVariantUrl
|
|
14
15
|
});
|
|
@@ -17,25 +18,29 @@
|
|
|
17
18
|
var m = window.Tether.__core["config.ts"];
|
|
18
19
|
var [cfg, isConfigured, log, MARKET_SOURCES, parseMarkets, reportError, warn] = m;
|
|
19
20
|
|
|
21
|
+
// tether-core:client.ts
|
|
22
|
+
var m2 = window.Tether.__core["client.ts"];
|
|
23
|
+
var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m2;
|
|
24
|
+
|
|
20
25
|
// tether-core:dom.ts
|
|
21
|
-
var
|
|
22
|
-
var [ANALYTICS_EVENTS, attr, attributesFromJson, busy, emit, formatDate, formatMoney, get, has, hasTemplate, integerAttribute, isOwnEvent, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, scoped, sel, setImage, setStoreHtml, setText, show] =
|
|
26
|
+
var m3 = window.Tether.__core["dom.ts"];
|
|
27
|
+
var [ANALYTICS_EVENTS, attr, attributesFromJson, busy, emit, formatDate, formatMoney, get, has, hasTemplate, integerAttribute, isOwnEvent, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, scoped, sel, setImage, setStoreHtml, setText, show] = m3;
|
|
23
28
|
|
|
24
29
|
// tether-core:product.ts
|
|
25
|
-
var
|
|
26
|
-
var [scopes] =
|
|
30
|
+
var m4 = window.Tether.__core["product.ts"];
|
|
31
|
+
var [scopes] = m4;
|
|
27
32
|
|
|
28
33
|
// tether-core:cart.ts
|
|
29
|
-
var
|
|
30
|
-
var [Cart] =
|
|
34
|
+
var m5 = window.Tether.__core["cart.ts"];
|
|
35
|
+
var [Cart] = m5;
|
|
31
36
|
|
|
32
37
|
// tether-core:page-market.ts
|
|
33
|
-
var
|
|
34
|
-
var [setCountry] =
|
|
38
|
+
var m6 = window.Tether.__core["page-market.ts"];
|
|
39
|
+
var [setCountry] = m6;
|
|
35
40
|
|
|
36
41
|
// tether-core:market-codes.ts
|
|
37
|
-
var
|
|
38
|
-
var [toCountry, toLanguage] =
|
|
42
|
+
var m7 = window.Tether.__core["market-codes.ts"];
|
|
43
|
+
var [toCountry, toLanguage] = m7;
|
|
39
44
|
|
|
40
45
|
// src/markets.ts
|
|
41
46
|
var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
|
|
@@ -89,6 +94,23 @@
|
|
|
89
94
|
return null;
|
|
90
95
|
}
|
|
91
96
|
}
|
|
97
|
+
function markInvalid(form, input, invalid) {
|
|
98
|
+
form.classList.toggle("is-invalid", invalid);
|
|
99
|
+
if (invalid) input?.setAttribute("aria-invalid", "true");
|
|
100
|
+
else input?.removeAttribute("aria-invalid");
|
|
101
|
+
}
|
|
102
|
+
async function applyDiscountCode(form, input, code) {
|
|
103
|
+
try {
|
|
104
|
+
await Cart.applyDiscount(code);
|
|
105
|
+
markInvalid(form, input, false);
|
|
106
|
+
emit("discount-applied", { code }, form);
|
|
107
|
+
if (input) input.value = "";
|
|
108
|
+
} catch (error) {
|
|
109
|
+
markInvalid(form, input, true);
|
|
110
|
+
if (error instanceof TetherError && error.code === "INVALID_DISCOUNT") emit("discount-invalid", { code }, form);
|
|
111
|
+
else reportError(error, "discount");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
92
114
|
function onStorage(event) {
|
|
93
115
|
if (event.key === cfg.storageKey || event.key === `${cfg.storageKey}:seen`) {
|
|
94
116
|
Cart.init().catch((error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var v=Object.defineProperty;var R=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0})};var p={};R(p,{addGroup:()=>V,applyDiscountCode:()=>W,onStorage:()=>G,writeVariantUrl:()=>Z});var O=window.Tether.__core["config.ts"],[i,X,ee,P,U,u,m]=O;var D=window.Tether.__core["client.ts"],[ne,re,oe,ae,ie,y,ce]=D;var H=window.Tether.__core["dom.ts"],[se,le,w,ge,s,de,fe,k,h,pe,me,ye,we,C,ke,S,he,Ce,l,Se,Me,xe,be]=H;var K=window.Tether.__core["product.ts"],[M]=K;var F=window.Tether.__core["cart.ts"],[g]=F;var $=window.Tether.__core["page-market.ts"],[x]=$;var q=window.Tether.__core["market-codes.ts"],[b,E]=q;var T=()=>`${i.prefix}:market:${i.domain}`;function J(e){try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return null;throw t}}function j(e){if(typeof e!="object"||e===null)return null;let t=b(Reflect.get(e,"country"));if(!t)return null;let n=Reflect.get(e,"locale");return{country:t,language:E(Reflect.get(e,"language"))??void 0,locale:typeof n=="string"&&n?n:void 0}}var _=e=>j(J(e));function z(e,t){let n=w(C(e,"line-attributes"));return t?[{key:"_group",value:t},...n]:n}async function V(e){let t=e.closest(l("group"));if(!t)return null;let n=k(t,"group"),r=z(t,n),c=S(t,l("product")).flatMap(a=>{let o=M.get(a);if(!o?.variant?.availableForSale||o.quantity<=0)return[];let f=o.getLine();return f?[{...f,attributes:[...f.attributes??[],...r]}]:[]});if(!c.length)return m("group-add: nothing selected"),null;try{let a=await g.add(c);return s("group-added",{group:n,lines:c},t),a}catch(a){return u(a,"group add"),null}}function L(e,t,n){e.classList.toggle("is-invalid",n),n?t?.setAttribute("aria-invalid","true"):t?.removeAttribute("aria-invalid")}async function W(e,t,n){try{await g.applyDiscount(n),L(e,t,!1),s("discount-applied",{code:n},e),t&&(t.value="")}catch(r){L(e,t,!0),r instanceof y&&r.code==="INVALID_DISCOUNT"?s("discount-invalid",{code:n},e):u(r,"discount")}}function G(e){if(e.key===i.storageKey||e.key===`${i.storageKey}:seen`){g.init().catch(r=>{u(r,"cart from another tab")});return}if(e.key!==T()||!e.newValue)return;let t=_(e.newValue);if(!t)return;let n={language:t.language??null,locale:t.locale,remember:!1};x(t.country,n).catch(r=>{u(r,"market from another tab")})}var A=new WeakMap,N=e=>e.split("/").pop()??e;function Y(e){try{window.history.replaceState(window.history.state,"",e)}catch{}}function Z(e,{variant:t,sellingPlanId:n}){let r=`${t.id}|${n??""}`,c=A.get(e);if(A.set(e,r),!c||c===r)return;let a=i.variantUrl&&document.querySelector(l("product"))===e;if(!h(e,"variant-url")&&!a)return;let o=new URL(window.location.href);o.searchParams.set("variant",N(t.id)),n?o.searchParams.set("selling_plan",N(n)):o.searchParams.delete("selling_plan"),Y(o)}function d(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function B(e){return d(e)&&d(e.__core)&&d(e.__parts)}function I(e,t){let n=Reflect.get(window,"Tether");if(!B(n))throw new Error(`tether.${e}.js runs after the Tether script, which loads it, and needs its window.Tether`);n.__parts[e]=t}I("extras",p);})();
|