@rejourneyco/react-native 1.0.7

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 (105) hide show
  1. package/README.md +29 -0
  2. package/android/build.gradle.kts +135 -0
  3. package/android/consumer-rules.pro +10 -0
  4. package/android/proguard-rules.pro +1 -0
  5. package/android/src/main/AndroidManifest.xml +15 -0
  6. package/android/src/main/java/com/rejourney/RejourneyModuleImpl.kt +860 -0
  7. package/android/src/main/java/com/rejourney/engine/DeviceRegistrar.kt +290 -0
  8. package/android/src/main/java/com/rejourney/engine/DiagnosticLog.kt +385 -0
  9. package/android/src/main/java/com/rejourney/engine/RejourneyImpl.kt +512 -0
  10. package/android/src/main/java/com/rejourney/platform/OEMDetector.kt +173 -0
  11. package/android/src/main/java/com/rejourney/platform/PerfTiming.kt +384 -0
  12. package/android/src/main/java/com/rejourney/platform/SessionLifecycleService.kt +160 -0
  13. package/android/src/main/java/com/rejourney/platform/Telemetry.kt +301 -0
  14. package/android/src/main/java/com/rejourney/platform/WindowUtils.kt +100 -0
  15. package/android/src/main/java/com/rejourney/recording/AnrSentinel.kt +129 -0
  16. package/android/src/main/java/com/rejourney/recording/EventBuffer.kt +330 -0
  17. package/android/src/main/java/com/rejourney/recording/InteractionRecorder.kt +519 -0
  18. package/android/src/main/java/com/rejourney/recording/ReplayOrchestrator.kt +740 -0
  19. package/android/src/main/java/com/rejourney/recording/SegmentDispatcher.kt +559 -0
  20. package/android/src/main/java/com/rejourney/recording/StabilityMonitor.kt +238 -0
  21. package/android/src/main/java/com/rejourney/recording/TelemetryPipeline.kt +633 -0
  22. package/android/src/main/java/com/rejourney/recording/ViewHierarchyScanner.kt +232 -0
  23. package/android/src/main/java/com/rejourney/recording/VisualCapture.kt +474 -0
  24. package/android/src/main/java/com/rejourney/utility/DataCompression.kt +63 -0
  25. package/android/src/main/java/com/rejourney/utility/ImageBlur.kt +412 -0
  26. package/android/src/main/java/com/rejourney/utility/ViewIdentifier.kt +169 -0
  27. package/android/src/newarch/java/com/rejourney/RejourneyModule.kt +232 -0
  28. package/android/src/newarch/java/com/rejourney/RejourneyPackage.kt +40 -0
  29. package/android/src/oldarch/java/com/rejourney/RejourneyModule.kt +268 -0
  30. package/android/src/oldarch/java/com/rejourney/RejourneyPackage.kt +23 -0
  31. package/ios/Engine/DeviceRegistrar.swift +288 -0
  32. package/ios/Engine/DiagnosticLog.swift +387 -0
  33. package/ios/Engine/RejourneyImpl.swift +719 -0
  34. package/ios/Recording/AnrSentinel.swift +142 -0
  35. package/ios/Recording/EventBuffer.swift +326 -0
  36. package/ios/Recording/InteractionRecorder.swift +428 -0
  37. package/ios/Recording/ReplayOrchestrator.swift +624 -0
  38. package/ios/Recording/SegmentDispatcher.swift +492 -0
  39. package/ios/Recording/StabilityMonitor.swift +223 -0
  40. package/ios/Recording/TelemetryPipeline.swift +547 -0
  41. package/ios/Recording/ViewHierarchyScanner.swift +156 -0
  42. package/ios/Recording/VisualCapture.swift +675 -0
  43. package/ios/Rejourney.h +38 -0
  44. package/ios/Rejourney.mm +375 -0
  45. package/ios/Utility/DataCompression.swift +55 -0
  46. package/ios/Utility/ImageBlur.swift +89 -0
  47. package/ios/Utility/RuntimeMethodSwap.swift +41 -0
  48. package/ios/Utility/ViewIdentifier.swift +37 -0
  49. package/lib/commonjs/NativeRejourney.js +40 -0
  50. package/lib/commonjs/components/Mask.js +88 -0
  51. package/lib/commonjs/index.js +1443 -0
  52. package/lib/commonjs/sdk/autoTracking.js +1087 -0
  53. package/lib/commonjs/sdk/constants.js +166 -0
  54. package/lib/commonjs/sdk/errorTracking.js +187 -0
  55. package/lib/commonjs/sdk/index.js +50 -0
  56. package/lib/commonjs/sdk/metricsTracking.js +205 -0
  57. package/lib/commonjs/sdk/navigation.js +128 -0
  58. package/lib/commonjs/sdk/networkInterceptor.js +375 -0
  59. package/lib/commonjs/sdk/utils.js +433 -0
  60. package/lib/commonjs/sdk/version.js +13 -0
  61. package/lib/commonjs/types/expo-router.d.js +2 -0
  62. package/lib/commonjs/types/index.js +2 -0
  63. package/lib/module/NativeRejourney.js +38 -0
  64. package/lib/module/components/Mask.js +83 -0
  65. package/lib/module/index.js +1341 -0
  66. package/lib/module/sdk/autoTracking.js +1059 -0
  67. package/lib/module/sdk/constants.js +154 -0
  68. package/lib/module/sdk/errorTracking.js +177 -0
  69. package/lib/module/sdk/index.js +26 -0
  70. package/lib/module/sdk/metricsTracking.js +187 -0
  71. package/lib/module/sdk/navigation.js +120 -0
  72. package/lib/module/sdk/networkInterceptor.js +364 -0
  73. package/lib/module/sdk/utils.js +412 -0
  74. package/lib/module/sdk/version.js +7 -0
  75. package/lib/module/types/expo-router.d.js +2 -0
  76. package/lib/module/types/index.js +2 -0
  77. package/lib/typescript/NativeRejourney.d.ts +160 -0
  78. package/lib/typescript/components/Mask.d.ts +54 -0
  79. package/lib/typescript/index.d.ts +117 -0
  80. package/lib/typescript/sdk/autoTracking.d.ts +226 -0
  81. package/lib/typescript/sdk/constants.d.ts +138 -0
  82. package/lib/typescript/sdk/errorTracking.d.ts +47 -0
  83. package/lib/typescript/sdk/index.d.ts +24 -0
  84. package/lib/typescript/sdk/metricsTracking.d.ts +75 -0
  85. package/lib/typescript/sdk/navigation.d.ts +48 -0
  86. package/lib/typescript/sdk/networkInterceptor.d.ts +62 -0
  87. package/lib/typescript/sdk/utils.d.ts +193 -0
  88. package/lib/typescript/sdk/version.d.ts +6 -0
  89. package/lib/typescript/types/index.d.ts +618 -0
  90. package/package.json +122 -0
  91. package/rejourney.podspec +23 -0
  92. package/src/NativeRejourney.ts +185 -0
  93. package/src/components/Mask.tsx +93 -0
  94. package/src/index.ts +1555 -0
  95. package/src/sdk/autoTracking.ts +1245 -0
  96. package/src/sdk/constants.ts +155 -0
  97. package/src/sdk/errorTracking.ts +231 -0
  98. package/src/sdk/index.ts +25 -0
  99. package/src/sdk/metricsTracking.ts +227 -0
  100. package/src/sdk/navigation.ts +152 -0
  101. package/src/sdk/networkInterceptor.ts +423 -0
  102. package/src/sdk/utils.ts +442 -0
  103. package/src/sdk/version.ts +6 -0
  104. package/src/types/expo-router.d.ts +7 -0
  105. package/src/types/index.ts +709 -0
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Copyright 2026 Rejourney
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.rejourney.recording
18
+
19
+ import android.content.Context
20
+ import com.rejourney.engine.DiagnosticLog
21
+ import org.json.JSONObject
22
+ import java.io.File
23
+ import java.io.PrintWriter
24
+ import java.io.StringWriter
25
+ import java.util.concurrent.Executors
26
+ import kotlin.concurrent.thread
27
+
28
+ /**
29
+ * Incident record for crash reporting
30
+ */
31
+ data class IncidentRecord(
32
+ val sessionId: String,
33
+ val timestampMs: Long,
34
+ val category: String,
35
+ val identifier: String,
36
+ val detail: String,
37
+ val frames: List<String>,
38
+ val context: Map<String, String>
39
+ ) {
40
+ fun toJson(): JSONObject {
41
+ return JSONObject().apply {
42
+ put("sessionId", sessionId)
43
+ put("timestampMs", timestampMs)
44
+ put("category", category)
45
+ put("identifier", identifier)
46
+ put("detail", detail)
47
+ put("frames", frames)
48
+ put("context", JSONObject(context))
49
+ }
50
+ }
51
+
52
+ companion object {
53
+ fun fromJson(json: JSONObject): IncidentRecord {
54
+ val framesArray = json.optJSONArray("frames")
55
+ val frames = mutableListOf<String>()
56
+ if (framesArray != null) {
57
+ for (i in 0 until framesArray.length()) {
58
+ frames.add(framesArray.getString(i))
59
+ }
60
+ }
61
+
62
+ val contextObj = json.optJSONObject("context")
63
+ val context = mutableMapOf<String, String>()
64
+ if (contextObj != null) {
65
+ contextObj.keys().forEach { key ->
66
+ context[key] = contextObj.optString(key, "")
67
+ }
68
+ }
69
+
70
+ return IncidentRecord(
71
+ sessionId = json.optString("sessionId", "unknown"),
72
+ timestampMs = json.optLong("timestampMs", 0),
73
+ category = json.optString("category", ""),
74
+ identifier = json.optString("identifier", ""),
75
+ detail = json.optString("detail", ""),
76
+ frames = frames,
77
+ context = context
78
+ )
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Crash and exception monitoring
85
+ * Android implementation aligned with iOS StabilityMonitor.swift
86
+ */
87
+ class StabilityMonitor private constructor(private val context: Context) {
88
+
89
+ companion object {
90
+ @Volatile
91
+ private var instance: StabilityMonitor? = null
92
+
93
+ fun getInstance(context: Context): StabilityMonitor {
94
+ return instance ?: synchronized(this) {
95
+ instance ?: StabilityMonitor(context.applicationContext).also { instance = it }
96
+ }
97
+ }
98
+
99
+ val shared: StabilityMonitor?
100
+ get() = instance
101
+ }
102
+
103
+ var isMonitoring = false
104
+ private set
105
+ var currentSessionId: String? = null
106
+
107
+ private val incidentStore: File by lazy {
108
+ File(context.cacheDir, "rj_incidents.json")
109
+ }
110
+
111
+ private val workerExecutor = Executors.newSingleThreadExecutor()
112
+
113
+ private var chainedExceptionHandler: Thread.UncaughtExceptionHandler? = null
114
+
115
+ fun activate() {
116
+ if (isMonitoring) return
117
+ isMonitoring = true
118
+
119
+ // Chain existing handler
120
+ chainedExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
121
+
122
+ Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
123
+ captureException(thread, throwable)
124
+
125
+ // Call chained handler
126
+ chainedExceptionHandler?.uncaughtException(thread, throwable)
127
+ }
128
+
129
+ // Upload any stored incidents
130
+ workerExecutor.execute {
131
+ uploadStoredIncidents()
132
+ }
133
+ }
134
+
135
+ fun deactivate() {
136
+ if (!isMonitoring) return
137
+ isMonitoring = false
138
+
139
+ // Restore original handler
140
+ Thread.setDefaultUncaughtExceptionHandler(chainedExceptionHandler)
141
+ chainedExceptionHandler = null
142
+ }
143
+
144
+ fun transmitStoredReport() {
145
+ workerExecutor.execute {
146
+ uploadStoredIncidents()
147
+ }
148
+ }
149
+
150
+ private fun captureException(thread: Thread, throwable: Throwable) {
151
+ val sw = StringWriter()
152
+ throwable.printStackTrace(PrintWriter(sw))
153
+ val stackTrace = sw.toString()
154
+
155
+ val frames = stackTrace.lines()
156
+ .filter { it.trim().startsWith("at ") }
157
+ .map { it.trim() }
158
+
159
+ val incident = IncidentRecord(
160
+ sessionId = currentSessionId ?: "unknown",
161
+ timestampMs = System.currentTimeMillis(),
162
+ category = "exception",
163
+ identifier = throwable.javaClass.name,
164
+ detail = throwable.message ?: "",
165
+ frames = frames,
166
+ context = mapOf(
167
+ "threadName" to thread.name,
168
+ "isMain" to (thread == android.os.Looper.getMainLooper().thread).toString(),
169
+ "priority" to thread.priority.toString()
170
+ )
171
+ )
172
+
173
+ ReplayOrchestrator.shared?.incrementFaultTally()
174
+ persistIncident(incident)
175
+
176
+ // Give time to write
177
+ Thread.sleep(150)
178
+ }
179
+
180
+ fun persistIncidentSync(incident: IncidentRecord) {
181
+ try {
182
+ incidentStore.writeText(incident.toJson().toString())
183
+ } catch (e: Exception) {
184
+ DiagnosticLog.fault("Incident persist failed: ${e.message}")
185
+ }
186
+ }
187
+
188
+ private fun persistIncident(incident: IncidentRecord) {
189
+ try {
190
+ incidentStore.writeText(incident.toJson().toString())
191
+ } catch (e: Exception) {
192
+ DiagnosticLog.fault("Incident persist failed: ${e.message}")
193
+ }
194
+ }
195
+
196
+ private fun uploadStoredIncidents() {
197
+ if (!incidentStore.exists()) return
198
+
199
+ try {
200
+ val data = incidentStore.readText()
201
+ val incident = IncidentRecord.fromJson(JSONObject(data))
202
+
203
+ transmitIncident(incident) { ok ->
204
+ if (ok) {
205
+ try { incidentStore.delete() } catch (_: Exception) { }
206
+ }
207
+ }
208
+ } catch (e: Exception) {
209
+ DiagnosticLog.fault("Failed to read stored incident: ${e.message}")
210
+ }
211
+ }
212
+
213
+ private fun transmitIncident(incident: IncidentRecord, completion: (Boolean) -> Unit) {
214
+ val base = SegmentDispatcher.shared.endpoint
215
+ val url = "$base/api/ingest/fault"
216
+
217
+ try {
218
+ val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
219
+ connection.requestMethod = "POST"
220
+ connection.setRequestProperty("Content-Type", "application/json")
221
+
222
+ SegmentDispatcher.shared.apiToken?.let {
223
+ connection.setRequestProperty("x-rejourney-key", it)
224
+ }
225
+
226
+ connection.doOutput = true
227
+ connection.outputStream.write(incident.toJson().toString().toByteArray())
228
+
229
+ val responseCode = connection.responseCode
230
+ completion(responseCode == 200)
231
+
232
+ connection.disconnect()
233
+ } catch (e: Exception) {
234
+ DiagnosticLog.fault("Failed to transmit incident: ${e.message}")
235
+ completion(false)
236
+ }
237
+ }
238
+ }