1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get a space computed revision |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | spaceId: string, |
12 | body: { |
13 | source: |
14 | | ({ |
15 | type: "builtin:openapi"; |
16 | dependencies: { |
17 | spec: |
18 | | { ref: { kind: "openapi"; spec: string } } |
19 | | { |
20 | ref: { kind: "openapi"; spec: string }; |
21 | value: { |
22 | object: "openapi-spec"; |
23 | id: string; |
24 | slug: string; |
25 | lastVersion?: string; |
26 | }; |
27 | }; |
28 | }; |
29 | } & { props: { models: false | true } }) |
30 | | { |
31 | type: "builtin:translation"; |
32 | props: {}; |
33 | dependencies: { |
34 | translation: |
35 | | { ref: { kind: "translation"; translation: string } } |
36 | | { |
37 | ref: { kind: "translation"; translation: string }; |
38 | value: { space: string; revision: string }; |
39 | }; |
40 | }; |
41 | } |
42 | | { type: string; props: {}; dependencies?: {} }; |
43 | seed: string; |
44 | }, |
45 | ) { |
46 | const url = new URL(`https://api.gitbook.com/v1/spaces/${spaceId}/content/computed/revision`); |
47 |
|
48 | const response = await fetch(url, { |
49 | method: "POST", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Bearer " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|