@qccareerschool/winston-nodemailer 3.0.0 → 4.0.0
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/.env.example +6 -0
- package/dist/index.d.ts +0 -6
- package/dist/index.js +21 -12
- package/dist/index.spec.d.ts +1 -0
- package/dist/index.spec.js +57 -0
- package/package.json +16 -13
- package/src/index.spec.ts +58 -0
- package/src/index.ts +21 -14
package/.env.example
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -26,12 +26,6 @@ export declare class NodemailerTransport extends Transport {
|
|
|
26
26
|
constructor(opts: INodemailerOptions);
|
|
27
27
|
/**
|
|
28
28
|
* log data
|
|
29
|
-
*
|
|
30
|
-
* @param {String} level
|
|
31
|
-
* @param {String} msg
|
|
32
|
-
* @param {Object} meta
|
|
33
|
-
* @param {Function} cb
|
|
34
|
-
*
|
|
35
29
|
*/
|
|
36
30
|
log(info: any, next: () => void): any;
|
|
37
31
|
}
|
package/dist/index.js
CHANGED
|
@@ -48,12 +48,6 @@ var NodemailerTransport = /** @class */ (function (_super) {
|
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* log data
|
|
51
|
-
*
|
|
52
|
-
* @param {String} level
|
|
53
|
-
* @param {String} msg
|
|
54
|
-
* @param {Object} meta
|
|
55
|
-
* @param {Function} cb
|
|
56
|
-
*
|
|
57
51
|
*/
|
|
58
52
|
NodemailerTransport.prototype.log = function (info, next) {
|
|
59
53
|
if (this.silent) {
|
|
@@ -62,13 +56,28 @@ var NodemailerTransport = /** @class */ (function (_super) {
|
|
|
62
56
|
if (this.filter && !this.filter(info)) {
|
|
63
57
|
return next();
|
|
64
58
|
}
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
var text;
|
|
60
|
+
if (typeof info.message === 'undefined') {
|
|
61
|
+
text = 'undefined';
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
else if (typeof info.message === 'string') {
|
|
64
|
+
text = info.message;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
text = util.inspect(info.message);
|
|
68
|
+
}
|
|
69
|
+
var subject = (this.tags || '') + ("[" + info.level + "] ") + text.slice(0, 51);
|
|
70
|
+
var meta = {};
|
|
71
|
+
var hasMeta = false;
|
|
72
|
+
for (var _i = 0, _a = Object.keys(info); _i < _a.length; _i++) {
|
|
73
|
+
var key = _a[_i];
|
|
74
|
+
if (key !== 'message' && key !== 'level') {
|
|
75
|
+
meta[key] = info[key];
|
|
76
|
+
hasMeta = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (hasMeta) {
|
|
80
|
+
text += '\n---\n' + util.inspect(meta);
|
|
72
81
|
}
|
|
73
82
|
this.smtpTransport.sendMail({
|
|
74
83
|
from: this.from,
|
package/dist/index.spec.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.spec.js
CHANGED
|
@@ -1 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
|
+
if (mod && mod.__esModule) return mod;
|
|
4
|
+
var result = {};
|
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
+
result["default"] = mod;
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
var dotenv = __importStar(require("dotenv"));
|
|
11
|
+
var winston = __importStar(require("winston"));
|
|
12
|
+
var index_1 = require("./index");
|
|
13
|
+
dotenv.config();
|
|
14
|
+
if (typeof process.env.EMAIL_USERNAME === 'undefined') {
|
|
15
|
+
throw new Error('EMAIL_USERNAME not specified in .env file');
|
|
16
|
+
}
|
|
17
|
+
var username = process.env.EMAIL_USERNAME;
|
|
18
|
+
if (typeof process.env.EMAIL_PASSWORD === 'undefined') {
|
|
19
|
+
throw new Error('EMAIL_PASSWORD not specified in .env file');
|
|
20
|
+
}
|
|
21
|
+
var password = process.env.EMAIL_PASSWORD;
|
|
22
|
+
if (typeof process.env.EMAIL_HOST === 'undefined') {
|
|
23
|
+
throw new Error('EMAIL_HOST not specified in .env file');
|
|
24
|
+
}
|
|
25
|
+
var host = process.env.EMAIL_HOST;
|
|
26
|
+
if (typeof process.env.EMAIL_TO === 'undefined') {
|
|
27
|
+
throw new Error('EMAIL_TO not specified in .env file');
|
|
28
|
+
}
|
|
29
|
+
var to = process.env.EMAIL_TO;
|
|
30
|
+
if (typeof process.env.EMAIL_FROM === 'undefined') {
|
|
31
|
+
throw new Error('EMAIL_FROM not specified in .env file');
|
|
32
|
+
}
|
|
33
|
+
var from = process.env.EMAIL_FROM;
|
|
34
|
+
var logger = winston.createLogger({
|
|
35
|
+
levels: winston.config.syslog.levels,
|
|
36
|
+
transports: [
|
|
37
|
+
new index_1.NodemailerTransport({
|
|
38
|
+
auth: {
|
|
39
|
+
pass: password,
|
|
40
|
+
user: username,
|
|
41
|
+
},
|
|
42
|
+
filter: function (_a) {
|
|
43
|
+
var level = _a.level, message = _a.message, meta = _a.meta;
|
|
44
|
+
return level === 'error' || level === 'crit' || level === 'alert' || level === 'emerg';
|
|
45
|
+
},
|
|
46
|
+
format: winston.format.simple(),
|
|
47
|
+
from: from,
|
|
48
|
+
host: host,
|
|
49
|
+
port: 587,
|
|
50
|
+
secure: false,
|
|
51
|
+
tags: ['test'],
|
|
52
|
+
to: to,
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
var object = { x: [1, 2, 3], y: true, z: 32, q: { a: 1, b: 'two', c: null } };
|
|
57
|
+
logger.crit('this should get logged with additional data', object);
|
|
58
|
+
logger.crit(object);
|
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qccareerschool/winston-nodemailer",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "An email transport for winston
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "An email transport for winston v3 using nodemailer written in typescript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "node dist/index.spec.js"
|
|
9
9
|
},
|
|
10
10
|
"author": "Dave Welsh",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@types/chai": "^4.
|
|
13
|
+
"@types/chai": "^4.2.10",
|
|
14
|
+
"@types/dotenv": "^4.0.3",
|
|
14
15
|
"@types/mocha": "^2.2.48",
|
|
15
|
-
"chai": "^4.
|
|
16
|
+
"chai": "^4.2.0",
|
|
17
|
+
"dotenv": "^6.2.0",
|
|
16
18
|
"mocha": "^5.2.0",
|
|
17
|
-
"tslint": "^
|
|
18
|
-
"typescript": "^
|
|
19
|
-
"winston": "^3.
|
|
19
|
+
"tslint": "^6.0.0",
|
|
20
|
+
"typescript": "^3.8.3",
|
|
21
|
+
"winston": "^3.2.1"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@types/node": "^9.
|
|
23
|
-
"@types/nodemailer": "^4.6.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"@types/node": "^13.9.0",
|
|
25
|
+
"@types/nodemailer": "^4.6.8",
|
|
26
|
+
"@types/winston": "^2.4.4",
|
|
27
|
+
"nodemailer": "^6.4.4",
|
|
28
|
+
"winston-transport": "^4.3.0"
|
|
26
29
|
},
|
|
27
30
|
"peerDependencies": {
|
|
28
|
-
"winston": "^3.
|
|
31
|
+
"winston": "^3.2.1"
|
|
29
32
|
}
|
|
30
33
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import * as winston from 'winston';
|
|
3
|
+
import { NodemailerTransport } from './index';
|
|
4
|
+
|
|
5
|
+
dotenv.config();
|
|
6
|
+
|
|
7
|
+
if (typeof process.env.EMAIL_USERNAME === 'undefined') {
|
|
8
|
+
throw new Error('EMAIL_USERNAME not specified in .env file');
|
|
9
|
+
}
|
|
10
|
+
const username = process.env.EMAIL_USERNAME;
|
|
11
|
+
|
|
12
|
+
if (typeof process.env.EMAIL_PASSWORD === 'undefined') {
|
|
13
|
+
throw new Error('EMAIL_PASSWORD not specified in .env file');
|
|
14
|
+
}
|
|
15
|
+
const password = process.env.EMAIL_PASSWORD;
|
|
16
|
+
|
|
17
|
+
if (typeof process.env.EMAIL_HOST === 'undefined') {
|
|
18
|
+
throw new Error('EMAIL_HOST not specified in .env file');
|
|
19
|
+
}
|
|
20
|
+
const host = process.env.EMAIL_HOST;
|
|
21
|
+
|
|
22
|
+
if (typeof process.env.EMAIL_TO === 'undefined') {
|
|
23
|
+
throw new Error('EMAIL_TO not specified in .env file');
|
|
24
|
+
}
|
|
25
|
+
const to = process.env.EMAIL_TO;
|
|
26
|
+
|
|
27
|
+
if (typeof process.env.EMAIL_FROM === 'undefined') {
|
|
28
|
+
throw new Error('EMAIL_FROM not specified in .env file');
|
|
29
|
+
}
|
|
30
|
+
const from = process.env.EMAIL_FROM;
|
|
31
|
+
|
|
32
|
+
const logger = winston.createLogger({
|
|
33
|
+
levels: winston.config.syslog.levels,
|
|
34
|
+
transports: [
|
|
35
|
+
new NodemailerTransport({
|
|
36
|
+
auth: {
|
|
37
|
+
pass: password,
|
|
38
|
+
user: username,
|
|
39
|
+
},
|
|
40
|
+
filter: ({ level, message, meta }: any) => {
|
|
41
|
+
return level === 'error' || level === 'crit' || level === 'alert' || level === 'emerg';
|
|
42
|
+
},
|
|
43
|
+
format: winston.format.simple(),
|
|
44
|
+
from,
|
|
45
|
+
host,
|
|
46
|
+
port: 587,
|
|
47
|
+
secure: false,
|
|
48
|
+
tags: [ 'test' ],
|
|
49
|
+
to,
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const object = { x: [ 1, 2, 3 ], y: true, z: 32, q: { a: 1, b: 'two', c: null } };
|
|
55
|
+
|
|
56
|
+
logger.crit('this should get logged with additional data', object);
|
|
57
|
+
|
|
58
|
+
logger.crit(object);
|
package/src/index.ts
CHANGED
|
@@ -13,14 +13,14 @@ export interface INodemailerOptions extends Transport.TransportStreamOptions {
|
|
|
13
13
|
port: number;
|
|
14
14
|
secure: boolean;
|
|
15
15
|
tags?: string[];
|
|
16
|
-
to: string | Address |
|
|
16
|
+
to: string | Address | (string | Address)[];
|
|
17
17
|
filter?: (obj: { level: string; message: any; meta: any }) => boolean;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class NodemailerTransport extends Transport {
|
|
21
21
|
|
|
22
22
|
private from?: string | Address;
|
|
23
|
-
private to?: string | Address |
|
|
23
|
+
private to?: string | Address | (string | Address)[];
|
|
24
24
|
|
|
25
25
|
private tags?: string;
|
|
26
26
|
private filter?: (obj: { level: string; message: any; meta: any }) => boolean;
|
|
@@ -52,12 +52,6 @@ export class NodemailerTransport extends Transport {
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* log data
|
|
55
|
-
*
|
|
56
|
-
* @param {String} level
|
|
57
|
-
* @param {String} msg
|
|
58
|
-
* @param {Object} meta
|
|
59
|
-
* @param {Function} cb
|
|
60
|
-
*
|
|
61
55
|
*/
|
|
62
56
|
public log(info: any, next: () => void): any {
|
|
63
57
|
if (this.silent) {
|
|
@@ -68,15 +62,28 @@ export class NodemailerTransport extends Transport {
|
|
|
68
62
|
return next();
|
|
69
63
|
}
|
|
70
64
|
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
let text: string;
|
|
66
|
+
if (typeof info.message === 'undefined') {
|
|
67
|
+
text = 'undefined';
|
|
68
|
+
} else if (typeof info.message === 'string') {
|
|
69
|
+
text = info.message;
|
|
70
|
+
} else {
|
|
71
|
+
text = util.inspect(info.message);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
const subject = '' + (this.tags || '') + `[${info.level}] ` + text.slice(0, 51);
|
|
74
|
+
const subject = (this.tags || '') + `[${info.level}] ` + text.slice(0, 51);
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const meta: any = {};
|
|
77
|
+
let hasMeta = false;
|
|
78
|
+
for (const key of Object.keys(info)) {
|
|
79
|
+
if (key !== 'message' && key !== 'level') {
|
|
80
|
+
meta[key] = info[key];
|
|
81
|
+
hasMeta = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (hasMeta) {
|
|
86
|
+
text += '\n---\n' + util.inspect(meta);
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
this.smtpTransport.sendMail({
|