npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sequelize-guard

v6.0.2

Published

An Authorization Library for Sequelize

Readme

Sequelize Guard

A powerful, type-safe authorization library for Sequelize.js


About

SequelizeGuard is a comprehensive authorization library for Sequelize.js that provides a robust, performant, and easy-to-use role-based access control (RBAC) system. Built with TypeScript and modern tooling, it enables you to manage complex permission structures with a clean, fluent API.

✨ What's New in v6

Sequelize Guard v6 is a complete rewrite with major improvements:

  • 🎯 Full TypeScript Support - Complete rewrite in TypeScript with full type definitions
  • Sequelize 6 Compatible - Updated to work with Sequelize v6.x
  • ESM & CommonJS - Dual package support for modern and legacy projects
  • 🏗️ Modern Tooling - Built with Vite, tested with Vitest
  • Better Type Safety - Enhanced IntelliSense and compile-time checking
  • 99% Backward Compatible - Minimal breaking changes from v5.x

Upgrading from v5? Check out the Migration Guide for a smooth transition.

Features

  • 🚀 Fast & Efficient - Cache-based permission resolution for optimal performance
  • 🎯 Intuitive API - Fluent, semantic API that reads like natural language
  • 🔐 Flexible RBAC - Assign multiple roles and permissions to users
  • 📊 Event-Driven - Listen for authorization events for logging and auditing
  • 💾 Smart Caching - Configurable user permission caching
  • 🛡️ Safe Operations - Built-in safeguards for role and permission deletions

Installation

# npm
npm install sequelize-guard sequelize

# yarn
yarn add sequelize-guard sequelize

# pnpm
pnpm add sequelize-guard sequelize

Requirements:

  • Node.js ≥ 20.19.0
  • Sequelize ≥ 6.37.7

Quick Start

import { Sequelize } from 'sequelize';
import SequelizeGuard from 'sequelize-guard';

const sequelize = new Sequelize(/* config */);
const guard = new SequelizeGuard(sequelize);

// Assign roles and permissions
await user.assignRole('admin');
await guard.allow('admin', ['view', 'edit'], 'blog');

// Check permissions
const canEdit = await user.can('edit blog');
const isAdmin = await user.isA('admin');

Note: Works with both TypeScript and JavaScript (ESM/CommonJS). See documentation for JavaScript examples.

Documentation

For comprehensive guides, API reference, and examples, visit our documentation:

📖 https://sequelize-guard.js.org

📖 (Fallback: https://sequelize-guard.vercel.app)

Key Topics

Migration

Core Concepts

Permission Checks

// Check specific permission
await user.can('edit blog');

// Check wildcard permissions
await user.can('* blog'); // All actions on blog
await user.can('view *'); // View all resources
await user.can('*'); // Superadmin - all actions on all resources

Role Checks

// Check single role
await user.isA('admin');
await user.isAn('editor');

// Check multiple roles
await user.isAnyOf(['admin', 'moderator']); // Has any of these roles
await user.isAllOf(['user', 'verified']); // Has all of these roles

Assigning Permissions

// Fluent API
await guard
  .init()
  .allow('admin')
  .to(['view', 'edit', 'delete'])
  .on('blog')
  .commit();

// One-liner
await guard.allow('admin', ['view', 'edit'], 'blog');

For more details, visit the full documentation.

Contributing

We love contributions! SequelizeGuard is open source and we welcome contributions of all kinds:

  • 🐛 Bug fixes
  • ✨ New features
  • 📝 Documentation improvements
  • ✅ Test coverage improvements
  • 💡 Ideas and suggestions
# Clone the repository
git clone https://github.com/lotivo/sequelize-guard.git
cd sequelize-guard

# Install dependencies
yarn install

# Run tests
yarn test

# Build
yarn build

Documentation

Generating API Documentation

API documentation is automatically generated from TypeScript source code:

# Generate API docs manually
yarn docs:generate

The API documentation is automatically updated after each release via GitHub Actions. See scripts/README.md for details.

Reporting Issues

Found a bug or have a feature request? Open an issue with:

  • Clear description
  • Steps to reproduce (for bugs)
  • Your environment (Node, Sequelize, sequelize-guard versions)

License

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

Acknowledgments

Influences

Alternatives

  • Node-ACL - A versatile library with support for most ORMs
  • AccessControl - Role and attribute-based access control
  • CASL - Isomorphic authorization library

Support

Need help? Here's how to get support:


Created by Pankaj Vaghela for Open Source Community.

If you find this project helpful, please consider giving it a ⭐️!