gw-customer-accounts 1.4.1 → 1.4.2
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/sign-in.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as l,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(){this.signInType==="password"?this._setupPasswordBasedAuth():this._setupEmailBasedAuth()}_setupPasswordBasedAuth(){const t={signIn:this.querySelector("[data-sign-in-form]"),registration:this.querySelector("[data-registeration-form]"),forgotPassword:this.querySelector("[data-forgot-password-form]")},e={signIn:this.querySelectorAll("[data-sign-in-link]"),createAccount:this.querySelectorAll("[data-create-account-link]"),forgotPassword:this.querySelectorAll("[data-forgot-password-link]")};this._setupFormNavigation(e,t),this._setupFormSubmissions(Object.values(t)),this._handleFormVisibility(t)}_handleFormVisibility(t){const r=new URLSearchParams(window.location.search).get("form_id");r&&Object.values(t).forEach(o=>{const
|
|
1
|
+
import{G as l,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(){this.signInType==="password"?this._setupPasswordBasedAuth():this._setupEmailBasedAuth()}_setupPasswordBasedAuth(){const t={signIn:this.querySelector("[data-sign-in-form]"),registration:this.querySelector("[data-registeration-form]"),forgotPassword:this.querySelector("[data-forgot-password-form]")},e={signIn:this.querySelectorAll("[data-sign-in-link]"),createAccount:this.querySelectorAll("[data-create-account-link]"),forgotPassword:this.querySelectorAll("[data-forgot-password-link]")};this._setupFormNavigation(e,t),this._setupFormSubmissions(Object.values(t)),this._handleFormVisibility(t)}_handleFormVisibility(t){const r=new URLSearchParams(window.location.search).get("form_id");r&&Object.values(t).forEach(o=>{const s=o.querySelector(".gw-error-message");r===o.getAttribute("id")?(o&&o.removeAttribute("hidden"),s&&s.removeAttribute("hidden"),r==="recover_customer"&&this._showPasswordResetMessage(o),r==="customer_login"&&this._showLoginErrorMessage(o)):(o&&o.setAttribute("hidden",""),s&&s.setAttribute("hidden",""))})}_showPasswordResetMessage(t){const e=t.querySelector("[data-forgot-password-error-message]");e&&(e.textContent="We've sent you an email to reset your password");const r=t.querySelector("[data-forgot-password-subtext]");r&&r.remove()}_showLoginErrorMessage(t){const e=t.querySelector("[data-login-error-message]");e&&(e.textContent="The email or password you entered is incorrect. Please try again.")}_setupFormNavigation(t,e){const r=s=>{Object.values(e).forEach(n=>{n.setAttribute("hidden","")}),s.removeAttribute("hidden")},o=()=>{const s=new URL(window.location.href);s.searchParams.delete("form_id"),window.history.replaceState({},"",s.toString())};t.createAccount.forEach(s=>{s.addEventListener("click",()=>{r(e.registration),o()})}),t.forgotPassword.forEach(s=>{s.addEventListener("click",()=>{r(e.forgotPassword),o()})}),t.signIn.forEach(s=>{s.addEventListener("click",()=>{r(e.signIn),o()})})}_setupFormSubmissions(t){t.forEach(e=>{const r=new URL(window.location.href);r.searchParams.forEach((n,a)=>{r.searchParams.delete(a)}),r.searchParams.append("my-account-open",!0),r.searchParams.append("form_id",e.getAttribute("id"));const o=e.querySelector('input[name="return_to"]'),s=e.querySelector('input[name="return_url"]');o&&(o.value=r.pathname+r.search),s&&(s.value=r.pathname+r.search),e.addEventListener("submit",n=>{n.preventDefault(),e.querySelectorAll('button[type="submit"]').forEach(a=>{a.disabled=!0;const i=a.querySelector("[data-loader]");i&&(i.hidden=!1)}),Shopify.captcha.protect(e,()=>{e.submit()})})})}_setupEmailBasedAuth(){this._handleEmailSubmitForm(),this._handleInputCodeGroup(),this.tryAnotherEmailButton.addEventListener("click",()=>{this._resetToEmailInput()}),this.sendAnotherCodeButton.addEventListener("click",()=>{this._resendVerificationCode()})}_resetToEmailInput(){this.signInBlock.removeAttribute("hidden"),this.verifyCodeBlock.setAttribute("hidden","");const t=this.signInBlock.querySelector("sl-input");t.value="",t.focus(),this.inputtedEmail="",this.inputtedCode="",this.acceptsMarketing=!1}_resendVerificationCode(){this._submitEmailForm(this.querySelector("[data-sign-in-form]")),l.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]"),e=this.querySelector("[data-email-error]");t.addEventListener("sl-invalid",r=>{r.preventDefault(),e.textContent=r.target.validationMessage,e.hidden=!1,r.target.focus()},{capture:!0}),t.addEventListener("submit",r=>{r.preventDefault(),e.hidden=!0,e.textContent="",this._submitEmailForm(t).then(()=>{const o=this.verifyCodeBlock.querySelector(".code-input");o&&o.focus()})})})}async _submitEmailForm(t){const e=t.querySelector('button[type="submit"]');e.disabled=!0,e.querySelector("[data-loader]").hidden=!1;const r=new FormData(t);this.inputtedEmail=r.get("email"),r.has("accepts_marketing")&&(this.acceptsMarketing=r.get("accepts_marketing"));let o="";const s=await this._fetchCaptchaToken();s&&(o=s);try{const n=await this._request({customerEmail:this.inputtedEmail,token:o},c.ENDPOINTS.AUTH.SIGN_IN);if(n.error){console.error(n.error);return}const a=this.querySelector("[data-code-sent-to]");return a&&(a.textContent=this.inputtedEmail),this.signInBlock.setAttribute("hidden",""),this.verifyCodeBlock.removeAttribute("hidden"),n}catch(n){console.error(n),alert("An error occurred. Please try again later.")}finally{e.disabled=!1,e.querySelector("[data-loader]").hidden=!0}}async _submitVerificationCode(){var n,a;const t=this.querySelector(".gw-verify-code__actions"),e=t.querySelectorAll("button, a"),r=t.querySelector("[data-verify-error]"),o=t.querySelector("[data-loader]"),s=this.querySelectorAll("input.code-input");try{s.forEach(u=>{u.disabled=!0}),e.forEach(u=>{u.disabled=!0,u.hidden=!0}),r.hidden=!0,o.hidden=!1;const i=await this._request({customerEmail:this.inputtedEmail,code:this.inputtedCode,is_marketing:this.acceptsMarketing},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 d=await fetch(i.url);if(d.error)throw new Error(d.error);const f=await(await fetch(window.location.href)).text(),h=new DOMParser().parseFromString(f,"text/html"),m=(a=(n=h.querySelector("#gw-customer-accounts-template").content)==null?void 0:n.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 p=sessionStorage.getItem(c.STORAGE_KEYS.REDIRECT_URL);if(p&&(sessionStorage.removeItem(c.STORAGE_KEYS.REDIRECT_URL),window.location.href=p),!m)return;window.location.pathname.includes(m)&&window.location.reload()}catch(i){console.error(i),setTimeout(()=>{s[s.length-1].focus()})}finally{s.forEach(i=>{i.disabled=!1}),e.forEach(i=>{i.disabled=!1,i.hidden=!1}),r.hidden=!1,o.hidden=!0}}async _request(t,e,r="POST"){return await(await fetch(l.baseURL+e,{method:r,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((e,r)=>{e.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.keyCode===86||(o.keyCode!==8&&(o.keyCode<48||o.keyCode>57)&&o.preventDefault(),o.keyCode===8&&o.target.value===""&&t[Math.max(0,r-1)].focus())}),e.addEventListener("input",o=>{const[s,...n]=o.target.value;o.target.value=s??"";const a=r===t.length-1,i=s!==void 0;i&&!a&&(t[r+1].focus(),t[r+1].value=n.join(""),t[r+1].dispatchEvent(new Event("input"))),i&&a&&t.every(d=>d.value)&&(this.inputtedCode=t.map(d=>d.value).join(""),this._submitVerificationCode())})})}async _fetchCaptchaToken(){const e=await(await fetch(l.baseURL+c.ENDPOINTS.AUTH.GET_CAPTCHA_TOKEN)).json();return e==null?void 0:e.token}});
|
package/package.json
CHANGED
|
@@ -87,6 +87,11 @@ customElements.define(
|
|
|
87
87
|
if (errorMessageContainer) {
|
|
88
88
|
errorMessageContainer.textContent = "We've sent you an email to reset your password";
|
|
89
89
|
};
|
|
90
|
+
|
|
91
|
+
const forgotPasswordSubtext = form.querySelector('[data-forgot-password-subtext]');
|
|
92
|
+
if (forgotPasswordSubtext) {
|
|
93
|
+
forgotPasswordSubtext.remove();
|
|
94
|
+
};
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
_showLoginErrorMessage(form) {
|