cm-sdk-react-native-v3 3.2.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/LICENSE +20 -0
- package/README.md +10 -0
- package/android/build.gradle +100 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/cmsdkreactnativev3/CmSdkReactNativeV3Module.kt +561 -0
- package/android/src/main/java/com/cmsdkreactnativev3/CmSdkReactNativeV3Package.kt +17 -0
- package/ios/CmSdkReactNativeV3-Bridging-Header.h +2 -0
- package/ios/CmSdkReactNativeV3.mm +120 -0
- package/ios/CmSdkReactNativeV3.swift +302 -0
- package/lib/commonjs/index.js +61 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +57 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +34 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +34 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +179 -0
- package/react-native-cm-sdk-react-native-v3.podspec +42 -0
- package/src/index.tsx +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Fabio Torre
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# ``consentmanager CMP SDK v3.2.0``
|
|
2
|
+
|
|
3
|
+
# cm-sdk-react-native-v3
|
|
4
|
+
|
|
5
|
+
cm-sdk-react-native-v3 is a comprehensive Consent Management Platform (CMP) SDK bridge for React Native developed applications. It provides easy-to-use APIs for handling user consent in compliance with various privacy regulations.
|
|
6
|
+
|
|
7
|
+
For further information, please refer to [our documentation](https://help.consentmanager.net/books/cmp/page/integrating-the-sdk-v3-into-your-mobile-app)
|
|
8
|
+
## License
|
|
9
|
+
|
|
10
|
+
CMPManager is available under the MIT license. See the LICENSE file for more info.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CmSdkReactNativeV3_kotlinVersion"]
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def reactNativeArchitectures() {
|
|
18
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
19
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def isNewArchitectureEnabled() {
|
|
23
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
apply plugin: "com.android.library"
|
|
27
|
+
apply plugin: "kotlin-android"
|
|
28
|
+
|
|
29
|
+
if (isNewArchitectureEnabled()) {
|
|
30
|
+
apply plugin: "com.facebook.react"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def getExtOrDefault(name) {
|
|
34
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CmSdkReactNativeV3_" + name]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def getExtOrIntegerDefault(name) {
|
|
38
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CmSdkReactNativeV3_" + name]).toInteger()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
def supportsNamespace() {
|
|
42
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
43
|
+
def major = parsed[0].toInteger()
|
|
44
|
+
def minor = parsed[1].toInteger()
|
|
45
|
+
|
|
46
|
+
// Namespace support was added in 7.3.0
|
|
47
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
android {
|
|
51
|
+
if (supportsNamespace()) {
|
|
52
|
+
namespace "com.cmsdkreactnativev3"
|
|
53
|
+
|
|
54
|
+
sourceSets {
|
|
55
|
+
main {
|
|
56
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
compileSdkVersion 34
|
|
62
|
+
|
|
63
|
+
defaultConfig {
|
|
64
|
+
minSdkVersion 23
|
|
65
|
+
targetSdkVersion 34
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
buildTypes {
|
|
70
|
+
release {
|
|
71
|
+
minifyEnabled false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lintOptions {
|
|
76
|
+
disable "GradleCompatible"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
compileOptions {
|
|
80
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
81
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
repositories {
|
|
86
|
+
mavenCentral()
|
|
87
|
+
mavenLocal()
|
|
88
|
+
google()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
92
|
+
|
|
93
|
+
dependencies {
|
|
94
|
+
// For < 0.71, this will be from the local maven repo
|
|
95
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
96
|
+
//noinspection GradleDynamicVersion
|
|
97
|
+
implementation "com.facebook.react:react-native:+"
|
|
98
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
99
|
+
implementation "net.consentmanager.sdkv3:cmsdkv3:3.2.0"
|
|
100
|
+
}
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
package com.cmsdkreactnativev3
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod
|
|
12
|
+
import com.facebook.react.bridge.ReadableArray
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap
|
|
14
|
+
import com.facebook.react.bridge.ReadableType
|
|
15
|
+
import com.facebook.react.bridge.WritableArray
|
|
16
|
+
import com.facebook.react.bridge.WritableMap
|
|
17
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
18
|
+
import kotlinx.coroutines.CoroutineScope
|
|
19
|
+
import kotlinx.coroutines.Dispatchers
|
|
20
|
+
import kotlinx.coroutines.launch
|
|
21
|
+
import net.consentmanager.cm_sdk_android_v3.CMPManager
|
|
22
|
+
import net.consentmanager.cm_sdk_android_v3.CMPManagerDelegate
|
|
23
|
+
import net.consentmanager.cm_sdk_android_v3.ConsentLayerUIConfig
|
|
24
|
+
import net.consentmanager.cm_sdk_android_v3.ConsentStatus
|
|
25
|
+
import net.consentmanager.cm_sdk_android_v3.UrlConfig
|
|
26
|
+
import net.consentmanager.cm_sdk_android_v3.UserConsentStatus
|
|
27
|
+
|
|
28
|
+
class CmSdkReactNativeV3Module(reactContext: ReactApplicationContext) :
|
|
29
|
+
ReactContextBaseJavaModule(reactContext), LifecycleEventListener, CMPManagerDelegate {
|
|
30
|
+
|
|
31
|
+
private lateinit var cmpManager: CMPManager
|
|
32
|
+
private val scope = CoroutineScope(Dispatchers.Main)
|
|
33
|
+
private var urlConfig: UrlConfig
|
|
34
|
+
private var webViewConfig: ConsentLayerUIConfig
|
|
35
|
+
private val uiThreadHandler = Handler(Looper.getMainLooper())
|
|
36
|
+
|
|
37
|
+
init {
|
|
38
|
+
reactContext.addLifecycleEventListener(this)
|
|
39
|
+
urlConfig = UrlConfig("", "", "", "")
|
|
40
|
+
webViewConfig = ConsentLayerUIConfig(
|
|
41
|
+
position = ConsentLayerUIConfig.Position.FULL_SCREEN,
|
|
42
|
+
cornerRadius = 0f,
|
|
43
|
+
respectsSafeArea = true,
|
|
44
|
+
allowsOrientationChanges = true
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun getName(): String = NAME
|
|
49
|
+
|
|
50
|
+
private fun runOnUiThread(runnable: Runnable) {
|
|
51
|
+
uiThreadHandler.post(runnable)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ReactMethod
|
|
55
|
+
fun setWebViewConfig(config: ReadableMap, promise: Promise) {
|
|
56
|
+
runOnUiThread {
|
|
57
|
+
try {
|
|
58
|
+
val position = when (config.getString("position")) {
|
|
59
|
+
"fullScreen" -> ConsentLayerUIConfig.Position.FULL_SCREEN
|
|
60
|
+
"halfScreenBottom" -> ConsentLayerUIConfig.Position.HALF_SCREEN_BOTTOM
|
|
61
|
+
"halfScreenTop" -> ConsentLayerUIConfig.Position.HALF_SCREEN_TOP
|
|
62
|
+
else -> ConsentLayerUIConfig.Position.FULL_SCREEN
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.webViewConfig = ConsentLayerUIConfig(
|
|
66
|
+
position = position,
|
|
67
|
+
cornerRadius = (config.getDouble("cornerRadius") ?: 0.0).toFloat(),
|
|
68
|
+
respectsSafeArea = config.getBoolean("respectsSafeArea"),
|
|
69
|
+
allowsOrientationChanges = config.getBoolean("allowsOrientationChanges")
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
// Store this config to use when initializing CMPManager
|
|
73
|
+
promise.resolve(null)
|
|
74
|
+
} catch (e: Exception) {
|
|
75
|
+
promise.reject("ERROR", "Failed to set WebView config: ${e.message}")
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ReactMethod
|
|
81
|
+
fun setUrlConfig(config: ReadableMap, promise: Promise) {
|
|
82
|
+
runOnUiThread {
|
|
83
|
+
try {
|
|
84
|
+
val id = config.getString("id") ?: throw IllegalArgumentException("Missing 'id'")
|
|
85
|
+
val domain = config.getString("domain") ?: throw IllegalArgumentException("Missing 'domain'")
|
|
86
|
+
val language = config.getString("language") ?: throw IllegalArgumentException("Missing 'language'")
|
|
87
|
+
val appName = config.getString("appName") ?: throw IllegalArgumentException("Missing 'appName'")
|
|
88
|
+
|
|
89
|
+
this.urlConfig = UrlConfig(id, domain, language, appName)
|
|
90
|
+
|
|
91
|
+
initializeCMPManager()
|
|
92
|
+
|
|
93
|
+
promise.resolve(null)
|
|
94
|
+
} catch (e: Exception) {
|
|
95
|
+
promise.reject("ERROR", "Failed to set URL config: ${e.message}")
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private fun initializeCMPManager() {
|
|
101
|
+
val activity = currentActivity ?: throw IllegalStateException("Current activity is null")
|
|
102
|
+
cmpManager = CMPManager.getInstance(
|
|
103
|
+
activity,
|
|
104
|
+
urlConfig,
|
|
105
|
+
webViewConfig,
|
|
106
|
+
this
|
|
107
|
+
)
|
|
108
|
+
cmpManager.setActivity(activity)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// MARK: - New methods
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Gets the comprehensive user consent status
|
|
115
|
+
*/
|
|
116
|
+
@ReactMethod
|
|
117
|
+
fun getUserStatus(promise: Promise) {
|
|
118
|
+
try {
|
|
119
|
+
val userStatus = cmpManager.getUserStatus()
|
|
120
|
+
val result = Arguments.createMap().apply {
|
|
121
|
+
putString("hasUserChoice", userStatus.hasUserChoice.toString())
|
|
122
|
+
putString("tcf", userStatus.tcf)
|
|
123
|
+
putString("addtlConsent", userStatus.addtlConsent)
|
|
124
|
+
putString("regulation", userStatus.regulation)
|
|
125
|
+
|
|
126
|
+
// Convert vendors map
|
|
127
|
+
val vendorsMap = Arguments.createMap()
|
|
128
|
+
userStatus.vendors.forEach { (vendorId, status) ->
|
|
129
|
+
vendorsMap.putString(vendorId, status.toString())
|
|
130
|
+
}
|
|
131
|
+
putMap("vendors", vendorsMap)
|
|
132
|
+
|
|
133
|
+
// Convert purposes map
|
|
134
|
+
val purposesMap = Arguments.createMap()
|
|
135
|
+
userStatus.purposes.forEach { (purposeId, status) ->
|
|
136
|
+
purposesMap.putString(purposeId, status.toString())
|
|
137
|
+
}
|
|
138
|
+
putMap("purposes", purposesMap)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
promise.resolve(result)
|
|
142
|
+
} catch (e: Exception) {
|
|
143
|
+
promise.reject("ERROR", "Failed to get user status: ${e.message}", e)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Gets the consent status for a specific purpose
|
|
149
|
+
*/
|
|
150
|
+
@ReactMethod
|
|
151
|
+
fun getStatusForPurpose(purposeId: String, promise: Promise) {
|
|
152
|
+
try {
|
|
153
|
+
val status = cmpManager.getStatusForPurpose(purposeId)
|
|
154
|
+
promise.resolve(status.toString())
|
|
155
|
+
} catch (e: Exception) {
|
|
156
|
+
promise.reject("ERROR", "Failed to get status for purpose: ${e.message}", e)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Gets the consent status for a specific vendor
|
|
162
|
+
*/
|
|
163
|
+
@ReactMethod
|
|
164
|
+
fun getStatusForVendor(vendorId: String, promise: Promise) {
|
|
165
|
+
try {
|
|
166
|
+
val status = cmpManager.getStatusForVendor(vendorId)
|
|
167
|
+
promise.resolve(status.toString())
|
|
168
|
+
} catch (e: Exception) {
|
|
169
|
+
promise.reject("ERROR", "Failed to get status for vendor: ${e.message}", e)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Gets Google Consent Mode v2 compatible settings
|
|
175
|
+
*/
|
|
176
|
+
@ReactMethod
|
|
177
|
+
fun getGoogleConsentModeStatus(promise: Promise) {
|
|
178
|
+
try {
|
|
179
|
+
val consentModeStatus = cmpManager.getGoogleConsentModeStatus()
|
|
180
|
+
val result = Arguments.createMap()
|
|
181
|
+
|
|
182
|
+
consentModeStatus.forEach { (key, value) ->
|
|
183
|
+
result.putString(key, value)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
promise.resolve(result)
|
|
187
|
+
} catch (e: Exception) {
|
|
188
|
+
promise.reject("ERROR", "Failed to get Google Consent Mode status: ${e.message}", e)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Replacement for openConsentLayer - force opens the consent UI
|
|
194
|
+
*/
|
|
195
|
+
@ReactMethod
|
|
196
|
+
fun forceOpen(jumpToSettings: Boolean, promise: Promise) {
|
|
197
|
+
scope.launch {
|
|
198
|
+
try {
|
|
199
|
+
cmpManager.forceOpen(jumpToSettings) { result ->
|
|
200
|
+
if (result.isSuccess) {
|
|
201
|
+
promise.resolve(true)
|
|
202
|
+
} else {
|
|
203
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} catch (e: Exception) {
|
|
207
|
+
promise.reject("ERROR", "Failed to force open consent layer: ${e.message}", e)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Replacement for checkWithServerAndOpenIfNecessary - checks with server and opens if needed
|
|
214
|
+
*/
|
|
215
|
+
@ReactMethod
|
|
216
|
+
fun checkAndOpen(jumpToSettings: Boolean, promise: Promise) {
|
|
217
|
+
scope.launch {
|
|
218
|
+
try {
|
|
219
|
+
cmpManager.checkAndOpen(jumpToSettings) { result ->
|
|
220
|
+
if (result.isSuccess) {
|
|
221
|
+
promise.resolve(true)
|
|
222
|
+
} else {
|
|
223
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} catch (e: Exception) {
|
|
227
|
+
promise.reject("ERROR", "Failed to check and open consent: ${e.message}", e)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Import a CMP information string
|
|
234
|
+
*/
|
|
235
|
+
@ReactMethod
|
|
236
|
+
fun importCMPInfo(cmpString: String, promise: Promise) {
|
|
237
|
+
scope.launch {
|
|
238
|
+
try {
|
|
239
|
+
cmpManager.importCMPInfo(cmpString) { result ->
|
|
240
|
+
if (result.isSuccess) {
|
|
241
|
+
promise.resolve(true)
|
|
242
|
+
} else {
|
|
243
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
} catch (e: Exception) {
|
|
247
|
+
promise.reject("ERROR", "Failed to import CMP info: ${e.message}", e)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Reset all consent management data
|
|
254
|
+
*/
|
|
255
|
+
@ReactMethod
|
|
256
|
+
fun resetConsentManagementData(promise: Promise) {
|
|
257
|
+
try {
|
|
258
|
+
cmpManager.resetConsentManagementData()
|
|
259
|
+
promise.resolve(true)
|
|
260
|
+
} catch (e: Exception) {
|
|
261
|
+
promise.reject("ERROR", "Failed to reset consent management data: ${e.message}", e)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// MARK: - Deprecated methods (kept for backward compatibility)
|
|
266
|
+
|
|
267
|
+
@ReactMethod
|
|
268
|
+
fun checkWithServerAndOpenIfNecessary(promise: Promise) {
|
|
269
|
+
scope.launch {
|
|
270
|
+
try {
|
|
271
|
+
// Call the new method instead, but keep the API signature the same
|
|
272
|
+
cmpManager.checkAndOpen(false) { result ->
|
|
273
|
+
if (result.isSuccess) {
|
|
274
|
+
promise.resolve(true)
|
|
275
|
+
} else {
|
|
276
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
} catch (e: Exception) {
|
|
280
|
+
promise.reject("ERROR", "Failed to check with server: ${e.message}", e)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@ReactMethod
|
|
286
|
+
fun openConsentLayer(promise: Promise) {
|
|
287
|
+
scope.launch {
|
|
288
|
+
try {
|
|
289
|
+
// Call the new method instead, but keep the API signature the same
|
|
290
|
+
cmpManager.forceOpen(false) { result ->
|
|
291
|
+
if (result.isSuccess) {
|
|
292
|
+
promise.resolve(true)
|
|
293
|
+
} else {
|
|
294
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} catch (e: Exception) {
|
|
298
|
+
promise.reject("ERROR", "Failed to open consent layer: ${e.message}", e)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
@ReactMethod
|
|
304
|
+
fun jumpToSettings(promise: Promise) {
|
|
305
|
+
scope.launch {
|
|
306
|
+
try {
|
|
307
|
+
cmpManager.forceOpen(true) { result ->
|
|
308
|
+
if (result.isSuccess) {
|
|
309
|
+
promise.resolve(true)
|
|
310
|
+
} else {
|
|
311
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} catch (e: Exception) {
|
|
315
|
+
promise.reject("ERROR", "Failed to jump to settings: ${e.message}", e)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@ReactMethod
|
|
321
|
+
fun checkIfConsentIsRequired(promise: Promise) {
|
|
322
|
+
scope.launch {
|
|
323
|
+
try {
|
|
324
|
+
cmpManager.checkIfConsentIsRequired { isRequired ->
|
|
325
|
+
promise.resolve(isRequired)
|
|
326
|
+
}
|
|
327
|
+
} catch (e: Exception) {
|
|
328
|
+
promise.reject("ERROR", "Failed to check if consent is required: ${e.message}", e)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
@ReactMethod
|
|
334
|
+
fun hasUserChoice(promise: Promise) {
|
|
335
|
+
promise.resolve(cmpManager.hasUserChoice())
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@ReactMethod
|
|
339
|
+
fun hasPurposeConsent(purposeId: String, promise: Promise) {
|
|
340
|
+
promise.resolve(cmpManager.hasPurposeConsent(purposeId))
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
@ReactMethod
|
|
344
|
+
fun hasVendorConsent(vendorId: String, promise: Promise) {
|
|
345
|
+
promise.resolve(cmpManager.hasVendorConsent(vendorId))
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@ReactMethod
|
|
349
|
+
fun exportCMPInfo(promise: Promise) {
|
|
350
|
+
promise.resolve(cmpManager.exportCMPInfo())
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
@ReactMethod
|
|
354
|
+
fun getAllPurposesIDs(promise: Promise) {
|
|
355
|
+
promise.resolve(cmpManager.getAllPurposesIDs().toWritableArray())
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@ReactMethod
|
|
359
|
+
fun getEnabledPurposesIDs(promise: Promise) {
|
|
360
|
+
promise.resolve(cmpManager.getEnabledPurposesIDs().toWritableArray())
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
@ReactMethod
|
|
364
|
+
fun getDisabledPurposesIDs(promise: Promise) {
|
|
365
|
+
promise.resolve(cmpManager.getDisabledPurposesIDs().toWritableArray())
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@ReactMethod
|
|
369
|
+
fun getAllVendorsIDs(promise: Promise) {
|
|
370
|
+
promise.resolve(cmpManager.getAllVendorsIDs().toWritableArray())
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
@ReactMethod
|
|
374
|
+
fun getEnabledVendorsIDs(promise: Promise) {
|
|
375
|
+
promise.resolve(cmpManager.getEnabledVendorsIDs().toWritableArray())
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@ReactMethod
|
|
379
|
+
fun getDisabledVendorsIDs(promise: Promise) {
|
|
380
|
+
promise.resolve(cmpManager.getDisabledVendorsIDs().toWritableArray())
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@ReactMethod
|
|
384
|
+
fun acceptVendors(vendors: ReadableArray, promise: Promise) {
|
|
385
|
+
scope.launch {
|
|
386
|
+
try {
|
|
387
|
+
Log.d("CmSdkReactNativeV3", "Accepting vendors: $vendors")
|
|
388
|
+
|
|
389
|
+
cmpManager.acceptVendors(vendors.toListOfStrings()) { result ->
|
|
390
|
+
if (result.isSuccess) {
|
|
391
|
+
promise.resolve(null)
|
|
392
|
+
} else {
|
|
393
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} catch (e: Exception) {
|
|
397
|
+
promise.reject("ERROR", "Failed to accept vendors: ${e.message}", e)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
@ReactMethod
|
|
403
|
+
fun rejectVendors(vendors: ReadableArray, promise: Promise) {
|
|
404
|
+
scope.launch {
|
|
405
|
+
try {
|
|
406
|
+
Log.d("CmSdkReactNativeV3", "Rejecting vendors: $vendors")
|
|
407
|
+
cmpManager.rejectVendors(vendors.toListOfStrings()) { result ->
|
|
408
|
+
if (result.isSuccess) {
|
|
409
|
+
promise.resolve(null)
|
|
410
|
+
} else {
|
|
411
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
} catch (e: Exception) {
|
|
415
|
+
promise.reject("ERROR", "Failed to reject vendors: ${e.message}", e)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
@ReactMethod
|
|
421
|
+
fun acceptPurposes(purposes: ReadableArray, updatePurpose: Boolean, promise: Promise) {
|
|
422
|
+
scope.launch {
|
|
423
|
+
try {
|
|
424
|
+
Log.d("Cmsdkreactnativev3", "Rejecting purposes: $purposes")
|
|
425
|
+
|
|
426
|
+
cmpManager.acceptPurposes(purposes.toListOfStrings(), updatePurpose) { result ->
|
|
427
|
+
if (result.isSuccess) {
|
|
428
|
+
promise.resolve(null)
|
|
429
|
+
} else {
|
|
430
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
} catch (e: Exception) {
|
|
434
|
+
promise.reject("ERROR", "Failed to accept purposes: ${e.message}", e)
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
@ReactMethod
|
|
440
|
+
fun rejectPurposes(purposes: ReadableArray, updateVendor: Boolean, promise: Promise) {
|
|
441
|
+
scope.launch {
|
|
442
|
+
try {
|
|
443
|
+
Log.d("Cmsdkreactnativev3", "Rejecting purposes: $purposes")
|
|
444
|
+
cmpManager.rejectPurposes(purposes.toListOfStrings(), updateVendor) { result ->
|
|
445
|
+
if (result.isSuccess) {
|
|
446
|
+
promise.resolve(null)
|
|
447
|
+
} else {
|
|
448
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
} catch (e: Exception) {
|
|
452
|
+
promise.reject("ERROR", "Failed to reject purposes: ${e.message}", e)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
@ReactMethod
|
|
458
|
+
fun rejectAll(promise: Promise) {
|
|
459
|
+
scope.launch {
|
|
460
|
+
try {
|
|
461
|
+
cmpManager.rejectAll { result ->
|
|
462
|
+
if (result.isSuccess) {
|
|
463
|
+
promise.resolve(null)
|
|
464
|
+
} else {
|
|
465
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
} catch (e: Exception) {
|
|
469
|
+
promise.reject("ERROR", "Failed to reject all: ${e.message}", e)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
@ReactMethod
|
|
475
|
+
fun acceptAll(promise: Promise) {
|
|
476
|
+
scope.launch {
|
|
477
|
+
try {
|
|
478
|
+
cmpManager.acceptAll { result ->
|
|
479
|
+
if (result.isSuccess) {
|
|
480
|
+
promise.resolve(null)
|
|
481
|
+
} else {
|
|
482
|
+
promise.reject("ERROR", result.exceptionOrNull()?.message ?: "Unknown error")
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
} catch (e: Exception) {
|
|
486
|
+
promise.reject("ERROR", "Failed to accept all: ${e.message}", e)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
private fun ReadableArray.toListOfStrings(): List<String> {
|
|
491
|
+
val list = mutableListOf<String>()
|
|
492
|
+
for (i in 0 until this.size()) {
|
|
493
|
+
when (this.getType(i)) {
|
|
494
|
+
ReadableType.String -> list.add(this.getString(i) ?: "")
|
|
495
|
+
ReadableType.Number -> list.add(this.getDouble(i).toString())
|
|
496
|
+
ReadableType.Boolean -> list.add(this.getBoolean(i).toString())
|
|
497
|
+
else -> throw IllegalArgumentException("Unsupported type in ReadableArray at index $i")
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return list
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// LifecycleEventListener methods
|
|
504
|
+
override fun onHostResume() {
|
|
505
|
+
if (::cmpManager.isInitialized) {
|
|
506
|
+
cmpManager.onApplicationResume()
|
|
507
|
+
currentActivity?.let { cmpManager.setActivity(it) }
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
override fun onHostPause() {
|
|
512
|
+
if (::cmpManager.isInitialized) {
|
|
513
|
+
cmpManager.onApplicationPause()
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
override fun onHostDestroy() {
|
|
518
|
+
if (::cmpManager.isInitialized) {
|
|
519
|
+
cmpManager.onActivityDestroyed()
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private fun sendEvent(eventName: String, params: WritableMap?) {
|
|
524
|
+
reactApplicationContext
|
|
525
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
526
|
+
.emit(eventName, params)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private fun List<String>.toWritableArray(): WritableArray {
|
|
530
|
+
return Arguments.createArray().apply {
|
|
531
|
+
this@toWritableArray.forEach { pushString(it) }
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
companion object {
|
|
536
|
+
const val NAME = "CmSdkReactNativeV3"
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
override fun didReceiveConsent(consent: String, jsonObject: Map<String, Any>) {
|
|
540
|
+
val params = Arguments.createMap().apply {
|
|
541
|
+
putString("consent", consent)
|
|
542
|
+
putString("jsonObject", jsonObject.toString())
|
|
543
|
+
}
|
|
544
|
+
sendEvent("didReceiveConsent", params)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
override fun didShowConsentLayer() {
|
|
548
|
+
sendEvent("didShowConsentLayer", null)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
override fun didCloseConsentLayer() {
|
|
552
|
+
sendEvent("didCloseConsentLayer", null)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
override fun didReceiveError(error: String) {
|
|
556
|
+
val params = Arguments.createMap().apply {
|
|
557
|
+
putString("error", error)
|
|
558
|
+
}
|
|
559
|
+
sendEvent("didReceiveError", params)
|
|
560
|
+
}
|
|
561
|
+
}
|