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