mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-17 22:52:09 +01:00
fix: resolve all TypeScript compilation errors and enable production build
- Fixed missing type imports in lib/api/index.ts - Updated Zod error property from 'errors' to 'issues' for compatibility - Added missing lru-cache dependency for performance caching - Fixed LRU Cache generic type constraints for TypeScript compliance - Resolved Map iteration ES5 compatibility issues using Array.from() - Fixed Redis configuration by removing unsupported socket options - Corrected Prisma relationship naming (auditLogs vs securityAuditLogs) - Applied type casting for missing database schema fields - Created missing security types file for enhanced security service - Disabled deprecated ESLint during build (using Biome for linting) - Removed deprecated critters dependency and disabled CSS optimization - Achieved successful production build with all 47 pages generated
This commit is contained in:
117
lib/api/response.ts
Normal file
117
lib/api/response.ts
Normal file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Standardized API Response System
|
||||
*
|
||||
* Provides consistent response formatting across all API endpoints
|
||||
* with proper typing, error handling, and metadata support.
|
||||
*/
|
||||
|
||||
export interface PaginationMeta {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export interface APIResponseMeta {
|
||||
timestamp: string;
|
||||
requestId: string;
|
||||
pagination?: PaginationMeta;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
export interface APIResponse<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: string;
|
||||
errors?: string[];
|
||||
meta: APIResponseMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a successful API response
|
||||
*/
|
||||
export function createSuccessResponse<T>(
|
||||
data: T,
|
||||
meta?: Partial<APIResponseMeta>
|
||||
): APIResponse<T> {
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
meta: {
|
||||
timestamp: new Date().toISOString(),
|
||||
requestId: crypto.randomUUID(),
|
||||
version: "1.0",
|
||||
...meta,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an error API response
|
||||
*/
|
||||
export function createErrorResponse(
|
||||
error: string,
|
||||
errors?: string[],
|
||||
meta?: Partial<APIResponseMeta>
|
||||
): APIResponse {
|
||||
return {
|
||||
success: false,
|
||||
error,
|
||||
errors,
|
||||
meta: {
|
||||
timestamp: new Date().toISOString(),
|
||||
requestId: crypto.randomUUID(),
|
||||
version: "1.0",
|
||||
...meta,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a paginated success response
|
||||
*/
|
||||
export function createPaginatedResponse<T>(
|
||||
data: T[],
|
||||
pagination: PaginationMeta,
|
||||
meta?: Partial<APIResponseMeta>
|
||||
): APIResponse<T[]> {
|
||||
return createSuccessResponse(data, {
|
||||
...meta,
|
||||
pagination,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract pagination parameters from request
|
||||
*/
|
||||
export function extractPaginationParams(searchParams: URLSearchParams): {
|
||||
page: number;
|
||||
limit: number;
|
||||
} {
|
||||
const page = Math.max(
|
||||
1,
|
||||
Number.parseInt(searchParams.get("page") || "1", 10)
|
||||
);
|
||||
const limit = Math.min(
|
||||
100,
|
||||
Math.max(1, Number.parseInt(searchParams.get("limit") || "20", 10))
|
||||
);
|
||||
|
||||
return { page, limit };
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate pagination metadata
|
||||
*/
|
||||
export function calculatePaginationMeta(
|
||||
page: number,
|
||||
limit: number,
|
||||
total: number
|
||||
): PaginationMeta {
|
||||
return {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user