1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Publish an integration |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | integrationName: string, |
12 | body: { |
13 | runtime?: "v1" | "v2"; |
14 | icon?: string; |
15 | title: string; |
16 | description: string; |
17 | summary?: string; |
18 | previewImages?: string[]; |
19 | visibility?: "public" | "private" | "unlisted"; |
20 | target?: "all" | "site" | "space" | "organization"; |
21 | scopes: |
22 | | "space:views:read" |
23 | | "space:content:read" |
24 | | "space:content:write" |
25 | | "space:metadata:read" |
26 | | "space:metadata:write" |
27 | | "space:script:inject" |
28 | | "space:script:cookies" |
29 | | "space:git:sync" |
30 | | "space:visitor:auth" |
31 | | "site:metadata:read" |
32 | | "site:views:read" |
33 | | "site:script:inject" |
34 | | "site:script:cookies" |
35 | | "site:visitor:auth" |
36 | | "site:adaptive:read" |
37 | | "site:adaptive:write" |
38 | | "openapi:read" |
39 | | "openapi:write" |
40 | | "conversations:ingest"[]; |
41 | categories?: |
42 | | "analytics" |
43 | | "collaboration" |
44 | | "content" |
45 | | "gitsync" |
46 | | "marketing" |
47 | | "visitor-auth" |
48 | | "other"[]; |
49 | blocks?: { |
50 | id: string; |
51 | title: string; |
52 | description?: string; |
53 | icon?: string; |
54 | urlUnfurl?: string[]; |
55 | markdown?: { codeblock: string; body: string }; |
56 | }[]; |
57 | contentSources?: { |
58 | id: string; |
59 | title: string; |
60 | description?: string; |
61 | icon?: string; |
62 | configuration: { componentId: string }; |
63 | }[]; |
64 | externalLinks?: { url: string; label: string }[]; |
65 | configurations?: { |
66 | account?: |
67 | | { properties: {}; required?: string[] } |
68 | | { componentId: string }; |
69 | space?: { properties: {}; required?: string[] } | { componentId: string }; |
70 | site?: { properties: {}; required?: string[] } | { componentId: string }; |
71 | }; |
72 | script: string; |
73 | organization: string; |
74 | secrets?: {}; |
75 | contentSecurityPolicy?: |
76 | | string |
77 | | { |
78 | "base-uri"?: string; |
79 | "block-all-mixed-content"?: string; |
80 | "child-src"?: string; |
81 | "connect-src"?: string; |
82 | "default-src"?: string; |
83 | "font-src"?: string; |
84 | "form-action"?: string; |
85 | "frame-ancestors"?: string; |
86 | "frame-src"?: string; |
87 | "img-src"?: string; |
88 | "manifest-src"?: string; |
89 | "media-src"?: string; |
90 | "navigate-to"?: string; |
91 | "object-src"?: string; |
92 | "plugin-types"?: string; |
93 | "prefetch-src"?: string; |
94 | referrer?: string; |
95 | "report-to"?: string; |
96 | "report-uri"?: string; |
97 | "require-sri-for"?: string; |
98 | "require-trusted-types-for"?: string; |
99 | sandbox?: string; |
100 | "script-src"?: string; |
101 | "script-src-attr"?: string; |
102 | "script-src-elem"?: string; |
103 | "style-src"?: string; |
104 | "style-src-attr"?: string; |
105 | "style-src-elem"?: string; |
106 | "trusted-types"?: string; |
107 | "upgrade-insecure-requests"?: string; |
108 | "worker-src"?: string; |
109 | }; |
110 | }, |
111 | ) { |
112 | const url = new URL(`https://api.gitbook.com/v1/integrations/${integrationName}`); |
113 |
|
114 | const response = await fetch(url, { |
115 | method: "POST", |
116 | headers: { |
117 | "Content-Type": "application/json", |
118 | Authorization: "Bearer " + auth.token, |
119 | }, |
120 | body: JSON.stringify(body), |
121 | }); |
122 | if (!response.ok) { |
123 | const text = await response.text(); |
124 | throw new Error(`${response.status} ${text}`); |
125 | } |
126 | return await response.json(); |
127 | } |
128 |
|