UNPKG

lbx-jwt

Version:

Provides JWT authentication for loopback applications. Includes storing roles inside tokens and handling refreshing. Built-in reuse detection.

154 lines (153 loc) 6.03 kB
import { Transporter } from 'nodemailer'; import { BaseDefaultStaticReplacements } from './base-default.replacements'; import { Email } from './email.model'; import { BaseUserWithRelations } from '../../models'; import { PasswordResetTokenWithRelations } from '../../models/password-reset-token.model'; /** * The directory for jwt mail templates (eg. For Password reset.). */ export declare const LBX_JWT_MAIL_TEMPLATE_DIRECTORY: string; /** * A service that handles sending emails to users. */ export declare abstract class BaseMailService<RoleType extends string, DefaultStaticReplacementsType extends BaseDefaultStaticReplacements = BaseDefaultStaticReplacements> { /** * The name of the mail address that sends any automated emails. */ protected abstract readonly WEBSERVER_MAIL: string; /** * The base link before '.../token' for resetting the users password. */ protected abstract readonly BASE_RESET_PASSWORD_LINK: string; /** * The path to the base email template. */ protected readonly BASE_MAIL_TEMPLATE_PATH: string; /** * The email transporter that sends all the emails. */ protected abstract readonly webserverMailTransporter: Transporter; /** * Whether or not this service is currently in production mode. * This is needed to determine if the email should be sent, or if the email content should be saved locally for testing purposes. */ protected abstract readonly PRODUCTION: boolean; /** * The path where emails should be saved to when this service is not in production mode. */ protected abstract readonly SAVED_EMAILS_PATH: string; /** * The url for the logo that is placed inside the header. */ protected readonly LOGO_HEADER_URL?: string; /** * The width of the logo placed inside the header. */ protected readonly LOGO_HEADER_WIDTH: number; /** * The url for the logo that is placed inside the footer. */ protected readonly LOGO_FOOTER_URL?: string; /** * The width of the logo placed inside the footer. */ protected readonly LOGO_FOOTER_WIDTH: number; /** * Lines of the address that is displayed inside the footer. */ protected abstract readonly ADDRESS_LINES: string[]; /** * The label for Password Reset. * @default 'Password Reset' */ protected readonly PASSWORD_RESET_LABEL: string; /** * A css color value for the address lines in the footer. */ protected readonly ADDRESS_LINES_COLOR: string; /** * A css color value for the background of emails. * @default 'whitesmoke' */ protected readonly BACKGROUND_COLOR: string; /** * A css color value for the background of the content box of the email. * @default 'white' */ protected readonly CONTENT_BACKGROUND_COLOR: string; /** * A css color value for any text elements. * @default '#363636' */ protected readonly TEXT_COLOR: string; /** * The default css font family value for text elements. * @default 'Arial, sans-serif' */ protected readonly DEFAULT_FONT_FAMILY: string; /** * A css color value for headline text elements. * @default '#363636' */ protected readonly HEADLINE_TEXT_COLOR: string; /** * The css for button elements. */ protected readonly BUTTON_CSS: string; /** * The css for button elements that are hovered. */ protected readonly BUTTON_HOVER_CSS: string; /** * Defines static replacements that are useful for multiple email templates. * * By default this contains: * - addressLine1 * - addressLine2 * - logoHeaderUrl * - logoFooterUrl. * * Does not contain the html title, as this is unique per template and also not required. */ protected get defaultStaticReplacements(): DefaultStaticReplacementsType; constructor(); /** * Sends an email for resetting the password of a specific user. * Contains a link that is active for a limited amount of time. * @param user - The user that should receive the email. * @param resetToken - The reset token needed to generate the link. */ sendResetPasswordMail(user: BaseUserWithRelations<RoleType>, resetToken: PasswordResetTokenWithRelations): Promise<void>; /** * Gets the content for the reset password email. * @param resetToken - The reset token needed for resetting the password. * @param user - The user that tries to reset his password. * @returns The finished html string that will be inserted inside the base template. */ protected getResetPasswordContent(resetToken: PasswordResetTokenWithRelations, user: BaseUserWithRelations<RoleType>): string; /** * Defines what to do with the email. * In a production environment this sends the email to the recipients. * In a non production environment this saves the email data in a file for testing purposes. * @param email - The email that should be handled. */ protected handleEmail(email: Email): Promise<void>; /** * Gets the first line for the email based on the user the mail is sent to. * This can be used to address the user correctly. * @param user - The user that should receive the email. * @returns The string that should be the first line inside the email. */ /** * Gets the first line to use in an email (eg. "Dear Mr. X") based on the user that the email is sent to. * @param user - The user that the email is sent to. * @returns A string, most likely some sort of greeting. */ protected getFirstLineForUser(user: BaseUserWithRelations<RoleType>): string; /** * Gets the handlebars html template from the given path. * @param path - The path of the template. * @returns The compiled handlebars template. */ protected getTemplate(path: string): HandlebarsTemplateDelegate<unknown>; }