@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
|
@@ -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,39 +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 { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
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";
|
|
10
9
|
import { MAILER_SETTINGS_PERMISSION } from "../../constants.js";
|
|
11
10
|
class SaveSettingsUseCaseImpl {
|
|
12
|
-
constructor(identityContext, eventPublisher, repository,
|
|
11
|
+
constructor(identityContext, eventPublisher, repository, definitions){
|
|
13
12
|
this.identityContext = identityContext;
|
|
14
13
|
this.eventPublisher = eventPublisher;
|
|
15
14
|
this.repository = repository;
|
|
16
|
-
this.
|
|
17
|
-
this.transportFactories = transportFactories;
|
|
15
|
+
this.definitions = definitions;
|
|
18
16
|
}
|
|
19
|
-
async execute(input) {
|
|
17
|
+
async execute(transport, input) {
|
|
20
18
|
const permission = await this.identityContext.getPermission(MAILER_SETTINGS_PERMISSION);
|
|
21
19
|
if (!permission) return Result.fail(new SettingsNotAuthorized());
|
|
22
|
-
const
|
|
20
|
+
const definition = findDefinition(this.definitions, transport);
|
|
21
|
+
if (!definition) return Result.fail(new UnknownTransportSettings(transport));
|
|
22
|
+
const validationResult = definition.schema.safeParse(input);
|
|
23
23
|
if (!validationResult.success) return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
input:
|
|
29
|
-
});
|
|
30
|
-
await this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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,
|
|
34
37
|
settings: result.value
|
|
35
|
-
});
|
|
36
|
-
await this.eventPublisher.publish(afterSaveEvent);
|
|
38
|
+
}));
|
|
37
39
|
return result;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -43,9 +45,8 @@ const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementati
|
|
|
43
45
|
IdentityContext,
|
|
44
46
|
EventPublisher,
|
|
45
47
|
SaveSettingsRepository,
|
|
46
|
-
CodeMailerSettings,
|
|
47
48
|
[
|
|
48
|
-
|
|
49
|
+
TransportSettingsDefinition,
|
|
49
50
|
{
|
|
50
51
|
multiple: true
|
|
51
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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SaveSettings/feature.js","sources":["../../../src/features/SaveSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SaveSettingsRepositoryImplementation } from \"./SaveSettingsRepository.js\";\nimport { SaveSettingsUseCaseImplementation } from \"./SaveSettingsUseCase.js\";\n\nexport const SaveSettingsFeature = createFeature({\n name: \"SaveSettings\",\n register(container) {\n container.register(SaveSettingsRepositoryImplementation).inSingletonScope();\n container.register(SaveSettingsUseCaseImplementation);\n }\n});\n"],"names":["SaveSettingsFeature","createFeature","container","SaveSettingsRepositoryImplementation","SaveSettingsUseCaseImplementation"],"mappings":";;;AAIO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sCAAsC,gBAAgB;QACzED,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
1
|
+
{"version":3,"file":"features/SaveSettings/feature.js","sources":["../../../src/features/SaveSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SaveSettingsRepositoryImplementation } from \"./SaveSettingsRepository.js\";\nimport { SaveSettingsUseCaseImplementation } from \"./SaveSettingsUseCase.js\";\n\nexport const SaveSettingsFeature = createFeature({\n name: \"Mailer/SaveSettings\",\n register(container) {\n container.register(SaveSettingsRepositoryImplementation).inSingletonScope();\n container.register(SaveSettingsUseCaseImplementation);\n }\n});\n"],"names":["SaveSettingsFeature","createFeature","container","SaveSettingsRepositoryImplementation","SaveSettingsUseCaseImplementation"],"mappings":";;;AAIO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sCAAsC,gBAAgB;QACzED,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
2
|
+
export type { SavedTransportSettings, MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./abstractions.js";
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
2
|
import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
|
|
3
3
|
import { ErrorResponse } from "@webiny/api-graphql/responses.js";
|
|
4
|
+
import { SendTestMailUseCase } from "../features/SendTestMail/abstractions.js";
|
|
4
5
|
import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
|
|
5
6
|
import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
|
|
6
|
-
import { SendTestMailUseCase } from "../features/SendTestMail/abstractions.js";
|
|
7
|
-
import { SMTP_TRANSPORT_NAME } from "../constants.js";
|
|
8
|
-
const toPublicSettings = (settings, source)=>{
|
|
9
|
-
if (!settings) return null;
|
|
10
|
-
const { password: _password, ...publicSettings } = settings;
|
|
11
|
-
return {
|
|
12
|
-
...publicSettings,
|
|
13
|
-
source
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
7
|
class MailerSchemaFactoryImpl {
|
|
17
8
|
async execute(builder) {
|
|
18
9
|
builder.addTypeDefs(`
|
|
@@ -22,48 +13,38 @@ class MailerSchemaFactoryImpl {
|
|
|
22
13
|
data: JSON
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
port: Number
|
|
28
|
-
secure: Boolean
|
|
29
|
-
user: String
|
|
30
|
-
from: String
|
|
31
|
-
replyTo: String
|
|
32
|
-
source: String
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type MailerTransportSettingsResponse {
|
|
36
|
-
data: MailerTransportSettings
|
|
16
|
+
type MailerSendTestMailResponse {
|
|
17
|
+
data: Boolean
|
|
37
18
|
error: MailerTransportSettingsError
|
|
38
19
|
}
|
|
39
20
|
|
|
40
|
-
type
|
|
41
|
-
|
|
21
|
+
type MailerTransportSettingsData {
|
|
22
|
+
transport: String!
|
|
23
|
+
settings: JSON
|
|
24
|
+
source: String
|
|
42
25
|
}
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
secure: Boolean
|
|
48
|
-
user: String!
|
|
49
|
-
password: String
|
|
50
|
-
from: String!
|
|
51
|
-
replyTo: String
|
|
27
|
+
type MailerTransportSettingsDataResponse {
|
|
28
|
+
data: MailerTransportSettingsData
|
|
29
|
+
error: MailerTransportSettingsError
|
|
52
30
|
}
|
|
53
31
|
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
error: MailerTransportSettingsError
|
|
32
|
+
type MailerQuery {
|
|
33
|
+
getTransportSettings(transport: String!): MailerTransportSettingsDataResponse!
|
|
57
34
|
}
|
|
58
35
|
|
|
59
36
|
type MailerMutation {
|
|
60
|
-
saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!
|
|
61
37
|
sendTestMail(to: String!): MailerSendTestMailResponse!
|
|
38
|
+
saveTransportSettings(
|
|
39
|
+
transport: String!
|
|
40
|
+
settings: JSON!
|
|
41
|
+
): MailerTransportSettingsDataResponse!
|
|
62
42
|
}
|
|
63
43
|
|
|
64
44
|
extend type Query {
|
|
65
45
|
mailer: MailerQuery
|
|
66
46
|
}
|
|
47
|
+
|
|
67
48
|
extend type Mutation {
|
|
68
49
|
mailer: MailerMutation
|
|
69
50
|
}
|
|
@@ -77,17 +58,19 @@ class MailerSchemaFactoryImpl {
|
|
|
77
58
|
resolver: ()=>async ()=>({})
|
|
78
59
|
});
|
|
79
60
|
builder.addResolver({
|
|
80
|
-
path: "MailerQuery.
|
|
61
|
+
path: "MailerQuery.getTransportSettings",
|
|
81
62
|
dependencies: [
|
|
82
63
|
GetSettingsUseCase
|
|
83
64
|
],
|
|
84
|
-
resolver: (getSettings)=>async ()=>{
|
|
65
|
+
resolver: (getSettings)=>async ({ args })=>{
|
|
85
66
|
try {
|
|
86
|
-
const result = await getSettings.execute(
|
|
67
|
+
const result = await getSettings.execute(args.transport);
|
|
87
68
|
if (result.isFail()) return new ErrorResponse(result.error);
|
|
88
|
-
const { settings, source } = result.value;
|
|
89
69
|
return {
|
|
90
|
-
data:
|
|
70
|
+
data: {
|
|
71
|
+
transport: args.transport,
|
|
72
|
+
...result.value
|
|
73
|
+
},
|
|
91
74
|
error: null
|
|
92
75
|
};
|
|
93
76
|
} catch (ex) {
|
|
@@ -96,16 +79,20 @@ class MailerSchemaFactoryImpl {
|
|
|
96
79
|
}
|
|
97
80
|
});
|
|
98
81
|
builder.addResolver({
|
|
99
|
-
path: "MailerMutation.
|
|
82
|
+
path: "MailerMutation.saveTransportSettings",
|
|
100
83
|
dependencies: [
|
|
101
84
|
SaveSettingsUseCase
|
|
102
85
|
],
|
|
103
86
|
resolver: (saveSettings)=>async ({ args })=>{
|
|
104
87
|
try {
|
|
105
|
-
const result = await saveSettings.execute(args.
|
|
88
|
+
const result = await saveSettings.execute(args.transport, args.settings);
|
|
106
89
|
if (result.isFail()) return new ErrorResponse(result.error);
|
|
107
90
|
return {
|
|
108
|
-
data:
|
|
91
|
+
data: {
|
|
92
|
+
transport: args.transport,
|
|
93
|
+
settings: result.value,
|
|
94
|
+
source: "storage"
|
|
95
|
+
},
|
|
109
96
|
error: null
|
|
110
97
|
};
|
|
111
98
|
} catch (ex) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/MailerSchemaFactory.js","sources":["../../src/graphql/MailerSchemaFactory.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport type { IGraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ErrorResponse } from \"@webiny/api-graphql/responses.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"graphql/MailerSchemaFactory.js","sources":["../../src/graphql/MailerSchemaFactory.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport type { IGraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ErrorResponse } from \"@webiny/api-graphql/responses.js\";\nimport { SendTestMailUseCase } from \"~/features/SendTestMail/abstractions.js\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\n\n/*\n * The `mailer` namespaces, the test email, and the settings of any transport that registers a\n * `TransportSettingsDefinition`, as JSON. Secrets are never returned.\n */\nclass MailerSchemaFactoryImpl implements GraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-mailer/MailerSchemaFactoryImpl\");\n\n async execute(builder: IGraphQLSchemaBuilder): Promise<IGraphQLSchemaBuilder> {\n builder.addTypeDefs(`\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n\n type MailerSendTestMailResponse {\n data: Boolean\n error: MailerTransportSettingsError\n }\n\n type MailerTransportSettingsData {\n transport: String!\n settings: JSON\n source: String\n }\n\n type MailerTransportSettingsDataResponse {\n data: MailerTransportSettingsData\n error: MailerTransportSettingsError\n }\n\n type MailerQuery {\n getTransportSettings(transport: String!): MailerTransportSettingsDataResponse!\n }\n\n type MailerMutation {\n sendTestMail(to: String!): MailerSendTestMailResponse!\n saveTransportSettings(\n transport: String!\n settings: JSON!\n ): MailerTransportSettingsDataResponse!\n }\n\n extend type Query {\n mailer: MailerQuery\n }\n\n extend type Mutation {\n mailer: MailerMutation\n }\n `);\n\n builder.addResolver({\n path: \"Query.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.mailer\",\n resolver: () => async () => ({})\n });\n\n builder.addResolver<{ transport: string }>({\n path: \"MailerQuery.getTransportSettings\",\n dependencies: [GetSettingsUseCase],\n resolver:\n (getSettings: GetSettingsUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await getSettings.execute(args.transport);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return {\n data: { transport: args.transport, ...result.value },\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ transport: string; settings: Record<string, unknown> }>({\n path: \"MailerMutation.saveTransportSettings\",\n dependencies: [SaveSettingsUseCase],\n resolver:\n (saveSettings: SaveSettingsUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await saveSettings.execute(args.transport, args.settings);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return {\n data: {\n transport: args.transport,\n settings: result.value,\n source: \"storage\"\n },\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n builder.addResolver<{ to: string }>({\n path: \"MailerMutation.sendTestMail\",\n dependencies: [SendTestMailUseCase],\n resolver:\n (sendTestMail: SendTestMailUseCase.Interface) =>\n async ({ args }) => {\n try {\n const result = await sendTestMail.execute({ to: args.to });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return { data: true, error: null };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n });\n\n return builder;\n }\n}\n\nexport const MailerSchemaFactory = GraphQLSchemaFactory.createImplementation({\n implementation: MailerSchemaFactoryImpl,\n dependencies: []\n});\n"],"names":["MailerSchemaFactoryImpl","builder","GetSettingsUseCase","getSettings","args","result","ErrorResponse","ex","SaveSettingsUseCase","saveSettings","SendTestMailUseCase","sendTestMail","staticSchemaKey","MailerSchemaFactory","GraphQLSchemaFactory"],"mappings":";;;;;;AAYA,MAAMA;IAGF,MAAM,QAAQC,OAA8B,EAAkC;QAC1EA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA0CrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IAAM,UAAa,EAAC;QAClC;QAEAA,QAAQ,WAAW,CAAwB;YACvC,MAAM;YACN,cAAc;gBAACC;aAAmB;YAClC,UACI,CAACC,cACD,OAAO,EAAEC,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMF,YAAY,OAAO,CAACC,KAAK,SAAS;wBACvD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAM;gCAAE,WAAWD,KAAK,SAAS;gCAAE,GAAGC,OAAO,KAAK;4BAAC;4BACnD,OAAO;wBACX;oBACJ,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEAN,QAAQ,WAAW,CAA2D;YAC1E,MAAM;YACN,cAAc;gBAACO;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEL,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMI,aAAa,OAAO,CAACL,KAAK,SAAS,EAAEA,KAAK,QAAQ;wBACvE,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAEzC,OAAO;4BACH,MAAM;gCACF,WAAWD,KAAK,SAAS;gCACzB,UAAUC,OAAO,KAAK;gCACtB,QAAQ;4BACZ;4BACA,OAAO;wBACX;oBACJ,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEAN,QAAQ,WAAW,CAAiB;YAChC,MAAM;YACN,cAAc;gBAACS;aAAoB;YACnC,UACI,CAACC,eACD,OAAO,EAAEP,IAAI,EAAE;oBACX,IAAI;wBACA,MAAMC,SAAS,MAAMM,aAAa,OAAO,CAAC;4BAAE,IAAIP,KAAK,EAAE;wBAAC;wBAExD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO;4BAAE,MAAM;4BAAM,OAAO;wBAAK;oBACrC,EAAE,OAAOE,IAAI;wBACT,OAAO,IAAID,cAAcC;oBAC7B;gBACJ;QACR;QAEA,OAAON;IACX;;aA5HO,YAAY,GAAGW,gBAAgB;;AA6H1C;AAEO,MAAMC,sBAAsBC,qBAAqB,oBAAoB,CAAC;IACzE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export { MailerFeature } from "./MailerFeature.js";
|
|
2
2
|
export { MailerService } from "./domain/MailerService/abstractions.js";
|
|
3
3
|
export type { IMailerService, IMailerServiceErrors } from "./domain/MailerService/abstractions.js";
|
|
4
|
+
export { MailTransport } from "./domain/MailTransport/abstractions.js";
|
|
5
|
+
export { MailTransportFactory } from "./domain/MailTransport/abstractions.js";
|
|
6
|
+
export { MAILER_SETTINGS_PERMISSION } from "./constants.js";
|
|
7
|
+
export { isMailboxAddress } from "./utils/isMailboxAddress.js";
|
|
8
|
+
export { TransportSettingsDefinition } from "./domain/TransportSettings/abstractions.js";
|
|
9
|
+
export { SettingsValidationError, SettingsNotAuthorized, SettingsPersistenceError, SettingsLockedByCode, UnknownTransportSettings } from "./domain/errors.js";
|
|
10
|
+
export { GetSettingsUseCase, GetSettingsRepository } from "./features/GetSettings/index.js";
|
|
11
|
+
export type { ISettingsWithSource, MailerSettingsSource } from "./features/GetSettings/index.js";
|
|
12
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./features/SaveSettings/index.js";
|
|
13
|
+
export type { SavedTransportSettings, MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./features/SaveSettings/index.js";
|
package/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export { MailerFeature } from "./MailerFeature.js";
|
|
2
2
|
export { MailerService } from "./domain/MailerService/abstractions.js";
|
|
3
|
+
export { MailTransport, MailTransportFactory } from "./domain/MailTransport/abstractions.js";
|
|
4
|
+
export { MAILER_SETTINGS_PERMISSION } from "./constants.js";
|
|
5
|
+
export { isMailboxAddress } from "./utils/isMailboxAddress.js";
|
|
6
|
+
export { TransportSettingsDefinition } from "./domain/TransportSettings/abstractions.js";
|
|
7
|
+
export { SettingsLockedByCode, SettingsNotAuthorized, SettingsPersistenceError, SettingsValidationError, UnknownTransportSettings } from "./domain/errors.js";
|
|
8
|
+
export { GetSettingsRepository, GetSettingsUseCase } from "./features/GetSettings/index.js";
|
|
9
|
+
export { MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler, SaveSettingsRepository, SaveSettingsUseCase } from "./features/SaveSettings/index.js";
|