gw-customer-accounts 1.2.8 → 1.3.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/dist/address-form.js +1 -1
- package/dist/assets/index-DkUQsudo.js +1 -0
- package/dist/assets/{tab-B7UDegaP.js → tab-D4kkRiyw.js} +1 -1
- package/dist/dashboard.js +1 -1
- package/dist/loyalty-integrations.js +1 -1
- package/dist/main.js +1 -1
- package/dist/malomo-button.js +1 -1
- package/dist/orders.js +1 -1
- package/dist/preferences-form.js +1 -1
- package/dist/profile.js +1 -1
- package/dist/quick-add-to-cart.js +1 -1
- package/dist/sign-in.js +1 -1
- package/dist/wishlist-button.js +1 -1
- package/package.json +1 -1
- package/src/scripts/components/sign-in.js +20 -1
- package/src/scripts/utils/constants.js +2 -0
- package/dist/assets/index-DI2a6rRk.js +0 -1
package/dist/address-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as a,a as i}from"./assets/index-
|
|
1
|
+
import{G as a,a as i}from"./assets/index-DkUQsudo.js";customElements.define("gw-address-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.type=this.getAttribute("type"),this.addressId=this.getAttribute("address-id")}connectedCallback(){if(this._handleFormSubmit(),this.type==="edit"){const e=this.querySelector("[data-delete-address]");if(!e)return;e.addEventListener("click",()=>{this._deleteAddress()})}this.type}async _handleFormSubmit(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{this.form.addEventListener("sl-invalid",e=>{e.preventDefault(),this._clearErrorMessages(),this.form.querySelectorAll("sl-input").forEach(t=>{if(t.hasAttribute("data-invalid")){const r=document.createElement("div");r.slot="help-text",r.classList.add("gw-error-message"),r.textContent=t.validationMessage,t.appendChild(r)}}),e.target.focus()},{capture:!0}),this.form.addEventListener("submit",e=>{e.preventDefault();const t=new FormData(this.form),r=Object.fromEntries(t.entries());this._submitAddressForm(r)})})}async _submitAddressForm(e){try{this._clearErrorMessages(),this.form.querySelector("[data-loader]").hidden=!1,e.province&&(e.province=e.province.replaceAll("_"," ")),e.country=e.country.replaceAll("_"," ");let t=e.isDefault;delete e.isDefault;let r=null;if(this.type==="edit"?r=await a.request(i.ENDPOINTS.ADDRESS.EDIT,{address:e,addrID:this.addressId,isDefault:t}):r=await a.request(i.ENDPOINTS.ADDRESS.ADD,{address:e,isDefault:t}),r.error)throw new Error(r.error);this.form.closest("sl-drawer").hide(),a.updateAjaxContent(["[data-gw-addresses-list]","[data-gw-addresses-carousel]"])}catch(t){console.error(t)}finally{this.form.querySelector("[data-loader]").hidden=!0}}async _deleteAddress(){try{this.querySelector("[data-delete-address]").querySelector("[data-loader]").hidden=!1;let e=await a.request(i.ENDPOINTS.ADDRESS.REMOVE,{addrID:this.addressId});if(e.error)throw new Error(e.error);this.form.closest("sl-drawer").hide(),await a.app.updateContent(["[data-gw-addresses-list]","[data-gw-addresses-carousel]"])}catch(e){console.error(e)}}_handleSubmitButton(){const e=this.form.querySelectorAll("sl-input, sl-select, sl-checkbox"),t=this.form.querySelector('button[type="submit"]'),r=()=>Array.from(e).some(s=>{if(s.tagName==="SL-CHECKBOX"){const n=s.getAttribute("defaultChecked"),c=s.getAttribute("checked");return n!==c}const d=s.getAttribute("value"),l=s.value;return d!==l});e.forEach(o=>{o.addEventListener("sl-input",()=>{r()?t.hidden=!1:t.hidden=!0})})}_clearErrorMessages(){this.form.querySelectorAll(".gw-error-message").forEach(e=>e.remove())}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=Object.freeze({MAP:{"#my-account":"dashboard","#my-orders":"orders","#my-profile":"profile","#my-favorites":"dashboard##favorites"},STORAGE_KEYS:{TOKEN:"i-shsgi--u0mihh3co1e3y9sns",EMAIL:"gw-customer-accounts-email",RECENTLY_VIEWED:"gw-recently-viewed",RECENTLY_VIEWED_COLLECTION:"gw-recently-viewed-collection",LOYALTY_POINTS:"gw-loyalty-points",YOTPO_POINTS:"gw-yotpo-points",WISHLIST_PRODUCT_IDS:"gw-wishlist-product-ids",RISE_POINTS:"gw-rise-points",REDIRECT_URL:"gw-customer-accounts-login-redirect",TEMP_WISHLIST_PRODUCTS:"gw-temp-wishlist-products",TEMP_CART_PRODUCTS:"gw-temp-cart-products",TEMP_RECENTLY_VIEWED_ITEMS:"gw-temp-recently-viewed-items",TEMP_PRODUCTS_UPDATED:"gw-temp-products-updated"},ENDPOINTS:{AUTH:{SIGN_IN:"/email-sign",SIGN_IN_TEST:"/email-sign-test",VERIFY_CODE:"/code-sign",GET_TOKEN:"/logged-sign",CUSTOMER_LOGGED:"/customer-logged",GET_CAPTCHA_TOKEN:"/get-token"},FAVORITES:{GET_ALL_IDS:"/get-all-favorites",GET:"/get-favorites",ADD:"/add-favorite",REMOVE:"/remove-favorite",ADD_BULK:"/add-favorites"},VIEWED_PRODUCTS:{GET:"/get-viewed-products",ADD:"/add-viewed-product",ADD_BULK:"/add-viewed-products"},CART:{GET:"/get-cart-products",ADD:"/add-cart-product",ADD_BULK:"/add-cart-products",REMOVE:"/remove-cart"},ADDRESS:{ADD:"/add-address",EDIT:"/edit-address",REMOVE:"/remove-address"},CUSTOMER:{UPDATE:"/update-customer"},LOYALTY:{GET_LL:"/get-ll-customer",GET_YOTPO_CUSTOMER:"/get-youtpo-customer",GET_RISE_CREDIT:"/get-rise-customer"},MISC:{GET_MALOMO_ORDER:"/get-malomo-order"}},TAGS_TO_HIDE:["accounts:hidden"],TEMPLATE_IDS:{PRODUCT_CARD:"gw-standard-product-card-template",FORM_PRODUCT_CARD:"gw-form-product-card-template"},CUSTOM_EVENTS:{FAVORITES_STORAGE_UPDATED:"gw:favorites-storage-updated",SAVED_ITEMS_FROM_CART:"gw:saved-items-from-cart"},DRAWER_IDS:{favorites:"#Drawer-Favorites"}});class u{constructor(){}get componentData(){const e=document.querySelector("gw-customer-accounts").shadowRoot.querySelector("[data-component-data]");return JSON.parse(e.textContent)}get customerId(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.id}get customerFirstName(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.firstName}get customerEmail(){return localStorage.getItem(i.STORAGE_KEYS.EMAIL)}get hasCustomer(){var t,e;return!!((e=(t=this.componentData)==null?void 0:t.customer)!=null&&e.id)}get customerToken(){return localStorage.getItem(i.STORAGE_KEYS.TOKEN)}get baseURL(){return this.componentData.baseUrl}get app(){return document.querySelector("gw-customer-accounts")}get appShadow(){return this.app.shadowRoot}get dashboard(){return this.appShadow.querySelector("gw-customer-accounts-dashboard")}get tabId(){return i.MAP[window.location.hash]||"dashboard"}async request(t,e={},s="POST"){const a=()=>{const o={method:s,mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}};return s==="POST"&&(o.body=JSON.stringify(e)),o};if(s==="GET"){const o=new URLSearchParams(e);t=`${t}?${o}`}return s==="POST"&&(e.token=this.customerToken,e.email=this.customerEmail,e.customerID=this.customerId),await(await fetch(this.baseURL+t,a())).json()}notify(t,e="success",s=3e3){const a=document.querySelector("gw-customer-accounts"),r=a.shadowRoot.querySelector("[data-notification-alert]"),o=a.shadowRoot.querySelector("[data-notification-message]");o.innerHTML=t,r.open=!0}async updateAjaxContent(t){return await this.app.updateContent(t)}parseVariantId(t){return String(t).split("/").pop()}formatMoney(t){return(t/100).toLocaleString("en-US",{style:"currency",currency:"USD"})}addToStorage({key:t,values:e,storageType:s="local",position:a="start"}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];a==="start"?r.setItem(t,JSON.stringify([...e,...o])):r.setItem(t,JSON.stringify([...o,...e]))}removeFromStorage({key:t,values:e,storageType:s="local",nestedKey:a}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];if(a){const n=o.map(c=>e.includes(c[a])?null:c);r.setItem(t,JSON.stringify(n.filter(Boolean)))}else{const n=o.filter(c=>!e.includes(c));r.setItem(t,JSON.stringify(n))}}}const E=new u;export{E as G,i as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as i,a as e}from"./index-
|
|
1
|
+
import{G as i,a as e}from"./index-DkUQsudo.js";class l extends HTMLElement{constructor(){var a;super(),this.tabData=this._parseTabData(),this.tabId=(a=this.tabData)==null?void 0:a.id,this.tabGroup=this.closest("sl-tab-group"),this.tabPanel=this.closest("sl-tab-panel"),this.mainDrawerLabel=i.appShadow.querySelector("[data-main-drawer-label]")}connectedCallback(){if(this._addAnimations(),this.tabGroup.addEventListener("sl-tab-show",n=>{n.detail.name===this.tabId?(this._playFadeInAnimations(),this._updateMainDrawerLabel(),this._updateSignInBlockHeading(),this._updateHash(),i.app.reinitializeCarousels()):this._resetAnimations()}),!e.MAP[window.location.hash])return;const a=window.location.hash===this.tabId,t=e.MAP[window.location.hash].includes(this.tabId);(a||t)&&this._playFadeInAnimations()}get animationElements(){const t=[...this.querySelectorAll("sl-animation")],n=i.appShadow.querySelector("[gw-sign-in-block-animation]");return n&&t.unshift(n),t}_parseTabData(){const a=this.querySelector("[data-tab-panel-data]");return a?JSON.parse(a.textContent):{}}_updateHash(){var n,s;const a=window.location.hash;(n=e.MAP[a])!=null&&n.includes("##")||(window.location.hash=(s=this.tabData)==null?void 0:s.hash)}_updateMainDrawerLabel(){var t;const a=(t=this.tabData)==null?void 0:t.label;a&&this.mainDrawerLabel&&(this.mainDrawerLabel.textContent=a)}_updateSignInBlockHeading(){var n;const a=(n=this.tabData)==null?void 0:n.signInBlockHeading,t=i.appShadow.querySelector("[data-sign-in-block-heading]");a&&t&&(t.textContent=a)}_playFadeInAnimations(){this.animationElements.forEach(a=>a.play=!0)}_addAnimations(){this.animationElements.forEach((a,t)=>{a.keyframes=[{offset:0,opacity:"0",transform:"translate3d(0, -10px, 0)",easing:"ease-in-out"},{offset:1,opacity:"1",transform:"translate3d(0, 0, 0)",easing:"ease-in-out"}],a.delay=t*80})}_resetAnimations(){this.animationElements.forEach(a=>{a.currentTime>0&&(a.currentTime=0)})}}export{l as G};
|
package/dist/dashboard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as i,a as m}from"./assets/index-
|
|
1
|
+
import{G as i,a as m}from"./assets/index-DkUQsudo.js";import{G as f}from"./assets/tab-D4kkRiyw.js";customElements.define("gw-customer-accounts-dashboard",class extends f{constructor(){super()}connectedCallback(){super.connectedCallback(),this._initDashboard()}async _initDashboard(){i.hasCustomer&&this._renderRecentlyViewedCollections(),this.loadSavedCartItems(),this.loadFavoriteItems(),this.loadRecentlyViewedItems()}async loadRecentlyViewedItems(e={}){const{preventDrawerRender:a=!1,preventCarouselRender:r=!1,page:t=1,limit:o=8}=e;try{const n=await this._getRecentlyViewedItems(t,o);this._renderRecentlyViewedItems(n,{preventDrawerRender:a,preventCarouselRender:r,page:t,limit:o})}catch(n){console.error("Error rendering recently viewed items:",n)}}async _getRecentlyViewedItems(e,a){if(!i.hasCustomer)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS))||[];const r=await i.request(m.ENDPOINTS.VIEWED_PRODUCTS.GET,{customerID:i.customerId,limit:a,page:e},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderRecentlyViewedItems(e,a){const r="[data-recently-viewed-container]",t="[data-recently-viewed-drawer-container]";if(i.appShadow.querySelector(r)){if(!e.length){this._renderEmptyState(r,t);return}a.preventCarouselRender||this._renderProductsToCarousel(e,r),a.preventDrawerRender||this._renderProductsToDrawer({products:e,containerSelector:t,productTemplateId:m.TEMPLATE_IDS.PRODUCT_CARD,currentPage:a.page,nextPage:null})}}async _getSavedCartItems(e,a){if(!i.customerId)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[];const r=await i.request(m.ENDPOINTS.CART.GET,{customerEmail:i.customerEmail,limit:a,page:e},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderSavedCartItems(e,a){const r="[data-saved-from-cart-items-container]",t="[data-saved-from-cart-drawer-container]";if(!this.querySelector(r))return;if(!e.length){this._renderEmptyState(r,t);return}const n=this._calculateNextPage({totalItems:e.length,currentPage:a.page,limit:a.limit});a.preventCarouselRender||this._renderProductsToCarousel(e,r),a.preventDrawerRender||this._renderProductsToDrawer({products:e,containerSelector:t,removeButtonAction:"data-saved-from-cart-remove",productTemplateId:m.TEMPLATE_IDS.FORM_PRODUCT_CARD,currentPage:a.page,nextPage:n})}async loadSavedCartItems(e={}){const{preventDrawerRender:a=!1,preventCarouselRender:r=!1,page:t=1,limit:o=10}=e;try{const n=await this._getSavedCartItems(t,o);this._renderSavedCartItems(n,{preventDrawerRender:a,preventCarouselRender:r,page:t,limit:o})}catch(n){console.error("Error rendering saved items from cart:",n)}}async _getFavoriteItems(e,a){if(!i.hasCustomer)return JSON.parse(localStorage.getItem(m.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS))||[];const r=await i.request(m.ENDPOINTS.FAVORITES.GET,{limit:a,page:e,customerID:i.customerId},"GET");if(r.error)throw new Error(r.error);return r.products||[]}_renderFavoriteItems(e,a){const r="[data-favorites-container]",t="[data-favorites-drawer-container]";if(!i.appShadow.querySelector(r))return;if(!e.length){this._renderEmptyState(r,t,"You have no favorite items.");return}const{preventDrawerRender:n=!1,preventCarouselRender:s=!1,page:d=1,limit:l=10}=a;s||this._renderProductsToCarousel(e,r);const c=this._calculateNextPage({totalItems:e.length,currentPage:d,limit:l});n||this._renderProductsToDrawer({products:e,containerSelector:t,removeButtonAction:"data-wishlist-remove",productTemplateId:m.TEMPLATE_IDS.FORM_PRODUCT_CARD,currentPage:d,nextPage:c})}_renderSingleFavoriteItem(e){const a="[data-favorites-container]",r="[data-favorites-drawer-container]",t=i.appShadow.querySelector(a),o=document.getElementById(m.TEMPLATE_IDS.PRODUCT_CARD);if(!o){console.warn("Product card template not found.");return}const n=o.content.cloneNode(!0),s=this._populateCarouselItem(n,e),d=t.querySelector("sl-carousel");if(d)d.prepend(s);else{const c=document.createElement("sl-carousel");c.setAttribute("navigation",""),c.setAttribute("slides-per-page","3"),c.setAttribute("slides-per-move","3"),c.setAttribute("style","--scroll-hint: 5%; --aspect-ratio: none"),c.appendChild(s),t.innerHTML="",t.appendChild(c)}const l=i.appShadow.querySelector(r);if(l){const c=document.getElementById(m.TEMPLATE_IDS.FORM_PRODUCT_CARD);if(!c){console.warn("Drawer product card template not found.");return}const p=this._createProductElement(e,c,"data-wishlist-remove");this._ensureDrawerNotEmpty(t),l.prepend(p)}}_removeFavoriteItem(e){const a="[data-favorites-container]",r="[data-favorites-drawer-container]",t=i.appShadow.querySelector(a),o=i.appShadow.querySelector(r);if(t){const n=t.querySelector(`[data-product-id="${e}"]`);n&&n.remove(),t.querySelector("sl-carousel-item")||this._renderEmptyState(a,r,"You have no favorite items.")}if(o){const n=o.querySelector(`[data-product-id="${e}"]`);n&&n.remove()}}async loadFavoriteItems(e={}){const{page:a=1,limit:r=10}=e;try{const t=await this._getFavoriteItems(a,r);this._renderFavoriteItems(t,e)}catch(t){console.error("Error rendering favorite items:",t)}}_renderRecentlyViewedCollections(){const e=m.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION,a=JSON.parse(localStorage.getItem(e))||[],r=this.querySelector("[data-recently-viewed-collections-container]");if(!r||(r.innerHTML="",!a.length))return;const t=document.createElement("sl-carousel");t.setAttribute("navigation",""),t.setAttribute("style","--scroll-hint: 5%; --aspect-ratio: none"),a.forEach(o=>{const n=document.createElement("sl-carousel-item");n.innerHTML=`
|
|
2
2
|
<a href="${o.url}" class="gw-button-text gw-unstyled-link gw-recently-viewed-collection">
|
|
3
3
|
${o.title}
|
|
4
4
|
</a>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as i,G as r}from"./assets/index-
|
|
1
|
+
import{a as i,G as r}from"./assets/index-DkUQsudo.js";customElements.define("gw-integrations-loyalty-points",class extends HTMLElement{constructor(){switch(super(),this.integration=this.getAttribute("integration"),this.loyaltyPageUrl=this.getAttribute("page-url"),this.pointsLabel=this.getAttribute("points-label"),this.linkLabel=this.getAttribute("link-label"),this.innerHTML=`
|
|
2
2
|
<a href="${this.loyaltyPageUrl}" class="gw-loyalty-points__link gw-unstyled-link">
|
|
3
3
|
<span class="gw-loader" data-loader></span>
|
|
4
4
|
<span class="gw-loyalty-points__points-value gw-header" data-points-container></span>
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as i,a as s}from"./assets/index-DI2a6rRk.js";customElements.define("gw-customer-accounts",class extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.getElementById("gw-customer-accounts-template");this.shadow.appendChild(t.content.cloneNode(!0)),t.remove(),this.drawer=this.shadowRoot.querySelector("sl-drawer"),this.tabGroup=this.shadowRoot.querySelector("sl-tab-group"),this.closeButtons=this.drawer.querySelectorAll("[data-main-drawer-close]")}connectedCallback(){this._checkCustomerStatus(),this._watchSavedItemsFromCart(),i.hasCustomer&&(this._saveTempWishlistProducts(),this._saveTempCartProducts(),this._saveTempRecentlyViewedProducts()),Promise.all([customElements.whenDefined("sl-drawer")]).then(()=>this.init())}init(){this.drawer.removeAttribute("hidden"),window.location.search.includes("my-account-open")&&!window.location.pathname.includes("/account")&&(window.history.replaceState({},document.title,window.location.pathname),window.location.hash="#my-account"),window.addEventListener("hashchange",()=>{this._handleHashChange(),this.reinitializeCarousels()}),this._handleHashChange(),this.closeButtons.forEach(t=>{t.addEventListener("click",()=>{this._closeDrawer()})}),this.drawer.addEventListener("sl-hide",t=>{t.target===this.drawer&&(window.location.hash="")}),this._updateAccountLinks(),this._handleInputElements(),this._addRecentlyViewedProducts(),i.hasCustomer&&this._updateRecentlyViewedCollection(),this.reinitializeCarousels(),this.shadowRoot.addEventListener("click",t=>{if(!t.target.closest("[data-drawer-id]"))return;const o=t.target.closest("[data-drawer-id]").getAttribute("data-drawer-id"),r=this.shadowRoot.querySelector(`#${o}`);r.hasAttribute("empty")||(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}),this.shadowRoot.addEventListener("click",t=>{t.target.closest("[data-inner-drawer-close]")&&(t.target.closest("sl-drawer").open=!1,navigator.userAgent.indexOf("iPhone")>-1&&this.drawer.classList.remove("inner-drawer-open"))}),i.hasCustomer&&this.updateFavoriteItemsStorage(),!i.hasCustomer&&sessionStorage.getItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED)!=="true"&&this._syncTempProducts()}reinitializeCarousels(){Promise.all([customElements.whenDefined("sl-carousel"),customElements.whenDefined("sl-carousel-item")]).then(()=>{setTimeout(()=>{this.shadowRoot.querySelectorAll("sl-carousel").forEach(t=>{t.initializeSlides()})},1e3)})}_updateAccountLinks(){const t=document.querySelectorAll("a[href]");Array.from(t).filter(r=>r.getAttribute("href").includes("/account")||r.getAttribute("href").startsWith("#status")).forEach(r=>{r.hasAttribute("data-ignore-account-link")||(r.getAttribute("href").includes("logout")?r.href="#my-profile":r.href="#my-account",Shopify.designMode&&r.addEventListener("click",()=>{this._openDrawer()}))})}_handleInputElements(){const t=e=>{!e.value&&!e.getAttribute("value")?e.classList.add("input--empty"):e.classList.remove("input--empty")},o=e=>{e.classList.add("input--focus")},r=e=>{e.classList.remove("input--focus")};this.shadowRoot.querySelectorAll("sl-input").forEach(e=>{e.addEventListener("sl-input",()=>t(e)),e.addEventListener("sl-focus",()=>o(e)),e.addEventListener("sl-blur",()=>r(e)),t(e)})}async _handleHashChange(){const t=window.location.hash;if(s.MAP[t]){if(await this._fetchComponents(),s.MAP[t].includes("##")){const[o,r]=s.MAP[t].split("##");this._renderTab(o),setTimeout(()=>{this._renderSubTab(r),this._openDrawer()},100);return}else this.shadowRoot.querySelectorAll("sl-drawer").forEach(o=>{o.open=!1});this._renderTab(),this._openDrawer()}}async _openDrawer(){this.drawer.open||this.drawer.show()}_closeDrawer(){this.drawer.open&&this.drawer.hide()}_fetchComponents(){const t="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.19.1/cdn/components/",r=["tab-group","tab-panel","tab","animation","skeleton","select","input","checkbox","carousel","carousel-item","popup","option","alert"].map(e=>new Promise((n,a)=>{if(customElements.get(`sl-${e}`)){n();return}const c=document.createElement("script");c.type="module",c.src=`${t}${e}/${e}.js`,c.onload=n,c.onerror=a,document.body.appendChild(c)}));return Promise.all(r)}async _addRecentlyViewedProducts(){if(!window.location.pathname.includes("/products/"))return;const{product:o}=i.componentData;if(!o||!(o!=null&&o.id))return;const{id:r}=o;if(i.hasCustomer)try{const e=await i.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD,{prodID:r});if(e.error)throw new Error(e.error);return e}catch(e){console.error(e)}else{if(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS)||"[]").some(n=>n.id===r))return;i.addToStorage({key:s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS,values:[{...o}]})}}_updateRecentlyViewedCollection(){if(!window.location.pathname.includes("/collections/"))return;const{collection:o}=i.componentData;if(!o)return;const{url:r,title:e}=o,n=localStorage.getItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION),c=(JSON.parse(n)||[]).filter(l=>l.url!==r),d=[{url:r,title:e},...c];localStorage.setItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION,JSON.stringify(d))}_renderTab(t){Promise.all([(customElements.whenDefined("sl-tab-group"),customElements.whenDefined("sl-tab-panel"),customElements.whenDefined("sl-tab"))]).then(()=>{this.tabGroup.show(t||i.tabId)})}_renderSubTab(t){const o=s.DRAWER_IDS[t];if(!o)return;const r=this.shadowRoot.querySelector(o);r&&(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}async updateContent(t=[]){const o=this.getAttribute("data-section-id"),r=await this._fetchContent(o);t.forEach(e=>{const n=this.shadow.querySelector(e);if(n){const c=r.querySelector("#gw-customer-accounts-template").content.querySelector(e);n.innerHTML=c.innerHTML}})}async _fetchContent(t){const r=await(await fetch(window.location.pathname+`?section_id=${t}`)).text();return new DOMParser().parseFromString(r,"text/html")}async updateFavoriteItemsStorage(t){const{removeIds:o,addIds:r}=t||{};let e=!1;if(r!=null&&r.length&&(i.addToStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:r,storageType:"session"}),e=!0),o!=null&&o.length&&(i.removeFromStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:o,storageType:"session"}),e=!0),e){this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED));return}try{const n=await i.request(s.ENDPOINTS.FAVORITES.GET_ALL_IDS,{customerID:i.customerId},"GET");if(n.error)throw new Error(n.error);sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(n.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))}catch(n){console.error("Error initializing wishlist:",n)}}async _checkCustomerStatus(){const t=i.customerToken,{id_sha256:o,email:r,tags:e,id:n}=i.componentData.customer;if(!t&&n)try{const a=await i.request(s.ENDPOINTS.AUTH.GET_TOKEN,{customerEmail:r,encode:o},"POST");if(a.error)throw new Error(a.error);a.token&&(localStorage.setItem(s.STORAGE_KEYS.TOKEN,a.token),localStorage.setItem(s.STORAGE_KEYS.EMAIL,r))}catch(a){console.error("Error checking customer status:",a)}if(e&&!e.includes("gw-customer"))try{const a=await i.request(s.ENDPOINTS.AUTH.CUSTOMER_LOGGED,{});if(a.error)throw new Error(a.error)}catch(a){console.error("Error checking customer status:",a)}}async _saveTempWishlistProducts(){var r;const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(e=>{const{id:n,variantId:a}=e;return{prodID:n,varID:a}})};try{const e=await i.request(s.ENDPOINTS.FAVORITES.ADD_BULK,o);if(e.error)throw new Error(e.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS),(r=e.products)!=null&&r.length&&(sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(e.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))),i.dashboard.loadFavoriteItems()}catch(e){console.error("Error saving temp wishlist products:",e)}}async _saveTempCartProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e,variantId:n}=r;return{prodID:e,varID:n}})};try{const r=await i.request(s.ENDPOINTS.CART.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS),i.dashboard.loadSavedCartItems()}catch(r){console.error("Error saving temp cart products:",r)}}async _saveTempRecentlyViewedProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e}=r;return{prodID:e}})};try{const r=await i.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS),console.log("Saved temp recently viewed products:",r),i.dashboard.loadRecentlyViewedItems()}catch(r){console.error("Error saving temp recently viewed products:",r)}}async _watchSavedItemsFromCart(){this.addEventListener(s.CUSTOM_EVENTS.SAVED_ITEMS_FROM_CART,async t=>{i.hasCustomer?await this._handleAuthedCartEvent(t):this._handleGuestCartEvent(t)})}async _handleGuestCartEvent(t){const o=t.detail.extra,r=o.handle,e={};try{const n=await fetch(`/products/${r}.js`);if(!n.ok)throw new Error("Product not found");const a=await n.json();e.variant_id=o.variant_id,e.featuredImage=o.featured_image,e.title=o.title,e.variants={},e.variants.nodes=a.variants,e.id=a.id,e.tags=a.tags,e.handle=a.handle;const d=(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[]).filter(u=>u.id!==a.id),l=[e,...d];localStorage.setItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS,JSON.stringify(l)),i.dashboard.loadSavedCartItems()}catch(n){console.error("Error adding product to cart:",n)}}async _handleAuthedCartEvent(t){try{const{productId:o,variantId:r}=t.detail||{};if(!o||!r)return;const e=await i.request(s.ENDPOINTS.CART.ADD,{prodID:o,varID:r});if(e.error)throw new Error(e.error);i.dashboard.loadSavedCartItems()}catch(o){console.error("Error adding product to cart:",o)}}async _syncTempProducts(){const t=[s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,s.STORAGE_KEYS.TEMP_CART_PRODUCTS,s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS],o=t.flatMap(a=>(JSON.parse(localStorage.getItem(a))||[]).filter(Boolean)),r=[...new Map(o.map(a=>[a.id,a])).values()];console.log("Unique products:",r);const n=(await Promise.all(r.map(async({id:a,handle:c})=>{try{const d=await fetch(`/products/${c}.js`);return d.ok?await d.json():null}catch{return null}}))).reduce((a,c)=>(c&&c.available&&(a[c.id]=c),a),{});t.forEach(a=>{const d=(JSON.parse(localStorage.getItem(a))||[]).map(l=>{if(!l)return null;const u=n[l.id];return u?(l.variants.nodes=u.variants,l):null}).filter(Boolean);localStorage.setItem(a,JSON.stringify(d))}),sessionStorage.setItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED,"true")}});
|
|
1
|
+
import{G as i,a as s}from"./assets/index-DkUQsudo.js";customElements.define("gw-customer-accounts",class extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"});const t=document.getElementById("gw-customer-accounts-template");this.shadow.appendChild(t.content.cloneNode(!0)),t.remove(),this.drawer=this.shadowRoot.querySelector("sl-drawer"),this.tabGroup=this.shadowRoot.querySelector("sl-tab-group"),this.closeButtons=this.drawer.querySelectorAll("[data-main-drawer-close]")}connectedCallback(){this._checkCustomerStatus(),this._watchSavedItemsFromCart(),i.hasCustomer&&(this._saveTempWishlistProducts(),this._saveTempCartProducts(),this._saveTempRecentlyViewedProducts()),Promise.all([customElements.whenDefined("sl-drawer")]).then(()=>this.init())}init(){this.drawer.removeAttribute("hidden"),window.location.search.includes("my-account-open")&&!window.location.pathname.includes("/account")&&(window.history.replaceState({},document.title,window.location.pathname),window.location.hash="#my-account"),window.addEventListener("hashchange",()=>{this._handleHashChange(),this.reinitializeCarousels()}),this._handleHashChange(),this.closeButtons.forEach(t=>{t.addEventListener("click",()=>{this._closeDrawer()})}),this.drawer.addEventListener("sl-hide",t=>{t.target===this.drawer&&(window.location.hash="")}),this._updateAccountLinks(),this._handleInputElements(),this._addRecentlyViewedProducts(),i.hasCustomer&&this._updateRecentlyViewedCollection(),this.reinitializeCarousels(),this.shadowRoot.addEventListener("click",t=>{if(!t.target.closest("[data-drawer-id]"))return;const o=t.target.closest("[data-drawer-id]").getAttribute("data-drawer-id"),r=this.shadowRoot.querySelector(`#${o}`);r.hasAttribute("empty")||(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}),this.shadowRoot.addEventListener("click",t=>{t.target.closest("[data-inner-drawer-close]")&&(t.target.closest("sl-drawer").open=!1,navigator.userAgent.indexOf("iPhone")>-1&&this.drawer.classList.remove("inner-drawer-open"))}),i.hasCustomer&&this.updateFavoriteItemsStorage(),!i.hasCustomer&&sessionStorage.getItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED)!=="true"&&this._syncTempProducts()}reinitializeCarousels(){Promise.all([customElements.whenDefined("sl-carousel"),customElements.whenDefined("sl-carousel-item")]).then(()=>{setTimeout(()=>{this.shadowRoot.querySelectorAll("sl-carousel").forEach(t=>{t.initializeSlides()})},1e3)})}_updateAccountLinks(){const t=document.querySelectorAll("a[href]");Array.from(t).filter(r=>r.getAttribute("href").includes("/account")||r.getAttribute("href").startsWith("#status")).forEach(r=>{r.hasAttribute("data-ignore-account-link")||(r.getAttribute("href").includes("logout")?r.href="#my-profile":r.href="#my-account",Shopify.designMode&&r.addEventListener("click",()=>{this._openDrawer()}))})}_handleInputElements(){const t=e=>{!e.value&&!e.getAttribute("value")?e.classList.add("input--empty"):e.classList.remove("input--empty")},o=e=>{e.classList.add("input--focus")},r=e=>{e.classList.remove("input--focus")};this.shadowRoot.querySelectorAll("sl-input").forEach(e=>{e.addEventListener("sl-input",()=>t(e)),e.addEventListener("sl-focus",()=>o(e)),e.addEventListener("sl-blur",()=>r(e)),t(e)})}async _handleHashChange(){const t=window.location.hash;if(s.MAP[t]){if(await this._fetchComponents(),s.MAP[t].includes("##")){const[o,r]=s.MAP[t].split("##");this._renderTab(o),setTimeout(()=>{this._renderSubTab(r),this._openDrawer()},100);return}else this.shadowRoot.querySelectorAll("sl-drawer").forEach(o=>{o.open=!1});this._renderTab(),this._openDrawer()}}async _openDrawer(){this.drawer.open||this.drawer.show()}_closeDrawer(){this.drawer.open&&this.drawer.hide()}_fetchComponents(){const t="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.19.1/cdn/components/",r=["tab-group","tab-panel","tab","animation","skeleton","select","input","checkbox","carousel","carousel-item","popup","option","alert"].map(e=>new Promise((n,a)=>{if(customElements.get(`sl-${e}`)){n();return}const c=document.createElement("script");c.type="module",c.src=`${t}${e}/${e}.js`,c.onload=n,c.onerror=a,document.body.appendChild(c)}));return Promise.all(r)}async _addRecentlyViewedProducts(){if(!window.location.pathname.includes("/products/"))return;const{product:o}=i.componentData;if(!o||!(o!=null&&o.id))return;const{id:r}=o;if(i.hasCustomer)try{const e=await i.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD,{prodID:r});if(e.error)throw new Error(e.error);return e}catch(e){console.error(e)}else{if(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS)||"[]").some(n=>n.id===r))return;i.addToStorage({key:s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS,values:[{...o}]})}}_updateRecentlyViewedCollection(){if(!window.location.pathname.includes("/collections/"))return;const{collection:o}=i.componentData;if(!o)return;const{url:r,title:e}=o,n=localStorage.getItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION),c=(JSON.parse(n)||[]).filter(l=>l.url!==r),d=[{url:r,title:e},...c];localStorage.setItem(s.STORAGE_KEYS.RECENTLY_VIEWED_COLLECTION,JSON.stringify(d))}_renderTab(t){Promise.all([(customElements.whenDefined("sl-tab-group"),customElements.whenDefined("sl-tab-panel"),customElements.whenDefined("sl-tab"))]).then(()=>{this.tabGroup.show(t||i.tabId)})}_renderSubTab(t){const o=s.DRAWER_IDS[t];if(!o)return;const r=this.shadowRoot.querySelector(o);r&&(r.open=!0,navigator.userAgent.indexOf("iPhone")>-1&&setTimeout(()=>{this.drawer.classList.add("inner-drawer-open")},150))}async updateContent(t=[]){const o=this.getAttribute("data-section-id"),r=await this._fetchContent(o);t.forEach(e=>{const n=this.shadow.querySelector(e);if(n){const c=r.querySelector("#gw-customer-accounts-template").content.querySelector(e);n.innerHTML=c.innerHTML}})}async _fetchContent(t){const r=await(await fetch(window.location.pathname+`?section_id=${t}`)).text();return new DOMParser().parseFromString(r,"text/html")}async updateFavoriteItemsStorage(t){const{removeIds:o,addIds:r}=t||{};let e=!1;if(r!=null&&r.length&&(i.addToStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:r,storageType:"session"}),e=!0),o!=null&&o.length&&(i.removeFromStorage({key:s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,values:o,storageType:"session"}),e=!0),e){this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED));return}try{const n=await i.request(s.ENDPOINTS.FAVORITES.GET_ALL_IDS,{customerID:i.customerId},"GET");if(n.error)throw new Error(n.error);sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(n.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))}catch(n){console.error("Error initializing wishlist:",n)}}async _checkCustomerStatus(){const t=i.customerToken,{id_sha256:o,email:r,tags:e,id:n}=i.componentData.customer;if(!t&&n)try{const a=await i.request(s.ENDPOINTS.AUTH.GET_TOKEN,{customerEmail:r,encode:o},"POST");if(a.error)throw new Error(a.error);a.token&&(localStorage.setItem(s.STORAGE_KEYS.TOKEN,a.token),localStorage.setItem(s.STORAGE_KEYS.EMAIL,r))}catch(a){console.error("Error checking customer status:",a)}if(e&&!e.includes("gw-customer"))try{const a=await i.request(s.ENDPOINTS.AUTH.CUSTOMER_LOGGED,{});if(a.error)throw new Error(a.error)}catch(a){console.error("Error checking customer status:",a)}}async _saveTempWishlistProducts(){var r;const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(e=>{const{id:n,variantId:a}=e;return{prodID:n,varID:a}})};try{const e=await i.request(s.ENDPOINTS.FAVORITES.ADD_BULK,o);if(e.error)throw new Error(e.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS),(r=e.products)!=null&&r.length&&(sessionStorage.setItem(s.STORAGE_KEYS.WISHLIST_PRODUCT_IDS,JSON.stringify(e.products)),this.dispatchEvent(new CustomEvent(s.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED))),i.dashboard.loadFavoriteItems()}catch(e){console.error("Error saving temp wishlist products:",e)}}async _saveTempCartProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e,variantId:n}=r;return{prodID:e,varID:n}})};try{const r=await i.request(s.ENDPOINTS.CART.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS),i.dashboard.loadSavedCartItems()}catch(r){console.error("Error saving temp cart products:",r)}}async _saveTempRecentlyViewedProducts(){const t=JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS));if(!(t!=null&&t.length))return;const o={products:t.map(r=>{const{id:e}=r;return{prodID:e}})};try{const r=await i.request(s.ENDPOINTS.VIEWED_PRODUCTS.ADD_BULK,o);if(r.error)throw new Error(r.error);localStorage.removeItem(s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS),console.log("Saved temp recently viewed products:",r),i.dashboard.loadRecentlyViewedItems()}catch(r){console.error("Error saving temp recently viewed products:",r)}}async _watchSavedItemsFromCart(){this.addEventListener(s.CUSTOM_EVENTS.SAVED_ITEMS_FROM_CART,async t=>{i.hasCustomer?await this._handleAuthedCartEvent(t):this._handleGuestCartEvent(t)})}async _handleGuestCartEvent(t){const o=t.detail.extra,r=o.handle,e={};try{const n=await fetch(`/products/${r}.js`);if(!n.ok)throw new Error("Product not found");const a=await n.json();e.variant_id=o.variant_id,e.featuredImage=o.featured_image,e.title=o.title,e.variants={},e.variants.nodes=a.variants,e.id=a.id,e.tags=a.tags,e.handle=a.handle;const d=(JSON.parse(localStorage.getItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[]).filter(u=>u.id!==a.id),l=[e,...d];localStorage.setItem(s.STORAGE_KEYS.TEMP_CART_PRODUCTS,JSON.stringify(l)),i.dashboard.loadSavedCartItems()}catch(n){console.error("Error adding product to cart:",n)}}async _handleAuthedCartEvent(t){try{const{productId:o,variantId:r}=t.detail||{};if(!o||!r)return;const e=await i.request(s.ENDPOINTS.CART.ADD,{prodID:o,varID:r});if(e.error)throw new Error(e.error);i.dashboard.loadSavedCartItems()}catch(o){console.error("Error adding product to cart:",o)}}async _syncTempProducts(){const t=[s.STORAGE_KEYS.TEMP_WISHLIST_PRODUCTS,s.STORAGE_KEYS.TEMP_CART_PRODUCTS,s.STORAGE_KEYS.TEMP_RECENTLY_VIEWED_ITEMS],o=t.flatMap(a=>(JSON.parse(localStorage.getItem(a))||[]).filter(Boolean)),r=[...new Map(o.map(a=>[a.id,a])).values()];console.log("Unique products:",r);const n=(await Promise.all(r.map(async({id:a,handle:c})=>{try{const d=await fetch(`/products/${c}.js`);return d.ok?await d.json():null}catch{return null}}))).reduce((a,c)=>(c&&c.available&&(a[c.id]=c),a),{});t.forEach(a=>{const d=(JSON.parse(localStorage.getItem(a))||[]).map(l=>{if(!l)return null;const u=n[l.id];return u?(l.variants.nodes=u.variants,l):null}).filter(Boolean);localStorage.setItem(a,JSON.stringify(d))}),sessionStorage.setItem(s.STORAGE_KEYS.TEMP_PRODUCTS_UPDATED,"true")}});
|
package/dist/malomo-button.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as o,a as s}from"./assets/index-
|
|
1
|
+
import{G as o,a as s}from"./assets/index-DkUQsudo.js";customElements.define("gw-malomo-button",class extends HTMLElement{constructor(){super(),this.trackingPageUrl=this.getAttribute("tracking-page-url"),this.orderId=this.getAttribute("order-id")}connectedCallback(){this._initMalomoButton()}async _initMalomoButton(){var r;const t=await o.request(s.ENDPOINTS.MISC.GET_MALOMO_ORDER,{orderID:this.orderId});if(t.error){console.error(t.error);return}if((r=t.order)!=null&&r.url){const e=this.querySelector("a");e.href=t.order.url}else this.remove()}});
|
package/dist/orders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as c}from"./assets/tab-
|
|
1
|
+
import{G as c}from"./assets/tab-D4kkRiyw.js";import"./assets/index-DkUQsudo.js";customElements.define("gw-customer-accounts-orders",class extends c{constructor(){super()}connectedCallback(){super.connectedCallback()}});
|
package/dist/preferences-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as a,a as o}from"./assets/index-
|
|
1
|
+
import{G as a,a as o}from"./assets/index-DkUQsudo.js";customElements.define("gw-preferences-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form")}connectedCallback(){this._handleFormSubmit()}async _handleFormSubmit(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{this.form.addEventListener("sl-invalid",e=>{e.preventDefault(),this._clearErrorMessages(),this.form.querySelectorAll("sl-input").forEach(r=>{if(r.hasAttribute("data-invalid")){const t=document.createElement("div");t.slot="help-text",t.classList.add("gw-error-message"),t.textContent=r.validationMessage,r.appendChild(t)}})},{capture:!0}),this.form.addEventListener("submit",e=>{e.preventDefault();const r=new FormData(this.form),t=Object.fromEntries(r.entries());this._submitPreferencesForm(t)})})}async _submitPreferencesForm(e){try{this._clearErrorMessages(),this.form.querySelector("[data-loader]").hidden=!1;let r=await a.request(o.ENDPOINTS.CUSTOMER.UPDATE,e);if(r.error)throw new Error(r.error);this.form.closest("sl-drawer").hide(),a.updateAjaxContent(["[data-main-drawer-label]","[data-my-preference-fields]"])}catch(r){this._handleErrors(r)}finally{this.form.querySelector("[data-loader]").hidden=!0}}_clearErrorMessages(){this.form.querySelectorAll(".gw-error-message").forEach(e=>e.remove())}_handleErrors(e){e.message.includes("valid phone number")&&this._displayErrorMessage('[name="phone"]',e.message)}_displayErrorMessage(e,r){let t=e;typeof e=="string"&&(t=this.form.querySelector(e));const s=document.createElement("div");s.slot="help-text",s.classList.add("gw-error-message"),s.textContent=r,t.appendChild(s),t.focus()}});
|
package/dist/profile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./assets/index-
|
|
1
|
+
import{a as t}from"./assets/index-DkUQsudo.js";import{G as c}from"./assets/tab-D4kkRiyw.js";customElements.define("gw-customer-accounts-profile",class extends c{constructor(){super()}connectedCallback(){var e;super.connectedCallback(),(e=this.querySelector("[data-logout-button]"))==null||e.addEventListener("click",function(o){o.preventDefault(),this.querySelector("[data-loader]").hidden=!1,localStorage.removeItem(t.STORAGE_KEYS.TOKEN),localStorage.removeItem(t.STORAGE_KEYS.EMAIL),document.dispatchEvent(new CustomEvent("gw-customer-accounts:logout")),window.location.href="/account/logout"})}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as a,a as d}from"./assets/index-
|
|
1
|
+
import{G as a,a as d}from"./assets/index-DkUQsudo.js";customElements.define("gw-quick-add-to-cart-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.productId=this.getAttribute("product-id")}connectedCallback(){this.form.addEventListener("submit",async e=>{e.preventDefault(),this._handleFormSubmit()}),this.addEventListener("click",e=>{e.target.matches("[data-wishlist-remove]")&&this.closest(".gw-product-card").querySelector("gw-wishlist-button").dispatchEvent(new Event("click")),e.target.matches("[data-saved-from-cart-remove]")&&this._handleRemoveFromSavedItems()})}async _handleFormSubmit(){this.form.querySelector("[data-loader]").hidden=!1;const r={method:"POST",body:new FormData(this.form),headers:{Accept:"application/javascript"}};try{const t=await fetch(routes.cart_add_url,r);if(t.error)throw new Error(t.error);const s=[await t.json()];document.dispatchEvent(new CustomEvent("CART_UPDATED",{detail:{added:s}})),a.notify(`
|
|
2
2
|
<span>Product added to cart</span>
|
|
3
3
|
<a href="/cart" class="gw-notification__link">View</a>
|
|
4
4
|
`)}catch(t){console.error(t)}finally{if(this.form.querySelector("[data-loader]").hidden=!0,!this.closest("[data-favorites-drawer-container]"))return;const t=this.form.querySelector('[name="productId"]').value,o=this.form.querySelector('[name="id"]').value;if(!t||!o)return;const s=new CustomEvent(d.CUSTOM_EVENTS.SAVED_ITEMS_FROM_CART,{detail:{productId:t,variantId:o,target:this}});a.app.dispatchEvent(s)}}async _handleRemoveFromSavedItems(){if(!a.hasCustomer){const r=this.form.querySelector('[name="productId"]').value,o=(JSON.parse(localStorage.getItem(d.STORAGE_KEYS.TEMP_CART_PRODUCTS))||[]).filter(s=>s.id!=r);localStorage.setItem(d.STORAGE_KEYS.TEMP_CART_PRODUCTS,JSON.stringify(o)),a.dashboard.loadSavedCartItems();return}this.form.closest(".gw-product-card").classList.add("gw-product-card--removing");const e={prodID:this.form.querySelector('[name="productId"]').value};try{const r=await a.request(d.ENDPOINTS.CART.REMOVE,e);if(r.error)throw new Error(r.error);await a.dashboard.loadSavedCartItems()}catch(r){console.error(r)}}});
|
package/dist/sign-in.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as
|
|
1
|
+
import{G as u,a as c}from"./assets/index-DkUQsudo.js";customElements.define("gw-customer-accounts-sign-in",class extends HTMLElement{constructor(){super(),this.signInType=this.getAttribute("type"),this.signInBlock=this.querySelector("[data-sign-in-block]"),this.signInType!=="password"&&(this.verifyCodeBlock=this.querySelector("[data-verify-code-block]"),this.tryAnotherEmailButton=this.querySelector("[data-try-another-email]"),this.sendAnotherCodeButton=this.querySelector("[data-send-another-code]"),this.inputtedEmail="",this.inputtedCode="")}connectedCallback(){if(this.signInType==="password"){const t=this.querySelector("[data-sign-in-button]"),n=t.getAttribute("href");t.addEventListener("click",o=>{o.preventDefault();let e=n;e.includes("?")&&(e+="&return_url="+window.location.pathname+"?my-account-open=true"),window.location.href=e})}else this._handleEmailSubmitForm(),this._handleInputCodeGroup(),this.tryAnotherEmailButton.addEventListener("click",()=>{this.signInBlock.removeAttribute("hidden"),this.verifyCodeBlock.setAttribute("hidden",""),this.signInBlock.querySelector("sl-input").value="",this.signInBlock.querySelector("sl-input").focus(),this.inputtedEmail="",this.inputtedCode=""}),this.sendAnotherCodeButton.addEventListener("click",()=>{this._submitEmailForm(this.querySelector("[data-sign-in-form]")),u.notify("Another code has been sent to your email.")})}async _handleEmailSubmitForm(){await Promise.all([customElements.whenDefined("sl-input")]).then(()=>{const t=this.querySelector("[data-sign-in-form]"),n=this.querySelector("[data-email-error]");t.addEventListener("sl-invalid",o=>{o.preventDefault(),n.textContent=o.target.validationMessage,n.hidden=!1,o.target.focus()},{capture:!0}),t.addEventListener("submit",o=>{o.preventDefault(),n.hidden=!0,n.textContent="",this._submitEmailForm(t).then(()=>{const e=this.verifyCodeBlock.querySelector(".code-input");e&&e.focus()})})})}async _submitEmailForm(t){const n=t.querySelector('button[type="submit"]');n.disabled=!0,n.querySelector("[data-loader]").hidden=!1;const o=new FormData(t);this.inputtedEmail=o.get("email");let e="";const r=await this._fetchCaptchaToken();r&&(e=r);try{const s=await this._request({customerEmail:this.inputtedEmail,token:e},c.ENDPOINTS.AUTH.SIGN_IN);if(s.error){console.error(s.error);return}const a=this.querySelector("[data-code-sent-to]");return a&&(a.textContent=this.inputtedEmail),this.signInBlock.setAttribute("hidden",""),this.verifyCodeBlock.removeAttribute("hidden"),s}catch(s){console.error(s),alert("An error occurred. Please try again later.")}finally{n.disabled=!1,n.querySelector("[data-loader]").hidden=!0}}async _submitVerificationCode(){var s,a;const t=this.querySelector(".gw-verify-code__actions"),n=t.querySelectorAll("button, a"),o=t.querySelector("[data-verify-error]"),e=t.querySelector("[data-loader]"),r=this.querySelectorAll("input.code-input");try{r.forEach(d=>{d.disabled=!0}),n.forEach(d=>{d.disabled=!0,d.hidden=!0}),o.hidden=!0,e.hidden=!1;const i=await this._request({customerEmail:this.inputtedEmail,code:this.inputtedCode},c.ENDPOINTS.AUTH.VERIFY_CODE);if(!i.url)throw new Error("Verification failed");localStorage.setItem(c.STORAGE_KEYS.TOKEN,i.token),localStorage.setItem(c.STORAGE_KEYS.EMAIL,this.inputtedEmail);const l=await fetch(i.url);if(l.error)throw new Error(l.error);const p=await(await fetch(window.location.href)).text(),h=new DOMParser().parseFromString(p,"text/html"),m=(a=(s=h.querySelector("#gw-customer-accounts-template").content)==null?void 0:s.querySelector("gw-integrations-loyalty-points"))==null?void 0:a.getAttribute("page-url");document.documentElement.innerHTML=h.documentElement.innerHTML,document.dispatchEvent(new CustomEvent("gw-customer-accounts:login"));const f=sessionStorage.getItem(c.STORAGE_KEYS.REDIRECT_URL);if(f&&(sessionStorage.removeItem(c.STORAGE_KEYS.REDIRECT_URL),window.location.href=f),!m)return;window.location.pathname.includes(m)&&window.location.reload()}catch(i){console.error(i),setTimeout(()=>{r[r.length-1].focus()})}finally{r.forEach(i=>{i.disabled=!1}),n.forEach(i=>{i.disabled=!1,i.hidden=!1}),o.hidden=!1,e.hidden=!0}}async _request(t,n,o="POST"){return await(await fetch(u.baseURL+n,{method:o,body:JSON.stringify(t),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}})).json()}_handleInputCodeGroup(){const t=[...this.querySelectorAll("input.code-input")];t.forEach((n,o)=>{n.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.keyCode===86||(e.keyCode!==8&&(e.keyCode<48||e.keyCode>57)&&e.preventDefault(),e.keyCode===8&&e.target.value===""&&t[Math.max(0,o-1)].focus())}),n.addEventListener("input",e=>{const[r,...s]=e.target.value;e.target.value=r??"";const a=o===t.length-1,i=r!==void 0;i&&!a&&(t[o+1].focus(),t[o+1].value=s.join(""),t[o+1].dispatchEvent(new Event("input"))),i&&a&&t.every(l=>l.value)&&(this.inputtedCode=t.map(l=>l.value).join(""),this._submitVerificationCode())})})}async _fetchCaptchaToken(){const n=await(await fetch(u.baseURL+c.ENDPOINTS.AUTH.GET_CAPTCHA_TOKEN)).json();return n==null?void 0:n.token}});
|
package/dist/wishlist-button.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as s,a}from"./assets/index-
|
|
1
|
+
import{G as s,a}from"./assets/index-DkUQsudo.js";customElements.whenDefined("gw-customer-accounts").then(()=>{class c extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}set variantId(t){this.setAttribute("variant-id",t)}get variantId(){return this.getAttribute("variant-id")}get productId(){return this.getAttribute("product-id")}connectedCallback(){this.renderButton(),this.button=this.shadowRoot.querySelector("button"),this.loader=this.shadowRoot.querySelector("[data-loader]"),this.addEventListener("click",t=>this._handleFavoriteButtonClick(t)),this._activateButton(this._isProductInFavorites()),document.addEventListener("variant:change",({detail:{productId:t,variant:e}})=>{t!==this.productId||!e||(this.variantId=e.id)}),s.app.addEventListener(a.CUSTOM_EVENTS.FAVORITES_STORAGE_UPDATED,()=>{this._activateButton(this._isProductInFavorites())})}log(t){const e="[GW_WISHLIST_BUTTON] Product ID: "+this.productId;console.log(e,t)}renderButton(){if(this.iconEl=this._createIcon("icon"),this.filledIconEl=this._createIcon("filled-icon"),this.hasAttribute("icon-only")){this.shadowRoot.innerHTML=`
|
|
2
2
|
<button class="wishlist-button wishlist-button--icon-only" part="button">
|
|
3
3
|
${this.iconEl}
|
|
4
4
|
${this.filledIconEl}
|
package/package.json
CHANGED
|
@@ -114,9 +114,16 @@ customElements.define(
|
|
|
114
114
|
const formData = new FormData(form);
|
|
115
115
|
this.inputtedEmail = formData.get('email');
|
|
116
116
|
|
|
117
|
+
// Fetch hidden captcha token
|
|
118
|
+
let token = '';
|
|
119
|
+
const captchaToken = await this._fetchCaptchaToken();
|
|
120
|
+
if (captchaToken) {
|
|
121
|
+
token = captchaToken;
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
try {
|
|
118
125
|
const response = await this._request(
|
|
119
|
-
{ customerEmail: this.inputtedEmail },
|
|
126
|
+
{ customerEmail: this.inputtedEmail, token: token },
|
|
120
127
|
GWCA.ENDPOINTS.AUTH.SIGN_IN
|
|
121
128
|
);
|
|
122
129
|
|
|
@@ -327,5 +334,17 @@ customElements.define(
|
|
|
327
334
|
});
|
|
328
335
|
});
|
|
329
336
|
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Fetches the captcha token.
|
|
340
|
+
* @returns {Promise<string>}
|
|
341
|
+
*/
|
|
342
|
+
async _fetchCaptchaToken() {
|
|
343
|
+
const response = await fetch(
|
|
344
|
+
GWUtils.baseURL + GWCA.ENDPOINTS.AUTH.GET_CAPTCHA_TOKEN
|
|
345
|
+
);
|
|
346
|
+
const data = await response.json();
|
|
347
|
+
return data?.token;
|
|
348
|
+
}
|
|
330
349
|
}
|
|
331
350
|
);
|
|
@@ -25,9 +25,11 @@ export const GWCA = Object.freeze({
|
|
|
25
25
|
ENDPOINTS: {
|
|
26
26
|
AUTH: {
|
|
27
27
|
SIGN_IN: '/email-sign',
|
|
28
|
+
SIGN_IN_TEST: '/email-sign-test',
|
|
28
29
|
VERIFY_CODE: '/code-sign',
|
|
29
30
|
GET_TOKEN: '/logged-sign',
|
|
30
31
|
CUSTOMER_LOGGED: '/customer-logged',
|
|
32
|
+
GET_CAPTCHA_TOKEN: '/get-token',
|
|
31
33
|
},
|
|
32
34
|
FAVORITES: {
|
|
33
35
|
GET_ALL_IDS: '/get-all-favorites',
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const i=Object.freeze({MAP:{"#my-account":"dashboard","#my-orders":"orders","#my-profile":"profile","#my-favorites":"dashboard##favorites"},STORAGE_KEYS:{TOKEN:"i-shsgi--u0mihh3co1e3y9sns",EMAIL:"gw-customer-accounts-email",RECENTLY_VIEWED:"gw-recently-viewed",RECENTLY_VIEWED_COLLECTION:"gw-recently-viewed-collection",LOYALTY_POINTS:"gw-loyalty-points",YOTPO_POINTS:"gw-yotpo-points",WISHLIST_PRODUCT_IDS:"gw-wishlist-product-ids",RISE_POINTS:"gw-rise-points",REDIRECT_URL:"gw-customer-accounts-login-redirect",TEMP_WISHLIST_PRODUCTS:"gw-temp-wishlist-products",TEMP_CART_PRODUCTS:"gw-temp-cart-products",TEMP_RECENTLY_VIEWED_ITEMS:"gw-temp-recently-viewed-items",TEMP_PRODUCTS_UPDATED:"gw-temp-products-updated"},ENDPOINTS:{AUTH:{SIGN_IN:"/email-sign",VERIFY_CODE:"/code-sign",GET_TOKEN:"/logged-sign",CUSTOMER_LOGGED:"/customer-logged"},FAVORITES:{GET_ALL_IDS:"/get-all-favorites",GET:"/get-favorites",ADD:"/add-favorite",REMOVE:"/remove-favorite",ADD_BULK:"/add-favorites"},VIEWED_PRODUCTS:{GET:"/get-viewed-products",ADD:"/add-viewed-product",ADD_BULK:"/add-viewed-products"},CART:{GET:"/get-cart-products",ADD:"/add-cart-product",ADD_BULK:"/add-cart-products",REMOVE:"/remove-cart"},ADDRESS:{ADD:"/add-address",EDIT:"/edit-address",REMOVE:"/remove-address"},CUSTOMER:{UPDATE:"/update-customer"},LOYALTY:{GET_LL:"/get-ll-customer",GET_YOTPO_CUSTOMER:"/get-youtpo-customer",GET_RISE_CREDIT:"/get-rise-customer"},MISC:{GET_MALOMO_ORDER:"/get-malomo-order"}},TAGS_TO_HIDE:["accounts:hidden"],TEMPLATE_IDS:{PRODUCT_CARD:"gw-standard-product-card-template",FORM_PRODUCT_CARD:"gw-form-product-card-template"},CUSTOM_EVENTS:{FAVORITES_STORAGE_UPDATED:"gw:favorites-storage-updated",SAVED_ITEMS_FROM_CART:"gw:saved-items-from-cart"},DRAWER_IDS:{favorites:"#Drawer-Favorites"}});class u{constructor(){}get componentData(){const e=document.querySelector("gw-customer-accounts").shadowRoot.querySelector("[data-component-data]");return JSON.parse(e.textContent)}get customerId(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.id}get customerFirstName(){var t,e;return(e=(t=this.componentData)==null?void 0:t.customer)==null?void 0:e.firstName}get customerEmail(){return localStorage.getItem(i.STORAGE_KEYS.EMAIL)}get hasCustomer(){var t,e;return!!((e=(t=this.componentData)==null?void 0:t.customer)!=null&&e.id)}get customerToken(){return localStorage.getItem(i.STORAGE_KEYS.TOKEN)}get baseURL(){return this.componentData.baseUrl}get app(){return document.querySelector("gw-customer-accounts")}get appShadow(){return this.app.shadowRoot}get dashboard(){return this.appShadow.querySelector("gw-customer-accounts-dashboard")}get tabId(){return i.MAP[window.location.hash]||"dashboard"}async request(t,e={},s="POST"){const a=()=>{const o={method:s,mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"}};return s==="POST"&&(o.body=JSON.stringify(e)),o};if(s==="GET"){const o=new URLSearchParams(e);t=`${t}?${o}`}return s==="POST"&&(e.token=this.customerToken,e.email=this.customerEmail,e.customerID=this.customerId),await(await fetch(this.baseURL+t,a())).json()}notify(t,e="success",s=3e3){const a=document.querySelector("gw-customer-accounts"),r=a.shadowRoot.querySelector("[data-notification-alert]"),o=a.shadowRoot.querySelector("[data-notification-message]");o.innerHTML=t,r.open=!0}async updateAjaxContent(t){return await this.app.updateContent(t)}parseVariantId(t){return String(t).split("/").pop()}formatMoney(t){return(t/100).toLocaleString("en-US",{style:"currency",currency:"USD"})}addToStorage({key:t,values:e,storageType:s="local",position:a="start"}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];a==="start"?r.setItem(t,JSON.stringify([...e,...o])):r.setItem(t,JSON.stringify([...o,...e]))}removeFromStorage({key:t,values:e,storageType:s="local",nestedKey:a}){const r=s==="local"?localStorage:sessionStorage,o=JSON.parse(r.getItem(t))||[];if(a){const n=o.map(c=>e.includes(c[a])?null:c);r.setItem(t,JSON.stringify(n.filter(Boolean)))}else{const n=o.filter(c=>!e.includes(c));r.setItem(t,JSON.stringify(n))}}}const g=new u;export{g as G,i as a};
|