1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Board |
7 | * Create a new board. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | name: string | undefined, |
12 | defaultLabels: string | undefined, |
13 | defaultLists: string | undefined, |
14 | desc: string | undefined, |
15 | idOrganization: string | undefined, |
16 | idBoardSource: string | undefined, |
17 | keepFromSource: "cards" | "none" | undefined, |
18 | powerUps: "all" | "calendar" | "cardAging" | "recap" | "voting" | undefined, |
19 | prefs_permissionLevel: "org" | "private" | "public" | undefined, |
20 | prefs_voting: |
21 | | "disabled" |
22 | | "members" |
23 | | "observers" |
24 | | "org" |
25 | | "public" |
26 | | undefined, |
27 | prefs_comments: |
28 | | "disabled" |
29 | | "members" |
30 | | "observers" |
31 | | "org" |
32 | | "public" |
33 | | undefined, |
34 | prefs_invitations: "members" | "admins" | undefined, |
35 | prefs_selfJoin: string | undefined, |
36 | prefs_cardCovers: string | undefined, |
37 | prefs_background: |
38 | | "blue" |
39 | | "orange" |
40 | | "green" |
41 | | "red" |
42 | | "purple" |
43 | | "pink" |
44 | | "lime" |
45 | | "sky" |
46 | | "grey" |
47 | | undefined, |
48 | prefs_cardAging: "pirate" | "regular" | undefined |
49 | ) { |
50 | const url = new URL(`https://api.trello.com/1/boards/`); |
51 | for (const [k, v] of [ |
52 | ["name", name], |
53 | ["defaultLabels", defaultLabels], |
54 | ["defaultLists", defaultLists], |
55 | ["desc", desc], |
56 | ["idOrganization", idOrganization], |
57 | ["idBoardSource", idBoardSource], |
58 | ["keepFromSource", keepFromSource], |
59 | ["powerUps", powerUps], |
60 | ["prefs_permissionLevel", prefs_permissionLevel], |
61 | ["prefs_voting", prefs_voting], |
62 | ["prefs_comments", prefs_comments], |
63 | ["prefs_invitations", prefs_invitations], |
64 | ["prefs_selfJoin", prefs_selfJoin], |
65 | ["prefs_cardCovers", prefs_cardCovers], |
66 | ["prefs_background", prefs_background], |
67 | ["prefs_cardAging", prefs_cardAging], |
68 | ["key", auth.key], |
69 | ["token", auth.token], |
70 | ]) { |
71 | if (v !== undefined && v !== "") { |
72 | url.searchParams.append(k, v); |
73 | } |
74 | } |
75 | const response = await fetch(url, { |
76 | method: "POST", |
77 | headers: { |
78 | Authorization: undefined, |
79 | }, |
80 | body: undefined, |
81 | }); |
82 | if (!response.ok) { |
83 | const text = await response.text(); |
84 | throw new Error(`${response.status} ${text}`); |
85 | } |
86 | return await response.text(); |
87 | } |
88 |
|