@zonos/elements 1.3.2 → 1.3.3-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 (45) hide show
  1. package/dist/cjs/zonos-cart-items_10.cjs.entry.js +36 -1
  2. package/dist/cjs/zonos-checkout.cjs.entry.js +8 -3
  3. package/dist/cjs/zonos-controller.cjs.entry.js +0 -46
  4. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +39 -0
  5. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +8 -3
  6. package/dist/collection/components/common/zonos-dialog/zonos-dialog.css +4 -4
  7. package/dist/collection/components/main/zonos-controller.js +0 -46
  8. package/dist/collection/scripts/zonosBase.js +16 -0
  9. package/dist/collection/types/LogErrorRequestBody.js +1 -0
  10. package/dist/collection/types/generated/graphql.customer.types.js +34 -0
  11. package/dist/components/zonos-checkout-finish2.js +35 -0
  12. package/dist/components/zonos-checkout.js +8 -3
  13. package/dist/components/zonos-controller.js +0 -46
  14. package/dist/components/zonos-dialog2.js +1 -1
  15. package/dist/esm/zonos-cart-items_10.entry.js +36 -1
  16. package/dist/esm/zonos-checkout.entry.js +8 -3
  17. package/dist/esm/zonos-controller.entry.js +0 -46
  18. package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
  19. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  20. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  21. package/dist/scripts/loadZonos.js +1 -1
  22. package/dist/scripts/zonos.js +1 -1
  23. package/dist/scripts/zonosBase.js +1 -1
  24. package/dist/types/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.d.ts +1 -0
  25. package/dist/types/components/main/zonos-controller.d.ts +0 -1
  26. package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
  27. package/dist/types/types/LogErrorRequestBody.d.ts +5 -0
  28. package/dist/types/types/generated/graphql.customer.types.d.ts +45 -0
  29. package/dist/types/types/generated/graphql.customer.types.ts +70 -0
  30. package/dist/types/types/generated/graphql.frontend.types.d.ts +1 -1
  31. package/dist/types/types/generated/graphql.frontend.types.ts +1 -1
  32. package/dist/zonos-elements/p-02175f85.entry.js +1 -0
  33. package/dist/zonos-elements/p-17ef815f.entry.js +1 -0
  34. package/dist/zonos-elements/p-24fbe845.system.js +1 -1
  35. package/dist/zonos-elements/{p-daa10b8c.system.entry.js → p-72cfaee2.system.entry.js} +1 -1
  36. package/dist/zonos-elements/p-80748529.system.entry.js +1 -0
  37. package/dist/zonos-elements/p-c0494ed6.entry.js +1 -0
  38. package/dist/zonos-elements/p-e2c7adaa.system.entry.js +1 -0
  39. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  40. package/package.json +1 -1
  41. package/dist/zonos-elements/p-436faf98.system.entry.js +0 -1
  42. package/dist/zonos-elements/p-5e87609f.entry.js +0 -1
  43. package/dist/zonos-elements/p-ad2b4bda.entry.js +0 -1
  44. package/dist/zonos-elements/p-b7e061e7.entry.js +0 -1
  45. package/dist/zonos-elements/p-f7b07128.system.entry.js +0 -1
@@ -117,17 +117,51 @@ const ZonosCheckoutFinish = class {
117
117
  await ((_b = (_a = zonosStore.zonosStore.checkoutSettings).onOrderSuccess) === null || _b === void 0 ? void 0 : _b.call(_a, json));
118
118
  return json;
119
119
  };
120
+ this.handleSuccessBehavior = (orderId) => {
121
+ const { successBehavior } = zonosStore.zonosStore.checkoutSettings;
122
+ switch (successBehavior) {
123
+ case 'REDIRECT_TO_SUCCESS_PAGE':
124
+ const redirectUrl = zonosStore.zonosStore.checkoutSettings.successRedirectUrl;
125
+ if (redirectUrl) {
126
+ window.location.href = `${redirectUrl}?zOrderNumber=${orderId}`;
127
+ }
128
+ // If no redirect URL, break and display Zonos success page
129
+ break;
130
+ case 'CLOSE_MODAL':
131
+ this.closeClickHandler();
132
+ break;
133
+ }
134
+ };
120
135
  // TODO: This method of pulling orders is temporary. Once we have a working event registry system, we will rely on that to tell us when the order is ready to trigger onOrderSuccess
