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

mvc-common-toolkit

v1.45.2

Published

This package contains common toolkits like query string parser, filter parser,... and other reusable patterns for any web projects

Readme

Common Toolkit

npm version License: MIT TypeScript

A comprehensive TypeScript toolkit providing common utilities, services, and patterns for modern web applications. Built with scalability, reliability, and developer experience in mind.

🚀 Features

Core Utilities

  • Query & Filter Parsing - Advanced query string and filter parsing with support for complex operators
  • String & Object Helpers - Comprehensive utilities for string manipulation and object operations
  • Array & Collection Helpers - Efficient array operations and collection management
  • Crypto & Security - Bcrypt helpers and cryptographic utilities
  • HTTP Request Utils - Enhanced HTTP request handling and utilities
  • GeoIP Support - Geographic IP location utilities
  • Excel Processing - Excel file generation and manipulation
  • Logging - Structured logging with Pino

Workflow & Task Management

  • Sync Task Queue - In-memory task queue for single-instance applications
  • Distributed Task Queue - Multi-instance distributed task queue with external queue engines
  • Delayed Task Registry - Scheduled task execution with retry mechanisms
  • Retry Task System - Robust retry logic with exponential backoff
  • Processing Milestones - Task progress tracking and milestone management

Services & Integrations

  • Redis Service - Comprehensive Redis client with caching, lists, and hash operations
  • Kafka Service - Message queue integration with Kafka
  • HTTP Service - Enhanced HTTP client with request/response handling
  • Mailer Service - Email sending capabilities
  • Security Service - Authentication and authorization utilities
  • Audit Service - Comprehensive audit logging
  • Paginated Cache - High-performance paginated data caching

Cloud & External Integrations

  • Alibaba Cloud Gateway - Alibaba Cloud service integrations
  • Audit Gateways - Multiple audit logging destinations (HTTP, Webhook, Stdout)
  • Internal Auth Gateway - Internal service authentication

Distributed Systems

  • Redis Queue Engine - Production-ready Redis-based queue engine
  • Distributed Locking - Reliable distributed locking mechanisms
  • Consumer Coordination - Single consumer across multiple instances
  • Message Serialization - Efficient message serialization and deserialization

📦 Installation

npm install mvc-common-toolkit
# or
yarn add mvc-common-toolkit

🔧 Quick Start

Basic Usage

import {
  queryHelper,
  filterHelpers,
  stringUtils,
  loggers,
} from "mvc-common-toolkit";

// Parse query parameters
const query = queryHelper.parseQueryString("page=1&limit=10&sort=name:asc");

// Apply filters
const filters = filterHelpers.parseFilters([
  { field: "status", operator: "eq", value: "active" },
  { field: "age", operator: "gte", value: 18 },
]);

// String utilities
const slug = stringUtils.slugify("Hello World!"); // hello-world

// Logging
const logger = loggers.PinoLogger;
logger.info("Application started");

Distributed Task Queue

import {
  DistributedTaskQueueFactory,
  RedisQueueEngine,
} from "mvc-common-toolkit";

// Create Redis queue engine
const redisEngine = new RedisQueueEngine({
  redis: { host: "localhost", port: 6379 },
  instanceId: "service-instance-1",
});

await redisEngine.connect();

// Create distributed task queue
const taskQueue = DistributedTaskQueueFactory.createWithDefaults(redisEngine);

// Start consumer (only one active across all replicas)
await taskQueue.startConsumer("order-processing-queue");

// Push tasks from any replica
const result = await taskQueue.push(
  "order-processing-queue",
  "process-order",
  async () => {
    // Task logic here
    return { orderId: "123", status: "processed" };
  }
);

Redis Service

import { RedisService } from "mvc-common-toolkit";

const redisService = new RedisService({
  host: "localhost",
  port: 6379,
  db: 0,
});

// Cache operations
await redisService.set("user:123", { name: "John", email: "[email protected]" });
const user = await redisService.get("user:123");

// List operations
await redisService.lpush("queue:orders", JSON.stringify(order));
const order = await redisService.brpop("queue:orders", 1);

// Hash operations
await redisService.hset("user:123", "lastLogin", new Date().toISOString());
const lastLogin = await redisService.hget("user:123", "lastLogin");

Query & Filter Parsing

import { queryHelper, filterHelpers } from "mvc-common-toolkit";

// Parse complex query strings
const query = queryHelper.parseQueryString(
  "page=1&limit=20&sort=name:asc,createdAt:desc&filter=status:eq:active,age:gte:18"
);

// Parse filters
const filters = filterHelpers.parseFilters([
  { field: "status", operator: "eq", value: "active" },
  { field: "age", operator: "gte", value: 18 },
  { field: "tags", operator: "in", value: ["javascript", "typescript"] },
  { field: "name", operator: "like", value: "john" },
]);

// Build SQL WHERE clause
const whereClause = filterHelpers.buildWhereClause(filters);

Excel Processing

import { excelService } from "mvc-common-toolkit";

// Generate Excel file
const workbook = await excelService.createWorkbook();
const worksheet = workbook.addWorksheet("Users");

// Add data
const users = [
  { id: 1, name: "John Doe", email: "[email protected]" },
  { id: 2, name: "Jane Smith", email: "[email protected]" },
];

await excelService.addDataToWorksheet(worksheet, users, {
  headers: ["ID", "Name", "Email"],
  startRow: 1,
});

// Save file
await excelService.saveWorkbook(workbook, "users.xlsx");

🏗️ Architecture

Package Structure

