@dynatrace/react-native-plugin 2.327.2 → 2.329.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.
Files changed (52) hide show
  1. package/README.md +414 -163
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/dynatrace/android/agent/DynatraceConfigurationModule.kt +48 -0
  4. package/android/src/main/java/com/dynatrace/android/agent/DynatraceRNBridgeImpl.kt +41 -8
  5. package/android/src/main/java/com/dynatrace/android/agent/DynatraceReactPackage.kt +3 -0
  6. package/android/src/main/java/com/dynatrace/android/agent/DynatraceRuntimeConfigurationStore.kt +14 -0
  7. package/android/src/main/java/com/dynatrace/android/agent/DynatraceUtils.kt +103 -47
  8. package/android/src/new/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +12 -4
  9. package/android/src/old/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +15 -5
  10. package/files/default.config.js +7 -0
  11. package/files/plugin-runtime.gradle +7 -17
  12. package/files/plugin.gradle +1 -1
  13. package/instrumentation/DynatraceInstrumentation.js +1 -1
  14. package/instrumentation/libs/react-navigation/ReactNavigation.js +53 -18
  15. package/ios/ConfigurationSubscriber.h +15 -0
  16. package/ios/DynatraceRNBridge.h +4 -0
  17. package/ios/DynatraceRNBridge.mm +125 -29
  18. package/lib/core/Dynatrace.js +8 -11
  19. package/lib/core/configuration/ConfigurationHandler.js +3 -0
  20. package/lib/next/Dynatrace.js +14 -32
  21. package/lib/next/DynatraceEventBus.js +35 -0
  22. package/lib/next/appstart/AppStartObserver.js +2 -3
  23. package/lib/next/configuration/INativeRuntimeConfiguration.js +7 -0
  24. package/lib/next/configuration/RuntimeConfigurationObserver.js +40 -0
  25. package/lib/next/events/EventBuilderUtil.js +7 -0
  26. package/lib/next/events/EventData.js +28 -0
  27. package/lib/next/events/EventPipeline.js +5 -11
  28. package/lib/next/events/ExceptionEventData.js +26 -0
  29. package/lib/next/events/{HttpRequestEventBuilder.js → HttpRequestEventData.js} +28 -52
  30. package/lib/next/events/SessionPropertyEventData.js +22 -0
  31. package/lib/next/events/interface/IBaseEvent.js +2 -0
  32. package/lib/next/events/interface/IEventData.js +2 -0
  33. package/lib/next/events/interface/IExceptionEventData.js +2 -0
  34. package/lib/next/events/interface/IHttpRequestEventData.js +2 -0
  35. package/lib/next/events/interface/ISessionPropertyEventData.js +2 -0
  36. package/lib/next/events/modifier/BaseDataEventModifier.js +1 -3
  37. package/lib/next/events/modifier/EventModifierUtil.js +34 -41
  38. package/lib/next/events/modifier/ModifyEventValidation.js +118 -26
  39. package/lib/next/events/modifier/SendEventValidation.js +53 -22
  40. package/lib/next/events/modifier/StringLengthEventModifier.js +53 -0
  41. package/lib/next/events/spec/EventSpecContstants.js +9 -2
  42. package/package.json +8 -3
  43. package/public.js +9 -3
  44. package/react-native-dynatrace.podspec +1 -1
  45. package/scripts/Config.js +6 -2
  46. package/scripts/LineOffsetAnalyze.js +1 -4
  47. package/scripts/core/LineOffsetAnalyzeCall.js +39 -46
  48. package/src/lib/core/interface/NativeDynatraceBridge.ts +6 -2
  49. package/types.d.ts +388 -158
  50. package/lib/next/events/ViewInfoCreator.js +0 -27
  51. package/lib/next/events/modifier/EventLimitation.js +0 -69
  52. /package/lib/next/events/{IHttpRequestEventBuilder.js → interface/EventProperty.js} +0 -0
@@ -72,7 +72,7 @@ repositories {
72
72
  }
73
73
 
74
74
  dependencies {
75
- implementation 'com.dynatrace.agent:agent-android:8.327.3.1006'
75
+ implementation 'com.dynatrace.agent:agent-android:8.329.1.1014'
76
76
  implementation "com.facebook.react:react-native:${safeExtGet('reactNative', '+')}"
77
77
  }
78
78
 
@@ -0,0 +1,48 @@
1
+ package com.dynatrace.android.agent
2
+
3
+ import android.util.Log
4
+ import com.dynatrace.android.agent.conf.ConfigurationSubscriber
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
8
+ import com.facebook.react.modules.core.DeviceEventManagerModule
9
+
10
+ /**
11
+ * Name of the module
12
+ */
13
+ private const val CONFIGURATION_MODULE = "DynatraceConfigurationModule"
14
+
15
+ /**
16
+ * Emitting configuration event with this identifier
17
+ */
18
+ private const val EMIT_CONFIGURATION = "dynatraceConfiguration"
19
+
20
+ /**
21
+ * Module which is handling the runtime configuration changes
22
+ */
23
+ internal class DynatraceConfigurationModule(reactContext: ReactApplicationContext?) :
24
+ ReactContextBaseJavaModule(reactContext) {
25
+
26
+ init {
27
+ setupInternalListener()
28
+ }
29
+
30
+ /**
31
+ * We setup the listener internally as we
32
+ */
33
+ private fun setupInternalListener() {
34
+ HybridBridge.addConfigurationSubscriber(object : ConfigurationSubscriber {
35
+ // Called when config changes on native side and for the initial value
36
+ override fun notify(configuration: Map<String, Any>) {
37
+ DynatraceRuntimeConfigurationStore.update(configuration)
38
+ reactApplicationContext
39
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
40
+ .emit(EMIT_CONFIGURATION, Arguments.makeNativeMap(configuration))
41
+ }
42
+ })
43
+ }
44
+
45
+ override fun getName(): String {
46
+ return CONFIGURATION_MODULE
47
+ }
48
+ }
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.Promise
10
10
  import com.facebook.react.bridge.ReactApplicationContext
11
11
  import com.facebook.react.bridge.ReadableMap
12
12
  import com.facebook.react.bridge.ReadableArray
13
+ import com.facebook.react.modules.core.DeviceEventManagerModule
13
14
  import org.json.JSONObject
14
15
  import java.net.URI
15
16
  import java.net.URISyntaxException
@@ -21,6 +22,12 @@ private const val DATA_COLLECTION_PERFORMANCE = "PERFORMANCE"
21
22
  private const val DATA_COLLECTION_USERBEHAVIOR = "USER_BEHAVIOR"
22
23
  const val BRIDGE_NAME = "DynatraceBridge"
23
24
 
