1.0.5 • Published 5 months ago

ts-can v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

ts-can

License npm version

Small 0 dependencies TypeScript library for managing and checking user permissions

Table of Contents

Installation

npm install ts-can

Usage

import { Permissions, TestRules, checkPermissions, canAllow } from 'permissions-library';

// Define user permissions
const userPermissions: Permissions = {
  'moduleA': {
    abilities: { read: true, write: false },
    checks: { isAdmin: (target) => target.isAdmin }
  },
  'moduleB': {
    abilities: { read: true, write: true },
    checks: { hasAccess: (target) => target.isValidUser }
  },
  // ... other modules
};

// Define test rules
const testRules: TestRules = {
  'moduleA': { abilities: ['read'] },
  'moduleB': { checks: ['hasAccess'], target: { isValidUser: true } },
  // ... other test rules
};

// Check if user has required permissions for all test rules
const result = canAllow(userPermissions, testRules);
console.log(result); // Output: true

API Documentation

Please refer to the official documentation for detailed information about the API and usage examples.

1.0.5

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago