@webiny/api-mailer 0.0.0-unstable.615a930a68 → 0.0.0-unstable.61c048f412

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 (177) hide show
  1. package/README.md +10 -13
  2. package/constants.d.ts +1 -0
  3. package/constants.js +3 -0
  4. package/constants.js.map +1 -0
  5. package/domain/Encryption/abstractions.d.ts +8 -0
  6. package/domain/Encryption/abstractions.js +4 -0
  7. package/domain/Encryption/abstractions.js.map +1 -0
  8. package/domain/MailTransport/abstractions.d.ts +18 -0
  9. package/domain/MailTransport/abstractions.js +5 -0
  10. package/domain/MailTransport/abstractions.js.map +1 -0
  11. package/domain/MailerService/abstractions.d.ts +19 -0
  12. package/domain/MailerService/abstractions.js +4 -0
  13. package/domain/MailerService/abstractions.js.map +1 -0
  14. package/domain/MailerService/errors.d.ts +16 -0
  15. package/domain/MailerService/errors.js +30 -0
  16. package/domain/MailerService/errors.js.map +1 -0
  17. package/domain/errors.d.ts +24 -0
  18. package/domain/errors.js +44 -0
  19. package/domain/errors.js.map +1 -0
  20. package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
  21. package/features/DummyTransport/DummyMailTransport.js +12 -0
  22. package/features/DummyTransport/DummyMailTransport.js.map +1 -0
  23. package/features/DummyTransport/DummyMailTransportFactory.d.ts +8 -0
  24. package/features/DummyTransport/DummyMailTransportFactory.js +13 -0
  25. package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
  26. package/features/DummyTransport/feature.d.ts +1 -0
  27. package/features/DummyTransport/feature.js +10 -0
  28. package/features/DummyTransport/feature.js.map +1 -0
  29. package/features/Encryption/PasswordEncryption.d.ts +9 -0
  30. package/features/Encryption/PasswordEncryption.js +23 -0
  31. package/features/Encryption/PasswordEncryption.js.map +1 -0
  32. package/features/Encryption/feature.d.ts +1 -0
  33. package/features/Encryption/feature.js +10 -0
  34. package/features/Encryption/feature.js.map +1 -0
  35. package/features/Encryption/utils/password.js +56 -0
  36. package/features/Encryption/utils/password.js.map +1 -0
  37. package/features/Encryption/utils/secret.js +11 -0
  38. package/features/Encryption/utils/secret.js.map +1 -0
  39. package/features/GetSettings/GetSettingsRepository.d.ts +15 -0
  40. package/features/GetSettings/GetSettingsRepository.js +39 -0
  41. package/features/GetSettings/GetSettingsRepository.js.map +1 -0
  42. package/features/GetSettings/GetSettingsUseCase.d.ts +12 -0
  43. package/features/GetSettings/GetSettingsUseCase.js +15 -0
  44. package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
  45. package/features/GetSettings/abstractions.d.ts +16 -0
  46. package/features/GetSettings/abstractions.js +5 -0
  47. package/features/GetSettings/abstractions.js.map +1 -0
  48. package/features/GetSettings/feature.d.ts +1 -0
  49. package/features/GetSettings/feature.js +12 -0
  50. package/features/GetSettings/feature.js.map +1 -0
  51. package/features/GetSettings/index.d.ts +1 -0
  52. package/features/GetSettings/index.js +3 -0
  53. package/features/GetSettings/index.js.map +1 -0
  54. package/features/MailerService/MailerService.d.ts +15 -0
  55. package/features/MailerService/MailerService.js +52 -0
  56. package/features/MailerService/MailerService.js.map +1 -0
  57. package/features/MailerService/TransportFactory.d.ts +2 -0
  58. package/features/MailerService/TransportFactory.js +31 -0
  59. package/features/MailerService/TransportFactory.js.map +1 -0
  60. package/features/MailerService/feature.d.ts +1 -0
  61. package/features/MailerService/feature.js +10 -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 +57 -0
  65. package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
  66. package/features/SaveSettings/SaveSettingsUseCase.d.ts +14 -0
  67. package/features/SaveSettings/SaveSettingsUseCase.js +51 -0
  68. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
  69. package/features/SaveSettings/abstractions.d.ts +53 -0
  70. package/features/SaveSettings/abstractions.js +11 -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 +16 -0
  74. package/features/SaveSettings/events.js.map +1 -0
  75. package/features/SaveSettings/feature.d.ts +1 -0
  76. package/features/SaveSettings/feature.js +12 -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 +3 -0
  80. package/features/SaveSettings/index.js.map +1 -0
  81. package/features/SaveSettings/validation.d.ts +23 -0
  82. package/features/SaveSettings/validation.js +19 -0
  83. package/features/SaveSettings/validation.js.map +1 -0
  84. package/features/SendMail/SendMailUseCase.d.ts +16 -0
  85. package/features/SendMail/SendMailUseCase.js +62 -0
  86. package/features/SendMail/SendMailUseCase.js.map +1 -0
  87. package/features/SendMail/abstractions.d.ts +45 -0
  88. package/features/SendMail/abstractions.js +11 -0
  89. package/features/SendMail/abstractions.js.map +1 -0
  90. package/features/SendMail/events.d.ts +14 -0
  91. package/features/SendMail/events.js +22 -0
  92. package/features/SendMail/events.js.map +1 -0
  93. package/features/SendMail/feature.d.ts +1 -0
  94. package/features/SendMail/feature.js +10 -0
  95. package/features/SendMail/feature.js.map +1 -0
  96. package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
  97. package/features/SmtpTransport/SmtpConfig.js +29 -0
  98. package/features/SmtpTransport/SmtpConfig.js.map +1 -0
  99. package/features/SmtpTransport/SmtpMailTransport.d.ts +18 -0
  100. package/features/SmtpTransport/SmtpMailTransport.js +61 -0
  101. package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
  102. package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +9 -0
  103. package/features/SmtpTransport/SmtpMailTransportFactory.js +14 -0
  104. package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
  105. package/features/SmtpTransport/feature.d.ts +1 -0
  106. package/features/SmtpTransport/feature.js +10 -0
  107. package/features/SmtpTransport/feature.js.map +1 -0
  108. package/graphql/settings.d.ts +2 -2
  109. package/graphql/settings.js +47 -41
  110. package/graphql/settings.js.map +1 -1
  111. package/index.d.ts +4 -8
  112. package/index.js +24 -86
  113. package/index.js.map +1 -1
  114. package/package.json +32 -42
  115. package/types.d.ts +2 -109
  116. package/types.js +2 -4
  117. package/types.js.map +1 -1
  118. package/context.d.ts +0 -3
  119. package/context.js +0 -24
  120. package/context.js.map +0 -1
  121. package/crud/group.d.ts +0 -2
  122. package/crud/group.js +0 -21
  123. package/crud/group.js.map +0 -1
  124. package/crud/mailer/onBeforeSend.d.ts +0 -7
  125. package/crud/mailer/onBeforeSend.js +0 -69
  126. package/crud/mailer/onBeforeSend.js.map +0 -1
  127. package/crud/mailer.crud.d.ts +0 -2
  128. package/crud/mailer.crud.js +0 -123
  129. package/crud/mailer.crud.js.map +0 -1
  130. package/crud/settings/hooks.d.ts +0 -5
  131. package/crud/settings/hooks.js +0 -55
  132. package/crud/settings/hooks.js.map +0 -1
  133. package/crud/settings/model.d.ts +0 -3
  134. package/crud/settings/model.js +0 -90
  135. package/crud/settings/model.js.map +0 -1
  136. package/crud/settings/password.js +0 -71
  137. package/crud/settings/password.js.map +0 -1
  138. package/crud/settings/secret.js +0 -23
  139. package/crud/settings/secret.js.map +0 -1
  140. package/crud/settings/transform.d.ts +0 -13
  141. package/crud/settings/transform.js +0 -56
  142. package/crud/settings/transform.js.map +0 -1
  143. package/crud/settings/validation.d.ts +0 -4
  144. package/crud/settings/validation.js +0 -38
  145. package/crud/settings/validation.js.map +0 -1
  146. package/crud/settings.crud.d.ts +0 -5
  147. package/crud/settings.crud.js +0 -331
  148. package/crud/settings.crud.js.map +0 -1
  149. package/crud/transport/onTransportBeforeSend.d.ts +0 -7
  150. package/crud/transport/onTransportBeforeSend.js +0 -69
  151. package/crud/transport/onTransportBeforeSend.js.map +0 -1
  152. package/crud/transporter.crud.d.ts +0 -2
  153. package/crud/transporter.crud.js +0 -193
  154. package/crud/transporter.crud.js.map +0 -1
  155. package/graphql/index.d.ts +0 -1
  156. package/graphql/index.js +0 -14
  157. package/graphql/index.js.map +0 -1
  158. package/mailers/createDummyMailer.d.ts +0 -5
  159. package/mailers/createDummyMailer.js +0 -24
  160. package/mailers/createDummyMailer.js.map +0 -1
  161. package/mailers/createSmtpMailer.d.ts +0 -13
  162. package/mailers/createSmtpMailer.js +0 -106
  163. package/mailers/createSmtpMailer.js.map +0 -1
  164. package/plugins/CreateTransportPlugin.d.ts +0 -17
  165. package/plugins/CreateTransportPlugin.js +0 -34
  166. package/plugins/CreateTransportPlugin.js.map +0 -1
  167. package/plugins/index.d.ts +0 -1
  168. package/plugins/index.js +0 -18
  169. package/plugins/index.js.map +0 -1
  170. package/transports/createDummyTransport.d.ts +0 -5
  171. package/transports/createDummyTransport.js +0 -25
  172. package/transports/createDummyTransport.js.map +0 -1
  173. package/transports/createSmtpTransport.d.ts +0 -12
  174. package/transports/createSmtpTransport.js +0 -101
  175. package/transports/createSmtpTransport.js.map +0 -1
  176. /package/{crud/settings → features/Encryption/utils}/password.d.ts +0 -0
  177. /package/{crud/settings → features/Encryption/utils}/secret.d.ts +0 -0
@@ -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,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,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H,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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