1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List team members |
7 | * Get a paginated list of team members for the provided team. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | teamId: string, |
12 | limit: string | undefined, |
13 | since: string | undefined, |
14 | until: string | undefined, |
15 | search: string | undefined, |
16 | role: |
17 | | "OWNER" |
18 | | "MEMBER" |
19 | | "DEVELOPER" |
20 | | "VIEWER" |
21 | | "BILLING" |
22 | | "CONTRIBUTOR" |
23 | | undefined, |
24 | excludeProject: string | undefined, |
25 | eligibleMembersForProjectId: string | undefined, |
26 | ) { |
27 | const url = new URL(`https://api.vercel.com/v2/teams/${teamId}/members`); |
28 | for (const [k, v] of [ |
29 | ["limit", limit], |
30 | ["since", since], |
31 | ["until", until], |
32 | ["search", search], |
33 | ["role", role], |
34 | ["excludeProject", excludeProject], |
35 | ["eligibleMembersForProjectId", eligibleMembersForProjectId], |
36 | ]) { |
37 | if (v !== undefined && v !== "" && k !== undefined) { |
38 | url.searchParams.append(k, v); |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "GET", |
43 | headers: { |
44 | Authorization: "Bearer " + auth.token, |
45 | }, |
46 | body: undefined, |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|