express-reaccess
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "express-reaccess", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Express/Connect middleware to manage API access on a RegExp basis", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,5 +5,6 @@ # express-reaccess | ||
[![NPM version](https://badge.fury.io/js/express-reaccess.png)](https://npmjs.org/package/express-reaccess) [![Build status](https://secure.travis-ci.org/SimpliField/express-reaccess.png)](https://travis-ci.org/SimpliField/express-reaccess) [![Dependency Status](https://david-dm.org/SimpliField/express-reaccess.png)](https://david-dm.org/SimpliField/express-reaccess) [![devDependency Status](https://david-dm.org/SimpliField/express-reaccess/dev-status.png)](https://david-dm.org/SimpliField/express-reaccess#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/SimpliField/express-reaccess/badge.png?branch=master)](https://coveralls.io/r/SimpliField/express-reaccess?branch=master) [![Code Climate](https://codeclimate.com/github/SimpliField/express-reaccess.png)](https://codeclimate.com/github/SimpliField/express-reaccess) | ||
See [those slides](http://slides.com/nfroidure/reaccess) to know more about the `reaccess` project principles. | ||
## Usage | ||
@@ -125,2 +126,8 @@ ```js | ||
### options.debug | ||
Type: `Function` | ||
Default: `undefined` | ||
Set your logging function here to get debugging informations. | ||
## Static properties | ||
@@ -127,0 +134,0 @@ Reaccess use bitwise operators to match methods. The reaccess function provides |
@@ -17,3 +17,7 @@ var escRegExp = require('escape-regexp-component'); | ||
return function reaccessMiddleware(req, res, next) { | ||
var rights = options.rightsProps.reduce(function(rights, prop) { | ||
var rights; | ||
if(options.debug) { | ||
options.debug('Checking access for:"', req.path); | ||
} | ||
rights = options.rightsProps.reduce(function(rights, prop) { | ||
return getValues([req], prop).reduce(function(finalRights, currentRights) { | ||
@@ -23,2 +27,6 @@ return finalRights.concat(currentRights); | ||
}, []); | ||
if(options.debug) { | ||
options.debug('Rights properties "' + options.rightsProps.join(',') + '"' + | ||
' has been resolved to:', rights); | ||
} | ||
var rootValues; | ||
@@ -32,8 +40,20 @@ if(!(rights && rights instanceof Array)) { | ||
}, []); | ||
if(options.debug) { | ||
options.debug('Values properties "' + options.valuesProps.join(',') + | ||
'" has been resolved to:', rootValues); | ||
} | ||
} | ||
if(rights.some(function(right) { | ||
var path = ''; | ||
var result = false; | ||
if(options.debug) { | ||
options.debug('Evaluating right:"', right); | ||
} | ||
if(!('undefined' !== typeof right.methods && | ||
'undefined' !== typeof right.path && | ||
right.methods&reaccess[req.method.toUpperCase()])) { | ||
if(options.debug) { | ||
options.debug('Method "' + req.method + '" do not match methods:"', | ||
right.methods); | ||
} | ||
return false; | ||
@@ -56,3 +76,8 @@ } | ||
} | ||
return path && new RegExp('^'+path+'$').test(req.path); | ||
result = path && new RegExp('^'+path+'$').test(req.path); | ||
if(options.debug) { | ||
options.debug('Testing : /^' + path.replace('/', '\\/') + '$/"' + | ||
' on "' + req.path + '" led to ' + (result ? 'SUCCESS' : 'FAILURE')); | ||
} | ||
return result; | ||
})) { | ||
@@ -84,3 +109,3 @@ next(); | ||
path = -1 !== index ? path.substring(index + 1) : ''; | ||
values = values.reduce(function(values, value) { | ||
@@ -114,2 +139,1 @@ if((value instanceof Object) && '*' === part) { | ||
module.exports = reaccess; | ||
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
21556
503
218