@webiny/api-mailer 6.6.0-alpha.11 → 6.6.0-alpha.13
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.js +8 -10
- package/MailerFeature.js.map +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +2 -2
- package/constants.js.map +1 -1
- package/domain/MailTransport/abstractions.d.ts +7 -4
- package/domain/MailTransport/abstractions.js.map +1 -1
- package/domain/MailerService/abstractions.d.ts +2 -0
- package/domain/MailerService/abstractions.js.map +1 -1
- package/domain/TransportSettings/abstractions.d.ts +47 -0
- package/domain/TransportSettings/abstractions.js +5 -0
- package/domain/TransportSettings/abstractions.js.map +1 -0
- package/domain/TransportSettings/findDefinition.d.ts +6 -0
- package/domain/TransportSettings/findDefinition.js +13 -0
- package/domain/TransportSettings/findDefinition.js.map +1 -0
- package/domain/errors.d.ts +15 -1
- package/domain/errors.js +27 -3
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.d.ts +3 -1
- package/exports/api/mailer.js +3 -1
- package/features/GetSettings/GetSettingsRepository.d.ts +5 -4
- package/features/GetSettings/GetSettingsRepository.js +23 -27
- package/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/features/GetSettings/GetSettingsUseCase.d.ts +11 -3
- package/features/GetSettings/GetSettingsUseCase.js +29 -4
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/GetSettings/abstractions.d.ts +14 -6
- package/features/GetSettings/abstractions.js.map +1 -1
- package/features/GetSettings/feature.js +1 -1
- package/features/GetSettings/feature.js.map +1 -1
- package/features/GetSettings/index.d.ts +1 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.d.ts +11 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js +19 -0
- package/features/IsMailerConfigured/IsMailerConfiguredUseCase.js.map +1 -0
- package/features/IsMailerConfigured/abstractions.d.ts +18 -0
- package/features/IsMailerConfigured/abstractions.js +5 -0
- package/features/IsMailerConfigured/abstractions.js.map +1 -0
- package/features/{CodeMailerSettings → IsMailerConfigured}/feature.d.ts +1 -1
- package/features/IsMailerConfigured/feature.js +11 -0
- package/features/IsMailerConfigured/feature.js.map +1 -0
- package/features/IsMailerConfigured/index.d.ts +1 -0
- package/features/IsMailerConfigured/index.js +1 -0
- package/features/MailerService/MailerService.d.ts +3 -4
- package/features/MailerService/MailerService.js +13 -19
- package/features/MailerService/MailerService.js.map +1 -1
- package/features/SaveSettings/SaveSettingsRepository.d.ts +3 -2
- package/features/SaveSettings/SaveSettingsRepository.js +44 -22
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -1
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +5 -7
- package/features/SaveSettings/SaveSettingsUseCase.js +27 -25
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
- package/features/SaveSettings/abstractions.d.ts +12 -20
- package/features/SaveSettings/abstractions.js.map +1 -1
- package/features/SaveSettings/feature.js +1 -1
- package/features/SaveSettings/feature.js.map +1 -1
- package/features/SaveSettings/index.d.ts +1 -0
- package/features/SendTestMail/SendTestMailUseCase.d.ts +13 -0
- package/features/SendTestMail/SendTestMailUseCase.js +40 -0
- package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
- package/features/SendTestMail/abstractions.d.ts +32 -0
- package/features/SendTestMail/abstractions.js +5 -0
- package/features/SendTestMail/abstractions.js.map +1 -0
- package/features/{SmtpTransport → SendTestMail}/feature.d.ts +1 -1
- package/features/SendTestMail/feature.js +11 -0
- package/features/SendTestMail/feature.js.map +1 -0
- package/graphql/MailerSchemaFactory.js +52 -38
- package/graphql/MailerSchemaFactory.js.map +1 -1
- package/index.d.ts +10 -0
- package/index.js +7 -0
- package/package.json +13 -15
- package/types.d.ts +0 -9
- package/domain/CodeMailerSettings/abstractions.d.ts +0 -8
- package/domain/CodeMailerSettings/abstractions.js +0 -5
- package/domain/CodeMailerSettings/abstractions.js.map +0 -1
- package/features/CodeMailerSettings/CodeMailerSettings.d.ts +0 -12
- package/features/CodeMailerSettings/CodeMailerSettings.js +0 -23
- package/features/CodeMailerSettings/CodeMailerSettings.js.map +0 -1
- package/features/CodeMailerSettings/feature.js +0 -11
- package/features/CodeMailerSettings/feature.js.map +0 -1
- package/features/DummyTransport/DummyMailTransport.d.ts +0 -9
- package/features/DummyTransport/DummyMailTransport.js +0 -14
- package/features/DummyTransport/DummyMailTransport.js.map +0 -1
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +0 -10
- package/features/DummyTransport/DummyMailTransportFactory.js +0 -20
- package/features/DummyTransport/DummyMailTransportFactory.js.map +0 -1
- package/features/DummyTransport/feature.d.ts +0 -4
- package/features/DummyTransport/feature.js +0 -11
- package/features/DummyTransport/feature.js.map +0 -1
- package/features/SaveSettings/validation.d.ts +0 -10
- package/features/SaveSettings/validation.js +0 -21
- package/features/SaveSettings/validation.js.map +0 -1
- package/features/SmtpTransport/SmtpConfig.d.ts +0 -6
- package/features/SmtpTransport/SmtpConfig.js +0 -26
- package/features/SmtpTransport/SmtpConfig.js.map +0 -1
- package/features/SmtpTransport/SmtpMailTransport.d.ts +0 -77
- package/features/SmtpTransport/SmtpMailTransport.js +0 -54
- package/features/SmtpTransport/SmtpMailTransport.js.map +0 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +0 -11
- package/features/SmtpTransport/SmtpMailTransportFactory.js +0 -21
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +0 -1
- package/features/SmtpTransport/feature.js +0 -11
- package/features/SmtpTransport/feature.js.map +0 -1
|
@@ -1 +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"}
|
|
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: \"Mailer/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,11 @@
|
|
|
1
|
+
import { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
declare class IsMailerConfiguredUseCaseImpl implements IsMailerConfiguredUseCase.Interface {
|
|
4
|
+
private mailerService;
|
|
5
|
+
constructor(mailerService: MailerService.Interface);
|
|
6
|
+
execute(): IsMailerConfiguredUseCase.Return;
|
|
7
|
+
}
|
|
8
|
+
export declare const IsMailerConfiguredUseCaseImplementation: typeof IsMailerConfiguredUseCaseImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IIsMailerConfiguredUseCase>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
class IsMailerConfiguredUseCaseImpl {
|
|
4
|
+
constructor(mailerService){
|
|
5
|
+
this.mailerService = mailerService;
|
|
6
|
+
}
|
|
7
|
+
execute() {
|
|
8
|
+
return this.mailerService.isConfigured();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const IsMailerConfiguredUseCaseImplementation = IsMailerConfiguredUseCase.createImplementation({
|
|
12
|
+
implementation: IsMailerConfiguredUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
MailerService
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { IsMailerConfiguredUseCaseImplementation };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=IsMailerConfiguredUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/IsMailerConfiguredUseCase.js","sources":["../../../src/features/IsMailerConfigured/IsMailerConfiguredUseCase.ts"],"sourcesContent":["import { IsMailerConfiguredUseCase } from \"./abstractions.js\";\nimport { MailerService } from \"~/domain/MailerService/abstractions.js\";\n\nclass IsMailerConfiguredUseCaseImpl implements IsMailerConfiguredUseCase.Interface {\n constructor(private mailerService: MailerService.Interface) {}\n\n execute(): IsMailerConfiguredUseCase.Return {\n return this.mailerService.isConfigured();\n }\n}\n\nexport const IsMailerConfiguredUseCaseImplementation =\n IsMailerConfiguredUseCase.createImplementation({\n implementation: IsMailerConfiguredUseCaseImpl,\n dependencies: [MailerService]\n });\n"],"names":["IsMailerConfiguredUseCaseImpl","mailerService","IsMailerConfiguredUseCaseImplementation","IsMailerConfiguredUseCase","MailerService"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,UAA4C;QACxC,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY;IAC1C;AACJ;AAEO,MAAMC,0CACTC,0BAA0B,oBAAoB,CAAC;IAC3C,gBAAgBH;IAChB,cAAc;QAACI;KAAc;AACjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IIsMailerConfiguredUseCase {
|
|
2
|
+
execute(): Promise<boolean>;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Whether a mail transport is set up. It does not connect or send, so a transport with wrong
|
|
6
|
+
* credentials still counts.
|
|
7
|
+
*
|
|
8
|
+
* Only for a question that has to be answered before anything is sent, like the password reset
|
|
9
|
+
* request, which must answer every address the same way. Otherwise send through `SendMailUseCase`
|
|
10
|
+
* and handle `NoTransportAvailableError`.
|
|
11
|
+
*
|
|
12
|
+
* No permission check: the password reset request is anonymous.
|
|
13
|
+
*/
|
|
14
|
+
export declare const IsMailerConfiguredUseCase: import("@webiny/di").Abstraction<IIsMailerConfiguredUseCase>;
|
|
15
|
+
export declare namespace IsMailerConfiguredUseCase {
|
|
16
|
+
type Interface = IIsMailerConfiguredUseCase;
|
|
17
|
+
type Return = Promise<boolean>;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/abstractions.js","sources":["../../../src/features/IsMailerConfigured/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IIsMailerConfiguredUseCase {\n execute(): Promise<boolean>;\n}\n\n/**\n * Whether a mail transport is set up. It does not connect or send, so a transport with wrong\n * credentials still counts.\n *\n * Only for a question that has to be answered before anything is sent, like the password reset\n * request, which must answer every address the same way. Otherwise send through `SendMailUseCase`\n * and handle `NoTransportAvailableError`.\n *\n * No permission check: the password reset request is anonymous.\n */\nexport const IsMailerConfiguredUseCase = createAbstraction<IIsMailerConfiguredUseCase>(\n \"IsMailerConfiguredUseCase\"\n);\n\nexport namespace IsMailerConfiguredUseCase {\n export type Interface = IIsMailerConfiguredUseCase;\n export type Return = Promise<boolean>;\n}\n"],"names":["IsMailerConfiguredUseCase","createAbstraction"],"mappings":";AAgBO,MAAMA,4BAA4BC,kBACrC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { IsMailerConfiguredUseCaseImplementation } from "./IsMailerConfiguredUseCase.js";
|
|
3
|
+
const IsMailerConfiguredFeature = createFeature({
|
|
4
|
+
name: "IsMailerConfigured",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(IsMailerConfiguredUseCaseImplementation);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { IsMailerConfiguredFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/IsMailerConfigured/feature.js","sources":["../../../src/features/IsMailerConfigured/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { IsMailerConfiguredUseCaseImplementation } from \"./IsMailerConfiguredUseCase.js\";\n\nexport const IsMailerConfiguredFeature = createFeature({\n name: \"IsMailerConfigured\",\n register(container) {\n container.register(IsMailerConfiguredUseCaseImplementation);\n }\n});\n"],"names":["IsMailerConfiguredFeature","createFeature","container","IsMailerConfiguredUseCaseImplementation"],"mappings":";;AAGO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IsMailerConfiguredUseCase } from "./abstractions.js";
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
2
2
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
3
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
4
3
|
import type { TransportSendData } from "../../types.js";
|
|
5
4
|
declare class MailerServiceImpl implements Abstraction.Interface {
|
|
6
|
-
private getSettingsRepository;
|
|
7
5
|
private transportFactories;
|
|
8
|
-
constructor(
|
|
6
|
+
constructor(transportFactories: MailTransportFactory.Interface[]);
|
|
9
7
|
sendMail<T = any>(data: TransportSendData): Abstraction.Return<T>;
|
|
10
|
-
|
|
8
|
+
isConfigured(): Promise<boolean>;
|
|
9
|
+
private createTransport;
|
|
11
10
|
}
|
|
12
11
|
export declare const MailerService: typeof MailerServiceImpl & {
|
|
13
12
|
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailerService/abstractions.js").IMailerService>;
|
|
@@ -2,15 +2,13 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
3
|
import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "../../domain/MailerService/errors.js";
|
|
4
4
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
5
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
6
5
|
class MailerServiceImpl {
|
|
7
|
-
constructor(
|
|
8
|
-
this.getSettingsRepository = getSettingsRepository;
|
|
6
|
+
constructor(transportFactories){
|
|
9
7
|
this.transportFactories = transportFactories;
|
|
10
8
|
}
|
|
11
9
|
async sendMail(data) {
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
10
|
+
const transport = await this.createTransport();
|
|
11
|
+
if (!transport) return Result.fail(new NoTransportAvailableError());
|
|
14
12
|
try {
|
|
15
13
|
const response = await transport.send(data);
|
|
16
14
|
if (response.error) return Result.fail(new TransportSendError(response.error));
|
|
@@ -19,33 +17,29 @@ class MailerServiceImpl {
|
|
|
19
17
|
return Result.fail(new TransportSendError(error));
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
async
|
|
20
|
+
async isConfigured() {
|
|
21
|
+
const transport = await this.createTransport();
|
|
22
|
+
return null !== transport;
|
|
23
|
+
}
|
|
24
|
+
async createTransport() {
|
|
23
25
|
const factories = [
|
|
24
26
|
...this.transportFactories
|
|
25
27
|
].reverse();
|
|
26
28
|
for (const factory of factories){
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const transport = await factory.createTransport(settings);
|
|
31
|
-
return {
|
|
32
|
-
factory,
|
|
33
|
-
transport
|
|
34
|
-
};
|
|
29
|
+
let transport;
|
|
30
|
+
try {
|
|
31
|
+
transport = await factory.createTransport();
|
|
35
32
|
} catch (error) {
|
|
36
33
|
throw new TransportCreateError(error);
|
|
37
34
|
}
|
|
35
|
+
if (transport) return transport;
|
|
38
36
|
}
|
|
39
|
-
return
|
|
40
|
-
factory: null,
|
|
41
|
-
transport: null
|
|
42
|
-
};
|
|
37
|
+
return null;
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
40
|
const MailerService_MailerService = MailerService.createImplementation({
|
|
46
41
|
implementation: MailerServiceImpl,
|
|
47
42
|
dependencies: [
|
|
48
|
-
GetSettingsRepository,
|
|
49
43
|
[
|
|
50
44
|
MailTransportFactory,
|
|
51
45
|
{
|
|
@@ -1 +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
|
|
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 } from \"~/domain/MailTransport/abstractions.js\";\nimport { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(private transportFactories: MailTransportFactory.Interface[]) {}\n\n async sendMail<T = any>(data: TransportSendData): Abstraction.Return<T> {\n const transport = await this.createTransport();\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 async isConfigured(): Promise<boolean> {\n const transport = await this.createTransport();\n\n return transport !== null;\n }\n\n // The last registered factory that is configured wins, so a project's own transport takes over.\n // Null when no factory is configured.\n private async createTransport(): Promise<MailTransport.Interface | null> {\n const factories = [...this.transportFactories].reverse();\n\n for (const factory of factories) {\n let transport: MailTransport.Interface | null;\n try {\n transport = await factory.createTransport();\n } catch (error) {\n throw new TransportCreateError(error);\n }\n\n if (transport) {\n return transport;\n }\n }\n\n return null;\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [[MailTransportFactory, { multiple: true }]]\n});\n"],"names":["MailerServiceImpl","transportFactories","data","transport","Result","NoTransportAvailableError","response","TransportSendError","error","factories","factory","TransportCreateError","MailerService","Abstraction","MailTransportFactory"],"mappings":";;;;AAWA,MAAMA;IACF,YAAoBC,kBAAoD,CAAE;aAAtDA,kBAAkB,GAAlBA;IAAuD;IAE3E,MAAM,SAAkBC,IAAuB,EAAyB;QACpE,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe;QAE5C,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YACA,MAAMC,WAAW,MAAMH,UAAU,IAAI,CAACD;YAEtC,IAAII,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,MAAM,eAAiC;QACnC,MAAML,YAAY,MAAM,IAAI,CAAC,eAAe;QAE5C,OAAOA,AAAc,SAAdA;IACX;IAIA,MAAc,kBAA2D;QACrE,MAAMM,YAAY;eAAI,IAAI,CAAC,kBAAkB;SAAC,CAAC,OAAO;QAEtD,KAAK,MAAMC,WAAWD,UAAW;YAC7B,IAAIN;YACJ,IAAI;gBACAA,YAAY,MAAMO,QAAQ,eAAe;YAC7C,EAAE,OAAOF,OAAO;gBACZ,MAAM,IAAIG,qBAAqBH;YACnC;YAEA,IAAIL,WACA,OAAOA;QAEf;QAEA,OAAO;IACX;AACJ;AAEO,MAAMS,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBb;IAChB,cAAc;QAAC;YAACc;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC9D"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
2
|
-
import { SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
2
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
+
import { SaveSettingsRepository } from "./abstractions.js";
|
|
4
|
+
import type { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
4
5
|
declare class SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {
|
|
5
6
|
private keyValueStore;
|
|
6
7
|
private encryption;
|
|
7
8
|
constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface);
|
|
8
|
-
execute(input:
|
|
9
|
+
execute(definition: TransportSettingsDefinition.Interface, input: TransportSettingsDefinition.Values): SaveSettingsRepository.Return;
|
|
9
10
|
}
|
|
10
11
|
export declare const SaveSettingsRepositoryImplementation: typeof SaveSettingsRepositoryImpl & {
|
|
11
12
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISaveSettingsRepository>;
|
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
3
|
+
import { KeyNotFoundError, KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
4
|
import { SaveSettingsRepository } from "./abstractions.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const
|
|
5
|
+
import { getStorageKey, withDefaults, withoutSecrets } from "../../domain/TransportSettings/findDefinition.js";
|
|
6
|
+
import { SettingsPersistenceError, SettingsValidationError } from "../../domain/errors.js";
|
|
7
|
+
const isSet = (value)=>null != value;
|
|
8
|
+
const secretRequiredMessage = (secret, fields)=>{
|
|
9
|
+
const name = secret.charAt(0).toUpperCase() + secret.slice(1);
|
|
10
|
+
const list = fields.length > 1 ? `${fields.slice(0, -1).join(", ")} or ${fields[fields.length - 1]}` : fields.join("");
|
|
11
|
+
return `${name} is required when changing the ${list} settings.`;
|
|
12
|
+
};
|
|
8
13
|
class SaveSettingsRepositoryImpl {
|
|
9
14
|
constructor(keyValueStore, encryption){
|
|
10
15
|
this.keyValueStore = keyValueStore;
|
|
11
16
|
this.encryption = encryption;
|
|
12
17
|
}
|
|
13
|
-
async execute(input) {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
async execute(definition, input) {
|
|
19
|
+
const storageKey = getStorageKey(definition);
|
|
20
|
+
const secrets = definition.secrets ?? [];
|
|
21
|
+
const existingResult = await this.keyValueStore.get(storageKey);
|
|
22
|
+
if (existingResult.isFail() && !(existingResult.error instanceof KeyNotFoundError)) return Result.fail(new SettingsPersistenceError(existingResult.error));
|
|
23
|
+
const stored = existingResult.isOk() ? existingResult.value : null;
|
|
24
|
+
const merged = {
|
|
25
|
+
...stored
|
|
26
|
+
};
|
|
27
|
+
for (const [key, value] of Object.entries(input))if (isSet(value) && !secrets.includes(key)) merged[key] = value;
|
|
28
|
+
const storedWithDefaults = withDefaults(definition, {
|
|
29
|
+
...stored
|
|
30
|
+
});
|
|
31
|
+
const mergedWithDefaults = withDefaults(definition, merged);
|
|
32
|
+
const boundFieldChanged = (definition.secretsBoundTo ?? []).some((field)=>mergedWithDefaults[field] !== storedWithDefaults[field]);
|
|
21
33
|
const data = {
|
|
22
|
-
|
|
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
|
|
34
|
+
...mergedWithDefaults
|
|
29
35
|
};
|
|
30
|
-
const
|
|
36
|
+
for (const secret of secrets){
|
|
37
|
+
let plain = input[secret] ? String(input[secret]) : "";
|
|
38
|
+
if (!plain && stored?.[secret]) {
|
|
39
|
+
if (boundFieldChanged) return Result.fail(new SettingsValidationError([
|
|
40
|
+
{
|
|
41
|
+
code: "custom",
|
|
42
|
+
path: [
|
|
43
|
+
secret
|
|
44
|
+
],
|
|
45
|
+
input: void 0,
|
|
46
|
+
message: secretRequiredMessage(secret, definition.secretsBoundTo ?? [])
|
|
47
|
+
}
|
|
48
|
+
]));
|
|
49
|
+
plain = await this.encryption.decrypt(String(stored[secret]));
|
|
50
|
+
}
|
|
51
|
+
data[secret] = await this.encryption.encrypt(plain);
|
|
52
|
+
}
|
|
53
|
+
const result = await this.keyValueStore.set(storageKey, data);
|
|
31
54
|
if (result.isFail()) return Result.fail(new SettingsPersistenceError(result.error));
|
|
32
|
-
|
|
33
|
-
return Result.ok(savedSettings);
|
|
55
|
+
return Result.ok(withoutSecrets(definition, data));
|
|
34
56
|
}
|
|
35
57
|
}
|
|
36
58
|
const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({
|
|
@@ -1 +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 {
|
|
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 { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { KeyNotFoundError } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { SaveSettingsRepository } from \"./abstractions.js\";\nimport type { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport {\n getStorageKey,\n withDefaults,\n withoutSecrets\n} from \"~/domain/TransportSettings/findDefinition.js\";\nimport { SettingsPersistenceError, SettingsValidationError } from \"~/domain/errors.js\";\n\nconst isSet = (value: unknown) => value !== undefined && value !== null;\n\n// \"Password is required when changing the host, port, secure or user settings.\"\nconst secretRequiredMessage = (secret: string, fields: string[]) => {\n const name = secret.charAt(0).toUpperCase() + secret.slice(1);\n const list =\n fields.length > 1\n ? `${fields.slice(0, -1).join(\", \")} or ${fields[fields.length - 1]}`\n : fields.join(\"\");\n return `${name} is required when changing the ${list} settings.`;\n};\n\nclass SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface\n ) {}\n\n async execute(\n definition: TransportSettingsDefinition.Interface,\n input: TransportSettingsDefinition.Values\n ): SaveSettingsRepository.Return {\n const storageKey = getStorageKey(definition);\n const secrets = definition.secrets ?? [];\n\n const existingResult =\n await this.keyValueStore.get<TransportSettingsDefinition.Values>(storageKey);\n /*\n * Only a missing key means \"nothing saved yet\". Any other read failure would have the save\n * below replace the stored secrets and fields with blanks.\n */\n if (existingResult.isFail() && !(existingResult.error instanceof KeyNotFoundError)) {\n return Result.fail(new SettingsPersistenceError(existingResult.error));\n }\n const stored = existingResult.isOk() ? existingResult.value : null;\n\n // A field left out (or sent as null) keeps its stored value.\n const merged: TransportSettingsDefinition.Values = { ...stored };\n for (const [key, value] of Object.entries(input)) {\n if (isSet(value) && !secrets.includes(key)) {\n merged[key] = value;\n }\n }\n\n const storedWithDefaults = withDefaults(definition, { ...stored });\n const mergedWithDefaults = withDefaults(definition, merged);\n const boundFieldChanged = (definition.secretsBoundTo ?? []).some(\n field => mergedWithDefaults[field] !== storedWithDefaults[field]\n );\n\n const data: TransportSettingsDefinition.Values = { ...mergedWithDefaults };\n for (const secret of secrets) {\n let plain = input[secret] ? String(input[secret]) : \"\";\n if (!plain && stored?.[secret]) {\n /**\n * Security: re-using a stored secret is only safe while it is sent to the same\n * server and account. Otherwise a settings editor could point the transport at a\n * host they control and receive it, so it must be entered again.\n */\n if (boundFieldChanged) {\n return Result.fail(\n new SettingsValidationError([\n {\n code: \"custom\",\n path: [secret],\n input: undefined,\n message: secretRequiredMessage(\n secret,\n definition.secretsBoundTo ?? []\n )\n }\n ])\n );\n }\n plain = await this.encryption.decrypt(String(stored[secret]));\n }\n data[secret] = await this.encryption.encrypt(plain);\n }\n\n const result = await this.keyValueStore.set(storageKey, data);\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n return Result.ok(withoutSecrets(definition, data));\n }\n}\n\nexport const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({\n implementation: SaveSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption]\n});\n"],"names":["isSet","value","secretRequiredMessage","secret","fields","name","list","SaveSettingsRepositoryImpl","keyValueStore","encryption","definition","input","storageKey","getStorageKey","secrets","existingResult","KeyNotFoundError","Result","SettingsPersistenceError","stored","merged","key","Object","storedWithDefaults","withDefaults","mergedWithDefaults","boundFieldChanged","field","data","plain","String","SettingsValidationError","undefined","result","withoutSecrets","SaveSettingsRepositoryImplementation","SaveSettingsRepository","KeyValueStore","Encryption"],"mappings":";;;;;;AAaA,MAAMA,QAAQ,CAACC,QAAmBA,QAAAA;AAGlC,MAAMC,wBAAwB,CAACC,QAAgBC;IAC3C,MAAMC,OAAOF,OAAO,MAAM,CAAC,GAAG,WAAW,KAAKA,OAAO,KAAK,CAAC;IAC3D,MAAMG,OACFF,OAAO,MAAM,GAAG,IACV,GAAGA,OAAO,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,IAAI,EAAEA,MAAM,CAACA,OAAO,MAAM,GAAG,EAAE,EAAE,GACnEA,OAAO,IAAI,CAAC;IACtB,OAAO,GAAGC,KAAK,+BAA+B,EAAEC,KAAK,UAAU,CAAC;AACpE;AAEA,MAAMC;IACF,YACYC,aAAsC,EACtCC,UAAgC,CAC1C;aAFUD,aAAa,GAAbA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,UAAiD,EACjDC,KAAyC,EACZ;QAC7B,MAAMC,aAAaC,cAAcH;QACjC,MAAMI,UAAUJ,WAAW,OAAO,IAAI,EAAE;QAExC,MAAMK,iBACF,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAqCH;QAKrE,IAAIG,eAAe,MAAM,MAAM,CAAEA,CAAAA,eAAe,KAAK,YAAYC,gBAAe,GAC5E,OAAOC,OAAO,IAAI,CAAC,IAAIC,yBAAyBH,eAAe,KAAK;QAExE,MAAMI,SAASJ,eAAe,IAAI,KAAKA,eAAe,KAAK,GAAG;QAG9D,MAAMK,SAA6C;YAAE,GAAGD,MAAM;QAAC;QAC/D,KAAK,MAAM,CAACE,KAAKpB,MAAM,IAAIqB,OAAO,OAAO,CAACX,OACtC,IAAIX,MAAMC,UAAU,CAACa,QAAQ,QAAQ,CAACO,MAClCD,MAAM,CAACC,IAAI,GAAGpB;QAItB,MAAMsB,qBAAqBC,aAAad,YAAY;YAAE,GAAGS,MAAM;QAAC;QAChE,MAAMM,qBAAqBD,aAAad,YAAYU;QACpD,MAAMM,oBAAqBhB,AAAAA,CAAAA,WAAW,cAAc,IAAI,EAAC,EAAG,IAAI,CAC5DiB,CAAAA,QAASF,kBAAkB,CAACE,MAAM,KAAKJ,kBAAkB,CAACI,MAAM;QAGpE,MAAMC,OAA2C;YAAE,GAAGH,kBAAkB;QAAC;QACzE,KAAK,MAAMtB,UAAUW,QAAS;YAC1B,IAAIe,QAAQlB,KAAK,CAACR,OAAO,GAAG2B,OAAOnB,KAAK,CAACR,OAAO,IAAI;YACpD,IAAI,CAAC0B,SAASV,QAAQ,CAAChB,OAAO,EAAE;gBAM5B,IAAIuB,mBACA,OAAOT,OAAO,IAAI,CACd,IAAIc,wBAAwB;oBACxB;wBACI,MAAM;wBACN,MAAM;4BAAC5B;yBAAO;wBACd,OAAO6B;wBACP,SAAS9B,sBACLC,QACAO,WAAW,cAAc,IAAI,EAAE;oBAEvC;iBACH;gBAGTmB,QAAQ,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACC,OAAOX,MAAM,CAAChB,OAAO;YAC/D;YACAyB,IAAI,CAACzB,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC0B;QACjD;QAEA,MAAMI,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACrB,YAAYgB;QACxD,IAAIK,OAAO,MAAM,IACb,OAAOhB,OAAO,IAAI,CAAC,IAAIC,yBAAyBe,OAAO,KAAK;QAGhE,OAAOhB,OAAO,EAAE,CAACiB,eAAexB,YAAYkB;IAChD;AACJ;AAEO,MAAMO,uCAAuCC,uBAAuB,oBAAoB,CAAC;IAC5F,gBAAgB7B;IAChB,cAAc;QAAC8B;QAAeC;KAAW;AAC7C"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
-
import { SaveSettingsUseCase, SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
2
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { SaveSettingsUseCase, SaveSettingsRepository } from "./abstractions.js";
|
|
4
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
6
5
|
declare class SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {
|
|
7
6
|
private identityContext;
|
|
8
7
|
private eventPublisher;
|
|
9
8
|
private repository;
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
execute(input: SaveSettingsInput): SaveSettingsUseCase.Return;
|
|
9
|
+
private definitions;
|
|
10
|
+
constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisher.Interface, repository: SaveSettingsRepository.Interface, definitions: TransportSettingsDefinition.Interface[]);
|
|
11
|
+
execute(transport: string, input: TransportSettingsDefinition.Values): SaveSettingsUseCase.Return;
|
|
14
12
|
}
|
|
15
13
|
export declare const SaveSettingsUseCaseImplementation: typeof SaveSettingsUseCaseImpl & {
|
|
16
14
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISaveSettings>;
|
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
4
|
import { SaveSettingsRepository, SaveSettingsUseCase } from "./abstractions.js";
|
|
4
5
|
import { MailerSettingsAfterSaveEvent, MailerSettingsBeforeSaveEvent } from "./events.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
6
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
7
|
+
import { findDefinition, withoutSecrets } from "../../domain/TransportSettings/findDefinition.js";
|
|
8
|
+
import { SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError, UnknownTransportSettings } from "../../domain/errors.js";
|
|
9
|
+
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
10
10
|
class SaveSettingsUseCaseImpl {
|
|
11
|
-
constructor(identityContext, eventPublisher, repository,
|
|
11
|
+
constructor(identityContext, eventPublisher, repository, definitions){
|
|
12
12
|
this.identityContext = identityContext;
|
|
13
13
|
this.eventPublisher = eventPublisher;
|
|
14
14
|
this.repository = repository;
|
|
15
|
-
this.
|
|
16
|
-
this.transportFactories = transportFactories;
|
|
15
|
+
this.definitions = definitions;
|
|
17
16
|
}
|
|
18
|
-
async execute(input) {
|
|
19
|
-
const permission = await this.identityContext.getPermission(
|
|
17
|
+
async execute(transport, input) {
|
|
18
|
+
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
20
19
|
if (!permission) return Result.fail(new SettingsNotAuthorized());
|
|
21
|
-
const
|
|
20
|
+
const definition = findDefinition(this.definitions, transport);
|
|
21
|
+
if (!definition) return Result.fail(new UnknownTransportSettings(transport));
|
|
22
|
+
const validationResult = definition.schema.safeParse(input);
|
|
22
23
|
if (!validationResult.success) return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
input:
|
|
28
|
-
});
|
|
29
|
-
await this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
const values = validationResult.data;
|
|
25
|
+
if ((definition.getCodeSettings?.() ?? null) !== null) return Result.fail(new SettingsLockedByCode());
|
|
26
|
+
await this.eventPublisher.publish(new MailerSettingsBeforeSaveEvent({
|
|
27
|
+
transport,
|
|
28
|
+
input: withoutSecrets(definition, values)
|
|
29
|
+
}));
|
|
30
|
+
const result = await this.repository.execute(definition, values);
|
|
31
|
+
if (result.isFail()) {
|
|
32
|
+
if (result.error instanceof SettingsValidationError) return Result.fail(result.error);
|
|
33
|
+
return Result.fail(new SettingsPersistenceError(result.error));
|
|
34
|
+
}
|
|
35
|
+
await this.eventPublisher.publish(new MailerSettingsAfterSaveEvent({
|
|
36
|
+
transport,
|
|
33
37
|
settings: result.value
|
|
34
|
-
});
|
|
35
|
-
await this.eventPublisher.publish(afterSaveEvent);
|
|
38
|
+
}));
|
|
36
39
|
return result;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -42,9 +45,8 @@ const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementati
|
|
|
42
45
|
IdentityContext,
|
|
43
46
|
EventPublisher,
|
|
44
47
|
SaveSettingsRepository,
|
|
45
|
-
CodeMailerSettings,
|
|
46
48
|
[
|
|
47
|
-
|
|
49
|
+
TransportSettingsDefinition,
|
|
48
50
|
{
|
|
49
51
|
multiple: true
|
|
50
52
|
}
|
|
@@ -1 +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 {
|
|
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 { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { SaveSettingsUseCase, SaveSettingsRepository } from \"./abstractions.js\";\nimport { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from \"./events.js\";\nimport { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport { findDefinition, withoutSecrets } from \"~/domain/TransportSettings/findDefinition.js\";\nimport {\n SettingsLockedByCode,\n SettingsNotAuthorized,\n SettingsPersistenceError,\n SettingsValidationError,\n UnknownTransportSettings\n} from \"~/domain/errors.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.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 definitions: TransportSettingsDefinition.Interface[]\n ) {}\n\n async execute(\n transport: string,\n input: TransportSettingsDefinition.Values\n ): SaveSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(new SettingsNotAuthorized());\n }\n\n const definition = findDefinition(this.definitions, transport);\n if (!definition) {\n return Result.fail(new UnknownTransportSettings(transport));\n }\n\n const validationResult = definition.schema.safeParse(input);\n if (!validationResult.success) {\n return Result.fail(new SettingsValidationError(validationResult.error.issues));\n }\n const values = validationResult.data as TransportSettingsDefinition.Values;\n\n // Settings set in code win over stored ones, so saving would change nothing.\n if ((definition.getCodeSettings?.() ?? null) !== null) {\n return Result.fail(new SettingsLockedByCode());\n }\n\n await this.eventPublisher.publish(\n new MailerSettingsBeforeSaveEvent({\n transport,\n input: withoutSecrets(definition, values)\n })\n );\n\n const result = await this.repository.execute(definition, values);\n if (result.isFail()) {\n if (result.error instanceof SettingsValidationError) {\n return Result.fail(result.error);\n }\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n await this.eventPublisher.publish(\n new MailerSettingsAfterSaveEvent({ transport, settings: result.value })\n );\n\n return result;\n }\n}\n\nexport const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({\n implementation: SaveSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n EventPublisher,\n SaveSettingsRepository,\n [TransportSettingsDefinition, { multiple: true }]\n ]\n});\n"],"names":["SaveSettingsUseCaseImpl","identityContext","eventPublisher","repository","definitions","transport","input","permission","MAILER_SETTINGS_PERMISSION","Result","SettingsNotAuthorized","definition","findDefinition","UnknownTransportSettings","validationResult","SettingsValidationError","values","SettingsLockedByCode","MailerSettingsBeforeSaveEvent","withoutSecrets","result","SettingsPersistenceError","MailerSettingsAfterSaveEvent","SaveSettingsUseCaseImplementation","SaveSettingsUseCase","IdentityContext","EventPublisher","SaveSettingsRepository","TransportSettingsDefinition"],"mappings":";;;;;;;;;AAgBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA4C,EAC5CC,WAAoD,CAC9D;aAJUH,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,SAAiB,EACjBC,KAAyC,EACf;QAC1B,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,eAAe,IAAI,CAAC,WAAW,EAAEP;QACpD,IAAI,CAACM,YACD,OAAOF,OAAO,IAAI,CAAC,IAAII,yBAAyBR;QAGpD,MAAMS,mBAAmBH,WAAW,MAAM,CAAC,SAAS,CAACL;QACrD,IAAI,CAACQ,iBAAiB,OAAO,EACzB,OAAOL,OAAO,IAAI,CAAC,IAAIM,wBAAwBD,iBAAiB,KAAK,CAAC,MAAM;QAEhF,MAAME,SAASF,iBAAiB,IAAI;QAGpC,IAAKH,AAAAA,CAAAA,WAAW,eAAe,QAAQ,IAAG,MAAO,MAC7C,OAAOF,OAAO,IAAI,CAAC,IAAIQ;QAG3B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,8BAA8B;YAC9Bb;YACA,OAAOc,eAAeR,YAAYK;QACtC;QAGJ,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACT,YAAYK;QACzD,IAAII,OAAO,MAAM,IAAI;YACjB,IAAIA,OAAO,KAAK,YAAYL,yBACxB,OAAON,OAAO,IAAI,CAACW,OAAO,KAAK;YAEnC,OAAOX,OAAO,IAAI,CAAC,IAAIY,yBAAyBD,OAAO,KAAK;QAChE;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,6BAA6B;YAAEjB;YAAW,UAAUe,OAAO,KAAK;QAAC;QAGzE,OAAOA;IACX;AACJ;AAEO,MAAMG,oCAAoCC,oBAAoB,oBAAoB,CAAC;IACtF,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACA;YAACC;YAA6B;gBAAE,UAAU;YAAK;SAAE;KACpD;AACL"}
|
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
-
import type {
|
|
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
|
-
}
|
|
3
|
+
import type { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
4
|
+
import type { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized, SettingsLockedByCode, UnknownTransportSettings } from "../../domain/errors.js";
|
|
14
5
|
export interface ISaveSettingsErrors {
|
|
15
6
|
validation: SettingsValidationError;
|
|
16
7
|
persistence: SettingsPersistenceError;
|
|
17
8
|
notAuthorized: SettingsNotAuthorized;
|
|
18
9
|
lockedByCode: SettingsLockedByCode;
|
|
10
|
+
unknownTransport: UnknownTransportSettings;
|
|
19
11
|
}
|
|
20
12
|
type SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];
|
|
21
13
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
25
|
-
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
14
|
+
* Everything the save path returns or publishes leaves the transport's secrets out. Only
|
|
15
|
+
* `GetSettingsRepository.get` returns them, for the transport itself.
|
|
26
16
|
*/
|
|
27
|
-
export type SavedTransportSettings =
|
|
17
|
+
export type SavedTransportSettings = TransportSettingsDefinition.Values;
|
|
28
18
|
export interface ISaveSettingsRepository {
|
|
29
|
-
execute(input:
|
|
19
|
+
execute(definition: TransportSettingsDefinition.Interface, input: TransportSettingsDefinition.Values): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
30
20
|
}
|
|
31
21
|
export declare const SaveSettingsRepository: import("@webiny/di").Abstraction<ISaveSettingsRepository>;
|
|
32
22
|
export declare namespace SaveSettingsRepository {
|
|
@@ -35,7 +25,7 @@ export declare namespace SaveSettingsRepository {
|
|
|
35
25
|
type Error = SaveSettingsError;
|
|
36
26
|
}
|
|
37
27
|
export interface ISaveSettings {
|
|
38
|
-
execute(input:
|
|
28
|
+
execute(transport: string, input: TransportSettingsDefinition.Values): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
39
29
|
}
|
|
40
30
|
export declare const SaveSettingsUseCase: import("@webiny/di").Abstraction<ISaveSettings>;
|
|
41
31
|
export declare namespace SaveSettingsUseCase {
|
|
@@ -44,10 +34,12 @@ export declare namespace SaveSettingsUseCase {
|
|
|
44
34
|
type Error = SaveSettingsError;
|
|
45
35
|
}
|
|
46
36
|
export interface MailerSettingsBeforeSavePayload {
|
|
47
|
-
|
|
37
|
+
transport: string;
|
|
38
|
+
input: TransportSettingsDefinition.Values;
|
|
48
39
|
}
|
|
49
40
|
export interface MailerSettingsAfterSavePayload {
|
|
50
|
-
|
|
41
|
+
transport: string;
|
|
42
|
+
settings: SavedTransportSettings;
|
|
51
43
|
}
|
|
52
44
|
export declare const MailerSettingsBeforeSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
53
45
|
export declare namespace MailerSettingsBeforeSaveEventHandler {
|
|
@@ -1 +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 {
|
|
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 { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport type {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode,\n UnknownTransportSettings\n} from \"~/domain/errors.js\";\n\nexport interface ISaveSettingsErrors {\n validation: SettingsValidationError;\n persistence: SettingsPersistenceError;\n notAuthorized: SettingsNotAuthorized;\n lockedByCode: SettingsLockedByCode;\n unknownTransport: UnknownTransportSettings;\n}\n\ntype SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];\n\n/**\n * Everything the save path returns or publishes leaves the transport's secrets out. Only\n * `GetSettingsRepository.get` returns them, for the transport itself.\n */\nexport type SavedTransportSettings = TransportSettingsDefinition.Values;\n\nexport interface ISaveSettingsRepository {\n execute(\n definition: TransportSettingsDefinition.Interface,\n input: TransportSettingsDefinition.Values\n ): 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(\n transport: string,\n input: TransportSettingsDefinition.Values\n ): 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 leave the transport's secrets out, so subscribers (audit logs,\n// telemetry) can't persist them.\nexport interface MailerSettingsBeforeSavePayload {\n transport: string;\n input: TransportSettingsDefinition.Values;\n}\n\nexport interface MailerSettingsAfterSavePayload {\n transport: string;\n settings: SavedTransportSettings;\n}\n\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":";AAmCO,MAAMA,yBACTC,kBAA2C;AAexC,MAAMC,sBAAsBD,kBAAiC;AAoB7D,MAAME,uCAAuCF,kBAElD;AAOK,MAAMG,sCAAsCH,kBAEjD"}
|
|
@@ -2,7 +2,7 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { SaveSettingsRepositoryImplementation } from "./SaveSettingsRepository.js";
|
|
3
3
|
import { SaveSettingsUseCaseImplementation } from "./SaveSettingsUseCase.js";
|
|
4
4
|
const SaveSettingsFeature = createFeature({
|
|
5
|
-
name: "SaveSettings",
|
|
5
|
+
name: "Mailer/SaveSettings",
|
|
6
6
|
register (container) {
|
|
7
7
|
container.register(SaveSettingsRepositoryImplementation).inSingletonScope();
|
|
8
8
|
container.register(SaveSettingsUseCaseImplementation);
|