@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 +4 -0
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4989,10 +4989,11 @@ function buildCheckoutUrlSync() {
|
|
|
4989
4989
|
// ../sdk/src/modules/checkout-challenge.ts
|
|
4990
4990
|
var TURNSTILE_FRAME_MESSAGE_SOURCE = "shoppex-turnstile";
|
|
4991
4991
|
var TURNSTILE_FRAME_MESSAGE_VERSION = 1;
|
|
4992
|
+
var TURNSTILE_FRAME_READY_TIMEOUT_MS = 1e4;
|
|
4992
4993
|
function readFrameMessage(value, nonce) {
|
|
4993
4994
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
4994
4995
|
const record2 = value;
|
|
4995
|
-
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;
|
|
4996
|
+
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;
|
|
4996
4997
|
if (record2.type === "success" && (typeof record2.token !== "string" || !record2.token.trim())) {
|
|
4997
4998
|
return null;
|
|
4998
4999
|
}
|
|
@@ -5023,10 +5024,16 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
|
|
|
5023
5024
|
frame.style.width = "100%";
|
|
5024
5025
|
frame.style.height = "72px";
|
|
5025
5026
|
let disposed = false;
|
|
5027
|
+
let ready = false;
|
|
5028
|
+
const readyTimeout = win.setTimeout(() => {
|
|
5029
|
+
if (!disposed && !ready) callbacks.onUnavailable?.();
|
|
5030
|
+
}, TURNSTILE_FRAME_READY_TIMEOUT_MS);
|
|
5026
5031
|
const onMessage = (event) => {
|
|
5027
5032
|
if (disposed || event.origin !== frameUrl.origin || event.source !== frame.contentWindow) return;
|
|
5028
5033
|
const message = readFrameMessage(event.data, nonce);
|
|
5029
5034
|
if (!message) return;
|
|
5035
|
+
ready = true;
|
|
5036
|
+
win.clearTimeout(readyTimeout);
|
|
5030
5037
|
if (message.type === "success") callbacks.onSuccess(message.token);
|
|
5031
5038
|
if (message.type === "expired" || message.type === "timeout") callbacks.onExpired?.();
|
|
5032
5039
|
if (message.type === "error") callbacks.onUnavailable?.();
|
|
@@ -5040,6 +5047,7 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
|
|
|
5040
5047
|
dispose() {
|
|
5041
5048
|
if (disposed) return;
|
|
5042
5049
|
disposed = true;
|
|
5050
|
+
win.clearTimeout(readyTimeout);
|
|
5043
5051
|
win.removeEventListener("message", onMessage);
|
|
5044
5052
|
frame.removeEventListener("error", onFrameError);
|
|
5045
5053
|
frame.remove();
|