@zonos/elements 1.3.50 → 1.3.52

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 (208) hide show
  1. package/dist/cjs/CheckoutConfig-65376e00.js +40 -0
  2. package/dist/cjs/{cart-688d674d.js → cart-61a8983d.js} +238 -370
  3. package/dist/cjs/{createCustomEvent-01bacaea.js → createCustomEvent-228027b5.js} +3 -2
  4. package/dist/cjs/handleFetch-842c95b0.js +322 -0
  5. package/dist/cjs/index.cjs.js +75 -35
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/cjs/{paypal-ce1516ba.js → paypal-f1eb6621.js} +16 -16
  8. package/dist/cjs/zonos-address_8.cjs.entry.js +4 -4
  9. package/dist/cjs/{zonos-cart-items_12.cjs.entry.js → zonos-badge_13.cjs.entry.js} +41 -9
  10. package/dist/cjs/zonos-checkout.cjs.entry.js +75 -174
  11. package/dist/cjs/zonos-controller.cjs.entry.js +27 -25
  12. package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
  13. package/dist/cjs/zonos-country-select_4.cjs.entry.js +2 -2
  14. package/dist/cjs/zonos-elements.cjs.js +1 -1
  15. package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
  16. package/dist/cjs/zonos-hello.cjs.entry.js +11 -11
  17. package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
  18. package/dist/cjs/zonos-notification_3.cjs.entry.js +9 -9
  19. package/dist/cjs/zonos-tooltip.cjs.entry.js +27 -0
  20. package/dist/collection/components/checkout/zonos-checkout/zonos-cart-subtotal/zonos-cart-subtotal.js +5 -2
  21. package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +44 -20
  22. package/dist/collection/components/store/checkout/cart.js +14 -2
  23. package/dist/collection/components/store/checkout/stripe.js +9 -4
  24. package/dist/collection/components/store/translationStore/strings.arabic.js +3 -3
  25. package/dist/collection/components/store/translationStore/strings.base.js +3 -3
  26. package/dist/collection/components/store/translationStore/strings.chinese.js +3 -3
  27. package/dist/collection/components/store/translationStore/strings.danish.js +3 -3
  28. package/dist/collection/components/store/translationStore/strings.dutch.js +3 -3
  29. package/dist/collection/components/store/translationStore/strings.french.js +3 -3
  30. package/dist/collection/components/store/translationStore/strings.german.js +3 -3
  31. package/dist/collection/components/store/translationStore/strings.hebrew.js +3 -3
  32. package/dist/collection/components/store/translationStore/strings.indonesian.js +3 -3
  33. package/dist/collection/components/store/translationStore/strings.italian.js +3 -3
  34. package/dist/collection/components/store/translationStore/strings.japanese.js +3 -3
  35. package/dist/collection/components/store/translationStore/strings.korean.js +3 -3
  36. package/dist/collection/components/store/translationStore/strings.norwegian.js +3 -3
  37. package/dist/collection/components/store/translationStore/strings.polish.js +3 -3
  38. package/dist/collection/components/store/translationStore/strings.portuguese.js +3 -3
  39. package/dist/collection/components/store/translationStore/strings.russian.js +3 -3
  40. package/dist/collection/components/store/translationStore/strings.spanish.js +3 -3
  41. package/dist/collection/components/store/translationStore/strings.swedish.js +3 -3
  42. package/dist/collection/components/store/translationStore/strings.turkish.js +3 -3
  43. package/dist/collection/components/store/translationStore/strings.vietnamese.js +3 -3
  44. package/dist/collection/components/utils/api/buildCartItemsByTempCart.js +14 -14
  45. package/dist/collection/components/utils/api/calculateLandedCostNormalized.js +28 -0
  46. package/dist/collection/components/utils/api/cartCalculateLandedCost.js +19 -0
  47. package/dist/collection/components/utils/api/prepCalculateLandedCost.js +65 -0
  48. package/dist/collection/components/utils/api/triggerBuildLandedCost.js +2 -2
  49. package/dist/collection/components/utils/checkout/initCheckout.js +4 -2
  50. package/dist/collection/components/utils/handleFetch.js +6 -1
  51. package/dist/collection/environment.js +1 -1
  52. package/dist/collection/scripts/_getNextFallbackUrl.js +1 -0
  53. package/dist/collection/scripts/_getTempCartById.js +14 -0
  54. package/dist/collection/scripts/_zonosBase.js +39 -10
  55. package/dist/collection/scripts/cart/_getCartIdFromParam.js +9 -0
  56. package/dist/collection/scripts/cart/_setupCartData.js +18 -0
  57. package/dist/collection/types/checkout/CheckoutConfig.js +2 -1
  58. package/dist/collection/types/generated/graphql.customer.types.js +12 -0
  59. package/dist/collection/utils/formattedCloudflareApiUrl.js +8 -2
  60. package/dist/collection/utils/generateCloudflareDeployUrl.js +3 -0
  61. package/dist/esm/CheckoutConfig-57350b28.js +36 -0
  62. package/dist/esm/{cart-4f300fcb.js → cart-45d2861f.js} +194 -323
  63. package/dist/esm/{createCustomEvent-c5ed9070.js → createCustomEvent-3fcc948a.js} +2 -1
  64. package/dist/esm/handleFetch-37cea185.js +315 -0
  65. package/dist/esm/index.js +56 -17
  66. package/dist/esm/loader.js +1 -1
  67. package/dist/esm/{paypal-70caf283.js → paypal-ee310945.js} +2 -2
  68. package/dist/esm/zonos-address_8.entry.js +2 -2
  69. package/dist/esm/{zonos-cart-items_12.entry.js → zonos-badge_13.entry.js} +40 -9
  70. package/dist/esm/zonos-checkout.entry.js +61 -160
  71. package/dist/esm/zonos-controller.entry.js +6 -4
  72. package/dist/esm/zonos-country-flag.entry.js +2 -2
  73. package/dist/esm/zonos-country-select_4.entry.js +2 -2
  74. package/dist/esm/zonos-elements.js +1 -1
  75. package/dist/esm/zonos-hello-dialog.entry.js +2 -2
  76. package/dist/esm/zonos-hello.entry.js +2 -2
  77. package/dist/esm/zonos-language-select_2.entry.js +2 -2
  78. package/dist/esm/zonos-notification_3.entry.js +3 -3
  79. package/dist/esm/zonos-tooltip.entry.js +23 -0
  80. package/dist/esm-es5/CheckoutConfig-57350b28.js +1 -0
  81. package/dist/esm-es5/cart-45d2861f.js +1 -0
  82. package/dist/esm-es5/{createCustomEvent-c5ed9070.js → createCustomEvent-3fcc948a.js} +1 -1
  83. package/dist/esm-es5/handleFetch-37cea185.js +1 -0
  84. package/dist/esm-es5/index.js +1 -1
  85. package/dist/esm-es5/loader.js +1 -1
  86. package/dist/esm-es5/{paypal-70caf283.js → paypal-ee310945.js} +1 -1
  87. package/dist/esm-es5/zonos-address_8.entry.js +1 -1
  88. package/dist/esm-es5/zonos-badge_13.entry.js +1 -0
  89. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  90. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  91. package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
  92. package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
  93. package/dist/esm-es5/zonos-elements.js +1 -1
  94. package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
  95. package/dist/esm-es5/zonos-hello.entry.js +1 -1
  96. package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
  97. package/dist/esm-es5/zonos-notification_3.entry.js +1 -1
  98. package/dist/esm-es5/zonos-tooltip.entry.js +1 -0
  99. package/dist/scripts/index.d.ts +74 -87
  100. package/dist/scripts/index.js +1 -1
  101. package/dist/scripts/loadZonos.js +1 -1
  102. package/dist/scripts/zonos.js +1 -1
  103. package/dist/types/components/checkout/zonos-checkout/zonos-checkout.d.ts +0 -2
  104. package/dist/types/components/store/checkout/cart.d.ts +13 -3
  105. package/dist/types/components/store/checkout/stripe.d.ts +3 -1
  106. package/dist/types/components/store/translationStore/strings.arabic.d.ts +3 -3
  107. package/dist/types/components/store/translationStore/strings.base.d.ts +3 -3
  108. package/dist/types/components/store/translationStore/strings.chinese.d.ts +3 -3
  109. package/dist/types/components/store/translationStore/strings.danish.d.ts +3 -3
  110. package/dist/types/components/store/translationStore/strings.dutch.d.ts +3 -3
  111. package/dist/types/components/store/translationStore/strings.french.d.ts +3 -3
  112. package/dist/types/components/store/translationStore/strings.german.d.ts +3 -3
  113. package/dist/types/components/store/translationStore/strings.hebrew.d.ts +3 -3
  114. package/dist/types/components/store/translationStore/strings.indonesian.d.ts +3 -3
  115. package/dist/types/components/store/translationStore/strings.italian.d.ts +3 -3
  116. package/dist/types/components/store/translationStore/strings.japanese.d.ts +3 -3
  117. package/dist/types/components/store/translationStore/strings.korean.d.ts +3 -3
  118. package/dist/types/components/store/translationStore/strings.norwegian.d.ts +3 -3
  119. package/dist/types/components/store/translationStore/strings.polish.d.ts +3 -3
  120. package/dist/types/components/store/translationStore/strings.portuguese.d.ts +3 -3
  121. package/dist/types/components/store/translationStore/strings.russian.d.ts +3 -3
  122. package/dist/types/components/store/translationStore/strings.spanish.d.ts +3 -3
  123. package/dist/types/components/store/translationStore/strings.swedish.d.ts +3 -3
  124. package/dist/types/components/store/translationStore/strings.turkish.d.ts +3 -3
  125. package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +3 -3
  126. package/dist/types/components/store/translationStore.d.ts +1 -1
  127. package/dist/types/components/utils/api/buildCartItemsByTempCart.d.ts +8 -3
  128. package/dist/types/components/utils/api/calculateLandedCostNormalized.d.ts +2 -0
  129. package/dist/types/components/utils/api/cartCalculateLandedCost.d.ts +5 -0
  130. package/dist/types/components/utils/api/prepCalculateLandedCost.d.ts +5 -1
  131. package/dist/types/components/utils/checkout/getIsTestMode.d.ts +1 -1
  132. package/dist/types/scripts/_getNextFallbackUrl.d.ts +1 -0
  133. package/dist/types/scripts/_getTempCartById.d.ts +8 -0
  134. package/dist/types/scripts/_zonosBase.d.ts +15 -12
  135. package/dist/types/scripts/cart/_getCartIdFromParam.d.ts +4 -0
  136. package/dist/types/scripts/cart/_setupCartData.d.ts +7 -0
  137. package/dist/types/types/checkout/CheckoutConfig.d.ts +18 -3
  138. package/dist/types/types/checkout/api/CalculateLandedCostRequest.d.ts +42 -1
  139. package/dist/types/types/checkout/api/NormalizedTempCart.d.ts +37 -0
  140. package/dist/types/types/generated/graphql.customer.types.d.ts +249 -2
  141. package/dist/types/types/generated/graphql.customer.types.ts +251 -3
  142. package/dist/types/utils/formattedCloudflareApiUrl.d.ts +2 -2
  143. package/dist/zonos-elements/index.esm.js +1 -1
  144. package/dist/zonos-elements/p-042c466d.system.entry.js +1 -0
  145. package/dist/zonos-elements/p-10cb0064.entry.js +1 -0
  146. package/dist/zonos-elements/{p-fe198a6c.entry.js → p-259ccf8d.entry.js} +1 -1
  147. package/dist/zonos-elements/p-2a47d2cc.system.entry.js +1 -0
  148. package/dist/zonos-elements/{p-89b1f4a5.entry.js → p-31eb835c.entry.js} +1 -1
  149. package/dist/zonos-elements/{p-4849604d.entry.js → p-36360905.entry.js} +1 -1
  150. package/dist/zonos-elements/{p-322600aa.system.entry.js → p-3703b814.system.entry.js} +1 -1
  151. package/dist/zonos-elements/p-4146feec.js +1 -0
  152. package/dist/zonos-elements/p-446c8f02.system.entry.js +1 -0
  153. package/dist/zonos-elements/{p-31905b60.system.js → p-5590f90c.system.js} +1 -1
  154. package/dist/zonos-elements/p-588396df.js +1 -0
  155. package/dist/zonos-elements/{p-124e3426.js → p-6e59c6e4.js} +2 -2
  156. package/dist/zonos-elements/p-6eedc3f8.entry.js +1 -0
  157. package/dist/zonos-elements/p-747eed39.entry.js +1 -0
  158. package/dist/zonos-elements/{p-d1cd0a5f.system.entry.js → p-8228e87c.system.entry.js} +1 -1
  159. package/dist/zonos-elements/p-827868e6.entry.js +1 -0
  160. package/dist/zonos-elements/{p-a67578ae.entry.js → p-88005b94.entry.js} +1 -1
  161. package/dist/zonos-elements/p-895fdefb.js +1 -0
  162. package/dist/zonos-elements/p-8f7773b0.system.js +1 -0
  163. package/dist/zonos-elements/{p-480a6094.entry.js → p-8fa49d94.entry.js} +1 -1
  164. package/dist/zonos-elements/p-a74a7afa.system.js +1 -0
  165. package/dist/zonos-elements/p-b1861e64.system.js +1 -0
  166. package/dist/zonos-elements/{p-ec31cd17.system.entry.js → p-b842b96a.system.entry.js} +1 -1
  167. package/dist/zonos-elements/{p-1719bedd.entry.js → p-bb186075.entry.js} +1 -1
  168. package/dist/zonos-elements/{p-8af4a9e7.system.entry.js → p-c008648a.system.entry.js} +1 -1
  169. package/dist/zonos-elements/p-c78dd680.system.js +1 -1
  170. package/dist/zonos-elements/{p-22e8d4ad.system.entry.js → p-cd4ad1be.system.entry.js} +1 -1
  171. package/dist/zonos-elements/{p-e7e73693.system.entry.js → p-d62e6bb0.system.entry.js} +1 -1
  172. package/dist/zonos-elements/{p-40d52dd6.system.entry.js → p-dc12f30a.system.entry.js} +1 -1
  173. package/dist/zonos-elements/p-eb2aedd0.js +1 -0
  174. package/dist/zonos-elements/{p-ceb8b836.system.js → p-f124e459.system.js} +2 -2
  175. package/dist/zonos-elements/p-f527cd5b.entry.js +1 -0
  176. package/dist/zonos-elements/p-f826b979.system.entry.js +1 -0
  177. package/dist/zonos-elements/p-f87a635b.system.js +1 -0
  178. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  179. package/package.json +2 -1
  180. package/dist/cjs/logError-4e2f2020.js +0 -58
  181. package/dist/cjs/zonos-badge_2.cjs.entry.js +0 -57
  182. package/dist/collection/components/utils/api/tempCartItem/getAttributes.js +0 -66
  183. package/dist/collection/components/utils/api/tempCartItem/getMeasurements.js +0 -58
  184. package/dist/esm/logError-c456c092.js +0 -55
  185. package/dist/esm/zonos-badge_2.entry.js +0 -52
  186. package/dist/esm-es5/cart-4f300fcb.js +0 -1
  187. package/dist/esm-es5/logError-c456c092.js +0 -1
  188. package/dist/esm-es5/zonos-badge_2.entry.js +0 -1
  189. package/dist/esm-es5/zonos-cart-items_12.entry.js +0 -1
  190. package/dist/types/components/utils/api/tempCartItem/getAttributes.d.ts +0 -11
  191. package/dist/types/components/utils/api/tempCartItem/getMeasurements.d.ts +0 -7
  192. package/dist/types/types/checkout/api/TempCart.d.ts +0 -80
  193. package/dist/zonos-elements/p-00f219bd.entry.js +0 -1
  194. package/dist/zonos-elements/p-05dff37f.js +0 -1
  195. package/dist/zonos-elements/p-1f2db2ff.entry.js +0 -1
  196. package/dist/zonos-elements/p-2018969a.js +0 -1
  197. package/dist/zonos-elements/p-27f2e8af.system.entry.js +0 -1
  198. package/dist/zonos-elements/p-4452dddc.entry.js +0 -1
  199. package/dist/zonos-elements/p-47c72c50.system.entry.js +0 -1
  200. package/dist/zonos-elements/p-595d406e.entry.js +0 -1
  201. package/dist/zonos-elements/p-5beccdce.system.entry.js +0 -1
  202. package/dist/zonos-elements/p-6013e370.entry.js +0 -1
  203. package/dist/zonos-elements/p-63db40b9.system.js +0 -1
  204. package/dist/zonos-elements/p-6ab615e6.system.js +0 -1
  205. package/dist/zonos-elements/p-81540fd6.system.js +0 -1
  206. package/dist/zonos-elements/p-d709ad28.system.entry.js +0 -1
  207. package/dist/zonos-elements/p-eaa335e1.js +0 -1
  208. /package/dist/collection/types/checkout/api/{TempCart.js → NormalizedTempCart.js} +0 -0
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const cart = require('./cart-688d674d.js');
3
+ const cart = require('./cart-61a8983d.js');
4
4
  const zonosStore = require('./zonosStore-67139f0e.js');
