import type { GetIdSdk } from '@get-id/react-native-sdk'; import { postEvent, type EventStep, type EventStepPhase, } from '../../api/postEvent'; import { clientTimestamp, toEventStep } from '../../utils/tracking'; import { Platform } from 'react-native'; const tracking = (sdk: GetIdSdk, configuration: any, flow = '') => { const metadata = { externalId: configuration.externalId, flowName: configuration.flowName || flow, locale: 'en', livenessSchemaVersion: '0.5', os: Platform.OS, }; const trySendEvent = async ( step: EventStep, stepPhase?: EventStepPhase | null, additional: any = {}, livenessServerMessage?: Record, screenEvent?: unknown ) => { const eventStep = toEventStep(step as any); // console.log('trySendEvent', step, '->', eventStep); if (eventStep === undefined) { console.error(`Unknown step: ${step}`); } else { const data = { event: { step: eventStep, ...(stepPhase && { stepPhase }), clientTimestamp: clientTimestamp(), livenessServerMessage, additional: additional ?? {}, event: screenEvent, }, metadata: metadata, } as any; try { await postEvent({ requestBody: data, sdk: sdk }); } catch (e) { console.error(e); } } }; return { trySendEvent, metadata, }; }; export default tracking;