@adshift/react-native-plugin 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/AdShiftReactNativePlugin.podspec +20 -4
  2. package/CHANGELOG.md +57 -8
  3. package/README.md +131 -74
  4. package/android/build.gradle +3 -2
  5. package/android/consumer-rules.pro +2 -21
  6. package/android/src/main/AndroidManifest.xml +14 -1
  7. package/android/src/main/java/com/adshift/reactnativeplugin/ActivityIntents.kt +307 -0
  8. package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +90 -153
  9. package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +0 -20
  10. package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +40 -7
  11. package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +51 -5
  12. package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +0 -5
  13. package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +21 -11
  14. package/android/src/test/java/com/adshift/reactnativeplugin/LaunchLinkRecordTest.kt +420 -0
  15. package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +97 -25
  16. package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +0 -4
  17. package/ios/AdShiftReactNativePlugin.h +0 -12
  18. package/ios/AdShiftReactNativePlugin.mm +7 -14
  19. package/ios/AdShiftReactNativePluginHelper.swift +38 -73
  20. package/ios/Core/BridgeRules.swift +42 -30
  21. package/lib/commonjs/Adshift.js +100 -284
  22. package/lib/commonjs/Adshift.js.map +1 -1
  23. package/lib/commonjs/NativeAdShiftReactNativePlugin.js +2 -11
  24. package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -1
  25. package/lib/commonjs/index.js +6 -0
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/jest/index.js +6 -18
  28. package/lib/commonjs/jest/index.js.map +1 -1
  29. package/lib/commonjs/nativeSdkVersions.js +4 -6
  30. package/lib/commonjs/nativeSdkVersions.js.map +1 -1
  31. package/lib/commonjs/types/AdshiftAdRevenue.js +0 -24
  32. package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -1
  33. package/lib/commonjs/types/AdshiftConfig.js +11 -23
  34. package/lib/commonjs/types/AdshiftConfig.js.map +1 -1
  35. package/lib/commonjs/types/AdshiftConsent.js +9 -45
  36. package/lib/commonjs/types/AdshiftConsent.js.map +1 -1
  37. package/lib/commonjs/types/AdshiftConsentSnapshot.js +5 -24
  38. package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -1
  39. package/lib/commonjs/types/AdshiftDeepLink.js +50 -33
  40. package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -1
  41. package/lib/commonjs/types/AdshiftError.js +7 -27
  42. package/lib/commonjs/types/AdshiftError.js.map +1 -1
  43. package/lib/commonjs/types/AdshiftEventParam.js +4 -38
  44. package/lib/commonjs/types/AdshiftEventParam.js.map +1 -1
  45. package/lib/commonjs/types/AdshiftEventType.js +1 -39
  46. package/lib/commonjs/types/AdshiftEventType.js.map +1 -1
  47. package/lib/commonjs/types/AdshiftThirdPartySharing.js +7 -38
  48. package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -1
  49. package/lib/commonjs/types/index.js +12 -0
  50. package/lib/commonjs/types/index.js.map +1 -1
  51. package/lib/commonjs/version.js +1 -1
  52. package/lib/module/Adshift.js +101 -285
  53. package/lib/module/Adshift.js.map +1 -1
  54. package/lib/module/NativeAdShiftReactNativePlugin.js +2 -12
  55. package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
  56. package/lib/module/index.js +2 -47
  57. package/lib/module/index.js.map +1 -1
  58. package/lib/module/jest/index.js +7 -19
  59. package/lib/module/jest/index.js.map +1 -1
  60. package/lib/module/nativeSdkVersions.js +4 -6
  61. package/lib/module/nativeSdkVersions.js.map +1 -1
  62. package/lib/module/types/AdshiftAdRevenue.js +0 -24
  63. package/lib/module/types/AdshiftAdRevenue.js.map +1 -1
  64. package/lib/module/types/AdshiftConfig.js +10 -23
  65. package/lib/module/types/AdshiftConfig.js.map +1 -1
  66. package/lib/module/types/AdshiftConsent.js +9 -45
  67. package/lib/module/types/AdshiftConsent.js.map +1 -1
  68. package/lib/module/types/AdshiftConsentSnapshot.js +5 -24
  69. package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -1
  70. package/lib/module/types/AdshiftDeepLink.js +49 -32
  71. package/lib/module/types/AdshiftDeepLink.js.map +1 -1
  72. package/lib/module/types/AdshiftError.js +7 -28
  73. package/lib/module/types/AdshiftError.js.map +1 -1
  74. package/lib/module/types/AdshiftEventParam.js +4 -38
  75. package/lib/module/types/AdshiftEventParam.js.map +1 -1
  76. package/lib/module/types/AdshiftEventType.js +1 -39
  77. package/lib/module/types/AdshiftEventType.js.map +1 -1
  78. package/lib/module/types/AdshiftThirdPartySharing.js +7 -38
  79. package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -1
  80. package/lib/module/types/index.js +2 -2
  81. package/lib/module/types/index.js.map +1 -1
  82. package/lib/module/version.js +1 -1
  83. package/lib/typescript/commonjs/src/Adshift.d.ts +68 -184
  84. package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
  86. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/index.d.ts +2 -34
  88. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/src/jest/index.d.ts +9 -21
  90. package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +4 -6
  92. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +0 -24
  94. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -1
  95. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +35 -39
  96. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -1
  97. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +9 -49
  98. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +10 -28
  100. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
  101. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +55 -39
  102. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -1
  103. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +7 -26
  104. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -1
  105. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +3 -19
  106. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -1
  107. package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts +1 -23
  108. package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -1
  109. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +7 -38
  110. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
  111. package/lib/typescript/commonjs/src/types/index.d.ts +3 -3
  112. package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -1
  113. package/lib/typescript/commonjs/src/version.d.ts +1 -1
  114. package/lib/typescript/module/src/Adshift.d.ts +68 -184
  115. package/lib/typescript/module/src/Adshift.d.ts.map +1 -1
  116. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
  117. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
  118. package/lib/typescript/module/src/index.d.ts +2 -34
  119. package/lib/typescript/module/src/index.d.ts.map +1 -1
  120. package/lib/typescript/module/src/jest/index.d.ts +9 -21
  121. package/lib/typescript/module/src/jest/index.d.ts.map +1 -1
  122. package/lib/typescript/module/src/nativeSdkVersions.d.ts +4 -6
  123. package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -1
  124. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +0 -24
  125. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -1
  126. package/lib/typescript/module/src/types/AdshiftConfig.d.ts +35 -39
  127. package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -1
  128. package/lib/typescript/module/src/types/AdshiftConsent.d.ts +9 -49
  129. package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -1
  130. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +10 -28
  131. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
  132. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +55 -39
  133. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -1
  134. package/lib/typescript/module/src/types/AdshiftError.d.ts +7 -26
  135. package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -1
  136. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +3 -19
  137. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -1
  138. package/lib/typescript/module/src/types/AdshiftEventType.d.ts +1 -23
  139. package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -1
  140. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +7 -38
  141. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
  142. package/lib/typescript/module/src/types/index.d.ts +3 -3
  143. package/lib/typescript/module/src/types/index.d.ts.map +1 -1
  144. package/lib/typescript/module/src/version.d.ts +1 -1
  145. package/package.json +11 -1
  146. package/src/Adshift.ts +118 -285
  147. package/src/NativeAdShiftReactNativePlugin.ts +19 -47
  148. package/src/index.tsx +7 -46
  149. package/src/jest/index.ts +11 -20
  150. package/src/nativeSdkVersions.ts +4 -6
  151. package/src/types/AdshiftAdRevenue.ts +0 -24
  152. package/src/types/AdshiftConfig.ts +48 -55
  153. package/src/types/AdshiftConsent.ts +9 -49
  154. package/src/types/AdshiftConsentSnapshot.ts +11 -38
  155. package/src/types/AdshiftDeepLink.ts +87 -39
  156. package/src/types/AdshiftError.ts +7 -26
  157. package/src/types/AdshiftEventParam.ts +4 -38
  158. package/src/types/AdshiftEventType.ts +1 -39
  159. package/src/types/AdshiftThirdPartySharing.ts +7 -38
  160. package/src/types/index.ts +9 -2
  161. package/src/version.ts +1 -1
  162. package/vendor/ios/AdshiftSDK.files.json +30 -0
  163. package/vendor/ios/AdshiftSDK.xcframework/Info.plist +44 -0
  164. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/AdshiftSDK +0 -0
  165. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +315 -0
  166. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Info.plist +0 -0
  167. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.abi.json +18729 -0
  168. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +414 -0
  169. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  170. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftinterface +414 -0
  171. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/module.modulemap +4 -0
  172. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/PrivacyInfo.xcprivacy +132 -0
  173. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/AdshiftSDK +0 -0
  174. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +626 -0
  175. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Info.plist +0 -0
  176. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +18729 -0
  177. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +414 -0
  178. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  179. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +414 -0
  180. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +18729 -0
  181. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +414 -0
  182. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  183. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +414 -0
  184. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/module.modulemap +4 -0
  185. package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/PrivacyInfo.xcprivacy +132 -0
