1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Retrieve a list of projects |
7 | * Allows to retrieve the list of projects of the authenticated user or team. The list will be paginated and the provided query parameters allow filtering the returned projects. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | from: string | undefined, |
12 | gitForkProtection: "1" | "0" | undefined, |
13 | limit: string | undefined, |
14 | search: string | undefined, |
15 | repo: string | undefined, |
16 | repoId: string | undefined, |
17 | repoUrl: string | undefined, |
18 | excludeRepos: string | undefined, |
19 | edgeConfigId: string | undefined, |
20 | edgeConfigTokenId: string | undefined, |
21 | deprecated: string | undefined, |
22 | teamId: string | undefined, |
23 | slug: string | undefined, |
24 | ) { |
25 | const url = new URL(`https://api.vercel.com/v10/projects`); |
26 | for (const [k, v] of [ |
27 | ["from", from], |
28 | ["gitForkProtection", gitForkProtection], |
29 | ["limit", limit], |
30 | ["search", search], |
31 | ["repo", repo], |
32 | ["repoId", repoId], |
33 | ["repoUrl", repoUrl], |
34 | ["excludeRepos", excludeRepos], |
35 | ["edgeConfigId", edgeConfigId], |
36 | ["edgeConfigTokenId", edgeConfigTokenId], |
37 | ["deprecated", deprecated], |
38 | ["teamId", teamId], |
39 | ["slug", slug], |
40 | ]) { |
41 | if (v !== undefined && v !== "" && k !== undefined) { |
42 | url.searchParams.append(k, v); |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: "GET", |
47 | headers: { |
48 | Authorization: "Bearer " + auth.token, |
49 | }, |
50 | body: undefined, |
51 | }); |
52 | if (!response.ok) { |
53 | const text = await response.text(); |
54 | throw new Error(`${response.status} ${text}`); |
55 | } |
56 | return await response.json(); |
57 | } |
58 |
|