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.
Files changed (332) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +35 -3
  3. package/RNRookSdk.podspec +22 -0
  4. package/android/build.gradle +21 -40
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/AndroidManifest.xml +1 -2
  7. package/android/src/main/java/com/rooksdk/RookSdkModule.kt +1709 -117
  8. package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +26 -42
  9. package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +34 -37
  10. package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +8 -14
  11. package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +8 -16
  12. package/android/src/main/java/com/rooksdk/utils/{DatasourcesUtils.kt → DatasourceUtils.kt} +10 -9
  13. package/android/src/main/java/com/rooksdk/utils/{PermissionConversion.kt → PermissionConvertions.kt} +1 -1
  14. package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +0 -1
  15. package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +3 -0
  16. package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +1 -0
  17. package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +0 -1
  18. package/android/src/main/java/com/rooksdk/utils/serializers/ZoneDateTimeSerializer.kt +18 -0
  19. package/ios/DateHelper.swift +4 -4
  20. package/ios/Encodable.swift +25 -0
  21. package/ios/EncodableDataSource.swift +2 -3
  22. package/ios/EncodableDataSourceAuthorizer.swift +2 -3
  23. package/ios/EncodableSDKState.swift +3 -2
  24. package/ios/{EncodableHeartRate.swift → HearRateMapper.swift} +3 -3
  25. package/ios/NutritionMapper.swift +3 -3
  26. package/ios/RookBackground.swift +5 -8
  27. package/ios/RookConfiguration.swift +33 -30
  28. package/ios/{RookLocalData.swift → RookData.swift} +76 -69
  29. package/ios/RookEntry.swift +62 -0
  30. package/ios/RookPermissions.swift +36 -40
  31. package/ios/RookSdk-Bridging-Header.h +12 -0
  32. package/ios/RookSdk.h +3 -3
  33. package/ios/RookSdk.mm +390 -134
  34. package/ios/RookSources.swift +60 -54
  35. package/ios/RookSync.swift +48 -78
  36. package/ios/boost-boost_privacy-Bridging-Header.h +4 -0
  37. package/lib/{commonjs/types/AppleHealthPermissions.js → module/NativeRookSdk.js} +50 -6
  38. package/lib/module/NativeRookSdk.js.map +1 -0
  39. package/lib/module/context/RookSyncGateContext.js +2 -0
  40. package/lib/module/context/RookSyncGateContext.js.map +1 -1
  41. package/lib/module/context/RookSyncGateProvider.js +17 -18
  42. package/lib/module/context/RookSyncGateProvider.js.map +1 -1
  43. package/lib/module/context/RookSyncGateReducer.js +2 -0
  44. package/lib/module/context/RookSyncGateReducer.js.map +1 -1
  45. package/lib/module/context/RookSyncGateTypes.js +2 -0
  46. package/lib/module/hooks/useRookAPISources.js +10 -16
  47. package/lib/module/hooks/useRookAPISources.js.map +1 -1
  48. package/lib/module/hooks/useRookAndroidBackgroundSteps.js +11 -12
  49. package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
  50. package/lib/module/hooks/useRookAppleHealth.js +9 -10
  51. package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
  52. package/lib/module/hooks/useRookConfiguration.js +17 -22
  53. package/lib/module/hooks/useRookConfiguration.js.map +1 -1
  54. package/lib/module/hooks/useRookData.js +33 -38
  55. package/lib/module/hooks/useRookData.js.map +1 -1
  56. package/lib/module/hooks/useRookHealthConnect.js +9 -10
  57. package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
  58. package/lib/module/hooks/useRookPermissions.js +34 -45
  59. package/lib/module/hooks/useRookPermissions.js.map +1 -1
  60. package/lib/module/hooks/useRookSamsungHealth.js +8 -20
  61. package/lib/module/hooks/useRookSamsungHealth.js.map +1 -1
  62. package/lib/module/hooks/useRookSync.js +23 -32
  63. package/lib/module/hooks/useRookSync.js.map +1 -1
  64. package/lib/module/hooks/useRookVariables.js +26 -29
  65. package/lib/module/hooks/useRookVariables.js.map +1 -1
  66. package/lib/module/index.js +18 -10
  67. package/lib/module/index.js.map +1 -1
  68. package/lib/module/modules/components/RookStateManager.js +31 -0
  69. package/lib/module/modules/components/RookStateManager.js.map +1 -0
  70. package/lib/module/modules/hook/useRookAutoSync.js +24 -36
  71. package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
  72. package/lib/module/modules/hook/useRookEmitter.js +61 -0
  73. package/lib/module/modules/hook/useRookEmitter.js.map +1 -0
  74. package/lib/module/modules/types/sendMessageBroadcast.js +1 -1
  75. package/lib/module/modules/utils/errors.js +2 -0
  76. package/lib/module/modules/utils/errors.js.map +1 -1
  77. package/lib/module/package.json +1 -0
  78. package/lib/module/types/ActivityEvent.js +2 -0
  79. package/lib/module/types/AppleHealthNutritionEvent.js +2 -0
  80. package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -1
  81. package/lib/module/types/AppleHealthPermissions.js +2 -0
  82. package/lib/module/types/AppleHealthPermissions.js.map +1 -1
  83. package/lib/module/types/AuthorizedSources.js +2 -0
  84. package/lib/module/types/BodySummary.js +2 -0
  85. package/lib/module/types/DataSource.js +2 -0
  86. package/lib/module/types/DataSource.js.map +1 -1
  87. package/lib/module/types/HCMealData.js +3 -1
  88. package/lib/module/types/HCMealData.js.map +1 -1
  89. package/lib/module/types/HeartRateEvent.js +1 -1
  90. package/lib/module/types/PermissionsType.js +1 -1
  91. package/lib/module/types/PhysicalSummary.js +2 -0
  92. package/lib/module/types/Rook.js +2 -0
  93. package/lib/{commonjs/types/BodySummary.js.map → module/types/Rook.js.map} +1 -1
  94. package/lib/module/types/SDKSources.js +2 -0
  95. package/lib/module/types/SDKSources.js.map +1 -1
  96. package/lib/module/types/SamsungHealthPermissions.js +3 -0
  97. package/lib/module/types/SamsungHealthPermissions.js.map +1 -1
  98. package/lib/module/types/SleepSummary.js +2 -0
  99. package/lib/module/types/SummaryTypes.js +1 -1
  100. package/lib/module/types/SyncTypes.js +2 -0
  101. package/lib/module/types/SyncTypes.js.map +1 -1
  102. package/lib/module/types/WriteNutrition.js +2 -0
  103. package/lib/module/types/WriteNutrition.js.map +1 -1
  104. package/lib/module/utils/isModuleReady.js +2 -0
  105. package/lib/module/utils/isModuleReady.js.map +1 -1
  106. package/lib/module/utils/isRunningOnAndroid.js +2 -0
  107. package/lib/module/utils/isRunningOnAndroid.js.map +1 -1
  108. package/lib/module/utils/isRunningOniOS.js +2 -0
  109. package/lib/module/utils/isRunningOniOS.js.map +1 -1
  110. package/lib/module/utils/isValidDate.js +2 -0
  111. package/lib/module/utils/isValidDate.js.map +1 -1
  112. package/lib/typescript/package.json +1 -0
  113. package/lib/typescript/src/NativeRookSdk.d.ts +705 -0
  114. package/lib/typescript/src/NativeRookSdk.d.ts.map +1 -0
  115. package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -1
  116. package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
  117. package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -1
  118. package/lib/typescript/src/hooks/useRookAPISources.d.ts.map +1 -1
  119. package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
  120. package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
  121. package/lib/typescript/src/hooks/useRookConfiguration.d.ts +1 -1
  122. package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
  123. package/lib/typescript/src/hooks/useRookData.d.ts +1 -1
  124. package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -1
  125. package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -1
  126. package/lib/typescript/src/hooks/useRookPermissions.d.ts +1 -1
  127. package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
  128. package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +0 -6
  129. package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts.map +1 -1
  130. package/lib/typescript/src/hooks/useRookSync.d.ts.map +1 -1
  131. package/lib/typescript/src/hooks/useRookVariables.d.ts +1 -1
  132. package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
  133. package/lib/typescript/src/index.d.ts +17 -8
  134. package/lib/typescript/src/index.d.ts.map +1 -1
  135. package/lib/typescript/src/modules/components/RookStateManager.d.ts +10 -0
  136. package/lib/typescript/src/modules/components/RookStateManager.d.ts.map +1 -0
  137. package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
  138. package/lib/typescript/src/modules/hook/useRookEmitter.d.ts +4 -0
  139. package/lib/typescript/src/modules/hook/useRookEmitter.d.ts.map +1 -0
  140. package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -1
  141. package/lib/typescript/src/types/AuthorizedSources.d.ts +11 -0
  142. package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
  143. package/lib/typescript/src/types/HCMealData.d.ts.map +1 -1
  144. package/lib/typescript/src/types/HeartRateEvent.d.ts +2 -2
  145. package/lib/typescript/src/types/HeartRateEvent.d.ts.map +1 -1
  146. package/lib/typescript/src/types/Rook.d.ts +9 -0
  147. package/lib/typescript/src/types/Rook.d.ts.map +1 -0
  148. package/lib/typescript/src/types/SamsungHealthPermissions.d.ts +1 -0
  149. package/lib/typescript/src/types/SamsungHealthPermissions.d.ts.map +1 -1
  150. package/lib/typescript/src/types/SyncTypes.d.ts +5 -1
  151. package/lib/typescript/src/types/SyncTypes.d.ts.map +1 -1
  152. package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
  153. package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
  154. package/package.json +94 -98
  155. package/src/NativeRookSdk.ts +839 -0
  156. package/{lib/commonjs/context/RookSyncGateContext.js → src/context/RookSyncGateContext.ts} +10 -13
  157. package/src/context/RookSyncGateProvider.tsx +82 -0
  158. package/{lib/commonjs/context/RookSyncGateReducer.js → src/context/RookSyncGateReducer.ts} +14 -41
  159. package/src/context/RookSyncGateTypes.ts +40 -0
  160. package/{lib/commonjs/hooks/useRookAPISources.js → src/hooks/useRookAPISources.ts} +40 -36
  161. package/src/hooks/useRookAndroidBackgroundSteps.ts +81 -0
  162. package/src/hooks/useRookAppleHealth.ts +55 -0
  163. package/src/hooks/useRookConfiguration.ts +106 -0
  164. package/src/hooks/useRookData.ts +133 -0
  165. package/src/hooks/useRookHealthConnect.ts +59 -0
  166. package/src/hooks/useRookPermissions.ts +240 -0
  167. package/src/hooks/useRookSamsungHealth.ts +37 -0
  168. package/src/hooks/useRookSync.ts +157 -0
  169. package/src/hooks/useRookVariables.ts +98 -0
  170. package/src/index.tsx +28 -0
  171. package/src/modules/components/RookStateManager.tsx +41 -0
  172. package/{lib/commonjs/modules/hook/useRookAutoSync.js → src/modules/hook/useRookAutoSync.ts} +141 -95
  173. package/src/modules/hook/useRookEmitter.ts +94 -0
  174. package/src/modules/types/sendMessageBroadcast.ts +5 -0
  175. package/src/modules/utils/errors.ts +9 -0
  176. package/src/types/ActivityEvent.ts +159 -0
  177. package/src/types/AppleHealthNutritionEvent.ts +142 -0
  178. package/src/types/AppleHealthPermissions.ts +49 -0
  179. package/src/types/AuthorizedSources.ts +33 -0
  180. package/src/types/BodySummary.ts +116 -0
  181. package/src/types/DataSource.ts +16 -0
  182. package/{lib/commonjs/types/HCMealData.js → src/types/HCMealData.ts} +60 -11
  183. package/src/types/HeartRateEvent.ts +26 -0
  184. package/src/types/PermissionsType.ts +9 -0
  185. package/src/types/PhysicalSummary.ts +84 -0
  186. package/src/types/Rook.ts +8 -0
  187. package/src/types/SDKSources.ts +5 -0
  188. package/src/types/SamsungHealthPermissions.ts +16 -0
  189. package/src/types/SleepSummary.ts +66 -0
  190. package/src/types/SummaryTypes.ts +70 -0
  191. package/src/types/SyncTypes.ts +63 -0
  192. package/src/types/WriteNutrition.ts +66 -0
  193. package/{lib/commonjs/utils/isModuleReady.js → src/utils/isModuleReady.ts} +4 -10
  194. package/src/utils/isRunningOnAndroid.ts +10 -0
  195. package/src/utils/isRunningOniOS.ts +10 -0
  196. package/{lib/commonjs/utils/isValidDate.js → src/utils/isValidDate.ts} +12 -14
  197. package/android/src/main/AndroidManifestNew.xml +0 -36
  198. package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +0 -99
  199. package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +0 -182
  200. package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +0 -301
  201. package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +0 -359
  202. package/android/src/main/java/com/rooksdk/modules/RookSourcesModule.kt +0 -102
  203. package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +0 -119
  204. package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +0 -551
  205. package/android/src/main/res/drawable/ic_health_connect.xml +0 -19
  206. package/android/src/main/res/values/themes.xml +0 -3
  207. package/ios/EncodableRookDataSource.swift +0 -36
  208. package/ios/EncodableStatusDataSources.swift +0 -47
  209. package/ios/RookBackgroundModule.h +0 -5
  210. package/ios/RookBackgroundModule.mm +0 -15
  211. package/ios/RookConfigurationModule.h +0 -5
  212. package/ios/RookConfigurationModule.mm +0 -22
  213. package/ios/RookExternalModule.h +0 -5
  214. package/ios/RookExternalModule.m +0 -31
  215. package/ios/RookPermissionsModule.h +0 -5
  216. package/ios/RookPermissionsModule.mm +0 -20
  217. package/ios/RookSourcesModule.h +0 -5
  218. package/ios/RookSourcesModule.mm +0 -18
  219. package/ios/RookSync.h +0 -5
  220. package/ios/RookSync.m +0 -35
  221. package/ios/SwiftTest.swift +0 -18
  222. package/ios/react-native-rook-sdk-Bridging-Header.h +0 -12
  223. package/lib/commonjs/context/RookSyncGateContext.js.map +0 -1
  224. package/lib/commonjs/context/RookSyncGateProvider.js +0 -108
  225. package/lib/commonjs/context/RookSyncGateProvider.js.map +0 -1
  226. package/lib/commonjs/context/RookSyncGateReducer.js.map +0 -1
  227. package/lib/commonjs/context/RookSyncGateTypes.js +0 -6
  228. package/lib/commonjs/context/RookSyncGateTypes.js.map +0 -1
  229. package/lib/commonjs/context/index.js +0 -14
  230. package/lib/commonjs/context/index.js.map +0 -1
  231. package/lib/commonjs/hooks/index.js +0 -76
  232. package/lib/commonjs/hooks/index.js.map +0 -1
  233. package/lib/commonjs/hooks/useRookAPISources.js.map +0 -1
  234. package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +0 -88
  235. package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +0 -1
  236. package/lib/commonjs/hooks/useRookAppleHealth.js +0 -63
  237. package/lib/commonjs/hooks/useRookAppleHealth.js.map +0 -1
  238. package/lib/commonjs/hooks/useRookConfiguration.js +0 -113
  239. package/lib/commonjs/hooks/useRookConfiguration.js.map +0 -1
  240. package/lib/commonjs/hooks/useRookData.js +0 -116
  241. package/lib/commonjs/hooks/useRookData.js.map +0 -1
  242. package/lib/commonjs/hooks/useRookHealthConnect.js +0 -70
  243. package/lib/commonjs/hooks/useRookHealthConnect.js.map +0 -1
  244. package/lib/commonjs/hooks/useRookPermissions.js +0 -211
  245. package/lib/commonjs/hooks/useRookPermissions.js.map +0 -1
  246. package/lib/commonjs/hooks/useRookSamsungHealth.js +0 -54
  247. package/lib/commonjs/hooks/useRookSamsungHealth.js.map +0 -1
  248. package/lib/commonjs/hooks/useRookSync.js +0 -148
  249. package/lib/commonjs/hooks/useRookSync.js.map +0 -1
  250. package/lib/commonjs/hooks/useRookVariables.js +0 -93
  251. package/lib/commonjs/hooks/useRookVariables.js.map +0 -1
  252. package/lib/commonjs/index.js +0 -121
  253. package/lib/commonjs/index.js.map +0 -1
  254. package/lib/commonjs/modules/hook/useRookAutoSync.js.map +0 -1
  255. package/lib/commonjs/modules/types/sendMessageBroadcast.js +0 -2
  256. package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +0 -1
  257. package/lib/commonjs/modules/utils/errors.js +0 -12
  258. package/lib/commonjs/modules/utils/errors.js.map +0 -1
  259. package/lib/commonjs/types/ActivityEvent.js +0 -6
  260. package/lib/commonjs/types/ActivityEvent.js.map +0 -1
  261. package/lib/commonjs/types/AppleHealthNutritionEvent.js +0 -77
  262. package/lib/commonjs/types/AppleHealthNutritionEvent.js.map +0 -1
  263. package/lib/commonjs/types/AppleHealthPermissions.js.map +0 -1
  264. package/lib/commonjs/types/AuthorizedSources.js +0 -6
  265. package/lib/commonjs/types/AuthorizedSources.js.map +0 -1
  266. package/lib/commonjs/types/BodySummary.js +0 -6
  267. package/lib/commonjs/types/DataSource.js +0 -16
  268. package/lib/commonjs/types/DataSource.js.map +0 -1
  269. package/lib/commonjs/types/DiagnosticState.js +0 -2
  270. package/lib/commonjs/types/DiagnosticState.js.map +0 -1
  271. package/lib/commonjs/types/HCMealData.js.map +0 -1
  272. package/lib/commonjs/types/HeartRateEvent.js +0 -2
  273. package/lib/commonjs/types/HeartRateEvent.js.map +0 -1
  274. package/lib/commonjs/types/PermissionsType.js +0 -2
  275. package/lib/commonjs/types/PermissionsType.js.map +0 -1
  276. package/lib/commonjs/types/PhysicalSummary.js +0 -6
  277. package/lib/commonjs/types/PhysicalSummary.js.map +0 -1
  278. package/lib/commonjs/types/SDKSources.js +0 -13
  279. package/lib/commonjs/types/SDKSources.js.map +0 -1
  280. package/lib/commonjs/types/SamsungHealthPermissions.js +0 -23
  281. package/lib/commonjs/types/SamsungHealthPermissions.js.map +0 -1
  282. package/lib/commonjs/types/SleepSummary.js +0 -6
  283. package/lib/commonjs/types/SleepSummary.js.map +0 -1
  284. package/lib/commonjs/types/SummaryTypes.js +0 -2
  285. package/lib/commonjs/types/SummaryTypes.js.map +0 -1
  286. package/lib/commonjs/types/SyncTypes.js +0 -33
  287. package/lib/commonjs/types/SyncTypes.js.map +0 -1
  288. package/lib/commonjs/types/WriteNutrition.js +0 -18
  289. package/lib/commonjs/types/WriteNutrition.js.map +0 -1
  290. package/lib/commonjs/utils/getNativeModule.js +0 -29
  291. package/lib/commonjs/utils/getNativeModule.js.map +0 -1
  292. package/lib/commonjs/utils/getRookModule.js +0 -28
  293. package/lib/commonjs/utils/getRookModule.js.map +0 -1
  294. package/lib/commonjs/utils/isModuleReady.js.map +0 -1
  295. package/lib/commonjs/utils/isRunningOnAndroid.js +0 -15
  296. package/lib/commonjs/utils/isRunningOnAndroid.js.map +0 -1
  297. package/lib/commonjs/utils/isRunningOniOS.js +0 -15
  298. package/lib/commonjs/utils/isRunningOniOS.js.map +0 -1
  299. package/lib/commonjs/utils/isValidDate.js.map +0 -1
  300. package/lib/commonjs/utils/nativeModules.js +0 -29
  301. package/lib/commonjs/utils/nativeModules.js.map +0 -1
  302. package/lib/commonjs/utils/packageInfo.js +0 -13
  303. package/lib/commonjs/utils/packageInfo.js.map +0 -1
  304. package/lib/module/context/index.js +0 -2
  305. package/lib/module/context/index.js.map +0 -1
  306. package/lib/module/hooks/index.js +0 -11
  307. package/lib/module/hooks/index.js.map +0 -1
  308. package/lib/module/types/DiagnosticState.js +0 -2
  309. package/lib/module/types/DiagnosticState.js.map +0 -1
  310. package/lib/module/utils/getNativeModule.js +0 -23
  311. package/lib/module/utils/getNativeModule.js.map +0 -1
  312. package/lib/module/utils/getRookModule.js +0 -22
  313. package/lib/module/utils/getRookModule.js.map +0 -1
  314. package/lib/module/utils/nativeModules.js +0 -23
  315. package/lib/module/utils/nativeModules.js.map +0 -1
  316. package/lib/module/utils/packageInfo.js +0 -7
  317. package/lib/module/utils/packageInfo.js.map +0 -1
  318. package/lib/typescript/src/context/index.d.ts +0 -2
  319. package/lib/typescript/src/context/index.d.ts.map +0 -1
  320. package/lib/typescript/src/hooks/index.d.ts +0 -11
  321. package/lib/typescript/src/hooks/index.d.ts.map +0 -1
  322. package/lib/typescript/src/types/DiagnosticState.d.ts +0 -13
  323. package/lib/typescript/src/types/DiagnosticState.d.ts.map +0 -1
  324. package/lib/typescript/src/utils/getNativeModule.d.ts +0 -10
  325. package/lib/typescript/src/utils/getNativeModule.d.ts.map +0 -1
  326. package/lib/typescript/src/utils/getRookModule.d.ts +0 -9
  327. package/lib/typescript/src/utils/getRookModule.d.ts.map +0 -1
  328. package/lib/typescript/src/utils/nativeModules.d.ts +0 -24
  329. package/lib/typescript/src/utils/nativeModules.d.ts.map +0 -1
  330. package/lib/typescript/src/utils/packageInfo.d.ts +0 -6
  331. package/lib/typescript/src/utils/packageInfo.d.ts.map +0 -1
  332. package/react-native-rook-sdk.podspec +0 -45
