1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Invite to a collection |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | collectionId: string, |
12 | body: |
13 | | ({ teams: string[] } & { |
14 | role: "admin" | "create" | "edit" | "review" | "comment" | "read"; |
15 | }) |
16 | | ({ users: string[] } & { |
17 | role: "admin" | "create" | "edit" | "review" | "comment" | "read"; |
18 | }), |
19 | ) { |
20 | const url = new URL(`https://api.gitbook.com/v1/collections/${collectionId}/permissions`); |
21 |
|
22 | const response = await fetch(url, { |
23 | method: "POST", |
24 | headers: { |
25 | "Content-Type": "application/json", |
26 | Authorization: "Bearer " + auth.token, |
27 | }, |
28 | body: JSON.stringify(body), |
29 | }); |
30 | if (!response.ok) { |
31 | const text = await response.text(); |
32 | throw new Error(`${response.status} ${text}`); |
33 | } |
34 | return await response.text(); |
35 | } |
36 |
|