@logrocket/react-native 0.22.0 → 0.24.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.
@@ -1,5 +1,6 @@
1
1
  #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
2
3
 
3
- @interface LogRocketNativeModule : NSObject <RCTBridgeModule>
4
+ @interface LogRocketNativeModule : RCTEventEmitter <RCTBridgeModule>
4
5
 
5
6
  @end
@@ -6,6 +6,37 @@
6
6
 
7
7
  RCT_EXPORT_MODULE();
8
8
 
9
+ static NSMutableDictionary<NSString *, LROResponseBuilder *> *capturedRequests;
10
+
11
+ - (id)init {
12
+ self = [super init];
13
+
14
+ if (self) {
15
+ capturedRequests = [[NSMutableDictionary alloc] init];
16
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleError:) name:@"LogRocketSDKError" object:nil];
17
+ }
18
+
19
+ return self;
20
+ }
21
+
22
+ -(void)handleError:(NSNotification*)notification
23
+ {
24
+ NSString *errorMessage = notification.userInfo[@"errorMessage"];
25
+ NSNumber *shouldDisableAndFreeMemory = notification.userInfo[@"shouldDisableAndFreeMemory"];
26
+ NSNumber *shouldWarnAboutReduxSize = notification.userInfo[@"shouldWarnAboutReduxSize"];
27
+
28
+ [self sendEventWithName:@"LogRocketSDKOnError" body:@{@"errorMessage": errorMessage, @"shouldDisableAndFreeMemory": shouldDisableAndFreeMemory, @"shouldWarnAboutReduxSize": shouldWarnAboutReduxSize}];
29
+ }
30
+
31
+ + (BOOL)requiresMainQueueSetup {
32
+ return YES;
33
+ }
34
+
35
+ - (NSArray<NSString *> *)supportedEvents {
36
+ return @[@"LogRocketSDKOnError"];
37
+ }
38
+
39
+
9
40
  RCT_EXPORT_METHOD(addLog:(NSString *)level args:(NSArray *)args)
