@webiny/api-mailer 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/README.md +10 -13
- package/constants.d.ts +1 -0
- package/constants.js +4 -0
- package/constants.js.map +1 -0
- package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +5 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +26 -0
- package/domain/MailTransport/abstractions.js +7 -0
- package/domain/MailTransport/abstractions.js.map +1 -0
- package/domain/MailerService/abstractions.d.ts +19 -0
- package/domain/MailerService/abstractions.js +5 -0
- package/domain/MailerService/abstractions.js.map +1 -0
- package/domain/MailerService/errors.d.ts +16 -0
- package/domain/MailerService/errors.js +28 -0
- package/domain/MailerService/errors.js.map +1 -0
- package/domain/errors.d.ts +28 -0
- package/domain/errors.js +48 -0
- package/domain/errors.js.map +1 -0
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +4 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +23 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +11 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransport.js +14 -0
- package/features/DummyTransport/DummyMailTransport.js.map +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +17 -0
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
- package/features/DummyTransport/feature.d.ts +4 -0
- package/features/DummyTransport/feature.js +11 -0
- package/features/DummyTransport/feature.js.map +1 -0
- package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
- package/features/GetSettings/GetSettingsRepository.js +54 -0
- package/features/GetSettings/GetSettingsRepository.js.map +1 -0
- package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
- package/features/GetSettings/GetSettingsUseCase.js +18 -0
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
- package/features/GetSettings/abstractions.d.ts +22 -0
- package/features/GetSettings/abstractions.js +6 -0
- package/features/GetSettings/abstractions.js.map +1 -0
- package/features/GetSettings/feature.d.ts +4 -0
- package/features/GetSettings/feature.js +13 -0
- package/features/GetSettings/feature.js.map +1 -0
- package/features/GetSettings/index.d.ts +1 -0
- package/features/GetSettings/index.js +1 -0
- package/features/MailerService/ActiveTransport.d.ts +10 -0
- package/features/MailerService/ActiveTransport.js +24 -0
- package/features/MailerService/ActiveTransport.js.map +1 -0
- package/features/MailerService/MailerService.d.ts +16 -0
- package/features/MailerService/MailerService.js +49 -0
- package/features/MailerService/MailerService.js.map +1 -0
- package/features/MailerService/feature.d.ts +4 -0
- package/features/MailerService/feature.js +13 -0
- package/features/MailerService/feature.js.map +1 -0
- package/features/SaveSettings/SaveSettingsRepository.d.ts +13 -0
- package/features/SaveSettings/SaveSettingsRepository.js +43 -0
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
- package/features/SaveSettings/SaveSettingsUseCase.js +51 -0
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
- package/features/SaveSettings/abstractions.d.ts +61 -0
- package/features/SaveSettings/abstractions.js +8 -0
- package/features/SaveSettings/abstractions.js.map +1 -0
- package/features/SaveSettings/events.d.ts +10 -0
- package/features/SaveSettings/events.js +21 -0
- package/features/SaveSettings/events.js.map +1 -0
- package/features/SaveSettings/feature.d.ts +4 -0
- package/features/SaveSettings/feature.js +13 -0
- package/features/SaveSettings/feature.js.map +1 -0
- package/features/SaveSettings/index.d.ts +1 -0
- package/features/SaveSettings/index.js +1 -0
- package/features/SaveSettings/validation.d.ts +9 -0
- package/features/SaveSettings/validation.js +20 -0
- package/features/SaveSettings/validation.js.map +1 -0
- package/features/SendMail/SendMailUseCase.d.ts +16 -0
- package/features/SendMail/SendMailUseCase.js +58 -0
- package/features/SendMail/SendMailUseCase.js.map +1 -0
- package/features/SendMail/abstractions.d.ts +45 -0
- package/features/SendMail/abstractions.js +8 -0
- package/features/SendMail/abstractions.js.map +1 -0
- package/features/SendMail/events.d.ts +14 -0
- package/features/SendMail/events.js +29 -0
- package/features/SendMail/events.js.map +1 -0
- package/features/SendMail/feature.d.ts +4 -0
- package/features/SendMail/feature.js +11 -0
- package/features/SendMail/feature.js.map +1 -0
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +1 -0
- package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
- package/features/SmtpTransport/SmtpConfig.js +25 -0
- package/features/SmtpTransport/SmtpConfig.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +68 -0
- package/features/SmtpTransport/SmtpMailTransport.js +53 -0
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +10 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +18 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
- package/features/SmtpTransport/feature.d.ts +4 -0
- package/features/SmtpTransport/feature.js +11 -0
- package/features/SmtpTransport/feature.js.map +1 -0
- package/graphql/settings.d.ts +2 -2
- package/graphql/settings.js +71 -73
- package/graphql/settings.js.map +1 -1
- package/index.d.ts +4 -8
- package/index.js +23 -89
- package/index.js.map +1 -1
- package/package.json +32 -45
- package/types.d.ts +2 -109
- package/types.js +0 -5
- package/utils/isMailboxAddress.d.ts +6 -0
- package/utils/isMailboxAddress.js +5 -0
- package/utils/isMailboxAddress.js.map +1 -0
- package/context.d.ts +0 -3
- package/context.js +0 -24
- package/context.js.map +0 -1
- package/crud/group.d.ts +0 -2
- package/crud/group.js +0 -21
- package/crud/group.js.map +0 -1
- package/crud/mailer/onBeforeSend.d.ts +0 -7
- package/crud/mailer/onBeforeSend.js +0 -69
- package/crud/mailer/onBeforeSend.js.map +0 -1
- package/crud/mailer.crud.d.ts +0 -2
- package/crud/mailer.crud.js +0 -123
- package/crud/mailer.crud.js.map +0 -1
- package/crud/settings/hooks.d.ts +0 -5
- package/crud/settings/hooks.js +0 -55
- package/crud/settings/hooks.js.map +0 -1
- package/crud/settings/model.d.ts +0 -3
- package/crud/settings/model.js +0 -90
- package/crud/settings/model.js.map +0 -1
- package/crud/settings/password.d.ts +0 -7
- package/crud/settings/password.js +0 -71
- package/crud/settings/password.js.map +0 -1
- package/crud/settings/secret.d.ts +0 -1
- package/crud/settings/secret.js +0 -23
- package/crud/settings/secret.js.map +0 -1
- package/crud/settings/transform.d.ts +0 -13
- package/crud/settings/transform.js +0 -56
- package/crud/settings/transform.js.map +0 -1
- package/crud/settings/validation.d.ts +0 -4
- package/crud/settings/validation.js +0 -38
- package/crud/settings/validation.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -5
- package/crud/settings.crud.js +0 -331
- package/crud/settings.crud.js.map +0 -1
- package/crud/transport/onTransportBeforeSend.d.ts +0 -7
- package/crud/transport/onTransportBeforeSend.js +0 -69
- package/crud/transport/onTransportBeforeSend.js.map +0 -1
- package/crud/transporter.crud.d.ts +0 -2
- package/crud/transporter.crud.js +0 -193
- package/crud/transporter.crud.js.map +0 -1
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +0 -14
- package/graphql/index.js.map +0 -1
- package/mailers/createDummyMailer.d.ts +0 -5
- package/mailers/createDummyMailer.js +0 -24
- package/mailers/createDummyMailer.js.map +0 -1
- package/mailers/createSmtpMailer.d.ts +0 -13
- package/mailers/createSmtpMailer.js +0 -106
- package/mailers/createSmtpMailer.js.map +0 -1
- package/plugins/CreateTransportPlugin.d.ts +0 -17
- package/plugins/CreateTransportPlugin.js +0 -34
- package/plugins/CreateTransportPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -1
- package/plugins/index.js +0 -18
- package/plugins/index.js.map +0 -1
- package/transports/createDummyTransport.d.ts +0 -5
- package/transports/createDummyTransport.js +0 -25
- package/transports/createDummyTransport.js.map +0 -1
- package/transports/createSmtpTransport.d.ts +0 -12
- package/transports/createSmtpTransport.js +0 -101
- package/transports/createSmtpTransport.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import type { TransportSendData, TransportSendResponse } from "../../types.js";
|
|
4
|
+
import type { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
5
|
+
import { MailValidationError } from "../../domain/errors.js";
|
|
6
|
+
export interface ISendMailErrors {
|
|
7
|
+
validation: MailValidationError;
|
|
8
|
+
mailService: MailerService.Error;
|
|
9
|
+
}
|
|
10
|
+
type SendMailErrors = ISendMailErrors[keyof ISendMailErrors];
|
|
11
|
+
export interface ISendMailUseCase {
|
|
12
|
+
execute(data: TransportSendData): Promise<Result<TransportSendResponse, SendMailErrors>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const SendMailUseCase: import("@webiny/di").Abstraction<ISendMailUseCase>;
|
|
15
|
+
export declare namespace SendMailUseCase {
|
|
16
|
+
type Interface = ISendMailUseCase;
|
|
17
|
+
type Error = SendMailErrors;
|
|
18
|
+
}
|
|
19
|
+
export interface MailBeforeSendPayload {
|
|
20
|
+
data: TransportSendData;
|
|
21
|
+
}
|
|
22
|
+
export interface MailAfterSendPayload {
|
|
23
|
+
data: TransportSendData;
|
|
24
|
+
response: TransportSendResponse;
|
|
25
|
+
}
|
|
26
|
+
export interface MailSendErrorPayload {
|
|
27
|
+
data: TransportSendData;
|
|
28
|
+
error: Error;
|
|
29
|
+
}
|
|
30
|
+
export declare const MailBeforeSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailBeforeSendPayload>>>;
|
|
31
|
+
export declare namespace MailBeforeSendEventHandler {
|
|
32
|
+
type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;
|
|
33
|
+
type Event = DomainEvent<MailBeforeSendPayload>;
|
|
34
|
+
}
|
|
35
|
+
export declare const MailAfterSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailAfterSendPayload>>>;
|
|
36
|
+
export declare namespace MailAfterSendEventHandler {
|
|
37
|
+
type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;
|
|
38
|
+
type Event = DomainEvent<MailAfterSendPayload>;
|
|
39
|
+
}
|
|
40
|
+
export declare const MailSendErrorEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailSendErrorPayload>>>;
|
|
41
|
+
export declare namespace MailSendErrorEventHandler {
|
|
42
|
+
type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;
|
|
43
|
+
type Event = DomainEvent<MailSendErrorPayload>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const SendMailUseCase = createAbstraction("SendMail");
|
|
3
|
+
const MailBeforeSendEventHandler = createAbstraction("MailBeforeSendEventHandler");
|
|
4
|
+
const MailAfterSendEventHandler = createAbstraction("MailAfterSendEventHandler");
|
|
5
|
+
const MailSendErrorEventHandler = createAbstraction("MailSendErrorEventHandler");
|
|
6
|
+
export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendMail/abstractions.js","sources":["../../../src/features/SendMail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { TransportSendData, TransportSendResponse } from \"~/types.js\";\nimport type { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\n\nexport interface ISendMailErrors {\n validation: MailValidationError;\n mailService: MailerService.Error;\n}\n\ntype SendMailErrors = ISendMailErrors[keyof ISendMailErrors];\n\nexport interface ISendMailUseCase {\n execute(data: TransportSendData): Promise<Result<TransportSendResponse, SendMailErrors>>;\n}\n\nexport const SendMailUseCase = createAbstraction<ISendMailUseCase>(\"SendMail\");\n\nexport namespace SendMailUseCase {\n export type Interface = ISendMailUseCase;\n export type Error = SendMailErrors;\n}\n\n// Domain Events\nexport interface MailBeforeSendPayload {\n data: TransportSendData;\n}\n\nexport interface MailAfterSendPayload {\n data: TransportSendData;\n response: TransportSendResponse;\n}\n\nexport interface MailSendErrorPayload {\n data: TransportSendData;\n error: Error;\n}\n\n// Event Handler Abstractions\nexport const MailBeforeSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailBeforeSendPayload>>\n>(\"MailBeforeSendEventHandler\");\n\nexport namespace MailBeforeSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;\n export type Event = DomainEvent<MailBeforeSendPayload>;\n}\n\nexport const MailAfterSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailAfterSendPayload>>\n>(\"MailAfterSendEventHandler\");\n\nexport namespace MailAfterSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;\n export type Event = DomainEvent<MailAfterSendPayload>;\n}\n\nexport const MailSendErrorEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailSendErrorPayload>>\n>(\"MailSendErrorEventHandler\");\n\nexport namespace MailSendErrorEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;\n export type Event = DomainEvent<MailSendErrorPayload>;\n}\n"],"names":["SendMailUseCase","createAbstraction","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler"],"mappings":";AAkBO,MAAMA,kBAAkBC,kBAAoC;AAuB5D,MAAMC,6BAA6BD,kBAExC;AAOK,MAAME,4BAA4BF,kBAEvC;AAOK,MAAMG,4BAA4BH,kBAEvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import type { MailBeforeSendPayload, MailAfterSendPayload, MailSendErrorPayload } from "./abstractions.js";
|
|
3
|
+
export declare class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {
|
|
4
|
+
eventType: "mailer.mail.beforeSend";
|
|
5
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailBeforeSendPayload>>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {
|
|
8
|
+
eventType: "mailer.mail.afterSend";
|
|
9
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailAfterSendPayload>>>;
|
|
10
|
+
}
|
|
11
|
+
export declare class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {
|
|
12
|
+
eventType: "mailer.mail.sendError";
|
|
13
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailSendErrorPayload>>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
3
|
+
class MailBeforeSendEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return MailBeforeSendEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "mailer.mail.beforeSend";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class MailAfterSendEvent extends DomainEvent {
|
|
12
|
+
getHandlerAbstraction() {
|
|
13
|
+
return MailAfterSendEventHandler;
|
|
14
|
+
}
|
|
15
|
+
constructor(...args){
|
|
16
|
+
super(...args), this.eventType = "mailer.mail.afterSend";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class MailSendErrorEvent extends DomainEvent {
|
|
20
|
+
getHandlerAbstraction() {
|
|
21
|
+
return MailSendErrorEventHandler;
|
|
22
|
+
}
|
|
23
|
+
constructor(...args){
|
|
24
|
+
super(...args), this.eventType = "mailer.mail.sendError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { MailAfterSendEvent, MailBeforeSendEvent, MailSendErrorEvent };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendMail/events.js","sources":["../../../src/features/SendMail/events.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n MailBeforeSendEventHandler,\n MailAfterSendEventHandler,\n MailSendErrorEventHandler\n} from \"./abstractions.js\";\nimport type {\n MailBeforeSendPayload,\n MailAfterSendPayload,\n MailSendErrorPayload\n} from \"./abstractions.js\";\n\nexport class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {\n eventType = \"mailer.mail.beforeSend\" as const;\n\n getHandlerAbstraction() {\n return MailBeforeSendEventHandler;\n }\n}\n\nexport class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {\n eventType = \"mailer.mail.afterSend\" as const;\n\n getHandlerAbstraction() {\n return MailAfterSendEventHandler;\n }\n}\n\nexport class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {\n eventType = \"mailer.mail.sendError\" as const;\n\n getHandlerAbstraction() {\n return MailSendErrorEventHandler;\n }\n}\n"],"names":["MailBeforeSendEvent","DomainEvent","MailBeforeSendEventHandler","MailAfterSendEvent","MailAfterSendEventHandler","MailSendErrorEvent","MailSendErrorEventHandler"],"mappings":";;AAYO,MAAMA,4BAA4BC;IAGrC,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMC,2BAA2BF;IAGpC,wBAAwB;QACpB,OAAOG;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMC,2BAA2BJ;IAGpC,wBAAwB;QACpB,OAAOK;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SendMailUseCaseImplementation } from "./SendMailUseCase.js";
|
|
3
|
+
const SendMailFeature = createFeature({
|
|
4
|
+
name: "SendMail",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SendMailUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { SendMailFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendMail/feature.js","sources":["../../../src/features/SendMail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SendMailUseCaseImplementation } from \"./SendMailUseCase.js\";\n\nexport const SendMailFeature = createFeature({\n name: \"SendMail\",\n register(container) {\n container.register(SendMailUseCaseImplementation);\n }\n});\n"],"names":["SendMailFeature","createFeature","container","SendMailUseCaseImplementation"],"mappings":";;AAGO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SendMailUseCase, MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TransportSettings } from "../../types.js";
|
|
2
|
+
import type SMTPTransport from "nodemailer/lib/smtp-transport";
|
|
3
|
+
export type SmtpTransportConfig = SMTPTransport.Options;
|
|
4
|
+
export declare class SmtpConfig {
|
|
5
|
+
static fromTransportSettings(settings: TransportSettings): SmtpTransportConfig;
|
|
6
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const configDefaults = {
|
|
2
|
+
socketTimeout: 15000,
|
|
3
|
+
connectionTimeout: 15000,
|
|
4
|
+
greetingTimeout: 15000
|
|
5
|
+
};
|
|
6
|
+
class SmtpConfig {
|
|
7
|
+
static fromTransportSettings(settings) {
|
|
8
|
+
const baseConfig = {
|
|
9
|
+
host: settings.host,
|
|
10
|
+
port: settings.port,
|
|
11
|
+
auth: {
|
|
12
|
+
user: settings.user,
|
|
13
|
+
pass: settings.password
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return Object.keys(configDefaults).reduce((config, key)=>{
|
|
17
|
+
const configKey = key;
|
|
18
|
+
if (void 0 === config[configKey] || null === config[configKey]) config[configKey] = configDefaults[configKey];
|
|
19
|
+
return config;
|
|
20
|
+
}, baseConfig);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { SmtpConfig };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=SmtpConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SmtpTransport/SmtpConfig.js","sources":["../../../src/features/SmtpTransport/SmtpConfig.ts"],"sourcesContent":["import type { TransportSettings } from \"~/types.js\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\n\nexport type SmtpTransportConfig = SMTPTransport.Options;\n\nconst configDefaults: Partial<SmtpTransportConfig> = {\n socketTimeout: 15000,\n connectionTimeout: 15000,\n greetingTimeout: 15000\n};\n\nexport class SmtpConfig {\n static fromTransportSettings(settings: TransportSettings): SmtpTransportConfig {\n const baseConfig: SmtpTransportConfig = {\n host: settings.host,\n port: settings.port,\n auth: {\n user: settings.user,\n pass: settings.password\n }\n };\n\n // Apply defaults\n return Object.keys(configDefaults).reduce<SmtpTransportConfig>((config, key) => {\n const configKey = key as keyof SmtpTransportConfig;\n if (config[configKey] === undefined || config[configKey] === null) {\n // @ts-expect-error\n config[configKey] = configDefaults[configKey];\n }\n return config;\n }, baseConfig);\n }\n}\n"],"names":["configDefaults","SmtpConfig","settings","baseConfig","Object","config","key","configKey","undefined"],"mappings":"AAKA,MAAMA,iBAA+C;IACjD,eAAe;IACf,mBAAmB;IACnB,iBAAiB;AACrB;AAEO,MAAMC;IACT,OAAO,sBAAsBC,QAA2B,EAAuB;QAC3E,MAAMC,aAAkC;YACpC,MAAMD,SAAS,IAAI;YACnB,MAAMA,SAAS,IAAI;YACnB,MAAM;gBACF,MAAMA,SAAS,IAAI;gBACnB,MAAMA,SAAS,QAAQ;YAC3B;QACJ;QAGA,OAAOE,OAAO,IAAI,CAACJ,gBAAgB,MAAM,CAAsB,CAACK,QAAQC;YACpE,MAAMC,YAAYD;YAClB,IAAID,AAAsBG,WAAtBH,MAAM,CAACE,UAAU,IAAkBF,AAAsB,SAAtBA,MAAM,CAACE,UAAU,EAEpDF,MAAM,CAACE,UAAU,GAAGP,cAAc,CAACO,UAAU;YAEjD,OAAOF;QACX,GAAGF;IACP;AACJ"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type SMTPTransport from "nodemailer/lib/smtp-transport";
|
|
2
|
+
import { MailTransport } from "../../domain/MailTransport/abstractions.js";
|
|
3
|
+
export declare class SmtpMailTransport implements MailTransport.Interface {
|
|
4
|
+
readonly name = "Mailer/SmtpTransport";
|
|
5
|
+
private readonly transporter;
|
|
6
|
+
constructor(config: SMTPTransport.Options);
|
|
7
|
+
send(params: MailTransport.SendParams): Promise<{
|
|
8
|
+
result: string;
|
|
9
|
+
error: null;
|
|
10
|
+
} | {
|
|
11
|
+
result: null;
|
|
12
|
+
error: {
|
|
13
|
+
message: string;
|
|
14
|
+
code: string;
|
|
15
|
+
data: {
|
|
16
|
+
envelope: import("nodemailer/lib/mime-node").Envelope;
|
|
17
|
+
messageId: string;
|
|
18
|
+
accepted: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
19
|
+
rejected: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
20
|
+
pending: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
21
|
+
response: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
result: null;
|
|
26
|
+
error: {
|
|
27
|
+
message: any;
|
|
28
|
+
code: any;
|
|
29
|
+
data: {
|
|
30
|
+
command: any;
|
|
31
|
+
response: any;
|
|
32
|
+
responseCode: any;
|
|
33
|
+
to: string[];
|
|
34
|
+
cc?: string[];
|
|
35
|
+
bcc?: string[];
|
|
36
|
+
from?: string;
|
|
37
|
+
subject: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
html?: string;
|
|
40
|
+
replyTo?: string;
|
|
41
|
+
} | {
|
|
42
|
+
command: any;
|
|
43
|
+
response: any;
|
|
44
|
+
responseCode: any;
|
|
45
|
+
to?: string[];
|
|
46
|
+
cc: string[];
|
|
47
|
+
bcc?: string[];
|
|
48
|
+
from?: string;
|
|
49
|
+
subject: string;
|
|
50
|
+
text?: string;
|
|
51
|
+
html?: string;
|
|
52
|
+
replyTo?: string;
|
|
53
|
+
} | {
|
|
54
|
+
command: any;
|
|
55
|
+
response: any;
|
|
56
|
+
responseCode: any;
|
|
57
|
+
to?: string[];
|
|
58
|
+
cc?: string[];
|
|
59
|
+
bcc: string[];
|
|
60
|
+
from?: string;
|
|
61
|
+
subject: string;
|
|
62
|
+
text?: string;
|
|
63
|
+
html?: string;
|
|
64
|
+
replyTo?: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import nodemailer from "nodemailer";
|
|
2
|
+
class SmtpMailTransport {
|
|
3
|
+
constructor(config){
|
|
4
|
+
this.name = "Mailer/SmtpTransport";
|
|
5
|
+
this.transporter = nodemailer.createTransport(config);
|
|
6
|
+
}
|
|
7
|
+
async send(params) {
|
|
8
|
+
const { replyTo, text, html, to, bcc, cc, from, subject } = params;
|
|
9
|
+
try {
|
|
10
|
+
const result = await this.transporter.sendMail({
|
|
11
|
+
replyTo,
|
|
12
|
+
bcc,
|
|
13
|
+
cc,
|
|
14
|
+
from,
|
|
15
|
+
text,
|
|
16
|
+
html,
|
|
17
|
+
to,
|
|
18
|
+
subject
|
|
19
|
+
});
|
|
20
|
+
if (result.messageId) return {
|
|
21
|
+
result: result.response,
|
|
22
|
+
error: null
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
result: null,
|
|
26
|
+
error: {
|
|
27
|
+
message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
|
|
28
|
+
code: "MAILER_ERROR",
|
|
29
|
+
data: {
|
|
30
|
+
...result
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
return {
|
|
36
|
+
result: null,
|
|
37
|
+
error: {
|
|
38
|
+
message: ex.message,
|
|
39
|
+
code: ex.code,
|
|
40
|
+
data: {
|
|
41
|
+
...params,
|
|
42
|
+
command: ex.command,
|
|
43
|
+
response: ex.response,
|
|
44
|
+
responseCode: ex.responseCode
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export { SmtpMailTransport };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=SmtpMailTransport.js.map
|
|
@@ -0,0 +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 = \"Mailer/SmtpTransport\";\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(config: SMTPTransport.Options) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n // 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: ex.message,\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":["SmtpMailTransport","config","nodemailer","params","replyTo","text","html","to","bcc","cc","from","subject","result","ex"],"mappings":";AAKO,MAAMA;IAIT,YAAYC,MAA6B,CAAE;aAH3B,IAAI,GAAG;QAInB,IAAI,CAAC,WAAW,GAAGC,WAAW,eAAe,CAACD;IAClD;IAEA,MAAM,KAAKE,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;gBAC3CR;gBACAI;gBACAC;gBACAC;gBACAL;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,OAAOC,IAAS;YAKd,OAAO;gBACH,QAAQ;gBACR,OAAO;oBACH,SAASA,GAAG,OAAO;oBACnB,MAAMA,GAAG,IAAI;oBACb,MAAM;wBACF,GAAGV,MAAM;wBACT,SAASU,GAAG,OAAO;wBACnB,UAAUA,GAAG,QAAQ;wBACrB,cAAcA,GAAG,YAAY;oBACjC;gBACJ;YACJ;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import type { TransportSettings } from "../../types.js";
|
|
3
|
+
declare class SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {
|
|
4
|
+
readonly name = "Mailer/SmtpTransport";
|
|
5
|
+
createTransport(settings: TransportSettings): MailTransportFactory.Return;
|
|
6
|
+
}
|
|
7
|
+
export declare const SmtpMailTransportFactory: typeof SmtpMailTransportFactoryImpl & {
|
|
8
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportFactory>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import { SmtpMailTransport } from "./SmtpMailTransport.js";
|
|
3
|
+
import { SmtpConfig } from "./SmtpConfig.js";
|
|
4
|
+
class SmtpMailTransportFactoryImpl {
|
|
5
|
+
async createTransport(settings) {
|
|
6
|
+
return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));
|
|
7
|
+
}
|
|
8
|
+
constructor(){
|
|
9
|
+
this.name = "Mailer/SmtpTransport";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const SmtpMailTransportFactory = MailTransportFactory.createImplementation({
|
|
13
|
+
implementation: SmtpMailTransportFactoryImpl,
|
|
14
|
+
dependencies: []
|
|
15
|
+
});
|
|
16
|
+
export { SmtpMailTransportFactory };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=SmtpMailTransportFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SmtpTransport/SmtpMailTransportFactory.js","sources":["../../../src/features/SmtpTransport/SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n\n async createTransport(settings: TransportSettings): MailTransportFactory.Return {\n return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));\n }\n}\n\nexport const SmtpMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: SmtpMailTransportFactoryImpl,\n dependencies: []\n});\n"],"names":["SmtpMailTransportFactoryImpl","settings","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactory","MailTransportFactory"],"mappings":";;;AAKA,MAAMA;IAGF,MAAM,gBAAgBC,QAA2B,EAA+B;QAC5E,OAAO,IAAIC,kBAAkBC,WAAW,qBAAqB,CAACF;IAClE;;aAJgB,IAAI,GAAG;;AAK3B;AAEO,MAAMG,2BAA2BC,qBAAqB,oBAAoB,CAAC;IAC9E,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SmtpMailTransportFactory } from "./SmtpMailTransportFactory.js";
|
|
3
|
+
const SmtpTransportFeature = createFeature({
|
|
4
|
+
name: "SmtpTransport",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SmtpMailTransportFactory).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { SmtpTransportFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SmtpTransport/feature.js","sources":["../../../src/features/SmtpTransport/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SmtpMailTransportFactory } from \"./SmtpMailTransportFactory.js\";\n\nexport const SmtpTransportFeature = createFeature({\n name: \"SmtpTransport\",\n register(container) {\n container.register(SmtpMailTransportFactory).inSingletonScope();\n }\n});\n"],"names":["SmtpTransportFeature","createFeature","container","SmtpMailTransportFactory"],"mappings":";;AAGO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,0BAA0B,gBAAgB;IACjE;AACJ"}
|
package/graphql/settings.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
|
-
import {
|
|
3
|
-
export declare const createSettingsGraphQL: () => GraphQLSchemaPlugin<
|
|
2
|
+
import type { Context } from "@webiny/api/types.js";
|
|
3
|
+
export declare const createSettingsGraphQL: () => GraphQLSchemaPlugin<Context>;
|
package/graphql/settings.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { ErrorResponse, GraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
|
+
import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
|
|
3
|
+
import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
|
|
4
|
+
import { ActiveTransport } from "../domain/MailTransport/abstractions.js";
|
|
5
|
+
const emptyResolver = ()=>({});
|
|
6
|
+
const toPublicSettings = (settings, source)=>{
|
|
7
|
+
if (!settings) return null;
|
|
8
|
+
const { password: _password, ...publicSettings } = settings;
|
|
9
|
+
return {
|
|
10
|
+
...publicSettings,
|
|
11
|
+
source
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const createSettingsGraphQL = ()=>new GraphQLSchemaPlugin({
|
|
15
|
+
typeDefs: `
|
|
15
16
|
type MailerTransportSettingsError {
|
|
16
17
|
message: String!
|
|
17
18
|
code: String
|
|
18
19
|
data: JSON
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
type MailerTransportSettings {
|
|
22
23
|
host: String
|
|
23
24
|
port: Number
|
|
24
25
|
user: String
|
|
25
26
|
from: String
|
|
26
27
|
replyTo: String
|
|
28
|
+
source: String
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
type
|
|
30
|
+
|
|
31
|
+
type MailerTransportSettingsResponse {
|
|
30
32
|
data: MailerTransportSettings
|
|
31
33
|
error: MailerTransportSettingsError
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
type MailerQuery {
|
|
35
|
-
getSettings:
|
|
37
|
+
getSettings: MailerTransportSettingsResponse!
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
input
|
|
39
|
+
|
|
40
|
+
input MailerTransportSettingsInput {
|
|
39
41
|
host: String!
|
|
40
42
|
port: Number
|
|
41
43
|
user: String!
|
|
@@ -43,11 +45,11 @@ const createSettingsGraphQL = () => {
|
|
|
43
45
|
from: String!
|
|
44
46
|
replyTo: String
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
|
|
47
49
|
type MailerMutation {
|
|
48
|
-
saveSettings(data:
|
|
50
|
+
saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
|
|
51
53
|
extend type Query {
|
|
52
54
|
mailer: MailerQuery
|
|
53
55
|
}
|
|
@@ -55,55 +57,51 @@ const createSettingsGraphQL = () => {
|
|
|
55
57
|
mailer: MailerMutation
|
|
56
58
|
}
|
|
57
59
|
`,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
resolvers: {
|
|
61
|
+
Query: {
|
|
62
|
+
mailer: emptyResolver
|
|
63
|
+
},
|
|
64
|
+
MailerQuery: {
|
|
65
|
+
getSettings: async (_, __, context)=>{
|
|
66
|
+
try {
|
|
67
|
+
const activeTransport = context.container.resolve(ActiveTransport);
|
|
68
|
+
const transportName = activeTransport.name();
|
|
69
|
+
if (!transportName) return {
|
|
70
|
+
data: null,
|
|
71
|
+
error: null
|
|
72
|
+
};
|
|
73
|
+
const getSettings = context.container.resolve(GetSettingsUseCase);
|
|
74
|
+
const result = await getSettings.execute(transportName);
|
|
75
|
+
const { settings, source } = result.value;
|
|
76
|
+
return {
|
|
77
|
+
data: toPublicSettings(settings, source),
|
|
78
|
+
error: null
|
|
79
|
+
};
|
|
80
|
+
} catch (ex) {
|
|
81
|
+
return new ErrorResponse(ex);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
Mutation: {
|
|
86
|
+
mailer: emptyResolver
|
|
87
|
+
},
|
|
88
|
+
MailerMutation: {
|
|
89
|
+
saveSettings: async (_, args, context)=>{
|
|
90
|
+
try {
|
|
91
|
+
const saveSettings = context.container.resolve(SaveSettingsUseCase);
|
|
92
|
+
const result = await saveSettings.execute(args.data);
|
|
93
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
94
|
+
return {
|
|
95
|
+
data: toPublicSettings(result.value, "storage"),
|
|
96
|
+
error: null
|
|
97
|
+
};
|
|
98
|
+
} catch (ex) {
|
|
99
|
+
return new ErrorResponse(ex);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
73
102
|
}
|
|
74
|
-
|
|
75
|
-
return new _handlerGraphql.Response(settings);
|
|
76
|
-
} catch (ex) {
|
|
77
|
-
return new _handlerGraphql.ErrorResponse(ex);
|
|
78
|
-
}
|
|
79
103
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
mailer: emptyResolver
|
|
83
|
-
},
|
|
84
|
-
MailerMutation: {
|
|
85
|
-
saveSettings: async (_, args, context) => {
|
|
86
|
-
try {
|
|
87
|
-
const settings = await context.mailer.saveSettings({
|
|
88
|
-
input: args.data
|
|
89
|
-
});
|
|
90
|
-
/**
|
|
91
|
-
* We want to remove the password from the response
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
if (settings) {
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
delete settings.password;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return new _handlerGraphql.Response(settings);
|
|
100
|
-
} catch (ex) {
|
|
101
|
-
return new _handlerGraphql.ErrorResponse(ex);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
104
|
+
});
|
|
105
|
+
export { createSettingsGraphQL };
|
|
108
106
|
|
|
109
|
-
|
|
107
|
+
//# sourceMappingURL=settings.js.map
|
package/graphql/settings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/settings.js","sources":["../../src/graphql/settings.ts"],"sourcesContent":["import { ErrorResponse, GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\nimport { ActiveTransport } from \"~/domain/MailTransport/abstractions.js\";\nimport type { MailerSettingsSource } from \"~/features/GetSettings/abstractions.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport type { TransportSettings } from \"~/types.js\";\n\nconst emptyResolver = () => ({});\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\nexport const createSettingsGraphQL = () => {\n return new GraphQLSchemaPlugin<Context>({\n typeDefs: `\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n\n type MailerTransportSettings {\n host: String\n port: Number\n user: String\n from: String\n replyTo: String\n 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 user: String!\n password: String\n from: String!\n replyTo: String\n }\n\n type MailerMutation {\n saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!\n }\n\n extend type Query {\n mailer: MailerQuery\n }\n extend type Mutation {\n mailer: MailerMutation\n }\n `,\n resolvers: {\n Query: {\n mailer: emptyResolver\n },\n MailerQuery: {\n getSettings: async (_, __, context) => {\n try {\n const activeTransport = context.container.resolve(ActiveTransport);\n const transportName = activeTransport.name();\n\n if (!transportName) {\n return { data: null, error: null };\n }\n\n const getSettings = context.container.resolve(GetSettingsUseCase);\n const result = await getSettings.execute(transportName);\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 Mutation: {\n mailer: emptyResolver\n },\n MailerMutation: {\n saveSettings: async (_, args: any, context) => {\n try {\n const saveSettings = context.container.resolve(SaveSettingsUseCase);\n const result = await saveSettings.execute(args.data);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return {\n data: toPublicSettings(result.value, \"storage\"),\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n }\n }\n });\n};\n"],"names":["emptyResolver","toPublicSettings","settings","source","_password","publicSettings","createSettingsGraphQL","GraphQLSchemaPlugin","_","__","context","activeTransport","ActiveTransport","transportName","getSettings","GetSettingsUseCase","result","ex","ErrorResponse","args","saveSettings","SaveSettingsUseCase"],"mappings":";;;;AAQA,MAAMA,gBAAgB,IAAO,EAAC;AAO9B,MAAMC,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;AAEO,MAAMG,wBAAwB,IAC1B,IAAIC,oBAA6B;QACpC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA4CX,CAAC;QACD,WAAW;YACP,OAAO;gBACH,QAAQP;YACZ;YACA,aAAa;gBACT,aAAa,OAAOQ,GAAGC,IAAIC;oBACvB,IAAI;wBACA,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,OAAO,CAACE;wBAClD,MAAMC,gBAAgBF,gBAAgB,IAAI;wBAE1C,IAAI,CAACE,eACD,OAAO;4BAAE,MAAM;4BAAM,OAAO;wBAAK;wBAGrC,MAAMC,cAAcJ,QAAQ,SAAS,CAAC,OAAO,CAACK;wBAC9C,MAAMC,SAAS,MAAMF,YAAY,OAAO,CAACD;wBAEzC,MAAM,EAAEX,QAAQ,EAAEC,MAAM,EAAE,GAAGa,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAMf,iBAAiBC,UAAUC;4BACjC,OAAO;wBACX;oBACJ,EAAE,OAAOc,IAAI;wBACT,OAAO,IAAIC,cAAcD;oBAC7B;gBACJ;YACJ;YACA,UAAU;gBACN,QAAQjB;YACZ;YACA,gBAAgB;gBACZ,cAAc,OAAOQ,GAAGW,MAAWT;oBAC/B,IAAI;wBACA,MAAMU,eAAeV,QAAQ,SAAS,CAAC,OAAO,CAACW;wBAC/C,MAAML,SAAS,MAAMI,aAAa,OAAO,CAACD,KAAK,IAAI;wBAEnD,IAAIH,OAAO,MAAM,IACb,OAAO,IAAIE,cAAcF,OAAO,KAAK;wBAGzC,OAAO;4BACH,MAAMf,iBAAiBe,OAAO,KAAK,EAAE;4BACrC,OAAO;wBACX;oBACJ,EAAE,OAAOC,IAAI;wBACT,OAAO,IAAIC,cAAcD;oBAC7B;gBACJ;YACJ;QACJ;IACJ"}
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { createDummyTransport, createSmtpTransport, createTransport };
|
|
6
|
-
export type { SmtpTransport, SmtpTransportConfig, DummyTransport };
|
|
7
|
-
export declare const createMailerContext: () => PluginCollection;
|
|
8
|
-
export declare const createMailerGraphQL: () => import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("./types").MailerContext>[];
|
|
1
|
+
export { MailerService } from "./domain/MailerService/abstractions.js";
|
|
2
|
+
export type { IMailerService, IMailerServiceErrors } from "./domain/MailerService/abstractions.js";
|
|
3
|
+
export declare const createMailerContext: () => import("@webiny/api").ContextPlugin<import("@webiny/api/types.js").Context>;
|
|
4
|
+
export declare const createMailerGraphQL: () => import("@webiny/handler-graphql/index.js").GraphQLSchemaPlugin<import("@webiny/api/types.js").Context>;
|