@c11/notifications-nestjs
v1.0.5
Published
NestJS module for notifications: in-app and email channels, TypeORM-backed storage, and pluggable resolvers and content providers.
Downloads
348
Readme
@c11/notifications-nestjs
NestJS module for notifications: in-app and email channels, TypeORM-backed storage, and pluggable resolvers and content providers.
Installation
npm install @c11/notifications-nestjsPeer dependencies: @nestjs/common, @nestjs/core, @nestjs/schedule, @nestjs/typeorm, typeorm, reflect-metadata. Ensure your app has them installed.
Usage
Register the module with forRoot() and optional overrides:
import { NotificationsModule } from "@c11/notifications-nestjs";
@Module({
imports: [
NotificationsModule.forRoot({
imports: [YourConfigModule], // modules that export your custom providers
providers: [
{ provide: NotificationEmailResolver, useClass: YourEmailResolver },
{ provide: NotificationEmailContentProvider, useClass: YourEmailContentProvider },
// optional: NotificationMailSender, NotificationInAppContentProvider
],
}),
],
})
export class AppModule {}- NotificationEmailResolver: resolve email for a receiver (user id).
- NotificationEmailContentProvider: build subject/body for email deliveries.
- NotificationMailSender: send emails (default: console logger).
- NotificationInAppContentProvider: build in-app content (default: minimal).
Exported services: NotificationsService, NotificationRepository, NotificationDeliveryRepository, and channel handlers as needed.
Database (TypeORM)
The module uses two entities:
- NotificationEntity → table
notifications - NotificationDeliveryEntity → table
notification_deliveriesand join tablenotification_delivery_notifications
Include the provided entities in your TypeORM setup so the schema is known to TypeORM. When you import NotificationsModule, it registers these entities via TypeOrmModule.forFeature(). If your app uses TypeOrmModule.forRoot({ autoLoadEntities: true }), they are picked up automatically. Otherwise, add NotificationEntity and NotificationDeliveryEntity (imported from @c11/notifications-nestjs) to your TypeORM root config or feature modules so they are part of your DataSource.
Generate a migration for your database from these entities using TypeORM’s migration generator (e.g. npm run typeorm migration:generate -- -n AddNotifications or your app’s equivalent). Then run the migration. This package does not ship migration files; the consuming app is responsible for generating and running migrations.
License
PRIVATE