10
41
  {
11
42
  [LROSDK addLogWithLevel:level args:args];
@@ -19,6 +50,75 @@ RCT_EXPORT_METHOD(captureException:(NSString *)message
19
50
  [LROSDK captureExceptionWithErrorMessage:message errorType:errorType exceptionType:exceptionType stackTrace:stackTrace];
20
51
  }
21
52
 
53
+ RCT_EXPORT_METHOD(captureReduxAction:(NSDictionary *)data)
54
+ {
55
+ NSNumber *storeId = data[@"storeId"];
56
+ NSNumber *count = data[@"count"];
57
+ NSNumber *duration = data[@"duration"];
58
+ NSString *stateDelta = data[@"stateDelta"];
59
+ NSString *action = data[@"action"];
60
+
61
+ [LROSDK captureReduxActionWithAction:action storeId:storeId duration:duration stateDelta:stateDelta count:count];
62
+ }
63
+
64
+ RCT_EXPORT_METHOD(captureReduxInitialState:(NSDictionary *)data)
65
+ {
66
+ NSNumber *storeId = data[@"storeId"];
67
+ NSString *state = data[@"state"];
68
+
69
+ [LROSDK captureReduxInitialStateWithState:state storeId:storeId];
70
+ }
71
+
72
+ RCT_EXPORT_METHOD(captureRequest:(NSString *)reqID request:(NSDictionary *)request)
73
+ {
74
+ LRORequestBuilder *builder = [LROSDK newRequestBuilder];
75
+ builder.url = request[@"url"];
76
+
77
+ if ([request objectForKey:@"body"]) {
78
+ NSDictionary *arson = [request objectForKey:@"body"];
79
+ if (arson && [arson objectForKey:@"arson"]) {
80
+ builder.arsonBody = [arson objectForKey:@"arson"];
81
+ }
82
+ }
83
+
84
+ if ([request objectForKey:@"method"]) {
85
+ builder.method = [request objectForKey:@"method"];
86
+ }
87
+
88
+ if ([request objectForKey:@"headers"]) {
89
+ builder.headers = [request objectForKey:@"headers"];
90
+ }
91
+
92
+ capturedRequests[reqID] = [builder capture];
93
+ }
94
+
95
+ RCT_EXPORT_METHOD(captureResponse:(NSString *)reqID response:(NSDictionary *)response)
96
+ {
97
+ LROResponseBuilder *builder = capturedRequests[reqID];
98
+
99
+ if (builder) {
100
+ if ([response objectForKey:@"body"]) {
101
+ NSDictionary *arson = [response objectForKey:@"body"];
102
+ if (arson && [arson objectForKey:@"arson"]) {
103
+ builder.arsonBody = [arson objectForKey:@"arson"];
104
+ }
105
+ }
106
+
107
+ if ([response objectForKey:@"statusCode"]) {
108
+ NSNumber *statusCode = (NSNumber *) [response objectForKey:@"statusCode"];
109
+ builder.status = [statusCode longValue];
110
+ }
111
+
112
+ if ([response objectForKey:@"headers"]) {
113
+ builder.headers = [response objectForKey:@"headers"];
114
+ }
115
+
116
+ [builder capture];
117
+ }
118
+
119
+ [capturedRequests removeObjectForKey:reqID];
120
+ }
121
+
22
122
  RCT_EXPORT_METHOD(getSessionURL:(RCTResponseSenderBlock)callback)
23
123
  {
24
124
  void (^completion)(NSString*) = ^(NSString* sessionURL) {
@@ -88,4 +188,26 @@ RCT_EXPORT_METHOD(shutdown:(RCTPromiseResolveBlock)resolve
88
188
  }
89
189
  }
90
190
 
191
+ RCT_EXPORT_METHOD(track:(NSString *)customEventName eventProperties:(NSDictionary *)eventProperties)
192
+ {
193
+ LROCustomEventBuilder *builder = [[LROCustomEventBuilder alloc] initWithName:customEventName];
194
+
195
+ for (NSString *key in eventProperties) {
196
+ NSDictionary *value = [eventProperties objectForKey:key];
197
+
198
+ if ([value objectForKey:@"doubleVal"]) {
199
+ NSArray *doubleArray = [value objectForKey:@"doubleVal"];
200
+ [builder putDoubleArray:key value:doubleArray];
201
+ } else if ([value objectForKey:@"boolVal"]) {
202
+ NSArray *boolArray = [value objectForKey:@"boolVal"];
203
+ [builder putBoolArray:key value:boolArray];
204
+ } else if ([value objectForKey:@"stringVal"]) {
205
+ NSArray *stringArray = [value objectForKey:@"stringVal"];
206
+ [builder putStringArray:key value:stringArray];
207
+ }
208
+ }
209
+
210
+ [LROSDK track:builder];
211
+ }
212
+
91
213
  @end
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,c,m,swift}"
17
17
  s.requires_arc = true
18
18
 
19
- s.dependency "LogRocket", "0.22.0"
19
+ s.dependency "LogRocket", "0.24.0"
20
20
  s.dependency "React"
21
21
  end
22
22
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@logrocket/react-native",
3
3
  "title": "Logrocket Native Module",
4
- "version": "0.22.0",
4
+ "version": "0.24.0",
5
5
  "description": "LogRocket SDK for react-native",
6
6
  "typings": "types.d.ts",
7
7
  "files": [
@@ -43,7 +43,7 @@
43
43
  "@apphub/logrocket-redux": "^0.0.85",
44
44
  "@apphub/diffpatch": "^0.0.85",
45
45
  "jest": "^26.6.3",
46
- "react-native": "0.63.4",
46
+ "react-native": "0.66.4",
47
47
  "@babel/core": "^7.13.15",
48
48
  "@babel/preset-env": "^7.13.15",
49
49
  "babel-jest": "^26.6.3"