1 | |
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Actimo, |
8 | type: string, |
9 | page: string | undefined, |
10 | pageSize: string | undefined, |
11 | search: string | undefined, |
12 | order: string | undefined, |
13 | stats: string | undefined, |
14 | selectedType: string | undefined, |
15 | tags: string | undefined, |
16 | path: string | undefined |
17 | ) { |
18 | const url = new URL(`https://actimo.com/api/v1/folder/${type}`) |
19 |
|
20 | for (const [k, v] of [ |
21 | ['page', page], |
22 | ['pageSize', pageSize], |
23 | ['search', search], |
24 | ['order', order], |
25 | ['stats', stats], |
26 | ['selectedType', selectedType], |
27 | ['tags', tags], |
28 | ['path', path] |
29 | ]) { |
30 | if (v !== undefined && v !== '' && k !== undefined) { |
31 | url.searchParams.append(k, v) |
32 | } |
33 | } |
34 |
|
35 | const response = await fetch(url, { |
36 | method: 'GET', |
37 | headers: { |
38 | 'api-key': auth.apiKey |
39 | }, |
40 | body: undefined |
41 | }) |
42 |
|
43 | if (!response.ok) { |
44 | const text = await response.text() |
45 | throw new Error(`${response.status} ${text}`) |
46 | } |
47 |
|
48 | return await response.json() |
49 | } |
50 |
|