5
+ const handleFetch = require('./handleFetch-842c95b0.js');
5
6
 
6
7
  const trackConversionEvent = async (eventName, metadata) => {
7
8
  var _a, _b;
@@ -29,7 +30,7 @@ const trackConversionEvent = async (eventName, metadata) => {
29
30
  metadata,
30
31
  organizationId,
31
32
  };
32
- await cart.handleFetch('/api/zonos-elements/track-conversion-event', {
33
+ await handleFetch.handleFetch('/api/zonos-elements/track-conversion-event', {
33
34
  body,
34
35
  method: 'POST',
35
36
  });
@@ -0,0 +1,322 @@
1
+ 'use strict';
2
+
3
+ const log = (message, type, ...additionalInfo) => {
4
+ var _a, _b;
5
+ const isDebug = !!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.debug) ||
6
+ !!window.location.search.match(/\?.*(&*)zonosDebug=1/);
7
+ // if debug is false, do not log
8
+ if (!isDebug) {
9
+ // log errors to the console if the type is error
10
+ if (type === 'error') {
11
+ // eslint-disable-next-line no-console
12
+ console.error(message, ...additionalInfo);
13
+ }
14
+ return;
15
+ }
16
+ let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
17
+ if (!loggingIframe) {
18
+ // add a hidden iframe
19
+ loggingIframe = document.createElement('iframe');
20
+ loggingIframe.id = 'zonos---debug-logging-iframe';
21
+ loggingIframe.style.display = 'none';
22
+ loggingIframe.style.opacity = '0';
23
+ loggingIframe.style.position = 'absolute';
24
+ loggingIframe.style.top = '-9999px';
25
+ loggingIframe.style.left = '-9999px';
26
+ loggingIframe.style.width = '1px';
27
+ loggingIframe.style.height = '1px';
28
+ loggingIframe.style.border = 'none';
29
+ loggingIframe.style.overflow = 'hidden';
30
+ loggingIframe.style.visibility = 'hidden';
31
+ document.body.appendChild(loggingIframe);
32
+ }
33
+ // use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
34
+ const zConsole = ((_b = loggingIframe.contentWindow) === null || _b === void 0 ? void 0 : _b.window.console) || window.console;
35
+ switch (type) {
36
+ case 'warn':
37
+ zConsole.warn(message, ...additionalInfo);
38
+ break;
39
+ case 'info':
40
+ zConsole.info(message, ...additionalInfo);
41
+ break;
42
+ case 'error':
43
+ zConsole.error(message, ...additionalInfo);
44
+ break;
45
+ default:
46
+ zConsole.groupCollapsed(message, ...additionalInfo);
47
+ zConsole.trace();
48
+ zConsole.groupEnd();
49
+ break;
50
+ }
51
+ };
52
+
53
+ const logError = (message, ...rest) => {
54
+ log(message, 'error', ...rest);
55
+ };
56
+
57
+ const fallbackApiType = ['cloudflare', 'vercel'];
58
+ const MAIN_BASE_API_TYPE = fallbackApiType[0];
59
+ const fallbackApiList = {
60
+ cloudflare: "https://route.elements.zonos.com",
61
+ vercel: "https://v1.route.js.zonos.com",
62
+ };
63
+ const MAIN_BASE_API = fallbackApiList[MAIN_BASE_API_TYPE];
64
+ /**
65
+ * Next available fallback api type
66
+ */
67
+ const getNextFallbackApiType = (currentApiType = MAIN_BASE_API_TYPE) => {
68
+ const currentIndex = fallbackApiType.indexOf(currentApiType);
69
+ const nextFallbackApiType = fallbackApiType[currentIndex + 1];
70
+ if (!nextFallbackApiType) {
71
+ return null;
72
+ }
73
+ return nextFallbackApiType;
74
+ };
75
+
76
+ const jsonParse = (_data) => {
77
+ if (typeof _data === 'string') {
78
+ try {
79
+ // eslint-disable-next-line no-restricted-syntax
80
+ const json = JSON.parse(_data);
81
+ return json;
82
+ }
83
+ catch (_error) {
84
+ return null;
85
+ }
86
+ }
87
+ return null;
88
+ };
89
+
90
+ /**
91
+ * This is the time in milliseconds after release time that we will start sending error logs to the new API
92
+ * @default 1 hour
93
+ */
94
+ const postReleaseReportingDuration = 1 * 3600 * 1000; // 1 hour
95
+ const sendErrorLog = async ({ endpoint, errors, metadata, shouldPostReleaseErrorReporting, }) => {
96
+ if (shouldPostReleaseErrorReporting) {
97
+ // We only want to report errors that happened if current time is less than 2 hours after release time
98
+ const releaseTime = Number(window.Zonos.releaseDate);
99
+ const currentTime = new Date().getTime();
100
+ if (currentTime - releaseTime > postReleaseReportingDuration) {
101
+ return;
102
+ }
103
+ }
104
+ const userAgentData = 'userAgentData' in window.navigator
105
+ ? // userAgentData is not yet supported in all browsers
106
+ window.navigator.userAgentData
107
+ : null;
108
+ const errorObject = {
109
+ endpoint,
110
+ errors,
111
+ metadata: Object.assign({ href: window.location.href, userAgent: userAgentData && userAgentData.brands.length > 0
112
+ ? userAgentData
113
+ : window.navigator.userAgent }, metadata),
114
+ };
115
+ try {
116
+ // use native fetch because in handleFetch also calls sendErrorLog and it will possibly cause circular dependencies issue
117
+ void fetch(`${MAIN_BASE_API}/api/zonos-elements/log-error`, {
118
+ body: JSON.stringify(errorObject),
119
+ method: 'POST',
120
+ });
121
+ }
122
+ catch (_err) {
123
+ const nextFallbackApi = getNextFallbackApiType();
124
+ if (!nextFallbackApi) {
125
+ return;
126
+ }
127
+ // request to the fallback API if the first one fails
128
+ void fetch(`${fallbackApiList[nextFallbackApi]}/api/zonos-elements/log-error`, {
129
+ body: JSON.stringify(errorObject),
130
+ method: 'POST',
131
+ });
132
+ }
133
+ };
134
+
135
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
136
+ var t = {};
137
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
138
+ t[p] = s[p];
139
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
140
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
141
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
142
+ t[p[i]] = s[p[i]];
143
+ }
144
+ return t;
145
+ };
146
+ const getResponseBody = async ({ response, shouldLog = true, shouldThrow = false, }) => {
147
+ try {
148
+ const json = await response.json();
149
+ return json;
150
+ }
151
+ catch (e) {
152
+ if (shouldThrow) {
153
+ throw e;
154
+ }
155
+ if (shouldLog) {
156
+ // eslint-disable-next-line
157
+ console.error(e);
158
+ }
159
+ return null;
160
+ }
161
+ };
162
+ const encodeString = (text) => {
163
+ try {
164
+ // encode the string, remove the "=" at the end of the encoded string
165
+ const encodedString = btoa(text).replace(/=/g, '');
166
+ return encodedString;
167
+ }
168
+ catch (error) {
169
+ // return the reverse string if the encoding failed
170
+ return text
171
+ .replace(/[^A-Za-z0-9]/g, '')
172
+ .split('')
173
+ .reverse()
174
+ .join('');
175
+ }
176
+ };
177
+ const handleRequest = async ({ basePathType, options, path, }) => {
178
+ let response;
179
+ // fallback to the main base API if the passed in base path is not available
180
+ const baseUrl = fallbackApiList[basePathType] || MAIN_BASE_API_TYPE;
181
+ const url = baseUrl + path;
182
+ // adding random encoded token to the url so that the request will be cached differently for each store
183
+ const modifiedUrl = new URL(url);
184
+ modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
185
+ try {
186
+ response = await fetch(modifiedUrl.toString(), options);
187
+ }
188
+ catch (e) {
189
+ if (e instanceof Error) {
190
+ return {
191
+ baseUrl,
192
+ errors: [{ message: e.message, type: 'unknown' }],
193
+ json: null,
194
+ response: null,
195
+ zonosMode: null,
196
+ };
197
+ }
198
+ const message = 'Fail to fetch';
199
+ return {
200
+ baseUrl,
201
+ errors: [{ message, type: 'unknown' }],
202
+ json: null,
203
+ response: null,
204
+ zonosMode: null,
205
+ };
206
+ }
207
+ const zonosMode = response.headers.get('Zonos-Mode');
208
+ const usingZonosPreview = window.Zonos.zonosQaUrl;
209
+ // We only want to alert once if the user is in preview mode and it's also using production environment
210
+ if (!window.Zonos.modeAlerted && zonosMode && usingZonosPreview) {
211
+ window.Zonos.modeAlerted = true;
212
+ }
213
+ if (response.ok) {
214
+ const data = await getResponseBody({ response });
215
+ return {
216
+ baseUrl,
217
+ errors: [],
218
+ json: data,
219
+ response,
220
+ zonosMode,
221
+ };
222
+ }
223
+ const status = response.status.toString();
224
+ try {
225
+ const data = await getResponseBody({
226
+ response,
227
+ shouldThrow: true,
228
+ });
229
+ const message = JSON.stringify(data);
230
+ return {
231
+ baseUrl,
232
+ errors: [{ message, type: status }],
233
+ json: null,
234
+ response,
235
+ zonosMode,
236
+ };
237
+ }
238
+ catch (e) {
239
+ const message = 'Unknown error';
240
+ return {
241
+ baseUrl,
242
+ errors: [{ message: `${status}: ${message}`, type: status }],
243
+ json: null,
244
+ response: null,
245
+ zonosMode,
246
+ };
247
+ }
248
+ };
249
+ const handleRequestWithFallback = async ({ basePathType: _basePathType, options, path, }) => {
250
+ var _a, _b;
251
+ // use vercel API if the path is `/api/bigcommerce`
252
+ const isBigcommerceEndpoint = path.startsWith('/api/bigcommerce');
253
+ const basePathType = isBigcommerceEndpoint
254
+ ? 'vercel'
255
+ : _basePathType;
256
+ const _c = await handleRequest({
257
+ basePathType,
258
+ options,
259
+ path,
260
+ }), { errors, response } = _c, rest = __rest(_c, ["errors", "response"]);
261
+ const nextFallbackApiType = getNextFallbackApiType(basePathType);
262
+ const unknownError = errors.find(({ type }) => type === 'unknown');
263
+ const isUnknownError = !!unknownError || (response === null || response === void 0 ? void 0 : response.status) === 404;
264
+ const shouldCallFallback =
265
+ // If next fallback is available, and the error is unknown (fail to fetch) or 404
266
+ nextFallbackApiType && isUnknownError;
267
+ // Should log the error if it's unknown error
268
+ if (isUnknownError) {
269
+ void sendErrorLog({
270
+ endpoint: fallbackApiList[basePathType] + path,
271
+ errors: errors.map(({ message }) => message),
272
+ metadata: {
273
+ currentBasePath: basePathType,
274
+ nextFallbackApiType,
275
+ requestHeaders: options === null || options === void 0 ? void 0 : options.headers,
276
+ requestPayload: jsonParse((_a = options === null || options === void 0 ? void 0 : options.body) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = options === null || options === void 0 ? void 0 : options.body) === null || _b === void 0 ? void 0 : _b.toString()),
277
+ status: response === null || response === void 0 ? void 0 : response.status,
278
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
279
+ },
280
+ // When the error is unknown, error reporting should be enabled for period of time after release, so we can monitor the error.
281
+ shouldPostReleaseErrorReporting: true,
282
+ });
283
+ }
284
+ if (shouldCallFallback) {
285
+ log(`=== "${path}" failed to fetch, trying next fallback ${nextFallbackApiType}`);
286
+ return handleRequestWithFallback({
287
+ basePathType: nextFallbackApiType,
288
+ options,
289
+ path,
290
+ });
291
+ }
292
+ // No more fallbacks, just return the result
293
+ return Object.assign({ errors, response }, rest);
294
+ };
295
+ /**
296
+ * Fetch request and will request to fallback API when the first one fails
297
+ * @param path Path name of the request (e.g. /api/something/com).
298
+ * @param _opts fetch options
299
+ */
300
+ const handleFetch = async (path, _opts) => {
301
+ const opts = __rest(_opts || {}, []);
302
+ const body = opts.body ? JSON.stringify(opts.body) : undefined;
303
+ const method = opts.method || 'GET';
304
+ // headers content type
305
+ 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);
306
+ const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
307
+ method });
308
+ // This is for testing fallback API, set fallback API type to start with
309
+ const useFallbackApi = new URLSearchParams(window.location.search).get('useFallbackApi');
310
+ return handleRequestWithFallback({
311
+ basePathType: useFallbackApi || MAIN_BASE_API_TYPE,
312
+ options,
313
+ path,
314
+ });
315
+ };
316
+
317
+ exports.fallbackApiList = fallbackApiList;
318
+ exports.handleFetch = handleFetch;
319
+ exports.jsonParse = jsonParse;
320
+ exports.log = log;
321
+ exports.logError = logError;
322
+ exports.sendErrorLog = sendErrorLog;
@@ -2,7 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const logError = require('./logError-4e2f2020.js');
5
+ const handleFetch = require('./handleFetch-842c95b0.js');
6
+ const CheckoutConfig = require('./CheckoutConfig-65376e00.js');
6
7
 
