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

perimeterx-node-core

v3.15.1

Published

PerimeterX NodeJS shared core for various applications to monitor and block traffic according to PerimeterX risk score

Downloads

48,498

Readme

Build Status Known Vulnerabilities

image

PerimeterX Shared base for NodeJS enforcers

Latest stable version: v3.15.1

This is a shared base implementation for PerimeterX Express enforcer and future NodeJS enforcers. For a fully functioning implementation example, see the Node-Express enforcer implementation.

Table of Contents

Installation

$ npm install --save perimeterx-node-core

Basic Usage Example

To integrate this module into an enforcer, users should initialize the enforcer.

function initPXModule(params, client) {
    params.px_module_version = '<your module version>';
    enforcer = new PxEnforcer(params, client);
    //if dynamic configurations is configured
    if (enforcer.config.conf.DYNAMIC_CONFIGURATIONS) {
        setInterval(enforcer.config.confManager.loadData.bind(enforcer.config.confManager), enforcer.config.conf.CONFIGURATION_LOAD_INTERVAL);
    }
}

On every request, call enforce.

/**
 * pxMiddleware - middleware wrapper to score verification.
 *
 * @param {Object} req - HTTP Request.
 * @param {Object} res - HTTP Response.
 * @param {Function} next - callback function.
 */
function pxMiddleware(req, res, next) {
    enforcer.enforce(req, res, (response) => {
        if (response) { //block
            res.status(response.status);
            res.setHeader(response.header.key, response.header.value);
            res.send(response.body);
        } else { //pass
            next();
        }
    });
}

Extend the PxClient class to send activities to PerimeterX.

const { PxClient } = require('perimeterx-node-core');

class MyClient extends PxClient {
    init(config) {
        setInterval(() => {
            this.submitActivities(config);
        }, 1000);
    }
}

module.exports = { MyClient };

Make sure to pass the client instance when initializing the enforcer.

function initPXModule(params) {
    params.px_module_version = '<your module version>';
    const pxClient = new MyClient();
    enforcer = new PxEnforcer(params, pxClient);
    //if dynamic configurations is configured
    if (enforcer.config.conf.DYNAMIC_CONFIGURATIONS) {
        setInterval(enforcer.config.confManager.loadData.bind(enforcer.config.confManager), enforcer.config.conf.CONFIGURATION_LOAD_INTERVAL);
    }
}

Contributing

The following steps are welcome when contributing to our project:

Fork/Clone

First and foremost, Create a fork of the repository, and clone it locally. Create a branch on your fork, preferably using a self descriptive branch name.

Code/Run

Help improve our project by implementing missing features, adding capabilites or fixing bugs.

To run the code, simply follow the steps in the installation guide. Grab the keys from the PerimeterX Portal, and try refreshing your page several times continously. If no default behaviours have been overriden, you should see the PerimeterX block page. Solve the CAPTCHA to clean yourself and start fresh again.

Test

Tests for this project are written using Mocha.

Dont forget to test. The project relies heavily on tests, thus ensuring each user has the same experience, and no new features break the code. Before you create any pull request, make sure your project has passed all tests, and if any new features require it, write your own.

Running tests
$ npm test

Note: running tests without a valid PerimeterX app id, auth token and cookie key will not work.

Pull Request

After you have completed the process, create a pull request to the Upstream repository. Please provide a complete and thorough description explaining the changes. Remember this code has to be read by our maintainers, so keep it simple, smart and accurate.