1import{y as e,j as t}from"./2c1ab0fe.GMbxnz74.js";import{P as i}from"./711bf263.C893LOGN.js";import{af as r,dF as o,y as s,fM as a,mQ as n,fP as d}from"./4c290a1e.C6TDJ9Fn.js";import{c as l}from"./21cc90a2.DAzJmttM.js";import{g as c,h as u}from"./e477f96c.BxtSUGa4.js";class p{canHandle(e){return void 0!==e[this.field]}}class g extends p{constructor(e){super(),this.field="delivery",this.#e=e}#e;async apply(e,t){const i=function(e){const t=e?.find(e=>e.selected);var i,o;if(t)return i=t.address,o=t.oneTimeUse,{address1:i.address1,address2:i.address2,city:i.city,company:i.company,countryCode:r(i.countryCode),firstName:i.firstName,lastName:i.lastName,phone:i.phone,zoneCode:i.provinceCode,postalCode:i.zip,oneTimeUse:o,coordinates:void 0,handle:void 0,streetName:void 0,streetNumber:void 0,neighborhood:void 0,line2:void 0}}(e.addresses);if(i)return this.#e.isVisible("phone",{countryCode:i.countryCode})||(i.phone=""),t.shippingAddress.value=i,{fieldsToResolve:["deliveryNext"]};t.shippingAddress.value=l(t.shippingAddress.value)}}class m extends p{constructor(){super(...arguments),this.field="payment"}async apply(e,t,{delegatedPaymentInstrument:i}){const{billingAddress:r}=t,a=e.methods[0]?.instruments[0];if(!a)return void(i.value=void 0);const n=i.value,d=null!=n&&c(n)===c(a);i.value=a;const l=u(a.billingAddress);l.countryCode&&!o(l.countryCode)&&(l.countryCode=void 0),d||(r.value=l);const p=t.paymentLines.value.find(e=>"direct"===e.method.type);return p&&(p.method.sessionId=void 0),{legacyFiltering:{include:["billingAddress"]},silenceViolations:s(["billingAddress"]),loading:["billingAddress"],fieldsToResolve:[]}}}class h{constructor(e){this.negotiate=e.negotiate,this.proposal=e.proposal,this.observability=e.observability,this.negotiationContext=e.negotiationContext,this.updaters=[new g(e.addressSettings),new m]}async applyCart(e){const t=this.updaters.filter(t=>t.canHandle(e));if(0===t.length)return void this.observability.log("cart_update_no_applicable_updaters","CartUpdateManager: No applicable updaters found for Cart",{cart:e});this.observability.log("cart_update_applying_fields","CartUpdateManager: Applying Cart fields",{fields:t.map(e=>e.field)});const i=[],r=[];for(const s of t){const t=s.field,a=e[t];if(void 0!==a)try{const e=await s.apply(a,this.proposal,this.negotiationContext);e&&(i.push(e),r.push(t))}catch(o){throw this.observability.log("cart_field_update_error","CartUpdateManager: Error updating field",{field:t,error:o instanceof Error?o.message:String(o)}),o}}if(i.length>0){const e=this.mergeNegotiateOptions(i);this.observability.log("cart_update_consolidated_negotiation","CartUpdateManager: Performing consolidated negotiation",{fieldsUpdated:r,mergedSilenceViolations:e.silenceViolations,mergedFieldsToResolve:e.fieldsToResolve});try{await this.negotiate(e),this.observability.log("cart_update_negotiation_complete","CartUpdateManager: Consolidated negotiation complete",{fieldsUpdated:r})}catch(o){for(const e of r)this.observability.log("cart_field_update_error","CartUpdateManager: Error updating field",{field:e,error:o instanceof Error?o.message:String(o)});throw o}}else this.observability.log("cart_update_no_negotiation_needed","CartUpdateManager: All fields updated without negotiation",{fieldsUpdated:t.map(e=>e.field).filter(t=>void 0!==e[t])})}mergeNegotiateOptions(e){const t=new Set,i=new Set,r=new Set,o=new Set,s=new Set;let a=!1,n=!1;for(const d of e){const e=d.legacyFiltering??{silenceViolations:d.silenceViolations};for(const i of e.include??[])t.add(i);for(const t of e.silenceViolations??[])i.add(t);if(d.fieldsToResolve)for(const t of d.fieldsToResolve)r.add(t);if(d.loading)for(const t of d.loading)o.add(t);if(d.silenceViolations)for(const t of d.silenceViolations)s.add(t);d.force&&(a=!0),d.skipStateUpdates&&(n=!0)}return{legacyFiltering:{include:t.size>0?[...t]:void 0,silenceViolations:i.size>0?[...i]:void 0},fieldsToResolve:r.size>0?[...r]:void 0,loading:o.size>0?[...o]:void 0,silenceViolations:s.size>0?[...s]:void 0,force:a||void 0,skipStateUpdates:n||void 0}}}const b=new Set(["microsoft","amazon","google"]),y=new Set([...Object.values(a),...Object.values(n),...Object.values(d)]);class _{#t;#i;#r={defaultLogAttributes:{},defaultMetricAttributes:{}};constructor(e,t){this.#t=e,t&&(this.#r=t)}bridgeInitialized(e="Embed bridge initialized successfully"){this.#o("embed_bridge_initialized",e),this.#s({name:"embed_bridge_initialization",value:1,exportImmediately:!0,attributes:{result:"success"}})}checkoutStarted(e={}){var t;this.#i=void 0===(t=e.hasPaymentInstrument)?void 0:{paymentPrefillState:t?"prefilled":"not_prefilled"},this.#s({name:"embedded_checkout_started",value:1,attributes:this.#i}),this.#a(e)}checkoutCompleted(){this.#s({name:"embedded_checkout_completed",value:1,attributes:this.#i})}readyForComplete(){this.#s({name:"embedded_checkout_ready_for_complete",value:1})}receiptError(e,t){this.#s({name:"embedded_checkout_receipt_error",value:1,attributes:{failure_type:e,failure_code:t,failureType:e,failureCode:t}})}completedEventSkipped(){this.#o("embed_completed_event_skipped","Embed completed event already emitted, skipping")}completedEventEmitted(){this.#o("embed_completed_event_emitted","Emitting embed completed event")}skipEcReady(){this.#o("embed_bridge_skip_ec_ready","Skipping ec.ready handshake â debug skip_ec_ready query param is active")}noTransportDetected(e,t){this.#o("embed_bridge_no_transport_detected",e,t),this.#s({name:"embed_transport_unavailable",value:1,exportImmediately:!0})}unauthenticatedIframe(e){this.#o("embed_bridge_unauthenticated_iframe",e)}readyMessagePortUpgrade(){this.#o("embed_bridge_ready_message_port_upgrade","Upgrading transport to use message port received in ec.ready response")}readyPaymentInstrument(){this.#o("embed_bridge_ready_payment_instrument","Applying UCP payment instrument from ec.ready response")}readyCartUpdate(e){this.#o("embed_bridge_ready_cart_update","Performing cart update from ec.ready response",{fields:e})}handshakeError(e,t){this.#o("embed_bridge_handshake_error","Handshake failed; tearing down embedded checkout",{errorCode:e,errorMessage:t}),this.#s({name:"embedded_checkout_handshake_failed",value:1,exportImmediately:!0,attributes:{errorCode:y.has(e)?e:"other"}})}submitResponseSent(e){this.#o("embed_bridge_submit_response_sent","Sending ec.submit response with order confirmation",{requestId:e})}submitBlocked(e,t){this.#o("embed_bridge_submit_blocked","Checkout submission blocked by buyer-fixable errors",{requestId:e,reason:t})}submitFailed(e,t){this.#o("embed_bridge_submit_failed","Checkout submission failed due to terminal journey status",{requestId:e,reason:t})}submitReceiptFailed(e,t){this.#o("embed_bridge_submit_receipt_failed","Checkout submission failed, sending error response",{requestId:e,failureType:t})}incomingRequestValidationFailed(e){this.#o("embed_bridge_incoming_request_error","Incoming request failed validation",{requestId:e})}incomingRequestError(e,t){this.#o("embed_bridge_incoming_request_error","Error processing incoming request",{requestId:e,error:String(t)})}enqueuedApplyPaymentInstrumentError(e){this.#o("embed_bridge_enqueued_apply_payment_instrument_error","Failed to apply enqueued payment instrument",{error:String(e)})}windowOpenRejected(e,t){this.#o("embed_window_open_rejected","Host rejected window open request",{url:e,errorMessage:t})}windowOpenError(e,t){this.#o("embed_window_open_error","Window open request failed",{url:e,error:t instanceof Error?t.message:String(t)}),this.#n("window.open","unknown")}paymentDelegationCancelled(){this.#o("embed_payment_delegation_cancelled","User cancelled payment delegation")}paymentDelegationTimeout(e,t){this.#o("embed_payment_delegation_timeout","Payment delegation failed",{error:t}),this.#n(e,"timeout")}paymentDelegationError(e,t){this.#o("embed_payment_delegation_error","Payment delegation failed",{error:t}),this.#n(e,"internal_error")}paymentDelegationUnexpectedError(e,t){this.#o("embed_payment_delegation_unexpected_error","Unexpected payment delegation error",{error:t}),this.#n(e,"unknown")}#a({embedder:e,buyerEmail:t}){e&&b.has(e)&&!t&&this.#s({name:"embedded_checkout_buyer_email_prefill_missing",value:1,attributes:{embedder:e}})}#n(e,t){this.#s({name:"embedded_checkout_delegation_failed",value:1,attributes:{delegation:e,reason:t}})}#o(e,t,i){const r={...this.#r.defaultLogAttributes,...i};return this.#t.log(e,t,r)}#s(e){return this.#t.counter({...e,attributes:{...this.#r.defaultMetricAttributes,...e.attributes}})}}class f{get embedderOrigin(){}get embedderHostname(){}#d=e([]);#l=e([]);#c;#u;#p;#g;#m;constructor(e){this.context=e,this.observability=new _(e.observability),this.addressErrors=this.#d,this.paymentErrors=this.#l}unstable_providePreactContext(e){this.#p=e.waitForPendingNegotiations,this.#g=e.waitForSkeletonRemoved,this.context.negotiationContext=e.negotiationContext,this.#m=e.journey;const t=new h({negotiate:t=>e.journey.negotiate(t),proposal:this.context.checkout.proposal.proposed,observability:this.context.observability,negotiationContext:this.context.negotiationContext,addressSettings:this.context.checkout.configuration.addressSettings.nonBillingAddressSettings.value});this.#c=t,this.#u?.()}addressChangeRequest(e){return Promise.resolve(void 0)}addressChangeStart(e){return Promise.resolve(void 0)}paymentMethodChangeStart(){return Promise.resolve(void 0)}submitStart(){return Promise.resolve(void 0)}unstable_setShopPaySubmitPreflight(e){return()=>{}}async windowOpenRequest(e){}beforeunload(){}dialogChange(e){}showToast(e){return!1}requestShopPaySessionRevalidation(){return Promise.resolve(!0)}shopPaySessionRevalidationChange(e){}async applyCart(e){const t=this.#c;if(t)await t.applyCart(e);else{let t;const i=new Promise(e=>{t=e});this.#u=async()=>{this.#u=void 0,await(this.#c?.applyCart(e)),t()},await i}}addAddressError(e){const t=this.#d.value;t.includes(e)||(this.#d.value=[...t,e])}removeAddressError(e){this.#d.value=this.#d.value.filter(t=>t!==e)}clearAddressErrors(){this.#d.value=[]}
1addPaymentError(e){const t=this.#l.value;t.includes(e)||(this.#l.value=[...t,e])}removePaymentError(e){this.#l.value=this.#l.value.filter(t=>t!==e)}clearPaymentErrors(){this.#l.value=[]}waitForPendingNegotiations(){return this.#p?.()}waitForSkeletonRemoved(){return this.#g?.()}hasDelegatedPaymentInstrument(){return void 0!==this.context.negotiationContext?.delegatedPaymentInstrument?.peek()}get journey(){return this.#m}}const v=Object.freeze(Object.defineProperty({__proto__:null,LegacyClient:class extends f{#h;#b=!1;#y;constructor(e){super(e),this.version=e.embed.protocol.version,this.#h=new i({observability:e.observability}),this.observability.bridgeInitialized("Embed bridge initialized with legacy protocol")}async ready(){}async start(){this.#_()}async resumeFromReceipt(){this.#_()}async complete(){}error(e){}cleanup(){this.#h.cleanup(),this.#y?.()}unstable_providePreactContext(){}#_(){this.#y=t(()=>{const e=this.context.checkout.latestReceipt.value;e&&"processed"===e.status&&!e.redirectUrl&&(this.#b?this.observability.completedEventSkipped():(this.#b=!0,this.observability.completedEventEmitted(),this.complete(),this.cleanup()))})}}},Symbol.toStringTag,{value:"Module"}));export{f as B,v as l};
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.