react-native-rook-sdk 4.0.0-beta.2 → 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/RNRookSdk.podspec +1 -1
- package/android/build.gradle +6 -0
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +1850 -6
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +62 -0
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +64 -0
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +44 -0
- package/android/src/main/java/com/rooksdk/utils/DatasourceUtils.kt +35 -0
- package/android/src/main/java/com/rooksdk/utils/PermissionConvertions.kt +21 -0
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +144 -0
- package/android/src/main/java/com/rooksdk/utils/RookDateTime.kt +26 -0
- package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +20 -0
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +22 -0
- package/android/src/main/java/com/rooksdk/utils/Source.kt +6 -0
- package/android/src/main/java/com/rooksdk/utils/StringToSyncType.kt +41 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +18 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/LocalDateSerializer.kt +21 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/ZoneDateTimeSerializer.kt +18 -0
- package/ios/EncodableSDKState.swift +95 -0
- package/ios/NutritionMapper.swift +114 -0
- package/ios/RookConfiguration.swift +13 -0
- package/ios/RookData.swift +29 -0
- package/ios/RookEntry.swift +5 -4
- package/ios/RookPermissions.swift +33 -9
- package/ios/RookSdk.h +1 -13
- package/ios/RookSdk.mm +44 -237
- package/lib/module/NativeRookSdk.js +98 -10
- package/lib/module/NativeRookSdk.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +29 -21
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +12 -2
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +20 -1
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +13 -4
- package/lib/module/hooks/useRookData.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +13 -1
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +1 -1
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +16 -1
- package/lib/module/hooks/useRookVariables.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 +5 -4
- 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/types/AppleHealthNutritionEvent.js +72 -0
- package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -0
- package/lib/module/types/HCMealData.js +61 -0
- package/lib/module/types/HCMealData.js.map +1 -0
- package/lib/module/types/WriteNutrition.js +14 -0
- package/lib/module/types/WriteNutrition.js.map +1 -0
- package/lib/module/utils/isValidDate.js +20 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/typescript/src/NativeRookSdk.d.ts +622 -33
- package/lib/typescript/src/NativeRookSdk.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/context/RookSyncGateTypes.d.ts +14 -4
- package/lib/typescript/src/context/RookSyncGateTypes.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +3 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +2 -2
- package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +2 -0
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts +2 -0
- package/lib/typescript/src/hooks/useRookVariables.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 +76 -0
- package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -0
- package/lib/typescript/src/types/HCMealData.d.ts +60 -0
- package/lib/typescript/src/types/HCMealData.d.ts.map +1 -0
- package/lib/typescript/src/types/WriteNutrition.d.ts +61 -0
- package/lib/typescript/src/types/WriteNutrition.d.ts.map +1 -0
- package/lib/typescript/src/utils/isValidDate.d.ts +8 -0
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeRookSdk.ts +682 -117
- package/src/context/RookSyncGateProvider.tsx +20 -16
- package/src/context/RookSyncGateReducer.ts +6 -2
- package/src/context/RookSyncGateTypes.ts +9 -3
- package/src/hooks/useRookConfiguration.ts +26 -2
- package/src/hooks/useRookData.ts +18 -7
- package/src/hooks/useRookPermissions.ts +16 -0
- package/src/hooks/useRookSync.ts +1 -1
- package/src/hooks/useRookVariables.ts +22 -1
- package/src/modules/components/RookStateManager.tsx +41 -0
- package/src/modules/hook/useRookAutoSync.ts +6 -4
- package/src/modules/hook/useRookEmitter.ts +94 -0
- package/src/types/AppleHealthNutritionEvent.ts +142 -0
- package/src/types/HCMealData.ts +114 -0
- package/src/types/WriteNutrition.ts +66 -0
- package/src/utils/isValidDate.ts +24 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NutritionMapper.swift
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Javier Villanueva on 07/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import RookSDK
|
|
10
|
+
|
|
11
|
+
class NutritionMapper {
|
|
12
|
+
|
|
13
|
+
static func mapToNutritionInsertionEvent(data: [String: Any]) -> NutritionInsertionEvent? {
|
|
14
|
+
// Helper for Date parsing
|
|
15
|
+
let dateFormatter = ISO8601DateFormatter()
|
|
16
|
+
guard let dateString = data["date"] as? String,
|
|
17
|
+
let date = dateFormatter.date(from: dateString),
|
|
18
|
+
let name = data["name"] as? String,
|
|
19
|
+
let quantityMap = data["quantity"] as? [String: Any],
|
|
20
|
+
let amount = quantityMap["amount"] as? Double,
|
|
21
|
+
let unit = quantityMap["unit"] as? Int else {
|
|
22
|
+
return nil
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Range check helper: [0.0, 100,000.0] for large values, [0.0, 100.0] for small
|
|
26
|
+
func validate(_ value: Any?, max: Double = 100000.0) -> Double? {
|
|
27
|
+
guard let val = value as? Double else { return nil }
|
|
28
|
+
return (val >= 0.0 && val <= max) ? val : nil
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 1. Quantity
|
|
32
|
+
let quantity = NutritionInsertionEventQuantity(unit: unit, amount: amount)
|
|
33
|
+
|
|
34
|
+
// 2. Energy & Water
|
|
35
|
+
let energyData = data["energyWaterData"] as? [String: Any]
|
|
36
|
+
let energyRelated = NutritionInsertionEnergyWaterDataRelated(
|
|
37
|
+
dietaryKiloCaloriesEnergyConsumed: validate(energyData?["dietaryKiloCaloriesEnergyConsumed"]),
|
|
38
|
+
dietaryMilliLiterWater: validate(energyData?["dietaryMilliLiterWater"])
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// 3. Carbohydrates
|
|
42
|
+
let carbData = data["carbohydratesData"] as? [String: Any]
|
|
43
|
+
let carbRelated = NutritionCarbohydratesDataRelated(
|
|
44
|
+
dietaryGramCarbohydrates: validate(carbData?["dietaryGramCarbohydrates"]),
|
|
45
|
+
dietaryGramFiber: validate(carbData?["dietaryGramFiber"]),
|
|
46
|
+
dietaryGramSugar: validate(carbData?["dietaryGramSugar"])
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
// 4. Fats
|
|
50
|
+
let fatData = data["fatsData"] as? [String: Any]
|
|
51
|
+
let fatRelated = NutritionFatsDataRelated(
|
|
52
|
+
dietaryGramFatTotal: validate(fatData?["dietaryGramFatTotal"]),
|
|
53
|
+
dietaryGramFatSaturated: validate(fatData?["dietaryGramFatSaturated"]),
|
|
54
|
+
dietaryGramFatMonounsaturated: validate(fatData?["dietaryGramFatMonounsaturated"]),
|
|
55
|
+
dietaryGramFatPolyunsaturated: validate(fatData?["dietaryGramFatPolyunsaturated"])
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
// 5. Protein
|
|
59
|
+
let proteinData = data["proteinData"] as? [String: Any]
|
|
60
|
+
let proteinRelated = NutritionProteinDataRelated(
|
|
61
|
+
dietaryGramProtein: validate(proteinData?["dietaryGramProtein"]),
|
|
62
|
+
dietaryMilliGramCholesterol: validate(proteinData?["dietaryMilliGramCholesterol"])
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
// 6. Vitamins (Using 100.0 as limit for safety, adjust if needed)
|
|
66
|
+
let vitData = data["vitaminsData"] as? [String: Any]
|
|
67
|
+
let vitRelated = NutritionVitaminsDataRelated(
|
|
68
|
+
dietaryMicroGramVitaminA: validate(vitData?["dietaryMicroGramVitaminA"]),
|
|
69
|
+
dietaryMilliGramVitaminB6: validate(vitData?["dietaryMilliGramVitaminB6"]),
|
|
70
|
+
dietaryMicroGramVitaminB12: validate(vitData?["dietaryMicroGramVitaminB12"]),
|
|
71
|
+
dietaryMilliGramVitaminC: validate(vitData?["dietaryMilliGramVitaminC"]),
|
|
72
|
+
dietaryMicroGramVitaminD: validate(vitData?["dietaryMicroGramVitaminD"]),
|
|
73
|
+
dietaryMilliGramVitaminE: validate(vitData?["dietaryMilliGramVitaminE"]),
|
|
74
|
+
dietaryMicroGramVitaminK: validate(vitData?["dietaryMicroGramVitaminK"]),
|
|
75
|
+
dietaryMilliGramThiamin: validate(vitData?["dietaryMilliGramThiamin"]),
|
|
76
|
+
dietaryMilliGramRiboflavin: validate(vitData?["dietaryMilliGramRiboflavin"]),
|
|
77
|
+
dietaryMilliGramNiacin: validate(vitData?["dietaryMilliGramNiacin"]),
|
|
78
|
+
dietaryMilliGramPantothenicAcid: validate(vitData?["dietaryMilliGramPantothenicAcid"]),
|
|
79
|
+
dietaryMicroGramFolate: validate(vitData?["dietaryMicroGramFolate"]),
|
|
80
|
+
dietaryMicroGramBiotin: validate(vitData?["dietaryMicroGramBiotin"])
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
// 7. Minerals
|
|
84
|
+
let minData = data["mineralData"] as? [String: Any]
|
|
85
|
+
let minRelated = NutritionMineralDataRelated(
|
|
86
|
+
dietaryMilliGramsCalcium: validate(minData?["dietaryMilliGramsCalcium"]),
|
|
87
|
+
dietaryMilliGramsChloride: validate(minData?["dietaryMilliGramsChloride"]),
|
|
88
|
+
dietaryMilliGramsChromium: validate(minData?["dietaryMilliGramsChromium"]),
|
|
89
|
+
dietaryMilliGramsCopper: validate(minData?["dietaryMilliGramsCopper"]),
|
|
90
|
+
dietaryMilliGramsIodine: validate(minData?["dietaryMilliGramsIodine"]),
|
|
91
|
+
dietaryMilliGramsIron: validate(minData?["dietaryMilliGramsIron"]),
|
|
92
|
+
dietaryMilliGramsMagnesium: validate(minData?["dietaryMilliGramsMagnesium"]),
|
|
93
|
+
dietaryMilliGramsManganese: validate(minData?["dietaryMilliGramsManganese"]),
|
|
94
|
+
dietaryMilliGramsMolybdenum: validate(minData?["dietaryMilliGramsMolybdenum"]),
|
|
95
|
+
dietaryMilliGramsPhosphorus: validate(minData?["dietaryMilliGramsPhosphorus"]),
|
|
96
|
+
dietaryMilliGramsPotassium: validate(minData?["dietaryMilliGramsPotassium"]),
|
|
97
|
+
dietaryMilliGramsSelenium: validate(minData?["dietaryMilliGramsSelenium"]),
|
|
98
|
+
dietaryMilliGramsSodium: validate(minData?["dietaryMilliGramsSodium"]),
|
|
99
|
+
dietaryMilliGramsZinc: validate(minData?["dietaryMilliGramsZinc"])
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return NutritionInsertionEvent(
|
|
103
|
+
name: name,
|
|
104
|
+
quantity: quantity,
|
|
105
|
+
date: date,
|
|
106
|
+
nutritionInsertionEnergyWaterDataRelated: energyRelated,
|
|
107
|
+
nutritionCarbohydratesDataRelated: carbRelated,
|
|
108
|
+
nutritionFatsDataRelated: fatRelated,
|
|
109
|
+
nutritionProteinDataRelated: proteinRelated,
|
|
110
|
+
nutritionVitaminsDataRelated: vitRelated,
|
|
111
|
+
nutritionMineralDataRelated: minRelated
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -113,4 +113,17 @@ import RookSDK
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
public func getDiagnosticState(
|
|
118
|
+
_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
119
|
+
){
|
|
120
|
+
Task {
|
|
121
|
+
var result = await RookConnectConfigurationManager.shared.getDiagnosticState()
|
|
122
|
+
let dic = EncodableSDKState(result).toDictionary()
|
|
123
|
+
|
|
124
|
+
DispatchQueue.main.async {
|
|
125
|
+
resolve(dic)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
116
129
|
}
|
package/ios/RookData.swift
CHANGED
|
@@ -167,4 +167,33 @@ import React
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
+
|
|
171
|
+
public func writeAppleHealthMealData(
|
|
172
|
+
_ data: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
173
|
+
){
|
|
174
|
+
guard let event = NutritionMapper.mapToNutritionInsertionEvent(data: data as! [String : Any]) else {
|
|
175
|
+
reject("1001", "Could not parse nutrition data", nil)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Task {
|
|
180
|
+
do {
|
|
181
|
+
|
|
182
|
+
let result = try await eventManager.writeNutritionEvent(event: event)
|
|
183
|
+
DispatchQueue.main.async {
|
|
184
|
+
resolve(result)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
} catch {
|
|
188
|
+
if let rookError: RookError = error as? RookError {
|
|
189
|
+
DispatchQueue.main.async {
|
|
190
|
+
reject(String(rookError.code), rookError.errorDescription, error as NSError)
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
reject("1001", "An error ocurred with SDK try again", error as NSError)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
170
199
|
}
|
package/ios/RookEntry.swift
CHANGED
|
@@ -19,8 +19,8 @@ import RookSDK
|
|
|
19
19
|
|
|
20
20
|
let environment = options["environment"] as? String ?? ""
|
|
21
21
|
let clientUUID = options["clientUUID"] as? String ?? ""
|
|
22
|
-
let
|
|
23
|
-
let
|
|
22
|
+
let secret = options["secret"] as? String ?? ""
|
|
23
|
+
let bundleId = options["bundleId"] as? String
|
|
24
24
|
let backgroundSync = options["enableBackground"] as? Bool ?? true
|
|
25
25
|
|
|
26
26
|
if (environment == "production") {
|
|
@@ -31,9 +31,10 @@ import RookSDK
|
|
|
31
31
|
|
|
32
32
|
RookConnectConfigurationManager.shared.setConfiguration(
|
|
33
33
|
clientUUID: clientUUID,
|
|
34
|
-
|
|
34
|
+
secret: secret,
|
|
35
|
+
bundleId: bundleId,
|
|
35
36
|
enableBackgroundSync: backgroundSync,
|
|
36
|
-
enableEventsBackgroundSync:
|
|
37
|
+
enableEventsBackgroundSync: backgroundSync)
|
|
37
38
|
|
|
38
39
|
let result = try await RookConnectConfigurationManager.shared.initRook()
|
|
39
40
|
|
|
@@ -12,13 +12,13 @@ import RookSDK
|
|
|
12
12
|
lazy var permissionsManager: RookConnectPermissionsManager = {
|
|
13
13
|
return RookConnectPermissionsManager()
|
|
14
14
|
}()
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
public func checkPermissionsStatus(
|
|
17
17
|
_ type: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
18
18
|
) {
|
|
19
19
|
Task {
|
|
20
20
|
do {
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
let result = await permissionsManager.checkPermissionStatus(type: type)
|
|
23
23
|
|
|
24
24
|
DispatchQueue.main.async {
|
|
@@ -36,7 +36,7 @@ import RookSDK
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
public func requestAppleHealthPermissions(
|
|
41
41
|
_ permissions: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
42
42
|
) {
|
|
@@ -61,18 +61,42 @@ import RookSDK
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
public func openAppleHealthSettings(
|
|
66
66
|
_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
67
67
|
){
|
|
68
68
|
guard let urlSettings = URL(string: "x-apple-health://") else {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
reject("1001", "An error ocurred with SDK try again", nil)
|
|
70
|
+
return
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
DispatchQueue.main.async {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
UIApplication.shared.open(urlSettings, options: [:]) { success in
|
|
75
|
+
resolve(success)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public func requestWriteNutritionPermission(
|
|
81
|
+
_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
|
|
82
|
+
) {
|
|
83
|
+
Task {
|
|
84
|
+
do {
|
|
85
|
+
|
|
86
|
+
let result = try await permissionsManager.requestDietaryWritePermissions()
|
|
87
|
+
|
|
88
|
+
DispatchQueue.main.async {
|
|
89
|
+
resolve(result)
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
if let rookError: RookError = error as? RookError {
|
|
93
|
+
DispatchQueue.main.async {
|
|
94
|
+
reject(String(rookError.code), rookError.errorDescription, error as NSError)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
reject("1001", "An error ocurred with SDK try again", error as NSError)
|
|
98
|
+
}
|
|
76
99
|
}
|
|
77
|
-
|
|
100
|
+
}
|
|
101
|
+
}
|
|
78
102
|
}
|
package/ios/RookSdk.h
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTInitializing.h>
|
|
3
|
-
|
|
4
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
1
|
#import <RookSdkSpec/RookSdkSpec.h>
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
#import <React/RCTInitializing.h>
|
|
9
3
|
|
|
10
|
-
// NEW ARCHITECTURE: Inherit from the generated Base class
|
|
11
4
|
@interface RNRookSdk : NativeRookSdkSpecBase <NativeRookSdkSpec, RCTInitializing>
|
|
12
|
-
#else
|
|
13
|
-
|
|
14
|
-
// OLD ARCHITECTURE: Inherit from NSObject and conform to RCTBridgeModule
|
|
15
|
-
@interface RNRookSdk : NSObject <RCTBridgeModule, RCTInitializing>
|
|
16
|
-
#endif
|
|
17
5
|
|
|
18
6
|
@end
|
package/ios/RookSdk.mm
CHANGED
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
RookSync *sync;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
16
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
17
|
+
{
|
|
18
|
+
return std::make_shared<facebook::react::NativeRookSdkSpecJSI>(params);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
+ (NSString *)moduleName
|
|
22
|
+
{
|
|
23
|
+
return @"RNRookSdk";
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
- (id) init {
|
|
16
27
|
if (self = [super init]) {
|
|
17
28
|
sources = [RookSources new];
|
|
@@ -27,19 +38,6 @@
|
|
|
27
38
|
return self;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
|
-
// --- TURBOMODULE (New Arch) ---
|
|
31
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
32
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
33
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
34
|
-
{
|
|
35
|
-
return std::make_shared<facebook::react::NativeRookSdkSpecJSI>(params);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
+ (NSString *)moduleName
|
|
39
|
-
{
|
|
40
|
-
return @"RNRookSdk";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
41
|
- (void)initialize {
|
|
44
42
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
45
43
|
selector:@selector(handleErrorBackground:)
|
|
@@ -96,10 +94,6 @@
|
|
|
96
94
|
[self isNotiOSSupported:reject];
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
- (void)scheduleBackgroundSync:(BOOL)enableLogs resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
100
|
-
[self isNotiOSSupported:reject];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
97
|
- (void)getHealthConnectActivityEvents:(nonnull NSString *)date resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
104
98
|
[self isNotiOSSupported:reject];
|
|
105
99
|
}
|
|
@@ -249,6 +243,31 @@
|
|
|
249
243
|
[self isNotiOSSupported:reject];
|
|
250
244
|
}
|
|
251
245
|
|
|
246
|
+
- (void)getSHTodayHeartRate:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
247
|
+
[self isNotiOSSupported:reject];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
- (void)shouldRequestAndroidBackgroundPermissions:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
251
|
+
[self isNotiOSSupported:reject];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
- (void)writeHealthConnectMealData:(JS::NativeRookSdk::HCMealData &)data resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
255
|
+
[self isNotiOSSupported:reject];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
- (void)scheduleBackgroundSync:(nonnull NSNumber *)enableLogs resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
259
|
+
[self isNotiOSSupported:reject];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
- (void)getHealthConnectDiagnosticState:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
263
|
+
[self isNotiOSSupported:reject];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
- (void)getSamsungHealthDiagnosticState:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
268
|
+
[self isNotiOSSupported:reject];
|
|
269
|
+
}
|
|
270
|
+
|
|
252
271
|
- (void)getAuthorizedDataSourcesV2:(nonnull NSString *)userid resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
253
272
|
[sources getAuthorizedDataSourcesV2:userid resolve:resolve reject:reject];
|
|
254
273
|
}
|
|
@@ -265,11 +284,11 @@
|
|
|
265
284
|
|
|
266
285
|
- (void)initRook:(JS::NativeRookSdk::RookConfig &)options resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
267
286
|
NSMutableDictionary *dict = [NSMutableDictionary new];
|
|
268
|
-
dict[@"
|
|
287
|
+
dict[@"secret"] = options.secret();
|
|
269
288
|
dict[@"environment"] = options.environment();
|
|
270
289
|
dict[@"clientUUID"] = options.clientUUID();
|
|
290
|
+
dict[@"bundleId"] = options.bundleId();
|
|
271
291
|
dict[@"enableBackground"] = @(options.enableBackground());
|
|
272
|
-
dict[@"enableEventsBackgroundSync"] = @(options.enableEventsBackgroundSync());
|
|
273
292
|
|
|
274
293
|
[entry initRook:dict resolve:resolve reject:reject];
|
|
275
294
|
}
|
|
@@ -388,229 +407,17 @@
|
|
|
388
407
|
}
|
|
389
408
|
}
|
|
390
409
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
RCT_EXPORT_MODULE()
|
|
394
|
-
|
|
395
|
-
-(void)startObserving {
|
|
396
|
-
shouldEmitEvent = YES;
|
|
397
|
-
|
|
398
|
-
NSLog(@"Hay alguien escuchando");
|
|
399
|
-
|
|
400
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
401
|
-
selector:@selector(receiveTestNotification:)
|
|
402
|
-
name:@"kRookErrorBackground"
|
|
403
|
-
object:nil];
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// Will be called when this module's last listener is removed, or on dealloc.
|
|
407
|
-
-(void)stopObserving {
|
|
408
|
-
shouldEmitEvent = NO;
|
|
409
|
-
|
|
410
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
414
|
-
return @[@"ROOK_NOTIFICATION"];
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// The above code is an Objective-C method that receives a notification and checks if the notification
|
|
418
|
-
// name is "kRookErrorBackground". If it is, it extracts information from the notification's userInfo
|
|
419
|
-
// dictionary, specifically an error object. It then creates a dictionary message containing the type,
|
|
420
|
-
// message, and code extracted from the error object. Finally, if there are listeners registered, it
|
|
421
|
-
// sends an event with the message dictionary to a specific event name "ROOK_NOTIFICATION".
|
|
422
|
-
- (void) receiveTestNotification:(NSNotification *) notification
|
|
423
|
-
{
|
|
424
|
-
if ([[notification name] isEqualToString:@"kRookErrorBackground"]) {
|
|
425
|
-
NSDictionary<NSString*, NSError *> *notificationInfo = [[notification userInfo] mutableCopy];
|
|
426
|
-
|
|
427
|
-
NSMutableDictionary *message = [[NSMutableDictionary alloc] init];
|
|
428
|
-
message[@"type"] = @"ROOK_APPLE_HEALTH_BACKGROUND_ERROR";
|
|
429
|
-
message[@"message"] = notificationInfo[@"Error"].localizedDescription;
|
|
430
|
-
message[@"code"] = notificationInfo[@"Error"].description;
|
|
431
|
-
|
|
432
|
-
if (shouldEmitEvent)
|
|
433
|
-
[self sendEventWithName:@"ROOK_NOTIFICATION" body: message];
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
RCT_EXPORT_METHOD(initRook:(NSDictionary *) data
|
|
438
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
439
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
440
|
-
|
|
441
|
-
NSMutableDictionary *dict = [NSMutableDictionary new];
|
|
442
|
-
dict[@"password"] = options.password();
|
|
443
|
-
dict[@"environment"] = options.environment();
|
|
444
|
-
dict[@"clientUUID"] = options.clientUUID();
|
|
445
|
-
dict[@"enableBackground"] = @(options.enableBackground());
|
|
446
|
-
dict[@"enableEventsBackgroundSync"] = @(options.enableEventsBackgroundSync());
|
|
447
|
-
|
|
448
|
-
[entry initRook:dict resolve:resolve reject:reject];
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Internal method to send messages to broadcast channel
|
|
453
|
-
*
|
|
454
|
-
* @param resolve A block called with a boolean value indicating whether the result is.
|
|
455
|
-
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
456
|
-
*/
|
|
457
|
-
RCT_EXPORT_METHOD(sendMessage: (NSDictionary *) message
|
|
458
|
-
resolve: (RCTPromiseResolveBlock) resolve
|
|
459
|
-
reject: (RCTPromiseRejectBlock) reject) {
|
|
460
|
-
if(shouldEmitEvent) {
|
|
461
|
-
[self sendEventWithName:@"ROOK_NOTIFICATION" body:message];
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
RCT_EXPORT_METHOD(getDataSourceAuthorizer:(NSDictionary *)props
|
|
466
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
467
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
468
|
-
[sources getDataSourceAuthorizer:props resolve:resolve reject:reject];
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
RCT_EXPORT_METHOD(revokeDataSource:(NSString *)userid
|
|
472
|
-
type:(NSString *)type
|
|
473
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
474
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
475
|
-
{
|
|
476
|
-
[sources revokeDataSource:userid source:type resolve:resolve reject:reject];
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
RCT_EXPORT_METHOD(getUserID:(RCTPromiseResolveBlock)resolve
|
|
480
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
481
|
-
{
|
|
482
|
-
[config getUserID:resolve reject:reject];
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
RCT_EXPORT_METHOD(removeUserFromRook:(NSArray *)sources
|
|
486
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
487
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
488
|
-
{
|
|
489
|
-
[config removeUserFromRook:resolve reject:reject];
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
RCT_EXPORT_METHOD(syncUserTimeZone:(RCTPromiseResolveBlock)resolve
|
|
493
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
494
|
-
{
|
|
495
|
-
[config syncUserTimeZone:resolve reject:reject];
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
RCT_EXPORT_METHOD(updateUserID:(NSString *)userID
|
|
499
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
500
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
501
|
-
{
|
|
502
|
-
[config updateUserID:userID resolve:resolve reject:reject];
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
RCT_EXPORT_METHOD(disableBackGroundUpdates:(RCTPromiseResolveBlock)resolve
|
|
506
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
507
|
-
{
|
|
508
|
-
[bg disableBackGroundUpdates:resolve reject:reject];
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
RCT_EXPORT_METHOD(enableBackGroundUpdates:(RCTPromiseResolveBlock)resolve
|
|
512
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
513
|
-
{
|
|
514
|
-
[bg enableBackGroundUpdates:resolve reject:reject];
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
RCT_EXPORT_METHOD(isBackgroundUpdatesEnabled:(RCTPromiseResolveBlock)resolve
|
|
518
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
519
|
-
{
|
|
520
|
-
[bg isBackgroundUpdatesEnabled:resolve reject:reject];
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
RCT_EXPORT_METHOD(appleHealthHasPermissions:(NSString *)param
|
|
524
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
525
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
526
|
-
{
|
|
527
|
-
[perm checkPermissionsStatus:param resolve:resolve reject:reject];
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
RCT_EXPORT_METHOD(openAppleHealthSettings:(RCTPromiseResolveBlock)resolve
|
|
531
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
532
|
-
{
|
|
533
|
-
[perm openAppleHealthSettings:resolve reject:reject];
|
|
410
|
+
- (void)requestAppleWriteNutritionPermission:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
411
|
+
[perm requestWriteNutritionPermission:resolve reject:reject];
|
|
534
412
|
}
|
|
535
413
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
539
|
-
{
|
|
540
|
-
[perm requestAppleHealthPermissions:permissions resolve:resolve reject:reject];
|
|
414
|
+
- (void)getDiagnosticState:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
415
|
+
[config getDiagnosticState:resolve reject:reject];
|
|
541
416
|
}
|
|
542
417
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
546
|
-
{
|
|
547
|
-
[data getAppleHealthActivityEvents:date resolve:resolve reject:reject];
|
|
418
|
+
- (void)writeAppleHealthMealData:(nonnull NSDictionary *)meal resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
419
|
+
[data writeAppleHealthMealData:meal resolve:resolve reject:reject];
|
|
548
420
|
}
|
|
549
421
|
|
|
550
|
-
RCT_EXPORT_METHOD(getAppleHealthBodySummary:(NSString *)date
|
|
551
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
552
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
553
|
-
{
|
|
554
|
-
[data getAppleHealthBodySummary:date resolve:resolve reject:reject];
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
RCT_EXPORT_METHOD(getAppleHealthPhysicalSummary:(NSString *)date
|
|
558
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
559
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
560
|
-
{
|
|
561
|
-
[data getAppleHealthPhysicalSummary:date resolve:resolve reject:reject];
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
RCT_EXPORT_METHOD(getAppleHealthSleepSummary:(NSString *)date
|
|
565
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
566
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
567
|
-
{
|
|
568
|
-
[data getAppleHealthSleepSummary:date resolve:resolve reject:reject];
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
RCT_EXPORT_METHOD(getTodayHeartRate:(RCTPromiseResolveBlock)resolve
|
|
572
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
573
|
-
{
|
|
574
|
-
[data getTodayHeartRate:resolve reject:reject];
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
RCT_EXPORT_METHOD(getTodayAppleHealthSteps:(RCTPromiseResolveBlock)resolve
|
|
578
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
579
|
-
{
|
|
580
|
-
[sync getTodayAppleHealthSteps:resolve reject:reject];
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
RCT_EXPORT_METHOD(syncTodayCaloriesCount:(RCTPromiseResolveBlock)resolve
|
|
584
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
585
|
-
{
|
|
586
|
-
[sync syncTodayCaloriesCount:resolve reject:reject];
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
RCT_EXPORT_METHOD(sync:(RCTResponseSenderBlock)cb)
|
|
590
|
-
{
|
|
591
|
-
[sync sync:cb];
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
RCT_EXPORT_METHOD(syncByDate:(NSString *)date
|
|
595
|
-
cb:(RCTResponseSenderBlock)cb)
|
|
596
|
-
{
|
|
597
|
-
[sync syncByDate:date callback:cb];
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
RCT_EXPORT_METHOD(syncByDefinition:(NSString *)summary
|
|
601
|
-
date:(NSString *)date
|
|
602
|
-
cb:(RCTResponseSenderBlock)cb)
|
|
603
|
-
{
|
|
604
|
-
[sync syncByDefinition:summary syncDate:date callback:cb];
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
RCT_EXPORT_METHOD(syncEvent:(NSString *)date
|
|
608
|
-
event:(NSString *)event
|
|
609
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
610
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
611
|
-
{
|
|
612
|
-
[sync syncEvent:date event:event resolve:resolve reject:reject];
|
|
613
|
-
}
|
|
614
|
-
#endif
|
|
615
422
|
|
|
616
423
|
@end
|