@didomi/react-native 2.8.0 → 2.10.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/android/build.gradle +1 -1
- package/android/src/main/java/io/didomi/reactnative/DidomiModule.kt +125 -10
- package/ios/Didomi.m +17 -0
- package/ios/Extensions/StringExtension.swift +24 -0
- package/ios/RNDidomi.swift +148 -27
- package/lib/commonjs/Constants.js +1 -1
- package/lib/commonjs/Constants.js.map +1 -1
- package/lib/commonjs/Didomi.js +37 -5
- package/lib/commonjs/Didomi.js.map +1 -1
- package/lib/commonjs/DidomiTypes.js +46 -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 +37 -5
- package/lib/module/Didomi.js.map +1 -1
- package/lib/module/DidomiTypes.js +49 -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 +32 -6
- package/lib/typescript/Didomi.d.ts.map +1 -1
- package/lib/typescript/DidomiTypes.d.ts +141 -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 +46 -6
- package/src/DidomiTypes.ts +146 -3
- 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
|
|
@@ -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) }
|
|
@@ -551,6 +579,15 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
551
579
|
}
|
|
552
580
|
}
|
|
553
581
|
|
|
582
|
+
@ReactMethod
|
|
583
|
+
fun getApplicableRegulation(promise: Promise) {
|
|
584
|
+
try {
|
|
585
|
+
promise.resolve(Didomi.getInstance().applicableRegulation.value)
|
|
586
|
+
} catch (e: DidomiNotReadyException) {
|
|
587
|
+
promise.reject(e)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
554
591
|
@ReactMethod
|
|
555
592
|
fun hideNotice(promise: Promise) {
|
|
556
593
|
try {
|
|
@@ -590,7 +627,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
590
627
|
}
|
|
591
628
|
|
|
592
629
|
@ReactMethod
|
|
593
|
-
@Deprecated("Use shouldUserStatusBeCollected instead", replaceWith = ReplaceWith("shouldUserStatusBeCollected()"))
|
|
594
630
|
fun isUserConsentStatusPartial(promise: Promise) {
|
|
595
631
|
try {
|
|
596
632
|
promise.resolve(Didomi.getInstance().isUserConsentStatusPartial)
|
|
@@ -655,7 +691,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
655
691
|
}
|
|
656
692
|
|
|
657
693
|
@ReactMethod
|
|
658
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
659
694
|
fun setUserWithHashAuth(
|
|
660
695
|
organizationUserId: String,
|
|
661
696
|
algorithm: String,
|
|
@@ -677,7 +712,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
677
712
|
}
|
|
678
713
|
|
|
679
714
|
@ReactMethod
|
|
680
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
681
715
|
fun setUserWithHashAuthAndSetupUI(
|
|
682
716
|
organizationUserId: String,
|
|
683
717
|
algorithm: String,
|
|
@@ -700,7 +734,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
700
734
|
}
|
|
701
735
|
|
|
702
736
|
@ReactMethod
|
|
703
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
704
737
|
fun setUserWithHashAuthWithExpiration(
|
|
705
738
|
organizationUserId: String,
|
|
706
739
|
algorithm: String,
|
|
@@ -724,7 +757,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
724
757
|
}
|
|
725
758
|
|
|
726
759
|
@ReactMethod
|
|
727
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
728
760
|
fun setUserWithHashAuthWithExpirationAndSetupUI(
|
|
729
761
|
organizationUserId: String,
|
|
730
762
|
algorithm: String,
|
|
@@ -749,7 +781,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
749
781
|
}
|
|
750
782
|
|
|
751
783
|
@ReactMethod
|
|
752
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
753
784
|
fun setUserWithEncryptionAuth(
|
|
754
785
|
organizationUserId: String,
|
|
755
786
|
algorithm: String,
|
|
@@ -769,7 +800,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
769
800
|
}
|
|
770
801
|
|
|
771
802
|
@ReactMethod
|
|
772
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
773
803
|
fun setUserWithEncryptionAuthAndSetupUI(
|
|
774
804
|
organizationUserId: String,
|
|
775
805
|
algorithm: String,
|
|
@@ -790,7 +820,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
790
820
|
}
|
|
791
821
|
|
|
792
822
|
@ReactMethod
|
|
793
|
-
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
794
823
|
fun setUserWithEncryptionAuthWithExpiration(
|
|
795
824
|
organizationUserId: String,
|
|
796
825
|
algorithm: String,
|
|
@@ -812,7 +841,6 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
812
841
|
}
|
|
813
842
|
|
|
814
843
|
@ReactMethod
|
|
815
|
-
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
816
844
|
fun setUserWithEncryptionAuthWithExpirationAndSetupUI(
|
|
817
845
|
organizationUserId: String,
|
|
818
846
|
algorithm: String,
|
|
@@ -889,6 +917,37 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
889
917
|
}
|
|
890
918
|
}
|
|
891
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
|
+
|
|
892
951
|
@ReactMethod
|
|
893
952
|
fun showNotice(promise: Promise) {
|
|
894
953
|
try {
|
|
@@ -1123,6 +1182,58 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
1123
1182
|
return Array(readableArray.size()) { i -> readableArray.getString(i) }
|
|
1124
1183
|
}
|
|
1125
1184
|
|
|
1185
|
+
private fun buildDidomiInitializeParameters(jsonParameters: String): DidomiInitializeParameters {
|
|
1186
|
+
val jsonObject = JSONObject(jsonParameters)
|
|
1187
|
+
|
|
1188
|
+
return DidomiInitializeParameters(
|
|
1189
|
+
apiKey = jsonObject.getString("apiKey"),
|
|
1190
|
+
localConfigurationPath = jsonObject.opt("localConfigurationPath")?.toString(),
|
|
1191
|
+
remoteConfigurationUrl = jsonObject.opt("remoteConfigurationUrl")?.toString(),
|
|
1192
|
+
providerId = jsonObject.opt("providerId")?.toString(),
|
|
1193
|
+
disableDidomiRemoteConfig = (jsonObject.opt("disableDidomiRemoteConfig") as? Boolean) ?: false,
|
|
1194
|
+
languageCode = jsonObject.opt("languageCode")?.toString(),
|
|
1195
|
+
noticeId = jsonObject.opt("noticeId")?.toString(),
|
|
1196
|
+
tvNoticeId = jsonObject.opt("androidTvNoticeId")?.toString(),
|
|
1197
|
+
androidTvEnabled = (jsonObject.opt("androidTvEnabled") as? Boolean) ?: false,
|
|
1198
|
+
countryCode = jsonObject.opt("countryCode")?.toString(),
|
|
1199
|
+
regionCode = jsonObject.opt("regionCode")?.toString(),
|
|
1200
|
+
isUnderage = (jsonObject.opt("isUnderage") as? Boolean) ?: false
|
|
1201
|
+
)
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
private fun buildDidomiUserParameters(
|
|
1205
|
+
jsonParameters: JSONObject,
|
|
1206
|
+
activity: FragmentActivity? = null
|
|
1207
|
+
): DidomiUserParameters {
|
|
1208
|
+
val userAuth = if (jsonParameters.has("userAuth")) {
|
|
1209
|
+
buildUserAuthParams(jsonParameters.getJSONObject("userAuth"))
|
|
1210
|
+
} else null
|
|
1211
|
+
|
|
1212
|
+
val dcsUserAuth = if (jsonParameters.has("dcsUserAuth")) {
|
|
1213
|
+
buildUserAuthParams(jsonParameters.getJSONObject("dcsUserAuth"))
|
|
1214
|
+
} else null
|
|
1215
|
+
|
|
1216
|
+
val isUnderage = jsonParameters.opt("isUnderage") as? Boolean
|
|
1217
|
+
|
|
1218
|
+
if (jsonParameters.has("synchronizedUsers")) {
|
|
1219
|
+
val synchronizedUsers = buildUserAuthParamsArray(jsonParameters.getJSONArray("synchronizedUsers"))
|
|
1220
|
+
return DidomiMultiUserParameters(
|
|
1221
|
+
userAuth = userAuth as UserAuth,
|
|
1222
|
+
dcsUserAuth = dcsUserAuth,
|
|
1223
|
+
synchronizedUsers = synchronizedUsers,
|
|
1224
|
+
activity = activity,
|
|
1225
|
+
isUnderage = isUnderage
|
|
1226
|
+
)
|
|
1227
|
+
} else {
|
|
1228
|
+
return DidomiUserParameters(
|
|
1229
|
+
userAuth = userAuth as UserAuth,
|
|
1230
|
+
dcsUserAuth = dcsUserAuth,
|
|
1231
|
+
activity = activity,
|
|
1232
|
+
isUnderage = isUnderage
|
|
1233
|
+
)
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1126
1237
|
private fun buildUserAuthParams(jsonParameters: JSONObject): UserAuthParams {
|
|
1127
1238
|
|
|
1128
1239
|
val id = jsonParameters.getString("id")
|
|
@@ -1153,4 +1264,8 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
1153
1264
|
)
|
|
1154
1265
|
}
|
|
1155
1266
|
}
|
|
1267
|
+
|
|
1268
|
+
private fun buildUserAuthParamsArray(jsonArray: JSONArray): Array<UserAuthParams> {
|
|
1269
|
+
return Array(jsonArray.length()) { i -> buildUserAuthParams(jsonArray.getJSONObject(i)) }
|
|
1270
|
+
}
|
|
1156
1271
|
}
|
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
|
|
|
@@ -53,6 +59,9 @@ RCT_EXTERN_METHOD(getCurrentUserStatus:(RCTPromiseResolveBlock)resolve
|
|
|
53
59
|
RCT_EXTERN_METHOD(getUserStatus:(RCTPromiseResolveBlock)resolve
|
|
54
60
|
reject:(RCTPromiseRejectBlock)reject)
|
|
55
61
|
|
|
62
|
+
RCT_EXTERN_METHOD(getApplicableRegulation:(RCTPromiseResolveBlock)resolve
|
|
63
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
64
|
+
|
|
56
65
|
RCT_EXTERN_METHOD(setCurrentUserStatus:(NSString *)currentUserStatusAsString
|
|
57
66
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
58
67
|
reject:(RCTPromiseRejectBlock)reject)
|
|
@@ -253,6 +262,14 @@ RCT_EXTERN_METHOD(setUserWithAuthParamsAndSetupUI:(NSString *)jsonUserAuthParams
|
|
|
253
262
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
254
263
|
reject:(RCTPromiseRejectBlock)reject)
|
|
255
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
|
+
|
|
256
273
|
RCT_EXTERN_METHOD(listenToVendorStatus:(NSString *)vendorId
|
|
257
274
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
258
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
|
|
@@ -104,6 +144,11 @@ class RNDidomi: RCTEventEmitter {
|
|
|
104
144
|
let userStatus = try? JSONSerialization.jsonObject(with: encoder.encode(Didomi.shared.getUserStatus())) as? [String: Any]
|
|
105
145
|
resolve(userStatus)
|
|
106
146
|
}
|
|
147
|
+
|
|
148
|
+
@objc(getApplicableRegulation:reject:)
|
|
149
|
+
func getApplicableRegulation(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
150
|
+
resolve(Didomi.shared.applicableRegulation.description)
|
|
151
|
+
}
|
|
107
152
|
|
|
108
153
|
@objc(setCurrentUserStatus:resolve:reject:)
|
|
109
154
|
func setCurrentUserStatus(currentUserStatusAsString: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
@@ -269,18 +314,10 @@ class RNDidomi: RCTEventEmitter {
|
|
|
269
314
|
|
|
270
315
|
@objc(showPreferences:resolve:reject:)
|
|
271
316
|
dynamic func showPreferences(view: String?, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
272
|
-
|
|
273
|
-
|
|
317
|
+
DispatchQueue.main.async {
|
|
318
|
+
if let containerController = RCTPresentedViewController() {
|
|
274
319
|
if let view = view {
|
|
275
|
-
|
|
276
|
-
switch view.lowercased() {
|
|
277
|
-
case "sensitive-personal-information":
|
|
278
|
-
preferencesView = .sensitivePersonalInformation
|
|
279
|
-
case "vendors":
|
|
280
|
-
preferencesView = .vendors
|
|
281
|
-
default:
|
|
282
|
-
preferencesView = .purposes
|
|
283
|
-
}
|
|
320
|
+
let preferencesView: Didomi.Views = view.lowercased() == "vendors" ? .vendors : .purposes
|
|
284
321
|
Didomi.shared.showPreferences(controller: containerController, view: preferencesView)
|
|
285
322
|
} else {
|
|
286
323
|
Didomi.shared.showPreferences(controller: containerController)
|
|
@@ -537,6 +574,46 @@ class RNDidomi: RCTEventEmitter {
|
|
|
537
574
|
reject("Error", "Error while setting user with auth params", error)
|
|
538
575
|
}
|
|
539
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
|
+
}
|
|
540
617
|
|
|
541
618
|
@objc(listenToVendorStatus:resolve:reject:)
|
|
542
619
|
dynamic func listenToVendorStatus(vendorId: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
@@ -872,16 +949,65 @@ extension RNDidomi {
|
|
|
872
949
|
Didomi.shared.removeEventListener(listener: didomiEventListener)
|
|
873
950
|
}
|
|
874
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
|
+
}
|
|
875
998
|
|
|
876
999
|
/// Build the user auth params from the JSON parameters
|
|
877
1000
|
private func buildUserAuthParams(from jsonString: String) throws -> UserAuthParams {
|
|
878
|
-
let
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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,
|
|
882
1008
|
let algorithm = json["algorithm"] as? String,
|
|
883
1009
|
let secretID = json["secretId"] as? String else {
|
|
884
|
-
|
|
1010
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Missing required parameters: id, algorithm or secretId"])
|
|
885
1011
|
}
|
|
886
1012
|
|
|
887
1013
|
let expiration = json["expiration"] as? CLong
|
|
@@ -908,7 +1034,7 @@ extension RNDidomi {
|
|
|
908
1034
|
}
|
|
909
1035
|
} else {
|
|
910
1036
|
guard let digest = digest else {
|
|
911
|
-
|
|
1037
|
+
throw NSError(domain: "Didomi", code: 400, userInfo: [NSLocalizedDescriptionKey: "Missing required digest parameter"])
|
|
912
1038
|
}
|
|
913
1039
|
if let expiration = expiration {
|
|
914
1040
|
return UserAuthWithHashParams(
|
|
@@ -933,13 +1059,8 @@ extension RNDidomi {
|
|
|
933
1059
|
|
|
934
1060
|
/// Build the user auth params list from the JSON parameters
|
|
935
1061
|
private func buildUserAuthParamsArray(from jsonString: String) throws -> [UserAuthParams] {
|
|
936
|
-
let
|
|
937
|
-
|
|
938
|
-
return try jsonArray.map { dictionary in
|
|
939
|
-
let jsonData = try JSONSerialization.data(withJSONObject: dictionary, options: [])
|
|
940
|
-
let jsonString = String(data: jsonData, encoding: .utf8)!
|
|
941
|
-
return try buildUserAuthParams(from: jsonString)
|
|
942
|
-
}
|
|
1062
|
+
let jsonArray = try jsonString.toJSONArray()
|
|
1063
|
+
return try jsonArray.map { try buildUserAuthParams(from: $0) }
|
|
943
1064
|
}
|
|
944
1065
|
}
|
|
945
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.0";
|
|
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":[]}
|