@withpotter/communication — module reference
HTTP routes this module mounts, plus its internal use-cases, entities, and repositories. The exhaustive request/response contract is the engine’s OpenAPI document at /docs; the layered structure below follows the package internal architecture.
HTTP routes
Communications /communications
| Method | Path | Auth | Description |
|---|---|---|---|
GET | /communications/logs | Yes | List notification logs |
GET | /communications/messaging-credits | Yes | Get messaging credit balance and info |
GET | /communications/messaging-credits/monthly-usage | Yes | Get messaging credit usage grouped by month |
GET | /communications/messaging-credits/transactions | Yes | Get messaging credit transaction history |
GET | /communications/messaging-credits/usage | Yes | Get messaging usage statistics |
GET | /communications/preferences/:memberId | Yes | Get notification preferences for a member |
GET | /communications/stats | Yes | Get notification statistics |
GET | /communications/templates | Yes | List all email templates |
GET | /communications/templates/:id | Yes | Get an email template by ID |
POST | /communications/messaging-credits/initialize-purchase | Yes | Initialize a Paystack payment to purchase messaging credits |
POST | /communications/messaging-credits/purchase | Yes | Manually add messaging credits (admin only) |
POST | /communications/send | Yes | Send an email using a template |
POST | /communications/send-bulk | Yes | Send bulk email using a template |
POST | /communications/send-sms | Yes | Send an SMS message |
POST | /communications/send-whatsapp | Yes | Send a WhatsApp message |
POST | /communications/templates | Yes | Create an email template |
POST | /communications/test-email | Yes | Send a test email to verify email configuration |
POST | /communications/test-sms | Yes | Send a test SMS to verify SMS configuration |
POST | /communications/test-whatsapp | Yes | Send a test WhatsApp to verify configuration |
PUT | /communications/preferences/:memberId | Yes | Update notification preferences for a member |
PUT | /communications/templates/:id | Yes | Update an email template |
DELETE | /communications/templates/:id | Yes | Delete an email template |
ResendWebhookController /webhooks/resend
| Method | Path | Auth | Description |
|---|---|---|---|
POST | /webhooks/resend | — | Handle webhook |
Internals
Use-cases
Application operations. Each is a single-purpose class with one execute() method.
| Use-case | Signature |
|---|---|
CreateEmailTemplateUseCase | execute(tenantId: string, dto: CreateEmailTemplateDto): Promise<EmailTemplateResponseDto> |
DeleteEmailTemplateUseCase | execute(tenantId: string, templateId: string): Promise<void> |
GetEmailTemplateUseCase | execute(tenantId: string, templateId: string): Promise<EmailTemplateResponseDto> |
GetNotificationStatsUseCase | execute(tenantId: string, startDate?: Date, endDate?: Date): Promise<NotificationStatsDto> |
GetPreferencesUseCase | execute(tenantId: string, memberId: string): Promise<PreferencesResponseDto> |
ListEmailTemplatesUseCase | execute(tenantId: string, type?: EmailTemplateType): Promise<EmailTemplateResponseDto[]> |
ListNotificationLogsUseCase | execute(tenantId: string, query: NotificationLogQueryDto): Promise<NotificationLogListResponseDto> |
SendBulkEmailUseCase | execute(tenantId: string, templateType: EmailTemplateType, templateId: string | undefined, recipients: BulkRecipient[], commonVariables?: Record<string, string>): Promise<BulkEmailSendResult> |
SendEmailUseCase | execute(tenantId: string, dto: SendEmailDto): Promise<EmailSendResult> |
SendSmsUseCase | execute(tenantId: string, dto: SendSmsDto): Promise<SmsSendResult> |
SendTestEmailUseCase | execute(tenantId: string, toEmail: string): Promise<{ success: boolean; message: string }> |
UpdateEmailTemplateUseCase | execute(tenantId: string, templateId: string, dto: UpdateEmailTemplateDto): Promise<EmailTemplateResponseDto> |
UpdatePreferencesUseCase | execute(tenantId: string, memberId: string, dto: UpdatePreferencesDto): Promise<PreferencesResponseDto> |
Entities
Sequelize models owned by this module.
EmailTemplate — table email_templates
| Field | Type |
|---|---|
id | string |
tenantId | string |
type | EmailTemplateType |
name | string |
subject | string |
htmlContent | string |
textContent | string |
variables | Record<string, string> |
isActive | boolean |
isDefault | boolean |
createdAt | Date |
updatedAt | Date |
id | string |
tenantId | string |
channel | NotificationChannel |
templateType | EmailTemplateType |
templateId | string | null |
memberId | string | null |
recipientEmail | string | null |
recipientPhone | string | null |
subject | string |
content | string |
metadata | Record<string, unknown> |
status | NotificationStatus |
errorMessage | string | null |
externalId | string | null |
sentAt | Date | null |
deliveredAt | Date | null |
createdAt | Date |
updatedAt | Date |
id | string |
tenantId | string |
memberId | string |
orderConfirmation | boolean |
orderShipped | boolean |
orderDelivered | boolean |
newsletter | boolean |
promotional | boolean |
reviewRequest | boolean |
abandonedCart | boolean |
emailEnabled | boolean |
smsEnabled | boolean |
pushEnabled | boolean |
createdAt | Date |
updatedAt | Date |
id | string |
messageType | MessageType |
scope | PricingScope |
organizationId | string | null |
tenantId | string | null |
costPerUnit | number |
currency | string |
effectiveFrom | Date | null |
effectiveUntil | Date | null |
isActive | boolean |
notes | string | null |
createdAt | Date |
updatedAt | Date |
Repositories
Data-access classes wrapping the entities.
EmailTemplateRepository
create · findById · findByTenantAndType · findAllByTenant · findByType · update · delete · setDefault · updateStatus · findWithFilters · getStats · findByMember · deleteOldLogs · getOrCreate · shouldSendNotification · getPricing · findByScope · seedPlatformDefaults
Services
EmailCreditsSchedulerEmailCreditsServiceEmailServiceMessagingCreditsSchedulerMessagingCreditsServiceNotificationDispatcherResendWebhookServiceSmsServiceTemplateServiceUsageTrackingServiceWhatsAppService
Providers
MetaWhatsAppProviderPlatformEmailProviderPlatformSmsProviderPlatformWhatsAppProviderResendProviderTermiiProviderTermiiWhatsAppProviderTwilioSmsProviderTwilioWhatsAppProvider
Generated from the module’s source. Routes are relative to the engine root
(default http://localhost:3001). For full request/response schemas use the live
OpenAPI document.