Files
ipal-kit/dist/modules/forms/honeypot.d.ts
T

47 lines
1.7 KiB
TypeScript

/**
* A honeypot: a hidden field real users never see or fill, but naive bots do.
* A cheap, zero-friction second layer alongside Turnstile — no network call, no
* user interaction. Pure functions, usable on client (render the input) and
* server (check it in the action).
*/
/**
* Default field name. Looks like a real field a bot would want to fill, but is
* not one your form uses. Override per project if you like — just keep the
* client and server in sync.
*/
export declare const HONEYPOT_FIELD = "company_url";
/**
* Props for the hidden input. Hidden from sight AND from assistive tech and tab
* order, so no real user (sighted, screen-reader, or keyboard) ever fills it —
* only a bot auto-filling every field.
*
* <input {...honeypotInputProps()} />
* // or with your own name:
* <input {...honeypotInputProps('website_2')} />
*/
export declare function honeypotInputProps(name?: string): {
name: string;
type: "text";
'aria-hidden': boolean;
autoComplete: "off";
tabIndex: number;
style: {
height: string;
left: string;
overflow: "hidden";
position: "absolute";
width: string;
};
};
/**
* True when the honeypot was filled → treat the submission as spam and drop it
* (silently return success so the bot gets no signal). Call it FIRST in your
* server action, before submitForm:
*
* if (isHoneypotTripped(values)) return { success: true } // pretend-accept
* // strip it so submitForm doesn't see an unknown field:
* const { [HONEYPOT_FIELD]: _hp, ...clean } = values
* return submitForm({ ...clean })
*/
export declare function isHoneypotTripped(values: Record<string, unknown>, name?: string): boolean;