Skip to main content

@rtorcato/cf-common

Interfaces​

TurnstileResult​

Defined in: index.ts:7

The siteverify response. See Cloudflare's Turnstile docs for error-codes.

Properties​

success​

success: boolean

Defined in: index.ts:8

challenge_ts?​

optional challenge_ts?: string

Defined in: index.ts:10

ISO timestamp of the challenge, when success.

hostname?​

optional hostname?: string

Defined in: index.ts:11

action?​

optional action?: string

Defined in: index.ts:12

cdata?​

optional cdata?: string

Defined in: index.ts:13

error-codes?​

optional error-codes?: string[]

Defined in: index.ts:14

Functions​

verifyTurnstile()​

verifyTurnstile(token, secret, options?): Promise<TurnstileResult>

Defined in: index.ts:26

Verify a Turnstile token server-side. Returns the raw siteverify result — inspect .success. Throws a CloudflareError only if the HTTP call itself fails (not on a failed challenge, which is a normal success: false).

Example​

const result = await verifyTurnstile(token, env.TURNSTILE_SECRET, { remoteip })
if (!result.success) return error(403, 'Failed challenge')

Parameters​

token​

string

secret​

string

options?​
remoteip?​

string

Returns​

Promise<TurnstileResult>


assertTurnstile()​

assertTurnstile(token, secret, options?): Promise<TurnstileResult>

Defined in: index.ts:51

Like verifyTurnstile but throws a 403 CloudflareError on a failed challenge, so callers can rely on the token being valid past this point. The code carries Turnstile's first error-code for branching.

Parameters​

token​

string

secret​

string

options?​
remoteip?​

string

Returns​

Promise<TurnstileResult>