(params: {
ip: string
token: string
fetch: typeof globalThis.fetch
})
| 381 | } |
| 382 | |
| 383 | export async function lookupIpinfoPrivacy(params: { |
| 384 | ip: string |
| 385 | token: string |
| 386 | fetch: typeof globalThis.fetch |
| 387 | }): Promise<FreeModeIpPrivacy | null> { |
| 388 | const cached = ipinfoPrivacyCache.get(params.ip) |
| 389 | if (cached && cached.expiresAt > Date.now()) { |
| 390 | return cached.privacy |
| 391 | } |
| 392 | |
| 393 | const response = await params.fetch( |
| 394 | `https://api.ipinfo.io/lookup/${encodeURIComponent(params.ip)}?token=${encodeURIComponent(params.token)}`, |
| 395 | ) |
| 396 | if (!response.ok) { |
| 397 | return null |
| 398 | } |
| 399 | |
| 400 | const data = (await response.json()) as Record<string, unknown> |
| 401 | const signals = privacySignalsFromIpinfo(data) |
| 402 | const privacy = { |
| 403 | signals, |
| 404 | } |
| 405 | setIpinfoPrivacyCache(params.ip, privacy) |
| 406 | return privacy |
| 407 | } |
| 408 | |
| 409 | export async function lookupSpurIpPrivacy(params: { |
| 410 | ip: string |
no test coverage detected