npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

suppressor

v1.0.0

Published

Simple module that helps limit log in requests made to an Express application.

Downloads

30

Readme

Suppressor

Simple module that helps limit log in requests made to an Express application.

Install


Install the package

npm install suppressor --save

Then simply include the module and add it into the application.

var Suppressor = require('suppressor');
var options = {
  count: 5,
  reset: 5 * 60,
  driver: 'session',
  session: request.session
};
var suppressor = new Suppressor(options);

passport.authenticate('local', function(error, user) {
  request.logIn(user, function(error) {
    if(error) {
      suppressor.increment(request, null, function(error, overLimit) {
        if(error) {
          next(error);
        }
        else {
          if(overLimit) {
            // Do something with when the
            // limit has been exceeded
          }
          else {
            // Log in failed but limit hasn't been hit
          }
        }
      });
    }
    else {
      suppressor.clear(null, function(error) {
        // Log in was successful
      });
    }
  });

})(request, response, next);

If the callback is omitted, than a Promise is returned.

var Suppressor = require('suppressor');
var options = {
  count: 5,
  reset: 5 * 60,
  driver: 'session',
  session: request.session
};
var suppressor = new Suppressor(options);

passport.authenticate('local', function(error, user) {
  request.logIn(user, function(error) {
    if(error) {
      suppressor
        .increment(request, null)
        .then(function(overLimit) {
          if(overLimit) {
            // Do something with when the
            // limit has been exceeded
          }
          else {
            // Log in failed but limit hasn't been hit
          }
        })
    }
    else {
      suppressor
        .clear(null)
        .then(function() {
          // Log in was successful
        });
    }
  });
})(request, response, next);

Methods


#Suppressor(options)

The constructor takes an options object. The available options properties are:

  • driver: The type of driver to use. The available options are session, mongo and redis.
  • session: The application's session object, only needed when using the session driver.
  • conString: The Mongo DB connection string, only needed when using the mongo driver.
  • collection: The Mongo DB collection to use, only needed when using the mongo driver.
  • host: The redis host to use, only needed when using the redis driver. [Defaults to '127.0.0.1']
  • port: The redis port to use, only needed when using the redis driver. [Defaults to 6379]
  • options: Any additional options to passed to the underlying redis connection.
  • whitelist: An array containing whitelisted IP addresses, these addresses skip all attempt counts. Default is an empty array.
  • blacklist: An array containing blacklist IP addresses, these addresses are always rejected. Default is an empty array.
  • count: The number of tries before blocking. Default is 5.
  • reset: The number of seconds until the try count is reset. Default is 300 seconds (5 min).
  • field: The field name to track and increment. Defaults to 'loginCount'.

Bare minimum for each driver

var session = {
  count: 5,
  reset: 5 * 60,
  driver: 'session',
  session: request.session
};
var sessionSuppressor = new Suppressor(session);

var mongo = {
  count: 5,
  reset: 5 * 60,
  driver: 'mongo',
  conString: 'mongodb://localhost/suppressor',
  collection: 'limiter'
};
var mongoSuppressor = new Suppressor(mongo);

var redis = {
  count: 5,
  reset: 5 * 60,
  driver: 'redis'
};
var redisSuppressor = new Suppressor(redis);

#increment(request, id[, callback])

Increments the try count. Requires the request object and an id. The callback can be omitted to return a Promise. The ID parameter can be null when using the Session driver as it handles IDs automatically. The callback is passed an error, if one occurs, and a boolean value of whether the try count is over the limit. If no callback is provided than a bluebird Promise is returned.

#clear(id[, callback])

Clears the saved count number and the last try time. The callback can be omitted to return a Promise. The ID parameter can be null when using the Session driver as it handles IDs automatically.

License


Suppressor is licensed under the MIT license.

Copyright (c) 2015 Bryan Kizer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.