(params: {
ip: string
token: string
fetch: typeof globalThis.fetch
})
| 407 | } |
| 408 | |
| 409 | export async function lookupSpurIpPrivacy(params: { |
| 410 | ip: string |
| 411 | token: string |
| 412 | fetch: typeof globalThis.fetch |
| 413 | }): Promise<FreeModeIpPrivacy | null> { |
| 414 | const cached = spurPrivacyCache.get(params.ip) |
| 415 | if (cached && cached.expiresAt > Date.now()) { |
| 416 | return cached.privacy |
| 417 | } |
| 418 | |
| 419 | const response = await params.fetch( |
| 420 | `https://api.spur.us/v2/context/${encodeURIComponent(params.ip)}`, |
| 421 | { |
| 422 | headers: { |
| 423 | Token: params.token, |
| 424 | }, |
| 425 | }, |
| 426 | ) |
| 427 | if (!response.ok) { |
| 428 | return null |
| 429 | } |
| 430 | |
| 431 | const data = (await response.json()) as Record<string, unknown> |
| 432 | const privacy = { |
| 433 | signals: privacySignalsFromSpur(data), |
| 434 | } |
| 435 | setSpurPrivacyCache(params.ip, privacy) |
| 436 | return privacy |
| 437 | } |
| 438 | |
| 439 | async function lookupSpurPrivacyStatus( |
| 440 | clientIp: string, |
no test coverage detected