mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
feat(frontend): rebuild package, detail and vulnerable views
Package groups use Accordion with Table or DataTable in the cards layout below sm. Delete confirmations use ConfirmDialog and results go to the Toaster. Vulnerability descriptions render through Markdown instead of v-html, and references use the library Link.
This commit is contained in:
@@ -1,250 +1,154 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-7xl mx-auto px-4 py-8">
|
<div class="flex flex-col gap-6">
|
||||||
<!-- Header with Back Button -->
|
<PageHeader :title="packageName">
|
||||||
<div class="mb-6">
|
<template #back>
|
||||||
<Button @click="goBack" variant="ghost" class="mb-4">
|
<Button variant="ghost" size="sm" :icon-start="faArrowLeft" @click="goBack">Back to packages</Button>
|
||||||
<i class="fas fa-arrow-left mr-2"></i>
|
</template>
|
||||||
Back to Packages
|
<template #description>
|
||||||
</Button>
|
<span class="flex flex-wrap items-center gap-2">
|
||||||
<div class="flex items-center gap-3">
|
<Badge variant="outline">{{ registry }}</Badge>
|
||||||
<i class="fas fa-box text-3xl text-primary-600"></i>
|
<Badge variant="outline" class="font-mono">v{{ version }}</Badge>
|
||||||
<div>
|
</span>
|
||||||
<h1 class="text-3xl font-bold text-gray-900">{{ packageName }}</h1>
|
</template>
|
||||||
<div class="flex items-center gap-2 mt-2">
|
</PageHeader>
|
||||||
<Badge :class="getRegistryBadgeClass(registry)">{{ registry }}</Badge>
|
|
||||||
<Badge variant="outline" class="font-mono">v{{ version }}</Badge>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Loading State -->
|
<LoadingState v-if="loading" variant="card" label="Loading vulnerability details..." />
|
||||||
<div v-if="loading" class="text-center py-12">
|
|
||||||
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
|
|
||||||
<p class="mt-4 text-gray-600">Loading vulnerability details...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error State -->
|
<ErrorState
|
||||||
<Alert v-else-if="error" variant="destructive" class="mb-4">
|
v-else-if="error"
|
||||||
<i class="fas fa-exclamation-circle mr-2"></i>
|
variant="card"
|
||||||
<AlertDescription>{{ error }}</AlertDescription>
|
title="Could not load vulnerability details"
|
||||||
</Alert>
|
:message="error"
|
||||||
|
@retry="fetchVulnerabilities"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Vulnerability Details -->
|
<template v-else-if="vulnerabilities">
|
||||||
<div v-else-if="vulnerabilities" class="space-y-6">
|
|
||||||
<!-- Summary Card -->
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle class="flex items-center gap-2">
|
<CardTitle as="h2">Security scan summary</CardTitle>
|
||||||
<i class="fas fa-shield-virus text-red-600"></i>
|
|
||||||
Security Scan Summary
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent class="flex flex-col gap-4">
|
||||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
|
<SeveritySummary :counts="severityCounts" label="Vulnerabilities by severity" />
|
||||||
<div class="text-center p-4 bg-red-50 rounded-lg border border-red-200">
|
<DescriptionList variant="inline" divided>
|
||||||
<p class="text-3xl font-bold text-red-600">{{ severityCounts.critical }}</p>
|
<DescriptionItem term="Scanned">{{ formatDate(vulnerabilities.scanned_at) }}</DescriptionItem>
|
||||||
<p class="text-sm text-gray-600 mt-1">Critical</p>
|
<DescriptionItem term="Scanners">
|
||||||
</div>
|
<span class="flex flex-wrap gap-1">
|
||||||
<div class="text-center p-4 bg-orange-50 rounded-lg border border-orange-200">
|
<Badge v-for="scanner in scannerList" :key="scanner" variant="secondary">{{ scanner }}</Badge>
|
||||||
<p class="text-3xl font-bold text-orange-600">{{ severityCounts.high }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">High</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-center p-4 bg-yellow-50 rounded-lg border border-yellow-200">
|
|
||||||
<p class="text-3xl font-bold text-yellow-600">{{ severityCounts.moderate }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">Moderate</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-center p-4 bg-blue-50 rounded-lg border border-blue-200">
|
|
||||||
<p class="text-3xl font-bold text-blue-600">{{ severityCounts.low }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">Low</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Separator class="my-4" />
|
|
||||||
<div class="flex items-center justify-between text-sm">
|
|
||||||
<div class="flex flex-col gap-3">
|
|
||||||
<span class="text-gray-600">
|
|
||||||
<i class="fas fa-search mr-1"></i>
|
|
||||||
Scanned: {{ formatDate(vulnerabilities.scanned_at) }}
|
|
||||||
</span>
|
</span>
|
||||||
<div class="flex items-center gap-2">
|
</DescriptionItem>
|
||||||
<span class="text-gray-600">
|
<DescriptionItem v-if="bypassedCount > 0" term="Bypassed">
|
||||||
<i class="fas fa-cog mr-1"></i>
|
<StatusBadge status="bypassed" :label="`${bypassedCount} bypassed`" :tones="{ bypassed: 'success' }" />
|
||||||
Scanners:
|
</DescriptionItem>
|
||||||
</span>
|
</DescriptionList>
|
||||||
<div class="flex flex-wrap gap-1">
|
|
||||||
<Badge
|
|
||||||
v-for="scanner in scannerList"
|
|
||||||
:key="scanner"
|
|
||||||
variant="secondary"
|
|
||||||
class="text-xs"
|
|
||||||
>
|
|
||||||
{{ scanner }}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="bypassedCount > 0" class="flex items-center gap-2 text-green-600">
|
|
||||||
<i class="fas fa-check-circle"></i>
|
|
||||||
<span>{{ bypassedCount }} bypassed</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- No Vulnerabilities -->
|
|
||||||
<Card v-if="vulnerabilityList.length === 0">
|
<Card v-if="vulnerabilityList.length === 0">
|
||||||
<CardContent class="text-center py-12">
|
<CardContent>
|
||||||
<i class="fas fa-check-circle text-6xl text-green-500 mb-4"></i>
|
<EmptyState
|
||||||
<p class="text-xl font-semibold text-gray-900">No Vulnerabilities Found</p>
|
tone="success"
|
||||||
<p class="mt-2 text-gray-600">This package is clean and safe to use</p>
|
:icon="faCircleCheck"
|
||||||
|
title="No vulnerabilities found"
|
||||||
|
description="The scanners reported nothing for this package version."
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- Vulnerability List -->
|
|
||||||
<Card v-else>
|
<Card v-else>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle class="flex items-center gap-2">
|
<CardTitle as="h2">Detected vulnerabilities ({{ vulnerabilityList.length }})</CardTitle>
|
||||||
<i class="fas fa-list text-gray-600"></i>
|
|
||||||
Detected Vulnerabilities ({{ vulnerabilityList.length }})
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent class="p-0">
|
<CardContent>
|
||||||
<div class="border-t overflow-x-auto">
|
<Table label="Detected vulnerabilities" layout="cards">
|
||||||
<Table class="min-w-[800px]">
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow class="bg-gray-50 hover:bg-gray-50">
|
<TableHead>Severity</TableHead>
|
||||||
<TableHead class="w-[100px]">Severity</TableHead>
|
<TableHead>CVE ID</TableHead>
|
||||||
<TableHead class="w-[180px]">CVE ID</TableHead>
|
<TableHead>Description</TableHead>
|
||||||
<TableHead>Description</TableHead>
|
<TableHead>Fix version</TableHead>
|
||||||
<TableHead class="w-[120px]">Fix Version</TableHead>
|
<TableHead align="center">Details</TableHead>
|
||||||
<TableHead class="w-[100px] text-center">Details</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody>
|
||||||
<TableBody>
|
<template v-for="(vuln, index) in vulnerabilityList" :key="vuln.id">
|
||||||
<template v-for="(vuln, index) in vulnerabilityList" :key="vuln.id">
|
<TableRow class="cursor-pointer" :selected="expandedRows.has(index)" @click="toggleRow(index)">
|
||||||
<!-- Main Row -->
|
<TableCell label="Severity">
|
||||||
<TableRow
|
<span class="flex flex-wrap items-center gap-2">
|
||||||
:class="getRowClass(index, vuln.severity)"
|
<StatusBadge
|
||||||
@click="toggleRow(index)"
|
:status="vuln.severity"
|
||||||
>
|
:tones="SEVERITY_TONES"
|
||||||
<TableCell>
|
:label="formatSeverityName(vuln.severity)"
|
||||||
<Badge :class="getSeverityBadgeClass(vuln.severity)">
|
/>
|
||||||
{{ formatSeverityName(vuln.severity) }}
|
<StatusBadge
|
||||||
</Badge>
|
|
||||||
<span
|
|
||||||
v-if="vuln.bypassed"
|
v-if="vuln.bypassed"
|
||||||
class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800"
|
status="bypassed"
|
||||||
title="Bypassed"
|
label="Bypassed"
|
||||||
>
|
:tones="{ bypassed: 'success' }"
|
||||||
<i class="fas fa-unlock text-xs"></i>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell label="CVE ID" class="font-mono font-medium">{{ vuln.id }}</TableCell>
|
||||||
<span class="font-mono text-sm font-medium">{{ vuln.id }}</span>
|
<TableCell label="Description">
|
||||||
</TableCell>
|
<p class="m-0 line-clamp-2 break-words">{{ vuln.title || vuln.description }}</p>
|
||||||
<TableCell>
|
</TableCell>
|
||||||
<p class="text-sm text-gray-900 line-clamp-2 break-words">{{ vuln.title || vuln.description }}</p>
|
<TableCell label="Fix version">
|
||||||
</TableCell>
|
<span v-if="vuln.fixed_in">v{{ vuln.fixed_in }}</span>
|
||||||
<TableCell>
|
<span v-else class="text-muted-foreground">-</span>
|
||||||
<span v-if="vuln.fixed_in" class="inline-flex items-center text-sm text-green-700">
|
</TableCell>
|
||||||
<i class="fas fa-arrow-up text-xs mr-1"></i>
|
<TableCell label="Details" align="center">
|
||||||
v{{ vuln.fixed_in }}
|
<IconButton
|
||||||
</span>
|
size="icon-sm"
|
||||||
<span v-else class="text-sm text-gray-400">-</span>
|
:icon="expandedRows.has(index) ? faChevronUp : faChevronDown"
|
||||||
</TableCell>
|
:label="`${expandedRows.has(index) ? 'Hide' : 'Show'} details for ${vuln.id}`"
|
||||||
<TableCell class="text-center">
|
:aria-expanded="expandedRows.has(index)"
|
||||||
<Button
|
@click.stop="toggleRow(index)"
|
||||||
variant="ghost"
|
/>
|
||||||
size="sm"
|
</TableCell>
|
||||||
class="h-8 w-8 p-0"
|
</TableRow>
|
||||||
@click.stop="toggleRow(index)"
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
:class="[
|
|
||||||
'fas transition-transform',
|
|
||||||
expandedRows.has(index) ? 'fa-chevron-up' : 'fa-chevron-down'
|
|
||||||
]"
|
|
||||||
></i>
|
|
||||||
</Button>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
|
|
||||||
<!-- Expanded Details Row -->
|
<TableRow v-if="expandedRows.has(index)" :hoverable="false">
|
||||||
<TableRow v-if="expandedRows.has(index)" class="bg-gray-50 hover:bg-gray-50">
|
<TableCell :colspan="5">
|
||||||
<TableCell colspan="5" class="p-0">
|
<div class="flex flex-col gap-4 py-2">
|
||||||
<div class="px-6 py-4 space-y-3">
|
<section>
|
||||||
<!-- Full Description -->
|
<h3 class="mb-2 text-sm font-semibold">Description</h3>
|
||||||
<div>
|
<Markdown :source="vuln.description" :heading-offset="3" />
|
||||||
<h5 class="font-semibold text-gray-900 mb-2">Description</h5>
|
</section>
|
||||||
<div
|
|
||||||
class="text-sm text-gray-700 leading-relaxed prose prose-sm max-w-none break-words overflow-hidden"
|
|
||||||
v-html="renderMarkdown(vuln.description)"
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Bypass Information -->
|
<Alert v-if="vuln.bypassed && vuln.bypass" variant="success">
|
||||||
<div v-if="vuln.bypassed && vuln.bypass" class="bg-green-50 border border-green-200 rounded-lg p-3">
|
<AlertTitle>Bypass active</AlertTitle>
|
||||||
<h5 class="font-semibold text-green-900 mb-2 flex items-center gap-2">
|
<AlertDescription>
|
||||||
<i class="fas fa-info-circle"></i>
|
<DescriptionList variant="grid" :columns="3" size="sm">
|
||||||
Bypass Active
|
<DescriptionItem term="Reason">{{ vuln.bypass.reason }}</DescriptionItem>
|
||||||
</h5>
|
<DescriptionItem term="By">{{ vuln.bypass.created_by }}</DescriptionItem>
|
||||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm text-green-800">
|
<DescriptionItem term="Expires">{{ formatDate(vuln.bypass.expires_at) }}</DescriptionItem>
|
||||||
<div class="break-words">
|
</DescriptionList>
|
||||||
<span class="font-medium">Reason:</span> {{ vuln.bypass.reason }}
|
</AlertDescription>
|
||||||
</div>
|
</Alert>
|
||||||
<div class="break-words">
|
|
||||||
<span class="font-medium">By:</span> {{ vuln.bypass.created_by }}
|
|
||||||
</div>
|
|
||||||
<div class="break-words">
|
|
||||||
<span class="font-medium">Expires:</span> {{ formatDate(vuln.bypass.expires_at) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Fix Information -->
|
<Alert v-if="vuln.fixed_in" variant="info">
|
||||||
<div v-if="vuln.fixed_in" class="bg-blue-50 border border-blue-200 rounded-lg p-3">
|
<AlertTitle>Fix available</AlertTitle>
|
||||||
<div class="flex items-center gap-2">
|
<AlertDescription>
|
||||||
<i class="fas fa-wrench text-blue-700"></i>
|
Upgrade to version <strong>{{ vuln.fixed_in }}</strong> or later.
|
||||||
<span class="text-sm text-blue-900">
|
</AlertDescription>
|
||||||
<span class="font-semibold">Fix Available:</span> Upgrade to version <strong>{{ vuln.fixed_in }}</strong> or later
|
</Alert>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- References -->
|
<section v-if="vuln.references && vuln.references.length > 0">
|
||||||
<div v-if="vuln.references && vuln.references.length > 0">
|
<h3 class="mb-2 text-sm font-semibold">References ({{ vuln.references.length }})</h3>
|
||||||
<h5 class="font-semibold text-gray-900 mb-2 flex items-center gap-2">
|
<ul class="m-0 flex list-none flex-col gap-1 p-0 text-sm">
|
||||||
<i class="fas fa-link"></i>
|
<li v-for="(ref, refIndex) in vuln.references" :key="refIndex" class="break-all">
|
||||||
References ({{ vuln.references.length }})
|
<Link :href="ref" external>{{ ref }}</Link>
|
||||||
</h5>
|
</li>
|
||||||
<div class="space-y-1.5">
|
</ul>
|
||||||
<div
|
</section>
|
||||||
v-for="(ref, refIndex) in vuln.references"
|
</div>
|
||||||
:key="refIndex"
|
</TableCell>
|
||||||
class="flex items-start gap-2 text-sm"
|
</TableRow>
|
||||||
>
|
</template>
|
||||||
<i class="fas fa-external-link-alt text-gray-400 text-xs mt-0.5"></i>
|
</TableBody>
|
||||||
<a
|
</Table>
|
||||||
:href="ref"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="text-blue-600 hover:text-blue-800 hover:underline break-all"
|
|
||||||
>
|
|
||||||
{{ ref }}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
</template>
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -252,32 +156,37 @@
|
|||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { marked } from 'marked'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import { Badge } from '@/components/ui/badge'
|
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
|
||||||
import { Separator } from '@/components/ui/separator'
|
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
|
AlertDescription,
|
||||||
|
AlertTitle,
|
||||||
|
Badge,
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
DescriptionItem,
|
||||||
|
DescriptionList,
|
||||||
|
EmptyState,
|
||||||
|
ErrorState,
|
||||||
|
IconButton,
|
||||||
|
Link,
|
||||||
|
LoadingState,
|
||||||
|
Markdown,
|
||||||
|
PageHeader,
|
||||||
|
StatusBadge,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '@/components/ui/table'
|
} from '@perfect-design/ui'
|
||||||
import {
|
import SeveritySummary from './SeveritySummary.vue'
|
||||||
getSeverityBadgeClass,
|
import { formatDate } from '@/lib/format'
|
||||||
getRegistryBadgeClass,
|
import { faArrowLeft, faChevronDown, faChevronUp, faCircleCheck } from '@/lib/icons'
|
||||||
getVulnerabilityBorderClass,
|
import { NO_VULNERABILITIES, SEVERITY_TONES, formatSeverityName, severityRank } from '@/lib/severity'
|
||||||
formatSeverityName,
|
|
||||||
} from '@/composables/useBadgeStyles'
|
|
||||||
|
|
||||||
// Configure marked
|
|
||||||
marked.setOptions({
|
|
||||||
breaks: true,
|
|
||||||
gfm: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -332,27 +241,15 @@ const error = ref<string | null>(null)
|
|||||||
const vulnerabilities = ref<VulnerabilityResponse | null>(null)
|
const vulnerabilities = ref<VulnerabilityResponse | null>(null)
|
||||||
const expandedRows = ref<Set<number>>(new Set())
|
const expandedRows = ref<Set<number>>(new Set())
|
||||||
|
|
||||||
// Severity order for sorting (higher values = more severe)
|
|
||||||
const severityOrder: Record<string, number> = {
|
|
||||||
CRITICAL: 4,
|
|
||||||
HIGH: 3,
|
|
||||||
MEDIUM: 2,
|
|
||||||
MODERATE: 2, // Treat MODERATE same as MEDIUM
|
|
||||||
LOW: 1,
|
|
||||||
UNKNOWN: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
const vulnerabilityList = computed(() => {
|
const vulnerabilityList = computed(() => {
|
||||||
const vulns = vulnerabilities.value?.vulnerabilities || []
|
const vulns = vulnerabilities.value?.vulnerabilities || []
|
||||||
// Sort by severity (most severe first)
|
// Sort by severity (most severe first)
|
||||||
return [...vulns].sort((a, b) => {
|
return [...vulns].sort((a, b) => {
|
||||||
const severityA = severityOrder[a.severity.toUpperCase()] || 0
|
return severityRank(b.severity) - severityRank(a.severity)
|
||||||
const severityB = severityOrder[b.severity.toUpperCase()] || 0
|
|
||||||
return severityB - severityA // Descending order
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const severityCounts = computed(() => vulnerabilities.value?.severity_counts || { critical: 0, high: 0, moderate: 0, low: 0 })
|
const severityCounts = computed(() => vulnerabilities.value?.severity_counts || NO_VULNERABILITIES)
|
||||||
const bypassedCount = computed(() => vulnerabilities.value?.bypassed_count || 0)
|
const bypassedCount = computed(() => vulnerabilities.value?.bypassed_count || 0)
|
||||||
|
|
||||||
// Parse scanner string into array of scanner names
|
// Parse scanner string into array of scanner names
|
||||||
@@ -396,21 +293,4 @@ function toggleRow(index: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRowClass(index: number, severity: string): string {
|
|
||||||
const classes = ['cursor-pointer']
|
|
||||||
if (expandedRows.value.has(index)) {
|
|
||||||
classes.push('bg-gray-50')
|
|
||||||
}
|
|
||||||
classes.push(getVulnerabilityBorderClass(severity))
|
|
||||||
return classes.join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(date: string): string {
|
|
||||||
return new Date(date).toLocaleString()
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderMarkdown(text: string): string {
|
|
||||||
if (!text) return ''
|
|
||||||
return marked.parse(text) as string
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ describe('PackageList.vue', () => {
|
|||||||
|
|
||||||
it('renders package list component', async () => {
|
it('renders package list component', async () => {
|
||||||
const wrapper = await mountWithRouter()
|
const wrapper = await mountWithRouter()
|
||||||
expect(wrapper.find('h2').text()).toBe('Packages')
|
expect(wrapper.find('h1').text()).toBe('Packages')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('displays loading state when loading', async () => {
|
it('displays loading state when loading', async () => {
|
||||||
@@ -169,7 +169,7 @@ describe('PackageList.vue', () => {
|
|||||||
expect(wrapper.text()).toContain('1 MB')
|
expect(wrapper.text()).toContain('1 MB')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('applies correct registry badge classes', async () => {
|
it('prints every registry as a badge with its name', async () => {
|
||||||
const wrapper = await mountWithRouter()
|
const wrapper = await mountWithRouter()
|
||||||
const store = usePackageStore()
|
const store = usePackageStore()
|
||||||
|
|
||||||
@@ -214,11 +214,8 @@ describe('PackageList.vue', () => {
|
|||||||
expect(wrapper.text()).toContain('pypi')
|
expect(wrapper.text()).toContain('pypi')
|
||||||
expect(wrapper.text()).toContain('go')
|
expect(wrapper.text()).toContain('go')
|
||||||
|
|
||||||
// Verify badge component is used with correct classes
|
// Each registry is printed as text in an outline badge, never as colour alone.
|
||||||
// (matches getRegistryBadgeClass in src/composables/useBadgeStyles.ts)
|
const badges = wrapper.findAll('[data-slot="badge"]').map((badge) => badge.text())
|
||||||
const html = wrapper.html()
|
expect(badges).toEqual(['go', 'npm', 'pypi'])
|
||||||
expect(html).toContain('bg-red-100') // npm badge
|
|
||||||
expect(html).toContain('bg-blue-100') // pypi badge
|
|
||||||
expect(html).toContain('bg-cyan-100') // go badge
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,128 +1,89 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="flex flex-col gap-6">
|
||||||
<div class="flex justify-between items-center mb-8">
|
<PageHeader title="Packages" description="Everything the proxy has cached, grouped by package.">
|
||||||
<h2 class="text-3xl font-bold text-gray-900">Packages</h2>
|
<template #actions>
|
||||||
<Button @click="store.fetchPackages()">
|
<Button variant="outline" :icon-start="faRotateRight" @click="store.fetchPackages()">Refresh</Button>
|
||||||
<i class="fas fa-sync-alt mr-2"></i>Refresh
|
</template>
|
||||||
</Button>
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4 sm:flex-row sm:items-center">
|
||||||
|
<SegmentedControl
|
||||||
|
:model-value="selectedRegistry"
|
||||||
|
:options="REGISTRY_OPTIONS"
|
||||||
|
aria-label="Filter by registry"
|
||||||
|
@update:model-value="changeRegistryFilter"
|
||||||
|
/>
|
||||||
|
<SearchInput v-model="searchTerm" aria-label="Search packages" placeholder="Search packages..." class="w-full sm:ms-auto sm:w-64" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Filter and Search Section -->
|
<ErrorState
|
||||||
<div class="mb-6 flex flex-col sm:flex-row items-start sm:items-center gap-4">
|
v-if="error"
|
||||||
<div class="flex items-center gap-2">
|
variant="card"
|
||||||
<span class="text-sm font-medium text-gray-700">Filter by registry:</span>
|
title="Could not load packages"
|
||||||
<div class="flex gap-2">
|
:message="error"
|
||||||
<Button
|
@retry="store.fetchPackages()"
|
||||||
@click="changeRegistryFilter('all')"
|
/>
|
||||||
:variant="selectedRegistry === 'all' ? 'default' : 'outline'"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
All
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
@click="changeRegistryFilter('npm')"
|
|
||||||
:variant="selectedRegistry === 'npm' ? 'default' : 'outline'"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
<i class="fab fa-npm mr-2"></i>NPM
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
@click="changeRegistryFilter('pypi')"
|
|
||||||
:variant="selectedRegistry === 'pypi' ? 'default' : 'outline'"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
<i class="fab fa-python mr-2"></i>PyPI
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
@click="changeRegistryFilter('go')"
|
|
||||||
:variant="selectedRegistry === 'go' ? 'default' : 'outline'"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
<i class="fas fa-code mr-2"></i>Go
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center gap-2 w-full sm:w-auto sm:ml-auto">
|
|
||||||
<i class="fas fa-search text-gray-500"></i>
|
|
||||||
<Input
|
|
||||||
v-model="searchTerm"
|
|
||||||
type="text"
|
|
||||||
placeholder="Search packages..."
|
|
||||||
class="w-full sm:w-64"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error Alert -->
|
<LoadingState v-if="loading" variant="table" label="Loading packages..." />
|
||||||
<Alert v-if="error" variant="destructive" class="mb-4">
|
|
||||||
<i class="fas fa-exclamation-circle mr-2"></i>
|
|
||||||
<AlertDescription>{{ error }}</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
|
|
||||||
<!-- Loading State -->
|
|
||||||
<div v-if="loading" class="text-center py-12">
|
|
||||||
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
|
|
||||||
<p class="mt-4 text-gray-600">Loading packages...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Package List -->
|
|
||||||
<Card v-else>
|
<Card v-else>
|
||||||
<CardContent class="p-6">
|
<CardContent>
|
||||||
<div v-if="packages.length === 0" class="text-center py-12 text-gray-500">
|
<EmptyState
|
||||||
<i class="fas fa-inbox text-6xl mb-4"></i>
|
v-if="packages.length === 0"
|
||||||
<p class="text-xl">No packages cached yet</p>
|
:icon="faBoxOpen"
|
||||||
<p class="mt-2">Packages will appear here once they are downloaded through the proxy</p>
|
title="No packages cached yet"
|
||||||
</div>
|
description="Packages will appear here once they are downloaded through the proxy."
|
||||||
|
/>
|
||||||
|
<EmptyState
|
||||||
|
v-else-if="groupedPackages.length === 0"
|
||||||
|
:icon="faMagnifyingGlass"
|
||||||
|
title="No packages match"
|
||||||
|
description="Change the registry filter or the search text."
|
||||||
|
/>
|
||||||
<Accordion v-else type="multiple" class="w-full">
|
<Accordion v-else type="multiple" class="w-full">
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
v-for="group in groupedPackages"
|
v-for="group in groupedPackages"
|
||||||
:key="`${group.registry}:${group.name}`"
|
:key="`${group.registry}:${group.name}`"
|
||||||
:value="`${group.registry}:${group.name}`"
|
:value="`${group.registry}:${group.name}`"
|
||||||
class="border-b border-gray-200"
|
>
|
||||||
>
|
<AccordionTrigger :heading-level="2">
|
||||||
<AccordionTrigger class="px-4 py-4 hover:bg-gray-50">
|
<span class="flex w-full min-w-0 items-center justify-between gap-4">
|
||||||
<div class="flex items-center justify-between w-full pr-4">
|
<span class="min-w-0 text-start">
|
||||||
<div class="flex items-center space-x-4">
|
<span class="block break-words font-semibold">{{ group.name }}</span>
|
||||||
<div class="text-left">
|
<span class="block text-sm text-muted-foreground">
|
||||||
<h4 class="font-semibold text-gray-900">{{ group.name }}</h4>
|
{{ group.versions.length }} version{{ group.versions.length > 1 ? 's' : '' }}
|
||||||
<p class="text-sm text-gray-500">{{ group.versions.length }} version{{ group.versions.length > 1 ? 's' : '' }}</p>
|
</span>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
<span class="flex shrink-0 items-center gap-4">
|
||||||
<div class="flex items-center space-x-6">
|
<Badge variant="outline">{{ group.registry }}</Badge>
|
||||||
<Badge variant="outline" :class="getRegistryBadgeClass(group.registry)">
|
<span class="text-end tabular-nums">
|
||||||
{{ group.registry }}
|
<span class="block text-sm font-medium">{{ formatBytes(group.totalSize) }}</span>
|
||||||
</Badge>
|
<span class="block text-xs text-muted-foreground">{{ formatNumber(group.totalDownloads) }} downloads</span>
|
||||||
<div class="text-right">
|
</span>
|
||||||
<p class="text-sm font-medium text-gray-900">{{ formatBytes(group.totalSize) }}</p>
|
</span>
|
||||||
<p class="text-xs text-gray-500">{{ formatNumber(group.totalDownloads) }} downloads</p>
|
</span>
|
||||||
</div>
|
</AccordionTrigger>
|
||||||
</div>
|
<AccordionContent>
|
||||||
</div>
|
<Table :label="`Versions of ${group.name}`" layout="cards">
|
||||||
</AccordionTrigger>
|
<TableHeader>
|
||||||
<AccordionContent class="px-4 pb-4">
|
<TableRow>
|
||||||
<div class="space-y-3">
|
<TableHead>Version</TableHead>
|
||||||
<div
|
<TableHead align="right">Downloads</TableHead>
|
||||||
v-for="version in group.versions"
|
<TableHead align="right">Size</TableHead>
|
||||||
:key="version.id"
|
<TableHead>Cached</TableHead>
|
||||||
class="flex items-center justify-between p-4 bg-gray-50 rounded-lg hover:bg-gray-100"
|
<TableHead>Vulnerabilities</TableHead>
|
||||||
>
|
<TableHead align="right">Actions</TableHead>
|
||||||
<div class="flex items-center space-x-4 flex-1">
|
</TableRow>
|
||||||
<div class="flex-1">
|
</TableHeader>
|
||||||
<p class="font-medium text-gray-900">{{ version.version.startsWith('v') ? version.version : 'v' + version.version }}</p>
|
<TableBody>
|
||||||
<div class="flex items-center space-x-4 mt-1 text-sm text-gray-500">
|
<TableRow v-for="version in group.versions" :key="version.id">
|
||||||
<span>
|
<TableCell label="Version" class="font-medium">{{ withVersionPrefix(version.version) }}</TableCell>
|
||||||
<i class="fas fa-download mr-1"></i>{{ formatNumber(version.download_count) }}
|
<TableCell label="Downloads" numeric>{{ formatNumber(version.download_count) }}</TableCell>
|
||||||
</span>
|
<TableCell label="Size" numeric>{{ formatBytes(version.size) }}</TableCell>
|
||||||
<span>
|
<TableCell label="Cached">{{ formatDate(version.cached_at) }}</TableCell>
|
||||||
<i class="fas fa-hard-drive mr-1"></i>{{ formatBytes(version.size) }}
|
<TableCell label="Vulnerabilities">
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
<i class="fas fa-clock mr-1"></i>{{ formatDate(version.cached_at) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<!-- Vulnerability Badge -->
|
|
||||||
<div v-if="version.vulnerabilities" class="mt-2">
|
|
||||||
<VulnerabilityBadge
|
<VulnerabilityBadge
|
||||||
|
v-if="version.vulnerabilities"
|
||||||
:scanned="version.vulnerabilities.scanned"
|
:scanned="version.vulnerabilities.scanned"
|
||||||
:status="version.vulnerabilities.status"
|
:status="version.vulnerabilities.status"
|
||||||
:counts="version.vulnerabilities.counts"
|
:counts="version.vulnerabilities.counts"
|
||||||
@@ -131,106 +92,44 @@
|
|||||||
:isBlocked="version.vulnerabilities.isBlocked"
|
:isBlocked="version.vulnerabilities.isBlocked"
|
||||||
@click="showVulnerabilityDetails(group.registry, group.name, version.version)"
|
@click="showVulnerabilityDetails(group.registry, group.name, version.version)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</TableCell>
|
||||||
</div>
|
<TableCell label="Actions" align="right">
|
||||||
</div>
|
<IconButton
|
||||||
<button
|
:icon="faTrash"
|
||||||
@click="confirmDelete(version)"
|
:label="`Delete ${group.name} ${version.version}`"
|
||||||
class="text-red-600 hover:text-red-900 p-2"
|
@click="confirmDelete(version)"
|
||||||
title="Delete this version"
|
/>
|
||||||
>
|
</TableCell>
|
||||||
<i class="fas fa-trash"></i>
|
</TableRow>
|
||||||
</button>
|
</TableBody>
|
||||||
</div>
|
</Table>
|
||||||
</div>
|
</AccordionContent>
|
||||||
</AccordionContent>
|
</AccordionItem>
|
||||||
</AccordionItem>
|
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<!-- Pagination -->
|
<div v-if="totalPages > 1" class="mt-6 flex flex-col gap-3 border-t pt-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div v-if="totalPages > 1" class="mt-6 flex items-center justify-between border-t pt-4">
|
<p class="m-0 text-sm text-muted-foreground">
|
||||||
<div class="text-sm text-gray-700">
|
|
||||||
Page {{ currentPage }} of {{ totalPages }} ({{ allGroupedPackages.length }} total packages)
|
Page {{ currentPage }} of {{ totalPages }} ({{ allGroupedPackages.length }} total packages)
|
||||||
</div>
|
</p>
|
||||||
<div class="flex items-center gap-2">
|
<Pagination
|
||||||
<Button
|
:page="currentPage"
|
||||||
@click="changePage(currentPage - 1)"
|
:total="allGroupedPackages.length"
|
||||||
:disabled="currentPage === 1"
|
:page-size="itemsPerPage"
|
||||||
variant="outline"
|
@update:page="changePage"
|
||||||
size="sm"
|
/>
|
||||||
>
|
|
||||||
<i class="fas fa-chevron-left mr-2"></i>Previous
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<div class="flex gap-1">
|
|
||||||
<!-- First page -->
|
|
||||||
<Button
|
|
||||||
v-if="currentPage > 3"
|
|
||||||
@click="changePage(1)"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
1
|
|
||||||
</Button>
|
|
||||||
<span v-if="currentPage > 4" class="px-2">...</span>
|
|
||||||
|
|
||||||
<!-- Page numbers around current page -->
|
|
||||||
<Button
|
|
||||||
v-for="page in getPageNumbers()"
|
|
||||||
:key="page"
|
|
||||||
@click="changePage(page)"
|
|
||||||
:variant="page === currentPage ? 'default' : 'outline'"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{{ page }}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<span v-if="currentPage < totalPages - 3" class="px-2">...</span>
|
|
||||||
<!-- Last page -->
|
|
||||||
<Button
|
|
||||||
v-if="currentPage < totalPages - 2"
|
|
||||||
@click="changePage(totalPages)"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{{ totalPages }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
@click="changePage(currentPage + 1)"
|
|
||||||
:disabled="currentPage === totalPages"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
Next<i class="fas fa-chevron-right ml-2"></i>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- Delete Confirmation Dialog -->
|
<ConfirmDialog
|
||||||
<Dialog v-model:open="showDeleteModal">
|
v-model:open="showDeleteModal"
|
||||||
<DialogContent>
|
title="Delete package version?"
|
||||||
<DialogHeader>
|
:description="`Delete ${packageToDelete?.name}@${packageToDelete?.version}? This action cannot be undone.`"
|
||||||
<DialogTitle>Confirm Deletion</DialogTitle>
|
confirm-label="Delete version"
|
||||||
<DialogDescription>
|
tone="danger"
|
||||||
Are you sure you want to delete <strong>{{ packageToDelete?.name }}@{{ packageToDelete?.version }}</strong>?
|
destructive
|
||||||
This action cannot be undone.
|
@confirm="deletePackage"
|
||||||
</DialogDescription>
|
/>
|
||||||
</DialogHeader>
|
|
||||||
<DialogFooter>
|
|
||||||
<Button @click="showDeleteModal = false" variant="outline">
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button @click="deletePackage" variant="destructive">
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -244,22 +143,30 @@ import {
|
|||||||
AccordionContent,
|
AccordionContent,
|
||||||
AccordionItem,
|
AccordionItem,
|
||||||
AccordionTrigger,
|
AccordionTrigger,
|
||||||
} from '@/components/ui/accordion'
|
Badge,
|
||||||
import { Button } from '@/components/ui/button'
|
Button,
|
||||||
import {
|
Card,
|
||||||
Dialog,
|
CardContent,
|
||||||
DialogContent,
|
ConfirmDialog,
|
||||||
DialogDescription,
|
EmptyState,
|
||||||
DialogFooter,
|
ErrorState,
|
||||||
DialogHeader,
|
IconButton,
|
||||||
DialogTitle,
|
LoadingState,
|
||||||
} from '@/components/ui/dialog'
|
PageHeader,
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
Pagination,
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
SearchInput,
|
||||||
import { Badge } from '@/components/ui/badge'
|
SegmentedControl,
|
||||||
import { Input } from '@/components/ui/input'
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
useToastStore,
|
||||||
|
} from '@perfect-design/ui'
|
||||||
import VulnerabilityBadge from './VulnerabilityBadge.vue'
|
import VulnerabilityBadge from './VulnerabilityBadge.vue'
|
||||||
import { getRegistryBadgeClass } from '@/composables/useBadgeStyles'
|
import { formatBytes, formatDate, formatNumber, withVersionPrefix } from '@/lib/format'
|
||||||
|
import { faBoxOpen, faMagnifyingGlass, faRotateRight, faTrash } from '@/lib/icons'
|
||||||
|
|
||||||
// Props from router
|
// Props from router
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -269,10 +176,18 @@ const props = defineProps<{
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const store = usePackageStore()
|
const store = usePackageStore()
|
||||||
|
const toasts = useToastStore()
|
||||||
const { packages, loading, error } = storeToRefs(store)
|
const { packages, loading, error } = storeToRefs(store)
|
||||||
|
|
||||||
const showDeleteModal = ref(false)
|
const showDeleteModal = ref(false)
|
||||||
const packageToDelete = ref<Package | null>(null)
|
const packageToDelete = ref<Package | null>(null)
|
||||||
|
const REGISTRY_OPTIONS = [
|
||||||
|
{ value: 'all', label: 'All' },
|
||||||
|
{ value: 'npm', label: 'npm' },
|
||||||
|
{ value: 'pypi', label: 'PyPI' },
|
||||||
|
{ value: 'go', label: 'Go' },
|
||||||
|
]
|
||||||
|
|
||||||
const selectedRegistry = ref<string>(props.registry || 'all')
|
const selectedRegistry = ref<string>(props.registry || 'all')
|
||||||
const searchTerm = ref<string>('')
|
const searchTerm = ref<string>('')
|
||||||
const currentPage = ref<number>(1)
|
const currentPage = ref<number>(1)
|
||||||
@@ -336,18 +251,6 @@ function changePage(page: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get page numbers to display around current page
|
|
||||||
function getPageNumbers(): number[] {
|
|
||||||
const pages: number[] = []
|
|
||||||
const start = Math.max(1, currentPage.value - 2)
|
|
||||||
const end = Math.min(totalPages.value, currentPage.value + 2)
|
|
||||||
|
|
||||||
for (let i = start; i <= end; i++) {
|
|
||||||
pages.push(i)
|
|
||||||
}
|
|
||||||
return pages
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset to page 1 when filters change
|
// Reset to page 1 when filters change
|
||||||
function resetPagination() {
|
function resetPagination() {
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
@@ -373,31 +276,14 @@ function confirmDelete(pkg: Package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deletePackage() {
|
async function deletePackage() {
|
||||||
if (packageToDelete.value) {
|
const target = packageToDelete.value
|
||||||
await store.deletePackage(
|
if (!target) return
|
||||||
packageToDelete.value.registry,
|
await store.deletePackage(target.registry, target.name, target.version)
|
||||||
packageToDelete.value.name,
|
showDeleteModal.value = false
|
||||||
packageToDelete.value.version
|
packageToDelete.value = null
|
||||||
)
|
const label = `${target.name}@${target.version}`
|
||||||
showDeleteModal.value = false
|
if (store.error) toasts.error('Could not delete package', `${label}: ${store.error}`)
|
||||||
packageToDelete.value = null
|
else toasts.success('Package deleted', label)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatNumber(num: number): string {
|
|
||||||
return new Intl.NumberFormat().format(num)
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatBytes(bytes: number): string {
|
|
||||||
if (bytes === 0) return '0 B'
|
|
||||||
const k = 1024
|
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
||||||
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(date: string): string {
|
|
||||||
return new Date(date).toLocaleString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVulnerabilityDetails(registry: string, name: string, version: string) {
|
function showVulnerabilityDetails(registry: string, name: string, version: string) {
|
||||||
|
|||||||
@@ -1,159 +1,103 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-7xl mx-auto px-4 py-8">
|
<div class="flex flex-col gap-6">
|
||||||
<!-- Header -->
|
<PageHeader
|
||||||
<div class="mb-6">
|
:title="showOnlyBlocked ? 'Blocked packages' : 'Vulnerable packages'"
|
||||||
<Button @click="goBack" variant="ghost" class="mb-4">
|
:description="
|
||||||
<i class="fas fa-arrow-left mr-2"></i>
|
showOnlyBlocked
|
||||||
Back to Stats
|
? 'Packages blocked from download because they exceed the vulnerability thresholds.'
|
||||||
</Button>
|
: 'Packages with known security vulnerabilities, sorted by risk.'
|
||||||
<div class="flex items-center gap-3">
|
"
|
||||||
<i :class="showOnlyBlocked ? 'fas fa-hand' : 'fas fa-exclamation-triangle'" class="text-3xl text-red-600"></i>
|
>
|
||||||
<div>
|
<template #back>
|
||||||
<h1 class="text-3xl font-bold text-gray-900">
|
<Button variant="ghost" size="sm" :icon-start="faArrowLeft" @click="goBack">Back to stats</Button>
|
||||||
{{ showOnlyBlocked ? 'Blocked Packages' : 'Vulnerable Packages' }}
|
</template>
|
||||||
</h1>
|
</PageHeader>
|
||||||
<p class="text-gray-600 mt-1">
|
|
||||||
{{ showOnlyBlocked
|
|
||||||
? 'Packages blocked from download due to exceeding vulnerability thresholds'
|
|
||||||
: 'Packages with known security vulnerabilities, sorted by risk'
|
|
||||||
}}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Loading State -->
|
<LoadingState v-if="loading" variant="card" label="Loading vulnerable packages..." />
|
||||||
<div v-if="loading" class="text-center py-12">
|
|
||||||
<i class="fas fa-spinner fa-spin text-4xl text-primary-600"></i>
|
|
||||||
<p class="mt-4 text-gray-600">Loading vulnerable packages...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Error State -->
|
<ErrorState
|
||||||
<Alert v-else-if="error" variant="destructive" class="mb-4">
|
v-else-if="error"
|
||||||
<i class="fas fa-exclamation-circle mr-2"></i>
|
variant="card"
|
||||||
<AlertDescription>{{ error }}</AlertDescription>
|
title="Could not load vulnerable packages"
|
||||||
</Alert>
|
:message="error"
|
||||||
|
@retry="fetchVulnerablePackages"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Empty State -->
|
|
||||||
<Card v-else-if="sortedVulnerablePackages.length === 0">
|
<Card v-else-if="sortedVulnerablePackages.length === 0">
|
||||||
<CardContent class="text-center py-12">
|
<CardContent>
|
||||||
<i class="fas fa-check-circle text-6xl text-green-500 mb-4"></i>
|
<EmptyState
|
||||||
<p class="text-xl font-semibold text-gray-900">No Vulnerable Packages</p>
|
tone="success"
|
||||||
<p class="mt-2 text-gray-600">All your packages are clean and safe to use!</p>
|
:icon="faCircleCheck"
|
||||||
|
:title="showOnlyBlocked ? 'No blocked packages' : 'No vulnerable packages'"
|
||||||
|
description="Every cached package is clean."
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- Vulnerable Packages List -->
|
<template v-else>
|
||||||
<div v-else class="space-y-6">
|
<SeveritySummary :counts="totalCounts" label="Vulnerabilities by severity" />
|
||||||
<!-- Summary Card -->
|
|
||||||
<Card>
|
|
||||||
<CardContent class="p-6">
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
|
||||||
<div class="text-center p-4 bg-red-50 rounded-lg border border-red-200">
|
|
||||||
<p class="text-3xl font-bold text-red-600">{{ criticalCount }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">Critical</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-center p-4 bg-orange-50 rounded-lg border border-orange-200">
|
|
||||||
<p class="text-3xl font-bold text-orange-600">{{ highCount }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">High</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-center p-4 bg-yellow-50 rounded-lg border border-yellow-200">
|
|
||||||
<p class="text-3xl font-bold text-yellow-600">{{ moderateCount }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">Moderate</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-center p-4 bg-blue-50 rounded-lg border border-blue-200">
|
|
||||||
<p class="text-3xl font-bold text-blue-600">{{ lowCount }}</p>
|
|
||||||
<p class="text-sm text-gray-600 mt-1">Low</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<!-- Packages List -->
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent class="p-6">
|
<CardHeader>
|
||||||
<div class="mb-4">
|
<CardTitle as="h2">
|
||||||
<h3 class="text-xl font-semibold text-gray-900">
|
{{ showOnlyBlocked ? 'Blocked' : 'Vulnerable' }} packages ({{ sortedVulnerablePackages.length }})
|
||||||
<i class="fas fa-list mr-2"></i>
|
</CardTitle>
|
||||||
Vulnerable Packages ({{ sortedVulnerablePackages.length }})
|
<CardDescription>
|
||||||
</h3>
|
{{ groupedPackages.length }} unique package{{ groupedPackages.length !== 1 ? 's' : '' }}, most critical first
|
||||||
<p class="text-sm text-gray-600 mt-1">
|
</CardDescription>
|
||||||
{{ groupedPackages.length }} unique package{{ groupedPackages.length !== 1 ? 's' : '' }} • Sorted by risk: Critical → High → Moderate → Low
|
</CardHeader>
|
||||||
</p>
|
<CardContent>
|
||||||
</div>
|
|
||||||
<Accordion type="multiple" class="w-full">
|
<Accordion type="multiple" class="w-full">
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
v-for="group in groupedPackages"
|
v-for="group in groupedPackages"
|
||||||
:key="`${group.registry}:${group.name}`"
|
:key="`${group.registry}:${group.name}`"
|
||||||
:value="`${group.registry}:${group.name}`"
|
:value="`${group.registry}:${group.name}`"
|
||||||
class="border-b border-gray-200"
|
|
||||||
>
|
>
|
||||||
<AccordionTrigger class="px-4 py-4 hover:bg-gray-50">
|
<AccordionTrigger :heading-level="3">
|
||||||
<div class="flex items-center justify-between w-full pr-4">
|
<span class="flex w-full min-w-0 items-center justify-between gap-4">
|
||||||
<div class="flex items-center space-x-4 flex-1 min-w-0">
|
<span class="min-w-0 text-start">
|
||||||
<div class="text-left flex-1 min-w-0">
|
<span class="block break-words font-semibold">{{ group.name }}</span>
|
||||||
<h4 class="font-semibold text-gray-900 break-words">{{ group.name }}</h4>
|
<span class="block text-sm text-muted-foreground">
|
||||||
<p class="text-sm text-gray-500">{{ group.versions.length }} vulnerable version{{ group.versions.length > 1 ? 's' : '' }}</p>
|
{{ group.versions.length }} vulnerable version{{ group.versions.length > 1 ? 's' : '' }}
|
||||||
</div>
|
</span>
|
||||||
</div>
|
</span>
|
||||||
<div class="flex items-center space-x-6 flex-shrink-0">
|
<span class="flex shrink-0 items-center gap-4">
|
||||||
<Badge variant="outline" :class="getRegistryBadgeClass(group.registry)">
|
<Badge variant="outline">{{ group.registry }}</Badge>
|
||||||
{{ group.registry }}
|
<span class="whitespace-nowrap text-end tabular-nums">
|
||||||
</Badge>
|
<span class="block text-sm font-medium">{{ formatBytes(group.totalSize) }}</span>
|
||||||
<div class="text-right whitespace-nowrap">
|
<span class="block text-xs text-muted-foreground">{{ formatNumber(group.totalDownloads) }} downloads</span>
|
||||||
<p class="text-sm font-medium text-gray-900">{{ formatBytes(group.totalSize) }}</p>
|
</span>
|
||||||
<p class="text-xs text-gray-500">{{ formatNumber(group.totalDownloads) }} downloads</p>
|
</span>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
<AccordionContent class="px-4 pb-4">
|
<AccordionContent>
|
||||||
<div class="space-y-3">
|
<DataTable
|
||||||
<div
|
:label="`Vulnerable versions of ${group.name}`"
|
||||||
v-for="version in group.versions"
|
layout="cards"
|
||||||
:key="version.id"
|
row-clickable
|
||||||
class="flex items-center justify-between p-4 bg-gray-50 rounded-lg hover:bg-gray-100 cursor-pointer"
|
:columns="versionColumns"
|
||||||
@click="navigateToPackage(version)"
|
:rows="group.versions"
|
||||||
>
|
@row-click="navigateToPackage"
|
||||||
<div class="flex items-center space-x-4 flex-1">
|
>
|
||||||
<div class="flex-1">
|
<template #cell-vulnerabilities="{ row }">
|
||||||
<p class="font-medium text-gray-900">{{ version.version.startsWith('v') ? version.version : 'v' + version.version }}</p>
|
<VulnerabilityBadge
|
||||||
<div class="flex items-center space-x-4 mt-1 text-sm text-gray-500">
|
v-if="row.vulnerabilities"
|
||||||
<span>
|
:scanned="row.vulnerabilities.scanned"
|
||||||
<i class="fas fa-download mr-1"></i>{{ formatNumber(version.download_count) }}
|
:status="row.vulnerabilities.status"
|
||||||
</span>
|
:counts="row.vulnerabilities.counts"
|
||||||
<span>
|
:total="row.vulnerabilities.total"
|
||||||
<i class="fas fa-hard-drive mr-1"></i>{{ formatBytes(version.size) }}
|
:scannedAt="row.vulnerabilities.scannedAt"
|
||||||
</span>
|
:isBlocked="row.vulnerabilities.isBlocked"
|
||||||
<span>
|
@click="navigateToPackage(row)"
|
||||||
<i class="fas fa-clock mr-1"></i>{{ formatDate(version.cached_at) }}
|
/>
|
||||||
</span>
|
</template>
|
||||||
</div>
|
</DataTable>
|
||||||
<!-- Vulnerability Badge -->
|
|
||||||
<div v-if="version.vulnerabilities" class="mt-2">
|
|
||||||
<VulnerabilityBadge
|
|
||||||
:scanned="version.vulnerabilities.scanned"
|
|
||||||
:status="version.vulnerabilities.status"
|
|
||||||
:counts="version.vulnerabilities.counts"
|
|
||||||
:total="version.vulnerabilities.total"
|
|
||||||
:scannedAt="version.vulnerabilities.scannedAt"
|
|
||||||
:isBlocked="version.vulnerabilities.isBlocked"
|
|
||||||
@click.stop="navigateToPackage(version)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ml-4 flex-shrink-0">
|
|
||||||
<i class="fas fa-chevron-right text-gray-400"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -161,18 +105,30 @@
|
|||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { usePackageStore, type Package } from '../stores/packages'
|
import { usePackageStore, type Package } from '../stores/packages'
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
|
||||||
import { Badge } from '@/components/ui/badge'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionContent,
|
AccordionContent,
|
||||||
AccordionItem,
|
AccordionItem,
|
||||||
AccordionTrigger,
|
AccordionTrigger,
|
||||||
} from '@/components/ui/accordion'
|
Badge,
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
DataTable,
|
||||||
|
EmptyState,
|
||||||
|
ErrorState,
|
||||||
|
LoadingState,
|
||||||
|
PageHeader,
|
||||||
|
type DataTableColumn,
|
||||||
|
} from '@perfect-design/ui'
|
||||||
import VulnerabilityBadge from './VulnerabilityBadge.vue'
|
import VulnerabilityBadge from './VulnerabilityBadge.vue'
|
||||||
import { getRegistryBadgeClass } from '@/composables/useBadgeStyles'
|
import SeveritySummary from './SeveritySummary.vue'
|
||||||
|
import { formatBytes, formatDate, formatNumber, withVersionPrefix } from '@/lib/format'
|
||||||
|
import { faArrowLeft, faCircleCheck } from '@/lib/icons'
|
||||||
|
import { NO_VULNERABILITIES } from '@/lib/severity'
|
||||||
|
|
||||||
const store = usePackageStore()
|
const store = usePackageStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -267,21 +223,28 @@ const groupedPackages = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Calculate total counts across all packages
|
// Calculate total counts across all packages
|
||||||
const criticalCount = computed(() =>
|
const totalCounts = computed(() =>
|
||||||
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.critical || 0), 0)
|
vulnerablePackages.value.reduce(
|
||||||
|
(sum, pkg) => {
|
||||||
|
const counts = pkg.vulnerabilities?.counts ?? NO_VULNERABILITIES
|
||||||
|
return {
|
||||||
|
critical: sum.critical + counts.critical,
|
||||||
|
high: sum.high + counts.high,
|
||||||
|
moderate: sum.moderate + counts.moderate,
|
||||||
|
low: sum.low + counts.low,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ ...NO_VULNERABILITIES },
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const highCount = computed(() =>
|
const versionColumns: DataTableColumn<Package>[] = [
|
||||||
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.high || 0), 0)
|
{ key: 'version', header: 'Version', rowHeader: true, accessor: (pkg) => withVersionPrefix(pkg.version) },
|
||||||
)
|
{ key: 'download_count', header: 'Downloads', numeric: true, accessor: (pkg) => formatNumber(pkg.download_count) },
|
||||||
|
{ key: 'size', header: 'Size', numeric: true, accessor: (pkg) => formatBytes(pkg.size) },
|
||||||
const moderateCount = computed(() =>
|
{ key: 'cached_at', header: 'Cached', accessor: (pkg) => formatDate(pkg.cached_at) },
|
||||||
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.moderate || 0), 0)
|
{ key: 'vulnerabilities', header: 'Vulnerabilities', accessor: () => '' },
|
||||||
)
|
]
|
||||||
|
|
||||||
const lowCount = computed(() =>
|
|
||||||
vulnerablePackages.value.reduce((sum, pkg) => sum + (pkg.vulnerabilities?.counts?.low || 0), 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
function navigateToPackage(pkg: Package) {
|
function navigateToPackage(pkg: Package) {
|
||||||
router.push(`/package/${pkg.registry}/${pkg.name}/${pkg.version}`)
|
router.push(`/package/${pkg.registry}/${pkg.name}/${pkg.version}`)
|
||||||
@@ -290,32 +253,4 @@ function navigateToPackage(pkg: Package) {
|
|||||||
function goBack() {
|
function goBack() {
|
||||||
router.push('/stats')
|
router.push('/stats')
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatNumber(num: number): string {
|
|
||||||
return new Intl.NumberFormat().format(num)
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatBytes(bytes: number): string {
|
|
||||||
if (bytes === 0) return '0 B'
|
|
||||||
const k = 1024
|
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
||||||
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(dateString: string): string {
|
|
||||||
if (!dateString) return 'N/A'
|
|
||||||
try {
|
|
||||||
const date = new Date(dateString)
|
|
||||||
return date.toLocaleDateString('en-US', {
|
|
||||||
year: 'numeric',
|
|
||||||
month: 'short',
|
|
||||||
day: 'numeric',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit'
|
|
||||||
})
|
|
||||||
} catch {
|
|
||||||
return dateString
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user