UNPKG

react-native-healthkit-bridge

Version:

A comprehensive React Native bridge for Apple HealthKit with TypeScript support, advanced authorization, and flexible data queries

33 lines (32 loc) 1.4 kB
import { HealthKitIdentifier } from '../value-objects/HealthKitIdentifier'; export class RequestAuthorizationUseCase { constructor(healthKitRepository) { this.healthKitRepository = healthKitRepository; } async execute() { try { if (!this.healthKitRepository.isAvailable()) { throw new Error('HealthKit is not available on this device'); } return await this.healthKitRepository.requestAuthorization(); } catch (error) { throw new Error(`Failed to request authorization: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async executeSelective(identifiers) { try { if (!this.healthKitRepository.isAvailable()) { throw new Error('HealthKit is not available on this device'); } if (!identifiers || identifiers.length === 0) { throw new Error('At least one identifier must be provided'); } const healthKitIdentifiers = identifiers.map(id => HealthKitIdentifier.create(id)); return await this.healthKitRepository.requestSelectiveAuthorization(healthKitIdentifiers); } catch (error) { throw new Error(`Failed to request selective authorization: ${error instanceof Error ? error.message : 'Unknown error'}`); } } }