@flusys/nestjs-email 7.1.0 → 8.0.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/config/index.d.ts +3 -3
- package/controllers/email-config.controller.d.ts +2 -2
- package/controllers/email-send.controller.d.ts +3 -3
- package/controllers/email-template.controller.d.ts +4 -4
- package/controllers/index.d.ts +3 -3
- package/docs/email-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/email-config.dto.d.ts +1 -1
- package/dtos/email-send.dto.d.ts +1 -1
- package/dtos/index.d.ts +3 -3
- package/entities/email-config-with-company.entity.d.ts +1 -1
- package/entities/email-template-with-company.entity.d.ts +1 -1
- package/entities/index.d.ts +10 -10
- package/enums/index.d.ts +1 -1
- package/fesm/261.js +799 -0
- package/fesm/493.js +1723 -0
- package/fesm/chunks/99.js +12 -0
- package/fesm/config/index.js +104 -3
- package/fesm/controllers/index.js +396 -3
- package/fesm/docs/index.js +134 -1
- package/fesm/dtos/index.js +22 -3
- package/fesm/entities/index.js +409 -13
- package/fesm/enums/index.js +37 -1
- package/fesm/index.js +762 -10
- package/fesm/interfaces/index.js +18 -4
- package/fesm/modules/index.js +541 -1
- package/fesm/providers/index.js +523 -5
- package/fesm/runtime.js +134 -0
- package/fesm/services/index.js +17 -5
- package/index.d.ts +10 -10
- package/interfaces/email-config.interface.d.ts +2 -2
- package/interfaces/email-module-options.interface.d.ts +3 -3
- package/interfaces/email-template.interface.d.ts +1 -1
- package/interfaces/index.d.ts +4 -4
- package/modules/email.module.d.ts +2 -2
- package/modules/index.d.ts +1 -1
- package/package.json +27 -38
- package/providers/email-factory.service.d.ts +2 -2
- package/providers/email-provider.registry.d.ts +2 -2
- package/providers/index.d.ts +5 -5
- package/providers/mailgun-provider.d.ts +1 -1
- package/providers/sendgrid-provider.d.ts +1 -1
- package/providers/smtp-provider.d.ts +1 -1
- package/services/email-config.service.d.ts +3 -3
- package/services/email-datasource.provider.d.ts +3 -3
- package/services/email-provider-config.service.d.ts +7 -7
- package/services/email-send.service.d.ts +7 -7
- package/services/email-template.service.d.ts +6 -6
- package/services/index.d.ts +5 -5
- package/utils/index.d.ts +1 -1
- package/cjs/config/email.constants.js +0 -22
- package/cjs/config/event-actions.js +0 -34
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -39
- package/cjs/controllers/email-config.controller.js +0 -111
- package/cjs/controllers/email-config.controller.spec.js +0 -85
- package/cjs/controllers/email-send.controller.js +0 -128
- package/cjs/controllers/email-send.controller.spec.js +0 -139
- package/cjs/controllers/email-template.controller.js +0 -142
- package/cjs/controllers/email-template.controller.spec.js +0 -89
- package/cjs/controllers/index.js +0 -20
- package/cjs/docs/email-swagger.config.js +0 -116
- package/cjs/docs/email-swagger.config.spec.js +0 -62
- package/cjs/docs/index.js +0 -11
- package/cjs/dtos/email-config.dto.js +0 -212
- package/cjs/dtos/email-send.dto.js +0 -354
- package/cjs/dtos/email-template.dto.js +0 -252
- package/cjs/dtos/index.js +0 -20
- package/cjs/entities/email-config-with-company.entity.js +0 -63
- package/cjs/entities/email-config.entity.js +0 -114
- package/cjs/entities/email-template-with-company.entity.js +0 -65
- package/cjs/entities/email-template.entity.js +0 -136
- package/cjs/entities/index.js +0 -56
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/enums/email-provider-type.enum.js +0 -18
- package/cjs/enums/index.js +0 -18
- package/cjs/index.js +0 -28
- package/cjs/interfaces/email-config.interface.js +0 -4
- package/cjs/interfaces/email-module-options.interface.js +0 -4
- package/cjs/interfaces/email-provider.interface.js +0 -4
- package/cjs/interfaces/email-template.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -21
- package/cjs/modules/email.module.js +0 -122
- package/cjs/modules/email.module.spec.js +0 -142
- package/cjs/modules/index.js +0 -18
- package/cjs/providers/email-factory.service.js +0 -113
- package/cjs/providers/email-factory.service.spec.js +0 -242
- package/cjs/providers/email-provider.registry.js +0 -41
- package/cjs/providers/email-provider.registry.spec.js +0 -58
- package/cjs/providers/index.js +0 -22
- package/cjs/providers/mailgun-provider.js +0 -119
- package/cjs/providers/mailgun-provider.spec.js +0 -244
- package/cjs/providers/sendgrid-provider.js +0 -129
- package/cjs/providers/sendgrid-provider.spec.js +0 -346
- package/cjs/providers/smtp-provider.js +0 -164
- package/cjs/providers/smtp-provider.spec.js +0 -327
- package/cjs/services/email-config.service.js +0 -71
- package/cjs/services/email-config.service.spec.js +0 -69
- package/cjs/services/email-datasource.provider.js +0 -84
- package/cjs/services/email-datasource.provider.spec.js +0 -135
- package/cjs/services/email-provider-config.service.js +0 -159
- package/cjs/services/email-provider-config.service.spec.js +0 -269
- package/cjs/services/email-send.service.js +0 -315
- package/cjs/services/email-send.service.spec.js +0 -614
- package/cjs/services/email-template.service.js +0 -144
- package/cjs/services/email-template.service.spec.js +0 -261
- package/cjs/services/index.js +0 -22
- package/cjs/utils/email-templates.util.js +0 -64
- package/cjs/utils/email-templates.util.spec.js +0 -61
- package/cjs/utils/index.js +0 -18
- package/fesm/config/email.constants.js +0 -4
- package/fesm/config/event-actions.js +0 -13
- package/fesm/config/message-keys.js +0 -18
- package/fesm/controllers/email-config.controller.js +0 -101
- package/fesm/controllers/email-config.controller.spec.js +0 -81
- package/fesm/controllers/email-send.controller.js +0 -118
- package/fesm/controllers/email-send.controller.spec.js +0 -135
- package/fesm/controllers/email-template.controller.js +0 -132
- package/fesm/controllers/email-template.controller.spec.js +0 -85
- package/fesm/docs/email-swagger.config.js +0 -109
- package/fesm/docs/email-swagger.config.spec.js +0 -58
- package/fesm/dtos/email-config.dto.js +0 -191
- package/fesm/dtos/email-send.dto.js +0 -324
- package/fesm/dtos/email-template.dto.js +0 -231
- package/fesm/entities/email-config-with-company.entity.js +0 -53
- package/fesm/entities/email-config.entity.js +0 -104
- package/fesm/entities/email-template-with-company.entity.js +0 -55
- package/fesm/entities/email-template.entity.js +0 -126
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/enums/email-provider-type.enum.js +0 -8
- package/fesm/interfaces/email-config.interface.js +0 -1
- package/fesm/interfaces/email-module-options.interface.js +0 -1
- package/fesm/interfaces/email-provider.interface.js +0 -1
- package/fesm/interfaces/email-template.interface.js +0 -1
- package/fesm/modules/email.module.js +0 -112
- package/fesm/modules/email.module.spec.js +0 -138
- package/fesm/providers/email-factory.service.js +0 -103
- package/fesm/providers/email-factory.service.spec.js +0 -238
- package/fesm/providers/email-provider.registry.js +0 -31
- package/fesm/providers/email-provider.registry.spec.js +0 -54
- package/fesm/providers/mailgun-provider.js +0 -109
- package/fesm/providers/mailgun-provider.spec.js +0 -240
- package/fesm/providers/sendgrid-provider.js +0 -119
- package/fesm/providers/sendgrid-provider.spec.js +0 -342
- package/fesm/providers/smtp-provider.js +0 -113
- package/fesm/providers/smtp-provider.spec.js +0 -282
- package/fesm/services/email-config.service.js +0 -61
- package/fesm/services/email-config.service.spec.js +0 -65
- package/fesm/services/email-datasource.provider.js +0 -74
- package/fesm/services/email-datasource.provider.spec.js +0 -131
- package/fesm/services/email-provider-config.service.js +0 -149
- package/fesm/services/email-provider-config.service.spec.js +0 -265
- package/fesm/services/email-send.service.js +0 -305
- package/fesm/services/email-send.service.spec.js +0 -610
- package/fesm/services/email-template.service.js +0 -134
- package/fesm/services/email-template.service.spec.js +0 -257
- package/fesm/utils/email-templates.util.js +0 -47
- package/fesm/utils/email-templates.util.spec.js +0 -57
- package/fesm/utils/index.js +0 -1
package/fesm/providers/index.js
CHANGED
|
@@ -1,5 +1,523 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { SYSTEM_MESSAGES } from "@flusys/nestjs-shared/constants";
|
|
3
|
+
import * as __rspack_external__flusys_nestjs_shared_393d2cae from "@flusys/nestjs-shared";
|
|
4
|
+
import * as __rspack_external__flusys_nestjs_shared_utils_9125c1f1 from "@flusys/nestjs-shared/utils";
|
|
5
|
+
import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
|
|
6
|
+
export const __rspack_esm_id = 467;
|
|
7
|
+
export const __rspack_esm_ids = [467];
|
|
8
|
+
export const __webpack_modules__ = {
|
|
9
|
+
887(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
10
|
+
// ==================== EMAIL MODULE MESSAGE KEYS ====================
|
|
11
|
+
const EMAIL_TEMPLATE_MESSAGES = {
|
|
12
|
+
GET_SUCCESS: 'email.template.get.success',
|
|
13
|
+
NOT_FOUND: 'email.template.not.found'
|
|
14
|
+
};
|
|
15
|
+
const EMAIL_CONFIG_MESSAGES = {
|
|
16
|
+
DEFAULT_DELETE_FORBIDDEN: 'email.config.default.delete.forbidden'
|
|
17
|
+
};
|
|
18
|
+
const EMAIL_SEND_MESSAGES = {
|
|
19
|
+
SUCCESS: 'email.send.success',
|
|
20
|
+
FAILED: 'email.send.failed',
|
|
21
|
+
CONFIG_NOT_FOUND: 'email.send.config.not.found',
|
|
22
|
+
CONFIG_INACTIVE: 'email.send.config.inactive',
|
|
23
|
+
CONFIG_DEFAULT_NOT_FOUND: 'email.send.config.default.not.found',
|
|
24
|
+
TEMPLATE_NOT_FOUND: 'email.send.template.not.found',
|
|
25
|
+
TEMPLATE_INACTIVE: 'email.send.template.inactive',
|
|
26
|
+
TEMPLATE_ID_OR_SLUG_REQUIRED: 'email.send.template.id.or.slug.required'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
30
|
+
}, {
|
|
31
|
+
T6: EMAIL_CONFIG_MESSAGES,
|
|
32
|
+
dP: EMAIL_SEND_MESSAGES,
|
|
33
|
+
xP: EMAIL_TEMPLATE_MESSAGES
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
},
|
|
38
|
+
603(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
39
|
+
|
|
40
|
+
// EXPORTS
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
c: () => (/* reexport */ EmailFactoryService),
|
|
43
|
+
xC: () => (/* reexport */ EmailProviderRegistry),
|
|
44
|
+
Xp: () => (/* reexport */ MailgunProvider),
|
|
45
|
+
Iw: () => (/* reexport */ SendGridProvider),
|
|
46
|
+
Kg: () => (/* reexport */ SmtpProvider)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/email-provider.registry.ts
|
|
50
|
+
class EmailProviderRegistry {
|
|
51
|
+
static providers = new Map();
|
|
52
|
+
static register(providerName, providerClass) {
|
|
53
|
+
this.providers.set(providerName.toLowerCase(), providerClass);
|
|
54
|
+
}
|
|
55
|
+
static get(providerName) {
|
|
56
|
+
return this.providers.get(providerName.toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
static has(providerName) {
|
|
59
|
+
return this.providers.has(providerName.toLowerCase());
|
|
60
|
+
}
|
|
61
|
+
static getAll() {
|
|
62
|
+
return Array.from(this.providers.keys());
|
|
63
|
+
}
|
|
64
|
+
static clear() {
|
|
65
|
+
this.providers.clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared"
|
|
70
|
+
var nestjs_shared_ = __webpack_require__(422);
|
|
71
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
72
|
+
var common_ = __webpack_require__(157);
|
|
73
|
+
;// CONCATENATED MODULE: external "crypto"
|
|
74
|
+
|
|
75
|
+
// EXTERNAL MODULE: ./projects/nestjs-email/src/config/message-keys.ts
|
|
76
|
+
var message_keys = __webpack_require__(887);
|
|
77
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/email-factory.service.ts
|
|
78
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
79
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
80
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
81
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
82
|
+
} else {
|
|
83
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
84
|
+
if (d = decorators[i]) {
|
|
85
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
90
|
+
}
|
|
91
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
92
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
93
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class EmailFactoryService {
|
|
102
|
+
providerCache = new Map();
|
|
103
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
104
|
+
async createProvider(config) {
|
|
105
|
+
const cacheKey = this.generateCacheKey(config);
|
|
106
|
+
const cached = this.providerCache.get(cacheKey);
|
|
107
|
+
if (cached) return cached;
|
|
108
|
+
const ProviderClass = EmailProviderRegistry.get(config.provider);
|
|
109
|
+
if (!ProviderClass) {
|
|
110
|
+
throw new common_.NotFoundException({
|
|
111
|
+
message: `Email provider '${config.provider}' is not registered`,
|
|
112
|
+
messageKey: message_keys/* .EMAIL_SEND_MESSAGES.CONFIG_NOT_FOUND */.dP.CONFIG_NOT_FOUND,
|
|
113
|
+
messageVariables: {
|
|
114
|
+
provider: config.provider,
|
|
115
|
+
available: EmailProviderRegistry.getAll().join(', ')
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const instance = new ProviderClass();
|
|
121
|
+
await instance.initialize?.(config.config);
|
|
122
|
+
this.providerCache.set(cacheKey, instance);
|
|
123
|
+
return instance;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
throw new common_.InternalServerErrorException({
|
|
126
|
+
message: `Email provider '${config.provider}' not initialized successfully: ${this.extractErrorMessage(error)}`,
|
|
127
|
+
messageKey: nestjs_shared_.SYSTEM_MESSAGES.SERVICE_NOT_AVAILABLE,
|
|
128
|
+
messageVariables: {
|
|
129
|
+
provider: config.provider,
|
|
130
|
+
available: EmailProviderRegistry.getAll().join(', ')
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
136
|
+
async onModuleDestroy() {
|
|
137
|
+
const closePromises = Array.from(this.providerCache.entries()).map(([, provider])=>this.closeProvider(provider));
|
|
138
|
+
await Promise.allSettled(closePromises);
|
|
139
|
+
this.providerCache.clear();
|
|
140
|
+
}
|
|
141
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
142
|
+
generateCacheKey(config) {
|
|
143
|
+
const sortedKeys = Object.keys(config.config || {}).sort();
|
|
144
|
+
const configString = JSON.stringify(config.config, sortedKeys);
|
|
145
|
+
const hash = createHash('sha256').update(configString).digest('hex').substring(0, 16);
|
|
146
|
+
return `${config.provider}-${hash}`;
|
|
147
|
+
}
|
|
148
|
+
async closeProvider(provider) {
|
|
149
|
+
if (!provider.close) return;
|
|
150
|
+
try {
|
|
151
|
+
await provider.close();
|
|
152
|
+
} catch {
|
|
153
|
+
// Silent failure
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
extractErrorMessage(error) {
|
|
157
|
+
return error instanceof Error ? error.message : 'Unknown error';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
_ts_decorate([
|
|
161
|
+
(0,nestjs_shared_.LogAction)({
|
|
162
|
+
action: 'email.createProvider',
|
|
163
|
+
module: 'email'
|
|
164
|
+
}),
|
|
165
|
+
_ts_metadata("design:type", Function),
|
|
166
|
+
_ts_metadata("design:paramtypes", [
|
|
167
|
+
typeof IEmailProviderConfig === "undefined" ? Object : IEmailProviderConfig
|
|
168
|
+
]),
|
|
169
|
+
_ts_metadata("design:returntype", Promise)
|
|
170
|
+
], EmailFactoryService.prototype, "createProvider", null);
|
|
171
|
+
EmailFactoryService = _ts_decorate([
|
|
172
|
+
(0,common_.Injectable)()
|
|
173
|
+
], EmailFactoryService);
|
|
174
|
+
|
|
175
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/smtp-provider.ts
|
|
176
|
+
const VERIFY_TIMEOUT_MS = 10_000;
|
|
177
|
+
const SEND_TIMEOUT_MS = 30_000;
|
|
178
|
+
class SmtpProvider {
|
|
179
|
+
transporter = null;
|
|
180
|
+
async initialize(config) {
|
|
181
|
+
const nodemailer = await __webpack_require__.e(/* import() */ 99).then(__webpack_require__.bind(__webpack_require__, 982));
|
|
182
|
+
this.transporter = nodemailer.createTransport({
|
|
183
|
+
host: config.host,
|
|
184
|
+
port: config.port,
|
|
185
|
+
secure: config.secure ?? config.port === 465,
|
|
186
|
+
auth: config.auth,
|
|
187
|
+
connectionTimeout: VERIFY_TIMEOUT_MS,
|
|
188
|
+
greetingTimeout: VERIFY_TIMEOUT_MS,
|
|
189
|
+
socketTimeout: SEND_TIMEOUT_MS,
|
|
190
|
+
tls: {
|
|
191
|
+
rejectUnauthorized: config.tls?.rejectUnauthorized ?? true,
|
|
192
|
+
minVersion: config.tls?.minVersion ?? 'TLSv1.2'
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
await this.withTimeout(this.transporter.verify(), VERIFY_TIMEOUT_MS, 'SMTP verification timeout');
|
|
196
|
+
}
|
|
197
|
+
async sendEmail(options) {
|
|
198
|
+
if (!this.transporter) return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: 'SMTP provider not initialized'
|
|
201
|
+
};
|
|
202
|
+
try {
|
|
203
|
+
const mailOptions = {
|
|
204
|
+
from: this.formatFrom(options.from, options.fromName),
|
|
205
|
+
to: this.joinAddresses(options.to),
|
|
206
|
+
cc: options.cc ? this.joinAddresses(options.cc) : undefined,
|
|
207
|
+
bcc: options.bcc ? this.joinAddresses(options.bcc) : undefined,
|
|
208
|
+
subject: options.subject,
|
|
209
|
+
text: options.text,
|
|
210
|
+
html: options.html,
|
|
211
|
+
replyTo: options.replyTo,
|
|
212
|
+
attachments: options.attachments?.map((a)=>({
|
|
213
|
+
filename: a.filename,
|
|
214
|
+
content: a.content,
|
|
215
|
+
contentType: a.contentType,
|
|
216
|
+
encoding: a.encoding
|
|
217
|
+
}))
|
|
218
|
+
};
|
|
219
|
+
const info = await this.withTimeout(this.transporter.sendMail(mailOptions), SEND_TIMEOUT_MS, 'SMTP send timeout');
|
|
220
|
+
return {
|
|
221
|
+
success: true,
|
|
222
|
+
messageId: info.messageId
|
|
223
|
+
};
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
error: this.extractError(error)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async sendBulkEmails(options) {
|
|
232
|
+
return Promise.all(options.map((opt)=>this.sendEmail(opt)));
|
|
233
|
+
}
|
|
234
|
+
async healthCheck() {
|
|
235
|
+
if (!this.transporter) return false;
|
|
236
|
+
try {
|
|
237
|
+
await this.transporter.verify();
|
|
238
|
+
return true;
|
|
239
|
+
} catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async close() {
|
|
244
|
+
if (this.transporter) {
|
|
245
|
+
this.transporter.close();
|
|
246
|
+
this.transporter = null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
250
|
+
formatFrom(from, fromName) {
|
|
251
|
+
return fromName ? `"${fromName}" <${from}>` : from;
|
|
252
|
+
}
|
|
253
|
+
joinAddresses(addresses) {
|
|
254
|
+
return Array.isArray(addresses) ? addresses.join(', ') : addresses;
|
|
255
|
+
}
|
|
256
|
+
async withTimeout(promise, ms, message) {
|
|
257
|
+
let timer;
|
|
258
|
+
const timeout = new Promise((_, reject)=>{
|
|
259
|
+
timer = setTimeout(()=>reject(new Error(message)), ms);
|
|
260
|
+
});
|
|
261
|
+
try {
|
|
262
|
+
return await Promise.race([
|
|
263
|
+
promise,
|
|
264
|
+
timeout
|
|
265
|
+
]);
|
|
266
|
+
} finally{
|
|
267
|
+
clearTimeout(timer);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
extractError(error) {
|
|
271
|
+
return error instanceof Error ? error.message : 'Unknown error';
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/constants"
|
|
276
|
+
|
|
277
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/utils"
|
|
278
|
+
var utils_ = __webpack_require__(216);
|
|
279
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/sendgrid-provider.ts
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class SendGridProvider {
|
|
284
|
+
sgMail = null;
|
|
285
|
+
apiKey = null;
|
|
286
|
+
async initialize(config) {
|
|
287
|
+
this.apiKey = config.apiKey;
|
|
288
|
+
try {
|
|
289
|
+
// Optional peer dependency - loaded at runtime so bundlers don't statically resolve it
|
|
290
|
+
const sgMailModule = await (0,utils_.loadOptionalModule)('@sendgrid/mail');
|
|
291
|
+
this.sgMail = sgMailModule.default || sgMailModule;
|
|
292
|
+
this.sgMail.setApiKey(config.apiKey);
|
|
293
|
+
} catch {
|
|
294
|
+
throw new common_.InternalServerErrorException({
|
|
295
|
+
message: 'SendGrid initialization failed. Install: npm install @sendgrid/mail',
|
|
296
|
+
messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
|
|
297
|
+
messageVariables: {
|
|
298
|
+
sdk: 'sendgrid'
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async sendEmail(options) {
|
|
304
|
+
if (!this.sgMail) return {
|
|
305
|
+
success: false,
|
|
306
|
+
error: 'SendGrid provider not initialized'
|
|
307
|
+
};
|
|
308
|
+
try {
|
|
309
|
+
const msg = this.buildMessage(options, true);
|
|
310
|
+
const [response] = await this.sgMail.send(msg);
|
|
311
|
+
const messageId = response.headers['x-message-id'] || response.headers['X-Message-Id'];
|
|
312
|
+
return {
|
|
313
|
+
success: true,
|
|
314
|
+
messageId
|
|
315
|
+
};
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
error: this.extractError(error)
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async sendBulkEmails(options) {
|
|
324
|
+
if (!this.sgMail) return options.map(()=>({
|
|
325
|
+
success: false,
|
|
326
|
+
error: 'SendGrid provider not initialized'
|
|
327
|
+
}));
|
|
328
|
+
try {
|
|
329
|
+
const messages = options.map((opt)=>this.buildMessage(opt, false));
|
|
330
|
+
await this.sgMail.send(messages);
|
|
331
|
+
return options.map(()=>({
|
|
332
|
+
success: true
|
|
333
|
+
}));
|
|
334
|
+
} catch (error) {
|
|
335
|
+
const errorMessage = this.extractError(error);
|
|
336
|
+
return options.map(()=>({
|
|
337
|
+
success: false,
|
|
338
|
+
error: errorMessage
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
async healthCheck() {
|
|
343
|
+
return !!(this.sgMail && this.apiKey?.startsWith('SG.'));
|
|
344
|
+
}
|
|
345
|
+
async close() {
|
|
346
|
+
this.sgMail = null;
|
|
347
|
+
}
|
|
348
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
349
|
+
buildMessage(options, includeExtras) {
|
|
350
|
+
const msg = {
|
|
351
|
+
to: this.toArray(options.to),
|
|
352
|
+
from: options.fromName ? {
|
|
353
|
+
email: options.from,
|
|
354
|
+
name: options.fromName
|
|
355
|
+
} : options.from,
|
|
356
|
+
subject: options.subject
|
|
357
|
+
};
|
|
358
|
+
if (options.html) msg.html = options.html;
|
|
359
|
+
if (options.text) msg.text = options.text;
|
|
360
|
+
if (includeExtras) {
|
|
361
|
+
if (options.cc) msg.cc = this.toArray(options.cc);
|
|
362
|
+
if (options.bcc) msg.bcc = this.toArray(options.bcc);
|
|
363
|
+
if (options.replyTo) msg.replyTo = options.replyTo;
|
|
364
|
+
if (options.attachments?.length) {
|
|
365
|
+
msg.attachments = options.attachments.map((a)=>({
|
|
366
|
+
filename: a.filename,
|
|
367
|
+
content: typeof a.content === 'string' ? a.content : a.content.toString('base64'),
|
|
368
|
+
type: a.contentType,
|
|
369
|
+
disposition: 'attachment'
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return msg;
|
|
374
|
+
}
|
|
375
|
+
toArray(value) {
|
|
376
|
+
return Array.isArray(value) ? value : [
|
|
377
|
+
value
|
|
378
|
+
];
|
|
379
|
+
}
|
|
380
|
+
extractError(error) {
|
|
381
|
+
const sgError = error;
|
|
382
|
+
return sgError.response?.body?.errors?.[0]?.message || sgError.message || 'Unknown error';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/mailgun-provider.ts
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
const MAILGUN_API_URL = 'https://api.mailgun.net';
|
|
391
|
+
const MAILGUN_EU_API_URL = 'https://api.eu.mailgun.net';
|
|
392
|
+
class MailgunProvider {
|
|
393
|
+
client = null;
|
|
394
|
+
domain = null;
|
|
395
|
+
async initialize(config) {
|
|
396
|
+
this.domain = config.domain;
|
|
397
|
+
try {
|
|
398
|
+
// Optional peer dependency - loaded at runtime so bundlers don't statically resolve it
|
|
399
|
+
const mailgunModule = await (0,utils_.loadOptionalModule)('mailgun.js');
|
|
400
|
+
const formDataModule = await (0,utils_.loadOptionalModule)('form-data');
|
|
401
|
+
const Mailgun = mailgunModule.default || mailgunModule;
|
|
402
|
+
const FormData = formDataModule.default || formDataModule;
|
|
403
|
+
const mailgun = new Mailgun(FormData);
|
|
404
|
+
const url = config.region === 'eu' ? MAILGUN_EU_API_URL : MAILGUN_API_URL;
|
|
405
|
+
this.client = mailgun.client({
|
|
406
|
+
username: 'api',
|
|
407
|
+
key: config.apiKey,
|
|
408
|
+
url
|
|
409
|
+
});
|
|
410
|
+
} catch {
|
|
411
|
+
throw new common_.InternalServerErrorException({
|
|
412
|
+
message: 'Mailgun initialization failed. Install: npm install mailgun.js form-data',
|
|
413
|
+
messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
|
|
414
|
+
messageVariables: {
|
|
415
|
+
sdk: 'mailgun'
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async sendEmail(options) {
|
|
421
|
+
if (!this.client || !this.domain) {
|
|
422
|
+
return {
|
|
423
|
+
success: false,
|
|
424
|
+
error: 'Mailgun provider not initialized'
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const messageData = this.buildMessageData(options);
|
|
429
|
+
const result = await this.client.messages.create(this.domain, messageData);
|
|
430
|
+
return {
|
|
431
|
+
success: true,
|
|
432
|
+
messageId: result.id
|
|
433
|
+
};
|
|
434
|
+
} catch (error) {
|
|
435
|
+
return {
|
|
436
|
+
success: false,
|
|
437
|
+
error: this.extractError(error)
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
async sendBulkEmails(options) {
|
|
442
|
+
return Promise.all(options.map((opt)=>this.sendEmail(opt)));
|
|
443
|
+
}
|
|
444
|
+
async healthCheck() {
|
|
445
|
+
if (!this.client || !this.domain) return false;
|
|
446
|
+
try {
|
|
447
|
+
await this.client.domains.get(this.domain);
|
|
448
|
+
return true;
|
|
449
|
+
} catch {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async close() {
|
|
454
|
+
this.client = null;
|
|
455
|
+
}
|
|
456
|
+
// ─── Private Helpers ────────────────────────────────────────────────────────
|
|
457
|
+
buildMessageData(options) {
|
|
458
|
+
const data = {
|
|
459
|
+
from: options.fromName ? `${options.fromName} <${options.from}>` : options.from,
|
|
460
|
+
to: this.joinAddresses(options.to),
|
|
461
|
+
subject: options.subject
|
|
462
|
+
};
|
|
463
|
+
if (options.html) data.html = options.html;
|
|
464
|
+
if (options.text) data.text = options.text;
|
|
465
|
+
if (options.cc) data.cc = this.joinAddresses(options.cc);
|
|
466
|
+
if (options.bcc) data.bcc = this.joinAddresses(options.bcc);
|
|
467
|
+
if (options.replyTo) data['h:Reply-To'] = options.replyTo;
|
|
468
|
+
if (options.attachments?.length) {
|
|
469
|
+
data.attachment = options.attachments.map((a)=>({
|
|
470
|
+
filename: a.filename,
|
|
471
|
+
data: typeof a.content === 'string' ? Buffer.from(a.content, 'base64') : a.content,
|
|
472
|
+
contentType: a.contentType
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
return data;
|
|
476
|
+
}
|
|
477
|
+
joinAddresses(addresses) {
|
|
478
|
+
return Array.isArray(addresses) ? addresses.join(', ') : addresses;
|
|
479
|
+
}
|
|
480
|
+
extractError(error) {
|
|
481
|
+
return error instanceof Error ? error.message : 'Unknown error';
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/index.ts
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
},
|
|
494
|
+
422(module) {
|
|
495
|
+
|
|
496
|
+
module.exports = __rspack_external__flusys_nestjs_shared_393d2cae;
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
},
|
|
500
|
+
216(module) {
|
|
501
|
+
|
|
502
|
+
module.exports = __rspack_external__flusys_nestjs_shared_utils_9125c1f1;
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
},
|
|
506
|
+
157(module) {
|
|
507
|
+
|
|
508
|
+
module.exports = __rspack_external__nestjs_common_a04939da;
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
};
|
|
514
|
+
import { __webpack_require__ } from '../runtime.js';
|
|
515
|
+
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
|
|
516
|
+
import * as __rspack_chunk_1 from './index.js';
|
|
517
|
+
__webpack_require__.C(__rspack_chunk_1);
|
|
518
|
+
var __webpack_exports__ = __webpack_exec__(603);var __webpack_exports__EmailFactoryService = __webpack_exports__.c;
|
|
519
|
+
var __webpack_exports__EmailProviderRegistry = __webpack_exports__.xC;
|
|
520
|
+
var __webpack_exports__MailgunProvider = __webpack_exports__.Xp;
|
|
521
|
+
var __webpack_exports__SendGridProvider = __webpack_exports__.Iw;
|
|
522
|
+
var __webpack_exports__SmtpProvider = __webpack_exports__.Kg;
|
|
523
|
+
export { __webpack_exports__EmailFactoryService as EmailFactoryService, __webpack_exports__EmailProviderRegistry as EmailProviderRegistry, __webpack_exports__MailgunProvider as MailgunProvider, __webpack_exports__SendGridProvider as SendGridProvider, __webpack_exports__SmtpProvider as SmtpProvider };
|
package/fesm/runtime.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __webpack_modules__ = ({});
|
|
2
|
+
// The module cache
|
|
3
|
+
var __webpack_module_cache__ = {};
|
|
4
|
+
|
|
5
|
+
// The require function
|
|
6
|
+
function __webpack_require__(moduleId) {
|
|
7
|
+
|
|
8
|
+
// Check if module is in cache
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (cachedModule !== undefined) {
|
|
11
|
+
return cachedModule.exports;
|
|
12
|
+
}
|
|
13
|
+
// Create a new module (and put it into the cache)
|
|
14
|
+
var module = (__webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
});
|
|
17
|
+
// Execute the module function
|
|
18
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
19
|
+
|
|
20
|
+
// Return the exports of the module
|
|
21
|
+
return module.exports;
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// expose the modules object (__webpack_modules__)
|
|
26
|
+
__webpack_require__.m = __webpack_modules__;
|
|
27
|
+
|
|
28
|
+
// webpack/runtime/define_property_getters
|
|
29
|
+
(() => {
|
|
30
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
31
|
+
var define = (defs, kind) => {
|
|
32
|
+
for(var key in defs) {
|
|
33
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
34
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
define(getters, "get");
|
|
39
|
+
define(values, "value");
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
// webpack/runtime/ensure_chunk
|
|
43
|
+
(() => {
|
|
44
|
+
__webpack_require__.f = {};
|
|
45
|
+
// This file contains only the entry chunk.
|
|
46
|
+
// The chunk loading function for additional chunks
|
|
47
|
+
__webpack_require__.e = (chunkId) => {
|
|
48
|
+
return Promise.all(
|
|
49
|
+
Object.keys(__webpack_require__.f).reduce((promises, key) => {
|
|
50
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
51
|
+
return promises;
|
|
52
|
+
}, [])
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
// webpack/runtime/export_webpack_require
|
|
57
|
+
var __webpack_require__temp = __webpack_require__;
|
|
58
|
+
export { __webpack_require__temp as __webpack_require__ };
|
|
59
|
+
// webpack/runtime/get javascript chunk filename
|
|
60
|
+
(() => {
|
|
61
|
+
// This function allow to reference chunks
|
|
62
|
+
__webpack_require__.u = (chunkId) => {
|
|
63
|
+
// return url for filenames not based on template
|
|
64
|
+
|
|
65
|
+
// return url for filenames based on template
|
|
66
|
+
return "chunks/" + chunkId + ".js"
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
// webpack/runtime/has_own_property
|
|
70
|
+
(() => {
|
|
71
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
})();
|
|
73
|
+
// webpack/runtime/module_chunk_loading
|
|
74
|
+
(() => {
|
|
75
|
+
// no BaseURI
|
|
76
|
+
// object to store loaded and loading chunks
|
|
77
|
+
// undefined = chunk not loaded, null = chunk preloaded/prefetched
|
|
78
|
+
// [resolve, Promise] = chunk loading, 0 = chunk loaded
|
|
79
|
+
var moduleInstalledChunks = {146: 0,};
|
|
80
|
+
var moduleInstallChunk = (data) => {
|
|
81
|
+
var __rspack_esm_ids = data.__rspack_esm_ids;
|
|
82
|
+
var moreModules = data.__webpack_modules__;
|
|
83
|
+
var __rspack_esm_runtime = data.__rspack_esm_runtime;
|
|
84
|
+
// add "modules" to the modules object,
|
|
85
|
+
// then flag all "ids" as loaded and fire callback
|
|
86
|
+
var moduleId, chunkId, i = 0;
|
|
87
|
+
for (moduleId in moreModules) {
|
|
88
|
+
if (__webpack_require__.o(moreModules, moduleId)) {
|
|
89
|
+
__webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__);
|
|
93
|
+
for (; i < __rspack_esm_ids.length; i++) {
|
|
94
|
+
chunkId = __rspack_esm_ids[i];
|
|
95
|
+
if (__webpack_require__.o(moduleInstalledChunks, chunkId) && moduleInstalledChunks[chunkId]) {
|
|
96
|
+
moduleInstalledChunks[chunkId][0]();
|
|
97
|
+
}
|
|
98
|
+
moduleInstalledChunks[__rspack_esm_ids[i]] = 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
__webpack_require__.f.j = function (chunkId, promises) {
|
|
104
|
+
// import() chunk loading for javascript
|
|
105
|
+
var installedChunkData = __webpack_require__.o(moduleInstalledChunks, chunkId) ? moduleInstalledChunks[chunkId] : undefined;
|
|
106
|
+
if (installedChunkData !== 0) { // 0 means "already installed".'
|
|
107
|
+
// a Promise means "currently loading".
|
|
108
|
+
if (installedChunkData) {
|
|
109
|
+
promises.push(installedChunkData[1]);
|
|
110
|
+
} else {
|
|
111
|
+
if (146 != chunkId) {
|
|
112
|
+
// setup Promise in chunk cache
|
|
113
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(moduleInstallChunk, (e) => {
|
|
114
|
+
if (moduleInstalledChunks[chunkId] !== 0) moduleInstalledChunks[chunkId] = undefined;
|
|
115
|
+
throw e;
|
|
116
|
+
});
|
|
117
|
+
var promise = Promise.race([promise, new Promise((resolve) => {
|
|
118
|
+
installedChunkData = moduleInstalledChunks[chunkId] = [resolve];
|
|
119
|
+
})]);
|
|
120
|
+
promises.push(installedChunkData[1] = promise);
|
|
121
|
+
}
|
|
122
|
+
else moduleInstalledChunks[chunkId] = 0;
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
__webpack_require__.C = moduleInstallChunk;
|
|
130
|
+
// no on chunks loaded
|
|
131
|
+
// no HMR
|
|
132
|
+
// no HMR manifest
|
|
133
|
+
|
|
134
|
+
})();
|
package/fesm/services/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const __rspack_esm_id = 995;
|
|
2
|
+
export const __rspack_esm_ids = [995];
|
|
3
|
+
export const __webpack_modules__ = {};
|
|
4
|
+
import { __webpack_require__ } from '../runtime.js';
|
|
5
|
+
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
|
|
6
|
+
import * as __rspack_chunk_1 from '../261.js';
|
|
7
|
+
__webpack_require__.C(__rspack_chunk_1);
|
|
8
|
+
import * as __rspack_chunk_2 from '../493.js';
|
|
9
|
+
__webpack_require__.C(__rspack_chunk_2);
|
|
10
|
+
import * as __rspack_chunk_3 from './index.js';
|
|
11
|
+
__webpack_require__.C(__rspack_chunk_3);
|
|
12
|
+
var __webpack_exports__ = __webpack_exec__(676);var __webpack_exports__EmailConfigService = __webpack_exports__.mi;
|
|
13
|
+
var __webpack_exports__EmailDataSourceProvider = __webpack_exports__.Zt;
|
|
14
|
+
var __webpack_exports__EmailProviderConfigService = __webpack_exports__.jG;
|
|
15
|
+
var __webpack_exports__EmailSendService = __webpack_exports__.yu;
|
|
16
|
+
var __webpack_exports__EmailTemplateService = __webpack_exports__.uS;
|
|
17
|
+
export { __webpack_exports__EmailConfigService as EmailConfigService, __webpack_exports__EmailDataSourceProvider as EmailDataSourceProvider, __webpack_exports__EmailProviderConfigService as EmailProviderConfigService, __webpack_exports__EmailSendService as EmailSendService, __webpack_exports__EmailTemplateService as EmailTemplateService };
|