7
8
  /**
8
9
  * Get the load version and url based on the loadScriptSrc and version
@@ -41,6 +42,7 @@ const checkIfLoadVersionDomain = ({ loadScriptSrc }) => {
41
42
  };
42
43
 
43
44
  const fallbackList = ['jsdelivr', 'cdnjs', 'unpkg', 'vercel'];
45
+ const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
44
46
  /**
45
47
  * Get the next cdn type in the fallback list
46
48
  * @param currentCdnType The current cdn type that want to get the next fallback url
@@ -94,7 +96,7 @@ const getZonosQaUrl = () => {
94
96
  return null;
95
97
  }
96
98
  const qaUrl = extractZonosQaUrl(window.location.href);
97
- const cdnUrl = "https://v1.3.50.js.zonos.com";
99
+ const cdnUrl = "https://v1.3.52.js.zonos.com";
98
100
  // when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
99
101
  if (!qaUrl &&
100
102
  (cdnUrl.includes('test.') ||
@@ -116,7 +118,7 @@ const getZonosQaUrl = () => {
116
118
  }
117
119
  const suffixDomain = 'preview.js.zonos.com';
118
120
  const fullUrl = `https://${qaUrl}.${suffixDomain}`;
119
- logError.log(`[ZONOS-WARNING] using '${fullUrl}' for loading script`, 'warn');
121
+ handleFetch.log(`[ZONOS-WARNING] using '${fullUrl}' for loading script`, 'warn');
120
122
  // request to the url and check if the request has an error
121
123
  void fetch(fullUrl)
122
124
  .then(() => {
@@ -167,7 +169,7 @@ const injectScript = (params) => {
167
169
  script.src = `${V3_URL}${queryString}`;
168
170
  const headBody = document.head || document.body;
169
171
  if (!headBody) {
170
- logError.logError('Expected document.body not to be null. Stripe.js requires a <body> element.');
172
+ handleFetch.logError('Expected document.body not to be null. Stripe.js requires a <body> element.');
171
173
  return null;
172
174
  }
173
175
  headBody.appendChild(script);
@@ -251,6 +253,16 @@ const zonosLoadStripe = async (...args) => {
251
253
  return stripePromise.then(maybeStripe => initStripe(maybeStripe, args, startTime));
252
254
  };
253
255
 
256
+ const TEMP_CART_ID_QUERY_PARAM = 'tempCartUUID';
257
+ /**
258
+ * Simple function to get the cart id from the query param.
259
+ */
260
+ const getCartIdFromQueryParam = () => {
261
+ const urlParams = new URLSearchParams(window.location.search);
262
+ const cartId = urlParams.get(TEMP_CART_ID_QUERY_PARAM);
263
+ return cartId;
264
+ };
265
+
254
266
  var _a;
