@webiny/api-mailer 0.0.0-unstable.e622468070 → 0.0.0-unstable.e6f0dc8ca7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/domain/CodeMailerSettings/abstractions.d.ts +8 -0
- package/domain/CodeMailerSettings/abstractions.js +4 -0
- package/domain/CodeMailerSettings/abstractions.js.map +1 -0
- package/domain/MailTransport/abstractions.d.ts +8 -0
- package/domain/MailTransport/abstractions.js +1 -0
- package/domain/MailTransport/abstractions.js.map +1 -1
- package/domain/errors.d.ts +8 -4
- package/domain/errors.js +8 -0
- package/domain/errors.js.map +1 -1
- package/exports/api/mailer.d.ts +4 -0
- package/exports/api/mailer.js +6 -0
- package/exports/api/mailer.js.map +1 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.d.ts +12 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js +22 -0
- package/features/CodeMailerSettings/CodeMailerSettingsImpl.js.map +1 -0
- package/features/CodeMailerSettings/feature.d.ts +4 -0
- package/features/CodeMailerSettings/feature.js +10 -0
- package/features/CodeMailerSettings/feature.js.map +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.d.ts +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.js +1 -0
- package/features/DummyTransport/DummyMailTransportFactory.js.map +1 -1
- package/features/DummyTransport/feature.d.ts +4 -1
- package/features/GetSettings/GetSettingsRepository.d.ts +6 -5
- package/features/GetSettings/GetSettingsRepository.js +29 -10
- package/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/features/GetSettings/GetSettingsUseCase.d.ts +3 -4
- package/features/GetSettings/GetSettingsUseCase.js +2 -2
- package/features/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/GetSettings/abstractions.d.ts +11 -5
- package/features/GetSettings/abstractions.js.map +1 -1
- package/features/GetSettings/feature.d.ts +4 -1
- package/features/GetSettings/index.d.ts +1 -1
- package/features/GetSettings/index.js +1 -1
- package/features/GetSettings/index.js.map +1 -1
- package/features/MailerService/ActiveTransport.d.ts +10 -0
- package/features/MailerService/ActiveTransport.js +20 -0
- package/features/MailerService/ActiveTransport.js.map +1 -0
- package/features/MailerService/MailerService.d.ts +3 -2
- package/features/MailerService/MailerService.js +16 -15
- package/features/MailerService/MailerService.js.map +1 -1
- package/features/MailerService/feature.d.ts +4 -1
- package/features/MailerService/feature.js +2 -0
- package/features/MailerService/feature.js.map +1 -1
- package/features/SaveSettings/SaveSettingsRepository.d.ts +1 -1
- package/features/SaveSettings/SaveSettingsRepository.js +12 -10
- package/features/SaveSettings/SaveSettingsRepository.js.map +1 -1
- package/features/SaveSettings/SaveSettingsUseCase.d.ts +6 -2
- package/features/SaveSettings/SaveSettingsUseCase.js +28 -10
- package/features/SaveSettings/SaveSettingsUseCase.js.map +1 -1
- package/features/SaveSettings/abstractions.d.ts +20 -12
- package/features/SaveSettings/abstractions.js +12 -3
- package/features/SaveSettings/abstractions.js.map +1 -1
- package/features/SaveSettings/events.d.ts +3 -3
- package/features/SaveSettings/events.js +4 -4
- package/features/SaveSettings/events.js.map +1 -1
- package/features/SaveSettings/feature.d.ts +4 -1
- package/features/SaveSettings/index.d.ts +1 -1
- package/features/SaveSettings/index.js +1 -1
- package/features/SaveSettings/index.js.map +1 -1
- package/features/SaveSettings/validation.d.ts +3 -17
- package/features/SaveSettings/validation.js +7 -3
- package/features/SaveSettings/validation.js.map +1 -1
- package/features/SendMail/SendMailUseCase.d.ts +1 -1
- package/features/SendMail/SendMailUseCase.js +11 -8
- package/features/SendMail/SendMailUseCase.js.map +1 -1
- package/features/SendMail/abstractions.d.ts +7 -7
- package/features/SendMail/abstractions.js +3 -3
- package/features/SendMail/abstractions.js.map +1 -1
- package/features/SendMail/events.d.ts +4 -4
- package/features/SendMail/events.js +5 -5
- package/features/SendMail/events.js.map +1 -1
- package/features/SendMail/feature.d.ts +4 -1
- package/features/SendMail/index.d.ts +1 -0
- package/features/SendMail/index.js +3 -0
- package/features/SendMail/index.js.map +1 -0
- package/features/SmtpTransport/SmtpMailTransport.d.ts +51 -1
- package/features/SmtpTransport/SmtpMailTransport.js +7 -1
- package/features/SmtpTransport/SmtpMailTransport.js.map +1 -1
- package/features/SmtpTransport/SmtpMailTransportFactory.d.ts +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js +1 -0
- package/features/SmtpTransport/SmtpMailTransportFactory.js.map +1 -1
- package/features/SmtpTransport/feature.d.ts +4 -1
- package/graphql/settings.js +44 -32
- package/graphql/settings.js.map +1 -1
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/package.json +26 -31
- package/utils/isMailboxAddress.d.ts +6 -0
- package/utils/isMailboxAddress.js +12 -0
- package/utils/isMailboxAddress.js.map +1 -0
- package/domain/Encryption/abstractions.d.ts +0 -8
- package/domain/Encryption/abstractions.js +0 -4
- package/domain/Encryption/abstractions.js.map +0 -1
- package/features/Encryption/PasswordEncryption.d.ts +0 -9
- package/features/Encryption/PasswordEncryption.js +0 -23
- package/features/Encryption/PasswordEncryption.js.map +0 -1
- package/features/Encryption/feature.d.ts +0 -1
- package/features/Encryption/feature.js +0 -10
- package/features/Encryption/feature.js.map +0 -1
- package/features/Encryption/utils/password.d.ts +0 -7
- package/features/Encryption/utils/password.js +0 -56
- package/features/Encryption/utils/password.js.map +0 -1
- package/features/Encryption/utils/secret.d.ts +0 -1
- package/features/Encryption/utils/secret.js +0 -11
- package/features/Encryption/utils/secret.js.map +0 -1
- package/features/MailerService/TransportFactory.d.ts +0 -2
- package/features/MailerService/TransportFactory.js +0 -31
- package/features/MailerService/TransportFactory.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","MailerService","Abstraction","NoTransportAvailableError","NoSettingsConfiguredError","TransportSendError","
|
|
1
|
+
{"version":3,"names":["Result","MailerService","Abstraction","NoTransportAvailableError","NoSettingsConfiguredError","TransportSendError","ActiveTransport","MailTransportFactory","GetSettingsRepository","MailerServiceImpl","constructor","getSettingsRepository","activeTransport","transportFactories","sendMail","data","transportName","name","fail","result","get","settings","value","transport","getTransport","response","send","error","ok","factory","find","f","createTransport","createImplementation","implementation","dependencies","multiple"],"sources":["MailerService.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { MailerService as Abstraction } from \"~/domain/MailerService/abstractions.js\";\nimport {\n NoTransportAvailableError,\n NoSettingsConfiguredError,\n TransportSendError\n} from \"~/domain/MailerService/errors.js\";\nimport {\n ActiveTransport,\n MailTransport,\n MailTransportFactory\n} from \"~/domain/MailTransport/abstractions.js\";\nimport { GetSettingsRepository } from \"../GetSettings/abstractions.js\";\nimport type { TransportSettings, TransportSendData } from \"~/types.js\";\n\nclass MailerServiceImpl implements Abstraction.Interface {\n constructor(\n private getSettingsRepository: GetSettingsRepository.Interface,\n private activeTransport: ActiveTransport.Interface,\n private transportFactories: MailTransportFactory.Interface[]\n ) {}\n\n async sendMail<T = any>(data: TransportSendData): Abstraction.Return<T> {\n const transportName = this.activeTransport.name();\n\n if (!transportName) {\n return Result.fail(new NoTransportAvailableError());\n }\n\n const result = await this.getSettingsRepository.get(transportName);\n const { settings } = result.value;\n\n if (!settings) {\n return Result.fail(new NoSettingsConfiguredError());\n }\n\n const transport = await this.getTransport(transportName, settings);\n\n if (!transport) {\n return Result.fail(new NoTransportAvailableError());\n }\n\n try {\n const response = await transport.send(data);\n\n if (response.error) {\n return Result.fail(new TransportSendError(response.error));\n }\n\n return Result.ok(response);\n } catch (error) {\n return Result.fail(new TransportSendError(error));\n }\n }\n\n private async getTransport(\n transportName: string,\n settings: TransportSettings\n ): Promise<MailTransport.Interface | null> {\n const factory = this.transportFactories.find(f => f.name === transportName);\n if (!factory) {\n return null;\n }\n return factory.createTransport(settings);\n }\n}\n\nexport const MailerService = Abstraction.createImplementation({\n implementation: MailerServiceImpl,\n dependencies: [\n GetSettingsRepository,\n ActiveTransport,\n [MailTransportFactory, { multiple: true }]\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;A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AC;MAC9D;MAEA,OAAO3B,MAAM,CAAC4B,EAAE,CAACH,QAAQ,CAAC;IAC9B,CAAC,CAAC,OAAOE,KAAK,EAAE;MACZ,OAAO3B,MAAM,CAACkB,IAAI,CAAC,IAAIb,kBAAkB,CAACsB,KAAK,CAAC,CAAC;IACrD;EACJ;EAEA,MAAcH,YAAYA,CACtBR,aAAqB,EACrBK,QAA2B,EACY;IACvC,MAAMQ,OAAO,GAAG,IAAI,CAAChB,kBAAkB,CAACiB,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACd,IAAI,KAAKD,aAAa,CAAC;IAC3E,IAAI,CAACa,OAAO,EAAE;MACV,OAAO,IAAI;IACf;IACA,OAAOA,OAAO,CAACG,eAAe,CAACX,QAAQ,CAAC;EAC5C;AACJ;AAEA,OAAO,MAAMpB,aAAa,GAAGC,WAAW,CAAC+B,oBAAoB,CAAC;EAC1DC,cAAc,EAAEzB,iBAAiB;EACjC0B,YAAY,EAAE,CACV3B,qBAAqB,EACrBF,eAAe,EACf,CAACC,oBAAoB,EAAE;IAAE6B,QAAQ,EAAE;EAAK,CAAC,CAAC;AAElD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { MailerService } from "./MailerService.js";
|
|
3
|
+
import { ActiveTransport } from "./ActiveTransport.js";
|
|
3
4
|
export const MailerServiceFeature = createFeature({
|
|
4
5
|
name: "Mailer/MailerService",
|
|
5
6
|
register(container) {
|
|
7
|
+
container.register(ActiveTransport).inSingletonScope();
|
|
6
8
|
container.register(MailerService).inSingletonScope();
|
|
7
9
|
}
|
|
8
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","MailerService","MailerServiceFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerService } from \"./MailerService.js\";\n\nexport const MailerServiceFeature = createFeature({\n name: \"Mailer/MailerService\",\n register(container) {\n container.register(MailerService).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,aAAa;
|
|
1
|
+
{"version":3,"names":["createFeature","MailerService","ActiveTransport","MailerServiceFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MailerService } from \"./MailerService.js\";\nimport { ActiveTransport } from \"./ActiveTransport.js\";\n\nexport const MailerServiceFeature = createFeature({\n name: \"Mailer/MailerService\",\n register(container) {\n container.register(ActiveTransport).inSingletonScope();\n container.register(MailerService).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,aAAa;AACtB,SAASC,eAAe;AAExB,OAAO,MAAMC,oBAAoB,GAAGH,aAAa,CAAC;EAC9CI,IAAI,EAAE,sBAAsB;EAC5BC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,eAAe,CAAC,CAACK,gBAAgB,CAAC,CAAC;IACtDD,SAAS,CAACD,QAAQ,CAACJ,aAAa,CAAC,CAACM,gBAAgB,CAAC,CAAC;EACxD;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Encryption } from "
|
|
1
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
2
2
|
import { SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
3
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
4
4
|
declare class SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { Encryption } from "
|
|
2
|
+
import { Encryption } from "@webiny/api-core/features/encryption/index.js";
|
|
3
3
|
import { SaveSettingsRepository } from "./abstractions.js";
|
|
4
4
|
import { SettingsPersistenceError } from "../../domain/errors.js";
|
|
5
5
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
@@ -19,11 +19,11 @@ class SaveSettingsRepositoryImpl {
|
|
|
19
19
|
// If updating and no password provided, keep the existing password
|
|
20
20
|
let passwordToStore = input.password || "";
|
|
21
21
|
if (!input.password && existingSettings) {
|
|
22
|
-
passwordToStore =
|
|
22
|
+
passwordToStore = this.encryption.decrypt(transportSettings.password || "");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Encrypt password
|
|
26
|
-
const encryptedPassword =
|
|
26
|
+
const encryptedPassword = this.encryption.encrypt(passwordToStore);
|
|
27
27
|
|
|
28
28
|
// Prepare data
|
|
29
29
|
const data = {
|
|
@@ -35,18 +35,20 @@ class SaveSettingsRepositoryImpl {
|
|
|
35
35
|
replyTo: input.replyTo ?? transportSettings.replyTo
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
// Save settings
|
|
38
|
+
// Save settings.
|
|
39
39
|
const result = await this.keyValueStore.set(MAILER_TRANSPORT_SETTINGS, data);
|
|
40
40
|
if (result.isFail()) {
|
|
41
41
|
return Result.fail(new SettingsPersistenceError(result.error));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// Return without
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
// Return the stored state without the password. Callers that need the
|
|
45
|
+
// plaintext password go through GetSettingsRepository.get(transportName).
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
+
const {
|
|
48
|
+
password: _password,
|
|
49
|
+
...savedSettings
|
|
50
|
+
} = data;
|
|
51
|
+
return Result.ok(savedSettings);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
export const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","Encryption","SaveSettingsRepository","SettingsPersistenceError","KeyValueStore","MAILER_TRANSPORT_SETTINGS","DEFAULT_PORT","SaveSettingsRepositoryImpl","constructor","keyValueStore","encryption","execute","input","existingResult","get","existingSettings","isOk","value","transportSettings","passwordToStore","password","decrypt","encryptedPassword","encrypt","data","host","port","user","from","replyTo","result","set","isFail","fail","error","
|
|
1
|
+
{"version":3,"names":["Result","Encryption","SaveSettingsRepository","SettingsPersistenceError","KeyValueStore","MAILER_TRANSPORT_SETTINGS","DEFAULT_PORT","SaveSettingsRepositoryImpl","constructor","keyValueStore","encryption","execute","input","existingResult","get","existingSettings","isOk","value","transportSettings","passwordToStore","password","decrypt","encryptedPassword","encrypt","data","host","port","user","from","replyTo","result","set","isFail","fail","error","_password","savedSettings","ok","SaveSettingsRepositoryImplementation","createImplementation","implementation","dependencies"],"sources":["SaveSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { Encryption } from \"@webiny/api-core/features/encryption/index.js\";\nimport { SaveSettingsRepository, type SaveSettingsInput } from \"./abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SettingsPersistenceError } from \"~/domain/errors.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { MAILER_TRANSPORT_SETTINGS } from \"~/constants.js\";\n\nconst DEFAULT_PORT = 25;\n\nclass SaveSettingsRepositoryImpl implements SaveSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsRepository.Return {\n // Check if settings exist\n const existingResult =\n await this.keyValueStore.get<TransportSettings>(MAILER_TRANSPORT_SETTINGS);\n const existingSettings = existingResult.isOk() ? existingResult.value : null;\n const transportSettings: Partial<TransportSettings> = existingSettings ?? {};\n\n // If updating and no password provided, keep the existing password\n let passwordToStore = input.password || \"\";\n if (!input.password && existingSettings) {\n passwordToStore = this.encryption.decrypt(transportSettings.password || \"\");\n }\n\n // Encrypt password\n const encryptedPassword = this.encryption.encrypt(passwordToStore);\n\n // Prepare data\n const data = {\n host: input.host ?? transportSettings.host,\n port: input.port ?? transportSettings.port ?? DEFAULT_PORT,\n user: input.user ?? transportSettings.user,\n password: encryptedPassword,\n from: input.from ?? transportSettings.from,\n replyTo: input.replyTo ?? transportSettings.replyTo\n };\n\n // Save settings.\n const result = await this.keyValueStore.set(MAILER_TRANSPORT_SETTINGS, data);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n // Return the stored state without the password. Callers that need the\n // plaintext password go through GetSettingsRepository.get(transportName).\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _password, ...savedSettings } = data as TransportSettings;\n return Result.ok(savedSettings);\n }\n}\n\nexport const SaveSettingsRepositoryImplementation = SaveSettingsRepository.createImplementation({\n implementation: SaveSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,UAAU,QAAQ,+CAA+C;AAC1E,SAASC,sBAAsB;AAE/B,SAASC,wBAAwB;AACjC,SAASC,aAAa,QAAQ,kDAAkD;AAChF,SAASC,yBAAyB;AAElC,MAAMC,YAAY,GAAG,EAAE;AAEvB,MAAMC,0BAA0B,CAA6C;EACzEC,WAAWA,CACCC,aAAsC,EACtCC,UAAgC,EAC1C;IAAA,KAFUD,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,UAAgC,GAAhCA,UAAgC;EACzC;EAEH,MAAMC,OAAOA,CAACC,KAAwB,EAAiC;IACnE;IACA,MAAMC,cAAc,GAChB,MAAM,IAAI,CAACJ,aAAa,CAACK,GAAG,CAAoBT,yBAAyB,CAAC;IAC9E,MAAMU,gBAAgB,GAAGF,cAAc,CAACG,IAAI,CAAC,CAAC,GAAGH,cAAc,CAACI,KAAK,GAAG,IAAI;IAC5E,MAAMC,iBAA6C,GAAGH,gBAAgB,IAAI,CAAC,CAAC;;IAE5E;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C,0BAA0B;EAC1CkC,YAAY,EAAE,CAACrC,aAAa,EAAEH,UAAU;AAC5C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/
|
|
1
|
+
import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
2
|
import { SaveSettingsUseCase, SaveSettingsRepository, type SaveSettingsInput } from "./abstractions.js";
|
|
3
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
5
|
+
import { ActiveTransport } from "../../domain/MailTransport/abstractions.js";
|
|
4
6
|
declare class SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {
|
|
5
7
|
private identityContext;
|
|
6
8
|
private eventPublisher;
|
|
7
9
|
private repository;
|
|
8
|
-
|
|
10
|
+
private codeSettings;
|
|
11
|
+
private activeTransport;
|
|
12
|
+
constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisherAbstraction.Interface, repository: SaveSettingsRepository.Interface, codeSettings: CodeMailerSettings.Interface, activeTransport: ActiveTransport.Interface);
|
|
9
13
|
execute(input: SaveSettingsInput): SaveSettingsUseCase.Return;
|
|
10
14
|
}
|
|
11
15
|
export declare const SaveSettingsUseCaseImplementation: typeof SaveSettingsUseCaseImpl & {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { EventPublisher } from "@webiny/api-core/features/
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { SaveSettingsUseCase, SaveSettingsRepository } from "./abstractions.js";
|
|
4
4
|
import { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from "./events.js";
|
|
5
5
|
import { saveValidation } from "./validation.js";
|
|
6
|
-
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized } from "../../domain/errors.js";
|
|
6
|
+
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized, SettingsLockedByCode } from "../../domain/errors.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
|
+
import { CodeMailerSettings } from "../../domain/CodeMailerSettings/abstractions.js";
|
|
9
|
+
import { ActiveTransport } from "../../domain/MailTransport/abstractions.js";
|
|
8
10
|
class SaveSettingsUseCaseImpl {
|
|
9
|
-
constructor(identityContext, eventPublisher, repository) {
|
|
11
|
+
constructor(identityContext, eventPublisher, repository, codeSettings, activeTransport) {
|
|
10
12
|
this.identityContext = identityContext;
|
|
11
13
|
this.eventPublisher = eventPublisher;
|
|
12
14
|
this.repository = repository;
|
|
15
|
+
this.codeSettings = codeSettings;
|
|
16
|
+
this.activeTransport = activeTransport;
|
|
13
17
|
}
|
|
14
18
|
async execute(input) {
|
|
15
19
|
const permission = await this.identityContext.getPermission("mailer.settings");
|
|
@@ -17,25 +21,39 @@ class SaveSettingsUseCaseImpl {
|
|
|
17
21
|
return Result.fail(new SettingsNotAuthorized());
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
// Validate input
|
|
24
|
+
// Validate input.
|
|
21
25
|
const validationResult = saveValidation.safeParse(input);
|
|
22
26
|
if (!validationResult.success) {
|
|
23
|
-
return Result.fail(new SettingsValidationError(validationResult.error.
|
|
27
|
+
return Result.fail(new SettingsValidationError(validationResult.error.issues));
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
//
|
|
30
|
+
// Refuse when settings are defined via code.
|
|
31
|
+
const transportName = this.activeTransport.name();
|
|
32
|
+
if (transportName && this.codeSettings.get(transportName) !== null) {
|
|
33
|
+
return Result.fail(new SettingsLockedByCode());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Publish before save event. Strip the password — subscribers (audit
|
|
37
|
+
// logs, telemetry) must never see the plaintext value from the input.
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
const {
|
|
40
|
+
password: _beforePassword,
|
|
41
|
+
...inputForEvent
|
|
42
|
+
} = input;
|
|
27
43
|
const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({
|
|
28
|
-
input
|
|
44
|
+
input: inputForEvent
|
|
29
45
|
});
|
|
30
46
|
await this.eventPublisher.publish(beforeSaveEvent);
|
|
31
47
|
|
|
32
|
-
// Save settings
|
|
48
|
+
// Save settings.
|
|
33
49
|
const result = await this.repository.execute(input);
|
|
34
50
|
if (result.isFail()) {
|
|
35
51
|
return Result.fail(new SettingsPersistenceError(result.error));
|
|
36
52
|
}
|
|
37
53
|
|
|
38
|
-
// Publish after save event
|
|
54
|
+
// Publish after save event. The repository return is already password-free
|
|
55
|
+
// (its type is Omit<TransportSettings, "password">), so no runtime strip
|
|
56
|
+
// is needed here.
|
|
39
57
|
const afterSaveEvent = new MailerSettingsAfterSaveEvent({
|
|
40
58
|
settings: result.value
|
|
41
59
|
});
|
|
@@ -45,7 +63,7 @@ class SaveSettingsUseCaseImpl {
|
|
|
45
63
|
}
|
|
46
64
|
export const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({
|
|
47
65
|
implementation: SaveSettingsUseCaseImpl,
|
|
48
|
-
dependencies: [IdentityContext, EventPublisher, SaveSettingsRepository]
|
|
66
|
+
dependencies: [IdentityContext, EventPublisher, SaveSettingsRepository, CodeMailerSettings, ActiveTransport]
|
|
49
67
|
});
|
|
50
68
|
|
|
51
69
|
//# sourceMappingURL=SaveSettingsUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","EventPublisher","SaveSettingsUseCase","SaveSettingsRepository","MailerSettingsBeforeSaveEvent","MailerSettingsAfterSaveEvent","saveValidation","SettingsValidationError","SettingsPersistenceError","SettingsNotAuthorized","IdentityContext","SaveSettingsUseCaseImpl","constructor","identityContext","eventPublisher","repository","execute","input","permission","getPermission","fail","validationResult","safeParse","success","error","
|
|
1
|
+
{"version":3,"names":["Result","EventPublisher","SaveSettingsUseCase","SaveSettingsRepository","MailerSettingsBeforeSaveEvent","MailerSettingsAfterSaveEvent","saveValidation","SettingsValidationError","SettingsPersistenceError","SettingsNotAuthorized","SettingsLockedByCode","IdentityContext","CodeMailerSettings","ActiveTransport","SaveSettingsUseCaseImpl","constructor","identityContext","eventPublisher","repository","codeSettings","activeTransport","execute","input","permission","getPermission","fail","validationResult","safeParse","success","error","issues","transportName","name","get","password","_beforePassword","inputForEvent","beforeSaveEvent","publish","result","isFail","afterSaveEvent","settings","value","SaveSettingsUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["SaveSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n type SaveSettingsInput\n} from \"./abstractions.js\";\nimport { MailerSettingsBeforeSaveEvent, MailerSettingsAfterSaveEvent } from \"./events.js\";\nimport { saveValidation } from \"./validation.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CodeMailerSettings } from \"~/domain/CodeMailerSettings/abstractions.js\";\nimport { ActiveTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nclass SaveSettingsUseCaseImpl implements SaveSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisherAbstraction.Interface,\n private repository: SaveSettingsRepository.Interface,\n private codeSettings: CodeMailerSettings.Interface,\n private activeTransport: ActiveTransport.Interface\n ) {}\n\n async execute(input: SaveSettingsInput): SaveSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(\"mailer.settings\");\n\n if (!permission) {\n return Result.fail(new SettingsNotAuthorized());\n }\n\n // Validate input.\n const validationResult = saveValidation.safeParse(input);\n if (!validationResult.success) {\n return Result.fail(new SettingsValidationError(validationResult.error.issues));\n }\n\n // Refuse when settings are defined via code.\n const transportName = this.activeTransport.name();\n if (transportName && this.codeSettings.get(transportName) !== null) {\n return Result.fail(new SettingsLockedByCode());\n }\n\n // Publish before save event. Strip the password — subscribers (audit\n // logs, telemetry) must never see the plaintext value from the input.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _beforePassword, ...inputForEvent } = input;\n const beforeSaveEvent = new MailerSettingsBeforeSaveEvent({ input: inputForEvent });\n await this.eventPublisher.publish(beforeSaveEvent);\n\n // Save settings.\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return Result.fail(new SettingsPersistenceError(result.error));\n }\n\n // Publish after save event. The repository return is already password-free\n // (its type is Omit<TransportSettings, \"password\">), so no runtime strip\n // is needed here.\n const afterSaveEvent = new MailerSettingsAfterSaveEvent({ settings: result.value });\n await this.eventPublisher.publish(afterSaveEvent);\n\n return result;\n }\n}\n\nexport const SaveSettingsUseCaseImplementation = SaveSettingsUseCase.createImplementation({\n implementation: SaveSettingsUseCaseImpl,\n dependencies: [\n IdentityContext,\n EventPublisher,\n SaveSettingsRepository,\n CodeMailerSettings,\n ActiveTransport\n ]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,cAAc,QAEX,mDAAmD;AAC1D,SACIC,mBAAmB,EACnBC,sBAAsB;AAG1B,SAASC,6BAA6B,EAAEC,4BAA4B;AACpE,SAASC,cAAc;AACvB,SACIC,uBAAuB,EACvBC,wBAAwB,EACxBC,qBAAqB,EACrBC,oBAAoB;AAExB,SAASC,eAAe,QAAQ,6DAA6D;AAC7F,SAASC,kBAAkB;AAC3B,SAASC,eAAe;AAExB,MAAMC,uBAAuB,CAA0C;EACnEC,WAAWA,CACCC,eAA0C,EAC1CC,cAAmD,EACnDC,UAA4C,EAC5CC,YAA0C,EAC1C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,CAACC,KAAK,CAAC;IAEnD,IAAIiB,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOxC,MAAM,CAACyB,IAAI,CAAC,IAAIjB,wBAAwB,CAAC+B,MAAM,CAACV,KAAK,CAAC,CAAC;IAClE;;IAEA;IACA;IACA;IACA,MAAMY,cAAc,GAAG,IAAIpC,4BAA4B,CAAC;MAAEqC,QAAQ,EAAEH,MAAM,CAACI;IAAM,CAAC,CAAC;IACnF,MAAM,IAAI,CAAC1B,cAAc,CAACqB,OAAO,CAACG,cAAc,CAAC;IAEjD,OAAOF,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMK,iCAAiC,GAAG1C,mBAAmB,CAAC2C,oBAAoB,CAAC;EACtFC,cAAc,EAAEhC,uBAAuB;EACvCiC,YAAY,EAAE,CACVpC,eAAe,EACfV,cAAc,EACdE,sBAAsB,EACtBS,kBAAkB,EAClBC,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/
|
|
2
|
+
import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import type { TransportSettings } from "../../types.js";
|
|
4
|
-
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized } from "../../domain/errors.js";
|
|
4
|
+
import { SettingsValidationError, SettingsPersistenceError, SettingsNotAuthorized, SettingsLockedByCode } from "../../domain/errors.js";
|
|
5
5
|
export interface SaveSettingsInput {
|
|
6
6
|
host: string;
|
|
7
7
|
port?: number;
|
|
@@ -14,39 +14,47 @@ export interface ISaveSettingsErrors {
|
|
|
14
14
|
validation: SettingsValidationError;
|
|
15
15
|
persistence: SettingsPersistenceError;
|
|
16
16
|
notAuthorized: SettingsNotAuthorized;
|
|
17
|
+
lockedByCode: SettingsLockedByCode;
|
|
17
18
|
}
|
|
18
19
|
type SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];
|
|
20
|
+
/**
|
|
21
|
+
* Save-side returns are password-free. The only path that exposes the password
|
|
22
|
+
* to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute
|
|
23
|
+
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
24
|
+
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
25
|
+
*/
|
|
26
|
+
export type SavedTransportSettings = Omit<TransportSettings, "password">;
|
|
19
27
|
export interface ISaveSettingsRepository {
|
|
20
|
-
execute(input: SaveSettingsInput): Promise<Result<
|
|
28
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
21
29
|
}
|
|
22
30
|
export declare const SaveSettingsRepository: import("@webiny/di").Abstraction<ISaveSettingsRepository>;
|
|
23
31
|
export declare namespace SaveSettingsRepository {
|
|
24
32
|
type Interface = ISaveSettingsRepository;
|
|
25
|
-
type Return = Promise<Result<
|
|
33
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
26
34
|
type Error = SaveSettingsError;
|
|
27
35
|
}
|
|
28
36
|
export interface ISaveSettings {
|
|
29
|
-
execute(input: SaveSettingsInput): Promise<Result<
|
|
37
|
+
execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
30
38
|
}
|
|
31
39
|
export declare const SaveSettingsUseCase: import("@webiny/di").Abstraction<ISaveSettings>;
|
|
32
40
|
export declare namespace SaveSettingsUseCase {
|
|
33
41
|
type Interface = ISaveSettings;
|
|
34
|
-
type Return = Promise<Result<
|
|
42
|
+
type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;
|
|
35
43
|
type Error = SaveSettingsError;
|
|
36
44
|
}
|
|
37
45
|
export interface MailerSettingsBeforeSavePayload {
|
|
38
|
-
input: SaveSettingsInput
|
|
46
|
+
input: Omit<SaveSettingsInput, "password">;
|
|
39
47
|
}
|
|
40
48
|
export interface MailerSettingsAfterSavePayload {
|
|
41
|
-
settings: TransportSettings
|
|
49
|
+
settings: Omit<TransportSettings, "password">;
|
|
42
50
|
}
|
|
43
|
-
export declare const
|
|
44
|
-
export declare namespace
|
|
51
|
+
export declare const MailerSettingsBeforeSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
52
|
+
export declare namespace MailerSettingsBeforeSaveEventHandler {
|
|
45
53
|
type Interface = IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>;
|
|
46
54
|
type Event = DomainEvent<MailerSettingsBeforeSavePayload>;
|
|
47
55
|
}
|
|
48
|
-
export declare const
|
|
49
|
-
export declare namespace
|
|
56
|
+
export declare const MailerSettingsAfterSaveEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>>;
|
|
57
|
+
export declare namespace MailerSettingsAfterSaveEventHandler {
|
|
50
58
|
type Interface = IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>;
|
|
51
59
|
type Event = DomainEvent<MailerSettingsAfterSavePayload>;
|
|
52
60
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Save-side returns are password-free. The only path that exposes the password
|
|
5
|
+
* to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute
|
|
6
|
+
* (used by MailerService to authenticate SMTP). Everything else — events,
|
|
7
|
+
* GraphQL responses, logs, audit trails — must use this Omit shape.
|
|
8
|
+
*/
|
|
9
|
+
|
|
2
10
|
export const SaveSettingsRepository = createAbstraction("SaveSettingsRepository");
|
|
3
11
|
export const SaveSettingsUseCase = createAbstraction("SaveSettingsUseCase");
|
|
4
12
|
|
|
5
|
-
// Domain Events
|
|
13
|
+
// Domain Events. Both payloads exclude `password` so subscribers (audit logs,
|
|
14
|
+
// telemetry, etc.) cannot accidentally persist plaintext or ciphertext secrets.
|
|
6
15
|
|
|
7
16
|
// Event Handler Abstractions
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
17
|
+
export const MailerSettingsBeforeSaveEventHandler = createAbstraction("MailerSettingsBeforeSaveEventHandler");
|
|
18
|
+
export const MailerSettingsAfterSaveEventHandler = createAbstraction("MailerSettingsAfterSaveEventHandler");
|
|
10
19
|
|
|
11
20
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","SaveSettingsRepository","SaveSettingsUseCase","
|
|
1
|
+
{"version":3,"names":["createAbstraction","SaveSettingsRepository","SaveSettingsUseCase","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEventHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport {\n SettingsValidationError,\n SettingsPersistenceError,\n SettingsNotAuthorized,\n SettingsLockedByCode\n} from \"~/domain/errors.js\";\n\nexport interface SaveSettingsInput {\n host: string;\n port?: number;\n user: string;\n password?: string;\n from: string;\n replyTo?: string;\n}\n\nexport interface ISaveSettingsErrors {\n validation: SettingsValidationError;\n persistence: SettingsPersistenceError;\n notAuthorized: SettingsNotAuthorized;\n lockedByCode: SettingsLockedByCode;\n}\n\ntype SaveSettingsError = ISaveSettingsErrors[keyof ISaveSettingsErrors];\n\n/**\n * Save-side returns are password-free. The only path that exposes the password\n * to in-process callers is GetSettingsRepository.get / GetSettingsUseCase.execute\n * (used by MailerService to authenticate SMTP). Everything else — events,\n * GraphQL responses, logs, audit trails — must use this Omit shape.\n */\nexport type SavedTransportSettings = Omit<TransportSettings, \"password\">;\n\nexport interface ISaveSettingsRepository {\n execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n}\n\nexport const SaveSettingsRepository =\n createAbstraction<ISaveSettingsRepository>(\"SaveSettingsRepository\");\n\nexport namespace SaveSettingsRepository {\n export type Interface = ISaveSettingsRepository;\n export type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n export type Error = SaveSettingsError;\n}\n\nexport interface ISaveSettings {\n execute(input: SaveSettingsInput): Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n}\n\nexport const SaveSettingsUseCase = createAbstraction<ISaveSettings>(\"SaveSettingsUseCase\");\n\nexport namespace SaveSettingsUseCase {\n export type Interface = ISaveSettings;\n export type Return = Promise<Result<SavedTransportSettings, SaveSettingsError>>;\n export type Error = SaveSettingsError;\n}\n\n// Domain Events. Both payloads exclude `password` so subscribers (audit logs,\n// telemetry, etc.) cannot accidentally persist plaintext or ciphertext secrets.\nexport interface MailerSettingsBeforeSavePayload {\n input: Omit<SaveSettingsInput, \"password\">;\n}\n\nexport interface MailerSettingsAfterSavePayload {\n settings: Omit<TransportSettings, \"password\">;\n}\n\n// Event Handler Abstractions\nexport const MailerSettingsBeforeSaveEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>\n>(\"MailerSettingsBeforeSaveEventHandler\");\n\nexport namespace MailerSettingsBeforeSaveEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>;\n export type Event = DomainEvent<MailerSettingsBeforeSavePayload>;\n}\n\nexport const MailerSettingsAfterSaveEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>\n>(\"MailerSettingsAfterSaveEventHandler\");\n\nexport namespace MailerSettingsAfterSaveEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>;\n export type Event = DomainEvent<MailerSettingsAfterSavePayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AA6BvD;AACA;AACA;AACA;AACA;AACA;;AAOA,OAAO,MAAMC,sBAAsB,GAC/BD,iBAAiB,CAA0B,wBAAwB,CAAC;AAYxE,OAAO,MAAME,mBAAmB,GAAGF,iBAAiB,CAAgB,qBAAqB,CAAC;;AAQ1F;AACA;;AASA;AACA,OAAO,MAAMG,oCAAoC,GAAGH,iBAAiB,CAEnE,sCAAsC,CAAC;AAOzC,OAAO,MAAMI,mCAAmC,GAAGJ,iBAAiB,CAElE,qCAAqC,CAAC","ignoreList":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DomainEvent } from "@webiny/api-core/features/
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
2
|
import type { MailerSettingsBeforeSavePayload, MailerSettingsAfterSavePayload } from "./abstractions.js";
|
|
3
3
|
export declare class MailerSettingsBeforeSaveEvent extends DomainEvent<MailerSettingsBeforeSavePayload> {
|
|
4
4
|
eventType: "mailer.settings.beforeSave";
|
|
5
|
-
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/
|
|
5
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailerSettingsBeforeSavePayload>>>;
|
|
6
6
|
}
|
|
7
7
|
export declare class MailerSettingsAfterSaveEvent extends DomainEvent<MailerSettingsAfterSavePayload> {
|
|
8
8
|
eventType: "mailer.settings.afterSave";
|
|
9
|
-
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/
|
|
9
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailerSettingsAfterSavePayload>>>;
|
|
10
10
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { DomainEvent } from "@webiny/api-core/features/
|
|
2
|
-
import {
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { MailerSettingsBeforeSaveEventHandler, MailerSettingsAfterSaveEventHandler } from "./abstractions.js";
|
|
3
3
|
export class MailerSettingsBeforeSaveEvent extends DomainEvent {
|
|
4
4
|
eventType = "mailer.settings.beforeSave";
|
|
5
5
|
getHandlerAbstraction() {
|
|
6
|
-
return
|
|
6
|
+
return MailerSettingsBeforeSaveEventHandler;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export class MailerSettingsAfterSaveEvent extends DomainEvent {
|
|
10
10
|
eventType = "mailer.settings.afterSave";
|
|
11
11
|
getHandlerAbstraction() {
|
|
12
|
-
return
|
|
12
|
+
return MailerSettingsAfterSaveEventHandler;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DomainEvent","
|
|
1
|
+
{"version":3,"names":["DomainEvent","MailerSettingsBeforeSaveEventHandler","MailerSettingsAfterSaveEventHandler","MailerSettingsBeforeSaveEvent","eventType","getHandlerAbstraction","MailerSettingsAfterSaveEvent"],"sources":["events.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n MailerSettingsBeforeSaveEventHandler,\n MailerSettingsAfterSaveEventHandler\n} from \"./abstractions.js\";\nimport type {\n MailerSettingsBeforeSavePayload,\n MailerSettingsAfterSavePayload\n} from \"./abstractions.js\";\n\nexport class MailerSettingsBeforeSaveEvent extends DomainEvent<MailerSettingsBeforeSavePayload> {\n eventType = \"mailer.settings.beforeSave\" as const;\n\n getHandlerAbstraction() {\n return MailerSettingsBeforeSaveEventHandler;\n }\n}\n\nexport class MailerSettingsAfterSaveEvent extends DomainEvent<MailerSettingsAfterSavePayload> {\n eventType = \"mailer.settings.afterSave\" as const;\n\n getHandlerAbstraction() {\n return MailerSettingsAfterSaveEventHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SACIC,oCAAoC,EACpCC,mCAAmC;AAOvC,OAAO,MAAMC,6BAA6B,SAASH,WAAW,CAAkC;EAC5FI,SAAS,GAAG,4BAA4B;EAExCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOJ,oCAAoC;EAC/C;AACJ;AAEA,OAAO,MAAMK,4BAA4B,SAASN,WAAW,CAAiC;EAC1FI,SAAS,GAAG,2BAA2B;EAEvCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,mCAAmC;EAC9C;AACJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SaveSettingsUseCase,
|
|
1
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SaveSettingsUseCase,
|
|
1
|
+
export { SaveSettingsUseCase, SaveSettingsRepository, MailerSettingsAfterSaveEventHandler, MailerSettingsBeforeSaveEventHandler } from "./abstractions.js";
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SaveSettingsUseCase","
|
|
1
|
+
{"version":3,"names":["SaveSettingsUseCase","SaveSettingsRepository","MailerSettingsAfterSaveEventHandler","MailerSettingsBeforeSaveEventHandler"],"sources":["index.ts"],"sourcesContent":["export {\n SaveSettingsUseCase,\n SaveSettingsRepository,\n MailerSettingsAfterSaveEventHandler,\n MailerSettingsBeforeSaveEventHandler\n} from \"./abstractions.js\";\n"],"mappings":"AAAA,SACIA,mBAAmB,EACnBC,sBAAsB,EACtBC,mCAAmC,EACnCC,oCAAoC","ignoreList":[]}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
2
|
export declare const saveValidation: zod.ZodObject<{
|
|
3
|
-
password: zod.
|
|
3
|
+
password: zod.ZodPipe<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodString>>>, zod.ZodTransform<string | null, string | null | undefined>>;
|
|
4
4
|
from: zod.ZodString;
|
|
5
5
|
port: zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodNumber>>>;
|
|
6
|
-
replyTo: zod.
|
|
6
|
+
replyTo: zod.ZodPreprocess<zod.ZodOptional<zod.ZodNullable<zod.ZodOptional<zod.ZodString>>>>;
|
|
7
7
|
host: zod.ZodString;
|
|
8
8
|
user: zod.ZodString;
|
|
9
|
-
},
|
|
10
|
-
host: string;
|
|
11
|
-
user: string;
|
|
12
|
-
password: string | null;
|
|
13
|
-
from: string;
|
|
14
|
-
port?: number | null | undefined;
|
|
15
|
-
replyTo?: string | null | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
host: string;
|
|
18
|
-
user: string;
|
|
19
|
-
from: string;
|
|
20
|
-
port?: number | null | undefined;
|
|
21
|
-
password?: string | null | undefined;
|
|
22
|
-
replyTo?: unknown;
|
|
23
|
-
}>;
|
|
9
|
+
}, zod.core.$strip>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
|
+
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
2
3
|
const password = zod.string().describe("Password");
|
|
4
|
+
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
5
|
+
message: "Invalid email address."
|
|
6
|
+
});
|
|
3
7
|
const common = {
|
|
4
|
-
from:
|
|
8
|
+
from: mailboxAddress.describe("Mail from"),
|
|
5
9
|
port: zod.number().optional().nullish().describe("Port"),
|
|
6
10
|
replyTo: zod.preprocess(
|
|
7
|
-
// We need to set empty strings to `null` before
|
|
8
|
-
value => value === "" ? null : value,
|
|
11
|
+
// We need to set empty strings to `null` before address validation kicks in.
|
|
12
|
+
value => value === "" ? null : value, mailboxAddress.optional().nullish()).describe("Mail reply-to"),
|
|
9
13
|
host: zod.string().describe("Hostname"),
|
|
10
14
|
user: zod.string().describe("User")
|
|
11
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["zod","password","string","describe","
|
|
1
|
+
{"version":3,"names":["zod","isMailboxAddress","password","string","describe","mailboxAddress","refine","message","common","from","port","number","optional","nullish","replyTo","preprocess","value","host","user","saveValidation","object","transform","undefined"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst password = zod.string().describe(\"Password\");\n\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst common = {\n from: mailboxAddress.describe(\"Mail from\"),\n port: zod.number().optional().nullish().describe(\"Port\"),\n replyTo: zod\n .preprocess(\n // We need to set empty strings to `null` before address validation kicks in.\n value => (value === \"\" ? null : value),\n mailboxAddress.optional().nullish()\n )\n .describe(\"Mail reply-to\"),\n host: zod.string().describe(\"Hostname\"),\n user: zod.string().describe(\"User\")\n};\n\nexport const saveValidation = zod.object({\n ...common,\n password: password\n .nullish()\n .optional()\n .transform(value => {\n return value === undefined ? null : value;\n })\n});\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,gBAAgB;AAEzB,MAAMC,QAAQ,GAAGF,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,UAAU,CAAC;AAElD,MAAMC,cAAc,GAAGL,GAAG,CAACG,MAAM,CAAC,CAAC,CAACG,MAAM,CAACL,gBAAgB,EAAE;EAAEM,OAAO,EAAE;AAAyB,CAAC,CAAC;AAEnG,MAAMC,MAAM,GAAG;EACXC,IAAI,EAAEJ,cAAc,CAACD,QAAQ,CAAC,WAAW,CAAC;EAC1CM,IAAI,EAAEV,GAAG,CAACW,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAACT,QAAQ,CAAC,MAAM,CAAC;EACxDU,OAAO,EAAEd,GAAG,CACPe,UAAU;EACP;EACAC,KAAK,IAAKA,KAAK,KAAK,EAAE,GAAG,IAAI,GAAGA,KAAM,EACtCX,cAAc,CAACO,QAAQ,CAAC,CAAC,CAACC,OAAO,CAAC,CACtC,CAAC,CACAT,QAAQ,CAAC,eAAe,CAAC;EAC9Ba,IAAI,EAAEjB,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,UAAU,CAAC;EACvCc,IAAI,EAAElB,GAAG,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,MAAM;AACtC,CAAC;AAED,OAAO,MAAMe,cAAc,GAAGnB,GAAG,CAACoB,MAAM,CAAC;EACrC,GAAGZ,MAAM;EACTN,QAAQ,EAAEA,QAAQ,CACbW,OAAO,CAAC,CAAC,CACTD,QAAQ,CAAC,CAAC,CACVS,SAAS,CAACL,KAAK,IAAI;IAChB,OAAOA,KAAK,KAAKM,SAAS,GAAG,IAAI,GAAGN,KAAK;EAC7C,CAAC;AACT,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/
|
|
1
|
+
import { EventPublisher as EventPublisherAbstraction } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
2
|
import { SendMailUseCase } from "./abstractions.js";
|
|
3
3
|
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
4
4
|
import type { TransportSendData } from "../../types.js";
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
|
-
import { EventPublisher } from "@webiny/api-core/features/
|
|
2
|
+
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { SendMailUseCase } from "./abstractions.js";
|
|
4
4
|
import { MailBeforeSendEvent, MailAfterSendEvent, MailSendErrorEvent } from "./events.js";
|
|
5
5
|
import { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
6
6
|
import { MailValidationError } from "../../domain/errors.js";
|
|
7
7
|
import { Result } from "@webiny/feature/api";
|
|
8
|
+
import { isMailboxAddress } from "../../utils/isMailboxAddress.js";
|
|
8
9
|
const requiredString = zod.string();
|
|
9
|
-
const
|
|
10
|
+
const mailboxAddress = zod.string().refine(isMailboxAddress, {
|
|
11
|
+
message: "Invalid email address."
|
|
12
|
+
});
|
|
10
13
|
const schema = zod.object({
|
|
11
|
-
to: zod.array(
|
|
12
|
-
from:
|
|
14
|
+
to: zod.array(mailboxAddress).optional(),
|
|
15
|
+
from: mailboxAddress.optional(),
|
|
13
16
|
subject: requiredString.max(1024).min(2),
|
|
14
|
-
cc: zod.array(
|
|
15
|
-
bcc: zod.array(
|
|
16
|
-
replyTo:
|
|
17
|
+
cc: zod.array(mailboxAddress).optional(),
|
|
18
|
+
bcc: zod.array(mailboxAddress).optional(),
|
|
19
|
+
replyTo: mailboxAddress.optional(),
|
|
17
20
|
text: zod.string().optional(),
|
|
18
21
|
html: zod.string().optional()
|
|
19
22
|
}).refine(data => {
|
|
@@ -27,7 +30,7 @@ class SendMailUseCaseImpl {
|
|
|
27
30
|
async execute(data) {
|
|
28
31
|
const validation = schema.safeParse(data);
|
|
29
32
|
if (!validation.success) {
|
|
30
|
-
return Result.fail(new MailValidationError(validation.error.
|
|
33
|
+
return Result.fail(new MailValidationError(validation.error.issues));
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
// Publish before send event
|