1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Search Trello |
7 | * Find what you're looking for in Trello |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | query: string | undefined, |
12 | idBoards: string | undefined, |
13 | idOrganizations: string | undefined, |
14 | idCards: string | undefined, |
15 | modelTypes: string | undefined, |
16 | board_fields: string | undefined, |
17 | boards_limit: string | undefined, |
18 | board_organization: string | undefined, |
19 | card_fields: string | undefined, |
20 | cards_limit: string | undefined, |
21 | cards_page: string | undefined, |
22 | card_board: string | undefined, |
23 | card_list: string | undefined, |
24 | card_members: string | undefined, |
25 | card_stickers: string | undefined, |
26 | card_attachments: string | undefined, |
27 | organization_fields: string | undefined, |
28 | organizations_limit: string | undefined, |
29 | member_fields: string | undefined, |
30 | members_limit: string | undefined, |
31 | partial: string | undefined |
32 | ) { |
33 | const url = new URL(`https://api.trello.com/1/search`); |
34 | for (const [k, v] of [ |
35 | ["query", query], |
36 | ["idBoards", idBoards], |
37 | ["idOrganizations", idOrganizations], |
38 | ["idCards", idCards], |
39 | ["modelTypes", modelTypes], |
40 | ["board_fields", board_fields], |
41 | ["boards_limit", boards_limit], |
42 | ["board_organization", board_organization], |
43 | ["card_fields", card_fields], |
44 | ["cards_limit", cards_limit], |
45 | ["cards_page", cards_page], |
46 | ["card_board", card_board], |
47 | ["card_list", card_list], |
48 | ["card_members", card_members], |
49 | ["card_stickers", card_stickers], |
50 | ["card_attachments", card_attachments], |
51 | ["organization_fields", organization_fields], |
52 | ["organizations_limit", organizations_limit], |
53 | ["member_fields", member_fields], |
54 | ["members_limit", members_limit], |
55 | ["partial", partial], |
56 | ["key", auth.key], |
57 | ["token", auth.token], |
58 | ]) { |
59 | if (v !== undefined && v !== "") { |
60 | url.searchParams.append(k, v); |
61 | } |
62 | } |
63 | const response = await fetch(url, { |
64 | method: "GET", |
65 | headers: { |
66 | Authorization: undefined, |
67 | }, |
68 | body: undefined, |
69 | }); |
70 | if (!response.ok) { |
71 | const text = await response.text(); |
72 | throw new Error(`${response.status} ${text}`); |
73 | } |
74 | return await response.json(); |
75 | } |
76 |
|