@webiny/api-mailer 0.0.0-unstable.40876133bb → 0.0.0-unstable.4373247389

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 (174) hide show
  1. package/MailerFeature.d.ts +4 -0
  2. package/MailerFeature.js +23 -0
  3. package/MailerFeature.js.map +1 -0
  4. package/README.md +10 -13
  5. package/constants.d.ts +1 -0
  6. package/constants.js +4 -0
  7. package/constants.js.map +1 -0
  8. package/domain/MailTransport/abstractions.d.ts +23 -0
  9. package/domain/MailTransport/abstractions.js +6 -0
  10. package/domain/MailTransport/abstractions.js.map +1 -0
  11. package/domain/MailerService/abstractions.d.ts +21 -0
  12. package/domain/MailerService/abstractions.js +5 -0
  13. package/domain/MailerService/abstractions.js.map +1 -0
  14. package/domain/MailerService/errors.d.ts +20 -0
  15. package/domain/MailerService/errors.js +35 -0
  16. package/domain/MailerService/errors.js.map +1 -0
  17. package/domain/TransportSettings/abstractions.d.ts +47 -0
  18. package/domain/TransportSettings/abstractions.js +5 -0
  19. package/domain/TransportSettings/abstractions.js.map +1 -0
  20. package/domain/TransportSettings/findDefinition.d.ts +6 -0
  21. package/domain/TransportSettings/findDefinition.js +13 -0
  22. package/domain/TransportSettings/findDefinition.js.map +1 -0
  23. package/domain/errors.d.ts +42 -0
  24. package/domain/errors.js +72 -0
  25. package/domain/errors.js.map +1 -0
  26. package/exports/api/mailer.d.ts +6 -0
  27. package/exports/api/mailer.js +6 -0
  28. package/features/GetSettings/GetSettingsRepository.d.ts +17 -0
  29. package/features/GetSettings/GetSettingsRepository.js +52 -0
  30. package/features/GetSettings/GetSettingsRepository.js.map +1 -0
  31. package/features/GetSettings/GetSettingsUseCase.d.ts +19 -0
  32. package/features/GetSettings/GetSettingsUseCase.js +43 -0
  33. package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
  34. package/features/GetSettings/abstractions.d.ts +30 -0
  35. package/features/GetSettings/abstractions.js +6 -0
  36. package/features/GetSettings/abstractions.js.map +1 -0
  37. package/features/GetSettings/feature.d.ts +4 -0
  38. package/features/GetSettings/feature.js +13 -0
  39. package/features/GetSettings/feature.js.map +1 -0
  40. package/features/GetSettings/index.d.ts +2 -0
  41. package/features/GetSettings/index.js +1 -0
  42. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.d.ts +11 -0
  43. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js +19 -0
  44. package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js.map +1 -0
  45. package/features/IsMailerConfigured/abstractions.d.ts +18 -0
  46. package/features/IsMailerConfigured/abstractions.js +5 -0
  47. package/features/IsMailerConfigured/abstractions.js.map +1 -0
  48. package/features/IsMailerConfigured/feature.d.ts +4 -0
  49. package/features/IsMailerConfigured/feature.js +11 -0
  50. package/features/IsMailerConfigured/feature.js.map +1 -0
  51. package/features/IsMailerConfigured/index.d.ts +1 -0
  52. package/features/IsMailerConfigured/index.js +1 -0
  53. package/features/MailerService/MailerService.d.ts +14 -0
  54. package/features/MailerService/MailerService.js +53 -0
  55. package/features/MailerService/MailerService.js.map +1 -0
  56. package/features/MailerService/feature.d.ts +4 -0
  57. package/features/MailerService/feature.js +11 -0
  58. package/features/MailerService/feature.js.map +1 -0
  59. package/features/SaveSettings/SaveSettingsRepository.d.ts +14 -0
  60. package/features/SaveSettings/SaveSettingsRepository.js +67 -0
  61. package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
  62. package/features/SaveSettings/SaveSettingsUseCase.d.ts +16 -0
  63. package/features/SaveSettings/SaveSettingsUseCase.js +58 -0
  64. package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
  65. package/features/SaveSettings/abstractions.d.ts +54 -0
  66. package/features/SaveSettings/abstractions.js +8 -0
  67. package/features/SaveSettings/abstractions.js.map +1 -0
  68. package/features/SaveSettings/events.d.ts +10 -0
  69. package/features/SaveSettings/events.js +21 -0
  70. package/features/SaveSettings/events.js.map +1 -0
  71. package/features/SaveSettings/feature.d.ts +4 -0
  72. package/features/SaveSettings/feature.js +13 -0
  73. package/features/SaveSettings/feature.js.map +1 -0
  74. package/features/SaveSettings/index.d.ts +2 -0
  75. package/features/SaveSettings/index.js +1 -0
  76. package/features/SendMail/SendMailUseCase.d.ts +16 -0
  77. package/features/SendMail/SendMailUseCase.js +58 -0
  78. package/features/SendMail/SendMailUseCase.js.map +1 -0
  79. package/features/SendMail/abstractions.d.ts +45 -0
  80. package/features/SendMail/abstractions.js +8 -0
  81. package/features/SendMail/abstractions.js.map +1 -0
  82. package/features/SendMail/events.d.ts +14 -0
  83. package/features/SendMail/events.js +29 -0
  84. package/features/SendMail/events.js.map +1 -0
  85. package/features/SendMail/feature.d.ts +4 -0
  86. package/features/SendMail/feature.js +11 -0
  87. package/features/SendMail/feature.js.map +1 -0
  88. package/features/SendMail/index.d.ts +1 -0
  89. package/features/SendMail/index.js +1 -0
  90. package/features/SendTestMail/SendTestMailUseCase.d.ts +13 -0
  91. package/features/SendTestMail/SendTestMailUseCase.js +40 -0
  92. package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
  93. package/features/SendTestMail/abstractions.d.ts +32 -0
  94. package/features/SendTestMail/abstractions.js +5 -0
  95. package/features/SendTestMail/abstractions.js.map +1 -0
  96. package/features/SendTestMail/feature.d.ts +4 -0
  97. package/features/SendTestMail/feature.js +11 -0
  98. package/features/SendTestMail/feature.js.map +1 -0
  99. package/graphql/MailerSchemaFactory.d.ts +10 -0
  100. package/graphql/MailerSchemaFactory.js +135 -0
  101. package/graphql/MailerSchemaFactory.js.map +1 -0
  102. package/index.d.ts +13 -8
  103. package/index.js +9 -89
  104. package/package.json +27 -45
  105. package/types.d.ts +2 -117
  106. package/types.js +0 -5
  107. package/utils/isMailboxAddress.d.ts +6 -0
  108. package/utils/isMailboxAddress.js +5 -0
  109. package/utils/isMailboxAddress.js.map +1 -0
  110. package/context.d.ts +0 -3
  111. package/context.js +0 -24
  112. package/context.js.map +0 -1
  113. package/crud/group.d.ts +0 -2
  114. package/crud/group.js +0 -21
  115. package/crud/group.js.map +0 -1
  116. package/crud/mailer/onBeforeSend.d.ts +0 -7
  117. package/crud/mailer/onBeforeSend.js +0 -69
  118. package/crud/mailer/onBeforeSend.js.map +0 -1
  119. package/crud/mailer.crud.d.ts +0 -2
  120. package/crud/mailer.crud.js +0 -123
  121. package/crud/mailer.crud.js.map +0 -1
  122. package/crud/settings/hooks.d.ts +0 -5
  123. package/crud/settings/hooks.js +0 -55
  124. package/crud/settings/hooks.js.map +0 -1
  125. package/crud/settings/model.d.ts +0 -3
  126. package/crud/settings/model.js +0 -90
  127. package/crud/settings/model.js.map +0 -1
  128. package/crud/settings/password.d.ts +0 -7
  129. package/crud/settings/password.js +0 -71
  130. package/crud/settings/password.js.map +0 -1
  131. package/crud/settings/secret.d.ts +0 -1
  132. package/crud/settings/secret.js +0 -23
  133. package/crud/settings/secret.js.map +0 -1
  134. package/crud/settings/transform.d.ts +0 -13
  135. package/crud/settings/transform.js +0 -56
  136. package/crud/settings/transform.js.map +0 -1
  137. package/crud/settings/validation.d.ts +0 -4
  138. package/crud/settings/validation.js +0 -38
  139. package/crud/settings/validation.js.map +0 -1
  140. package/crud/settings.crud.d.ts +0 -5
  141. package/crud/settings.crud.js +0 -331
  142. package/crud/settings.crud.js.map +0 -1
  143. package/crud/transport/onTransportBeforeSend.d.ts +0 -7
  144. package/crud/transport/onTransportBeforeSend.js +0 -69
  145. package/crud/transport/onTransportBeforeSend.js.map +0 -1
  146. package/crud/transporter.crud.d.ts +0 -2
  147. package/crud/transporter.crud.js +0 -193
  148. package/crud/transporter.crud.js.map +0 -1
  149. package/graphql/index.d.ts +0 -1
  150. package/graphql/index.js +0 -14
  151. package/graphql/index.js.map +0 -1
  152. package/graphql/settings.d.ts +0 -3
  153. package/graphql/settings.js +0 -109
  154. package/graphql/settings.js.map +0 -1
  155. package/index.js.map +0 -1
  156. package/mailers/createDummyMailer.d.ts +0 -5
  157. package/mailers/createDummyMailer.js +0 -24
  158. package/mailers/createDummyMailer.js.map +0 -1
  159. package/mailers/createSmtpMailer.d.ts +0 -13
  160. package/mailers/createSmtpMailer.js +0 -106
  161. package/mailers/createSmtpMailer.js.map +0 -1
  162. package/plugins/CreateTransportPlugin.d.ts +0 -17
  163. package/plugins/CreateTransportPlugin.js +0 -34
  164. package/plugins/CreateTransportPlugin.js.map +0 -1
  165. package/plugins/index.d.ts +0 -1
  166. package/plugins/index.js +0 -18
  167. package/plugins/index.js.map +0 -1
  168. package/transports/createDummyTransport.d.ts +0 -5
  169. package/transports/createDummyTransport.js +0 -25
  170. package/transports/createDummyTransport.js.map +0 -1
  171. package/transports/createSmtpTransport.d.ts +0 -12
  172. package/transports/createSmtpTransport.js +0 -101
  173. package/transports/createSmtpTransport.js.map +0 -1
  174. 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/README.md CHANGED
