1import{j as e}from"./2c1ab0fe.GMbxnz74.js";import{dn as t,cn as s,dp as r}from"./4c290a1e.DMQ9xOwP.js";import{g as o}from"./e477f96c.DJuIaq7S.js";import{b as n}from"./0a7dffce.BcNpdEJk.js";import{S as a}from"./app.DGSHpWaV.js";import{c as i,i as d,P as c}from"./711bf263.CXsAdxw9.js";import{B as l}from"./9c523c9d.MigMTTTS.js";import{g as u}from"./e592f8b9.DUn4Te8e.js";import"./21cc90a2.Ccyorzx_.js";import"./5c5c2e96.D7xkIHuT.js";function p(e){if(!e||"object"!=typeof e)return!1;const t=e,s="cart"in t,r="errors"in t;if(!s&&!r)return!1;if(s&&(null===t.cart||"object"!=typeof t.cart))return!1;if(r){if(!Array.isArray(t.errors))return!1;for(const e of t.errors)if(!e||"object"!=typeof e||!("code"in e)||!("message"in e)||"string"!=typeof e.code||"string"!=typeof e.message)return!1}return!0}class m extends a{constructor(e,t){super("checkoutSessionIdentifier is required but was not available. This may indicate the GraphQL session field was not queried or the response has not been received.",{metadata:{sourceId:e,sourceType:t}}),this.sourceId=e,this.sourceType=t,this.name="MissingCheckoutSessionIdError",this.unactionable=!0}}function h(e){const s=e.negotiated.value,r=s.shippingAddress,o=e.proposed.shippingAddress.value,n="unavailable"===s.deliveryNext?.status,a=t(o),i=!r||t(r);if(!a||!i)return n&&i?o:r}function y(e){const{checkout:t,shop:{domain:s},negotiationContext:r}=e,n=t.proposal.negotiated.value,{merchandiseLines:a,subtotal:i,total:d,discountLines:c,contactInfo:l,buyerIdentity:u,paymentMethods:p}=n,m=h(t.proposal),y=p?.find(e=>"wallet"===e.type&&"GOOGLE_PAY"===e.name);return{id:e.source.sourceId,lines:w(a?.lines),cost:{subtotalAmount:_(i),totalAmount:_(d)},buyerIdentity:{email:l?.email,phone:l?.phone,customer:u?.customerProfile?.id?{id:u.customerProfile.id,firstName:u.customerProfile.firstName||void 0,lastName:u.customerProfile.lastName||void 0,email:u.customerProfile.email||void 0,phone:u.customerProfile.phone||void 0}:void 0,countryCode:u?.countryCode||m?.countryCode},deliveryGroups:E(n.deliveryNext,m),delivery:{addresses:m?[{address:{address1:m.address1,address2:m.address2,city:m.city,countryCode:m.countryCode,provinceCode:m.zoneCode,zip:m.postalCode,firstName:m.firstName,lastName:m.lastName,phone:m.phone,company:m.company},oneTimeUse:m.oneTimeUse||!1,selected:!0}]:[]},discountCodes:j(n.discountLines?.lines),appliedGiftCards:x(n.paymentLines?.lines),discountAllocations:A(c?.lines||[]),payment:{methods:r?.delegatedPaymentInstrument?.value?[{type:"creditCard",instruments:[{externalReferenceId:o(r.delegatedPaymentInstrument.value)??""}]}]:[],...y?{handlers:[{id:"gpay",name:"com.google.pay",config:{api_version:2,api_version_minor:0,allowed_payment_methods:[{type:"CARD",parameters:{allowed_auth_methods:y.allowedAuthMethods,allowed_card_networks:y.allowedCardNetworks},tokenization_specification:{type:"PAYMENT_GATEWAY",parameters:{gateway:y.gateway,gateway_merchant_id:y.gatewayMerchantId}}}],merchant_info:{merchant_name:"shopify",merchant_id:y.merchantId,merchant_origin:s,auth_jwt:y.authJwt}}}]}:void 0}}}const f={shopify_installments:"shop_pay",paypal_express:"paypal",amazon_pay_classic:"amazon_pay"};function v(e){const t=e.toLowerCase();return f[t]??t}function g(e){const t=e?.find(e=>"wallet"===e.method.type);if(t)return{expressCheckout:{wallet:v(t.method.name)}};const s=e?.find(e=>"walletsPlatformPaymentMethod"===e.method.type);if(s)return{expressCheckout:{wallet:s.method.name}};const r=e?.some(e=>"redeemable"===e.method.type&&"SHOP_CASH"===e.method.redemptionSource);return r?{expressCheckout:{wallet:"shop_pay"}}:void 0}function C(e){if(e)return{address1:e.address1,address2:e.address2,city:e.city,company:e.company,countryCode:e.countryCode,firstName:e.firstName,lastName:e.lastName,phone:e.phone,provinceCode:e.zoneCode,zip:e.postalCode}}function b(e){if("available"!==e.status||!e.methods||!e.selectedDeliveryMethodHandle)return;const t=e.methods.find(t=>t.handle===e.selectedDeliveryMethodHandle);return t?{code:t.code,title:t.title,description:t.description,handle:t.handle,estimatedCost:_(t.cost),deliveryMethodType:I(t.methodType)}:void 0}function I(e){switch(e){case"SHIPPING":default:return"SHIPPING";case"PICK_UP":case"RETAIL":return"PICKUP";case"PICKUP_POINT":return"PICKUP_POINT";case"LOCAL":return"LOCAL";case"NONE":return"NONE"}}function A(e){return e?e.filter(e=>e.discount&&n(e.discount)&&"CART"===e.discount.presentationLevel).map(e=>({discountedAmount:_(e.amount),discountApplication:N(e),targetType:S(e.discount.targetType)})):[]}function N(e){return{allocationMethod:"ALL"===e.discount.targetSelection?"ACROSS":"EACH",targetSelection:e.discount.targetSelection,targetType:S(e.discount.targetType),value:T(e.discount.value)}}function S(e){return"DELIVERYLINE"===e?"SHIPPING_LINE":"LINE_ITEM"}function _(e){return e&&"object"==typeof e?{amount:e.amount.toFixed(2),currencyCode:e.currencyCode}:{amount:"0.00",currencyCode:"USD"}}function w(e){return e?e.flatMap(e=>e.lineAllocations.map(t=>
1({id:t.stableId,quantity:t.quantity,merchandise:{id:e.id||e.stableId,title:e.title,product:{id:e.productId||"",title:e.title},image:e.image?{url:e.image.url||"",altText:e.image.altText}:void 0,selectedOptions:e.options?e.options.map(({name:e,value:t})=>({name:e,value:t})):[]},cost:{amountPerQuantity:_(e.itemPrice),subtotalAmount:_(t.totalAmountBeforeReductions),totalAmount:_(t.totalAmountAfterLineDiscounts)},discountAllocations:P(t)}))):[]}function P(e){const t=[];return e.allocations.forEach(e=>{const{discountDetails:s,amount:r}=e,o=s.discount;"discountCodeTrigger"!==o.type&&t.push({discountedAmount:_(r),discountApplication:{allocationMethod:"ONE"===o.allocationMethod?"ACROSS":o.allocationMethod,targetSelection:o.targetSelection,targetType:S(o.targetType),value:T(o.value)},targetType:"LINE_ITEM"})}),t}function T(e){return"PercentageValue"===e.typename?{percentage:e.percentage}:_(e.fixedAmount)}function x(e){return e?e.filter(e=>"giftCard"===e.method.type&&void 0!==e.cost&&void 0!==e.method.balance).map(e=>({amountUsed:_(e.cost),balance:_(e.method.balance),lastCharacters:s(e.method),presentmentAmountUsed:_(e.cost)})):[]}function E(e,t){return"filled"===e?.status&&e.lines?e.lines.map(e=>{return{deliveryAddress:{address1:t?.address1,address2:t?.address2,city:t?.city,province:t?.zoneCode,country:t?.countryCode,countryCodeV2:t?.countryCode,zip:t?.postalCode,firstName:t?.firstName,lastName:t?.lastName,phone:t?.phone,company:t?.company},deliveryOptions:(s=e,"available"===s.status&&s.methods?s.methods.map(e=>({code:e.code,title:e.title,description:e.description,handle:e.handle,estimatedCost:_(e.cost),deliveryMethodType:I(e.methodType)})):[]),selectedDeliveryOption:b(e),groupType:e.type};var s}):[]}function j(e){return e?e.map(e=>{if(!("discount"in e))return null;const t=e.discount;if("code"!==t.type&&"discountCodeTrigger"!==t.type)return null;const s=!("message"in e&&e.message);return{code:t.title,applicable:s,...e.message&&{reason:e.message}}}).filter(e=>null!==e):[]}function k(e,t){if(function(e){return!d(e)}(t))return e;const s=JSON.parse(JSON.stringify(e));return"cart"in s.params&&s.params.cart&&function(e){if(e.buyerIdentity&&(delete e.buyerIdentity.email,delete e.buyerIdentity.phone,e.buyerIdentity.customer&&delete e.buyerIdentity.customer),e.delivery?.addresses)for(const t of e.delivery.addresses)t.address&&(delete t.address.firstName,delete t.address.lastName,delete t.address.company,delete t.address.address1,delete t.address.address2,delete t.address.city,delete t.address.provinceCode,delete t.address.zip,delete t.address.phone);if(e.deliveryGroups)for(const t of e.deliveryGroups)t.deliveryAddress&&(delete t.deliveryAddress.firstName,delete t.deliveryAddress.lastName,delete t.deliveryAddress.company,delete t.deliveryAddress.address1,delete t.deliveryAddress.address2,delete t.deliveryAddress.city,delete t.deliveryAddress.province,delete t.deliveryAddress.zip,delete t.deliveryAddress.phone)}(s.params.cart),"orderConfirmation"in s.params&&s.params.orderConfirmation&&delete s.params.orderConfirmation.url,s}class L extends l{constructor(e){super(e),this.version="2025-10",this.#e=!1,this.#t=3e5,this.#s=new c({observability:e.observability}),this.observability.bridgeInitialized()}#s;#e;#r;#t;async ready(){}async start(){const e=k(function(e){const{i18n:{locale:t},shop:{merchantPolicies:s=[]}}=e,r=y(e),o=s.find(e=>"terms-of-service"===e.handle),n=s.find(e=>"privacy-policy"===e.handle),a=o?.url||n?.url?{...o?.url&&{termsOfService:o.url},...n?.url&&{privacyPolicy:n.url}}:void 0;return{jsonrpc:"2.0",method:"checkout.start",params:{locale:t,cart:r,...a&&{policies:a}}}}(this.context),this.context);this.#s.notify(e),this.observability.checkoutStarted({embedder:this.context.embed.embedder,buyerEmail:this.context.checkout.proposal.proposed.email.peek(),hasPaymentInstrument:this.hasDelegatedPaymentInstrument()}),this.#o()}async resumeFromReceipt(){this.#o()}async complete(){if(this.#e)return void this.observability.completedEventSkipped();this.#e=!0,this.observability.checkoutCompleted();const e=function(e){const{checkout:t,source:{sourceId:s}}=e,r=t.latestReceipt.value;return{jsonrpc:"2.0",method:"checkout.complete",params:{cart:function(e,t){const s=e.purchaseOrder,{shippingAddress:r,billingAddress:o}=s,n=o||r;return{id:t,lines:w(s.merchandiseLines?.lines),cost:{subtotalAmount:_(e.subtotal),totalAmount:_(e.checkoutTotal)},buyerIdentity:{email:s.email,phone:s.phone,customer:e.customerId?{id:e.customerId,email:s.email,phone:s.phone,firstName:n?.firstName,lastName:n?.lastName}:void 0,countryCode:n?.countryCode},deliveryGroups:E(s.deliveryNext,r),delivery:r?{addresses:[{address:{address1:r.address1,address2:r.address2,city:r.city,countryCode:r.countryCode,provinceCode:r.zoneCode,zip:r.postalCode,firstName:r.firstName,lastName:r.lastName,phone:r.phone,company:r.company},oneTimeUse:r.oneTimeUse||!1,selected:!0}]}:{addresses:[]},discountCodes:j(e.discountLines?.lines),appliedGiftCards:x(e.purchaseOrder.paymentLines),discountAllocations:A(e.discountLines?.lines),payment:{methods:[],...g(e.purchaseOrder.paymentLines)}}}(r,s),orderConfirmation:{url:r.confirmationPage.url,order:{id:r.orderIdentity.id},number:r.orderIdentity.buyerIdentifier??void 0,isFirstOrder:r.isFirstOrder??!0}}}}(this.context);this.observability.completedEventEmitted(),this.#s.notify(e)}error(e){const t={jsonrpc:"2.0",method:"checkout.error",params:{code:(s={code:e.code,message:e.message}).code,message:s.message}};var s;this.#s.notify(t)}async addressChangeRequest(e){const t=function(e,t,s=i()){const{addressType:r}=e;return{jsonrpc:"2.0",id:s,method:"checkout.addressChangeRequested",params:{addressType:r,selectedAddress:C(h(t.checkout.proposal))}}}({addressType:e},this.context),s=await this.#s.request(t,{timeoutMs:this.#t});return this.#n(s)}async addressChangeStart(e){const t=function(e,t,s=i()){const{addressType:r}=e;return{jsonrpc:"2.0",id:s,method:"checkout.addressChangeStart",params:{addressType:r,cart:y(t)}}}({addressType:e},this.context),s=k(t,this.context),r=await this.#s.request(s,{timeoutMs:this.#t});return this.#a(r)}async paymentMethodChangeStart(){const e=k(function(e,t=i()){return{jsonrpc:"2.0",id:t,method:"checkout.paymentMethodChangeStart",params:{cart:y(e)}}}(this.context),this.context),t=await this.#s.request(e,{timeoutMs:this.#t});return this.#i(t)}async submitStart(){await this.waitForPendingNegotiations();const e=k(function(e,t=i()){const{source:{sourceId:s,checkoutSessionIdentifier:r}}=e,o=y(e);
1if(!r)throw new m(s,"checkout.submitStart");return{jsonrpc:"2.0",id:t,method:"checkout.submitStart",params:{cart:o,sessionId:r}}}(this.context),this.context),t=await this.#s.request(e,{timeoutMs:u(this.context.embed.embedder)});return this.#d(t)}cleanup(){this.#s.cleanup(),this.#r?.()}#o(){this.#r=e(()=>{const e=this.context.checkout.latestReceipt.value;e&&"processed"===e.status&&(this.complete(),this.cleanup())})}#n(e){if(!function(e){if(!e||"object"!=typeof e)return!1;const t=e.delivery;if(!t||"object"!=typeof t)return!1;const s=t.addresses;if(!Array.isArray(s)||0===s.length)return!1;const r=s[0],o=r?.address;return null!==o&&"object"==typeof o}(e))throw new r("Invalid address change response structure");const t=e.delivery.addresses[0].address;return{firstName:t.firstName,lastName:t.lastName,address1:t.address1,address2:t.address2,city:t.city,company:t.company,countryCode:t.countryCode,phone:t.phone,zoneCode:t.provinceCode,postalCode:t.zip}}#a(e){if(!p(e))throw this.context.observability.log("message_mapper_invalid_response_schema","Invalid response schema for addressChangeStart",{response:e}),new r("Invalid addressChangeStart response structure: must be an object with cart and/or errors fields");return e}#i(e){if(!p(e))throw this.context.observability.log("message_mapper_invalid_response_schema","Invalid response schema for paymentMethodChangeStart",{response:e}),new r("Invalid paymentMethodChangeStart response structure: must be an object with cart and/or errors fields");return e}#d(e){if(!p(e))throw this.context.observability.log("message_mapper_invalid_response_schema","Invalid response schema for submitStart",{response:e}),new r("Invalid submitStart response structure: must be an object with cart and/or errors fields");return e}}export{L as ShopifyEcp2025_10Client};
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.