Socket
Socket
Sign inDemoInstall

@cobuildlab/rbac

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cobuildlab/rbac - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

23

lib/rbac.js

@@ -17,6 +17,6 @@ "use strict";

RBAC.prototype.createRule = function (roleName, permissionName, test, message) {
var _a, _b;
Object.assign(this.rules, (_a = {},
_a[roleName] = (_b = {},
_b[permissionName] = {
var _a, _b, _c;
if (this.rules[roleName]) {
Object.assign(this.rules[roleName], (_a = {},
_a[permissionName] = {
can: typeof test === 'boolean' ? test : undefined,

@@ -26,4 +26,15 @@ dynamic: typeof test === 'function' ? test : undefined,

},
_b),
_a));
_a));
}
else {
Object.assign(this.rules, (_b = {},
_b[roleName] = (_c = {},
_c[permissionName] = {
can: typeof test === 'boolean' ? test : undefined,
dynamic: typeof test === 'function' ? test : undefined,
message: message,
},
_c),
_b));
}
};

@@ -30,0 +41,0 @@ /**

{
"name": "@cobuildlab/rbac",
"version": "0.2.0",
"version": "0.2.1",
"description": "",

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

@@ -11,2 +11,3 @@ import { test, expect } from '@jest/globals';

DASHBOARD = 'DASHBOARD',
SETTINGS = 'SETTINGS',
}

@@ -23,2 +24,8 @@

staticRules.createRule(
Roles.ADMIN,
Permissions.SETTINGS,
true,
'Access granted',
);
staticRules.createRule(
Roles.MANAGER,

@@ -33,2 +40,6 @@ Permissions.DASHBOARD,

]);
expect(staticRules.check(Roles.ADMIN, Permissions.SETTINGS)).toStrictEqual([
true,
'Access granted',
]);
expect(

@@ -35,0 +46,0 @@ staticRules.check(Roles.MANAGER, Permissions.DASHBOARD),

@@ -31,4 +31,4 @@ /* eslint-disable @typescript-eslint/ban-types */

): void {
Object.assign(this.rules, {
[roleName]: {
if (this.rules[roleName]) {
Object.assign(this.rules[roleName], {
[permissionName]: {

@@ -39,4 +39,14 @@ can: typeof test === 'boolean' ? test : undefined,

},
},
});
});
} else {
Object.assign(this.rules, {
[roleName]: {
[permissionName]: {
can: typeof test === 'boolean' ? test : undefined,
dynamic: typeof test === 'function' ? test : undefined,
message,
},
},
});
}
}

@@ -43,0 +53,0 @@

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