@webiny/api-mailer 0.0.0-unstable.06b2ede40f → 0.0.0-unstable.0d717d18dd
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 +25 -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/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +5 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +20 -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 +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/errors.d.ts +28 -0
- package/domain/errors.js +48 -0
- package/domain/errors.js.map +1 -0
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +4 -0
- package/features/CodeMailerSettings/CodeMailerSettings.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettings.js +23 -0
- package/features/CodeMailerSettings/CodeMailerSettings.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +11 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransport.js +14 -0
- package/features/DummyTransport/DummyMailTransport.js.map +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +10 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +20 -0
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
- package/features/DummyTransport/feature.d.ts +4 -0
- package/features/DummyTransport/feature.js +11 -0
- package/features/DummyTransport/feature.js.map +1 -0
- package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
- package/features/GetSettings/GetSettingsRepository.js +56 -0
- package/features/GetSettings/GetSettingsRepository.js.map +1 -0
- package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
- package/features/GetSettings/GetSettingsUseCase.js +18 -0
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
- package/features/GetSettings/abstractions.d.ts +22 -0
- package/features/GetSettings/abstractions.js +6 -0
- package/features/GetSettings/abstractions.js.map +1 -0
- package/features/GetSettings/feature.d.ts +4 -0
- package/features/GetSettings/feature.js +13 -0
- package/features/GetSettings/feature.js.map +1 -0
- package/features/GetSettings/index.d.ts +1 -0
- package/features/GetSettings/index.js +1 -0
- package/features/MailerService/MailerService.d.ts +15 -0
- package/features/MailerService/MailerService.js +59 -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 +13 -0
- package/features/SaveSettings/SaveSettingsRepository.js +45 -0
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
- package/features/SaveSettings/SaveSettingsUseCase.js +56 -0
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
- package/features/SaveSettings/abstractions.d.ts +62 -0
- package/features/SaveSettings/abstractions.js +8 -0
- package/features/SaveSettings/abstractions.js.map +1 -0
- package/features/SaveSettings/events.d.ts +10 -0
- package/features/SaveSettings/events.js +21 -0
- package/features/SaveSettings/events.js.map +1 -0
- package/features/SaveSettings/feature.d.ts +4 -0
- package/features/SaveSettings/feature.js +13 -0
- package/features/SaveSettings/feature.js.map +1 -0
- package/features/SaveSettings/index.d.ts +1 -0
- package/features/SaveSettings/index.js +1 -0
- package/features/SaveSettings/validation.d.ts +10 -0
- package/features/SaveSettings/validation.js +21 -0
- package/features/SaveSettings/validation.js.map +1 -0
- package/features/SendMail/SendMailUseCase.d.ts +16 -0
- package/features/SendMail/SendMailUseCase.js +58 -0
- package/features/SendMail/SendMailUseCase.js.map +1 -0
- package/features/SendMail/abstractions.d.ts +45 -0
- package/features/SendMail/abstractions.js +8 -0
- package/features/SendMail/abstractions.js.map +1 -0
- package/features/SendMail/events.d.ts +14 -0
- package/features/SendMail/events.js +29 -0
- package/features/SendMail/events.js.map +1 -0
- package/features/SendMail/feature.d.ts +4 -0
- package/features/SendMail/feature.js +11 -0
- package/features/SendMail/feature.js.map +1 -0
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +1 -0
- package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
- package/features/SmtpTransport/SmtpConfig.js +26 -0
- package/features/SmtpTransport/SmtpConfig.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +68 -0
- package/features/SmtpTransport/SmtpMailTransport.js +53 -0
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +11 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +21 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
- package/features/SmtpTransport/feature.d.ts +4 -0
- package/features/SmtpTransport/feature.js +11 -0
- package/features/SmtpTransport/feature.js.map +1 -0
- package/graphql/MailerSchemaFactory.d.ts +9 -0
- package/graphql/MailerSchemaFactory.js +116 -0
- package/graphql/MailerSchemaFactory.js.map +1 -0
- package/index.d.ts +3 -5
- package/index.js +2 -83
- package/package.json +28 -34
- package/types.d.ts +1 -107
- 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,22 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { TransportSettings } from "../../types.js";
|
|
3
|
+
export type MailerSettingsSource = "code" | "storage" | null;
|
|
4
|
+
export interface ISettingsWithSource {
|
|
5
|
+
settings: TransportSettings | null;
|
|
6
|
+
source: MailerSettingsSource;
|
|
7
|
+
}
|
|
8
|
+
export interface IGetSettingsRepository {
|
|
9
|
+
get(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const GetSettingsRepository: import("@webiny/di").Abstraction<IGetSettingsRepository>;
|
|
12
|
+
export declare namespace GetSettingsRepository {
|
|
13
|
+
type Interface = IGetSettingsRepository;
|
|
14
|
+
type Return = Promise<Result<ISettingsWithSource>>;
|
|
15
|
+
}
|
|
16
|
+
export interface IGetSettingsUseCase {
|
|
17
|
+
execute(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const GetSettingsUseCase: import("@webiny/di").Abstraction<IGetSettingsUseCase>;
|
|
20
|
+
export declare namespace GetSettingsUseCase {
|
|
21
|
+
type Interface = IGetSettingsUseCase;
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const GetSettingsRepository = createAbstraction("GetSettingsRepository");
|
|
3
|
+
const GetSettingsUseCase = createAbstraction("GetSettingsUseCase");
|
|
4
|
+
export { GetSettingsRepository, GetSettingsUseCase };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetSettings/abstractions.js","sources":["../../../src/features/GetSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { TransportSettings } from \"~/types.js\";\n\nexport type MailerSettingsSource = \"code\" | \"storage\" | null;\n\nexport interface ISettingsWithSource {\n settings: TransportSettings | null;\n source: MailerSettingsSource;\n}\n\nexport interface IGetSettingsRepository {\n get(transportName: string): Promise<Result<ISettingsWithSource>>;\n}\n\nexport const GetSettingsRepository =\n createAbstraction<IGetSettingsRepository>(\"GetSettingsRepository\");\n\nexport namespace GetSettingsRepository {\n export type Interface = IGetSettingsRepository;\n export type Return = Promise<Result<ISettingsWithSource>>;\n}\n\nexport interface IGetSettingsUseCase {\n execute(transportName: string): Promise<Result<ISettingsWithSource>>;\n}\n\nexport const GetSettingsUseCase = createAbstraction<IGetSettingsUseCase>(\"GetSettingsUseCase\");\n\nexport namespace GetSettingsUseCase {\n export type Interface = IGetSettingsUseCase;\n}\n"],"names":["GetSettingsRepository","createAbstraction","GetSettingsUseCase"],"mappings":";AAeO,MAAMA,wBACTC,kBAA0C;AAWvC,MAAMC,qBAAqBD,kBAAuC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetSettingsRepositoryImplementation } from "./GetSettingsRepository.js";
|
|
3
|
+
import { GetSettingsUseCaseImplementation } from "./GetSettingsUseCase.js";
|
|
4
|
+
const GetSettingsFeature = createFeature({
|
|
5
|
+
name: "GetSettings",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(GetSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(GetSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { GetSettingsFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetSettings/feature.js","sources":["../../../src/features/GetSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetSettingsRepositoryImplementation } from \"./GetSettingsRepository.js\";\nimport { GetSettingsUseCaseImplementation } from \"./GetSettingsUseCase.js\";\n\nexport const GetSettingsFeature = createFeature({\n name: \"GetSettings\",\n register(container) {\n container.register(GetSettingsRepositoryImplementation).inSingletonScope();\n container.register(GetSettingsUseCaseImplementation);\n }\n});\n"],"names":["GetSettingsFeature","createFeature","container","GetSettingsRepositoryImplementation","GetSettingsUseCaseImplementation"],"mappings":";;;AAIO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,qCAAqC,gBAAgB;QACxED,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GetSettingsRepository, GetSettingsUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
2
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
3
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
4
|
+
import type { TransportSendData } from "../../types.js";
|
|
5
|
+
declare class MailerServiceImpl implements Abstraction.Interface {
|
|
6
|
+
private getSettingsRepository;
|
|
7
|
+
private transportFactories;
|
|
8
|
+
constructor(getSettingsRepository: GetSettingsRepository.Interface, transportFactories: MailTransportFactory.Interface[]);
|
|
9
|
+
sendMail<T = any>(data: TransportSendData): Abstraction.Return<T>;
|
|
10
|
+
private resolveTransport;
|
|
11
|
+
}
|
|
12
|
+
export declare const MailerService: typeof MailerServiceImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailerService/abstractions.js").IMailerService>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "../../domain/MailerService/errors.js";
|
|
4
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
5
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
6
|
+
class MailerServiceImpl {
|
|
7
|
+
constructor(getSettingsRepository, transportFactories){
|
|
8
|
+
this.getSettingsRepository = getSettingsRepository;
|
|
9
|
+
this.transportFactories = transportFactories;
|
|
10
|
+
}
|
|
11
|
+
async sendMail(data) {
|
|
12
|
+
const { factory, transport } = await this.resolveTransport();
|
|
13
|
+
if (!factory || !transport) return Result.fail(new NoTransportAvailableError());
|
|
14
|
+
try {
|
|
15
|
+
const response = await transport.send(data);
|
|
16
|
+
if (response.error) return Result.fail(new TransportSendError(response.error));
|
|
17
|
+
return Result.ok(response);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return Result.fail(new TransportSendError(error));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async resolveTransport() {
|
|
23
|
+
const factories = [
|
|
24
|
+
...this.transportFactories
|
|
25
|
+
].reverse();
|
|
26
|
+
for (const factory of factories){
|
|
27
|
+
const result = await this.getSettingsRepository.get(factory.name);
|
|
28
|
+
const { settings } = result.value;
|
|
29
|
+
if (factory.canUse(settings)) try {
|
|
30
|
+
const transport = await factory.createTransport(settings);
|
|
31
|
+
return {
|
|
32
|
+
factory,
|
|
33
|
+
transport
|
|
34
|
+
};
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new TransportCreateError(error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
factory: null,
|
|
41
|
+
transport: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const MailerService_MailerService = MailerService.createImplementation({
|
|
46
|
+
implementation: MailerServiceImpl,
|
|
47
|
+
dependencies: [
|
|
48
|
+
GetSettingsRepository,
|
|
49
|
+
[
|
|
50
|
+
MailTransportFactory,
|
|
51
|
+
{
|
|
52
|
+
multiple: true
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
export { MailerService_MailerService as MailerService };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=MailerService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/MailerService/MailerService.js","sources":["../../../src/features/MailerService/MailerService.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { MailerService as Abstraction } from \"~/domain/MailerService/abstractions.js\";\nimport {\n NoTransportAvailableError,\n TransportCreateError,\n TransportSendError\n} from \"~/domain/MailerService/errors.js\";\nimport { MailTransport, MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport { GetSettingsRepository } from \"../GetSettings/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(\n private getSettingsRepository: GetSettingsRepository.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async sendMail<T = any>(data: TransportSendData): Abstraction.Return<T> {\n const { factory, transport } = await this.resolveTransport();\n\n if (!factory || !transport) {\n return Result.fail(new NoTransportAvailableError());\n }\n\n try {\n const response = await transport.send(data);\n\n if (response.error) {\n return Result.fail(new TransportSendError(response.error));\n }\n\n return Result.ok(response);\n } catch (error) {\n return Result.fail(new TransportSendError(error));\n }\n }\n\n private async resolveTransport(): Promise<{\n factory: MailTransportFactory.Interface | null;\n transport: MailTransport.Interface | null;\n }> {\n const factories = [...this.transportFactories].reverse();\n\n for (const factory of factories) {\n const result = await this.getSettingsRepository.get(factory.name);\n const { settings } = result.value;\n\n if (!factory.canUse(settings)) {\n continue;\n }\n\n try {\n const transport = await factory.createTransport(settings!);\n return { factory, transport };\n } catch (error) {\n throw new TransportCreateError(error);\n }\n }\n\n return { factory: null, transport: null };\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [GetSettingsRepository, [MailTransportFactory, { multiple: true }]]\n});\n"],"names":["MailerServiceImpl","getSettingsRepository","transportFactories","data","factory","transport","Result","NoTransportAvailableError","response","TransportSendError","error","factories","result","settings","TransportCreateError","MailerService","Abstraction","GetSettingsRepository","MailTransportFactory"],"mappings":";;;;;AAWA,MAAMA;IACF,YACYC,qBAAsD,EACtDC,kBAAoD,CAC9D;aAFUD,qBAAqB,GAArBA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,SAAkBC,IAAuB,EAAyB;QACpE,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB;QAE1D,IAAI,CAACD,WAAW,CAACC,WACb,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YACA,MAAMC,WAAW,MAAMH,UAAU,IAAI,CAACF;YAEtC,IAAIK,SAAS,KAAK,EACd,OAAOF,OAAO,IAAI,CAAC,IAAIG,mBAAmBD,SAAS,KAAK;YAG5D,OAAOF,OAAO,EAAE,CAACE;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIG,mBAAmBC;QAC9C;IACJ;IAEA,MAAc,mBAGX;QACC,MAAMC,YAAY;eAAI,IAAI,CAAC,kBAAkB;SAAC,CAAC,OAAO;QAEtD,KAAK,MAAMP,WAAWO,UAAW;YAC7B,MAAMC,SAAS,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACR,QAAQ,IAAI;YAChE,MAAM,EAAES,QAAQ,EAAE,GAAGD,OAAO,KAAK;YAEjC,IAAKR,QAAQ,MAAM,CAACS,WAIpB,IAAI;gBACA,MAAMR,YAAY,MAAMD,QAAQ,eAAe,CAACS;gBAChD,OAAO;oBAAET;oBAASC;gBAAU;YAChC,EAAE,OAAOK,OAAO;gBACZ,MAAM,IAAII,qBAAqBJ;YACnC;QACJ;QAEA,OAAO;YAAE,SAAS;YAAM,WAAW;QAAK;IAC5C;AACJ;AAEO,MAAMK,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBhB;IAChB,cAAc;QAACiB;QAAuB;YAACC;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { MailerService } from "./MailerService.js";
|
|
3
|
+
const MailerServiceFeature = createFeature({
|
|
4
|
+
name: "Mailer/MailerService",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(MailerService).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { MailerServiceFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/MailerService/feature.js","sources":["../../../src/features/MailerService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerService } from \"./MailerService.js\";\n\nexport const MailerServiceFeature = createFeature({\n name: \"Mailer/MailerService\",\n register(container) {\n container.register(MailerService).inSingletonScope();\n }\n});\n"],"names":["MailerServiceFeature","createFeature","container","MailerService"],"mappings":";;AAGO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,eAAe,gBAAgB;IACtD;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
2
|
+
import { SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
|
+
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
|
+
declare class SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {
|
|
5
|
+
private keyValueStore;
|
|
6
|
+
private encryption;
|
|
7
|
+
constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface);
|
|
8
|
+
execute(input: SaveSettingsInput): SaveSettingsRepository.Return;
|
|
9
|
+
}
|
|
10
|
+
export declare const SaveSettingsRepositoryImplementation: typeof SaveSettingsRepositoryImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISaveSettingsRepository>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
3
|
+
import { SaveSettingsRepository } from "./abstractions.js";
|
|
4
|
+
import { SettingsPersistenceError } from "../../domain/errors.js";
|
|
5
|
+
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
6
|
+
import { MAILER_TRANSPORT_SETTINGS } from "../../constants.js";
|
|
7
|
+
const DEFAULT_PORT = 587;
|
|
8
|
+
class SaveSettingsRepositoryImpl {
|
|
9
|
+
constructor(keyValueStore, encryption){
|
|
10
|
+
this.keyValueStore = keyValueStore;
|
|
11
|
+
this.encryption = encryption;
|
|
12
|
+
}
|
|
13
|
+
async execute(input) {
|
|
14
|
+
const existingResult = await this.keyValueStore.get(MAILER_TRANSPORT_SETTINGS);
|
|
15
|
+
const existingSettings = existingResult.isOk() ? existingResult.value : null;
|
|
16
|
+
const transportSettings = existingSettings ?? {};
|
|
17
|
+
let passwordToStore = input.password || "";
|
|
18
|
+
if (!input.password && existingSettings) passwordToStore = await this.encryption.decrypt(transportSettings.password || "");
|
|
19
|
+
const encryptedPassword = await this.encryption.encrypt(passwordToStore);
|
|
20
|
+
const port = input.port ?? transportSettings.port ?? DEFAULT_PORT;
|
|
21
|
+
const data = {
|
|
22
|
+
host: input.host ?? transportSettings.host,
|
|
23
|
+
port,
|
|
24
|
+
secure: input.secure ?? transportSettings.secure ?? 465 === port,
|
|
25
|
+
user: input.user ?? transportSettings.user,
|
|
26
|
+
password: encryptedPassword,
|
|
27
|
+
from: input.from ?? transportSettings.from,
|
|
28
|
+
replyTo: input.replyTo ?? transportSettings.replyTo
|
|
29
|
+
};
|
|
30
|
+
const result = await this.keyValueStore.set(MAILER_TRANSPORT_SETTINGS, data);
|
|
31
|
+
if (result.isFail()) return Result.fail(new SettingsPersistenceError(result.error));
|
|
32
|
+
const { password: _password, ...savedSettings } = data;
|
|
33
|
+
return Result.ok(savedSettings);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({
|
|
37
|
+
implementation: SaveSettingsRepositoryImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
KeyValueStore,
|
|
40
|
+
Encryption
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
export { SaveSettingsRepositoryImplementation };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=SaveSettingsRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/SaveSettingsRepository.js","sources":["../../../src/features/SaveSettings/SaveSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { Encryption } from \"@webiny/api-core/features/encryption/index.js\";\nimport { SaveSettingsRepository, type SaveSettingsInput } from \"./abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SettingsPersistenceError } from \"~/domain/errors.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { MAILER_TRANSPORT_SETTINGS } from \"~/constants.js\";\n\nconst DEFAULT_PORT = 587;\n\nclass SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsRepository.Return {\n // Check if settings exist\n const existingResult =\n await this.keyValueStore.get<TransportSettings>(MAILER_TRANSPORT_SETTINGS);\n const existingSettings = existingResult.isOk() ? existingResult.value : null;\n const transportSettings: Partial<TransportSettings> = existingSettings ?? {};\n\n // If updating and no password provided, keep the existing password\n let passwordToStore = input.password || \"\";\n if (!input.password && existingSettings) {\n passwordToStore = await this.encryption.decrypt(transportSettings.password || \"\");\n }\n\n // Encrypt password\n const encryptedPassword = await this.encryption.encrypt(passwordToStore);\n\n // Prepare data\n const port = input.port ?? transportSettings.port ?? DEFAULT_PORT;\n\n const data = {\n host: input.host ?? transportSettings.host,\n port,\n secure: input.secure ?? transportSettings.secure ?? port === 465,\n user: input.user ?? transportSettings.user,\n password: encryptedPassword,\n from: input.from ?? transportSettings.from,\n replyTo: input.replyTo ?? transportSettings.replyTo\n };\n\n // Save settings.\n const result = await this.keyValueStore.set(MAILER_TRANSPORT_SETTINGS, data);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n // Return the stored state without the password. Callers that need the\n // plaintext password go through GetSettingsRepository.get(transportName).\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _password, ...savedSettings } = data as TransportSettings;\n return Result.ok(savedSettings);\n }\n}\n\nexport const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({\n implementation: SaveSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption]\n});\n"],"names":["DEFAULT_PORT","SaveSettingsRepositoryImpl","keyValueStore","encryption","input","existingResult","MAILER_TRANSPORT_SETTINGS","existingSettings","transportSettings","passwordToStore","encryptedPassword","port","data","result","Result","SettingsPersistenceError","_password","savedSettings","SaveSettingsRepositoryImplementation","SaveSettingsRepository","KeyValueStore","Encryption"],"mappings":";;;;;;AAQA,MAAMA,eAAe;AAErB,MAAMC;IACF,YACYC,aAAsC,EACtCC,UAAgC,CAC1C;aAFUD,aAAa,GAAbA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAwB,EAAiC;QAEnE,MAAMC,iBACF,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAoBC;QACpD,MAAMC,mBAAmBF,eAAe,IAAI,KAAKA,eAAe,KAAK,GAAG;QACxE,MAAMG,oBAAgDD,oBAAoB,CAAC;QAG3E,IAAIE,kBAAkBL,MAAM,QAAQ,IAAI;QACxC,IAAI,CAACA,MAAM,QAAQ,IAAIG,kBACnBE,kBAAkB,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD,kBAAkB,QAAQ,IAAI;QAIlF,MAAME,oBAAoB,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD;QAGxD,MAAME,OAAOP,MAAM,IAAI,IAAII,kBAAkB,IAAI,IAAIR;QAErD,MAAMY,OAAO;YACT,MAAMR,MAAM,IAAI,IAAII,kBAAkB,IAAI;YAC1CG;YACA,QAAQP,MAAM,MAAM,IAAII,kBAAkB,MAAM,IAAIG,AAAS,QAATA;YACpD,MAAMP,MAAM,IAAI,IAAII,kBAAkB,IAAI;YAC1C,UAAUE;YACV,MAAMN,MAAM,IAAI,IAAII,kBAAkB,IAAI;YAC1C,SAASJ,MAAM,OAAO,IAAII,kBAAkB,OAAO;QACvD;QAGA,MAAMK,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACP,2BAA2BM;QAEvE,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,yBAAyBF,OAAO,KAAK;QAMhE,MAAM,EAAE,UAAUG,SAAS,EAAE,GAAGC,eAAe,GAAGL;QAClD,OAAOE,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAMC,uCAAuCC,uBAAuB,oBAAoB,CAAC;IAC5F,gBAAgBlB;IAChB,cAAc;QAACmB;QAAeC;KAAW;AAC7C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { SaveSettingsUseCase, SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
5
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
6
|
+
declare class SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {
|
|
7
|
+
private identityContext;
|
|
8
|
+
private eventPublisher;
|
|
9
|
+
private repository;
|
|
10
|
+
private codeSettings;
|
|
11
|
+
private transportFactories;
|
|
12
|
+
constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisher.Interface, repository: SaveSettingsRepository.Interface, codeSettings: CodeMailerSettings.Interface, transportFactories: MailTransportFactory.Interface[]);
|
|
13
|
+
execute(input: SaveSettingsInput): SaveSettingsUseCase.Return;
|
|
14
|
+
}
|
|
15
|
+
export declare const SaveSettingsUseCaseImplementation: typeof SaveSettingsUseCaseImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISaveSettings>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { SaveSettingsRepository, SaveSettingsUseCase } from "./abstractions.js";
|
|
4
|
+
import { MailerSettingsAfterSaveEvent, MailerSettingsBeforeSaveEvent } from "./events.js";
|
|
5
|
+
import { saveValidation } from "./validation.js";
|
|
6
|
+
import { SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError } from "../../domain/errors.js";
|
|
7
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
9
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
10
|
+
class SaveSettingsUseCaseImpl {
|
|
11
|
+
constructor(identityContext, eventPublisher, repository, codeSettings, transportFactories){
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
this.eventPublisher = eventPublisher;
|
|
14
|
+
this.repository = repository;
|
|
15
|
+
this.codeSettings = codeSettings;
|
|
16
|
+
this.transportFactories = transportFactories;
|
|
17
|
+
}
|
|
18
|
+
async execute(input) {
|
|
19
|
+
const permission = await this.identityContext.getPermission("mailer.settings");
|
|
20
|
+
if (!permission) return Result.fail(new SettingsNotAuthorized());
|
|
21
|
+
const validationResult = saveValidation.safeParse(input);
|
|
22
|
+
if (!validationResult.success) return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
23
|
+
const isLockedByCode = this.transportFactories.some((f)=>null !== this.codeSettings.get(f.name));
|
|
24
|
+
if (isLockedByCode) return Result.fail(new SettingsLockedByCode());
|
|
25
|
+
const { password: _beforePassword, ...inputForEvent } = input;
|
|
26
|
+
const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({
|
|
27
|
+
input: inputForEvent
|
|
28
|
+
});
|
|
29
|
+
await this.eventPublisher.publish(beforeSaveEvent);
|
|
30
|
+
const result = await this.repository.execute(input);
|
|
31
|
+
if (result.isFail()) return Result.fail(new SettingsPersistenceError(result.error));
|
|
32
|
+
const afterSaveEvent = new MailerSettingsAfterSaveEvent({
|
|
33
|
+
settings: result.value
|
|
34
|
+
});
|
|
35
|
+
await this.eventPublisher.publish(afterSaveEvent);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({
|
|
40
|
+
implementation: SaveSettingsUseCaseImpl,
|
|
41
|
+
dependencies: [
|
|
42
|
+
IdentityContext,
|
|
43
|
+
EventPublisher,
|
|
44
|
+
SaveSettingsRepository,
|
|
45
|
+
CodeMailerSettings,
|
|
46
|
+
[
|
|
47
|
+
MailTransportFactory,
|
|
48
|
+
{
|
|
49
|
+
multiple: true
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
export { SaveSettingsUseCaseImplementation };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=SaveSettingsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/SaveSettingsUseCase.js","sources":["../../../src/features/SaveSettings/SaveSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n type SaveSettingsInput\n} from \"./abstractions.js\";\nimport { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from \"./events.js\";\nimport { saveValidation } from \"./validation.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CodeMailerSettings } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\n\nclass SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: SaveSettingsRepository.Interface,\n private codeSettings: CodeMailerSettings.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(\"mailer.settings\");\n\n if (!permission) {\n return Result.fail(new SettingsNotAuthorized());\n }\n\n const validationResult = saveValidation.safeParse(input);\n if (!validationResult.success) {\n return Result.fail(new SettingsValidationError(validationResult.error.issues));\n }\n\n /* Refuse when any registered transport has code-defined settings. */\n const isLockedByCode = this.transportFactories.some(\n f => this.codeSettings.get(f.name) !== null\n );\n\n if (isLockedByCode) {\n return Result.fail(new SettingsLockedByCode());\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _beforePassword, ...inputForEvent } = input;\n const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({ input: inputForEvent });\n await this.eventPublisher.publish(beforeSaveEvent);\n\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n const afterSaveEvent = new MailerSettingsAfterSaveEvent({ settings: result.value });\n await this.eventPublisher.publish(afterSaveEvent);\n\n return result;\n }\n}\n\nexport const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({\n implementation: SaveSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n EventPublisher,\n SaveSettingsRepository,\n CodeMailerSettings,\n [MailTransportFactory, { multiple: true }]\n ]\n});\n"],"names":["SaveSettingsUseCaseImpl","identityContext","eventPublisher","repository","codeSettings","transportFactories","input","permission","Result","SettingsNotAuthorized","validationResult","saveValidation","SettingsValidationError","isLockedByCode","f","SettingsLockedByCode","_beforePassword","inputForEvent","beforeSaveEvent","MailerSettingsBeforeSaveEvent","result","SettingsPersistenceError","afterSaveEvent","MailerSettingsAfterSaveEvent","SaveSettingsUseCaseImplementation","SaveSettingsUseCase","IdentityContext","EventPublisher","SaveSettingsRepository","CodeMailerSettings","MailTransportFactory"],"mappings":";;;;;;;;;AAmBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA4C,EAC5CC,YAA0C,EAC1CC,kBAAoD,CAC9D;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,YAAY,GAAZA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAwB,EAA8B;QAChE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAE5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,mBAAmBC,eAAe,SAAS,CAACL;QAClD,IAAI,CAACI,iBAAiB,OAAO,EACzB,OAAOF,OAAO,IAAI,CAAC,IAAII,wBAAwBF,iBAAiB,KAAK,CAAC,MAAM;QAIhF,MAAMG,iBAAiB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAC/CC,CAAAA,IAAK,AAAkC,SAAlC,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,EAAE,IAAI;QAGrC,IAAID,gBACA,OAAOL,OAAO,IAAI,CAAC,IAAIO;QAI3B,MAAM,EAAE,UAAUC,eAAe,EAAE,GAAGC,eAAe,GAAGX;QACxD,MAAMY,kBAAkB,IAAIC,8BAA8B;YAAE,OAAOF;QAAc;QACjF,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACC;QAElC,MAAME,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACd;QAE7C,IAAIc,OAAO,MAAM,IACb,OAAOZ,OAAO,IAAI,CAAC,IAAIa,yBAAyBD,OAAO,KAAK;QAGhE,MAAME,iBAAiB,IAAIC,6BAA6B;YAAE,UAAUH,OAAO,KAAK;QAAC;QACjF,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACE;QAElC,OAAOF;IACX;AACJ;AAEO,MAAMI,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgBzB;IAChB,cAAc;QACV0B;QACAC;QACAC;QACAC;QACA;YAACC;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAC7C;AACL"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import type { TransportSettings } from "../../types.js";
|
|
4
|
+
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized, SettingsLockedByCode } from "../../domain/errors.js";
|
|
5
|
+
export interface SaveSettingsInput {
|
|
6
|
+
host: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
user: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
from: string;
|
|
12
|
+
replyTo?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ISaveSettingsErrors {
|
|
15
|
+
validation: SettingsValidationError;
|
|
16
|
+
persistence: SettingsPersistenceError;
|
|
17
|
+
notAuthorized: SettingsNotAuthorized;
|
|
18
|
+
lockedByCode: SettingsLockedByCode;
|
|
19
|
+
}
|
|
20
|
+
type SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];
|
|
21
|
+
/**
|
|
22
|
+
* Save-side returns are password-free. The only path that exposes the password
|
|
23
|
+
* to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute
|
|
24
|
+
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
25
|
+
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
26
|
+
*/
|
|
27
|
+
export type SavedTransportSettings = Omit<TransportSettings, "password">;
|
|
28
|
+
export interface ISaveSettingsRepository {
|
|
29
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const SaveSettingsRepository: import("@webiny/di").Abstraction<ISaveSettingsRepository>;
|
|
32
|
+
export declare namespace SaveSettingsRepository {
|
|
33
|
+
type Interface = ISaveSettingsRepository;
|
|
34
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
35
|
+
type Error = SaveSettingsError;
|
|
36
|
+
}
|
|
37
|
+
export interface ISaveSettings {
|
|
38
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
39
|
+
}
|
|
40
|
+
export declare const SaveSettingsUseCase: import("@webiny/di").Abstraction<ISaveSettings>;
|
|
41
|
+
export declare namespace SaveSettingsUseCase {
|
|
42
|
+
type Interface = ISaveSettings;
|
|
43
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
44
|
+
type Error = SaveSettingsError;
|
|
45
|
+
}
|
|
46
|
+
export interface MailerSettingsBeforeSavePayload {
|
|
47
|
+
input: Omit<SaveSettingsInput, "password">;
|
|
48
|
+
}
|
|
49
|
+
export interface MailerSettingsAfterSavePayload {
|
|
50
|
+
settings: Omit<TransportSettings, "password">;
|
|
51
|
+
}
|
|
52
|
+
export declare const MailerSettingsBeforeSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
53
|
+
export declare namespace MailerSettingsBeforeSaveEventHandler {
|
|
54
|
+
type Interface = IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>;
|
|
55
|
+
type Event = DomainEvent<MailerSettingsBeforeSavePayload>;
|
|
56
|
+
}
|
|
57
|
+
export declare const MailerSettingsAfterSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>>;
|
|
58
|
+
export declare namespace MailerSettingsAfterSaveEventHandler {
|
|
59
|
+
type Interface = IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>;
|
|
60
|
+
type Event = DomainEvent<MailerSettingsAfterSavePayload>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const SaveSettingsRepository = createAbstraction("SaveSettingsRepository");
|
|
3
|
+
const SaveSettingsUseCase = createAbstraction("SaveSettingsUseCase");
|
|
4
|
+
const MailerSettingsBeforeSaveEventHandler = createAbstraction("MailerSettingsBeforeSaveEventHandler");
|
|
5
|
+
const MailerSettingsAfterSaveEventHandler = createAbstraction("MailerSettingsAfterSaveEventHandler");
|
|
6
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/abstractions.js","sources":["../../../src/features/SaveSettings/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 { TransportSettings } from \"~/types.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\n\nexport interface SaveSettingsInput {\n host: string;\n port?: number;\n secure?: boolean;\n user: string;\n password?: string;\n from: string;\n replyTo?: string;\n}\n\nexport interface ISaveSettingsErrors {\n validation: SettingsValidationError;\n persistence: SettingsPersistenceError;\n notAuthorized: SettingsNotAuthorized;\n lockedByCode: SettingsLockedByCode;\n}\n\ntype SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];\n\n/**\n * Save-side returns are password-free. The only path that exposes the password\n * to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute\n * (used by MailerService to authenticate SMTP). Everything else — events,\n * GraphQL responses, logs, audit trails — must use this Omit shape.\n */\nexport type SavedTransportSettings = Omit<TransportSettings, \"password\">;\n\nexport interface ISaveSettingsRepository {\n execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n}\n\nexport const SaveSettingsRepository =\n createAbstraction<ISaveSettingsRepository>(\"SaveSettingsRepository\");\n\nexport namespace SaveSettingsRepository {\n export type Interface = ISaveSettingsRepository;\n export type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n export type Error = SaveSettingsError;\n}\n\nexport interface ISaveSettings {\n execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n}\n\nexport const SaveSettingsUseCase = createAbstraction<ISaveSettings>(\"SaveSettingsUseCase\");\n\nexport namespace SaveSettingsUseCase {\n export type Interface = ISaveSettings;\n export type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n export type Error = SaveSettingsError;\n}\n\n// Domain Events. Both payloads exclude `password` so subscribers (audit logs,\n// telemetry, etc.) cannot accidentally persist plaintext or ciphertext secrets.\nexport interface MailerSettingsBeforeSavePayload {\n input: Omit<SaveSettingsInput, \"password\">;\n}\n\nexport interface MailerSettingsAfterSavePayload {\n settings: Omit<TransportSettings, \"password\">;\n}\n\n// Event Handler Abstractions\nexport const MailerSettingsBeforeSaveEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>\n>(\"MailerSettingsBeforeSaveEventHandler\");\n\nexport namespace MailerSettingsBeforeSaveEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>;\n export type Event = DomainEvent<MailerSettingsBeforeSavePayload>;\n}\n\nexport const MailerSettingsAfterSaveEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>\n>(\"MailerSettingsAfterSaveEventHandler\");\n\nexport namespace MailerSettingsAfterSaveEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>;\n export type Event = DomainEvent<MailerSettingsAfterSavePayload>;\n}\n"],"names":["SaveSettingsRepository","createAbstraction","SaveSettingsUseCase","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEventHandler"],"mappings":";AA0CO,MAAMA,yBACTC,kBAA2C;AAYxC,MAAMC,sBAAsBD,kBAAiC;AAmB7D,MAAME,uCAAuCF,kBAElD;AAOK,MAAMG,sCAAsCH,kBAEjD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import type { MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./abstractions.js";
|
|
3
|
+
export declare class MailerSettingsBeforeSaveEvent extends DomainEvent<MailerSettingsBeforeSavePayload> {
|
|
4
|
+
eventType: "mailer.settings.beforeSave";
|
|
5
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class MailerSettingsAfterSaveEvent extends DomainEvent<MailerSettingsAfterSavePayload> {
|
|
8
|
+
eventType: "mailer.settings.afterSave";
|
|
9
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
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
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class MailerSettingsAfterSaveEvent extends DomainEvent {
|
|
12
|
+
getHandlerAbstraction() {
|
|
13
|
+
return MailerSettingsAfterSaveEventHandler;
|
|
14
|
+
}
|
|
15
|
+
constructor(...args){
|
|
16
|
+
super(...args), this.eventType = "mailer.settings.afterSave";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export { MailerSettingsAfterSaveEvent, MailerSettingsBeforeSaveEvent };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SaveSettingsRepositoryImplementation } from "./SaveSettingsRepository.js";
|
|
3
|
+
import { SaveSettingsUseCaseImplementation } from "./SaveSettingsUseCase.js";
|
|
4
|
+
const SaveSettingsFeature = createFeature({
|
|
5
|
+
name: "SaveSettings",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(SaveSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(SaveSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { SaveSettingsFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -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: \"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 @@
|
|
|
1
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
export declare const saveValidation: zod.ZodObject<{
|
|
3
|
+
from: zod.ZodString;
|
|
4
|
+
port: zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodNumber>>>;
|
|
5
|
+
replyTo: zod.ZodPreprocess<zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodString>>>>;
|
|
6
|
+
host: zod.ZodString;
|
|
7
|
+
user: zod.ZodString;
|
|
8
|
+
secure: zod.ZodOptional<zod.ZodBoolean>;
|
|
9
|
+
password: zod.ZodPipe<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodString>>>, zod.ZodTransform<string | null, string | null | undefined>>;
|
|
10
|
+
}, zod.core.$strip>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
3
|
+
const validation_password = zod.string().describe("Password");
|
|
4
|
+
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
5
|
+
message: "Invalid email address."
|
|
6
|
+
});
|
|
7
|
+
const common = {
|
|
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")
|
|
13
|
+
};
|
|
14
|
+
const saveValidation = zod.object({
|
|
15
|
+
...common,
|
|
16
|
+
secure: zod.boolean().optional().describe("Use TLS/SSL"),
|
|
17
|
+
password: validation_password.nullish().optional().transform((value)=>void 0 === value ? null : value)
|
|
18
|
+
});
|
|
19
|
+
export { saveValidation };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 secure: zod.boolean().optional().describe(\"Use TLS/SSL\"),\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,QAAQH,IAAI,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,UAAUD,oBACL,OAAO,GACP,QAAQ,GACR,SAAS,CAACK,CAAAA,QACAA,AAAUE,WAAVF,QAAsB,OAAOA;AAEhD"}
|
|
@@ -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
|