255
267
  /**
256
268
  * Get the load version and url based on the loadScriptSrc, if the domain that used to load `zonos.js` is in white listed domains, use currentLoadScriptUrl as the load url instead, if zonosQaUrl exists, it would also fall under the white listed domain
@@ -268,11 +280,10 @@ const zonosLoadUrl = (() => {
268
280
  }
269
281
  return null;
270
282
  })();
271
- const ZONOS_URL = "https://v1.3.50.js.zonos.com";
272
- const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.50";
273
- const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.50";
274
- const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.50";
275
- const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
283
+ const ZONOS_URL = "https://v1.3.52.js.zonos.com";
284
+ const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.52";
285
+ const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.52";
286
+ const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.52";
276
287
  const INTER_FONT_URL = 'https://rsms.me';
277
288
  const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
278
289
  const INTER_FONT_REGEX = /^https:\/\/rsms\.me\/inter\/inter\.css(.*)$/;
@@ -287,31 +298,59 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
287
298
  !!window.location.search.match(/\?.*(&*)zonosConversionTest/);
288
299
  Zonos._paypalMockResponse = null;
289
300
  Zonos.isBigCommerce = false;
290
- Zonos.releaseDate = "1726504733366";
301
+ Zonos.releaseDate = "1726602626855";
302
+ Zonos.isLegacyCheckout = false;
291
303
  /**
292
304
  * By default, the package will load from npm
293
305
  */
