@webiny/api-mailer 0.0.0-unstable.1e66d121db
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/LICENSE +21 -0
- package/README.md +14 -0
- package/context.d.ts +3 -0
- package/context.js +24 -0
- package/context.js.map +1 -0
- package/crud/group.d.ts +2 -0
- package/crud/group.js +20 -0
- package/crud/group.js.map +1 -0
- package/crud/mailer/onBeforeSend.d.ts +7 -0
- package/crud/mailer/onBeforeSend.js +69 -0
- package/crud/mailer/onBeforeSend.js.map +1 -0
- package/crud/mailer.crud.d.ts +2 -0
- package/crud/mailer.crud.js +123 -0
- package/crud/mailer.crud.js.map +1 -0
- package/crud/settings/hooks.d.ts +5 -0
- package/crud/settings/hooks.js +55 -0
- package/crud/settings/hooks.js.map +1 -0
- package/crud/settings/model.d.ts +3 -0
- package/crud/settings/model.js +72 -0
- package/crud/settings/model.js.map +1 -0
- package/crud/settings/password.d.ts +7 -0
- package/crud/settings/password.js +71 -0
- package/crud/settings/password.js.map +1 -0
- package/crud/settings/secret.d.ts +1 -0
- package/crud/settings/secret.js +23 -0
- package/crud/settings/secret.js.map +1 -0
- package/crud/settings/transform.d.ts +13 -0
- package/crud/settings/transform.js +56 -0
- package/crud/settings/transform.js.map +1 -0
- package/crud/settings/validation.d.ts +4 -0
- package/crud/settings/validation.js +37 -0
- package/crud/settings/validation.js.map +1 -0
- package/crud/settings.crud.d.ts +5 -0
- package/crud/settings.crud.js +321 -0
- package/crud/settings.crud.js.map +1 -0
- package/crud/transport/onTransportBeforeSend.d.ts +7 -0
- package/crud/transport/onTransportBeforeSend.js +69 -0
- package/crud/transport/onTransportBeforeSend.js.map +1 -0
- package/crud/transporter.crud.d.ts +2 -0
- package/crud/transporter.crud.js +182 -0
- package/crud/transporter.crud.js.map +1 -0
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +14 -0
- package/graphql/index.js.map +1 -0
- package/graphql/settings.d.ts +3 -0
- package/graphql/settings.js +107 -0
- package/graphql/settings.js.map +1 -0
- package/index.d.ts +7 -0
- package/index.js +65 -0
- package/index.js.map +1 -0
- package/mailers/createDummyMailer.d.ts +5 -0
- package/mailers/createDummyMailer.js +24 -0
- package/mailers/createDummyMailer.js.map +1 -0
- package/mailers/createSmtpMailer.d.ts +13 -0
- package/mailers/createSmtpMailer.js +106 -0
- package/mailers/createSmtpMailer.js.map +1 -0
- package/package.json +65 -0
- package/plugins/CreateTransportPlugin.d.ts +17 -0
- package/plugins/CreateTransportPlugin.js +34 -0
- package/plugins/CreateTransportPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/transports/createDummyTransport.d.ts +5 -0
- package/transports/createDummyTransport.js +25 -0
- package/transports/createDummyTransport.js.map +1 -0
- package/transports/createSmtpTransport.d.ts +12 -0
- package/transports/createSmtpTransport.js +80 -0
- package/transports/createSmtpTransport.js.map +1 -0
- package/types.d.ts +148 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin as BasePlugin } from "@webiny/plugins";
|
|
2
|
+
import { Transport, MailerContext, TransportSettings } from "../types";
|
|
3
|
+
interface TransportParams {
|
|
4
|
+
settings: TransportSettings | null;
|
|
5
|
+
context: MailerContext;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateTransportCallable<T> {
|
|
8
|
+
(params: TransportParams): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
export declare class CreateTransportPlugin<T extends Transport = Transport> extends BasePlugin {
|
|
11
|
+
static type: string;
|
|
12
|
+
private readonly cb;
|
|
13
|
+
constructor(cb: CreateTransportCallable<T>);
|
|
14
|
+
buildMailerTransport(params: TransportParams): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
export declare const createTransport: <T extends Transport<any> = Transport<any>>(cb: CreateTransportCallable<T>) => CreateTransportPlugin<T>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createTransport = exports.CreateTransportPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class CreateTransportPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(cb) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
+
this.cb = cb;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async buildMailerTransport(params) {
|
|
22
|
+
return this.cb(params);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.CreateTransportPlugin = CreateTransportPlugin;
|
|
28
|
+
(0, _defineProperty2.default)(CreateTransportPlugin, "type", "mailer.builder.plugin");
|
|
29
|
+
|
|
30
|
+
const createTransport = cb => {
|
|
31
|
+
return new CreateTransportPlugin(cb);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createTransport = createTransport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CreateTransportPlugin","BasePlugin","constructor","cb","buildMailerTransport","params","createTransport"],"sources":["CreateTransportPlugin.ts"],"sourcesContent":["import { Plugin as BasePlugin } from \"@webiny/plugins\";\nimport { Transport, MailerContext, TransportSettings } from \"~/types\";\n\ninterface TransportParams {\n settings: TransportSettings | null;\n context: MailerContext;\n}\n\nexport interface CreateTransportCallable<T> {\n (params: TransportParams): Promise<T>;\n}\n\nexport class CreateTransportPlugin<T extends Transport = Transport> extends BasePlugin {\n public static override type = \"mailer.builder.plugin\";\n\n private readonly cb: CreateTransportCallable<T>;\n\n public constructor(cb: CreateTransportCallable<T>) {\n super();\n this.cb = cb;\n }\n\n public async buildMailerTransport(params: TransportParams): Promise<T> {\n return this.cb(params);\n }\n}\n\nexport const createTransport = <T extends Transport = Transport>(\n cb: CreateTransportCallable<T>\n) => {\n return new CreateTransportPlugin<T>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAYO,MAAMA,qBAAN,SAAqEC,eAArE,CAAgF;EAK5EC,WAAW,CAACC,EAAD,EAAiC;IAC/C;IAD+C;IAE/C,KAAKA,EAAL,GAAUA,EAAV;EACH;;EAEgC,MAApBC,oBAAoB,CAACC,MAAD,EAAsC;IACnE,OAAO,KAAKF,EAAL,CAAQE,MAAR,CAAP;EACH;;AAZkF;;;8BAA1EL,qB,UACqB,uB;;AAc3B,MAAMM,eAAe,GACxBH,EAD2B,IAE1B;EACD,OAAO,IAAIH,qBAAJ,CAA6BG,EAA7B,CAAP;AACH,CAJM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CreateTransportPlugin";
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _CreateTransportPlugin = require("./CreateTransportPlugin");
|
|
8
|
+
|
|
9
|
+
Object.keys(_CreateTransportPlugin).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _CreateTransportPlugin[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _CreateTransportPlugin[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CreateTransportPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDummyTransport = void 0;
|
|
7
|
+
|
|
8
|
+
const createDummyTransport = () => {
|
|
9
|
+
const sent = [];
|
|
10
|
+
return {
|
|
11
|
+
name: "dummy-default",
|
|
12
|
+
send: async params => {
|
|
13
|
+
sent.push(params);
|
|
14
|
+
return {
|
|
15
|
+
result: true,
|
|
16
|
+
error: null
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
getAllSent: () => {
|
|
20
|
+
return sent;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.createDummyTransport = createDummyTransport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDummyTransport","sent","name","send","params","push","result","error","getAllSent"],"sources":["createDummyTransport.ts"],"sourcesContent":["import { Transport, TransportSendData } from \"~/types\";\n\nexport interface DummyTransport extends Transport {\n getAllSent: () => TransportSendData[];\n}\nexport const createDummyTransport = (): DummyTransport => {\n const sent: TransportSendData[] = [];\n\n return {\n name: \"dummy-default\",\n send: async params => {\n sent.push(params);\n return {\n result: true,\n error: null\n };\n },\n getAllSent: () => {\n return sent;\n }\n };\n};\n"],"mappings":";;;;;;;AAKO,MAAMA,oBAAoB,GAAG,MAAsB;EACtD,MAAMC,IAAyB,GAAG,EAAlC;EAEA,OAAO;IACHC,IAAI,EAAE,eADH;IAEHC,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClBH,IAAI,CAACI,IAAL,CAAUD,MAAV;MACA,OAAO;QACHE,MAAM,EAAE,IADL;QAEHC,KAAK,EAAE;MAFJ,CAAP;IAIH,CARE;IASHC,UAAU,EAAE,MAAM;MACd,OAAOP,IAAP;IACH;EAXE,CAAP;AAaH,CAhBM"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nodemailer docs
|
|
3
|
+
* https://nodemailer.com/about/
|
|
4
|
+
*/
|
|
5
|
+
import { Transport } from "../types";
|
|
6
|
+
import { Transporter } from "nodemailer";
|
|
7
|
+
import SMTPTransport, { Options } from "nodemailer/lib/smtp-transport";
|
|
8
|
+
export declare type SmtpTransportConfig = Options;
|
|
9
|
+
export interface SmtpTransport extends Transport {
|
|
10
|
+
transporter: Transporter<SMTPTransport.SentMessageInfo>;
|
|
11
|
+
}
|
|
12
|
+
export declare const createSmtpTransport: (config?: Partial<SmtpTransportConfig> | null) => SmtpTransport;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSmtpTransport = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _nodemailer = _interopRequireDefault(require("nodemailer"));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Nodemailer docs
|
|
18
|
+
* https://nodemailer.com/about/
|
|
19
|
+
*/
|
|
20
|
+
const createSmtpTransport = config => {
|
|
21
|
+
if (!config || typeof config !== "object" || Object.keys(config).length === 0) {
|
|
22
|
+
throw new _error.default("There is no configuration for the SMTP transport.");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const transporter = _nodemailer.default.createTransport(config);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
name: "smtp-default",
|
|
29
|
+
transporter,
|
|
30
|
+
send: async params => {
|
|
31
|
+
const {
|
|
32
|
+
replyTo,
|
|
33
|
+
text,
|
|
34
|
+
html,
|
|
35
|
+
to,
|
|
36
|
+
bcc,
|
|
37
|
+
cc,
|
|
38
|
+
from,
|
|
39
|
+
subject
|
|
40
|
+
} = params;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = await transporter.sendMail({
|
|
44
|
+
replyTo,
|
|
45
|
+
bcc,
|
|
46
|
+
cc,
|
|
47
|
+
from,
|
|
48
|
+
text,
|
|
49
|
+
html,
|
|
50
|
+
to,
|
|
51
|
+
subject
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (result.messageId) {
|
|
55
|
+
return {
|
|
56
|
+
result: true,
|
|
57
|
+
error: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw new _error.default({
|
|
62
|
+
message: "nodemailer.sendMail does not have a messageId in the result. Something went wrong...",
|
|
63
|
+
code: "MAILER_ERROR",
|
|
64
|
+
data: (0, _objectSpread2.default)({}, result)
|
|
65
|
+
});
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
return {
|
|
68
|
+
result: null,
|
|
69
|
+
error: {
|
|
70
|
+
message: ex.message,
|
|
71
|
+
code: ex.code,
|
|
72
|
+
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), ex.data)
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.createSmtpTransport = createSmtpTransport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSmtpTransport","config","Object","keys","length","WebinyError","transporter","nodemailer","createTransport","name","send","params","replyTo","text","html","to","bcc","cc","from","subject","result","sendMail","messageId","error","message","code","data","ex"],"sources":["createSmtpTransport.ts"],"sourcesContent":["/**\n * Nodemailer docs\n * https://nodemailer.com/about/\n */\nimport { Transport } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport nodemailer, { Transporter } from \"nodemailer\";\nimport SMTPTransport, { Options } from \"nodemailer/lib/smtp-transport\";\n\nexport type SmtpTransportConfig = Options;\n\nexport interface SmtpTransport extends Transport {\n transporter: Transporter<SMTPTransport.SentMessageInfo>;\n}\n\nexport const createSmtpTransport = (\n config?: Partial<SmtpTransportConfig> | null\n): SmtpTransport => {\n if (!config || typeof config !== \"object\" || Object.keys(config).length === 0) {\n throw new WebinyError(\"There is no configuration for the SMTP transport.\");\n }\n\n const transporter = nodemailer.createTransport(config);\n\n return {\n name: \"smtp-default\",\n transporter,\n send: async params => {\n const { replyTo, text, html, to, bcc, cc, from, subject } = params;\n\n try {\n const result = await transporter.sendMail({\n replyTo,\n bcc,\n cc,\n from,\n text,\n html,\n to,\n subject\n });\n if (result.messageId) {\n return {\n result: true,\n error: null\n };\n }\n\n throw new WebinyError({\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 } catch (ex) {\n return {\n result: null,\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...params,\n ...ex.data\n }\n }\n };\n }\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA;;AACA;;AANA;AACA;AACA;AACA;AAYO,MAAMA,mBAAmB,GAC5BC,MAD+B,IAEf;EAChB,IAAI,CAACA,MAAD,IAAW,OAAOA,MAAP,KAAkB,QAA7B,IAAyCC,MAAM,CAACC,IAAP,CAAYF,MAAZ,EAAoBG,MAApB,KAA+B,CAA5E,EAA+E;IAC3E,MAAM,IAAIC,cAAJ,CAAgB,mDAAhB,CAAN;EACH;;EAED,MAAMC,WAAW,GAAGC,mBAAA,CAAWC,eAAX,CAA2BP,MAA3B,CAApB;;EAEA,OAAO;IACHQ,IAAI,EAAE,cADH;IAEHH,WAFG;IAGHI,IAAI,EAAE,MAAMC,MAAN,IAAgB;MAClB,MAAM;QAAEC,OAAF;QAAWC,IAAX;QAAiBC,IAAjB;QAAuBC,EAAvB;QAA2BC,GAA3B;QAAgCC,EAAhC;QAAoCC,IAApC;QAA0CC;MAA1C,IAAsDR,MAA5D;;MAEA,IAAI;QACA,MAAMS,MAAM,GAAG,MAAMd,WAAW,CAACe,QAAZ,CAAqB;UACtCT,OADsC;UAEtCI,GAFsC;UAGtCC,EAHsC;UAItCC,IAJsC;UAKtCL,IALsC;UAMtCC,IANsC;UAOtCC,EAPsC;UAQtCI;QARsC,CAArB,CAArB;;QAUA,IAAIC,MAAM,CAACE,SAAX,EAAsB;UAClB,OAAO;YACHF,MAAM,EAAE,IADL;YAEHG,KAAK,EAAE;UAFJ,CAAP;QAIH;;QAED,MAAM,IAAIlB,cAAJ,CAAgB;UAClBmB,OAAO,EACH,sFAFc;UAGlBC,IAAI,EAAE,cAHY;UAIlBC,IAAI,kCACGN,MADH;QAJc,CAAhB,CAAN;MAQH,CA1BD,CA0BE,OAAOO,EAAP,EAAW;QACT,OAAO;UACHP,MAAM,EAAE,IADL;UAEHG,KAAK,EAAE;YACHC,OAAO,EAAEG,EAAE,CAACH,OADT;YAEHC,IAAI,EAAEE,EAAE,CAACF,IAFN;YAGHC,IAAI,8DACGf,MADH,GAEGgB,EAAE,CAACD,IAFN;UAHD;QAFJ,CAAP;MAWH;IACJ;EA7CE,CAAP;AA+CH,CAxDM"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { CmsContext } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Topic } from "@webiny/pubsub/types";
|
|
3
|
+
export interface MailerTransporterContext<T extends Transport = Transport> {
|
|
4
|
+
onTransportBeforeSend: Topic<OnTransportBeforeSendParams>;
|
|
5
|
+
onTransportAfterSend: Topic<OnTransportAfterSendParams>;
|
|
6
|
+
onTransportError: Topic<OnTransportErrorParams>;
|
|
7
|
+
getTransport: () => Promise<T | null>;
|
|
8
|
+
sendMail: <D>(data: TransportSendData) => Promise<TransportSendResponse<D>>;
|
|
9
|
+
}
|
|
10
|
+
export interface MailerSettingsCreateParams {
|
|
11
|
+
input: Partial<TransportSettings>;
|
|
12
|
+
}
|
|
13
|
+
export interface MailerSettingsUpdateParams {
|
|
14
|
+
input: Partial<TransportSettings>;
|
|
15
|
+
original?: ExtendedTransportSettings | null;
|
|
16
|
+
}
|
|
17
|
+
export interface MailerSettingsSaveParams {
|
|
18
|
+
input: Partial<TransportSettings>;
|
|
19
|
+
}
|
|
20
|
+
export interface OnSettingsBeforeGetTopicParams {
|
|
21
|
+
tenant: string;
|
|
22
|
+
}
|
|
23
|
+
export interface OnSettingsAfterGetTopicParams {
|
|
24
|
+
tenant: string;
|
|
25
|
+
settings: TransportSettings | null;
|
|
26
|
+
}
|
|
27
|
+
export interface OnSettingsGetErrorTopicParams {
|
|
28
|
+
tenant: string;
|
|
29
|
+
error: Error;
|
|
30
|
+
}
|
|
31
|
+
export interface OnSettingsBeforeCreateTopicParams {
|
|
32
|
+
settings: TransportSettings;
|
|
33
|
+
}
|
|
34
|
+
export interface OnSettingsAfterCreateTopicParams {
|
|
35
|
+
settings: TransportSettings;
|
|
36
|
+
}
|
|
37
|
+
export interface OnSettingsCreateErrorTopicParams {
|
|
38
|
+
settings: TransportSettings;
|
|
39
|
+
error: Error;
|
|
40
|
+
}
|
|
41
|
+
export interface OnSettingsBeforeUpdateTopicParams {
|
|
42
|
+
settings: TransportSettings;
|
|
43
|
+
original: TransportSettings;
|
|
44
|
+
}
|
|
45
|
+
export interface OnSettingsAfterUpdateTopicParams {
|
|
46
|
+
original: TransportSettings;
|
|
47
|
+
settings: TransportSettings;
|
|
48
|
+
}
|
|
49
|
+
export interface OnSettingsUpdateErrorTopicParams {
|
|
50
|
+
original: TransportSettings;
|
|
51
|
+
settings: TransportSettings;
|
|
52
|
+
error: Error;
|
|
53
|
+
}
|
|
54
|
+
export interface ExtendedTransportSettings extends TransportSettings {
|
|
55
|
+
id: string;
|
|
56
|
+
}
|
|
57
|
+
export interface MailerSettingsContext {
|
|
58
|
+
getSettings: () => Promise<ExtendedTransportSettings | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Method should not be used outside of mailer
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
createSettings: (params: MailerSettingsCreateParams) => Promise<TransportSettings>;
|
|
64
|
+
/**
|
|
65
|
+
* Method should not be used outside of mailer
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
updateSettings: (params: MailerSettingsUpdateParams) => Promise<TransportSettings>;
|
|
69
|
+
/**
|
|
70
|
+
* Use to store the settings data.
|
|
71
|
+
*/
|
|
72
|
+
saveSettings: (params: MailerSettingsSaveParams) => Promise<TransportSettings>;
|
|
73
|
+
/**
|
|
74
|
+
* Lifecycle events
|
|
75
|
+
*/
|
|
76
|
+
onSettingsBeforeGet: Topic<OnSettingsBeforeGetTopicParams>;
|
|
77
|
+
onSettingsAfterGet: Topic<OnSettingsAfterGetTopicParams>;
|
|
78
|
+
onSettingsGetError: Topic<OnSettingsGetErrorTopicParams>;
|
|
79
|
+
onSettingsBeforeCreate: Topic<OnSettingsBeforeCreateTopicParams>;
|
|
80
|
+
onSettingsAfterCreate: Topic<OnSettingsAfterCreateTopicParams>;
|
|
81
|
+
onSettingsCreateError: Topic<OnSettingsCreateErrorTopicParams>;
|
|
82
|
+
onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;
|
|
83
|
+
onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;
|
|
84
|
+
onSettingsUpdateError: Topic<OnSettingsUpdateErrorTopicParams>;
|
|
85
|
+
}
|
|
86
|
+
export interface MailerContextObject<T extends Transport = Transport> extends MailerTransporterContext<T>, MailerSettingsContext {
|
|
87
|
+
}
|
|
88
|
+
export interface MailerContext extends CmsContext {
|
|
89
|
+
mailer: MailerContextObject;
|
|
90
|
+
}
|
|
91
|
+
export interface OnTransportBeforeSendParams {
|
|
92
|
+
data: TransportSendData;
|
|
93
|
+
transport: Transport;
|
|
94
|
+
}
|
|
95
|
+
export interface OnTransportAfterSendParams {
|
|
96
|
+
data: TransportSendData;
|
|
97
|
+
transport: Transport;
|
|
98
|
+
}
|
|
99
|
+
export interface OnTransportErrorParams {
|
|
100
|
+
error: Error;
|
|
101
|
+
data: TransportSendData;
|
|
102
|
+
transport: Transport;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Interface to implement the actual mailer.
|
|
106
|
+
*/
|
|
107
|
+
export interface TransportSendResponse<T = any> {
|
|
108
|
+
result: T | null;
|
|
109
|
+
error: {
|
|
110
|
+
message: string;
|
|
111
|
+
code: string;
|
|
112
|
+
data?: {
|
|
113
|
+
[key: string]: any;
|
|
114
|
+
};
|
|
115
|
+
} | null;
|
|
116
|
+
}
|
|
117
|
+
interface TransportSendToData {
|
|
118
|
+
to: string[];
|
|
119
|
+
}
|
|
120
|
+
interface TransportSendCcData {
|
|
121
|
+
cc: string[];
|
|
122
|
+
}
|
|
123
|
+
interface TransportSendBccData {
|
|
124
|
+
bcc: string[];
|
|
125
|
+
}
|
|
126
|
+
interface BaseTransportSendData {
|
|
127
|
+
to?: string[];
|
|
128
|
+
cc?: string[];
|
|
129
|
+
bcc?: string[];
|
|
130
|
+
from?: string;
|
|
131
|
+
subject: string;
|
|
132
|
+
text: string;
|
|
133
|
+
html?: string;
|
|
134
|
+
replyTo?: string;
|
|
135
|
+
}
|
|
136
|
+
export declare type TransportSendData = BaseTransportSendData & (TransportSendToData | TransportSendBccData | TransportSendCcData);
|
|
137
|
+
export interface Transport<T = any> {
|
|
138
|
+
name: string;
|
|
139
|
+
send: (params: TransportSendData) => Promise<TransportSendResponse<T>>;
|
|
140
|
+
}
|
|
141
|
+
export interface TransportSettings {
|
|
142
|
+
host: string;
|
|
143
|
+
user: string;
|
|
144
|
+
password: string;
|
|
145
|
+
from: string;
|
|
146
|
+
replyTo?: string;
|
|
147
|
+
}
|
|
148
|
+
export {};
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\n\nexport interface MailerTransporterContext<T extends Transport = Transport> {\n onTransportBeforeSend: Topic<OnTransportBeforeSendParams>;\n onTransportAfterSend: Topic<OnTransportAfterSendParams>;\n onTransportError: Topic<OnTransportErrorParams>;\n getTransport: () => Promise<T | null>;\n sendMail: <D>(data: TransportSendData) => Promise<TransportSendResponse<D>>;\n}\n\nexport interface MailerSettingsCreateParams {\n input: Partial<TransportSettings>;\n}\nexport interface MailerSettingsUpdateParams {\n input: Partial<TransportSettings>;\n original?: ExtendedTransportSettings | null;\n}\n\nexport interface MailerSettingsSaveParams {\n input: Partial<TransportSettings>;\n}\n\nexport interface OnSettingsBeforeGetTopicParams {\n tenant: string;\n}\n\nexport interface OnSettingsAfterGetTopicParams {\n tenant: string;\n settings: TransportSettings | null;\n}\n\nexport interface OnSettingsGetErrorTopicParams {\n tenant: string;\n error: Error;\n}\n\nexport interface OnSettingsBeforeCreateTopicParams {\n settings: TransportSettings;\n}\n\nexport interface OnSettingsAfterCreateTopicParams {\n settings: TransportSettings;\n}\n\nexport interface OnSettingsCreateErrorTopicParams {\n settings: TransportSettings;\n error: Error;\n}\n\nexport interface OnSettingsBeforeUpdateTopicParams {\n settings: TransportSettings;\n original: TransportSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n original: TransportSettings;\n settings: TransportSettings;\n}\n\nexport interface OnSettingsUpdateErrorTopicParams {\n original: TransportSettings;\n settings: TransportSettings;\n error: Error;\n}\n\nexport interface ExtendedTransportSettings extends TransportSettings {\n id: string;\n}\n\nexport interface MailerSettingsContext {\n getSettings: () => Promise<ExtendedTransportSettings | null>;\n /**\n * Method should not be used outside of mailer\n * @internal\n */\n createSettings: (params: MailerSettingsCreateParams) => Promise<TransportSettings>;\n /**\n * Method should not be used outside of mailer\n * @internal\n */\n updateSettings: (params: MailerSettingsUpdateParams) => Promise<TransportSettings>;\n /**\n * Use to store the settings data.\n */\n saveSettings: (params: MailerSettingsSaveParams) => Promise<TransportSettings>;\n /**\n * Lifecycle events\n */\n onSettingsBeforeGet: Topic<OnSettingsBeforeGetTopicParams>;\n onSettingsAfterGet: Topic<OnSettingsAfterGetTopicParams>;\n onSettingsGetError: Topic<OnSettingsGetErrorTopicParams>;\n onSettingsBeforeCreate: Topic<OnSettingsBeforeCreateTopicParams>;\n onSettingsAfterCreate: Topic<OnSettingsAfterCreateTopicParams>;\n onSettingsCreateError: Topic<OnSettingsCreateErrorTopicParams>;\n onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\n onSettingsUpdateError: Topic<OnSettingsUpdateErrorTopicParams>;\n}\n\nexport interface MailerContextObject<T extends Transport = Transport>\n extends MailerTransporterContext<T>,\n MailerSettingsContext {}\nexport interface MailerContext extends CmsContext {\n mailer: MailerContextObject;\n}\n\nexport interface OnTransportBeforeSendParams {\n data: TransportSendData;\n transport: Transport;\n}\nexport interface OnTransportAfterSendParams {\n data: TransportSendData;\n transport: Transport;\n}\nexport interface OnTransportErrorParams {\n error: Error;\n data: TransportSendData;\n transport: Transport;\n}\n\n/**\n * Interface to implement the actual mailer.\n */\nexport interface TransportSendResponse<T = any> {\n result: T | null;\n error: {\n message: string;\n code: string;\n data?: {\n [key: string]: any;\n };\n } | null;\n}\n\ninterface TransportSendToData {\n to: string[];\n}\ninterface TransportSendCcData {\n cc: string[];\n}\ninterface TransportSendBccData {\n bcc: string[];\n}\n\ninterface BaseTransportSendData {\n to?: string[];\n cc?: string[];\n bcc?: string[];\n from?: string;\n subject: string;\n text: string;\n html?: string;\n replyTo?: string;\n}\n\nexport type TransportSendData = BaseTransportSendData &\n (TransportSendToData | TransportSendBccData | TransportSendCcData);\nexport interface Transport<T = any> {\n name: string;\n send: (params: TransportSendData) => Promise<TransportSendResponse<T>>;\n}\n\nexport interface TransportSettings {\n host: string;\n user: string;\n password: string;\n from: string;\n replyTo?: string;\n}\n"],"mappings":""}
|