feat(notifications): cross-channel digest subscriptions (#365) - #419
Open
BernardOnuh wants to merge 1 commit into
Open
feat(notifications): cross-channel digest subscriptions (#365)#419BernardOnuh wants to merge 1 commit into
BernardOnuh wants to merge 1 commit into
Conversation
) Opt-in DAILY/WEEKLY/MONTHLY portfolio summaries delivered over a user's chosen channels (WHATSAPP + WEBHOOK wired; TELEGRAM/EMAIL reserved). - schema: DigestFrequency/DigestChannel enums + DigestSubscription model, migration + rollback (validated with prisma migrate diff — zero drift) - src/notifications: pure buildDigest assembler, per-channel renderer, UTC schedule/quiet-hours helpers, DB/data loader - src/jobs/digests.ts: atomic per-occurrence claim, assemble-once/deliver- per-channel, quiet-hour defer (never drop), catch-up storm guard - digest.generated added as socket-only alert-topic event; delivered to the user's own webhook endpoints, never operator webhooks - routes: /api/v1/notifications/digests CRUD + rate-limited preview, channel-link validation; Zod validators - docs: DIGESTS.md, openapi.yaml paths/schemas, stream/webhook notes - tests: 16 unit tests; full suite 1739 passing; tsc + eslint clean Closes Neurowealth#365
|
@BernardOnuh 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 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 Cross-Channel Digest Notifications (#365) — an opt-in daily / weekly / monthly portfolio summary delivered over a user's own channels. This PR wires WHATSAPP + WEBHOOK delivery end to end. TELEGRAM has no outbound push engine and EMAIL is a sibling issue (#367); both channel enum values are reserved but not yet wired.
A digest is a scheduled "here's how your money did this period" message (portfolio value change, yield, agent rebalances, goal progress, one risk line, notable transactions) — distinct from event-triggered alerts.
Changes Made
Schema & migration
DigestFrequency(DAILY|WEEKLY|MONTHLY) andDigestChannel(WHATSAPP|TELEGRAM|EMAIL|WEBHOOK) enums.DigestSubscriptionmodel +User.digestSubscriptionsrelation.20260904000000_add_digest_subscriptions+ rollback. Validated withprisma migrate deployagainst a local Postgres andprisma migrate diff→ zero digest-related drift.Digest core (
src/notifications/)digest.ts— pure, deterministicbuildDigest(channel-agnosticDigestModel). "Honesty discipline": insufficient snapshot coverage →nulldelta +caveat, never a fabricated number; no positions → short "deposit to get started" digest.render.ts— per-channel rendering (WHATSAPPconcise text;WEBHOOK/EMAILreturn structured/null),isChannelDeliverable.schedule.ts— UTCnextOccurrence,deferForQuietHours,isQuietHours; MONTHLY clamps to last day.load.ts—loadDigestData+periodFromFrequency(positions, snapshots, CONFIRMED txns, rebalances,computeGoalProgress).Scheduled job (
src/jobs/digests.ts)updateManyon{id, isActive, nextRunAt}) → no double-send.nextRunAtback for retry.src/index.tsstartup + graceful shutdown;config.digests.intervalMsfromDIGESTS_INTERVAL_MS.Delivery path
digest.generatedadded as a socket-only event type on thealertstopic (src/events/types.ts) → durable stream + live sockets + the user's own webhook endpoints, never operator webhooks. Payload allowlist added insrc/utils/api-formatters.ts.API (
src/routes/digests.ts+src/validators/digest-validators.ts)POST /api/v1/notifications/digests,GET /,GET /preview,PATCH /:id,DELETE /:id.WEEKLYrequiresweeklyDayUtc; 409 on duplicate active subscription.Docs
docs/DIGESTS.md(new);docs/openapi.yamlpaths + schemas; notes added todocs/WEBSOCKET_STREAMING.mdanddocs/USER_WEBHOOKS.md.Test Plan
tests/unit/notifications/digest.test.ts(7) +schedule.test.ts(6) — 16 new tests, all pass.npx tsc --noEmitclean;npx eslintclean;prisma validate+prisma generatepass.Breaking Changes
None — additive (new table, new enums, new socket-only event, new endpoints, new job).
Notes
docs/NOTIFICATIONS.md(the EMAIL-channel doc) is untouched; digest docs live indocs/DIGESTS.mdto avoid clobbering the sibling channel's documentation.Closes #365