smtp-server-as-promised
Advanced tools
Comparing version 2.0.4 to 3.0.0
# Changelog | ||
## v3.0.0 2018-01-25 | ||
* Removed `usePromiseReadable` option. `onData` handler gives `Readable` | ||
stream always. | ||
## v2.0.4 2017-10-24 | ||
@@ -4,0 +9,0 @@ |
@@ -7,3 +7,2 @@ /// <reference types="node" /> | ||
export { Logger, LoggerLevel } from 'nodemailer/lib/shared' | ||
import { PromiseReadable } from 'promise-readable' | ||
import { Readable } from 'stream' | ||
@@ -24,3 +23,2 @@ import * as tls from 'tls' | ||
port?: number | ||
usePromiseReadable?: boolean | ||
@@ -30,3 +28,3 @@ onAuth?: (auth: SMTPServerAuthentication, session: SMTPServerSession) => Promise<SMTPServerAuthenticationResponse> | ||
onConnect?: (session: SMTPServerSession) => Promise<void> | ||
onData?: (stream: Readable | PromiseReadable<Readable>, session: SMTPServerSession) => Promise<void> | ||
onData?: (stream: Readable, session: SMTPServerSession) => Promise<void> | ||
onMailFrom?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void> | ||
@@ -33,0 +31,0 @@ onRcptTo?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void> |
@@ -5,4 +5,2 @@ 'use strict' | ||
const PromiseReadable = require('promise-readable').PromiseReadable | ||
class SMTPServerAsPromised { | ||
@@ -18,4 +16,4 @@ constructor (options) { | ||
if (options.onAuth) { | ||
const promise = options.onAuth | ||
options.onAuth = (auth, session, callback) => promise(auth, session) | ||
const handler = options.onAuth | ||
options.onAuth = (auth, session, callback) => handler(auth, session) | ||
.then((response) => callback(null, response)) | ||
@@ -25,18 +23,18 @@ .catch((err) => callback(err)) | ||
if (options.onMailFrom) { | ||
const promise = options.onMailFrom | ||
options.onMailFrom = (from, session, callback) => promise(from, session).then(callback).catch((err) => callback(err)) | ||
const handler = options.onMailFrom | ||
options.onMailFrom = (from, session, callback) => handler(from, session).then(callback).catch((err) => callback(err)) | ||
} | ||
if (options.onRcptTo) { | ||
const promise = options.onRcptTo | ||
options.onRcptTo = (to, session, callback) => promise(to, session).then(callback).catch((err) => callback(err)) | ||
const handler = options.onRcptTo | ||
options.onRcptTo = (to, session, callback) => handler(to, session).then(callback).catch((err) => callback(err)) | ||
} | ||
if (options.onData) { | ||
const promise = options.onData | ||
const handler = options.onData | ||
options.onData = (stream, session, callback) => { | ||
return promise(options.usePromiseReadable ? new PromiseReadable(stream) : stream, session).then(callback).catch((err) => callback(err)) | ||
return handler(stream, session).then(callback).catch((err) => callback(err)) | ||
} | ||
} | ||
if (options.onClose) { | ||
const promise = options.onClose | ||
options.onClose = (session) => promise(session) | ||
const handler = options.onClose | ||
options.onClose = (session) => handler(session) | ||
} | ||
@@ -43,0 +41,0 @@ |
{ | ||
"name": "smtp-server-as-promised", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Promisify smtp-server module", | ||
@@ -26,3 +26,2 @@ "main": "lib/smtp-server-as-promised.js", | ||
"dependencies": { | ||
"promise-readable": "^2.1.0", | ||
"smtp-server": "^3.3.0" | ||
@@ -37,2 +36,3 @@ }, | ||
"onchange": "^3.2.1", | ||
"promise-readable": "^2.1.0", | ||
"promise-socket": "^2.0.2", | ||
@@ -39,0 +39,0 @@ "snazzy": "^7.0.0", |
@@ -10,6 +10,2 @@ ## smtp-server-as-promised | ||
Additionally, `stream` argument for `onData` promise is changed to | ||
[`PromiseReadable`](https://www.npmjs.com/package/promise-readable) object if | ||
`options.usePromiseReadable` is `true`. | ||
### Requirements | ||
@@ -52,3 +48,2 @@ | ||
port: 2525, | ||
usePromiseReadable: true, | ||
onConnect, onMailFrom, onData, onError | ||
@@ -107,17 +102,5 @@ }) | ||
##### usePromiseReadable | ||
```js | ||
options.usePromiseReadable = true | ||
```` | ||
Callback handler `onData` provides `stream` object as an instance of | ||
[`PromiseReadable`](https://www.npmjs.com/package/promise-readable) class if | ||
`options.usePromiseReadable` options is `true` | ||
##### onData | ||
```js | ||
const server = new SMTPServerAsPromised({usePromiseReadable: true, onData}) | ||
async function onData (stream, session) { | ||
@@ -138,4 +121,22 @@ console.log(`[${session.id}] onData started`) | ||
[`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable) | ||
object if `options.usePromiseReadable` is `false`. | ||
object. | ||
Warning: if an error occures in `onData` handler, stream have to be consumed | ||
before return from function. | ||
_Example_: | ||
```js | ||
const { NullWritable } = require('null-writable') | ||
async function onData (stream, session) { | ||
try { | ||
throw new Error('Something bad happened') | ||
} catch (e) { | ||
stream.pipe(new NullWritable()) // read it to the end | ||
throw e // rethrow original error | ||
} | ||
} | ||
``` | ||
##### onError | ||
@@ -201,4 +202,4 @@ | ||
Copyright (c) 2016-2017 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
Copyright (c) 2016-2018 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
[MIT](https://opensource.org/licenses/MIT) |
@@ -8,7 +8,4 @@ { | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"typeRoots": [ | ||
"./typings" | ||
] | ||
"strictNullChecks": true | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
201
13574
12
123
- Removedpromise-readable@^2.1.0
- Removedpromise-readable@2.1.1(transitive)