@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
package/fesm/493.js ADDED
@@ -0,0 +1,1723 @@
1
+ import { Identity } from "@flusys/nestjs-shared/entities";
2
+ import { createHash } from "crypto";
3
+ import { SYSTEM_MESSAGES } from "@flusys/nestjs-shared/constants";
4
+ import * as __rspack_external__flusys_nestjs_shared_393d2cae from "@flusys/nestjs-shared";
5
+ import * as __rspack_external__flusys_nestjs_shared_classes_6076a329 from "@flusys/nestjs-shared/classes";
6
+ import * as __rspack_external__flusys_nestjs_shared_modules_24702bee from "@flusys/nestjs-shared/modules";
7
+ import * as __rspack_external__flusys_nestjs_shared_utils_9125c1f1 from "@flusys/nestjs-shared/utils";
8
+ import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
9
+ import * as __rspack_external_typeorm from "typeorm";
10
+ import * as __rspack_external__nestjs_core_d7b00a1a from "@nestjs/core";
11
+ export const __rspack_esm_id = 493;
12
+ export const __rspack_esm_ids = [493];
13
+ export const __webpack_modules__ = {
14
+ 966(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
15
+ /**
16
+ * Email Module Constants
17
+ */ const EMAIL_MODULE_OPTIONS = 'EMAIL_MODULE_OPTIONS';
18
+ const DEFAULT_FROM_NAME = 'FLUSYS';
19
+
20
+ __webpack_require__.d(__webpack_exports__, {
21
+ }, {
22
+ F: EMAIL_MODULE_OPTIONS
23
+ });
24
+
25
+
26
+ },
27
+ 399(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
28
+ /**
29
+ * Domain event actions published by the email module, alongside the CRUD
30
+ * lifecycle actions every ApiService emits.
31
+ */ const EMAIL_EVENT_ACTIONS = {
32
+ SENT: 'sent',
33
+ FAILED: 'failed'
34
+ };
35
+ /** Every entity the email module publishes under, ApiService backed or not */ const EMAIL_EVENT_ENTITIES = {
36
+ MESSAGE: 'email_message',
37
+ CONFIG: 'emailConfig',
38
+ TEMPLATE: 'emailTemplate'
39
+ };
40
+ const EMAIL_EVENT_MODULE = 'email';
41
+
42
+ __webpack_require__.d(__webpack_exports__, {
43
+ }, {
44
+ C: EMAIL_EVENT_ACTIONS,
45
+ y: EMAIL_EVENT_ENTITIES
46
+ });
47
+
48
+
49
+ },
50
+ 887(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
51
+ // ==================== EMAIL MODULE MESSAGE KEYS ====================
52
+ const EMAIL_TEMPLATE_MESSAGES = {
53
+ GET_SUCCESS: 'email.template.get.success',
54
+ NOT_FOUND: 'email.template.not.found'
55
+ };
56
+ const EMAIL_CONFIG_MESSAGES = {
57
+ DEFAULT_DELETE_FORBIDDEN: 'email.config.default.delete.forbidden'
58
+ };
59
+ const EMAIL_SEND_MESSAGES = {
60
+ SUCCESS: 'email.send.success',
61
+ FAILED: 'email.send.failed',
62
+ CONFIG_NOT_FOUND: 'email.send.config.not.found',
63
+ CONFIG_INACTIVE: 'email.send.config.inactive',
64
+ CONFIG_DEFAULT_NOT_FOUND: 'email.send.config.default.not.found',
65
+ TEMPLATE_NOT_FOUND: 'email.send.template.not.found',
66
+ TEMPLATE_INACTIVE: 'email.send.template.inactive',
67
+ TEMPLATE_ID_OR_SLUG_REQUIRED: 'email.send.template.id.or.slug.required'
68
+ };
69
+
70
+ __webpack_require__.d(__webpack_exports__, {
71
+ }, {
72
+ T6: EMAIL_CONFIG_MESSAGES,
73
+ dP: EMAIL_SEND_MESSAGES,
74
+ xP: EMAIL_TEMPLATE_MESSAGES
75
+ });
76
+
77
+
78
+ },
79
+ 454(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
80
+
81
+ // EXPORTS
82
+ __webpack_require__.d(__webpack_exports__, {
83
+ BC: () => (/* binding */ EmailCompanyEntities),
84
+ pG: () => (/* reexport */ EmailConfig),
85
+ Y5: () => (/* reexport */ EmailConfig),
86
+ Ed: () => (/* reexport */ EmailConfigWithCompany),
87
+ BZ: () => (/* binding */ EmailCoreEntities),
88
+ Fy: () => (/* reexport */ EmailTemplate),
89
+ An: () => (/* reexport */ EmailTemplate),
90
+ U7: () => (/* reexport */ EmailTemplateWithCompany),
91
+ B0: () => (/* binding */ getEmailEntitiesByConfig)
92
+ });
93
+
94
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared"
95
+ var nestjs_shared_ = __webpack_require__(422);
96
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared/entities"
97
+
98
+ // EXTERNAL MODULE: external "typeorm"
99
+ var external_typeorm_ = __webpack_require__(158);
100
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/entities/email-config.entity.ts
101
+ function _ts_decorate(decorators, target, key, desc) {
102
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
103
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
104
+ r = Reflect.decorate(decorators, target, key, desc);
105
+ } else {
106
+ for(var i = decorators.length - 1; i >= 0; i--){
107
+ if (d = decorators[i]) {
108
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
109
+ }
110
+ }
111
+ }
112
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
113
+ }
114
+ function _ts_metadata(metadataKey, metadataValue) {
115
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
116
+ return Reflect.metadata(metadataKey, metadataValue);
117
+ }
118
+ }
119
+
120
+
121
+
122
+ class EmailConfig extends Identity {
123
+ name;
124
+ provider;
125
+ config;
126
+ fromEmail;
127
+ fromName;
128
+ isActive;
129
+ isDefault;
130
+ }
131
+ _ts_decorate([
132
+ (0,external_typeorm_.Column)({
133
+ type: 'varchar',
134
+ length: 255,
135
+ nullable: false
136
+ }),
137
+ _ts_metadata("design:type", String)
138
+ ], EmailConfig.prototype, "name", void 0);
139
+ _ts_decorate([
140
+ (0,external_typeorm_.Column)({
141
+ type: 'varchar',
142
+ length: 50,
143
+ nullable: false
144
+ }),
145
+ _ts_metadata("design:type", String)
146
+ ], EmailConfig.prototype, "provider", void 0);
147
+ _ts_decorate([
148
+ (0,external_typeorm_.Column)({
149
+ type: (0,nestjs_shared_.getJsonColumnType)(),
150
+ nullable: false
151
+ }),
152
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
153
+ ], EmailConfig.prototype, "config", void 0);
154
+ _ts_decorate([
155
+ (0,external_typeorm_.Column)({
156
+ type: 'varchar',
157
+ length: 255,
158
+ nullable: true,
159
+ name: 'from_email'
160
+ }),
161
+ _ts_metadata("design:type", Object)
162
+ ], EmailConfig.prototype, "fromEmail", void 0);
163
+ _ts_decorate([
164
+ (0,external_typeorm_.Column)({
165
+ type: 'varchar',
166
+ length: 255,
167
+ nullable: true,
168
+ name: 'from_name'
169
+ }),
170
+ _ts_metadata("design:type", Object)
171
+ ], EmailConfig.prototype, "fromName", void 0);
172
+ _ts_decorate([
173
+ (0,external_typeorm_.Column)({
174
+ type: 'boolean',
175
+ default: true,
176
+ name: 'is_active'
177
+ }),
178
+ _ts_metadata("design:type", Boolean)
179
+ ], EmailConfig.prototype, "isActive", void 0);
180
+ _ts_decorate([
181
+ (0,external_typeorm_.Column)({
182
+ type: 'boolean',
183
+ default: false,
184
+ name: 'is_default'
185
+ }),
186
+ _ts_metadata("design:type", Boolean)
187
+ ], EmailConfig.prototype, "isDefault", void 0);
188
+ EmailConfig = _ts_decorate([
189
+ (0,external_typeorm_.Entity)({
190
+ name: 'email_config'
191
+ }),
192
+ (0,external_typeorm_.Index)([
193
+ 'name'
194
+ ]),
195
+ (0,external_typeorm_.Index)([
196
+ 'provider'
197
+ ]),
198
+ (0,external_typeorm_.Index)([
199
+ 'isActive'
200
+ ]),
201
+ (0,external_typeorm_.Index)([
202
+ 'isDefault'
203
+ ])
204
+ ], EmailConfig);
205
+
206
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/entities/email-template.entity.ts
207
+ function email_template_entity_ts_decorate(decorators, target, key, desc) {
208
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
209
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
210
+ r = Reflect.decorate(decorators, target, key, desc);
211
+ } else {
212
+ for(var i = decorators.length - 1; i >= 0; i--){
213
+ if (d = decorators[i]) {
214
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
215
+ }
216
+ }
217
+ }
218
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
219
+ }
220
+ function email_template_entity_ts_metadata(metadataKey, metadataValue) {
221
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
222
+ return Reflect.metadata(metadataKey, metadataValue);
223
+ }
224
+ }
225
+
226
+
227
+
228
+ class EmailTemplate extends Identity {
229
+ name;
230
+ slug;
231
+ description;
232
+ subject;
233
+ schema;
234
+ htmlContent;
235
+ textContent;
236
+ schemaVersion;
237
+ isActive;
238
+ isHtml;
239
+ }
240
+ email_template_entity_ts_decorate([
241
+ (0,external_typeorm_.Column)({
242
+ type: 'varchar',
243
+ length: 255,
244
+ nullable: false
245
+ }),
246
+ email_template_entity_ts_metadata("design:type", String)
247
+ ], EmailTemplate.prototype, "name", void 0);
248
+ email_template_entity_ts_decorate([
249
+ (0,external_typeorm_.Column)({
250
+ type: 'varchar',
251
+ length: 255,
252
+ nullable: false
253
+ }),
254
+ email_template_entity_ts_metadata("design:type", String)
255
+ ], EmailTemplate.prototype, "slug", void 0);
256
+ email_template_entity_ts_decorate([
257
+ (0,external_typeorm_.Column)({
258
+ type: 'varchar',
259
+ length: 500,
260
+ nullable: true
261
+ }),
262
+ email_template_entity_ts_metadata("design:type", Object)
263
+ ], EmailTemplate.prototype, "description", void 0);
264
+ email_template_entity_ts_decorate([
265
+ (0,external_typeorm_.Column)({
266
+ type: 'varchar',
267
+ length: 500,
268
+ nullable: false
269
+ }),
270
+ email_template_entity_ts_metadata("design:type", String)
271
+ ], EmailTemplate.prototype, "subject", void 0);
272
+ email_template_entity_ts_decorate([
273
+ (0,external_typeorm_.Column)({
274
+ type: (0,nestjs_shared_.getJsonColumnType)(),
275
+ nullable: false
276
+ }),
277
+ email_template_entity_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
278
+ ], EmailTemplate.prototype, "schema", void 0);
279
+ email_template_entity_ts_decorate([
280
+ (0,external_typeorm_.Column)({
281
+ type: 'text',
282
+ nullable: false,
283
+ name: 'html_content'
284
+ }),
285
+ email_template_entity_ts_metadata("design:type", String)
286
+ ], EmailTemplate.prototype, "htmlContent", void 0);
287
+ email_template_entity_ts_decorate([
288
+ (0,external_typeorm_.Column)({
289
+ type: 'text',
290
+ nullable: true,
291
+ name: 'text_content'
292
+ }),
293
+ email_template_entity_ts_metadata("design:type", Object)
294
+ ], EmailTemplate.prototype, "textContent", void 0);
295
+ email_template_entity_ts_decorate([
296
+ (0,external_typeorm_.Column)({
297
+ type: 'int',
298
+ nullable: false,
299
+ default: 1,
300
+ name: 'schema_version'
301
+ }),
302
+ email_template_entity_ts_metadata("design:type", Number)
303
+ ], EmailTemplate.prototype, "schemaVersion", void 0);
304
+ email_template_entity_ts_decorate([
305
+ (0,external_typeorm_.Column)({
306
+ type: 'boolean',
307
+ default: true,
308
+ name: 'is_active'
309
+ }),
310
+ email_template_entity_ts_metadata("design:type", Boolean)
311
+ ], EmailTemplate.prototype, "isActive", void 0);
312
+ email_template_entity_ts_decorate([
313
+ (0,external_typeorm_.Column)({
314
+ type: 'boolean',
315
+ default: true,
316
+ name: 'is_html'
317
+ }),
318
+ email_template_entity_ts_metadata("design:type", Boolean)
319
+ ], EmailTemplate.prototype, "isHtml", void 0);
320
+ EmailTemplate = email_template_entity_ts_decorate([
321
+ (0,external_typeorm_.Entity)({
322
+ name: 'email_template'
323
+ }),
324
+ (0,external_typeorm_.Index)([
325
+ 'name'
326
+ ]),
327
+ (0,external_typeorm_.Index)([
328
+ 'slug'
329
+ ], {
330
+ unique: true
331
+ }),
332
+ (0,external_typeorm_.Index)([
333
+ 'isActive'
334
+ ])
335
+ ], EmailTemplate);
336
+
337
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/entities/email-config-with-company.entity.ts
338
+ function email_config_with_company_entity_ts_decorate(decorators, target, key, desc) {
339
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
340
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
341
+ r = Reflect.decorate(decorators, target, key, desc);
342
+ } else {
343
+ for(var i = decorators.length - 1; i >= 0; i--){
344
+ if (d = decorators[i]) {
345
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
346
+ }
347
+ }
348
+ }
349
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
350
+ }
351
+ function email_config_with_company_entity_ts_metadata(metadataKey, metadataValue) {
352
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
353
+ return Reflect.metadata(metadataKey, metadataValue);
354
+ }
355
+ }
356
+
357
+
358
+ class EmailConfigWithCompany extends EmailConfig {
359
+ companyId;
360
+ }
361
+ email_config_with_company_entity_ts_decorate([
362
+ (0,external_typeorm_.Column)({
363
+ type: 'uuid',
364
+ nullable: true,
365
+ name: 'company_id'
366
+ }),
367
+ email_config_with_company_entity_ts_metadata("design:type", Object)
368
+ ], EmailConfigWithCompany.prototype, "companyId", void 0);
369
+ EmailConfigWithCompany = email_config_with_company_entity_ts_decorate([
370
+ (0,external_typeorm_.Entity)({
371
+ name: 'email_config'
372
+ }),
373
+ (0,external_typeorm_.Index)([
374
+ 'companyId'
375
+ ]),
376
+ (0,external_typeorm_.Index)([
377
+ 'companyId',
378
+ 'name'
379
+ ]),
380
+ (0,external_typeorm_.Index)([
381
+ 'companyId',
382
+ 'isActive'
383
+ ])
384
+ ], EmailConfigWithCompany);
385
+
386
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/entities/email-template-with-company.entity.ts
387
+ function email_template_with_company_entity_ts_decorate(decorators, target, key, desc) {
388
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
389
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
390
+ r = Reflect.decorate(decorators, target, key, desc);
391
+ } else {
392
+ for(var i = decorators.length - 1; i >= 0; i--){
393
+ if (d = decorators[i]) {
394
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
395
+ }
396
+ }
397
+ }
398
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
399
+ }
400
+ function email_template_with_company_entity_ts_metadata(metadataKey, metadataValue) {
401
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
402
+ return Reflect.metadata(metadataKey, metadataValue);
403
+ }
404
+ }
405
+
406
+
407
+ class EmailTemplateWithCompany extends EmailTemplate {
408
+ companyId;
409
+ }
410
+ email_template_with_company_entity_ts_decorate([
411
+ (0,external_typeorm_.Column)({
412
+ type: 'uuid',
413
+ nullable: true,
414
+ name: 'company_id'
415
+ }),
416
+ email_template_with_company_entity_ts_metadata("design:type", Object)
417
+ ], EmailTemplateWithCompany.prototype, "companyId", void 0);
418
+ EmailTemplateWithCompany = email_template_with_company_entity_ts_decorate([
419
+ (0,external_typeorm_.Entity)({
420
+ name: 'email_template'
421
+ }),
422
+ (0,external_typeorm_.Index)([
423
+ 'companyId'
424
+ ]),
425
+ (0,external_typeorm_.Index)([
426
+ 'companyId',
427
+ 'slug'
428
+ ], {
429
+ unique: true
430
+ }),
431
+ (0,external_typeorm_.Index)([
432
+ 'companyId',
433
+ 'isActive'
434
+ ])
435
+ ], EmailTemplateWithCompany);
436
+
437
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/entities/index.ts
438
+ // Entities without company feature
439
+
440
+
441
+ // Entities with company feature
442
+
443
+
444
+
445
+
446
+
447
+
448
+ // Core entities (no company feature)
449
+ const EmailCoreEntities = [
450
+ EmailConfig,
451
+ EmailTemplate
452
+ ];
453
+ // Company-specific entities
454
+ const EmailCompanyEntities = [
455
+ EmailConfigWithCompany,
456
+ EmailTemplateWithCompany
457
+ ];
458
+ function getEmailEntitiesByConfig(enableCompanyFeature) {
459
+ return enableCompanyFeature ? EmailCompanyEntities : EmailCoreEntities;
460
+ }
461
+ // Base type aliases for backwards compatibility with services
462
+
463
+
464
+
465
+
466
+ },
467
+ 603(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
468
+
469
+ // EXPORTS
470
+ __webpack_require__.d(__webpack_exports__, {
471
+ c: () => (/* reexport */ EmailFactoryService),
472
+ xC: () => (/* reexport */ EmailProviderRegistry),
473
+ Xp: () => (/* reexport */ MailgunProvider),
474
+ Iw: () => (/* reexport */ SendGridProvider),
475
+ Kg: () => (/* reexport */ SmtpProvider)
476
+ });
477
+
478
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/email-provider.registry.ts
479
+ class EmailProviderRegistry {
480
+ static providers = new Map();
481
+ static register(providerName, providerClass) {
482
+ this.providers.set(providerName.toLowerCase(), providerClass);
483
+ }
484
+ static get(providerName) {
485
+ return this.providers.get(providerName.toLowerCase());
486
+ }
487
+ static has(providerName) {
488
+ return this.providers.has(providerName.toLowerCase());
489
+ }
490
+ static getAll() {
491
+ return Array.from(this.providers.keys());
492
+ }
493
+ static clear() {
494
+ this.providers.clear();
495
+ }
496
+ }
497
+
498
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared"
499
+ var nestjs_shared_ = __webpack_require__(422);
500
+ // EXTERNAL MODULE: external "@nestjs/common"
501
+ var common_ = __webpack_require__(157);
502
+ ;// CONCATENATED MODULE: external "crypto"
503
+
504
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/config/message-keys.ts
505
+ var message_keys = __webpack_require__(887);
506
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/email-factory.service.ts
507
+ function _ts_decorate(decorators, target, key, desc) {
508
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
509
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
510
+ r = Reflect.decorate(decorators, target, key, desc);
511
+ } else {
512
+ for(var i = decorators.length - 1; i >= 0; i--){
513
+ if (d = decorators[i]) {
514
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
515
+ }
516
+ }
517
+ }
518
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
519
+ }
520
+ function _ts_metadata(metadataKey, metadataValue) {
521
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
522
+ return Reflect.metadata(metadataKey, metadataValue);
523
+ }
524
+ }
525
+
526
+
527
+
528
+
529
+
530
+ class EmailFactoryService {
531
+ providerCache = new Map();
532
+ // ─── Public API ─────────────────────────────────────────────────────────────
533
+ async createProvider(config) {
534
+ const cacheKey = this.generateCacheKey(config);
535
+ const cached = this.providerCache.get(cacheKey);
536
+ if (cached) return cached;
537
+ const ProviderClass = EmailProviderRegistry.get(config.provider);
538
+ if (!ProviderClass) {
539
+ throw new common_.NotFoundException({
540
+ message: `Email provider '${config.provider}' is not registered`,
541
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.CONFIG_NOT_FOUND */.dP.CONFIG_NOT_FOUND,
542
+ messageVariables: {
543
+ provider: config.provider,
544
+ available: EmailProviderRegistry.getAll().join(', ')
545
+ }
546
+ });
547
+ }
548
+ try {
549
+ const instance = new ProviderClass();
550
+ await instance.initialize?.(config.config);
551
+ this.providerCache.set(cacheKey, instance);
552
+ return instance;
553
+ } catch (error) {
554
+ throw new common_.InternalServerErrorException({
555
+ message: `Email provider '${config.provider}' not initialized successfully: ${this.extractErrorMessage(error)}`,
556
+ messageKey: nestjs_shared_.SYSTEM_MESSAGES.SERVICE_NOT_AVAILABLE,
557
+ messageVariables: {
558
+ provider: config.provider,
559
+ available: EmailProviderRegistry.getAll().join(', ')
560
+ }
561
+ });
562
+ }
563
+ }
564
+ // ─── Lifecycle ──────────────────────────────────────────────────────────────
565
+ async onModuleDestroy() {
566
+ const closePromises = Array.from(this.providerCache.entries()).map(([, provider])=>this.closeProvider(provider));
567
+ await Promise.allSettled(closePromises);
568
+ this.providerCache.clear();
569
+ }
570
+ // ─── Private Helpers ────────────────────────────────────────────────────────
571
+ generateCacheKey(config) {
572
+ const sortedKeys = Object.keys(config.config || {}).sort();
573
+ const configString = JSON.stringify(config.config, sortedKeys);
574
+ const hash = createHash('sha256').update(configString).digest('hex').substring(0, 16);
575
+ return `${config.provider}-${hash}`;
576
+ }
577
+ async closeProvider(provider) {
578
+ if (!provider.close) return;
579
+ try {
580
+ await provider.close();
581
+ } catch {
582
+ // Silent failure
583
+ }
584
+ }
585
+ extractErrorMessage(error) {
586
+ return error instanceof Error ? error.message : 'Unknown error';
587
+ }
588
+ }
589
+ _ts_decorate([
590
+ (0,nestjs_shared_.LogAction)({
591
+ action: 'email.createProvider',
592
+ module: 'email'
593
+ }),
594
+ _ts_metadata("design:type", Function),
595
+ _ts_metadata("design:paramtypes", [
596
+ typeof IEmailProviderConfig === "undefined" ? Object : IEmailProviderConfig
597
+ ]),
598
+ _ts_metadata("design:returntype", Promise)
599
+ ], EmailFactoryService.prototype, "createProvider", null);
600
+ EmailFactoryService = _ts_decorate([
601
+ (0,common_.Injectable)()
602
+ ], EmailFactoryService);
603
+
604
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/smtp-provider.ts
605
+ const VERIFY_TIMEOUT_MS = 10_000;
606
+ const SEND_TIMEOUT_MS = 30_000;
607
+ class SmtpProvider {
608
+ transporter = null;
609
+ async initialize(config) {
610
+ const nodemailer = await __webpack_require__.e(/* import() */ 99).then(__webpack_require__.bind(__webpack_require__, 982));
611
+ this.transporter = nodemailer.createTransport({
612
+ host: config.host,
613
+ port: config.port,
614
+ secure: config.secure ?? config.port === 465,
615
+ auth: config.auth,
616
+ connectionTimeout: VERIFY_TIMEOUT_MS,
617
+ greetingTimeout: VERIFY_TIMEOUT_MS,
618
+ socketTimeout: SEND_TIMEOUT_MS,
619
+ tls: {
620
+ rejectUnauthorized: config.tls?.rejectUnauthorized ?? true,
621
+ minVersion: config.tls?.minVersion ?? 'TLSv1.2'
622
+ }
623
+ });
624
+ await this.withTimeout(this.transporter.verify(), VERIFY_TIMEOUT_MS, 'SMTP verification timeout');
625
+ }
626
+ async sendEmail(options) {
627
+ if (!this.transporter) return {
628
+ success: false,
629
+ error: 'SMTP provider not initialized'
630
+ };
631
+ try {
632
+ const mailOptions = {
633
+ from: this.formatFrom(options.from, options.fromName),
634
+ to: this.joinAddresses(options.to),
635
+ cc: options.cc ? this.joinAddresses(options.cc) : undefined,
636
+ bcc: options.bcc ? this.joinAddresses(options.bcc) : undefined,
637
+ subject: options.subject,
638
+ text: options.text,
639
+ html: options.html,
640
+ replyTo: options.replyTo,
641
+ attachments: options.attachments?.map((a)=>({
642
+ filename: a.filename,
643
+ content: a.content,
644
+ contentType: a.contentType,
645
+ encoding: a.encoding
646
+ }))
647
+ };
648
+ const info = await this.withTimeout(this.transporter.sendMail(mailOptions), SEND_TIMEOUT_MS, 'SMTP send timeout');
649
+ return {
650
+ success: true,
651
+ messageId: info.messageId
652
+ };
653
+ } catch (error) {
654
+ return {
655
+ success: false,
656
+ error: this.extractError(error)
657
+ };
658
+ }
659
+ }
660
+ async sendBulkEmails(options) {
661
+ return Promise.all(options.map((opt)=>this.sendEmail(opt)));
662
+ }
663
+ async healthCheck() {
664
+ if (!this.transporter) return false;
665
+ try {
666
+ await this.transporter.verify();
667
+ return true;
668
+ } catch {
669
+ return false;
670
+ }
671
+ }
672
+ async close() {
673
+ if (this.transporter) {
674
+ this.transporter.close();
675
+ this.transporter = null;
676
+ }
677
+ }
678
+ // ─── Private Helpers ────────────────────────────────────────────────────────
679
+ formatFrom(from, fromName) {
680
+ return fromName ? `"${fromName}" <${from}>` : from;
681
+ }
682
+ joinAddresses(addresses) {
683
+ return Array.isArray(addresses) ? addresses.join(', ') : addresses;
684
+ }
685
+ async withTimeout(promise, ms, message) {
686
+ let timer;
687
+ const timeout = new Promise((_, reject)=>{
688
+ timer = setTimeout(()=>reject(new Error(message)), ms);
689
+ });
690
+ try {
691
+ return await Promise.race([
692
+ promise,
693
+ timeout
694
+ ]);
695
+ } finally{
696
+ clearTimeout(timer);
697
+ }
698
+ }
699
+ extractError(error) {
700
+ return error instanceof Error ? error.message : 'Unknown error';
701
+ }
702
+ }
703
+
704
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared/constants"
705
+
706
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/utils"
707
+ var utils_ = __webpack_require__(216);
708
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/sendgrid-provider.ts
709
+
710
+
711
+
712
+ class SendGridProvider {
713
+ sgMail = null;
714
+ apiKey = null;
715
+ async initialize(config) {
716
+ this.apiKey = config.apiKey;
717
+ try {
718
+ // Optional peer dependency - loaded at runtime so bundlers don't statically resolve it
719
+ const sgMailModule = await (0,utils_.loadOptionalModule)('@sendgrid/mail');
720
+ this.sgMail = sgMailModule.default || sgMailModule;
721
+ this.sgMail.setApiKey(config.apiKey);
722
+ } catch {
723
+ throw new common_.InternalServerErrorException({
724
+ message: 'SendGrid initialization failed. Install: npm install @sendgrid/mail',
725
+ messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
726
+ messageVariables: {
727
+ sdk: 'sendgrid'
728
+ }
729
+ });
730
+ }
731
+ }
732
+ async sendEmail(options) {
733
+ if (!this.sgMail) return {
734
+ success: false,
735
+ error: 'SendGrid provider not initialized'
736
+ };
737
+ try {
738
+ const msg = this.buildMessage(options, true);
739
+ const [response] = await this.sgMail.send(msg);
740
+ const messageId = response.headers['x-message-id'] || response.headers['X-Message-Id'];
741
+ return {
742
+ success: true,
743
+ messageId
744
+ };
745
+ } catch (error) {
746
+ return {
747
+ success: false,
748
+ error: this.extractError(error)
749
+ };
750
+ }
751
+ }
752
+ async sendBulkEmails(options) {
753
+ if (!this.sgMail) return options.map(()=>({
754
+ success: false,
755
+ error: 'SendGrid provider not initialized'
756
+ }));
757
+ try {
758
+ const messages = options.map((opt)=>this.buildMessage(opt, false));
759
+ await this.sgMail.send(messages);
760
+ return options.map(()=>({
761
+ success: true
762
+ }));
763
+ } catch (error) {
764
+ const errorMessage = this.extractError(error);
765
+ return options.map(()=>({
766
+ success: false,
767
+ error: errorMessage
768
+ }));
769
+ }
770
+ }
771
+ async healthCheck() {
772
+ return !!(this.sgMail && this.apiKey?.startsWith('SG.'));
773
+ }
774
+ async close() {
775
+ this.sgMail = null;
776
+ }
777
+ // ─── Private Helpers ────────────────────────────────────────────────────────
778
+ buildMessage(options, includeExtras) {
779
+ const msg = {
780
+ to: this.toArray(options.to),
781
+ from: options.fromName ? {
782
+ email: options.from,
783
+ name: options.fromName
784
+ } : options.from,
785
+ subject: options.subject
786
+ };
787
+ if (options.html) msg.html = options.html;
788
+ if (options.text) msg.text = options.text;
789
+ if (includeExtras) {
790
+ if (options.cc) msg.cc = this.toArray(options.cc);
791
+ if (options.bcc) msg.bcc = this.toArray(options.bcc);
792
+ if (options.replyTo) msg.replyTo = options.replyTo;
793
+ if (options.attachments?.length) {
794
+ msg.attachments = options.attachments.map((a)=>({
795
+ filename: a.filename,
796
+ content: typeof a.content === 'string' ? a.content : a.content.toString('base64'),
797
+ type: a.contentType,
798
+ disposition: 'attachment'
799
+ }));
800
+ }
801
+ }
802
+ return msg;
803
+ }
804
+ toArray(value) {
805
+ return Array.isArray(value) ? value : [
806
+ value
807
+ ];
808
+ }
809
+ extractError(error) {
810
+ const sgError = error;
811
+ return sgError.response?.body?.errors?.[0]?.message || sgError.message || 'Unknown error';
812
+ }
813
+ }
814
+
815
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/mailgun-provider.ts
816
+
817
+
818
+
819
+ const MAILGUN_API_URL = 'https://api.mailgun.net';
820
+ const MAILGUN_EU_API_URL = 'https://api.eu.mailgun.net';
821
+ class MailgunProvider {
822
+ client = null;
823
+ domain = null;
824
+ async initialize(config) {
825
+ this.domain = config.domain;
826
+ try {
827
+ // Optional peer dependency - loaded at runtime so bundlers don't statically resolve it
828
+ const mailgunModule = await (0,utils_.loadOptionalModule)('mailgun.js');
829
+ const formDataModule = await (0,utils_.loadOptionalModule)('form-data');
830
+ const Mailgun = mailgunModule.default || mailgunModule;
831
+ const FormData = formDataModule.default || formDataModule;
832
+ const mailgun = new Mailgun(FormData);
833
+ const url = config.region === 'eu' ? MAILGUN_EU_API_URL : MAILGUN_API_URL;
834
+ this.client = mailgun.client({
835
+ username: 'api',
836
+ key: config.apiKey,
837
+ url
838
+ });
839
+ } catch {
840
+ throw new common_.InternalServerErrorException({
841
+ message: 'Mailgun initialization failed. Install: npm install mailgun.js form-data',
842
+ messageKey: SYSTEM_MESSAGES.SDK_NOT_INSTALLED,
843
+ messageVariables: {
844
+ sdk: 'mailgun'
845
+ }
846
+ });
847
+ }
848
+ }
849
+ async sendEmail(options) {
850
+ if (!this.client || !this.domain) {
851
+ return {
852
+ success: false,
853
+ error: 'Mailgun provider not initialized'
854
+ };
855
+ }
856
+ try {
857
+ const messageData = this.buildMessageData(options);
858
+ const result = await this.client.messages.create(this.domain, messageData);
859
+ return {
860
+ success: true,
861
+ messageId: result.id
862
+ };
863
+ } catch (error) {
864
+ return {
865
+ success: false,
866
+ error: this.extractError(error)
867
+ };
868
+ }
869
+ }
870
+ async sendBulkEmails(options) {
871
+ return Promise.all(options.map((opt)=>this.sendEmail(opt)));
872
+ }
873
+ async healthCheck() {
874
+ if (!this.client || !this.domain) return false;
875
+ try {
876
+ await this.client.domains.get(this.domain);
877
+ return true;
878
+ } catch {
879
+ return false;
880
+ }
881
+ }
882
+ async close() {
883
+ this.client = null;
884
+ }
885
+ // ─── Private Helpers ────────────────────────────────────────────────────────
886
+ buildMessageData(options) {
887
+ const data = {
888
+ from: options.fromName ? `${options.fromName} <${options.from}>` : options.from,
889
+ to: this.joinAddresses(options.to),
890
+ subject: options.subject
891
+ };
892
+ if (options.html) data.html = options.html;
893
+ if (options.text) data.text = options.text;
894
+ if (options.cc) data.cc = this.joinAddresses(options.cc);
895
+ if (options.bcc) data.bcc = this.joinAddresses(options.bcc);
896
+ if (options.replyTo) data['h:Reply-To'] = options.replyTo;
897
+ if (options.attachments?.length) {
898
+ data.attachment = options.attachments.map((a)=>({
899
+ filename: a.filename,
900
+ data: typeof a.content === 'string' ? Buffer.from(a.content, 'base64') : a.content,
901
+ contentType: a.contentType
902
+ }));
903
+ }
904
+ return data;
905
+ }
906
+ joinAddresses(addresses) {
907
+ return Array.isArray(addresses) ? addresses.join(', ') : addresses;
908
+ }
909
+ extractError(error) {
910
+ return error instanceof Error ? error.message : 'Unknown error';
911
+ }
912
+ }
913
+
914
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/providers/index.ts
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+ },
923
+ 676(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
924
+
925
+ // EXPORTS
926
+ __webpack_require__.d(__webpack_exports__, {
927
+ mi: () => (/* reexport */ EmailConfigService),
928
+ Zt: () => (/* reexport */ EmailDataSourceProvider),
929
+ jG: () => (/* reexport */ EmailProviderConfigService),
930
+ yu: () => (/* reexport */ EmailSendService),
931
+ uS: () => (/* reexport */ EmailTemplateService)
932
+ });
933
+
934
+ // EXTERNAL MODULE: external "@nestjs/common"
935
+ var common_ = __webpack_require__(157);
936
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/config/email.constants.ts
937
+ var email_constants = __webpack_require__(966);
938
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/email-config.service.ts
939
+ function _ts_decorate(decorators, target, key, desc) {
940
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
941
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
942
+ r = Reflect.decorate(decorators, target, key, desc);
943
+ } else {
944
+ for(var i = decorators.length - 1; i >= 0; i--){
945
+ if (d = decorators[i]) {
946
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
947
+ }
948
+ }
949
+ }
950
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
951
+ }
952
+ function _ts_metadata(metadataKey, metadataValue) {
953
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
954
+ return Reflect.metadata(metadataKey, metadataValue);
955
+ }
956
+ }
957
+ function _ts_param(paramIndex, decorator) {
958
+ return function(target, key) {
959
+ decorator(target, key, paramIndex);
960
+ };
961
+ }
962
+
963
+
964
+ class EmailConfigService {
965
+ options;
966
+ constructor(options){
967
+ this.options = options;
968
+ }
969
+ // ─── IModuleConfigService Implementation ────────────────────────────────────
970
+ isCompanyFeatureEnabled() {
971
+ return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
972
+ }
973
+ getDatabaseMode() {
974
+ return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
975
+ }
976
+ isMultiTenant() {
977
+ return this.getDatabaseMode() === 'multi-tenant';
978
+ }
979
+ // ─── Config Getters ─────────────────────────────────────────────────────────
980
+ getDefaultFromName() {
981
+ return (/* inlined export .DEFAULT_FROM_NAME */"FLUSYS");
982
+ }
983
+ getOptions() {
984
+ return this.options;
985
+ }
986
+ }
987
+ EmailConfigService = _ts_decorate([
988
+ (0,common_.Injectable)(),
989
+ _ts_param(0, (0,common_.Inject)(email_constants/* .EMAIL_MODULE_OPTIONS */.F)),
990
+ _ts_metadata("design:type", Function),
991
+ _ts_metadata("design:paramtypes", [
992
+ typeof EmailModuleOptions === "undefined" ? Object : EmailModuleOptions
993
+ ])
994
+ ], EmailConfigService);
995
+
996
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
997
+ var modules_ = __webpack_require__(236);
998
+ ;// CONCATENATED MODULE: external "@nestjs/core"
999
+
1000
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/entities/index.ts + 5 modules
1001
+ var src_entities = __webpack_require__(454);
1002
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/email-datasource.provider.ts
1003
+ function email_datasource_provider_ts_decorate(decorators, target, key, desc) {
1004
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1005
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1006
+ r = Reflect.decorate(decorators, target, key, desc);
1007
+ } else {
1008
+ for(var i = decorators.length - 1; i >= 0; i--){
1009
+ if (d = decorators[i]) {
1010
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1011
+ }
1012
+ }
1013
+ }
1014
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1015
+ }
1016
+ function email_datasource_provider_ts_metadata(metadataKey, metadataValue) {
1017
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1018
+ return Reflect.metadata(metadataKey, metadataValue);
1019
+ }
1020
+ }
1021
+ function email_datasource_provider_ts_param(paramIndex, decorator) {
1022
+ return function(target, key) {
1023
+ decorator(target, key, paramIndex);
1024
+ };
1025
+ }
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+ class EmailDataSourceProvider extends modules_.MultiTenantDataSourceService {
1032
+ configService;
1033
+ static tenantConnections = new Map();
1034
+ static singleDataSource = null;
1035
+ static tenantsRegistry = new Map();
1036
+ static initialized = false;
1037
+ static connectionLocks = new Map();
1038
+ static singleConnectionLock = null;
1039
+ constructor(configService, request){
1040
+ super(EmailDataSourceProvider.buildParentOptions(configService.getOptions()), request), this.configService = configService;
1041
+ }
1042
+ static buildParentOptions(options) {
1043
+ return {
1044
+ bootstrapAppConfig: options.bootstrapAppConfig,
1045
+ defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
1046
+ tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
1047
+ tenants: options.config?.tenants
1048
+ };
1049
+ }
1050
+ getEnableCompanyFeatureForTenant(tenant) {
1051
+ return tenant?.enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
1052
+ }
1053
+ async createDataSourceFromConfig(config) {
1054
+ const currentTenant = this.getCurrentTenant();
1055
+ const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
1056
+ const entities = (0,src_entities/* .getEmailEntitiesByConfig */.B0)(enableCompanyFeature);
1057
+ return super.createDataSourceFromConfig(config, entities);
1058
+ }
1059
+ }
1060
+ EmailDataSourceProvider = email_datasource_provider_ts_decorate([
1061
+ (0,common_.Injectable)({
1062
+ scope: common_.Scope.REQUEST
1063
+ }),
1064
+ email_datasource_provider_ts_param(0, (0,common_.Inject)(EmailConfigService)),
1065
+ email_datasource_provider_ts_param(1, (0,common_.Optional)()),
1066
+ email_datasource_provider_ts_param(1, (0,common_.Inject)(__rspack_external__nestjs_core_d7b00a1a.REQUEST)),
1067
+ email_datasource_provider_ts_metadata("design:type", Function),
1068
+ email_datasource_provider_ts_metadata("design:paramtypes", [
1069
+ typeof EmailConfigService === "undefined" ? Object : EmailConfigService,
1070
+ typeof Request === "undefined" ? Object : Request
1071
+ ])
1072
+ ], EmailDataSourceProvider);
1073
+
1074
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/classes"
1075
+ var classes_ = __webpack_require__(937);
1076
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/utils"
1077
+ var utils_ = __webpack_require__(216);
1078
+ // EXTERNAL MODULE: external "typeorm"
1079
+ var external_typeorm_ = __webpack_require__(158);
1080
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/config/event-actions.ts
1081
+ var event_actions = __webpack_require__(399);
1082
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/config/message-keys.ts
1083
+ var message_keys = __webpack_require__(887);
1084
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/email-provider-config.service.ts
1085
+ function email_provider_config_service_ts_decorate(decorators, target, key, desc) {
1086
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1087
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1088
+ r = Reflect.decorate(decorators, target, key, desc);
1089
+ } else {
1090
+ for(var i = decorators.length - 1; i >= 0; i--){
1091
+ if (d = decorators[i]) {
1092
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1093
+ }
1094
+ }
1095
+ }
1096
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1097
+ }
1098
+ function email_provider_config_service_ts_metadata(metadataKey, metadataValue) {
1099
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1100
+ return Reflect.metadata(metadataKey, metadataValue);
1101
+ }
1102
+ }
1103
+ function email_provider_config_service_ts_param(paramIndex, decorator) {
1104
+ return function(target, key) {
1105
+ decorator(target, key, paramIndex);
1106
+ };
1107
+ }
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+ class EmailProviderConfigService extends classes_.ApiService {
1118
+ cacheManager;
1119
+ utilsService;
1120
+ emailConfig;
1121
+ constructor(cacheManager, utilsService, emailConfig, dataSourceProvider){
1122
+ super(event_actions/* .EMAIL_EVENT_ENTITIES.CONFIG */.y.CONFIG, cacheManager, utilsService, EmailProviderConfigService.name, true, (/* inlined export .EMAIL_EVENT_MODULE */"email"), dataSourceProvider, emailConfig.isCompanyFeatureEnabled() ? src_entities/* .EmailConfigWithCompany */.Ed : src_entities/* .EmailConfig */.pG), this.cacheManager = cacheManager, this.utilsService = utilsService, this.emailConfig = emailConfig;
1123
+ }
1124
+ async beforeDeleteOperation(dto, _user, _queryRunner) {
1125
+ const ids = Array.isArray(dto.id) ? dto.id : [
1126
+ dto.id
1127
+ ];
1128
+ await this.ensureDataSourceRepository();
1129
+ const defaultConfigs = await this.repository.find({
1130
+ where: {
1131
+ id: (0,external_typeorm_.In)(ids),
1132
+ isDefault: true,
1133
+ deletedAt: (0,external_typeorm_.IsNull)()
1134
+ }
1135
+ });
1136
+ if (defaultConfigs.length > 0) {
1137
+ const names = defaultConfigs.map((c)=>c.name).join(', ');
1138
+ throw new common_.ForbiddenException({
1139
+ message: `Cannot delete the default email config(s): ${names}. Set another config as default first.`,
1140
+ messageKey: message_keys/* .EMAIL_CONFIG_MESSAGES.DEFAULT_DELETE_FORBIDDEN */.T6.DEFAULT_DELETE_FORBIDDEN,
1141
+ messageVariables: {
1142
+ names
1143
+ }
1144
+ });
1145
+ }
1146
+ }
1147
+ async convertSingleDtoToEntity(dto, user) {
1148
+ const entity = {
1149
+ ...dto
1150
+ };
1151
+ if (this.emailConfig.isCompanyFeatureEnabled()) {
1152
+ entity.companyId = user?.companyId ?? null;
1153
+ }
1154
+ return entity;
1155
+ }
1156
+ async getSelectQuery(query, _user, select) {
1157
+ if (!select?.length) {
1158
+ select = [
1159
+ 'id',
1160
+ 'name',
1161
+ 'provider',
1162
+ 'config',
1163
+ 'fromEmail',
1164
+ 'fromName',
1165
+ 'isActive',
1166
+ 'isDefault',
1167
+ 'createdAt',
1168
+ 'updatedAt'
1169
+ ];
1170
+ if (this.emailConfig.isCompanyFeatureEnabled()) select.push('companyId');
1171
+ }
1172
+ query.select(select.map((field)=>`${this.entityName}.${field}`));
1173
+ return {
1174
+ query,
1175
+ isRaw: false
1176
+ };
1177
+ }
1178
+ async getExtraManipulateQuery(query, filterDto, user) {
1179
+ const result = await super.getExtraManipulateQuery(query, filterDto, user);
1180
+ (0,utils_.applyCompanyFilter)(query, {
1181
+ isCompanyFeatureEnabled: this.emailConfig.isCompanyFeatureEnabled(),
1182
+ entityAlias: 'emailConfig'
1183
+ }, user);
1184
+ query.orderBy(`${this.entityName}.createdAt`, 'DESC');
1185
+ return result;
1186
+ }
1187
+ async findByIdDirect(id) {
1188
+ await this.ensureDataSourceRepository();
1189
+ return this.repository.findOne({
1190
+ where: {
1191
+ id
1192
+ }
1193
+ });
1194
+ }
1195
+ async getDefaultConfig(user) {
1196
+ await this.ensureDataSourceRepository();
1197
+ const baseWhere = (0,utils_.buildCompanyWhereCondition)({
1198
+ isActive: true
1199
+ }, this.emailConfig.isCompanyFeatureEnabled(), user);
1200
+ const defaultConfig = await this.repository.findOne({
1201
+ where: {
1202
+ ...baseWhere,
1203
+ isDefault: true
1204
+ },
1205
+ order: {
1206
+ createdAt: 'ASC'
1207
+ }
1208
+ });
1209
+ return defaultConfig || this.repository.findOne({
1210
+ where: baseWhere,
1211
+ order: {
1212
+ createdAt: 'ASC'
1213
+ }
1214
+ });
1215
+ }
1216
+ }
1217
+ EmailProviderConfigService = email_provider_config_service_ts_decorate([
1218
+ (0,common_.Injectable)({
1219
+ scope: common_.Scope.REQUEST
1220
+ }),
1221
+ email_provider_config_service_ts_param(0, (0,common_.Inject)('CACHE_INSTANCE')),
1222
+ email_provider_config_service_ts_param(1, (0,common_.Inject)(modules_.UtilsService)),
1223
+ email_provider_config_service_ts_param(2, (0,common_.Inject)(EmailConfigService)),
1224
+ email_provider_config_service_ts_param(3, (0,common_.Inject)(EmailDataSourceProvider)),
1225
+ email_provider_config_service_ts_metadata("design:type", Function),
1226
+ email_provider_config_service_ts_metadata("design:paramtypes", [
1227
+ typeof classes_.HybridCache === "undefined" ? Object : classes_.HybridCache,
1228
+ typeof modules_.UtilsService === "undefined" ? Object : modules_.UtilsService,
1229
+ typeof EmailConfigService === "undefined" ? Object : EmailConfigService,
1230
+ typeof EmailDataSourceProvider === "undefined" ? Object : EmailDataSourceProvider
1231
+ ])
1232
+ ], EmailProviderConfigService);
1233
+
1234
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared"
1235
+ var nestjs_shared_ = __webpack_require__(422);
1236
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/dtos/index.ts + 6 modules
1237
+ var dtos = __webpack_require__(684);
1238
+ // EXTERNAL MODULE: ./projects/nestjs-email/src/providers/index.ts + 7 modules
1239
+ var providers = __webpack_require__(603);
1240
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/email-template.service.ts
1241
+ function email_template_service_ts_decorate(decorators, target, key, desc) {
1242
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1243
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1244
+ r = Reflect.decorate(decorators, target, key, desc);
1245
+ } else {
1246
+ for(var i = decorators.length - 1; i >= 0; i--){
1247
+ if (d = decorators[i]) {
1248
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1249
+ }
1250
+ }
1251
+ }
1252
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1253
+ }
1254
+ function email_template_service_ts_metadata(metadataKey, metadataValue) {
1255
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1256
+ return Reflect.metadata(metadataKey, metadataValue);
1257
+ }
1258
+ }
1259
+ function email_template_service_ts_param(paramIndex, decorator) {
1260
+ return function(target, key) {
1261
+ decorator(target, key, paramIndex);
1262
+ };
1263
+ }
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+ const DEFAULT_SELECT_FIELDS = [
1273
+ 'id',
1274
+ 'name',
1275
+ 'slug',
1276
+ 'description',
1277
+ 'subject',
1278
+ 'schema',
1279
+ 'htmlContent',
1280
+ 'textContent',
1281
+ 'schemaVersion',
1282
+ 'isActive',
1283
+ 'isHtml',
1284
+ 'createdAt',
1285
+ 'updatedAt'
1286
+ ];
1287
+ class EmailTemplateService extends classes_.ApiService {
1288
+ cacheManager;
1289
+ utilsService;
1290
+ emailConfig;
1291
+ constructor(cacheManager, utilsService, emailConfig, dataSourceProvider){
1292
+ super(event_actions/* .EMAIL_EVENT_ENTITIES.TEMPLATE */.y.TEMPLATE, cacheManager, utilsService, EmailTemplateService.name, true, (/* inlined export .EMAIL_EVENT_MODULE */"email"), dataSourceProvider, emailConfig.isCompanyFeatureEnabled() ? src_entities/* .EmailTemplateWithCompany */.U7 : src_entities/* .EmailTemplate */.Fy), this.cacheManager = cacheManager, this.utilsService = utilsService, this.emailConfig = emailConfig;
1293
+ }
1294
+ async convertSingleDtoToEntity(dto, user) {
1295
+ const entity = await super.convertSingleDtoToEntity(dto, user);
1296
+ await this.incrementSchemaVersionIfChanged(dto, entity);
1297
+ if (this.emailConfig.isCompanyFeatureEnabled()) {
1298
+ entity.companyId = user?.companyId ?? null;
1299
+ }
1300
+ return entity;
1301
+ }
1302
+ async getSelectQuery(query, _user, select) {
1303
+ if (!select?.length) {
1304
+ select = [
1305
+ ...DEFAULT_SELECT_FIELDS
1306
+ ];
1307
+ if (this.emailConfig.isCompanyFeatureEnabled()) select.push('companyId');
1308
+ }
1309
+ query.select(select.map((field)=>`${this.entityName}.${field}`));
1310
+ return {
1311
+ query,
1312
+ isRaw: false
1313
+ };
1314
+ }
1315
+ async getExtraManipulateQuery(query, filterDto, user) {
1316
+ const result = await super.getExtraManipulateQuery(query, filterDto, user);
1317
+ (0,utils_.applyCompanyFilter)(query, {
1318
+ isCompanyFeatureEnabled: this.emailConfig.isCompanyFeatureEnabled(),
1319
+ entityAlias: 'emailTemplate'
1320
+ }, user);
1321
+ query.orderBy(`${this.entityName}.createdAt`, 'DESC');
1322
+ return result;
1323
+ }
1324
+ // ─── Public Query Methods ───────────────────────────────────────────────────
1325
+ async findByIdDirect(id) {
1326
+ await this.ensureDataSourceRepository();
1327
+ return this.repository.findOne({
1328
+ where: {
1329
+ id
1330
+ }
1331
+ });
1332
+ }
1333
+ async findBySlug(slug, user) {
1334
+ await this.ensureDataSourceRepository();
1335
+ const where = (0,utils_.buildCompanyWhereCondition)({
1336
+ slug,
1337
+ isActive: true
1338
+ }, this.emailConfig.isCompanyFeatureEnabled(), user);
1339
+ return this.repository.findOne({
1340
+ where
1341
+ });
1342
+ }
1343
+ // ─── Private Helpers ────────────────────────────────────────────────────────
1344
+ async incrementSchemaVersionIfChanged(dto, entity) {
1345
+ const updateDto = dto;
1346
+ if (!updateDto.id || !dto.schema) return;
1347
+ await this.ensureDataSourceRepository();
1348
+ const existing = await this.repository.findOne({
1349
+ where: {
1350
+ id: updateDto.id
1351
+ }
1352
+ });
1353
+ if (existing && JSON.stringify(dto.schema) !== JSON.stringify(existing.schema)) {
1354
+ entity.schemaVersion = existing.schemaVersion + 1;
1355
+ }
1356
+ }
1357
+ }
1358
+ EmailTemplateService = email_template_service_ts_decorate([
1359
+ (0,common_.Injectable)({
1360
+ scope: common_.Scope.REQUEST
1361
+ }),
1362
+ email_template_service_ts_param(0, (0,common_.Inject)('CACHE_INSTANCE')),
1363
+ email_template_service_ts_param(1, (0,common_.Inject)(modules_.UtilsService)),
1364
+ email_template_service_ts_param(2, (0,common_.Inject)(EmailConfigService)),
1365
+ email_template_service_ts_param(3, (0,common_.Inject)(EmailDataSourceProvider)),
1366
+ email_template_service_ts_metadata("design:type", Function),
1367
+ email_template_service_ts_metadata("design:paramtypes", [
1368
+ typeof classes_.HybridCache === "undefined" ? Object : classes_.HybridCache,
1369
+ typeof modules_.UtilsService === "undefined" ? Object : modules_.UtilsService,
1370
+ typeof EmailConfigService === "undefined" ? Object : EmailConfigService,
1371
+ typeof EmailDataSourceProvider === "undefined" ? Object : EmailDataSourceProvider
1372
+ ])
1373
+ ], EmailTemplateService);
1374
+
1375
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/email-send.service.ts
1376
+ function email_send_service_ts_decorate(decorators, target, key, desc) {
1377
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1378
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1379
+ r = Reflect.decorate(decorators, target, key, desc);
1380
+ } else {
1381
+ for(var i = decorators.length - 1; i >= 0; i--){
1382
+ if (d = decorators[i]) {
1383
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1384
+ }
1385
+ }
1386
+ }
1387
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1388
+ }
1389
+ function email_send_service_ts_metadata(metadataKey, metadataValue) {
1390
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1391
+ return Reflect.metadata(metadataKey, metadataValue);
1392
+ }
1393
+ }
1394
+ function email_send_service_ts_param(paramIndex, decorator) {
1395
+ return function(target, key) {
1396
+ decorator(target, key, paramIndex);
1397
+ };
1398
+ }
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+
1405
+
1406
+
1407
+
1408
+
1409
+ /** Valid identifier pattern for template variables: {{varName}} */ const VARIABLE_PATTERN = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g;
1410
+ class EmailSendService {
1411
+ emailFactory;
1412
+ emailConfigService;
1413
+ emailProviderConfigService;
1414
+ emailTemplateService;
1415
+ constructor(emailFactory, emailConfigService, emailProviderConfigService, emailTemplateService){
1416
+ this.emailFactory = emailFactory;
1417
+ this.emailConfigService = emailConfigService;
1418
+ this.emailProviderConfigService = emailProviderConfigService;
1419
+ this.emailTemplateService = emailTemplateService;
1420
+ }
1421
+ // ─── Public API ─────────────────────────────────────────────────────────────
1422
+ async sendEmail(dto, user) {
1423
+ const { provider, config } = await this.getEmailProviderWithConfig(dto.emailConfigId, user);
1424
+ const sender = this.resolveSender(dto, config);
1425
+ const result = await provider.sendEmail({
1426
+ to: dto.to,
1427
+ cc: dto.cc,
1428
+ bcc: dto.bcc,
1429
+ subject: dto.subject,
1430
+ html: dto.html,
1431
+ text: dto.text,
1432
+ ...sender,
1433
+ replyTo: dto.replyTo,
1434
+ attachments: this.buildAttachments(dto.attachments)
1435
+ });
1436
+ await this.publishSendEvent(result, dto.to, user, {
1437
+ emailConfigId: config.id
1438
+ });
1439
+ return result;
1440
+ }
1441
+ async sendTemplateEmail(dto, user) {
1442
+ const template = await this.resolveTemplate(dto, user);
1443
+ const { subject, html, text } = this.buildTemplateContent(template, dto.variables);
1444
+ const { provider, config } = await this.getEmailProviderWithConfig(dto.emailConfigId, user);
1445
+ const sender = this.resolveSender(dto, config);
1446
+ const result = await provider.sendEmail({
1447
+ to: dto.to,
1448
+ cc: dto.cc,
1449
+ bcc: dto.bcc,
1450
+ subject,
1451
+ html,
1452
+ text,
1453
+ ...sender,
1454
+ replyTo: dto.replyTo,
1455
+ attachments: this.buildAttachments(dto.attachments)
1456
+ });
1457
+ await this.publishSendEvent(result, dto.to, user, {
1458
+ emailConfigId: config.id,
1459
+ templateId: template.id,
1460
+ templateSlug: template.slug
1461
+ });
1462
+ return result;
1463
+ }
1464
+ async sendTestEmail(emailConfigId, recipient, user) {
1465
+ const { provider, config } = await this.getEmailProviderWithConfig(emailConfigId, user);
1466
+ const safeConfig = (0,utils_.escapeHtmlVariables)({
1467
+ name: config.name,
1468
+ provider: config.provider.toUpperCase()
1469
+ });
1470
+ const result = await provider.sendEmail({
1471
+ to: recipient,
1472
+ subject: 'Test Email from FLUSYS',
1473
+ html: this.buildTestEmailHtml(safeConfig),
1474
+ text: `Test Email from FLUSYS\n\nThis is a test email.\nConfiguration: ${config.name}\nProvider: ${config.provider.toUpperCase()}`,
1475
+ from: config.fromEmail || undefined,
1476
+ fromName: config.fromName || this.emailConfigService.getDefaultFromName()
1477
+ });
1478
+ await this.publishSendEvent(result, recipient, user, {
1479
+ emailConfigId: config.id,
1480
+ isTest: true
1481
+ });
1482
+ return result;
1483
+ }
1484
+ // ─── Private: Provider & Config Resolution ──────────────────────────────────
1485
+ async getEmailProviderWithConfig(emailConfigId, user) {
1486
+ const emailConfig = emailConfigId ? await this.resolveConfigById(emailConfigId, user) : await this.resolveDefaultConfig(user);
1487
+ const providerConfig = {
1488
+ provider: emailConfig.provider,
1489
+ config: emailConfig.config
1490
+ };
1491
+ return {
1492
+ provider: await this.emailFactory.createProvider(providerConfig),
1493
+ config: emailConfig
1494
+ };
1495
+ }
1496
+ async resolveConfigById(id, user) {
1497
+ const config = await this.emailProviderConfigService.findByIdDirect(id);
1498
+ if (!config) {
1499
+ throw new common_.NotFoundException({
1500
+ message: 'Email configuration not found',
1501
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.CONFIG_NOT_FOUND */.dP.CONFIG_NOT_FOUND
1502
+ });
1503
+ }
1504
+ (0,utils_.validateCompanyOwnership)(config, user, this.emailConfigService.isCompanyFeatureEnabled(), 'Email configuration');
1505
+ if (!config.isActive) {
1506
+ throw new common_.BadRequestException({
1507
+ message: 'Email configuration is inactive',
1508
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.CONFIG_INACTIVE */.dP.CONFIG_INACTIVE
1509
+ });
1510
+ }
1511
+ return config;
1512
+ }
1513
+ async resolveDefaultConfig(user) {
1514
+ const config = await this.emailProviderConfigService.getDefaultConfig(user);
1515
+ if (!config) {
1516
+ throw new common_.NotFoundException({
1517
+ message: 'No default email configuration found',
1518
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.CONFIG_DEFAULT_NOT_FOUND */.dP.CONFIG_DEFAULT_NOT_FOUND
1519
+ });
1520
+ }
1521
+ return config;
1522
+ }
1523
+ // ─── Private: Template Resolution ───────────────────────────────────────────
1524
+ async resolveTemplate(dto, user) {
1525
+ let template;
1526
+ if (dto.templateId) {
1527
+ template = await this.emailTemplateService.findByIdDirect(dto.templateId);
1528
+ } else if (dto.templateSlug) {
1529
+ template = await this.emailTemplateService.findBySlug(dto.templateSlug, user);
1530
+ } else {
1531
+ throw new common_.BadRequestException({
1532
+ message: 'templateId or templateSlug is required',
1533
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.TEMPLATE_ID_OR_SLUG_REQUIRED */.dP.TEMPLATE_ID_OR_SLUG_REQUIRED
1534
+ });
1535
+ }
1536
+ if (!template) {
1537
+ throw new common_.NotFoundException({
1538
+ message: 'Email template not found',
1539
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.TEMPLATE_NOT_FOUND */.dP.TEMPLATE_NOT_FOUND
1540
+ });
1541
+ }
1542
+ if (!template.isActive) {
1543
+ throw new common_.BadRequestException({
1544
+ message: 'Email template is inactive',
1545
+ messageKey: message_keys/* .EMAIL_SEND_MESSAGES.TEMPLATE_INACTIVE */.dP.TEMPLATE_INACTIVE
1546
+ });
1547
+ }
1548
+ (0,utils_.validateCompanyOwnership)(template, user, this.emailConfigService.isCompanyFeatureEnabled(), 'Email template');
1549
+ return template;
1550
+ }
1551
+ buildTemplateContent(template, variables) {
1552
+ const vars = variables || {};
1553
+ const subject = this.interpolateVariables(template.subject, vars, false);
1554
+ if (template.isHtml) {
1555
+ return {
1556
+ subject,
1557
+ html: this.interpolateVariables(template.htmlContent, vars, true),
1558
+ text: template.textContent ? this.interpolateVariables(template.textContent, vars, false) : undefined
1559
+ };
1560
+ }
1561
+ return {
1562
+ subject,
1563
+ html: undefined,
1564
+ text: template.textContent ? this.interpolateVariables(template.textContent, vars, false) : this.interpolateVariables(template.htmlContent, vars, false)
1565
+ };
1566
+ }
1567
+ // ─── Private: Helpers ───────────────────────────────────────────────────────
1568
+ resolveSender(dto, config) {
1569
+ return {
1570
+ from: dto.from || config.fromEmail || undefined,
1571
+ fromName: dto.fromName || config.fromName || this.emailConfigService.getDefaultFromName()
1572
+ };
1573
+ }
1574
+ buildAttachments(attachments) {
1575
+ return attachments?.map((a)=>({
1576
+ filename: a.filename,
1577
+ content: Buffer.from(a.content, 'base64'),
1578
+ contentType: a.contentType
1579
+ }));
1580
+ }
1581
+ interpolateVariables(content, variables, escapeHtml) {
1582
+ if (!variables || Object.keys(variables).length === 0) return content;
1583
+ const safeVars = escapeHtml ? (0,utils_.escapeHtmlVariables)(variables) : variables;
1584
+ return content.replace(VARIABLE_PATTERN, (match, varName)=>{
1585
+ return varName in safeVars && safeVars[varName] !== undefined ? String(safeVars[varName]) : match;
1586
+ });
1587
+ }
1588
+ buildTestEmailHtml(safeConfig) {
1589
+ return `
1590
+ <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
1591
+ <h1 style="color: #333;">Test Email</h1>
1592
+ <p>This is a test email from FLUSYS Email Service.</p>
1593
+ <p><strong>Configuration:</strong> ${safeConfig.name}</p>
1594
+ <p><strong>Provider:</strong> ${safeConfig.provider}</p>
1595
+ <p style="color: #666; font-size: 12px;">
1596
+ If you received this email, your email configuration is working correctly.
1597
+ </p>
1598
+ </div>
1599
+ `;
1600
+ }
1601
+ async publishSendEvent(result, to, user, metadata) {
1602
+ const recipients = Array.isArray(to) ? to : [
1603
+ to
1604
+ ];
1605
+ await (0,classes_.publishDomainEvent)({
1606
+ module: (/* inlined export .EMAIL_EVENT_MODULE */"email"),
1607
+ entity: event_actions/* .EMAIL_EVENT_ENTITIES.MESSAGE */.y.MESSAGE,
1608
+ action: result.success ? event_actions/* .EMAIL_EVENT_ACTIONS.SENT */.C.SENT : event_actions/* .EMAIL_EVENT_ACTIONS.FAILED */.C.FAILED,
1609
+ ids: result.messageId ? [
1610
+ result.messageId
1611
+ ] : [],
1612
+ metadata: {
1613
+ ...metadata,
1614
+ recipientCount: recipients.length,
1615
+ ...result.error ? {
1616
+ error: result.error
1617
+ } : {}
1618
+ },
1619
+ user: user ?? null
1620
+ });
1621
+ }
1622
+ }
1623
+ email_send_service_ts_decorate([
1624
+ (0,nestjs_shared_.LogAction)({
1625
+ action: 'email.send',
1626
+ module: 'email'
1627
+ }),
1628
+ email_send_service_ts_metadata("design:type", Function),
1629
+ email_send_service_ts_metadata("design:paramtypes", [
1630
+ typeof dtos/* .SendEmailDto */.m5 === "undefined" ? Object : dtos/* .SendEmailDto */.m5,
1631
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
1632
+ ]),
1633
+ email_send_service_ts_metadata("design:returntype", Promise)
1634
+ ], EmailSendService.prototype, "sendEmail", null);
1635
+ email_send_service_ts_decorate([
1636
+ (0,nestjs_shared_.LogAction)({
1637
+ action: 'email.sendTemplate',
1638
+ module: 'email'
1639
+ }),
1640
+ email_send_service_ts_metadata("design:type", Function),
1641
+ email_send_service_ts_metadata("design:paramtypes", [
1642
+ typeof dtos/* .SendTemplateEmailDto */.iu === "undefined" ? Object : dtos/* .SendTemplateEmailDto */.iu,
1643
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
1644
+ ]),
1645
+ email_send_service_ts_metadata("design:returntype", Promise)
1646
+ ], EmailSendService.prototype, "sendTemplateEmail", null);
1647
+ email_send_service_ts_decorate([
1648
+ (0,nestjs_shared_.LogAction)({
1649
+ action: 'email.sendTest',
1650
+ module: 'email'
1651
+ }),
1652
+ email_send_service_ts_metadata("design:type", Function),
1653
+ email_send_service_ts_metadata("design:paramtypes", [
1654
+ String,
1655
+ String,
1656
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
1657
+ ]),
1658
+ email_send_service_ts_metadata("design:returntype", Promise)
1659
+ ], EmailSendService.prototype, "sendTestEmail", null);
1660
+ EmailSendService = email_send_service_ts_decorate([
1661
+ (0,common_.Injectable)({
1662
+ scope: common_.Scope.REQUEST
1663
+ }),
1664
+ email_send_service_ts_param(0, (0,common_.Inject)(providers/* .EmailFactoryService */.c)),
1665
+ email_send_service_ts_param(1, (0,common_.Inject)(EmailConfigService)),
1666
+ email_send_service_ts_param(2, (0,common_.Inject)(EmailProviderConfigService)),
1667
+ email_send_service_ts_param(3, (0,common_.Inject)(EmailTemplateService)),
1668
+ email_send_service_ts_metadata("design:type", Function),
1669
+ email_send_service_ts_metadata("design:paramtypes", [
1670
+ typeof providers/* .EmailFactoryService */.c === "undefined" ? Object : providers/* .EmailFactoryService */.c,
1671
+ typeof EmailConfigService === "undefined" ? Object : EmailConfigService,
1672
+ typeof EmailProviderConfigService === "undefined" ? Object : EmailProviderConfigService,
1673
+ typeof EmailTemplateService === "undefined" ? Object : EmailTemplateService
1674
+ ])
1675
+ ], EmailSendService);
1676
+
1677
+ ;// CONCATENATED MODULE: ./projects/nestjs-email/src/services/index.ts
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+ },
1686
+ 422(module) {
1687
+
1688
+ module.exports = __rspack_external__flusys_nestjs_shared_393d2cae;
1689
+
1690
+
1691
+ },
1692
+ 937(module) {
1693
+
1694
+ module.exports = __rspack_external__flusys_nestjs_shared_classes_6076a329;
1695
+
1696
+
1697
+ },
1698
+ 236(module) {
1699
+
1700
+ module.exports = __rspack_external__flusys_nestjs_shared_modules_24702bee;
1701
+
1702
+
1703
+ },
1704
+ 216(module) {
1705
+
1706
+ module.exports = __rspack_external__flusys_nestjs_shared_utils_9125c1f1;
1707
+
1708
+
1709
+ },
1710
+ 157(module) {
1711
+
1712
+ module.exports = __rspack_external__nestjs_common_a04939da;
1713
+
1714
+
1715
+ },
1716
+ 158(module) {
1717
+
1718
+ module.exports = __rspack_external_typeorm;
1719
+
1720
+
1721
+ },
1722
+
1723
+ };