1 | |
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main(auth: Adhook, id: string, deleteInPlatform: string | undefined) { |
7 | const url = new URL(`https://app.adhook.io/v1/promotions/${id}`) |
8 |
|
9 | for (const [k, v] of [['deleteInPlatform', deleteInPlatform]]) { |
10 | if (v !== undefined && v !== '' && k !== undefined) { |
11 | url.searchParams.append(k, v) |
12 | } |
13 | } |
14 |
|
15 | const response = await fetch(url, { |
16 | method: 'DELETE', |
17 | headers: { |
18 | Authorization: `Bearer ${auth.token}` |
19 | }, |
20 | body: undefined |
21 | }) |
22 |
|
23 | if (!response.ok) { |
24 | const text = await response.text() |
25 | throw new Error(`${response.status} ${text}`) |
26 | } |
27 |
|
28 | return await response.text() |
29 | } |
30 |
|