@adv-ui/boros-tcf
Version:
Adevinta GDPR - Transparency and Consent Framework - API
112 lines (88 loc) • 3.39 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CookieConsentRepository = void 0;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/inheritsLoose"));
var _ConsentRepository2 = require("../../domain/consent/ConsentRepository");
var _ioc = require("../../core/ioc/ioc");
var CookieConsentRepository = /*#__PURE__*/function (_ConsentRepository) {
(0, _inheritsLoose2["default"])(CookieConsentRepository, _ConsentRepository);
function CookieConsentRepository(_temp) {
var _this;
var _ref = _temp === void 0 ? {} : _temp,
window = _ref.window,
scope = _ref.scope,
_ref$euconsentCookieS = _ref.euconsentCookieStorage,
euconsentCookieStorage = _ref$euconsentCookieS === void 0 ? (0, _ioc.inject)('euconsentCookieStorage') : _ref$euconsentCookieS,
_ref$borosTcfCookieSt = _ref.borosTcfCookieStorage,
borosTcfCookieStorage = _ref$borosTcfCookieSt === void 0 ? (0, _ioc.inject)('borosTcfCookieStorage') : _ref$borosTcfCookieSt;
_this = _ConsentRepository.call(this) || this;
_this._window = window;
_this._scope = scope;
_this._euconsentCookieStorage = euconsentCookieStorage;
_this._borosTcfCookieStorage = borosTcfCookieStorage;
return _this;
}
var _proto = CookieConsentRepository.prototype;
_proto.loadUserConsent = function loadUserConsent() {
try {
return this._euconsentCookieStorage.load() || '';
} catch (error) {
return '';
}
};
_proto.saveUserConsent = function saveUserConsent(_ref2) {
var encodedConsent = _ref2.encodedConsent,
decodedConsent = _ref2.decodedConsent;
this._euconsentCookieStorage.save({
data: encodedConsent
});
try {
var data = this._encodeBorosTcfData({
data: decodedConsent
});
this._borosTcfCookieStorage.save({
data: data
});
} catch (ignored) {}
};
_proto._encodeBorosTcfData = function _encodeBorosTcfData(_ref3) {
var data = _ref3.data;
var policyVersion = data.policyVersion,
cmpVersion = data.cmpVersion,
purpose = data.purpose,
specialFeatures = data.specialFeatures,
vendor = data.vendor;
var scopedInterestVendorConsents = this._scopedInterestConsentOnVendors({
vendors: vendor.consents
});
var usedData = {
policyVersion: policyVersion,
cmpVersion: cmpVersion,
purpose: {
consents: purpose.consents
},
specialFeatures: specialFeatures,
vendor: {
consents: scopedInterestVendorConsents
}
};
var stringData = JSON.stringify(usedData);
var base64Data = this._window.btoa(stringData);
return base64Data;
};
_proto._scopedInterestConsentOnVendors = function _scopedInterestConsentOnVendors(_ref4) {
var _this$_scope;
var vendors = _ref4.vendors;
var consents = {};
var scopedVendors = ((_this$_scope = this._scope) == null ? void 0 : _this$_scope.interestConsentVendors) || [];
scopedVendors.forEach(function (key) {
consents[key] = vendors[key] === true;
});
return consents;
};
return CookieConsentRepository;
}(_ConsentRepository2.ConsentRepository);
exports.CookieConsentRepository = CookieConsentRepository;