@studiosonrai/nestjs-email 1.1.0 → 1.2.0
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/README.md +2 -26
- package/dist/src/email.module.js +0 -7
- package/dist/src/email.module.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces/email.interfaces.d.ts +1 -5
- package/dist/src/providers/index.d.ts +0 -1
- package/dist/src/providers/index.js +0 -1
- package/dist/src/providers/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -7
- package/dist/src/providers/resend.provider.d.ts +0 -17
- package/dist/src/providers/resend.provider.js +0 -178
- package/dist/src/providers/resend.provider.js.map +0 -1
- package/dist/src/providers/resend.provider.spec.d.ts +0 -1
- package/dist/src/providers/resend.provider.spec.js +0 -108
- package/dist/src/providers/resend.provider.spec.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studiosonrai/nestjs-email",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Email module for NestJS applications with Azure Communication Service
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Email module for NestJS applications with Azure Communication Service and SMTP support",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"test": "jest",
|
|
15
15
|
"test:smtp": "jest smtp.provider.spec.ts",
|
|
16
16
|
"test:azure": "jest azure.provider.spec.ts",
|
|
17
|
-
"test:resend": "jest resend.provider.spec.ts",
|
|
18
17
|
"test:watch": "jest --watch",
|
|
19
18
|
"test:coverage": "jest --coverage"
|
|
20
19
|
},
|
|
@@ -23,8 +22,7 @@
|
|
|
23
22
|
"email",
|
|
24
23
|
"azure-communication-service",
|
|
25
24
|
"smtp",
|
|
26
|
-
"nodemailer"
|
|
27
|
-
"resend"
|
|
25
|
+
"nodemailer"
|
|
28
26
|
],
|
|
29
27
|
"author": "",
|
|
30
28
|
"license": "UNLICENSED",
|
|
@@ -36,7 +34,6 @@
|
|
|
36
34
|
"optionalDependencies": {
|
|
37
35
|
"@azure/communication-email": "^1.0.0",
|
|
38
36
|
"nodemailer": "^7.0.0",
|
|
39
|
-
"resend": "^4.0.0",
|
|
40
37
|
"sharp": "^0.34.0"
|
|
41
38
|
},
|
|
42
39
|
"dependencies": {},
|
|
@@ -51,7 +48,6 @@
|
|
|
51
48
|
"jest": "^29.7.0",
|
|
52
49
|
"nodemailer": "^7.0.10",
|
|
53
50
|
"reflect-metadata": "^0.2.2",
|
|
54
|
-
"resend": "^4.0.0",
|
|
55
51
|
"rxjs": "^7.8.1",
|
|
56
52
|
"sharp": "^0.34.4",
|
|
57
53
|
"ts-jest": "^29.2.0",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { EmailProvider, SendEmailOptions, SendEmailResult, ResendEmailConfig, ImageCompressionOptions } from '../interfaces/email.interfaces';
|
|
2
|
-
export declare class ResendEmailProvider implements EmailProvider {
|
|
3
|
-
private resendClient;
|
|
4
|
-
private ready;
|
|
5
|
-
private defaultFrom?;
|
|
6
|
-
private imageCompression?;
|
|
7
|
-
private verbose;
|
|
8
|
-
constructor(config: ResendEmailConfig, options?: {
|
|
9
|
-
defaultFrom?: string;
|
|
10
|
-
imageCompression?: ImageCompressionOptions;
|
|
11
|
-
verbose?: boolean;
|
|
12
|
-
});
|
|
13
|
-
private initializeClient;
|
|
14
|
-
private compressAttachment;
|
|
15
|
-
sendEmail(options: SendEmailOptions): Promise<SendEmailResult>;
|
|
16
|
-
isReady(): boolean;
|
|
17
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ResendEmailProvider = void 0;
|
|
37
|
-
class ResendEmailProvider {
|
|
38
|
-
resendClient;
|
|
39
|
-
ready = false;
|
|
40
|
-
defaultFrom;
|
|
41
|
-
imageCompression;
|
|
42
|
-
verbose;
|
|
43
|
-
constructor(config, options) {
|
|
44
|
-
this.defaultFrom = options?.defaultFrom;
|
|
45
|
-
this.imageCompression = options?.imageCompression;
|
|
46
|
-
this.verbose = options?.verbose ?? false;
|
|
47
|
-
this.initializeClient(config.apiKey);
|
|
48
|
-
}
|
|
49
|
-
async initializeClient(apiKey) {
|
|
50
|
-
try {
|
|
51
|
-
const { Resend } = await Promise.resolve().then(() => __importStar(require('resend')));
|
|
52
|
-
this.resendClient = new Resend(apiKey);
|
|
53
|
-
this.ready = true;
|
|
54
|
-
if (this.verbose) {
|
|
55
|
-
console.log('[EmailModule] Resend provider initialized');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error('[EmailModule] Failed to initialize Resend provider:', error);
|
|
60
|
-
throw new Error('Failed to initialize Resend provider. Make sure resend is installed.');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async compressAttachment(attachment) {
|
|
64
|
-
if (!this.imageCompression?.enabled) {
|
|
65
|
-
return attachment;
|
|
66
|
-
}
|
|
67
|
-
if (!attachment.contentType?.startsWith('image/')) {
|
|
68
|
-
return attachment;
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
const sharp = (await Promise.resolve().then(() => __importStar(require('sharp')))).default;
|
|
72
|
-
const buffer = attachment.content instanceof Buffer
|
|
73
|
-
? attachment.content
|
|
74
|
-
: Buffer.from(attachment.content, 'base64');
|
|
75
|
-
const compressedBuffer = await sharp(buffer)
|
|
76
|
-
.resize({
|
|
77
|
-
width: this.imageCompression.maxWidth ?? 1200,
|
|
78
|
-
withoutEnlargement: true,
|
|
79
|
-
})
|
|
80
|
-
.jpeg({ quality: this.imageCompression.quality ?? 75 })
|
|
81
|
-
.toBuffer();
|
|
82
|
-
return {
|
|
83
|
-
...attachment,
|
|
84
|
-
content: compressedBuffer,
|
|
85
|
-
contentType: 'image/jpeg',
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (this.verbose) {
|
|
90
|
-
console.warn(`[EmailModule] Failed to compress ${attachment.filename}, sending original.`);
|
|
91
|
-
}
|
|
92
|
-
return attachment;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async sendEmail(options) {
|
|
96
|
-
if (!this.resendClient) {
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
error: new Error('Resend client not initialized'),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
let processedAttachments = [];
|
|
104
|
-
if (options.attachments?.length) {
|
|
105
|
-
processedAttachments = await Promise.all(options.attachments.map((att) => this.compressAttachment(att)));
|
|
106
|
-
}
|
|
107
|
-
if (processedAttachments.length > 0) {
|
|
108
|
-
const totalSize = processedAttachments.reduce((acc, att) => {
|
|
109
|
-
const size = att.content instanceof Buffer
|
|
110
|
-
? att.content.length
|
|
111
|
-
: Buffer.byteLength(att.content, 'base64');
|
|
112
|
-
return acc + size;
|
|
113
|
-
}, 0);
|
|
114
|
-
if (totalSize > 40 * 1024 * 1024) {
|
|
115
|
-
return {
|
|
116
|
-
success: false,
|
|
117
|
-
error: new Error('Attachments exceed Resend 40MB email size limit'),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const emailOptions = {
|
|
122
|
-
from: options.from ?? this.defaultFrom,
|
|
123
|
-
to: Array.isArray(options.to) ? options.to : [options.to],
|
|
124
|
-
subject: options.subject,
|
|
125
|
-
};
|
|
126
|
-
if (options.html) {
|
|
127
|
-
emailOptions.html = options.html;
|
|
128
|
-
}
|
|
129
|
-
if (options.text) {
|
|
130
|
-
emailOptions.text = options.text;
|
|
131
|
-
}
|
|
132
|
-
if (options.cc) {
|
|
133
|
-
emailOptions.cc = Array.isArray(options.cc) ? options.cc : [options.cc];
|
|
134
|
-
}
|
|
135
|
-
if (options.bcc) {
|
|
136
|
-
emailOptions.bcc = Array.isArray(options.bcc) ? options.bcc : [options.bcc];
|
|
137
|
-
}
|
|
138
|
-
if (options.replyTo) {
|
|
139
|
-
emailOptions.replyTo = options.replyTo;
|
|
140
|
-
}
|
|
141
|
-
if (processedAttachments.length > 0) {
|
|
142
|
-
emailOptions.attachments = processedAttachments.map((att) => ({
|
|
143
|
-
filename: att.filename,
|
|
144
|
-
content: att.content instanceof Buffer
|
|
145
|
-
? att.content
|
|
146
|
-
: Buffer.from(att.content, 'base64'),
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
const { data, error } = await this.resendClient.emails.send(emailOptions);
|
|
150
|
-
if (error) {
|
|
151
|
-
console.error('[EmailModule] Resend send error:', error);
|
|
152
|
-
return {
|
|
153
|
-
success: false,
|
|
154
|
-
error: new Error(error.message || 'Resend send failed'),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (this.verbose) {
|
|
158
|
-
console.log(`[EmailModule] Email sent successfully via Resend to ${options.to}`);
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
success: true,
|
|
162
|
-
messageId: data?.id,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
console.error('[EmailModule] Resend send error:', error);
|
|
167
|
-
return {
|
|
168
|
-
success: false,
|
|
169
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
isReady() {
|
|
174
|
-
return this.ready;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.ResendEmailProvider = ResendEmailProvider;
|
|
178
|
-
//# sourceMappingURL=resend.provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resend.provider.js","sourceRoot":"","sources":["../../../src/providers/resend.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAa,mBAAmB;IACtB,YAAY,CAAM;IAClB,KAAK,GAAG,KAAK,CAAC;IACd,WAAW,CAAU;IACrB,gBAAgB,CAA2B;IAC3C,OAAO,CAAU;IAEzB,YACE,MAAyB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E,CAAC,CAAC;YACnF,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,IAAI,EAAE,EAAE;aACpB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;YACzD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACjE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhMD,kDAgMC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const resend_provider_1 = require("./resend.provider");
|
|
4
|
-
describe('ResendEmailProvider Integration', () => {
|
|
5
|
-
let provider;
|
|
6
|
-
const config = {
|
|
7
|
-
apiKey: process.env.RESEND_API_KEY || '',
|
|
8
|
-
};
|
|
9
|
-
const defaultFrom = process.env.RESEND_FROM || 'testsender@resend.dev';
|
|
10
|
-
const testRecipient = process.env.TEST_EMAIL_TO || 'testreceiver@resend.dev';
|
|
11
|
-
const rateLimitDelay = () => new Promise((resolve) => setTimeout(resolve, 600));
|
|
12
|
-
beforeAll(async () => {
|
|
13
|
-
if (!config.apiKey) {
|
|
14
|
-
throw new Error('Resend API key is required (RESEND_API_KEY)');
|
|
15
|
-
}
|
|
16
|
-
if (!defaultFrom) {
|
|
17
|
-
throw new Error('Resend sender address is required (RESEND_FROM)');
|
|
18
|
-
}
|
|
19
|
-
provider = new resend_provider_1.ResendEmailProvider(config, {
|
|
20
|
-
defaultFrom,
|
|
21
|
-
verbose: true,
|
|
22
|
-
});
|
|
23
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
24
|
-
});
|
|
25
|
-
afterEach(async () => {
|
|
26
|
-
await rateLimitDelay();
|
|
27
|
-
});
|
|
28
|
-
it('should initialize successfully', () => {
|
|
29
|
-
expect(provider.isReady()).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
it('should send a simple email', async () => {
|
|
32
|
-
const result = await provider.sendEmail({
|
|
33
|
-
to: testRecipient,
|
|
34
|
-
subject: `[Resend Test] Simple Email - ${new Date().toISOString()}`,
|
|
35
|
-
html: '<h1>Test Email</h1><p>This is a test email sent via Resend.</p>',
|
|
36
|
-
text: 'Test Email\n\nThis is a test email sent via Resend.',
|
|
37
|
-
});
|
|
38
|
-
expect(result.success).toBe(true);
|
|
39
|
-
expect(result.messageId).toBeDefined();
|
|
40
|
-
console.log('Message ID:', result.messageId);
|
|
41
|
-
});
|
|
42
|
-
it('should send email with custom from address', async () => {
|
|
43
|
-
const result = await provider.sendEmail({
|
|
44
|
-
to: testRecipient,
|
|
45
|
-
from: defaultFrom,
|
|
46
|
-
subject: `[Resend Test] Custom From - ${new Date().toISOString()}`,
|
|
47
|
-
html: '<p>Email with custom from address.</p>',
|
|
48
|
-
});
|
|
49
|
-
expect(result.success).toBe(true);
|
|
50
|
-
expect(result.messageId).toBeDefined();
|
|
51
|
-
});
|
|
52
|
-
it('should send email with cc', async () => {
|
|
53
|
-
const result = await provider.sendEmail({
|
|
54
|
-
to: testRecipient,
|
|
55
|
-
cc: testRecipient,
|
|
56
|
-
subject: `[Resend Test] CC Test - ${new Date().toISOString()}`,
|
|
57
|
-
html: '<p>Email with CC recipient.</p>',
|
|
58
|
-
});
|
|
59
|
-
expect(result.success).toBe(true);
|
|
60
|
-
expect(result.messageId).toBeDefined();
|
|
61
|
-
});
|
|
62
|
-
it('should send email with bcc', async () => {
|
|
63
|
-
const result = await provider.sendEmail({
|
|
64
|
-
to: testRecipient,
|
|
65
|
-
bcc: testRecipient,
|
|
66
|
-
subject: `[Resend Test] BCC Test - ${new Date().toISOString()}`,
|
|
67
|
-
html: '<p>Email with BCC recipient.</p>',
|
|
68
|
-
});
|
|
69
|
-
expect(result.success).toBe(true);
|
|
70
|
-
expect(result.messageId).toBeDefined();
|
|
71
|
-
});
|
|
72
|
-
it('should send email with replyTo', async () => {
|
|
73
|
-
const result = await provider.sendEmail({
|
|
74
|
-
to: testRecipient,
|
|
75
|
-
replyTo: testRecipient,
|
|
76
|
-
subject: `[Resend Test] Reply-To Test - ${new Date().toISOString()}`,
|
|
77
|
-
html: '<p>Email with reply-to address.</p>',
|
|
78
|
-
});
|
|
79
|
-
expect(result.success).toBe(true);
|
|
80
|
-
expect(result.messageId).toBeDefined();
|
|
81
|
-
});
|
|
82
|
-
it('should send email with attachment', async () => {
|
|
83
|
-
const result = await provider.sendEmail({
|
|
84
|
-
to: testRecipient,
|
|
85
|
-
subject: `[Resend Test] Attachment Test - ${new Date().toISOString()}`,
|
|
86
|
-
html: '<p>Email with attachment.</p>',
|
|
87
|
-
attachments: [
|
|
88
|
-
{
|
|
89
|
-
filename: 'test.txt',
|
|
90
|
-
content: Buffer.from('This is a test attachment content.'),
|
|
91
|
-
contentType: 'text/plain',
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
});
|
|
95
|
-
expect(result.success).toBe(true);
|
|
96
|
-
expect(result.messageId).toBeDefined();
|
|
97
|
-
});
|
|
98
|
-
it('should send email to multiple recipients', async () => {
|
|
99
|
-
const result = await provider.sendEmail({
|
|
100
|
-
to: [testRecipient],
|
|
101
|
-
subject: `[Resend Test] Multiple Recipients - ${new Date().toISOString()}`,
|
|
102
|
-
html: '<p>Email to multiple recipients.</p>',
|
|
103
|
-
});
|
|
104
|
-
expect(result.success).toBe(true);
|
|
105
|
-
expect(result.messageId).toBeDefined();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
//# sourceMappingURL=resend.provider.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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