25
+
26
+ /**
27
+ * Emitting configuration event with this identifier
28
+ */
29
+ private const val EMIT_CONFIGURATION = "dynatraceConfiguration"
30
+
24
31
  class DynatraceRNBridgeImpl(
25
32
  private val reactApplicationContext: ReactApplicationContext,
26
33
  private val _internal: DynatraceInternalModule
@@ -36,6 +43,11 @@ class DynatraceRNBridgeImpl(
36
43
  "DATA_COLLECTION_USERBEHAVIOR" to DATA_COLLECTION_USERBEHAVIOR
37
44
  )
38
45
 
46
+ private var lastConfiguration: MutableMap<String, Any>? = null
47
+ private var hasInternalListener: Boolean = false
48
+ private var listenersCount: Int = 0
49
+
50
+
39
51
  fun getConstants(): Map<String, Any> {
40
52
  return constants;
41
53
  }
@@ -300,10 +312,6 @@ class DynatraceRNBridgeImpl(
300
312
  Dynatrace.startView(name)
301
313
  }
302
314
 
303
- fun stopView() {
304
- Dynatrace.stopView()
305
- }
306
-
307
315
  fun setGPSLocation(lat: Double, lng: Double, platform: String?) {
308
316
  if (shouldWorkOnAndroid(platform)) {
309
317
  val location = Location("")
@@ -392,14 +400,39 @@ class DynatraceRNBridgeImpl(
392
400
  }
393
401
  }
394
402
 
395
- @Suppress("UNUSED_PARAMETER")
396
403
  fun addListener(eventName: String) {
397
- // Here because of event emitter
404
+ listenersCount += 1
405
+ reactApplicationContext
406
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
407
+ .emit(EMIT_CONFIGURATION, Arguments.makeNativeMap(DynatraceRuntimeConfigurationStore.get()))
398
408
  }
399
409
 
400
- @Suppress("UNUSED_PARAMETER")
401
410
  fun removeListeners(count: Double) {
402
- // Here because of event emitter
411
+ listenersCount -= count.toInt()
412
+ if (listenersCount < 0) {
413
+ listenersCount = 0
414
+ }
415
+ }
416
+
417
+ fun onConfigurationUpdated(configuration: Map<String, Any>) {
418
+ lastConfiguration = configuration.toMutableMap()
419
+ }
420
+
421
+ fun getCurrentConfiguration(promise: Promise) {
422
+ val config = DynatraceRuntimeConfigurationStore.get()
423
+ if (config != null) {
424
+ promise.resolve(Arguments.makeNativeMap(config))
425
+ } else {
426
+ promise.resolve(null)
427
+ }
428
+ }
429
+
430
+ fun startViewInternal(fields: ReadableMap) {
431
+ HybridBridge.startView(JSONObject(DynatraceUtils.toHashMap(fields)))
432
+ }
433
+
434
+ fun stopViewInternal() {
435
+ HybridBridge.stopView()
403
436
  }
404
437
 
405
438
  private fun newAction(name: String, key: String) {
@@ -20,10 +20,12 @@ class DynatraceReactPackage : TurboReactPackage() {
20
20
 
21
21
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
22
22
  val bridge = DynatraceInternalModule(reactContext)
23
+ val configurationSubscriber = DynatraceConfigurationModule(reactContext)
23
24
  val appStart = DynatraceAppStartModule(reactContext)
24
25
  return Arrays.asList<NativeModule>(
25
26
  DynatraceRNBridge(reactContext, bridge),
26
27
  bridge,
28
+ configurationSubscriber,
27
29
  appStart
28
30
  )
29
31
  }
@@ -45,6 +47,7 @@ class DynatraceReactPackage : TurboReactPackage() {
45
47
 
46
48
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
47
49
  return if (name == BRIDGE_NAME) {
50
+ DynatraceConfigurationModule(reactContext)
48
51
  DynatraceAppStartModule(reactContext)
49
52
  DynatraceRNBridge(reactContext, DynatraceInternalModule(reactContext))
50
53
  } else {
@@ -0,0 +1,14 @@
1
+ package com.dynatrace.android.agent
2
+
3
+ object DynatraceRuntimeConfigurationStore {
4
+ @Volatile
5
+ private var lastConfiguration: MutableMap<String, Any>? = null
6
+
7
+ fun update(configuration: Map<String, Any>) {
8
+ lastConfiguration = configuration.toMutableMap()
9
+ }
10
+
11
+ fun get(): MutableMap<String, Any>? {
12
+ return lastConfiguration
13
+ }
14
+ }
@@ -1,5 +1,6 @@
1
1
  package com.dynatrace.android.agent
2
2
 
3
+ import android.util.Log
3
4
  import com.facebook.react.bridge.ReadableArray
4
5
  import com.facebook.react.bridge.ReadableMap
5
6
  import com.facebook.react.bridge.ReadableType
@@ -8,77 +9,132 @@ import com.facebook.react.bridge.ReadableType
8
9
  * @author matthias.hochrieser
9
10
  */
10
11
  internal object DynatraceUtils {
11
- // https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java#L56
12
+
13
+ private const val TAG = "DynatraceUtils"
14
+
15
+ /**
16
+ * Converts a ReadableArray to an ArrayList.
17
+ *
18
+ * This method supports the following types:
19
+ * - Null
20
+ * - Boolean
21
+ * - Number (which will be converted to an Int or Long if possible, otherwise a Double)
22
+ * - String
23
+ * - Map (which will be converted to a HashMap)
24
+ * - Array (which will be converted to an ArrayList)
25
+ *
26
+ * If the ReadableArray contains an unsupported type, an IllegalArgumentException will be thrown.
27
+ *
28
+ * @param array the ReadableArray to be converted
29
+ * @return the converted ArrayList
30
+ */
12
31
  private fun toArrayList(array: ReadableArray?): ArrayList<Any?> {
13
- val arrayList = ArrayList<Any?>(array!!.size())
14
- var i = 0
32
+ if (array == null) {
33
+ return ArrayList()
34
+ }
35
+
36
+ val arrayList = ArrayList<Any?>(array.size())
37
+
15
38
  val size = array.size()
16
- while (i < size) {
17
- when (array.getType(i)) {
39
+ for (i in 0 until size) {
40
+ val type = array.getType(i)
41
+
42
+ when (type) {
18
43
  ReadableType.Null -> arrayList.add(null)
19
- ReadableType.Boolean -> arrayList.add(array.getBoolean(i))
44
+
45
+ ReadableType.Boolean ->
46
+ arrayList.add(array.getBoolean(i))
47
+
20
48
  ReadableType.Number -> {
21
49
  val value = array.getDouble(i)
22
- if (java.lang.Double.isFinite(value)) {
23
- if (value >= Int.MIN_VALUE && value <= Int.MAX_VALUE && value == value.toInt()
24
- .toDouble()
25
- ) {
26
- // This is a int
27
- arrayList.add(array.getDouble(i).toInt())
28
- } else if (value >= Long.MIN_VALUE && value <= Long.MAX_VALUE && value == value.toLong()
29
- .toDouble()
30
- ) {
31
- // This is a long
32
- arrayList.add(array.getDouble(i).toLong())
33
- }
34
- } else {
35
- arrayList.add(array.getDouble(i))
50
+ val converted = when {
51
+ value.isFinite() && value == value.toInt().toDouble() ->
52
+ value.toInt()
53
+ value.isFinite() && value == value.toLong().toDouble() ->
54
+ value.toLong()
55
+ else ->
56
+ value
36
57
  }
58
+ arrayList.add(converted)
37
59
  }
38
60
 
39
- ReadableType.String -> arrayList.add(array.getString(i))
40
- ReadableType.Map -> arrayList.add(toHashMap(array.getMap(i)))
41
- ReadableType.Array -> arrayList.add(toArrayList(array.getArray(i)))
42
- else -> throw IllegalArgumentException("Could not convert object at index: $i.")
61
+ ReadableType.String ->
62
+ arrayList.add(array.getString(i))
63
+
64
+ ReadableType.Map -> {
65
+ val map = array.getMap(i)
66
+ arrayList.add(toHashMap(map))
67
+ }
68
+
69
+ ReadableType.Array -> {
70
+ val nestedArray = array.getArray(i)
71
+ arrayList.add(toArrayList(nestedArray))
72
+ }
73
+
74
+ else -> {
75
+ throw IllegalArgumentException("Could not convert object at index: $i.")
76
+ }
43
77
  }
44
- i++
45
78
  }
79
+
46
80
  return arrayList
47
81
  }
48
82
 
83
+
84
+ /**
85
+ * Converts a ReadableMap to a HashMap.
86
+ *
87
+ * @param map the ReadableMap to convert
88
+ * @return a HashMap containing the same key-value pairs as the ReadableMap
89
+ * @throws IllegalArgumentException if the ReadableMap contains an object that cannot be converted to a HashMap
90
+ */
49
91
  fun toHashMap(map: ReadableMap?): HashMap<String, Any?> {
50
92
  val hashMap = HashMap<String, Any?>()
51
- val iterator = map!!.keySetIterator()
93
+
94
+ if (map == null) {
95
+ return hashMap
96
+ }
97
+
98
+ val iterator = map.keySetIterator()
52
99
  while (iterator.hasNextKey()) {
53
100
  val key = iterator.nextKey()
54
- when (map.getType(key)) {
55
- ReadableType.Null -> hashMap[key] = null
56
- ReadableType.Boolean -> hashMap[key] = map.getBoolean(key)
101
+ val type = map.getType(key)
102
+
103
+
104
+ when (type) {
105
+ ReadableType.Null ->
106
+ hashMap[key] = null
107
+
108
+ ReadableType.Boolean ->
109
+ hashMap[key] = map.getBoolean(key)
110
+
57
111
  ReadableType.Number -> {
58
112
  val value = map.getDouble(key)
59
- if (java.lang.Double.isFinite(value)) {
60
- if (value >= Int.MIN_VALUE && value <= Int.MAX_VALUE && value == value.toInt()
61
- .toDouble()
62
- ) {
63
- // This is a int
64
- hashMap[key] = map.getDouble(key).toInt()
65
- } else if (value >= Long.MIN_VALUE && value <= Long.MAX_VALUE && value == value.toLong()
66
- .toDouble()
67
- ) {
68
- // This is a long
69
- hashMap[key] = map.getDouble(key).toLong()
70
- }
71
- } else {
72
- hashMap[key] = map.getDouble(key)
113
+ hashMap[key] = when {
114
+ value.isFinite() && value == value.toInt().toDouble() ->
115
+ value.toInt()
116
+ value.isFinite() && value == value.toLong().toDouble() ->
117
+ value.toLong()
118
+ else ->
119
+ value
73
120
  }
74
121
  }
75
122
 
76
- ReadableType.String -> hashMap[key] = map.getString(key)
77
- ReadableType.Map -> hashMap[key] = toHashMap(map.getMap(key))
78
- ReadableType.Array -> hashMap[key] = toArrayList(map.getArray(key))
79
- else -> throw IllegalArgumentException("Could not convert object with key: $key.")
123
+ ReadableType.String ->
124
+ hashMap[key] = map.getString(key)
125
+
126
+ ReadableType.Map ->
127
+ hashMap[key] = toHashMap(map.getMap(key))
128
+
129
+ ReadableType.Array ->
130
+ hashMap[key] = toArrayList(map.getArray(key))
131
+
132
+ else -> {
133
+ throw IllegalArgumentException("Could not convert object with key: $key.")
134
+ }
80
135
  }
81
136
  }
137
+
82
138
  return hashMap
83
139
  }
84
140
  }
@@ -183,10 +183,6 @@ class DynatraceRNBridge(
183
183
  impl.startView(name)
184
184
  }
185
185
 
186
- override fun stopView() {
187
- impl.stopView()
188
- }
189
-
190
186
  override fun setGPSLocation(latitude: Double, longitude: Double, platform: String?) {
191
187
  impl.setGPSLocation(latitude, longitude, platform)
192
188
  }
@@ -230,4 +226,16 @@ class DynatraceRNBridge(
230
226
  override fun removeListeners(count: Double) {
231
227
  impl.removeListeners(count)
232
228
  }
229
+
230
+ override fun getCurrentConfiguration(promise: Promise) {
231
+ impl.getCurrentConfiguration(promise)
232
+ }
233
+
234
+ override fun startViewInternal(fields: ReadableMap) {
235
+ impl.startViewInternal(fields)
236
+ }
237
+
238
+ override fun stopViewInternal() {
239
+ impl.stopViewInternal()
240
+ }
233
241
  }
@@ -202,11 +202,6 @@ class DynatraceRNBridge(
202
202
  impl.startView(name)
203
203
  }
204
204
 
205
- @ReactMethod
206
- fun stopView() {
207
- impl.stopView()
208
- }
209
-
210
205
  @ReactMethod
211
206
  fun setGPSLocation(latitude: Double, longitude: Double, platform: String?) {
212
207
  impl.setGPSLocation(latitude, longitude, platform)
@@ -261,4 +256,19 @@ class DynatraceRNBridge(
261
256
  fun removeListeners(count: Double) {
262
257
  impl.removeListeners(count)
263
258
  }
259
+
260
+ @ReactMethod
261
+ fun getCurrentConfiguration(promise: Promise) {
262
+ impl.getCurrentConfiguration(promise)
263
+ }
264
+
265
+ @ReactMethod
266
+ fun startViewInternal(fields: ReadableMap) {
267
+ impl.startViewInternal(fields)
268
+ }
269
+
270
+ @ReactMethod
271
+ fun stopViewInternal() {
272
+ impl.stopViewInternal()
273
+ }
264
274
  }
@@ -46,6 +46,13 @@ module.exports = {
46
46
  instrument: (filename) => {
47
47
  return true;
48
48
  }
49
+ },
50
+
51
+ navigation: {
52
+ /**
53
+ * Enables the automatic instrumentation of @react-navigation
54
+ */
55
+ enabled: true,
49
56
  }
50
57
  },
51
58
  android: {
@@ -4,24 +4,14 @@ android.applicationVariants.all { variant ->
4
4
  if (variant.buildType.name == "release") {
5
5
  variant.mergeAssetsProvider.configure { task ->
6
6
  task.doLast {
7
- def sourceMap = file("$buildDir/generated/sourcemaps/react/release/index.android.bundle.map")
8
- println("🔍 Check sourceMap: $sourceMap")
9
-
10
- if (sourceMap.exists()) {
11
- println("✅ Source map found. Starting post-processing...")
12
-
13
- exec {
14
- workingDir rootDir
15
- if (DefaultNativePlatform.currentOperatingSystem.isWindows()) {
16
- // On windows, npx.cmd may not be a true binary executable and may need to be interpreted by a shell instead of executed direclty
17
- commandLine 'cmd', '/c', 'npx', 'lineOffsetDynatrace', 'env=prod'
18
- } else {
19
- commandLine 'npx', 'lineOffsetDynatrace', 'env=prod'
20
- }
7
+ exec {
8
+ workingDir rootDir
9
+ if (DefaultNativePlatform.currentOperatingSystem.isWindows()) {
10
+ // On windows, npx.cmd may not be a true binary executable and may need to be interpreted by a shell instead of executed direclty
11
+ commandLine 'cmd', '/c', 'npx', 'lineOffsetDynatrace'
12
+ } else {
13
+ commandLine 'npx', 'lineOffsetDynatrace'
21
14
  }
22
-
23
- } else {
24
- println("❌ Source map not found")
25
15
  }
26
16
  }
27
17
  }
@@ -1,4 +1,4 @@
1
1
  // TEMPLATE: plugin-gradle.template
2
2
  dependencies {
3
- classpath 'com.dynatrace.tools.android:gradle-plugin:8.327.3.1006'
3
+ classpath 'com.dynatrace.tools.android:gradle-plugin:8.329.1.1014'
4
4
  }
@@ -1 +1 @@
1
- var o,n=require("@babel/runtime/helpers/interopRequireDefault"),e=n(require("@babel/runtime/helpers/toConsumableArray")),c=(Object.defineProperty(exports,"t",{value:!0}),exports.instrument=void 0,require("path")),u=require("jscodeshift"),i=require("jscodeshift/src/Collection"),r=require("../scripts/FileOperationHelper"),l=require("../scripts/PathsConstants"),f=require("../lib/core/util/GetValuesFromPackage"),t=require("../scripts/util/InstrumentUtil"),a=require("./libs/react-native/Touchables.InstrInfo"),s=require("./libs/react-native/RefreshControl.InstrInfo"),v=require("./libs/react-native/Switch.InstrInfo"),d=require("./libs/community/gesture-handler/Touchables.InstrInfo"),p=require("./libs/community/Picker.InstrInfo"),m=require("./model/Types"),y=require("./parser/ParserUtil"),g=((n=>{n[n.i=-1]="Filtered",n[n.u=0]="Normal",n[n.o=1]="ReactNative",n[n.l=2]="React",n[n.v=3]="ReactNativeCssInterop"})(o=o||{}),[]),q=(g.push.apply(g,(0,e.default)(a.instrumentationInfo)),g.push.apply(g,(0,e.default)(s.instrumentationInfo)),g.push.apply(g,(0,e.default)(v.instrumentationInfo)),g.push.apply(g,(0,e.default)(d.instrumentationInfo)),g.push.apply(g,(0,e.default)(p.instrumentationInfo)),["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"]),b="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(n,e,r){e=O(e);var t=z(e);if(t!==o.i){var i=!1,u=I(e,n);if(t===o.l)k(u),i=!0;else if(t===o.o)e.endsWith("AppRegistryImpl.js")?null!=r&&r.autoStart&&U(u)&&(i=!0):e.endsWith("AppRegistry.js")?null!=r&&r.autoStart&&w(u)&&(i=!0):e.endsWith("renderApplication.js")?(A(u),i=!0):e.endsWith("ExceptionsManager.js")&&(a=void 0!==r&&r.autoStart&&r.errorHandler.enabled,J(u,r.errorHandler.reportFatalErrorAsCrash,a),i=!0);else if(t===o.v)i=G(u)||i;else{var a=V(e,r);if(r.custom.reactnavigation&&T(e,u))i=!0;else{if(!a.input&&!a.lifecycle)return null!=r&&r.debug&&console.log("Dynatrace - Filtered All: ".concat(e)),h(e),n;a.lifecycle&&A(u)&&(i=!0),a.input&&g.forEach(function(n){n=X(u,n);u=n.root,i=i||n.p})}}i?(n=u.toSource({quote:"single"}),N(n,e)):h(e),null!=r&&r.debug&&i&&console.log("Dynatrace - Modified Filename: "+e)}else e.includes(c.join("@dynatrace","react-native-plugin"))&&e.endsWith(c.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==r&&(t=(0,f.getHostAppBundleInfo)(l.default.getPackageJsonFile()),a=I(e,n),void 0!==r.lifecycle&&j(a,"getLifecycleUpdate",r.lifecycle.includeUpdate),void 0!==r.debug&&j(a,"getLogLevel",r.debug?0:1),void 0!==r.bundleName?j(a,"getBundleName",r.bundleName):null!==t&&j(a,"getBundleName",null==t?void 0:t.name),void 0!==r.bundleVersion?j(a,"getBundleVersion",r.bundleVersion):null!==t&&j(a,"getBundleVersion",null==t?void 0:t.version),void 0!==r.input&&void 0!==r.input.actionNamePrivacy&&j(a,"getActionNamePrivacy",r.input.actionNamePrivacy),void 0!==r.errorHandler&&(j(a,"isErrorHandlerEnabled",r.errorHandler.enabled),j(a,"isReportFatalErrorAsCrash",r.errorHandler.reportFatalErrorAsCrash)),r.autoStart&&j(a,"isAutoStartupEnabled",r.autoStart),n=a.toSource({quote:"single"}),N(n,e));return n},T=(exports.instrument=instrument,function(n,e){return!!B(n,e)&&(n="import { registerListener } from '".concat(b,"/react-navigation/ReactNavigation';"),e.find(u.ImportDeclaration).at(0).insertBefore(n),!0)}),B=function(n,e){var r=!1;return n.includes("react-navigation")&&n.includes("NavigationContainer.tsx")&&e.find(u.VariableDeclarator).forEach(function(n){r||null==n.value||null==n.value.id||"refContainer"!==n.value.id.name||null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.type&&"VariableDeclaration"===n.parent.value.type&&(n.parent.insertAfter("registerListener(refContainer);"),r=!0)}),r},A=function(n){var e=n.findJSXElements(),t=!1;return 0<e.length&&(n.find(u.FunctionDeclaration).forEach(function(n){var e,r=(0,i.fromPaths)([n]);0<r.findJSXElements().length&&null!=n&&null!=n.value&&null!=n.value.id&&n.value.id.name.toString()&&(e=r.find(u.ClassDeclaration),r=r.find(u.ClassExpression),0===e.length)&&0===r.length&&(x(n,m.Types.FunctionalComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ClassDeclaration).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n&&null!=n.value&&n.value.id&&n.value.id.name.toString()&&(x(n,m.Types.ClassComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ArrowFunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(x(n,m.Types.FunctionalComponent,n.parent.value.id.name),t=!0)})),t},x=function(n,e,r){for(e=u.expressionStatement(u.assignmentExpression("=",u.memberExpression(u.identifier(r),u.identifier("_dtInfo")),M(e,r)));"body"!==(null==n?void 0:n.parentPath.name);)n=n.parentPath;void 0!==n.parentPath&&n.insertAfter(e)},M=function(n,e){return u.objectExpression([u.objectProperty(u.identifier("type"),u.numericLiteral(n)),u.objectProperty(u.identifier("name"),u.stringLiteral(e))])},j=function(n,e,r){var n=n.find(u.Identifier).filter(function(n){return n.node.name===e});1===n.length&&"ReturnStatement"===(n=n.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof r&&(n.argument=u.booleanLiteral(r)),"string"==typeof r&&(n.argument=u.stringLiteral(r)),"number"==typeof r)&&(n.argument=u.numericLiteral(r))},I=function(n,e){return u.withParser((0,y.chooseParser)(n,e))(e)},O=function(n){return c.isAbsolute(n)?n.replace(l.default.getApplicationPath()+c.sep,""):n},h=function(n){try{var e=c.join(l.default.getBuildPath(),n+t.INSTRUMENTED_FILE_EXTENSION);r.default.checkIfFileExistsSync(e),r.default.deleteFileSync(e)}catch(n){}},N=function(n,e){e=c.join(l.default.getBuildPath(),e);try{r.default.checkIfFileExistsSync(c.dirname(e))}catch(n){r.default.createDirectorySync(c.dirname(e))}r.default.writeTextToFileSync(e+t.INSTRUMENTED_FILE_EXTENSION,n)},V=function(n,e){var r={input:!1,lifecycle:!1};return void 0!==e&&(void 0!==e.lifecycle&&void 0!==e.lifecycle.instrument&&e.lifecycle.instrument(n)&&(r.lifecycle=!0),void 0!==e.input)&&void 0!==e.input.instrument&&e.input.instrument(n)&&(r.input=!0),r},k=function(n){var e,n=n.find(u.Program);1===n.length&&(e=u.expressionStatement(u.callExpression(u.memberExpression(u.callExpression(u.identifier("require"),[u.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),u.identifier("instrumentCreateElement")),[u.memberExpression(u.identifier("module"),u.identifier("exports"))])),n.paths()[0].node.body.push(e))},U=function(n){var e=n.find(u.FunctionDeclaration,{id:{name:"runApplication"}});return 1===e.length&&(_(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,F("_DynatraceApplicationHandler","startup",[])),!0)},w=function(n){var e=n.find(u.ObjectMethod,{key:{name:"runApplication"}});return 1===e.length&&(_(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,F("_DynatraceApplicationHandler","startup",[])),!0)},J=function(n,r,t){var i=u;n.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(n){var e=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(r),i.literal(t)]),e=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(n.node.body.body)),e]));n.node.body.body=[e]})},G=function(n){var e=!1,n=n.find(u.CallExpression,{callee:{name:"require"}});return n.find(u.Literal,{value:"react/jsx-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-runtime",e=!0,n}),n.find(u.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-dev-runtime",e=!0,n}),e},R=function(n,e){for(var r=arguments.length,t=new Array(2<r?r-2:0),i=2;i<r;i++)t[i-2]=arguments[i];return n.splice.apply(n,[e,0].concat(t))},z=function(n){if(n.includes("@dynatrace"))return o.i;var e=c.extname(n);if(".js"!==e&&".ts"!==e&&".tsx"!==e&&".jsx"!==e)return o.i;for(var r=c.parse(n),t=r.dir.split(c.sep),i=0;i<t.length;i++)if("node_modules"===t[i]){if("react-native"===t[i+1]||"create-react-class"===t[i+1]||"react-clone-referenced-element"===t[i+1])return q.includes(r.name)?o.o:o.i;if("react"===t[i+1]&&"index"===r.name)return o.l;if("react-native-css-interop"===t[i+1]&&("jsx-runtime"===r.name||"jsx-dev-runtime"===r.name))return o.v}return o.u},K=function(n,e,r){var t=Q(n,e,r);return W(n,e,r)||t},Q=function(n,e,r){var t=Y(n,e);return 0<t.length&&(void 0!==(t=H(t,e.reference,!1))&&(r.m=t.localName),tn(n,r),!0)},W=function(n,e,r){var t=E(n,e.module);if(1===t.length){t=H(t,e.reference,!0);if(void 0!==t)return un(n,r.defaultImport,t.localName,"ImportNamespaceSpecifier"===t.type),!0}return!1},X=function(n,e){var r=JSON.parse(JSON.stringify(e.new));return{root:n,p:K(n,e.old,r)||Z(n,e.old,e.new.defaultImport)}},Y=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module&&null!=n.node.specifiers&&n.node.specifiers.some(function(n){return C(n)&&n.imported.name===e.reference||n.local&&n.local.name===e.reference})})},C=function(n){return void 0!==n.imported},Z=function(n,e,r){var t=!1;return n.find(u.CallExpression).filter(function(n){return $(n.node.callee)&&nn(n.node.arguments[0])&&n.node.arguments[0].value===e.module&&void 0!==n.parent}).forEach(function(n){(void 0===n.parent.value.property||void 0!==n.parent.value.property&&void 0!==n.parent.value.property.name&&n.parent.value.property.name===e.reference)&&(n.node.arguments[0].value=r,t=t||!0)}),t},$=function(n){return"require"===n.name},nn=function(n){return"StringLiteral"===n.type||"Literal"===n.type},E=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e})},H=function(n,r,t){var i;return n.forEach(function(n){void 0!==n.node.specifiers&&(n.node.specifiers=n.node.specifiers.filter(function(n){var e;return C(n)&&!t?((e=n.imported.name!==r)||null==n.local||n.imported.name===n.local.name||(i={localName:n.local.name.toString(),type:n.type}),e):!(!C(n)&&t&&(null!=n.local&&(i={localName:n.local.name.toString(),type:n.type}),1))}),0===n.node.specifiers.length)&&n.prune()}),i},en=function(n,e){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(P(e))})},rn=function(n,e,r){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(r)})},D=function(n,e,r){var t=n.find(u.ImportDeclaration);0<t.length?u(t.paths()[0]).insertAfter(S(e,r)):1===(t=n.find(u.Program)).length&&t.paths()[0].node.body.unshift(S(e,r))},tn=function(n,e){0<E(n,e.module).length?en(n,e):D(n,e.module,[P(e)])},un=function(n,e,r,t){var i=E(n,e),t=(t?vn:sn)(r);0<i.length?rn(n,e,t):D(n,e,[t])},_=function(n,e){n=n.find(u.VariableDeclaration);0<n.length&&u(n.paths()[0]).insertAfter(on(e))},F=function(n,e,r){return u.expressionStatement(an(n,e,r))},an=function(n,e,r){return u.callExpression(fn(n,e),r)},on=function(n){return u.variableDeclaration("var",[cn(n)])},cn=function(n){return u.variableDeclarator(void 0!==n.m?u.identifier(n.m):u.identifier(n.reference),(0<n.reference.length?ln:L)(n))},ln=function(n){return u.memberExpression(L(n),u.identifier(n.reference))},fn=function(n,e){return u.memberExpression(u.identifier(n),u.identifier(e))},L=function(n){return u.callExpression(u.identifier("require"),[u.literal(n.module)])},S=function(n,e){return u.importDeclaration(e,u.literal(n))},P=function(n){return void 0!==n.m?u.importSpecifier(u.identifier(n.reference),u.identifier(n.m)):u.importSpecifier(u.identifier(n.reference))},sn=function(n){return u.importDefaultSpecifier(u.identifier(n))},vn=function(n){return u.importNamespaceSpecifier(u.identifier(n))};
1
+ var a,n=require("@babel/runtime/helpers/interopRequireDefault"),e=n(require("@babel/runtime/helpers/toConsumableArray")),c=(Object.defineProperty(exports,"t",{value:!0}),exports.instrument=void 0,require("path")),u=require("jscodeshift"),i=require("jscodeshift/src/Collection"),r=require("../scripts/FileOperationHelper"),l=require("../scripts/PathsConstants"),f=require("../lib/core/util/GetValuesFromPackage"),t=require("../scripts/util/InstrumentUtil"),o=require("./libs/react-native/Touchables.InstrInfo"),s=require("./libs/react-native/RefreshControl.InstrInfo"),v=require("./libs/react-native/Switch.InstrInfo"),d=require("./libs/community/gesture-handler/Touchables.InstrInfo"),p=require("./libs/community/Picker.InstrInfo"),m=require("./model/Types"),g=require("./parser/ParserUtil"),y=((n=>{n[n.i=-1]="Filtered",n[n.u=0]="Normal",n[n.o=1]="ReactNative",n[n.l=2]="React",n[n.v=3]="ReactNativeCssInterop"})(a=a||{}),[]),q=(y.push.apply(y,(0,e.default)(o.instrumentationInfo)),y.push.apply(y,(0,e.default)(s.instrumentationInfo)),y.push.apply(y,(0,e.default)(v.instrumentationInfo)),y.push.apply(y,(0,e.default)(d.instrumentationInfo)),y.push.apply(y,(0,e.default)(p.instrumentationInfo)),["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"]),b="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(n,e,r){e=O(e);var t=z(e);if(t!==a.i){var i=!1,u=N(e,n);if(t===a.l)U(u),i=!0;else if(t===a.o)e.endsWith("AppRegistryImpl.js")?null!=r&&r.autoStart&&V(u)&&(i=!0):e.endsWith("AppRegistry.js")?null!=r&&r.autoStart&&w(u)&&(i=!0):e.endsWith("renderApplication.js")?(A(u),i=!0):e.endsWith("ExceptionsManager.js")&&(o=void 0!==r&&r.autoStart&&r.errorHandler.enabled,J(u,r.errorHandler.reportFatalErrorAsCrash,o),i=!0);else if(t===a.v)i=G(u)||i;else{var o=k(e,r);if(r.navigation.enabled&&L(e,u))i=!0;else{if(!o.input&&!o.lifecycle)return null!=r&&r.debug&&console.log("Dynatrace - Filtered All: ".concat(e)),I(e),n;o.lifecycle&&A(u)&&(i=!0),o.input&&y.forEach(function(n){n=X(u,n);u=n.root,i=i||n.p})}}i?(n=u.toSource({quote:"single"}),h(n,e)):I(e),null!=r&&r.debug&&i&&console.log("Dynatrace - Modified Filename: "+e)}else e.includes(c.join("@dynatrace","react-native-plugin"))&&e.endsWith(c.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==r&&(t=(0,f.getHostAppBundleInfo)(l.default.getPackageJsonFile()),o=N(e,n),void 0!==r.lifecycle&&x(o,"getLifecycleUpdate",r.lifecycle.includeUpdate),void 0!==r.debug&&x(o,"getLogLevel",r.debug?0:1),void 0!==r.bundleName?x(o,"getBundleName",r.bundleName):null!==t&&x(o,"getBundleName",null==t?void 0:t.name),void 0!==r.bundleVersion?x(o,"getBundleVersion",r.bundleVersion):null!==t&&x(o,"getBundleVersion",null==t?void 0:t.version),void 0!==r.input&&void 0!==r.input.actionNamePrivacy&&x(o,"getActionNamePrivacy",r.input.actionNamePrivacy),void 0!==r.errorHandler&&(x(o,"isErrorHandlerEnabled",r.errorHandler.enabled),x(o,"isReportFatalErrorAsCrash",r.errorHandler.reportFatalErrorAsCrash)),r.autoStart&&x(o,"isAutoStartupEnabled",r.autoStart),n=o.toSource({quote:"single"}),h(n,e));return n},L=(exports.instrument=instrument,function(n,e){return!!T(n,e)&&(n="import { monitorNavigation } from '".concat(b,"/react-navigation/ReactNavigation';"),e.find(u.ImportDeclaration).at(0).insertBefore(n),!0)}),T=function(n,e){var r=!1;return n.includes("@react-navigation")&&n.includes("core")&&(n.includes("BaseNavigationContainer.js")||n.includes("BaseNavigationContainer.tsx"))&&e.find(u.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(n){r=!0,n.parent.insertAfter("monitorNavigation(getRootState);")}),r},A=function(n){var e=n.findJSXElements(),t=!1;return 0<e.length&&(n.find(u.FunctionDeclaration).forEach(function(n){var e,r=(0,i.fromPaths)([n]);0<r.findJSXElements().length&&null!=n&&null!=n.value&&null!=n.value.id&&n.value.id.name.toString()&&(e=r.find(u.ClassDeclaration),r=r.find(u.ClassExpression),0===e.length)&&0===r.length&&(j(n,m.Types.FunctionalComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ClassDeclaration).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n&&null!=n.value&&n.value.id&&n.value.id.name.toString()&&(j(n,m.Types.ClassComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ArrowFunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(j(n,m.Types.FunctionalComponent,n.parent.value.id.name),t=!0)})),t},j=function(n,e,r){for(e=u.expressionStatement(u.assignmentExpression("=",u.memberExpression(u.identifier(r),u.identifier("_dtInfo")),M(e,r)));"body"!==(null==n?void 0:n.parentPath.name);)n=n.parentPath;void 0!==n.parentPath&&n.insertAfter(e)},M=function(n,e){return u.objectExpression([u.objectProperty(u.identifier("type"),u.numericLiteral(n)),u.objectProperty(u.identifier("name"),u.stringLiteral(e))])},x=function(n,e,r){var n=n.find(u.Identifier).filter(function(n){return n.node.name===e});1===n.length&&"ReturnStatement"===(n=n.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof r&&(n.argument=u.booleanLiteral(r)),"string"==typeof r&&(n.argument=u.stringLiteral(r)),"number"==typeof r)&&(n.argument=u.numericLiteral(r))},N=function(n,e){return u.withParser((0,g.chooseParser)(n,e))(e)},O=function(n){return c.isAbsolute(n)?n.replace(l.default.getApplicationPath()+c.sep,""):n},I=function(n){try{var e=c.join(l.default.getBuildPath(),n+t.INSTRUMENTED_FILE_EXTENSION);r.default.checkIfFileExistsSync(e),r.default.deleteFileSync(e)}catch(n){}},h=function(n,e){e=c.join(l.default.getBuildPath(),e);try{r.default.checkIfFileExistsSync(c.dirname(e))}catch(n){r.default.createDirectorySync(c.dirname(e))}r.default.writeTextToFileSync(e+t.INSTRUMENTED_FILE_EXTENSION,n)},k=function(n,e){var r={input:!1,lifecycle:!1};return void 0!==e&&(void 0!==e.lifecycle&&void 0!==e.lifecycle.instrument&&e.lifecycle.instrument(n)&&(r.lifecycle=!0),void 0!==e.input)&&void 0!==e.input.instrument&&e.input.instrument(n)&&(r.input=!0),r},U=function(n){var e,n=n.find(u.Program);1===n.length&&(e=u.expressionStatement(u.callExpression(u.memberExpression(u.callExpression(u.identifier("require"),[u.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),u.identifier("instrumentCreateElement")),[u.memberExpression(u.identifier("module"),u.identifier("exports"))])),n.paths()[0].node.body.push(e))},V=function(n){var e=n.find(u.FunctionDeclaration,{id:{name:"runApplication"}});return 1===e.length&&(D(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,_("_DynatraceApplicationHandler","startup",[])),!0)},w=function(n){var e=n.find(u.ObjectMethod,{key:{name:"runApplication"}});return 1===e.length&&(D(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,_("_DynatraceApplicationHandler","startup",[])),!0)},J=function(n,r,t){var i=u;n.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(n){var e=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(r),i.literal(t)]),e=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(n.node.body.body)),e]));n.node.body.body=[e]})},G=function(n){var e=!1,n=n.find(u.CallExpression,{callee:{name:"require"}});return n.find(u.Literal,{value:"react/jsx-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-runtime",e=!0,n}),n.find(u.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-dev-runtime",e=!0,n}),e},R=function(n,e){for(var r=arguments.length,t=new Array(2<r?r-2:0),i=2;i<r;i++)t[i-2]=arguments[i];return n.splice.apply(n,[e,0].concat(t))},z=function(n){if(n.includes("@dynatrace"))return a.i;var e=c.extname(n);if(".js"!==e&&".ts"!==e&&".tsx"!==e&&".jsx"!==e)return a.i;for(var r=c.parse(n),t=r.dir.split(c.sep),i=0;i<t.length;i++)if("node_modules"===t[i]){if("react-native"===t[i+1]||"create-react-class"===t[i+1]||"react-clone-referenced-element"===t[i+1])return q.includes(r.name)?a.o:a.i;if("react"===t[i+1]&&"index"===r.name)return a.l;if("react-native-css-interop"===t[i+1]&&("jsx-runtime"===r.name||"jsx-dev-runtime"===r.name))return a.v}return a.u},K=function(n,e,r){var t=Q(n,e,r);return W(n,e,r)||t},Q=function(n,e,r){var t=Y(n,e);return 0<t.length&&(void 0!==(t=H(t,e.reference,!1))&&(r.m=t.localName),tn(n,r),!0)},W=function(n,e,r){var t=C(n,e.module);if(1===t.length){t=H(t,e.reference,!0);if(void 0!==t)return un(n,r.defaultImport,t.localName,"ImportNamespaceSpecifier"===t.type),!0}return!1},X=function(n,e){var r=JSON.parse(JSON.stringify(e.new));return{root:n,p:K(n,e.old,r)||Z(n,e.old,e.new.defaultImport)}},Y=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module&&null!=n.node.specifiers&&n.node.specifiers.some(function(n){return E(n)&&n.imported.name===e.reference||n.local&&n.local.name===e.reference})})},E=function(n){return void 0!==n.imported},Z=function(n,e,r){var t=!1;return n.find(u.CallExpression).filter(function(n){return $(n.node.callee)&&nn(n.node.arguments[0])&&n.node.arguments[0].value===e.module&&void 0!==n.parent}).forEach(function(n){(void 0===n.parent.value.property||void 0!==n.parent.value.property&&void 0!==n.parent.value.property.name&&n.parent.value.property.name===e.reference)&&(n.node.arguments[0].value=r,t=t||!0)}),t},$=function(n){return"require"===n.name},nn=function(n){return"StringLiteral"===n.type||"Literal"===n.type},C=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e})},H=function(n,r,t){var i;return n.forEach(function(n){void 0!==n.node.specifiers&&(n.node.specifiers=n.node.specifiers.filter(function(n){var e;return E(n)&&!t?((e=n.imported.name!==r)||null==n.local||n.imported.name===n.local.name||(i={localName:n.local.name.toString(),type:n.type}),e):!(!E(n)&&t&&(null!=n.local&&(i={localName:n.local.name.toString(),type:n.type}),1))}),0===n.node.specifiers.length)&&n.prune()}),i},en=function(n,e){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(P(e))})},rn=function(n,e,r){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(r)})},S=function(n,e,r){var t=n.find(u.ImportDeclaration);0<t.length?u(t.paths()[0]).insertAfter(B(e,r)):1===(t=n.find(u.Program)).length&&t.paths()[0].node.body.unshift(B(e,r))},tn=function(n,e){0<C(n,e.module).length?en(n,e):S(n,e.module,[P(e)])},un=function(n,e,r,t){var i=C(n,e),t=(t?vn:sn)(r);0<i.length?rn(n,e,t):S(n,e,[t])},D=function(n,e){n=n.find(u.VariableDeclaration);0<n.length&&u(n.paths()[0]).insertAfter(an(e))},_=function(n,e,r){return u.expressionStatement(on(n,e,r))},on=function(n,e,r){return u.callExpression(fn(n,e),r)},an=function(n){return u.variableDeclaration("var",[cn(n)])},cn=function(n){return u.variableDeclarator(void 0!==n.m?u.identifier(n.m):u.identifier(n.reference),(0<n.reference.length?ln:F)(n))},ln=function(n){return u.memberExpression(F(n),u.identifier(n.reference))},fn=function(n,e){return u.memberExpression(u.identifier(n),u.identifier(e))},F=function(n){return u.callExpression(u.identifier("require"),[u.literal(n.module)])},B=function(n,e){return u.importDeclaration(e,u.literal(n))},P=function(n){return void 0!==n.m?u.importSpecifier(u.identifier(n.reference),u.identifier(n.m)):u.importSpecifier(u.identifier(n.reference))},sn=function(n){return u.importDefaultSpecifier(u.identifier(n))},vn=function(n){return u.importNamespaceSpecifier(u.identifier(n))};
@@ -1,27 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerListener = void 0;
3
+ exports.monitorNavigation = void 0;
4
4
  const react_1 = require("react");
