UNPKG

@zingersystems/parse-server-api-mail-adapter

Version:

Universal Mail Adapter for Parse Server, supports any email provider REST API, with localization and templates - both built-in and external.

177 lines 7.39 kB
export = ApiMailAdapter; /** * @class ApiMailAdapter * @description An email adapter for Parse Server to send emails via mail provider APIs. */ declare class ApiMailAdapter extends MailAdapter { /** * Creates a new mail adapter. * @param {Object} options The configuration options. */ constructor(options: any); external: any; sender: any; verificationEmail: any; passwordResetEmail: any; templates: any; apiCallback: any; /** * @function sendPasswordResetEmail * @description Sends a password reset email. * @param {String} link The password reset link. * @param {String} appName The app name. * @param {String} user The Parse User. * @returns {Promise<Any>} The mail provider API response. */ sendPasswordResetEmail({ link, appName, user }: string): Promise<Any>; /** * @function sendVerificationEmail * @description Sends a verification email. * @param {String} link The email verification link. * @param {String} appName The app name. * @param {String} user The Parse User. * @returns {Promise<Any>} The mail provider API response. */ sendVerificationEmail({ link, appName, user }: string): Promise<Any>; /** * @function sendMail * @description Sends an email. * @param {String} [sender] The email from address. * @param {String} recipient The email recipient; if set overrides the email address of the `user`. * @param {String} [subject] The email subject. * @param {String} [text] The plain-text email content. * @param {String} [html] The HTML email content. * @param {String} [templateName] The template name or Id. * @param {Object} [placeholders] The template placeholders. * @param {Object} [extra] Any additional variables to pass to the mail provider API. * @param {Parse.User} [user] The Parse User that the is the recipient of the email. * @returns {Promise<Any>} The mail provider API response. */ sendMail({ sender, recipient, subject, text, html, templateName, placeholders, extra, user }?: string): Promise<Any>; /** * @function _sendMail * @description Sends an email. * @param {Object} email The email to send. * @returns {Promise} The mail provider API response. */ _sendMail(email: any): Promise<any>; /** * @typedef {Object} CreateApiDataResponse * @property {Object} payload The generic API payload. * @property {String} payload.from The sender email address. * @property {String} payload.to The recipient email address. * @property {String} payload.replyTo The reply-to address. * @property {String} payload.subject The subject. * @property {String} payload.text The plain-text content. * @property {String} payload.html The HTML content. * @property {String} payload.message The MIME content. * @property {String} [locale] The user locale, if it has been determined via the * locale callback. */ /** * @function _createApiData * @description Creates the API data, includes the payload and optional meta data. * @param {Object} options The payload options. * @param {Object} options.message The message to send. * @param {Object} options.template The email template to use. * @param {Object} [options.placeholders] The email template placeholders. * @param {Object} [options.user] The Parse User who is the email recipient. * @returns {Promise<CreateApiDataResponse>} The API data. */ _createApiData(options: { message: any; template: any; placeholders?: any; user?: any; }): Promise<{ /** * The generic API payload. */ payload: { from: string; to: string; replyTo: string; subject: string; text: string; html: string; message: string; }; /** * The user locale, if it has been determined via the * locale callback. */ locale?: string; }>; /** * @function _loadFile * @description Loads a file's content. * @param {String} path The file path. * @param {String} locale The locale if a localized version of the file should be * loaded if available, or `undefined` if no localization should occur. * @returns {Promise<Buffer>} The file content. */ _loadFile(path: string, locale: string): Promise<Buffer>; /** * @function _fillPlaceholders * @description Substitutes placeholders in a template with their values. * @param {String} template The template with placeholders, e.g. {{placeholder}}. * @param {Object} placeholders A map of placeholder keys with values. * @returns {String} The template with filled in placeholders. */ _fillPlaceholders(template: string, placeholders: any): string; /** * @function _validateTemplate * @description Validates a template. * @param {Object} template The template to validate. * @returns {} */ _validateTemplate(template: any): any; /** * @function _validatePlaceholders * @description Validates the template placeholders. * @param {Object} placeholders The template placeholders. * @returns {Object} The validated (cleaned) placeholders. */ _validatePlaceholders(placeholders: any): any; /** * @function _validateUserLocale * @description Validates the user locale callback result. * @param {String} locale The user locale. * @returns {String|undefined} Returns the locale or undefined if the locale is invalid. */ _validateUserLocale(locale: string): string | undefined; /** * @function getLocalizedFilePath * @description Returns a localized file path matching a given locale. * * Localized files are placed in sub-folders of the given path, for example: * * root/ * ├── base/ // base path to files * │ ├── example.html // default file * │ └── de/ // de language folder * │ │ └── example.html // de localized file * │ └── de-AT/ // de-AT locale folder * │ │ └── example.html // de-AT localized file * * Files are matched with the user locale in the following order: * 1. Locale match, e.g. locale `de-AT` matches file in folder `de-AT`. * 2. Language match, e.g. locale `de-AT` matches file in folder `de`. * 3. Default match: file in base folder is returned. * * @param {String} filePath The file path. * @param {String} locale The locale to match. * @returns {Promise<String>} The localized file path, or the original file path * if a localized file could not be determined. */ _getLocalizedFilePath(filePath: string, locale: string): Promise<string>; /** * @function fileExists * @description Checks whether a file exists. * @param {String} path The file path. * @returns {Promise<Boolean>} Is true if the file can be accessed, false otherwise. */ _fileExists(path: string): Promise<boolean>; } import MailAdapter = require("./MailAdapter"); //# sourceMappingURL=ApiMailAdapter.d.ts.map