UNPKG

@brandazm/dynamic-permissions

Version:

A flexible and powerful permissions management system for NestJS applications with built-in security features

92 lines 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationException = exports.CacheException = exports.MigrationException = exports.DatabaseException = exports.ConfigurationException = exports.RoleNotFoundException = exports.InvalidPermissionException = exports.PermissionDeniedException = void 0; const common_1 = require("@nestjs/common"); class PermissionDeniedException extends common_1.HttpException { constructor(permission, userId, metadata) { super({ message: `User ${userId} lacks permission: ${permission}`, errorCode: 'PERMISSION_DENIED', requiredPermission: permission, userId, metadata, }, common_1.HttpStatus.FORBIDDEN); } } exports.PermissionDeniedException = PermissionDeniedException; class InvalidPermissionException extends common_1.HttpException { constructor(permission, reason) { super({ message: `Invalid permission: ${permission}. Reason: ${reason}`, errorCode: 'INVALID_PERMISSION', permission, reason, }, common_1.HttpStatus.BAD_REQUEST); } } exports.InvalidPermissionException = InvalidPermissionException; class RoleNotFoundException extends common_1.HttpException { constructor(role) { super({ message: `Role not found: ${role}`, errorCode: 'ROLE_NOT_FOUND', role, }, common_1.HttpStatus.NOT_FOUND); } } exports.RoleNotFoundException = RoleNotFoundException; class ConfigurationException extends common_1.HttpException { constructor(errors) { super({ message: 'Configuration validation failed', errorCode: 'CONFIG_INVALID', errors, }, common_1.HttpStatus.INTERNAL_SERVER_ERROR); } } exports.ConfigurationException = ConfigurationException; class DatabaseException extends common_1.HttpException { constructor(operation, error) { super({ message: `Database operation failed: ${operation}`, errorCode: 'DATABASE_ERROR', operation, error: error.message, stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, }, common_1.HttpStatus.INTERNAL_SERVER_ERROR); } } exports.DatabaseException = DatabaseException; class MigrationException extends common_1.HttpException { constructor(type, details) { super({ message: `Migration error: ${details}`, errorCode: type, details, }, common_1.HttpStatus.INTERNAL_SERVER_ERROR); } } exports.MigrationException = MigrationException; class CacheException extends common_1.HttpException { constructor(operation, error) { super({ message: `Cache operation failed: ${operation}`, errorCode: 'CACHE_ERROR', operation, error: error.message, }, common_1.HttpStatus.INTERNAL_SERVER_ERROR); } } exports.CacheException = CacheException; class ValidationException extends common_1.HttpException { constructor(field, reason) { super({ message: `Validation failed for field: ${field}`, errorCode: 'VALIDATION_ERROR', field, reason, }, common_1.HttpStatus.BAD_REQUEST); } } exports.ValidationException = ValidationException; //# sourceMappingURL=permission.exceptions.js.map