@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.
Files changed (51) hide show
  1. package/dist/cjs/{cart-f31374d4.js → cart-f038cf46.js} +6 -1
  2. package/dist/cjs/index.cjs.js +1 -1
  3. package/dist/cjs/zonos-address_2.cjs.entry.js +36 -26
  4. package/dist/cjs/zonos-cart-items_10.cjs.entry.js +1 -1
  5. package/dist/cjs/zonos-checkout.cjs.entry.js +1 -1
  6. package/dist/cjs/zonos-controller.cjs.entry.js +1 -1
  7. package/dist/cjs/zonos-payment.cjs.entry.js +1 -1
  8. package/dist/collection/components/stripe/zonos-address/zonos-address.js +35 -25
  9. package/dist/collection/components/utils/api/calculateLandedCost.js +6 -1
  10. package/dist/components/cart.js +6 -1
  11. package/dist/components/zonos-address2.js +35 -25
  12. package/dist/esm/{cart-c9124cc3.js → cart-ba9b0d4c.js} +6 -1
  13. package/dist/esm/index.js +1 -1
  14. package/dist/esm/zonos-address_2.entry.js +36 -26
  15. package/dist/esm/zonos-cart-items_10.entry.js +1 -1
  16. package/dist/esm/zonos-checkout.entry.js +1 -1
  17. package/dist/esm/zonos-controller.entry.js +1 -1
  18. package/dist/esm/zonos-payment.entry.js +1 -1
  19. package/dist/esm-es5/cart-ba9b0d4c.js +1 -0
  20. package/dist/esm-es5/index.js +1 -1
  21. package/dist/esm-es5/zonos-address_2.entry.js +1 -1
  22. package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
  23. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  24. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  25. package/dist/esm-es5/zonos-payment.entry.js +1 -1
  26. package/dist/scripts/loadZonos.js +1 -1
  27. package/dist/scripts/zonos.js +1 -1
  28. package/dist/scripts/zonosBase.js +1 -1
  29. package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +1 -0
  30. package/dist/zonos-elements/index.esm.js +1 -1
  31. package/dist/zonos-elements/{p-ffc91e42.entry.js → p-1165b6e5.entry.js} +1 -1
  32. package/dist/zonos-elements/{p-741a1402.system.entry.js → p-12c19be6.system.entry.js} +1 -1
  33. package/dist/zonos-elements/p-245997d9.js +1 -0
  34. package/dist/zonos-elements/{p-c134eecd.system.js → p-59343e23.system.js} +1 -1
  35. package/dist/zonos-elements/{p-f7b1dfd0.system.entry.js → p-7beaee33.system.entry.js} +1 -1
  36. package/dist/zonos-elements/{p-43220d68.entry.js → p-824ebf9d.entry.js} +1 -1
  37. package/dist/zonos-elements/p-839f6cd9.entry.js +1 -0
  38. package/dist/zonos-elements/{p-62851827.system.entry.js → p-8970e202.system.entry.js} +1 -1
  39. package/dist/zonos-elements/p-b035f9e5.system.js +1 -1
  40. package/dist/zonos-elements/{p-b494d540.entry.js → p-be4bc6bc.entry.js} +1 -1
  41. package/dist/zonos-elements/p-c3d75f4f.system.js +1 -0
  42. package/dist/zonos-elements/{p-d170748c.system.entry.js → p-da2387d2.system.entry.js} +1 -1
  43. package/dist/zonos-elements/p-dcf1e1b4.system.entry.js +1 -0
  44. package/dist/zonos-elements/{p-139fc767.entry.js → p-fdb9568e.entry.js} +1 -1
  45. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  46. package/package.json +1 -1
  47. package/dist/esm-es5/cart-c9124cc3.js +0 -1
  48. package/dist/zonos-elements/p-2ac66cea.system.entry.js +0 -1
  49. package/dist/zonos-elements/p-51a40ddf.system.js +0 -1
  50. package/dist/zonos-elements/p-97e659b7.entry.js +0 -1
  51. package/dist/zonos-elements/p-e59b6648.js +0 -1
@@ -56,6 +56,7 @@ const triggerBuildLandedCost = async (buildLandedCost) => {
56
56
  };
57
57
 
