UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

220 lines (202 loc) 7.24 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Consent = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/extends")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createClass")); var _constants = require("../../core/constants"); var _VendorAcceptanceStatus = require("../vendorlist/VendorAcceptanceStatus"); var _ConsentAcceptanceStatus = require("./ConsentAcceptanceStatus"); var Consent = /*#__PURE__*/function () { /** * * @param {Object} param * @param {Object} param.scope * @param {Object} param.vendor * @param {Object.<Number, Boolean>} param.vendor.consents * @param {Object.<Number, Boolean>} param.vendor.legitimateInterests * @param {Object} param.purpose * @param {Object.<Number, Boolean>} param.purpose.consents * @param {Object.<Number, Boolean>} param.purpose.legitimateInterests * @param {Object} [param.publisher] * @param {Object.<Number, Boolean>} param.publisher.consents * @param {Object.<Number, Boolean>} param.publisher.legitimateInterests * @param {Object} param.publisher.customPurpose * @param {Object} param.publisher.restrictions * @param {Object.<Number, Boolean>} param.specialFeatures * @param {boolean} [param.valid] * @param {boolean} [param.isNew] */ function Consent(_ref) { var _ref$scope = _ref.scope, scope = _ref$scope === void 0 ? {} : _ref$scope, _ref$cmpId = _ref.cmpId, cmpId = _ref$cmpId === void 0 ? _constants.BOROS_TCF_ID : _ref$cmpId, _ref$cmpVersion = _ref.cmpVersion, cmpVersion = _ref$cmpVersion === void 0 ? _constants.BOROS_TCF_VERSION : _ref$cmpVersion, created = _ref.created, lastUpdated = _ref.lastUpdated, _ref$policyVersion = _ref.policyVersion, policyVersion = _ref$policyVersion === void 0 ? _constants.TCF_API_VERSION : _ref$policyVersion, vendorListVersion = _ref.vendorListVersion, _ref$publisherCC = _ref.publisherCC, publisherCC = _ref$publisherCC === void 0 ? _constants.PUBLISHER_CC : _ref$publisherCC, _ref$isServiceSpecifi = _ref.isServiceSpecific, isServiceSpecific = _ref$isServiceSpecifi === void 0 ? true : _ref$isServiceSpecifi, _ref$useNonStandardSt = _ref.useNonStandardStacks, useNonStandardStacks = _ref$useNonStandardSt === void 0 ? false : _ref$useNonStandardSt, _ref$purposeOneTreatm = _ref.purposeOneTreatment, purposeOneTreatment = _ref$purposeOneTreatm === void 0 ? false : _ref$purposeOneTreatm, vendor = _ref.vendor, purpose = _ref.purpose, specialFeatures = _ref.specialFeatures, _ref$publisher = _ref.publisher, publisher = _ref$publisher === void 0 ? { consents: {}, legitimateInterests: {}, customPurpose: {}, restrictions: {} } : _ref$publisher, _ref$valid = _ref.valid, valid = _ref$valid === void 0 ? false : _ref$valid, _ref$isNew = _ref.isNew, isNew = _ref$isNew === void 0 ? false : _ref$isNew; this._scope = scope; this._cmpId = cmpId; this._cmpVersion = cmpVersion; this._created = created; this._lastUpdated = lastUpdated; this._policyVersion = policyVersion; this._vendorListVersion = vendorListVersion; this._publisherCC = publisherCC; this._isServiceSpecific = isServiceSpecific; this._useNonStandardStacks = useNonStandardStacks; this._purposeOneTreatment = purposeOneTreatment; this._vendor = vendor; this._purpose = purpose; this._specialFeatures = specialFeatures; this._publisher = publisher; this._valid = valid; this._isNew = isNew; } var _proto = Consent.prototype; _proto.checkValidity = function checkValidity(_ref2) { var _this = this; var consentVendorList = _ref2.consentVendorList, newVendorList = _ref2.newVendorList; if (!newVendorList && this._vendorListVersion !== consentVendorList.version) { this._valid = false; return; } var consentAcceptanceStatus = new _ConsentAcceptanceStatus.ConsentAcceptanceStatus({ consent: this, vendorList: consentVendorList }); var validConsentVendors = true; if (newVendorList && newVendorList.version !== this._vendorListVersion) { var updated = { consents: {}, legitimateInterests: {} }; var consentVendorsAcceptanceStatus = new _VendorAcceptanceStatus.VendorAcceptanceStatus({ consent: this, vendorList: consentVendorList }); Object.keys(newVendorList.vendors).forEach(function (key) { updated.consents[key] = consentVendorsAcceptanceStatus.resolveConsent({ current: _this._vendor.consents[key] }); updated.legitimateInterests[key] = consentVendorsAcceptanceStatus.resolveLegitimateInterest({ current: _this._vendor.legitimateInterests[key] }); }); this._vendor = updated; this._vendorListVersion = newVendorList.version; validConsentVendors = consentVendorsAcceptanceStatus.isValid(); } this._valid = consentAcceptanceStatus.isValid() && validConsentVendors; }; _proto.toJSON = function toJSON() { return { cmpId: this._cmpId, cmpVersion: this._cmpVersion, policyVersion: this._policyVersion, vendorListVersion: this._vendorListVersion, publisherCC: this._publisherCC, isServiceSpecific: this._isServiceSpecific, useNonStandardStacks: this._useNonStandardStacks, purposeOneTreatment: this._purposeOneTreatment, vendor: (0, _extends2["default"])({}, this._vendor), purpose: (0, _extends2["default"])({}, this._purpose), specialFeatures: (0, _extends2["default"])({}, this._specialFeatures), publisher: (0, _extends2["default"])({}, this._publisher), valid: this._valid, isNew: this._isNew }; }; (0, _createClass2["default"])(Consent, [{ key: "vendor", get: function get() { return this._vendor; } }, { key: "purpose", get: function get() { return this._purpose; } }, { key: "publisher", get: function get() { return this._publisher; } }, { key: "specialFeatures", get: function get() { return this._specialFeatures; } }, { key: "isNew", get: function get() { return this._isNew; } }, { key: "valid", get: function get() { return this._valid; } }, { key: "cmpVersion", get: function get() { return this._cmpVersion; } }, { key: "policyVersion", get: function get() { return this._policyVersion; } }, { key: "vendorListVersion", get: function get() { return this._vendorListVersion; } }, { key: "created", get: function get() { return this._created; } }, { key: "lastUpdated", get: function get() { return this._lastUpdated; } }, { key: "scope", get: function get() { return this._scope; } }]); return Consent; }(); exports.Consent = Consent;