@zonos/elements 1.3.6 → 1.3.7-alpha.1

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.
Files changed (306) hide show
  1. package/dist/cjs/{localization-2c9f5765.js → cart-89d9fff4.js} +863 -89
  2. package/dist/cjs/formatStringWithLinks-52341fc7.js +17 -0
  3. package/dist/cjs/{getBorderRadius-b252096d.js → getBorderRadius-d8f18958.js} +1 -1
  4. package/dist/cjs/{isDarkColor-168002d6.js → isDarkColor-57860b44.js} +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/submitGtag-24740560.js +55 -0
  7. package/dist/cjs/zonos-address_4.cjs.entry.js +36 -18
  8. package/dist/cjs/zonos-badge_2.cjs.entry.js +6 -6
  9. package/dist/cjs/zonos-banner.cjs.entry.js +1 -1
  10. package/dist/cjs/zonos-button_3.cjs.entry.js +8 -8
  11. package/dist/cjs/zonos-card_2.cjs.entry.js +10 -8
  12. package/dist/cjs/zonos-cart-items_9.cjs.entry.js +66 -56
  13. package/dist/cjs/zonos-checkout.cjs.entry.js +170 -34
  14. package/dist/cjs/zonos-component.cjs.entry.js +1 -1
  15. package/dist/cjs/zonos-controller.cjs.entry.js +51 -32
  16. package/dist/cjs/zonos-country-flag.cjs.entry.js +5 -3
  17. package/dist/cjs/zonos-country-select_3.cjs.entry.js +21 -12
  18. package/dist/cjs/zonos-elements.cjs.js +1 -1
  19. package/dist/cjs/zonos-hello-dialog.cjs.entry.js +23 -19
  20. package/dist/cjs/zonos-hello.cjs.entry.js +51 -34
  21. package/dist/cjs/zonos-link.cjs.entry.js +24 -0
  22. package/dist/cjs/zonos-logo.cjs.entry.js +3 -3
  23. package/dist/cjs/zonos-notification.cjs.entry.js +1 -1
  24. package/dist/cjs/zonos-payment.cjs.entry.js +5 -6
  25. package/dist/cjs/zonos-select-dialog-header_2.cjs.entry.js +5 -5
  26. package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +3 -3
  27. package/dist/cjs/zonos-text.cjs.entry.js +1 -1
  28. package/dist/cjs/{zonosStore-5d94dabb.js → zonosStore-138c5555.js} +9 -7
  29. package/dist/collection/collection-manifest.json +1 -0
  30. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.js +1 -6
  31. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +27 -13
  32. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.css +3 -0
  33. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +39 -18
  34. package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.css +5 -1
  35. package/dist/collection/components/checkout/zonos-checkout/zonos-customer-info/zonos-customer-info.js +2 -0
  36. package/dist/collection/components/checkout/zonos-checkout/zonos-review/zonos-review.js +1 -6
  37. package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.css +3 -0
  38. package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +5 -0
  39. package/dist/collection/components/common/component-template/zonos-link/zonos-link.css +54 -0
  40. package/dist/collection/components/common/component-template/zonos-link/zonos-link.js +97 -0
  41. package/dist/collection/components/common/zonos-badge/zonos-badge.js +3 -3
  42. package/dist/collection/components/common/zonos-button/zonos-button.css +2 -0
  43. package/dist/collection/components/common/zonos-button/zonos-button.js +4 -4
  44. package/dist/collection/components/common/zonos-card/zonos-card.js +2 -2
  45. package/dist/collection/components/common/zonos-checkbox/zonos-checkbox.js +3 -3
  46. package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +26 -6
  47. package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +8 -2
  48. package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +4 -2
  49. package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +3 -3
  50. package/dist/collection/components/common/zonos-language-select/zonos-language-select.js +2 -2
  51. package/dist/collection/components/common/zonos-logo/zonos-logo.js +2 -2
  52. package/dist/collection/components/common/zonos-select-dialog-header/zonos-select-dialog-header.js +2 -2
  53. package/dist/collection/components/common/zonos-shipping-rich-radio/zonos-shipping-rich-radio.js +1 -1
  54. package/dist/collection/components/common/zonos-tooltip/zonos-tooltip.js +2 -2
  55. package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.js +2 -2
  56. package/dist/collection/components/component-template/zonos-component/zonos-component.js +1 -1
  57. package/dist/collection/components/hello/zonos-hello/zonos-hello.js +50 -11
  58. package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.js +2 -2
  59. package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +5 -3
  60. package/dist/collection/components/main/zonos-controller.js +1 -1
  61. package/dist/collection/components/store/checkout/cart.js +2 -2
  62. package/dist/collection/components/store/checkout/stripe.js +29 -4
  63. package/dist/collection/components/store/hello/localization.js +34 -7
  64. package/dist/collection/components/store/zonosStore.js +9 -7
  65. package/dist/collection/components/stripe/zonos-address/zonos-address.js +1 -1
  66. package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +1 -1
  67. package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +1 -1
  68. package/dist/collection/components/utils/api/trackConversionEvent.js +22 -0
  69. package/dist/collection/components/utils/checkout/isShippableCountry.js +15 -0
  70. package/dist/collection/components/utils/checkout/watchBigcommerceDomesticCheckout.js +111 -0
  71. package/dist/collection/components/utils/formatStringWithLinks.js +13 -0
  72. package/dist/collection/components/utils/handleFetch.js +1 -1
  73. package/dist/collection/components/utils/hello/currencyConversion/defaultCurrencyConverter.js +25 -28
  74. package/dist/collection/components/utils/hello/currencyConversion/getCurrencyElements.js +2 -1
  75. package/dist/collection/components/utils/hello/currencyConversion/getInitialElementAmount.js +8 -6
  76. package/dist/collection/components/utils/hello/initHello.js +23 -3
  77. package/dist/collection/components/utils/logging/log.js +20 -9
  78. package/dist/collection/components/utils/logging/logError.js +2 -1
  79. package/dist/collection/components/utils/logging/sendErrorLog.js +12 -0
  80. package/dist/collection/scripts/checkIfLoadVersionDomain.js +35 -0
  81. package/dist/collection/scripts/zonosBase.js +21 -31
  82. package/dist/collection/styles/stripe/addressRuleStyle.js +4 -0
  83. package/dist/collection/types/generated/graphql.customer.types.js +7 -4
  84. package/dist/collection/types/generated/graphql.frontend.types.js +3 -0
  85. package/dist/components/stripe.js +4097 -7
  86. package/dist/components/submitGtag.js +1 -1
  87. package/dist/components/trackConversionEvent.js +24 -0
  88. package/dist/components/zonos-address2.js +2 -3
  89. package/dist/components/zonos-badge2.js +3 -3
  90. package/dist/components/zonos-button2.js +5 -5
  91. package/dist/components/zonos-card2.js +2 -2
  92. package/dist/components/zonos-cart-subtotal2.js +2 -8
  93. package/dist/components/zonos-checkbox2.js +3 -3
  94. package/dist/components/zonos-checkout-finish2.js +44 -16
  95. package/dist/components/zonos-checkout-footer2.js +1 -1
  96. package/dist/components/zonos-checkout-payment2.js +2 -3
  97. package/dist/components/zonos-checkout.js +157 -19
  98. package/dist/components/zonos-collapse2.js +26 -6
  99. package/dist/components/zonos-component.js +1 -1
  100. package/dist/components/zonos-controller.js +25 -6
  101. package/dist/components/zonos-country-flag2.js +1 -1
  102. package/dist/components/zonos-country-select2.js +9 -3
  103. package/dist/components/zonos-custom-message2.js +18 -3
  104. package/dist/components/zonos-customer-info2.js +4 -3
  105. package/dist/components/zonos-dialog2.js +3 -3
  106. package/dist/components/zonos-hello-dialog-footer2.js +3 -3
  107. package/dist/components/zonos-hello-dialog2.js +6 -5
  108. package/dist/components/zonos-hello.js +23 -7
  109. package/dist/components/zonos-language-select2.js +3 -3
  110. package/dist/components/zonos-link-authentication2.js +1 -1
  111. package/dist/components/zonos-link.d.ts +11 -0
  112. package/dist/components/zonos-link.js +43 -0
  113. package/dist/components/zonos-logo.js +2 -2
  114. package/dist/components/zonos-payment2.js +1 -1
  115. package/dist/components/zonos-review2.js +2 -8
  116. package/dist/components/zonos-select-dialog-header2.js +2 -2
  117. package/dist/components/zonos-shipping-rich-radio2.js +1 -1
  118. package/dist/components/zonos-shipping2.js +7 -3
  119. package/dist/components/zonos-tooltip2.js +2 -2
  120. package/dist/components/zonos-v-stack2.js +2 -2
  121. package/dist/components/zonosStore.js +9 -7
  122. package/dist/esm/{localization-d8f6453b.js → cart-1bbb7662.js} +846 -90
  123. package/dist/esm/formatStringWithLinks-9e819405.js +15 -0
  124. package/dist/esm/{getBorderRadius-e9736f7e.js → getBorderRadius-19787feb.js} +1 -1
  125. package/dist/esm/{isDarkColor-e982fa09.js → isDarkColor-2344e7a5.js} +1 -1
  126. package/dist/esm/loader.js +1 -1
  127. package/dist/esm/submitGtag-d3d11f1a.js +51 -0
  128. package/dist/esm/zonos-address_4.entry.js +33 -15
  129. package/dist/esm/zonos-badge_2.entry.js +6 -6
  130. package/dist/esm/zonos-banner.entry.js +1 -1
  131. package/dist/esm/zonos-button_3.entry.js +8 -8
  132. package/dist/esm/zonos-card_2.entry.js +8 -6
  133. package/dist/esm/zonos-cart-items_9.entry.js +47 -37
  134. package/dist/esm/zonos-checkout.entry.js +158 -22
  135. package/dist/esm/zonos-component.entry.js +1 -1
  136. package/dist/esm/zonos-controller.entry.js +28 -9
  137. package/dist/esm/zonos-country-flag.entry.js +4 -2
  138. package/dist/esm/zonos-country-select_3.entry.js +19 -10
  139. package/dist/esm/zonos-elements.js +1 -1
  140. package/dist/esm/zonos-hello-dialog.entry.js +9 -5
  141. package/dist/esm/zonos-hello.entry.js +24 -7
  142. package/dist/esm/zonos-link.entry.js +20 -0
  143. package/dist/esm/zonos-logo.entry.js +3 -3
  144. package/dist/esm/zonos-notification.entry.js +1 -1
  145. package/dist/esm/zonos-payment.entry.js +5 -6
  146. package/dist/esm/zonos-select-dialog-header_2.entry.js +5 -5
  147. package/dist/esm/zonos-shipping-rich-radio.entry.js +3 -3
  148. package/dist/esm/zonos-text.entry.js +1 -1
  149. package/dist/esm/{zonosStore-e6c7be3a.js → zonosStore-00bce01b.js} +9 -7
  150. package/dist/esm-es5/cart-1bbb7662.js +1 -0
  151. package/dist/esm-es5/formatStringWithLinks-9e819405.js +1 -0
  152. package/dist/esm-es5/{getBorderRadius-e9736f7e.js → getBorderRadius-19787feb.js} +1 -1
  153. package/dist/esm-es5/{isDarkColor-e982fa09.js → isDarkColor-2344e7a5.js} +1 -1
  154. package/dist/esm-es5/loader.js +1 -1
  155. package/dist/esm-es5/submitGtag-d3d11f1a.js +1 -0
  156. package/dist/esm-es5/zonos-address_4.entry.js +1 -1
  157. package/dist/esm-es5/zonos-badge_2.entry.js +1 -1
  158. package/dist/esm-es5/zonos-banner.entry.js +1 -1
  159. package/dist/esm-es5/zonos-button_3.entry.js +1 -1
  160. package/dist/esm-es5/zonos-card_2.entry.js +1 -1
  161. package/dist/esm-es5/zonos-cart-items_9.entry.js +1 -1
  162. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  163. package/dist/esm-es5/zonos-component.entry.js +1 -1
  164. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  165. package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
  166. package/dist/esm-es5/zonos-country-select_3.entry.js +1 -1
  167. package/dist/esm-es5/zonos-elements.js +1 -1
  168. package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
  169. package/dist/esm-es5/zonos-hello.entry.js +1 -1
  170. package/dist/esm-es5/zonos-link.entry.js +1 -0
  171. package/dist/esm-es5/zonos-logo.entry.js +1 -1
  172. package/dist/esm-es5/zonos-notification.entry.js +1 -1
  173. package/dist/esm-es5/zonos-payment.entry.js +1 -1
  174. package/dist/esm-es5/zonos-select-dialog-header_2.entry.js +1 -1
  175. package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
  176. package/dist/esm-es5/zonos-text.entry.js +1 -1
  177. package/dist/esm-es5/{zonosStore-e6c7be3a.js → zonosStore-00bce01b.js} +1 -1
  178. package/dist/scripts/checkIfLoadVersionDomain.js +1 -0
  179. package/dist/scripts/loadStripe.js +1 -1
  180. package/dist/scripts/loadZonos.js +1 -1
  181. package/dist/scripts/stripe.js +1 -1
  182. package/dist/scripts/zonos.js +1 -1
  183. package/dist/scripts/zonosBase.js +1 -1
  184. package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +1 -1
  185. package/dist/types/components/common/component-template/zonos-link/zonos-link.d.ts +19 -0
  186. package/dist/types/components/common/zonos-collapse/zonos-collapse.d.ts +1 -0
  187. package/dist/types/components/common/zonos-country-select/zonos-country-select.d.ts +2 -0
  188. package/dist/types/components/hello/zonos-hello/zonos-hello.d.ts +9 -3
  189. package/dist/types/components/store/checkout/cart.d.ts +6 -3
  190. package/dist/types/components/store/checkout/stripe.d.ts +26 -1
  191. package/dist/types/components/store/hello/localization.d.ts +1 -1
  192. package/dist/types/components/store/zonosStore.d.ts +2 -1
  193. package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
  194. package/dist/types/components/utils/api/trackConversionEvent.d.ts +3 -0
  195. package/dist/types/components/utils/checkout/isShippableCountry.d.ts +1 -0
  196. package/dist/types/components/utils/checkout/watchBigcommerceDomesticCheckout.d.ts +20 -0
  197. package/dist/types/components/utils/formatStringWithLinks.d.ts +1 -0
  198. package/dist/types/components/utils/hello/currencyConversion/getCurrencyElements.d.ts +1 -1
  199. package/dist/types/components/utils/hello/currencyConversion/getLanguageCode.d.ts +1 -1
  200. package/dist/types/components/utils/logging/log.d.ts +1 -1
  201. package/dist/types/components/utils/logging/sendErrorLog.d.ts +7 -0
  202. package/dist/types/components.d.ts +53 -3
  203. package/dist/types/scripts/checkIfLoadVersionDomain.d.ts +13 -0
  204. package/dist/types/scripts/zonosBase.d.ts +2 -0
  205. package/dist/types/types/ICountryJson.d.ts +2 -1
  206. package/dist/types/types/checkout/CheckoutConfig.d.ts +1 -1
  207. package/dist/types/types/generated/graphql.customer.types.d.ts +23 -53
  208. package/dist/types/types/generated/graphql.customer.types.ts +42 -62
  209. package/dist/types/types/generated/graphql.frontend.types.d.ts +9 -1
  210. package/dist/types/types/generated/graphql.frontend.types.ts +19 -1
  211. package/dist/zonos-elements/p-0318632a.entry.js +1 -0
  212. package/dist/zonos-elements/p-066c5893.system.js +1 -1
  213. package/dist/zonos-elements/p-07966463.entry.js +1 -0
  214. package/dist/zonos-elements/p-0c0aa552.js +1 -0
  215. package/dist/zonos-elements/p-127b480c.entry.js +1 -0
  216. package/dist/zonos-elements/p-135ab559.system.entry.js +1 -0
  217. package/dist/zonos-elements/{p-b81a0577.system.entry.js → p-143dc0d9.system.entry.js} +1 -1
  218. package/dist/zonos-elements/{p-32bca9c8.system.entry.js → p-14d27ce1.system.entry.js} +1 -1
  219. package/dist/zonos-elements/p-15a80c4a.entry.js +1 -0
  220. package/dist/zonos-elements/p-17e87be1.entry.js +1 -0
  221. package/dist/zonos-elements/{p-0c7480a5.entry.js → p-1e0dd491.entry.js} +1 -1
  222. package/dist/zonos-elements/{p-a33745e9.entry.js → p-279d1c5f.entry.js} +1 -1
  223. package/dist/zonos-elements/p-2d6557ee.system.js +1 -0
  224. package/dist/zonos-elements/p-314be538.system.entry.js +1 -0
  225. package/dist/zonos-elements/{p-dd7729fd.system.entry.js → p-328b7f6f.system.entry.js} +1 -1
  226. package/dist/zonos-elements/p-354603b3.system.entry.js +1 -0
  227. package/dist/zonos-elements/{p-50287643.system.js → p-49f6a985.system.js} +1 -1
  228. package/dist/zonos-elements/p-57b65321.system.entry.js +1 -0
  229. package/dist/zonos-elements/p-58c1ddef.system.js +1 -0
  230. package/dist/zonos-elements/{p-06652d87.system.entry.js → p-58e2f6a1.system.entry.js} +1 -1
  231. package/dist/zonos-elements/p-5ee03db0.system.entry.js +1 -0
  232. package/dist/zonos-elements/{p-5a113c3d.system.entry.js → p-61e5cf29.system.entry.js} +1 -1
  233. package/dist/zonos-elements/{p-49a764e9.system.entry.js → p-799d8a17.system.entry.js} +1 -1
  234. package/dist/zonos-elements/p-7a32526c.entry.js +1 -0
  235. package/dist/zonos-elements/p-7b87b82f.js +1 -0
  236. package/dist/zonos-elements/{p-9cbbf261.system.entry.js → p-7c45ce37.system.entry.js} +1 -1
  237. package/dist/zonos-elements/p-84f4f00f.entry.js +1 -0
  238. package/dist/zonos-elements/{p-e8a9bc56.entry.js → p-857cfe35.entry.js} +1 -1
  239. package/dist/zonos-elements/p-87e9c42f.entry.js +1 -0
  240. package/dist/zonos-elements/{p-e99d79d9.system.js → p-91797d4e.system.js} +1 -1
  241. package/dist/zonos-elements/{p-17550a10.js → p-95e0fc06.js} +1 -1
  242. package/dist/zonos-elements/{p-7a6144b1.entry.js → p-a3cc0f84.entry.js} +1 -1
  243. package/dist/zonos-elements/p-a5f12396.entry.js +1 -0
  244. package/dist/zonos-elements/p-a87561b8.js +1 -0
  245. package/dist/zonos-elements/{p-ba43275e.entry.js → p-ac0a7b8f.entry.js} +1 -1
  246. package/dist/zonos-elements/p-ae82a9ae.js +1 -0
  247. package/dist/zonos-elements/p-b0462325.system.entry.js +1 -0
  248. package/dist/zonos-elements/p-b2c0ec71.system.entry.js +1 -0
  249. package/dist/zonos-elements/{p-fcc4f140.system.js → p-b4725505.system.js} +1 -1
  250. package/dist/zonos-elements/p-bef54fb1.entry.js +1 -0
  251. package/dist/zonos-elements/p-c0d431f6.system.entry.js +1 -0
  252. package/dist/zonos-elements/p-d054788b.system.js +1 -0
  253. package/dist/zonos-elements/p-d407c93a.system.entry.js +1 -0
  254. package/dist/zonos-elements/p-e55dd932.js +1 -0
  255. package/dist/zonos-elements/p-ec37439e.entry.js +1 -0
  256. package/dist/zonos-elements/p-edace42b.entry.js +1 -0
  257. package/dist/zonos-elements/p-f478c814.system.entry.js +1 -0
  258. package/dist/zonos-elements/{p-7dd8e8ba.system.entry.js → p-f6eaef7b.system.entry.js} +1 -1
  259. package/dist/zonos-elements/{p-bd6a2095.entry.js → p-f7c36fcc.entry.js} +1 -1
  260. package/dist/zonos-elements/p-f862b97f.system.entry.js +1 -0
  261. package/dist/zonos-elements/p-fd642725.entry.js +1 -0
  262. package/dist/zonos-elements/p-fdb72530.system.entry.js +1 -0
  263. package/dist/zonos-elements/{p-a4de3fb2.entry.js → p-ff64ddc5.entry.js} +1 -1
  264. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  265. package/package.json +1 -1
  266. package/dist/cjs/cart-b8bbf22d.js +0 -698
  267. package/dist/cjs/submitGtag-792fe45d.js +0 -21
  268. package/dist/collection/scripts/extractZonosQaUrl.js +0 -26
  269. package/dist/components/localization.js +0 -4016
  270. package/dist/esm/cart-bc3bb22e.js +0 -682
  271. package/dist/esm/submitGtag-bebe2cb0.js +0 -19
  272. package/dist/esm-es5/cart-bc3bb22e.js +0 -1
  273. package/dist/esm-es5/localization-d8f6453b.js +0 -1
  274. package/dist/esm-es5/submitGtag-bebe2cb0.js +0 -1
  275. package/dist/types/scripts/extractZonosQaUrl.d.ts +0 -11
  276. package/dist/zonos-elements/p-00d63df1.system.entry.js +0 -1
  277. package/dist/zonos-elements/p-04f63cea.entry.js +0 -1
  278. package/dist/zonos-elements/p-16b74c31.system.js +0 -1
  279. package/dist/zonos-elements/p-1d16a6fb.js +0 -1
  280. package/dist/zonos-elements/p-1ea68e3b.entry.js +0 -1
  281. package/dist/zonos-elements/p-1ed530cc.entry.js +0 -1
  282. package/dist/zonos-elements/p-289c8b1a.system.entry.js +0 -1
  283. package/dist/zonos-elements/p-2a00c270.system.entry.js +0 -1
  284. package/dist/zonos-elements/p-37f53a79.entry.js +0 -1
  285. package/dist/zonos-elements/p-394cf1cf.js +0 -1
  286. package/dist/zonos-elements/p-3ef27745.js +0 -1
  287. package/dist/zonos-elements/p-458fd100.system.entry.js +0 -1
  288. package/dist/zonos-elements/p-47fac33f.js +0 -1
  289. package/dist/zonos-elements/p-4fafb2a5.system.entry.js +0 -1
  290. package/dist/zonos-elements/p-4fb71a93.js +0 -1
  291. package/dist/zonos-elements/p-5276c61b.system.entry.js +0 -1
  292. package/dist/zonos-elements/p-6308b347.entry.js +0 -1
  293. package/dist/zonos-elements/p-63d1b1fe.entry.js +0 -1
  294. package/dist/zonos-elements/p-7347ee7c.system.entry.js +0 -1
  295. package/dist/zonos-elements/p-8c26a080.system.js +0 -1
  296. package/dist/zonos-elements/p-96aabe02.entry.js +0 -1
  297. package/dist/zonos-elements/p-a682fd38.system.entry.js +0 -1
  298. package/dist/zonos-elements/p-ba1a111a.system.entry.js +0 -1
  299. package/dist/zonos-elements/p-c4321084.system.entry.js +0 -1
  300. package/dist/zonos-elements/p-cdf114a2.entry.js +0 -1
  301. package/dist/zonos-elements/p-d5ae3cbb.system.entry.js +0 -1
  302. package/dist/zonos-elements/p-d5d7c8f5.entry.js +0 -1
  303. package/dist/zonos-elements/p-de339fb6.entry.js +0 -1
  304. package/dist/zonos-elements/p-ec25f180.entry.js +0 -1
  305. package/dist/zonos-elements/p-f49dfd06.system.js +0 -1
  306. package/dist/zonos-elements/p-f6f5f644.entry.js +0 -1
