@zonos/elements 1.2.4-alpha.4 → 1.2.4-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{cart-3ff38a09.js → cart-7ad04cdb.js} +1 -1
- package/dist/cjs/index.cjs.js +2 -2
- package/dist/cjs/{localization-dcd11e9d.js → localization-5069ab0b.js} +20 -0
- package/dist/cjs/{submitGtag-08527ddb.js → submitGtag-44e938ff.js} +1 -1
- package/dist/cjs/zonos-address_2.cjs.entry.js +2 -2
- package/dist/cjs/zonos-cart-items_10.cjs.entry.js +3 -3
- package/dist/cjs/zonos-checkout.cjs.entry.js +3 -3
- package/dist/cjs/zonos-controller.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-flag_4.cjs.entry.js +1 -1
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +1 -1
- package/dist/cjs/zonos-hello.cjs.entry.js +1 -1
- package/dist/cjs/zonos-payment.cjs.entry.js +2 -2
- package/dist/collection/components/utils/logging/log.js +20 -0
- package/dist/collection/scripts/zonos.js +53 -0
- package/dist/components/localization.js +20 -0
- package/dist/esm/{cart-54eab7ab.js → cart-face98c8.js} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/{localization-9c80f0f5.js → localization-ed07b7f0.js} +20 -0
- package/dist/esm/{submitGtag-7affec95.js → submitGtag-5b553683.js} +1 -1
- package/dist/esm/zonos-address_2.entry.js +2 -2
- package/dist/esm/zonos-cart-items_10.entry.js +3 -3
- package/dist/esm/zonos-checkout.entry.js +3 -3
- package/dist/esm/zonos-controller.entry.js +2 -2
- package/dist/esm/zonos-country-flag_4.entry.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm/zonos-hello.entry.js +1 -1
- package/dist/esm/zonos-payment.entry.js +2 -2
- package/dist/esm-es5/{cart-54eab7ab.js → cart-face98c8.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{localization-9c80f0f5.js → localization-ed07b7f0.js} +1 -1
- package/dist/esm-es5/{submitGtag-7affec95.js → submitGtag-5b553683.js} +1 -1
- package/dist/esm-es5/zonos-address_2.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_10.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-payment.entry.js +1 -1
- package/dist/scripts/loadZonos.js +76 -3
- package/dist/scripts/zonos.js +76 -3
- package/dist/types/components/utils/changeDeepProperty.d.ts +1 -1
- package/dist/types/components/utils/changeDeepPropertyAtIndex.d.ts +1 -1
- package/dist/types/scripts/zonos.d.ts +1 -0
- package/dist/types/types/global.d.ts +12 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-0362c416.entry.js → p-03df1466.entry.js} +1 -1
- package/dist/zonos-elements/{p-07c900e2.entry.js → p-39dfc72b.entry.js} +1 -1
- package/dist/zonos-elements/{p-197e4528.entry.js → p-3c40bb08.entry.js} +1 -1
- package/dist/zonos-elements/{p-40e68452.system.entry.js → p-4138e220.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-7aab4cf0.system.js → p-47c110a4.system.js} +1 -1
- package/dist/zonos-elements/{p-46d935ea.system.js → p-4db8bd2e.system.js} +1 -1
- package/dist/zonos-elements/{p-c8fcaddc.system.entry.js → p-507e1954.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9232db22.system.js → p-5aefdcdc.system.js} +1 -1
- package/dist/zonos-elements/{p-3ab985c6.entry.js → p-5e6be2a3.entry.js} +1 -1
- package/dist/zonos-elements/{p-1d4b6d59.system.js → p-94f03799.system.js} +1 -1
- package/dist/zonos-elements/{p-e3c617a4.js → p-99c9bd01.js} +1 -1
- package/dist/zonos-elements/{p-7c3ea8c6.system.entry.js → p-9e396855.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-84447396.entry.js → p-9fa111f1.entry.js} +1 -1
- package/dist/zonos-elements/{p-c1f4349c.system.entry.js → p-aeeaaa7a.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-de3db699.system.entry.js → p-b2984730.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-887e2f9a.system.entry.js → p-b944303a.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-8858537d.entry.js → p-bca3d02f.entry.js} +1 -1
- package/dist/zonos-elements/p-bec21999.system.js +1 -1
- package/dist/zonos-elements/{p-3379ee13.js → p-c6ed3777.js} +1 -1
- package/dist/zonos-elements/{p-426a5999.system.entry.js → p-d8daeec4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-35035961.entry.js → p-d9ed23ec.entry.js} +1 -1
- package/dist/zonos-elements/{p-472c97b6.entry.js → p-f09eb5c5.entry.js} +1 -1
- package/dist/zonos-elements/{p-17bc1266.js → p-f0f9c43a.js} +1 -1
- package/dist/zonos-elements/{p-81da740f.system.entry.js → p-f2ed98bb.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
4
|
-
const localization = require('./localization-
|
|
4
|
+
const localization = require('./localization-5069ab0b.js');
|
|
5
5
|
const isDarkColor = require('./isDarkColor-261fcf3d.js');
|
|
6
6
|
const getBorderRadius = require('./getBorderRadius-a97a5f75.js');
|
|
7
7
|
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const cart = require('./cart-
|
|
5
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
6
6
|
require('./zonosStore-a0fa5b77.js');
|
|
7
7
|
require('./index-20cb112f.js');
|
|
8
|
-
require('./localization-
|
|
8
|
+
require('./localization-5069ab0b.js');
|
|
9
9
|
require('./isDarkColor-261fcf3d.js');
|
|
10
10
|
require('./getBorderRadius-a97a5f75.js');
|
|
11
11
|
|
|
@@ -3372,10 +3372,30 @@ const isValidSelector = (selector) => {
|
|
|
3372
3372
|
};
|
|
3373
3373
|
|
|
3374
3374
|
const log = (message, type, ...additionalInfo) => {
|
|
3375
|
+
var _a;
|
|
3375
3376
|
// if type is error and debug is false, do not log
|
|
3376
3377
|
if (!window.Zonos.debug) {
|
|
3377
3378
|
return;
|
|
3378
3379
|
}
|
|
3380
|
+
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
3381
|
+
if (!loggingIframe) {
|
|
3382
|
+
// add a hidden iframe
|
|
3383
|
+
loggingIframe = document.createElement('iframe');
|
|
3384
|
+
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
3385
|
+
loggingIframe.style.display = 'none';
|
|
3386
|
+
loggingIframe.style.opacity = '0';
|
|
3387
|
+
loggingIframe.style.position = 'absolute';
|
|
3388
|
+
loggingIframe.style.top = '-9999px';
|
|
3389
|
+
loggingIframe.style.left = '-9999px';
|
|
3390
|
+
loggingIframe.style.width = '1px';
|
|
3391
|
+
loggingIframe.style.height = '1px';
|
|
3392
|
+
loggingIframe.style.border = 'none';
|
|
3393
|
+
loggingIframe.style.overflow = 'hidden';
|
|
3394
|
+
loggingIframe.style.visibility = 'hidden';
|
|
3395
|
+
document.body.appendChild(loggingIframe);
|
|
3396
|
+
}
|
|
3397
|
+
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
3398
|
+
const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
|
|
3379
3399
|
switch (type) {
|
|
3380
3400
|
case 'warn':
|
|
3381
3401
|
// eslint-disable-next-line no-console
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
4
|
-
const localization = require('./localization-
|
|
4
|
+
const localization = require('./localization-5069ab0b.js');
|
|
5
5
|
|
|
6
6
|
const checkoutBreakpoint = 890;
|
|
7
7
|
const isCheckoutMobile = (isMobile) => {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const cart = require('./cart-
|
|
7
|
-
const localization = require('./localization-
|
|
6
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
7
|
+
const localization = require('./localization-5069ab0b.js');
|
|
8
8
|
require('./zonosStore-a0fa5b77.js');
|
|
9
9
|
require('./isDarkColor-261fcf3d.js');
|
|
10
10
|
require('./getBorderRadius-a97a5f75.js');
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const cart = require('./cart-
|
|
7
|
-
const localization = require('./localization-
|
|
6
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
7
|
+
const localization = require('./localization-5069ab0b.js');
|
|
8
8
|
const getBorderRadius = require('./getBorderRadius-a97a5f75.js');
|
|
9
|
-
const submitGtag = require('./submitGtag-
|
|
9
|
+
const submitGtag = require('./submitGtag-44e938ff.js');
|
|
10
10
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
11
11
|
const classes = require('./classes-b7918f56.js');
|
|
12
12
|
require('./isDarkColor-261fcf3d.js');
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const cart = require('./cart-
|
|
7
|
-
const localization = require('./localization-
|
|
6
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
7
|
+
const localization = require('./localization-5069ab0b.js');
|
|
8
8
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
9
|
-
const submitGtag = require('./submitGtag-
|
|
9
|
+
const submitGtag = require('./submitGtag-44e938ff.js');
|
|
10
10
|
const classes = require('./classes-b7918f56.js');
|
|
11
11
|
const getBorderRadius = require('./getBorderRadius-a97a5f75.js');
|
|
12
12
|
const isDarkColor = require('./isDarkColor-261fcf3d.js');
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const cart = require('./cart-
|
|
7
|
-
const localization = require('./localization-
|
|
6
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
7
|
+
const localization = require('./localization-5069ab0b.js');
|
|
8
8
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
9
9
|
require('./isDarkColor-261fcf3d.js');
|
|
10
10
|
require('./getBorderRadius-a97a5f75.js');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const localization = require('./localization-
|
|
6
|
+
const localization = require('./localization-5069ab0b.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
const isDarkColor = require('./isDarkColor-261fcf3d.js');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const localization = require('./localization-
|
|
6
|
+
const localization = require('./localization-5069ab0b.js');
|
|
7
7
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
const getHasMoreSpaceOnRight = require('./getHasMoreSpaceOnRight-4c94667f.js');
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
6
|
const zonosStore = require('./zonosStore-a0fa5b77.js');
|
|
7
|
-
const localization = require('./localization-
|
|
7
|
+
const localization = require('./localization-5069ab0b.js');
|
|
8
8
|
const classes = require('./classes-b7918f56.js');
|
|
9
9
|
const getHasMoreSpaceOnRight = require('./getHasMoreSpaceOnRight-4c94667f.js');
|
|
10
10
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-20cb112f.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-7ad04cdb.js');
|
|
7
7
|
require('./zonosStore-a0fa5b77.js');
|
|
8
|
-
require('./localization-
|
|
8
|
+
require('./localization-5069ab0b.js');
|
|
9
9
|
require('./isDarkColor-261fcf3d.js');
|
|
10
10
|
require('./getBorderRadius-a97a5f75.js');
|
|
11
11
|
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
export const log = (message, type, ...additionalInfo) => {
|
|
2
|
+
var _a;
|
|
2
3
|
// if type is error and debug is false, do not log
|
|
3
4
|
if (!window.Zonos.debug) {
|
|
4
5
|
return;
|
|
5
6
|
}
|
|
7
|
+
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
8
|
+
if (!loggingIframe) {
|
|
9
|
+
// add a hidden iframe
|
|
10
|
+
loggingIframe = document.createElement('iframe');
|
|
11
|
+
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
12
|
+
loggingIframe.style.display = 'none';
|
|
13
|
+
loggingIframe.style.opacity = '0';
|
|
14
|
+
loggingIframe.style.position = 'absolute';
|
|
15
|
+
loggingIframe.style.top = '-9999px';
|
|
16
|
+
loggingIframe.style.left = '-9999px';
|
|
17
|
+
loggingIframe.style.width = '1px';
|
|
18
|
+
loggingIframe.style.height = '1px';
|
|
19
|
+
loggingIframe.style.border = 'none';
|
|
20
|
+
loggingIframe.style.overflow = 'hidden';
|
|
21
|
+
loggingIframe.style.visibility = 'hidden';
|
|
22
|
+
document.body.appendChild(loggingIframe);
|
|
23
|
+
}
|
|
24
|
+
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
25
|
+
const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
|
|
6
26
|
switch (type) {
|
|
7
27
|
case 'warn':
|
|
8
28
|
// eslint-disable-next-line no-console
|
|
@@ -63,6 +63,8 @@ Zonos.init = async ({ appearance, checkoutSettings, currencyConverter, helloSett
|
|
|
63
63
|
}
|
|
64
64
|
_a.zonosApiKey = zonosApiKey;
|
|
65
65
|
log('init zonos');
|
|
66
|
+
// add sentry to the project
|
|
67
|
+
_a.injectSentryScript();
|
|
66
68
|
// inject zonos cdn
|
|
67
69
|
_a.injectZonosCdn();
|
|
68
70
|
// inject css for zonos elements
|
|
@@ -160,6 +162,56 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
|
|
|
160
162
|
_a.zonosController = zonosController;
|
|
161
163
|
log('Zonos controller injected!');
|
|
162
164
|
};
|
|
165
|
+
Zonos.injectSentryScript = () => {
|
|
166
|
+
const scriptUrl = 'https://browser.sentry-cdn.com/7.88.0/bundle.tracing.min.js';
|
|
167
|
+
const findScript = () => {
|
|
168
|
+
const script = document.querySelector(`script[src="${scriptUrl}"]`);
|
|
169
|
+
return !!script;
|
|
170
|
+
};
|
|
171
|
+
if (findScript()) {
|
|
172
|
+
// eslint-disable-next-line no-console
|
|
173
|
+
log('Sentry script already exists in the document', 'warn');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const headOrBody = document.head || document.body;
|
|
177
|
+
// init zonos elements when the zonosKey is valid
|
|
178
|
+
// inject esmodule cdn for zonos elements
|
|
179
|
+
const script = document.createElement('script');
|
|
180
|
+
script.crossOrigin = 'anonymous';
|
|
181
|
+
script.src = scriptUrl;
|
|
182
|
+
script.integrity =
|
|
183
|
+
'sha384-z/aQww1Fr6Mes0MO/2wlzQd2nXBCdDcKPXDTsMDMNPgTGRPqii3a4bzH79I+Vo8l';
|
|
184
|
+
script.setAttribute('data-lazy', 'no');
|
|
185
|
+
script.onerror = () => {
|
|
186
|
+
logError(`Failed to load ${script.src}`);
|
|
187
|
+
};
|
|
188
|
+
script.onload = () => {
|
|
189
|
+
var _b;
|
|
190
|
+
(_b = window.Sentry) === null || _b === void 0 ? void 0 : _b.init({
|
|
191
|
+
denyUrls: [
|
|
192
|
+
// Facebook flakiness
|
|
193
|
+
/graph\.facebook\.com/i,
|
|
194
|
+
// Facebook blocked
|
|
195
|
+
/connect\.facebook\.net\/en_US\/all\.js/i,
|
|
196
|
+
// Woopra flakiness
|
|
197
|
+
/eatdifferent\.com\.woopra-ns\.com/i,
|
|
198
|
+
/static\.woopra\.com\/js\/woopra\.js/i,
|
|
199
|
+
// Chrome extensions
|
|
200
|
+
/extensions\//i,
|
|
201
|
+
/^chrome:\/\//i,
|
|
202
|
+
/^chrome-extension:\/\//i,
|
|
203
|
+
// Other plugins
|
|
204
|
+
/webappstoolbarba\.texthelp\.com\//i,
|
|
205
|
+
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
|
|
206
|
+
/dev.elements.zonos.com/i,
|
|
207
|
+
/js.zonos.com/,
|
|
208
|
+
],
|
|
209
|
+
dsn: 'https://19168bd05af0e2e0e7520ad58953e4f2@o446983.ingest.sentry.io/4506400622837760',
|
|
210
|
+
release: `zonos-elements@${_a.version}`,
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
headOrBody.appendChild(script);
|
|
214
|
+
};
|
|
163
215
|
Zonos.injectScript = ({ fallBackDomain, isModule, scriptDomain, theRestUrl, }) => {
|
|
164
216
|
const fullScriptUrl = `${scriptDomain}/${theRestUrl}`;
|
|
165
217
|
const findScript = () => {
|
|
@@ -182,6 +234,7 @@ Zonos.injectScript = ({ fallBackDomain, isModule, scriptDomain, theRestUrl, }) =
|
|
|
182
234
|
script.noModule = true;
|
|
183
235
|
}
|
|
184
236
|
script.src = fullScriptUrl;
|
|
237
|
+
script.crossOrigin = 'anonymous';
|
|
185
238
|
script.onerror = () => {
|
|
186
239
|
// only fallback if the stylesheetDomain is versioned. (https://v1.2.3.something.com || https://v1.something.com)
|
|
187
240
|
const isVersioned = /\/\/v\d+\./g.test(scriptDomain);
|
|
@@ -3370,10 +3370,30 @@ const isValidSelector = (selector) => {
|
|
|
3370
3370
|
};
|
|
3371
3371
|
|
|
3372
3372
|
const log = (message, type, ...additionalInfo) => {
|
|
3373
|
+
var _a;
|
|
3373
3374
|
// if type is error and debug is false, do not log
|
|
3374
3375
|
if (!window.Zonos.debug) {
|
|
3375
3376
|
return;
|
|
3376
3377
|
}
|
|
3378
|
+
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
3379
|
+
if (!loggingIframe) {
|
|
3380
|
+
// add a hidden iframe
|
|
3381
|
+
loggingIframe = document.createElement('iframe');
|
|
3382
|
+
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
3383
|
+
loggingIframe.style.display = 'none';
|
|
3384
|
+
loggingIframe.style.opacity = '0';
|
|
3385
|
+
loggingIframe.style.position = 'absolute';
|
|
3386
|
+
loggingIframe.style.top = '-9999px';
|
|
3387
|
+
loggingIframe.style.left = '-9999px';
|
|
3388
|
+
loggingIframe.style.width = '1px';
|
|
3389
|
+
loggingIframe.style.height = '1px';
|
|
3390
|
+
loggingIframe.style.border = 'none';
|
|
3391
|
+
loggingIframe.style.overflow = 'hidden';
|
|
3392
|
+
loggingIframe.style.visibility = 'hidden';
|
|
3393
|
+
document.body.appendChild(loggingIframe);
|
|
3394
|
+
}
|
|
3395
|
+
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
3396
|
+
const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
|
|
3377
3397
|
switch (type) {
|
|
3378
3398
|
case 'warn':
|
|
3379
3399
|
// eslint-disable-next-line no-console
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as createStore, z as zonosStore } from './zonosStore-e0b7a5cf.js';
|
|
2
|
-
import { h as handleFetch, l as log, a as localizationStore, b as logError, t as translate } from './localization-
|
|
2
|
+
import { h as handleFetch, l as log, a as localizationStore, b as logError, t as translate } from './localization-ed07b7f0.js';
|
|
3
3
|
import { i as isDarkColor } from './isDarkColor-44e9e451.js';
|
|
4
4
|
import { g as getBorderRadius } from './getBorderRadius-35e8acce.js';
|
|
5
5
|
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
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-face98c8.js';
|
|
2
2
|
import './zonosStore-e0b7a5cf.js';
|
|
3
3
|
import './index-3617e24c.js';
|
|
4
|
-
import './localization-
|
|
4
|
+
import './localization-ed07b7f0.js';
|
|
5
5
|
import './isDarkColor-44e9e451.js';
|
|
6
6
|
import './getBorderRadius-35e8acce.js';
|
|
@@ -3370,10 +3370,30 @@ const isValidSelector = (selector) => {
|
|
|
3370
3370
|
};
|
|
3371
3371
|
|
|
3372
3372
|
const log = (message, type, ...additionalInfo) => {
|
|
3373
|
+
var _a;
|
|
3373
3374
|
// if type is error and debug is false, do not log
|
|
3374
3375
|
if (!window.Zonos.debug) {
|
|
3375
3376
|
return;
|
|
3376
3377
|
}
|
|
3378
|
+
let loggingIframe = document.querySelector('iframe#zonos---debug-logging-iframe');
|
|
3379
|
+
if (!loggingIframe) {
|
|
3380
|
+
// add a hidden iframe
|
|
3381
|
+
loggingIframe = document.createElement('iframe');
|
|
3382
|
+
loggingIframe.id = 'zonos---debug-logging-iframe';
|
|
3383
|
+
loggingIframe.style.display = 'none';
|
|
3384
|
+
loggingIframe.style.opacity = '0';
|
|
3385
|
+
loggingIframe.style.position = 'absolute';
|
|
3386
|
+
loggingIframe.style.top = '-9999px';
|
|
3387
|
+
loggingIframe.style.left = '-9999px';
|
|
3388
|
+
loggingIframe.style.width = '1px';
|
|
3389
|
+
loggingIframe.style.height = '1px';
|
|
3390
|
+
loggingIframe.style.border = 'none';
|
|
3391
|
+
loggingIframe.style.overflow = 'hidden';
|
|
3392
|
+
loggingIframe.style.visibility = 'hidden';
|
|
3393
|
+
document.body.appendChild(loggingIframe);
|
|
3394
|
+
}
|
|
3395
|
+
// use the logging iframe's console to log just in case the console is disabled (overriden) by the site owner
|
|
3396
|
+
const console = ((_a = loggingIframe.contentWindow) === null || _a === void 0 ? void 0 : _a.window.console) || window.console;
|
|
3377
3397
|
switch (type) {
|
|
3378
3398
|
case 'warn':
|
|
3379
3399
|
// eslint-disable-next-line no-console
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, h, H as Host, d as getElement } from './index-3617e24c.js';
|
|
2
|
-
import { s as stripeStore, m as stripeStorePrefetchLandedCost } from './cart-
|
|
3
|
-
import { b as logError, a as localizationStore } from './localization-
|
|
2
|
+
import { s as stripeStore, m as stripeStorePrefetchLandedCost } from './cart-face98c8.js';
|
|
3
|
+
import { b as logError, a as localizationStore } from './localization-ed07b7f0.js';
|
|
4
4
|
import './zonosStore-e0b7a5cf.js';
|
|
5
5
|
import './isDarkColor-44e9e451.js';
|
|
6
6
|
import './getBorderRadius-35e8acce.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as registerInstance, a as getAssetPath, h, H as Host, F as Fragment, c as createEvent, d as getElement } from './index-3617e24c.js';
|
|
2
|
-
import { c as cartStore, s as stripeStore, p as stripeStoreRetrievePayment, o as stripeStoreReset, i as cartStoreUpdateSelectedShippingOption, b as cartStoreGetShippingTransitInfo } from './cart-
|
|
3
|
-
import { t as translate } from './localization-
|
|
2
|
+
import { c as cartStore, s as stripeStore, p as stripeStoreRetrievePayment, o as stripeStoreReset, i as cartStoreUpdateSelectedShippingOption, b as cartStoreGetShippingTransitInfo } from './cart-face98c8.js';
|
|
3
|
+
import { t as translate } from './localization-ed07b7f0.js';
|
|
4
4
|
import { g as getBorderRadius } from './getBorderRadius-35e8acce.js';
|
|
5
|
-
import { s as submitGtag, i as isCheckoutMobile } from './submitGtag-
|
|
5
|
+
import { s as submitGtag, i as isCheckoutMobile } from './submitGtag-5b553683.js';
|
|
6
6
|
import { e as zonosStoreFontFamily, z as zonosStore } from './zonosStore-e0b7a5cf.js';
|
|
7
7
|
import { c as classes } from './classes-0d95c529.js';
|
|
8
8
|
import './isDarkColor-44e9e451.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as registerInstance, h, F as Fragment, H as Host } from './index-3617e24c.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-
|
|
3
|
-
import { a as localizationStore, l as log, t as translate } from './localization-
|
|
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-face98c8.js';
|
|
3
|
+
import { a as localizationStore, l as log, t as translate } from './localization-ed07b7f0.js';
|
|
4
4
|
import { z as zonosStore, m as mergeConfig } from './zonosStore-e0b7a5cf.js';
|
|
5
|
-
import { s as submitGtag, i as isCheckoutMobile } from './submitGtag-
|
|
5
|
+
import { s as submitGtag, i as isCheckoutMobile } from './submitGtag-5b553683.js';
|
|
6
6
|
import { c as classes } from './classes-0d95c529.js';
|
|
7
7
|
import { g as getBorderRadius } from './getBorderRadius-35e8acce.js';
|
|
8
8
|
import { i as isDarkColor } from './isDarkColor-44e9e451.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, c as createEvent, h, H as Host } from './index-3617e24c.js';
|
|
2
|
-
import { s as stripeStore } from './cart-
|
|
3
|
-
import { h as handleFetch, b as logError, i as isValidSelector, l as log, c as initLocalizationStore, d as localizationStoreUpdateSelectedCountryCode } from './localization-
|
|
2
|
+
import { s as stripeStore } from './cart-face98c8.js';
|
|
3
|
+
import { h as handleFetch, b as logError, i as isValidSelector, l as log, c as initLocalizationStore, d as localizationStoreUpdateSelectedCountryCode } from './localization-ed07b7f0.js';
|
|
4
4
|
import { z as zonosStore, d as zonosStoreInitSetting, e as zonosStoreFontFamily } from './zonosStore-e0b7a5cf.js';
|
|
5
5
|
import './isDarkColor-44e9e451.js';
|
|
6
6
|
import './getBorderRadius-35e8acce.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as registerInstance, h, H as Host, d as getElement } from './index-3617e24c.js';
|
|
2
|
-
import { a as localizationStore, d as localizationStoreUpdateSelectedCountryCode, t as translate } from './localization-
|
|
2
|
+
import { a as localizationStore, d as localizationStoreUpdateSelectedCountryCode, t as translate } from './localization-ed07b7f0.js';
|
|
3
3
|
import { e as zonosStoreFontFamily } from './zonosStore-e0b7a5cf.js';
|
|
4
4
|
import { c as classes } from './classes-0d95c529.js';
|
|
5
5
|
import { i as isDarkColor } from './isDarkColor-44e9e451.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as registerInstance, c as createEvent, h, H as Host } from './index-3617e24c.js';
|
|
2
|
-
import { k as currencyFormat, a as localizationStore, t as translate } from './localization-
|
|
2
|
+
import { k as currencyFormat, a as localizationStore, t as translate } from './localization-ed07b7f0.js';
|
|
3
3
|
import { z as zonosStore } from './zonosStore-e0b7a5cf.js';
|
|
4
4
|
import { c as classes } from './classes-0d95c529.js';
|
|
5
5
|
import { g as getHasMoreSpaceOnRight } from './getHasMoreSpaceOnRight-70eb913a.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, h, H as Host } from './index-3617e24c.js';
|
|
2
2
|
import { _ as _root, i as isObjectLike_1, f as _baseGetTag, g as isObject_1, z as zonosStore, m as mergeConfig } from './zonosStore-e0b7a5cf.js';
|
|
3
|
-
import { h as handleFetch, b as logError, a as localizationStore, i as isValidSelector, t as translate, g as getZCountryUrlParam, s as setZCountryUrlParam, l as log, e as currencyDisplay, f as currencyConvertAndFormat, j as currencyConvert, k as currencyFormat } from './localization-
|
|
3
|
+
import { h as handleFetch, b as logError, a as localizationStore, i as isValidSelector, t as translate, g as getZCountryUrlParam, s as setZCountryUrlParam, l as log, e as currencyDisplay, f as currencyConvertAndFormat, j as currencyConvert, k as currencyFormat } from './localization-ed07b7f0.js';
|
|
4
4
|
import { c as classes } from './classes-0d95c529.js';
|
|
5
5
|
import { g as getHasMoreSpaceOnRight } from './getHasMoreSpaceOnRight-70eb913a.js';
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as registerInstance, h, H as Host, d as getElement } from './index-3617e24c.js';
|
|
2
|
-
import { s as stripeStore } from './cart-
|
|
2
|
+
import { s as stripeStore } from './cart-face98c8.js';
|
|
3
3
|
import './zonosStore-e0b7a5cf.js';
|
|
4
|
-
import './localization-
|
|
4
|
+
import './localization-ed07b7f0.js';
|
|
5
5
|
import './isDarkColor-44e9e451.js';
|
|
6
6
|
import './getBorderRadius-35e8acce.js';
|
|
7
7
|
|
|
@@ -1 +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{c as createStore,z as zonosStore}from"./zonosStore-e0b7a5cf.js";import{h as handleFetch,l as log,a as localizationStore,b as logError,t as translate}from"./localization-9c80f0f5.js";import{i as isDarkColor}from"./isDarkColor-44e9e451.js";import{g as getBorderRadius}from"./getBorderRadius-35e8acce.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 calculateLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n;return __generator(this,(function(i){switch(i.label){case 0:t="".concat("https://v1.route.js.zonos.com","/api/calculate-landed-cost");return[4,handleFetch(t,{body:prepCalculateLandedCost(),method:"POST",signal:e===null||e===void 0?void 0:e.signal})];case 1:r=i.sent(),o=r.errors,n=r.json;if(o.length||!n){throw new Error("Failed to calculate landed cost")}return[2,n]}}))}))};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,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,S,p;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);S=!!d?d.subtotals:null;if(S){cartStoreApplySubtotals({exchangeRate:S.exchangeRate,items:S.items,landedCostTotal:0,presentmentCurrencyCode:S.presentmentCurrencyCode,shipping:0,total:S.items})}return[3,4];case 3:p=f.sent();logError(p);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/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/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 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,S,p;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";S=!!((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=S;cartStore.isSelectedShippingGuarantee=d;return[4,cartStoreReCalculateTotal({landedCostId:(i=l.landedCost)===null||i===void 0?void 0:i.id})];case 1:p=f.sent();return[2,p]}}))}))};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
|
+
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{c as createStore,z as zonosStore}from"./zonosStore-e0b7a5cf.js";import{h as handleFetch,l as log,a as localizationStore,b as logError,t as translate}from"./localization-ed07b7f0.js";import{i as isDarkColor}from"./isDarkColor-44e9e451.js";import{g as getBorderRadius}from"./getBorderRadius-35e8acce.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 calculateLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,o,n;return __generator(this,(function(i){switch(i.label){case 0:t="".concat("https://v1.route.js.zonos.com","/api/calculate-landed-cost");return[4,handleFetch(t,{body:prepCalculateLandedCost(),method:"POST",signal:e===null||e===void 0?void 0:e.signal})];case 1:r=i.sent(),o=r.errors,n=r.json;if(o.length||!n){throw new Error("Failed to calculate landed cost")}return[2,n]}}))}))};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,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,S,p;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);S=!!d?d.subtotals:null;if(S){cartStoreApplySubtotals({exchangeRate:S.exchangeRate,items:S.items,landedCostTotal:0,presentmentCurrencyCode:S.presentmentCurrencyCode,shipping:0,total:S.items})}return[3,4];case 3:p=f.sent();logError(p);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/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/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 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,S,p;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";S=!!((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=S;cartStore.isSelectedShippingGuarantee=d;return[4,cartStoreReCalculateTotal({landedCostId:(i=l.landedCost)===null||i===void 0?void 0:i.id})];case 1:p=f.sent();return[2,p]}}))}))};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};
|
package/dist/esm-es5/index.js
CHANGED
|
@@ -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-
|
|
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-face98c8.js";import"./zonosStore-e0b7a5cf.js";import"./index-3617e24c.js";import"./localization-ed07b7f0.js";import"./isDarkColor-44e9e451.js";import"./getBorderRadius-35e8acce.js";
|