react-native-rook-sdk 4.0.0 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +35 -3
- package/RNRookSdk.podspec +22 -0
- package/android/build.gradle +21 -40
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +1709 -117
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +26 -42
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +34 -37
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +8 -14
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +8 -16
- package/android/src/main/java/com/rooksdk/utils/{DatasourcesUtils.kt → DatasourceUtils.kt} +10 -9
- package/android/src/main/java/com/rooksdk/utils/{PermissionConversion.kt → PermissionConvertions.kt} +1 -1
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +3 -0
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +1 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/serializers/ZoneDateTimeSerializer.kt +18 -0
- package/ios/DateHelper.swift +4 -4
- package/ios/Encodable.swift +25 -0
- package/ios/EncodableDataSource.swift +2 -3
- package/ios/EncodableDataSourceAuthorizer.swift +2 -3
- package/ios/EncodableSDKState.swift +3 -2
- package/ios/{EncodableHeartRate.swift → HearRateMapper.swift} +3 -3
- package/ios/NutritionMapper.swift +3 -3
- package/ios/RookBackground.swift +5 -8
- package/ios/RookConfiguration.swift +33 -30
- package/ios/{RookLocalData.swift → RookData.swift} +76 -69
- package/ios/RookEntry.swift +62 -0
- package/ios/RookPermissions.swift +36 -40
- package/ios/RookSdk-Bridging-Header.h +12 -0
- package/ios/RookSdk.h +3 -3
- package/ios/RookSdk.mm +390 -134
- package/ios/RookSources.swift +60 -54
- package/ios/RookSync.swift +48 -78
- package/ios/boost-boost_privacy-Bridging-Header.h +4 -0
- package/lib/{commonjs/types/AppleHealthPermissions.js → module/NativeRookSdk.js} +50 -6
- package/lib/module/NativeRookSdk.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +2 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +17 -18
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +2 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/context/RookSyncGateTypes.js +2 -0
- package/lib/module/hooks/useRookAPISources.js +10 -16
- package/lib/module/hooks/useRookAPISources.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +11 -12
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +9 -10
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +17 -22
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +33 -38
- package/lib/module/hooks/useRookData.js.map +1 -1
- package/lib/module/hooks/useRookHealthConnect.js +9 -10
- package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +34 -45
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSamsungHealth.js +8 -20
- package/lib/module/hooks/useRookSamsungHealth.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +23 -32
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +26 -29
- package/lib/module/hooks/useRookVariables.js.map +1 -1
- package/lib/module/index.js +18 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/components/RookStateManager.js +31 -0
- package/lib/module/modules/components/RookStateManager.js.map +1 -0
- package/lib/module/modules/hook/useRookAutoSync.js +24 -36
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/hook/useRookEmitter.js +61 -0
- package/lib/module/modules/hook/useRookEmitter.js.map +1 -0
- package/lib/module/modules/types/sendMessageBroadcast.js +1 -1
- package/lib/module/modules/utils/errors.js +2 -0
- package/lib/module/modules/utils/errors.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/types/ActivityEvent.js +2 -0
- package/lib/module/types/AppleHealthNutritionEvent.js +2 -0
- package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -1
- package/lib/module/types/AppleHealthPermissions.js +2 -0
- package/lib/module/types/AppleHealthPermissions.js.map +1 -1
- package/lib/module/types/AuthorizedSources.js +2 -0
- package/lib/module/types/BodySummary.js +2 -0
- package/lib/module/types/DataSource.js +2 -0
- package/lib/module/types/DataSource.js.map +1 -1
- package/lib/module/types/HCMealData.js +3 -1
- package/lib/module/types/HCMealData.js.map +1 -1
- package/lib/module/types/HeartRateEvent.js +1 -1
- package/lib/module/types/PermissionsType.js +1 -1
- package/lib/module/types/PhysicalSummary.js +2 -0
- package/lib/module/types/Rook.js +2 -0
- package/lib/{commonjs/types/BodySummary.js.map → module/types/Rook.js.map} +1 -1
- package/lib/module/types/SDKSources.js +2 -0
- package/lib/module/types/SDKSources.js.map +1 -1
- package/lib/module/types/SamsungHealthPermissions.js +3 -0
- package/lib/module/types/SamsungHealthPermissions.js.map +1 -1
- package/lib/module/types/SleepSummary.js +2 -0
- package/lib/module/types/SummaryTypes.js +1 -1
- package/lib/module/types/SyncTypes.js +2 -0
- package/lib/module/types/SyncTypes.js.map +1 -1
- package/lib/module/types/WriteNutrition.js +2 -0
- package/lib/module/types/WriteNutrition.js.map +1 -1
- package/lib/module/utils/isModuleReady.js +2 -0
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isRunningOnAndroid.js +2 -0
- package/lib/module/utils/isRunningOnAndroid.js.map +1 -1
- package/lib/module/utils/isRunningOniOS.js +2 -0
- package/lib/module/utils/isRunningOniOS.js.map +1 -1
- package/lib/module/utils/isValidDate.js +2 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeRookSdk.d.ts +705 -0
- package/lib/typescript/src/NativeRookSdk.d.ts.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAPISources.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +0 -6
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSync.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +17 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/components/RookStateManager.d.ts +10 -0
- package/lib/typescript/src/modules/components/RookStateManager.d.ts.map +1 -0
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts +4 -0
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts.map +1 -0
- package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/AuthorizedSources.d.ts +11 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/HCMealData.d.ts.map +1 -1
- package/lib/typescript/src/types/HeartRateEvent.d.ts +2 -2
- package/lib/typescript/src/types/HeartRateEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/Rook.d.ts +9 -0
- package/lib/typescript/src/types/Rook.d.ts.map +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts.map +1 -1
- package/lib/typescript/src/types/SyncTypes.d.ts +5 -1
- package/lib/typescript/src/types/SyncTypes.d.ts.map +1 -1
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/package.json +94 -98
- package/src/NativeRookSdk.ts +839 -0
- package/{lib/commonjs/context/RookSyncGateContext.js → src/context/RookSyncGateContext.ts} +10 -13
- package/src/context/RookSyncGateProvider.tsx +82 -0
- package/{lib/commonjs/context/RookSyncGateReducer.js → src/context/RookSyncGateReducer.ts} +14 -41
- package/src/context/RookSyncGateTypes.ts +40 -0
- package/{lib/commonjs/hooks/useRookAPISources.js → src/hooks/useRookAPISources.ts} +40 -36
- package/src/hooks/useRookAndroidBackgroundSteps.ts +81 -0
- package/src/hooks/useRookAppleHealth.ts +55 -0
- package/src/hooks/useRookConfiguration.ts +106 -0
- package/src/hooks/useRookData.ts +133 -0
- package/src/hooks/useRookHealthConnect.ts +59 -0
- package/src/hooks/useRookPermissions.ts +240 -0
- package/src/hooks/useRookSamsungHealth.ts +37 -0
- package/src/hooks/useRookSync.ts +157 -0
- package/src/hooks/useRookVariables.ts +98 -0
- package/src/index.tsx +28 -0
- package/src/modules/components/RookStateManager.tsx +41 -0
- package/{lib/commonjs/modules/hook/useRookAutoSync.js → src/modules/hook/useRookAutoSync.ts} +141 -95
- package/src/modules/hook/useRookEmitter.ts +94 -0
- package/src/modules/types/sendMessageBroadcast.ts +5 -0
- package/src/modules/utils/errors.ts +9 -0
- package/src/types/ActivityEvent.ts +159 -0
- package/src/types/AppleHealthNutritionEvent.ts +142 -0
- package/src/types/AppleHealthPermissions.ts +49 -0
- package/src/types/AuthorizedSources.ts +33 -0
- package/src/types/BodySummary.ts +116 -0
- package/src/types/DataSource.ts +16 -0
- package/{lib/commonjs/types/HCMealData.js → src/types/HCMealData.ts} +60 -11
- package/src/types/HeartRateEvent.ts +26 -0
- package/src/types/PermissionsType.ts +9 -0
- package/src/types/PhysicalSummary.ts +84 -0
- package/src/types/Rook.ts +8 -0
- package/src/types/SDKSources.ts +5 -0
- package/src/types/SamsungHealthPermissions.ts +16 -0
- package/src/types/SleepSummary.ts +66 -0
- package/src/types/SummaryTypes.ts +70 -0
- package/src/types/SyncTypes.ts +63 -0
- package/src/types/WriteNutrition.ts +66 -0
- package/{lib/commonjs/utils/isModuleReady.js → src/utils/isModuleReady.ts} +4 -10
- package/src/utils/isRunningOnAndroid.ts +10 -0
- package/src/utils/isRunningOniOS.ts +10 -0
- package/{lib/commonjs/utils/isValidDate.js → src/utils/isValidDate.ts} +12 -14
- package/android/src/main/AndroidManifestNew.xml +0 -36
- package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +0 -99
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +0 -182
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +0 -301
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +0 -359
- package/android/src/main/java/com/rooksdk/modules/RookSourcesModule.kt +0 -102
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +0 -119
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +0 -551
- package/android/src/main/res/drawable/ic_health_connect.xml +0 -19
- package/android/src/main/res/values/themes.xml +0 -3
- package/ios/EncodableRookDataSource.swift +0 -36
- package/ios/EncodableStatusDataSources.swift +0 -47
- package/ios/RookBackgroundModule.h +0 -5
- package/ios/RookBackgroundModule.mm +0 -15
- package/ios/RookConfigurationModule.h +0 -5
- package/ios/RookConfigurationModule.mm +0 -22
- package/ios/RookExternalModule.h +0 -5
- package/ios/RookExternalModule.m +0 -31
- package/ios/RookPermissionsModule.h +0 -5
- package/ios/RookPermissionsModule.mm +0 -20
- package/ios/RookSourcesModule.h +0 -5
- package/ios/RookSourcesModule.mm +0 -18
- package/ios/RookSync.h +0 -5
- package/ios/RookSync.m +0 -35
- package/ios/SwiftTest.swift +0 -18
- package/ios/react-native-rook-sdk-Bridging-Header.h +0 -12
- package/lib/commonjs/context/RookSyncGateContext.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateProvider.js +0 -108
- package/lib/commonjs/context/RookSyncGateProvider.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateReducer.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateTypes.js +0 -6
- package/lib/commonjs/context/RookSyncGateTypes.js.map +0 -1
- package/lib/commonjs/context/index.js +0 -14
- package/lib/commonjs/context/index.js.map +0 -1
- package/lib/commonjs/hooks/index.js +0 -76
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/useRookAPISources.js.map +0 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +0 -88
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +0 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +0 -63
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +0 -113
- package/lib/commonjs/hooks/useRookConfiguration.js.map +0 -1
- package/lib/commonjs/hooks/useRookData.js +0 -116
- package/lib/commonjs/hooks/useRookData.js.map +0 -1
- package/lib/commonjs/hooks/useRookHealthConnect.js +0 -70
- package/lib/commonjs/hooks/useRookHealthConnect.js.map +0 -1
- package/lib/commonjs/hooks/useRookPermissions.js +0 -211
- package/lib/commonjs/hooks/useRookPermissions.js.map +0 -1
- package/lib/commonjs/hooks/useRookSamsungHealth.js +0 -54
- package/lib/commonjs/hooks/useRookSamsungHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookSync.js +0 -148
- package/lib/commonjs/hooks/useRookSync.js.map +0 -1
- package/lib/commonjs/hooks/useRookVariables.js +0 -93
- package/lib/commonjs/hooks/useRookVariables.js.map +0 -1
- package/lib/commonjs/index.js +0 -121
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +0 -1
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +0 -2
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +0 -1
- package/lib/commonjs/modules/utils/errors.js +0 -12
- package/lib/commonjs/modules/utils/errors.js.map +0 -1
- package/lib/commonjs/types/ActivityEvent.js +0 -6
- package/lib/commonjs/types/ActivityEvent.js.map +0 -1
- package/lib/commonjs/types/AppleHealthNutritionEvent.js +0 -77
- package/lib/commonjs/types/AppleHealthNutritionEvent.js.map +0 -1
- package/lib/commonjs/types/AppleHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/AuthorizedSources.js +0 -6
- package/lib/commonjs/types/AuthorizedSources.js.map +0 -1
- package/lib/commonjs/types/BodySummary.js +0 -6
- package/lib/commonjs/types/DataSource.js +0 -16
- package/lib/commonjs/types/DataSource.js.map +0 -1
- package/lib/commonjs/types/DiagnosticState.js +0 -2
- package/lib/commonjs/types/DiagnosticState.js.map +0 -1
- package/lib/commonjs/types/HCMealData.js.map +0 -1
- package/lib/commonjs/types/HeartRateEvent.js +0 -2
- package/lib/commonjs/types/HeartRateEvent.js.map +0 -1
- package/lib/commonjs/types/PermissionsType.js +0 -2
- package/lib/commonjs/types/PermissionsType.js.map +0 -1
- package/lib/commonjs/types/PhysicalSummary.js +0 -6
- package/lib/commonjs/types/PhysicalSummary.js.map +0 -1
- package/lib/commonjs/types/SDKSources.js +0 -13
- package/lib/commonjs/types/SDKSources.js.map +0 -1
- package/lib/commonjs/types/SamsungHealthPermissions.js +0 -23
- package/lib/commonjs/types/SamsungHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/SleepSummary.js +0 -6
- package/lib/commonjs/types/SleepSummary.js.map +0 -1
- package/lib/commonjs/types/SummaryTypes.js +0 -2
- package/lib/commonjs/types/SummaryTypes.js.map +0 -1
- package/lib/commonjs/types/SyncTypes.js +0 -33
- package/lib/commonjs/types/SyncTypes.js.map +0 -1
- package/lib/commonjs/types/WriteNutrition.js +0 -18
- package/lib/commonjs/types/WriteNutrition.js.map +0 -1
- package/lib/commonjs/utils/getNativeModule.js +0 -29
- package/lib/commonjs/utils/getNativeModule.js.map +0 -1
- package/lib/commonjs/utils/getRookModule.js +0 -28
- package/lib/commonjs/utils/getRookModule.js.map +0 -1
- package/lib/commonjs/utils/isModuleReady.js.map +0 -1
- package/lib/commonjs/utils/isRunningOnAndroid.js +0 -15
- package/lib/commonjs/utils/isRunningOnAndroid.js.map +0 -1
- package/lib/commonjs/utils/isRunningOniOS.js +0 -15
- package/lib/commonjs/utils/isRunningOniOS.js.map +0 -1
- package/lib/commonjs/utils/isValidDate.js.map +0 -1
- package/lib/commonjs/utils/nativeModules.js +0 -29
- package/lib/commonjs/utils/nativeModules.js.map +0 -1
- package/lib/commonjs/utils/packageInfo.js +0 -13
- package/lib/commonjs/utils/packageInfo.js.map +0 -1
- package/lib/module/context/index.js +0 -2
- package/lib/module/context/index.js.map +0 -1
- package/lib/module/hooks/index.js +0 -11
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/types/DiagnosticState.js +0 -2
- package/lib/module/types/DiagnosticState.js.map +0 -1
- package/lib/module/utils/getNativeModule.js +0 -23
- package/lib/module/utils/getNativeModule.js.map +0 -1
- package/lib/module/utils/getRookModule.js +0 -22
- package/lib/module/utils/getRookModule.js.map +0 -1
- package/lib/module/utils/nativeModules.js +0 -23
- package/lib/module/utils/nativeModules.js.map +0 -1
- package/lib/module/utils/packageInfo.js +0 -7
- package/lib/module/utils/packageInfo.js.map +0 -1
- package/lib/typescript/src/context/index.d.ts +0 -2
- package/lib/typescript/src/context/index.d.ts.map +0 -1
- package/lib/typescript/src/hooks/index.d.ts +0 -11
- package/lib/typescript/src/hooks/index.d.ts.map +0 -1
- package/lib/typescript/src/types/DiagnosticState.d.ts +0 -13
- package/lib/typescript/src/types/DiagnosticState.d.ts.map +0 -1
- package/lib/typescript/src/utils/getNativeModule.d.ts +0 -10
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/getRookModule.d.ts +0 -9
- package/lib/typescript/src/utils/getRookModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +0 -24
- package/lib/typescript/src/utils/nativeModules.d.ts.map +0 -1
- package/lib/typescript/src/utils/packageInfo.d.ts +0 -6
- package/lib/typescript/src/utils/packageInfo.d.ts.map +0 -1
- package/react-native-rook-sdk.podspec +0 -45
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useRookSyncGateContext = exports.RookSyncGateContext = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
1
|
// RookSyncGateContext.tsx
|
|
2
|
+
import { createContext, useContext, type Dispatch } from 'react';
|
|
3
|
+
import type { RookSyncGateState, Action } from './RookSyncGateTypes';
|
|
9
4
|
|
|
10
5
|
/* This line of code is creating a context using the `createContext` function provided by React. The
|
|
11
6
|
context being created is named `RookSyncGateContext` and it is defined to hold an object with two
|
|
12
7
|
properties: `state` of type `RookSyncGateState` and `dispatch` of type `Dispatch<Action>`. The
|
|
13
8
|
`Dispatch` type is a generic type that represents a function to dispatch actions. */
|
|
14
|
-
const RookSyncGateContext =
|
|
9
|
+
export const RookSyncGateContext = createContext<
|
|
10
|
+
{ state: RookSyncGateState; dispatch: Dispatch<Action> } | undefined
|
|
11
|
+
>(undefined);
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* The function `useRookSyncGateContext` ensures that it is used within the `RookSyncGateProvider`
|
|
@@ -20,12 +17,12 @@ const RookSyncGateContext = exports.RookSyncGateContext = /*#__PURE__*/(0, _reac
|
|
|
20
17
|
* `RookSyncGateContext` using the `useContext` hook. If the context is not found, it throws an error
|
|
21
18
|
* indicating that `useRookSyncGateContext` should be used inside `RookSyncGateProvider`.
|
|
22
19
|
*/
|
|
23
|
-
const useRookSyncGateContext = () => {
|
|
24
|
-
const context =
|
|
20
|
+
export const useRookSyncGateContext = () => {
|
|
21
|
+
const context = useContext(RookSyncGateContext);
|
|
25
22
|
if (!context) {
|
|
26
|
-
throw new Error(
|
|
23
|
+
throw new Error(
|
|
24
|
+
'useRookSyncGateContext should be used inside RookSyncGateProvider'
|
|
25
|
+
);
|
|
27
26
|
}
|
|
28
27
|
return context;
|
|
29
28
|
};
|
|
30
|
-
exports.useRookSyncGateContext = useRookSyncGateContext;
|
|
31
|
-
//# sourceMappingURL=RookSyncGateContext.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import { useReducer, type FC, useEffect } from 'react';
|
|
3
|
+
import { rookSyncGateReducer } from './RookSyncGateReducer'; // Importa el reducer
|
|
4
|
+
import type {
|
|
5
|
+
RookSyncGateState,
|
|
6
|
+
RookSyncGateProviderProps,
|
|
7
|
+
} from './RookSyncGateTypes';
|
|
8
|
+
import { RookSyncGateContext } from './RookSyncGateContext';
|
|
9
|
+
import RookSdk from '../NativeRookSdk';
|
|
10
|
+
import { RookStateManager } from '../modules/components/RookStateManager';
|
|
11
|
+
|
|
12
|
+
const initialState: RookSyncGateState = {
|
|
13
|
+
clientUUID: '',
|
|
14
|
+
environment: 'sandbox',
|
|
15
|
+
secret: '',
|
|
16
|
+
bundleId: undefined,
|
|
17
|
+
packageName: undefined,
|
|
18
|
+
ready: false,
|
|
19
|
+
userID: '',
|
|
20
|
+
permissions: 0,
|
|
21
|
+
enableLogs: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* This code snippet is defining a React functional component called `RookSyncGateProvider`.
|
|
26
|
+
* this define the provider for the SDK
|
|
27
|
+
*/
|
|
28
|
+
const RookSyncGateProvider: FC<RookSyncGateProviderProps> = ({
|
|
29
|
+
environment,
|
|
30
|
+
clientUUID,
|
|
31
|
+
secret,
|
|
32
|
+
bundleId,
|
|
33
|
+
packageName,
|
|
34
|
+
children,
|
|
35
|
+
enableLogs = false,
|
|
36
|
+
enableBackgroundSync,
|
|
37
|
+
}) => {
|
|
38
|
+
const [state, dispatch] = useReducer(rookSyncGateReducer, initialState);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
initModule();
|
|
42
|
+
}, [environment, clientUUID, secret]);
|
|
43
|
+
|
|
44
|
+
const initModule = async (): Promise<void> => {
|
|
45
|
+
dispatch({ type: 'SET_ROOK_ENVIRONMENT', environment });
|
|
46
|
+
dispatch({ type: 'SET_CLIENT_UUID', clientUUID });
|
|
47
|
+
dispatch({ type: 'SET_SECRET', secret });
|
|
48
|
+
dispatch({ type: 'SET_BUNDLE_ID', bundle: bundleId });
|
|
49
|
+
dispatch({ type: 'SET_PACKAGE_NAME', package: packageName });
|
|
50
|
+
dispatch({ type: 'SET_ENABLE_LOGS', enableLogs });
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
await RookSdk.initRook({
|
|
54
|
+
environment,
|
|
55
|
+
clientUUID,
|
|
56
|
+
secret,
|
|
57
|
+
bundleId,
|
|
58
|
+
packageName,
|
|
59
|
+
enableLogs,
|
|
60
|
+
enableBackground: enableBackgroundSync,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
dispatch({ type: 'SET_READY', ready: true });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log(error);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<RookSyncGateContext.Provider value={{ state, dispatch }}>
|
|
71
|
+
<RookStateManager
|
|
72
|
+
state={state}
|
|
73
|
+
enableBackground={enableBackgroundSync}
|
|
74
|
+
enableLogs={enableLogs}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
{children}
|
|
78
|
+
</RookSyncGateContext.Provider>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default RookSyncGateProvider;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { RookSyncGateState, Action } from './RookSyncGateTypes';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.rookSyncGateReducer = void 0;
|
|
7
3
|
/**
|
|
8
4
|
* The rookSyncGateReducer function in TypeScript handles various actions to update the state of a
|
|
9
5
|
* RookSyncGate component.
|
|
@@ -19,56 +15,33 @@ exports.rookSyncGateReducer = void 0;
|
|
|
19
15
|
* type provided. The state object is updated with the corresponding values based on the action type.
|
|
20
16
|
* If the action type is not recognized, it returns the current state unchanged.
|
|
21
17
|
*/
|
|
22
|
-
const rookSyncGateReducer = (
|
|
18
|
+
export const rookSyncGateReducer = (
|
|
19
|
+
state: RookSyncGateState,
|
|
20
|
+
action: Action
|
|
21
|
+
): RookSyncGateState => {
|
|
23
22
|
switch (action.type) {
|
|
24
23
|
case 'SET_READY':
|
|
25
|
-
return {
|
|
26
|
-
...state,
|
|
27
|
-
ready: action.ready
|
|
28
|
-
};
|
|
24
|
+
return { ...state, ready: action.ready };
|
|
29
25
|
case 'SET_ROOK_ENVIRONMENT':
|
|
30
|
-
return {
|
|
31
|
-
...state,
|
|
32
|
-
environment: action.environment
|
|
33
|
-
};
|
|
26
|
+
return { ...state, environment: action.environment };
|
|
34
27
|
case 'SET_CLIENT_UUID':
|
|
35
|
-
return {
|
|
36
|
-
...state,
|
|
37
|
-
clientUUID: action.clientUUID
|
|
38
|
-
};
|
|
28
|
+
return { ...state, clientUUID: action.clientUUID };
|
|
39
29
|
case 'SET_SECRET':
|
|
40
|
-
return {
|
|
41
|
-
...state,
|
|
42
|
-
secret: action.secret
|
|
43
|
-
};
|
|
30
|
+
return { ...state, secret: action.secret };
|
|
44
31
|
case 'SET_BUNDLE_ID':
|
|
45
|
-
return {
|
|
46
|
-
...state,
|
|
47
|
-
bundleId: action.bundle
|
|
48
|
-
};
|
|
32
|
+
return { ...state, bundleId: action.bundle };
|
|
49
33
|
case 'SET_PACKAGE_NAME':
|
|
50
|
-
return {
|
|
51
|
-
...state,
|
|
52
|
-
packageName: action.package
|
|
53
|
-
};
|
|
34
|
+
return { ...state, packageName: action.package };
|
|
54
35
|
case 'SET_USER_ID':
|
|
55
|
-
return {
|
|
56
|
-
...state,
|
|
57
|
-
userID: action.userID
|
|
58
|
-
};
|
|
36
|
+
return { ...state, userID: action.userID };
|
|
59
37
|
case 'SET_ENABLE_LOGS':
|
|
60
|
-
return {
|
|
61
|
-
...state,
|
|
62
|
-
enableLogs: action.enableLogs
|
|
63
|
-
};
|
|
38
|
+
return { ...state, enableLogs: action.enableLogs };
|
|
64
39
|
case 'SET_PERMISSIONS':
|
|
65
40
|
return {
|
|
66
41
|
...state,
|
|
67
|
-
permissions: state.permissions + 1
|
|
42
|
+
permissions: state.permissions + 1,
|
|
68
43
|
};
|
|
69
44
|
default:
|
|
70
45
|
return state;
|
|
71
46
|
}
|
|
72
47
|
};
|
|
73
|
-
exports.rookSyncGateReducer = rookSyncGateReducer;
|
|
74
|
-
//# sourceMappingURL=RookSyncGateReducer.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type Environment = 'sandbox' | 'production';
|
|
4
|
+
|
|
5
|
+
type RookSyncGateState = {
|
|
6
|
+
clientUUID: string;
|
|
7
|
+
environment: Environment;
|
|
8
|
+
secret: string;
|
|
9
|
+
bundleId?: string;
|
|
10
|
+
packageName?: string;
|
|
11
|
+
ready: boolean;
|
|
12
|
+
userID: string;
|
|
13
|
+
permissions: number;
|
|
14
|
+
enableLogs: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Action =
|
|
18
|
+
| { type: 'SET_CLIENT_UUID'; clientUUID: string }
|
|
19
|
+
| { type: 'SET_ENABLE_LOGS'; enableLogs: boolean }
|
|
20
|
+
| { type: 'SET_SECRET'; secret: string }
|
|
21
|
+
| { type: 'SET_BUNDLE_ID'; bundle: string | undefined }
|
|
22
|
+
| { type: 'SET_PACKAGE_NAME'; package: string | undefined }
|
|
23
|
+
| { type: 'SET_PERMISSIONS' }
|
|
24
|
+
| { type: 'SET_READY'; ready: boolean }
|
|
25
|
+
| { type: 'SET_ROOK_ENVIRONMENT'; environment: Environment }
|
|
26
|
+
| { type: 'SET_USER_ID'; userID: string };
|
|
27
|
+
|
|
28
|
+
type RookSyncGateProviderProps = {
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
environment: Environment;
|
|
31
|
+
clientUUID: string;
|
|
32
|
+
secret: string;
|
|
33
|
+
bundleId?: string;
|
|
34
|
+
packageName?: string;
|
|
35
|
+
enableLogs?: boolean;
|
|
36
|
+
enableBackgroundSync: boolean;
|
|
37
|
+
enableEventsBackgroundSync?: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type { RookSyncGateState, Action, RookSyncGateProviderProps };
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import RookSdk from '../NativeRookSdk';
|
|
2
|
+
import { isModuleReady } from '../utils/isModuleReady';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { useRookSyncGateContext } from '../context/RookSyncGateContext';
|
|
5
|
+
import type { APIDataSource } from '../types/DataSource';
|
|
6
|
+
import type {
|
|
7
|
+
AuthorizedSource,
|
|
8
|
+
DataSourceAuthorizer,
|
|
9
|
+
DataSourceProps,
|
|
10
|
+
} from '../types/AuthorizedSources';
|
|
2
11
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useRookAPISources = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _isModuleReady = require("../utils/isModuleReady");
|
|
9
|
-
var _reactNative = require("react-native");
|
|
10
|
-
var _RookSyncGateContext = require("../context/RookSyncGateContext");
|
|
11
|
-
var _getNativeModule = _interopRequireDefault(require("../utils/getNativeModule"));
|
|
12
|
-
var _nativeModules = _interopRequireDefault(require("../utils/nativeModules"));
|
|
13
|
-
var _packageInfo = require("../utils/packageInfo");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
12
|
/**
|
|
16
13
|
* The `useRookDataSources` hook provides functionality to interact with data sources in Rook,
|
|
17
14
|
* including retrieving available data sources, presenting a connections page, and revoking user
|
|
18
15
|
* authorization for a specific data source.
|
|
19
16
|
* @returns An object is being returned from the `useRookDataSources` hook to allow the user to access to the sources API
|
|
20
17
|
*/
|
|
21
|
-
const useRookAPISources = () => {
|
|
22
|
-
const rookSync = (0, _react.useRef)((0, _getNativeModule.default)(_reactNative.Platform.select({
|
|
23
|
-
android: () => _nativeModules.default.android.SOURCES,
|
|
24
|
-
default: () => _nativeModules.default.ios.SOURCES
|
|
25
|
-
})()));
|
|
18
|
+
export const useRookAPISources = () => {
|
|
26
19
|
const {
|
|
27
|
-
state: {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
} = (0, _RookSyncGateContext.useRookSyncGateContext)();
|
|
20
|
+
state: { ready },
|
|
21
|
+
} = useRookSyncGateContext();
|
|
31
22
|
|
|
32
23
|
/**
|
|
33
24
|
* The function `revokeDataSource` revokes user authorization for the specified data source.
|
|
@@ -35,9 +26,13 @@ const useRookAPISources = () => {
|
|
|
35
26
|
* the type of data source that you want to revoke access to. It is of type `DataSourceType`.
|
|
36
27
|
* @returns A Promise<boolean> is being returned from the `revokeDataSource` function.
|
|
37
28
|
*/
|
|
38
|
-
const revokeDataSource = (
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
const revokeDataSource = (
|
|
30
|
+
userid: string,
|
|
31
|
+
type: APIDataSource
|
|
32
|
+
): Promise<boolean> => {
|
|
33
|
+
isModuleReady(ready);
|
|
34
|
+
|
|
35
|
+
return RookSdk.revokeDataSource(userid, type);
|
|
41
36
|
};
|
|
42
37
|
|
|
43
38
|
/**
|
|
@@ -49,9 +44,14 @@ const useRookAPISources = () => {
|
|
|
49
44
|
* @returns The function `getDataSourceAuthorizer` is returning a `DataSourceAuthorizer` object after
|
|
50
45
|
* parsing the response from `rookSync.current.getDataSourceAuthorizer()` as JSON.
|
|
51
46
|
*/
|
|
52
|
-
const getDataSourceAuthorizer = async
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const getDataSourceAuthorizer = async (
|
|
48
|
+
props: DataSourceProps
|
|
49
|
+
): Promise<DataSourceAuthorizer> => {
|
|
50
|
+
const response = await RookSdk.getDataSourceAuthorizer(props);
|
|
51
|
+
|
|
52
|
+
if (Platform.OS === 'android')
|
|
53
|
+
return JSON.parse(response as any) as DataSourceAuthorizer;
|
|
54
|
+
|
|
55
55
|
return response;
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -62,18 +62,22 @@ const useRookAPISources = () => {
|
|
|
62
62
|
* @returns The function `getAuthorizedDataSources` is returning a Promise that will resolve to the
|
|
63
63
|
* result of calling `rookSync.current.getAuthorizedDataSources()`.
|
|
64
64
|
*/
|
|
65
|
-
const getAuthorizedDataSourcesV2 = async
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const getAuthorizedDataSourcesV2 = async (
|
|
66
|
+
userid: string
|
|
67
|
+
): Promise<AuthorizedSource[]> => {
|
|
68
|
+
isModuleReady(ready);
|
|
69
|
+
|
|
70
|
+
if (Platform.OS !== 'android')
|
|
71
|
+
return RookSdk.getAuthorizedDataSourcesV2(userid);
|
|
72
|
+
|
|
73
|
+
const response = await RookSdk.getAuthorizedDataSourcesV2(userid);
|
|
74
|
+
return JSON.parse(response as any) as AuthorizedSource[];
|
|
70
75
|
};
|
|
76
|
+
|
|
71
77
|
return {
|
|
72
78
|
ready,
|
|
73
79
|
revokeDataSource,
|
|
74
80
|
getDataSourceAuthorizer,
|
|
75
|
-
getAuthorizedDataSourcesV2
|
|
81
|
+
getAuthorizedDataSourcesV2,
|
|
76
82
|
};
|
|
77
83
|
};
|
|
78
|
-
exports.useRookAPISources = useRookAPISources;
|
|
79
|
-
//# sourceMappingURL=useRookAPISources.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import RookSdk from '../NativeRookSdk';
|
|
2
|
+
import { useRookSyncGateContext } from '../context/RookSyncGateContext';
|
|
3
|
+
import { isModuleReady } from '../utils/isModuleReady';
|
|
4
|
+
import isRunningOnAndroid from '../utils/isRunningOnAndroid';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `useRookAndroidBackgroundSteps` function provides various methods for managing and retrieving
|
|
8
|
+
* step count data on Android devices using the Rook module.
|
|
9
|
+
* @returns The `useRookAndroidBackgroundSteps` function returns a hook with the functions that allows the user to
|
|
10
|
+
* control de steps sync
|
|
11
|
+
*/
|
|
12
|
+
export const useRookAndroidBackgroundSteps = () => {
|
|
13
|
+
const {
|
|
14
|
+
state: { ready },
|
|
15
|
+
} = useRookSyncGateContext();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The function `isStepsAvailable` checks if steps data is available.
|
|
19
|
+
* @returns The function `isStepsAvailable` is returning a promise that resolve in a boolean value.
|
|
20
|
+
*/
|
|
21
|
+
const isStepsAvailable = async (): Promise<boolean> => {
|
|
22
|
+
isRunningOnAndroid();
|
|
23
|
+
isModuleReady(ready);
|
|
24
|
+
|
|
25
|
+
return RookSdk.isStepsAvailable();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The function `enableBackgroundAndroidSteps` starts collecting of steps during the day
|
|
30
|
+
* @returns The `enableBackgroundAndroidSteps` function is returning a Promise that resolves to a boolean
|
|
31
|
+
*/
|
|
32
|
+
const enableBackgroundAndroidSteps = async (): Promise<boolean> => {
|
|
33
|
+
isRunningOnAndroid();
|
|
34
|
+
isModuleReady(ready);
|
|
35
|
+
|
|
36
|
+
return RookSdk.enableBackgroundAndroidSteps();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The function `disableBackgroundAndroidSteps` stops a process of collecting steps during the day
|
|
41
|
+
* @returns The function `disableBackgroundAndroidSteps` function is returning a Promise that resolves to a boolean
|
|
42
|
+
*/
|
|
43
|
+
const disableBackgroundAndroidSteps = (): Promise<boolean> => {
|
|
44
|
+
isRunningOnAndroid();
|
|
45
|
+
isModuleReady(ready);
|
|
46
|
+
|
|
47
|
+
return RookSdk.disableBackgroundAndroidSteps();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The function `isBackgroundAndroidStepsActive` checks if steps are active and returns a Promise with a boolean
|
|
52
|
+
* value.
|
|
53
|
+
* @returns The function is returning a Promise that resolves to a boolean
|
|
54
|
+
*/
|
|
55
|
+
const isBackgroundAndroidStepsActive = (): Promise<boolean> => {
|
|
56
|
+
isRunningOnAndroid();
|
|
57
|
+
isModuleReady(ready);
|
|
58
|
+
|
|
59
|
+
return RookSdk.isBackgroundAndroidStepsActive();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The function `getTodayAndroidStepsCount` retrieves the number of steps taken today asynchronously as string.
|
|
64
|
+
* @returns The function `getTodaySteps` is returning the result of calling
|
|
65
|
+
*/
|
|
66
|
+
const syncTodayAndroidStepsCount = (): Promise<string> => {
|
|
67
|
+
isRunningOnAndroid();
|
|
68
|
+
isModuleReady(ready);
|
|
69
|
+
|
|
70
|
+
return RookSdk.syncTodayAndroidStepsCount();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
ready,
|
|
75
|
+
isStepsAvailable,
|
|
76
|
+
enableBackgroundAndroidSteps,
|
|
77
|
+
disableBackgroundAndroidSteps,
|
|
78
|
+
isBackgroundAndroidStepsActive,
|
|
79
|
+
syncTodayAndroidStepsCount,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import RookSdk from '../NativeRookSdk';
|
|
2
|
+
|
|
3
|
+
import { useRookSyncGateContext } from '../context/RookSyncGateContext';
|
|
4
|
+
import { isModuleReady } from '../utils/isModuleReady';
|
|
5
|
+
import { isRunningOniOS } from '../utils/isRunningOniOS';
|
|
6
|
+
|
|
7
|
+
export const useRookAppleHealth = () => {
|
|
8
|
+
const {
|
|
9
|
+
state: { ready },
|
|
10
|
+
} = useRookSyncGateContext();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The function `enableBackGroundUpdates` enable background updates and returns a promise
|
|
14
|
+
* indicating success.
|
|
15
|
+
* @returns The function `enableBackGroundUpdates` returns a Promise that resolves to a boolean
|
|
16
|
+
* value.
|
|
17
|
+
*/
|
|
18
|
+
const enableBackGroundUpdates = (): Promise<boolean> => {
|
|
19
|
+
isRunningOniOS();
|
|
20
|
+
isModuleReady(ready);
|
|
21
|
+
|
|
22
|
+
return RookSdk.enableBackGroundUpdates();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The function `disableBackGroundUpdates` disables background updates and returns a promise
|
|
27
|
+
* indicating success.
|
|
28
|
+
* @returns The function `disableBackGroundUpdates` returns a Promise that resolves to a boolean
|
|
29
|
+
* value.
|
|
30
|
+
*/
|
|
31
|
+
const disableBackGroundUpdates = (): Promise<boolean> => {
|
|
32
|
+
isRunningOniOS();
|
|
33
|
+
isModuleReady(ready);
|
|
34
|
+
|
|
35
|
+
return RookSdk.disableBackGroundUpdates();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This function checks if background summaries are enabled.
|
|
40
|
+
* @returns The function `isBackGroundForSummariesEnable` is returning a boolean value
|
|
41
|
+
*/
|
|
42
|
+
const isBackgroundUpdatesEnabled = async (): Promise<boolean> => {
|
|
43
|
+
isRunningOniOS();
|
|
44
|
+
isModuleReady(ready);
|
|
45
|
+
|
|
46
|
+
return RookSdk.isBackgroundUpdatesEnabled();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
ready,
|
|
51
|
+
enableBackGroundUpdates,
|
|
52
|
+
disableBackGroundUpdates,
|
|
53
|
+
isBackgroundUpdatesEnabled,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import RookSdk, { type DiagnosticState } from '../NativeRookSdk';
|
|
2
|
+
|
|
3
|
+
import { useRookSyncGateContext } from '../context/RookSyncGateContext';
|
|
4
|
+
import { isModuleReady } from '../utils/isModuleReady';
|
|
5
|
+
import { SDKDataSource } from '../types/SDKSources';
|
|
6
|
+
import { Platform } from 'react-native';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The `useRookConfiguration` hook provides various asynchronous methods for managing the configuration
|
|
10
|
+
* of the ROOK SDK
|
|
11
|
+
* @returns The `useRookConfiguration` function returns an object containing that allow the user to configure
|
|
12
|
+
* the SDK
|
|
13
|
+
*/
|
|
14
|
+
export const useRookConfiguration = () => {
|
|
15
|
+
const {
|
|
16
|
+
state: { ready },
|
|
17
|
+
dispatch,
|
|
18
|
+
} = useRookSyncGateContext();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The `getUserID` function retrieves the user ID
|
|
22
|
+
* @returns The function `getUserID` is returning a Promise that resolves to a string value.
|
|
23
|
+
*/
|
|
24
|
+
const getUserID = async (): Promise<string> => {
|
|
25
|
+
isModuleReady(ready);
|
|
26
|
+
|
|
27
|
+
const result = await RookSdk.getUserID();
|
|
28
|
+
|
|
29
|
+
if (result) dispatch({ type: 'SET_USER_ID', userID: result });
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The function `updateUserID` updates the user ID and returns a boolean indicating the success of
|
|
36
|
+
* the update.
|
|
37
|
+
* @param {string} userID - The `userID` parameter is a string that represents the user ID that needs
|
|
38
|
+
* to be updated in the system.
|
|
39
|
+
* @returns The `updateUserID` function returns a Promise that resolves to a boolean value.
|
|
40
|
+
*/
|
|
41
|
+
const updateUserID = async (userID: string): Promise<boolean> => {
|
|
42
|
+
isModuleReady(ready);
|
|
43
|
+
|
|
44
|
+
const result: boolean = await RookSdk.updateUserID(userID);
|
|
45
|
+
|
|
46
|
+
dispatch({ type: 'SET_USER_ID', userID });
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This function `syncUserTimeZone` synchronizes the user's time zone using
|
|
53
|
+
* @returns The `syncUserTimeZone` function returns a boolean value, indicating success or failure
|
|
54
|
+
*/
|
|
55
|
+
const syncUserTimeZone = async (): Promise<boolean> => {
|
|
56
|
+
isModuleReady(ready);
|
|
57
|
+
|
|
58
|
+
const result: boolean = await RookSdk.syncUserTimeZone();
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 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.
|
|
64
|
+
* @returns The `removeUserFromRook` function is returning a boolean value.
|
|
65
|
+
*/
|
|
66
|
+
const removeUserFromRook = async (
|
|
67
|
+
sources: SDKDataSource[]
|
|
68
|
+
): Promise<boolean> => {
|
|
69
|
+
isModuleReady(ready);
|
|
70
|
+
|
|
71
|
+
dispatch({ type: 'SET_USER_ID', userID: '' });
|
|
72
|
+
|
|
73
|
+
return RookSdk.removeUserFromRook(sources);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const getDiagnosticState = async (
|
|
77
|
+
source: SDKDataSource
|
|
78
|
+
): Promise<DiagnosticState> => {
|
|
79
|
+
isModuleReady(ready);
|
|
80
|
+
|
|
81
|
+
if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
|
|
82
|
+
const value = await RookSdk.getHealthConnectDiagnosticState();
|
|
83
|
+
return JSON.parse(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
|
|
87
|
+
const value = await RookSdk.getSamsungHealthDiagnosticState();
|
|
88
|
+
return JSON.parse(value);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
|
|
92
|
+
return RookSdk.getDiagnosticState();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
throw new Error('Check the datasource');
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
ready,
|
|
100
|
+
getUserID,
|
|
101
|
+
updateUserID,
|
|
102
|
+
removeUserFromRook,
|
|
103
|
+
syncUserTimeZone,
|
|
104
|
+
getDiagnosticState,
|
|
105
|
+
};
|
|
106
|
+
};
|