@webda/core
Version:
Expose API with Lambda
166 lines (165 loc) • 3.94 kB
TypeScript
import { Counter, Ident, User } from "../index.js";
import { NotificationService } from "./notificationservice.js";
import { Service, ServiceParameters } from "./service.js";
interface IEmailTemplate {
renderAll(file: string, options: any): any;
}
interface TemplatesMap {
[key: string]: IEmailTemplate;
}
/**
* Represent a mailer service
*/
export interface MailerService extends NotificationService {
/**
*
* @params options Options to pass to the sendMail option of the nodemailer module
* @params callback to pass to the sendMail
*/
send(options: MailerSendOptions, callback: () => void): Promise<any>;
}
interface MailerSendOptions {
/**
* Sender of the email
*
* @default parameters.sender
*/
from?: string;
/**
* Destination of the email
*/
to: string;
/**
* Template to user
*/
template?: string;
/**
* Replacements for the template
*/
replacements?: any;
/**
* Subject of the email
*
* Can be overriden by the template
*/
subject?: string;
/**
* HTML of the email
*
* Can be overriden by the template
*/
html?: string;
/**
* Text of the email
*
* Can be overriden by the template
*/
text?: string;
}
export declare class MailerParameters extends ServiceParameters {
/**
* Specify which foldeer contains templates
*
* @default "templates"
*/
templates?: string;
/**
* Template engine to usee
*
* @default "mustache"
*/
templatesEngine?: string;
/**
* Define the default sender
*/
sender: string;
/**
* @see https://www.npmjs.com/package/email-templates
*/
emailTemplateOptions?: any;
/**
* Define the type of transport to use
*/
transport?: string;
/**
* SES AWS Bean if transport === "ses"
*/
SES: any;
constructor(params: any);
}
export declare abstract class AbstractMailer<T extends ServiceParameters = ServiceParameters> extends Service<T> implements MailerService {
metrics: {
sent: Counter;
errors: Counter;
};
/**
* @override
*/
initMetrics(): void;
/**
* @inheritdoc
*/
abstract send(options: MailerSendOptions, callback?: () => void): Promise<any>;
/**
* @inheritdoc
*/
abstract hasNotification(notification: string): any;
/**
* If user has an email
* @param user
* @returns
*/
handleNotificationFor(user: User | Ident): Promise<boolean>;
/**
* @override
*/
sendNotification(user: User | Ident, notification: string, replacements: any): Promise<void>;
}
/**
* A basic Mailer based on the nodemailer module
*
* Inside config it is the nodemailer module option for the method createTransport ( https://nodemailer.com/ )
*
* Only ses transport module is installed by default
*
* Parameters
* config: { ... }
* @category CoreServices
* @WebdaModda
*/
declare class Mailer<T extends MailerParameters = MailerParameters> extends AbstractMailer<T> {
_transporter: any;
_templates: TemplatesMap;
/**
* Load parameters
*
* @param params
* @ignore
*/
loadParameters(params: any): ServiceParameters;
/**
* Compute parameters
*/
init(): Promise<this>;
/**
* Get a template by name
*
* @param name
* @returns
*/
_getTemplate(name: string): IEmailTemplate;
/**
* Check if the email template exists
*
* @param name
* @returns
*/
hasNotification(name: string): boolean;
/**
*
* @params options Options to pass to the sendMail option of the nodemailer module
* @params callback to pass to the sendMail
*/
send(options: MailerSendOptions, callback?: any): Promise<any>;
}
export { Mailer, TemplatesMap, IEmailTemplate };