Expand description
Web Push notification service.
Stores push subscriptions per wallet in Postgres and delivers notifications via the Web Push protocol (VAPID-signed, RFC 8291).
Subscriptions are cached in memory (DashMap) to avoid a DB query on every fill. The cache is invalidated on subscribe/unsubscribe.
Push delivery is decoupled from the event forwarder via a bounded mpsc channel. A single background task drains the queue and sends up to MAX_CONCURRENT_SENDS push messages in parallel.
StructsΒ§
- PushJob π
- Internal message sent through the bounded channel from the event forwarder to the background push sender task.
- Push
Notification Service - Push
Payload - JSON payload sent inside the push message. The service worker parses this to decide what to show.
EnumsΒ§
- Notification
Type - Notification category. The backend checks the userβs preferences before sending a push for each category.
ConstantsΒ§
- ALLOWED_
PUSH_ πENDPOINT_ PREFIXES - Allowed push endpoint URL prefixes. Rejects anything that isnβt a known browser push service to prevent SSRF.
- CACHE_
MAX_ πENTRIES - Maximum number of wallets to cache. When exceeded, the cache is cleared entirely (simple eviction strategy suitable for this use case since most entries are empty vecs and re-population is cheap).
- MAX_
CONCURRENT_ πSENDS - Maximum number of push HTTP requests in flight at once.
- MAX_
SUBSCRIPTIONS_ πPER_ WALLET - Maximum push subscriptions per wallet. Prevents a single wallet from registering thousands of endpoints.
- PUSH_
QUEUE_ πCAPACITY - Bounded channel capacity for pending push jobs. If the sender task falls behind, new jobs are dropped (best-effort delivery).
FunctionsΒ§
- default_
preferences - Default preferences: everything enabled.
- get_
subscriptions π - Load subscriptions for a wallet, using cache when available.
- is_
enabled π - Check whether a subscription has a given notification type enabled. Missing keys default to enabled. Non-boolean values are treated as disabled (reject malformed preferences rather than silently enabling).
- push_
sender_ πloop - Single background task that drains the push job queue and sends notifications with bounded concurrency.
- remove_
stale π - to_
base64url π - Normalize a base64 or base64url string to base64url (no padding).