feat(api): propagate X-Correlation-Id through /api/invites handlers and outbound calls - #713
Merged
greatest0fallt1me merged 3 commits intoJul 29, 2026
Conversation
…nd outbound calls - Add Zod input validation (strict) for POST body and GET query params - Consume correlation ID from correlationMiddleware for structured logging - Echo X-Correlation-Id response header on every invite endpoint - Propagate correlation ID to optional outbound webhook calls via fetchWithCorrelationId - Add missing logger import to rateLimit.ts (fixes all 429 -> 500 bugs) - Add 12 focused correlation tests; all 19 invites tests passing - Coverage: invites.ts 95.55%, correlation.ts 90.9% (both > 90%) Closes Predictify-org#626
|
@Nife-tanny 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
|
CI green, LGTM ✨ merged. |
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.
feat: propagate X-Correlation-Id through /api/invites handlers
Closes #626
Summary
Generate, accept, and propagate
X-Correlation-Idthroughout the/api/invitesrequest lifecycle — including outbound calls, structured logging, validation errors, and response headers.Changes
src/middleware/correlation.ts(unchanged)The existing correlation middleware was already comprehensive and globally mounted in
src/index.ts. No changes were needed.src/routes/invites.tscreateInviteSchema(optionalrecipientEmail,message,outboundUrl). GET query validated againstlistInvitesQuerySchema(optionallimit,cursor). Unknown properties rejected via.strict().getCorrelationId()withres.locals.correlationIdfallback).X-Correlation-Idheader.correlationIdfield via Pino.outboundUrlfield triggers an outbound HTTP call usingfetchWithCorrelationId(), which injects the sameX-Correlation-Idheader into the downstream request.next(e)for centralized error handling.src/middleware/rateLimit.ts(pre-existing bug fix)import { logger } from "../config/logger"— the rate limiter's on-block handler was callinglogger.warn()without importing it, causing all 429 rate-limit responses to return 500 withinternal_error. This bug affected every route usingcreatePerUserTokenBucketLimiter.tests/invites.test.tsrequestContextmock to preserverequestContextStorageviajest.requireActual()stellarAddressmock to be unique per user for rate limit isolationmakeAppWithCorrelation()for correlation propagation tests (separate from basicmakeApp())New correlation tests:
Coverage
src/routes/invites.tssrc/middleware/correlation.tsValidation
npm test -- tests/invites.test.tsnpm test -- tests/tokenBucketRateLimit.test.tsnpm run lint(changed files)Security
X-Correlation-Idis sanitised bycorrelationMiddleware(only[A-Za-z0-9\-_]allowed, max 128 chars)X-Correlation-Id, not other inbound headersAPI Changes
POST /api/invitesnow accepts optional body fields:recipientEmail(email),message(string, max 1000),outboundUrl(URL for webhook)GET /api/invitesnow accepts optional query params:limit(1–100),cursor(pagination token)X-Correlation-Idresponse header400 validation_error400 validation_errorFiles Changed
Pre-existing Issues Fixed
src/middleware/rateLimit.tsmissingloggerimport — all token-bucket rate-limit blocks were silently returning 500 instead of 429. This was discovered and fixed as part of this work since it blocked invites rate-limit tests.