@shoppexio/storefront 1.0.61 → 1.0.62

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.62
4
+
5
+ - Fail open with an unavailable callback when the hosted checkout verification broker never completes its ready handshake.
6
+
3
7
  ## 1.0.61
4
8
 
5
9
  - 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", "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
  }
@@ -20418,10 +20419,16 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
20418
20419
  frame.style.width = "100%";
20419
20420
  frame.style.height = "72px";
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;
20430
+ ready = true;
20431
+ win.clearTimeout(readyTimeout);
20425
20432
  if (message.type === "success") callbacks.onSuccess(message.token);
20426
20433
  if (message.type === "expired" || message.type === "timeout") callbacks.onExpired?.();
20427
20434
  if (message.type === "error") callbacks.onUnavailable?.();
@@ -20435,6 +20442,7 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
20435
20442
  dispose() {
20436
20443
  if (disposed) return;
20437
20444
  disposed = true;
20445
+ win.clearTimeout(readyTimeout);
20438
20446
  win.removeEventListener("message", onMessage);
20439
20447
  frame.removeEventListener("error", onFrameError);
20440
20448
  frame.remove();