@usercentrics/cmp-web-sdk
Version:
Please visit our official [https://usercentrics.com/docs/web/implementation/sdk/][docs] (alpha version, not to be used in production).
106 lines (97 loc) • 3.96 kB
JavaScript
import {SignalStatus as $5cwui$SignalStatus, CmpStatus as $5cwui$CmpStatus, CmpDisplayStatus as $5cwui$CmpDisplayStatus, CmpApi as $5cwui$CmpApi} from "@iabgpp/cmpapi";
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var $parcel$global = globalThis;
var parcelRequire = $parcel$global["parcelRequire94c2"];
var parcelRegister = parcelRequire.register;
parcelRegister("lzCWz", function(module, exports) {
$parcel$export(module.exports, "GppService", () => $41296cacd4eca75c$export$ade638b431c827be);
const $41296cacd4eca75c$var$APPLICABLE_SECTIONS = {
tcfeuv2: 2,
tcfcav1: 5,
uspv1: 6,
usnat: 7,
usca: 8,
usva: 9,
usco: 10,
usut: 11,
usct: 12
};
class $41296cacd4eca75c$export$ade638b431c827be {
// Applicable Sections (https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform/blob/main/Sections/Section%20Information.md)
// 2: tcfeuv2 (TCF V2)
// 5: tcfcav1 (TCF Canada)
// 6: uspv1 (US - USPrivacy String)
// 7: usnat (US - national section)
// 8: usca (US - California section)
// 9: usva (US - Virginia section)
// 10 usco (US - Colorado section)
// 11 usut (US - Utah section)
// 12 usct (US - Connecticut section)
constructor({ cmpId: cmpId, cmpVersion: cmpVersion }){
this.legalFramework = 'tcfeuv2';
this.setApplicableSections = (legalFramework)=>{
try {
this.gppApi.setApplicableSections([
$41296cacd4eca75c$var$APPLICABLE_SECTIONS[legalFramework]
]);
} catch (error) {
throw new Error(`GppService - setApplicableSections - unrecognized legal framework "${legalFramework}"`);
}
};
this.setCmpSignalReady = async ()=>{
this.gppApi.setSignalStatus((0, $5cwui$SignalStatus).READY);
};
this.setCmpStatusLoaded = async ()=>{
this.gppApi.setCmpStatus((0, $5cwui$CmpStatus).LOADED);
};
this.setCmpDisplayHidden = async ()=>{
this.gppApi.setCmpDisplayStatus((0, $5cwui$CmpDisplayStatus).HIDDEN);
};
this.setCmpDisplayVisible = async ()=>{
this.gppApi.setCmpDisplayStatus((0, $5cwui$CmpDisplayStatus).VISIBLE);
};
this.setSectionString = async (sectionString, settingsType, legislation)=>{
const gppLegalFramework = this.getGppLegalFramework(settingsType, legislation);
if (sectionString !== '') {
this.gppApi.setSectionString(gppLegalFramework, sectionString);
this.gppApi.fireSectionChange(gppLegalFramework);
}
};
this.gppApi = new (0, $5cwui$CmpApi)(cmpId, cmpVersion);
this.gppApi.setCmpStatus((0, $5cwui$CmpStatus).LOADING);
this.gppApi.setSignalStatus((0, $5cwui$SignalStatus).NOT_READY);
}
getGppLegalFramework(settingsType, legislation) {
if (settingsType === 'TCF') return 'tcfeuv2'; // TODO what about Canada?
// UCPA -> Utah -> usut
// CTDPA -> Connecticut -> usct
// VCDPA -> Virginia -> usva
// CPRA -> California -> usca
// CPA -> Colorado -> usco
// US -> uspv1
switch(legislation){
case 'UCPA':
return 'usut';
case 'CTDPA':
return 'usct';
case 'VCDPA':
return 'usva';
case 'CPRA':
return 'usca';
case 'CPA':
return 'usco';
default:
return 'uspv1';
}
}
applyApplicableSections(settingsType, legislation) {
this.setApplicableSections(this.getGppLegalFramework(settingsType, legislation));
}
resetGpp() {
this.gppApi = {};
}
}
var $41296cacd4eca75c$export$2e2bcd8739ae039 = $41296cacd4eca75c$export$ade638b431c827be;
});