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

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 (178) hide show
  1. package/README.md +10 -13
  2. package/constants.d.ts +1 -0
  3. package/constants.js +4 -0
  4. package/constants.js.map +1 -0
  5. package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
  6. package/domain/CodeMailerSettings/abstractions.js +5 -0
  7. package/domain/CodeMailerSettings/abstractions.js.map +1 -0
  8. package/domain/MailTransport/abstractions.d.ts +26 -0
  9. package/domain/MailTransport/abstractions.js +7 -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 +5 -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 +28 -0
  16. package/domain/MailerService/errors.js.map +1 -0
  17. package/domain/errors.d.ts +28 -0
  18. package/domain/errors.js +48 -0
  19. package/domain/errors.js.map +1 -0
  20. package/exports/api/mailer.d.ts +4 -0
  21. package/exports/api/mailer.js +4 -0
  22. package/features/CodeMailerSettings/CodeMailerSettingsImpl.d.ts +12 -0
  23. package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +23 -0
  24. package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -0
  25. package/features/CodeMailerSettings/feature.d.ts +4 -0
  26. package/features/CodeMailerSettings/feature.js +11 -0
  27. package/features/CodeMailerSettings/feature.js.map +1 -0
  28. package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
  29. package/features/DummyTransport/DummyMailTransport.js +14 -0
  30. package/features/DummyTransport/DummyMailTransport.js.map +1 -0
  31. package/features/DummyTransport/DummyMailTransportFactory.d.ts +9 -0
  32. package/features/DummyTransport/DummyMailTransportFactory.js +17 -0
  33. package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
  34. package/features/DummyTransport/feature.d.ts +4 -0
  35. package/features/DummyTransport/feature.js +11 -0
  36. package/features/DummyTransport/feature.js.map +1 -0
  37. package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
  38. package/features/GetSettings/GetSettingsRepository.js +54 -0
  39. package/features/GetSettings/GetSettingsRepository.js.map +1 -0
  40. package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
  41. package/features/GetSettings/GetSettingsUseCase.js +18 -0
  42. package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
  43. package/features/GetSettings/abstractions.d.ts +22 -0
  44. package/features/GetSettings/abstractions.js +6 -0
  45. package/features/GetSettings/abstractions.js.map +1 -0
  46. package/features/GetSettings/feature.d.ts +4 -0
  47. package/features/GetSettings/feature.js +13 -0
  48. package/features/GetSettings/feature.js.map +1 -0
  49. package/features/GetSettings/index.d.ts +1 -0
  50. package/features/GetSettings/index.js +1 -0
  51. package/features/MailerService/ActiveTransport.d.ts +10 -0
  52. package/features/MailerService/ActiveTransport.js +24 -0
  53. package/features/MailerService/ActiveTransport.js.map +1 -0
  54. package/features/MailerService/MailerService.d.ts +16 -0
  55. package/features/MailerService/MailerService.js +49 -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 +13 -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 +43 -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 +51 -0
  65. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
  66. package/features/SaveSettings/abstractions.d.ts +61 -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 +9 -0
  78. package/features/SaveSettings/validation.js +20 -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 +25 -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 +10 -0
  101. package/features/SmtpTransport/SmtpMailTransportFactory.js +18 -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/settings.d.ts +2 -2
  107. package/graphql/settings.js +71 -73
  108. package/graphql/settings.js.map +1 -1
  109. package/index.d.ts +4 -8
  110. package/index.js +23 -89
  111. package/index.js.map +1 -1
  112. package/package.json +32 -45
  113. package/types.d.ts +2 -109
  114. package/types.js +0 -5
  115. package/utils/isMailboxAddress.d.ts +6 -0
  116. package/utils/isMailboxAddress.js +5 -0
  117. package/utils/isMailboxAddress.js.map +1 -0
  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.d.ts +0 -7
  137. package/crud/settings/password.js +0 -71
  138. package/crud/settings/password.js.map +0 -1
  139. package/crud/settings/secret.d.ts +0 -1
  140. package/crud/settings/secret.js +0 -23
  141. package/crud/settings/secret.js.map +0 -1
  142. package/crud/settings/transform.d.ts +0 -13
  143. package/crud/settings/transform.js +0 -56
  144. package/crud/settings/transform.js.map +0 -1
  145. package/crud/settings/validation.d.ts +0 -4
  146. package/crud/settings/validation.js +0 -38
  147. package/crud/settings/validation.js.map +0 -1
  148. package/crud/settings.crud.d.ts +0 -5
  149. package/crud/settings.crud.js +0 -331
  150. package/crud/settings.crud.js.map +0 -1
  151. package/crud/transport/onTransportBeforeSend.d.ts +0 -7
  152. package/crud/transport/onTransportBeforeSend.js +0 -69
  153. package/crud/transport/onTransportBeforeSend.js.map +0 -1
  154. package/crud/transporter.crud.d.ts +0 -2
  155. package/crud/transporter.crud.js +0 -193
  156. package/crud/transporter.crud.js.map +0 -1
  157. package/graphql/index.d.ts +0 -1
  158. package/graphql/index.js +0 -14
  159. package/graphql/index.js.map +0 -1
  160. package/mailers/createDummyMailer.d.ts +0 -5
  161. package/mailers/createDummyMailer.js +0 -24
  162. package/mailers/createDummyMailer.js.map +0 -1
  163. package/mailers/createSmtpMailer.d.ts +0 -13
  164. package/mailers/createSmtpMailer.js +0 -106
  165. package/mailers/createSmtpMailer.js.map +0 -1
  166. package/plugins/CreateTransportPlugin.d.ts +0 -17
  167. package/plugins/CreateTransportPlugin.js +0 -34
  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 -12
  176. package/transports/createSmtpTransport.js +0 -101
  177. package/transports/createSmtpTransport.js.map +0 -1
  178. 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,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,E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AFJ,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,e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,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":""}