
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
mvc-common-toolkit
Advanced tools
This package contains common toolkits like query string parser, filter parser,... and other reusable patterns for any web projects
A comprehensive TypeScript toolkit providing common utilities, services, and patterns for modern web applications. Built with scalability, reliability, and developer experience in mind.
npm install mvc-common-toolkit
# or
yarn add mvc-common-toolkit
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");
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" };
}
);
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: "john@example.com" });
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");
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);
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: "john@example.com" },
{ id: 2, name: "Jane Smith", email: "jane@example.com" },
];
await excelService.addDataToWorksheet(worksheet, users, {
headers: ["ID", "Name", "Email"],
startRow: 1,
});
// Save file
await excelService.saveWorkbook(workbook, "users.xlsx");
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
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 |
Engine | Description | Use Case |
---|---|---|
RedisQueueEngine | Redis-based distributed queue | High-performance, Reliable |
KafkaQueueEngine | Kafka-based queue (planned) | High-throughput, Event streaming |
# 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
# 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
// 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",
});
// 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);
// 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...
// 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();
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
Made with ā¤ļø by Andy Devstic
FAQs
This package contains common toolkits like query string parser, filter parser,... and other reusable patterns for any web projects
The npm package mvc-common-toolkit receives a total of 650 weekly downloads. As such, mvc-common-toolkit popularity was classified as not popular.
We found that mvc-common-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.