@webiny/api-mailer 6.6.0-alpha.12 → 6.6.0-alpha.14
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 +4 -8
- package/MailerFeature.js.map +1 -1
- package/constants.d.ts +0 -2
- package/constants.js +1 -3
- package/constants.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 -9
- package/domain/errors.js +27 -17
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.d.ts +3 -2
- package/exports/api/mailer.js +3 -2
- 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/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 +25 -24
- 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/graphql/MailerSchemaFactory.js +31 -44
- 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.d.ts +0 -4
- package/features/CodeMailerSettings/feature.js +0 -11
- package/features/CodeMailerSettings/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 -78
- package/features/SmtpTransport/SmtpMailTransport.js +0 -61
- package/features/SmtpTransport/SmtpMailTransport.js.map +0 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +0 -12
- package/features/SmtpTransport/SmtpMailTransportFactory.js +0 -26
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +0 -1
- package/features/SmtpTransport/feature.d.ts +0 -4
- package/features/SmtpTransport/feature.js +0 -11
- package/features/SmtpTransport/feature.js.map +0 -1
package/MailerFeature.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
|
-
import { CodeMailerSettingsFeature } from "./features/CodeMailerSettings/feature.js";
|
|
3
|
-
import { SmtpTransportFeature } from "./features/SmtpTransport/feature.js";
|
|
4
|
-
import { GetSettingsFeature } from "./features/GetSettings/feature.js";
|
|
5
|
-
import { SaveSettingsFeature } from "./features/SaveSettings/feature.js";
|
|
6
2
|
import { MailerServiceFeature } from "./features/MailerService/feature.js";
|
|
7
3
|
import { SendMailFeature } from "./features/SendMail/feature.js";
|
|
8
4
|
import { SendTestMailFeature } from "./features/SendTestMail/feature.js";
|
|
9
5
|
import { IsMailerConfiguredFeature } from "./features/IsMailerConfigured/feature.js";
|
|
6
|
+
import { GetSettingsFeature } from "./features/GetSettings/feature.js";
|
|
7
|
+
import { SaveSettingsFeature } from "./features/SaveSettings/feature.js";
|
|
10
8
|
import { MailerSchemaFactory } from "./graphql/MailerSchemaFactory.js";
|
|
11
9
|
const MailerFeature = createFeature({
|
|
12
10
|
name: "Mailer",
|
|
13
11
|
register (container) {
|
|
14
|
-
CodeMailerSettingsFeature.register(container);
|
|
15
|
-
SmtpTransportFeature.register(container);
|
|
16
|
-
GetSettingsFeature.register(container);
|
|
17
|
-
SaveSettingsFeature.register(container);
|
|
18
12
|
MailerServiceFeature.register(container);
|
|
19
13
|
SendMailFeature.register(container);
|
|
20
14
|
SendTestMailFeature.register(container);
|
|
21
15
|
IsMailerConfiguredFeature.register(container);
|
|
16
|
+
GetSettingsFeature.register(container);
|
|
17
|
+
SaveSettingsFeature.register(container);
|
|
22
18
|
container.register(MailerSchemaFactory);
|
|
23
19
|
}
|
|
24
20
|
});
|
package/MailerFeature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailerFeature.js","sources":["../src/MailerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport {
|
|
1
|
+
{"version":3,"file":"MailerFeature.js","sources":["../src/MailerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerServiceFeature } from \"~/features/MailerService/feature.js\";\nimport { SendMailFeature } from \"~/features/SendMail/feature.js\";\nimport { SendTestMailFeature } from \"~/features/SendTestMail/feature.js\";\nimport { IsMailerConfiguredFeature } from \"~/features/IsMailerConfigured/feature.js\";\nimport { GetSettingsFeature } from \"~/features/GetSettings/feature.js\";\nimport { SaveSettingsFeature } from \"~/features/SaveSettings/feature.js\";\nimport { MailerSchemaFactory } from \"~/graphql/MailerSchemaFactory.js\";\n\n/*\n * Sending, without a transport of its own. Transports are `MailTransportFactory` implementations\n * registered by other packages (`@webiny/mailer-smtp`) or by the project. A transport with stored\n * settings registers a `TransportSettingsDefinition`; reading and saving them is done here.\n */\nexport const MailerFeature = createFeature({\n name: \"Mailer\",\n register(container) {\n MailerServiceFeature.register(container);\n SendMailFeature.register(container);\n SendTestMailFeature.register(container);\n IsMailerConfiguredFeature.register(container);\n GetSettingsFeature.register(container);\n SaveSettingsFeature.register(container);\n container.register(MailerSchemaFactory);\n }\n});\n"],"names":["MailerFeature","createFeature","container","MailerServiceFeature","SendMailFeature","SendTestMailFeature","IsMailerConfiguredFeature","GetSettingsFeature","SaveSettingsFeature","MailerSchemaFactory"],"mappings":";;;;;;;;AAcO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdC,qBAAqB,QAAQ,CAACD;QAC9BE,gBAAgB,QAAQ,CAACF;QACzBG,oBAAoB,QAAQ,CAACH;QAC7BI,0BAA0B,QAAQ,CAACJ;QACnCK,mBAAmB,QAAQ,CAACL;QAC5BM,oBAAoB,QAAQ,CAACN;QAC7BA,UAAU,QAAQ,CAACO;IACvB;AACJ"}
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
const MAILER_TRANSPORT_SETTINGS = "Mailer/Settings/Transport";
|
|
2
1
|
const MAILER_SETTINGS_PERMISSION = "mailer.settings";
|
|
3
|
-
|
|
4
|
-
export { MAILER_SETTINGS_PERMISSION, MAILER_TRANSPORT_SETTINGS, SMTP_TRANSPORT_NAME };
|
|
2
|
+
export { MAILER_SETTINGS_PERMISSION };
|
|
5
3
|
|
|
6
4
|
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const MAILER_SETTINGS_PERMISSION = \"mailer.settings\";\n"],"names":["MAILER_SETTINGS_PERMISSION"],"mappings":"AAAO,MAAMA,6BAA6B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
export type TransportSettingsValues = Record<string, unknown>;
|
|
3
|
+
export interface ITransportSettingsDefinition {
|
|
4
|
+
/**
|
|
5
|
+
* The transport the settings belong to. Matches the `name` of its `MailTransportFactory`.
|
|
6
|
+
*/
|
|
7
|
+
transport: string;
|
|
8
|
+
/**
|
|
9
|
+
* Key-value store key. Defaults to `Mailer/Settings/Transport/<transport>`.
|
|
10
|
+
*/
|
|
11
|
+
storageKey?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Validates the settings sent to save. Secret fields are optional in it: a save without one
|
|
14
|
+
* keeps the stored value.
|
|
15
|
+
*/
|
|
16
|
+
schema: ZodType;
|
|
17
|
+
/**
|
|
18
|
+
* Fields that are encrypted at rest and never leave the server: they are left out of the
|
|
19
|
+
* settings the GraphQL API returns and out of the save events.
|
|
20
|
+
*/
|
|
21
|
+
secrets?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Fields a stored secret is bound to. When a save changes one of them, the secrets must be sent
|
|
24
|
+
* again, so a settings editor can't point the transport at a server they control and receive the
|
|
25
|
+
* stored secret.
|
|
26
|
+
*/
|
|
27
|
+
secretsBoundTo?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Fills in defaults, on read and before comparing `secretsBoundTo` fields on save.
|
|
30
|
+
*/
|
|
31
|
+
withDefaults?(settings: TransportSettingsValues): TransportSettingsValues;
|
|
32
|
+
/**
|
|
33
|
+
* Settings set in code. When not null, they are used instead of the stored ones, and saving
|
|
34
|
+
* fails with `SettingsLockedByCode`.
|
|
35
|
+
*/
|
|
36
|
+
getCodeSettings?(): TransportSettingsValues | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Registered by a transport whose settings are stored and edited in Settings > Mailer. The core
|
|
40
|
+
* mailer then provides reading, saving, the `mailer.settings` permission, encryption of secrets,
|
|
41
|
+
* the save events and the audit log for it.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TransportSettingsDefinition: import("@webiny/di").Abstraction<ITransportSettingsDefinition>;
|
|
44
|
+
export declare namespace TransportSettingsDefinition {
|
|
45
|
+
type Interface = ITransportSettingsDefinition;
|
|
46
|
+
type Values = TransportSettingsValues;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/TransportSettings/abstractions.js","sources":["../../../src/domain/TransportSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ZodType } from \"zod\";\n\nexport type TransportSettingsValues = Record<string, unknown>;\n\nexport interface ITransportSettingsDefinition {\n /**\n * The transport the settings belong to. Matches the `name` of its `MailTransportFactory`.\n */\n transport: string;\n /**\n * Key-value store key. Defaults to `Mailer/Settings/Transport/<transport>`.\n */\n storageKey?: string;\n /**\n * Validates the settings sent to save. Secret fields are optional in it: a save without one\n * keeps the stored value.\n */\n schema: ZodType;\n /**\n * Fields that are encrypted at rest and never leave the server: they are left out of the\n * settings the GraphQL API returns and out of the save events.\n */\n secrets?: string[];\n /**\n * Fields a stored secret is bound to. When a save changes one of them, the secrets must be sent\n * again, so a settings editor can't point the transport at a server they control and receive the\n * stored secret.\n */\n secretsBoundTo?: string[];\n /**\n * Fills in defaults, on read and before comparing `secretsBoundTo` fields on save.\n */\n withDefaults?(settings: TransportSettingsValues): TransportSettingsValues;\n /**\n * Settings set in code. When not null, they are used instead of the stored ones, and saving\n * fails with `SettingsLockedByCode`.\n */\n getCodeSettings?(): TransportSettingsValues | null;\n}\n\n/**\n * Registered by a transport whose settings are stored and edited in Settings > Mailer. The core\n * mailer then provides reading, saving, the `mailer.settings` permission, encryption of secrets,\n * the save events and the audit log for it.\n */\nexport const TransportSettingsDefinition = createAbstraction<ITransportSettingsDefinition>(\n \"Mailer/TransportSettingsDefinition\"\n);\n\nexport namespace TransportSettingsDefinition {\n export type Interface = ITransportSettingsDefinition;\n export type Values = TransportSettingsValues;\n}\n"],"names":["TransportSettingsDefinition","createAbstraction"],"mappings":";AA8CO,MAAMA,8BAA8BC,kBACvC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TransportSettingsDefinition } from "./abstractions.js";
|
|
2
|
+
export declare const DEFAULT_STORAGE_KEY_PREFIX = "Mailer/Settings/Transport/";
|
|
3
|
+
export declare const findDefinition: (definitions: TransportSettingsDefinition.Interface[], transport: string) => TransportSettingsDefinition.Interface | null;
|
|
4
|
+
export declare const getStorageKey: (definition: TransportSettingsDefinition.Interface) => string;
|
|
5
|
+
export declare const withDefaults: (definition: TransportSettingsDefinition.Interface, settings: TransportSettingsDefinition.Values) => TransportSettingsDefinition.Values;
|
|
6
|
+
export declare const withoutSecrets: (definition: TransportSettingsDefinition.Interface, settings: TransportSettingsDefinition.Values) => TransportSettingsDefinition.Values;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const DEFAULT_STORAGE_KEY_PREFIX = "Mailer/Settings/Transport/";
|
|
2
|
+
const findDefinition = (definitions, transport)=>[
|
|
3
|
+
...definitions
|
|
4
|
+
].reverse().find((d)=>d.transport === transport) ?? null;
|
|
5
|
+
const getStorageKey = (definition)=>definition.storageKey ?? `${DEFAULT_STORAGE_KEY_PREFIX}${definition.transport}`;
|
|
6
|
+
const withDefaults = (definition, settings)=>definition.withDefaults ? definition.withDefaults(settings) : settings;
|
|
7
|
+
const withoutSecrets = (definition, settings)=>{
|
|
8
|
+
const secrets = new Set(definition.secrets ?? []);
|
|
9
|
+
return Object.fromEntries(Object.entries(settings).filter(([key])=>!secrets.has(key)));
|
|
10
|
+
};
|
|
11
|
+
export { DEFAULT_STORAGE_KEY_PREFIX, findDefinition, getStorageKey, withDefaults, withoutSecrets };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=findDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/TransportSettings/findDefinition.js","sources":["../../../src/domain/TransportSettings/findDefinition.ts"],"sourcesContent":["import type { TransportSettingsDefinition } from \"./abstractions.js\";\n\nexport const DEFAULT_STORAGE_KEY_PREFIX = \"Mailer/Settings/Transport/\";\n\n// The last registered definition for a transport wins, so a project can replace a package's.\nexport const findDefinition = (\n definitions: TransportSettingsDefinition.Interface[],\n transport: string\n): TransportSettingsDefinition.Interface | null => {\n return [...definitions].reverse().find(d => d.transport === transport) ?? null;\n};\n\nexport const getStorageKey = (definition: TransportSettingsDefinition.Interface): string => {\n return definition.storageKey ?? `${DEFAULT_STORAGE_KEY_PREFIX}${definition.transport}`;\n};\n\nexport const withDefaults = (\n definition: TransportSettingsDefinition.Interface,\n settings: TransportSettingsDefinition.Values\n): TransportSettingsDefinition.Values => {\n return definition.withDefaults ? definition.withDefaults(settings) : settings;\n};\n\nexport const withoutSecrets = (\n definition: TransportSettingsDefinition.Interface,\n settings: TransportSettingsDefinition.Values\n): TransportSettingsDefinition.Values => {\n const secrets = new Set(definition.secrets ?? []);\n return Object.fromEntries(Object.entries(settings).filter(([key]) => !secrets.has(key)));\n};\n"],"names":["DEFAULT_STORAGE_KEY_PREFIX","findDefinition","definitions","transport","d","getStorageKey","definition","withDefaults","settings","withoutSecrets","secrets","Set","Object","key"],"mappings":"AAEO,MAAMA,6BAA6B;AAGnC,MAAMC,iBAAiB,CAC1BC,aACAC,YAEO;WAAID;KAAY,CAAC,OAAO,GAAG,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS,KAAKD,cAAc;AAGvE,MAAME,gBAAgB,CAACC,aACnBA,WAAW,UAAU,IAAI,GAAGN,6BAA6BM,WAAW,SAAS,EAAE;AAGnF,MAAMC,eAAe,CACxBD,YACAE,WAEOF,WAAW,YAAY,GAAGA,WAAW,YAAY,CAACE,YAAYA;AAGlE,MAAMC,iBAAiB,CAC1BH,YACAE;IAEA,MAAME,UAAU,IAAIC,IAAIL,WAAW,OAAO,IAAI,EAAE;IAChD,OAAOM,OAAO,WAAW,CAACA,OAAO,OAAO,CAACJ,UAAU,MAAM,CAAC,CAAC,CAACK,IAAI,GAAK,CAACH,QAAQ,GAAG,CAACG;AACtF"}
|
package/domain/errors.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ export declare class MailValidationError extends BaseError<{
|
|
|
6
6
|
readonly code: "Mailer/SendMail/Validation";
|
|
7
7
|
constructor(errors: ZodError["issues"]);
|
|
8
8
|
}
|
|
9
|
+
export declare class TestMailNotAuthorized extends BaseError {
|
|
10
|
+
readonly code: "Mailer/SendTestMail/NotAuthorized";
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class TestMailNotConfigured extends BaseError {
|
|
14
|
+
readonly code: "Mailer/SendTestMail/NotConfigured";
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
9
17
|
export declare class SettingsValidationError extends BaseError<{
|
|
10
18
|
errors: ZodError["issues"];
|
|
11
19
|
}> {
|
|
@@ -14,7 +22,7 @@ export declare class SettingsValidationError extends BaseError<{
|
|
|
14
22
|
}
|
|
15
23
|
export declare class SettingsNotAuthorized extends BaseError {
|
|
16
24
|
readonly code: "Mailer/Settings/NotAuthorized";
|
|
17
|
-
constructor();
|
|
25
|
+
constructor(message?: string);
|
|
18
26
|
}
|
|
19
27
|
export declare class SettingsPersistenceError extends BaseError<{
|
|
20
28
|
error: Error;
|
|
@@ -22,15 +30,13 @@ export declare class SettingsPersistenceError extends BaseError<{
|
|
|
22
30
|
readonly code: "Mailer/Settings/Persistence";
|
|
23
31
|
constructor(error: Error);
|
|
24
32
|
}
|
|
25
|
-
export declare class TestMailNotAuthorized extends BaseError {
|
|
26
|
-
readonly code: "Mailer/SendTestMail/NotAuthorized";
|
|
27
|
-
constructor();
|
|
28
|
-
}
|
|
29
|
-
export declare class TestMailNotConfigured extends BaseError {
|
|
30
|
-
readonly code: "Mailer/SendTestMail/NotConfigured";
|
|
31
|
-
constructor();
|
|
32
|
-
}
|
|
33
33
|
export declare class SettingsLockedByCode extends BaseError {
|
|
34
34
|
readonly code: "Mailer/Settings/LockedByCode";
|
|
35
35
|
constructor();
|
|
36
36
|
}
|
|
37
|
+
export declare class UnknownTransportSettings extends BaseError<{
|
|
38
|
+
transport: string;
|
|
39
|
+
}> {
|
|
40
|
+
readonly code: "Mailer/Settings/UnknownTransport";
|
|
41
|
+
constructor(transport: string);
|
|
42
|
+
}
|
package/domain/errors.js
CHANGED
|
@@ -9,6 +9,20 @@ class MailValidationError extends BaseError {
|
|
|
9
9
|
}), this.code = "Mailer/SendMail/Validation";
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
class TestMailNotAuthorized extends BaseError {
|
|
13
|
+
constructor(){
|
|
14
|
+
super({
|
|
15
|
+
message: "Not allowed to send a test email."
|
|
16
|
+
}), this.code = "Mailer/SendTestMail/NotAuthorized";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class TestMailNotConfigured extends BaseError {
|
|
20
|
+
constructor(){
|
|
21
|
+
super({
|
|
22
|
+
message: "No mail transport is configured, so there is nothing to test."
|
|
23
|
+
}), this.code = "Mailer/SendTestMail/NotConfigured";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
12
26
|
class SettingsValidationError extends BaseError {
|
|
13
27
|
constructor(errors){
|
|
14
28
|
super({
|
|
@@ -20,9 +34,9 @@ class SettingsValidationError extends BaseError {
|
|
|
20
34
|
}
|
|
21
35
|
}
|
|
22
36
|
class SettingsNotAuthorized extends BaseError {
|
|
23
|
-
constructor(){
|
|
37
|
+
constructor(message = "Not allowed to update the mailer settings."){
|
|
24
38
|
super({
|
|
25
|
-
message
|
|
39
|
+
message
|
|
26
40
|
}), this.code = "Mailer/Settings/NotAuthorized";
|
|
27
41
|
}
|
|
28
42
|
}
|
|
@@ -36,20 +50,6 @@ class SettingsPersistenceError extends BaseError {
|
|
|
36
50
|
}), this.code = "Mailer/Settings/Persistence";
|
|
37
51
|
}
|
|
38
52
|
}
|
|
39
|
-
class TestMailNotAuthorized extends BaseError {
|
|
40
|
-
constructor(){
|
|
41
|
-
super({
|
|
42
|
-
message: "Not allowed to send a test email."
|
|
43
|
-
}), this.code = "Mailer/SendTestMail/NotAuthorized";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
class TestMailNotConfigured extends BaseError {
|
|
47
|
-
constructor(){
|
|
48
|
-
super({
|
|
49
|
-
message: "No mail transport is configured, so there is nothing to test."
|
|
50
|
-
}), this.code = "Mailer/SendTestMail/NotConfigured";
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
53
|
class SettingsLockedByCode extends BaseError {
|
|
54
54
|
constructor(){
|
|
55
55
|
super({
|
|
@@ -57,6 +57,16 @@ class SettingsLockedByCode extends BaseError {
|
|
|
57
57
|
}), this.code = "Mailer/Settings/LockedByCode";
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
class UnknownTransportSettings extends BaseError {
|
|
61
|
+
constructor(transport){
|
|
62
|
+
super({
|
|
63
|
+
message: `Mail transport "${transport}" has no settings.`,
|
|
64
|
+
data: {
|
|
65
|
+
transport
|
|
66
|
+
}
|
|
67
|
+
}), this.code = "Mailer/Settings/UnknownTransport";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export { MailValidationError, SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError, TestMailNotAuthorized, TestMailNotConfigured, UnknownTransportSettings };
|
|
61
71
|
|
|
62
72
|
//# sourceMappingURL=errors.js.map
|
package/domain/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { ZodError } from \"zod\";\n\nexport class MailValidationError extends BaseError<{ errors: ZodError[\"issues\"] }> {\n override readonly code = \"Mailer/SendMail/Validation\" as const;\n\n constructor(errors: ZodError[\"issues\"]) {\n super({\n message: \"Email params are invalid.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class
|
|
1
|
+
{"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { ZodError } from \"zod\";\n\nexport class MailValidationError extends BaseError<{ errors: ZodError[\"issues\"] }> {\n override readonly code = \"Mailer/SendMail/Validation\" as const;\n\n constructor(errors: ZodError[\"issues\"]) {\n super({\n message: \"Email params are invalid.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class TestMailNotAuthorized extends BaseError {\n override readonly code = \"Mailer/SendTestMail/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not allowed to send a test email.\" });\n }\n}\n\nexport class TestMailNotConfigured extends BaseError {\n override readonly code = \"Mailer/SendTestMail/NotConfigured\" as const;\n\n constructor() {\n super({\n message: \"No mail transport is configured, so there is nothing to test.\"\n });\n }\n}\n\nexport class SettingsValidationError extends BaseError<{ errors: ZodError[\"issues\"] }> {\n override readonly code = \"Mailer/Settings/Validation\" as const;\n\n constructor(errors: ZodError[\"issues\"]) {\n super({\n message: \"Settings validation failed.\",\n data: {\n errors\n }\n });\n }\n}\n\nexport class SettingsNotAuthorized extends BaseError {\n override readonly code = \"Mailer/Settings/NotAuthorized\" as const;\n\n constructor(message = \"Not allowed to update the mailer settings.\") {\n super({ message });\n }\n}\n\nexport class SettingsPersistenceError extends BaseError<{ error: Error }> {\n override readonly code = \"Mailer/Settings/Persistence\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to persist settings.\",\n data: {\n error\n }\n });\n }\n}\n\nexport class SettingsLockedByCode extends BaseError {\n override readonly code = \"Mailer/Settings/LockedByCode\" as const;\n\n constructor() {\n super({\n message: \"Mailer settings are managed by code and cannot be saved via the API.\"\n });\n }\n}\n\nexport class UnknownTransportSettings extends BaseError<{ transport: string }> {\n override readonly code = \"Mailer/Settings/UnknownTransport\" as const;\n\n constructor(transport: string) {\n super({\n message: `Mail transport \"${transport}\" has no settings.`,\n data: { transport }\n });\n }\n}\n"],"names":["MailValidationError","BaseError","errors","TestMailNotAuthorized","TestMailNotConfigured","SettingsValidationError","SettingsNotAuthorized","message","SettingsPersistenceError","error","SettingsLockedByCode","UnknownTransportSettings","transport"],"mappings":";AAGO,MAAMA,4BAA4BC;IAGrC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,8BAA8BF;IAGvC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAoC,SAHvC,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMG,8BAA8BH;IAGvC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMI,gCAAgCJ;IAGzC,YAAYC,MAA0B,CAAE;QACpC,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMI,8BAA8BL;IAGvC,YAAYM,UAAU,4CAA4C,CAAE;QAChE,KAAK,CAAC;YAAEA;QAAQ,SAHF,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,iCAAiCP;IAG1C,YAAYQ,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAEO,MAAMC,6BAA6BT;IAGtC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMU,iCAAiCV;IAG1C,YAAYW,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,gBAAgB,EAAEA,UAAU,kBAAkB,CAAC;YACzD,MAAM;gBAAEA;YAAU;QACtB,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
package/exports/api/mailer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { SendMailUseCase, MailSendErrorEventHandler, MailBeforeSendEventHandler, MailAfterSendEventHandler } from "../../features/SendMail/index.js";
|
|
2
|
-
export { GetSettingsUseCase, GetSettingsRepository } from "../../features/GetSettings/index.js";
|
|
3
|
-
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "../../features/SaveSettings/index.js";
|
|
4
2
|
export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
|
|
5
3
|
export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
4
|
+
export { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
5
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "../../features/GetSettings/index.js";
|
|
6
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "../../features/SaveSettings/index.js";
|
package/exports/api/mailer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler, SendMailUseCase } from "../../features/SendMail/index.js";
|
|
2
|
-
export { GetSettingsRepository, GetSettingsUseCase } from "../../features/GetSettings/index.js";
|
|
3
|
-
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "../../features/SaveSettings/index.js";
|
|
4
2
|
export { IsMailerConfiguredUseCase } from "../../features/IsMailerConfigured/index.js";
|
|
5
3
|
export { MailTransport, MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
4
|
+
export { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
5
|
+
export { GetSettingsRepository, GetSettingsUseCase } from "../../features/GetSettings/index.js";
|
|
6
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "../../features/SaveSettings/index.js";
|
|
@@ -2,13 +2,14 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
3
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
4
|
import { GetSettingsRepository, type ISettingsWithSource } from "./abstractions.js";
|
|
5
|
-
import {
|
|
5
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
6
|
+
import { UnknownTransportSettings } from "../../domain/errors.js";
|
|
6
7
|
declare class GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {
|
|
7
8
|
private keyValueStore;
|
|
8
9
|
private encryption;
|
|
9
|
-
private
|
|
10
|
-
constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface,
|
|
11
|
-
get(
|
|
10
|
+
private definitions;
|
|
11
|
+
constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface, definitions: TransportSettingsDefinition.Interface[]);
|
|
12
|
+
get<TSettings extends object>(transport: string): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>>;
|
|
12
13
|
}
|
|
13
14
|
export declare const GetSettingsRepositoryImplementation: typeof GetSettingsRepositoryImpl & {
|
|
14
15
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsRepository>;
|
|
@@ -2,43 +2,34 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
3
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
4
|
import { GetSettingsRepository } from "./abstractions.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
6
|
+
import { findDefinition, getStorageKey, withDefaults } from "../../domain/TransportSettings/findDefinition.js";
|
|
7
|
+
import { UnknownTransportSettings } from "../../domain/errors.js";
|
|
7
8
|
class GetSettingsRepositoryImpl {
|
|
8
|
-
constructor(keyValueStore, encryption,
|
|
9
|
+
constructor(keyValueStore, encryption, definitions){
|
|
9
10
|
this.keyValueStore = keyValueStore;
|
|
10
11
|
this.encryption = encryption;
|
|
11
|
-
this.
|
|
12
|
+
this.definitions = definitions;
|
|
12
13
|
}
|
|
13
|
-
async get(
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
14
|
+
async get(transport) {
|
|
15
|
+
const definition = findDefinition(this.definitions, transport);
|
|
16
|
+
if (!definition) return Result.fail(new UnknownTransportSettings(transport));
|
|
17
|
+
const codeSettings = definition.getCodeSettings?.() ?? null;
|
|
18
|
+
if (null !== codeSettings) return Result.ok({
|
|
19
|
+
settings: withDefaults(definition, codeSettings),
|
|
17
20
|
source: "code"
|
|
18
21
|
});
|
|
19
|
-
const result = await this.keyValueStore.get(
|
|
20
|
-
if (result.isFail()) return Result.ok({
|
|
22
|
+
const result = await this.keyValueStore.get(getStorageKey(definition));
|
|
23
|
+
if (result.isFail() || !result.value) return Result.ok({
|
|
21
24
|
settings: null,
|
|
22
25
|
source: null
|
|
23
26
|
});
|
|
24
|
-
const settings =
|
|
25
|
-
|
|
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
|
|
27
|
+
const settings = {
|
|
28
|
+
...result.value
|
|
39
29
|
};
|
|
30
|
+
for (const secret of definition.secrets ?? [])settings[secret] = settings[secret] ? await this.encryption.decrypt(String(settings[secret])) : "";
|
|
40
31
|
return Result.ok({
|
|
41
|
-
settings:
|
|
32
|
+
settings: withDefaults(definition, settings),
|
|
42
33
|
source: "storage"
|
|
43
34
|
});
|
|
44
35
|
}
|
|
@@ -48,7 +39,12 @@ const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplemen
|
|
|
48
39
|
dependencies: [
|
|
49
40
|
KeyValueStore,
|
|
50
41
|
Encryption,
|
|
51
|
-
|
|
42
|
+
[
|
|
43
|
+
TransportSettingsDefinition,
|
|
44
|
+
{
|
|
45
|
+
multiple: true
|
|
46
|
+
}
|
|
47
|
+
]
|
|
52
48
|
]
|
|
53
49
|
});
|
|
54
50
|
export { GetSettingsRepositoryImplementation };
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport {\n findDefinition,\n getStorageKey,\n withDefaults\n} from \"~/domain/TransportSettings/findDefinition.js\";\nimport { UnknownTransportSettings } from \"~/domain/errors.js\";\n\nclass GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface,\n private definitions: TransportSettingsDefinition.Interface[]\n ) {}\n\n async get<TSettings extends object>(\n transport: string\n ): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>> {\n const definition = findDefinition(this.definitions, transport);\n if (!definition) {\n return Result.fail(new UnknownTransportSettings(transport));\n }\n\n // Settings set in code win over stored ones.\n const codeSettings = definition.getCodeSettings?.() ?? null;\n if (codeSettings !== null) {\n return Result.ok({\n settings: withDefaults(definition, codeSettings) as TSettings,\n source: \"code\"\n });\n }\n\n const result = await this.keyValueStore.get<TransportSettingsDefinition.Values>(\n getStorageKey(definition)\n );\n if (result.isFail() || !result.value) {\n return Result.ok({ settings: null, source: null });\n }\n\n const settings = { ...result.value };\n for (const secret of definition.secrets ?? []) {\n settings[secret] = settings[secret]\n ? await this.encryption.decrypt(String(settings[secret]))\n : \"\";\n }\n\n return Result.ok({\n settings: withDefaults(definition, settings) as TSettings,\n source: \"storage\"\n });\n }\n}\n\nexport const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({\n implementation: GetSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption, [TransportSettingsDefinition, { multiple: true }]]\n});\n"],"names":["GetSettingsRepositoryImpl","keyValueStore","encryption","definitions","transport","definition","findDefinition","Result","UnknownTransportSettings","codeSettings","withDefaults","result","getStorageKey","settings","secret","String","GetSettingsRepositoryImplementation","GetSettingsRepository","KeyValueStore","Encryption","TransportSettingsDefinition"],"mappings":";;;;;;;AAYA,MAAMA;IACF,YACYC,aAAsC,EACtCC,UAAgC,EAChCC,WAAoD,CAC9D;aAHUF,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IACFC,SAAiB,EACwD;QACzE,MAAMC,aAAaC,eAAe,IAAI,CAAC,WAAW,EAAEF;QACpD,IAAI,CAACC,YACD,OAAOE,OAAO,IAAI,CAAC,IAAIC,yBAAyBJ;QAIpD,MAAMK,eAAeJ,WAAW,eAAe,QAAQ;QACvD,IAAII,AAAiB,SAAjBA,cACA,OAAOF,OAAO,EAAE,CAAC;YACb,UAAUG,aAAaL,YAAYI;YACnC,QAAQ;QACZ;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvCC,cAAcP;QAElB,IAAIM,OAAO,MAAM,MAAM,CAACA,OAAO,KAAK,EAChC,OAAOJ,OAAO,EAAE,CAAC;YAAE,UAAU;YAAM,QAAQ;QAAK;QAGpD,MAAMM,WAAW;YAAE,GAAGF,OAAO,KAAK;QAAC;QACnC,KAAK,MAAMG,UAAUT,WAAW,OAAO,IAAI,EAAE,CACzCQ,QAAQ,CAACC,OAAO,GAAGD,QAAQ,CAACC,OAAO,GAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACC,OAAOF,QAAQ,CAACC,OAAO,KACrD;QAGV,OAAOP,OAAO,EAAE,CAAC;YACb,UAAUG,aAAaL,YAAYQ;YACnC,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAMG,sCAAsCC,sBAAsB,oBAAoB,CAAC;IAC1F,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;QAAY;YAACC;YAA6B;gBAAE,UAAU;YAAK;SAAE;KAAC;AAChG"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
import { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
4
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
5
|
+
import { SettingsNotAuthorized, UnknownTransportSettings } from "../../domain/errors.js";
|
|
3
6
|
declare class GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {
|
|
7
|
+
private identityContext;
|
|
4
8
|
private repository;
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
private definitions;
|
|
10
|
+
constructor(identityContext: IdentityContext.Interface, repository: GetSettingsRepository.Interface, definitions: TransportSettingsDefinition.Interface[]);
|
|
11
|
+
execute(transport: string): Promise<Result<never, SettingsNotAuthorized> | Result<never, UnknownTransportSettings> | Result<{
|
|
12
|
+
settings: import("~/domain/TransportSettings/abstractions.js").TransportSettingsValues | null;
|
|
13
|
+
source: import("./abstractions.js").MailerSettingsSource;
|
|
14
|
+
}, never>>;
|
|
7
15
|
}
|
|
8
16
|
export declare const GetSettingsUseCaseImplementation: typeof GetSettingsUseCaseImpl & {
|
|
9
17
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsUseCase>;
|
|
@@ -1,16 +1,41 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
1
3
|
import { GetSettingsRepository, GetSettingsUseCase } from "./abstractions.js";
|
|
4
|
+
import { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
5
|
+
import { findDefinition, withoutSecrets } from "../../domain/TransportSettings/findDefinition.js";
|
|
6
|
+
import { SettingsNotAuthorized, UnknownTransportSettings } from "../../domain/errors.js";
|
|
7
|
+
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
2
8
|
class GetSettingsUseCaseImpl {
|
|
3
|
-
constructor(repository){
|
|
9
|
+
constructor(identityContext, repository, definitions){
|
|
10
|
+
this.identityContext = identityContext;
|
|
4
11
|
this.repository = repository;
|
|
12
|
+
this.definitions = definitions;
|
|
5
13
|
}
|
|
6
|
-
execute(
|
|
7
|
-
|
|
14
|
+
async execute(transport) {
|
|
15
|
+
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
16
|
+
if (!permission) return Result.fail(new SettingsNotAuthorized("Not allowed to read the mailer settings."));
|
|
17
|
+
const definition = findDefinition(this.definitions, transport);
|
|
18
|
+
if (!definition) return Result.fail(new UnknownTransportSettings(transport));
|
|
19
|
+
const result = await this.repository.get(transport);
|
|
20
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
21
|
+
const { settings, source } = result.value;
|
|
22
|
+
return Result.ok({
|
|
23
|
+
settings: settings ? withoutSecrets(definition, settings) : null,
|
|
24
|
+
source
|
|
25
|
+
});
|
|
8
26
|
}
|
|
9
27
|
}
|
|
10
28
|
const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({
|
|
11
29
|
implementation: GetSettingsUseCaseImpl,
|
|
12
30
|
dependencies: [
|
|
13
|
-
|
|
31
|
+
IdentityContext,
|
|
32
|
+
GetSettingsRepository,
|
|
33
|
+
[
|
|
34
|
+
TransportSettingsDefinition,
|
|
35
|
+
{
|
|
36
|
+
multiple: true
|
|
37
|
+
}
|
|
38
|
+
]
|
|
14
39
|
]
|
|
15
40
|
});
|
|
16
41
|
export { GetSettingsUseCaseImplementation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/GetSettings/GetSettingsUseCase.js","sources":["../../../src/features/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\
|
|
1
|
+
{"version":3,"file":"features/GetSettings/GetSettingsUseCase.js","sources":["../../../src/features/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { GetSettingsUseCase, GetSettingsRepository } from \"./abstractions.js\";\nimport { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\nimport { findDefinition, withoutSecrets } from \"~/domain/TransportSettings/findDefinition.js\";\nimport { SettingsNotAuthorized, UnknownTransportSettings } from \"~/domain/errors.js\";\nimport { MAILER_SETTINGS_PERMISSION } from \"~/constants.js\";\n\nclass GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private repository: GetSettingsRepository.Interface,\n private definitions: TransportSettingsDefinition.Interface[]\n ) {}\n\n async execute(transport: string) {\n const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);\n if (!permission) {\n return Result.fail(\n new SettingsNotAuthorized(\"Not allowed to read the mailer settings.\")\n );\n }\n\n const definition = findDefinition(this.definitions, transport);\n if (!definition) {\n return Result.fail(new UnknownTransportSettings(transport));\n }\n\n const result = await this.repository.get(transport);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const { settings, source } = result.value;\n return Result.ok({\n settings: settings ? withoutSecrets(definition, settings) : null,\n source\n });\n }\n}\n\nexport const GetSettingsUseCaseImplementation = GetSettingsUseCase.createImplementation({\n implementation: GetSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n GetSettingsRepository,\n [TransportSettingsDefinition, { multiple: true }]\n ]\n});\n"],"names":["GetSettingsUseCaseImpl","identityContext","repository","definitions","transport","permission","MAILER_SETTINGS_PERMISSION","Result","SettingsNotAuthorized","definition","findDefinition","UnknownTransportSettings","result","settings","source","withoutSecrets","GetSettingsUseCaseImplementation","GetSettingsUseCase","IdentityContext","GetSettingsRepository","TransportSettingsDefinition"],"mappings":";;;;;;;AAQA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,UAA2C,EAC3CC,WAAoD,CAC9D;aAHUF,eAAe,GAAfA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,SAAiB,EAAE;QAC7B,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAACC;QAC5D,IAAI,CAACD,YACD,OAAOE,OAAO,IAAI,CACd,IAAIC,sBAAsB;QAIlC,MAAMC,aAAaC,eAAe,IAAI,CAAC,WAAW,EAAEN;QACpD,IAAI,CAACK,YACD,OAAOF,OAAO,IAAI,CAAC,IAAII,yBAAyBP;QAGpD,MAAMQ,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAACR;QACzC,IAAIQ,OAAO,MAAM,IACb,OAAOL,OAAO,IAAI,CAACK,OAAO,KAAK;QAGnC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGF,OAAO,KAAK;QACzC,OAAOL,OAAO,EAAE,CAAC;YACb,UAAUM,WAAWE,eAAeN,YAAYI,YAAY;YAC5DC;QACJ;IACJ;AACJ;AAEO,MAAME,mCAAmCC,mBAAmB,oBAAoB,CAAC;IACpF,gBAAgBjB;IAChB,cAAc;QACVkB;QACAC;QACA;YAACC;YAA6B;gBAAE,UAAU;YAAK;SAAE;KACpD;AACL"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SettingsNotAuthorized, UnknownTransportSettings } from "../../domain/errors.js";
|
|
3
|
+
import type { TransportSettingsDefinition } from "../../domain/TransportSettings/abstractions.js";
|
|
3
4
|
export type MailerSettingsSource = "code" | "storage" | null;
|
|
4
|
-
export interface ISettingsWithSource {
|
|
5
|
-
settings:
|
|
5
|
+
export interface ISettingsWithSource<TSettings extends object = TransportSettingsDefinition.Values> {
|
|
6
|
+
settings: TSettings | null;
|
|
6
7
|
source: MailerSettingsSource;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Reads a transport's settings with its secrets decrypted. For the transport itself (its
|
|
11
|
+
* `MailTransportFactory`); no permission check.
|
|
12
|
+
*/
|
|
8
13
|
export interface IGetSettingsRepository {
|
|
9
|
-
get(
|
|
14
|
+
get<TSettings extends object = TransportSettingsDefinition.Values>(transport: string): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>>;
|
|
10
15
|
}
|
|
11
16
|
export declare const GetSettingsRepository: import("@webiny/di").Abstraction<IGetSettingsRepository>;
|
|
12
17
|
export declare namespace GetSettingsRepository {
|
|
13
18
|
type Interface = IGetSettingsRepository;
|
|
14
|
-
type Return = Promise<Result<ISettingsWithSource>>;
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads a transport's settings for the GraphQL API: requires the `mailer.settings` permission and
|
|
22
|
+
* leaves the secrets out.
|
|
23
|
+
*/
|
|
16
24
|
export interface IGetSettingsUseCase {
|
|
17
|
-
execute(
|
|
25
|
+
execute(transport: string): Promise<Result<ISettingsWithSource, SettingsNotAuthorized | UnknownTransportSettings>>;
|
|
18
26
|
}
|
|
19
27
|
export declare const GetSettingsUseCase: import("@webiny/di").Abstraction<IGetSettingsUseCase>;
|
|
20
28
|
export declare namespace GetSettingsUseCase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/GetSettings/abstractions.js","sources":["../../../src/features/GetSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type {
|
|
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 { SettingsNotAuthorized, UnknownTransportSettings } from \"~/domain/errors.js\";\nimport type { TransportSettingsDefinition } from \"~/domain/TransportSettings/abstractions.js\";\n\nexport type MailerSettingsSource = \"code\" | \"storage\" | null;\n\nexport interface ISettingsWithSource<\n TSettings extends object = TransportSettingsDefinition.Values\n> {\n settings: TSettings | null;\n source: MailerSettingsSource;\n}\n\n/**\n * Reads a transport's settings with its secrets decrypted. For the transport itself (its\n * `MailTransportFactory`); no permission check.\n */\nexport interface IGetSettingsRepository {\n get<TSettings extends object = TransportSettingsDefinition.Values>(\n transport: string\n ): Promise<Result<ISettingsWithSource<TSettings>, UnknownTransportSettings>>;\n}\n\nexport const GetSettingsRepository =\n createAbstraction<IGetSettingsRepository>(\"GetSettingsRepository\");\n\nexport namespace GetSettingsRepository {\n export type Interface = IGetSettingsRepository;\n}\n\n/**\n * Reads a transport's settings for the GraphQL API: requires the `mailer.settings` permission and\n * leaves the secrets out.\n */\nexport interface IGetSettingsUseCase {\n execute(\n transport: string\n ): Promise<Result<ISettingsWithSource, SettingsNotAuthorized | UnknownTransportSettings>>;\n}\n\nexport const GetSettingsUseCase = createAbstraction<IGetSettingsUseCase>(\"GetSettingsUseCase\");\n\nexport namespace GetSettingsUseCase {\n export type Interface = IGetSettingsUseCase;\n}\n"],"names":["GetSettingsRepository","createAbstraction","GetSettingsUseCase"],"mappings":";AAwBO,MAAMA,wBACTC,kBAA0C;AAgBvC,MAAMC,qBAAqBD,kBAAuC"}
|
|
@@ -2,7 +2,7 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetSettingsRepositoryImplementation } from "./GetSettingsRepository.js";
|
|
3
3
|
import { GetSettingsUseCaseImplementation } from "./GetSettingsUseCase.js";
|
|
4
4
|
const GetSettingsFeature = createFeature({
|
|
5
|
-
name: "GetSettings",
|
|
5
|
+
name: "Mailer/GetSettings",
|
|
6
6
|
register (container) {
|
|
7
7
|
container.register(GetSettingsRepositoryImplementation).inSingletonScope();
|
|
8
8
|
container.register(GetSettingsUseCaseImplementation);
|
|
@@ -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"}
|