1 | |
2 | type Netlify = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update site snippet |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Netlify, |
11 | site_id: string, |
12 | snippet_id: string, |
13 | body: { |
14 | id?: number; |
15 | site_id?: string; |
16 | title?: string; |
17 | general?: string; |
18 | general_position?: string; |
19 | goal?: string; |
20 | goal_position?: string; |
21 | }, |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.netlify.com/api/v1/sites/${site_id}/snippets/${snippet_id}`, |
25 | ); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "PUT", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Bearer " + auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|