All files / lib/communication types.ts

0% Statements 0/4
100% Branches 0/0
100% Functions 0/0
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                                                                                                                                                                                                                 
import type { WhatsAppTemplateComponent } from "../whatsapp/types";
 
// ── Channels & Statuses ──
export const COMMUNICATION_CHANNELS = ["email", "whatsapp", "sms"] as const;
export type CommunicationChannel = (typeof COMMUNICATION_CHANNELS)[number];
 
export const COMMUNICATION_STATUSES = ["queued", "sent", "failed", "skipped"] as const;
export type CommunicationStatus = (typeof COMMUNICATION_STATUSES)[number];
 
export const COMMUNICATION_EVENT_TYPES = [
	"new_inquiry",
	"inquiry_confirmation",
	"password_reset",
	"email_verification",
	"welcome",
	"team_invitation",
	"blog_approval_request",
	"blog_approval_reminder",
	"blog_published",
	"email_verified",
	"onboarding_complete",
	"pro_account_published",
	"pro_account_archived",
	"website_build_success",
	"website_build_failed",
	"reminder_due",
	"otp_verification",
	"magic_link",
] as const;
export type CommunicationEventType = (typeof COMMUNICATION_EVENT_TYPES)[number];
 
// ── Content Types ──
export type EmailContent = {
	template: string;
	subject: string;
	props: Record<string, unknown>;
	recipientName?: string;
};
 
export type WhatsAppContent = {
	templateName: string;
	languageCode: string;
	components?: WhatsAppTemplateComponent[];
	textBody?: string;
};
 
export type SmsContent = {
	code: string;
};
 
// ── Gateway Request ──
export type CommunicationRequest = {
	channel: CommunicationChannel;
	recipient: string;
	eventType: CommunicationEventType;
	proId?: string;
	userId?: string;
	content: EmailContent | WhatsAppContent | SmsContent;
	transactional?: boolean;
	metadata?: Record<string, unknown>;
};
 
// ── Queue Message ──
export type CommunicationQueueMessage = {
	type?: "send";
	logId: number;
	channel: CommunicationChannel;
	recipient: string;
	eventType: CommunicationEventType;
	proId?: string;
	userId?: string;
	content: EmailContent | WhatsAppContent | SmsContent;
	transactional?: boolean;
	metadata?: Record<string, unknown>;
};
 
// ── Adapter Result ──
// Error codes discriminate between compliance failures (drive suppression) and
// transport failures (drive retry). See marketing-comms-platform.md code
// quality invariants.
export const ADAPTER_ERROR_CODES = [
	"transport",
	"policy",
	"template_rejected",
	"rate_limit",
	"quota",
	"content_filtered",
	"suppressed",
	"config",
	"unknown",
] as const;
export type AdapterErrorCode = (typeof ADAPTER_ERROR_CODES)[number];
 
export type AdapterResult = {
	status: "sent" | "failed" | "skipped";
	actualRecipient: string;
	provider: string;
	externalId?: string;
	previewHtml?: string;
	previewText?: string;
	errorMessage?: string;
	errorCode?: AdapterErrorCode;
};