Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

accesscontrol-re

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accesscontrol-re - npm Package Compare versions

Comparing version 0.2.1 to 1.0.0

15

build/src/accesscontrol-re.d.ts
import { AccessControl, IAccessInfo } from 'accesscontrol';
export declare const addAccessInfo: (accessInfo: IAccessInfo | IAccessInfo[]) => void;
export declare const build: () => AccessControl;
export declare const addCustomActions: (customActions: string[]) => void;
export declare const getRoles: () => string[];
export declare const getResources: () => string[];
export declare const getActions: () => string[];
export declare class AcccessControlRe {
private accessInfos;
addAccessInfo: (accessInfo: IAccessInfo | IAccessInfo[]) => void;
build: () => AccessControl;
addCustomActions: (customActions: string[]) => void;
getRoles: () => string[];
getResources: () => string[];
getActions: () => string[];
}
export declare const cleanStarEtc: (a1: {}) => any[];

101

build/src/accesscontrol-re.js

@@ -6,52 +6,59 @@ "use strict";

const accesscontrol_1 = require("accesscontrol");
const accessInfos = [];
exports.addAccessInfo = (accessInfo) => {
if (!accessInfo || !_.isObject(accessInfo))
throw new Error(`Invalid accessInfo:\n${JSON.stringify(accessInfo)}`);
_.isArray(accessInfo) ? accessInfos.push(...accessInfo) : accessInfos.push(accessInfo);
};
exports.build = _.once(() => {
const actions = exports.getActions();
const resources = exports.getResources();
const roles = exports.getRoles();
exports.addCustomActions(actions);
const ac = new accesscontrol_1.AccessControl();
for (const ai of accessInfos) {
const [action, actionPossession] = ai.action.split(':');
ai.role = _.isArray(ai.role) ? ai.role : [ai.role];
const actionsToGrant = action === '*' ? actions : [action];
const resourcesToGrant = ai.resource === '*' ? resources : [ai.resource];
const rolesToGrant = ai.role.includes('*') ? roles : ai.role;
for (const actionToGrant of actionsToGrant) {
for (const resourceToGrant of resourcesToGrant) {
const accessInfo = Object.assign({}, ai, { possession: actionPossession || ai.possession || 'any', action: actionToGrant, resource: resourceToGrant, role: rolesToGrant });
accessInfo.denied ? ac.deny(accessInfo) : ac.grant(accessInfo);
const enums_1 = require("accesscontrol/lib/enums");
const crudActions = [...enums_1.actions];
class AcccessControlRe {
constructor() {
this.accessInfos = [];
this.addAccessInfo = (accessInfo) => {
if (!accessInfo || !_.isObject(accessInfo))
throw new Error(`Invalid accessInfo:\n${JSON.stringify(accessInfo)}`);
_.isArray(accessInfo) ? this.accessInfos.push(...accessInfo) : this.accessInfos.push(accessInfo);
};
this.build = _.once(() => {
const actions = this.getActions();
const resources = this.getResources();
const roles = this.getRoles();
this.addCustomActions(actions);
const ac = new accesscontrol_1.AccessControl();
for (const ai of this.accessInfos) {
const [action, actionPossession] = ai.action.split(':');
ai.role = _.isArray(ai.role) ? ai.role : [ai.role];
const actionsToGrant = action === '*' ? actions : [action];
const resourcesToGrant = ai.resource === '*' ? resources : [ai.resource];
const rolesToGrant = ai.role.includes('*') ? roles : ai.role;
for (const actionToGrant of actionsToGrant) {
for (const resourceToGrant of resourcesToGrant) {
const accessInfo = Object.assign({}, ai, { possession: actionPossession || ai.possession || 'any', action: actionToGrant, resource: resourceToGrant, role: rolesToGrant });
accessInfo.denied ? ac.deny(accessInfo) : ac.grant(accessInfo);
}
}
}
}
return ac.lock();
});
this.addCustomActions = (customActions) => {
_.each(_.uniq(customActions), customAction => {
customAction = customAction.toLowerCase();
enums_1.Action[customAction.toUpperCase()] = customAction;
if (!enums_1.actions.includes(customAction))
enums_1.actions.push(customAction);
});
};
this.getRoles = () => {
return exports.cleanStarEtc(_.map(this.accessInfos, ai => ai.role));
};
this.getResources = () => {
return exports.cleanStarEtc(_.map(this.accessInfos, ai => ai.resource));
};
this.getActions = () => {
return exports.cleanStarEtc(_.reduce(this.accessInfos, (actions, accessInfo) => {
const [action] = accessInfo.action.split(':');
if (action !== '*')
actions.push(action);
return actions;
}, []).concat(crudActions));
};
}
return ac.lock();
});
const enums_1 = require("accesscontrol/lib/enums");
const crudActions = [...enums_1.actions];
exports.addCustomActions = (customActions) => {
_.each(_.uniq(customActions), customAction => {
enums_1.Action[customAction.toUpperCase()] = customAction.toLowerCase();
enums_1.actions.push(customAction.toLowerCase());
});
};
exports.getRoles = () => {
return exports.cleanStarEtc(_.map(accessInfos, ai => ai.role));
};
exports.getResources = () => {
return exports.cleanStarEtc(_.map(accessInfos, ai => ai.resource));
};
exports.getActions = () => {
return exports.cleanStarEtc(_.reduce(accessInfos, (actions, accessInfo) => {
const [action] = accessInfo.action.split(':');
if (action !== '*')
actions.push(action);
return actions;
}, []).concat(crudActions));
};
}
exports.AcccessControlRe = AcccessControlRe;
exports.cleanStarEtc = _.flow(_f.flatten, _f.remove(_f.isEqual('*')), _f.uniq, _f.sortBy(_f.identity));
//# sourceMappingURL=accesscontrol-re.js.map

@@ -1,1 +0,1 @@

export { addAccessInfo, build, getActions } from './accesscontrol-re';
export { AcccessControlRe } from './accesscontrol-re';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var accesscontrol_re_1 = require("./accesscontrol-re");
exports.addAccessInfo = accesscontrol_re_1.addAccessInfo;
exports.build = accesscontrol_re_1.build;
exports.getActions = accesscontrol_re_1.getActions;
exports.AcccessControlRe = accesscontrol_re_1.AcccessControlRe;
//# sourceMappingURL=index.js.map
{
"name": "accesscontrol-re",
"version": "0.2.1",
"version": "1.0.0",
"main": "./build/src/index.js",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc