fix: comprehensive security and type improvements from PR #20 review

Security Enhancements:
- Implemented proper rate limiting with automatic cleanup for /register and /forgot-password endpoints
- Added memory usage protection with MAX_ENTRIES limit (10000)
- Fixed rate limiter memory leaks by adding cleanup intervals
- Improved IP extraction with x-real-ip and x-client-ip header support

Code Quality Improvements:
- Refactored ProcessingStatusManager from individual functions to class-based architecture
- Maintained backward compatibility with singleton instance pattern
- Fixed TypeScript strict mode violations across the codebase
- Resolved all build errors and type mismatches

UI Component Fixes:
- Removed unused chart components (Charts.tsx, DonutChart.tsx)
- Fixed calendar component type issues by removing unused custom implementations
- Resolved theme provider type imports
- Fixed confetti component default options handling
- Corrected pointer component coordinate type definitions

Type System Improvements:
- Extended NextAuth types to support dual auth systems (regular and platform users)
- Fixed nullable type handling throughout the codebase
- Resolved Prisma JSON field type compatibility issues
- Corrected SessionMessage and ImportRecord interface definitions
- Fixed ES2015 iteration compatibility issues

Database & Performance:
- Updated database pool configuration for Prisma adapter compatibility
- Fixed pagination response structure in user management endpoints
- Improved error handling with proper error class usage

Testing & Build:
- All TypeScript compilation errors resolved
- ESLint warnings remain but no errors
- Build completes successfully with proper static generation
This commit is contained in:
2025-06-30 19:15:25 +02:00
parent 5042a6c016
commit 38aff21c3a
32 changed files with 1002 additions and 929 deletions

View File

@ -1,16 +1,16 @@
// SessionImport to Session processor
import { ProcessingStage, SentimentCategory } from "@prisma/client";
import cron from "node-cron";
import { withRetry } from "./database-retry.js";
import { withRetry } from "./database-retry";
import { getSchedulerConfig } from "./env";
import { prisma } from "./prisma.js";
import { prisma } from "./prisma";
import {
completeStage,
failStage,
initializeSession,
skipStage,
startStage,
} from "./processingStatusManager.js";
} from "./processingStatusManager";
import {
fetchTranscriptContent,
isValidTranscriptUrl,
@ -22,19 +22,23 @@ interface ImportRecord {
startTimeRaw: string;
endTimeRaw: string;
externalSessionId: string;
sessionId?: string;
userId?: string;
category?: string;
language?: string;
sentiment?: string;
escalated?: boolean;
forwardedHr?: boolean;
avgResponseTime?: number;
messagesSent?: number;
fullTranscriptUrl?: string;
rawTranscriptContent?: string;
aiSummary?: string;
initialMsg?: string;
sessionId?: string | null;
userId?: string | null;
category: string | null;
language: string | null;
sentiment?: string | null;
escalated?: boolean | null;
forwardedHr?: boolean | null;
avgResponseTime?: number | null;
messagesSent: number | null;
fullTranscriptUrl: string | null;
rawTranscriptContent: string | null;
aiSummary?: string | null;
initialMsg?: string | null;
ipAddress: string | null;
countryCode: string | null;
avgResponseTimeSeconds: number | null;
initialMessage: string | null;
}
/**
@ -245,7 +249,7 @@ async function handleTranscriptFetching(
);
if (transcriptResult.success) {
transcriptContent = transcriptResult.content;
transcriptContent = transcriptResult.content ?? null;
console.log(
`[Import Processor] ✓ Fetched transcript for ${importRecord.externalSessionId} (${transcriptContent?.length} chars)`
);
@ -282,7 +286,7 @@ async function handleTranscriptFetching(
});
}
return transcriptContent;
return transcriptContent ?? null;
}
/**
@ -429,7 +433,10 @@ async function processQueuedImportsInternal(batchSize = 50): Promise<void> {
// Process with concurrency limit to avoid overwhelming the database
const concurrencyLimit = 5;
const results = [];
const results: Array<{
importRecord: typeof unprocessedImports[0];
result: Awaited<ReturnType<typeof processSingleImport>>;
}> = [];
for (let i = 0; i < batchPromises.length; i += concurrencyLimit) {
const chunk = batchPromises.slice(i, i + concurrencyLimit);