1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update Edge Config items in batch |
7 | * Update multiple Edge Config Items in batch. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | edgeConfigId: string, |
12 | dryRun: string | undefined, |
13 | teamId: string | undefined, |
14 | slug: string | undefined, |
15 | body: { |
16 | items: |
17 | | { operation: "create" } |
18 | | { operation: "update" | "upsert" } |
19 | | { operation: "update" | "upsert" } |
20 | | { operation: "delete" }[]; |
21 | definition: unknown; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://api.vercel.com/v1/edge-config/${edgeConfigId}/items`, |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["dryRun", dryRun], |
29 | ["teamId", teamId], |
30 | ["slug", slug], |
31 | ]) { |
32 | if (v !== undefined && v !== "" && k !== undefined) { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "PATCH", |
38 | headers: { |
39 | "Content-Type": "application/json", |
40 | Authorization: "Bearer " + auth.token, |
41 | }, |
42 | body: JSON.stringify(body), |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|