mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 12:12:09 +01:00
feat: complete development environment setup and code quality improvements
- Set up pre-commit hooks with husky and lint-staged for automated code quality - Improved TypeScript type safety by replacing 'any' types with proper generics - Fixed markdown linting violations (MD030 spacing) across all documentation - Fixed compound adjective hyphenation in technical documentation - Fixed invalid JSON union syntax in API documentation examples - Automated code formatting and linting on commit - Enhanced error handling with better type constraints - Configured biome and markdownlint for consistent code style - All changes verified with successful production build
This commit is contained in:
@ -6,19 +6,19 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
PerformanceEnhanced,
|
||||
PerformanceOptimized,
|
||||
Cached,
|
||||
Deduplicated,
|
||||
Monitored,
|
||||
PerformanceEnhanced,
|
||||
PerformanceOptimized,
|
||||
} from "../performance/integration";
|
||||
import { AuditOutcome, AuditSeverity } from "../securityAuditLogger";
|
||||
import { AlertChannel, type MonitoringConfig } from "../securityMonitoring";
|
||||
import type { Alert, SecurityEvent } from "../types/security";
|
||||
import { ThreatLevel } from "../types/security";
|
||||
import { AlertManagementService } from "./AlertManagementService";
|
||||
import { SecurityEventProcessor } from "./SecurityEventProcessor";
|
||||
import { ThreatDetectionService } from "./ThreatDetectionService";
|
||||
import { AlertManagementService } from "./AlertManagementService";
|
||||
import { AlertChannel, type MonitoringConfig } from "../securityMonitoring";
|
||||
import { AuditOutcome, AuditSeverity } from "../securityAuditLogger";
|
||||
import { ThreatLevel } from "../types/security";
|
||||
import type { SecurityEvent, Alert } from "../types/security";
|
||||
|
||||
/**
|
||||
* Configuration for enhanced security service
|
||||
@ -161,26 +161,31 @@ export class EnhancedSecurityService {
|
||||
{ metadata: event.metadata }, // Cast to AuditLogContext
|
||||
event.metadata
|
||||
);
|
||||
|
||||
|
||||
// Return threat level based on detected threats
|
||||
if (result.threats.length === 0) {
|
||||
return ThreatLevel.LOW;
|
||||
}
|
||||
|
||||
|
||||
// Find the highest severity threat
|
||||
const highestSeverity = result.threats.reduce((max, threat) => {
|
||||
const severityOrder = { LOW: 1, MEDIUM: 2, HIGH: 3, CRITICAL: 4 };
|
||||
const current = severityOrder[threat.severity as keyof typeof severityOrder] || 1;
|
||||
const current =
|
||||
severityOrder[threat.severity as keyof typeof severityOrder] || 1;
|
||||
const maxVal = severityOrder[max as keyof typeof severityOrder] || 1;
|
||||
return current > maxVal ? threat.severity : max;
|
||||
}, "LOW" as any);
|
||||
|
||||
|
||||
// Map AlertSeverity to ThreatLevel
|
||||
switch (highestSeverity) {
|
||||
case "CRITICAL": return ThreatLevel.CRITICAL;
|
||||
case "HIGH": return ThreatLevel.HIGH;
|
||||
case "MEDIUM": return ThreatLevel.MEDIUM;
|
||||
default: return ThreatLevel.LOW;
|
||||
case "CRITICAL":
|
||||
return ThreatLevel.CRITICAL;
|
||||
case "HIGH":
|
||||
return ThreatLevel.HIGH;
|
||||
case "MEDIUM":
|
||||
return ThreatLevel.MEDIUM;
|
||||
default:
|
||||
return ThreatLevel.LOW;
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,7 +354,7 @@ export class EnhancedSecurityService {
|
||||
// cache: {
|
||||
// enabled: true,
|
||||
// ttl: 10 * 60 * 1000, // 10 minutes
|
||||
// keyGenerator: (query: any) => `search:${JSON.stringify(query)}`,
|
||||
// keyGenerator: (query: Record<string, unknown>) => `search:${JSON.stringify(query)}`,
|
||||
// },
|
||||
// deduplication: {
|
||||
// enabled: true,
|
||||
@ -394,11 +399,11 @@ export class EnhancedSecurityService {
|
||||
private calculateThreatDistribution(
|
||||
events: SecurityEvent[]
|
||||
): Record<ThreatLevel, number> {
|
||||
return {
|
||||
[ThreatLevel.LOW]: 0,
|
||||
[ThreatLevel.MEDIUM]: 0,
|
||||
[ThreatLevel.HIGH]: 0,
|
||||
[ThreatLevel.CRITICAL]: 0
|
||||
return {
|
||||
[ThreatLevel.LOW]: 0,
|
||||
[ThreatLevel.MEDIUM]: 0,
|
||||
[ThreatLevel.HIGH]: 0,
|
||||
[ThreatLevel.CRITICAL]: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@ -441,7 +446,9 @@ export class EnhancedSecurityService {
|
||||
};
|
||||
}
|
||||
|
||||
private async performSearch(query: any): Promise<SecurityEvent[]> {
|
||||
private async performSearch(
|
||||
query: Record<string, unknown>
|
||||
): Promise<SecurityEvent[]> {
|
||||
// Mock search implementation
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ export class SecurityMetricsService {
|
||||
.slice(0, 5);
|
||||
|
||||
// User risk scores - transform data to match expected format
|
||||
const transformedEvents = events.map(event => ({
|
||||
const transformedEvents = events.map((event) => ({
|
||||
userId: event.userId || undefined,
|
||||
user: event.user ? { email: event.user.email } : undefined,
|
||||
eventType: event.eventType as SecurityEventType,
|
||||
@ -76,7 +76,8 @@ export class SecurityMetricsService {
|
||||
severity: event.severity as AuditSeverity,
|
||||
country: event.country || undefined,
|
||||
}));
|
||||
const userRiskScores = await this.calculateUserRiskScores(transformedEvents);
|
||||
const userRiskScores =
|
||||
await this.calculateUserRiskScores(transformedEvents);
|
||||
|
||||
// Calculate overall security score
|
||||
const securityScore = this.calculateSecurityScore({
|
||||
@ -122,7 +123,9 @@ export class SecurityMetricsService {
|
||||
country?: string;
|
||||
}>
|
||||
): Promise<Array<{ userId: string; email: string; riskScore: number }>> {
|
||||
const userEvents = events.filter((e) => e.userId) as Array<typeof events[0] & { userId: string }>;
|
||||
const userEvents = events.filter((e) => e.userId) as Array<
|
||||
(typeof events)[0] & { userId: string }
|
||||
>;
|
||||
const userScores = new Map<
|
||||
string,
|
||||
{ email: string; score: number; events: typeof userEvents }
|
||||
|
||||
@ -139,7 +139,7 @@ export class ThreatDetectionService {
|
||||
// Check for geographical anomalies
|
||||
if (context.country && context.userId) {
|
||||
// Transform historical events to match expected type
|
||||
const transformedEvents = historicalEvents.map(event => ({
|
||||
const transformedEvents = historicalEvents.map((event) => ({
|
||||
userId: event.userId || undefined,
|
||||
country: event.country || undefined,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user