import { NativeModules, Platform } from 'react-native'; import { BureauModule } from 'bureau-core'; const LINKING_ERROR = `The package 'bureau-device-intelligence' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const FraudNativeModule = NativeModules.FraudNativeModule ? NativeModules.FraudNativeModule : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, } ); // Type definitions export type MetaInfo = Record; export interface BureauConfig { credentialId: string; env: Environment; enableSmartInsightFetch?: boolean; enableBehavioralBiometrics?: boolean; } export enum Environment { PRODUCTION, SANDBOX, } export interface GPSLocation { city?: string; country?: string; latitude?: number; longitude?: number; region?: string; } export interface IPLocation { city?: string; country?: string; latitude?: number; longitude?: number; region?: string; } export interface IPSecurity { vpn?: boolean; isCrawler?: boolean; isProxy?: boolean; isTor?: boolean; threatLevel?: string; } export interface NetworkInformation { ipType?: string; isp?: string; } export interface BaseInsights { gpsLocation?: GPSLocation; ip?: string; ipLocation?: IPLocation; ipSecurity?: IPSecurity; ipType?: string; os?: string; accessibilityEnabled?: boolean; behaviouralRiskLevel?: string; confidenceScore?: number; createdAt?: number; debuggable?: boolean; developerMode?: boolean; deviceRiskLevel?: string; deviceRiskScore?: number; deviceTrustScore?: number; emulator?: boolean; factoryResetRisk?: string; factoryResetTime?: number; fingerprint?: string; firstSeenDays?: number; merchantId?: string; mitmAttackDetected?: boolean; mockgps?: boolean; model?: string; networkInformation?: NetworkInformation; package?: string; remoteDesktop?: boolean; requestId?: string; riskCauses?: string[]; riskLevel?: string; riskScore?: number; sessionId?: string; timestamp?: number; userId?: string; voiceCallDetected?: boolean; jailbreak?: boolean; appStoreInstall?: boolean; fridaDetected?: boolean; } export interface AndroidInsights extends BaseInsights { adbConnected?: boolean; adbEnabled?: boolean; appInstallerSource?: string; googlePlayStoreInstall?: boolean; isAppCloned?: boolean; isAppTampered?: boolean; isDebuggingEnabled?: boolean; isHookingDetected?: boolean; isOEMUnlockAllowed?: boolean; isSimPresent?: boolean; requestTimestamp?: number; rooted?: boolean; screenSharing?: boolean; } export interface IOSInsights extends BaseInsights { appStoreInstall?: boolean; fridaDetected?: boolean; jailbreak?: boolean; statusCode?: number; } export type InsightsPayload = | AndroidInsights | IOSInsights | Record | string; export interface SubmitResponse { message: string; eventId: string; action?: string; iv?: string; insights?: InsightsPayload; } // BureauApi class for unified API export class BureauApi { private static modules: Map = new Map(); private constructor() { } /** * Static method to initialize the Bureau API with device intelligence */ static async init({ credentialId, env, enableSmartInsightFetch = false, enableBehavioralBiometrics = false, }: BureauConfig): Promise { if (Platform.OS === 'ios') { return FraudNativeModule.initDeviceIntelligence( credentialId, Environment[env], enableSmartInsightFetch ); } //Exectution will reach here only in case of android so it will correctly pass the paramter to //android native code return FraudNativeModule.initDeviceIntelligence( credentialId, Environment[env], enableBehavioralBiometrics, enableSmartInsightFetch ); } /** * Submit device intelligence data */ static async submit(): Promise { const data = await FraudNativeModule.submitDeviceIntelligence(); return data as SubmitResponse; } /** * Async submit device intelligence data and return event ID */ static async asyncSubmit(): Promise { return FraudNativeModule.asyncSubmitDeviceIntelligence(); } /** * Check if the SDK is initialized */ static isInitialized(): Promise { return FraudNativeModule.isInitialized(); } /** * Get the current user ID */ static getUserId(): Promise { return FraudNativeModule.getUserId(); } /** * Set meta information */ static setMetaInfo(metaInfo: MetaInfo): void { FraudNativeModule.setMetaInfo(metaInfo); } /** * Set user ID */ static setUserId(userId: string): void { FraudNativeModule.setUserId(userId); } /** * Set flow */ static setFlow(flow: string): void { FraudNativeModule.setFlow(flow); } /** * Add a module to the Bureau API */ static async addModule(module: BureauModule): Promise { await module.initialize(); this.modules.set(module.name, module); } /** * Get a module by name */ static getModule(name: string): T | undefined { return this.modules.get(name) as T | undefined; } /** * Get all registered modules */ static getModules(): BureauModule[] { return Array.from(this.modules.values()); } /** * Check if a module is registered */ static hasModule(name: string): boolean { return this.modules.has(name); } }