@webiny/api-mailer 0.0.0-unstable.d16f688daf → 0.0.0-unstable.d65ec29d44

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 (39) hide show
  1. package/context.js +0 -7
  2. package/context.js.map +1 -1
  3. package/crud/group.js +0 -3
  4. package/crud/group.js.map +1 -1
  5. package/crud/settings/hooks.js +3 -15
  6. package/crud/settings/hooks.js.map +1 -1
  7. package/crud/settings/model.js +0 -12
  8. package/crud/settings/model.js.map +1 -1
  9. package/crud/settings/password.js +0 -18
  10. package/crud/settings/password.js.map +1 -1
  11. package/crud/settings/secret.js +0 -6
  12. package/crud/settings/secret.js.map +1 -1
  13. package/crud/settings/transform.js +0 -12
  14. package/crud/settings/transform.js.map +1 -1
  15. package/crud/settings/validation.js +0 -9
  16. package/crud/settings/validation.js.map +1 -1
  17. package/crud/settings.crud.js +15 -68
  18. package/crud/settings.crud.js.map +1 -1
  19. package/crud/transport/onTransportBeforeSend.js +2 -14
  20. package/crud/transport/onTransportBeforeSend.js.map +1 -1
  21. package/crud/transporter.crud.js +1 -32
  22. package/crud/transporter.crud.js.map +1 -1
  23. package/graphql/index.js +0 -3
  24. package/graphql/index.js.map +1 -1
  25. package/graphql/settings.js +0 -8
  26. package/graphql/settings.js.map +1 -1
  27. package/index.js +0 -15
  28. package/index.js.map +1 -1
  29. package/package.json +23 -23
  30. package/plugins/CreateTransportPlugin.js +0 -9
  31. package/plugins/CreateTransportPlugin.js.map +1 -1
  32. package/plugins/index.js +0 -2
  33. package/plugins/index.js.map +1 -1
  34. package/transports/createDummyTransport.js +0 -2
  35. package/transports/createDummyTransport.js.map +1 -1
  36. package/transports/createSmtpTransport.js +1 -16
  37. package/transports/createSmtpTransport.js.map +1 -1
  38. package/types.d.ts +1 -1
  39. package/types.js.map +1 -1
