1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update showSidebar Pref on a Board |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | value: string | undefined |
13 | ) { |
14 | const url = new URL( |
15 | `https://api.trello.com/1/boards/${id}/myPrefs/showSidebar` |
16 | ); |
17 | for (const [k, v] of [ |
18 | ["value", value], |
19 | ["key", auth.key], |
20 | ["token", auth.token], |
21 | ]) { |
22 | if (v !== undefined && v !== "") { |
23 | url.searchParams.append(k, v); |
24 | } |
25 | } |
26 | const response = await fetch(url, { |
27 | method: "PUT", |
28 | headers: { |
29 | Authorization: undefined, |
30 | }, |
31 | body: undefined, |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.text(); |
38 | } |
39 |
|