1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | promotionStatus: |
9 | | 'ALL' |
10 | | 'DRAFT' |
11 | | 'PLANNED' |
12 | | 'IN_PROGRESS' |
13 | | 'STOPPED' |
14 | | 'IN_REVIEW' |
15 | | 'COMPLETED' |
16 | | undefined, |
17 | start: string | undefined, |
18 | end: string | undefined, |
19 | subtenantId: string | undefined, |
20 | groupId: string | undefined, |
21 | tagIds: string | undefined, |
22 | topicIds: string | undefined, |
23 | channels: string | undefined, |
24 | adhookToken: string |
25 | ) { |
26 | const url = new URL(`https://app.adhook.io/v1/promotions/calendar`) |
27 |
|
28 | for (const [k, v] of [ |
29 | ['promotionStatus', promotionStatus], |
30 | ['start', start], |
31 | ['end', end], |
32 | ['subtenantId', subtenantId], |
33 | ['groupId', groupId], |
34 | ['tagIds', tagIds], |
35 | ['topicIds', topicIds], |
36 | ['channels', channels] |
37 | ]) { |
38 | if (v !== undefined && v !== '' && k !== undefined) { |
39 | url.searchParams.append(k, v) |
40 | } |
41 | } |
42 |
|
43 | const response = await fetch(url, { |
44 | method: 'GET', |
45 | headers: { |
46 | adhookToken: adhookToken, |
47 | Authorization: `Bearer ${auth.token}` |
48 | }, |
49 | body: undefined |
50 | }) |
51 |
|
52 | if (!response.ok) { |
53 | const text = await response.text() |
54 | throw new Error(`${response.status} ${text}`) |
55 | } |
56 |
|
57 | return await response.json() |
58 | } |
59 |
|