import { Platform } from 'react-native' import { NitroModules } from 'react-native-nitro-modules' import type { NitroChucker } from './specs/NitroChucker.nitro' export type { NitroChucker } from './specs/NitroChucker.nitro' const SUPPORTED = Platform.OS === 'android' || Platform.OS === 'ios' let cached: NitroChucker | null = null /** Returns the native hybrid, or null if unsupported / not linked. Never throws. */ function getHybrid(): NitroChucker | null { if (!SUPPORTED) return null if (cached) return cached try { cached = NitroModules.createHybridObject('NitroChucker') return cached } catch { return null } } /** Whether on-device inspection is available on this platform. Never throws. */ export function isSupported(): boolean { return getHybrid()?.isSupported ?? false } /** Open the on-device inspector UI. No-op when unsupported. */ export function show(): void { getHybrid()?.show() } /** Wipe captured transactions (best-effort). No-op when unsupported. */ export function clearLogs(): void { getHybrid()?.clearLogs() } /** Best-effort close of the inspector UI. No-op when unsupported. */ export function dismiss(): void { getHybrid()?.dismiss() } /** Pause/resume capture at runtime. No-op when unsupported. */ export function setEnabled(enabled: boolean): void { getHybrid()?.setEnabled(enabled) } /** * Cap how many transactions are retained; the oldest are evicted as new ones arrive. * Pass 0 for unlimited. iOS defaults to 200 — see README for why this matters there. * No-op when unsupported. */ export function setMaxLogCount(maxCount: number): void { getHybrid()?.setMaxLogCount(maxCount) } /** * Skip capture for these hosts so their payloads are never retained — the most * effective guard against large media/CDN responses. No-op when unsupported. */ export function setIgnoredHosts(hosts: string[]): void { getHybrid()?.setIgnoredHosts(hosts) }