@webiny/api-mailer 6.3.0 → 6.4.0-beta.0
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/constants.js +2 -1
- package/constants.js.map +1 -1
- package/domain/CodeMailerSettings/abstractions.js +2 -1
- package/domain/CodeMailerSettings/abstractions.js.map +1 -1
- package/domain/MailTransport/abstractions.js +4 -3
- package/domain/MailTransport/abstractions.js.map +1 -1
- package/domain/MailerService/abstractions.js +2 -1
- package/domain/MailerService/abstractions.js.map +1 -1
- package/domain/MailerService/errors.js +22 -24
- package/domain/MailerService/errors.js.map +1 -1
- package/domain/errors.js +40 -44
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.js +3 -5
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +14 -13
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -1
- package/features/CodeMailerSettings/feature.js +6 -5
- package/features/CodeMailerSettings/feature.js.map +1 -1
- package/features/DummyTransport/DummyMailTransport.js +11 -9
- package/features/DummyTransport/DummyMailTransport.js.map +1 -1
- package/features/DummyTransport/DummyMailTransportFactory.js +10 -7
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -1
- package/features/DummyTransport/feature.js +6 -5
- package/features/DummyTransport/feature.js.map +1 -1
- package/features/GetSettings/GetSettingsRepository.js +41 -45
- package/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/features/GetSettings/GetSettingsUseCase.js +13 -10
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/GetSettings/abstractions.js +3 -2
- package/features/GetSettings/abstractions.js.map +1 -1
- package/features/GetSettings/feature.js +7 -6
- package/features/GetSettings/feature.js.map +1 -1
- package/features/GetSettings/index.js +1 -3
- package/features/MailerService/ActiveTransport.js +18 -14
- package/features/MailerService/ActiveTransport.js.map +1 -1
- package/features/MailerService/MailerService.js +38 -42
- package/features/MailerService/MailerService.js.map +1 -1
- package/features/MailerService/feature.js +7 -6
- package/features/MailerService/feature.js.map +1 -1
- package/features/SaveSettings/SaveSettingsRepository.js +29 -45
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -1
- package/features/SaveSettings/SaveSettingsUseCase.js +38 -56
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
- package/features/SaveSettings/abstractions.js +5 -17
- package/features/SaveSettings/abstractions.js.map +1 -1
- package/features/SaveSettings/events.js +16 -11
- package/features/SaveSettings/events.js.map +1 -1
- package/features/SaveSettings/feature.js +7 -6
- package/features/SaveSettings/feature.js.map +1 -1
- package/features/SaveSettings/index.js +1 -3
- package/features/SaveSettings/validation.d.ts +1 -1
- package/features/SaveSettings/validation.js +11 -14
- package/features/SaveSettings/validation.js.map +1 -1
- package/features/SendMail/SendMailUseCase.js +40 -47
- package/features/SendMail/SendMailUseCase.js.map +1 -1
- package/features/SendMail/abstractions.js +5 -8
- package/features/SendMail/abstractions.js.map +1 -1
- package/features/SendMail/events.js +23 -16
- package/features/SendMail/events.js.map +1 -1
- package/features/SendMail/feature.js +6 -5
- package/features/SendMail/feature.js.map +1 -1
- package/features/SendMail/index.js +1 -3
- package/features/SmtpTransport/SmtpConfig.js +20 -24
- package/features/SmtpTransport/SmtpConfig.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransport.js +47 -61
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.js +10 -7
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -1
- package/features/SmtpTransport/feature.js +6 -5
- package/features/SmtpTransport/feature.js.map +1 -1
- package/graphql/settings.js +54 -74
- package/graphql/settings.js.map +1 -1
- package/index.js +11 -15
- package/index.js.map +1 -1
- package/package.json +17 -17
- package/types.js +0 -3
- package/utils/isMailboxAddress.js +3 -10
- package/utils/isMailboxAddress.js.map +1 -1
- package/exports/api/mailer.js.map +0 -1
- package/features/GetSettings/index.js.map +0 -1
- package/features/SaveSettings/index.js.map +0 -1
- package/features/SendMail/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
3
|
+
class MailerSettingsBeforeSaveEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return MailerSettingsBeforeSaveEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "mailer.settings.beforeSave";
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
class MailerSettingsAfterSaveEvent extends DomainEvent {
|
|
12
|
+
getHandlerAbstraction() {
|
|
13
|
+
return MailerSettingsAfterSaveEventHandler;
|
|
14
|
+
}
|
|
15
|
+
constructor(...args){
|
|
16
|
+
super(...args), this.eventType = "mailer.settings.afterSave";
|
|
17
|
+
}
|
|
14
18
|
}
|
|
19
|
+
export { MailerSettingsAfterSaveEvent, MailerSettingsBeforeSaveEvent };
|
|
15
20
|
|
|
16
21
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/events.js","sources":["../../../src/features/SaveSettings/events.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n MailerSettingsBeforeSaveEventHandler,\n MailerSettingsAfterSaveEventHandler\n} from \"./abstractions.js\";\nimport type {\n MailerSettingsBeforeSavePayload,\n MailerSettingsAfterSavePayload\n} from \"./abstractions.js\";\n\nexport class MailerSettingsBeforeSaveEvent extends DomainEvent<MailerSettingsBeforeSavePayload> {\n eventType = \"mailer.settings.beforeSave\" as const;\n\n getHandlerAbstraction() {\n return MailerSettingsBeforeSaveEventHandler;\n }\n}\n\nexport class MailerSettingsAfterSaveEvent extends DomainEvent<MailerSettingsAfterSavePayload> {\n eventType = \"mailer.settings.afterSave\" as const;\n\n getHandlerAbstraction() {\n return MailerSettingsAfterSaveEventHandler;\n }\n}\n"],"names":["MailerSettingsBeforeSaveEvent","DomainEvent","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEvent","MailerSettingsAfterSaveEventHandler"],"mappings":";;AAUO,MAAMA,sCAAsCC;IAG/C,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMC,qCAAqCF;IAG9C,wBAAwB;QACpB,OAAOG;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { SaveSettingsRepositoryImplementation } from "./SaveSettingsRepository.js";
|
|
3
3
|
import { SaveSettingsUseCaseImplementation } from "./SaveSettingsUseCase.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const SaveSettingsFeature = createFeature({
|
|
5
|
+
name: "SaveSettings",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(SaveSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(SaveSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
10
|
});
|
|
11
|
+
export { SaveSettingsFeature };
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/feature.js","sources":["../../../src/features/SaveSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SaveSettingsRepositoryImplementation } from \"./SaveSettingsRepository.js\";\nimport { SaveSettingsUseCaseImplementation } from \"./SaveSettingsUseCase.js\";\n\nexport const SaveSettingsFeature = createFeature({\n name: \"SaveSettings\",\n register(container) {\n container.register(SaveSettingsRepositoryImplementation).inSingletonScope();\n container.register(SaveSettingsUseCaseImplementation);\n }\n});\n"],"names":["SaveSettingsFeature","createFeature","container","SaveSettingsRepositoryImplementation","SaveSettingsUseCaseImplementation"],"mappings":";;;AAIO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sCAAsC,gBAAgB;QACzED,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "./abstractions.js";
|
|
@@ -3,7 +3,7 @@ export declare const saveValidation: zod.ZodObject<{
|
|
|
3
3
|
password: zod.ZodPipe<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodString>>>, zod.ZodTransform<string | null, string | null | undefined>>;
|
|
4
4
|
from: zod.ZodString;
|
|
5
5
|
port: zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodNumber>>>;
|
|
6
|
-
replyTo: zod.
|
|
6
|
+
replyTo: zod.ZodPreprocess<zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodString>>>>;
|
|
7
7
|
host: zod.ZodString;
|
|
8
8
|
user: zod.ZodString;
|
|
9
9
|
}, zod.core.$strip>;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
2
|
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
3
|
-
const
|
|
3
|
+
const validation_password = zod.string().describe("Password");
|
|
4
4
|
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
5
|
-
|
|
5
|
+
message: "Invalid email address."
|
|
6
6
|
});
|
|
7
7
|
const common = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
host: zod.string().describe("Hostname"),
|
|
14
|
-
user: zod.string().describe("User")
|
|
8
|
+
from: mailboxAddress.describe("Mail from"),
|
|
9
|
+
port: zod.number().optional().nullish().describe("Port"),
|
|
10
|
+
replyTo: zod.preprocess((value)=>"" === value ? null : value, mailboxAddress.optional().nullish()).describe("Mail reply-to"),
|
|
11
|
+
host: zod.string().describe("Hostname"),
|
|
12
|
+
user: zod.string().describe("User")
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return value === undefined ? null : value;
|
|
20
|
-
})
|
|
14
|
+
const saveValidation = zod.object({
|
|
15
|
+
...common,
|
|
16
|
+
password: validation_password.nullish().optional().transform((value)=>void 0 === value ? null : value)
|
|
21
17
|
});
|
|
18
|
+
export { saveValidation };
|
|
22
19
|
|
|
23
20
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/validation.js","sources":["../../../src/features/SaveSettings/validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst password = zod.string().describe(\"Password\");\n\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst common = {\n from: mailboxAddress.describe(\"Mail from\"),\n port: zod.number().optional().nullish().describe(\"Port\"),\n replyTo: zod\n .preprocess(\n // We need to set empty strings to `null` before address validation kicks in.\n value => (value === \"\" ? null : value),\n mailboxAddress.optional().nullish()\n )\n .describe(\"Mail reply-to\"),\n host: zod.string().describe(\"Hostname\"),\n user: zod.string().describe(\"User\")\n};\n\nexport const saveValidation = zod.object({\n ...common,\n password: password\n .nullish()\n .optional()\n .transform(value => {\n return value === undefined ? null : value;\n })\n});\n"],"names":["password","zod","mailboxAddress","isMailboxAddress","common","value","saveValidation","undefined"],"mappings":";;AAGA,MAAMA,sBAAWC,IAAI,MAAM,GAAG,QAAQ,CAAC;AAEvC,MAAMC,iBAAiBD,IAAI,MAAM,GAAG,MAAM,CAACE,kBAAkB;IAAE,SAAS;AAAyB;AAEjG,MAAMC,SAAS;IACX,MAAMF,eAAe,QAAQ,CAAC;IAC9B,MAAMD,IAAI,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACjD,SAASA,IAAAA,UACM,CAEPI,CAAAA,QAAUA,AAAU,OAAVA,QAAe,OAAOA,OAChCH,eAAe,QAAQ,GAAG,OAAO,IAEpC,QAAQ,CAAC;IACd,MAAMD,IAAI,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,IAAI,MAAM,GAAG,QAAQ,CAAC;AAChC;AAEO,MAAMK,iBAAiBL,IAAI,MAAM,CAAC;IACrC,GAAGG,MAAM;IACT,UAAUJ,oBACL,OAAO,GACP,QAAQ,GACR,SAAS,CAACK,CAAAA,QACAA,AAAUE,WAAVF,QAAsB,OAAOA;AAEhD"}
|
|
@@ -1,65 +1,58 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
2
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { SendMailUseCase } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { MailAfterSendEvent, MailBeforeSendEvent, MailSendErrorEvent } from "./events.js";
|
|
5
5
|
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
6
6
|
import { MailValidationError } from "../../domain/errors.js";
|
|
7
7
|
import { Result } from "@webiny/feature/api";
|
|
8
8
|
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
9
9
|
const requiredString = zod.string();
|
|
10
10
|
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
11
|
-
|
|
11
|
+
message: "Invalid email address."
|
|
12
12
|
});
|
|
13
13
|
const schema = zod.object({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}).refine(data
|
|
23
|
-
return !!data.text || !!data.html;
|
|
24
|
-
}, "Either text or html is required.");
|
|
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)=>!!data.text || !!data.html, "Either text or html is required.");
|
|
25
23
|
class SendMailUseCaseImpl {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
async execute(data) {
|
|
31
|
-
const validation = schema.safeParse(data);
|
|
32
|
-
if (!validation.success) {
|
|
33
|
-
return Result.fail(new MailValidationError(validation.error.issues));
|
|
24
|
+
constructor(mailerService, eventPublisher){
|
|
25
|
+
this.mailerService = mailerService;
|
|
26
|
+
this.eventPublisher = eventPublisher;
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
async execute(data) {
|
|
29
|
+
const validation = schema.safeParse(data);
|
|
30
|
+
if (!validation.success) return Result.fail(new MailValidationError(validation.error.issues));
|
|
31
|
+
await this.eventPublisher.publish(new MailBeforeSendEvent({
|
|
32
|
+
data
|
|
33
|
+
}));
|
|
34
|
+
const result = await this.mailerService.sendMail(data);
|
|
35
|
+
if (result.isFail()) {
|
|
36
|
+
await this.eventPublisher.publish(new MailSendErrorEvent({
|
|
37
|
+
data,
|
|
38
|
+
error: result.error
|
|
39
|
+
}));
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
await this.eventPublisher.publish(new MailAfterSendEvent({
|
|
43
|
+
data,
|
|
44
|
+
response: result.value
|
|
45
|
+
}));
|
|
46
|
+
return result;
|
|
50
47
|
}
|
|
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
48
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({
|
|
50
|
+
implementation: SendMailUseCaseImpl,
|
|
51
|
+
dependencies: [
|
|
52
|
+
MailerService,
|
|
53
|
+
EventPublisher
|
|
54
|
+
]
|
|
63
55
|
});
|
|
56
|
+
export { SendMailUseCaseImplementation };
|
|
64
57
|
|
|
65
58
|
//# sourceMappingURL=SendMailUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/SendMail/SendMailUseCase.js","sources":["../../../src/features/SendMail/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"],"names":["requiredString","zod","mailboxAddress","isMailboxAddress","schema","data","SendMailUseCaseImpl","mailerService","eventPublisher","validation","Result","MailValidationError","MailBeforeSendEvent","result","MailSendErrorEvent","MailAfterSendEvent","SendMailUseCaseImplementation","SendMailUseCase","MailerService","EventPublisher"],"mappings":";;;;;;;;AAaA,MAAMA,iBAAiBC,IAAI,MAAM;AACjC,MAAMC,iBAAiBD,IAAI,MAAM,GAAG,MAAM,CAACE,kBAAkB;IAAE,SAAS;AAAyB;AAEjG,MAAMC,SAASH,IAAAA,MACJ,CAAC;IACJ,IAAIA,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACtC,MAAMA,eAAe,QAAQ;IAC7B,SAASF,eAAe,GAAG,CAAC,MAAM,GAAG,CAAC;IACtC,IAAIC,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACtC,KAAKD,IAAI,KAAK,CAACC,gBAAgB,QAAQ;IACvC,SAASA,eAAe,QAAQ;IAChC,MAAMD,IAAI,MAAM,GAAG,QAAQ;IAC3B,MAAMA,IAAI,MAAM,GAAG,QAAQ;AAC/B,GACC,MAAM,CAACI,CAAAA,OACG,CAAC,CAACA,KAAK,IAAI,IAAI,CAAC,CAACA,KAAK,IAAI,EAClC;AAEP,MAAMC;IACF,YACYC,aAAsC,EACtCC,cAAmD,CAC7D;aAFUD,aAAa,GAAbA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQH,IAAuB,EAAE;QACnC,MAAMI,aAAaL,OAAO,SAAS,CAACC;QACpC,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOC,OAAO,IAAI,CAAC,IAAIC,oBAAoBF,WAAW,KAAK,CAAC,MAAM;QAItE,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIG,oBAAoB;YAAEP;QAAK;QAGjE,MAAMQ,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAACR;QAEjD,IAAIQ,OAAO,MAAM,IAAI;YAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,mBAAmB;gBACnBT;gBACA,OAAOQ,OAAO,KAAK;YACvB;YAGJ,OAAOA;QACX;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,mBAAmB;YACnBV;YACA,UAAUQ,OAAO,KAAK;QAC1B;QAGJ,OAAOA;IACX;AACJ;AAEO,MAAMG,gCAAgCC,gBAAgB,oBAAoB,CAAC;IAC9E,gBAAgBX;IAChB,cAAc;QAACY;QAAeC;KAAe;AACjD"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const MailBeforeSendEventHandler = createAbstraction("MailBeforeSendEventHandler");
|
|
8
|
-
export const MailAfterSendEventHandler = createAbstraction("MailAfterSendEventHandler");
|
|
9
|
-
export const MailSendErrorEventHandler = createAbstraction("MailSendErrorEventHandler");
|
|
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 };
|
|
10
7
|
|
|
11
8
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
class MailAfterSendEvent extends DomainEvent {
|
|
12
|
+
getHandlerAbstraction() {
|
|
13
|
+
return MailAfterSendEventHandler;
|
|
14
|
+
}
|
|
15
|
+
constructor(...args){
|
|
16
|
+
super(...args), this.eventType = "mailer.mail.afterSend";
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
class MailSendErrorEvent extends DomainEvent {
|
|
20
|
+
getHandlerAbstraction() {
|
|
21
|
+
return MailSendErrorEventHandler;
|
|
22
|
+
}
|
|
23
|
+
constructor(...args){
|
|
24
|
+
super(...args), this.eventType = "mailer.mail.sendError";
|
|
25
|
+
}
|
|
20
26
|
}
|
|
27
|
+
export { MailAfterSendEvent, MailBeforeSendEvent, MailSendErrorEvent };
|
|
21
28
|
|
|
22
29
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { SendMailUseCaseImplementation } from "./SendMailUseCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const SendMailFeature = createFeature({
|
|
4
|
+
name: "SendMail",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SendMailUseCaseImplementation);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { SendMailFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "./abstractions.js";
|
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
const configDefaults = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
socketTimeout: 15000,
|
|
3
|
+
connectionTimeout: 15000,
|
|
4
|
+
greetingTimeout: 15000
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
config[configKey] = configDefaults[configKey];
|
|
23
|
-
}
|
|
24
|
-
return config;
|
|
25
|
-
}, baseConfig);
|
|
26
|
-
}
|
|
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
|
+
}
|
|
27
22
|
}
|
|
23
|
+
export { SmtpConfig };
|
|
28
24
|
|
|
29
25
|
//# sourceMappingURL=SmtpConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,67 +1,53 @@
|
|
|
1
1
|
import nodemailer from "nodemailer";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
}
|
|
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
|
+
};
|
|
61
48
|
}
|
|
62
|
-
};
|
|
63
49
|
}
|
|
64
|
-
}
|
|
65
50
|
}
|
|
51
|
+
export { SmtpMailTransport };
|
|
66
52
|
|
|
67
53
|
//# sourceMappingURL=SmtpMailTransport.js.map
|