You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add notification preferences and Web Push subscription APIs #1718
Push permission is browser- and device-specific, while notification preferences belong to an authenticated ProPR user. The backend must store both without ever exposing VAPID private-key material.
Requirements
Add core helpers to read and update notification preferences.
Validate category values, HH:mm quiet-hour values, and IANA timezone identifiers.
Add endpoints for reading notification capability/configuration and preferences.
Add endpoints to create or refresh a browser push subscription and revoke it by endpoint.
Derive the subscription owner from the authenticated session.
Reject non-HTTPS push endpoints except localhost development endpoints.
Upsert by endpoint so repeated browser enrollment is idempotent.
Return only the VAPID public key to the browser.
Keep push disabled until the user explicitly opts in.
Acceptance Criteria
A new user receives documented default preferences.
Updating one preference does not silently reset unrelated categories.
Invalid timezones, quiet-hour values, or subscription keys return 400.
Resubscribing the same endpoint updates its keys and clears revoked_at.
Revocation affects only the authenticated user's matching endpoint.
The VAPID private key never appears in API responses or logs.
Store preferences separately from browser subscriptions because one user may install the PWA on several devices with different push endpoints. The browser subscription is treated as a replaceable transport credential; preferences are the durable user-level policy. Storing the whole PushSubscription JSON blob was considered but rejected because explicit columns make endpoint uniqueness, expiration, and revocation easier to query safely.
File: packages/core/src/services/notificationPreferencesService.ts (new file)
Why this file: This module normalizes persistence defaults and prevents route handlers or delivery jobs from interpreting preference JSON differently.
import{randomUUID}from'node:crypto';import{db}from'../db/connection.js';import{DEFAULT_NOTIFICATION_PREFERENCES,typeNotificationCategory,typeNotificationPreferences,typeWebPushSubscriptionInput,}from'@propr/shared';constcategories=['plans','tasks','pull_requests','indexing','system']asconst;constparseCategories=(raw: string|undefined): NotificationPreferences['categories']=>{try{return{ ...DEFAULT_NOTIFICATION_PREFERENCES.categories, ...JSON.parse(raw??'{}')};}catch{return{ ...DEFAULT_NOTIFICATION_PREFERENCES.categories};}};exportasyncfunctiongetNotificationPreferences(userId: string): Promise<NotificationPreferences>{constrow=awaitdb('notification_preferences').where({user_id: userId}).first();if(!row)returnstructuredClone(DEFAULT_NOTIFICATION_PREFERENCES);return{enabled: Boolean(row.enabled),pushEnabled: Boolean(row.push_enabled),badgeEnabled: Boolean(row.badge_enabled),quietHoursStart: row.quiet_hours_start,quietHoursEnd: row.quiet_hours_end,timezone: row.timezone,categories: parseCategories(row.categories_json),};}exportasyncfunctionsaveNotificationPreferences(userId: string,preferences: NotificationPreferences,): Promise<NotificationPreferences>{constnow=newDate().toISOString();awaitdb('notification_preferences').insert({user_id: userId,enabled: preferences.enabled,push_enabled: preferences.pushEnabled,badge_enabled: preferences.badgeEnabled,quiet_hours_start: preferences.quietHoursStart,quiet_hours_end: preferences.quietHoursEnd,timezone: preferences.timezone,categories_json: JSON.stringify(preferences.categories),updated_at: now,}).onConflict('user_id').merge();returngetNotificationPreferences(userId);}exportfunctionvalidateNotificationPreferences(value: unknown): NotificationPreferences{if(!value||typeofvalue!=='object')thrownewError('Preferences must be an object');constinput=valueasPartial<NotificationPreferences>;consttimePattern=/^([01][0-9]|2[0-3]):[0-5][0-9]$/;for(constcandidateof[input.quietHoursStart,input.quietHoursEnd]){if(candidate!==null&&candidate!==undefined&&!timePattern.test(candidate)){thrownewError('Quiet hours must use HH:mm in 24-hour time');}}try{newIntl.DateTimeFormat('en',{timeZone: input.timezone??'UTC'}).format();}catch{thrownewError('timezone must be a valid IANA timezone');}constnormalizedCategories={ ...DEFAULT_NOTIFICATION_PREFERENCES.categories};for(constcategoryofcategories){constselected=input.categories?.[categoryasNotificationCategory];if(selected!==undefined&&typeofselected!=='boolean'){thrownewError(`Category ${category} must be boolean`);}if(selected!==undefined)normalizedCategories[category]=selected;}return{enabled: input.enabled??true,pushEnabled: input.pushEnabled??false,badgeEnabled: input.badgeEnabled??true,quietHoursStart: input.quietHoursStart??null,quietHoursEnd: input.quietHoursEnd??null,timezone: input.timezone??'UTC',categories: normalizedCategories,};}exportasyncfunctionupsertPushSubscription(userId: string,subscription: WebPushSubscriptionInput,userAgent?: string,): Promise<void>{constnow=newDate().toISOString();awaitdb('push_subscriptions').insert({id: randomUUID(),user_id: userId,endpoint: subscription.endpoint,p256dh: subscription.keys.p256dh,auth: subscription.keys.auth,expiration_time: subscription.expirationTime,user_agent: userAgent??null,created_at: now,updated_at: now,revoked_at: null,}).onConflict('endpoint').merge({// Ownership follows the current authenticated enrollment. This permits a// browser profile to be re-associated after an account switch without// retaining delivery access for the prior user.user_id: userId,p256dh: subscription.keys.p256dh,auth: subscription.keys.auth,expiration_time: subscription.expirationTime,user_agent: userAgent??null,updated_at: now,revoked_at: null,});}exportasyncfunctionrevokePushSubscription(userId: string,endpoint: string): Promise<boolean>{return(awaitdb('push_subscriptions').where({user_id: userId, endpoint }).update({revoked_at: newDate().toISOString()}))>0;}
File: packages/core/src/index.ts
Why this file: The API and delivery dispatcher need the same normalized preference helpers.
Activity
propr-dev commentedon Aug 2, 2026
Suggested Implementation:
Implementation Approach
Store preferences separately from browser subscriptions because one user may install the PWA on several devices with different push endpoints. The browser subscription is treated as a replaceable transport credential; preferences are the durable user-level policy. Storing the whole PushSubscription JSON blob was considered but rejected because explicit columns make endpoint uniqueness, expiration, and revocation easier to query safely.
File:
packages/core/src/services/notificationPreferencesService.ts(new file)Why this file: This module normalizes persistence defaults and prevents route handlers or delivery jobs from interpreting preference JSON differently.
File:
packages/core/src/index.tsWhy this file: The API and delivery dispatcher need the same normalized preference helpers.
File:
packages/api/routes/notifications.tsWhy this file: Preferences and subscriptions belong beside the Inbox routes under one authenticated resource namespace.
propr-dev commentedon Aug 2, 2026
🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
codexgpt-5.6-sol1718/gpt-5.6-sol-add-notification-preferen-20260802-1158-5gv1716-epic-failed-to-3m8issue-1718-20260802-1158-gpt-5.6-sol-5gv🔍 Track Task Execution
fix(ai): Resolve issue #1718 - Add notification preferences and Web P…
fix(ai): Resolve issue #1718 - Add notification preferences and Web P…
[Epic] PWA & Web push (#1731)