UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

67 lines (50 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TcfApiRegistryService = void 0; var _ioc = require("../../core/ioc/ioc"); var _TcfApiController = require("../controller/TcfApiController"); var TcfApiRegistryService = /*#__PURE__*/function () { function TcfApiRegistryService(_temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$tcfApiController = _ref.tcfApiController, tcfApiController = _ref$tcfApiController === void 0 ? (0, _ioc.inject)(_TcfApiController.TcfApiController) : _ref$tcfApiController; this._tcfApiController = tcfApiController; } var _proto = TcfApiRegistryService.prototype; _proto.register = function register(_ref2) { var _this = this; var borosTcf = _ref2.borosTcf; if (typeof window === 'undefined') return; var onReady = this._getStubbed(ON_READY_COMMAND); var pending = this._getStubbed(PENDING_COMMAND); window.__tcfapi = function (command, version, callback, parameter) { return _this._tcfApiController.process(command, version, callback, parameter); }; this._run(function () { return onReady && onReady(borosTcf); }); this._run(function () { return pending && pending.forEach(function (pendingFunction) { return pendingFunction(); }); }); }; _proto._getStubbed = function _getStubbed(command) { try { return window.__tcfapi(command) || null; } catch (error) { return null; } }; _proto._run = function _run(initialization) { try { initialization(); } catch (ignored) {} }; return TcfApiRegistryService; }(); exports.TcfApiRegistryService = TcfApiRegistryService; var PENDING_COMMAND = 'pending'; var ON_READY_COMMAND = 'onReady';