294
306
  Zonos.isNpm = true;
295
307
  Zonos.zonosQaUrl = null;
296
- Zonos.version = `v${"1.3.50"}`;
308
+ Zonos.version = `v${"1.3.52"}`;
297
309
  Zonos.modeAlerted = false;
298
- Zonos.tempCartData = null;
310
+ Zonos.cartData = null;
299
311
  Zonos.paypal = null;
300
312
  Zonos.getCurrentTimestamp = () => new Date().getTime();
301
313
  Zonos.zonosController = null;
302
314
  Zonos.init = async ({ appearance, checkoutSettings, currencyConverter, helloSettings, onCountryChange, overrideCurrencyFormat, storeId, zonosApiKey, }) => {
315
+ _a.cartId = getCartIdFromQueryParam();
303
316
  if (_a.doneInit) {
304
317
  // do nothing if zonos is already initializeds
305
318
  return;
306
319
  }
307
- logError.log(`====== ZONOS DEBUG MODE: on (${_a.version}) ======`);
308
- if (!zonosApiKey) {
309
- logError.logError('Missing Zonos API key');
310
- return;
311
- }
320
+ handleFetch.log(`====== ZONOS DEBUG MODE: on (${_a.version}) ======`);
312
321
  _a.zonosApiKey = zonosApiKey;
313
322
  _a.storeId = storeId;
314
- logError.log('init zonos');
323
+ if (_a.isNpm) {
324
+ handleFetch.log('====== ZONOS LOADING FROM NPM ======');
325
+ // zonosApiKey is required if tempCartUUID in query params are not provided
326
+ if (!zonosApiKey && !_a.cartId) {
327
+ handleFetch.logError('Zonos API key is required unless `tempCartUUID` is provided in url query params.');
328
+ return;
329
+ }
330
+ /**
331
+ * This is mainly for user that integrates Zonos with npm
332
+ * If cartUUID is provided in query param and cartData is not available, get and initialize cart data to prepare to open checkout right away
333
+ */
334
+ if (!_a.cartData && _a.cartId) {
335
+ handleFetch.log('Initialize cart data');
336
+ const params = await CheckoutConfig.setupCartData(_a.cartId);
337
+ if (!params) {
338
+ handleFetch.logError('Failed to get cart data');
339
+ return;
340
+ }
341
+ _a.cartData = params.cartData;
342
+ _a.zonosApiKey = params.zonosApiKey;
343
+ }
344
+ }
345
+ // inject hidden button to body to trigger checkout right away if we have cartData
346
+ if (_a.cartId && _a.cartData) {
347
+ handleFetch.log('Cart data is available, inject hidden button and trigger checkout');
348
+ const hiddenButton = document.createElement('button');
349
+ hiddenButton.style.display = 'none';
350
+ hiddenButton.id = `${CheckoutConfig.checkoutHiddenBtnSelector}`;
351
+ document.body.appendChild(hiddenButton);
352
+ }
353
+ handleFetch.log('init zonos');
315
354
  // inject zonos cdn
316
355
  _a.injectZonosCdn();
317
356
  // inject css for zonos elements
@@ -328,7 +367,6 @@ Zonos.init = async ({ appearance, checkoutSettings, currencyConverter, helloSett
328
367
  onCountryChange,
329
368
  overrideCurrencyFormat,
330
369
  },
331
- zonosApiKey,
332
370
  });
