@webiny/api-mailer 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.3fddf667ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MailerFeature.d.ts +4 -0
- package/MailerFeature.js +27 -0
- package/MailerFeature.js.map +1 -0
- package/constants.d.ts +3 -0
- package/constants.js +5 -1
- package/constants.js.map +1 -1
- package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +5 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +18 -0
- package/domain/MailTransport/abstractions.js +4 -2
- package/domain/MailTransport/abstractions.js.map +1 -1
- package/domain/MailerService/abstractions.d.ts +2 -2
- package/domain/MailerService/abstractions.js +2 -1
- package/domain/MailerService/abstractions.js.map +1 -1
- package/domain/MailerService/errors.d.ts +4 -0
- package/domain/MailerService/errors.js +29 -24
- package/domain/MailerService/errors.js.map +1 -1
- package/domain/errors.d.ts +16 -4
- package/domain/errors.js +55 -37
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +4 -0
- package/features/CodeMailerSettings/CodeMailerSettings.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettings.js +23 -0
- package/features/CodeMailerSettings/CodeMailerSettings.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +11 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransport.js +12 -9
- package/features/DummyTransport/DummyMailTransport.js.map +1 -1
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +2 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +14 -6
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -1
- package/features/DummyTransport/feature.d.ts +4 -1
- package/features/DummyTransport/feature.js +6 -5
- package/features/DummyTransport/feature.js.map +1 -1
- package/features/GetSettings/GetSettingsRepository.d.ts +6 -5
- package/features/GetSettings/GetSettingsRepository.js +46 -29
- package/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/features/GetSettings/GetSettingsUseCase.d.ts +3 -4
- package/features/GetSettings/GetSettingsUseCase.js +13 -10
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/GetSettings/abstractions.d.ts +11 -5
- package/features/GetSettings/abstractions.js +3 -2
- package/features/GetSettings/abstractions.js.map +1 -1
- package/features/GetSettings/feature.d.ts +4 -1
- package/features/GetSettings/feature.js +7 -6
- package/features/GetSettings/feature.js.map +1 -1
- package/features/GetSettings/index.d.ts +1 -1
- package/features/GetSettings/index.js +1 -3
- package/features/MailerService/MailTransportResolver.d.ts +13 -0
- package/features/MailerService/MailTransportResolver.js +37 -0
- package/features/MailerService/MailTransportResolver.js.map +1 -0
- package/features/MailerService/MailerService.d.ts +4 -6
- package/features/MailerService/MailerService.js +29 -43
- package/features/MailerService/MailerService.js.map +1 -1
- package/features/MailerService/feature.d.ts +4 -1
- package/features/MailerService/feature.js +8 -5
- package/features/MailerService/feature.js.map +1 -1
- package/features/SaveSettings/SaveSettingsRepository.d.ts +1 -1
- package/features/SaveSettings/SaveSettingsRepository.js +33 -45
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -1
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +6 -2
- package/features/SaveSettings/SaveSettingsUseCase.js +47 -41
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
- package/features/SaveSettings/abstractions.d.ts +21 -12
- package/features/SaveSettings/abstractions.js +5 -8
- package/features/SaveSettings/abstractions.js.map +1 -1
- package/features/SaveSettings/events.d.ts +3 -3
- package/features/SaveSettings/events.js +17 -12
- package/features/SaveSettings/events.js.map +1 -1
- package/features/SaveSettings/feature.d.ts +4 -1
- package/features/SaveSettings/feature.js +7 -6
- package/features/SaveSettings/feature.js.map +1 -1
- package/features/SaveSettings/index.d.ts +1 -1
- package/features/SaveSettings/index.js +1 -3
- package/features/SaveSettings/validation.d.ts +4 -17
- package/features/SaveSettings/validation.js +15 -13
- package/features/SaveSettings/validation.js.map +1 -1
- package/features/SendMail/SendMailUseCase.d.ts +2 -2
- package/features/SendMail/SendMailUseCase.js +44 -48
- package/features/SendMail/SendMailUseCase.js.map +1 -1
- package/features/SendMail/abstractions.d.ts +7 -7
- package/features/SendMail/abstractions.js +5 -8
- package/features/SendMail/abstractions.js.map +1 -1
- package/features/SendMail/events.d.ts +4 -4
- package/features/SendMail/events.js +24 -17
- package/features/SendMail/events.js.map +1 -1
- package/features/SendMail/feature.d.ts +4 -1
- package/features/SendMail/feature.js +6 -5
- package/features/SendMail/feature.js.map +1 -1
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +1 -0
- package/features/SendTestMail/SendTestMailUseCase.d.ts +15 -0
- package/features/SendTestMail/SendTestMailUseCase.js +43 -0
- package/features/SendTestMail/SendTestMailUseCase.js.map +1 -0
- package/features/SendTestMail/abstractions.d.ts +32 -0
- package/features/SendTestMail/abstractions.js +5 -0
- package/features/SendTestMail/abstractions.js.map +1 -0
- package/features/SendTestMail/feature.d.ts +4 -0
- package/features/SendTestMail/feature.js +11 -0
- package/features/SendTestMail/feature.js.map +1 -0
- package/features/SmtpTransport/SmtpConfig.js +21 -24
- package/features/SmtpTransport/SmtpConfig.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransport.d.ts +62 -3
- package/features/SmtpTransport/SmtpMailTransport.js +54 -55
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +2 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +14 -6
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -1
- package/features/SmtpTransport/feature.d.ts +4 -1
- package/features/SmtpTransport/feature.js +6 -5
- package/features/SmtpTransport/feature.js.map +1 -1
- package/graphql/MailerSchemaFactory.d.ts +10 -0
- package/graphql/MailerSchemaFactory.js +148 -0
- package/graphql/MailerSchemaFactory.js.map +1 -0
- package/index.d.ts +1 -2
- package/index.js +1 -26
- package/package.json +26 -32
- package/types.d.ts +1 -0
- package/types.js +0 -3
- package/utils/isMailboxAddress.d.ts +6 -0
- package/utils/isMailboxAddress.js +5 -0
- package/utils/isMailboxAddress.js.map +1 -0
- package/domain/Encryption/abstractions.d.ts +0 -8
- package/domain/Encryption/abstractions.js +0 -4
- package/domain/Encryption/abstractions.js.map +0 -1
- package/features/Encryption/PasswordEncryption.d.ts +0 -9
- package/features/Encryption/PasswordEncryption.js +0 -23
- package/features/Encryption/PasswordEncryption.js.map +0 -1
- package/features/Encryption/feature.d.ts +0 -1
- package/features/Encryption/feature.js +0 -10
- package/features/Encryption/feature.js.map +0 -1
- package/features/Encryption/utils/password.d.ts +0 -7
- package/features/Encryption/utils/password.js +0 -56
- package/features/Encryption/utils/password.js.map +0 -1
- package/features/Encryption/utils/secret.d.ts +0 -1
- package/features/Encryption/utils/secret.js +0 -11
- package/features/Encryption/utils/secret.js.map +0 -1
- package/features/GetSettings/index.js.map +0 -1
- package/features/MailerService/TransportFactory.d.ts +0 -2
- package/features/MailerService/TransportFactory.js +0 -31
- package/features/MailerService/TransportFactory.js.map +0 -1
- package/features/SaveSettings/index.js.map +0 -1
- package/graphql/settings.d.ts +0 -3
- package/graphql/settings.js +0 -115
- package/graphql/settings.js.map +0 -1
- package/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { Encryption } from "
|
|
3
|
-
import { GetSettingsRepository } from "./abstractions.js";
|
|
4
|
-
import type { TransportSettings } from "../../types.js";
|
|
2
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
5
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
|
+
import { GetSettingsRepository, type ISettingsWithSource } from "./abstractions.js";
|
|
5
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
6
6
|
declare class GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {
|
|
7
7
|
private keyValueStore;
|
|
8
8
|
private encryption;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
private codeSettings;
|
|
10
|
+
constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface, codeSettings: CodeMailerSettings.Interface);
|
|
11
|
+
get(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
11
12
|
}
|
|
12
13
|
export declare const GetSettingsRepositoryImplementation: typeof GetSettingsRepositoryImpl & {
|
|
13
14
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsRepository>;
|
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { Encryption } from "
|
|
3
|
-
import { GetSettingsRepository } from "./abstractions.js";
|
|
2
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
4
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
|
+
import { GetSettingsRepository } from "./abstractions.js";
|
|
5
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
5
6
|
import { MAILER_TRANSPORT_SETTINGS } from "../../constants.js";
|
|
6
7
|
class GetSettingsRepositoryImpl {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async get() {
|
|
12
|
-
const result = await this.keyValueStore.get(MAILER_TRANSPORT_SETTINGS);
|
|
13
|
-
if (result.isFail()) {
|
|
14
|
-
return Result.ok(null);
|
|
8
|
+
constructor(keyValueStore, encryption, codeSettings){
|
|
9
|
+
this.keyValueStore = keyValueStore;
|
|
10
|
+
this.encryption = encryption;
|
|
11
|
+
this.codeSettings = codeSettings;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
async get(transportName) {
|
|
14
|
+
const codeSettingsValue = this.codeSettings.get(transportName);
|
|
15
|
+
if (null !== codeSettingsValue) return Result.ok({
|
|
16
|
+
settings: codeSettingsValue,
|
|
17
|
+
source: "code"
|
|
18
|
+
});
|
|
19
|
+
const result = await this.keyValueStore.get(MAILER_TRANSPORT_SETTINGS);
|
|
20
|
+
if (result.isFail()) return Result.ok({
|
|
21
|
+
settings: null,
|
|
22
|
+
source: null
|
|
23
|
+
});
|
|
24
|
+
const settings = result.value;
|
|
25
|
+
if (!settings) return Result.ok({
|
|
26
|
+
settings: null,
|
|
27
|
+
source: null
|
|
28
|
+
});
|
|
29
|
+
const password = settings.password ? await this.encryption.decrypt(String(settings.password)) : "";
|
|
30
|
+
const port = Number(settings.port || 587);
|
|
31
|
+
const transportSettings = {
|
|
32
|
+
host: String(settings.host || ""),
|
|
33
|
+
port,
|
|
34
|
+
secure: settings.secure ?? 465 === port,
|
|
35
|
+
user: String(settings.user || ""),
|
|
36
|
+
password,
|
|
37
|
+
from: String(settings.from || ""),
|
|
38
|
+
replyTo: settings.replyTo ? String(settings.replyTo) : void 0
|
|
39
|
+
};
|
|
40
|
+
return Result.ok({
|
|
41
|
+
settings: transportSettings,
|
|
42
|
+
source: "storage"
|
|
43
|
+
});
|
|
19
44
|
}
|
|
20
|
-
|
|
21
|
-
// Decrypt password if present
|
|
22
|
-
const password = settings.password ? await this.encryption.decrypt(String(settings.password)) : "";
|
|
23
|
-
const transportSettings = {
|
|
24
|
-
host: String(settings.host || ""),
|
|
25
|
-
port: Number(settings.port || 25),
|
|
26
|
-
user: String(settings.user || ""),
|
|
27
|
-
password,
|
|
28
|
-
from: String(settings.from || ""),
|
|
29
|
-
replyTo: settings.replyTo ? String(settings.replyTo) : undefined
|
|
30
|
-
};
|
|
31
|
-
return Result.ok(transportSettings);
|
|
32
|
-
}
|
|
33
45
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({
|
|
47
|
+
implementation: GetSettingsRepositoryImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
KeyValueStore,
|
|
50
|
+
Encryption,
|
|
51
|
+
CodeMailerSettings
|
|
52
|
+
]
|
|
37
53
|
});
|
|
54
|
+
export { GetSettingsRepositoryImplementation };
|
|
38
55
|
|
|
39
56
|
//# sourceMappingURL=GetSettingsRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetSettings/GetSettingsRepository.js","sources":["../../../src/features/GetSettings/GetSettingsRepository.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 { GetSettingsRepository, type ISettingsWithSource } from \"./abstractions.js\";\nimport { CodeMailerSettings } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { MAILER_TRANSPORT_SETTINGS } from \"~/constants.js\";\n\nclass GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface,\n private codeSettings: CodeMailerSettings.Interface\n ) {}\n\n async get(transportName: string): Promise<Result<ISettingsWithSource>> {\n // Code-defined settings win over the KV store.\n const codeSettingsValue = this.codeSettings.get(transportName);\n if (codeSettingsValue !== null) {\n return Result.ok({\n settings: codeSettingsValue,\n source: \"code\"\n });\n }\n\n const result = await this.keyValueStore.get<TransportSettings>(MAILER_TRANSPORT_SETTINGS);\n\n if (result.isFail()) {\n return Result.ok({ settings: null, source: null });\n }\n\n const settings = result.value;\n if (!settings) {\n return Result.ok({ settings: null, source: null });\n }\n\n // Decrypt password if present.\n const password = settings.password\n ? await this.encryption.decrypt(String(settings.password))\n : \"\";\n\n const port = Number(settings.port || 587);\n\n const transportSettings: TransportSettings = {\n host: String(settings.host || \"\"),\n port,\n secure: settings.secure ?? port === 465,\n user: String(settings.user || \"\"),\n password,\n from: String(settings.from || \"\"),\n replyTo: settings.replyTo ? String(settings.replyTo) : undefined\n };\n\n return Result.ok({ settings: transportSettings, source: \"storage\" });\n }\n}\n\nexport const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({\n implementation: GetSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption, CodeMailerSettings]\n});\n"],"names":["GetSettingsRepositoryImpl","keyValueStore","encryption","codeSettings","transportName","codeSettingsValue","Result","result","MAILER_TRANSPORT_SETTINGS","settings","password","String","port","Number","transportSettings","undefined","GetSettingsRepositoryImplementation","GetSettingsRepository","KeyValueStore","Encryption","CodeMailerSettings"],"mappings":";;;;;;AAQA,MAAMA;IACF,YACYC,aAAsC,EACtCC,UAAgC,EAChCC,YAA0C,CACpD;aAHUF,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,IAAIC,aAAqB,EAAwC;QAEnE,MAAMC,oBAAoB,IAAI,CAAC,YAAY,CAAC,GAAG,CAACD;QAChD,IAAIC,AAAsB,SAAtBA,mBACA,OAAOC,OAAO,EAAE,CAAC;YACb,UAAUD;YACV,QAAQ;QACZ;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAoBC;QAE/D,IAAID,OAAO,MAAM,IACb,OAAOD,OAAO,EAAE,CAAC;YAAE,UAAU;YAAM,QAAQ;QAAK;QAGpD,MAAMG,WAAWF,OAAO,KAAK;QAC7B,IAAI,CAACE,UACD,OAAOH,OAAO,EAAE,CAAC;YAAE,UAAU;YAAM,QAAQ;QAAK;QAIpD,MAAMI,WAAWD,SAAS,QAAQ,GAC5B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACE,OAAOF,SAAS,QAAQ,KACtD;QAEN,MAAMG,OAAOC,OAAOJ,SAAS,IAAI,IAAI;QAErC,MAAMK,oBAAuC;YACzC,MAAMH,OAAOF,SAAS,IAAI,IAAI;YAC9BG;YACA,QAAQH,SAAS,MAAM,IAAIG,AAAS,QAATA;YAC3B,MAAMD,OAAOF,SAAS,IAAI,IAAI;YAC9BC;YACA,MAAMC,OAAOF,SAAS,IAAI,IAAI;YAC9B,SAASA,SAAS,OAAO,GAAGE,OAAOF,SAAS,OAAO,IAAIM;QAC3D;QAEA,OAAOT,OAAO,EAAE,CAAC;YAAE,UAAUQ;YAAmB,QAAQ;QAAU;IACtE;AACJ;AAEO,MAAME,sCAAsCC,sBAAsB,oBAAoB,CAAC;IAC1F,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;QAAYC;KAAmB;AACjE"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
3
|
-
import type { TransportSettings } from "../../types.js";
|
|
2
|
+
import { GetSettingsUseCase, GetSettingsRepository, type ISettingsWithSource } from "./abstractions.js";
|
|
4
3
|
declare class GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {
|
|
5
4
|
private repository;
|
|
6
5
|
constructor(repository: GetSettingsRepository.Interface);
|
|
7
|
-
execute(): Promise<Result<
|
|
6
|
+
execute(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
8
7
|
}
|
|
9
8
|
export declare const GetSettingsUseCaseImplementation: typeof GetSettingsUseCaseImpl & {
|
|
10
|
-
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsUseCase>;
|
|
11
10
|
};
|
|
12
11
|
export {};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetSettingsRepository, GetSettingsUseCase } from "./abstractions.js";
|
|
2
2
|
class GetSettingsUseCaseImpl {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
constructor(repository){
|
|
4
|
+
this.repository = repository;
|
|
5
|
+
}
|
|
6
|
+
execute(transportName) {
|
|
7
|
+
return this.repository.get(transportName);
|
|
8
|
+
}
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({
|
|
11
|
+
implementation: GetSettingsUseCaseImpl,
|
|
12
|
+
dependencies: [
|
|
13
|
+
GetSettingsRepository
|
|
14
|
+
]
|
|
13
15
|
});
|
|
16
|
+
export { GetSettingsUseCaseImplementation };
|
|
14
17
|
|
|
15
18
|
//# sourceMappingURL=GetSettingsUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetSettings/GetSettingsUseCase.js","sources":["../../../src/features/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n GetSettingsUseCase,\n GetSettingsRepository,\n type ISettingsWithSource\n} from \"./abstractions.js\";\n\nclass GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {\n constructor(private repository: GetSettingsRepository.Interface) {}\n\n execute(transportName: string): Promise<Result<ISettingsWithSource>> {\n return this.repository.get(transportName);\n }\n}\n\nexport const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({\n implementation: GetSettingsUseCaseImpl,\n dependencies: [GetSettingsRepository]\n});\n"],"names":["GetSettingsUseCaseImpl","repository","transportName","GetSettingsUseCaseImplementation","GetSettingsUseCase","GetSettingsRepository"],"mappings":";AAOA,MAAMA;IACF,YAAoBC,UAA2C,CAAE;aAA7CA,UAAU,GAAVA;IAA8C;IAElE,QAAQC,aAAqB,EAAwC;QACjE,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACA;IAC/B;AACJ;AAEO,MAAMC,mCAAmCC,mBAAmB,oBAAoB,CAAC;IACpF,gBAAgBJ;IAChB,cAAc;QAACK;KAAsB;AACzC"}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { TransportSettings } from "../../types.js";
|
|
3
|
+
export type MailerSettingsSource = "code" | "storage" | null;
|
|
4
|
+
export interface ISettingsWithSource {
|
|
5
|
+
settings: TransportSettings | null;
|
|
6
|
+
source: MailerSettingsSource;
|
|
7
|
+
}
|
|
3
8
|
export interface IGetSettingsRepository {
|
|
4
|
-
get(): Promise<Result<
|
|
9
|
+
get(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
5
10
|
}
|
|
6
11
|
export declare const GetSettingsRepository: import("@webiny/di").Abstraction<IGetSettingsRepository>;
|
|
7
12
|
export declare namespace GetSettingsRepository {
|
|
8
13
|
type Interface = IGetSettingsRepository;
|
|
14
|
+
type Return = Promise<Result<ISettingsWithSource>>;
|
|
9
15
|
}
|
|
10
|
-
export interface
|
|
11
|
-
execute(): Promise<Result<
|
|
16
|
+
export interface IGetSettingsUseCase {
|
|
17
|
+
execute(transportName: string): Promise<Result<ISettingsWithSource>>;
|
|
12
18
|
}
|
|
13
|
-
export declare const GetSettingsUseCase: import("@webiny/di").Abstraction<
|
|
19
|
+
export declare const GetSettingsUseCase: import("@webiny/di").Abstraction<IGetSettingsUseCase>;
|
|
14
20
|
export declare namespace GetSettingsUseCase {
|
|
15
|
-
type Interface =
|
|
21
|
+
type Interface = IGetSettingsUseCase;
|
|
16
22
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const GetSettingsRepository = createAbstraction("GetSettingsRepository");
|
|
3
|
+
const GetSettingsUseCase = createAbstraction("GetSettingsUseCase");
|
|
4
|
+
export { GetSettingsRepository, GetSettingsUseCase };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetSettings/abstractions.js","sources":["../../../src/features/GetSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { TransportSettings } from \"~/types.js\";\n\nexport type MailerSettingsSource = \"code\" | \"storage\" | null;\n\nexport interface ISettingsWithSource {\n settings: TransportSettings | null;\n source: MailerSettingsSource;\n}\n\nexport interface IGetSettingsRepository {\n get(transportName: string): Promise<Result<ISettingsWithSource>>;\n}\n\nexport const GetSettingsRepository =\n createAbstraction<IGetSettingsRepository>(\"GetSettingsRepository\");\n\nexport namespace GetSettingsRepository {\n export type Interface = IGetSettingsRepository;\n export type Return = Promise<Result<ISettingsWithSource>>;\n}\n\nexport interface IGetSettingsUseCase {\n execute(transportName: string): Promise<Result<ISettingsWithSource>>;\n}\n\nexport const GetSettingsUseCase = createAbstraction<IGetSettingsUseCase>(\"GetSettingsUseCase\");\n\nexport namespace GetSettingsUseCase {\n export type Interface = IGetSettingsUseCase;\n}\n"],"names":["GetSettingsRepository","createAbstraction","GetSettingsUseCase"],"mappings":";AAeO,MAAMA,wBACTC,kBAA0C;AAWvC,MAAMC,qBAAqBD,kBAAuC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { GetSettingsRepositoryImplementation } from "./GetSettingsRepository.js";
|
|
3
3
|
import { GetSettingsUseCaseImplementation } from "./GetSettingsUseCase.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const GetSettingsFeature = createFeature({
|
|
5
|
+
name: "GetSettings",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(GetSettingsRepositoryImplementation).inSingletonScope();
|
|
8
|
+
container.register(GetSettingsUseCaseImplementation);
|
|
9
|
+
}
|
|
10
10
|
});
|
|
11
|
+
export { GetSettingsFeature };
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 +1 @@
|
|
|
1
|
-
export { GetSettingsUseCase } from "./abstractions.js";
|
|
1
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import { MailTransportResolver as Abstraction } from "../../domain/MailTransport/abstractions.js";
|
|
3
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
4
|
+
declare class MailTransportResolverImpl implements Abstraction.Interface {
|
|
5
|
+
private getSettingsRepository;
|
|
6
|
+
private transportFactories;
|
|
7
|
+
constructor(getSettingsRepository: GetSettingsRepository.Interface, transportFactories: MailTransportFactory.Interface[]);
|
|
8
|
+
resolve(): Promise<Abstraction.Resolved | null>;
|
|
9
|
+
}
|
|
10
|
+
export declare const MailTransportResolver: typeof MailTransportResolverImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailTransport/abstractions.js").IMailTransportResolver>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MailTransportFactory, MailTransportResolver } from "../../domain/MailTransport/abstractions.js";
|
|
2
|
+
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
3
|
+
class MailTransportResolverImpl {
|
|
4
|
+
constructor(getSettingsRepository, transportFactories){
|
|
5
|
+
this.getSettingsRepository = getSettingsRepository;
|
|
6
|
+
this.transportFactories = transportFactories;
|
|
7
|
+
}
|
|
8
|
+
async resolve() {
|
|
9
|
+
const factories = [
|
|
10
|
+
...this.transportFactories
|
|
11
|
+
].reverse();
|
|
12
|
+
for (const factory of factories){
|
|
13
|
+
const result = await this.getSettingsRepository.get(factory.name);
|
|
14
|
+
const { settings } = result.value;
|
|
15
|
+
if (factory.canUse(settings)) return {
|
|
16
|
+
factory,
|
|
17
|
+
settings
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const MailTransportResolver_MailTransportResolver = MailTransportResolver.createImplementation({
|
|
24
|
+
implementation: MailTransportResolverImpl,
|
|
25
|
+
dependencies: [
|
|
26
|
+
GetSettingsRepository,
|
|
27
|
+
[
|
|
28
|
+
MailTransportFactory,
|
|
29
|
+
{
|
|
30
|
+
multiple: true
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
export { MailTransportResolver_MailTransportResolver as MailTransportResolver };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=MailTransportResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/MailerService/MailTransportResolver.js","sources":["../../../src/features/MailerService/MailTransportResolver.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport { MailTransportResolver as Abstraction } from \"~/domain/MailTransport/abstractions.js\";\nimport { GetSettingsRepository } from \"../GetSettings/abstractions.js\";\n\nclass MailTransportResolverImpl implements Abstraction.Interface {\n constructor(\n private getSettingsRepository: GetSettingsRepository.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async resolve(): Promise<Abstraction.Resolved | null> {\n const factories = [...this.transportFactories].reverse();\n\n for (const factory of factories) {\n const result = await this.getSettingsRepository.get(factory.name);\n const { settings } = result.value;\n\n if (factory.canUse(settings)) {\n return { factory, settings };\n }\n }\n\n return null;\n }\n}\n\nexport const MailTransportResolver = Abstraction.createImplementation({\n implementation: MailTransportResolverImpl,\n dependencies: [GetSettingsRepository, [MailTransportFactory, { multiple: true }]]\n});\n"],"names":["MailTransportResolverImpl","getSettingsRepository","transportFactories","factories","factory","result","settings","MailTransportResolver","Abstraction","GetSettingsRepository","MailTransportFactory"],"mappings":";;AAIA,MAAMA;IACF,YACYC,qBAAsD,EACtDC,kBAAoD,CAC9D;aAFUD,qBAAqB,GAArBA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,UAAgD;QAClD,MAAMC,YAAY;eAAI,IAAI,CAAC,kBAAkB;SAAC,CAAC,OAAO;QAEtD,KAAK,MAAMC,WAAWD,UAAW;YAC7B,MAAME,SAAS,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAACD,QAAQ,IAAI;YAChE,MAAM,EAAEE,QAAQ,EAAE,GAAGD,OAAO,KAAK;YAEjC,IAAID,QAAQ,MAAM,CAACE,WACf,OAAO;gBAAEF;gBAASE;YAAS;QAEnC;QAEA,OAAO;IACX;AACJ;AAEO,MAAMC,8CAAwBC,sBAAAA,oBAAgC,CAAC;IAClE,gBAAgBR;IAChB,cAAc;QAACS;QAAuB;YAACC;YAAsB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrF"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { MailerService as Abstraction } from "../../domain/MailerService/abstractions.js";
|
|
2
|
-
import {
|
|
3
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
2
|
+
import { MailTransportResolver } from "../../domain/MailTransport/abstractions.js";
|
|
4
3
|
import type { TransportSendData } from "../../types.js";
|
|
5
4
|
declare class MailerServiceImpl implements Abstraction.Interface {
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
constructor(getSettingsRepository: GetSettingsRepository.Interface, transportFactories: MailTransportFactory.Interface[]);
|
|
5
|
+
private transportResolver;
|
|
6
|
+
constructor(transportResolver: MailTransportResolver.Interface);
|
|
9
7
|
sendMail<T = any>(data: TransportSendData): Abstraction.Return<T>;
|
|
10
|
-
private
|
|
8
|
+
private createTransport;
|
|
11
9
|
}
|
|
12
10
|
export declare const MailerService: typeof MailerServiceImpl & {
|
|
13
11
|
__abstraction: import("@webiny/di").Abstraction<import("~/domain/MailerService/abstractions.js").IMailerService>;
|
|
@@ -1,52 +1,38 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { MailerService
|
|
3
|
-
import { NoTransportAvailableError,
|
|
4
|
-
import {
|
|
5
|
-
import { GetSettingsRepository } from "../GetSettings/abstractions.js";
|
|
6
|
-
import { getDefaultSettingsFromEnv } from "./TransportFactory.js";
|
|
2
|
+
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
3
|
+
import { NoTransportAvailableError, TransportCreateError, TransportSendError } from "../../domain/MailerService/errors.js";
|
|
4
|
+
import { MailTransportResolver } from "../../domain/MailTransport/abstractions.js";
|
|
7
5
|
class MailerServiceImpl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.transportFactories = transportFactories;
|
|
11
|
-
}
|
|
12
|
-
async sendMail(data) {
|
|
13
|
-
// Get settings from repository or environment variables
|
|
14
|
-
const result = await this.getSettingsRepository.get();
|
|
15
|
-
const settings = result.value ?? getDefaultSettingsFromEnv();
|
|
16
|
-
if (!settings) {
|
|
17
|
-
return Result.fail(new NoSettingsConfiguredError());
|
|
6
|
+
constructor(transportResolver){
|
|
7
|
+
this.transportResolver = transportResolver;
|
|
18
8
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (response.error) {
|
|
30
|
-
return Result.fail(new TransportSendError(response.error));
|
|
31
|
-
}
|
|
32
|
-
return Result.ok(response);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Result.fail(new TransportSendError(error));
|
|
9
|
+
async sendMail(data) {
|
|
10
|
+
const transport = await this.createTransport();
|
|
11
|
+
if (!transport) return Result.fail(new NoTransportAvailableError());
|
|
12
|
+
try {
|
|
13
|
+
const response = await transport.send(data);
|
|
14
|
+
if (response.error) return Result.fail(new TransportSendError(response.error));
|
|
15
|
+
return Result.ok(response);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return Result.fail(new TransportSendError(error));
|
|
18
|
+
}
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
async createTransport() {
|
|
21
|
+
const resolved = await this.transportResolver.resolve();
|
|
22
|
+
if (!resolved) return null;
|
|
23
|
+
try {
|
|
24
|
+
return await resolved.factory.createTransport(resolved.settings);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new TransportCreateError(error);
|
|
27
|
+
}
|
|
40
28
|
}
|
|
41
|
-
const factory = this.transportFactories[this.transportFactories.length - 1];
|
|
42
|
-
return factory.createTransport(settings);
|
|
43
|
-
}
|
|
44
29
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
const MailerService_MailerService = MailerService.createImplementation({
|
|
31
|
+
implementation: MailerServiceImpl,
|
|
32
|
+
dependencies: [
|
|
33
|
+
MailTransportResolver
|
|
34
|
+
]
|
|
50
35
|
});
|
|
36
|
+
export { MailerService_MailerService as MailerService };
|
|
51
37
|
|
|
52
38
|
//# sourceMappingURL=MailerService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 { MailTransportResolver } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(private transportResolver: MailTransportResolver.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 private async createTransport(): Promise<MailTransport.Interface | null> {\n const resolved = await this.transportResolver.resolve();\n\n if (!resolved) {\n return null;\n }\n\n try {\n return await resolved.factory.createTransport(resolved.settings!);\n } catch (error) {\n throw new TransportCreateError(error);\n }\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [MailTransportResolver]\n});\n"],"names":["MailerServiceImpl","transportResolver","data","transport","Result","NoTransportAvailableError","response","TransportSendError","error","resolved","TransportCreateError","MailerService","Abstraction","MailTransportResolver"],"mappings":";;;;AAWA,MAAMA;IACF,YAAoBC,iBAAkD,CAAE;aAApDA,iBAAiB,GAAjBA;IAAqD;IAEzE,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,MAAc,kBAA2D;QACrE,MAAMC,WAAW,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO;QAErD,IAAI,CAACA,UACD,OAAO;QAGX,IAAI;YACA,OAAO,MAAMA,SAAS,OAAO,CAAC,eAAe,CAACA,SAAS,QAAQ;QACnE,EAAE,OAAOD,OAAO;YACZ,MAAM,IAAIE,qBAAqBF;QACnC;IACJ;AACJ;AAEO,MAAMG,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBZ;IAChB,cAAc;QAACa;KAAsB;AACzC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { MailTransportResolver } from "./MailTransportResolver.js";
|
|
2
3
|
import { MailerService } from "./MailerService.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const MailerServiceFeature = createFeature({
|
|
5
|
+
name: "Mailer/MailerService",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(MailTransportResolver).inSingletonScope();
|
|
8
|
+
container.register(MailerService).inSingletonScope();
|
|
9
|
+
}
|
|
8
10
|
});
|
|
11
|
+
export { MailerServiceFeature };
|
|
9
12
|
|
|
10
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/MailerService/feature.js","sources":["../../../src/features/MailerService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailTransportResolver } from \"./MailTransportResolver.js\";\nimport { MailerService } from \"./MailerService.js\";\n\nexport const MailerServiceFeature = createFeature({\n name: \"Mailer/MailerService\",\n register(container) {\n container.register(MailTransportResolver).inSingletonScope();\n container.register(MailerService).inSingletonScope();\n }\n});\n"],"names":["MailerServiceFeature","createFeature","container","MailTransportResolver","MailerService"],"mappings":";;;AAIO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,uBAAuB,gBAAgB;QAC1DD,UAAU,QAAQ,CAACE,eAAe,gBAAgB;IACtD;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Encryption } from "
|
|
1
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
2
2
|
import { SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
4
|
declare class SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {
|