Skip to content

feat: service worker push notification router with topic registry (#55) - #82

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/push-notification-router
Jun 25, 2026
Merged

feat: service worker push notification router with topic registry (#55)#82
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/push-notification-router

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

Service Worker Push Notification Router with Topic-Based Subscription Registry (#55)

Closes #55

File Responsibility
src/types/notification.ts Topic/payload/action/toast types and invariants: 3-level taxonomy, 200 topics × 5 handlers, 60s window, 2 actions, 4 KB payload.
src/utils/topicRouter.ts Topic trie: insert(pattern, handler) → unsubscribe, match(topic) collecting the exact path and every trailing-wildcard ancestor (meter.*meter.water.breach), limit enforcement, isolated emit, plus the shared coalescenceKey(topic, body) helper.
src/services/pushSubscriptionManager.ts VAPID subscribe/unsubscribe (userVisibleOnly: true), REST register (POST)/remove (DELETE), urlBase64ToUint8Array. Transport + registration injectable.
src/store/slices/notificationSlice.ts Coalescing queue store + useNotifications: same key → increment count and extend the 60s auto-dismiss timer; injectable clock/scheduler.
src/hooks/usePushNotifications.ts Orchestrates permission prompt, subscription, and a navigator.serviceWorker message listener that fans foreground pushes to the topic router and the toast queue.
src/components/panels/ToastContainer.tsx In-app toasts grouped by coalescence key with "(N more)" and up to 2 action buttons (URL or internal route).
public/sw.js Extended with push + notificationclick listeners: a visible client gets a postMessage; in the background a tag-coalesced system notification is shown (count folded into the title), and clicks focus/open the action's target.
tests/unit/* Router (exact/wildcard matching, limits, isolation), subscription manager (base64url decode, subscribe/reuse/DELETE), and the coalescence store (count, window extension, auto-dismiss, action cap).

…ility-Protocol#55)

Adds a topic-based push notification router so UI modules can subscribe to
specific event topics, with 60s coalescence and a foreground in-app toast
fallback.

- types/notification.ts: topic/payload/action/toast types and bounds (3-level
  taxonomy, 200 topics × 5 handlers, 60s window, 2 actions, 4KB payload)
- utils/topicRouter.ts: topic trie — insert/match with trailing-wildcard
  ancestor matching (meter.* → meter.water.breach), limit enforcement, isolated
  emit, plus the shared coalescenceKey helper
- services/pushSubscriptionManager.ts: VAPID subscribe/unsubscribe with
  userVisibleOnly, REST register/DELETE, urlBase64ToUint8Array (injectable)
- store/slices/notificationSlice.ts: coalescing queue store + useNotifications;
  identical events increment a count and extend the 60s auto-dismiss timer
- hooks/usePushNotifications.ts: permission prompt, subscribe, and a
  navigator.serviceWorker message listener fanning foreground pushes to the
  topic router and toast queue
- components/panels/ToastContainer.tsx: coalesced toasts with '(N more)' and
  up to 2 action buttons (url/route)
- public/sw.js: push + notificationclick listeners — foreground clients get a
  postMessage, background shows a tag-coalesced system notification
- unit tests for the router, subscription manager, and coalescence store
@elizabetheonoja-art
elizabetheonoja-art merged commit 61f4791 into Utility-Protocol:main Jun 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service Worker Push Notification Router with Topic-Based Subscription Registry

2 participants