@@ -1,4 +1,6 @@
1
- import { c as createStore, z as zonosStore } from './zonosStore-e6c7be3a.js';
1
+ import { c as createStore, z as zonosStore } from './zonosStore-00bce01b.js';
2
+ import { i as isDarkColor } from './isDarkColor-2344e7a5.js';
3
+ import { g as getBorderRadius } from './getBorderRadius-19787feb.js';
2
4
 
3
5
  const stringsArabic = {
4
6
  'Above de minimis threshold for': {
@@ -3544,7 +3546,7 @@ const handleFetch = async (url, _opts) => {
3544
3546
  const modifiedUrl = new URL(url);
3545
3547
  modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
3546
3548
  // headers content type
3547
- const headers = Object.assign({ 'Content-Type': 'application/json', 'Zonos-Is-BigCommerce': window.Zonos.isBigCommerce.toString(), 'Zonos-Referer': window.location.hostname, 'Zonos-Version': window.Zonos.version, credentialtoken: window.Zonos.zonosApiKey }, opts.headers);
3549
+ const headers = Object.assign({ 'Content-Type': 'application/json', 'Zonos-Is-BigCommerce': window.Zonos.isBigCommerce.toString(), 'Zonos-Referer': window.location.hostname, 'Zonos-Version': window.Zonos.version, credentialtoken: window.Zonos.zonosApiKey || 'Empty credential token from zonos-elements' }, opts.headers);
3548
3550
  const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
3549
3551
  method });
3550
3552
  return handleRequest(modifiedUrl.toString(), options);
@@ -3565,9 +3567,65 @@ const getCountries = async () => {
3565
3567
  }
3566
3568
  };
