Headless pakket src/cms-client met importgrens, formulier dat pas verschijnt als de API antwoordt (anders blijft de mailto-knop), honeypot, idempotentie, token-vernieuwing en property-based tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
4.7 KiB
4.7 KiB
Code Summary — contact-form (U4)
What was built
- Movable package
src/cms-client/(no imports from the app; ESLintno-restricted-importsplus a boundary test):http/(apiUrl,fetchJsonwith 10 s timeout, problem+json parsing),contact/(validateContact,contactFormReducer,createContactClient,messages.nl,useContactForm, types),README.md. - Validation equal to the API (trim; 100/254/100/2000; email regex; control characters rejected except line breaks in the message; first failing rule per field). Reducer:
sentonly leaves throughreset; edits and a second submit are ignored whilesending; input is kept onfailed. - Client:
getToken(200 → token, 404 → closed, anything else → failed, malformed body → failed) andsubmit(202 ok; 400 → field errors or token expired; 413; 404; 429 withRetry-After; 5xx/network → failed). Never throws, never logs. - Hook
useContactForm: prop getters with ids fromidPrefix,aria-invalid/aria-describedby, honeypot props (silent success without a request when filled), one idempotency key per attempt series (reused on retry, renewed after success/reset), a single automatic token refresh onexpired, preselect with change counter (unknown values ignored), focus on the first invalid field after the render, telemetry only throughonEvent('sent' | 'failed'). - UI:
ContactPanel(mailto panel by default, upgrades to the form whenGET …/tokenanswers 200 without captcha; min height 280px),MailtoPanel,ContactFormView(design B: panel colours, underline inputs onbg-field, brand submit button, errors outside the labels,role=alertfailure with the mail address,role=statussuccess with focus, privacy sentence), hidden honeypot field.useContactAvailabilitystarts the token request when the section nears the viewport (IntersectionObserver,rootMargin 300px), or on first focus without IntersectionObserver. Subject options = offerings (slug/title) + "Overig".trackEvent('contact-sent' | 'contact-failed')without data. - Tokens: new
--color-danger(error text) in all four sets, contrast-tested againstpanelandfield. - Dependencies:
fast-check(dev) for property-based tests; no runtime dependency.
Verification (Step 13.5, real output)
- Before this unit (after U3): 14 files / 154 tests. After: 19 files / 239 tests passed;
pnpm lint0 errors (same 2 existing warnings, boundary rule active);pnpm buildOK (JS 466 kB, CSS 58.8 kB). - Found and fixed by the tests: (1) field errors inside the
<label>polluted the accessible name of the input → errors now sit outside the label; (2) focus after server field errors did not move because inputs are disabled while sending → focus is applied after the render. - New tests: validation examples and properties (trim invariance, inclusive limits, control characters, known codes), reducer examples and properties (absorbing
sent, ignored edits while sending, values kept on failure), client against a contract-following mockedfetch(all status mappings, timeout, serialization and problem-parsing round trips), boundary, availability (200/404/500/429/captcha/malformed/network, once only, first-focus fallback), full UI flows (success with body/headers, validation + focus, blur errors, honeypot, server field errors, token refresh with same key, 413/429 minutes, failure + retry with same key, double submit, reset with new key, preselect, no PII in console/analytics).
Notes and deviations
- Mail address is not assembled after mount (BR-U4-10): the address is already present as a literal in the section (visible mailto link) and the site is a client-rendered SPA, so the extra step would add nothing; kept simple.
- No end-to-end test against the real API is possible yet: the contact routes exist only on the unmerged CMS branch and answer 404 in production until released and switched on, which keeps the mailto panel (by design).
style-src 'unsafe-inline'/ headers: see the infrastructure design (Operations list).
Enabling end to end later (checklist)
- CMS branch rebased/merged and deployed; per-client rate limiting active on the API host.
Contact:Enabled=trueon the host; then the CMS switch (PUT /api/v1/contact-settingsor the Berichten screen).- Confirm the header/CSP setup of the delivering web server (SECURITY-04) and
connect-src 'self'. - Check on the test environment first: token 200 → form appears; submit → message in the CMS.
Hand-offs
- U5: build
ContactFormTerminalonuseContactForm(same options); reuseContactPanellogic (availability) for the 1989 terminal; texts are injectable viamessages. - CMS: type generation from
openapi/slpsoftware.v1.jsonand movingsrc/cms-clientinto SlpModularCms are follow-ups.