rbac 5.0.3 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/RBAC.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/RBAC.js"],"names":["DEFAULT_OPTIONS","permissions","roles","grant","delimiter","RBAC","getPermissionNames","Error","map","permission","Permission","createName","constructor","options","storage","MemoryStorage","useRBAC","init","grants","create","get","name","add","item","rbac","remove","removeByName","role","child","Role","revoke","revokeByName","roleName","childName","Promise","all","grantByName","createRole","createPermission","action","resource","exists","existsRole","existsPermission","getRole","getRoles","getPermission","getPermissionByName","data","decodeName","getPermissions","createPermissions","resources","Object","keys","actions","createRoles","roleNames","permissionNames","grantsData","traverseGrants","cb","next","used","actualRole","shift","getGrants","i","length","push","result","undefined","can","canAny","includes","canAll","founded","foundedCount","hasRole","roleChildName","has","getScope","scope"],"mappings":";;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,MAAMA,eAAe,GAAG;AACtBC,EAAAA,WAAW,EAAE,EADS;AAEtBC,EAAAA,KAAK,EAAE,EAFe;AAGtBC,EAAAA,KAAK,EAAE,EAHe;AAItBC,EAAAA,SAAS,EAAE;AAJW,CAAxB;;AAOe,MAAMC,IAAN,CAAW;AACxB;;;;;;;;;AASA,SAAOC,kBAAP,CAA0BL,WAA1B,EAAuCG,SAAvC,EAAoE;AAClE,QAAI,CAACA,SAAL,EAAgB;AACd,YAAM,IAAIG,KAAJ,CAAU,0BAAV,CAAN;AACD;;AAED,WAAON,WAAW,CAACO,GAAZ,CACLC,UAAU,IAAIC,oBAAWC,UAAX,CAAsBF,UAAU,CAAC,CAAD,CAAhC,EAAqCA,UAAU,CAAC,CAAD,CAA/C,EAAoDL,SAApD,CADT,CAAP;AAGD;AAED;;;;;;;;;;;AASAQ,EAAAA,WAAW,CAACC,OAAD,EAAkB;AAC3B,SAAKA,OAAL,qBACKb,eADL,EAEKa,OAF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P,GAAqB,IAArB;AACAwD,UAAAA,YAAY,IAAI,CAAhB;;AAEA,cAAIA,YAAY,KAAKnB,eAAe,CAACU,MAArC,EAA6C;AAC3C,mBAAO,IAAP;AACD;AACF;;AAED,eAAOG,SAAP;AACD,OAXK,CAAN;AAaA,aAAOM,YAAY,KAAKnB,eAAe,CAACU,MAAxC;AApBoD;AAqBrD;AAED;;;;;;;;;AAOMU,EAAAA,OAAN,CAAc9C,QAAd,EAAgC+C,aAAhC,EAAgE;AAAA;;AAAA;AAC9D,UAAI/C,QAAQ,KAAK+C,aAAjB,EAAgC;AAC9B,eAAO,IAAP;AACD;;AAED,YAAMC,GAAG,SAAS,OAAI,CAACpB,cAAL,CAAoB5B,QAApB,EAA+BT,IAAD,IAAU;AACxD,YAAIA,IAAI,YAAYM,aAAhB,IAAwBN,IAAI,CAACF,IAAL,KAAc0D,aAA1C,EAAyD;AACvD,iBAAO,IAAP;AACD;;AAED,eAAOR,SAAP;AACD,OANiB,CAAlB;AAQA,aAAOS,GAAG,IAAI,KAAd;AAb8D;AAc/D;AAED;;;;;;;;AAMMC,EAAAA,QAAN,CAAejD,QAAf,EAA2C;AAAA;;AAAA;AACzC,YAAMkD,KAAK,GAAG,EAAd,CADyC,CAGzC;;AACA,YAAM,OAAI,CAACtB,cAAL,CAAoB5B,QAApB,EAA+BT,IAAD,IAAU;AAC5C,YAAIA,IAAI,YAAYb,mBAAhB,IAA8B,CAACwE,KAAK,CAACR,QAAN,CAAenD,IAAI,CAACF,IAApB,CAAnC,EAA8D;AAC5D6D,UAAAA,KAAK,CAACb,IAAN,CAAW9C,IAAI,CAACF,IAAhB;AACD;AACF,OAJK,CAAN;AAMA,aAAO6D,KAAP;AAVyC;AAW1C;;AA5fuB","sourcesContent":["// @flow\nimport isPlainObject from 'lodash/isPlainObject';\nimport Base from './Base';\nimport Role from './Role';\nimport Permission from './Permission';\nimport Storage from './Storage';\nimport MemoryStorage from './Memory';\n\nconst DEFAULT_OPTIONS = {\n permissions: {},\n roles: [],\n grant: {},\n delimiter: '_',\n};\n\nexport default class RBAC {\n /**\n * Convert Array of permissions to permission name\n * @function getPermissionNames\n * @memberof RBAC\n * @param {Array} permissions List of array items of permission names. It contan action and resource\n * @param {string} delimiter\n * @return {string[]}\n * @static\n */\n static getPermissionNames(permissions, delimiter: string): string[] {\n if (!delimiter) {\n throw new Error('Delimiter is not defined');\n }\n\n return permissions.map(\n permission => Permission.createName(permission[0], permission[1], delimiter),\n );\n }\n\n /**\n * RBAC constructor\n * @constructor RBAC\n * @param {Object} options Options for RBAC\n * @param {Storage} [options.storage] Storage of grants\n * @param {Array} [options.roles] List of role names (String)\n * @param {Object} [options.permissions] List of permissions\n * @param {Object} [options.grants] List of grants\n */\n constructor(options: Object) {\n this.options = {\n ...DEFAULT_OPTIONS,\n ...options,\n };\n\n this.storage = this.options.storage || new MemoryStorage();\n this.storage.useRBAC(this);\n }\n\n async init() {\n const { roles, permissions, grants } = this.options;\n\n return this.create(roles, permissions, grants);\n }\n\n /**\n * Get instance of Role or Permission by his name\n * @method RBAC#get\n * @param {String} name Name of item\n */\n async get(name: string): ?Base {\n return this.storage.get(name);\n }\n\n /**\n * Register role or permission to actual RBAC instance\n * @method RBAC#add\n * @param {Base} item Instance of Base\n */\n async add(item: Base): boolean {\n if (!item) {\n throw new Error('Item is undefined');\n }\n\n if (item.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.add(item);\n }\n\n /**\n * Remove role or permission from RBAC\n * @method RBAC#remove\n * @param {Base} item Instance of role or permission\n */\n async remove(item: Base): boolean {\n if (!item) {\n throw new Error('Item is undefined');\n }\n\n if (item.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.remove(item);\n }\n\n /**\n * Remove role or permission from RBAC\n * @method RBAC#removeByName\n * @param {String} name Name of role or permission\n */\n async removeByName(name: string): boolean {\n const item = await this.get(name);\n if (!item) {\n return true;\n }\n\n return item.remove();\n }\n\n /**\n * Grant permission or role to the role\n * @method RBAC#grant\n * @param {Role} role Instance of the role\n * @param {Base} child Instance of the role or permission\n */\n async grant(role: Role, child: Base): boolean {\n if (!role || !child) {\n throw new Error('One of item is undefined');\n }\n\n if (role.rbac !== this || child.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n if (!(role instanceof Role)) {\n throw new Error('Role is not instance of Role');\n }\n\n return this.storage.grant(role, child);\n }\n\n /**\n * Revoke permission or role from the role\n * @method RBAC#revoke\n * @param {Role} role Instance of the role\n * @param {Base} child Instance of the role or permission\n */\n async revoke(role: Role, child: Base): boolean {\n if (!role || !child) {\n throw new Error('One of item is undefined');\n }\n\n if (role.rbac !== this || child.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.revoke(role, child);\n }\n\n /**\n * Revoke permission or role from the role by names\n * @method RBAC#revokeByName\n * @param {String} roleName Instance of the role\n * @param {String} childName Instance of the role or permission\n */\n async revokeByName(roleName: string, childName: string): void {\n const [role, child] = await Promise.all([\n this.get(roleName),\n this.get(childName),\n ]);\n\n return this.revoke(role, child);\n }\n\n /**\n * Grant permission or role from the role by names\n * @method RBAC#grantByName\n * @param {String} roleName Instance of the role\n * @param {String} childName Instance of the role or permission\n */\n async grantByName(roleName: string, childName: string): void {\n const [role, child] = await Promise.all([\n this.get(roleName),\n this.get(childName),\n ]);\n\n return this.grant(role, child);\n }\n\n /**\n * Create a new role assigned to actual instance of RBAC\n * @method RBAC#createRole\n * @param {String} roleName Name of new Role\n * @param {Boolean} [add] True if you need to add it to the storage\n * @return {Role} Instance of the Role\n */\n async createRole(roleName: string, add?: boolean): Role {\n const role = new Role(this, roleName);\n if (add) {\n await role.add();\n }\n\n return role;\n }\n\n /**\n * Create a new permission assigned to actual instance of RBAC\n * @method RBAC#createPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n * @param {Boolean} [add] True if you need to add it to the storage\n * @return {Permission} Instance of the Permission\n */\n async createPermission(action:string, resource: string, add?: boolean): Permission {\n const permission = new Permission(this, action, resource);\n if (add) {\n await permission.add();\n }\n\n return permission;\n }\n\n /**\n * Callback returns true if role or permission exists\n * @method RBAC#exists\n * @param {String} name Name of item\n */\n async exists(name: string): boolean {\n return this.storage.exists(name);\n }\n\n /**\n * Callback returns true if role exists\n * @method RBAC#existsRole\n * @param {String} name Name of item\n */\n async existsRole(name: string): boolean {\n return this.storage.existsRole(name);\n }\n\n /**\n * Callback returns true if permission exists\n * @method RBAC#existsPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n */\n async existsPermission(action: string, resource: string): boolean {\n return this.storage.existsPermission(action, resource);\n }\n\n /**\n * Return instance of Role by his name\n * @method RBAC#getRole\n * @param {String} name Name of role\n */\n async getRole(name: string): ?Role {\n return this.storage.getRole(name);\n }\n\n /**\n * Return all instances of Role\n * @method RBAC#getRoles\n */\n async getRoles(): Role[] {\n return this.storage.getRoles();\n }\n\n /**\n * Return instance of Permission by his action and resource\n * @method RBAC#getPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n */\n async getPermission(action: string, resource: string): ?Permission {\n return this.storage.getPermission(action, resource);\n }\n\n /**\n * Return instance of Permission by his name\n * @method RBAC#getPermission\n * @param {String} name Name of permission\n */\n async getPermissionByName(name: string): ?Permission {\n const data = Permission.decodeName(name, this.options.delimiter);\n return this.storage.getPermission(data.action, data.resource);\n }\n\n /**\n * Return all instances of Permission\n * @method RBAC#getPermissions\n */\n async getPermissions(): Permission[] {\n return this.storage.getPermissions();\n }\n\n /**\n * Create multiple permissions in one step\n * @method RBAC#createPermissions\n * @param {Object} permissions Object of permissions\n * @param {Boolean} [add=true] True if you need to add it to the storage\n */\n async createPermissions(resources: Object, add?: boolean = true): Permission[] {\n if (!isPlainObject(resources)) {\n throw new Error('Resources is not a plain object');\n }\n\n const permissions = {};\n\n await Promise.all(Object.keys(resources).map(async (resource) => {\n const actions = resources[resource];\n\n await Promise.all(actions.map(async (action) => {\n const permission = await this.createPermission(action, resource, add);\n permissions[permission.name] = permission;\n }));\n }));\n\n return permissions;\n }\n\n /**\n * Create multiple roles in one step assigned to actual instance of RBAC\n * @method RBAC#createRoles\n * @param {Array} roleNames Array of role names\n * @param {Boolean} [add=true] True if you need to add it to the storage\n */\n async createRoles(roleNames: string[], add?: boolean = true): Role[] {\n const roles = {};\n await Promise.all(roleNames.map(async (roleName) => {\n const role = await this.createRole(roleName, add);\n\n roles[role.name] = role;\n }));\n\n return roles;\n }\n\n /**\n * Grant multiple items in one function\n * @method RBAC#grants\n * @param {Object} List of roles\n */\n async grants(roles: Object) {\n if (!isPlainObject(roles)) {\n throw new Error('Grants is not a plain object');\n }\n\n await Promise.all(Object.keys(roles).map(async (roleName) => {\n const grants = roles[roleName];\n\n await Promise.all(grants.map(async (grant) => {\n await this.grantByName(roleName, grant);\n }));\n }));\n }\n\n /**\n * Create multiple permissions and roles in one step\n * @method RBAC#create\n * @param {Object[]} roleNames List of role names\n * @param {Object[]} permissionNames List of permission names\n * @param {Object} [grants] List of grants\n */\n async create(roleNames, permissionNames, grantsData): Object {\n const [permissions, roles] = await Promise.all([\n this.createPermissions(permissionNames),\n this.createRoles(roleNames),\n ]);\n\n\n if (grantsData) {\n await this.grants(grantsData);\n }\n\n return {\n permissions,\n roles,\n };\n }\n\n /**\n * Traverse hierarchy of roles.\n * Callback function returns as second parameter item from hierarchy or null if we are on the end of hierarchy.\n * @method RBAC#_traverseGrants\n * @param {string} roleName Name of role\n * @param {Function} cb Callback function\n * @private\n */\n async traverseGrants(roleName: string, cb: Function, next: String[] = [roleName], used: Object = {}): any {\n const actualRole = next.shift();\n used[actualRole] = true;\n\n const grants = await this.storage.getGrants(actualRole);\n for (let i = 0; i < grants.length; i += 1) {\n const item = grants[i];\n const { name } = item;\n\n if (item instanceof Role && !used[name]) {\n used[name] = true;\n next.push(name);\n }\n\n const result = await cb(item);\n if (result !== undefined) {\n return result;\n }\n }\n\n if (next.length) {\n return this.traverseGrants(null, cb, next, used);\n }\n }\n\n /**\n * Return true if role has allowed permission\n * @method RBAC#can\n * @param {string} roleName Name of role\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {boolean}\n */\n async can(roleName: string, action: string, resource: string): boolean {\n const can = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && item.can(action, resource)) {\n return true;\n }\n });\n\n return can || false;\n }\n\n\n /**\n * Check if the role has any of the given permissions.\n * @method RBAC#canAny\n * @param {string} roleName Name of role\n * @param {Object[]} permissions Array (String action, String resource)\n * @return {boolean}\n */\n async canAny(roleName: string, permissions: Object[]): boolean {\n // prepare the names of permissions\n const permissionNames = RBAC.getPermissionNames(permissions, this.options.delimiter);\n\n // traverse hierarchy\n const can = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && permissionNames.includes(item.name)) {\n return true;\n }\n\n return undefined;\n });\n\n return can || false;\n }\n\n /**\n * Check if the model has all of the given permissions.\n * @method RBAC#canAll\n * @param {string} roleName Name of role\n * @param {Object[]} permissions Array (String action, String resource)\n * @return {boolean} Current instance\n */\n async canAll(roleName: string, permissions: Object[]) {\n // prepare the names of permissions\n const permissionNames = RBAC.getPermissionNames(permissions, this.options.delimiter);\n const founded = {};\n let foundedCount = 0;\n\n // traverse hierarchy\n await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && permissionNames.includes(item.name) && !founded[item.name]) {\n founded[item.name] = true;\n foundedCount += 1;\n\n if (foundedCount === permissionNames.length) {\n return true;\n }\n }\n\n return undefined;\n });\n\n return foundedCount === permissionNames.length;\n }\n\n /**\n * Return true if role has allowed permission\n * @method RBAC#hasRole\n * @param {String} roleName Name of role\n * @param {String} roleChildName Name of child role\n * @return {boolean}\n */\n async hasRole(roleName: string, roleChildName: string): boolean {\n if (roleName === roleChildName) {\n return true;\n }\n\n const has = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Role && item.name === roleChildName) {\n return true;\n }\n\n return undefined;\n });\n\n return has || false;\n }\n\n /**\n * Return array of all permission assigned to role of RBAC\n * @method RBAC#getScope\n * @param {string} roleName Name of role\n * @return {string[]}\n */\n async getScope(roleName: string): string[] {\n const scope = [];\n\n // traverse hierarchy\n await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && !scope.includes(item.name)) {\n scope.push(item.name);\n }\n });\n\n return scope;\n }\n}\n"],"file":"RBAC.js"}
1
+ {"version":3,"file":"RBAC.js","names":["_Base","_interopRequireDefault","require","_Role","_Permission","_Storage","_Memory","e","__esModule","default","isPlainObject","value","proto","Object","getPrototypeOf","prototype","DEFAULT_OPTIONS","permissions","roles","grant","delimiter","RBAC","getPermissionNames","Error","map","permission","Permission","createName","constructor","options","storage","MemoryStorage","useRBAC","init","grants","create","get","name","add","item","rbac","remove","removeByName","role","child","Role","revoke","revokeByName","roleName","childName","Promise","all","grantByName","createRole","createPermission","action","resource","exists","existsRole","existsPermission","getRole","getRoles","getPermission","getPermissionByName","data","decodeName","getPermissions","createPermissions","resources","keys","actions","createRoles","roleNames","permissionNames","grantsData","traverseGrants","cb","next","used","actualRole","shift","getGrants","i","length","push","result","undefined","can","canAny","includes","canAll","founded","foundedCount","hasRole","roleChildName","has","getScope","scope","exports"],"sources":["../src/RBAC.js"],"sourcesContent":["// @flow\nimport Base from './Base';\n\nfunction isPlainObject(value) {\n if (typeof value !== 'object' || value === null) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\nimport Role from './Role';\nimport Permission from './Permission';\nimport Storage from './Storage';\nimport MemoryStorage from './Memory';\n\nconst DEFAULT_OPTIONS = {\n permissions: {},\n roles: [],\n grant: {},\n delimiter: '_',\n};\n\nexport default class RBAC {\n /**\n * Convert Array of permissions to permission name\n * @function getPermissionNames\n * @memberof RBAC\n * @param {Array} permissions List of array items of permission names. It contan action and resource\n * @param {string} delimiter\n * @return {string[]}\n * @static\n */\n static getPermissionNames(permissions, delimiter: string): string[] {\n if (!delimiter) {\n throw new Error('Delimiter is not defined');\n }\n\n return permissions.map(\n permission => Permission.createName(permission[0], permission[1], delimiter),\n );\n }\n\n /**\n * RBAC constructor\n * @constructor RBAC\n * @param {Object} options Options for RBAC\n * @param {Storage} [options.storage] Storage of grants\n * @param {Array} [options.roles] List of role names (String)\n * @param {Object} [options.permissions] List of permissions\n * @param {Object} [options.grants] List of grants\n */\n constructor(options: Object) {\n this.options = {\n ...DEFAULT_OPTIONS,\n ...options,\n };\n\n this.storage = this.options.storage || new MemoryStorage();\n this.storage.useRBAC(this);\n }\n\n async init() {\n const { roles, permissions, grants } = this.options;\n\n return this.create(roles, permissions, grants);\n }\n\n /**\n * Get instance of Role or Permission by his name\n * @method RBAC#get\n * @param {String} name Name of item\n */\n async get(name: string): ?Base {\n return this.storage.get(name);\n }\n\n /**\n * Register role or permission to actual RBAC instance\n * @method RBAC#add\n * @param {Base} item Instance of Base\n */\n async add(item: Base): boolean {\n if (!item) {\n throw new Error('Item is undefined');\n }\n\n if (item.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.add(item);\n }\n\n /**\n * Remove role or permission from RBAC\n * @method RBAC#remove\n * @param {Base} item Instance of role or permission\n */\n async remove(item: Base): boolean {\n if (!item) {\n throw new Error('Item is undefined');\n }\n\n if (item.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.remove(item);\n }\n\n /**\n * Remove role or permission from RBAC\n * @method RBAC#removeByName\n * @param {String} name Name of role or permission\n */\n async removeByName(name: string): boolean {\n const item = await this.get(name);\n if (!item) {\n return true;\n }\n\n return item.remove();\n }\n\n /**\n * Grant permission or role to the role\n * @method RBAC#grant\n * @param {Role} role Instance of the role\n * @param {Base} child Instance of the role or permission\n */\n async grant(role: Role, child: Base): boolean {\n if (!role || !child) {\n throw new Error('One of item is undefined');\n }\n\n if (role.rbac !== this || child.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n if (!(role instanceof Role)) {\n throw new Error('Role is not instance of Role');\n }\n\n return this.storage.grant(role, child);\n }\n\n /**\n * Revoke permission or role from the role\n * @method RBAC#revoke\n * @param {Role} role Instance of the role\n * @param {Base} child Instance of the role or permission\n */\n async revoke(role: Role, child: Base): boolean {\n if (!role || !child) {\n throw new Error('One of item is undefined');\n }\n\n if (role.rbac !== this || child.rbac !== this) {\n throw new Error('Item is associated to another RBAC instance');\n }\n\n return this.storage.revoke(role, child);\n }\n\n /**\n * Revoke permission or role from the role by names\n * @method RBAC#revokeByName\n * @param {String} roleName Instance of the role\n * @param {String} childName Instance of the role or permission\n */\n async revokeByName(roleName: string, childName: string): void {\n const [role, child] = await Promise.all([\n this.get(roleName),\n this.get(childName),\n ]);\n\n return this.revoke(role, child);\n }\n\n /**\n * Grant permission or role from the role by names\n * @method RBAC#grantByName\n * @param {String} roleName Instance of the role\n * @param {String} childName Instance of the role or permission\n */\n async grantByName(roleName: string, childName: string): void {\n const [role, child] = await Promise.all([\n this.get(roleName),\n this.get(childName),\n ]);\n\n return this.grant(role, child);\n }\n\n /**\n * Create a new role assigned to actual instance of RBAC\n * @method RBAC#createRole\n * @param {String} roleName Name of new Role\n * @param {Boolean} [add] True if you need to add it to the storage\n * @return {Role} Instance of the Role\n */\n async createRole(roleName: string, add?: boolean): Role {\n const role = new Role(this, roleName);\n if (add) {\n await role.add();\n }\n\n return role;\n }\n\n /**\n * Create a new permission assigned to actual instance of RBAC\n * @method RBAC#createPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n * @param {Boolean} [add] True if you need to add it to the storage\n * @return {Permission} Instance of the Permission\n */\n async createPermission(action:string, resource: string, add?: boolean): Permission {\n const permission = new Permission(this, action, resource);\n if (add) {\n await permission.add();\n }\n\n return permission;\n }\n\n /**\n * Callback returns true if role or permission exists\n * @method RBAC#exists\n * @param {String} name Name of item\n */\n async exists(name: string): boolean {\n return this.storage.exists(name);\n }\n\n /**\n * Callback returns true if role exists\n * @method RBAC#existsRole\n * @param {String} name Name of item\n */\n async existsRole(name: string): boolean {\n return this.storage.existsRole(name);\n }\n\n /**\n * Callback returns true if permission exists\n * @method RBAC#existsPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n */\n async existsPermission(action: string, resource: string): boolean {\n return this.storage.existsPermission(action, resource);\n }\n\n /**\n * Return instance of Role by his name\n * @method RBAC#getRole\n * @param {String} name Name of role\n */\n async getRole(name: string): ?Role {\n return this.storage.getRole(name);\n }\n\n /**\n * Return all instances of Role\n * @method RBAC#getRoles\n */\n async getRoles(): Role[] {\n return this.storage.getRoles();\n }\n\n /**\n * Return instance of Permission by his action and resource\n * @method RBAC#getPermission\n * @param {String} action Name of action\n * @param {String} resource Name of resource\n */\n async getPermission(action: string, resource: string): ?Permission {\n return this.storage.getPermission(action, resource);\n }\n\n /**\n * Return instance of Permission by his name\n * @method RBAC#getPermission\n * @param {String} name Name of permission\n */\n async getPermissionByName(name: string): ?Permission {\n const data = Permission.decodeName(name, this.options.delimiter);\n return this.storage.getPermission(data.action, data.resource);\n }\n\n /**\n * Return all instances of Permission\n * @method RBAC#getPermissions\n */\n async getPermissions(): Permission[] {\n return this.storage.getPermissions();\n }\n\n /**\n * Create multiple permissions in one step\n * @method RBAC#createPermissions\n * @param {Object} permissions Object of permissions\n * @param {Boolean} [add=true] True if you need to add it to the storage\n */\n async createPermissions(resources: Object, add?: boolean = true): Permission[] {\n if (!isPlainObject(resources)) {\n throw new Error('Resources is not a plain object');\n }\n\n const permissions = {};\n\n await Promise.all(Object.keys(resources).map(async (resource) => {\n const actions = resources[resource];\n\n await Promise.all(actions.map(async (action) => {\n const permission = await this.createPermission(action, resource, add);\n permissions[permission.name] = permission;\n }));\n }));\n\n return permissions;\n }\n\n /**\n * Create multiple roles in one step assigned to actual instance of RBAC\n * @method RBAC#createRoles\n * @param {Array} roleNames Array of role names\n * @param {Boolean} [add=true] True if you need to add it to the storage\n */\n async createRoles(roleNames: string[], add?: boolean = true): Role[] {\n const roles = {};\n await Promise.all(roleNames.map(async (roleName) => {\n const role = await this.createRole(roleName, add);\n\n roles[role.name] = role;\n }));\n\n return roles;\n }\n\n /**\n * Grant multiple items in one function\n * @method RBAC#grants\n * @param {Object} List of roles\n */\n async grants(roles: Object) {\n if (!isPlainObject(roles)) {\n throw new Error('Grants is not a plain object');\n }\n\n await Promise.all(Object.keys(roles).map(async (roleName) => {\n const grants = roles[roleName];\n\n await Promise.all(grants.map(async (grant) => {\n await this.grantByName(roleName, grant);\n }));\n }));\n }\n\n /**\n * Create multiple permissions and roles in one step\n * @method RBAC#create\n * @param {Object[]} roleNames List of role names\n * @param {Object[]} permissionNames List of permission names\n * @param {Object} [grants] List of grants\n */\n async create(roleNames, permissionNames, grantsData): Object {\n const [permissions, roles] = await Promise.all([\n this.createPermissions(permissionNames),\n this.createRoles(roleNames),\n ]);\n\n\n if (grantsData) {\n await this.grants(grantsData);\n }\n\n return {\n permissions,\n roles,\n };\n }\n\n /**\n * Traverse hierarchy of roles.\n * Callback function returns as second parameter item from hierarchy or null if we are on the end of hierarchy.\n * @method RBAC#_traverseGrants\n * @param {string} roleName Name of role\n * @param {Function} cb Callback function\n * @private\n */\n async traverseGrants(roleName: string, cb: Function, next: String[] = [roleName], used: Object = {}): any {\n const actualRole = next.shift();\n used[actualRole] = true;\n\n const grants = await this.storage.getGrants(actualRole);\n for (let i = 0; i < grants.length; i += 1) {\n const item = grants[i];\n const { name } = item;\n\n if (item instanceof Role && !used[name]) {\n used[name] = true;\n next.push(name);\n }\n\n const result = await cb(item);\n if (result !== undefined) {\n return result;\n }\n }\n\n if (next.length) {\n return this.traverseGrants(null, cb, next, used);\n }\n }\n\n /**\n * Return true if role has allowed permission\n * @method RBAC#can\n * @param {string} roleName Name of role\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {boolean}\n */\n async can(roleName: string, action: string, resource: string): boolean {\n const can = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && item.can(action, resource)) {\n return true;\n }\n });\n\n return can || false;\n }\n\n\n /**\n * Check if the role has any of the given permissions.\n * @method RBAC#canAny\n * @param {string} roleName Name of role\n * @param {Object[]} permissions Array (String action, String resource)\n * @return {boolean}\n */\n async canAny(roleName: string, permissions: Object[]): boolean {\n // prepare the names of permissions\n const permissionNames = RBAC.getPermissionNames(permissions, this.options.delimiter);\n\n // traverse hierarchy\n const can = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && permissionNames.includes(item.name)) {\n return true;\n }\n\n return undefined;\n });\n\n return can || false;\n }\n\n /**\n * Check if the model has all of the given permissions.\n * @method RBAC#canAll\n * @param {string} roleName Name of role\n * @param {Object[]} permissions Array (String action, String resource)\n * @return {boolean} Current instance\n */\n async canAll(roleName: string, permissions: Object[]) {\n // prepare the names of permissions\n const permissionNames = RBAC.getPermissionNames(permissions, this.options.delimiter);\n const founded = {};\n let foundedCount = 0;\n\n // traverse hierarchy\n await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && permissionNames.includes(item.name) && !founded[item.name]) {\n founded[item.name] = true;\n foundedCount += 1;\n\n if (foundedCount === permissionNames.length) {\n return true;\n }\n }\n\n return undefined;\n });\n\n return foundedCount === permissionNames.length;\n }\n\n /**\n * Return true if role has allowed permission\n * @method RBAC#hasRole\n * @param {String} roleName Name of role\n * @param {String} roleChildName Name of child role\n * @return {boolean}\n */\n async hasRole(roleName: string, roleChildName: string): boolean {\n if (roleName === roleChildName) {\n return true;\n }\n\n const has = await this.traverseGrants(roleName, (item) => {\n if (item instanceof Role && item.name === roleChildName) {\n return true;\n }\n\n return undefined;\n });\n\n return has || false;\n }\n\n /**\n * Return array of all permission assigned to role of RBAC\n * @method RBAC#getScope\n * @param {string} roleName Name of role\n * @return {string[]}\n */\n async getScope(roleName: string): string[] {\n const scope = [];\n\n // traverse hierarchy\n await this.traverseGrants(roleName, (item) => {\n if (item instanceof Permission && !scope.includes(item.name)) {\n scope.push(item.name);\n }\n });\n\n return scope;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAOA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAA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A;EACE,MAAMC,QAAQA,CAAChD,QAAgB,EAAY;IACzC,MAAMiD,KAAK,GAAG,EAAE;;IAEhB;IACA,MAAM,IAAI,CAACtB,cAAc,CAAC3B,QAAQ,EAAGT,IAAI,IAAK;MAC5C,IAAIA,IAAI,YAAYb,mBAAU,IAAI,CAACuE,KAAK,CAACR,QAAQ,CAAClD,IAAI,CAACF,IAAI,CAAC,EAAE;QAC5D4D,KAAK,CAACb,IAAI,CAAC7C,IAAI,CAACF,IAAI,CAAC;MACvB;IACF,CAAC,CAAC;IAEF,OAAO4D,KAAK;EACd;AACF;AAACC,OAAA,CAAAzF,OAAA,GAAAY,IAAA","ignoreList":[]}
package/dist/Role.js CHANGED
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.default = void 0;
5
-
6
7
  var _Base = _interopRequireDefault(require("./Base"));
7
-
8
8
  var _Permission = _interopRequireDefault(require("./Permission"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
-
14
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
15
-
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
10
  class Role extends _Base.default {
17
11
  /**
18
12
  * Role constructor
@@ -25,109 +19,71 @@ class Role extends _Base.default {
25
19
  if (!_Permission.default.isValidName(name, rbac.options.delimiter)) {
26
20
  throw new Error('Role has no valid name');
27
21
  }
28
-
29
22
  super(rbac, name);
30
23
  }
24
+
31
25
  /**
32
26
  * Add role or permission to current role
33
27
  * @method Role#grant
34
28
  * @param {Role|Permission} item Instance of role or permission
35
29
  */
36
-
37
-
38
- grant(item) {
39
- var _this = this;
40
-
41
- return _asyncToGenerator(function* () {
42
- return _this.rbac.grant(_this, item);
43
- })();
30
+ async grant(item) {
31
+ return this.rbac.grant(this, item);
44
32
  }
33
+
45
34
  /**
46
35
  * Remove role or permission from current role
47
36
  * @method Role#revoke
48
37
  * @param {Role|Permission} item Instance of role or permission
49
38
  */
50
-
51
-
52
- revoke(item) {
53
- var _this2 = this;
54
-
55
- return _asyncToGenerator(function* () {
56
- return _this2.rbac.revoke(_this2, item);
57
- })();
39
+ async revoke(item) {
40
+ return this.rbac.revoke(this, item);
58
41
  }
42
+
59
43
  /**
60
44
  * Return true if contains permission
61
45
  * @method Role#can
62
46
  * @param {string} action Name of action
63
47
  * @param {string} resource Name of resource
64
48
  */
65
-
66
-
67
- can(action, resource) {
68
- var _this3 = this;
69
-
70
- return _asyncToGenerator(function* () {
71
- return _this3.rbac.can(_this3.name, action, resource);
72
- })();
49
+ async can(action, resource) {
50
+ return this.rbac.can(this.name, action, resource);
73
51
  }
52
+
74
53
  /**
75
54
  * Check if the role has any of the given permissions
76
55
  * @method Role#canAny
77
- * @param {Array} permissions List of permissions. Each has structure (String action, String resource)
56
+ * @param {Array} permissions List of permissions. Each has structure (String action, String resource)
78
57
  */
79
-
80
-
81
- canAny(permissions) {
82
- var _this4 = this;
83
-
84
- return _asyncToGenerator(function* () {
85
- return _this4.rbac.canAny(_this4.name, permissions);
86
- })();
58
+ async canAny(permissions) {
59
+ return this.rbac.canAny(this.name, permissions);
87
60
  }
61
+
88
62
  /**
89
63
  * Check if the model has all of the given permissions
90
64
  * @method Role#canAll
91
65
  * @param {Array} permissions List of permissions. Each has structure (String action, String resource)
92
66
  */
93
-
94
-
95
- canAll(permissions) {
96
- var _this5 = this;
97
-
98
- return _asyncToGenerator(function* () {
99
- return _this5.rbac.canAll(_this5.name, permissions);
100
- })();
67
+ async canAll(permissions) {
68
+ return this.rbac.canAll(this.name, permissions);
101
69
  }
70
+
102
71
  /**
103
72
  * Return true if the current role contains the specified role name
104
73
  * @method Role#hasRole
105
74
  * @param {String} roleChildName Name of role
106
75
  */
107
-
108
-
109
- hasRole(roleChildName) {
110
- var _this6 = this;
111
-
112
- return _asyncToGenerator(function* () {
113
- return _this6.rbac.hasRole(_this6.name, roleChildName);
114
- })();
76
+ async hasRole(roleChildName) {
77
+ return this.rbac.hasRole(this.name, roleChildName);
115
78
  }
79
+
116
80
  /**
117
81
  * Return array of permission assigned to actual role
118
82
  * @method Role#getScope
119
83
  */
120
-
121
-
122
- getScope() {
123
- var _this7 = this;
124
-
125
- return _asyncToGenerator(function* () {
126
- return _this7.rbac.getScope(_this7.name);
127
- })();
84
+ async getScope() {
85
+ return this.rbac.getScope(this.name);
128
86
  }
129
-
130
87
  }
131
-
132
88
  exports.default = Role;
133
89
  //# sourceMappingURL=Role.js.map
package/dist/Role.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Role.js"],"names":["Role","Base","constructor","rbac","name","Permission","isValidName","options","delimiter","Error","grant","item","revoke","can","action","resource","canAny","permissions","canAll","hasRole","roleChildName","getScope"],"mappings":";;;;;AACA;;AACA;;;;;;;;AAEe,MAAMA,IAAN,SAAmBC,aAAnB,CAAwB;AACrC;;;;;;;AAOAC,EAAAA,WAAW,CAACC,IAAD,EAAaC,IAAb,EAA2B;AACpC,QAAI,CAACC,oBAAWC,WAAX,CAAuBF,IAAvB,EAA6BD,IAAI,CAACI,OAAL,CAAaC,SAA1C,CAAL,EAA2D;AACzD,YAAM,IAAIC,KAAJ,CAAU,wBAAV,CAAN;AACD;;AAED,UAAMN,IAAN,EAAYC,IAAZ;AACD;AAED;;;;;;;AAKMM,EAAAA,KAAN,CAAYC,IAAZ,EAAwB;AAAA;;AAAA;AACtB,aAAO,KAAI,CAACR,IAAL,CAAUO,KAAV,CAAgB,KAAhB,EAAsBC,IAAtB,CAAP;AADsB;AAEvB;AAED;;;;;;;AAKMC,EAAAA,MAAN,CAAaD,IAAb,EAAkC;AAAA;;AAAA;AAChC,aAAO,MAAI,CAACR,IAAL,CAAUS,MAAV,CAAiB,MAAjB,EAAuBD,IAAvB,CAAP;AADgC;AAEjC;AAED;;;;;;;;AAMME,EAAAA,GAAN,CAAUC,MAAV,EAA0BC,QAA1B,EAAqD;AAAA;;AAAA;AACnD,aAAO,MAAI,CAACZ,IAAL,CAAUU,GAAV,CAAc,MAAI,CAACT,IAAnB,EAAyBU,MAAzB,EAAiCC,QAAjC,CAAP;AADmD;AAEpD;AAED;;;;;;;AAKMC,EAAAA,MAAN,CAAaC,WAAb,EAAmC;AAAA;;AAAA;AACjC,aAAO,MAAI,CAACd,IAAL,CAAUa,MAAV,CAAiB,MAAI,CAACZ,IAAtB,EAA4Ba,WAA5B,CAAP;AADiC;AAElC;AAED;;;;;;;AAKMC,EAAAA,MAAN,CAAaD,WAAb,EAAmC;AAAA;;AAAA;AACjC,aAAO,MAAI,CAACd,IAAL,CAAUe,MAAV,CAAiB,MAAI,CAACd,IAAtB,EAA4Ba,WAA5B,CAAP;AADiC;AAElC;AAED;;;;;;;AAKME,EAAAA,OAAN,CAAcC,aAAd,EAA8C;AAAA;;AAAA;AAC5C,aAAO,MAAI,CAACjB,IAAL,CAAUgB,OAAV,CAAkB,MAAI,CAACf,IAAvB,EAA6BgB,aAA7B,CAAP;AAD4C;AAE7C;AAED;;;;;;AAIMC,EAAAA,QAAN,GAA+B;AAAA;;AAAA;AAC7B,aAAO,MAAI,CAAClB,IAAL,CAAUkB,QAAV,CAAmB,MAAI,CAACjB,IAAxB,CAAP;AAD6B;AAE9B;;AA7EoC","sourcesContent":["// @flow\nimport Base from './Base';\nimport Permission from './Permission';\n\nexport default class Role extends Base {\n /**\n * Role constructor\n * @constructor Role\n * @extends {Base}\n * @param {RBAC} rbac Instance of the RBAC\n * @param {String} name Name of the role\n */\n constructor(rbac: RBAC, name: string) {\n if (!Permission.isValidName(name, rbac.options.delimiter)) {\n throw new Error('Role has no valid name');\n }\n\n super(rbac, name);\n }\n\n /**\n * Add role or permission to current role\n * @method Role#grant\n * @param {Role|Permission} item Instance of role or permission\n */\n async grant(item: Base) {\n return this.rbac.grant(this, item);\n }\n\n /**\n * Remove role or permission from current role\n * @method Role#revoke\n * @param {Role|Permission} item Instance of role or permission\n */\n async revoke(item: Base): boolean {\n return this.rbac.revoke(this, item);\n }\n\n /**\n * Return true if contains permission\n * @method Role#can\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n */\n async can(action: string, resource: string): boolean {\n return this.rbac.can(this.name, action, resource);\n }\n\n /**\n * Check if the role has any of the given permissions\n * @method Role#canAny\n * @param {Array} permissions List of permissions. Each has structure (String action, String resource)\n */\n async canAny(permissions): boolean {\n return this.rbac.canAny(this.name, permissions);\n }\n\n /**\n * Check if the model has all of the given permissions\n * @method Role#canAll\n * @param {Array} permissions List of permissions. Each has structure (String action, String resource)\n */\n async canAll(permissions): boolean {\n return this.rbac.canAll(this.name, permissions);\n }\n\n /**\n * Return true if the current role contains the specified role name\n * @method Role#hasRole\n * @param {String} roleChildName Name of role\n */\n async hasRole(roleChildName: string): boolean {\n return this.rbac.hasRole(this.name, roleChildName);\n }\n\n /**\n * Return array of permission assigned to actual role\n * @method Role#getScope\n */\n async getScope(): Permission[] {\n return this.rbac.getScope(this.name);\n }\n}\n"],"file":"Role.js"}
1
+ {"version":3,"file":"Role.js","names":["_Base","_interopRequireDefault","require","_Permission","e","__esModule","default","Role","Base","constructor","rbac","name","Permission","isValidName","options","delimiter","Error","grant","item","revoke","can","action","resource","canAny","permissions","canAll","hasRole","roleChildName","getScope","exports"],"sources":["../src/Role.js"],"sourcesContent":["// @flow\nimport Base from './Base';\nimport Permission from './Permission';\nimport type RBAC from './RBAC';\n\nexport default class Role extends Base {\n /**\n * Role constructor\n * @constructor Role\n * @extends {Base}\n * @param {RBAC} rbac Instance of the RBAC\n * @param {String} name Name of the role\n */\n constructor(rbac: RBAC, name: string) {\n if (!Permission.isValidName(name, rbac.options.delimiter)) {\n throw new Error('Role has no valid name');\n }\n\n super(rbac, name);\n }\n\n /**\n * Add role or permission to current role\n * @method Role#grant\n * @param {Role|Permission} item Instance of role or permission\n */\n async grant(item: Base) {\n return this.rbac.grant(this, item);\n }\n\n /**\n * Remove role or permission from current role\n * @method Role#revoke\n * @param {Role|Permission} item Instance of role or permission\n */\n async revoke(item: Base): boolean {\n return this.rbac.revoke(this, item);\n }\n\n /**\n * Return true if contains permission\n * @method Role#can\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n */\n async can(action: string, resource: string): boolean {\n return this.rbac.can(this.name, action, resource);\n }\n\n /**\n * Check if the role has any of the given permissions\n * @method Role#canAny\n * @param {Array} permissions List of permissions. Each has structure (String action, String resource)\n */\n async canAny(permissions): boolean {\n return this.rbac.canAny(this.name, permissions);\n }\n\n /**\n * Check if the model has all of the given permissions\n * @method Role#canAll\n * @param {Array} permissions List of permissions. Each has structure (String action, String resource)\n */\n async canAll(permissions): boolean {\n return this.rbac.canAll(this.name, permissions);\n }\n\n /**\n * Return true if the current role contains the specified role name\n * @method Role#hasRole\n * @param {String} roleChildName Name of role\n */\n async hasRole(roleChildName: string): boolean {\n return this.rbac.hasRole(this.name, roleChildName);\n }\n\n /**\n * Return array of permission assigned to actual role\n * @method Role#getScope\n */\n async getScope(): Permission[] {\n return this.rbac.getScope(this.name);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGvB,MAAMG,IAAI,SAASC,aAAI,CAAC;EACrC;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,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AAiB;IAC7B,OAAO,IAAI,CAAClB,IAAI,CAACkB,QAAQ,CAAC,IAAI,CAACjB,IAAI,CAAC;EACtC;AACF;AAACkB,OAAA,CAAAvB,OAAA,GAAAC,IAAA","ignoreList":[]}
package/dist/Storage.js CHANGED
@@ -1,149 +1,111 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.default = void 0;
5
-
6
7
  var _Permission = _interopRequireDefault(require("./Permission"));
7
-
8
8
  var _Role = _interopRequireDefault(require("./Role"));
9
-
10
9
  var _Base = _interopRequireDefault(require("./Base"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
-
16
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
17
-
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
11
  class Storage {
19
12
  useRBAC(rbac) {
20
13
  if (this.rbac) {
21
14
  throw new Error('Storage is already in use with another instance of RBAC');
22
15
  }
23
-
24
16
  this.rbac = rbac;
25
17
  }
18
+
26
19
  /**
27
20
  * Add permission or role
28
21
  * @method Storage#add
29
22
  * @param {Base} item Instance of role or permission
30
23
  */
31
-
32
-
33
- add(item) {
34
- return _asyncToGenerator(function* () {
35
- throw new Error('Storage method add is not implemented');
36
- })();
24
+ async add(item) {
25
+ throw new Error('Storage method add is not implemented');
37
26
  }
27
+
38
28
  /**
39
29
  * Remove permission or role
40
30
  * @method Storage#remove
41
31
  * @param {Base} item Instance of role or permission
42
32
  */
43
-
44
-
45
- remove(item) {
46
- return _asyncToGenerator(function* () {
47
- throw new Error('Storage method remove is not implemented');
48
- })();
33
+ async remove(item) {
34
+ throw new Error('Storage method remove is not implemented');
49
35
  }
36
+
50
37
  /**
51
38
  * Add (grant) permission or role to hierarchy of actual role
52
39
  * @method Storage#grant
53
40
  * @param {Role} role Instance of role
54
41
  * @param {Base} child Instance of role or permission
55
42
  */
56
-
57
-
58
- grant(role, child) {
59
- return _asyncToGenerator(function* () {
60
- throw new Error('Storage method grant is not implemented');
61
- })();
43
+ async grant(role, child) {
44
+ throw new Error('Storage method grant is not implemented');
62
45
  }
46
+
63
47
  /**
64
48
  * Remove (revoke) permission or role from hierarchy of actual role
65
49
  * @method Storage#revoke
66
50
  * @param {Role} role Instance of role
67
51
  * @param {Base} child Instance of role or permission
68
52
  */
69
-
70
-
71
- revoke(role, child) {
72
- return _asyncToGenerator(function* () {
73
- throw new Error('Storage method revoke is not implemented');
74
- })();
53
+ async revoke(role, child) {
54
+ throw new Error('Storage method revoke is not implemented');
75
55
  }
56
+
76
57
  /**
77
58
  * Get instance of permission or role by his name
78
59
  * @method Storage#get
79
60
  * @param {String} name Name of role or permission
80
61
  * @return {Base}
81
62
  */
82
-
83
-
84
- get(name) {
85
- return _asyncToGenerator(function* () {
86
- throw new Error('Storage method get is not implemented');
87
- })();
63
+ async get(name) {
64
+ throw new Error('Storage method get is not implemented');
88
65
  }
66
+
89
67
  /**
90
68
  * Get all instances of Roles
91
69
  * @method Storage#getRoles
92
70
  * @return {Role[]}
93
71
  */
94
-
95
-
96
- getRoles() {
97
- return _asyncToGenerator(function* () {
98
- throw new Error('Storage method getRoles is not implemented');
99
- })();
72
+ async getRoles() {
73
+ throw new Error('Storage method getRoles is not implemented');
100
74
  }
75
+
101
76
  /**
102
77
  * Get all instances of Permissions
103
78
  * @method Storage#getPermissions
104
79
  * @return {Permission[]}
105
80
  */
106
-
107
-
108
- getPermissions() {
109
- return _asyncToGenerator(function* () {
110
- throw new Error('Storage method getPermissions is not implemented');
111
- })();
81
+ async getPermissions() {
82
+ throw new Error('Storage method getPermissions is not implemented');
112
83
  }
84
+
113
85
  /**
114
86
  * Get instances of Roles and Permissions assigned to role
115
87
  * @method Storage#getGrants
116
88
  * @param {String} role Name of role
117
89
  * @return {Base[]}
118
90
  */
119
-
120
-
121
- getGrants(role) {
122
- return _asyncToGenerator(function* () {
123
- throw new Error('Storage method getGrants is not implemented');
124
- })();
91
+ async getGrants(role) {
92
+ throw new Error('Storage method getGrants is not implemented');
125
93
  }
94
+
126
95
  /**
127
96
  * Get instance of role by his name
128
97
  * @method Storage#getRole
129
98
  * @param {String} name Name of role
130
99
  * @return {Role}
131
100
  */
132
-
133
-
134
- getRole(name) {
135
- var _this = this;
136
-
137
- return _asyncToGenerator(function* () {
138
- const role = yield _this.get(name);
139
-
140
- if (role && role instanceof _Role.default) {
141
- return role;
142
- }
143
-
144
- return undefined;
145
- })();
101
+ async getRole(name) {
102
+ const role = await this.get(name);
103
+ if (role && role instanceof _Role.default) {
104
+ return role;
105
+ }
106
+ return undefined;
146
107
  }
108
+
147
109
  /**
148
110
  * Get instance of permission by his name
149
111
  * @method Storage#getPermission
@@ -151,55 +113,37 @@ class Storage {
151
113
  * @param {string} resource Name of resource
152
114
  * @return {Permission} Instance of actual storage
153
115
  */
154
-
155
-
156
- getPermission(action, resource) {
157
- var _this2 = this;
158
-
159
- return _asyncToGenerator(function* () {
160
- const name = _Permission.default.createName(action, resource, _this2.rbac.options.delimiter);
161
-
162
- const item = yield _this2.get(name);
163
-
164
- if (item && item instanceof _Permission.default) {
165
- return item;
166
- }
167
-
168
- return undefined;
169
- })();
116
+ async getPermission(action, resource) {
117
+ const name = _Permission.default.createName(action, resource, this.rbac.options.delimiter);
118
+ const item = await this.get(name);
119
+ if (item && item instanceof _Permission.default) {
120
+ return item;
121
+ }
122
+ return undefined;
170
123
  }
124
+
171
125
  /**
172
126
  * Return true with callback if role or permission exists
173
127
  * @method Storage#exists
174
128
  * @param {string} name Name of role or permission
175
129
  * @return {boolean}
176
130
  */
177
-
178
-
179
- exists(name) {
180
- var _this3 = this;
181
-
182
- return _asyncToGenerator(function* () {
183
- const item = yield _this3.get(name);
184
- return !!item;
185
- })();
131
+ async exists(name) {
132
+ const item = await this.get(name);
133
+ return !!item;
186
134
  }
135
+
187
136
  /**
188
137
  * Return true with callback if role exists
189
138
  * @method Storage#existsRole
190
139
  * @param {string} name Name of role
191
140
  * @return {boolean}
192
141
  */
193
-
194
-
195
- existsRole(name) {
196
- var _this4 = this;
197
-
198
- return _asyncToGenerator(function* () {
199
- const role = yield _this4.getRole(name);
200
- return !!role;
201
- })();
142
+ async existsRole(name) {
143
+ const role = await this.getRole(name);
144
+ return !!role;
202
145
  }
146
+
203
147
  /**
204
148
  * Return true with callback if permission exists
205
149
  * @method Storage#existsPermission
@@ -207,18 +151,10 @@ class Storage {
207
151
  * @param {string} resource Name of resource
208
152
  * @return {boolean}
209
153
  */
210
-
211
-
212
- existsPermission(action, resource) {
213
- var _this5 = this;
214
-
215
- return _asyncToGenerator(function* () {
216
- const permission = yield _this5.getPermission(action, resource);
217
- return !!permission;
218
- })();
154
+ async existsPermission(action, resource) {
155
+ const permission = await this.getPermission(action, resource);
156
+ return !!permission;
219
157
  }
220
-
221
158
  }
222
-
223
159
  exports.default = Storage;
224
160
  //# sourceMappingURL=Storage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Storage.js"],"names":["Storage","useRBAC","rbac","Error","add","item","remove","grant","role","child","revoke","get","name","getRoles","getPermissions","getGrants","getRole","Role","undefined","getPermission","action","resource","Permission","createName","options","delimiter","exists","existsRole","existsPermission","permission"],"mappings":";;;;;AACA;;AACA;;AACA;;;;;;;;AAGe,MAAMA,OAAN,CAAc;AAC3BC,EAAAA,OAAO,CAACC,IAAD,EAAmB;AACxB,QAAI,KAAKA,IAAT,EAAe;AACb,YAAM,IAAIC,KAAJ,CAAU,yDAAV,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AAOU,SAAP;AANiC;AAOlC;AAED;;;;;;;;;AAOMC,EAAAA,aAAN,CAAoBC,MAApB,EAAoCC,QAApC,EAAmE;AAAA;;AAAA;AACjE,YAAMT,IAAI,GAAGU,oBAAWC,UAAX,CAAsBH,MAAtB,EAA8BC,QAA9B,EAAwC,MAAI,CAACnB,IAAL,CAAUsB,OAAV,CAAkBC,SAA1D,CAAb;;AACA,YAAMpB,IAAI,SAAS,MAAI,CAACM,GAAL,CAASC,IAAT,CAAnB;;AACA,UAAIP,IAAI,IAAIA,IAAI,YAAYiB,mBAA5B,EAAwC;AACtC,eAAOjB,IAAP;AACD;;AAED,aAAOa,SAAP;AAPiE;AAQlE;AAED;;;;;;;;AAMMQ,EAAAA,MAAN,CAAad,IAAb,EAAoC;AAAA;;AAAA;AAClC,YAAMP,IAAI,SAAS,MAAI,CAACM,GAAL,CAASC,IAAT,CAAnB;AACA,aAAO,CAAC,CAACP,IAAT;AAFkC;AAGnC;AAED;;;;;;;;AAMMsB,EAAAA,UAAN,CAAiBf,IAAjB,EAAwC;AAAA;;AAAA;AACtC,YAAMJ,IAAI,SAAS,MAAI,CAACQ,OAAL,CAAaJ,IAAb,CAAnB;AACA,aAAO,CAAC,CAACJ,IAAT;AAFsC;AAGvC;AAED;;;;;;;;;AAOMoB,EAAAA,gBAAN,CAAuBR,MAAvB,EAAuCC,QAAvC,EAAkE;AAAA;;AAAA;AAChE,YAAMQ,UAAU,SAAS,MAAI,CAACV,aAAL,CAAmBC,MAAnB,EAA2BC,QAA3B,CAAzB;AACA,aAAO,CAAC,CAACQ,UAAT;AAFgE;AAGjE;;AArJ0B","sourcesContent":["// @flow\nimport Permission from './Permission';\nimport Role from './Role';\nimport Base from './Base';\nimport type RBAC from './RBAC';\n\nexport default class Storage {\n useRBAC(rbac: RBAC): void {\n if (this.rbac) {\n throw new Error('Storage is already in use with another instance of RBAC');\n }\n\n this.rbac = rbac;\n }\n\n /**\n * Add permission or role\n * @method Storage#add\n * @param {Base} item Instance of role or permission\n */\n async add(item: Base): boolean {\n throw new Error('Storage method add is not implemented');\n }\n\n /**\n * Remove permission or role\n * @method Storage#remove\n * @param {Base} item Instance of role or permission\n */\n async remove(item: Base): boolean {\n throw new Error('Storage method remove is not implemented');\n }\n\n /**\n * Add (grant) permission or role to hierarchy of actual role\n * @method Storage#grant\n * @param {Role} role Instance of role\n * @param {Base} child Instance of role or permission\n */\n async grant(role: Role, child: Base): boolean {\n throw new Error('Storage method grant is not implemented');\n }\n\n /**\n * Remove (revoke) permission or role from hierarchy of actual role\n * @method Storage#revoke\n * @param {Role} role Instance of role\n * @param {Base} child Instance of role or permission\n */\n async revoke(role: Role, child: Base): boolean {\n throw new Error('Storage method revoke is not implemented');\n }\n\n /**\n * Get instance of permission or role by his name\n * @method Storage#get\n * @param {String} name Name of role or permission\n * @return {Base}\n */\n async get(name: string): ?Base {\n throw new Error('Storage method get is not implemented');\n }\n\n /**\n * Get all instances of Roles\n * @method Storage#getRoles\n * @return {Role[]}\n */\n async getRoles(): Role[] {\n throw new Error('Storage method getRoles is not implemented');\n }\n\n /**\n * Get all instances of Permissions\n * @method Storage#getPermissions\n * @return {Permission[]}\n */\n async getPermissions(): Permission[] {\n throw new Error('Storage method getPermissions is not implemented');\n }\n\n /**\n * Get instances of Roles and Permissions assigned to role\n * @method Storage#getGrants\n * @param {String} role Name of role\n * @return {Base[]}\n */\n async getGrants(role: string): Base[] {\n throw new Error('Storage method getGrants is not implemented');\n }\n\n /**\n * Get instance of role by his name\n * @method Storage#getRole\n * @param {String} name Name of role\n * @return {Role}\n */\n async getRole(name: string): ?Role {\n const role = await this.get(name);\n if (role && role instanceof Role) {\n return role;\n }\n\n return undefined;\n }\n\n /**\n * Get instance of permission by his name\n * @method Storage#getPermission\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {Permission} Instance of actual storage\n */\n async getPermission(action: string, resource: string): ?Permission {\n const name = Permission.createName(action, resource, this.rbac.options.delimiter);\n const item = await this.get(name);\n if (item && item instanceof Permission) {\n return item;\n }\n\n return undefined;\n }\n\n /**\n * Return true with callback if role or permission exists\n * @method Storage#exists\n * @param {string} name Name of role or permission\n * @return {boolean}\n */\n async exists(name: string): boolean {\n const item = await this.get(name);\n return !!item;\n }\n\n /**\n * Return true with callback if role exists\n * @method Storage#existsRole\n * @param {string} name Name of role\n * @return {boolean}\n */\n async existsRole(name: string): boolean {\n const role = await this.getRole(name);\n return !!role;\n }\n\n /**\n * Return true with callback if permission exists\n * @method Storage#existsPermission\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {boolean}\n */\n async existsPermission(action: string, resource: string): boolean {\n const permission = await this.getPermission(action, resource);\n return !!permission;\n }\n}\n"],"file":"Storage.js"}
1
+ {"version":3,"file":"Storage.js","names":["_Permission","_interopRequireDefault","require","_Role","_Base","e","__esModule","default","Storage","useRBAC","rbac","Error","add","item","remove","grant","role","child","revoke","get","name","getRoles","getPermissions","getGrants","getRole","Role","undefined","getPermission","action","resource","Permission","createName","options","delimiter","exists","existsRole","existsPermission","permission","exports"],"sources":["../src/Storage.js"],"sourcesContent":["// @flow\nimport Permission from './Permission';\nimport Role from './Role';\nimport Base from './Base';\nimport type RBAC from './RBAC';\n\nexport default class Storage {\n useRBAC(rbac: RBAC): void {\n if (this.rbac) {\n throw new Error('Storage is already in use with another instance of RBAC');\n }\n\n this.rbac = rbac;\n }\n\n /**\n * Add permission or role\n * @method Storage#add\n * @param {Base} item Instance of role or permission\n */\n async add(item: Base): boolean {\n throw new Error('Storage method add is not implemented');\n }\n\n /**\n * Remove permission or role\n * @method Storage#remove\n * @param {Base} item Instance of role or permission\n */\n async remove(item: Base): boolean {\n throw new Error('Storage method remove is not implemented');\n }\n\n /**\n * Add (grant) permission or role to hierarchy of actual role\n * @method Storage#grant\n * @param {Role} role Instance of role\n * @param {Base} child Instance of role or permission\n */\n async grant(role: Role, child: Base): boolean {\n throw new Error('Storage method grant is not implemented');\n }\n\n /**\n * Remove (revoke) permission or role from hierarchy of actual role\n * @method Storage#revoke\n * @param {Role} role Instance of role\n * @param {Base} child Instance of role or permission\n */\n async revoke(role: Role, child: Base): boolean {\n throw new Error('Storage method revoke is not implemented');\n }\n\n /**\n * Get instance of permission or role by his name\n * @method Storage#get\n * @param {String} name Name of role or permission\n * @return {Base}\n */\n async get(name: string): ?Base {\n throw new Error('Storage method get is not implemented');\n }\n\n /**\n * Get all instances of Roles\n * @method Storage#getRoles\n * @return {Role[]}\n */\n async getRoles(): Role[] {\n throw new Error('Storage method getRoles is not implemented');\n }\n\n /**\n * Get all instances of Permissions\n * @method Storage#getPermissions\n * @return {Permission[]}\n */\n async getPermissions(): Permission[] {\n throw new Error('Storage method getPermissions is not implemented');\n }\n\n /**\n * Get instances of Roles and Permissions assigned to role\n * @method Storage#getGrants\n * @param {String} role Name of role\n * @return {Base[]}\n */\n async getGrants(role: string): Base[] {\n throw new Error('Storage method getGrants is not implemented');\n }\n\n /**\n * Get instance of role by his name\n * @method Storage#getRole\n * @param {String} name Name of role\n * @return {Role}\n */\n async getRole(name: string): ?Role {\n const role = await this.get(name);\n if (role && role instanceof Role) {\n return role;\n }\n\n return undefined;\n }\n\n /**\n * Get instance of permission by his name\n * @method Storage#getPermission\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {Permission} Instance of actual storage\n */\n async getPermission(action: string, resource: string): ?Permission {\n const name = Permission.createName(action, resource, this.rbac.options.delimiter);\n const item = await this.get(name);\n if (item && item instanceof Permission) {\n return item;\n }\n\n return undefined;\n }\n\n /**\n * Return true with callback if role or permission exists\n * @method Storage#exists\n * @param {string} name Name of role or permission\n * @return {boolean}\n */\n async exists(name: string): boolean {\n const item = await this.get(name);\n return !!item;\n }\n\n /**\n * Return true with callback if role exists\n * @method Storage#existsRole\n * @param {string} name Name of role\n * @return {boolean}\n */\n async existsRole(name: string): boolean {\n const role = await this.getRole(name);\n return !!role;\n }\n\n /**\n * Return true with callback if permission exists\n * @method Storage#existsPermission\n * @param {string} action Name of action\n * @param {string} resource Name of resource\n * @return {boolean}\n */\n async existsPermission(action: string, resource: string): boolean {\n const permission = await this.getPermission(action, resource);\n return !!permission;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGX,MAAMG,OAAO,CAAC;EAC3BC,OAAOA,CAACC,IAAU,EAAQ;IACxB,IAAI,IAAI,CAACA,IAAI,EAAE;MACb,MAAM,IAAIC,KAAK,CAAC,yDAAyD,CAAC;IAC5E;IAEA,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB;;EAEA;AACF;AACA;AACA;AACA;EACE,MAAME,GAAGA,CAACC,IAAU,EAAW;IAC7B,MAAM,IAAIF,KAAK,CAAC,uCAAuC,CAAC;EAC1D;;EAEA;AACF;AACA;AACA;AACA;EACE,MAAMG,MAAMA,CAACD,IAAU,EAAW;IAChC,MAAM,IAAIF,KAAK,CAAC,0CAA0C,CAAC;EAC7D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMI,KAAKA,CAACC,IAAU,EAAEC,KAAW,EAAW;IAC5C,MAAM,IAAIN,KAAK,CAAC,yCAAyC,CAAC;EAC5D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMO,MAAMA,CAACF,IAAU,EAAEC,KAAW,EAAW;IAC7C,MAAM,IAAIN,KAAK,CAAC,0CAA0C,CAAC;EAC7D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMQ,GAAGA,CAACC,IAAY,EAAS;IAC7B,MAAM,IAAIT,KAAK,CAAC,uCAAuC,CAAC;EAC1D;;EAEA;AACF;AACA;AACA;AACA;EACE,MAAMU,QAAQA,CAAA,EAAW;IACvB,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