API reference
captcha.turnstile(options) creates a Cloudflare Turnstile guard. captcha.recaptcha(options) creates a Google reCAPTCHA guard from an existing Google widget.
Import
Section titled “Import”import { captcha } from "@layeron/modules"captcha.turnstile
Section titled “captcha.turnstile”Create a Cloudflare Turnstile Captcha guard.
TypeSpec operation: turnstile.
captcha.turnstile(options: CaptchaTurnstileOptions): CaptchaModuleCaptchaTokenSource
Section titled “CaptchaTokenSource”One request location that may contain a CAPTCHA token.
| Field | Type | Description |
|---|---|---|
kind | CaptchaTokenSourceKind | Request location kind. |
name | string | Header, form field, or JSON property name. |
CaptchaFailureOptions
Section titled “CaptchaFailureOptions”Failure response returned by automatic guards and manual result.response().
| Field | Type | Description |
|---|---|---|
status | int32 | undefined | HTTP error status returned when verification fails. |
body | unknown | undefined | JSON body returned when verification fails. |
CaptchaTokenSourceOptions
Section titled “CaptchaTokenSourceOptions”Custom request locations used to read CAPTCHA tokens.
| Field | Type | Description |
|---|---|---|
header | string | undefined | Header name that carries the token. |
form | string | undefined | Form field name that carries the token. |
json | string | undefined | JSON property name that carries the token. |
SecretRef
Section titled “SecretRef”Reference to a Layeron secret.
| Field | Type | Description |
|---|---|---|
kind | ”secret_ref” | Secret reference discriminator. |
name | string | Layeron secret name. |
CaptchaTurnstileOptions
Section titled “CaptchaTurnstileOptions”Options accepted by captcha.turnstile().
| Field | Type | Description |
|---|---|---|
name | string | Stable Captcha instance name. |
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
mode | TurnstileMode | undefined | Cloudflare Turnstile widget mode. Defaults to managed. |
domains | string[] | undefined | Allowed hostnames returned by the provider Siteverify response. |
action | string | undefined | Expected provider action value for this flow. |
cData | string | undefined | Expected Cloudflare Turnstile cData value for this flow. |
sitekey | string | undefined | Existing Turnstile sitekey to adopt. Omit it to let Layeron create and maintain the widget. |
secret | SecretRef | undefined | Layeron secret reference for an adopted Turnstile widget secret. |
tokenFrom | CaptchaTokenSourceOptions | undefined | Custom request locations used to read the token. |
failure | CaptchaFailureOptions | undefined | Failure response used by automatic guards and manual result.response(). |
dev | CaptchaDevOptions | undefined | Local development options. |
CaptchaDevOptions
Section titled “CaptchaDevOptions”Local development Captcha behavior.
| Field | Type | Description |
|---|---|---|
mode | ”bypass” | undefined | Bypass provider verification in local or test environments. |
CaptchaRecaptchaOptions
Section titled “CaptchaRecaptchaOptions”Options accepted by captcha.recaptcha().
| Field | Type | Description |
|---|---|---|
name | string | Stable Captcha instance name. |
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
sitekey | string | Google reCAPTCHA public sitekey. |
secret | SecretRef | Layeron secret reference for the Google reCAPTCHA secret. |
domains | string[] | undefined | Allowed hostnames returned by the provider Siteverify response. |
action | string | undefined | Expected provider action value for this flow. |
minScore | float64 | undefined | Minimum accepted Google reCAPTCHA score from 0 to 1. |
tokenFrom | CaptchaTokenSourceOptions | undefined | Custom request locations used to read the token. |
failure | CaptchaFailureOptions | undefined | Failure response used by automatic guards and manual result.response(). |
dev | CaptchaDevOptions | undefined | Local development options. |
CaptchaTurnstileConfig
Section titled “CaptchaTurnstileConfig”Normalized configuration for a Cloudflare Turnstile Captcha instance.
| Field | Type | Description |
|---|---|---|
kind | ”captcha” | Module config kind. |
provider | CaptchaProvider | Provider used by this Captcha instance. |
name | string | Stable Captcha instance name. |
namespace | string | Platform namespace for the instance. Defaults to default. |
mode | TurnstileMode | Cloudflare Turnstile widget mode. |
domains | string[] | undefined | Allowed hostnames returned by the provider Siteverify response. |
action | string | undefined | Expected provider action value for this flow. |
cData | string | undefined | Expected Cloudflare Turnstile cData value for this flow. |
sitekey | string | undefined | Existing or generated public sitekey. |
secretRef | SecretRef | undefined | Layeron secret reference for an adopted Turnstile widget secret. |
tokenSources | CaptchaTokenSource[] | Request locations used to read the token. |
failure | CaptchaFailureOptions | Failure response used by automatic guards and manual result.response(). |
dev | CaptchaDevOptions | undefined | Local development options. |
CaptchaRecaptchaConfig
Section titled “CaptchaRecaptchaConfig”Normalized configuration for a Google reCAPTCHA Captcha instance.
| Field | Type | Description |
|---|---|---|
kind | ”captcha” | Module config kind. |
provider | CaptchaProvider | Provider used by this Captcha instance. |
name | string | Stable Captcha instance name. |
namespace | string | Platform namespace for the instance. Defaults to default. |
domains | string[] | undefined | Allowed hostnames returned by the provider Siteverify response. |
action | string | undefined | Expected provider action value for this flow. |
minScore | float64 | undefined | Minimum accepted Google reCAPTCHA score from 0 to 1. |
sitekey | string | Google reCAPTCHA public sitekey. |
secretRef | SecretRef | Layeron secret reference for the Google reCAPTCHA secret. |
tokenSources | CaptchaTokenSource[] | Request locations used to read the token. |
failure | CaptchaFailureOptions | Failure response used by automatic guards and manual result.response(). |
dev | CaptchaDevOptions | undefined | Local development options. |
CaptchaModule
Section titled “CaptchaModule”Layeron Captcha module returned by captcha.turnstile() or captcha.recaptcha().
| Field | Type | Description |
|---|---|---|
name | ”captcha” | Module name. |
config | CaptchaTurnstileConfig | CaptchaRecaptchaConfig | Normalized module configuration. |
CaptchaVerifyInput
Section titled “CaptchaVerifyInput”Manual Captcha verification input.
| Field | Type | Description |
|---|---|---|
token | string | undefined | Provider token. verify(request) can extract the token from configured token sources. |
remoteIp | string | undefined | Remote user IP sent to the provider Siteverify endpoint. |
idempotencyKey | string | undefined | Idempotency key forwarded to providers that support it. |
hostname | string | undefined | Expected hostname for this verification call. |
action | string | undefined | Expected provider action for this verification call. |
cData | string | undefined | Expected Cloudflare Turnstile cData for this verification call. |
minScore | float64 | undefined | Minimum accepted Google reCAPTCHA score from 0 to 1 for this verification call. |
CaptchaVerifyTokenInput
Section titled “CaptchaVerifyTokenInput”Manual Captcha verification input used after the token is passed separately.
| Field | Type | Description |
|---|---|---|
remoteIp | string | undefined | Remote user IP sent to the provider Siteverify endpoint. |
idempotencyKey | string | undefined | Idempotency key forwarded to providers that support it. |
hostname | string | undefined | Expected hostname for this verification call. |
action | string | undefined | Expected provider action for this verification call. |
cData | string | undefined | Expected Cloudflare Turnstile cData for this verification call. |
minScore | float64 | undefined | Minimum accepted Google reCAPTCHA score from 0 to 1 for this verification call. |
CaptchaVerifyResult
Section titled “CaptchaVerifyResult”Result returned by manual Captcha verification.
| Field | Type | Description |
|---|---|---|
ok | boolean | True when provider verification and Layeron validation pass. |
success | boolean | Provider-compatible success flag. |
errorCodes | string[] | Provider errors and Layeron validation error codes. |
hostname | string | undefined | Hostname returned by the provider Siteverify response. |
action | string | undefined | Action returned by the provider Siteverify response. |
cData | string | undefined | Cloudflare Turnstile cData returned by the provider Siteverify response. |
score | float64 | undefined | Google reCAPTCHA score returned by the provider Siteverify response. |
challengeTs | string | undefined | Challenge timestamp returned by the provider Siteverify response. |
CaptchaTokenSourceKind
Section titled “CaptchaTokenSourceKind”Request location used to read a CAPTCHA token.
| Value | Description |
|---|---|
header | Read the token from an HTTP request header. |
form | Read the token from a submitted form field. |
json | Read the token from a JSON request body field. |
TurnstileMode
Section titled “TurnstileMode”Cloudflare Turnstile widget interaction mode.
| Value | Description |
|---|---|
managed | Cloudflare managed challenge mode. |
invisible | Invisible challenge mode. |
non-interactive | Non-interactive challenge mode. |
CaptchaProvider
Section titled “CaptchaProvider”CAPTCHA provider verified by the Captcha module.
| Value | Description |
|---|---|
cloudflare_turnstile | Cloudflare Turnstile verification. |
google_recaptcha | Google reCAPTCHA verification. |
Operations
Section titled “Operations”captcha.recaptcha
Section titled “captcha.recaptcha”Create a Google reCAPTCHA guard from an existing Google widget.
TypeSpec operation: recaptcha.
captcha.recaptcha(options: CaptchaRecaptchaOptions): CaptchaModulecaptcha.verify
Section titled “captcha.verify”Verify a Captcha request or token with manual control flow.
TypeSpec operation: verify.
captcha.verify(input: CaptchaVerifyInput): CaptchaVerifyResultcaptcha.verifyToken
Section titled “captcha.verifyToken”Verify an explicit Captcha token with manual control flow.
TypeSpec operation: verifyToken.
captcha.verifyToken(token: string, input?: CaptchaVerifyTokenInput): CaptchaVerifyResultTypeScript result contracts
Section titled “TypeScript result contracts”These TypeScript result contracts are part of the public module API.
| Result |
|---|
TurnstileSiteverifyResponse |
RecaptchaSiteverifyResponse |