@betterinternship/core 2.3.3 → 2.3.4

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,91 +1,67 @@
1
- import { TransactionalEmailsApi } from '@getbrevo/brevo';
2
- import * as nodemailer from 'nodemailer';
3
- import { ENV } from '../env.js';
4
- const SMTP_EMAIL = ENV.SMTP_EMAIL;
5
- const SMTP_PASSWORD = ENV.SMTP_PASSWORD;
6
- if (!SMTP_EMAIL || !SMTP_PASSWORD)
7
- throw Error('[ERROR:ENV]: Missing SMTP setup.');
8
- let transacApi = null;
9
- if (process.env.NODE_ENV !== 'development') {
10
- const BREVO_API_KEY = process.env.BREVO_API_KEY;
11
- if (!BREVO_API_KEY)
12
- throw Error('[ERROR:ENV]: Missing Brevo setup.');
13
- transacApi = new TransactionalEmailsApi();
14
- transacApi.setApiKey(0, BREVO_API_KEY);
15
- }
16
- const transporterConfig = {
17
- service: 'Gmail',
18
- host: 'smtp.gmail.com',
19
- port: 465,
20
- secure: true,
21
- };
22
- const transporters = {
23
- hello: nodemailer.createTransport({
24
- ...transporterConfig,
25
- auth: {
26
- user: 'hello@betterinternship.com',
27
- pass: SMTP_PASSWORD,
28
- },
29
- }),
30
- otp: nodemailer.createTransport({
31
- ...transporterConfig,
32
- auth: {
33
- user: 'otp@betterinternship.com',
34
- pass: SMTP_PASSWORD,
35
- },
36
- }),
37
- applications: nodemailer.createTransport({
38
- ...transporterConfig,
39
- auth: {
40
- user: 'applications@betterinternship.com',
41
- pass: SMTP_PASSWORD,
42
- },
43
- }),
44
- sign: nodemailer.createTransport({
45
- ...transporterConfig,
46
- auth: {
47
- user: 'sign@betterinternship.com',
48
- pass: SMTP_PASSWORD,
49
- },
50
- }),
51
- };
52
- export const sendSingleEmail = async ({ sender, subject, recipient, content, alias = 'hello', }) => {
53
- if (process.env.NODE_ENV === 'development' || true) {
54
- return new Promise((resolve, reject) => {
55
- transporters[alias].sendMail({
56
- from: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
57
- to: recipient,
58
- subject,
59
- html: content,
60
- }, (error, info) => {
61
- if (error) {
62
- console.error('[ERROR] Could not send email.');
63
- console.error('[-----] ' + error.message);
64
- }
65
- else {
66
- resolve({
67
- messageId: info.messageId,
68
- response: info.response,
69
- });
70
- console.warn('[LOG] Email sent to ' + recipient);
71
- }
72
- });
73
- });
74
- }
75
- else {
76
- const response = await transacApi?.sendTransacEmail({
77
- sender: {
78
- email: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
79
- },
80
- to: [{ email: recipient }],
81
- subject,
82
- htmlContent: content,
83
- });
84
- console.warn('[LOG] Email sent to ' + recipient);
85
- return {
86
- messageId: response?.body?.messageId,
87
- response: response?.response,
88
- };
89
- }
90
- };
1
+ import { TransactionalEmailsApi } from '@getbrevo/brevo';
2
+ import * as nodemailer from 'nodemailer';
3
+ import { v4 } from 'uuid';
4
+ import { ENV } from '../env.js';
5
+ const SMTP_EMAIL = ENV.SMTP_EMAIL;
6
+ const SMTP_PASSWORD = ENV.SMTP_PASSWORD;
7
+ if (!SMTP_EMAIL || !SMTP_PASSWORD)
8
+ throw Error('[ERROR:ENV]: Missing SMTP setup.');
9
+ let transacApi = null;
10
+ if (process.env.NODE_ENV !== 'development') {
11
+ const BREVO_API_KEY = process.env.BREVO_API_KEY;
12
+ if (!BREVO_API_KEY)
13
+ throw Error('[ERROR:ENV]: Missing Brevo setup.');
14
+ transacApi = new TransactionalEmailsApi();
15
+ transacApi.setApiKey(0, BREVO_API_KEY);
16
+ }
17
+ const transporter = nodemailer.createTransport({
18
+ service: 'Gmail',
19
+ host: 'smtp.gmail.com',
20
+ port: 465,
21
+ secure: true,
22
+ auth: {
23
+ user: SMTP_EMAIL,
24
+ pass: SMTP_PASSWORD,
25
+ },
26
+ messageId: `${v4()}${SMTP_EMAIL}`,
27
+ });
28
+ export const sendSingleEmail = async ({ sender, subject, recipient, content, alias = 'hello', }) => {
29
+ if (process.env.NODE_ENV === 'development' || true) {
30
+ return new Promise((resolve, reject) => {
31
+ transporter.sendMail({
32
+ from: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
33
+ to: recipient,
34
+ subject,
35
+ html: content,
36
+ }, (error, info) => {
37
+ if (error) {
38
+ console.error('[ERROR] Could not send email.');
39
+ console.error('[-----] ' + error.message);
40
+ }
41
+ else {
42
+ resolve({
43
+ messageId: info.messageId,
44
+ response: info.response,
45
+ });
46
+ console.warn('[LOG] Email sent to ' + recipient);
47
+ }
48
+ });
49
+ });
50
+ }
51
+ else {
52
+ const response = await transacApi?.sendTransacEmail({
53
+ sender: {
54
+ email: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
55
+ },
56
+ to: [{ email: recipient }],
57
+ subject,
58
+ htmlContent: content,
59
+ });
60
+ console.warn('[LOG] Email sent to ' + recipient);
61
+ return {
62
+ messageId: response?.body?.messageId,
63
+ response: response?.response,
64
+ };
65
+ }
66
+ };
91
67
  //# sourceMappingURL=email.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"email.js","sourceRoot":"","sources":["../../../lib/email/email.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;AAClC,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;AAExC,IAAI,CAAC,UAAU,IAAI,CAAC,aAAa;IAC/B,MAAM,KAAK,CAAC,kCAAkC,CAAC,CAAC;AAIlD,IAAI,UAAU,GAAkC,IAAI,CAAC;AACrD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;IAC3C,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAChD,IAAI,CAAC,aA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