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