import { NativeModules } from 'react-native'; export function resolveAppId(explicit: string | undefined, nativeApplicationId: string | undefined): string | null { const value = explicit ?? nativeApplicationId; return typeof value === 'string' && /^[A-Za-z0-9._-]{1,128}$/.test(value) ? value : null; } interface DebugToolkitDevConnectNativeModule { isDebugBuild?: () => Promise; getLocalIp?: () => Promise; getPreference?: (key: string) => Promise; getAppInfo?: () => Promise; } export interface NativeAppInfo { nativeApplicationId?: string; manufacturer?: string; model?: string; osVersion?: string; appVersion?: string; buildNumber?: string; } function getNativeModule(): DebugToolkitDevConnectNativeModule | null { const nativeModule = NativeModules.DebugToolkitDevConnect as Partial | undefined; if (nativeModule) { return nativeModule as DebugToolkitDevConnectNativeModule; } return null; } export function isNativeDevConnectAvailable(): boolean { return getNativeModule() !== null; } export async function nativeIsDebugBuild(): Promise { const nativeModule = getNativeModule(); if (!nativeModule?.isDebugBuild) { return null; } try { const result = await nativeModule.isDebugBuild(); return typeof result === 'boolean' ? result : null; } catch { return null; } } export async function getDeviceLocalIp(): Promise { const nativeModule = getNativeModule(); if (!nativeModule?.getLocalIp) { return null; } try { const ip = await nativeModule.getLocalIp(); return typeof ip === 'string' ? ip : null; } catch { return null; } } export async function getNativeAppInfo(): Promise { const nativeModule = getNativeModule(); if (!nativeModule?.getAppInfo) return null; try { const info = await nativeModule.getAppInfo(); return info && typeof info === 'object' ? info : null; } catch { return null; } }