New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

role-acl

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

role-acl - npm Package Compare versions

Comparing version

to
4.2.0

68

lib/src/utils/common.js

@@ -37,8 +37,12 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var Notation = require("notation");
var Matcher = require("matcher");
var notation_1 = __importDefault(require("notation"));
var matcher_1 = __importDefault(require("matcher"));
var array_1 = require("./array");
var conditions_1 = require("../conditions");
var core_1 = require("../core");
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
var CommonUtil = /** @class */ (function () {

@@ -56,3 +60,3 @@ function CommonUtil() {

var patternArray = array_1.ArrayUtil.toStringArray(patterns);
return Matcher(stringArray, patternArray).length !== 0;
return matcher_1.default(stringArray, patternArray).length !== 0;
};

@@ -79,3 +83,3 @@ CommonUtil.toExtendedJSON = function (o) {

CommonUtil.clone = function (o) {
return CommonUtil.fromExtendedJSON(CommonUtil.toExtendedJSON(o));
return lodash_clonedeep_1.default(o);
};

@@ -159,43 +163,43 @@ CommonUtil.type = function (o) {

// clone the object
query = Object.assign({}, query);
var newQuery = this.clone(query);
// validate and normalize role(s)
query.role = array_1.ArrayUtil.toStringArray(query.role);
if (!array_1.ArrayUtil.isFilledStringArray(query.role)) {
throw new core_1.AccessControlError("Invalid role(s): " + JSON.stringify(query.role));
newQuery.role = array_1.ArrayUtil.toStringArray(newQuery.role);
if (!array_1.ArrayUtil.isFilledStringArray(newQuery.role)) {
throw new core_1.AccessControlError("Invalid role(s): " + JSON.stringify(newQuery.role));
}
// validate resource
if (query.resource) {
if (typeof query.resource !== 'string' || query.resource.trim() === '') {
throw new core_1.AccessControlError("Invalid resource: \"" + query.resource + "\"");
if (newQuery.resource) {
if (typeof newQuery.resource !== 'string' || newQuery.resource.trim() === '') {
throw new core_1.AccessControlError("Invalid resource: \"" + newQuery.resource + "\"");
}
query.resource = query.resource.trim();
newQuery.resource = newQuery.resource.trim();
}
// validate action
if (query.action) {
if (typeof query.action !== 'string' || query.action.trim() === '') {
throw new core_1.AccessControlError("Invalid action: " + query.action);
if (newQuery.action) {
if (typeof newQuery.action !== 'string' || newQuery.action.trim() === '') {
throw new core_1.AccessControlError("Invalid action: " + newQuery.action);
}
}
return query;
return newQuery;
};
CommonUtil.normalizeAccessInfo = function (access) {
// clone the object
access = Object.assign({}, access);
var newAccess = this.clone(access);
// validate and normalize role(s)
access.role = array_1.ArrayUtil.toStringArray(access.role);
if (!array_1.ArrayUtil.isFilledStringArray(access.role)) {
throw new core_1.AccessControlError("Invalid role(s): " + JSON.stringify(access.role));
newAccess.role = array_1.ArrayUtil.toStringArray(newAccess.role);
if (!array_1.ArrayUtil.isFilledStringArray(newAccess.role)) {
throw new core_1.AccessControlError("Invalid role(s): " + JSON.stringify(newAccess.role));
}
// validate and normalize resource
access.resource = array_1.ArrayUtil.toStringArray(access.resource);
if (!array_1.ArrayUtil.isFilledStringArray(access.resource)) {
throw new core_1.AccessControlError("Invalid resource(s): " + JSON.stringify(access.resource));
newAccess.resource = array_1.ArrayUtil.toStringArray(newAccess.resource);
if (!array_1.ArrayUtil.isFilledStringArray(newAccess.resource)) {
throw new core_1.AccessControlError("Invalid resource(s): " + JSON.stringify(newAccess.resource));
}
// validate and normalize resource
access.action = array_1.ArrayUtil.toStringArray(access.action);
if (!array_1.ArrayUtil.isFilledStringArray(access.action)) {
throw new core_1.AccessControlError("Invalid resource(s): " + JSON.stringify(access.action));
newAccess.action = array_1.ArrayUtil.toStringArray(newAccess.action);
if (!array_1.ArrayUtil.isFilledStringArray(newAccess.action)) {
throw new core_1.AccessControlError("Invalid resource(s): " + JSON.stringify(newAccess.action));
}
access.attributes = !access.attributes ? ['*'] : array_1.ArrayUtil.toStringArray(access.attributes);
return access;
newAccess.attributes = !newAccess.attributes ? ['*'] : array_1.ArrayUtil.toStringArray(newAccess.attributes);
return newAccess;
};

@@ -287,3 +291,3 @@ /**

return array_1.ArrayUtil.toStringArray(grant.resource);
}).reduce(Notation.Glob.union, [])];
}).reduce(notation_1.default.Glob.union, [])];
}

@@ -311,3 +315,3 @@ });

return array_1.ArrayUtil.toStringArray(grant.action);
}).reduce(Notation.Glob.union, [])];
}).reduce(notation_1.default.Glob.union, [])];
}

@@ -345,3 +349,3 @@ });

return array_1.ArrayUtil.toStringArray(grant.attributes);
}).reduce(Notation.Glob.union, [])];
}).reduce(notation_1.default.Glob.union, [])];
}

@@ -598,3 +602,3 @@ });

}
var notation = new Notation(object);
var notation = new notation_1.default(object);
return notation.filter(attributes).value;

@@ -601,0 +605,0 @@ };

{
"name": "role-acl",
"version": "4.1.2",
"version": "4.2.0",
"description": "Role, Attribute and Condition based Access Control for Node.js",

@@ -55,5 +55,6 @@ "main": "./index.js",

"@types/jasmine": "^3.3.0",
"@types/lodash.clonedeep": "^4.5.6",
"@types/matcher": "^1.1.0",
"@types/node": "^9.4.7",
"handlebars": "^4.4.0",
"handlebars": "^4.5.3",
"istanbul": "^1.1.0-alpha.1",

@@ -71,2 +72,3 @@ "jasmine": "^3.3.0",

"jsonpath-plus": "^0.18.0",
"lodash.clonedeep": "^4.5.0",
"matcher": "^1.0.0",

@@ -73,0 +75,0 @@ "notation": "^1.3.5"

@@ -29,2 +29,5 @@ [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=73QY55FZWSPRJ) [![Build Status](https://travis-ci.org/tensult/role-acl.png?branch=master)](https://travis-ci.org/tensult/role-acl) [![Test Coverage](https://api.codeclimate.com/v1/badges/2d748a99b2c54e057cc2/test_coverage)](https://codeclimate.com/github/tensult/role-acl/test_coverage) [![NPM Version](https://badge.fury.io/js/role-acl.svg?style=flat)](https://npmjs.org/package/role-acl) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/tensult/role-acl/issues)

- TypeScript support.
- **Note**:
- For versions < 4.0: Every function in AccessControl class in synchronous.
- For versions >= 4.0 Most of the functions in AccessControl class are asychronous.

@@ -31,0 +34,0 @@ ## Guide

Sorry, the diff of this file is too big to display