Function bodies 63 total
getSignalHistory function · typescript · L27-L29 (3 LOC)lib/refinex-api.ts
export async function getSignalHistory() {
return apiFetch('/v1/signals?limit=20');
}getSystemHealth function · typescript · L31-L33 (3 LOC)lib/refinex-api.ts
export async function getSystemHealth() {
return apiFetch('/v1/trinity/health', true);
}getDashboardSnapshot function · typescript · L35-L37 (3 LOC)lib/refinex-api.ts
export async function getDashboardSnapshot() {
return apiFetch('/v1/trinity/dashboard', true);
}cn function · typescript · L3-L5 (3 LOC)lib/utils.ts
export function cn(...inputs: ClassValue[]) {
return clsx(inputs)
}formatNumber function · typescript · L7-L9 (3 LOC)lib/utils.ts
export function formatNumber(num: number): string {
return new Intl.NumberFormat('en-US').format(num)
}formatCurrency function · typescript · L11-L18 (8 LOC)lib/utils.ts
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: 4,
}).format(amount)
}formatPercentage function · typescript · L20-L22 (3 LOC)lib/utils.ts
export function formatPercentage(value: number, decimals: number = 1): string {
return `${value.toFixed(decimals)}%`
}Citation: Repobility (2026). State of AI-Generated Code. https://repobility.com/research/
validateInput function · typescript · L58-L61 (4 LOC)lib/validation.ts
export function validateInput<T>(
schema: z.ZodSchema<T>,
data: unknown
): { success: true; data: T } | { success: false; error: string } {containsSQLInjection function · typescript · L85-L87 (3 LOC)lib/validation.ts
export function containsSQLInjection(input: string): boolean {
return SQL_INJECTION_PATTERNS.some(pattern => pattern.test(input))
}containsXSS function · typescript · L100-L102 (3 LOC)lib/validation.ts
export function containsXSS(input: string): boolean {
return XSS_PATTERNS.some(pattern => pattern.test(input))
}sanitizeForDisplay function · typescript · L105-L113 (9 LOC)lib/validation.ts
export function sanitizeForDisplay(input: string, maxLength: number = 500): string {
return input
.trim()
.slice(0, maxLength)
.replace(/[<>]/g, '') // Remove HTML tags
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
}rateLimit function · typescript · L15-L35 (21 LOC)src/middleware.ts
function rateLimit(ip: string, endpoint: string): boolean {
const config = Object.keys(RATE_LIMITS).find(pattern => endpoint.startsWith(pattern))
if (!config) return true // No rate limit for this endpoint
const limit = RATE_LIMITS[config as keyof typeof RATE_LIMITS]
const key = `${ip}:${config}`
const now = Date.now()
const record = rateLimitMap.get(key)
if (!record || now > record.resetTime) {
rateLimitMap.set(key, { count: 1, resetTime: now + limit.windowMs })
return true
}
if (record.count >= limit.maxRequests) {
return false // Rate limited
}
record.count++
return true
}middleware function · typescript · L47-L125 (79 LOC)src/middleware.ts
export function middleware(request: NextRequest) {
const response = NextResponse.next()
// Get client IP (handle various proxy headers)
const ip =
request.headers.get('x-forwarded-for')?.split(',')[0] ||
request.headers.get('x-real-ip') ||
'unknown'
// Rate limiting for API routes
if (request.nextUrl.pathname.startsWith('/api/')) {
if (!rateLimit(ip, request.nextUrl.pathname)) {
return new NextResponse(
JSON.stringify({
error: 'Rate limit exceeded. Please try again later.',
retryAfter: 600
}),
{
status: 429,
headers: {
'Content-Type': 'application/json',
'Retry-After': '600',
}
}
)
}
}
// Security Headers (Applied to all routes)
// Content Security Policy
const cspDirectives = [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' 'unsafe-eval'", // Next.js needs unsafe-inline/eval for dev
"style-src 'self'‹ prevpage 2 / 2