@datadog/mobile-react-native-webview 2.4.3 → 2.5.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 (86) hide show
  1. package/DatadogSDKReactNativeWebView.podspec +46 -0
  2. package/android/build.gradle +249 -0
  3. package/android/detekt.yml +572 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +11 -0
  6. package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +35 -0
  7. package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt +112 -0
  8. package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +36 -0
  9. package/android/src/test/kotlin/com/datadog/reactnative/tools/unit/GenericAssert.kt +18 -0
  10. package/android/src/test/kotlin/com/datadog/reactnative/webview/DatadogWebViewTest.kt +126 -0
  11. package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
  12. package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.pbxproj +272 -0
  13. package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  14. package/ios/Sources/DatadogSDKReactNativeWebView.h +12 -0
  15. package/ios/Sources/RCTDatadogWebView.h +21 -0
  16. package/ios/Sources/RCTDatadogWebView.mm +53 -0
  17. package/ios/Sources/RCTDatadogWebViewManager.h +10 -0
  18. package/ios/Sources/RCTDatadogWebViewManager.mm +84 -0
  19. package/ios/Sources/RCTDatadogWebViewTracking.swift +67 -0
  20. package/lib/commonjs/ext-specs/NativeDdLogs.js +19 -0
  21. package/lib/commonjs/ext-specs/NativeDdLogs.js.map +1 -0
  22. package/lib/commonjs/ext-specs/NativeDdSdk.js.map +1 -0
  23. package/lib/commonjs/index.js +40 -7
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/specs/NativeDdWebView.js +16 -0
  26. package/lib/commonjs/specs/NativeDdWebView.js.map +1 -0
  27. package/lib/commonjs/utils/env-utils.js +17 -0
  28. package/lib/commonjs/utils/env-utils.js.map +1 -0
  29. package/lib/commonjs/utils/webview-js-utils.js +124 -0
  30. package/lib/commonjs/utils/webview-js-utils.js.map +1 -0
  31. package/lib/module/ext-specs/NativeDdLogs.js +17 -0
  32. package/lib/module/ext-specs/NativeDdLogs.js.map +1 -0
  33. package/lib/module/ext-specs/NativeDdSdk.js.map +1 -0
  34. package/lib/module/index.js +39 -7
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/specs/NativeDdWebView.js +11 -0
  37. package/lib/module/specs/NativeDdWebView.js.map +1 -0
  38. package/lib/module/utils/env-utils.js +10 -0
  39. package/lib/module/utils/env-utils.js.map +1 -0
  40. package/lib/module/utils/webview-js-utils.js +115 -0
  41. package/lib/module/utils/webview-js-utils.js.map +1 -0
  42. package/lib/typescript/ext-specs/NativeDdLogs.d.ts +16 -0
  43. package/lib/typescript/ext-specs/NativeDdLogs.d.ts.map +1 -0
  44. package/lib/typescript/ext-specs/NativeDdSdk.d.ts.map +1 -0
  45. package/lib/typescript/index.d.ts +20 -0
  46. package/lib/typescript/index.d.ts.map +1 -1
  47. package/lib/typescript/specs/NativeDdWebView.d.ts +4 -0
  48. package/lib/typescript/specs/NativeDdWebView.d.ts.map +1 -0
  49. package/lib/typescript/utils/env-utils.d.ts +2 -0
  50. package/lib/typescript/utils/env-utils.d.ts.map +1 -0
  51. package/lib/typescript/utils/webview-js-utils.d.ts +34 -0
  52. package/lib/typescript/utils/webview-js-utils.d.ts.map +1 -0
  53. package/package.json +22 -4
  54. package/src/__tests__/WebviewDatadog.test.tsx +39 -43
  55. package/src/__tests__/WebviewDatadogInjectedJS.test.tsx +200 -1
  56. package/src/__tests__/WebviewDatadogPerformance.test.tsx +12 -0
  57. package/src/__tests__/__utils__/string-utils.ts +13 -0
  58. package/src/__tests__/webview-js-utils.test.ts +51 -0
  59. package/src/ext-specs/NativeDdLogs.ts +25 -0
  60. package/src/{NativeDdSdk.ts → ext-specs/NativeDdSdk.ts} +1 -0
  61. package/src/index.tsx +70 -13
  62. package/src/specs/NativeDdWebView.ts +16 -0
  63. package/src/utils/env-utils.ts +9 -0
  64. package/src/utils/webview-js-utils.ts +150 -0
  65. package/lib/commonjs/NativeDdSdk.js.map +0 -1
  66. package/lib/commonjs/__utils__/formatAllowedHosts.js +0 -65
  67. package/lib/commonjs/__utils__/formatAllowedHosts.js.map +0 -1
  68. package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -32
  69. package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
  70. package/lib/module/NativeDdSdk.js.map +0 -1
  71. package/lib/module/__utils__/formatAllowedHosts.js +0 -58
  72. package/lib/module/__utils__/formatAllowedHosts.js.map +0 -1
  73. package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -24
  74. package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
  75. package/lib/typescript/NativeDdSdk.d.ts.map +0 -1
  76. package/lib/typescript/__utils__/formatAllowedHosts.d.ts +0 -2
  77. package/lib/typescript/__utils__/formatAllowedHosts.d.ts.map +0 -1
  78. package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts +0 -3
  79. package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts.map +0 -1
  80. package/src/__tests__/formatAllowedHosts.test.ts +0 -40
  81. package/src/__tests__/getInjectedJavaScriptBeforeContentLoaded.test.ts +0 -86
  82. package/src/__utils__/formatAllowedHosts.ts +0 -70
  83. package/src/__utils__/getInjectedJavaScriptBeforeContentLoaded.ts +0 -29
  84. /package/lib/commonjs/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
  85. /package/lib/module/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
  86. /package/lib/typescript/{NativeDdSdk.d.ts → ext-specs/NativeDdSdk.d.ts} +0 -0
