@duvdu-v1/duvdu 1.1.360 → 1.1.362
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
|
|
4
|
-
|
|
5
|
-
private
|
|
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.
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
+
return new resend_strategy_1.ResendStrategy();
|
|
70
75
|
default:
|
|
71
76
|
console.warn(`Unsupported mail driver: ${driver}. Mail sending might fail.`);
|
|
72
|
-
|
|
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
|
-
|
|
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
|
|
142
|
+
yield strategy.send({
|
|
137
143
|
to: options.to,
|
|
138
144
|
subject: options.subject,
|
|
139
145
|
html: html,
|
|
@@ -28,9 +28,9 @@ const userSchema = new mongoose_1.Schema({
|
|
|
28
28
|
isEmailVerified: { type: Boolean, default: false },
|
|
29
29
|
isPhoneNumberVerified: { type: Boolean, default: false },
|
|
30
30
|
verificationCode: new mongoose_1.Schema({
|
|
31
|
-
expireAt: { type: Date,
|
|
32
|
-
reason: { type: String,
|
|
33
|
-
code: { type: String,
|
|
31
|
+
expireAt: { type: Date, default: null },
|
|
32
|
+
reason: { type: String, default: null },
|
|
33
|
+
code: { type: String, default: null },
|
|
34
34
|
isVerified: { type: Boolean, default: false },
|
|
35
35
|
}, { timestamps: true }),
|
|
36
36
|
refreshTokens: [
|