11import { VULNERABILITIES_URL } from '#site/next.constants.mjs' ;
2+ import { fetchWithRetry } from '#site/util/fetch' ;
23
34const RANGE_REGEX = / ( [ < > ] = ? ) \s * ( \d + ) (?: \. ( \d + ) ) ? / ;
5+ const V0_REGEX = / ^ 0 \. \d + ( \. x ) ? $ / ;
6+ const VER_REGEX = / ^ \d + \. x $ / ;
47
58/**
69 * Fetches vulnerability data from the Node.js Security Working Group repository,
@@ -9,7 +12,7 @@ const RANGE_REGEX = /([<>]=?)\s*(\d+)(?:\.(\d+))?/;
912 * @returns {Promise<import('#site/types/vulnerabilities').GroupedVulnerabilities> } Grouped vulnerabilities
1013 */
1114export default async function generateVulnerabilityData ( ) {
12- const response = await fetch ( VULNERABILITIES_URL ) ;
15+ const response = await fetchWithRetry ( VULNERABILITIES_URL ) ;
1316
1417 /** @type {Array<import('#site/types/vulnerabilities').RawVulnerability> } */
1518 const data = Object . values ( await response . json ( ) ) ;
@@ -26,14 +29,14 @@ export default async function generateVulnerabilityData() {
2629 // Helper function to process version patterns
2730 const processVersion = ( version , vulnerability ) => {
2831 // Handle 0.X versions (pre-semver)
29- if ( / ^ 0 \. \d + ( \. x ) ? $ / . test ( version ) ) {
32+ if ( V0_REGEX . test ( version ) ) {
3033 addToGroup ( '0' , vulnerability ) ;
3134
3235 return ;
3336 }
3437
3538 // Handle simple major.x patterns (e.g., 12.x)
36- if ( / ^ \d + \. x $ / . test ( version ) ) {
39+ if ( VER_REGEX . test ( version ) ) {
3740 const majorVersion = version . split ( '.' ) [ 0 ] ;
3841
3942 addToGroup ( majorVersion , vulnerability ) ;
@@ -67,25 +70,14 @@ export default async function generateVulnerabilityData() {
6770 }
6871 } ;
6972
70- for ( const vulnerability of Object . values ( data ) ) {
71- const parsedVulnerability = {
72- cve : vulnerability . cve ,
73- url : vulnerability . ref ,
74- vulnerable : vulnerability . vulnerable ,
75- patched : vulnerability . patched ,
76- description : vulnerability . description ,
77- overview : vulnerability . overview ,
78- affectedEnvironments : vulnerability . affectedEnvironments ,
79- severity : vulnerability . severity ,
80- } ;
73+ for ( const { ref, ...vulnerability } of Object . values ( data ) ) {
74+ vulnerability . url = ref ;
8175
8276 // Process all potential versions from the vulnerable field
83- const versions = parsedVulnerability . vulnerable
84- . split ( ' || ' )
85- . filter ( Boolean ) ;
77+ const versions = vulnerability . vulnerable . split ( ' || ' ) . filter ( Boolean ) ;
8678
8779 for ( const version of versions ) {
88- processVersion ( version , parsedVulnerability ) ;
80+ processVersion ( version , vulnerability ) ;
8981 }
9082 }
9183
0 commit comments