@rejourneyco/react-native 1.0.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 (152) hide show
  1. package/android/build.gradle.kts +135 -0
  2. package/android/consumer-rules.pro +10 -0
  3. package/android/proguard-rules.pro +1 -0
  4. package/android/src/main/AndroidManifest.xml +15 -0
  5. package/android/src/main/java/com/rejourney/RejourneyModuleImpl.kt +2981 -0
  6. package/android/src/main/java/com/rejourney/capture/ANRHandler.kt +206 -0
  7. package/android/src/main/java/com/rejourney/capture/ActivityTracker.kt +98 -0
  8. package/android/src/main/java/com/rejourney/capture/CaptureEngine.kt +1553 -0
  9. package/android/src/main/java/com/rejourney/capture/CaptureHeuristics.kt +375 -0
  10. package/android/src/main/java/com/rejourney/capture/CrashHandler.kt +153 -0
  11. package/android/src/main/java/com/rejourney/capture/MotionEvent.kt +215 -0
  12. package/android/src/main/java/com/rejourney/capture/SegmentUploader.kt +512 -0
  13. package/android/src/main/java/com/rejourney/capture/VideoEncoder.kt +773 -0
  14. package/android/src/main/java/com/rejourney/capture/ViewHierarchyScanner.kt +633 -0
  15. package/android/src/main/java/com/rejourney/capture/ViewSerializer.kt +286 -0
  16. package/android/src/main/java/com/rejourney/core/Constants.kt +117 -0
  17. package/android/src/main/java/com/rejourney/core/Logger.kt +93 -0
  18. package/android/src/main/java/com/rejourney/core/Types.kt +124 -0
  19. package/android/src/main/java/com/rejourney/lifecycle/SessionLifecycleService.kt +162 -0
  20. package/android/src/main/java/com/rejourney/network/DeviceAuthManager.kt +747 -0
  21. package/android/src/main/java/com/rejourney/network/HttpClientProvider.kt +16 -0
  22. package/android/src/main/java/com/rejourney/network/NetworkMonitor.kt +272 -0
  23. package/android/src/main/java/com/rejourney/network/UploadManager.kt +1363 -0
  24. package/android/src/main/java/com/rejourney/network/UploadWorker.kt +492 -0
  25. package/android/src/main/java/com/rejourney/privacy/PrivacyMask.kt +645 -0
  26. package/android/src/main/java/com/rejourney/touch/GestureClassifier.kt +233 -0
  27. package/android/src/main/java/com/rejourney/touch/KeyboardTracker.kt +158 -0
  28. package/android/src/main/java/com/rejourney/touch/TextInputTracker.kt +181 -0
  29. package/android/src/main/java/com/rejourney/touch/TouchInterceptor.kt +591 -0
  30. package/android/src/main/java/com/rejourney/utils/EventBuffer.kt +284 -0
  31. package/android/src/main/java/com/rejourney/utils/OEMDetector.kt +154 -0
  32. package/android/src/main/java/com/rejourney/utils/PerfTiming.kt +235 -0
  33. package/android/src/main/java/com/rejourney/utils/Telemetry.kt +297 -0
  34. package/android/src/main/java/com/rejourney/utils/WindowUtils.kt +84 -0
  35. package/android/src/newarch/java/com/rejourney/RejourneyModule.kt +187 -0
  36. package/android/src/newarch/java/com/rejourney/RejourneyPackage.kt +40 -0
  37. package/android/src/oldarch/java/com/rejourney/RejourneyModule.kt +218 -0
  38. package/android/src/oldarch/java/com/rejourney/RejourneyPackage.kt +23 -0
  39. package/ios/Capture/RJANRHandler.h +42 -0
  40. package/ios/Capture/RJANRHandler.m +328 -0
  41. package/ios/Capture/RJCaptureEngine.h +275 -0
  42. package/ios/Capture/RJCaptureEngine.m +2062 -0
  43. package/ios/Capture/RJCaptureHeuristics.h +80 -0
  44. package/ios/Capture/RJCaptureHeuristics.m +903 -0
  45. package/ios/Capture/RJCrashHandler.h +46 -0
  46. package/ios/Capture/RJCrashHandler.m +313 -0
  47. package/ios/Capture/RJMotionEvent.h +183 -0
  48. package/ios/Capture/RJMotionEvent.m +183 -0
  49. package/ios/Capture/RJPerformanceManager.h +100 -0
  50. package/ios/Capture/RJPerformanceManager.m +373 -0
  51. package/ios/Capture/RJPixelBufferDownscaler.h +42 -0
  52. package/ios/Capture/RJPixelBufferDownscaler.m +85 -0
  53. package/ios/Capture/RJSegmentUploader.h +146 -0
  54. package/ios/Capture/RJSegmentUploader.m +778 -0
  55. package/ios/Capture/RJVideoEncoder.h +247 -0
  56. package/ios/Capture/RJVideoEncoder.m +1036 -0
  57. package/ios/Capture/RJViewControllerTracker.h +73 -0
  58. package/ios/Capture/RJViewControllerTracker.m +508 -0
  59. package/ios/Capture/RJViewHierarchyScanner.h +215 -0
  60. package/ios/Capture/RJViewHierarchyScanner.m +1464 -0
  61. package/ios/Capture/RJViewSerializer.h +119 -0
  62. package/ios/Capture/RJViewSerializer.m +498 -0
  63. package/ios/Core/RJConstants.h +124 -0
  64. package/ios/Core/RJConstants.m +88 -0
  65. package/ios/Core/RJLifecycleManager.h +85 -0
  66. package/ios/Core/RJLifecycleManager.m +308 -0
  67. package/ios/Core/RJLogger.h +61 -0
  68. package/ios/Core/RJLogger.m +211 -0
  69. package/ios/Core/RJTypes.h +176 -0
  70. package/ios/Core/RJTypes.m +66 -0
  71. package/ios/Core/Rejourney.h +64 -0
  72. package/ios/Core/Rejourney.mm +2495 -0
  73. package/ios/Network/RJDeviceAuthManager.h +94 -0
  74. package/ios/Network/RJDeviceAuthManager.m +967 -0
  75. package/ios/Network/RJNetworkMonitor.h +68 -0
  76. package/ios/Network/RJNetworkMonitor.m +267 -0
  77. package/ios/Network/RJRetryManager.h +73 -0
  78. package/ios/Network/RJRetryManager.m +325 -0
  79. package/ios/Network/RJUploadManager.h +267 -0
  80. package/ios/Network/RJUploadManager.m +2296 -0
  81. package/ios/Privacy/RJPrivacyMask.h +163 -0
  82. package/ios/Privacy/RJPrivacyMask.m +922 -0
  83. package/ios/Rejourney.h +63 -0
  84. package/ios/Touch/RJGestureClassifier.h +130 -0
  85. package/ios/Touch/RJGestureClassifier.m +333 -0
  86. package/ios/Touch/RJTouchInterceptor.h +169 -0
  87. package/ios/Touch/RJTouchInterceptor.m +772 -0
  88. package/ios/Utils/RJEventBuffer.h +112 -0
  89. package/ios/Utils/RJEventBuffer.m +358 -0
  90. package/ios/Utils/RJGzipUtils.h +33 -0
  91. package/ios/Utils/RJGzipUtils.m +89 -0
  92. package/ios/Utils/RJKeychainManager.h +48 -0
  93. package/ios/Utils/RJKeychainManager.m +111 -0
  94. package/ios/Utils/RJPerfTiming.h +209 -0
  95. package/ios/Utils/RJPerfTiming.m +264 -0
  96. package/ios/Utils/RJTelemetry.h +92 -0
  97. package/ios/Utils/RJTelemetry.m +320 -0
  98. package/ios/Utils/RJWindowUtils.h +66 -0
  99. package/ios/Utils/RJWindowUtils.m +133 -0
  100. package/lib/commonjs/NativeRejourney.js +40 -0
  101. package/lib/commonjs/components/Mask.js +79 -0
  102. package/lib/commonjs/index.js +1381 -0
  103. package/lib/commonjs/sdk/autoTracking.js +1259 -0
  104. package/lib/commonjs/sdk/constants.js +151 -0
  105. package/lib/commonjs/sdk/errorTracking.js +199 -0
  106. package/lib/commonjs/sdk/index.js +50 -0
  107. package/lib/commonjs/sdk/metricsTracking.js +204 -0
  108. package/lib/commonjs/sdk/navigation.js +151 -0
  109. package/lib/commonjs/sdk/networkInterceptor.js +412 -0
  110. package/lib/commonjs/sdk/utils.js +363 -0
  111. package/lib/commonjs/types/expo-router.d.js +2 -0
  112. package/lib/commonjs/types/index.js +2 -0
  113. package/lib/module/NativeRejourney.js +38 -0
  114. package/lib/module/components/Mask.js +72 -0
  115. package/lib/module/index.js +1284 -0
  116. package/lib/module/sdk/autoTracking.js +1233 -0
  117. package/lib/module/sdk/constants.js +145 -0
  118. package/lib/module/sdk/errorTracking.js +189 -0
  119. package/lib/module/sdk/index.js +12 -0
  120. package/lib/module/sdk/metricsTracking.js +187 -0
  121. package/lib/module/sdk/navigation.js +143 -0
  122. package/lib/module/sdk/networkInterceptor.js +401 -0
  123. package/lib/module/sdk/utils.js +342 -0
  124. package/lib/module/types/expo-router.d.js +2 -0
  125. package/lib/module/types/index.js +2 -0
  126. package/lib/typescript/NativeRejourney.d.ts +147 -0
  127. package/lib/typescript/components/Mask.d.ts +39 -0
  128. package/lib/typescript/index.d.ts +117 -0
  129. package/lib/typescript/sdk/autoTracking.d.ts +204 -0
  130. package/lib/typescript/sdk/constants.d.ts +120 -0
  131. package/lib/typescript/sdk/errorTracking.d.ts +32 -0
  132. package/lib/typescript/sdk/index.d.ts +9 -0
  133. package/lib/typescript/sdk/metricsTracking.d.ts +58 -0
  134. package/lib/typescript/sdk/navigation.d.ts +33 -0
  135. package/lib/typescript/sdk/networkInterceptor.d.ts +47 -0
  136. package/lib/typescript/sdk/utils.d.ts +148 -0
  137. package/lib/typescript/types/index.d.ts +624 -0
  138. package/package.json +102 -0
  139. package/rejourney.podspec +21 -0
  140. package/src/NativeRejourney.ts +165 -0
  141. package/src/components/Mask.tsx +80 -0
  142. package/src/index.ts +1459 -0
  143. package/src/sdk/autoTracking.ts +1373 -0
  144. package/src/sdk/constants.ts +134 -0
  145. package/src/sdk/errorTracking.ts +231 -0
  146. package/src/sdk/index.ts +11 -0
  147. package/src/sdk/metricsTracking.ts +232 -0
  148. package/src/sdk/navigation.ts +157 -0
  149. package/src/sdk/networkInterceptor.ts +440 -0
  150. package/src/sdk/utils.ts +369 -0
  151. package/src/types/expo-router.d.ts +7 -0
  152. package/src/types/index.ts +739 -0
