Skip to content
SprecherEast
Issue 133

tech-debt: Contact module: form safeguards and email in one place, behind small interfaces

Back to our plan
Done
frontendcmstech-debtpriority: medium

Type

tech-debt

Summary

Put everything that protects and delivers contact-form messages (spam check, size limit, rate limit, email safety, email settings) in one place, behind small interfaces, so it is easy to test and to change providers later.

Problem

The contact-form safeguards work, but they are split across hooks/ (3 files), utilities/ (turnstile.ts, turnstileHeader.ts, clientIp.ts, email.ts), plugins/index.ts, components/TurnstileWidget and blocks/Form. The form component posts to the API and handles the robot check itself (226 lines). The Turnstile call is a concrete function, so tests must mock fetch.

Proposed fix

Create src/modules/contact/:

  • domain/: submission limits, the rules for which form emails may be sent (no recipient from submitted data, From and Reply-To handling).
  • HumanVerifier interface with a TurnstileVerifier adapter and a test double.
  • cms/: the form-builder plugin options and the form-submission hooks (moved, behavior unchanged).
  • ui/: the form block component split into smaller parts (field rendering, submission state, robot check).
  • Email transport settings move to src/platform/email/, since password-reset email uses them too.

Acceptance criteria

  • Not done: All contact-form safeguards live in src/modules/contact (or platform/email for transport) and keep their current behavior; every existing test still passes and moves with its code.
  • Not done: HumanVerifier has unit tests through the test double; the Turnstile adapter keeps its own tests.
  • Not done: No file in the module exceeds 250 lines.
  • Not done: Submitting /contact locally (test keys) stores the submission and sends the owner notification to a local SMTP catcher.

Depends on

#129 and #130. Step 8 of #127.

Area

cms, frontend

Priority

medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab