Fix turnstile
This commit is contained in:
Vendored
+28
-28
@@ -1,15 +1,13 @@
|
||||
import 'server-only';
|
||||
import type { BasePayload } from 'payload';
|
||||
export type SubmitFormArgs = {
|
||||
/**
|
||||
* Name of the GDPR consent checkbox. A field with this name must be checked
|
||||
* for the submission to succeed (enforced server-side). Defaults to 'consent'.
|
||||
*/
|
||||
consentFieldName?: string;
|
||||
/** Submitted field data — shape matches the form's fields. */
|
||||
data: Record<string, unknown>;
|
||||
payload: BasePayload;
|
||||
/** Form-builder form ID this submission belongs to. */
|
||||
formId: string;
|
||||
/** Submitted field data — shape matches the form's fields. */
|
||||
data: Record<string, unknown>;
|
||||
/** Turnstile token; when present it is verified, when absent it is skipped. */
|
||||
turnstileToken?: string;
|
||||
/** Client IP — used for Turnstile and rate limiting. */
|
||||
ip?: string;
|
||||
/**
|
||||
@@ -17,15 +15,17 @@ export type SubmitFormArgs = {
|
||||
* Set to 0 to disable (e.g. when a real limiter sits in front).
|
||||
*/
|
||||
maxPerMinute?: number;
|
||||
payload: BasePayload;
|
||||
/**
|
||||
* Name of the GDPR consent checkbox. A field with this name must be checked
|
||||
* for the submission to succeed (enforced server-side). Defaults to 'consent'.
|
||||
*/
|
||||
consentFieldName?: string;
|
||||
/**
|
||||
* Turnstile can't be verified because of OUR side (missing/wrong secret,
|
||||
* Cloudflare unreachable): 'allow' (default) accepts the submission and shows
|
||||
* the problem in the panel; 'reject' refuses it.
|
||||
*/
|
||||
turnstileOnConfigError?: 'allow' | 'reject';
|
||||
/** Turnstile token; when present it is verified, when absent it is skipped. */
|
||||
turnstileToken?: string;
|
||||
};
|
||||
/**
|
||||
* Why a submission failed — a code, never a user-facing string.
|
||||
@@ -45,34 +45,34 @@ export type SubmitFormArgs = {
|
||||
* - `error` — persistence failed unexpectedly
|
||||
*/
|
||||
export type SubmitFailure = {
|
||||
success: false;
|
||||
reason: 'rate_limited';
|
||||
} | {
|
||||
success: false;
|
||||
reason: 'turnstile';
|
||||
} | {
|
||||
success: false;
|
||||
reason: 'validation';
|
||||
/** The offending field's name, when one field is at fault. */
|
||||
field?: string;
|
||||
/** What was wrong with it. */
|
||||
kind?: 'required' | 'too_long' | 'unknown_fields';
|
||||
reason: 'validation';
|
||||
success: false;
|
||||
} | {
|
||||
field?: string;
|
||||
success: false;
|
||||
reason: 'not_found';
|
||||
} | {
|
||||
success: false;
|
||||
/** A GDPR consent field existed on the form but wasn't checked. */
|
||||
reason: 'consent';
|
||||
success: false;
|
||||
field?: string;
|
||||
} | {
|
||||
success: false;
|
||||
reason: 'error';
|
||||
success: false;
|
||||
} | {
|
||||
reason: 'not_found';
|
||||
success: false;
|
||||
} | {
|
||||
reason: 'rate_limited';
|
||||
success: false;
|
||||
} | {
|
||||
reason: 'turnstile';
|
||||
success: false;
|
||||
};
|
||||
export type SubmitFormResult = {
|
||||
submissionId: number | string;
|
||||
export type SubmitFormResult = SubmitFailure | {
|
||||
success: true;
|
||||
} | SubmitFailure;
|
||||
submissionId: string | number;
|
||||
};
|
||||
/**
|
||||
* Handles a form submission end to end: rate limit, verify Turnstile, validate
|
||||
* against the form's own schema, then store.
|
||||
@@ -86,4 +86,4 @@ export type SubmitFormResult = {
|
||||
*
|
||||
* server-only: touches the Turnstile secret.
|
||||
*/
|
||||
export declare function submitForm({ consentFieldName, data, formId, ip, maxPerMinute, payload, turnstileOnConfigError, turnstileToken, }: SubmitFormArgs): Promise<SubmitFormResult>;
|
||||
export declare function submitForm({ payload, formId, data, turnstileToken, ip, maxPerMinute, consentFieldName, turnstileOnConfigError, }: SubmitFormArgs): Promise<SubmitFormResult>;
|
||||
|
||||
Reference in New Issue
Block a user