@webiny/api-mailer 0.0.0-unstable.461c047ab7 → 0.0.0-unstable.48a4e5b6c1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MailerFeature.d.ts +4 -0
- package/MailerFeature.js +23 -0
- package/MailerFeature.js.map +1 -0
- package/README.md +10 -13
- package/constants.d.ts +1 -0
- package/constants.js +4 -0
- package/constants.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +23 -0
- package/domain/MailTransport/abstractions.js +6 -0
- package/domain/MailTransport/abstractions.js.map +1 -0
- package/domain/MailerService/abstractions.d.ts +21 -0
- package/domain/MailerService/abstractions.js +5 -0
- package/domain/MailerService/abstractions.js.map +1 -0
- package/domain/MailerService/errors.d.ts +20 -0
- package/domain/MailerService/errors.js +35 -0
- package/domain/MailerService/errors.js.map +1 -0
- package/domain/TransportSettings/abstractions.d.ts +47 -0
- package/domain/TransportSettings/abstractions.js +5 -0
- package/domain/TransportSettings/abstractions.js.map +1 -0
- package/domain/TransportSettings/findDefinition.d.ts +6 -0
- package/domain/TransportSettings/findDefinition.js +13 -0
- package/domain/TransportSettings/findDefinition.js.map +1 -0
- package/domain/errors.d.ts +42 -0
- package/domain/errors.js +72 -0
- package/domain/errors.js.map +1 -0
- package/exports/api/mailer.d.ts +6 -0
- package/exports/api/mailer.js +6 -0
- package/features/GetSettings/GetSettingsRepository.d.ts +17 -0
- package/features/GetSettings/GetSettingsRepository.js +52 -0
- package/features/GetSettings/GetSettingsRepository.js.map +1 -0
- package/features/GetSettings/GetSettingsUseCase.d.ts +19 -0
- package/features/GetSettings/GetSettingsUseCase.js +43 -0
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
- package/features/GetSettings/abstractions.d.ts +30 -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 +2 -0
- package/features/GetSettings/index.js +1 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.d.ts +11 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js +19 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js.map +1 -0
- package/features/IsMailerConfigured/abstractions.d.ts +18 -0
- package/features/IsMailerConfigured/abstractions.js +5 -0
- package/features/IsMailerConfigured/abstractions.js.map +1 -0
- package/features/IsMailerConfigured/feature.d.ts +4 -0
- package/features/IsMailerConfigured/feature.js +11 -0
- package/features/IsMailerConfigured/feature.js.map +1 -0
- package/features/IsMailerConfigured/index.d.ts +1 -0
- package/features/IsMailerConfigured/index.js +1 -0
- package/features/MailerService/MailerService.d.ts +14 -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 +11 -0
- package/features/MailerService/feature.js.map +1 -0
- package/features/SaveSettings/SaveSettingsRepository.d.ts +14 -0
- package/features/SaveSettings/SaveSettingsRepository.js +67 -0
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +16 -0
- package/features/SaveSettings/SaveSettingsUseCase.js +58 -0
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
- package/features/SaveSettings/abstractions.d.ts +54 -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 +2 -0
- package/features/SaveSettings/index.js +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/SendTestMail/SendTestMailUseCase.d.ts +13 -0
- package/features/SendTestMail/SendTestMailUseCase.js +40 -0
- package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
- package/features/SendTestMail/abstractions.d.ts +32 -0
- package/features/SendTestMail/abstractions.js +5 -0
- package/features/SendTestMail/abstractions.js.map +1 -0
- package/features/SendTestMail/feature.d.ts +4 -0
- package/features/SendTestMail/feature.js +11 -0
- package/features/SendTestMail/feature.js.map +1 -0
- package/graphql/MailerSchemaFactory.d.ts +10 -0
- package/graphql/MailerSchemaFactory.js +135 -0
- package/graphql/MailerSchemaFactory.js.map +1 -0
- package/index.d.ts +13 -5
- package/index.js +9 -83
- package/package.json +27 -34
- package/types.d.ts +0 -115
- package/types.js +0 -7
- 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 -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/graphql/settings.d.ts +0 -3
- package/graphql/settings.js +0 -103
- package/graphql/settings.js.map +0 -1
- package/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
- package/types.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
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: \"Mailer/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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
2
|
+
export type { SavedTransportSettings, MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { SendMailUseCase } from "./abstractions.js";
|
|
3
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
4
|
+
import type { TransportSendData } from "../../types.js";
|
|
5
|
+
import { MailValidationError } from "../../domain/errors.js";
|
|
6
|
+
import { Result } from "@webiny/feature/api";
|
|
7
|
+
declare class SendMailUseCaseImpl implements SendMailUseCase.Interface {
|
|
8
|
+
private mailerService;
|
|
9
|
+
private eventPublisher;
|
|
10
|
+
constructor(mailerService: MailerService.Interface, eventPublisher: EventPublisherAbstraction.Interface);
|
|
11
|
+
execute(data: TransportSendData): Promise<Result<never, MailValidationError> | Result<import("~/types.js").TransportSendResponse<any>, import("../../domain/MailerService/errors.js").NoTransportAvailableError | import("../../domain/MailerService/errors.js").TransportCreateError | import("../../domain/MailerService/errors.js").TransportSendError>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const SendMailUseCaseImplementation: typeof SendMailUseCaseImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendMailUseCase>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { SendMailUseCase } from "./abstractions.js";
|
|
4
|
+
import { MailAfterSendEvent, MailBeforeSendEvent, 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)=>!!data.text || !!data.html, "Either text or html is required.");
|
|
23
|
+
class SendMailUseCaseImpl {
|
|
24
|
+
constructor(mailerService, eventPublisher){
|
|
25
|
+
this.mailerService = mailerService;
|
|
26
|
+
this.eventPublisher = eventPublisher;
|
|
27
|
+
}
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({
|
|
50
|
+
implementation: SendMailUseCaseImpl,
|
|
51
|
+
dependencies: [
|
|
52
|
+
MailerService,
|
|
53
|
+
EventPublisher
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
export { SendMailUseCaseImplementation };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=SendMailUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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,13 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { SendTestMailUseCase } from "./abstractions.js";
|
|
3
|
+
import { SendMailUseCase } from "../../features/SendMail/abstractions.js";
|
|
4
|
+
declare class SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {
|
|
5
|
+
private identityContext;
|
|
6
|
+
private sendMailUseCase;
|
|
7
|
+
constructor(identityContext: IdentityContext.Interface, sendMailUseCase: SendMailUseCase.Interface);
|
|
8
|
+
execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return;
|
|
9
|
+
}
|
|
10
|
+
export declare const SendTestMailUseCaseImplementation: typeof SendTestMailUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendTestMailUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { SendTestMailUseCase } from "./abstractions.js";
|
|
4
|
+
import { SendMailUseCase } from "../SendMail/abstractions.js";
|
|
5
|
+
import { TestMailNotAuthorized, TestMailNotConfigured } from "../../domain/errors.js";
|
|
6
|
+
import { NoTransportAvailableError } from "../../domain/MailerService/errors.js";
|
|
7
|
+
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
8
|
+
const TEST_MAIL_TEXT = "This is a test email from Webiny.\n\nIt was sent from the Mailer settings screen to check that mail is delivered. No action is needed.";
|
|
9
|
+
class SendTestMailUseCaseImpl {
|
|
10
|
+
constructor(identityContext, sendMailUseCase){
|
|
11
|
+
this.identityContext = identityContext;
|
|
12
|
+
this.sendMailUseCase = sendMailUseCase;
|
|
13
|
+
}
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
16
|
+
if (!permission) return Result.fail(new TestMailNotAuthorized());
|
|
17
|
+
const result = await this.sendMailUseCase.execute({
|
|
18
|
+
to: [
|
|
19
|
+
input.to
|
|
20
|
+
],
|
|
21
|
+
subject: "Webiny test email",
|
|
22
|
+
text: TEST_MAIL_TEXT
|
|
23
|
+
});
|
|
24
|
+
if (result.isFail()) {
|
|
25
|
+
if (result.error instanceof NoTransportAvailableError) return Result.fail(new TestMailNotConfigured());
|
|
26
|
+
return Result.fail(result.error);
|
|
27
|
+
}
|
|
28
|
+
return Result.ok(void 0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({
|
|
32
|
+
implementation: SendTestMailUseCaseImpl,
|
|
33
|
+
dependencies: [
|
|
34
|
+
IdentityContext,
|
|
35
|
+
SendMailUseCase
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { SendTestMailUseCaseImplementation };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=SendTestMailUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/SendTestMailUseCase.js","sources":["../../../src/features/SendTestMail/SendTestMailUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { SendTestMailUseCase } from \"./abstractions.js\";\nimport { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\nimport { NoTransportAvailableError } from \"~/domain/MailerService/errors.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nconst TEST_MAIL_TEXT = [\n \"This is a test email from Webiny.\",\n \"\",\n \"It was sent from the Mailer settings screen to check that mail is delivered. \" +\n \"No action is needed.\"\n].join(\"\\n\");\n\nclass SendTestMailUseCaseImpl implements SendTestMailUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private sendMailUseCase: SendMailUseCase.Interface\n ) {}\n\n async execute(input: SendTestMailUseCase.Input): SendTestMailUseCase.Return {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(new TestMailNotAuthorized());\n }\n\n const result = await this.sendMailUseCase.execute({\n to: [input.to],\n subject: \"Webiny test email\",\n text: TEST_MAIL_TEXT\n });\n\n if (result.isFail()) {\n if (result.error instanceof NoTransportAvailableError) {\n return Result.fail(new TestMailNotConfigured());\n }\n return Result.fail(result.error);\n }\n\n return Result.ok(undefined);\n }\n}\n\nexport const SendTestMailUseCaseImplementation = SendTestMailUseCase.createImplementation({\n implementation: SendTestMailUseCaseImpl,\n dependencies: [IdentityContext, SendMailUseCase]\n});\n"],"names":["TEST_MAIL_TEXT","SendTestMailUseCaseImpl","identityContext","sendMailUseCase","input","permission","MAILER_SETTINGS_PERMISSION","Result","TestMailNotAuthorized","result","NoTransportAvailableError","TestMailNotConfigured","undefined","SendTestMailUseCaseImplementation","SendTestMailUseCase","IdentityContext","SendMailUseCase"],"mappings":";;;;;;;AASA,MAAMA,iBAAiB;AAOvB,MAAMC;IACF,YACYC,eAA0C,EAC1CC,eAA0C,CACpD;aAFUD,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAAgC,EAA8B;QACxE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAC9C,IAAI;gBAACL,MAAM,EAAE;aAAC;YACd,SAAS;YACT,MAAMJ;QACV;QAEA,IAAIS,OAAO,MAAM,IAAI;YACjB,IAAIA,OAAO,KAAK,YAAYC,2BACxB,OAAOH,OAAO,IAAI,CAAC,IAAII;YAE3B,OAAOJ,OAAO,IAAI,CAACE,OAAO,KAAK;QACnC;QAEA,OAAOF,OAAO,EAAE,CAACK;IACrB;AACJ;AAEO,MAAMC,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgBb;IAChB,cAAc;QAACc;QAAiBC;KAAgB;AACpD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { SendMailUseCase } from "../../features/SendMail/abstractions.js";
|
|
3
|
+
import { TestMailNotAuthorized } from "../../domain/errors.js";
|
|
4
|
+
import { TestMailNotConfigured } from "../../domain/errors.js";
|
|
5
|
+
export interface SendTestMailInput {
|
|
6
|
+
to: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ISendTestMailErrors {
|
|
9
|
+
notAuthorized: TestMailNotAuthorized;
|
|
10
|
+
notConfigured: TestMailNotConfigured;
|
|
11
|
+
sendMail: SendMailUseCase.Error;
|
|
12
|
+
}
|
|
13
|
+
type SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];
|
|
14
|
+
export interface ISendTestMailUseCase {
|
|
15
|
+
execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sends one message through the transport that delivers this project's mail, so an operator can
|
|
19
|
+
* tell settings that deliver from settings that only look configured. The mail server's own error
|
|
20
|
+
* comes back to the caller.
|
|
21
|
+
*
|
|
22
|
+
* The test goes through `SendMailUseCase` like any other mail, so it publishes the same
|
|
23
|
+
* `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SendTestMailUseCase: import("@webiny/di").Abstraction<ISendTestMailUseCase>;
|
|
26
|
+
export declare namespace SendTestMailUseCase {
|
|
27
|
+
type Interface = ISendTestMailUseCase;
|
|
28
|
+
type Input = SendTestMailInput;
|
|
29
|
+
type Return = Promise<Result<void, SendTestMailError>>;
|
|
30
|
+
type Error = SendTestMailError;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/abstractions.js","sources":["../../../src/features/SendTestMail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { SendMailUseCase } from \"~/features/SendMail/abstractions.js\";\nimport { TestMailNotAuthorized } from \"~/domain/errors.js\";\nimport { TestMailNotConfigured } from \"~/domain/errors.js\";\n\nexport interface SendTestMailInput {\n to: string;\n}\n\nexport interface ISendTestMailErrors {\n notAuthorized: TestMailNotAuthorized;\n notConfigured: TestMailNotConfigured;\n sendMail: SendMailUseCase.Error;\n}\n\ntype SendTestMailError = ISendTestMailErrors[keyof ISendTestMailErrors];\n\nexport interface ISendTestMailUseCase {\n execute(input: SendTestMailInput): Promise<Result<void, SendTestMailError>>;\n}\n\n/**\n * Sends one message through the transport that delivers this project's mail, so an operator can\n * tell settings that deliver from settings that only look configured. The mail server's own error\n * comes back to the caller.\n *\n * The test goes through `SendMailUseCase` like any other mail, so it publishes the same\n * `MailBeforeSend`, `MailAfterSend` and `MailSendError` events.\n */\nexport const SendTestMailUseCase = createAbstraction<ISendTestMailUseCase>(\"SendTestMailUseCase\");\n\nexport namespace SendTestMailUseCase {\n export type Interface = ISendTestMailUseCase;\n export type Input = SendTestMailInput;\n export type Return = Promise<Result<void, SendTestMailError>>;\n export type Error = SendTestMailError;\n}\n"],"names":["SendTestMailUseCase","createAbstraction"],"mappings":";AA8BO,MAAMA,sBAAsBC,kBAAwC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SendTestMailUseCaseImplementation } from "./SendTestMailUseCase.js";
|
|
3
|
+
const SendTestMailFeature = createFeature({
|
|
4
|
+
name: "SendTestMail",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(SendTestMailUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { SendTestMailFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SendTestMail/feature.js","sources":["../../../src/features/SendTestMail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SendTestMailUseCaseImplementation } from \"./SendTestMailUseCase.js\";\n\nexport const SendTestMailFeature = createFeature({\n name: \"SendTestMail\",\n register(container) {\n container.register(SendTestMailUseCaseImplementation);\n }\n});\n"],"names":["SendTestMailFeature","createFeature","container","SendTestMailUseCaseImplementation"],"mappings":";;AAGO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import type { IGraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js";
|
|
3
|
+
declare class MailerSchemaFactoryImpl implements GraphQLSchemaFactory.Interface {
|
|
4
|
+
getSchemaKey: () => string;
|
|
5
|
+
execute(builder: IGraphQLSchemaBuilder): Promise<IGraphQLSchemaBuilder>;
|
|
6
|
+
}
|
|
7
|
+
export declare const MailerSchemaFactory: typeof MailerSchemaFactoryImpl & {
|
|
8
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.public").IGraphQLSchemaFactory>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
|
|
3
|
+
import { ErrorResponse } from "@webiny/api-graphql/responses.js";
|
|
4
|
+
import { SendTestMailUseCase } from "../features/SendTestMail/abstractions.js";
|
|
5
|
+
import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
|
|
6
|
+
import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
|
|
7
|
+
class MailerSchemaFactoryImpl {
|
|
8
|
+
async execute(builder) {
|
|
9
|
+
builder.addTypeDefs(`
|
|
10
|
+
type MailerTransportSettingsError {
|
|
11
|
+
message: String!
|
|
12
|
+
code: String
|
|
13
|
+
data: JSON
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type MailerSendTestMailResponse {
|
|
17
|
+
data: Boolean
|
|
18
|
+
error: MailerTransportSettingsError
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type MailerTransportSettingsData {
|
|
22
|
+
transport: String!
|
|
23
|
+
settings: JSON
|
|
24
|
+
source: String
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type MailerTransportSettingsDataResponse {
|
|
28
|
+
data: MailerTransportSettingsData
|
|
29
|
+
error: MailerTransportSettingsError
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type MailerQuery {
|
|
33
|
+
getTransportSettings(transport: String!): MailerTransportSettingsDataResponse!
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type MailerMutation {
|
|
37
|
+
sendTestMail(to: String!): MailerSendTestMailResponse!
|
|
38
|
+
saveTransportSettings(
|
|
39
|
+
transport: String!
|
|
40
|
+
settings: JSON!
|
|
41
|
+
): MailerTransportSettingsDataResponse!
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
extend type Query {
|
|
45
|
+
mailer: MailerQuery
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
extend type Mutation {
|
|
49
|
+
mailer: MailerMutation
|
|
50
|
+
}
|
|
51
|
+
`);
|
|
52
|
+
builder.addResolver({
|
|
53
|
+
path: "Query.mailer",
|
|
54
|
+
resolver: ()=>async ()=>({})
|
|
55
|
+
});
|
|
56
|
+
builder.addResolver({
|
|
57
|
+
path: "Mutation.mailer",
|
|
58
|
+
resolver: ()=>async ()=>({})
|
|
59
|
+
});
|
|
60
|
+
builder.addResolver({
|
|
61
|
+
path: "MailerQuery.getTransportSettings",
|
|
62
|
+
dependencies: [
|
|
63
|
+
GetSettingsUseCase
|
|
64
|
+
],
|
|
65
|
+
resolver: (getSettings)=>async ({ args })=>{
|
|
66
|
+
try {
|
|
67
|
+
const result = await getSettings.execute(args.transport);
|
|
68
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
69
|
+
return {
|
|
70
|
+
data: {
|
|
71
|
+
transport: args.transport,
|
|
72
|
+
...result.value
|
|
73
|
+
},
|
|
74
|
+
error: null
|
|
75
|
+
};
|
|
76
|
+
} catch (ex) {
|
|
77
|
+
return new ErrorResponse(ex);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
builder.addResolver({
|
|
82
|
+
path: "MailerMutation.saveTransportSettings",
|
|
83
|
+
dependencies: [
|
|
84
|
+
SaveSettingsUseCase
|
|
85
|
+
],
|
|
86
|
+
resolver: (saveSettings)=>async ({ args })=>{
|
|
87
|
+
try {
|
|
88
|
+
const result = await saveSettings.execute(args.transport, args.settings);
|
|
89
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
90
|
+
return {
|
|
91
|
+
data: {
|
|
92
|
+
transport: args.transport,
|
|
93
|
+
settings: result.value,
|
|
94
|
+
source: "storage"
|
|
95
|
+
},
|
|
96
|
+
error: null
|
|
97
|
+
};
|
|
98
|
+
} catch (ex) {
|
|
99
|
+
return new ErrorResponse(ex);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
builder.addResolver({
|
|
104
|
+
path: "MailerMutation.sendTestMail",
|
|
105
|
+
dependencies: [
|
|
106
|
+
SendTestMailUseCase
|
|
107
|
+
],
|
|
108
|
+
resolver: (sendTestMail)=>async ({ args })=>{
|
|
109
|
+
try {
|
|
110
|
+
const result = await sendTestMail.execute({
|
|
111
|
+
to: args.to
|
|
112
|
+
});
|
|
113
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
114
|
+
return {
|
|
115
|
+
data: true,
|
|
116
|
+
error: null
|
|
117
|
+
};
|
|
118
|
+
} catch (ex) {
|
|
119
|
+
return new ErrorResponse(ex);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return builder;
|
|
124
|
+
}
|
|
125
|
+
constructor(){
|
|
126
|
+
this.getSchemaKey = staticSchemaKey("api-mailer/MailerSchemaFactoryImpl");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const MailerSchemaFactory = GraphQLSchemaFactory.createImplementation({
|
|
130
|
+
implementation: MailerSchemaFactoryImpl,
|
|
131
|
+
dependencies: []
|
|
132
|
+
});
|
|
133
|
+
export { MailerSchemaFactory };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=MailerSchemaFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/MailerSchemaFactory.js","sources":["../../src/graphql/MailerSchemaFactory.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport type { IGraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ErrorResponse } from \"@webiny/api-graphql/responses.js\";\nimport { SendTestMailUseCase } from \"~/features/SendTestMail/abstractions.js\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\n\n/*\n * The `mailer` namespaces, the test email, and the settings of any transport that registers a\n * `TransportSettingsDefinition`, as JSON. Secrets are never returned.\n */\nclass MailerSchemaFactoryImpl implements GraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-mailer/MailerSchemaFactoryImpl\");\n\n async execute(builder: IGraphQLSchemaBuilder): Promise<IGraphQLSchemaBuilder> {\n builder.addTypeDefs(`\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n\n type MailerSendTestMailResponse {\n data: Boolean\n error: MailerTransportSettingsError\n }\n\n type MailerTransportSettingsData {\n transport: String!\n settings: JSON\n source: String\n }\n\n type MailerTransportSettingsDataResponse {\n data: MailerTransportSettingsData\n error: MailerTransportSettingsError\n }\n\n type MailerQuery {\n getTransportSettings(transport: String!): MailerTransportSettingsDataResponse!\n }\n\n type MailerMutation {\n sendTestMail(to: String!): MailerSendTestMailResponse!\n saveTransportSettings(\n transport: String!\n settings: JSON!\n ): MailerTransportSettingsDataResponse!\n }\n\n extend type Query {\n mailer: MailerQuery\n }\n\n extend type Mutation {\n mailer: MailerMutation\n }\n `);\n\n builder.addResolver({\n path: \"Query.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver<{ transport: string }>({\n path: \"MailerQuery.getTransportSettings\",\n dependencies: [GetSettingsUseCase],\n resolver:\n (getSettings: GetSettingsUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await getSettings.execute(args.transport);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return {\n data: { transport: args.transport, ...result.value },\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ transport: string; settings: Record<string, unknown> }>({\n path: \"MailerMutation.saveTransportSettings\",\n dependencies: [SaveSettingsUseCase],\n resolver:\n (saveSettings: SaveSettingsUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await saveSettings.execute(args.transport, args.settings);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return {\n data: {\n transport: args.transport,\n settings: result.value,\n source: \"storage\"\n },\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ to: string }>({\n path: \"MailerMutation.sendTestMail\",\n dependencies: [SendTestMailUseCase],\n resolver:\n (sendTestMail: SendTestMailUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await sendTestMail.execute({ to: args.to });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return { data: true, error: null };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n return builder;\n }\n}\n\nexport const MailerSchemaFactory = GraphQLSchemaFactory.createImplementation({\n implementation: MailerSchemaFactoryImpl,\n dependencies: []\n});\n"],"names":["MailerSchemaFactoryImpl","builder","GetSettingsUseCase","getSettings","args","result","ErrorResponse","ex","SaveSettingsUseCase","saveSettings","SendTestMailUseCase","sendTestMail","staticSchemaKey","MailerSchemaFactory","GraphQLSchemaFactory"],"mappings":";;;;;;AAYA,MAAMA;IAGF,MAAM,QAAQC,OAA8B,EAAkC;QAC1EA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA0CrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAwB;YACvC,MAAM;YACN,cAAc;gBAACC;aAAmB;YAClC,UACI,CAACC,cACD,OAAO,EAAEC,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMF,YAAY,OAAO,CAACC,KAAK,SAAS;wBACvD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAM;gCAAE,WAAWD,KAAK,SAAS;gCAAE,GAAGC,OAAO,KAAK;4BAAC;4BACnD,OAAO;wBACX;oBACJ,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEAN,QAAQ,WAAW,CAA2D;YAC1E,MAAM;YACN,cAAc;gBAACO;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEL,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMI,aAAa,OAAO,CAACL,KAAK,SAAS,EAAEA,KAAK,QAAQ;wBACvE,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAM;gCACF,WAAWD,KAAK,SAAS;gCACzB,UAAUC,OAAO,KAAK;gCACtB,QAAQ;4BACZ;4BACA,OAAO;wBACX;oBACJ,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEAN,QAAQ,WAAW,CAAiB;YAChC,MAAM;YACN,cAAc;gBAACS;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEP,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMM,aAAa,OAAO,CAAC;4BAAE,IAAIP,KAAK,EAAE;wBAAC;wBAExD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO;4BAAE,MAAM;4BAAM,OAAO;wBAAK;oBACrC,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEA,OAAON;IACX;;aA5HO,YAAY,GAAGW,gBAAgB;;AA6H1C;AAEO,MAAMC,sBAAsBC,qBAAqB,oBAAoB,CAAC;IACzE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export { MailerFeature } from "./MailerFeature.js";
|
|
2
|
+
export { MailerService } from "./domain/MailerService/abstractions.js";
|
|
3
|
+
export type { IMailerService, IMailerServiceErrors } from "./domain/MailerService/abstractions.js";
|
|
4
|
+
export { MailTransport } from "./domain/MailTransport/abstractions.js";
|
|
5
|
+
export { MailTransportFactory } from "./domain/MailTransport/abstractions.js";
|
|
6
|
+
export { MAILER_SETTINGS_PERMISSION } from "./constants.js";
|
|
7
|
+
export { isMailboxAddress } from "./utils/isMailboxAddress.js";
|
|
8
|
+
export { TransportSettingsDefinition } from "./domain/TransportSettings/abstractions.js";
|
|
9
|
+
export { SettingsValidationError, SettingsNotAuthorized, SettingsPersistenceError, SettingsLockedByCode, UnknownTransportSettings } from "./domain/errors.js";
|
|
10
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "./features/GetSettings/index.js";
|
|
11
|
+
export type { ISettingsWithSource, MailerSettingsSource } from "./features/GetSettings/index.js";
|
|
12
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./features/SaveSettings/index.js";
|
|
13
|
+
export type { SavedTransportSettings, MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./features/SaveSettings/index.js";
|