var u=Object.defineProperty;var p=(r,t,e)=>t in r?u(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var o=(r,t,e)=>(p(r,typeof t!="symbol"?t+"":t,e),e);import{M as d,W as l,A as i,F as m,c as g,w as E,C as S,a as A}from"./bundle-messageHandler.js";import{L as U}from"./bundle-login.js";class _ extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_LOGGED_USER)}async handle(e,s){var a;try{if(!i.isCrossStorePossible())return this.replyError(new Error("Requesting user session in a non-cross-store context"),s);e.storeId&&i.setCurrentStoreId(e.storeId),e.visitorData&&e.deviceId&&m.storeVisitorData(e.visitorData,e.deviceId);const n=i.getCurrentUser();if(!n)return this.reply({cause:"NEW_CART",context:{storedCause:i.getLogoutCauseOnce()}},s,l.messages.NUVEM_CLEAR_AUTH_DATA);if(e.email&&e.email.toLocaleLowerCase()!==n.email.toLocaleLowerCase())return this.reply({cause:"EMAIL_MISMATCH",context:{payloadEmail:e.email,userEmail:n.email}},s,l.messages.NUVEM_NO_SESSION);const{user:h}=await this.api.getUser();return this.reply({user:g(h),storeId:i.getLoggedStore(),sessionExpirationDate:(a=i.getSessionExpirationDate())==null?void 0:a.toISOString()},s)}catch(n){return i.storeLogoutCause(n),this.replyError(n,s,l.messages.NUVEM_CLEAR_AUTH_DATA)}}}class T extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_LOGOUT)}async handle(e,s){i.isAuthenticated()?(await this.api.logout(e),i.clearSession(),i.storeLogoutCause({cause:"User intentionally did logout"}),this.reply({success:!0},s)):this.reply({cause:"NO_SESSION"},s)}}class C extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_REQUEST);o(this,"methodsByResource",{createOrder:e=>this.api.createOrder(e),shouldShowOneTapSurvey:e=>this.api.shouldShowOneTapSurvey(e),sendCES:e=>this.api.sendCES(e),storeInfo:e=>this.api.getStoreInfo(e),deleteAddress:e=>this.api.deleteAddress(e.addressId),setAddressAsMain:e=>this.api.setAddressAsMain(e.addressId),autocompleteCart:e=>this.api.autocompleteCart(e),exchangeToken:e=>this.api.exchangeToken(e),validateEmail:e=>this.api.validateEmail(e.otp),doesStorefrontUserEmailMatch:e=>this.api.doesStorefrontUserEmailMatch(e),initSessionTransfer:()=>this.api.initSessionTransfer()})}async handle(e,s){const a=this.methodsByResource[e.resource];a||this.replyError(new Error("Request not allowed"),s),this.reply(await a(e.body),s)}}var M=Object.defineProperty,w=Object.getOwnPropertyDescriptor,f=(r,t,e,s)=>{for(var a=w(t,e),n=r.length-1,h;n>=0;n--)(h=r[n])&&(a=h(t,e,a)||a);return a&&M(t,e,a),a};class c extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_PAYMENT_INIT)}handle(e,s){return s===S.CHECKOUT_SECURITY_HOST?this.reply({accessToken:i.getAccessToken()},s):this.reply({error:"Invalid origin"},s),Promise.resolve()}}f([E],c.prototype,"handle");class H extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_UPDATE_USER)}async handle(e,s){const a=await this.api.updateUser(e);this.reply(a,s)}}class I extends d{constructor(){super(...arguments);o(this,"messageToHandle",l.messages.NUVEM_ADD_ADDRESS)}async handle(e,s){const a=await this.api.updateAddressForUser(e);this.reply(a,s)}}class y extends A{constructor(){super(...arguments);o(this,"messageHandlers",[new _(this.api),new U(this.api),new T(this.api),new C(this.api),new c(this.api),new H(this.api),new I(this.api)]);o(this,"initialMessage",{message:l.messages.NUVEM_AUTH_DATA_READY,data:{isCrossStoreImpossible:!i.isCrossStorePossible()}})}}(function(){new y().init()})();