58
58
  const calculateLandedCost = async (abortController) => {
59
+ var _a;
59
60
  // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
60
61
  const buildLandedCost = zonosStore.zonosStore.checkoutSettings.buildLandedCost;
61
62
  if (buildLandedCost) {
@@ -70,7 +71,11 @@ const calculateLandedCost = async (abortController) => {
70
71
  signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
71
72
  });
72
73
  if (errors.length || !json) {
73
- throw new Error('Failed to calculate landed cost');
74
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
75
+ const errorMessage = isAbortedRequest
76
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
77
+ : 'Failed to calculate landed cost';
78
+ throw new Error(errorMessage);
74
79
  }
75
80
  return json;
76
81
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const cart = require('./cart-f31374d4.js');
5
+ const cart = require('./cart-f038cf46.js');
6
6
  require('./zonosStore-b88b5671.js');
7
7
  require('./index-3ead02fe.js');
8
8
  require('./localization-d43e1540.js');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-3ead02fe.js');
6
- const cart = require('./cart-f31374d4.js');
6
+ const cart = require('./cart-f038cf46.js');
7
7
  const localization = require('./localization-d43e1540.js');
8
8
  require('./zonosStore-b88b5671.js');
9
9
  require('./isDarkColor-5eda1323.js');
@@ -21,7 +21,7 @@ const ZonosAddress = class {
21
21
  this.stripe = window.Zonos.stripe;
22
22
  }
23
23
  async watchInitStripe() {
24
- var _a, _b;
24
+ var _a, _b, _c, _d, _e, _f, _g;
25
25
  this.stripe = window.Zonos.stripe;
26
26
  if (!this.stripe || !cart.stripeStore.stripeElements) {
27
27
  localization.logError("Stripe is not initialized. Couldn't load stripe element.");
@@ -34,30 +34,35 @@ const ZonosAddress = class {
34
34
  (_b = this.defaultAddress) === null || _b === void 0 ? true : delete _b.phone;
35
35
  }
36
36
  const shippableCountries = localization.localizationStore.shippingZoneCountries;
37
- const addressElement = cart.stripeStore.stripeAddressElement ||
38
- cart.stripeStore.stripeElements.create('address', {
39
- allowedCountries: shippableCountries
40
- ? Object.values(shippableCountries).map(country => country.code)
41
- : [],
42
- contacts: this.defaultAddress ? [this.defaultAddress] : undefined,
43
- defaultValues: {
44
- address: {
45
- country: localization.localizationStore.selectedCountryCode || 'AL',
46
- },
37
+ const addressElement = cart.stripeStore.stripeElements.create('address', {
38
+ allowedCountries: shippableCountries
39
+ ? Object.values(shippableCountries).map(country => country.code)
40
+ : [],
41
+ autocomplete: {
42
+ mode: 'automatic',
43
+ },
44
+ contacts: this.defaultAddress ? [this.defaultAddress] : [],
45
+ defaultValues: {
46
+ address: Object.assign(Object.assign({}, (_c = cart.stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.address), { country: ((_d = cart.stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value.address.country) ||
47
+ localization.localizationStore.selectedCountryCode ||
48
+ 'AL' }),
49
+ firstName: (_e = cart.stripeStore.stripeAddressEventData) === null || _e === void 0 ? void 0 : _e.value.firstName,
50
+ lastName: (_f = cart.stripeStore.stripeAddressEventData) === null || _f === void 0 ? void 0 : _f.value.lastName,
51
+ phone: (_g = cart.stripeStore.stripeAddressEventData) === null || _g === void 0 ? void 0 : _g.value.phone,
52
+ },
53
+ display: {
54
+ name: 'split',
55
+ },
56
+ fields: {
57
+ phone: 'always',
58
+ },
59
+ mode: this.type,
60
+ validation: {
61
+ phone: {
62
+ required: 'always',
47
63
  },
48
- display: {
49
- name: 'split',
50
- },
51
- fields: {
52
- phone: 'always',
53
- },
54
- mode: this.type,
55
- validation: {
56
- phone: {
57
- required: 'always',
58
- },
59
- },
60
- });
64
+ },
65
+ });
61
66
  addressElement.mount(this.el.querySelector('.zonos--address-component'));
62
67
  addressElement.on('change', event => {
63
68
  const eventValue = event.value;
@@ -67,13 +72,18 @@ const ZonosAddress = class {
67
72
  });
68
73
  cart.stripeStore.stripeAddressElement = addressElement;
69
74
  }
75
+ disconnectedCallback() {
76
+ var _a;
77
+ // destroy the stripe element when this component is removed from the DOM, so that we can re-create the new one with previous value
78
+ (_a = cart.stripeStore.stripeAddressElement) === null || _a === void 0 ? void 0 : _a.destroy();
79
+ }
70
80
  componentDidLoad() {
71
81
  // @Watch doesn't get trigger on initial load
72
82
  void this.watchInitStripe();
73
83
  }
74
84
  render() {
75
85
  // this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
76
- return (index.h(index.Host, { key: '47fa225123b7c944732b018fbb374bcb6da0f4ca', class: "zonos--address zonos--elements" }, index.h("zonos-text", { key: '4d0d9d4f9c09d6b2f29bc6a44164a0ef8db0acc9', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), index.h("div", { key: 'd279ba97287890e489230f9e449a344db76556f2', class: "zonos--address-component" })));
86
+ return (index.h(index.Host, { key: 'f376a81e62581bff4ac25d53f11c8e53408f9e7e', class: "zonos--address zonos--elements" }, index.h("zonos-text", { key: 'bdc1a8b7414cae0e79c90e0685700590cd920468', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), index.h("div", { key: 'fe384f4c0e508a9f8ddff8fa579c504c3f18e7bb', class: "zonos--address-component" })));
77
87
  }
78
88
  get el() { return index.getElement(this); }
79
89
  static get watchers() { return {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-3ead02fe.js');
6
- const cart = require('./cart-f31374d4.js');
6
+ const cart = require('./cart-f038cf46.js');
7
7
  const localization = require('./localization-d43e1540.js');
8
8
  const zonosStore = require('./zonosStore-b88b5671.js');
9
9
  const getBorderRadius = require('./getBorderRadius-cd7ef574.js');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-3ead02fe.js');
6
- const cart = require('./cart-f31374d4.js');
6
+ const cart = require('./cart-f038cf46.js');
7
7
  const localization = require('./localization-d43e1540.js');
8
8
  const zonosStore = require('./zonosStore-b88b5671.js');
9
9
  const submitGtag = require('./submitGtag-42f29b3a.js');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-3ead02fe.js');
6
- const cart = require('./cart-f31374d4.js');
6
+ const cart = require('./cart-f038cf46.js');
7
7
  const localization = require('./localization-d43e1540.js');
8
8
  const zonosStore = require('./zonosStore-b88b5671.js');
9
9
  require('./isDarkColor-5eda1323.js');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-3ead02fe.js');
6
- const cart = require('./cart-f31374d4.js');
6
+ const cart = require('./cart-f038cf46.js');
7
7
  require('./zonosStore-b88b5671.js');
8
8
  require('./localization-d43e1540.js');
9
9
  require('./isDarkColor-5eda1323.js');
@@ -14,7 +14,7 @@ export class ZonosAddress {
14
14
  this.stripe = window.Zonos.stripe;
15
15
  }
16
16
  async watchInitStripe() {
17
- var _a, _b;
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
18
  this.stripe = window.Zonos.stripe;
19
19
  if (!this.stripe || !stripeStore.stripeElements) {
20
20
  logError("Stripe is not initialized. Couldn't load stripe element.");
@@ -27,30 +27,35 @@ export class ZonosAddress {
27
27
  (_b = this.defaultAddress) === null || _b === void 0 ? true : delete _b.phone;
28
28
  }
29
29
  const shippableCountries = localizationStore.shippingZoneCountries;
30
- const addressElement = stripeStore.stripeAddressElement ||
31
- stripeStore.stripeElements.create('address', {
32
- allowedCountries: shippableCountries
33
- ? Object.values(shippableCountries).map(country => country.code)
34
- : [],
35
- contacts: this.defaultAddress ? [this.defaultAddress] : undefined,
36
- defaultValues: {
37
- address: {
38
- country: localizationStore.selectedCountryCode || 'AL',
39
- },
40
- },
41
- display: {
42
- name: 'split',
43
- },
44
- fields: {
45
- phone: 'always',
46
- },
47
- mode: this.type,
48
- validation: {
49
- phone: {
50
- required: 'always',
51
- },
30
+ const addressElement = stripeStore.stripeElements.create('address', {
31
+ allowedCountries: shippableCountries
32
+ ? Object.values(shippableCountries).map(country => country.code)
33
+ : [],
34
+ autocomplete: {
35
+ mode: 'automatic',
36
+ },
37
+ contacts: this.defaultAddress ? [this.defaultAddress] : [],
38
+ defaultValues: {
39
+ address: Object.assign(Object.assign({}, (_c = stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.address), { country: ((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value.address.country) ||
40
+ localizationStore.selectedCountryCode ||
41
+ 'AL' }),
42
+ firstName: (_e = stripeStore.stripeAddressEventData) === null || _e === void 0 ? void 0 : _e.value.firstName,
43
+ lastName: (_f = stripeStore.stripeAddressEventData) === null || _f === void 0 ? void 0 : _f.value.lastName,
44
+ phone: (_g = stripeStore.stripeAddressEventData) === null || _g === void 0 ? void 0 : _g.value.phone,
45
+ },
46
+ display: {
47
+ name: 'split',
48
+ },
49
+ fields: {
50
+ phone: 'always',
51
+ },
52
+ mode: this.type,
53
+ validation: {
54
+ phone: {
55
+ required: 'always',
52
56
  },
53
- });
57
+ },
58
+ });
54
59
  addressElement.mount(this.el.querySelector('.zonos--address-component'));
55
60
  addressElement.on('change', event => {
56
61
  const eventValue = event.value;
@@ -60,13 +65,18 @@ export class ZonosAddress {
60
65
  });
61
66
  stripeStore.stripeAddressElement = addressElement;
62
67
  }
68
+ disconnectedCallback() {
69
+ var _a;
70
+ // destroy the stripe element when this component is removed from the DOM, so that we can re-create the new one with previous value
71
+ (_a = stripeStore.stripeAddressElement) === null || _a === void 0 ? void 0 : _a.destroy();
72
+ }
63
73
  componentDidLoad() {
64
74
  // @Watch doesn't get trigger on initial load
65
75
  void this.watchInitStripe();
66
76
  }
67
77
  render() {
68
78
  // this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
69
- return (h(Host, { key: '47fa225123b7c944732b018fbb374bcb6da0f4ca', class: "zonos--address zonos--elements" }, h("zonos-text", { key: '4d0d9d4f9c09d6b2f29bc6a44164a0ef8db0acc9', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'd279ba97287890e489230f9e449a344db76556f2', class: "zonos--address-component" })));
79
+ return (h(Host, { key: 'f376a81e62581bff4ac25d53f11c8e53408f9e7e', class: "zonos--address zonos--elements" }, h("zonos-text", { key: 'bdc1a8b7414cae0e79c90e0685700590cd920468', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'fe384f4c0e508a9f8ddff8fa579c504c3f18e7bb', class: "zonos--address-component" })));
70
80
  }
71
81
  static get is() { return "zonos-address"; }
72
82
  static get encapsulation() { return "scoped"; }
@@ -3,6 +3,7 @@ import { prepCalculateLandedCost } from "./prepCalculateLandedCost";
3
3
  import { triggerBuildLandedCost } from "./triggerBuildLandedCost";
4
4
  import { handleFetch } from "../handleFetch";
5
5
  export const calculateLandedCost = async (abortController) => {
6
+ var _a;
6
7
  // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
7
8
  const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
8
9
  if (buildLandedCost) {
@@ -17,7 +18,11 @@ export const calculateLandedCost = async (abortController) => {
17
18
  signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
18
19
  });
19
20
  if (errors.length || !json) {
20
- throw new Error('Failed to calculate landed cost');
21
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
22
+ const errorMessage = isAbortedRequest
23
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
24
+ : 'Failed to calculate landed cost';
25
+ throw new Error(errorMessage);
21
26
  }
22
27
  return json;
23
28
  };
@@ -54,6 +54,7 @@ const triggerBuildLandedCost = async (buildLandedCost) => {
54
54
  };
55
55
 
56
56
  const calculateLandedCost = async (abortController) => {
57
+ var _a;
57
58
  // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
58
59
  const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
59
60
  if (buildLandedCost) {
@@ -68,7 +69,11 @@ const calculateLandedCost = async (abortController) => {
68
69
  signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
69
70
  });
70
71
  if (errors.length || !json) {
71
- throw new Error('Failed to calculate landed cost');
72
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
73
+ const errorMessage = isAbortedRequest
74
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
75
+ : 'Failed to calculate landed cost';
76
+ throw new Error(errorMessage);
72
77
  }
73
78
  return json;
74
79
  };
@@ -16,7 +16,7 @@ const ZonosAddress = /*@__PURE__*/ proxyCustomElement(class ZonosAddress extends
16
16
  this.stripe = window.Zonos.stripe;
17
17
  }
18
18
  async watchInitStripe() {
19
- var _a, _b;
19
+ var _a, _b, _c, _d, _e, _f, _g;
20
20
  this.stripe = window.Zonos.stripe;
21
21
  if (!this.stripe || !stripeStore.stripeElements) {
22
22
  logError("Stripe is not initialized. Couldn't load stripe element.");
@@ -29,30 +29,35 @@ const ZonosAddress = /*@__PURE__*/ proxyCustomElement(class ZonosAddress extends
29
29
  (_b = this.defaultAddress) === null || _b === void 0 ? true : delete _b.phone;
30
30
  }
31
31
  const shippableCountries = localizationStore.shippingZoneCountries;
32
- const addressElement = stripeStore.stripeAddressElement ||
33
- stripeStore.stripeElements.create('address', {
34
- allowedCountries: shippableCountries
35
- ? Object.values(shippableCountries).map(country => country.code)
36
- : [],
37
- contacts: this.defaultAddress ? [this.defaultAddress] : undefined,
38
- defaultValues: {
39
- address: {
40
- country: localizationStore.selectedCountryCode || 'AL',
41
- },
32
+ const addressElement = stripeStore.stripeElements.create('address', {
33
+ allowedCountries: shippableCountries
34
+ ? Object.values(shippableCountries).map(country => country.code)
35
+ : [],
36
+ autocomplete: {
37
+ mode: 'automatic',
38
+ },
39
+ contacts: this.defaultAddress ? [this.defaultAddress] : [],
40
+ defaultValues: {
41
+ address: Object.assign(Object.assign({}, (_c = stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.address), { country: ((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value.address.country) ||
42
+ localizationStore.selectedCountryCode ||
43
+ 'AL' }),
44
+ firstName: (_e = stripeStore.stripeAddressEventData) === null || _e === void 0 ? void 0 : _e.value.firstName,
45
+ lastName: (_f = stripeStore.stripeAddressEventData) === null || _f === void 0 ? void 0 : _f.value.lastName,
46
+ phone: (_g = stripeStore.stripeAddressEventData) === null || _g === void 0 ? void 0 : _g.value.phone,
47
+ },
48
+ display: {
49
+ name: 'split',
50
+ },
51
+ fields: {
52
+ phone: 'always',
53
+ },
54
+ mode: this.type,
55
+ validation: {
56
+ phone: {
57
+ required: 'always',
42
58
  },
43
- display: {
44
- name: 'split',
45
- },
46
- fields: {
47
- phone: 'always',
48
- },
49
- mode: this.type,
50
- validation: {
51
- phone: {
52
- required: 'always',
53
- },
54
- },
55
- });
59
+ },
60
+ });
56
61
  addressElement.mount(this.el.querySelector('.zonos--address-component'));
57
62
  addressElement.on('change', event => {
58
63
  const eventValue = event.value;
@@ -62,13 +67,18 @@ const ZonosAddress = /*@__PURE__*/ proxyCustomElement(class ZonosAddress extends
62
67
  });
63
68
  stripeStore.stripeAddressElement = addressElement;
64
69
  }
70
+ disconnectedCallback() {
71
+ var _a;
72
+ // destroy the stripe element when this component is removed from the DOM, so that we can re-create the new one with previous value
73
+ (_a = stripeStore.stripeAddressElement) === null || _a === void 0 ? void 0 : _a.destroy();
74
+ }
65
75
  componentDidLoad() {
66
76
  // @Watch doesn't get trigger on initial load
67
77
  void this.watchInitStripe();
68
78
  }
69
79
  render() {
70
80
  // this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
71
- return (h(Host, { key: '47fa225123b7c944732b018fbb374bcb6da0f4ca', class: "zonos--address zonos--elements" }, h("zonos-text", { key: '4d0d9d4f9c09d6b2f29bc6a44164a0ef8db0acc9', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'd279ba97287890e489230f9e449a344db76556f2', class: "zonos--address-component" })));
81
+ return (h(Host, { key: 'f376a81e62581bff4ac25d53f11c8e53408f9e7e', class: "zonos--address zonos--elements" }, h("zonos-text", { key: 'bdc1a8b7414cae0e79c90e0685700590cd920468', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'fe384f4c0e508a9f8ddff8fa579c504c3f18e7bb', class: "zonos--address-component" })));
72
82
  }
73
83
  get el() { return this; }
74
84
  static get watchers() { return {
@@ -54,6 +54,7 @@ const triggerBuildLandedCost = async (buildLandedCost) => {
54
54
  };
55
55
 
56
56
  const calculateLandedCost = async (abortController) => {
57
+ var _a;
57
58
  // If buildLandedCost callback is supplied, use that instead of our regular request to '/calculate-landed-cost'
58
59
  const buildLandedCost = zonosStore.checkoutSettings.buildLandedCost;
59
60
  if (buildLandedCost) {
@@ -68,7 +69,11 @@ const calculateLandedCost = async (abortController) => {
68
69
  signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
69
70
  });
70
71
  if (errors.length || !json) {
71
- throw new Error('Failed to calculate landed cost');
72
+ const isAbortedRequest = ((_a = errors[0]) === null || _a === void 0 ? void 0 : _a.message) === 'The user aborted a request.';
73
+ const errorMessage = isAbortedRequest
74
+ ? 'The landed cost calculation request was aborted to initiate a new one.'
75
+ : 'Failed to calculate landed cost';
76
+ throw new Error(errorMessage);
72
77
  }
73
78
  return json;
74
79
  };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { c as cartStore, a as cartStoreApplySubtotals, b as cartStoreGetShippingTransitInfo, d as cartStoreNextStep, e as cartStorePreviousStep, f as cartStoreReCalculateTotal, g as cartStoreReset, h as cartStoreUpdateItems, i as cartStoreUpdateSelectedShippingOption, j as cartStoreUpdateToErrorState } from './cart-c9124cc3.js';
1
+ export { c as cartStore, a as cartStoreApplySubtotals, b as cartStoreGetShippingTransitInfo, d as cartStoreNextStep, e as cartStorePreviousStep, f as cartStoreReCalculateTotal, g as cartStoreReset, h as cartStoreUpdateItems, i as cartStoreUpdateSelectedShippingOption, j as cartStoreUpdateToErrorState } from './cart-ba9b0d4c.js';
2
2
  import './zonosStore-e59617f8.js';
3
3
  import './index-81a199ef.js';
4
4
  import './localization-5d83fde2.js';
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, H as Host, d as getElement } from './index-81a199ef.js';
2
- import { s as stripeStore, m as stripeStorePrefetchLandedCost } from './cart-c9124cc3.js';
2
+ import { s as stripeStore, m as stripeStorePrefetchLandedCost } from './cart-ba9b0d4c.js';
3
3
  import { b as logError, a as localizationStore } from './localization-5d83fde2.js';
4
4
  import './zonosStore-e59617f8.js';
5
5
  import './isDarkColor-8696cb70.js';
@@ -17,7 +17,7 @@ const ZonosAddress = class {
17
17
  this.stripe = window.Zonos.stripe;
18
18
  }
19
19
  async watchInitStripe() {
20
- var _a, _b;
20
+ var _a, _b, _c, _d, _e, _f, _g;
21
21
  this.stripe = window.Zonos.stripe;
22
22
  if (!this.stripe || !stripeStore.stripeElements) {
23
23
  logError("Stripe is not initialized. Couldn't load stripe element.");
@@ -30,30 +30,35 @@ const ZonosAddress = class {
30
30
  (_b = this.defaultAddress) === null || _b === void 0 ? true : delete _b.phone;
31
31
  }
32
32
  const shippableCountries = localizationStore.shippingZoneCountries;
33
- const addressElement = stripeStore.stripeAddressElement ||
34
- stripeStore.stripeElements.create('address', {
35
- allowedCountries: shippableCountries
36
- ? Object.values(shippableCountries).map(country => country.code)
37
- : [],
38
- contacts: this.defaultAddress ? [this.defaultAddress] : undefined,
39
- defaultValues: {
40
- address: {
41
- country: localizationStore.selectedCountryCode || 'AL',
42
- },
33
+ const addressElement = stripeStore.stripeElements.create('address', {
34
+ allowedCountries: shippableCountries
35
+ ? Object.values(shippableCountries).map(country => country.code)
36
+ : [],
37
+ autocomplete: {
38
+ mode: 'automatic',
39
+ },
40
+ contacts: this.defaultAddress ? [this.defaultAddress] : [],
41
+ defaultValues: {
42
+ address: Object.assign(Object.assign({}, (_c = stripeStore.stripeAddressEventData) === null || _c === void 0 ? void 0 : _c.value.address), { country: ((_d = stripeStore.stripeAddressEventData) === null || _d === void 0 ? void 0 : _d.value.address.country) ||
43
+ localizationStore.selectedCountryCode ||
44
+ 'AL' }),
45
+ firstName: (_e = stripeStore.stripeAddressEventData) === null || _e === void 0 ? void 0 : _e.value.firstName,
46
+ lastName: (_f = stripeStore.stripeAddressEventData) === null || _f === void 0 ? void 0 : _f.value.lastName,
47
+ phone: (_g = stripeStore.stripeAddressEventData) === null || _g === void 0 ? void 0 : _g.value.phone,
48
+ },
49
+ display: {
50
+ name: 'split',
51
+ },
52
+ fields: {
53
+ phone: 'always',
54
+ },
55
+ mode: this.type,
56
+ validation: {
57
+ phone: {
58
+ required: 'always',
43
59
  },
44
- display: {
45
- name: 'split',
46
- },
47
- fields: {
48
- phone: 'always',
49
- },
50
- mode: this.type,
51
- validation: {
52
- phone: {
53
- required: 'always',
54
- },
55
- },
56
- });
60
+ },
61
+ });
57
62
  addressElement.mount(this.el.querySelector('.zonos--address-component'));
58
63
  addressElement.on('change', event => {
59
64
  const eventValue = event.value;
@@ -63,13 +68,18 @@ const ZonosAddress = class {
63
68
  });
64
69
  stripeStore.stripeAddressElement = addressElement;
65
70
  }
71
+ disconnectedCallback() {
72
+ var _a;
73
+ // destroy the stripe element when this component is removed from the DOM, so that we can re-create the new one with previous value
74
+ (_a = stripeStore.stripeAddressElement) === null || _a === void 0 ? void 0 : _a.destroy();
75
+ }
66
76
  componentDidLoad() {
67
77
  // @Watch doesn't get trigger on initial load
68
78
  void this.watchInitStripe();
69
79
  }
70
80
  render() {
71
81
  // this component loads iframe from the stripe elements and puts here, so we don't need to do anything here
72
- return (h(Host, { key: '47fa225123b7c944732b018fbb374bcb6da0f4ca', class: "zonos--address zonos--elements" }, h("zonos-text", { key: '4d0d9d4f9c09d6b2f29bc6a44164a0ef8db0acc9', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'd279ba97287890e489230f9e449a344db76556f2', class: "zonos--address-component" })));
82
+ return (h(Host, { key: 'f376a81e62581bff4ac25d53f11c8e53408f9e7e', class: "zonos--address zonos--elements" }, h("zonos-text", { key: 'bdc1a8b7414cae0e79c90e0685700590cd920468', class: "zonos--title", type: "semiBoldLabel" }, this.titleText), h("div", { key: 'fe384f4c0e508a9f8ddff8fa579c504c3f18e7bb', class: "zonos--address-component" })));
73
83
  }
74
84
  get el() { return getElement(this); }
75
85
  static get watchers() { return {
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, a as getAssetPath, h, H as Host, F as Fragment, c as createEvent, d as getElement } from './index-81a199ef.js';
2
- import { c as cartStore, s as stripeStore, p as stripeStoreRetrievePayment, o as stripeStoreReset, i as cartStoreUpdateSelectedShippingOption, b as cartStoreGetShippingTransitInfo } from './cart-c9124cc3.js';
2
+ import { c as cartStore, s as stripeStore, p as stripeStoreRetrievePayment, o as stripeStoreReset, i as cartStoreUpdateSelectedShippingOption, b as cartStoreGetShippingTransitInfo } from './cart-ba9b0d4c.js';
3
3
  import { t as translate, h as handleFetch } from './localization-5d83fde2.js';
4
4
  import { z as zonosStore, d as zonosStoreFontFamily } from './zonosStore-e59617f8.js';
5
5
  import { g as getBorderRadius } from './getBorderRadius-9e4cb3b1.js';
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, F as Fragment, H as Host } from './index-81a199ef.js';
2
- import { k as initStripeElements, c as cartStore, h as cartStoreUpdateItems, g as cartStoreReset, s as stripeStore, l as stripeStoreInitCheckoutSession, j as cartStoreUpdateToErrorState, m as stripeStorePrefetchLandedCost, d as cartStoreNextStep, n as stripeStoreConfirmPayment, o as stripeStoreReset, e as cartStorePreviousStep } from './cart-c9124cc3.js';
2
+ import { k as initStripeElements, c as cartStore, h as cartStoreUpdateItems, g as cartStoreReset, s as stripeStore, l as stripeStoreInitCheckoutSession, j as cartStoreUpdateToErrorState, m as stripeStorePrefetchLandedCost, d as cartStoreNextStep, n as stripeStoreConfirmPayment, o as stripeStoreReset, e as cartStorePreviousStep } from './cart-ba9b0d4c.js';
3
3
  import { a as localizationStore, l as log, t as translate } from './localization-5d83fde2.js';
4
4
  import { z as zonosStore, m as mergeConfig } from './zonosStore-e59617f8.js';
5
5
  import { s as submitGtag, i as isCheckoutMobile } from './submitGtag-a7d07aec.js';
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host } from './index-81a199ef.js';
2
- import { s as stripeStore } from './cart-c9124cc3.js';
2
+ import { s as stripeStore } from './cart-ba9b0d4c.js';
3
3
  import { h as handleFetch, b as logError, i as isValidSelector, l as log, c as initLocalizationStore, d as localizationStoreUpdateSelectedCountryCode } from './localization-5d83fde2.js';
4
4
  import { z as zonosStore, b as zonosStoreInitSetting, d as zonosStoreFontFamily } from './zonosStore-e59617f8.js';
5
5
  import './isDarkColor-8696cb70.js';
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, H as Host, d as getElement } from './index-81a199ef.js';
2
- import { s as stripeStore } from './cart-c9124cc3.js';
2
+ import { s as stripeStore } from './cart-ba9b0d4c.js';
3
3
  import './zonosStore-e59617f8.js';
4
4
  import './localization-5d83fde2.js';
5
5
  import './isDarkColor-8696cb70.js';
@@ -0,0 +1 @@
1
+ var __awaiter=this&&this.__awaiter||function(e,t,r,o){function n(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o["throw"](e))}catch(e){i(e)}}function c(e){e.done?r(e.value):n(e.value).then(a,s)}c((o=o.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},o,n,i,a;return a={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(e){return function(t){return c([e,t])}}function c(s){if(o)throw new TypeError("Generator is already executing.");while(a&&(a=0,s[0]&&(r=0)),r)try{if(o=1,n&&(i=s[0]&2?n["return"]:s[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;if(n=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;n=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(s[0]===6&&r.label<i[1]){r.label=i[1];i=s;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(s);break}if(i[2])r.ops.pop();r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e];n=0}finally{o=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};import{z as zonosStore,c as createStore}from"./zonosStore-e59617f8.js";import{h as handleFetch,l as log,a as localizationStore,b as logError,t as translate}from"./localization-5d83fde2.js";import{i as isDarkColor}from"./isDarkColor-8696cb70.js";import{g as getBorderRadius}from"./getBorderRadius-9e4cb3b1.js";var prepCalculateLandedCost=function(){var e=stripeStore.stripeLinkEventData;var t=stripeStore.stripeAddressEventData;if(!t||!t.complete){throw new Error("Missing stripe address data")}return{checkoutSessionId:cartStore.checkoutSessionId||"",contact:{email:(e===null||e===void 0?void 0:e.value.email)||"",firstName:t.value.firstName||"",lastName:t.value.lastName||"",phone:t.value.phone||""},items:cartStore.items.map((function(e){return 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}}};var triggerBuildLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n,i,a;return __generator(this,(function(s){switch(s.label){case 0:r=prepCalculateLandedCost();return[4,e(r.checkoutSessionId,r.contact,r.shippingAddress)];case 1:o=s.sent();if(!o){throw new Error("Failed to build landed cost")}return[4,handleFetch("".concat("https://v1.route.js.zonos.com","/api/zonos-elements/validate-landed-cost"),{body:o,headers:{"Content-Type":"application/json"},method:"POST"})];case 2:n=s.sent(),i=n.errors,a=n.json;if(!a||i.length){throw new Error("Invalid landed cost object: ".concat(((t=i.find(Boolean))===null||t===void 0?void 0:t.message)||"Unknown error"))}return[2,o]}}))}))};var calculateLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n,i,a,s,c,u;return __generator(this,(function(l){switch(l.label){case 0:r=zonosStore.checkoutSettings.buildLandedCost;if(!r)return[3,2];return[4,triggerBuildLandedCost(r)];case 1:o=l.sent();return[2,o];case 2:n="".concat("https://v1.route.js.zonos.com","/api/zonos-elements/calculate-landed-cost");return[4,handleFetch(n,{body:prepCalculateLandedCost(),method:"POST",signal:e===null||e===void 0?void 0:e.signal})];case 3:i=l.sent(),a=i.errors,s=i.json;if(a.length||!s){c=((t=a[0])===null||t===void 0?void 0:t.message)==="The user aborted a request.";u=c?"The landed cost calculation request was aborted to initiate a new one.":"Failed to calculate landed cost";throw new Error(u)}return[2,s]}}))}))};var addressRuleStyle=function(e){var t=e.theme;switch(t){default:return{".Input":{padding:"0",paddingBottom:"8px",paddingLeft:"16px",paddingRight:"8px",paddingTop:"6px"}}}};var defaultVariable=function(e){var t=e.borderStyle,r=e.theme;switch(r){case"DARK":return{borderRadius:getBorderRadius(t),colorBackground:"#101117",colorBackgroundText:"#C5C6CA",colorText:"#C5C6CA",colorTextPlaceholder:"#C5C6CA"};default:return{borderRadius:getBorderRadius(t)}}};var _f=createStore((function(){return{clientSecret:sessionStorage.getItem("zonos--client-secret")||null,fetchingLandedCostAbordController:null,isFetchingLandedCost:false,isFetchingSession:false,stripe:null,stripeAddressElement:null,stripeAddressEventData:null,stripeAddressUsedWhenFetchingLC:null,stripeBillingAddressElement:null,stripeElements:null,stripeElementsOptions:null,stripeLinkElement:null,stripeLinkEventData:null,stripeLinkUsedWhenFetchingLC:null,stripePaymentElement:null,stripePaymentEventData:null}})),onChange$1=_f.onChange,reset$1=_f.reset,stripeStore=_f.state;var getStripeOptions=function(e){var t=e.clientSecret,r=e.overrideBorderRaidus,o=e.overridePrimaryColor,n=e.overrideTheme;var i=o||zonosStore.appearance.colorPrimary;var a=i&&isDarkColor(i)?"night":"flat";var s=n==="DARK"?"night":"flat";return{appearance:{labels:"floating",rules:Object.assign({},addressRuleStyle({theme:"LIGHT"})),theme:n?s:a,variables:Object.assign({},defaultVariable({borderStyle:r,theme:"LIGHT"}))},clientSecret:t,locale:localizationStore.selectedLocale}};var initStripeElements=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n;return __generator(this,(function(i){r=stripeStore.clientSecret;if(!stripeStore.stripe){log("Skip. Stripe is not initialized");return[2]}if(r){o=getStripeOptions({clientSecret:r,overrideBorderRaidus:e===null||e===void 0?void 0:e.overrideBorderRaidus,overridePrimaryColor:e===null||e===void 0?void 0:e.overridePrimaryColor,overrideTheme:e===null||e===void 0?void 0:e.overrideTheme});n=JSON.stringify(o)===JSON.stringify(stripeStore.stripeElementsOptions);if(!stripeStore.stripeElements){stripeStore.stripeElements=(t=stripeStore.stripe)===null||t===void 0?void 0:t.elements(o);stripeStore.stripeElementsOptions=o;log("Stripe elements initialized");return[2]}if(!n){stripeStore.stripeElements.update(o);stripeStore.stripeElementsOptions=o}log("Stripe elements initialized")}return[2]}))}))};var stripeStoreReset=function(){sessionStorage.removeItem("zonos--client-secret");reset$1();stripeStore.stripe=window.Zonos.stripe};var isPrefetchInfoOutdated=function(){var e,t,r,o;var n=stripeStore.fetchingLandedCostAbordController;if(!n){return false}var i=JSON.stringify((e=stripeStore.stripeLinkUsedWhenFetchingLC)===null||e===void 0?void 0:e.value)!==JSON.stringify((t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.value);var a=JSON.stringify((r=stripeStore.stripeAddressUsedWhenFetchingLC)===null||r===void 0?void 0:r.value)!==JSON.stringify((o=stripeStore.stripeAddressEventData)===null||o===void 0?void 0:o.value);return i||a};var stripeStorePrefetchLandedCost=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,o,n,i,a,s,c,u,l,d,p,S;return __generator(this,(function(f){switch(f.label){case 0:n=!!((e=stripeStore.stripeAddressEventData)===null||e===void 0?void 0:e.complete);i=!!((t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.complete);a=isPrefetchInfoOutdated();if(a){(r=stripeStore.fetchingLandedCostAbordController)===null||r===void 0?void 0:r.abort();stripeStore.fetchingLandedCostAbordController=null}if(!(n&&i&&(a||!stripeStore.isFetchingLandedCost)))return[3,5];stripeStore.isFetchingLandedCost=true;if(stripeStore.stripeAddressEventData){stripeStore.stripeAddressUsedWhenFetchingLC=Object.assign({},stripeStore.stripeAddressEventData)}if(stripeStore.stripeLinkEventData){stripeStore.stripeLinkUsedWhenFetchingLC=Object.assign({},stripeStore.stripeLinkEventData)}f.label=1;case 1:f.trys.push([1,3,,4]);s=new AbortController;stripeStore.fetchingLandedCostAbordController=s;return[4,calculateLandedCost(s)];case 2:c=f.sent(),u=c.checkoutSessionWorkflow,l=c.shipmentRatingCalculateWorkflow;stripeStore.fetchingLandedCostAbordController=null;cartStore.landedCostData=(u===null||u===void 0?void 0:u.filter(Boolean))||null;cartStore.shippingData=(l===null||l===void 0?void 0:l.filter(Boolean))||null;d=(o=cartStore.landedCostData)===null||o===void 0?void 0:o.find(Boolean);p=!!d?d.subtotals:null;if(p){cartStoreApplySubtotals({exchangeRate:p.exchangeRate,items:p.items,landedCostTotal:0,presentmentCurrencyCode:p.presentmentCurrencyCode,shipping:0,total:p.items})}return[3,4];case 3:S=f.sent();logError(S);return[3,4];case 4:stripeStore.isFetchingLandedCost=false;f.label=5;case 5:return[2]}}))}))};var getStripeMessageBasedOnStatus=function(e){var t=[];var r=true;switch(e){case"succeeded":{t=[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."),"","",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.")];r=false;break}case"requires_capture":case"processing":{t=[translate("Payment processing. We'll update you when payment is received.")];r=false;break}case"requires_payment_method":{t=[translate("Payment failed. Please try another payment method.")];break}default:{t=[translate("Something went wrong.")];break}}return{isError:r,messages:t}};var stripeStoreRetrievePayment=function(e){var t=e.clientSecret,r=e.storybookForceStatus;return __awaiter(void 0,void 0,void 0,(function(){var e,o,n,i,a,s,c,u,l;return __generator(this,(function(d){switch(d.label){case 0:if(r){e=getStripeMessageBasedOnStatus(r),o=e.isError,n=e.messages;return[2,{error:o,messages:n}]}i=t||stripeStore.clientSecret;if(!stripeStore.stripe||!i){logError("Failed to retrieve payment intent. Stripe is not initialized");return[2,{error:true,message:[translate("Something went wrong.")]}]}return[4,stripeStore.stripe.retrievePaymentIntent(i)];case 1:a=d.sent().paymentIntent;s=a===null||a===void 0?void 0:a.status;c=getStripeMessageBasedOnStatus(s),u=c.isError,l=c.messages;return[2,{error:u,messages:l}]}}))}))};var stripeStoreConfirmPayment=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,o,n,i,a,s;return __generator(this,(function(c){switch(c.label){case 0:o=!!((e=stripeStore.stripePaymentEventData)===null||e===void 0?void 0:e.complete);n=stripeStore.stripeElements;i=stripeStore.stripe;a=stripeStore.clientSecret;if(!(i&&n&&o&&a))return[3,2];return[4,i.confirmPayment({confirmParams:{receipt_email:(r=(t=stripeStore.stripeLinkEventData)===null||t===void 0?void 0:t.value)===null||r===void 0?void 0:r.email,return_url:window.location.href},elements:n,redirect:"if_required"})];case 1:s=c.sent().error;if(s){if(s.type==="card_error"||s.type==="validation_error"){throw new Error(s.message)}if(s.type==="invalid_request_error"){if(s.code==="payment_intent_unexpected_state"){return[2]}}throw new Error("An unexpected error occurred.")}c.label=2;case 2:return[2]}}))}))};var stripeStoreInitCheckoutSession=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,r,o,n,i;return __generator(this,(function(a){switch(a.label){case 0:t=cartStore.items.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!t||!localizationStore.targetCurrency){logError("Fail to create checkout session - invalid total or currency");return[2,false]}stripeStore.isFetchingSession=true;return[4,handleFetch("".concat("https://v1.route.js.zonos.com","/api/zonos-elements/create-checkout-session"),{body:{currency:((e=cartStore.items.find(Boolean))===null||e===void 0?void 0:e.currencyCode)||"",itemsAmount:t,presentmentCountryCode:localizationStore.selectedCountryCode||null},method:"POST"})];case 1:r=a.sent(),o=r.errors,n=r.json;stripeStore.isFetchingSession=false;if(o.length||!n){logError("Error occurs when creating checkout session",JSON.stringify(o,null,2));return[2,false]}i=n.checkoutSessionCreate;stripeStore.clientSecret=i.clientSecret;cartStore.checkoutSessionId=i.id;cartStoreApplySubtotals(Object.assign(Object.assign({},i.subtotals),{landedCostTotal:0,shipping:0,total:i.subtotals.items}));log("Exchange rate updated for cart items (checkout session create)","info",cartStore.exchangeRate);log("done-init-checkout-session");return[2,true]}}))}))};var stripeStoreUpdateCheckoutSession=function(e){var t=e.currency,r=e.id,o=e.itemsAmount,n=e.landedCostId,i=e.presentmentCountryCode;return __awaiter(void 0,void 0,void 0,(function(){var e,a,s;return __generator(this,(function(c){switch(c.label){case 0:return[4,handleFetch("".concat("https://v1.route.js.zonos.com","/api/zonos-elements/update-checkout-session"),{body:{currency:t,id:r,itemsAmount:o,landedCostId:n,presentmentCountryCode:i},method:"POST"})];case 1:e=c.sent(),a=e.errors,s=e.json;if(a.length||!s){logError("Error occurs when updating checkout session",JSON.stringify(a,null,2));return[2,{errors:a,json:s}]}return[2,{errors:[],json:s}]}}))}))};onChange$1("clientSecret",(function(e){if(e&&stripeStore.stripe){sessionStorage.setItem("zonos--client-secret",e)}if(!e){sessionStorage.removeItem("zonos--client-secret")}}));var formatDate=function(e){var t=e.date,r=e.formatOptions,o=r===void 0?{day:"numeric",weekday:"long",year:"numeric"}:r;return new Intl.DateTimeFormat("en-US",o).format(t)};var getDaysDifference=function(e){var t=new Date;var r=e.getTime()-t.getTime();var o=Math.floor(r/(1e3*60*60*24));return o};var _g=createStore((function(){return{checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id")||null,currency:"USD",dutiesTaxFees:0,error:null,exchangeRate:null,isSelectedShippingAboveDeminimis:false,isSelectedShippingGuarantee:false,items:[],landedCostData:null,selectedLandedCost:null,selectedShippingOption:null,selectedShippingOptionExpectedDate:"",selectedShippingOptionTransitTime:"",shipping:0,shippingData:null,step:"customer-info",subtotal:0,total:0}})),onChange=_g.onChange,reset=_g.reset,cartStore=_g.state;var cartStoreGetShippingTransitInfo=function(e){var t=e.minTransitAt?getDaysDifference(new Date(e.minTransitAt)):"";var r=e.maxTransitAt?getDaysDifference(new Date(e.maxTransitAt)):"";var o=e.minTransitAt?formatDate({date:new Date(e.minTransitAt)}):"";return{expectedDate:o,maxTransit:r,minTransit:t}};var cartStoreReset=function(){sessionStorage.removeItem("zonos--checkout-session-id");reset()};var cartStoreUpdateToErrorState=function(e){var t=e.messages,r=e.title;cartStore.step="error";cartStore.error={messages:t,title:r}};var cartStoreApplySubtotals=function(e){cartStore.exchangeRate=e.exchangeRate;cartStore.dutiesTaxFees=e.landedCostTotal;cartStore.subtotal=e.items;cartStore.total=e.total;cartStore.currency=e.presentmentCurrencyCode};var cartStoreReCalculateTotal=function(e){var t=e.currency,r=e.itemsAmount,o=e.landedCostId;return __awaiter(void 0,void 0,void 0,(function(){var e,n;return __generator(this,(function(i){switch(i.label){case 0:if(o&&cartStore.selectedLandedCost){e=cartStore.selectedLandedCost.subtotals;cartStoreApplySubtotals(e);log("Exchange rate updated for cart items (landed cost subtotal)","info",cartStore.exchangeRate)}if(!cartStore.checkoutSessionId){logError("Could not update cart total without checkout session id");return[2,false]}return[4,stripeStoreUpdateCheckoutSession({currency:t,id:cartStore.checkoutSessionId,itemsAmount:r,landedCostId:o,presentmentCountryCode:localizationStore.selectedCountryCode})];case 1:n=i.sent().json;if(!n){logError("Error occurs when updating checkout session");cartStoreUpdateToErrorState({messages:[translate("There's been an error updating your checkout session. Please reload and try again or contact support if the error persists")],title:translate("Error updating Checkout")});return[2,false]}if(!o){cartStoreApplySubtotals(n.checkoutSessionUpdate.subtotals);log("Exchange rate updated for cart items (checkout session update)","info",cartStore.exchangeRate)}return[2,true]}}))}))};var cartStoreUpdateSelectedShippingOption=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n,i,a,s,c,u,l,d,p,S;return __generator(this,(function(f){switch(f.label){case 0:cartStore.selectedShippingOption=e;a=cartStoreGetShippingTransitInfo(cartStore.selectedShippingOption),s=a.expectedDate,c=a.maxTransit,u=a.minTransit;cartStore.selectedShippingOptionExpectedDate=s;cartStore.selectedShippingOptionTransitTime=u&&c?"".concat(u,"-").concat(c):"".concat(u||c);l=(t=cartStore.landedCostData)===null||t===void 0?void 0:t.find((function(e){var t,r,o;return((r=(t=e.landedCost)===null||t===void 0?void 0:t.shipmentRating)===null||r===void 0?void 0:r.id)===((o=cartStore.selectedShippingOption)===null||o===void 0?void 0:o.id)}));cartStore.selectedLandedCost=l||null;if(!l){return[2,false]}cartStore.shipping=l.subtotals.shipping;d=((r=l===null||l===void 0?void 0:l.landedCost)===null||r===void 0?void 0:r.landedCostGuaranteeCode)==="ZONOS";p=!!((n=(o=l===null||l===void 0?void 0:l.landedCost)===null||o===void 0?void 0:o.deMinimis)===null||n===void 0?void 0:n.find((function(e){return["DUTY","TAX"].includes(e.type)&&e.threshold==="ABOVE"})));cartStore.isSelectedShippingAboveDeminimis=p;cartStore.isSelectedShippingGuarantee=d;return[4,cartStoreReCalculateTotal({landedCostId:(i=l.landedCost)===null||i===void 0?void 0:i.id})];case 1:S=f.sent();return[2,S]}}))}))};onChange("checkoutSessionId",(function(){if(!cartStore.checkoutSessionId){sessionStorage.removeItem("zonos--checkout-session-id");return}sessionStorage.setItem("zonos--checkout-session-id",cartStore.checkoutSessionId)}));var cartStoreUpdateItems=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o;return __generator(this,(function(n){switch(n.label){case 0:cartStore.items=e;r=(t=e.find(Boolean))===null||t===void 0?void 0:t.currencyCode;o=e.reduce((function(e,t){return e+t.amount*t.quantity}),0);if(!r||!o){return[2]}cartStore.currency=r;stripeStore.isFetchingSession=true;return[4,cartStoreReCalculateTotal({currency:r,itemsAmount:o})];case 1:n.sent();stripeStore.isFetchingSession=false;return[2]}}))}))};var cartStoreResetSelectedShippingOption=function(){cartStore.selectedShippingOption=null;cartStore.isSelectedShippingAboveDeminimis=false;cartStore.isSelectedShippingGuarantee=false;cartStore.selectedShippingOptionExpectedDate="";cartStore.selectedShippingOptionTransitTime="";cartStore.shipping=0};var cartStoreNextStep=function(){if(cartStore.step==="customer-info"){cartStore.step="shipping"}else if(cartStore.step==="shipping"){cartStore.step="payment"}else if(cartStore.step==="payment"){cartStore.step="finish"}};var cartStorePreviousStep=function(){if(cartStore.step==="payment"){cartStore.step="shipping"}else if(cartStore.step==="shipping"){cartStore.step="customer-info";cartStoreResetSelectedShippingOption()}};export{cartStoreApplySubtotals as a,cartStoreGetShippingTransitInfo as b,cartStore as c,cartStoreNextStep as d,cartStorePreviousStep as e,cartStoreReCalculateTotal as f,cartStoreReset as g,cartStoreUpdateItems as h,cartStoreUpdateSelectedShippingOption as i,cartStoreUpdateToErrorState as j,initStripeElements as k,stripeStoreInitCheckoutSession as l,stripeStorePrefetchLandedCost as m,stripeStoreConfirmPayment as n,stripeStoreReset as o,stripeStoreRetrievePayment as p,stripeStore as s};
@@ -1 +1 @@
1
- export{c as cartStore,a as cartStoreApplySubtotals,b as cartStoreGetShippingTransitInfo,d as cartStoreNextStep,e as cartStorePreviousStep,f as cartStoreReCalculateTotal,g as cartStoreReset,h as cartStoreUpdateItems,i as cartStoreUpdateSelectedShippingOption,j as cartStoreUpdateToErrorState}from"./cart-c9124cc3.js";import"./zonosStore-e59617f8.js";import"./index-81a199ef.js";import"./localization-5d83fde2.js";import"./isDarkColor-8696cb70.js";import"./getBorderRadius-9e4cb3b1.js";
1
+ export{c as cartStore,a as cartStoreApplySubtotals,b as cartStoreGetShippingTransitInfo,d as cartStoreNextStep,e as cartStorePreviousStep,f as cartStoreReCalculateTotal,g as cartStoreReset,h as cartStoreUpdateItems,i as cartStoreUpdateSelectedShippingOption,j as cartStoreUpdateToErrorState}from"./cart-ba9b0d4c.js";import"./zonosStore-e59617f8.js";import"./index-81a199ef.js";import"./localization-5d83fde2.js";import"./isDarkColor-8696cb70.js";import"./getBorderRadius-9e4cb3b1.js";