121
136
  this.getPullOrder = async (attempts = 0) => {
122
137
  const order = await this.pullOrder();
123
138
  if (order) {
124
139
  this.order = order;
140
+ this.handleSuccessBehavior(order.id);
141
+ this.isLoading = false;
125
142
  }
126
143
  else if (!order && attempts < 5) {
127
144
  // Wait for 1 second before the next attempt
128
145
  await new Promise(resolve => setTimeout(resolve, 1000));
129
146
  await this.getPullOrder(attempts + 1);
130
147
  }
148
+ else {
149
+ // Set loading to false to display generic success page and log error
150
+ this.isLoading = false;
151
+ const errorObject = {
152
+ endpoint: `${"https://v1.route.js.zonos.com"}/api/zonos-elements/get-order`,
153
+ errors: ['Order not found after multiple attempts'],
154
+ metadata: {
155
+ checkoutSessionId: cart.cartStore.checkoutSessionId || '',
156
+ domain: window.location.hostname,
157
+ storeId: zonosStore.zonosStore.storeId,
158
+ },
159
+ };
160
+ void localization.handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/log-error`, {
161
+ body: errorObject,
162
+ method: 'POST',
163
+ });
164
+ }
131
165
  };
132
166
  this.checkPaymentStatus = async () => {
133
167
  this.isLoading = true;
@@ -156,6 +190,7 @@ const ZonosCheckoutFinish = class {
156
190
  }
157
191
  // Attempt to pull the order details from the graph every second on 5 attempts
158
192
  if (this.notificationType === 'success') {
193
+ this.isLoading = true;
159
194
  void this.getPullOrder();
160
195
  }
161
196
  }
@@ -323,7 +358,7 @@ ZonosCustomerInfo.style = zonosCustomerInfoCss;
323
358
 
324
359
  const RemoveIcon = `<svg xmlns="https://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path fill="#C5C6CA" fill-rule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z" clip-rule="evenodd"/><path fill="#4D505A" fill-rule="evenodd" d="M8.293 8.293a1 1 0 0 1 1.414 0L12 10.586l2.293-2.293a1 1 0 1 1 1.414 1.414L13.414 12l2.293 2.293a1 1 0 0 1-1.414 1.414L12 13.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L10.586 12 8.293 9.707a1 1 0 0 1 0-1.414Z" clip-rule="evenodd"/></svg>`;
325
360
 
326
- const zonosDialogCss = ":host{font-family:var(--font-family, Inter), Inter;display:block;white-space:normal}:host *{font-family:var(--font-family, Inter), Inter}:host img{max-width:100%}:host dl,:host dd,:host h1,:host h2,:host h3,:host h4,:host h5,:host h6,:host hr,:host figure,:host p,:host pre{margin:0}:host{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}:host .zonos--backdrop,:host .zonos--dialog-layout{opacity:0;z-index:-999;visibility:hidden;-webkit-transition:0.3s all ease;transition:0.3s all ease}:host .zonos--backdrop{width:100vw;height:100vh;left:0px;top:0px;background:var(--amino-backdrop-color);z-index:-999;opacity:0;visibility:hidden;position:fixed}:host .zonos--loading{position:absolute;left:0;right:0;bottom:0;top:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;z-index:1002;background:white}:host .zonos--dialog-layout{width:100vw;height:100vh;left:0;top:0;position:fixed;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;color:var(--amino-text-color);visibility:hidden}:host .zonos--dialog{position:relative;z-index:1001;background:var(--amino-gray-0);max-width:90vw;max-height:90vh;min-height:500px;height:var(--height, auto);width:var(--width, auto);border-radius:var(--border-radius, var(--amino-radius-10));outline:none;-webkit-box-shadow:var(--amino-v3-shadow-xxl);box-shadow:var(--amino-v3-shadow-xxl);border:var(--amino-border);overflow:hidden;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}:host .zonos--header{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;padding:var(--amino-space-16) var(--amino-space-24)}:host .zonos--header .-zonos-stencil-library--header-text{-ms-flex-positive:1;flex-grow:1}:host .zonos--header .zonos--close-button{width:var(--amino-size-md);height:var(--amino-size-md);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;cursor:pointer;border-radius:var(--amino-radius-10)}:host .zonos--header .zonos--close-button:hover{background:var(--amino-hover-color)}:host .zonos--body{padding:var(--amino-space-8) var(--amino-space-24);max-height:100%;height:100%;overflow:auto}:host .zonos--body.zonos--no-body-padding{padding:0}:host .zonos--footer{padding:var(--amino-space-16) var(--amino-space-24)}:host(.open) .zonos--dialog-layout,:host(.open) .zonos--backdrop{visibility:visible}:host(.open) .zonos--backdrop{z-index:1001;opacity:0.65}:host(.open) .zonos--dialog-layout{opacity:1;z-index:1002;-webkit-transform:scale(1);transform:scale(1)}:host(.no-border) .zonos--dialog{border:none}:host(.mobile) .zonos--dialog{max-width:100vw;max-height:100vh;height:100%;width:100%;border-radius:0;-webkit-box-shadow:none;box-shadow:none;border:none}";
361
+ const zonosDialogCss = ":host{font-family:var(--font-family, Inter), Inter;display:block;white-space:normal}:host *{font-family:var(--font-family, Inter), Inter}:host img{max-width:100%}:host dl,:host dd,:host h1,:host h2,:host h3,:host h4,:host h5,:host h6,:host hr,:host figure,:host p,:host pre{margin:0}:host{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}:host .zonos--backdrop,:host .zonos--dialog-layout{opacity:0;z-index:-999;visibility:hidden;-webkit-transition:0.3s all ease;transition:0.3s all ease}:host .zonos--backdrop{width:100vw;height:100vh;left:0px;top:0px;background:var(--amino-backdrop-color);z-index:-999;opacity:0;visibility:hidden;position:fixed}:host .zonos--loading{position:absolute;left:0;right:0;bottom:0;top:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;z-index:10002;background:white}:host .zonos--dialog-layout{width:100vw;height:100vh;left:0;top:0;position:fixed;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;color:var(--amino-text-color);visibility:hidden}:host .zonos--dialog{position:relative;z-index:10001;background:var(--amino-gray-0);max-width:90vw;max-height:90vh;min-height:500px;height:var(--height, auto);width:var(--width, auto);border-radius:var(--border-radius, var(--amino-radius-10));outline:none;-webkit-box-shadow:var(--amino-v3-shadow-xxl);box-shadow:var(--amino-v3-shadow-xxl);border:var(--amino-border);overflow:hidden;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}:host .zonos--header{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;padding:var(--amino-space-16) var(--amino-space-24)}:host .zonos--header .-zonos-stencil-library--header-text{-ms-flex-positive:1;flex-grow:1}:host .zonos--header .zonos--close-button{width:var(--amino-size-md);height:var(--amino-size-md);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;cursor:pointer;border-radius:var(--amino-radius-10)}:host .zonos--header .zonos--close-button:hover{background:var(--amino-hover-color)}:host .zonos--body{padding:var(--amino-space-8) var(--amino-space-24);max-height:100%;height:100%;overflow:auto}:host .zonos--body.zonos--no-body-padding{padding:0}:host .zonos--footer{padding:var(--amino-space-16) var(--amino-space-24)}:host(.open) .zonos--dialog-layout,:host(.open) .zonos--backdrop{visibility:visible}:host(.open) .zonos--backdrop{z-index:10001;opacity:0.65}:host(.open) .zonos--dialog-layout{opacity:1;z-index:10002;-webkit-transform:scale(1);transform:scale(1)}:host(.no-border) .zonos--dialog{border:none}:host(.mobile) .zonos--dialog{max-width:100vw;max-height:100vh;height:100%;width:100%;border-radius:0;-webkit-box-shadow:none;box-shadow:none;border:none}";
327
362
 
328
363
  const ZonosDialog = class {
329
364
  constructor(hostRef) {
@@ -157,6 +157,7 @@ const ZonosCheckout = class {
157
157
  });
158
158
  }
159
159
  });
