@didomi/react-native 1.0.0 → 1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Didomi React Native
2
2
 
3
- Didomi is a leading Consent Management Platform that allows companies to collect, store, and leverage user consent under GDPR, CCPA, and other data privacy regulations. This plugin enables Flutter developers to get in compliance and optimize their consent rate and monetization on native mobile apps.
3
+ Didomi is a leading Consent Management Platform that allows companies to collect, store, and leverage user consent under GDPR, CCPA, and other data privacy regulations. This plugin enables React Native developers to get in compliance and optimize their consent rate and monetization on native mobile apps.
4
4
 
5
5
  This repository contains the source code and a sample app for the Didomi React Native plugin. This plugin enables React Native developers to easily use Didomi's Consent Management Platform on Android and iOS apps.
6
6
 
@@ -18,12 +18,26 @@ As Didomi requires Swift runtime for iOS, you may need to add an empty Swift fil
18
18
 
19
19
  ```js
20
20
  import { Didomi, DidomiEventType } from '@didomi/react-native';
21
+ import { useEffect } from 'react';
21
22
 
22
23
  // ...
24
+ function App() {
25
+ useEffect(() => {
26
+ // Initialize and setup UI
27
+ // The initialize function need to be called only once and as early as possible to give time for the SDK initialization
28
+ Didomi.initialize('YOUR_API_KEY', undefined, undefined, undefined, false, undefined, 'YOUR_NOTICE_ID');
29
+
30
+ // The setupUI displays the popup and is only available once the SDK sent the onReady events
31
+ Didomi.setupUI();
32
+ }, [])
33
+ return (
34
+ <SafeAreaView style={{ flex: 1 }}>
35
+ // ...
36
+ </SafeAreaView>
37
+ );
38
+ }
23
39
 
24
- // Initialize and setup UI
25
- Didomi.initialize('YOUR_API_KEY', undefined, undefined, undefined, true, undefined, 'YOUR_NOTICE_ID');
26
- Didomi.setupUI();
40
+ //...
27
41
 
28
42
  // Retrieve data
29
43
  const purposes = await Didomi.getEnabledPurposes();
@@ -40,7 +54,7 @@ Didomi.addEventListener(DidomiEventType.SHOW_NOTICE, () => {
40
54
 
41
55
  ```
42
56
 
