A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/levi2ki/improved-rbac below:

GitHub - levi2ki/improved-rbac

A modern, type-safe Role-Based Access Control (RBAC) system built with TypeScript and functional programming principles. This monorepo provides a comprehensive solution for implementing robust permission systems in your applications.

@levi2ki/rbac-core - Foundation Library

The core RBAC system that provides the building blocks for permission management:

@levi2ki/rbac-expression - DSL for Complex Permissions ⭐

A powerful Domain Specific Language for building complex permission expressions with full type safety:

import { createExpression } from '@levi2ki/rbac-expression';
import { createModule, getDefaultRegistry, register } from '@levi2ki/rbac-core';
import { pipe } from 'fp-ts/function';
import * as Option from 'fp-ts/Option';

// Define permissions
enum UserPermissions {
    READ = 'READ',
    WRITE = 'WRITE',
    DELETE = 'DELETE',
    ADMIN = 'ADMIN',
}

enum TeamPermissions {
    MANAGE = 'MANAGE',
    VIEW = 'VIEW',
}

// Create registry
const registry = pipe(getDefaultRegistry(), register(createModule<UserPermissions>()('user')), register(createModule<TeamPermissions>()('team')));

// Create expressions
const { has, not, and, or } = createExpression(registry);

// Build complex permission logic
const canEditSensitiveData = and([has('user.WRITE'), or([has('user.ADMIN'), has('team.MANAGE')]), not('user.RESTRICTED')]);

// Evaluate against user context
const userContext = {
    user: Option.some([UserPermissions.WRITE, UserPermissions.ADMIN]),
    team: Option.some([TeamPermissions.VIEW]),
};

const result = canEditSensitiveData(userContext);
console.log(result); // true

✨ Key Features:

📖 Read More →

@levi2ki/rbac-react - React Integration (Coming Soon! 🚧)

React hooks and components for seamless RBAC integration in React applications:

# Install the entire monorepo
pnpm add @levi2ki/rbac-core @levi2ki/rbac-expression

# Or install individual packages
pnpm add @levi2ki/rbac-core
pnpm add @levi2ki/rbac-expression
  1. Set up your permission modules:
import { createModule, getDefaultRegistry, register } from '@levi2ki/rbac-core';

const registry = pipe(getDefaultRegistry(), register(createModule<UserPermissions>()('user')), register(createModule<TeamPermissions>()('team')));
  1. Create expressions:
import { createExpression } from '@levi2ki/rbac-expression';

const { has, and, or } = createExpression(registry);

const canAccessAdminPanel = and([has('user.ADMIN'), or([has('user.SUPER_USER'), has('team.ADMIN')])]);
  1. Evaluate permissions:
const userContext = {
    user: Option.some([UserPermissions.ADMIN]),
    team: Option.some([TeamPermissions.VIEW]),
};

const hasAccess = canAccessAdminPanel(userContext);
improved-rbac/
├── packages/
│   ├── rbac-core/          # Core RBAC system
│   ├── rbac-expression/    # DSL for complex permissions
│   └── rbac-react/         # React integration (coming soon)
├── examples/               # Usage examples
└── docs/                  # Documentation

This is a monorepo built with Nx and managed with pnpm.

# Install dependencies
pnpm install

# Run tests
nx test

# Build packages
nx build

# Run linting
nx lint

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: nx test
  5. Commit your changes: git commit -m 'feat: add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

This project is licensed under the MIT License - see the LICENSE file for details.

Ready to build robust permission systems? Start with @levi2ki/rbac-core for the foundation, then explore @levi2ki/rbac-expression for complex permission logic! 🚀


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4