@mistriwork/challenge-turnstile
v1.4.2
Published
Cloudflare Turnstile human-check pack for mistri Apps' public doors (auth.challenge), with a local test stub and zero extra dependencies.
Maintainers
Readme
@mistriwork/challenge-turnstile
Cloudflare Turnstile human-check pack for mistri Apps' public doors (auth.challenge), with a local loopback stub for automated node and browser tests and zero external dependencies.
Install
npm install @mistriwork/challenge-turnstileUsage
Declare the verifier in your App's commands.ts:
import { defineChallenges } from '@mistriwork/mistri/commands';
import { turnstile } from '@mistriwork/challenge-turnstile';
export const challenges = defineChallenges({
verifyHuman: turnstile({
siteKey: process.env.TURNSTILE_SITE_KEY!,
secret: process.env.TURNSTILE_SECRET!,
}),
});Then enable it in app.ts:
auth: {
challenge: 'verifyHuman',
}Local Testing (turnstileStub)
Use turnstileStub() in node and Playwright tests to run a local loopback siteverify endpoint and widget script without hitting Cloudflare:
import { turnstile, turnstileStub } from '@mistriwork/challenge-turnstile';
const stub = await turnstileStub();
const verifyHuman = turnstile({
siteKey: 'test-site-key',
secret: stub.secret,
verifyUrl: stub.verifyUrl,
scriptUrl: stub.scriptUrl,
});Options (TurnstileOptions)
| Option | Description |
| --- | --- |
| siteKey | Public Turnstile site key rendered in the browser widget. |
| secret | Server-side secret key sent to Cloudflare siteverify (never exposed to the client). |
| hostnames | Allowed hostnames for issued tokens (defaults to the request's Host). |
| action | Expected Turnstile widget action name. |
| timeoutMs | Verification request timeout in milliseconds (default 4000). |
| verifyUrl | Custom siteverify URL (for turnstileStub()). |
| scriptUrl | Custom widget script URL (for turnstileStub()). |
| fetch | Custom fetch implementation for unit tests. |
