@duvdu-v1/duvdu 1.1.360 → 1.1.361

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,8 +1,9 @@
1
1
  import type { EmailJobData, EmailTemplate } from './mailer.interface';
2
2
  declare class MailerServiceClass {
3
- private strategy;
4
- constructor();
5
- private setStrategy;
3
+ private _strategy;
4
+ private strategyInitialized;
5
+ private get strategy();
6
+ private buildStrategy;
6
7
  private renderTemplate;
7
8
  sendMail<T extends EmailTemplate>(options: EmailJobData<T>): Promise<void>;
8
9
  }
@@ -50,26 +50,31 @@ const resend_strategy_1 = require("./strategies/resend.strategy");
50
50
  const smtp_strategy_1 = require("./strategies/smtp.strategy");
51
51
  class MailerServiceClass {
52
52
  constructor() {
53
- this.strategy = null;
54
- if (process.env.SEND_MAIL) {
55
- this.setStrategy();
53
+ this._strategy = null;
54
+ this.strategyInitialized = false;
55
+ }
56
+ get strategy() {
57
+ if (!this.strategyInitialized) {
58
+ this.strategyInitialized = true;
59
+ this._strategy = this.buildStrategy();
56
60
  }
61
+ return this._strategy;
57
62
  }
58
- setStrategy() {
63
+ buildStrategy() {
64
+ if (!process.env.SEND_MAIL)
65
+ return null;
59
66
  const driver = process.env.MAIL_DRIVER;
60
67
  /* eslint-disable indent */
61
68
  switch (driver) {
62
69
  case 'smtp':
63
- this.strategy = new smtp_strategy_1.SmtpStrategy();
64
70
  console.log('Mailer strategy set to SMTP');
65
- break;
71
+ return new smtp_strategy_1.SmtpStrategy();
66
72
  case 'resend':
67
- this.strategy = new resend_strategy_1.ResendStrategy();
68
73
  console.log('Mailer strategy set to Resend');
69
- break;
74
+ return new resend_strategy_1.ResendStrategy();
70
75
  default:
71
76
  console.warn(`Unsupported mail driver: ${driver}. Mail sending might fail.`);
72
- this.strategy = null;
77
+ return null;
73
78
  /* eslint-enable indent */
74
79
  }
75
80
  }
@@ -115,7 +120,8 @@ class MailerServiceClass {
115
120
  console.log(`Dry run: Sending mail to ${options.to} with subject ${options.subject}`);
116
121
  return;
117
122
  }
118
- if (!this.strategy) {
123
+ const strategy = this.strategy;
124
+ if (!strategy) {
119
125
  console.error('No mailer strategy configured.');
120
126
  return;
121
127
  }
@@ -133,7 +139,7 @@ class MailerServiceClass {
133
139
  html = options.body.includes('<') ? options.body : `<p>${options.body}</p>`;
134
140
  }
135
141
  try {
136
- yield this.strategy.send({
142
+ yield strategy.send({
137
143
  to: options.to,
138
144
  subject: options.subject,
139
145
  html: html,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.360",
3
+ "version": "1.1.361",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [