Repository navigation
Description
SahajCloud has replaced POST /api/contact-admin with a user-messages collection and its built-in create endpoint, so messages can be screened asynchronously for spam before delivery (sydevs/SahajCloud#632, PR sydevs/SahajCloud#653).
The old endpoint is deleted, not deprecated. ReportIssueForm will 404 the moment that PR deploys, so this needs to land alongside it.
What moves on the wire
| Before | After | |
|---|---|---|
| Path | POST /contact-admin |
POST /user-messages |
| Turnstile token | turnstileToken in the JSON body |
x-turnstile-token header |
| Sender address | email |
senderEmail |
| Success | 200 { ok: true } |
201 { doc, message } (Payload's create envelope) |
| Refusal code | errors[].code |
errors[].data.code |
message, subject and the whole context bag (path, hostUrl, locale, error, userAgent) are unchanged. subject still defaults to "Message" server-side when omitted. The refusal codes themselves are unchanged — captcha_failed, disposable_email, urls_not_allowed — only their position in the body moves.
The trap: don't just switch asRefusal
asRefusal / RefusalBodySchema in src/config/api/mutate.ts is shared with createRegistration, and POST /api/events/{id}/register is a hand-written endpoint that still builds { errors: [{ message, code }] } with the code at the top level. Only the collection-backed route goes through Payload's formatErrors, which emits:
{ errors: [{ name, data: { code }, message }] }So RefusalBodySchema has to accept both positions and asRefusal should prefer whichever is present. Switching it to data.code outright would silently stop recognising every registration refusal — they'd fall through as generic errors and the form would show the wrong copy.
Types
src/types/payload/contact-types.ts was synced from SahajCloud's src/endpoints/responseTypes.ts; the ContactAdmin* types are deleted upstream in that PR, so the local copy is now orphaned. user-messages is a real collection, so its shape comes from the generated Config instead — which is also why PayloadSDK<Config>'s typed create is an option worth considering here rather than the raw request helper, if per-request headers can be threaded through it for the captcha token.
Acceptance criteria
- The report form POSTs
/user-messageswith the captcha token in thex-turnstile-tokenheader and the sender's address assenderEmail. - A successful submit is driven off the 201 create response, not
{ ok: true }. -
RefusalBodySchemaaccepts a code at botherrors[].codeanderrors[].data.code; registration refusals still resolve to their existing copy (regression test). - Each of
captcha_failed,disposable_email,urls_not_allowedstill reaches its existing error copy from the new position. -
src/types/payload/contact-types.tsremoved (or reduced to whatever still has a consumer). - Ladle story / submit tests updated for the new path + envelope.
Worth knowing
Screening is now asynchronous, so a 201 means accepted, not delivered — the viewer can no longer be told a delivery failed, because the send happens minutes later in a job. If the form's success copy promises delivery, it should promise receipt instead. Undelivered messages surface to SahajCloud admins as a failed status rather than to the sender.
Activity
feat(report): migrate the issue-report form to POST /api/user-messages (