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