-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathsupportersData.mjs
More file actions
32 lines (27 loc) · 1.04 KB
/
supportersData.mjs
File metadata and controls
32 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs';
import { fetchWithRetry } from '#site/next.fetch.mjs';
/**
* Fetches supporters data from Open Collective API, filters active backers,
* and maps it to the Supporters type.
*
* @returns {Promise<Array<import('#site/types/supporters').OpenCollectiveSupporter>>} Array of supporters
*/
async function fetchOpenCollectiveData() {
const response = await fetchWithRetry(OPENCOLLECTIVE_MEMBERS_URL);
const payload = await response.json();
const members = payload
.filter(({ role, isActive }) => role === 'BACKER' && isActive)
.sort((a, b) => b.totalAmountDonated - a.totalAmountDonated)
.map(({ name, website, image, profile }) => ({
name,
image,
url: website,
// If profile starts with the guest- prefix, it's a non-existing account
profile: profile.startsWith('https://opencollective.com/guest-')
? undefined
: profile,
source: 'opencollective',
}));
return members;
}
export default fetchOpenCollectiveData;