MEDIUM-SEVERITY FIXES (Fase 3 complete): 1. Mock Data em Produção (Vulnerabilidade 3.2) ✅ - Mock data apenas em desenvolvimento (import.meta.env.DEV) - Produção mostra erro claro com retry button - Estado de erro com UI profissional 2. Connection Pool Timeouts (Vulnerabilidade 3.3) ✅ - JÁ CORRIGIDO em commit anterior (20c16ab) - connectTimeout: 10s, acquireTimeout: 15s, timeout: 30s 3. Tipo 'any' em Catch Blocks (Vulnerabilidade 3.4) ✅ - TODOS os ficheiros corrigidos (10/10) - catch (error: unknown) em vez de catch (error) - Type guards: error instanceof Error - Mensagens seguras sem vazamento de stack trace - Ficheiros: routes/*.ts, services/*.ts, middleware/validation.ts 4. APIs Sem Autenticação Backend (Vulnerabilidade 3.5) ✅ - JÁ IMPLEMENTADO em commit anterior (f175682) - OIDC opcional via OIDC_ENABLED=true 5. Algoritmos SSH Legacy (Vulnerabilidade 3.6) ✅ - Adicionados: curve25519-sha256, curve25519-sha256@libssh.org - Removidos: diffie-hellman-group14-sha1 (legacy) - Removidos: diffie-hellman-group1-sha1 (INSEGURO) - Apenas SHA256+ algorithms mantidos 6. Configuração OIDC (Vulnerabilidade 3.1) ✅ - JÁ IMPLEMENTADO em commit anterior (f175682) - OIDC completamente funcional (opcional) FILES CHANGED: - src/App.tsx - Error state + mock data apenas em dev - api/routes/*.ts - Tipos unknown em todos os catch blocks - api/services/*.ts - Tipos unknown em todos os catch blocks - api/middleware/validation.ts - Tipo correto (error.issues) - api/services/server-metrics.ts - Algoritmos SSH modernos BUILD STATUS: - TypeScript: ✅ PASSED - npm run build: ✅ SUCCESS - npm audit: ✅ 0 vulnerabilities PROGRESS: - Phase 1 (Critical): 3/3 ✅ COMPLETE - Phase 2 (High): 6/6 ✅ COMPLETE - Phase 3 (Medium): 6/6 ✅ COMPLETE - Phase 4 (Low): 0/5 - Next Related: AUDIT-REPORT.md vulnerabilities 3.1, 3.2, 3.3, 3.4, 3.5, 3.6 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
107 lines
3.0 KiB
TypeScript
Executable File
107 lines
3.0 KiB
TypeScript
Executable File
/**
|
|
* Google Calendar Service
|
|
* @author Descomplicar® | @link descomplicar.pt | @copyright 2026
|
|
*/
|
|
import { google } from 'googleapis'
|
|
|
|
const oauth2Client = new google.auth.OAuth2(
|
|
'188617934470-pomrua9oj4459dk69jpv6qhvst9pd3f6.apps.googleusercontent.com',
|
|
'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',
|
|
'https://developers.google.com/oauthplayground'
|
|
)
|
|
|
|
oauth2Client.setCredentials({
|
|
refresh_token: '1//03AJOfA8x4_eyCgYIARAAGAMSNwF-L9Ir2hVygx8arVuZpZKJpqPsFpGCLo3pXJGC9rxpHnVw5Gki5cLWG7Ez64RcT0RFVItZ2fQ'
|
|
})
|
|
|
|
const calendar = google.calendar({ version: 'v3', auth: oauth2Client })
|
|
|
|
interface CalendarEvent {
|
|
titulo: string
|
|
hora: string
|
|
data?: string
|
|
tipo: 'personal' | 'work'
|
|
link: string
|
|
}
|
|
|
|
export async function getEvents(calendarId: string, timeMin: string, timeMax: string): Promise<CalendarEvent[]> {
|
|
try {
|
|
const response = await calendar.events.list({
|
|
calendarId,
|
|
timeMin,
|
|
timeMax,
|
|
singleEvents: true,
|
|
orderBy: 'startTime',
|
|
maxResults: 20
|
|
})
|
|
|
|
const events: CalendarEvent[] = []
|
|
const items = response.data.items || []
|
|
|
|
for (const event of items) {
|
|
const start = event.start?.dateTime || event.start?.date
|
|
if (!start) continue
|
|
|
|
const startDate = new Date(start)
|
|
const tipo = calendarId === 'primary' ? 'personal' : 'work'
|
|
|
|
events.push({
|
|
titulo: event.summary || 'Sem título',
|
|
hora: startDate.toLocaleTimeString('pt-PT', { hour: '2-digit', minute: '2-digit' }),
|
|
data: calendarId === 'primary'
|
|
? undefined
|
|
: startDate.toLocaleDateString('pt-PT', { weekday: 'short', day: '2-digit', month: '2-digit' }),
|
|
tipo,
|
|
link: event.htmlLink || '#'
|
|
})
|
|
}
|
|
|
|
return events
|
|
} catch (error: unknown) {
|
|
console.error(`Calendar error (${calendarId}):`, error)
|
|
return []
|
|
}
|
|
}
|
|
|
|
export async function getTodayEvents(): Promise<CalendarEvent[]> {
|
|
const today = new Date()
|
|
today.setHours(0, 0, 0, 0)
|
|
const tomorrow = new Date(today)
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
|
|
const timeMin = today.toISOString()
|
|
const timeMax = tomorrow.toISOString()
|
|
|
|
const [personal, work] = await Promise.all([
|
|
getEvents('primary', timeMin, timeMax),
|
|
getEvents('emanuel@descomplicar.pt', timeMin, timeMax)
|
|
])
|
|
|
|
return [...personal, ...work].sort((a, b) => a.hora.localeCompare(b.hora))
|
|
}
|
|
|
|
export async function getWeekEvents(): Promise<CalendarEvent[]> {
|
|
const today = new Date()
|
|
today.setHours(0, 0, 0, 0)
|
|
const tomorrow = new Date(today)
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
|
|
const nextSunday = new Date(today)
|
|
nextSunday.setDate(today.getDate() + (7 - today.getDay()))
|
|
nextSunday.setHours(23, 59, 59, 999)
|
|
|
|
const timeMin = tomorrow.toISOString()
|
|
const timeMax = nextSunday.toISOString()
|
|
|
|
const [personal, work] = await Promise.all([
|
|
getEvents('primary', timeMin, timeMax),
|
|
getEvents('emanuel@descomplicar.pt', timeMin, timeMax)
|
|
])
|
|
|
|
return [...personal, ...work].sort((a, b) => {
|
|
const dateA = a.data + a.hora
|
|
const dateB = b.data + b.hora
|
|
return dateA.localeCompare(dateB)
|
|
})
|
|
}
|