Skip to content

API reference

captcha.turnstile(options) creates a Cloudflare Turnstile guard. captcha.recaptcha(options) creates a Google reCAPTCHA guard from an existing Google widget.

Terminal window
import { captcha } from "@layeron/modules"

Create a Cloudflare Turnstile Captcha guard.

TypeSpec operation: turnstile.

Terminal window
captcha.turnstile(options: CaptchaTurnstileOptions): CaptchaModule

One request location that may contain a CAPTCHA token.

FieldTypeDescription
kindCaptchaTokenSourceKindRequest location kind.
namestringHeader, form field, or JSON property name.

Failure response returned by automatic guards and manual result.response().

FieldTypeDescription
statusint32 | undefinedHTTP error status returned when verification fails.
bodyunknown | undefinedJSON body returned when verification fails.

Custom request locations used to read CAPTCHA tokens.

FieldTypeDescription
headerstring | undefinedHeader name that carries the token.
formstring | undefinedForm field name that carries the token.
jsonstring | undefinedJSON property name that carries the token.

Reference to a Layeron secret.

FieldTypeDescription
kind”secret_ref”Secret reference discriminator.
namestringLayeron secret name.

Options accepted by captcha.turnstile().

FieldTypeDescription
namestringStable Captcha instance name.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
modeTurnstileMode | undefinedCloudflare Turnstile widget mode. Defaults to managed.
domainsstring[] | undefinedAllowed hostnames returned by the provider Siteverify response.
actionstring | undefinedExpected provider action value for this flow.
cDatastring | undefinedExpected Cloudflare Turnstile cData value for this flow.
sitekeystring | undefinedExisting Turnstile sitekey to adopt. Omit it to let Layeron create and maintain the widget.
secretSecretRef | undefinedLayeron secret reference for an adopted Turnstile widget secret.
tokenFromCaptchaTokenSourceOptions | undefinedCustom request locations used to read the token.
failureCaptchaFailureOptions | undefinedFailure response used by automatic guards and manual result.response().
devCaptchaDevOptions | undefinedLocal development options.

Local development Captcha behavior.

FieldTypeDescription
mode”bypass” | undefinedBypass provider verification in local or test environments.

Options accepted by captcha.recaptcha().

FieldTypeDescription
namestringStable Captcha instance name.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
sitekeystringGoogle reCAPTCHA public sitekey.
secretSecretRefLayeron secret reference for the Google reCAPTCHA secret.
domainsstring[] | undefinedAllowed hostnames returned by the provider Siteverify response.
actionstring | undefinedExpected provider action value for this flow.
minScorefloat64 | undefinedMinimum accepted Google reCAPTCHA score from 0 to 1.
tokenFromCaptchaTokenSourceOptions | undefinedCustom request locations used to read the token.
failureCaptchaFailureOptions | undefinedFailure response used by automatic guards and manual result.response().
devCaptchaDevOptions | undefinedLocal development options.

Normalized configuration for a Cloudflare Turnstile Captcha instance.

FieldTypeDescription
kind”captcha”Module config kind.
providerCaptchaProviderProvider used by this Captcha instance.
namestringStable Captcha instance name.
namespacestringPlatform namespace for the instance. Defaults to default.
modeTurnstileModeCloudflare Turnstile widget mode.
domainsstring[] | undefinedAllowed hostnames returned by the provider Siteverify response.
actionstring | undefinedExpected provider action value for this flow.
cDatastring | undefinedExpected Cloudflare Turnstile cData value for this flow.
sitekeystring | undefinedExisting or generated public sitekey.
secretRefSecretRef | undefinedLayeron secret reference for an adopted Turnstile widget secret.
tokenSourcesCaptchaTokenSource[]Request locations used to read the token.
failureCaptchaFailureOptionsFailure response used by automatic guards and manual result.response().
devCaptchaDevOptions | undefinedLocal development options.

Normalized configuration for a Google reCAPTCHA Captcha instance.

