@loomcore/api 0.1.127 → 0.1.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  import { IEmailClient } from "../models/email-client.interface.js";
2
2
  export declare class TestEmailClient implements IEmailClient {
3
- sendHtmlEmail(toEmailAddress: string, subject: string, body: string): Promise<void>;
3
+ sendResetPasswordEmail(toEmailAddress: string, resetPasswordLink: string): Promise<void>;
4
4
  }
@@ -1,6 +1,6 @@
1
1
  export class TestEmailClient {
2
- sendHtmlEmail(toEmailAddress, subject, body) {
3
- console.log(`Sending email to ${toEmailAddress} with subject ${subject} and body ${body}`);
2
+ sendResetPasswordEmail(toEmailAddress, resetPasswordLink) {
3
+ console.log(`Sending reset password email to ${toEmailAddress} with reset password link ${resetPasswordLink}`);
4
4
  return Promise.resolve();
5
5
  }
6
6
  }
@@ -1,3 +1,3 @@
1
1
  export interface IEmailClient {
2
- sendHtmlEmail(toEmailAddress: string, subject: string, body: string): Promise<void>;
2
+ sendResetPasswordEmail(toEmailAddress: string, resetPasswordLink: string): Promise<void>;
3
3
  }
@@ -202,8 +202,7 @@ export class AuthService extends MultiTenantApiService {
202
202
  const httpOrHttps = config.env === 'local' ? 'http' : 'https';
203
203
  const urlEncodedEmail = encodeURIComponent(emailAddress);
204
204
  const resetPasswordLink = `${httpOrHttps}://${config.app.name}/reset-password/${passwordResetToken.token}/${urlEncodedEmail}`;
205
- const htmlEmailBody = `<strong><a href="${resetPasswordLink}">Reset Password</a></strong>`;
206
- await this.emailService.sendHtmlEmail(emailAddress, `Reset Password for ${config.app.name}`, htmlEmailBody);
205
+ await this.emailService.sendResetPasswordEmail(emailAddress, resetPasswordLink);
207
206
  }
208
207
  async resetPassword(email, passwordResetToken, password) {
209
208
  const lowerCaseEmail = email.toLowerCase();
@@ -1,6 +1,5 @@
1
1
  export declare class EmailService {
2
- private emailConfig;
3
2
  private emailClient;
4
3
  constructor();
5
- sendHtmlEmail(emailAddress: string, subject: string, body: string): Promise<void>;
4
+ sendResetPasswordEmail(emailAddress: string, resetPasswordLink: string): Promise<void>;
6
5
  }
@@ -1,15 +1,8 @@
1
1
  import { ServerError } from '../errors/index.js';
2
2
  import { config } from '../config/index.js';
3
3
  export class EmailService {
4
- emailConfig;
5
4
  emailClient;
6
5
  constructor() {
7
- if (config.email) {
8
- this.emailConfig = config.email;
9
- }
10
- else {
11
- throw new ServerError('Email configuration is not available. Email API credentials are not set in the config.');
12
- }
13
6
  if (config.thirdPartyClients?.emailClient) {
14
7
  this.emailClient = config.thirdPartyClients.emailClient;
15
8
  }
@@ -17,31 +10,14 @@ export class EmailService {
17
10
  throw new ServerError('Email client is not available. Email client is not set in the config.');
18
11
  }
19
12
  }
20
- async sendHtmlEmail(emailAddress, subject, body) {
21
- const messageData = {
22
- Messages: [
23
- {
24
- From: {
25
- Email: this.emailConfig.fromAddress,
26
- Name: config.app.name
27
- },
28
- To: [
29
- {
30
- Email: emailAddress
31
- }
32
- ],
33
- Subject: subject,
34
- HTMLPart: body
35
- }
36
- ]
37
- };
13
+ async sendResetPasswordEmail(emailAddress, resetPasswordLink) {
38
14
  try {
39
- await this.emailClient.sendHtmlEmail(emailAddress, subject, body);
40
- console.log(`Email sent to ${emailAddress} with subject ${subject}`);
15
+ await this.emailClient.sendResetPasswordEmail(emailAddress, resetPasswordLink);
16
+ console.log(`Reset password email sent to ${emailAddress} with reset password link ${resetPasswordLink}`);
41
17
  }
42
18
  catch (error) {
43
- console.error('Error sending email:', error);
44
- throw new ServerError('Error sending email');
19
+ console.error('Error sending reset password email:', error);
20
+ throw new ServerError('Error sending reset password email');
45
21
  }
46
22
  }
47
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.127",
3
+ "version": "0.1.128",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {