/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
apps/analytics/src/utils/consent-check.ts
27 строк
1 KB
Steve Ruiz
Analytics: use consent worker on tldraw.com (#6973)
21 окт 2025, 17:31
Не верифицирован
21 окт 2025, 17:31
03d244d
Код
Авторство
О чём код?
type ConsentCheckResult = 'requires-consent' | 'no-consent-needed' /** * Checks if consent is required based on CloudFlare geolocation headers * * @returns Promise<'requires-consent' | 'no-consent-needed'> - 'requires-consent' if explicit consent is required, 'no-consent-needed' if confident it's not */ export async function shouldRequireConsent(): Promise<ConsentCheckResult> { // CloudFlare provides the CF-IPCountry header on all requests // Our consent worker checks this and returns whether consent is required try { const response = await fetch('https://consent.tldraw.xyz') if (response.ok) { const data = await response.json() // Worker returns { requires_consent: boolean, country_code: string } if (typeof data.requires_consent === 'boolean') { return data.requires_consent ? 'requires-consent' : 'no-consent-needed' } } } catch (error) { // Fetch failed or timed out - will default to requiring consent console.warn('Consent check failed, defaulting to requiring consent:', error) } // Conservative default: require consent return 'requires-consent' }