react-native-rook-sdk 2.0.3 → 2.1.0-rc.1
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/android/src/main/java/com/rooksdk/RookSdkPackage.kt +3 -1
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +247 -0
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +17 -1
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +19 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/LocalDateSerializer.kt +21 -0
- package/ios/EncodableDataSource.swift +32 -0
- package/ios/EncodableDataSourceAuthorizer.swift +32 -0
- package/ios/EncodableRookDataSource.swift +36 -0
- package/ios/EncodableStatusDataSources.swift +47 -0
- package/ios/RookExternalModule.h +5 -0
- package/ios/RookExternalModule.m +27 -0
- package/ios/RookLocalData.swift +152 -0
- package/ios/RookSdk.mm +1 -0
- package/ios/RookSources.swift +148 -0
- package/ios/RookSourcesModule.mm +29 -98
- package/ios/RookSync.h +5 -0
- package/ios/RookSync.m +27 -0
- package/ios/RookSync.swift +135 -0
- package/ios/RookSyncModule.h +1 -1
- package/ios/RookSyncModule.mm +10 -5
- package/ios/SwiftTest.swift +18 -0
- package/ios/react-native-rook-sdk-Bridging-Header.h +12 -0
- package/lib/commonjs/hooks/index.js +7 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useRookData.js +100 -0
- package/lib/commonjs/hooks/useRookData.js.map +1 -0
- package/lib/commonjs/hooks/useRookDataSources.js +17 -6
- package/lib/commonjs/hooks/useRookDataSources.js.map +1 -1
- package/lib/commonjs/hooks/useRookSync.js +1 -1
- package/lib/commonjs/hooks/useRookSync.js.map +1 -1
- package/lib/commonjs/types/ActivityEvent.js +6 -0
- package/lib/commonjs/types/ActivityEvent.js.map +1 -0
- package/lib/commonjs/types/BodySummary.js +6 -0
- package/lib/commonjs/types/BodySummary.js.map +1 -0
- package/lib/commonjs/types/PhysicalSummary.js +6 -0
- package/lib/commonjs/types/PhysicalSummary.js.map +1 -0
- package/lib/commonjs/types/SleepSummary.js +6 -0
- package/lib/commonjs/types/SleepSummary.js.map +1 -0
- package/lib/commonjs/types/SummaryTypes.js +2 -0
- package/lib/commonjs/types/SummaryTypes.js.map +1 -0
- package/lib/commonjs/utils/getNativeModule.js +1 -1
- package/lib/commonjs/utils/getNativeModule.js.map +1 -1
- package/lib/commonjs/utils/nativeModules.js +5 -2
- package/lib/commonjs/utils/nativeModules.js.map +1 -1
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useRookData.js +92 -0
- package/lib/module/hooks/useRookData.js.map +1 -0
- package/lib/module/hooks/useRookDataSources.js +17 -6
- package/lib/module/hooks/useRookDataSources.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +1 -1
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/types/ActivityEvent.js +2 -0
- package/lib/module/types/ActivityEvent.js.map +1 -0
- package/lib/module/types/BodySummary.js +2 -0
- package/lib/module/types/BodySummary.js.map +1 -0
- package/lib/module/types/PhysicalSummary.js +2 -0
- package/lib/module/types/PhysicalSummary.js.map +1 -0
- package/lib/module/types/SleepSummary.js +2 -0
- package/lib/module/types/SleepSummary.js.map +1 -0
- package/lib/module/types/SummaryTypes.js +2 -0
- package/lib/module/types/SummaryTypes.js.map +1 -0
- package/lib/module/utils/getNativeModule.js +1 -1
- package/lib/module/utils/getNativeModule.js.map +1 -1
- package/lib/module/utils/nativeModules.js +5 -2
- package/lib/module/utils/nativeModules.js.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +18 -0
- package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookDataSources.d.ts +2 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +1 -1
- package/lib/typescript/src/types/ActivityEvent.d.ts +137 -0
- package/lib/typescript/src/types/ActivityEvent.d.ts.map +1 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts +5 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/BodySummary.d.ts +99 -0
- package/lib/typescript/src/types/BodySummary.d.ts.map +1 -0
- package/lib/typescript/src/types/PhysicalSummary.d.ts +70 -0
- package/lib/typescript/src/types/PhysicalSummary.d.ts.map +1 -0
- package/lib/typescript/src/types/SleepSummary.d.ts +57 -0
- package/lib/typescript/src/types/SleepSummary.d.ts.map +1 -0
- package/lib/typescript/src/types/SummaryTypes.d.ts +59 -0
- package/lib/typescript/src/types/SummaryTypes.d.ts.map +1 -0
- package/lib/typescript/src/utils/nativeModules.d.ts +3 -0
- package/lib/typescript/src/utils/nativeModules.d.ts.map +1 -1
- package/package.json +22 -22
- package/react-native-rook-sdk.podspec +5 -3
|
@@ -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
|
+
}
|
package/ios/RookSourcesModule.mm
CHANGED
|
@@ -1,117 +1,47 @@
|
|
|
1
1
|
#import "RookSourcesModule.h"
|
|
2
|
-
#import
|
|
3
|
-
#import "RCTConvert.h"
|
|
2
|
+
#import <React/RCTBridgeModule.h>
|
|
4
3
|
|
|
5
|
-
@
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
+
/*
|
|
30
|
+
@implementation RookSourcesModule
|
|
87
31
|
|
|
88
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
[self checkSourcesInstance];
|
|
34
|
+
DataSourceManagerObjc *sourceManager;
|
|
35
|
+
UserManager* sourceUserManager;
|
|
104
36
|
|
|
105
|
-
|
|
106
|
-
|
|
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
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
|
+
}
|
package/ios/RookSyncModule.h
CHANGED
package/ios/RookSyncModule.mm
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
// La clase debe heredar de NSObject y tener @objc para ser visible
|
|
4
|
+
@objc(SwiftTest)
|
|
5
|
+
public class SwiftTest: NSObject {
|
|
6
|
+
|
|
7
|
+
// Un método estático (de clase) que también debe ser @objc
|
|
8
|
+
@objc
|
|
9
|
+
public static func getGreeting(name: String) -> String {
|
|
10
|
+
return "Hello, \(name) from Swift! 👋"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Un método de instancia
|
|
14
|
+
@objc
|
|
15
|
+
public func showMessage() {
|
|
16
|
+
print("This is a message from a Swift instance.")
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// react-native-rook-sdk-Bridging-Header.h
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Javier Villanueva on 04/09/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef react_native_rook_sdk_Bridging_Header_h
|
|
9
|
+
#define react_native_rook_sdk_Bridging_Header_h
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#endif /* react_native_rook_sdk_Bridging_Header_h */
|
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "useRookConfiguration", {
|
|
|
27
27
|
return _useRookConfiguration.useRookConfiguration;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "useRookData", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _useRookData.useRookData;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "useRookDataSources", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
|
@@ -80,4 +86,5 @@ var _useRookPermissions = require("./useRookPermissions");
|
|
|
80
86
|
var _useRookSummaries = require("./useRookSummaries");
|
|
81
87
|
var _useRookSync = require("./useRookSync");
|
|
82
88
|
var _useRookVariables = require("./useRookVariables");
|
|
89
|
+
var _useRookData = require("./useRookData");
|
|
83
90
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useRookAndroidBackgroundSteps","require","_useRookAppleHealth","_useRookAppleHealthVariables","_useRookConfiguration","_useRookDataSources","_useRookEvents","_useRookHealthConnect","_useRookPermissions","_useRookSummaries","_useRookSync","_useRookVariables"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_useRookAndroidBackgroundSteps","require","_useRookAppleHealth","_useRookAppleHealthVariables","_useRookConfiguration","_useRookDataSources","_useRookEvents","_useRookHealthConnect","_useRookPermissions","_useRookSummaries","_useRookSync","_useRookVariables","_useRookData"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,8BAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,4BAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,qBAAA,GAAAN,OAAA;AACA,IAAAO,mBAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,YAAA,GAAAX,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRookData = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _getNativeModule = _interopRequireDefault(require("../utils/getNativeModule"));
|
|
10
|
+
var _isModuleReady = require("../utils/isModuleReady");
|
|
11
|
+
var _isValidDate = require("../utils/isValidDate");
|
|
12
|
+
var _nativeModules = _interopRequireDefault(require("../utils/nativeModules"));
|
|
13
|
+
var _RookSyncGateContext = require("../context/RookSyncGateContext");
|
|
14
|
+
var _SDKSources = require("../types/SDKSources");
|
|
15
|
+
var _packageInfo = require("../utils/packageInfo");
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
const useRookData = () => {
|
|
18
|
+
const rookData = (0, _react.useRef)((0, _getNativeModule.default)(_reactNative.Platform.select({
|
|
19
|
+
android: () => _nativeModules.default.android.LOCAL_DATA,
|
|
20
|
+
default: () => _nativeModules.default.ios.LOCAL_DATA
|
|
21
|
+
})()));
|
|
22
|
+
const {
|
|
23
|
+
state: {
|
|
24
|
+
ready
|
|
25
|
+
}
|
|
26
|
+
} = (0, _RookSyncGateContext.useRookSyncGateContext)();
|
|
27
|
+
const getSleepSummary = async ({
|
|
28
|
+
date,
|
|
29
|
+
source
|
|
30
|
+
}) => {
|
|
31
|
+
(0, _isModuleReady.isModuleReady)(ready);
|
|
32
|
+
(0, _isValidDate.isValidDate)(date);
|
|
33
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.SAMSUNG_HEALTH) {
|
|
34
|
+
const result = await rookData.current.getSamsungSleepSummary(date);
|
|
35
|
+
return JSON.parse(result);
|
|
36
|
+
}
|
|
37
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.HEALTH_CONNECT) {
|
|
38
|
+
const result = await rookData.current.getHealthConnectSleepSummary(date);
|
|
39
|
+
return JSON.parse(result);
|
|
40
|
+
}
|
|
41
|
+
return rookData.current.getAppleHealthSleepSummary(date);
|
|
42
|
+
};
|
|
43
|
+
const getPhysicalSummary = async ({
|
|
44
|
+
date,
|
|
45
|
+
source
|
|
46
|
+
}) => {
|
|
47
|
+
(0, _isModuleReady.isModuleReady)(ready);
|
|
48
|
+
(0, _isValidDate.isValidDate)(date);
|
|
49
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.SAMSUNG_HEALTH) {
|
|
50
|
+
const result = await rookData.current.getSamsungPhysicalSummary(date);
|
|
51
|
+
return JSON.parse(result);
|
|
52
|
+
}
|
|
53
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.HEALTH_CONNECT) {
|
|
54
|
+
const result = await rookData.current.getHealthConnectPhysicalSummary(date);
|
|
55
|
+
return JSON.parse(result);
|
|
56
|
+
}
|
|
57
|
+
return rookData.current.getAppleHealthPhysicalSummary(date);
|
|
58
|
+
};
|
|
59
|
+
const getBodySummary = async ({
|
|
60
|
+
date,
|
|
61
|
+
source
|
|
62
|
+
}) => {
|
|
63
|
+
(0, _isModuleReady.isModuleReady)(ready);
|
|
64
|
+
(0, _isValidDate.isValidDate)(date);
|
|
65
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.SAMSUNG_HEALTH) {
|
|
66
|
+
const result = await rookData.current.getSamsungBodySummary(date);
|
|
67
|
+
return JSON.parse(result);
|
|
68
|
+
}
|
|
69
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.HEALTH_CONNECT) {
|
|
70
|
+
const result = await rookData.current.getHealthConnectBodySummary(date);
|
|
71
|
+
return JSON.parse(result);
|
|
72
|
+
}
|
|
73
|
+
return rookData.current.getAppleHealthBodySummary(date);
|
|
74
|
+
};
|
|
75
|
+
const getActivityEvents = async ({
|
|
76
|
+
date,
|
|
77
|
+
source
|
|
78
|
+
}) => {
|
|
79
|
+
(0, _isModuleReady.isModuleReady)(ready);
|
|
80
|
+
(0, _isValidDate.isValidDate)(date);
|
|
81
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.SAMSUNG_HEALTH) {
|
|
82
|
+
const result = await rookData.current.getSamsungActivityEvents(date);
|
|
83
|
+
return JSON.parse(result);
|
|
84
|
+
}
|
|
85
|
+
if (_packageInfo.packageInfo.isAndroid && source === _SDKSources.SDKDataSource.HEALTH_CONNECT) {
|
|
86
|
+
const result = await rookData.current.getHealthConnectActivityEvents(date);
|
|
87
|
+
return JSON.parse(result);
|
|
88
|
+
}
|
|
89
|
+
return rookData.current.getAppleHealthActivityEvents(date);
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
ready,
|
|
93
|
+
getSleepSummary,
|
|
94
|
+
getPhysicalSummary,
|
|
95
|
+
getBodySummary,
|
|
96
|
+
getActivityEvents
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
exports.useRookData = useRookData;
|
|
100
|
+
//# sourceMappingURL=useRookData.js.map
|