@@ -616,6 +616,7 @@ export interface AdvisoryRow {
616616 osvId : string
617617 severity : string
618618 resolution : 'open' | 'patched' | null
619+ isCritical : boolean
619620}
620621
621622export async function getPackageDetailByPurl (
@@ -775,13 +776,21 @@ export async function listPackagesForScatter(
775776export async function getAdvisoriesByPackageId (
776777 qx : QueryExecutor ,
777778 packageId : string ,
778- opts ?: { page : number ; pageSize : number ; version ?: string ; severities ?: string [ ] } ,
779+ opts ?: {
780+ page : number
781+ pageSize : number
782+ version ?: string
783+ severities ?: string [ ]
784+ resolutions ?: ( 'open' | 'patched' ) [ ]
785+ critical ?: boolean
786+ } ,
779787) : Promise < { rows : AdvisoryRow [ ] ; total : number } > {
780788 const cte = `
781789 WITH advisory_data AS (
782790 SELECT
783791 a.osv_id AS "osvId",
784792 LOWER(a.severity) AS severity,
793+ a.is_critical AS "isCritical",
785794 CASE
786795 WHEN COALESCE($(version), p.latest_version) IS NULL THEN NULL
787796 WHEN COUNT(ar.id) = 0 THEN NULL
@@ -803,25 +812,36 @@ export async function getAdvisoriesByPackageId(
803812 LEFT JOIN advisory_affected_ranges ar ON ar.advisory_package_id = ap.id
804813 JOIN packages p ON p.id = ap.package_id
805814 WHERE ap.package_id = $(packageId)::bigint
806- GROUP BY a.osv_id, a.severity, p.latest_version
815+ GROUP BY a.osv_id, a.severity, a.is_critical, p.latest_version
807816 )
808817 `
809818
810- const severityClause = opts ?. severities ?. length
811- ? `WHERE severity = ANY($(severities)::text[])`
812- : ''
819+ const conditions : string [ ] = [ ]
820+ if ( opts ?. severities ?. length ) {
821+ conditions . push ( 'severity = ANY($(severities)::text[])' )
822+ }
823+ if ( opts ?. resolutions ?. length ) {
824+ conditions . push ( 'resolution = ANY($(resolutions)::text[])' )
825+ }
826+ if ( opts ?. critical !== undefined ) {
827+ conditions . push ( '"isCritical" = $(critical)' )
828+ }
829+
830+ const whereClause = conditions . length ? `WHERE ${ conditions . join ( ' AND ' ) } ` : ''
813831 const paginationClause = opts ? `LIMIT $(limit) OFFSET $(offset)` : ''
814832 const params = {
815833 packageId,
816834 version : opts ?. version ?? null ,
817835 severities : opts ?. severities ?? null ,
836+ resolutions : opts ?. resolutions ?? null ,
837+ critical : opts ?. critical ?? null ,
818838 limit : opts ?. pageSize ,
819839 offset : opts ? ( opts . page - 1 ) * opts . pageSize : 0 ,
820840 }
821841
822842 const rows = ( await qx . select (
823843 `${ cte } SELECT * FROM advisory_data
824- ${ severityClause }
844+ ${ whereClause }
825845 ORDER BY
826846 CASE severity WHEN 'critical' THEN 1 WHEN 'high' THEN 2 WHEN 'moderate' THEN 3 WHEN 'low' THEN 4 ELSE 5 END,
827847 CASE resolution WHEN 'open' THEN 1 WHEN 'patched' THEN 2 ELSE 3 END,
@@ -835,7 +855,7 @@ export async function getAdvisoriesByPackageId(
835855 }
836856
837857 const countResult = ( await qx . selectOne (
838- `${ cte } SELECT COUNT(*) AS total FROM advisory_data ${ severityClause } ` ,
858+ `${ cte } SELECT COUNT(*) AS total FROM advisory_data ${ whereClause } ` ,
839859 params ,
840860 ) ) as { total : string }
841861
0 commit comments