@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
|
@@ -7173,6 +7173,84 @@ const translate = (...[key, replacement]) => {
|
|
|
7173
7173
|
return ((_b = translationStore.translatedChunks[key]) === null || _b === void 0 ? void 0 : _b.value) || key;
|
|
7174
7174
|
};
|
|
7175
7175
|
|
|
7176
|
+
const fallbackApiType = ['vercel', 'cloudflare'];
|
|
7177
|
+
const MAIN_BASE_API_TYPE = fallbackApiType[0];
|
|
7178
|
+
const fallbackApiList = {
|
|
7179
|
+
cloudflare: "https://route.elements.zonos.com",
|
|
7180
|
+
vercel: "https://v1.route.js.zonos.com",
|
|
7181
|
+
};
|
|
7182
|
+
const MAIN_BASE_API = fallbackApiList[MAIN_BASE_API_TYPE];
|
|
7183
|
+
/**
|
|
7184
|
+
* Next available fallback api type
|
|
7185
|
+
*/
|
|
7186
|
+
const getNextFallbackApiType = (currentApiType = MAIN_BASE_API_TYPE) => {
|
|
7187
|
+
const currentIndex = fallbackApiType.indexOf(currentApiType);
|
|
7188
|
+
const nextFallbackApiType = fallbackApiType[currentIndex + 1];
|
|
7189
|
+
if (!nextFallbackApiType) {
|
|
7190
|
+
return null;
|
|
7191
|
+
}
|
|
7192
|
+
return nextFallbackApiType;
|
|
7193
|
+
};
|
|
7194
|
+
|
|
7195
|
+
const jsonParse = (_data) => {
|
|
7196
|
+
if (typeof _data === 'string') {
|
|
7197
|
+
try {
|
|
7198
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7199
|
+
const json = JSON.parse(_data);
|
|
7200
|
+
return json;
|
|
7201
|
+
}
|
|
7202
|
+
catch (_error) {
|
|
7203
|
+
return null;
|
|
7204
|
+
}
|
|
7205
|
+
}
|
|
7206
|
+
return null;
|
|
7207
|
+
};
|
|
7208
|
+
|
|
7209
|
+
/**
|
|
7210
|
+
* This is the time in milliseconds after release time that we will start sending error logs to the new API
|
|
7211
|
+
* @default 1 hour
|
|
7212
|
+
*/
|
|
7213
|
+
const postReleaseReportingDuration = 1 * 3600 * 1000; // 1 hour
|
|
7214
|
+
const sendErrorLog = async ({ endpoint, errors, metadata, shouldPostReleaseErrorReporting, }) => {
|
|
7215
|
+
if (shouldPostReleaseErrorReporting) {
|
|
7216
|
+
// We only want to report errors that happened if current time is less than 2 hours after release time
|
|
7217
|
+
const releaseTime = Number(window.Zonos.releaseDate);
|
|
7218
|
+
const currentTime = new Date().getTime();
|
|
7219
|
+
if (currentTime - releaseTime > postReleaseReportingDuration) {
|
|
7220
|
+
return;
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
const userAgentData = 'userAgentData' in window.navigator
|
|
7224
|
+
? // userAgentData is not yet supported in all browsers
|
|
7225
|
+
window.navigator.userAgentData
|
|
7226
|
+
: null;
|
|
7227
|
+
const errorObject = {
|
|
7228
|
+
endpoint,
|
|
7229
|
+
errors,
|
|
7230
|
+
metadata: Object.assign({ href: window.location.href, userAgent: userAgentData && userAgentData.brands.length > 0
|
|
7231
|
+
? userAgentData
|
|
7232
|
+
: window.navigator.userAgent }, metadata),
|
|
7233
|
+
};
|
|
7234
|
+
try {
|
|
7235
|
+
// use native fetch because in handleFetch also calls sendErrorLog and it will possibly cause circular dependencies issue
|
|
7236
|
+
void fetch(`${MAIN_BASE_API}/api/zonos-elements/log-error`, {
|
|
7237
|
+
body: JSON.stringify(errorObject),
|
|
7238
|
+
method: 'POST',
|
|
7239
|
+
});
|
|
7240
|
+
}
|
|
7241
|
+
catch (_err) {
|
|
7242
|
+
const nextFallbackApi = getNextFallbackApiType();
|
|
7243
|
+
if (!nextFallbackApi) {
|
|
7244
|
+
return;
|
|
7245
|
+
}
|
|
7246
|
+
// request to the fallback API if the first one fails
|
|
7247
|
+
void fetch(`${fallbackApiList[nextFallbackApi]}/api/zonos-elements/log-error`, {
|
|
7248
|
+
body: JSON.stringify(errorObject),
|
|
7249
|
+
method: 'POST',
|
|
7250
|
+
});
|
|
7251
|
+
}
|
|
7252
|
+
};
|
|
7253
|
+
|
|
7176
7254
|
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
7177
7255
|
var t = {};
|
|
7178
7256
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -7200,14 +7278,36 @@ const getResponseBody = async ({ response, shouldLog = true, shouldThrow = false
|
|
|
7200
7278
|
return null;
|
|
7201
7279
|
}
|
|
7202
7280
|
};
|
|
7203
|
-
const
|
|
7281
|
+
const encodeString = (text) => {
|
|
7282
|
+
try {
|
|
7283
|
+
// encode the string, remove the "=" at the end of the encoded string
|
|
7284
|
+
const encodedString = btoa(text).replace(/=/g, '');
|
|
7285
|
+
return encodedString;
|
|
7286
|
+
}
|
|
7287
|
+
catch (error) {
|
|
7288
|
+
// return the reverse string if the encoding failed
|
|
7289
|
+
return text
|
|
7290
|
+
.replace(/[^A-Za-z0-9]/g, '')
|
|
7291
|
+
.split('')
|
|
7292
|
+
.reverse()
|
|
7293
|
+
.join('');
|
|
7294
|
+
}
|
|
7295
|
+
};
|
|
7296
|
+
const handleRequest = async ({ basePathType, options, path, }) => {
|
|
7204
7297
|
let response;
|
|
7298
|
+
// fallback to the main base API if the passed in base path is not available
|
|
7299
|
+
const baseUrl = fallbackApiList[basePathType] || MAIN_BASE_API_TYPE;
|
|
7300
|
+
const url = baseUrl + path;
|
|
7301
|
+
// adding random encoded token to the url so that the request will be cached differently for each store
|
|
7302
|
+
const modifiedUrl = new URL(url);
|
|
7303
|
+
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
7205
7304
|
try {
|
|
7206
|
-
response = await fetch(
|
|
7305
|
+
response = await fetch(modifiedUrl.toString(), options);
|
|
7207
7306
|
}
|
|
7208
7307
|
catch (e) {
|
|
7209
7308
|
if (e instanceof Error) {
|
|
7210
7309
|
return {
|
|
7310
|
+
baseUrl,
|
|
7211
7311
|
errors: [{ message: e.message, type: 'unknown' }],
|
|
7212
7312
|
json: null,
|
|
7213
7313
|
response: null,
|
|
@@ -7216,6 +7316,7 @@ const handleRequest = async (url, options) => {
|
|
|
7216
7316
|
}
|
|
7217
7317
|
const message = 'Fail to fetch';
|
|
7218
7318
|
return {
|
|
7319
|
+
baseUrl,
|
|
7219
7320
|
errors: [{ message, type: 'unknown' }],
|
|
7220
7321
|
json: null,
|
|
7221
7322
|
response: null,
|
|
@@ -7231,6 +7332,7 @@ const handleRequest = async (url, options) => {
|
|
|
7231
7332
|
if (response.ok) {
|
|
7232
7333
|
const data = await getResponseBody({ response });
|
|
7233
7334
|
return {
|
|
7335
|
+
baseUrl,
|
|
7234
7336
|
errors: [],
|
|
7235
7337
|
json: data,
|
|
7236
7338
|
response,
|
|
@@ -7245,6 +7347,7 @@ const handleRequest = async (url, options) => {
|
|
|
7245
7347
|
});
|
|
7246
7348
|
const message = JSON.stringify(data);
|
|
7247
7349
|
return {
|
|
7350
|
+
baseUrl,
|
|
7248
7351
|
errors: [{ message, type: status }],
|
|
7249
7352
|
json: null,
|
|
7250
7353
|
response,
|
|
@@ -7254,6 +7357,7 @@ const handleRequest = async (url, options) => {
|
|
|
7254
7357
|
catch (e) {
|
|
7255
7358
|
const message = 'Unknown error';
|
|
7256
7359
|
return {
|
|
7360
|
+
baseUrl,
|
|
7257
7361
|
errors: [{ message: `${status}: ${message}`, type: status }],
|
|
7258
7362
|
json: null,
|
|
7259
7363
|
response: null,
|
|
@@ -7261,38 +7365,72 @@ const handleRequest = async (url, options) => {
|
|
|
7261
7365
|
};
|
|
7262
7366
|
}
|
|
7263
7367
|
};
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7368
|
+
const handleRequestWithFallback = async ({ basePathType, options, path, }) => {
|
|
7369
|
+
var _a, _b;
|
|
7370
|
+
const _c = await handleRequest({
|
|
7371
|
+
basePathType,
|
|
7372
|
+
options,
|
|
7373
|
+
path,
|
|
7374
|
+
}), { errors, response } = _c, rest = __rest(_c, ["errors", "response"]);
|
|
7375
|
+
const nextFallbackApiType = getNextFallbackApiType(basePathType);
|
|
7376
|
+
const unknownError = errors.find(({ type }) => type === 'unknown');
|
|
7377
|
+
const isUnknownError = !!unknownError || (response === null || response === void 0 ? void 0 : response.status) === 404;
|
|
7378
|
+
const shouldCallFallback =
|
|
7379
|
+
// If next fallback is available, and the error is unknown (fail to fetch) or 404
|
|
7380
|
+
nextFallbackApiType && isUnknownError;
|
|
7381
|
+
// Should log the error if it's unknown error
|
|
7382
|
+
if (isUnknownError) {
|
|
7383
|
+
void sendErrorLog({
|
|
7384
|
+
endpoint: fallbackApiList[basePathType] + path,
|
|
7385
|
+
errors: errors.map(({ message }) => message),
|
|
7386
|
+
metadata: {
|
|
7387
|
+
currentBasePath: basePathType,
|
|
7388
|
+
nextFallbackApiType,
|
|
7389
|
+
requestHeaders: options === null || options === void 0 ? void 0 : options.headers,
|
|
7390
|
+
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()),
|
|
7391
|
+
status: response === null || response === void 0 ? void 0 : response.status,
|
|
7392
|
+
statusText: response === null || response === void 0 ? void 0 : response.statusText,
|
|
7393
|
+
},
|
|
7394
|
+
// 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
|
|
7395
|
+
shouldPostReleaseErrorReporting: !!nextFallbackApiType,
|
|
7396
|
+
});
|
|
7269
7397
|
}
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
return
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7398
|
+
if (shouldCallFallback) {
|
|
7399
|
+
logError.log(`=== "${path}" failed to fetch, trying next fallback ${nextFallbackApiType}`);
|
|
7400
|
+
return handleRequestWithFallback({
|
|
7401
|
+
basePathType: nextFallbackApiType,
|
|
7402
|
+
options,
|
|
7403
|
+
path,
|
|
7404
|
+
});
|
|
7277
7405
|
}
|
|
7278
|
-
|
|
7279
|
-
|
|
7406
|
+
// No more fallbacks, just return the result
|
|
7407
|
+
return Object.assign({ errors, response }, rest);
|
|
7408
|
+
};
|
|
7409
|
+
/**
|
|
7410
|
+
* Fetch request and will request to fallback API when the first one fails
|
|
7411
|
+
* @param path Path name of the request (e.g. /api/something/com).
|
|
7412
|
+
* @param _opts fetch options
|
|
7413
|
+
*/
|
|
7414
|
+
const handleFetch = async (path, _opts) => {
|
|
7280
7415
|
const opts = __rest(_opts || {}, []);
|
|
7281
7416
|
const body = opts.body ? JSON.stringify(opts.body) : undefined;
|
|
7282
7417
|
const method = opts.method || 'GET';
|
|
7283
|
-
// adding random encoded token to the url so that the request will be cached differently for each store
|
|
7284
|
-
const modifiedUrl = new URL(url);
|
|
7285
|
-
modifiedUrl.searchParams.set('zToken', encodeString(window.location.hostname));
|
|
7286
7418
|
// headers content type
|
|
7287
7419
|
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);
|
|
7288
7420
|
const options = Object.assign(Object.assign({}, opts), { body: method === 'GET' ? undefined : body, headers,
|
|
7289
7421
|
method });
|
|
7290
|
-
|
|
7422
|
+
// This is for testing fallback API, set fallback API type to start with
|
|
7423
|
+
const useFallbackApi = new URLSearchParams(window.location.search).get('useFallbackApi');
|
|
7424
|
+
return handleRequestWithFallback({
|
|
7425
|
+
basePathType: useFallbackApi || MAIN_BASE_API_TYPE,
|
|
7426
|
+
options,
|
|
7427
|
+
path,
|
|
7428
|
+
});
|
|
7291
7429
|
};
|
|
7292
7430
|
|
|
7293
7431
|
const getCountries = async () => {
|
|
7294
7432
|
try {
|
|
7295
|
-
const { errors, json } = await handleFetch(
|
|
7433
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/get-countries', {
|
|
7296
7434
|
method: 'GET',
|
|
7297
7435
|
});
|
|
7298
7436
|
if (errors.length || !json) {
|
|
@@ -7310,7 +7448,7 @@ const getCountryLandedCost = async (countryCode) => {
|
|
|
7310
7448
|
if (!countryCode) {
|
|
7311
7449
|
return null;
|
|
7312
7450
|
}
|
|
7313
|
-
const url =
|
|
7451
|
+
const url = `/api/zonos-elements/country-landed-cost/${countryCode}`;
|
|
7314
7452
|
const { errors, json } = await handleFetch(url);
|
|
7315
7453
|
if (errors.length || !json) {
|
|
7316
7454
|
logError.logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
@@ -7339,8 +7477,12 @@ const getExchangeRate = async ({ country, isGuaranteed, sourceCurrency, targetCu
|
|
|
7339
7477
|
if (sourceCurrency === targetCurrency && !isGuaranteed) {
|
|
7340
7478
|
return defaultUsExchangeRate;
|
|
7341
7479
|
}
|
|
7342
|
-
const
|
|
7343
|
-
|
|
7480
|
+
const searchParams = new URLSearchParams();
|
|
7481
|
+
searchParams.set('sourceCurrency', sourceCurrency);
|
|
7482
|
+
searchParams.set('targetCurrency', targetCurrency);
|
|
7483
|
+
searchParams.set('isGuaranteed', String(isGuaranteed));
|
|
7484
|
+
searchParams.set('country', country || '');
|
|
7485
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/exchange-rates?${searchParams.toString()}`);
|
|
7344
7486
|
if (errors.length || !json) {
|
|
7345
7487
|
logError.logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7346
7488
|
return defaultUsExchangeRate;
|
|
@@ -7360,8 +7502,7 @@ const getInclusivePricing = async (countryCode) => {
|
|
|
7360
7502
|
if (!countryCode) {
|
|
7361
7503
|
return null;
|
|
7362
7504
|
}
|
|
7363
|
-
const
|
|
7364
|
-
const { errors, json } = await handleFetch(url);
|
|
7505
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/inclusive-prices/${countryCode}`);
|
|
7365
7506
|
if (errors.length || !json) {
|
|
7366
7507
|
logError.logError(`Error fetching country inclusive price setting: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7367
7508
|
return null;
|
|
@@ -7371,8 +7512,13 @@ const getInclusivePricing = async (countryCode) => {
|
|
|
7371
7512
|
|
|
7372
7513
|
const getLocaleMessages = async ({ countryCode, localeTo, storeId, }) => {
|
|
7373
7514
|
var _a;
|
|
7374
|
-
const
|
|
7375
|
-
|
|
7515
|
+
const searchParams = new URLSearchParams();
|
|
7516
|
+
searchParams.set('countryCode', countryCode);
|
|
7517
|
+
searchParams.set('storeId', storeId.toString());
|
|
7518
|
+
if (localeTo) {
|
|
7519
|
+
searchParams.set('localeTo', localeTo);
|
|
7520
|
+
}
|
|
7521
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/locale-messages?${searchParams.toString()}`);
|
|
7376
7522
|
if (errors.length || !json) {
|
|
7377
7523
|
logError.logError('Error fetching exchange rate', (_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message);
|
|
7378
7524
|
return [];
|
|
@@ -7392,14 +7538,11 @@ const getLocalization = async () => {
|
|
|
7392
7538
|
// load and use country from session storage when zCountry query param is not present
|
|
7393
7539
|
const countryLoadedSession = window.sessionStorage.getItem('zonos--country');
|
|
7394
7540
|
const zCountry = getZCountryUrlParam(currentUrl.searchParams) || countryLoadedSession;
|
|
7395
|
-
const
|
|
7541
|
+
const searchParams = new URLSearchParams();
|
|
7396
7542
|
if (zCountry) {
|
|
7397
|
-
|
|
7543
|
+
searchParams.set('zCountry', zCountry);
|
|
7398
7544
|
}
|
|
7399
|
-
const
|
|
7400
|
-
const { errors, json } = await handleFetch(fetchUrl, {
|
|
7401
|
-
method: 'GET',
|
|
7402
|
-
});
|
|
7545
|
+
const { errors, json } = await handleFetch(`/api/zonos-elements/localization?${searchParams.toString()}`);
|
|
7403
7546
|
if (errors.length || !json) {
|
|
7404
7547
|
return { country: null, locale: null };
|
|
7405
7548
|
}
|
|
@@ -7415,8 +7558,7 @@ const getLocalization = async () => {
|
|
|
7415
7558
|
|
|
7416
7559
|
const getShippingZones = async () => {
|
|
7417
7560
|
var _a, _b;
|
|
7418
|
-
const
|
|
7419
|
-
const { errors, json } = await handleFetch(url);
|
|
7561
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/shipping-zones');
|
|
7420
7562
|
if (errors.length || !json) {
|
|
7421
7563
|
logError.logError(`Error fetching shipping zones: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
7422
7564
|
return null;
|
|
@@ -7823,7 +7965,7 @@ const updateCheckoutSessionLanguage = async () => {
|
|
|
7823
7965
|
if (!cartStore.checkoutSessionId) {
|
|
7824
7966
|
return null;
|
|
7825
7967
|
}
|
|
7826
|
-
const { errors, json } = await handleFetch(
|
|
7968
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session-metadata', {
|
|
7827
7969
|
body: {
|
|
7828
7970
|
id: cartStore.checkoutSessionId,
|
|
7829
7971
|
metadata: [
|
|
@@ -7935,13 +8077,13 @@ const triggerBuildLandedCost = async (buildLandedCost) => {
|
|
|
7935
8077
|
checkoutSessionId: data.checkoutSessionId,
|
|
7936
8078
|
contact: data.contact,
|
|
7937
8079
|
shippingAddress: data.shippingAddress,
|
|
7938
|
-
zonosApiRoute:
|
|
8080
|
+
zonosApiRoute: MAIN_BASE_API,
|
|
7939
8081
|
});
|
|
7940
8082
|
if (!landedCost || ((_a = landedCost.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
7941
8083
|
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'}`);
|
|
7942
8084
|
}
|
|
7943
8085
|
// Validate the landed cost object to make sure the returned value from buildLandedCost has a valid schema
|
|
7944
|
-
const { errors, json } = await handleFetch(
|
|
8086
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-landed-cost', {
|
|
7945
8087
|
body: landedCost,
|
|
7946
8088
|
headers: {
|
|
7947
8089
|
'Content-Type': 'application/json',
|
|
@@ -7963,8 +8105,7 @@ const calculateLandedCost = async (abortController) => {
|
|
|
7963
8105
|
return json;
|
|
7964
8106
|
}
|
|
7965
8107
|
// request to get landed cost info
|
|
7966
|
-
const
|
|
7967
|
-
const { errors, json } = await handleFetch(url, {
|
|
8108
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/calculate-landed-cost', {
|
|
7968
8109
|
body: prepCalculateLandedCost(),
|
|
7969
8110
|
method: 'POST',
|
|
7970
8111
|
signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
|
|
@@ -8078,20 +8219,6 @@ const buildTranslateRequestBody = ({ addressInvalidCharactersList, billingAddres
|
|
|
8078
8219
|
};
|
|
8079
8220
|
};
|
|
8080
8221
|
|
|
8081
|
-
const jsonParse = (_data) => {
|
|
8082
|
-
if (typeof _data === 'string') {
|
|
8083
|
-
try {
|
|
8084
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
8085
|
-
const json = JSON.parse(_data);
|
|
8086
|
-
return json;
|
|
8087
|
-
}
|
|
8088
|
-
catch (_error) {
|
|
8089
|
-
return null;
|
|
8090
|
-
}
|
|
8091
|
-
}
|
|
8092
|
-
return null;
|
|
8093
|
-
};
|
|
8094
|
-
|
|
8095
8222
|
const addressRuleStyle = ({ theme, }) => {
|
|
8096
8223
|
const defaultStyle = {
|
|
8097
8224
|
'.AccordionItem': {
|
|
@@ -8495,13 +8622,11 @@ const stripeStoreInitCheckoutSession = async () => {
|
|
|
8495
8622
|
return false;
|
|
8496
8623
|
}
|
|
8497
8624
|
stripeStore.isFetchingSession = true;
|
|
8498
|
-
const { errors, json } = await handleFetch(
|
|
8625
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/create-checkout-session', {
|
|
8499
8626
|
body: {
|
|
8500
8627
|
currency: ((_a = cartStore.items.find(Boolean)) === null || _a === void 0 ? void 0 : _a.currencyCode) || '',
|
|
8501
8628
|
itemsAmount: total,
|
|
8502
|
-
metadata: [
|
|
8503
|
-
{ key: 'language', value: localizationStore.selectedLocale },
|
|
8504
|
-
],
|
|
8629
|
+
metadata: [{ key: 'language', value: localizationStore.selectedLocale }],
|
|
8505
8630
|
presentmentCountryCode: localizationStore.selectedCountryCode || null,
|
|
8506
8631
|
},
|
|
8507
8632
|
method: 'POST',
|
|
@@ -8526,7 +8651,7 @@ const stripeStoreInitCheckoutSession = async () => {
|
|
|
8526
8651
|
const stripeStoreUpdateCheckoutSession = async ({ currency, id, itemsAmount, landedCostId, presentmentCountryCode, }) => {
|
|
8527
8652
|
// No need to set loading state here because this function will be called under the hood to update
|
|
8528
8653
|
// landed cost id for the section.
|
|
8529
|
-
const { errors, json } = await handleFetch(
|
|
8654
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/update-checkout-session', {
|
|
8530
8655
|
body: {
|
|
8531
8656
|
currency,
|
|
8532
8657
|
id,
|
|
@@ -8625,8 +8750,7 @@ const stripeStoreTranslateAddressToLatin = async ({ addressInvalidCharactersList
|
|
|
8625
8750
|
if (!isAddressOutdated) {
|
|
8626
8751
|
return;
|
|
8627
8752
|
}
|
|
8628
|
-
const
|
|
8629
|
-
const { errors, json } = await handleFetch(`${routeUrl}/api/zonos-elements/validate-address`, {
|
|
8753
|
+
const { errors, json } = await handleFetch('/api/zonos-elements/validate-address', {
|
|
8630
8754
|
body: requestBody,
|
|
8631
8755
|
method: 'POST',
|
|
8632
8756
|
});
|
|
@@ -9009,6 +9133,7 @@ exports.localizationStore = localizationStore;
|
|
|
9009
9133
|
exports.localizationStoreOnUpdate = localizationStoreOnUpdate;
|
|
9010
9134
|
exports.localizationStoreUpdateSelectedCountryCode = localizationStoreUpdateSelectedCountryCode;
|
|
9011
9135
|
exports.localizationStoreUpdateSelectedLocale = localizationStoreUpdateSelectedLocale;
|
|
9136
|
+
exports.sendErrorLog = sendErrorLog;
|
|
9012
9137
|
exports.setZCountryUrlParam = setZCountryUrlParam;
|
|
9013
9138
|
exports.stripeStore = stripeStore;
|
|
9014
9139
|
exports.stripeStoreCleanupDomesticShippingSession = stripeStoreCleanupDomesticShippingSession;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const cart = require('./cart-
|
|
3
|
+
const cart = require('./cart-85870c2e.js');
|
|
4
4
|
const zonosStore = require('./zonosStore-56401fdb.js');
|
|
5
5
|
|
|
6
6
|
const trackConversionEvent = async (eventName, metadata) => {
|
|
@@ -15,7 +15,6 @@ const trackConversionEvent = async (eventName, metadata) => {
|
|
|
15
15
|
!window.Zonos.zonosConversionTest) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const url = `${"https://v1.route.js.zonos.com"}/api/zonos-elements/track-conversion-event`;
|
|
19
18
|
const countryCode = cart.localizationStore.selectedCountryCode;
|
|
20
19
|
const organizationId = zonosStore.zonosStore.organizationId;
|
|
21
20
|
const checkoutSessionId = cart.cartStore.checkoutSessionId;
|
|
@@ -30,7 +29,7 @@ const trackConversionEvent = async (eventName, metadata) => {
|
|
|
30
29
|
metadata,
|
|
31
30
|
organizationId,
|
|
32
31
|
};
|
|
33
|
-
await cart.handleFetch(
|
|
32
|
+
await cart.handleFetch('/api/zonos-elements/track-conversion-event', {
|
|
34
33
|
body,
|
|
35
34
|
method: 'POST',
|
|
36
35
|
});
|
|
@@ -48,25 +47,6 @@ const createCustomEvent = (eventName, detail) => {
|
|
|
48
47
|
});
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
const sendErrorLog = async ({ endpoint, errors, metadata }) => {
|
|
52
|
-
const userAgentData = 'userAgentData' in window.navigator
|
|
53
|
-
? // userAgentData is not yet supported in all browsers
|
|
54
|
-
window.navigator.userAgentData
|
|
55
|
-
: null;
|
|
56
|
-
const errorObject = {
|
|
57
|
-
endpoint,
|
|
58
|
-
errors,
|
|
59
|
-
metadata: Object.assign({ href: window.location.href, userAgent: userAgentData && userAgentData.brands.length > 0
|
|
60
|
-
? userAgentData
|
|
61
|
-
: window.navigator.userAgent }, metadata),
|
|
62
|
-
};
|
|
63
|
-
void cart.handleFetch(`${"https://v1.route.js.zonos.com"}/api/zonos-elements/log-error`, {
|
|
64
|
-
body: errorObject,
|
|
65
|
-
method: 'POST',
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
50
|
exports.createCustomEvent = createCustomEvent;
|
|
70
51
|
exports.getIsTestMode = getIsTestMode;
|
|
71
|
-
exports.sendErrorLog = sendErrorLog;
|
|
72
52
|
exports.trackConversionEvent = trackConversionEvent;
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -94,13 +94,17 @@ const getZonosQaUrl = () => {
|
|
|
94
94
|
return null;
|
|
95
95
|
}
|
|
96
96
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
97
|
-
const cdnUrl = "https://v1.3.
|
|
97
|
+
const cdnUrl = "https://v1.3.47.js.zonos.com";
|
|
98
98
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
99
|
-
if (!qaUrl &&
|
|
99
|
+
if (!qaUrl &&
|
|
100
|
+
(cdnUrl.includes('test.') ||
|
|
101
|
+
// Vercel git domain
|
|
102
|
+
cdnUrl.includes('test-'))) {
|
|
100
103
|
return cdnUrl;
|
|
101
104
|
}
|
|
102
105
|
// when local demo app is running, it needs to use the local dev script unless the qaUrl is set
|
|
103
|
-
if (!qaUrl &&
|
|
106
|
+
if (!qaUrl &&
|
|
107
|
+
['dev.demo.elements.zonos.com'].includes(window.location.hostname)) {
|
|
104
108
|
return 'https://dev.elements.zonos.com';
|
|
105
109
|
}
|
|
106
110
|
if (!qaUrl) {
|
|
@@ -264,10 +268,10 @@ const zonosLoadUrl = (() => {
|
|
|
264
268
|
}
|
|
265
269
|
return null;
|
|
266
270
|
})();
|
|
267
|
-
const ZONOS_URL = "https://v1.3.
|
|
268
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
269
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.
|
|
270
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.
|
|
271
|
+
const ZONOS_URL = "https://v1.3.47.js.zonos.com";
|
|
272
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.47";
|
|
273
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.47";
|
|
274
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.47";
|
|
271
275
|
const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
|
|
272
276
|
const INTER_FONT_URL = 'https://rsms.me';
|
|
273
277
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
@@ -283,12 +287,13 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
|
|
|
283
287
|
!!window.location.search.match(/\?.*(&*)zonosConversionTest/);
|
|
284
288
|
Zonos._paypalMockResponse = null;
|
|
285
289
|
Zonos.isBigCommerce = false;
|
|
290
|
+
Zonos.releaseDate = "1726091038924";
|
|
286
291
|
/**
|
|
287
292
|
* By default, the package will load from npm
|
|
288
293
|
*/
|
|
289
294
|
Zonos.isNpm = true;
|
|
290
295
|
Zonos.zonosQaUrl = null;
|
|
291
|
-
Zonos.version = `v${"1.3.
|
|
296
|
+
Zonos.version = `v${"1.3.47"}`;
|
|
292
297
|
Zonos.modeAlerted = false;
|
|
293
298
|
Zonos.tempCartData = null;
|
|
294
299
|
Zonos.paypal = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const zonosStore = require('./zonosStore-56401fdb.js');
|
|
4
|
-
const cart = require('./cart-
|
|
4
|
+
const cart = require('./cart-85870c2e.js');
|
|
5
5
|
const isDarkColor = require('./isDarkColor-4eb96a1e.js');
|
|
6
6
|
const logError = require('./logError-4e2f2020.js');
|
|
7
7
|
|
|
@@ -209,7 +209,7 @@ function validateArguments(options, PromisePonyfill) {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
const paypalCaptureOrder = async ({ checkoutSessionId, paypalMockResponse, }) => {
|
|
212
|
-
const { errors, json } = await cart.handleFetch(
|
|
212
|
+
const { errors, json } = await cart.handleFetch('/api/zonos-elements/capture-paypal-order', {
|
|
213
213
|
body: { checkoutSessionId, paypalMockResponse },
|
|
214
214
|
method: 'POST',
|
|
215
215
|
});
|
|
@@ -217,7 +217,7 @@ const paypalCaptureOrder = async ({ checkoutSessionId, paypalMockResponse, }) =>
|
|
|
217
217
|
};
|
|
218
218
|
|
|
219
219
|
const paypalCreateOrder = async ({ checkoutSessionId, }) => {
|
|
220
|
-
const { errors, json } = await cart.handleFetch(
|
|
220
|
+
const { errors, json } = await cart.handleFetch('/api/zonos-elements/create-paypal-order', {
|
|
221
221
|
body: { checkoutSessionId },
|
|
222
222
|
method: 'POST',
|
|
223
223
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-d56e0a8b.js');
|
|
6
|
-
const cart = require('./cart-
|
|
6
|
+
const cart = require('./cart-85870c2e.js');
|
|
7
7
|
const isCheckoutMobile = require('./isCheckoutMobile-f491ca7c.js');
|
|
8
8
|
const logError = require('./logError-4e2f2020.js');
|
|
9
9
|
const containsNonLatinChars = require('./containsNonLatinChars-2be5129b.js');
|