@didomi/react-native 2.2.0 → 2.4.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/com/reactnativedidomi/DidomiModule.kt +153 -11
- package/android/src/main/java/com/reactnativedidomi/EventTypes.kt +1 -0
- package/ios/Didomi.m +20 -10
- package/ios/RNDidomi.swift +156 -4
- package/lib/commonjs/Constants.js +1 -1
- package/lib/commonjs/Constants.js.map +1 -1
- package/lib/commonjs/Didomi.js +22 -2
- package/lib/commonjs/Didomi.js.map +1 -1
- package/lib/commonjs/DidomiListener.js +12 -1
- package/lib/commonjs/DidomiListener.js.map +1 -1
- package/lib/commonjs/DidomiTypes.js +2 -1
- package/lib/commonjs/DidomiTypes.js.map +1 -1
- package/lib/commonjs/index.js +12 -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 +22 -2
- package/lib/module/Didomi.js.map +1 -1
- package/lib/module/DidomiListener.js +12 -1
- package/lib/module/DidomiListener.js.map +1 -1
- package/lib/module/DidomiTypes.js +2 -1
- 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/Didomi.d.ts +22 -2
- package/lib/typescript/DidomiTypes.d.ts +19 -1
- package/lib/typescript/index.d.ts +1 -1
- package/package.json +1 -1
- package/react-native-didomi.podspec +1 -1
- package/src/Constants.ts +1 -1
- package/src/Didomi.ts +35 -3
- package/src/DidomiListener.ts +11 -1
- package/src/DidomiTypes.ts +24 -1
- package/src/index.tsx +15 -1
package/android/build.gradle
CHANGED
|
@@ -15,8 +15,12 @@ import io.didomi.sdk.DidomiInitializeParameters
|
|
|
15
15
|
import io.didomi.sdk.events.*
|
|
16
16
|
import io.didomi.sdk.exceptions.DidomiNotReadyException
|
|
17
17
|
import io.didomi.sdk.models.CurrentUserStatus
|
|
18
|
+
import io.didomi.sdk.user.UserAuthParams
|
|
18
19
|
import io.didomi.sdk.user.UserAuthWithEncryptionParams
|
|
19
20
|
import io.didomi.sdk.user.UserAuthWithHashParams
|
|
21
|
+
import org.json.JSONArray
|
|
22
|
+
import org.json.JSONException
|
|
23
|
+
import org.json.JSONObject
|
|
20
24
|
|
|
21
25
|
class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
22
26
|
|
|
@@ -208,6 +212,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
208
212
|
/**
|
|
209
213
|
* Sync finished
|
|
210
214
|
*/
|
|
215
|
+
@Deprecated("Use syncReady instead", replaceWith = ReplaceWith("syncReady()"))
|
|
211
216
|
override fun syncDone(event: SyncDoneEvent) = prepareEvent(EventTypes.SYNC_DONE.event, event.organizationUserId)
|
|
212
217
|
|
|
213
218
|
/**
|
|
@@ -215,6 +220,11 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
215
220
|
*/
|
|
216
221
|
override fun syncError(event: SyncErrorEvent) = prepareEvent(EventTypes.SYNC_ERROR.event, event.error)
|
|
217
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Sync ready
|
|
225
|
+
*/
|
|
226
|
+
override fun syncReady(event: SyncReadyEvent) = prepareSyncReadyEvent(event)
|
|
227
|
+
|
|
218
228
|
/**
|
|
219
229
|
* Language updated
|
|
220
230
|
*/
|
|
@@ -225,7 +235,10 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
225
235
|
*/
|
|
226
236
|
override fun languageUpdateFailed(event: LanguageUpdateFailedEvent) = prepareEvent(EventTypes.LANGUAGE_UPDATE_FAILED.event, event.reason)
|
|
227
237
|
}
|
|
238
|
+
|
|
228
239
|
private val vendorStatusListeners: MutableSet<String> = mutableSetOf()
|
|
240
|
+
private val syncAcknowledgedCallbacks: MutableMap<Int, () -> Boolean> = mutableMapOf()
|
|
241
|
+
private var syncAcknowledgedCallbackIndex = 0
|
|
229
242
|
|
|
230
243
|
override fun getName() = "Didomi"
|
|
231
244
|
|
|
@@ -253,7 +266,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
253
266
|
val set = mutableSetOf<String>()
|
|
254
267
|
|
|
255
268
|
for (i in 0 until size()) {
|
|
256
|
-
set.add(getString(i)
|
|
269
|
+
set.add(getString(i))
|
|
257
270
|
}
|
|
258
271
|
|
|
259
272
|
return set
|
|
@@ -315,6 +328,8 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
315
328
|
noticeId: String?,
|
|
316
329
|
androidTvNoticeId: String?,
|
|
317
330
|
androidTvEnabled: Boolean,
|
|
331
|
+
countryCode: String?,
|
|
332
|
+
regionCode: String?,
|
|
318
333
|
promise: Promise
|
|
319
334
|
) {
|
|
320
335
|
try {
|
|
@@ -331,7 +346,9 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
331
346
|
languageCode,
|
|
332
347
|
noticeId,
|
|
333
348
|
androidTvNoticeId,
|
|
334
|
-
androidTvEnabled
|
|
349
|
+
androidTvEnabled,
|
|
350
|
+
countryCode,
|
|
351
|
+
regionCode
|
|
335
352
|
)
|
|
336
353
|
|
|
337
354
|
val application = currentActivity?.application ?: throw IllegalStateException("No activity present")
|
|
@@ -607,6 +624,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
607
624
|
}
|
|
608
625
|
|
|
609
626
|
@ReactMethod
|
|
627
|
+
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
610
628
|
fun setUserWithHashAuth(
|
|
611
629
|
organizationUserId: String,
|
|
612
630
|
algorithm: String,
|
|
@@ -628,6 +646,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
628
646
|
}
|
|
629
647
|
|
|
630
648
|
@ReactMethod
|
|
649
|
+
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
631
650
|
fun setUserWithHashAuthAndSetupUI(
|
|
632
651
|
organizationUserId: String,
|
|
633
652
|
algorithm: String,
|
|
@@ -637,19 +656,20 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
637
656
|
promise: Promise
|
|
638
657
|
) {
|
|
639
658
|
Didomi.getInstance().setUser(
|
|
640
|
-
UserAuthWithHashParams(
|
|
659
|
+
userAuthParams = UserAuthWithHashParams(
|
|
641
660
|
organizationUserId,
|
|
642
661
|
algorithm,
|
|
643
662
|
secretId,
|
|
644
663
|
digest,
|
|
645
664
|
salt
|
|
646
665
|
),
|
|
647
|
-
currentActivity as? FragmentActivity
|
|
666
|
+
activity = currentActivity as? FragmentActivity
|
|
648
667
|
)
|
|
649
668
|
promise.resolve(0)
|
|
650
669
|
}
|
|
651
670
|
|
|
652
671
|
@ReactMethod
|
|
672
|
+
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
653
673
|
fun setUserWithHashAuthWithExpiration(
|
|
654
674
|
organizationUserId: String,
|
|
655
675
|
algorithm: String,
|
|
@@ -673,6 +693,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
673
693
|
}
|
|
674
694
|
|
|
675
695
|
@ReactMethod
|
|
696
|
+
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
676
697
|
fun setUserWithHashAuthWithExpirationAndSetupUI(
|
|
677
698
|
organizationUserId: String,
|
|
678
699
|
algorithm: String,
|
|
@@ -683,7 +704,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
683
704
|
promise: Promise
|
|
684
705
|
) {
|
|
685
706
|
Didomi.getInstance().setUser(
|
|
686
|
-
UserAuthWithHashParams(
|
|
707
|
+
userAuthParams = UserAuthWithHashParams(
|
|
687
708
|
organizationUserId,
|
|
688
709
|
algorithm,
|
|
689
710
|
secretId,
|
|
@@ -691,12 +712,13 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
691
712
|
salt,
|
|
692
713
|
expiration.toLong()
|
|
693
714
|
),
|
|
694
|
-
currentActivity as? FragmentActivity
|
|
715
|
+
activity = currentActivity as? FragmentActivity
|
|
695
716
|
)
|
|
696
717
|
promise.resolve(0)
|
|
697
718
|
}
|
|
698
719
|
|
|
699
720
|
@ReactMethod
|
|
721
|
+
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
700
722
|
fun setUserWithEncryptionAuth(
|
|
701
723
|
organizationUserId: String,
|
|
702
724
|
algorithm: String,
|
|
@@ -716,6 +738,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
716
738
|
}
|
|
717
739
|
|
|
718
740
|
@ReactMethod
|
|
741
|
+
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
719
742
|
fun setUserWithEncryptionAuthAndSetupUI(
|
|
720
743
|
organizationUserId: String,
|
|
721
744
|
algorithm: String,
|
|
@@ -724,18 +747,19 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
724
747
|
promise: Promise
|
|
725
748
|
) {
|
|
726
749
|
Didomi.getInstance().setUser(
|
|
727
|
-
UserAuthWithEncryptionParams(
|
|
750
|
+
userAuthParams = UserAuthWithEncryptionParams(
|
|
728
751
|
organizationUserId,
|
|
729
752
|
algorithm,
|
|
730
753
|
secretId,
|
|
731
754
|
initializationVector
|
|
732
755
|
),
|
|
733
|
-
currentActivity as? FragmentActivity
|
|
756
|
+
activity = currentActivity as? FragmentActivity
|
|
734
757
|
)
|
|
735
758
|
promise.resolve(0)
|
|
736
759
|
}
|
|
737
760
|
|
|
738
761
|
@ReactMethod
|
|
762
|
+
@Deprecated("Use setUserWithAuthParams instead", replaceWith = ReplaceWith("setUserWithAuthParams()"))
|
|
739
763
|
fun setUserWithEncryptionAuthWithExpiration(
|
|
740
764
|
organizationUserId: String,
|
|
741
765
|
algorithm: String,
|
|
@@ -757,6 +781,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
757
781
|
}
|
|
758
782
|
|
|
759
783
|
@ReactMethod
|
|
784
|
+
@Deprecated("Use setUserWithAuthParamsAndSetupUI instead", replaceWith = ReplaceWith("setUserWithAuthParamsAndSetupUI()"))
|
|
760
785
|
fun setUserWithEncryptionAuthWithExpirationAndSetupUI(
|
|
761
786
|
organizationUserId: String,
|
|
762
787
|
algorithm: String,
|
|
@@ -766,18 +791,73 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
766
791
|
promise: Promise
|
|
767
792
|
) {
|
|
768
793
|
Didomi.getInstance().setUser(
|
|
769
|
-
UserAuthWithEncryptionParams(
|
|
794
|
+
userAuthParams = UserAuthWithEncryptionParams(
|
|
770
795
|
organizationUserId,
|
|
771
796
|
algorithm,
|
|
772
797
|
secretId,
|
|
773
798
|
initializationVector,
|
|
774
799
|
expiration.toLong()
|
|
775
800
|
),
|
|
776
|
-
currentActivity as? FragmentActivity
|
|
801
|
+
activity = currentActivity as? FragmentActivity
|
|
777
802
|
)
|
|
778
803
|
promise.resolve(0)
|
|
779
804
|
}
|
|
780
805
|
|
|
806
|
+
@ReactMethod
|
|
807
|
+
fun setUserWithAuthParams(
|
|
808
|
+
jsonUserAuthParams: String,
|
|
809
|
+
jsonSynchronizedUsers: String?,
|
|
810
|
+
promise: Promise
|
|
811
|
+
) {
|
|
812
|
+
try {
|
|
813
|
+
val userAuthParams = buildUserAuthParams(JSONObject(jsonUserAuthParams))
|
|
814
|
+
|
|
815
|
+
val synchronizedUsers = jsonSynchronizedUsers?.let {
|
|
816
|
+
JSONArray(it).run {
|
|
817
|
+
List(length()) { i -> buildUserAuthParams(getJSONObject(i)) }
|
|
818
|
+
}
|
|
819
|
+
} ?: emptyList()
|
|
820
|
+
|
|
821
|
+
Didomi.getInstance().setUser(
|
|
822
|
+
userAuthParams = userAuthParams,
|
|
823
|
+
synchronizedUsers = synchronizedUsers,
|
|
824
|
+
)
|
|
825
|
+
|
|
826
|
+
promise.resolve(0)
|
|
827
|
+
} catch (e: JSONException) {
|
|
828
|
+
Log.e("setUserWithAuthParams", "Error while parsing user with auth params", e)
|
|
829
|
+
promise.reject(e)
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
@ReactMethod
|
|
834
|
+
fun setUserWithAuthParamsAndSetupUI(
|
|
835
|
+
jsonUserAuthParams: String,
|
|
836
|
+
jsonSynchronizedUsers: String?,
|
|
837
|
+
promise: Promise
|
|
838
|
+
) {
|
|
839
|
+
try {
|
|
840
|
+
val userAuthParams = buildUserAuthParams(JSONObject(jsonUserAuthParams))
|
|
841
|
+
|
|
842
|
+
val synchronizedUsers = jsonSynchronizedUsers?.let {
|
|
843
|
+
JSONArray(it).run {
|
|
844
|
+
List(length()) { i -> buildUserAuthParams(getJSONObject(i)) }
|
|
845
|
+
}
|
|
846
|
+
} ?: emptyList()
|
|
847
|
+
|
|
848
|
+
Didomi.getInstance().setUser(
|
|
849
|
+
userAuthParams = userAuthParams,
|
|
850
|
+
synchronizedUsers = synchronizedUsers,
|
|
851
|
+
activity = currentActivity as? FragmentActivity,
|
|
852
|
+
)
|
|
853
|
+
|
|
854
|
+
promise.resolve(0)
|
|
855
|
+
} catch (e: JSONException) {
|
|
856
|
+
Log.e("setUserWithAuthParams", "Error while parsing user with auth params", e)
|
|
857
|
+
promise.reject(e)
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
781
861
|
@ReactMethod
|
|
782
862
|
fun showNotice(promise: Promise) {
|
|
783
863
|
try {
|
|
@@ -968,6 +1048,23 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
968
1048
|
promise.resolve(transaction.commit())
|
|
969
1049
|
}
|
|
970
1050
|
|
|
1051
|
+
@ReactMethod
|
|
1052
|
+
fun syncAcknowledged(callbackIndex: Int, promise: Promise) {
|
|
1053
|
+
val result = syncAcknowledgedCallbacks[callbackIndex]?.let { it() }
|
|
1054
|
+
syncAcknowledgedCallbacks.remove(callbackIndex)
|
|
1055
|
+
if (result != null) {
|
|
1056
|
+
promise.resolve(result)
|
|
1057
|
+
} else {
|
|
1058
|
+
promise.reject(java.lang.IllegalStateException("SyncAcknowledged: Native callback not found. The method can be called only once."))
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
@ReactMethod
|
|
1063
|
+
fun removeSyncAcknowledgedCallback(callbackIndex: Int, promise: Promise) {
|
|
1064
|
+
syncAcknowledgedCallbacks.remove(callbackIndex)
|
|
1065
|
+
promise.resolve(0)
|
|
1066
|
+
}
|
|
1067
|
+
|
|
971
1068
|
private fun prepareEvent(eventName: String, params: Any?) {
|
|
972
1069
|
Log.d("prepareEvent", "Sending $eventName")
|
|
973
1070
|
reactContext
|
|
@@ -975,8 +1072,53 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
975
1072
|
.emit(eventName, params)
|
|
976
1073
|
}
|
|
977
1074
|
|
|
1075
|
+
private fun prepareSyncReadyEvent(event: SyncReadyEvent) {
|
|
1076
|
+
val eventName = EventTypes.SYNC_READY.event
|
|
1077
|
+
Log.d("prepareEvent", "Sending $eventName")
|
|
1078
|
+
val callbackIndex = syncAcknowledgedCallbackIndex++
|
|
1079
|
+
syncAcknowledgedCallbacks[callbackIndex] = event.syncAcknowledged
|
|
1080
|
+
val params = WritableNativeMap().apply {
|
|
1081
|
+
putBoolean("statusApplied", event.statusApplied)
|
|
1082
|
+
putInt("syncAcknowledgedIndex", callbackIndex)
|
|
1083
|
+
}
|
|
1084
|
+
reactContext
|
|
1085
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
1086
|
+
.emit(eventName, params)
|
|
1087
|
+
}
|
|
1088
|
+
|
|
978
1089
|
// Required to transform from array to variadic.
|
|
979
1090
|
private fun readableArrayToStringArray(readableArray: ReadableArray): Array<String> {
|
|
980
|
-
return Array(readableArray.size()) { i -> readableArray.getString(i)
|
|
1091
|
+
return Array(readableArray.size()) { i -> readableArray.getString(i) }
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
private fun buildUserAuthParams(jsonParameters: JSONObject): UserAuthParams {
|
|
1095
|
+
|
|
1096
|
+
val id = jsonParameters.getString("id")
|
|
1097
|
+
val algorithm = jsonParameters.getString("algorithm")
|
|
1098
|
+
val secretId = jsonParameters.getString("secretId")
|
|
1099
|
+
|
|
1100
|
+
return if (jsonParameters.has("initializationVector")) {
|
|
1101
|
+
val expiration = if (jsonParameters.has("expiration")) jsonParameters.getLong("expiration") else null
|
|
1102
|
+
val initializationVector = jsonParameters.getString("initializationVector")
|
|
1103
|
+
UserAuthWithEncryptionParams(
|
|
1104
|
+
id = id,
|
|
1105
|
+
algorithm = algorithm,
|
|
1106
|
+
secretId = secretId,
|
|
1107
|
+
initializationVector = initializationVector,
|
|
1108
|
+
expiration = expiration
|
|
1109
|
+
)
|
|
1110
|
+
} else {
|
|
1111
|
+
val expiration = if (jsonParameters.has("expiration")) jsonParameters.getLong("expiration") else null
|
|
1112
|
+
val digest = jsonParameters.getString("digest")
|
|
1113
|
+
val salt = if (jsonParameters.has("salt")) jsonParameters.getString("salt") else null
|
|
1114
|
+
UserAuthWithHashParams(
|
|
1115
|
+
id = id,
|
|
1116
|
+
algorithm = algorithm,
|
|
1117
|
+
secretId = secretId,
|
|
1118
|
+
digest = digest,
|
|
1119
|
+
salt = salt,
|
|
1120
|
+
expiration = expiration
|
|
1121
|
+
)
|
|
1122
|
+
}
|
|
981
1123
|
}
|
|
982
1124
|
}
|
|
@@ -49,6 +49,7 @@ enum class EventTypes(val event: String) {
|
|
|
49
49
|
PREFERENCES_CLICK_SPI_PURPOSE_SAVE_CHOICES("on_preferences_click_spi_purpose_save_choices"),
|
|
50
50
|
// Sync
|
|
51
51
|
SYNC_DONE("on_sync_done"),
|
|
52
|
+
SYNC_READY("on_sync_ready"),
|
|
52
53
|
SYNC_ERROR("on_sync_error"),
|
|
53
54
|
// Language
|
|
54
55
|
LANGUAGE_UPDATED("on_language_updated"),
|
package/ios/Didomi.m
CHANGED
|
@@ -14,6 +14,8 @@ RCT_EXTERN_METHOD(initialize:(NSString *)userAgentName
|
|
|
14
14
|
noticeId:(nullable NSString *)noticeId
|
|
15
15
|
androidTvNoticeId:(nullable NSString *)androidTvNoticeId
|
|
16
16
|
androidTvEnabled:(BOOL)androidTvEnabled
|
|
17
|
+
countryCode:(nullable NSString *)countryCode
|
|
18
|
+
regionCode:(nullable NSString *)regionCode
|
|
17
19
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
18
20
|
reject:(RCTPromiseRejectBlock)reject)
|
|
19
21
|
|
|
@@ -79,16 +81,6 @@ RCT_EXTERN_METHOD(setUserAgreeToAll:(RCTPromiseResolveBlock)resolve
|
|
|
79
81
|
RCT_EXTERN_METHOD(setUserDisagreeToAll:(RCTPromiseResolveBlock)resolve
|
|
80
82
|
reject:(RCTPromiseRejectBlock)reject)
|
|
81
83
|
|
|
82
|
-
// @objc(onReady:)
|
|
83
|
-
// func onReady(callback: @escaping RCTResponseSenderBlock) {
|
|
84
|
-
// Didomi.shared.onReady(callback: callback)
|
|
85
|
-
// }
|
|
86
|
-
|
|
87
|
-
// @objc(onError:)
|
|
88
|
-
// func onError(callback: @escaping (Didomi.DidomiErrorEvent)) {
|
|
89
|
-
// Didomi.shared.onError(callback: callback)
|
|
90
|
-
// }
|
|
91
|
-
|
|
92
84
|
RCT_EXTERN_METHOD(reset:(RCTPromiseResolveBlock)resolve
|
|
93
85
|
reject:(RCTPromiseRejectBlock)reject)
|
|
94
86
|
|
|
@@ -242,6 +234,16 @@ RCT_EXTERN_METHOD(setUserWithEncryptionAuthWithExpirationAndSetupUI:(NSString *)
|
|
|
242
234
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
243
235
|
reject:(RCTPromiseRejectBlock)reject)
|
|
244
236
|
|
|
237
|
+
RCT_EXTERN_METHOD(setUserWithAuthParams:(NSString *)jsonUserAuthParams
|
|
238
|
+
jsonSynchronizedUsers:(NSString)jsonSynchronizedUsers
|
|
239
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
240
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
241
|
+
|
|
242
|
+
RCT_EXTERN_METHOD(setUserWithAuthParamsAndSetupUI:(NSString *)jsonUserAuthParams
|
|
243
|
+
jsonSynchronizedUsers:(NSString)jsonSynchronizedUsers
|
|
244
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
245
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
246
|
+
|
|
245
247
|
RCT_EXTERN_METHOD(listenToVendorStatus:(NSString *)vendorId
|
|
246
248
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
247
249
|
reject:(RCTPromiseRejectBlock)reject)
|
|
@@ -257,6 +259,14 @@ RCT_EXTERN_METHOD(commitCurrentUserStatusTransaction:(NSArray<NSString *> *)enab
|
|
|
257
259
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
258
260
|
reject:(RCTPromiseRejectBlock)reject)
|
|
259
261
|
|
|
262
|
+
RCT_EXTERN_METHOD(syncAcknowledged:(int)callbackIndex
|
|
263
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
264
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
265
|
+
|
|
266
|
+
RCT_EXTERN_METHOD(removeSyncAcknowledgedCallback:(int)callbackIndex
|
|
267
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
268
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
269
|
+
|
|
260
270
|
RCT_EXTERN_METHOD(supportedEvents)
|
|
261
271
|
|
|
262
272
|
@end
|
package/ios/RNDidomi.swift
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import Didomi
|
|
2
2
|
import AdSupport
|
|
3
3
|
import AppTrackingTransparency
|
|
4
|
+
import Foundation
|
|
4
5
|
|
|
5
6
|
@objc(Didomi)
|
|
6
7
|
class RNDidomi: RCTEventEmitter {
|
|
7
8
|
|
|
8
9
|
var didomiEventListener: EventListener
|
|
9
10
|
var vendorStatusListeners: Set<String> = Set()
|
|
11
|
+
var syncAcknowledgedCallbacks: Dictionary<Int, (() -> Bool)> = [:]
|
|
12
|
+
private var syncAcknowledgedCallbackIndex: Int = 0
|
|
10
13
|
|
|
11
14
|
override init() {
|
|
12
15
|
didomiEventListener = EventListener()
|
|
@@ -18,8 +21,8 @@ class RNDidomi: RCTEventEmitter {
|
|
|
18
21
|
return true
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
@objc(initialize:userAgentVersion:apiKey:localConfigurationPath:remoteConfigurationURL:providerId:disableDidomiRemoteConfig:languageCode:noticeId:androidTvNoticeId:androidTvEnabled:resolve:reject:)
|
|
22
|
-
func initialize(userAgentName: String, userAgentVersion: String, apiKey: String, localConfigurationPath: String?, remoteConfigurationURL: String?, providerId: String?, disableDidomiRemoteConfig: Bool = false, languageCode: String? = nil, noticeId: String? = nil, androidTvNoticeId: String? = nil, androidTvEnabled: Bool = false, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
24
|
+
@objc(initialize:userAgentVersion:apiKey:localConfigurationPath:remoteConfigurationURL:providerId:disableDidomiRemoteConfig:languageCode:noticeId:androidTvNoticeId:androidTvEnabled:countryCode:regionCode:resolve:reject:)
|
|
25
|
+
func initialize(userAgentName: String, userAgentVersion: String, apiKey: String, localConfigurationPath: String?, remoteConfigurationURL: String?, providerId: String?, disableDidomiRemoteConfig: Bool = false, languageCode: String? = nil, noticeId: String? = nil, androidTvNoticeId: String? = nil, androidTvEnabled: Bool = false, countryCode: String? = nil, regionCode: String? = nil, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
23
26
|
Didomi.shared.setUserAgent(name: userAgentName, version: userAgentVersion)
|
|
24
27
|
|
|
25
28
|
Didomi.shared.initialize(DidomiInitializeParameters(
|
|
@@ -29,7 +32,9 @@ class RNDidomi: RCTEventEmitter {
|
|
|
29
32
|
providerID: providerId,
|
|
30
33
|
disableDidomiRemoteConfig: disableDidomiRemoteConfig,
|
|
31
34
|
languageCode: languageCode ?? Locale.current.languageCode ?? "",
|
|
32
|
-
noticeID: noticeId
|
|
35
|
+
noticeID: noticeId,
|
|
36
|
+
countryCode: countryCode,
|
|
37
|
+
regionCode: regionCode
|
|
33
38
|
))
|
|
34
39
|
|
|
35
40
|
resolve(0)
|
|
@@ -475,6 +480,48 @@ class RNDidomi: RCTEventEmitter {
|
|
|
475
480
|
}
|
|
476
481
|
resolve(0)
|
|
477
482
|
}
|
|
483
|
+
|
|
484
|
+
@objc(setUserWithAuthParams:jsonSynchronizedUsers:resolve:reject:)
|
|
485
|
+
dynamic func setUserWithAuthParams(jsonUserAuthParams: String, jsonSynchronizedUsers: String?, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
486
|
+
do {
|
|
487
|
+
let userAuthParams = try buildUserAuthParams(from: jsonUserAuthParams)
|
|
488
|
+
let synchronizedUsers = try jsonSynchronizedUsers.flatMap { try buildUserAuthParamsArray(from: $0) } ?? []
|
|
489
|
+
|
|
490
|
+
Didomi.shared.setUser(
|
|
491
|
+
userAuthParams: userAuthParams,
|
|
492
|
+
synchronizedUsers: synchronizedUsers
|
|
493
|
+
)
|
|
494
|
+
resolve(0)
|
|
495
|
+
} catch {
|
|
496
|
+
reject("Error", "Error while setting user with auth params", error)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
@objc(setUserWithAuthParamsAndSetupUI:jsonSynchronizedUsers:resolve:reject:)
|
|
501
|
+
dynamic func setUserWithAuthParamsAndSetupUI(jsonUserAuthParams: String, jsonSynchronizedUsers: String?, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
502
|
+
do {
|
|
503
|
+
let userAuthParams = try buildUserAuthParams(from: jsonUserAuthParams)
|
|
504
|
+
let synchronizedUsers = try jsonSynchronizedUsers.flatMap { try buildUserAuthParamsArray(from: $0) } ?? []
|
|
505
|
+
|
|
506
|
+
DispatchQueue.main.async {
|
|
507
|
+
if let containerController = RCTPresentedViewController() {
|
|
508
|
+
Didomi.shared.setUser(
|
|
509
|
+
userAuthParams: userAuthParams,
|
|
510
|
+
synchronizedUsers: synchronizedUsers,
|
|
511
|
+
containerController: containerController
|
|
512
|
+
)
|
|
513
|
+
} else {
|
|
514
|
+
Didomi.shared.setUser(
|
|
515
|
+
userAuthParams: userAuthParams,
|
|
516
|
+
synchronizedUsers: synchronizedUsers
|
|
517
|
+
)
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
resolve(0)
|
|
521
|
+
} catch {
|
|
522
|
+
reject("Error", "Error while setting user with auth params", error)
|
|
523
|
+
}
|
|
524
|
+
}
|
|
478
525
|
|
|
479
526
|
@objc(listenToVendorStatus:resolve:reject:)
|
|
480
527
|
dynamic func listenToVendorStatus(vendorId: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
@@ -513,7 +560,31 @@ class RNDidomi: RCTEventEmitter {
|
|
|
513
560
|
transaction.enableVendors(enabledVendors)
|
|
514
561
|
transaction.disableVendors(disabledVendors)
|
|
515
562
|
resolve(transaction.commit())
|
|
516
|
-
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
@objc(syncAcknowledged:resolve:reject:)
|
|
566
|
+
dynamic func syncAcknowledged(
|
|
567
|
+
callbackIndex: Int,
|
|
568
|
+
resolve:RCTPromiseResolveBlock,
|
|
569
|
+
reject:RCTPromiseRejectBlock
|
|
570
|
+
) {
|
|
571
|
+
if let callback = syncAcknowledgedCallbacks[callbackIndex] {
|
|
572
|
+
syncAcknowledgedCallbacks.removeValue(forKey: callbackIndex)
|
|
573
|
+
resolve(callback())
|
|
574
|
+
} else {
|
|
575
|
+
reject("not_found", "SyncAcknowledged: Native callback not found. The method can be called only once.", NSError.init(domain: "Didomi", code: 404))
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
@objc(removeSyncAcknowledgedCallback:resolve:reject:)
|
|
580
|
+
dynamic func removeSyncAcknowledgedCallback(
|
|
581
|
+
callbackIndex: Int,
|
|
582
|
+
resolve:RCTPromiseResolveBlock,
|
|
583
|
+
reject:RCTPromiseRejectBlock
|
|
584
|
+
) {
|
|
585
|
+
syncAcknowledgedCallbacks.removeValue(forKey: callbackIndex)
|
|
586
|
+
resolve(0)
|
|
587
|
+
}
|
|
517
588
|
}
|
|
518
589
|
|
|
519
590
|
// MARK: Didomi Specific structs
|
|
@@ -588,6 +659,7 @@ extension RNDidomi {
|
|
|
588
659
|
"on_preferences_click_spi_purpose_save_choices",
|
|
589
660
|
// Sync
|
|
590
661
|
"on_sync_done",
|
|
662
|
+
"on_sync_ready",
|
|
591
663
|
"on_sync_error",
|
|
592
664
|
// Language
|
|
593
665
|
"on_language_updated",
|
|
@@ -748,6 +820,17 @@ extension RNDidomi {
|
|
|
748
820
|
didomiEventListener.onSyncDone = { [weak self] event, organizationUserId in
|
|
749
821
|
self?.dispatchEvent(withName: "on_sync_done", body: organizationUserId)
|
|
750
822
|
}
|
|
823
|
+
|
|
824
|
+
didomiEventListener.onSyncReady = { [weak self] event in
|
|
825
|
+
let callbackIndex = self?.syncAcknowledgedCallbackIndex ?? -1
|
|
826
|
+
self?.syncAcknowledgedCallbackIndex += 1
|
|
827
|
+
self?.syncAcknowledgedCallbacks[callbackIndex] = event.syncAcknowledged
|
|
828
|
+
let result = [
|
|
829
|
+
"statusApplied": event.statusApplied,
|
|
830
|
+
"syncAcknowledgedIndex": callbackIndex
|
|
831
|
+
]
|
|
832
|
+
self?.dispatchEvent(withName: "on_sync_ready", body: result)
|
|
833
|
+
}
|
|
751
834
|
|
|
752
835
|
didomiEventListener.onSyncError = { [weak self] event, error in
|
|
753
836
|
self?.dispatchEvent(withName: "on_sync_error", body: error)
|
|
@@ -773,6 +856,75 @@ extension RNDidomi {
|
|
|
773
856
|
Didomi.shared.removeEventListener(listener: didomiEventListener)
|
|
774
857
|
}
|
|
775
858
|
}
|
|
859
|
+
|
|
860
|
+
/// Build the user auth params from the JSON parameters
|
|
861
|
+
private func buildUserAuthParams(from jsonString: String) throws -> UserAuthParams {
|
|
862
|
+
let data = jsonString.data(using: .utf8)!
|
|
863
|
+
let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
|
|
864
|
+
|
|
865
|
+
guard let id = json["id"] as? String,
|
|
866
|
+
let algorithm = json["algorithm"] as? String,
|
|
867
|
+
let secretID = json["secretId"] as? String else {
|
|
868
|
+
fatalError("Missing required parameters")
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
let expiration = json["expiration"] as? CLong
|
|
872
|
+
let initializationVector = json["initializationVector"] as? String
|
|
873
|
+
let digest = json["digest"] as? String
|
|
874
|
+
let salt = json["salt"] as? String
|
|
875
|
+
|
|
876
|
+
if let initializationVector = initializationVector {
|
|
877
|
+
if let expiration = expiration {
|
|
878
|
+
return UserAuthWithEncryptionParams(
|
|
879
|
+
id: id,
|
|
880
|
+
algorithm: algorithm,
|
|
881
|
+
secretID: secretID,
|
|
882
|
+
initializationVector: initializationVector,
|
|
883
|
+
legacyExpiration: Double(expiration)
|
|
884
|
+
)
|
|
885
|
+
} else {
|
|
886
|
+
return UserAuthWithEncryptionParams(
|
|
887
|
+
id: id,
|
|
888
|
+
algorithm: algorithm,
|
|
889
|
+
secretID: secretID,
|
|
890
|
+
initializationVector: initializationVector
|
|
891
|
+
)
|
|
892
|
+
}
|
|
893
|
+
} else {
|
|
894
|
+
guard let digest = digest else {
|
|
895
|
+
fatalError("Missing required digest parameter")
|
|
896
|
+
}
|
|
897
|
+
if let expiration = expiration {
|
|
898
|
+
return UserAuthWithHashParams(
|
|
899
|
+
id: id,
|
|
900
|
+
algorithm: algorithm,
|
|
901
|
+
secretID: secretID,
|
|
902
|
+
digest: digest,
|
|
903
|
+
salt: salt,
|
|
904
|
+
legacyExpiration: Double(expiration)
|
|
905
|
+
)
|
|
906
|
+
} else {
|
|
907
|
+
return UserAuthWithHashParams(
|
|
908
|
+
id: id,
|
|
909
|
+
algorithm: algorithm,
|
|
910
|
+
secretID: secretID,
|
|
911
|
+
digest: digest,
|
|
912
|
+
salt: salt
|
|
913
|
+
)
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/// Build the user auth params list from the JSON parameters
|
|
919
|
+
private func buildUserAuthParamsArray(from jsonString: String) throws -> [UserAuthParams] {
|
|
920
|
+
let jsonData = jsonString.data(using: .utf8)!
|
|
921
|
+
let jsonArray = try JSONSerialization.jsonObject(with: jsonData, options: []) as! [[String: Any]]
|
|
922
|
+
return try jsonArray.map { dictionary in
|
|
923
|
+
let jsonData = try JSONSerialization.data(withJSONObject: dictionary, options: [])
|
|
924
|
+
let jsonString = String(data: jsonData, encoding: .utf8)!
|
|
925
|
+
return try buildUserAuthParams(from: jsonString)
|
|
926
|
+
}
|
|
927
|
+
}
|
|
776
928
|
}
|
|
777
929
|
|
|
778
930
|
extension Int {
|
|
@@ -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.4.0";
|
|
11
11
|
//# sourceMappingURL=Constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DIDOMI_USER_AGENT_NAME","exports","DIDOMI_VERSION"],"sources":["Constants.ts"],"sourcesContent":["// User agent name\nexport const DIDOMI_USER_AGENT_NAME = \"Didomi React-Native SDK\"\n// User agent version\nexport const DIDOMI_VERSION = \"2.
|
|
1
|
+
{"version":3,"names":["DIDOMI_USER_AGENT_NAME","exports","DIDOMI_VERSION"],"sources":["Constants.ts"],"sourcesContent":["// User agent name\nexport const DIDOMI_USER_AGENT_NAME = \"Didomi React-Native SDK\"\n// User agent version\nexport const DIDOMI_VERSION = \"2.4.0\"\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,yBAAyB;AAC/D;AACO,MAAME,cAAc,GAAAD,OAAA,CAAAC,cAAA,GAAG,OAAO","ignoreList":[]}
|