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