96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
|
|
import { Email } from './classes.email.js';
|
||
|
|
/**
|
||
|
|
* Email template type definition
|
||
|
|
*/
|
||
|
|
export interface IEmailTemplate<T = any> {
|
||
|
|
id: string;
|
||
|
|
name: string;
|
||
|
|
description: string;
|
||
|
|
from: string;
|
||
|
|
subject: string;
|
||
|
|
bodyHtml: string;
|
||
|
|
bodyText?: string;
|
||
|
|
category?: string;
|
||
|
|
sampleData?: T;
|
||
|
|
attachments?: Array<{
|
||
|
|
name: string;
|
||
|
|
path: string;
|
||
|
|
contentType?: string;
|
||
|
|
}>;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Email template context - data used to render the template
|
||
|
|
*/
|
||
|
|
export interface ITemplateContext {
|
||
|
|
[key: string]: any;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Template category definitions
|
||
|
|
*/
|
||
|
|
export declare enum TemplateCategory {
|
||
|
|
NOTIFICATION = "notification",
|
||
|
|
TRANSACTIONAL = "transactional",
|
||
|
|
MARKETING = "marketing",
|
||
|
|
SYSTEM = "system"
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Enhanced template manager using Email class for template rendering
|
||
|
|
*/
|
||
|
|
export declare class TemplateManager {
|
||
|
|
private templates;
|
||
|
|
private defaultConfig;
|
||
|
|
constructor(defaultConfig?: {
|
||
|
|
from?: string;
|
||
|
|
replyTo?: string;
|
||
|
|
footerHtml?: string;
|
||
|
|
footerText?: string;
|
||
|
|
});
|
||
|
|
/**
|
||
|
|
* Register built-in email templates
|
||
|
|
*/
|
||
|
|
private registerBuiltinTemplates;
|
||
|
|
/**
|
||
|
|
* Register a new email template
|
||
|
|
* @param template The email template to register
|
||
|
|
*/
|
||
|
|
registerTemplate<T = any>(template: IEmailTemplate<T>): void;
|
||
|
|
/**
|
||
|
|
* Get an email template by ID
|
||
|
|
* @param templateId The template ID
|
||
|
|
* @returns The template or undefined if not found
|
||
|
|
*/
|
||
|
|
getTemplate<T = any>(templateId: string): IEmailTemplate<T> | undefined;
|
||
|
|
/**
|
||
|
|
* List all available templates
|
||
|
|
* @param category Optional category filter
|
||
|
|
* @returns Array of email templates
|
||
|
|
*/
|
||
|
|
listTemplates(category?: TemplateCategory): IEmailTemplate[];
|
||
|
|
/**
|
||
|
|
* Create an Email instance from a template
|
||
|
|
* @param templateId The template ID
|
||
|
|
* @param context The template context data
|
||
|
|
* @returns A configured Email instance
|
||
|
|
*/
|
||
|
|
createEmail<T = any>(templateId: string, context?: ITemplateContext): Promise<Email>;
|
||
|
|
/**
|
||
|
|
* Create and completely process an Email instance from a template
|
||
|
|
* @param templateId The template ID
|
||
|
|
* @param context The template context data
|
||
|
|
* @returns A complete, processed Email instance ready to send
|
||
|
|
*/
|
||
|
|
prepareEmail<T = any>(templateId: string, context?: ITemplateContext): Promise<Email>;
|
||
|
|
/**
|
||
|
|
* Create a MIME-formatted email from a template
|
||
|
|
* @param templateId The template ID
|
||
|
|
* @param context The template context data
|
||
|
|
* @returns A MIME-formatted email string
|
||
|
|
*/
|
||
|
|
createMimeEmail(templateId: string, context?: ITemplateContext): Promise<string>;
|
||
|
|
/**
|
||
|
|
* Load templates from a directory
|
||
|
|
* @param directory The directory containing template JSON files
|
||
|
|
*/
|
||
|
|
loadTemplatesFromDirectory(directory: string): Promise<void>;
|
||
|
|
}
|