feat(event-process): EnricherService (ua-parser + geoip + bot detect) (EVO-1212)#40
Open
nickoliveira23 wants to merge 1 commit into
Open
feat(event-process): EnricherService (ua-parser + geoip + bot detect) (EVO-1212)#40nickoliveira23 wants to merge 1 commit into
nickoliveira23 wants to merge 1 commit into
Conversation
…eo/bot (EVO-1212)
Implements story 3.6: enriches a received webhook envelope with parsed
user-agent (ua-parser-js), IP geolocation (reused GeoLocationService /
geoip-lite) and basic bot markers, before the pipeline persists it.
- EnricherService.enrich(envelope) => EnrichedEvent (envelope + { ua, geo, botMarkers })
- RecipientSourceExtractor: pulls the end-recipient UA/IP from the provider body
(sendgrid, mandrill, resend, mailersend, ses/SNS, sparkpost) since for email
engagement events the HTTP envelope only carries the provider's own infra;
falls back to the envelope (header UA / sourceIp) when the body lacks it
- bot detection via a small UA denylist (substring, case-insensitive);
isDatacenter is false in the MVP
- GeoLocationService reused as a provider (no ClickTrackingModule coupling)
- specs: enricher (AC1/AC2/AC3 + body-precedence + fallback) and extractor (per provider)
The handle() wire-up (enrich -> writer.enqueue) lands in story 3.7 (EVO-1213).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @nickoliveira23, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
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.
Summary
Implements story 3.6 (Webhook Event Pipeline): a new
EnricherServicethat enriches a received webhook envelope with parsed user-agent, IP geolocation and basic bot markers, before the event-process pipeline persists it.EnricherService.enrich(envelope) => EnrichedEvent= the envelope plus{ ua, geo, botMarkers }(theenrichmentshape reused fromEventsEnrichedContract).ua-parser-js; geo resolved with the existingGeoLocationService(geoip-lite), reused as a provider to avoid coupling to the wholeClickTrackingModule.isDatacenterisfalsein the MVP (datacenter IP ranges deferred to Growth, per the card).Recipient context (review follow-up, M1)
For email engagement events (open/click) the real recipient UA/IP live in the provider payload, not the HTTP envelope — the receiver fills
headers/sourceIpfrom the inbound POST, which is the provider's own infra.RecipientSourceExtractorpulls the recipient UA/IP from the body per provider (sendgrid,mandrill,resend,mailersend,sesvia SNS,sparkpost) and the enricher prefers it, falling back to the envelope when the body lacks it.Scope notes
mailersendreuses the engagement heuristic as a best-effort (payload shape not verified against a real fixture).EnricherServiceis registered but has no caller yet — thehandle()wire-up (enrich -> writer.enqueue) lands in story 3.7 (EVO-1213) per the epic sequencing. This is a tested unit awaiting its consumer, not dead code.Security
Test plan
evo-flow: npm run typecheck— cleanevo-flow: npx jest src/runners/event-process/services/enricher.service.spec.ts src/runners/event-process/services/recipient-source.extractor.spec.ts— 18 examples, 0 failuresevo-flow: npx eslint <changed .ts>— cleanCovers ACs: iPhone UA ->
device.type === 'mobile'(AC1),sourceIp 8.8.8.8->geo.country === 'US'(AC2, real geoip-lite), Googlebot ->isBot === true(AC3); plus body-over-envelope precedence and per-provider extraction.Changed Files
src/runners/event-process/services/enricher.service.ts(new)src/runners/event-process/services/enricher.service.spec.ts(new)src/runners/event-process/services/recipient-source.extractor.ts(new)src/runners/event-process/services/recipient-source.extractor.spec.ts(new)src/runners/event-process/event-process.module.tsLinked Issue