Repository navigation
feat(notifications): add scheduled email reports - #1841
Merged
github-actions[bot] merged 1 commit intoOct 19, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
Implements issue Smartdevs17#1758. Merchants can now schedule recurring analytics summary emails (daily / weekly / monthly) delivered via the existing EmailProvider (SendGrid or SES). New files backend/services/notification/scheduledReportService.ts - ScheduledReportService: CRUD for schedules, recipient management, buildReportEmail() (pure renderer), sendReport(), runDue() - InMemoryReportStore with injectable ReportStore interface for swap-in - nextSendAt() helper with clock-drift-safe hour normalisation - Report types: analytics_summary, mrr_breakdown, churn_report, full_report backend/services/notification/scheduledReportRouter.ts - Plain Node.js HTTP router (no framework) mounted at /scheduled-reports - POST / GET (list) / GET /:id / PATCH /:id / DELETE /:id - POST /:id/recipients DELETE /:id/recipients - POST /:id/send-now (ad-hoc trigger) backend/services/notification/jobs/scheduledReportJob.ts - createScheduledReportPoller() — lightweight setInterval loop (15 min) - registerScheduledReportJob() — registers with WeightedFairQueue - createScheduledReportHandler() — queue handler factory backend/services/notification/__tests__/scheduledReportService.test.ts - 49 unit tests; all passing Modified backend/server.ts — wires the service, router, and poller into the server lifecycle; poller stopped cleanly on shutdown Closes Smartdevs17#1758
This branch was successfully deployed
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 #1758
Summary
Merchants can now schedule recurring analytics summary emails (daily, weekly, or monthly) delivered via the existing
EmailProvider(SendGrid or SES). Previously reports had to be pulled manually.Changes
New files:
backend/services/notification/scheduledReportService.tsrunDue()batch processing. IncludesInMemoryReportStorewith an injectableReportStoreinterface for swap-in persistence.backend/services/notification/scheduledReportRouter.ts/scheduled-reports. Routes:POST(create),GET(list),GET/:id,PATCH/:id,DELETE/:id,POST/:id/recipients,DELETE/:id/recipients,POST/:id/send-now.backend/services/notification/jobs/scheduledReportJob.tscreateScheduledReportPoller()(15-minsetIntervalloop),registerScheduledReportJob()(WeightedFairQueue),createScheduledReportHandler()(queue handler factory).backend/services/notification/__tests__/scheduledReportService.test.tsModified:
backend/server.ts— wires the service, router, and poller into the server lifecycle; poller is stopped cleanly on shutdown.Design decisions
runDue()accepts asnapshotFor()callback so the service has no hard dependency onSubscriptionAnalyticsService— easy to test and swap.sendReport()iterates recipients individually; one bad address doesn't block the rest; errors are collected in the result.nextSendAt()normalises to the start of the hour so minor drift doesn't cause a full-period skip.InMemoryReportStoreis the default; a real DB store can be injected via theReportStoreinterface without touching the service.escapeHtml()applied to all user-controlled strings in HTML output; subject is escaped once, not double-escaped.Acceptance criteria (from issue)
Testing
Covers:
nextSendAt()for all frequencies, schedule CRUD validation, recipient management, email rendering for all 4 report types, HTML escaping, partial send failures, post-send timestamp advance,runDue()skipping disabled/empty schedules, and snapshot error isolation.