src/
├── constants.ts              # Application constants and enums
├── interfaces.ts             # TypeScript interfaces and types
├── index.ts                  # Main package exports
├── pkg/                      # Core utilities and helpers
│   ├── array-helper.ts       # Array manipulation utilities
│   ├── bcrypt-helper.ts      # Password hashing utilities
│   ├── crypto-helper.ts      # Cryptographic utilities
│   ├── filter-helper.ts      # Query filter parsing and building
│   ├── geoip-helper.ts       # Geographic IP utilities
│   ├── hash-helper.ts        # Hash generation utilities
│   ├── http-request-utils.ts # HTTP request utilities
│   ├── key-helper.ts         # Key generation utilities
│   ├── logger.ts             # Logging utilities
│   ├── object-helper.ts      # Object manipulation utilities
│   ├── query-helper.ts       # Query string parsing
│   ├── sort-helper.ts        # Sorting utilities
│   ├── string-utils.ts       # String manipulation utilities
│   ├── task-helper.ts        # Task execution utilities
│   ├── worksheet.utils.ts    # Excel worksheet utilities
│   └── workflow/             # Workflow and task management
│       ├── delayed-task-registry.ts
│       ├── delayed-task.ts
│       ├── distributed-sync-taskqueue.ts
│       ├── distributed-taskqueue-factory.ts
│       ├── processing-milestone.ts
│       ├── retry-task.ts
│       └── sync-taskqueue.ts
├── services/                 # Service integrations
│   ├── audit-service.ts      # Audit logging service
│   ├── excel.service.ts      # Excel processing service
│   ├── http-service.ts       # HTTP client service
│   ├── kafka-service.ts      # Kafka integration service
│   ├── mailer-service.ts     # Email service
│   ├── paginated-cache.ts    # Paginated caching service
│   ├── redis-service.ts      # Redis client service
│   ├── redis-queue-engine.ts # Redis queue engine
│   └── security-service.ts   # Security utilities service
├── gateways/                 # External service gateways
│   ├── alibaba-cloud-gateway.ts
│   ├── http-audit-gateway.ts
│   ├── internal-auth-gateway.ts
│   ├── stdout-audit-gateway.ts
│   └── webhook-audit-gateway.ts
└── models/                   # Data models
    └── audit-log.ts          # Audit log model

🔌 Available Services

Core Services

| Service | Description | Features | | ------------------- | ----------------------------------------------------- | -------------------------------------- | | RedisService | Redis client with caching, lists, and hash operations | Caching, Queuing, Distributed locking | | KafkaService | Kafka message queue integration | Producer/Consumer, Topic management | | HttpService | Enhanced HTTP client | Request/Response handling, Retry logic | | MailerService | Email sending capabilities | SMTP, Template support | | SecurityService | Authentication and authorization | JWT, Password hashing | | AuditService | Comprehensive audit logging | Multiple destinations, Structured logs | | ExcelService | Excel file processing | Read/Write, Formatting, Templates |

Queue Engines

| Engine | Description | Use Case | | -------------------- | ----------------------------- | -------------------------------- | | RedisQueueEngine | Redis-based distributed queue | High-performance, Reliable | | KafkaQueueEngine | Kafka-based queue (planned) | High-throughput, Event streaming |

🛠️ Development

Prerequisites

  • Node.js 16+
  • TypeScript 5.0+
  • Redis (for queue functionality)
  • Kafka (optional, for message queuing)

Setup

# Clone the repository
git clone https://github.com/andydevstic/common-toolkit.git
cd common-toolkit

# Install dependencies
yarn install

# Run tests
yarn test

# Build the project
yarn build

Testing

# Run all tests
yarn test

# Run specific test file
yarn test src/services/redis-queue-engine.spec.ts

# Run tests with coverage
yarn test -- --reporter spec --require ts-node/register

📚 API Documentation

Query Helpers

// Parse query string
const query = queryHelper.parseQueryString("page=1&limit=10&sort=name:asc");

// Build query string
const queryString = queryHelper.buildQueryString({
  page: 1,
  limit: 10,
  sort: "name:asc",
});

Filter Helpers

// Parse filters
const filters = filterHelpers.parseFilters([
  { field: "status", operator: "eq", value: "active" },
  { field: "age", operator: "gte", value: 18 },
]);

// Build SQL WHERE clause
const whereClause = filterHelpers.buildWhereClause(filters);

// Validate filters
const isValid = filterHelpers.validateFilters(filters);

String Utilities

// Slugify
const slug = stringUtils.slugify("Hello World!"); // hello-world

// Generate random string
const random = stringUtils.generateRandomString(10);

// Truncate
const truncated = stringUtils.truncate("Long text here", 10); // Long text...

Workflow Management

// Delayed task registry
const registry = new DelayedTaskRegistry();
await registry.register({
  callback: () => console.log("Task executed"),
  timeout: 5000,
  startOnCreate: true,
});

// Retry task
const retryTask = new RetryTask({
  maxAttempts: 3,
  backoffMs: 1000,
  task: async () => {
    /* task logic */
  },
});
await retryTask.execute();

🚀 Performance

Benchmarks

  • Query Parsing: ~10,000 ops/sec
  • Filter Building: ~5,000 ops/sec
  • Redis Operations: ~50,000 ops/sec
  • Task Queue: ~1,000 tasks/sec

Memory Usage

  • Base Package: ~2MB
  • With Redis: ~5MB
  • With Kafka: ~8MB

🔒 Security

  • Password Hashing: Bcrypt with configurable rounds
  • JWT Support: Secure token generation and validation
  • Input Validation: Comprehensive input sanitization
  • Audit Logging: Security event tracking

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write comprehensive tests
  • Update documentation
  • Follow the existing code style
  • Add type definitions for new features

📄 License

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

🙏 Acknowledgments

📞 Support


Made with ❤️ by Andy Devstic