Repository navigation
fix(content): keep a cut-off 2xx as sent, say why a webhook test failed, and tie the test to a brand - #1605
Conversation
No redirect is followed since ansvisor#1568, so a 3xx means the payload never arrived. A single send answers 502 `webhook_redirect` ("The webhook address redirects. Use the address it redirects to."). A bulk send counts it failed. Either way the opportunity keeps its status, as Send to CMS does for a 3xx. Any other answer still marks it sent. The docs say so (api-reference/webhooks.mdx). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed, and tie the test to a brand Follow-ups 2–5 from ansvisor#1568. - postJson: once the status is in, a dropped connection resolves with that status and what was read, so a 2xx whose answer is cut off still counts as delivered. A 3xx also returns its location, made absolute. - checkWebhookUrl checks the scheme and sign-in details first in both modes, with its own words. On the cloud checkPageUrl runs only for the address check. - The webhook test: - takes a brandId the caller can edit the webhook for (admins and managers); - has its own limit (10 a minute, webhookTestLimiter); - names a network error's code ("…could not be reached (ENOTFOUND)"). The dialog says where a redirect points, and why a test was refused. - Docs: the User-Agent (Ansvisor-Webhook/1.0), cut-off answers, redirects, error codes, and who may run the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups. Rebase it onto main before merging: #1590 was squashed, so GitHub now shows a conflict.
What I checked:
-
Own change. One commit, 32dc544, on #1590's branch head (ca5fde6).
-
Merge.
- On main (15b5b5f),
server/src/lib/safe-post.jsandserver/src/routes/content.jsconflict. That's only because #1590 went in as a squash: every file this PR touches is the same on main as on ca5fde6, apart fromen.json, which merges on its own. - Replaying the own commit onto main (
git rebase --onto origin/main ca5fde6e) has no conflicts and gives exactly the PR's own diff.
- On main (15b5b5f),
-
With #1590. A cut-off answer keeps its status, so:
- a cut-off 3xx is still a redirect, which the single send, the bulk send, Daily Pulse, the task send and Send to CMS all count as not delivered;
- a cut-off 2xx counts as delivered everywhere.
locationis only added to a 3xx's result. EverypostJsoncaller still reads onlystatusandanswer. -
Address checks. The scheme and credentials checks now run first. On Cloud,
checkPageUrland the public-only lookup still run on every request, and no redirect is followed. Self-hosted works as before. -
Error text. The test answers with:
- our own
PageFetchErrormessages; - for a network failure, the error's string code (ENOTFOUND, ECONNREFUSED, a TLS code). A numeric errno is left out;
- for a 3xx, the
Locationthe webhook sent.
Nothing about our own servers or network appears in any of them.
- our own
-
Access.
assertBrandAccessand then the profile's role, ascms.jsdoes. This matches thewebhook_configspolicies: only admins and managers can insert, update or delete.webhookTestLimiterallows 10 tests a minute per user.- Zod rejects a missing brand, a brand that isn't an id, and a missing address before anything is posted.
-
Web.
- A 403
forbiddenshowstestForbidden. Any other refusal goes throughapiFailure: 429 shows busy, and #1589's 402subscription_inactiveshows plan. - A redirect names its target. Every other failure shows the API's
error.
- A 403
-
Tests.
- At the head, the
safe-post,content-webhooksandrate-limitertests pass (61). - With ca5fde6's source under the head's tests, 19 of them fail: the scheme and credentials wording, cut-off answers,
location, network codes, the 400s, the 403s and the 429. - CI passes.
- At the head, the
-
Before the API deploy. The web sends
brandId, and the old API ignores it. The dialog shows the same messages as today. The 403, 429 and redirect messages appear once the API is deployed. -
Speed. This PR adds no regex and no loop over user input.
Follow-ups:
- A 2xx still arriving at the time limit is reported as a timeout (
server/src/lib/safe-post.js:124-131,docs/api-reference/webhooks.mdx:296).- I tested a webhook that sends 200 and part of the answer, then nothing more. With a 300 ms limit,
postJsonrejects withtimeout, because the abort reachesreq.on('error')first. So a send is marked failed, and a task send is reported as refused, although the status arrived. - Either set a flag in the response callback and, in
req.on('error'), resolve withdone()once a response has started, or make the docs line say "if the connection drops", not a slow answer.
- I tested a webhook that sends 200 and part of the answer, then nothing more. With a 300 ms limit,
- Members still see Test Webhook (
_webhook-settings.tsx:252). They only learn they can't test after pressing it. As the description says, hiding or disabling the button can come in its own change.
…r doesn't arrive in time (#1668) Follow-up from #1605 (item 1). A webhook that sends 200 and part of its answer, then nothing more, was reported as a timeout: the time limit's abort reaches the request's error handler before the answer's, so postJson rejected with `timeout` though the status had arrived. A send was marked failed, and a task send reported as refused. postJson now remembers once the status has arrived; an error the request hears after that (the time limit, the connection dropping) ends that answer with what was read of it. The docs' Delivery line says so. The new test fails on main: a 200 that stalls past a 100 ms limit. Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…nd Save aren't pressed only to be refused (#1673) * fix(content): show a member the webhook settings read-only, so Test and Save aren't pressed only to be refused Follow-up from #1605 (item 2). Only admins and managers can save a brand's webhook (webhook_configs' RLS) and test it (the API's assertWebhookEditor). A member saw Test Webhook and Save Webhook as for anyone and learned they couldn't only after pressing: a "forbidden" test result, or a failed save. The dialog now reads the role (useUserRole): for a member the address, secret, events and on/off switch show as they are but disabled, Test and Save are disabled, and a line says "Only admins and managers can change or test this webhook." The webhooks docs say members see it read-only. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(content): dim the webhook's Active switch for a member, as its other disabled fields Review follow-up. The hand-made Active switch had no disabled styles, so a member saw it in full colour with the pointer cursor although it does nothing. It now takes disabled:cursor-not-allowed disabled:opacity-50, as the disabled checkboxes beside it do. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Follow-ups 2–5 from #1568's approval (1 is #1590).
Stacked on #1590. This PR's own change is its commit after #1590's: 32dc544.
2. A 2xx cut off mid-answer counts as delivered (
lib/safe-post.js).res.on('error', done)), instead of rejecting with the rawabortederror.sentagain, the bulk send counts it sent, and a task send isn't reported as refused.3. The test's messages.
checkWebhookUrlchecks the scheme and any sign-in details first, in both modes, in its own words: "Only http and https addresses can be posted to", "URLs with credentials are not posted to". On the cloud,checkPageUrlruns only for the address check.postJsonreturns a 3xx'slocation, made absolute, and the dialog says where the redirect points.4. The test route is tied to a brand (
POST /api/content/webhook-test).brandId(Zod).forbidden; another workspace's brand gets 403not_in_workspace.webhookTestLimiter).testWebhook(brandId, url, secret)returns why it failed. The dialog says it for a 403, a 429, a redirect and a network error (testRedirect,testForbidden).5. Docs (
api-reference/webhooks.mdx, Delivery):User-Agent(Ansvisor-Webhook/1.0 (+https://ansvisor.com), asUSER_AGENTsends it), so a firewall can allow it;Related issue
Follow-up to #1568 (items 2–5).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/safe-post.test.js src/routes/content-webhooks.test.js src/middleware/rate-limiter.test.jscd web && yarn vitest run src/lib/actions/content-webhook.test.ts "src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.test.tsx"ftp://…: the scheme message;Checked in the browser at 1024 px, light and dark, with this branch's API and web against the dev DB. Nothing was saved, and the
webhook_configsrows are unchanged.http://localhost:9/hookread "The webhook could not be reached (ECONNREFUSED)".ftp://example.com/hookit read "Only http and https addresses can be posted to".Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
server/:npm run format,npm run lintandnpm test(2,966 tests);web/:yarn format,yarn lint(0 errors),yarn typecheck,yarn test(4,152 tests) andyarn build.The fixer broke 18 behaviours one at a time to check the tests catch them.
The Test Webhook button still shows to members. They get the 403's message; hiding it would be its own change.
🤖 Generated with Claude Code