@webiny/api-mailer 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7c2def32a7

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 +25 -0
  3. package/MailerFeature.js.map +1 -0
  4. package/README.md +10 -13
  5. package/constants.d.ts +1 -0
  6. package/constants.js +4 -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 +20 -0
  12. package/domain/MailTransport/abstractions.js +6 -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 +28 -0
  21. package/domain/errors.js +48 -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 +14 -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 +20 -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/MailerService.d.ts +15 -0
  55. package/features/MailerService/MailerService.js +59 -0
  56. package/features/MailerService/MailerService.js.map +1 -0
  57. package/features/MailerService/feature.d.ts +4 -0
  58. package/features/MailerService/feature.js +11 -0
  59. package/features/MailerService/feature.js.map +1 -0
  60. package/features/SaveSettings/SaveSettingsRepository.d.ts +13 -0
  61. package/features/SaveSettings/SaveSettingsRepository.js +45 -0
  62. package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
  63. package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
  64. package/features/SaveSettings/SaveSettingsUseCase.js +56 -0
  65. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
  66. package/features/SaveSettings/abstractions.d.ts +62 -0
  67. package/features/SaveSettings/abstractions.js +8 -0
  68. package/features/SaveSettings/abstractions.js.map +1 -0
  69. package/features/SaveSettings/events.d.ts +10 -0
  70. package/features/SaveSettings/events.js +21 -0
  71. package/features/SaveSettings/events.js.map +1 -0
  72. package/features/SaveSettings/feature.d.ts +4 -0
  73. package/features/SaveSettings/feature.js +13 -0
  74. package/features/SaveSettings/feature.js.map +1 -0
  75. package/features/SaveSettings/index.d.ts +1 -0
  76. package/features/SaveSettings/index.js +1 -0
  77. package/features/SaveSettings/validation.d.ts +10 -0
  78. package/features/SaveSettings/validation.js +21 -0
  79. package/features/SaveSettings/validation.js.map +1 -0
  80. package/features/SendMail/SendMailUseCase.d.ts +16 -0
  81. package/features/SendMail/SendMailUseCase.js +58 -0
  82. package/features/SendMail/SendMailUseCase.js.map +1 -0
  83. package/features/SendMail/abstractions.d.ts +45 -0
  84. package/features/SendMail/abstractions.js +8 -0
  85. package/features/SendMail/abstractions.js.map +1 -0
  86. package/features/SendMail/events.d.ts +14 -0
  87. package/features/SendMail/events.js +29 -0
  88. package/features/SendMail/events.js.map +1 -0
  89. package/features/SendMail/feature.d.ts +4 -0
  90. package/features/SendMail/feature.js +11 -0
  91. package/features/SendMail/feature.js.map +1 -0
  92. package/features/SendMail/index.d.ts +1 -0
  93. package/features/SendMail/index.js +1 -0
  94. package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
  95. package/features/SmtpTransport/SmtpConfig.js +26 -0
  96. package/features/SmtpTransport/SmtpConfig.js.map +1 -0
  97. package/features/SmtpTransport/SmtpMailTransport.d.ts +68 -0
  98. package/features/SmtpTransport/SmtpMailTransport.js +53 -0
  99. package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
  100. package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +11 -0
  101. package/features/SmtpTransport/SmtpMailTransportFactory.js +21 -0
  102. package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
  103. package/features/SmtpTransport/feature.d.ts +4 -0
  104. package/features/SmtpTransport/feature.js +11 -0
  105. package/features/SmtpTransport/feature.js.map +1 -0
  106. package/graphql/MailerSchemaFactory.d.ts +10 -0
  107. package/graphql/MailerSchemaFactory.js +121 -0
  108. package/graphql/MailerSchemaFactory.js.map +1 -0
  109. package/index.d.ts +3 -8
  110. package/index.js +2 -89
  111. package/package.json +29 -45
  112. package/types.d.ts +3 -109
  113. package/types.js +0 -5
  114. package/utils/isMailboxAddress.d.ts +6 -0
  115. package/utils/isMailboxAddress.js +5 -0
  116. package/utils/isMailboxAddress.js.map +1 -0
  117. package/context.d.ts +0 -3
  118. package/context.js +0 -24
  119. package/context.js.map +0 -1
  120. package/crud/group.d.ts +0 -2
  121. package/crud/group.js +0 -21
  122. package/crud/group.js.map +0 -1
  123. package/crud/mailer/onBeforeSend.d.ts +0 -7
  124. package/crud/mailer/onBeforeSend.js +0 -69
  125. package/crud/mailer/onBeforeSend.js.map +0 -1
  126. package/crud/mailer.crud.d.ts +0 -2
  127. package/crud/mailer.crud.js +0 -123
  128. package/crud/mailer.crud.js.map +0 -1
  129. package/crud/settings/hooks.d.ts +0 -5
  130. package/crud/settings/hooks.js +0 -55
  131. package/crud/settings/hooks.js.map +0 -1
  132. package/crud/settings/model.d.ts +0 -3
  133. package/crud/settings/model.js +0 -90
  134. package/crud/settings/model.js.map +0 -1
  135. package/crud/settings/password.d.ts +0 -7
  136. package/crud/settings/password.js +0 -71
  137. package/crud/settings/password.js.map +0 -1
  138. package/crud/settings/secret.d.ts +0 -1
  139. package/crud/settings/secret.js +0 -23
  140. package/crud/settings/secret.js.map +0 -1
  141. package/crud/settings/transform.d.ts +0 -13
  142. package/crud/settings/transform.js +0 -56
  143. package/crud/settings/transform.js.map +0 -1
  144. package/crud/settings/validation.d.ts +0 -4
  145. package/crud/settings/validation.js +0 -38
  146. package/crud/settings/validation.js.map +0 -1
  147. package/crud/settings.crud.d.ts +0 -5
  148. package/crud/settings.crud.js +0 -331
  149. package/crud/settings.crud.js.map +0 -1
  150. package/crud/transport/onTransportBeforeSend.d.ts +0 -7
  151. package/crud/transport/onTransportBeforeSend.js +0 -69
  152. package/crud/transport/onTransportBeforeSend.js.map +0 -1
  153. package/crud/transporter.crud.d.ts +0 -2
  154. package/crud/transporter.crud.js +0 -193
  155. package/crud/transporter.crud.js.map +0 -1
  156. package/graphql/index.d.ts +0 -1
  157. package/graphql/index.js +0 -14
  158. package/graphql/index.js.map +0 -1
  159. package/graphql/settings.d.ts +0 -3
  160. package/graphql/settings.js +0 -109
  161. package/graphql/settings.js.map +0 -1
  162. package/index.js.map +0 -1
  163. package/mailers/createDummyMailer.d.ts +0 -5
  164. package/mailers/createDummyMailer.js +0 -24
  165. package/mailers/createDummyMailer.js.map +0 -1
  166. package/mailers/createSmtpMailer.d.ts +0 -13
  167. package/mailers/createSmtpMailer.js +0 -106
  168. package/mailers/createSmtpMailer.js.map +0 -1
  169. package/plugins/CreateTransportPlugin.d.ts +0 -17
  170. package/plugins/CreateTransportPlugin.js +0 -34
  171. package/plugins/CreateTransportPlugin.js.map +0 -1
  172. package/plugins/index.d.ts +0 -1
  173. package/plugins/index.js +0 -18
  174. package/plugins/index.js.map +0 -1
  175. package/transports/createDummyTransport.d.ts +0 -5
  176. package/transports/createDummyTransport.js +0 -25
  177. package/transports/createDummyTransport.js.map +0 -1
  178. package/transports/createSmtpTransport.d.ts +0 -12
  179. package/transports/createSmtpTransport.js +0 -101
  180. package/transports/createSmtpTransport.js.map +0 -1
  181. package/types.js.map +0 -1
