PageSourceSearch

https://www.zip2tax.com/cdn/shopifycloud/checkout-web/assets/c1/6f1b819b.BzY-omxL.js

js zip2tax.com collected 2026-10-01 13:03:26 UTC 88,806 bytes, 1 lines download raw bytes

1import{c as Dt,j as nt,n as G,a as Nt,b as Rt}from"./2c1ab0fe.DYQSH7bT.js";import{s as Te,c as he,a as Ae,R as Se,b as Ot,i as x,d as Ut,n as ke,r as xt,e as it,f as Ft,g as $t,h as qt,C as Ht,V as ne,p as jt,j as Bt,k as Gt,U as Yt,l as Wt,m as zt,o as Vt,q as Xt,F as Kt,t as Jt,u as Re,v as Oe,w as Zt,x as Qt,y as en,z as tn,A as nn,B as on}from"./4c290a1e.CvCmFIo_.js";import{c as rn,i as sn,a as an}from"./65f3d4da.CPQqj7Ry.js";import{c as dn}from"./cadec7c0.DuUayRsU.js";import{i as ln}from"./8599b02a.CeEg7uRS.js";import{s as cn}from"./08a3b809.Bq-zVo5U.js";import{a as $,i as un}from"./6a2fc6d6.B_7pa-ZL.js";class pn{#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)}}}const fn=["buyer_action_required","checkout_busy","completion_failed","completion_in_progress","internal_error","invalid_request","navigation_failed","rejected","update_failed"];function hn(e){return fn.includes(e)}function S(e){return typeof e=="object"&&e!==null&&"error"in e}const me=Symbol("WebMcpFailureDetails");function mn(e){if(!S(e))return;const t=e.error;if(!(typeof t!="object"||t===null||!(me in t)))return t[me]}function v(e,t,n){const i={code:e,message:t};return n&&Object.defineProperty(i,me,{value:n}),{error:i}}function R(e){return`Do not attempt to ${e} by interacting with the page.`}const Pe="Retry shortly.",ot=`Checkout is still initializing. ${Pe}`,K="Nothing was applied.",yn="Call get_checkout before retrying.",_n="Correct the input and retry.",gn=`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. ${R("update the checkout")}`,vn=`Checkout completion could not be confirmed. Call get_checkout for the current state and its messages before retrying. ${R("complete the checkout")}`;function re(e,t,n,i=yn){return v(e,`${t}: ${n} ${K} ${i}`)}function rt(e,t){return v("invalid_request",`${e.message} ${_n} ${R(t)}`,{invalidInputPath:e.loggablePath.replace(/\[\d+\]/g,"[]"),invalidInputExpected:e.expected})}function bn(){return v("checkout_busy","Another checkout tool is running. Wait for it to finish before retrying.")}function En(){return v("internal_error",`Checkout data is not available yet. ${Pe} ${R("read checkout state")}`)}function In(){return v("internal_error",`Unable to read the checkout. ${R("read checkout state")}`)}function Ue(){return v("internal_error",`Checkout is not available for updates. ${Pe} ${R("update the checkout")}`)}function I(e="update_failed"){return v(e,gn)}function Cn(e){return v("update_failed",`Unable to update ${e}. Call get_checkout to review the checkout and its messages before retrying. ${R("update the checkout")}`)}function xe(e){return v("rejected",`The selected delivery option does not support selected_option_details.${e}. ${K} Remove ${e} from selected_option_details or choose an option that supports it, then retry. ${R("update the checkout")}`)}function Tn(e,t,n){const i=n?` Supported countries: ${n.join(", ")}.`:"";return v("rejected",`${e} ${t} is not a country this shop ships to. ${K}${i} Tell the buyer. ${R("update the checkout")}`)}const st=`${K} 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. ${R("update the checkout")}`;function An(){return v("rejected",`fulfillment.methods[].groups[] does not match a delivery group in the current checkout. ${st}`)}function Sn(){return v("rejected",`fulfillment.methods[].groups[] has no selectable delivery option in the current checkout. ${K} Send the update without groups, then choose an option from the next get_checkout. ${R("update the checkout")}`)}function kn(){return v("rejected",`fulfillment.methods[].groups[].selected_option_id is not an option for this group in the current checkout. ${st}`)}function U(e){return re("rejected","fulfillment",e)}function de(e,t){return re("rejected",e,`${t}.`)}function Pn(){return re("update_failed","context","Pickup locality lookup is unavailable.",`Call get_checkout and retry with the latest checkout. ${R("update the checkout")}`)}function wn(){return re("rejected","context","Could not resolve a unique postal locality.","Check address_country, address_regi
1on and postal_code, then retry.")}function Y(){return v("completion_in_progress","A credentialed completion is in progress. Wait for it to finish before updating payment.")}function Ln(){return v("invalid_request","This checkout does not accept the supplied payment handler. Call get_checkout for the current checkout state.",{invalidInputPath:"payment.instruments[].handler_id",invalidInputExpected:"a handler this checkout accepts"})}function Mn(){return v("completion_in_progress","A checkout completion is already in progress. Wait for it to finish, then call get_checkout before retrying.")}function Dn(){return v("buyer_action_required","The buyer must manually complete checkout on the page. Do not attempt to complete checkout on their behalf.")}function le(){return v("internal_error",`${ot} ${R("complete the checkout")}`)}function Z(e="completion_failed",t){return v(e,vn,t)}function Nn(){return v("invalid_request","This checkout requires no payment. Retry complete_checkout without the payment field.",{invalidInputPath:"input.payment",invalidInputExpected:"no payment"})}function Rn(){return v("invalid_request","navigate_to_storefront takes no input. Retry with an empty object.",{invalidInputPath:"input",invalidInputExpected:"an empty object"})}function On(){return v("internal_error",ot)}function Un(){return v("navigation_failed","Checkout updates are still pending. Navigation was not started. Retry after updates finish.")}function xn(){return v("navigation_failed","Unable to navigate to the storefront. Refresh the available tools and check the current page before retrying.")}function Fe(){return v("navigation_failed","Navigation was cancelled. The tool did not leave checkout.")}function $e(){return v("checkout_busy","Checkout submission or payment is in progress. Wait for it to finish and call get_checkout before navigating away.")}function Fn(){return v("navigation_failed","A supported storefront destination is not available. Stay on the current checkout.")}function $n(e){return Array.from(e.values()).flatMap(t=>{const n=t.read();return n?[n]:[]}).sort((t,n)=>qn(t.key,n.key))}function qn(e,t){return e===t?0:e<t?-1:1}function Q(e,t){const n=e??[],i=new Map;for(const[r,{key:s,value:a}]of n.entries()){const d=`$.checkout.declared_fields[${r}]`,l=t.get(s);if(!l?.read())return de(`${d}.key`,"must identify a declared field available in the current checkout");const c=l.prepare(a);if("requirement"in c)return de(`${d}.value`,c.requirement);i.set(s,c)}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 de("$.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 Hn(e){const{email:t,phone:n}=e??{};if(!(!t&&!n))return{...t?{email:t}:{},...n?{phone_number:n}:{}}}function M(e){if(!e)return 0;const t=Dt(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 jn(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=Bn(r,n);a.amount>0&&o.push(a)}}return{codes:[...i.values()],applied:o}}function Bn(e,t){const{discount:n}=e,i=[];let o=0,r=!1;for(const{target:d}of e.allocations){let l=d.index;if(d.type==="MERCHANDISELINE"&&t&&(l=d.stableId==null?void 0:t.get(d.stableId),l==null)){r=!0;continue}const c=M(d.amount);o+=c,d.type==="MERCHANDISELINE"&&l!=null?i.push({path:`$.line_items[${l}]`,amount:c}):d.type==="DELIVERYLINE"&&i.push({path:"$.totals.shipping",amount:c})}const s=n.type==="code"&&n.codeHidden,a=r?0:M(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 ie(e,{extendedAddressMode:t}){const n=e.address_country?.toUpperCase()??"",i=t.get(n),o=i===null?Gn(n,e):Yn(n,e,i);return{...dn({...e,street_address:o.address1,extended_address:o.address2}),company:e.company??"",district:void 0,subdistrict:void 0,...o}}function we(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?Vn(n,e):Kn(n,e,i),address_locality:e.city,address_regi
1on:e.zoneCode,address_country:e.countryCode,postal_code:e.postalCode}}function at({street_address:e="",street_name:t,street_number:n=""}){return t?.trim()?{streetName:t,streetNumber:n}:{line:e}}function Gn(e,t){const n=at(t);return{address1:"line"in n?n.line:Qn(e,n),address2:t.extended_address??""}}function Yn(e,t,n){const{packedLine2:i,...o}=Wn(e,at(t)),{neighborhood:r,...s}=zn(e,t,i);return{...o,...s,...n==="dedicated"?r!==void 0&&{district:r,neighborhood:""}:{neighborhood:r}}}function Wn(e,t){if("line"in t){const i=Te(e,t.line,!0);if(!i?.streetNumber)return{address1:t.line};const o=he({countryCode:e,streetName:i.streetName??"",streetNumber:i.streetNumber});return o==null?{address1:t.line}:{address1:o,packedLine2:i.line2}}const n=he({countryCode:e,...t});return n==null?{address1:ut(t)}:{address1:n,...t}}function zn(e,{extended_address:t="",district:n},i){const o=Ae(e,t);if(!o)return{address2:qe(t,i)};const r=qe(o.line2??"",i),s=n??o.neighborhood??"";return{address2:ct(e,r,s),line2:r,neighborhood:s}}function qe(e,t){return!t||t===e.trim()?e:pt(e,t)}function Vn(e,t){return{street_address:dt(e,t),extended_address:Xn(e,t)}}function dt(e,{address1:t,streetName:n,streetNumber:i}){return t||!(n||i)?t:lt(e,{streetName:n??"",streetNumber:i??""})}function Xn(e,{address2:t,line2:n,district:i,neighborhood:o}){const r=i||o;return n==null&&!r?t:ct(e,n??"",r??"")}function Kn(e,t,n){const i=Jn(e,t,n);return{...i?.streetName?{street_name:i.streetName,street_number:i.streetNumber??""}:{street_address:dt(e,t)},...Zn(e,t,n)}}function Jn(e,t,n){return n==="dedicated"&&(t.streetName!=null||t.streetNumber!=null)?t:t.address1?.includes(Se)?Te(e,t.address1):null}function Zn(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(Se)?Ae(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 lt(e,t){return he({countryCode:e,...t})??ut(t)}function ct(e,t,n){return Ot({countryCode:e,line2:t,neighborhood:n})??pt(t,n)}function Qn(e,t){return ei(lt(e,t))}function ut({streetName:e,streetNumber:t}){return[t,e].filter(Boolean).join(" ")}function pt(e,t){return[e,t].filter(Boolean).join(", ")}function ei(e){return e.split(Se).join("")}function ti(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}=ii(o.lineAllocations),l=[];n+=d,s&&l.push({type:"subtotal",amount:M(s)}),a!==0&&s&&(t+=a,l.push({type:"items_discount",amount:M({...s,amount:-a})}));const c=s?{...s,amount:s.amount-a}:o.totalPrice;return l.push({type:"total",amount:M(c)}),{id:A(o),...o.parentRelationship?.parent?.stableId?{parent_id:o.parentRelationship.parent.stableId}:{},quantity:o.quantity,item:{id:o.variantId??o.stableId,title:o.title,price:M(r),...o.image?.url?{image_url:o.image.url}:{}},totals:l}}),itemsDiscountAmount:t,cartLevelDiscountAmount:n}}function se(e){return e?.flatMap(t=>(t.lineComponents.length?t.lineComponents:[t]).filter(n=>n.requiresShipping).map(A))??[]}function ni(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 A(e){return e.stableId}function ii(e){let t=0,n=0;for(const i of e)for(const{discountDetails:o,amount:r}of i.allocations)oi(o.discount)?n+=r.amount:t+=r.amount;return{lineLevel:t,cartLevel:n}}function oi(e){return"presentationLevel"in e&&e.presentationLevel==="CART"}function ee(e){return e==="SHIPPING"||e==="LOCAL"||x(e)}function ri(e,t,n){return!!(e&&!n&&(t.some(i=>!ee(i))||t.some(x)&&t.some(i=>i==="SHIPPING"||i==="LOCAL")))}function si(e,t,n){return!n||e===t}function oe(e,t){switch(t){case"phone_number":return!!e.phoneRequired;case"instructions":return!!e.acceptsInstructions}}function z(e,t){if(!e?.length||!t?.length)return!1;const n=new Set(t),i=e.filter(o=>o.requiresShipping).map(o=>A(o));return i.length===n.size&&i.every(o=>n.has(o))}const ye="pickup";function V(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 x(n)?"pickup":"shipping"}function ft(e){const t=e.filter(r=>V(r)==="pickup"),n=t.map(r=>{const s=new Map;for(const a of r.methods){if(!a.pickupLocation)continue;const d=ai(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,l]of t.entries()){const c=n[d].get(r);if(!c)break;a.push({line:l,method:c})}a.length===t.length&&o.push({id:s.handle,selections:a})}return o}function ai(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 di(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})=>Ut(r,t)):void 0;return{destinations:i,selectedDestinationId:o?.id}}function li(e){const t=ui(e);return t.length?{methods:t}:void 0}function ci(e){const{deliveryNext:t}=e;if(t?.status!=="filled"||!t.lines)return;const n=[];let i;for(const r of t.lines){if(r.status!=="available"||!r.selectedDeliveryMethodHandle)continue;const s=ke(r);s?.cost&&(n.push({cost:s.costAfterDiscounts.amount,costBeforeDiscounts:s.cost.amount,rateGroupKey:s.methodType==="SHIPPING"?xt({line:r,method:s,localShopId:e.shopId,marketDrivenShippingEnabled:e.marketDrivenShippingEnabled,remoteShopsConfigMap:e.remoteShopsConfigMap,remoteMerchandiseDetails:e.remoteMerchandiseDetails}):void 0}),i??=s.cost.currencyCode)}if(i==null)return;const{priceBeforeDiscounts:o}=rn(n,({rateGroupKey:r})=>r);return{amount:o,currencyCode:i}}const Le=we;function ui(e){const{deliveryNext:t}=e;if(e.readMode!=="proposed"&&(t?.status!=="filled"&&t?.status!=="partial"||!t.lines))return He(e);const n=(t?.status==="filled"||t?.status==="partial")&&t.lines?t.lines.filter(Ei):[],o=(e.readMode==="proposed"?gi(n,e.proposedDeliveryLines,e.merchandiseLines):n).filter(d=>(d.proposedLine?d.proposedLine.deliveryMethodTypes.some(je):d.methods.some(l=>je(l.methodType)))&&d.targetMerchandiseLines?.some(l=>l.requiresShipping));if(e.readMode==="proposed"&&!o.length)return He(e);const r=t?.status==="partial"?ht(e,o):new Map,s=new Set([...pi(o),...r.keys()]),a=[];for(const d of s){const l=o.filter(p=>V(p)===d),c=l.map(p=>_i(p,p.proposedLine?[p.proposedLine]:e.proposedDeliveryLines)),u=[...new Set([...c.flatMap(p=>p.line_item_ids),...r.get(d)??[]])];a.push({id:d,type:d,line_item_ids:u,destinations:[],...fi(d,l,e),groups:c})}return a}function ht(e,t){const n=new Set(t.flatMap(r=>r.targetMerchandiseLines?.map(A)??[])),i=new Map,o=new Set;for(const r of e.merchandiseLines??[]){if(e.readMode!=="proposed"&&!r.requiresShipping)continue;const s=A(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(A(u))).map(A));if(!a.size)continue;const d=e.proposedDeliveryLines?.filter(u=>u.targetMerchandiseLines.some(p=>A(p)===s||a.has(A(p)))).flatMap(u=>u.deliveryMethodTypes),l=d?.length&&d.every(x)?"pickup":"shipping",c=i.get(l)??[];c.push(...e.readMode==="proposed"?a:[s]),i.set(l,c)}return i}function He(e){return[...ht(e,[])].map(([n,i])=>({id:n,type:n,line_item_ids:i,destinations:[],...n==="shipping"?mt(e):{},groups:[]}))}function pi(e){const t=new Set;for(const n of e){const i=V(n);i&&t.add(i)}return Array.from(t)}function je(e){return e==="SHIPPING"||e==="LOCAL"||x(e)}function fi(e,t,n){if(e==="shipping")return mt(n);const i=ft(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=hi(s[0].method,n.addressContext);return a?[{...a,id:r}]:[]}),...o&&{selected_destination_id:o.id}}}function mt({savedDestinations:e,shippingAddress:t,addressContext:n}){if(e===void 0)return t&&it(t)?{destinations:[mi(t,n)]}:{};const{destinations:i,selectedDestinationId:o}=di(e,t);return i.length?{destinations:i.map(({id:r,address:s})=>({id:r,type:"shipping_address",...Le(s,n)})),...o&&{selected_destination_id:o}}:{}}function hi(e,t){const{pickupLocation:n}=e;if(n)return{id:e.handle,type:"business_location",name:n.name??"",pickup_location_address:Le(n.address,t)}}function mi(e,t){return{...Le(e,t),id:yi(e),type:"shipping_address"}}function yi(e){return["shipping",e.countryCode,e.postalCode].filter(
1Boolean).join("-").replace(/\s+/g,"")}function _i(e,t){const n=yt(e),i=ke(e),o=e.proposedLine?e.selectedDeliveryMethodHandle:i?.handle,r=o?vi(e,n,t):void 0,s=V(e)==="pickup",a=s?[{...i?Be(i):{totals:[]},id:ye,title:"Pickup"}]:e.methods.filter(({methodType:d})=>d==="SHIPPING"||d==="LOCAL").map(Be);return{id:e.id??"",line_item_ids:n,options:a,...o&&{selected_option_id:s?ye:o},...r&&{selected_option_details:r}}}function gi(e,t,n){const i=new Map;for(const o of n??[]){i.set(A(o),se([o]).length>0);for(const r of o.lineComponents)i.set(A(r),r.requiresShipping)}return(t??[]).map(o=>{const r=o.targetMerchandiseLines.filter(a=>a.requiresShipping).map(a=>A(a)),s=e.find(a=>o.id!==void 0&&a.id===o.id)??e.find(a=>a.type===o.type&&z(a.targetMerchandiseLines,r));return{...s,status:"available",id:o.id,type:o.type,targetMerchandiseLines:o.targetMerchandiseLines.flatMap(a=>{const d=i.get(A(a));return d===void 0?[]:[{...a,requiresShipping:d}]}),selectedDeliveryMethodHandle:o.deliveryMethodHandle,methods:s?.methods.filter(a=>o.deliveryMethodTypes.includes(a.methodType))??[],proposedLine:o}})}function vi(e,t,n){const i=bi(e,n,t);if(!i||!e.selectedDeliveryMethodHandle||i.deliveryMethodHandle!==e.selectedDeliveryMethodHandle)return;const o=i.deliveryMethodOptions;if(!o)return;const r=ke(e),s=r&&!oe(r,"phone_number")?void 0:o.phone,a=r&&!oe(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 bi(e,t,n=yt(e)){return t?.find(i=>!!e.id&&i.id===e.id)??t?.find(i=>z(i.targetMerchandiseLines,n))}function yt(e){return e.targetMerchandiseLines?.filter(t=>t.requiresShipping).map(t=>A(t))??[]}function Be(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:x(e.methodType)?"Pickup":"Shipping",amount:M(e.costAfterDiscounts)}]}}function Ei(e){return e.status==="available"}const Ii=new Map([["terms-of-service","terms_of_service"],["privacy-policy","privacy_policy"],["refund-policy","refund_policy"],["shipping-policy","shipping_policy"]]);function Ci(e){const t=[];for(const{handle:n,url:i}of e){const o=Ii.get(n);o&&t.push({type:o,url:i})}return t}function Ti(e){if(e?.status!=="processed")return;const t=e.orderIdentity.buyerIdentifier,n=Ft(e.orderIdentity.id);return{...n?{id:$t("Order",n)}:{},...t?{label:t}:{},permalink_url:e.confirmationPage.url}}function Ai(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:we(e,t)}]:[]}}function Si(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 ki={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 Pi(e){return ki[e]}const wi=new Set(["AcceptNewTermViolation","RequiredArtifactsUnavailableViolation"]),Li=new Set(["PendingTermViolation"]),Mi=new Set(["PAYMENTS_UNACCEPTABLE_PAYMENT_AMOUNT"]),Di={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 Ni(e){const{receipt:t,isShippingRequired:n,hasShippingAddress:i,deliveryNext:o,skipsShippingAddress:r=qt(o)}=e,s=Ri(e),a=Ui({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(Di),{status:a,messages:s}}function Ri(e){const t=[];for(const n of e.violations??[]){if(wi.has(n.__typename)||Mi.has(n.code)||e.requiresCaptcha&&Ht.has(n.code))continue;const i=n.code.startsWith("DISCOUNTS_"),o=i||Li.has(n.__typename),r=Pi(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:Oi(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 Oi(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 Ui({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 xi({subtotal:e,itemsDiscountAmount:t,cartLevelDiscountAmount:n,discountLines:i,fulfillmentTotal:o,tax:r,duty:s,dutiesIncluded:a,runningTotal:d}){const l=[];return e!=null&&(l.push({type:"subtotal",display_text:"Subtotal",amount:M(e)}),l.push(...Fi({currencyCode:e.currencyCode,discountLines:i,itemsDiscountAmount:t,cartLevelDiscountAmount:n}))),o!=null&&l.push({type:"fulfillment",display_text:"Shipping",amount:M(o)}),s!=null&&!a&&l.push({type:"duty",display_text:"Duties",amount:M(s)}),r!=null&&l.push({type:"tax",display_text:"Taxes",amount:M(r)}),d!=null&&l.push({type:"total",display_text:"Total",amount:M(d)}),l}function Fi({currencyCode:e,discountLines:t,itemsDiscountAmount:n,cartLevelDiscountAmount:i}){let o=i;for(const s of t?.lines??[])if(sn(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:M({amount:-n,currencyCode:e})}),o>0&&r.push({type:"discount",display_text:"Discount",amount:M({amount:-o,currencyCode:e})}),r}function $i(e){const t=e.merchandiseLines?.lines;if(!t||!ji(t)||e.runningTotal==null)return;const n=e.readMode==="proposed"&&t.length===0?{...e.runningTotal,amount:0}:ni(t)??e.subtotal;if(n==null)return;const{lineItems:i,itemsDiscountAmount:o,cartLevelDiscountAmount:r}=ti(t),s=ci(e),a=e.receipt?.status==="processed"&&e.receipt.isRedacted?void 0:Hn(e.contactInfo),d=jn(e.discountLines,e.readMode==="proposed"?i:void 0),l=li({readMode:e.readMode,deliveryNext:e.deliveryNext,shippingAddress:e.shippingAddress,merchandiseLines:t,savedDestinations:e.savedDestinations,addressContext:e.addressContext,proposedDeliveryLines:e.proposedDeliveryLines}),{status:c,messages:u}=Ni({i18n:e.i18n,requiresBuyerReview:e.buyerReviewUrl!=null,requiresCaptcha:e.requiresCaptcha,violations:e.violations,receipt:e.receipt,isShippingRequired:e.readMode==="proposed"?se(t).length>0:e.isShippingRequired,hasShippingAddress:e.readMode==="proposed"?it(e.shippingAddress):e.shippingAddress!=null,deliveryNext:e.deliveryNext,skipsShippingAddress:e.readMode==="proposed"?Hi(l,t):void 0,hasUnselectableShippingGroup:qi(l,t,e.readMode)}),p=Ti(e.receipt),f=Ai(e.billingAddress,e.addressContext,e.savedCards),y=Si(e.savedCards??[]),b=[...u,...y];return{...e.id?{id:e.id}:{},...e.continueUrl?{continue_url:e.continueUrl}:{},currency:e.runningTotal.currencyCode,status:c==="ready_for_complete"&&y.length?"incomplete":c,...c==="requires_escalation"&&e.buyerReviewUrl?{continue_url:e.buyerReviewUrl}:{},links:Ci(e.merchantPolicies),line_items:i,totals:xi({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},...l&&{fulfillment:l},payment:f,...b.length?{messages:b}:{},...p&&{order:p}}}
1function qi(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=se([o]);return r.length>0&&!i.has(A(o))&&!r.every(s=>i.has(s))})}function Hi(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(A(i))||se([i]).every(o=>n.has(o)))}function ji(e){return e.every(t=>t.itemPrice!=null&&t.title!=null)}function Bi({checkout:e,i18n:t,shop:n,router:i,readMode:o="negotiated",savedCards:r,declaredFields:s=new Map,paymentInstrument:a}){const d=$i({...Yi(e,t,n,o,i),savedCards:e.isPaymentRequired.value?r:void 0});if(!d)return;const l=$n(s),c=d.payment.instruments[0],u={...d,...a?{payment:{instruments:[Gi(a,e,c&&"billing_address"in c?c.billing_address:{})]}}:{},...l.length>0?{declared_fields:l}:{}},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_region:p.zoneCode},postal_code:p.postalCode}}}function Gi(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 Yi(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,l=d?[...d.addresses.value,...d.immutableAddresses.value]:void 0,c=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??Vi(s.fields.taxes.value),duty:e.proposal.facts.duty??Xi(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,shopId:n.id,marketDrivenShippingEnabled:n.marketDrivenShippingEnabled,remoteShopsConfigMap:n.remoteShopsConfigMap,remoteMerchandiseDetails:s.fields.remoteMerchandiseDetails.value,shippingAddress:i==="proposed"?r.shippingAddress.value:c,billingAddress:e.identity.current.value==="shopPay"?void 0:Wi(e,n,i),addressContext:e.address,savedDestinations:l,proposedDeliveryLines:r.deliveryLines.value.map(f=>
1f.value),isShippingRequired:!!s.fields.isShippingRequired.value,violations:s.fields.allViolations.value,receipt:e.latestReceipt.value}}function Wi(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"?zi(e,t):e.proposal.negotiated.fields.billingAddress.value}function zi(e,t){const{proposed:n,negotiated:i,facts:o}=e.proposal,r=n.paymentLines.value;for(const{method:l}of r)if(l.type===ne.CreditCard||l.type===ne.PayPal)return l.billingAddress;const s=n.billingAddress.value,a=!s.address1&&o.billingAddress?o.billingAddress:s;if(n.billingAddressOption.value!=="shipping"||!i.fields.isShippingRequired.value||!jt(r))return a;const d=r[0]?.method;if(d?.type==="wallet"){const l=i.fields.runningTotal.value,c=l&&l.amount<=0,u=Bt(i.fields.merchandiseLines.value?.lines).some(f=>!!f.sellingPlan?.subscriptionDetails);if((!c||u||i.fields.deferredTotal.value?.amount.amount)&&(d.name==="GOOGLE_PAY"||d.name==="APPLE_PAY"||d.name==="PAYPAL_EXPRESS"&&an({checkout:e,shop:t,paymentMethods:i.fields.paymentMethods.value})))return a}return o.delivery?.[0]?.deliveryAddress??n.shippingAddress.value}function Vi(e){return e?.status==="available_total"?e.totalTax:void 0}function Xi(e){return e?.status==="available_total"?e.totalDuty:void 0}const Ge="store_credit",Ki=1e4;function Ji(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,Ki),o=nt(()=>{i.settling.value||s()})}).then(()=>{clearTimeout(r),o()})};return{key:Ge,read(){const i=e();if(i?.available.value)return{key:Ge,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 Ye="tax_number",Zi=["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 Qi(e){const t={key:Ye,read(){const n=We(e);if(!n)return;const{title:i,value:o,required:r}=n.fields;return{key:Ye,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=We(e);if(!i)return!1;const{value:o}=i.fields;return o.value=n??"",!0}}}};return t}function We(e){const n=e.proposal.proposed.localizationExtensions.value.flatMap(i=>Zi.some(r=>r===i.fields.key.value)?[i]:[]);return n.length===1?n[0]:void 0}function Me(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 _e(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 eo(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=Me(t.merchandiseLines.value,r);if(!to(o,n)){e.applyMethodChange(n,o,i);return}G(()=>{for(const a of t.deliveryLines.value){const d=a.value;d.targetMerchandiseLines.some(({stableId:l})=>s.has(l))&&(d.deliveryMethodTypes.length!==n.length||d.deliveryMethodTypes.some(l=>!n.includes(l)))&&(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 to(e,t){return e.length>0&&e.every(n=>n==="SHIPPING"||n==="LOCAL"?t.includes("SHIPPING")||t.includes("LOCAL"):t.includes(n))}function no(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 J(e,t){return{...e,ucp:no(S(e)?"error":"success",t.proposal.negotiated.fields.ucp.value?.paymentHandlers)}}class io{#e;#t;#n;#i=!1;#r=!1;#s=!1;constructor({observability:t,checkout:n}){this.#e=t,this.#t=n,this.#n=n.latestReceipt.peek()?.status==="processed"}log({name:t,message:n,attributes:i}){this.#e.log(t,n,i)}error({error:t,...n}){this.#e.error(t,n)}histogram(t){this.#e.histogram(t)}initialized(){this.#o("web_mcp_initialized")}toolCalled(t){this.#i||(this.#i=!0,this.#o("web_mcp_tool_called",{tool:t})),!this.#r&&(t==="update_checkout"||t==="complete_checkout")&&(this.#r=!0,this.#o("web_mcp_write_tool_called",{tool:t})),!this.#s&&t==="complete_checkout"&&(this.#s=!0,this.#o("web_mcp_complete_checkout_called"))}#o(t,n={}){this.#n||this.#e.counter({name:t,value:1,attributes:{...n,identity:this.#t.identity.current.peek()}})}}function oo({checkout:e,shopPay:t}){const n=cn({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(Gt).filter(({id:c})=>c!==Yt).sort(Wt),a=zt(s,n.value),d=t.session.selectedPaymentMethod.value,l=e.proposal.proposed.paymentLines.value.some(({method:c})=>c.type==="wallet"&&c.name==="SHOP_PAY");return s.map(c=>{const u=c.paymentAttributes;return{instrument:{id:c.id,type:"card",selected:l&&d?.paymentMethod==="CREDIT_CARD"&&d.id===c.id,display:{brand:u.brand,last_digits:u.lastDigits}},usable:!u.expired&&u.verified&&a.includes(c)&&!ln(u,i,o,r)}})}}function ze(e){return e?.replace(/[\s-]/g,"").toUpperCase()}function ro(e,t){return!!e?.coordinates&&e?.countryCode===t.countryCode&&(!t.zoneCode||e.zoneCode===t.zoneCode)&&ze(e.postalCode)===ze(t.postalCode)}function ce(e,{checkout:t},n){const i=e.fulfillmentMethods.methods;if(i.length>1)return U("At most one fulfillment method is supported.");const o=i[0];if(o?.id!==void 0&&o.id!==o.type)return U("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(h=>h.value),d=Me(r.merchandiseLines.value,a),l=_e(a,d);if(l.some(x)&&l.some(ue)){const h=s.fields.deliveryNext.value,C=h?.status==="filled"||h?.status==="partial"?h.lines.filter(g=>g.status==="available"):[],N=a.map(g=>{const T=(C.find(({id:O})=>!!g.id&&O===g.id)??C.find(O=>z(O.targetMerchandiseLines,g.targetMerchandiseLines.filter(w=>w.requiresShipping).map(A))))?.methods.find(({handle:O,methodType:w})=>O===g.deliveryMethodHandle&&g.deliveryMethodTypes.includes(w))?.methodType??(g.deliveryMethodHandle?void 0:g.deliveryMethodTypes[0]);return T?{...g,deliveryMethodTypes:[T]}:g}),k=_e(N,d);if(k.some(x)&&k.some(ue))return U("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 c=o?.type??(l.length&&l.every(x)?"pickup":void 0),u=!!(e.context&&!ge(r.locationAddress.value,e.context));if(u&&c!=="pickup")return U("Changing context locality requires a pickup method.");if(!o&&c!=="pickup")return;const p=h=>c==="pickup"?x(h):ue(h);if(o&&(o.selected_destination_id!==void 0||o.groups.length))return u||l.length&&!l.some(p)?U("Change the method/search origin first, then select a destination or option returned by that update."):void 0;if(c==="pickup"&&l.length&&l.every(h=>h==="PICKUP_POINT"))return u?U("Pickup-point locality discovery is not supported. Select an existing destination instead."):void 0;if(!d.size)return U("This checkout has no physical items to fulfill.");if(c==="pickup"&&e.context){const h=r.shippingAddress.value?.countryCode||r.locationAddress.value?.countryCode;if(!h)return U("Pickup search requires an established checkout country. Ask the buyer to choose a country in checkout.");if(e.context.address_country!==h)return U("Pickup search must remain in the checkout country.")}if(!n&&!u&&l.every(p)&&l.length)return;const f=!l.length||!l.every(p);if(!n&&f)return U("The delivery selector is not ready.");const y=n?n.getAvailableMethodTypes().find(h=>c==="pickup"?h.includes("PICK_UP"):h.some(p)):l;if(!y)return U(`The checkout does not offer ${c}.`);const b=s.fields;return(f||u)&&(b.mustSelectProvidedShippingRate.value||b.mustSelectProvidedAddress.value||b.canUpdateDeliveryAddress.value===!1)?U("The checkout locks its delivery method or address."):{methodTypes:y,needsLocalityLookup:u,changesMo
1de:f}}function ue(e){return e==="SHIPPING"||e==="LOCAL"}function ge(e,t){return ro(e,{countryCode:t.address_country,zoneCode:t.address_region,postalCode:t.postal_code})}const j={status:"written"};function so(e){return e.paymentLines.value.some(t=>t.method.type===ne.CreditCard||t.method.type===ne.PayPal||ao(t))}function ao(e){if(e.method.type!=="wallet")return!1;switch(e.method.name){case"APPLE_PAY":return tn(e);case"GOOGLE_PAY":return en(e);case"PAYPAL_EXPRESS":return Qt(e);default:return!1}}const lo=({buyer:e},{checkout:t,shopPay:n})=>{const i=un({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,j}}},_t=({shippingAddress:e},t)=>{if("saved_address_id"in e)return uo(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=Et(e.address_country,"fulfillment.methods[0].destinations[0].address_country",t.shop);if(a)return a;const d=ie(e,n.address);return{status:"ready",negotiation:{include:["shippingAddress","deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["shippingAddress","deliveryNext"]},async apply(){const l=await r.applyAddressChange({source:"ucp",address:d});return l.type!=="success"?(i.log({name:"web_mcp_address_change_declined",message:"[WebMcp] address manager declined an admitted address",attributes:{reason:l.reason}}),{status:"failed"}):(o(),j)}}};function Ve(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)?j:{status:"failed"}}}:{status:"rejected",field:"payment"}}function co(e,{readSavedCards:t}){return!!t()?.some(({instrument:n,usable:i})=>n.id===e&&n.selected&&i)}function uo(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=Et(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(),j):{status:"failed"}}}}function ve({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(To):[],a=new Map;for(const l of i.deliveryLines.peek()){const{id:c,targetMerchandiseLines:u,deliveryMethodTypes:p,deliveryMethodHandle:f}=l.peek();if(p.filter(ee).length===0)continue;const h=(s.find(C=>!!c&&C.id===c)??s.find(C=>z(C.targetMerchandiseLines,u.filter(N=>N.requiresShipping).map(A))))?.methods.find(C=>C.handle===f);if(h){if(!ee(h.methodType))continue}else if(ri(f,p,h))return{status:"rejected",field:"fulfillmentMethods"};a.set(l,{deliveryLine:l,selectedOptionId:void 0,selectedOptionDetails:void 0})}try{for(const l of bo(e,i.deliveryLines.peek(),s))a.set(l.deliveryLine,l)}catch(l){if(!(l instanceof F))throw l;return{status:"rejected",field:"fulfillmentMethods",reason:l.reason}}const d=o.fields.mustSelectProvidedShippingRate.peek();return[...a.values()].some(({deliveryLine:l,selectedOptionId:c})=>!si(l.peek().deliveryMethodHandle,c,d))?{status:"rejected",field:"fulfillmentMethods"}:{status:"ready",negotiation:{include:["deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["deliveryNext"]},async apply(){for(const l of i.deliveryLines.value){const c=a.get(l);if(!c&&(!n||!l.value.deliveryMethodTypes.some(ee)))continue;
1const{selectedOptionId:u,selectedOptionDetails:p}=c??{};l.value={...l.peek(),deliveryMethodHandle:u,deliveryMethodOptions:Co(p),...u===void 0&&{isCustomRate:void 0,customDeliveryStrategy:void 0}}}return j}}}const po=({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(),l=o.get(d);l?l.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 l=o.get(d);l?r.push(...l):r.push({title:a,discount:{type:"discountCodeTrigger",title:a}})}return G(()=>{n.discountLines.value=r,n.reduction.value=void 0;const{discountCodeWarningSignal:a,currentDiscountCodeAttemptSignal:d}=t.negotiator.context;a.value=null,d.value=null}),j}}},fo=[lo,po,_t,ve];function Xe(e,t,{fulfillmentRequest:n,fulfillment:i,locationAddress:o}={}){const r=[];for(const s of fo){if(s===_t&&n){const{methodTypes:d}=n,{proposed:l}=t.checkout.proposal;r.push({status:"ready",negotiation:{include:["deliveryNext"],loading:["deliveryNext"],fieldsToResolve:["deliveryNext"]},async apply(){return i?i.setDesiredMethod(d,o):o&&(l.locationAddress.value=o),j}})}const a=s===ve?ve(e,t,n!==void 0):s(e,t);if(a!==void 0){if(a.status==="rejected")return vt(a.field,a.reason);r.push(a)}}return r}class gt{#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 S(r)?r:(G(()=>{r?.apply(),o?.apply()}),{status:"applied"})}#t(t){const{checkout:n}=this.#e;if(!$(n))return;const i=t===void 0?void 0:ie(t,n.address);return{apply({replacement:o=!1}={}){if(!$(n))return!1;const{proposed:r,negotiated:s,facts:a}=n.proposal,d=s.fields.isShippingRequired.value===!1;if(i&&!Vt(i)&&(d||!go(i,n)))return G(()=>{r.billingAddress.value=i,r.billingAddressOption.value="custom"}),!0;if(o&&d)return a.billingAddress||so(r)?!1:(G(()=>{r.billingAddress.value=ie({address_country:r.billingAddress.value.countryCode},n.address),r.billingAddressOption.value="custom"}),!0);const l=r.billingAddressOption.value;return r.billingAddressOption.value="shipping",i!==void 0||l!=="shipping"}}}#n(t){const{checkout:n,shop:i,paymentInstrument:o}=this.#e;if(!$(n)||!t&&!o.value)return;const{proposed:r,negotiated:s}=n.proposal,a=s.fields.paymentMethods.value,d=r.paymentLines.value.find(c=>!c.due&&c.method.type==="direct"),l=Xt(a??[],d?.method.type==="direct"&&!!d.method.alternative);return t&&(t.handler_id==="shopify.card"?!l:!i.hasFlagEnabled(Kt)||!Jt(a))?Ln():{apply(){$(n)&&G(()=>{const c=o.value;if(c?.handler_id==="shop_pay"&&c.credential?.approval_id&&(r.paymentLines.value=r.paymentLines.value.map(u=>u.method.type==="shopWallet"&&u.method.shopPayApprovalId===c.credential?.approval_id?{...u,method:{...u.method,shopPayApprovalId:void 0}}:u)),o.value=t,!!t){t.handler_id==="shopify.card"&&t.credential?.token&&l?(d?.method.type!=="direct"||d.method.paymentMethodIdentifier!==l.paymentMethodIdentifier)&&(r.paymentLines.value=Re(r.paymentLines.value,{method:{type:"direct",paymentMethodIdentifier:l.paymentMethodIdentifier,alternative:l.alternative}},Oe(i))):t.handler_id==="shop_pay"&&t.credential?.approval_id&&(r.paymentLines.value=Re(r.paymentLines.value,{method:{type:"shopWallet",shopPayApprovalId:t.credential.approval_id}},Oe(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,$(this.#e.checkout)?o:void 0]),n?.())return I();if(this.#e.isSubmitting.value)return Y();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 I();let s=Q(t.declaredFields,this.#e.declaredFields);if(S(s))return s;if(s.some(({changed:m})=>m)){if(await this.#e.waitForPendingNegotiations(),n?.())return I();if(this.#e.isSubmitting.value)return Y();if(s=Q(t.declaredFields,this.#e.declaredFields),S(s))return s}let a=this.#e.getFulfillmentController?.(),d=ce(t,this.#e,a);if(S(d))return d;let l;if(d?.needsLocalityLookup&&t.context){try{const m=this.#e.resolvePickupLocality;if(!m)throw new pe;l=await m(t.context)}catch(m){return this.#e.observability.error({error:m instanceof pe?m:new pe(m)}),n?.()?I():Pn()}if(n?.())return I();if(!l)return wn();if(s=Q(t.declaredFields,this.#e.declaredFields),S(s))return s}if(t.context){const m=this.#e.checkout.proposal.proposed.locationAddress.value;ge(m,t.context)&&(l=m)}if(a=this.#e.getFulfillmentController?.(),d=ce(t,this.#e,a),S(d))return d;let c=this.#t(o);const u=t.payment&&"handler_id"in t.payment?t.payment:void 0;let p=this.#n(u);if(S(p))return p;let f=r===void 0?void 0:Ve(r,this.#e);if(f?.status==="rejected")return vt(f.field);let y=Xe(t,this.#e,{fulfillmentRequest:d,fulfillment:a,locationAddress:l});if(S(y))return y;if(n?.())return I();const b=[];let h=!1;for(const m of["negotiate","stage"]){if(m==="stage"&&h&&(s=Q(t.declaredFields,this.#e.declaredFields),S(s)))return I();for(const T of s)if(!(T.phase!==m||!T.changed)){if(n?.())return I();try{if(!await T.apply()||n?.())return I()}catch{return I()}if(T.phase==="stage")b.push(T.negotiation);else if(h=!0,a=this.#e.getFulfillmentController?.(),d=ce(t,this.#e,a),S(d)||(y=Xe(t,this.#e,{fulfillmentRequest:d,fulfillment:a,locationAddress:l}),S(y))||(c=this.#t(o),p=this.#n(u),S(p))||(f=r===void 0?void 0:Ve(r,this.#e),f?.status==="rejected"))return I()}}if(p){const m=p;y.push({status:"ready",negotiation:{include:["paymentLines"],loading:["paymentLines"],fieldsToResolve:["paymentLines"]},async apply(){return m.apply(),j}})}if(!f&&y.length===0&&b.length===0&&!c)return{status:"applied"};if(n?.())return I();if(this.#e.isSubmitting.value)return Y();if((await Promise.all(G(()=>y.map(m=>m.apply())))).find(m=>m.status==="failed")||n?.())return I();if(this.#e.isSubmitting.value)return Y();if(f){if((await f.apply()).status==="failed"||n?.()||(await this.#e.waitForPendingNegotiations(),n?.()))return I();if(this.#e.isSubmitting.value)return Y()}const k=c?.apply({replacement:!0})??!1;if(!f&&y.length===0&&b.length===0&&!k)return{status:"applied"};const g=await this.#i(mo([...y.map(m=>m.negotiation),...b,...f?[f.negotiation]:[],...k?[{include:["billingAddress"],loading:["billingAddress"],fieldsToResolve:["billingAddress"]}]:[]]));await this.#e.waitForPendingNegotiations();const E=yo(g);if(r!==void 0&&!co(r,this.#e))return I();if(!S(E)&&!n?.()&&d?.needsLocalityLookup&&l&&t.context&&ge(this.#e.checkout.proposal.proposed.locationAddress.value,t.context)){const{proposed:m}=this.#e.checkout.proposal,T=m.deliveryLines.value.map(q=>q.value),O=Me(m.merchandiseLines.value,T),w=_e(T,O);w.length&&w.every(x)&&this.#e.announcePickupLocality?.(l)}return n?.()?I():E}async loadAddressMetadata(t){const n=new Set;for(const o of t){const r=o?.address_country?.toUpperCase();o&&r&&ho(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}}
1class pe extends Error{constructor(t){super("WebMCP pickup locality lookup failed",{cause:t}),this.name="WebMcpLocalityLookupError"}}function ho(e,t){const n=!!(t.street_address||t.street_name||t.street_number),i=!!(t.extended_address||t.district),o=Te(e,"")!==null,r=Ae(e,"")!==null;return n&&o||i&&r}function mo(e){return{include:fe(e,"include"),loading:fe(e,"loading"),fieldsToResolve:fe(e,"fieldsToResolve")}}function fe(e,t){return[...new Set(e.flatMap(n=>n[t]))]}function yo(e){return e?.status==="success"||e?.status==="error"?{status:"applied"}:I()}const _o={context:"context",buyer:"buyer",discountCodes:"discounts",declaredFields:"declared_fields",shippingAddress:"fulfillment",fulfillmentMethods:"fulfillment",payment:"payment"};function go(e,t){const n=we(t.proposal.proposed.shippingAddress.value,t.address);return Zt(e,ie(n,t.address))}function vt(e,t){return t instanceof bt?Tn(t.path,t.countryCode,t.listedCountryCodes):t==="unsupported_option_instructions"?xe("instructions"):t==="unsupported_option_phone"?xe("phone_number"):t==="unknown_fulfillment_group"?An():t==="unselectable_fulfillment_group"?Sn():t==="unknown_fulfillment_option"?kn():Cn(_o[e])}class F extends Error{constructor(t){super(t),this.name="WebMcpFulfillmentMethodUpdateError",this.reason=t}}const vo=20;class bt 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 Et(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 bt(i,t,n.length<=vo?n.map(({value:o})=>o):void 0)}}function bo(e,t,n){return e.methods.flatMap(i=>i.type==="pickup"?Eo(i,t,n):i.groups.map(o=>{const r=It(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||V(r)!=="shipping")throw new F("unknown_fulfillment_option");return be(r,s,o.selected_option_details,t)}))}function Eo(e,t,n){const i=e.selected_destination_id===void 0?void 0:ft(n).find(({id:r})=>r===e.selected_destination_id);if(e.selected_destination_id!==void 0&&!i)throw new F("unknown_pickup_destination");const o=new Map;for(const r of e.groups){if(r.selected_option_id!==ye)throw new F("unknown_fulfillment_option");const s=It(r,n);if(V(s)!=="pickup"||i&&!i.selections.some(a=>a.line===s)||o.has(s))throw new F("unknown_fulfillment_group");o.set(s,r)}return i?i.selections.map(({line:r,method:s})=>be(r,s,o.get(r)?.selected_option_details,t)):[...o].map(([r,s])=>{const a=r.methods.find(d=>d.handle===r.selectedDeliveryMethodHandle&&x(d.methodType)&&d.pickupLocation);if(!a)throw new F("unknown_pickup_destination");return be(r,a,s.selected_option_details,t)})}function It(e,t,n="unknown_fulfillment_group"){const i=t.find(o=>!!e.id&&o.id===e.id)??t.find(o=>z(o.targetMerchandiseLines,e.line_item_ids));if(!i)throw new F(n);return i}function be(e,t,n,i){const o=i.find(r=>!!e.id&&r.value.id===e.id)??i.find(r=>z(r.value.targetMerchandiseLines,e.targetMerchandiseLines?.filter(s=>s.requiresShipping).map(A)));if(!o)throw new F("unknown_fulfillment_group");if(!o.value.deliveryMethodTypes.includes(t.methodType))throw new F("unsupported_fulfillment_transition");return Io(t,n),{deliveryLine:o,selectedOptionId:t.handle,selectedOptionDetails:n}}function Io(e,t){if(t){if(t.instructions!==void 0&&!oe(e,"instructions"))throw new F("unsupported_option_instructions");
1if(t.phone_number!==void 0&&!oe(e,"phone_number"))throw new F("unsupported_option_phone")}}function Co(e){return{phone:e?.phone_number,instructions:e?.instructions}}function To(e){return e.status==="available"}const Ke=Rt()(["shipping","pickup"]);class _ extends Error{constructor(t,n,i,{loggablePath:o=t}={}){super(`${t}: expected ${n}, got ${i} instead.`),this.name="WebMcpInputError",this.expected=n,this.loggablePath=o}}const Ct='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.',Tt={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)."}},Ao={type:"object",description:`Replacement address. Include all fields to retain; omitted fields are cleared. Use PUT semantics, not PATCH. ${Ct}`,properties:Tt},te={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:Ao}}}}};function So(e,{ignorePayment:t=!1}={}){const n=D(e,"input");return Ie({object:n,allowedFields:["payment"],path:"input"}),t||n.payment===void 0?{}:{payment:At(n.payment,{path:"input.payment",requireCredential:!0})}}function At(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=jo(o.instruments,`${t}.instruments`);if(!n&&i)return No(s,r);const a=s.handler_id;if(!n&&a===void 0&&s.credential===void 0){const y=Je(s,r);return y===void 0?void 0:{billing_address:y}}if(a!=="shopify.card"&&a!=="shop_pay")throw new _(`${r}.handler_id`,"shopify.card or shop_pay","an unsupported handler");const d=H(s,{id:void 0,type:void 0},r),l=a==="shopify.card"?"card":"shop_pay";if(d.type!==void 0&&d.type!==l)throw new _(`${r}.type`,l,"an unsupported instrument type");const c=Je(s,r),u={id:d.id??nn(),...c===void 0?{}:{billing_address:c}},p=`${r}.credential`,f=!n&&s.credential===void 0?void 0:D(s.credential,p);if(a==="shopify.card"){if(f===void 0)return{...u,handler_id:a,type:"card"};if(Ie({object:f,allowedFields:["type","token"],path:p}),f.type!==void 0&&f.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||f.token!==void 0?{token:Ee(f.token,`${p}.token`)}:{}}}}if(f===void 0)return{...u,handler_id:a,type:"shop_pay"};if(Ie({object:f,allowedFields:["type","approval_id"],path:p}),f.type!==void 0&&f.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||f.approval_id!==void 0?{approval_id:Ee(f.approval_id,`${p}.approval_id`).trim()}:{}}}}function Ee(e,t){if(typeof e!="string"||e.trim().length===0)throw new _(t,"a non-empty string",P(e));return e}function Je(e,t){if(e.billing_address!==void 0)return H(e.billing_address,kt,`${t}.billing_address`)}function Ie({object:e,allowedFields:t,path:n}){if(Object.keys(e).some(i=>!t.includes(i)))throw new _(n,"only supported fields","extra properties")}
1const St={email:"",phone_number:""},W={first_name:"",last_name:"",phone_number:"",street_address:void 0,extended_address:void 0,address_locality:"",address_region:"",address_country:"",postal_code:""},kt={...W,company:void 0,street_name:void 0,street_number:void 0,district:void 0},Ze={phone_number:void 0,instructions:void 0};function ko(e,t={}){const n=Lo(e,t);return wo(Po(),n)}function Po(){return{buyer:{...St},discountCodes:[],declaredFields:[],shippingAddress:{...W},fulfillmentMethods:{methods:[]},payment:void 0}}function wo(e,t){return{...e,...t,buyer:{...e.buyer,...t.buyer}}}function Lo(e,t){const n=D(D(e,"input").checkout,"input.checkout"),i={};if(n.context!==void 0){const o="input.checkout.context",r=H(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=H(n.buyer,St,"input.checkout.buyer")),n.discounts!==void 0&&(i.discountCodes=Ro(n.discounts)??[]),n.declared_fields!==void 0&&(i.declaredFields=Do(n.declared_fields)),n.fulfillment!==void 0&&Object.assign(i,Oo(n.fulfillment)),!t.ignorePayment&&n.payment!==void 0&&(i.payment=At(n.payment,{path:"input.checkout.payment",savedPaymentMethodsOnly:t.savedPaymentMethodsOnly})),i}const Mo=new Set(["purpose","title","description","value_schema","presentation","required"]);function Do(e){const t="input.checkout.declared_fields";if(!Array.isArray(e))throw new _(t,"an array",P(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)&&!Mo.has(a))throw new _(`${r}.${a}`,"a declared field key or value","an unknown field",{loggablePath:r});if(typeof s.key!="string"||s.key.length===0)throw new _(`${r}.key`,"a non-empty string",P(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 No(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",{loggablePath:t});return{instrument_id:Ee(e.id,`${t}.id`)}}function Ro(e){const t="input.checkout.discounts",{codes:n}=D(e,t);if(n!==void 0){if(!Pt(n))throw new _(`${t}.codes`,"an array of strings",P(n));return n}}function Oo(e){const t="input.checkout.fulfillment",n=D(e,t);if(!Array.isArray(n.methods))throw new _(`${t}.methods`,"an array",P(n.methods));if(n.methods.length>1)throw new _(`${t}.methods`,"at most 1 fulfillment method",`${n.methods.length} methods`);let i={...W};const o=[];for(const[r,s]of n.methods.entries()){const a=`${t}.methods[${r}]`,d=D(s,a),l=Uo(d.type??"shipping",`${a}.type`),{id:c}=H(d,{id:void 0},a),u={...c!==void 0&&{id:c}},p=d.groups===void 0?[]:qo(d.groups,`${a}.groups`),f=Fo(d,a);switch(l){case"pickup":{f===void 0&&xo(d.destinations,`${a}.destinations`),o.push({...u,type:l,...f!==void 0&&{selected_destination_id:f},groups:p});break}case"shipping":{i=f===void 0?$o(d,a):{saved_address_id:f},o.push({...u,type:l,groups:p});break}default:Nt(l)}}return{shippingAddress:i,fulfillmentMethods:{methods:o}}}function Uo(e,t){const n=Ke.find(i=>i===e);if(n!==void 0)return n;throw new _(t,Ke.map(i=>JSON.stringify(i)).join(" or "),typeof e=="string"?JSON.stringify(e):P(e))}function xo(e,t){if(e!==void 0){if(!Array.isArray(e))throw new _(t,"an array",P(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',P(o.type))}}}function Fo(e,t){if(e.selected_destination_id===null)return;const{selected_destination_id:n}=H(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 $o(e,t){const n=`${t}.destinations[0]`,i=`${t}.destinations`,{destinations:o}=e;if(o===void 0)return{...W};if(!Array.isArray(o))throw new _(i,"an array",P(o));if(o.length===0)return{...W};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=H(r,kt,n);return{...W,...s,address_country:(s.address_country??"").trim()}}function qo(e,t){if(!Array.isArray(e))throw new _(t,"an array",P(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",P(s));const d=r.id;if(typeof d!="string")throw new _(`${o}.id`,"a string",P(d));const l=r.line_item_ids;if(l!==void 0&&!Pt(l))throw new _(`${o}.line_item_ids`,"an array of strings",P(l));const c={...Ze,...H(a===void 0?{}:a,Ze,`${o}.selected_option_details`)};return[{id:d,line_item_ids:l,selected_option_id:s,selected_option_details:c}]})}function D(e,t){if(!Ho(e))throw new _(t,"an object",P(e));return e}function Ho(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function jo(e,t){if(!Array.isArray(e))throw new _(t,"an array",P(e));if(e.length!==1)throw new _(t,"1 item",`${e.length} items`);return D(e[0],`${t}[0]`)}function H(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",P(s));o[r]=s}return o}function Pt(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function P(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"an array":typeof e=="object"?"an object":`a ${typeof e}`}const De="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.",Bo={type:"object",additionalProperties:!1,properties:{payment:{...te,required:["instruments"],properties:{instruments:{...te.properties.instruments,minItems:1,items:{...te.properties.instruments.items,required:["handler_id","credential"]}}}}}};class Go extends Error{constructor(){super("WebMCP complete_checkout failed"),this.name="WebMcpCompleteCheckoutError"}}function Qe(e){return!!(e?.handler_id==="shopify.card"?e.credential?.token:e?.credential?.approval_id)}function Yo(e){return e.status==="invalid"?e.reasons:"violations"in e?[...e.violations,...e.errors].map(({code:t})=>t):[]}function Wo(e){const t=Yo(e);return{progressionStatus:e.status,...t.length>0&&{progressionReasons:[...new Set(t)].sort().join(",")}}}function zo({isSubmitting:e,paymentInstrument:t,signal:n,checkout:i,shop:o,readCheckout:r,readSavedCards:s,shopPay:a,observability:d,getPreactContext:l,declaredFields:c}){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. ${De}`,inputSchema:Bo,annotations:{consequentialHint:!0,readOnlyHint:!1,untrustedContentHint:!0},execute:async f=>J(await p(f),i)};async function p(f){if(u||e.value)return Mn();u=!0;try{if(!o.hasFlagEnabled(on))return Dn();const{payment:y}=So(f,{ignorePayment:!$(i)}),b=i.latestReceipt.value?.status;if(b==="processing"||b==="processing_remote_checkouts"||b==="polling_for_order"||b==="processed"||b==="action_required")return r()??Z();const h=l();if(!h||n?.aborted)return le();if($(i)&&(y||t.value)){if(await h.waitForPendingNegotiations(),n?.aborted)return le();const E=$(i)?y??t.value:void 0;if(E&&y&&!i.isPaymentRequired.value)return Nn();if(E&&Qe(E)&&i.isPaymentRequired.value){const m=new gt({isSubmitting:e,paymentInstrument:t,checkout:i,shop:o,shopPay:a,observability:d,declaredFields:c,...h,readSavedCards:s});if(y&&(await m.loadAddressMetadata([y.billing_address]),n?.aborted))return le();const T=m.writePayment({payment:E,applyBilling:y!==void 0});if(S(T))return T}}let C=!1,N=!1,k={progressionStatus:"none"};try{e.value=$(i)&&i.isPaymentRequired.value&&Qe(t.value),await h.journey.progress("web-mcp-complete-checkout",E=>{k=Wo(E),C=E.status==="success"||E.status==="alreadyCompleted",N||="negotiated"in E||"receipt"in E})}finally{e.value&&N&&(t.value=void 0),e.value=!1}const g=r();return!C&&!g?.messages?.some(E=>E.type==="error"&&E.severity==="requires_buyer_input")?Z("completion_failed",k):g??Z("completion_failed",k)}catch(y){return y instanceof _?rt(y,"complete the checkout"):(d.error({error:new Go}),Z("internal_error"))}finally{u=!1}}}
1class Vo extends Error{constructor(){super("WebMCP get_checkout failed to read the checkout"),this.name="WebMcpGetCheckoutError"}}function Xo({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. ${De}`,inputSchema:{type:"object",properties:{}},annotations:{consequentialHint:!1,readOnlyHint:!0,untrustedContentHint:!0},execute:()=>J(i(),e)};function i(){try{const o=t(e.latestReceipt.value?.status==="processed"?"negotiated":"proposed");return o||En()}catch{return n.error({error:new Vo}),In()}}}const Ko=3e4;
1class Jo extends Error{constructor(t){super("WebMCP navigate_to_storefront failed",{cause:t}),this.name="WebMcpStorefrontNavigationError"}}function wt({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 Zo({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,l)=>J(await s(d,l?.signal??o),e)};async function s(d,l){let c;try{if(d===null||typeof d!="object"||Array.isArray(d)||Object.keys(d).length>0)return Rn();if(l.aborted||o.aborted)return Fe();const u=r();if(!u)return On();if(a(u))return $e();const p=wt({shop:t,url:n});if(!p)return Fn();const f=new Promise(b=>{c=setTimeout(()=>b("timeout"),Ko)}),y=await Promise.race([u.waitForPendingNegotiations(),f]);return l.aborted||o.aborted?Fe():y==="timeout"?(i.log({name:"web_mcp_storefront_navigation_timed_out",message:"Storefront navigation timed out waiting for pending checkout updates"}),Un()):a(u)?$e():(window.location.assign(p),{status:"navigation_started",destination_url:p,message:"Refresh the available tools after the storefront loads."})}catch(u){return i.error({error:new Jo(u)}),xn()}finally{clearTimeout(c)}}function a({journey:d}){const l=e.latestReceipt.value;return d.completing.value||d.progressing.value||l!=null&&!["processed","failed","abandoned"].includes(l.status)}}const et=3e4,Qo={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."},address_region:{type:"string",description:"Province or region code."},postal_code:{type:"string"}}},payment:{...te,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. ${Ct}`,properties:Tt}},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"}}}}}}}}}}}}}}},er="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 tr extends Error{constructor(){super("WebMCP update_checkout failed to apply"),this.name="WebMcpUpdateCheckoutError"}}function nr({isSubmitting:e,paymentInstrument:t,signal:n,checkout:i,shop:o,shopPay:r,router:s,getSavedCardSelector:a,readCheckout:d,readSavedCards:l,observability:c,getPreactContext:u,declaredFields:p,getFulfillmentController:f}){return{name:"update_checkout",title:"Update checkout",description:`${er} ${De}`,inputSchema:Qo,annotations:{consequentialHint:!1,readOnlyHint:!1,untrustedContentHint:!0},execute:async b=>J(await y(b),i)};async function y(b){let h;try{if(e.value)return Y();const C=i.identity.current.value==="shopPay",N=ko(b,{savedPaymentMethodsOnly:C,ignorePayment:C?!i.isPaymentRequired.value:!$(i)}),k=u();if(!k||n?.aborted||(s.currentUrl.value.normalizedPath==="/review"&&s.navigate("/"),N.payment&&"instrument_id"in N.payment&&!a()))return Ue();const{loadPickupLocalityServices:g}=k;let E;const m=new gt({isSubmitting:e,paymentInstrument:t,checkout:i,shop:o,shopPay:r,getSavedCardSelector:a,observability:c,declaredFields:p,...k,readSavedCards:l,getFulfillmentController:f,resolvePickupLocality:g?async q=>(E=await g(),E.resolvePickupLocality(q)):void 0,announcePickupLocality:q=>E?.announcePickupLocality(q),get negotiator(){return k.negotiator}});let T=!1;const O=new Promise(q=>{h=setTimeout(()=>{T=!0,q("timeout")},et)}),w=await Promise.race([m.applyUpdate(N,{isExpired:()=>T||!!n?.aborted}),O]);return w==="timeout"?(c.log({name:"web_mcp_update_timed_out",message:"[WebMcp] Update did not finish in time; update outcome is unknown",attributes:{timeoutMs:et}}),I()):S(w)?w:d()??I()}catch(C){return C instanceof _?rt(C,"update the checkout"):(c.error({error:new tr}),I("internal_error"))}finally{clearTimeout(h)}}}function ir(e){return typeof e=="object"&&e!==null&&"error"in e&&typeof e.error=="object"}function or(e){if(typeof e!="object"||e===null||!("error"in e))return"unknown";const{error:t}=e;return typeof t!="object"||t===null||!("code"in t)?"unknown":hn(t.code)?t.code:"unknown"}function Ce(e,t,n,i){const o=Math.round(performance.now()-i),r=ir(n),s={tool:t,outcome:r?"error":"success",...r&&{errorCode:or(n)}};e.log({name:"web_mcp_tool_executed",message:"[WebMcp] tool executed",attributes:{...s,...mn(n),durationMs:o}}),e.histogram({name:"web_mcp_tool_execution",value:o,unit:"ms",attributes:s})}function tt(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=J(bn(),i);return Ce(n,o,a,s),a}return t.during(o,async()=>{const a=await e.execute(...r);return Ce(n,o,a,s),a})}}}function rr(e,t){const n=e.name;return{...e,execute:(...i)=>{const o=performance.now(),r=e.execute(...i);return Ce(t,n,r,o),r}}}class sr extends Error{constructor(t,n){super(`WebMCP tool registration failed for ${t}: ${String(n)}`),this.name="WebMcpRegistrationError",n instanceof Error&&(this.cause=n)}}function ar(e,t){const n=new AbortController,i=nt(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 dr({modelContext:e,signal:t,isSubmitting:n,paymentInstrument:i,checkout:o,i18n:r,shop:s,shopPay:a,url:d,router:l,observability:c,activeTool:u,onActiveToolCreated:p,getPreactContext:f,markToolCallStarted:y,getSavedCardSelector:b,declaredFields:h,getFulfillmentProvider:C,getStoreCreditProvider:N,unregisterInitializingTool:k}){if(t.aborted)return;const g=new io({observability:c,checkout:o}),E=oo({checkout:o,shopPay:a}),m=L=>Bi({checkout:o,i18n:r,shop:s,router:l,readMode:L,savedCards:E(),declaredFields:h,paymentInstrument:i.value}),T=Qi(o);h.set(T.key,T);const O=Ji(()=>N?.());h.set(O.key,O);const w=u??new pn;p?.(w);const ae=[{tool:rr(Xo({checkout:o,readCheckout:m,observability:g}),g),signal:t}],Ne=ar(o,t);Ne.aborted||ae.push(...[nr({isSubmitting:n,paymentInstrument:i,signal:t,checkout:o,shop:s,shopPay:a,router:l,getSavedCardSelector:b,readCheckout:m,readSavedCards:E,observability:g,getPreactContext:f,declaredFields:h,getFulfillmentController:()=>{const L=C?.();return L?eo(L,o.proposal):void 0}}),zo({isSubmitting:n,paymentInstrument:i,signal:t,checkout:o,shop:s,shopPay:a,readCheckout:m,readSavedCards:E,observability:g,getPreactContext:f,declaredFields:h})].map(L=>({tool:tt(L,{activeTool:w,observability:g,checkout:o}),signal:Ne}))),wt({shop:s,url:d})&&ae.push({tool:tt(Zo({checkout:o,shop:s,url:d,observability:g,signal:t,getPreactContext:f}),{activeTool:w,observability:g,checkout:o}),signal:t}),k?.();const Lt=ae.map(async({tool:L,signal:X})=>{try{return await e.registerTool({...L,execute(B,Mt){return y(),g.toolCalled(L.name),L.execute(B,Mt)}},{signal:X}),"registered"}catch(B){return X.aborted?"withdrawn":(g.error({error:new sr(L.name,B)}),"failed")}});return Promise.all(Lt).then(L=>{if(t.aborted)return;
1const X=L.filter(B=>B==="registered").length;g.log({name:"web_mcp_tools_registered",message:"[WebMcp] tools registered",attributes:{registered:X,failed:L.filter(B=>B==="failed").length}}),X>0&&g.initialized()}).catch(()=>{}),w}const yr=Object.freeze(Object.defineProperty({__proto__:null,registerWebMcpTools:dr},Symbol.toStringTag,{value:"Module"}));export{ze as n,yr 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.