@oodle-ai/mobile-sdk-reactnative 0.0.0-stage → 0.1.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 (166) hide show
  1. package/LICENSE +201 -0
  2. package/OodleMobileSdkReactNative.podspec +24 -0
  3. package/README.md +191 -2
  4. package/android/build.gradle +55 -0
  5. package/android/proguard-rules.pro +5 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/java/ai/oodle/rum/Connectivity.kt +19 -0
  8. package/android/src/main/java/ai/oodle/rum/CrashReporter.kt +88 -0
  9. package/android/src/main/java/ai/oodle/rum/DeviceInfo.kt +50 -0
  10. package/android/src/main/java/ai/oodle/rum/ExitReasons.kt +104 -0
  11. package/android/src/main/java/ai/oodle/rum/NativeEvents.kt +24 -0
  12. package/android/src/main/java/ai/oodle/rum/OodleRumModule.kt +96 -0
  13. package/android/src/main/java/ai/oodle/rum/OodleRumPackage.kt +26 -0
  14. package/android/src/main/java/ai/oodle/rum/Storage.kt +84 -0
  15. package/android/src/main/java/ai/oodle/rum/Vitals.kt +188 -0
  16. package/android/src/main/java/ai/oodle/rum/Watchdog.kt +81 -0
  17. package/android/src/main/java/ai/oodle/rum/WireframeCapture.kt +398 -0
  18. package/bin/oodle-rum-upload.mjs +104 -0
  19. package/ios/OodleCrashReporter.h +16 -0
  20. package/ios/OodleCrashReporter.m +202 -0
  21. package/ios/OodleRum.h +18 -0
  22. package/ios/OodleRum.mm +129 -0
  23. package/ios/OodleRumImpl.swift +450 -0
  24. package/ios/WireframeWalker.swift +279 -0
  25. package/lib/core/clock.d.ts +19 -0
  26. package/lib/core/clock.js +47 -0
  27. package/lib/core/clock.js.map +1 -0
  28. package/lib/core/config.d.ts +142 -0
  29. package/lib/core/config.js +178 -0
  30. package/lib/core/config.js.map +1 -0
  31. package/lib/core/consent.d.ts +5 -0
  32. package/lib/core/consent.js +33 -0
  33. package/lib/core/consent.js.map +1 -0
  34. package/lib/core/context.d.ts +36 -0
  35. package/lib/core/context.js +172 -0
  36. package/lib/core/context.js.map +1 -0
  37. package/lib/core/flags.d.ts +3 -0
  38. package/lib/core/flags.js +20 -0
  39. package/lib/core/flags.js.map +1 -0
  40. package/lib/core/ids.d.ts +7 -0
  41. package/lib/core/ids.js +40 -0
  42. package/lib/core/ids.js.map +1 -0
  43. package/lib/core/internal.d.ts +6 -0
  44. package/lib/core/internal.js +10 -0
  45. package/lib/core/internal.js.map +1 -0
  46. package/lib/core/logger.d.ts +8 -0
  47. package/lib/core/logger.js +38 -0
  48. package/lib/core/logger.js.map +1 -0
  49. package/lib/core/native.d.ts +71 -0
  50. package/lib/core/native.js +156 -0
  51. package/lib/core/native.js.map +1 -0
  52. package/lib/core/rate-limiter.d.ts +7 -0
  53. package/lib/core/rate-limiter.js +31 -0
  54. package/lib/core/rate-limiter.js.map +1 -0
  55. package/lib/core/session.d.ts +51 -0
  56. package/lib/core/session.js +196 -0
  57. package/lib/core/session.js.map +1 -0
  58. package/lib/core/size.d.ts +15 -0
  59. package/lib/core/size.js +68 -0
  60. package/lib/core/size.js.map +1 -0
  61. package/lib/core/tags.d.ts +10 -0
  62. package/lib/core/tags.js +33 -0
  63. package/lib/core/tags.js.map +1 -0
  64. package/lib/core/telemetry.d.ts +6 -0
  65. package/lib/core/telemetry.js +37 -0
  66. package/lib/core/telemetry.js.map +1 -0
  67. package/lib/core/tracing.d.ts +9 -0
  68. package/lib/core/tracing.js +57 -0
  69. package/lib/core/tracing.js.map +1 -0
  70. package/lib/core/transport.d.ts +76 -0
  71. package/lib/core/transport.js +560 -0
  72. package/lib/core/transport.js.map +1 -0
  73. package/lib/core/user.d.ts +12 -0
  74. package/lib/core/user.js +41 -0
  75. package/lib/core/user.js.map +1 -0
  76. package/lib/events/actions.d.ts +13 -0
  77. package/lib/events/actions.js +147 -0
  78. package/lib/events/actions.js.map +1 -0
  79. package/lib/events/emit.d.ts +21 -0
  80. package/lib/events/emit.js +144 -0
  81. package/lib/events/emit.js.map +1 -0
  82. package/lib/events/errors.d.ts +19 -0
  83. package/lib/events/errors.js +257 -0
  84. package/lib/events/errors.js.map +1 -0
  85. package/lib/events/lifecycle.d.ts +7 -0
  86. package/lib/events/lifecycle.js +101 -0
  87. package/lib/events/lifecycle.js.map +1 -0
  88. package/lib/events/longtasks.d.ts +2 -0
  89. package/lib/events/longtasks.js +42 -0
  90. package/lib/events/longtasks.js.map +1 -0
  91. package/lib/events/resources.d.ts +15 -0
  92. package/lib/events/resources.js +156 -0
  93. package/lib/events/resources.js.map +1 -0
  94. package/lib/events/tap-target.d.ts +42 -0
  95. package/lib/events/tap-target.js +191 -0
  96. package/lib/events/tap-target.js.map +1 -0
  97. package/lib/events/view-state.d.ts +13 -0
  98. package/lib/events/view-state.js +25 -0
  99. package/lib/events/view-state.js.map +1 -0
  100. package/lib/events/views.d.ts +21 -0
  101. package/lib/events/views.js +347 -0
  102. package/lib/events/views.js.map +1 -0
  103. package/lib/index.d.ts +16 -0
  104. package/lib/index.js +24 -0
  105. package/lib/index.js.map +1 -0
  106. package/lib/navigation/react-navigation.d.ts +33 -0
  107. package/lib/navigation/react-navigation.js +61 -0
  108. package/lib/navigation/react-navigation.js.map +1 -0
  109. package/lib/react/OodlePrivacy.d.ts +15 -0
  110. package/lib/react/OodlePrivacy.js +13 -0
  111. package/lib/react/OodlePrivacy.js.map +1 -0
  112. package/lib/react/OodleProvider.d.ts +18 -0
  113. package/lib/react/OodleProvider.js +72 -0
  114. package/lib/react/OodleProvider.js.map +1 -0
  115. package/lib/replay/recorder.d.ts +22 -0
  116. package/lib/replay/recorder.js +317 -0
  117. package/lib/replay/recorder.js.map +1 -0
  118. package/lib/replay/rrweb.d.ts +105 -0
  119. package/lib/replay/rrweb.js +335 -0
  120. package/lib/replay/rrweb.js.map +1 -0
  121. package/lib/rum.d.ts +52 -0
  122. package/lib/rum.js +281 -0
  123. package/lib/rum.js.map +1 -0
  124. package/lib/specs/NativeOodleRum.d.ts +43 -0
  125. package/lib/specs/NativeOodleRum.js +5 -0
  126. package/lib/specs/NativeOodleRum.js.map +1 -0
  127. package/lib/version.d.ts +1 -0
  128. package/lib/version.js +6 -0
  129. package/lib/version.js.map +1 -0
  130. package/package.json +91 -4
  131. package/react-native.config.js +10 -0
  132. package/src/core/clock.ts +43 -0
  133. package/src/core/config.ts +344 -0
  134. package/src/core/consent.ts +32 -0
  135. package/src/core/context.ts +189 -0
  136. package/src/core/flags.ts +15 -0
  137. package/src/core/ids.ts +35 -0
  138. package/src/core/internal.ts +6 -0
  139. package/src/core/logger.ts +37 -0
  140. package/src/core/native.ts +201 -0
  141. package/src/core/rate-limiter.ts +34 -0
  142. package/src/core/session.ts +209 -0
  143. package/src/core/size.ts +79 -0
  144. package/src/core/tags.ts +30 -0
  145. package/src/core/telemetry.ts +35 -0
  146. package/src/core/tracing.ts +60 -0
  147. package/src/core/transport.ts +590 -0
  148. package/src/core/user.ts +45 -0
  149. package/src/events/actions.ts +157 -0
  150. package/src/events/emit.ts +131 -0
  151. package/src/events/errors.ts +283 -0
  152. package/src/events/lifecycle.ts +102 -0
  153. package/src/events/longtasks.ts +40 -0
  154. package/src/events/resources.ts +167 -0
  155. package/src/events/tap-target.ts +210 -0
  156. package/src/events/view-state.ts +30 -0
  157. package/src/events/views.ts +356 -0
  158. package/src/index.ts +34 -0
  159. package/src/navigation/react-navigation.ts +72 -0
  160. package/src/react/OodlePrivacy.tsx +25 -0
  161. package/src/react/OodleProvider.tsx +88 -0
  162. package/src/replay/recorder.ts +310 -0
  163. package/src/replay/rrweb.ts +460 -0
  164. package/src/rum.ts +295 -0
  165. package/src/specs/NativeOodleRum.ts +51 -0
  166. package/src/version.ts +2 -0
