@haykal/notifications-backend
v1.0.0
Published
Multi-channel notification system for the Haykal platform.
Readme
@haykal/notifications-backend
Multi-channel notification system for the Haykal platform.
Features
- Multi-channel delivery: Email, Push, SMS, and In-App notifications
- Template system: Handlebars-based notification templates with variable interpolation
- User preferences: Per-type, per-channel notification preferences
- Pluggable channels: Implement
NotificationChannelinterface to add custom channels - Event-driven: Trigger notifications via domain events or direct service API
- Real-time: SSE support for in-app notification streaming
Usage
import { NotificationsModule } from '@haykal/notifications-backend';
@Module({
imports: [
NotificationsModule.forRoot({
channels: {
inApp: { enabled: true },
email: { enabled: false },
push: { enabled: false },
sms: { enabled: false },
},
defaultChannels: ['in_app'],
retentionDays: 90,
}),
],
})
export class AppModule {}Sending Notifications
@Injectable()
export class OrdersService {
constructor(private readonly notifications: NotificationSenderService) {}
async shipOrder(orderId: string) {
await this.notifications.send({
userId: order.userId,
type: 'order.shipped',
data: { orderId, trackingNumber },
});
}
}Key Exports
| Export | Type | Description |
| ------------------------------ | ------------- | ----------------------------------------------- |
| NotificationsModule | NestJS Module | Main module with forRoot() / forRootAsync() |
| NotificationSenderService | Service | Send notifications across channels |
| NotificationEntity | Entity | Notification records |
| NotificationPreferenceEntity | Entity | User notification preferences |
| NotificationTemplateEntity | Entity | Notification templates |
| NOTIFICATION_ENTITIES | Array | Entities for migration discovery |
| EmailChannel | Channel | Email notification delivery |
| InAppChannel | Channel | In-app notification (SSE) |
| PushChannel | Channel | Push notification delivery |
| SmsChannel | Channel | SMS notification delivery |
Related Packages
@haykal/notifications-client— React Query hooks for notifications@haykal/email-backend— Email delivery provider@haykal/jobs-backend— Queue integration for async delivery@haykal/core-backend— Base infrastructure
Further Reading
- API Reference — Full endpoint listing
- Backend Style Guide — Coding conventions
