@guardian/consent-management-platform
Advanced tools
Comparing version 0.0.0-beta-20240119094923 to 0.0.0-beta-20240122213831
import type { CMP } from './types'; | ||
export { cmpGetCookie, cmpSetCookie, cmpSetSessionCookie } from './cmpCookies'; | ||
export { storage } from './cmpStorage'; | ||
export declare const cmp: CMP; | ||
@@ -3,0 +5,0 @@ export declare const onConsent: () => Promise<import("./types").ConsentState>; |
@@ -1,2 +0,2 @@ | ||
import { log, removeCookie, storage } from '@guardian/libs'; | ||
import { log, removeCookie, storage as storage$1, getCookie, setCookie, setSessionCookie } from '@guardian/libs'; | ||
@@ -254,124 +254,65 @@ let currentFramework; | ||
/* istanbul ignore file */ | ||
// Reference : https://docs.sourcepoint.com/hc/en-us/articles/18007731422099-Enable-GPP-Multi-State-Privacy-String-MSPS-with-U-S-Privacy-CCPA-solution | ||
const stub_gpp_ccpa = () => { | ||
(window.__gpp_addFrame = function (e) { | ||
if (!window.frames[e]) { | ||
if (document.body) { | ||
var t = document.createElement('iframe'); | ||
(t.style.cssText = 'display:none'), | ||
(t.name = e), | ||
document.body.appendChild(t); | ||
} else window.setTimeout(window.__gpp_addFrame, 10, e); | ||
/* | ||
This code is the CCPA stub made available by Sourcepoint. | ||
See the documentation on how to retrieve the latest version: | ||
https://documentation.sourcepoint.com/implementation/web-implementation/multi-campaign-web-implementation#stub-file | ||
*/ | ||
const stub_ccpa = () => { | ||
(function () { | ||
var e = false; | ||
var c = window; | ||
var t = document; | ||
function r() { | ||
if (!c.frames['__uspapiLocator']) { | ||
if (t.body) { | ||
var a = t.body; | ||
var e = t.createElement('iframe'); | ||
e.style.cssText = 'display:none'; | ||
e.name = '__uspapiLocator'; | ||
a.appendChild(e); | ||
} else { | ||
setTimeout(r, 5); | ||
} | ||
} | ||
} | ||
}), | ||
(window.__gpp_stub = function () { | ||
var e = arguments; | ||
if ( | ||
((__gpp.queue = __gpp.queue || []), | ||
(__gpp.events = __gpp.events || []), | ||
!e.length || (1 == e.length && 'queue' == e[0])) | ||
) { | ||
return __gpp.queue; | ||
r(); | ||
function p() { | ||
var a = arguments; | ||
__uspapi.a = __uspapi.a || []; | ||
if (!a.length) { | ||
return __uspapi.a; | ||
} else if (a[0] === 'ping') { | ||
a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true); | ||
} else { | ||
__uspapi.a.push([].slice.apply(a)); | ||
} | ||
if (1 == e.length && 'events' == e[0]) return __gpp.events; | ||
var t = e[0], | ||
p = e.length > 1 ? e[1] : null, | ||
n = e.length > 2 ? e[2] : null; | ||
if ('ping' === t) { | ||
return { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfcav2', 'uspv1'], | ||
cmpId: 31, | ||
}; | ||
} | ||
if ('addEventListener' === t) { | ||
'lastId' in __gpp || (__gpp.lastId = 0), __gpp.lastId++; | ||
var a = __gpp.lastId; | ||
return ( | ||
__gpp.events.push({ id: a, callback: p, parameter: n }), | ||
{ | ||
eventName: 'listenerRegistered', | ||
listenerId: a, | ||
data: !0, | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
} | ||
); | ||
} | ||
if ('removeEventListener' === t) { | ||
for (var s = !1, i = 0; i < __gpp.events.length; i++) { | ||
if (__gpp.events[i].id == n) { | ||
__gpp.events.splice(i, 1), (s = !0); | ||
break; | ||
} | ||
} | ||
return { | ||
eventName: 'listenerRemoved', | ||
listenerId: n, | ||
data: s, | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
}; | ||
} | ||
return 'getGPPData' === t | ||
? { | ||
sectionId: 3, | ||
gppVersion: 1, | ||
sectionList: [], | ||
applicableSections: [0], | ||
gppString: '', | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
} | ||
: 'hasSection' === t || 'getSection' === t || 'getField' === t | ||
? null | ||
: void __gpp.queue.push([].slice.apply(e)); | ||
}), | ||
(window.__gpp_msghandler = function (e) { | ||
var t = 'string' == typeof e.data; | ||
} | ||
function l(t) { | ||
var r = typeof t.data === 'string'; | ||
try { | ||
var p = t ? JSON.parse(e.data) : e.data; | ||
} catch (e) { | ||
p = null; | ||
} | ||
if ('object' == typeof p && null !== p && '__gppCall' in p) { | ||
var n = p.__gppCall; | ||
window.__gpp( | ||
n.command, | ||
function (p, a) { | ||
var s = { | ||
__gppReturn: { | ||
returnValue: p, | ||
success: a, | ||
var a = r ? JSON.parse(t.data) : t.data; | ||
if (a.__cmpCall) { | ||
var n = a.__cmpCall; | ||
c.__uspapi(n.command, n.parameter, function (a, e) { | ||
var c = { | ||
__cmpReturn: { | ||
returnValue: a, | ||
success: e, | ||
callId: n.callId, | ||
}, | ||
}; | ||
e.source.postMessage(t ? JSON.stringify(s) : s, '*'); | ||
}, | ||
'parameter' in n ? n.parameter : null, | ||
'version' in n ? n.version : 1, | ||
); | ||
} | ||
}), | ||
('__gpp' in window && 'function' == typeof window.__gpp) || | ||
((window.__gpp = window.__gpp_stub), | ||
window.addEventListener('message', window.__gpp_msghandler, !1), | ||
window.__gpp_addFrame('__gppLocator')); | ||
t.source.postMessage(r ? JSON.stringify(c) : c, '*'); | ||
}); | ||
} | ||
} catch (a) {} | ||
} | ||
if (typeof __uspapi !== 'function') { | ||
c.__uspapi = p; | ||
__uspapi.msgHandler = l; | ||
c.addEventListener('message', l, false); | ||
} | ||
})(); | ||
}; | ||
@@ -687,82 +628,7 @@ | ||
/* eslint-disable -- this is third party code */ | ||
/* istanbul ignore file */ | ||
/* | ||
This code is the CCPA stub made available by Sourcepoint. | ||
See the documentation on how to retrieve the latest version: | ||
https://documentation.sourcepoint.com/implementation/web-implementation/multi-campaign-web-implementation#stub-file | ||
*/ | ||
const stub_uspapi_ccpa = () => { | ||
(function () { | ||
var e = false; | ||
var c = window; | ||
var t = document; | ||
function r() { | ||
if (!c.frames['__uspapiLocator']) { | ||
if (t.body) { | ||
var a = t.body; | ||
var e = t.createElement('iframe'); | ||
e.style.cssText = 'display:none'; | ||
e.name = '__uspapiLocator'; | ||
a.appendChild(e); | ||
} else { | ||
setTimeout(r, 5); | ||
} | ||
} | ||
} | ||
r(); | ||
function p() { | ||
var a = arguments; | ||
__uspapi.a = __uspapi.a || []; | ||
if (!a.length) { | ||
return __uspapi.a; | ||
} else if (a[0] === 'ping') { | ||
a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true); | ||
} else { | ||
__uspapi.a.push([].slice.apply(a)); | ||
} | ||
} | ||
function l(t) { | ||
var r = typeof t.data === 'string'; | ||
try { | ||
var a = r ? JSON.parse(t.data) : t.data; | ||
if (a.__cmpCall) { | ||
var n = a.__cmpCall; | ||
c.__uspapi(n.command, n.parameter, function (a, e) { | ||
var c = { | ||
__cmpReturn: { | ||
returnValue: a, | ||
success: e, | ||
callId: n.callId, | ||
}, | ||
}; | ||
t.source.postMessage(r ? JSON.stringify(c) : c, '*'); | ||
}); | ||
} | ||
} catch (a) {} | ||
} | ||
if (typeof __uspapi !== 'function') { | ||
c.__uspapi = p; | ||
__uspapi.msgHandler = l; | ||
c.addEventListener('message', l, false); | ||
} | ||
})(); | ||
}; | ||
const stub = (framework) => { | ||
switch (framework) { | ||
case 'tcfv2': | ||
stub_tcfv2(); | ||
break; | ||
case 'ccpa': | ||
stub_uspapi_ccpa(); | ||
stub_gpp_ccpa(); | ||
break; | ||
case 'aus': | ||
stub_uspapi_ccpa(); | ||
break; | ||
} | ||
if (framework === 'tcfv2') | ||
stub_tcfv2(); | ||
else | ||
stub_ccpa(); | ||
}; | ||
@@ -866,26 +732,16 @@ | ||
}; | ||
switch (framework) { | ||
case 'tcfv2': | ||
window._sp_.config.gdpr = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
case 'ccpa': | ||
window._sp_.config.ccpa = { | ||
includeGppApi: true, | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
case 'aus': | ||
window._sp_.config.ccpa = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
if (framework === 'tcfv2') { | ||
window._sp_.config.gdpr = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
} | ||
else { | ||
window._sp_.config.ccpa = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
} | ||
const spLib = document.createElement('script'); | ||
@@ -1089,3 +945,3 @@ spLib.id = 'sourcepoint-lib'; | ||
vendorData.localStorage.forEach((name) => { | ||
storage.local.remove(name); | ||
storage$1.local.remove(name); | ||
}); | ||
@@ -1095,3 +951,3 @@ } | ||
vendorData.sessionStorage.forEach((name) => { | ||
storage.session.remove(name); | ||
storage$1.session.remove(name); | ||
}); | ||
@@ -1116,2 +972,183 @@ } | ||
const hasConsentForUseCaseWithConsentState = (useCase, consentState) => { | ||
switch (useCase) { | ||
case "Targeted advertising": return (consentState.canTarget); | ||
case "Targeted marketing": { | ||
if ((consentState.tcfv2?.consents['1'] | ||
&& consentState.tcfv2?.consents['3'] | ||
&& consentState.tcfv2?.consents['7']) | ||
|| !consentState.ccpa?.doNotSell | ||
|| consentState.aus?.personalisedAdvertising) | ||
return (true); | ||
else | ||
return (false); | ||
} | ||
case "Essential": return (true); | ||
case "No consent required": return (true); | ||
default: return (false); | ||
} | ||
}; | ||
const cmpGetCookie = async ({ useCase, name, shouldMemoize, }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpGetCookieWithConsentState({ useCase, consentState, name, shouldMemoize })); | ||
}; | ||
const cmpGetCookieWithConsentState = ({ useCase, consentState, name, shouldMemoize }) => { | ||
console.log('in cmpGetCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
return getCookie({ name: name, shouldMemoize: shouldMemoize }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot get cookie ${name} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
}; | ||
const cmpSetCookie = async ({ useCase, name, value, daysToLive, isCrossSubdomain, }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpSetCookieWithConsentState({ useCase, consentState, name, value, daysToLive, isCrossSubdomain })); | ||
}; | ||
const cmpSetCookieWithConsentState = ({ useCase, consentState, name, value, daysToLive, isCrossSubdomain, }) => { | ||
console.log('in cmpSetCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
setCookie({ name: name, value: value, daysToLive: daysToLive, isCrossSubdomain: isCrossSubdomain }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot set cookie ${name} due to missing consent for use-case ${useCase}`); | ||
} | ||
}; | ||
const cmpSetSessionCookie = async ({ useCase, name, value }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpSetSessionCookieWithConsentState({ useCase, consentState, name, value })); | ||
}; | ||
const cmpSetSessionCookieWithConsentState = async ({ useCase, consentState, name, value }) => { | ||
console.log('in cmpSetSessionCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
setSessionCookie({ name: name, value: value }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot set cookie ${name} due to missing consent for use-case ${useCase}`); | ||
} | ||
}; | ||
class StorageFactory { | ||
#storageHandler; | ||
constructor(storageHandler) { | ||
this.#storageHandler = storageHandler; | ||
} | ||
isAvailable() { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return Boolean(storage$1.local.isAvailable()); | ||
} | ||
case 'sessionStorage': { | ||
return Boolean(storage$1.session.isAvailable()); | ||
} | ||
} | ||
} | ||
async get(useCase, key) { | ||
const consentState = await onConsent$1(); | ||
return (this.getWithConsentState(useCase, consentState, key)); | ||
} | ||
getWithConsentState(useCase, consentState, key) { | ||
console.log('in cmp get storage'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
console.log('in cmp get local'); | ||
return storage$1.local.get(key); | ||
} | ||
case 'sessionStorage': { | ||
console.log('in cmp get session'); | ||
return storage$1.session.get(key); | ||
} | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot get local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
} | ||
async set(useCase, key, value, expires) { | ||
const consentState = await onConsent$1(); | ||
return (this.setWithConsentState(useCase, consentState, key, value, expires)); | ||
} | ||
setWithConsentState(useCase, consentState, key, value, expires) { | ||
console.log('in cmp set storage'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': return storage$1.local.set(key, value, expires); | ||
case 'sessionStorage': return storage$1.session.set(key, value, expires); | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot set local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
} | ||
} | ||
remove(key) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return storage$1.local.remove(key); | ||
} | ||
case 'sessionStorage': { | ||
return storage$1.session.remove(key); | ||
} | ||
} | ||
} | ||
clear() { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return storage$1.local.clear(); | ||
} | ||
case 'sessionStorage': { | ||
return storage$1.session.clear(); | ||
} | ||
} | ||
} | ||
async getRaw(useCase, key) { | ||
const consentState = await onConsent$1(); | ||
return (this.getRawWithConsentState(useCase, consentState, key)); | ||
} | ||
getRawWithConsentState(useCase, consentState, key) { | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return storage$1.local.getRaw(key); | ||
} | ||
case 'sessionStorage': { | ||
return storage$1.session.getRaw(key); | ||
} | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot get local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
} | ||
async setRaw(useCase, key, value) { | ||
const consentState = await onConsent$1(); | ||
return (this.setRawWithConsentState(useCase, consentState, key, value)); | ||
} | ||
setRawWithConsentState(useCase, consentState, key, value) { | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': return storage$1.local.setRaw(key, value); | ||
case 'sessionStorage': return storage$1.session.setRaw(key, value); | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot set local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
} | ||
} | ||
} | ||
const storage = new (class { | ||
#local; | ||
#session; | ||
get local() { | ||
return (this.#local ||= new StorageFactory('localStorage')); | ||
} | ||
get session() { | ||
return (this.#session ||= new StorageFactory('sessionStorage')); | ||
} | ||
})(); | ||
if (!isServerSide) { | ||
@@ -1130,5 +1167,5 @@ window.guCmpHotFix ||= {}; | ||
if (window.guCmpHotFix.initialised) { | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240119094923") | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240122213831") | ||
console.warn('Two different versions of the CMP are running:', [ | ||
"0.0.0-beta-20240119094923", | ||
"0.0.0-beta-20240122213831", | ||
window.guCmpHotFix.cmp?.version, | ||
@@ -1171,3 +1208,3 @@ ]); | ||
showPrivacyManager, | ||
version: "0.0.0-beta-20240119094923", | ||
version: "0.0.0-beta-20240122213831", | ||
__isDisabled: isDisabled, | ||
@@ -1187,2 +1224,2 @@ __enable: enable, | ||
export { cmp, getConsentFor, onConsent, onConsentChange }; | ||
export { cmp, cmpGetCookie, cmpSetCookie, cmpSetSessionCookie, getConsentFor, onConsent, onConsentChange, storage }; |
@@ -258,124 +258,65 @@ 'use strict'; | ||
/* istanbul ignore file */ | ||
// Reference : https://docs.sourcepoint.com/hc/en-us/articles/18007731422099-Enable-GPP-Multi-State-Privacy-String-MSPS-with-U-S-Privacy-CCPA-solution | ||
const stub_gpp_ccpa = () => { | ||
(window.__gpp_addFrame = function (e) { | ||
if (!window.frames[e]) { | ||
if (document.body) { | ||
var t = document.createElement('iframe'); | ||
(t.style.cssText = 'display:none'), | ||
(t.name = e), | ||
document.body.appendChild(t); | ||
} else window.setTimeout(window.__gpp_addFrame, 10, e); | ||
/* | ||
This code is the CCPA stub made available by Sourcepoint. | ||
See the documentation on how to retrieve the latest version: | ||
https://documentation.sourcepoint.com/implementation/web-implementation/multi-campaign-web-implementation#stub-file | ||
*/ | ||
const stub_ccpa = () => { | ||
(function () { | ||
var e = false; | ||
var c = window; | ||
var t = document; | ||
function r() { | ||
if (!c.frames['__uspapiLocator']) { | ||
if (t.body) { | ||
var a = t.body; | ||
var e = t.createElement('iframe'); | ||
e.style.cssText = 'display:none'; | ||
e.name = '__uspapiLocator'; | ||
a.appendChild(e); | ||
} else { | ||
setTimeout(r, 5); | ||
} | ||
} | ||
} | ||
}), | ||
(window.__gpp_stub = function () { | ||
var e = arguments; | ||
if ( | ||
((__gpp.queue = __gpp.queue || []), | ||
(__gpp.events = __gpp.events || []), | ||
!e.length || (1 == e.length && 'queue' == e[0])) | ||
) { | ||
return __gpp.queue; | ||
r(); | ||
function p() { | ||
var a = arguments; | ||
__uspapi.a = __uspapi.a || []; | ||
if (!a.length) { | ||
return __uspapi.a; | ||
} else if (a[0] === 'ping') { | ||
a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true); | ||
} else { | ||
__uspapi.a.push([].slice.apply(a)); | ||
} | ||
if (1 == e.length && 'events' == e[0]) return __gpp.events; | ||
var t = e[0], | ||
p = e.length > 1 ? e[1] : null, | ||
n = e.length > 2 ? e[2] : null; | ||
if ('ping' === t) { | ||
return { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfcav2', 'uspv1'], | ||
cmpId: 31, | ||
}; | ||
} | ||
if ('addEventListener' === t) { | ||
'lastId' in __gpp || (__gpp.lastId = 0), __gpp.lastId++; | ||
var a = __gpp.lastId; | ||
return ( | ||
__gpp.events.push({ id: a, callback: p, parameter: n }), | ||
{ | ||
eventName: 'listenerRegistered', | ||
listenerId: a, | ||
data: !0, | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
} | ||
); | ||
} | ||
if ('removeEventListener' === t) { | ||
for (var s = !1, i = 0; i < __gpp.events.length; i++) { | ||
if (__gpp.events[i].id == n) { | ||
__gpp.events.splice(i, 1), (s = !0); | ||
break; | ||
} | ||
} | ||
return { | ||
eventName: 'listenerRemoved', | ||
listenerId: n, | ||
data: s, | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
}; | ||
} | ||
return 'getGPPData' === t | ||
? { | ||
sectionId: 3, | ||
gppVersion: 1, | ||
sectionList: [], | ||
applicableSections: [0], | ||
gppString: '', | ||
pingData: { | ||
gppVersion: '1.0', | ||
cmpStatus: 'stub', | ||
cmpDisplayStatus: 'hidden', | ||
supportedAPIs: ['tcfeuv2', 'tcfva', 'usnat'], | ||
cmpId: 31, | ||
}, | ||
} | ||
: 'hasSection' === t || 'getSection' === t || 'getField' === t | ||
? null | ||
: void __gpp.queue.push([].slice.apply(e)); | ||
}), | ||
(window.__gpp_msghandler = function (e) { | ||
var t = 'string' == typeof e.data; | ||
} | ||
function l(t) { | ||
var r = typeof t.data === 'string'; | ||
try { | ||
var p = t ? JSON.parse(e.data) : e.data; | ||
} catch (e) { | ||
p = null; | ||
} | ||
if ('object' == typeof p && null !== p && '__gppCall' in p) { | ||
var n = p.__gppCall; | ||
window.__gpp( | ||
n.command, | ||
function (p, a) { | ||
var s = { | ||
__gppReturn: { | ||
returnValue: p, | ||
success: a, | ||
var a = r ? JSON.parse(t.data) : t.data; | ||
if (a.__cmpCall) { | ||
var n = a.__cmpCall; | ||
c.__uspapi(n.command, n.parameter, function (a, e) { | ||
var c = { | ||
__cmpReturn: { | ||
returnValue: a, | ||
success: e, | ||
callId: n.callId, | ||
}, | ||
}; | ||
e.source.postMessage(t ? JSON.stringify(s) : s, '*'); | ||
}, | ||
'parameter' in n ? n.parameter : null, | ||
'version' in n ? n.version : 1, | ||
); | ||
} | ||
}), | ||
('__gpp' in window && 'function' == typeof window.__gpp) || | ||
((window.__gpp = window.__gpp_stub), | ||
window.addEventListener('message', window.__gpp_msghandler, !1), | ||
window.__gpp_addFrame('__gppLocator')); | ||
t.source.postMessage(r ? JSON.stringify(c) : c, '*'); | ||
}); | ||
} | ||
} catch (a) {} | ||
} | ||
if (typeof __uspapi !== 'function') { | ||
c.__uspapi = p; | ||
__uspapi.msgHandler = l; | ||
c.addEventListener('message', l, false); | ||
} | ||
})(); | ||
}; | ||
@@ -691,82 +632,7 @@ | ||
/* eslint-disable -- this is third party code */ | ||
/* istanbul ignore file */ | ||
/* | ||
This code is the CCPA stub made available by Sourcepoint. | ||
See the documentation on how to retrieve the latest version: | ||
https://documentation.sourcepoint.com/implementation/web-implementation/multi-campaign-web-implementation#stub-file | ||
*/ | ||
const stub_uspapi_ccpa = () => { | ||
(function () { | ||
var e = false; | ||
var c = window; | ||
var t = document; | ||
function r() { | ||
if (!c.frames['__uspapiLocator']) { | ||
if (t.body) { | ||
var a = t.body; | ||
var e = t.createElement('iframe'); | ||
e.style.cssText = 'display:none'; | ||
e.name = '__uspapiLocator'; | ||
a.appendChild(e); | ||
} else { | ||
setTimeout(r, 5); | ||
} | ||
} | ||
} | ||
r(); | ||
function p() { | ||
var a = arguments; | ||
__uspapi.a = __uspapi.a || []; | ||
if (!a.length) { | ||
return __uspapi.a; | ||
} else if (a[0] === 'ping') { | ||
a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true); | ||
} else { | ||
__uspapi.a.push([].slice.apply(a)); | ||
} | ||
} | ||
function l(t) { | ||
var r = typeof t.data === 'string'; | ||
try { | ||
var a = r ? JSON.parse(t.data) : t.data; | ||
if (a.__cmpCall) { | ||
var n = a.__cmpCall; | ||
c.__uspapi(n.command, n.parameter, function (a, e) { | ||
var c = { | ||
__cmpReturn: { | ||
returnValue: a, | ||
success: e, | ||
callId: n.callId, | ||
}, | ||
}; | ||
t.source.postMessage(r ? JSON.stringify(c) : c, '*'); | ||
}); | ||
} | ||
} catch (a) {} | ||
} | ||
if (typeof __uspapi !== 'function') { | ||
c.__uspapi = p; | ||
__uspapi.msgHandler = l; | ||
c.addEventListener('message', l, false); | ||
} | ||
})(); | ||
}; | ||
const stub = (framework) => { | ||
switch (framework) { | ||
case 'tcfv2': | ||
stub_tcfv2(); | ||
break; | ||
case 'ccpa': | ||
stub_uspapi_ccpa(); | ||
stub_gpp_ccpa(); | ||
break; | ||
case 'aus': | ||
stub_uspapi_ccpa(); | ||
break; | ||
} | ||
if (framework === 'tcfv2') | ||
stub_tcfv2(); | ||
else | ||
stub_ccpa(); | ||
}; | ||
@@ -870,26 +736,16 @@ | ||
}; | ||
switch (framework) { | ||
case 'tcfv2': | ||
window._sp_.config.gdpr = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
case 'ccpa': | ||
window._sp_.config.ccpa = { | ||
includeGppApi: true, | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
case 'aus': | ||
window._sp_.config.ccpa = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
break; | ||
if (framework === 'tcfv2') { | ||
window._sp_.config.gdpr = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
} | ||
else { | ||
window._sp_.config.ccpa = { | ||
targetingParams: { | ||
framework, | ||
}, | ||
}; | ||
} | ||
const spLib = document.createElement('script'); | ||
@@ -1118,2 +974,183 @@ spLib.id = 'sourcepoint-lib'; | ||
const hasConsentForUseCaseWithConsentState = (useCase, consentState) => { | ||
switch (useCase) { | ||
case "Targeted advertising": return (consentState.canTarget); | ||
case "Targeted marketing": { | ||
if ((consentState.tcfv2?.consents['1'] | ||
&& consentState.tcfv2?.consents['3'] | ||
&& consentState.tcfv2?.consents['7']) | ||
|| !consentState.ccpa?.doNotSell | ||
|| consentState.aus?.personalisedAdvertising) | ||
return (true); | ||
else | ||
return (false); | ||
} | ||
case "Essential": return (true); | ||
case "No consent required": return (true); | ||
default: return (false); | ||
} | ||
}; | ||
const cmpGetCookie = async ({ useCase, name, shouldMemoize, }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpGetCookieWithConsentState({ useCase, consentState, name, shouldMemoize })); | ||
}; | ||
const cmpGetCookieWithConsentState = ({ useCase, consentState, name, shouldMemoize }) => { | ||
console.log('in cmpGetCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
return libs.getCookie({ name: name, shouldMemoize: shouldMemoize }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot get cookie ${name} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
}; | ||
const cmpSetCookie = async ({ useCase, name, value, daysToLive, isCrossSubdomain, }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpSetCookieWithConsentState({ useCase, consentState, name, value, daysToLive, isCrossSubdomain })); | ||
}; | ||
const cmpSetCookieWithConsentState = ({ useCase, consentState, name, value, daysToLive, isCrossSubdomain, }) => { | ||
console.log('in cmpSetCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
libs.setCookie({ name: name, value: value, daysToLive: daysToLive, isCrossSubdomain: isCrossSubdomain }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot set cookie ${name} due to missing consent for use-case ${useCase}`); | ||
} | ||
}; | ||
const cmpSetSessionCookie = async ({ useCase, name, value }) => { | ||
const consentState = await onConsent$1(); | ||
return (cmpSetSessionCookieWithConsentState({ useCase, consentState, name, value })); | ||
}; | ||
const cmpSetSessionCookieWithConsentState = async ({ useCase, consentState, name, value }) => { | ||
console.log('in cmpSetSessionCookie'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
libs.setSessionCookie({ name: name, value: value }); | ||
} | ||
else { | ||
console.error('cmp', `Cannot set cookie ${name} due to missing consent for use-case ${useCase}`); | ||
} | ||
}; | ||
class StorageFactory { | ||
#storageHandler; | ||
constructor(storageHandler) { | ||
this.#storageHandler = storageHandler; | ||
} | ||
isAvailable() { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return Boolean(libs.storage.local.isAvailable()); | ||
} | ||
case 'sessionStorage': { | ||
return Boolean(libs.storage.session.isAvailable()); | ||
} | ||
} | ||
} | ||
async get(useCase, key) { | ||
const consentState = await onConsent$1(); | ||
return (this.getWithConsentState(useCase, consentState, key)); | ||
} | ||
getWithConsentState(useCase, consentState, key) { | ||
console.log('in cmp get storage'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
console.log('in cmp get local'); | ||
return libs.storage.local.get(key); | ||
} | ||
case 'sessionStorage': { | ||
console.log('in cmp get session'); | ||
return libs.storage.session.get(key); | ||
} | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot get local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
} | ||
async set(useCase, key, value, expires) { | ||
const consentState = await onConsent$1(); | ||
return (this.setWithConsentState(useCase, consentState, key, value, expires)); | ||
} | ||
setWithConsentState(useCase, consentState, key, value, expires) { | ||
console.log('in cmp set storage'); | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': return libs.storage.local.set(key, value, expires); | ||
case 'sessionStorage': return libs.storage.session.set(key, value, expires); | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot set local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
} | ||
} | ||
remove(key) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return libs.storage.local.remove(key); | ||
} | ||
case 'sessionStorage': { | ||
return libs.storage.session.remove(key); | ||
} | ||
} | ||
} | ||
clear() { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return libs.storage.local.clear(); | ||
} | ||
case 'sessionStorage': { | ||
return libs.storage.session.clear(); | ||
} | ||
} | ||
} | ||
async getRaw(useCase, key) { | ||
const consentState = await onConsent$1(); | ||
return (this.getRawWithConsentState(useCase, consentState, key)); | ||
} | ||
getRawWithConsentState(useCase, consentState, key) { | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': { | ||
return libs.storage.local.getRaw(key); | ||
} | ||
case 'sessionStorage': { | ||
return libs.storage.session.getRaw(key); | ||
} | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot get local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
return (null); | ||
} | ||
} | ||
async setRaw(useCase, key, value) { | ||
const consentState = await onConsent$1(); | ||
return (this.setRawWithConsentState(useCase, consentState, key, value)); | ||
} | ||
setRawWithConsentState(useCase, consentState, key, value) { | ||
if (hasConsentForUseCaseWithConsentState(useCase, consentState)) { | ||
switch (this.#storageHandler) { | ||
case 'localStorage': return libs.storage.local.setRaw(key, value); | ||
case 'sessionStorage': return libs.storage.session.setRaw(key, value); | ||
} | ||
} | ||
else { | ||
console.error('cmp', `Cannot set local storage item ${key} due to missing consent for use-case ${useCase}`); | ||
} | ||
} | ||
} | ||
const storage = new (class { | ||
#local; | ||
#session; | ||
get local() { | ||
return (this.#local ||= new StorageFactory('localStorage')); | ||
} | ||
get session() { | ||
return (this.#session ||= new StorageFactory('sessionStorage')); | ||
} | ||
})(); | ||
if (!isServerSide) { | ||
@@ -1132,5 +1169,5 @@ window.guCmpHotFix ||= {}; | ||
if (window.guCmpHotFix.initialised) { | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240119094923") | ||
if (window.guCmpHotFix.cmp?.version !== "0.0.0-beta-20240122213831") | ||
console.warn('Two different versions of the CMP are running:', [ | ||
"0.0.0-beta-20240119094923", | ||
"0.0.0-beta-20240122213831", | ||
window.guCmpHotFix.cmp?.version, | ||
@@ -1173,3 +1210,3 @@ ]); | ||
showPrivacyManager, | ||
version: "0.0.0-beta-20240119094923", | ||
version: "0.0.0-beta-20240122213831", | ||
__isDisabled: isDisabled, | ||
@@ -1190,4 +1227,8 @@ __enable: enable, | ||
exports.cmp = cmp; | ||
exports.cmpGetCookie = cmpGetCookie; | ||
exports.cmpSetCookie = cmpSetCookie; | ||
exports.cmpSetSessionCookie = cmpSetSessionCookie; | ||
exports.getConsentFor = getConsentFor; | ||
exports.onConsent = onConsent; | ||
exports.onConsentChange = onConsentChange; | ||
exports.storage = storage; |
@@ -8,5 +8,1 @@ export interface CCPAConsentState { | ||
} | ||
export interface GPPData { | ||
gppVersion: number; | ||
gppString: string; | ||
} |
{ | ||
"name": "@guardian/consent-management-platform", | ||
"version": "0.0.0-beta-20240119094923", | ||
"version": "0.0.0-beta-20240122213831", | ||
"description": "Consent management for *.theguardian.com.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/guardian/consent-management-platform.git", |
118724
63
2958