@webiny/api-mailer 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 +3 -0
- package/constants.js.map +1 -0
- package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +4 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +26 -0
- package/domain/MailTransport/abstractions.js +6 -0
- package/domain/MailTransport/abstractions.js.map +1 -0
- package/domain/MailerService/abstractions.d.ts +19 -0
- package/domain/MailerService/abstractions.js +4 -0
- package/domain/MailerService/abstractions.js.map +1 -0
- package/domain/MailerService/errors.d.ts +16 -0
- package/domain/MailerService/errors.js +30 -0
- package/domain/MailerService/errors.js.map +1 -0
- package/domain/errors.d.ts +28 -0
- package/domain/errors.js +52 -0
- package/domain/errors.js.map +1 -0
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +6 -0
- package/exports/api/mailer.js.map +1 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +22 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +10 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransport.js +12 -0
- package/features/DummyTransport/DummyMailTransport.js.map +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +14 -0
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
- package/features/DummyTransport/feature.d.ts +4 -0
- package/features/DummyTransport/feature.js +10 -0
- package/features/DummyTransport/feature.js.map +1 -0
- package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
- package/features/GetSettings/GetSettingsRepository.js +58 -0
- package/features/GetSettings/GetSettingsRepository.js.map +1 -0
- package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
- package/features/GetSettings/GetSettingsUseCase.js +15 -0
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
- package/features/GetSettings/abstractions.d.ts +22 -0
- package/features/GetSettings/abstractions.js +5 -0
- package/features/GetSettings/abstractions.js.map +1 -0
- package/features/GetSettings/feature.d.ts +4 -0
- package/features/GetSettings/feature.js +12 -0
- package/features/GetSettings/feature.js.map +1 -0
- package/features/GetSettings/index.d.ts +1 -0
- package/features/GetSettings/index.js +3 -0
- package/features/GetSettings/index.js.map +1 -0
- package/features/MailerService/ActiveTransport.d.ts +10 -0
- package/features/MailerService/ActiveTransport.js +20 -0
- package/features/MailerService/ActiveTransport.js.map +1 -0
- package/features/MailerService/MailerService.d.ts +16 -0
- package/features/MailerService/MailerService.js +53 -0
- package/features/MailerService/MailerService.js.map +1 -0
- package/features/MailerService/feature.d.ts +4 -0
- package/features/MailerService/feature.js +12 -0
- package/features/MailerService/feature.js.map +1 -0
- package/features/SaveSettings/SaveSettingsRepository.d.ts +13 -0
- package/features/SaveSettings/SaveSettingsRepository.js +59 -0
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
- package/features/SaveSettings/SaveSettingsUseCase.js +69 -0
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
- package/features/SaveSettings/abstractions.d.ts +61 -0
- package/features/SaveSettings/abstractions.js +20 -0
- package/features/SaveSettings/abstractions.js.map +1 -0
- package/features/SaveSettings/events.d.ts +10 -0
- package/features/SaveSettings/events.js +16 -0
- package/features/SaveSettings/events.js.map +1 -0
- package/features/SaveSettings/feature.d.ts +4 -0
- package/features/SaveSettings/feature.js +12 -0
- package/features/SaveSettings/feature.js.map +1 -0
- package/features/SaveSettings/index.d.ts +1 -0
- package/features/SaveSettings/index.js +3 -0
- package/features/SaveSettings/index.js.map +1 -0
- package/features/SaveSettings/validation.d.ts +9 -0
- package/features/SaveSettings/validation.js +23 -0
- package/features/SaveSettings/validation.js.map +1 -0
- package/features/SendMail/SendMailUseCase.d.ts +16 -0
- package/features/SendMail/SendMailUseCase.js +65 -0
- package/features/SendMail/SendMailUseCase.js.map +1 -0
- package/features/SendMail/abstractions.d.ts +45 -0
- package/features/SendMail/abstractions.js +11 -0
- package/features/SendMail/abstractions.js.map +1 -0
- package/features/SendMail/events.d.ts +14 -0
- package/features/SendMail/events.js +22 -0
- package/features/SendMail/events.js.map +1 -0
- package/features/SendMail/feature.d.ts +4 -0
- package/features/SendMail/feature.js +10 -0
- package/features/SendMail/feature.js.map +1 -0
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +3 -0
- package/features/SendMail/index.js.map +1 -0
- package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
- package/features/SmtpTransport/SmtpConfig.js +29 -0
- package/features/SmtpTransport/SmtpConfig.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +68 -0
- package/features/SmtpTransport/SmtpMailTransport.js +67 -0
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +10 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +15 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
- package/features/SmtpTransport/feature.d.ts +4 -0
- package/features/SmtpTransport/feature.js +10 -0
- package/features/SmtpTransport/feature.js.map +1 -0
- package/graphql/settings.d.ts +2 -2
- package/graphql/settings.js +60 -36
- package/graphql/settings.js.map +1 -1
- package/index.d.ts +4 -5
- package/index.js +22 -78
- package/index.js.map +1 -1
- package/package.json +27 -31
- package/types.d.ts +0 -107
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/isMailboxAddress.d.ts +6 -0
- package/utils/isMailboxAddress.js +12 -0
- package/utils/isMailboxAddress.js.map +1 -0
- package/context.d.ts +0 -3
- package/context.js +0 -20
- package/context.js.map +0 -1
- package/crud/settings/hooks.d.ts +0 -5
- package/crud/settings/hooks.js +0 -42
- package/crud/settings/hooks.js.map +0 -1
- package/crud/settings/model.d.ts +0 -2
- package/crud/settings/model.js +0 -72
- package/crud/settings/model.js.map +0 -1
- package/crud/settings/password.d.ts +0 -7
- package/crud/settings/password.js +0 -55
- package/crud/settings/password.js.map +0 -1
- package/crud/settings/secret.d.ts +0 -1
- package/crud/settings/secret.js +0 -19
- package/crud/settings/secret.js.map +0 -1
- package/crud/settings/transform.d.ts +0 -13
- package/crud/settings/transform.js +0 -46
- package/crud/settings/transform.js.map +0 -1
- package/crud/settings/validation.d.ts +0 -45
- package/crud/settings/validation.js +0 -28
- package/crud/settings/validation.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -5
- package/crud/settings.crud.js +0 -269
- package/crud/settings.crud.js.map +0 -1
- package/crud/transport/onTransportBeforeSend.d.ts +0 -7
- package/crud/transport/onTransportBeforeSend.js +0 -62
- package/crud/transport/onTransportBeforeSend.js.map +0 -1
- package/crud/transporter.crud.d.ts +0 -2
- package/crud/transporter.crud.js +0 -158
- package/crud/transporter.crud.js.map +0 -1
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +0 -13
- package/graphql/index.js.map +0 -1
- package/plugins/CreateTransportPlugin.d.ts +0 -17
- package/plugins/CreateTransportPlugin.js +0 -24
- 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 -13
- package/transports/createSmtpTransport.js +0 -94
- package/transports/createSmtpTransport.js.map +0 -1
- package/transports/index.d.ts +0 -2
- package/transports/index.js +0 -29
- package/transports/index.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { SendMailUseCase } from "./abstractions.js";
|
|
4
|
+
import { MailBeforeSendEvent, MailAfterSendEvent, MailSendErrorEvent } from "./events.js";
|
|
5
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
6
|
+
import { MailValidationError } from "../../domain/errors.js";
|
|
7
|
+
import { Result } from "@webiny/feature/api";
|
|
8
|
+
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
9
|
+
const requiredString = zod.string();
|
|
10
|
+
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
11
|
+
message: "Invalid email address."
|
|
12
|
+
});
|
|
13
|
+
const schema = zod.object({
|
|
14
|
+
to: zod.array(mailboxAddress).optional(),
|
|
15
|
+
from: mailboxAddress.optional(),
|
|
16
|
+
subject: requiredString.max(1024).min(2),
|
|
17
|
+
cc: zod.array(mailboxAddress).optional(),
|
|
18
|
+
bcc: zod.array(mailboxAddress).optional(),
|
|
19
|
+
replyTo: mailboxAddress.optional(),
|
|
20
|
+
text: zod.string().optional(),
|
|
21
|
+
html: zod.string().optional()
|
|
22
|
+
}).refine(data => {
|
|
23
|
+
return !!data.text || !!data.html;
|
|
24
|
+
}, "Either text or html is required.");
|
|
25
|
+
class SendMailUseCaseImpl {
|
|
26
|
+
constructor(mailerService, eventPublisher) {
|
|
27
|
+
this.mailerService = mailerService;
|
|
28
|
+
this.eventPublisher = eventPublisher;
|
|
29
|
+
}
|
|
30
|
+
async execute(data) {
|
|
31
|
+
const validation = schema.safeParse(data);
|
|
32
|
+
if (!validation.success) {
|
|
33
|
+
return Result.fail(new MailValidationError(validation.error.issues));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Publish before send event
|
|
37
|
+
await this.eventPublisher.publish(new MailBeforeSendEvent({
|
|
38
|
+
data
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// Send mail
|
|
42
|
+
const result = await this.mailerService.sendMail(data);
|
|
43
|
+
if (result.isFail()) {
|
|
44
|
+
// Publish error event
|
|
45
|
+
await this.eventPublisher.publish(new MailSendErrorEvent({
|
|
46
|
+
data,
|
|
47
|
+
error: result.error
|
|
48
|
+
}));
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Publish after send event
|
|
53
|
+
await this.eventPublisher.publish(new MailAfterSendEvent({
|
|
54
|
+
data,
|
|
55
|
+
response: result.value
|
|
56
|
+
}));
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({
|
|
61
|
+
implementation: SendMailUseCaseImpl,
|
|
62
|
+
dependencies: [MailerService, EventPublisher]
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=SendMailUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["zod","EventPublisher","SendMailUseCase","MailBeforeSendEvent","MailAfterSendEvent","MailSendErrorEvent","MailerService","MailValidationError","Result","isMailboxAddress","requiredString","string","mailboxAddress","refine","message","schema","object","to","array","optional","from","subject","max","min","cc","bcc","replyTo","text","html","data","SendMailUseCaseImpl","constructor","mailerService","eventPublisher","execute","validation","safeParse","success","fail","error","issues","publish","result","sendMail","isFail","response","value","SendMailUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["SendMailUseCase.ts"],"sourcesContent":["import zod from \"zod\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { SendMailUseCase } from \"./abstractions.js\";\nimport { MailBeforeSendEvent, MailAfterSendEvent, MailSendErrorEvent } from \"./events.js\";\nimport { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst requiredString = zod.string();\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst schema = zod\n .object({\n to: zod.array(mailboxAddress).optional(),\n from: mailboxAddress.optional(),\n subject: requiredString.max(1024).min(2),\n cc: zod.array(mailboxAddress).optional(),\n bcc: zod.array(mailboxAddress).optional(),\n replyTo: mailboxAddress.optional(),\n text: zod.string().optional(),\n html: zod.string().optional()\n })\n .refine(data => {\n return !!data.text || !!data.html;\n }, \"Either text or html is required.\");\n\nclass SendMailUseCaseImpl implements SendMailUseCase.Interface {\n constructor(\n private mailerService: MailerService.Interface,\n private eventPublisher: EventPublisherAbstraction.Interface\n ) {}\n\n async execute(data: TransportSendData) {\n const validation = schema.safeParse(data);\n if (!validation.success) {\n return Result.fail(new MailValidationError(validation.error.issues));\n }\n\n // Publish before send event\n await this.eventPublisher.publish(new MailBeforeSendEvent({ data }));\n\n // Send mail\n const result = await this.mailerService.sendMail(data);\n\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new MailSendErrorEvent({\n data,\n error: result.error\n })\n );\n\n return result;\n }\n\n // Publish after send event\n await this.eventPublisher.publish(\n new MailAfterSendEvent({\n data,\n response: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({\n implementation: SendMailUseCaseImpl,\n dependencies: [MailerService, EventPublisher]\n});\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
export const SendMailUseCase = createAbstraction("SendMail");
|
|
3
|
+
|
|
4
|
+
// Domain Events
|
|
5
|
+
|
|
6
|
+
// Event Handler Abstractions
|
|
7
|
+
export const MailBeforeSendEventHandler = createAbstraction("MailBeforeSendEventHandler");
|
|
8
|
+
export const MailAfterSendEventHandler = createAbstraction("MailAfterSendEventHandler");
|
|
9
|
+
export const MailSendErrorEventHandler = createAbstraction("MailSendErrorEventHandler");
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","SendMailUseCase","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAkBvD,OAAO,MAAMC,eAAe,GAAGD,iBAAiB,CAAmB,UAAU,CAAC;;AAO9E;;AAeA;AACA,OAAO,MAAME,0BAA0B,GAAGF,iBAAiB,CAEzD,4BAA4B,CAAC;AAO/B,OAAO,MAAMG,yBAAyB,GAAGH,iBAAiB,CAExD,2BAA2B,CAAC;AAO9B,OAAO,MAAMI,yBAAyB,GAAGJ,iBAAiB,CAExD,2BAA2B,CAAC","ignoreList":[]}
|
|
@@ -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,22 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { MailBeforeSendEventHandler, MailAfterSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
3
|
+
export class MailBeforeSendEvent extends DomainEvent {
|
|
4
|
+
eventType = "mailer.mail.beforeSend";
|
|
5
|
+
getHandlerAbstraction() {
|
|
6
|
+
return MailBeforeSendEventHandler;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class MailAfterSendEvent extends DomainEvent {
|
|
10
|
+
eventType = "mailer.mail.afterSend";
|
|
11
|
+
getHandlerAbstraction() {
|
|
12
|
+
return MailAfterSendEventHandler;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class MailSendErrorEvent extends DomainEvent {
|
|
16
|
+
eventType = "mailer.mail.sendError";
|
|
17
|
+
getHandlerAbstraction() {
|
|
18
|
+
return MailSendErrorEventHandler;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DomainEvent","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler","MailBeforeSendEvent","eventType","getHandlerAbstraction","MailAfterSendEvent","MailSendErrorEvent"],"sources":["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"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SACIC,0BAA0B,EAC1BC,yBAAyB,EACzBC,yBAAyB;AAQ7B,OAAO,MAAMC,mBAAmB,SAASJ,WAAW,CAAwB;EACxEK,SAAS,GAAG,wBAAwB;EAEpCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOL,0BAA0B;EACrC;AACJ;AAEA,OAAO,MAAMM,kBAAkB,SAASP,WAAW,CAAuB;EACtEK,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOJ,yBAAyB;EACpC;AACJ;AAEA,OAAO,MAAMM,kBAAkB,SAASR,WAAW,CAAuB;EACtEK,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,yBAAyB;EACpC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SendMailUseCaseImplementation } from "./SendMailUseCase.js";
|
|
3
|
+
export const SendMailFeature = createFeature({
|
|
4
|
+
name: "SendMail",
|
|
5
|
+
register(container) {
|
|
6
|
+
container.register(SendMailUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","SendMailUseCaseImplementation","SendMailFeature","name","register","container"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,6BAA6B;AAEtC,OAAO,MAAMC,eAAe,GAAGF,aAAa,CAAC;EACzCG,IAAI,EAAE,UAAU;EAChBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,6BAA6B,CAAC;EACrD;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SendMailUseCase, MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SendMailUseCase","MailAfterSendEventHandler","MailBeforeSendEventHandler","MailSendErrorEventHandler"],"sources":["index.ts"],"sourcesContent":["export {\n SendMailUseCase,\n MailAfterSendEventHandler,\n MailBeforeSendEventHandler,\n MailSendErrorEventHandler\n} from \"./abstractions.js\";\n"],"mappings":"AAAA,SACIA,eAAe,EACfC,yBAAyB,EACzBC,0BAA0B,EAC1BC,yBAAyB","ignoreList":[]}
|
|
@@ -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,29 @@
|
|
|
1
|
+
const configDefaults = {
|
|
2
|
+
socketTimeout: 15000,
|
|
3
|
+
connectionTimeout: 15000,
|
|
4
|
+
greetingTimeout: 15000
|
|
5
|
+
};
|
|
6
|
+
export 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
|
+
|
|
17
|
+
// Apply defaults
|
|
18
|
+
return Object.keys(configDefaults).reduce((config, key) => {
|
|
19
|
+
const configKey = key;
|
|
20
|
+
if (config[configKey] === undefined || config[configKey] === null) {
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
config[configKey] = configDefaults[configKey];
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
}, baseConfig);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=SmtpConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["configDefaults","socketTimeout","connectionTimeout","greetingTimeout","SmtpConfig","fromTransportSettings","settings","baseConfig","host","port","auth","user","pass","password","Object","keys","reduce","config","key","configKey","undefined"],"sources":["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"],"mappings":"AAKA,MAAMA,cAA4C,GAAG;EACjDC,aAAa,EAAE,KAAK;EACpBC,iBAAiB,EAAE,KAAK;EACxBC,eAAe,EAAE;AACrB,CAAC;AAED,OAAO,MAAMC,UAAU,CAAC;EACpB,OAAOC,qBAAqBA,CAACC,QAA2B,EAAuB;IAC3E,MAAMC,UAA+B,GAAG;MACpCC,IAAI,EAAEF,QAAQ,CAACE,IAAI;MACnBC,IAAI,EAAEH,QAAQ,CAACG,IAAI;MACnBC,IAAI,EAAE;QACFC,IAAI,EAAEL,QAAQ,CAACK,IAAI;QACnBC,IAAI,EAAEN,QAAQ,CAACO;MACnB;IACJ,CAAC;;IAED;IACA,OAAOC,MAAM,CAACC,IAAI,CAACf,cAAc,CAAC,CAACgB,MAAM,CAAsB,CAACC,MAAM,EAAEC,GAAG,KAAK;MAC5E,MAAMC,SAAS,GAAGD,GAAgC;MAClD,IAAID,MAAM,CAACE,SAAS,CAAC,KAAKC,SAAS,IAAIH,MAAM,CAACE,SAAS,CAAC,KAAK,IAAI,EAAE;QAC/D;QACAF,MAAM,CAACE,SAAS,CAAC,GAAGnB,cAAc,CAACmB,SAAS,CAAC;MACjD;MACA,OAAOF,MAAM;IACjB,CAAC,EAAEV,UAAU,CAAC;EAClB;AACJ","ignoreList":[]}
|
|
@@ -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,67 @@
|
|
|
1
|
+
import nodemailer from "nodemailer";
|
|
2
|
+
export class SmtpMailTransport {
|
|
3
|
+
name = "Mailer/SmtpTransport";
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.transporter = nodemailer.createTransport(config);
|
|
6
|
+
}
|
|
7
|
+
async send(params) {
|
|
8
|
+
const {
|
|
9
|
+
replyTo,
|
|
10
|
+
text,
|
|
11
|
+
html,
|
|
12
|
+
to,
|
|
13
|
+
bcc,
|
|
14
|
+
cc,
|
|
15
|
+
from,
|
|
16
|
+
subject
|
|
17
|
+
} = params;
|
|
18
|
+
try {
|
|
19
|
+
const result = await this.transporter.sendMail({
|
|
20
|
+
replyTo,
|
|
21
|
+
bcc,
|
|
22
|
+
cc,
|
|
23
|
+
from,
|
|
24
|
+
text,
|
|
25
|
+
html,
|
|
26
|
+
to,
|
|
27
|
+
subject
|
|
28
|
+
});
|
|
29
|
+
if (result.messageId) {
|
|
30
|
+
return {
|
|
31
|
+
result: result.response,
|
|
32
|
+
error: null
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
result: null,
|
|
37
|
+
error: {
|
|
38
|
+
message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
|
|
39
|
+
code: "MAILER_ERROR",
|
|
40
|
+
data: {
|
|
41
|
+
...result
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
} catch (ex) {
|
|
46
|
+
// Allow-list specific nodemailer/SMTP error fields. Spreading `ex`
|
|
47
|
+
// or `ex.data` blindly would risk surfacing the transporter's auth
|
|
48
|
+
// config (or anything else a future nodemailer version stamps onto
|
|
49
|
+
// its errors) in error responses.
|
|
50
|
+
return {
|
|
51
|
+
result: null,
|
|
52
|
+
error: {
|
|
53
|
+
message: ex.message,
|
|
54
|
+
code: ex.code,
|
|
55
|
+
data: {
|
|
56
|
+
...params,
|
|
57
|
+
command: ex.command,
|
|
58
|
+
response: ex.response,
|
|
59
|
+
responseCode: ex.responseCode
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=SmtpMailTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["nodemailer","SmtpMailTransport","name","constructor","config","transporter","createTransport","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","response","error","message","code","data","ex","command","responseCode"],"sources":["SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(config: SMTPTransport.Options) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n // 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"],"mappings":"AACA,OAAOA,UAAU,MAAM,YAAY;AAInC,OAAO,MAAMC,iBAAiB,CAAoC;EAC9CC,IAAI,GAAG,sBAAsB;EAG7CC,WAAWA,CAACC,MAA6B,EAAE;IACvC,IAAI,CAACC,WAAW,GAAGL,UAAU,CAACM,eAAe,CAACF,MAAM,CAAC;EACzD;EAEA,MAAMG,IAAIA,CAACC,MAAgC,EAAE;IACzC,MAAM;MAAEC,OAAO;MAAEC,IAAI;MAAEC,IAAI;MAAEC,EAAE;MAAEC,GAAG;MAAEC,EAAE;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGR,MAAM;IAElE,IAAI;MACA,MAAMS,MAAM,GAAG,MAAM,IAAI,CAACZ,WAAW,CAACa,QAAQ,CAAC;QAC3CT,OAAO;QACPI,GAAG;QACHC,EAAE;QACFC,IAAI;QACJL,IAAI;QACJC,IAAI;QACJC,EAAE;QACFI;MACJ,CAAC,CAAC;MAEF,IAAIC,MAAM,CAACE,SAAS,EAAE;QAClB,OAAO;UACHF,MAAM,EAAEA,MAAM,CAACG,QAAQ;UACvBC,KAAK,EAAE;QACX,CAAC;MACL;MAEA,OAAO;QACHJ,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EACH,sFAAsF;UAC1FC,IAAI,EAAE,cAAc;UACpBC,IAAI,EAAE;YACF,GAAGP;UACP;QACJ;MACJ,CAAC;IACL,CAAC,CAAC,OAAOQ,EAAO,EAAE;MACd;MACA;MACA;MACA;MACA,OAAO;QACHR,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EAAEG,EAAE,CAACH,OAAO;UACnBC,IAAI,EAAEE,EAAE,CAACF,IAAI;UACbC,IAAI,EAAE;YACF,GAAGhB,MAAM;YACTkB,OAAO,EAAED,EAAE,CAACC,OAAO;YACnBN,QAAQ,EAAEK,EAAE,CAACL,QAAQ;YACrBO,YAAY,EAAEF,EAAE,CAACE;UACrB;QACJ;MACJ,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
|
|
@@ -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,15 @@
|
|
|
1
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import { SmtpMailTransport } from "./SmtpMailTransport.js";
|
|
3
|
+
import { SmtpConfig } from "./SmtpConfig.js";
|
|
4
|
+
class SmtpMailTransportFactoryImpl {
|
|
5
|
+
name = "Mailer/SmtpTransport";
|
|
6
|
+
async createTransport(settings) {
|
|
7
|
+
return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const SmtpMailTransportFactory = MailTransportFactory.createImplementation({
|
|
11
|
+
implementation: SmtpMailTransportFactoryImpl,
|
|
12
|
+
dependencies: []
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=SmtpMailTransportFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MailTransportFactory","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactoryImpl","name","createTransport","settings","fromTransportSettings","SmtpMailTransportFactory","createImplementation","implementation","dependencies"],"sources":["SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n 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"],"mappings":"AAAA,SAASA,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAEnB,MAAMC,4BAA4B,CAA2C;EACzDC,IAAI,GAAG,sBAAsB;EAE7C,MAAMC,eAAeA,CAACC,QAA2B,EAA+B;IAC5E,OAAO,IAAIL,iBAAiB,CAACC,UAAU,CAACK,qBAAqB,CAACD,QAAQ,CAAC,CAAC;EAC5E;AACJ;AAEA,OAAO,MAAME,wBAAwB,GAAGR,oBAAoB,CAACS,oBAAoB,CAAC;EAC9EC,cAAc,EAAEP,4BAA4B;EAC5CQ,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SmtpMailTransportFactory } from "./SmtpMailTransportFactory.js";
|
|
3
|
+
export const SmtpTransportFeature = createFeature({
|
|
4
|
+
name: "SmtpTransport",
|
|
5
|
+
register(container) {
|
|
6
|
+
container.register(SmtpMailTransportFactory).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","SmtpMailTransportFactory","SmtpTransportFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SmtpMailTransportFactory } from \"./SmtpMailTransportFactory.js\";\n\nexport const SmtpTransportFeature = createFeature({\n name: \"SmtpTransport\",\n register(container) {\n container.register(SmtpMailTransportFactory).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,wBAAwB;AAEjC,OAAO,MAAMC,oBAAoB,GAAGF,aAAa,CAAC;EAC9CG,IAAI,EAAE,eAAe;EACrBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,wBAAwB,CAAC,CAACK,gBAAgB,CAAC,CAAC;EACnE;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/graphql/settings.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
|
-
import type {
|
|
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,37 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.createSettingsGraphQL = void 0;
|
|
7
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
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";
|
|
8
5
|
const emptyResolver = () => ({});
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
|
|
7
|
+
// Strip `password` before the settings leave the server and tack on `source`
|
|
8
|
+
// so the admin UI can branch on code-vs-storage. Accepts both the full
|
|
9
|
+
// `TransportSettings` (from getSettings) and the already-stripped
|
|
10
|
+
// `Omit<TransportSettings, "password">` (from saveSettings) — defense in depth
|
|
11
|
+
// even when the input type carries no password to begin with.
|
|
12
|
+
const toPublicSettings = (settings, source) => {
|
|
13
|
+
if (!settings) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
const {
|
|
18
|
+
password: _password,
|
|
19
|
+
...publicSettings
|
|
20
|
+
} = settings;
|
|
21
|
+
return {
|
|
22
|
+
...publicSettings,
|
|
23
|
+
source
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const createSettingsGraphQL = () => {
|
|
27
|
+
return new GraphQLSchemaPlugin({
|
|
11
28
|
typeDefs: `
|
|
12
29
|
type MailerTransportSettingsError {
|
|
13
30
|
message: String!
|
|
14
31
|
code: String
|
|
15
32
|
data: JSON
|
|
16
33
|
}
|
|
17
|
-
|
|
34
|
+
|
|
18
35
|
type MailerTransportSettings {
|
|
19
36
|
host: String
|
|
20
37
|
port: Number
|
|
21
38
|
user: String
|
|
22
39
|
from: String
|
|
23
40
|
replyTo: String
|
|
41
|
+
source: String
|
|
24
42
|
}
|
|
25
|
-
|
|
43
|
+
|
|
26
44
|
type MailerTransportSettingsResponse {
|
|
27
45
|
data: MailerTransportSettings
|
|
28
46
|
error: MailerTransportSettingsError
|
|
29
47
|
}
|
|
30
|
-
|
|
48
|
+
|
|
31
49
|
type MailerQuery {
|
|
32
50
|
getSettings: MailerTransportSettingsResponse!
|
|
33
51
|
}
|
|
34
|
-
|
|
52
|
+
|
|
35
53
|
input MailerTransportSettingsInput {
|
|
36
54
|
host: String!
|
|
37
55
|
port: Number
|
|
@@ -40,11 +58,11 @@ const createSettingsGraphQL = () => {
|
|
|
40
58
|
from: String!
|
|
41
59
|
replyTo: String
|
|
42
60
|
}
|
|
43
|
-
|
|
61
|
+
|
|
44
62
|
type MailerMutation {
|
|
45
63
|
saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!
|
|
46
64
|
}
|
|
47
|
-
|
|
65
|
+
|
|
48
66
|
extend type Query {
|
|
49
67
|
mailer: MailerQuery
|
|
50
68
|
}
|
|
@@ -59,17 +77,26 @@ const createSettingsGraphQL = () => {
|
|
|
59
77
|
MailerQuery: {
|
|
60
78
|
getSettings: async (_, __, context) => {
|
|
61
79
|
try {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
const activeTransport = context.container.resolve(ActiveTransport);
|
|
81
|
+
const transportName = activeTransport.name();
|
|
82
|
+
if (!transportName) {
|
|
83
|
+
return {
|
|
84
|
+
data: null,
|
|
85
|
+
error: null
|
|
86
|
+
};
|
|
69
87
|
}
|
|
70
|
-
|
|
88
|
+
const getSettings = context.container.resolve(GetSettingsUseCase);
|
|
89
|
+
const result = await getSettings.execute(transportName);
|
|
90
|
+
const {
|
|
91
|
+
settings,
|
|
92
|
+
source
|
|
93
|
+
} = result.value;
|
|
94
|
+
return {
|
|
95
|
+
data: toPublicSettings(settings, source),
|
|
96
|
+
error: null
|
|
97
|
+
};
|
|
71
98
|
} catch (ex) {
|
|
72
|
-
return new
|
|
99
|
+
return new ErrorResponse(ex);
|
|
73
100
|
}
|
|
74
101
|
}
|
|
75
102
|
},
|
|
@@ -79,25 +106,22 @@ const createSettingsGraphQL = () => {
|
|
|
79
106
|
MailerMutation: {
|
|
80
107
|
saveSettings: async (_, args, context) => {
|
|
81
108
|
try {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* We want to remove the password from the response, if it exists.
|
|
87
|
-
*/
|
|
88
|
-
if (settings?.password) {
|
|
89
|
-
// @ts-expect-error
|
|
90
|
-
delete settings.password;
|
|
109
|
+
const saveSettings = context.container.resolve(SaveSettingsUseCase);
|
|
110
|
+
const result = await saveSettings.execute(args.data);
|
|
111
|
+
if (result.isFail()) {
|
|
112
|
+
return new ErrorResponse(result.error);
|
|
91
113
|
}
|
|
92
|
-
return
|
|
114
|
+
return {
|
|
115
|
+
data: toPublicSettings(result.value, "storage"),
|
|
116
|
+
error: null
|
|
117
|
+
};
|
|
93
118
|
} catch (ex) {
|
|
94
|
-
return new
|
|
119
|
+
return new ErrorResponse(ex);
|
|
95
120
|
}
|
|
96
121
|
}
|
|
97
122
|
}
|
|
98
123
|
}
|
|
99
124
|
});
|
|
100
125
|
};
|
|
101
|
-
exports.createSettingsGraphQL = createSettingsGraphQL;
|
|
102
126
|
|
|
103
127
|
//# sourceMappingURL=settings.js.map
|