@lenne.tech/nest-server 10.2.10 → 10.2.11
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.11",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
import { Injectable } from '@nestjs/common';
|
|
3
2
|
|
|
4
3
|
import { ConfigService } from './config.service';
|
|
5
4
|
|
|
6
5
|
import brevo = require('@getbrevo/brevo');
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Brevo service to send transactional emails
|
|
9
|
+
*/
|
|
9
10
|
@Injectable()
|
|
10
11
|
export class BrevoService {
|
|
11
12
|
brevoConfig: ConfigService['configFastButReadOnly']['brevo'];
|
|
@@ -24,25 +25,26 @@ export class BrevoService {
|
|
|
24
25
|
* Send a transactional email via Brevo
|
|
25
26
|
*/
|
|
26
27
|
async sendMail(to: string, templateId: number, params?: object): Promise<unknown> {
|
|
27
|
-
// Check input
|
|
28
|
-
if (!to || !templateId) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Exclude (test) users
|
|
33
|
-
if (this.configService.configFastButReadOnly.brevo?.exclude?.test(to)) {
|
|
34
|
-
return 'TEST_USER!';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Prepare data
|
|
38
|
-
const apiInstance = new brevo.TransactionalEmailsApi();
|
|
39
|
-
const sendSmtpEmail = new brevo.SendSmtpEmail();
|
|
40
|
-
sendSmtpEmail.templateId = templateId;
|
|
41
|
-
sendSmtpEmail.to = [{ email: to }];
|
|
42
|
-
sendSmtpEmail.params = params;
|
|
43
|
-
|
|
44
|
-
// Send email
|
|
45
28
|
try {
|
|
29
|
+
// Check input
|
|
30
|
+
if (!to || !templateId) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Exclude (test) users, must be done via config and not via configFastButReadOnly,
|
|
35
|
+
// otherwise the error TypeError: Cannot assign to read only property 'lastIndex' of object '[object RegExp]' occurs
|
|
36
|
+
if (this.configService.config?.brevo?.exclude?.test?.(to)) {
|
|
37
|
+
return 'TEST_USER!';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Prepare data
|
|
41
|
+
const apiInstance = new brevo.TransactionalEmailsApi();
|
|
42
|
+
const sendSmtpEmail = new brevo.SendSmtpEmail();
|
|
43
|
+
sendSmtpEmail.templateId = templateId;
|
|
44
|
+
sendSmtpEmail.to = [{ email: to }];
|
|
45
|
+
sendSmtpEmail.params = params;
|
|
46
|
+
|
|
47
|
+
// Send email
|
|
46
48
|
return await apiInstance.sendTransacEmail(sendSmtpEmail);
|
|
47
49
|
} catch (error) {
|
|
48
50
|
console.error(error);
|
|
@@ -61,27 +63,28 @@ export class BrevoService {
|
|
|
61
63
|
html: string,
|
|
62
64
|
options?: { params?: Record<string, string> },
|
|
63
65
|
): Promise<unknown> {
|
|
64
|
-
// Check input
|
|
65
|
-
if (!to || !subject || !html) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Exclude (test) users
|
|
70
|
-
if (this.brevoConfig.exclude?.test(to)) {
|
|
71
|
-
return 'TEST_USER!';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Prepare data
|
|
75
|
-
const apiInstance = new brevo.TransactionalEmailsApi();
|
|
76
|
-
const sendSmtpEmail = new brevo.SendSmtpEmail();
|
|
77
|
-
sendSmtpEmail.htmlContent = html;
|
|
78
|
-
sendSmtpEmail.params = options?.params;
|
|
79
|
-
sendSmtpEmail.sender = this.brevoConfig.sender;
|
|
80
|
-
sendSmtpEmail.subject = subject;
|
|
81
|
-
sendSmtpEmail.to = [{ email: to }];
|
|
82
|
-
|
|
83
|
-
// Send email
|
|
84
66
|
try {
|
|
67
|
+
// Check input
|
|
68
|
+
if (!to || !subject || !html) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Exclude (test) users, must be done via config and not via configFastButReadOnly,
|
|
73
|
+
// otherwise the error TypeError: Cannot assign to read only property 'lastIndex' of object '[object RegExp]' occurs
|
|
74
|
+
if (this.configService.config?.brevo?.exclude?.test?.(to)) {
|
|
75
|
+
return 'TEST_USER!';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Prepare data
|
|
79
|
+
const apiInstance = new brevo.TransactionalEmailsApi();
|
|
80
|
+
const sendSmtpEmail = new brevo.SendSmtpEmail();
|
|
81
|
+
sendSmtpEmail.htmlContent = html;
|
|
82
|
+
sendSmtpEmail.params = options?.params;
|
|
83
|
+
sendSmtpEmail.sender = this.brevoConfig.sender;
|
|
84
|
+
sendSmtpEmail.subject = subject;
|
|
85
|
+
sendSmtpEmail.to = [{ email: to }];
|
|
86
|
+
|
|
87
|
+
// Send email
|
|
85
88
|
return await apiInstance.sendTransacEmail(sendSmtpEmail);
|
|
86
89
|
} catch (error) {
|
|
87
90
|
console.error(error);
|