1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get a change request page by its path |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | spaceId: string, |
12 | changeRequestId: string, |
13 | pagePath: string, |
14 | format: "document" | "markdown" | undefined, |
15 | evaluated: string | undefined, |
16 | metadata: string | undefined, |
17 | computed: string | undefined, |
18 | ) { |
19 | const url = new URL( |
20 | `https://api.gitbook.com/v1/spaces/${spaceId}/change-requests/${changeRequestId}/content/path/${pagePath}`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["format", format], |
24 | ["evaluated", evaluated], |
25 | ["metadata", metadata], |
26 | ["computed", computed], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "GET", |
34 | headers: { |
35 | Authorization: "Bearer " + auth.token, |
36 | }, |
37 | body: undefined, |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|