@zonos/elements 1.3.45 → 1.3.47
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-89b4f62d.js → cart-85870c2e.js} +187 -62
- package/dist/cjs/{sendErrorLog-a966a8c1.js → createCustomEvent-aacc2833.js} +2 -22
- package/dist/cjs/index.cjs.js +13 -8
- package/dist/cjs/{paypal-1a1882c4.js → paypal-e4428dbf.js} +3 -3
- package/dist/cjs/zonos-address_8.cjs.entry.js +1 -1
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +25 -19
- package/dist/cjs/zonos-checkout.cjs.entry.js +10 -10
- package/dist/cjs/zonos-controller.cjs.entry.js +6 -6
- package/dist/cjs/zonos-country-flag.cjs.entry.js +1 -1
- package/dist/cjs/zonos-country-select_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 +2 -3
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +1 -1
- package/dist/cjs/zonos-notification_3.cjs.entry.js +2 -2
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +14 -8
- package/dist/collection/components/main/zonos-controller.js +4 -3
- package/dist/collection/components/store/checkout/stripe.js +4 -7
- package/dist/collection/components/store/hello/localization.js +1 -1
- package/dist/collection/components/utils/api/calculateLandedCost.js +1 -2
- package/dist/collection/components/utils/api/checkItemRestrictions.js +1 -2
- package/dist/collection/components/utils/api/getCountries.js +1 -1
- package/dist/collection/components/utils/api/getCountryLandedCost.js +1 -1
- package/dist/collection/components/utils/api/getExchangeRate.js +6 -2
- package/dist/collection/components/utils/api/getInclusivePricing.js +1 -2
- package/dist/collection/components/utils/api/getLocaleMessages.js +7 -2
- package/dist/collection/components/utils/api/getLocalization.js +3 -6
- package/dist/collection/components/utils/api/getShippingZones.js +1 -2
- package/dist/collection/components/utils/api/getZonosSettings.js +1 -2
- package/dist/collection/components/utils/api/paypalCaptureOrder.js +1 -1
- package/dist/collection/components/utils/api/paypalCreateOrder.js +1 -1
- package/dist/collection/components/utils/api/trackConversionEvent.js +1 -2
- package/dist/collection/components/utils/api/triggerBuildLandedCost.js +3 -2
- package/dist/collection/components/utils/getNextFallbackApi.js +18 -0
- package/dist/collection/components/utils/handleFetch.js +84 -20
- package/dist/collection/components/utils/logging/sendErrorLog.js +33 -6
- package/dist/collection/components/utils/logging/sendLoadScriptLog.js +1 -1
- package/dist/collection/environment.js +15 -78
- package/dist/collection/scripts/_getZonosQaUrl.js +6 -2
- package/dist/collection/scripts/_zonosBase.js +1 -0
- package/dist/collection/utils/formattedCloudflareApiUrl.js +43 -0
- package/dist/collection/utils/formattedUrl.js +80 -0
- package/dist/collection/utils/generateCloudflareDeployUrl.js +21 -0
- package/dist/esm/{cart-9f40efd7.js → cart-3aae6236.js} +188 -64
- package/dist/esm/{sendErrorLog-aea606c0.js → createCustomEvent-ccb20b48.js} +3 -22
- package/dist/esm/index.js +13 -8
- package/dist/esm/{paypal-f4bb6ce7.js → paypal-b1589e7b.js} +3 -3
- package/dist/esm/zonos-address_8.entry.js +1 -1
- package/dist/esm/zonos-cart-items_12.entry.js +17 -11
- package/dist/esm/zonos-checkout.entry.js +3 -3
- package/dist/esm/zonos-controller.entry.js +6 -6
- package/dist/esm/zonos-country-flag.entry.js +1 -1
- package/dist/esm/zonos-country-select_4.entry.js +1 -1
- package/dist/esm/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm/zonos-hello.entry.js +2 -3
- package/dist/esm/zonos-language-select_2.entry.js +1 -1
- package/dist/esm/zonos-notification_3.entry.js +2 -2
- package/dist/esm-es5/{cart-9f40efd7.js → cart-3aae6236.js} +1 -1
- package/dist/esm-es5/createCustomEvent-ccb20b48.js +1 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/paypal-b1589e7b.js +17 -0
- package/dist/esm-es5/zonos-address_8.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.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.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_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-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-notification_3.entry.js +1 -1
- package/dist/scripts/index.d.ts +11 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/components/utils/getNextFallbackApi.d.ts +10 -0
- package/dist/types/components/utils/handleFetch.d.ts +10 -1
- package/dist/types/components/utils/logging/sendErrorLog.d.ts +7 -1
- package/dist/types/environment.d.ts +8 -9
- package/dist/types/scripts/_getNextFallbackUrl.d.ts +1 -1
- package/dist/types/scripts/_zonosBase.d.ts +5 -0
- package/dist/types/utils/formattedCloudflareApiUrl.d.ts +20 -0
- package/dist/types/utils/formattedUrl.d.ts +9 -0
- package/dist/types/utils/generateCloudflareDeployUrl.d.ts +10 -0
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-7b8099ed.js → p-08a43211.js} +1 -1
- package/dist/zonos-elements/p-1738fe3f.entry.js +1 -0
- package/dist/zonos-elements/p-284520ae.js +17 -0
- package/dist/zonos-elements/{p-578f42c1.entry.js → p-3225705b.entry.js} +1 -1
- package/dist/zonos-elements/{p-8630168f.system.entry.js → p-3403a81a.system.entry.js} +1 -1
- package/dist/zonos-elements/p-3fb9e320.system.js +17 -0
- package/dist/zonos-elements/{p-acf9a97e.system.entry.js → p-3fd66f5b.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-8bf1af28.entry.js → p-57c67bbf.entry.js} +1 -1
- package/dist/zonos-elements/{p-4204ccf9.system.entry.js → p-6d613cee.system.entry.js} +1 -1
- package/dist/zonos-elements/p-7d0663ab.system.entry.js +1 -0
- package/dist/zonos-elements/{p-7bd28076.system.entry.js → p-8949d4a2.system.entry.js} +1 -1
- package/dist/zonos-elements/p-8b02985f.entry.js +1 -0
- package/dist/zonos-elements/p-90935326.system.entry.js +1 -0
- package/dist/zonos-elements/{p-c7952400.entry.js → p-9c9e8288.entry.js} +1 -1
- package/dist/zonos-elements/{p-43d3cafd.system.js → p-a576cbb8.system.js} +1 -1
- package/dist/zonos-elements/p-aa0127b3.system.js +1 -0
- package/dist/zonos-elements/{p-d014791e.entry.js → p-b9815df4.entry.js} +1 -1
- package/dist/zonos-elements/{p-ca0a5c22.system.entry.js → p-c035c64f.system.entry.js} +1 -1
- package/dist/zonos-elements/p-c3ca9e48.system.entry.js +1 -0
- package/dist/zonos-elements/p-c78dd680.system.js +1 -1
- package/dist/zonos-elements/{p-5845029a.system.entry.js → p-d5741e4e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-8618e185.entry.js → p-d5b21512.entry.js} +1 -1
- package/dist/zonos-elements/{p-37c9fdd2.system.entry.js → p-e4033aa7.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-567b457b.entry.js → p-ea58a4a6.entry.js} +1 -1
- package/dist/zonos-elements/{p-f9754e48.entry.js → p-ed496e98.entry.js} +1 -1
- package/dist/zonos-elements/p-eefeab02.js +1 -0
- package/dist/zonos-elements/p-f25559fd.entry.js +1 -0
- package/dist/zonos-elements/p-f9b50965.system.js +1 -0
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/paypal-f4bb6ce7.js +0 -17
- package/dist/esm-es5/sendErrorLog-aea606c0.js +0 -1
- package/dist/zonos-elements/p-0bfe455c.system.entry.js +0 -1
- package/dist/zonos-elements/p-13618b27.system.entry.js +0 -1
- package/dist/zonos-elements/p-29f4cce5.system.js +0 -17
- package/dist/zonos-elements/p-2d01b8e6.system.entry.js +0 -1
- package/dist/zonos-elements/p-3490d40f.js +0 -17
- package/dist/zonos-elements/p-5b9f2535.system.js +0 -1
- package/dist/zonos-elements/p-6f759c76.system.js +0 -1
- package/dist/zonos-elements/p-757166b8.entry.js +0 -1
- package/dist/zonos-elements/p-76291114.entry.js +0 -1
- package/dist/zonos-elements/p-9aef3a35.entry.js +0 -1
- package/dist/zonos-elements/p-d99e58f2.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as createStore, z as zonosStore } from './zonosStore-8fc9ceb2.js';
|
|
2
|
-
import {
|
|
2
|
+
import { l as log, a as logError } from './logError-c456c092.js';
|
|
3
3
|
import { i as isDarkColor } from './isDarkColor-3119e351.js';
|
|
4
4
|
import { g as getBorderRadius } from './getBorderRadius-3ba98361.js';
|
|
5
5
|
|
|
@@ -7171,6 +7171,84 @@ const translate = (...[key, replacement]) => {
|
|
|
7171
7171
|
return ((_b = translationStore.translatedChunks[key]) === null || _b === void 0 ? void 0 : _b.value) || key;
|
|
7172
7172
|
};
|
|
7173
7173
|
|
|
7174
|
+
const fallbackApiType = ['vercel', 'cloudflare'];
|
|
7175
|
+
const MAIN_BASE_API_TYPE = fallbackApiType[0];
|
|
7176
|
+
const fallbackApiList = {
|
|
7177
|
+
cloudflare: "https://route.elements.zonos.com",
|
|
7178
|
+
vercel: "https://v1.route.js.zonos.com",
|
|
7179
|
+
};
|
|
7180
|
+
const MAIN_BASE_API = fallbackApiList[MAIN_BASE_API_TYPE];
|
|
7181
|
+
/**
|
|
7182
|
+
* Next available fallback api type
|
|
7183
|
+
*/
|
|
7184
|
+
const getNextFallbackApiType = (currentApiType = MAIN_BASE_API_TYPE) => {
|
|
7185
|
+
const currentIndex = fallbackApiType.indexOf(currentApiType);
|
|
7186
|
+
const nextFallbackApiType = fallbackApiType[currentIndex + 1];
|
|
7187
|
+
if (!nextFallbackApiType) {
|
|
7188
|
+
return null;
|
|
7189
|
+
}
|
|
7190
|
+
return nextFallbackApiType;
|
|
7191
|
+
};
|
|
7192
|
+
|
|
7193
|
+
const jsonParse = (_data) => {
|
|
7194
|
+
if (typeof _data === 'string') {
|
|
7195
|
+
try {
|
|
7196
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7197
|
+
const json = JSON.parse(_data);
|
|
7198
|
+
return json;
|
|
7199
|
+
}
|
|
7200
|
+
catch (_error) {
|
|
7201
|
+
return null;
|
|
7202
|
+
}
|
|
7203
|
+
}
|
|
7204
|
+
return null;
|
|
7205
|
+
};
|
|
7206
|
+
|
|
7207
|
+
/**
|
|
7208
|
+
* This is the time in milliseconds after release time that we will start sending error logs to the new API
|
|
7209
|
+
* @default 1 hour
|
|
7210
|
+
*/
|
|
7211
|
+
const postReleaseReportingDuration = 1 * 3600 * 1000; // 1 hour
|
|
7212
|
+
const sendErrorLog = async ({ endpoint, errors, metadata, shouldPostReleaseErrorReporting, }) => {
|
|
7213
|
+
if (shouldPostReleaseErrorReporting) {
|
|
7214
|
+
// We only want to report errors that happened if current time is less than 2 hours after release time
|
|
7215
|
+
const releaseTime = Number(window.Zonos.releaseDate);
|
|
7216
|
+
const currentTime = new Date().getTime();
|
|
7217
|
+
if (currentTime - releaseTime > postReleaseReportingDuration) {
|
|
7218
|
+
return;
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
const userAgentData = 'userAgentData' in window.navigator
|
|
7222
|
+
? // userAgentData is not yet supported in all browsers
|
|
7223
|
+
window.navigator.userAgentData
|
|
7224
|
+
: null;
|
|
7225
|
+
const errorObject = {
|
|
7226
|
+
endpoint,
|
|
7227
|
+
errors,
|
|
7228
|
+
metadata: Object.assign({ href: window.location.href, userAgent: userAgentData && userAgentData.brands.length > 0
|
|
7229
|
+
? userAgentData
|
|
7230
|
+
: window.navigator.userAgent }, metadata),
|
|
7231
|
+
};
|
|
7232
|
+
try {
|
|
7233
|
+
// use native fetch because in handleFetch also calls sendErrorLog and it will possibly cause circular dependencies issue
|
|
7234
|
+
void fetch(`${MAIN_BASE_API}/api/zonos-elements/log-error`, {
|
|
7235
|
+
body: JSON.stringify(errorObject),
|
|
7236
|
+
method: 'POST',
|
|
7237
|
+
});
|
|
7238
|
+
}
|
|
7239
|
+
catch (_err) {
|
|
7240
|
+
const nextFallbackApi = getNextFallbackApiType();
|
|
7241
|
+
if (!nextFallbackApi) {
|
|
7242
|
+
return;
|
|
7243
|
+
}
|
|
7244
|
+
// request to the fallback API if the first one fails
|
|
7245
|
+
void fetch(`${fallbackApiList[nextFallbackApi]}/api/zonos-elements/log-error`, {
|
|
7246
|
+
body: JSON.stringify(errorObject),
|
|
7247
|
+
method: 'POST',
|
|
7248
|
+
});
|
|
7249
|
+
}
|
|
7250
|
+
};
|
|
7251
|
+
|
|
7174
7252
|
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
7175
7253
|
var t = {};
|
|
7176
7254
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -7198,14 +7276,36 @@ const getResponseBody = async ({ response, shouldLog = true, shouldThrow = false
|
|
|
7198
7276
|
return null;
|
|
7199
7277
|
}
|
|
7200
7278
|
};
|
|
7201
|
-
const
|
|
7279
|
+
const encodeString = (text) => {
|
|
7280
|
+
try {
|
|
7281
|
+
// encode the string, remove the "=" at the end of the encoded string
|
|
7282
|
+
const encodedString = btoa(text).replace(/=/g, '');
|
|
7283
|
+
return encodedString;
|
|
7284
|
+
}
|
|
7285
|
+
catch (error) {
|
|
7286
|
+
// return the reverse string if the encoding failed
|
|
7287
|
+
return text
|
|
7288
|
+
.replace(/[^A-Za-z0-9]/g, '')
|
|
7289
|
+
.split('')
|
|
7290
|
+
.reverse()
|
|
7291
|
+
.join('');
|
|
7292
|
+
}
|
|
7293
|
+
};
|
|
7294
|
+
const handleRequest = async ({ basePathType, options, path, }) => {
|
|
7202
7295
|
let response;
|
|
7296
|
+
// fallback to the main base API if the passed in base path is not available
|
|
7297
|
+
const baseUrl = fallbackApiList[basePathType] || MAIN_BASE_API_TYPE;
|
|
7298
|
+
const url = baseUrl + path;
|
|
7299
|
+
// adding random encoded token to the url so that the request will be cached differently for each store
|
|
7300
|
+
const modifiedUrl = new URL(url);
|
|
7301
|
+
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
7203
7302
|
try {
|
|
7204
|
-
response = await fetch(
|
|
7303
|
+
response = await fetch(modifiedUrl.toString(), options);
|
|
7205
7304
|
}
|
|
7206
7305
|
catch (e) {
|
|
7207
7306
|
if (e instanceof Error) {
|
|
7208
7307
|
return {
|
|
7308
|
+
baseUrl,
|
|
7209
7309
|
errors: [{ message: e.message, type: 'unknown' }],
|
|
7210
7310
|
json: null,
|
|
7211
7311
|
response: null,
|
|
@@ -7214,6 +7314,7 @@ const handleRequest = async (url, options) => {
|
|
|
7214
7314
|
}
|
|
7215
7315
|
const message = 'Fail to fetch';
|
|
7216
7316
|
return {
|
|
7317
|
+
baseUrl,
|
|
7217
7318
|
errors: [{ message, type: 'unknown' }],
|
|
7218
7319
|
json: null,
|
|
7219
7320
|
response: null,
|
|
@@ -7229,6 +7330,7 @@ const handleRequest = async (url, options) => {
|
|
|
7229
7330
|
if (response.ok) {
|
|
7230
7331
|
const data = await getResponseBody({ response });
|
|
7231
7332
|
return {
|
|
7333
|
+
baseUrl,
|
|
7232
7334
|
errors: [],
|
|
7233
7335
|
json: data,
|
|
7234
7336
|
response,
|
|
@@ -7243,6 +7345,7 @@ const handleRequest = async (url, options) => {
|
|
|
7243
7345
|
});
|
|
7244
7346
|
const message = JSON.stringify(data);
|
|
7245
7347
|
return {
|
|
7348
|
+
baseUrl,
|
|
7246
7349
|
errors: [{ message, type: status }],
|
|
7247
7350
|
json: null,
|
|
7248
7351
|
response,
|
|
@@ -7252,6 +7355,7 @@ const handleRequest = async (url, options) => {
|
|
|
7252
7355
|
catch (e) {
|
|
7253
7356
|
const message = 'Unknown error';
|
|
7254
7357
|
return {
|
|
7358
|
+
baseUrl,
|
|
7255
7359
|
errors: [{ message: `${status}: ${message}`, type: status }],
|
|
7256
7360
|
json: null,
|
|
7257
7361
|
response: null,
|
|
@@ -7259,38 +7363,72 @@ const handleRequest = async (url, options) => {
|
|
|
7259
7363
|
};
|
|
7260
7364
|
}
|
|
7261
7365
|
};
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7366
|
+
const handleRequestWithFallback = async ({ basePathType, options, path, }) => {
|
|
7367
|
+
var _a, _b;
|
|
7368
|
+
const _c = await handleRequest({
|
|
7369
|
+
basePathType,
|
|
7370
|
+
options,
|
|
7371
|
+
path,
|
|
7372
|
+
}), { errors, response } = _c, rest = __rest(_c, ["errors", "response"]);
|
|
7373
|
+
const nextFallbackApiType = getNextFallbackApiType(basePathType);
|
|
7374
|
+
const unknownError = errors.find(({ type }) => type === 'unknown');
|
|
7375
|
+
const isUnknownError = !!unknownError || (response === null || response === void 0 ? void 0 : response.status) === 404;
|
|
7376
|
+
const shouldCallFallback =
|
|
7377
|
+
// If next fallback is available, and the error is unknown (fail to fetch) or 404
|
|
7378
|
+
nextFallbackApiType && isUnknownError;
|
|
7379
|
+
// Should log the error if it's unknown error
|
|
7380
|
+
if (isUnknownError) {
|
|
7381
|
+
void sendErrorLog({
|
|
7382
|
+
endpoint: fallbackApiList[basePathType] + path,
|
|
7383
|
+
errors: errors.map(({ message }) => message),
|
|
7384
|
+
metadata: {
|
|
7385
|
+
currentBasePath: basePathType,
|
|
7386
|
+
nextFallbackApiType,
|
|
7387
|
+
requestHeaders: options === null || options === void 0 ? void 0 : options.headers,
|
|
7388
|
+
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()),
|
|
7389
|
+
status: response === null || response === void 0 ? void 0 : response.status,
|
|
7390
|
+
statusText: response === null || response === void 0 ? void 0 : response.statusText,
|
|
7391
|
+
},
|
|
7392
|
+
// When the error is unknown, error reporting should be enabled for period of time after release, so we can monitor the error. We should always report error for the last fallback API fails
|
|
7393
|
+
shouldPostReleaseErrorReporting: !!nextFallbackApiType,
|
|
7394
|
+
});
|
|
7267
7395
|
}
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
return
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7396
|
+
if (shouldCallFallback) {
|
|
7397
|
+
log(`=== "${path}" failed to fetch, trying next fallback ${nextFallbackApiType}`);
|
|
7398
|
+
return handleRequestWithFallback({
|
|
7399
|
+
basePathType: nextFallbackApiType,
|
|
7400
|
+
options,
|
|
7401
|
+
path,
|
|
7402
|
+
});
|
|
7275
7403
|
}
|
|
7276
|
-
|
|
7277
|
-
|
|
7404
|
+
// No more fallbacks, just return the result
|
|
7405
|
+
return Object.assign({ errors, response }, rest);
|
|
7406
|
+
};
|
|
7407
|
+
/**
|
|
7408
|
+
* Fetch request and will request to fallback API when the first one fails
|
|
7409
|
+
* @param path Path name of the request (e.g. /api/something/com).
|
|
7410
|
+
* @param _opts fetch options
|
|
7411
|
+
*/
|
|
7412
|
+
const handleFetch = async (path, _opts) => {
|
|
7278
7413
|
const opts = __rest(_opts || {}, []);
|
|
7279
7414
|
const body = opts.body ? JSON.stringify(opts.body) : undefined;
|
|
7280
7415
|
const method = opts.method || 'GET';
|
|
7281
|
-
// adding random encoded token to the url so that the request will be cached differently for each store
|
|
7282
|
-
const modifiedUrl = new URL(url);
|
|
7283
|
-
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
7284
7416
|
// headers content type
|
|
7285
7417
|
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);
|
|
7286
7418
|
const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
|
|
7287
7419
|
method });
|
|
7288
|
-
|
|
7420
|
+
// This is for testing fallback API, set fallback API type to start with
|
|
7421
|
+
const useFallbackApi = new URLSearchParams(window.location.search).get('useFallbackApi');
|
|
7422
|
+
return handleRequestWithFallback({
|
|
7423
|
+
basePathType: useFallbackApi || MAIN_BASE_API_TYPE,
|
|
7424
|
+
options,
|
|
7425
|
+
path,
|
|
7426
|
+
});
|
|
7289
7427
|
};
|
|
7290
7428
|
|
|
7291
7429
|
const getCountries = async () => {
|
|
7292
7430
|
try {
|
|
7293
|
-
const { errors, json } = await handleFetch(
|
|
7431
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/get-countries', {
|
|
7294
7432
|
method: 'GET',
|
|
7295
7433
|
});
|
|
7296
7434
|
if (errors.length || !json) {
|
|
@@ -7308,7 +7446,7 @@ const getCountryLandedCost = async (countryCode) => {
|
|
|
7308
7446
|
if (!countryCode) {
|
|
7309
7447
|
return null;
|
|
7310
7448
|
}
|
|
7311
|
-
const url =
|
|
7449
|
+
const url = `/api/zonos-elements/country-landed-cost/${countryCode}`;
|
|
7312
7450
|
const { errors, json } = await handleFetch(url);
|
|
7313
7451
|
if (errors.length || !json) {
|
|
7314
7452
|
logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
@@ -7337,8 +7475,12 @@ const getExchangeRate = async ({ country, isGuaranteed, sourceCurrency, targetCu
|
|
|
7337
7475
|
if (sourceCurrency === targetCurrency && !isGuaranteed) {
|
|
7338
7476
|
return defaultUsExchangeRate;
|
|
7339
7477
|
}
|
|
7340
|
-
const
|
|
7341
|
-
|
|
7478
|
+
const searchParams = new URLSearchParams();
|
|
7479
|
+
searchParams.set('sourceCurrency', sourceCurrency);
|
|
7480
|
+
searchParams.set('targetCurrency', targetCurrency);
|
|
7481
|
+
searchParams.set('isGuaranteed', String(isGuaranteed));
|
|
7482
|
+
searchParams.set('country', country || '');
|
|
7483
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/exchange-rates?${searchParams.toString()}`);
|
|
7342
7484
|
if (errors.length || !json) {
|
|
7343
7485
|
logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7344
7486
|
return defaultUsExchangeRate;
|
|
@@ -7358,8 +7500,7 @@ const getInclusivePricing = async (countryCode) => {
|
|
|
7358
7500
|
if (!countryCode) {
|
|
7359
7501
|
return null;
|
|
7360
7502
|
}
|
|
7361
|
-
const
|
|
7362
|
-
const { errors, json } = await handleFetch(url);
|
|
7503
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/inclusive-prices/${countryCode}`);
|
|
7363
7504
|
if (errors.length || !json) {
|
|
7364
7505
|
logError(`Error fetching country inclusive price setting: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7365
7506
|
return null;
|
|
@@ -7369,8 +7510,13 @@ const getInclusivePricing = async (countryCode) => {
|
|
|
7369
7510
|
|
|
7370
7511
|
const getLocaleMessages = async ({ countryCode, localeTo, storeId, }) => {
|
|
7371
7512
|
var _a;
|
|
7372
|
-
const
|
|
7373
|
-
|
|
7513
|
+
const searchParams = new URLSearchParams();
|
|
7514
|
+
searchParams.set('countryCode', countryCode);
|
|
7515
|
+
searchParams.set('storeId', storeId.toString());
|
|
7516
|
+
if (localeTo) {
|
|
7517
|
+
searchParams.set('localeTo', localeTo);
|
|
7518
|
+
}
|
|
7519
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/locale-messages?${searchParams.toString()}`);
|
|
7374
7520
|
if (errors.length || !json) {
|
|
7375
7521
|
logError('Error fetching exchange rate', (_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message);
|
|
7376
7522
|
return [];
|
|
@@ -7390,14 +7536,11 @@ const getLocalization = async () => {
|
|
|
7390
7536
|
// load and use country from session storage when zCountry query param is not present
|
|
7391
7537
|
const countryLoadedSession = window.sessionStorage.getItem('zonos--country');
|
|
7392
7538
|
const zCountry = getZCountryUrlParam(currentUrl.searchParams) || countryLoadedSession;
|
|
7393
|
-
const
|
|
7539
|
+
const searchParams = new URLSearchParams();
|
|
7394
7540
|
if (zCountry) {
|
|
7395
|
-
|
|
7541
|
+
searchParams.set('zCountry', zCountry);
|
|
7396
7542
|
}
|
|
7397
|
-
const
|
|
7398
|
-
const { errors, json } = await handleFetch(fetchUrl, {
|
|
7399
|
-
method: 'GET',
|
|
7400
|
-
});
|
|
7543
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/localization?${searchParams.toString()}`);
|
|
7401
7544
|
if (errors.length || !json) {
|
|
7402
7545
|
return { country: null, locale: null };
|
|
7403
7546
|
}
|
|
@@ -7413,8 +7556,7 @@ const getLocalization = async () => {
|
|
|
7413
7556
|
|
|
7414
7557
|
const getShippingZones = async () => {
|
|
7415
7558
|
var _a, _b;
|
|
7416
|
-
const
|
|
7417
|
-
const { errors, json } = await handleFetch(url);
|
|
7559
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/shipping-zones');
|
|
7418
7560
|
if (errors.length || !json) {
|
|
7419
7561
|
logError(`Error fetching shipping zones: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7420
7562
|
return null;
|
|
@@ -7821,7 +7963,7 @@ const updateCheckoutSessionLanguage = async () => {
|
|
|
7821
7963
|
if (!cartStore.checkoutSessionId) {
|
|
7822
7964
|
return null;
|
|
7823
7965
|
}
|
|
7824
|
-
const { errors, json } = await handleFetch(
|
|
7966
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session-metadata', {
|
|
7825
7967
|
body: {
|
|
7826
7968
|
id: cartStore.checkoutSessionId,
|
|
7827
7969
|
metadata: [
|
|
@@ -7933,13 +8075,13 @@ const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
|
7933
8075
|
checkoutSessionId: data.checkoutSessionId,
|
|
7934
8076
|
contact: data.contact,
|
|
7935
8077
|
shippingAddress: data.shippingAddress,
|
|
7936
|
-
zonosApiRoute:
|
|
8078
|
+
zonosApiRoute: MAIN_BASE_API,
|
|
7937
8079
|
});
|
|
7938
8080
|
if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
7939
8081
|
throw new Error(`Failed to build landed cost: ${((_c = (_b = landedCost === null || landedCost === void 0 ? void 0 : landedCost.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error'}`);
|
|
7940
8082
|
}
|
|
7941
8083
|
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
7942
|
-
const { errors, json } = await handleFetch(
|
|
8084
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-landed-cost', {
|
|
7943
8085
|
body: landedCost,
|
|
7944
8086
|
headers: {
|
|
7945
8087
|
'Content-Type': 'application/json',
|
|
@@ -7961,8 +8103,7 @@ const calculateLandedCost = async (abortController) => {
|
|
|
7961
8103
|
return json;
|
|
7962
8104
|
}
|
|
7963
8105
|
// request to get landed cost info
|
|
7964
|
-
const
|
|
7965
|
-
const { errors, json } = await handleFetch(url, {
|
|
8106
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/calculate-landed-cost', {
|
|
7966
8107
|
body: prepCalculateLandedCost(),
|
|
7967
8108
|
method: 'POST',
|
|
7968
8109
|
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
@@ -8076,20 +8217,6 @@ const buildTranslateRequestBody = ({ addressInvalidCharactersList, billingAddres
|
|
|
8076
8217
|
};
|
|
8077
8218
|
};
|
|
8078
8219
|
|
|
8079
|
-
const jsonParse = (_data) => {
|
|
8080
|
-
if (typeof _data === 'string') {
|
|
8081
|
-
try {
|
|
8082
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
8083
|
-
const json = JSON.parse(_data);
|
|
8084
|
-
return json;
|
|
8085
|
-
}
|
|
8086
|
-
catch (_error) {
|
|
8087
|
-
return null;
|
|
8088
|
-
}
|
|
8089
|
-
}
|
|
8090
|
-
return null;
|
|
8091
|
-
};
|
|
8092
|
-
|
|
8093
8220
|
const addressRuleStyle = ({ theme, }) => {
|
|
8094
8221
|
const defaultStyle = {
|
|
8095
8222
|
'.AccordionItem': {
|
|
@@ -8493,13 +8620,11 @@ const stripeStoreInitCheckoutSession = async () => {
|
|
|
8493
8620
|
return false;
|
|
8494
8621
|
}
|
|
8495
8622
|
stripeStore.isFetchingSession = true;
|
|
8496
|
-
const { errors, json } = await handleFetch(
|
|
8623
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-checkout-session', {
|
|
8497
8624
|
body: {
|
|
8498
8625
|
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
8499
8626
|
itemsAmount: total,
|
|
8500
|
-
metadata: [
|
|
8501
|
-
{ key: 'language', value: localizationStore.selectedLocale },
|
|
8502
|
-
],
|
|
8627
|
+
metadata: [{ key: 'language', value: localizationStore.selectedLocale }],
|
|
8503
8628
|
presentmentCountryCode: localizationStore.selectedCountryCode || null,
|
|
8504
8629
|
},
|
|
8505
8630
|
method: 'POST',
|
|
@@ -8524,7 +8649,7 @@ const stripeStoreInitCheckoutSession = async () => {
|
|
|
8524
8649
|
const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
8525
8650
|
// No need to set loading state here because this function will be called under the hood to update
|
|
8526
8651
|
// landed cost id for the section.
|
|
8527
|
-
const { errors, json } = await handleFetch(
|
|
8652
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session', {
|
|
8528
8653
|
body: {
|
|
8529
8654
|
currency,
|
|
8530
8655
|
id,
|
|
@@ -8623,8 +8748,7 @@ const stripeStoreTranslateAddressToLatin = async ({ addressInvalidCharactersList
|
|
|
8623
8748
|
if (!isAddressOutdated) {
|
|
8624
8749
|
return;
|
|
8625
8750
|
}
|
|
8626
|
-
const
|
|
8627
|
-
const { errors, json } = await handleFetch(`${routeUrl}/api/zonos-elements/validate-address`, {
|
|
8751
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-address', {
|
|
8628
8752
|
body: requestBody,
|
|
8629
8753
|
method: 'POST',
|
|
8630
8754
|
});
|
|
@@ -8982,4 +9106,4 @@ const cartStoreResetTabItems = () => {
|
|
|
8982
9106
|
cartStoreResetSelectedShippingOption();
|
|
8983
9107
|
};
|
|
8984
9108
|
|
|
8985
|
-
export {
|
|
9109
|
+
export { initLocalizationStore as A, getZCountryUrlParam as B, setZCountryUrlParam as C, currencyDisplay as D, currencyConvertAndFormat as E, currencyConvert as F, currencyFormat as G, cartStoreHasOneEligibleItem as H, stripeStoreRetrievePayment as I, stripeStoreMessageBasedOnStatus as J, stripeStoreTranslateAddressToLatin as K, cartStoreUpdateSelectedShippingOption as L, cartStoreGetShippingTransitInfo as M, localizationStoreUpdateSelectedLocale as N, localizationStoreUpdateSelectedCountryCode as a, stripeStoreCleanupDomesticShippingSession as b, sendErrorLog as c, stripeStoreSaveDomesticShippingSession as d, cartStore as e, cartStoreUpdateItems as f, cartStoreReset as g, cartStoreResetTabItems as h, initStripeElements as i, cartStoreClearCheckoutInterval as j, stripeStore as k, localizationStore as l, stripeStoreInitCheckoutSession as m, cartStoreStartCheckoutInterval as n, cartStoreUpdateToErrorState as o, stripeStorePrefetchLandedCost as p, cartStoreNextStep as q, stripeStoreHandleInventoryCheck as r, stripeStoreGetDomesticShippingSession as s, translate as t, stripeStoreConfirmPayment as u, stripeStoreReset as v, localizationStoreOnUpdate as w, handleFetch as x, jsonParse as y, isValidSelector as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as handleFetch, e as cartStore, l as localizationStore } from './cart-3aae6236.js';
|
|
2
2
|
import { z as zonosStore } from './zonosStore-8fc9ceb2.js';
|
|
3
3
|
|
|
4
4
|
const trackConversionEvent = async (eventName, metadata) => {
|
|
@@ -13,7 +13,6 @@ const trackConversionEvent = async (eventName, metadata) => {
|
|
|
13
13
|
!window.Zonos.zonosConversionTest) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/track-conversion-event`;
|
|
17
16
|
const countryCode = localizationStore.selectedCountryCode;
|
|
18
17
|
const organizationId = zonosStore.organizationId;
|
|
19
18
|
const checkoutSessionId = cartStore.checkoutSessionId;
|
|
@@ -28,7 +27,7 @@ const trackConversionEvent = async (eventName, metadata) => {
|
|
|
28
27
|
metadata,
|
|
29
28
|
organizationId,
|
|
30
29
|
};
|
|
31
|
-
await handleFetch(
|
|
30
|
+
await handleFetch('/api/zonos-elements/track-conversion-event', {
|
|
32
31
|
body,
|
|
33
32
|
method: 'POST',
|
|
34
33
|
});
|
|
@@ -46,22 +45,4 @@ const createCustomEvent = (eventName, detail) => {
|
|
|
46
45
|
});
|
|
47
46
|
};
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
const userAgentData = 'userAgentData' in window.navigator
|
|
51
|
-
? // userAgentData is not yet supported in all browsers
|
|
52
|
-
window.navigator.userAgentData
|
|
53
|
-
: null;
|
|
54
|
-
const errorObject = {
|
|
55
|
-
endpoint,
|
|
56
|
-
errors,
|
|
57
|
-
metadata: Object.assign({ href: window.location.href, userAgent: userAgentData && userAgentData.brands.length > 0
|
|
58
|
-
? userAgentData
|
|
59
|
-
: window.navigator.userAgent }, metadata),
|
|
60
|
-
};
|
|
61
|
-
void handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/log-error`, {
|
|
62
|
-
body: errorObject,
|
|
63
|
-
method: 'POST',
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { createCustomEvent as c, getIsTestMode as g, sendErrorLog as s, trackConversionEvent as t };
|
|
48
|
+
export { createCustomEvent as c, getIsTestMode as g, trackConversionEvent as t };
|
package/dist/esm/index.js
CHANGED
|
@@ -90,13 +90,17 @@ const getZonosQaUrl = () => {
|
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
92
92
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
93
|
-
const cdnUrl = "https://v1.3.
|
|
93
|
+
const cdnUrl = "https://v1.3.47.js.zonos.com";
|
|
94
94
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
95
|
-
if (!qaUrl &&
|
|
95
|
+
if (!qaUrl &&
|
|
96
|
+
(cdnUrl.includes('test.') ||
|
|
97
|
+
// Vercel git domain
|
|
98
|
+
cdnUrl.includes('test-'))) {
|
|
96
99
|
return cdnUrl;
|
|
97
100
|
}
|
|
98
101
|
// when local demo app is running, it needs to use the local dev script unless the qaUrl is set
|
|
99
|
-
if (!qaUrl &&
|
|
102
|
+
if (!qaUrl &&
|
|
103
|
+
['dev.demo.elements.zonos.com'].includes(window.location.hostname)) {
|
|
100
104
|
return 'https://dev.elements.zonos.com';
|
|
101
105
|
}
|
|
102
106
|
if (!qaUrl) {
|
|
@@ -260,10 +264,10 @@ const zonosLoadUrl = (() => {
|
|
|
260
264
|
}
|
|
261
265
|
return null;
|
|
262
266
|
})();
|
|
263
|
-
const ZONOS_URL = "https://v1.3.
|
|
264
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
265
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.
|
|
266
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.
|
|
267
|
+
const ZONOS_URL = "https://v1.3.47.js.zonos.com";
|
|
268
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.47";
|
|
269
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.47";
|
|
270
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.47";
|
|
267
271
|
const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
|
|
268
272
|
const INTER_FONT_URL = 'https://rsms.me';
|
|
269
273
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
@@ -279,12 +283,13 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
|
|
|
279
283
|
!!window.location.search.match(/\?.*(&*)zonosConversionTest/);
|
|
280
284
|
Zonos._paypalMockResponse = null;
|
|
281
285
|
Zonos.isBigCommerce = false;
|
|
286
|
+
Zonos.releaseDate = "1726091038924";
|
|
282
287
|
/**
|
|
283
288
|
* By default, the package will load from npm
|
|
284
289
|
*/
|
|
285
290
|
Zonos.isNpm = true;
|
|
286
291
|
Zonos.zonosQaUrl = null;
|
|
287
|
-
Zonos.version = `v${"1.3.
|
|
292
|
+
Zonos.version = `v${"1.3.47"}`;
|
|
288
293
|
Zonos.modeAlerted = false;
|
|
289
294
|
Zonos.tempCartData = null;
|
|
290
295
|
Zonos.paypal = null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z as zonosStore, c as createStore } from './zonosStore-8fc9ceb2.js';
|
|
2
|
-
import {
|
|
2
|
+
import { x as handleFetch, e as cartStore, r as stripeStoreHandleInventoryCheck, t as translate, q as cartStoreNextStep, j as cartStoreClearCheckoutInterval, y as jsonParse } from './cart-3aae6236.js';
|
|
3
3
|
import { t as tinycolor } from './isDarkColor-3119e351.js';
|
|
4
4
|
import { l as log, a as logError } from './logError-c456c092.js';
|
|
5
5
|
|
|
@@ -207,7 +207,7 @@ function validateArguments(options, PromisePonyfill) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
const paypalCaptureOrder = async ({ checkoutSessionId, paypalMockResponse, }) => {
|
|
210
|
-
const { errors, json } = await handleFetch(
|
|
210
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/capture-paypal-order', {
|
|
211
211
|
body: { checkoutSessionId, paypalMockResponse },
|
|
212
212
|
method: 'POST',
|
|
213
213
|
});
|
|
@@ -215,7 +215,7 @@ const paypalCaptureOrder = async ({ checkoutSessionId, paypalMockResponse, }) =>
|
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
const paypalCreateOrder = async ({ checkoutSessionId, }) => {
|
|
218
|
-
const { errors, json } = await handleFetch(
|
|
218
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-paypal-order', {
|
|
219
219
|
body: { checkoutSessionId },
|
|
220
220
|
method: 'POST',
|
|
221
221
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as registerInstance, c as createEvent, h, H as Host, d as getElement } from './index-86b8247e.js';
|
|
2
|
-
import {
|
|
2
|
+
import { k as stripeStore, l as localizationStore, t as translate } from './cart-3aae6236.js';
|
|
3
3
|
import { i as isCheckoutMobile } from './isCheckoutMobile-8846dccb.js';
|
|
4
4
|
import { a as logError } from './logError-c456c092.js';
|
|
5
5
|
import { i as isTextContainsNonLatinChars, c as containsNonLatinChars } from './containsNonLatinChars-2d8810c3.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { r as registerInstance, a as getAssetPath, h, H as Host, F as Fragment, c as createEvent, d as getElement } from './index-86b8247e.js';
|
|
2
|
-
import {
|
|
2
|
+
import { e as cartStore, G as currencyFormat, H as cartStoreHasOneEligibleItem, t as translate, x as handleFetch, v as stripeStoreReset, c as sendErrorLog, k as stripeStore, I as stripeStoreRetrievePayment, J as stripeStoreMessageBasedOnStatus, l as localizationStore, K as stripeStoreTranslateAddressToLatin, L as cartStoreUpdateSelectedShippingOption, M as cartStoreGetShippingTransitInfo } from './cart-3aae6236.js';
|
|
3
3
|
import { c as classes } from './classes-0d95c529.js';
|
|
4
|
-
import { s as submitGtag, a as paypalStore, b as paypalStoreReset, c as paypalStoreHasPaypalEnabled, i as isContrastColor } from './paypal-
|
|
4
|
+
import { s as submitGtag, a as paypalStore, b as paypalStoreReset, c as paypalStoreHasPaypalEnabled, i as isContrastColor } from './paypal-b1589e7b.js';
|
|
5
5
|
import { z as zonosStore, g as getZonosStoreTheme, d as zonosStoreFontFamily } from './zonosStore-8fc9ceb2.js';
|
|
6
|
-
import { t as trackConversionEvent,
|
|
6
|
+
import { t as trackConversionEvent, c as createCustomEvent, g as getIsTestMode } from './createCustomEvent-ccb20b48.js';
|
|
7
7
|
import { g as getBorderRadius } from './getBorderRadius-3ba98361.js';
|
|
8
8
|
import { i as isCheckoutMobile } from './isCheckoutMobile-8846dccb.js';
|
|
9
9
|
import { l as languages } from './ILanguage-cd6acb72.js';
|
|
@@ -186,18 +186,25 @@ const ZonosCheckoutFinish = class {
|
|
|
186
186
|
this.closeClick = createEvent(this, "closeClick", 7);
|
|
187
187
|
this.pullOrder = async () => {
|
|
188
188
|
var _a, _b;
|
|
189
|
-
const baseUrl = "https://v1.route.js.zonos.com";
|
|
190
189
|
const checkoutSessionId = cartStore.checkoutSessionId;
|
|
191
|
-
const
|
|
190
|
+
const searchParams = new URLSearchParams();
|
|
191
|
+
searchParams.set('checkoutSessionId', checkoutSessionId || '');
|
|
192
|
+
const { baseUrl, errors, json } = await handleFetch(`/api/zonos-elements/get-order?${searchParams.toString()}`);
|
|
192
193
|
if (errors.length || !(json === null || json === void 0 ? void 0 : json.id)) {
|
|
193
|
-
return
|
|
194
|
+
return {
|
|
195
|
+
baseUrl,
|
|
196
|
+
order: null,
|
|
197
|
+
};
|
|
194
198
|
}
|
|
195
199
|
// onOrderSuccess callback may be provided on Zonos.init
|
|
196
200
|
await ((_b = (_a = zonosStore.checkoutSettings).onOrderSuccess) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
197
201
|
zonosApiRoute: baseUrl,
|
|
198
202
|
zonosOrder: json,
|
|
199
203
|
}));
|
|
200
|
-
return
|
|
204
|
+
return {
|
|
205
|
+
baseUrl,
|
|
206
|
+
order: json,
|
|
207
|
+
};
|
|
201
208
|
};
|
|
202
209
|
this.redirectToUrl = (url) => {
|
|
203
210
|
// reset store and checkout session id before redirecting
|
|
@@ -229,7 +236,7 @@ const ZonosCheckoutFinish = class {
|
|
|
229
236
|
};
|
|
230
237
|
// TODO: This method of pulling orders is temporary. Once we have a working event registry system, we will rely on that to tell us when the order is ready to trigger onOrderSuccess
|
|
231
238
|
this.getPullOrder = async (attempts = 0) => {
|
|
232
|
-
const order = await this.pullOrder();
|
|
239
|
+
const { baseUrl, order } = await this.pullOrder();
|
|
233
240
|
if (order) {
|
|
234
241
|
void trackConversionEvent('checkout_orderCompleted');
|
|
235
242
|
this.order = order;
|
|
@@ -243,7 +250,6 @@ const ZonosCheckoutFinish = class {
|
|
|
243
250
|
else {
|
|
244
251
|
// Set loading to false to display generic success page and log error
|
|
245
252
|
this.isLoading = false;
|
|
246
|
-
const baseUrl = "https://v1.route.js.zonos.com";
|
|
247
253
|
const checkoutSessionId = cartStore.checkoutSessionId;
|
|
248
254
|
void sendErrorLog({
|
|
249
255
|
endpoint: `${baseUrl}/api/zonos-elements/get-order?checkoutSessionId=${checkoutSessionId}`,
|
|
@@ -370,11 +376,11 @@ const ZonosCheckoutFinish = class {
|
|
|
370
376
|
var _a, _b;
|
|
371
377
|
const orderId = ((_a = this.order) === null || _a === void 0 ? void 0 : _a.accountOrderNumber) || getGraphQlShortId((_b = this.order) === null || _b === void 0 ? void 0 : _b.id);
|
|
372
378
|
const isTestMode = getIsTestMode();
|
|
373
|
-
return (h(Host, { key: '
|
|
379
|
+
return (h(Host, { key: 'ac24d728b66f975dc5f4abcc0e019577b92b5265', class: "zonos--checkout-finish zonos--elements", style: {
|
|
374
380
|
'--border-radius': getBorderRadius({
|
|
375
381
|
overrideBorderStyle: this.borderRadius,
|
|
376
382
|
}),
|
|
377
|
-
} }, this.isLoading && (h("div", { key: '
|
|
383
|
+
} }, this.isLoading && (h("div", { key: '5e445cb54f5a22f59823d502d6d20679568ccad9', class: "loading-wrapper" }, h("zonos-spinner", { key: 'c96e41437570caa001f3f5b8841a02d3896c2142' }))), !this.isLoading && (h("div", { key: '4a3f1cd814fa7d0bee7193d9ae3a39d170826944', class: "zonos--finish-details" }, h("div", { key: 'abc20383d6ddcfbe1833e8e846d629dcbabc83f9', class: "zonos--group" }, this.notificationType === 'success' ? (h("zonos-icon", { "aria-label": "Order success", content: SuccessIcon, iconColor: 'blue-800', size: 50 })) : (h("zonos-icon", { "aria-label": "Order failed", content: RemoveIcon, iconColor: 'red-800', size: 50 })), h("zonos-text", { key: 'ea5344bba3f55d026bf6f25a624f5bf94045f581', class: "zonos--title", type: "semiBoldSubheader" }, this.notificationTitle), orderId && (h("div", { key: '7622b546b79aefb379b70c1505b20a5c9926fc4d', class: "zonos--order-number" }, "Order #", orderId)), h("zonos-text", { key: '5748732fc28167b733ed917645db52b88522238f', textColor: "gray-600" }, this.notificationMessages.map(message => (h(Fragment, null, message, h("br", null))))), h("zonos-button", { key: 'd83ebfc701253978240eeccf685f4ea03ce1e25a', onClick: () => this.closeClickHandler(), size: "md", variant: "primary" }, this.notificationActionText)), isTestMode && cartStore.step === 'finish' && (h("div", { key: '5c08c8322043cde4c7ad687cc53d6b4ad9f94233', class: "zonos--finish-button-wrapper" }, h("zonos-button", { key: '8e69a15a544893304d143071e1321c6a4cd455c3', backgroundColor: "gray-0", buttonColor: "gray-1200", onClick: () => this.closeClickHandler(), size: "lg", variant: "outline" }, "New test cart"), h("zonos-button", { key: '132b343fef61cea8063dca9afc55e708226fa166', onClick: () => this.redirectToUrl(`/orders/all`), size: "lg", variant: "primary" }, "View order in Dashboard")))))));
|
|
378
384
|
}
|
|
379
385
|
static get assetsDirs() { return ["assets"]; }
|
|
380
386
|
};
|