160
+ button.removeAttribute('disabled');
160
161
  button.setAttribute('data-zonos-checkout-attached', 'true');
161
162
  });
162
163
  }
@@ -220,10 +221,14 @@ const ZonosCheckout = class {
220
221
  }
221
222
  else {
222
223
  this.attachCheckout();
223
- // keep checking for checkout selector every 50ms just in case the selector is not loaded in the DOM yet
224
- setInterval(() => {
224
+ // create a mutation observer to see if any new elements that match our selector is added to the DOM
225
+ const observer = new MutationObserver(() => {
225
226
  this.attachCheckout();
226
- }, 50);
227
+ });
228
+ observer.observe(document.body, {
229
+ childList: true,
230
+ subtree: true,
231
+ });
227
232
  }
228
233
  clearInterval(interval);
229
234
  }, 50);
@@ -66,44 +66,6 @@ const ZonosController = class {
66
66
  constructor(hostRef) {
67
67
  index.registerInstance(this, hostRef);
68
68
  this.stripeInitEvent = index.createEvent(this, "stripeInitEvent", 7);
69
- this.disablePlaceOrderButtons = ({ disable }) => {
70
- const placeOrderButtonSelector = zonosStore.zonosStore.checkoutSettings.placeOrderButtonSelector;
71
- if (!placeOrderButtonSelector) {
72
- return;
73
- }
74
- const disableEvent = (e) => {
75
- const target = e.target;
76
- // prevent default and propagation when the item has disabled attribute
77
- if (target.getAttribute('disabled')) {
78
- e.preventDefault();
79
- e.stopPropagation();
80
- }
81
- };
82
- const placeOrderButton = document.querySelectorAll(placeOrderButtonSelector);
83
- placeOrderButton.forEach(button => {
84
- if (disable) {
85
- button.setAttribute('disabled', 'true');
86
- // prevent the selector to perform default action when it's disabled
87
- button.addEventListener('click', disableEvent);
88
- }
89
- else {
90
- button.removeAttribute('disabled');
91
- // clean up the event listener
92
- button.removeEventListener('click', disableEvent);
93
- }
94
- });
95
- // only auto enable if autoEnable is true and the state is enable
96
- if (disable) {
97
- setTimeout(() => {
98
- // release it if zonos is not initialized after 5 seconds (this is to prevent the place order button from being disabled forever due to api)
99
- placeOrderButton.forEach(button => {
100
- button.removeAttribute('disabled');
101
- // clean up the event listener if exists
102
- button.removeEventListener('click', disableEvent);
103
- });
104
- }, 5000);
105
- }
106
- };
107
69
  this.config = undefined;
108
70
  this.zonosApiKey = undefined;
109
71
  }
@@ -119,10 +81,6 @@ const ZonosController = class {
119
81
  cart.stripeStore.stripe = stripe;
120
82
  void initCheckout(zonosStore.zonosStore.checkoutSettings);
121
83
  localization.log('init checkout element');
122
- // enable place order button after checkout is loaded
123
- this.disablePlaceOrderButtons({
124
- disable: false,
125
- });
126
84
  }
127
85
  /**
128
86
  * Init zonos notification
@@ -175,10 +133,6 @@ const ZonosController = class {
175
133
  localization.log('Failed to load zonos settings. This domain may not have access', 'warn');
176
134
  return;
177
135
  }
178
- // disable place order button until checkout is loaded
179
- this.disablePlaceOrderButtons({
180
- disable: true,
181
- });
182
136
  // init zonos notification
183
137
  this.initZonosNotification();
184
138
  // load default setting if fail to load user setting
@@ -25,17 +25,55 @@ export class ZonosCheckoutFinish {
25
25
  await ((_b = (_a = zonosStore.checkoutSettings).onOrderSuccess) === null || _b === void 0 ? void 0 : _b.call(_a, json));
26
26
  return json;
27
27
  };
28
+ this.handleSuccessBehavior = (orderId) => {
29
+ const { successBehavior } = zonosStore.checkoutSettings;
30
+ switch (successBehavior) {
31
+ case 'REDIRECT_TO_SUCCESS_PAGE':
32
+ const redirectUrl = zonosStore.checkoutSettings.successRedirectUrl;
33
+ if (redirectUrl) {
34
+ window.location.href = `${redirectUrl}?zOrderNumber=${orderId}`;
35
+ }
36
+ // If no redirect URL, break and display Zonos success page
37
+ break;
38
+ case 'CLOSE_MODAL':
39
+ this.closeClickHandler();
40
+ break;
41
+ case 'ZONOS_SUCCESS_PAGE':
42
+ default:
43
+ // Do nothing, display Zonos success page
44
+ break;
45
+ }
46
+ };
28
47
  // TODO: This method of pulling orders is temporary. Once we have a working event registry system, we will rely on that to tell us when the order is ready to trigger onOrderSuccess
29
48
  this.getPullOrder = async (attempts = 0) => {
30
49
  const order = await this.pullOrder();
31
50
  if (order) {
32
51
  this.order = order;
52
+ this.handleSuccessBehavior(order.id);
53
+ this.isLoading = false;
33
54
  }
34
55
  else if (!order && attempts < 5) {
35
56
  // Wait for 1 second before the next attempt
36
57
  await new Promise(resolve => setTimeout(resolve, 1000));
37
58
  await this.getPullOrder(attempts + 1);
38
59
  }
60
+ else {
61
+ // Set loading to false to display generic success page and log error
62
+ this.isLoading = false;
63
+ const errorObject = {
64
+ endpoint: `${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/zonos-elements/get-order`,
65
+ errors: ['Order not found after multiple attempts'],
66
+ metadata: {
67
+ checkoutSessionId: cartStore.checkoutSessionId || '',
68
+ domain: window.location.hostname,
69
+ storeId: zonosStore.storeId,
70
+ },
71
+ };
72
+ void handleFetch(`${process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL}/api/zonos-elements/log-error`, {
73
+ body: errorObject,
74
+ method: 'POST',
75
+ });
76
+ }
39
77
  };
40
78
  this.checkPaymentStatus = async () => {
41
79
  this.isLoading = true;
@@ -64,6 +102,7 @@ export class ZonosCheckoutFinish {
64
102
  }
65
103
  // Attempt to pull the order details from the graph every second on 5 attempts
66
104
  if (this.notificationType === 'success') {
105
+ this.isLoading = true;
67
106
  void this.getPullOrder();
68
107
  }
69
108
  }
@@ -152,6 +152,7 @@ export class ZonosCheckout {
152
152
  });
153
153
  }
154
154
  });
155
+ button.removeAttribute('disabled');
155
156
  button.setAttribute('data-zonos-checkout-attached', 'true');
156
157
  });
157
158
  }
@@ -215,10 +216,14 @@ export class ZonosCheckout {
215
216
  }
216
217
  else {
217
218
  this.attachCheckout();
218
- // keep checking for checkout selector every 50ms just in case the selector is not loaded in the DOM yet
219
- setInterval(() => {
219
+ // create a mutation observer to see if any new elements that match our selector is added to the DOM
220
+ const observer = new MutationObserver(() => {
220
221
  this.attachCheckout();
221
- }, 50);
222
+ });
223
+ observer.observe(document.body, {
224
+ childList: true,
225
+ subtree: true,
226
+ });
222
227
  }
223
228
  clearInterval(interval);
224
229
  }, 50);
@@ -58,7 +58,7 @@
58
58
  display: flex;
59
59
  align-items: center;
60
60
  justify-content: center;
61
- z-index: 1002;
61
+ z-index: 10002;
62
62
  background: white;
63
63
  }
64
64
  :host .zonos--dialog-layout {
@@ -75,7 +75,7 @@
75
75
  }
76
76
  :host .zonos--dialog {
77
77
  position: relative;
78
- z-index: 1001;
78
+ z-index: 10001;
79
79
  background: var(--amino-gray-0);
80
80
  max-width: 90vw;
81
81
  max-height: 90vh;
@@ -130,12 +130,12 @@
130
130
  visibility: visible;
131
131
  }
132
132
  :host(.open) .zonos--backdrop {
133
- z-index: 1001;
133
+ z-index: 10001;
134
134
  opacity: 0.65;
135
135
  }
136
136
  :host(.open) .zonos--dialog-layout {
137
137
  opacity: 1;
138
- z-index: 1002;
138
+ z-index: 10002;
139
139
  transform: scale(1);
140
140
  }
141
141
 
@@ -9,44 +9,6 @@ import { initHello } from "../utils/hello/initHello";
9
9
  import { log } from "../utils/logging/log";
10
10
  export class ZonosController {
11
11
  constructor() {
12
- this.disablePlaceOrderButtons = ({ disable }) => {
13
- const placeOrderButtonSelector = zonosStore.checkoutSettings.placeOrderButtonSelector;
14
- if (!placeOrderButtonSelector) {
15
- return;
16
- }
17
- const disableEvent = (e) => {
18
- const target = e.target;
19
- // prevent default and propagation when the item has disabled attribute
20
- if (target.getAttribute('disabled')) {
21
- e.preventDefault();
22
- e.stopPropagation();
23
- }
24
- };
25
- const placeOrderButton = document.querySelectorAll(placeOrderButtonSelector);
26
- placeOrderButton.forEach(button => {
27
- if (disable) {
28
- button.setAttribute('disabled', 'true');
29
- // prevent the selector to perform default action when it's disabled
30
- button.addEventListener('click', disableEvent);
31
- }
32
- else {
33
- button.removeAttribute('disabled');
34
- // clean up the event listener
35
- button.removeEventListener('click', disableEvent);
36
- }
37
- });
38
- // only auto enable if autoEnable is true and the state is enable
39
- if (disable) {
40
- setTimeout(() => {
41
- // release it if zonos is not initialized after 5 seconds (this is to prevent the place order button from being disabled forever due to api)
42
- placeOrderButton.forEach(button => {
43
- button.removeAttribute('disabled');
44
- // clean up the event listener if exists
45
- button.removeEventListener('click', disableEvent);
46
- });
47
- }, 5000);
48
- }
49
- };
50
12
  this.config = undefined;
51
13
  this.zonosApiKey = undefined;
52
14
  }
@@ -62,10 +24,6 @@ export class ZonosController {
62
24
  stripeStore.stripe = stripe;
63
25
  void initCheckout(zonosStore.checkoutSettings);
64
26
  log('init checkout element');
65
- // enable place order button after checkout is loaded
66
- this.disablePlaceOrderButtons({
67
- disable: false,
68
- });
69
27
  }
70
28
  /**
71
29
  * Init zonos notification
@@ -118,10 +76,6 @@ export class ZonosController {
118
76
  log('Failed to load zonos settings. This domain may not have access', 'warn');
119
77
  return;
120
78
  }
121
- // disable place order button until checkout is loaded
122
- this.disablePlaceOrderButtons({
123
- disable: true,
124
- });
125
79
  // init zonos notification
126
80
  this.initZonosNotification();
127
81
  // load default setting if fail to load user setting
@@ -111,6 +111,11 @@ Zonos.disablePlaceOrderButtons = ({ autoEnable = true, disable, placeOrderButton
111
111
  }
112
112
  };
113
113
  placeOrderButton.forEach(button => {
114
+ const isEventAttached = button.getAttribute('data-zonos-checkout-attached');
115
+ if (isEventAttached) {
116
+ // do nothing if event is already attached
117
+ return;
118
+ }
114
119
  if (disable) {
115
120
  button.setAttribute('disabled', 'true');
116
121
  // prevent the selector to perform default action when it's disabled
@@ -147,6 +152,17 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
147
152
  disable: true,
148
153
  placeOrderButtonSelector,
149
154
  });
155
+ // create a mutation observer to see if any new elements that match our selector is added to the DOM
156
+ const observer = new MutationObserver(() => {
157
+ _a.disablePlaceOrderButtons({
158
+ disable: true,
159
+ placeOrderButtonSelector,
160
+ });
161
+ });
162
+ observer.observe(document.body, {
163
+ childList: true,
164
+ subtree: true,
165
+ });
150
166
  }
151
167
  const zonosController = document.createElement('zonos-controller');
152
168
  zonosController.config = config;
@@ -0,0 +1 @@
1
+ export {};
@@ -17,6 +17,10 @@ export const addressResult = {
17
17
  Unavailable: 'UNAVAILABLE',
18
18
  Valid: 'VALID',
19
19
  };
20
+ export const alcoholRecipientType = {
21
+ Consumer: 'CONSUMER',
22
+ Licensee: 'LICENSEE',
23
+ };
20
24
  export const analyticsProviderStatus = {
21
25
  Disabled: 'DISABLED',
22
26
  Enabled: 'ENABLED',
@@ -29,6 +33,15 @@ export const bankAccountType = {
29
33
  Checking: 'CHECKING',
30
34
  Savings: 'SAVINGS',
31
35
  };
36
+ export const batteryMaterialType = {
37
+ LithiumIon: 'LITHIUM_ION',
38
+ LithiumMetal: 'LITHIUM_METAL',
39
+ };
40
+ export const batteryPackingType = {
41
+ BatteryInsideEquipment: 'BATTERY_INSIDE_EQUIPMENT',
42
+ BatteryOnly: 'BATTERY_ONLY',
43
+ BatteryPackagedWithEquipment: 'BATTERY_PACKAGED_WITH_EQUIPMENT',
44
+ };
32
45
  export const billingOptionCode = {
33
46
  DdpAndDdu: 'DDP_AND_DDU',
34
47
  ShipperOnly: 'SHIPPER_ONLY',
@@ -925,6 +938,12 @@ export const deMinimisType = {
925
938
  Fee: 'FEE',
926
939
  Tax: 'TAX',
927
940
  };
941
+ export const deleteJobStatus = {
942
+ Completed: 'COMPLETED',
943
+ Error: 'ERROR',
944
+ Initialized: 'INITIALIZED',
945
+ Processing: 'PROCESSING',
946
+ };
928
947
  export const deliveryType = {
929
948
  Consolidated: 'CONSOLIDATED',
930
949
  Courier: 'COURIER',
@@ -1607,6 +1626,7 @@ export const shipmentAmountType = {
1607
1626
  };
1608
1627
  export const shipmentCartonSpecialService = {
1609
1628
  Alcohol: 'ALCOHOL',
1629
+ Battery: 'BATTERY',
1610
1630
  BatteryInsideEquipment: 'BATTERY_INSIDE_EQUIPMENT',
1611
1631
  BatteryOnly: 'BATTERY_ONLY',
1612
1632
  BatteryPackagedWithEquipment: 'BATTERY_PACKAGED_WITH_EQUIPMENT',
@@ -1633,6 +1653,10 @@ export const shipmentStatusType = {
1633
1653
  Created: 'CREATED',
1634
1654
  Voided: 'VOIDED',
1635
1655
  };
1656
+ export const shipmentType = {
1657
+ Domestic: 'DOMESTIC',
1658
+ International: 'INTERNATIONAL',
1659
+ };
1636
1660
  export const shippingPaymentType = {
1637
1661
  Sender: 'SENDER',
1638
1662
  ThirdParty: 'THIRD_PARTY',
@@ -1641,6 +1665,13 @@ export const shippingRateCalculation = {
1641
1665
  Fixed: 'FIXED',
1642
1666
  PerUnit: 'PER_UNIT',
1643
1667
  };
1668
+ export const signatureOptionType = {
1669
+ Adult: 'ADULT',
1670
+ Default: 'DEFAULT',
1671
+ Direct: 'DIRECT',
1672
+ Indirect: 'INDIRECT',
1673
+ None: 'NONE',
1674
+ };
1644
1675
  export const stripeActiveStatus = {
1645
1676
  Active: 'ACTIVE',
1646
1677
  Inactive: 'INACTIVE',
@@ -1849,5 +1880,8 @@ export function getSdk(client, withWrapper = defaultWrapper) {
1849
1880
  ZonosSettings(variables, requestHeaders) {
1850
1881
  return withWrapper(wrappedRequestHeaders => client.request('', variables, Object.assign(Object.assign({}, requestHeaders), wrappedRequestHeaders)), 'ZonosSettings', 'query');
1851
1882
  },
1883
+ getCheckoutPlaceOrderButtonSelector(variables, requestHeaders) {
1884
+ return withWrapper(wrappedRequestHeaders => client.request('', variables, Object.assign(Object.assign({}, requestHeaders), wrappedRequestHeaders)), 'getCheckoutPlaceOrderButtonSelector', 'query');
1885
+ },
1852
1886
  };
1853
1887
  }
@@ -33,17 +33,51 @@ const ZonosCheckoutFinish = /*@__PURE__*/ proxyCustomElement(class ZonosCheckout
33
33
  await ((_b = (_a = zonosStore.checkoutSettings).onOrderSuccess) === null || _b === void 0 ? void 0 : _b.call(_a, json));
34
34
  return json;
35
35
  };
36
+ this.handleSuccessBehavior = (orderId) => {
37
+ const { successBehavior } = zonosStore.checkoutSettings;
38
+ switch (successBehavior) {
39
+ case 'REDIRECT_TO_SUCCESS_PAGE':
40
+ const redirectUrl = zonosStore.checkoutSettings.successRedirectUrl;
41
+ if (redirectUrl) {
42
+ window.location.href = `${redirectUrl}?zOrderNumber=${orderId}`;
43
+ }
44
+ // If no redirect URL, break and display Zonos success page
45
+ break;
46
+ case 'CLOSE_MODAL':
47
+ this.closeClickHandler();
48
+ break;
49
+ }
50
+ };
36
51
  // TODO: This method of pulling orders is temporary. Once we have a working event registry system, we will rely on that to tell us when the order is ready to trigger onOrderSuccess
37
52
  this.getPullOrder = async (attempts = 0) => {
38
53
  const order = await this.pullOrder();
39
54
  if (order) {
40
55
  this.order = order;
56
+ this.handleSuccessBehavior(order.id);
57
+ this.isLoading = false;
41
58
  }
42
59
  else if (!order && attempts < 5) {
43
60
  // Wait for 1 second before the next attempt
44
61
  await new Promise(resolve => setTimeout(resolve, 1000));
45
62
  await this.getPullOrder(attempts + 1);
46
63
  }
64
+ else {
65
+ // Set loading to false to display generic success page and log error
66
+ this.isLoading = false;
67
+ const errorObject = {
68
+ endpoint: `${"https://v1.route.js.zonos.com"}/api/zonos-elements/get-order`,
69
+ errors: ['Order not found after multiple attempts'],
70
+ metadata: {
71
+ checkoutSessionId: cartStore.checkoutSessionId || '',
72
+ domain: window.location.hostname,
73
+ storeId: zonosStore.storeId,
74
+ },
75
+ };
76
+ void handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/log-error`, {
77
+ body: errorObject,
78
+ method: 'POST',
79
+ });
80
+ }
47
81
  };
48
82
  this.checkPaymentStatus = async () => {
49
83
  this.isLoading = true;
@@ -72,6 +106,7 @@ const ZonosCheckoutFinish = /*@__PURE__*/ proxyCustomElement(class ZonosCheckout
72
106
  }
73
107
  // Attempt to pull the order details from the graph every second on 5 attempts
74
108
  if (this.notificationType === 'success') {
109
+ this.isLoading = true;
75
110
  void this.getPullOrder();
76
111
  }
77
112
  }
@@ -177,6 +177,7 @@ const ZonosCheckout$1 = /*@__PURE__*/ proxyCustomElement(class ZonosCheckout ext
177
177
  });
178
178
  }
179
179
  });
180
+ button.removeAttribute('disabled');
180
181
  button.setAttribute('data-zonos-checkout-attached', 'true');
181
182
  });
182
183
  }
@@ -240,10 +241,14 @@ const ZonosCheckout$1 = /*@__PURE__*/ proxyCustomElement(class ZonosCheckout ext
240
241
  }
241
242
  else {
242
243
  this.attachCheckout();
243
- // keep checking for checkout selector every 50ms just in case the selector is not loaded in the DOM yet
244
- setInterval(() => {
244
+ // create a mutation observer to see if any new elements that match our selector is added to the DOM
245
+ const observer = new MutationObserver(() => {
245
246
  this.attachCheckout();
246
- }, 50);
247
+ });
248
+ observer.observe(document.body, {
249
+ childList: true,
250
+ subtree: true,
251
+ });
247
252
  }
248
253
  clearInterval(interval);
249
254
  }, 50);
@@ -64,44 +64,6 @@ const ZonosController$1 = /*@__PURE__*/ proxyCustomElement(class ZonosController
64
64
  this.__registerHost();
65
65
  this.__attachShadow();
66
66
  this.stripeInitEvent = createEvent(this, "stripeInitEvent", 7);
67
- this.disablePlaceOrderButtons = ({ disable }) => {
68
- const placeOrderButtonSelector = zonosStore.checkoutSettings.placeOrderButtonSelector;
69
- if (!placeOrderButtonSelector) {
70
- return;
71
- }
72
- const disableEvent = (e) => {
73
- const target = e.target;
74
- // prevent default and propagation when the item has disabled attribute
75
- if (target.getAttribute('disabled')) {
76
- e.preventDefault();
77
- e.stopPropagation();
78
- }
79
- };
80
- const placeOrderButton = document.querySelectorAll(placeOrderButtonSelector);
81
- placeOrderButton.forEach(button => {
82
- if (disable) {
83
- button.setAttribute('disabled', 'true');
84
- // prevent the selector to perform default action when it's disabled
85
- button.addEventListener('click', disableEvent);
86
- }
87
- else {
88
- button.removeAttribute('disabled');
89
- // clean up the event listener
90
- button.removeEventListener('click', disableEvent);
91
- }
92
- });
93
- // only auto enable if autoEnable is true and the state is enable
94
- if (disable) {
95
- setTimeout(() => {
96
- // release it if zonos is not initialized after 5 seconds (this is to prevent the place order button from being disabled forever due to api)
97
- placeOrderButton.forEach(button => {
98
- button.removeAttribute('disabled');
99
- // clean up the event listener if exists
100
- button.removeEventListener('click', disableEvent);
101
- });
102
- }, 5000);
103
- }
104
- };
105
67
  this.config = undefined;
106
68
  this.zonosApiKey = undefined;
107
69
  }
@@ -117,10 +79,6 @@ const ZonosController$1 = /*@__PURE__*/ proxyCustomElement(class ZonosController
117
79
  stripeStore.stripe = stripe;
118
80
  void initCheckout(zonosStore.checkoutSettings);
119
81
  log('init checkout element');
120
- // enable place order button after checkout is loaded
121
- this.disablePlaceOrderButtons({
122
- disable: false,
123
- });
124
82
  }
125
83
  /**
126
84
  * Init zonos notification
@@ -173,10 +131,6 @@ const ZonosController$1 = /*@__PURE__*/ proxyCustomElement(class ZonosController
173
131
  log('Failed to load zonos settings. This domain may not have access', 'warn');
174
132
  return;
175
133
  }
176
- // disable place order button until checkout is loaded
177
- this.disablePlaceOrderButtons({
178
- disable: true,
179
- });
180
134
  // init zonos notification
181
135
  this.initZonosNotification();
182
136
  // load default setting if fail to load user setting
@@ -8,7 +8,7 @@ import { d as defineCustomElement$1 } from './zonos-spinner2.js';
8
8
 
9
9
  const RemoveIcon = `<svg xmlns="https://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path fill="#C5C6CA" fill-rule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z" clip-rule="evenodd"/><path fill="#4D505A" fill-rule="evenodd" d="M8.293 8.293a1 1 0 0 1 1.414 0L12 10.586l2.293-2.293a1 1 0 1 1 1.414 1.414L13.414 12l2.293 2.293a1 1 0 0 1-1.414 1.414L12 13.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L10.586 12 8.293 9.707a1 1 0 0 1 0-1.414Z" clip-rule="evenodd"/></svg>`;
10
10
 
11
- const zonosDialogCss = ":host{font-family:var(--font-family, Inter), Inter;display:block;white-space:normal}:host *{font-family:var(--font-family, Inter), Inter}:host img{max-width:100%}:host dl,:host dd,:host h1,:host h2,:host h3,:host h4,:host h5,:host h6,:host hr,:host figure,:host p,:host pre{margin:0}:host{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}:host .zonos--backdrop,:host .zonos--dialog-layout{opacity:0;z-index:-999;visibility:hidden;-webkit-transition:0.3s all ease;transition:0.3s all ease}:host .zonos--backdrop{width:100vw;height:100vh;left:0px;top:0px;background:var(--amino-backdrop-color);z-index:-999;opacity:0;visibility:hidden;position:fixed}:host .zonos--loading{position:absolute;left:0;right:0;bottom:0;top:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;z-index:1002;background:white}:host .zonos--dialog-layout{width:100vw;height:100vh;left:0;top:0;position:fixed;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;color:var(--amino-text-color);visibility:hidden}:host .zonos--dialog{position:relative;z-index:1001;background:var(--amino-gray-0);max-width:90vw;max-height:90vh;min-height:500px;height:var(--height, auto);width:var(--width, auto);border-radius:var(--border-radius, var(--amino-radius-10));outline:none;-webkit-box-shadow:var(--amino-v3-shadow-xxl);box-shadow:var(--amino-v3-shadow-xxl);border:var(--amino-border);overflow:hidden;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}:host .zonos--header{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;padding:var(--amino-space-16) var(--amino-space-24)}:host .zonos--header .-zonos-stencil-library--header-text{-ms-flex-positive:1;flex-grow:1}:host .zonos--header .zonos--close-button{width:var(--amino-size-md);height:var(--amino-size-md);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;cursor:pointer;border-radius:var(--amino-radius-10)}:host .zonos--header .zonos--close-button:hover{background:var(--amino-hover-color)}:host .zonos--body{padding:var(--amino-space-8) var(--amino-space-24);max-height:100%;height:100%;overflow:auto}:host .zonos--body.zonos--no-body-padding{padding:0}:host .zonos--footer{padding:var(--amino-space-16) var(--amino-space-24)}:host(.open) .zonos--dialog-layout,:host(.open) .zonos--backdrop{visibility:visible}:host(.open) .zonos--backdrop{z-index:1001;opacity:0.65}:host(.open) .zonos--dialog-layout{opacity:1;z-index:1002;-webkit-transform:scale(1);transform:scale(1)}:host(.no-border) .zonos--dialog{border:none}:host(.mobile) .zonos--dialog{max-width:100vw;max-height:100vh;height:100%;width:100%;border-radius:0;-webkit-box-shadow:none;box-shadow:none;border:none}";
11
+ const zonosDialogCss = ":host{font-family:var(--font-family, Inter), Inter;display:block;white-space:normal}:host *{font-family:var(--font-family, Inter), Inter}:host img{max-width:100%}:host dl,:host dd,:host h1,:host h2,:host h3,:host h4,:host h5,:host h6,:host hr,:host figure,:host p,:host pre{margin:0}:host{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}:host .zonos--backdrop,:host .zonos--dialog-layout{opacity:0;z-index:-999;visibility:hidden;-webkit-transition:0.3s all ease;transition:0.3s all ease}:host .zonos--backdrop{width:100vw;height:100vh;left:0px;top:0px;background:var(--amino-backdrop-color);z-index:-999;opacity:0;visibility:hidden;position:fixed}:host .zonos--loading{position:absolute;left:0;right:0;bottom:0;top:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;z-index:10002;background:white}:host .zonos--dialog-layout{width:100vw;height:100vh;left:0;top:0;position:fixed;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;color:var(--amino-text-color);visibility:hidden}:host .zonos--dialog{position:relative;z-index:10001;background:var(--amino-gray-0);max-width:90vw;max-height:90vh;min-height:500px;height:var(--height, auto);width:var(--width, auto);border-radius:var(--border-radius, var(--amino-radius-10));outline:none;-webkit-box-shadow:var(--amino-v3-shadow-xxl);box-shadow:var(--amino-v3-shadow-xxl);border:var(--amino-border);overflow:hidden;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}:host .zonos--header{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;padding:var(--amino-space-16) var(--amino-space-24)}:host .zonos--header .-zonos-stencil-library--header-text{-ms-flex-positive:1;flex-grow:1}:host .zonos--header .zonos--close-button{width:var(--amino-size-md);height:var(--amino-size-md);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;cursor:pointer;border-radius:var(--amino-radius-10)}:host .zonos--header .zonos--close-button:hover{background:var(--amino-hover-color)}:host .zonos--body{padding:var(--amino-space-8) var(--amino-space-24);max-height:100%;height:100%;overflow:auto}:host .zonos--body.zonos--no-body-padding{padding:0}:host .zonos--footer{padding:var(--amino-space-16) var(--amino-space-24)}:host(.open) .zonos--dialog-layout,:host(.open) .zonos--backdrop{visibility:visible}:host(.open) .zonos--backdrop{z-index:10001;opacity:0.65}:host(.open) .zonos--dialog-layout{opacity:1;z-index:10002;-webkit-transform:scale(1);transform:scale(1)}:host(.no-border) .zonos--dialog{border:none}:host(.mobile) .zonos--dialog{max-width:100vw;max-height:100vh;height:100%;width:100%;border-radius:0;-webkit-box-shadow:none;box-shadow:none;border:none}";
12
12
 
13
13
  const ZonosDialog = /*@__PURE__*/ proxyCustomElement(class ZonosDialog extends HTMLElement {
14
14
  constructor() {