Notifications & Preferences
PreferenceAwareNotifier centralizes contact resolution, preference checks, and deduplication before emitting notifications.
Usage
import { PreferenceAwareNotifier } from '@digiwedge/auth';
import { NotificationType } from '@digiwedge/messaging-notifications';
import { Channel } from '@prisma/messaging';
await notifier.sendIfAllowed(
{
scope: NotificationType.ACTIVITY_FEED,
channel: Channel.EMAIL,
tenantId,
identifiers: { authUserId: user.id, email: user.email },
variables: { event: 'login_success', ipAddress, userAgent },
},
{ dedupKey: jti, failOpenOnResolveError: true },
);
Notes
| Feature | Description |
|---|---|
| Tenant ID | Provide tenantId for strict preference enforcement; omit only for non-critical flows |
| OTP scope | Use scope='OTP' and fail-open on lookup errors to avoid lockouts |
| Dedup key | Keeps downstream queues idempotent |
| Missing templates | Logged and the channel is skipped without blocking other sends |