UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

117 lines (90 loc) 3.98 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.GetTCDataUseCase = void 0; var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/inheritsLoose")); var _ioc = require("../../../core/ioc/ioc"); var _TCData = require("../../../domain/tcdata/TCData"); var _ConsentRepository = require("../../../domain/consent/ConsentRepository"); var _ConsentDecoderService = require("../../../domain/consent/ConsentDecoderService"); var _StatusRepository = require("../../../domain/status/StatusRepository"); var _ConsentFactory = require("../../../domain/consent/ConsentFactory"); var _SyncUseCase2 = require("../SyncUseCase"); var GetTCDataUseCase = /*#__PURE__*/function (_SyncUseCase) { (0, _inheritsLoose2["default"])(GetTCDataUseCase, _SyncUseCase); /** * * @param {Object} param * @param {StatusRepository} param.statusRepository */ function GetTCDataUseCase(_temp) { var _this; var _ref = _temp === void 0 ? {} : _temp, _ref$statusRepository = _ref.statusRepository, statusRepository = _ref$statusRepository === void 0 ? (0, _ioc.inject)(_StatusRepository.StatusRepository) : _ref$statusRepository, _ref$consentRepositor = _ref.consentRepository, consentRepository = _ref$consentRepositor === void 0 ? (0, _ioc.inject)(_ConsentRepository.ConsentRepository) : _ref$consentRepositor, _ref$consentDecoderSe = _ref.consentDecoderService, consentDecoderService = _ref$consentDecoderSe === void 0 ? (0, _ioc.inject)(_ConsentDecoderService.ConsentDecoderService) : _ref$consentDecoderSe, _ref$consentFactory = _ref.consentFactory, consentFactory = _ref$consentFactory === void 0 ? (0, _ioc.inject)(_ConsentFactory.ConsentFactory) : _ref$consentFactory; _this = _SyncUseCase.call(this) || this; _this._statusRepository = statusRepository; _this._consentRepository = consentRepository; _this._consentDecoderService = consentDecoderService; _this._consentFactory = consentFactory; return _this; } /** * * @param {Object} param * @param {Array<Number>} param.vendorIds */ var _proto = GetTCDataUseCase.prototype; _proto.execute = function execute(_temp2) { var _ref2 = _temp2 === void 0 ? {} : _temp2, vendorIds = _ref2.vendorIds; if (Array.isArray(vendorIds) && vendorIds.some(function (vendorId) { return !Number.isInteger(vendorId) || vendorId < 1; })) { throw Error('vendorIds parameter of getTCData has invalid data. It must be an array of positive integers, or undefined'); } else if (vendorIds !== undefined && !Array.isArray(vendorIds)) { throw Error('vendorIds, if defined, needs to be an array of positive integers'); } var _this$_statusReposito = this._statusRepository.getStatus(), cmpStatus = _this$_statusReposito.cmpStatus, eventStatus = _this$_statusReposito.eventStatus; var encodedConsent = this._consentRepository.loadUserConsent(); var tcModel; if (encodedConsent) { tcModel = this._consentDecoderService.decode({ encodedConsent: encodedConsent }); } else { tcModel = this._consentFactory.createEmpty().toJSON(); } var vendor; if (!vendorIds) { vendor = tcModel.vendor; } else { vendor = {}; Object.entries(tcModel.vendor).forEach(function (_ref3) { var key = _ref3[0], value = _ref3[1]; return vendorIds.includes(key) && (vendor[key] = value); }); } var tcData = new _TCData.TCData({ tcString: encodedConsent, tcModel: tcModel, cmpStatus: cmpStatus, eventStatus: eventStatus }).value(); return tcData; }; return GetTCDataUseCase; }(_SyncUseCase2.SyncUseCase); exports.GetTCDataUseCase = GetTCDataUseCase; GetTCDataUseCase.ID = 'GetTCDataUseCase';