feat(webhooks): add delivery detail endpoint and list filtering#35
Open
Jaydbrown wants to merge 3 commits into
Open
feat(webhooks): add delivery detail endpoint and list filtering#35Jaydbrown wants to merge 3 commits into
Jaydbrown wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17
Summary
The webhook delivery log endpoint only supported a bare
limitquery param and had no way to fetch a single delivery's full attempt history. This PR addsGET /v1/webhooks/deliveries/:idfor per-delivery inspection and extendsGET /v1/webhooks/deliverieswith filtering by event type, status, and date range — matching the requirements in the issue.Changes
src/webhook/webhook.service.tsListDeliveriesOptionsinterface — named options bag replaces the singlelimitparameter:listDeliveries— builds a dynamicand(...)condition from whichever filters are provided:getDelivery— new method, scoped to the merchant to prevent cross-tenant access:The response includes
attemptLog(all attempt timestamps, HTTP statuses, and errors),deliveredAt,nextRetryAt, and every other column onwebhook_deliveries.src/webhook/webhook.controller.tsGET /v1/webhooks/deliveries— accepts the new filter query params:Example queries:
GET /v1/webhooks/deliveries?status=failed— all failed deliveriesGET /v1/webhooks/deliveries?event=payment.confirmed— only payment confirmationsGET /v1/webhooks/deliveries?after=2024-01-01T00:00:00Z&before=2024-02-01T00:00:00Z— date rangeGET /v1/webhooks/deliveries/:id— new endpoint, returns 404 if the delivery doesn't belong to the requesting merchant:Example response for
GET /v1/webhooks/deliveries/:id{ "id": "...", "deliveryId": "018e9f2a-...", "merchantId": "...", "event": "payment.confirmed", "status": "failed", "attempts": 2, "sequence": 3, "attemptLog": [ { "attempt": 1, "timestamp": "2024-01-15T10:00:00Z", "status": 503, "error": "HTTP 503" }, { "attempt": 2, "timestamp": "2024-01-15T10:05:00Z", "status": null, "error": "ECONNRESET: read ECONNRESET" } ], "nextRetryAt": "2024-01-15T10:35:00Z", "deliveredAt": null, "createdAt": "2024-01-15T09:59:58Z" }Existing behaviour unchanged
The DLQ endpoints (
GET /dead-letter,POST /dead-letter/:id/retry,DELETE /dead-letter/:id), the idempotency headers, and the ordering/retry/dead-letter logic in the queue service are untouched. Thelimitcap of 100 is preserved.Test plan
GET /deliveries(no params) → returns up to 50 most recent deliveriesGET /deliveries?limit=10→ returns at most 10GET /deliveries?event=payment.confirmed→ onlypayment.confirmedeventsGET /deliveries?status=delivered→ only successfully delivered webhooksGET /deliveries?after=2024-01-01T00:00:00Z→ only deliveries after the given dateGET /deliveries/:idwith a valid delivery ID belonging to the merchant → full record withattemptLogGET /deliveries/:idwith a non-existent ID → 404GET /deliveries/:idwith a delivery ID belonging to a different merchant → 404 (tenant isolation)