1 | |
2 | type Figma = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get activity logs |
7 | * Returns a list of activity log events |
8 | */ |
9 | export async function main( |
10 | auth: Figma, |
11 | events: string | undefined, |
12 | start_time: string | undefined, |
13 | end_time: string | undefined, |
14 | limit: string | undefined, |
15 | order: "asc" | "desc" | undefined, |
16 | ) { |
17 | const url = new URL(`https://api.figma.com/v1/activity_logs`); |
18 | for (const [k, v] of [ |
19 | ["events", events], |
20 | ["start_time", start_time], |
21 | ["end_time", end_time], |
22 | ["limit", limit], |
23 | ["order", order], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "GET", |
31 | headers: { |
32 | Authorization: "Bearer " + auth.token, |
33 | }, |
34 | body: undefined, |
35 | }); |
36 | if (!response.ok) { |
37 | const text = await response.text(); |
38 | throw new Error(`${response.status} ${text}`); |
39 | } |
40 | return await response.json(); |
41 | } |
42 |
|