@webiny/api-mailer 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -13
- package/constants.d.ts +1 -0
- package/constants.js +3 -0
- package/constants.js.map +1 -0
- package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +4 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +26 -0
- package/domain/MailTransport/abstractions.js +6 -0
- package/domain/MailTransport/abstractions.js.map +1 -0
- package/domain/MailerService/abstractions.d.ts +19 -0
- package/domain/MailerService/abstractions.js +4 -0
- package/domain/MailerService/abstractions.js.map +1 -0
- package/domain/MailerService/errors.d.ts +16 -0
- package/domain/MailerService/errors.js +30 -0
- package/domain/MailerService/errors.js.map +1 -0
- package/domain/errors.d.ts +28 -0
- package/domain/errors.js +52 -0
- package/domain/errors.js.map +1 -0
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +6 -0
- package/exports/api/mailer.js.map +1 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +22 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +10 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransport.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransport.js +12 -0
- package/features/DummyTransport/DummyMailTransport.js.map +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +9 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +14 -0
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -0
- package/features/DummyTransport/feature.d.ts +4 -0
- package/features/DummyTransport/feature.js +10 -0
- package/features/DummyTransport/feature.js.map +1 -0
- package/features/GetSettings/GetSettingsRepository.d.ts +16 -0
- package/features/GetSettings/GetSettingsRepository.js +58 -0
- package/features/GetSettings/GetSettingsRepository.js.map +1 -0
- package/features/GetSettings/GetSettingsUseCase.d.ts +11 -0
- package/features/GetSettings/GetSettingsUseCase.js +15 -0
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -0
- package/features/GetSettings/abstractions.d.ts +22 -0
- package/features/GetSettings/abstractions.js +5 -0
- package/features/GetSettings/abstractions.js.map +1 -0
- package/features/GetSettings/feature.d.ts +4 -0
- package/features/GetSettings/feature.js +12 -0
- package/features/GetSettings/feature.js.map +1 -0
- package/features/GetSettings/index.d.ts +1 -0
- package/features/GetSettings/index.js +3 -0
- package/features/GetSettings/index.js.map +1 -0
- package/features/MailerService/ActiveTransport.d.ts +10 -0
- package/features/MailerService/ActiveTransport.js +20 -0
- package/features/MailerService/ActiveTransport.js.map +1 -0
- package/features/MailerService/MailerService.d.ts +16 -0
- package/features/MailerService/MailerService.js +53 -0
- package/features/MailerService/MailerService.js.map +1 -0
- package/features/MailerService/feature.d.ts +4 -0
- package/features/MailerService/feature.js +12 -0
- package/features/MailerService/feature.js.map +1 -0
- package/features/SaveSettings/SaveSettingsRepository.d.ts +13 -0
- package/features/SaveSettings/SaveSettingsRepository.js +59 -0
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -0
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +18 -0
- package/features/SaveSettings/SaveSettingsUseCase.js +69 -0
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -0
- package/features/SaveSettings/abstractions.d.ts +61 -0
- package/features/SaveSettings/abstractions.js +20 -0
- package/features/SaveSettings/abstractions.js.map +1 -0
- package/features/SaveSettings/events.d.ts +10 -0
- package/features/SaveSettings/events.js +16 -0
- package/features/SaveSettings/events.js.map +1 -0
- package/features/SaveSettings/feature.d.ts +4 -0
- package/features/SaveSettings/feature.js +12 -0
- package/features/SaveSettings/feature.js.map +1 -0
- package/features/SaveSettings/index.d.ts +1 -0
- package/features/SaveSettings/index.js +3 -0
- package/features/SaveSettings/index.js.map +1 -0
- package/features/SaveSettings/validation.d.ts +9 -0
- package/features/SaveSettings/validation.js +23 -0
- package/features/SaveSettings/validation.js.map +1 -0
- package/features/SendMail/SendMailUseCase.d.ts +16 -0
- package/features/SendMail/SendMailUseCase.js +65 -0
- package/features/SendMail/SendMailUseCase.js.map +1 -0
- package/features/SendMail/abstractions.d.ts +45 -0
- package/features/SendMail/abstractions.js +11 -0
- package/features/SendMail/abstractions.js.map +1 -0
- package/features/SendMail/events.d.ts +14 -0
- package/features/SendMail/events.js +22 -0
- package/features/SendMail/events.js.map +1 -0
- package/features/SendMail/feature.d.ts +4 -0
- package/features/SendMail/feature.js +10 -0
- package/features/SendMail/feature.js.map +1 -0
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +3 -0
- package/features/SendMail/index.js.map +1 -0
- package/features/SmtpTransport/SmtpConfig.d.ts +6 -0
- package/features/SmtpTransport/SmtpConfig.js +29 -0
- package/features/SmtpTransport/SmtpConfig.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +68 -0
- package/features/SmtpTransport/SmtpMailTransport.js +67 -0
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +10 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +15 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -0
- package/features/SmtpTransport/feature.d.ts +4 -0
- package/features/SmtpTransport/feature.js +10 -0
- package/features/SmtpTransport/feature.js.map +1 -0
- package/graphql/settings.d.ts +2 -2
- package/graphql/settings.js +60 -36
- package/graphql/settings.js.map +1 -1
- package/index.d.ts +4 -5
- package/index.js +22 -78
- package/index.js.map +1 -1
- package/package.json +27 -31
- package/types.d.ts +0 -107
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/isMailboxAddress.d.ts +6 -0
- package/utils/isMailboxAddress.js +12 -0
- package/utils/isMailboxAddress.js.map +1 -0
- package/context.d.ts +0 -3
- package/context.js +0 -20
- package/context.js.map +0 -1
- package/crud/settings/hooks.d.ts +0 -5
- package/crud/settings/hooks.js +0 -42
- package/crud/settings/hooks.js.map +0 -1
- package/crud/settings/model.d.ts +0 -2
- package/crud/settings/model.js +0 -72
- package/crud/settings/model.js.map +0 -1
- package/crud/settings/password.d.ts +0 -7
- package/crud/settings/password.js +0 -55
- package/crud/settings/password.js.map +0 -1
- package/crud/settings/secret.d.ts +0 -1
- package/crud/settings/secret.js +0 -19
- package/crud/settings/secret.js.map +0 -1
- package/crud/settings/transform.d.ts +0 -13
- package/crud/settings/transform.js +0 -46
- package/crud/settings/transform.js.map +0 -1
- package/crud/settings/validation.d.ts +0 -45
- package/crud/settings/validation.js +0 -28
- package/crud/settings/validation.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -5
- package/crud/settings.crud.js +0 -269
- package/crud/settings.crud.js.map +0 -1
- package/crud/transport/onTransportBeforeSend.d.ts +0 -7
- package/crud/transport/onTransportBeforeSend.js +0 -62
- package/crud/transport/onTransportBeforeSend.js.map +0 -1
- package/crud/transporter.crud.d.ts +0 -2
- package/crud/transporter.crud.js +0 -158
- package/crud/transporter.crud.js.map +0 -1
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +0 -13
- package/graphql/index.js.map +0 -1
- package/plugins/CreateTransportPlugin.d.ts +0 -17
- package/plugins/CreateTransportPlugin.js +0 -24
- package/plugins/CreateTransportPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -1
- package/plugins/index.js +0 -18
- package/plugins/index.js.map +0 -1
- package/transports/createDummyTransport.d.ts +0 -5
- package/transports/createDummyTransport.js +0 -25
- package/transports/createDummyTransport.js.map +0 -1
- package/transports/createSmtpTransport.d.ts +0 -13
- package/transports/createSmtpTransport.js +0 -94
- package/transports/createSmtpTransport.js.map +0 -1
- package/transports/index.d.ts +0 -2
- package/transports/index.js +0 -29
- package/transports/index.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetSettingsRepositoryImplementation } from "./GetSettingsRepository.js";
|
|
3
|
+
import { GetSettingsUseCaseImplementation } from "./GetSettingsUseCase.js";
|
|
4
|
+
export const GetSettingsFeature = createFeature({
|
|
5
|
+
name: "GetSettings",
|
|
6
|
+
register(container) {
|
|
7
|
+
container.register(GetSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(GetSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","GetSettingsRepositoryImplementation","GetSettingsUseCaseImplementation","GetSettingsFeature","name","register","container","inSingletonScope"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,mCAAmC;AAC5C,SAASC,gCAAgC;AAEzC,OAAO,MAAMC,kBAAkB,GAAGH,aAAa,CAAC;EAC5CI,IAAI,EAAE,aAAa;EACnBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACJ,mCAAmC,CAAC,CAACM,gBAAgB,CAAC,CAAC;IAC1ED,SAAS,CAACD,QAAQ,CAACH,gCAAgC,CAAC;EACxD;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GetSettingsUseCase","GetSettingsRepository"],"sources":["index.ts"],"sourcesContent":["export { GetSettingsUseCase, GetSettingsRepository } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActiveTransport as ActiveTransportAbstraction, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
declare class ActiveTransportImpl implements ActiveTransportAbstraction.Interface {
|
|
3
|
+
private transportFactories;
|
|
4
|
+
constructor(transportFactories: MailTransportFactory.Interface[]);
|
|
5
|
+
name(): string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare const ActiveTransport: typeof ActiveTransportImpl & {
|
|
8
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IActiveTransport>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActiveTransport as ActiveTransportAbstraction, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
class ActiveTransportImpl {
|
|
3
|
+
constructor(transportFactories) {
|
|
4
|
+
this.transportFactories = transportFactories;
|
|
5
|
+
}
|
|
6
|
+
name() {
|
|
7
|
+
if (this.transportFactories.length === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return this.transportFactories[this.transportFactories.length - 1].name;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const ActiveTransport = ActiveTransportAbstraction.createImplementation({
|
|
14
|
+
implementation: ActiveTransportImpl,
|
|
15
|
+
dependencies: [[MailTransportFactory, {
|
|
16
|
+
multiple: true
|
|
17
|
+
}]]
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=ActiveTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ActiveTransport","ActiveTransportAbstraction","MailTransportFactory","ActiveTransportImpl","constructor","transportFactories","name","length","createImplementation","implementation","dependencies","multiple"],"sources":["ActiveTransport.ts"],"sourcesContent":["import {\n ActiveTransport as ActiveTransportAbstraction,\n MailTransportFactory\n} from \"~/domain/MailTransport/abstractions.js\";\n\nclass ActiveTransportImpl implements ActiveTransportAbstraction.Interface {\n constructor(private transportFactories: MailTransportFactory.Interface[]) {}\n\n name(): string | null {\n if (this.transportFactories.length === 0) {\n return null;\n }\n return this.transportFactories[this.transportFactories.length - 1].name;\n }\n}\n\nexport const ActiveTransport = ActiveTransportAbstraction.createImplementation({\n implementation: ActiveTransportImpl,\n dependencies: [[MailTransportFactory, { multiple: true }]]\n});\n"],"mappings":"AAAA,SACIA,eAAe,IAAIC,0BAA0B,EAC7CC,oBAAoB;AAGxB,MAAMC,mBAAmB,CAAiD;EACtEC,WAAWA,CAASC,kBAAoD,EAAE;IAAA,KAAtDA,kBAAoD,GAApDA,kBAAoD;EAAG;EAE3EC,IAAIA,CAAA,EAAkB;IAClB,IAAI,IAAI,CAACD,kBAAkB,CAACE,MAAM,KAAK,CAAC,EAAE;MACtC,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACF,kBAAkB,CAAC,IAAI,CAACA,kBAAkB,CAACE,MAAM,GAAG,CAAC,CAAC,CAACD,IAAI;EAC3E;AACJ;AAEA,OAAO,MAAMN,eAAe,GAAGC,0BAA0B,CAACO,oBAAoB,CAAC;EAC3EC,cAAc,EAAEN,mBAAmB;EACnCO,YAAY,EAAE,CAAC,CAACR,oBAAoB,EAAE;IAAES,QAAQ,EAAE;EAAK,CAAC,CAAC;AAC7D,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
2
|
+
import { ActiveTransport, 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 activeTransport;
|
|
8
|
+
private transportFactories;
|
|
9
|
+
constructor(getSettingsRepository: GetSettingsRepository.Interface, activeTransport: ActiveTransport.Interface, transportFactories: MailTransportFactory.Interface[]);
|
|
10
|
+
sendMail<T = any>(data: TransportSendData): Abstraction.Return<T>;
|
|
11
|
+
private getTransport;
|
|
12
|
+
}
|
|
13
|
+
export declare const MailerService: typeof MailerServiceImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailerService/abstractions.js").IMailerService>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
import { NoTransportAvailableError, NoSettingsConfiguredError, TransportSendError } from "../../domain/MailerService/errors.js";
|
|
4
|
+
import { ActiveTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
5
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
6
|
+
class MailerServiceImpl {
|
|
7
|
+
constructor(getSettingsRepository, activeTransport, transportFactories) {
|
|
8
|
+
this.getSettingsRepository = getSettingsRepository;
|
|
9
|
+
this.activeTransport = activeTransport;
|
|
10
|
+
this.transportFactories = transportFactories;
|
|
11
|
+
}
|
|
12
|
+
async sendMail(data) {
|
|
13
|
+
const transportName = this.activeTransport.name();
|
|
14
|
+
if (!transportName) {
|
|
15
|
+
return Result.fail(new NoTransportAvailableError());
|
|
16
|
+
}
|
|
17
|
+
const result = await this.getSettingsRepository.get(transportName);
|
|
18
|
+
const {
|
|
19
|
+
settings
|
|
20
|
+
} = result.value;
|
|
21
|
+
if (!settings) {
|
|
22
|
+
return Result.fail(new NoSettingsConfiguredError());
|
|
23
|
+
}
|
|
24
|
+
const transport = await this.getTransport(transportName, settings);
|
|
25
|
+
if (!transport) {
|
|
26
|
+
return Result.fail(new NoTransportAvailableError());
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const response = await transport.send(data);
|
|
30
|
+
if (response.error) {
|
|
31
|
+
return Result.fail(new TransportSendError(response.error));
|
|
32
|
+
}
|
|
33
|
+
return Result.ok(response);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return Result.fail(new TransportSendError(error));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async getTransport(transportName, settings) {
|
|
39
|
+
const factory = this.transportFactories.find(f => f.name === transportName);
|
|
40
|
+
if (!factory) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return factory.createTransport(settings);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const MailerService = Abstraction.createImplementation({
|
|
47
|
+
implementation: MailerServiceImpl,
|
|
48
|
+
dependencies: [GetSettingsRepository, ActiveTransport, [MailTransportFactory, {
|
|
49
|
+
multiple: true
|
|
50
|
+
}]]
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=MailerService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","MailerService","Abstraction","NoTransportAvailableError","NoSettingsConfiguredError","TransportSendError","ActiveTransport","MailTransportFactory","GetSettingsRepository","MailerServiceImpl","constructor","getSettingsRepository","activeTransport","transportFactories","sendMail","data","transportName","name","fail","result","get","settings","value","transport","getTransport","response","send","error","ok","factory","find","f","createTransport","createImplementation","implementation","dependencies","multiple"],"sources":["MailerService.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { MailerService as Abstraction } from \"~/domain/MailerService/abstractions.js\";\nimport {\n NoTransportAvailableError,\n NoSettingsConfiguredError,\n TransportSendError\n} from \"~/domain/MailerService/errors.js\";\nimport {\n ActiveTransport,\n MailTransport,\n MailTransportFactory\n} from \"~/domain/MailTransport/abstractions.js\";\nimport { GetSettingsRepository } from \"../GetSettings/abstractions.js\";\nimport type { TransportSettings, TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(\n private getSettingsRepository: GetSettingsRepository.Interface,\n private activeTransport: ActiveTransport.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async sendMail<T = any>(data: TransportSendData): Abstraction.Return<T> {\n const transportName = this.activeTransport.name();\n\n if (!transportName) {\n return Result.fail(new NoTransportAvailableError());\n }\n\n const result = await this.getSettingsRepository.get(transportName);\n const { settings } = result.value;\n\n if (!settings) {\n return Result.fail(new NoSettingsConfiguredError());\n }\n\n const transport = await this.getTransport(transportName, settings);\n\n if (!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 getTransport(\n transportName: string,\n settings: TransportSettings\n ): Promise<MailTransport.Interface | null> {\n const factory = this.transportFactories.find(f => f.name === transportName);\n if (!factory) {\n return null;\n }\n return factory.createTransport(settings);\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [\n GetSettingsRepository,\n ActiveTransport,\n [MailTransportFactory, { multiple: true }]\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,aAAa,IAAIC,WAAW;AACrC,SACIC,yBAAyB,EACzBC,yBAAyB,EACzBC,kBAAkB;AAEtB,SACIC,eAAe,EAEfC,oBAAoB;AAExB,SAASC,qBAAqB;AAG9B,MAAMC,iBAAiB,CAAkC;EACrDC,WAAWA,CACCC,qBAAsD,EACtDC,eAA0C,EAC1CC,kBAAoD,EAC9D;IAAA,KAHUF,qBAAsD,GAAtDA,qBAAsD;IAAA,KACtDC,eAA0C,GAA1CA,eAA0C;IAAA,KAC1CC,kBAAoD,GAApDA,kBAAoD;EAC7D;EAEH,MAAMC,QAAQA,CAAUC,IAAuB,EAAyB;IACpE,MAAMC,aAAa,GAAG,IAAI,CAACJ,eAAe,CAACK,IAAI,CAAC,CAAC;IAEjD,IAAI,CAACD,aAAa,EAAE;MAChB,OAAOhB,MAAM,CAACkB,IAAI,CAAC,IAAIf,yBAAyB,CAAC,CAAC,CAAC;IACvD;IAEA,MAAMgB,MAAM,GAAG,MAAM,IAAI,CAACR,qBAAqB,CAACS,GAAG,CAACJ,aAAa,CAAC;IAClE,MAAM;MAAEK;IAAS,CAAC,GAAGF,MAAM,CAACG,KAAK;IAEjC,IAAI,CAACD,QAAQ,EAAE;MACX,OAAOrB,MAAM,CAACkB,IAAI,CAAC,IAAId,yBAAyB,CAAC,CAAC,CAAC;IACvD;IAEA,MAAMmB,SAAS,GAAG,MAAM,IAAI,CAACC,YAAY,CAACR,aAAa,EAAEK,QAAQ,CAAC;IAElE,IAAI,CAACE,SAAS,EAAE;MACZ,OAAOvB,MAAM,CAACkB,IAAI,CAAC,IAAIf,yBAAyB,CAAC,CAAC,CAAC;IACvD;IAEA,IAAI;MACA,MAAMsB,QAAQ,GAAG,MAAMF,SAAS,CAACG,IAAI,CAACX,IAAI,CAAC;MAE3C,IAAIU,QAAQ,CAACE,KAAK,EAAE;QAChB,OAAO3B,MAAM,CAACkB,IAAI,CAAC,IAAIb,kBAAkB,CAACoB,QAAQ,CAACE,KAAK,CAAC,CAAC;MAC9D;MAEA,OAAO3B,MAAM,CAAC4B,EAAE,CAACH,QAAQ,CAAC;IAC9B,CAAC,CAAC,OAAOE,KAAK,EAAE;MACZ,OAAO3B,MAAM,CAACkB,IAAI,CAAC,IAAIb,kBAAkB,CAACsB,KAAK,CAAC,CAAC;IACrD;EACJ;EAEA,MAAcH,YAAYA,CACtBR,aAAqB,EACrBK,QAA2B,EACY;IACvC,MAAMQ,OAAO,GAAG,IAAI,CAAChB,kBAAkB,CAACiB,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACd,IAAI,KAAKD,aAAa,CAAC;IAC3E,IAAI,CAACa,OAAO,EAAE;MACV,OAAO,IAAI;IACf;IACA,OAAOA,OAAO,CAACG,eAAe,CAACX,QAAQ,CAAC;EAC5C;AACJ;AAEA,OAAO,MAAMpB,aAAa,GAAGC,WAAW,CAAC+B,oBAAoB,CAAC;EAC1DC,cAAc,EAAEzB,iBAAiB;EACjC0B,YAAY,EAAE,CACV3B,qBAAqB,EACrBF,eAAe,EACf,CAACC,oBAAoB,EAAE;IAAE6B,QAAQ,EAAE;EAAK,CAAC,CAAC;AAElD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { MailerService } from "./MailerService.js";
|
|
3
|
+
import { ActiveTransport } from "./ActiveTransport.js";
|
|
4
|
+
export const MailerServiceFeature = createFeature({
|
|
5
|
+
name: "Mailer/MailerService",
|
|
6
|
+
register(container) {
|
|
7
|
+
container.register(ActiveTransport).inSingletonScope();
|
|
8
|
+
container.register(MailerService).inSingletonScope();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","MailerService","ActiveTransport","MailerServiceFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerService } from \"./MailerService.js\";\nimport { ActiveTransport } from \"./ActiveTransport.js\";\n\nexport const MailerServiceFeature = createFeature({\n name: \"Mailer/MailerService\",\n register(container) {\n container.register(ActiveTransport).inSingletonScope();\n container.register(MailerService).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,aAAa;AACtB,SAASC,eAAe;AAExB,OAAO,MAAMC,oBAAoB,GAAGH,aAAa,CAAC;EAC9CI,IAAI,EAAE,sBAAsB;EAC5BC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,eAAe,CAAC,CAACK,gBAAgB,CAAC,CAAC;IACtDD,SAAS,CAACD,QAAQ,CAACJ,aAAa,CAAC,CAACM,gBAAgB,CAAC,CAAC;EACxD;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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,59 @@
|
|
|
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 = 25;
|
|
8
|
+
class SaveSettingsRepositoryImpl {
|
|
9
|
+
constructor(keyValueStore, encryption) {
|
|
10
|
+
this.keyValueStore = keyValueStore;
|
|
11
|
+
this.encryption = encryption;
|
|
12
|
+
}
|
|
13
|
+
async execute(input) {
|
|
14
|
+
// Check if settings exist
|
|
15
|
+
const existingResult = await this.keyValueStore.get(MAILER_TRANSPORT_SETTINGS);
|
|
16
|
+
const existingSettings = existingResult.isOk() ? existingResult.value : null;
|
|
17
|
+
const transportSettings = existingSettings ?? {};
|
|
18
|
+
|
|
19
|
+
// If updating and no password provided, keep the existing password
|
|
20
|
+
let passwordToStore = input.password || "";
|
|
21
|
+
if (!input.password && existingSettings) {
|
|
22
|
+
passwordToStore = this.encryption.decrypt(transportSettings.password || "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Encrypt password
|
|
26
|
+
const encryptedPassword = this.encryption.encrypt(passwordToStore);
|
|
27
|
+
|
|
28
|
+
// Prepare data
|
|
29
|
+
const data = {
|
|
30
|
+
host: input.host ?? transportSettings.host,
|
|
31
|
+
port: input.port ?? transportSettings.port ?? DEFAULT_PORT,
|
|
32
|
+
user: input.user ?? transportSettings.user,
|
|
33
|
+
password: encryptedPassword,
|
|
34
|
+
from: input.from ?? transportSettings.from,
|
|
35
|
+
replyTo: input.replyTo ?? transportSettings.replyTo
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Save settings.
|
|
39
|
+
const result = await this.keyValueStore.set(MAILER_TRANSPORT_SETTINGS, data);
|
|
40
|
+
if (result.isFail()) {
|
|
41
|
+
return Result.fail(new SettingsPersistenceError(result.error));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Return the stored state without the password. Callers that need the
|
|
45
|
+
// plaintext password go through GetSettingsRepository.get(transportName).
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
+
const {
|
|
48
|
+
password: _password,
|
|
49
|
+
...savedSettings
|
|
50
|
+
} = data;
|
|
51
|
+
return Result.ok(savedSettings);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({
|
|
55
|
+
implementation: SaveSettingsRepositoryImpl,
|
|
56
|
+
dependencies: [KeyValueStore, Encryption]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=SaveSettingsRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","Encryption","SaveSettingsRepository","SettingsPersistenceError","KeyValueStore","MAILER_TRANSPORT_SETTINGS","DEFAULT_PORT","SaveSettingsRepositoryImpl","constructor","keyValueStore","encryption","execute","input","existingResult","get","existingSettings","isOk","value","transportSettings","passwordToStore","password","decrypt","encryptedPassword","encrypt","data","host","port","user","from","replyTo","result","set","isFail","fail","error","_password","savedSettings","ok","SaveSettingsRepositoryImplementation","createImplementation","implementation","dependencies"],"sources":["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 = 25;\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 = this.encryption.decrypt(transportSettings.password || \"\");\n }\n\n // Encrypt password\n const encryptedPassword = this.encryption.encrypt(passwordToStore);\n\n // Prepare data\n const data = {\n host: input.host ?? transportSettings.host,\n port: input.port ?? transportSettings.port ?? DEFAULT_PORT,\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"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,UAAU,QAAQ,+CAA+C;AAC1E,SAASC,sBAAsB;AAE/B,SAASC,wBAAwB;AACjC,SAASC,aAAa,QAAQ,kDAAkD;AAChF,SAASC,yBAAyB;AAElC,MAAMC,YAAY,GAAG,EAAE;AAEvB,MAAMC,0BAA0B,CAA6C;EACzEC,WAAWA,CACCC,aAAsC,EACtCC,UAAgC,EAC1C;IAAA,KAFUD,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,UAAgC,GAAhCA,UAAgC;EACzC;EAEH,MAAMC,OAAOA,CAACC,KAAwB,EAAiC;IACnE;IACA,MAAMC,cAAc,GAChB,MAAM,IAAI,CAACJ,aAAa,CAACK,GAAG,CAAoBT,yBAAyB,CAAC;IAC9E,MAAMU,gBAAgB,GAAGF,cAAc,CAACG,IAAI,CAAC,CAAC,GAAGH,cAAc,CAACI,KAAK,GAAG,IAAI;IAC5E,MAAMC,iBAA6C,GAAGH,gBAAgB,IAAI,CAAC,CAAC;;IAE5E;IACA,IAAII,eAAe,GAAGP,KAAK,CAACQ,QAAQ,IAAI,EAAE;IAC1C,IAAI,CAACR,KAAK,CAACQ,QAAQ,IAAIL,gBAAgB,EAAE;MACrCI,eAAe,GAAG,IAAI,CAACT,UAAU,CAACW,OAAO,CAACH,iBAAiB,CAACE,QAAQ,IAAI,EAAE,CAAC;IAC/E;;IAEA;IACA,MAAME,iBAAiB,GAAG,IAAI,CAACZ,UAAU,CAACa,OAAO,CAACJ,eAAe,CAAC;;IAElE;IACA,MAAMK,IAAI,GAAG;MACTC,IAAI,EAAEb,KAAK,CAACa,IAAI,IAAIP,iBAAiB,CAACO,IAAI;MAC1CC,IAAI,EAAEd,KAAK,CAACc,IAAI,IAAIR,iBAAiB,CAACQ,IAAI,IAAIpB,YAAY;MAC1DqB,IAAI,EAAEf,KAAK,CAACe,IAAI,IAAIT,iBAAiB,CAACS,IAAI;MAC1CP,QAAQ,EAAEE,iBAAiB;MAC3BM,IAAI,EAAEhB,KAAK,CAACgB,IAAI,IAAIV,iBAAiB,CAACU,IAAI;MAC1CC,OAAO,EAAEjB,KAAK,CAACiB,OAAO,IAAIX,iBAAiB,CAACW;IAChD,CAAC;;IAED;IACA,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACrB,aAAa,CAACsB,GAAG,CAAC1B,yBAAyB,EAAEmB,IAAI,CAAC;IAE5E,IAAIM,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOhC,MAAM,CAACiC,IAAI,CAAC,IAAI9B,wBAAwB,CAAC2B,MAAM,CAACI,KAAK,CAAC,CAAC;IAClE;;IAEA;IACA;IACA;IACA,MAAM;MAAEd,QAAQ,EAAEe,SAAS;MAAE,GAAGC;IAAc,CAAC,GAAGZ,IAAyB;IAC3E,OAAOxB,MAAM,CAACqC,EAAE,CAACD,aAAa,CAAC;EACnC;AACJ;AAEA,OAAO,MAAME,oCAAoC,GAAGpC,sBAAsB,CAACqC,oBAAoB,CAAC;EAC5FC,cAAc,EAAEjC,0BAA0B;EAC1CkC,YAAY,EAAE,CAACrC,aAAa,EAAEH,UAAU;AAC5C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventPublisher as EventPublisherAbstraction } 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 { ActiveTransport } 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 activeTransport;
|
|
12
|
+
constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisherAbstraction.Interface, repository: SaveSettingsRepository.Interface, codeSettings: CodeMailerSettings.Interface, activeTransport: ActiveTransport.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,69 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { SaveSettingsUseCase, SaveSettingsRepository } from "./abstractions.js";
|
|
4
|
+
import { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from "./events.js";
|
|
5
|
+
import { saveValidation } from "./validation.js";
|
|
6
|
+
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized, SettingsLockedByCode } 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 { ActiveTransport } from "../../domain/MailTransport/abstractions.js";
|
|
10
|
+
class SaveSettingsUseCaseImpl {
|
|
11
|
+
constructor(identityContext, eventPublisher, repository, codeSettings, activeTransport) {
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
this.eventPublisher = eventPublisher;
|
|
14
|
+
this.repository = repository;
|
|
15
|
+
this.codeSettings = codeSettings;
|
|
16
|
+
this.activeTransport = activeTransport;
|
|
17
|
+
}
|
|
18
|
+
async execute(input) {
|
|
19
|
+
const permission = await this.identityContext.getPermission("mailer.settings");
|
|
20
|
+
if (!permission) {
|
|
21
|
+
return Result.fail(new SettingsNotAuthorized());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Validate input.
|
|
25
|
+
const validationResult = saveValidation.safeParse(input);
|
|
26
|
+
if (!validationResult.success) {
|
|
27
|
+
return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Refuse when settings are defined via code.
|
|
31
|
+
const transportName = this.activeTransport.name();
|
|
32
|
+
if (transportName && this.codeSettings.get(transportName) !== null) {
|
|
33
|
+
return Result.fail(new SettingsLockedByCode());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Publish before save event. Strip the password — subscribers (audit
|
|
37
|
+
// logs, telemetry) must never see the plaintext value from the input.
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
const {
|
|
40
|
+
password: _beforePassword,
|
|
41
|
+
...inputForEvent
|
|
42
|
+
} = input;
|
|
43
|
+
const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({
|
|
44
|
+
input: inputForEvent
|
|
45
|
+
});
|
|
46
|
+
await this.eventPublisher.publish(beforeSaveEvent);
|
|
47
|
+
|
|
48
|
+
// Save settings.
|
|
49
|
+
const result = await this.repository.execute(input);
|
|
50
|
+
if (result.isFail()) {
|
|
51
|
+
return Result.fail(new SettingsPersistenceError(result.error));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Publish after save event. The repository return is already password-free
|
|
55
|
+
// (its type is Omit<TransportSettings, "password">), so no runtime strip
|
|
56
|
+
// is needed here.
|
|
57
|
+
const afterSaveEvent = new MailerSettingsAfterSaveEvent({
|
|
58
|
+
settings: result.value
|
|
59
|
+
});
|
|
60
|
+
await this.eventPublisher.publish(afterSaveEvent);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({
|
|
65
|
+
implementation: SaveSettingsUseCaseImpl,
|
|
66
|
+
dependencies: [IdentityContext, EventPublisher, SaveSettingsRepository, CodeMailerSettings, ActiveTransport]
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=SaveSettingsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","EventPublisher","SaveSettingsUseCase","SaveSettingsRepository","MailerSettingsBeforeSaveEvent","MailerSettingsAfterSaveEvent","saveValidation","SettingsValidationError","SettingsPersistenceError","SettingsNotAuthorized","SettingsLockedByCode","IdentityContext","CodeMailerSettings","ActiveTransport","SaveSettingsUseCaseImpl","constructor","identityContext","eventPublisher","repository","codeSettings","activeTransport","execute","input","permission","getPermission","fail","validationResult","safeParse","success","error","issues","transportName","name","get","password","_beforePassword","inputForEvent","beforeSaveEvent","publish","result","isFail","afterSaveEvent","settings","value","SaveSettingsUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["SaveSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} 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 { ActiveTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nclass SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisherAbstraction.Interface,\n private repository: SaveSettingsRepository.Interface,\n private codeSettings: CodeMailerSettings.Interface,\n private activeTransport: ActiveTransport.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 // Validate input.\n const validationResult = saveValidation.safeParse(input);\n if (!validationResult.success) {\n return Result.fail(new SettingsValidationError(validationResult.error.issues));\n }\n\n // Refuse when settings are defined via code.\n const transportName = this.activeTransport.name();\n if (transportName && this.codeSettings.get(transportName) !== null) {\n return Result.fail(new SettingsLockedByCode());\n }\n\n // Publish before save event. Strip the password — subscribers (audit\n // logs, telemetry) must never see the plaintext value from the input.\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 // Save settings.\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n // Publish after save event. The repository return is already password-free\n // (its type is Omit<TransportSettings, \"password\">), so no runtime strip\n // is needed here.\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 ActiveTransport\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,cAAc,QAEX,mDAAmD;AAC1D,SACIC,mBAAmB,EACnBC,sBAAsB;AAG1B,SAASC,6BAA6B,EAAEC,4BAA4B;AACpE,SAASC,cAAc;AACvB,SACIC,uBAAuB,EACvBC,wBAAwB,EACxBC,qBAAqB,EACrBC,oBAAoB;AAExB,SAASC,eAAe,QAAQ,6DAA6D;AAC7F,SAASC,kBAAkB;AAC3B,SAASC,eAAe;AAExB,MAAMC,uBAAuB,CAA0C;EACnEC,WAAWA,CACCC,eAA0C,EAC1CC,cAAmD,EACnDC,UAA4C,EAC5CC,YAA0C,EAC1CC,eAA0C,EACpD;IAAA,KALUJ,eAA0C,GAA1CA,eAA0C;IAAA,KAC1CC,cAAmD,GAAnDA,cAAmD;IAAA,KACnDC,UAA4C,GAA5CA,UAA4C;IAAA,KAC5CC,YAA0C,GAA1CA,YAA0C;IAAA,KAC1CC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAMC,OAAOA,CAACC,KAAwB,EAA8B;IAChE,MAAMC,UAAU,GAAG,MAAM,IAAI,CAACP,eAAe,CAACQ,aAAa,CAAC,iBAAiB,CAAC;IAE9E,IAAI,CAACD,UAAU,EAAE;MACb,OAAOvB,MAAM,CAACyB,IAAI,CAAC,IAAIhB,qBAAqB,CAAC,CAAC,CAAC;IACnD;;IAEA;IACA,MAAMiB,gBAAgB,GAAGpB,cAAc,CAACqB,SAAS,CAACL,KAAK,CAAC;IACxD,IAAI,CAACI,gBAAgB,CAACE,OAAO,EAAE;MAC3B,OAAO5B,MAAM,CAACyB,IAAI,CAAC,IAAIlB,uBAAuB,CAACmB,gBAAgB,CAACG,KAAK,CAACC,MAAM,CAAC,CAAC;IAClF;;IAEA;IACA,MAAMC,aAAa,GAAG,IAAI,CAACX,eAAe,CAACY,IAAI,CAAC,CAAC;IACjD,IAAID,aAAa,IAAI,IAAI,CAACZ,YAAY,CAACc,GAAG,CAACF,aAAa,CAAC,KAAK,IAAI,EAAE;MAChE,OAAO/B,MAAM,CAACyB,IAAI,CAAC,IAAIf,oBAAoB,CAAC,CAAC,CAAC;IAClD;;IAEA;IACA;IACA;IACA,MAAM;MAAEwB,QAAQ,EAAEC,eAAe;MAAE,GAAGC;IAAc,CAAC,GAAGd,KAAK;IAC7D,MAAMe,eAAe,GAAG,IAAIjC,6BAA6B,CAAC;MAAEkB,KAAK,EAAEc;IAAc,CAAC,CAAC;IACnF,MAAM,IAAI,CAACnB,cAAc,CAACqB,OAAO,CAACD,eAAe,CAAC;;IAElD;IACA,MAAME,MAAM,GAAG,MAAM,IAAI,CAACrB,UAAU,CAACG,OAAO,CAACC,KAAK,CAAC;IAEnD,IAAIiB,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOxC,MAAM,CAACyB,IAAI,CAAC,IAAIjB,wBAAwB,CAAC+B,MAAM,CAACV,KAAK,CAAC,CAAC;IAClE;;IAEA;IACA;IACA;IACA,MAAMY,cAAc,GAAG,IAAIpC,4BAA4B,CAAC;MAAEqC,QAAQ,EAAEH,MAAM,CAACI;IAAM,CAAC,CAAC;IACnF,MAAM,IAAI,CAAC1B,cAAc,CAACqB,OAAO,CAACG,cAAc,CAAC;IAEjD,OAAOF,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMK,iCAAiC,GAAG1C,mBAAmB,CAAC2C,oBAAoB,CAAC;EACtFC,cAAc,EAAEhC,uBAAuB;EACvCiC,YAAY,EAAE,CACVpC,eAAe,EACfV,cAAc,EACdE,sBAAsB,EACtBS,kBAAkB,EAClBC,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
user: string;
|
|
9
|
+
password?: string;
|
|
10
|
+
from: string;
|
|
11
|
+
replyTo?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ISaveSettingsErrors {
|
|
14
|
+
validation: SettingsValidationError;
|
|
15
|
+
persistence: SettingsPersistenceError;
|
|
16
|
+
notAuthorized: SettingsNotAuthorized;
|
|
17
|
+
lockedByCode: SettingsLockedByCode;
|
|
18
|
+
}
|
|
19
|
+
type SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];
|
|
20
|
+
/**
|
|
21
|
+
* Save-side returns are password-free. The only path that exposes the password
|
|
22
|
+
* to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute
|
|
23
|
+
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
24
|
+
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
25
|
+
*/
|
|
26
|
+
export type SavedTransportSettings = Omit<TransportSettings, "password">;
|
|
27
|
+
export interface ISaveSettingsRepository {
|
|
28
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
29
|
+
}
|
|
30
|
+
export declare const SaveSettingsRepository: import("@webiny/di").Abstraction<ISaveSettingsRepository>;
|
|
31
|
+
export declare namespace SaveSettingsRepository {
|
|
32
|
+
type Interface = ISaveSettingsRepository;
|
|
33
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
34
|
+
type Error = SaveSettingsError;
|
|
35
|
+
}
|
|
36
|
+
export interface ISaveSettings {
|
|
37
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
38
|
+
}
|
|
39
|
+
export declare const SaveSettingsUseCase: import("@webiny/di").Abstraction<ISaveSettings>;
|
|
40
|
+
export declare namespace SaveSettingsUseCase {
|
|
41
|
+
type Interface = ISaveSettings;
|
|
42
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
43
|
+
type Error = SaveSettingsError;
|
|
44
|
+
}
|
|
45
|
+
export interface MailerSettingsBeforeSavePayload {
|
|
46
|
+
input: Omit<SaveSettingsInput, "password">;
|
|
47
|
+
}
|
|
48
|
+
export interface MailerSettingsAfterSavePayload {
|
|
49
|
+
settings: Omit<TransportSettings, "password">;
|
|
50
|
+
}
|
|
51
|
+
export declare const MailerSettingsBeforeSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
52
|
+
export declare namespace MailerSettingsBeforeSaveEventHandler {
|
|
53
|
+
type Interface = IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>;
|
|
54
|
+
type Event = DomainEvent<MailerSettingsBeforeSavePayload>;
|
|
55
|
+
}
|
|
56
|
+
export declare const MailerSettingsAfterSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>>;
|
|
57
|
+
export declare namespace MailerSettingsAfterSaveEventHandler {
|
|
58
|
+
type Interface = IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>;
|
|
59
|
+
type Event = DomainEvent<MailerSettingsAfterSavePayload>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Save-side returns are password-free. The only path that exposes the password
|
|
5
|
+
* to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute
|
|
6
|
+
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
7
|
+
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const SaveSettingsRepository = createAbstraction("SaveSettingsRepository");
|
|
11
|
+
export const SaveSettingsUseCase = createAbstraction("SaveSettingsUseCase");
|
|
12
|
+
|
|
13
|
+
// Domain Events. Both payloads exclude `password` so subscribers (audit logs,
|
|
14
|
+
// telemetry, etc.) cannot accidentally persist plaintext or ciphertext secrets.
|
|
15
|
+
|
|
16
|
+
// Event Handler Abstractions
|
|
17
|
+
export const MailerSettingsBeforeSaveEventHandler = createAbstraction("MailerSettingsBeforeSaveEventHandler");
|
|
18
|
+
export const MailerSettingsAfterSaveEventHandler = createAbstraction("MailerSettingsAfterSaveEventHandler");
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","SaveSettingsRepository","SaveSettingsUseCase","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEventHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { 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 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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AA6BvD;AACA;AACA;AACA;AACA;AACA;;AAOA,OAAO,MAAMC,sBAAsB,GAC/BD,iBAAiB,CAA0B,wBAAwB,CAAC;AAYxE,OAAO,MAAME,mBAAmB,GAAGF,iBAAiB,CAAgB,qBAAqB,CAAC;;AAQ1F;AACA;;AASA;AACA,OAAO,MAAMG,oCAAoC,GAAGH,iBAAiB,CAEnE,sCAAsC,CAAC;AAOzC,OAAO,MAAMI,mCAAmC,GAAGJ,iBAAiB,CAElE,qCAAqC,CAAC","ignoreList":[]}
|
|
@@ -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,16 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { MailerSettingsBeforeSaveEventHandler, MailerSettingsAfterSaveEventHandler } from "./abstractions.js";
|
|
3
|
+
export class MailerSettingsBeforeSaveEvent extends DomainEvent {
|
|
4
|
+
eventType = "mailer.settings.beforeSave";
|
|
5
|
+
getHandlerAbstraction() {
|
|
6
|
+
return MailerSettingsBeforeSaveEventHandler;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class MailerSettingsAfterSaveEvent extends DomainEvent {
|
|
10
|
+
eventType = "mailer.settings.afterSave";
|
|
11
|
+
getHandlerAbstraction() {
|
|
12
|
+
return MailerSettingsAfterSaveEventHandler;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DomainEvent","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEventHandler","MailerSettingsBeforeSaveEvent","eventType","getHandlerAbstraction","MailerSettingsAfterSaveEvent"],"sources":["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"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SACIC,oCAAoC,EACpCC,mCAAmC;AAOvC,OAAO,MAAMC,6BAA6B,SAASH,WAAW,CAAkC;EAC5FI,SAAS,GAAG,4BAA4B;EAExCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOJ,oCAAoC;EAC/C;AACJ;AAEA,OAAO,MAAMK,4BAA4B,SAASN,WAAW,CAAiC;EAC1FI,SAAS,GAAG,2BAA2B;EAEvCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,mCAAmC;EAC9C;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SaveSettingsRepositoryImplementation } from "./SaveSettingsRepository.js";
|
|
3
|
+
import { SaveSettingsUseCaseImplementation } from "./SaveSettingsUseCase.js";
|
|
4
|
+
export const SaveSettingsFeature = createFeature({
|
|
5
|
+
name: "SaveSettings",
|
|
6
|
+
register(container) {
|
|
7
|
+
container.register(SaveSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(SaveSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","SaveSettingsRepositoryImplementation","SaveSettingsUseCaseImplementation","SaveSettingsFeature","name","register","container","inSingletonScope"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,oCAAoC;AAC7C,SAASC,iCAAiC;AAE1C,OAAO,MAAMC,mBAAmB,GAAGH,aAAa,CAAC;EAC7CI,IAAI,EAAE,cAAc;EACpBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACJ,oCAAoC,CAAC,CAACM,gBAAgB,CAAC,CAAC;IAC3ED,SAAS,CAACD,QAAQ,CAACH,iCAAiC,CAAC;EACzD;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SaveSettingsUseCase","SaveSettingsRepository","MailerSettingsAfterSaveEventHandler","MailerSettingsBeforeSaveEventHandler"],"sources":["index.ts"],"sourcesContent":["export {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n MailerSettingsAfterSaveEventHandler,\n MailerSettingsBeforeSaveEventHandler\n} from \"./abstractions.js\";\n"],"mappings":"AAAA,SACIA,mBAAmB,EACnBC,sBAAsB,EACtBC,mCAAmC,EACnCC,oCAAoC","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
export declare const saveValidation: zod.ZodObject<{
|
|
3
|
+
password: zod.ZodPipe<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodString>>>, zod.ZodTransform<string | null, string | null | undefined>>;
|
|
4
|
+
from: zod.ZodString;
|
|
5
|
+
port: zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodNumber>>>;
|
|
6
|
+
replyTo: zod.ZodPreprocess<zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodString>>>>;
|
|
7
|
+
host: zod.ZodString;
|
|
8
|
+
user: zod.ZodString;
|
|
9
|
+
}, zod.core.$strip>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
3
|
+
const 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(
|
|
11
|
+
// We need to set empty strings to `null` before address validation kicks in.
|
|
12
|
+
value => value === "" ? null : value, mailboxAddress.optional().nullish()).describe("Mail reply-to"),
|
|
13
|
+
host: zod.string().describe("Hostname"),
|
|
14
|
+
user: zod.string().describe("User")
|
|
15
|
+
};
|
|
16
|
+
export const saveValidation = zod.object({
|
|
17
|
+
...common,
|
|
18
|
+
password: password.nullish().optional().transform(value => {
|
|
19
|
+
return value === undefined ? null : value;
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["zod","isMailboxAddress","password","string","describe","mailboxAddress","refine","message","common","from","port","number","optional","nullish","replyTo","preprocess","value","host","user","saveValidation","object","transform","undefined"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst password = zod.string().describe(\"Password\");\n\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst common = {\n from: mailboxAddress.describe(\"Mail from\"),\n port: zod.number().optional().nullish().describe(\"Port\"),\n replyTo: zod\n .preprocess(\n // We need to set empty strings to `null` before address validation kicks in.\n value => (value === \"\" ? null : value),\n mailboxAddress.optional().nullish()\n )\n .describe(\"Mail reply-to\"),\n host: zod.string().describe(\"Hostname\"),\n user: zod.string().describe(\"User\")\n};\n\nexport const saveValidation = zod.object({\n ...common,\n password: password\n .nullish()\n .optional()\n .transform(value => {\n return value === undefined ? null : value;\n })\n});\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,gBAAgB;AAEzB,MAAMC,QAAQ,GAAGF,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,UAAU,CAAC;AAElD,MAAMC,cAAc,GAAGL,GAAG,CAACG,MAAM,CAAC,CAAC,CAACG,MAAM,CAACL,gBAAgB,EAAE;EAAEM,OAAO,EAAE;AAAyB,CAAC,CAAC;AAEnG,MAAMC,MAAM,GAAG;EACXC,IAAI,EAAEJ,cAAc,CAACD,QAAQ,CAAC,WAAW,CAAC;EAC1CM,IAAI,EAAEV,GAAG,CAACW,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAACT,QAAQ,CAAC,MAAM,CAAC;EACxDU,OAAO,EAAEd,GAAG,CACPe,UAAU;EACP;EACAC,KAAK,IAAKA,KAAK,KAAK,EAAE,GAAG,IAAI,GAAGA,KAAM,EACtCX,cAAc,CAACO,QAAQ,CAAC,CAAC,CAACC,OAAO,CAAC,CACtC,CAAC,CACAT,QAAQ,CAAC,eAAe,CAAC;EAC9Ba,IAAI,EAAEjB,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,UAAU,CAAC;EACvCc,IAAI,EAAElB,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,MAAM;AACtC,CAAC;AAED,OAAO,MAAMe,cAAc,GAAGnB,GAAG,CAACoB,MAAM,CAAC;EACrC,GAAGZ,MAAM;EACTN,QAAQ,EAAEA,QAAQ,CACbW,OAAO,CAAC,CAAC,CACTD,QAAQ,CAAC,CAAC,CACVS,SAAS,CAACL,KAAK,IAAI;IAChB,OAAOA,KAAK,KAAKM,SAAS,GAAG,IAAI,GAAGN,KAAK;EAC7C,CAAC;AACT,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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").NoSettingsConfiguredError | 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 {};
|