feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services

This commit is contained in:
2026-07-21 18:53:11 -03:00
parent 40090cdec5
commit 10ca449f88
82 changed files with 10249 additions and 171 deletions
@@ -0,0 +1,71 @@
export enum NotificationJobStatus {
PENDING = "pending",
PROCESSING = "processing",
SENT = "sent",
FAILED = "failed",
CANCELLED = "cancelled",
}
export type NotificationChannel = "whatsapp" | "email" | "system";
export type NotificationJobType =
| "creation"
| "reminder"
| "update"
| "cancellation";
export interface NotificationJobPayload {
email?: string;
phoneNumber?: string;
userId?: string;
companyOwnerId?: string;
subject?: string;
message?: string;
emailSubject?: string;
emailMessage?: string;
wapMessage?: string;
systemSubject?: string;
systemMessage?: string;
}
export interface INotificationJob {
id?: string;
companyId: string;
appointmentId: string;
clientId: string;
channel: NotificationChannel;
type: NotificationJobType;
scheduledAt: Date;
status: NotificationJobStatus;
attempts: number;
maxAttempts: number;
lastError?: string;
nextRetryAt?: Date;
providerResponse?: string;
payload?: NotificationJobPayload;
createdAt: Date;
updatedAt: Date;
sentAt?: Date;
}
export interface CreateJobParams {
companyId: string;
appointmentId: string;
clientId: string;
channel: NotificationChannel;
type: NotificationJobType;
scheduledAt: Date;
payload?: NotificationJobPayload;
}
export interface INotificationJobAdapter {
create(data: CreateJobParams): Promise<INotificationJob>;
findPendingDue(now: Date): Promise<INotificationJob[]>;
updateStatus(
jobId: string,
status: NotificationJobStatus,
data?: { lastError?: string; nextRetryAt?: Date; providerResponse?: string }
): Promise<void>;
cancelByAppointment(appointmentId: string): Promise<void>;
findByAppointment(appointmentId: string): Promise<INotificationJob[]>;
}