1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | filter: string | undefined, |
9 | subtenantId: string | undefined, |
10 | groupId: string | undefined, |
11 | tagIds: string | undefined, |
12 | topicIds: string | undefined, |
13 | channels: string | undefined, |
14 | postStatus: |
15 | | 'ALL' |
16 | | 'DRAFT' |
17 | | 'PLANNED' |
18 | | 'PUBLISHED' |
19 | | 'IN_REVIEW' |
20 | | 'MANUALLY_ACTIVATING' |
21 | | 'TRANSLATION_IN_PROGRESS' |
22 | | 'TRANSLATION_COMPLETED' |
23 | | 'NON_PUBLISHED' |
24 | | undefined, |
25 | Origin: string |
26 | ) { |
27 | const url = new URL(`https://app.adhook.io/v1/posts/count`) |
28 |
|
29 | for (const [k, v] of [ |
30 | ['filter', filter], |
31 | ['subtenantId', subtenantId], |
32 | ['groupId', groupId], |
33 | ['tagIds', tagIds], |
34 | ['topicIds', topicIds], |
35 | ['channels', channels], |
36 | ['postStatus', postStatus] |
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 | Authorization: `Bearer ${auth.token}`, |
47 | Origin: Origin |
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 |
|