UNPKG

@iabtechlabtcf/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.1 kB
"use strict";var __read=this&&this.__read||function(o,n){var e="function"==typeof Symbol&&o[Symbol.iterator];if(!e)return o;var s,a,i=e.call(o),t=[];try{for(;(void 0===n||n-- >0)&&!(s=i.next()).done;)t.push(s.value)}catch(o){a={error:o}}finally{try{s&&!s.done&&(e=i.return)&&e.call(i)}finally{if(a)throw a.error}}return t},__spreadArray=this&&this.__spreadArray||function(o,n,e){if(e||2===arguments.length)for(var s,a=0,i=n.length;a<i;a++)!s&&a in n||(s||(s=Array.prototype.slice.call(n,0,a)),s[a]=n[a]);return o.concat(s||Array.prototype.slice.call(n))};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 n=index_js_1.TCFCommand.ADD_EVENT_LISTENER;if(null==o?void 0:o[n])throw new Error("Built-In Custom Commmand for ".concat(n," not allowed: Use ").concat(index_js_1.TCFCommand.GET_TC_DATA," instead"));if(n=index_js_1.TCFCommand.REMOVE_EVENT_LISTENER,null==o?void 0:o[n])throw new Error("Built-In Custom Commmand for ".concat(n," 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],o[index_js_1.TCFCommand.REMOVE_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,n,e){for(var s,a=[],i=3;i<arguments.length;i++)a[i-3]=arguments[i];if("string"!=typeof o)e(null,!1);else if(SupportedVersions_js_1.SupportedVersions.has(n)){if("function"!=typeof e)throw new Error("invalid callback function");CmpApiModel_js_1.CmpApiModel.disabled?e(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([e],__read(a),!1)):o===index_js_1.TCFCommand.PING?this.isCustomCommand(o)?new CommandMap_js_1.CommandMap[o](this.customCommands[o],a[0],null,e):new CommandMap_js_1.CommandMap[o](e,a[0]):void 0===CmpApiModel_js_1.CmpApiModel.tcModel?this.callQueue.push(__spreadArray([o,n,e],__read(a),!1)):this.isCustomCommand(o)&&this.isBuiltInCommand(o)?new CommandMap_js_1.CommandMap[o](this.customCommands[o],a[0],null,e):new CommandMap_js_1.CommandMap[o](e,a[0]):e(null,!1)}else e(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;