Files
livedash-node/lib/types.ts
Kaj Kowalski 93fbb44eec feat: comprehensive Biome linting fixes and code quality improvements
Major code quality overhaul addressing 58% of all linting issues:

• Type Safety Improvements:
  - Replace all any types with proper TypeScript interfaces
  - Fix Map component shadowing (renamed to CountryMap)
  - Add comprehensive custom error classes system
  - Enhance API route type safety

• Accessibility Enhancements:
  - Add explicit button types to all interactive elements
  - Implement useId() hooks for form element accessibility
  - Add SVG title attributes for screen readers
  - Fix static element interactions with keyboard handlers

• React Best Practices:
  - Resolve exhaustive dependencies warnings with useCallback
  - Extract nested component definitions to top level
  - Fix array index keys with proper unique identifiers
  - Improve component organization and prop typing

• Code Organization:
  - Automatic import organization and type import optimization
  - Fix unused function parameters and variables
  - Enhanced error handling with structured error responses
  - Improve component reusability and maintainability

Results: 248 → 104 total issues (58% reduction)
- Fixed all critical type safety and security issues
- Enhanced accessibility compliance significantly
- Improved code maintainability and performance
2025-06-29 07:35:45 +02:00

173 lines
4.2 KiB
TypeScript

import type { Session as NextAuthSession } from "next-auth";
export interface UserSession extends NextAuthSession {
user: {
id?: string;
name?: string;
email?: string;
image?: string;
companyId: string;
role: string;
};
}
export interface Company {
id: string;
name: string;
csvUrl: string;
csvUsername?: string;
csvPassword?: string;
sentimentAlert?: number; // Match Prisma schema naming
createdAt: Date;
updatedAt: Date;
}
export interface User {
id: string;
email: string;
password: string;
role: string;
companyId: string;
resetToken?: string | null;
resetTokenExpiry?: Date | null;
company?: Company;
createdAt: Date;
updatedAt: Date;
}
export interface Message {
id: string;
sessionId: string;
timestamp: Date | null;
role: string; // "User", "Assistant", "System", etc.
content: string;
order: number; // Order within the conversation (0, 1, 2, ...)
createdAt: Date;
}
export interface ChatSession {
id: string;
sessionId: string;
companyId: string;
userId?: string | null;
category?: string | null;
language?: string | null;
country?: string | null;
ipAddress?: string | null;
sentiment?: string | null; // Now a SentimentCategory enum: "POSITIVE", "NEUTRAL", "NEGATIVE"
messagesSent?: number;
startTime: Date;
endTime?: Date | null;
createdAt: Date;
updatedAt: Date;
// Extended session properties that might be used in metrics
avgResponseTime?: number | null;
escalated?: boolean;
forwardedHr?: boolean;
initialMsg?: string;
fullTranscriptUrl?: string | null;
summary?: string | null; // Brief summary of the conversation
messages?: Message[]; // Parsed messages from transcript
transcriptContent?: string | null; // Full transcript content
}
export interface SessionQuery {
searchTerm?: string;
category?: string;
language?: string;
startDate?: string;
endDate?: string;
sortKey?: string;
sortOrder?: "asc" | "desc";
page?: number;
pageSize?: number;
}
export interface SessionApiResponse {
sessions: ChatSession[];
totalSessions: number;
}
export interface SessionFilterOptions {
categories: string[];
languages: string[];
}
export interface DayMetrics {
[day: string]: number;
}
export interface CategoryMetrics {
[category: string]: number;
}
export interface LanguageMetrics {
[language: string]: number;
}
export interface CountryMetrics {
[country: string]: number;
}
export interface WordCloudWord {
text: string;
value: number;
}
export interface TopQuestion {
question: string;
count: number;
}
export interface MetricsResult {
totalSessions: number;
avgSessionsPerDay: number;
avgSessionLength: number | null;
days: DayMetrics;
languages: LanguageMetrics;
categories: CategoryMetrics;
countries: CountryMetrics; // Added for geographic distribution
belowThresholdCount: number;
// Additional properties for dashboard
escalatedCount?: number;
forwardedCount?: number;
avgSentiment?: number;
avgResponseTime?: number;
totalTokens?: number;
totalTokensEur?: number;
sentimentThreshold?: number | null;
lastUpdated?: number; // Timestamp for when metrics were last updated
// New metrics for enhanced dashboard
sentimentPositiveCount?: number;
sentimentNeutralCount?: number;
sentimentNegativeCount?: number;
tokensByDay?: DayMetrics;
tokensCostByDay?: DayMetrics;
wordCloudData?: WordCloudWord[]; // Added for transcript-based word cloud
// Properties for overview page cards and trends
uniqueUsers?: number;
sessionTrend?: number; // e.g., percentage change in totalSessions
usersTrend?: number; // e.g., percentage change in uniqueUsers
avgSessionTimeTrend?: number; // e.g., percentage change in avgSessionLength
avgResponseTimeTrend?: number; // e.g., percentage change in avgResponseTime
// New metrics for enhanced dashboard
avgDailyCosts?: number; // Average daily costs in euros
peakUsageTime?: string; // Peak usage time (e.g., "14:00-15:00")
resolvedChatsPercentage?: number; // Percentage of resolved chats
topQuestions?: TopQuestion[]; // Top 5 most asked questions
// Debug properties
totalSessionDuration?: number;
validSessionsForDuration?: number;
}
export interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
}