@dpgradio/creative 7.1.1 → 7.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "7.1.1",
3
+ "version": "7.2.1",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -52,10 +52,39 @@ class Privacy {
52
52
  this.consentSubscribers.forEach((subscriber) => subscriber(null))
53
53
  }, timeoutTime)
54
54
 
55
- this.pushFunctional(() => {
56
- clearTimeout(timeout)
57
- this.consent = new Consent(window._privacy.consentString, window._privacy.purposesProvider.enabledPurposes)
58
- this.consentSubscribers.forEach((subscriber) => subscriber(this.consent))
55
+ this.pushConsentGiven((consentData) => {
56
+ let updatedConsentData = {
57
+ consentString: consentData.tcString,
58
+ purposes: new Set(consentData.dpgConsentString.split('|')),
59
+ }
60
+ const iabPurposePromises = []
61
+
62
+ // We have 10 IAB purposes, so we create 10 promises that resolve with the purpose number or null if the purpose is not given.
63
+ for (let i = 1; i < 11; i++) {
64
+ iabPurposePromises.push(
65
+ new Promise((resolve) => {
66
+ this.push(
67
+ i,
68
+ () => resolve(i), // Resolve with the purpose number
69
+ () => resolve(null) // Resolve without a value, indicating that the purpose is not given
70
+ )
71
+ })
72
+ )
73
+ }
74
+
75
+ Promise.all(iabPurposePromises).then((purposeConsents) => {
76
+ updatedConsentData = purposeConsents.reduce((acc, purpose) => {
77
+ if (purpose) {
78
+ acc.purposes.add(purpose)
79
+ }
80
+ return acc
81
+ }, updatedConsentData)
82
+
83
+ this.consent = new Consent(updatedConsentData)
84
+ this.consentSubscribers.forEach((subscriber) => subscriber(this.consent))
85
+
86
+ clearTimeout(timeout)
87
+ })
59
88
  })
60
89
  }
61
90
 
@@ -78,8 +107,12 @@ class Privacy {
78
107
  })
79
108
  }
80
109
 
81
- push(type, callback) {
82
- window._privacy.push([type, callback])
110
+ push(type, successCallback, failCallback = () => {}) {
111
+ window._privacy.push([type, successCallback, failCallback])
112
+ }
113
+
114
+ pushConsentGiven(callback) {
115
+ this.push('consentgiven', callback)
83
116
  }
84
117
 
85
118
  pushFunctional(callback) {
@@ -87,16 +120,14 @@ class Privacy {
87
120
  }
88
121
  }
89
122
 
90
- const targetedAdvertisingPurposes = [3, 4]
91
-
92
123
  class Consent {
93
- constructor(consentString, purposes) {
94
- this.consentString = consentString
95
- this.purposes = purposes
124
+ constructor(consentData) {
125
+ this.consentString = consentData.consentString
126
+ this.purposes = consentData.purposes
96
127
  }
97
128
 
98
129
  allowsTargetedAdvertising() {
99
- return targetedAdvertisingPurposes.every((purpose) => this.purposes.has(purpose.toString()))
130
+ return this.purposes.has('targeted_advertising')
100
131
  }
101
132
  }
102
133