@flusys/nestjs-email 7.1.0 → 8.0.0-beta.1

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.
Files changed (159) hide show
  1. package/config/index.d.ts +3 -3
  2. package/controllers/email-config.controller.d.ts +2 -2
  3. package/controllers/email-send.controller.d.ts +3 -3
  4. package/controllers/email-template.controller.d.ts +4 -4
  5. package/controllers/index.d.ts +3 -3
  6. package/docs/email-swagger.config.d.ts +2 -2
  7. package/docs/index.d.ts +1 -1
  8. package/dtos/email-config.dto.d.ts +1 -1
  9. package/dtos/email-send.dto.d.ts +1 -1
  10. package/dtos/index.d.ts +3 -3
  11. package/entities/email-config-with-company.entity.d.ts +1 -1
  12. package/entities/email-template-with-company.entity.d.ts +1 -1
  13. package/entities/index.d.ts +10 -10
  14. package/enums/index.d.ts +1 -1
  15. package/fesm/261.js +799 -0
  16. package/fesm/493.js +1723 -0
  17. package/fesm/chunks/99.js +12 -0
  18. package/fesm/config/index.js +104 -3
  19. package/fesm/controllers/index.js +396 -3
  20. package/fesm/docs/index.js +134 -1
  21. package/fesm/dtos/index.js +22 -3
  22. package/fesm/entities/index.js +409 -13
  23. package/fesm/enums/index.js +37 -1
  24. package/fesm/index.js +762 -10
  25. package/fesm/interfaces/index.js +18 -4
  26. package/fesm/modules/index.js +541 -1
  27. package/fesm/providers/index.js +523 -5
  28. package/fesm/runtime.js +134 -0
  29. package/fesm/services/index.js +17 -5
  30. package/index.d.ts +10 -10
  31. package/interfaces/email-config.interface.d.ts +2 -2
  32. package/interfaces/email-module-options.interface.d.ts +3 -3
  33. package/interfaces/email-template.interface.d.ts +1 -1
  34. package/interfaces/index.d.ts +4 -4
  35. package/modules/email.module.d.ts +2 -2
  36. package/modules/index.d.ts +1 -1
  37. package/package.json +27 -38
  38. package/providers/email-factory.service.d.ts +2 -2
  39. package/providers/email-provider.registry.d.ts +2 -2
  40. package/providers/index.d.ts +5 -5
  41. package/providers/mailgun-provider.d.ts +1 -1
  42. package/providers/sendgrid-provider.d.ts +1 -1
  43. package/providers/smtp-provider.d.ts +1 -1
  44. package/services/email-config.service.d.ts +3 -3
  45. package/services/email-datasource.provider.d.ts +3 -3
  46. package/services/email-provider-config.service.d.ts +7 -7
  47. package/services/email-send.service.d.ts +7 -7
  48. package/services/email-template.service.d.ts +6 -6
  49. package/services/index.d.ts +5 -5
  50. package/utils/index.d.ts +1 -1
  51. package/cjs/config/email.constants.js +0 -22
  52. package/cjs/config/event-actions.js +0 -34
  53. package/cjs/config/index.js +0 -20
  54. package/cjs/config/message-keys.js +0 -39
  55. package/cjs/controllers/email-config.controller.js +0 -111
  56. package/cjs/controllers/email-config.controller.spec.js +0 -85
  57. package/cjs/controllers/email-send.controller.js +0 -128
  58. package/cjs/controllers/email-send.controller.spec.js +0 -139
  59. package/cjs/controllers/email-template.controller.js +0 -142
  60. package/cjs/controllers/email-template.controller.spec.js +0 -89
  61. package/cjs/controllers/index.js +0 -20
  62. package/cjs/docs/email-swagger.config.js +0 -116
  63. package/cjs/docs/email-swagger.config.spec.js +0 -62
  64. package/cjs/docs/index.js +0 -11
  65. package/cjs/dtos/email-config.dto.js +0 -212
  66. package/cjs/dtos/email-send.dto.js +0 -354
  67. package/cjs/dtos/email-template.dto.js +0 -252
  68. package/cjs/dtos/index.js +0 -20
  69. package/cjs/entities/email-config-with-company.entity.js +0 -63
  70. package/cjs/entities/email-config.entity.js +0 -114
  71. package/cjs/entities/email-template-with-company.entity.js +0 -65
  72. package/cjs/entities/email-template.entity.js +0 -136
  73. package/cjs/entities/index.js +0 -56
  74. package/cjs/entities/index.spec.js +0 -18
  75. package/cjs/enums/email-provider-type.enum.js +0 -18
  76. package/cjs/enums/index.js +0 -18
  77. package/cjs/index.js +0 -28
  78. package/cjs/interfaces/email-config.interface.js +0 -4
  79. package/cjs/interfaces/email-module-options.interface.js +0 -4
  80. package/cjs/interfaces/email-provider.interface.js +0 -4
  81. package/cjs/interfaces/email-template.interface.js +0 -4
  82. package/cjs/interfaces/index.js +0 -21
  83. package/cjs/modules/email.module.js +0 -122
  84. package/cjs/modules/email.module.spec.js +0 -142
  85. package/cjs/modules/index.js +0 -18
  86. package/cjs/providers/email-factory.service.js +0 -113
  87. package/cjs/providers/email-factory.service.spec.js +0 -242
  88. package/cjs/providers/email-provider.registry.js +0 -41
  89. package/cjs/providers/email-provider.registry.spec.js +0 -58
  90. package/cjs/providers/index.js +0 -22
  91. package/cjs/providers/mailgun-provider.js +0 -119
  92. package/cjs/providers/mailgun-provider.spec.js +0 -244
  93. package/cjs/providers/sendgrid-provider.js +0 -129
  94. package/cjs/providers/sendgrid-provider.spec.js +0 -346
  95. package/cjs/providers/smtp-provider.js +0 -164
  96. package/cjs/providers/smtp-provider.spec.js +0 -327
  97. package/cjs/services/email-config.service.js +0 -71
  98. package/cjs/services/email-config.service.spec.js +0 -69
  99. package/cjs/services/email-datasource.provider.js +0 -84
  100. package/cjs/services/email-datasource.provider.spec.js +0 -135
  101. package/cjs/services/email-provider-config.service.js +0 -159
  102. package/cjs/services/email-provider-config.service.spec.js +0 -269
  103. package/cjs/services/email-send.service.js +0 -315
  104. package/cjs/services/email-send.service.spec.js +0 -614
  105. package/cjs/services/email-template.service.js +0 -144
  106. package/cjs/services/email-template.service.spec.js +0 -261
  107. package/cjs/services/index.js +0 -22
  108. package/cjs/utils/email-templates.util.js +0 -64
  109. package/cjs/utils/email-templates.util.spec.js +0 -61
  110. package/cjs/utils/index.js +0 -18
  111. package/fesm/config/email.constants.js +0 -4
  112. package/fesm/config/event-actions.js +0 -13
  113. package/fesm/config/message-keys.js +0 -18
  114. package/fesm/controllers/email-config.controller.js +0 -101
  115. package/fesm/controllers/email-config.controller.spec.js +0 -81
  116. package/fesm/controllers/email-send.controller.js +0 -118
  117. package/fesm/controllers/email-send.controller.spec.js +0 -135
  118. package/fesm/controllers/email-template.controller.js +0 -132
  119. package/fesm/controllers/email-template.controller.spec.js +0 -85
  120. package/fesm/docs/email-swagger.config.js +0 -109
  121. package/fesm/docs/email-swagger.config.spec.js +0 -58
  122. package/fesm/dtos/email-config.dto.js +0 -191
  123. package/fesm/dtos/email-send.dto.js +0 -324
  124. package/fesm/dtos/email-template.dto.js +0 -231
  125. package/fesm/entities/email-config-with-company.entity.js +0 -53
  126. package/fesm/entities/email-config.entity.js +0 -104
  127. package/fesm/entities/email-template-with-company.entity.js +0 -55
  128. package/fesm/entities/email-template.entity.js +0 -126
  129. package/fesm/entities/index.spec.js +0 -14
  130. package/fesm/enums/email-provider-type.enum.js +0 -8
  131. package/fesm/interfaces/email-config.interface.js +0 -1
  132. package/fesm/interfaces/email-module-options.interface.js +0 -1
  133. package/fesm/interfaces/email-provider.interface.js +0 -1
  134. package/fesm/interfaces/email-template.interface.js +0 -1
  135. package/fesm/modules/email.module.js +0 -112
  136. package/fesm/modules/email.module.spec.js +0 -138
  137. package/fesm/providers/email-factory.service.js +0 -103
  138. package/fesm/providers/email-factory.service.spec.js +0 -238
  139. package/fesm/providers/email-provider.registry.js +0 -31
  140. package/fesm/providers/email-provider.registry.spec.js +0 -54
  141. package/fesm/providers/mailgun-provider.js +0 -109
  142. package/fesm/providers/mailgun-provider.spec.js +0 -240
  143. package/fesm/providers/sendgrid-provider.js +0 -119
  144. package/fesm/providers/sendgrid-provider.spec.js +0 -342
  145. package/fesm/providers/smtp-provider.js +0 -113
  146. package/fesm/providers/smtp-provider.spec.js +0 -282
  147. package/fesm/services/email-config.service.js +0 -61
  148. package/fesm/services/email-config.service.spec.js +0 -65
  149. package/fesm/services/email-datasource.provider.js +0 -74
  150. package/fesm/services/email-datasource.provider.spec.js +0 -131
  151. package/fesm/services/email-provider-config.service.js +0 -149
  152. package/fesm/services/email-provider-config.service.spec.js +0 -265
  153. package/fesm/services/email-send.service.js +0 -305
  154. package/fesm/services/email-send.service.spec.js +0 -610
  155. package/fesm/services/email-template.service.js +0 -134
  156. package/fesm/services/email-template.service.spec.js +0 -257
  157. package/fesm/utils/email-templates.util.js +0 -47
  158. package/fesm/utils/email-templates.util.spec.js +0 -57
  159. package/fesm/utils/index.js +0 -1
