@didomi/react-native 2.9.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/didomi/reactnative/DidomiModule.kt +117 -13
- package/ios/Didomi.m +14 -0
- package/ios/Extensions/StringExtension.swift +24 -0
- package/ios/RNDidomi.swift +140 -16
- package/lib/commonjs/Constants.js +1 -1
- package/lib/commonjs/Constants.js.map +1 -1
- package/lib/commonjs/Didomi.js +31 -4
- package/lib/commonjs/Didomi.js.map +1 -1
- package/lib/commonjs/DidomiTypes.js +12 -0
- package/lib/commonjs/DidomiTypes.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Constants.js +1 -1
- package/lib/module/Constants.js.map +1 -1
- package/lib/module/Didomi.js +31 -4
- package/lib/module/Didomi.js.map +1 -1
- package/lib/module/DidomiTypes.js +15 -0
- package/lib/module/DidomiTypes.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Constants.d.ts +1 -1
- package/lib/typescript/Constants.d.ts.map +1 -1
- package/lib/typescript/Didomi.d.ts +26 -5
- package/lib/typescript/Didomi.d.ts.map +1 -1
- package/lib/typescript/DidomiTypes.d.ts +117 -1
- package/lib/typescript/DidomiTypes.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-didomi.podspec +1 -1
- package/src/Constants.ts +1 -1
- package/src/Didomi.ts +39 -5
- package/src/DidomiTypes.ts +121 -1
- package/src/index.tsx +2 -1
package/android/build.gradle
CHANGED
|
@@ -11,10 +11,13 @@ import com.google.gson.Gson
|
|
|
11
11
|
import com.google.gson.reflect.TypeToken
|
|
12
12
|
import io.didomi.sdk.Didomi
|
|
13
13
|
import io.didomi.sdk.DidomiInitializeParameters
|
|
14
|
+
import io.didomi.sdk.DidomiMultiUserParameters
|
|
15
|
+
import io.didomi.sdk.DidomiUserParameters
|
|
14
16
|
import io.didomi.sdk.events.*
|
|
15
17
|
import io.didomi.sdk.exceptions.DidomiNotReadyException
|
|
16
18
|
import io.didomi.sdk.models.CurrentUserStatus
|
|
17
19
|
import io.didomi.sdk.user.model.UserAuthParams
|
|
20
|
+
import io.didomi.sdk.user.model.UserAuth
|
|
18
21
|
import io.didomi.sdk.user.model.UserAuthWithEncryptionParams
|
|
19
22
|
import io.didomi.sdk.user.model.UserAuthWithHashParams
|
|
20
23
|
import org.json.JSONArray
|
|
@@ -265,7 +268,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
265
268
|
val set = mutableSetOf<String>()
|
|
266
269
|
|
|
267
270
|
for (i in 0 until size()) {
|
|
268
|
-
set.add(
|
|
271
|
+
getString(i)?.also { set.add(it) }
|
|
269
272
|
}
|
|
270
273
|
|
|
271
274
|
return set
|
|
@@ -351,7 +354,8 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
351
354
|
androidTvNoticeId,
|
|
352
355
|
androidTvEnabled,
|
|
353
356
|
countryCode,
|
|
354
|
-
regionCode
|
|
357
|
+
regionCode,
|
|
358
|
+
false
|
|
355
359
|
)
|
|
356
360
|
|
|
357
361
|
val application = currentActivity?.application ?: throw IllegalStateException("No activity present")
|
|
@@ -365,6 +369,30 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
365
369
|
}
|
|
366
370
|
}
|
|
367
371
|
|
|
372
|
+
@ReactMethod
|
|
373
|
+
fun initializeWithParameters(
|
|
374
|
+
userAgentName: String,
|
|
375
|
+
userAgentVersion: String,
|
|
376
|
+
jsonParameters: String,
|
|
377
|
+
promise: Promise
|
|
378
|
+
) {
|
|
379
|
+
try {
|
|
380
|
+
Didomi.getInstance().addEventListener(eventListener)
|
|
381
|
+
|
|
382
|
+
Didomi.getInstance().setUserAgent(userAgentName, userAgentVersion)
|
|
383
|
+
|
|
384
|
+
val parameters = buildDidomiInitializeParameters(jsonParameters)
|
|
385
|
+
|
|
386
|
+
val application = currentActivity?.application ?: throw IllegalStateException("No activity present")
|
|
387
|
+
Didomi.getInstance().initialize(application, parameters)
|
|
388
|
+
|
|
389
|
+
promise.resolve(0)
|
|
390
|
+
} catch (e: Exception) {
|
|
391
|
+
Log.e("initialize", "Error while initializing the Didomi SDK", e)
|
|
392
|
+
promise.reject(e)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
368
396
|
@ReactMethod
|
|
369
397
|
fun onReady(promise: Promise) {
|
|
370
398
|
Didomi.getInstance().onReady { prepareEvent(EventTypes.READY_CALLBACK.event, null) }
|
|
@@ -599,7 +627,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
599
627
|
}
|
|
600
628
|
|
|
601
629
|
@ReactMethod
|
|
602
|
-
@Deprecated("Use shouldUserStatusBeCollected instead", replaceWith = ReplaceWith("shouldUserStatusBeCollected()"))
|
|
603
630
|
fun isUserConsentStatusPartial(promise: Promise) {
|
|
604
631
|
try {
|
|
605
632
|
promise.resolve(Didomi.getInstance().isUserConsentStatusPartial)
|
|
@@ -664,7 +691,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
664
691
|
}
|
|
665
692
|
|
|
666
693
|
@ReactMethod
|
|
667
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
668
694
|
fun setUserWithHashAuth(
|
|
669
695
|
organizationUserId: String,
|
|
670
696
|
algorithm: String,
|
|
@@ -686,7 +712,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
686
712
|
}
|
|
687
713
|
|
|
688
714
|
@ReactMethod
|
|
689
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
690
715
|
fun setUserWithHashAuthAndSetupUI(
|
|
691
716
|
organizationUserId: String,
|
|
692
717
|
algorithm: String,
|
|
@@ -709,7 +734,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
709
734
|
}
|
|
710
735
|
|
|
711
736
|
@ReactMethod
|
|
712
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
713
737
|
fun setUserWithHashAuthWithExpiration(
|
|
714
738
|
organizationUserId: String,
|
|
715
739
|
algorithm: String,
|
|
@@ -733,7 +757,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
733
757
|
}
|
|
734
758
|
|
|
735
759
|
@ReactMethod
|
|
736
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
737
760
|
fun setUserWithHashAuthWithExpirationAndSetupUI(
|
|
738
761
|
organizationUserId: String,
|
|
739
762
|
algorithm: String,
|
|
@@ -758,7 +781,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
758
781
|
}
|
|
759
782
|
|
|
760
783
|
@ReactMethod
|
|
761
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
762
784
|
fun setUserWithEncryptionAuth(
|
|
763
785
|
organizationUserId: String,
|
|
764
786
|
algorithm: String,
|
|
@@ -778,7 +800,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
778
800
|
}
|
|
779
801
|
|
|
780
802
|
@ReactMethod
|
|
781
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
782
803
|
fun setUserWithEncryptionAuthAndSetupUI(
|
|
783
804
|
organizationUserId: String,
|
|
784
805
|
algorithm: String,
|
|
@@ -799,7 +820,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
799
820
|
}
|
|
800
821
|
|
|
801
822
|
@ReactMethod
|
|
802
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
803
823
|
fun setUserWithEncryptionAuthWithExpiration(
|
|
804
824
|
organizationUserId: String,
|
|
805
825
|
algorithm: String,
|
|
@@ -821,7 +841,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
821
841
|
}
|
|
822
842
|
|
|
823
843
|
@ReactMethod
|
|
824
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
825
844
|
fun setUserWithEncryptionAuthWithExpirationAndSetupUI(
|
|
826
845
|
organizationUserId: String,
|
|
827
846
|
algorithm: String,
|
|
@@ -898,6 +917,37 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
898
917
|
}
|
|
899
918
|
}
|
|
900
919
|
|
|
920
|
+
@ReactMethod
|
|
921
|
+
fun setUserWithParameters(
|
|
922
|
+
jsonUserParameters: String,
|
|
923
|
+
promise: Promise
|
|
924
|
+
) {
|
|
925
|
+
try {
|
|
926
|
+
val userParameters = buildDidomiUserParameters(JSONObject(jsonUserParameters))
|
|
927
|
+
Didomi.getInstance().setUser(userParameters)
|
|
928
|
+
promise.resolve(0)
|
|
929
|
+
} catch (e: JSONException) {
|
|
930
|
+
Log.e("setUserWithParameters", "Error while parsing user with parameters", e)
|
|
931
|
+
promise.reject(e)
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
@ReactMethod
|
|
936
|
+
fun setUserWithParametersAndSetupUI(
|
|
937
|
+
jsonUserParameters: String,
|
|
938
|
+
promise: Promise
|
|
939
|
+
) {
|
|
940
|
+
try {
|
|
941
|
+
val userParameters = buildDidomiUserParameters(JSONObject(jsonUserParameters), currentActivity as? FragmentActivity)
|
|
942
|
+
|
|
943
|
+
Didomi.getInstance().setUser(userParameters)
|
|
944
|
+
promise.resolve(0)
|
|
945
|
+
} catch (e: JSONException) {
|
|
946
|
+
Log.e("setUserWithParameters", "Error while parsing user with parameters", e)
|
|
947
|
+
promise.reject(e)
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
901
951
|
@ReactMethod
|
|
902
952
|
fun showNotice(promise: Promise) {
|
|
903
953
|
try {
|
|
@@ -1128,8 +1178,58 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
1128
1178
|
}
|
|
1129
1179
|
|
|
1130
1180
|
// Required to transform from array to variadic.
|
|
1131
|
-
private fun readableArrayToStringArray(readableArray: ReadableArray)
|
|
1132
|
-
|
|
1181
|
+
private fun readableArrayToStringArray(readableArray: ReadableArray) = readableArray.toSet().toTypedArray()
|
|
1182
|
+
|
|
1183
|
+
private fun buildDidomiInitializeParameters(jsonParameters: String): DidomiInitializeParameters {
|
|
1184
|
+
val jsonObject = JSONObject(jsonParameters)
|
|
1185
|
+
|
|
1186
|
+
return DidomiInitializeParameters(
|
|
1187
|
+
apiKey = jsonObject.getString("apiKey"),
|
|
1188
|
+
localConfigurationPath = jsonObject.opt("localConfigurationPath")?.toString(),
|
|
1189
|
+
remoteConfigurationUrl = jsonObject.opt("remoteConfigurationUrl")?.toString(),
|
|
1190
|
+
providerId = jsonObject.opt("providerId")?.toString(),
|
|
1191
|
+
disableDidomiRemoteConfig = (jsonObject.opt("disableDidomiRemoteConfig") as? Boolean) ?: false,
|
|
1192
|
+
languageCode = jsonObject.opt("languageCode")?.toString(),
|
|
1193
|
+
noticeId = jsonObject.opt("noticeId")?.toString(),
|
|
1194
|
+
tvNoticeId = jsonObject.opt("androidTvNoticeId")?.toString(),
|
|
1195
|
+
androidTvEnabled = (jsonObject.opt("androidTvEnabled") as? Boolean) ?: false,
|
|
1196
|
+
countryCode = jsonObject.opt("countryCode")?.toString(),
|
|
1197
|
+
regionCode = jsonObject.opt("regionCode")?.toString(),
|
|
1198
|
+
isUnderage = (jsonObject.opt("isUnderage") as? Boolean) ?: false
|
|
1199
|
+
)
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
private fun buildDidomiUserParameters(
|
|
1203
|
+
jsonParameters: JSONObject,
|
|
1204
|
+
activity: FragmentActivity? = null
|
|
1205
|
+
): DidomiUserParameters {
|
|
1206
|
+
val userAuth = if (jsonParameters.has("userAuth")) {
|
|
1207
|
+
buildUserAuthParams(jsonParameters.getJSONObject("userAuth"))
|
|
1208
|
+
} else null
|
|
1209
|
+
|
|
1210
|
+
val dcsUserAuth = if (jsonParameters.has("dcsUserAuth")) {
|
|
1211
|
+
buildUserAuthParams(jsonParameters.getJSONObject("dcsUserAuth"))
|
|
1212
|
+
} else null
|
|
1213
|
+
|
|
1214
|
+
val isUnderage = jsonParameters.opt("isUnderage") as? Boolean
|
|
1215
|
+
|
|
1216
|
+
if (jsonParameters.has("synchronizedUsers")) {
|
|
1217
|
+
val synchronizedUsers = buildUserAuthParamsArray(jsonParameters.getJSONArray("synchronizedUsers"))
|
|
1218
|
+
return DidomiMultiUserParameters(
|
|
1219
|
+
userAuth = userAuth as UserAuth,
|
|
1220
|
+
dcsUserAuth = dcsUserAuth,
|
|
1221
|
+
synchronizedUsers = synchronizedUsers,
|
|
1222
|
+
activity = activity,
|
|
1223
|
+
isUnderage = isUnderage
|
|
1224
|
+
)
|
|
1225
|
+
} else {
|
|
1226
|
+
return DidomiUserParameters(
|
|
1227
|
+
userAuth = userAuth as UserAuth,
|
|
1228
|
+
dcsUserAuth = dcsUserAuth,
|
|
1229
|
+
activity = activity,
|
|
1230
|
+
isUnderage = isUnderage
|
|
1231
|
+
)
|
|
1232
|
+
}
|
|
1133
1233
|
}
|
|
1134
1234
|
|
|
1135
1235
|
private fun buildUserAuthParams(jsonParameters: JSONObject): UserAuthParams {
|
|
@@ -1162,4 +1262,8 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
1162
1262
|
)
|
|
1163
1263
|
}
|
|
1164
1264
|
}
|
|
1265
|
+
|
|
1266
|
+
private fun buildUserAuthParamsArray(jsonArray: JSONArray): Array<UserAuthParams> {
|
|
1267
|
+
return Array(jsonArray.length()) { i -> buildUserAuthParams(jsonArray.getJSONObject(i)) }
|
|
1268
|
+
}
|
|
1165
1269
|
}
|
package/ios/Didomi.m
CHANGED
|
@@ -19,6 +19,12 @@ RCT_EXTERN_METHOD(initialize:(NSString *)userAgentName
|
|
|
19
19
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
20
20
|
reject:(RCTPromiseRejectBlock)reject)
|
|
21
21
|
|
|
22
|
+
RCT_EXTERN_METHOD(initializeWithParameters:(NSString *)userAgentName
|
|
23
|
+
userAgentVersion:(NSString *)userAgentVersion
|
|
24
|
+
parameters:(NSString *)parameters
|
|
25
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
26
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
27
|
+
|
|
22
28
|
RCT_EXTERN_METHOD(onReady:(RCTPromiseResolveBlock)resolve
|
|
23
29
|
reject:(RCTPromiseRejectBlock)reject)
|
|
24
30
|
|
|
@@ -256,6 +262,14 @@ RCT_EXTERN_METHOD(setUserWithAuthParamsAndSetupUI:(NSString *)jsonUserAuthParams
|
|
|
256
262
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
257
263
|
reject:(RCTPromiseRejectBlock)reject)
|
|
258
264
|
|
|
265
|
+
RCT_EXTERN_METHOD(setUserWithParameters:(NSString *)jsonParameters
|
|
266
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
267
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
268
|
+
|
|
269
|
+
RCT_EXTERN_METHOD(setUserWithParametersAndSetupUI:(NSString *)jsonParameters
|
|
270
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
271
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
272
|
+
|
|
259
273
|
RCT_EXTERN_METHOD(listenToVendorStatus:(NSString *)vendorId
|
|
260
274
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
261
275
|
reject:(RCTPromiseRejectBlock)reject)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
extension String {
|
|
4
|
+
func toJSON() throws -> [String: Any] {
|
|
5
|
+
guard let data = self.data(using: .utf8),
|
|
6
|
+
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
|
|
7
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Invalid JSON format"])
|
|
8
|
+
}
|
|
9
|
+
return json
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
func toJSONArray() throws -> [[String: Any]] {
|
|
13
|
+
guard let data = self.data(using: .utf8),
|
|
14
|
+
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] else {
|
|
15
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Invalid JSON array format"])
|
|
16
|
+
}
|
|
17
|
+
return json
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func getJSONValue(for key: String) throws -> Any? {
|
|
21
|
+
let json = try self.toJSON()
|
|
22
|
+
return json[key]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/ios/RNDidomi.swift
CHANGED
|
@@ -22,10 +22,26 @@ class RNDidomi: RCTEventEmitter {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@objc(initialize:userAgentVersion:apiKey:localConfigurationPath:remoteConfigurationURL:providerId:disableDidomiRemoteConfig:languageCode:noticeId:androidTvNoticeId:androidTvEnabled:countryCode:regionCode:resolve:reject:)
|
|
25
|
-
func initialize(
|
|
25
|
+
func initialize(
|
|
26
|
+
userAgentName: String,
|
|
27
|
+
userAgentVersion: String,
|
|
28
|
+
apiKey: String,
|
|
29
|
+
localConfigurationPath: String?,
|
|
30
|
+
remoteConfigurationURL: String?,
|
|
31
|
+
providerId: String?,
|
|
32
|
+
disableDidomiRemoteConfig: Bool = false,
|
|
33
|
+
languageCode: String? = nil,
|
|
34
|
+
noticeId: String? = nil,
|
|
35
|
+
androidTvNoticeId: String? = nil,
|
|
36
|
+
androidTvEnabled: Bool = false,
|
|
37
|
+
countryCode: String? = nil,
|
|
38
|
+
regionCode: String? = nil,
|
|
39
|
+
resolve: RCTPromiseResolveBlock,
|
|
40
|
+
reject: RCTPromiseRejectBlock
|
|
41
|
+
) {
|
|
26
42
|
Didomi.shared.setUserAgent(name: userAgentName, version: userAgentVersion)
|
|
27
43
|
|
|
28
|
-
|
|
44
|
+
let parameters = DidomiInitializeParameters(
|
|
29
45
|
apiKey: apiKey,
|
|
30
46
|
localConfigurationPath: localConfigurationPath,
|
|
31
47
|
remoteConfigurationURL: remoteConfigurationURL,
|
|
@@ -35,11 +51,35 @@ class RNDidomi: RCTEventEmitter {
|
|
|
35
51
|
noticeID: noticeId,
|
|
36
52
|
countryCode: countryCode,
|
|
37
53
|
regionCode: regionCode
|
|
38
|
-
)
|
|
54
|
+
)
|
|
55
|
+
Didomi.shared.initialize(parameters)
|
|
39
56
|
|
|
40
57
|
resolve(0)
|
|
41
58
|
}
|
|
42
59
|
|
|
60
|
+
@objc(initializeWithParameters:userAgentVersion:parameters:resolve:reject:)
|
|
61
|
+
func initializeWithParameters(
|
|
62
|
+
userAgentName: String,
|
|
63
|
+
userAgentVersion: String,
|
|
64
|
+
jsonParameters: String,
|
|
65
|
+
resolve: RCTPromiseResolveBlock,
|
|
66
|
+
reject: RCTPromiseRejectBlock
|
|
67
|
+
) {
|
|
68
|
+
do {
|
|
69
|
+
let parameters = try buildDidomiInitializeParameters(from: jsonParameters)
|
|
70
|
+
|
|
71
|
+
if let userAgentName = try? jsonParameters.getJSONValue(for: "userAgentName") as? String,
|
|
72
|
+
let userAgentVersion = try? jsonParameters.getJSONValue(for: "userAgentVersion") as? String {
|
|
73
|
+
Didomi.shared.setUserAgent(name: userAgentName, version: userAgentVersion)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Didomi.shared.initialize(parameters)
|
|
77
|
+
resolve(0)
|
|
78
|
+
} catch {
|
|
79
|
+
reject("Error", "Error while initializing with parameters", error)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
43
83
|
@objc(onReady:reject:)
|
|
44
84
|
func onReady(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
45
85
|
Didomi.shared.onReady { [weak self] in
|
|
@@ -534,6 +574,46 @@ class RNDidomi: RCTEventEmitter {
|
|
|
534
574
|
reject("Error", "Error while setting user with auth params", error)
|
|
535
575
|
}
|
|
536
576
|
}
|
|
577
|
+
|
|
578
|
+
@objc(setUserWithParameters:resolve:reject:)
|
|
579
|
+
dynamic func setUserWithParameters(
|
|
580
|
+
jsonParameters: String,
|
|
581
|
+
resolve: RCTPromiseResolveBlock,
|
|
582
|
+
reject: RCTPromiseRejectBlock
|
|
583
|
+
) {
|
|
584
|
+
do {
|
|
585
|
+
let parameters = try buildDidomiUserParameters(from: jsonParameters, containerController: nil)
|
|
586
|
+
Didomi.shared.setUser(parameters)
|
|
587
|
+
resolve(0)
|
|
588
|
+
} catch {
|
|
589
|
+
reject("Error", "Error while setting user with parameters", error)
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
@objc(setUserWithParametersAndSetupUI:resolve:reject:)
|
|
594
|
+
dynamic func setUserWithParametersAndSetupUI(
|
|
595
|
+
jsonParameters: String,
|
|
596
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
597
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
598
|
+
) {
|
|
599
|
+
DispatchQueue.main.async { [weak self] in
|
|
600
|
+
do {
|
|
601
|
+
guard let strongSelf = self else {
|
|
602
|
+
resolve(0)
|
|
603
|
+
return
|
|
604
|
+
}
|
|
605
|
+
let containerController = RCTPresentedViewController()
|
|
606
|
+
let parameters = try strongSelf.buildDidomiUserParameters(
|
|
607
|
+
from: jsonParameters,
|
|
608
|
+
containerController: containerController
|
|
609
|
+
)
|
|
610
|
+
Didomi.shared.setUser(parameters)
|
|
611
|
+
resolve(0)
|
|
612
|
+
} catch {
|
|
613
|
+
reject("Error", "Error while setting user with parameters", error)
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
537
617
|
|
|
538
618
|
@objc(listenToVendorStatus:resolve:reject:)
|
|
539
619
|
dynamic func listenToVendorStatus(vendorId: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
@@ -869,16 +949,65 @@ extension RNDidomi {
|
|
|
869
949
|
Didomi.shared.removeEventListener(listener: didomiEventListener)
|
|
870
950
|
}
|
|
871
951
|
}
|
|
952
|
+
|
|
953
|
+
// Build parameters object used when calling `initialize`.
|
|
954
|
+
private func buildDidomiInitializeParameters(from jsonString: String) throws -> DidomiInitializeParameters {
|
|
955
|
+
let json = try jsonString.toJSON()
|
|
956
|
+
|
|
957
|
+
return DidomiInitializeParameters(
|
|
958
|
+
apiKey: json["apiKey"] as? String ?? "",
|
|
959
|
+
localConfigurationPath: json["localConfigurationPath"] as? String,
|
|
960
|
+
remoteConfigurationURL: json["remoteConfigurationURL"] as? String,
|
|
961
|
+
providerID: json["providerId"] as? String,
|
|
962
|
+
disableDidomiRemoteConfig: json["disableDidomiRemoteConfig"] as? Bool ?? false,
|
|
963
|
+
languageCode: json["languageCode"] as? String ?? Locale.current.languageCode ?? "",
|
|
964
|
+
noticeID: json["noticeId"] as? String,
|
|
965
|
+
countryCode: json["countryCode"] as? String,
|
|
966
|
+
regionCode: json["regionCode"] as? String,
|
|
967
|
+
isUnderage: json["isUnderage"] as? Bool ?? false
|
|
968
|
+
)
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Build parameters object used when calling `setUser`.
|
|
972
|
+
private func buildDidomiUserParameters(from jsonString: String, containerController: UIViewController? = nil) throws -> DidomiUserParameters {
|
|
973
|
+
let json = try jsonString.toJSON()
|
|
974
|
+
|
|
975
|
+
let userAuthJSON = json["userAuth"] as? [String: Any]
|
|
976
|
+
let userAuth = try buildUserAuthParams(from: userAuthJSON)
|
|
977
|
+
let dcsUserAuthJSON = json["dcsUserAuth"] as? [String: Any]
|
|
978
|
+
let dcsUserAuth = try? buildUserAuthParams(from: dcsUserAuthJSON)
|
|
979
|
+
let isUnderage = json["isUnderage"] as? Bool
|
|
980
|
+
|
|
981
|
+
if let synchronizedUsers = json["synchronizedUsers"] as? [[String: Any]] {
|
|
982
|
+
return DidomiMultiUserParameters(
|
|
983
|
+
userAuth: userAuth,
|
|
984
|
+
dcsUserAuth: dcsUserAuth,
|
|
985
|
+
synchronizedUsers: try synchronizedUsers.map { try buildUserAuthParams(from: $0) },
|
|
986
|
+
containerController: containerController,
|
|
987
|
+
isUnderage: isUnderage
|
|
988
|
+
)
|
|
989
|
+
} else {
|
|
990
|
+
return DidomiUserParameters(
|
|
991
|
+
userAuth: userAuth,
|
|
992
|
+
dcsUserAuth: dcsUserAuth,
|
|
993
|
+
containerController: containerController,
|
|
994
|
+
isUnderage: isUnderage
|
|
995
|
+
)
|
|
996
|
+
}
|
|
997
|
+
}
|
|
872
998
|
|
|
873
999
|
/// Build the user auth params from the JSON parameters
|
|
874
1000
|
private func buildUserAuthParams(from jsonString: String) throws -> UserAuthParams {
|
|
875
|
-
let
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1001
|
+
let json = try jsonString.toJSON()
|
|
1002
|
+
return try buildUserAuthParams(from: json)
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
private func buildUserAuthParams(from json: [String: Any]?) throws -> UserAuthParams {
|
|
1006
|
+
guard let json = json,
|
|
1007
|
+
let id = json["id"] as? String,
|
|
879
1008
|
let algorithm = json["algorithm"] as? String,
|
|
880
1009
|
let secretID = json["secretId"] as? String else {
|
|
881
|
-
|
|
1010
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Missing required parameters: id, algorithm or secretId"])
|
|
882
1011
|
}
|
|
883
1012
|
|
|
884
1013
|
let expiration = json["expiration"] as? CLong
|
|
@@ -905,7 +1034,7 @@ extension RNDidomi {
|
|
|
905
1034
|
}
|
|
906
1035
|
} else {
|
|
907
1036
|
guard let digest = digest else {
|
|
908
|
-
|
|
1037
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Missing required digest parameter"])
|
|
909
1038
|
}
|
|
910
1039
|
if let expiration = expiration {
|
|
911
1040
|
return UserAuthWithHashParams(
|
|
@@ -930,13 +1059,8 @@ extension RNDidomi {
|
|
|
930
1059
|
|
|
931
1060
|
/// Build the user auth params list from the JSON parameters
|
|
932
1061
|
private func buildUserAuthParamsArray(from jsonString: String) throws -> [UserAuthParams] {
|
|
933
|
-
let
|
|
934
|
-
|
|
935
|
-
return try jsonArray.map { dictionary in
|
|
936
|
-
let jsonData = try JSONSerialization.data(withJSONObject: dictionary, options: [])
|
|
937
|
-
let jsonString = String(data: jsonData, encoding: .utf8)!
|
|
938
|
-
return try buildUserAuthParams(from: jsonString)
|
|
939
|
-
}
|
|
1062
|
+
let jsonArray = try jsonString.toJSONArray()
|
|
1063
|
+
return try jsonArray.map { try buildUserAuthParams(from: $0) }
|
|
940
1064
|
}
|
|
941
1065
|
}
|
|
942
1066
|
|
|
@@ -7,5 +7,5 @@ exports.DIDOMI_VERSION = exports.DIDOMI_USER_AGENT_NAME = void 0;
|
|
|
7
7
|
// User agent name
|
|
8
8
|
const DIDOMI_USER_AGENT_NAME = exports.DIDOMI_USER_AGENT_NAME = "Didomi React-Native SDK";
|
|
9
9
|
// User agent version
|
|
10
|
-
const DIDOMI_VERSION = exports.DIDOMI_VERSION = "2.
|
|
10
|
+
const DIDOMI_VERSION = exports.DIDOMI_VERSION = "2.10.1";
|
|
11
11
|
//# sourceMappingURL=Constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DIDOMI_USER_AGENT_NAME","exports","DIDOMI_VERSION"],"sourceRoot":"../../src","sources":["Constants.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,yBAAyB;AAC/D;AACO,MAAME,cAAc,GAAAD,OAAA,CAAAC,cAAA,GAAG,
|
|
1
|
+
{"version":3,"names":["DIDOMI_USER_AGENT_NAME","exports","DIDOMI_VERSION"],"sourceRoot":"../../src","sources":["Constants.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,yBAAyB;AAC/D;AACO,MAAME,cAAc,GAAAD,OAAA,CAAAC,cAAA,GAAG,QAAQ","ignoreList":[]}
|
package/lib/commonjs/Didomi.js
CHANGED
|
@@ -26,6 +26,7 @@ const Didomi = exports.Didomi = {
|
|
|
26
26
|
* @param androidTvEnabled: Whether to allow Didomi SDK to run on Android TV, default to "false".
|
|
27
27
|
* @param countryCode: Override user country code when determining the privacy regulation to apply. Keep undefined to let the Didomi SDK determine the user country.
|
|
28
28
|
* @param regionCode: Override user region code when determining the privacy regulation to apply. Keep undefined to let the Didomi SDK determine the user region. Ignored if countryCode is not set.
|
|
29
|
+
* @deprecated Use {@link #initializeWithParameters} instead
|
|
29
30
|
*/
|
|
30
31
|
initialize: (apiKey, localConfigurationPath, remoteConfigurationUrl, providerId, disableDidomiRemoteConfig = false, languageCode, noticeId, androidTvNoticeId, androidTvEnabled = false, countryCode, regionCode) => {
|
|
31
32
|
// Init listener
|
|
@@ -34,6 +35,18 @@ const Didomi = exports.Didomi = {
|
|
|
34
35
|
// Trigger native SDK init
|
|
35
36
|
return RNDidomi.initialize(_Constants.DIDOMI_USER_AGENT_NAME, _Constants.DIDOMI_VERSION, apiKey, localConfigurationPath, remoteConfigurationUrl, providerId, disableDidomiRemoteConfig, languageCode, noticeId, androidTvNoticeId, androidTvEnabled, countryCode, regionCode);
|
|
36
37
|
},
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the Didomi SDK with parameters
|
|
40
|
+
* @param parameters: Parameters to initialize the Didomi SDK
|
|
41
|
+
* @returns: Promise that resolves we have called the native initialize method
|
|
42
|
+
*/
|
|
43
|
+
initializeWithParameters: parameters => {
|
|
44
|
+
// Init listener
|
|
45
|
+
_DidomiListener.DidomiListener.init();
|
|
46
|
+
|
|
47
|
+
// Trigger native SDK init
|
|
48
|
+
return RNDidomi.initializeWithParameters(_Constants.DIDOMI_USER_AGENT_NAME, _Constants.DIDOMI_VERSION, JSON.stringify(parameters));
|
|
49
|
+
},
|
|
37
50
|
/**
|
|
38
51
|
* Listen to SDK ready state
|
|
39
52
|
*/
|
|
@@ -389,7 +402,7 @@ const Didomi = exports.Didomi = {
|
|
|
389
402
|
* @param digest Digest of the organization user ID and secret
|
|
390
403
|
* @param salt Salt used for computing the digest (optional)
|
|
391
404
|
* @param expiration Expiration date as timestamp (to prevent replay attacks)
|
|
392
|
-
* @deprecated
|
|
405
|
+
* @deprecated Use {@link setUserWithParameters} instead
|
|
393
406
|
*/
|
|
394
407
|
setUserWithHashAuth: (id, algorithm, secretId, digest, salt, expiration) => {
|
|
395
408
|
if (expiration === undefined) {
|
|
@@ -407,7 +420,7 @@ const Didomi = exports.Didomi = {
|
|
|
407
420
|
* @param digest Digest of the organization user ID and secret
|
|
408
421
|
* @param salt Salt used for computing the digest (optional)
|
|
409
422
|
* @param expiration Expiration date as timestamp (to prevent replay attacks)
|
|
410
|
-
* @deprecated
|
|
423
|
+
* @deprecated Use {@link setUserWithParametersAndSetupUI} instead
|
|
411
424
|
*/
|
|
412
425
|
setUserWithHashAuthAndSetupUI: (id, algorithm, secretId, digest, salt, expiration) => {
|
|
413
426
|
if (expiration === undefined) {
|
|
@@ -424,7 +437,7 @@ const Didomi = exports.Didomi = {
|
|
|
424
437
|
* @param secretId ID of the secret used for computing the digest
|
|
425
438
|
* @param initializationVector Initialization Vector used for computing the user ID
|
|
426
439
|
* @param expiration Expiration date as timestamp (to prevent replay attacks)
|
|
427
|
-
* @deprecated
|
|
440
|
+
* @deprecated Use {@link setUserWithParameters} instead
|
|
428
441
|
*/
|
|
429
442
|
setUserWithEncryptionAuth: (id, algorithm, secretId, initializationVector, expiration) => {
|
|
430
443
|
if (expiration === undefined) {
|
|
@@ -441,7 +454,7 @@ const Didomi = exports.Didomi = {
|
|
|
441
454
|
* @param secretId ID of the secret used for computing the digest
|
|
442
455
|
* @param initializationVector Initialization Vector used for computing the user ID
|
|
443
456
|
* @param expiration Expiration date as timestamp (to prevent replay attacks)
|
|
444
|
-
* @deprecated
|
|
457
|
+
* @deprecated Use {@link setUserWithParametersAndSetupUI} instead
|
|
445
458
|
*/
|
|
446
459
|
setUserWithEncryptionAuthAndSetupUI: (id, algorithm, secretId, initializationVector, expiration) => {
|
|
447
460
|
if (expiration === undefined) {
|
|
@@ -455,6 +468,7 @@ const Didomi = exports.Didomi = {
|
|
|
455
468
|
*
|
|
456
469
|
* @param userAuthParams as UserAuthParams (use UserAuthWithEncryptionParams or UserAuthWithHashParams)
|
|
457
470
|
* @param synchronizedUsers as UserAuthParams[] (optional)
|
|
471
|
+
* @deprecated Use {@link setUserWithParameters} instead
|
|
458
472
|
*/
|
|
459
473
|
setUserWithAuthParams: (userAuthParams, synchronizedUsers) => RNDidomi.setUserWithAuthParams(JSON.stringify(userAuthParams), JSON.stringify(synchronizedUsers)),
|
|
460
474
|
/**
|
|
@@ -462,8 +476,21 @@ const Didomi = exports.Didomi = {
|
|
|
462
476
|
*
|
|
463
477
|
* @param userAuthParams as UserAuthParams (use UserAuthWithEncryptionParams or UserAuthWithHashParams)
|
|
464
478
|
* @param synchronizedUsers as UserAuthParams[] (optional)
|
|
479
|
+
* @deprecated Use {@link setUserWithParametersAndSetupUI} instead
|
|
465
480
|
*/
|
|
466
481
|
setUserWithAuthParamsAndSetupUI: (userAuthParams, synchronizedUsers) => RNDidomi.setUserWithAuthParamsAndSetupUI(JSON.stringify(userAuthParams), JSON.stringify(synchronizedUsers)),
|
|
482
|
+
/**
|
|
483
|
+
* Set user information with parameters
|
|
484
|
+
*
|
|
485
|
+
* @param parameters as DidomiUserParameters
|
|
486
|
+
*/
|
|
487
|
+
setUserWithParameters: parameters => RNDidomi.setUserWithParameters(JSON.stringify(parameters)),
|
|
488
|
+
/**
|
|
489
|
+
* Set user information with parameters and check for missing consent
|
|
490
|
+
*
|
|
491
|
+
* @param parameters as DidomiUserParameters
|
|
492
|
+
*/
|
|
493
|
+
setUserWithParametersAndSetupUI: parameters => RNDidomi.setUserWithParametersAndSetupUI(JSON.stringify(parameters)),
|
|
467
494
|
/**
|
|
468
495
|
* Show the consent notice (if required, not disabled in the config and not already displayed)
|
|
469
496
|
*/
|