@@ -0,0 +1,98 @@
1
+ import RookSdk, { type HeartRateData } from '../NativeRookSdk';
2
+ import { Platform } from 'react-native';
3
+ import { isModuleReady } from '../utils/isModuleReady';
4
+ import { useRookSyncGateContext } from '../context/RookSyncGateContext';
5
+ import { SDKDataSource } from '../types/SDKSources';
6
+
7
+ export type Calories = {
8
+ active: number;
9
+ basal: number;
10
+ };
11
+
12
+ /**
13
+ * The `useRookVariables` hook returns an object with a `ready` boolean and an
14
+ * asynchronous function `getTodaySteps` that retrieves the number of steps taken today.
15
+ * @returns The `useRookVariable` hook is returning an object with two properties:
16
+ * 1. `ready`: This property is coming from the `useRookSyncGateContext` hook and represents the state
17
+ * of readiness.
18
+ * 2. `getTodaySteps`: This property is a function that retrieves the number of steps taken today
19
+ * asynchronously and returns a Promise<string> representing the number of steps taken today.
20
+ * 3. `getTodayCalories`: This property is a function that retrieves the number of calories burned today
21
+ * asynchronously and returns a Promise<string> representing the number of calories burned today.
22
+ */
23
+ export const useRookVariables = () => {
24
+ const {
25
+ state: { ready },
26
+ } = useRookSyncGateContext();
27
+
28
+ /**
29
+ * The function `getTodaySteps` retrieves the number of steps taken today asynchronously.
30
+ * @returns The function `getTodaySteps` is returning a string representing the number of steps taken today.
31
+ */
32
+ const getTodaySteps = async (source: SDKDataSource): Promise<string> => {
33
+ isModuleReady(ready);
34
+
35
+ if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
36
+ return RookSdk.syncTodayHealthConnectStepsCount();
37
+ }
38
+
39
+ if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
40
+ return RookSdk.syncTodaySamsungHealthStepsCount();
41
+ }
42
+
43
+ if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
44
+ return RookSdk.getTodayAppleHealthSteps();
45
+ }
46
+
47
+ throw new Error('Invalid SDK datasource');
48
+ };
49
+
50
+ /**
51
+ * The function `syncTodayCaloriesCount` retrieves the number of calories burned today asynchronously as string
52
+ * @returns The function `syncTodayCaloriesCount` is returning the result of calling
53
+ */
54
+ const getTodayCalories = async (source: SDKDataSource): Promise<Calories> => {
55
+ isModuleReady(ready);
56
+
57
+ if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
58
+ return RookSdk.syncTodayCaloriesCount();
59
+ }
60
+
61
+ if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
62
+ return RookSdk.syncSHTodayCaloriesCount();
63
+ }
64
+
65
+ if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
66
+ return RookSdk.syncTodayCaloriesCount();
67
+ }
68
+
69
+ throw new Error('Invalid SDK datasource');
70
+ };
71
+
72
+ const getTodayHeartRate = async (
73
+ source: SDKDataSource
74
+ ): Promise<HeartRateData> => {
75
+ if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
76
+ const result = await RookSdk.getTodayHeartRate();
77
+ return JSON.parse(result as unknown as string);
78
+ }
79
+
80
+ if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
81
+ const result = await RookSdk.getSHTodayHeartRate();
82
+ return JSON.parse(result as unknown as string);
83
+ }
84
+
85
+ if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
86
+ return RookSdk.getTodayHeartRate();
87
+ }
88
+
89
+ throw new Error('Please check the data source');
90
+ };
91
+
92
+ return {
93
+ ready,
94
+ getTodaySteps,
95
+ getTodayCalories,
96
+ getTodayHeartRate,
97
+ };
98
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,28 @@
1
+ export { default as RookSdk } from './NativeRookSdk';
2
+
3
+ export { default as RookSyncGate } from './context/RookSyncGateProvider';
4
+
5
+ export { useRookAPISources } from './hooks/useRookAPISources';
6
+ export { useRookAppleHealth } from './hooks/useRookAppleHealth';
7
+ export { useRookConfiguration } from './hooks/useRookConfiguration';
8
+ export { useRookPermissions } from './hooks/useRookPermissions';
9
+ export { useRookData } from './hooks/useRookData';
10
+ export { useRookAndroidBackgroundSteps } from './hooks/useRookAndroidBackgroundSteps';
11
+ export { useRookHealthConnect } from './hooks/useRookHealthConnect';
12
+ export { useRookSamsungHealth } from './hooks/useRookSamsungHealth';
13
+ export { useRookVariables } from './hooks/useRookVariables';
14
+ export { useRookSync } from './hooks/useRookSync';
15
+
16
+ export { APIDataSource } from './types/DataSource';
17
+ export { SDKDataSource } from './types/SDKSources';
18
+ export { AppleHealthPermission } from './types/AppleHealthPermissions';
19
+ export { type SamsungHealthPermission } from './types/SamsungHealthPermissions';
20
+ export { type PhysicalSummary } from './types/PhysicalSummary';
21
+ export { type BodySummary } from './types/BodySummary';
22
+ export { type SleepSummary } from './types/SleepSummary';
23
+ export {
24
+ SharedHealthEvents,
25
+ UniqueAppleHealthEvents,
26
+ UniqueSamsungHealthEvents,
27
+ UniqueHealthConnectEvents,
28
+ } from './types/SyncTypes';
@@ -0,0 +1,41 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ import { useEffect, useRef, type FC } from 'react';
3
+ import { AppState, type AppStateStatus } from 'react-native';
4
+ import type { RookSyncGateState } from '../../context/RookSyncGateTypes';
5
+ import { useRookPermissionEmitter } from '../hook/useRookEmitter';
6
+ import { useRookAutoSync } from '../hook/useRookAutoSync';
7
+
8
+ type Props = {
9
+ state: RookSyncGateState;
10
+ enableBackground: boolean;
11
+ enableLogs: boolean;
12
+ };
13
+
14
+ export const RookStateManager: FC<Props> = (props) => {
15
+ const { checkAndroidPermissions } = useRookPermissionEmitter();
16
+ const { startBackgroundServices } = useRookAutoSync(props);
17
+ const appState = useRef(AppState.currentState);
18
+
19
+ useEffect(() => {
20
+ const subscription = AppState.addEventListener(
21
+ 'change',
22
+ (nextAppState: AppStateStatus) => {
23
+ if (
24
+ appState.current?.match(/inactive|background/) &&
25
+ nextAppState === 'active'
26
+ ) {
27
+ checkAndroidPermissions();
28
+ startBackgroundServices();
29
+ }
30
+
31
+ appState.current = nextAppState;
32
+ }
33
+ );
34
+
35
+ return () => {
36
+ subscription.remove();
37
+ };
38
+ }, [checkAndroidPermissions]);
39
+
40
+ return <></>;
41
+ };
@@ -1,16 +1,17 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRookAutoSync = void 0;
7
- var _react = require("react");
8
- var _reactNative = require("react-native");
9
- var _errors = require("../utils/errors");
10
- var _getNativeModule = _interopRequireDefault(require("../../utils/getNativeModule"));
11
- var _nativeModules = _interopRequireDefault(require("../../utils/nativeModules"));
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
1
  /* eslint-disable react-hooks/exhaustive-deps */
