@occluze/tether 0.6.7 → 0.7.0
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 +11 -11
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-UIPWJQ3Y.js +1 -0
- package/dist/esm/chunks/account-pages-6ROA6Y4V.js +1 -0
- package/dist/esm/chunks/analytics-2V632IRV.js +1 -0
- package/dist/esm/chunks/chunk-4GCXM764.js +1 -0
- package/dist/esm/chunks/chunk-56FCLJJD.js +1 -0
- package/dist/esm/chunks/chunk-5Z5O3767.js +1 -0
- package/dist/esm/chunks/chunk-6OZJCAGZ.js +1 -0
- package/dist/esm/chunks/chunk-A5SYCVQM.js +1 -0
- package/dist/esm/chunks/chunk-BA4LQJJQ.js +1 -0
- package/dist/esm/chunks/chunk-BFTZR4OB.js +4 -0
- package/dist/esm/chunks/chunk-C5JYQCWH.js +1 -0
- package/dist/esm/chunks/chunk-E5YO6274.js +1 -0
- package/dist/esm/chunks/chunk-MPDWM2NN.js +1 -0
- package/dist/esm/chunks/chunk-T44MUL4Y.js +1 -0
- package/dist/esm/chunks/chunk-YLUULATY.js +1 -0
- package/dist/esm/chunks/diagnose-3FEKRIEK.js +14 -0
- package/dist/esm/chunks/extras-6POFBNOP.js +1 -0
- package/dist/esm/chunks/markets-ui-FD6NI2OG.js +1 -0
- package/dist/esm/chunks/search-UJ73YBQ5.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -1
- package/dist/presets/barba.esm.js +55 -39
- package/dist/tether.account-pages.js +781 -495
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +462 -381
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +299 -194
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +354 -262
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +82 -45
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +3653 -2116
- package/dist/tether.markets.js +238 -150
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +3 -3
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +207 -136
- package/dist/tether.search.min.js +1 -1
- package/dist/types/server/src/shared/account-orders.d.ts +44 -0
- package/dist/types/server/src/shared/account-routes.d.ts +153 -0
- package/dist/types/server/src/shared/api-versions.d.ts +13 -0
- package/dist/types/server/src/shared/error-message.d.ts +2 -0
- package/dist/types/server/src/shared/json.d.ts +25 -0
- package/dist/types/server/src/shared/market-codes.d.ts +16 -0
- package/dist/types/src/account/addresses-view.d.ts +5 -0
- package/dist/types/src/account/answers.d.ts +40 -0
- package/dist/types/src/account/markup.d.ts +19 -0
- package/dist/types/src/account/operations.d.ts +41 -0
- package/dist/types/src/account/order-lines.d.ts +13 -0
- package/dist/types/src/account/order-list.d.ts +12 -0
- package/dist/types/src/account/order-page.d.ts +6 -0
- package/dist/types/src/account/page-answers.d.ts +182 -0
- package/dist/types/src/account/page-events.d.ts +2 -0
- package/dist/types/src/account/server-client.d.ts +60 -0
- package/dist/types/src/account/subscriptions-view.d.ts +2 -0
- package/dist/types/src/account-api.d.ts +18 -0
- package/dist/types/src/account-marks.d.ts +15 -0
- package/dist/types/src/account-pages.d.ts +8 -0
- package/dist/types/src/account.d.ts +64 -0
- package/dist/types/src/amounts.d.ts +12 -0
- package/dist/types/src/analytics-shopify.d.ts +41 -0
- package/dist/types/src/analytics.d.ts +2 -0
- package/dist/types/src/api-version.d.ts +28 -0
- package/dist/types/src/astro.d.ts +42 -0
- package/dist/types/src/cart/cart-shape.d.ts +43 -0
- package/dist/types/src/cart/checkout.d.ts +16 -0
- package/dist/types/src/cart/drawer.d.ts +18 -0
- package/dist/types/src/cart/mutations.d.ts +79 -0
- package/dist/types/src/cart/render.d.ts +17 -0
- package/dist/types/src/cart/store.d.ts +182 -0
- package/dist/types/src/cart.d.ts +106 -0
- package/dist/types/src/client.d.ts +100 -0
- package/dist/types/src/collection.d.ts +25 -0
- package/dist/types/src/config-sections.d.ts +40 -0
- package/dist/types/src/config.d.ts +185 -0
- package/dist/types/src/controls/cart-controls.d.ts +2 -0
- package/dist/types/src/controls/discount.d.ts +2 -0
- package/dist/types/src/controls/extras.d.ts +5 -0
- package/dist/types/src/controls/navigation.d.ts +12 -0
- package/dist/types/src/diagnose-markup.d.ts +19 -0
- package/dist/types/src/diagnose.d.ts +60 -0
- package/dist/types/src/dom.d.ts +75 -0
- package/dist/types/src/extras.d.ts +21 -0
- package/dist/types/src/fragments.d.ts +158 -0
- package/dist/types/src/globals.d.ts +15 -0
- package/dist/types/src/images.d.ts +20 -0
- package/dist/types/src/index.d.ts +167 -0
- package/dist/types/src/initial.d.ts +56 -0
- package/dist/types/src/lazy.d.ts +28 -0
- package/dist/types/src/loader.d.ts +84 -0
- package/dist/types/src/market-codes.d.ts +6 -0
- package/dist/types/src/markets-ui.d.ts +32 -0
- package/dist/types/src/markets.d.ts +72 -0
- package/dist/types/src/markup.d.ts +131 -0
- package/dist/types/src/mounting.d.ts +46 -0
- package/dist/types/src/page-market.d.ts +27 -0
- package/dist/types/src/presets/barba.d.ts +56 -0
- package/dist/types/src/product-events.d.ts +2 -0
- package/dist/types/src/product-render.d.ts +17 -0
- package/dist/types/src/product-shape.d.ts +88 -0
- package/dist/types/src/product-state.d.ts +110 -0
- package/dist/types/src/product.d.ts +66 -0
- package/dist/types/src/repeaters.d.ts +16 -0
- package/dist/types/src/search.d.ts +33 -0
- package/dist/types/src/selling-plans.d.ts +64 -0
- package/dist/types/src/server.d.ts +88 -0
- package/dist/types/src/shopify-values.d.ts +46 -0
- package/dist/types/src/status.d.ts +33 -0
- package/dist/types/src/storage.d.ts +12 -0
- package/dist/types/src/store-html.d.ts +39 -0
- package/dist/types/src/storefront/catalog.d.ts +38 -0
- package/dist/types/src/storefront/json-ld.d.ts +20 -0
- package/dist/types/src/variant-render.d.ts +14 -0
- package/package.json +42 -22
- package/src/account/addresses-view.ts +58 -0
- package/src/account/answers.ts +79 -0
- package/src/account/markup.ts +36 -0
- package/src/account/operations.ts +145 -0
- package/src/account/order-lines.ts +75 -0
- package/src/account/order-list.ts +107 -0
- package/src/account/order-page.ts +137 -0
- package/src/account/page-answers.ts +317 -0
- package/src/account/page-events.ts +253 -0
- package/src/account/server-client.ts +183 -0
- package/src/account/subscriptions-view.ts +115 -0
- package/src/account-api.ts +98 -0
- package/src/account-marks.ts +35 -0
- package/src/account-pages.ts +81 -0
- package/src/account.ts +284 -0
- package/src/amounts.ts +64 -0
- package/src/analytics-shopify.ts +246 -0
- package/src/analytics.ts +315 -0
- package/src/api-version.ts +79 -0
- package/src/astro.ts +272 -0
- package/src/cart/cart-shape.ts +25 -0
- package/src/cart/checkout.ts +101 -0
- package/src/cart/drawer.ts +125 -0
- package/src/cart/mutations.ts +237 -0
- package/src/cart/render.ts +266 -0
- package/src/cart/store.ts +279 -0
- package/src/cart.ts +345 -0
- package/src/client.ts +391 -0
- package/src/collection.ts +175 -0
- package/src/config-sections.ts +284 -0
- package/src/config.ts +480 -0
- package/src/controls/cart-controls.ts +123 -0
- package/src/controls/discount.ts +75 -0
- package/src/controls/extras.ts +54 -0
- package/src/controls/navigation.ts +77 -0
- package/src/diagnose-markup.ts +298 -0
- package/src/diagnose.ts +294 -0
- package/src/dom.ts +268 -0
- package/src/extras.ts +136 -0
- package/src/fragments.ts +261 -0
- package/src/globals.d.ts +15 -0
- package/src/images.ts +91 -0
- package/src/index.ts +415 -0
- package/src/initial.ts +101 -0
- package/src/lazy-iife.ts +197 -0
- package/src/lazy.ts +42 -0
- package/src/loader.ts +363 -0
- package/src/market-codes.ts +6 -0
- package/src/markets-ui.ts +227 -0
- package/src/markets.ts +246 -0
- package/src/markup.ts +127 -0
- package/src/mounting.ts +264 -0
- package/src/page-market.ts +110 -0
- package/src/part-integrity.ts +7 -0
- package/src/parts/account-pages.ts +7 -0
- package/src/parts/account.ts +7 -0
- package/src/parts/analytics.ts +7 -0
- package/src/parts/diagnose.ts +7 -0
- package/src/parts/extras.ts +7 -0
- package/src/parts/markets.ts +7 -0
- package/src/parts/search.ts +7 -0
- package/src/presets/barba.ts +194 -0
- package/src/product-events.ts +115 -0
- package/src/product-render.ts +218 -0
- package/src/product-shape.ts +49 -0
- package/src/product-state.ts +318 -0
- package/src/product.ts +308 -0
- package/src/repeaters.ts +161 -0
- package/src/search.ts +305 -0
- package/src/selling-plans.ts +145 -0
- package/src/server.ts +211 -0
- package/src/shopify-values.ts +91 -0
- package/src/status.ts +106 -0
- package/src/storage.ts +34 -0
- package/src/store-html.ts +359 -0
- package/src/storefront/catalog.ts +196 -0
- package/src/storefront/json-ld.ts +144 -0
- package/src/variant-render.ts +139 -0
- package/dist/esm/chunks/account-Q6E2TFEV.js +0 -1
- package/dist/esm/chunks/account-pages-UZXR4R5F.js +0 -1
- package/dist/esm/chunks/analytics-IJBKATUP.js +0 -1
- package/dist/esm/chunks/chunk-4QJKLPYR.js +0 -1
- package/dist/esm/chunks/chunk-64TUD3QR.js +0 -1
- package/dist/esm/chunks/chunk-AJLPU2JC.js +0 -4
- package/dist/esm/chunks/chunk-FIOZPPC5.js +0 -1
- package/dist/esm/chunks/chunk-K2YEQAIH.js +0 -1
- package/dist/esm/chunks/chunk-KIDH76B7.js +0 -1
- package/dist/esm/chunks/chunk-PAYT5ZD7.js +0 -1
- package/dist/esm/chunks/chunk-RREHGH4A.js +0 -1
- package/dist/esm/chunks/chunk-SSJT43CJ.js +0 -1
- package/dist/esm/chunks/chunk-VC46IEJQ.js +0 -1
- package/dist/esm/chunks/diagnose-3WVAWNTX.js +0 -14
- package/dist/esm/chunks/extras-7I7WJX35.js +0 -1
- package/dist/esm/chunks/markets-ui-545XLFTE.js +0 -1
- package/dist/esm/chunks/search-NILMGYXG.js +0 -1
- package/src/account-pages.js +0 -318
- package/src/account.js +0 -385
- package/src/analytics.js +0 -232
- package/src/api-version.js +0 -35
- package/src/astro.js +0 -101
- package/src/cart.js +0 -559
- package/src/client.js +0 -131
- package/src/collection.js +0 -114
- package/src/config.js +0 -85
- package/src/diagnose.js +0 -246
- package/src/dom.js +0 -288
- package/src/extras.js +0 -63
- package/src/fragments.js +0 -144
- package/src/index.js +0 -395
- package/src/initial.js +0 -75
- package/src/lazy-iife.js +0 -46
- package/src/lazy.js +0 -18
- package/src/loader.js +0 -198
- package/src/markets-ui.js +0 -90
- package/src/markets.js +0 -133
- package/src/mounting.js +0 -154
- package/src/parts/account-pages.js +0 -3
- package/src/parts/account.js +0 -3
- package/src/parts/analytics.js +0 -3
- package/src/parts/diagnose.js +0 -3
- package/src/parts/extras.js +0 -3
- package/src/parts/markets.js +0 -3
- package/src/parts/search.js +0 -3
- package/src/presets/barba.js +0 -100
- package/src/product.js +0 -570
- package/src/search.js +0 -153
- package/src/selling-plans.js +0 -94
- package/src/server.js +0 -252
- package/src/status.js +0 -66
- package/types/astro.d.ts +0 -17
- package/types/barba.d.ts +0 -16
- package/types/index.d.ts +0 -426
- package/types/server.d.ts +0 -110
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as k,c as U,e as z,f as B,g as M,h as L,i as N}from"./chunk-SSJT43CJ.js";import{a as C,b,c as T,d as A,e as I,f as v}from"./chunk-64TUD3QR.js";import"./chunk-KIDH76B7.js";import"./chunk-RREHGH4A.js";import{b as d}from"./chunk-4QJKLPYR.js";import{d as E}from"./chunk-FIOZPPC5.js";import"./chunk-AJLPU2JC.js";import{b as t,g as p,h as w,n as g,o as h,p as P,u as x}from"./chunk-K2YEQAIH.js";import"./chunk-VC46IEJQ.js";function O(s=document){let u=L(s,`select${h("country-select")}`),m=L(s,h("country-bind"));return!u.length&&!m.length?Promise.resolve():v().then(l=>{let r=(t.country||l.country?.isoCode||"").toUpperCase(),c=[...l.availableCountries||[]].sort((e,o)=>e.name.localeCompare(o.name,t.locale||void 0)),i=c.find(e=>e.isoCode===r)||l.country,f=(e,o)=>e.replace(/\{name\}/g,o.name).replace(/\{code\}/g,o.isoCode).replace(/\{currency\}/g,o.currency?.isoCode||"").replace(/\{symbol\}/g,o.currency?.symbol||"");u.forEach(e=>{let o=e.getAttribute(g("country-label"))||"{name} ({currency})",a=(e.getAttribute(g("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),n=a.length?a.map(y=>c.find(S=>S.isoCode===y)).filter(Boolean):c;e.innerHTML="",n.forEach(y=>e.appendChild(new Option(f(o,y),y.isoCode))),e.value=r,e.value!==r&&(e.selectedIndex=-1),e.disabled=n.length<2&&!e.hasAttribute(g("always-enabled"))}),m.forEach(e=>{let o=P(e,"country-bind")||"name",a={name:i?.name,code:i?.isoCode,currency:i?.currency?.isoCode,symbol:i?.currency?.symbol}[o];e.textContent=a||""})}).catch(l=>p(l,"country select"))}async function q(s,{language:u,locale:m,remember:l=!0}={}){let r=C(s);if(!r)throw new w(`Not a country code: ${s}`,{code:"INVALID_COUNTRY"});let c=Object.values(t.markets?.locales||{}).find(n=>C(n?.country)===r),i=m||c?.locale,f=i||t.locale,e=u!==void 0?b(u):c?c.language?b(c.language):void 0:t.language,o=r!==String(t.country||"").toUpperCase()||e!==t.language||f!==t.locale;if(t.country=r,t.language=e||void 0,t.locale=f,l&&A({country:r,language:e,locale:i}),!o)return O(),d.state;E();let a=[];return u!==void 0&&I(),d.id()&&a.push(d.setBuyerIdentity({countryCode:r},{create:!1}).catch(n=>p(n,"cart country"))),M(),B.forEach(n=>a.push(n.load())),z.forEach(n=>{n.closest(k())||(U.delete(n),N(n))}),O(),x("country-changed",{country:r,language:t.language}),await Promise.all(a),d.state}export{T as detectMarket,v as getLocalization,O as renderCountrySelects,q as setCountry};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as N,B as O,D as q,G as V,b as y,g as C,l as E,n as D,o as u,p,r as R,s as h,u as U,w as P}from"./chunk-K2YEQAIH.js";import"./chunk-VC46IEJQ.js";var H="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}}}",F=new WeakSet,W=0;function J(s=document){[...s.matches?.(u("search"))?[s]:[],...h(s,u("search"))].forEach(c=>{F.has(c)||(F.add(c),j(c))})}function j(s){let n=s.querySelector(u("search-input"))||s.querySelector("input"),c=s.querySelector(u("search-results"));if(!n||!c)return;let M=parseInt(p(s,"search-limit")||"6",10)||6,v=parseInt(p(s,"search-min")||"2",10)||2,k=c.id||(c.id=`${y.prefix}-search-${++W}`);n.setAttribute("role","combobox"),n.setAttribute("aria-autocomplete","list"),n.setAttribute("aria-controls",k),n.setAttribute("aria-expanded","false"),n.setAttribute("autocomplete","off"),c.hasAttribute("role")||c.setAttribute("role","listbox"),c.hidden=!0;let x=0,w=null,I="",L=new Map,b=t=>s.setAttribute(D("search-state"),t),f=t=>{s.classList.toggle("is-open",t),c.hidden=!t,n.setAttribute("aria-expanded",String(t)),t||n.removeAttribute("aria-activedescendant")},S=()=>h(c,'[role="option"]');async function Q(t){let e=++x;if(t.length<v){f(!1),b("idle");return}b("loading");try{let r=L.get(t)||(await E(H,{q:t,limit:M})).predictiveSearch;if(L.set(t,r),e!==x)return;Y(r,t)}catch(r){if(e!==x)return;b("error"),C(r,"search")}}function Y(t,e){let r=t?.products||[],o=t?.collections||[],l=(t?.queries||[]).filter(i=>i.text.toLowerCase()!==e.toLowerCase()),d=(i,a,A)=>h(c,u(i)).forEach(g=>{V(g,a,A),q(g,a.length>0)});d("search-products",r,(i,a)=>{$(i,{title:a.title,price:P(a.priceRange?.minVariantPrice),image:a.featuredImage}),T(i,R(a.handle,a.id)),i.classList.toggle("is-sold-out",!a.availableForSale)}),d("search-collections",o,(i,a)=>{$(i,{title:a.title,image:a.image}),T(i,`${(y.collectionPath||"/collection").replace(/\/$/,"")}/${a.handle}`)}),d("search-queries",l,(i,a)=>{$(i,{text:a.text});let A=i.tagName==="A"?i:i.querySelector("a"),g=s.getAttribute("action")||"/search";A&&A.setAttribute("href",`${g}${g.includes("?")?"&":"?"}${n.name||"q"}=${encodeURIComponent(a.text)}`)});let m=r.length+o.length+l.length;h(s,u("show")).forEach(i=>{let a=p(i,"show");a==="search-empty"&&q(i,m===0),a==="search-results"&&q(i,m>0)}),S().forEach((i,a)=>{i.id||(i.id=`${k}-${a}`),i.setAttribute("aria-selected","false")}),b(m?"ready":"empty"),f(!0),U("search",{term:e,products:r,collections:o,queries:l},s)}function $(t,e){h(t,u("search-bind")).forEach(r=>{let o=p(r,"search-bind");o==="image"?N(r,e.image?.url,e.image?.altText||e.title):e[o]!=null&&O(r,e[o])})}function T(t,e){let r=t.tagName==="A"?t:t.querySelector("a");r&&(r.setAttribute("href",e),r.setAttribute("role","option"))}n.addEventListener("input",()=>{let t=n.value.trim();t!==I&&(I=t,clearTimeout(w),w=setTimeout(()=>Q(t),y.searchDelay??150))}),n.addEventListener("focus",()=>{n.value.trim().length>=v&&S().length&&f(!0)}),n.addEventListener("keydown",t=>{let e=S(),r=e.findIndex(l=>l.getAttribute("aria-selected")==="true"),o=l=>{e.forEach((d,m)=>d.setAttribute("aria-selected",String(m===l))),e[l]&&(n.setAttribute("aria-activedescendant",e[l].id),e[l].scrollIntoView?.({block:"nearest"}))};t.key==="ArrowDown"&&e.length?(t.preventDefault(),f(!0),o((r+1)%e.length)):t.key==="ArrowUp"&&e.length?(t.preventDefault(),o(r<=0?e.length-1:r-1)):t.key==="Enter"&&r>=0?(t.preventDefault(),e[r].click()):t.key==="Escape"&&f(!1)}),document.addEventListener("click",t=>{s.contains(t.target)||f(!1)})}export{J as mountSearch};
|
package/src/account-pages.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Customer account pages (optional part, loaded by the account part on pages that use them):
|
|
3
|
-
* order detail with returns, profile, addresses, subscriptions. The operations and their input
|
|
4
|
-
* checks are shared with the Worker (server/src/account-ops.js), so both modes do the same.
|
|
5
|
-
*/
|
|
6
|
-
import { cfg, reportError } from './config.js';
|
|
7
|
-
import { TetherError } from './client.js';
|
|
8
|
-
import { attr, sel, get, qsa, setText, setImage, repeat, show, formatMoney, emit } from './dom.js';
|
|
9
|
-
import { ops, InputError } from '../server/src/account-ops.js';
|
|
10
|
-
|
|
11
|
-
let ctx = null; // the account part's server(), serverFetch(), query(), customer(), reset()
|
|
12
|
-
let bound = false;
|
|
13
|
-
export function setup(c) { ctx = c; }
|
|
14
|
-
|
|
15
|
-
const https = (u) => { try { return new URL(u).protocol === 'https:'; } catch { return false; } };
|
|
16
|
-
const date = (s) => { try { return new Date(s).toLocaleDateString(cfg.locale || undefined); } catch { return s; } };
|
|
17
|
-
// ---------------------------------------------------------------- order detail, profile, addresses, subscriptions, returns
|
|
18
|
-
|
|
19
|
-
// The same fixed operations in both modes: the Worker's routes in server mode, the Customer
|
|
20
|
-
// Account API directly (with the same documents and input checks) in browser mode.
|
|
21
|
-
const ROUTE = {
|
|
22
|
-
order: (i) => ['GET', `/order?id=${encodeURIComponent(i.id)}`],
|
|
23
|
-
addresses: () => ['GET', '/addresses'],
|
|
24
|
-
subscriptions: () => ['GET', '/subscriptions'],
|
|
25
|
-
profile: () => ['POST', '/profile'],
|
|
26
|
-
saveAddress: () => ['POST', '/address'],
|
|
27
|
-
deleteAddress: () => ['POST', '/address/delete'],
|
|
28
|
-
subscription: () => ['POST', '/subscription'],
|
|
29
|
-
requestReturn: () => ['POST', '/return'],
|
|
30
|
-
};
|
|
31
|
-
async function run(name, input = {}) {
|
|
32
|
-
const { server, serverFetch, query } = ctx;
|
|
33
|
-
if (server()) {
|
|
34
|
-
const [method, path] = ROUTE[name](input);
|
|
35
|
-
const data = await serverFetch(path, method === 'POST' ? { method, body: input } : {});
|
|
36
|
-
if (data.loggedIn === false) throw new TetherError('Not logged in', { code: 'NOT_LOGGED_IN', status: 401 });
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
try { return await ops[name]((q, v) => query(q, v), input); } catch (err) {
|
|
40
|
-
if (err instanceof InputError) throw new TetherError(err.message, { code: 'INVALID', userErrors: err.userErrors });
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const changed = (what) => { ctx.reset(); emit('account-updated', { what }); };
|
|
45
|
-
|
|
46
|
-
/** One of the customer's orders, in full (lines, totals, addresses, fulfillments, returns). */
|
|
47
|
-
export const order = (id) => run('order', { id }).then((r) => r.order);
|
|
48
|
-
export const updateProfile = ({ firstName, lastName } = {}) => run('profile', { firstName, lastName }).then((r) => { changed('profile'); return r.customer; });
|
|
49
|
-
export const addresses = () => run('addresses').then((r) => r.addresses);
|
|
50
|
-
/** saveAddress({ address1, city, zip, countryCode, … }, { id, isDefault }): creates, or updates with an id. */
|
|
51
|
-
export const saveAddress = (address, { id, isDefault } = {}) => run('saveAddress', { id, address, isDefault }).then((r) => { changed('addresses'); return r.address; });
|
|
52
|
-
export const deleteAddress = (id) => run('deleteAddress', { id }).then((r) => { changed('addresses'); return r.deleted; });
|
|
53
|
-
export const subscriptions = () => run('subscriptions').then((r) => r.subscriptions);
|
|
54
|
-
/** subscriptionAction(id, 'pause' | 'resume' | 'skip' | 'unskip' | 'cancel') */
|
|
55
|
-
export const subscriptionAction = (id, action) => run('subscription', { id, action }).then((r) => { changed('subscriptions'); return r; });
|
|
56
|
-
/** requestReturn(orderId, [{ lineItemId, quantity, reasonId, note }]) */
|
|
57
|
-
export const requestReturn = (orderId, lines) => run('requestReturn', { orderId, lines }).then((r) => { changed('orders'); return r.return; });
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const nid = (g) => String(g || '').split('/').pop().split('?')[0];
|
|
61
|
-
/** The order's page: your own (account.orderUrl: '/account/order?id={id}') or Shopify's status page. */
|
|
62
|
-
function orderUrl(o) {
|
|
63
|
-
const t = cfg.account?.orderUrl;
|
|
64
|
-
if (t) return String(t).replace('{id}', encodeURIComponent(nid(o.id)));
|
|
65
|
-
return https(o.statusPageUrl) ? o.statusPageUrl : null;
|
|
66
|
-
}
|
|
67
|
-
const lower = (v) => (v ? String(v).toLowerCase().replace(/_/g, ' ') : '');
|
|
68
|
-
const lines = (a) => (a?.formatted || []).join(', ');
|
|
69
|
-
const showIn = (root, name, conds) => qsa(root, sel(name)).forEach((el) => { const k = get(el, name); if (k in conds) show(el, Boolean(conds[k])); });
|
|
70
|
-
const showGlobal = (root, conds) => showIn(root, 'show', conds);
|
|
71
|
-
|
|
72
|
-
function fillLines(box, items, returnable = null) {
|
|
73
|
-
repeat(box, items, (row, l) => {
|
|
74
|
-
const can = returnable ? returnable.get(l.id) || 0 : 0;
|
|
75
|
-
row.dataset.tetherLine = l.id;
|
|
76
|
-
qsa(row, sel('order-line')).concat(row.matches(sel('order-line')) ? [row] : []).forEach((el) => {
|
|
77
|
-
const k = get(el, 'order-line');
|
|
78
|
-
if (k === 'image') { if (l.image) setImage(el, l.image.url, l.image.altText || l.title); return; }
|
|
79
|
-
const v = { title: l.title || l.name, 'variant-title': l.variantTitle || '', quantity: String(l.quantity), price: l.price ? formatMoney(l.price) : '', total: l.totalPrice ? formatMoney(l.totalPrice) : '', sku: l.sku || '', returnable: String(can) }[k];
|
|
80
|
-
if (v != null) setText(el, v);
|
|
81
|
-
});
|
|
82
|
-
showIn(row, 'order-line-show', { returnable: can > 0 });
|
|
83
|
-
qsa(row, sel('return-quantity')).forEach((input) => { input.max = String(can); input.min = '0'; if (!input.value) input.value = '0'; input.disabled = can < 1; });
|
|
84
|
-
qsa(row, `select${sel('return-reason')}`).forEach((select) => {
|
|
85
|
-
const reasons = l.suggestedReturnReasonDefinitions?.nodes || [];
|
|
86
|
-
if (select.dataset.tetherFilled !== l.id) {
|
|
87
|
-
select.dataset.tetherFilled = l.id;
|
|
88
|
-
reasons.forEach((r) => select.appendChild(new Option(r.name, r.id)));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const SCOPE = { order: sel('order') };
|
|
95
|
-
async function renderOrder(el) {
|
|
96
|
-
const raw = get(el, 'order') || '';
|
|
97
|
-
const key = raw.startsWith('url:') ? new URL(window.location.href).searchParams.get(raw.slice(4) || 'id') : raw;
|
|
98
|
-
const state = (s) => el.setAttribute(attr('order-state'), s);
|
|
99
|
-
if (!key) { state('not-found'); showIn(el, 'order-show', { 'not-found': true }); return; }
|
|
100
|
-
state('loading');
|
|
101
|
-
showIn(el, 'order-show', { loading: true, ready: false, 'not-found': false, error: false });
|
|
102
|
-
let o;
|
|
103
|
-
try { o = await order(key); } catch (err) {
|
|
104
|
-
reportError(err, 'order'); state('error'); showIn(el, 'order-show', { loading: false, error: true }); return;
|
|
105
|
-
}
|
|
106
|
-
if (!o) { state('not-found'); showIn(el, 'order-show', { loading: false, 'not-found': true }); return; }
|
|
107
|
-
el.dataset.tetherOrderId = o.id;
|
|
108
|
-
const returnable = new Map((o.returnInformation?.returnableLineItems?.nodes || []).map((r) => [r.lineItem?.id, r.quantity]));
|
|
109
|
-
const ships = o.fulfillments?.nodes || [];
|
|
110
|
-
qsa(el, sel('order-bind')).forEach((b) => {
|
|
111
|
-
const k = get(b, 'order-bind');
|
|
112
|
-
if (k === 'url') { if (https(o.statusPageUrl)) b.setAttribute('href', o.statusPageUrl); return; }
|
|
113
|
-
const v = {
|
|
114
|
-
name: o.name, date: date(o.processedAt), total: formatMoney(o.totalPrice), subtotal: o.subtotal ? formatMoney(o.subtotal) : '',
|
|
115
|
-
shipping: o.totalShipping ? formatMoney(o.totalShipping) : '', tax: o.totalTax ? formatMoney(o.totalTax) : '',
|
|
116
|
-
status: lower(o.financialStatus), fulfillment: lower(o.fulfillmentStatus), 'shipping-address': lines(o.shippingAddress),
|
|
117
|
-
'billing-address': lines(o.billingAddress), items: (o.lineItems?.nodes || []).map((l) => `${l.quantity}× ${l.title || l.name}`).join(', '),
|
|
118
|
-
cancelled: o.cancelledAt ? date(o.cancelledAt) : '',
|
|
119
|
-
}[k];
|
|
120
|
-
if (v != null) setText(b, v);
|
|
121
|
-
});
|
|
122
|
-
qsa(el, sel('order-lines')).forEach((box) => fillLines(box, o.lineItems?.nodes || [], returnable));
|
|
123
|
-
qsa(el, sel('order-fulfillments')).forEach((box) => repeat(box, ships, (row, f) => {
|
|
124
|
-
const t = f.trackingInformation?.[0] || {};
|
|
125
|
-
qsa(row, sel('fulfillment-bind')).concat(row.matches(sel('fulfillment-bind')) ? [row] : []).forEach((b) => {
|
|
126
|
-
const k = get(b, 'fulfillment-bind');
|
|
127
|
-
if (k === 'url') { const ok = https(t.url); if (ok) b.setAttribute('href', t.url); show(b, ok); return; } // no tracking link: hidden
|
|
128
|
-
const v = { status: lower(f.latestShipmentStatus || f.status), date: date(f.createdAt), eta: f.estimatedDeliveryAt ? date(f.estimatedDeliveryAt) : '', company: t.company || '', number: t.number || '' }[k];
|
|
129
|
-
if (v != null) setText(b, v);
|
|
130
|
-
});
|
|
131
|
-
}));
|
|
132
|
-
showIn(el, 'order-show', {
|
|
133
|
-
loading: false, ready: true, error: false, 'not-found': false, cancelled: Boolean(o.cancelledAt), shipped: ships.length > 0,
|
|
134
|
-
returnable: [...returnable.values()].some((q) => q > 0), 'has-returns': el.dataset.tetherReturned !== '1' && (o.returns?.nodes || []).length > 0, 'return-requested': el.dataset.tetherReturned === '1',
|
|
135
|
-
});
|
|
136
|
-
state('ready');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function renderProfile(form) {
|
|
140
|
-
const c = await ctx.customer().catch(() => null);
|
|
141
|
-
if (!c) return;
|
|
142
|
-
['firstName', 'lastName'].forEach((n) => { const i = form.elements?.[n]; if (i && !i.dataset.tetherTouched) i.value = c[n] || ''; });
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let addressCache = null;
|
|
146
|
-
async function renderAddresses(root) {
|
|
147
|
-
const boxes = qsa(root, sel('addresses'));
|
|
148
|
-
if (!boxes.length) return;
|
|
149
|
-
showGlobal(root, { 'addresses-loading': true, 'addresses-empty': false });
|
|
150
|
-
let list;
|
|
151
|
-
try { list = addressCache = await addresses(); } catch (err) {
|
|
152
|
-
reportError(err, 'addresses'); // not "no addresses yet": keep what's shown
|
|
153
|
-
showGlobal(root, { 'addresses-loading': false, 'addresses-error': true });
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
showGlobal(root, { 'addresses-loading': false, 'addresses-empty': list.length === 0, 'addresses-error': false });
|
|
157
|
-
boxes.forEach((box) => repeat(box, list, (row, a) => {
|
|
158
|
-
row.dataset.tetherAddress = a.id;
|
|
159
|
-
qsa(row, sel('address-bind')).concat(row.matches(sel('address-bind')) ? [row] : []).forEach((b) => {
|
|
160
|
-
const v = { formatted: lines(a), name: [a.firstName, a.lastName].filter(Boolean).join(' '), company: a.company || '', address1: a.address1 || '', address2: a.address2 || '', city: a.city || '', zip: a.zip || '', province: a.province || '', country: a.country || '', phone: a.phoneNumber || '' }[get(b, 'address-bind')];
|
|
161
|
-
if (v != null) setText(b, v);
|
|
162
|
-
});
|
|
163
|
-
showIn(row, 'address-show', { default: a.isDefault, 'not-default': !a.isDefault });
|
|
164
|
-
}));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const SUB_ACTIONS = ['pause', 'resume', 'skip', 'unskip', 'cancel'];
|
|
168
|
-
function subConds(c) {
|
|
169
|
-
const next = c.upcomingBillingCycles?.nodes?.[0];
|
|
170
|
-
const st = c.status;
|
|
171
|
-
return {
|
|
172
|
-
active: st === 'ACTIVE', paused: st === 'PAUSED', cancelled: st === 'CANCELLED', expired: st === 'EXPIRED', failed: st === 'FAILED',
|
|
173
|
-
skipped: Boolean(next?.skipped), 'can-pause': st === 'ACTIVE', 'can-resume': st === 'PAUSED' || st === 'FAILED',
|
|
174
|
-
'can-skip': st === 'ACTIVE' && Boolean(next) && !next.skipped, 'can-unskip': st === 'ACTIVE' && Boolean(next?.skipped), 'can-cancel': st === 'ACTIVE' || st === 'PAUSED' || st === 'FAILED',
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
async function renderSubscriptions(root) {
|
|
178
|
-
const boxes = qsa(root, sel('subscriptions'));
|
|
179
|
-
if (!boxes.length) return;
|
|
180
|
-
showGlobal(root, { 'subscriptions-loading': true, 'subscriptions-empty': false });
|
|
181
|
-
let list;
|
|
182
|
-
try { list = await subscriptions(); } catch (err) {
|
|
183
|
-
reportError(err, 'subscriptions');
|
|
184
|
-
showGlobal(root, { 'subscriptions-loading': false, 'subscriptions-error': true });
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
showGlobal(root, { 'subscriptions-loading': false, 'subscriptions-empty': list.length === 0, 'subscriptions-error': false });
|
|
188
|
-
boxes.forEach((box) => repeat(box, list, (row, c) => {
|
|
189
|
-
row.dataset.tetherSubscription = c.id;
|
|
190
|
-
row.setAttribute(attr('subscription-status'), lower(c.status));
|
|
191
|
-
const ls = c.lines?.nodes || [];
|
|
192
|
-
const n = c.deliveryPolicy?.intervalCount?.count || 1;
|
|
193
|
-
const unit = lower(c.deliveryPolicy?.interval);
|
|
194
|
-
const total = ls.reduce((sum, l) => sum + parseFloat(l.lineDiscountedPrice?.amount || 0), 0);
|
|
195
|
-
qsa(row, sel('subscription-bind')).forEach((b) => {
|
|
196
|
-
const k = get(b, 'subscription-bind');
|
|
197
|
-
const v = {
|
|
198
|
-
status: lower(c.status), next: c.nextBillingDate ? date(c.nextBillingDate) : '', interval: unit ? (n === 1 ? unit : `${n} ${unit}s`) : '',
|
|
199
|
-
products: ls.map((l) => `${l.quantity}× ${l.title}`).join(', '), total: ls.length ? formatMoney({ amount: String(total), currencyCode: c.currencyCode }) : '',
|
|
200
|
-
delivery: c.deliveryPrice ? formatMoney(c.deliveryPrice) : '',
|
|
201
|
-
}[k];
|
|
202
|
-
if (v != null) setText(b, v);
|
|
203
|
-
});
|
|
204
|
-
qsa(row, sel('subscription-lines')).forEach((lb) => repeat(lb, ls, (lr, l) => {
|
|
205
|
-
qsa(lr, sel('subscription-line')).concat(lr.matches(sel('subscription-line')) ? [lr] : []).forEach((b) => {
|
|
206
|
-
const k = get(b, 'subscription-line');
|
|
207
|
-
if (k === 'image') { if (l.image) setImage(b, l.image.url, l.image.altText || l.title); return; }
|
|
208
|
-
const v = { title: l.title, 'variant-title': l.variantTitle || '', quantity: String(l.quantity), price: formatMoney(l.currentPrice) }[k];
|
|
209
|
-
if (v != null) setText(b, v);
|
|
210
|
-
});
|
|
211
|
-
}));
|
|
212
|
-
const conds = subConds(c);
|
|
213
|
-
showIn(row, 'subscription-show', conds);
|
|
214
|
-
qsa(row, sel('subscription-action')).forEach((btn) => {
|
|
215
|
-
const a = get(btn, 'subscription-action');
|
|
216
|
-
const ok = conds[`can-${a}`];
|
|
217
|
-
btn.disabled = !ok;
|
|
218
|
-
btn.classList.toggle('is-disabled', !ok);
|
|
219
|
-
});
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Order page, profile form, addresses, subscriptions: only what the page has. */
|
|
224
|
-
export async function renderPages(root = document) {
|
|
225
|
-
if (!bound) { bound = true; bindPages(); }
|
|
226
|
-
await Promise.all([
|
|
227
|
-
...qsa(root, sel('order')).map((el) => renderOrder(el)),
|
|
228
|
-
...qsa(root, sel('profile-form')).map((f) => renderProfile(f)),
|
|
229
|
-
renderAddresses(root),
|
|
230
|
-
renderSubscriptions(root),
|
|
231
|
-
]);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const fieldsOf = (form) => Object.fromEntries([...form.elements].filter((i) => i.name && i.type !== 'submit' && i.type !== 'button' && i.type !== 'checkbox').map((i) => [i.name, i.value]));
|
|
235
|
-
async function act(el, fn, { error } = {}) {
|
|
236
|
-
if (el.getAttribute('aria-busy') === 'true') return undefined; // already sending: no second request (Enter, double click)
|
|
237
|
-
el.classList.add('is-busy'); el.setAttribute('aria-busy', 'true');
|
|
238
|
-
el.setAttribute(attr('form-state'), 'pending');
|
|
239
|
-
qsa(el, sel('form-error')).forEach((e) => setText(e, ''));
|
|
240
|
-
try {
|
|
241
|
-
const out = await fn();
|
|
242
|
-
el.setAttribute(attr('form-state'), 'saved');
|
|
243
|
-
return out;
|
|
244
|
-
} catch (err) {
|
|
245
|
-
el.setAttribute(attr('form-state'), 'error');
|
|
246
|
-
const msg = err?.userErrors?.map((u) => u.message).join(' ') || err?.message || 'Something went wrong';
|
|
247
|
-
qsa(el, sel('form-error')).forEach((e) => setText(e, msg.replace(/^Customer accounts: /, '')));
|
|
248
|
-
if (error) reportError(err, error);
|
|
249
|
-
return undefined;
|
|
250
|
-
} finally { el.classList.remove('is-busy'); el.removeAttribute('aria-busy'); }
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function bindPages() {
|
|
254
|
-
document.addEventListener('submit', (e) => {
|
|
255
|
-
const f = e.target;
|
|
256
|
-
if (f.matches?.(sel('profile-form'))) {
|
|
257
|
-
e.preventDefault();
|
|
258
|
-
act(f, async () => { await updateProfile(fieldsOf(f)); await ctx.bindCustomer?.(document); });
|
|
259
|
-
} else if (f.matches?.(sel('address-form'))) {
|
|
260
|
-
e.preventDefault();
|
|
261
|
-
const id = f.dataset.tetherAddressId || undefined;
|
|
262
|
-
const isDefault = Boolean(f.elements?.isDefault?.checked);
|
|
263
|
-
act(f, async () => { await saveAddress(fieldsOf(f), { id, isDefault }); f.reset(); delete f.dataset.tetherAddressId; await renderAddresses(document); });
|
|
264
|
-
}
|
|
265
|
-
}, true); // capture: before a router (Astro's ClientRouter) turns the submit into a navigation with the fields in the URL
|
|
266
|
-
document.addEventListener('input', (e) => { if (e.target.closest?.(sel('profile-form'))) e.target.dataset.tetherTouched = '1'; });
|
|
267
|
-
document.addEventListener('click', (e) => {
|
|
268
|
-
const t = e.target;
|
|
269
|
-
const row = t.closest?.('[data-tether-address]');
|
|
270
|
-
const confirmOk = (btn) => { const q = get(btn, 'confirm'); return !q || window.confirm(q); };
|
|
271
|
-
let btn;
|
|
272
|
-
if ((btn = t.closest?.(sel('address-delete'))) && row) {
|
|
273
|
-
e.preventDefault();
|
|
274
|
-
if (confirmOk(btn)) act(row, async () => { await deleteAddress(row.dataset.tetherAddress); await renderAddresses(document); });
|
|
275
|
-
} else if ((btn = t.closest?.(sel('address-default'))) && row) {
|
|
276
|
-
e.preventDefault();
|
|
277
|
-
act(row, async () => { await saveAddress(null, { id: row.dataset.tetherAddress, isDefault: true }); await renderAddresses(document); });
|
|
278
|
-
} else if ((btn = t.closest?.(sel('address-edit'))) && row) {
|
|
279
|
-
e.preventDefault();
|
|
280
|
-
const a = (addressCache || []).find((x) => x.id === row.dataset.tetherAddress);
|
|
281
|
-
const f = document.querySelector(sel('address-form'));
|
|
282
|
-
if (a && f) {
|
|
283
|
-
f.dataset.tetherAddressId = a.id;
|
|
284
|
-
[...f.elements].forEach((i) => { if (i.name && i.name in a) i.value = a[i.name] ?? ''; if (i.name === 'isDefault') i.checked = a.isDefault; });
|
|
285
|
-
f.scrollIntoView?.({ block: 'nearest' });
|
|
286
|
-
}
|
|
287
|
-
} else if ((btn = t.closest?.(sel('address-new')))) {
|
|
288
|
-
const f = document.querySelector(sel('address-form'));
|
|
289
|
-
if (f) { f.reset(); delete f.dataset.tetherAddressId; }
|
|
290
|
-
} else if ((btn = t.closest?.(sel('subscription-action')))) {
|
|
291
|
-
e.preventDefault();
|
|
292
|
-
const sub = btn.closest('[data-tether-subscription]');
|
|
293
|
-
const a = get(btn, 'subscription-action');
|
|
294
|
-
if (!sub || !SUB_ACTIONS.includes(a) || btn.disabled || !confirmOk(btn)) return;
|
|
295
|
-
const id = sub.dataset.tetherSubscription;
|
|
296
|
-
sub.setAttribute(attr('subscription-state'), 'pending');
|
|
297
|
-
act(sub, async () => { await subscriptionAction(id, a); await renderSubscriptions(document); }).then(() => {
|
|
298
|
-
const state = sub.getAttribute(attr('form-state')) === 'error' ? 'error' : 'done';
|
|
299
|
-
// The re-render may have replaced the row: mark the one that shows this subscription now.
|
|
300
|
-
qsa(document, '[data-tether-subscription]').filter((r) => r === sub || r.dataset.tetherSubscription === id)
|
|
301
|
-
.forEach((r) => r.setAttribute(attr('subscription-state'), state));
|
|
302
|
-
});
|
|
303
|
-
} else if ((btn = t.closest?.(sel('order-return')))) {
|
|
304
|
-
e.preventDefault();
|
|
305
|
-
const scope = btn.closest(SCOPE.order);
|
|
306
|
-
if (!scope?.dataset.tetherOrderId) return;
|
|
307
|
-
const req = qsa(scope, '[data-tether-line]').map((r) => ({
|
|
308
|
-
lineItemId: r.dataset.tetherLine,
|
|
309
|
-
quantity: parseInt(r.querySelector(sel('return-quantity'))?.value || '0', 10),
|
|
310
|
-
reasonId: r.querySelector(sel('return-reason'))?.value || undefined,
|
|
311
|
-
note: r.querySelector(sel('return-note'))?.value || undefined,
|
|
312
|
-
})).filter((l) => l.quantity > 0);
|
|
313
|
-
if (!req.length || !confirmOk(btn)) return;
|
|
314
|
-
act(scope, async () => { await requestReturn(scope.dataset.tetherOrderId, req); scope.dataset.tetherReturned = '1'; await renderOrder(scope); });
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|