@pixelplex/mail-service 0.2.0 → 0.2.2
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/README.md +27 -20
- package/audit-ci.json +4 -0
- package/commitlint.config.js +27 -0
- package/dist/constants/mail.constants.d.ts +2 -1
- package/dist/constants/mail.constants.js +1 -0
- package/dist/constants/mail.constants.js.map +1 -1
- package/dist/factories/gateway.factory.js +1 -0
- package/dist/factories/gateway.factory.js.map +1 -1
- package/dist/gateways/console.gateway.js +2 -1
- package/dist/gateways/console.gateway.js.map +1 -1
- package/dist/gateways/index.d.ts +1 -0
- package/dist/gateways/index.js +1 -0
- package/dist/gateways/index.js.map +1 -1
- package/dist/gateways/sendgrid.gateway.d.ts +8 -0
- package/dist/gateways/sendgrid.gateway.js +46 -0
- package/dist/gateways/sendgrid.gateway.js.map +1 -0
- package/dist/gateways/slack.gateway.js +3 -2
- package/dist/gateways/slack.gateway.js.map +1 -1
- package/dist/gateways/smtp.gateway.js +2 -1
- package/dist/gateways/smtp.gateway.js.map +1 -1
- package/dist/mail.module.js +2 -1
- package/dist/mail.module.js.map +1 -1
- package/dist/services/mail-sender.service.d.ts +2 -2
- package/dist/services/mail-sender.service.js +21 -13
- package/dist/services/mail-sender.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.types.d.ts +4 -1
- package/dist/types/sendgrid-options.types.d.ts +4 -0
- package/dist/types/sendgrid-options.types.js +3 -0
- package/dist/types/sendgrid-options.types.js.map +1 -0
- package/dist/types/slack-options.types.d.ts +1 -1
- package/dist/types/templates.types.d.ts +5 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/object.utils.d.ts +1 -0
- package/dist/utils/object.utils.js +8 -0
- package/dist/utils/object.utils.js.map +1 -0
- package/package.json +33 -15
- package/.husky/pre-commit +0 -9
package/README.md
CHANGED
|
@@ -8,9 +8,16 @@ The sends messages them via email.
|
|
|
8
8
|
|
|
9
9
|
1. create template for html, plain text and subject
|
|
10
10
|
2. add `@pixelplex/mail-service` to your application
|
|
11
|
-
3. Call `MailModule.
|
|
12
|
-
with specified gateways
|
|
13
|
-
4. send a message by calling `this.mailSenderService.sendEmail('test@gmail.com', {
|
|
11
|
+
3. Call `MailModule.forRoot` from `@pixelplex/mail-service`
|
|
12
|
+
with specified gateways and options
|
|
13
|
+
4. send a message by calling `this.mailSenderService.sendEmail('test@gmail.com', { htmlPath: htmlTemplatePath, plainPath: plainTextTemplatePath, subjectPath: subjectTemplatePath }, {year: 20});` where `mailSenderService` is `MailSenderService`
|
|
14
|
+
|
|
15
|
+
Currently supported gateways:
|
|
16
|
+
|
|
17
|
+
- slack
|
|
18
|
+
- console
|
|
19
|
+
- smtp
|
|
20
|
+
- sendgrid
|
|
14
21
|
|
|
15
22
|
Didn't understand anything? Okay, let's see more details
|
|
16
23
|
|
|
@@ -21,10 +28,8 @@ The service uses Handlebars as template engine. So all your email templates shou
|
|
|
21
28
|
For sending message your templates folder should include this files:
|
|
22
29
|
|
|
23
30
|
- `{name}.handlebars` - body of your email where `{name}` is just your template name for email. For example `welcome.handlebars` for the welcome use email
|
|
24
|
-
- `{name}.subject.handlebars` - subject (title) of your email
|
|
25
|
-
- `{name}.plain.handlebars` - subject (title) of your email
|
|
26
|
-
|
|
27
|
-
Use provided naming convention
|
|
31
|
+
- `{name}.subject.handlebars` - subject (title) of your email. You can use subject field to specify subject directly. It will override subjectPath
|
|
32
|
+
- `{name}.plain.handlebars` - subject (title) of your email. You can use plain field to specify plain directly. It will override plainPath
|
|
28
33
|
|
|
29
34
|
```handlebars
|
|
30
35
|
# welcome.subject.handlebars Welcome, {{name}}! This is subject
|
|
@@ -56,16 +61,17 @@ Use provided naming convention
|
|
|
56
61
|
|
|
57
62
|
## Configuration
|
|
58
63
|
|
|
59
|
-
| Name
|
|
60
|
-
|
|
|
61
|
-
| gateways
|
|
62
|
-
| customGateways
|
|
63
|
-
| smtp.host
|
|
64
|
-
| smtp.port
|
|
65
|
-
| smtp.username
|
|
66
|
-
| smtp.password
|
|
67
|
-
|
|
|
68
|
-
| slack.url
|
|
64
|
+
| Name | Description | Example |
|
|
65
|
+
| --------------- | -------------------------------------------------------- | ------------------------- |
|
|
66
|
+
| gateways | Array of gateways to send email | `['slack']` |
|
|
67
|
+
| customGateways | Array of custom gateways classes | `[CustomGateway]` |
|
|
68
|
+
| smtp.host | Mail gateway host address | `smtp.gmail.com` |
|
|
69
|
+
| smtp.port | Mail gateway port number | `586` |
|
|
70
|
+
| smtp.username | Mail gateway username | `username` |
|
|
71
|
+
| smtp.password | Mail gateway password | `qh05780c2qcm034579` |
|
|
72
|
+
| \*.sender | Mail sender address | `postmail@pixelplex.io` |
|
|
73
|
+
| slack.url | Hook URL in case you want to duplicate messages to Slack | `https://hooks.slack.com` |
|
|
74
|
+
| sendgrid.apiKey | Sendgrid api key | `oiqur9823uiofhaoafoe` |
|
|
69
75
|
|
|
70
76
|
### Trigger new message sending
|
|
71
77
|
|
|
@@ -106,8 +112,7 @@ export class AppModule {}
|
|
|
106
112
|
|
|
107
113
|
```typescript
|
|
108
114
|
import { Injectable } from '@nestjs/common';
|
|
109
|
-
import {
|
|
110
|
-
import { MailSenderService } from './mail-sender.service';
|
|
115
|
+
import { MailSenderService } from '@pixelplex/mail-service';
|
|
111
116
|
|
|
112
117
|
@Injectable()
|
|
113
118
|
export class AppService {
|
|
@@ -116,7 +121,9 @@ export class AppService {
|
|
|
116
121
|
async onModuleInit() {
|
|
117
122
|
this.mailSenderService.sendEmail(
|
|
118
123
|
'test@gmail.com',
|
|
119
|
-
|
|
124
|
+
// additionaly you can use plain: plainText, subject: subjectText to specify plain or subject directly
|
|
125
|
+
// if so, plainPath or subjectPath will be ignored
|
|
126
|
+
{ htmlPath: htmlTemplatePath, plainPath: plainTextTemplatePath, subjectPath: subjectTemplatePath },
|
|
120
127
|
{ year: 20 },
|
|
121
128
|
);
|
|
122
129
|
}
|
package/audit-ci.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['@commitlint/config-conventional'],
|
|
3
|
+
rules: {
|
|
4
|
+
'body-leading-blank': [2, 'always'],
|
|
5
|
+
'footer-leading-blank': [2, 'always'],
|
|
6
|
+
'jira-issue-in-scope': [2, 'always'],
|
|
7
|
+
},
|
|
8
|
+
plugins: [
|
|
9
|
+
{
|
|
10
|
+
rules: {
|
|
11
|
+
'jira-issue-in-scope': ({ scope }) => {
|
|
12
|
+
return [
|
|
13
|
+
scope && scope.match(/\b([A-Z]{1,10}-\d+(, ?[A-Z]{1,10}-\d+)*|HOTFIX|VERSION)\b/),
|
|
14
|
+
'scope should contain a JIRA issue number. Something like this - "KEY-20", "KEY-20, KEY-21", "HOTFIX" or "VERSION"',
|
|
15
|
+
];
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
prompt: {
|
|
21
|
+
questions: {
|
|
22
|
+
scope: {
|
|
23
|
+
description: 'What is the scope of this change (JIRA issue number like KEY-20)',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail.constants.js","sourceRoot":"","sources":["../../src/constants/mail.constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,uDAA8B,CAAA;IAC9B,iEAAwC,CAAA;IACxC,mEAA0C,CAAA;AAC5C,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"mail.constants.js","sourceRoot":"","sources":["../../src/constants/mail.constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,uDAA8B,CAAA;IAC9B,iEAAwC,CAAA;IACxC,mEAA0C,CAAA;AAC5C,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAED,IAAY,OAKX;AALD,WAAY,OAAO;IACjB,wBAAa,CAAA;IACb,0BAAe,CAAA;IACf,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;AACvB,CAAC,EALW,OAAO,uBAAP,OAAO,QAKlB"}
|
|
@@ -9,6 +9,7 @@ class GatewayFactory {
|
|
|
9
9
|
[constants_1.GATEWAY.SLACK]: gateways_1.SlackGateway,
|
|
10
10
|
[constants_1.GATEWAY.CONSOLE]: gateways_1.ConsoleGateway,
|
|
11
11
|
[constants_1.GATEWAY.SMTP]: gateways_1.SmtpGateway,
|
|
12
|
+
[constants_1.GATEWAY.SENDGRID]: gateways_1.SendgridGateway,
|
|
12
13
|
};
|
|
13
14
|
return gateways[gateway];
|
|
14
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.factory.js","sourceRoot":"","sources":["../../src/factories/gateway.factory.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"gateway.factory.js","sourceRoot":"","sources":["../../src/factories/gateway.factory.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AACvC,0CAAyF;AAGzF,MAAa,cAAc;IACzB,MAAM,CAAC,UAAU,CAAC,OAAgB;QAChC,MAAM,QAAQ,GAAG;YACf,CAAC,mBAAO,CAAC,KAAK,CAAC,EAAE,uBAAY;YAC7B,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,yBAAc;YACjC,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE,sBAAW;YAC3B,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,0BAAe;SACpC,CAAC;QAEF,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAXD,wCAWC"}
|
|
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ConsoleGateway = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
-
let ConsoleGateway =
|
|
11
|
+
let ConsoleGateway = class ConsoleGateway {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.logger = new common_1.Logger('Mail::ConsoleGateway');
|
|
14
14
|
}
|
|
@@ -18,6 +18,7 @@ let ConsoleGateway = exports.ConsoleGateway = class ConsoleGateway {
|
|
|
18
18
|
return Promise.resolve();
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
+
exports.ConsoleGateway = ConsoleGateway;
|
|
21
22
|
exports.ConsoleGateway = ConsoleGateway = __decorate([
|
|
22
23
|
(0, common_1.Injectable)()
|
|
23
24
|
], ConsoleGateway);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.gateway.js","sourceRoot":"","sources":["../../src/gateways/console.gateway.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AAM7C,IAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"console.gateway.js","sourceRoot":"","sources":["../../src/gateways/console.gateway.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AAM7C,IAAM,cAAc,GAApB,MAAM,cAAc;IAApB;QACY,WAAM,GAAW,IAAI,eAAM,CAAC,sBAAsB,CAAC,CAAC;IAOvE,CAAC;IALC,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,IAAI,GAAG,eAAe,EAAE,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AARY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAQ1B"}
|
package/dist/gateways/index.d.ts
CHANGED
package/dist/gateways/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./console.gateway"), exports);
|
|
18
|
+
__exportStar(require("./sendgrid.gateway"), exports);
|
|
18
19
|
__exportStar(require("./slack.gateway"), exports);
|
|
19
20
|
__exportStar(require("./smtp.gateway"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateways/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gateways/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,iDAA+B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IGateway } from '../interfaces';
|
|
2
|
+
import { Content, SendgridOptions } from '../types';
|
|
3
|
+
export declare class SendgridGateway implements IGateway {
|
|
4
|
+
private readonly sendgridOptions;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(sendgridOptions: SendgridOptions);
|
|
7
|
+
send(to: string, content: Content): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SendgridGateway = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const mail_1 = __importDefault(require("@sendgrid/mail"));
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
const decorators_1 = require("../decorators");
|
|
23
|
+
let SendgridGateway = class SendgridGateway {
|
|
24
|
+
constructor(sendgridOptions) {
|
|
25
|
+
this.sendgridOptions = sendgridOptions;
|
|
26
|
+
this.logger = new common_1.Logger('Mail::SendgridGateway');
|
|
27
|
+
mail_1.default.setApiKey(sendgridOptions.apiKey);
|
|
28
|
+
}
|
|
29
|
+
async send(to, content) {
|
|
30
|
+
await mail_1.default.send({
|
|
31
|
+
to,
|
|
32
|
+
from: this.sendgridOptions.sender,
|
|
33
|
+
subject: content.subject,
|
|
34
|
+
html: content.html,
|
|
35
|
+
text: content.plain,
|
|
36
|
+
});
|
|
37
|
+
this.logger.debug(`Message to ${to} sent with sendgrid`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.SendgridGateway = SendgridGateway;
|
|
41
|
+
exports.SendgridGateway = SendgridGateway = __decorate([
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
|
+
__param(0, (0, decorators_1.InjectGatewayOptions)(constants_1.GATEWAY.SENDGRID)),
|
|
44
|
+
__metadata("design:paramtypes", [Object])
|
|
45
|
+
], SendgridGateway);
|
|
46
|
+
//# sourceMappingURL=sendgrid.gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendgrid.gateway.js","sourceRoot":"","sources":["../../src/gateways/sendgrid.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAoC;AAEpC,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,eAAe,GAArB,MAAM,eAAe;IAG1B,YAAoD,eAAiD;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QAFpF,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAuB,CAAC,CAAC;QAG5D,cAAM,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,cAAM,CAAC,IAAI,CAAC;YAChB,EAAE;YACF,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM;YACjC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;IAC3D,CAAC;CACF,CAAA;AAlBY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,iCAAoB,EAAC,mBAAO,CAAC,QAAQ,CAAC,CAAA;;GAHxC,eAAe,CAkB3B"}
|
|
@@ -20,7 +20,7 @@ const common_1 = require("@nestjs/common");
|
|
|
20
20
|
const axios_1 = __importDefault(require("axios"));
|
|
21
21
|
const constants_1 = require("../constants");
|
|
22
22
|
const decorators_1 = require("../decorators");
|
|
23
|
-
let SlackGateway =
|
|
23
|
+
let SlackGateway = class SlackGateway {
|
|
24
24
|
constructor(slackOption) {
|
|
25
25
|
this.slackOption = slackOption;
|
|
26
26
|
this.logger = new common_1.Logger('Mail::SlackGateway');
|
|
@@ -29,9 +29,10 @@ let SlackGateway = exports.SlackGateway = class SlackGateway {
|
|
|
29
29
|
const text = `Message for ${to}: \n${content.plain}`;
|
|
30
30
|
const slackUrl = new URL(this.slackOption.url, 'https://hooks.slack.com');
|
|
31
31
|
await axios_1.default.post(slackUrl.href, { text });
|
|
32
|
-
this.logger.debug(
|
|
32
|
+
this.logger.debug(`Slack message to ${to} sent`);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
+
exports.SlackGateway = SlackGateway;
|
|
35
36
|
exports.SlackGateway = SlackGateway = __decorate([
|
|
36
37
|
(0, common_1.Injectable)(),
|
|
37
38
|
__param(0, (0, decorators_1.InjectGatewayOptions)(constants_1.GATEWAY.SLACK)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slack.gateway.js","sourceRoot":"","sources":["../../src/gateways/slack.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,kDAA0B;AAE1B,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"slack.gateway.js","sourceRoot":"","sources":["../../src/gateways/slack.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,kDAA0B;AAE1B,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGvB,YAAiD,WAA0C;QAAzB,gBAAW,GAAX,WAAW,CAAc;QAF1E,WAAM,GAAW,IAAI,eAAM,CAAC,oBAAoB,CAAC,CAAC;IAE2B,CAAC;IAE/F,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,IAAI,GAAG,eAAe,EAAE,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;QAC1E,MAAM,eAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AAXY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,iCAAoB,EAAC,mBAAO,CAAC,KAAK,CAAC,CAAA;;GAHrC,YAAY,CAWxB"}
|
|
@@ -17,7 +17,7 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const nodemailer_1 = require("nodemailer");
|
|
18
18
|
const constants_1 = require("../constants");
|
|
19
19
|
const decorators_1 = require("../decorators");
|
|
20
|
-
let SmtpGateway =
|
|
20
|
+
let SmtpGateway = class SmtpGateway {
|
|
21
21
|
constructor(smtpOptions) {
|
|
22
22
|
this.smtpOptions = smtpOptions;
|
|
23
23
|
this.logger = new common_1.Logger('Mail::SmtpGateway');
|
|
@@ -35,6 +35,7 @@ let SmtpGateway = exports.SmtpGateway = class SmtpGateway {
|
|
|
35
35
|
this.logger.debug(`Message sent: ${info.messageId}, ${info.response}`);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
exports.SmtpGateway = SmtpGateway;
|
|
38
39
|
exports.SmtpGateway = SmtpGateway = __decorate([
|
|
39
40
|
(0, common_1.Injectable)(),
|
|
40
41
|
__param(0, (0, decorators_1.InjectGatewayOptions)(constants_1.GATEWAY.SMTP)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smtp.gateway.js","sourceRoot":"","sources":["../../src/gateways/smtp.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,2CAA2E;AAE3E,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"smtp.gateway.js","sourceRoot":"","sources":["../../src/gateways/smtp.gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,2CAA2E;AAE3E,4CAAuC;AACvC,8CAAqD;AAK9C,IAAM,WAAW,GAAjB,MAAM,WAAW;IAItB,YAAgD,WAAyC;QAAxB,gBAAW,GAAX,WAAW,CAAa;QAHxE,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;QAIxD,IAAI,CAAC,WAAW,GAAG,IAAA,4BAAe,EAAC;YACjC,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,IAAI,EAAE;gBACJ,IAAI,EAAE,WAAW,CAAC,QAAQ;gBAC1B,IAAI,EAAE,WAAW,CAAC,QAAQ;aAC3B;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAgB;QACrC,MAAM,IAAI,GAAoB,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,+BAC3D,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,EAC7B,EAAE,IACC,OAAO,KACV,IAAI,EAAE,OAAO,CAAC,KAAK,IACnB,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;CACF,CAAA;AAzBY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAKE,WAAA,IAAA,iCAAoB,EAAC,mBAAO,CAAC,IAAI,CAAC,CAAA;;GAJpC,WAAW,CAyBvB"}
|
package/dist/mail.module.js
CHANGED
|
@@ -35,7 +35,7 @@ const common_1 = require("@nestjs/common");
|
|
|
35
35
|
const factories_1 = require("./factories");
|
|
36
36
|
const Services = __importStar(require("./services"));
|
|
37
37
|
const utils_1 = require("./utils");
|
|
38
|
-
let MailModule =
|
|
38
|
+
let MailModule = MailModule_1 = class MailModule {
|
|
39
39
|
static forRoot(options, connection) {
|
|
40
40
|
const mailOptionsProvider = {
|
|
41
41
|
provide: (0, utils_1.getMailOptionsToken)(connection),
|
|
@@ -62,6 +62,7 @@ let MailModule = exports.MailModule = MailModule_1 = class MailModule {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
+
exports.MailModule = MailModule;
|
|
65
66
|
exports.MailModule = MailModule = MailModule_1 = __decorate([
|
|
66
67
|
(0, common_1.Module)({})
|
|
67
68
|
], MailModule);
|
package/dist/mail.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail.module.js","sourceRoot":"","sources":["../src/mail.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAiE;AAEjE,2CAA6C;AAC7C,qDAAuC;AAEvC,mCAAwF;AAGjF,IAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"mail.module.js","sourceRoot":"","sources":["../src/mail.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAiE;AAEjE,2CAA6C;AAC7C,qDAAuC;AAEvC,mCAAwF;AAGjF,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAmC,OAA8B,EAAE,UAAmB;QAClG,MAAM,mBAAmB,GAAa;YACpC,OAAO,EAAE,IAAA,2BAAmB,EAAC,UAAU,CAAC;YACxC,QAAQ,EAAE,OAAO;SAClB,CAAC;QAEF,MAAM,uBAAuB,GAAe,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC7E,OAAO,EAAE,IAAA,8BAAsB,EAAC,OAAO,EAAE,UAAU,CAAC;YACpD,QAAQ,EAAG,OAAe,CAAC,OAAO,CAAC;SACpC,CAAC,CAAC,CAAC;QAEJ,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,0BAAc,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;QAEvF,IAAI,OAAO,CAAC,cAAc,EAAE;YAC1B,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;SAC1C;QAED,MAAM,wBAAwB,GAAa;YACzC,OAAO,EAAE,IAAA,wBAAgB,EAAC,UAAU,CAAC;YACrC,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI;YAC7B,MAAM,EAAE,QAAQ;SACjB,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,SAAS,EAAE,CAAC,mBAAmB,EAAE,wBAAwB,EAAE,GAAG,uBAAuB,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC;YAChH,OAAO,EAAE,QAAQ;SAClB,CAAC;IACJ,CAAC;CACF,CAAA;AA/BY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CA+BtB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IGateway } from '../interfaces';
|
|
2
|
-
import {
|
|
2
|
+
import { TemplatePathsOrContent } from '../types';
|
|
3
3
|
export declare class MailSenderService {
|
|
4
4
|
private readonly gateways;
|
|
5
5
|
private readonly templateDelegatesCache;
|
|
6
6
|
constructor(gateways: IGateway[]);
|
|
7
|
-
sendEmail(to: string,
|
|
7
|
+
sendEmail(to: string, templatePathsOrContent: TemplatePathsOrContent, context?: Record<string, any>): Promise<void>;
|
|
8
8
|
private compileAllTemplates;
|
|
9
9
|
private getTemplateDelegate;
|
|
10
10
|
private compileTemplate;
|
|
@@ -40,25 +40,32 @@ const node_fs_1 = require("node:fs");
|
|
|
40
40
|
const common_1 = require("@nestjs/common");
|
|
41
41
|
const handlebars = __importStar(require("handlebars"));
|
|
42
42
|
const decorators_1 = require("../decorators");
|
|
43
|
-
|
|
43
|
+
const utils_1 = require("../utils");
|
|
44
|
+
let MailSenderService = class MailSenderService {
|
|
44
45
|
constructor(gateways) {
|
|
45
46
|
this.gateways = gateways;
|
|
46
47
|
this.templateDelegatesCache = new Map();
|
|
47
48
|
}
|
|
48
|
-
async sendEmail(to,
|
|
49
|
-
const content = await this.compileAllTemplates(
|
|
49
|
+
async sendEmail(to, templatePathsOrContent, context) {
|
|
50
|
+
const content = await this.compileAllTemplates(templatePathsOrContent, context);
|
|
50
51
|
await Promise.all(this.gateways.map(async (gateway) => gateway.send(to, content)));
|
|
51
52
|
}
|
|
52
|
-
async compileAllTemplates(
|
|
53
|
-
const content = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
content
|
|
61
|
-
}
|
|
53
|
+
async compileAllTemplates(templatePathsOrContent, context) {
|
|
54
|
+
const content = {
|
|
55
|
+
html: await this.compileTemplate(templatePathsOrContent.htmlPath, context),
|
|
56
|
+
};
|
|
57
|
+
if ((0, utils_1.isDefined)(templatePathsOrContent.subject)) {
|
|
58
|
+
content.subject = templatePathsOrContent.subject;
|
|
59
|
+
}
|
|
60
|
+
else if ((0, utils_1.isDefined)(templatePathsOrContent.subjectPath)) {
|
|
61
|
+
content.subject = await this.compileTemplate(templatePathsOrContent.subjectPath, context);
|
|
62
|
+
}
|
|
63
|
+
if ((0, utils_1.isDefined)(templatePathsOrContent.plain)) {
|
|
64
|
+
content.plain = templatePathsOrContent.plain;
|
|
65
|
+
}
|
|
66
|
+
else if ((0, utils_1.isDefined)(templatePathsOrContent.plainPath)) {
|
|
67
|
+
content.plain = await this.compileTemplate(templatePathsOrContent.plainPath, context);
|
|
68
|
+
}
|
|
62
69
|
return content;
|
|
63
70
|
}
|
|
64
71
|
async getTemplateDelegate(templatePath) {
|
|
@@ -76,6 +83,7 @@ let MailSenderService = exports.MailSenderService = class MailSenderService {
|
|
|
76
83
|
return templateDelegate(context);
|
|
77
84
|
}
|
|
78
85
|
};
|
|
86
|
+
exports.MailSenderService = MailSenderService;
|
|
79
87
|
exports.MailSenderService = MailSenderService = __decorate([
|
|
80
88
|
(0, common_1.Injectable)(),
|
|
81
89
|
__param(0, (0, decorators_1.InjectGateways)()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail-sender.service.js","sourceRoot":"","sources":["../../src/services/mail-sender.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyC;AAEzC,2CAA4C;AAC5C,uDAAyC;AAEzC,8CAA+C;
|
|
1
|
+
{"version":3,"file":"mail-sender.service.js","sourceRoot":"","sources":["../../src/services/mail-sender.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyC;AAEzC,2CAA4C;AAC5C,uDAAyC;AAEzC,8CAA+C;AAG/C,oCAAqC;AAG9B,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAE5B,YAA8B,QAAqC;QAApB,aAAQ,GAAR,QAAQ,CAAY;QADlD,2BAAsB,GAAG,IAAI,GAAG,EAAsC,CAAC;IAClB,CAAC;IAEhE,KAAK,CAAC,SAAS,CACpB,EAAU,EACV,sBAA8C,EAC9C,OAA6B;QAE7B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;QAChF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACrF,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,sBAA8C,EAC9C,OAA6B;QAE7B,MAAM,OAAO,GAAY;YACvB,IAAI,EAAE,MAAM,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC;SAC3E,CAAC;QAEF,IAAI,IAAA,iBAAS,EAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE;YAC7C,OAAO,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC;SAClD;aAAM,IAAI,IAAA,iBAAS,EAAC,sBAAsB,CAAC,WAAW,CAAC,EAAE;YACxD,OAAO,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SAC3F;QAED,IAAI,IAAA,iBAAS,EAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE;YAC3C,OAAO,CAAC,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC;SAC9C;aAAM,IAAI,IAAA,iBAAS,EAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE;YACtD,OAAO,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACvF;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAAC,YAAoB;QACpD,MAAM,uBAAuB,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC9E,IAAI,uBAAuB,EAAE;YAC3B,OAAO,uBAAuB,CAAC;SAChC;QAED,MAAM,QAAQ,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC1D,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;QAChE,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,YAAoB,EAAE,UAA+B,EAAE;QACnF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;QACtE,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACF,CAAA;AApDY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAGE,WAAA,IAAA,2BAAc,GAAE,CAAA;;GAFlB,iBAAiB,CAoD7B"}
|