PageSourceSearch

https://lovehero.co/cdn/shopifycloud/checkout-web/assets/c1/web-mcp-runtime.CGES2-3O.js

js lovehero.co collected 2026-09-26 06:14:21 UTC 87,471 bytes, 1 lines download raw bytes

1import{c as Ct,j as ze,n as F,a as It,b as Tt}from"./esnext-vendor.B9Da21W6.js";import{c as Et,s as ge,a as ce,b as ve,R as be,d as St,i as M,e as wt,n as Xe,f as Ke,g as kt,h as Dt,j as Lt,C as Pt,V as Q,p as Nt,k as Mt,l as Ot,m as Rt,U as Ut,o as xt,q as qt,r as Ht,t as Ft,F as jt,u as $t,v as Se,w as we,x as Bt,y as Gt,z as Yt,A as Wt,B as Vt,D as zt}from"./addresses-is-address-empty.Bn2lNY_L.js";import{i as Xt}from"./graphql-PaymentSessionMutation.CAXCwUvV.js";import{i as Kt}from"./cvv-cvvBridge.B-VIACTq.js";import{s as Jt}from"./helpers-derivations.Dug6X2_v.js";import{a as x,i as Qt}from"./context-browser.DZZzP-lc.js";class Zt{#e;#t=0;get current(){return this.#e}async during(t,n){this.#e=t,this.#t+=1;try{return await n()}finally{this.#t-=1,this.#t===0&&(this.#e=void 0)}}}function en(e){return Array.from(e.values()).flatMap(t=>{const n=t.read();return n?[n]:[]}).sort((t,n)=>tn(t.key,n.key))}function tn(e,t){return e===t?0:e<t?-1:1}function V(e,t){const n=e??[],i=new Map;for(const[r,{key:s,value:a}]of n.entries()){const d=`$.checkout.declared_fields[${r}]`,c=t.get(s);if(!c?.read())return ie(`${d}.key`,"must identify a declared field available in the current checkout");const l=c.prepare(a);if("requirement"in l)return ie(`${d}.value`,l.requirement);i.set(s,l)}const o=[];for(const[r,s]of t){if(!s.read())continue;const a=i.get(r)??s.prepare(null);if("requirement"in a)return ie("$.checkout.declared_fields",a.requirement);o.push({...a,get changed(){return a.changed},async apply(){return t.get(r)===s&&s.read()?a.apply():!1}})}return o}function ie(e,t){return{error:{code:"rejected",message:`${e}: ${t}. Nothing was applied. Call get_checkout before retrying.`}}}function nn(e){const{email:t,phone:n}=e??{};if(!(!t&&!n))return{...t?{email:t}:{},...n?{phone_number:n}:{}}}function k(e){if(!e)return 0;const t=Ct(e.currencyCode),n=new Intl.NumberFormat("en",{style:"decimal",useGrouping:!1,minimumFractionDigits:t,maximumFractionDigits:t}),[i,o=""]=n.format(e.amount).split(".");return Number(i+o.padEnd(t,"0"))}function on(e,t){if(!e?.lines.length)return;const n=t?new Map(t.map(({id:r},s)=>[r,s])):void 0,i=new Map,o=[];for(const r of e.lines){const{discount:s}=r;if(s.type==="code"||s.type==="discountCodeTrigger"){const a=s.title.toUpperCase();i.has(a)||i.set(a,s.title)}if("allocations"in r){const a=rn(r,n);a.amount>0&&o.push(a)}}return{codes:[...i.values()],applied:o}}function rn(e,t){const{discount:n}=e,i=[];let o=0,r=!1;for(const{target:d}of e.allocations){let c=d.index;if(d.type==="MERCHANDISELINE"&&t&&(c=d.stableId==null?void 0:t.get(d.stableId),c==null)){r=!0;continue}const l=k(d.amount);o+=l,d.type==="MERCHANDISELINE"&&c!=null?i.push({path:`$.line_items[${c}]`,amount:l}):d.type==="DELIVERYLINE"&&i.push({path:"$.totals.shipping",amount:l})}const s=n.type==="code"&&n.codeHidden,a=r?0:k(e.amount);return{title:s?"Discount":n.title,amount:o||a,...n.type==="code"&&!s&&{code:n.title},...n.type!=="code"&&{automatic:!0},...n.allocationMethod==="EACH"&&{method:"each"},...n.allocationMethod==="ACROSS"&&{method:"across"},...i.length>0&&{allocations:i}}}function Z(e,{extendedAddressMode:t}){const n=e.address_country?.toUpperCase()??"",i=t.get(n),o=i===null?sn(n,e):an(n,e,i);return{...Et({...e,street_address:o.address1,extended_address:o.address2}),company:e.company??"",district:void 0,subdistrict:void 0,...o}}function Ae(e,t){const n=e.countryCode??"",i=t?.extendedAddressMode.get(n)??null;return{company:e.company,first_name:e.firstName,last_name:e.lastName,phone_number:e.phone,...i===null?ln(n,e):pn(n,e,i),address_locality:e.city,address_region:e.zoneCode,address_country:e.countryCode,postal_code:e.postalCode}}function Je({street_address:e="",street_name:t,street_number:n=""}){return t?.trim()?{streetName:t,streetNumber:n}:{line:e}}function sn(e,t){const n=Je(t);return{address1:"line"in n?n.line:mn(e,n),address2:t.extended_address??""}}function an(e,t,n){const{packedLine2:i,...o}=dn(e,Je(t)),{neighborhood:r,...s}=cn(e,t,i);return{...o,...s,...n==="dedicated"?r!==void 0&&{district:r,neighborhood:""}:{neighborhood:r}}}function dn(e,t){if("line"in t){const i=ge(e,t.line,!0);if(!i?.streetNumber)return{address1:t.line};const o=ce({countryCode:e,streetName:i.streetName??"",streetNumber:i.streetNumber});return o==null?{address1:t.line}:{address1:o,packedLine2:i.line2}}const n=ce({countryCode:e,...t});return n==null?{address1:tt(t)}:{address1:n,...t}}function cn(e,{extended_address:t="",district:n},i){const o=ve(e,t);if(!o)return{address2:ke(t,i)};const r=ke(o.line2??"",i),s=n??o.neighborhood??"";return{address2:et(e,r,s),line2:r,neighborhood:s}}function ke(e,t){return!t||t===e.trim()?e:nt(e,t)}function ln(e,t){return{street_address:Qe(e,t),extended_address:un(e,t)}}function Qe(e,{address1:t,streetName:n,streetNumber:i}){return t||!(n||i)?t:Ze(e,{streetName:n??"",streetNumber:i??""})}function un(e,{address2:t,line2:n,district:i,neighborhood:o}){const r=i||o;return n==null&&!r?t:et(e,n??"",r??"")}function pn(e,t,n){const i=hn(e,t,n);return{...i?.streetName?{street_name:i.streetName,street_number:i.streetNumber??""}:{street_address:Qe(e,t)},...fn(e,t,n)}}function hn(e,t,n){return n==="dedicated"&&(t.streetName!=null||t.streetNumber!=null)?t:t.address1?.includes(be)?ge(e,t.address1):null}function fn(e,t,n){if(n==="dedicated"&&(t.line2!=null||t.district!=null)){const o=t.district??t.neighborhood;return{extended_address:t.line2,...o!=null&&{district:o}}}const i=t.address2?.includes(be)?ve(e,t.address2):null;return i?{extended_address:i.line2??"",district:i.neighborhood??""}:{extended_address:t.address2||t.line2,...n==="concatenated"&&t.neighborhood!=null&&{district:t.neighborhood}}}function Ze(e,t){return ce({countryCode:e,...t})??tt(t)}function et(e,t,n){return St({countryCode:e,line2:t,neighborhood:n})??nt(t,n)}function mn(e,t){return yn(Ze(e,t))}function tt({streetName:e,streetNumber:t}
1){return[t,e].filter(Boolean).join(" ")}function nt(e,t){return[e,t].filter(Boolean).join(", ")}function yn(e){return e.split(be).join("")}function _n(e){if(!e?.length)return{lineItems:[],itemsDiscountAmount:0,cartLevelDiscountAmount:0};let t=0,n=0;return{lineItems:e.map(o=>{const{itemPrice:r}=o,s=r?{...r,amount:r.amount*o.quantity}:void 0,{lineLevel:a,cartLevel:d}=vn(o.lineAllocations),c=[];n+=d,s&&c.push({type:"subtotal",amount:k(s)}),a!==0&&s&&(t+=a,c.push({type:"items_discount",amount:k({...s,amount:-a})}));const l=s?{...s,amount:s.amount-a}:o.totalPrice;return c.push({type:"total",amount:k(l)}),{id:C(o),...o.parentRelationship?.parent?.stableId?{parent_id:o.parentRelationship.parent.stableId}:{},quantity:o.quantity,item:{id:o.variantId??o.stableId,title:o.title,price:k(r),...o.image?.url?{image_url:o.image.url}:{}},totals:c}}),itemsDiscountAmount:t,cartLevelDiscountAmount:n}}function te(e){return e?.flatMap(t=>(t.lineComponents.length?t.lineComponents:[t]).filter(n=>n.requiresShipping).map(C))??[]}function gn(e){if(e)return e.reduce((t,n)=>{const{itemPrice:i}=n;if(!i)return t;const o=i.amount*n.quantity;return t?{...t,amount:t.amount+o}:{...i,amount:o}},void 0)}function C(e){return e.stableId}function vn(e){let t=0,n=0;for(const i of e)for(const{discountDetails:o,amount:r}of i.allocations)bn(o.discount)?n+=r.amount:t+=r.amount;return{lineLevel:t,cartLevel:n}}function bn(e){return"presentationLevel"in e&&e.presentationLevel==="CART"}function X(e){return e==="SHIPPING"||e==="LOCAL"||M(e)}function An(e,t,n){return!!(e&&!n&&(t.some(i=>!X(i))||t.some(M)&&t.some(i=>i==="SHIPPING"||i==="LOCAL")))}function Cn(e,t,n){return!n||e===t}function ee(e,t){switch(t){case"phone_number":return!!e.phoneRequired;case"instructions":return!!e.acceptsInstructions}}function G(e,t){if(!e?.length||!t?.length)return!1;const n=new Set(t),i=e.filter(o=>o.requiresShipping).map(o=>C(o));return i.length===n.size&&i.every(o=>n.has(o))}const le="pickup";function Y(e){const t=e.methods.find(({handle:i})=>i===e.selectedDeliveryMethodHandle),n=e.proposedLine?t?.methodType??e.proposedLine.deliveryMethodTypes[0]:(t??e.methods[0])?.methodType;if(n)return M(n)?"pickup":"shipping"}function it(e){const t=e.filter(r=>Y(r)==="pickup"),n=t.map(r=>{const s=new Map;for(const a of r.methods){if(!a.pickupLocation)continue;const d=In(a.pickupLocation);(!s.has(d)||a.handle===r.selectedDeliveryMethodHandle)&&s.set(d,a)}return s}),i=n[0];if(!i)return[];const o=[];for(const[r,s]of i){const a=[];for(const[d,c]of t.entries()){const l=n[d].get(r);if(!l)break;a.push({line:c,method:l})}a.length===t.length&&o.push({id:s.handle,selections:a})}return o}function In(e){if(e.type==="PickupPointLocation"&&e.handle)return JSON.stringify([e.type,e.carrierCode||e.carrierName,e.handle]);const{address:t}=e;return JSON.stringify([e.type,e.name??"",t.address1??"",t.address2??"",t.city??"",t.zoneCode??"",t.countryCode??"",t.postalCode?.replace(/\s+/g,"").toUpperCase()??"",t.streetName??"",t.streetNumber??"",t.neighborhood??"",t.district??"",t.subdistrict??"",t.line2??""])}function Tn(e,t){const n=new Map;for(const r of e)n.has(r.id)||n.set(r.id,r);const i=[...n.values()],o=t?i.find(({address:r})=>wt(r,t)):void 0;return{destinations:i,selectedDestinationId:o?.id}}function En(e){const t=wn(e);return t.length?{methods:t}:void 0}function Sn(e){if(e?.status!=="filled"||!e.lines)return;let t=0,n;for(const i of e.lines){if(i.status!=="available")continue;const o=i.selectedDeliveryMethodHandle;if(!o)continue;const r=i.methods.find(s=>s.handle===o);r?.cost&&(t+=r.cost.amount,n??=r.cost.currencyCode)}if(n!=null)return{amount:t,currencyCode:n}}const Ce=Ae;function wn(e){const{deliveryNext:t}=e;if(e.readMode!=="proposed"&&(t?.status!=="filled"&&t?.status!=="partial"||!t.lines))return De(e);const n=(t?.status==="filled"||t?.status==="partial")&&t.lines?t.lines.filter(xn):[],o=(e.readMode==="proposed"?On(n,e.proposedDeliveryLines,e.merchandiseLines):n).filter(d=>(d.proposedLine?d.proposedLine.deliveryMethodTypes.some(Le):d.methods.some(c=>Le(c.methodType)))&&d.targetMerchandiseLines?.some(c=>c.requiresShipping));if(e.readMode==="proposed"&&!o.length)return De(e);const r=t?.status==="partial"?ot(e,o):new Map,s=new Set([...kn(o),...r.keys()]),a=[];for(const d of s){const c=o.filter(p=>Y(p)===d),l=c.map(p=>Mn(p,p.proposedLine?[p.proposedLine]:e.proposedDeliveryLines)),u=[...new Set([...l.flatMap(p=>p.line_item_ids),...r.get(d)??[]])];a.push({id:d,type:d,line_item_ids:u,destinations:[],...Dn(d,c,e),groups:l})}return a}function ot(e,t){const n=new Set(t.flatMap(r=>r.targetMerchandiseLines?.map(C)??[])),i=new Map,o=new Set;for(const r of e.merchandiseLines??[]){if(e.readMode!=="proposed"&&!r.requiresShipping)continue;const s=C(r);if(n.has(s)||o.has(s))continue;o.add(s);const a=new Set((r.lineComponents.length?r.lineComponents:[r]).filter(u=>u.requiresShipping&&!n.has(C(u))).map(C));if(!a.size)continue;const d=e.proposedDeliveryLines?.filter(u=>u.targetMerchandiseLines.some(p=>C(p)===s||a.has(C(p)))).flatMap(u=>u.deliveryMethodTypes),c=d?.length&&d.every(M)?"pickup":"shipping",l=i.get(c)??[];l.push(...e.readMode==="proposed"?a:[s]),i.set(c,l)}return i}function De(e){return[...ot(e,[])].map(([n,i])=>({id:n,type:n,line_item_ids:i,destinations:[],...n==="shipping"?rt(e):{},groups:[]}))}function kn(e){const t=new Set;for(const n of e){const i=Y(n);i&&t.add(i)}return Array.from(t)}function Le(e){return e==="SHIPPING"||e==="LOCAL"||M(e)}function Dn(e,t,n){if(e==="shipping")return rt(n);const i=it(t);if(!i.length)return{};const o=i.find(({selections:r})=>r.every(({line:s,method:a})=>s.selectedDeliveryMethodHandle===a.handle));return{destinations:i.flatMap(({id:r,selections:s})=>{const a=Ln(s[0].method,n.addressContext);return a?[{...a,id:r}]:[]}),...o&&{selected_destination_id:o.id}}}function rt({savedDestinations:e,shippingAddress:t,addressContext:n}){if(e===void 0)return t&&Ke(t)?{destinations:[Pn(t,n)]}:{};const{destinations:i,selectedDestinationId:o}=Tn(e,t);return i.length?{destinations:i.map(({id:r,address:s})=>({id:r,type:"shipping_address",...Ce(s,n)})),...o&&{selected_destination_id:o}}:{}}function Ln(e,t){const{pickupLocation:n}=e;if(n)return{id:e.handle,type:"business_location",name:n.name??"",pickup_location_address:Ce(n.address,t)}}function Pn(e,t){return{...Ce(e,t),id:Nn(e),type:"shipping_address"}}function Nn(e){return["shipping",e.countryCode,e.postalCode].filter(
1Boolean).join("-").replace(/\s+/g,"")}function Mn(e,t){const n=st(e),i=Xe(e),o=e.proposedLine?e.selectedDeliveryMethodHandle:i?.handle,r=o?Rn(e,n,t):void 0,s=Y(e)==="pickup",a=s?[{...i?Pe(i):{totals:[]},id:le,title:"Pickup"}]:e.methods.filter(({methodType:d})=>d==="SHIPPING"||d==="LOCAL").map(Pe);return{id:e.id??"",line_item_ids:n,options:a,...o&&{selected_option_id:s?le:o},...r&&{selected_option_details:r}}}function On(e,t,n){const i=new Map;for(const o of n??[]){i.set(C(o),te([o]).length>0);for(const r of o.lineComponents)i.set(C(r),r.requiresShipping)}return(t??[]).map(o=>{const r=o.targetMerchandiseLines.filter(a=>a.requiresShipping).map(a=>C(a)),s=e.find(a=>o.id!==void 0&&a.id===o.id)??e.find(a=>a.type===o.type&&G(a.targetMerchandiseLines,r));return{...s,status:"available",id:o.id,type:o.type,targetMerchandiseLines:o.targetMerchandiseLines.flatMap(a=>{const d=i.get(C(a));return d===void 0?[]:[{...a,requiresShipping:d}]}),selectedDeliveryMethodHandle:o.deliveryMethodHandle,methods:s?.methods.filter(a=>o.deliveryMethodTypes.includes(a.methodType))??[],proposedLine:o}})}function Rn(e,t,n){const i=Un(e,n,t);if(!i||!e.selectedDeliveryMethodHandle||i.deliveryMethodHandle!==e.selectedDeliveryMethodHandle)return;const o=i.deliveryMethodOptions;if(!o)return;const r=Xe(e),s=r&&!ee(r,"phone_number")?void 0:o.phone,a=r&&!ee(r,"instructions")?void 0:o.instructions;if(!(s===void 0&&a===void 0))return{...s!==void 0&&{phone_number:s},...a!==void 0&&{instructions:a}}}function Un(e,t,n=st(e)){return t?.find(i=>!!e.id&&i.id===e.id)??t?.find(i=>G(i.targetMerchandiseLines,n))}function st(e){return e.targetMerchandiseLines?.filter(t=>t.requiresShipping).map(t=>C(t))??[]}function Pe(e){return{id:e.handle,title:e.title,...e.description&&{description:{plain:e.description}},...e.carrierName&&{carrier:e.carrierName},...e.minDeliveryDateTime&&{earliest_fulfillment_time:e.minDeliveryDateTime},...e.maxDeliveryDateTime&&{latest_fulfillment_time:e.maxDeliveryDateTime},totals:[{type:"fulfillment",display_text:M(e.methodType)?"Pickup":"Shipping",amount:k(e.costAfterDiscounts)}]}}function xn(e){return e.status==="available"}const qn=new Map([["terms-of-service","terms_of_service"],["privacy-policy","privacy_policy"],["refund-policy","refund_policy"],["shipping-policy","shipping_policy"]]);function Hn(e){const t=[];for(const{handle:n,url:i}of e){const o=qn.get(n);o&&t.push({type:o,url:i})}return t}function Fn(e){if(e?.status!=="processed")return;const t=e.orderIdentity.buyerIdentifier,n=kt(e.orderIdentity.id);return{...n?{id:Dt("Order",n)}:{},...t?{label:t}:{},permalink_url:e.confirmationPage.url}}function jn(e,t,n){const i=n?.filter(({instrument:o,usable:r})=>o.selected||r).map(({instrument:o})=>o);return i?.length?{instruments:i}:{instruments:e?[{billing_address:Ae(e,t)}]:[]}}function $n(e){return e.some(({instrument:n,usable:i})=>n.selected&&!i)?[{type:"error",severity:e.some(({usable:n})=>n)?"recoverable":"requires_buyer_input",code:"payment_instrument_unusable",path:"$.payment",content:"The selected card cannot be used for this checkout. Select another instrument by id, or ask the buyer to update payment on the page."}]:[]}const Bn={DELIVERY_NO_DELIVERY_STRATEGY_AVAILABLE_FOR_MERCHANDISE_LINE:"address_undeliverable",DELIVERY_OUT_OF_STOCK_AT_ORIGIN_LOCATION:"out_of_stock",DELIVERY_ZONE_NOT_FOUND:"address_undeliverable",DELIVERY_ZONE_REQUIRED_FOR_COUNTRY:"address_undeliverable",DISCOUNTS_ADDITIONAL_REQUESTED_DISCOUNT_CODE_DISCARDED:"discount_code_not_applied",DISCOUNTS_ALLOCATIONS_MISMATCH:"discount_changed",DISCOUNTS_CURRENTLY_INACTIVE:"discount_code_expired",DISCOUNTS_CUSTOMER_NOT_ELIGIBLE:"discount_code_user_ineligible",DISCOUNTS_CUSTOMER_USAGE_LIMIT_REACHED:"discount_code_user_ineligible",DISCOUNTS_CUSTOM_DISCOUNT_NOT_HONOURED:"discount_code_rejected",DISCOUNTS_DISCOUNTS_NOT_ALLOWED_FOR_B2B:"discount_code_rejected",DISCOUNTS_DISCOUNT_ALREADY_APPLIED:"discount_code_already_applied",DISCOUNTS_DISCOUNT_CODE_APPLICATION_FAILED:"discount_code_rejected",DISCOUNTS_DISCOUNT_CODE_NOT_HONOURED:"discount_code_rejected",DISCOUNTS_DISCOUNT_TITLE_TOO_LONG:"checkout_warning",DISCOUNTS_ELIGIBLE_CUSTOMER_MISSING:"discount_code_user_ineligible",DISCOUNTS_HIGHER_VALUE_DISCOUNT_APPLIED:"discount_code_not_applied",DISCOUNTS_INCOMPATIBLE_PURCHASE_TYPE:"discount_code_combination_disallowed",DISCOUNTS_INCOMPATIBLE_SCRIPT_DISCOUNT:"discount_code_combination_disallowed",DISCOUNTS_INVALID_SIGNATURE:"checkout_warning",DISCOUNTS_MAXIMUM_DISCOUNT_CODE_LIMIT_REACHED:"discount_code_rejected",DISCOUNTS_MIXED_DESTINATION_COUNTRIES:"discount_code_rejected",DISCOUNTS_NOT_FOUND:"discount_code_invalid",DISCOUNTS_NO_ENTITLED_LINE_ITEMS:"discount_code_rejected",DISCOUNTS_NO_ENTITLED_SHIPPING_LINES:"discount_code_rejected",DISCOUNTS_ONLY_EMPTY_TERMS_ACCEPTED:"checkout_warning",DISCOUNTS_PURCHASE_NOT_IN_RANGE:"discount_code_rejected",DISCOUNTS_QUANTITY_NOT_IN_RANGE:"discount_code_rejected",DISCOUNTS_UNSUPPORTED_EXPECTATION:"checkout_warning",DISCOUNTS_USAG
1E_LIMIT_REACHED:"discount_code_rejected",MERCHANDISE_INVENTORY_NOT_FOUND:"out_of_stock",MERCHANDISE_NOT_APPLICABLE:"item_unavailable",MERCHANDISE_NOT_ENOUGH_STOCK_AVAILABLE:"out_of_stock",MERCHANDISE_NOT_FOUND:"item_unavailable",MERCHANDISE_OUT_OF_STOCK:"out_of_stock",MERCHANDISE_OUT_OF_STOCK_IN_CONTEXT:"out_of_stock",MERCHANDISE_PRODUCT_NOT_PUBLISHED:"item_unavailable",MERCHANDISE_PRODUCT_NOT_PUBLISHED_IN_BUYER_LOCATION:"item_unavailable",MERCHANDISE_PRODUCT_VARIANT_NOT_FOUND:"item_unavailable",PAYMENTS_CREDIT_CARD_BASE_EXPIRED:"payment_failed",PAYMENTS_CREDIT_CARD_BASE_GATEWAY_NOT_SUPPORTED:"payment_failed",PAYMENTS_CREDIT_CARD_GENERIC:"payment_failed",PAYMENTS_CREDIT_CARD_YEAR_EXPIRED:"payment_failed",PAYMENTS_PAYMENT_METHOD_INCOMPATIBLE_WITH_PAYMENT_TERMS:"payment_failed",PAYMENTS_PROPOSED_GATEWAY_UNAVAILABLE:"payment_failed"};function Gn(e){return Bn[e]}const Yn=new Set(["AcceptNewTermViolation","RequiredArtifactsUnavailableViolation"]),Wn=new Set(["PendingTermViolation"]),Vn=new Set(["PAYMENTS_UNACCEPTABLE_PAYMENT_AMOUNT"]),zn={type:"error",severity:"requires_buyer_review",code:"buyer_review_required",content:"The buyer must review the order on the checkout page. After the buyer authorizes submission, call complete_checkout again to submit."};function Xn(e){const{receipt:t,isShippingRequired:n,hasShippingAddress:i,deliveryNext:o,skipsShippingAddress:r=Lt(o)}=e,s=Kn(e),a=Qn({receipt:t,isShippingRequired:n,hasShippingAddress:i,skipsShippingAddress:r,hasUnselectableShippingGroup:e.hasUnselectableShippingGroup??!1,requiresBuyerReview:e.requiresBuyerReview??!1,requiresCaptcha:e.requiresCaptcha??!1});return a==="incomplete"&&e.requiresCaptcha&&t?.status!=="action_required"&&s.push({type:"error",severity:"requires_buyer_input",code:"buyer_action_required",content:"The buyer must complete the CAPTCHA on the checkout page. After the buyer completes it, call get_checkout before retrying complete_checkout. Do not attempt to solve the CAPTCHA on the buyer's behalf."}),a==="requires_escalation"&&s.push(zn),{status:a,messages:s}}function Kn(e){const t=[];for(const n of e.violations??[]){if(Yn.has(n.__typename)||Vn.has(n.code)||e.requiresCaptcha&&Pt.has(n.code))continue;const i=n.code.startsWith("DISCOUNTS_"),o=i||Wn.has(n.__typename),r=Gn(n.code)??(o?"checkout_warning":"checkout_error"),s="target"in n?n.target:void 0,a=i?"$.discounts.codes":s;t.push({...o?{type:"warning"}:{type:"error",severity:"recoverable"},code:r,content:Jn(n,r,e.i18n),...a?{path:a}:{}})}return e.receipt?.status==="action_required"&&t.push({type:"error",severity:"requires_buyer_input",code:"buyer_action_required",content:"Payment requires buyer action. Ask the buyer to complete the payment challenge on the checkout page, then call get_checkout. Do not resubmit checkout."}),t}function Jn(e,t,n){if(e.localizedMessage)return e.localizedMessage;switch(t){case"address_undeliverable":return n.translate("shipping_errors.shipping_method_not_available_generic.one");case"checkout_error":case"checkout_warning":case"discount_changed":case"discount_code_already_applied":case"discount_code_combination_disallowed":case"discount_code_expired":case"discount_code_invalid":case"discount_code_not_applied":case"discount_code_rejected":case"discount_code_user_ineligible":return n.translate("notice_banner.generic_processing_error.title");case"item_unavailable":case"out_of_stock":return n.translate("ucp.standard_errors.item_unavailable");case"payment_failed":return n.translate("payment_errors.generic_error")}}function Qn({receipt:e,isShippingRequired:t,hasShippingAddress:n,skipsShippingAddress:i,hasUnselectableShippingGroup:o,requiresBuyerReview:r,requiresCaptcha:s}){const a=e?.status;return a==="processed"?"completed":a==="processing"||a==="processing_remote_checkouts"||a==="polling_for_order"?"complete_in_progress":a==="action_required"||s?"incomplete":r?"requires_escalation":t&&!n&&!i||t&&o?"incomplete":"ready_for_complete"}function Zn({subtotal:e,itemsDiscountAmount:t,cartLevelDiscountAmount:n,discountLines:i,fulfillmentTotal:o,tax:r,duty:s,dutiesIncluded:a,runningTotal:d}){const c=[];return e!=null&&(c.push({type:"subtotal",display_text:"Subtotal",amount:k(e)}),c.push(...ei({currencyCode:e.currencyCode,discountLines:i,itemsDiscountAmount:t,cartLevelDiscountAmount:n}))),o!=null&&c.push({type:"fulfillment",display_text:"Shipping",amount:k(o)}),s!=null&&!a&&c.push({type:"duty",display_text:"Duties",amount:k(s)}),r!=null&&c.push({type:"tax",display_text:"Taxes",amount:k(r)}),d!=null&&c.push({type:"total",display_text:"Total",amount:k(d)}),c}function ei({currencyCode:e,discountLines:t,itemsDiscountAmount:n,cartLevelDiscountAmount:i}){let o=i;for(const s of t?.lines??[])if(Xt(s))for(const a of s.allocations)a.target.type==="DELIVERYLINE"&&(o+=a.target.amount.amount);const r=[];return n>0&&r.push({type:"items_discount",display_text:"Discounts",amount:k({amount:-n,currencyCode:e})}),o>0&&r.push({type:"discount",display_text:"Discount",amount:k({amount:-o,currencyCode:e})}),r}function ti(e){const t=e.merchandiseLines?.lines;if(!t||!oi(t)||e.runningTotal==null)return;const n=e.readMode==="proposed"&&t.length===0?{...e.runningTotal,amount:0}:gn(t)??e.subtotal;if(n==null)return;const{lineItems:i,itemsDiscountAmount:o,cartLevelDiscountAmount:r}=_n(t),s=Sn(e.deliveryNext),a=e.receipt?.status==="processed"&&e.receipt.isRedacted?void 0:nn(e.contactInfo),d=on(e.discountLines,e.readMode==="proposed"?i:void 0),c=En({readMode:e.readMode,deliveryNext:e.deliveryNext,shippingAddress:e.shippingAddress,merchandiseLines:t,savedDestinations:e.savedDestinations,addressContext:e.addressContext,proposedDeliveryLines:e.proposedDeliveryLines}),{status:l,messages:u}=Xn({i18n:e.i18n,requiresBuyerReview:e.buyerReviewUrl!=null,requiresCaptcha:e.requiresCaptcha,violations:e.violations,receipt:e.receipt,isShippingRequired:e.readMode==="proposed"?te(t).length>0:e.isShippingRequired,hasShippingAddress:e.readMode==="proposed"?Ke(e.shippingAddress):e.shippingAddress!=null,deliveryNext:e.deliveryNext,skipsShippingAddress:e.readMode==="proposed"?ii(c,t):void 0,hasUnselectableShippingGroup:ni(c,t,e.readMode)}),p=Fn(e.receipt),h=jn(e.billingAddress,e.addressContext,e.savedCards),m=$n(e.savedCards??[]),v=[...u,...m];return{...e.id?{id:e.id}:{},...e.continueUrl?{continue_url:e.continueUrl}:{},currency:e.runningTotal.currencyCode,status:l==="ready_for_complete"&&m.length?"incomplete":l,...l==="requires_escalation"&&e.buyerReviewUrl?{continue_url:e.buyerReviewUrl}:{},links:Hn(e.merchantPolicies),line_items:i,totals:Zn({subtotal:n,itemsDiscountAmount:o,cartLevelDiscountAmount:r,discountLines:e.discountLines,fulfillmentTotal:s,tax:e.tax,duty:e.duty,dutiesIncluded:e.dutiesIncluded,runningTotal:e.runningTotal}),...a&&{buyer:a},...d&&{discounts:d},...c&&{fulfillment:c},payment:h,...v.length?{messages:v}:{},...p&&{order:p}}}function ni(e,t,n){const i=new Set(e?.methods.flatMap(o=>o.type==="pickup"?o.line_item_ids:(o.groups??[]).filter(({options:r})=>!!r?.length).flatMap(r=>r.line_item_ids)));return t.some(o=>{if(n!=="proposed"&&!o.requiresShipping)return!1;const r=te([o]);return r.length>0&&!i.has(C(o))&&!r.every(s=>i.has(s))})}function ii(e,t){const n=new Set(e?.methods.filter(i=>i.type==="pickup").flatMap(i=>(i.groups??[]).filter(o=>!!o.selected_option_id).flatMap(o=>o.line_item_ids))??[]);return t.every(i=>n.has(C(i))||te([i]).every(o=>n.has(o)))}function oi(e){return e.every(t=>t.itemPrice!=null&&t.title!=null)}function ri({checkout:e,i18n:t,shop:n,router:i,readMode:o="negotiated",savedCards:r,declaredFields:s=new Map,paymentInstrument:a}){const d=ti({...ai(e,t,n,o,i),savedCards:e.isPaymentRequired.value?r:void 0});if(!d)return;const c=en(s),l=d.payment.instruments[0],u={...d,...a?{payment:{instruments:[si(a,e,l&&"billing_address"in l?l.billing_address:{})]}}:{},...c.length>0?{declared_fields:c}:{}},p=e.proposal.proposed.locationAddress.value;return u.fulfillment?.methods.length!==1||u.fulfillment.methods[0].type!=="pickup"||!p?.countryCode||!p.postalCode||!p.coordinates?u:{...u,context:{address_country:p.countryCode,...p.zoneCode&&{address_regi
1on:p.zoneCode},postal_code:p.postalCode}}}function si(e,t,n){const i=t.proposal.proposed.paymentLines.value[0]?.method.type;return{id:e.id,handler_id:e.handler_id,type:e.type,...e.credential?{credential:{type:e.credential.type}}:{},selected:e.handler_id==="shopify.card"?i==="direct":i==="shopWallet",billing_address:n}}function ai(e,t,n,i,o){const{proposed:r,negotiated:s}=e.proposal,a=e.addressManager.shipping.value,d=e.identity.current.value==="shopPay"?a:void 0,c=d?[...d.addresses.value,...d.immutableAddresses.value]:void 0,l=s.fields.shippingAddress.value,u=o?.currentUrl.value,p=r.captcha.value;return{i18n:t,readMode:i,requiresCaptcha:!!(p?.provider==="hcaptcha"&&p.sitekey&&(!p.token||p.violationCode)),buyerReviewUrl:u?.normalizedPath==="/review"?u.href:void 0,id:s.fields.ucp.value?.id,continueUrl:s.fields.ucp.value?.continueUrl,merchantPolicies:n.merchantPolicies,merchandiseLines:i==="proposed"?{lines:r.merchandiseLines.value}:s.fields.merchandiseLines.value,subtotal:s.fields.subtotal.value,discountLines:i==="proposed"?{lines:r.discountLines.value}:s.fields.discountLines.value,tax:e.proposal.facts.tax??li(s.fields.taxes.value),duty:e.proposal.facts.duty??ui(s.fields.duties.value),dutiesIncluded:!!s.fields.dutiesIncluded.value||!!e.proposal.facts.dutiesIncluded,runningTotal:s.fields.runningTotal.value,contactInfo:i==="proposed"?{email:r.email.value,phone:r.phone.value}:s.fields.contactInfo.value,deliveryNext:s.fields.deliveryNext.value,shippingAddress:i==="proposed"?r.shippingAddress.value:l,billingAddress:e.identity.current.value==="shopPay"?void 0:di(e,n,i),addressContext:e.address,savedDestinations:c,proposedDeliveryLines:r.deliveryLines.value.map(h=>h.value),isShippingRequired:!!s.fields.isShippingRequired.value,violations:s.fields.allViolations.value,receipt:e.latestReceipt.value}}function di(e,t,n){const i=e.latestReceipt.value;if(i?.status==="processed")return i.purchaseOrder.billingAddress;if(!(i?.status==="processing"||i?.status==="processing_remote_checkouts"||i?.status==="polling_for_order"))return n==="proposed"?ci(e,t):e.proposal.negotiated.fields.billingAddress.value}function ci(e,t){const{proposed:n,negotiated:i,facts:o}=e.proposal,r=n.paymentLines.value;for(const{method:c}of r)if(c.type===Q.CreditCard||c.type===Q.PayPal)return c.billingAddress;const s=n.billingAddress.value,a=!s.address1&&o.billingAddress?o.billingAddress:s;if(n.billingAddressOption.value!=="shipping"||!i.fields.isShippingRequired.value||!Nt(r))return a;const d=r[0]?.method;if(d?.type==="wallet"){const c=i.fields.runningTotal.value,l=c&&c.amount<=0,u=Mt(i.fields.merchandiseLines.value?.lines).some(h=>!!h.sellingPlan?.subscriptionDetails);if((!l||u||i.fields.deferredTotal.value?.amount.amount)&&(d.name==="GOOGLE_PAY"||d.name==="APPLE_PAY"||d.name==="PAYPAL_EXPRESS"&&Ot({checkout:e,shop:t,paymentMethods:i.fields.paymentMethods.value})))return a}return o.delivery?.[0]?.deliveryAddress??n.shippingAddress.value}function li(e){return e?.status==="available_total"?e.totalTax:void 0}function ui(e){return e?.status==="available_total"?e.totalDuty:void 0}const Ne="store_credit",pi=1e4;function hi(e){const t=(i,o)=>{if(i.hasGiftCard.value)return"cannot change while the cart contains a gift card";if(i.hasFixedSellingPlan.value)return"cannot change while the cart contains a fixed-date subscription";if(i.settling.value)return"is still updating from a previous change; retry shortly";if(o&&i.paymentDue.value?.amount===0&&!i.applied.value)return"cannot be applied when nothing is left to pay"},n=i=>{if(!i.settling.peek())return Promise.resolve();let o=()=>{},r;return new Promise(s=>{r=setTimeout(s,pi),o=ze(()=>{i.settling.value||s()})}).then(()=>{clearTimeout(r),o()})};return{key:Ne,read(){const i=e();if(i?.available.value)return{key:Ne,purpose:"dev.shopify.shopping.declared_fields.generic",title:"Store credit",description:"Apply the buyer's available store credit balance to this checkout. Send true to apply and false to remove; omitting the field or sending null keeps the current choice. Removing it also stops store credit from covering subscription renewals.",value_schema:{type:"boolean"},value:i.redeeming.value,required:!1}},prepare(i){if(i!==null&&typeof i!="boolean")return{requirement:"must be a boolean or null"};const o=i??void 0,r=e();if(!r)return{requirement:"is no longer offered on this checkout"};if(o!==void 0&&o!==r.redeeming.value){const s=t(r,o);if(s)return{requirement:s}}return{phase:"negotiate",get changed(){if(o===void 0)return!1;const s=e();return s?o!==s.redeeming.value?!0:s.settling.value:!1},async apply(){if(o===void 0)return!1;const s=e();return!s||(await n(s),e()!==s||!s.available.value||t(s,o)!==void 0)?!1:(await s.setRedeeming(o),s.applied.peek()===o)}}}}}const Me="tax_number",fi=["TAX_CREDENTIAL_BR","SHIPPING_CREDENTIAL_BR","TAX_CREDENTIAL_CL","SHIPPING_CREDENTIAL_CL","SHIPPING_CREDENTIAL_CN","TAX_CREDENTIAL_CO","SHIPPING_CREDENTIAL_CO","TAX_CREDENTIAL_CR","SHIPPING_CREDENTIAL_CR","TAX_CREDENTIAL_EC","SHIPPING_CREDENTIAL_EC","TAX_CREDENTIAL_ES","SHIPPING_CREDENTIAL_ES","TAX_CREDENTIAL_GT","SHIPPING_CREDENTIAL_GT","TAX_CREDENTIAL_ID","SHIPPING_CREDENTIAL_ID","TAX_CREDENTIAL_IT","SHIPPING_CREDENTIAL_KR","TAX_CREDENTIAL_MX","SHIPPING_CREDENTIAL_MX","TAX_CREDENTIAL_MY","SHIPPING_CREDENTIAL_MY","TAX_CREDENTIAL_PE","SHIPPING_CREDENTIAL_PE","TAX_CREDENTIAL_PT","SHIPPING_CREDENTIAL_PT","TAX_CREDENTIAL_PY","SHIPPING_CREDENTIAL_PY","TAX_CREDENTIAL_TR","SHIPPING_CREDENTIAL_TR","SHIPPING_CREDENTIAL_TW"];function mi(e){const t={key:Me,read(){const n=Oe(e);if(!n)return;const{title:i,value:o,required:r}=n.fields;return{key:Me,purpose:"dev.shopify.shopping.declared_fields.generic",title:i.value,description:`Enter the buyer's ${i.value} tax number for this checkout.`,value_schema:{type:"string"},value:o.value||null,required:r.value??!1}}
1,prepare(n){return n!==null&&typeof n!="string"?{requirement:"must be a string or null"}:{phase:"stage",get changed(){return n!==t.read()?.value},negotiation:{include:["localizationExtensions"],loading:[],fieldsToResolve:["localizationExtensions"]},async apply(){const i=Oe(e);if(!i)return!1;const{value:o}=i.fields;return o.value=n??"",!0}}}};return t}function Oe(e){const n=e.proposal.proposed.localizationExtensions.value.flatMap(i=>fi.some(r=>r===i.fields.key.value)?[i]:[]);return n.length===1?n[0]:void 0}function Ie(e,t){const n=new Map(t.flatMap(({targetMerchandiseLines:o})=>o.map(r=>[r.stableId,r]))),i=new Set;for(const o of e){const r=(o.lineComponents?.length?o.lineComponents:[o]).filter(s=>s.requiresShipping??n.get(s.stableId)?.requiresShipping);for(const{stableId:s}of r)i.add(s);r.length&&o.lineComponents?.length&&i.add(o.stableId)}return i}function ue(e,t){return[...new Set(e.filter(({targetMerchandiseLines:n})=>n.some(({stableId:i})=>t.has(i))).flatMap(({deliveryMethodTypes:n})=>n).filter(n=>n!=="NONE"))]}function yi(e,{proposed:t}){return{getAvailableMethodTypes:()=>e.getAvailableMethodTypes().filter(n=>!n.includes("PICKUP_POINT")),setDesiredMethod(n,i){const o=e.getSelectedMethodTypes();e.markBuyerSelection();const r=t.deliveryLines.value.map(a=>a.value),s=Ie(t.merchandiseLines.value,r);if(!_i(o,n)){e.applyMethodChange(n,o,i);return}F(()=>{for(const a of t.deliveryLines.value){const d=a.value;d.targetMerchandiseLines.some(({stableId:c})=>s.has(c))&&(d.deliveryMethodTypes.length!==n.length||d.deliveryMethodTypes.some(c=>!n.includes(c)))&&(a.value={...d,deliveryMethodTypes:n})}if(e.reconcileSameMethod(n),i){if(i!==t.locationAddress.value)for(const a of t.deliveryLines.value)a.value={...a.value,deliveryMethodHandle:void 0};t.locationAddress.value=i}})}}}function _i(e,t){return e.length>0&&e.every(n=>n==="SHIPPING"||n==="LOCAL"?t.includes("SHIPPING")||t.includes("LOCAL"):t.includes(n))}function gi(e,t=[]){const n={};for(const i of t)i.name&&(n[i.name]??=[]).push(i);return{version:"2026-08-25",status:e,services:{"dev.ucp.shopping":[{version:"2026-08-25",transport:"webmcp"}]},capabilities:{"dev.ucp.shopping.checkout":[{version:"2026-08-25",spec:"https://ucp.dev/2026-08-25/specification/shopping/checkout/",schema:"https://ucp.dev/2026-08-25/schemas/shopping/checkout.json"}],"dev.ucp.shopping.fulfillment":[{version:"2026-08-25",spec:"https://ucp.dev/2026-08-25/specification/shopping/extensions/fulfillment/",schema:"https://ucp.dev/2026-08-25/schemas/shopping/fulfillment.json",extends:["dev.ucp.shopping.checkout"],requires:{protocol:{min:"2026-08-25"}}}],"dev.ucp.shopping.discount":[{version:"2026-08-25",extends:"dev.ucp.shopping.checkout",spec:"https://ucp.dev/2026-08-25/specification/discount",schema:"https://ucp.dev/2026-08-25/schemas/shopping/discount.json"}],"dev.shopify.shopping.declared_fields":[{version:"2026-09-04",extends:"dev.ucp.shopping.checkout",spec:"https://shopify.dev/ucp/specification/declared-fields",schema:"https://shopify.dev/ucp/schemas/2026-09-04/declared_fields.json",requires:{protocol:{min:"2026-04-08"}}}]},payment_handlers:n}}function W(e,t){return{...e,ucp:gi("error"in e?"error":"success",t.proposal.negotiated.fields.ucp.value?.paymentHandlers)}}function vi({checkout:e,shopPay:t}){const n=Jt({identity:e.identity,shopPay:t,negotiatedFields:e.proposal.negotiated.fields},{isApplePayAvailable:t.user.isApplePayAvailable}),i=e.proposal.negotiated.fields.paymentMethods,o=t.session.isInstallmentsSelected,r=e.installments.paymentMethodMustSupportInterestBearingLoans;return()=>{if(e.identity.current.value!=="shopPay"||t.session.isLoading.value)return;const s=t.user.paymentMethods.value.filter(Rt).filter(({id:l})=>l!==Ut).sort(xt),a=qt(s,n.value),d=t.session.selectedPaymentMethod.value,c=e.proposal.proposed.paymentLines.value.some(({method:l})=>l.type==="wallet"&&l.name==="SHOP_PAY");return s.map(l=>{const u=l.paymentAttributes;return{instrument:{id:l.id,type:"card",selected:c&&d?.paymentMethod==="CREDIT_CARD"&&d.id===l.id,display:{brand:u.brand,last_digits:u.lastDigits}},usable:!u.expired&&u.verified&&a.includes(l)&&!Kt(u,i,o,r)}})}}function Re(e){return e?.replace(/[\s-]/g,"").toUpperCase()}function bi(e,t){return!!e?.coordinates&&e?.countryCode===t.countryCode&&(!t.zoneCode||e.zoneCode===t.zoneCode)&&Re(e.postalCode)===Re(t.postalCode)}function oe(e,{checkout:t},n){const i=e.fulfillmentMethods.methods;if(i.length>1)return N("At most one fulfillment method is supported.");const o=i[0];if(o?.id!==void 0&&o.id!==o.type)return N("Method id must match its shipping or pickup type; omit id when requesting a new method.");const{proposed:r,negotiated:s}=t.proposal,a=r.deliveryLines.value.map(f=>f.value),d=Ie(r.merchandiseLines.value,a),c=ue(a,d);if(c.some(M)&&c.some(re)){const f=s.fields.deliveryNext.value,A=f?.status==="filled"||f?.status==="partial"?f.lines.filter(g=>g.status==="available"):[],L=a.map(g=>{const I=(A.find(({id:w})=>!!g.id&&w===g.id)??A.find(w=>G(w.targetMerchandiseLines,g.targetMerchandiseLines.filter(O=>O.requiresShipping).map(C))))?.methods.find(({handle:w,methodType:O})=>w===g.deliveryMethodHandle&&g.deliveryMethodTypes.includes(O))?.methodType??(g.deliveryMethodHandle?void 0:g.deliveryMethodTypes[0]);return I?{...g,deliveryMethodTypes:[I]}:g}),E=ue(L,d);if(E.some(M)&&E.some(re))return N("Updates to checkouts with both shipping and pickup are not supported. Ask the buyer to continue in checkout.")}if(!i.length&&!e.context)return;const l=o?.type??(c.length&&c.every(M)?"pickup":void 0),u=!!(e.context&&!pe(r.locationAddress.value,e.context));if(u&&l!=="pickup")return N("Changing context locality requires a pickup method.");if(!o&&l!=="pickup")return;const p=f=>l==="pickup"?M(f):re(f);if(o&&(o.selected_destination_id!==void 0||o.groups.length))return u||c.length&&!c.some(p)?N("Change the method/search origin first, then select a destination or option returned by that update."):void 0;if(l==="pickup"&&c.length&&c.every(f=>f==="PICKUP_POINT"))return u?N("Pickup-point locality discovery is not supported. Select an existing destination instead."):void 0;if(!d.size)return N("This checkout has no physical items to fulfill.");if(l==="pickup"&&e.context){const f=r.shippingAddress.value?.countryCode||r.locationAddress.value?.countryCode;if(!f)return N("Pickup search requires an established checkout country. Ask the buyer to choose a country in checkout.");if(e.context.address_country!==f)return N("Pickup search must remain in the checkout country.")}if(!n&&!u&&c.every(p)&&c.length)return;const h=!c.length||!c.every(p);if(!n&&h)return N("The delivery selector is not ready.");const m=n?n.getAvailableMethodTypes().find(f=>l==="pickup"?f.includes("PICK_UP"):f.some(p)):c;if(!m)return N(`The checkout does not offer ${l}.`);const v=s.fields;
1return(h||u)&&(v.mustSelectProvidedShippingRate.value||v.mustSelectProvidedAddress.value||v.canUpdateDeliveryAddress.value===!1)?N("The checkout locks its delivery method or address."):{methodTypes:m,needsLocalityLookup:u,changesMode:h}}function re(e){return e==="SHIPPING"||e==="LOCAL"}function pe(e,t){return bi(e,{countryCode:t.address_country,zoneCode:t.address_region,postalCode:t.postal_code})}function N(e){return{error:{code:"rejected",message:`fulfillment: ${e} Nothing was applied. Call get_checkout before retrying.`}}}const K="Unable to confirm the checkout update. Call get_checkout to review the checkout and its messages. Do not retry if the requested change is already present. Otherwise, build a complete replacement from the latest checkout, change only the requested values, and resend all other buyer, fulfillment, discount-code, and declared-field values to retain them. Do not attempt to update the checkout by interacting with the page.",Ue="Nothing was applied. Group and option ids come from the latest get_checkout and change when the destination or fulfillment method changes. Use ids from the latest get_checkout. If this request also changes the destination, send it without groups, then choose an option from the next get_checkout. Do not attempt to update the checkout by interacting with the page.",H={status:"written"};function Ai(e){return e.paymentLines.value.some(t=>t.method.type===Q.CreditCard||t.method.type===Q.PayPal||Ci(t))}function Ci(e){if(e.method.type!=="wallet")return!1;switch(e.method.name){case"APPLE_PAY":return Wt(e);case"GOOGLE_PAY":return Yt(e);case"PAYPAL_EXPRESS":return Gt(e);default:return!1}}const Ii=({buyer:e},{checkout:t,shopPay:n})=>{const i=Qt({identity:t.identity,proposal:t.proposal,shopPay:n});if(i&&t.identity.current.value==="shopPay")return;const{proposed:o}=t.proposal;return{status:"ready",negotiation:{include:["contactInfo"],loading:["contactInfo"],fieldsToResolve:["contactInfo"]},async apply(){return i||(o.email.value=e.email),o.phone.value=e.phone_number,H}}},at=({shippingAddress:e},t)=>{if("saved_address_id"in e)return Ei(e.saved_address_id,t);const{checkout:n,observability:i,clearShippingAddressErrors:o}=t,r=n.addressManager.shipping.value;if(r.applyAddressChangeBlockReason("ucp").value)return;const a=ut(e.address_country,"fulfillment.methods[0].destinations[0].address_country",t.shop);if(a)return a;const d=Z(e,n.address);return{status:"ready",negotiation:{include:["shippingAddress","deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["shippingAddress","deliveryNext"]},async apply(){const c=await r.applyAddressChange({source:"ucp",address:d});return c.type!=="success"?(i.log("web_mcp_address_change_declined","[WebMcp] address manager declined an admitted address",{reason:c.reason}),{status:"failed"}):(o(),H)}}};function xe(e,{readSavedCards:t,getSavedCardSelector:n}){return t()?.find(({instrument:o})=>o.id===e)?.usable?{status:"ready",negotiation:{include:["paymentLines","billingAddress"],loading:["paymentLines"],fieldsToResolve:["paymentLines"]},async apply(){const o=n?.();return o&&await o(e)?H:{status:"failed"}}}:{status:"rejected",field:"payment"}}function Ti(e,{readSavedCards:t}){return!!t()?.some(({instrument:n,usable:i})=>n.id===e&&n.selected&&i)}function Ei(e,t){const{checkout:n,clearShippingAddressErrors:i}=t;if(n.identity.current.value!=="shopPay")return{status:"rejected",field:"shippingAddress"};const o=n.addressManager.shipping.value,r=[...o.addresses.value,...o.immutableAddresses.value].find(d=>d.id===e);if(!r||r.disabled)return{status:"rejected",field:"shippingAddress"};const s=o.applyAddressChangeBlockReason("ucp").value;if(s&&s!=="MUST_SELECT_PROVIDED_ADDRESS")return;const a=ut(r.address.countryCode,"fulfillment.methods[0].selected_destination_id",t.shop);return a||{status:"ready",negotiation:{include:["shippingAddress","deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["shippingAddress","deliveryNext"]},async apply(){return await o.selectAddress(e)?(i(),H):{status:"failed"}}}}function he({fulfillmentMethods:e},{checkout:t},n=!1){const{proposed:i,negotiated:o}=t.proposal,r=o.fields.deliveryNext.peek(),s=r?.status==="filled"||r?.status==="partial"?r.lines.filter(Hi):[],a=new Map;for(const c of i.deliveryLines.peek()){const{id:l,targetMerchandiseLines:u,deliveryMethodTypes:p,deliveryMethodHandle:h}=c.peek();if(p.filter(X).length===0)continue;const f=(s.find(A=>!!l&&A.id===l)??s.find(A=>G(A.targetMerchandiseLines,u.filter(L=>L.requiresShipping).map(C))))?.methods.find(A=>A.handle===h);if(f){if(!X(f.methodType))continue}else if(An(h,p,f))return{status:"rejected",field:"fulfillmentMethods"};a.set(c,{deliveryLine:c,selectedOptionId:void 0,selectedOptionDetail
1s:void 0})}try{for(const c of Ri(e,i.deliveryLines.peek(),s))a.set(c.deliveryLine,c)}catch(c){if(!(c instanceof U))throw c;return{status:"rejected",field:"fulfillmentMethods",reason:c.reason}}const d=o.fields.mustSelectProvidedShippingRate.peek();return[...a.values()].some(({deliveryLine:c,selectedOptionId:l})=>!Cn(c.peek().deliveryMethodHandle,l,d))?{status:"rejected",field:"fulfillmentMethods"}:{status:"ready",negotiation:{include:["deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["deliveryNext"]},async apply(){for(const c of i.deliveryLines.value){const l=a.get(c);if(!l&&(!n||!c.value.deliveryMethodTypes.some(X)))continue;const{selectedOptionId:u,selectedOptionDetails:p}=l??{};c.value={...c.peek(),deliveryMethodHandle:u,deliveryMethodOptions:qi(p),...u===void 0&&{isCustomRate:void 0,customDeliveryStrategy:void 0}}}return H}}}const Si=({discountCodes:e=[]},t)=>{const{proposed:n,negotiated:i}=t.checkout.proposal,o=new Map,r=[];for(const s of n.discountLines.value){const{discount:a}=s;if(a.type==="code"||a.type==="discountCodeTrigger"){const d=a.title.toUpperCase(),c=o.get(d);c?c.push(s):o.set(d,[s])}else r.push(s)}if(i.fields.canUpdateDiscountCodes.value===!1){const s=new Set(e.map(d=>d.toUpperCase()));return s.size===o.size&&[...s].every(d=>o.has(d))?void 0:{status:"rejected",field:"discountCodes"}}return{status:"ready",negotiation:{include:["discountLines","deliveryNext"],loading:["discountLines","deliveryNext"],fieldsToResolve:["discountLines","totalSavings","merchandiseLines","deliveryNext"]},async apply(){const s=new Set;for(const a of e){const d=a.toUpperCase();if(s.has(d))continue;s.add(d);const c=o.get(d);c?r.push(...c):r.push({title:a,discount:{type:"discountCodeTrigger",title:a}})}return F(()=>{n.discountLines.value=r,n.reduction.value=void 0;const{discountCodeWarningSignal:a,currentDiscountCodeAttemptSignal:d}=t.negotiator.context;a.value=null,d.value=null}),H}}},wi=[Ii,Si,at,he];function qe(e,t,{fulfillmentRequest:n,fulfillment:i,locationAddress:o}={}){const r=[];for(const s of wi){if(s===at&&n){const{methodTypes:d}=n,{proposed:c}=t.checkout.proposal;r.push({status:"ready",negotiation:{include:["deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["deliveryNext"]},async apply(){return i?i.setDesiredMethod(d,o):o&&(c.locationAddress.value=o),H}})}const a=s===he?he(e,t,n!==void 0):s(e,t);if(a!==void 0){if(a.status==="rejected")return ct(a.field,a.reason);r.push(a)}}return r}class dt{#e;constructor(t){this.#e=t}writePayment({payment:t,billingAddress:n=t?.billing_address,applyBilling:i=!0}){const o=i?this.#t(n):void 0,r=this.#n(t);return r&&"error"in r?r:(F(()=>{r?.apply(),o?.apply()}),{status:"applied"})}#t(t){const{checkout:n}=this.#e;if(!x(n))return;const i=t===void 0?void 0:Z(t,n.address);return{apply({replacement:o=!1}={}){if(!x(n))return!1;const{proposed:r,negotiated:s,facts:a}=n.proposal,d=s.fields.isShippingRequired.value===!1;if(i&&!Ht(i)&&(d||!Mi(i,n)))return F(()=>{r.billingAddress.value=i,r.billingAddressOption.value="custom"}),!0;if(o&&d)return a.billingAddress||Ai(r)?!1:(F(()=>{r.billingAddress.value=Z({address_country:r.billingAddress.value.countryCode},n.address),r.billingAddressOption.value="custom"}),!0);const c=r.billingAddressOption.value;return r.billingAddressOption.value="shipping",i!==void 0||c!=="shipping"}}}#n(t){const{checkout:n,shop:i,paymentInstrument:o}=this.#e;if(!x(n)||!t&&!o.value)return;const{proposed:r,negotiated:s}=n.proposal,a=s.fields.paymentMethods.value,d=r.paymentLines.value.find(l=>!l.due&&l.method.type==="direct"),c=Ft(a??[],d?.method.type==="direct"&&!!d.method.alternative);return t&&(t.handler_id==="shopify.card"?!c:!i.hasFlagEnabled(jt)||!$t(a))?Pi():{apply(){x(n)&&F(()=>{const l=o.value;if(l?.handler_id==="shop_pay"&&l.credential?.approval_id&&(r.paymentLines.value=r.paymentLines.value.map(u=>u.method.type==="shopWallet"&&u.method.shopPayApprovalId===l.credential?.approval_id?{...u,method:{...u.method,shopPayApprovalId:void 0}}:u)),o.value=t,!!t){t.handler_id==="shopify.card"&&t.credential?.token&&c?(d?.method.type!=="direct"||d.method.paymentMethodIdentifier!==c.paymentMethodIdentifier)&&(r.paymentLines.value=Se(r.paymentLines.value,{method:{type:"direct",paymentMethodIdentifier:c.paymentMethodIdentifier,alternative:c.alternative}},we(i))):t.handler_id==="shop_pay"&&t.credential?.approval_id&&(r.paymentLines.value=Se(r.paymentLines.value,{method:{type:"shopWallet",shopPayApprovalId:t.credential.approval_id}},we(i)));for(const u of Object.values(r.directPaymentErrors))u.value=void 0;r.generalPaymentError.value=void 0,r.generalPaymentErrorCode.value=void 0}})}}}async applyUpdate(t,{isExpired:n}={}){const{shippingAddress:i}=t,o=t.payment&&"billing_address"in t.payment?t.payment.billing_address:void 0;if(await this.loadAddressMetadata(["saved_address_id"in i?void 0:i,x(this.#e.checkout)?o:void 0]),n?.())return b();if(this.#e.isSubmitting.value)return $();const r=t.payment&&"instrument_id"in t.payment?t.payment.instrument_id:void 0;if(r!==void 0&&(await this.#e.waitForPendingNegotiations(),n?.()))return b();let s=V(t.declaredFields,this.#e.declaredFields);if("error"in s)return s;if(s.some(({changed:y})=>y)){if(await this.#e.waitForPendingNegotiations(),n?.())return b();if(this.#e.isSubmitting.value)return $();if(s=V(t.declaredFields,this.#e.declaredFields),"error"in s)return s}let a=this.#e.getFulfillmentController?.(),d=oe(t,this.#e,a);if(d&&"error"in d)return d;let c;if(d?.needsLocalityLookup&&t.context){try{const y=this.#e.resolvePickupLocality;if(!y)throw new se;c=await y(t.context)}catch(y){return this.#e.observability.error(y instanceof se?y:new se(y)),n?.()?b():{error:{code:"update_failed",message:"context: Pickup locality lookup is unavailable. Nothing was applied. Call get_checkout and retry with the latest checkout. Do not attempt to update the checkout by interacting with the page."}}}if(n?.())return b();if(!c)return{error:{code:"rejected",message:"context: Could not resolve a unique postal locality. Nothing was applied. Check address_country, address_regi
1on and postal_code, then retry."}};if(s=V(t.declaredFields,this.#e.declaredFields),"error"in s)return s}if(t.context){const y=this.#e.checkout.proposal.proposed.locationAddress.value;pe(y,t.context)&&(c=y)}if(a=this.#e.getFulfillmentController?.(),d=oe(t,this.#e,a),d&&"error"in d)return d;let l=this.#t(o);const u=t.payment&&"handler_id"in t.payment?t.payment:void 0;let p=this.#n(u);if(p&&"error"in p)return p;let h=r===void 0?void 0:xe(r,this.#e);if(h?.status==="rejected")return ct(h.field);let m=qe(t,this.#e,{fulfillmentRequest:d,fulfillment:a,locationAddress:c});if("error"in m)return m;if(n?.())return b();const v=[];let f=!1;for(const y of["negotiate","stage"]){if(y==="stage"&&f&&(s=V(t.declaredFields,this.#e.declaredFields),"error"in s))return b();for(const I of s)if(!(I.phase!==y||!I.changed)){if(n?.())return b();try{if(!await I.apply()||n?.())return b()}catch{return b()}if(I.phase==="stage")v.push(I.negotiation);else if(f=!0,a=this.#e.getFulfillmentController?.(),d=oe(t,this.#e,a),d&&"error"in d||(m=qe(t,this.#e,{fulfillmentRequest:d,fulfillment:a,locationAddress:c}),"error"in m)||(l=this.#t(o),p=this.#n(u),p&&"error"in p)||(h=r===void 0?void 0:xe(r,this.#e),h?.status==="rejected"))return b()}}if(p){const y=p;m.push({status:"ready",negotiation:{include:["paymentLines"],loading:["paymentLines"],fieldsToResolve:["paymentLines"]},async apply(){return y.apply(),H}})}if(!h&&m.length===0&&v.length===0&&!l)return{status:"applied"};if(n?.())return b();if(this.#e.isSubmitting.value)return $();if((await Promise.all(F(()=>m.map(y=>y.apply())))).find(y=>y.status==="failed")||n?.())return b();if(this.#e.isSubmitting.value)return $();if(h){if((await h.apply()).status==="failed"||n?.()||(await this.#e.waitForPendingNegotiations(),n?.()))return b();if(this.#e.isSubmitting.value)return $()}const E=l?.apply({replacement:!0})??!1;if(!h&&m.length===0&&v.length===0&&!E)return{status:"applied"};const g=await this.#i(Di([...m.map(y=>y.negotiation),...v,...h?[h.negotiation]:[],...E?[{include:["billingAddress"],loading:["billingAddress"],fieldsToResolve:["billingAddress"]}]:[]]));await this.#e.waitForPendingNegotiations();const S=Li(g);if(r!==void 0&&!Ti(r,this.#e))return b();if(!("error"in S)&&!n?.()&&d?.needsLocalityLookup&&c&&t.context&&pe(this.#e.checkout.proposal.proposed.locationAddress.value,t.context)){const{proposed:y}=this.#e.checkout.proposal,I=y.deliveryLines.value.map(R=>R.value),w=Ie(y.merchandiseLines.value,I),O=ue(I,w);O.length&&O.every(M)&&this.#e.announcePickupLocality?.(c)}return n?.()?b():S}async loadAddressMetadata(t){const n=new Set;for(const o of t){const r=o?.address_country?.toUpperCase();o&&r&&ki(r,o)&&n.add(r)}const{countryDetails:i}=this.#e.checkout.address;for(const o of n){const r=i.get(o);(!r||r.isFallback)&&await i.fetch(o)}}async#i(t){let n;return await this.#e.journey.negotiate({...t,runListenersOnError:t.include.includes("shippingAddress")||t.include.includes("discountLines"),onComplete:i=>{n=i}}),n}}class se extends Error{constructor(t){super("WebMCP pickup locality lookup failed",{cause:t}),this.name="WebMcpLocalityLookupError"}}function ki(e,t){const n=!!(t.street_address||t.street_name||t.street_number),i=!!(t.extended_address||t.district),o=ge(e,"")!==null,r=ve(e,"")!==null;return n&&o||i&&r}function Di(e){return{include:ae(e,"include"),loading:ae(e,"loading"),fieldsToResolve:ae(e,"fieldsToResolve")}}function ae(e,t){return[...new Set(e.flatMap(n=>n[t]))]}function Li(e){return e?.status==="success"||e?.status==="error"?{status:"applied"}:b()}function $(){return{error:{code:"completion_in_progress",message:"A credentialed completion is in progress. Wait for it to finish before updating payment."}}}function Pi(){return{error:{code:"invalid_request",message:"This checkout does not accept the supplied payment handler. Call get_checkout for the current checkout state."}}}function b(){return{error:{code:"update_failed",message:K}}}const Ni={context:"context",buyer:"buyer",discountCodes:"discounts",declaredFields:"declared_fields",shippingAddress:"fulfillment",fulfillmentMethods:"fulfillment",payment:"payment"};function Mi(e,t){const n=Ae(t.proposal.proposed.shippingAddress.value,t.address);return Bt(e,Z(n,t.address))}function ct(e,t){if(t instanceof lt){const n=t.listedCountryCodes?` Supported countries: ${t.listedCountryCodes.join(", ")}.`:"";return{error:{code:"rejected",message:`${t.path} ${t.countryCode}
1 is not a country this shop ships to. Nothing was applied.${n} Tell the buyer. Do not attempt to update the checkout by interacting with the page.`}}}if(t==="unsupported_option_instructions"||t==="unsupported_option_phone"){const n=t==="unsupported_option_instructions"?"instructions":"phone_number";return{error:{code:"rejected",message:`The selected delivery option does not support selected_option_details.${n}. Nothing was applied. Remove ${n} from selected_option_details or choose an option that supports it, then retry. Do not attempt to update the checkout by interacting with the page.`}}}return t==="unknown_fulfillment_group"?{error:{code:"rejected",message:`fulfillment.methods[].groups[] does not match a delivery group in the current checkout. ${Ue}`}}:t==="unselectable_fulfillment_group"?{error:{code:"rejected",message:"fulfillment.methods[].groups[] has no selectable delivery option in the current checkout. Nothing was applied. Send the update without groups, then choose an option from the next get_checkout. Do not attempt to update the checkout by interacting with the page."}}:t==="unknown_fulfillment_option"?{error:{code:"rejected",message:`fulfillment.methods[].groups[].selected_option_id is not an option for this group in the current checkout. ${Ue}`}}:{error:{code:"update_failed",message:`Unable to update ${Ni[e]}. Call get_checkout to review the checkout and its messages before retrying. Do not attempt to update the checkout by interacting with the page.`}}}class U extends Error{constructor(t){super(t),this.name="WebMcpFulfillmentMethodUpdateError",this.reason=t}}const Oi=20;class lt extends Error{constructor(t,n,i){super(`${t} is not a shipping country`),this.name="UnsupportedShippingCountryError",this.countryCode=t,this.path=n,this.listedCountryCodes=i}}function ut(e,t,{shippingCountries:n}){const i=e?.trim().toUpperCase();if(!(!i||n.length===0)&&!n.some(({value:o})=>o===i))return{status:"rejected",field:"shippingAddress",reason:new lt(i,t,n.length<=Oi?n.map(({value:o})=>o):void 0)}}function Ri(e,t,n){return e.methods.flatMap(i=>i.type==="pickup"?Ui(i,t,n):i.groups.map(o=>{const r=pt(o,n,o.id&&t.some(({value:a})=>a.id===o.id)?"unselectable_fulfillment_group":"unknown_fulfillment_group"),s=r.methods.find(({handle:a,methodType:d})=>a===o.selected_option_id&&(d==="SHIPPING"||d==="LOCAL"));if(!s||Y(r)!=="shipping")throw new U("unknown_fulfillment_option");return fe(r,s,o.selected_option_details,t)}))}function Ui(e,t,n){const i=e.selected_destination_id===void 0?void 0:it(n).find(({id:r})=>r===e.selected_destination_id);if(e.selected_destination_id!==void 0&&!i)throw new U("unknown_pickup_destination");const o=new Map;for(const r of e.groups){if(r.selected_option_id!==le)throw new U("unknown_fulfillment_option");const s=pt(r,n);if(Y(s)!=="pickup"||i&&!i.selections.some(a=>a.line===s)||o.has(s))throw new U("unknown_fulfillment_group");o.set(s,r)}return i?i.selections.map(({line:r,method:s})=>fe(r,s,o.get(r)?.selected_option_details,t)):[...o].map(([r,s])=>{const a=r.methods.find(d=>d.handle===r.selectedDeliveryMethodHandle&&M(d.methodType)&&d.pickupLocation);if(!a)throw new U("unknown_pickup_destination");return fe(r,a,s.selected_option_details,t)})}function pt(e,t,n="unknown_fulfillment_group"){const i=t.find(o=>!!e.id&&o.id===e.id)??t.find(o=>G(o.targetMerchandiseLines,e.line_item_ids));if(!i)throw new U(n);return i}function fe(e,t,n,i){const o=i.find(r=>!!e.id&&r.value.id===e.id)??i.find(r=>G(r.value.targetMerchandiseLines,e.targetMerchandiseLines?.filter(s=>s.requiresShipping).map(C)));if(!o)throw new U("unknown_fulfillment_group");if(!o.value.deliveryMethodTypes.includes(t.methodType))throw new U("unsupported_fulfillment_transition");return xi(t,n),{deliveryLine:o,selectedOptionId:t.handle,selectedOptionDetails:n}}function xi(e,t){if(t){if(t.instructions!==void 0&&!ee(e,"instructions"))throw new U("unsupported_option_instructions");
1if(t.phone_number!==void 0&&!ee(e,"phone_number"))throw new U("unsupported_option_phone")}}function qi(e){return{phone:e?.phone_number,instructions:e?.instructions}}function Hi(e){return e.status==="available"}const He=Tt()(["shipping","pickup"]);class _ extends Error{constructor(t,n,i){super(`${t}: expected ${n}, got ${i} instead.`),this.name="UpdateCheckoutInputError"}}const ht='Give the street either as street_address (e.g. "123 Yonge St") or as street_name plus street_number (e.g. "Yonge St" and "123"). Partial addresses are accepted; checkout reports missing or invalid address information in messages.',ft={id:{type:"string"},street_address:{type:"string",description:'First address line, typically the street address or PO Box number, e.g. "123 Yonge St". Ignored when street_name is nonempty.'},street_name:{type:"string",description:'Street name without the house or building number, e.g. "Yonge St". When nonempty, street_name and street_number replace street_address.'},street_number:{type:"string",description:'House or building number, e.g. "123". Used only with a nonempty street_name.'},extended_address:{type:"string",description:"Apartment, suite, unit, or other address complement."},district:{type:"string",description:"A regional or city subdivision, such as a neighborhood, district, or block. An empty string clears it. Ignored when the address country has no district field."},address_locality:{type:"string",description:"The city, town, or village used as the locality in the address country."},address_region:{type:"string",description:'State/province/region code (e.g. "ON", "NY") or full name; required for some countries. get_checkout returns the code.'},address_country:{type:"string",description:'ISO 3166-1 alpha-2 country code, e.g. "CA", "US". Not a country name.'},postal_code:{type:"string",description:'Postal or ZIP code in the address country format, e.g. "K1A 0B1", "94103". Case and spacing are normalized.'},company:{type:"string"},first_name:{type:"string"},last_name:{type:"string"},phone_number:{type:"string",description:"Contact phone: address-country national format or E.164 (e.g. +16135550123)."}},Fi={type:"object",description:`Replacement address. Include all fields to retain; omitted fields are cleared. Use PUT semantics, not PATCH. ${ht}`,properties:ft},J={type:"object",properties:{instruments:{type:"array",maxItems:1,items:{type:"object",properties:{handler_id:{type:"string",enum:["shopify.card","shop_pay"]},credential:{type:"object"},id:{type:"string"},type:{type:"string",enum:["card","shop_pay"]},selected:{type:"boolean"},billing_address:Fi}}}}};function ji(e,{ignorePayment:t=!1}={}){const n=D(e,"input");return ye({object:n,allowedFields:["payment"],path:"input"}),t||n.payment===void 0?{}:{payment:mt(n.payment,{path:"input.payment",requireCredential:!0})}}function mt(e,{path:t,requireCredential:n=!1,savedPaymentMethodsOnly:i=!1}){const o=D(e,t);if(!n&&(o.instruments===void 0||Array.isArray(o.instruments)&&o.instruments.length===0))return;const r=`${t}.instruments[0]`,s=io(o.instruments,`${t}.instruments`);if(!n&&i)return zi(s,r);const a=s.handler_id;if(!n&&a===void 0&&s.credential===void 0){const m=Fe(s,r);return m===void 0?void 0:{billing_address:m}}if(a!=="shopify.card"&&a!=="shop_pay")throw new _(`${r}.handler_id`,"shopify.card or shop_pay","an unsupported handler");const d=q(s,{id:void 0,type:void 0},r),c=a==="shopify.card"?"card":"shop_pay";if(d.type!==void 0&&d.type!==c)throw new _(`${r}.type`,c,"an unsupported instrument type");const l=Fe(s,r),u={id:d.id??Vt(),...l===void 0?{}:{billing_address:l}},p=`${r}.credential`,h=!n&&s.credential===void 0?void 0:D(s.credential,p);if(a==="shopify.card"){if(h===void 0)return{...u,handler_id:a,type:"card"};if(ye({object:h,allowedFields:["type","token"],path:p}),h.type!==void 0&&h.type!=="shopify_token")throw new _(`${p}.type`,"shopify_token","an unsupported credential type");return{...u,handler_id:a,type:"card",credential:{type:"shopify_token",...n||h.token!==void 0?{token:me(h.token,`${p}.token`)}:{}}}}if(h===void 0)return{...u,handler_id:a,type:"shop_pay"};if(ye({object:h,allowedFields:["type","approval_id"],path:p}),h.type!==void 0&&h.type!=="shop_token")throw new _(`${p}.type`,"shop_token","an unsupported credential type");return{...u,handler_id:a,type:"shop_pay",credential:{type:"shop_token",...n||h.approval_id!==void 0?{approval_id:me(h.approval_id,`${p}.approval_id`).trim()}:{}}}}function me(e,t){if(typeof e!="string"||e.trim().length===0)throw new _(t,"a non-empty string",T(e));return e}function Fe(e,t){if(e.billing_address!==void 0)return q(e.billing_address,_t,`${t}.billing_address`)}function ye({object:e,allowedFields:t,path:n}){if(Object.keys(e).some(i=>!t.includes(i)))throw new _(n,"only supported fields","extra properties")}
1const yt={email:"",phone_number:""},B={first_name:"",last_name:"",phone_number:"",street_address:void 0,extended_address:void 0,address_locality:"",address_region:"",address_country:"",postal_code:""},_t={...B,company:void 0,street_name:void 0,street_number:void 0,district:void 0},je={phone_number:void 0,instructions:void 0};function $i(e,t={}){const n=Yi(e,t);return Gi(Bi(),n)}function Bi(){return{buyer:{...yt},discountCodes:[],declaredFields:[],shippingAddress:{...B},fulfillmentMethods:{methods:[]},payment:void 0}}function Gi(e,t){return{...e,...t,buyer:{...e.buyer,...t.buyer}}}function Yi(e,t){const n=D(D(e,"input").checkout,"input.checkout"),i={};if(n.context!==void 0){const o="input.checkout.context",r=q(n.context,{address_country:void 0,address_region:void 0,postal_code:void 0},o);if(!r.address_country?.trim()||!r.postal_code?.trim())throw new _(o,"address_country and postal_code for a pickup search","incomplete locality");i.context={address_country:r.address_country.trim().toUpperCase(),postal_code:r.postal_code.trim(),...r.address_region?.trim()&&{address_region:r.address_region.trim().toUpperCase()}}}return n.buyer!==void 0&&(i.buyer=q(n.buyer,yt,"input.checkout.buyer")),n.discounts!==void 0&&(i.discountCodes=Xi(n.discounts)??[]),n.declared_fields!==void 0&&(i.declaredFields=Vi(n.declared_fields)),n.fulfillment!==void 0&&Object.assign(i,Ki(n.fulfillment)),!t.ignorePayment&&n.payment!==void 0&&(i.payment=mt(n.payment,{path:"input.checkout.payment",savedPaymentMethodsOnly:t.savedPaymentMethodsOnly})),i}const Wi=new Set(["purpose","title","description","value_schema","presentation","required"]);function Vi(e){const t="input.checkout.declared_fields";if(!Array.isArray(e))throw new _(t,"an array",T(e));const n=new Set;return e.map((i,o)=>{const r=`${t}[${o}]`,s=D(i,r);for(const a of Object.keys(s))if(!["key","value"].includes(a)&&!Wi.has(a))throw new _(`${r}.${a}`,"a declared field key or value","an unknown field");if(typeof s.key!="string"||s.key.length===0)throw new _(`${r}.key`,"a non-empty string",T(s.key));if(n.has(s.key))throw new _(`${r}.key`,"a unique declared field key",`duplicate ${JSON.stringify(s.key)}`);if(n.add(s.key),!Object.hasOwn(s,"value")||s.value===void 0)throw new _(`${r}.value`,"a value","undefined");return{key:s.key,value:s.value}})}function zi(e,t){for(const n of Object.keys(e))if(!["id","type","selected","display"].includes(n))throw new _(`${t}.${n}`,"a saved instrument id from get_checkout, not new payment data","an unsupported field");return{instrument_id:me(e.id,`${t}.id`)}}function Xi(e){const t="input.checkout.discounts",{codes:n}=D(e,t);if(n!==void 0){if(!gt(n))throw new _(`${t}.codes`,"an array of strings",T(n));return n}}function Ki(e){const t="input.checkout.fulfillment",n=D(e,t);if(!Array.isArray(n.methods))throw new _(`${t}.methods`,"an array",T(n.methods));if(n.methods.length>1)throw new _(`${t}.methods`,"at most 1 fulfillment method",`${n.methods.length} methods`);let i={...B};const o=[];for(const[r,s]of n.methods.entries()){const a=`${t}.methods[${r}]`,d=D(s,a),c=Ji(d.type??"shipping",`${a}.type`),{id:l}=q(d,{id:void 0},a),u={...l!==void 0&&{id:l}},p=d.groups===void 0?[]:to(d.groups,`${a}.groups`),h=Zi(d,a);switch(c){case"pickup":{h===void 0&&Qi(d.destinations,`${a}.destinations`),o.push({...u,type:c,...h!==void 0&&{selected_destination_id:h},groups:p});break}case"shipping":{i=h===void 0?eo(d,a):{saved_address_id:h},o.push({...u,type:c,groups:p});break}default:It(c)}}return{shippingAddress:i,fulfillmentMethods:{methods:o}}}function Ji(e,t){const n=He.find(i=>i===e);if(n!==void 0)return n;throw new _(t,He.map(i=>JSON.stringify(i)).join(" or "),typeof e=="string"?JSON.stringify(e):T(e))}function Qi(e,t){if(e!==void 0){if(!Array.isArray(e))throw new _(t,"an array",T(e));for(const[n,i]of e.entries()){const o=D(i,`${t}[${n}]`);if(o.type!=="business_location")throw new _(`${t}[${n}].type`,'a read-only "business_location" from get_checkout; select pickup through selected_destination_id',T(o.type))}}}function Zi(e,t){if(e.selected_destination_id===null)return;const{selected_destination_id:n}=q(e,{selected_destination_id:void 0},t);
1if(n==="")throw new _(`${t}.selected_destination_id`,"a non-empty string or null","an empty string");return n}function eo(e,t){const n=`${t}.destinations[0]`,i=`${t}.destinations`,{destinations:o}=e;if(o===void 0)return{...B};if(!Array.isArray(o))throw new _(i,"an array",T(o));if(o.length===0)return{...B};if(o.length!==1)throw new _(i,"1 item",`${o.length} items`);const r=D(o[0],n);if(r.pickup_location_address!==void 0||r.type==="business_location")throw new _(n,"a flat shipping address","a pickup location");const s=q(r,_t,n);return{...B,...s,address_country:(s.address_country??"").trim()}}function to(e,t){if(!Array.isArray(e))throw new _(t,"an array",T(e));return e.flatMap((n,i)=>{const o=`${t}[${i}]`,r=D(n,o),s=r.selected_option_id,a=r.selected_option_details;if(s===void 0){if(a!==void 0)throw new _(`${o}.selected_option_details`,"selected_option_id to also be present","selected_option_details without selected_option_id");return[]}if(typeof s!="string")throw new _(`${o}.selected_option_id`,"a string",T(s));const d=r.id;if(typeof d!="string")throw new _(`${o}.id`,"a string",T(d));const c=r.line_item_ids;if(c!==void 0&&!gt(c))throw new _(`${o}.line_item_ids`,"an array of strings",T(c));const l={...je,...q(a===void 0?{}:a,je,`${o}.selected_option_details`)};return[{id:d,line_item_ids:c,selected_option_id:s,selected_option_details:l}]})}function D(e,t){if(!no(e))throw new _(t,"an object",T(e));return e}function no(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function io(e,t){if(!Array.isArray(e))throw new _(t,"an array",T(e));if(e.length!==1)throw new _(t,"1 item",`${e.length} items`);return D(e[0],`${t}[0]`)}function q(e,t,n){const i=D(e,n),o={};for(const r in t){if(!Object.hasOwn(i,r))continue;const s=i[r];if(typeof s!="string")throw new _(`${n}.${r}`,"a string",T(s));o[r]=s}return o}function gt(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function T(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"an array":typeof e=="object"?"an object":`a ${typeof e}`}const Te="Recoverable messages may be stale and do not by themselves mean completion is blocked. Use supported update_checkout fields to correct known missing or invalid data. When status is ready_for_complete and the buyer has authorized the purchase, call complete_checkout even if recoverable messages remain. Do not retry an unchanged update just to clear messages. After a completion failure, inspect the current checkout and resolve the cause before retrying. requires_buyer_input means a confirmed buyer action, such as a payment challenge: follow the message instructions and do not resubmit checkout. requires_buyer_review means the buyer must review the checkout on the page and authorize submission before complete_checkout is called again to submit.",oo={type:"object",additionalProperties:!1,properties:{payment:{...J,required:["instruments"],properties:{instruments:{...J.properties.instruments,minItems:1,items:{...J.properties.instruments.items,required:["handler_id","credential"]}}}}}},de="Checkout is still initializing. Retry shortly. Do not attempt to complete the checkout by interacting with the page.",z="Checkout completion could not be confirmed. Call get_checkout for the current state and its messages before retrying. Do not attempt to complete the checkout by interacting with the page.";class ro extends Error{constructor(){super("WebMCP complete_checkout failed"),this.name="WebMcpCompleteCheckoutError"}}function $e(e){return!!(e?.handler_id==="shopify.card"?e.credential?.token:e?.credential?.approval_id)}function so({isSubmitting:e,paymentInstrument:t,signal:n,checkout:i,shop:o,readCheckout:r,readSavedCards:s,shopPay:a,observability:d,getPreactContext:c,declaredFields:l}){let u=!1;return{name:"complete_checkout",title:"Complete checkout",description:`Advances the current checkout toward placing an order, with optional payment details. Use this tool—not browser or DOM controls—to progress or submit, and only after the buyer authorizes the purchase. Read get_checkout first and follow the field schemas. To change the saved Shop Pay card, select an available instrument using update_checkout first. If a review step is configured, the first call opens it without placing an order and returns buyer_review_required. Call complete_checkout again from review only after the buyer reviews the checkout and authorizes submission. Returns checkout state, which may still be processing, or an error. Use get_checkout to verify the outcome; do not resubmit while status is complete_in_progress or completed. A status of completed means the order was successfully placed. If buyer_action_required is returned, ask the buyer to follow the returned instructions on the page; do not act on their behalf. ${Te}`,inputSchema:oo,annotations:{consequentialHint:!0,readOnlyHint:!1,untrustedContentHint:!0},execute:async h=>W(await p(h),i)};async function p(h){if(u||e.value)return{error:{code:"completion_in_progress",message:"A checkout completion is already in progress. Wait for it to finish, then call get_checkout before retrying."}};u=!0;try{if(!o.hasFlagEnabled(zt))return{error:{code:"buyer_action_required",message:"The buyer must manually complete checkout on the page. Do not attempt to complete checkout on their behalf."}};const{payment:m}=ji(h,{ignorePayment:!x(i)}),v=i.latestReceipt.value?.status;if(v==="processing"||v==="processing_remote_checkouts"||v==="polling_for_order"||v==="processed"||v==="action_required")return r()??{error:{code:"completion_failed",message:z}};const f=c();if(!f||n?.aborted)return{error:{code:"internal_error",message:de}};if(x(i)&&(m||t.value)){if(await f.waitForPendingNegotiations(),n?.aborted)return{error:{code:"internal_error",message:de}};const g=x(i)?m??t.value:void 0;if(g&&m&&!i.isPaymentRequired.value)return{error:{code:"invalid_request",message:"This checkout requires no payment. Retry complete_checkout without the payment field."}};if(g&&$e(g)&&i.isPaymentRequired.value){const S=new dt({isSubmitting:e,paymentInstrument:t,checkout:i,shop:o,shopPay:a,observability:d,declaredFields:l,...f,readSavedCards:s});if(m&&(await S.loadAddressMetadata([m.billing_address]),n?.aborted))return{error:{code:"internal_error",message:de}};
1const y=S.writePayment({payment:g,applyBilling:m!==void 0});if("error"in y)return y}}let A=!1,L=!1;try{e.value=x(i)&&i.isPaymentRequired.value&&$e(t.value),await f.journey.progress("web-mcp-complete-checkout",g=>{A=g.status==="success"||g.status==="alreadyCompleted",L||="negotiated"in g||"receipt"in g})}finally{e.value&&L&&(t.value=void 0),e.value=!1}const E=r();return!A&&!E?.messages?.some(g=>g.type==="error"&&g.severity==="requires_buyer_input")?{error:{code:"completion_failed",message:z}}:E??{error:{code:"completion_failed",message:z}}}catch(m){return m instanceof _?{error:{code:"invalid_request",message:`${m.message} Correct the input and retry. Do not attempt to complete the checkout by interacting with the page.`}}:(d.error(new ro),{error:{code:"internal_error",message:z}})}finally{u=!1}}}const ao="Checkout data is not available yet. Retry shortly. Do not attempt to read checkout state by interacting with the page.",co="Unable to read the checkout. Do not attempt to read checkout state by interacting with the page.";
1class lo extends Error{constructor(){super("WebMCP get_checkout failed to read the checkout"),this.name="WebMcpGetCheckoutError"}}function uo({checkout:e,readCheckout:t,observability:n}){return{name:"get_checkout",title:"Get checkout",description:`Reads the current checkout without changing it. Use it before updating, to inspect validation messages, or to check completion and order confirmation. Available Shop Pay saved cards are reported under payment.instruments for selection by id; raw credentials and security codes are never reported. A status of completed means the order was successfully placed. Monetary amounts are integers in the currency’s minor units. Returns the checkout or an error with a code and message. ${Te}`,inputSchema:{type:"object",properties:{}},annotations:{consequentialHint:!1,readOnlyHint:!0,untrustedContentHint:!0},execute:()=>W(i(),e)};function i(){try{const o=t(e.latestReceipt.value?.status==="processed"?"negotiated":"proposed");return o||{error:{code:"internal_error",message:ao}}}catch{return n.error(new lo),{error:{code:"internal_error",message:co}}}}}const po=3e4;class ho extends Error{constructor(t){super("WebMCP navigate_to_storefront failed",{cause:t}),this.name="WebMcpStorefrontNavigationError"}}function vt({shop:e,url:t}){if(e.hasStorefront)try{const n=new URL(e.previewReturnUrl??t.storefront());return n.protocol!=="https:"&&n.protocol!=="http:"||n.username||n.password?void 0:n.href}catch{return}}function fo({checkout:e,shop:t,url:n,observability:i,signal:o,getPreactContext:r}){return{name:"navigate_to_storefront",title:"Return to storefront",description:"Leaves checkout and navigates this tab to the store’s storefront to continue shopping. Does not place an order or change the cart. After navigation, refresh the available tools before searching for products or changing the cart.",inputSchema:{type:"object",properties:{},additionalProperties:!1},annotations:{readOnlyHint:!1,consequentialHint:!1},execute:async(d,c)=>W(await s(d,c?.signal??o),e)};async function s(d,c){let l;try{if(d===null||typeof d!="object"||Array.isArray(d)||Object.keys(d).length>0)return{error:{code:"invalid_request",message:"navigate_to_storefront takes no input. Retry with an empty object."}};if(c.aborted||o.aborted)return Be();const u=r();if(!u)return{error:{code:"internal_error",message:"Checkout is still initializing. Retry shortly."}};if(a(u))return Ge();const p=vt({shop:t,url:n});if(!p)return mo();const h=new Promise(v=>{l=setTimeout(()=>v("timeout"),po)}),m=await Promise.race([u.waitForPendingNegotiations(),h]);return c.aborted||o.aborted?Be():m==="timeout"?(i.log("web_mcp_storefront_navigation_timed_out","Storefront navigation timed out waiting for pending checkout updates"),{error:{code:"navigation_failed",message:"Checkout updates are still pending. Navigation was not started. Retry after updates finish."}}):a(u)?Ge():(window.location.assign(p),{status:"navigation_started",destination_url:p,message:"Refresh the available tools after the storefront loads."})}catch(u){return i.error(new ho(u)),{error:{code:"navigation_failed",message:"Unable to navigate to the storefront. Refresh the available tools and check the current page before retrying."}}}finally{clearTimeout(l)}}function a({journey:d}){const c=e.latestReceipt.value;return d.completing.value||d.progressing.value||c!=null&&!["processed","failed","abandoned"].includes(c.status)}}function Be(){return{error:{code:"navigation_failed",message:"Navigation was cancelled. The tool did not leave checkout."}}}function Ge(){return{error:{code:"checkout_busy",message:"Checkout submission or payment is in progress. Wait for it to finish and call get_checkout before navigating away."}}}function mo(){return{error:{code:"navigation_failed",message:"A supported storefront destination is not available. Stay on the current checkout."}}}const Ye=3e4,We="Checkout is not available for updates. Retry shortly. Do not attempt to update the checkout by interacting with the page.",yo="Correct the input and retry. Do not attempt to update the checkout by interacting with the page.",_o={type:"object",required:["checkout"],properties:{checkout:{type:"object",description:"Replacement buyer, fulfillment, and discount-code state. Omitted sections and fields are cleared; resend values to retain them.",properties:{context:{type:"object",required:["address_country","postal_code"],description:"Optional pickup search origin. Omission retains the current search origin. An unchanged origin may be echoed when switching to shipping. Does not replace shipping or billing addresses. Resolve discovery before selecting a destination in a subsequent call.",properties:{address_country:{type:"string",description:"ISO country code."}
1,address_region:{type:"string",description:"Province or region code."},postal_code:{type:"string"}}},payment:{...J,description:"Payment and billing replacement. Billing may be supplied without a handler or credential. When shipping is required, omitted billing or billing matching shipping uses shipping as billing; a different address becomes custom billing."},buyer:{type:"object",description:"Buyer contact details.",properties:{email:{type:"string",description:'Buyer email address, e.g. "[email protected]".'},phone_number:{type:"string",description:"Buyer phone number; E.164 recommended (e.g. +16135550123)."}}},discounts:{type:"object",description:"Buyer-entered discount codes.",properties:{codes:{type:"array",items:{type:"string"}}}},declared_fields:{type:"array",description:"Replacement values for declared checkout fields. Each field's description in get_checkout states its omission behavior. Echoed descriptor metadata is ignored; only key and value are used.",items:{type:"object",required:["key","value"],properties:{key:{type:"string"},value:{type:["string","boolean","null"]}}}},fulfillment:{type:"object",description:"Use a method type to switch all physical items between shipping and pickup while the delivery selector is mounted. Supply context locality to search for pickup locations. Select a returned destination in a subsequent call. selected_destination_id wins when both it and destinations are supplied.",required:["methods"],properties:{methods:{type:"array",maxItems:1,description:"At most one fulfillment method. Mode changes apply to all physical items; split shipping is not supported. Updates to checkouts with both shipping and pickup are rejected. Omitted methods clear selections without changing the active mode.",items:{type:"object",properties:{id:{type:"string",description:"Existing method ID; omit when changing type."},type:{type:"string",enum:["shipping","pickup"],description:"shipping or pickup. Defaults to shipping. Mode changes and locality discovery support store pickup only. Existing pickup-point destinations remain selectable. A new type or search origin cannot be combined with destination or option selections."},selected_destination_id:{type:["string","null"],description:"Pickup: a location id from get_checkout. Shipping: Shop Pay saved destination ids only. Null selects nothing, so destinations applies instead."},destinations:{type:"array",items:{type:"object",description:`One replacement shipping address, ignored when selected_destination_id is set. Use PUT semantics, not PATCH. ${ht}`,properties:ft}},groups:{type:"array",items:{type:"object",required:["id"],properties:{id:{type:"string"},line_item_ids:{type:"array",items:{type:"string"}},options:{type:"array",items:{type:"object",required:["id"],properties:{id:{type:"string"}}}},selected_option_id:{type:"string",description:'Option ID from get_checkout; "pickup" for pickup groups.'},selected_option_details:{type:"object",description:"Requires selected_option_id.",properties:{phone_number:{type:"string"},instructions:{type:"string"}}}}}}}}}}}}}}},go="Updates the current checkout without placing an order. Use this tool—not browser or DOM controls—whenever checkout data needs to change, even if visible fields are partially filled. Supports buyer contact details, shipping addresses and options, billing addresses, discounts, and payment details. In Shop Pay, select one payment.instruments entry by its id from get_checkout, or omit payment to keep the current card; new payment credentials are not accepted. Read get_checkout first and follow the field schemas’ replacement rules; do not assume omitted data is preserved. Returns the resulting checkout or an error. If an update fails, call get_checkout and inspect its messages before retrying.";
1class vo extends Error{constructor(){super("WebMCP update_checkout failed to apply"),this.name="WebMcpUpdateCheckoutError"}}function bo({isSubmitting:e,paymentInstrument:t,signal:n,checkout:i,shop:o,shopPay:r,router:s,getSavedCardSelector:a,readCheckout:d,readSavedCards:c,observability:l,getPreactContext:u,declaredFields:p,getFulfillmentController:h}){return{name:"update_checkout",title:"Update checkout",description:`${go} ${Te}`,inputSchema:_o,annotations:{consequentialHint:!1,readOnlyHint:!1,untrustedContentHint:!0},execute:async v=>W(await m(v),i)};async function m(v){let f;try{if(e.value)return $();const A=i.identity.current.value==="shopPay",L=$i(v,{savedPaymentMethodsOnly:A,ignorePayment:A?!i.isPaymentRequired.value:!x(i)}),E=u();if(!E||n?.aborted)return{error:{code:"internal_error",message:We}};if(s.currentUrl.value.normalizedPath==="/review"&&s.navigate("/"),L.payment&&"instrument_id"in L.payment&&!a())return{error:{code:"internal_error",message:We}};const{loadPickupLocalityServices:g}=E;let S;const y=new dt({isSubmitting:e,paymentInstrument:t,checkout:i,shop:o,shopPay:r,getSavedCardSelector:a,observability:l,declaredFields:p,...E,readSavedCards:c,getFulfillmentController:h,resolvePickupLocality:g?async R=>(S=await g(),S.resolvePickupLocality(R)):void 0,announcePickupLocality:R=>S?.announcePickupLocality(R),get negotiator(){return E.negotiator}});let I=!1;const w=new Promise(R=>{f=setTimeout(()=>{I=!0,R("timeout")},Ye)}),O=await Promise.race([y.applyUpdate(L,{isExpired:()=>I||!!n?.aborted}),w]);return O==="timeout"?(l.log("web_mcp_update_timed_out","[WebMcp] Update did not finish in time; update outcome is unknown",{timeoutMs:Ye}),{error:{code:"update_failed",message:K}}):"error"in O?O:d()??{error:{code:"update_failed",message:K}}}catch(A){return A instanceof _?{error:{code:"invalid_request",message:`${A.message} ${yo}`}}:(l.error(new vo),{error:{code:"internal_error",message:K}})}finally{clearTimeout(f)}}}function Ao(e){return typeof e=="object"&&e!==null&&"error"in e&&typeof e.error=="object"}function Co(e){if(typeof e!="object"||e===null||!("error"in e))return"unknown";const{error:t}=e;if(typeof t!="object"||t===null||!("code"in t))return"unknown";switch(t.code){case"buyer_action_required":case"checkout_busy":case"completion_failed":case"completion_in_progress":case"internal_error":case"invalid_request":case"navigation_failed":case"rejected":case"update_failed":return t.code;default:return"unknown"}}function _e(e,t,n,i){const o=Math.round(performance.now()-i),r=Ao(n),s={tool:t,outcome:r?"error":"success",...r&&{errorCode:Co(n)}};e.log("web_mcp_tool_executed","[WebMcp] tool executed",{...s,durationMs:o}),e.histogram({name:"web_mcp_tool_execution",value:o,unit:"ms",attributes:s})}function Ve(e,{activeTool:t,observability:n,checkout:i}){const o=e.name;return{...e,execute:async(...r)=>{const s=performance.now();if(t.current==="navigate_to_storefront"||o==="navigate_to_storefront"&&t.current!==void 0){const a=W({error:{code:"checkout_busy",message:"Another checkout tool is running. Wait for it to finish before retrying."}},i);return _e(n,o,a,s),a}return t.during(o,async()=>{const a=await e.execute(...r);return _e(n,o,a,s),a})}}}function Io(e,t){const n=e.name;return{...e,execute:(...i)=>{const o=performance.now(),r=e.execute(...i);return _e(t,n,r,o),r}}}
1class To extends Error{constructor(t,n){super(`WebMCP tool registration failed for ${t}: ${String(n)}`),this.name="WebMcpRegistrationError",n instanceof Error&&(this.cause=n)}}function Eo(e,t){const n=new AbortController,i=ze(function(){e.latestReceipt.value?.status==="processed"&&(this.dispose(),n.abort())});return t.addEventListener("abort",()=>{i(),n.abort()},{once:!0,signal:n.signal}),n.signal}function So({modelContext:e,signal:t,isSubmitting:n,paymentInstrument:i,checkout:o,i18n:r,shop:s,shopPay:a,url:d,router:c,observability:l,activeTool:u,onActiveToolCreated:p,getPreactContext:h,markToolCallStarted:m,getSavedCardSelector:v,declaredFields:f,getFulfillmentProvider:A,getStoreCreditProvider:L,unregisterInitializingTool:E}){if(t.aborted)return;const g=vi({checkout:o,shopPay:a}),S=P=>ri({checkout:o,i18n:r,shop:s,router:c,readMode:P,savedCards:g(),declaredFields:f,paymentInstrument:i.value}),y=mi(o);f.set(y.key,y);const I=hi(()=>L?.());f.set(I.key,I);const w=u??new Zt;p?.(w);const R=[{tool:Io(uo({checkout:o,readCheckout:S,observability:l}),l),signal:t}],Ee=Eo(o,t);Ee.aborted||R.push(...[bo({isSubmitting:n,paymentInstrument:i,signal:t,checkout:o,shop:s,shopPay:a,router:c,getSavedCardSelector:v,readCheckout:S,readSavedCards:g,observability:l,getPreactContext:h,declaredFields:f,getFulfillmentController:()=>{const P=A?.();return P?yi(P,o.proposal):void 0}}),so({isSubmitting:n,paymentInstrument:i,signal:t,checkout:o,shop:s,shopPay:a,readCheckout:S,readSavedCards:g,observability:l,getPreactContext:h,declaredFields:f})].map(P=>({tool:Ve(P,{activeTool:w,observability:l,checkout:o}),signal:Ee}))),vt({shop:s,url:d})&&R.push({tool:Ve(fo({checkout:o,shop:s,url:d,observability:l,signal:t,getPreactContext:h}),{activeTool:w,observability:l,checkout:o}),signal:t}),E?.();const bt=R.map(async({tool:P,signal:j})=>{try{return await e.registerTool({...P,execute(ne,At){return m(),P.execute(ne,At)}},{signal:j}),"registered"}catch(ne){return j.aborted?"withdrawn":(l.error(new To(P.name,ne)),"failed")}});return Promise.all(bt).then(P=>{t.aborted||l.log("web_mcp_tools_registered","[WebMcp] tools registered",{registered:P.filter(j=>j==="registered").length,failed:P.filter(j=>j==="failed").length})}).catch(()=>{}),w}const Mo=Object.freeze(Object.defineProperty({__proto__:null,registerWebMcpTools:So},Symbol.toStringTag,{value:"Module"}));export{Re as n,Mo as w};

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.