@webiny/api-mailer 0.0.0-unstable.61c048f412 → 0.0.0-unstable.676006d08e

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
@@ -0,0 +1,4 @@
1
+ export declare const MailerFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,23 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { MailerServiceFeature } from "./features/MailerService/feature.js";
3
+ import { SendMailFeature } from "./features/SendMail/feature.js";
4
+ import { SendTestMailFeature } from "./features/SendTestMail/feature.js";
5
+ import { IsMailerConfiguredFeature } from "./features/IsMailerConfigured/feature.js";
6
+ import { GetSettingsFeature } from "./features/GetSettings/feature.js";
7
+ import { SaveSettingsFeature } from "./features/SaveSettings/feature.js";
8
+ import { MailerSchemaFactory } from "./graphql/MailerSchemaFactory.js";
9
+ const MailerFeature = createFeature({
10
+ name: "Mailer",
11
+ register (container) {
12
+ MailerServiceFeature.register(container);
13
+ SendMailFeature.register(container);
14
+ SendTestMailFeature.register(container);
15
+ IsMailerConfiguredFeature.register(container);
16
+ GetSettingsFeature.register(container);
17
+ SaveSettingsFeature.register(container);
18
+ container.register(MailerSchemaFactory);
19
+ }
20
+ });
21
+ export { MailerFeature };
22
+
23
+ //# sourceMappingURL=MailerFeature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MailerFeature.js","sources":["../src/MailerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerServiceFeature } from \"~/features/MailerService/feature.js\";\nimport { SendMailFeature } from \"~/features/SendMail/feature.js\";\nimport { SendTestMailFeature } from \"~/features/SendTestMail/feature.js\";\nimport { IsMailerConfiguredFeature } from \"~/features/IsMailerConfigured/feature.js\";\nimport { GetSettingsFeature } from \"~/features/GetSettings/feature.js\";\nimport { SaveSettingsFeature } from \"~/features/SaveSettings/feature.js\";\nimport { MailerSchemaFactory } from \"~/graphql/MailerSchemaFactory.js\";\n\n/*\n * Sending, without a transport of its own. Transports are `MailTransportFactory` implementations\n * registered by other packages (`@webiny/mailer-smtp`) or by the project. A transport with stored\n * settings registers a `TransportSettingsDefinition`; reading and saving them is done here.\n */\nexport const MailerFeature = createFeature({\n name: \"Mailer\",\n register(container) {\n MailerServiceFeature.register(container);\n SendMailFeature.register(container);\n SendTestMailFeature.register(container);\n IsMailerConfiguredFeature.register(container);\n GetSettingsFeature.register(container);\n SaveSettingsFeature.register(container);\n container.register(MailerSchemaFactory);\n }\n});\n"],"names":["MailerFeature","createFeature","container","MailerServiceFeature","SendMailFeature","SendTestMailFeature","IsMailerConfiguredFeature","GetSettingsFeature","SaveSettingsFeature","MailerSchemaFactory"],"mappings":";;;;;;;;AAcO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdC,qBAAqB,QAAQ,CAACD;QAC9BE,gBAAgB,QAAQ,CAACF;QACzBG,oBAAoB,QAAQ,CAACH;QAC7BI,0BAA0B,QAAQ,CAACJ;QACnCK,mBAAmB,QAAQ,CAACL;QAC5BM,oBAAoB,QAAQ,CAACN;QAC7BA,UAAU,QAAQ,CAACO;IACvB;AACJ"}
package/constants.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MAILER_TRANSPORT_SETTINGS = "Mailer/Settings/Transport";
1
+ export declare const MAILER_SETTINGS_PERMISSION = "mailer.settings";
package/constants.js CHANGED
@@ -1,3 +1,4 @@
1
- export const MAILER_TRANSPORT_SETTINGS = "Mailer/Settings/Transport";
1
+ const MAILER_SETTINGS_PERMISSION = "mailer.settings";
2
+ export { MAILER_SETTINGS_PERMISSION };
2
3
 
