@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 +8 -0
- package/dist/index.cjs +16 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -3
- 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", "visible", "hidden", "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
|
}
|
|
@@ -5021,13 +5022,24 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
|
|
|
5021
5022
|
frame.referrerPolicy = "no-referrer";
|
|
5022
5023
|
frame.style.border = "0";
|
|
5023
5024
|
frame.style.width = "100%";
|
|
5024
|
-
frame.style.height = "
|
|
5025
|
+
frame.style.height = "0";
|
|
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;
|
|
5030
|
-
|
|
5035
|
+
ready = true;
|
|
5036
|
+
win.clearTimeout(readyTimeout);
|
|
5037
|
+
if (message.type === "visible") frame.style.height = "72px";
|
|
5038
|
+
if (message.type === "hidden") frame.style.height = "0";
|
|
5039
|
+
if (message.type === "success") {
|
|
5040
|
+
frame.style.height = "0";
|
|
5041
|
+
callbacks.onSuccess(message.token);
|
|
5042
|
+
}
|
|
5031
5043
|
if (message.type === "expired" || message.type === "timeout") callbacks.onExpired?.();
|
|
5032
5044
|
if (message.type === "error") callbacks.onUnavailable?.();
|
|
5033
5045
|
};
|
|
@@ -5040,6 +5052,7 @@ function mountCheckoutChallenge(container, challenge, callbacks) {
|
|
|
5040
5052
|
dispose() {
|
|
5041
5053
|
if (disposed) return;
|
|
5042
5054
|
disposed = true;
|
|
5055
|
+
win.clearTimeout(readyTimeout);
|
|
5043
5056
|
win.removeEventListener("message", onMessage);
|
|
5044
5057
|
frame.removeEventListener("error", onFrameError);
|
|
5045
5058
|
frame.remove();
|