Skip to content

Open source alternative to Semrush and Ahrefs

Fix free tool Turnstile verification failures (#644)

Ben Senescua07af3625c3f
diff --git a/web/package.json b/web/package.json
index 98914985..9a760423 100644
--- a/web/package.json
+++ b/web/package.json
@@ -19,6 +19,7 @@
"test:protection": "vitest run && node scripts/check-free-tool-budget.cjs"
},
"dependencies": {
+ "@marsidev/react-turnstile": "1.6.1",
"@tanstack/react-router": "^1.170.16",
"@tanstack/react-router-devtools": "^1.167.0",
"@tanstack/react-start": "^1.168.26",
@@ -40,6 +41,7 @@
"@types/react": "^19.2.13",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.3",
+ "jsdom": "^30.0.1",
"prettier": "^3.6.2",
"srvx": "^0.11.22",
"tailwindcss": "^4.1.18",
diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml
index 0e8814b3..54fa7c8d 100644
--- a/web/pnpm-lock.yaml
+++ b/web/pnpm-lock.yaml
@@ -22,6 +22,9 @@ importers:
.:
dependencies:
+ '@marsidev/react-turnstile':
+ specifier: 1.6.1
'@radix-ui/react-popover':
specifier: ^1.1.15
@@ -80,6 +83,9 @@ importers:
'@vitejs/plugin-react':
specifier: ^5.1.3
+ jsdom:
+ specifier: ^30.0.1
+ version: 30.0.1
prettier:
specifier: ^3.6.2
version: 3.8.1
@@ -97,13 +103,21 @@ importers:
vitest:
specifier: 3.2.6
wrangler:
specifier: ^4.67.0
version: 4.71.0(@cloudflare/[email protected])(@types/[email protected])
packages:
+ '@asamuzakjp/[email protected]':
+ resolution: {integrity: sha512-vC/bk1Lz7Tn/EfU9/apOTBk80/8dyGyWMowPoV1tJ52muDGsDqt2HPT2klrFUiY60MQmQv9q8yIht15JnBgDGw==}
+ engines: {node: ^22.13.0 || >=24.0.0}
+
+ '@asamuzakjp/[email protected]':
+ resolution: {integrity: sha512-93Z1N+BQNXysodoicpOIyNh2drHfz/CTf9nnT0FEx72GJcIiwgydD7tGAr78j41LsYn3hlRn+LdGPuBLn1Bl8Q==}
+ engines: {node: ^22.13.0 || >=24.0.0}
+
resolution: {integrity: sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==}
engines: {node: '>=6.9.0'}
@@ -208,6 +222,10 @@ packages:
resolution: {integrity: sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==}
engines: {node: '>=6.9.0'}
+ '@bramus/[email protected]':
+ resolution: {integrity: sha512-ctxtJ/eA+t+6q2++vj5j7FYX3nRu311q1wfYH3xjlLOsczhlhxAg2FWNUXhpGvAw3BWo1xBcvOV6/YLc2r5FJw==}
+ hasBin: true
+
'@cloudflare/[email protected]':
resolution: {integrity: sha512-SIOD2DxrRRwQ+jgzlXCqoEFiKOFqaPjhnNTGKXSRLvp1HiOvapLaFG2kEr9dYQTYe8rKrd9uvDUzmAITeNyaHQ==}
engines: {node: '>=18.0.0'}
@@ -264,6 +282,42 @@ packages:
resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}
engines: {node: '>=12'}
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-gLNsunvwf3mCi5u5o46/Z/JcJMnhbHSaZ69rkgPzNM3J4s8hWwpPUQB6/tt0EDFyCiWzxANlx+2LJwpYj4zS1w==}
+ engines: {node: '>=20.19.0'}
+
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-c5ihYsPkdG6JCkU2zTMm4+k6r7RXuGxtWYhu5DHMIiF1FHzrfmHL5so11AoFpUv/tu61xfcmT4AmKoFfMPoqdQ==}
+ engines: {node: '>=20.19.0'}
+ peerDependencies:
+ '@csstools/css-parser-algorithms': ^4.0.0
+ '@csstools/css-tokenizer': ^4.0.0
+
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-3QKjR/vxyjcSXBLgb6lP0S3MGdvwbmqSsvLPbYdVORqPDc8FX1HAJ0Spk38bxaRXgvENTA47tlhhbb5Z2e8hEg==}
+ engines: {node: '>=20.19.0'}
+ peerDependencies:
+ '@csstools/css-parser-algorithms': ^4.0.0
+ '@csstools/css-tokenizer': ^4.0.0
+
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-+B87qS7fIG3L5h3qwJ/IFbjoVoOe/bpOdh9hAjXbvx0o8ImEmUsGXN0inFOnk2ChCFgqkkGFQ+TpM5rbhkKe4w==}
+ engines: {node: '>=20.19.0'}
+ peerDependencies:
+ '@csstools/css-tokenizer': ^4.0.0
+
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-3vLQK+dXxhBMR2Wx99PTCifE+vHtW2ndZWyla8yK813ev6oGhyn8Lja8jCyGAWTJ+LEYZK7EVtJxrDj8ztevJw==}
+ peerDependencies:
+ css-tree: ^3.2.1
+ peerDependenciesMeta:
+ css-tree:
+ optional: true
+
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-QxULHAm7cNu72w97JUNCBFODFaXpbDg+dP8b/oWFAZ2MTRppA3U00Y2L1HqaS4J6yBqxwa/Y3nMBaxVKbB/NsA==}
+ engines: {node: '>=20.19.0'}
+
'@emnapi/[email protected]':
resolution: {integrity: sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==}
@@ -579,6 +633,15 @@ packages:
cpu: [x64]
os: [win32]
+ '@exodus/[email protected]':
+ resolution: {integrity: sha512-S6mL0yNB/Abt9Ei4tq8gDhcczc4S3+vQ4ra7vxnAf+YHC02srtqxKKZghx2Dq6p0e66THKwR6r8N6P95wEty7Q==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
+ peerDependencies:
+ '@noble/hashes': ^1.8.0 || ^2.0.0
+ peerDependenciesMeta:
+ '@noble/hashes':
+ optional: true
+
'@floating-ui/[email protected]':
resolution: {integrity: sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==}
@@ -796,6 +859,12 @@ packages:
'@jridgewell/[email protected]':
resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==}
+ '@marsidev/[email protected]':
+ resolution: {integrity: sha512-ojI9NLYv821IRKi7KraTkxTto6KC/m58hNNyKxvYxm/cQBu5MI5eMkaiJs2JSQBFiXE3LPQI3seJVjv/2lgALA==}
+ peerDependencies:
+ react: ^17.0.2 || ^18.0.0 || ^19.0
+ react-dom: ^17.0.2 || ^18.0.0 || ^19.0
+
'@mdx-js/[email protected]':
resolution: {integrity: sha512-f6ZO2ifpwAQIpzGWaBQT2TXxPv6z3RBzQKpVftEWN78Vl/YweF1uwussDx8ECAXVtr3Rs89fKyG9YlzUs9DyGQ==}
@@ -1763,6 +1832,9 @@ packages:
engines: {node: '>=6.0.0'}
hasBin: true
+ resolution: {integrity: sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg==}
+
resolution: {integrity: sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g==}
@@ -1840,9 +1912,17 @@ packages:
resolution: {integrity: sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==}
engines: {node: '>=18'}
+ resolution: {integrity: sha512-X7sjQzceUhu1u7Y/ylrRZFU2FS6LRiFVp6rKLPg23y3x3c3DOKAwuXGDp+PAGjh6CSnCjYeAul8pcT8bAl+lSA==}
+ engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0}
+
resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==}
+ resolution: {integrity: sha512-23XHcCF+coGYevirZceTVD7NdJOqVn+49IHyxgszm+JIiHLoB2TkmPtsYkNWT1pvRSGkc35L6NHs0yHkN2SumA==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
+
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
engines: {node: '>=6.0'}
@@ -1852,6 +1932,9 @@ packages:
supports-color:
optional: true
+ resolution: {integrity: sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==}
+
resolution: {integrity: sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==}
@@ -1888,6 +1971,10 @@ packages:
resolution: {integrity: sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==}
engines: {node: '>=0.12'}
+ resolution: {integrity: sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==}
+ engines: {node: '>=20.19.0'}
+
resolution: {integrity: sha512-5qucVt2XcuGMcEGgWI7i+yZpmpByQ8J1lHhcL7PwqCwu9FPP3VUXzT4ltHe5i2z9dePwEHcDVOAfSnHsOlCXRA==}
@@ -2140,6 +2227,10 @@ packages:
resolution: {integrity: sha512-g7df9rMFX/SPi34tyGCyUBREQoKkapwdY/T04Qn9TDWfHhAYt4/I0gMVirzK5wEzeUqIjEB+LXC/ypb7Aqno5w==}
+ resolution: {integrity: sha512-CV9TW3Y3f8/wT0BRFc1/KAVQ3TUHiXmaAb6VW9vtiMFf7SLoMd1PdAc4W3KFOFETBJUb90KatHqlsZMWV+R9Gg==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
+
resolution: {integrity: sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==}
@@ -2162,6 +2253,9 @@ packages:
resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==}
engines: {node: '>=12'}
+ resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}
+
resolution: {integrity: sha512-iQcBXcd+Rv/pkubRyGh2utW2j1oPG5hZY6TUhVPpqK4G+o3IbxpJNx04hgksjc/N7GK5pEorUxDeg31cFgEk/w==}
engines: {node: '>=18'}
@@ -2184,6 +2278,15 @@ packages:
resolution: {integrity: sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==}
hasBin: true
+ resolution: {integrity: sha512-52v7mUVUfNQVYYqE1lcdaymWL0njO7lTLUog6ZvW2U5KsbiLk/GnZlVJ+qx0xfNJZ6Gn+KSpPNE52vurbxZwrA==}
+ engines: {node: ^22.22.2 || ^24.15.0 || >=26.0.0}
+ peerDependencies:
+ canvas: ^3.2.3
+ peerDependenciesMeta:
+ canvas:
+ optional: true
+
resolution: {integrity: sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==}
engines: {node: '>=6'}
@@ -2422,6 +2525,9 @@ packages:
resolution: {integrity: sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==}
+ resolution: {integrity: sha512-9Yubnt3e8A0OKwxYSXyhLymGW4sCufcLG6VdiDdUGVkPhpqLxlvP5vl1983gQjJl3tqbrM731mjaZaP68AgosQ==}
+
resolution: {integrity: sha512-RDBrHEMSxVFLg6xvnXmb1Ayr2WzLAWjeSATAoxwKYJV94TeNavgoIdA0a9ytzDSVzBy2YKFK+emCPOEibLeCrg==}
@@ -2583,6 +2689,9 @@ packages:
resolution: {integrity: sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==}
+ resolution: {integrity: sha512-z1e/HMG90obSGeidlli3hj7cbocou0/wa5HacvI3ASx34PecNjNQeaHNo5WIZpWofN9kgkqV1q5YvXe3F0FoPw==}
+
resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==}
@@ -2612,6 +2721,10 @@ packages:
resolution: {integrity: sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==}
+ resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
+ engines: {node: '>=6'}
+
resolution: {integrity: sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==}
peerDependencies:
@@ -2710,6 +2823,10 @@ packages:
resolution: {integrity: sha512-Eht5w30ruCXgFmxVUSlNWQ9iiimq07URKeFS3hNc8cUWy1llX4KDWfyEDZRycMc+znsN9Ux5/tJ/BFdgdOwA3A==}
+ resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==}
+ engines: {node: '>=0.10.0'}
+
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
@@ -2721,6 +2838,10 @@ packages:
resolution: {integrity: sha512-ePa+XGk00/3HuCqrEnK3LxJW7I0SdNg6EFzKUJG73hMAdDcOUC/i/aSz7LSDwLrGr33kal/rqOGydzwl6U7zBA==}
+ resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==}
+ engines: {node: '>=v12.22.7'}
+
resolution: {integrity: sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==}
@@ -2800,6 +2921,9 @@ packages:
resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==}
engines: {node: '>=18'}
+ resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==}
+
resolution: {integrity: sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw==}
@@ -2833,6 +2957,21 @@ packages:
resolution: {integrity: sha512-u8KszXvGfU68hVcZpRHKG28T0krMuv2G5nDhiHaMLen/gIuFEgIJhaJuO69qjnXg5paSrbPMFfx3brNuN8eVSg==}
engines: {node: '>=14.0.0'}
+ resolution: {integrity: sha512-nYNzS2WRf4QJmjzFFgAxLOBjyBxAGRbCy9PVBPaglcYyYajh40VBn+v5Ngr96ZMc7oM0+aCJdtQnNejvdBnXMQ==}
+
+ resolution: {integrity: sha512-WylhSDKVeYnWXL3a+vKTaOxjnOeEGw938hImY8zoRWJjRRK/Jp1K+IihBzIONpUmW4e3WmXT6q5FW6vlESVZCA==}
+ hasBin: true
+
+ resolution: {integrity: sha512-exgYmnmL/sJpR3upZfXG5PoatXQii55xAiXGXzY+sROLZ/Y+SLcp9PgJNI9Vz37HpQ74WvDcLT8eqm+kV3FzrA==}
+ engines: {node: '>=16'}
+
+ resolution: {integrity: sha512-bLVMLPtstlZ4iMQHpFHTR7GAGj2jxi8Dg0s2h2MafAE4uSWF98FC/3MomU51iQAMf8/qDUbKWf5GxuvvVcXEhw==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==}
@@ -3058,12 +3197,32 @@ packages:
jsdom:
optional: true
+ resolution: {integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==}
+ engines: {node: '>=18'}
+
resolution: {integrity: sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==}
+ resolution: {integrity: sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==}
+ resolution: {integrity: sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==}
+ engines: {node: '>=20'}
+
+ resolution: {integrity: sha512-1to4zXBxmXHV3IiSSEInrreIlu02vUOvrhxJJH5vcxYTBDAx51cqZiKdyTxlecdKNSjj8EcxGBxNf6Vg+945gw==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
+
+ resolution: {integrity: sha512-ohjk1mdUebJVadRt3bAhQhx8lSnISq+GDttK79LFl8EHQkAPvzwctoasC4hs8tBt6kLAncBWWyq1N52qEfKvDw==}
+ engines: {node: ^22.14.0 || >=24.0.0}
+
resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==}
engines: {node: '>=8'}
@@ -3096,10 +3255,17 @@ packages:
utf-8-validate:
optional: true
+ resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
+ engines: {node: '>=18'}
+
resolution: {integrity: sha512-bx8Q1STctnNaaDymWnkfQLKofs0mGNN7rLLapJlGuV3VlvegD7Ls4ggMjE3aUSWItCCzU0PEv45lI87iSigiCA==}
engines: {node: '>=20.0'}
+ resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==}
+
resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==}
@@ -3126,6 +3292,21 @@ packages:
snapshots:
+ '@asamuzakjp/[email protected]':
+ dependencies:
+ '@csstools/css-calc': 3.3.0(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])
+ '@csstools/css-color-parser': 4.2.2(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])
+ '@csstools/css-parser-algorithms': 4.0.0(@csstools/[email protected])
+ '@csstools/css-tokenizer': 4.0.0
+ lru-cache: 11.5.2
+
+ '@asamuzakjp/[email protected]':
+ dependencies:
+ bidi-js: 1.1.0
+ css-tree: 3.2.1
+ is-potential-custom-element-name: 1.0.1
+ lru-cache: 11.5.2
+
dependencies:
'@babel/helper-validator-identifier': 7.29.7
@@ -3257,6 +3438,10 @@ snapshots:
'@babel/helper-string-parser': 7.29.7
'@babel/helper-validator-identifier': 7.29.7
+ '@bramus/[email protected]':
+ dependencies:
+ css-tree: 3.2.1
+
'@cloudflare/[email protected]': {}
@@ -3300,6 +3485,30 @@ snapshots:
dependencies:
'@jridgewell/trace-mapping': 0.3.9
+ '@csstools/[email protected]': {}
+
+ '@csstools/[email protected](@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])':
+ dependencies:
+ '@csstools/css-parser-algorithms': 4.0.0(@csstools/[email protected])
+ '@csstools/css-tokenizer': 4.0.0
+
+ '@csstools/[email protected](@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])':
+ dependencies:
+ '@csstools/color-helpers': 6.1.1
+ '@csstools/css-calc': 3.3.0(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])
+ '@csstools/css-parser-algorithms': 4.0.0(@csstools/[email protected])
+ '@csstools/css-tokenizer': 4.0.0
+
+ '@csstools/[email protected](@csstools/[email protected])':
+ dependencies:
+ '@csstools/css-tokenizer': 4.0.0
+
+ optionalDependencies:
+ css-tree: 3.2.1
+
+ '@csstools/[email protected]': {}
+
'@emnapi/[email protected]':
dependencies:
tslib: 2.8.1
@@ -3461,6 +3670,8 @@ snapshots:
'@esbuild/[email protected]':
optional: true
+ '@exodus/[email protected]': {}
+
'@floating-ui/[email protected]':
dependencies:
'@floating-ui/utils': 0.2.12
@@ -3621,6 +3832,11 @@ snapshots:
'@jridgewell/resolve-uri': 3.1.2
'@jridgewell/sourcemap-codec': 1.5.5
+ dependencies:
+ react: 19.3.0
+ react-dom: 19.3.0([email protected])
+
'@mdx-js/[email protected]':
dependencies:
'@types/estree': 1.0.9
@@ -4626,6 +4842,10 @@ snapshots:
+ dependencies:
+ require-from-string: 2.0.2
+
@@ -4688,12 +4908,26 @@ snapshots:
+ dependencies:
+ mdn-data: 2.27.1
+ source-map-js: 1.2.1
+
+ dependencies:
+ whatwg-mimetype: 5.0.0
+ whatwg-url: 16.0.1
+ transitivePeerDependencies:
+ - '@noble/hashes'
+
dependencies:
ms: 2.1.3
+
dependencies:
character-entities: 2.0.2
@@ -4721,6 +4955,8 @@ snapshots:
+
@@ -5089,6 +5325,12 @@ snapshots:
property-information: 7.2.0
space-separated-tokens: 2.0.2
+ dependencies:
+ '@exodus/bytes': 1.15.1
+ transitivePeerDependencies:
+ - '@noble/hashes'
+
@@ -5106,6 +5348,8 @@ snapshots:
+
@@ -5120,6 +5364,32 @@ snapshots:
dependencies:
argparse: 2.0.1
+ dependencies:
+ '@asamuzakjp/css-color': 6.0.7
+ '@asamuzakjp/dom-selector': 8.3.2
+ '@bramus/specificity': 2.4.2
+ '@csstools/css-syntax-patches-for-csstree': 1.1.12([email protected])
+ '@exodus/bytes': 1.15.1
+ css-tree: 3.2.1
+ data-urls: 7.0.0
+ decimal.js: 10.6.0
+ html-encoding-sniffer: 6.0.0
+ is-potential-custom-element-name: 1.0.1
+ lru-cache: 11.5.2
+ parse5: 8.0.1
+ saxes: 6.0.0
+ symbol-tree: 3.2.4
+ tough-cookie: 6.0.2
+ undici: 7.29.1
+ w3c-xmlserializer: 5.0.0
+ webidl-conversions: 8.0.1
+ whatwg-mimetype: 5.0.0
+ whatwg-url: 17.1.1
+ xml-name-validator: 5.0.0
+ transitivePeerDependencies:
+ - '@noble/hashes'
+
@@ -5409,6 +5679,8 @@ snapshots:
dependencies:
'@types/mdast': 4.0.4
+
dependencies:
decode-named-character-reference: 1.3.0
@@ -5735,6 +6007,10 @@ snapshots:
dependencies:
entities: 6.0.1
+ dependencies:
+ entities: 8.1.0
+
@@ -5755,6 +6031,8 @@ snapshots:
+
dependencies:
react: 19.3.0
@@ -5898,6 +6176,8 @@ snapshots:
transitivePeerDependencies:
- supports-color
+
optional: true
@@ -5935,6 +6215,10 @@ snapshots:
+ dependencies:
+ xmlchars: 2.2.0
+
@@ -6028,6 +6312,8 @@ snapshots:
+
@@ -6049,6 +6335,20 @@ snapshots:
+
+ dependencies:
+ tldts-core: 7.4.12
+
+ dependencies:
+ tldts: 7.4.12
+
+ dependencies:
+ punycode: 2.3.1
+
@@ -6222,7 +6522,7 @@ snapshots:
optionalDependencies:
dependencies:
'@types/chai': 5.2.3
'@vitest/expect': 3.2.6
@@ -6250,6 +6550,7 @@ snapshots:
optionalDependencies:
'@types/debug': 4.1.13
'@types/node': 22.19.15
+ jsdom: 30.0.1
transitivePeerDependencies:
- jiti
- less
@@ -6264,10 +6565,34 @@ snapshots:
- tsx
- yaml
+ dependencies:
+ xml-name-validator: 5.0.0
+
+
+
+ dependencies:
+ '@exodus/bytes': 1.15.1
+ tr46: 6.0.0
+ webidl-conversions: 8.0.1
+ transitivePeerDependencies:
+ - '@noble/hashes'
+
+ dependencies:
+ '@exodus/bytes': 1.15.1
+ tr46: 6.0.0
+ webidl-conversions: 8.0.1
+ transitivePeerDependencies:
+ - '@noble/hashes'
+
dependencies:
siginfo: 2.0.0
@@ -6301,6 +6626,8 @@ snapshots:
+
dependencies:
'@oozcitak/dom': 2.0.2
@@ -6308,6 +6635,8 @@ snapshots:
'@oozcitak/util': 10.0.0
js-yaml: 4.3.2
+
diff --git a/web/src/components/backlink-checker-tool.tsx b/web/src/components/backlink-checker-tool.tsx
index c3d7be3e..86e3f289 100644
--- a/web/src/components/backlink-checker-tool.tsx
+++ b/web/src/components/backlink-checker-tool.tsx
@@ -1,5 +1,5 @@
import { ToolTable } from "@/lib/free-tools/tool-table";
-import { type FormEvent, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import { FIELD_CLASS, SubmitButton, ToolForm } from "@/lib/free-tools/form";
import { formatCount, InfoTip, MetricGrid } from "@/lib/free-tools/metric-grid";
import { UpsellCard } from "@/lib/free-tools/upsell-card";
@@ -34,8 +34,10 @@ export function BacklinkCheckerTool({
initialTarget?: string;
}) {
const [target, setTarget] = useState("");
- const { status, errorMessage, result, run, turnstile } =
- useToolRun<CheckResult>(TOOL, "/api/backlink-check");
+ const { status, errorMessage, result, run } = useToolRun<CheckResult>(
+ TOOL,
+ "/api/backlink-check",
+ );
// Applied after hydration so the prerendered HTML and the first client
// render agree, whatever ?target= the visitor arrived with.
@@ -43,16 +45,11 @@ export function BacklinkCheckerTool({
if (initialTarget) setTarget(initialTarget);
}, [initialTarget]);
- const handleSubmit = (e: FormEvent) => {
- e.preventDefault();
- void run({ target });
- };
-
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{ target }}
status={status}
errorMessage={errorMessage}
>
diff --git a/web/src/components/competitor-analysis-tool.tsx b/web/src/components/competitor-analysis-tool.tsx
index 33c38139..ec3b6c10 100644
--- a/web/src/components/competitor-analysis-tool.tsx
+++ b/web/src/components/competitor-analysis-tool.tsx
@@ -1,6 +1,6 @@
import { KeywordTable } from "@/lib/free-tools/keyword-table";
import { ToolTable } from "@/lib/free-tools/tool-table";
-import { type FormEvent, useState } from "react";
+import { useState } from "react";
import { DEFAULT_COUNTRY_CODE } from "@/lib/free-tools/countries";
import {
CountrySelect,
@@ -57,23 +57,20 @@ export function CompetitorAnalysisTool() {
const [competitor, setCompetitor] = useState("");
const [yourDomain, setYourDomain] = useState("");
const [locationCode, setLocationCode] = useState(DEFAULT_COUNTRY_CODE);
- const { status, errorMessage, result, run, turnstile } =
- useToolRun<AnalysisResult>(TOOL, "/api/competitor-analysis");
-
- const handleSubmit = (e: FormEvent) => {
- e.preventDefault();
- void run({
- competitor,
- yourDomain: yourDomain.trim() || undefined,
- locationCode,
- });
- };
+ const { status, errorMessage, result, run } = useToolRun<AnalysisResult>(
+ TOOL,
+ "/api/competitor-analysis",
+ );
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{
+ competitor,
+ yourDomain: yourDomain.trim() || undefined,
+ locationCode,
+ }}
status={status}
errorMessage={errorMessage}
>
diff --git a/web/src/components/domain-age-checker-tool.tsx b/web/src/components/domain-age-checker-tool.tsx
index 96a892f8..d46ef34e 100644
--- a/web/src/components/domain-age-checker-tool.tsx
+++ b/web/src/components/domain-age-checker-tool.tsx
@@ -1,5 +1,5 @@
import { ToolTable } from "@/lib/free-tools/tool-table";
-import { type FormEvent, useState } from "react";
+import { useState } from "react";
import { FIELD_CLASS, SubmitButton, ToolForm } from "@/lib/free-tools/form";
import { UpsellCard } from "@/lib/free-tools/upsell-card";
import { useToolRun } from "@/lib/free-tools/use-tool-run";
@@ -38,7 +38,7 @@ function formatAge(row: AgeRow): string {
export function DomainAgeCheckerTool() {
const [domains, setDomains] = useState("");
- const { status, errorMessage, result, run, turnstile } = useToolRun<{
+ const { status, errorMessage, result, run } = useToolRun<{
rows: AgeRow[];
}>(TOOL, "/api/domain-age-checker");
@@ -48,16 +48,11 @@ export function DomainAgeCheckerTool() {
.filter(Boolean);
const overLimit = entered.length > MAX_DOMAINS;
- const handleSubmit = (e: FormEvent) => {
- e.preventDefault();
- void run({ domains: entered.slice(0, MAX_DOMAINS) });
- };
-
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{ domains: entered.slice(0, MAX_DOMAINS) }}
status={status}
errorMessage={errorMessage}
cacheDuration="7 days"
diff --git a/web/src/components/keyword-discovery-tool.tsx b/web/src/components/keyword-discovery-tool.tsx
index d9a24650..0482da0e 100644
--- a/web/src/components/keyword-discovery-tool.tsx
+++ b/web/src/components/keyword-discovery-tool.tsx
@@ -1,4 +1,4 @@
-import { type FormEvent, useState } from "react";
+import { useState } from "react";
import { DEFAULT_COUNTRY_CODE, countryLabel } from "@/lib/free-tools/countries";
import {
CountrySelect,
@@ -26,19 +26,15 @@ export function KeywordDiscoveryTool({
const competitor = tool === "competitor-keyword-finder";
const [input, setInput] = useState("");
const [locationCode, setLocationCode] = useState(DEFAULT_COUNTRY_CODE);
- const { status, errorMessage, result, run, turnstile } = useToolRun<Result>(
+ const { status, errorMessage, result, run } = useToolRun<Result>(
tool,
`/api/${tool}`,
);
- const handleSubmit = (event: FormEvent) => {
- event.preventDefault();
- void run({ [competitor ? "target" : "keyword"]: input, locationCode });
- };
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{ [competitor ? "target" : "keyword"]: input, locationCode }}
status={status}
errorMessage={errorMessage}
>
diff --git a/web/src/components/spam-score-checker-tool.tsx b/web/src/components/spam-score-checker-tool.tsx
index 49676f6e..53bb6b00 100644
--- a/web/src/components/spam-score-checker-tool.tsx
+++ b/web/src/components/spam-score-checker-tool.tsx
@@ -1,5 +1,5 @@
import { ToolTable } from "@/lib/free-tools/tool-table";
-import { type FormEvent, useState } from "react";
+import { useState } from "react";
import { FIELD_CLASS, SubmitButton, ToolForm } from "@/lib/free-tools/form";
import { formatCount, MetricGrid } from "@/lib/free-tools/metric-grid";
import { UpsellCard } from "@/lib/free-tools/upsell-card";
@@ -26,19 +26,16 @@ type SpamResult = {
export function SpamScoreCheckerTool() {
const [target, setTarget] = useState("");
- const { status, errorMessage, result, run, turnstile } =
- useToolRun<SpamResult>(TOOL, "/api/spam-score-checker");
-
- const handleSubmit = (e: FormEvent) => {
- e.preventDefault();
- void run({ target });
- };
+ const { status, errorMessage, result, run } = useToolRun<SpamResult>(
+ TOOL,
+ "/api/spam-score-checker",
+ );
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{ target }}
status={status}
errorMessage={errorMessage}
>
diff --git a/web/src/components/website-traffic-checker-tool.tsx b/web/src/components/website-traffic-checker-tool.tsx
index a877eeb0..33377c59 100644
--- a/web/src/components/website-traffic-checker-tool.tsx
+++ b/web/src/components/website-traffic-checker-tool.tsx
@@ -1,5 +1,5 @@
import { ToolTable } from "@/lib/free-tools/tool-table";
-import { type FormEvent, useState } from "react";
+import { useState } from "react";
import { DEFAULT_COUNTRY_CODE } from "@/lib/free-tools/countries";
import {
CountrySelect,
@@ -51,19 +51,16 @@ export function WebsiteTrafficCheckerTool() {
const [target, setTarget] = useState("");
const [compare, setCompare] = useState("");
const [locationCode, setLocationCode] = useState(DEFAULT_COUNTRY_CODE);
- const { status, errorMessage, result, run, turnstile } =
- useToolRun<TrafficResult>(TOOL, "/api/website-traffic-checker");
-
- const handleSubmit = (e: FormEvent) => {
- e.preventDefault();
- void run({ target, compare: compare.trim() || undefined, locationCode });
- };
+ const { status, errorMessage, result, run } = useToolRun<TrafficResult>(
+ TOOL,
+ "/api/website-traffic-checker",
+ );
return (
<div>
<ToolForm
- onSubmit={handleSubmit}
- turnstileRef={turnstile.containerRef}
+ onSubmit={run}
+ input={{ target, compare: compare.trim() || undefined, locationCode }}
status={status}
errorMessage={errorMessage}
>
diff --git a/web/src/lib/free-tools/form.tsx b/web/src/lib/free-tools/form.tsx
index 2de42d02..f9fb6655 100644
--- a/web/src/lib/free-tools/form.tsx
+++ b/web/src/lib/free-tools/form.tsx
@@ -1,6 +1,24 @@
-import type { FormEvent, ReactNode, RefObject } from "react";
+import {
+ createContext,
+ useContext,
+ useRef,
+ useState,
+ type FormEvent,
+ type ReactNode,
+} from "react";
+import {
+ Turnstile,
+ DEFAULT_SCRIPT_ID,
+ type TurnstileInstance,
+} from "@marsidev/react-turnstile";
import { TOOL_COUNTRIES } from "@/lib/free-tools/countries";
+const SITE_KEY =
+ import.meta.env.VITE_TURNSTILE_SITE_KEY?.trim() ||
+ (import.meta.env.DEV ? "1x00000000000000000000AA" : "");
+type VerificationStatus = "loading" | "ready" | "error";
+const VerificationContext = createContext<VerificationStatus>("loading");
+
export type ToolStatus = "idle" | "loading" | "done" | "error";
export const FIELD_CLASS =
@@ -61,48 +79,132 @@ export function SubmitButton({
idleLabel: string;
loadingLabel?: string;
}) {
+ const verificationStatus = useContext(VerificationContext);
return (
<button
type="submit"
- disabled={status === "loading"}
+ disabled={status === "loading" || verificationStatus !== "ready"}
className="h-11 shrink-0 rounded-lg bg-neutral-950 px-6 text-sm font-medium text-white transition-colors hover:bg-neutral-800 disabled:opacity-50"
>
- {status === "loading" ? loadingLabel : idleLabel}
+ {status === "loading"
+ ? loadingLabel
+ : verificationStatus === "loading"
+ ? "Verifying…"
+ : idleLabel}
</button>
);
}
/**
- * The card every tool form lives in: fields, the invisible Turnstile mount,
- * the "Free · No signup" microcopy, and the error line.
+ * Every API-backed tool submits through this form. It owns verification and
+ * supplies button readiness through context so individual tools cannot drift.
*/
export function ToolForm({
onSubmit,
- turnstileRef,
+ input,
status,
errorMessage,
cacheDuration = "24 hours",
children,
}: {
- onSubmit: (event: FormEvent) => void;
- turnstileRef?: RefObject<HTMLDivElement | null>;
+ onSubmit: (input: Record<string, unknown>, token: string) => Promise<void>;
+ input: Record<string, unknown>;
status: ToolStatus;
errorMessage: string;
cacheDuration?: string;
children: ReactNode;
}) {
+ const widget = useRef<TurnstileInstance>(null);
+ const token = useRef("");
+ const submitting = useRef(false);
+ const scriptFailed = useRef(false);
+ const [widgetKey, setWidgetKey] = useState(0);
+ const [verification, setVerification] = useState<VerificationStatus>(
+ SITE_KEY ? "loading" : "error",
+ );
+ const updateToken = (value = "") => {
+ token.current = value;
+ setVerification(value ? "ready" : "loading");
+ };
+ const fail = () => {
+ token.current = "";
+ setVerification("error");
+ };
+ const retry = () => {
+ if (!SITE_KEY) return;
+ updateToken();
+ if (scriptFailed.current) {
+ document.getElementById(DEFAULT_SCRIPT_ID)?.remove();
+ scriptFailed.current = false;
+ setWidgetKey((key) => key + 1);
+ } else {
+ widget.current?.reset();
+ }
+ };
+ const submit = async (event: FormEvent) => {
+ event.preventDefault();
+ if (submitting.current || !token.current) return;
+ if (widget.current?.isExpired()) return retry();
+ const verifiedToken = token.current;
+ updateToken();
+ submitting.current = true;
+ try {
+ await onSubmit(input, verifiedToken);
+ } finally {
+ submitting.current = false;
+ updateToken();
+ widget.current?.reset();
+ }
+ };
return (
<form
- onSubmit={onSubmit}
+ onSubmit={submit}
className="rounded-xl border border-[var(--color-border-subtle)] bg-white p-4 md:p-5"
>
- {children}
- {turnstileRef ? (
- <div ref={turnstileRef} className="empty:hidden" />
+ <VerificationContext.Provider value={verification}>
+ {children}
+ </VerificationContext.Provider>
+ {SITE_KEY ? (
+ <Turnstile
+ key={widgetKey}
+ ref={widget}
+ siteKey={SITE_KEY}
+ options={{ appearance: "interaction-only", action: "free_tool" }}
+ onSuccess={updateToken}
+ onExpire={() => updateToken()}
+ onError={fail}
+ onTimeout={fail}
+ onUnsupported={fail}
+ scriptOptions={{
+ onError: () => {
+ scriptFailed.current = true;
+ fail();
+ },
+ }}
+ />
) : null}
<p className="mt-2.5 text-xs text-[var(--color-brand-muted)]">
Free &middot; No signup
</p>
+ {verification === "loading" && status !== "loading" ? (
+ <p
+ role="status"
+ className="mt-2 text-xs text-[var(--color-brand-muted)]"
+ >
+ Verifying your browser. Complete the check above if prompted.
+ </p>
+ ) : null}
+ {verification === "error" ? (
+ <div role="alert" className="mt-2 text-sm text-red-600">
+ <p>
+ Verification could not complete. Check your connection and try
+ again.
+ </p>
+ <button type="button" onClick={retry} className="mt-1 underline">
+ Retry verification
+ </button>
+ </div>
+ ) : null}
{status === "error" && errorMessage ? (
<p role="alert" className="mt-2 text-sm text-red-600">
{errorMessage}
diff --git a/web/src/lib/free-tools/turnstile.ts b/web/src/lib/free-tools/turnstile.ts
deleted file mode 100644
index 9d8d23d1..00000000
--- a/web/src/lib/free-tools/turnstile.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import { useEffect, useRef } from "react";
-
-// Public site key. Cloudflare's always-passing test key is the dev-only
-// fallback; a build without VITE_TURNSTILE_SITE_KEY renders no widget.
-const TURNSTILE_SITE_KEY =
- (import.meta.env.VITE_TURNSTILE_SITE_KEY as string | undefined)?.trim() ||
- (import.meta.env.DEV ? "1x00000000000000000000AA" : "");
-
-// A deployable build without this key is rejected by the
-// openseo:require-turnstile-site-key plugin in vite.config.ts — a throw here
-// would only be swallowed by the prerenderer.
-
-/** How long a submit waits for the widget to produce its first token. */
-const TOKEN_WAIT_MS = 3_000;
-
-type TurnstileApi = {
- render(
- container: HTMLElement,
- options: {
- sitekey: string;
- appearance?: string;
- action?: string;
- callback: (token: string) => void;
- "expired-callback"?: () => void;
- },
- ): string;
- reset(widgetId?: string): void;
-};
-
-/**
- * Renders Turnstile into `containerRef`. `waitForToken()` waits for verification;
- * `reset()` clears the single-use token after every submit.
- */
-export function useTurnstile() {
- const containerRef = useRef<HTMLDivElement>(null);
- const widgetIdRef = useRef<string | null>(null);
- const tokenRef = useRef("");
-
- useEffect(() => {
- if (!TURNSTILE_SITE_KEY) return;
- const w = window as unknown as {
- turnstile?: TurnstileApi;
- onloadTurnstileCallback?: () => void;
- };
- const renderWidget = () => {
- if (!w.turnstile || !containerRef.current) return;
- if (widgetIdRef.current !== null) return;
- widgetIdRef.current = w.turnstile.render(containerRef.current, {
- sitekey: TURNSTILE_SITE_KEY,
- // Invisible unless Turnstile decides the visitor needs a challenge.
- appearance: "interaction-only",
- action: "free_tool",
- callback: (token) => {
- tokenRef.current = token;
- },
- "expired-callback": () => {
- tokenRef.current = "";
- },
- });
- };
-
- if (w.turnstile) {
- renderWidget();
- return;
- }
- w.onloadTurnstileCallback = renderWidget;
- if (!document.querySelector("script[data-turnstile]")) {
- const script = document.createElement("script");
- script.src =
- "https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback";
- script.async = true;
- script.dataset.turnstile = "true";
- document.head.appendChild(script);
- }
- }, []);
-
- return {
- containerRef,
- /**
- * Turnstile solves asynchronously, so an immediate first submit can race
- * the widget and come back 403. Wait briefly for a token instead of
- * POSTing without one. Resolves immediately when Turnstile isn't
- * configured. Local development uses a public test site key.
- */
- waitForToken: async () => {
- if (!TURNSTILE_SITE_KEY) return undefined;
- const deadline = Date.now() + TOKEN_WAIT_MS;
- while (!tokenRef.current && Date.now() < deadline) {
- await new Promise((resolve) => setTimeout(resolve, 100));
- }
- return tokenRef.current || undefined;
- },
- reset: () => {
- tokenRef.current = "";
- const w = window as unknown as { turnstile?: TurnstileApi };
- if (w.turnstile && widgetIdRef.current !== null) {
- w.turnstile.reset(widgetIdRef.current);
- }
- },
- };
-}
diff --git a/web/src/lib/free-tools/use-tool-run.ts b/web/src/lib/free-tools/use-tool-run.ts
index d692a871..abe5ce2e 100644
--- a/web/src/lib/free-tools/use-tool-run.ts
+++ b/web/src/lib/free-tools/use-tool-run.ts
@@ -1,26 +1,22 @@
import { useState } from "react";
import { trackTool } from "@/lib/free-tools/analytics";
import type { ToolStatus } from "@/lib/free-tools/form";
-import { useTurnstile } from "@/lib/free-tools/turnstile";
/**
* The submit cycle every API-backed free tool shares: status machine, error
- * message, Plausible events, and a single-use Turnstile token.
+ * message and Plausible events. ToolForm supplies the verified token.
*/
export function useToolRun<T>(tool: string, path: string) {
const [status, setStatus] = useState<ToolStatus>("idle");
const [errorMessage, setErrorMessage] = useState("");
const [result, setResult] = useState<T | null>(null);
- const turnstile = useTurnstile();
- const run = async (body: Record<string, unknown>) => {
+ const run = async (body: Record<string, unknown>, turnstileToken: string) => {
+ if (!turnstileToken) return;
setStatus("loading");
setErrorMessage("");
trackTool("tool_run", tool);
try {
- // Blocks only while Turnstile is still solving; resolves immediately
- // when no widget is configured.
- const turnstileToken = await turnstile.waitForToken();
const res = await fetch(path, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -42,11 +38,8 @@ export function useToolRun<T>(tool: string, path: string) {
setErrorMessage(
err instanceof Error ? err.message : "Something went wrong",
);
- } finally {
- // Turnstile tokens are single-use; get a fresh one for the next run.
- turnstile.reset();
}
};
- return { status, errorMessage, result, run, turnstile };
+ return { status, errorMessage, result, run };
}
diff --git a/web/tests/free-tool-verification.test.ts b/web/tests/free-tool-verification.test.ts
new file mode 100644
index 00000000..373393fb
--- /dev/null
+++ b/web/tests/free-tool-verification.test.ts
@@ -0,0 +1,172 @@
+// @vitest-environment jsdom
+import { act, createElement, type ComponentType } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import type { TurnstileProps } from "@marsidev/react-turnstile";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { ToolForm, SubmitButton } from "../src/lib/free-tools/form";
+
+const widget = vi.hoisted(() => ({
+ props: {} as TurnstileProps,
+ reset: vi.fn(),
+ isExpired: vi.fn(() => false),
+}));
+vi.mock("@marsidev/react-turnstile", async () => {
+ const { forwardRef, useImperativeHandle } = await import("react");
+ return {
+ DEFAULT_SCRIPT_ID: "cf-turnstile-script",
+ Turnstile: forwardRef((props: TurnstileProps, ref) => {
+ widget.props = props;
+ useImperativeHandle(ref, () => widget);
+ return null;
+ }),
+ };
+});
+let root: Root;
+let host: HTMLDivElement;
+let onSubmit: ReturnType<typeof vi.fn>;
+beforeEach(async () => {
+ vi.clearAllMocks();
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ root = createRoot(host);
+ onSubmit = vi.fn().mockResolvedValue(undefined);
+ await act(async () =>
+ root.render(
+ createElement(ToolForm, {
+ onSubmit,
+ input: { target: "example.com" },
+ status: "idle",
+ errorMessage: "",
+ children: createElement(SubmitButton, {
+ status: "idle",
+ idleLabel: "Check",
+ }),
+ }),
+ ),
+ );
+});
+afterEach(async () => {
+ await act(async () => root.unmount());
+ host.remove();
+ vi.unstubAllGlobals();
+});
+const submit = async () =>
+ act(async () => {
+ host
+ .querySelector("form")!
+ .dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
+ });
+const solve = async () =>
+ act(async () => widget.props.onSuccess!("verified-token"));
+const button = () =>
+ host.querySelector<HTMLButtonElement>('button[type="submit"]')!;
+
+it("does not submit or restart verification until a token exists", async () => {
+ expect(button().disabled).toBe(true);
+ await submit();
+ expect(onSubmit).not.toHaveBeenCalled();
+ expect(widget.reset).not.toHaveBeenCalled();
+ await solve();
+ expect(button().disabled).toBe(false);
+ await submit();
+ expect(onSubmit).toHaveBeenCalledWith(
+ { target: "example.com" },
+ "verified-token",
+ );
+ expect(widget.reset).toHaveBeenCalledOnce();
+ await submit();
+ expect(onSubmit).toHaveBeenCalledOnce();
+});
+
+it("blocks duplicate submissions and requires a fresh token for the next request", async () => {
+ let finish!: () => void;
+ onSubmit.mockImplementationOnce(
+ () =>
+ new Promise<void>((resolve) => {
+ finish = resolve;
+ }),
+ );
+ await solve();
+ await submit();
+ await submit();
+ expect(onSubmit).toHaveBeenCalledOnce();
+ await act(async () => finish());
+ expect(button().disabled).toBe(true);
+ await solve();
+ await submit();
+ expect(onSubmit).toHaveBeenCalledTimes(2);
+});
+
+it.each(["onExpire", "onError", "onTimeout", "onUnsupported"] as const)(
+ "%s invalidates a ready token",
+ async (callback) => {
+ await solve();
+ await act(async () => widget.props[callback]!("test-error"));
+ await submit();
+ expect(onSubmit).not.toHaveBeenCalled();
+ expect(button().disabled).toBe(true);
+ await solve();
+ await submit();
+ expect(onSubmit).toHaveBeenCalledOnce();
+ },
+);
+
+it("checks expiry at submit time and retries script failures without submitting", async () => {
+ await solve();
+ widget.isExpired.mockReturnValueOnce(true);
+ await submit();
+ expect(onSubmit).not.toHaveBeenCalled();
+ const script = document.createElement("script");
+ script.id = "cf-turnstile-script";
+ document.head.appendChild(script);
+ await act(async () => widget.props.scriptOptions!.onError!());
+ expect(host.textContent).toContain("Verification could not complete");
+ await act(async () =>
+ host.querySelector<HTMLButtonElement>('button[type="button"]')!.click(),
+ );
+ expect(script.isConnected).toBe(false);
+ await solve();
+ await submit();
+ expect(onSubmit).toHaveBeenCalledOnce();
+});
+
+const tools = [
+ ["backlink-checker", "BacklinkCheckerTool", "backlink-check"],
+ ["spam-score-checker", "SpamScoreCheckerTool", "spam-score-checker"],
+ [
+ "website-traffic-checker",
+ "WebsiteTrafficCheckerTool",
+ "website-traffic-checker",
+ ],
+ ["competitor-analysis", "CompetitorAnalysisTool", "competitor-analysis"],
+ ["domain-age-checker", "DomainAgeCheckerTool", "domain-age-checker"],
+ ["keyword-discovery", "KeywordDiscoveryTool", "keyword-generator"],
+ ["keyword-discovery", "KeywordDiscoveryTool", "competitor-keyword-finder"],
+];
+it.each(tools)(
+ "%s routes %s through the verified form (%s)",
+ async (file, name, endpoint) => {
+ const module = await import(`../src/components/${file}-tool.tsx`);
+ const Component = module[name] as ComponentType<Record<string, unknown>>;
+ const fetchMock = vi
+ .fn()
+ .mockResolvedValue(
+ Response.json({ error: "Try again" }, { status: 503 }),
+ );
+ vi.stubGlobal("fetch", fetchMock);
+ await act(async () =>
+ root.render(createElement(Component, { tool: endpoint })),
+ );
+ await submit();
+ expect(fetchMock).not.toHaveBeenCalled();
+ await solve();
+ await submit();
+ expect(fetchMock).toHaveBeenCalledOnce();
+ expect(fetchMock.mock.calls[0][0]).toBe(`/api/${endpoint}`);
+ expect(JSON.parse(fetchMock.mock.calls[0][1].body).turnstileToken).toBe(
+ "verified-token",
+ );
+ expect(button().disabled).toBe(true);
+ },
+);