3
4
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["MAILER_TRANSPORT_SETTINGS"],"sources":["constants.ts"],"sourcesContent":["export const MAILER_TRANSPORT_SETTINGS = \"Mailer/Settings/Transport\";\n"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,GAAG,2BAA2B","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const MAILER_SETTINGS_PERMISSION = \"mailer.settings\";\n"],"names":["MAILER_SETTINGS_PERMISSION"],"mappings":"AAAO,MAAMA,6BAA6B"}
@@ -1,4 +1,4 @@
1
- import type { TransportSendData, TransportSendResponse, TransportSettings } from "../../types.js";
1
+ import type { TransportSendData, TransportSendResponse } from "../../types.js";
2
2
  export interface IMailTransport {
3
3
  name: string;
4
4
  send(params: TransportSendData): Promise<TransportSendResponse>;
@@ -9,10 +9,15 @@ export declare namespace MailTransport {
9
9
  type SendParams = TransportSendData;
10
10
  }
11
11
  export interface IMailTransportFactory {
12
- createTransport(settings: TransportSettings): Promise<IMailTransport>;
12
+ name: string;
13
+ /**
14
+ * Reads the transport's own configuration (stored settings, environment variables, whatever the
15
+ * transport uses) and builds it. Null when the transport is not configured.
16
+ */
17
+ createTransport(): Promise<IMailTransport | null>;
13
18
  }
14
19
  export declare const MailTransportFactory: import("@webiny/di").Abstraction<IMailTransportFactory>;
15
20
  export declare namespace MailTransportFactory {
16
21
  type Interface = IMailTransportFactory;
17
- type Return = Promise<IMailTransport>;
22
+ type Return = Promise<IMailTransport | null>;
18
23
  }
@@ -1,5 +1,6 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
- export const MailTransport = createAbstraction("MailTransport");
3
- export const MailTransportFactory = createAbstraction("MailTransportFactory");
2
+ const MailTransport = createAbstraction("MailTransport");
3
+ const MailTransportFactory = createAbstraction("MailTransportFactory");
4
+ export { MailTransport, MailTransportFactory };
4
5
 
5
6
  //# sourceMappingURL=abstractions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","MailTransport","MailTransportFactory"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { TransportSendData, TransportSendResponse, TransportSettings } from \"~/types.js\";\n\nexport interface IMailTransport {\n name: string;\n send(params: TransportSendData): Promise<TransportSendResponse>;\n}\n\nexport const MailTransport = createAbstraction<IMailTransport>(\"MailTransport\");\n\nexport namespace MailTransport {\n export type Interface = IMailTransport;\n export type SendParams = TransportSendData;\n}\n\nexport interface IMailTransportFactory {\n createTransport(settings: TransportSettings): Promise<IMailTransport>;\n}\n\nexport const MailTransportFactory =\n createAbstraction<IMailTransportFactory>(\"MailTransportFactory\");\n\nexport namespace MailTransportFactory {\n export type Interface = IMailTransportFactory;\n export type Return = Promise<IMailTransport>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAQvD,OAAO,MAAMC,aAAa,GAAGD,iBAAiB,CAAiB,eAAe,CAAC;AAW/E,OAAO,MAAME,oBAAoB,GAC7BF,iBAAiB,CAAwB,sBAAsB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"domain/MailTransport/abstractions.js","sources":["../../../src/domain/MailTransport/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { TransportSendData, TransportSendResponse } from \"~/types.js\";\n\nexport interface IMailTransport {\n name: string;\n send(params: TransportSendData): Promise<TransportSendResponse>;\n}\n\nexport const MailTransport = createAbstraction<IMailTransport>(\"MailTransport\");\n\nexport namespace MailTransport {\n export type Interface = IMailTransport;\n export type SendParams = TransportSendData;\n}\n\nexport interface IMailTransportFactory {\n name: string;\n /**\n * Reads the transport's own configuration (stored settings, environment variables, whatever the\n * transport uses) and builds it. Null when the transport is not configured.\n */\n createTransport(): Promise<IMailTransport | null>;\n}\n\nexport const MailTransportFactory =\n createAbstraction<IMailTransportFactory>(\"MailTransportFactory\");\n\nexport namespace MailTransportFactory {\n export type Interface = IMailTransportFactory;\n export type Return = Promise<IMailTransport | null>;\n}\n"],"names":["MailTransport","createAbstraction","MailTransportFactory"],"mappings":";AAQO,MAAMA,gBAAgBC,kBAAkC;AAgBxD,MAAMC,uBACTD,kBAAyC"}
@@ -1,14 +1,16 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import type { TransportSendData, TransportSendResponse } from "../../types.js";
3
- import { NoTransportAvailableError, NoSettingsConfiguredError, TransportSendError } from "./errors.js";
3
+ import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "./errors.js";
4
4
  export interface IMailerServiceErrors {
5
5
  noTransport: NoTransportAvailableError;
6
- noSettings: NoSettingsConfiguredError;
6
+ transportCreate: TransportCreateError;
7
7
  transportSend: TransportSendError;
8
8
  }
9
9
  type MailerServiceError = IMailerServiceErrors[keyof IMailerServiceErrors];
10
10
  export interface IMailerService {
11
11
  sendMail<T = any>(data: TransportSendData): Promise<Result<TransportSendResponse<T>, MailerServiceError>>;
12
+ /** Whether a transport is set up. Outside api-mailer, ask `IsMailerConfiguredUseCase`. */
13
+ isConfigured(): Promise<boolean>;
12
14
  }
13
15
  export declare const MailerService: import("@webiny/di").Abstraction<IMailerService>;
14
16
  export declare namespace MailerService {
@@ -1,4 +1,5 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
- export const MailerService = createAbstraction("MailerService");
2
+ const MailerService = createAbstraction("MailerService");
3
+ export { MailerService };
3
4
 
4
5
  //# sourceMappingURL=abstractions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","MailerService"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { TransportSendData, TransportSendResponse } from \"~/types.js\";\nimport {\n NoTransportAvailableError,\n NoSettingsConfiguredError,\n TransportSendError\n} from \"./errors.js\";\n\nexport interface IMailerServiceErrors {\n noTransport: NoTransportAvailableError;\n noSettings: NoSettingsConfiguredError;\n transportSend: TransportSendError;\n}\n\ntype MailerServiceError = IMailerServiceErrors[keyof IMailerServiceErrors];\n\nexport interface IMailerService {\n sendMail<T = any>(\n data: TransportSendData\n ): Promise<Result<TransportSendResponse<T>, MailerServiceError>>;\n}\n\nexport const MailerService = createAbstraction<IMailerService>(\"MailerService\");\n\nexport namespace MailerService {\n export type Interface = IMailerService;\n export type Return<T = any> = Promise<Result<TransportSendResponse<T>, MailerServiceError>>;\n export type Error = MailerServiceError;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAuBvD,OAAO,MAAMC,aAAa,GAAGD,iBAAiB,CAAiB,eAAe,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"domain/MailerService/abstractions.js","sources":["../../../src/domain/MailerService/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { TransportSendData, TransportSendResponse } from \"~/types.js\";\nimport { NoTransportAvailableError, TransportCreateError, TransportSendError } from \"./errors.js\";\n\nexport interface IMailerServiceErrors {\n noTransport: NoTransportAvailableError;\n transportCreate: TransportCreateError;\n transportSend: TransportSendError;\n}\n\ntype MailerServiceError = IMailerServiceErrors[keyof IMailerServiceErrors];\n\nexport interface IMailerService {\n sendMail<T = any>(\n data: TransportSendData\n ): Promise<Result<TransportSendResponse<T>, MailerServiceError>>;\n\n /** Whether a transport is set up. Outside api-mailer, ask `IsMailerConfiguredUseCase`. */\n isConfigured(): Promise<boolean>;\n}\n\nexport const MailerService = createAbstraction<IMailerService>(\"MailerService\");\n\nexport namespace MailerService {\n export type Interface = IMailerService;\n export type Return<T = any> = Promise<Result<TransportSendResponse<T>, MailerServiceError>>;\n export type Error = MailerServiceError;\n}\n"],"names":["MailerService","createAbstraction"],"mappings":";AAsBO,MAAMA,gBAAgBC,kBAAkC"}
@@ -8,6 +8,10 @@ export declare class NoSettingsConfiguredError extends BaseError {
8
8
  readonly code: "Mailer/MailerService/NoSettingsConfigured";
9
9
  constructor();
10
10
  }
11
+ export declare class TransportCreateError extends BaseError {
12
+ readonly code: "Mailer/MailerService/TransportCreateError";
13
+ constructor(error: unknown);
14
+ }
11
15
  export declare class TransportSendError extends BaseError<{
12
16
  error: TransportSendResponse["error"];
13
17
  }> {
@@ -1,30 +1,35 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
- export class NoTransportAvailableError extends BaseError {
3
- code = "Mailer/MailerService/NoTransportAvailable";
4
- constructor() {
5
- super({
6
- message: "There is no transport available."
7
- });
8
- }
2
+ class NoTransportAvailableError extends BaseError {
3
+ constructor(){
4
+ super({
5
+ message: "There is no transport available."
6
+ }), this.code = "Mailer/MailerService/NoTransportAvailable";
7
+ }
9
8
  }
10
- export class NoSettingsConfiguredError extends BaseError {
11
- code = "Mailer/MailerService/NoSettingsConfigured";
12
- constructor() {
13
- super({
14
- message: "No mailer settings are configured and no environment variables are set."
15
- });
16
- }
9
+ class NoSettingsConfiguredError extends BaseError {
10
+ constructor(){
11
+ super({
12
+ message: "No mailer settings are configured and no environment variables are set."
13
+ }), this.code = "Mailer/MailerService/NoSettingsConfigured";
14
+ }
17
15
  }
18
- export class TransportSendError extends BaseError {
19
- code = "Mailer/MailerService/TransportSendError";
20
- constructor(error) {
21
- super({
22
- message: error.message,
23
- data: {
24
- error
25
- }
26
- });
27
- }
16
+ class TransportCreateError extends BaseError {
17
+ constructor(error){
18
+ super({
19
+ message: error instanceof Error ? error.message : String(error)
20
+ }), this.code = "Mailer/MailerService/TransportCreateError";
21
+ }
28
22
  }
23
+ class TransportSendError extends BaseError {
24
+ constructor(error){
25
+ super({
26
+ message: error.message,
27
+ data: {
28
+ error
29
+ }
30
+ }), this.code = "Mailer/MailerService/TransportSendError";
31
+ }
32
+ }
33
+ export { NoSettingsConfiguredError, NoTransportAvailableError, TransportCreateError, TransportSendError };
29
34
 
30
35
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BaseError","NoTransportAvailableError","code","constructor","message","NoSettingsConfiguredError","TransportSendError","error","data"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { TransportSendResponse } from \"~/types.js\";\n\nexport class NoTransportAvailableError extends BaseError {\n override readonly code = \"Mailer/MailerService/NoTransportAvailable\" as const;\n\n constructor() {\n super({\n message: \"There is no transport available.\"\n });\n }\n}\n\nexport class NoSettingsConfiguredError extends BaseError {\n override readonly code = \"Mailer/MailerService/NoSettingsConfigured\" as const;\n\n constructor() {\n super({\n message: \"No mailer settings are configured and no environment variables are set.\"\n });\n }\n}\n\nexport class TransportSendError extends BaseError<{ error: TransportSendResponse[\"error\"] }> {\n override readonly code = \"Mailer/MailerService/TransportSendError\" as const;\n\n constructor(error: NonNullable<TransportSendResponse[\"error\"]>) {\n super({\n message: error.message,\n data: {\n error\n }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;AAG/C,OAAO,MAAMC,yBAAyB,SAASD,SAAS,CAAC;EACnCE,IAAI,GAAG,2CAA2C;EAEpEC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFC,OAAO,EAAE;IACb,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMC,yBAAyB,SAASL,SAAS,CAAC;EACnCE,IAAI,GAAG,2CAA2C;EAEpEC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFC,OAAO,EAAE;IACb,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAME,kBAAkB,SAASN,SAAS,CAA4C;EACvEE,IAAI,GAAG,yCAAyC;EAElEC,WAAWA,CAACI,KAAkD,EAAE;IAC5D,KAAK,CAAC;MACFH,OAAO,EAAEG,KAAK,CAACH,OAAO;MACtBI,IAAI,EAAE;QACFD;MACJ;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/MailerService/errors.js","sources":["../../../src/domain/MailerService/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { TransportSendResponse } from \"~/types.js\";\n\nexport class NoTransportAvailableError extends BaseError {\n override readonly code = \"Mailer/MailerService/NoTransportAvailable\" as const;\n\n constructor() {\n super({\n message: \"There is no transport available.\"\n });\n }\n}\n\nexport class NoSettingsConfiguredError extends BaseError {\n override readonly code = \"Mailer/MailerService/NoSettingsConfigured\" as const;\n\n constructor() {\n super({\n message: \"No mailer settings are configured and no environment variables are set.\"\n });\n }\n}\n\nexport class TransportCreateError extends BaseError {\n override readonly code = \"Mailer/MailerService/TransportCreateError\" as const;\n\n constructor(error: unknown) {\n super({\n message: error instanceof Error ? error.message : String(error)\n });\n }\n}\n\nexport class TransportSendError extends BaseError<{ error: TransportSendResponse[\"error\"] }> {\n override readonly code = \"Mailer/MailerService/TransportSendError\" as const;\n\n constructor(error: NonNullable<TransportSendResponse[\"error\"]>) {\n super({\n message: error.message,\n data: {\n error\n }\n });\n }\n}\n"],"names":["NoTransportAvailableError","BaseError","NoSettingsConfiguredError","TransportCreateError","error","Error","String","TransportSendError"],"mappings":";AAGO,MAAMA,kCAAkCC;IAG3C,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMC,kCAAkCD;IAG3C,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAME,6BAA6BF;IAGtC,YAAYG,KAAc,CAAE;QACxB,KAAK,CAAC;YACF,SAASA,iBAAiBC,QAAQD,MAAM,OAAO,GAAGE,OAAOF;QAC7D,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMG,2BAA2BN;IAGpC,YAAYG,KAAkD,CAAE;QAC5D,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;YACtB,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ"}
@@ -0,0 +1,47 @@
1
+ import type { ZodType } from "zod";
2
+ export type TransportSettingsValues = Record<string, unknown>;
3
+ export interface ITransportSettingsDefinition {
4
+ /**
5
+ * The transport the settings belong to. Matches the `name` of its `MailTransportFactory`.
6
+ */
7
+ transport: string;
8
+ /**
9
+ * Key-value store key. Defaults to `Mailer/Settings/Transport/<transport>`.
10
+ */
11
+ storageKey?: string;
12
+ /**
13
+ * Validates the settings sent to save. Secret fields are optional in it: a save without one
14
+ * keeps the stored value.
15
+ */
16
+ schema: ZodType;
17
+ /**
18
+ * Fields that are encrypted at rest and never leave the server: they are left out of the
19
+ * settings the GraphQL API returns and out of the save events.
20
+ */
21
+ secrets?: string[];
22
+ /**
23
+ * Fields a stored secret is bound to. When a save changes one of them, the secrets must be sent
24
+ * again, so a settings editor can't point the transport at a server they control and receive the
25
+ * stored secret.
26
+ */
27
+ secretsBoundTo?: string[];
28
+ /**
29
+ * Fills in defaults, on read and before comparing `secretsBoundTo` fields on save.
30
+ */
31
+ withDefaults?(settings: TransportSettingsValues): TransportSettingsValues;
32
+ /**
33
+ * Settings set in code. When not null, they are used instead of the stored ones, and saving
34
+ * fails with `SettingsLockedByCode`.
35
+ */
36
+ getCodeSettings?(): TransportSettingsValues | null;
37
+ }
38
+ /**
39
+ * Registered by a transport whose settings are stored and edited in Settings > Mailer. The core
40
+ * mailer then provides reading, saving, the `mailer.settings` permission, encryption of secrets,
41
+ * the save events and the audit log for it.
42
+ */
43
+ export declare const TransportSettingsDefinition: import("@webiny/di").Abstraction<ITransportSettingsDefinition>;
44
+ export declare namespace TransportSettingsDefinition {
45
+ type Interface = ITransportSettingsDefinition;
46
+ type Values = TransportSettingsValues;
47
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const TransportSettingsDefinition = createAbstraction("Mailer/TransportSettingsDefinition");
3
+ export { TransportSettingsDefinition };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain/TransportSettings/abstractions.js","sources":["../../../src/domain/TransportSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ZodType } from \"zod\";\n\nexport type TransportSettingsValues = Record<string, unknown>;\n\nexport interface ITransportSettingsDefinition {\n /**\n * The transport the settings belong to. Matches the `name` of its `MailTransportFactory`.\n */\n transport: string;\n /**\n * Key-value store key. Defaults to `Mailer/Settings/Transport/<transport>`.\n */\n storageKey?: string;\n /**\n * Validates the settings sent to save. Secret fields are optional in it: a save without one\n * keeps the stored value.\n */\n schema: ZodType;\n /**\n * Fields that are encrypted at rest and never leave the server: they are left out of the\n * settings the GraphQL API returns and out of the save events.\n */\n secrets?: string[];\n /**\n * Fields a stored secret is bound to. When a save changes one of them, the secrets must be sent\n * again, so a settings editor can't point the transport at a server they control and receive the\n * stored secret.\n */\n secretsBoundTo?: string[];\n /**\n * Fills in defaults, on read and before comparing `secretsBoundTo` fields on save.\n */\n withDefaults?(settings: TransportSettingsValues): TransportSettingsValues;\n /**\n * Settings set in code. When not null, they are used instead of the stored ones, and saving\n * fails with `SettingsLockedByCode`.\n */\n getCodeSettings?(): TransportSettingsValues | null;\n}\n\n/**\n * Registered by a transport whose settings are stored and edited in Settings > Mailer. The core\n * mailer then provides reading, saving, the `mailer.settings` permission, encryption of secrets,\n * the save events and the audit log for it.\n */\nexport const TransportSettingsDefinition = createAbstraction<ITransportSettingsDefinition>(\n \"Mailer/TransportSettingsDefinition\"\n);\n\nexport namespace TransportSettingsDefinition {\n export type Interface = ITransportSettingsDefinition;\n export type Values = TransportSettingsValues;\n}\n"],"names":["TransportSettingsDefinition","createAbstraction"],"mappings":";AA8CO,MAAMA,8BAA8BC,kBACvC"}
@@ -0,0 +1,6 @@
1
+ import type { TransportSettingsDefinition } from "./abstractions.js";
2
+ export declare const DEFAULT_STORAGE_KEY_PREFIX = "Mailer/Settings/Transport/";
3
+ export declare const findDefinition: (definitions: TransportSettingsDefinition.Interface[], transport: string) => TransportSettingsDefinition.Interface | null;
4
+ export declare const getStorageKey: (definition: TransportSettingsDefinition.Interface) => string;
5
+ export declare const withDefaults: (definition: TransportSettingsDefinition.Interface, settings: TransportSettingsDefinition.Values) => TransportSettingsDefinition.Values;
6
+ export declare const withoutSecrets: (definition: TransportSettingsDefinition.Interface, settings: TransportSettingsDefinition.Values) => TransportSettingsDefinition.Values;
@@ -0,0 +1,13 @@
1
+ const DEFAULT_STORAGE_KEY_PREFIX = "Mailer/Settings/Transport/";
2
+ const findDefinition = (definitions, transport)=>[
3
+ ...definitions
4
+ ].reverse().find((d)=>d.transport === transport) ?? null;
5
+ const getStorageKey = (definition)=>definition.storageKey ?? `${DEFAULT_STORAGE_KEY_PREFIX}${definition.transport}`;
6
+ const withDefaults = (definition, settings)=>definition.withDefaults ? definition.withDefaults(settings) : settings;
7
+ const withoutSecrets = (definition, settings)=>{
8
+ const secrets = new Set(definition.secrets ?? []);
9
+ return Object.fromEntries(Object.entries(settings).filter(([key])=>!secrets.has(key)));
10
+ };
11
+ export { DEFAULT_STORAGE_KEY_PREFIX, findDefinition, getStorageKey, withDefaults, withoutSecrets };
12
+
13
+ //# sourceMappingURL=findDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain/TransportSettings/findDefinition.js","sources":["../../../src/domain/TransportSettings/findDefinition.ts"],"sourcesContent":["import type { TransportSettingsDefinition } from \"./abstractions.js\";\n\nexport const DEFAULT_STORAGE_KEY_PREFIX = \"Mailer/Settings/Transport/\";\n\n// The last registered definition for a transport wins, so a project can replace a package's.\nexport const findDefinition = (\n definitions: TransportSettingsDefinition.Interface[],\n transport: string\n): TransportSettingsDefinition.Interface | null => {\n return [...definitions].reverse().find(d => d.transport === transport) ?? null;\n};\n\nexport const getStorageKey = (definition: TransportSettingsDefinition.Interface): string => {\n return definition.storageKey ?? `${DEFAULT_STORAGE_KEY_PREFIX}${definition.transport}`;\n};\n\nexport const withDefaults = (\n definition: TransportSettingsDefinition.Interface,\n settings: TransportSettingsDefinition.Values\n): TransportSettingsDefinition.Values => {\n return definition.withDefaults ? definition.withDefaults(settings) : settings;\n};\n\nexport const withoutSecrets = (\n definition: TransportSettingsDefinition.Interface,\n settings: TransportSettingsDefinition.Values\n): TransportSettingsDefinition.Values => {\n const secrets = new Set(definition.secrets ?? []);\n return Object.fromEntries(Object.entries(settings).filter(([key]) => !secrets.has(key)));\n};\n"],"names":["DEFAULT_STORAGE_KEY_PREFIX","findDefinition","definitions","transport","d","getStorageKey","definition","withDefaults","settings","withoutSecrets","secrets","Set","Object","key"],"mappings":"AAEO,MAAMA,6BAA6B;AAGnC,MAAMC,iBAAiB,CAC1BC,aACAC,YAEO;WAAID;KAAY,CAAC,OAAO,GAAG,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS,KAAKD,cAAc;AAGvE,MAAME,gBAAgB,CAACC,aACnBA,WAAW,UAAU,IAAI,GAAGN,6BAA6BM,WAAW,SAAS,EAAE;AAGnF,MAAMC,eAAe,CACxBD,YACAE,WAEOF,WAAW,YAAY,GAAGA,WAAW,YAAY,CAACE,YAAYA;AAGlE,MAAMC,iBAAiB,CAC1BH,YACAE;IAEA,MAAME,UAAU,IAAIC,IAAIL,WAAW,OAAO,IAAI,EAAE;IAChD,OAAOM,OAAO,WAAW,CAACA,OAAO,OAAO,CAACJ,UAAU,MAAM,CAAC,CAAC,CAACK,IAAI,GAAK,CAACH,QAAQ,GAAG,CAACG;AACtF"}
@@ -1,20 +1,28 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
2
  import type { ZodError } from "zod";
3
3
  export declare class MailValidationError extends BaseError<{
4
- errors: ZodError["errors"];
4
+ errors: ZodError["issues"];
5
5
  }> {
6
6
  readonly code: "Mailer/SendMail/Validation";
7
- constructor(errors: ZodError["errors"]);
7
+ constructor(errors: ZodError["issues"]);
8
+ }
9
+ export declare class TestMailNotAuthorized extends BaseError {
10
+ readonly code: "Mailer/SendTestMail/NotAuthorized";
11
+ constructor();
12
+ }
13
+ export declare class TestMailNotConfigured extends BaseError {
14
+ readonly code: "Mailer/SendTestMail/NotConfigured";
15
+ constructor();
8
16
  }
9
17
  export declare class SettingsValidationError extends BaseError<{
10
- errors: ZodError["errors"];
18
+ errors: ZodError["issues"];
11
19
  }> {
12
20
  readonly code: "Mailer/Settings/Validation";
13
- constructor(errors: ZodError["errors"]);
21
+ constructor(errors: ZodError["issues"]);
14
22
  }
15
23
  export declare class SettingsNotAuthorized extends BaseError {
16
24
  readonly code: "Mailer/Settings/NotAuthorized";
17
- constructor();
25
+ constructor(message?: string);
18
26
  }
19
27
  export declare class SettingsPersistenceError extends BaseError<{
20
28
  error: Error;
@@ -22,3 +30,13 @@ export declare class SettingsPersistenceError extends BaseError<{
22
30
  readonly code: "Mailer/Settings/Persistence";
23
31
  constructor(error: Error);
24
32
  }
33
+ export declare class SettingsLockedByCode extends BaseError {
34
+ readonly code: "Mailer/Settings/LockedByCode";
35
+ constructor();
36
+ }
37
+ export declare class UnknownTransportSettings extends BaseError<{
38
+ transport: string;
39
+ }> {
40
+ readonly code: "Mailer/Settings/UnknownTransport";
41
+ constructor(transport: string);
42
+ }
package/domain/errors.js CHANGED
@@ -1,44 +1,72 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
- export class MailValidationError extends BaseError {
3
- code = "Mailer/SendMail/Validation";
4
- constructor(errors) {
5
- super({
6
- message: "Email params are invalid.",
7
- data: {
8
- errors
9
- }
10
- });
11
- }
12
- }
13
- export class SettingsValidationError extends BaseError {
14
- code = "Mailer/Settings/Validation";
15
- constructor(errors) {
16
- super({
17
- message: "Settings validation failed.",
18
- data: {
19
- errors
20
- }
21
- });
22
- }
23
- }
24
- export class SettingsNotAuthorized extends BaseError {
25
- code = "Mailer/Settings/NotAuthorized";
26
- constructor() {
27
- super({
28
- message: "Not allowed to update the mailer settings."
29
- });
30
- }
31
- }
32
- export class SettingsPersistenceError extends BaseError {
33
- code = "Mailer/Settings/Persistence";
34
- constructor(error) {
35
- super({
36
- message: "Failed to persist settings.",
37
- data: {
38
- error
39
- }
40
- });
41
- }
2
+ class MailValidationError extends BaseError {
3
+ constructor(errors){
4
+ super({
5
+ message: "Email params are invalid.",
6
+ data: {
7
+ errors
8
+ }
9
+ }), this.code = "Mailer/SendMail/Validation";
10
+ }
42
11
  }
12
+ class TestMailNotAuthorized extends BaseError {
13
+ constructor(){
14
+ super({
15
+ message: "Not allowed to send a test email."
16
+ }), this.code = "Mailer/SendTestMail/NotAuthorized";
17
+ }
18
+ }
19
+ class TestMailNotConfigured extends BaseError {
20
+ constructor(){
21
+ super({
22
+ message: "No mail transport is configured, so there is nothing to test."
23
+ }), this.code = "Mailer/SendTestMail/NotConfigured";
24
+ }
25
+ }
26
+ class SettingsValidationError extends BaseError {
27
+ constructor(errors){
28
+ super({
29
+ message: "Settings validation failed.",
30
+ data: {
31
+ errors
32
+ }
33
+ }), this.code = "Mailer/Settings/Validation";
34
+ }
35
+ }
36
+ class SettingsNotAuthorized extends BaseError {
37
+ constructor(message = "Not allowed to update the mailer settings."){
38
+ super({
39
+ message
40
+ }), this.code = "Mailer/Settings/NotAuthorized";
41
+ }
42
+ }
43
+ class SettingsPersistenceError extends BaseError {
44
+ constructor(error){
45
+ super({
46
+ message: "Failed to persist settings.",
47
+ data: {
48
+ error
49
+ }
50
+ }), this.code = "Mailer/Settings/Persistence";
51
+ }
52
+ }
53
+ class SettingsLockedByCode extends BaseError {
54
+ constructor(){
55
+ super({
56
+ message: "Mailer settings are managed by code and cannot be saved via the API."
57
+ }), this.code = "Mailer/Settings/LockedByCode";
58
+ }
59
+ }
60
+ class UnknownTransportSettings extends BaseError {
61
+ constructor(transport){
62
+ super({
63
+ message: `Mail transport "${transport}" has no settings.`,
64
+ data: {
65
+ transport
66
+ }
67
+ }), this.code = "Mailer/Settings/UnknownTransport";
68
+ }
69
+ }
70
+ export { MailValidationError, SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError, TestMailNotAuthorized, TestMailNotConfigured, UnknownTransportSettings };
43
71
 
44
72
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BaseError","MailValidationError","code","constructor","errors","message","data","SettingsValidationError","SettingsNotAuthorized","SettingsPersistenceError","error"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { ZodError } from \"zod\";\n\nexport class MailValidationError extends BaseError<{ errors: ZodError[\"errors\"] }> {\n override readonly code = \"Mailer/SendMail/Validation\" as const;\n\n constructor(errors: ZodError[\"errors\"]) {\n super({\n message: \"Email params are invalid.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class SettingsValidationError extends BaseError<{ errors: ZodError[\"errors\"] }> {\n override readonly code = \"Mailer/Settings/Validation\" as const;\n\n constructor(errors: ZodError[\"errors\"]) {\n super({\n message: \"Settings validation failed.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class SettingsNotAuthorized extends BaseError {\n override readonly code = \"Mailer/Settings/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not allowed to update the mailer settings.\" });\n }\n}\n\nexport class SettingsPersistenceError extends BaseError<{ error: Error }> {\n override readonly code = \"Mailer/Settings/Persistence\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to persist settings.\",\n data: {\n error\n }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;AAG/C,OAAO,MAAMC,mBAAmB,SAASD,SAAS,CAAiC;EAC7DE,IAAI,GAAG,4BAA4B;EAErDC,WAAWA,CAACC,MAA0B,EAAE;IACpC,KAAK,CAAC;MACFC,OAAO,EAAE,2BAA2B;MACpCC,IAAI,EAAE;QACFF;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMG,uBAAuB,SAASP,SAAS,CAAiC;EACjEE,IAAI,GAAG,4BAA4B;EAErDC,WAAWA,CAACC,MAA0B,EAAE;IACpC,KAAK,CAAC;MACFC,OAAO,EAAE,6BAA6B;MACtCC,IAAI,EAAE;QACFF;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMI,qBAAqB,SAASR,SAAS,CAAC;EAC/BE,IAAI,GAAG,+BAA+B;EAExDC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MAAEE,OAAO,EAAE;IAA6C,CAAC,CAAC;EACpE;AACJ;AAEA,OAAO,MAAMI,wBAAwB,SAAST,SAAS,CAAmB;EACpDE,IAAI,GAAG,6BAA6B;EAEtDC,WAAWA,CAACO,KAAY,EAAE;IACtB,KAAK,CAAC;MACFL,OAAO,EAAE,6BAA6B;MACtCC,IAAI,EAAE;QACFI;MACJ;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { ZodError } from \"zod\";\n\nexport class MailValidationError extends BaseError<{ errors: ZodError[\"issues\"] }> {\n override readonly code = \"Mailer/SendMail/Validation\" as const;\n\n constructor(errors: ZodError[\"issues\"]) {\n super({\n message: \"Email params are invalid.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class TestMailNotAuthorized extends BaseError {\n override readonly code = \"Mailer/SendTestMail/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not allowed to send a test email.\" });\n }\n}\n\nexport class TestMailNotConfigured extends BaseError {\n override readonly code = \"Mailer/SendTestMail/NotConfigured\" as const;\n\n constructor() {\n super({\n message: \"No mail transport is configured, so there is nothing to test.\"\n });\n }\n}\n\nexport class SettingsValidationError extends BaseError<{ errors: ZodError[\"issues\"] }> {\n override readonly code = \"Mailer/Settings/Validation\" as const;\n\n constructor(errors: ZodError[\"issues\"]) {\n super({\n message: \"Settings validation failed.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class SettingsNotAuthorized extends BaseError {\n override readonly code = \"Mailer/Settings/NotAuthorized\" as const;\n\n constructor(message = \"Not allowed to update the mailer settings.\") {\n super({ message });\n }\n}\n\nexport class SettingsPersistenceError extends BaseError<{ error: Error }> {\n override readonly code = \"Mailer/Settings/Persistence\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to persist settings.\",\n data: {\n error\n }\n });\n }\n}\n\nexport class SettingsLockedByCode extends BaseError {\n override readonly code = \"Mailer/Settings/LockedByCode\" as const;\n\n constructor() {\n super({\n message: \"Mailer settings are managed by code and cannot be saved via the API.\"\n });\n }\n}\n\nexport class UnknownTransportSettings extends BaseError<{ transport: string }> {\n override readonly code = \"Mailer/Settings/UnknownTransport\" as const;\n\n constructor(transport: string) {\n super({\n message: `Mail transport \"${transport}\" has no settings.`,\n data: { transport }\n });\n }\n}\n"],"names":["MailValidationError","BaseError","errors","TestMailNotAuthorized","TestMailNotConfigured","SettingsValidationError","SettingsNotAuthorized","message","SettingsPersistenceError","error","SettingsLockedByCode","UnknownTransportSettings","transport"],"mappings":";AAGO,MAAMA,4BAA4BC;IAGrC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,8BAA8BF;IAGvC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAoC,SAHvC,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMG,8BAA8BH;IAGvC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMI,gCAAgCJ;IAGzC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMI,8BAA8BL;IAGvC,YAAYM,UAAU,4CAA4C,CAAE;QAChE,KAAK,CAAC;YAAEA;QAAQ,SAHF,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,iCAAiCP;IAG1C,YAAYQ,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,6BAA6BT;IAGtC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMU,iCAAiCV;IAG1C,YAAYW,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,gBAAgB,EAAEA,UAAU,kBAAkB,CAAC;YACzD,MAAM;gBAAEA;YAAU;QACtB,SANc,IAAI,GAAG;IAOzB;AACJ"}
@@ -0,0 +1,6 @@
1
+ export { SendMailUseCase, MailSendErrorEventHandler, MailBeforeSendEventHandler, MailAfterSendEventHandler } from "../../features/SendMail/index.js";
2
+ export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
3
+ export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
4
+ export { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
5
+ export { GetSettingsUseCase, GetSettingsRepository } from "../../features/GetSettings/index.js";
6
+ export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "../../features/SaveSettings/index.js";
@@ -0,0 +1,6 @@
1
+ export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "../../features/SendMail/index.js";
2
+ export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
3
+ export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
4
+ export { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
5
+ export { GetSettingsRepository, GetSettingsUseCase } from "../../features/GetSettings/index.js";
6
+ export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "../../features/SaveSettings/index.js";
@@ -1,13 +1,15 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { Encryption } from "../../domain/Encryption/abstractions.js";
3
- import { GetSettingsRepository } from "./abstractions.js";
4
- import type { TransportSettings } from "../../types.js";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
5
3
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ import { GetSettingsRepository, type ISettingsWithSource } from "./abstractions.js";
5
+ import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
6
+ import { UnknownTransportSettings } from "../../domain/errors.js";
6
7
  declare class GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {
7
8
  private keyValueStore;
8
9
  private encryption;
9
- constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface);
10
- get(): Promise<Result<TransportSettings | null>>;
10
+ private definitions;
11
+ constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface, definitions: TransportSettingsDefinition.Interface[]);
12
+ get<TSettings extends object>(transport: string): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>>;
11
13
  }
12
14
  export declare const GetSettingsRepositoryImplementation: typeof GetSettingsRepositoryImpl & {
13
15
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsRepository>;
@@ -1,39 +1,52 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { Encryption } from "../../domain/Encryption/abstractions.js";
3
- import { GetSettingsRepository } from "./abstractions.js";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
4
3
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
5
- import { MAILER_TRANSPORT_SETTINGS } from "../../constants.js";
4
+ import { GetSettingsRepository } from "./abstractions.js";
5
+ import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
6
+ import { findDefinition, getStorageKey, withDefaults } from "../../domain/TransportSettings/findDefinition.js";
7
+ import { UnknownTransportSettings } from "../../domain/errors.js";
6
8
  class GetSettingsRepositoryImpl {
7
- constructor(keyValueStore, encryption) {
8
- this.keyValueStore = keyValueStore;
9
- this.encryption = encryption;
10
- }
11
- async get() {
12
- const result = await this.keyValueStore.get(MAILER_TRANSPORT_SETTINGS);
13
- if (result.isFail()) {
14
- return Result.ok(null);
9
+ constructor(keyValueStore, encryption, definitions){
10
+ this.keyValueStore = keyValueStore;
11
+ this.encryption = encryption;
12
+ this.definitions = definitions;
15
13
  }
16
- const settings = result.value;
17
- if (!settings) {
18
- return Result.ok(null);
14
+ async get(transport) {
15
+ const definition = findDefinition(this.definitions, transport);
16
+ if (!definition) return Result.fail(new UnknownTransportSettings(transport));
17
+ const codeSettings = definition.getCodeSettings?.() ?? null;
18
+ if (null !== codeSettings) return Result.ok({
19
+ settings: withDefaults(definition, codeSettings),
20
+ source: "code"
21
+ });
22
+ const result = await this.keyValueStore.get(getStorageKey(definition));
23
+ if (result.isFail() || !result.value) return Result.ok({
24
+ settings: null,
25
+ source: null
26
+ });
27
+ const settings = {
28
+ ...result.value
29
+ };
30
+ for (const secret of definition.secrets ?? [])settings[secret] = settings[secret] ? await this.encryption.decrypt(String(settings[secret])) : "";
31
+ return Result.ok({
32
+ settings: withDefaults(definition, settings),
33
+ source: "storage"
34
+ });
19
35
  }
20
-
21
- // Decrypt password if present
22
- const password = settings.password ? await this.encryption.decrypt(String(settings.password)) : "";
23
- const transportSettings = {
24
- host: String(settings.host || ""),
25
- port: Number(settings.port || 25),
26
- user: String(settings.user || ""),
27
- password,
28
- from: String(settings.from || ""),
29
- replyTo: settings.replyTo ? String(settings.replyTo) : undefined
30
- };
31
- return Result.ok(transportSettings);
32
- }
33
36
  }
34
- export const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({
35
- implementation: GetSettingsRepositoryImpl,
36
- dependencies: [KeyValueStore, Encryption]
37
+ const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({
38
+ implementation: GetSettingsRepositoryImpl,
39
+ dependencies: [
40
+ KeyValueStore,
41
+ Encryption,
42
+ [
43
+ TransportSettingsDefinition,
44
+ {
45
+ multiple: true
46
+ }
47
+ ]
48
+ ]
37
49
  });
50
+ export { GetSettingsRepositoryImplementation };
38
51
 
39
52
  //# sourceMappingURL=GetSettingsRepository.js.map