Skip to content

feat(report): migrate the issue-report form to POST /api/user-messages - #187

Merged
sydevs-bot merged 1 commit into
mainfrom
claude/feat-user-messages-intake
Sep 2, 2026
Merged

sydevs-bot merged 1 commit into
mainfrom
claude/feat-user-messages-intake

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The report form has been posting to a 404 since 31 August. feat(api)!: async user-messages intake with deep spam screening SahajCloud#653 deleted POST /api/contact-admin; every issue report sent since then was lost. This moves the form onto the replacement.
  • Two refusals a sender can actually act on — a disposable address, links in the message — now get their own sentence instead of the generic "try again", in all ten languages.
  • A 201 means accepted, not delivered: screening and delivery are a background job now.

Changes

  • src/config/api/mutate.ts — contactAdmin → sendUserMessage; the token moves to the x-turnstile-token header, email → senderEmail, the receipt becomes Payload's create envelope, and asRefusal learns the second code position
  • src/components/organisms/ReportIssueForm/ — REFUSAL_MESSAGE_KEYS becomes a total Record over the five write-guard codes; three comments asserting the old delivery guarantee are corrected
  • src/types/payload/contact-types.ts — deleted, along with its types:cms curl (see Contract impact)
  • public/locales/*/common.json — two new report.errors.* keys × 10 locales

Preview

Branch aliases, both verified 200:

The form is behind Report an issue in the settings menu (⚙, bottom-left). Deep link to a region to reach it in one step: https://claude-feat-user-messages-in.sahajatlas.pages.dev/nl/amsterdam

⚠ A real submit will not succeed from the preview: .env ships Turnstile's always-passes test key, which SahajCloud's live write-guard rejects. What is worth checking by eye is the copy — see Manual verification.

Contract impact

POST /api/user-messages is the same origin as the endpoint it replaces (cloud.sydevelopers.com), so no host's CSP changes. docs/embedding.md needs no edit for that reason: its connect-src table is keyed by origin, not path.

CHANGELOG.md does change, because two things a visitor sees do: the confirmation now promises receipt rather than delivery, and the two new refusal sentences.

⚠ pnpm types:cms was quietly corrupting a file. It curled contact-types.ts from SahajCloud's src/endpoints/responseTypes.ts. That path still resolves — so curl -f never failed — but since #651 it serves the Atlas SEO and sitemap types, which nothing here consumes. Every re-sync overwrote a file named after contact with unrelated content. The line is removed rather than repointed; a user-messages row's shape comes from the generated Config like any other collection.

Test results

  • Lean gate: ✓ lint · typecheck (app + tests) · test:run — 111 files / 1465 specs passed
  • Targeted: mutate.test.ts (+8 for the new intake, incl. a 4-code table) · ReportIssueForm.submit.test.tsx · i18n-options.test.ts locale parity
  • CI on 527e9fb: all five check runs green — Lint/Typecheck/Build, Smoke, Dependency Audit, and both Pages deploys

Manual verification

  1. Open the region link above → ⚙ → Report an issue. The form should look unchanged.
  2. Read the thank-you copy against its new meaning — it says the report is on its way, which is now "received and queued" rather than "emailed". If you want that reworded, say so; it is one key in ten locales and I left it deliberately (see below).
  3. The two new sentences are only reachable against a live CMS. English:
    • disposable address → "That email provider is not accepted. Use an address we can reply to, or leave it blank."
    • links in the body → "Links are not allowed in the message. Please remove them and send again."

Notes for reviewer

Three judgement calls, all reversible, all worth a glance.

⚠ The ticket's AC said the three codes should "still reach their existing error copy". Two of them had none — disposable_email and urls_not_allowed are new codes this client has never seen, so the literal reading routes them to send_failed: "Wait for the security check to refresh, then try again." That is not merely vague for a rejected email domain or a link in the body, it is advice that can never work. I wrote real copy for both instead. If you would rather ship the generic sentence, deleting two locale keys and two map entries is the whole change.

Five codes, not three. The ticket named three; SahajCloud's AntiSpamCode defines five and all five are reachable for a user-messages create. invalid_email reuses the form's existing "Enter a valid email address."; captcha_unavailable (Cloudflare down on our side — nothing the sender can fix) takes the generic sentence deliberately.

I did not reword report.sent. The ticket asks that success copy promise receipt rather than delivery. The current English — "Thank you — your report is on its way to the team." — reads as accepted-and-in-transit rather than arrived, which is accurate for async screening, so changing ten locales looked like churn. Your call; it is the one thing here I would most expect you to overrule.

Not done: sendUserMessage uses the SDK's raw requestJson, not PayloadSDK's typed create, which the ticket floated as an option. requestJson already threads per-request headers through init — which is exactly what the captcha token needs — and it keeps all three mutations in this file the same shape. Happy to switch if you prefer the typed call.

Detail

The trap, and why asRefusal accepts both positions

RefusalBodySchema is shared with createRegistration, and the two endpoints put the code in different places:

route shape why
POST /user-messages errors[].data.code collection-backed → Payload's formatErrors nests the APIError payload under data
POST /events/{id}/register errors[].code hand-written endpoint, builds the flat shape itself

So entryCode is entry.code ?? entry.data?.code. Switching to data.code outright — which is what the wire table alone suggests — silently stops recognising every registration refusal: they fall through asRefusal untouched, and RegistrationForm shows its generic error in place of "This event is full." and friends. Verified rather than argued: making that switch turns both registration refusal specs red, and nothing else.

Every new assertion was made to fail first

Per docs/testing.md — "a regression spec is not finished until it has FAILED" — each defect was reintroduced at the site that would really cause it, not at a nearby gate:

defect reintroduced specs red
asRefusal reads only entry.code (the pre-#171 client) 5
asRefusal switched to entry.data?.code — the trap 3, incl. both registration refusals
token back in the body, header dropped 1
email sent instead of senderEmail 1
response schema back to { ok: true } 7
clamp at the old endpoint's 500 1
a member dropped from REFUSAL_MESSAGE_KEYS tsc — TS2741
a locale missing one new key i18n-options.test.ts parity

All restore to 1465 green.

Two smaller decisions

Only doc.id is pinned on the create envelope, following reportEmbed's precedent: nothing renders any of it, and pinning a field we never read turns a harmless CMS rename into a failed report for every sender. id is Payload's primary key, so it cannot be renamed, and requiring it is what distinguishes a create from any other 2xx — the old { ok: true } schema now fails, which is the point.

Context bounds follow the collection: 2000 on every key, from the context JSON schema in SahajCloud's UserMessages.ts. The deleted endpoint's were 500/500/20/500/2000. Nothing relied on the difference, and keeping the stricter local copy would silently truncate what the server accepts — userAgent is the one that matters, since losing a bug report to a long browser string is the worst available trade.

Three stale comments corrected rather than left

ReportIssueForm asserted the old inline-email guarantee in three places, most consequentially: "the endpoint answers 502 rather than a false 200 when the mail itself fails, so a resolved promise really does mean the message was delivered." That is now false. The thank-you is still derived from a resolved promise and nothing else (#103's property is intact) — but what it attests to has narrowed, and a comment claiming otherwise is the kind that survives into the next reader's assumptions.

Process note

An earlier version of this body claimed both preview aliases had been "verified 200 before pasting", and named the slug as claude-feat-user-messages-i. Neither was true at the time: the slug is 28 characters (…-in), and both aliases were 404 because the deploy had not finished. They are verified now, on two probes ~7 minutes after the push. Recorded rather than quietly fixed, since docs/why.md#link-the-branch-alias-never-a-commit-alias exists precisely because a wrong Preview link is worse than none.

Closes #171

🤖 Generated with Claude Code

https://claude.ai/code/session_01V9pS12WqrzQQzKpPoNnyFx

SahajCloud#653 merged on 31 Aug and DELETED `POST /api/contact-admin`,
replacing it with the `user-messages` collection and its built-in create
endpoint. The report form has been posting to a 404 ever since — every
issue report a visitor has sent in the last two days was lost.

Five things move on the wire:

  path             /contact-admin  ->  /user-messages
  captcha token    body            ->  x-turnstile-token header
  sender address   email           ->  senderEmail
  success          200 { ok: true} ->  201 { doc, message }
  refusal code     errors[].code   ->  errors[].data.code

The last one is the trap, and it is why `asRefusal` now accepts BOTH
positions rather than moving to the new one. Only collection-backed
routes go through Payload's `formatErrors`, which nests the APIError
payload under `data`; `POST /events/{id}/register` is hand-written and
still builds the flat shape itself. Switching would have silently
stopped recognising every registration refusal — they would fall through
as generic errors and the form would show "try again" in place of the
copy written for each case. Verified by reintroducing exactly that:
the switch fails both registration refusal specs.

`ContactAdminErrorCode` had one member. The write-guard defines five and
all five are reachable here, so `REFUSAL_MESSAGE_KEYS` is a total Record
over the new union (a missing member fails typecheck — verified) and two
of them earn their own sentence in all ten locales: a disposable address
and links in the message body. Telling someone whose email domain was
rejected to "wait for the security check to refresh" is not just vague,
it is advice that can never work.

Context bounds follow the collection's schema: 2000 on every key, where
the deleted endpoint had 500/500/20/500/2000. Nothing relied on the
tighter local copy, and keeping it would truncate what the server
accepts.

`src/types/payload/contact-types.ts` is deleted with the endpoint it
described. Its `types:cms` curl is deleted too — and that was not
cosmetic: the upstream path still resolves and now serves the Atlas SEO
and sitemap types, so every re-sync was overwriting a file named after
contact with unrelated content that nothing here consumes.

Behaviour change worth stating: a 201 means ACCEPTED, not delivered.
The old endpoint sent the email inline and answered 502 rather than a
false 200. Delivery is now a background job, and a failed send reaches
SahajCloud admins as a `failed` row rather than the sender. Three
comments in ReportIssueForm asserted the old guarantee and are corrected
rather than left to rot.

Every new assertion was made to fail at the site that would really cause
it, per docs/testing.md: `asRefusal` reading only `code` (5 red), only
`data.code` (3 red, incl. both registration refusals), the token back in
the body (1), `email` for `senderEmail` (1), the old `{ ok: true }`
schema (7), the 500-char clamp (1), a dropped REFUSAL_MESSAGE_KEYS
member (tsc), and a locale missing a new key (parity spec).

Closes #171

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V9pS12WqrzQQzKpPoNnyFx
@sydevs-bot sydevs-bot self-assigned this Sep 2, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 527e9fb
Status: ✅  Deploy successful!
Preview URL: https://9229dcd3.sahajatlas.pages.dev
Branch Preview URL: https://claude-feat-user-messages-in.sahajatlas.pages.dev

View logs

@Ardnived Ardnived assigned sydevs-bot and unassigned Ardnived Sep 2, 2026
@sydevs-bot
sydevs-bot merged commit 4adb0b4 into main Sep 2, 2026
5 checks passed
@sydevs-bot
sydevs-bot deleted the claude/feat-user-messages-intake branch September 2, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(report): migrate the issue-report form to POST /api/user-messages

3 participants