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

@nebular/security

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nebular/security - npm Package Compare versions

Comparing version 6.1.0 to 6.2.0

253

bundles/security.umd.js

@@ -7,3 +7,3 @@ (function (global, factory) {

const NB_SECURITY_OPTIONS_TOKEN = new _angular_core.InjectionToken('Nebular Security Options');
var NB_SECURITY_OPTIONS_TOKEN = new _angular_core.InjectionToken('Nebular Security Options');

@@ -15,17 +15,18 @@ /**

*/
const shallowObjectClone = (o) => Object.assign({}, o);
const ɵ0 = shallowObjectClone;
const shallowArrayClone = (a) => Object.assign([], a);
const ɵ1 = shallowArrayClone;
const popParent = (abilities) => {
const parent = abilities['parent'];
var shallowObjectClone = function (o) { return Object.assign({}, o); };
var ɵ0 = shallowObjectClone;
var shallowArrayClone = function (a) { return Object.assign([], a); };
var ɵ1 = shallowArrayClone;
var popParent = function (abilities) {
var parent = abilities['parent'];
delete abilities['parent'];
return parent;
};
const ɵ2 = popParent;
var ɵ2 = popParent;
/**
* Common acl service.
*/
class NbAclService {
constructor(settings = {}) {
var NbAclService = /** @class */ (function () {
function NbAclService(settings) {
if (settings === void 0) { settings = {}; }
this.settings = settings;

@@ -41,9 +42,10 @@ this.state = {};

*/
setAccessControl(list) {
for (const [role, value] of Object.entries(list)) {
const abilities = shallowObjectClone(value);
const parent = popParent(abilities);
this.register(role, parent, abilities);
NbAclService.prototype.setAccessControl = function (list) {
for (var _i = 0, _a = Object.entries(list); _i < _a.length; _i++) {
var _b = _a[_i], role = _b[0], value = _b[1];
var abilities = shallowObjectClone(value);
var parent_1 = popParent(abilities);
this.register(role, parent_1, abilities);
}
}
};
/**

@@ -55,3 +57,5 @@ * Register a new role with a list of abilities (permission/resources combinations)

*/
register(role, parent = null, abilities = {}) {
NbAclService.prototype.register = function (role, parent, abilities) {
if (parent === void 0) { parent = null; }
if (abilities === void 0) { abilities = {}; }
this.validateRole(role);

@@ -61,7 +65,8 @@ this.state[role] = {

};
for (const [permission, value] of Object.entries(abilities)) {
const resources = typeof value === 'string' ? [value] : value;
for (var _i = 0, _a = Object.entries(abilities); _i < _a.length; _i++) {
var _b = _a[_i], permission = _b[0], value = _b[1];
var resources = typeof value === 'string' ? [value] : value;
this.allow(role, permission, shallowArrayClone(resources));
}
}
};
/**

@@ -73,3 +78,3 @@ * Allow a permission for specific resources to a role

*/
allow(role, permission, resource) {
NbAclService.prototype.allow = function (role, permission, resource) {
this.validateRole(role);

@@ -80,7 +85,7 @@ if (!this.getRole(role)) {

resource = typeof resource === 'string' ? [resource] : resource;
let resources = shallowArrayClone(this.getRoleResources(role, permission));
var resources = shallowArrayClone(this.getRoleResources(role, permission));
resources = resources.concat(resource);
this.state[role][permission] = resources
.filter((item, pos) => resources.indexOf(item) === pos);
}
.filter(function (item, pos) { return resources.indexOf(item) === pos; });
};
/**

@@ -93,48 +98,52 @@ * Check whether the role has a permission to a resource

*/
can(role, permission, resource) {
NbAclService.prototype.can = function (role, permission, resource) {
this.validateResource(resource);
const parentRole = this.getRoleParent(role);
const parentCan = parentRole && this.can(this.getRoleParent(role), permission, resource);
var parentRole = this.getRoleParent(role);
var parentCan = parentRole && this.can(this.getRoleParent(role), permission, resource);
return parentCan || this.exactCan(role, permission, resource);
}
getRole(role) {
};
NbAclService.prototype.getRole = function (role) {
return this.state[role];
}
validateRole(role) {
};
NbAclService.prototype.validateRole = function (role) {
if (!role) {
throw new Error('NbAclService: role name cannot be empty');
}
}
validateResource(resource) {
};
NbAclService.prototype.validateResource = function (resource) {
if (!resource || [NbAclService.ANY_RESOURCE].includes(resource)) {
throw new Error(`NbAclService: cannot use empty or bulk '*' resource placeholder with 'can' method`);
throw new Error("NbAclService: cannot use empty or bulk '*' resource placeholder with 'can' method");
}
}
exactCan(role, permission, resource) {
const resources = this.getRoleResources(role, permission);
};
NbAclService.prototype.exactCan = function (role, permission, resource) {
var resources = this.getRoleResources(role, permission);
return resources.includes(resource) || resources.includes(NbAclService.ANY_RESOURCE);
}
getRoleResources(role, permission) {
};
NbAclService.prototype.getRoleResources = function (role, permission) {
return this.getRoleAbilities(role)[permission] || [];
}
getRoleAbilities(role) {
const abilities = shallowObjectClone(this.state[role] || {});
};
NbAclService.prototype.getRoleAbilities = function (role) {
var abilities = shallowObjectClone(this.state[role] || {});
popParent(shallowObjectClone(this.state[role] || {}));
return abilities;
}
getRoleParent(role) {
};
NbAclService.prototype.getRoleParent = function (role) {
return this.state[role] ? this.state[role]['parent'] : null;
};
NbAclService.ANY_RESOURCE = '*';
NbAclService.decorators = [
{ type: _angular_core.Injectable }
];
NbAclService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Inject, args: [NB_SECURITY_OPTIONS_TOKEN,] }] }
]; };
return NbAclService;
}());
var NbRoleProvider = /** @class */ (function () {
function NbRoleProvider() {
}
}
NbAclService.ANY_RESOURCE = '*';
NbAclService.decorators = [
{ type: _angular_core.Injectable }
];
NbAclService.ctorParameters = () => [
{ type: undefined, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Inject, args: [NB_SECURITY_OPTIONS_TOKEN,] }] }
];
return NbRoleProvider;
}());
class NbRoleProvider {
}
/**

@@ -150,4 +159,4 @@ * @license

*/
class NbAccessChecker {
constructor(roleProvider, acl) {
var NbAccessChecker = /** @class */ (function () {
function NbAccessChecker(roleProvider, acl) {
this.roleProvider = roleProvider;

@@ -163,19 +172,21 @@ this.acl = acl;

*/
isGranted(permission, resource) {
NbAccessChecker.prototype.isGranted = function (permission, resource) {
var _this = this;
return this.roleProvider.getRole()
.pipe(rxjs_operators.map((role) => Array.isArray(role) ? role : [role]), rxjs_operators.map((roles) => {
return roles.some(role => this.acl.can(role, permission, resource));
.pipe(rxjs_operators.map(function (role) { return Array.isArray(role) ? role : [role]; }), rxjs_operators.map(function (roles) {
return roles.some(function (role) { return _this.acl.can(role, permission, resource); });
}));
}
}
NbAccessChecker.decorators = [
{ type: _angular_core.Injectable }
];
NbAccessChecker.ctorParameters = () => [
{ type: NbRoleProvider },
{ type: NbAclService }
];
};
NbAccessChecker.decorators = [
{ type: _angular_core.Injectable }
];
NbAccessChecker.ctorParameters = function () { return [
{ type: NbRoleProvider },
{ type: NbAclService }
]; };
return NbAccessChecker;
}());
class NbIsGrantedDirective {
constructor(templateRef, viewContainer, accessChecker) {
var NbIsGrantedDirective = /** @class */ (function () {
function NbIsGrantedDirective(templateRef, viewContainer, accessChecker) {
this.templateRef = templateRef;

@@ -187,35 +198,44 @@ this.viewContainer = viewContainer;

}
set nbIsGranted([permission, resource]) {
this.accessChecker.isGranted(permission, resource)
.pipe(rxjs_operators.takeUntil(this.destroy$))
.subscribe((can) => {
if (can && !this.hasView) {
this.viewContainer.createEmbeddedView(this.templateRef);
this.hasView = true;
}
else if (!can && this.hasView) {
this.viewContainer.clear();
this.hasView = false;
}
});
}
ngOnDestroy() {
Object.defineProperty(NbIsGrantedDirective.prototype, "nbIsGranted", {
set: function (_a) {
var _this = this;
var permission = _a[0], resource = _a[1];
this.accessChecker.isGranted(permission, resource)
.pipe(rxjs_operators.takeUntil(this.destroy$))
.subscribe(function (can) {
if (can && !_this.hasView) {
_this.viewContainer.createEmbeddedView(_this.templateRef);
_this.hasView = true;
}
else if (!can && _this.hasView) {
_this.viewContainer.clear();
_this.hasView = false;
}
});
},
enumerable: false,
configurable: true
});
NbIsGrantedDirective.prototype.ngOnDestroy = function () {
this.destroy$.next();
this.destroy$.complete();
};
NbIsGrantedDirective.decorators = [
{ type: _angular_core.Directive, args: [{ selector: '[nbIsGranted]' },] }
];
NbIsGrantedDirective.ctorParameters = function () { return [
{ type: _angular_core.TemplateRef },
{ type: _angular_core.ViewContainerRef },
{ type: NbAccessChecker }
]; };
NbIsGrantedDirective.propDecorators = {
nbIsGranted: [{ type: _angular_core.Input }]
};
return NbIsGrantedDirective;
}());
var NbSecurityModule = /** @class */ (function () {
function NbSecurityModule() {
}
}
NbIsGrantedDirective.decorators = [
{ type: _angular_core.Directive, args: [{ selector: '[nbIsGranted]' },] }
];
NbIsGrantedDirective.ctorParameters = () => [
{ type: _angular_core.TemplateRef },
{ type: _angular_core.ViewContainerRef },
{ type: NbAccessChecker }
];
NbIsGrantedDirective.propDecorators = {
nbIsGranted: [{ type: _angular_core.Input }]
};
class NbSecurityModule {
static forRoot(nbSecurityOptions) {
NbSecurityModule.forRoot = function (nbSecurityOptions) {
return {

@@ -229,17 +249,18 @@ ngModule: NbSecurityModule,

};
}
}
NbSecurityModule.decorators = [
{ type: _angular_core.NgModule, args: [{
imports: [
_angular_common.CommonModule,
],
declarations: [
NbIsGrantedDirective,
],
exports: [
NbIsGrantedDirective,
],
},] }
];
};
NbSecurityModule.decorators = [
{ type: _angular_core.NgModule, args: [{
imports: [
_angular_common.CommonModule,
],
declarations: [
NbIsGrantedDirective,
],
exports: [
NbIsGrantedDirective,
],
},] }
];
return NbSecurityModule;
}());

@@ -246,0 +267,0 @@ /**

{
"name": "@nebular/security",
"version": "6.1.0",
"version": "6.2.0",
"description": "@nebular/security",

@@ -5,0 +5,0 @@ "author": "akveo",

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