1 | |
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | mode: |
9 | | 'CAMPAIGN' |
10 | | 'POST' |
11 | | 'CAMPAIGN_GENERATION' |
12 | | 'POST_GENERATION' |
13 | | 'POST_TEMPLATE' |
14 | | 'AD_TEMPLATE' |
15 | | 'MANAGE' |
16 | | 'REVIEW' |
17 | | 'MODERATION' |
18 | | 'DEFAULT' |
19 | | undefined, |
20 | q: string | undefined, |
21 | skip: string | undefined, |
22 | limit: string | undefined, |
23 | adhookToken: string, |
24 | Origin: string |
25 | ) { |
26 | const url = new URL(`https://app.adhook.io/v1/subtenants/read/browse`) |
27 |
|
28 | for (const [k, v] of [ |
29 | ['mode', mode], |
30 | ['q', q], |
31 | ['skip', skip], |
32 | ['limit', limit] |
33 | ]) { |
34 | if (v !== undefined && v !== '' && k !== undefined) { |
35 | url.searchParams.append(k, v) |
36 | } |
37 | } |
38 |
|
39 | const response = await fetch(url, { |
40 | method: 'GET', |
41 | headers: { |
42 | adhookToken: adhookToken, |
43 | Authorization: `Bearer ${auth.token}`, |
44 | Origin: Origin |
45 | }, |
46 | body: undefined |
47 | }) |
48 |
|
49 | if (!response.ok) { |
50 | const text = await response.text() |
51 | throw new Error(`${response.status} ${text}`) |
52 | } |
53 |
|
54 | return await response.json() |
55 | } |
56 |
|