@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":["zod","EventPublisher","SendMailUseCase","MailBeforeSendEvent","MailAfterSendEvent","MailSendErrorEvent","MailerService","MailValidationError","Result","requiredString","string","
|
|
1
|
+
{"version":3,"names":["zod","EventPublisher","SendMailUseCase","MailBeforeSendEvent","MailAfterSendEvent","MailSendErrorEvent","MailerService","MailValidationError","Result","isMailboxAddress","requiredString","string","mailboxAddress","refine","message","schema","object","to","array","optional","from","subject","max","min","cc","bcc","replyTo","text","html","data","SendMailUseCaseImpl","constructor","mailerService","eventPublisher","execute","validation","safeParse","success","fail","error","issues","publish","result","sendMail","isFail","response","value","SendMailUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["SendMailUseCase.ts"],"sourcesContent":["import zod from \"zod\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { SendMailUseCase } from \"./abstractions.js\";\nimport { MailBeforeSendEvent, MailAfterSendEvent, MailSendErrorEvent } from \"./events.js\";\nimport { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport type { TransportSendData } from \"~/types.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { isMailboxAddress } from \"~/utils/isMailboxAddress.js\";\n\nconst requiredString = zod.string();\nconst mailboxAddress = zod.string().refine(isMailboxAddress, { message: \"Invalid email address.\" });\n\nconst schema = zod\n .object({\n to: zod.array(mailboxAddress).optional(),\n from: mailboxAddress.optional(),\n subject: requiredString.max(1024).min(2),\n cc: zod.array(mailboxAddress).optional(),\n bcc: zod.array(mailboxAddress).optional(),\n replyTo: mailboxAddress.optional(),\n text: zod.string().optional(),\n html: zod.string().optional()\n })\n .refine(data => {\n return !!data.text || !!data.html;\n }, \"Either text or html is required.\");\n\nclass SendMailUseCaseImpl implements SendMailUseCase.Interface {\n constructor(\n private mailerService: MailerService.Interface,\n private eventPublisher: EventPublisherAbstraction.Interface\n ) {}\n\n async execute(data: TransportSendData) {\n const validation = schema.safeParse(data);\n if (!validation.success) {\n return Result.fail(new MailValidationError(validation.error.issues));\n }\n\n // Publish before send event\n await this.eventPublisher.publish(new MailBeforeSendEvent({ data }));\n\n // Send mail\n const result = await this.mailerService.sendMail(data);\n\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new MailSendErrorEvent({\n data,\n error: result.error\n })\n );\n\n return result;\n }\n\n // Publish after send event\n await this.eventPublisher.publish(\n new MailAfterSendEvent({\n data,\n response: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const SendMailUseCaseImplementation = SendMailUseCase.createImplementation({\n implementation: SendMailUseCaseImpl,\n dependencies: [MailerService, EventPublisher]\n});\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SACIC,cAAc,QAEX,mDAAmD;AAC1D,SAASC,eAAe;AACxB,SAASC,mBAAmB,EAAEC,kBAAkB,EAAEC,kBAAkB;AACpE,SAASC,aAAa;AAEtB,SAASC,mBAAmB;AAC5B,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,gBAAgB;AAEzB,MAAMC,cAAc,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAC;AACnC,MAAMC,cAAc,GAAGZ,GAAG,CAACW,MAAM,CAAC,CAAC,CAACE,MAAM,CAACJ,gBAAgB,EAAE;EAAEK,OAAO,EAAE;AAAyB,CAAC,CAAC;AAEnG,MAAMC,MAAM,GAAGf,GAAG,CACbgB,MAAM,CAAC;EACJC,EAAE,EAAEjB,GAAG,CAACkB,KAAK,CAACN,cAAc,CAAC,CAACO,QAAQ,CAAC,CAAC;EACxCC,IAAI,EAAER,cAAc,CAACO,QAAQ,CAAC,CAAC;EAC/BE,OAAO,EAAEX,cAAc,CAACY,GAAG,CAAC,IAAI,CAAC,CAACC,GAAG,CAAC,CAAC,CAAC;EACxCC,EAAE,EAAExB,GAAG,CAACkB,KAAK,CAACN,cAAc,CAAC,CAACO,QAAQ,CAAC,CAAC;EACxCM,GAAG,EAAEzB,GAAG,CAACkB,KAAK,CAACN,cAAc,CAAC,CAACO,QAAQ,CAAC,CAAC;EACzCO,OAAO,EAAEd,cAAc,CAACO,QAAQ,CAAC,CAAC;EAClCQ,IAAI,EAAE3B,GAAG,CAACW,MAAM,CAAC,CAAC,CAACQ,QAAQ,CAAC,CAAC;EAC7BS,IAAI,EAAE5B,GAAG,CAACW,MAAM,CAAC,CAAC,CAACQ,QAAQ,CAAC;AAChC,CAAC,CAAC,CACDN,MAAM,CAACgB,IAAI,IAAI;EACZ,OAAO,CAAC,CAACA,IAAI,CAACF,IAAI,IAAI,CAAC,CAACE,IAAI,CAACD,IAAI;AACrC,CAAC,EAAE,kCAAkC,CAAC;AAE1C,MAAME,mBAAmB,CAAsC;EAC3DC,WAAWA,CACCC,aAAsC,EACtCC,cAAmD,EAC7D;IAAA,KAFUD,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,cAAmD,GAAnDA,cAAmD;EAC5D;EAEH,MAAMC,OAAOA,CAACL,IAAuB,EAAE;IACnC,MAAMM,UAAU,GAAGpB,MAAM,CAACqB,SAAS,CAACP,IAAI,CAAC;IACzC,IAAI,CAACM,UAAU,CAACE,OAAO,EAAE;MACrB,OAAO7B,MAAM,CAAC8B,IAAI,CAAC,IAAI/B,mBAAmB,CAAC4B,UAAU,CAACI,KAAK,CAACC,MAAM,CAAC,CAAC;IACxE;;IAEA;IACA,MAAM,IAAI,CAACP,cAAc,CAACQ,OAAO,CAAC,IAAItC,mBAAmB,CAAC;MAAE0B;IAAK,CAAC,CAAC,CAAC;;IAEpE;IACA,MAAMa,MAAM,GAAG,MAAM,IAAI,CAACV,aAAa,CAACW,QAAQ,CAACd,IAAI,CAAC;IAEtD,IAAIa,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;MACjB;MACA,MAAM,IAAI,CAACX,cAAc,CAACQ,OAAO,CAC7B,IAAIpC,kBAAkB,CAAC;QACnBwB,IAAI;QACJU,KAAK,EAAEG,MAAM,CAACH;MAClB,CAAC,CACL,CAAC;MAED,OAAOG,MAAM;IACjB;;IAEA;IACA,MAAM,IAAI,CAACT,cAAc,CAACQ,OAAO,CAC7B,IAAIrC,kBAAkB,CAAC;MACnByB,IAAI;MACJgB,QAAQ,EAAEH,MAAM,CAACI;IACrB,CAAC,CACL,CAAC;IAED,OAAOJ,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMK,6BAA6B,GAAG7C,eAAe,CAAC8C,oBAAoB,CAAC;EAC9EC,cAAc,EAAEnB,mBAAmB;EACnCoB,YAAY,EAAE,CAAC5C,aAAa,EAAEL,cAAc;AAChD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
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 { TransportSendData, TransportSendResponse } from "../../types.js";
|
|
4
4
|
import type { MailerService } from "../../domain/MailerService/abstractions.js";
|
|
5
5
|
import { MailValidationError } from "../../domain/errors.js";
|
|
@@ -27,18 +27,18 @@ export interface MailSendErrorPayload {
|
|
|
27
27
|
data: TransportSendData;
|
|
28
28
|
error: Error;
|
|
29
29
|
}
|
|
30
|
-
export declare const
|
|
31
|
-
export declare namespace
|
|
30
|
+
export declare const MailBeforeSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailBeforeSendPayload>>>;
|
|
31
|
+
export declare namespace MailBeforeSendEventHandler {
|
|
32
32
|
type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;
|
|
33
33
|
type Event = DomainEvent<MailBeforeSendPayload>;
|
|
34
34
|
}
|
|
35
|
-
export declare const
|
|
36
|
-
export declare namespace
|
|
35
|
+
export declare const MailAfterSendEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailAfterSendPayload>>>;
|
|
36
|
+
export declare namespace MailAfterSendEventHandler {
|
|
37
37
|
type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;
|
|
38
38
|
type Event = DomainEvent<MailAfterSendPayload>;
|
|
39
39
|
}
|
|
40
|
-
export declare const
|
|
41
|
-
export declare namespace
|
|
40
|
+
export declare const MailSendErrorEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<MailSendErrorPayload>>>;
|
|
41
|
+
export declare namespace MailSendErrorEventHandler {
|
|
42
42
|
type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;
|
|
43
43
|
type Event = DomainEvent<MailSendErrorPayload>;
|
|
44
44
|
}
|
|
@@ -4,8 +4,8 @@ export const SendMailUseCase = createAbstraction("SendMail");
|
|
|
4
4
|
// Domain Events
|
|
5
5
|
|
|
6
6
|
// Event Handler Abstractions
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
7
|
+
export const MailBeforeSendEventHandler = createAbstraction("MailBeforeSendEventHandler");
|
|
8
|
+
export const MailAfterSendEventHandler = createAbstraction("MailAfterSendEventHandler");
|
|
9
|
+
export const MailSendErrorEventHandler = createAbstraction("MailSendErrorEventHandler");
|
|
10
10
|
|
|
11
11
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","SendMailUseCase","
|
|
1
|
+
{"version":3,"names":["createAbstraction","SendMailUseCase","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler"],"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 { TransportSendData, TransportSendResponse } from \"~/types.js\";\nimport type { MailerService } from \"~/domain/MailerService/abstractions.js\";\nimport { MailValidationError } from \"~/domain/errors.js\";\n\nexport interface ISendMailErrors {\n validation: MailValidationError;\n mailService: MailerService.Error;\n}\n\ntype SendMailErrors = ISendMailErrors[keyof ISendMailErrors];\n\nexport interface ISendMailUseCase {\n execute(data: TransportSendData): Promise<Result<TransportSendResponse, SendMailErrors>>;\n}\n\nexport const SendMailUseCase = createAbstraction<ISendMailUseCase>(\"SendMail\");\n\nexport namespace SendMailUseCase {\n export type Interface = ISendMailUseCase;\n export type Error = SendMailErrors;\n}\n\n// Domain Events\nexport interface MailBeforeSendPayload {\n data: TransportSendData;\n}\n\nexport interface MailAfterSendPayload {\n data: TransportSendData;\n response: TransportSendResponse;\n}\n\nexport interface MailSendErrorPayload {\n data: TransportSendData;\n error: Error;\n}\n\n// Event Handler Abstractions\nexport const MailBeforeSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailBeforeSendPayload>>\n>(\"MailBeforeSendEventHandler\");\n\nexport namespace MailBeforeSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailBeforeSendPayload>>;\n export type Event = DomainEvent<MailBeforeSendPayload>;\n}\n\nexport const MailAfterSendEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailAfterSendPayload>>\n>(\"MailAfterSendEventHandler\");\n\nexport namespace MailAfterSendEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailAfterSendPayload>>;\n export type Event = DomainEvent<MailAfterSendPayload>;\n}\n\nexport const MailSendErrorEventHandler = createAbstraction<\n IEventHandler<DomainEvent<MailSendErrorPayload>>\n>(\"MailSendErrorEventHandler\");\n\nexport namespace MailSendErrorEventHandler {\n export type Interface = IEventHandler<DomainEvent<MailSendErrorPayload>>;\n export type Event = DomainEvent<MailSendErrorPayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAkBvD,OAAO,MAAMC,eAAe,GAAGD,iBAAiB,CAAmB,UAAU,CAAC;;AAO9E;;AAeA;AACA,OAAO,MAAME,0BAA0B,GAAGF,iBAAiB,CAEzD,4BAA4B,CAAC;AAO/B,OAAO,MAAMG,yBAAyB,GAAGH,iBAAiB,CAExD,2BAA2B,CAAC;AAO9B,OAAO,MAAMI,yBAAyB,GAAGJ,iBAAiB,CAExD,2BAA2B,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DomainEvent } from "@webiny/api-core/features/
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
2
|
import type { MailBeforeSendPayload, MailAfterSendPayload, MailSendErrorPayload } from "./abstractions.js";
|
|
3
3
|
export declare class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {
|
|
4
4
|
eventType: "mailer.mail.beforeSend";
|
|
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<MailBeforeSendPayload>>>;
|
|
6
6
|
}
|
|
7
7
|
export declare class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {
|
|
8
8
|
eventType: "mailer.mail.afterSend";
|
|
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<MailAfterSendPayload>>>;
|
|
10
10
|
}
|
|
11
11
|
export declare class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {
|
|
12
12
|
eventType: "mailer.mail.sendError";
|
|
13
|
-
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/
|
|
13
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<MailSendErrorPayload>>>;
|
|
14
14
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { DomainEvent } from "@webiny/api-core/features/
|
|
2
|
-
import {
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { MailBeforeSendEventHandler, MailAfterSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
3
3
|
export class MailBeforeSendEvent extends DomainEvent {
|
|
4
4
|
eventType = "mailer.mail.beforeSend";
|
|
5
5
|
getHandlerAbstraction() {
|
|
6
|
-
return
|
|
6
|
+
return MailBeforeSendEventHandler;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export class MailAfterSendEvent extends DomainEvent {
|
|
10
10
|
eventType = "mailer.mail.afterSend";
|
|
11
11
|
getHandlerAbstraction() {
|
|
12
|
-
return
|
|
12
|
+
return MailAfterSendEventHandler;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class MailSendErrorEvent extends DomainEvent {
|
|
16
16
|
eventType = "mailer.mail.sendError";
|
|
17
17
|
getHandlerAbstraction() {
|
|
18
|
-
return
|
|
18
|
+
return MailSendErrorEventHandler;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DomainEvent","
|
|
1
|
+
{"version":3,"names":["DomainEvent","MailBeforeSendEventHandler","MailAfterSendEventHandler","MailSendErrorEventHandler","MailBeforeSendEvent","eventType","getHandlerAbstraction","MailAfterSendEvent","MailSendErrorEvent"],"sources":["events.ts"],"sourcesContent":["import { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n MailBeforeSendEventHandler,\n MailAfterSendEventHandler,\n MailSendErrorEventHandler\n} from \"./abstractions.js\";\nimport type {\n MailBeforeSendPayload,\n MailAfterSendPayload,\n MailSendErrorPayload\n} from \"./abstractions.js\";\n\nexport class MailBeforeSendEvent extends DomainEvent<MailBeforeSendPayload> {\n eventType = \"mailer.mail.beforeSend\" as const;\n\n getHandlerAbstraction() {\n return MailBeforeSendEventHandler;\n }\n}\n\nexport class MailAfterSendEvent extends DomainEvent<MailAfterSendPayload> {\n eventType = \"mailer.mail.afterSend\" as const;\n\n getHandlerAbstraction() {\n return MailAfterSendEventHandler;\n }\n}\n\nexport class MailSendErrorEvent extends DomainEvent<MailSendErrorPayload> {\n eventType = \"mailer.mail.sendError\" as const;\n\n getHandlerAbstraction() {\n return MailSendErrorEventHandler;\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mDAAmD;AAC/E,SACIC,0BAA0B,EAC1BC,yBAAyB,EACzBC,yBAAyB;AAQ7B,OAAO,MAAMC,mBAAmB,SAASJ,WAAW,CAAwB;EACxEK,SAAS,GAAG,wBAAwB;EAEpCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOL,0BAA0B;EACrC;AACJ;AAEA,OAAO,MAAMM,kBAAkB,SAASP,WAAW,CAAuB;EACtEK,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOJ,yBAAyB;EACpC;AACJ;AAEA,OAAO,MAAMM,kBAAkB,SAASR,WAAW,CAAuB;EACtEK,SAAS,GAAG,uBAAuB;EAEnCC,qBAAqBA,CAAA,EAAG;IACpB,OAAOH,yBAAyB;EACpC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SendMailUseCase, MailAfterSendEventHandler, MailBeforeSendEventHandler, MailSendErrorEventHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SendMailUseCase","MailAfterSendEventHandler","MailBeforeSendEventHandler","MailSendErrorEventHandler"],"sources":["index.ts"],"sourcesContent":["export {\n SendMailUseCase,\n MailAfterSendEventHandler,\n MailBeforeSendEventHandler,\n MailSendErrorEventHandler\n} from \"./abstractions.js\";\n"],"mappings":"AAAA,SACIA,eAAe,EACfC,yBAAyB,EACzBC,0BAA0B,EAC1BC,yBAAyB","ignoreList":[]}
|
|
@@ -7,12 +7,62 @@ export declare class SmtpMailTransport implements MailTransport.Interface {
|
|
|
7
7
|
send(params: MailTransport.SendParams): Promise<{
|
|
8
8
|
result: string;
|
|
9
9
|
error: null;
|
|
10
|
+
} | {
|
|
11
|
+
result: null;
|
|
12
|
+
error: {
|
|
13
|
+
message: string;
|
|
14
|
+
code: string;
|
|
15
|
+
data: {
|
|
16
|
+
envelope: import("nodemailer/lib/mime-node").Envelope;
|
|
17
|
+
messageId: string;
|
|
18
|
+
accepted: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
19
|
+
rejected: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
20
|
+
pending: Array<string | import("nodemailer/lib/mailer").Address>;
|
|
21
|
+
response: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
10
24
|
} | {
|
|
11
25
|
result: null;
|
|
12
26
|
error: {
|
|
13
27
|
message: any;
|
|
14
28
|
code: any;
|
|
15
|
-
data:
|
|
29
|
+
data: {
|
|
30
|
+
command: any;
|
|
31
|
+
response: any;
|
|
32
|
+
responseCode: any;
|
|
33
|
+
to: string[];
|
|
34
|
+
cc?: string[];
|
|
35
|
+
bcc?: string[];
|
|
36
|
+
from?: string;
|
|
37
|
+
subject: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
html?: string;
|
|
40
|
+
replyTo?: string;
|
|
41
|
+
} | {
|
|
42
|
+
command: any;
|
|
43
|
+
response: any;
|
|
44
|
+
responseCode: any;
|
|
45
|
+
to?: string[];
|
|
46
|
+
cc: string[];
|
|
47
|
+
bcc?: string[];
|
|
48
|
+
from?: string;
|
|
49
|
+
subject: string;
|
|
50
|
+
text?: string;
|
|
51
|
+
html?: string;
|
|
52
|
+
replyTo?: string;
|
|
53
|
+
} | {
|
|
54
|
+
command: any;
|
|
55
|
+
response: any;
|
|
56
|
+
responseCode: any;
|
|
57
|
+
to?: string[];
|
|
58
|
+
cc?: string[];
|
|
59
|
+
bcc: string[];
|
|
60
|
+
from?: string;
|
|
61
|
+
subject: string;
|
|
62
|
+
text?: string;
|
|
63
|
+
html?: string;
|
|
64
|
+
replyTo?: string;
|
|
65
|
+
};
|
|
16
66
|
};
|
|
17
67
|
}>;
|
|
18
68
|
}
|
|
@@ -43,6 +43,10 @@ export class SmtpMailTransport {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
} catch (ex) {
|
|
46
|
+
// Allow-list specific nodemailer/SMTP error fields. Spreading `ex`
|
|
47
|
+
// or `ex.data` blindly would risk surfacing the transporter's auth
|
|
48
|
+
// config (or anything else a future nodemailer version stamps onto
|
|
49
|
+
// its errors) in error responses.
|
|
46
50
|
return {
|
|
47
51
|
result: null,
|
|
48
52
|
error: {
|
|
@@ -50,7 +54,9 @@ export class SmtpMailTransport {
|
|
|
50
54
|
code: ex.code,
|
|
51
55
|
data: {
|
|
52
56
|
...params,
|
|
53
|
-
|
|
57
|
+
command: ex.command,
|
|
58
|
+
response: ex.response,
|
|
59
|
+
responseCode: ex.responseCode
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["nodemailer","SmtpMailTransport","name","constructor","config","transporter","createTransport","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","response","error","message","code","data","ex"],"sources":["SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(config: SMTPTransport.Options) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n return {\n result: null,\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...params,\n
|
|
1
|
+
{"version":3,"names":["nodemailer","SmtpMailTransport","name","constructor","config","transporter","createTransport","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","response","error","message","code","data","ex","command","responseCode"],"sources":["SmtpMailTransport.ts"],"sourcesContent":["import type { Transporter } from \"nodemailer\";\nimport nodemailer from \"nodemailer\";\nimport type SMTPTransport from \"nodemailer/lib/smtp-transport\";\nimport { MailTransport } from \"~/domain/MailTransport/abstractions.js\";\n\nexport class SmtpMailTransport implements MailTransport.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n private readonly transporter: Transporter<SMTPTransport.SentMessageInfo>;\n\n constructor(config: SMTPTransport.Options) {\n this.transporter = nodemailer.createTransport(config);\n }\n\n async send(params: MailTransport.SendParams) {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await this.transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n\n if (result.messageId) {\n return {\n result: result.response,\n error: null\n };\n }\n\n return {\n result: null,\n error: {\n message:\n \"nodemailer.sendMail does not have a messageId in the result. Something went wrong...\",\n code: \"MAILER_ERROR\",\n data: {\n ...result\n }\n }\n };\n } catch (ex: any) {\n // Allow-list specific nodemailer/SMTP error fields. Spreading `ex`\n // or `ex.data` blindly would risk surfacing the transporter's auth\n // config (or anything else a future nodemailer version stamps onto\n // its errors) in error responses.\n return {\n result: null,\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...params,\n command: ex.command,\n response: ex.response,\n responseCode: ex.responseCode\n }\n }\n };\n }\n }\n}\n"],"mappings":"AACA,OAAOA,UAAU,MAAM,YAAY;AAInC,OAAO,MAAMC,iBAAiB,CAAoC;EAC9CC,IAAI,GAAG,sBAAsB;EAG7CC,WAAWA,CAACC,MAA6B,EAAE;IACvC,IAAI,CAACC,WAAW,GAAGL,UAAU,CAACM,eAAe,CAACF,MAAM,CAAC;EACzD;EAEA,MAAMG,IAAIA,CAACC,MAAgC,EAAE;IACzC,MAAM;MAAEC,OAAO;MAAEC,IAAI;MAAEC,IAAI;MAAEC,EAAE;MAAEC,GAAG;MAAEC,EAAE;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGR,MAAM;IAElE,IAAI;MACA,MAAMS,MAAM,GAAG,MAAM,IAAI,CAACZ,WAAW,CAACa,QAAQ,CAAC;QAC3CT,OAAO;QACPI,GAAG;QACHC,EAAE;QACFC,IAAI;QACJL,IAAI;QACJC,IAAI;QACJC,EAAE;QACFI;MACJ,CAAC,CAAC;MAEF,IAAIC,MAAM,CAACE,SAAS,EAAE;QAClB,OAAO;UACHF,MAAM,EAAEA,MAAM,CAACG,QAAQ;UACvBC,KAAK,EAAE;QACX,CAAC;MACL;MAEA,OAAO;QACHJ,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EACH,sFAAsF;UAC1FC,IAAI,EAAE,cAAc;UACpBC,IAAI,EAAE;YACF,GAAGP;UACP;QACJ;MACJ,CAAC;IACL,CAAC,CAAC,OAAOQ,EAAO,EAAE;MACd;MACA;MACA;MACA;MACA,OAAO;QACHR,MAAM,EAAE,IAAI;QACZI,KAAK,EAAE;UACHC,OAAO,EAAEG,EAAE,CAACH,OAAO;UACnBC,IAAI,EAAEE,EAAE,CAACF,IAAI;UACbC,IAAI,EAAE;YACF,GAAGhB,MAAM;YACTkB,OAAO,EAAED,EAAE,CAACC,OAAO;YACnBN,QAAQ,EAAEK,EAAE,CAACL,QAAQ;YACrBO,YAAY,EAAEF,EAAE,CAACE;UACrB;QACJ;MACJ,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js";
|
|
2
2
|
import type { TransportSettings } from "../../types.js";
|
|
3
3
|
declare class SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {
|
|
4
|
+
readonly name = "Mailer/SmtpTransport";
|
|
4
5
|
createTransport(settings: TransportSettings): MailTransportFactory.Return;
|
|
5
6
|
}
|
|
6
7
|
export declare const SmtpMailTransportFactory: typeof SmtpMailTransportFactoryImpl & {
|
|
@@ -2,6 +2,7 @@ import { MailTransportFactory } from "../../domain/MailTransport/abstractions.js
|
|
|
2
2
|
import { SmtpMailTransport } from "./SmtpMailTransport.js";
|
|
3
3
|
import { SmtpConfig } from "./SmtpConfig.js";
|
|
4
4
|
class SmtpMailTransportFactoryImpl {
|
|
5
|
+
name = "Mailer/SmtpTransport";
|
|
5
6
|
async createTransport(settings) {
|
|
6
7
|
return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MailTransportFactory","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactoryImpl","createTransport","settings","fromTransportSettings","SmtpMailTransportFactory","createImplementation","implementation","dependencies"],"sources":["SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n async createTransport(settings: TransportSettings): MailTransportFactory.Return {\n return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));\n }\n}\n\nexport const SmtpMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: SmtpMailTransportFactoryImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAEnB,MAAMC,4BAA4B,CAA2C;
|
|
1
|
+
{"version":3,"names":["MailTransportFactory","SmtpMailTransport","SmtpConfig","SmtpMailTransportFactoryImpl","name","createTransport","settings","fromTransportSettings","SmtpMailTransportFactory","createImplementation","implementation","dependencies"],"sources":["SmtpMailTransportFactory.ts"],"sourcesContent":["import { MailTransportFactory } from \"~/domain/MailTransport/abstractions.js\";\nimport type { TransportSettings } from \"~/types.js\";\nimport { SmtpMailTransport } from \"~/features/SmtpTransport/SmtpMailTransport.js\";\nimport { SmtpConfig } from \"~/features/SmtpTransport/SmtpConfig.js\";\n\nclass SmtpMailTransportFactoryImpl implements MailTransportFactory.Interface {\n public readonly name = \"Mailer/SmtpTransport\";\n\n async createTransport(settings: TransportSettings): MailTransportFactory.Return {\n return new SmtpMailTransport(SmtpConfig.fromTransportSettings(settings));\n }\n}\n\nexport const SmtpMailTransportFactory = MailTransportFactory.createImplementation({\n implementation: SmtpMailTransportFactoryImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAEnB,MAAMC,4BAA4B,CAA2C;EACzDC,IAAI,GAAG,sBAAsB;EAE7C,MAAMC,eAAeA,CAACC,QAA2B,EAA+B;IAC5E,OAAO,IAAIL,iBAAiB,CAACC,UAAU,CAACK,qBAAqB,CAACD,QAAQ,CAAC,CAAC;EAC5E;AACJ;AAEA,OAAO,MAAME,wBAAwB,GAAGR,oBAAoB,CAACS,oBAAoB,CAAC;EAC9EC,cAAc,EAAEP,4BAA4B;EAC5CQ,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
package/graphql/settings.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import { ErrorResponse, GraphQLSchemaPlugin
|
|
1
|
+
import { ErrorResponse, GraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
2
|
import { GetSettingsUseCase } from "../features/GetSettings/abstractions.js";
|
|
3
3
|
import { SaveSettingsUseCase } from "../features/SaveSettings/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ActiveTransport } from "../domain/MailTransport/abstractions.js";
|
|
5
5
|
const emptyResolver = () => ({});
|
|
6
|
+
|
|
7
|
+
// Strip `password` before the settings leave the server and tack on `source`
|
|
8
|
+
// so the admin UI can branch on code-vs-storage. Accepts both the full
|
|
9
|
+
// `TransportSettings` (from getSettings) and the already-stripped
|
|
10
|
+
// `Omit<TransportSettings, "password">` (from saveSettings) — defense in depth
|
|
11
|
+
// even when the input type carries no password to begin with.
|
|
12
|
+
const toPublicSettings = (settings, source) => {
|
|
13
|
+
if (!settings) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
const {
|
|
18
|
+
password: _password,
|
|
19
|
+
...publicSettings
|
|
20
|
+
} = settings;
|
|
21
|
+
return {
|
|
22
|
+
...publicSettings,
|
|
23
|
+
source
|
|
24
|
+
};
|
|
25
|
+
};
|
|
6
26
|
export const createSettingsGraphQL = () => {
|
|
7
27
|
return new GraphQLSchemaPlugin({
|
|
8
28
|
typeDefs: `
|
|
@@ -18,6 +38,7 @@ export const createSettingsGraphQL = () => {
|
|
|
18
38
|
user: String
|
|
19
39
|
from: String
|
|
20
40
|
replyTo: String
|
|
41
|
+
source: String
|
|
21
42
|
}
|
|
22
43
|
|
|
23
44
|
type MailerTransportSettingsResponse {
|
|
@@ -56,24 +77,24 @@ export const createSettingsGraphQL = () => {
|
|
|
56
77
|
MailerQuery: {
|
|
57
78
|
getSettings: async (_, __, context) => {
|
|
58
79
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Remove password from response
|
|
68
|
-
if (settings?.password) {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
-
const {
|
|
71
|
-
password,
|
|
72
|
-
...settingsWithoutPassword
|
|
73
|
-
} = settings;
|
|
74
|
-
return new Response(settingsWithoutPassword);
|
|
80
|
+
const activeTransport = context.container.resolve(ActiveTransport);
|
|
81
|
+
const transportName = activeTransport.name();
|
|
82
|
+
if (!transportName) {
|
|
83
|
+
return {
|
|
84
|
+
data: null,
|
|
85
|
+
error: null
|
|
86
|
+
};
|
|
75
87
|
}
|
|
76
|
-
|
|
88
|
+
const getSettings = context.container.resolve(GetSettingsUseCase);
|
|
89
|
+
const result = await getSettings.execute(transportName);
|
|
90
|
+
const {
|
|
91
|
+
settings,
|
|
92
|
+
source
|
|
93
|
+
} = result.value;
|
|
94
|
+
return {
|
|
95
|
+
data: toPublicSettings(settings, source),
|
|
96
|
+
error: null
|
|
97
|
+
};
|
|
77
98
|
} catch (ex) {
|
|
78
99
|
return new ErrorResponse(ex);
|
|
79
100
|
}
|
|
@@ -90,19 +111,10 @@ export const createSettingsGraphQL = () => {
|
|
|
90
111
|
if (result.isFail()) {
|
|
91
112
|
return new ErrorResponse(result.error);
|
|
92
113
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (settings?.password) {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
-
const {
|
|
100
|
-
password,
|
|
101
|
-
...settingsWithoutPassword
|
|
102
|
-
} = settings;
|
|
103
|
-
return new Response(settingsWithoutPassword);
|
|
104
|
-
}
|
|
105
|
-
return new Response(settings);
|
|
114
|
+
return {
|
|
115
|
+
data: toPublicSettings(result.value, "storage"),
|
|
116
|
+
error: null
|
|
117
|
+
};
|
|
106
118
|
} catch (ex) {
|
|
107
119
|
return new ErrorResponse(ex);
|
|
108
120
|
}
|
package/graphql/settings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ErrorResponse","GraphQLSchemaPlugin","
|
|
1
|
+
{"version":3,"names":["ErrorResponse","GraphQLSchemaPlugin","GetSettingsUseCase","SaveSettingsUseCase","ActiveTransport","emptyResolver","toPublicSettings","settings","source","password","_password","publicSettings","createSettingsGraphQL","typeDefs","resolvers","Query","mailer","MailerQuery","getSettings","_","__","context","activeTransport","container","resolve","transportName","name","data","error","result","execute","value","ex","Mutation","MailerMutation","saveSettings","args","isFail"],"sources":["settings.ts"],"sourcesContent":["import { ErrorResponse, GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { GetSettingsUseCase } from \"~/features/GetSettings/abstractions.js\";\nimport { SaveSettingsUseCase } from \"~/features/SaveSettings/abstractions.js\";\nimport { ActiveTransport } from \"~/domain/MailTransport/abstractions.js\";\nimport type { MailerSettingsSource } from \"~/features/GetSettings/abstractions.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport type { TransportSettings } from \"~/types.js\";\n\nconst emptyResolver = () => ({});\n\n// Strip `password` before the settings leave the server and tack on `source`\n// so the admin UI can branch on code-vs-storage. Accepts both the full\n// `TransportSettings` (from getSettings) and the already-stripped\n// `Omit<TransportSettings, \"password\">` (from saveSettings) — defense in depth\n// even when the input type carries no password to begin with.\nconst toPublicSettings = (\n settings: TransportSettings | Omit<TransportSettings, \"password\"> | null,\n source: MailerSettingsSource\n): (Omit<TransportSettings, \"password\"> & { source: MailerSettingsSource }) | null => {\n if (!settings) {\n return null;\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { password: _password, ...publicSettings } = settings as TransportSettings;\n return { ...publicSettings, source };\n};\n\nexport const createSettingsGraphQL = () => {\n return new GraphQLSchemaPlugin<Context>({\n typeDefs: `\n type MailerTransportSettingsError {\n message: String!\n code: String\n data: JSON\n }\n\n type MailerTransportSettings {\n host: String\n port: Number\n user: String\n from: String\n replyTo: String\n source: String\n }\n\n type MailerTransportSettingsResponse {\n data: MailerTransportSettings\n error: MailerTransportSettingsError\n }\n\n type MailerQuery {\n getSettings: MailerTransportSettingsResponse!\n }\n\n input MailerTransportSettingsInput {\n host: String!\n port: Number\n user: String!\n password: String\n from: String!\n replyTo: String\n }\n\n type MailerMutation {\n saveSettings(data: MailerTransportSettingsInput!): MailerTransportSettingsResponse!\n }\n\n extend type Query {\n mailer: MailerQuery\n }\n extend type Mutation {\n mailer: MailerMutation\n }\n `,\n resolvers: {\n Query: {\n mailer: emptyResolver\n },\n MailerQuery: {\n getSettings: async (_, __, context) => {\n try {\n const activeTransport = context.container.resolve(ActiveTransport);\n const transportName = activeTransport.name();\n\n if (!transportName) {\n return { data: null, error: null };\n }\n\n const getSettings = context.container.resolve(GetSettingsUseCase);\n const result = await getSettings.execute(transportName);\n\n const { settings, source } = result.value;\n\n return {\n data: toPublicSettings(settings, source),\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n },\n Mutation: {\n mailer: emptyResolver\n },\n MailerMutation: {\n saveSettings: async (_, args: any, context) => {\n try {\n const saveSettings = context.container.resolve(SaveSettingsUseCase);\n const result = await saveSettings.execute(args.data);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return {\n data: toPublicSettings(result.value, \"storage\"),\n error: null\n };\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n }\n }\n }\n });\n};\n"],"mappings":"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","ignoreList":[]}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContextPlugin } from "@webiny/api";
|
|
2
|
-
import {
|
|
2
|
+
import { CodeMailerSettingsFeature } from "./features/CodeMailerSettings/feature.js";
|
|
3
3
|
import { GetSettingsFeature } from "./features/GetSettings/feature.js";
|
|
4
4
|
import { SaveSettingsFeature } from "./features/SaveSettings/feature.js";
|
|
5
5
|
import { DummyTransportFeature } from "./features/DummyTransport/feature.js";
|
|
@@ -10,8 +10,8 @@ import { createSettingsGraphQL } from "./graphql/settings.js";
|
|
|
10
10
|
export { MailerService } from "./domain/MailerService/abstractions.js";
|
|
11
11
|
export const createMailerContext = () => {
|
|
12
12
|
return createContextPlugin(context => {
|
|
13
|
-
// Register all features
|
|
14
|
-
|
|
13
|
+
// Register all features.
|
|
14
|
+
CodeMailerSettingsFeature.register(context.container);
|
|
15
15
|
DummyTransportFeature.register(context.container);
|
|
16
16
|
SmtpTransportFeature.register(context.container);
|
|
17
17
|
GetSettingsFeature.register(context.container);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContextPlugin","
|
|
1
|
+
{"version":3,"names":["createContextPlugin","CodeMailerSettingsFeature","GetSettingsFeature","SaveSettingsFeature","DummyTransportFeature","SmtpTransportFeature","MailerServiceFeature","SendMailFeature","createSettingsGraphQL","MailerService","createMailerContext","context","register","container","createMailerGraphQL"],"sources":["index.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { CodeMailerSettingsFeature } from \"~/features/CodeMailerSettings/feature.js\";\nimport { GetSettingsFeature } from \"~/features/GetSettings/feature.js\";\nimport { SaveSettingsFeature } from \"~/features/SaveSettings/feature.js\";\nimport { DummyTransportFeature } from \"~/features/DummyTransport/feature.js\";\nimport { SmtpTransportFeature } from \"~/features/SmtpTransport/feature.js\";\nimport { MailerServiceFeature } from \"~/features/MailerService/feature.js\";\nimport { SendMailFeature } from \"~/features/SendMail/feature.js\";\nimport { createSettingsGraphQL } from \"~/graphql/settings.js\";\n\nexport { MailerService } from \"./domain/MailerService/abstractions.js\";\nexport type { IMailerService, IMailerServiceErrors } from \"./domain/MailerService/abstractions.js\";\n\nexport const createMailerContext = () => {\n return createContextPlugin(context => {\n // Register all features.\n CodeMailerSettingsFeature.register(context.container);\n DummyTransportFeature.register(context.container);\n SmtpTransportFeature.register(context.container);\n GetSettingsFeature.register(context.container);\n SaveSettingsFeature.register(context.container);\n MailerServiceFeature.register(context.container);\n SendMailFeature.register(context.container);\n });\n};\n\nexport const createMailerGraphQL = () => {\n return createSettingsGraphQL();\n};\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,aAAa;AACjD,SAASC,yBAAyB;AAClC,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAC5B,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AACxB,SAASC,qBAAqB;AAE9B,SAASC,aAAa;AAGtB,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,OAAOV,mBAAmB,CAACW,OAAO,IAAI;IAClC;IACAV,yBAAyB,CAACW,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IACrDT,qBAAqB,CAACQ,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IACjDR,oBAAoB,CAACO,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAChDX,kBAAkB,CAACU,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAC9CV,mBAAmB,CAACS,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAC/CP,oBAAoB,CAACM,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;IAChDN,eAAe,CAACK,QAAQ,CAACD,OAAO,CAACE,SAAS,CAAC;EAC/C,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,OAAON,qBAAqB,CAAC,CAAC;AAClC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-mailer",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e6f0dc8ca7",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/webiny/webiny-js.git",
|
|
@@ -15,41 +18,33 @@
|
|
|
15
18
|
"description": "The API to send e-mails.",
|
|
16
19
|
"license": "MIT",
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"@webiny/api": "0.0.0-unstable.
|
|
19
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
23
|
-
"
|
|
24
|
-
"nodemailer": "
|
|
25
|
-
"zod": "
|
|
21
|
+
"@webiny/api": "0.0.0-unstable.e6f0dc8ca7",
|
|
22
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.e6f0dc8ca7",
|
|
23
|
+
"@webiny/feature": "0.0.0-unstable.e6f0dc8ca7",
|
|
24
|
+
"@webiny/handler-graphql": "0.0.0-unstable.e6f0dc8ca7",
|
|
25
|
+
"@webiny/plugins": "0.0.0-unstable.e6f0dc8ca7",
|
|
26
|
+
"email-addresses": "5.0.0",
|
|
27
|
+
"nodemailer": "8.0.7",
|
|
28
|
+
"zod": "4.4.3"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"@
|
|
30
|
-
"@webiny/
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
34
|
-
"@webiny/handler-
|
|
35
|
-
"@webiny/
|
|
36
|
-
"
|
|
37
|
-
"graphql": "16.12.0",
|
|
31
|
+
"@types/nodemailer": "8.0.0",
|
|
32
|
+
"@webiny/api-core": "0.0.0-unstable.e6f0dc8ca7",
|
|
33
|
+
"@webiny/build-tools": "0.0.0-unstable.e6f0dc8ca7",
|
|
34
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.e6f0dc8ca7",
|
|
35
|
+
"@webiny/handler": "0.0.0-unstable.e6f0dc8ca7",
|
|
36
|
+
"@webiny/handler-aws": "0.0.0-unstable.e6f0dc8ca7",
|
|
37
|
+
"@webiny/handler-db": "0.0.0-unstable.e6f0dc8ca7",
|
|
38
|
+
"@webiny/project-utils": "0.0.0-unstable.e6f0dc8ca7",
|
|
39
|
+
"graphql": "16.14.0",
|
|
38
40
|
"jest-dynalite": "3.6.1",
|
|
39
|
-
"rimraf": "6.1.
|
|
40
|
-
"typescript": "
|
|
41
|
-
"vitest": "
|
|
41
|
+
"rimraf": "6.1.3",
|
|
42
|
+
"typescript": "6.0.3",
|
|
43
|
+
"vitest": "4.1.5"
|
|
42
44
|
},
|
|
43
45
|
"publishConfig": {
|
|
44
46
|
"access": "public",
|
|
45
47
|
"directory": "dist"
|
|
46
48
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
-
"adio": {
|
|
49
|
-
"ignore": {
|
|
50
|
-
"src": [
|
|
51
|
-
"node:crypto"
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
}
|
|
49
|
+
"gitHead": "e6f0dc8ca741c1fcc3fec9a5b9e86fdd49544641"
|
|
55
50
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 5322 mailbox validator. Accepts both addr-spec ("addr@domain") and
|
|
3
|
+
* name-addr ("Display Name <addr@domain>") forms — both are valid SMTP
|
|
4
|
+
* From / Reply-To inputs that nodemailer and most providers accept.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isMailboxAddress: (value: string) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import emailAddresses from "email-addresses";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RFC 5322 mailbox validator. Accepts both addr-spec ("addr@domain") and
|
|
5
|
+
* name-addr ("Display Name <addr@domain>") forms — both are valid SMTP
|
|
6
|
+
* From / Reply-To inputs that nodemailer and most providers accept.
|
|
7
|
+
*/
|
|
8
|
+
export const isMailboxAddress = value => {
|
|
9
|
+
return emailAddresses.parseOneAddress(value) !== null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=isMailboxAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["emailAddresses","isMailboxAddress","value","parseOneAddress"],"sources":["isMailboxAddress.ts"],"sourcesContent":["import emailAddresses from \"email-addresses\";\n\n/**\n * RFC 5322 mailbox validator. Accepts both addr-spec (\"addr@domain\") and\n * name-addr (\"Display Name <addr@domain>\") forms — both are valid SMTP\n * From / Reply-To inputs that nodemailer and most providers accept.\n */\nexport const isMailboxAddress = (value: string): boolean => {\n return emailAddresses.parseOneAddress(value) !== null;\n};\n"],"mappings":"AAAA,OAAOA,cAAc,MAAM,iBAAiB;;AAE5C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAIC,KAAa,IAAc;EACxD,OAAOF,cAAc,CAACG,eAAe,CAACD,KAAK,CAAC,KAAK,IAAI;AACzD,CAAC","ignoreList":[]}
|