1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Search for Members |
7 | * Search for Trello members. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | query: string | undefined, |
12 | limit: string | undefined, |
13 | idBoard: string | undefined, |
14 | idOrganization: string | undefined, |
15 | onlyOrgMembers: string | undefined |
16 | ) { |
17 | const url = new URL(`https://api.trello.com/1/search/members/`); |
18 | for (const [k, v] of [ |
19 | ["query", query], |
20 | ["limit", limit], |
21 | ["idBoard", idBoard], |
22 | ["idOrganization", idOrganization], |
23 | ["onlyOrgMembers", onlyOrgMembers], |
24 | ["key", auth.key], |
25 | ["token", auth.token], |
26 | ]) { |
27 | if (v !== undefined && v !== "") { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: undefined, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|