@@ -0,0 +1,46 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "DatadogSDKReactNativeWebView"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => "12.0", :tvos => "12.0" }
14
+ s.source = { :git => "https://github.com/DataDog/dd-sdk-reactnative.git", :tag => "#{s.version}" }
15
+
16
+
17
+ s.source_files = "ios/Sources/*.{h,m,mm,swift}"
18
+
19
+ s.dependency "React-Core"
20
+
21
+ # /!\ Remember to keep the version in sync with DatadogSDKReactNative.podspec
22
+ s.dependency 'DatadogWebViewTracking', '~> 2.18.0'
23
+ s.dependency 'DatadogInternal', '~> 2.18.0'
24
+ s.dependency 'DatadogSDKReactNative'
25
+
26
+ s.test_spec 'Tests' do |test_spec|
27
+ test_spec.dependency "react-native-webview"
28
+ test_spec.dependency "React-RCTText"
29
+
30
+ test_spec.source_files = 'ios/Tests/*.swift'
31
+ test_spec.platforms = { :ios => "13.4", :tvos => "13.4" }
32
+ end
33
+
34
+
35
+ # This guard prevents installing the dependencies when we run `pod install` in the old architecture.
36
+ # The `install_modules_dependencies` function is only available from RN 0.71, the new architecture is not
37
+ # supported on earlier RN versions.
38
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
39
+ s.pod_target_xcconfig = {
40
+ "DEFINES_MODULE" => "YES",
41
+ "OTHER_CPLUSPLUSFLAGS" => "-DRCT_NEW_ARCH_ENABLED=1"
42
+ }
43
+
44
+ install_modules_dependencies(s)
45
+ end
46
+ end
@@ -0,0 +1,249 @@
1
+ import java.nio.file.Paths
2
+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3
+
4
+ buildscript {
5
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
6
+ def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['DatadogSDKReactNativeWebView_kotlinVersion']
7
+
8
+ repositories {
9
+ mavenCentral()
10
+ google()
11
+ gradlePluginPortal()
12
+ }
13
+
14
+ dependencies {
15
+ classpath 'com.android.tools.build:gradle:7.2.2'
16
+ // noinspection DifferentKotlinGradleVersion
17
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
18
+ classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1"
19
+ classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0"
20
+ classpath 'com.github.bjoernq:unmockplugin:0.7.9'
21
+ }
22
+ }
23
+
24
+
25
+ apply plugin: 'de.mobilej.unmock'
26
+
27
+ def isNewArchitectureEnabled() {
28
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
29
+ }
30
+
31
+ apply plugin: 'com.android.library'
32
+ if (isNewArchitectureEnabled()) {
33
+ apply plugin: 'com.facebook.react'
34
+ }
35
+ apply plugin: 'kotlin-android'
36
+ apply plugin: 'org.jlleitschuh.gradle.ktlint'
37
+ apply plugin: "io.gitlab.arturbosch.detekt"
38
+
39
+ /**
40
+ * Finds the path of the installed npm package with the given name using Node's
41
+ * module resolution algorithm, which searches "node_modules" directories up to
42
+ * the file system root.
43
+ * This enables us to handle monorepos without requiring the node executable.
44
+ *
45
+ * The search begins at the given base directory (a File object). The returned
46
+ * path is a string.
47
+ */
48
+ static def findNodeModulePath(baseDir, packageName) {
49
+ def basePath = baseDir.toPath().normalize()
50
+ // Node's module resolution algorithm searches up to the root directory,
51
+ // after which the base path will be null
52
+ while (basePath) {
53
+ def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
54
+ if (candidatePath.toFile().exists()) {
55
+ return candidatePath.toString()
56
+ }
57
+ basePath = basePath.getParent()
58
+ }
59
+ return null
60
+ }
61
+
62
+ def resolveReactNativeDirectory() {
63
+ def reactNativeLocation = rootProject.hasProperty("reactNativeDir") ? rootProject.getProperty("reactNativeDir") : null
64
+
65
+ if (reactNativeLocation != null) {
66
+ return file(reactNativeLocation)
67
+ }
68
+
69
+ def reactNativePath = findNodeModulePath(projectDir, "react-native")
70
+
71
+ if (reactNativePath != null) {
72
+ return file(reactNativePath)
73
+ }
74
+
75
+ throw new Exception(
76
+ "${project.name}: Failed to resolve 'react-native' in the project. " +
77
+ "Altenatively, you can specify 'reactNativeDir' with the path to 'react-native' in your 'gradle.properties' file."
78
+ )
79
+ }
80
+
81
+ def reactNativeRootDir = resolveReactNativeDirectory()
82
+ def reactProperties = new Properties()
83
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
84
+
85
+ def reactNativeVersion = reactProperties.getProperty("VERSION_NAME")
86
+ def (reactNativeMajorVersion, reactNativeMinorVersion) = reactNativeVersion.split("\\.").collect { it.isInteger() ? it.toInteger() : it }
87
+
88
+ def getExtOrDefault(name) {
89
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['DatadogSDKReactNativeWebView_' + name]
90
+ }
91
+
92
+ def getExtOrIntegerDefault(name) {
93
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['DatadogSDKReactNativeWebView_' + name]).toInteger()
94
+ }
95
+
96
+ android {
97
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
98
+ buildToolsVersion getExtOrDefault('buildToolsVersion')
99
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
100
+ if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
101
+ namespace = "com.datadog.reactnative.webview"
102
+ }
103
+ if (agpVersion.tokenize('.')[0].toInteger() >= 8) {
104
+ buildFeatures {
105
+ buildConfig = true
106
+ }
107
+ }
108
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
109
+ compileOptions {
110
+ sourceCompatibility JavaVersion.VERSION_11
111
+ targetCompatibility JavaVersion.VERSION_11
112
+ }
113
+ kotlinOptions {
114
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
115
+ }
116
+ }
117
+
118
+ defaultConfig {
119
+ minSdkVersion 21
120
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
121
+ versionCode 1
122
+ versionName "1.0"
123
+ buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
124
+ }
125
+
126
+ sourceSets {
127
+ main {
128
+ if (isNewArchitectureEnabled()) {
129
+ java.srcDirs += ['src/newarch']
130
+ } else {
131
+ java.srcDirs += ['src/oldarch']
132
+ }
133
+ }
134
+
135
+ test {
136
+ java.srcDir("src/test/kotlin")
137
+ }
138
+ }
139
+
140
+ testOptions {
141
+ unitTests {
142
+ returnDefaultValues = true
143
+ }
144
+ }
145
+
146
+ buildTypes {
147
+ release {
148
+ minifyEnabled false
149
+ }
150
+ }
151
+ lintOptions {
152
+ disable 'GradleCompatible'
153
+ }
154
+ compileOptions {
155
+ sourceCompatibility JavaVersion.VERSION_11
156
+ targetCompatibility JavaVersion.VERSION_11
157
+ }
158
+ }
159
+
160
+ repositories {
161
+ mavenCentral()
162
+ google()
163
+ maven { url "https://jitpack.io" }
164
+ mavenLocal()
165
+
166
+ if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
167
+ def androidSourcesDir = file("$reactNativeRootDir/android")
168
+ def androidSourcesName = "React Native sources"
169
+
170
+ if (androidSourcesDir.exists()) {
171
+ maven {
172
+ url androidSourcesDir.toString()
173
+ name androidSourcesName
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ def kotlin_version = getExtOrDefault('kotlinVersion')
180
+
181
+ dependencies {
182
+ if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
183
+ // noinspection GradleDynamicVersion
184
+ api 'com.facebook.react:react-native:+'
185
+ } else {
186
+ // We specify the $reactNativeVersion, like it's done on the react-native-gradle-plugin, as the plugin is not applied in tests.
187
+ // There is no impact for apps as we apply the same logic:
188
+ // https://github.com/facebook/react-native/blob/e1a1e6aa8030bf11d691c3dcf7abd13b25175027/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt
189
+ implementation "com.facebook.react:react-android:$reactNativeVersion"
190
+ }
191
+
192
+ implementation "com.datadoghq:dd-sdk-android-webview:2.14.0"
193
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
194
+
195
+ implementation project(path: ':datadog_mobile-react-native')
196
+ implementation project(path: ':react-native-webview')
197
+
198
+ testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
199
+ testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
200
+ testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
201
+ testImplementation "org.junit.jupiter:junit-jupiter-params:5.6.2"
202
+ testImplementation "org.mockito:mockito-junit-jupiter:3.4.6"
203
+ testImplementation "org.assertj:assertj-core:3.18.1"
204
+ testImplementation "com.github.xgouchet.Elmyr:core:1.3.1"
205
+ testImplementation "com.github.xgouchet.Elmyr:inject:1.3.1"
206
+ testImplementation "com.github.xgouchet.Elmyr:junit5:1.3.1"
207
+ testImplementation "com.github.xgouchet.Elmyr:jvm:1.3.1"
208
+ testImplementation "org.mockito.kotlin:mockito-kotlin:5.1.0"
209
+ testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
210
+ unmock 'org.robolectric:android-all:4.4_r1-robolectric-r2'
211
+ }
212
+
213
+ tasks.withType(Test) {
214
+ useJUnitPlatform {
215
+ includeEngines("spek", "junit-jupiter", "junit-vintage")
216
+ }
217
+ reports {
218
+ junitXml.required.set(true)
219
+ html.required.set(true)
220
+ }
221
+ }
222
+
223
+ tasks.named("check") {
224
+ dependsOn("ktlintCheck")
225
+ dependsOn("detekt")
226
+ }
227
+
228
+ ktlint {
229
+ debug.set(false)
230
+ android.set(true)
231
+ outputToConsole.set(true)
232
+ ignoreFailures.set(false)
233
+ enableExperimentalRules.set(false)
234
+ filter {
235
+ exclude("**/generated/**")
236
+ include("**/kotlin/**")
237
+ }
238
+ }
239
+
240
+ detekt {
241
+ input = files("$projectDir/src/main/kotlin")
242
+ config = files("$projectDir/detekt.yml")
243
+ reports {
244
+ xml {
245
+ enabled = true
246
+ destination = file("build/reports/detekt.xml")
247
+ }
248
+ }
249
+ }