@didomi/iabtcf-cmpapi
Version:
Ensures other in-page digital marketing technologies have access to CMP transparency and consent information for the iab. Transparency and Consent Framework (TCF).
1 lines • 3.02 kB
JavaScript
;var __read=this&&this.__read||function(o,e){var n="function"==typeof Symbol&&o[Symbol.iterator];if(!n)return o;var s,a,t=n.call(o),r=[];try{for(;(void 0===e||e-- >0)&&!(s=t.next()).done;)r.push(s.value)}catch(o){a={error:o}}finally{try{s&&!s.done&&(n=t.return)&&n.call(t)}finally{if(a)throw a.error}}return r},__spreadArray=this&&this.__spreadArray||function(o,e,n){if(n||2===arguments.length)for(var s,a=0,t=e.length;a<t;a++)!s&&a in e||(s||(s=Array.prototype.slice.call(e,0,a)),s[a]=e[a]);return o.concat(s||Array.prototype.slice.call(e))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CallResponder=exports.API_KEY=void 0;var index_js_1=require("./command/index.js"),CommandMap_js_1=require("./command/CommandMap.js"),CmpApiModel_js_1=require("./CmpApiModel.js"),Disabled_js_1=require("./response/Disabled.js"),SupportedVersions_js_1=require("./SupportedVersions.js");exports.API_KEY="__tcfapi";var CallResponder=function(){function o(o){if(o){var e=index_js_1.TCFCommand.ADD_EVENT_LISTENER;if(null==o?void 0:o[e])throw new Error("Built-In Custom Commmand for ".concat(e," not allowed: Use ").concat(index_js_1.TCFCommand.GET_TC_DATA," instead"));if(e=index_js_1.TCFCommand.REMOVE_EVENT_LISTENER,null==o?void 0:o[e])throw new Error("Built-In Custom Commmand for ".concat(e," not allowed"));(null==o?void 0:o[index_js_1.TCFCommand.GET_TC_DATA])&&(o[index_js_1.TCFCommand.ADD_EVENT_LISTENER]=o[index_js_1.TCFCommand.GET_TC_DATA]),this.customCommands=o}try{this.callQueue=window[exports.API_KEY]()||[]}catch(o){this.callQueue=[]}finally{window[exports.API_KEY]=this.apiCall.bind(this),this.purgeQueuedCalls()}}return o.prototype.apiCall=function(o,e,n){for(var s,a=[],t=3;t<arguments.length;t++)a[t-3]=arguments[t];if("string"!=typeof o)n(null,!1);else if(SupportedVersions_js_1.SupportedVersions.has(e)){if("function"!=typeof n)throw new Error("invalid callback function");CmpApiModel_js_1.CmpApiModel.disabled?n(new Disabled_js_1.Disabled,!1):this.isCustomCommand(o)||this.isBuiltInCommand(o)?this.isCustomCommand(o)&&!this.isBuiltInCommand(o)?(s=this.customCommands)[o].apply(s,__spreadArray([n],__read(a),!1)):o===index_js_1.TCFCommand.PING?this.isCustomCommand(o)?new CommandMap_js_1.CommandMap[o](this.customCommands[o],a[0],null,n):new CommandMap_js_1.CommandMap[o](n,a[0]):void 0===CmpApiModel_js_1.CmpApiModel.tcModel?this.callQueue.push(__spreadArray([o,e,n],__read(a),!1)):this.isCustomCommand(o)&&this.isBuiltInCommand(o)?new CommandMap_js_1.CommandMap[o](this.customCommands[o],a[0],null,n):new CommandMap_js_1.CommandMap[o](n,a[0]):n(null,!1)}else n(null,!1)},o.prototype.purgeQueuedCalls=function(){var o=this.callQueue;this.callQueue=[],o.forEach((function(o){window[exports.API_KEY].apply(window,__spreadArray([],__read(o),!1))}))},o.prototype.isCustomCommand=function(o){return this.customCommands&&"function"==typeof this.customCommands[o]},o.prototype.isBuiltInCommand=function(o){return void 0!==CommandMap_js_1.CommandMap[o]},o}();exports.CallResponder=CallResponder;