1 | |
2 | type Netlify = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create site dev server hook |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Netlify, |
11 | site_id: string, |
12 | body: { |
13 | title?: string; |
14 | branch?: string; |
15 | type?: "new_dev_server" | "content_refresh"; |
16 | }, |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.netlify.com/api/v1/sites/${site_id}/dev_server_hooks`, |
20 | ); |
21 |
|
22 | const response = await fetch(url, { |
23 | method: "POST", |
24 | headers: { |
25 | "Content-Type": "application/json", |
26 | Authorization: "Bearer " + auth.token, |
27 | }, |
28 | body: JSON.stringify(body), |
29 | }); |
30 | if (!response.ok) { |
31 | const text = await response.text(); |
32 | throw new Error(`${response.status} ${text}`); |
33 | } |
34 | return await response.json(); |
35 | } |
36 |
|