react-native-rook-sdk 2.0.2 → 2.1.0-rc.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 (94) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +3 -1
  3. package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +14 -0
  4. package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +247 -0
  5. package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +17 -1
  6. package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +19 -0
  7. package/android/src/main/java/com/rooksdk/utils/serializers/LocalDateSerializer.kt +21 -0
  8. package/ios/EncodableDataSource.swift +32 -0
  9. package/ios/EncodableDataSourceAuthorizer.swift +32 -0
  10. package/ios/EncodableRookDataSource.swift +36 -0
  11. package/ios/EncodableStatusDataSources.swift +47 -0
  12. package/ios/RookExternalModule.h +5 -0
  13. package/ios/RookExternalModule.m +27 -0
  14. package/ios/RookLocalData.swift +152 -0
  15. package/ios/RookSdk.mm +1 -0
  16. package/ios/RookSources.swift +148 -0
  17. package/ios/RookSourcesModule.mm +29 -98
  18. package/ios/RookSync.h +5 -0
  19. package/ios/RookSync.m +27 -0
  20. package/ios/RookSync.swift +135 -0
  21. package/ios/RookSyncModule.h +1 -1
  22. package/ios/RookSyncModule.mm +10 -5
  23. package/ios/SwiftTest.swift +18 -0
  24. package/ios/react-native-rook-sdk-Bridging-Header.h +12 -0
  25. package/lib/commonjs/hooks/index.js +7 -0
  26. package/lib/commonjs/hooks/index.js.map +1 -1
  27. package/lib/commonjs/hooks/useRookData.js +100 -0
  28. package/lib/commonjs/hooks/useRookData.js.map +1 -0
  29. package/lib/commonjs/hooks/useRookDataSources.js +17 -6
  30. package/lib/commonjs/hooks/useRookDataSources.js.map +1 -1
  31. package/lib/commonjs/hooks/useRookHealthConnect.js +7 -1
  32. package/lib/commonjs/hooks/useRookHealthConnect.js.map +1 -1
  33. package/lib/commonjs/hooks/useRookSync.js +1 -1
  34. package/lib/commonjs/hooks/useRookSync.js.map +1 -1
  35. package/lib/commonjs/types/ActivityEvent.js +6 -0
  36. package/lib/commonjs/types/ActivityEvent.js.map +1 -0
  37. package/lib/commonjs/types/BodySummary.js +6 -0
  38. package/lib/commonjs/types/BodySummary.js.map +1 -0
  39. package/lib/commonjs/types/PhysicalSummary.js +6 -0
  40. package/lib/commonjs/types/PhysicalSummary.js.map +1 -0
  41. package/lib/commonjs/types/SleepSummary.js +6 -0
  42. package/lib/commonjs/types/SleepSummary.js.map +1 -0
  43. package/lib/commonjs/types/SummaryTypes.js +2 -0
  44. package/lib/commonjs/types/SummaryTypes.js.map +1 -0
  45. package/lib/commonjs/utils/getNativeModule.js +1 -1
  46. package/lib/commonjs/utils/getNativeModule.js.map +1 -1
  47. package/lib/commonjs/utils/nativeModules.js +5 -2
  48. package/lib/commonjs/utils/nativeModules.js.map +1 -1
  49. package/lib/module/hooks/index.js +1 -0
  50. package/lib/module/hooks/index.js.map +1 -1
  51. package/lib/module/hooks/useRookData.js +92 -0
  52. package/lib/module/hooks/useRookData.js.map +1 -0
  53. package/lib/module/hooks/useRookDataSources.js +17 -6
  54. package/lib/module/hooks/useRookDataSources.js.map +1 -1
  55. package/lib/module/hooks/useRookHealthConnect.js +7 -1
  56. package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
  57. package/lib/module/hooks/useRookSync.js +1 -1
  58. package/lib/module/hooks/useRookSync.js.map +1 -1
  59. package/lib/module/types/ActivityEvent.js +2 -0
  60. package/lib/module/types/ActivityEvent.js.map +1 -0
  61. package/lib/module/types/BodySummary.js +2 -0
  62. package/lib/module/types/BodySummary.js.map +1 -0
  63. package/lib/module/types/PhysicalSummary.js +2 -0
  64. package/lib/module/types/PhysicalSummary.js.map +1 -0
  65. package/lib/module/types/SleepSummary.js +2 -0
  66. package/lib/module/types/SleepSummary.js.map +1 -0
  67. package/lib/module/types/SummaryTypes.js +2 -0
  68. package/lib/module/types/SummaryTypes.js.map +1 -0
  69. package/lib/module/utils/getNativeModule.js +1 -1
  70. package/lib/module/utils/getNativeModule.js.map +1 -1
  71. package/lib/module/utils/nativeModules.js +5 -2
  72. package/lib/module/utils/nativeModules.js.map +1 -1
  73. package/lib/typescript/src/hooks/index.d.ts +1 -0
  74. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  75. package/lib/typescript/src/hooks/useRookData.d.ts +18 -0
  76. package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -0
  77. package/lib/typescript/src/hooks/useRookDataSources.d.ts +1 -0
  78. package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +1 -1
  79. package/lib/typescript/src/hooks/useRookHealthConnect.d.ts +1 -0
  80. package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -1
  81. package/lib/typescript/src/types/ActivityEvent.d.ts +137 -0
  82. package/lib/typescript/src/types/ActivityEvent.d.ts.map +1 -0
  83. package/lib/typescript/src/types/BodySummary.d.ts +99 -0
  84. package/lib/typescript/src/types/BodySummary.d.ts.map +1 -0
  85. package/lib/typescript/src/types/PhysicalSummary.d.ts +70 -0
  86. package/lib/typescript/src/types/PhysicalSummary.d.ts.map +1 -0
  87. package/lib/typescript/src/types/SleepSummary.d.ts +57 -0
  88. package/lib/typescript/src/types/SleepSummary.d.ts.map +1 -0
  89. package/lib/typescript/src/types/SummaryTypes.d.ts +59 -0
  90. package/lib/typescript/src/types/SummaryTypes.d.ts.map +1 -0
  91. package/lib/typescript/src/utils/nativeModules.d.ts +3 -0
  92. package/lib/typescript/src/utils/nativeModules.d.ts.map +1 -1
  93. package/package.json +22 -22
  94. package/react-native-rook-sdk.podspec +5 -3
