Skip to content

Commit f2bf1af

Browse files
committed
refactor: split IAB sellers downloader
1 parent 2973ddc commit f2bf1af

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as Zod from 'zod'
2+
import { HTTPSRequest } from '@typescriptprime/securereq'
3+
4+
5+
const IABSellersJsonURL = 'https://info.ad-shield.io/sellers.json'
6+
7+
export async function FetchIABSellersJsonData(): Promise<string[]> {
8+
const IABSellersJsonResponse: { StatusCode: number, Headers: Record<string, string | string[]>, Body: unknown } = await HTTPSRequest(new URL(IABSellersJsonURL), { ExpectedAs: 'JSON' })
9+
let IABSellersJsonData =IABSellersJsonResponse.Body as {
10+
// eslint-disable-next-line @typescript-eslint/naming-convention
11+
sellers: Array<{
12+
// eslint-disable-next-line @typescript-eslint/naming-convention
13+
seller_id: number,
14+
// eslint-disable-next-line @typescript-eslint/naming-convention
15+
seller_type: string,
16+
// eslint-disable-next-line @typescript-eslint/naming-convention
17+
name: string,
18+
// eslint-disable-next-line @typescript-eslint/naming-convention
19+
domain: string
20+
}>
21+
}
22+
IABSellersJsonData = await Zod.object({
23+
sellers: Zod.array(Zod.object({
24+
seller_id: Zod.number(),
25+
seller_type: Zod.string(),
26+
name: Zod.string(),
27+
domain: Zod.string().refine(D => {
28+
try {
29+
new URL(`https://${D}`)
30+
} catch {
31+
return false
32+
}
33+
return true
34+
})
35+
}))
36+
}).parseAsync(IABSellersJsonData)
37+
return [...new Set(IABSellersJsonData.sellers.map(S => S.domain))]
38+
}

0 commit comments

Comments
 (0)