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