cordova-plugin-onetrust-cmp 202602.1.2 → 202604.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 202604.1.0
2
+ * Adds support for OneTrust 202604.1.0
3
+ * Added renameProfile, fetchBannerCmpApiData, fetchPreferencesCmpApiData, fetchVendorsCmpApiData methods
4
+
5
+ ## 202603.1.0
6
+ * Exposed OTConsentUpdated event
7
+ * Adds support for OneTrust 202603.1.0
8
+
1
9
  ## 202602.1.2
2
10
  * Adds support for OneTrust 202602.1.2
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-onetrust-cmp",
3
- "version": "202602.1.2",
3
+ "version": "202604.1.0",
4
4
  "description": "OneTrust is the leading Consent Management solution provider. This plugin exposes OneTrust's native CMP functionality to Cordova and Ionic environments.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-onetrust-cmp" version="202602.1.2"
2
+ <plugin id="cordova-plugin-onetrust-cmp" version="202604.1.0"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  xmlns:android="http://schemas.android.com/apk/res/android">
5
5
  <name>OneTrust</name>
@@ -18,12 +18,12 @@
18
18
  <config>
19
19
  </config>
20
20
  <pods use-frameworks="true">
21
- <pod name="OneTrust-CMP-XCFramework" spec="~> 202602.1.2.0" />
21
+ <pod name="OneTrust-CMP-XCFramework" spec="~> 202604.1.0.0" />
22
22
  </pods>
23
23
  </podspec>
24
24
  </platform>
25
25
  <platform name="android">
26
- <framework src="com.onetrust.cmp:native-sdk:202602.1.2.0" />
26
+ <framework src="com.onetrust.cmp:native-sdk:202604.1.0.0" />
27
27
  <framework src="androidx.appcompat:appcompat:1.2.0" />
28
28
  <config-file parent="/*" target="res/xml/config.xml">
29
29
  <feature name="OneTrust">
@@ -5,6 +5,7 @@ import android.content.Context;
5
5
  import android.content.Intent;
6
6
  import android.content.IntentFilter;
7
7
  import android.os.Build;
8
+ import androidx.annotation.NonNull;
8
9
 
9
10
  import com.onetrust.otpublishers.headless.Public.DataModel.OTProfileSyncParams;
10
11
  import com.onetrust.otpublishers.headless.Public.Keys.OTBroadcastServiceKeys;
@@ -71,6 +72,9 @@ public class OneTrust extends CordovaPlugin{
71
72
  String catId = args.getString(0);
72
73
  observeChanges(catId);
73
74
  return true;
75
+ case "stopObservingChanges":
76
+ stopObservingChanges();
77
+ return true;
74
78
  case "addCustomStyles":
75
79
  callbackContext.error("Deprecated Method. Add your JSON as androidUXParams in the params object of startSDK.");
76
80
  case "getCachedIdentifier":
@@ -90,7 +94,21 @@ public class OneTrust extends CordovaPlugin{
90
94
  return true;
91
95
  case "getOTGoogleConsentModeData":
92
96
  getOTGoogleConsentModeData(callbackContext);
93
- return true;
97
+ return true;
98
+ case "fetchBannerCmpApiData":
99
+ fetchBannerCmpApiData(callbackContext);
100
+ return true;
101
+ case "fetchPreferencesCmpApiData":
102
+ fetchPreferencesCmpApiData(callbackContext);
103
+ return true;
104
+ case "fetchVendorsCmpApiData":
105
+ fetchVendorsCmpApiData(callbackContext);
106
+ return true;
107
+ case "renameProfile":
108
+ String fromIdentifier = args.optString(0, "");
109
+ String toIdentifier = args.getString(1);
110
+ renameProfile(fromIdentifier, toIdentifier, callbackContext);
111
+ return true;
94
112
  default:
95
113
  callbackContext.error("Unimplemented method called");
96
114
  break;
@@ -232,6 +250,14 @@ public class OneTrust extends CordovaPlugin{
232
250
  }
233
251
 
234
252
  private void observeChanges(String catId){
253
+ if (catId.equals("OTConsentUpdated")) {
254
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
255
+ cordova.getActivity().registerReceiver(otConsentUpdated, new IntentFilter(OTBroadcastServiceKeys.OT_CONSENT_UPDATED), Context.RECEIVER_NOT_EXPORTED);
256
+ } else {
257
+ cordova.getActivity().registerReceiver(otConsentUpdated, new IntentFilter(OTBroadcastServiceKeys.OT_CONSENT_UPDATED));
258
+ }
259
+ return;
260
+ }
235
261
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
236
262
  cordova.getActivity().registerReceiver(consentStatusChanged, new IntentFilter(catId), Context.RECEIVER_NOT_EXPORTED);
237
263
  } else {
@@ -240,6 +266,15 @@ public class OneTrust extends CordovaPlugin{
240
266
 
241
267
  }
242
268
 
269
+ private void stopObservingChanges(){
270
+ try{
271
+ cordova.getActivity().unregisterReceiver(consentStatusChanged);
272
+ cordova.getActivity().unregisterReceiver(otConsentUpdated);
273
+ } catch (Exception e) {
274
+ Log.e("ot_log", "Error when trying to unregister receiver.");
275
+ }
276
+ }
277
+
243
278
  private void getCachedIdentifier(CallbackContext callbackContext){
244
279
  Runnable runnable = new Runnable() {
245
280
  @Override
@@ -325,6 +360,14 @@ public class OneTrust extends CordovaPlugin{
325
360
  }
326
361
  };
327
362
 
363
+ BroadcastReceiver otConsentUpdated = new BroadcastReceiver() {
364
+ @Override
365
+ public void onReceive(Context context, Intent intent) {
366
+ String category = intent.getAction();
367
+ emit(category, "{}");
368
+ }
369
+ };
370
+
328
371
  private void startCMPActivity(int uiType){
329
372
  Intent intent = new Intent(cordova.getContext(), CMPActivity.class);
330
373
  intent.putExtra("UIType", uiType);
@@ -365,4 +408,84 @@ public class OneTrust extends CordovaPlugin{
365
408
  };
366
409
  runInThreadPool(runnable);
367
410
  }
411
+
412
+ private void fetchBannerCmpApiData(CallbackContext callbackContext) {
413
+ Runnable runnable = new Runnable() {
414
+ @Override
415
+ public void run() {
416
+ new OTPublishersHeadlessSDK(cordova.getContext()).fetchBannerCmpApiData(new OTCallback() {
417
+ @Override
418
+ public void onSuccess(@NonNull OTResponse otSuccessResponse) {
419
+ callbackContext.success(otSuccessResponse.getResponseData());
420
+ }
421
+
422
+ @Override
423
+ public void onFailure(@NonNull OTResponse otErrorResponse) {
424
+ callbackContext.error(otErrorResponse.getResponseMessage());
425
+ }
426
+ });
427
+ }
428
+ };
429
+ runInThreadPool(runnable);
430
+ }
431
+
432
+ private void fetchPreferencesCmpApiData(CallbackContext callbackContext) {
433
+ Runnable runnable = new Runnable() {
434
+ @Override
435
+ public void run() {
436
+ new OTPublishersHeadlessSDK(cordova.getContext()).fetchPreferencesCmpApiData(new OTCallback() {
437
+ @Override
438
+ public void onSuccess(@NonNull OTResponse otSuccessResponse) {
439
+ callbackContext.success(otSuccessResponse.getResponseData());
440
+ }
441
+
442
+ @Override
443
+ public void onFailure(@NonNull OTResponse otErrorResponse) {
444
+ callbackContext.error(otErrorResponse.getResponseMessage());
445
+ }
446
+ });
447
+ }
448
+ };
449
+ runInThreadPool(runnable);
450
+ }
451
+
452
+ private void fetchVendorsCmpApiData(CallbackContext callbackContext) {
453
+ Runnable runnable = new Runnable() {
454
+ @Override
455
+ public void run() {
456
+ new OTPublishersHeadlessSDK(cordova.getContext()).fetchVendorsCmpApiData(new OTCallback() {
457
+ @Override
458
+ public void onSuccess(@NonNull OTResponse otSuccessResponse) {
459
+ callbackContext.success(otSuccessResponse.getResponseData());
460
+ }
461
+
462
+ @Override
463
+ public void onFailure(@NonNull OTResponse otErrorResponse) {
464
+ callbackContext.error(otErrorResponse.getResponseMessage());
465
+ }
466
+ });
467
+ }
468
+ };
469
+ runInThreadPool(runnable);
470
+ }
471
+
472
+ private void renameProfile(String fromIdentifier, String toIdentifier, CallbackContext callbackContext) {
473
+ Runnable runnable = new Runnable() {
474
+ @Override
475
+ public void run() {
476
+ ot.renameProfile(fromIdentifier, toIdentifier, new OTCallback() {
477
+ @Override
478
+ public void onSuccess(@NonNull OTResponse otResponse) {
479
+ callbackContext.success(1);
480
+ }
481
+
482
+ @Override
483
+ public void onFailure(@NonNull OTResponse otResponse) {
484
+ callbackContext.error(otResponse.getResponseMessage());
485
+ }
486
+ });
487
+ }
488
+ };
489
+ runInThreadPool(runnable);
490
+ }
368
491
  }
@@ -155,7 +155,11 @@ import AppTrackingTransparency
155
155
  func observeChanges(_ command:CDVInvokedUrlCommand){
156
156
  var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR)
157
157
  if let category = command.argument(at: 0) as? String{
158
- NotificationCenter.default.addObserver(self, selector: #selector(consentChanged(_:)), name: Notification.Name(category), object: nil)
158
+ if category == "OTConsentUpdated" {
159
+ NotificationCenter.default.addObserver(self, selector: #selector(otConsentUpdated(_:)), name: Notification.Name(category), object: nil)
160
+ } else {
161
+ NotificationCenter.default.addObserver(self, selector: #selector(consentChanged(_:)), name: Notification.Name(category), object: nil)
162
+ }
159
163
  pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
160
164
  }
161
165
  self.returnToCordova(pluginResult: pluginResult, command: command)
@@ -264,6 +268,13 @@ import AppTrackingTransparency
264
268
 
265
269
  }
266
270
 
271
+ @objc private func otConsentUpdated(_ notification:Notification){
272
+ let ex = "cordova.fireDocumentEvent('OTConsentUpdated',{});"
273
+ DispatchQueue.main.async{
274
+ self.webViewEngine.evaluateJavaScript(ex, completionHandler: nil)
275
+ }
276
+ }
277
+
267
278
  private func getATTStatusAsString() -> String?{
268
279
  guard #available(iOS 14, *) else {return nil}
269
280
  let statusMap:[ATTrackingManager.AuthorizationStatus:String] = [.authorized:"authorized", .denied:"denied", .notDetermined:"notDetermined", .restricted:"restricted"]
@@ -276,7 +287,72 @@ import AppTrackingTransparency
276
287
  self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
277
288
  }
278
289
  }
279
-
290
+
291
+ // Add this private helper method
292
+ private func fetchCmpApiData(
293
+ fetcher: (@escaping ([String: Any]?) -> Void) -> Void,
294
+ command: CDVInvokedUrlCommand,
295
+ errorMessage: String
296
+ ) {
297
+ fetcher { response in
298
+ let pluginResult: CDVPluginResult
299
+ if let data = response,
300
+ let jsonData = try? JSONSerialization.data(withJSONObject: data),
301
+ let jsonString = String(data: jsonData, encoding: .utf8) {
302
+ pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: jsonString)
303
+ } else {
304
+ pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: errorMessage)
305
+ }
306
+ self.returnToCordova(pluginResult: pluginResult, command: command)
307
+ }
308
+ }
309
+
310
+ @objc(fetchBannerCmpApiData:)
311
+ func fetchBannerCmpApiData(_ command: CDVInvokedUrlCommand) {
312
+ fetchCmpApiData(
313
+ fetcher: OTPublishersHeadlessSDK.shared.fetchBannerCmpApiData,
314
+ command: command,
315
+ errorMessage: "No response from fetchBannerCmpApiData"
316
+ )
317
+ }
318
+
319
+ @objc(fetchPreferencesCmpApiData:)
320
+ func fetchPreferencesCmpApiData(_ command: CDVInvokedUrlCommand) {
321
+ fetchCmpApiData(
322
+ fetcher: OTPublishersHeadlessSDK.shared.fetchPreferencesCmpApiData,
323
+ command: command,
324
+ errorMessage: "No response from fetchPreferencesCmpApiData"
325
+ )
326
+ }
327
+
328
+ @objc(fetchVendorsCmpApiData:)
329
+ func fetchVendorsCmpApiData(_ command: CDVInvokedUrlCommand) {
330
+ fetchCmpApiData(
331
+ fetcher: OTPublishersHeadlessSDK.shared.fetchVendorsCmpApiData,
332
+ command: command,
333
+ errorMessage: "No response from fetchVendorsCmpApiData"
334
+ )
335
+ }
336
+
337
+ @objc(renameProfile:)
338
+ func renameProfile(_ command: CDVInvokedUrlCommand) {
339
+ let fromIdentifier = command.argument(at: 0) as? String
340
+ guard let toIdentifier = command.argument(at: 1) as? String else {
341
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "toIdentifier is required")
342
+ self.returnToCordova(pluginResult: pluginResult, command: command)
343
+ return
344
+ }
345
+
346
+ OTPublishersHeadlessSDK.shared.renameProfile(from: fromIdentifier, to: toIdentifier) { success in
347
+ let pluginResult: CDVPluginResult
348
+ if success {
349
+ pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: true)
350
+ } else {
351
+ pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "Error renaming profile")
352
+ }
353
+ self.returnToCordova(pluginResult: pluginResult, command: command)
354
+ }
355
+ }
280
356
  }
281
357
 
282
358
  extension OneTrust:OTEventListener{
package/www/OneTrust.js CHANGED
@@ -59,6 +59,22 @@ var exports = {
59
59
  exec(success,error, pluginName, 'getOTGoogleConsentModeData')
60
60
  },
61
61
 
62
+ fetchBannerCmpApiData: (success, error) => {
63
+ exec(success, error, pluginName, 'fetchBannerCmpApiData')
64
+ },
65
+
66
+ fetchPreferencesCmpApiData: (success, error) => {
67
+ exec(success, error, pluginName, 'fetchPreferencesCmpApiData')
68
+ },
69
+
70
+ fetchVendorsCmpApiData: (success, error) => {
71
+ exec(success, error, pluginName, 'fetchVendorsCmpApiData')
72
+ },
73
+
74
+ renameProfile: (fromIdentifier, toIdentifier, success, error) => {
75
+ exec(success, error, pluginName, 'renameProfile', [fromIdentifier, toIdentifier])
76
+ },
77
+
62
78
  devicePermission: Object.freeze({idfa:0})
63
79
  }
64
80