@@ -0,0 +1,202 @@
1
+ #import "OodleCrashReporter.h"
2
+
3
+ #import <execinfo.h>
4
+ #import <fcntl.h>
5
+ #import <signal.h>
6
+ #import <string.h>
7
+ #import <time.h>
8
+ #import <unistd.h>
9
+
10
+ static NSString *const kExceptionFile = @"crash-exception.json";
11
+ static NSString *const kSignalFile = @"crash-signal.txt";
12
+ /// Written by the JS fatal error handler just before it rethrows.
13
+ static NSString *const kJsCrashMarker = @"js_crash_marker";
14
+ /// A JS fatal reaches native code shortly after the JS handler ran.
15
+ static const NSTimeInterval kJsCrashWindowSeconds = 10;
16
+
17
+ static const int kSignals[] = {SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP, SIGSYS};
18
+ static const int kSignalCount = sizeof(kSignals) / sizeof(kSignals[0]);
19
+
20
+ // The signal handler may only use async-signal-safe calls, so the file
21
+ // path is prepared before any signal arrives.
22
+ static char gSignalPath[1024];
23
+ static struct sigaction gPrevious[NSIG];
24
+ static volatile sig_atomic_t gHandled = 0;
25
+ static NSUncaughtExceptionHandler *gPreviousExceptionHandler = NULL;
26
+ static NSString *gDirectory = nil;
27
+ static BOOL gInstalled = NO;
28
+
29
+ static void WriteAll(int fd, const char *s)
30
+ {
31
+ size_t len = strlen(s);
32
+ while (len > 0) {
33
+ ssize_t n = write(fd, s, len);
34
+ if (n <= 0) return;
35
+ s += n;
36
+ len -= (size_t)n;
37
+ }
38
+ }
39
+
40
+ static void WriteNumber(int fd, long value)
41
+ {
42
+ char buf[24];
43
+ int i = (int)sizeof(buf) - 1;
44
+ buf[i] = '\0';
45
+ BOOL negative = value < 0;
46
+ unsigned long v = negative ? (unsigned long)(-value) : (unsigned long)value;
47
+ do {
48
+ buf[--i] = (char)('0' + (v % 10));
49
+ v /= 10;
50
+ } while (v > 0 && i > 1);
51
+ if (negative) buf[--i] = '-';
52
+ WriteAll(fd, &buf[i]);
53
+ }
54
+
55
+ static void OodleSignalHandler(int sig, siginfo_t *info, void *context)
56
+ {
57
+ // An uncaught NSException ends in abort(); its report is already written.
58
+ if (!gHandled) {
59
+ gHandled = 1;
60
+ int fd = open(gSignalPath, O_WRONLY | O_CREAT | O_TRUNC, 0644);
61
+ if (fd >= 0) {
62
+ WriteAll(fd, "signal ");
63
+ WriteNumber(fd, sig);
64
+ WriteAll(fd, "\ntime ");
65
+ WriteNumber(fd, (long)time(NULL));
66
+ WriteAll(fd, "\n");
67
+ void *frames[64];
68
+ int count = backtrace(frames, 64);
69
+ backtrace_symbols_fd(frames, count, fd);
70
+ close(fd);
71
+ }
72
+ }
73
+ // Hand the signal to whoever had it before, then let it end the process.
74
+ struct sigaction *previous = &gPrevious[sig];
75
+ if (previous->sa_flags & SA_SIGINFO) {
76
+ if (previous->sa_sigaction) {
77
+ previous->sa_sigaction(sig, info, context);
78
+ return;
79
+ }
80
+ } else if (previous->sa_handler != SIG_DFL && previous->sa_handler != SIG_IGN) {
81
+ previous->sa_handler(sig);
82
+ return;
83
+ }
84
+ sigaction(sig, previous, NULL);
85
+ raise(sig);
86
+ }
87
+
88
+ static BOOL ReportedByJs(NSException *exception)
89
+ {
90
+ // React Native turns a fatal JS error into an RCTFatalException. The JS
91
+ // handler has already recorded it with its JS stack.
92
+ if (![exception.name hasPrefix:@"RCTFatalException"]) return NO;
93
+ NSString *path = [gDirectory stringByAppendingPathComponent:kJsCrashMarker];
94
+ NSString *raw = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
95
+ if (raw.length == 0) return NO;
96
+ NSTimeInterval at = raw.doubleValue / 1000.0;
97
+ return [[NSDate date] timeIntervalSince1970] - at < kJsCrashWindowSeconds;
98
+ }
99
+
100
+ static void OodleExceptionHandler(NSException *exception)
101
+ {
102
+ gHandled = 1;
103
+ @try {
104
+ if (!ReportedByJs(exception)) {
105
+ NSDictionary *crash = @{
106
+ @"timestamp" : @((long long)([[NSDate date] timeIntervalSince1970] * 1000)),
107
+ @"type" : exception.name ?: @"NSException",
108
+ @"message" : exception.reason ?: exception.name ?: @"",
109
+ @"stack" : [exception.callStackSymbols componentsJoinedByString:@"\n"] ?: @"",
110
+ @"source" : @"ios",
111
+ };
112
+ NSData *data = [NSJSONSerialization dataWithJSONObject:crash options:0 error:nil];
113
+ [data writeToFile:[gDirectory stringByAppendingPathComponent:kExceptionFile] atomically:YES];
114
+ }
115
+ } @catch (__unused NSException *ignored) {
116
+ }
117
+ if (gPreviousExceptionHandler) gPreviousExceptionHandler(exception);
118
+ }
119
+
120
+ static NSString *SignalName(int sig)
121
+ {
122
+ switch (sig) {
123
+ case SIGABRT: return @"SIGABRT";
124
+ case SIGBUS: return @"SIGBUS";
125
+ case SIGFPE: return @"SIGFPE";
126
+ case SIGILL: return @"SIGILL";
127
+ case SIGSEGV: return @"SIGSEGV";
128
+ case SIGTRAP: return @"SIGTRAP";
129
+ case SIGSYS: return @"SIGSYS";
130
+ default: return [NSString stringWithFormat:@"SIG%d", sig];
131
+ }
132
+ }
133
+
134
+ @implementation OodleCrashReporter
135
+
136
+ + (BOOL)installWithDirectory:(NSString *)directory
137
+ {
138
+ @synchronized(self) {
139
+ if (gInstalled) return YES;
140
+ gDirectory = [directory copy];
141
+ NSString *signalPath = [directory stringByAppendingPathComponent:kSignalFile];
142
+ strlcpy(gSignalPath, signalPath.fileSystemRepresentation, sizeof(gSignalPath));
143
+
144
+ gPreviousExceptionHandler = NSGetUncaughtExceptionHandler();
145
+ NSSetUncaughtExceptionHandler(&OodleExceptionHandler);
146
+
147
+ struct sigaction action;
148
+ memset(&action, 0, sizeof(action));
149
+ action.sa_sigaction = OodleSignalHandler;
150
+ action.sa_flags = SA_SIGINFO | SA_ONSTACK;
151
+ sigemptyset(&action.sa_mask);
152
+ for (int i = 0; i < kSignalCount; i++) {
153
+ sigaction(kSignals[i], &action, &gPrevious[kSignals[i]]);
154
+ }
155
+ gInstalled = YES;
156
+ return YES;
157
+ }
158
+ }
159
+
160
+ + (nullable NSString *)consumeWithDirectory:(NSString *)directory
161
+ {
162
+ NSFileManager *fm = [NSFileManager defaultManager];
163
+ NSString *exceptionPath = [directory stringByAppendingPathComponent:kExceptionFile];
164
+ NSString *signalPath = [directory stringByAppendingPathComponent:kSignalFile];
165
+ NSString *result = nil;
166
+
167
+ NSString *exception = [NSString stringWithContentsOfFile:exceptionPath encoding:NSUTF8StringEncoding error:nil];
168
+ if (exception.length > 0) {
169
+ result = exception;
170
+ } else {
171
+ NSString *raw = [NSString stringWithContentsOfFile:signalPath encoding:NSUTF8StringEncoding error:nil];
172
+ if (raw.length > 0) {
173
+ int sig = 0;
174
+ double when = [[NSDate date] timeIntervalSince1970];
175
+ NSMutableArray<NSString *> *frames = [NSMutableArray array];
176
+ for (NSString *line in [raw componentsSeparatedByString:@"\n"]) {
177
+ if ([line hasPrefix:@"signal "]) {
178
+ sig = [[line substringFromIndex:7] intValue];
179
+ } else if ([line hasPrefix:@"time "]) {
180
+ when = [[line substringFromIndex:5] doubleValue];
181
+ } else if (line.length > 0) {
182
+ [frames addObject:line];
183
+ }
184
+ }
185
+ NSString *name = SignalName(sig);
186
+ NSDictionary *crash = @{
187
+ @"timestamp" : @((long long)(when * 1000)),
188
+ @"type" : name,
189
+ @"message" : [NSString stringWithFormat:@"Application crashed with %@", name],
190
+ @"stack" : [frames componentsJoinedByString:@"\n"],
191
+ @"source" : @"ios",
192
+ };
193
+ NSData *data = [NSJSONSerialization dataWithJSONObject:crash options:0 error:nil];
194
+ result = data ? [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] : nil;
195
+ }
196
+ }
197
+ [fm removeItemAtPath:exceptionPath error:nil];
198
+ [fm removeItemAtPath:signalPath error:nil];
199
+ return result;
200
+ }
201
+
202
+ @end
package/ios/OodleRum.h ADDED
@@ -0,0 +1,18 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ // The codegen spec is C++. Swift builds the module of this pod as
4
+ // Objective-C, so the spec is imported only in Objective-C++ files.
5
+ #ifdef __cplusplus
6
+ #import <OodleRumSpec/OodleRumSpec.h>
7
+ #endif
8
+
9
+ NS_ASSUME_NONNULL_BEGIN
10
+
11
+ #ifdef __cplusplus
12
+ @interface OodleRum : NSObject <NativeOodleRumSpec>
13
+ #else
14
+ @interface OodleRum : NSObject
15
+ #endif
16
+ @end
17
+
18
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,129 @@
1
+ #import "OodleRum.h"
2
+ #import "OodleCrashReporter.h"
3
+
4
+ #if __has_include(<OodleMobileSdkReactNative/OodleMobileSdkReactNative-Swift.h>)
5
+ #import <OodleMobileSdkReactNative/OodleMobileSdkReactNative-Swift.h>
6
+ #else
7
+ #import "OodleMobileSdkReactNative-Swift.h"
8
+ #endif
9
+
10
+ // Every method returns a fallback instead of throwing: a failure in
11
+ // monitoring code must never reach the app.
12
+ @implementation OodleRum
13
+
14
+ RCT_EXPORT_MODULE()
15
+
16
+ + (BOOL)requiresMainQueueSetup
17
+ {
18
+ return NO;
19
+ }
20
+
21
+ - (NSString *)getDeviceInfo
22
+ {
23
+ @try {
24
+ return [OodleRumImpl.shared deviceInfo];
25
+ } @catch (NSException *e) {
26
+ return @"{}";
27
+ }
28
+ }
29
+
30
+ - (NSString *_Nullable)storageGet:(NSString *)key
31
+ {
32
+ @try {
33
+ return [OodleRumImpl.shared storageGet:key];
34
+ } @catch (NSException *e) {
35
+ return nil;
36
+ }
37
+ }
38
+
39
+ - (NSNumber *)storageSet:(NSString *)key value:(NSString *)value
40
+ {
41
+ @try {
42
+ return @([OodleRumImpl.shared storageSet:key value:value]);
43
+ } @catch (NSException *e) {
44
+ return @NO;
45
+ }
46
+ }
47
+
48
+ - (void)storageSetAsync:(NSString *)key
49
+ value:(NSString *)value
50
+ resolve:(RCTPromiseResolveBlock)resolve
51
+ reject:(RCTPromiseRejectBlock)reject
52
+ {
53
+ @try {
54
+ [OodleRumImpl.shared storageSetAsync:key value:value done:^(BOOL ok) {
55
+ resolve(@(ok));
56
+ }];
57
+ } @catch (NSException *e) {
58
+ resolve(@NO);
59
+ }
60
+ }
61
+
62
+ - (NSNumber *)storageRemove:(NSString *)key
63
+ {
64
+ @try {
65
+ return @([OodleRumImpl.shared storageRemove:key]);
66
+ } @catch (NSException *e) {
67
+ return @NO;
68
+ }
69
+ }
70
+
71
+ - (NSNumber *)enableCrashReporting
72
+ {
73
+ return @([OodleCrashReporter installWithDirectory:[OodleRumImpl.shared storageDirectory]]);
74
+ }
75
+
76
+ - (NSString *_Nullable)consumePendingCrash
77
+ {
78
+ @try {
79
+ return [OodleCrashReporter consumeWithDirectory:[OodleRumImpl.shared storageDirectory]];
80
+ } @catch (NSException *e) {
81
+ return nil;
82
+ }
83
+ }
84
+
85
+ - (NSNumber *)startWatchdog:(double)thresholdMs
86
+ {
87
+ return @([OodleRumImpl.shared startWatchdog:thresholdMs]);
88
+ }
89
+
90
+ - (NSString *)drainNativeEvents
91
+ {
92
+ return [OodleRumImpl.shared drainNativeEvents];
93
+ }
94
+
95
+ - (NSNumber *)startVitals
96
+ {
97
+ return @([OodleRumImpl.shared startVitals]);
98
+ }
99
+
100
+ - (NSString *)collectVitals
101
+ {
102
+ return [OodleRumImpl.shared collectVitals];
103
+ }
104
+
105
+ - (NSString *)getConnectivity
106
+ {
107
+ return [OodleRumImpl.shared connectivity];
108
+ }
109
+
110
+ - (void)captureWireframes:(NSString *)optionsJson
111
+ resolve:(RCTPromiseResolveBlock)resolve
112
+ reject:(RCTPromiseRejectBlock)reject
113
+ {
114
+ dispatch_async(dispatch_get_main_queue(), ^{
115
+ @try {
116
+ resolve([OodleRumImpl.shared captureWireframes:optionsJson]);
117
+ } @catch (NSException *e) {
118
+ reject(@"capture_failed", e.reason ?: e.name, nil);
119
+ }
120
+ });
121
+ }
122
+
123
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
124
+ (const facebook::react::ObjCTurboModule::InitParams &)params
125
+ {
126
+ return std::make_shared<facebook::react::NativeOodleRumSpecJSI>(params);
127
+ }
128
+
129
+ @end