@@ -0,0 +1,152 @@
1
+ //
2
+ // RookLocalData.swift
3
+ // react-native-rook-sdk
4
+ //
5
+ // Created by Javier Villanueva on 10/09/25.
6
+ //
7
+
8
+ import RookSDK
9
+
10
+ @objc(RookLocalData)
11
+ public class RookLocalData: NSObject {
12
+
13
+ lazy var summaryManager: RookSummaryManager = {
14
+ return RookSummaryManager()
15
+ }()
16
+
17
+ lazy var eventManager: RookEventsManager = {
18
+ return RookEventsManager()
19
+ }()
20
+
21
+ func parseStringToDate(_ input: String) -> Date? {
22
+ let dateFormatter = DateFormatter()
23
+ dateFormatter.dateFormat = "yyyy-MM-dd"
24
+ return dateFormatter.date(from: input)
25
+ }
26
+
27
+ @objc(getAppleHealthSleepSummary:resolve:reject:)
28
+ public func getAppleHealthSleepSummary(
29
+ _ date: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
30
+ ) {
31
+ Task {
32
+ do {
33
+ guard let parsed = parseStringToDate(date) else {
34
+ reject("AppleHealthGetSleepSummaryError", "Invalid date format", nil)
35
+ return
36
+ }
37
+
38
+ let sleepSummaries = try await summaryManager.getSleepSummary(date: parsed)
39
+ let dic = sleepSummaries.map { $0.toDictionary() }
40
+
41
+ DispatchQueue.main.async {
42
+ resolve(dic)
43
+ }
44
+ } catch {
45
+
46
+ DispatchQueue.main.async {
47
+ reject("AppleHealthGetSleepSummaryError", error.localizedDescription, error as NSError)
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ @objc(getAppleHealthPhysicalSummary:resolve:reject:)
54
+ public func getAppleHealthPhysicalSummary(
55
+ _ date: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
56
+ ) {
57
+ Task {
58
+ do {
59
+ guard let parsed = parseStringToDate(date) else {
60
+ reject("AppleHealthGetPhysicalSummaryError", "Invalid date format", nil)
61
+ return
62
+ }
63
+
64
+ let physicalSummaries = try await summaryManager.getPhysicalSummary(date: parsed)
65
+ let dic = physicalSummaries.toDictionary()
66
+
67
+ DispatchQueue.main.async {
68
+ resolve(dic)
69
+ }
70
+
71
+ } catch {
72
+
73
+ DispatchQueue.main.async {
74
+ reject("AppleHealthGetBodySummaryError", error.localizedDescription, error as NSError)
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ @objc(getAppleHealthBodySummary:resolve:reject:)
81
+ public func getAppleHealthBodySummary(
82
+ _ date: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
83
+ ) {
84
+ Task {
85
+ do {
86
+ guard let parsed = parseStringToDate(date) else {
87
+ reject("AppleHealthGetBodySummaryError", "Invalid date format", nil)
88
+ return
89
+ }
90
+ let bodySummaries = try await summaryManager.getBodySummary(date: parsed)
91
+ let dic = bodySummaries.toDictionary()
92
+
93
+ DispatchQueue.main.async {
94
+ resolve(dic)
95
+ }
96
+
97
+ } catch {
98
+
99
+ DispatchQueue.main.async {
100
+ reject("AppleHealthGetBodySummaryError", error.localizedDescription, error as NSError)
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ @objc(getAppleHealthActivityEvents:resolve:reject:)
107
+ public func getAppleHealthActivityEvents(
108
+ _ date: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
109
+ ) {
110
+ Task {
111
+ do {
112
+ guard let parsed = parseStringToDate(date) else {
113
+ reject("AppleHealthGetActivityEventsError", "Invalid date format", nil)
114
+ return
115
+ }
116
+
117
+ let activityEvents = try await eventManager.getActivityEvents(date: parsed)
118
+ let dic = activityEvents.map { $0.toDictionary() }
119
+
120
+ DispatchQueue.main.async {
121
+ resolve(dic)
122
+ }
123
+
124
+ } catch {
125
+
126
+ DispatchQueue.main.async {
127
+ reject("AppleHealthGetActivityEvents", error.localizedDescription, error as NSError)
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ }
134
+
135
+ extension Encodable {
136
+ func toDictionary() -> [String: Any] {
137
+ let encoder = JSONEncoder()
138
+
139
+ let dateFormatter = DateFormatter()
140
+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
141
+
142
+ encoder.dateEncodingStrategy = .formatted(dateFormatter)
143
+
144
+ guard let data = try? encoder.encode(self),
145
+ let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
146
+ else {
147
+ return [:]
148
+ }
149
+
150
+ return dictionary
151
+ }
152
+ }
package/ios/RookSdk.mm CHANGED
@@ -1,4 +1,5 @@
1
1
  #import "RookSdk.h"
2
+ #import <React/RCTLog.h>
2
3
  #import "RookSDK/RookSDK-Swift.h"
3
4
  #import "RCTConvert.h"
4
5
 
@@ -0,0 +1,148 @@
1
+ //
2
+ // RookSources.swift
3
+ // react-native-rook-sdk
4
+ //
5
+ // Created by Javier Villanueva on 07/10/25.
6
+ //
7
+
8
+ import RookSDK
9
+
10
+ @objc(RookSources)
11
+ public class RookSources: NSObject {
12
+
13
+ lazy var dataSourceManager: DataSourcesManager = {
14
+ return DataSourcesManager()
15
+ }()
16
+
17
+ lazy var userManager: UserManager = {
18
+ return UserManager()
19
+ }()
20
+
21
+ /**
22
+ * Check the authorizers and retrieve the sources available and configured
23
+ *
24
+ * @param resolve A block called with a boolean value indicating whether the result.
25
+ * @param reject A block called if an error occurs.
26
+ */
27
+ @objc(getAvailableDataSources:resolve:reject:)
28
+ public func getAvailableDataSources(
29
+ _ options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
30
+ ) {
31
+ Task {
32
+ do {
33
+ let redirect = options["redirectURL"] as? String ?? ""
34
+
35
+ let sources = try await self.dataSourceManager.getAvailableDataSources(redirectURL: redirect)
36
+ let dic = sources.map { source in
37
+ let enc = EncodableRookDataSource(source)
38
+ return enc.toDictionary()
39
+ }
40
+
41
+ DispatchQueue.main.async {
42
+ resolve(dic)
43
+ }
44
+ } catch {
45
+ DispatchQueue.main.async {
46
+ reject("AppleHealthGetAvailableDataSources", error.localizedDescription, error as NSError)
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Check the authorizers and present a default view.
54
+ *
55
+ * @param resolve A block called with a boolean value indicating whether the result.
56
+ * @param reject A block called if an error occurs.
57
+ */
58
+ @objc(presentDataSourceView:resolve:reject:)
59
+ public func presentDataSourceView(
60
+ _ options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
61
+ ) {
62
+
63
+ let redirect = options["redirectURL"] as? String ?? ""
64
+
65
+ DispatchQueue.main.sync {
66
+ self.dataSourceManager.presentDataSourceView(redirectURL: redirect) { result in
67
+ switch result {
68
+ case .success(let value):
69
+ resolve(value)
70
+ case .failure(let error):
71
+ reject("AppleHealthPresentDataSources", error.localizedDescription, error as NSError)
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Revoke the access to a API source
79
+ *
80
+ * @param resolve A block called with a boolean value indicating whether the result is.
81
+ * @param reject A block called if an error occurs, such as Apple Health not being installed.
82
+ */
83
+ @objc(revokeDataSource:resolve:reject:)
84
+ public func revokeDataSource(
85
+ _ source: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
86
+ ) {
87
+ Task {
88
+ do {
89
+ let result = try await self.userManager.revokeDataSource(dataSource: source)
90
+ resolve(result)
91
+ } catch {
92
+ reject("AppleHealthRevokeDataSource", error.localizedDescription, error as NSError)
93
+ }
94
+ }
95
+ }
96
+
97
+ @objc(getAuthorizedDataSources:reject:)
98
+ public func getAuthorizedDataSources(
99
+ _ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
100
+ ) {
101
+ self.dataSourceManager.getAuthorizedDataSources() { result in
102
+ switch result {
103
+ case .success(let value):
104
+ resolve(EncodableStatusDataSources(value).toDictionary())
105
+ case .failure(let error):
106
+ reject("AppleHealthGetAuthorizedDataSources", error.localizedDescription, error as NSError)
107
+ }
108
+ }
109
+ }
110
+
111
+ @objc(getDataSourceAuthorizer:resolve:reject:)
112
+ public func getDataSourceAuthorizer(
113
+ _ options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
114
+ ) {
115
+ Task {
116
+ do {
117
+ let source = options["dataSource"] as? String ?? ""
118
+ let redirect = options["redirectURL"] as? String ?? ""
119
+
120
+ let result = try await self.dataSourceManager.getDataSourceAuthorizer(dataSource: source, redirectUrl: redirect)
121
+ let dic = EncodableDataSourceAuthorizer(result).toDictionary()
122
+
123
+ DispatchQueue.main.async {
124
+ resolve(dic)
125
+ }
126
+ } catch {
127
+ DispatchQueue.main.async {
128
+ reject("AppleHealthDataSourceAuthorizer", error.localizedDescription, error as NSError)
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ @objc(getAuthorizedDataSourcesV2:reject:)
135
+ public func getAuthorizedDataSourcesV2(
136
+ _ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
137
+ ){
138
+ self.dataSourceManager.getAuthorizedSources { result in
139
+ switch result {
140
+ case .success(let value):
141
+ let dic = value.map{ EncodableDataSource($0).toDictionary() }
142
+ resolve(dic)
143
+ case .failure(let error):
144
+ reject("AppleHealthGetAuthorizedDataSources", error.localizedDescription, error as NSError)
145
+ }
146
+ }
147
+ }
148
+ }
@@ -1,117 +1,47 @@
1
1
  #import "RookSourcesModule.h"
2
- #import "RookSDK/RookSDK-Swift.h"
3
- #import "RCTConvert.h"
2
+ #import <React/RCTBridgeModule.h>
4
3
 
5
- @implementation RookSourcesModule
6
-
7
- RCT_EXPORT_MODULE()
8
-
9
- DataSourceManagerObjc *sourceManager;
10
- UserManager* sourceUserManager;
11
-
12
- - (void) checkUserInstance {
13
- if (sourceUserManager == nil) sourceUserManager = [UserManager new];
14
- }
15
-
16
- - (void) checkSourcesInstance {
17
- if (sourceManager == nil) sourceManager = [DataSourceManagerObjc new];
18
- }
4
+ @interface RCT_EXTERN_MODULE(RookSources, NSObject)
19
5
 
6
+ RCT_EXTERN_METHOD(getAvailableDataSources: (NSDictionary *) options
7
+ resolve:(RCTPromiseResolveBlock)resolve
8
+ reject:(RCTPromiseRejectBlock)reject)
20
9
 
21
- /**
22
- * Check the authorizers and retrieve the sources available and configured
23
- *
24
- * @param resolve A block called with a boolean value indicating whether the result.
25
- * @param reject A block called if an error occurs.
26
- */
27
- RCT_EXPORT_METHOD(getAvailableDataSources: (NSDictionary *) options
10
+ RCT_EXTERN_METHOD(presentDataSourceView: (NSDictionary *) options
28
11
  resolve:(RCTPromiseResolveBlock)resolve
29
- reject:(RCTPromiseRejectBlock)reject) {
30
-
31
- [self checkSourcesInstance];
12
+ reject:(RCTPromiseRejectBlock)reject)
32
13
 
33
- NSString *redirectURL = [RCTConvert NSString:options[@"redirectURL"]];
34
-
35
- [sourceManager getAvailableDataSourcesWithRedirectURL:redirectURL
36
- completion:^(NSArray<NSDictionary<NSString *,id> *> * _Nullable sources, NSError * _Nullable error) {
37
- if (error) {
38
- reject(error.description, error.localizedDescription, error);
39
- return;
40
- }
14
+ RCT_EXTERN_METHOD(revokeDataSource: (NSString *) options
15
+ resolve:(RCTPromiseResolveBlock)resolve
16
+ reject:(RCTPromiseRejectBlock)reject)
41
17
 
42
- if (sources) {
43
- resolve(sources);
44
- return;
45
- }
46
-
47
- resolve([NSDictionary dictionary]);
48
- }];
49
- }
18
+ RCT_EXTERN_METHOD(getAuthorizedDataSources: (RCTPromiseResolveBlock)resolve
19
+ reject:(RCTPromiseRejectBlock)reject)
50
20
 
51
- /**
52
- * Check the authorizers and present a default view.
53
- *
54
- * @param resolve A block called with a boolean value indicating whether the result.
55
- * @param reject A block called if an error occurs.
56
- */
57
- RCT_EXPORT_METHOD(presentDataSourceView: (NSDictionary *) options
21
+ RCT_EXTERN_METHOD(getDataSourceAuthorizer: (NSDictionary *) options
58
22
  resolve:(RCTPromiseResolveBlock)resolve
59
- reject:(RCTPromiseRejectBlock)reject) {
60
- [self checkSourcesInstance];
61
-
62
- dispatch_async(dispatch_get_main_queue(), ^{
63
- NSString *redirectURL = [RCTConvert NSString:options[@"redirectURL"]];
64
-
65
- [sourceManager presentDataSourceViewWithRedirectURL:redirectURL completion:^(BOOL succeed, NSError * _Nullable error) {
66
- if (error) {
67
- reject(error.description, error.localizedDescription, error);
68
- return;
69
- }
70
-
71
- resolve(@(succeed));
72
- }];
73
- });
74
- }
23
+ reject:(RCTPromiseRejectBlock)reject)
75
24
 
76
- /**
77
- * Revoke the access to a API source
78
- *
79
- * @param resolve A block called with a boolean value indicating whether the result is.
80
- * @param reject A block called if an error occurs, such as Apple Health not being installed.
81
- */
82
- RCT_EXPORT_METHOD(revokeDataSource: (NSString *) source
83
- resolve:(RCTPromiseResolveBlock)resolve
84
- reject:(RCTPromiseRejectBlock)reject) {
25
+ RCT_EXTERN_METHOD(getAuthorizedDataSourcesV2:(RCTPromiseResolveBlock)resolve
26
+ reject:(RCTPromiseRejectBlock)reject)
27
+ @end
85
28
 
86
- [self checkUserInstance];
29
+ /*
30
+ @implementation RookSourcesModule
87
31
 
88
- dispatch_async(dispatch_get_main_queue(), ^{
89
- [sourceUserManager revokeDataSourceWithDataSource:source completion:^(BOOL succeed, NSError * _Nullable error) {
90
- if (error) {
91
- reject(error.description, error.localizedDescription, error);
92
- return;
93
- }
94
-
95
- resolve(@(succeed));
96
- }];
97
- });
98
- }
32
+ RCT_EXPORT_MODULE()
99
33
 
100
- RCT_EXPORT_METHOD(getAuthorizedDataSources: (RCTPromiseResolveBlock) resolve
101
- reject:(RCTPromiseRejectBlock)reject ) {
102
-
103
- [self checkSourcesInstance];
34
+ DataSourceManagerObjc *sourceManager;
35
+ UserManager* sourceUserManager;
104
36
 
105
- [sourceManager getAuthorizedDataSourcesWithCompletion:^(NSArray<NSDictionary<NSString *,id> *> * _Nullable sources, NSError * _Nullable error) {
106
- if(error) {
107
- reject(error.description, error.localizedDescription, error);
108
- return;
109
- }
110
-
111
- resolve(sources);
112
- }];
37
+ - (void) checkUserInstance {
38
+ if (sourceUserManager == nil) sourceUserManager = [UserManager new];
113
39
  }
114
40
 
41
+ - (void) checkSourcesInstance {
42
+ if (sourceManager == nil) sourceManager = [DataSourceManagerObjc new];
43
+ }
44
+
115
45
  RCT_EXPORT_METHOD(getDataSourceAuthorizer:(NSDictionary *)params
116
46
  resolve:(RCTPromiseResolveBlock) resolve
117
47
  reject:(RCTPromiseRejectBlock)reject ) {
@@ -134,3 +64,4 @@ RCT_EXPORT_METHOD(getDataSourceAuthorizer:(NSDictionary *)params
134
64
  }
135
65
 
136
66
  @end
67
+ */
package/ios/RookSync.h ADDED
@@ -0,0 +1,5 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RookSync: NSObject<RCTBridgeModule>
4
+
5
+ @end
package/ios/RookSync.m ADDED
@@ -0,0 +1,27 @@
1
+ //
2
+ // RookSync.m
3
+ // react-native-rook-sdk
4
+ //
5
+ // Created by Javier Villanueva on 15/09/25.
6
+ //
7
+
8
+ #import <React/RCTBridgeModule.h>
9
+
10
+ @interface RCT_EXTERN_MODULE(RookSync, NSObject)
11
+
12
+ RCT_EXTERN_METHOD(sync: (RCTResponseSenderBlock) callback)
13
+
14
+ RCT_EXTERN_METHOD(syncByDate: (NSString *) date
15
+ callback: (RCTResponseSenderBlock)callback)
16
+
17
+ RCT_EXTERN_METHOD(syncByDefinition: (NSString *) summary
18
+ syncDate: (NSString *) date
19
+ callback: (RCTResponseSenderBlock)callback)
20
+
21
+ RCT_EXTERN_METHOD(syncEvent:(NSString *) syncDate
22
+ event: (NSString *) event
23
+ resolve: (RCTPromiseResolveBlock) resolve
24
+ reject:(RCTPromiseRejectBlock)reject)
25
+
26
+
27
+ @end
@@ -0,0 +1,135 @@
1
+ //
2
+ // RookSyncModule.swift
3
+ // react-native-rook-sdk
4
+ //
5
+ // Created by Javier Villanueva on 15/09/25.
6
+ //
7
+
8
+ import RookSDK
9
+
10
+ @objc(RookSync)
11
+ public class RookSync: NSObject {
12
+ lazy var summaryManager: RookSummaryManager = {
13
+ return RookSummaryManager()
14
+ }()
15
+
16
+ lazy var eventManager: RookEventsManager = {
17
+ return RookEventsManager()
18
+ }()
19
+
20
+ @objc(sync:)
21
+ public func sync(_ callback: @escaping RCTResponseSenderBlock) {
22
+ Task {
23
+ do {
24
+ let result = try await summaryManager.sync()
25
+
26
+ DispatchQueue.main.async {
27
+ callback([NSNull(), result])
28
+ }
29
+ } catch {
30
+ DispatchQueue.main.async {
31
+ callback([error.localizedDescription, false])
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ @objc(syncByDate:callback:)
38
+ public func syncByDate(_ date: String, callback: @escaping RCTResponseSenderBlock) {
39
+ Task {
40
+ do {
41
+
42
+ guard let parsed = parseStringToDate(date) else {
43
+ let error: [String: Any] = [
44
+ "code": "INVALID_DATE",
45
+ "message": "The date provided is not valid",
46
+ ]
47
+
48
+ callback([error, false])
49
+ return
50
+ }
51
+
52
+ let result = try await summaryManager.sync(parsed)
53
+
54
+ DispatchQueue.main.async {
55
+ callback([NSNull(), result])
56
+ }
57
+
58
+ } catch {
59
+ DispatchQueue.main.async {
60
+ callback([error.localizedDescription, false])
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ @objc(syncByDefinition:syncDate:callback:)
67
+ public func syncByDefinition(_ summary: String, syncDate date: String, callback: @escaping RCTResponseSenderBlock) {
68
+ Task {
69
+ do {
70
+ guard let parsed = parseStringToDate(date) else {
71
+ let error: [String: Any] = [
72
+ "code": "INVALID_DATE",
73
+ "message": "The date provided is not valid",
74
+ ]
75
+
76
+ callback([error, false])
77
+ return
78
+ }
79
+
80
+ guard let type = RookSDK.SummaryTypeToUpload(rawValue: summary) else {
81
+ let error: [String: Any] = [
82
+ "code": "INVALID_SUMMARY_TYPE",
83
+ "message": "The summary type provided is not valid",
84
+ ]
85
+
86
+ callback([error, false])
87
+ return
88
+ }
89
+
90
+ let result = try await summaryManager.sync(parsed, [type])
91
+
92
+ DispatchQueue.main.async {
93
+ callback([NSNull(), result])
94
+ }
95
+
96
+ } catch {
97
+ DispatchQueue.main.async {
98
+ callback([error.localizedDescription, false])
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ @objc(syncEvent:event:resolve:reject:)
105
+ public func syncEvent(
106
+ _ syncDate: String, event: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock
107
+ ) {
108
+ guard let parsed = parseStringToDate(syncDate) else {
109
+ reject("AppleHealthSyncEventError", "Invalid date format", nil)
110
+ return
111
+ }
112
+
113
+ guard let type = RookSDK.EventTypeToUpload(rawValue: event) else {
114
+ reject("AppleHealthSyncEventError", "Invalid event type", nil)
115
+ return
116
+ }
117
+
118
+ Task {
119
+ do {
120
+ let result = try await eventManager.syncEvents(date: parsed, eventType: type)
121
+ resolve(result)
122
+ } catch {
123
+ reject("AppleHealthSyncEventError", error.localizedDescription, nil)
124
+ }
125
+ }
126
+
127
+ }
128
+
129
+ func parseStringToDate(_ input: String) -> Date? {
130
+ let dateFormatter = DateFormatter()
131
+ dateFormatter.dateFormat = "yyyy-MM-dd"
132
+ return dateFormatter.date(from: input)
133
+ }
134
+
135
+ }
@@ -2,4 +2,4 @@
2
2
 
3
3
  @interface RookSyncModule : NSObject<RCTBridgeModule>
4
4
 
5
- @end
5
+ @end
@@ -1,10 +1,11 @@
1
1
  #import "RookSyncModule.h"
2
2
  #import "RookSDK/RookSDK-Swift.h"
3
3
 
4
- @implementation RookSyncModule
4
+ @implementation RookSyncModule
5
5
 
6
6
  RCT_EXPORT_MODULE()
7
7
 
8
+
8
9
  RookSummaryManager *summaryManager;
9
10
  RookEventsManager *eventsManager;
10
11
 
@@ -381,6 +382,7 @@ RCT_EXPORT_METHOD(syncTodayCaloriesCount: (RCTPromiseResolveBlock) resolve
381
382
 
382
383
  }
383
384
 
385
+ /*
384
386
  RCT_EXPORT_METHOD(sync: (RCTResponseSenderBlock)callback) {
385
387
 
386
388
  [self checkSummariesInstance];
@@ -399,8 +401,9 @@ RCT_EXPORT_METHOD(sync: (RCTResponseSenderBlock)callback) {
399
401
  callback(@[[NSNull null], @(result)]);
400
402
  }
401
403
  }];
402
- }
404
+ }*/
403
405
 
406
+ /*
404
407
  RCT_EXPORT_METHOD(syncByDefinition: (NSString *) summary
405
408
  syncDate: (NSString *) syncDate
406
409
  callback: (RCTResponseSenderBlock)callback) {
@@ -426,8 +429,9 @@ RCT_EXPORT_METHOD(syncByDefinition: (NSString *) summary
426
429
  }
427
430
  }];
428
431
 
429
- }
432
+ }*/
430
433
 
434
+ /*
431
435
  RCT_EXPORT_METHOD(syncByDate: (NSString *) syncDate
432
436
  callback: (RCTResponseSenderBlock)callback) {
433
437
 
@@ -449,8 +453,9 @@ RCT_EXPORT_METHOD(syncByDate: (NSString *) syncDate
449
453
  }
450
454
  }];
451
455
 
452
- }
456
+ }*/
453
457
 
458
+ /*
454
459
  RCT_EXPORT_METHOD(syncEvent:(NSString *) syncDate
455
460
  event: (NSString *) event
456
461
  resolve: (RCTPromiseResolveBlock) resolve
@@ -467,5 +472,5 @@ RCT_EXPORT_METHOD(syncEvent:(NSString *) syncDate
467
472
  resolve(@(result));
468
473
  }];
469
474
 
470
- }
475
+ }*/
471
476
  @end