@webiny/api-mailer 6.6.0-alpha.11 → 6.6.0-alpha.12
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.
- package/MailerFeature.js +4 -2
- package/MailerFeature.js.map +1 -1
- package/constants.d.ts +2 -0
- package/constants.js +3 -1
- package/constants.js.map +1 -1
- package/domain/MailTransport/abstractions.d.ts +7 -4
- package/domain/MailTransport/abstractions.js.map +1 -1
- package/domain/MailerService/abstractions.d.ts +2 -0
- package/domain/MailerService/abstractions.js.map +1 -1
- package/domain/errors.d.ts +8 -0
- package/domain/errors.js +15 -1
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.d.ts +2 -1
- package/exports/api/mailer.js +2 -1
- package/features/CodeMailerSettings/CodeMailerSettings.js +1 -1
- package/features/CodeMailerSettings/CodeMailerSettings.js.map +1 -1
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.d.ts +11 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js +19 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js.map +1 -0
- package/features/IsMailerConfigured/abstractions.d.ts +18 -0
- package/features/IsMailerConfigured/abstractions.js +5 -0
- package/features/IsMailerConfigured/abstractions.js.map +1 -0
- package/features/IsMailerConfigured/feature.d.ts +4 -0
- package/features/IsMailerConfigured/feature.js +11 -0
- package/features/IsMailerConfigured/feature.js.map +1 -0
- package/features/IsMailerConfigured/index.d.ts +1 -0
- package/features/IsMailerConfigured/index.js +1 -0
- package/features/MailerService/MailerService.d.ts +3 -4
- package/features/MailerService/MailerService.js +13 -19
- package/features/MailerService/MailerService.js.map +1 -1
- package/features/SaveSettings/SaveSettingsUseCase.js +2 -1
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
- package/features/SendTestMail/SendTestMailUseCase.d.ts +13 -0
- package/features/SendTestMail/SendTestMailUseCase.js +40 -0
- package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
- package/features/SendTestMail/abstractions.d.ts +32 -0
- package/features/SendTestMail/abstractions.js +5 -0
- package/features/SendTestMail/abstractions.js.map +1 -0
- package/features/{DummyTransport → SendTestMail}/feature.d.ts +1 -1
- package/features/SendTestMail/feature.js +11 -0
- package/features/SendTestMail/feature.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +3 -2
- package/features/SmtpTransport/SmtpMailTransport.js +11 -4
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +4 -3
- package/features/SmtpTransport/SmtpMailTransportFactory.js +13 -8
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -1
- package/graphql/MailerSchemaFactory.js +28 -1
- package/graphql/MailerSchemaFactory.js.map +1 -1
- package/package.json +10 -10
- package/features/DummyTransport/DummyMailTransport.d.ts +0 -9
- package/features/DummyTransport/DummyMailTransport.js +0 -14
- package/features/DummyTransport/DummyMailTransport.js.map +0 -1
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +0 -10
- package/features/DummyTransport/DummyMailTransportFactory.js +0 -20
- package/features/DummyTransport/DummyMailTransportFactory.js.map +0 -1
- package/features/DummyTransport/feature.js +0 -11
- package/features/DummyTransport/feature.js.map +0 -1
package/MailerFeature.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CodeMailerSettingsFeature } from "./features/CodeMailerSettings/feature.js";
|
|
3
|
-
import { DummyTransportFeature } from "./features/DummyTransport/feature.js";
|
|
4
3
|
import { SmtpTransportFeature } from "./features/SmtpTransport/feature.js";
|
|
5
4
|
import { GetSettingsFeature } from "./features/GetSettings/feature.js";
|
|
6
5
|
import { SaveSettingsFeature } from "./features/SaveSettings/feature.js";
|
|
7
6
|
import { MailerServiceFeature } from "./features/MailerService/feature.js";
|
|
8
7
|
import { SendMailFeature } from "./features/SendMail/feature.js";
|
|
8
|
+
import { SendTestMailFeature } from "./features/SendTestMail/feature.js";
|
|
9
|
+
import { IsMailerConfiguredFeature } from "./features/IsMailerConfigured/feature.js";
|
|
9
10
|
import { MailerSchemaFactory } from "./graphql/MailerSchemaFactory.js";
|
|
10
11
|
const MailerFeature = createFeature({
|
|
11
12
|
name: "Mailer",
|
|
12
13
|
register (container) {
|
|
13
14
|
CodeMailerSettingsFeature.register(container);
|
|
14
|
-
DummyTransportFeature.register(container);
|
|
15
15
|
SmtpTransportFeature.register(container);
|
|
16
16
|
GetSettingsFeature.register(container);
|
|
17
17
|
SaveSettingsFeature.register(container);
|
|
18
18
|
MailerServiceFeature.register(container);
|
|
19
19
|
SendMailFeature.register(container);
|
|
20
|
+
SendTestMailFeature.register(container);
|
|
21
|
+
IsMailerConfiguredFeature.register(container);
|
|
20
22
|
container.register(MailerSchemaFactory);
|
|
21
23
|
}
|
|
22
24
|
});
|
package/MailerFeature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailerFeature.js","sources":["../src/MailerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CodeMailerSettingsFeature } from \"~/features/CodeMailerSettings/feature.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"MailerFeature.js","sources":["../src/MailerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CodeMailerSettingsFeature } from \"~/features/CodeMailerSettings/feature.js\";\nimport { SmtpTransportFeature } from \"~/features/SmtpTransport/feature.js\";\nimport { GetSettingsFeature } from \"~/features/GetSettings/feature.js\";\nimport { SaveSettingsFeature } from \"~/features/SaveSettings/feature.js\";\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 { MailerSchemaFactory } from \"~/graphql/MailerSchemaFactory.js\";\n\nexport const MailerFeature = createFeature({\n name: \"Mailer\",\n register(container) {\n CodeMailerSettingsFeature.register(container);\n SmtpTransportFeature.register(container);\n GetSettingsFeature.register(container);\n SaveSettingsFeature.register(container);\n MailerServiceFeature.register(container);\n SendMailFeature.register(container);\n SendTestMailFeature.register(container);\n IsMailerConfiguredFeature.register(container);\n container.register(MailerSchemaFactory);\n }\n});\n"],"names":["MailerFeature","createFeature","container","CodeMailerSettingsFeature","SmtpTransportFeature","GetSettingsFeature","SaveSettingsFeature","MailerServiceFeature","SendMailFeature","SendTestMailFeature","IsMailerConfiguredFeature","MailerSchemaFactory"],"mappings":";;;;;;;;;;AAWO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdC,0BAA0B,QAAQ,CAACD;QACnCE,qBAAqB,QAAQ,CAACF;QAC9BG,mBAAmB,QAAQ,CAACH;QAC5BI,oBAAoB,QAAQ,CAACJ;QAC7BK,qBAAqB,QAAQ,CAACL;QAC9BM,gBAAgB,QAAQ,CAACN;QACzBO,oBAAoB,QAAQ,CAACP;QAC7BQ,0BAA0B,QAAQ,CAACR;QACnCA,UAAU,QAAQ,CAACS;IACvB;AACJ"}
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const MAILER_TRANSPORT_SETTINGS = "Mailer/Settings/Transport";
|
|
2
|
-
|
|
2
|
+
const MAILER_SETTINGS_PERMISSION = "mailer.settings";
|
|
3
|
+
const SMTP_TRANSPORT_NAME = "Mailer/SmtpTransport";
|
|
4
|
+
export { MAILER_SETTINGS_PERMISSION, MAILER_TRANSPORT_SETTINGS, SMTP_TRANSPORT_NAME };
|
|
3
5
|
|
|
4
6
|
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const MAILER_TRANSPORT_SETTINGS = \"Mailer/Settings/Transport\";\n"],"names":["MAILER_TRANSPORT_SETTINGS"],"mappings":"AAAO,MAAMA,4BAA4B"}
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const MAILER_TRANSPORT_SETTINGS = \"Mailer/Settings/Transport\";\nexport const MAILER_SETTINGS_PERMISSION = \"mailer.settings\";\nexport const SMTP_TRANSPORT_NAME = \"Mailer/SmtpTransport\";\n"],"names":["MAILER_TRANSPORT_SETTINGS","MAILER_SETTINGS_PERMISSION","SMTP_TRANSPORT_NAME"],"mappings":"AAAO,MAAMA,4BAA4B;AAClC,MAAMC,6BAA6B;AACnC,MAAMC,sBAAsB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransportSendData, TransportSendResponse
|
|
1
|
+
import type { TransportSendData, TransportSendResponse } from "../../types.js";
|
|
2
2
|
export interface IMailTransport {
|
|
3
3
|
name: string;
|
|
4
4
|
send(params: TransportSendData): Promise<TransportSendResponse>;
|
|
@@ -10,11 +10,14 @@ export declare namespace MailTransport {
|
|
|
10
10
|
}
|
|
11
11
|
export interface IMailTransportFactory {
|
|
12
12
|
name: string;
|
|
13
|
-
|
|
14
|
-
|
|
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>;
|
|
15
18
|
}
|
|
16
19
|
export declare const MailTransportFactory: import("@webiny/di").Abstraction<IMailTransportFactory>;
|
|
17
20
|
export declare namespace MailTransportFactory {
|
|
18
21
|
type Interface = IMailTransportFactory;
|
|
19
|
-
type Return = Promise<IMailTransport>;
|
|
22
|
+
type Return = Promise<IMailTransport | null>;
|
|
20
23
|
}
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -9,6 +9,8 @@ export interface IMailerServiceErrors {
|
|
|
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 +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\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":";
|
|
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"}
|
package/domain/errors.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export declare class SettingsPersistenceError extends BaseError<{
|
|
|
22
22
|
readonly code: "Mailer/Settings/Persistence";
|
|
23
23
|
constructor(error: Error);
|
|
24
24
|
}
|
|
25
|
+
export declare class TestMailNotAuthorized extends BaseError {
|
|
26
|
+
readonly code: "Mailer/SendTestMail/NotAuthorized";
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
export declare class TestMailNotConfigured extends BaseError {
|
|
30
|
+
readonly code: "Mailer/SendTestMail/NotConfigured";
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
25
33
|
export declare class SettingsLockedByCode extends BaseError {
|
|
26
34
|
readonly code: "Mailer/Settings/LockedByCode";
|
|
27
35
|
constructor();
|
package/domain/errors.js
CHANGED
|
@@ -36,6 +36,20 @@ class SettingsPersistenceError extends BaseError {
|
|
|
36
36
|
}), this.code = "Mailer/Settings/Persistence";
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
class TestMailNotAuthorized extends BaseError {
|
|
40
|
+
constructor(){
|
|
41
|
+
super({
|
|
42
|
+
message: "Not allowed to send a test email."
|
|
43
|
+
}), this.code = "Mailer/SendTestMail/NotAuthorized";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class TestMailNotConfigured extends BaseError {
|
|
47
|
+
constructor(){
|
|
48
|
+
super({
|
|
49
|
+
message: "No mail transport is configured, so there is nothing to test."
|
|
50
|
+
}), this.code = "Mailer/SendTestMail/NotConfigured";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
39
53
|
class SettingsLockedByCode extends BaseError {
|
|
40
54
|
constructor(){
|
|
41
55
|
super({
|
|
@@ -43,6 +57,6 @@ class SettingsLockedByCode extends BaseError {
|
|
|
43
57
|
}), this.code = "Mailer/Settings/LockedByCode";
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
|
-
export { MailValidationError, SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError };
|
|
60
|
+
export { MailValidationError, SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError, TestMailNotAuthorized, TestMailNotConfigured };
|
|
47
61
|
|
|
48
62
|
//# sourceMappingURL=errors.js.map
|
package/domain/errors.js.map
CHANGED
|
@@ -1 +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 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() {\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\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"],"names":["MailValidationError","BaseError","errors","SettingsValidationError","SettingsNotAuthorized","SettingsPersistenceError","error","SettingsLockedByCode"],"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,gCAAgCF;IAGzC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAME,8BAA8BH;IAGvC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAA6C,SAHhD,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMI,iCAAiCJ;IAG1C,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,
|
|
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 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() {\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\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 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"],"names":["MailValidationError","BaseError","errors","SettingsValidationError","SettingsNotAuthorized","SettingsPersistenceError","error","TestMailNotAuthorized","TestMailNotConfigured","SettingsLockedByCode"],"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,gCAAgCF;IAGzC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAME,8BAA8BH;IAGvC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAA6C,SAHhD,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMI,iCAAiCJ;IAG1C,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,8BAA8BN;IAGvC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAoC,SAHvC,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMO,8BAA8BP;IAGvC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMQ,6BAA6BR;IAGtC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ"}
|
package/exports/api/mailer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { SendMailUseCase, MailSendErrorEventHandler, MailBeforeSendEventHandler, MailAfterSendEventHandler } from "../../features/SendMail/index.js";
|
|
2
2
|
export { GetSettingsUseCase, GetSettingsRepository } from "../../features/GetSettings/index.js";
|
|
3
3
|
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "../../features/SaveSettings/index.js";
|
|
4
|
-
export {
|
|
4
|
+
export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
|
|
5
|
+
export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
package/exports/api/mailer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "../../features/SendMail/index.js";
|
|
2
2
|
export { GetSettingsRepository, GetSettingsUseCase } from "../../features/GetSettings/index.js";
|
|
3
3
|
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "../../features/SaveSettings/index.js";
|
|
4
|
-
export {
|
|
4
|
+
export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
|
|
5
|
+
export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
2
2
|
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
3
|
-
|
|
3
|
+
import { SMTP_TRANSPORT_NAME } from "../../constants.js";
|
|
4
4
|
const SMTP_BUILD_PARAM_KEY = "Mailer.SmtpSettings";
|
|
5
5
|
class CodeMailerSettingsImpl {
|
|
6
6
|
constructor(buildParams){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CodeMailerSettings/CodeMailerSettings.js","sources":["../../../src/features/CodeMailerSettings/CodeMailerSettings.ts"],"sourcesContent":["import { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { CodeMailerSettings as Abstraction } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\
|
|
1
|
+
{"version":3,"file":"features/CodeMailerSettings/CodeMailerSettings.js","sources":["../../../src/features/CodeMailerSettings/CodeMailerSettings.ts"],"sourcesContent":["import { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { CodeMailerSettings as Abstraction } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SMTP_TRANSPORT_NAME } from \"~/constants.js\";\n\nconst SMTP_BUILD_PARAM_KEY = \"Mailer.SmtpSettings\";\n\nclass CodeMailerSettingsImpl implements Abstraction.Interface {\n constructor(private buildParams: BuildParams.Interface) {}\n\n get(transportName: string): TransportSettings | null {\n if (transportName !== SMTP_TRANSPORT_NAME) {\n return null;\n }\n const value = this.buildParams.get<TransportSettings>(SMTP_BUILD_PARAM_KEY);\n return value ?? null;\n }\n}\n\nexport const CodeMailerSettings = Abstraction.createImplementation({\n implementation: CodeMailerSettingsImpl,\n dependencies: [BuildParams]\n});\n"],"names":["SMTP_BUILD_PARAM_KEY","CodeMailerSettingsImpl","buildParams","transportName","SMTP_TRANSPORT_NAME","value","CodeMailerSettings","Abstraction","BuildParams"],"mappings":";;;AAKA,MAAMA,uBAAuB;AAE7B,MAAMC;IACF,YAAoBC,WAAkC,CAAE;aAApCA,WAAW,GAAXA;IAAqC;IAEzD,IAAIC,aAAqB,EAA4B;QACjD,IAAIA,kBAAkBC,qBAClB,OAAO;QAEX,MAAMC,QAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAoBL;QACtD,OAAOK,SAAS;IACpB;AACJ;AAEO,MAAMC,wCAAqBC,mBAAAA,oBAAgC,CAAC;IAC/D,gBAAgBN;IAChB,cAAc;QAACO;KAAY;AAC/B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
declare class IsMailerConfiguredUseCaseImpl implements IsMailerConfiguredUseCase.Interface {
|
|
4
|
+
private mailerService;
|
|
5
|
+
constructor(mailerService: MailerService.Interface);
|
|
6
|
+
execute(): IsMailerConfiguredUseCase.Return;
|
|
7
|
+
}
|
|
8
|
+
export declare const IsMailerConfiguredUseCaseImplementation: typeof IsMailerConfiguredUseCaseImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IIsMailerConfiguredUseCase>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
class IsMailerConfiguredUseCaseImpl {
|
|
4
|
+
constructor(mailerService){
|
|
5
|
+
this.mailerService = mailerService;
|
|
6
|
+
}
|
|
7
|
+
execute() {
|
|
8
|
+
return this.mailerService.isConfigured();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const IsMailerConfiguredUseCaseImplementation = IsMailerConfiguredUseCase.createImplementation({
|
|
12
|
+
implementation: IsMailerConfiguredUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
MailerService
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { IsMailerConfiguredUseCaseImplementation };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=IsMailerConfiguredUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/IsMailerConfiguredUseCase.js","sources":["../../../src/features/IsMailerConfigured/IsMailerConfiguredUseCase.ts"],"sourcesContent":["import { IsMailerConfiguredUseCase } from \"./abstractions.js\";\nimport { MailerService } from \"~/domain/MailerService/abstractions.js\";\n\nclass IsMailerConfiguredUseCaseImpl implements IsMailerConfiguredUseCase.Interface {\n constructor(private mailerService: MailerService.Interface) {}\n\n execute(): IsMailerConfiguredUseCase.Return {\n return this.mailerService.isConfigured();\n }\n}\n\nexport const IsMailerConfiguredUseCaseImplementation =\n IsMailerConfiguredUseCase.createImplementation({\n implementation: IsMailerConfiguredUseCaseImpl,\n dependencies: [MailerService]\n });\n"],"names":["IsMailerConfiguredUseCaseImpl","mailerService","IsMailerConfiguredUseCaseImplementation","IsMailerConfiguredUseCase","MailerService"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,UAA4C;QACxC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY;IAC1C;AACJ;AAEO,MAAMC,0CACTC,0BAA0B,oBAAoB,CAAC;IAC3C,gBAAgBH;IAChB,cAAc;QAACI;KAAc;AACjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IIsMailerConfiguredUseCase {
|
|
2
|
+
execute(): Promise<boolean>;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Whether a mail transport is set up. It does not connect or send, so a transport with wrong
|
|
6
|
+
* credentials still counts.
|
|
7
|
+
*
|
|
8
|
+
* Only for a question that has to be answered before anything is sent, like the password reset
|
|
9
|
+
* request, which must answer every address the same way. Otherwise send through `SendMailUseCase`
|
|
10
|
+
* and handle `NoTransportAvailableError`.
|
|
11
|
+
*
|
|
12
|
+
* No permission check: the password reset request is anonymous.
|
|
13
|
+
*/
|
|
14
|
+
export declare const IsMailerConfiguredUseCase: import("@webiny/di").Abstraction<IIsMailerConfiguredUseCase>;
|
|
15
|
+
export declare namespace IsMailerConfiguredUseCase {
|
|
16
|
+
type Interface = IIsMailerConfiguredUseCase;
|
|
17
|
+
type Return = Promise<boolean>;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/abstractions.js","sources":["../../../src/features/IsMailerConfigured/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IIsMailerConfiguredUseCase {\n execute(): Promise<boolean>;\n}\n\n/**\n * Whether a mail transport is set up. It does not connect or send, so a transport with wrong\n * credentials still counts.\n *\n * Only for a question that has to be answered before anything is sent, like the password reset\n * request, which must answer every address the same way. Otherwise send through `SendMailUseCase`\n * and handle `NoTransportAvailableError`.\n *\n * No permission check: the password reset request is anonymous.\n */\nexport const IsMailerConfiguredUseCase = createAbstraction<IIsMailerConfiguredUseCase>(\n \"IsMailerConfiguredUseCase\"\n);\n\nexport namespace IsMailerConfiguredUseCase {\n export type Interface = IIsMailerConfiguredUseCase;\n export type Return = Promise<boolean>;\n}\n"],"names":["IsMailerConfiguredUseCase","createAbstraction"],"mappings":";AAgBO,MAAMA,4BAA4BC,kBACrC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { IsMailerConfiguredUseCaseImplementation } from "./IsMailerConfiguredUseCase.js";
|
|
3
|
+
const IsMailerConfiguredFeature = createFeature({
|
|
4
|
+
name: "IsMailerConfigured",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(IsMailerConfiguredUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { IsMailerConfiguredFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/feature.js","sources":["../../../src/features/IsMailerConfigured/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { IsMailerConfiguredUseCaseImplementation } from \"./IsMailerConfiguredUseCase.js\";\n\nexport const IsMailerConfiguredFeature = createFeature({\n name: \"IsMailerConfigured\",\n register(container) {\n container.register(IsMailerConfiguredUseCaseImplementation);\n }\n});\n"],"names":["IsMailerConfiguredFeature","createFeature","container","IsMailerConfiguredUseCaseImplementation"],"mappings":";;AAGO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
2
2
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
3
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
4
3
|
import type { TransportSendData } from "../../types.js";
|
|
5
4
|
declare class MailerServiceImpl implements Abstraction.Interface {
|
|
6
|
-
private getSettingsRepository;
|
|
7
5
|
private transportFactories;
|
|
8
|
-
constructor(
|
|
6
|
+
constructor(transportFactories: MailTransportFactory.Interface[]);
|
|
9
7
|
sendMail<T = any>(data: TransportSendData): Abstraction.Return<T>;
|
|
10
|
-
|
|
8
|
+
isConfigured(): Promise<boolean>;
|
|
9
|
+
private createTransport;
|
|
11
10
|
}
|
|
12
11
|
export declare const MailerService: typeof MailerServiceImpl & {
|
|
13
12
|
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailerService/abstractions.js").IMailerService>;
|
|
@@ -2,15 +2,13 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
3
|
import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "../../domain/MailerService/errors.js";
|
|
4
4
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
5
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
6
5
|
class MailerServiceImpl {
|
|
7
|
-
constructor(
|
|
8
|
-
this.getSettingsRepository = getSettingsRepository;
|
|
6
|
+
constructor(transportFactories){
|
|
9
7
|
this.transportFactories = transportFactories;
|
|
10
8
|
}
|
|
11
9
|
async sendMail(data) {
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
10
|
+
const transport = await this.createTransport();
|
|
11
|
+
if (!transport) return Result.fail(new NoTransportAvailableError());
|
|
14
12
|
try {
|
|
15
13
|
const response = await transport.send(data);
|
|
16
14
|
if (response.error) return Result.fail(new TransportSendError(response.error));
|
|
@@ -19,33 +17,29 @@ class MailerServiceImpl {
|
|
|
19
17
|
return Result.fail(new TransportSendError(error));
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
async
|
|
20
|
+
async isConfigured() {
|
|
21
|
+
const transport = await this.createTransport();
|
|
22
|
+
return null !== transport;
|
|
23
|
+
}
|
|
24
|
+
async createTransport() {
|
|
23
25
|
const factories = [
|
|
24
26
|
...this.transportFactories
|
|
25
27
|
].reverse();
|
|
26
28
|
for (const factory of factories){
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const transport = await factory.createTransport(settings);
|
|
31
|
-
return {
|
|
32
|
-
factory,
|
|
33
|
-
transport
|
|
34
|
-
};
|
|
29
|
+
let transport;
|
|
30
|
+
try {
|
|
31
|
+
transport = await factory.createTransport();
|
|
35
32
|
} catch (error) {
|
|
36
33
|
throw new TransportCreateError(error);
|
|
37
34
|
}
|
|
35
|
+
if (transport) return transport;
|
|
38
36
|
}
|
|
39
|
-
return
|
|
40
|
-
factory: null,
|
|
41
|
-
transport: null
|
|
42
|
-
};
|
|
37
|
+
return null;
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
40
|
const MailerService_MailerService = MailerService.createImplementation({
|
|
46
41
|
implementation: MailerServiceImpl,
|
|
47
42
|
dependencies: [
|
|
48
|
-
GetSettingsRepository,
|
|
49
43
|
[
|
|
50
44
|
MailTransportFactory,
|
|
51
45
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/MailerService/MailerService.js","sources":["../../../src/features/MailerService/MailerService.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { MailerService as Abstraction } from \"~/domain/MailerService/abstractions.js\";\nimport {\n NoTransportAvailableError,\n TransportCreateError,\n TransportSendError\n} from \"~/domain/MailerService/errors.js\";\nimport { MailTransport
|
|
1
|
+
{"version":3,"file":"features/MailerService/MailerService.js","sources":["../../../src/features/MailerService/MailerService.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { MailerService as Abstraction } from \"~/domain/MailerService/abstractions.js\";\nimport {\n NoTransportAvailableError,\n TransportCreateError,\n TransportSendError\n} from \"~/domain/MailerService/errors.js\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\nimport { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(private transportFactories: MailTransportFactory.Interface[]) {}\n\n async sendMail<T = any>(data: TransportSendData): Abstraction.Return<T> {\n const transport = await this.createTransport();\n\n if (!transport) {\n return Result.fail(new NoTransportAvailableError());\n }\n\n try {\n const response = await transport.send(data);\n\n if (response.error) {\n return Result.fail(new TransportSendError(response.error));\n }\n\n return Result.ok(response);\n } catch (error) {\n return Result.fail(new TransportSendError(error));\n }\n }\n\n async isConfigured(): Promise<boolean> {\n const transport = await this.createTransport();\n\n return transport !== null;\n }\n\n // The last registered factory that is configured wins, so a project's own transport takes over.\n // Null when no factory is configured.\n private async createTransport(): Promise<MailTransport.Interface | null> {\n const factories = [...this.transportFactories].reverse();\n\n for (const factory of factories) {\n let transport: MailTransport.Interface | null;\n try {\n transport = await factory.createTransport();\n } catch (error) {\n throw new TransportCreateError(error);\n }\n\n if (transport) {\n return transport;\n }\n }\n\n return null;\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [[MailTransportFactory, { multiple: true }]]\n});\n"],"names":["MailerServiceImpl","transportFactories","data","transport","Result","NoTransportAvailableError","response","TransportSendError","error","factories","factory","TransportCreateError","MailerService","Abstraction","MailTransportFactory"],"mappings":";;;;AAWA,MAAMA;IACF,YAAoBC,kBAAoD,CAAE;aAAtDA,kBAAkB,GAAlBA;IAAuD;IAE3E,MAAM,SAAkBC,IAAuB,EAAyB;QACpE,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe;QAE5C,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YACA,MAAMC,WAAW,MAAMH,UAAU,IAAI,CAACD;YAEtC,IAAII,SAAS,KAAK,EACd,OAAOF,OAAO,IAAI,CAAC,IAAIG,mBAAmBD,SAAS,KAAK;YAG5D,OAAOF,OAAO,EAAE,CAACE;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIG,mBAAmBC;QAC9C;IACJ;IAEA,MAAM,eAAiC;QACnC,MAAML,YAAY,MAAM,IAAI,CAAC,eAAe;QAE5C,OAAOA,AAAc,SAAdA;IACX;IAIA,MAAc,kBAA2D;QACrE,MAAMM,YAAY;eAAI,IAAI,CAAC,kBAAkB;SAAC,CAAC,OAAO;QAEtD,KAAK,MAAMC,WAAWD,UAAW;YAC7B,IAAIN;YACJ,IAAI;gBACAA,YAAY,MAAMO,QAAQ,eAAe;YAC7C,EAAE,OAAOF,OAAO;gBACZ,MAAM,IAAIG,qBAAqBH;YACnC;YAEA,IAAIL,WACA,OAAOA;QAEf;QAEA,OAAO;IACX;AACJ;AAEO,MAAMS,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBb;IAChB,cAAc;QAAC;YAACc;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC9D"}
|
|
@@ -7,6 +7,7 @@ import { SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError,
|
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
8
|
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
9
9
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
10
|
+
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
10
11
|
class SaveSettingsUseCaseImpl {
|
|
11
12
|
constructor(identityContext, eventPublisher, repository, codeSettings, transportFactories){
|
|
12
13
|
this.identityContext = identityContext;
|
|
@@ -16,7 +17,7 @@ class SaveSettingsUseCaseImpl {
|
|
|
16
17
|
this.transportFactories = transportFactories;
|
|
17
18
|
}
|
|
18
19
|
async execute(input) {
|
|
19
|
-
const permission = await this.identityContext.getPermission(
|
|
20
|
+
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
20
21
|
if (!permission) return Result.fail(new SettingsNotAuthorized());
|
|
21
22
|
const validationResult = saveValidation.safeParse(input);
|
|
22
23
|
if (!validationResult.success) return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SaveSettings/SaveSettingsUseCase.js","sources":["../../../src/features/SaveSettings/SaveSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n type SaveSettingsInput\n} from \"./abstractions.js\";\nimport { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from \"./events.js\";\nimport { saveValidation } from \"./validation.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CodeMailerSettings } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\n\nclass SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: SaveSettingsRepository.Interface,\n private codeSettings: CodeMailerSettings.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/SaveSettingsUseCase.js","sources":["../../../src/features/SaveSettings/SaveSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n type SaveSettingsInput\n} from \"./abstractions.js\";\nimport { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from \"./events.js\";\nimport { saveValidation } from \"./validation.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CodeMailerSettings } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nclass SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: SaveSettingsRepository.Interface,\n private codeSettings: CodeMailerSettings.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n\n if (!permission) {\n return Result.fail(new SettingsNotAuthorized());\n }\n\n const validationResult = saveValidation.safeParse(input);\n if (!validationResult.success) {\n return Result.fail(new SettingsValidationError(validationResult.error.issues));\n }\n\n /* Refuse when any registered transport has code-defined settings. */\n const isLockedByCode = this.transportFactories.some(\n f => this.codeSettings.get(f.name) !== null\n );\n\n if (isLockedByCode) {\n return Result.fail(new SettingsLockedByCode());\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _beforePassword, ...inputForEvent } = input;\n const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({ input: inputForEvent });\n await this.eventPublisher.publish(beforeSaveEvent);\n\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n const afterSaveEvent = new MailerSettingsAfterSaveEvent({ settings: result.value });\n await this.eventPublisher.publish(afterSaveEvent);\n\n return result;\n }\n}\n\nexport const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({\n implementation: SaveSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n EventPublisher,\n SaveSettingsRepository,\n CodeMailerSettings,\n [MailTransportFactory, { multiple: true }]\n ]\n});\n"],"names":["SaveSettingsUseCaseImpl","identityContext","eventPublisher","repository","codeSettings","transportFactories","input","permission","MAILER_SETTINGS_PERMISSION","Result","SettingsNotAuthorized","validationResult","saveValidation","SettingsValidationError","isLockedByCode","f","SettingsLockedByCode","_beforePassword","inputForEvent","beforeSaveEvent","MailerSettingsBeforeSaveEvent","result","SettingsPersistenceError","afterSaveEvent","MailerSettingsAfterSaveEvent","SaveSettingsUseCaseImplementation","SaveSettingsUseCase","IdentityContext","EventPublisher","SaveSettingsRepository","CodeMailerSettings","MailTransportFactory"],"mappings":";;;;;;;;;;AAoBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA4C,EAC5CC,YAA0C,EAC1CC,kBAAoD,CAC9D;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,YAAY,GAAZA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAwB,EAA8B;QAChE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAE5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,mBAAmBC,eAAe,SAAS,CAACN;QAClD,IAAI,CAACK,iBAAiB,OAAO,EACzB,OAAOF,OAAO,IAAI,CAAC,IAAII,wBAAwBF,iBAAiB,KAAK,CAAC,MAAM;QAIhF,MAAMG,iBAAiB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAC/CC,CAAAA,IAAK,AAAkC,SAAlC,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,EAAE,IAAI;QAGrC,IAAID,gBACA,OAAOL,OAAO,IAAI,CAAC,IAAIO;QAI3B,MAAM,EAAE,UAAUC,eAAe,EAAE,GAAGC,eAAe,GAAGZ;QACxD,MAAMa,kBAAkB,IAAIC,8BAA8B;YAAE,OAAOF;QAAc;QACjF,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACC;QAElC,MAAME,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACf;QAE7C,IAAIe,OAAO,MAAM,IACb,OAAOZ,OAAO,IAAI,CAAC,IAAIa,yBAAyBD,OAAO,KAAK;QAGhE,MAAME,iBAAiB,IAAIC,6BAA6B;YAAE,UAAUH,OAAO,KAAK;QAAC;QACjF,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACE;QAElC,OAAOF;IACX;AACJ;AAEO,MAAMI,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACA;YAACC;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAC7C;AACL"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { SendTestMailUseCase } from "./abstractions.js";
|
|
3
|
+
import { SendMailUseCase } from "../../features/SendMail/abstractions.js";
|
|
4
|
+
declare class SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {
|
|
5
|
+
private identityContext;
|
|
6
|
+
private sendMailUseCase;
|
|
7
|
+
constructor(identityContext: IdentityContext.Interface, sendMailUseCase: SendMailUseCase.Interface);
|
|
8
|
+
execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return;
|
|
9
|
+
}
|
|
10
|
+
export declare const SendTestMailUseCaseImplementation: typeof SendTestMailUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendTestMailUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { SendTestMailUseCase } from "./abstractions.js";
|
|
4
|
+
import { SendMailUseCase } from "../SendMail/abstractions.js";
|
|
5
|
+
import { TestMailNotAuthorized, TestMailNotConfigured } from "../../domain/errors.js";
|
|
6
|
+
import { NoTransportAvailableError } from "../../domain/MailerService/errors.js";
|
|
7
|
+
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
8
|
+
const TEST_MAIL_TEXT = "This is a test email from Webiny.\n\nIt was sent from the Mailer settings screen to check that mail is delivered. No action is needed.";
|
|
9
|
+
class SendTestMailUseCaseImpl {
|
|
10
|
+
constructor(identityContext, sendMailUseCase){
|
|
11
|
+
this.identityContext = identityContext;
|
|
12
|
+
this.sendMailUseCase = sendMailUseCase;
|
|
13
|
+
}
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
16
|
+
if (!permission) return Result.fail(new TestMailNotAuthorized());
|
|
17
|
+
const result = await this.sendMailUseCase.execute({
|
|
18
|
+
to: [
|
|
19
|
+
input.to
|
|
20
|
+
],
|
|
21
|
+
subject: "Webiny test email",
|
|
22
|
+
text: TEST_MAIL_TEXT
|
|
23
|
+
});
|
|
24
|
+
if (result.isFail()) {
|
|
25
|
+
if (result.error instanceof NoTransportAvailableError) return Result.fail(new TestMailNotConfigured());
|
|
26
|
+
return Result.fail(result.error);
|
|
27
|
+
}
|
|
28
|
+
return Result.ok(void 0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({
|
|
32
|
+
implementation: SendTestMailUseCaseImpl,
|
|
33
|
+
dependencies: [
|
|
34
|
+
IdentityContext,
|
|
35
|
+
SendMailUseCase
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { SendTestMailUseCaseImplementation };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=SendTestMailUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/SendTestMailUseCase.js","sources":["../../../src/features/SendTestMail/SendTestMailUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { SendTestMailUseCase } from \"./abstractions.js\";\nimport { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\nimport { NoTransportAvailableError } from \"~/domain/MailerService/errors.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nconst TEST_MAIL_TEXT = [\n \"This is a test email from Webiny.\",\n \"\",\n \"It was sent from the Mailer settings screen to check that mail is delivered. \" +\n \"No action is needed.\"\n].join(\"\\n\");\n\nclass SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private sendMailUseCase: SendMailUseCase.Interface\n ) {}\n\n async execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(new TestMailNotAuthorized());\n }\n\n const result = await this.sendMailUseCase.execute({\n to: [input.to],\n subject: \"Webiny test email\",\n text: TEST_MAIL_TEXT\n });\n\n if (result.isFail()) {\n if (result.error instanceof NoTransportAvailableError) {\n return Result.fail(new TestMailNotConfigured());\n }\n return Result.fail(result.error);\n }\n\n return Result.ok(undefined);\n }\n}\n\nexport const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({\n implementation: SendTestMailUseCaseImpl,\n dependencies: [IdentityContext, SendMailUseCase]\n});\n"],"names":["TEST_MAIL_TEXT","SendTestMailUseCaseImpl","identityContext","sendMailUseCase","input","permission","MAILER_SETTINGS_PERMISSION","Result","TestMailNotAuthorized","result","NoTransportAvailableError","TestMailNotConfigured","undefined","SendTestMailUseCaseImplementation","SendTestMailUseCase","IdentityContext","SendMailUseCase"],"mappings":";;;;;;;AASA,MAAMA,iBAAiB;AAOvB,MAAMC;IACF,YACYC,eAA0C,EAC1CC,eAA0C,CACpD;aAFUD,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAAgC,EAA8B;QACxE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAC9C,IAAI;gBAACL,MAAM,EAAE;aAAC;YACd,SAAS;YACT,MAAMJ;QACV;QAEA,IAAIS,OAAO,MAAM,IAAI;YACjB,IAAIA,OAAO,KAAK,YAAYC,2BACxB,OAAOH,OAAO,IAAI,CAAC,IAAII;YAE3B,OAAOJ,OAAO,IAAI,CAACE,OAAO,KAAK;QACnC;QAEA,OAAOF,OAAO,EAAE,CAACK;IACrB;AACJ;AAEO,MAAMC,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgBb;IAChB,cAAc;QAACc;QAAiBC;KAAgB;AACpD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { SendMailUseCase } from "../../features/SendMail/abstractions.js";
|
|
3
|
+
import { TestMailNotAuthorized } from "../../domain/errors.js";
|
|
4
|
+
import { TestMailNotConfigured } from "../../domain/errors.js";
|
|
5
|
+
export interface SendTestMailInput {
|
|
6
|
+
to: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ISendTestMailErrors {
|
|
9
|
+
notAuthorized: TestMailNotAuthorized;
|
|
10
|
+
notConfigured: TestMailNotConfigured;
|
|
11
|
+
sendMail: SendMailUseCase.Error;
|
|
12
|
+
}
|
|
13
|
+
type SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];
|
|
14
|
+
export interface ISendTestMailUseCase {
|
|
15
|
+
execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sends one message through the transport that delivers this project's mail, so an operator can
|
|
19
|
+
* tell settings that deliver from settings that only look configured. The mail server's own error
|
|
20
|
+
* comes back to the caller.
|
|
21
|
+
*
|
|
22
|
+
* The test goes through `SendMailUseCase` like any other mail, so it publishes the same
|
|
23
|
+
* `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SendTestMailUseCase: import("@webiny/di").Abstraction<ISendTestMailUseCase>;
|
|
26
|
+
export declare namespace SendTestMailUseCase {
|
|
27
|
+
type Interface = ISendTestMailUseCase;
|
|
28
|
+
type Input = SendTestMailInput;
|
|
29
|
+
type Return = Promise<Result<void, SendTestMailError>>;
|
|
30
|
+
type Error = SendTestMailError;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/abstractions.js","sources":["../../../src/features/SendTestMail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\n\nexport interface SendTestMailInput {\n to: string;\n}\n\nexport interface ISendTestMailErrors {\n notAuthorized: TestMailNotAuthorized;\n notConfigured: TestMailNotConfigured;\n sendMail: SendMailUseCase.Error;\n}\n\ntype SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];\n\nexport interface ISendTestMailUseCase {\n execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;\n}\n\n/**\n * Sends one message through the transport that delivers this project's mail, so an operator can\n * tell settings that deliver from settings that only look configured. The mail server's own error\n * comes back to the caller.\n *\n * The test goes through `SendMailUseCase` like any other mail, so it publishes the same\n * `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.\n */\nexport const SendTestMailUseCase = createAbstraction<ISendTestMailUseCase>(\"SendTestMailUseCase\");\n\nexport namespace SendTestMailUseCase {\n export type Interface = ISendTestMailUseCase;\n export type Input = SendTestMailInput;\n export type Return = Promise<Result<void, SendTestMailError>>;\n export type Error = SendTestMailError;\n}\n"],"names":["SendTestMailUseCase","createAbstraction"],"mappings":";AA8BO,MAAMA,sBAAsBC,kBAAwC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SendTestMailUseCaseImplementation } from "./SendTestMailUseCase.js";
|
|
3
|
+
const SendTestMailFeature = createFeature({
|
|
4
|
+
name: "SendTestMail",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SendTestMailUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { SendTestMailFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/feature.js","sources":["../../../src/features/SendTestMail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SendTestMailUseCaseImplementation } from \"./SendTestMailUseCase.js\";\n\nexport const SendTestMailFeature = createFeature({\n name: \"SendTestMail\",\n register(container) {\n container.register(SendTestMailUseCaseImplementation);\n }\n});\n"],"names":["SendTestMailFeature","createFeature","container","SendTestMailUseCaseImplementation"],"mappings":";;AAGO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -2,9 +2,10 @@ import type SMTPTransport from "nodemailer/lib/smtp-transport";
|
|
|
2
2
|
import { MailTransport } from "../../domain/MailTransport/abstractions.js";
|
|
3
3
|
export declare class SmtpMailTransport implements MailTransport.Interface {
|
|
4
4
|
private readonly defaultFrom?;
|
|
5
|
+
private readonly defaultReplyTo?;
|
|
5
6
|
readonly name = "Mailer/SmtpTransport";
|
|
6
7
|
private readonly transporter;
|
|
7
|
-
constructor(config: SMTPTransport.Options, defaultFrom?: string | undefined);
|
|
8
|
+
constructor(config: SMTPTransport.Options, defaultFrom?: string | undefined, defaultReplyTo?: string | undefined);
|
|
8
9
|
send(params: MailTransport.SendParams): Promise<{
|
|
9
10
|
result: string;
|
|
10
11
|
error: null;
|
|
@@ -33,7 +34,7 @@ export declare class SmtpMailTransport implements MailTransport.Interface {
|
|
|
33
34
|
} | {
|
|
34
35
|
result: null;
|
|
35
36
|
error: {
|
|
36
|
-
message:
|
|
37
|
+
message: string;
|
|
37
38
|
code: any;
|
|
38
39
|
data: {
|
|
39
40
|
to?: string[];
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import nodemailer from "nodemailer";
|
|
2
|
+
import { SMTP_TRANSPORT_NAME } from "../../constants.js";
|
|
3
|
+
const getErrorMessage = (ex)=>{
|
|
4
|
+
if (ex.message) return ex.message;
|
|
5
|
+
if (Array.isArray(ex.errors)) return ex.errors.map((error)=>error.message).filter(Boolean).join("; ");
|
|
6
|
+
return "";
|
|
7
|
+
};
|
|
2
8
|
class SmtpMailTransport {
|
|
3
|
-
constructor(config, defaultFrom){
|
|
9
|
+
constructor(config, defaultFrom, defaultReplyTo){
|
|
4
10
|
this.defaultFrom = defaultFrom;
|
|
5
|
-
this.
|
|
11
|
+
this.defaultReplyTo = defaultReplyTo;
|
|
12
|
+
this.name = SMTP_TRANSPORT_NAME;
|
|
6
13
|
this.transporter = nodemailer.createTransport(config);
|
|
7
14
|
}
|
|
8
15
|
async send(params) {
|
|
9
16
|
const { replyTo, text, html, to, bcc, cc, from, subject } = params;
|
|
10
17
|
try {
|
|
11
18
|
const result = await this.transporter.sendMail({
|
|
12
|
-
replyTo,
|
|
19
|
+
replyTo: replyTo || this.defaultReplyTo || void 0,
|
|
13
20
|
bcc,
|
|
14
21
|
cc,
|
|
15
22
|
from: from || this.defaultFrom || void 0,
|
|
@@ -36,7 +43,7 @@ class SmtpMailTransport {
|
|
|
36
43
|
return {
|
|
37
44
|
result: null,
|
|
38
45
|
error: {
|
|
39
|
-
message: ex
|
|
46
|
+
message: getErrorMessage(ex),
|
|
40
47
|
code: ex.code,
|
|
41
48
|
data: {
|
|
42
49
|
...params,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SmtpTransport/SmtpMailTransport.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name =
|
|
1
|
+
{"version":3,"file":"features/SmtpTransport/SmtpMailTransport.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\nimport { SMTP_TRANSPORT_NAME } from \"~/constants.js\";\n\n/*\n * A host with both IPv4 and IPv6 addresses (`localhost`, most mail providers) fails to connect\n * with an AggregateError: one error per address and an empty message of its own.\n */\nconst getErrorMessage = (ex: any): string => {\n if (ex.message) {\n return ex.message;\n }\n if (Array.isArray(ex.errors)) {\n return ex.errors\n .map((error: Error) => error.message)\n .filter(Boolean)\n .join(\"; \");\n }\n return \"\";\n};\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = SMTP_TRANSPORT_NAME;\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(\n config: SMTPTransport.Options,\n private readonly defaultFrom?: string,\n private readonly defaultReplyTo?: string\n ) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo: replyTo || this.defaultReplyTo || undefined,\n bcc,\n cc,\n // An explicit sender wins; otherwise the configured settings sender (R201).\n // An empty default counts as none, so a missing settings `from` changes nothing.\n from: from || this.defaultFrom || undefined,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n // Allow-list specific nodemailer/SMTP error fields. Spreading `ex`\n // or `ex.data` blindly would risk surfacing the transporter's auth\n // config (or anything else a future nodemailer version stamps onto\n // its errors) in error responses.\n return {\n result: null,\n error: {\n message: getErrorMessage(ex),\n code: ex.code,\n data: {\n ...params,\n command: ex.command,\n response: ex.response,\n responseCode: ex.responseCode\n }\n }\n };\n }\n }\n}\n"],"names":["getErrorMessage","ex","Array","error","Boolean","SmtpMailTransport","config","defaultFrom","defaultReplyTo","SMTP_TRANSPORT_NAME","nodemailer","params","replyTo","text","html","to","bcc","cc","from","subject","result","undefined"],"mappings":";;AAUA,MAAMA,kBAAkB,CAACC;IACrB,IAAIA,GAAG,OAAO,EACV,OAAOA,GAAG,OAAO;IAErB,IAAIC,MAAM,OAAO,CAACD,GAAG,MAAM,GACvB,OAAOA,GAAG,MAAM,CACX,GAAG,CAAC,CAACE,QAAiBA,MAAM,OAAO,EACnC,MAAM,CAACC,SACP,IAAI,CAAC;IAEd,OAAO;AACX;AAEO,MAAMC;IAIT,YACIC,MAA6B,EACZC,WAAoB,EACpBC,cAAuB,CAC1C;aAFmBD,WAAW,GAAXA;aACAC,cAAc,GAAdA;aANL,IAAI,GAAGC;QAQnB,IAAI,CAAC,WAAW,GAAGC,WAAW,eAAe,CAACJ;IAClD;IAEA,MAAM,KAAKK,MAAgC,EAAE;QACzC,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAEC,EAAE,EAAEC,GAAG,EAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAGR;QAE5D,IAAI;YACA,MAAMS,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBAC3C,SAASR,WAAW,IAAI,CAAC,cAAc,IAAIS;gBAC3CL;gBACAC;gBAGA,MAAMC,QAAQ,IAAI,CAAC,WAAW,IAAIG;gBAClCR;gBACAC;gBACAC;gBACAI;YACJ;YAEA,IAAIC,OAAO,SAAS,EAChB,OAAO;gBACH,QAAQA,OAAO,QAAQ;gBACvB,OAAO;YACX;YAGJ,OAAO;gBACH,QAAQ;gBACR,OAAO;oBACH,SACI;oBACJ,MAAM;oBACN,MAAM;wBACF,GAAGA,MAAM;oBACb;gBACJ;YACJ;QACJ,EAAE,OAAOnB,IAAS;YAKd,OAAO;gBACH,QAAQ;gBACR,OAAO;oBACH,SAASD,gBAAgBC;oBACzB,MAAMA,GAAG,IAAI;oBACb,MAAM;wBACF,GAAGU,MAAM;wBACT,SAASV,GAAG,OAAO;wBACnB,UAAUA,GAAG,QAAQ;wBACrB,cAAcA,GAAG,YAAY;oBACjC;gBACJ;YACJ;QACJ;IACJ;AACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
-
import
|
|
2
|
+
import { GetSettingsRepository } from "../../features/GetSettings/abstractions.js";
|
|
3
3
|
declare class SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {
|
|
4
|
+
private getSettingsRepository;
|
|
4
5
|
readonly name = "Mailer/SmtpTransport";
|
|
5
|
-
|
|
6
|
-
createTransport(
|
|
6
|
+
constructor(getSettingsRepository: GetSettingsRepository.Interface);
|
|
7
|
+
createTransport(): MailTransportFactory.Return;
|
|
7
8
|
}
|
|
8
9
|
export declare const SmtpMailTransportFactory: typeof SmtpMailTransportFactoryImpl & {
|
|
9
10
|
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportFactory>;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
2
3
|
import { SmtpMailTransport } from "./SmtpMailTransport.js";
|
|
3
4
|
import { SmtpConfig } from "./SmtpConfig.js";
|
|
5
|
+
import { SMTP_TRANSPORT_NAME } from "../../constants.js";
|
|
4
6
|
class SmtpMailTransportFactoryImpl {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
constructor(getSettingsRepository){
|
|
8
|
+
this.getSettingsRepository = getSettingsRepository;
|
|
9
|
+
this.name = SMTP_TRANSPORT_NAME;
|
|
7
10
|
}
|
|
8
|
-
async createTransport(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
async createTransport() {
|
|
12
|
+
const result = await this.getSettingsRepository.get(this.name);
|
|
13
|
+
const { settings } = result.value;
|
|
14
|
+
if (!settings) return null;
|
|
15
|
+
return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings), settings.from, settings.replyTo);
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
const SmtpMailTransportFactory = MailTransportFactory.createImplementation({
|
|
16
19
|
implementation: SmtpMailTransportFactoryImpl,
|
|
17
|
-
dependencies: [
|
|
20
|
+
dependencies: [
|
|
21
|
+
GetSettingsRepository
|
|
22
|
+
]
|
|
18
23
|
});
|
|
19
24
|
export { SmtpMailTransportFactory };
|
|
20
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SmtpTransport/SmtpMailTransportFactory.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/SmtpTransport/SmtpMailTransportFactory.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport { GetSettingsRepository } from \"~/features/GetSettings/abstractions.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\nimport { SMTP_TRANSPORT_NAME } from \"~/constants.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n public readonly name = SMTP_TRANSPORT_NAME;\n\n constructor(private getSettingsRepository: GetSettingsRepository.Interface) {}\n\n // The settings come from code when `Api.Mailer.Smtp` sets them, otherwise from the settings form.\n async createTransport(): MailTransportFactory.Return {\n const result = await this.getSettingsRepository.get(this.name);\n const { settings } = result.value;\n if (!settings) {\n return null;\n }\n\n return new SmtpMailTransport(\n SmtpConfig.fromTransportSettings(settings),\n settings.from,\n settings.replyTo\n );\n }\n}\n\nexport const SmtpMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: SmtpMailTransportFactoryImpl,\n dependencies: [GetSettingsRepository]\n});\n"],"names":["SmtpMailTransportFactoryImpl","getSettingsRepository","SMTP_TRANSPORT_NAME","result","settings","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactory","MailTransportFactory","GetSettingsRepository"],"mappings":";;;;;AAMA,MAAMA;IAGF,YAAoBC,qBAAsD,CAAE;aAAxDA,qBAAqB,GAArBA;aAFJ,IAAI,GAAGC;IAEsD;IAG7E,MAAM,kBAA+C;QACjD,MAAMC,SAAS,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI;QAC7D,MAAM,EAAEC,QAAQ,EAAE,GAAGD,OAAO,KAAK;QACjC,IAAI,CAACC,UACD,OAAO;QAGX,OAAO,IAAIC,kBACPC,WAAW,qBAAqB,CAACF,WACjCA,SAAS,IAAI,EACbA,SAAS,OAAO;IAExB;AACJ;AAEO,MAAMG,2BAA2BC,qBAAqB,oBAAoB,CAAC;IAC9E,gBAAgBR;IAChB,cAAc;QAACS;KAAsB;AACzC"}
|
|
@@ -3,7 +3,8 @@ import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js"
|
|
|
3
3
|
import { ErrorResponse } from "@webiny/api-graphql/responses.js";
|
|
4
4
|
import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
|
|
5
5
|
import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
|
|
6
|
-
|
|
6
|
+
import { SendTestMailUseCase } from "../features/SendTestMail/abstractions.js";
|
|
7
|
+
import { SMTP_TRANSPORT_NAME } from "../constants.js";
|
|
7
8
|
const toPublicSettings = (settings, source)=>{
|
|
8
9
|
if (!settings) return null;
|
|
9
10
|
const { password: _password, ...publicSettings } = settings;
|
|
@@ -50,8 +51,14 @@ class MailerSchemaFactoryImpl {
|
|
|
50
51
|
replyTo: String
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
type MailerSendTestMailResponse {
|
|
55
|
+
data: Boolean
|
|
56
|
+
error: MailerTransportSettingsError
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
type MailerMutation {
|
|
54
60
|
saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!
|
|
61
|
+
sendTestMail(to: String!): MailerSendTestMailResponse!
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
extend type Query {
|
|
@@ -106,6 +113,26 @@ class MailerSchemaFactoryImpl {
|
|
|
106
113
|
}
|
|
107
114
|
}
|
|
108
115
|
});
|
|
116
|
+
builder.addResolver({
|
|
117
|
+
path: "MailerMutation.sendTestMail",
|
|
118
|
+
dependencies: [
|
|
119
|
+
SendTestMailUseCase
|
|
120
|
+
],
|
|
121
|
+
resolver: (sendTestMail)=>async ({ args })=>{
|
|
122
|
+
try {
|
|
123
|
+
const result = await sendTestMail.execute({
|
|
124
|
+
to: args.to
|
|
125
|
+
});
|
|
126
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
127
|
+
return {
|
|
128
|
+
data: true,
|
|
129
|
+
error: null
|
|
130
|
+
};
|
|
131
|
+
} catch (ex) {
|
|
132
|
+
return new ErrorResponse(ex);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
109
136
|
return builder;
|
|
110
137
|
}
|
|
111
138
|
constructor(){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/MailerSchemaFactory.js","sources":["../../src/graphql/MailerSchemaFactory.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport type { IGraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ErrorResponse } from \"@webiny/api-graphql/responses.js\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\nimport type { MailerSettingsSource } from \"~/features/GetSettings/abstractions.js\";\nimport type { SaveSettingsInput } from \"~/features/SaveSettings/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\
|
|
1
|
+
{"version":3,"file":"graphql/MailerSchemaFactory.js","sources":["../../src/graphql/MailerSchemaFactory.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport type { IGraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ErrorResponse } from \"@webiny/api-graphql/responses.js\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\nimport { SendTestMailUseCase } from \"~/features/SendTestMail/abstractions.js\";\nimport type { MailerSettingsSource } from \"~/features/GetSettings/abstractions.js\";\nimport type { SaveSettingsInput } from \"~/features/SaveSettings/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SMTP_TRANSPORT_NAME } from \"~/constants.js\";\n\n// Strip `password` before the settings leave the server and tack on `source`\n// so the admin UI can branch on code-vs-storage. Accepts both the full\n// `TransportSettings` (from getSettings) and the already-stripped\n// `Omit<TransportSettings, \"password\">` (from saveSettings) — defense in depth\n// even when the input type carries no password to begin with.\nconst toPublicSettings = (\n settings: TransportSettings | Omit<TransportSettings, \"password\"> | null,\n source: MailerSettingsSource\n): (Omit<TransportSettings, \"password\"> & { source: MailerSettingsSource }) | null => {\n if (!settings) {\n return null;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _password, ...publicSettings } = settings as TransportSettings;\n return { ...publicSettings, source };\n};\n\nclass MailerSchemaFactoryImpl implements GraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-mailer/MailerSchemaFactoryImpl\");\n\n async execute(builder: IGraphQLSchemaBuilder): Promise<IGraphQLSchemaBuilder> {\n builder.addTypeDefs(`\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n\n type MailerTransportSettings {\n host: String\n port: Number\n secure: Boolean\n user: String\n from: String\n replyTo: String\n source: String\n }\n\n type MailerTransportSettingsResponse {\n data: MailerTransportSettings\n error: MailerTransportSettingsError\n }\n\n type MailerQuery {\n getSettings: MailerTransportSettingsResponse!\n }\n\n input MailerTransportSettingsInput {\n host: String!\n port: Number\n secure: Boolean\n user: String!\n password: String\n from: String!\n replyTo: String\n }\n\n type MailerSendTestMailResponse {\n data: Boolean\n error: MailerTransportSettingsError\n }\n\n type MailerMutation {\n saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!\n sendTestMail(to: String!): MailerSendTestMailResponse!\n }\n\n extend type Query {\n mailer: MailerQuery\n }\n extend type Mutation {\n mailer: MailerMutation\n }\n `);\n\n builder.addResolver({\n path: \"Query.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"MailerQuery.getSettings\",\n dependencies: [GetSettingsUseCase],\n resolver: (getSettings: GetSettingsUseCase.Interface) => async () => {\n try {\n const result = await getSettings.execute(SMTP_TRANSPORT_NAME);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n const { settings, source } = result.value;\n\n return {\n data: toPublicSettings(settings, source),\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ data: SaveSettingsInput }>({\n path: \"MailerMutation.saveSettings\",\n dependencies: [SaveSettingsUseCase],\n resolver:\n (saveSettings: SaveSettingsUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await saveSettings.execute(args.data);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return {\n data: toPublicSettings(result.value, \"storage\"),\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ to: string }>({\n path: \"MailerMutation.sendTestMail\",\n dependencies: [SendTestMailUseCase],\n resolver:\n (sendTestMail: SendTestMailUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await sendTestMail.execute({ to: args.to });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return { data: true, error: null };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n return builder;\n }\n}\n\nexport const MailerSchemaFactory = GraphQLSchemaFactory.createImplementation({\n implementation: MailerSchemaFactoryImpl,\n dependencies: []\n});\n"],"names":["toPublicSettings","settings","source","_password","publicSettings","MailerSchemaFactoryImpl","builder","GetSettingsUseCase","getSettings","result","SMTP_TRANSPORT_NAME","ErrorResponse","ex","SaveSettingsUseCase","saveSettings","args","SendTestMailUseCase","sendTestMail","staticSchemaKey","MailerSchemaFactory","GraphQLSchemaFactory"],"mappings":";;;;;;;AAiBA,MAAMA,mBAAmB,CACrBC,UACAC;IAEA,IAAI,CAACD,UACD,OAAO;IAGX,MAAM,EAAE,UAAUE,SAAS,EAAE,GAAGC,gBAAgB,GAAGH;IACnD,OAAO;QAAE,GAAGG,cAAc;QAAEF;IAAO;AACvC;AAEA,MAAMG;IAGF,MAAM,QAAQC,OAA8B,EAAkC;QAC1EA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAoDrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;aAAmB;YAClC,UAAU,CAACC,cAA8C;oBACrD,IAAI;wBACA,MAAMC,SAAS,MAAMD,YAAY,OAAO,CAACE;wBAEzC,IAAID,OAAO,MAAM,IACb,OAAO,IAAIE,cAAcF,OAAO,KAAK;wBAGzC,MAAM,EAAER,QAAQ,EAAEC,MAAM,EAAE,GAAGO,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAMT,iBAAiBC,UAAUC;4BACjC,OAAO;wBACX;oBACJ,EAAE,OAAOU,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACJ;QAEAN,QAAQ,WAAW,CAA8B;YAC7C,MAAM;YACN,cAAc;gBAACO;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEC,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMN,SAAS,MAAMK,aAAa,OAAO,CAACC,KAAK,IAAI;wBAEnD,IAAIN,OAAO,MAAM,IACb,OAAO,IAAIE,cAAcF,OAAO,KAAK;wBAGzC,OAAO;4BACH,MAAMT,iBAAiBS,OAAO,KAAK,EAAE;4BACrC,OAAO;wBACX;oBACJ,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEAN,QAAQ,WAAW,CAAiB;YAChC,MAAM;YACN,cAAc;gBAACU;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEF,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMN,SAAS,MAAMQ,aAAa,OAAO,CAAC;4BAAE,IAAIF,KAAK,EAAE;wBAAC;wBAExD,IAAIN,OAAO,MAAM,IACb,OAAO,IAAIE,cAAcF,OAAO,KAAK;wBAGzC,OAAO;4BAAE,MAAM;4BAAM,OAAO;wBAAK;oBACrC,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEA,OAAON;IACX;;aAtIO,YAAY,GAAGY,gBAAgB;;AAuI1C;AAEO,MAAMC,sBAAsBC,qBAAqB,oBAAoB,CAAC;IACzE,gBAAgBf;IAChB,cAAc,EAAE;AACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-mailer",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"description": "The API to send e-mails.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api-graphql": "6.6.0-alpha.
|
|
22
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
23
|
-
"@webiny/plugins": "6.6.0-alpha.
|
|
21
|
+
"@webiny/api-graphql": "6.6.0-alpha.12",
|
|
22
|
+
"@webiny/feature": "6.6.0-alpha.12",
|
|
23
|
+
"@webiny/plugins": "6.6.0-alpha.12",
|
|
24
24
|
"email-addresses": "5.0.0",
|
|
25
25
|
"nodemailer": "10.3.1",
|
|
26
26
|
"zod": "4.6.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/nodemailer": "8.0.2",
|
|
30
|
-
"@webiny/api": "6.6.0-alpha.
|
|
31
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
32
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
33
|
-
"@webiny/db-dynamodb": "6.6.0-alpha.
|
|
30
|
+
"@webiny/api": "6.6.0-alpha.12",
|
|
31
|
+
"@webiny/api-core": "6.6.0-alpha.12",
|
|
32
|
+
"@webiny/build-tools": "6.6.0-alpha.12",
|
|
33
|
+
"@webiny/db-dynamodb": "6.6.0-alpha.12",
|
|
34
34
|
"@webiny/di": "2.0.0",
|
|
35
|
-
"@webiny/event-handler-core": "6.6.0-alpha.
|
|
36
|
-
"@webiny/handler": "6.6.0-alpha.
|
|
35
|
+
"@webiny/event-handler-core": "6.6.0-alpha.12",
|
|
36
|
+
"@webiny/handler": "6.6.0-alpha.12",
|
|
37
37
|
"graphql": "16.14.2",
|
|
38
38
|
"rimraf": "6.1.3",
|
|
39
39
|
"typescript": "7.0.2",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MailTransport } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
-
export declare class DummyMailTransport implements MailTransport.Interface {
|
|
3
|
-
readonly name = "Mailer/DummyTransport";
|
|
4
|
-
constructor();
|
|
5
|
-
send(): Promise<{
|
|
6
|
-
result: boolean;
|
|
7
|
-
error: null;
|
|
8
|
-
}>;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/DummyTransport/DummyMailTransport.js","sources":["../../../src/features/DummyTransport/DummyMailTransport.ts"],"sourcesContent":["import { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class DummyMailTransport implements MailTransport.Interface {\n public readonly name = \"Mailer/DummyTransport\";\n\n constructor() {}\n\n async send() {\n return {\n result: true,\n error: null\n };\n }\n}\n"],"names":["DummyMailTransport"],"mappings":"AAEO,MAAMA;IAGT,aAAc;aAFE,IAAI,GAAG;IAER;IAEf,MAAM,OAAO;QACT,OAAO;YACH,QAAQ;YACR,OAAO;QACX;IACJ;AACJ"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type IMailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
-
declare class DummyMailTransportFactoryImpl implements MailTransportFactory.Interface {
|
|
3
|
-
readonly name = "Mailer/DummyTransport";
|
|
4
|
-
canUse(): boolean;
|
|
5
|
-
createTransport(): Promise<IMailTransport>;
|
|
6
|
-
}
|
|
7
|
-
export declare const DummyMailTransportFactory: typeof DummyMailTransportFactoryImpl & {
|
|
8
|
-
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportFactory>;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
-
import { DummyMailTransport } from "./DummyMailTransport.js";
|
|
3
|
-
class DummyMailTransportFactoryImpl {
|
|
4
|
-
canUse() {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
async createTransport() {
|
|
8
|
-
return new DummyMailTransport();
|
|
9
|
-
}
|
|
10
|
-
constructor(){
|
|
11
|
-
this.name = "Mailer/DummyTransport";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const DummyMailTransportFactory = MailTransportFactory.createImplementation({
|
|
15
|
-
implementation: DummyMailTransportFactoryImpl,
|
|
16
|
-
dependencies: []
|
|
17
|
-
});
|
|
18
|
-
export { DummyMailTransportFactory };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=DummyMailTransportFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/DummyTransport/DummyMailTransportFactory.js","sources":["../../../src/features/DummyTransport/DummyMailTransportFactory.ts"],"sourcesContent":["import { type IMailTransport, MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport { DummyMailTransport } from \"./DummyMailTransport.js\";\n\nclass DummyMailTransportFactoryImpl implements MailTransportFactory.Interface {\n public readonly name = \"Mailer/DummyTransport\";\n\n canUse(): boolean {\n return true;\n }\n\n async createTransport(): Promise<IMailTransport> {\n return new DummyMailTransport();\n }\n}\n\nexport const DummyMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: DummyMailTransportFactoryImpl,\n dependencies: []\n});\n"],"names":["DummyMailTransportFactoryImpl","DummyMailTransport","DummyMailTransportFactory","MailTransportFactory"],"mappings":";;AAGA,MAAMA;IAGF,SAAkB;QACd,OAAO;IACX;IAEA,MAAM,kBAA2C;QAC7C,OAAO,IAAIC;IACf;;aARgB,IAAI,GAAG;;AAS3B;AAEO,MAAMC,4BAA4BC,qBAAqB,oBAAoB,CAAC;IAC/E,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api";
|
|
2
|
-
import { DummyMailTransportFactory } from "./DummyMailTransportFactory.js";
|
|
3
|
-
const DummyTransportFeature = createFeature({
|
|
4
|
-
name: "Mailer/DummyTransport",
|
|
5
|
-
register (container) {
|
|
6
|
-
container.register(DummyMailTransportFactory).inSingletonScope();
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
export { DummyTransportFeature };
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/DummyTransport/feature.js","sources":["../../../src/features/DummyTransport/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { DummyMailTransportFactory } from \"./DummyMailTransportFactory.js\";\n\nexport const DummyTransportFeature = createFeature({\n name: \"Mailer/DummyTransport\",\n register(container) {\n container.register(DummyMailTransportFactory).inSingletonScope();\n }\n});\n"],"names":["DummyTransportFeature","createFeature","container","DummyMailTransportFactory"],"mappings":";;AAGO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,2BAA2B,gBAAgB;IAClE;AACJ"}
|