2
+ import RookSdk from '../../NativeRookSdk';
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { AppState, Platform } from 'react-native';
5
+ import type { RookSyncGateState } from '../../context/RookSyncGateTypes';
6
+ import { errors } from '../utils/errors';
7
+ import type { Message } from '../types/sendMessageBroadcast';
8
+ import { AppleHealthPermission } from '../../types/AppleHealthPermissions';
9
+
10
+ type StartBackgroundSync = {
11
+ state: RookSyncGateState;
12
+ enableBackground: boolean;
13
+ enableLogs: boolean;
14
+ };
14
15
 
15
16
  const MESSAGE_TYPE = 'ROOK_BACKGROUND_ENABLED';
16
17
 
@@ -30,119 +31,149 @@ const MESSAGE_TYPE = 'ROOK_BACKGROUND_ENABLED';
30
31
  * is ready, the permissions status, and the user ID associated with the state. This state is used to
31
32
  * determine when to start the
32
33
  */
33
- const useRookAutoSync = ({
34
+ export const useRookAutoSync = ({
34
35
  enableBackground,
35
36
  enableLogs,
36
- state
37
- }) => {
38
- const appState = (0, _react.useRef)(_reactNative.AppState.currentState);
39
- const [changeAppState, setChangeState] = (0, _react.useState)(0);
40
- (0, _react.useEffect)(() => {
37
+ state,
38
+ }: StartBackgroundSync) => {
39
+ const appState = useRef(AppState.currentState);
40
+ const [changeAppState, setChangeState] = useState(0);
41
+
42
+ useEffect(() => {
41
43
  if (!enableBackground) return;
42
- const subscription = _reactNative.AppState.addEventListener('change', nextAppState => {
44
+
45
+ const subscription = AppState.addEventListener('change', (nextAppState) => {
43
46
  if (
44
- // Check previous state to check if he app was inactive or in background
45
- // and then pass to be active
46
- appState.current.match(/inactive|background/) && nextAppState === 'active') {
47
- setChangeState(prev => prev + 1);
47
+ // Check previous state to check if he app was inactive or in background
48
+ // and then pass to be active
49
+ appState.current?.match(/inactive|background/) &&
50
+ nextAppState === 'active'
51
+ ) {
52
+ setChangeState((prev) => prev + 1);
48
53
  }
54
+
49
55
  appState.current = nextAppState;
50
56
  });
57
+
51
58
  return () => {
52
59
  subscription.remove();
53
60
  };
54
61
  }, []);
55
- (0, _react.useEffect)(() => {
62
+
63
+ useEffect(() => {
56
64
  if (!state.ready || !enableBackground) return;
65
+
57
66
  startBackgroundServices();
58
67
  }, [state, changeAppState]);
68
+
59
69
  const startBackgroundServices = () => {
60
- const {
61
- clientUUID,
62
- secret,
63
- ready
64
- } = state;
70
+ const { clientUUID, secret, ready } = state;
71
+
72
+ if (!enableBackground) return;
73
+
65
74
  if (!ready || !clientUUID || !secret) {
66
75
  return;
67
76
  }
68
- if (_reactNative.Platform.OS === 'android') {
77
+
78
+ if (Platform.OS === 'android') {
69
79
  startAndroidBackgroundSync();
70
80
  return;
71
81
  }
82
+
72
83
  startIOSBackgroundSync();
73
84
  };
74
- const isValidUser = async () => {
85
+
86
+ const isValidUser = async (): Promise<boolean> => {
75
87
  try {
76
- const rookModule = (0, _getNativeModule.default)(_nativeModules.default.android.CONFIGURATION);
77
- const userID = await rookModule.getUserID();
88
+ const userID = await RookSdk.getUserID();
89
+
78
90
  if (userID) return true;
79
- if (enableLogs) console.error(_errors.errors.noUserIDAndroidBackground);
80
- throw new Error(_errors.errors.noUserIDAndroidBackground);
91
+
92
+ if (enableLogs) console.error(errors.noUserIDAndroidBackground);
93
+
94
+ throw new Error(errors.noUserIDAndroidBackground);
81
95
  } catch (error) {
82
96
  sendMessageToBroadcast({
83
97
  type: 'ROOK_BACKGROUND_ENABLED',
84
- message: 'There is not a user id',
85
- value: false
98
+ message: (error as any).message || 'There is not a user id',
99
+ value: false,
86
100
  });
101
+
87
102
  return false;
88
103
  }
89
104
  };
90
- const tryToStartBackgroundSync = async () => {
105
+
106
+ const tryToStartBackgroundSync = async (): Promise<boolean> => {
91
107
  try {
92
- const rookPermissions = (0, _getNativeModule.default)(_nativeModules.default.android.PERMISSIONS);
93
- const backgroundStatus = await rookPermissions.checkHealthConnectPermissionsPartially();
94
- if (!backgroundStatus) throw new Error('No permission granted or not available');
95
- const rookBackground = (0, _getNativeModule.default)(_nativeModules.default.android.BACKGROUND);
96
- const result = await rookBackground.scheduleBackgroundSync(enableLogs);
108
+ const backgroundStatus =
109
+ await RookSdk.checkHealthConnectBackgroundReadStatus();
110
+
111
+ if (backgroundStatus !== 'PERMISSION_GRANTED')
112
+ throw new Error('No permission granted or not available');
113
+
114
+ const result = await RookSdk.scheduleBackgroundSync(enableLogs);
115
+
97
116
  return result;
98
117
  } catch (error) {
99
- console.log(error);
100
118
  sendMessageToBroadcast({
101
119
  type: 'ROOK_BACKGROUND_ENABLED',
102
- message: 'Health Connect background is not available on the device or the user does not grants permission',
103
- value: false
120
+ message:
121
+ (error as any).message ||
122
+ 'Health Connect background is not available on the device or the user does not grants permission',
123
+ value: false,
104
124
  });
125
+
105
126
  return false;
106
127
  }
107
128
  };
108
- const tryToStartForegroundSync = async () => {
129
+
130
+ const tryToStartForegroundSync = async (): Promise<boolean> => {
109
131
  try {
110
- const rookPermissionsModule = (0, _getNativeModule.default)(_nativeModules.default.android.PERMISSIONS);
111
- const hasHCPermissions = await rookPermissionsModule.checkHealthConnectPermissions();
112
- const hasAndroidPermissions = await rookPermissionsModule.hasAndroidBackgroundPermissions();
132
+ const hasHCPermissions =
133
+ await RookSdk.healthConnectHasPartialPermissions();
134
+ const hasAndroidPermissions =
135
+ await RookSdk.androidHasBackgroundPermissions();
136
+
113
137
  if (!hasHCPermissions || !hasAndroidPermissions) {
114
- if (enableLogs) console.error(_errors.errors.autoStartAndroidBackgroundSync);
115
- throw new Error(_errors.errors.autoStartAndroidBackgroundSync);
138
+ if (enableLogs) console.error(errors.autoStartAndroidBackgroundSync);
139
+
140
+ throw new Error(errors.autoStartAndroidBackgroundSync);
116
141
  }
117
- const rookStepsModule = (0, _getNativeModule.default)(_nativeModules.default.android.STEPS);
118
- if (_reactNative.AppState.currentState === 'active' && appState.current === 'active') {
119
- await rookStepsModule.enableBackgroundAndroidSteps();
142
+
143
+ if (AppState.currentState === 'active' && appState.current === 'active') {
144
+ await RookSdk.enableBackgroundAndroidSteps();
145
+
120
146
  return true;
121
147
  }
148
+
122
149
  return false;
123
150
  } catch (error) {
124
151
  sendMessageToBroadcast({
125
152
  type: 'ROOK_BACKGROUND_ENABLED',
126
153
  value: false,
127
- message: error.message
154
+ message: (error as Error).message,
128
155
  });
156
+
129
157
  return false;
130
158
  }
131
159
  };
132
- const tryToStartSamsungHealthSync = async () => {
160
+
161
+ const tryToStartSamsungHealthSync = async (): Promise<boolean> => {
133
162
  try {
134
- const rookPermissionsModule = (0, _getNativeModule.default)(_nativeModules.default.android.PERMISSIONS);
135
- const isAvailable = await rookPermissionsModule.checkSamsungAvailability();
163
+ const isAvailable = await RookSdk.checkSamsungAvailability();
164
+
136
165
  if (isAvailable !== 'INSTALLED') return false;
137
- const rookSyncModule = (0, _getNativeModule.default)(_nativeModules.default.android.SYNC);
138
- await rookSyncModule.enableSamsungSync();
166
+
167
+ await RookSdk.enableSamsungSync();
168
+
139
169
  return true;
140
170
  } catch (error) {
141
171
  sendMessageToBroadcast({
142
172
  type: 'ROOK_BACKGROUND_ENABLED',
143
173
  value: false,
144
- message: error.message
174
+ message: (error as Error).message,
145
175
  });
176
+
146
177
  return false;
147
178
  }
148
179
  };
@@ -155,37 +186,45 @@ const useRookAutoSync = ({
155
186
  * broadcast with `value` set to `false` and an error message is logged.
156
187
  */
157
188
  const startAndroidBackgroundSync = async () => {
158
- const {
159
- clientUUID,
160
- secret,
161
- ready
162
- } = state;
189
+ const { clientUUID, secret, ready } = state;
190
+
163
191
  if (!ready || !clientUUID || !secret) {
164
192
  return;
165
193
  }
194
+
166
195
  try {
167
196
  const enabledSources = [];
197
+
168
198
  const isValid = await isValidUser();
169
199
  if (!isValid) return;
200
+
170
201
  const isSamsungEnabled = await tryToStartSamsungHealthSync();
171
202
  const isEnabled = await tryToStartBackgroundSync();
203
+
172
204
  if (isSamsungEnabled) enabledSources.push('Samsung Health');
173
205
  if (isEnabled) enabledSources.push('Health Connect');
206
+
174
207
  if (!isEnabled) {
175
208
  const isForegroundEnabled = await tryToStartForegroundSync();
176
- if (!isForegroundEnabled && !isSamsungEnabled) throw new Error("We couldn't start background sync");
209
+
210
+ if (!isForegroundEnabled && !isSamsungEnabled)
211
+ throw new Error("We couldn't start background sync");
212
+
177
213
  if (isForegroundEnabled) enabledSources.push('Foreground Service');
178
214
  }
215
+
179
216
  sendMessageToBroadcast({
180
217
  type: 'ROOK_BACKGROUND_ENABLED',
181
218
  value: true,
182
- message: `via: ${enabledSources.join(', ')}`
219
+ message: `via: ${enabledSources.join(', ')}`,
183
220
  });
221
+
184
222
  if (enableLogs) console.log('ROOK - Background enabled successfully');
185
223
  } catch (error) {
186
224
  sendMessageToBroadcast({
187
225
  type: 'ROOK_BACKGROUND_ENABLED',
188
- value: false
226
+ message: (error as any).message,
227
+ value: false,
189
228
  });
190
229
  }
191
230
  };
@@ -199,44 +238,56 @@ const useRookAutoSync = ({
199
238
  */
200
239
  const startIOSBackgroundSync = async () => {
201
240
  try {
202
- const rookPermissions = (0, _getNativeModule.default)(_nativeModules.default.ios.PERMISSIONS);
203
- const rookBackground = (0, _getNativeModule.default)(_nativeModules.default.ios.BACKGROUND);
204
- const rookConfigModule = (0, _getNativeModule.default)(_nativeModules.default.ios.CONFIGURATION);
205
- const rookSync = (0, _getNativeModule.default)(_nativeModules.default.ios.SYNC);
206
- const userID = await rookConfigModule.getUserID();
241
+ const userID = await RookSdk.getUserID();
242
+
207
243
  if (!userID) {
208
- if (enableLogs) console.error(_errors.errors.noUserIDAndroidBackground);
244
+ if (enableLogs) console.error(errors.noUserIDAndroidBackground);
245
+
209
246
  sendMessageToBroadcast({
210
247
  type: MESSAGE_TYPE,
211
248
  value: false,
212
- message: _errors.errors.noUserIDAndroidBackground
249
+ message: errors.noUserIDAndroidBackground,
213
250
  });
251
+
214
252
  return;
215
253
  }
216
- const status = await rookPermissions.checkPermissionsStatus(null);
217
- if (status === 'PERMISSION_NOT_REQUESTED') throw new Error('Permissions required');
218
- await rookBackground.enableBackGroundUpdates();
219
- rookSync.sync(() => {
254
+
255
+ const status = await RookSdk.appleHealthHasPermissions(
256
+ AppleHealthPermission.STEP_COUNT
257
+ );
258
+
259
+ if (status === 'PERMISSION_NOT_REQUESTED')
260
+ throw new Error('Permissions required');
261
+
262
+ await RookSdk.enableBackGroundUpdates();
263
+
264
+ RookSdk.sync(() => {
220
265
  sendMessageToBroadcast({
221
266
  type: MESSAGE_TYPE,
222
267
  value: true,
223
- message: 'Some data has already uploaded'
268
+ message: 'Some data has already uploaded',
224
269
  });
225
270
  });
271
+
226
272
  sendMessageToBroadcast({
227
273
  type: MESSAGE_TYPE,
228
- value: true
274
+ value: true,
229
275
  });
276
+
230
277
  if (enableLogs) console.log('ROOK - Background enabled successfully');
231
278
  } catch (err) {
232
- const error = err;
279
+ const error = err as any;
280
+
233
281
  sendMessageToBroadcast({
234
282
  type: MESSAGE_TYPE,
235
283
  value: false,
236
- message: _errors.errors.autoStartIOSBackgroundSync
284
+ message: errors.autoStartIOSBackgroundSync,
237
285
  });
286
+
238
287
  if (enableLogs) {
239
- if (error.message && error.message.includes('emptyUserId')) console.error(_errors.errors.noUserIDAndroidBackground);else console.error(_errors.errors.autoStartIOSBackgroundSync);
288
+ if (error.message && (error.message as string).includes('emptyUserId'))
289
+ console.error(errors.noUserIDAndroidBackground);
290
+ else console.error(errors.autoStartIOSBackgroundSync);
240
291
  }
241
292
  }
242
293
  };
@@ -246,16 +297,11 @@ const useRookAutoSync = ({
246
297
  * @param {Message} message - The `message` parameter is of type `Message`, which is likely an object
247
298
  * containing information to be sent as a broadcast message.
248
299
  */
249
- const sendMessageToBroadcast = message => {
250
- const rookSyncModule = (0, _getNativeModule.default)(_reactNative.Platform.select({
251
- android: () => _nativeModules.default.android.MAIN,
252
- default: () => _nativeModules.default.ios.MAIN
253
- })());
254
- rookSyncModule.sendMessageToBroadcast(message).then().catch();
300
+ const sendMessageToBroadcast = (message: Message): void => {
301
+ RookSdk.sendMessage(message);
255
302
  };
303
+
256
304
  return {
257
- startBackgroundServices
305
+ startBackgroundServices,
258
306
  };
259
307
  };
260
- exports.useRookAutoSync = useRookAutoSync;
261
- //# sourceMappingURL=useRookAutoSync.js.map
@@ -0,0 +1,94 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ import { useRef, useCallback } from 'react';
3
+ import RookSdk, { type BackgroundStatus } from '../../NativeRookSdk';
4
+
5
+ const PERM_KEYS = {
6
+ HC: 'ROOK_HEALTH_CONNECT_PERMISSIONS',
7
+ HC_PARTIAL: 'ROOK_HEALTH_CONNECT_PERMISSIONS_PARTIALLY_GRANTED',
8
+ HC_BG: 'ROOK_HEALTH_CONNECT_BACKGROUND_PERMISSIONS',
9
+ SAMSUNG: 'ROOK_SAMSUNG_HEALTH_PERMISSIONS',
10
+ SAMSUNG_PARTIAL: 'ROOK_SAMSUNG_HEALTH_PERMISSIONS_PARTIALLY_GRANTED',
11
+ ANDROID_BG: 'ROOK_BACKGROUND_ANDROID_PERMISSIONS',
12
+ } as const;
13
+
14
+ export const useRookPermissionEmitter = () => {
15
+ const emittedRef = useRef<Record<string, boolean>>({});
16
+
17
+ const evaluateAndEmit = useCallback(
18
+ async (key: string, checkFn: () => Promise<boolean | BackgroundStatus>) => {
19
+ let previuos = emittedRef.current[key] || false;
20
+
21
+ try {
22
+ const result = await checkFn();
23
+
24
+ const isGranted =
25
+ typeof result === 'string' ? result === 'PERMISSION_GRANTED' : result;
26
+
27
+ if (previuos === isGranted) return;
28
+
29
+ const success = await RookSdk.sendMessage({
30
+ type: key,
31
+ value: isGranted,
32
+ });
33
+
34
+ if (success) {
35
+ emittedRef.current[key] = true;
36
+ }
37
+ } catch (error) {
38
+ console.error(`Error checking/emitting ${key}:`, error);
39
+ }
40
+ },
41
+ []
42
+ );
43
+
44
+ const checkAndroidSystem = async () => {
45
+ await evaluateAndEmit(
46
+ PERM_KEYS.ANDROID_BG,
47
+ RookSdk.androidHasBackgroundPermissions
48
+ );
49
+ };
50
+
51
+ const checkHealthConnect = async () => {
52
+ await Promise.all([
53
+ evaluateAndEmit(PERM_KEYS.HC, RookSdk.healthConnectHasPermissions),
54
+ evaluateAndEmit(
55
+ PERM_KEYS.HC_PARTIAL,
56
+ RookSdk.healthConnectHasPartialPermissions
57
+ ),
58
+ evaluateAndEmit(
59
+ PERM_KEYS.HC_BG,
60
+ RookSdk.checkHealthConnectBackgroundReadStatus
61
+ ),
62
+ ]);
63
+ };
64
+
65
+ const checkSamsungHealth = async () => {
66
+ await Promise.all([
67
+ evaluateAndEmit(PERM_KEYS.SAMSUNG, RookSdk.samsungHealthHasPermissions),
68
+ evaluateAndEmit(
69
+ PERM_KEYS.SAMSUNG_PARTIAL,
70
+ RookSdk.samsungHealthHasPartialPermissions
71
+ ),
72
+ ]);
73
+ };
74
+
75
+ const checkAndroidPermissions = async () => {
76
+ try {
77
+ const samsungStatus = await RookSdk.checkSamsungAvailability();
78
+ const isSamsungAvailable = samsungStatus === 'INSTALLED';
79
+
80
+ checkAndroidSystem().then().catch(console.log);
81
+ checkHealthConnect().then().catch(console.log);
82
+
83
+ if (isSamsungAvailable) {
84
+ checkSamsungHealth().catch(console.log);
85
+ } else {
86
+ console.log(`Skipping Samsung Health checks. Status: ${samsungStatus}`);
87
+ }
88
+ } catch (error) {
89
+ console.error('Global Permission Check Failed', error);
90
+ }
91
+ };
92
+
93
+ return { checkAndroidPermissions };
94
+ };
@@ -0,0 +1,5 @@
1
+ export type Message = {
2
+ type: string;
3
+ value: boolean;
4
+ message?: string;
5
+ };
@@ -0,0 +1,9 @@
1
+ export const errors = {
2
+ autoStartAndroidBackgroundSync:
3
+ 'ROOK - We try to start the health connect background sync but some permissions are missing, please grant permissions on health connect and android permissions, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/grantpermissons/#request-permissions',
4
+
5
+ autoStartIOSBackgroundSync:
6
+ 'ROOK - We try to start the background sync but some error occurred please check the permissions are granted and data exists in the device, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/grantpermissons/#request-permissions',
7
+ noUserIDAndroidBackground:
8
+ "ROOK - We couldn't start the background sync cause there is no user registered, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/updateuserid/",
9
+ };