import RookSdk, { type DiagnosticState } from '../NativeRookSdk'; import { useRookSyncGateContext } from '../context/RookSyncGateContext'; import { isModuleReady } from '../utils/isModuleReady'; import { SDKDataSource } from '../types/SDKSources'; import { Platform } from 'react-native'; /** * The `useRookConfiguration` hook provides various asynchronous methods for managing the configuration * of the ROOK SDK * @returns The `useRookConfiguration` function returns an object containing that allow the user to configure * the SDK */ export const useRookConfiguration = () => { const { state: { ready }, dispatch, } = useRookSyncGateContext(); /** * The `getUserID` function retrieves the user ID * @returns The function `getUserID` is returning a Promise that resolves to a string value. */ const getUserID = async (): Promise => { isModuleReady(ready); const result = await RookSdk.getUserID(); if (result) dispatch({ type: 'SET_USER_ID', userID: result }); return result; }; /** * The function `updateUserID` updates the user ID and returns a boolean indicating the success of * the update. * @param {string} userID - The `userID` parameter is a string that represents the user ID that needs * to be updated in the system. * @returns The `updateUserID` function returns a Promise that resolves to a boolean value. */ const updateUserID = async (userID: string): Promise => { isModuleReady(ready); const result: boolean = await RookSdk.updateUserID(userID); dispatch({ type: 'SET_USER_ID', userID }); return result; }; /** * This function `syncUserTimeZone` synchronizes the user's time zone using * @returns The `syncUserTimeZone` function returns a boolean value, indicating success or failure */ const syncUserTimeZone = async (): Promise => { isModuleReady(ready); const result: boolean = await RookSdk.syncUserTimeZone(); return result; }; /** * The function `removeUserFromRook` removes a user from a rook services, If you delete the user from the Rook services you have to create the user again with updateUserID and request permissions. * @returns The `removeUserFromRook` function is returning a boolean value. */ const removeUserFromRook = async ( sources: SDKDataSource[] ): Promise => { isModuleReady(ready); dispatch({ type: 'SET_USER_ID', userID: '' }); return RookSdk.removeUserFromRook(sources); }; const getDiagnosticState = async ( source: SDKDataSource ): Promise => { isModuleReady(ready); if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) { const value = await RookSdk.getHealthConnectDiagnosticState(); return JSON.parse(value); } if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) { const value = await RookSdk.getSamsungHealthDiagnosticState(); return JSON.parse(value); } if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) { return RookSdk.getDiagnosticState(); } throw new Error('Check the datasource'); }; return { ready, getUserID, updateUserID, removeUserFromRook, syncUserTimeZone, getDiagnosticState, }; };