1 | |
2 | type Render = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List projects |
7 | * List projects matching the provided filters. If no filters are provided, all projects are returned. |
8 |
|
9 | */ |
10 | export async function main( |
11 | auth: Render, |
12 | name: string | undefined, |
13 | createdBefore: string | undefined, |
14 | createdAfter: string | undefined, |
15 | updatedBefore: string | undefined, |
16 | updatedAfter: string | undefined, |
17 | ownerId: string | undefined, |
18 | cursor: string | undefined, |
19 | limit: string | undefined |
20 | ) { |
21 | const url = new URL(`https://api.render.com/v1/projects`) |
22 | for (const [k, v] of [ |
23 | ['name', name], |
24 | ['createdBefore', createdBefore], |
25 | ['createdAfter', createdAfter], |
26 | ['updatedBefore', updatedBefore], |
27 | ['updatedAfter', updatedAfter], |
28 | ['ownerId', ownerId], |
29 | ['cursor', cursor], |
30 | ['limit', limit] |
31 | ]) { |
32 | if (v !== undefined && v !== '' && k !== undefined) { |
33 | url.searchParams.append(k, v) |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: 'GET', |
38 | headers: { |
39 | Authorization: 'Bearer ' + auth.apiKey |
40 | }, |
41 | body: undefined |
42 | }) |
43 | if (!response.ok) { |
44 | const text = await response.text() |
45 | throw new Error(`${response.status} ${text}`) |
46 | } |
47 | return await response.json() |
48 | } |
49 |
|