@webiny/api-mailer 0.0.0-unstable.3bc8100a7f → 0.0.0-unstable.3fddf667ea

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 (181) hide show
  1. package/MailerFeature.d.ts +4 -0
  2. package/MailerFeature.js +27 -0
  3. package/MailerFeature.js.map +1 -0
  4. package/README.md +10 -13
  5. package/constants.d.ts +4 -0
  6. package/constants.js +7 -0
  7. package/constants.js.map +1 -0
  8. package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
  9. package/domain/CodeMailerSettings/abstractions.js +5 -0
  10. package/domain/CodeMailerSettings/abstractions.js.map +1 -0
  11. package/domain/MailTransport/abstractions.d.ts +36 -0
  12. package/domain/MailTransport/abstractions.js +7 -0
  13. package/domain/MailTransport/abstractions.js.map +1 -0
  14. package/domain/MailerService/abstractions.d.ts +19 -0
  15. package/domain/MailerService/abstractions.js +5 -0
  16. package/domain/MailerService/abstractions.js.map +1 -0
  17. package/domain/MailerService/errors.d.ts +20 -0
  18. package/domain/MailerService/errors.js +35 -0
  19. package/domain/MailerService/errors.js.map +1 -0
  20. package/domain/errors.d.ts +36 -0
  21. package/domain/errors.js +62 -0
  22. package/domain/errors.js.map +1 -0
  23. package/exports/api/mailer.d.ts +4 -0
  24. package/exports/api/mailer.js +4 -0
  25. package/features/CodeMailerSettings/CodeMailerSettings.d.ts +12 -0
  26. package/features/CodeMailerSettings/CodeMailerSettings.js +23 -0
  27. package/features/CodeMailerSettings/CodeMailerSettings.js.map +1 -0
  28. package/features/CodeMailerSettings/feature.d.ts +4 -0
  29. package/features/CodeMailerSettings/feature.js +11 -0
  30. package/features/CodeMailerSettings/feature.js.map +1 -0
  31. package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
  32. package/features/DummyTransport/DummyMailTransport.js +15 -0
  33. package/features/DummyTransport/DummyMailTransport.js.map +1 -0
  34. package/features/DummyTransport/DummyMailTransportFactory.d.ts +10 -0
  35. package/features/DummyTransport/DummyMailTransportFactory.js +21 -0
  36. package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
  37. package/features/DummyTransport/feature.d.ts +4 -0
  38. package/features/DummyTransport/feature.js +11 -0
  39. package/features/DummyTransport/feature.js.map +1 -0
  40. package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
  41. package/features/GetSettings/GetSettingsRepository.js +56 -0
  42. package/features/GetSettings/GetSettingsRepository.js.map +1 -0
  43. package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
  44. package/features/GetSettings/GetSettingsUseCase.js +18 -0
  45. package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
  46. package/features/GetSettings/abstractions.d.ts +22 -0
  47. package/features/GetSettings/abstractions.js +6 -0
  48. package/features/GetSettings/abstractions.js.map +1 -0
  49. package/features/GetSettings/feature.d.ts +4 -0
  50. package/features/GetSettings/feature.js +13 -0
  51. package/features/GetSettings/feature.js.map +1 -0
  52. package/features/GetSettings/index.d.ts +1 -0
  53. package/features/GetSettings/index.js +1 -0
  54. package/features/MailerService/MailTransportResolver.d.ts +13 -0
  55. package/features/MailerService/MailTransportResolver.js +37 -0
  56. package/features/MailerService/MailTransportResolver.js.map +1 -0
  57. package/features/MailerService/MailerService.d.ts +13 -0
  58. package/features/MailerService/MailerService.js +38 -0
  59. package/features/MailerService/MailerService.js.map +1 -0
  60. package/features/MailerService/feature.d.ts +4 -0
  61. package/features/MailerService/feature.js +13 -0
  62. package/features/MailerService/feature.js.map +1 -0
  63. package/features/SaveSettings/SaveSettingsRepository.d.ts +13 -0
  64. package/features/SaveSettings/SaveSettingsRepository.js +45 -0
  65. package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
  66. package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
  67. package/features/SaveSettings/SaveSettingsUseCase.js +57 -0
  68. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
  69. package/features/SaveSettings/abstractions.d.ts +62 -0
  70. package/features/SaveSettings/abstractions.js +8 -0
  71. package/features/SaveSettings/abstractions.js.map +1 -0
  72. package/features/SaveSettings/events.d.ts +10 -0
  73. package/features/SaveSettings/events.js +21 -0
  74. package/features/SaveSettings/events.js.map +1 -0
  75. package/features/SaveSettings/feature.d.ts +4 -0
  76. package/features/SaveSettings/feature.js +13 -0
  77. package/features/SaveSettings/feature.js.map +1 -0
  78. package/features/SaveSettings/index.d.ts +1 -0
  79. package/features/SaveSettings/index.js +1 -0
  80. package/features/SaveSettings/validation.d.ts +10 -0
  81. package/features/SaveSettings/validation.js +21 -0
  82. package/features/SaveSettings/validation.js.map +1 -0
  83. package/features/SendMail/SendMailUseCase.d.ts +16 -0
  84. package/features/SendMail/SendMailUseCase.js +58 -0
  85. package/features/SendMail/SendMailUseCase.js.map +1 -0
  86. package/features/SendMail/abstractions.d.ts +45 -0
  87. package/features/SendMail/abstractions.js +8 -0
  88. package/features/SendMail/abstractions.js.map +1 -0
  89. package/features/SendMail/events.d.ts +14 -0
  90. package/features/SendMail/events.js +29 -0
  91. package/features/SendMail/events.js.map +1 -0
  92. package/features/SendMail/feature.d.ts +4 -0
  93. package/features/SendMail/feature.js +11 -0
  94. package/features/SendMail/feature.js.map +1 -0
  95. package/features/SendMail/index.d.ts +1 -0
  96. package/features/SendMail/index.js +1 -0
  97. package/features/SendTestMail/SendTestMailUseCase.d.ts +15 -0
  98. package/features/SendTestMail/SendTestMailUseCase.js +43 -0
  99. package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
  100. package/features/SendTestMail/abstractions.d.ts +32 -0
  101. package/features/SendTestMail/abstractions.js +5 -0
  102. package/features/SendTestMail/abstractions.js.map +1 -0
  103. package/features/SendTestMail/feature.d.ts +4 -0
  104. package/features/SendTestMail/feature.js +11 -0
  105. package/features/SendTestMail/feature.js.map +1 -0
  106. package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
  107. package/features/SmtpTransport/SmtpConfig.js +26 -0
  108. package/features/SmtpTransport/SmtpConfig.js.map +1 -0
  109. package/features/SmtpTransport/SmtpMailTransport.d.ts +77 -0
  110. package/features/SmtpTransport/SmtpMailTransport.js +60 -0
  111. package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
  112. package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +11 -0
  113. package/features/SmtpTransport/SmtpMailTransportFactory.js +22 -0
  114. package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
  115. package/features/SmtpTransport/feature.d.ts +4 -0
  116. package/features/SmtpTransport/feature.js +11 -0
  117. package/features/SmtpTransport/feature.js.map +1 -0
  118. package/graphql/MailerSchemaFactory.d.ts +10 -0
  119. package/graphql/MailerSchemaFactory.js +148 -0
  120. package/graphql/MailerSchemaFactory.js.map +1 -0
  121. package/index.d.ts +3 -5
  122. package/index.js +2 -83
  123. package/package.json +29 -34
  124. package/types.d.ts +1 -107
  125. package/types.js +0 -7
  126. package/utils/isMailboxAddress.d.ts +6 -0
  127. package/utils/isMailboxAddress.js +5 -0
  128. package/utils/isMailboxAddress.js.map +1 -0
  129. package/context.d.ts +0 -3
  130. package/context.js +0 -20
  131. package/context.js.map +0 -1
  132. package/crud/settings/hooks.d.ts +0 -5
  133. package/crud/settings/hooks.js +0 -42
  134. package/crud/settings/hooks.js.map +0 -1
  135. package/crud/settings/model.d.ts +0 -2
  136. package/crud/settings/model.js +0 -72
  137. package/crud/settings/model.js.map +0 -1
  138. package/crud/settings/password.d.ts +0 -7
  139. package/crud/settings/password.js +0 -55
  140. package/crud/settings/password.js.map +0 -1
  141. package/crud/settings/secret.d.ts +0 -1
  142. package/crud/settings/secret.js +0 -19
  143. package/crud/settings/secret.js.map +0 -1
  144. package/crud/settings/transform.d.ts +0 -13
  145. package/crud/settings/transform.js +0 -46
  146. package/crud/settings/transform.js.map +0 -1
  147. package/crud/settings/validation.d.ts +0 -45
  148. package/crud/settings/validation.js +0 -28
  149. package/crud/settings/validation.js.map +0 -1
  150. package/crud/settings.crud.d.ts +0 -5
  151. package/crud/settings.crud.js +0 -269
  152. package/crud/settings.crud.js.map +0 -1
  153. package/crud/transport/onTransportBeforeSend.d.ts +0 -7
  154. package/crud/transport/onTransportBeforeSend.js +0 -62
  155. package/crud/transport/onTransportBeforeSend.js.map +0 -1
  156. package/crud/transporter.crud.d.ts +0 -2
  157. package/crud/transporter.crud.js +0 -158
  158. package/crud/transporter.crud.js.map +0 -1
  159. package/graphql/index.d.ts +0 -1
  160. package/graphql/index.js +0 -13
  161. package/graphql/index.js.map +0 -1
  162. package/graphql/settings.d.ts +0 -3
  163. package/graphql/settings.js +0 -103
  164. package/graphql/settings.js.map +0 -1
  165. package/index.js.map +0 -1
  166. package/plugins/CreateTransportPlugin.d.ts +0 -17
  167. package/plugins/CreateTransportPlugin.js +0 -24
  168. package/plugins/CreateTransportPlugin.js.map +0 -1
  169. package/plugins/index.d.ts +0 -1
  170. package/plugins/index.js +0 -18
  171. package/plugins/index.js.map +0 -1
  172. package/transports/createDummyTransport.d.ts +0 -5
  173. package/transports/createDummyTransport.js +0 -25
  174. package/transports/createDummyTransport.js.map +0 -1
  175. package/transports/createSmtpTransport.d.ts +0 -13
  176. package/transports/createSmtpTransport.js +0 -94
  177. package/transports/createSmtpTransport.js.map +0 -1
  178. package/transports/index.d.ts +0 -2
  179. package/transports/index.js +0 -29
  180. package/transports/index.js.map +0 -1
  181. package/types.js.map +0 -1
