import Logger from '../utils/logger'; import { API_ENDPOINTS } from './apiEndpoints'; import type { VerificationResultsResponse } from '../types/apiTypes'; import type { GetIdSdk } from '@get-id/react-native-sdk'; type VerificationResultsProps = { sdk: GetIdSdk; }; type VerificationResultsResult = Promise; const getVerificationResults = async ({ sdk, }: VerificationResultsProps): VerificationResultsResult => { Logger.log(`Getting application verification results...`); const headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + sdk.config.token, }; try { const response = await fetch( sdk.config.apiUrl + API_ENDPOINTS.APPLICATION, { method: 'GET', headers: headers, } ); if (!response.ok) { const errorData = await response.json(); Logger.error( `Error fetching application results: ${errorData}`, sdk.tracking.trySendEvent ); throw new Error('Error fetching application results'); } const responseData = await response.json(); Logger.log(`Proccessing state: ${responseData.processingState}`); return responseData as VerificationResultsResponse; } catch (error: any) { Logger.error( `Error fetching application results: ${error}`, sdk.tracking.trySendEvent ); throw new Error('Error Fetching application results'); } }; export default getVerificationResults;