@@ -3,6 +3,9 @@ package com.adshift.reactnativeplugin
3
3
  import android.app.Activity
4
4
  import android.content.Context
5
5
  import android.content.Intent
6
+ import android.os.Build
7
+ import android.os.Bundle
8
+ import android.provider.Settings
6
9
  import androidx.test.core.app.ApplicationProvider
7
10
  import com.facebook.react.bridge.JavaOnlyArray
8
11
  import com.facebook.react.bridge.JavaOnlyMap
@@ -13,15 +16,19 @@ import com.facebook.soloader.nativeloader.NativeLoader
13
16
  import com.facebook.soloader.nativeloader.NativeLoaderDelegate
14
17
  import io.mockk.every
15
18
  import io.mockk.mockk
19
+ import java.io.File
20
+ import java.lang.reflect.Field
16
21
 
17
- /**
18
- * The module keeps its Intent bookkeeping in the companion object, so it survives module
19
- * instances the way it survives JavaScript reloads. Each test starts from a freshly launched
20
- * process, which this helper restores through reflection.
21
- */
22
+ /** The module's state lives in its companion object and outlives instances; tests reset it here. */
22
23
  internal object ModuleState {
23
24
 
24
25
  fun reset() {
26
+ killProcess()
27
+ LaunchRecordsState.deleteFile()
28
+ }
29
+
30
+ /** As when Android kills the process: memory goes, the app's files stay. */
31
+ fun killProcess() {
25
32
  set("currentModule", null)
26
33
  set("sdkInitialized", false)
27
34
  set("readyForIntents", false)
@@ -29,21 +36,24 @@ internal object ModuleState {
29
36
  set("autoHandleDeepLinks", true)
30
37
  set("collectOaidApplied", false)
31
38
  set("pendingIntent", null)
32
- set("lastLaunchIntentFingerprint", null)
33
39
  clear("processedIntents")
34
40
  clear("autoForwardedUrls")
35
41
  clear("launchForwardedUrls")
36
42
  clear("registeredPushPaths")
37
43
  clear("pendingDeepLinks")
44
+ for (name in listOf("byActivity", "byIntent", "newIntentReceived")) {
45
+ when (val value = objectField(ActivityIntents::class.java, name).get(null)) {
46
+ is MutableMap<*, *> -> value.clear()
47
+ is MutableCollection<*> -> value.clear()
48
+ }
49
+ }
50
+ objectField(ActivityIntents::class.java, "application").set(null, null)
51
+ LaunchRecordsState.forgetMemory()
38
52
  }
39
53
 
40
- /** Deep link results still waiting for a JavaScript listener. */
41
54
  fun pendingDeepLinkCount(): Int = (field("pendingDeepLinks").get(null) as Collection<*>).size
42
55
 
43
- /**
44
- * Simulates the short dedup window having passed, so what remains is the memory that lasts
45
- * as long as the process. A reload can happen minutes after the app was opened.
46
- */
56
+ /** Stands in for the two-second window passing; what lasts for the process remains. */
47
57
  fun expireAutoForwardWindow() = clear("autoForwardedUrls")
48
58
 
49
59
  private fun set(name: String, value: Any?) = field(name).set(null, value)
@@ -55,25 +65,90 @@ internal object ModuleState {
55
65
  }
56
66
  }
57
67
 
58
- private fun field(name: String) = AdShiftReactNativePluginModule::class.java
59
- .getDeclaredField(name)
60
- .apply { isAccessible = true }
68
+ private fun field(name: String) = objectField(AdShiftReactNativePluginModule::class.java, name)
69
+ }
70
+
71
+ internal object LaunchRecordsState {
72
+
73
+ private val app: Context get() = ApplicationProvider.getApplicationContext()
74
+
75
+ val file: File get() = File(app.noBackupFilesDir, "adshift_rn_launch_links.json")
76
+
77
+ fun deleteFile() {
78
+ file.delete()
79
+ File(file.path + ".bak").delete()
80
+ }
81
+
82
+ /** Drops what the process read, so the next use reads the file again. */
83
+ fun forgetMemory() {
84
+ objectField(LaunchRecords::class.java, "file").set(null, null)
85
+ objectField(LaunchRecords::class.java, "entries").set(null, null)
86
+ }
87
+
88
+ /** A new boot of the phone, as the next process reads it. */
89
+ fun restartPhone(bootCount: Int) {
90
+ Settings.Global.putInt(app.contentResolver, Settings.Global.BOOT_COUNT, bootCount)
91
+ forgetMemory()
92
+ }
93
+ }
94
+
95
+ internal fun objectField(type: Class<*>, name: String): Field =
96
+ type.getDeclaredField(name).apply { isAccessible = true }
97
+
98
+ internal const val TASK_ID = 38
99
+
100
+ internal class FakeActivity(var intent: Intent?, val taskId: Int = TASK_ID) {
101
+
102
+ var finishing = false
103
+
104
+ val activity: Activity = mockk<Activity>(relaxed = true).also {
105
+ every { it.intent } answers { intent }
106
+ every { it.taskId } answers { taskId }
107
+ every { it.isFinishing } answers { finishing }
108
+ }
109
+
110
+ /** From API 29 the state the system kept, then what the app passes to `super.onCreate`. */
111
+ fun create(savedState: Bundle?, appPassesState: Boolean = true): FakeActivity {
112
+ if (Build.VERSION.SDK_INT >= 29) ActivityIntents.onActivityPreCreated(activity, savedState)
113
+ ActivityIntents.onActivityCreated(activity, if (appPassesState) savedState else null)
114
+ return this
115
+ }
116
+
117
+ /** `super.onNewIntent` and `setIntent`, the step the setup asks of `MainActivity`. */
118
+ fun keepNewIntent(newIntent: Intent) {
119
+ intent = newIntent
120
+ }
121
+
122
+ /** Closed for good, for example with Back. */
123
+ fun finish() {
124
+ finishing = true
125
+ ActivityIntents.onActivityDestroyed(activity)
126
+ }
61
127
  }