3567
3569
 
3570
+ const log = (message, type, ...additionalInfo) => {
3571
+ var _a, _b;
3572
+ const isDebug = !((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.debug) ||
3573
+ !window.location.search.match(/\?.*(&*)zonosDebug=1/);
3574
+ // if debug is false, do not log
3575
+ if (!isDebug) {
3576
+ // log errors to the console if the type is error
3577
+ if (type === 'error') {
3578
+ // eslint-disable-next-line no-console
3579
+ console.error(message, ...additionalInfo);
3580
+ }
3581
+ return;
3582
+ }
3583
+ let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
3584
+ if (!loggingIframe) {
3585
+ // add a hidden iframe
3586
+ loggingIframe = document.createElement('iframe');
3587
+ loggingIframe.id = 'zonos---debug-logging-iframe';
3588
+ loggingIframe.style.display = 'none';
3589
+ loggingIframe.style.opacity = '0';
3590
+ loggingIframe.style.position = 'absolute';
3591
+ loggingIframe.style.top = '-9999px';
3592
+ loggingIframe.style.left = '-9999px';
3593
+ loggingIframe.style.width = '1px';
3594
+ loggingIframe.style.height = '1px';
3595
+ loggingIframe.style.border = 'none';
3596
+ loggingIframe.style.overflow = 'hidden';
3597
+ loggingIframe.style.visibility = 'hidden';
3598
+ document.body.appendChild(loggingIframe);
3599
+ }
3600
+ // use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
3601
+ const zConsole = ((_b = loggingIframe.contentWindow) === null || _b === void 0 ? void 0 : _b.window.console) || window.console;
3602
+ switch (type) {
3603
+ case 'warn':
3604
+ // eslint-disable-next-line no-console
3605
+ zConsole.warn(message, ...additionalInfo);
3606
+ break;
3607
+ case 'info':
3608
+ // eslint-disable-next-line no-console
3609
+ zConsole.info(message, ...additionalInfo);
3610
+ break;
3611
+ case 'error':
3612
+ // eslint-disable-next-line no-console
3613
+ zConsole.error(message, ...additionalInfo);
3614
+ break;
3615
+ default:
3616
+ // eslint-disable-next-line no-console
3617
+ zConsole.groupCollapsed(message, ...additionalInfo);
3618
+ // eslint-disable-next-line no-console
3619
+ zConsole.trace();
3620
+ // eslint-disable-next-line no-console
3621
+ zConsole.groupEnd();
3622
+ break;
3623
+ }
3624
+ };
3625
+
3568
3626
  const logError = (message, ...rest) => {
3569
3627
  // eslint-disable-next-line no-console
3570
- console.error(message, ...rest);
3628
+ log(message, 'error', ...rest);
3571
3629
  };
3572
3630
 
3573
3631
  const getCountryLandedCost = async (countryCode) => {
@@ -3729,51 +3787,6 @@ const isValidSelector = (selector) => {
3729
3787
  return true;
3730
3788
  };
3731
3789
 
3732
- const log = (message, type, ...additionalInfo) => {
3733
- var _a;
3734
- // if type is error and debug is false, do not log
3735
- if (!window.Zonos.debug) {
3736
- return;
3737
- }
3738
- let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
3739
- if (!loggingIframe) {
3740
- // add a hidden iframe
3741
- loggingIframe = document.createElement('iframe');
3742
- loggingIframe.id = 'zonos---debug-logging-iframe';
3743
- loggingIframe.style.display = 'none';
3744
- loggingIframe.style.opacity = '0';
3745
- loggingIframe.style.position = 'absolute';
3746
- loggingIframe.style.top = '-9999px';
3747
- loggingIframe.style.left = '-9999px';
3748
- loggingIframe.style.width = '1px';
3749
- loggingIframe.style.height = '1px';
3750
- loggingIframe.style.border = 'none';
3751
- loggingIframe.style.overflow = 'hidden';
3752
- loggingIframe.style.visibility = 'hidden';
3753
- document.body.appendChild(loggingIframe);
3754
- }
3755
- // use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
3756
- const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
3757
- switch (type) {
3758
- case 'warn':
3759
- // eslint-disable-next-line no-console
3760
- console.warn(message, ...additionalInfo);
3761
- break;
3762
- case 'info':
3763
- // eslint-disable-next-line no-console
3764
- console.info(message, ...additionalInfo);
3765
- break;
3766
- default:
3767
- // eslint-disable-next-line no-console
3768
- console.groupCollapsed(message, ...additionalInfo);
3769
- // eslint-disable-next-line no-console
3770
- console.trace();
3771
- // eslint-disable-next-line no-console
3772
- console.groupEnd();
3773
- break;
3774
- }
3775
- };
3776
-
3777
3790
  const getCurrencyElements = (selector) => {
3778
3791
  const currencySelector = selector || '.money';
3779
3792
  if (!isValidSelector(currencySelector)) {
@@ -3787,18 +3800,21 @@ const getCurrencyElements = (selector) => {
3787
3800
  log(`No currency elements found with selector "${currencySelector}"`, 'warn');
3788
3801
  return null;
3789
3802
  }
3790
- return currencyElements;
3803
+ // return array of currency elements instead of a NodeList
3804
+ return Array.from(currencyElements);
3791
3805
  };
3792
3806
 
3793
3807
  const getInitialElementAmount = (element) => {
3794
3808
  var _a;
3795
3809
  const domesticValue = element.getAttribute('data-domestic');
3796
- if (!domesticValue) {
3797
- // Only keep numbers, decimal, and hyphens
3798
- const cleanedText = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.-]/g, '');
3799
- if (!cleanedText) {
3800
- return null;
3801
- }
3810
+ const intlValue = element.getAttribute('data-zintl');
3811
+ // Only keep numbers, decimal, and hyphens
3812
+ const cleanedText = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.-]/g, '');
3813
+ if (!cleanedText) {
3814
+ return null;
3815
+ }
3816
+ // If the element has no data-domestic attribute, or the text content is different from the data-zintl attribute, set the data-domestic attribute
3817
+ if (!domesticValue || element.textContent !== intlValue) {
3802
3818
  // Store the original value on the element once, and international on every new conversion
3803
3819
  element.setAttribute('data-domestic', cleanedText);
3804
3820
  return parseFloat(cleanedText);
@@ -3806,9 +3822,32 @@ const getInitialElementAmount = (element) => {
3806
3822
  return parseFloat(domesticValue);
3807
3823
  };
3808
3824
 
3825
+ const convertCurrency = (element) => {
3826
+ var _a;
3827
+ const amount = getInitialElementAmount(element);
3828
+ if (!amount || isNaN(amount)) {
3829
+ return;
3830
+ }
3831
+ const currentIntlValue = element.getAttribute('data-zintl');
3832
+ const currentCountryValue = element.getAttribute('data-zcountry-code');
3833
+ // do nothing if the target currency is the same
3834
+ const isExchangeRateReady = localizationStore.targetCurrency ===
3835
+ ((_a = localizationStore.exchangeRate) === null || _a === void 0 ? void 0 : _a.targetFormat.currencyCode);
3836
+ // if the current value on the element is different from the current intl value, update the data-zintl attribute
3837
+ if (isExchangeRateReady &&
3838
+ (element.textContent !== currentIntlValue ||
3839
+ currentCountryValue !== localizationStore.selectedCountryCode)) {
3840
+ const observedFormattedValue = currencyConvertAndFormat(amount);
3841
+ element.textContent = observedFormattedValue;
3842
+ // save the new value to the data-zintl attribute
3843
+ element.setAttribute('data-zintl', observedFormattedValue);
3844
+ element.setAttribute('data-zcountry-code', localizationStore.selectedCountryCode || '');
3845
+ }
3846
+ };
3809
3847
  const defaultCurrencyConverter = () => {
3810
3848
  const { currencyElementSelector } = zonosStore.helloSettings;
3811
3849
  const currencyElements = getCurrencyElements(currencyElementSelector);
3850
+ // do nothing if none of the currency elements are found
3812
3851
  if (!(currencyElements === null || currencyElements === void 0 ? void 0 : currencyElements.length)) {
3813
3852
  return;
3814
3853
  }
@@ -3817,33 +3856,8 @@ const defaultCurrencyConverter = () => {
3817
3856
  return;
3818
3857
  }
3819
3858
  currencyElements.forEach((element) => {
3820
- const amount = getInitialElementAmount(element);
3821
- if (!amount || isNaN(amount)) {
3822
- return;
3823
- }
3824
- element.setAttribute('data-zintl', currencyConvert(amount).toString());
3825
- // Check if an observer is already attached to the element
3826
- let observer = element._mutationObserver;
3827
- if (!observer) {
3828
- observer = new MutationObserver(() => {
3829
- const observedFormattedValue = currencyConvertAndFormat(amount);
3830
- element.textContent = observedFormattedValue;
3831
- });
3832
- observer.observe(element, {
3833
- characterData: true,
3834
- childList: true,
3835
- });
3836
- element._mutationObserver = observer;
3837
- }
3838
- // Temporarily disconnect the observer to prevent an infinite loop
3839
- observer.disconnect();
3840
- const formattedValue = currencyConvertAndFormat(amount);
3841
- element.textContent = formattedValue;
3842
- // Reconnect the observer after the update is complete
3843
- observer.observe(element, {
3844
- characterData: true,
3845
- childList: true,
3846
- });
3859
+ // convert the currency and save the formatted value to the data-zintl attribute
3860
+ convertCurrency(element);
3847
3861
  });
3848
3862
  };
3849
3863
 
@@ -3925,11 +3939,9 @@ const getNewLocalization = async () => {
3925
3939
  !selectedCountryCode) {
3926
3940
  return;
3927
3941
  }
3928
- if (zonosStore.sourceCurrency !== localizationStore.targetCurrency) {
3929
- const isGuaranteed = zonosStore.checkoutSettings.visibilityStatus === 'ENABLED';
3930
- const { maxAge } = await triggerGetExchangeRate(isGuaranteed);
3931
- startExchangeRateTimeout({ isGuaranteed, maxAge });
3932
- }
3942
+ const isGuaranteed = zonosStore.checkoutSettings.visibilityStatus === 'ENABLED';
3943
+ const { maxAge } = await triggerGetExchangeRate(isGuaranteed);
3944
+ startExchangeRateTimeout({ isGuaranteed, maxAge });
3933
3945
  localizationStore.countryLandedCost = await getCountryLandedCost(localizationStore.selectedCountryCode);
3934
3946
  };
3935
3947
  const getCustomMessages = async () => {
@@ -3956,7 +3968,8 @@ const getOverrideLocale = () => {
3956
3968
  const zonosLocale = currentUrl.searchParams.get('zonosLocale');
3957
3969
  return zonosLocale;
3958
3970
  };
3959
- const localizationStoreUpdateSelectedCountryCode = async (newSelectedCountryCode) => {
3971
+ const localizationStoreUpdateSelectedCountryCode = (newSelectedCountryCode) => {
3972
+ var _a;
3960
3973
  log('update selected country code');
3961
3974
  localizationStore.selectedCountryCode = newSelectedCountryCode;
3962
3975
  const { selectedCountryCode, shippingZoneCountries } = localizationStore;
@@ -3980,6 +3993,8 @@ const localizationStoreUpdateSelectedCountryCode = async (newSelectedCountryCode
3980
3993
  window.sessionStorage.setItem('zonos--country', selectedCountryCode);
3981
3994
  // Update the URL query param with the new country code
3982
3995
  setZCountryUrlParam(selectedCountryCode);
3996
+ (_a = document
3997
+ .querySelector('zonos-hello')) === null || _a === void 0 ? void 0 : _a.setAttribute('z-country', selectedCountryCode);
3983
3998
  };
3984
3999
  const initLocalizationStore = async () => {
3985
4000
  // all countries from countries.json, shipping zone and localization
@@ -3987,7 +4002,7 @@ const initLocalizationStore = async () => {
3987
4002
  // Filter countries to only include countries in the shipping zone
3988
4003
  const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
3989
4004
  const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
3990
- return countryInfo
4005
+ return countryInfo && countryInfo.active
3991
4006
  ? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
3992
4007
  }, {});
3993
4008
  localizationStore.shippingZoneCountries = filteredCountries || null;
@@ -4008,9 +4023,750 @@ const initLocalizationStore = async () => {
4008
4023
  localizationStore.localizationLoaded = true;
4009
4024
  void getCustomMessages();
4010
4025
  };
4026
+ const updateCheckoutSessionLanguage = async () => {
4027
+ if (!cartStore.checkoutSessionId) {
4028
+ return null;
4029
+ }
4030
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session-metadata`, {
4031
+ body: {
4032
+ id: cartStore.checkoutSessionId,
4033
+ metadata: [
4034
+ {
4035
+ key: 'language',
4036
+ value: localizationStore.selectedLocale,
4037
+ },
4038
+ ],
4039
+ },
4040
+ method: 'POST',
4041
+ });
4042
+ if (errors.length || !json) {
4043
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4044
+ return { errors, json };
4045
+ }
4046
+ return { errors: [], json };
4047
+ };
4011
4048
  const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
4012
4049
  localizationStore.selectedLocale = newSelectedLocale;
4013
4050
  translationStoreUpdateLanguage(newSelectedLocale);
4051
+ void updateCheckoutSessionLanguage();
4052
+ };
4053
+
4054
+ const prepCalculateLandedCost = () => {
4055
+ // maybe we don't need email now for prefetch the landed cost
4056
+ const stripeLinkData = stripeStore.stripeLinkEventData;
4057
+ const stripeAddressData = stripeStore.stripeAddressEventData;
4058
+ const stripeBillingAddressData = stripeStore.stripeShippingSameAsBilling
4059
+ ? stripeStore.stripeAddressEventData
4060
+ : stripeStore.stripeBillingAddressEventData;
4061
+ if (!(stripeAddressData === null || stripeAddressData === void 0 ? void 0 : stripeAddressData.complete) || !(stripeBillingAddressData === null || stripeBillingAddressData === void 0 ? void 0 : stripeBillingAddressData.complete)) {
4062
+ throw new Error('Missing stripe address data');
4063
+ }
4064
+ return {
4065
+ billingAddress: {
4066
+ addressLine1: stripeBillingAddressData.value.address.line1,
4067
+ addressLine2: stripeBillingAddressData.value.address.line2 || '',
4068
+ city: stripeBillingAddressData.value.address.city,
4069
+ country: stripeBillingAddressData.value.address.country,
4070
+ postalCode: stripeBillingAddressData.value.address.postal_code,
4071
+ state: stripeBillingAddressData.value.address.state,
4072
+ },
4073
+ billingContact: {
4074
+ // firstName and lastName should be valid now since stripe only mark
4075
+ // the address as complete when both fields are filled.
4076
+ firstName: stripeBillingAddressData.value.firstName || '',
4077
+ lastName: stripeBillingAddressData.value.lastName || '',
4078
+ phone: stripeBillingAddressData.value.phone || '',
4079
+ },
4080
+ checkoutSessionId: cartStore.checkoutSessionId || '',
4081
+ contact: {
4082
+ email: (stripeLinkData === null || stripeLinkData === void 0 ? void 0 : stripeLinkData.value.email) || '',
4083
+ // firstName and lastName should be valid now since stripe only mark
4084
+ // the address as complete when both fields are filled.
4085
+ firstName: stripeAddressData.value.firstName || '',
4086
+ lastName: stripeAddressData.value.lastName || '',
4087
+ phone: stripeAddressData.value.phone || '',
4088
+ },
4089
+ items: cartStore.items.map(item => item),
4090
+ shippingAddress: {
4091
+ addressLine1: stripeAddressData.value.address.line1,
4092
+ addressLine2: stripeAddressData.value.address.line2 || '',
4093
+ city: stripeAddressData.value.address.city,
4094
+ country: stripeAddressData.value.address.country,
4095
+ postalCode: stripeAddressData.value.address.postal_code,
4096
+ state: stripeAddressData.value.address.state,
4097
+ },
4098
+ };
4099
+ };
4100
+
4101
+ const triggerBuildLandedCost = async (buildLandedCost) => {
4102
+ var _a, _b, _c, _d;
4103
+ const data = prepCalculateLandedCost();
4104
+ const landedCost = await buildLandedCost({
4105
+ billingAddress: data.billingAddress,
4106
+ billingContact: data.billingContact,
4107
+ checkoutSessionId: data.checkoutSessionId,
4108
+ contact: data.contact,
4109
+ shippingAddress: data.shippingAddress,
4110
+ });
4111
+ if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
4112
+ throw new Error(`Failed to build landed cost: ${((_c = (_b = landedCost === null || landedCost === void 0 ? void 0 : landedCost.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error'}`);
4113
+ }
4114
+ // Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
4115
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/validate-landed-cost`, {
4116
+ body: landedCost,
4117
+ headers: {
4118
+ 'Content-Type': 'application/json',
4119
+ },
4120
+ method: 'POST',
4121
+ });
4122
+ if (!json || errors.length) {
4123
+ throw new Error(`Invalid landed cost object: ${((_d = errors.find(Boolean)) === null || _d === void 0 ? void 0 : _d.message) || 'Unknown error'}`);
4124
+ }
4125
+ return landedCost;
4126
+ };
4127
+
4128
+ const calculateLandedCost = async (abortController) => {
4129
+ var _a;
4130
+ // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
4131
+ const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
4132
+ if (buildLandedCost) {
4133
+ const json = await triggerBuildLandedCost(buildLandedCost);
4134
+ return json;
4135
+ }
4136
+ // request to get landed cost info
4137
+ const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/calculate-landed-cost`;
4138
+ const { errors, json } = await handleFetch(url, {
4139
+ body: prepCalculateLandedCost(),
4140
+ method: 'POST',
4141
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
4142
+ });
4143
+ if (errors.length || !json) {
4144
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
4145
+ const errorMessage = isAbortedRequest
4146
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
4147
+ : 'Failed to calculate landed cost';
4148
+ throw new Error(errorMessage);
4149
+ }
4150
+ return json;
4151
+ };
4152
+
4153
+ const jsonParse = (_data) => {
4154
+ if (typeof _data === 'string') {
4155
+ try {
4156
+ // eslint-disable-next-line no-restricted-syntax
4157
+ const json = JSON.parse(_data);
4158
+ return json;
4159
+ }
4160
+ catch (_error) {
4161
+ return null;
4162
+ }
4163
+ }
4164
+ return null;
4165
+ };
4166
+
4167
+ const addressRuleStyle = ({ theme, }) => {
4168
+ switch (theme) {
4169
+ default:
4170
+ return {
4171
+ '.Input': {
4172
+ boxShadow: 'none',
4173
+ // need to reset everything and the paddingTop to default, otherwise the paddingTop will not be updated.
4174
+ padding: '0',
4175
+ paddingBottom: '8px',
4176
+ paddingLeft: '16px',
4177
+ paddingRight: '8px',
4178
+ // any value here will be add up to the default paddingTop (20px).
4179
+ paddingTop: '6px',
4180
+ },
4181
+ '.Input:focus': {
4182
+ boxShadow: 'none',
4183
+ },
4184
+ };
4185
+ }
4186
+ };
4187
+
4188
+ const defaultVariable = ({ borderStyle, theme, }) => {
4189
+ switch (theme) {
4190
+ case 'DARK':
4191
+ return {
4192
+ borderRadius: getBorderRadius(borderStyle),
4193
+ colorBackground: '#101117',
4194
+ colorBackgroundText: '#C5C6CA',
4195
+ colorText: '#C5C6CA',
4196
+ colorTextPlaceholder: '#C5C6CA',
4197
+ };
4198
+ default:
4199
+ return {
4200
+ borderRadius: getBorderRadius(borderStyle),
4201
+ };
4202
+ }
4203
+ };
4204
+
4205
+ const { onChange: onChange$1, reset: reset$1, state: stripeStore, } = createStore(() => ({
4206
+ clientSecret: sessionStorage.getItem('zonos--client-secret') || null,
4207
+ fetchingLandedCostAbordController: null,
4208
+ isFetchingLandedCost: false,
4209
+ isFetchingSession: false,
4210
+ stripe: null,
4211
+ stripeAddressElement: null,
4212
+ stripeAddressEventData: null,
4213
+ stripeAddressUsedWhenFetchingLC: null,
4214
+ stripeBillingAddressElement: null,
4215
+ stripeBillingAddressEventData: null,
4216
+ stripeBillingAddressUsedWhenFetchingLC: null,
4217
+ stripeElements: null,
4218
+ stripeElementsForBillingAddress: null,
4219
+ stripeElementsOptions: null,
4220
+ stripeLinkElement: null,
4221
+ stripeLinkEventData: null,
4222
+ stripeLinkUsedWhenFetchingLC: null,
4223
+ stripePaymentElement: null,
4224
+ stripePaymentEventData: null,
4225
+ stripeShippingSameAsBilling: true,
4226
+ }));
4227
+ const getStripeOptions = ({ clientSecret, overrideBorderRaidus, overridePrimaryColor, overrideSecondaryColor, overrideTheme, }) => {
4228
+ const primaryColor = overridePrimaryColor || zonosStore.appearance.colorPrimary;
4229
+ const secondaryColor = overrideSecondaryColor || zonosStore.appearance.colorSecondary;
4230
+ const themeBasedColor = primaryColor && isDarkColor(primaryColor) ? 'night' : 'flat';
4231
+ // if overrideTheme is provided, use it. Otherwise, use theme based on primary color
4232
+ const theme = overrideTheme === 'DARK' ? 'night' : 'flat';
4233
+ return {
4234
+ appearance: {
4235
+ labels: 'floating',
4236
+ rules: Object.assign({}, addressRuleStyle({ theme: 'LIGHT' })),
4237
+ // get contrast theme color base on primary color
4238
+ theme: overrideTheme ? theme : themeBasedColor,
4239
+ variables: Object.assign(Object.assign({}, defaultVariable({
4240
+ borderStyle: overrideBorderRaidus,
4241
+ theme: 'LIGHT',
4242
+ })), {
4243
+ // use the button background color for input glow color
4244
+ colorPrimary: secondaryColor }),
4245
+ },
4246
+ clientSecret,
4247
+ locale: localizationStore.selectedLocale,
4248
+ };
4249
+ };
4250
+ const stripeStoreCleanupDomesticShippingSession = () => {
4251
+ window.sessionStorage.removeItem('zonos--bigcommerce-domestic-checkout-shipping');
4252
+ };
4253
+ // Save shipping address to session storage
4254
+ const stripeStoreSaveDomesticShippingSession = (props) => {
4255
+ window.sessionStorage.setItem('zonos--bigcommerce-domestic-checkout-shipping', JSON.stringify(props));
4256
+ };
4257
+ const stripeStoreGetDomesticShippingSession = () => {
4258
+ const session = window.sessionStorage.getItem('zonos--bigcommerce-domestic-checkout-shipping');
4259
+ return jsonParse(session);
4260
+ };
4261
+ const initStripeElements = async (props) => {
4262
+ var _a, _b;
4263
+ const clientSecret = stripeStore.clientSecret;
4264
+ if (!stripeStore.stripe) {
4265
+ log('Skip. Stripe is not initialized');
4266
+ return;
4267
+ }
4268
+ if (clientSecret) {
4269
+ const stripeOptions = getStripeOptions({
4270
+ clientSecret,
4271
+ overrideBorderRaidus: props === null || props === void 0 ? void 0 : props.overrideBorderRaidus,
4272
+ overridePrimaryColor: props === null || props === void 0 ? void 0 : props.overridePrimaryColor,
4273
+ overrideSecondaryColor: props === null || props === void 0 ? void 0 : props.overrideSecondaryColor,
4274
+ overrideTheme: props === null || props === void 0 ? void 0 : props.overrideTheme,
4275
+ });
4276
+ // compare with the previous options to see if we need to update
4277
+ const isSameOptions = JSON.stringify(stripeOptions) ===
4278
+ JSON.stringify(stripeStore.stripeElementsOptions);
4279
+ if (!stripeStore.stripeElements ||
4280
+ !stripeStore.stripeElementsForBillingAddress) {
4281
+ // init stripe elements if it doesn't exist
4282
+ stripeStore.stripeElements = (_a = stripeStore.stripe) === null || _a === void 0 ? void 0 : _a.elements(stripeOptions);
4283
+ // save stripe elements options for later comparison
4284
+ stripeStore.stripeElementsOptions = stripeOptions;
4285
+ log('Stripe elements initialized');
4286
+ // init stripe elements for billing address
4287
+ stripeStore.stripeElementsForBillingAddress =
4288
+ (_b = stripeStore.stripe) === null || _b === void 0 ? void 0 : _b.elements(stripeOptions);
4289
+ log('Stripe elements for billing address initialized');
4290
+ return;
4291
+ }
4292
+ if (!isSameOptions) {
4293
+ // update elements with new option if it already exists
4294
+ stripeStore.stripeElements.update(stripeOptions);
4295
+ // update elements for stripe billing address
4296
+ stripeStore.stripeElementsForBillingAddress.update(stripeOptions);
4297
+ // save stripe elements options for later comparison
4298
+ stripeStore.stripeElementsOptions = stripeOptions;
4299
+ }
4300
+ log('Stripe elements initialized');
4301
+ }
4302
+ };
4303
+ const stripeStoreReset = () => {
4304
+ // clean clientSecret so that we can start the new one.
4305
+ sessionStorage.removeItem('zonos--client-secret');
4306
+ // cleanup stripe elements
4307
+ reset$1();
4308
+ // set stripe back to window.Zonos.stripe
4309
+ stripeStore.stripe = window.Zonos.stripe;
4310
+ };
4311
+ /**
4312
+ * Check if the address and email info used when fetching landed cost with the current email and address info are different
4313
+ * Purpose is to resend the request if the info used when fetching landed cost is different from the current info
4314
+ */
4315
+ const isPrefetchInfoOutdated = () => {
4316
+ var _a, _b, _c, _d, _e, _f;
4317
+ const hasAbortController = stripeStore.fetchingLandedCostAbordController;
4318
+ if (!hasAbortController) {
4319
+ // if there is no abort controller, this is a new request
4320
+ return false;
4321
+ }
4322
+ const isLinkDataDirty = JSON.stringify((_a = stripeStore.stripeLinkUsedWhenFetchingLC) === null || _a === void 0 ? void 0 : _a.value) !==
4323
+ JSON.stringify((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value);
4324
+ const isAddressDataDirty = JSON.stringify((_c = stripeStore.stripeAddressUsedWhenFetchingLC) === null || _c === void 0 ? void 0 : _c.value) !==
4325
+ JSON.stringify((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value);
4326
+ const isBillingAddressDataDirty = !stripeStore.stripeShippingSameAsBilling &&
4327
+ JSON.stringify((_e = stripeStore.stripeBillingAddressEventData) === null || _e === void 0 ? void 0 : _e.value) !==
4328
+ JSON.stringify((_f = stripeStore.stripeBillingAddressUsedWhenFetchingLC) === null || _f === void 0 ? void 0 : _f.value);
4329
+ return isLinkDataDirty || isAddressDataDirty || isBillingAddressDataDirty;
4330
+ };
4331
+ const stripeStorePrefetchLandedCost = async () => {
4332
+ var _a, _b, _c, _d, _e, _f;
4333
+ const stripeAddressReady = !!((_a = stripeStore.stripeAddressEventData) === null || _a === void 0 ? void 0 : _a.complete);
4334
+ const stripeLinkReady = !!((_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.complete);
4335
+ const stripeBillingAddressReady = stripeStore.stripeShippingSameAsBilling
4336
+ ? !!((_c = stripeStore.stripeLinkEventData) === null || _c === void 0 ? void 0 : _c.complete)
4337
+ : !!((_d = stripeStore.stripeBillingAddressEventData) === null || _d === void 0 ? void 0 : _d.complete);
4338
+ const shouldRefetch = isPrefetchInfoOutdated();
4339
+ if (shouldRefetch) {
4340
+ // if the info used when fetching landed cost is different from the current info, abort the previous request
4341
+ (_e = stripeStore.fetchingLandedCostAbordController) === null || _e === void 0 ? void 0 : _e.abort();
4342
+ stripeStore.fetchingLandedCostAbordController = null;
4343
+ }
4344
+ // only fetch if we are not fetching or we need to refetch
4345
+ if (stripeAddressReady &&
4346
+ stripeLinkReady &&
4347
+ stripeBillingAddressReady &&
4348
+ (shouldRefetch || !stripeStore.isFetchingLandedCost)) {
4349
+ stripeStore.isFetchingLandedCost = true;
4350
+ if (stripeStore.stripeAddressEventData) {
4351
+ stripeStore.stripeAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeAddressEventData);
4352
+ }
4353
+ if (stripeStore.stripeBillingAddressEventData) {
4354
+ stripeStore.stripeBillingAddressUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeBillingAddressEventData);
4355
+ }
4356
+ if (stripeStore.stripeLinkEventData) {
4357
+ stripeStore.stripeLinkUsedWhenFetchingLC = Object.assign({}, stripeStore.stripeLinkEventData);
4358
+ }
4359
+ try {
4360
+ const abortController = new AbortController();
4361
+ stripeStore.fetchingLandedCostAbordController = abortController;
4362
+ const { checkoutSessionWorkflow, landedCostCalculateWorkflow, shipmentRatingCalculateWorkflow, } = await calculateLandedCost(abortController);
4363
+ // reset abort controller after we are done
4364
+ stripeStore.fetchingLandedCostAbordController = null;
4365
+ // update cart store with landed cost info
4366
+ cartStore.landedCostData =
4367
+ (checkoutSessionWorkflow === null || checkoutSessionWorkflow === void 0 ? void 0 : checkoutSessionWorkflow.map(checkoutSession => {
4368
+ const foundLandedCost = landedCostCalculateWorkflow === null || landedCostCalculateWorkflow === void 0 ? void 0 : landedCostCalculateWorkflow.find(item => { var _a; return (item === null || item === void 0 ? void 0 : item.id) === ((_a = checkoutSession.landedCost) === null || _a === void 0 ? void 0 : _a.id); });
4369
+ if (!foundLandedCost) {
4370
+ return null;
4371
+ }
4372
+ return Object.assign(Object.assign({}, checkoutSession), { landedCost: foundLandedCost });
4373
+ }).filter(Boolean)) || null;
4374
+ cartStore.shippingData =
4375
+ (shipmentRatingCalculateWorkflow === null || shipmentRatingCalculateWorkflow === void 0 ? void 0 : shipmentRatingCalculateWorkflow.filter(Boolean)) || null;
4376
+ // apply new subtotal and total, this is mainly to show items in the presentment currency
4377
+ const firstLandedCostData = (_f = cartStore.landedCostData) === null || _f === void 0 ? void 0 : _f.find(Boolean);
4378
+ const subtotals = !!firstLandedCostData
4379
+ ? firstLandedCostData.subtotals
4380
+ : null;
4381
+ if (subtotals) {
4382
+ // prefetch landed cost will not update shipping and taxes since we haven't selected shipping method yet
4383
+ cartStoreApplySubtotals({
4384
+ exchangeRate: subtotals.exchangeRate,
4385
+ items: subtotals.items,
4386
+ landedCostTotal: 0,
4387
+ presentmentCurrencyCode: subtotals.presentmentCurrencyCode,
4388
+ shipping: 0,
4389
+ total: subtotals.items,
4390
+ });
4391
+ }
4392
+ }
4393
+ catch (err) {
4394
+ logError(err);
4395
+ }
4396
+ stripeStore.isFetchingLandedCost = false;
4397
+ }
4398
+ };
4399
+ const getStripeMessageBasedOnStatus = (status) => {
4400
+ let messages = [];
4401
+ let isError = true;
4402
+ // Inspect the PaymentIntent `status` to indicate the status of the payment
4403
+ // to your customer.
4404
+ //
4405
+ // Some payment methods will [immediately succeed or fail][0] upon
4406
+ // confirmation, while others will first enter a `processing` state.
4407
+ //
4408
+ // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
4409
+ switch (status) {
4410
+ case 'succeeded': {
4411
+ messages = [
4412
+ translate('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.'),
4413
+ '',
4414
+ '',
4415
+ translate("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."),
4416
+ ];
4417
+ isError = false;
4418
+ break;
4419
+ }
4420
+ case 'requires_capture':
4421
+ case 'processing': {
4422
+ messages = [
4423
+ translate("Payment processing. We'll update you when payment is received."),
4424
+ ];
4425
+ isError = false;
4426
+ break;
4427
+ }
4428
+ case 'requires_payment_method': {
4429
+ messages = [
4430
+ translate('Payment failed. Please try another payment method.'),
4431
+ ];
4432
+ break;
4433
+ }
4434
+ default: {
4435
+ messages = [translate('Something went wrong.')];
4436
+ break;
4437
+ }
4438
+ }
4439
+ return {
4440
+ isError,
4441
+ messages,
4442
+ };
4443
+ };
4444
+ const stripeStoreRetrievePayment = async ({ clientSecret: _clientSecret, storybookForceStatus, }) => {
4445
+ if (storybookForceStatus) {
4446
+ // return status right away if we are in storybook mode
4447
+ const { isError, messages } = getStripeMessageBasedOnStatus(storybookForceStatus);
4448
+ return { error: isError, messages };
4449
+ }
4450
+ const clientSecret = _clientSecret || stripeStore.clientSecret;
4451
+ if (!stripeStore.stripe || !clientSecret) {
4452
+ logError('Failed to retrieve payment intent. Stripe is not initialized');
4453
+ return { error: true, message: [translate('Something went wrong.')] };
4454
+ }
4455
+ const { paymentIntent } = await stripeStore.stripe.retrievePaymentIntent(clientSecret);
4456
+ const status = paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.status;
4457
+ const { isError, messages } = getStripeMessageBasedOnStatus(status);
4458
+ return {
4459
+ error: isError,
4460
+ messages,
4461
+ paymentMethod: paymentIntent === null || paymentIntent === void 0 ? void 0 : paymentIntent.payment_method,
4462
+ };
4463
+ };
4464
+ const stripeStoreConfirmPayment = async () => {
4465
+ var _a, _b, _c;
4466
+ const stripePaymentReady = !!((_a = stripeStore.stripePaymentEventData) === null || _a === void 0 ? void 0 : _a.complete);
4467
+ const stripeElements = stripeStore.stripeElements;
4468
+ const stripe = stripeStore.stripe;
4469
+ const stripeClientSecret = stripeStore.clientSecret;
4470
+ if (stripe && stripeElements && stripePaymentReady && stripeClientSecret) {
4471
+ const { error } = await stripe.confirmPayment({
4472
+ confirmParams: {
4473
+ receipt_email: (_c = (_b = stripeStore.stripeLinkEventData) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.email,
4474
+ return_url: window.location.href,
4475
+ },
4476
+ elements: stripeElements,
4477
+ redirect: 'if_required',
4478
+ });
4479
+ if (error) {
4480
+ if (error.type === 'card_error' || error.type === 'validation_error') {
4481
+ throw new Error(error.message);
4482
+ }
4483
+ if (error.type === 'invalid_request_error') {
4484
+ if (error.code === 'payment_intent_unexpected_state') {
4485
+ // PaymentIntent was canceled or expired, or status is `require_capture`.
4486
+ // don't throw error here because we will reset the checkout session last step
4487
+ return;
4488
+ }
4489
+ }
4490
+ throw new Error('An unexpected error occurred.');
4491
+ }
4492
+ }
4493
+ };
4494
+ /**
4495
+ * Init checkout session
4496
+ * @returns {boolean} whether or not the checkout session is successfully created
4497
+ */
4498
+ const stripeStoreInitCheckoutSession = async () => {
4499
+ var _a;
4500
+ const total = cartStore.items.reduce((amount, item) => amount + item.amount * item.quantity, 0);
4501
+ if (!total || !localizationStore.targetCurrency) {
4502
+ logError('Fail to create checkout session - invalid total or currency');
4503
+ return false;
4504
+ }
4505
+ stripeStore.isFetchingSession = true;
4506
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/create-checkout-session`, {
4507
+ body: {
4508
+ currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
4509
+ itemsAmount: total,
4510
+ metadata: [
4511
+ { key: 'language', value: localizationStore.selectedLocale },
4512
+ ],
4513
+ presentmentCountryCode: localizationStore.selectedCountryCode || null,
4514
+ },
4515
+ method: 'POST',
4516
+ });
4517
+ stripeStore.isFetchingSession = false;
4518
+ if (errors.length || !json) {
4519
+ logError('Error occurs when creating checkout session', JSON.stringify(errors, null, 2));
4520
+ return false;
4521
+ }
4522
+ const result = json.checkoutSessionCreate;
4523
+ stripeStore.clientSecret = result.clientSecret;
4524
+ // update cart store with updated informations
4525
+ cartStore.checkoutSessionId = result.id;
4526
+ cartStoreApplySubtotals(Object.assign(Object.assign({}, result.subtotals), { landedCostTotal: 0, shipping: 0, total: result.subtotals.items }));
4527
+ log('Exchange rate updated for cart items (checkout session create)', 'info', cartStore.exchangeRate);
4528
+ log('done-init-checkout-session');
4529
+ return true;
4530
+ };
4531
+ /**
4532
+ * Update checkout session. Use for updating amount with landed cost id, or update session when cart items change
4533
+ */
4534
+ const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
4535
+ // No need to set loading state here because this function will be called under the hood to update
4536
+ // landed cost id for the section.
4537
+ const { errors, json } = await handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/update-checkout-session`, {
4538
+ body: {
4539
+ currency,
4540
+ id,
4541
+ itemsAmount,
4542
+ landedCostId,
4543
+ presentmentCountryCode,
4544
+ },
4545
+ method: 'POST',
4546
+ });
4547
+ if (errors.length || !json) {
4548
+ logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
4549
+ return { errors, json };
4550
+ }
4551
+ return { errors: [], json };
4552
+ };
4553
+ onChange$1('clientSecret', clientSecret => {
4554
+ // update stripe elements when client secret changes
4555
+ if (clientSecret && stripeStore.stripe) {
4556
+ sessionStorage.setItem('zonos--client-secret', clientSecret);
4557
+ }
4558
+ if (!clientSecret) {
4559
+ sessionStorage.removeItem('zonos--client-secret');
4560
+ }
4561
+ });
4562
+
4563
+ const formatDate = ({ date, formatOptions = { day: 'numeric', weekday: 'long', year: 'numeric' }, }) => {
4564
+ // format date to Thursday 3, 2023
4565
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
4566
+ };
4567
+
4568
+ const getDaysDifference = (targetDate) => {
4569
+ const currentDate = new Date();
4570
+ const timeDifference = targetDate.getTime() - currentDate.getTime();
4571
+ const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); // Convert milliseconds to days
4572
+ return daysDifference;
4573
+ };
4574
+
4575
+ const { onChange, reset, state: cartStore, } = createStore(() => ({
4576
+ checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id') || null,
4577
+ currency: 'USD',
4578
+ dutiesTaxFees: 0,
4579
+ error: null,
4580
+ exchangeRate: null,
4581
+ isSelectedShippingAboveDeminimis: false,
4582
+ isSelectedShippingGuarantee: false,
4583
+ items: [],
4584
+ landedCostData: null,
4585
+ selectedLandedCost: null,
4586
+ selectedShippingOption: null,
4587
+ selectedShippingOptionExpectedDate: '',
4588
+ selectedShippingOptionTransitTime: '',
4589
+ shipping: 0,
4590
+ shippingData: null,
4591
+ step: 'customer-info',
4592
+ subtotal: 0,
4593
+ total: 0,
4594
+ }));
4595
+ /**
4596
+ * Format shipping transit info to be displayed on UI
4597
+ * @returns
4598
+ * - expectedDate: Thursday, Aug 12
4599
+ * - maxTransit: 5
4600
+ * - minTransit: 3
4601
+ */
4602
+ const cartStoreGetShippingTransitInfo = (item) => {
4603
+ const minTransit = item.minTransitAt
4604
+ ? getDaysDifference(new Date(item.minTransitAt))
4605
+ : '';
4606
+ const maxTransit = item.maxTransitAt
4607
+ ? getDaysDifference(new Date(item.maxTransitAt))
4608
+ : '';
4609
+ const expectedDate = item.minTransitAt
4610
+ ? formatDate({
4611
+ date: new Date(item.minTransitAt),
4612
+ })
4613
+ : '';
4614
+ return {
4615
+ expectedDate,
4616
+ maxTransit,
4617
+ minTransit,
4618
+ };
4619
+ };
4620
+ const cartStoreReset = () => {
4621
+ sessionStorage.removeItem('zonos--checkout-session-id');
4622
+ // reset cart store
4623
+ reset();
4624
+ };
4625
+ const cartStoreUpdateToErrorState = ({ messages, title, }) => {
4626
+ cartStoreReset();
4627
+ stripeStoreReset();
4628
+ cartStore.step = 'error';
4629
+ cartStore.error = {
4630
+ messages,
4631
+ title,
4632
+ };
4633
+ };
4634
+ const cartStoreApplySubtotals = (subtotals) => {
4635
+ // update exchange rate so we can use it to display cart items
4636
+ cartStore.exchangeRate = subtotals.exchangeRate;
4637
+ cartStore.dutiesTaxFees = subtotals.landedCostTotal;
4638
+ cartStore.subtotal = subtotals.items;
4639
+ cartStore.total = subtotals.total;
4640
+ cartStore.currency = subtotals.presentmentCurrencyCode;
4641
+ };
4642
+ const cartStoreReCalculateTotal = async ({ currency, itemsAmount, landedCostId, }) => {
4643
+ if (landedCostId && cartStore.selectedLandedCost) {
4644
+ // update cart total right away if we have landed cost id to avoid order total flickering
4645
+ const subtotals = cartStore.selectedLandedCost.subtotals;
4646
+ cartStoreApplySubtotals(subtotals);
4647
+ log('Exchange rate updated for cart items (landed cost subtotal)', 'info', cartStore.exchangeRate);
4648
+ }
4649
+ // update checkout session
4650
+ if (!cartStore.checkoutSessionId) {
4651
+ logError('Could not update cart total without checkout session id');
4652
+ return false;
4653
+ }
4654
+ const { errors, json } = await stripeStoreUpdateCheckoutSession({
4655
+ currency,
4656
+ id: cartStore.checkoutSessionId,
4657
+ itemsAmount,
4658
+ landedCostId,
4659
+ presentmentCountryCode: localizationStore.selectedCountryCode,
4660
+ });
4661
+ if (errors.length > 0 || !json) {
4662
+ // do nothing if we can't get checkout session
4663
+ logError('Error occurs when updating checkout session');
4664
+ cartStoreUpdateToErrorState({
4665
+ messages: [
4666
+ translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists"),
4667
+ ],
4668
+ title: translate('Error updating Checkout'),
4669
+ });
4670
+ return false;
4671
+ }
4672
+ if (!landedCostId) {
4673
+ // This is when first open the checkout modal and we just want to get info from the old cart session.
4674
+ // use subtotals from checkout session to update cart total
4675
+ cartStoreApplySubtotals(json.checkoutSessionUpdate.subtotals);
4676
+ log('Exchange rate updated for cart items (checkout session update)', 'info', cartStore.exchangeRate);
4677
+ }
4678
+ return true;
4679
+ };
4680
+ const cartStoreUpdateSelectedShippingOption = async (selectedShippingOption) => {
4681
+ var _a, _b, _c, _d, _e;
4682
+ cartStore.selectedShippingOption = selectedShippingOption;
4683
+ // update shipping transit info
4684
+ const { expectedDate, maxTransit, minTransit } = cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption);
4685
+ cartStore.selectedShippingOptionExpectedDate = expectedDate;
4686
+ cartStore.selectedShippingOptionTransitTime =
4687
+ minTransit && maxTransit
4688
+ ? `${minTransit}-${maxTransit}`
4689
+ : `${minTransit || maxTransit}`;
4690
+ const selectedLandedCost = (_a = cartStore.landedCostData) === null || _a === void 0 ? void 0 : _a.find(checkoutSessionPresentment => {
4691
+ var _a, _b, _c;
4692
+ return ((_b = (_a = checkoutSessionPresentment.landedCost) === null || _a === void 0 ? void 0 : _a.shipmentRating) === null || _b === void 0 ? void 0 : _b.id) ===
4693
+ ((_c = cartStore.selectedShippingOption) === null || _c === void 0 ? void 0 : _c.id);
4694
+ });
4695
+ // save selected landed cost for later use
4696
+ cartStore.selectedLandedCost = selectedLandedCost || null;
4697
+ if (!selectedLandedCost) {
4698
+ // do nothing if we can't find landed cost for selected shipping option
4699
+ return false;
4700
+ }
4701
+ // update shipping value and dutiesTaxFees on selectedShippingOption change
4702
+ cartStore.shipping = selectedLandedCost.subtotals.shipping;
4703
+ // update deminimis status
4704
+ const isGuarantee = ((_b = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _b === void 0 ? void 0 : _b.landedCostGuaranteeCode) === 'ZONOS';
4705
+ // one item in deminimis with type of duty and tax has threshold value is "ABOVE"
4706
+ const isAboveDeminimis = !!((_d = (_c = selectedLandedCost === null || selectedLandedCost === void 0 ? void 0 : selectedLandedCost.landedCost) === null || _c === void 0 ? void 0 : _c.deMinimis) === null || _d === void 0 ? void 0 : _d.find(item => ['DUTY', 'TAX'].includes(item.type) && item.threshold === 'ABOVE'));
4707
+ cartStore.isSelectedShippingAboveDeminimis = isAboveDeminimis;
4708
+ cartStore.isSelectedShippingGuarantee = isGuarantee;
4709
+ // update session with selected landed cost
4710
+ const updateCalulateStatus = await cartStoreReCalculateTotal({
4711
+ landedCostId: (_e = selectedLandedCost.landedCost) === null || _e === void 0 ? void 0 : _e.id,
4712
+ });
4713
+ return updateCalulateStatus;
4714
+ };
4715
+ onChange('checkoutSessionId', () => {
4716
+ if (!cartStore.checkoutSessionId) {
4717
+ sessionStorage.removeItem('zonos--checkout-session-id');
4718
+ return;
4719
+ }
4720
+ sessionStorage.setItem('zonos--checkout-session-id', cartStore.checkoutSessionId);
4721
+ });
4722
+ const cartStoreUpdateItems = async (items) => {
4723
+ var _a;
4724
+ cartStore.items = items;
4725
+ const currency = (_a = items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode;
4726
+ const total = items.reduce((amt, item) => {
4727
+ return amt + item.amount * item.quantity;
4728
+ }, 0);
4729
+ if (!currency || !total) {
4730
+ // do nothing if we can't get currency or total
4731
+ return;
4732
+ }
4733
+ cartStore.currency = currency;
4734
+ // set loading state here because this is first load checkout session when we already have checkout session id stored
4735
+ stripeStore.isFetchingSession = true;
4736
+ await cartStoreReCalculateTotal({
4737
+ currency: currency,
4738
+ itemsAmount: total,
4739
+ });
4740
+ stripeStore.isFetchingSession = false;
4741
+ };
4742
+ const cartStoreResetSelectedShippingOption = () => {
4743
+ cartStore.selectedShippingOption = null;
4744
+ cartStore.isSelectedShippingAboveDeminimis = false;
4745
+ cartStore.isSelectedShippingGuarantee = false;
4746
+ cartStore.selectedShippingOptionExpectedDate = '';
4747
+ cartStore.selectedShippingOptionTransitTime = '';
4748
+ cartStore.shipping = 0;
4749
+ };
4750
+ const cartStoreNextStep = () => {
4751
+ if (cartStore.step === 'customer-info') {
4752
+ cartStore.step = 'shipping';
4753
+ }
4754
+ else if (cartStore.step === 'shipping') {
4755
+ cartStore.step = 'payment';
4756
+ }
4757
+ else if (cartStore.step === 'payment') {
4758
+ cartStore.step = 'finish';
4759
+ }
4760
+ };
4761
+ const cartStorePreviousStep = () => {
4762
+ if (cartStore.step === 'payment') {
4763
+ cartStore.step = 'shipping';
4764
+ }
4765
+ else if (cartStore.step === 'shipping') {
4766
+ cartStore.step = 'customer-info';
4767
+ // reset selected shipping option
4768
+ cartStoreResetSelectedShippingOption();
4769
+ }
4014
4770
  };
4015
4771
 
4016
- export { log as a, logError as b, initLocalizationStore as c, localizationStoreUpdateSelectedCountryCode as d, currencyDisplay as e, currencyConvertAndFormat as f, getZCountryUrlParam as g, handleFetch as h, isValidSelector as i, currencyConvert as j, currencyFormat as k, localizationStore as l, localizationStoreUpdateSelectedLocale as m, setZCountryUrlParam as s, translate as t };
4772
+ export { currencyConvertAndFormat as A, currencyConvert as B, currencyFormat as C, stripeStoreRetrievePayment as D, cartStoreUpdateSelectedShippingOption as E, cartStoreGetShippingTransitInfo as F, localizationStoreUpdateSelectedLocale as G, log as a, localizationStoreUpdateSelectedCountryCode as b, stripeStoreCleanupDomesticShippingSession as c, logError as d, stripeStoreSaveDomesticShippingSession as e, cartStore as f, cartStoreUpdateItems as g, cartStoreReset as h, initStripeElements as i, stripeStore as j, stripeStoreInitCheckoutSession as k, localizationStore as l, cartStoreUpdateToErrorState as m, stripeStorePrefetchLandedCost as n, cartStoreNextStep as o, stripeStoreConfirmPayment as p, stripeStoreReset as q, cartStorePreviousStep as r, stripeStoreGetDomesticShippingSession as s, translate as t, handleFetch as u, isValidSelector as v, initLocalizationStore as w, getZCountryUrlParam as x, setZCountryUrlParam as y, currencyDisplay as z };