FieldTypeDescription
kind”captcha”Module config kind.
providerCaptchaProviderProvider used by this Captcha instance.
namestringStable Captcha instance name.
namespacestringPlatform namespace for the instance. Defaults to default.
domainsstring[] | undefinedAllowed hostnames returned by the provider Siteverify response.
actionstring | undefinedExpected provider action value for this flow.
minScorefloat64 | undefinedMinimum accepted Google reCAPTCHA score from 0 to 1.
sitekeystringGoogle reCAPTCHA public sitekey.
secretRefSecretRefLayeron secret reference for the Google reCAPTCHA secret.
tokenSourcesCaptchaTokenSource[]Request locations used to read the token.
failureCaptchaFailureOptionsFailure response used by automatic guards and manual result.response().
devCaptchaDevOptions | undefinedLocal development options.

Layeron Captcha module returned by captcha.turnstile() or captcha.recaptcha().

FieldTypeDescription
name”captcha”Module name.
configCaptchaTurnstileConfig | CaptchaRecaptchaConfigNormalized module configuration.

Manual Captcha verification input.

FieldTypeDescription
tokenstring | undefinedProvider token. verify(request) can extract the token from configured token sources.
remoteIpstring | undefinedRemote user IP sent to the provider Siteverify endpoint.
idempotencyKeystring | undefinedIdempotency key forwarded to providers that support it.
hostnamestring | undefinedExpected hostname for this verification call.
actionstring | undefinedExpected provider action for this verification call.
cDatastring | undefinedExpected Cloudflare Turnstile cData for this verification call.
minScorefloat64 | undefinedMinimum accepted Google reCAPTCHA score from 0 to 1 for this verification call.

Manual Captcha verification input used after the token is passed separately.

FieldTypeDescription
remoteIpstring | undefinedRemote user IP sent to the provider Siteverify endpoint.
idempotencyKeystring | undefinedIdempotency key forwarded to providers that support it.
hostnamestring | undefinedExpected hostname for this verification call.
actionstring | undefinedExpected provider action for this verification call.
cDatastring | undefinedExpected Cloudflare Turnstile cData for this verification call.
minScorefloat64 | undefinedMinimum accepted Google reCAPTCHA score from 0 to 1 for this verification call.

Result returned by manual Captcha verification.

FieldTypeDescription
okbooleanTrue when provider verification and Layeron validation pass.
successbooleanProvider-compatible success flag.
errorCodesstring[]Provider errors and Layeron validation error codes.
hostnamestring | undefinedHostname returned by the provider Siteverify response.
actionstring | undefinedAction returned by the provider Siteverify response.
cDatastring | undefinedCloudflare Turnstile cData returned by the provider Siteverify response.
scorefloat64 | undefinedGoogle reCAPTCHA score returned by the provider Siteverify response.
challengeTsstring | undefinedChallenge timestamp returned by the provider Siteverify response.

Request location used to read a CAPTCHA token.

ValueDescription
headerRead the token from an HTTP request header.
formRead the token from a submitted form field.
jsonRead the token from a JSON request body field.

Cloudflare Turnstile widget interaction mode.

ValueDescription
managedCloudflare managed challenge mode.
invisibleInvisible challenge mode.
non-interactiveNon-interactive challenge mode.

CAPTCHA provider verified by the Captcha module.

ValueDescription
cloudflare_turnstileCloudflare Turnstile verification.
google_recaptchaGoogle reCAPTCHA verification.

Create a Google reCAPTCHA guard from an existing Google widget.

TypeSpec operation: recaptcha.

Terminal window
captcha.recaptcha(options: CaptchaRecaptchaOptions): CaptchaModule

Verify a Captcha request or token with manual control flow.

TypeSpec operation: verify.

Terminal window
captcha.verify(input: CaptchaVerifyInput): CaptchaVerifyResult

Verify an explicit Captcha token with manual control flow.

TypeSpec operation: verifyToken.

Terminal window
captcha.verifyToken(token: string, input?: CaptchaVerifyTokenInput): CaptchaVerifyResult

These TypeScript result contracts are part of the public module API.

Result
TurnstileSiteverifyResponse
RecaptchaSiteverifyResponse