62
128
 
63
- /**
64
- * Minimal React context for the module: only the members it touches are stubbed. [launchIntent]
65
- * is what `currentActivity.intent` returns and may change between deliveries.
66
- */
129
+ internal fun recreateActivityHolding(intent: Intent): FakeActivity =
130
+ FakeActivity(intent).create(Bundle())
131
+
132
+ /** Setting [launchIntent] hands the current Activity a new Intent, as `setIntent` does. */
67
133
  internal class TestReactContext {
68
134
 
69
- var launchIntent: Intent? = null
135
+ var activity: FakeActivity? = null
136
+
137
+ var launchIntent: Intent?
138
+ get() = activity?.intent
139
+ set(value) {
140
+ val current = activity
141
+ when {
142
+ value == null -> activity = null
143
+ current == null -> activity = FakeActivity(value)
144
+ else -> current.keepNewIntent(value)
145
+ }
146
+ }
70
147
 
71
148
  val reactContext: ReactApplicationContext = mockk(relaxed = true)
72
149
 
73
150
  init {
74
- val activity = mockk<Activity>(relaxed = true)
75
- every { activity.intent } answers { launchIntent }
76
- every { reactContext.currentActivity } answers { launchIntent?.let { activity } }
151
+ every { reactContext.currentActivity } answers { activity?.activity }
77
152
  every { reactContext.applicationContext } returns
78
153
  ApplicationProvider.getApplicationContext<Context>()
79
154
  }
@@ -83,7 +158,6 @@ internal const val API_KEY = "test-api-key"
83
158
  internal const val BRANDED_DOMAIN = "links.example.com"
84
159
  internal const val PUSH_LINK_KEY = "as_push_link"
85
160
 
86
- /** Config as the JavaScript layer sends it: branded domains, a push path and the debug flag. */
87
161
  internal fun initializeConfig(): JavaOnlyMap = JavaOnlyMap().apply {
88
162
  putString("apiKey", API_KEY)
89
163
  putBoolean("isDebug", true)
@@ -91,7 +165,6 @@ internal fun initializeConfig(): JavaOnlyMap = JavaOnlyMap().apply {
91
165
  putArray("pushDeepLinkPaths", JavaOnlyArray.of(JavaOnlyArray.of(PUSH_LINK_KEY)))
92
166
  }
93
167
 
94
- /** A plain launcher start: no data URI and no extras. */
95
168
  internal fun launcherIntent(): Intent = Intent(Intent.ACTION_MAIN).apply {
96
169
  addCategory(Intent.CATEGORY_LAUNCHER)
97
170
  }
@@ -102,7 +175,6 @@ internal fun notificationIntent(link: String, messageId: String): Intent = launc
102
175
  putExtra("google.message_id", messageId)
103
176
  }
104
177
 
105
- /** Records what the module answered, in place of the JavaScript promise. */
106
178
  internal class RecordingPromise : Promise {
107
179
 
108
180
  var resolved = false
@@ -25,10 +25,6 @@ import org.robolectric.RobolectricTestRunner
25
25
  import org.robolectric.Shadows.shadowOf
26
26
  import org.robolectric.annotation.Config
27
27
 
28
- /**
29
- * `start` answers with what the SDK reported, so a device that opted out or a key the backend
30
- * refused is visible to JavaScript instead of only reaching the log.
31
- */
32
28
  @RunWith(RobolectricTestRunner::class)
33
29
  @Config(sdk = [35])
34
30
  class StartVerdictTest {
@@ -1,22 +1,10 @@
1
- //
2
- // AdShiftReactNativePlugin.h
3
- // AdShiftReactNativePlugin
4
- //
5
- // Turbo Module header for the AdShift React Native Plugin.
6
- //
7
1
  // Copyright © 2025 AdShift. All rights reserved.
8
- //
9
2
 
10
3
  #import <React/RCTInvalidating.h>
11
4
  #import <AdShiftReactNativePluginSpec/AdShiftReactNativePluginSpec.h>
12
5
 
13
6
  NS_ASSUME_NONNULL_BEGIN
14
7
 
15
- /// AdShift Turbo Module.
16
- ///
17
- /// Implements the Codegen-generated `NativeAdShiftReactNativePluginSpec` and
18
- /// forwards every call to the Swift helper, which talks to the AdShift iOS SDK.
19
- /// Deep link results reach JavaScript through the `onDeepLink` event.
20
8
  @interface AdShiftReactNativePlugin : NativeAdShiftReactNativePluginSpecBase <NativeAdShiftReactNativePluginSpec, RCTInvalidating>
21
9
 
22
10
  @end
@@ -1,12 +1,4 @@
1
- //
2
- // AdShiftReactNativePlugin.mm
3
- // AdShiftReactNativePlugin
4
- //
5
- // Objective-C++ implementation of the Turbo Module.
6
- // Forwards JavaScript calls to the Swift helper and emits deep link events.
7
- //
8
1
  // Copyright © 2025 AdShift. All rights reserved.
9
- //
10
2
 
11
3
  #import "AdShiftReactNativePlugin.h"
12
4
 
@@ -18,10 +10,8 @@
18
10
 
19
11
  static NSString *const kAdShiftBridgeErrorDomain = @"com.adshift.reactnativeplugin";
20
12
 
21
- /// Rejects a promise with the bridge error code carried in `error.userInfo[@"code"]`.
22
- ///
23
- /// JavaScript receives `error.code` (bridge code) and
24
- /// `error.userInfo.nativeCode` / `error.userInfo.nativeDomain` when available.
13
+ /// JavaScript reads the bridge code as `error.code` and the SDK's code and domain
14
+ /// as `error.userInfo.nativeCode` and `error.userInfo.nativeDomain`.
25
15
  static void RejectWithError(RCTPromiseRejectBlock reject, NSError *error)
26
16
  {
27
17
  NSString *code = error.userInfo[@"code"];
@@ -81,8 +71,6 @@ RCT_EXPORT_MODULE(AdShiftReactNativePlugin)
81
71
 
82
72
  #pragma mark - AdShiftDeepLinkEmitting
83
73
 
84
- /// Returns NO when JavaScript cannot receive the event, so the caller can keep the payload.
85
- /// The emitter callback is absent before the module is installed and after it is torn down.
86
74
  - (BOOL)emitDeepLink:(NSDictionary<NSString *, id> *)payload
87
75
  {
88
76
  if (_invalidated || !_eventEmitterCallback) {
@@ -259,6 +247,11 @@ RCT_EXPORT_MODULE(AdShiftReactNativePlugin)
259
247
  }];
260
248
  }
261
249
 
250
+ - (void)handlePastedDeepLink:(NSString *_Nullable)url
251
+ {
252
+ [[AdShiftReactNativePluginHelper shared] handlePastedDeepLink:url];
253
+ }
254
+
262
255
  - (void)addPushNotificationDeepLinkPath:(NSArray *)path
263
256
  {
264
257
  [[AdShiftReactNativePluginHelper shared] addPushNotificationDeepLinkPath:path];
@@ -1,27 +1,16 @@
1
- //
2
- // AdShiftReactNativePluginHelper.swift
3
- // AdShiftReactNativePlugin
4
- //
5
- // Swift bridge between the Objective-C++ Turbo Module and the AdShift iOS SDK.
6
- //
7
1
  // Copyright © 2025 AdShift. All rights reserved.
8
- //
9
2
 
10
3
  import Foundation
11
4
  import AdshiftSDK
12
5
  import os
13
6
 
14
- // MARK: - Objective-C facing types
15
-
16
- /// Implemented by the Turbo Module. Receives serialised deep link payloads on the main thread.
17
- /// Returns false when JavaScript cannot receive the payload, so it can be delivered later.
7
+ /// Called on the main thread. Returns false when JavaScript cannot receive the payload,
8
+ /// so the bridge keeps it for later.
18
9
  @objc public protocol AdShiftDeepLinkEmitting: AnyObject, Sendable {
19
10
  func emitDeepLink(_ payload: [String: Any]) -> Bool
20
11
  }
21
12
 
22
- /// Delivers the `start()` result dictionary; `start()` never fails at the bridge level.
23
13
  public typealias AdShiftStartCompletion = @Sendable ([String: Any]) -> Void
24
- /// Delivers a result dictionary or a bridge `NSError` (see `BridgeError`).
25
14
  public typealias AdShiftResultCompletion = @Sendable ([String: Any]?, NSError?) -> Void
26
15
  public typealias AdShiftVoidCompletion = @Sendable (NSError?) -> Void
27
16
  public typealias AdShiftStringCompletion = @Sendable (String?) -> Void
@@ -29,12 +18,7 @@ public typealias AdShiftBoolCompletion = @Sendable (Bool) -> Void
29
18
 
30
19
  private let log = Logger(subsystem: "com.adshift.reactnativeplugin", category: "bridge")
31
20
 
32
- // MARK: - Error model
33
-
34
- /// Platform-neutral error passed to JavaScript.
35
- ///
36
- /// Serialised as an `NSError` whose `userInfo` carries the bridge `code`
37
- /// plus the native SDK code and domain when available.
21
+ /// The Turbo Module reads `code`, `nativeCode` and `nativeDomain` from `nsError.userInfo`.
38
22
  struct BridgeError: Error {
39
23
  static let domain = "com.adshift.reactnativeplugin"
40
24
 
@@ -90,25 +74,18 @@ func mapError(_ error: Error) -> BridgeError {
90
74
  )
91
75
  }
92
76
 
93
- // MARK: - Main-actor state
94
-
95
- /// Mutable bridge state. Lives on the main actor together with the SDK.
96
77
  @MainActor
97
78
  private final class BridgeState {
98
79
  static let shared = BridgeState()
99
80
 
100
- /// The current Turbo Module instance; replaced on React Native reloads.
101
81
  weak var emitter: AdShiftDeepLinkEmitting?
102
- /// The SDK listener is registered once per process.
103
82
  var isDeepLinkListenerRegistered = false
104
83
  var pushDeepLinkPaths: Set<[String]> = []
105
- /// Deep links kept while no module could receive them, oldest first.
84
+ /// Results that arrive while no module can receive them, as during a reload,
85
+ /// wait here; they are not delivered again.
106
86
  var pendingDeepLinks: [[String: Any]] = []
107
- /// URLs that opened this process, oldest first. Kept until the process dies,
108
- /// because JavaScript reads the launch URL again after every reload.
109
87
  var launchForwardedUrls: [String] = []
110
88
 
111
- /// Deep link results are delivered once, so a reload must not consume them.
112
89
  static let pendingDeepLinkLimit = 20
113
90
  static let launchUrlMemoryLimit = 20
114
91
 
@@ -121,12 +98,7 @@ private struct BridgeValue<Value>: @unchecked Sendable {
121
98
  let value: Value
122
99
  }
123
100
 
124
- // MARK: - Helper
125
-
126
- /// Objective-C entry points for the Turbo Module.
127
- ///
128
- /// Every method returns immediately and performs the SDK call on the main
129
- /// actor; results are delivered through `@Sendable` completion blocks.
101
+ /// Every method returns at once and runs its SDK call on the main actor.
130
102
  @objc public final class AdShiftReactNativePluginHelper: NSObject, @unchecked Sendable {
131
103
 
132
104
  @objc public static let shared = AdShiftReactNativePluginHelper()
@@ -135,8 +107,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
135
107
  super.init()
136
108
  }
137
109
 
138
- // MARK: Module binding
139
-
140
110
  /// Registers the module that receives deep link events and delivers anything kept for it.
141
111
  @objc nonisolated public func setModule(_ module: AdShiftDeepLinkEmitting) {
142
112
  Task { @MainActor in
@@ -160,18 +130,17 @@ private struct BridgeValue<Value>: @unchecked Sendable {
160
130
  }
161
131
  }
162
132
 
163
- // MARK: Lifecycle
164
-
165
- /// Applies the configuration dictionary. Only keys that are present change SDK settings.
133
+ /// Keys that are absent leave the SDK's settings untouched.
166
134
  @objc nonisolated public func initialize(config: [String: Any]) {
167
135
  let boxed = BridgeValue(value: config)
168
136
  Task { @MainActor in
137
+ Adshift.shared.wrapper = "react_native"
169
138
  Self.applyConfig(boxed.value)
170
139
  Self.registerDeepLinkListenerIfNeeded()
171
140
  }
172
141
  }
173
142
 
174
- /// Starts the SDK. The result dictionary always contains `success`.
143
+ /// The result dictionary always contains `success`.
175
144
  @objc nonisolated public func start(completion: @escaping AdShiftStartCompletion) {
176
145
  Task { @MainActor in
177
146
  Adshift.shared.start { response, error in
@@ -186,8 +155,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
186
155
  }
187
156
  }
188
157
 
189
- // MARK: Configuration
190
-
191
158
  @objc nonisolated public func setCustomerUserId(_ userId: String) {
192
159
  Task { @MainActor in
193
160
  Adshift.shared.setCustomerUserId(userId)
@@ -214,18 +181,14 @@ private struct BridgeValue<Value>: @unchecked Sendable {
214
181
  }
215
182
  }
216
183
 
217
- /// Meta app id is used by the Android SDK only.
218
184
  @objc nonisolated public func setMetaAppId(_ appId: String) {
219
185
  log.debug("setMetaAppId has no effect on iOS")
220
186
  }
221
187
 
222
- /// OAID exists on Android devices only.
223
188
  @objc nonisolated public func setOaidData(_ oaid: String) {
224
189
  log.debug("setOaidData has no effect on iOS")
225
190
  }
226
191
 
227
- // MARK: Consent
228
-
229
192
  @objc nonisolated public func setConsentData(_ consent: [String: Any]) {
230
193
  let boxed = BridgeValue(value: consent)
231
194
  Task { @MainActor in
@@ -245,8 +208,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
245
208
  }
246
209
  }
247
210
 
248
- /// A call carrying no usable answer is dropped rather than defaulted; the
249
- /// reasoning sits with the rule in `BridgeRules`.
250
211
  @objc nonisolated public func setThirdPartySharing(_ sharing: [String: Any]) {
251
212
  let boxed = BridgeValue(value: sharing)
252
213
  Task { @MainActor in
@@ -272,8 +233,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
272
233
  }
273
234
  }
274
235
 
275
- // MARK: Event tracking
276
-
277
236
  @objc nonisolated public func trackEvent(
278
237
  _ eventName: String,
279
238
  values: [String: Any]?,
@@ -312,10 +271,8 @@ private struct BridgeValue<Value>: @unchecked Sendable {
312
271
  }
313
272
  }
314
273
 
315
- /// Turns the answer to a tracking call into a single outcome.
316
- ///
317
- /// An excluded device comes back as a status next to no error, and it is a
318
- /// refusal to record the event, so JavaScript is told so on both platforms.
274
+ /// An opted-out device comes back as a status, not an error; JavaScript gets
275
+ /// `OPTED_OUT`, as on Android.
319
276
  private static func trackingOutcome(_ response: [String: Any]?, _ error: Error?) -> NSError? {
320
277
  if let error {
321
278
  return mapError(error).nsError
@@ -344,21 +301,14 @@ private struct BridgeValue<Value>: @unchecked Sendable {
344
301
  }
345
302
  }
346
303
 
347
- // MARK: Identity
348
-
349
304
  @objc nonisolated public func getAdShiftDeviceId(completion: @escaping AdShiftStringCompletion) {
350
305
  Task { @MainActor in
351
306
  completion(Adshift.shared.getAdShiftDeviceId())
352
307
  }
353
308
  }
354
309
 
355
- // MARK: Deep links
356
-
357
- /// Passes a URL to the SDK. The result is delivered through the deep link listener only.
358
- ///
359
- /// `fromLaunch` marks the URL that opened the app. Those are remembered for the lifetime of
360
- /// the process, so a JavaScript reload cannot book the same link twice, while a second tap
361
- /// arrives as a live URL and is forwarded.
310
+ /// A `fromLaunch` URL is forwarded once per process, because JavaScript reads the
311
+ /// launch URL again after every reload.
362
312
  @objc nonisolated public func handleDeepLink(
363
313
  _ urlString: String,
364
314
  fromLaunch: Bool,
@@ -394,6 +344,13 @@ private struct BridgeValue<Value>: @unchecked Sendable {
394
344
  }
395
345
  }
396
346
 
347
+ /// `nil`, or a string `URL(string:)` cannot parse, tells the SDK the user skipped the paste.
348
+ @objc nonisolated public func handlePastedDeepLink(_ urlString: String?) {
349
+ Task { @MainActor in
350
+ Adshift.shared.handlePastedDeepLink(urlString.flatMap(URL.init(string:)))
351
+ }
352
+ }
353
+
397
354
  @objc nonisolated public func addPushNotificationDeepLinkPath(_ path: [String]) {
398
355
  Task { @MainActor in
399
356
  Self.registerPushDeepLinkPath(path)
@@ -410,8 +367,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
410
367
  }
411
368
  }
412
369
 
413
- // MARK: - Main-actor helpers
414
-
415
370
  @MainActor
416
371
  private static func applyConfig(_ config: [String: Any]) {
417
372
  let sdk = Adshift.shared
@@ -438,6 +393,15 @@ private struct BridgeValue<Value>: @unchecked Sendable {
438
393
  if let domains = config["brandedDomains"] as? [String] {
439
394
  sdk.brandedDomains = domains
440
395
  }
396
+ if let testMode = boolValue(config["testMode"]) {
397
+ sdk.testMode = testMode
398
+ }
399
+ switch config["deferredDeepLinkClipboard"] as? String {
400
+ case "disabled": sdk.deferredDeepLinkClipboard = .disabled
401
+ case "prompt": sdk.deferredDeepLinkClipboard = .prompt
402
+ case "pasteControl": sdk.deferredDeepLinkClipboard = .pasteControl
403
+ default: break
404
+ }
441
405
  if let paths = config["pushDeepLinkPaths"] as? [[String]] {
442
406
  for path in paths {
443
407
  registerPushDeepLinkPath(path)
@@ -474,8 +438,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
474
438
  Adshift.shared.addPushNotificationDeepLinkPath(path)
475
439
  }
476
440
 
477
- // MARK: - Pure helpers
478
-
479
441
  private static func startResult(response: [String: Any]?, error: Error?) -> [String: Any] {
480
442
  if let error {
481
443
  if case AdShiftError.alreadyStarted = error {
@@ -512,10 +474,7 @@ private struct BridgeValue<Value>: @unchecked Sendable {
512
474
  return Int(min(value, Double(Int32.max)).rounded())
513
475
  }
514
476
 
515
- /// Restricts event values to strings, numbers and booleans.
516
- ///
517
- /// Booleans arrive as `NSNumber` and are converted to `Bool`; other numbers
518
- /// stay `NSNumber`. Null, array and dictionary values are dropped.
477
+ /// Keeps strings, numbers and booleans; drops everything else.
519
478
  private static func coerceEventValues(_ values: [String: Any]) -> [String: Any] {
520
479
  var result: [String: Any] = [:]
521
480
  result.reserveCapacity(values.count)
@@ -670,7 +629,6 @@ private struct BridgeValue<Value>: @unchecked Sendable {
670
629
  }
671
630
  }
672
631
 
673
- /// Serialises a deep link response for JavaScript.
674
632
  private static func serialize(_ response: DeeplinkResponse) -> [String: Any] {
675
633
  BridgeRules.deepLinkPayload(
676
634
  deepLink: response.deeplink,
@@ -685,7 +643,11 @@ private struct BridgeValue<Value>: @unchecked Sendable {
685
643
  params: response.params,
686
644
  reportedIsDeferred: response.isDeferred,
687
645
  reportedStatus: statusName(response.status),
688
- errorMessage: response.error.map(message(for:))
646
+ errorMessage: response.error.map(message(for:)),
647
+ source: response.source?.rawValue,
648
+ isFirstSession: response.isFirstSession,
649
+ clickId: response.clickId,
650
+ matchGuaranteed: response.matchGuaranteed
689
651
  )
690
652
  }
691
653
 
@@ -705,6 +667,9 @@ private struct BridgeValue<Value>: @unchecked Sendable {
705
667
  case .invalidURL: return "Invalid URL"
706
668
  case .deepLinkNotFound: return "Deep link not found"
707
669
  case .systemError(let message): return message
670
+ case .timeout: return "Timeout"
671
+ case .network: return "Network error"
672
+ case .server: return "Server error"
708
673
  @unknown default: return "Unknown error"
709
674
  }
710
675
  }
@@ -1,17 +1,11 @@
1
1
  import Foundation
2
2
 
3
- /// Decisions the bridge makes on its own, and the shapes it hands to JavaScript.
4
- ///
5
- /// Free of SDK and React types on purpose: the call sites translate native
6
- /// values into plain ones, which keeps these rules exercisable on their own.
3
+ /// Free of SDK and React types on purpose, so `swift test` can build and run
4
+ /// these rules without either.
7
5
  enum BridgeRules {
8
- /// Builds a deep link result as JavaScript reads it.
9
- ///
10
- /// `params`, `isDeferred` and `status` are always present. A deferred result
11
- /// states the routing value and nothing about its own origin or outcome,
12
- /// while a direct one states both, so the missing halves are derived here
13
- /// and JavaScript gets one shape whatever the source was. An error outranks
14
- /// any status that came with it.
6
+ /// `params`, `isDeferred` and `status` are always present. A deferred result can
7
+ /// arrive without `isDeferred` and `status`, so both are derived here; an error
8
+ /// outranks any reported status.
15
9
  static func deepLinkPayload(
16
10
  deepLink: String?,
17
11
  deepLinkValue: String?,
@@ -19,7 +13,11 @@ enum BridgeRules {
19
13
  params: [String: String]?,
20
14
  reportedIsDeferred: Bool?,
21
15
  reportedStatus: String?,
22
- errorMessage: String?
16
+ errorMessage: String?,
17
+ source: String? = nil,
18
+ isFirstSession: Bool? = nil,
19
+ clickId: String? = nil,
20
+ matchGuaranteed: Bool? = nil
23
21
  ) -> [String: Any] {
24
22
  var result: [String: Any] = [:]
25
23
 
@@ -35,8 +33,20 @@ enum BridgeRules {
35
33
  }
36
34
  }
37
35
 
38
- result["params"] = params ?? [:]
39
- result["isDeferred"] = reportedIsDeferred ?? (reportedStatus == nil)
36
+ let isDeferred = reportedIsDeferred ?? (reportedStatus == nil)
37
+ var resolvedParams = params ?? [:]
38
+ // A deferred result has no query string, so its subs go into `params` as on
39
+ // Android, and routing code reads them the same way for every link.
40
+ if isDeferred {
41
+ for (index, sub) in subs.prefix(5).enumerated() {
42
+ let key = "deep_link_sub\(index + 1)"
43
+ if let sub, resolvedParams[key] == nil {
44
+ resolvedParams[key] = sub
45
+ }
46
+ }
47
+ }
48
+ result["params"] = resolvedParams
49
+ result["isDeferred"] = isDeferred
40
50
 
41
51
  let hasLink = deepLink != nil || deepLinkValue != nil
42
52
  result["status"] = reportedStatus ?? (hasLink ? "found" : "notFound")
@@ -46,21 +56,28 @@ enum BridgeRules {
46
56
  result["errorMessage"] = errorMessage
47
57
  }
48
58
 
59
+ if let source {
60
+ result["source"] = source
61
+ }
62
+ if let isFirstSession {
63
+ result["isFirstSession"] = isFirstSession
64
+ }
65
+ if let clickId {
66
+ result["clickId"] = clickId
67
+ }
68
+ if let matchGuaranteed {
69
+ result["matchGuaranteed"] = matchGuaranteed
70
+ }
71
+
49
72
  return result
50
73
  }
51
74
 
52
- /// Whether a tracking call was refused because this device is excluded.
53
- ///
54
- /// The refusal arrives as a status next to no error, and it means the event
55
- /// was not recorded.
56
75
  static func isExcludedFromTracking(responseStatus: String?) -> Bool {
57
76
  responseStatus == "opted_out"
58
77
  }
59
78
 
60
- /// Whether consent lets the SDK use the advertising identifier.
61
- ///
62
- /// Storage and data usage both have to be allowed, and only an explicit
63
- /// denial refuses them.
79
+ /// An explicit `false` for either withholds the identifiers; `nil` (not decided)
80
+ /// does not.
64
81
  static func adIdentifiersAllowed(
65
82
  adStorageEnabled: Bool?,
66
83
  adUserDataEnabled: Bool?
@@ -68,14 +85,9 @@ enum BridgeRules {
68
85
  adStorageEnabled != false && adUserDataEnabled != false
69
86
  }
70
87
 
71
- /// What the app said about passing this user's data on, or `nil` when the
72
- /// call carried no usable answer and nothing should be forwarded.
73
- ///
74
- /// This axis reads an absent answer as the opposite of how consent reads one:
75
- /// nothing said here means sharing is allowed. So a malformed call cannot be
76
- /// defaulted in either direction — `false` would record a declaration the app
77
- /// never made, `true` would withhold data the user never asked to withhold,
78
- /// and neither can be recalled for events already sent.
88
+ /// `nil` when the call carries no usable `optOut`; then nothing is forwarded.
89
+ /// No default is safe: `false` records a declaration the app never made, and
90
+ /// `true` withholds data the user never asked to withhold.
79
91
  static func thirdPartySharingOptOut(from dictionary: [String: Any]) -> Bool? {
80
92
  (dictionary["optOut"] as? NSNumber)?.boolValue
81
93
  }