@@ -1 +1 @@
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
+ {"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,+BAAqB,GAAE,CAAC;AACpC,CAAC;AAAC"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createSettingsGraphQL = void 0;
7
-
8
7
  var _handlerGraphql = require("@webiny/handler-graphql");
9
-
10
8
  const emptyResolver = () => ({});
11
-
12
9
  const createSettingsGraphQL = () => {
13
10
  return new _handlerGraphql.GraphQLSchemaPlugin({
14
11
  typeDefs: `
@@ -66,12 +63,10 @@ const createSettingsGraphQL = () => {
66
63
  /**
67
64
  * We want to remove the password from the response, if it exists.
68
65
  */
69
-
70
66
  if (settings !== null && settings !== void 0 && settings.password) {
71
67
  // @ts-ignore
72
68
  delete settings.password;
73
69
  }
74
-
75
70
  return new _handlerGraphql.Response(settings);
76
71
  } catch (ex) {
77
72
  return new _handlerGraphql.ErrorResponse(ex);
@@ -90,12 +85,10 @@ const createSettingsGraphQL = () => {
90
85
  /**
91
86
  * We want to remove the password from the response, if it exists.
92
87
  */
93
-
94
88
  if (settings !== null && settings !== void 0 && settings.password) {
95
89
  // @ts-ignore
96
90
  delete settings.password;
97
91
  }
98
-
99
92
  return new _handlerGraphql.Response(settings);
100
93
  } catch (ex) {
101
94
  return new _handlerGraphql.ErrorResponse(ex);
@@ -105,5 +98,4 @@ const createSettingsGraphQL = () => {
105
98
  }
106
99
  });
107
100
  };
108
-
109
101
  exports.createSettingsGraphQL = createSettingsGraphQL;
@@ -1 +1 @@
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 MailerTransportSettingsResponse {\n data: MailerTransportSettings\n error: MailerTransportSettingsError\n }\n \n type MailerQuery {\n getSettings: MailerTransportSettingsResponse!\n }\n \n input MailerTransportSettingsInput {\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: MailerTransportSettingsInput!): MailerTransportSettingsResponse!\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, if it exists.\n */\n if (settings?.password) {\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, if it exists.\n */\n if (settings?.password) {\n // @ts-ignore\n delete settings.password;\n }\n return new Response(settings);\n } catch (ex) {\n return new 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IAAIV,QAAJ,aAAIA,QAAJ,eAAIA,QAAQ,CAAEC,QAAd,EAAwB;cACpB;cACA,OAAOD,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"}
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 MailerTransportSettingsResponse {\n data: MailerTransportSettings\n error: MailerTransportSettingsError\n }\n \n type MailerQuery {\n getSettings: MailerTransportSettingsResponse!\n }\n \n input MailerTransportSettingsInput {\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: MailerTransportSettingsInput!): MailerTransportSettingsResponse!\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, if it exists.\n */\n if (settings?.password) {\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, if it exists.\n */\n if (settings?.password) {\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,CAAC,CAAC,CAAC;AAEzB,MAAMC,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIC,mCAAmB,CAAgB;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,SAAS;IACDC,SAAS,EAAE;MACPC,KAAK,EAAE;QACHC,MAAM,EAAEN;MACZ,CAAC;MACDO,WAAW,EAAE;QACTC,WAAW,EAAE,OAAOC,CAAC,EAAEC,EAAE,EAAEC,OAAO,KAAK;UACnC,IAAI;YACA,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACL,MAAM,CAACE,WAAW,EAAE;YACnD;AACxB;AACA;YACwB,IAAII,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEC,QAAQ,EAAE;cACpB;cACA,OAAOD,QAAQ,CAACC,QAAQ;YAC5B;YACA,OAAO,IAAIC,wBAAQ,CAACF,QAAQ,CAAC;UACjC,CAAC,CAAC,OAAOG,EAAE,EAAE;YACT,OAAO,IAAIC,6BAAa,CAACD,EAAE,CAAC;UAChC;QACJ;MACJ,CAAC;MACDE,QAAQ,EAAE;QACNX,MAAM,EAAEN;MACZ,CAAC;MACDkB,cAAc,EAAE;QACZC,YAAY,EAAE,OAAOV,CAAC,EAAEW,IAAS,EAAET,OAAO,KAAK;UAC3C,IAAI;YACA,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACL,MAAM,CAACa,YAAY,CAAC;cAC/CE,KAAK,EAAED,IAAI,CAACE;YAChB,CAAC,CAAC;YACF;AACxB;AACA;YACwB,IAAIV,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEC,QAAQ,EAAE;cACpB;cACA,OAAOD,QAAQ,CAACC,QAAQ;YAC5B;YACA,OAAO,IAAIC,wBAAQ,CAACF,QAAQ,CAAC;UACjC,CAAC,CAAC,OAAOG,EAAE,EAAE;YACT,OAAO,IAAIC,6BAAa,CAACD,EAAE,CAAC;UAChC;QACJ;MACJ;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
package/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -24,23 +23,14 @@ Object.defineProperty(exports, "createTransport", {
24
23
  return _plugins.createTransport;
25
24
  }
26
25
  });
27
-
28
26
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
29
-
30
27
  var _context = require("./context");
31
-
32
28
  var _createDummyTransport = require("./transports/createDummyTransport");
33
-
34
29
  var _createSmtpTransport = require("./transports/createSmtpTransport");
35
-
36
30
  var _plugins = require("./plugins");
37
-
38
31
  var _model = require("./crud/settings/model");
39
-
40
32
  var _group = require("./crud/group");
41
-
42
33
  var _graphql = require("./graphql");
43
-
44
34
  const createMailerContext = () => {
45
35
  const group = (0, _group.createGroup)();
46
36
  return [group,
@@ -66,24 +56,19 @@ const createMailerContext = () => {
66
56
  * We need to map our settings to the required settings for the SMTP NodeMailer transport.
67
57
  */
68
58
  const config = (0, _objectSpread2.default)({}, settings || {});
69
-
70
59
  if (settings) {
71
60
  config.auth = {
72
61
  user: settings.user,
73
62
  pass: settings.password
74
63
  };
75
64
  }
76
-
77
65
  const plugin = await (0, _createSmtpTransport.createSmtpTransport)(config);
78
66
  plugin.name = "smtp-default";
79
67
  return plugin;
80
68
  }), (0, _context.createMailerContext)()];
81
69
  };
82
-
83
70
  exports.createMailerContext = createMailerContext;
84
-
85
71
  const createMailerGraphQL = () => {
86
72
  return [...(0, _graphql.createGraphQL)()];
87
73
  };
88
-
89
74
  exports.createMailerGraphQL = createMailerGraphQL;
package/index.js.map CHANGED
@@ -1 +1 @@
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
+ {"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,kBAAW,GAAE;EAC3B,OAAO,CACHD,KAAK;EACL;AACR;AACA;EACQ,IAAAE,0BAAmB,EAACF,KAAK,CAAC;EAC1B;AACR;AACA;EACQ,IAAAG,wBAAe,EAAC,YAAY;IACxB,MAAMC,MAAM,GAAG,MAAM,IAAAC,0CAAoB,GAAE;IAC3CD,MAAM,CAACE,IAAI,GAAG,eAAe;IAC7B,OAAOF,MAAM;EACjB,CAAC,CAAC;EACF;AACR;AACA;EACQ,IAAAD,wBAAe,EAAC,OAAO;IAAEI;EAAS,CAAC,KAAK;IACpC;AACZ;AACA;IACY,MAAMC,MAA2B,mCACzBD,QAAQ,IAAI,CAAC,CAAC,CACrB;IACD,IAAIA,QAAQ,EAAE;MACVC,MAAM,CAACC,IAAI,GAAG;QACVC,IAAI,EAAEH,QAAQ,CAACG,IAAI;QACnBC,IAAI,EAAEJ,QAAQ,CAACK;MACnB,CAAC;IACL;IACA,MAAMR,MAAM,GAAG,MAAM,IAAAS,wCAAmB,EAACL,MAAM,CAAC;IAChDJ,MAAM,CAACE,IAAI,GAAG,cAAc;IAC5B,OAAOF,MAAM;EACjB,CAAC,CAAC,EACF,IAAAU,4BAAyB,GAAE,CAC9B;AACL,CAAC;AAAC;AAEK,MAAMC,mBAAmB,GAAG,MAAM;EACrC,OAAO,CAAC,GAAG,IAAAC,sBAAa,GAAE,CAAC;AAC/B,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-mailer",
3
- "version": "0.0.0-unstable.d16f688daf",
3
+ "version": "0.0.0-unstable.d65ec29d44",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,16 +14,16 @@
14
14
  "description": "The API to send e-mails.",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "7.19.0",
18
- "@webiny/api": "0.0.0-unstable.d16f688daf",
19
- "@webiny/api-headless-cms": "0.0.0-unstable.d16f688daf",
20
- "@webiny/error": "0.0.0-unstable.d16f688daf",
21
- "@webiny/handler-graphql": "0.0.0-unstable.d16f688daf",
22
- "@webiny/plugins": "0.0.0-unstable.d16f688daf",
23
- "@webiny/pubsub": "0.0.0-unstable.d16f688daf",
17
+ "@babel/runtime": "7.20.13",
18
+ "@webiny/api": "0.0.0-unstable.d65ec29d44",
19
+ "@webiny/api-headless-cms": "0.0.0-unstable.d65ec29d44",
20
+ "@webiny/error": "0.0.0-unstable.d65ec29d44",
21
+ "@webiny/handler-graphql": "0.0.0-unstable.d65ec29d44",
22
+ "@webiny/plugins": "0.0.0-unstable.d65ec29d44",
23
+ "@webiny/pubsub": "0.0.0-unstable.d65ec29d44",
24
24
  "crypto-js": "4.1.1",
25
25
  "lodash": "4.17.21",
26
- "nodemailer": "6.8.0",
26
+ "nodemailer": "6.9.1",
27
27
  "zod": "3.20.2"
28
28
  },
29
29
  "devDependencies": {
@@ -33,19 +33,19 @@
33
33
  "@babel/preset-typescript": "^7.18.6",
34
34
  "@types/crypto-js": "^4.1.1",
35
35
  "@types/nodemailer": "^6.4.4",
36
- "@webiny/api-headless-cms-ddb": "^0.0.0-unstable.d16f688daf",
37
- "@webiny/api-i18n": "^0.0.0-unstable.d16f688daf",
38
- "@webiny/api-i18n-ddb": "^0.0.0-unstable.d16f688daf",
39
- "@webiny/api-security": "^0.0.0-unstable.d16f688daf",
40
- "@webiny/api-security-so-ddb": "^0.0.0-unstable.d16f688daf",
41
- "@webiny/api-tenancy": "^0.0.0-unstable.d16f688daf",
42
- "@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.d16f688daf",
43
- "@webiny/cli": "^0.0.0-unstable.d16f688daf",
44
- "@webiny/db-dynamodb": "^0.0.0-unstable.d16f688daf",
45
- "@webiny/handler": "^0.0.0-unstable.d16f688daf",
46
- "@webiny/handler-aws": "^0.0.0-unstable.d16f688daf",
47
- "@webiny/handler-db": "^0.0.0-unstable.d16f688daf",
48
- "@webiny/project-utils": "^0.0.0-unstable.d16f688daf",
36
+ "@webiny/api-headless-cms-ddb": "^0.0.0-unstable.d65ec29d44",
37
+ "@webiny/api-i18n": "^0.0.0-unstable.d65ec29d44",
38
+ "@webiny/api-i18n-ddb": "^0.0.0-unstable.d65ec29d44",
39
+ "@webiny/api-security": "^0.0.0-unstable.d65ec29d44",
40
+ "@webiny/api-security-so-ddb": "^0.0.0-unstable.d65ec29d44",
41
+ "@webiny/api-tenancy": "^0.0.0-unstable.d65ec29d44",
42
+ "@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.d65ec29d44",
43
+ "@webiny/cli": "^0.0.0-unstable.d65ec29d44",
44
+ "@webiny/db-dynamodb": "^0.0.0-unstable.d65ec29d44",
45
+ "@webiny/handler": "^0.0.0-unstable.d65ec29d44",
46
+ "@webiny/handler-aws": "^0.0.0-unstable.d65ec29d44",
47
+ "@webiny/handler-db": "^0.0.0-unstable.d65ec29d44",
48
+ "@webiny/project-utils": "^0.0.0-unstable.d65ec29d44",
49
49
  "graphql": "^15.7.2",
50
50
  "jest": "^28.1.0",
51
51
  "jest-dynalite": "^3.6.1",
@@ -61,5 +61,5 @@
61
61
  "build": "yarn webiny run build",
62
62
  "watch": "yarn webiny run watch"
63
63
  },
64
- "gitHead": "d16f688daf2f36622d725e53a4dd1c0486017015"
64
+ "gitHead": "d65ec29d4408dff33cb4e30a943bf7d2dabceb4d"
65
65
  }
@@ -1,34 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createTransport = exports.CreateTransportPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class CreateTransportPlugin extends _plugins.Plugin {
15
11
  constructor(cb) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "cb", void 0);
18
14
  this.cb = cb;
19
15
  }
20
-
21
16
  async buildMailerTransport(params) {
22
17
  return this.cb(params);
23
18
  }
24
-
25
19
  }
26
-
27
20
  exports.CreateTransportPlugin = CreateTransportPlugin;
28
21
  (0, _defineProperty2.default)(CreateTransportPlugin, "type", "mailer.builder.plugin");
29
-
30
22
  const createTransport = cb => {
31
23
  return new CreateTransportPlugin(cb);
32
24
  };
33
-
34
25
  exports.createTransport = createTransport;
@@ -1 +1 @@
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
+ {"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,qBAAqB,SAA0CC,eAAU,CAAC;EAK5EC,WAAW,CAACC,EAA8B,EAAE;IAC/C,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAaC,oBAAoB,CAACC,MAAuB,EAAc;IACnE,OAAO,IAAI,CAACF,EAAE,CAACE,MAAM,CAAC;EAC1B;AACJ;AAAC;AAAA,8BAbYL,qBAAqB,UACA,uBAAuB;AAclD,MAAMM,eAAe,GACxBH,EAA8B,IAC7B;EACD,OAAO,IAAIH,qBAAqB,CAAIG,EAAE,CAAC;AAC3C,CAAC;AAAC"}
package/plugins/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _CreateTransportPlugin = require("./CreateTransportPlugin");
8
-
9
7
  Object.keys(_CreateTransportPlugin).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _CreateTransportPlugin[key]) return;
@@ -1 +1 @@
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
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CreateTransportPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createDummyTransport = void 0;
7
-
8
7
  const createDummyTransport = () => {
9
8
  const sent = [];
10
9
  return {
@@ -21,5 +20,4 @@ const createDummyTransport = () => {
21
20
  }
22
21
  };
23
22
  };
24
-
25
23
  exports.createDummyTransport = createDummyTransport;
@@ -1 +1 @@
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
+ {"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,EAAE;EAEpC,OAAO;IACHC,IAAI,EAAE,eAAe;IACrBC,IAAI,EAAE,MAAMC,MAAM,IAAI;MAClBH,IAAI,CAACI,IAAI,CAACD,MAAM,CAAC;MACjB,OAAO;QACHE,MAAM,EAAE,IAAI;QACZC,KAAK,EAAE;MACX,CAAC;IACL,CAAC;IACDC,UAAU,EAAE,MAAM;MACd,OAAOP,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,50 +1,39 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSmtpTransport = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _nodemailer = _interopRequireDefault(require("nodemailer"));
15
-
16
11
  /**
17
12
  * Nodemailer docs
18
13
  * https://nodemailer.com/about/
19
14
  */
15
+
20
16
  const configDefaults = {
21
17
  socketTimeout: 15000,
22
18
  connectionTimeout: 15000,
23
19
  greetingTimeout: 15000
24
20
  };
25
-
26
21
  const applyDefaults = initialConfig => {
27
22
  return Object.keys(configDefaults).reduce((config, key) => {
28
23
  const configKey = key;
29
-
30
24
  if (config[configKey] === undefined || config[configKey] === null) {
31
25
  // @ts-ignore
32
26
  config[configKey] = configDefaults[configKey];
33
27
  }
34
-
35
28
  return config;
36
29
  }, (0, _objectSpread2.default)({}, initialConfig));
37
30
  };
38
-
39
31
  const createSmtpTransport = initialConfig => {
40
32
  if (!initialConfig || typeof initialConfig !== "object" || Object.keys(initialConfig).length === 0) {
41
33
  throw new _error.default("There is no configuration for the SMTP transport.");
42
34
  }
43
-
44
35
  const config = applyDefaults(initialConfig);
45
-
46
36
  const transporter = _nodemailer.default.createTransport(config);
47
-
48
37
  return {
49
38
  name: "smtp-default",
50
39
  transporter,
@@ -59,7 +48,6 @@ const createSmtpTransport = initialConfig => {
59
48
  from,
60
49
  subject
61
50
  } = params;
62
-
63
51
  try {
64
52
  const result = await transporter.sendMail({
65
53
  replyTo,
@@ -71,14 +59,12 @@ const createSmtpTransport = initialConfig => {
71
59
  to,
72
60
  subject
73
61
  });
74
-
75
62
  if (result.messageId) {
76
63
  return {
77
64
  result: result.response,
78
65
  error: null
79
66
  };
80
67
  }
81
-
82
68
  throw new _error.default({
83
69
  message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
84
70
  code: "MAILER_ERROR",
@@ -97,5 +83,4 @@ const createSmtpTransport = initialConfig => {
97
83
  }
98
84
  };
99
85
  };
100
-
101
86
  exports.createSmtpTransport = createSmtpTransport;
@@ -1 +1 @@
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,GAA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B;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"}
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,KAAK;EACpBC,iBAAiB,EAAE,KAAK;EACxBC,eAAe,EAAE;AACrB,CAAC;AAED,MAAMC,aAAa,GACfC,aAA2C,IACZ;EAC/B,OAAOC,MAAM,CAACC,IAAI,CAACP,cAAc,CAAC,CAACQ,MAAM,CACrC,CAACC,MAAM,EAAEC,GAAG,KAAK;IACb,MAAMC,SAAS,GAAGD,GAA2C;IAC7D,IAAID,MAAM,CAACE,SAAS,CAAC,KAAKC,SAAS,IAAIH,MAAM,CAACE,SAAS,CAAC,KAAK,IAAI,EAAE;MAC/D;MACAF,MAAM,CAACE,SAAS,CAAC,GAAGX,cAAc,CAACW,SAAS,CAAC;IACjD;IAEA,OAAOF,MAAM;EACjB,CAAC,kCACIJ,aAAa,EACrB;AACL,CAAC;AAEM,MAAMQ,mBAAmB,GAC5BR,aAAmD,IACnC;EAChB,IACI,CAACA,aAAa,IACd,OAA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@ interface BaseTransportSendData {
129
129
  bcc?: string[];
130
130
  from?: string;
131
131
  subject: string;
132
- text: string;
132
+ text?: string;
133
133
  html?: string;
134
134
  replyTo?: string;
135
135
  }
package/types.js.map CHANGED
@@ -1 +1 @@
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":""}
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":""}