feat: idempotency-key middleware for POST/PATCH on /api/reports - #865
Merged
greatest0fallt1me merged 1 commit intoJul 29, 2026
Merged
Conversation
|
@Glam26 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Nice — merging. Thanks! |
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.
I have successfully implemented the backend requirement to add Idempotency-
Key middleware for POST and PATCH endpoints on the /api/reports routes,
ensuring safe retries.
Here is a breakdown of what was accomplished on the new branch
(feature/reports-idempotency):
• ReferenceError: Discovered and fixed a critical bug where persisted
was being checked and assigned without being declared (let persisted =
false;). This would have historically thrown a ReferenceError on all
POST/PATCH requests trying to use idempotency.
• Duplicate Database Inserts: The res.json interceptor was
independently attempting a db.insert call, while delegating to the
wrapped res.send function that made its own db.insert call. This
resulted in dual insert conflicts. I refactored the wrapper functions
to share a robust, centralized saveIdempotency() function that handles
caching correctly.
• Fixed missing dependencies where the logging utility referenced a
non-existent correlationId (replaced with the intended reqId) and where
the TTL relied on an undefined TTL_MS (replaced with the exported
IDEMPOTENCY_TTL_MS).
• Updated src/routes/reports.ts to directly apply the idempotency
middleware natively using .use() for POST and PATCH methods upstream of
the scheduled reports endpoints, cementing the behavior natively to the
sub-router.
• Re-ran the idempotency test suite (npx jest
tests/middleware/idempotency.test.ts), verifying that all previous
broken tests are now fully patched. Specifically, the "cache miss"
checks correctly assert exactly 1 persistent insert call (rather than 2
or 0) indicating our interceptor modifications perfectly patched the
duplication defect.
• Overwrote PR_DESCRIPTION.md logging the new changes and ensuring the
commit contained Closes Reconcile predictions table against on-chain balances nightly #123.
• I branched from main to feature/reports-idempotency, staged the files,
and created a well-formatted commit mapping to your exact requested
format.
closes Add Idempotency-Key support on /api/reports mutations [b#071] #645