Skip to content

Commit d265052

Browse files
committed
fixup!
1 parent 6a3b0bb commit d265052

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

apps/site/next-data/generators/supportersData.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs';
2+
import { fetchWithRetry } from '#site/util/fetch';
23

34
/**
45
* Fetches supporters data from Open Collective API, filters active backers,
@@ -7,7 +8,7 @@ import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs';
78
* @returns {Promise<Array<import('#site/types/supporters').OpenCollectiveSupporter>>} Array of supporters
89
*/
910
export default () =>
10-
fetch(OPENCOLLECTIVE_MEMBERS_URL)
11+
fetchWithRetry(OPENCOLLECTIVE_MEMBERS_URL)
1112
.then(response => response.json())
1213
.then(payload =>
1314
payload
@@ -20,5 +21,4 @@ export default () =>
2021
profile,
2122
source: 'opencollective',
2223
}))
23-
)
24-
.catch(() => []);
24+
);

apps/site/next-data/generators/vulnerabilities.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { VULNERABILITIES_URL } from '#site/next.constants.mjs';
2+
import { fetchWithRetry } from '#site/util/fetch';
23

34
const 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
*/
1114
export default () =>
12-
fetch(VULNERABILITIES_URL)
15+
fetchWithRetry(VULNERABILITIES_URL)
1316
.then(response => response.json())
1417
.then(payload => {
1518
/** @type {Array<import('#site/types/vulnerabilities').RawVulnerability>} */
@@ -27,14 +30,14 @@ export default () =>
2730
// Helper function to process version patterns
2831
const processVersion = (version, vulnerability) => {
2932
// Handle 0.X versions (pre-semver)
30-
if (/^0\.\d+(\.x)?$/.test(version)) {
33+
if (V0_REGEX.test(version)) {
3134
addToGroup('0', vulnerability);
3235

3336
return;
3437
}
3538

3639
// Handle simple major.x patterns (e.g., 12.x)
37-
if (/^\d+\.x$/.test(version)) {
40+
if (VER_REGEX.test(version)) {
3841
const majorVersion = version.split('.')[0];
3942

4043
addToGroup(majorVersion, vulnerability);
@@ -79,5 +82,4 @@ export default () =>
7982
}
8083

8184
return grouped;
82-
})
83-
.catch(() => ({}));
85+
});

apps/site/next.calendar.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
BASE_CALENDAR_URL,
55
SHARED_CALENDAR_KEY,
66
} from './next.calendar.constants.mjs';
7+
import { fetchWithRetry } from './util/fetch';
78

89
/**
910
*
@@ -33,7 +34,7 @@ export const getCalendarEvents = async (calendarId = '', maxResults = 20) => {
3334
calendarQueryUrl.searchParams.append(key, value)
3435
);
3536

36-
return fetch(calendarQueryUrl)
37+
return fetchWithRetry(calendarQueryUrl)
3738
.then(response => response.json())
3839
.then(calendar => calendar.items ?? []);
3940
};

apps/site/types/supporters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export type Supporter = {
1+
export type Supporter<T extends string> = {
22
name: string;
33
image: string;
44
url: string;
55
profile: string;
6-
source: string;
6+
source: T;
77
};
88

9-
export type OpenCollectiveSupporter = Supporter & { source: 'opencollective' };
9+
export type OpenCollectiveSupporter = Supporter<'opencollective'>;

apps/site/util/fetch.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { setTimeout } from 'node:timers/promises';
2+
3+
type RetryOptions = RequestInit & {
4+
maxRetry: number;
5+
delay: number;
6+
};
7+
8+
export const fetchWithRetry = async (
9+
url: string,
10+
{ maxRetry = 3, delay = 100, ...options }: RetryOptions
11+
) => {
12+
for (let i = 1; i <= maxRetry; i++) {
13+
try {
14+
return fetch(url, options);
15+
} catch (e) {
16+
if (i === maxRetry) {
17+
throw e;
18+
}
19+
20+
await setTimeout(delay);
21+
continue;
22+
}
23+
}
24+
};

0 commit comments

Comments
 (0)