1.0.1 โ€ข Published 8 months ago

@mission-fabric/router-core v1.0.1

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

@mission-fabric/router-core

Overview

Mission Fabric Router Core is an enterprise-grade routing library designed to provide military-grade security with developer-friendly ergonomics. Built for organizations that require the utmost in security, reliability, and performance, while still maintaining superior developer experience.

// The easiest way to create an enterprise-grade API
import { Router, SecurityPolicies } from '@mission-fabric/router-core';

const router = new Router();

// Apply enterprise security with one line
router.use(SecurityPolicies.strictCSP());

// Define routes with strong typing and validation
router.addRoute({
  method: 'get',
  path: '/users/:id',
  auth: true,
  roles: ['admin'],
  handler: async (req, res) => {
    res.json({ id: req.params.id, name: 'John Doe' });
  }
});

// Connect to Express app
app.use(router.getRouter());

Key Features

  • ๐Ÿ”’ Military-Grade Security: RBAC, JWT, API keys, CSRF protection, rate limiting, and more
  • ๐Ÿš€ High Performance: Built-in performance monitoring, caching, compression, and circuit-breaking
  • ๐Ÿ“Š Observability: Detailed metrics, logging, and tracing capabilities built-in
  • ๐Ÿงฉ Modular Design: Use only what you need, from simple routes to full API gateway features
  • ๐Ÿ”„ Versioning: Easy API versioning and backward compatibility
  • ๐Ÿงช Testable: First-class testing support with mocks and test harnesses
  • ๐Ÿข Enterprise-Ready: Designed for large-scale applications and microservices
  • ๐Ÿ“˜ TypeScript-First: 100% TypeScript with comprehensive types for superb IDE integration

Installation

npm install @mission-fabric/router-core

Quick Start

Basic Router

import express from 'express';
import { Router } from '@mission-fabric/router-core';

const app = express();
const router = new Router();

// Add a simple GET route
router.addRoute({
  method: 'get',
  path: '/hello',
  handler: (req, res) => {
    res.send('Hello, world!');
  }
});

// Mount router with Express
app.use(router.getRouter());
app.listen(3000);

Secure API with Authentication

import { Router, MiddlewareFactory } from '@mission-fabric/router-core';

const router = new Router({
  security: {
    jwtSecret: process.env.JWT_SECRET,
    enableHelmet: true
  }
});

// Apply predefined security middleware
router.use(...MiddlewareFactory.apiSecurity({
  cors: { origin: 'https://example.com' },
  rateLimit: { max: 100, windowMs: 60000 } // 100 requests per minute
}));

// Secure route with authentication and roles
router.addRoute({
  method: 'post',
  path: '/admin/settings',
  auth: true,
  roles: ['admin'],
  handler: async (req, res) => {
    res.json({ success: true });
  }
});

Route Groups

// Group routes with shared middleware and prefix
const apiGroup = router.group('/api/v1', {
  middleware: [someSharedMiddleware],
  roles: ['user'] // Base role for all routes in this group
});

// Routes will be mounted at /api/v1/users
apiGroup.get('/users', listUsersHandler);
apiGroup.post('/users', createUserHandler, { roles: ['admin'] }); // Requires admin role

// Nested group for admin routes
const adminGroup = apiGroup.group('/admin', { roles: ['admin'] });
adminGroup.get('/stats', getStatsHandler);

Comprehensive Documentation

Visit our documentation site for detailed guides, API references, and examples.

Security Features

  • Request Validation: Prevent injection and other input attacks
  • RBAC: Fine-grained role-based access control
  • Rate Limiting: Protection against brute-force and DoS attacks
  • CSRF Protection: Built-in cross-site request forgery prevention
  • JWT Management: Secure token handling with key rotation support
  • Security Headers: CSP, HSTS, XSS protection, and more
  • API Key Authentication: For service-to-service communication
  • OAuth Integration: Connect with identity providers

Enterprise Support

Enterprise support plans are available. Contact our sales team for more information.

Contributing

We welcome contributions! See CONTRIBUTING.md for details.

License

MIT ยฉ Mission Fabric