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