@@ -0,0 +1,369 @@
1
+ /**
2
+ * Rejourney Utility Functions
3
+ *
4
+ * IMPORTANT: This file uses lazy loading for react-native imports to avoid
5
+ * "PlatformConstants could not be found" errors on RN 0.81+.
6
+ */
7
+
8
+ import type { TouchPoint, GestureType } from '../types';
9
+
10
+ // Lazy-loaded Platform module
11
+ let _Platform: typeof import('react-native').Platform | null = null;
12
+
13
+ function getPlatform(): typeof import('react-native').Platform | null {
14
+ if (_Platform) return _Platform;
15
+ try {
16
+ const RN = require('react-native');
17
+ _Platform = RN.Platform;
18
+ return _Platform;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Generate a unique ID
26
+ */
27
+ export function generateId(): string {
28
+ const timestamp = Date.now().toString(36);
29
+ const randomPart = Math.random().toString(36).substring(2, 9);
30
+ return `${timestamp}-${randomPart}`;
31
+ }
32
+
33
+ /**
34
+ * Generate a session ID
35
+ */
36
+ export function generateSessionId(): string {
37
+ const date = new Date();
38
+ const dateStr = date.toISOString().split('T')[0]?.replace(/-/g, '') ?? '';
39
+ const timeStr = date.toTimeString().split(' ')[0]?.replace(/:/g, '') ?? '';
40
+ const random = Math.random().toString(36).substring(2, 6);
41
+ return `session_${dateStr}_${timeStr}_${random}`;
42
+ }
43
+
44
+ /**
45
+ * Get current timestamp in milliseconds
46
+ */
47
+ export function now(): number {
48
+ return Date.now();
49
+ }
50
+
51
+ /**
52
+ * Check if running in development mode
53
+ */
54
+ export function isDevelopment(): boolean {
55
+ return __DEV__;
56
+ }
57
+
58
+ /**
59
+ * Check platform
60
+ */
61
+ export function isIOS(): boolean {
62
+ const platform = getPlatform();
63
+ return platform?.OS === 'ios';
64
+ }
65
+
66
+ export function isAndroid(): boolean {
67
+ const platform = getPlatform();
68
+ return platform?.OS === 'android';
69
+ }
70
+
71
+ /**
72
+ * Calculate distance between two points
73
+ */
74
+ export function distance(p1: TouchPoint, p2: TouchPoint): number {
75
+ const dx = p2.x - p1.x;
76
+ const dy = p2.y - p1.y;
77
+ return Math.sqrt(dx * dx + dy * dy);
78
+ }
79
+
80
+ /**
81
+ * Calculate velocity between two points
82
+ */
83
+ export function velocity(p1: TouchPoint, p2: TouchPoint): { x: number; y: number } {
84
+ const dt = p2.timestamp - p1.timestamp;
85
+ if (dt === 0) return { x: 0, y: 0 };
86
+ return {
87
+ x: (p2.x - p1.x) / dt,
88
+ y: (p2.y - p1.y) / dt,
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Determine gesture type from touch points
94
+ */
95
+ export function classifyGesture(
96
+ touches: TouchPoint[],
97
+ duration: number
98
+ ): GestureType {
99
+ if (touches.length < 2) {
100
+ if (duration > 500) return 'long_press';
101
+ return 'tap';
102
+ }
103
+
104
+ const first = touches[0];
105
+ const last = touches[touches.length - 1];
106
+
107
+ if (!first || !last) return 'tap';
108
+
109
+ const dx = last.x - first.x;
110
+ const dy = last.y - first.y;
111
+ const dist = distance(first, last);
112
+
113
+ // If very little movement, it's a tap
114
+ if (dist < 10) {
115
+ if (duration > 500) return 'long_press';
116
+ return 'tap';
117
+ }
118
+
119
+ // Determine swipe direction
120
+ const absX = Math.abs(dx);
121
+ const absY = Math.abs(dy);
122
+
123
+ if (absX > absY) {
124
+ return dx > 0 ? 'swipe_right' : 'swipe_left';
125
+ } else {
126
+ return dy > 0 ? 'swipe_down' : 'swipe_up';
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Throttle function execution
132
+ */
133
+ export function throttle<T extends (...args: any[]) => any>(
134
+ fn: T,
135
+ delay: number
136
+ ): (...args: Parameters<T>) => void {
137
+ let lastCall = 0;
138
+ return (...args: Parameters<T>) => {
139
+ const currentTime = now();
140
+ if (currentTime - lastCall >= delay) {
141
+ lastCall = currentTime;
142
+ fn(...args);
143
+ }
144
+ };
145
+ }
146
+
147
+ /**
148
+ * Debounce function execution
149
+ */
150
+ export function debounce<T extends (...args: any[]) => any>(
151
+ fn: T,
152
+ delay: number
153
+ ): (...args: Parameters<T>) => void {
154
+ let timeoutId: ReturnType<typeof setTimeout> | null = null;
155
+ return (...args: Parameters<T>) => {
156
+ if (timeoutId) clearTimeout(timeoutId);
157
+ timeoutId = setTimeout(() => fn(...args), delay);
158
+ };
159
+ }
160
+
161
+ /**
162
+ * Format bytes to human readable string
163
+ */
164
+ export function formatBytes(bytes: number): string {
165
+ if (bytes === 0) return '0 Bytes';
166
+ const k = 1024;
167
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
168
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
169
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
170
+ }
171
+
172
+ /**
173
+ * Format duration to human readable string
174
+ */
175
+ export function formatDuration(ms: number): string {
176
+ const seconds = Math.floor(ms / 1000);
177
+ const minutes = Math.floor(seconds / 60);
178
+ const hours = Math.floor(minutes / 60);
179
+
180
+ if (hours > 0) {
181
+ return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
182
+ }
183
+ if (minutes > 0) {
184
+ return `${minutes}m ${seconds % 60}s`;
185
+ }
186
+ return `${seconds}s`;
187
+ }
188
+
189
+ /**
190
+ * Format timestamp to readable time
191
+ */
192
+ export function formatTime(ms: number): string {
193
+ const totalSeconds = Math.floor(ms / 1000);
194
+ const minutes = Math.floor(totalSeconds / 60);
195
+ const seconds = totalSeconds % 60;
196
+ return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
197
+ }
198
+
199
+ /**
200
+ * Create a simple hash of a string
201
+ */
202
+ export function simpleHash(str: string): string {
203
+ let hash = 0;
204
+ for (let i = 0; i < str.length; i++) {
205
+ const char = str.charCodeAt(i);
206
+ hash = ((hash << 5) - hash) + char;
207
+ hash = hash & hash; // Convert to 32bit integer
208
+ }
209
+ return Math.abs(hash).toString(36);
210
+ }
211
+
212
+ /**
213
+ * Log levels for controlling verbosity.
214
+ *
215
+ * Default behavior minimizes log pollution for integrators:
216
+ * - Release/Production: SILENT (no logs)
217
+ * - Development: ERROR (only critical issues)
218
+ */
219
+ export enum LogLevel {
220
+ DEBUG = 0,
221
+ INFO = 1,
222
+ WARNING = 2,
223
+ ERROR = 3,
224
+ SILENT = 4,
225
+ }
226
+
227
+ /**
228
+ * Logger with production-aware log levels.
229
+ *
230
+ * Designed to minimize log pollution for integrators:
231
+ * - Production/Release: SILENT (completely silent, no logs)
232
+ * - Development/Debug: ERROR (only critical errors)
233
+ *
234
+ * Only essential lifecycle logs (init success, session start/end) bypass
235
+ * these levels via dedicated methods.
236
+ */
237
+ class Logger {
238
+ private prefix = '[Rejourney]';
239
+ private debugMode = false;
240
+
241
+ /**
242
+ * Minimum log level to display.
243
+ *
244
+ * Defaults to SILENT to avoid polluting integrator's console.
245
+ * SDK developers can adjust this for internal debugging.
246
+ *
247
+ * Note: In production builds, this should remain SILENT.
248
+ * The native layers handle build-type detection automatically.
249
+ */
250
+ private minimumLogLevel: LogLevel = typeof __DEV__ !== 'undefined' && __DEV__
251
+ ? LogLevel.ERROR
252
+ : LogLevel.SILENT;
253
+
254
+ /**
255
+ * Set the minimum log level. Logs below this level will be suppressed.
256
+ * SDK developers can use this for internal debugging.
257
+ */
258
+ setLogLevel(level: LogLevel): void {
259
+ this.minimumLogLevel = level;
260
+ }
261
+
262
+ setDebugMode(enabled: boolean): void {
263
+ this.debugMode = enabled;
264
+ this.minimumLogLevel = enabled
265
+ ? LogLevel.DEBUG
266
+ : typeof __DEV__ !== 'undefined' && __DEV__
267
+ ? LogLevel.ERROR
268
+ : LogLevel.SILENT;
269
+ }
270
+
271
+ /** Log a debug message - SDK internal use only */
272
+ debug(...args: any[]): void {
273
+ if (this.minimumLogLevel <= LogLevel.DEBUG) {
274
+ console.log(this.prefix, ...args);
275
+ }
276
+ }
277
+
278
+ /** Log an info message - SDK internal use only */
279
+ info(...args: any[]): void {
280
+ if (this.minimumLogLevel <= LogLevel.INFO) {
281
+ console.info(this.prefix, ...args);
282
+ }
283
+ }
284
+
285
+ /** Log a warning message */
286
+ warn(...args: any[]): void {
287
+ if (this.minimumLogLevel <= LogLevel.WARNING) {
288
+ console.warn(this.prefix, ...args);
289
+ }
290
+ }
291
+
292
+ /** Log an error message */
293
+ error(...args: any[]): void {
294
+ if (this.minimumLogLevel <= LogLevel.ERROR) {
295
+ console.error(this.prefix, ...args);
296
+ }
297
+ }
298
+
299
+ notice(...args: any[]): void {
300
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
301
+ console.info(this.prefix, ...args);
302
+ }
303
+ }
304
+
305
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
306
+ // Lifecycle Logs - Industry standard minimal logging
307
+ // These are the only logs integrators will see in debug builds
308
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
309
+
310
+ /**
311
+ * Log SDK initialization success.
312
+ * Only shown in development builds - this is the minimal "SDK started" log.
313
+ */
314
+ logInitSuccess(version: string): void {
315
+ if (this.debugMode) {
316
+ this.info(`✓ SDK initialized (v${version})`);
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Log SDK initialization failure.
322
+ * Always shown - this is a critical error.
323
+ */
324
+ logInitFailure(reason: string): void {
325
+ console.error(this.prefix, `✗ Initialization failed: ${reason}`);
326
+ }
327
+
328
+ /**
329
+ * Log session start.
330
+ * Only shown in development builds.
331
+ */
332
+ logSessionStart(sessionId: string): void {
333
+ if (this.debugMode) {
334
+ this.info(`Session started: ${sessionId}`);
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Log session end.
340
+ * Only shown in development builds.
341
+ */
342
+ logSessionEnd(sessionId: string): void {
343
+ if (this.debugMode) {
344
+ this.info(`Session ended: ${sessionId}`);
345
+ }
346
+ }
347
+
348
+ logObservabilityStart(): void {
349
+ this.notice('Starting Rejourney observability');
350
+ }
351
+
352
+ logRecordingStart(): void {
353
+ this.notice('Starting recording');
354
+ }
355
+
356
+ logRecordingRemoteDisabled(): void {
357
+ this.notice('Recording disabled by remote toggle');
358
+ }
359
+
360
+ logInvalidProjectKey(): void {
361
+ this.notice('Invalid project API key');
362
+ }
363
+
364
+ logPackageMismatch(): void {
365
+ this.notice('Bundle ID / package name mismatch');
366
+ }
367
+ }
368
+
369
+ export const logger = new Logger();
@@ -0,0 +1,7 @@
1
+ // Type stub for expo-router (optional peer dependency)
2
+ // This module is only used when installed by the host app
3
+
4
+ declare module 'expo-router' {
5
+ export function usePathname(): string;
6
+ export function useSegments(): string[];
7
+ }