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