@webiny/api-mailer 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0

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 (157) hide show
  1. package/MailerFeature.d.ts +4 -0
  2. package/MailerFeature.js +23 -0
  3. package/MailerFeature.js.map +1 -0
  4. package/constants.d.ts +1 -1
  5. package/constants.js +2 -1
  6. package/constants.js.map +1 -1
  7. package/domain/MailTransport/abstractions.d.ts +8 -3
  8. package/domain/MailTransport/abstractions.js +3 -2
  9. package/domain/MailTransport/abstractions.js.map +1 -1
  10. package/domain/MailerService/abstractions.d.ts +4 -2
  11. package/domain/MailerService/abstractions.js +2 -1
  12. package/domain/MailerService/abstractions.js.map +1 -1
  13. package/domain/MailerService/errors.d.ts +4 -0
  14. package/domain/MailerService/errors.js +29 -24
  15. package/domain/MailerService/errors.js.map +1 -1
  16. package/domain/TransportSettings/abstractions.d.ts +47 -0
  17. package/domain/TransportSettings/abstractions.js +5 -0
  18. package/domain/TransportSettings/abstractions.js.map +1 -0
  19. package/domain/TransportSettings/findDefinition.d.ts +6 -0
  20. package/domain/TransportSettings/findDefinition.js +13 -0
  21. package/domain/TransportSettings/findDefinition.js.map +1 -0
  22. package/domain/errors.d.ts +23 -5
  23. package/domain/errors.js +68 -40
  24. package/domain/errors.js.map +1 -1
  25. package/exports/api/mailer.d.ts +6 -0
  26. package/exports/api/mailer.js +6 -0
  27. package/features/GetSettings/GetSettingsRepository.d.ts +7 -5
  28. package/features/GetSettings/GetSettingsRepository.js +43 -30
  29. package/features/GetSettings/GetSettingsRepository.js.map +1 -1
  30. package/features/GetSettings/GetSettingsUseCase.d.ts +11 -4
  31. package/features/GetSettings/GetSettingsUseCase.js +38 -10
  32. package/features/GetSettings/GetSettingsUseCase.js.map +1 -1
  33. package/features/GetSettings/abstractions.d.ts +20 -6
  34. package/features/GetSettings/abstractions.js +3 -2
  35. package/features/GetSettings/abstractions.js.map +1 -1
  36. package/features/GetSettings/feature.d.ts +4 -1
  37. package/features/GetSettings/feature.js +7 -6
  38. package/features/GetSettings/feature.js.map +1 -1
  39. package/features/GetSettings/index.d.ts +2 -1
  40. package/features/GetSettings/index.js +1 -3
  41. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.d.ts +11 -0
  42. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js +19 -0
  43. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js.map +1 -0
  44. package/features/IsMailerConfigured/abstractions.d.ts +18 -0
  45. package/features/IsMailerConfigured/abstractions.js +5 -0
  46. package/features/IsMailerConfigured/abstractions.js.map +1 -0
  47. package/features/IsMailerConfigured/feature.d.ts +4 -0
  48. package/features/IsMailerConfigured/feature.js +11 -0
  49. package/features/IsMailerConfigured/feature.js.map +1 -0
  50. package/features/IsMailerConfigured/index.d.ts +1 -0
  51. package/features/IsMailerConfigured/index.js +1 -0
  52. package/features/MailerService/MailerService.d.ts +3 -4
  53. package/features/MailerService/MailerService.js +42 -41
  54. package/features/MailerService/MailerService.js.map +1 -1
  55. package/features/MailerService/feature.d.ts +4 -1
  56. package/features/MailerService/feature.js +6 -5
  57. package/features/MailerService/feature.js.map +1 -1
  58. package/features/SaveSettings/SaveSettingsRepository.d.ts +4 -3
  59. package/features/SaveSettings/SaveSettingsRepository.js +58 -48
  60. package/features/SaveSettings/SaveSettingsRepository.js.map +1 -1
  61. package/features/SaveSettings/SaveSettingsUseCase.d.ts +6 -4
  62. package/features/SaveSettings/SaveSettingsUseCase.js +49 -42
  63. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
  64. package/features/SaveSettings/abstractions.d.ts +22 -21
  65. package/features/SaveSettings/abstractions.js +5 -8
  66. package/features/SaveSettings/abstractions.js.map +1 -1
  67. package/features/SaveSettings/events.d.ts +3 -3
  68. package/features/SaveSettings/events.js +17 -12
  69. package/features/SaveSettings/events.js.map +1 -1
  70. package/features/SaveSettings/feature.d.ts +4 -1
  71. package/features/SaveSettings/feature.js +7 -6
  72. package/features/SaveSettings/feature.js.map +1 -1
  73. package/features/SaveSettings/index.d.ts +2 -1
  74. package/features/SaveSettings/index.js +1 -3
  75. package/features/SendMail/SendMailUseCase.d.ts +2 -2
  76. package/features/SendMail/SendMailUseCase.js +44 -48
  77. package/features/SendMail/SendMailUseCase.js.map +1 -1
  78. package/features/SendMail/abstractions.d.ts +7 -7
  79. package/features/SendMail/abstractions.js +5 -8
  80. package/features/SendMail/abstractions.js.map +1 -1
  81. package/features/SendMail/events.d.ts +4 -4
  82. package/features/SendMail/events.js +24 -17
  83. package/features/SendMail/events.js.map +1 -1
  84. package/features/SendMail/feature.d.ts +4 -1
  85. package/features/SendMail/feature.js +6 -5
  86. package/features/SendMail/feature.js.map +1 -1
  87. package/features/SendMail/index.d.ts +1 -0
  88. package/features/SendMail/index.js +1 -0
  89. package/features/SendTestMail/SendTestMailUseCase.d.ts +13 -0
  90. package/features/SendTestMail/SendTestMailUseCase.js +40 -0
  91. package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
  92. package/features/SendTestMail/abstractions.d.ts +32 -0
  93. package/features/SendTestMail/abstractions.js +5 -0
  94. package/features/SendTestMail/abstractions.js.map +1 -0
  95. package/features/SendTestMail/feature.d.ts +4 -0
  96. package/features/SendTestMail/feature.js +11 -0
  97. package/features/SendTestMail/feature.js.map +1 -0
  98. package/graphql/MailerSchemaFactory.d.ts +10 -0
  99. package/graphql/MailerSchemaFactory.js +135 -0
  100. package/graphql/MailerSchemaFactory.js.map +1 -0
  101. package/index.d.ts +11 -2
  102. package/index.js +8 -26
  103. package/package.json +25 -33
  104. package/types.d.ts +0 -8
  105. package/types.js +0 -3
  106. package/utils/isMailboxAddress.d.ts +6 -0
  107. package/utils/isMailboxAddress.js +5 -0
  108. package/utils/isMailboxAddress.js.map +1 -0
  109. package/domain/Encryption/abstractions.d.ts +0 -8
  110. package/domain/Encryption/abstractions.js +0 -4
  111. package/domain/Encryption/abstractions.js.map +0 -1
  112. package/features/DummyTransport/DummyMailTransport.d.ts +0 -9
  113. package/features/DummyTransport/DummyMailTransport.js +0 -12
  114. package/features/DummyTransport/DummyMailTransport.js.map +0 -1
  115. package/features/DummyTransport/DummyMailTransportFactory.d.ts +0 -8
  116. package/features/DummyTransport/DummyMailTransportFactory.js +0 -13
  117. package/features/DummyTransport/DummyMailTransportFactory.js.map +0 -1
  118. package/features/DummyTransport/feature.d.ts +0 -1
  119. package/features/DummyTransport/feature.js +0 -10
  120. package/features/DummyTransport/feature.js.map +0 -1
  121. package/features/Encryption/PasswordEncryption.d.ts +0 -9
  122. package/features/Encryption/PasswordEncryption.js +0 -23
  123. package/features/Encryption/PasswordEncryption.js.map +0 -1
  124. package/features/Encryption/feature.d.ts +0 -1
  125. package/features/Encryption/feature.js +0 -10
  126. package/features/Encryption/feature.js.map +0 -1
  127. package/features/Encryption/utils/password.d.ts +0 -7
  128. package/features/Encryption/utils/password.js +0 -56
  129. package/features/Encryption/utils/password.js.map +0 -1
  130. package/features/Encryption/utils/secret.d.ts +0 -1
  131. package/features/Encryption/utils/secret.js +0 -11
  132. package/features/Encryption/utils/secret.js.map +0 -1
  133. package/features/GetSettings/index.js.map +0 -1
  134. package/features/MailerService/TransportFactory.d.ts +0 -2
  135. package/features/MailerService/TransportFactory.js +0 -31
  136. package/features/MailerService/TransportFactory.js.map +0 -1
  137. package/features/SaveSettings/index.js.map +0 -1
  138. package/features/SaveSettings/validation.d.ts +0 -23
  139. package/features/SaveSettings/validation.js +0 -19
  140. package/features/SaveSettings/validation.js.map +0 -1
  141. package/features/SmtpTransport/SmtpConfig.d.ts +0 -6
  142. package/features/SmtpTransport/SmtpConfig.js +0 -29
  143. package/features/SmtpTransport/SmtpConfig.js.map +0 -1
  144. package/features/SmtpTransport/SmtpMailTransport.d.ts +0 -18
  145. package/features/SmtpTransport/SmtpMailTransport.js +0 -61
  146. package/features/SmtpTransport/SmtpMailTransport.js.map +0 -1
  147. package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +0 -9
  148. package/features/SmtpTransport/SmtpMailTransportFactory.js +0 -14
  149. package/features/SmtpTransport/SmtpMailTransportFactory.js.map +0 -1
  150. package/features/SmtpTransport/feature.d.ts +0 -1
  151. package/features/SmtpTransport/feature.js +0 -10
  152. package/features/SmtpTransport/feature.js.map +0 -1
  153. package/graphql/settings.d.ts +0 -3
  154. package/graphql/settings.js +0 -115
  155. package/graphql/settings.js.map +0 -1
  156. package/index.js.map +0 -1
  157. package/types.js.map +0 -1
