@dpgradio/creative 7.1.1 → 7.2.2

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.2",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -5,6 +5,10 @@ import loadScript from '../utils/loadScript.js'
5
5
 
6
6
  class DataLayer {
7
7
  constructor() {
8
+ if (typeof window === 'undefined') {
9
+ return
10
+ }
11
+
8
12
  window.dataLayer = window.dataLayer || []
9
13
  this.campaignDetails = {}
10
14
  this.userInformation = {}
package/src/app/hybrid.js CHANGED
@@ -17,6 +17,10 @@ class Hybrid {
17
17
  }
18
18
 
19
19
  constructor() {
20
+ if (typeof window === 'undefined') {
21
+ return
22
+ }
23
+
20
24
  // Hook this on window so it can be required in multiple packs
21
25
  window._hybridEventSubscriptions = window._hybridEventSubscriptions || {}
22
26
 
@@ -3,6 +3,10 @@ import loadScript from '../utils/loadScript.js'
3
3
 
4
4
  class Privacy {
5
5
  constructor() {
6
+ if (typeof window === 'undefined') {
7
+ return
8
+ }
9
+
6
10
  window._privacy = window._privacy || []
7
11
 
8
12
  this.consent = undefined
@@ -52,10 +56,39 @@ class Privacy {
52
56
  this.consentSubscribers.forEach((subscriber) => subscriber(null))
53
57
  }, timeoutTime)
54
58
 
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))
59
+ this.pushConsentGiven((consentData) => {
60
+ let updatedConsentData = {
61
+ consentString: consentData.tcString,
62
+ purposes: new Set(consentData.dpgConsentString.split('|')),
63
+ }
64
+ const iabPurposePromises = []
65
+
66
+ // We have 10 IAB purposes, so we create 10 promises that resolve with the purpose number or null if the purpose is not given.
67
+ for (let i = 1; i < 11; i++) {
68
+ iabPurposePromises.push(
69
+ new Promise((resolve) => {
70
+ this.push(
71
+ i,
72
+ () => resolve(i), // Resolve with the purpose number
73
+ () => resolve(null) // Resolve without a value, indicating that the purpose is not given
74
+ )
75
+ })
76
+ )
77
+ }
78
+
79
+ Promise.all(iabPurposePromises).then((purposeConsents) => {
80
+ updatedConsentData = purposeConsents.reduce((acc, purpose) => {
81
+ if (purpose) {
82
+ acc.purposes.add(purpose)
83
+ }
84
+ return acc
85
+ }, updatedConsentData)
86
+
87
+ this.consent = new Consent(updatedConsentData)
88
+ this.consentSubscribers.forEach((subscriber) => subscriber(this.consent))
89
+
90
+ clearTimeout(timeout)
91
+ })
59
92
  })
60
93
  }
61
94
 
@@ -78,8 +111,12 @@ class Privacy {
78
111
  })
79
112
  }
80
113
 
81
- push(type, callback) {
82
- window._privacy.push([type, callback])
114
+ push(type, successCallback, failCallback = () => {}) {
115
+ window._privacy.push([type, successCallback, failCallback])
116
+ }
117
+
118
+ pushConsentGiven(callback) {
119
+ this.push('consentgiven', callback)
83
120
  }
84
121
 
85
122
  pushFunctional(callback) {
@@ -87,16 +124,14 @@ class Privacy {
87
124
  }
88
125
  }
89
126
 
90
- const targetedAdvertisingPurposes = [3, 4]
91
-
92
127
  class Consent {
93
- constructor(consentString, purposes) {
94
- this.consentString = consentString
95
- this.purposes = purposes
128
+ constructor(consentData) {
129
+ this.consentString = consentData.consentString
130
+ this.purposes = consentData.purposes
96
131
  }
97
132
 
98
133
  allowsTargetedAdvertising() {
99
- return targetedAdvertisingPurposes.every((purpose) => this.purposes.has(purpose.toString()))
134
+ return this.purposes.has('targeted_advertising')
100
135
  }
101
136
  }
102
137
 
@@ -1,4 +1,4 @@
1
- import openLink from '../utils/openLink.js'
1
+ import openExternalUrl from '../utils/openExternalUrl.js'
2
2
 
3
3
  export default class ShareResult {
4
4
  constructor(shareable, { url, image }) {
@@ -20,14 +20,14 @@ export default class ShareResult {
20
20
  }
21
21
 
22
22
  openFacebookUrl() {
23
- openLink(this.facebookUrl())
23
+ openExternalUrl(this.facebookUrl())
24
24
  }
25
25
 
26
26
  openWhatsappUrl() {
27
- openLink(this.whatsappUrl())
27
+ openExternalUrl(this.whatsappUrl())
28
28
  }
29
29
 
30
30
  openInstagramUrl() {
31
- openLink(this.instagramUrl())
31
+ openExternalUrl(this.instagramUrl())
32
32
  }
33
33
  }
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line import/no-unresolved -- TODO: Needs a rewrite to fetch
2
- import axios from 'axios'
3
1
  import ShareResult from './ShareResult.js'
4
2
 
5
3
  export default class Shareable {
@@ -36,21 +34,18 @@ export default class Shareable {
36
34
  return this
37
35
  }
38
36
 
39
- generateUsingImage(imageGeneratorProperties) {
40
- return new Promise((resolve, reject) => {
41
- axios({
42
- url: 'https://dba1du5ckc.execute-api.eu-west-3.amazonaws.com/prod/',
43
- method: 'post',
44
- data: {
45
- title: this.title,
46
- description: this.description,
47
- image_generator: imageGeneratorProperties.toJson(),
48
- redirect_url: this.redirectUrl,
49
- domain: this.domain,
50
- },
51
- })
52
- .then((response) => resolve(new ShareResult(this, response.data)))
53
- .catch(reject)
37
+ async generateUsingImage(imageGeneratorProperties) {
38
+ const response = await fetch('https://dba1du5ckc.execute-api.eu-west-3.amazonaws.com/prod/', {
39
+ method: 'POST',
40
+ body: JSON.stringify({
41
+ title: this.title,
42
+ description: this.description,
43
+ image_generator: imageGeneratorProperties.toJson(),
44
+ redirect_url: this.redirectUrl,
45
+ domain: this.domain,
46
+ }),
54
47
  })
48
+ const data = await response.json()
49
+ return new ShareResult(this, data)
55
50
  }
56
51
  }