@adv-ui/boros-tcf
Version:
Adevinta GDPR - Transparency and Consent Framework - API
152 lines (116 loc) • 5.48 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LoadConsentService = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
var _ioc = require("../../core/ioc/ioc");
var _ConsentRepository = require("../consent/ConsentRepository");
var _ConsentFactory = require("../consent/ConsentFactory");
var _ConsentDecoderService = require("../consent/ConsentDecoderService");
var _VendorListRepository = require("../vendorlist/VendorListRepository");
var _ConsentEncoderService = require("./ConsentEncoderService");
var _Version = require("../vendorlist/Version");
var LoadConsentService = /*#__PURE__*/function () {
function LoadConsentService(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$consentRepositor = _ref.consentRepository,
consentRepository = _ref$consentRepositor === void 0 ? (0, _ioc.inject)(_ConsentRepository.ConsentRepository) : _ref$consentRepositor,
_ref$consentFactory = _ref.consentFactory,
consentFactory = _ref$consentFactory === void 0 ? (0, _ioc.inject)(_ConsentFactory.ConsentFactory) : _ref$consentFactory,
_ref$consentDecoderSe = _ref.consentDecoderService,
consentDecoderService = _ref$consentDecoderSe === void 0 ? (0, _ioc.inject)(_ConsentDecoderService.ConsentDecoderService) : _ref$consentDecoderSe,
_ref$consentEncoderSe = _ref.consentEncoderService,
consentEncoderService = _ref$consentEncoderSe === void 0 ? (0, _ioc.inject)(_ConsentEncoderService.ConsentEncoderService) : _ref$consentEncoderSe,
_ref$vendorListReposi = _ref.vendorListRepository,
vendorListRepository = _ref$vendorListReposi === void 0 ? (0, _ioc.inject)(_VendorListRepository.VendorListRepository) : _ref$vendorListReposi;
this._consentRepository = consentRepository;
this._consentFactory = consentFactory;
this._consentDecoderService = consentDecoderService;
this._consentEncoderService = consentEncoderService;
this._vendorListRepository = vendorListRepository;
}
var _proto = LoadConsentService.prototype;
_proto.loadConsent = /*#__PURE__*/function () {
var _loadConsent = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var encodedConsent, decodedConsent, newVendorList, consent, oldVendorList, _encodedConsent;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
encodedConsent = this._consentRepository.loadUserConsent();
if (encodedConsent) {
_context.next = 3;
break;
}
return _context.abrupt("return", this._consentFactory.createEmptyConsent());
case 3:
decodedConsent = this._consentDecoderService.decode({
encodedConsent: encodedConsent
});
_context.next = 6;
return this._vendorListRepository.getVendorList();
case 6:
newVendorList = _context.sent;
if (!(newVendorList.policyVersion !== decodedConsent.policyVersion)) {
_context.next = 9;
break;
}
return _context.abrupt("return", this._consentFactory.createEmptyConsent());
case 9:
if (!(newVendorList.version === decodedConsent.vendorListVersion)) {
_context.next = 14;
break;
}
consent = this._consentFactory.createConsent(decodedConsent);
consent.checkValidity({
consentVendorList: newVendorList
});
_context.next = 24;
break;
case 14:
consent = this._consentFactory.createConsent(decodedConsent);
_context.next = 17;
return this._vendorListRepository.getVendorList({
version: new _Version.Version(consent.vendorListVersion)
});
case 17:
oldVendorList = _context.sent;
consent.checkValidity({
consentVendorList: oldVendorList,
newVendorList: newVendorList
});
if (!consent.valid) {
_context.next = 24;
break;
}
_context.next = 22;
return this._consentEncoderService.encode({
consent: consent,
vendorListVersion: consent.vendorListVersion
});
case 22:
_encodedConsent = _context.sent;
this._consentRepository.saveUserConsent({
encodedConsent: _encodedConsent,
decodedConsent: consent
});
case 24:
return _context.abrupt("return", consent);
case 25:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function loadConsent() {
return _loadConsent.apply(this, arguments);
}
return loadConsent;
}();
return LoadConsentService;
}();
exports.LoadConsentService = LoadConsentService;