@@ -1,109 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- import { SYSTEM_MESSAGES } from '@flusys/nestjs-shared/constants';
15
- import { InternalServerErrorException } from '@nestjs/common';
16
- const MAILGUN_API_URL = 'https://api.mailgun.net';
17
- const MAILGUN_EU_API_URL = 'https://api.eu.mailgun.net';
18
- export class MailgunProvider {
19
- async initialize(config) {
20
- this.domain = config.domain;
21
- try {
22
- // Dynamic import for optional dependency
23
- const Mailgun = (await new Function('return import("mailgun.js")')()).default;
24
- const FormData = (await new Function('return import("form-data")')()).default;
25
- const mailgun = new Mailgun(FormData);
26
- const url = config.region === 'eu' ? MAILGUN_EU_API_URL : MAILGUN_API_URL;
27
- this.client = mailgun.client({
28
- username: 'api',
29
- key: config.apiKey,
30
- url
31
- });
32
- } catch {
33
- throw new InternalServerErrorException({
34
- message: 'Mailgun initialization failed. Install: npm install mailgun.js form-data',
35
- messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
36
- messageVariables: {
37
- sdk: 'mailgun'
38
- }
39
- });
40
- }
41
- }
42
- async sendEmail(options) {
43
- if (!this.client || !this.domain) {
44
- return {
45
- success: false,
46
- error: 'Mailgun provider not initialized'
47
- };
48
- }
49
- try {
50
- const messageData = this.buildMessageData(options);
51
- const result = await this.client.messages.create(this.domain, messageData);
52
- return {
53
- success: true,
54
- messageId: result.id
55
- };
56
- } catch (error) {
57
- return {
58
- success: false,
59
- error: this.extractError(error)
60
- };
61
- }
62
- }
63
- async sendBulkEmails(options) {
64
- return Promise.all(options.map((opt)=>this.sendEmail(opt)));
65
- }
66
- async healthCheck() {
67
- if (!this.client || !this.domain) return false;
68
- try {
69
- await this.client.domains.get(this.domain);
70
- return true;
71
- } catch {
72
- return false;
73
- }
74
- }
75
- async close() {
76
- this.client = null;
77
- }
78
- // ─── Private Helpers ────────────────────────────────────────────────────────
79
- buildMessageData(options) {
80
- const data = {
81
- from: options.fromName ? `${options.fromName} <${options.from}>` : options.from,
82
- to: this.joinAddresses(options.to),
83
- subject: options.subject
84
- };
85
- if (options.html) data.html = options.html;
86
- if (options.text) data.text = options.text;
87
- if (options.cc) data.cc = this.joinAddresses(options.cc);
88
- if (options.bcc) data.bcc = this.joinAddresses(options.bcc);
89
- if (options.replyTo) data['h:Reply-To'] = options.replyTo;
90
- if (options.attachments?.length) {
91
- data.attachment = options.attachments.map((a)=>({
92
- filename: a.filename,
93
- data: typeof a.content === 'string' ? Buffer.from(a.content, 'base64') : a.content,
94
- contentType: a.contentType
95
- }));
96
- }
97
- return data;
98
- }
99
- joinAddresses(addresses) {
100
- return Array.isArray(addresses) ? addresses.join(', ') : addresses;
101
- }
102
- extractError(error) {
103
- return error instanceof Error ? error.message : 'Unknown error';
104
- }
105
- constructor(){
106
- _define_property(this, "client", null);
107
- _define_property(this, "domain", null);
108
- }
109
- }
@@ -1,240 +0,0 @@
1
- import { InternalServerErrorException } from '@nestjs/common';
2
- import { MailgunProvider } from './mailgun-provider';
3
- // mailgun.js is not an installed dependency in this workspace, so the real dynamic
4
- // import() inside `initialize()` fails — that's exercised directly (no mocking needed).
5
- // For "happy path" behavior we bypass initialize() and inject a fake client, matching
6
- // the private `client`/`domain` fields the provider mutates internally.
7
- function injectClient(provider, client, domain = 'example.com') {
8
- provider.client = client;
9
- provider.domain = domain;
10
- }
11
- describe('MailgunProvider', ()=>{
12
- let provider;
13
- beforeEach(()=>{
14
- provider = new MailgunProvider();
15
- });
16
- describe('initialize', ()=>{
17
- it('throws InternalServerErrorException with SDK_NOT_INSTALLED when mailgun.js is unavailable', async ()=>{
18
- await expect(provider.initialize({
19
- apiKey: 'key',
20
- domain: 'example.com'
21
- })).rejects.toThrow(InternalServerErrorException);
22
- });
23
- it('surfaces the sdk name in the exception messageVariables', async ()=>{
24
- try {
25
- await provider.initialize({
26
- apiKey: 'key',
27
- domain: 'example.com'
28
- });
29
- fail('expected initialize to throw');
30
- } catch (error) {
31
- expect(error.getResponse()).toEqual(expect.objectContaining({
32
- messageKey: 'system.sdk.not.installed',
33
- messageVariables: {
34
- sdk: 'mailgun'
35
- }
36
- }));
37
- }
38
- });
39
- });
40
- describe('sendEmail', ()=>{
41
- it('returns a failure result when the provider was never initialized', async ()=>{
42
- const result = await provider.sendEmail({
43
- to: 'a@example.com',
44
- subject: 'Hi'
45
- });
46
- expect(result).toEqual({
47
- success: false,
48
- error: 'Mailgun provider not initialized'
49
- });
50
- });
51
- it('sends via the mailgun client and returns the message id on success', async ()=>{
52
- const create = jest.fn().mockResolvedValue({
53
- id: '<msg-1@mailgun>'
54
- });
55
- injectClient(provider, {
56
- messages: {
57
- create
58
- }
59
- });
60
- const result = await provider.sendEmail({
61
- to: 'a@example.com',
62
- cc: [
63
- 'b@example.com',
64
- 'c@example.com'
65
- ],
66
- bcc: 'd@example.com',
67
- subject: 'Hello',
68
- html: '<p>hi</p>',
69
- text: 'hi',
70
- from: 'sender@example.com',
71
- fromName: 'Sender Name',
72
- replyTo: 'reply@example.com'
73
- });
74
- expect(result).toEqual({
75
- success: true,
76
- messageId: '<msg-1@mailgun>'
77
- });
78
- expect(create).toHaveBeenCalledWith('example.com', expect.objectContaining({
79
- from: 'Sender Name <sender@example.com>',
80
- to: 'a@example.com',
81
- subject: 'Hello',
82
- html: '<p>hi</p>',
83
- text: 'hi',
84
- cc: 'b@example.com, c@example.com',
85
- bcc: 'd@example.com',
86
- 'h:Reply-To': 'reply@example.com'
87
- }));
88
- });
89
- it('omits optional fields (cc/bcc/replyTo/html/text) when not provided', async ()=>{
90
- const create = jest.fn().mockResolvedValue({
91
- id: 'id-1'
92
- });
93
- injectClient(provider, {
94
- messages: {
95
- create
96
- }
97
- });
98
- await provider.sendEmail({
99
- to: 'a@example.com',
100
- subject: 'Hi',
101
- from: 'x@example.com'
102
- });
103
- const [, messageData] = create.mock.calls[0];
104
- expect(messageData).not.toHaveProperty('cc');
105
- expect(messageData).not.toHaveProperty('bcc');
106
- expect(messageData).not.toHaveProperty('h:Reply-To');
107
- expect(messageData).not.toHaveProperty('html');
108
- expect(messageData).not.toHaveProperty('text');
109
- });
110
- it('base64-decodes attachment content before sending', async ()=>{
111
- const create = jest.fn().mockResolvedValue({
112
- id: 'id-1'
113
- });
114
- injectClient(provider, {
115
- messages: {
116
- create
117
- }
118
- });
119
- await provider.sendEmail({
120
- to: 'a@example.com',
121
- subject: 'Hi',
122
- attachments: [
123
- {
124
- filename: 'doc.txt',
125
- content: Buffer.from('hello').toString('base64'),
126
- contentType: 'text/plain'
127
- }
128
- ]
129
- });
130
- const [, messageData] = create.mock.calls[0];
131
- const attachment = messageData.attachment[0];
132
- expect(attachment.filename).toBe('doc.txt');
133
- expect(attachment.contentType).toBe('text/plain');
134
- expect(Buffer.isBuffer(attachment.data)).toBe(true);
135
- expect(attachment.data.toString('utf8')).toBe('hello');
136
- });
137
- it('returns the error message when the mailgun client rejects with an Error', async ()=>{
138
- injectClient(provider, {
139
- messages: {
140
- create: jest.fn().mockRejectedValue(new Error('domain not found'))
141
- }
142
- });
143
- const result = await provider.sendEmail({
144
- to: 'a@example.com',
145
- subject: 'Hi'
146
- });
147
- expect(result).toEqual({
148
- success: false,
149
- error: 'domain not found'
150
- });
151
- });
152
- it('returns "Unknown error" when the mailgun client rejects with a non-Error', async ()=>{
153
- injectClient(provider, {
154
- messages: {
155
- create: jest.fn().mockRejectedValue('some string failure')
156
- }
157
- });
158
- const result = await provider.sendEmail({
159
- to: 'a@example.com',
160
- subject: 'Hi'
161
- });
162
- expect(result).toEqual({
163
- success: false,
164
- error: 'Unknown error'
165
- });
166
- });
167
- });
168
- describe('sendBulkEmails', ()=>{
169
- it('sends each message individually and aggregates the results', async ()=>{
170
- const create = jest.fn().mockResolvedValueOnce({
171
- id: 'id-1'
172
- }).mockRejectedValueOnce(new Error('failed-2'));
173
- injectClient(provider, {
174
- messages: {
175
- create
176
- }
177
- });
178
- const results = await provider.sendBulkEmails([
179
- {
180
- to: 'a@example.com',
181
- subject: 'A'
182
- },
183
- {
184
- to: 'b@example.com',
185
- subject: 'B'
186
- }
187
- ]);
188
- expect(results).toEqual([
189
- {
190
- success: true,
191
- messageId: 'id-1'
192
- },
193
- {
194
- success: false,
195
- error: 'failed-2'
196
- }
197
- ]);
198
- expect(create).toHaveBeenCalledTimes(2);
199
- });
200
- });
201
- describe('healthCheck', ()=>{
202
- it('returns false when not initialized', async ()=>{
203
- await expect(provider.healthCheck()).resolves.toBe(false);
204
- });
205
- it('returns true when the mailgun domain lookup succeeds', async ()=>{
206
- injectClient(provider, {
207
- domains: {
208
- get: jest.fn().mockResolvedValue({})
209
- }
210
- });
211
- await expect(provider.healthCheck()).resolves.toBe(true);
212
- });
213
- it('returns false when the mailgun domain lookup fails', async ()=>{
214
- injectClient(provider, {
215
- domains: {
216
- get: jest.fn().mockRejectedValue(new Error('nope'))
217
- }
218
- });
219
- await expect(provider.healthCheck()).resolves.toBe(false);
220
- });
221
- });
222
- describe('close', ()=>{
223
- it('clears the client reference', async ()=>{
224
- injectClient(provider, {
225
- messages: {
226
- create: jest.fn()
227
- }
228
- });
229
- await provider.close();
230
- const result = await provider.sendEmail({
231
- to: 'a@example.com',
232
- subject: 'Hi'
233
- });
234
- expect(result).toEqual({
235
- success: false,
236
- error: 'Mailgun provider not initialized'
237
- });
238
- });
239
- });
240
- });
@@ -1,119 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- import { SYSTEM_MESSAGES } from '@flusys/nestjs-shared/constants';
15
- import { InternalServerErrorException } from '@nestjs/common';
16
- export class SendGridProvider {
17
- async initialize(config) {
18
- this.apiKey = config.apiKey;
19
- try {
20
- // Dynamic import to avoid bundling issues
21
- const sgMailModule = await new Function('return import("@sendgrid/mail")')();
22
- this.sgMail = sgMailModule.default || sgMailModule;
23
- this.sgMail.setApiKey(config.apiKey);
24
- } catch {
25
- throw new InternalServerErrorException({
26
- message: 'SendGrid initialization failed. Install: npm install @sendgrid/mail',
27
- messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
28
- messageVariables: {
29
- sdk: 'sendgrid'
30
- }
31
- });
32
- }
33
- }
34
- async sendEmail(options) {
35
- if (!this.sgMail) return {
36
- success: false,
37
- error: 'SendGrid provider not initialized'
38
- };
39
- try {
40
- const msg = this.buildMessage(options, true);
41
- const [response] = await this.sgMail.send(msg);
42
- const messageId = response.headers['x-message-id'] || response.headers['X-Message-Id'];
43
- return {
44
- success: true,
45
- messageId
46
- };
47
- } catch (error) {
48
- return {
49
- success: false,
50
- error: this.extractError(error)
51
- };
52
- }
53
- }
54
- async sendBulkEmails(options) {
55
- if (!this.sgMail) return options.map(()=>({
56
- success: false,
57
- error: 'SendGrid provider not initialized'
58
- }));
59
- try {
60
- const messages = options.map((opt)=>this.buildMessage(opt, false));
61
- await this.sgMail.send(messages);
62
- return options.map(()=>({
63
- success: true
64
- }));
65
- } catch (error) {
66
- const errorMessage = this.extractError(error);
67
- return options.map(()=>({
68
- success: false,
69
- error: errorMessage
70
- }));
71
- }
72
- }
73
- async healthCheck() {
74
- return !!(this.sgMail && this.apiKey?.startsWith('SG.'));
75
- }
76
- async close() {
77
- this.sgMail = null;
78
- }
79
- // ─── Private Helpers ────────────────────────────────────────────────────────
80
- buildMessage(options, includeExtras) {
81
- const msg = {
82
- to: this.toArray(options.to),
83
- from: options.fromName ? {
84
- email: options.from,
85
- name: options.fromName
86
- } : options.from,
87
- subject: options.subject
88
- };
89
- if (options.html) msg.html = options.html;
90
- if (options.text) msg.text = options.text;
91
- if (includeExtras) {
92
- if (options.cc) msg.cc = this.toArray(options.cc);
93
- if (options.bcc) msg.bcc = this.toArray(options.bcc);
94
- if (options.replyTo) msg.replyTo = options.replyTo;
95
- if (options.attachments?.length) {
96
- msg.attachments = options.attachments.map((a)=>({
97
- filename: a.filename,
98
- content: typeof a.content === 'string' ? a.content : a.content.toString('base64'),
99
- type: a.contentType,
100
- disposition: 'attachment'
101
- }));
102
- }
103
- }
104
- return msg;
105
- }
106
- toArray(value) {
107
- return Array.isArray(value) ? value : [
108
- value
109
- ];
110
- }
111
- extractError(error) {
112
- const sgError = error;
113
- return sgError.response?.body?.errors?.[0]?.message || sgError.message || 'Unknown error';
114
- }
115
- constructor(){
116
- _define_property(this, "sgMail", null);
117
- _define_property(this, "apiKey", null);
118
- }
119
- }