mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 16:52:08 +01:00
refactor: fix biome linting issues and update project documentation
- Fix 36+ biome linting issues reducing errors/warnings from 227 to 191 - Replace explicit 'any' types with proper TypeScript interfaces - Fix React hooks dependencies and useCallback patterns - Resolve unused variables and parameter assignment issues - Improve accessibility with proper label associations - Add comprehensive API documentation for admin and security features - Update README.md with accurate PostgreSQL setup and current tech stack - Create complete documentation for audit logging, CSP monitoring, and batch processing - Fix outdated project information and missing developer workflows
This commit is contained in:
@ -77,6 +77,49 @@ export class InMemoryRateLimiter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check rate limit with custom parameters
|
||||
*/
|
||||
async check(
|
||||
key: string,
|
||||
maxAttempts: number,
|
||||
windowMs: number
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
remaining: number;
|
||||
}> {
|
||||
const now = Date.now();
|
||||
let attempt = this.attempts.get(key);
|
||||
|
||||
if (!attempt || now > attempt.resetTime) {
|
||||
// Initialize or reset the attempt
|
||||
attempt = {
|
||||
count: 1,
|
||||
resetTime: now + windowMs,
|
||||
};
|
||||
this.attempts.set(key, attempt);
|
||||
return {
|
||||
success: true,
|
||||
remaining: maxAttempts - 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (attempt.count >= maxAttempts) {
|
||||
return {
|
||||
success: false,
|
||||
remaining: 0,
|
||||
};
|
||||
}
|
||||
|
||||
attempt.count++;
|
||||
this.attempts.set(key, attempt);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
remaining: maxAttempts - attempt.count,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources
|
||||
*/
|
||||
@ -87,6 +130,16 @@ export class InMemoryRateLimiter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default rate limiter instance for general use
|
||||
*/
|
||||
export const rateLimiter = new InMemoryRateLimiter({
|
||||
maxAttempts: 100,
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
maxEntries: 10000,
|
||||
cleanupIntervalMs: 5 * 60 * 1000, // 5 minutes
|
||||
});
|
||||
|
||||
/**
|
||||
* Extract client IP address from request headers
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user