@zonos/elements 1.3.258 → 1.3.259
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 +7 -7
- package/dist/cjs/zonos-checkout.cjs.entry.js +439 -14
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +6 -6
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +72 -0
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +6 -6
- package/dist/collection/components/utils/checkout/bigcommerceStorefrontApi.js +6 -0
- package/dist/collection/components/utils/checkout/buildBigcommerceLoginUrl.js +65 -0
- package/dist/collection/components/utils/checkout/checkBigCommerceBypassCustomerGroup.js +12 -7
- package/dist/collection/components/utils/checkout/checkBigCommerceForceLogin.js +116 -0
- package/dist/collection/components/utils/checkout/fetchBigCommerceCheckoutSettings.js +92 -0
- package/dist/collection/components/utils/checkout/fixBigCommerceLoginCreateAccountLink.js +53 -0
- package/dist/collection/components/utils/checkout/watchImmediateBigcommerceDomesticCheckoutRedirect.js +40 -7
- package/dist/collection/types/checkout/api/BigCommerceCheckoutSettings.js +1 -0
- package/dist/collection/types/generated/graphql.frontend.types.js +2 -0
- package/dist/collection/types/generated/graphql.internal.types.js +39 -0
- package/dist/collection/types/index.js +1 -0
- package/dist/esm/index.js +7 -7
- package/dist/esm/zonos-checkout.entry.js +440 -15
- package/dist/esm/zonos-hello-dialog.entry.js +6 -6
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/scripts/index.d.ts +21 -5
- 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/checkout/zonos-checkout/zonos-checkout.d.ts +16 -0
- package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
- package/dist/types/components/utils/checkout/bigcommerceStorefrontApi.d.ts +6 -0
- package/dist/types/components/utils/checkout/buildBigcommerceLoginUrl.d.ts +27 -0
- package/dist/types/components/utils/checkout/checkBigCommerceBypassCustomerGroup.d.ts +12 -0
- package/dist/types/components/utils/checkout/checkBigCommerceForceLogin.d.ts +50 -0
- package/dist/types/components/utils/checkout/fetchBigCommerceCheckoutSettings.d.ts +18 -0
- package/dist/types/components/utils/checkout/fixBigCommerceLoginCreateAccountLink.d.ts +17 -0
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +6 -5
- package/dist/types/types/checkout/CheckoutConfig.d.ts +9 -0
- package/dist/types/types/checkout/api/BigCommerceCheckoutSettings.d.ts +12 -0
- package/dist/types/types/generated/graphql.frontend.types.d.ts +3 -1
- package/dist/types/types/generated/graphql.frontend.types.ts +3 -1
- package/dist/types/types/generated/graphql.internal.types.d.ts +58 -9
- package/dist/types/types/generated/graphql.internal.types.ts +69 -9
- package/dist/types/types/index.d.ts +1 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-29b60bf3.system.js +1 -1
- package/dist/zonos-elements/p-439dc620.system.entry.js +1 -0
- package/dist/zonos-elements/{p-5182e492.entry.js → p-9cbac993.entry.js} +1 -1
- package/dist/zonos-elements/{p-867d05d7.system.js → p-cc645667.system.js} +1 -1
- package/dist/zonos-elements/p-d13120f6.entry.js +1 -0
- package/dist/zonos-elements/{p-9c97671b.system.entry.js → p-f4e54f09.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/zonos-elements/p-50b32476.system.entry.js +0 -1
- package/dist/zonos-elements/p-733f118d.entry.js +0 -1
|
@@ -4,7 +4,7 @@ import { p as paypalStoreHasPaypalEnabled, a as paypalStore, b as paypalInitScri
|
|
|
4
4
|
import { f as filterValidTests, l as localizationStore, a as localizationStoreUpdateSelectedCountryCode, g as getZCountryUrlParam, s as storageStore, V as VARIANT_TEST_KEY_EXPIRATION, b as storageStoreSetEnabledVariantTestKeys, t as translate, c as localizationStoreOnChange, d as currencyFormat } from './localization-76ce3e29.js';
|
|
5
5
|
import { z as zonosStore, g as getZonosStoreTheme, m as mergeConfig } from './zonosStore-f1d45eac.js';
|
|
6
6
|
import { b as buildCartItemsByTempCart } from './buildCartItemsByTempCart-a117f75d.js';
|
|
7
|
-
import { h as handleFetch, g as getIsTestMode, l as logError,
|
|
7
|
+
import { h as handleFetch, g as getIsTestMode, l as logError, j as jsonParse, b as getAdditionalLogMetadata, s as sendErrorLog, a as getIsStagingMode, i as isCheckoutMobile } from './handleFetch-a844cac1.js';
|
|
8
8
|
import { u as updateCheckoutSessionAttributes } from './updateCheckoutSessionAttributes-8f3f932e.js';
|
|
9
9
|
import { l as log, g as getElapsedTime, b as allLogs } from './VarianceTest-572cecf5.js';
|
|
10
10
|
import { _ as _getIsValidCartId, c as checkoutHiddenBtnSelector, a as checkoutHiddenInternationalBtnSelector, d as domesticRedirectedBtnSelector, g as getAbandonedCartRenewTokenValue } from './CheckoutConfig-724d7bae.js';
|
|
@@ -93,6 +93,71 @@ const buildCartUrl = ({ cartId, checkoutSessionId, customerAddress1, customerAdd
|
|
|
93
93
|
return `${hostedCheckoutUrl}?${urlParams.toString()}`;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* The query flag that BigCommerce carries back to `cart.php` after the
|
|
98
|
+
* shopper logs in. When present, Zonos-elements knows to resume the
|
|
99
|
+
* international checkout flow instead of letting BC's native cart UX
|
|
100
|
+
* take over.
|
|
101
|
+
*/
|
|
102
|
+
const BIGCOMMERCE_INTERNATIONAL_CHECKOUT_FLAG = 'isInternationalCheckout';
|
|
103
|
+
/**
|
|
104
|
+
* Build the `from` query value handed to BigCommerce's `/login.php` so that
|
|
105
|
+
* after a successful login the shopper lands back on `cart.php` with the
|
|
106
|
+
* `isInternationalCheckout=true` flag set (plus any `zonosTestMode` /
|
|
107
|
+
* `zonosQaUrl` / `zonosQaUrlApi` that were on the current URL, so the
|
|
108
|
+
* preview build / API host / test credentials carry through the round trip).
|
|
109
|
+
*/
|
|
110
|
+
const buildFromCartPath = () => {
|
|
111
|
+
const params = new URLSearchParams();
|
|
112
|
+
params.set(BIGCOMMERCE_INTERNATIONAL_CHECKOUT_FLAG, 'true');
|
|
113
|
+
const currentParams = new URLSearchParams(window.location.search);
|
|
114
|
+
const zonosQaUrl = currentParams.get('zonosQaUrl');
|
|
115
|
+
if (zonosQaUrl) {
|
|
116
|
+
params.set('zonosQaUrl', zonosQaUrl);
|
|
117
|
+
}
|
|
118
|
+
const zonosQaUrlApi = currentParams.get('zonosQaUrlApi');
|
|
119
|
+
if (zonosQaUrlApi) {
|
|
120
|
+
params.set('zonosQaUrlApi', zonosQaUrlApi);
|
|
121
|
+
}
|
|
122
|
+
if (getIsTestMode()) {
|
|
123
|
+
params.set('zonosTestMode', '1');
|
|
124
|
+
}
|
|
125
|
+
return `cart.php?${params.toString()}`;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Build an absolute URL to BigCommerce's `/login.php` with the
|
|
129
|
+
* `from=cart.php?isInternationalCheckout=true` round-trip encoded so the
|
|
130
|
+
* shopper resumes Zonos international checkout after authenticating.
|
|
131
|
+
*
|
|
132
|
+
* Preserves `zonosTestMode` / `zonosQaUrl` / `zonosQaUrlApi` from the current
|
|
133
|
+
* URL across the redirect — the login round trip leaves BC's frontend, so
|
|
134
|
+
* without this the returning `cart.php` would drop back to the production
|
|
135
|
+
* build / API host.
|
|
136
|
+
*/
|
|
137
|
+
const buildBigcommerceLoginUrl = ({ action } = {}) => {
|
|
138
|
+
const url = new URL('/login.php', window.location.origin);
|
|
139
|
+
if (action) {
|
|
140
|
+
url.searchParams.set('action', action);
|
|
141
|
+
}
|
|
142
|
+
const currentParams = new URLSearchParams(window.location.search);
|
|
143
|
+
// set zonosQaUrl from the current URL
|
|
144
|
+
const zonosQaUrl = currentParams.get('zonosQaUrl');
|
|
145
|
+
if (zonosQaUrl) {
|
|
146
|
+
url.searchParams.set('zonosQaUrl', zonosQaUrl);
|
|
147
|
+
}
|
|
148
|
+
// set zonosQaUrlApi from the current URL
|
|
149
|
+
const zonosQaUrlApi = currentParams.get('zonosQaUrlApi');
|
|
150
|
+
if (zonosQaUrlApi) {
|
|
151
|
+
url.searchParams.set('zonosQaUrlApi', zonosQaUrlApi);
|
|
152
|
+
}
|
|
153
|
+
// set zonosTestMode from the current URL
|
|
154
|
+
if (getIsTestMode()) {
|
|
155
|
+
url.searchParams.set('zonosTestMode', '1');
|
|
156
|
+
}
|
|
157
|
+
url.searchParams.set('from', buildFromCartPath());
|
|
158
|
+
return url.toString();
|
|
159
|
+
};
|
|
160
|
+
|
|
96
161
|
/**
|
|
97
162
|
* Build an absolute redirect URL used by the BigCommerce checkout flows to
|
|
98
163
|
* navigate between the BC native `/checkout` page and the Zonos international
|
|
@@ -165,6 +230,12 @@ const fetchBigCommerceCheckout = async (checkoutId) => {
|
|
|
165
230
|
return null;
|
|
166
231
|
}
|
|
167
232
|
};
|
|
233
|
+
/**
|
|
234
|
+
* Whether the BigCommerce shopper is already logged in. We key off the
|
|
235
|
+
* customer's numeric `id` since the storefront API populates it only for
|
|
236
|
+
* authenticated sessions (guest checkouts have an empty `customer` object).
|
|
237
|
+
*/
|
|
238
|
+
const isBigCommerceCustomerLoggedIn = (checkout) => { var _a; return !!((_a = checkout === null || checkout === void 0 ? void 0 : checkout.customer) === null || _a === void 0 ? void 0 : _a.id); };
|
|
168
239
|
|
|
169
240
|
const DEFAULT_RESULT = {
|
|
170
241
|
customerGroupId: null,
|
|
@@ -174,7 +245,7 @@ const DEFAULT_RESULT = {
|
|
|
174
245
|
* Performs the actual fetch logic to determine if the customer
|
|
175
246
|
* belongs to a bypass group.
|
|
176
247
|
*/
|
|
177
|
-
const fetchBypassOutcome = async () => {
|
|
248
|
+
const fetchBypassOutcome = async (preFetched) => {
|
|
178
249
|
var _a, _b, _c, _d;
|
|
179
250
|
// Only relevant for BigCommerce stores — permanent no-op on other platforms
|
|
180
251
|
if (!window.Zonos.isBigCommerce) {
|
|
@@ -191,8 +262,11 @@ const fetchBypassOutcome = async () => {
|
|
|
191
262
|
// Mark as inconclusive so a later caller retries after config loads.
|
|
192
263
|
return { conclusive: false, result: DEFAULT_RESULT };
|
|
193
264
|
}
|
|
194
|
-
// Fetch customer group from BigCommerce Storefront API
|
|
195
|
-
|
|
265
|
+
// Fetch customer group from BigCommerce Storefront API — or reuse
|
|
266
|
+
// caller-supplied data when available.
|
|
267
|
+
const checkoutId = preFetched
|
|
268
|
+
? preFetched.checkoutId
|
|
269
|
+
: await fetchCheckoutId();
|
|
196
270
|
if (!checkoutId) {
|
|
197
271
|
// No active cart yet — inconclusive. Common on fresh sessions where
|
|
198
272
|
// `initBigCommerceBypassCheck` runs before the user has added anything
|
|
@@ -200,7 +274,9 @@ const fetchBypassOutcome = async () => {
|
|
|
200
274
|
log('BigCommerce bypass check: no active cart yet, will retry on next call', 'info');
|
|
201
275
|
return { conclusive: false, result: DEFAULT_RESULT };
|
|
202
276
|
}
|
|
203
|
-
const checkout =
|
|
277
|
+
const checkout = preFetched
|
|
278
|
+
? preFetched.checkout
|
|
279
|
+
: await fetchBigCommerceCheckout(checkoutId);
|
|
204
280
|
if (!checkout) {
|
|
205
281
|
// API call failed (network error, non-200, etc.) — inconclusive.
|
|
206
282
|
// Caching this would permanently disable bypass for the session if
|
|
@@ -234,8 +310,8 @@ const fetchBypassOutcome = async () => {
|
|
|
234
310
|
* cart or after settings finish loading).
|
|
235
311
|
*/
|
|
236
312
|
let bypassCheckPromise = null;
|
|
237
|
-
const startBypassCheck = () => {
|
|
238
|
-
const outcomePromise = fetchBypassOutcome();
|
|
313
|
+
const startBypassCheck = (preFetched) => {
|
|
314
|
+
const outcomePromise = fetchBypassOutcome(preFetched);
|
|
239
315
|
const resultPromise = outcomePromise.then(({ conclusive, result }) => {
|
|
240
316
|
if (!conclusive && bypassCheckPromise === resultPromise) {
|
|
241
317
|
// Invalidate cache so the next caller performs a fresh fetch.
|
|
@@ -281,11 +357,259 @@ const initBigCommerceBypassCheck = () => {
|
|
|
281
357
|
*/
|
|
282
358
|
const checkBigCommerceBypassCustomerGroup = async (options = {}) => {
|
|
283
359
|
if (options.forceRefresh || !bypassCheckPromise) {
|
|
284
|
-
return startBypassCheck();
|
|
360
|
+
return startBypassCheck(options.preFetched);
|
|
285
361
|
}
|
|
286
362
|
return bypassCheckPromise;
|
|
287
363
|
};
|
|
288
364
|
|
|
365
|
+
const EMPTY = { guestCheckoutType: null };
|
|
366
|
+
/**
|
|
367
|
+
* BigCommerce's `/checkouts/settings` values almost never change after a
|
|
368
|
+
* merchant's initial setup, so we persist the result in `localStorage` and
|
|
369
|
+
* reuse it across page loads up to this TTL. Short enough that if the
|
|
370
|
+
* merchant flips `guest_checkout_type` the change still propagates within
|
|
371
|
+
* an hour.
|
|
372
|
+
*/
|
|
373
|
+
const CACHE_TTL_MS = 60 * 60 * 1000;
|
|
374
|
+
const CACHE_KEY = 'zonos--bc-checkout-settings';
|
|
375
|
+
const readFromCache = (storeHash) => {
|
|
376
|
+
try {
|
|
377
|
+
const raw = window.localStorage.getItem(CACHE_KEY);
|
|
378
|
+
if (!raw) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
const parsed = jsonParse(raw);
|
|
382
|
+
if (!parsed) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
// Different store on the same origin (e.g. zonosQaUrl preview) — ignore.
|
|
386
|
+
if (parsed.storeHash !== storeHash) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
if (parsed.expiresAt < Date.now()) {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
return { guestCheckoutType: parsed.guestCheckoutType };
|
|
393
|
+
}
|
|
394
|
+
catch (_a) {
|
|
395
|
+
// localStorage access can throw in blocked-storage contexts (Safari
|
|
396
|
+
// private mode, cross-origin iframes) — treat as a cache miss so the
|
|
397
|
+
// network fallback runs.
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
const writeToCache = (storeHash, result) => {
|
|
402
|
+
try {
|
|
403
|
+
const payload = {
|
|
404
|
+
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
405
|
+
guestCheckoutType: result.guestCheckoutType,
|
|
406
|
+
storeHash,
|
|
407
|
+
};
|
|
408
|
+
window.localStorage.setItem(CACHE_KEY, JSON.stringify(payload));
|
|
409
|
+
}
|
|
410
|
+
catch (_a) {
|
|
411
|
+
// localStorage can be disabled / quota-exceeded in some browser contexts
|
|
412
|
+
// (private mode, cross-origin iframes) — drop silently since caching
|
|
413
|
+
// is only an optimization.
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Fetch the merchant's BigCommerce `/checkouts/settings` (via the demo-app
|
|
418
|
+
* proxy) so we can inspect `guest_checkout_type` from the storefront. The
|
|
419
|
+
* Store API is auth-gated, which is why we don't call it directly.
|
|
420
|
+
*
|
|
421
|
+
* Results are cached in `localStorage` for `CACHE_TTL_MS` so navigations
|
|
422
|
+
* inside the same store don't all pay the proxy round trip — the setting
|
|
423
|
+
* is merchant-level and rarely changes.
|
|
424
|
+
*/
|
|
425
|
+
const fetchBigCommerceCheckoutSettings = async () => {
|
|
426
|
+
var _a;
|
|
427
|
+
if (!window.Zonos.isBigCommerce) {
|
|
428
|
+
return EMPTY;
|
|
429
|
+
}
|
|
430
|
+
const storeHash = (_a = zonosStore.checkoutSettings.bigCommerceConfig) === null || _a === void 0 ? void 0 : _a.storeHash;
|
|
431
|
+
if (!storeHash) {
|
|
432
|
+
log('BigCommerce checkout settings: no storeHash provided — skipping fetch', 'info');
|
|
433
|
+
return EMPTY;
|
|
434
|
+
}
|
|
435
|
+
const cached = readFromCache(storeHash);
|
|
436
|
+
if (cached) {
|
|
437
|
+
return cached;
|
|
438
|
+
}
|
|
439
|
+
const { errors, json } = await handleFetch('/api/bigcommerce/checkout-settings', {
|
|
440
|
+
body: { storeHash },
|
|
441
|
+
method: 'POST',
|
|
442
|
+
});
|
|
443
|
+
if (errors.length || !json) {
|
|
444
|
+
log('BigCommerce checkout settings: proxy call failed, falling back to guest-allowed behavior', 'info');
|
|
445
|
+
return EMPTY;
|
|
446
|
+
}
|
|
447
|
+
const result = {
|
|
448
|
+
guestCheckoutType: json.guestCheckoutType,
|
|
449
|
+
};
|
|
450
|
+
writeToCache(storeHash, result);
|
|
451
|
+
return result;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const SKIP = {
|
|
455
|
+
redirectUrl: null,
|
|
456
|
+
shouldForceLogin: false,
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Session cache for the merchant-level "does BC require login?" answer.
|
|
460
|
+
* Hitting `/checkouts/settings` on every checkout open would add a visible
|
|
461
|
+
* round trip to the hot path, so we resolve it once and reuse — the setting
|
|
462
|
+
* is configured at the store level and very rarely changes.
|
|
463
|
+
*
|
|
464
|
+
* `null` means we haven't kicked off the fetch yet; the promise holds the
|
|
465
|
+
* eventual boolean so multiple concurrent callers deduplicate.
|
|
466
|
+
*/
|
|
467
|
+
let storeRequiresLoginPromise = null;
|
|
468
|
+
const resolveStoreRequiresLogin = () => {
|
|
469
|
+
if (!storeRequiresLoginPromise) {
|
|
470
|
+
const pending = fetchBigCommerceCheckoutSettings()
|
|
471
|
+
.then(({ guestCheckoutType }) => {
|
|
472
|
+
if (!guestCheckoutType) {
|
|
473
|
+
// `null` here means either the proxy call failed (transient) or the
|
|
474
|
+
// storeHash wasn't known yet. Fail open for this call, but clear
|
|
475
|
+
// the cached promise so the next caller retries instead of
|
|
476
|
+
// permanently disabling force-login for the rest of the session.
|
|
477
|
+
if (storeRequiresLoginPromise === pending) {
|
|
478
|
+
storeRequiresLoginPromise = null;
|
|
479
|
+
}
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
return guestCheckoutType === 'no_guest_checkout';
|
|
483
|
+
})
|
|
484
|
+
.catch(() => {
|
|
485
|
+
// Defense-in-depth: `fetchBigCommerceCheckoutSettings` is expected to
|
|
486
|
+
// swallow its own errors, but if anything above does reject we fail
|
|
487
|
+
// open and clear the cached promise so the next caller can retry.
|
|
488
|
+
if (storeRequiresLoginPromise === pending) {
|
|
489
|
+
storeRequiresLoginPromise = null;
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
492
|
+
});
|
|
493
|
+
storeRequiresLoginPromise = pending;
|
|
494
|
+
}
|
|
495
|
+
return storeRequiresLoginPromise;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Kick off the `/checkouts/settings` fetch in the background on page load
|
|
499
|
+
* so the result is warm by the time the shopper opens checkout. Safe to
|
|
500
|
+
* call more than once — re-invocations reuse the in-flight/resolved
|
|
501
|
+
* promise.
|
|
502
|
+
*/
|
|
503
|
+
const initBigCommerceForceLoginCheck = () => {
|
|
504
|
+
if (!window.Zonos.isBigCommerce) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
void resolveStoreRequiresLogin();
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* Decide whether the current BigCommerce shopper must sign in before the
|
|
511
|
+
* Zonos international checkout is allowed to open.
|
|
512
|
+
*
|
|
513
|
+
* Required conditions (all must hold):
|
|
514
|
+
* 1. Running on a BigCommerce storefront.
|
|
515
|
+
* 2. BC merchant has `guest_checkout_type === 'no_guest_checkout'` in their
|
|
516
|
+
* live `/v3/checkouts/settings` response.
|
|
517
|
+
* 3. Shopper has an active cart.
|
|
518
|
+
* 4. Shopper is not already logged in to BigCommerce.
|
|
519
|
+
*
|
|
520
|
+
* Returning a `redirectUrl` is an instruction, not an action: callers drive
|
|
521
|
+
* the navigation themselves so they can short-circuit any UI state (loading
|
|
522
|
+
* overlays, dialog open flags) before `window.location.href` flips.
|
|
523
|
+
*/
|
|
524
|
+
const checkBigCommerceForceLogin = async ({ preFetched, } = {}) => {
|
|
525
|
+
if (!window.Zonos.isBigCommerce) {
|
|
526
|
+
return SKIP;
|
|
527
|
+
}
|
|
528
|
+
const requiresLogin = await resolveStoreRequiresLogin();
|
|
529
|
+
if (!requiresLogin) {
|
|
530
|
+
return SKIP;
|
|
531
|
+
}
|
|
532
|
+
const checkoutId = preFetched
|
|
533
|
+
? preFetched.checkoutId
|
|
534
|
+
: await fetchCheckoutId();
|
|
535
|
+
if (!checkoutId) {
|
|
536
|
+
// No active cart — nothing to protect. Force-login only matters once
|
|
537
|
+
// the shopper has a cart we're about to carry into Zonos checkout.
|
|
538
|
+
return SKIP;
|
|
539
|
+
}
|
|
540
|
+
const checkout = preFetched
|
|
541
|
+
? preFetched.checkout
|
|
542
|
+
: await fetchBigCommerceCheckout(checkoutId);
|
|
543
|
+
if (!checkout) {
|
|
544
|
+
// Storefront API failure — fail open so a transient outage doesn't
|
|
545
|
+
// block the shopper. The merchant's BC checkout will still enforce
|
|
546
|
+
// login server-side as a last line of defense.
|
|
547
|
+
log('BigCommerce force-login check: failed to fetch checkout data, allowing flow to continue', 'info');
|
|
548
|
+
return SKIP;
|
|
549
|
+
}
|
|
550
|
+
if (isBigCommerceCustomerLoggedIn(checkout)) {
|
|
551
|
+
return SKIP;
|
|
552
|
+
}
|
|
553
|
+
log('BigCommerce force-login check: guest shopper on no-guest-checkout store, redirecting to /login.php', 'info');
|
|
554
|
+
return {
|
|
555
|
+
redirectUrl: buildBigcommerceLoginUrl(),
|
|
556
|
+
shouldForceLogin: true,
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Mark we've already rewritten a given anchor so the MutationObserver
|
|
562
|
+
* doesn't loop on its own mutation.
|
|
563
|
+
*/
|
|
564
|
+
const REWRITTEN_ATTR = 'data-zonos-login-from-rewritten';
|
|
565
|
+
const CREATE_ACCOUNT_SELECTOR = 'a[href*="login.php?action=create_account"]:not([' + REWRITTEN_ATTR + '])';
|
|
566
|
+
const rewriteCreateAccountLinks = () => {
|
|
567
|
+
const anchors = document.querySelectorAll(CREATE_ACCOUNT_SELECTOR);
|
|
568
|
+
if (!anchors.length) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const target = buildBigcommerceLoginUrl({ action: 'create_account' });
|
|
572
|
+
anchors.forEach(anchor => {
|
|
573
|
+
anchor.setAttribute('href', target);
|
|
574
|
+
anchor.setAttribute(REWRITTEN_ATTR, 'true');
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* On BigCommerce's `/login.php`, the default **Create account** button links
|
|
579
|
+
* to `login.php?action=create_account` without the `from=cart.php...`
|
|
580
|
+
* parameter that the shopper had when they arrived. Without this, completing
|
|
581
|
+
* signup would drop them on the account home page instead of resuming Zonos
|
|
582
|
+
* international checkout.
|
|
583
|
+
*
|
|
584
|
+
* This watcher finds any create-account anchor on the page (including ones
|
|
585
|
+
* that the BC theme renders later via Stencil bundle load) and rewrites the
|
|
586
|
+
* `href` so the account-creation round trip preserves the
|
|
587
|
+
* `isInternationalCheckout=true` flag as well as `zonosTestMode` /
|
|
588
|
+
* `zonosQaUrl`.
|
|
589
|
+
*
|
|
590
|
+
* Safe to call more than once — idempotent thanks to the `data-zonos-…`
|
|
591
|
+
* attribute on rewritten anchors.
|
|
592
|
+
*/
|
|
593
|
+
const fixBigCommerceLoginCreateAccountLink = () => {
|
|
594
|
+
if (!window.Zonos.isBigCommerce) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (!window.location.pathname.includes('/login.php')) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
rewriteCreateAccountLinks();
|
|
601
|
+
// BC's login page often renders the auth form asynchronously, so the
|
|
602
|
+
// anchor may not exist yet when this runs. Observe for a short window,
|
|
603
|
+
// then stop so we don't leak a listener for the rest of the session.
|
|
604
|
+
const observer = new MutationObserver(() => {
|
|
605
|
+
rewriteCreateAccountLinks();
|
|
606
|
+
});
|
|
607
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
608
|
+
// 10 seconds is plenty for the login form to mount; stopping the observer
|
|
609
|
+
// avoids churn from the rest of the page's normal DOM activity.
|
|
610
|
+
setTimeout(() => observer.disconnect(), 10000);
|
|
611
|
+
};
|
|
612
|
+
|
|
289
613
|
const isDisabledCountry = (showLog = true) => {
|
|
290
614
|
if (!localizationStore.localizationLoaded) {
|
|
291
615
|
return true;
|
|
@@ -335,19 +659,27 @@ const FALLBACK_SHIP_TO_COUNTRY_SELECTOR = 'select[name="shippingAddress.countryC
|
|
|
335
659
|
*/
|
|
336
660
|
const checkLoggedInUserShippingAddress = async ({ onInternationalCheckoutSelected, onLoggedInInternationalAddressDetected, }) => {
|
|
337
661
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
662
|
+
// Fetch the Storefront API data once up front and thread it through every
|
|
663
|
+
// decision below (bypass, shipping-address inspection, force-login). The
|
|
664
|
+
// function always needs the checkout for the address check, so reusing one
|
|
665
|
+
// fetch avoids the earlier 4x round-trip fan-out where bypass, address
|
|
666
|
+
// lookup, and force-login each fetched independently.
|
|
667
|
+
const checkoutId = await fetchCheckoutId();
|
|
668
|
+
if (!checkoutId) {
|
|
669
|
+
return 'noAction';
|
|
670
|
+
}
|
|
671
|
+
const checkout = await fetchBigCommerceCheckout(checkoutId);
|
|
672
|
+
const preFetched = { checkout, checkoutId };
|
|
338
673
|
// Check if the customer belongs to a bypass group (e.g. resellers) before
|
|
339
674
|
// redirecting them away from BigCommerce native checkout. This delegates to
|
|
340
675
|
// the shared helper so the bypass decision has a single source of truth and
|
|
341
676
|
// reuses the cached promise warmed by `initBigCommerceBypassCheck`.
|
|
342
|
-
const { shouldBypass } = await checkBigCommerceBypassCustomerGroup(
|
|
677
|
+
const { shouldBypass } = await checkBigCommerceBypassCustomerGroup({
|
|
678
|
+
preFetched,
|
|
679
|
+
});
|
|
343
680
|
if (shouldBypass) {
|
|
344
681
|
return 'noAction';
|
|
345
682
|
}
|
|
346
|
-
const checkoutId = await fetchCheckoutId();
|
|
347
|
-
if (!checkoutId) {
|
|
348
|
-
return 'noAction';
|
|
349
|
-
}
|
|
350
|
-
const checkout = await fetchBigCommerceCheckout(checkoutId);
|
|
351
683
|
const shippingAddress = (_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.consignments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.shippingAddress;
|
|
352
684
|
if (!(shippingAddress === null || shippingAddress === void 0 ? void 0 : shippingAddress.countryCode)) {
|
|
353
685
|
return 'noAction';
|
|
@@ -370,6 +702,14 @@ const checkLoggedInUserShippingAddress = async ({ onInternationalCheckoutSelecte
|
|
|
370
702
|
return 'optedOut';
|
|
371
703
|
}
|
|
372
704
|
}
|
|
705
|
+
// Force-login merchants must sign the guest shopper in before we leave
|
|
706
|
+
// BC's native checkout. Reuse the checkout we already fetched above so we
|
|
707
|
+
// don't double up on Storefront API round trips.
|
|
708
|
+
const forceLogin = await checkBigCommerceForceLogin({ preFetched });
|
|
709
|
+
if (forceLogin.shouldForceLogin && forceLogin.redirectUrl) {
|
|
710
|
+
window.location.href = forceLogin.redirectUrl;
|
|
711
|
+
return 'redirected';
|
|
712
|
+
}
|
|
373
713
|
if (onInternationalCheckoutSelected) {
|
|
374
714
|
await onInternationalCheckoutSelected();
|
|
375
715
|
}
|
|
@@ -427,9 +767,17 @@ const watchImmediateBigcommerceDomesticCheckoutRedirect = ({ domesticRedirectedB
|
|
|
427
767
|
// Only check bypass after confirming the country is shippable (i.e. user is
|
|
428
768
|
// about to be redirected to Zonos international checkout). Force-refresh so
|
|
429
769
|
// we re-fetch BigCommerce checkout data every time the ship-to country
|
|
430
|
-
// changes — prevents stale customer-group data from a cached fetch.
|
|
770
|
+
// changes — prevents stale customer-group data from a cached fetch. Share
|
|
771
|
+
// one fetch between the bypass and force-login decisions so this poll
|
|
772
|
+
// tick does 2 Storefront API round trips instead of 4.
|
|
773
|
+
const checkoutId = await fetchCheckoutId();
|
|
774
|
+
const checkout = checkoutId
|
|
775
|
+
? await fetchBigCommerceCheckout(checkoutId)
|
|
776
|
+
: null;
|
|
777
|
+
const preFetched = { checkout, checkoutId };
|
|
431
778
|
const { shouldBypass } = await checkBigCommerceBypassCustomerGroup({
|
|
432
779
|
forceRefresh: true,
|
|
780
|
+
preFetched,
|
|
433
781
|
});
|
|
434
782
|
if (shouldBypass) {
|
|
435
783
|
// Logged-in customer is in a bypass group — keep them on BC native
|
|
@@ -437,6 +785,14 @@ const watchImmediateBigcommerceDomesticCheckoutRedirect = ({ domesticRedirectedB
|
|
|
437
785
|
log('Bypass customer group detected on BC checkout, stopping interval', 'info');
|
|
438
786
|
return true;
|
|
439
787
|
}
|
|
788
|
+
// Same force-login gate as the logged-in-default-address path — we run
|
|
789
|
+
// it *after* the bypass check so reseller groups never see the login
|
|
790
|
+
// bounce, and *before* any UI/session state flips to the redirect.
|
|
791
|
+
const forceLogin = await checkBigCommerceForceLogin({ preFetched });
|
|
792
|
+
if (forceLogin.shouldForceLogin && forceLogin.redirectUrl) {
|
|
793
|
+
window.location.href = forceLogin.redirectUrl;
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
440
796
|
if (onInternationalCheckoutSelected) {
|
|
441
797
|
await onInternationalCheckoutSelected();
|
|
442
798
|
}
|
|
@@ -1560,6 +1916,15 @@ const ZonosCheckout = class {
|
|
|
1560
1916
|
window.location.href = buildBigcommerceRedirectUrl('/checkout');
|
|
1561
1917
|
return;
|
|
1562
1918
|
}
|
|
1919
|
+
// Merchants who disable BC guest checkout need the shopper
|
|
1920
|
+
// signed in before we open the Zonos international checkout.
|
|
1921
|
+
// Redirecting here keeps the dialog from flashing before the
|
|
1922
|
+
// login bounce.
|
|
1923
|
+
const forceLogin = await checkBigCommerceForceLogin();
|
|
1924
|
+
if (forceLogin.shouldForceLogin && forceLogin.redirectUrl) {
|
|
1925
|
+
window.location.href = forceLogin.redirectUrl;
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1563
1928
|
}
|
|
1564
1929
|
// start loading
|
|
1565
1930
|
stripeStore.isFetchingSession = true;
|
|
@@ -1812,6 +2177,19 @@ const ZonosCheckout = class {
|
|
|
1812
2177
|
// Start fetching BigCommerce customer group on page load so the bypass
|
|
1813
2178
|
// result is ready by the time checkout opens or the BC watcher fires
|
|
1814
2179
|
initBigCommerceBypassCheck();
|
|
2180
|
+
// Warm the BigCommerce `/checkouts/settings` fetch (merchant's
|
|
2181
|
+
// `guest_checkout_type`) so force-login gating resolves instantly when
|
|
2182
|
+
// the shopper clicks checkout — otherwise the first checkout open
|
|
2183
|
+
// would block on a proxy round trip.
|
|
2184
|
+
initBigCommerceForceLoginCheck();
|
|
2185
|
+
// On BC's `/login.php`, rewrite the "Create account" button href so
|
|
2186
|
+
// the post-signup round trip preserves the `from=cart.php?...` flag
|
|
2187
|
+
// that carries the shopper back into Zonos international checkout.
|
|
2188
|
+
fixBigCommerceLoginCreateAccountLink();
|
|
2189
|
+
// If BC redirected the shopper back here after login with the Zonos
|
|
2190
|
+
// resume flag, auto-open the international checkout. Strip the flag
|
|
2191
|
+
// from the URL so a refresh doesn't keep re-triggering the dialog.
|
|
2192
|
+
this.handleBigcommerceInternationalResumeFlag();
|
|
1815
2193
|
// check if bigcommerce, if user enters the shipping address that's in the shipping zone at bigcommerce checkout
|
|
1816
2194
|
watchImmediateBigcommerceDomesticCheckoutRedirect({
|
|
1817
2195
|
domesticRedirectedBtnSelector: domesticRedirectedBtnSelector,
|
|
@@ -1893,6 +2271,53 @@ const ZonosCheckout = class {
|
|
|
1893
2271
|
clearInterval(interval);
|
|
1894
2272
|
}, 10000);
|
|
1895
2273
|
}
|
|
2274
|
+
/**
|
|
2275
|
+
* After BigCommerce's `/login.php` round trip, the shopper lands back on
|
|
2276
|
+
* `cart.php?isInternationalCheckout=true`. Detect the flag, strip it from
|
|
2277
|
+
* the URL (so refreshing doesn't re-open the dialog), then fire the
|
|
2278
|
+
* international-checkout trigger once three preconditions are all met:
|
|
2279
|
+
* 1. Hello localization finished loading (`localizationLoaded`).
|
|
2280
|
+
* 2. A country code is selected — otherwise `buildCartDetail` runs
|
|
2281
|
+
* without a `countryCode` / `currencyCode` and never builds a cart.
|
|
2282
|
+
* 3. The hidden trigger button has mounted.
|
|
2283
|
+
*
|
|
2284
|
+
* Without the first two gates we race Hello's own init and the click
|
|
2285
|
+
* fires against a half-initialized store, which is what happens when
|
|
2286
|
+
* the shopper refreshes back into cart.php straight from the login
|
|
2287
|
+
* round trip.
|
|
2288
|
+
*/
|
|
2289
|
+
handleBigcommerceInternationalResumeFlag() {
|
|
2290
|
+
if (!window.Zonos.isBigCommerce) {
|
|
2291
|
+
return;
|
|
2292
|
+
}
|
|
2293
|
+
const url = new URL(window.location.href);
|
|
2294
|
+
if (url.searchParams.get(BIGCOMMERCE_INTERNATIONAL_CHECKOUT_FLAG) !== 'true') {
|
|
2295
|
+
return;
|
|
2296
|
+
}
|
|
2297
|
+
url.searchParams.delete(BIGCOMMERCE_INTERNATIONAL_CHECKOUT_FLAG);
|
|
2298
|
+
window.history.replaceState({}, '', url.toString());
|
|
2299
|
+
const start = Date.now();
|
|
2300
|
+
const interval = setInterval(() => {
|
|
2301
|
+
if (!localizationStore.localizationLoaded ||
|
|
2302
|
+
!localizationStore.selectedCountryCode) {
|
|
2303
|
+
if (Date.now() - start > 15000) {
|
|
2304
|
+
clearInterval(interval);
|
|
2305
|
+
log('BigCommerce international checkout resume flag: localization did not initialize within 15s', 'info');
|
|
2306
|
+
}
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
const btn = document.querySelector(`#${checkoutHiddenInternationalBtnSelector}`);
|
|
2310
|
+
if (btn) {
|
|
2311
|
+
clearInterval(interval);
|
|
2312
|
+
btn.dispatchEvent(createCustomEvent('click'));
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
if (Date.now() - start > 15000) {
|
|
2316
|
+
clearInterval(interval);
|
|
2317
|
+
log('BigCommerce international checkout resume flag: trigger button did not mount within 15s', 'info');
|
|
2318
|
+
}
|
|
2319
|
+
}, 200);
|
|
2320
|
+
}
|
|
1896
2321
|
/**
|
|
1897
2322
|
* For storybook to set to finish step, this is to trigger in the story for zonos-checkout-finish
|
|
1898
2323
|
*/
|
|
@@ -139,7 +139,7 @@ const ZonosHelloDialog = class {
|
|
|
139
139
|
};
|
|
140
140
|
this.getDutyMessage = () => {
|
|
141
141
|
// Domestic orders stay within the merchant's origin country, so no
|
|
142
|
-
// duty is ever assessed —
|
|
142
|
+
// duty is ever assessed — skip the de minimis message.
|
|
143
143
|
if (this.isDomesticCountry()) {
|
|
144
144
|
return null;
|
|
145
145
|
}
|
|
@@ -163,7 +163,7 @@ const ZonosHelloDialog = class {
|
|
|
163
163
|
this.getTaxMessage = () => {
|
|
164
164
|
const { countryLandedCost } = localizationStore;
|
|
165
165
|
// Domestic orders stay within the merchant's origin country, so no
|
|
166
|
-
//
|
|
166
|
+
// import tax is ever assessed — skip the de minimis message.
|
|
167
167
|
if (this.isDomesticCountry()) {
|
|
168
168
|
return null;
|
|
169
169
|
}
|
|
@@ -379,25 +379,25 @@ const ZonosHelloDialog = class {
|
|
|
379
379
|
// If deminimis is undefined or null, assume it's $0
|
|
380
380
|
const taxDeMinimisMessage = this.getTaxMessage();
|
|
381
381
|
const inclusivePriceMessage = this.getInclusivePriceMessage();
|
|
382
|
-
return (h(Host, { key: '
|
|
382
|
+
return (h(Host, { key: '910b2b5600107a097fa4cdc77ec487e03fe6a8d2', class: "zonos--elements" }, h("div", { key: 'edf1d9b554807db1c973a1ccdb6e20a647c24204', class: classes([
|
|
383
383
|
'zonos--hello-dialog',
|
|
384
384
|
animateLeft && 'zonos--hello-dialog-animate-from-left',
|
|
385
385
|
animateFromBottom && 'zonos--hello-dialog-animate-from-bottom',
|
|
386
386
|
!!this.mobileLocationOverride &&
|
|
387
387
|
'zonos--hello-dialog-mobile-override',
|
|
388
388
|
this.isOpen && 'zonos--hello-dialog-open',
|
|
389
|
-
]), inert: !this.isOpen, ref: el => el && (this.dialogRef = el) }, !this.showCountrySelect && !this.showLanguageSelect && (h("div", { key: '
|
|
389
|
+
]), inert: !this.isOpen, ref: el => el && (this.dialogRef = el) }, !this.showCountrySelect && !this.showLanguageSelect && (h("div", { key: 'f5316102d12d07e1a3c701ad641995413ee445b2' }, h("div", { key: 'c11cc7e8d11f733c82435a531d7d8595b0237eae', class: "zonos--hello-dialog-content" }, h("zonos-button", { key: 'a2aa2802331e9ed5c40d877fcb7ffb0cebd318c5', class: "zonos--close-button", icon: h("zonos-icon", { "aria-label": "Close Zonos Hello dialog", content: RemoveIcon }), noBackground: true, onClick: () => this.setIsOpen(false) }), h("zonos-v-stack", { key: 'f6df6e6562b8ddebb0e910d669a6a263114f6407', spacing: 24 }, h("zonos-country-flag", { key: '71c320b3364deee7c545284a2fc639cef3a3ba27', class: "zonos--hello-country-flag", countryCode: selectedCountryCode }), h("zonos-v-stack", { key: '9603247163d334db33fe00428190fafdd6ef6c42', class: "zonos--hello-dialog-header", spacing: 4 }, h("zonos-text", { key: 'aad7fd909092a9fad15ce88a3f43ad5115bca1f9', type: "boldSubheader" }, welcomeMessage), h("zonos-text", { key: 'c3c9c5d5f9e1000b2b6c6aebc73f18c6653f9de2', innerHTML: defaultMessage, textColor: "gray-800" })), h("zonos-v-stack", { key: 'c34b1b9debb507ce6f230bd13b493a14af12e880', spacing: 8 }, this.restrictedItems.map(item => {
|
|
390
390
|
var _a;
|
|
391
391
|
return item && (h("zonos-banner", { bannerTitle: item.name, intent: "error" }, (_a = item.itemRestrictions) === null || _a === void 0 ? void 0 : _a.map(x => (h("zonos-text", { textColor: "red-800" }, x === null || x === void 0 ? void 0 : x.note)))));
|
|
392
392
|
}), (dutyDeMinimisMessage ||
|
|
393
393
|
taxDeMinimisMessage ||
|
|
394
394
|
inclusivePriceMessage ||
|
|
395
|
-
!!(additionalInformation === null || additionalInformation === void 0 ? void 0 : additionalInformation.length)) && (h("zonos-card", { key: '
|
|
395
|
+
!!(additionalInformation === null || additionalInformation === void 0 ? void 0 : additionalInformation.length)) && (h("zonos-card", { key: '5dc5af9af7263333433b8a0382a30ccf9f28056d', spacing: "12px" }, h("zonos-v-stack", { key: '725669eaca664abc90f5ec8181c3b81c05cc3b52', spacing: 12 }, this.renderHelloMessage({
|
|
396
396
|
dutyDeMinimisMessage,
|
|
397
397
|
inclusivePriceMessage,
|
|
398
398
|
taxDeMinimisMessage,
|
|
399
399
|
}), additionalInformation === null || additionalInformation === void 0 ? void 0 :
|
|
400
|
-
additionalInformation.map(info => (h("div", { class: "zonos--flex-message" }, h("zonos-icon", { "aria-label": "Additional information for buying goods from selected country icon", content: BagIcon }), h("zonos-text", { "aria-label": `Additional information for buying goods from selected country message`, innerHTML: info }))))))), filteredMessages.map(x => (h("zonos-custom-message", { icon: MessageIcon, message: x.message })))))), h("zonos-hello-dialog-footer", { key: '
|
|
400
|
+
additionalInformation.map(info => (h("div", { class: "zonos--flex-message" }, h("zonos-icon", { "aria-label": "Additional information for buying goods from selected country icon", content: BagIcon }), h("zonos-text", { "aria-label": `Additional information for buying goods from selected country message`, innerHTML: info }))))))), filteredMessages.map(x => (h("zonos-custom-message", { icon: MessageIcon, message: x.message })))))), h("zonos-hello-dialog-footer", { key: '077adfd58b2d7d95d5f352a09783089a1e91c99f', appearanceSettings: this.appearanceSettings, setShowCountrySelect: value => this.setShowCountrySelect(value), setShowLanguageSelect: value => this.setShowLanguageSelect(value) }))), this.showCountrySelect && (h("div", { key: '8c2dd5d73a649eebf1517a9b359d3ecc93b12620' }, h("zonos-country-select", { key: 'e2f64c73efe1e931808fdfe6aa5f8545d6f39c93', handleOnClose: () => this.setShowCountrySelect(false) }))), this.showLanguageSelect && (h("div", { key: '0b9ba684ac67fa652a34e6fbad8e966970f391ce' }, h("zonos-language-select", { key: '2e03e02459b0f31bc69376bc154ed8bb2d96ef56', handleOnClose: () => this.setShowLanguageSelect(false) }))))));
|
|
401
401
|
}
|
|
402
402
|
static get assetsDirs() { return ["assets"]; }
|
|
403
403
|
static get watchers() { return {
|