1import{w as k,g as w,a as v,l as h}from"./chunk-vendor-other-CPATiX-4.js";import{M as p,f as x,e as S}from"./chunk-vendor-ovee-CfTeiR4R.js";import{a as M}from"./chunk-website-utils-CGzOoRqv.js";import{N as T,$ as E,a3 as R}from"./chunk-vendor-vue-Co4JtY-K.js";const l="fm_at",u="fm_at_expire",m="fm_at_uid",$=new x("AuthTokenModule");class C extends p{constructor(){super(...arguments),this.currentState=T({accessToken:null,expiresAt:null,uid:null})}init(){this.$app.$auth=this,this.client=k({storeDomain:"finallyme-store.myshopify.com",apiVersion:"2025-01",publicAccessToken:"2dc38e8eff497d10b271e584894ccabf"}),this.readFromStorage(),this.$app.$on("storage",e=>{[l,u,m].includes(e.key)&&this.readFromStorage()},{target:window}),this.accessToken&&(!this.isCurrentUidMatching||this.isExpired)&&(this.reset(),localStorage.removeItem("fm_jwt"),sessionStorage.removeItem("fm_survey_id"),sessionStorage.removeItem("fm_survey_step_result"),sessionStorage.removeItem("fm_survey_step"),sessionStorage.removeItem("fm_customer_consents"),sessionStorage.removeItem("fm_is_survey_completed"),sessionStorage.removeItem("fm_survey_current_step"),sessionStorage.removeItem("fm_customer_email"),$.warn("Reset token due to expiration or not matching uid"))}readFromStorage(){this.currentState.accessToken=localStorage.getItem(l),this.currentState.expiresAt=localStorage.getItem(u),this.currentState.uid=localStorage.getItem(m)}get accessToken(){return this.currentState.accessToken}get expiresAt(){return this.currentState.expiresAt}get isExpired(){if(!this.expiresAt)return!0;const e=new Date(this.expiresAt).getTime(),t=Date.now();return e<t}get uid(){return this.currentState.uid}get isCurrentUidMatching(){return this.verifyUid(this.uid)}verifyUid(e){if(!e)return!1;const t=window.customerData.id,r=e.split("/").pop();return t===r}update(e,t,r){localStorage.setItem(l,e),localStorage.setItem(u,t),localStorage.setItem(m,r)}reset(){localStorage.removeItem(l),localStorage.removeItem(u),localStorage.removeItem(m)}async apiLogin(e,t){var i;const r=` 2 mutation SignInWithEmailAndPassword( 3 $email: String!, 4 $password: String!, 5 ) { 6 customerAccessTokenCreate(input: { 7 email: $email, 8 password: $password, 9 }) { 10 customerAccessToken { 11 accessToken 12 expiresAt 13 } 14 customerUserErrors { 15 code 16 message 17 } 18 } 19 } 20 `,{data:s}=await this.client.request(r,{variables:{email:e,password:t}}),{accessToken:o,expiresAt:c}=((i=s==null?void 0:s.customerAccessTokenCreate)==null?void 0:i.customerAccessToken)??{};if(o){const a=await this.apiGetUidFromToken(o);if(a)return this.update(o,c,a),await this.getJwtToken(o),!0}return this.reset(),!1}async apiGetUidFromToken(e){var s;const t=` 21 query Customer($token: String!) { 22 customer(customerAccessToken: $token) { 23 id 24 } 25 } 26 `,{data:r}=await this.client.request(t,{variables:{token:e}});return(s=r==null?void 0:r.customer)==null?void 0:s.id}async getJwtToken(e){var r;const t="https://api.finally.me/api";try{const o=(await M.post(`${t}/auth/token`,{accessToken:e},{suppressToken:!0})).data.access_token;localStorage.setItem("fm_jwt",o)}catch(s){console.error("BÅÄ d podczas pobierania JWT:",((r=s.response)==null?void 0:r.data)||s.message)}}static getName(){return"AuthTokenModule"}}class U extends p{init(){var t;if(!sessionStorage.getItem("returnToTarget"))return;const e=sessionStorage.getItem("returnToTarget");((t=document.querySelector("[data-return-to],return-to"))==null?void 0:t.dataset.returnTo)!==e&&(sessionStorage.removeItem("returnToTarget"),!(!this.isSafeRedirectUrl(e)||!this.isDifferentFromCurrentUrl(e))&&(location.href=e))}isSafeRedirectUrl(e){return!(!e.startsWith("/")||/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(e)||/[?#]/.test(e))}isDifferentFromCurrentUrl(e){const t=window.location.pathname;return e!==t}static getName(){return"HandleReturnToModule"}}w.registerPlugin(v);class q extends p{init(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),this.bind()}async scrollTo(e="",t=!1,r={}){const{ignoreHeader:s=!1,ignoreMargin:o=!0,offset:c=0}=r??{};if(this.target=e,typeof e=="string"&&(this.hash=e!==""?e:window.location.hash),e instanceof Node&&(e=e.href.split("#"),this.hash=e[1]===void 0?"":`#${e[1]}`),this.header=document.querySelector(".header"),this.element=this.hash?document.querySelector(this.hash):!1,this.hash&&this.element){const i=this.element,a=this.header?this.header.getBoundingClientRect().height:0,d=i.getBoundingClientRect(),{clientTop:y}=document.documentElement,{pageYOffset:_}=window,A=o?0:Math.floor(parseFloat(getComputedStyle(i).getPropertyValue("margin-top"))),I=d.top+_-y-(s?0:a)-A-c;await this.scrollY(I,t,{})}}async scrollY(e,t=!1,r={}){const{speed:s=1,ease:o="power2.out"}=r,{innerHeight:c,scrollY:i}=window,a=Math.abs(i-e),d=t?0:(Math.log(a)/Math.log(c)+Math.sqrt(a)/Math.sqrt(c))*s*.5;await w.to(window,{duration:d,scrollTo:e+1,ease:o,onStart:()=>{S(window,"scroll-to:start")},onComplete:()=>{S(window,"scroll-to:complete")}})}bind(){this.$app.$on("load hashchange",()=>{setTimeout(()=>{this.scrollTo("",!1)})},{target:window})}static getName(){return"ScrollToModule"}}const G=[q,U,C];let g;class f{constructor(){this.stores={}}registerStore(e,t){this.stores[e]?console.error(`[OveeStore] Store with name '${e}' was already registered!`):this.stores[e]=t}unregisterStore(e){this.stores[e]&&delete this.stores[e]}
26static getInstance(){return g||(g=new f),g}}function N(n,e){const t=T(h.isFunction(e)?e():h.cloneDeep(e)),r=E(t);return f.getInstance().registerStore(n,t),{state:r,getter:F(r),mutation:b(t)}}function F(n){return e=>R(()=>e(n))}function b(n){return e=>t=>{const r=h.cloneDeep(t);return e(n,r)}}export{N as c,G as m};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.