43
- For a complete overview of available methods and events, have a look at the [online documentation](https://developers.didomi.io/cmp/react-native).
57
+ For a complete overview of available methods and events, have a look at the [online documentation](https://developers.didomi.io/cmp/mobile-sdk/react-native).
44
58
 
45
59
  ## Configuration with local file
46
60
 
@@ -49,7 +63,7 @@ In case you need to use a local configuration. The ``didomi_config.json`` must b
49
63
 
50
64
  On iOS, drag and drop the file to Xcode files.
51
65
 
52
- On Android, copy it to the ``src/main/assets` folder.
66
+ On Android, copy it to the ``src/main/assets`` folder.
53
67
 
54
68
  ## Documentation
55
69
 
@@ -61,13 +75,13 @@ For complete instructions on installing and using the plugin, please read our do
61
75
 
62
76
  ## Example applications
63
77
 
64
- Sources contain 2 applications: ``/example`` (an app designed mostly for UI testing ) and ``/example2`` (more human friendly app).
78
+ Sources contain 2 applications: ``/testApp`` (an app designed mostly for UI testing ) and ``/sampleApp`` (more human friendly app).
65
79
 
66
80
  They can be run with:
67
81
 
68
82
  ```bash
69
- # example or example2
70
- cd example
83
+ # testApp or sampleApp
84
+ cd testApp
71
85
  cd ios && pod install
72
86
  yarn ios
73
87
  # or yarn android
@@ -34,6 +34,8 @@ android {
34
34
  versionCode 1
35
35
  versionName "1.0"
36
36
 
37
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
38
+ multiDexEnabled = true
37
39
  }
38
40
 
39
41
  buildTypes {
@@ -128,5 +130,5 @@ dependencies {
128
130
  api "com.facebook.react:react-native:+"
129
131
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
130
132
 
131
- implementation "io.didomi.sdk:android:1.40.0"
133
+ implementation "io.didomi.sdk:android:1.54.0"
132
134
  }
@@ -36,12 +36,12 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
36
36
  override fun consentChanged(event: ConsentChangedEvent) = prepareEvent(EventTypes.CONSENT_CHANGED.event, null)
37
37
 
38
38
  /**
39
- * The notice is being hidden
39
+ * The notice screen is being hidden
40
40
  */
41
41
  override fun hideNotice(event: HideNoticeEvent) = prepareEvent(EventTypes.HIDE_NOTICE.event, null)
42
42
 
43
43
  /**
44
- * The notice is being shown
44
+ * The notice screen is being shown
45
45
  */
46
46
  override fun showNotice(event: ShowNoticeEvent) = prepareEvent(EventTypes.SHOW_NOTICE.event, null)
47
47
 
@@ -70,6 +70,16 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
70
70
  */
71
71
  override fun noticeClickPrivacyPolicy(event: NoticeClickPrivacyPolicyEvent) = prepareEvent(EventTypes.NOTICE_CLICK_PRIVACY_POLICY.event, null)
72
72
 
73
+ /**
74
+ * The preferences screen is being hidden
75
+ */
76
+ override fun hidePreferences(event: HidePreferencesEvent) = prepareEvent(EventTypes.HIDE_PREFERENCES.event, null)
77
+
78
+ /**
79
+ * The preferences screen is being shown
80
+ */
81
+ override fun showPreferences(event: ShowPreferencesEvent) = prepareEvent(EventTypes.SHOW_PREFERENCES.event, null)
82
+
73
83
  /**
74
84
  * Click on agree to all on preferences popup
75
85
  */
@@ -242,6 +252,10 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
242
252
  languageCode,
243
253
  noticeId
244
254
  )
255
+
256
+ Didomi.getInstance().onReady { prepareEvent(EventTypes.READY_CALLBACK.event, null) }
257
+ Didomi.getInstance().onError { prepareEvent(EventTypes.ERROR_CALLBACK.event, null) }
258
+
245
259
  promise.resolve(0)
246
260
 
247
261
  } catch (e: Exception) {
@@ -349,9 +363,14 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
349
363
  }
350
364
 
351
365
  @ReactMethod
352
- fun getJavaScriptForWebView(promise: Promise) {
366
+ fun getJavaScriptForWebView(extra: String?, promise: Promise) {
353
367
  try {
354
- promise.resolve(Didomi.getInstance().javaScriptForWebView)
368
+ extra?.let {
369
+ promise.resolve(Didomi.getInstance().getJavaScriptForWebView(extra))
370
+ } ?: run {
371
+ promise.resolve(Didomi.getInstance().getJavaScriptForWebView())
372
+ }
373
+
355
374
  } catch (e: DidomiNotReadyException) {
356
375
  promise.reject(e)
357
376
  }
@@ -490,6 +509,15 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
490
509
  }
491
510
  }
492
511
 
512
+ @ReactMethod
513
+ fun getUserStatus(promise: Promise) {
514
+ try {
515
+ promise.resolve(objectToWritableMap(Didomi.getInstance().getUserStatus()))
516
+ } catch (e: DidomiNotReadyException) {
517
+ promise.reject(e)
518
+ }
519
+ }
520
+
493
521
  @ReactMethod
494
522
  fun getUserStatusForVendor(vendorId: String, promise: Promise) {
495
523
  try {
@@ -743,6 +771,7 @@ class DidomiModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
743
771
  }
744
772
 
745
773
  private fun prepareEvent(eventName: String, params: String?) {
774
+ Log.d("prepareEvent", "Sending $eventName")
746
775
  reactContext
747
776
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
748
777
  .emit(eventName, params)
@@ -2,7 +2,9 @@ package com.reactnativedidomi
2
2
 
3
3
  enum class EventTypes(val event: String) {
4
4
  READY("on_ready"),
5
+ READY_CALLBACK("on_ready_callback"),
5
6
  ERROR("on_error"),
7
+ ERROR_CALLBACK("on_error_callback"),
6
8
  CONSENT_CHANGED("on_consent_changed"),
7
9
  HIDE_NOTICE("on_hide_notice"),
8
10
  SHOW_NOTICE("on_show_notice"),
@@ -11,6 +13,8 @@ enum class EventTypes(val event: String) {
11
13
  NOTICE_CLICK_MORE_INFO("on_notice_click_more_info"),
12
14
  NOTICE_CLICK_VIEW_VENDORS("on_notice_click_view_vendors"),
13
15
  NOTICE_CLICK_PRIVACY_POLICY("on_notice_click_privacy_policy"),
16
+ HIDE_PREFERENCES("on_hide_preferences"),
17
+ SHOW_PREFERENCES("on_show_preferences"),
14
18
  PREFERENCES_CLICK_AGREE_TO_ALL("on_preferences_click_agree_to_all"),
15
19
  PREFERENCES_CLICK_DISAGREE_TO_ALL("on_preferences_click_disagree_to_all"),
16
20
  PREFERENCES_CLICK_PURPOSE_AGREE("on_preferences_click_purpose_agree"),
package/ios/Didomi.m CHANGED
@@ -21,6 +21,13 @@ RCT_EXTERN_METHOD(initialize:(NSString *)apikey
21
21
  languageCode:(nullable NSString *)languageCode
22
22
  noticeId:(nullable NSString *)noticeId)
23
23
 
24
+ RCT_EXTERN_METHOD(onReady)
25
+
26
+ RCT_EXTERN_METHOD(onError)
27
+
28
+ RCT_EXTERN_METHOD(getQueryStringForWebView:(RCTPromiseResolveBlock)resolve
29
+ reject:(RCTPromiseRejectBlock)reject)
30
+
24
31
  RCT_EXTERN_METHOD(setUserAgent:(NSString *)name
25
32
  version:(NSString *)version)
26
33
 
@@ -45,6 +52,9 @@ RCT_EXTERN_METHOD(getUserLegitimateInterestStatusForPurpose:(NSString *)purposeI
45
52
  resolve:(RCTPromiseResolveBlock)resolve
46
53
  reject:(RCTPromiseRejectBlock)reject)
47
54
 
55
+ RCT_EXTERN_METHOD(getUserStatus:(RCTPromiseResolveBlock)resolve
56
+ reject:(RCTPromiseRejectBlock)reject)
57
+
48
58
  RCT_EXTERN_METHOD(getUserStatusForVendor:(NSString *)vendorId
49
59
  resolve:(RCTPromiseResolveBlock)resolve
50
60
  reject:(RCTPromiseRejectBlock)reject)
@@ -5,7 +5,7 @@ import AppTrackingTransparency
5
5
  @objc(Didomi)
6
6
  class RNDidomi: RCTEventEmitter {
7
7
 
8
- var initialized = false
8
+ public static var initialized = false
9
9
  let didomiEventListener = EventListener()
10
10
 
11
11
  override static func requiresMainQueueSetup() -> Bool {
@@ -14,12 +14,31 @@ class RNDidomi: RCTEventEmitter {
14
14
 
15
15
  @objc(initialize:localConfigurationPath:remoteConfigurationURL:providerId:disableDidomiRemoteConfig:languageCode:noticeId:)
16
16
  func initialize(apiKey: String, localConfigurationPath: String?, remoteConfigurationURL: String?, providerId: String?, disableDidomiRemoteConfig: Bool = false, languageCode: String? = nil, noticeId: String? = nil) {
17
- if !initialized {
17
+ onReady()
18
+ onError()
19
+ if !RNDidomi.initialized {
18
20
  initEventListener()
19
21
  let newLanguageCode = Locale.current.languageCode ?? ""
20
22
  Didomi.shared.initialize(apiKey: apiKey, localConfigurationPath: localConfigurationPath, remoteConfigurationURL: remoteConfigurationURL, providerId: providerId, disableDidomiRemoteConfig: disableDidomiRemoteConfig, languageCode: languageCode != nil ? languageCode : newLanguageCode, noticeId: noticeId)
21
23
  }
22
- initialized = true
24
+ RNDidomi.initialized = true
25
+ }
26
+
27
+ private func onReady() {
28
+ Didomi.shared.onReady {
29
+ self.sendEvent(withName: "on_ready_callback", body: nil)
30
+ }
31
+ }
32
+
33
+ private func onError() {
34
+ Didomi.shared.onError { error in
35
+ self.sendEvent(withName: "on_error_callback", body: error.descriptionText)
36
+ }
37
+ }
38
+
39
+ @objc(getQueryStringForWebView:reject:)
40
+ func getQueryStringForWebView(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
41
+ resolve(Didomi.shared.getQueryStringForWebView())
23
42
  }
24
43
 
25
44
  @objc(setUserAgent:version:)
@@ -50,43 +69,50 @@ class RNDidomi: RCTEventEmitter {
50
69
  @objc(getUserConsentStatusForPurpose:resolve:reject:)
51
70
  func getUserConsentStatusForPurpose(purposeId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
52
71
  let consentStatus = Didomi.shared.getUserConsentStatusForPurpose(purposeId: purposeId)
53
- resolve(consentStatus)
72
+ resolve(consentStatus.rawValue.consentStatusBool)
54
73
  }
55
74
 
56
75
  @objc(getUserLegitimateInterestStatusForPurpose:resolve:reject:)
57
76
  func getUserLegitimateInterestStatusForPurpose(purposeId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
58
77
  let consentStatus = Didomi.shared.getUserLegitimateInterestStatusForPurpose(purposeId: purposeId)
59
- resolve(consentStatus)
78
+ resolve(consentStatus.rawValue.consentStatusBool)
79
+ }
80
+
81
+ @objc(getUserStatus:reject:)
82
+ func getUserStatus(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
83
+ let encoder = JSONEncoder()
84
+ let userStatus = try? JSONSerialization.jsonObject(with: encoder.encode(Didomi.shared.getUserStatus())) as? [String: Any]
85
+ resolve(userStatus)
60
86
  }
61
87
 
62
88
  @objc(getUserStatusForVendor:resolve:reject:)
63
89
  func getUserStatusForVendor(vendorId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
64
90
  let userStatus = Didomi.shared.getUserStatusForVendor(vendorId: vendorId)
65
- resolve(userStatus)
91
+ resolve(userStatus.rawValue.consentStatusBool)
66
92
  }
67
93
 
68
94
  @objc(getUserConsentStatusForVendor:resolve:reject:)
69
95
  func getUserConsentStatusForVendor(vendorId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
70
96
  let consentStatus = Didomi.shared.getUserConsentStatusForVendor(vendorId: vendorId)
71
- resolve(consentStatus)
97
+ resolve(consentStatus.rawValue.consentStatusBool)
72
98
  }
73
99
 
74
100
  @objc(getUserLegitimateInterestStatusForVendor:resolve:reject:)
75
101
  func getUserLegitimateInterestStatusForPurpose(vendorId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
76
102
  let consentStatus = Didomi.shared.getUserLegitimateInterestStatusForVendor(vendorId: vendorId)
77
- resolve(consentStatus)
103
+ resolve(consentStatus.rawValue.consentStatusBool)
78
104
  }
79
105
 
80
106
  @objc(getUserConsentStatusForVendorAndRequiredPurposes:resolve:reject:)
81
107
  func getUserConsentStatusForVendorAndRequiredPurposes(vendorId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
82
108
  let consentStatus = Didomi.shared.getUserConsentStatusForVendorAndRequiredPurposes(vendorId: vendorId)
83
- resolve(consentStatus)
109
+ resolve(consentStatus.rawValue.consentStatusBool)
84
110
  }
85
111
 
86
112
  @objc(getUserLegitimateInterestStatusForVendorAndRequiredPurposes:resolve:reject:)
87
113
  func getUserLegitimateInterestStatusForVendorAndRequiredPurposes(vendorId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
88
114
  let consentStatus = Didomi.shared.getUserLegitimateInterestStatusForVendorAndRequiredPurposes(vendorId: vendorId)
89
- resolve(consentStatus)
115
+ resolve(consentStatus.rawValue.consentStatusBool)
90
116
  }
91
117
 
92
118
  @objc(setUserStatus:purposesLIStatus:vendorsConsentStatus:vendorsLIStatus:resolve:reject:)
@@ -210,8 +236,12 @@ class RNDidomi: RCTEventEmitter {
210
236
  }
211
237
 
212
238
  @objc(getJavaScriptForWebView:resolve:reject:)
213
- func getJavaScriptForWebView(extra: String = "", resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
214
- resolve(Didomi.shared.getJavaScriptForWebView(extra: extra))
239
+ func getJavaScriptForWebView(_ extra: String? = "", resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) {
240
+ if let extra = extra {
241
+ resolve(Didomi.shared.getJavaScriptForWebView(extra: extra))
242
+ } else {
243
+ resolve(Didomi.shared.getJavaScriptForWebView())
244
+ }
215
245
  }
216
246
 
217
247
  @objc(updateSelectedLanguage:)
@@ -423,16 +453,20 @@ extension RNDidomi {
423
453
 
424
454
  @objc(supportedEvents)
425
455
  override func supportedEvents() -> [String]! {
426
- return ["on_consent_changed",
427
- "on_hide_notice",
456
+ return ["on_ready_callback",
457
+ "on_error_callback",
458
+ "on_consent_changed",
428
459
  "on_ready",
429
460
  "on_error",
461
+ "on_hide_notice",
430
462
  "on_show_notice",
431
463
  "on_notice_click_agree",
432
464
  "on_notice_click_disagree",
433
465
  "on_notice_click_more_info",
434
466
  "on_notice_click_view_vendors",
435
467
  "on_notice_click_privacy_policy",
468
+ "on_hide_preferences",
469
+ "on_show_preferences",
436
470
  "on_preferences_click_agree_to_all",
437
471
  "on_preferences_click_disagree_to_all",
438
472
  "on_preferences_click_agree_to_all_purposes",
@@ -461,10 +495,6 @@ extension RNDidomi {
461
495
  self.sendEvent(withName: "on_consent_changed", body:"")
462
496
  }
463
497
 
464
- didomiEventListener.onHideNotice = { event in
465
- self.sendEvent(withName: "on_hide_notice", body: "")
466
- }
467
-
468
498
  didomiEventListener.onReady = { event in
469
499
  self.sendEvent(withName: "on_ready", body: "")
470
500
  }
@@ -477,6 +507,10 @@ extension RNDidomi {
477
507
  self.sendEvent(withName: "on_show_notice", body: "")
478
508
  }
479
509
 
510
+ didomiEventListener.onHideNotice = { event in
511
+ self.sendEvent(withName: "on_hide_notice", body: "")
512
+ }
513
+
480
514
  didomiEventListener.onNoticeClickAgree = { event in
481
515
  self.sendEvent(withName: "on_notice_click_agree", body: "")
482
516
  }
@@ -497,6 +531,14 @@ extension RNDidomi {
497
531
  self.sendEvent(withName: "on_notice_click_privacy_policy", body: "")
498
532
  }
499
533
 
534
+ didomiEventListener.onShowPreferences = { event in
535
+ self.sendEvent(withName: "on_show_preferences", body: "")
536
+ }
537
+
538
+ didomiEventListener.onHidePreferences = { event in
539
+ self.sendEvent(withName: "on_hide_preferences", body: "")
540
+ }
541
+
500
542
  didomiEventListener.onPreferencesClickAgreeToAll = { event in
501
543
  self.sendEvent(withName: "on_preferences_click_agree_to_all", body: "")
502
544
  }
@@ -573,3 +615,12 @@ extension RNDidomi {
573
615
  }
574
616
  }
575
617
 
618
+ extension Int {
619
+ var consentStatusBool: Bool? {
620
+ if self == 2 {
621
+ return nil
622
+ } else {
623
+ return self == 0
624
+ }
625
+ }
626
+ }