Repository navigation
feat(notifications): add scheduled email reports - #1840
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
|
@retkatmun 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! 🚀 |
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 by merchant),GET/:id,PATCH/:id,DELETE/:id,POST/:id/recipients,DELETE/:id/recipients,POST/:id/send-now.backend/services/notification/jobs/scheduledReportJob.tscreateScheduledReportPoller()(lightweightsetIntervalloop, 15-min default),registerScheduledReportJob()(WeightedFairQueue registration),createScheduledReportHandler()(queue handler factory).backend/services/notification/__tests__/scheduledReportService.test.tsModified files:
backend/server.ts— wires the service, router, and poller into the server lifecycle. The poller is stopped cleanly on shutdown. Snapshot factory is stubbed with zeros (production should wire toSubscriptionAnalyticsService.compute()).Design decisions
runDue()accepts asnapshotFor()callback so the service has no dependency on the analytics layer — easy to test and swap implementations.sendReport()iterates recipients individually; one bad address doesn't block others. Errors are collected and returned in the result.nextSendAt()normalises to the start of the hour so minor drift doesn't cause a full-period skip.analytics_summary,mrr_breakdown,churn_report,full_report— each renders different sections.escapeHtml()applied to all user-controlled content in HTML output. The subject line is escaped once (not double-escaped).InMemoryReportStoreis the default; a real DB store can be injected via theReportStoreinterface without touching the service.Acceptance criteria
What was tested
npx jest --config jest.backend.config.js \ --testMatch '**/backend/services/notification/__tests__/scheduledReportService.test.ts'Result: 49 passed, 0 failed.
Test coverage includes:
nextSendAt()for all frequencies, schedule CRUD validation, recipient management, email rendering for all report types, HTML escaping, send with partial failures, post-send timestamp advance,runDue()skipping disabled/empty schedules, and snapshot error isolation.