333
371
  _a.doneInit = true;
334
372
  };
@@ -400,7 +438,7 @@ Zonos.disablePlaceOrderButtons = ({ autoEnable = true, config, disable, placeOrd
400
438
  }
401
439
  }
402
440
  };
403
- Zonos.injectController = ({ config, zonosApiKey, }) => {
441
+ Zonos.injectController = ({ config, }) => {
404
442
  var _b;
405
443
  if (document.querySelector('zonos-controller')) {
406
444
  return;
@@ -428,13 +466,13 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
428
466
  }
429
467
  const zonosController = document.createElement('zonos-controller');
430
468
  zonosController.config = config;
431
- zonosController.zonosApiKey = zonosApiKey;
469
+ zonosController.zonosApiKey = _a.zonosApiKey || '';
432
470
  zonosController.addEventListener('stripeInitEvent', async (event) => {
433
471
  const { detail } = event;
434
- logError.log('loading Stripe');
472
+ handleFetch.log('loading Stripe');
435
473
  const stripe = await zonosLoadStripe(detail.publishableKey);
436
474
  if (!stripe) {
437
- logError.logError('API seems to be invalid or missing. Failed to load Stripe');
475
+ handleFetch.logError('API seems to be invalid or missing. Failed to load Stripe');
438
476
  return;
439
477
  }
440
478
  window.Zonos.stripe = stripe;
@@ -443,7 +481,7 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
443
481
  document.body.appendChild(zonosController);
444
482
  // set zonos controller to be global
445
483
  _a.zonosController = zonosController;
446
- logError.log('Zonos controller injected!');
484
+ handleFetch.log('Zonos controller injected!');
447
485
  };
448
486
  Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
449
487
  const scriptDomain = _a.getZonosUrl(cdnType);
@@ -453,7 +491,7 @@ Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
453
491
  return !!script;
454
492
  };
455
493
  if (findScript()) {
456
- logError.log(`Zonos script "${fullScriptUrl}" already exists in the document`, 'warn');
494
+ handleFetch.log(`Zonos script "${fullScriptUrl}" already exists in the document`, 'warn');
457
495
  return;
458
496
  }
459
497
  const headOrBody = document.head || document.body;
@@ -469,7 +507,7 @@ Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
469
507
  script.src = fullScriptUrl;
470
508
  script.crossOrigin = 'anonymous';
471
509
  script.onerror = () => {
472
- logError.logError(`Failed to load ${script.src}`);
510
+ handleFetch.logError(`Failed to load ${script.src}`);
473
511
  const nextFallbackCdnType = getNextFallbackUrl(cdnType);
474
512
  // if next fallback cdn type exists, inject the script with the next fallback cdn type
475
513
  if (!nextFallbackCdnType) {
@@ -521,7 +559,7 @@ Zonos.injectZonosCdn = () => {
521
559
  isModule: false,
522
560
  theRestUrl: 'dist/zonos-elements/zonos-elements.js',
523
561
  });
524
- logError.log('Zonos cdn script injected!');
562
+ handleFetch.log('Zonos cdn script injected!');
525
563
  };
526
564
  Zonos.injectStylesheet = ({ cdnType, theRestUrl, }) => {
527
565
  const stylesheetDomain = _a.getZonosUrl(cdnType);
@@ -536,7 +574,7 @@ Zonos.injectStylesheet = ({ cdnType, theRestUrl, }) => {
536
574
  zonosCss.rel = 'stylesheet';
537
575
  zonosCss.href = `${stylesheetDomain}/${theRestUrl}`;
538
576
  zonosCss.onerror = () => {
539
- logError.logError(`Failed to load ${zonosCss.href}`);
577
+ handleFetch.logError(`Failed to load ${zonosCss.href}`);
540
578
  const nextFallbackCdnType = getNextFallbackUrl(cdnType);
541
579
  // if the css failed to load, try to load the next fallback cdn if exists
542
580
  if (!nextFallbackCdnType) {
@@ -554,7 +592,7 @@ Zonos.injectZonosCss = () => {
554
592
  return !!document.querySelector(`link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]`);
555
593
  };
556
594
  if (findStyleLink()) {
557
- logError.log('Zonos style links already injected', 'warn');
595
+ handleFetch.log('Zonos style links already injected', 'warn');
558
596
  return;
559
597
  }
560
598
  // inject css for zonos elements
@@ -562,7 +600,7 @@ Zonos.injectZonosCss = () => {
562
600
  cdnType: MAIN_LOAD_CDN_TYPE,
563
601
  theRestUrl: 'dist/zonos-elements/zonos-elements.css',
564
602
  });
565
- logError.log('Zonos style css injected!');
603
+ handleFetch.log('Zonos style css injected!');
566
604
  };
567
605
  Zonos.injectFonts = () => {
568
606
  const findFont = () => {
@@ -580,7 +618,7 @@ Zonos.injectFonts = () => {
580
618
  return null;
581
619
  };
582
620
  if (findFont()) {
583
- logError.log('Inter font already injected', 'warn');
621
+ handleFetch.log('Inter font already injected', 'warn');
584
622
  return;
585
623
  }
586
624
  const headOrBody = document.head || document.body;
@@ -594,7 +632,7 @@ Zonos.injectFonts = () => {
594
632
  font.rel = 'stylesheet';
595
633
  font.href = `${INTER_FONT_URL}/inter/inter.css`;
596
634
  headOrBody.appendChild(font);
597
- logError.log('Zonos font injected!');
635
+ handleFetch.log('Zonos font injected!');
598
636
  };
599
637
  // apply font for zonos elements and inject font if needed
600
638
  Zonos.setupGoogleFont = (fontFamily) => {
@@ -604,7 +642,7 @@ Zonos.setupGoogleFont = (fontFamily) => {
604
642
  // this function is to inject google font to the browser, not apply the font for zonos elements, to apply the font and inject font if needed, use `setupGoogleFont` instead
605
643
  Zonos.injectSupportGoogleFont = (fontUrl) => {
606
644
  var _b;
607
- logError.log(`[FONT] injecting ${fontUrl}`);
645
+ handleFetch.log(`[FONT] injecting ${fontUrl}`);
608
646
  const fontFamily = (_b = fontUrl.match(/family=(.*?):/)) === null || _b === void 0 ? void 0 : _b[1];
609
647
  const headOrBody = document.head || document.body;
610
648
  // inject font css for zonos elements
@@ -615,14 +653,16 @@ Zonos.injectSupportGoogleFont = (fontUrl) => {
615
653
  headOrBody.appendChild(customFontPreconnect);
616
654
  }
617
655
  if (document.querySelector(`link[rel="stylesheet"][href="${fontUrl}"]`)) {
618
- logError.log(`[FONT] ${fontFamily} font already injected`, 'warn');
656
+ handleFetch.log(`[FONT] ${fontFamily} font already injected`, 'warn');
619
657
  return;
620
658
  }
621
659
  const customFont = document.createElement('link');
622
660
  customFont.rel = 'stylesheet';
623
661
  customFont.href = fontUrl;
624
662
  headOrBody.appendChild(customFont);
625
- logError.log(`[FONT] ${fontFamily} font injected!`);
663
+ handleFetch.log(`[FONT] ${fontFamily} font injected!`);
626
664
  };
627
665
 
666
+ exports.checkoutHiddenBtnSelector = CheckoutConfig.checkoutHiddenBtnSelector;
667
+ exports.domesticRedirectedBtnSelector = CheckoutConfig.domesticRedirectedBtnSelector;
628
668
  exports.Zonos = Zonos;