@@ -1,14 +1,11 @@
1
1
  # @webiny/api-mailer
2
- [![](https://img.shields.io/npm/dw/@webiny/api-mailer.svg)](https://www.npmjs.com/package/@webiny/api-mailer)
3
- [![](https://img.shields.io/npm/v/@webiny/api-mailer.svg)](https://www.npmjs.com/package/@webiny/api-mailer)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
-
7
-
8
- ## Install
9
- ```
10
- yarn add @webiny/api-mailer
11
- ```
12
-
13
- ## Documentation
14
- [Webiny Documentation > Overview > Features > Mailer](https://www.webiny.com/docs/overview/features/mailer)
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const MAILER_SETTINGS_PERMISSION = "mailer.settings";
package/constants.js ADDED
@@ -0,0 +1,4 @@
1
+ const MAILER_SETTINGS_PERMISSION = "mailer.settings";
2
+ export { MAILER_SETTINGS_PERMISSION };
3
+
4
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,23 @@
1
+ import type { TransportSendData, TransportSendResponse } from "../../types.js";
2
+ export interface IMailTransport {
3
+ name: string;
4
+ send(params: TransportSendData): Promise<TransportSendResponse>;
5
+ }
6
+ export declare const MailTransport: import("@webiny/di").Abstraction<IMailTransport>;
7
+ export declare namespace MailTransport {
8
+ type Interface = IMailTransport;
9
+ type SendParams = TransportSendData;
10
+ }
11
+ export interface IMailTransportFactory {
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>;
18
+ }
19
+ export declare const MailTransportFactory: import("@webiny/di").Abstraction<IMailTransportFactory>;
20
+ export declare namespace MailTransportFactory {
21
+ type Interface = IMailTransportFactory;
22
+ type Return = Promise<IMailTransport | null>;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const MailTransport = createAbstraction("MailTransport");
3
+ const MailTransportFactory = createAbstraction("MailTransportFactory");
4
+ export { MailTransport, MailTransportFactory };
5
+
6
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,21 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { TransportSendData, TransportSendResponse } from "../../types.js";
3
+ import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "./errors.js";
4
+ export interface IMailerServiceErrors {
5
+ noTransport: NoTransportAvailableError;
6
+ transportCreate: TransportCreateError;
7
+ transportSend: TransportSendError;
8
+ }
9
+ type MailerServiceError = IMailerServiceErrors[keyof IMailerServiceErrors];
10
+ export interface IMailerService {
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>;
14
+ }
15
+ export declare const MailerService: import("@webiny/di").Abstraction<IMailerService>;
16
+ export declare namespace MailerService {
17
+ type Interface = IMailerService;
18
+ type Return<T = any> = Promise<Result<TransportSendResponse<T>, MailerServiceError>>;
19
+ type Error = MailerServiceError;
20
+ }
21
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const MailerService = createAbstraction("MailerService");
3
+ export { MailerService };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,20 @@
1
+ import { BaseError } from "@webiny/feature/api";
2
+ import type { TransportSendResponse } from "../../types.js";
3
+ export declare class NoTransportAvailableError extends BaseError {
4
+ readonly code: "Mailer/MailerService/NoTransportAvailable";
5
+ constructor();
6
+ }
7
+ export declare class NoSettingsConfiguredError extends BaseError {
8
+ readonly code: "Mailer/MailerService/NoSettingsConfigured";
9
+ constructor();
10
+ }
11
+ export declare class TransportCreateError extends BaseError {
12
+ readonly code: "Mailer/MailerService/TransportCreateError";
13
+ constructor(error: unknown);
14
+ }
15
+ export declare class TransportSendError extends BaseError<{
16
+ error: TransportSendResponse["error"];
17
+ }> {
18
+ readonly code: "Mailer/MailerService/TransportSendError";
19
+ constructor(error: NonNullable<TransportSendResponse["error"]>);
20
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseError } from "@webiny/feature/api";
2
+ class NoTransportAvailableError extends BaseError {
3
+ constructor(){
4
+ super({
5
+ message: "There is no transport available."
6
+ }), this.code = "Mailer/MailerService/NoTransportAvailable";
7
+ }
8
+ }
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
+ }
15
+ }
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
+ }
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 };
34
+
35
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,42 @@
1
+ import { BaseError } from "@webiny/feature/api";
2
+ import type { ZodError } from "zod";
3
+ export declare class MailValidationError extends BaseError<{
4
+ errors: ZodError["issues"];
5
+ }> {
6
+ readonly code: "Mailer/SendMail/Validation";
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();
16
+ }
17
+ export declare class SettingsValidationError extends BaseError<{
18
+ errors: ZodError["issues"];
19
+ }> {
20
+ readonly code: "Mailer/Settings/Validation";
21
+ constructor(errors: ZodError["issues"]);
22
+ }
23
+ export declare class SettingsNotAuthorized extends BaseError {
24
+ readonly code: "Mailer/Settings/NotAuthorized";
25
+ constructor(message?: string);
26
+ }
27
+ export declare class SettingsPersistenceError extends BaseError<{
28
+ error: Error;
29
+ }> {
30
+ readonly code: "Mailer/Settings/Persistence";
31
+ constructor(error: Error);
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
+ }
@@ -0,0 +1,72 @@
1
+ import { BaseError } from "@webiny/feature/api";
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
+ }
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 };
71
+
72
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
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";
@@ -0,0 +1,17 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
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";
7
+ declare class GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {
8
+ private keyValueStore;
9
+ private encryption;
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>>;
13
+ }
14
+ export declare const GetSettingsRepositoryImplementation: typeof GetSettingsRepositoryImpl & {
15
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsRepository>;
16
+ };
17
+ export {};
@@ -0,0 +1,52 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
3
+ import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.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";
8
+ class GetSettingsRepositoryImpl {
9
+ constructor(keyValueStore, encryption, definitions){
10
+ this.keyValueStore = keyValueStore;
11
+ this.encryption = encryption;
12
+ this.definitions = definitions;
13
+ }
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
+ });
35
+ }
36
+ }
37
+ const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({
38
+ implementation: GetSettingsRepositoryImpl,
39
+ dependencies: [
40
+ KeyValueStore,
41
+ Encryption,
42
+ [
43
+ TransportSettingsDefinition,
44
+ {
45
+ multiple: true
46
+ }
47
+ ]
48
+ ]
49
+ });
50
+ export { GetSettingsRepositoryImplementation };
51
+
52
+ //# sourceMappingURL=GetSettingsRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetSettings/GetSettingsRepository.js","sources":["../../../src/features/GetSettings/GetSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { Encryption } from \"@webiny/api-core/features/encryption/index.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { GetSettingsRepository, type ISettingsWithSource } from \"./abstractions.js\";\nimport { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport {\n findDefinition,\n getStorageKey,\n withDefaults\n} from \"~/domain/TransportSettings/findDefinition.js\";\nimport { UnknownTransportSettings } from \"~/domain/errors.js\";\n\nclass GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface,\n private definitions: TransportSettingsDefinition.Interface[]\n ) {}\n\n async get<TSettings extends object>(\n transport: string\n ): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>> {\n const definition = findDefinition(this.definitions, transport);\n if (!definition) {\n return Result.fail(new UnknownTransportSettings(transport));\n }\n\n // Settings set in code win over stored ones.\n const codeSettings = definition.getCodeSettings?.() ?? null;\n if (codeSettings !== null) {\n return Result.ok({\n settings: withDefaults(definition, codeSettings) as TSettings,\n source: \"code\"\n });\n }\n\n const result = await this.keyValueStore.get<TransportSettingsDefinition.Values>(\n getStorageKey(definition)\n );\n if (result.isFail() || !result.value) {\n return Result.ok({ settings: null, source: null });\n }\n\n const settings = { ...result.value };\n for (const secret of definition.secrets ?? []) {\n settings[secret] = settings[secret]\n ? await this.encryption.decrypt(String(settings[secret]))\n : \"\";\n }\n\n return Result.ok({\n settings: withDefaults(definition, settings) as TSettings,\n source: \"storage\"\n });\n }\n}\n\nexport const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({\n implementation: GetSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption, [TransportSettingsDefinition, { multiple: true }]]\n});\n"],"names":["GetSettingsRepositoryImpl","keyValueStore","encryption","definitions","transport","definition","findDefinition","Result","UnknownTransportSettings","codeSettings","withDefaults","result","getStorageKey","settings","secret","String","GetSettingsRepositoryImplementation","GetSettingsRepository","KeyValueStore","Encryption","TransportSettingsDefinition"],"mappings":";;;;;;;AAYA,MAAMA;IACF,YACYC,aAAsC,EACtCC,UAAgC,EAChCC,WAAoD,CAC9D;aAHUF,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IACFC,SAAiB,EACwD;QACzE,MAAMC,aAAaC,eAAe,IAAI,CAAC,WAAW,EAAEF;QACpD,IAAI,CAACC,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC,yBAAyBJ;QAIpD,MAAMK,eAAeJ,WAAW,eAAe,QAAQ;QACvD,IAAII,AAAiB,SAAjBA,cACA,OAAOF,OAAO,EAAE,CAAC;YACb,UAAUG,aAAaL,YAAYI;YACnC,QAAQ;QACZ;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvCC,cAAcP;QAElB,IAAIM,OAAO,MAAM,MAAM,CAACA,OAAO,KAAK,EAChC,OAAOJ,OAAO,EAAE,CAAC;YAAE,UAAU;YAAM,QAAQ;QAAK;QAGpD,MAAMM,WAAW;YAAE,GAAGF,OAAO,KAAK;QAAC;QACnC,KAAK,MAAMG,UAAUT,WAAW,OAAO,IAAI,EAAE,CACzCQ,QAAQ,CAACC,OAAO,GAAGD,QAAQ,CAACC,OAAO,GAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACC,OAAOF,QAAQ,CAACC,OAAO,KACrD;QAGV,OAAOP,OAAO,EAAE,CAAC;YACb,UAAUG,aAAaL,YAAYQ;YACnC,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAMG,sCAAsCC,sBAAsB,oBAAoB,CAAC;IAC1F,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;QAAY;YAACC;YAA6B;gBAAE,UAAU;YAAK;SAAE;KAAC;AAChG"}
@@ -0,0 +1,19 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
+ import { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
4
+ import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
5
+ import { SettingsNotAuthorized, UnknownTransportSettings } from "../../domain/errors.js";
6
+ declare class GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {
7
+ private identityContext;
8
+ private repository;
9
+ private definitions;
10
+ constructor(identityContext: IdentityContext.Interface, repository: GetSettingsRepository.Interface, definitions: TransportSettingsDefinition.Interface[]);
11
+ execute(transport: string): Promise<Result<never, SettingsNotAuthorized> | Result<never, UnknownTransportSettings> | Result<{
12
+ settings: import("~/domain/TransportSettings/abstractions.js").TransportSettingsValues | null;
13
+ source: import("./abstractions.js").MailerSettingsSource;
14
+ }, never>>;
15
+ }
16
+ export declare const GetSettingsUseCaseImplementation: typeof GetSettingsUseCaseImpl & {
17
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsUseCase>;
18
+ };
19
+ export {};
@@ -0,0 +1,43 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
+ import { GetSettingsRepository, GetSettingsUseCase } from "./abstractions.js";
4
+ import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
5
+ import { findDefinition, withoutSecrets } from "../../domain/TransportSettings/findDefinition.js";
6
+ import { SettingsNotAuthorized, UnknownTransportSettings } from "../../domain/errors.js";
7
+ import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
8
+ class GetSettingsUseCaseImpl {
9
+ constructor(identityContext, repository, definitions){
10
+ this.identityContext = identityContext;
11
+ this.repository = repository;
12
+ this.definitions = definitions;
13
+ }
14
+ async execute(transport) {
15
+ const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
16
+ if (!permission) return Result.fail(new SettingsNotAuthorized("Not allowed to read the mailer settings."));
17
+ const definition = findDefinition(this.definitions, transport);
18
+ if (!definition) return Result.fail(new UnknownTransportSettings(transport));
19
+ const result = await this.repository.get(transport);
20
+ if (result.isFail()) return Result.fail(result.error);
21
+ const { settings, source } = result.value;
22
+ return Result.ok({
23
+ settings: settings ? withoutSecrets(definition, settings) : null,
24
+ source
25
+ });
26
+ }
27
+ }
28
+ const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({
29
+ implementation: GetSettingsUseCaseImpl,
30
+ dependencies: [
31
+ IdentityContext,
32
+ GetSettingsRepository,
33
+ [
34
+ TransportSettingsDefinition,
35
+ {
36
+ multiple: true
37
+ }
38
+ ]
39
+ ]
40
+ });
41
+ export { GetSettingsUseCaseImplementation };
42
+
43
+ //# sourceMappingURL=GetSettingsUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetSettings/GetSettingsUseCase.js","sources":["../../../src/features/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { GetSettingsUseCase, GetSettingsRepository } from \"./abstractions.js\";\nimport { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport { findDefinition, withoutSecrets } from \"~/domain/TransportSettings/findDefinition.js\";\nimport { SettingsNotAuthorized, UnknownTransportSettings } from \"~/domain/errors.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nclass GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private repository: GetSettingsRepository.Interface,\n private definitions: TransportSettingsDefinition.Interface[]\n ) {}\n\n async execute(transport: string) {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(\n new SettingsNotAuthorized(\"Not allowed to read the mailer settings.\")\n );\n }\n\n const definition = findDefinition(this.definitions, transport);\n if (!definition) {\n return Result.fail(new UnknownTransportSettings(transport));\n }\n\n const result = await this.repository.get(transport);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const { settings, source } = result.value;\n return Result.ok({\n settings: settings ? withoutSecrets(definition, settings) : null,\n source\n });\n }\n}\n\nexport const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({\n implementation: GetSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n GetSettingsRepository,\n [TransportSettingsDefinition, { multiple: true }]\n ]\n});\n"],"names":["GetSettingsUseCaseImpl","identityContext","repository","definitions","transport","permission","MAILER_SETTINGS_PERMISSION","Result","SettingsNotAuthorized","definition","findDefinition","UnknownTransportSettings","result","settings","source","withoutSecrets","GetSettingsUseCaseImplementation","GetSettingsUseCase","IdentityContext","GetSettingsRepository","TransportSettingsDefinition"],"mappings":";;;;;;;AAQA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,UAA2C,EAC3CC,WAAoD,CAC9D;aAHUF,eAAe,GAAfA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,SAAiB,EAAE;QAC7B,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CACd,IAAIC,sBAAsB;QAIlC,MAAMC,aAAaC,eAAe,IAAI,CAAC,WAAW,EAAEN;QACpD,IAAI,CAACK,YACD,OAAOF,OAAO,IAAI,CAAC,IAAII,yBAAyBP;QAGpD,MAAMQ,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACR;QACzC,IAAIQ,OAAO,MAAM,IACb,OAAOL,OAAO,IAAI,CAACK,OAAO,KAAK;QAGnC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGF,OAAO,KAAK;QACzC,OAAOL,OAAO,EAAE,CAAC;YACb,UAAUM,WAAWE,eAAeN,YAAYI,YAAY;YAC5DC;QACJ;IACJ;AACJ;AAEO,MAAME,mCAAmCC,mBAAmB,oBAAoB,CAAC;IACpF,gBAAgBjB;IAChB,cAAc;QACVkB;QACAC;QACA;YAACC;YAA6B;gBAAE,UAAU;YAAK;SAAE;KACpD;AACL"}