1 |
|
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Actimo, |
8 | id: string, |
9 | limit: string | undefined, |
10 | page: string | undefined, |
11 | order: string | undefined, |
12 | search: string | undefined |
13 | ) { |
14 | const url = new URL(`https://actimo.com/api/v1/messages/${id}/access`) |
15 | for (const [k, v] of [ |
16 | ['limit', limit], |
17 | ['page', page], |
18 | ['order', order], |
19 | ['search', search] |
20 | ]) { |
21 | if (v !== undefined && v !== '' && k !== undefined) { |
22 | url.searchParams.append(k, v) |
23 | } |
24 | } |
25 |
|
26 | const response = await fetch(url, { |
27 | method: 'GET', |
28 | headers: { |
29 | 'api-key': auth.apiKey |
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 |
|