UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

104 lines (81 loc) 3.32 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsentFactory = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/extends")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator")); var _ioc = require("../../core/ioc/ioc"); var _Consent = require("./Consent"); var _ConsentDecoderService = require("../../domain/consent/ConsentDecoderService"); var _ConsentEncoderService = require("../../domain/consent/ConsentEncoderService"); var emptyVendorPurpose = function emptyVendorPurpose() { return { consents: {}, legitimateInterests: {} }; }; var ConsentFactory = /*#__PURE__*/function () { function ConsentFactory(_temp) { var _this = this; var _ref = _temp === void 0 ? {} : _temp, scope = _ref.scope, _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; this.createEmpty = function () { return new _Consent.Consent({ vendor: emptyVendorPurpose(), purpose: emptyVendorPurpose(), specialFeatures: {}, valid: false, isNew: true, scope: _this._scope }); }; this._scope = scope; this._consentDecoderService = consentDecoderService; this._consentEncoderService = consentEncoderService; } var _proto = ConsentFactory.prototype; _proto.createEmptyConsent = /*#__PURE__*/function () { var _createEmptyConsent = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { var encodedValue, decodedValue; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return this._consentEncoderService.encode(); case 2: encodedValue = _context.sent; decodedValue = this._consentDecoderService.decode({ encodedConsent: encodedValue }); return _context.abrupt("return", new _Consent.Consent((0, _extends2["default"])({}, decodedValue, { isNew: true, scope: this._scope }))); case 5: case "end": return _context.stop(); } } }, _callee, this); })); function createEmptyConsent() { return _createEmptyConsent.apply(this, arguments); } return createEmptyConsent; }(); _proto.createConsent = function createConsent(initialData) { return new _Consent.Consent((0, _extends2["default"])({}, initialData, { scope: this._scope })); }; return ConsentFactory; }(); exports.ConsentFactory = ConsentFactory;