UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

106 lines (85 loc) 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsentAcceptanceStatus = void 0; var ConsentAcceptanceStatus = /*#__PURE__*/function () { function ConsentAcceptanceStatus(_ref) { var consent = _ref.consent, vendorList = _ref.vendorList; this._consent = consent; this._vendorList = vendorList; this._status = { purposeConsents: STATUS_UNKNOWN, specialFeatures: STATUS_UNKNOWN }; this._initialize(); } var _proto = ConsentAcceptanceStatus.prototype; _proto.isValid = function isValid() { var _this$_consent$scope, _this$_consent$scope$; var allTrue = this._status[NODE_PURPOSE_CONSENTS] === STATUS_ALL_TRUE && this._status[NODE_SPECIAL_FEATURES] === STATUS_ALL_TRUE; if (allTrue || typeof ((_this$_consent$scope = this._consent.scope) == null ? void 0 : (_this$_consent$scope$ = _this$_consent$scope.options) == null ? void 0 : _this$_consent$scope$.onRejectionResurfaceAfterDays) !== 'number') { return true; } var now = Date.now(); var consentDate = this._consent.lastUpdated || this._consent.created || new Date(); var timeDiffInMillis = now - consentDate.valueOf(); var timeDiffInDays = Math.floor(timeDiffInMillis / DAY_IN_MILLIS); var isNotExpired = timeDiffInDays < this._consent.scope.options.onRejectionResurfaceAfterDays; return isNotExpired; }; _proto._initialize = function _initialize() { var _this = this; Object.keys(this._vendorList.purposes).filter(function (id) { var _this$_consent$scope2; return !((_this$_consent$scope2 = _this._consent.scope) != null && _this$_consent$scope2.purposes) || _this._consent.scope.purposes.indexOf(parseInt(id)) > -1; }).forEach(function (id) { var accepted = _this._purposeConsentStatus({ id: id }); _this._update({ node: NODE_PURPOSE_CONSENTS, accepted: accepted }); }); Object.keys(this._vendorList.specialFeatures).filter(function (id) { var _this$_consent$scope3; return !((_this$_consent$scope3 = _this._consent.scope) != null && _this$_consent$scope3.specialFeatures) || _this._consent.scope.specialFeatures.indexOf(parseInt(id)) > -1; }).forEach(function (id) { var accepted = _this._specialFeatureStatus({ id: id }); _this._update({ node: NODE_SPECIAL_FEATURES, accepted: accepted }); }); }; _proto._update = function _update(_ref2) { var node = _ref2.node, accepted = _ref2.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._purposeConsentStatus = function _purposeConsentStatus(_ref3) { var id = _ref3.id; return this._consent.purpose.consents.hasOwnProperty(id) && this._consent.purpose.consents[id] || false; }; _proto._specialFeatureStatus = function _specialFeatureStatus(_ref4) { var id = _ref4.id; return this._consent.specialFeatures.hasOwnProperty(id) && this._consent.specialFeatures[id] || false; }; return ConsentAcceptanceStatus; }(); exports.ConsentAcceptanceStatus = ConsentAcceptanceStatus; var DAY_IN_MILLIS = 86400000; 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_PURPOSE_CONSENTS = 'purposeConsents'; var NODE_SPECIAL_FEATURES = 'specialFeatures';