1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | q: string | undefined, |
9 | skip: string | undefined, |
10 | limit: string | undefined, |
11 | adhookToken: string |
12 | ) { |
13 | const url = new URL(`https://app.adhook.io/v1/subtenants/read`) |
14 |
|
15 | for (const [k, v] of [ |
16 | ['q', q], |
17 | ['skip', skip], |
18 | ['limit', limit] |
19 | ]) { |
20 | if (v !== undefined && v !== '' && k !== undefined) { |
21 | url.searchParams.append(k, v) |
22 | } |
23 | } |
24 |
|
25 | const response = await fetch(url, { |
26 | method: 'GET', |
27 | headers: { |
28 | adhookToken: adhookToken, |
29 | Authorization: `Bearer ${auth.token}` |
30 | }, |
31 | body: undefined |
32 | }) |
33 |
|
34 | if (!response.ok) { |
35 | const text = await response.text() |
36 | throw new Error(`${response.status} ${text}`) |
37 | } |
38 |
|
39 | return await response.json() |
40 | } |
41 |
|