@@ -1,61 +0,0 @@
1
- import nodemailer from "nodemailer";
2
- export class SmtpMailTransport {
3
- name = "Mailer/SmtpTransport";
4
- constructor(config) {
5
- this.transporter = nodemailer.createTransport(config);
6
- }
7
- async send(params) {
8
- const {
9
- replyTo,
10
- text,
11
- html,
12
- to,
13
- bcc,
14
- cc,
15
- from,
16
- subject
17
- } = params;
18
- try {
19
- const result = await this.transporter.sendMail({
20
- replyTo,
21
- bcc,
22
- cc,
23
- from,
24
- text,
25
- html,
26
- to,
27
- subject
28
- });
29
- if (result.messageId) {
30
- return {
31
- result: result.response,
32
- error: null
33
- };
34
- }
35
- return {
36
- result: null,
37
- error: {
38
- message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
39
- code: "MAILER_ERROR",
40
- data: {
41
- ...result
42
- }
43
- }
44
- };
45
- } catch (ex) {
46
- return {
47
- result: null,
48
- error: {
49
- message: ex.message,
50
- code: ex.code,
51
- data: {
52
- ...params,
53
- ...ex.data
54
- }
55
- }
56
- };
57
- }
58
- }
59
- }
60
-
61
- //# sourceMappingURL=SmtpMailTransport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["nodemailer","SmtpMailTransport","name","constructor","config","transporter","createTransport","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","response","error","message","code","data","ex"],"sources":["SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(config: SMTPTransport.Options) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n 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"],"mappings":"AACA,OAAOA,UAAU,MAAM,YAAY;AAInC,OAAO,MAAMC,iBAAiB,CAAoC;EAC9CC,IAAI,GAAG,sBAAsB;EAG7CC,WAAWA,CAACC,MAA6B,EAAE;IACvC,IAAI,CAACC,WAAW,GAAGL,UAAU,CAACM,eAAe,CAACF,MAAM,CAAC;EACzD;EAEA,MAAMG,IAAIA,CAACC,MAAgC,EAAE;IACzC,MAAM;MAAEC,OAAO;MAAEC,IAAI;MAAEC,IAAI;MAAEC,EAAE;MAAEC,GAAG;MAAEC,EAAE;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGR,MAAM;IAElE,IAAI;MACA,MAAMS,MAAM,GAAG,MAAM,IAAI,CAACZ,WAAW,CAACa,QAAQ,CAAC;QAC3CT,OAAO;QACPI,GAAG;QACHC,EAAE;QACFC,IAAI;QACJL,IAAI;QACJC,IAAI;QACJC,EAAE;QACFI;MACJ,CAAC,CAAC;MAEF,IAAIC,MAAM,CAACE,SAAS,EAAE;QAClB,OAAO;UACHF,MAAM,EAAEA,MAAM,CAACG,QAAQ;UACvBC,KAAK,EAAE;QACX,CAAC;MACL;MAEA,OAAO;QACHJ,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EACH,sFAAsF;UAC1FC,IAAI,EAAE,cAAc;UACpBC,IAAI,EAAE;YACF,GAAGP;UACP;QACJ;MACJ,CAAC;IACL,CAAC,CAAC,OAAOQ,EAAO,EAAE;MACd,OAAO;QACHR,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EAAEG,EAAE,CAACH,OAAO;UACnBC,IAAI,EAAEE,EAAE,CAACF,IAAI;UACbC,IAAI,EAAE;YACF,GAAGhB,MAAM;YACT,GAAGiB,EAAE,CAACD;UACV;QACJ;MACJ,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
@@ -1,9 +0,0 @@
1
- import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
2
- import type { TransportSettings } from "../../types.js";
3
- declare class SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {
4
- createTransport(settings: TransportSettings): MailTransportFactory.Return;
5
- }
6
- export declare const SmtpMailTransportFactory: typeof SmtpMailTransportFactoryImpl & {
7
- __abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportFactory>;
8
- };
9
- export {};
@@ -1,14 +0,0 @@
1
- import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
2
- import { SmtpMailTransport } from "./SmtpMailTransport.js";
3
- import { SmtpConfig } from "./SmtpConfig.js";
4
- class SmtpMailTransportFactoryImpl {
5
- async createTransport(settings) {
6
- return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));
7
- }
8
- }
9
- export const SmtpMailTransportFactory = MailTransportFactory.createImplementation({
10
- implementation: SmtpMailTransportFactoryImpl,
11
- dependencies: []
12
- });
13
-
14
- //# sourceMappingURL=SmtpMailTransportFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["MailTransportFactory","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactoryImpl","createTransport","settings","fromTransportSettings","SmtpMailTransportFactory","createImplementation","implementation","dependencies"],"sources":["SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n async createTransport(settings: TransportSettings): MailTransportFactory.Return {\n return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));\n }\n}\n\nexport const SmtpMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: SmtpMailTransportFactoryImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAEnB,MAAMC,4BAA4B,CAA2C;EACzE,MAAMC,eAAeA,CAACC,QAA2B,EAA+B;IAC5E,OAAO,IAAIJ,iBAAiB,CAACC,UAAU,CAACI,qBAAqB,CAACD,QAAQ,CAAC,CAAC;EAC5E;AACJ;AAEA,OAAO,MAAME,wBAAwB,GAAGP,oBAAoB,CAACQ,oBAAoB,CAAC;EAC9EC,cAAc,EAAEN,4BAA4B;EAC5CO,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- export declare const SmtpTransportFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -1,10 +0,0 @@
1
- import { createFeature } from "@webiny/feature/api";
2
- import { SmtpMailTransportFactory } from "./SmtpMailTransportFactory.js";
3
- export const SmtpTransportFeature = createFeature({
4
- name: "SmtpTransport",
5
- register(container) {
6
- container.register(SmtpMailTransportFactory).inSingletonScope();
7
- }
8
- });
9
-
10
- //# sourceMappingURL=feature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createFeature","SmtpMailTransportFactory","SmtpTransportFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SmtpMailTransportFactory } from \"./SmtpMailTransportFactory.js\";\n\nexport const SmtpTransportFeature = createFeature({\n name: \"SmtpTransport\",\n register(container) {\n container.register(SmtpMailTransportFactory).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,wBAAwB;AAEjC,OAAO,MAAMC,oBAAoB,GAAGF,aAAa,CAAC;EAC9CG,IAAI,EAAE,eAAe;EACrBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,wBAAwB,CAAC,CAACK,gBAAgB,CAAC,CAAC;EACnE;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
- import type { Context } from "@webiny/api/types.js";
3
- export declare const createSettingsGraphQL: () => GraphQLSchemaPlugin<Context>;
@@ -1,115 +0,0 @@
1
- import { ErrorResponse, GraphQLSchemaPlugin, Response } from "@webiny/handler-graphql";
2
- import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
3
- import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
4
- import { getSecret } from "../features/Encryption/utils/secret.js";
5
- const emptyResolver = () => ({});
6
- export const createSettingsGraphQL = () => {
7
- return new GraphQLSchemaPlugin({
8
- typeDefs: `
9
- type MailerTransportSettingsError {
10
- message: String!
11
- code: String
12
- data: JSON
13
- }
14
-
15
- type MailerTransportSettings {
16
- host: String
17
- port: Number
18
- user: String
19
- from: String
20
- replyTo: String
21
- }
22
-
23
- type MailerTransportSettingsResponse {
24
- data: MailerTransportSettings
25
- error: MailerTransportSettingsError
26
- }
27
-
28
- type MailerQuery {
29
- getSettings: MailerTransportSettingsResponse!
30
- }
31
-
32
- input MailerTransportSettingsInput {
33
- host: String!
34
- port: Number
35
- user: String!
36
- password: String
37
- from: String!
38
- replyTo: String
39
- }
40
-
41
- type MailerMutation {
42
- saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!
43
- }
44
-
45
- extend type Query {
46
- mailer: MailerQuery
47
- }
48
- extend type Mutation {
49
- mailer: MailerMutation
50
- }
51
- `,
52
- resolvers: {
53
- Query: {
54
- mailer: emptyResolver
55
- },
56
- MailerQuery: {
57
- getSettings: async (_, __, context) => {
58
- try {
59
- // First check of encryption key is set!
60
- // If not, this function will throw an error.
61
- // TODO: refactor this to make more sense.
62
- getSecret();
63
- const getSettings = context.container.resolve(GetSettingsUseCase);
64
- const result = await getSettings.execute();
65
- const settings = result.value;
66
-
67
- // Remove password from response
68
- if (settings?.password) {
69
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
- const {
71
- password,
72
- ...settingsWithoutPassword
73
- } = settings;
74
- return new Response(settingsWithoutPassword);
75
- }
76
- return new Response(settings);
77
- } catch (ex) {
78
- return new ErrorResponse(ex);
79
- }
80
- }
81
- },
82
- Mutation: {
83
- mailer: emptyResolver
84
- },
85
- MailerMutation: {
86
- saveSettings: async (_, args, context) => {
87
- try {
88
- const saveSettings = context.container.resolve(SaveSettingsUseCase);
89
- const result = await saveSettings.execute(args.data);
90
- if (result.isFail()) {
91
- return new ErrorResponse(result.error);
92
- }
93
- const settings = result.value;
94
-
95
- // Remove password from response
96
- // TODO: create a GraphQL output mapper
97
- if (settings?.password) {
98
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
99
- const {
100
- password,
101
- ...settingsWithoutPassword
102
- } = settings;
103
- return new Response(settingsWithoutPassword);
104
- }
105
- return new Response(settings);
106
- } catch (ex) {
107
- return new ErrorResponse(ex);
108
- }
109
- }
110
- }
111
- }
112
- });
113
- };
114
-
115
- //# sourceMappingURL=settings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ErrorResponse","GraphQLSchemaPlugin","Response","GetSettingsUseCase","SaveSettingsUseCase","getSecret","emptyResolver","createSettingsGraphQL","typeDefs","resolvers","Query","mailer","MailerQuery","getSettings","_","__","context","container","resolve","result","execute","settings","value","password","settingsWithoutPassword","ex","Mutation","MailerMutation","saveSettings","args","data","isFail","error"],"sources":["settings.ts"],"sourcesContent":["import { ErrorResponse, GraphQLSchemaPlugin, Response } from \"@webiny/handler-graphql\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport { getSecret } from \"~/features/Encryption/utils/secret.js\";\n\nconst emptyResolver = () => ({});\n\nexport const createSettingsGraphQL = () => {\n return new GraphQLSchemaPlugin<Context>({\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 // First check of encryption key is set!\n // If not, this function will throw an error.\n // TODO: refactor this to make more sense.\n getSecret();\n\n const getSettings = context.container.resolve(GetSettingsUseCase);\n const result = await getSettings.execute();\n\n const settings = result.value;\n\n // Remove password from response\n if (settings?.password) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password, ...settingsWithoutPassword } = settings;\n return new Response(settingsWithoutPassword);\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 saveSettings = context.container.resolve(SaveSettingsUseCase);\n const result = await saveSettings.execute(args.data);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n const settings = result.value;\n\n // Remove password from response\n // TODO: create a GraphQL output mapper\n if (settings?.password) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password, ...settingsWithoutPassword } = settings;\n return new Response(settingsWithoutPassword);\n }\n return new Response(settings);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n }\n }\n });\n};\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,mBAAmB,EAAEC,QAAQ,QAAQ,yBAAyB;AACtF,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAE5B,SAASC,SAAS;AAElB,MAAMC,aAAa,GAAGA,CAAA,MAAO,CAAC,CAAC,CAAC;AAEhC,OAAO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,OAAO,IAAIN,mBAAmB,CAAU;IACpCO,QAAQ,EAAE;AAClB;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,EAAEL;MACZ,CAAC;MACDM,WAAW,EAAE;QACTC,WAAW,EAAE,MAAAA,CAAOC,CAAC,EAAEC,EAAE,EAAEC,OAAO,KAAK;UACnC,IAAI;YACA;YACA;YACA;YACAX,SAAS,CAAC,CAAC;YAEX,MAAMQ,WAAW,GAAGG,OAAO,CAACC,SAAS,CAACC,OAAO,CAACf,kBAAkB,CAAC;YACjE,MAAMgB,MAAM,GAAG,MAAMN,WAAW,CAACO,OAAO,CAAC,CAAC;YAE1C,MAAMC,QAAQ,GAAGF,MAAM,CAACG,KAAK;;YAE7B;YACA,IAAID,QAAQ,EAAEE,QAAQ,EAAE;cACpB;cACA,MAAM;gBAAEA,QAAQ;gBAAE,GAAGC;cAAwB,CAAC,GAAGH,QAAQ;cACzD,OAAO,IAAInB,QAAQ,CAACsB,uBAAuB,CAAC;YAChD;YACA,OAAO,IAAItB,QAAQ,CAACmB,QAAQ,CAAC;UACjC,CAAC,CAAC,OAAOI,EAAE,EAAE;YACT,OAAO,IAAIzB,aAAa,CAACyB,EAAE,CAAC;UAChC;QACJ;MACJ,CAAC;MACDC,QAAQ,EAAE;QACNf,MAAM,EAAEL;MACZ,CAAC;MACDqB,cAAc,EAAE;QACZC,YAAY,EAAE,MAAAA,CAAOd,CAAC,EAAEe,IAAS,EAAEb,OAAO,KAAK;UAC3C,IAAI;YACA,MAAMY,YAAY,GAAGZ,OAAO,CAACC,SAAS,CAACC,OAAO,CAACd,mBAAmB,CAAC;YACnE,MAAMe,MAAM,GAAG,MAAMS,YAAY,CAACR,OAAO,CAACS,IAAI,CAACC,IAAI,CAAC;YAEpD,IAAIX,MAAM,CAACY,MAAM,CAAC,CAAC,EAAE;cACjB,OAAO,IAAI/B,aAAa,CAACmB,MAAM,CAACa,KAAK,CAAC;YAC1C;YAEA,MAAMX,QAAQ,GAAGF,MAAM,CAACG,KAAK;;YAE7B;YACA;YACA,IAAID,QAAQ,EAAEE,QAAQ,EAAE;cACpB;cACA,MAAM;gBAAEA,QAAQ;gBAAE,GAAGC;cAAwB,CAAC,GAAGH,QAAQ;cACzD,OAAO,IAAInB,QAAQ,CAACsB,uBAAuB,CAAC;YAChD;YACA,OAAO,IAAItB,QAAQ,CAACmB,QAAQ,CAAC;UACjC,CAAC,CAAC,OAAOI,EAAE,EAAE;YACT,OAAO,IAAIzB,aAAa,CAACyB,EAAE,CAAC;UAChC;QACJ;MACJ;IACJ;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["createContextPlugin","EncryptionFeature","GetSettingsFeature","SaveSettingsFeature","DummyTransportFeature","SmtpTransportFeature","MailerServiceFeature","SendMailFeature","createSettingsGraphQL","MailerService","createMailerContext","context","register","container","createMailerGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { EncryptionFeature } from \"~/features/Encryption/feature.js\";\nimport { GetSettingsFeature } from \"~/features/GetSettings/feature.js\";\nimport { SaveSettingsFeature } from \"~/features/SaveSettings/feature.js\";\nimport { DummyTransportFeature } from \"~/features/DummyTransport/feature.js\";\nimport { SmtpTransportFeature } from \"~/features/SmtpTransport/feature.js\";\nimport { MailerServiceFeature } from \"~/features/MailerService/feature.js\";\nimport { SendMailFeature } from \"~/features/SendMail/feature.js\";\nimport { createSettingsGraphQL } from \"~/graphql/settings.js\";\n\nexport { MailerService } from \"./domain/MailerService/abstractions.js\";\nexport type { IMailerService, IMailerServiceErrors } from \"./domain/MailerService/abstractions.js\";\n\nexport const createMailerContext = () => {\n return createContextPlugin(context => {\n // Register all features\n EncryptionFeature.register(context.container);\n DummyTransportFeature.register(context.container);\n SmtpTransportFeature.register(context.container);\n GetSettingsFeature.register(context.container);\n SaveSettingsFeature.register(context.container);\n MailerServiceFeature.register(context.container);\n SendMailFeature.register(context.container);\n });\n};\n\nexport const createMailerGraphQL = () => {\n return createSettingsGraphQL();\n};\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,aAAa;AACjD,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAC5B,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AACxB,SAASC,qBAAqB;AAE9B,SAASC,aAAa;AAGtB,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,OAAOV,mBAAmB,CAACW,OAAO,IAAI;IAClC;IACAV,iBAAiB,CAACW,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAC7CT,qBAAqB,CAACQ,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IACjDR,oBAAoB,CAACO,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAChDX,kBAAkB,CAACU,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAC9CV,mBAAmB,CAACS,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAC/CP,oBAAoB,CAACM,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAChDN,eAAe,CAACK,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;EAC/C,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,OAAON,qBAAqB,CAAC,CAAC;AAClC,CAAC","ignoreList":[]}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["// TODO: place types into appropriate domain abstractions\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);\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":"","ignoreList":[]}