@adv-ui/boros-tcf
Version:
Adevinta GDPR - Transparency and Consent Framework - API
125 lines (102 loc) • 3.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VendorAcceptanceStatus = void 0;
var VendorAcceptanceStatus = /*#__PURE__*/function () {
function VendorAcceptanceStatus(_ref) {
var consent = _ref.consent,
vendorList = _ref.vendorList;
this._consent = consent;
this._vendorList = vendorList;
this._status = {
consents: STATUS_UNKNOWN,
legitimateInterests: STATUS_UNKNOWN
};
this._initialize();
}
var _proto = VendorAcceptanceStatus.prototype;
_proto.resolveConsent = function resolveConsent(_ref2) {
var current = _ref2.current;
return this._resolve({
node: NODE_CONSENTS,
current: current
});
};
_proto.resolveLegitimateInterest = function resolveLegitimateInterest(_ref3) {
var current = _ref3.current;
return this._resolve({
node: NODE_LEGITIMATE_INTERESTS,
current: current
});
};
_proto.isValid = function isValid() {
return this._isSetToAll({
node: NODE_CONSENTS
}) && this._isSetToAll({
node: NODE_LEGITIMATE_INTERESTS
});
};
_proto._initialize = function _initialize() {
var _this = this;
this._vendorList.vendorsWithPurposes().forEach(function (id) {
var accepted = _this._vendorNodeStatus({
id: id,
node: NODE_CONSENTS
});
_this._update({
node: NODE_CONSENTS,
accepted: accepted
});
});
this._vendorList.vendorsWithLegitimateInterests().forEach(function (id) {
var accepted = _this._vendorNodeStatus({
id: id,
node: NODE_LEGITIMATE_INTERESTS
});
_this._update({
node: NODE_LEGITIMATE_INTERESTS,
accepted: accepted
});
});
};
_proto._isSetToAll = function _isSetToAll(_ref4) {
var node = _ref4.node;
return this._status[node] === STATUS_ALL_TRUE || this._status[node] === STATUS_ALL_FALSE;
};
_proto._resolve = function _resolve(_ref5) {
var node = _ref5.node,
_ref5$current = _ref5.current,
current = _ref5$current === void 0 ? false : _ref5$current;
switch (this._status[node]) {
case STATUS_ALL_TRUE:
return true;
case STATUS_ALL_FALSE:
return false;
default:
return current;
}
};
_proto._update = function _update(_ref6) {
var node = _ref6.node,
accepted = _ref6.accepted;
if (this._status[node] === STATUS_UNKNOWN) {
this._status[node] = accepted === true ? STATUS_ALL_TRUE : STATUS_ALL_FALSE;
} else if (this._status[node] === STATUS_ALL_TRUE && accepted === false || this._status[node] === STATUS_ALL_FALSE && accepted === true) {
this._status[node] = STATUS_MIXED;
}
};
_proto._vendorNodeStatus = function _vendorNodeStatus(_ref7) {
var id = _ref7.id,
node = _ref7.node;
return this._consent.vendor[node].hasOwnProperty(id) && this._consent.vendor[node][id] || false;
};
return VendorAcceptanceStatus;
}();
exports.VendorAcceptanceStatus = VendorAcceptanceStatus;
var STATUS_UNKNOWN = 0;
var STATUS_ALL_TRUE = 1;
var STATUS_ALL_FALSE = 2;
var STATUS_MIXED = 3; // has true and false consents
var NODE_CONSENTS = 'consents';
var NODE_LEGITIMATE_INTERESTS = 'legitimateInterests';