@@ -1 +0,0 @@
1
- export declare const createGraphQL: () => import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("../types").MailerContext>[];
package/graphql/index.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createGraphQL = void 0;
7
-
8
- var _settings = require("./settings");
9
-
10
- const createGraphQL = () => {
11
- return [(0, _settings.createSettingsGraphQL)()];
12
- };
13
-
14
- exports.createGraphQL = createGraphQL;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createGraphQL","createSettingsGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createSettingsGraphQL } from \"~/graphql/settings\";\n\nexport const createGraphQL = () => {\n return [createSettingsGraphQL()];\n};\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,aAAa,GAAG,MAAM;EAC/B,OAAO,CAAC,IAAAC,+BAAA,GAAD,CAAP;AACH,CAFM"}
@@ -1,3 +0,0 @@
1
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
- import { MailerContext } from "../types";
3
- export declare const createSettingsGraphQL: () => GraphQLSchemaPlugin<MailerContext>;
@@ -1,109 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createSettingsGraphQL = void 0;
7
-
8
- var _handlerGraphql = require("@webiny/handler-graphql");
9
-
10
- const emptyResolver = () => ({});
11
-
12
- const createSettingsGraphQL = () => {
13
- return new _handlerGraphql.GraphQLSchemaPlugin({
14
- typeDefs: `
15
- type MailerTransportSettingsError {
16
- message: String!
17
- code: String
18
- data: JSON
19
- }
20
-
21
- type MailerTransportSettings {
22
- host: String
23
- port: Number
24
- user: String
25
- from: String
26
- replyTo: String
27
- }
28
-
29
- type MailerSettingsResponse {
30
- data: MailerTransportSettings
31
- error: MailerTransportSettingsError
32
- }
33
-
34
- type MailerQuery {
35
- getSettings: MailerSettingsResponse!
36
- }
37
-
38
- input TransportSettingsInput {
39
- host: String!
40
- port: Number
41
- user: String!
42
- password: String
43
- from: String!
44
- replyTo: String
45
- }
46
-
47
- type MailerMutation {
48
- saveSettings(data: TransportSettingsInput!): MailerSettingsResponse!
49
- }
50
-
51
- extend type Query {
52
- mailer: MailerQuery
53
- }
54
- extend type Mutation {
55
- mailer: MailerMutation
56
- }
57
- `,
58
- resolvers: {
59
- Query: {
60
- mailer: emptyResolver
61
- },
62
- MailerQuery: {
63
- getSettings: async (_, __, context) => {
64
- try {
65
- const settings = await context.mailer.getSettings();
66
- /**
67
- * We want to remove the password from the response
68
- */
69
-
70
- if (settings) {
71
- // @ts-ignore
72
- delete settings.password;
73
- }
74
-
75
- return new _handlerGraphql.Response(settings);
76
- } catch (ex) {
77
- return new _handlerGraphql.ErrorResponse(ex);
78
- }
79
- }
80
- },
81
- Mutation: {
82
- mailer: emptyResolver
83
- },
84
- MailerMutation: {
85
- saveSettings: async (_, args, context) => {
86
- try {
87
- const settings = await context.mailer.saveSettings({
88
- input: args.data
89
- });
90
- /**
91
- * We want to remove the password from the response
92
- */
93
-
94
- if (settings) {
95
- // @ts-ignore
96
- delete settings.password;
97
- }
98
-
99
- return new _handlerGraphql.Response(settings);
100
- } catch (ex) {
101
- return new _handlerGraphql.ErrorResponse(ex);
102
- }
103
- }
104
- }
105
- }
106
- });
107
- };
108
-
109
- exports.createSettingsGraphQL = createSettingsGraphQL;
@@ -1 +0,0 @@
1
- {"version":3,"names":["emptyResolver","createSettingsGraphQL","GraphQLSchemaPlugin","typeDefs","resolvers","Query","mailer","MailerQuery","getSettings","_","__","context","settings","password","Response","ex","ErrorResponse","Mutation","MailerMutation","saveSettings","args","input","data"],"sources":["settings.ts"],"sourcesContent":["import { ErrorResponse, GraphQLSchemaPlugin, Response } from \"@webiny/handler-graphql\";\nimport { MailerContext } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\nexport const createSettingsGraphQL = () => {\n return new GraphQLSchemaPlugin<MailerContext>({\n typeDefs: `\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n \n type MailerTransportSettings {\n host: String\n port: Number\n user: String\n from: String\n replyTo: String\n }\n \n type MailerSettingsResponse {\n data: MailerTransportSettings\n error: MailerTransportSettingsError\n }\n \n type MailerQuery {\n getSettings: MailerSettingsResponse!\n }\n \n input TransportSettingsInput {\n host: String!\n port: Number\n user: String!\n password: String\n from: String!\n replyTo: String\n }\n \n type MailerMutation {\n saveSettings(data: TransportSettingsInput!): MailerSettingsResponse!\n }\n \n extend type Query {\n mailer: MailerQuery\n }\n extend type Mutation {\n mailer: MailerMutation\n }\n `,\n resolvers: {\n Query: {\n mailer: emptyResolver\n },\n MailerQuery: {\n getSettings: async (_, __, context) => {\n try {\n const settings = await context.mailer.getSettings();\n /**\n * We want to remove the password from the response\n */\n if (settings) {\n // @ts-ignore\n delete settings.password;\n }\n return new Response(settings);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n },\n Mutation: {\n mailer: emptyResolver\n },\n MailerMutation: {\n saveSettings: async (_, args: any, context) => {\n try {\n const settings = await context.mailer.saveSettings({\n input: args.data\n });\n /**\n * We want to remove the password from the response\n */\n if (settings) {\n // @ts-ignore\n delete settings.password;\n }\n return new Response(settings);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n }\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAGA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;;AAEO,MAAMC,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIC,mCAAJ,CAAuC;IAC1CC,QAAQ,EAAG;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SA5CkD;IA6C1CC,SAAS,EAAE;MACPC,KAAK,EAAE;QACHC,MAAM,EAAEN;MADL,CADA;MAIPO,WAAW,EAAE;QACTC,WAAW,EAAE,OAAOC,CAAP,EAAUC,EAAV,EAAcC,OAAd,KAA0B;UACnC,IAAI;YACA,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACL,MAAR,CAAeE,WAAf,EAAvB;YACA;AACxB;AACA;;YACwB,IAAII,QAAJ,EAAc;cACV;cACA,OAAOA,QAAQ,CAACC,QAAhB;YACH;;YACD,OAAO,IAAIC,wBAAJ,CAAaF,QAAb,CAAP;UACH,CAVD,CAUE,OAAOG,EAAP,EAAW;YACT,OAAO,IAAIC,6BAAJ,CAAkBD,EAAlB,CAAP;UACH;QACJ;MAfQ,CAJN;MAqBPE,QAAQ,EAAE;QACNX,MAAM,EAAEN;MADF,CArBH;MAwBPkB,cAAc,EAAE;QACZC,YAAY,EAAE,OAAOV,CAAP,EAAUW,IAAV,EAAqBT,OAArB,KAAiC;UAC3C,IAAI;YACA,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACL,MAAR,CAAea,YAAf,CAA4B;cAC/CE,KAAK,EAAED,IAAI,CAACE;YADmC,CAA5B,CAAvB;YAGA;AACxB;AACA;;YACwB,IAAIV,QAAJ,EAAc;cACV;cACA,OAAOA,QAAQ,CAACC,QAAhB;YACH;;YACD,OAAO,IAAIC,wBAAJ,CAAaF,QAAb,CAAP;UACH,CAZD,CAYE,OAAOG,EAAP,EAAW;YACT,OAAO,IAAIC,6BAAJ,CAAkBD,EAAlB,CAAP;UACH;QACJ;MAjBW;IAxBT;EA7C+B,CAAvC,CAAP;AA0FH,CA3FM"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["createMailerContext","group","createGroup","createSettingsModel","createTransport","plugin","createDummyTransport","name","settings","config","auth","user","pass","password","createSmtpTransport","createMailerContextPlugin","createMailerGraphQL","createGraphQL"],"sources":["index.ts"],"sourcesContent":["import { PluginCollection } from \"@webiny/plugins/types\";\nimport { createMailerContext as createMailerContextPlugin } from \"~/context\";\nimport { createDummyTransport, DummyTransport } from \"~/transports/createDummyTransport\";\nimport {\n createSmtpTransport,\n SmtpTransport,\n SmtpTransportConfig\n} from \"~/transports/createSmtpTransport\";\nimport { createTransport } from \"~/plugins\";\nimport { createSettingsModel } from \"~/crud/settings/model\";\nimport { createGroup } from \"~/crud/group\";\nimport { createGraphQL } from \"~/graphql\";\n\nexport { createDummyTransport, createSmtpTransport, createTransport };\nexport type { SmtpTransport, SmtpTransportConfig, DummyTransport };\n\nexport const createMailerContext = (): PluginCollection => {\n const group = createGroup();\n return [\n group,\n /**\n * Groups and models to use via the CMS\n */\n createSettingsModel(group),\n /**\n * If something is wrong with the smtp mailer, we will initialize the dummy one.\n */\n createTransport(async () => {\n const plugin = await createDummyTransport();\n plugin.name = \"dummy-default\";\n return plugin;\n }),\n /**\n * Smtp mailer goes into the plugins after the dummy one because plugins are loaded in reverse.\n */\n createTransport(async ({ settings }) => {\n /**\n * We need to map our settings to the required settings for the SMTP NodeMailer transport.\n */\n const config: SmtpTransportConfig = {\n ...(settings || {})\n };\n if (settings) {\n config.auth = {\n user: settings.user,\n pass: settings.password\n };\n }\n const plugin = await createSmtpTransport(config);\n plugin.name = \"smtp-default\";\n return plugin;\n }),\n createMailerContextPlugin()\n ];\n};\n\nexport const createMailerGraphQL = () => {\n return [...createGraphQL()];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAKO,MAAMA,mBAAmB,GAAG,MAAwB;EACvD,MAAMC,KAAK,GAAG,IAAAC,kBAAA,GAAd;EACA,OAAO,CACHD,KADG;EAEH;AACR;AACA;EACQ,IAAAE,0BAAA,EAAoBF,KAApB,CALG;EAMH;AACR;AACA;EACQ,IAAAG,wBAAA,EAAgB,YAAY;IACxB,MAAMC,MAAM,GAAG,MAAM,IAAAC,0CAAA,GAArB;IACAD,MAAM,CAACE,IAAP,GAAc,eAAd;IACA,OAAOF,MAAP;EACH,CAJD,CATG;EAcH;AACR;AACA;EACQ,IAAAD,wBAAA,EAAgB,OAAO;IAAEI;EAAF,CAAP,KAAwB;IACpC;AACZ;AACA;IACY,MAAMC,MAA2B,mCACzBD,QAAQ,IAAI,EADa,CAAjC;;IAGA,IAAIA,QAAJ,EAAc;MACVC,MAAM,CAACC,IAAP,GAAc;QACVC,IAAI,EAAEH,QAAQ,CAACG,IADL;QAEVC,IAAI,EAAEJ,QAAQ,CAACK;MAFL,CAAd;IAIH;;IACD,MAAMR,MAAM,GAAG,MAAM,IAAAS,wCAAA,EAAoBL,MAApB,CAArB;IACAJ,MAAM,CAACE,IAAP,GAAc,cAAd;IACA,OAAOF,MAAP;EACH,CAhBD,CAjBG,EAkCH,IAAAU,4BAAA,GAlCG,CAAP;AAoCH,CAtCM;;;;AAwCA,MAAMC,mBAAmB,GAAG,MAAM;EACrC,OAAO,CAAC,GAAG,IAAAC,sBAAA,GAAJ,CAAP;AACH,CAFM"}
@@ -1,5 +0,0 @@
1
- import { Mailer, MailerSendData } from "../types";
2
- export interface DummyMailer extends Mailer {
3
- getAllSent: () => MailerSendData[];
4
- }
5
- export declare const createDummyMailer: () => DummyMailer;
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDummyMailer = void 0;
7
-
8
- const createDummyMailer = () => {
9
- const sent = [];
10
- return {
11
- send: async params => {
12
- sent.push(params);
13
- return {
14
- result: true,
15
- error: null
16
- };
17
- },
18
- getAllSent: () => {
19
- return sent;
20
- }
21
- };
22
- };
23
-
24
- exports.createDummyMailer = createDummyMailer;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createDummyMailer","sent","send","params","push","result","error","getAllSent"],"sources":["createDummyMailer.ts"],"sourcesContent":["import { Mailer, MailerSendData } from \"~/types\";\n\nexport interface DummyMailer extends Mailer {\n getAllSent: () => MailerSendData[];\n}\nexport const createDummyMailer = (): DummyMailer => {\n const sent: MailerSendData[] = [];\n\n return {\n send: async params => {\n sent.push(params);\n return {\n result: true,\n error: null\n };\n },\n getAllSent: () => {\n return sent;\n }\n };\n};\n"],"mappings":";;;;;;;AAKO,MAAMA,iBAAiB,GAAG,MAAmB;EAChD,MAAMC,IAAsB,GAAG,EAA/B;EAEA,OAAO;IACHC,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClBF,IAAI,CAACG,IAAL,CAAUD,MAAV;MACA,OAAO;QACHE,MAAM,EAAE,IADL;QAEHC,KAAK,EAAE;MAFJ,CAAP;IAIH,CAPE;IAQHC,UAAU,EAAE,MAAM;MACd,OAAON,IAAP;IACH;EAVE,CAAP;AAYH,CAfM"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Nodemailer docs
3
- * https://nodemailer.com/about/
4
- */
5
- import { Mailer } from "../types";
6
- import { Transporter } from "nodemailer";
7
- import SMTPTransport, { Options } from "nodemailer/lib/smtp-transport";
8
- import { DummyMailer } from "./createDummyMailer";
9
- export declare type SmtpMailerConfig = Options;
10
- export interface SmtpMailer extends Mailer {
11
- transporter: Transporter<SMTPTransport.SentMessageInfo>;
12
- }
13
- export declare const createSmtpMailer: (config?: SmtpMailerConfig) => SmtpMailer | DummyMailer;
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createSmtpMailer = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _nodemailer = _interopRequireDefault(require("nodemailer"));
15
-
16
- var _createDummyMailer = require("./createDummyMailer");
17
-
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
-
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
- const variables = {
23
- host: process.env.WEBINY_MAILER_HOST,
24
- user: process.env.WEBINY_MAILER_USER,
25
- password: process.env.WEBINY_MAILER_PASSWORD
26
- };
27
-
28
- const createSmtpMailer = config => {
29
- /**
30
- * If we have environment variables, use those as config.
31
- */
32
- if (variables.host && variables.user && variables.password) {
33
- if (config) {
34
- throw new _error.default({
35
- message: `Cannot use both config and environment variables to setup the nodemailer.`,
36
- code: "SMTP_MAILER_INIT_ERROR"
37
- });
38
- }
39
-
40
- config = {
41
- host: variables.host,
42
- auth: {
43
- user: variables.user,
44
- pass: variables.password
45
- }
46
- };
47
- } else if (!config) {
48
- console.log("There is no config or required environment variables defined. Using dummy mailer.");
49
- return (0, _createDummyMailer.createDummyMailer)();
50
- }
51
-
52
- const transporter = _nodemailer.default.createTransport(_objectSpread({}, config));
53
-
54
- return {
55
- transporter,
56
- send: async params => {
57
- const {
58
- replyTo,
59
- text,
60
- html,
61
- to,
62
- bcc,
63
- cc,
64
- from,
65
- subject
66
- } = params;
67
-
68
- try {
69
- const result = await transporter.sendMail({
70
- replyTo,
71
- bcc,
72
- cc,
73
- from,
74
- text,
75
- html,
76
- to,
77
- subject
78
- });
79
-
80
- if (result.messageId) {
81
- return {
82
- result: true,
83
- error: null
84
- };
85
- }
86
-
87
- throw new _error.default({
88
- message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
89
- code: "MAILER_ERROR",
90
- data: _objectSpread({}, result)
91
- });
92
- } catch (ex) {
93
- return {
94
- result: null,
95
- error: {
96
- message: ex.message,
97
- code: ex.code,
98
- data: _objectSpread(_objectSpread({}, params), ex.data)
99
- }
100
- };
101
- }
102
- }
103
- };
104
- };
105
-
106
- exports.createSmtpMailer = createSmtpMailer;
@@ -1 +0,0 @@
1
- {"version":3,"names":["variables","host","process","env","WEBINY_MAILER_HOST","user","WEBINY_MAILER_USER","password","WEBINY_MAILER_PASSWORD","createSmtpMailer","config","WebinyError","message","code","auth","pass","console","log","createDummyMailer","transporter","nodemailer","createTransport","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","error","data","ex"],"sources":["createSmtpMailer.ts"],"sourcesContent":["/**\n * Nodemailer docs\n * https://nodemailer.com/about/\n */\nimport { Mailer } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport nodemailer, { Transporter } from \"nodemailer\";\nimport SMTPTransport, { Options } from \"nodemailer/lib/smtp-transport\";\nimport { createDummyMailer, DummyMailer } from \"~/mailers/createDummyMailer\";\n\nexport type SmtpMailerConfig = Options;\n\nexport interface SmtpMailer extends Mailer {\n transporter: Transporter<SMTPTransport.SentMessageInfo>;\n}\n\ninterface SmtpMailerEnvironmentVariables {\n host?: string;\n user?: string;\n password?: string;\n}\nconst variables: SmtpMailerEnvironmentVariables = {\n host: process.env.WEBINY_MAILER_HOST,\n user: process.env.WEBINY_MAILER_USER,\n password: process.env.WEBINY_MAILER_PASSWORD\n};\n\nexport const createSmtpMailer = (config?: SmtpMailerConfig): SmtpMailer | DummyMailer => {\n /**\n * If we have environment variables, use those as config.\n */\n if (variables.host && variables.user && variables.password) {\n if (config) {\n throw new WebinyError({\n message: `Cannot use both config and environment variables to setup the nodemailer.`,\n code: \"SMTP_MAILER_INIT_ERROR\"\n });\n }\n config = {\n host: variables.host,\n auth: {\n user: variables.user,\n pass: variables.password\n }\n };\n } else if (!config) {\n console.log(\n \"There is no config or required environment variables defined. Using dummy mailer.\"\n );\n return createDummyMailer();\n }\n const transporter = nodemailer.createTransport({\n ...config\n });\n\n return {\n transporter,\n send: async params => {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n if (result.messageId) {\n return {\n result: true,\n error: null\n };\n }\n\n throw new WebinyError({\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 } catch (ex) {\n return {\n result: null,\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...params,\n ...ex.data\n }\n }\n };\n }\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA;;AACA;;AAEA;;;;;;AAaA,MAAMA,SAAyC,GAAG;EAC9CC,IAAI,EAAEC,OAAO,CAACC,GAAR,CAAYC,kBAD4B;EAE9CC,IAAI,EAAEH,OAAO,CAACC,GAAR,CAAYG,kBAF4B;EAG9CC,QAAQ,EAAEL,OAAO,CAACC,GAAR,CAAYK;AAHwB,CAAlD;;AAMO,MAAMC,gBAAgB,GAAIC,MAAD,IAAyD;EACrF;AACJ;AACA;EACI,IAAIV,SAAS,CAACC,IAAV,IAAkBD,SAAS,CAACK,IAA5B,IAAoCL,SAAS,CAACO,QAAlD,EAA4D;IACxD,IAAIG,MAAJ,EAAY;MACR,MAAM,IAAIC,cAAJ,CAAgB;QAClBC,OAAO,EAAG,2EADQ;QAElBC,IAAI,EAAE;MAFY,CAAhB,CAAN;IAIH;;IACDH,MAAM,GAAG;MACLT,IAAI,EAAED,SAAS,CAACC,IADX;MAELa,IAAI,EAAE;QACFT,IAAI,EAAEL,SAAS,CAACK,IADd;QAEFU,IAAI,EAAEf,SAAS,CAACO;MAFd;IAFD,CAAT;EAOH,CAdD,MAcO,IAAI,CAACG,MAAL,EAAa;IAChBM,OAAO,CAACC,GAAR,CACI,mFADJ;IAGA,OAAO,IAAAC,oCAAA,GAAP;EACH;;EACD,MAAMC,WAAW,GAAGC,mBAAA,CAAWC,eAAX,mBACbX,MADa,EAApB;;EAIA,OAAO;IACHS,WADG;IAEHG,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClB,MAAM;QAAEC,OAAF;QAAWC,IAAX;QAAiBC,IAAjB;QAAuBC,EAAvB;QAA2BC,GAA3B;QAAgCC,EAAhC;QAAoCC,IAApC;QAA0CC;MAA1C,IAAsDR,MAA5D;;MAEA,IAAI;QACA,MAAMS,MAAM,GAAG,MAAMb,WAAW,CAACc,QAAZ,CAAqB;UACtCT,OADsC;UAEtCI,GAFsC;UAGtCC,EAHsC;UAItCC,IAJsC;UAKtCL,IALsC;UAMtCC,IANsC;UAOtCC,EAPsC;UAQtCI;QARsC,CAArB,CAArB;;QAUA,IAAIC,MAAM,CAACE,SAAX,EAAsB;UAClB,OAAO;YACHF,MAAM,EAAE,IADL;YAEHG,KAAK,EAAE;UAFJ,CAAP;QAIH;;QAED,MAAM,IAAIxB,cAAJ,CAAgB;UAClBC,OAAO,EACH,sFAFc;UAGlBC,IAAI,EAAE,cAHY;UAIlBuB,IAAI,oBACGJ,MADH;QAJc,CAAhB,CAAN;MAQH,CA1BD,CA0BE,OAAOK,EAAP,EAAW;QACT,OAAO;UACHL,MAAM,EAAE,IADL;UAEHG,KAAK,EAAE;YACHvB,OAAO,EAAEyB,EAAE,CAACzB,OADT;YAEHC,IAAI,EAAEwB,EAAE,CAACxB,IAFN;YAGHuB,IAAI,kCACGb,MADH,GAEGc,EAAE,CAACD,IAFN;UAHD;QAFJ,CAAP;MAWH;IACJ;EA5CE,CAAP;AA8CH,CA1EM"}
@@ -1,17 +0,0 @@
1
- import { Plugin as BasePlugin } from "@webiny/plugins";
2
- import { Transport, MailerContext, TransportSettings } from "../types";
3
- interface TransportParams {
4
- settings: TransportSettings | null;
5
- context: MailerContext;
6
- }
7
- export interface CreateTransportCallable<T> {
8
- (params: TransportParams): Promise<T>;
9
- }
10
- export declare class CreateTransportPlugin<T extends Transport = Transport> extends BasePlugin {
11
- static type: string;
12
- private readonly cb;
13
- constructor(cb: CreateTransportCallable<T>);
14
- buildMailerTransport(params: TransportParams): Promise<T>;
15
- }
16
- export declare const createTransport: <T extends Transport<any> = Transport<any>>(cb: CreateTransportCallable<T>) => CreateTransportPlugin<T>;
17
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createTransport = exports.CreateTransportPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _plugins = require("@webiny/plugins");
13
-
14
- class CreateTransportPlugin extends _plugins.Plugin {
15
- constructor(cb) {
16
- super();
17
- (0, _defineProperty2.default)(this, "cb", void 0);
18
- this.cb = cb;
19
- }
20
-
21
- async buildMailerTransport(params) {
22
- return this.cb(params);
23
- }
24
-
25
- }
26
-
27
- exports.CreateTransportPlugin = CreateTransportPlugin;
28
- (0, _defineProperty2.default)(CreateTransportPlugin, "type", "mailer.builder.plugin");
29
-
30
- const createTransport = cb => {
31
- return new CreateTransportPlugin(cb);
32
- };
33
-
34
- exports.createTransport = createTransport;
@@ -1 +0,0 @@
1
- {"version":3,"names":["CreateTransportPlugin","BasePlugin","constructor","cb","buildMailerTransport","params","createTransport"],"sources":["CreateTransportPlugin.ts"],"sourcesContent":["import { Plugin as BasePlugin } from \"@webiny/plugins\";\nimport { Transport, MailerContext, TransportSettings } from \"~/types\";\n\ninterface TransportParams {\n settings: TransportSettings | null;\n context: MailerContext;\n}\n\nexport interface CreateTransportCallable<T> {\n (params: TransportParams): Promise<T>;\n}\n\nexport class CreateTransportPlugin<T extends Transport = Transport> extends BasePlugin {\n public static override type = \"mailer.builder.plugin\";\n\n private readonly cb: CreateTransportCallable<T>;\n\n public constructor(cb: CreateTransportCallable<T>) {\n super();\n this.cb = cb;\n }\n\n public async buildMailerTransport(params: TransportParams): Promise<T> {\n return this.cb(params);\n }\n}\n\nexport const createTransport = <T extends Transport = Transport>(\n cb: CreateTransportCallable<T>\n) => {\n return new CreateTransportPlugin<T>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAYO,MAAMA,qBAAN,SAAqEC,eAArE,CAAgF;EAK5EC,WAAW,CAACC,EAAD,EAAiC;IAC/C;IAD+C;IAE/C,KAAKA,EAAL,GAAUA,EAAV;EACH;;EAEgC,MAApBC,oBAAoB,CAACC,MAAD,EAAsC;IACnE,OAAO,KAAKF,EAAL,CAAQE,MAAR,CAAP;EACH;;AAZkF;;;8BAA1EL,qB,UACqB,uB;;AAc3B,MAAMM,eAAe,GACxBH,EAD2B,IAE1B;EACD,OAAO,IAAIH,qBAAJ,CAA6BG,EAA7B,CAAP;AACH,CAJM"}
@@ -1 +0,0 @@
1
- export * from "./CreateTransportPlugin";
package/plugins/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _CreateTransportPlugin = require("./CreateTransportPlugin");
8
-
9
- Object.keys(_CreateTransportPlugin).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _CreateTransportPlugin[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _CreateTransportPlugin[key];
16
- }
17
- });
18
- });
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CreateTransportPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,5 +0,0 @@
1
- import { Transport, TransportSendData } from "../types";
2
- export interface DummyTransport extends Transport {
3
- getAllSent: () => TransportSendData[];
4
- }
5
- export declare const createDummyTransport: () => DummyTransport;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDummyTransport = void 0;
7
-
8
- const createDummyTransport = () => {
9
- const sent = [];
10
- return {
11
- name: "dummy-default",
12
- send: async params => {
13
- sent.push(params);
14
- return {
15
- result: true,
16
- error: null
17
- };
18
- },
19
- getAllSent: () => {
20
- return sent;
21
- }
22
- };
23
- };
24
-
25
- exports.createDummyTransport = createDummyTransport;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createDummyTransport","sent","name","send","params","push","result","error","getAllSent"],"sources":["createDummyTransport.ts"],"sourcesContent":["import { Transport, TransportSendData } from \"~/types\";\n\nexport interface DummyTransport extends Transport {\n getAllSent: () => TransportSendData[];\n}\nexport const createDummyTransport = (): DummyTransport => {\n const sent: TransportSendData[] = [];\n\n return {\n name: \"dummy-default\",\n send: async params => {\n sent.push(params);\n return {\n result: true,\n error: null\n };\n },\n getAllSent: () => {\n return sent;\n }\n };\n};\n"],"mappings":";;;;;;;AAKO,MAAMA,oBAAoB,GAAG,MAAsB;EACtD,MAAMC,IAAyB,GAAG,EAAlC;EAEA,OAAO;IACHC,IAAI,EAAE,eADH;IAEHC,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClBH,IAAI,CAACI,IAAL,CAAUD,MAAV;MACA,OAAO;QACHE,MAAM,EAAE,IADL;QAEHC,KAAK,EAAE;MAFJ,CAAP;IAIH,CARE;IASHC,UAAU,EAAE,MAAM;MACd,OAAOP,IAAP;IACH;EAXE,CAAP;AAaH,CAhBM"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Nodemailer docs
3
- * https://nodemailer.com/about/
4
- */
5
- import { Transport } from "../types";
6
- import { Transporter } from "nodemailer";
7
- import SMTPTransport, { Options } from "nodemailer/lib/smtp-transport";
8
- export declare type SmtpTransportConfig = Options;
9
- export interface SmtpTransport extends Transport {
10
- transporter: Transporter<SMTPTransport.SentMessageInfo>;
11
- }
12
- export declare const createSmtpTransport: (initialConfig?: Partial<SmtpTransportConfig> | null) => SmtpTransport;
@@ -1,101 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createSmtpTransport = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _nodemailer = _interopRequireDefault(require("nodemailer"));
15
-
16
- /**
17
- * Nodemailer docs
18
- * https://nodemailer.com/about/
19
- */
20
- const configDefaults = {
21
- socketTimeout: 15000,
22
- connectionTimeout: 15000,
23
- greetingTimeout: 15000
24
- };
25
-
26
- const applyDefaults = initialConfig => {
27
- return Object.keys(configDefaults).reduce((config, key) => {
28
- const configKey = key;
29
-
30
- if (config[configKey] === undefined || config[configKey] === null) {
31
- // @ts-ignore
32
- config[configKey] = configDefaults[configKey];
33
- }
34
-
35
- return config;
36
- }, (0, _objectSpread2.default)({}, initialConfig));
37
- };
38
-
39
- const createSmtpTransport = initialConfig => {
40
- if (!initialConfig || typeof initialConfig !== "object" || Object.keys(initialConfig).length === 0) {
41
- throw new _error.default("There is no configuration for the SMTP transport.");
42
- }
43
-
44
- const config = applyDefaults(initialConfig);
45
-
46
- const transporter = _nodemailer.default.createTransport(config);
47
-
48
- return {
49
- name: "smtp-default",
50
- transporter,
51
- send: async params => {
52
- const {
53
- replyTo,
54
- text,
55
- html,
56
- to,
57
- bcc,
58
- cc,
59
- from,
60
- subject
61
- } = params;
62
-
63
- try {
64
- const result = await transporter.sendMail({
65
- replyTo,
66
- bcc,
67
- cc,
68
- from,
69
- text,
70
- html,
71
- to,
72
- subject
73
- });
74
-
75
- if (result.messageId) {
76
- return {
77
- result: result.response,
78
- error: null
79
- };
80
- }
81
-
82
- throw new _error.default({
83
- message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
84
- code: "MAILER_ERROR",
85
- data: (0, _objectSpread2.default)({}, result)
86
- });
87
- } catch (ex) {
88
- return {
89
- result: null,
90
- error: {
91
- message: ex.message,
92
- code: ex.code,
93
- data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), ex.data)
94
- }
95
- };
96
- }
97
- }
98
- };
99
- };
100
-
101
- exports.createSmtpTransport = createSmtpTransport;
@@ -1 +0,0 @@
1
- {"version":3,"names":["configDefaults","socketTimeout","connectionTimeout","greetingTimeout","applyDefaults","initialConfig","Object","keys","reduce","config","key","configKey","undefined","createSmtpTransport","length","WebinyError","transporter","nodemailer","createTransport","name","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","response","error","message","code","data","ex"],"sources":["createSmtpTransport.ts"],"sourcesContent":["/**\n * Nodemailer docs\n * https://nodemailer.com/about/\n */\nimport { Transport } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport nodemailer, { Transporter } from \"nodemailer\";\nimport SMTPTransport, { Options } from \"nodemailer/lib/smtp-transport\";\n\nexport type SmtpTransportConfig = Options;\n\nexport interface SmtpTransport extends Transport {\n transporter: Transporter<SMTPTransport.SentMessageInfo>;\n}\n\nconst configDefaults: Partial<SmtpTransportConfig> = {\n socketTimeout: 15000,\n connectionTimeout: 15000,\n greetingTimeout: 15000\n};\n\nconst applyDefaults = (\n initialConfig: Partial<SmtpTransportConfig>\n): Partial<SmtpTransportConfig> => {\n return Object.keys(configDefaults).reduce<Partial<SmtpTransportConfig>>(\n (config, key) => {\n const configKey = key as unknown as keyof SmtpTransportConfig;\n if (config[configKey] === undefined || config[configKey] === null) {\n // @ts-ignore\n config[configKey] = configDefaults[configKey];\n }\n\n return config;\n },\n { ...initialConfig }\n );\n};\n\nexport const createSmtpTransport = (\n initialConfig?: Partial<SmtpTransportConfig> | null\n): SmtpTransport => {\n if (\n !initialConfig ||\n typeof initialConfig !== \"object\" ||\n Object.keys(initialConfig).length === 0\n ) {\n throw new WebinyError(\"There is no configuration for the SMTP transport.\");\n }\n\n const config = applyDefaults(initialConfig);\n\n const transporter = nodemailer.createTransport(config);\n\n return {\n name: \"smtp-default\",\n transporter,\n send: async params => {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n throw new WebinyError({\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 } catch (ex) {\n return {\n result: null,\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...params,\n ...ex.data\n }\n }\n };\n }\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA;;AACA;;AANA;AACA;AACA;AACA;AAYA,MAAMA,cAA4C,GAAG;EACjDC,aAAa,EAAE,KADkC;EAEjDC,iBAAiB,EAAE,KAF8B;EAGjDC,eAAe,EAAE;AAHgC,CAArD;;AAMA,MAAMC,aAAa,GACfC,aADkB,IAEa;EAC/B,OAAOC,MAAM,CAACC,IAAP,CAAYP,cAAZ,EAA4BQ,MAA5B,CACH,CAACC,MAAD,EAASC,GAAT,KAAiB;IACb,MAAMC,SAAS,GAAGD,GAAlB;;IACA,IAAID,MAAM,CAACE,SAAD,CAAN,KAAsBC,SAAtB,IAAmCH,MAAM,CAACE,SAAD,CAAN,KAAsB,IAA7D,EAAmE;MAC/D;MACAF,MAAM,CAACE,SAAD,CAAN,GAAoBX,cAAc,CAACW,SAAD,CAAlC;IACH;;IAED,OAAOF,MAAP;EACH,CATE,kCAUEJ,aAVF,EAAP;AAYH,CAfD;;AAiBO,MAAMQ,mBAAmB,GAC5BR,aAD+B,IAEf;EAChB,IACI,CAACA,aAAD,IACA,OAAOA,aAAP,KAAyB,QADzB,IAEAC,MAAM,CAACC,IAAP,CAAYF,aAAZ,EAA2BS,MAA3B,KAAsC,CAH1C,EAIE;IACE,MAAM,IAAIC,cAAJ,CAAgB,mDAAhB,CAAN;EACH;;EAED,MAAMN,MAAM,GAAGL,aAAa,CAACC,aAAD,CAA5B;;EAEA,MAAMW,WAAW,GAAGC,mBAAA,CAAWC,eAAX,CAA2BT,MAA3B,CAApB;;EAEA,OAAO;IACHU,IAAI,EAAE,cADH;IAEHH,WAFG;IAGHI,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClB,MAAM;QAAEC,OAAF;QAAWC,IAAX;QAAiBC,IAAjB;QAAuBC,EAAvB;QAA2BC,GAA3B;QAAgCC,EAAhC;QAAoCC,IAApC;QAA0CC;MAA1C,IAAsDR,MAA5D;;MAEA,IAAI;QACA,MAAMS,MAAM,GAAG,MAAMd,WAAW,CAACe,QAAZ,CAAqB;UACtCT,OADsC;UAEtCI,GAFsC;UAGtCC,EAHsC;UAItCC,IAJsC;UAKtCL,IALsC;UAMtCC,IANsC;UAOtCC,EAPsC;UAQtCI;QARsC,CAArB,CAArB;;QAUA,IAAIC,MAAM,CAACE,SAAX,EAAsB;UAClB,OAAO;YACHF,MAAM,EAAEA,MAAM,CAACG,QADZ;YAEHC,KAAK,EAAE;UAFJ,CAAP;QAIH;;QAED,MAAM,IAAInB,cAAJ,CAAgB;UAClBoB,OAAO,EACH,sFAFc;UAGlBC,IAAI,EAAE,cAHY;UAIlBC,IAAI,kCACGP,MADH;QAJc,CAAhB,CAAN;MAQH,CA1BD,CA0BE,OAAOQ,EAAP,EAAW;QACT,OAAO;UACHR,MAAM,EAAE,IADL;UAEHI,KAAK,EAAE;YACHC,OAAO,EAAEG,EAAE,CAACH,OADT;YAEHC,IAAI,EAAEE,EAAE,CAACF,IAFN;YAGHC,IAAI,8DACGhB,MADH,GAEGiB,EAAE,CAACD,IAFN;UAHD;QAFJ,CAAP;MAWH;IACJ;EA7CE,CAAP;AA+CH,CA9DM"}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\n\nexport interface MailerTransporterContext<T extends Transport = Transport> {\n onTransportBeforeSend: Topic<OnTransportBeforeSendParams>;\n onTransportAfterSend: Topic<OnTransportAfterSendParams>;\n onTransportError: Topic<OnTransportErrorParams>;\n getTransport: () => Promise<T | null>;\n sendMail: <D>(data: TransportSendData) => Promise<TransportSendResponse<D>>;\n}\n\nexport interface MailerSettingsCreateParams {\n input: Partial<TransportSettings>;\n}\nexport interface MailerSettingsUpdateParams {\n input: Partial<TransportSettings>;\n original?: ExtendedTransportSettings | null;\n}\n\nexport interface MailerSettingsSaveParams {\n input: Partial<TransportSettings>;\n}\n\nexport interface OnSettingsBeforeGetTopicParams {\n tenant: string;\n}\n\nexport interface OnSettingsAfterGetTopicParams {\n tenant: string;\n settings: TransportSettings | null;\n}\n\nexport interface OnSettingsGetErrorTopicParams {\n tenant: string;\n error: Error;\n}\n\nexport interface OnSettingsBeforeCreateTopicParams {\n settings: TransportSettings;\n}\n\nexport interface OnSettingsAfterCreateTopicParams {\n settings: TransportSettings;\n}\n\nexport interface OnSettingsCreateErrorTopicParams {\n settings: TransportSettings;\n error: Error;\n}\n\nexport interface OnSettingsBeforeUpdateTopicParams {\n settings: TransportSettings;\n original: TransportSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n original: TransportSettings;\n settings: TransportSettings;\n}\n\nexport interface OnSettingsUpdateErrorTopicParams {\n original: TransportSettings;\n settings: TransportSettings;\n error: Error;\n}\n\nexport interface ExtendedTransportSettings extends TransportSettings {\n id: string;\n}\n\nexport interface MailerSettingsContext {\n getSettings: () => Promise<ExtendedTransportSettings | null>;\n /**\n * Method should not be used outside of mailer\n * @internal\n */\n createSettings: (params: MailerSettingsCreateParams) => Promise<TransportSettings>;\n /**\n * Method should not be used outside of mailer\n * @internal\n */\n updateSettings: (params: MailerSettingsUpdateParams) => Promise<TransportSettings>;\n /**\n * Use to store the settings data.\n */\n saveSettings: (params: MailerSettingsSaveParams) => Promise<TransportSettings>;\n /**\n * Lifecycle events\n */\n onSettingsBeforeGet: Topic<OnSettingsBeforeGetTopicParams>;\n onSettingsAfterGet: Topic<OnSettingsAfterGetTopicParams>;\n onSettingsGetError: Topic<OnSettingsGetErrorTopicParams>;\n onSettingsBeforeCreate: Topic<OnSettingsBeforeCreateTopicParams>;\n onSettingsAfterCreate: Topic<OnSettingsAfterCreateTopicParams>;\n onSettingsCreateError: Topic<OnSettingsCreateErrorTopicParams>;\n onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\n onSettingsUpdateError: Topic<OnSettingsUpdateErrorTopicParams>;\n}\n\nexport interface MailerContextObject<T extends Transport = Transport>\n extends MailerTransporterContext<T>,\n MailerSettingsContext {}\nexport interface MailerContext extends CmsContext {\n mailer: MailerContextObject;\n}\n\nexport interface OnTransportBeforeSendParams {\n data: TransportSendData;\n transport: Transport;\n}\nexport interface OnTransportAfterSendParams {\n data: TransportSendData;\n transport: Transport;\n}\nexport interface OnTransportErrorParams {\n error: Error;\n data: TransportSendData;\n transport: Transport;\n}\n\n/**\n * Interface to implement the actual mailer.\n */\nexport interface TransportSendResponse<T = any> {\n result: T | null;\n error: {\n message: string;\n code: string;\n data?: {\n [key: string]: any;\n };\n } | null;\n}\n\ninterface TransportSendToData {\n to: string[];\n}\ninterface TransportSendCcData {\n cc: string[];\n}\ninterface TransportSendBccData {\n bcc: string[];\n}\n\ninterface BaseTransportSendData {\n to?: string[];\n cc?: string[];\n bcc?: string[];\n from?: string;\n subject: string;\n text: string;\n html?: string;\n replyTo?: string;\n}\n\nexport type TransportSendData = BaseTransportSendData &\n (TransportSendToData | TransportSendBccData | TransportSendCcData);\nexport interface Transport<T = any> {\n name: string;\n send: (params: TransportSendData) => Promise<TransportSendResponse<T>>;\n}\n\nexport interface TransportSettings {\n host: string;\n port: number;\n user: string;\n password: string;\n from: string;\n replyTo?: string;\n}\n"],"mappings":""}