@islamgalal-mdlabs/notification-module
v1.0.42
Published
A reusable module for handling notifications in nestjs applications
Readme
NestJS Notification Module
A powerful and flexible notification module for NestJS applications with multi-tenancy support, designed for managing notifications across multiple channels.
Features
- 🏢 Multi-tenancy support out of the box
- 📨 Multiple notification channels support
- 🔌 Pluggable architecture with dependency injection
- 📦 Easy integration with existing NestJS applications
- 🗄️ Database storage with TypeORM
- 📋 Flexible message templating
- 🎯 Topic-based notifications
- 👥 Recipient management
- ⚙️ Configurable notification settings per tenant
Installation
npm install @islamgalal_mdlabs/notification-moduleQuick Start
- Import the NotificationModule in your app.module.ts:
import { NotificationModule } from '@islamgalal_mdlabs/notification-module';
@Module({
imports: [
NotificationModule.register({
connectionProvider: {
// Your multi-tenant connection provider
getTenantConnection: async (tenantId: string) => {
// Return TypeORM connection for the tenant
},
},
// Additional configuration options
}),
],
})
export class AppModule {}- Inject and use the NotificationService:
import { NotificationService } from '@islamgalal_mdlabs/notification-module';
@Injectable()
export class YourService {
constructor(private readonly notificationService: NotificationService) {}
async sendNotification(tenantId: string) {
// Use the notification service with tenant context
const notification = await this.notificationService.findById(tenantId, 1);
// Additional notification operations
}
}Database Structure
The module includes the following main entities:
Notification: Core notification entityNotificationTopic: For topic-based notificationsNotificationRecipient: Manages notification recipientsTopicSubscription: Handles topic subscriptionsNotificationConfiguration: Tenant-specific settings
Database Migrations
The module provides TypeORM migrations for all required tables. To use them:
# Run migrations
npm run migration:run
# Revert migrations
npm run migration:revertConfiguration
Module Configuration
Configure the module with your connection provider and additional options:
NotificationModule.register({
connectionProvider: {
getTenantConnection: async (tenantId: string) => {
// Implement your connection logic
return connection;
},
},
// Additional configuration options
});Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the MIT License.