5
+ const react_native_1 = require("react-native");
5
6
  const ConsoleLogger_1 = require("../../../lib/core/logging/ConsoleLogger");
6
- let isRegistered = false;
7
+ const DynatraceBridge_1 = require("../../../lib/core/DynatraceBridge");
8
+ const BaseDataEventModifier_1 = require("../../../lib/next/events/modifier/BaseDataEventModifier");
7
9
  const logger = new ConsoleLogger_1.ConsoleLogger('ReactNavigation');
8
- const registerListener = (navContainer) => {
10
+ let activePath = '';
11
+ let appState = react_native_1.AppState.currentState;
12
+ const monitorNavigation = (getRootState) => {
9
13
  (0, react_1.useEffect)(() => {
10
- if (isRegistered &&
11
- navContainer.current != null &&
12
- navContainer.current.addListener != null) {
13
- isRegistered = true;
14
- navContainer.current.addListener('__unsafe_action__', (data) => {
15
- if (data != null &&
16
- data.data != null &&
17
- data.data.action != null) {
18
- logger.debug(`Listener Dispatch: ${JSON.stringify(data.data.action)}`);
19
- }
20
- });
21
- navContainer.current.addListener('state', (state) => {
22
- logger.debug(`Listener State: ${JSON.stringify(state)}`);
23
- });
14
+ var _a, _b;
15
+ let currentState = getRootState();
16
+ let newPath = '';
17
+ while (currentState === null || currentState === void 0 ? void 0 : currentState.routes[(_a = currentState.index) !== null && _a !== void 0 ? _a : 0]) {
18
+ const currentRoute = currentState === null || currentState === void 0 ? void 0 : currentState.routes[(_b = currentState.index) !== null && _b !== void 0 ? _b : 0];
19
+ newPath += `/${currentRoute.name}`;
20
+ currentState = currentRoute.state;
21
+ }
22
+ if (newPath !== activePath) {
23
+ if (activePath !== '') {
24
+ stopView();
25
+ }
26
+ startView(newPath);
27
+ activePath = newPath;
24
28
  }
25
29
  });
30
+ (0, react_1.useEffect)(() => {
31
+ const subscription = react_native_1.AppState.addEventListener('change', (nextAppState) => {
32
+ if (nextAppState !== 'active' && appState === 'active') {
33
+ stopView();
34
+ }
35
+ else if (nextAppState === 'active' && appState !== 'active') {
36
+ startView(activePath);
37
+ }
38
+ appState = nextAppState;
39
+ });
40
+ return () => {
41
+ subscription.remove();
42
+ };
43
+ }, []);
44
+ };
45
+ exports.monitorNavigation = monitorNavigation;
46
+ const startView = (newPath) => {
47
+ const startViewInternalEvent = new BaseDataEventModifier_1.BaseDataEventModifier().modifyEvent(Object.assign({ 'view.detected_name': newPath }, (activePath && {
48
+ 'view.source.detected_name': activePath,
49
+ })));
50
+ const fn = DynatraceBridge_1.DynatraceNative === null || DynatraceBridge_1.DynatraceNative === void 0 ? void 0 : DynatraceBridge_1.DynatraceNative.startViewInternal;
51
+ if (typeof fn === 'function') {
52
+ fn(startViewInternalEvent);
53
+ }
54
+ logger.debug(`startViewinternal(${JSON.stringify(startViewInternalEvent)})`);
55
+ };
56
+ const stopView = () => {
57
+ const fn = DynatraceBridge_1.DynatraceNative === null || DynatraceBridge_1.DynatraceNative === void 0 ? void 0 : DynatraceBridge_1.DynatraceNative.stopViewInternal;
58
+ if (typeof fn === 'function') {
59
+ fn();
60
+ }
61
+ logger.debug('stopViewInternal()');
26
62
  };
27
- exports.registerListener = registerListener;
@@ -0,0 +1,15 @@
1
+ //
2
+ // ConfigurationSubscriber.h
3
+ // DynatraceUEM
4
+ //
5
+ // Created by Schnalzenberger, Ralph on 07.07.25.
6
+ // Copyright © 2025 Dynatrace LLC. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+
11
+ @protocol ConfigurationSubscriber <NSObject>
12
+
13
+ - (void)notifyWithConfiguration:(NSDictionary<NSString*, id>*)configuration;
14
+
15
+ @end