@shoppexio/storefront 1.0.61 → 1.0.63

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.63
4
+
5
+ - Keep managed checkout verification collapsed until Cloudflare requires buyer interaction.
6
+
7
+ ## 1.0.62
8
+
9
+ - Fail open with an unavailable callback when the hosted checkout verification broker never completes its ready handshake.
10
+
3
11
  ## 1.0.61
4
12
 
5
13
  - Add `mountCheckoutChallenge()` so custom storefront domains can complete the hosted checkout verification broker and retry invoice creation.
package/dist/index.cjs CHANGED
@@ -20384,10 +20384,11 @@ function buildCheckoutUrlSync() {
20384
20384
  // ../sdk/src/modules/checkout-challenge.ts
20385
20385
  var TURNSTILE_FRAME_MESSAGE_SOURCE = "shoppex-turnstile";
20386
20386
  var TURNSTILE_FRAME_MESSAGE_VERSION = 1;
20387
+ var TURNSTILE_FRAME_READY_TIMEOUT_MS = 1e4;
20387
20388
  function readFrameMessage(value, nonce) {
20388
20389
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
20389
20390
  const record2 = value;
20390
- if (record2.source !== TURNSTILE_FRAME_MESSAGE_SOURCE || record2.version !== TURNSTILE_FRAME_MESSAGE_VERSION || record2.nonce !== nonce || !["success", "expired", "timeout", "error"].includes(String(record2.type))) return null;
20391
+ if (record2.source !== TURNSTILE_FRAME_MESSAGE_SOURCE || record2.version !== TURNSTILE_FRAME_MESSAGE_VERSION || record2.nonce !== nonce || !["ready", "visible", "hidden", "success", "expired", "timeout", "error"].includes(String(record2.type))) return null;
20391
20392
  if (record2.type === "success" && (typeof record2.token !== "string" || !record2.token.trim())) {
20392
20393
  return null;
20393
20394
  }
@@ -20416,13 +20417,24 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
20416
20417
  frame.referrerPolicy = "no-referrer";
20417
20418
  frame.style.border = "0";
20418
20419
  frame.style.width = "100%";
20419
- frame.style.height = "72px";
20420
+ frame.style.height = "0";
20420
20421
  let disposed = false;
20422
+ let ready = false;
20423
+ const readyTimeout = win.setTimeout(() => {
20424
+ if (!disposed && !ready) callbacks.onUnavailable?.();
20425
+ }, TURNSTILE_FRAME_READY_TIMEOUT_MS);
20421
20426
  const onMessage = (event) => {
20422
20427
  if (disposed || event.origin !== frameUrl.origin || event.source !== frame.contentWindow) return;
20423
20428
  const message = readFrameMessage(event.data, nonce);
20424
20429
  if (!message) return;
20425
- if (message.type === "success") callbacks.onSuccess(message.token);
20430
+ ready = true;
20431
+ win.clearTimeout(readyTimeout);
20432
+ if (message.type === "visible") frame.style.height = "72px";
20433
+ if (message.type === "hidden") frame.style.height = "0";
20434
+ if (message.type === "success") {
20435
+ frame.style.height = "0";
20436
+ callbacks.onSuccess(message.token);
20437
+ }
20426
20438
  if (message.type === "expired" || message.type === "timeout") callbacks.onExpired?.();
20427
20439
  if (message.type === "error") callbacks.onUnavailable?.();
20428
20440
  };
@@ -20435,6 +20447,7 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
20435
20447
  dispose() {
20436
20448
  if (disposed) return;
20437
20449
  disposed = true;
20450
+ win.clearTimeout(readyTimeout);
20438
20451
  win.removeEventListener("message", onMessage);
20439
20452
  frame.removeEventListener("error", onFrameError);
20440
20453
  frame.remove();