@zonos/elements 1.4.0 → 1.4.2
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/index.cjs.js +11 -7
- package/dist/cjs/zonos-checkout.cjs.entry.js +77 -0
- package/dist/collection/components/utils/checkout/isBigCommerceCheckoutBypassEnabled.js +74 -0
- package/dist/collection/components/utils/checkout/watchImmediateBigcommerceDomesticCheckoutRedirect.js +8 -0
- package/dist/collection/scripts/_getZonosQaUrl.js +8 -1
- package/dist/esm/index.js +11 -7
- package/dist/esm/zonos-checkout.entry.js +77 -0
- package/dist/esm-es5/index.js +12 -10
- package/dist/esm-es5/zonos-checkout.entry.js +38 -13
- package/dist/scripts/index.d.ts +14 -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/checkout/isBigCommerceCheckoutBypassEnabled.d.ts +11 -0
- package/dist/types/types/checkout/CheckoutConfig.d.ts +14 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-0457f579.entry.js +1 -0
- package/dist/zonos-elements/p-Bu9WCfUC.system.js +1 -1
- package/dist/zonos-elements/{p-BiR2fYOJ.system.js → p-DCS8qcL6.system.js} +7 -5
- package/dist/zonos-elements/{p-5236c676.system.entry.js → p-be1237fc.system.entry.js} +68 -43
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/zonos-elements/p-f8b50aa0.entry.js +0 -1
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -131,7 +131,7 @@ const getZonosQaUrl = () => {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
134
|
-
const cdnUrl = "https://v1.4.
|
|
134
|
+
const cdnUrl = "https://v1.4.2.js.zonos.com";
|
|
135
135
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
136
136
|
if (!qaUrl &&
|
|
137
137
|
(cdnUrl.includes('test.') ||
|
|
@@ -155,6 +155,10 @@ const getZonosQaUrl = () => {
|
|
|
155
155
|
if (qaUrl === 'dev-elements') {
|
|
156
156
|
return 'https://dev.elements.zonos.com';
|
|
157
157
|
}
|
|
158
|
+
// The worker alias selects the API host only. Scripts stay on the normal CDN.
|
|
159
|
+
if (qaUrl === 'worker') {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
158
162
|
const suffixDomain = 'preview.js.zonos.com';
|
|
159
163
|
const fullUrl = `https://${qaUrl}.${suffixDomain}`;
|
|
160
164
|
VarianceTest.log(`[ZONOS-WARNING] using '${fullUrl}' for loading elements script`, 'warn');
|
|
@@ -416,10 +420,10 @@ const zonosLoadUrl = (() => {
|
|
|
416
420
|
return null;
|
|
417
421
|
})();
|
|
418
422
|
const startLoadTime = Date.now();
|
|
419
|
-
const ZONOS_URL = "https://v1.4.
|
|
420
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.
|
|
421
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.4.
|
|
422
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.
|
|
423
|
+
const ZONOS_URL = "https://v1.4.2.js.zonos.com";
|
|
424
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.2";
|
|
425
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.4.2";
|
|
426
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.2";
|
|
423
427
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
424
428
|
const GOOGLE_FONT_REGEX = /^https:\/\/fonts\.googleapis\.com/;
|
|
425
429
|
class Zonos {
|
|
@@ -437,7 +441,7 @@ Zonos.iframeLogType = typeof window !== 'undefined'
|
|
|
437
441
|
? new URLSearchParams(window.location.search).get('iframeLogType')
|
|
438
442
|
: null;
|
|
439
443
|
Zonos.isBigCommerce = false;
|
|
440
|
-
Zonos.releaseDate = "
|
|
444
|
+
Zonos.releaseDate = "1792599810755";
|
|
441
445
|
Zonos.isLegacyCheckout = false;
|
|
442
446
|
Zonos.googleAnalyticId = null;
|
|
443
447
|
Zonos.googleAnalyticReady = false;
|
|
@@ -462,7 +466,7 @@ Zonos.isNpm = true;
|
|
|
462
466
|
Zonos.zonosQaUrl = null;
|
|
463
467
|
Zonos.zonosQaUrlApi = null;
|
|
464
468
|
Zonos.trackEventLogs = [];
|
|
465
|
-
Zonos.version = `v${"1.4.
|
|
469
|
+
Zonos.version = `v${"1.4.2"}`;
|
|
466
470
|
Zonos.modeAlerted = false;
|
|
467
471
|
Zonos.cartData = null;
|
|
468
472
|
Zonos.paypal = null;
|
|
@@ -700,6 +700,76 @@ providedCountryCode) => {
|
|
|
700
700
|
return true;
|
|
701
701
|
};
|
|
702
702
|
|
|
703
|
+
const ZBYPASS_ON_VALUES = ['1', 'true', 'yes'];
|
|
704
|
+
/**
|
|
705
|
+
* Page-load result of reading the checkout `zBypass` query. Later calls on the
|
|
706
|
+
* same checkout URL reuse this so stripping the parameter does not change the
|
|
707
|
+
* answer.
|
|
708
|
+
*/
|
|
709
|
+
let consumedZBypassQuery = null;
|
|
710
|
+
const isCheckoutPage = () => {
|
|
711
|
+
return window.location.pathname.includes('/checkout');
|
|
712
|
+
};
|
|
713
|
+
const isAcceptedZBypassQuery = (rawValue) => {
|
|
714
|
+
if (rawValue === null) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
return ZBYPASS_ON_VALUES.includes(rawValue.trim().toLowerCase());
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* True only when zonos-settings set
|
|
721
|
+
* `checkoutSettings.plugins.bigcommerce.allowBypassQuery` to `true`.
|
|
722
|
+
*/
|
|
723
|
+
const isBypassQueryAllowed = () => {
|
|
724
|
+
var _a, _b;
|
|
725
|
+
return (((_b = (_a = zonosStore.zonosStore.checkoutSettings.plugins) === null || _a === void 0 ? void 0 : _a.bigcommerce) === null || _b === void 0 ? void 0 : _b.allowBypassQuery) === true);
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Read an accepted `zBypass` query on the checkout page once, then remove it
|
|
729
|
+
* from the URL. A later call on that same URL returns the same answer.
|
|
730
|
+
*/
|
|
731
|
+
const readCheckoutZBypassQuery = () => {
|
|
732
|
+
const { pathname, search } = window.location;
|
|
733
|
+
if (consumedZBypassQuery &&
|
|
734
|
+
consumedZBypassQuery.pathname === pathname &&
|
|
735
|
+
consumedZBypassQuery.search === search) {
|
|
736
|
+
return consumedZBypassQuery.enabled;
|
|
737
|
+
}
|
|
738
|
+
const params = new URLSearchParams(search);
|
|
739
|
+
const accepted = isAcceptedZBypassQuery(params.get('zBypass'));
|
|
740
|
+
if (!accepted) {
|
|
741
|
+
consumedZBypassQuery = { enabled: false, pathname, search };
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
params.delete('zBypass');
|
|
745
|
+
const nextSearch = params.toString();
|
|
746
|
+
const hash = window.location.hash || '';
|
|
747
|
+
const nextUrl = `${pathname}${nextSearch ? `?${nextSearch}` : ''}${hash}`;
|
|
748
|
+
window.history.replaceState(window.history.state, document.title, nextUrl);
|
|
749
|
+
const enabled = isBypassQueryAllowed();
|
|
750
|
+
consumedZBypassQuery = {
|
|
751
|
+
enabled,
|
|
752
|
+
pathname,
|
|
753
|
+
search: window.location.search,
|
|
754
|
+
};
|
|
755
|
+
return enabled;
|
|
756
|
+
};
|
|
757
|
+
/**
|
|
758
|
+
* True when this BigCommerce checkout page should skip address detection.
|
|
759
|
+
* That is only when zonos-settings allows the `zBypass` query and this
|
|
760
|
+
* checkout URL has an accepted value. Storefront pages are never bypassed, so
|
|
761
|
+
* the query stays in the URL until checkout. The query is removed once, and
|
|
762
|
+
* later calls on that checkout URL keep the same answer. Nothing is written
|
|
763
|
+
* to storage.
|
|
764
|
+
*/
|
|
765
|
+
const isBigCommerceCheckoutBypassEnabled = () => {
|
|
766
|
+
var _a;
|
|
767
|
+
if (!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.isBigCommerce) || !isCheckoutPage()) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
return readCheckoutZBypassQuery();
|
|
771
|
+
};
|
|
772
|
+
|
|
703
773
|
const FALLBACK_SHIP_TO_COUNTRY_SELECTOR = 'select[name="shippingAddress.countryCode"]';
|
|
704
774
|
/**
|
|
705
775
|
* Native BigCommerce shipping-step "Continue" button. Clicking it commits the
|
|
@@ -800,6 +870,13 @@ const watchImmediateBigcommerceDomesticCheckoutRedirect = ({ domesticRedirectedB
|
|
|
800
870
|
if (!window.Zonos.isBigCommerce) {
|
|
801
871
|
return;
|
|
802
872
|
}
|
|
873
|
+
// Only the native checkout page skips address detection. Storefront pages
|
|
874
|
+
// still run the domestic-session handoff below, and they do not consume
|
|
875
|
+
// a `zBypass` query, so the parameter can survive until `/checkout`.
|
|
876
|
+
if (window.location.pathname.includes('/checkout') &&
|
|
877
|
+
isBigCommerceCheckoutBypassEnabled()) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
803
880
|
/**
|
|
804
881
|
* Keep checking.
|
|
805
882
|
* @returns `true` if the caller should stop polling — either because the user
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { zonosStore } from "../../store/zonosStore";
|
|
2
|
+
const ZBYPASS_ON_VALUES = ['1', 'true', 'yes'];
|
|
3
|
+
/**
|
|
4
|
+
* Page-load result of reading the checkout `zBypass` query. Later calls on the
|
|
5
|
+
* same checkout URL reuse this so stripping the parameter does not change the
|
|
6
|
+
* answer.
|
|
7
|
+
*/
|
|
8
|
+
let consumedZBypassQuery = null;
|
|
9
|
+
const isCheckoutPage = () => {
|
|
10
|
+
return window.location.pathname.includes('/checkout');
|
|
11
|
+
};
|
|
12
|
+
const isAcceptedZBypassQuery = (rawValue) => {
|
|
13
|
+
if (rawValue === null) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return ZBYPASS_ON_VALUES.includes(rawValue.trim().toLowerCase());
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* True only when zonos-settings set
|
|
20
|
+
* `checkoutSettings.plugins.bigcommerce.allowBypassQuery` to `true`.
|
|
21
|
+
*/
|
|
22
|
+
const isBypassQueryAllowed = () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return (((_b = (_a = zonosStore.checkoutSettings.plugins) === null || _a === void 0 ? void 0 : _a.bigcommerce) === null || _b === void 0 ? void 0 : _b.allowBypassQuery) === true);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Read an accepted `zBypass` query on the checkout page once, then remove it
|
|
28
|
+
* from the URL. A later call on that same URL returns the same answer.
|
|
29
|
+
*/
|
|
30
|
+
const readCheckoutZBypassQuery = () => {
|
|
31
|
+
const { pathname, search } = window.location;
|
|
32
|
+
if (consumedZBypassQuery &&
|
|
33
|
+
consumedZBypassQuery.pathname === pathname &&
|
|
34
|
+
consumedZBypassQuery.search === search) {
|
|
35
|
+
return consumedZBypassQuery.enabled;
|
|
36
|
+
}
|
|
37
|
+
const params = new URLSearchParams(search);
|
|
38
|
+
const accepted = isAcceptedZBypassQuery(params.get('zBypass'));
|
|
39
|
+
if (!accepted) {
|
|
40
|
+
consumedZBypassQuery = { enabled: false, pathname, search };
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
params.delete('zBypass');
|
|
44
|
+
const nextSearch = params.toString();
|
|
45
|
+
const hash = window.location.hash || '';
|
|
46
|
+
const nextUrl = `${pathname}${nextSearch ? `?${nextSearch}` : ''}${hash}`;
|
|
47
|
+
window.history.replaceState(window.history.state, document.title, nextUrl);
|
|
48
|
+
const enabled = isBypassQueryAllowed();
|
|
49
|
+
consumedZBypassQuery = {
|
|
50
|
+
enabled,
|
|
51
|
+
pathname,
|
|
52
|
+
search: window.location.search,
|
|
53
|
+
};
|
|
54
|
+
return enabled;
|
|
55
|
+
};
|
|
56
|
+
/** Clears the page-load query result. Tests use this between cases. */
|
|
57
|
+
export const resetBigCommerceCheckoutBypassCache = () => {
|
|
58
|
+
consumedZBypassQuery = null;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* True when this BigCommerce checkout page should skip address detection.
|
|
62
|
+
* That is only when zonos-settings allows the `zBypass` query and this
|
|
63
|
+
* checkout URL has an accepted value. Storefront pages are never bypassed, so
|
|
64
|
+
* the query stays in the URL until checkout. The query is removed once, and
|
|
65
|
+
* later calls on that checkout URL keep the same answer. Nothing is written
|
|
66
|
+
* to storage.
|
|
67
|
+
*/
|
|
68
|
+
export const isBigCommerceCheckoutBypassEnabled = () => {
|
|
69
|
+
var _a;
|
|
70
|
+
if (!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.isBigCommerce) || !isCheckoutPage()) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return readCheckoutZBypassQuery();
|
|
74
|
+
};
|
|
@@ -5,6 +5,7 @@ import { fetchBigCommerceCheckout, fetchCheckoutId, } from "./bigcommerceStorefr
|
|
|
5
5
|
import { buildBigcommerceRedirectUrl } from "./buildBigcommerceRedirectUrl";
|
|
6
6
|
import { checkBigCommerceBypassCustomerGroup } from "./checkBigCommerceBypassCustomerGroup";
|
|
7
7
|
import { checkBigCommerceForceLogin } from "./checkBigCommerceForceLogin";
|
|
8
|
+
import { isBigCommerceCheckoutBypassEnabled } from "./isBigCommerceCheckoutBypassEnabled";
|
|
8
9
|
import { isShippableCountry } from "./isShippableCountry";
|
|
9
10
|
import { log } from "../logging/log";
|
|
10
11
|
import { logError } from "../logging/logError";
|
|
@@ -108,6 +109,13 @@ export const watchImmediateBigcommerceDomesticCheckoutRedirect = ({ domesticRedi
|
|
|
108
109
|
if (!window.Zonos.isBigCommerce) {
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
112
|
+
// Only the native checkout page skips address detection. Storefront pages
|
|
113
|
+
// still run the domestic-session handoff below, and they do not consume
|
|
114
|
+
// a `zBypass` query, so the parameter can survive until `/checkout`.
|
|
115
|
+
if (window.location.pathname.includes('/checkout') &&
|
|
116
|
+
isBigCommerceCheckoutBypassEnabled()) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
111
119
|
/**
|
|
112
120
|
* Keep checking.
|
|
113
121
|
* @returns `true` if the caller should stop polling — either because the user
|
|
@@ -38,6 +38,10 @@ export const getZonosQaUrl = () => {
|
|
|
38
38
|
if (qaUrl === 'dev-elements') {
|
|
39
39
|
return 'https://dev.elements.zonos.com';
|
|
40
40
|
}
|
|
41
|
+
// The worker alias selects the API host only. Scripts stay on the normal CDN.
|
|
42
|
+
if (qaUrl === 'worker') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
41
45
|
const suffixDomain = 'preview.js.zonos.com';
|
|
42
46
|
const fullUrl = `https://${qaUrl}.${suffixDomain}`;
|
|
43
47
|
log(`[ZONOS-WARNING] using '${fullUrl}' for loading elements script`, 'warn');
|
|
@@ -80,10 +84,13 @@ export const getZonosQaUrlApi = () => {
|
|
|
80
84
|
if (!qaUrl) {
|
|
81
85
|
return null;
|
|
82
86
|
}
|
|
83
|
-
//
|
|
87
|
+
// Local API debugging. The worker host is a separate explicit alias.
|
|
84
88
|
if (qaUrl === 'dev-elements') {
|
|
85
89
|
return 'https://dev.demo.elements.zonos.com';
|
|
86
90
|
}
|
|
91
|
+
if (qaUrl === 'worker') {
|
|
92
|
+
return 'https://worker.iglobalstores.com';
|
|
93
|
+
}
|
|
87
94
|
// Only do this if `zonosQaUrlApi` is set, don't use zonosQaUrl
|
|
88
95
|
if (!_qaUrlApi) {
|
|
89
96
|
return null;
|
package/dist/esm/index.js
CHANGED
|
@@ -131,7 +131,7 @@ const getZonosQaUrl = () => {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
134
|
-
const cdnUrl = "https://v1.4.
|
|
134
|
+
const cdnUrl = "https://v1.4.2.js.zonos.com";
|
|
135
135
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
136
136
|
if (!qaUrl &&
|
|
137
137
|
(cdnUrl.includes('test.') ||
|
|
@@ -155,6 +155,10 @@ const getZonosQaUrl = () => {
|
|
|
155
155
|
if (qaUrl === 'dev-elements') {
|
|
156
156
|
return 'https://dev.elements.zonos.com';
|
|
157
157
|
}
|
|
158
|
+
// The worker alias selects the API host only. Scripts stay on the normal CDN.
|
|
159
|
+
if (qaUrl === 'worker') {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
158
162
|
const suffixDomain = 'preview.js.zonos.com';
|
|
159
163
|
const fullUrl = `https://${qaUrl}.${suffixDomain}`;
|
|
160
164
|
log(`[ZONOS-WARNING] using '${fullUrl}' for loading elements script`, 'warn');
|
|
@@ -416,10 +420,10 @@ const zonosLoadUrl = (() => {
|
|
|
416
420
|
return null;
|
|
417
421
|
})();
|
|
418
422
|
const startLoadTime = Date.now();
|
|
419
|
-
const ZONOS_URL = "https://v1.4.
|
|
420
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.
|
|
421
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.4.
|
|
422
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.
|
|
423
|
+
const ZONOS_URL = "https://v1.4.2.js.zonos.com";
|
|
424
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.2";
|
|
425
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.4.2";
|
|
426
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.2";
|
|
423
427
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
424
428
|
const GOOGLE_FONT_REGEX = /^https:\/\/fonts\.googleapis\.com/;
|
|
425
429
|
class Zonos {
|
|
@@ -437,7 +441,7 @@ Zonos.iframeLogType = typeof window !== 'undefined'
|
|
|
437
441
|
? new URLSearchParams(window.location.search).get('iframeLogType')
|
|
438
442
|
: null;
|
|
439
443
|
Zonos.isBigCommerce = false;
|
|
440
|
-
Zonos.releaseDate = "
|
|
444
|
+
Zonos.releaseDate = "1792599810755";
|
|
441
445
|
Zonos.isLegacyCheckout = false;
|
|
442
446
|
Zonos.googleAnalyticId = null;
|
|
443
447
|
Zonos.googleAnalyticReady = false;
|
|
@@ -462,7 +466,7 @@ Zonos.isNpm = true;
|
|
|
462
466
|
Zonos.zonosQaUrl = null;
|
|
463
467
|
Zonos.zonosQaUrlApi = null;
|
|
464
468
|
Zonos.trackEventLogs = [];
|
|
465
|
-
Zonos.version = `v${"1.4.
|
|
469
|
+
Zonos.version = `v${"1.4.2"}`;
|
|
466
470
|
Zonos.modeAlerted = false;
|
|
467
471
|
Zonos.cartData = null;
|
|
468
472
|
Zonos.paypal = null;
|
|
@@ -698,6 +698,76 @@ providedCountryCode) => {
|
|
|
698
698
|
return true;
|
|
699
699
|
};
|
|
700
700
|
|
|
701
|
+
const ZBYPASS_ON_VALUES = ['1', 'true', 'yes'];
|
|
702
|
+
/**
|
|
703
|
+
* Page-load result of reading the checkout `zBypass` query. Later calls on the
|
|
704
|
+
* same checkout URL reuse this so stripping the parameter does not change the
|
|
705
|
+
* answer.
|
|
706
|
+
*/
|
|
707
|
+
let consumedZBypassQuery = null;
|
|
708
|
+
const isCheckoutPage = () => {
|
|
709
|
+
return window.location.pathname.includes('/checkout');
|
|
710
|
+
};
|
|
711
|
+
const isAcceptedZBypassQuery = (rawValue) => {
|
|
712
|
+
if (rawValue === null) {
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
return ZBYPASS_ON_VALUES.includes(rawValue.trim().toLowerCase());
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* True only when zonos-settings set
|
|
719
|
+
* `checkoutSettings.plugins.bigcommerce.allowBypassQuery` to `true`.
|
|
720
|
+
*/
|
|
721
|
+
const isBypassQueryAllowed = () => {
|
|
722
|
+
var _a, _b;
|
|
723
|
+
return (((_b = (_a = zonosStore.checkoutSettings.plugins) === null || _a === void 0 ? void 0 : _a.bigcommerce) === null || _b === void 0 ? void 0 : _b.allowBypassQuery) === true);
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* Read an accepted `zBypass` query on the checkout page once, then remove it
|
|
727
|
+
* from the URL. A later call on that same URL returns the same answer.
|
|
728
|
+
*/
|
|
729
|
+
const readCheckoutZBypassQuery = () => {
|
|
730
|
+
const { pathname, search } = window.location;
|
|
731
|
+
if (consumedZBypassQuery &&
|
|
732
|
+
consumedZBypassQuery.pathname === pathname &&
|
|
733
|
+
consumedZBypassQuery.search === search) {
|
|
734
|
+
return consumedZBypassQuery.enabled;
|
|
735
|
+
}
|
|
736
|
+
const params = new URLSearchParams(search);
|
|
737
|
+
const accepted = isAcceptedZBypassQuery(params.get('zBypass'));
|
|
738
|
+
if (!accepted) {
|
|
739
|
+
consumedZBypassQuery = { enabled: false, pathname, search };
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
params.delete('zBypass');
|
|
743
|
+
const nextSearch = params.toString();
|
|
744
|
+
const hash = window.location.hash || '';
|
|
745
|
+
const nextUrl = `${pathname}${nextSearch ? `?${nextSearch}` : ''}${hash}`;
|
|
746
|
+
window.history.replaceState(window.history.state, document.title, nextUrl);
|
|
747
|
+
const enabled = isBypassQueryAllowed();
|
|
748
|
+
consumedZBypassQuery = {
|
|
749
|
+
enabled,
|
|
750
|
+
pathname,
|
|
751
|
+
search: window.location.search,
|
|
752
|
+
};
|
|
753
|
+
return enabled;
|
|
754
|
+
};
|
|
755
|
+
/**
|
|
756
|
+
* True when this BigCommerce checkout page should skip address detection.
|
|
757
|
+
* That is only when zonos-settings allows the `zBypass` query and this
|
|
758
|
+
* checkout URL has an accepted value. Storefront pages are never bypassed, so
|
|
759
|
+
* the query stays in the URL until checkout. The query is removed once, and
|
|
760
|
+
* later calls on that checkout URL keep the same answer. Nothing is written
|
|
761
|
+
* to storage.
|
|
762
|
+
*/
|
|
763
|
+
const isBigCommerceCheckoutBypassEnabled = () => {
|
|
764
|
+
var _a;
|
|
765
|
+
if (!((_a = window.Zonos) === null || _a === void 0 ? void 0 : _a.isBigCommerce) || !isCheckoutPage()) {
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
return readCheckoutZBypassQuery();
|
|
769
|
+
};
|
|
770
|
+
|
|
701
771
|
const FALLBACK_SHIP_TO_COUNTRY_SELECTOR = 'select[name="shippingAddress.countryCode"]';
|
|
702
772
|
/**
|
|
703
773
|
* Native BigCommerce shipping-step "Continue" button. Clicking it commits the
|
|
@@ -798,6 +868,13 @@ const watchImmediateBigcommerceDomesticCheckoutRedirect = ({ domesticRedirectedB
|
|
|
798
868
|
if (!window.Zonos.isBigCommerce) {
|
|
799
869
|
return;
|
|
800
870
|
}
|
|
871
|
+
// Only the native checkout page skips address detection. Storefront pages
|
|
872
|
+
// still run the domestic-session handoff below, and they do not consume
|
|
873
|
+
// a `zBypass` query, so the parameter can survive until `/checkout`.
|
|
874
|
+
if (window.location.pathname.includes('/checkout') &&
|
|
875
|
+
isBigCommerceCheckoutBypassEnabled()) {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
801
878
|
/**
|
|
802
879
|
* Keep checking.
|
|
803
880
|
* @returns `true` if the caller should stop polling — either because the user
|
package/dist/esm-es5/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var n=new URL(e).searchParams;var o=n.get("zonosQaUrl");if(!o){return null}var t
|
|
|
54
54
|
* When developing, if the script load is from `dev.elements.zonos.com`,
|
|
55
55
|
* it would load script from that same domain instead of loading from cdn
|
|
56
56
|
*/
|
|
57
|
-
var e=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||e){return null}var n=extractZonosQaUrl(window.location.href);var o="https://v1.4.
|
|
57
|
+
var e=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||e){return null}var n=extractZonosQaUrl(window.location.href);var o="https://v1.4.2.js.zonos.com";
|
|
58
58
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
59
59
|
if(!n&&(o.includes("test.")||
|
|
60
60
|
// Vercel git domain
|
|
@@ -62,7 +62,9 @@ o.includes("test-"))){return o}
|
|
|
62
62
|
// when local demo app is running, it needs to use the local dev script unless the qaUrl is set
|
|
63
63
|
if(!n&&["dev.demo.elements.zonos.com","dev.checkout.elements.zonos.com","dev.storybook.elements.zonos.com"].includes(window.location.hostname)){return"https://dev.elements.zonos.com"}if(!n){return null}
|
|
64
64
|
// If the qaUrl, use the dev-elements domain to forward the request to the dev server to quickly debug the issue
|
|
65
|
-
if(n==="dev-elements"){return"https://dev.elements.zonos.com"}
|
|
65
|
+
if(n==="dev-elements"){return"https://dev.elements.zonos.com"}
|
|
66
|
+
// The worker alias selects the API host only. Scripts stay on the normal CDN.
|
|
67
|
+
if(n==="worker"){return null}var t="preview.js.zonos.com";var r="https://".concat(n,".").concat(t);log("[ZONOS-WARNING] using '".concat(r,"' for loading elements script"),"warn");
|
|
66
68
|
// request to the url and check if the request has an error
|
|
67
69
|
void fetch(r).then((function(){
|
|
68
70
|
// cleanup checkout session to avoid using the prod session in preview domain
|
|
@@ -90,22 +92,22 @@ if(!hasCheckoutCartCallback()){return null}return zonosStripeLoadScript(null)}))
|
|
|
90
92
|
console.warn(e)}}));var zonosLoadStripe=function(){var e=[];for(var n=0;n<arguments.length;n++){e[n]=arguments[n]}return __awaiter(void 0,void 0,void 0,(function(){var n,o,t,r;return __generator(this,(function(i){switch(i.label){case 0:loadCalled=true;o=Date.now();return[4/*yield*/,stripePromise];case 1:if(!((n=i.sent())!==null&&n!==void 0))return[3/*break*/,2];r=n;return[3/*break*/,4];case 2:return[4/*yield*/,zonosStripeLoadScript(null)];case 3:r=i.sent();i.label=4;case 4:t=r;return[2/*return*/,initStripe(t,e,o)]}}))}))};var TEMP_CART_ID_QUERY_PARAM="tempCartUUID";
|
|
91
93
|
/**
|
|
92
94
|
* Simple function to get the cart id from the query param.
|
|
93
|
-
*/var getCartIdFromQueryParam=function(){var e=new URLSearchParams(window.location.search);var n=e.get(TEMP_CART_ID_QUERY_PARAM);return n};var getCartInfoById=function(e){return __awaiter(void 0,[e],void 0,(function(e){var n,o,t,r,i,a,s,u,c;var
|
|
95
|
+
*/var getCartIdFromQueryParam=function(){var e=new URLSearchParams(window.location.search);var n=e.get(TEMP_CART_ID_QUERY_PARAM);return n};var getCartInfoById=function(e){return __awaiter(void 0,[e],void 0,(function(e){var n,o,t,r,i,a,s,u,c;var l=e.cartId,d=e.retries;return __generator(this,(function(e){switch(e.label){case 0:n=getIsTestMode();o=getGenericSettingsOverride();t=getAbandonedCartRenewTokenValue()||undefined;r=new URLSearchParams;if(o.overrideShouldEnabledCustomAddress){r.set("overrideShouldEnabledCustomAddress",o.overrideShouldEnabledCustomAddress)}return[4/*yield*/,handleFetch("/api/zonos-elements/get-cart?".concat(r.toString()),{body:{isTestMode:n,renewCartExpirationToken:t,tempCartUUID:l},headers:{"Content-Type":"application/json"},method:"POST"})];case 1:i=e.sent(),a=i.errors,s=i.json,u=i.zonosMode;c=!s||a.length;if(!(c&&d))return[3/*break*/,3];log("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:d});
|
|
94
96
|
// wait 1 second before retrying
|
|
95
97
|
return[4/*yield*/,new Promise((function(e){return setTimeout(e,500)}))];case 2:
|
|
96
98
|
// wait 1 second before retrying
|
|
97
|
-
e.sent();return[2/*return*/,getCartInfoById({cartId:
|
|
99
|
+
e.sent();return[2/*return*/,getCartInfoById({cartId:l,retries:d-1})];case 3:if(c){return[2/*return*/,null]}return[2/*return*/,Object.assign(Object.assign({},s),{zonosMode:u})]}}))}))};var setupCartDataWithSettings=function(e){return __awaiter(void 0,void 0,void 0,(function(){var n,o,t,r;return __generator(this,(function(i){switch(i.label){case 0:n=_getIsValidCartId(e),o=n.isDgsCartId,t=n.isLegacyCartId;if(!t&&!o){logError("[ZONOS - loadZonos] invalid cart id");return[2/*return*/,null]}return[4/*yield*/,getCartInfoById({cartId:e,retries:5})];case 1:r=i.sent();log("[ZONOS - loadZonos] getting temp cart data","info",r);if(!r){logError("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process.");return[2/*return*/,null]}window.Zonos.storeId=r.cartData.storeId;window.Zonos.zonosApiKey=r.cartData.credentialToken;window.Zonos.zonosMode=r.zonosMode;return[2/*return*/,{cartData:r.cartData,settings:r.settings,storeFavicon:r.storeFaviconUrl,storeId:r.cartData.storeId,storeLogo:r.storeLogoUrl,zonosApiKey:r.cartData.credentialToken}]}}))}))};var _a;
|
|
98
100
|
/**
|
|
99
101
|
* Get the load version and url based on the loadScriptSrc, if the domain that used to load `zonos.js` is in white listed domains, use currentLoadScriptUrl as the load url instead, if zonosQaUrl exists, it would also fall under the white listed domain
|
|
100
|
-
*/var zonosLoadUrl=function(){if(typeof document==="undefined"){return null}var e=document.querySelector('script[src*="/zonos.js"]');var n=checkIfLoadVersionDomain({loadScriptSrc:e===null||e===void 0?void 0:e.src}),o=n.currentLoadScriptUrl,t=n.isWhiteListed;if(t){return o}return null}();var startLoadTime=Date.now();var ZONOS_URL="https://v1.4.
|
|
102
|
+
*/var zonosLoadUrl=function(){if(typeof document==="undefined"){return null}var e=document.querySelector('script[src*="/zonos.js"]');var n=checkIfLoadVersionDomain({loadScriptSrc:e===null||e===void 0?void 0:e.src}),o=n.currentLoadScriptUrl,t=n.isWhiteListed;if(t){return o}return null}();var startLoadTime=Date.now();var ZONOS_URL="https://v1.4.2.js.zonos.com";var JS_DELIVR_ZONOS_URL=zonosLoadUrl||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.2";var UNPKG_ZONOS_URL="https://unpkg.com/@zonos/elements@1.4.2";var CDNJS_ZONOS_URL="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.2";var GOOGLE_FONT_URL="https://fonts.googleapis.com";var GOOGLE_FONT_REGEX=/^https:\/\/fonts\.googleapis\.com/;var Zonos=/** @class */function(){function e(){}return e}();_a=Zonos;Zonos.doneInit=false;Zonos.cartSettings=null;
|
|
101
103
|
// if query 'zonosDebug=1' param from url, debug mode is on
|
|
102
|
-
Zonos.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);Zonos.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);Zonos._paypalMockResponse=null;Zonos.iframeLogType=typeof window!=="undefined"?new URLSearchParams(window.location.search).get("iframeLogType"):null;Zonos.isBigCommerce=false;Zonos.releaseDate="
|
|
104
|
+
Zonos.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);Zonos.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);Zonos._paypalMockResponse=null;Zonos.iframeLogType=typeof window!=="undefined"?new URLSearchParams(window.location.search).get("iframeLogType"):null;Zonos.isBigCommerce=false;Zonos.releaseDate="1792599810755";Zonos.isLegacyCheckout=false;Zonos.googleAnalyticId=null;Zonos.googleAnalyticReady=false;Zonos.facebookPixelId=null;Zonos.facebookPixelReady=false;Zonos.startLoadTime=startLoadTime;Zonos.domain=typeof window!=="undefined"?// domain that embeds the iframe
|
|
103
105
|
window.location!=window.parent.location&&document.referrer||
|
|
104
106
|
// current domain
|
|
105
107
|
document.location.hostname:"";Zonos.showBaseForeign=typeof window!=="undefined"&&window.location.search.includes("zonosShowBaseForeign");Zonos.overrideUseCustomAddressForm=false;Zonos.isCollect=false;Zonos.isInvoice=false;
|
|
106
108
|
/**
|
|
107
109
|
* By default, the package will load from npm
|
|
108
|
-
*/Zonos.isNpm=true;Zonos.zonosQaUrl=null;Zonos.zonosQaUrlApi=null;Zonos.trackEventLogs=[];Zonos.version="v".concat("1.4.
|
|
110
|
+
*/Zonos.isNpm=true;Zonos.zonosQaUrl=null;Zonos.zonosQaUrlApi=null;Zonos.trackEventLogs=[];Zonos.version="v".concat("1.4.2");Zonos.modeAlerted=false;Zonos.cartData=null;Zonos.paypal=null;Zonos.zonosMode=null;Zonos.IframeService=IframeService;Zonos.getCurrentTimestamp=function(){return(new Date).getTime()};Zonos.zonosController=null;Zonos.loadTimeApiInfoList=[];Zonos.logIntervalId=null;Zonos.init=function(e){return __awaiter(void 0,void 0,void 0,(function(){var n,o,t,r,i,a,s,u,c,l,d,f,v,m,_;return __generator(this,(function(p){switch(p.label){case 0:n=e.appearance,o=e.checkoutSettings,t=e.currencyConverter,r=e.helloSettings,i=e.onCountryChange,a=e.overrideCurrencyFormat,s=e.storeId,u=e.zonosApiKey;_a.cartId=getCartIdFromQueryParam();
|
|
109
111
|
// Expose the checkout cart callbacks on the global so Stripe loading can be
|
|
110
112
|
// gated on whether at least one of them is configured.
|
|
111
113
|
_a.createCartId=o===null||o===void 0?void 0:o.createCartId;
|
|
@@ -116,13 +118,13 @@ return[2/*return*/]}log("====== ZONOS DEBUG MODE: on (".concat(_a.version,") ===
|
|
|
116
118
|
// When not in iframe, providers are ready (gtag/fbq work directly). When in iframe, relay sets these after parent configures.
|
|
117
119
|
if(typeof window!=="undefined"&&window.parent===window){_a.googleAnalyticReady=true;_a.facebookPixelReady=true}if(!_a.isNpm)return[3/*break*/,4];log("====== ZONOS LOADING FROM NPM ======");c=getZonosQaUrl();
|
|
118
120
|
// if zonosQaUrl is available, inject the script from the zonosQaUrl and then call init again
|
|
119
|
-
if(c&&!window.isZonosPreview){log('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(c," ======"),"info");
|
|
121
|
+
if(c&&!window.isZonosPreview){log('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(c," ======"),"info");l=document.createElement("script");l.src="".concat(c,"/dist/scripts/zonos.js");document.head.appendChild(l);l.addEventListener("load",(function(){window.Zonos.isNpm=_a.isNpm;window.Zonos.isBigCommerce=_a.isBigCommerce;window.Zonos.isLegacyCheckout=_a.isLegacyCheckout;window.Zonos.zonosMode=_a.zonosMode;
|
|
120
122
|
// call init again after the script is loaded
|
|
121
|
-
void window.Zonos.init(e)}));
|
|
123
|
+
void window.Zonos.init(e)}));l.addEventListener("error",(function(){alert('[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: '.concat(c))}));
|
|
122
124
|
// Set so won't inject the preview script again
|
|
123
125
|
window.isZonosPreview=true;return[2/*return*/]}
|
|
124
126
|
// zonosApiKey is required if tempCartUUID in query params are not provided
|
|
125
|
-
if(!u&&!_a.cartId){logError("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2/*return*/]}if(!(!_a.cartData&&_a.cartId))return[3/*break*/,2];log("Initialize cart data");return[4/*yield*/,setupCartDataWithSettings(_a.cartId)];case 1:
|
|
127
|
+
if(!u&&!_a.cartId){logError("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2/*return*/]}if(!(!_a.cartData&&_a.cartId))return[3/*break*/,2];log("Initialize cart data");return[4/*yield*/,setupCartDataWithSettings(_a.cartId)];case 1:d=p.sent();if(!d){logError("Failed to get cart data");return[2/*return*/]}_a.cartData=d.cartData;_a.zonosApiKey=d.zonosApiKey;_a.cartSettings=d.settings;p.label=2;case 2:return[4/*yield*/,getWithTestPublicCredential()];case 3:f=p.sent();if(f){_a.zonosApiKey=f}p.label=4;case 4:v=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");m=_a.cartId&&_a.cartData||!!v;
|
|
126
128
|
// inject hidden button to body to trigger checkout right away if we have cartData or stripe client secret
|
|
127
129
|
if(m){log("Cart data or stripe client secret is available, inject hidden button and trigger checkout");_=document.createElement("button");_.style.display="none";_.id="".concat(checkoutHiddenBtnSelector);document.body.appendChild(_)}log("init zonos");_a.restoreNativeBrowserFunctions();
|
|
128
130
|
// inject custom script for hosted checkout if can find it in metadata
|