From a99913c308fa981d548ccdf89932d32b2fc31385 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 18 May 2024 19:33:43 +0100 Subject: [PATCH] refactor(view): render view asynchronous --- package-lock.json | 4 ++-- package.json | 2 +- src/drivers/SmtpDriver.ts | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e4c17e..de609a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/mail", - "version": "4.20.0", + "version": "4.21.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/mail", - "version": "4.20.0", + "version": "4.21.0", "license": "MIT", "dependencies": { "nodemailer": "^6.9.13", diff --git a/package.json b/package.json index 66039db..bb01ead 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/mail", - "version": "4.20.0", + "version": "4.21.0", "description": "The Athenna email handler. Built on top of nodemailer.", "license": "MIT", "author": "Victor Tesoura JĂșnior ", diff --git a/src/drivers/SmtpDriver.ts b/src/drivers/SmtpDriver.ts index 17b231e..b3be5d2 100644 --- a/src/drivers/SmtpDriver.ts +++ b/src/drivers/SmtpDriver.ts @@ -49,6 +49,22 @@ export class SmtpDriver extends Driver { * Send a new mail message. */ public async send(): Promise { + if (this.message.text) { + this.message.text = await Promise.resolve(this.message.text) + } + + if (this.message.html) { + this.message.html = await Promise.resolve(this.message.html) + } + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + if (this.message.markdown) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + this.message.markdown = await Promise.resolve(this.message.markdown) + } + return this.transport.sendMail(this.message) } @@ -491,7 +507,7 @@ export class SmtpDriver extends Driver { public view(name: string, data: any = {}, options: ContentOptions = {}) { options = Options.create(options, { type: 'html' }) - this.message[options.type] = View.renderSync(name, { + this.message[options.type] = View.render(name, { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore content: this.message.text || this.message.html || this.message.markdown,