UNPKG

qapinterface

Version:

Comprehensive API utilities for Node.js applications including authentication, security, request processing, and response handling with zero external dependencies

61 lines (48 loc) 2.66 kB
# Library Folder This folder contains the core API utility modules organized by responsibility area. ## Purpose - Houses enterprise-grade API utility functions - Provides lightweight, production-ready modules - Implements security-first design patterns - Offers comprehensive testing coverage ## Module Organization ### Core Utilities (`/core`, `/utility`, `/data`) - `validation/`: Email validation, API path validation, request structure validation - `data/sanitizer.js`: Removes sensitive information from API responses - `id/generator.js`: Generates unique identifiers for tracking - `versioning/formatter.js`: Formats API version strings consistently ### HTTP Modules (`/http`) - `success-response-creator.js`: Creates standardized success responses - `error-response-creator.js`: Creates standardized error responses - `json-response-sender.js`: Safely sends JSON responses with error handling - `response-validator.js`: Validates Fetch API responses with comprehensive error handling - `api-request.js`: Standardized HTTP methods (GET, POST, PUT, DELETE, PATCH) ### Security Modules (`/security`) - `csp-*.js`: Content Security Policy headers and nonce generation - `https-enforcer.js`: HTTPS enforcement middleware - `*-detector.js`: Threat detection (SQL injection, XSS, path traversal) - `pattern-analyzer.js`: Advanced security pattern analysis - `event-logger.js`: Security event logging ### Authentication (`/authentication`) - `api-key-extractor.js`: Multi-source API key extraction - `api-key-validator.js`: Format validation and timing-safe comparison - `api-key-middleware.js`: Express middleware for API key validation ### Request Processing (`/request`) - `id-generator.js`: Request ID generation with correlation - `context-extractor.js`: Extracts request metadata and timing - `structure-validator.js`: Validates request structure and payload limits ### Services (`/services`) - `async-validator.js`: Async service validation with timeout handling - `health-checker.js`: Multi-service health monitoring - `retry-handler.js`: Exponential backoff retry logic ### Logging (`/logging`) - `console-logger.js`: Lightweight console logging with timestamps - Source-bound loggers for consistent messaging ### Utilities (`/url`, `/timing`, `/rate-limiting`) - `url/`: Security-first URL parsing, validation, and construction - `timing/`: High-precision performance timing utilities - `rate-limiting/`: Memory-efficient sliding window rate limiting ## Testing Structure - Unit tests: `lib/**/__tests__` (co-located with modules) - Integration tests: `tests/` (top-level directory) - Test runner: `qtests` framework via `test-runner.js`