@zonos/elements 1.3.4-alpha.2 → 1.3.5-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{cart-f31374d4.js → cart-f038cf46.js} +6 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/zonos-address_2.cjs.entry.js +36 -26
- package/dist/cjs/zonos-cart-items_10.cjs.entry.js +1 -1
- package/dist/cjs/zonos-checkout.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +1 -1
- package/dist/cjs/zonos-payment.cjs.entry.js +1 -1
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +35 -25
- package/dist/collection/components/utils/api/calculateLandedCost.js +6 -1
- package/dist/components/cart.js +6 -1
- package/dist/components/zonos-address2.js +35 -25
- package/dist/esm/{cart-c9124cc3.js → cart-ba9b0d4c.js} +6 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/zonos-address_2.entry.js +36 -26
- package/dist/esm/zonos-cart-items_10.entry.js +1 -1
- package/dist/esm/zonos-checkout.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +1 -1
- package/dist/esm/zonos-payment.entry.js +1 -1
- package/dist/esm-es5/cart-ba9b0d4c.js +1 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/zonos-address_2.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-payment.entry.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/scripts/zonosBase.js +1 -1
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +1 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-ffc91e42.entry.js → p-1165b6e5.entry.js} +1 -1
- package/dist/zonos-elements/{p-741a1402.system.entry.js → p-12c19be6.system.entry.js} +1 -1
- package/dist/zonos-elements/p-245997d9.js +1 -0
- package/dist/zonos-elements/{p-c134eecd.system.js → p-59343e23.system.js} +1 -1
- package/dist/zonos-elements/{p-f7b1dfd0.system.entry.js → p-7beaee33.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-43220d68.entry.js → p-824ebf9d.entry.js} +1 -1
- package/dist/zonos-elements/p-839f6cd9.entry.js +1 -0
- package/dist/zonos-elements/{p-62851827.system.entry.js → p-8970e202.system.entry.js} +1 -1
- package/dist/zonos-elements/p-b035f9e5.system.js +1 -1
- package/dist/zonos-elements/{p-b494d540.entry.js → p-be4bc6bc.entry.js} +1 -1
- package/dist/zonos-elements/p-c3d75f4f.system.js +1 -0
- package/dist/zonos-elements/{p-d170748c.system.entry.js → p-da2387d2.system.entry.js} +1 -1
- package/dist/zonos-elements/p-dcf1e1b4.system.entry.js +1 -0
- package/dist/zonos-elements/{p-139fc767.entry.js → p-fdb9568e.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/cart-c9124cc3.js +0 -1
- package/dist/zonos-elements/p-2ac66cea.system.entry.js +0 -1
- package/dist/zonos-elements/p-51a40ddf.system.js +0 -1
- package/dist/zonos-elements/p-97e659b7.entry.js +0 -1
- package/dist/zonos-elements/p-e59b6648.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as e,c as t}from"./p-e8da4463.js";import{h as n,l as o,a as s,b as r,t as i}from"./p-8ebc0b64.js";import{i as a}from"./p-0024f8c2.js";import{g as l}from"./p-f2733cc7.js";const d=()=>{const e=m.stripeLinkEventData,t=m.stripeAddressEventData;if(!t||!t.complete)throw new Error("Missing stripe address data");return{checkoutSessionId:E.checkoutSessionId||"",contact:{email:(null==e?void 0:e.value.email)||"",firstName:t.value.firstName||"",lastName:t.value.lastName||"",phone:t.value.phone||""},items:E.items.map((e=>e)),shippingAddress:{addressLine1:t.value.address.line1,addressLine2:t.value.address.line2||"",city:t.value.address.city,country:t.value.address.country,postalCode:t.value.address.postal_code,state:t.value.address.state}}},c=({borderStyle:e,theme:t})=>"DARK"===t?{borderRadius:l(e),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"}:{borderRadius:l(e)},{onChange:u,reset:p,state:m}=t((()=>({clientSecret:sessionStorage.getItem("zonos--client-secret")||null,fetchingLandedCostAbordController:null,isFetchingLandedCost:!1,isFetchingSession:!1,stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenFetchingLC:null,stripeBillingAddressElement:null,stripeElements:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null}))),h=async t=>{var n;const r=m.clientSecret;if(m.stripe){if(r){const i=(({clientSecret:t,overrideBorderRaidus:n,overridePrimaryColor:o,overrideTheme:r})=>{const i=o||e.appearance.colorPrimary,l=i&&a(i)?"night":"flat",d="DARK"===r?"night":"flat";return{appearance:{labels:"floating",rules:Object.assign({},{".Input":{padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"}}),theme:r?d:l,variables:Object.assign({},c({borderStyle:n,theme:"LIGHT"}))},clientSecret:t,locale:s.selectedLocale}})({clientSecret:r,overrideBorderRaidus:null==t?void 0:t.overrideBorderRaidus,overridePrimaryColor:null==t?void 0:t.overridePrimaryColor,overrideTheme:null==t?void 0:t.overrideTheme}),l=JSON.stringify(i)===JSON.stringify(m.stripeElementsOptions);if(!m.stripeElements)return m.stripeElements=null===(n=m.stripe)||void 0===n?void 0:n.elements(i),m.stripeElementsOptions=i,void o("Stripe elements initialized");l||(m.stripeElements.update(i),m.stripeElementsOptions=i),o("Stripe elements initialized")}}else o("Skip. Stripe is not initialized")},v=()=>{sessionStorage.removeItem("zonos--client-secret"),p(),m.stripe=window.Zonos.stripe},g=async()=>{var t,o,s,i;const a=!!(null===(t=m.stripeAddressEventData)||void 0===t?void 0:t.complete),l=!!(null===(o=m.stripeLinkEventData)||void 0===o?void 0:o.complete),c=(()=>{var e,t,n,o;if(!m.fetchingLandedCostAbordController)return!1;const s=JSON.stringify(null===(e=m.stripeLinkUsedWhenFetchingLC)||void 0===e?void 0:e.value)!==JSON.stringify(null===(t=m.stripeLinkEventData)||void 0===t?void 0:t.value),r=JSON.stringify(null===(n=m.stripeAddressUsedWhenFetchingLC)||void 0===n?void 0:n.value)!==JSON.stringify(null===(o=m.stripeAddressEventData)||void 0===o?void 0:o.value);return s||r})();if(c&&(null===(s=m.fetchingLandedCostAbordController)||void 0===s||s.abort(),m.fetchingLandedCostAbordController=null),a&&l&&(c||!m.isFetchingLandedCost)){m.isFetchingLandedCost=!0,m.stripeAddressEventData&&(m.stripeAddressUsedWhenFetchingLC=Object.assign({},m.stripeAddressEventData)),m.stripeLinkEventData&&(m.stripeLinkUsedWhenFetchingLC=Object.assign({},m.stripeLinkEventData));try{const t=new AbortController;m.fetchingLandedCostAbordController=t;const{checkoutSessionWorkflow:o,shipmentRatingCalculateWorkflow:s}=await(async t=>{const o=e.checkoutSettings.buildLandedCost;if(o){const e=await(async e=>{var t;const o=d(),s=await e(o.checkoutSessionId,o.contact,o.shippingAddress);if(!s)throw new Error("Failed to build landed cost");const{errors:r,json:i}=await n("https://v1.route.js.zonos.com/api/zonos-elements/validate-landed-cost",{body:s,headers:{"Content-Type":"application/json"},method:"POST"});if(!i||r.length)throw new Error(`Invalid landed cost object: ${(null===(t=r.find(Boolean))||void 0===t?void 0:t.message)||"Unknown error"}`);return s})(o);return e}const{errors:s,json:r}=await n("https://v1.route.js.zonos.com/api/zonos-elements/calculate-landed-cost",{body:d(),method:"POST",signal:null==t?void 0:t.signal});if(s.length||!r)throw new Error("Failed to calculate landed cost");return r})(t);m.fetchingLandedCostAbordController=null,E.landedCostData=(null==o?void 0:o.filter(Boolean))||null,E.shippingData=(null==s?void 0:s.filter(Boolean))||null;const r=null===(i=E.landedCostData)||void 0===i?void 0:i.find(Boolean),a=r?r.subtotals:null;a&&A({exchangeRate:a.exchangeRate,items:a.items,landedCostTotal:0,presentmentCurrencyCode:a.presentmentCurrencyCode,shipping:0,total:a.items})}catch(e){r(e)}m.isFetchingLandedCost=!1}},y=e=>{let t=[],n=!0;switch(e){case"succeeded":t=[i("Your payment went through successfully! Thank you for shopping with us! We hope you had an enjoyable experience and your support means the world to us."),"","",i("We've sent an email confirmation of the order details for your review. And our team is carefully preparing your order so it arrives on time.")],n=!1;break;case"requires_capture":case"processing":t=[i("Payment processing. We'll update you when payment is received.")],n=!1;break;case"requires_payment_method":t=[i("Payment failed. Please try another payment method.")];break;default:t=[i("Something went wrong.")]}return{isError:n,messages:t}},f=async({clientSecret:e,storybookForceStatus:t})=>{if(t){const{isError:e,messages:n}=y(t);return{error:e,messages:n}}const n=e||m.clientSecret;if(!m.stripe||!n)return r("Failed to retrieve payment intent. Stripe is not initialized"),{error:!0,message:[i("Something went wrong.")]};const{paymentIntent:o}=await m.stripe.retrievePaymentIntent(n),s=null==o?void 0:o.status,{isError:a,messages:l}=y(s);return{error:a,messages:l}},w=async()=>{var e,t,n;const o=!!(null===(e=m.stripePaymentEventData)||void 0===e?void 0:e.complete),s=m.stripeElements,r=m.stripe;if(r&&s&&o&&m.clientSecret){const{error:e}=await r.confirmPayment({confirmParams:{receipt_email:null===(n=null===(t=m.stripeLinkEventData)||void 0===t?void 0:t.value)||void 0===n?void 0:n.email,return_url:window.location.href},elements:s,redirect:"if_required"});if(e){if("card_error"===e.type||"validation_error"===e.type)throw new Error(e.message);if("invalid_request_error"===e.type&&"payment_intent_unexpected_state"===e.code)return;throw new Error("An unexpected error occurred.")}}},S=async()=>{var e;const t=E.items.reduce(((e,t)=>e+t.amount*t.quantity),0);if(!t||!s.targetCurrency)return r("Fail to create checkout session - invalid total or currency"),!1;m.isFetchingSession=!0;const{errors:i,json:a}=await n("https://v1.route.js.zonos.com/api/zonos-elements/create-checkout-session",{body:{currency:(null===(e=E.items.find(Boolean))||void 0===e?void 0:e.currencyCode)||"",itemsAmount:t,presentmentCountryCode:s.selectedCountryCode||null},method:"POST"});if(m.isFetchingSession=!1,i.length||!a)return r("Error occurs when creating checkout session",JSON.stringify(i,null,2)),!1;const l=a.checkoutSessionCreate;return m.clientSecret=l.clientSecret,E.checkoutSessionId=l.id,A(Object.assign(Object.assign({},l.subtotals),{landedCostTotal:0,shipping:0,total:l.subtotals.items})),o("Exchange rate updated for cart items (checkout session create)","info",E.exchangeRate),o("done-init-checkout-session"),!0};u("clientSecret",(e=>{e&&m.stripe&&sessionStorage.setItem("zonos--client-secret",e),e||sessionStorage.removeItem("zonos--client-secret")}));const C=e=>{const t=new Date,n=e.getTime()-t.getTime();return Math.floor(n/864e5)},{onChange:k,reset:b,state:E}=t((()=>({checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id")||null,currency:"USD",dutiesTaxFees:0,error:null,exchangeRate:null,isSelectedShippingAboveDeminimis:!1,isSelectedShippingGuarantee:!1,items:[],landedCostData:null,selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,step:"customer-info",subtotal:0,total:0}))),O=e=>{const t=e.minTransitAt?C(new Date(e.minTransitAt)):"",n=e.maxTransitAt?C(new Date(e.maxTransitAt)):"";return{expectedDate:e.minTransitAt?(({date:e,formatOptions:t={day:"numeric",weekday:"long",year:"numeric"}})=>new Intl.DateTimeFormat("en-US",t).format(e))({date:new Date(e.minTransitAt)}):"",maxTransit:n,minTransit:t}},j=()=>{sessionStorage.removeItem("zonos--checkout-session-id"),b()},T=({messages:e,title:t})=>{E.step="error",E.error={messages:e,title:t}},A=e=>{E.exchangeRate=e.exchangeRate,E.dutiesTaxFees=e.landedCostTotal,E.subtotal=e.items,E.total=e.total,E.currency=e.presentmentCurrencyCode},x=async({currency:e,itemsAmount:t,landedCostId:a})=>{if(a&&E.selectedLandedCost&&(A(E.selectedLandedCost.subtotals),o("Exchange rate updated for cart items (landed cost subtotal)","info",E.exchangeRate)),!E.checkoutSessionId)return r("Could not update cart total without checkout session id"),!1;const{json:l}=await(async({currency:e,id:t,itemsAmount:o,landedCostId:s,presentmentCountryCode:i})=>{const{errors:a,json:l}=await n("https://v1.route.js.zonos.com/api/zonos-elements/update-checkout-session",{body:{currency:e,id:t,itemsAmount:o,landedCostId:s,presentmentCountryCode:i},method:"POST"});return a.length||!l?(r("Error occurs when updating checkout session",JSON.stringify(a,null,2)),{errors:a,json:l}):{errors:[],json:l}})({currency:e,id:E.checkoutSessionId,itemsAmount:t,landedCostId:a,presentmentCountryCode:s.selectedCountryCode});return l?(a||(A(l.checkoutSessionUpdate.subtotals),o("Exchange rate updated for cart items (checkout session update)","info",E.exchangeRate)),!0):(r("Error occurs when updating checkout session"),T({messages:[i("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists")],title:i("Error updating Checkout")}),!1)},z=async e=>{var t,n,o,s,r;E.selectedShippingOption=e;const{expectedDate:i,maxTransit:a,minTransit:l}=O(E.selectedShippingOption);E.selectedShippingOptionExpectedDate=i,E.selectedShippingOptionTransitTime=l&&a?`${l}-${a}`:`${l||a}`;const d=null===(t=E.landedCostData)||void 0===t?void 0:t.find((e=>{var t,n,o;return(null===(n=null===(t=e.landedCost)||void 0===t?void 0:t.shipmentRating)||void 0===n?void 0:n.id)===(null===(o=E.selectedShippingOption)||void 0===o?void 0:o.id)}));if(E.selectedLandedCost=d||null,!d)return!1;E.shipping=d.subtotals.shipping;const c="ZONOS"===(null===(n=null==d?void 0:d.landedCost)||void 0===n?void 0:n.landedCostGuaranteeCode),u=!!(null===(s=null===(o=null==d?void 0:d.landedCost)||void 0===o?void 0:o.deMinimis)||void 0===s?void 0:s.find((e=>["DUTY","TAX"].includes(e.type)&&"ABOVE"===e.threshold)));return E.isSelectedShippingAboveDeminimis=u,E.isSelectedShippingGuarantee=c,await x({landedCostId:null===(r=d.landedCost)||void 0===r?void 0:r.id})};k("checkoutSessionId",(()=>{E.checkoutSessionId?sessionStorage.setItem("zonos--checkout-session-id",E.checkoutSessionId):sessionStorage.removeItem("zonos--checkout-session-id")}));const D=async e=>{var t;E.items=e;const n=null===(t=e.find(Boolean))||void 0===t?void 0:t.currencyCode,o=e.reduce(((e,t)=>e+t.amount*t.quantity),0);n&&o&&(E.currency=n,m.isFetchingSession=!0,await x({currency:n,itemsAmount:o}),m.isFetchingSession=!1)},P=()=>{"customer-info"===E.step?E.step="shipping":"shipping"===E.step?E.step="payment":"payment"===E.step&&(E.step="finish")},B=()=>{"payment"===E.step?E.step="shipping":"shipping"===E.step&&(E.step="customer-info",E.selectedShippingOption=null,E.isSelectedShippingAboveDeminimis=!1,E.isSelectedShippingGuarantee=!1,E.selectedShippingOptionExpectedDate="",E.selectedShippingOptionTransitTime="",E.shipping=0)};export{A as a,O as b,E as c,P as d,B as e,x as f,j as g,D as h,z as i,T as j,h as k,S as l,g as m,w as n,v as o,f as p,m as s}
|