🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

empower-permission

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empower-permission - npm Package Compare versions

Comparing version

to
1.0.2

dist/permission-map-builder.js

28

dist/index.js
// Generated by CoffeeScript 1.10.0
(function() {
var DEFAULT_ACTION, Map, PermissionMap, Token;
var DEFAULT_ACTION, Factory, Map, MapBuilder, PermissionMap;
Map = require('./permission-map');
Token = require('./permission-token');
MapBuilder = require('./permission-map-builder');

@@ -21,7 +21,4 @@ DEFAULT_ACTION = '*';

PermissionMap.prototype.getToken = function(path, action) {
var token, tokenAction;
token = Map.getToken(this.map, path);
tokenAction = Token.getAction(token, action);
return (tokenAction === action ? Token.addAction(token, action) : token).replace(/!/g, '');
PermissionMap.prototype.getToken = function(path) {
return Map.getToken(this.map, path);
};

@@ -33,9 +30,16 @@

module.exports = {
Map: function() {
return new PermissionMap();
},
Permission: Map.Permission
Factory = function() {
return new PermissionMap();
};
Factory.fromJson = function(json) {
var map, permissionMap;
map = MapBuilder.fromJson(json);
permissionMap = new PermissionMap();
permissionMap.map = map;
return permissionMap;
};
module.exports = Factory;
}).call(this);

@@ -10,3 +10,3 @@ // Generated by CoffeeScript 1.10.0

_match = function(path, perm) {
return pathToRegExp(perm.path).test(path);
return perm.path.test(path);
};

@@ -16,3 +16,3 @@

return {
path: path,
path: pathToRegExp(path),
token: token

@@ -19,0 +19,0 @@ };

{
"name": "empower-permission",
"version": "1.0.1",
"version": "1.0.2",
"description": "Given a permission set and a request return a permission token.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

[![Build Status](https://travis-ci.org/scull7/empower-permission.svg?branch=master)](https://travis-ci.org/scull7/empower-permission)
[![Coverage Status](https://coveralls.io/repos/scull7/empower-permission/badge.svg?branch=master&service=github)](https://coveralls.io/github/scull7/empower-permission?branch=master)
# empower-permission
# empower-permission
Given a permission set and a request return a permission token.
it will look in the `PermissionMap` for for a url that matches the given URL.
If found, then it will return the `BasePermissionToken` associated with that URL.
If found, then it will return the token string associated with that path.
Otherwise, it will return the `GeneralAccessToken` or _'*'_.
Once it has the base permission token then it will append the interpreted `Method`
_(Action)_ to the token using a `:` character separator.
Paths will be parsed using the `pathToRegexp` module.
g
## PermissionToken
### PermissionToken
Example Token Strings:
```javascript
'token:entity:create'
'token:entity:update'
'token:entity:sub-entity:read'
```
'token:entity:create`
`token:entity:update`
`token:entity:sub-entity:read`
```
***NOTE*** what precedes the `:<action>` is entirely up to what you put in the
`PermissionMap` you provide.
### PermissionMap
## PermissionMap
This is a map of URL strings to `PermissionTokens`
This is a map of path strings to `PermissionTokens`
Example Map:
```
```json
{
"url/token/entity": "token:entity",
"url/token/entity/action": "token:entity:action!"
"/url/token/entity/:entityId": "url:token:entity",
"/url/token/:tokenId": "url:token",
"/url/token": "url:token:list",
"/url/token/:tokenId/action": "url:token:action"
}
```
***Note*** adding `!` to the end of your token marks anything after the last
`:` as an action.
### Method
This is either an HTTP Method or a custom action. It will be interpreted
into one of the following:
- ***READ*** _(GET)_
- ***WRITE*** _(POST / PUT)_
- ***CREATE*** _(POST)_
- ***UPDATE*** _(PUT)_
- ***DELETE*** _(DELETE)_
- ***CUSTOM ACTION***
## Usage
### Building the Map from JSON
```javascript
var PermissionMap = require('empower-permission');
var map = PermissionMap.fromJson({
"/url/token/entity/:entityId": "url:token:entity",
"/url/token/:tokenId": "url:token",
"/url/token": "url:token:list",
"/url/token/:tokenId/action": "url:token:action"
}}
var token = map.getToken("/url/token/entity/1234");
console.log(token); // will output "url:token:entity"
```
### Building the Map Programmatically
```javascript
var PermissionMap = require('empower-permission');
var map = PermissionMap();
map
.addToken("/url/token/entity/:entityId", "url:token:entity")
.addToken("/url/token/:tokenId", "url:token")
.addToken("/url/token", "url:token:list")
.addToken("/url/token/:tokenId/action", "url:token:action")
var token = map.getToken("/url/token");
console.log(token); // will output "url:token:list"
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet