@mparticle/web-onetrust-kit 2.0.4 → 3.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.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  /* eslint-disable no-undef */
4
4
  var CONSENT_REGULATIONS = {
5
5
  GDPR: 'gdpr',
6
- CCPA: 'ccpa'
6
+ CCPA: 'ccpa',
7
7
  };
8
8
  var CCPA_PURPOSE = 'data_sale_opt_out';
9
9
 
@@ -23,14 +23,19 @@ var initialization = {
23
23
  parseConsentMapping: function(rawConsentMapping) {
24
24
  var _consentMapping = {};
25
25
  if (rawConsentMapping) {
26
- var parsedMapping = JSON.parse(rawConsentMapping.replace(/"/g, '\"'));
26
+ var parsedMapping = JSON.parse(
27
+ rawConsentMapping.replace(/"/g, '"')
28
+ );
27
29
 
28
30
  // TODO: [67837] Revise this to use an actual 'regulation' mapping if UI ever returns this
29
31
  parsedMapping.forEach(function(mapping) {
30
32
  var purpose = mapping.map;
31
33
  _consentMapping[mapping.value] = {
32
34
  purpose: purpose,
33
- regulation: purpose === CCPA_PURPOSE ? CONSENT_REGULATIONS.CCPA : CONSENT_REGULATIONS.GDPR
35
+ regulation:
36
+ purpose === CCPA_PURPOSE
37
+ ? CONSENT_REGULATIONS.CCPA
38
+ : CONSENT_REGULATIONS.GDPR,
34
39
  };
35
40
  });
36
41
  }
@@ -57,7 +62,7 @@ var initialization = {
57
62
  // it for something custom so we can hijack
58
63
  var OptanonWrapperCopy = window.OptanonWrapper;
59
64
 
60
- window.OptanonWrapper = function () {
65
+ window.OptanonWrapper = function() {
61
66
  if (window.Optanon && window.Optanon.OnConsentChanged) {
62
67
  window.Optanon.OnConsentChanged(function() {
63
68
  self.createConsentEvents();
@@ -69,51 +74,78 @@ var initialization = {
69
74
  OptanonWrapperCopy();
70
75
  };
71
76
  },
72
- createConsentEvents: function () {
73
- if (window.Optanon) {
74
- var location = window.location.href,
75
- consent,
76
- consentState,
77
- user = mParticle.Identity.getCurrentUser();
78
-
79
- if (user) {
80
- consentState = user.getConsentState();
77
+ createConsentEvents: function() {
78
+ var user = mParticle.Identity.getCurrentUser();
79
+ if (!window.Optanon || !user) {
80
+ return;
81
+ }
81
82
 
82
- if (!consentState) {
83
- consentState = mParticle.Consent.createConsentState();
84
- }
85
- for (var key in this.consentMapping) {
86
- var consentPurpose = this.consentMapping[key].purpose;
87
- var regulation = this.consentMapping[key].regulation;
88
- var consentBoolean = false;
89
-
90
- // removes all non-digits
91
- // 1st version of OneTrust required a selection from group1, group2, etc
92
- if (key.indexOf('group') >= 0) {
93
- key = key.replace(/\D/g, '');
94
- }
83
+ var location = window.location.href;
84
+ var consentState =
85
+ user.getConsentState() || mParticle.Consent.createConsentState();
95
86
 
96
- consentBoolean = (this.getConsentGroupIds().indexOf(key) > -1);
87
+ for (var key in this.consentMapping) {
88
+ // removes all non-digits
89
+ // 1st version of OneTrust required a selection from group1, group2, etc
90
+ if (key.indexOf('group') >= 0) {
91
+ key = key.replace(/\D/g, '');
92
+ }
97
93
 
98
- // At present, only CCPA and GDPR are known regulations
99
- // Using a switch in case a new regulation is added in the future
100
- switch (regulation) {
101
- case CONSENT_REGULATIONS.CCPA:
102
- consent = mParticle.Consent.createCCPAConsent(consentBoolean, Date.now(), consentPurpose, location);
103
- consentState.setCCPAConsentState(consent);
104
- break;
105
- case CONSENT_REGULATIONS.GDPR:
106
- consent = mParticle.Consent.createGDPRConsent(consentBoolean, Date.now(), consentPurpose, location);
107
- consentState.addGDPRConsentState(consentPurpose, consent);
94
+ // Although consent purposes can be inputted into the UI in any casing
95
+ // the SDK will automatically lowercase them to prevent pseudo-duplicate
96
+ // consent purposes, so we call `toLowerCase` on the consentMapping purposes here
97
+ var consentPurpose = this.consentMapping[key].purpose.toLowerCase();
98
+ var regulation = this.consentMapping[key].regulation;
99
+
100
+ var latestOTConsentBoolean =
101
+ this.getConsentGroupIds().indexOf(key) > -1;
102
+
103
+ // At present, only CCPA and GDPR are known regulations
104
+ // Using a switch in case a new regulation is added in the future
105
+ switch (regulation) {
106
+ case CONSENT_REGULATIONS.CCPA:
107
+ var ccpaConsent = mParticle.Consent.createCCPAConsent(
108
+ latestOTConsentBoolean,
109
+ Date.now(),
110
+ consentPurpose,
111
+ location
112
+ );
113
+ consentState.setCCPAConsentState(ccpaConsent);
114
+ break;
115
+
116
+ case CONSENT_REGULATIONS.GDPR:
117
+ var GDPRConsentState =
118
+ consentState.getGDPRConsentState() || {};
119
+
120
+ // if the consent boolean exists, and the current users consent
121
+ // is the same as the latest OT consent (consent hasn't changed)
122
+ // then don't update the consent state
123
+ if (GDPRConsentState[consentPurpose]) {
124
+ var currentConsentBoolean =
125
+ GDPRConsentState[consentPurpose].Consented;
126
+ if (currentConsentBoolean === latestOTConsentBoolean) {
108
127
  break;
109
- default:
110
- console.error('Unknown Consent Regulation', regulation);
128
+ }
111
129
  }
112
- }
113
130
 
114
- user.setConsentState(consentState);
131
+ var gdprConsent = mParticle.Consent.createGDPRConsent(
132
+ latestOTConsentBoolean,
133
+ Date.now(),
134
+ consentPurpose,
135
+ location
136
+ );
137
+ consentState.addGDPRConsentState(
138
+ consentPurpose,
139
+ gdprConsent
140
+ );
141
+ break;
142
+
143
+ default:
144
+ console.error('Unknown Consent Regulation', regulation);
115
145
  }
116
146
  }
147
+
148
+ user.setConsentState(consentState);
117
149
  },
118
150
 
119
151
  createVendorConsentEvents: function() {
@@ -198,9 +230,11 @@ function setGoogleVendorRequests(
198
230
 
199
231
  if (googleConsentedVendors && googleConsentedVendors.length) {
200
232
  for (var vendorId in googleVendorConsentMapping) {
201
- var consentPurpose = googleVendorConsentMapping[vendorId].purpose;
233
+ var consentPurpose =
234
+ googleVendorConsentMapping[vendorId].purpose;
202
235
  // consent is true if the vendor id is in the array of consented IDs
203
- var consentBoolean = googleConsentedVendors.indexOf(vendorId) > -1;
236
+ var consentBoolean =
237
+ googleConsentedVendors.indexOf(vendorId) > -1;
204
238
  var consent = mParticle.Consent.createGDPRConsent(
205
239
  consentBoolean,
206
240
  Date.now(),
@@ -228,11 +262,11 @@ function setIABVendorRequests(
228
262
  var IABConsentedVendors = oneTrustVendorConsent
229
263
  ? oneTrustVendorConsent.vendor.consents
230
264
  : null;
231
-
232
265
  for (var vendorIndex in IABVendorConsentMappings) {
233
266
  var consentPurpose = IABVendorConsentMappings[vendorIndex].purpose;
234
267
  // consent is true if the (vendorIndex - 1) is 1
235
- var consentBoolean = IABConsentedVendors[parseInt(vendorIndex) - 1] === '1';
268
+ var consentBoolean =
269
+ IABConsentedVendors[parseInt(vendorIndex) - 1] === '1';
236
270
  var consent = mParticle.Consent.createGDPRConsent(
237
271
  consentBoolean,
238
272
  Date.now(),
@@ -255,9 +289,11 @@ function setGeneralVendorRequests(
255
289
  try {
256
290
  if (window.Optanon) {
257
291
  for (var vendorId in generalVendorConsentMapping) {
258
- var consentPurpose = generalVendorConsentMapping[vendorId].purpose;
292
+ var consentPurpose =
293
+ generalVendorConsentMapping[vendorId].purpose;
259
294
  // consent is true if the vendorId is in the oneTrustVendorConsent array
260
- var consentBoolean = oneTrustVendorConsent.indexOf(vendorId) > -1;
295
+ var consentBoolean =
296
+ oneTrustVendorConsent.indexOf(vendorId) > -1;
261
297
  var consent = mParticle.Consent.createGDPRConsent(
262
298
  consentBoolean,
263
299
  Date.now(),
@@ -294,99 +330,115 @@ var initialization_1 = {
294
330
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
295
331
  // See the License for the specific language governing permissions and
296
332
  // limitations under the License.
297
- var Initialization = initialization_1.initialization;
298
-
299
- var name = Initialization.name,
300
- moduleId = Initialization.moduleId;
301
-
302
- var constructor = function () {
303
- var self = this,
304
- isInitialized = false,
305
- forwarderSettings;
306
-
307
- self.name = Initialization.name;
308
-
309
- function initForwarder(settings) {
310
- forwarderSettings = settings;
311
- if (!isInitialized) {
312
- try {
313
- Initialization.initForwarder(forwarderSettings, isInitialized);
314
- isInitialized = true;
315
- } catch (e) {
316
- console.log('Failed to initialize ' + name + ' - ' + e);
317
- }
333
+ var Initialization = initialization_1
334
+ .initialization;
335
+
336
+ var name = Initialization.name,
337
+ moduleId = Initialization.moduleId;
338
+
339
+ var constructor = function() {
340
+ var self = this,
341
+ isInitialized = false,
342
+ forwarderSettings;
343
+
344
+ self.name = Initialization.name;
345
+
346
+ function initForwarder(settings) {
347
+ forwarderSettings = settings;
348
+ if (!isInitialized) {
349
+ try {
350
+ Initialization.initForwarder(forwarderSettings, isInitialized);
351
+ isInitialized = true;
352
+ } catch (e) {
353
+ console.log('Failed to initialize ' + name + ' - ' + e);
354
+ }
355
+
356
+ Initialization.createConsentEvents();
357
+ Initialization.createVendorConsentEvents();
358
+ }
359
+ }
318
360
 
361
+ function onUserIdentified() {
362
+ if (isInitialized) {
363
+ try {
319
364
  Initialization.createConsentEvents();
320
365
  Initialization.createVendorConsentEvents();
366
+ } catch (e) {
367
+ return {
368
+ error:
369
+ 'Error setting user identity on forwarder ' +
370
+ name +
371
+ '; ' +
372
+ e,
373
+ };
321
374
  }
375
+ } else {
376
+ return (
377
+ "Can't set new user identities on forwader " +
378
+ name +
379
+ ', not initialized'
380
+ );
322
381
  }
382
+ }
323
383
 
324
- function onUserIdentified() {
325
- if (isInitialized) {
326
- try {
327
- Initialization.createConsentEvents();
328
- Initialization.createVendorConsentEvents();
329
- } catch (e) {
330
- return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
331
- }
332
- }
333
- else {
334
- return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
335
- }
336
- }
384
+ this.init = initForwarder;
385
+ this.onUserIdentified = onUserIdentified;
386
+ this.process = function() {};
387
+ };
337
388
 
338
- this.init = initForwarder;
339
- this.onUserIdentified = onUserIdentified;
340
- this.process = function() {
389
+ function getId() {
390
+ return moduleId;
391
+ }
341
392
 
342
- };
343
- };
393
+ function isObject(val) {
394
+ return (
395
+ val != null && typeof val === 'object' && Array.isArray(val) === false
396
+ );
397
+ }
344
398
 
345
- function getId() {
346
- return moduleId;
399
+ function register(config) {
400
+ if (!config) {
401
+ console.log(
402
+ 'You must pass a config object to register the kit ' + name
403
+ );
404
+ return;
347
405
  }
348
406
 
349
- function isObject(val) {
350
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
407
+ if (!isObject(config)) {
408
+ console.log(
409
+ "'config' must be an object. You passed in a " + typeof config
410
+ );
411
+ return;
351
412
  }
352
413
 
353
- function register(config) {
354
- if (!config) {
355
- console.log('You must pass a config object to register the kit ' + name);
356
- return;
357
- }
358
-
359
- if (!isObject(config)) {
360
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
361
- return;
362
- }
363
-
364
- if (isObject(config.kits)) {
365
- config.kits[name] = {
366
- constructor: constructor
367
- };
368
- } else {
369
- config.kits = {};
370
- config.kits[name] = {
371
- constructor: constructor
372
- };
373
- }
374
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
414
+ if (isObject(config.kits)) {
415
+ config.kits[name] = {
416
+ constructor: constructor,
417
+ };
418
+ } else {
419
+ config.kits = {};
420
+ config.kits[name] = {
421
+ constructor: constructor,
422
+ };
375
423
  }
424
+ console.log(
425
+ 'Successfully registered ' + name + ' to your mParticle configuration'
426
+ );
427
+ }
376
428
 
377
- if (typeof window !== 'undefined') {
378
- if (window && window.mParticle && window.mParticle.addForwarder) {
379
- window.mParticle.addForwarder({
380
- name: name,
381
- constructor: constructor,
382
- getId: getId
383
- });
384
- }
429
+ if (typeof window !== 'undefined') {
430
+ if (window && window.mParticle && window.mParticle.addForwarder) {
431
+ window.mParticle.addForwarder({
432
+ name: name,
433
+ constructor: constructor,
434
+ getId: getId,
435
+ });
385
436
  }
437
+ }
386
438
 
387
- var oneTrustWrapper = {
388
- register: register
389
- };
439
+ var oneTrustWrapper = {
440
+ register: register,
441
+ };
390
442
  var oneTrustWrapper_1 = oneTrustWrapper.register;
391
443
 
392
444
  exports.default = oneTrustWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-onetrust-kit",
3
- "version": "2.0.4",
3
+ "version": "3.1.0",
4
4
  "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
5
  "description": "mParticle integration sdk for OneTrust",
6
6
  "browser": "dist/OneTrustKit.common.js",
@@ -8,7 +8,11 @@
8
8
  "files": [
9
9
  "dist/OneTrustKit.common.js"
10
10
  ],
11
- "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-onetrust",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/mParticle/mparticle-web-sdk",
14
+ "directory": "kits/onetrust"
15
+ },
12
16
  "scripts": {
13
17
  "build": "rollup --config rollup.config.js",
14
18
  "watch": "rollup --config rollup.config.js -w",
@@ -31,7 +35,7 @@
31
35
  },
32
36
  "dependencies": {
33
37
  "isobject": "^4.0.0",
34
- "@mparticle/web-sdk": "^2.11.15"
38
+ "@mparticle/web-sdk": "^3.0.0"
35
39
  },
36
40
  "license": "Apache-2.0"
37
41
  }