@@ -0,0 +1,21 @@
1
+ import zod from "zod";
2
+ import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
3
+ const validation_password = zod.string().describe("Password");
4
+ const mailboxAddress = zod.string().refine(isMailboxAddress, {
5
+ message: "Invalid email address."
6
+ });
7
+ const common = {
8
+ from: mailboxAddress.describe("Mail from"),
9
+ port: zod.number().optional().nullish().describe("Port"),
10
+ replyTo: zod.preprocess((value)=>"" === value ? null : value, mailboxAddress.optional().nullish()).describe("Mail reply-to"),
11
+ host: zod.string().describe("Hostname"),
12
+ user: zod.string().describe("User")
13
+ };
14
+ const saveValidation = zod.object({
15
+ ...common,
16
+ secure: zod.boolean().optional().describe("Use TLS/SSL"),
17
+ password: validation_password.nullish().optional().transform((value)=>void 0 === value ? null : value)
18
+ });
19
+ export { saveValidation };
20
+
21
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SaveSettings/validation.js","sources":["../../../src/features/SaveSettings/validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst password = zod.string().describe(\"Password\");\n\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst common = {\n from: mailboxAddress.describe(\"Mail from\"),\n port: zod.number().optional().nullish().describe(\"Port\"),\n replyTo: zod\n .preprocess(\n // We need to set empty strings to `null` before address validation kicks in.\n value => (value === \"\" ? null : value),\n mailboxAddress.optional().nullish()\n )\n .describe(\"Mail reply-to\"),\n host: zod.string().describe(\"Hostname\"),\n user: zod.string().describe(\"User\")\n};\n\nexport const saveValidation = zod.object({\n ...common,\n secure: zod.boolean().optional().describe(\"Use TLS/SSL\"),\n password: password\n .nullish()\n .optional()\n .transform(value => {\n return value === undefined ? null : value;\n })\n});\n"],"names":["password","zod","mailboxAddress","isMailboxAddress","common","value","saveValidation","undefined"],"mappings":";;AAGA,MAAMA,sBAAWC,IAAI,MAAM,GAAG,QAAQ,CAAC;AAEvC,MAAMC,iBAAiBD,IAAI,MAAM,GAAG,MAAM,CAACE,kBAAkB;IAAE,SAAS;AAAyB;AAEjG,MAAMC,SAAS;IACX,MAAMF,eAAe,QAAQ,CAAC;IAC9B,MAAMD,IAAI,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACjD,SAASA,IAAAA,UACM,CAEPI,CAAAA,QAAUA,AAAU,OAAVA,QAAe,OAAOA,OAChCH,eAAe,QAAQ,GAAG,OAAO,IAEpC,QAAQ,CAAC;IACd,MAAMD,IAAI,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,IAAI,MAAM,GAAG,QAAQ,CAAC;AAChC;AAEO,MAAMK,iBAAiBL,IAAI,MAAM,CAAC;IACrC,GAAGG,MAAM;IACT,QAAQH,IAAI,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,UAAUD,oBACL,OAAO,GACP,QAAQ,GACR,SAAS,CAACK,CAAAA,QACAA,AAAUE,WAAVF,QAAsB,OAAOA;AAEhD"}
@@ -0,0 +1,16 @@
1
+ import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/eventPublisher/index.js";
2
+ import { SendMailUseCase } from "./abstractions.js";
3
+ import { MailerService } from "../../domain/MailerService/abstractions.js";
4
+ import type { TransportSendData } from "../../types.js";
5
+ import { MailValidationError } from "../../domain/errors.js";
6
+ import { Result } from "@webiny/feature/api";
7
+ declare class SendMailUseCaseImpl implements SendMailUseCase.Interface {
8
+ private mailerService;
9
+ private eventPublisher;
10
+ constructor(mailerService: MailerService.Interface, eventPublisher: EventPublisherAbstraction.Interface);
11
+ execute(data: TransportSendData): Promise<Result<never, MailValidationError> | Result<import("~/types.js").TransportSendResponse<any>, import("../../domain/MailerService/errors.js").NoTransportAvailableError | import("../../domain/MailerService/errors.js").TransportCreateError | import("../../domain/MailerService/errors.js").TransportSendError>>;
12
+ }
13
+ export declare const SendMailUseCaseImplementation: typeof SendMailUseCaseImpl & {
14
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendMailUseCase>;
15
+ };
16
+ export {};
@@ -0,0 +1,58 @@
1
+ import zod from "zod";
2
+ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
3
+ import { SendMailUseCase } from "./abstractions.js";
4
+ import { MailAfterSendEvent, MailBeforeSendEvent, MailSendErrorEvent } from "./events.js";
5
+ import { MailerService } from "../../domain/MailerService/abstractions.js";
6
+ import { MailValidationError } from "../../domain/errors.js";
7
+ import { Result } from "@webiny/feature/api";
8
+ import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
9
+ const requiredString = zod.string();
10
+ const mailboxAddress = zod.string().refine(isMailboxAddress, {
11
+ message: "Invalid email address."
12
+ });
13
+ const schema = zod.object({
14
+ to: zod.array(mailboxAddress).optional(),
15
+ from: mailboxAddress.optional(),
16
+ subject: requiredString.max(1024).min(2),
17
+ cc: zod.array(mailboxAddress).optional(),
18
+ bcc: zod.array(mailboxAddress).optional(),
19
+ replyTo: mailboxAddress.optional(),
20
+ text: zod.string().optional(),
21
+ html: zod.string().optional()
22
+ }).refine((data)=>!!data.text || !!data.html, "Either text or html is required.");
23
+ class SendMailUseCaseImpl {
24
+ constructor(mailerService, eventPublisher){
25
+ this.mailerService = mailerService;
26
+ this.eventPublisher = eventPublisher;
27
+ }
28
+ async execute(data) {
29
+ const validation = schema.safeParse(data);
30
+ if (!validation.success) return Result.fail(new MailValidationError(validation.error.issues));
31
+ await this.eventPublisher.publish(new MailBeforeSendEvent({
32
+ data
33
+ }));
34
+ const result = await this.mailerService.sendMail(data);
35
+ if (result.isFail()) {
36
+ await this.eventPublisher.publish(new MailSendErrorEvent({
37
+ data,
38
+ error: result.error
39
+ }));
40
+ return result;
41
+ }
42
+ await this.eventPublisher.publish(new MailAfterSendEvent({
43
+ data,
44
+ response: result.value
45
+ }));
46
+ return result;
47
+ }
48
+ }
49
+ const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({
50
+ implementation: SendMailUseCaseImpl,
51
+ dependencies: [
52
+ MailerService,
53
+ EventPublisher
54
+ ]
55
+ });
56
+ export { SendMailUseCaseImplementation };
57
+
58
+ //# sourceMappingURL=SendMailUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendMail/SendMailUseCase.js","sources":["../../../src/features/SendMail/SendMailUseCase.ts"],"sourcesContent":["import zod from \"zod\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { SendMailUseCase } from \"./abstractions.js\";\nimport { MailBeforeSendEvent, MailAfterSendEvent, MailSendErrorEvent } from \"./events.js\";\nimport { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst requiredString = zod.string();\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst schema = zod\n .object({\n to: zod.array(mailboxAddress).optional(),\n from: mailboxAddress.optional(),\n subject: requiredString.max(1024).min(2),\n cc: zod.array(mailboxAddress).optional(),\n bcc: zod.array(mailboxAddress).optional(),\n replyTo: mailboxAddress.optional(),\n text: zod.string().optional(),\n html: zod.string().optional()\n })\n .refine(data => {\n return !!data.text || !!data.html;\n }, \"Either text or html is required.\");\n\nclass SendMailUseCaseImpl implements SendMailUseCase.Interface {\n constructor(\n private mailerService: MailerService.Interface,\n private eventPublisher: EventPublisherAbstraction.Interface\n ) {}\n\n async execute(data: TransportSendData) {\n const validation = schema.safeParse(data);\n if (!validation.success) {\n return Result.fail(new MailValidationError(validation.error.issues));\n }\n\n // Publish before send event\n await this.eventPublisher.publish(new MailBeforeSendEvent({ data }));\n\n // Send mail\n const result = await this.mailerService.sendMail(data);\n\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new MailSendErrorEvent({\n data,\n error: result.error\n })\n );\n\n return result;\n }\n\n // Publish after send event\n await this.eventPublisher.publish(\n new MailAfterSendEvent({\n data,\n response: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({\n implementation: SendMailUseCaseImpl,\n dependencies: [MailerService, EventPublisher]\n});\n"],"names":["requiredString","zod","mailboxAddress","isMailboxAddress","schema","data","SendMailUseCaseImpl","mailerService","eventPublisher","validation","Result","MailValidationError","MailBeforeSendEvent","result","MailSendErrorEvent","MailAfterSendEvent","SendMailUseCaseImplementation","SendMailUseCase","MailerService","EventPublisher"],"mappings":";;;;;;;;AAaA,MAAMA,iBAAiBC,IAAI,MAAM;AACjC,MAAMC,iBAAiBD,IAAI,MAAM,GAAG,MAAM,CAACE,kBAAkB;IAAE,SAAS;AAAyB;AAEjG,MAAMC,SAASH,IAAAA,MACJ,CAAC;IACJ,IAAIA,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACtC,MAAMA,eAAe,QAAQ;IAC7B,SAASF,eAAe,GAAG,CAAC,MAAM,GAAG,CAAC;IACtC,IAAIC,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACtC,KAAKD,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACvC,SAASA,eAAe,QAAQ;IAChC,MAAMD,IAAI,MAAM,GAAG,QAAQ;IAC3B,MAAMA,IAAI,MAAM,GAAG,QAAQ;AAC/B,GACC,MAAM,CAACI,CAAAA,OACG,CAAC,CAACA,KAAK,IAAI,IAAI,CAAC,CAACA,KAAK,IAAI,EAClC;AAEP,MAAMC;IACF,YACYC,aAAsC,EACtCC,cAAmD,CAC7D;aAFUD,aAAa,GAAbA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQH,IAAuB,EAAE;QACnC,MAAMI,aAAaL,OAAO,SAAS,CAACC;QACpC,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOC,OAAO,IAAI,CAAC,IAAIC,oBAAoBF,WAAW,KAAK,CAAC,MAAM;QAItE,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIG,oBAAoB;YAAEP;QAAK;QAGjE,MAAMQ,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAACR;QAEjD,IAAIQ,OAAO,MAAM,IAAI;YAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,mBAAmB;gBACnBT;gBACA,OAAOQ,OAAO,KAAK;YACvB;YAGJ,OAAOA;QACX;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,mBAAmB;YACnBV;YACA,UAAUQ,OAAO,KAAK;QAC1B;QAGJ,OAAOA;IACX;AACJ;AAEO,MAAMG,gCAAgCC,gBAAgB,oBAAoB,CAAC;IAC9E,gBAAgBX;IAChB,cAAc;QAACY;QAAeC;KAAe;AACjD"}
@@ -0,0 +1,45 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
3
+ import type { TransportSendData, TransportSendResponse } from "../../types.js";
4
+ import type { MailerService } from "../../domain/MailerService/abstractions.js";
5
+ import { MailValidationError } from "../../domain/errors.js";
6
+ export interface ISendMailErrors {
7
+ validation: MailValidationError;
8
+ mailService: MailerService.Error;
9
+ }
10
+ type SendMailErrors = ISendMailErrors[keyof ISendMailErrors];
11
+ export interface ISendMailUseCase {
12
+ execute(data: TransportSendData): Promise<Result<TransportSendResponse, SendMailErrors>>;
13
+ }
14
+ export declare const SendMailUseCase: import("@webiny/di").Abstraction<ISendMailUseCase>;
15
+ export declare namespace SendMailUseCase {
16
+ type Interface = ISendMailUseCase;
17
+ type Error = SendMailErrors;
18
+ }
19
+ export interface MailBeforeSendPayload {
20
+ data: TransportSendData;
21
+ }
22
+ export interface MailAfterSendPayload {
23
+ data: TransportSendData;
24
+ response: TransportSendResponse;
25
+ }
26
+ export interface MailSendErrorPayload {
27
+ data: TransportSendData;
28
+ error: Error;
29
+ }
30
+ export declare const MailBeforeSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailBeforeSendPayload>>>;
31
+ export declare namespace MailBeforeSendEventHandler {
32
+ type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;
33
+ type Event = DomainEvent<MailBeforeSendPayload>;
34
+ }
35
+ export declare const MailAfterSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailAfterSendPayload>>>;
36
+ export declare namespace MailAfterSendEventHandler {
37
+ type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;
38
+ type Event = DomainEvent<MailAfterSendPayload>;
39
+ }
40
+ export declare const MailSendErrorEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailSendErrorPayload>>>;
41
+ export declare namespace MailSendErrorEventHandler {
42
+ type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;
43
+ type Event = DomainEvent<MailSendErrorPayload>;
44
+ }
45
+ export {};
@@ -0,0 +1,8 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const SendMailUseCase = createAbstraction("SendMail");
3
+ const MailBeforeSendEventHandler = createAbstraction("MailBeforeSendEventHandler");
4
+ const MailAfterSendEventHandler = createAbstraction("MailAfterSendEventHandler");
5
+ const MailSendErrorEventHandler = createAbstraction("MailSendErrorEventHandler");
6
+ export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase };
7
+
8
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendMail/abstractions.js","sources":["../../../src/features/SendMail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { TransportSendData, TransportSendResponse } from \"~/types.js\";\nimport type { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\n\nexport interface ISendMailErrors {\n validation: MailValidationError;\n mailService: MailerService.Error;\n}\n\ntype SendMailErrors = ISendMailErrors[keyof ISendMailErrors];\n\nexport interface ISendMailUseCase {\n execute(data: TransportSendData): Promise<Result<TransportSendResponse, SendMailErrors>>;\n}\n\nexport const SendMailUseCase = createAbstraction<ISendMailUseCase>(\"SendMail\");\n\nexport namespace SendMailUseCase {\n export type Interface = ISendMailUseCase;\n export type Error = SendMailErrors;\n}\n\n// Domain Events\nexport interface MailBeforeSendPayload {\n data: TransportSendData;\n}\n\nexport interface MailAfterSendPayload {\n data: TransportSendData;\n response: TransportSendResponse;\n}\n\nexport interface MailSendErrorPayload {\n data: TransportSendData;\n error: Error;\n}\n\n// Event Handler Abstractions\nexport const MailBeforeSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailBeforeSendPayload>>\n>(\"MailBeforeSendEventHandler\");\n\nexport namespace MailBeforeSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;\n export type Event = DomainEvent<MailBeforeSendPayload>;\n}\n\nexport const MailAfterSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailAfterSendPayload>>\n>(\"MailAfterSendEventHandler\");\n\nexport namespace MailAfterSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;\n export type Event = DomainEvent<MailAfterSendPayload>;\n}\n\nexport const MailSendErrorEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailSendErrorPayload>>\n>(\"MailSendErrorEventHandler\");\n\nexport namespace MailSendErrorEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;\n export type Event = DomainEvent<MailSendErrorPayload>;\n}\n"],"names":["SendMailUseCase","createAbstraction","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler"],"mappings":";AAkBO,MAAMA,kBAAkBC,kBAAoC;AAuB5D,MAAMC,6BAA6BD,kBAExC;AAOK,MAAME,4BAA4BF,kBAEvC;AAOK,MAAMG,4BAA4BH,kBAEvC"}
@@ -0,0 +1,14 @@
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
+ import type { MailBeforeSendPayload, MailAfterSendPayload, MailSendErrorPayload } from "./abstractions.js";
3
+ export declare class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {
4
+ eventType: "mailer.mail.beforeSend";
5
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailBeforeSendPayload>>>;
6
+ }
7
+ export declare class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {
8
+ eventType: "mailer.mail.afterSend";
9
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailAfterSendPayload>>>;
10
+ }
11
+ export declare class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {
12
+ eventType: "mailer.mail.sendError";
13
+ getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailSendErrorPayload>>>;
14
+ }
@@ -0,0 +1,29 @@
1
+ import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
2
+ import { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
3
+ class MailBeforeSendEvent extends DomainEvent {
4
+ getHandlerAbstraction() {
5
+ return MailBeforeSendEventHandler;
6
+ }
7
+ constructor(...args){
8
+ super(...args), this.eventType = "mailer.mail.beforeSend";
9
+ }
10
+ }
11
+ class MailAfterSendEvent extends DomainEvent {
12
+ getHandlerAbstraction() {
13
+ return MailAfterSendEventHandler;
14
+ }
15
+ constructor(...args){
16
+ super(...args), this.eventType = "mailer.mail.afterSend";
17
+ }
18
+ }
19
+ class MailSendErrorEvent extends DomainEvent {
20
+ getHandlerAbstraction() {
21
+ return MailSendErrorEventHandler;
22
+ }
23
+ constructor(...args){
24
+ super(...args), this.eventType = "mailer.mail.sendError";
25
+ }
26
+ }
27
+ export { MailAfterSendEvent, MailBeforeSendEvent, MailSendErrorEvent };
28
+
29
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendMail/events.js","sources":["../../../src/features/SendMail/events.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n MailBeforeSendEventHandler,\n MailAfterSendEventHandler,\n MailSendErrorEventHandler\n} from \"./abstractions.js\";\nimport type {\n MailBeforeSendPayload,\n MailAfterSendPayload,\n MailSendErrorPayload\n} from \"./abstractions.js\";\n\nexport class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {\n eventType = \"mailer.mail.beforeSend\" as const;\n\n getHandlerAbstraction() {\n return MailBeforeSendEventHandler;\n }\n}\n\nexport class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {\n eventType = \"mailer.mail.afterSend\" as const;\n\n getHandlerAbstraction() {\n return MailAfterSendEventHandler;\n }\n}\n\nexport class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {\n eventType = \"mailer.mail.sendError\" as const;\n\n getHandlerAbstraction() {\n return MailSendErrorEventHandler;\n }\n}\n"],"names":["MailBeforeSendEvent","DomainEvent","MailBeforeSendEventHandler","MailAfterSendEvent","MailAfterSendEventHandler","MailSendErrorEvent","MailSendErrorEventHandler"],"mappings":";;AAYO,MAAMA,4BAA4BC;IAGrC,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMC,2BAA2BF;IAGpC,wBAAwB;QACpB,OAAOG;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMC,2BAA2BJ;IAGpC,wBAAwB;QACpB,OAAOK;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB"}
@@ -0,0 +1,4 @@
1
+ export declare const SendMailFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { SendMailUseCaseImplementation } from "./SendMailUseCase.js";
3
+ const SendMailFeature = createFeature({
4
+ name: "SendMail",
5
+ register (container) {
6
+ container.register(SendMailUseCaseImplementation);
7
+ }
8
+ });
9
+ export { SendMailFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendMail/feature.js","sources":["../../../src/features/SendMail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SendMailUseCaseImplementation } from \"./SendMailUseCase.js\";\n\nexport const SendMailFeature = createFeature({\n name: \"SendMail\",\n register(container) {\n container.register(SendMailUseCaseImplementation);\n }\n});\n"],"names":["SendMailFeature","createFeature","container","SendMailUseCaseImplementation"],"mappings":";;AAGO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1 @@
1
+ export { SendMailUseCase, MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
@@ -0,0 +1 @@
1
+ export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "./abstractions.js";
@@ -0,0 +1,15 @@
1
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
2
+ import { SendTestMailUseCase } from "./abstractions.js";
3
+ import { MailTransportResolver } from "../../domain/MailTransport/abstractions.js";
4
+ import { SendMailUseCase } from "../../features/SendMail/abstractions.js";
5
+ declare class SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {
6
+ private identityContext;
7
+ private transportResolver;
8
+ private sendMailUseCase;
9
+ constructor(identityContext: IdentityContext.Interface, transportResolver: MailTransportResolver.Interface, sendMailUseCase: SendMailUseCase.Interface);
10
+ execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return;
11
+ }
12
+ export declare const SendTestMailUseCaseImplementation: typeof SendTestMailUseCaseImpl & {
13
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendTestMailUseCase>;
14
+ };
15
+ export {};
@@ -0,0 +1,43 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
+ import { SendTestMailUseCase } from "./abstractions.js";
4
+ import { MailTransportResolver } from "../../domain/MailTransport/abstractions.js";
5
+ import { SendMailUseCase } from "../SendMail/abstractions.js";
6
+ import { TestMailNotAuthorized, TestMailNotConfigured } from "../../domain/errors.js";
7
+ import { DUMMY_TRANSPORT_NAME, MAILER_SETTINGS_PERMISSION } from "../../constants.js";
8
+ const TEST_MAIL_TEXT = "This is a test email from Webiny.\n\nIt was sent from the Mailer settings screen to check that mail is delivered. No action is needed.";
9
+ class SendTestMailUseCaseImpl {
10
+ constructor(identityContext, transportResolver, sendMailUseCase){
11
+ this.identityContext = identityContext;
12
+ this.transportResolver = transportResolver;
13
+ this.sendMailUseCase = sendMailUseCase;
14
+ }
15
+ async execute(input) {
16
+ const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
17
+ if (!permission) return Result.fail(new TestMailNotAuthorized());
18
+ const resolved = await this.transportResolver.resolve();
19
+ if (!resolved || resolved.factory.name === DUMMY_TRANSPORT_NAME) return Result.fail(new TestMailNotConfigured());
20
+ const result = await this.sendMailUseCase.execute({
21
+ to: [
22
+ input.to
23
+ ],
24
+ from: resolved.settings?.from || void 0,
25
+ replyTo: resolved.settings?.replyTo || void 0,
26
+ subject: "Webiny test email",
27
+ text: TEST_MAIL_TEXT
28
+ });
29
+ if (result.isFail()) return Result.fail(result.error);
30
+ return Result.ok(void 0);
31
+ }
32
+ }
33
+ const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({
34
+ implementation: SendTestMailUseCaseImpl,
35
+ dependencies: [
36
+ IdentityContext,
37
+ MailTransportResolver,
38
+ SendMailUseCase
39
+ ]
40
+ });
41
+ export { SendTestMailUseCaseImplementation };
42
+
43
+ //# sourceMappingURL=SendTestMailUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendTestMail/SendTestMailUseCase.js","sources":["../../../src/features/SendTestMail/SendTestMailUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { SendTestMailUseCase } from \"./abstractions.js\";\nimport { MailTransportResolver } from \"~/domain/MailTransport/abstractions.js\";\nimport { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\nimport { DUMMY_TRANSPORT_NAME } from \"~/constants.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nconst TEST_MAIL_TEXT = [\n \"This is a test email from Webiny.\",\n \"\",\n \"It was sent from the Mailer settings screen to check that mail is delivered. \" +\n \"No action is needed.\"\n].join(\"\\n\");\n\nclass SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private transportResolver: MailTransportResolver.Interface,\n private sendMailUseCase: SendMailUseCase.Interface\n ) {}\n\n async execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(new TestMailNotAuthorized());\n }\n\n /*\n * The test goes out through whichever transport delivers this project's mail. When that\n * is the dummy transport, it would report success without sending anything, so a test\n * that passed would prove nothing.\n */\n const resolved = await this.transportResolver.resolve();\n if (!resolved || resolved.factory.name === DUMMY_TRANSPORT_NAME) {\n return Result.fail(new TestMailNotConfigured());\n }\n\n const result = await this.sendMailUseCase.execute({\n to: [input.to],\n from: resolved.settings?.from || undefined,\n replyTo: resolved.settings?.replyTo || undefined,\n subject: \"Webiny test email\",\n text: TEST_MAIL_TEXT\n });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(undefined);\n }\n}\n\nexport const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({\n implementation: SendTestMailUseCaseImpl,\n dependencies: [IdentityContext, MailTransportResolver, SendMailUseCase]\n});\n"],"names":["TEST_MAIL_TEXT","SendTestMailUseCaseImpl","identityContext","transportResolver","sendMailUseCase","input","permission","MAILER_SETTINGS_PERMISSION","Result","TestMailNotAuthorized","resolved","DUMMY_TRANSPORT_NAME","TestMailNotConfigured","result","undefined","SendTestMailUseCaseImplementation","SendTestMailUseCase","IdentityContext","MailTransportResolver","SendMailUseCase"],"mappings":";;;;;;;AAUA,MAAMA,iBAAiB;AAOvB,MAAMC;IACF,YACYC,eAA0C,EAC1CC,iBAAkD,EAClDC,eAA0C,CACpD;aAHUF,eAAe,GAAfA;aACAC,iBAAiB,GAAjBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAAgC,EAA8B;QACxE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAQ3B,MAAMC,WAAW,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO;QACrD,IAAI,CAACA,YAAYA,SAAS,OAAO,CAAC,IAAI,KAAKC,sBACvC,OAAOH,OAAO,IAAI,CAAC,IAAII;QAG3B,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAC9C,IAAI;gBAACR,MAAM,EAAE;aAAC;YACd,MAAMK,SAAS,QAAQ,EAAE,QAAQI;YACjC,SAASJ,SAAS,QAAQ,EAAE,WAAWI;YACvC,SAAS;YACT,MAAMd;QACV;QAEA,IAAIa,OAAO,MAAM,IACb,OAAOL,OAAO,IAAI,CAACK,OAAO,KAAK;QAGnC,OAAOL,OAAO,EAAE,CAACM;IACrB;AACJ;AAEO,MAAMC,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgBf;IAChB,cAAc;QAACgB;QAAiBC;QAAuBC;KAAgB;AAC3E"}
@@ -0,0 +1,32 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { SendMailUseCase } from "../../features/SendMail/abstractions.js";
3
+ import { TestMailNotAuthorized } from "../../domain/errors.js";
4
+ import { TestMailNotConfigured } from "../../domain/errors.js";
5
+ export interface SendTestMailInput {
6
+ to: string;
7
+ }
8
+ export interface ISendTestMailErrors {
9
+ notAuthorized: TestMailNotAuthorized;
10
+ notConfigured: TestMailNotConfigured;
11
+ sendMail: SendMailUseCase.Error;
12
+ }
13
+ type SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];
14
+ export interface ISendTestMailUseCase {
15
+ execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;
16
+ }
17
+ /**
18
+ * Sends one message through the transport that delivers this project's mail, so an operator can
19
+ * tell settings that deliver from settings that only look configured. The mail server's own error
20
+ * comes back to the caller.
21
+ *
22
+ * The test goes through `SendMailUseCase` like any other mail, so it publishes the same
23
+ * `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.
24
+ */
25
+ export declare const SendTestMailUseCase: import("@webiny/di").Abstraction<ISendTestMailUseCase>;
26
+ export declare namespace SendTestMailUseCase {
27
+ type Interface = ISendTestMailUseCase;
28
+ type Input = SendTestMailInput;
29
+ type Return = Promise<Result<void, SendTestMailError>>;
30
+ type Error = SendTestMailError;
31
+ }
32
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const SendTestMailUseCase = createAbstraction("SendTestMailUseCase");
3
+ export { SendTestMailUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendTestMail/abstractions.js","sources":["../../../src/features/SendTestMail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\n\nexport interface SendTestMailInput {\n to: string;\n}\n\nexport interface ISendTestMailErrors {\n notAuthorized: TestMailNotAuthorized;\n notConfigured: TestMailNotConfigured;\n sendMail: SendMailUseCase.Error;\n}\n\ntype SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];\n\nexport interface ISendTestMailUseCase {\n execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;\n}\n\n/**\n * Sends one message through the transport that delivers this project's mail, so an operator can\n * tell settings that deliver from settings that only look configured. The mail server's own error\n * comes back to the caller.\n *\n * The test goes through `SendMailUseCase` like any other mail, so it publishes the same\n * `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.\n */\nexport const SendTestMailUseCase = createAbstraction<ISendTestMailUseCase>(\"SendTestMailUseCase\");\n\nexport namespace SendTestMailUseCase {\n export type Interface = ISendTestMailUseCase;\n export type Input = SendTestMailInput;\n export type Return = Promise<Result<void, SendTestMailError>>;\n export type Error = SendTestMailError;\n}\n"],"names":["SendTestMailUseCase","createAbstraction"],"mappings":";AA8BO,MAAMA,sBAAsBC,kBAAwC"}
@@ -0,0 +1,4 @@
1
+ export declare const SendTestMailFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { SendTestMailUseCaseImplementation } from "./SendTestMailUseCase.js";
3
+ const SendTestMailFeature = createFeature({
4
+ name: "SendTestMail",
5
+ register (container) {
6
+ container.register(SendTestMailUseCaseImplementation);
7
+ }
8
+ });
9
+ export { SendTestMailFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SendTestMail/feature.js","sources":["../../../src/features/SendTestMail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SendTestMailUseCaseImplementation } from \"./SendTestMailUseCase.js\";\n\nexport const SendTestMailFeature = createFeature({\n name: \"SendTestMail\",\n register(container) {\n container.register(SendTestMailUseCaseImplementation);\n }\n});\n"],"names":["SendTestMailFeature","createFeature","container","SendTestMailUseCaseImplementation"],"mappings":";;AAGO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,6 @@
1
+ import type { TransportSettings } from "../../types.js";
2
+ import type SMTPTransport from "nodemailer/lib/smtp-transport";
3
+ export type SmtpTransportConfig = SMTPTransport.Options;
4
+ export declare class SmtpConfig {
5
+ static fromTransportSettings(settings: TransportSettings): SmtpTransportConfig;
6
+ }
@@ -0,0 +1,26 @@
1
+ const configDefaults = {
2
+ socketTimeout: 15000,
3
+ connectionTimeout: 15000,
4
+ greetingTimeout: 15000
5
+ };
6
+ class SmtpConfig {
7
+ static fromTransportSettings(settings) {
8
+ const baseConfig = {
9
+ host: settings.host,
10
+ port: settings.port,
11
+ secure: settings.secure,
12
+ auth: {
13
+ user: settings.user,
14
+ pass: settings.password
15
+ }
16
+ };
17
+ return Object.keys(configDefaults).reduce((config, key)=>{
18
+ const configKey = key;
19
+ if (void 0 === config[configKey] || null === config[configKey]) config[configKey] = configDefaults[configKey];
20
+ return config;
21
+ }, baseConfig);
22
+ }
23
+ }
24
+ export { SmtpConfig };
25
+
26
+ //# sourceMappingURL=SmtpConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SmtpTransport/SmtpConfig.js","sources":["../../../src/features/SmtpTransport/SmtpConfig.ts"],"sourcesContent":["import type { TransportSettings } from \"~/types.js\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\n\nexport type SmtpTransportConfig = SMTPTransport.Options;\n\nconst configDefaults: Partial<SmtpTransportConfig> = {\n socketTimeout: 15000,\n connectionTimeout: 15000,\n greetingTimeout: 15000\n};\n\nexport class SmtpConfig {\n static fromTransportSettings(settings: TransportSettings): SmtpTransportConfig {\n const baseConfig: SmtpTransportConfig = {\n host: settings.host,\n port: settings.port,\n secure: settings.secure,\n auth: {\n user: settings.user,\n pass: settings.password\n }\n };\n\n // Apply defaults\n return Object.keys(configDefaults).reduce<SmtpTransportConfig>((config, key) => {\n const configKey = key as keyof SmtpTransportConfig;\n if (config[configKey] === undefined || config[configKey] === null) {\n // @ts-expect-error\n config[configKey] = configDefaults[configKey];\n }\n return config;\n }, baseConfig);\n }\n}\n"],"names":["configDefaults","SmtpConfig","settings","baseConfig","Object","config","key","configKey","undefined"],"mappings":"AAKA,MAAMA,iBAA+C;IACjD,eAAe;IACf,mBAAmB;IACnB,iBAAiB;AACrB;AAEO,MAAMC;IACT,OAAO,sBAAsBC,QAA2B,EAAuB;QAC3E,MAAMC,aAAkC;YACpC,MAAMD,SAAS,IAAI;YACnB,MAAMA,SAAS,IAAI;YACnB,QAAQA,SAAS,MAAM;YACvB,MAAM;gBACF,MAAMA,SAAS,IAAI;gBACnB,MAAMA,SAAS,QAAQ;YAC3B;QACJ;QAGA,OAAOE,OAAO,IAAI,CAACJ,gBAAgB,MAAM,CAAsB,CAACK,QAAQC;YACpE,MAAMC,YAAYD;YAClB,IAAID,AAAsBG,WAAtBH,MAAM,CAACE,UAAU,IAAkBF,AAAsB,SAAtBA,MAAM,CAACE,UAAU,EAEpDF,MAAM,CAACE,UAAU,GAAGP,cAAc,CAACO,UAAU;YAEjD,OAAOF;QACX,GAAGF;IACP;AACJ"}
@@ -0,0 +1,77 @@
1
+ import type SMTPTransport from "nodemailer/lib/smtp-transport";
2
+ import { MailTransport } from "../../domain/MailTransport/abstractions.js";
3
+ export declare class SmtpMailTransport implements MailTransport.Interface {
4
+ private readonly defaultFrom?;
5
+ readonly name = "Mailer/SmtpTransport";
6
+ private readonly transporter;
7
+ constructor(config: SMTPTransport.Options, defaultFrom?: string | undefined);
8
+ send(params: MailTransport.SendParams): Promise<{
9
+ result: string;
10
+ error: null;
11
+ } | {
12
+ result: null;
13
+ error: {
14
+ message: string;
15
+ code: string;
16
+ data: {
17
+ [key: string]: any;
18
+ ehlo?: string[] | undefined;
19
+ rejectedErrors?: import("nodemailer").NodemailerError[] | undefined;
20
+ envelopeTime: number;
21
+ messageTime: number;
22
+ messageSize: number;
23
+ serverMessageId?: string | undefined;
24
+ envelope: import("nodemailer/lib/mime-node").MimeNodeEnvelope;
25
+ messageId: string;
26
+ accepted: string[];
27
+ rejected: string[];
28
+ response: string;
29
+ pending?: string[] | undefined;
30
+ message?: any;
31
+ };
32
+ };
33
+ } | {
34
+ result: null;
35
+ error: {
36
+ message: string;
37
+ code: any;
38
+ data: {
39
+ to?: string[];
40
+ cc?: string[];
41
+ bcc: string[];
42
+ from?: string;
43
+ subject: string;
44
+ text?: string;
45
+ html?: string;
46
+ replyTo?: string;
47
+ command: any;
48
+ response: any;
49
+ responseCode: any;
50
+ } | {
51
+ to?: string[];
52
+ cc: string[];
53
+ bcc?: string[];
54
+ from?: string;
55
+ subject: string;
56
+ text?: string;
57
+ html?: string;
58
+ replyTo?: string;
59
+ command: any;
60
+ response: any;
61
+ responseCode: any;
62
+ } | {
63
+ to: string[];
64
+ cc?: string[];
65
+ bcc?: string[];
66
+ from?: string;
67
+ subject: string;
68
+ text?: string;
69
+ html?: string;
70
+ replyTo?: string;
71
+ command: any;
72
+ response: any;
73
+ responseCode: any;
74
+ };
75
+ };
76
+ }>;
77
+ }
@@ -0,0 +1,60 @@
1
+ import nodemailer from "nodemailer";
2
+ import { SMTP_TRANSPORT_NAME } from "../../constants.js";
3
+ const getErrorMessage = (ex)=>{
4
+ if (ex.message) return ex.message;
5
+ if (Array.isArray(ex.errors)) return ex.errors.map((error)=>error.message).filter(Boolean).join("; ");
6
+ return "";
7
+ };
8
+ class SmtpMailTransport {
9
+ constructor(config, defaultFrom){
10
+ this.defaultFrom = defaultFrom;
11
+ this.name = SMTP_TRANSPORT_NAME;
12
+ this.transporter = nodemailer.createTransport(config);
13
+ }
14
+ async send(params) {
15
+ const { replyTo, text, html, to, bcc, cc, from, subject } = params;
16
+ try {
17
+ const result = await this.transporter.sendMail({
18
+ replyTo,
19
+ bcc,
20
+ cc,
21
+ from: from || this.defaultFrom || void 0,
22
+ text,
23
+ html,
24
+ to,
25
+ subject
26
+ });
27
+ if (result.messageId) return {
28
+ result: result.response,
29
+ error: null
30
+ };
31
+ return {
32
+ result: null,
33
+ error: {
34
+ message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
35
+ code: "MAILER_ERROR",
36
+ data: {
37
+ ...result
38
+ }
39
+ }
40
+ };
41
+ } catch (ex) {
42
+ return {
43
+ result: null,
44
+ error: {
45
+ message: getErrorMessage(ex),
46
+ code: ex.code,
47
+ data: {
48
+ ...params,
49
+ command: ex.command,
50
+ response: ex.response,
51
+ responseCode: ex.responseCode
52
+ }
53
+ }
54
+ };
55
+ }
56
+ }
57
+ }
58
+ export { SmtpMailTransport };
59
+
60
+ //# sourceMappingURL=SmtpMailTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/SmtpTransport/SmtpMailTransport.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\nimport { SMTP_TRANSPORT_NAME } from \"~/constants.js\";\n\n/*\n * A host with both IPv4 and IPv6 addresses (`localhost`, most mail providers) fails to connect\n * with an AggregateError: one error per address and an empty message of its own.\n */\nconst getErrorMessage = (ex: any): string => {\n if (ex.message) {\n return ex.message;\n }\n if (Array.isArray(ex.errors)) {\n return ex.errors\n .map((error: Error) => error.message)\n .filter(Boolean)\n .join(\"; \");\n }\n return \"\";\n};\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = SMTP_TRANSPORT_NAME;\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(\n config: SMTPTransport.Options,\n private readonly defaultFrom?: string\n ) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n // An explicit sender wins; otherwise the configured settings sender (R201).\n // An empty default counts as none, so a missing settings `from` changes nothing.\n from: from || this.defaultFrom || undefined,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n // Allow-list specific nodemailer/SMTP error fields. Spreading `ex`\n // or `ex.data` blindly would risk surfacing the transporter's auth\n // config (or anything else a future nodemailer version stamps onto\n // its errors) in error responses.\n return {\n result: null,\n error: {\n message: getErrorMessage(ex),\n code: ex.code,\n data: {\n ...params,\n command: ex.command,\n response: ex.response,\n responseCode: ex.responseCode\n }\n }\n };\n }\n }\n}\n"],"names":["getErrorMessage","ex","Array","error","Boolean","SmtpMailTransport","config","defaultFrom","SMTP_TRANSPORT_NAME","nodemailer","params","replyTo","text","html","to","bcc","cc","from","subject","result","undefined"],"mappings":";;AAUA,MAAMA,kBAAkB,CAACC;IACrB,IAAIA,GAAG,OAAO,EACV,OAAOA,GAAG,OAAO;IAErB,IAAIC,MAAM,OAAO,CAACD,GAAG,MAAM,GACvB,OAAOA,GAAG,MAAM,CACX,GAAG,CAAC,CAACE,QAAiBA,MAAM,OAAO,EACnC,MAAM,CAACC,SACP,IAAI,CAAC;IAEd,OAAO;AACX;AAEO,MAAMC;IAIT,YACIC,MAA6B,EACZC,WAAoB,CACvC;aADmBA,WAAW,GAAXA;aALL,IAAI,GAAGC;QAOnB,IAAI,CAAC,WAAW,GAAGC,WAAW,eAAe,CAACH;IAClD;IAEA,MAAM,KAAKI,MAAgC,EAAE;QACzC,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAEC,EAAE,EAAEC,GAAG,EAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAGR;QAE5D,IAAI;YACA,MAAMS,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBAC3CR;gBACAI;gBACAC;gBAGA,MAAMC,QAAQ,IAAI,CAAC,WAAW,IAAIG;gBAClCR;gBACAC;gBACAC;gBACAI;YACJ;YAEA,IAAIC,OAAO,SAAS,EAChB,OAAO;gBACH,QAAQA,OAAO,QAAQ;gBACvB,OAAO;YACX;YAGJ,OAAO;gBACH,QAAQ;gBACR,OAAO;oBACH,SACI;oBACJ,MAAM;oBACN,MAAM;wBACF,GAAGA,MAAM;oBACb;gBACJ;YACJ;QACJ,EAAE,OAAOlB,IAAS;YAKd,OAAO;gBACH,QAAQ;gBACR,OAAO;oBACH,SAASD,gBAAgBC;oBACzB,MAAMA,GAAG,IAAI;oBACb,MAAM;wBACF,GAAGS,MAAM;wBACT,SAAST,GAAG,OAAO;wBACnB,UAAUA,GAAG,QAAQ;wBACrB,cAAcA,GAAG,YAAY;oBACjC;gBACJ;YACJ;QACJ;IACJ;AACJ"}
@@ -0,0 +1,11 @@
1
+ import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
2
+ import type { TransportSettings } from "../../types.js";
3
+ declare class SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {
4
+ readonly name = "Mailer/SmtpTransport";
5
+ canUse(settings: TransportSettings | null): boolean;
6
+ createTransport(settings: TransportSettings): MailTransportFactory.Return;
7
+ }
8
+ export declare const SmtpMailTransportFactory: typeof SmtpMailTransportFactoryImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportFactory>;
10
+ };
11
+ export {};