Added healhtRoute, honeypot, ConsentScript, asserEnv

This commit is contained in:
2026-10-10 00:17:13 +02:00
parent 52977e67fc
commit 1b52060dce
63 changed files with 2110 additions and 36 deletions
+46
View File
@@ -0,0 +1,46 @@
/**
* 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;
+50
View File
@@ -0,0 +1,50 @@
/**
* 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 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 function honeypotInputProps(name = HONEYPOT_FIELD) {
return {
name,
type: 'text',
'aria-hidden': true,
autoComplete: 'off',
tabIndex: -1,
// Off-screen rather than display:none — some bots skip display:none fields.
style: {
height: '1px',
left: '-9999px',
overflow: 'hidden',
position: 'absolute',
width: '1px'
}
};
}
/**
* 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 function isHoneypotTripped(values, name = HONEYPOT_FIELD) {
const v = values[name];
return typeof v === 'string' ? v.trim().length > 0 : v != null;
}
//# sourceMappingURL=honeypot.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/modules/forms/honeypot.ts"],"sourcesContent":["/**\n * A honeypot: a hidden field real users never see or fill, but naive bots do.\n * A cheap, zero-friction second layer alongside Turnstile — no network call, no\n * user interaction. Pure functions, usable on client (render the input) and\n * server (check it in the action).\n */\n\n/**\n * Default field name. Looks like a real field a bot would want to fill, but is\n * not one your form uses. Override per project if you like — just keep the\n * client and server in sync.\n */\nexport const HONEYPOT_FIELD = 'company_url'\n\n/**\n * Props for the hidden input. Hidden from sight AND from assistive tech and tab\n * order, so no real user (sighted, screen-reader, or keyboard) ever fills it —\n * only a bot auto-filling every field.\n *\n * <input {...honeypotInputProps()} />\n * // or with your own name:\n * <input {...honeypotInputProps('website_2')} />\n */\nexport function honeypotInputProps(name: string = HONEYPOT_FIELD) {\n return {\n name,\n type: 'text' as const,\n 'aria-hidden': true,\n autoComplete: 'off' as const,\n tabIndex: -1,\n // Off-screen rather than display:none — some bots skip display:none fields.\n style: {\n height: '1px',\n left: '-9999px',\n overflow: 'hidden' as const,\n position: 'absolute' as const,\n width: '1px',\n },\n }\n}\n\n/**\n * True when the honeypot was filled → treat the submission as spam and drop it\n * (silently return success so the bot gets no signal). Call it FIRST in your\n * server action, before submitForm:\n *\n * if (isHoneypotTripped(values)) return { success: true } // pretend-accept\n * // strip it so submitForm doesn't see an unknown field:\n * const { [HONEYPOT_FIELD]: _hp, ...clean } = values\n * return submitForm({ ...clean })\n */\nexport function isHoneypotTripped(\n values: Record<string, unknown>,\n name: string = HONEYPOT_FIELD,\n): boolean {\n const v = values[name]\n return typeof v === 'string' ? v.trim().length > 0 : v != null\n}\n"],"names":["HONEYPOT_FIELD","honeypotInputProps","name","type","autoComplete","tabIndex","style","height","left","overflow","position","width","isHoneypotTripped","values","v","trim","length"],"mappings":"AAAA;;;;;CAKC,GAED;;;;CAIC,GACD,OAAO,MAAMA,iBAAiB,cAAa;AAE3C;;;;;;;;CAQC,GACD,OAAO,SAASC,mBAAmBC,OAAeF,cAAc;IAC9D,OAAO;QACLE;QACAC,MAAM;QACN,eAAe;QACfC,cAAc;QACdC,UAAU,CAAC;QACX,4EAA4E;QAC5EC,OAAO;YACLC,QAAQ;YACRC,MAAM;YACNC,UAAU;YACVC,UAAU;YACVC,OAAO;QACT;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASC,kBACdC,MAA+B,EAC/BX,OAAeF,cAAc;IAE7B,MAAMc,IAAID,MAAM,CAACX,KAAK;IACtB,OAAO,OAAOY,MAAM,WAAWA,EAAEC,IAAI,GAAGC,MAAM,GAAG,IAAIF,KAAK;AAC5D"}
+1
View File
@@ -1,4 +1,5 @@
export { buildFormsPlugin } from './formsPluginConfig.js';
export { HONEYPOT_FIELD, honeypotInputProps, isHoneypotTripped } from './honeypot.js';
export { checkRateLimit } from './rateLimit.js';
export type { RateLimitArgs } from './rateLimit.js';
export { submitForm } from './submitForm.js';
+2
View File
@@ -1,6 +1,8 @@
// buildFormsPlugin is config-time (safe anywhere). submitForm is server-only
// (Turnstile secret) — never import it from a client component.
export { buildFormsPlugin } from './formsPluginConfig.js';
// Honeypot anti-spam (pure — client renders the input, server checks it).
export { HONEYPOT_FIELD, honeypotInputProps, isHoneypotTripped } from './honeypot.js';
export { checkRateLimit } from './rateLimit.js';
export { submitForm } from './submitForm.js';
export { useContactForm } from './useContactForm.js';
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["../../../src/modules/forms/index.ts"],"sourcesContent":["// buildFormsPlugin is config-time (safe anywhere). submitForm is server-only\n// (Turnstile secret) — never import it from a client component.\nexport { buildFormsPlugin } from './formsPluginConfig.js'\nexport { checkRateLimit } from './rateLimit.js'\nexport type { RateLimitArgs } from './rateLimit.js'\nexport { submitForm } from './submitForm.js'\nexport type { SubmitFormArgs, SubmitFormResult } from './submitForm.js'\nexport type { FormsCollectionOverrides, FormsFieldsOverride, FormsOption } from './types.js'\nexport { useContactForm } from './useContactForm.js'\nexport type { ContactFormErrors, ContactFormValues, SubmitAction } from './useContactForm.js'\n// Generic form engine (any field set) + the standard contact-form preset.\nexport { useForm } from './useForm.js'\nexport type { FormErrors, FormSubmitAction, Validator } from './useForm.js'\nexport { validateSubmission } from './validateSubmission.js'\nexport type { FormValidationResult } from './validateSubmission.js'\n// Composable validation rules (pure — safe on server or client).\nexport {\n buildValidator,\n checked,\n custom,\n email,\n isEmail,\n maxLength,\n minLength,\n pattern,\n required,\n} from './validators.js'\nexport type { Rule } from './validators.js'\n"],"names":["buildFormsPlugin","checkRateLimit","submitForm","useContactForm","useForm","validateSubmission","buildValidator","checked","custom","email","isEmail","maxLength","minLength","pattern","required"],"mappings":"AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,SAASA,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,UAAU,QAAQ,kBAAiB;AAG5C,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,0EAA0E;AAC1E,SAASC,OAAO,QAAQ,eAAc;AAEtC,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,iEAAiE;AACjE,SACEC,cAAc,EACdC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACH,kBAAiB"}
{"version":3,"sources":["../../../src/modules/forms/index.ts"],"sourcesContent":["// buildFormsPlugin is config-time (safe anywhere). submitForm is server-only\n// (Turnstile secret) — never import it from a client component.\nexport { buildFormsPlugin } from './formsPluginConfig.js'\n// Honeypot anti-spam (pure — client renders the input, server checks it).\nexport { HONEYPOT_FIELD, honeypotInputProps, isHoneypotTripped } from './honeypot.js'\nexport { checkRateLimit } from './rateLimit.js'\nexport type { RateLimitArgs } from './rateLimit.js'\nexport { submitForm } from './submitForm.js'\nexport type { SubmitFormArgs, SubmitFormResult } from './submitForm.js'\nexport type { FormsCollectionOverrides, FormsFieldsOverride, FormsOption } from './types.js'\nexport { useContactForm } from './useContactForm.js'\nexport type { ContactFormErrors, ContactFormValues, SubmitAction } from './useContactForm.js'\n// Generic form engine (any field set) + the standard contact-form preset.\nexport { useForm } from './useForm.js'\nexport type { FormErrors, FormSubmitAction, Validator } from './useForm.js'\nexport { validateSubmission } from './validateSubmission.js'\nexport type { FormValidationResult } from './validateSubmission.js'\n// Composable validation rules (pure — safe on server or client).\nexport {\n buildValidator,\n checked,\n custom,\n email,\n isEmail,\n maxLength,\n minLength,\n pattern,\n required,\n} from './validators.js'\nexport type { Rule } from './validators.js'\n"],"names":["buildFormsPlugin","HONEYPOT_FIELD","honeypotInputProps","isHoneypotTripped","checkRateLimit","submitForm","useContactForm","useForm","validateSubmission","buildValidator","checked","custom","email","isEmail","maxLength","minLength","pattern","required"],"mappings":"AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,SAASA,gBAAgB,QAAQ,yBAAwB;AACzD,0EAA0E;AAC1E,SAASC,cAAc,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,gBAAe;AACrF,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,UAAU,QAAQ,kBAAiB;AAG5C,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,0EAA0E;AAC1E,SAASC,OAAO,QAAQ,eAAc;AAEtC,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,iEAAiE;AACjE,SACEC,cAAc,EACdC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACH,kBAAiB"}