1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Get a Member |
7 | * Get a member |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | actions: string | undefined, |
13 | boards: string | undefined, |
14 | boardBackgrounds: |
15 | | "all" |
16 | | "custom" |
17 | | "default" |
18 | | "none" |
19 | | "premium" |
20 | | undefined, |
21 | boardsInvited: |
22 | | "closed" |
23 | | "members" |
24 | | "open" |
25 | | "organization" |
26 | | "pinned" |
27 | | "public" |
28 | | "starred" |
29 | | "unpinned" |
30 | | undefined, |
31 | boardsInvited_fields: |
32 | | "id" |
33 | | "name" |
34 | | "desc" |
35 | | "descData" |
36 | | "closed" |
37 | | "idMemberCreator" |
38 | | "idOrganization" |
39 | | "pinned" |
40 | | "url" |
41 | | "shortUrl" |
42 | | "prefs" |
43 | | "labelNames" |
44 | | "starred" |
45 | | "limits" |
46 | | "memberships" |
47 | | "enterpriseOwned" |
48 | | undefined, |
49 | boardStars: string | undefined, |
50 | cards: string | undefined, |
51 | customBoardBackgrounds: "all" | "none" | undefined, |
52 | customEmoji: "all" | "none" | undefined, |
53 | customStickers: "all" | "none" | undefined, |
54 | fields: "id" | undefined, |
55 | notifications: string | undefined, |
56 | organizations: "all" | "members" | "none" | "public" | undefined, |
57 | organization_fields: "id" | "name" | undefined, |
58 | organization_paid_account: string | undefined, |
59 | organizationsInvited: "all" | "members" | "none" | "public" | undefined, |
60 | organizationsInvited_fields: "id" | "name" | undefined, |
61 | paid_account: string | undefined, |
62 | savedSearches: string | undefined, |
63 | tokens: "all" | "none" | undefined |
64 | ) { |
65 | const url = new URL(`https://api.trello.com/1/members/${id}`); |
66 | for (const [k, v] of [ |
67 | ["actions", actions], |
68 | ["boards", boards], |
69 | ["boardBackgrounds", boardBackgrounds], |
70 | ["boardsInvited", boardsInvited], |
71 | ["boardsInvited_fields", boardsInvited_fields], |
72 | ["boardStars", boardStars], |
73 | ["cards", cards], |
74 | ["customBoardBackgrounds", customBoardBackgrounds], |
75 | ["customEmoji", customEmoji], |
76 | ["customStickers", customStickers], |
77 | ["fields", fields], |
78 | ["notifications", notifications], |
79 | ["organizations", organizations], |
80 | ["organization_fields", organization_fields], |
81 | ["organization_paid_account", organization_paid_account], |
82 | ["organizationsInvited", organizationsInvited], |
83 | ["organizationsInvited_fields", organizationsInvited_fields], |
84 | ["paid_account", paid_account], |
85 | ["savedSearches", savedSearches], |
86 | ["tokens", tokens], |
87 | ["key", auth.key], |
88 | ["token", auth.token], |
89 | ]) { |
90 | if (v !== undefined && v !== "") { |
91 | url.searchParams.append(k, v); |
92 | } |
93 | } |
94 | const response = await fetch(url, { |
95 | method: "GET", |
96 | headers: { |
97 | Authorization: undefined, |
98 | }, |
99 | body: undefined, |
100 | }); |
101 | if (!response.ok) { |
102 | const text = await response.text(); |
103 | throw new Error(`${response.status} ${text}`); |
104 | } |
105 | return await response.json(); |
106 | } |
107 |
|