Skip to content

Commit

Permalink
add isolated email templates and template builder
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 13, 2024
1 parent 2393fb1 commit 8e4b05e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { WELCOME_EMAIL_HTML_CONTENT } from '@api/modules/notifications/email/templates/welcome-email.template';
import { RESET_PASSWORD_HTML_CONTENT } from '@api/modules/notifications/email/templates/reset-password.template';
import { EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT } from '@api/modules/notifications/email/templates/email-update-confirmation.template';

export enum TEMPLATE_TYPE {
WELCOME = 'welcome',
RESET_PASSWORD = 'reset-password',
EMAIL_UPDATE_CONFIRMATION = 'email-update-confirmation',
}

export interface TemplateConfig {
url: string;
expiration: number;
type: TEMPLATE_TYPE;
}

export class EmailTemplateBuilder {
url: string;
expiration: number;
type: TEMPLATE_TYPE;
templateMap = {
WELCOME_EMAIL_HTML_CONTENT: WELCOME_EMAIL_HTML_CONTENT,
RESET_PASSWORD_HTML_CONTENT: RESET_PASSWORD_HTML_CONTENT,
EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT:
EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT,
};
constructor(contentConfig: TemplateConfig) {
this.url = contentConfig.url;
this.expiration = contentConfig.expiration;
this.type = contentConfig.type;
}

build() {
const template = this.templateMap[this.type];
return template(this.url, this.expiration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const EMAIL_UPDATE_CONFIRMATION_HTML_CONTENT = (
url,
expiration,
): string => `
<h1>Dear User,</h1>
<br/>
<p>We have received a request to change the email address associated with your account. If you initiated this request, please confirm the change by clicking the link below:</p>
<br/>
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Confirm Email Change</a></p>
<br/>
<p>This link will redirect you to our app to confirm the new email address. For security reasons, this link will expire in ${expiration}.</p>
<p>If you did not request this email change, please ignore this message; your account information will remain unchanged.</p>
<br/>
<p>Thank you for using our platform. We value your security and account privacy.</p>
<p>Best regards.</p>`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const RESET_PASSWORD_HTML_CONTENT = (
url: string,
expiration: number,
): string => `
<h1>Dear User,</h1>
<br/>
<p>We recently received a request to reset your password for your account. If you made this request, please click on the link below to securely change your password:</p>
<br/>
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Secure Password Reset Link</a></p>
<br/>
<p>This link will direct you to our app to create a new password. For security reasons, this link will expire after ${expiration}.</p>
<p>If you did not request a password reset, please ignore this email; your password will remain the same.</p>
<br/>
<p>Thank you for using the platform. We're committed to ensuring your account's security.</p>
<p>Best regards.</p>`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const WELCOME_EMAIL_HTML_CONTENT = (url, expiration): string => `
<h1>Dear User,</h1>
<br/>
<p>We recently received a request to reset your password for your account. If you made this request, please click on the link below to securely change your password:</p>
<br/>
<p><a href="${url}" target="_blank" rel="noopener noreferrer">Secure Password Reset Link</a></p>
<br/>
<p>This link will direct you to our app to create a new password. For security reasons, this link will expire after ${expiration}.</p>
<p>If you did not request a password reset, please ignore this email; your password will remain the same.</p>
<br/>
<p>Thank you for using the platform. We're committed to ensuring your account's security.</p>
<p>Best regards.</p>`;

0 comments on commit 8e4b05e

Please sign in to comment.