@xtr-dev/payload-mailing
Version:
Template-based email system with scheduling and job processing for PayloadCMS
110 lines • 3.46 kB
TypeScript
import { Payload, SendEmailOptions } from 'payload';
import type { CollectionConfig, RichTextField } from 'payload';
export type PayloadID = string | number;
export type PayloadRelation<T extends {
id: PayloadID;
}> = T | PayloadID;
export type JSONValue = string | number | boolean | {
[k: string]: unknown;
} | unknown[] | null | undefined;
export interface BaseEmailDocument {
id: string | number;
template?: any;
templateSlug?: string | null;
to: string[];
cc?: string[] | null;
bcc?: string[] | null;
from?: string | null;
fromName?: string | null;
replyTo?: string | null;
subject: string;
html: string;
text?: string | null;
variables?: JSONValue;
scheduledAt?: string | Date | null;
sentAt?: string | Date | null;
status?: 'pending' | 'processing' | 'sent' | 'failed' | null;
attempts?: number | null;
lastAttemptAt?: string | Date | null;
error?: string | null;
priority?: number | null;
createdAt?: string | Date | null;
updatedAt?: string | Date | null;
}
export interface BaseEmailTemplateDocument {
id: string | number;
name: string;
slug: string;
subject?: string | null;
content?: any;
createdAt?: string | Date | null;
updatedAt?: string | Date | null;
}
export type TemplateRendererHook = (template: string, variables: Record<string, any>) => string | Promise<string>;
export type TemplateEngine = 'liquidjs' | 'mustache' | 'simple';
export type BeforeSendHook = (options: SendEmailOptions, email: BaseEmailDocument) => SendEmailOptions | Promise<SendEmailOptions>;
export interface JobPollingConfig {
maxAttempts?: number;
initialDelay?: number;
maxTotalTime?: number;
maxBackoffDelay?: number;
}
export interface MailingPluginConfig {
collections?: {
templates?: string | Partial<CollectionConfig>;
emails?: string | Partial<CollectionConfig>;
};
defaultFrom?: string;
defaultFromName?: string;
queue?: string;
retryAttempts?: number;
retryDelay?: number;
templateRenderer?: TemplateRendererHook;
templateEngine?: TemplateEngine;
richTextEditor?: RichTextField['editor'];
beforeSend?: BeforeSendHook;
initOrder?: 'before' | 'after';
jobPolling?: JobPollingConfig;
}
export interface QueuedEmail {
id: string;
template?: string | null;
to: string[];
cc?: string[] | null;
bcc?: string[] | null;
from?: string | null;
fromName?: string | null;
replyTo?: string | null;
subject: string;
html: string;
text?: string | null;
variables?: JSONValue;
scheduledAt?: string | Date | null;
sentAt?: string | Date | null;
status: 'pending' | 'processing' | 'sent' | 'failed';
attempts: number;
lastAttemptAt?: string | Date | null;
error?: string | null;
priority?: number | null;
createdAt: string;
updatedAt: string;
}
export interface TemplateVariables {
[key: string]: any;
}
export interface MailingService {
processEmails(): Promise<void>;
processEmailItem(emailId: string): Promise<void>;
retryFailedEmails(): Promise<void>;
renderTemplate(templateSlug: string, variables: TemplateVariables): Promise<{
html: string;
text: string;
subject: string;
}>;
}
export interface MailingContext {
payload: Payload;
config: MailingPluginConfig;
service: MailingService;
}
//# sourceMappingURL=index.d.ts.map