access-matrix
v0.1.2
Published
A flexible and extensible access control library for Node.js applications, currently supporting SQLite with a clean, type-safe API. Designed to be easily extensible for additional database backends in the future.
Maintainers
Readme
Access Matrix
A lightweight, type-safe access control library for Node.js with SQLite and PostgreSQL support.
Features
- 🔒 Role-based and permission-based access control
- 🛠️ Extensible adapter architecture
- 🚀 Built with TypeScript for better developer experience
- ⚡ Simple and intuitive API
- 🗄️ Database Support:
- ✅ SQLite (built-in)
- ✅ PostgreSQL
- 📅 Auto-loading routes from source code
Installation
npm install access-matrix
# or
yarn add access-matrixQuick Start
TypeScript
import AccessControl, { RouteData } from 'access-matrix';
interface AppRoute extends RouteData {
requiresAuth?: boolean;
}
const ac = await AccessControl.create<AppRoute>({
type: 'sqlite',
database: './access.db'
});Auto-Loading Routes
The access-matrix library can automatically detect and load routes from your source files.
Configuration
Create config/database.json:
{
"database": {
"type": "sqlite",
"config": {
"sqlite": {
"mode": "file",
"file_name": "access-matrix.db"
}
}
},
"route": {
"loading": "auto",
"auto": {
"directories": ["src/routes", "api", "controllers"],
"patterns": ["**/*.ts", "**/*.js"],
"recursive": true,
"exclude": ["node_modules", "*.test.*"]
}
}
}Usage
import { AccessControl, loadRoutes } from 'access-matrix';
async function setupAccessControl() {
const configPath = './config/database.json';
const accessControl = await AccessControl.create(configPath);
// Auto-load routes from configured directories
const routes = await loadRoutes(configPath);
console.log(`Found ${routes.length} routes:`);
routes.forEach((route, index) => {
console.log(`${index + 1}. ${route.method} ${route.path}`);
});
// Sync routes to database
const syncResult = await accessControl.syncRoutes(routes);
console.log(`Synced: ${syncResult.added} added, ${syncResult.removed} removed`);
return accessControl;
}Supported Frameworks
- Express.js -
router.get(),router.post(), etc. - Fastify -
fastify.get(),fastify.post(), etc. - NestJS -
@Get(),@Post(),@Put()decorators - Koa.js -
router.get(),router.post(), etc.
See Route Patterns Documentation for detailed examples.
Documentation
Development
# Install dependencies
npm install
# Build the project
npm run build
# Run examples
npm run example
npm run example:postgres
npm run example:autoload📝 Reviews & Feedback
We'd love to hear your feedback! Help us improve access-matrix:
🌟 Rate This Package
📋 Quick Review Form
Copy this template and share your experience:
## Review: access-matrix
**⭐ Rating:** ★★★★★☆ (1-5 stars)
**🚀 Use Case:** What are you using it for?
- [ ] Role-based access control
- [ ] API route protection
- [ ] Database permissions
- [ ] Auto-loading routes
- [ ] Other: _________
**✅ What Works Well:**
-
-
**💡 Suggestions for Improvement:**
-
-
**🔧 Technical Details:**
- Node.js version: _________
- Database: [ ] SQLite [ ] PostgreSQL [ ] Other
- TypeScript: [ ] Yes [ ] No
**📝 Overall Experience:**
_______________________________________________________🎯 How to Share Your Review
- GitHub Issue: Use the template above in Issues
- GitHub Discussion: Start a Discussion
- Detailed Template: See REVIEW_TEMPLATE.md for comprehensive feedback
📊 Review Analytics
We track all feedback to improve access-matrix:
- ⭐ Ratings help us know what we're doing right
- 🐛 Bug reports get immediate attention
- 💡 Suggestions shape future development
- 📝 Documentation feedback improves examples
🙏 Thank You!
Your feedback helps us improve access-matrix for everyone! 🚀
📝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT
