@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.
- package/AdShiftReactNativePlugin.podspec +20 -4
- package/CHANGELOG.md +57 -8
- package/README.md +131 -74
- package/android/build.gradle +3 -2
- package/android/consumer-rules.pro +2 -21
- package/android/src/main/AndroidManifest.xml +14 -1
- package/android/src/main/java/com/adshift/reactnativeplugin/ActivityIntents.kt +307 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +90 -153
- package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +0 -20
- package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +40 -7
- package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +51 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +0 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +21 -11
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchLinkRecordTest.kt +420 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +97 -25
- package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +0 -4
- package/ios/AdShiftReactNativePlugin.h +0 -12
- package/ios/AdShiftReactNativePlugin.mm +7 -14
- package/ios/AdShiftReactNativePluginHelper.swift +38 -73
- package/ios/Core/BridgeRules.swift +42 -30
- package/lib/commonjs/Adshift.js +100 -284
- package/lib/commonjs/Adshift.js.map +1 -1
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js +2 -11
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest/index.js +6 -18
- package/lib/commonjs/jest/index.js.map +1 -1
- package/lib/commonjs/nativeSdkVersions.js +4 -6
- package/lib/commonjs/nativeSdkVersions.js.map +1 -1
- package/lib/commonjs/types/AdshiftAdRevenue.js +0 -24
- package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -1
- package/lib/commonjs/types/AdshiftConfig.js +11 -23
- package/lib/commonjs/types/AdshiftConfig.js.map +1 -1
- package/lib/commonjs/types/AdshiftConsent.js +9 -45
- package/lib/commonjs/types/AdshiftConsent.js.map +1 -1
- package/lib/commonjs/types/AdshiftConsentSnapshot.js +5 -24
- package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -1
- package/lib/commonjs/types/AdshiftDeepLink.js +50 -33
- package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -1
- package/lib/commonjs/types/AdshiftError.js +7 -27
- package/lib/commonjs/types/AdshiftError.js.map +1 -1
- package/lib/commonjs/types/AdshiftEventParam.js +4 -38
- package/lib/commonjs/types/AdshiftEventParam.js.map +1 -1
- package/lib/commonjs/types/AdshiftEventType.js +1 -39
- package/lib/commonjs/types/AdshiftEventType.js.map +1 -1
- package/lib/commonjs/types/AdshiftThirdPartySharing.js +7 -38
- package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -1
- package/lib/commonjs/types/index.js +12 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/Adshift.js +101 -285
- package/lib/module/Adshift.js.map +1 -1
- package/lib/module/NativeAdShiftReactNativePlugin.js +2 -12
- package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
- package/lib/module/index.js +2 -47
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +7 -19
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/nativeSdkVersions.js +4 -6
- package/lib/module/nativeSdkVersions.js.map +1 -1
- package/lib/module/types/AdshiftAdRevenue.js +0 -24
- package/lib/module/types/AdshiftAdRevenue.js.map +1 -1
- package/lib/module/types/AdshiftConfig.js +10 -23
- package/lib/module/types/AdshiftConfig.js.map +1 -1
- package/lib/module/types/AdshiftConsent.js +9 -45
- package/lib/module/types/AdshiftConsent.js.map +1 -1
- package/lib/module/types/AdshiftConsentSnapshot.js +5 -24
- package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -1
- package/lib/module/types/AdshiftDeepLink.js +49 -32
- package/lib/module/types/AdshiftDeepLink.js.map +1 -1
- package/lib/module/types/AdshiftError.js +7 -28
- package/lib/module/types/AdshiftError.js.map +1 -1
- package/lib/module/types/AdshiftEventParam.js +4 -38
- package/lib/module/types/AdshiftEventParam.js.map +1 -1
- package/lib/module/types/AdshiftEventType.js +1 -39
- package/lib/module/types/AdshiftEventType.js.map +1 -1
- package/lib/module/types/AdshiftThirdPartySharing.js +7 -38
- package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -1
- package/lib/module/types/index.js +2 -2
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/commonjs/src/Adshift.d.ts +68 -184
- package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +2 -34
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/jest/index.d.ts +9 -21
- package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +4 -6
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +0 -24
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +35 -39
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +9 -49
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +10 -28
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +55 -39
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +7 -26
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +3 -19
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts +1 -23
- package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +7 -38
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/version.d.ts +1 -1
- package/lib/typescript/module/src/Adshift.d.ts +68 -184
- package/lib/typescript/module/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +2 -34
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/jest/index.d.ts +9 -21
- package/lib/typescript/module/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeSdkVersions.d.ts +4 -6
- package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +0 -24
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts +35 -39
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts +9 -49
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +10 -28
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +55 -39
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftError.d.ts +7 -26
- package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +3 -19
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts +1 -23
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +7 -38
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
- package/lib/typescript/module/src/types/index.d.ts +3 -3
- package/lib/typescript/module/src/types/index.d.ts.map +1 -1
- package/lib/typescript/module/src/version.d.ts +1 -1
- package/package.json +11 -1
- package/src/Adshift.ts +118 -285
- package/src/NativeAdShiftReactNativePlugin.ts +19 -47
- package/src/index.tsx +7 -46
- package/src/jest/index.ts +11 -20
- package/src/nativeSdkVersions.ts +4 -6
- package/src/types/AdshiftAdRevenue.ts +0 -24
- package/src/types/AdshiftConfig.ts +48 -55
- package/src/types/AdshiftConsent.ts +9 -49
- package/src/types/AdshiftConsentSnapshot.ts +11 -38
- package/src/types/AdshiftDeepLink.ts +87 -39
- package/src/types/AdshiftError.ts +7 -26
- package/src/types/AdshiftEventParam.ts +4 -38
- package/src/types/AdshiftEventType.ts +1 -39
- package/src/types/AdshiftThirdPartySharing.ts +7 -38
- package/src/types/index.ts +9 -2
- package/src/version.ts +1 -1
- package/vendor/ios/AdshiftSDK.files.json +30 -0
- package/vendor/ios/AdshiftSDK.xcframework/Info.plist +44 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/AdshiftSDK +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +315 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Info.plist +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/module.modulemap +4 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/PrivacyInfo.xcprivacy +132 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/AdshiftSDK +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +626 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Info.plist +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/module.modulemap +4 -0
- 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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
///
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
///
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
///
|
|
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
|
-
///
|
|
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
|
-
|
|
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
|
-
///
|
|
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
|
-
///
|
|
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
|
-
///
|
|
9
|
-
///
|
|
10
|
-
///
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
///
|
|
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
|
-
///
|
|
72
|
-
///
|
|
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
|
}
|