1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List all the site spaces |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | siteId: string, |
13 | shareKey: string | undefined, |
14 | page: string | undefined, |
15 | limit: string | undefined, |
16 | _default: string | undefined, |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/site-spaces`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["shareKey", shareKey], |
23 | ["page", page], |
24 | ["limit", limit], |
25 | ["default", _default], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Bearer " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|