diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js index a6bf56f8cad..dcbd8283c71 100644 --- a/modules/adkernelBidAdapter.js +++ b/modules/adkernelBidAdapter.js @@ -1,4 +1,7 @@ -import * as utils from '../src/utils.js'; +import { + isStr, isArray, isPlainObject, deepSetValue, isNumber, deepAccess, getAdUnitSizes, parseGPTSingleSizeArrayToRtbSize, + cleanObj, contains, getDNT, parseUrl, createTrackPixelHtml, _each, isArrayOfNums +} from '../src/utils.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import find from 'core-js-pure/features/array/find.js'; @@ -154,24 +157,24 @@ export const spec = { prBid.mediaType = NATIVE; prBid.native = buildNativeAd(JSON.parse(rtbBid.adm)); } - if (utils.isStr(rtbBid.dealid)) { + if (isStr(rtbBid.dealid)) { prBid.dealId = rtbBid.dealid; } - if (utils.isArray(rtbBid.adomain)) { - utils.deepSetValue(prBid, 'meta.advertiserDomains', rtbBid.adomain); + if (isArray(rtbBid.adomain)) { + deepSetValue(prBid, 'meta.advertiserDomains', rtbBid.adomain); } - if (utils.isArray(rtbBid.cat)) { - utils.deepSetValue(prBid, 'meta.secondaryCatIds', rtbBid.cat); + if (isArray(rtbBid.cat)) { + deepSetValue(prBid, 'meta.secondaryCatIds', rtbBid.cat); } - if (utils.isPlainObject(rtbBid.ext)) { - if (utils.isNumber(rtbBid.ext.advertiser_id)) { - utils.deepSetValue(prBid, 'meta.advertiserId', rtbBid.ext.advertiser_id); + if (isPlainObject(rtbBid.ext)) { + if (isNumber(rtbBid.ext.advertiser_id)) { + deepSetValue(prBid, 'meta.advertiserId', rtbBid.ext.advertiser_id); } - if (utils.isStr(rtbBid.ext.advertiser_name)) { - utils.deepSetValue(prBid, 'meta.advertiserName', rtbBid.ext.advertiser_name); + if (isStr(rtbBid.ext.advertiser_name)) { + deepSetValue(prBid, 'meta.advertiserName', rtbBid.ext.advertiser_name); } - if (utils.isStr(rtbBid.ext.agency_name)) { - utils.deepSetValue(prBid, 'meta.agencyName', rtbBid.ext.agency_name); + if (isStr(rtbBid.ext.agency_name)) { + deepSetValue(prBid, 'meta.agencyName', rtbBid.ext.agency_name); } } @@ -241,19 +244,19 @@ function buildImp(bidRequest, secure) { var mediaType; var sizes = []; - if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { - sizes = utils.getAdUnitSizes(bidRequest); + if (deepAccess(bidRequest, 'mediaTypes.banner')) { + sizes = getAdUnitSizes(bidRequest); imp.banner = { - format: sizes.map(wh => utils.parseGPTSingleSizeArrayToRtbSize(wh)), + format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)), topframe: 0 }; mediaType = BANNER; - } else if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { - let video = utils.deepAccess(bidRequest, 'mediaTypes.video'); + } else if (deepAccess(bidRequest, 'mediaTypes.video')) { + let video = deepAccess(bidRequest, 'mediaTypes.video'); imp.video = {}; if (video.playerSize) { sizes = video.playerSize[0]; - imp.video = Object.assign(imp.video, utils.parseGPTSingleSizeArrayToRtbSize(sizes) || {}); + imp.video = Object.assign(imp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {}); } if (bidRequest.params.video) { Object.keys(bidRequest.params.video) @@ -261,7 +264,7 @@ function buildImp(bidRequest, secure) { .forEach(key => imp.video[key] = bidRequest.params.video[key]); } mediaType = VIDEO; - } else if (utils.deepAccess(bidRequest, 'mediaTypes.native')) { + } else if (deepAccess(bidRequest, 'mediaTypes.native')) { let nativeRequest = buildNativeRequest(bidRequest.mediaTypes.native); imp.native = { ver: '1.1', @@ -299,7 +302,7 @@ function buildNativeRequest(nativeReq) { if (desc.assetType === 'img') { assetRoot[desc.assetType] = buildImageAsset(desc, v); } else if (desc.assetType === 'data') { - assetRoot.data = utils.cleanObj({type: desc.type, len: v.len}); + assetRoot.data = cleanObj({type: desc.type, len: v.len}); } else if (desc.assetType === 'title') { assetRoot.title = {len: v.len || 90}; } else { @@ -323,7 +326,7 @@ function buildImageAsset(desc, val) { img.wmin = val.aspect_ratios[0].min_width; img.hmin = val.aspect_ratios[0].min_height; } - return utils.cleanObj(img); + return cleanObj(img); } /** @@ -336,9 +339,9 @@ function isSyncMethodAllowed(syncRule, bidderCode) { if (!syncRule) { return false; } - let bidders = utils.isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; + let bidders = isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; let rule = syncRule.filter === 'include'; - return utils.contains(bidders, bidderCode) === rule; + return contains(bidders, bidderCode) === rule; } /** @@ -382,33 +385,33 @@ function buildRtbRequest(imps, bidderRequest, schain) { }, 'tmax': parseInt(timeout) }; - if (utils.getDNT()) { + if (getDNT()) { req.device.dnt = 1; } if (gdprConsent) { if (gdprConsent.gdprApplies !== undefined) { - utils.deepSetValue(req, 'regs.ext.gdpr', ~~gdprConsent.gdprApplies); + deepSetValue(req, 'regs.ext.gdpr', ~~gdprConsent.gdprApplies); } if (gdprConsent.consentString !== undefined) { - utils.deepSetValue(req, 'user.ext.consent', gdprConsent.consentString); + deepSetValue(req, 'user.ext.consent', gdprConsent.consentString); } } if (uspConsent) { - utils.deepSetValue(req, 'regs.ext.us_privacy', uspConsent); + deepSetValue(req, 'regs.ext.us_privacy', uspConsent); } if (coppa) { - utils.deepSetValue(req, 'regs.coppa', 1); + deepSetValue(req, 'regs.coppa', 1); } let syncMethod = getAllowedSyncMethod(bidderCode); if (syncMethod) { - utils.deepSetValue(req, 'ext.adk_usersync', syncMethod); + deepSetValue(req, 'ext.adk_usersync', syncMethod); } if (schain) { - utils.deepSetValue(req, 'source.ext.schain', schain); + deepSetValue(req, 'source.ext.schain', schain); } let eids = getExtendedUserIds(bidderRequest); if (eids) { - utils.deepSetValue(req, 'user.ext.eids', eids); + deepSetValue(req, 'user.ext.eids', eids); } return req; } @@ -426,7 +429,7 @@ function getLanguage() { * Creates site description object */ function createSite(refInfo) { - let url = utils.parseUrl(refInfo.referer); + let url = parseUrl(refInfo.referer); let site = { 'domain': url.hostname, 'page': `${url.protocol}://${url.hostname}${url.pathname}` @@ -442,8 +445,8 @@ function createSite(refInfo) { } function getExtendedUserIds(bidderRequest) { - let eids = utils.deepAccess(bidderRequest, 'bids.0.userIdAsEids'); - if (utils.isArray(eids)) { + let eids = deepAccess(bidderRequest, 'bids.0.userIdAsEids'); + if (isArray(eids)) { return eids; } } @@ -455,7 +458,7 @@ function getExtendedUserIds(bidderRequest) { function formatAdMarkup(bid) { let adm = bid.adm; if ('nurl' in bid) { - adm += utils.createTrackPixelHtml(`${bid.nurl}&px=1`); + adm += createTrackPixelHtml(`${bid.nurl}&px=1`); } return adm; } @@ -465,8 +468,8 @@ function formatAdMarkup(bid) { */ function validateNativeAdUnit(adUnit) { return validateNativeImageSize(adUnit.image) && validateNativeImageSize(adUnit.icon) && - !utils.deepAccess(adUnit, 'privacyLink.required') && // not supported yet - !utils.deepAccess(adUnit, 'privacyIcon.required'); // not supported yet + !deepAccess(adUnit, 'privacyLink.required') && // not supported yet + !deepAccess(adUnit, 'privacyIcon.required'); // not supported yet } /** @@ -477,9 +480,9 @@ function validateNativeImageSize(img) { return true; } if (img.sizes) { - return utils.isArrayOfNums(img.sizes, 2); + return isArrayOfNums(img.sizes, 2); } - if (utils.isArray(img.aspect_ratios)) { + if (isArray(img.aspect_ratios)) { return img.aspect_ratios.length > 0 && img.aspect_ratios[0].min_height && img.aspect_ratios[0].min_width; } return true; @@ -496,14 +499,14 @@ function buildNativeAd(nativeResp) { javascriptTrackers: jstracker ? [jstracker] : undefined, privacyLink: privacy, }; - utils._each(assets, asset => { + _each(assets, asset => { let assetName = NATIVE_MODEL[asset.id].name; let assetType = NATIVE_MODEL[asset.id].assetType; - nativeAd[assetName] = asset[assetType].text || asset[assetType].value || utils.cleanObj({ + nativeAd[assetName] = asset[assetType].text || asset[assetType].value || cleanObj({ url: asset[assetType].url, width: asset[assetType].w, height: asset[assetType].h }); }); - return utils.cleanObj(nativeAd); + return cleanObj(nativeAd); } diff --git a/modules/adlooxAdServerVideo.js b/modules/adlooxAdServerVideo.js index 2a61e59b714..7305283039c 100644 --- a/modules/adlooxAdServerVideo.js +++ b/modules/adlooxAdServerVideo.js @@ -11,48 +11,48 @@ import { command as analyticsCommand, COMMAND } from './adlooxAnalyticsAdapter.j import { ajax } from '../src/ajax.js'; import { EVENTS } from '../src/constants.json'; import { targeting } from '../src/targeting.js'; -import * as utils from '../src/utils.js'; +import { logInfo, isFn, logError, isPlainObject, isStr, isBoolean, deepSetValue, deepClone, timestamp, logWarn } from '../src/utils.js'; const MODULE = 'adlooxAdserverVideo'; const URL_VAST = 'https://j.adlooxtracking.com/ads/vast/tag.php'; export function buildVideoUrl(options, callback) { - utils.logInfo(MODULE, 'buildVideoUrl', options); + logInfo(MODULE, 'buildVideoUrl', options); - if (!utils.isFn(callback)) { - utils.logError(MODULE, 'invalid callback'); + if (!isFn(callback)) { + logError(MODULE, 'invalid callback'); return false; } - if (!utils.isPlainObject(options)) { - utils.logError(MODULE, 'missing options'); + if (!isPlainObject(options)) { + logError(MODULE, 'missing options'); return false; } - if (!(options.url_vast === undefined || utils.isStr(options.url_vast))) { - utils.logError(MODULE, 'invalid url_vast options value'); + if (!(options.url_vast === undefined || isStr(options.url_vast))) { + logError(MODULE, 'invalid url_vast options value'); return false; } - if (!(utils.isPlainObject(options.adUnit) || utils.isPlainObject(options.bid))) { - utils.logError(MODULE, "requires either 'adUnit' or 'bid' options value"); + if (!(isPlainObject(options.adUnit) || isPlainObject(options.bid))) { + logError(MODULE, "requires either 'adUnit' or 'bid' options value"); return false; } - if (!utils.isStr(options.url)) { - utils.logError(MODULE, 'invalid url options value'); + if (!isStr(options.url)) { + logError(MODULE, 'invalid url options value'); return false; } - if (!(options.wrap === undefined || utils.isBoolean(options.wrap))) { - utils.logError(MODULE, 'invalid wrap options value'); + if (!(options.wrap === undefined || isBoolean(options.wrap))) { + logError(MODULE, 'invalid wrap options value'); return false; } - if (!(options.blob === undefined || utils.isBoolean(options.blob))) { - utils.logError(MODULE, 'invalid blob options value'); + if (!(options.blob === undefined || isBoolean(options.blob))) { + logError(MODULE, 'invalid blob options value'); return false; } // same logic used in modules/dfpAdServerVideo.js options.bid = options.bid || targeting.getWinningBids(options.adUnit.code)[0]; - utils.deepSetValue(options.bid, 'ext.adloox.video.adserver', true); + deepSetValue(options.bid, 'ext.adloox.video.adserver', true); if (options.wrap !== false) { VASTWrapper(options, callback); @@ -70,7 +70,7 @@ registerVideoSupport('adloox', { function track(options, callback) { callback(options.url); - const bid = utils.deepClone(options.bid); + const bid = deepClone(options.bid); bid.ext.adloox.video.adserver = false; analyticsCommand(COMMAND.TRACK, { @@ -85,13 +85,13 @@ function VASTWrapper(options, callback) { function process(result) { function getAd(xml) { if (!xml || xml.documentElement.tagName != 'VAST') { - utils.logError(MODULE, 'not a VAST tag, using non-wrapped tracking'); + logError(MODULE, 'not a VAST tag, using non-wrapped tracking'); return; } const ads = xml.querySelectorAll('Ad'); if (!ads.length) { - utils.logError(MODULE, 'no VAST ads, using non-wrapped tracking'); + logError(MODULE, 'no VAST ads, using non-wrapped tracking'); return; } @@ -132,7 +132,7 @@ function VASTWrapper(options, callback) { options.url = toBlob(chain[0]); - const epoch = utils.timestamp() - new Date().getTimezoneOffset() * 60 * 1000; + const epoch = timestamp() - new Date().getTimezoneOffset() * 60 * 1000; const expires0 = options.bid.ttl * 1000 - (epoch - options.bid.responseTimestamp); const expires = Math.max(30 * 1000, expires0); setTimeout(function() { urls.forEach(u => URL.revokeObjectURL(u)) }, expires); @@ -154,7 +154,7 @@ function VASTWrapper(options, callback) { const wrapper = getWrapper(ad); if (wrapper) { if (chain.length > 5) { - utils.logWarn(MODULE, `got wrapped tag at depth ${chain.length}, not continuing`); + logWarn(MODULE, `got wrapped tag at depth ${chain.length}, not continuing`); blobify(); return track(options, callback); } @@ -191,7 +191,7 @@ function VASTWrapper(options, callback) { if (duration != 15) args.push([ 'duration', duration ]); if (skip) args.push([ 'skip', skip ]); - utils.logInfo(MODULE, `processed VAST tag chain of depth ${chain.depth}, running callback`); + logInfo(MODULE, `processed VAST tag chain of depth ${chain.depth}, running callback`); analyticsCommand(COMMAND.URL, { url: (options.url_vast || URL_VAST) + '?', @@ -202,7 +202,7 @@ function VASTWrapper(options, callback) { } function fetch(url, withoutcredentials) { - utils.logInfo(MODULE, `fetching VAST ${url}`); + logInfo(MODULE, `fetching VAST ${url}`); ajax(url, { success: function(responseText, q) { @@ -210,10 +210,10 @@ function VASTWrapper(options, callback) { }, error: function(statusText, q) { if (!withoutcredentials) { - utils.logWarn(MODULE, `unable to download (${statusText}), suspected CORS withCredentials problem, retrying without`); + logWarn(MODULE, `unable to download (${statusText}), suspected CORS withCredentials problem, retrying without`); return fetch(url, true); } - utils.logError(MODULE, `failed to fetch (${statusText}), using non-wrapped tracking`); + logError(MODULE, `failed to fetch (${statusText}), using non-wrapped tracking`); process(); } }, undefined, { withCredentials: !withoutcredentials }); diff --git a/modules/adlooxAnalyticsAdapter.js b/modules/adlooxAnalyticsAdapter.js index 17787f816df..6ea1df1b72c 100644 --- a/modules/adlooxAnalyticsAdapter.js +++ b/modules/adlooxAnalyticsAdapter.js @@ -11,7 +11,10 @@ import { auctionManager } from '../src/auctionManager.js'; import { AUCTION_COMPLETED } from '../src/auction.js'; import { EVENTS } from '../src/constants.json'; import find from 'core-js-pure/features/array/find.js'; -import * as utils from '../src/utils.js'; +import { + deepAccess, logInfo, isPlainObject, logError, isStr, isNumber, getGptSlotInfoForAdUnitCode, + isFn, mergeDeep, logMessage, insertElement, logWarn, getUniqueIdentifierStr, parseUrl +} from '../src/utils.js'; const MODULE = 'adlooxAnalyticsAdapter'; @@ -45,7 +48,7 @@ MACRO['creatype'] = function(b, c) { }; MACRO['pbadslot'] = function(b, c) { const adUnit = find(auctionManager.getAdUnits(), a => b.adUnitCode === a.code); - return utils.deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot') || utils.getGptSlotInfoForAdUnitCode(b.adUnitCode).gptSlot || b.adUnitCode; + return deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot') || getGptSlotInfoForAdUnitCode(b.adUnitCode).gptSlot || b.adUnitCode; }; MACRO['pbAdSlot'] = MACRO['pbadslot']; // legacy @@ -66,7 +69,7 @@ let analyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoint' }), { track({ eventType, args }) { if (!analyticsAdapter[`handle_${eventType}`]) return; - utils.logInfo(MODULE, 'track', eventType, args); + logInfo(MODULE, 'track', eventType, args); analyticsAdapter[`handle_${eventType}`](args); } @@ -78,45 +81,45 @@ analyticsAdapter.originEnableAnalytics = analyticsAdapter.enableAnalytics; analyticsAdapter.enableAnalytics = function(config) { analyticsAdapter.context = null; - utils.logInfo(MODULE, 'config', config); + logInfo(MODULE, 'config', config); - if (!utils.isPlainObject(config.options)) { - utils.logError(MODULE, 'missing options'); + if (!isPlainObject(config.options)) { + logError(MODULE, 'missing options'); return; } - if (!(config.options.js === undefined || utils.isStr(config.options.js))) { - utils.logError(MODULE, 'invalid js options value'); + if (!(config.options.js === undefined || isStr(config.options.js))) { + logError(MODULE, 'invalid js options value'); return; } - if (!(config.options.toselector === undefined || utils.isFn(config.options.toselector))) { - utils.logError(MODULE, 'invalid toselector options value'); + if (!(config.options.toselector === undefined || isFn(config.options.toselector))) { + logError(MODULE, 'invalid toselector options value'); return; } - if (!utils.isStr(config.options.client)) { - utils.logError(MODULE, 'invalid client options value'); + if (!isStr(config.options.client)) { + logError(MODULE, 'invalid client options value'); return; } - if (!utils.isNumber(config.options.clientid)) { - utils.logError(MODULE, 'invalid clientid options value'); + if (!isNumber(config.options.clientid)) { + logError(MODULE, 'invalid clientid options value'); return; } - if (!utils.isNumber(config.options.tagid)) { - utils.logError(MODULE, 'invalid tagid options value'); + if (!isNumber(config.options.tagid)) { + logError(MODULE, 'invalid tagid options value'); return; } - if (!utils.isNumber(config.options.platformid)) { - utils.logError(MODULE, 'invalid platformid options value'); + if (!isNumber(config.options.platformid)) { + logError(MODULE, 'invalid platformid options value'); return; } - if (!(config.options.params === undefined || utils.isPlainObject(config.options.params))) { - utils.logError(MODULE, 'invalid params options value'); + if (!(config.options.params === undefined || isPlainObject(config.options.params))) { + logError(MODULE, 'invalid params options value'); return; } analyticsAdapter.context = { js: config.options.js || URL_JS, toselector: config.options.toselector || function(bid) { - let code = utils.getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId || bid.adUnitCode; + let code = getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId || bid.adUnitCode; // https://mathiasbynens.be/notes/css-escapes code = code.replace(/^\d/, '\\3$& '); return `#${code}` @@ -128,7 +131,7 @@ analyticsAdapter.enableAnalytics = function(config) { params: [] }; - config.options.params = utils.mergeDeep({}, PARAMS_DEFAULT, config.options.params || {}); + config.options.params = mergeDeep({}, PARAMS_DEFAULT, config.options.params || {}); Object .keys(config.options.params) .forEach(k => { @@ -180,15 +183,15 @@ analyticsAdapter.url = function(url, args, bid) { let n = args.length; while (n-- > 0) { - if (utils.isFn(args[n][1])) { + if (isFn(args[n][1])) { try { args[n][1] = args[n][1](bid); } catch (_) { - utils.logError(MODULE, 'macro', args[n][0], _.message); + logError(MODULE, 'macro', args[n][0], _.message); args[n][1] = `ERROR: ${_.message}`; } } - if (utils.isStr(args[n][1])) { + if (isStr(args[n][1])) { args[n][1] = macros(args[n][1]); } } @@ -200,20 +203,20 @@ analyticsAdapter[`handle_${EVENTS.AUCTION_END}`] = function(auctionDetails) { if (!(auctionDetails.auctionStatus == AUCTION_COMPLETED && auctionDetails.bidsReceived.length > 0)) return; analyticsAdapter[`handle_${EVENTS.AUCTION_END}`] = NOOP; - utils.logMessage(MODULE, 'preloading verification JS'); + logMessage(MODULE, 'preloading verification JS'); - const uri = utils.parseUrl(analyticsAdapter.url(`${analyticsAdapter.context.js}#`)); + const uri = parseUrl(analyticsAdapter.url(`${analyticsAdapter.context.js}#`)); const link = document.createElement('link'); link.setAttribute('href', `${uri.protocol}://${uri.host}${uri.pathname}`); link.setAttribute('rel', 'preload'); link.setAttribute('as', 'script'); - utils.insertElement(link); + insertElement(link); } analyticsAdapter[`handle_${EVENTS.BID_WON}`] = function(bid) { - if (utils.deepAccess(bid, 'ext.adloox.video.adserver')) { - utils.logMessage(MODULE, `measuring '${bid.mediaType}' ad unit code '${bid.adUnitCode}' via Ad Server module`); + if (deepAccess(bid, 'ext.adloox.video.adserver')) { + logMessage(MODULE, `measuring '${bid.mediaType}' ad unit code '${bid.adUnitCode}' via Ad Server module`); return; } @@ -223,11 +226,11 @@ analyticsAdapter[`handle_${EVENTS.BID_WON}`] = function(bid) { el = document.querySelector(sl); } catch (_) { } if (!el) { - utils.logWarn(MODULE, `unable to find ad unit code '${bid.adUnitCode}' slot using selector '${sl}' (use options.toselector to change), ignoring`); + logWarn(MODULE, `unable to find ad unit code '${bid.adUnitCode}' slot using selector '${sl}' (use options.toselector to change), ignoring`); return; } - utils.logMessage(MODULE, `measuring '${bid.mediaType}' unit at '${bid.adUnitCode}'`); + logMessage(MODULE, `measuring '${bid.mediaType}' unit at '${bid.adUnitCode}'`); const params = analyticsAdapter.context.params.concat([ [ 'tagid', '%%tagid%%' ], @@ -257,7 +260,7 @@ export const COMMAND = { TRACK: 'track' }; export function command(cmd, data, callback0) { - const cid = utils.getUniqueIdentifierStr(); + const cid = getUniqueIdentifierStr(); const callback = function() { delete COMMAND_QUEUE[cid]; if (callback0) callback0.apply(null, arguments); @@ -268,7 +271,7 @@ export function command(cmd, data, callback0) { function commandProcess(cid) { const { cmd, data, callback } = COMMAND_QUEUE[cid]; - utils.logInfo(MODULE, 'command', cmd, data); + logInfo(MODULE, 'command', cmd, data); switch (cmd) { case COMMAND.CONFIG: @@ -292,7 +295,7 @@ function commandProcess(cid) { callback(); // drain queue break; default: - utils.logWarn(MODULE, 'command unknown', cmd); + logWarn(MODULE, 'command unknown', cmd); // do not callback as arguments are unknown and to aid debugging } } diff --git a/modules/adlooxRtdProvider.js b/modules/adlooxRtdProvider.js index 3e93047cccc..34d1428ea1d 100644 --- a/modules/adlooxRtdProvider.js +++ b/modules/adlooxRtdProvider.js @@ -16,7 +16,10 @@ import { config as _config } from '../src/config.js'; import { submodule } from '../src/hook.js'; import { ajax } from '../src/ajax.js'; import { getGlobal } from '../src/prebidGlobal.js'; -import * as utils from '../src/utils.js'; +import { + getAdUnitSizes, logInfo, isPlainObject, logError, isStr, isInteger, isArray, isBoolean, mergeDeep, deepAccess, + _each, deepSetValue, logWarn, getGptSlotInfoForAdUnitCode +} from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const MODULE_NAME = 'adloox'; @@ -49,7 +52,7 @@ function atf(adUnit, cb) { // Google's advice is to collapse slots on no fill but // we have to cater to clients that grow slots on fill const rect = (function(rect) { - const sizes = utils.getAdUnitSizes(adUnit); + const sizes = getAdUnitSizes(adUnit); if (sizes.length == 0) return false; // interstitial (0x0, 1x1) @@ -141,54 +144,54 @@ function atf(adUnit, cb) { } function init(config, userConsent) { - utils.logInfo(MODULE, 'init', config, userConsent); + logInfo(MODULE, 'init', config, userConsent); - if (!utils.isPlainObject(config)) { - utils.logError(MODULE, 'missing config'); + if (!isPlainObject(config)) { + logError(MODULE, 'missing config'); return false; } if (config.params === undefined) config.params = {}; - if (!(utils.isPlainObject(config.params))) { - utils.logError(MODULE, 'invalid params'); + if (!(isPlainObject(config.params))) { + logError(MODULE, 'invalid params'); return false; } - if (!(config.params.api_origin === undefined || utils.isStr(config.params.api_origin))) { - utils.logError(MODULE, 'invalid api_origin params value'); + if (!(config.params.api_origin === undefined || isStr(config.params.api_origin))) { + logError(MODULE, 'invalid api_origin params value'); return false; } - if (!(config.params.imps === undefined || (utils.isInteger(config.params.imps) && config.params.imps > 0))) { - utils.logError(MODULE, 'invalid imps params value'); + if (!(config.params.imps === undefined || (isInteger(config.params.imps) && config.params.imps > 0))) { + logError(MODULE, 'invalid imps params value'); return false; } - if (!(config.params.freqcap_ip === undefined || (utils.isInteger(config.params.freqcap_ip) && config.params.freqcap_ip >= 0))) { - utils.logError(MODULE, 'invalid freqcap_ip params value'); + if (!(config.params.freqcap_ip === undefined || (isInteger(config.params.freqcap_ip) && config.params.freqcap_ip >= 0))) { + logError(MODULE, 'invalid freqcap_ip params value'); return false; } - if (!(config.params.freqcap_ipua === undefined || (utils.isInteger(config.params.freqcap_ipua) && config.params.freqcap_ipua >= 0))) { - utils.logError(MODULE, 'invalid freqcap_ipua params value'); + if (!(config.params.freqcap_ipua === undefined || (isInteger(config.params.freqcap_ipua) && config.params.freqcap_ipua >= 0))) { + logError(MODULE, 'invalid freqcap_ipua params value'); return false; } - if (!(config.params.thresholds === undefined || (utils.isArray(config.params.thresholds) && config.params.thresholds.every(x => utils.isInteger(x) && x > 0 && x <= 100)))) { - utils.logError(MODULE, 'invalid thresholds params value'); + if (!(config.params.thresholds === undefined || (isArray(config.params.thresholds) && config.params.thresholds.every(x => isInteger(x) && x > 0 && x <= 100)))) { + logError(MODULE, 'invalid thresholds params value'); return false; } - if (!(config.params.slotinpath === undefined || utils.isBoolean(config.params.slotinpath))) { - utils.logError(MODULE, 'invalid slotinpath params value'); + if (!(config.params.slotinpath === undefined || isBoolean(config.params.slotinpath))) { + logError(MODULE, 'invalid slotinpath params value'); return false; } // legacy/deprecated configuration code path - if (!(config.params.params === undefined || (utils.isPlainObject(config.params.params) && utils.isInteger(config.params.params.clientid) && utils.isInteger(config.params.params.tagid) && utils.isInteger(config.params.params.platformid)))) { - utils.logError(MODULE, 'invalid subsection params block'); + if (!(config.params.params === undefined || (isPlainObject(config.params.params) && isInteger(config.params.params.clientid) && isInteger(config.params.params.tagid) && isInteger(config.params.params.platformid)))) { + logError(MODULE, 'invalid subsection params block'); return false; } config.params.thresholds = config.params.thresholds || [ 50, 60, 70, 80, 90 ]; function analyticsConfigCallback(data) { - config = utils.mergeDeep(config.params, data); + config = mergeDeep(config.params, data); } if (config.params.params) { - utils.logWarn(MODULE, `legacy/deprecated configuration (please migrate to ${MODULE_NAME}AnalyticsAdapter)`); + logWarn(MODULE, `legacy/deprecated configuration (please migrate to ${MODULE_NAME}AnalyticsAdapter)`); analyticsConfigCallback(config.params.params); } else { analyticsCommand(COMMAND.CONFIG, null, analyticsConfigCallback); @@ -200,8 +203,8 @@ function init(config, userConsent) { function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { // gptPreAuction runs *after* RTD so pbadslot may not be populated... (╯°□°)╯ ┻━┻ const adUnits = (reqBidsConfigObj.adUnits || getGlobal().adUnits).map(adUnit => { - let path = utils.deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot'); - if (!path) path = utils.getGptSlotInfoForAdUnitCode(adUnit.code).gptSlot; + let path = deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot'); + if (!path) path = getGptSlotInfoForAdUnitCode(adUnit.code).gptSlot; return { path: path, unit: adUnit @@ -219,33 +222,33 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { const dataSite = _config.getConfig('ortb2.site.ext.data') || {}; const dataUser = _config.getConfig('ortb2.user.ext.data') || {}; - utils._each(response, (v0, k0) => { + _each(response, (v0, k0) => { if (k0 == '_') return; const k = SEGMENT_HISTORIC[k0] || k0; const v = val(v0, k0); - utils.deepSetValue(k == k0 ? dataUser : dataSite, `${MODULE_NAME}_rtd.${k}`, v); + deepSetValue(k == k0 ? dataUser : dataSite, `${MODULE_NAME}_rtd.${k}`, v); }); - utils.deepSetValue(dataSite, `${MODULE_NAME}_rtd.ok`, true); + deepSetValue(dataSite, `${MODULE_NAME}_rtd.ok`, true); - utils.deepSetValue(ortb2, 'site.ext.data', dataSite); - utils.deepSetValue(ortb2, 'user.ext.data', dataUser); + deepSetValue(ortb2, 'site.ext.data', dataSite); + deepSetValue(ortb2, 'user.ext.data', dataUser); _config.setConfig({ ortb2 }); adUnits.forEach((adUnit, i) => { - utils._each(response['_'][i], (v0, k0) => { + _each(response['_'][i], (v0, k0) => { const k = SEGMENT_HISTORIC[k0] || k0; const v = val(v0, k0); - utils.deepSetValue(adUnit.unit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd.${k}`, v); + deepSetValue(adUnit.unit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd.${k}`, v); }); }); }; - // utils.mergeDeep does not handle merging deep arrays... (╯°□°)╯ ┻━┻ + // mergeDeep does not handle merging deep arrays... (╯°□°)╯ ┻━┻ function mergeDeep(target, ...sources) { function emptyValue(v) { - if (utils.isPlainObject(v)) { + if (isPlainObject(v)) { return {}; - } else if (utils.isArray(v)) { + } else if (isArray(v)) { return []; } else { return undefined; @@ -255,12 +258,12 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { if (!sources.length) return target; const source = sources.shift(); - if (utils.isPlainObject(target) && utils.isPlainObject(source)) { + if (isPlainObject(target) && isPlainObject(source)) { Object.keys(source).forEach(key => { if (!(key in target)) target[key] = emptyValue(source[key]); target[key] = target[key] !== undefined ? mergeDeep(target[key], source[key]) : source[key]; }); - } else if (utils.isArray(target) && utils.isArray(source)) { + } else if (isArray(target) && isArray(source)) { source.forEach((v, i) => { if (!(i in target)) target[i] = emptyValue(v); target[i] = target[i] !== undefined ? mergeDeep(target[i], v) : v; @@ -294,7 +297,7 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { ]; if (!adUnits.length) { - utils.logWarn(MODULE, 'no suitable adUnits (missing pbadslot?)'); + logWarn(MODULE, 'no suitable adUnits (missing pbadslot?)'); } const atfQueue = []; adUnits.map((adUnit, i) => { @@ -307,7 +310,7 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { atf(adUnit.unit, function(x) { let viewable = document.visibilityState === undefined || document.visibilityState == 'visible'; try { viewable = viewable && top.document.hasFocus() } catch (_) {} - utils.logInfo(MODULE, `atf code=${adUnit.unit.code} has area=${x}, viewable=${viewable}`); + logInfo(MODULE, `atf code=${adUnit.unit.code} has area=${x}, viewable=${viewable}`); const atfList = []; atfList[i] = { atf: parseInt(x * 100) }; response = mergeDeep(response, { _: atfList }); semaphoreInc(-1); @@ -336,12 +339,12 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { throw false; } } catch (_) { - utils.logError(MODULE, 'unexpected response'); + logError(MODULE, 'unexpected response'); } semaphoreInc(-1); }, error: function(statusText, q) { - utils.logError(MODULE, 'request failed'); + logError(MODULE, 'request failed'); semaphoreInc(-1); } }); @@ -350,8 +353,8 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { function getTargetingData(adUnitArray, config, userConsent) { function targetingNormalise(v) { - if (utils.isArray(v) && v.length == 0) return undefined; - if (utils.isBoolean(v)) v = ~~v; + if (isArray(v) && v.length == 0) return undefined; + if (isBoolean(v)) v = ~~v; if (!v) return undefined; // empty string and zero return v; } @@ -363,14 +366,14 @@ function getTargetingData(adUnitArray, config, userConsent) { return getGlobal().adUnits.filter(adUnit => includes(adUnitArray, adUnit.code)).reduce((a, adUnit) => { a[adUnit.code] = {}; - utils._each(dataSite, (v0, k) => { + _each(dataSite, (v0, k) => { if (includes(SEGMENT_HISTORIC_VALUES, k)) return; // ignore site average viewability const v = targetingNormalise(v0); if (v) a[adUnit.code][ADSERVER_TARGETING_PREFIX + k] = v; }); - const adUnitSegments = utils.deepAccess(adUnit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd`, {}); - utils._each(Object.assign({}, dataUser, adUnitSegments), (v0, k) => { + const adUnitSegments = deepAccess(adUnit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd`, {}); + _each(Object.assign({}, dataUser, adUnitSegments), (v0, k) => { const v = targetingNormalise(v0); if (v) a[adUnit.code][ADSERVER_TARGETING_PREFIX + k] = v; }); diff --git a/modules/admanBidAdapter.js b/modules/admanBidAdapter.js index 18d1fb57486..e02a1a9df04 100644 --- a/modules/admanBidAdapter.js +++ b/modules/admanBidAdapter.js @@ -1,6 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; +import { isFn, deepAccess, logMessage } from '../src/utils.js'; const BIDDER_CODE = 'adman'; const AD_URL = 'https://pub.admanmedia.com/?c=o&m=multi'; @@ -24,8 +24,8 @@ function isBidResponseValid(bid) { } function getBidFloor(bid) { - if (!utils.isFn(bid.getFloor)) { - return utils.deepAccess(bid, 'params.bidfloor', 0); + if (!isFn(bid.getFloor)) { + return deepAccess(bid, 'params.bidfloor', 0); } try { @@ -69,7 +69,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - utils.logMessage(e); + logMessage(e); }; let placements = []; let request = { diff --git a/modules/admixerBidAdapter.js b/modules/admixerBidAdapter.js index bb9a6dd44a3..e136dfcfbdb 100644 --- a/modules/admixerBidAdapter.js +++ b/modules/admixerBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { logError } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; @@ -61,7 +61,7 @@ export const spec = { const {body: {ads = []} = {}} = serverResponse; ads.forEach((ad) => bidResponses.push(ad)); } catch (e) { - utils.logError(e); + logError(e); } return bidResponses; }, diff --git a/modules/admixerIdSystem.js b/modules/admixerIdSystem.js index c963f1e5b88..49ffe4f4680 100644 --- a/modules/admixerIdSystem.js +++ b/modules/admixerIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import * as utils from '../src/utils.js' +import { logError, logInfo } from '../src/utils.js' import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -43,13 +43,13 @@ export const admixerIdSubmodule = { getId(config, consentData) { const {e, p, pid} = (config && config.params) || {}; if (!pid || typeof pid !== 'string') { - utils.logError('admixerId submodule requires partner id to be defined'); + logError('admixerId submodule requires partner id to be defined'); return; } const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; if (gdpr && !consentString) { - utils.logInfo('Consent string is required to call admixer id.'); + logInfo('Consent string is required to call admixer id.'); return; } const url = `https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}${e ? `&e=${e}` : ''}${p ? `&p=${p}` : ''}${consentString ? `&cs=${consentString}` : ''}`; @@ -83,7 +83,7 @@ function retrieveVisitorId(url, callback) { } }, error: error => { - utils.logInfo(`admixerId: fetch encountered an error`, error); + logInfo(`admixerId: fetch encountered an error`, error); callback(); } }, undefined, { method: 'GET', withCredentials: true }); diff --git a/modules/adnowBidAdapter.js b/modules/adnowBidAdapter.js index 7412db8d7b6..badf57ed5c9 100644 --- a/modules/adnowBidAdapter.js +++ b/modules/adnowBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { NATIVE, BANNER } from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; +import { parseSizesInput, deepAccess, parseQueryStringParameters } from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const BIDDER_CODE = 'adnow'; @@ -61,13 +61,13 @@ export const spec = { }; if (mediaType === BANNER) { - data.sizes = utils.parseSizesInput( + data.sizes = parseSizesInput( req.mediaTypes && req.mediaTypes.banner && req.mediaTypes.banner.sizes ).join('|') } else { data.width = data.height = 200; - let sizes = utils.deepAccess(req, 'mediaTypes.native.image.sizes', []); + let sizes = deepAccess(req, 'mediaTypes.native.image.sizes', []); if (sizes.length > 0) { const size = Array.isArray(sizes[0]) ? sizes[0] : sizes; @@ -81,7 +81,7 @@ export const spec = { return { method: 'GET', url: ENDPOINT, - data: utils.parseQueryStringParameters(data), + data: parseQueryStringParameters(data), options: { withCredentials: false, crossOrigin: true diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 68c3e9caffd..4429e37f091 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; +import { isStr, deepAccess } from '../src/utils.js'; import { config } from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -9,12 +9,12 @@ const ENDPOINT_URL = 'https://ads.adnuntius.delivery/i'; const GVLID = 855; const checkSegment = function (segment) { - if (utils.isStr(segment)) return segment; + if (isStr(segment)) return segment; if (segment.id) return segment.id } const getSegmentsFromOrtb = function (ortb2) { - const userData = utils.deepAccess(ortb2, 'user.data'); + const userData = deepAccess(ortb2, 'user.data'); let segments = []; if (userData) { userData.forEach(userdat => { @@ -59,8 +59,8 @@ export const spec = { const usi = getUsi(adnMeta, ortb2, bidderRequest) const segments = getSegmentsFromOrtb(ortb2); const tzo = new Date().getTimezoneOffset(); - const gdprApplies = utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies'); - const consentString = utils.deepAccess(bidderRequest, 'gdprConsent.consentString'); + const gdprApplies = deepAccess(bidderRequest, 'gdprConsent.gdprApplies'); + const consentString = deepAccess(bidderRequest, 'gdprConsent.consentString'); request.push('tzo=' + tzo) request.push('format=json') diff --git a/modules/adoceanBidAdapter.js b/modules/adoceanBidAdapter.js index 7ce9c7ae8f2..0c23f5e3d8a 100644 --- a/modules/adoceanBidAdapter.js +++ b/modules/adoceanBidAdapter.js @@ -1,11 +1,11 @@ -import * as utils from '../src/utils.js'; +import { _each, parseSizesInput, isStr, isArray } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'adocean'; function buildEndpointUrl(emiter, payloadMap) { const payload = []; - utils._each(payloadMap, function(v, k) { + _each(payloadMap, function(v, k) { payload.push(k + '=' + encodeURIComponent(v)); }); @@ -26,12 +26,12 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) { const bidIdMap = {}; - utils._each(masterBidRequests, function(bid, slaveId) { + _each(masterBidRequests, function(bid, slaveId) { if (!emiter) { emiter = bid.params.emiter; } - const slaveSizes = utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('_'); + const slaveSizes = parseSizesInput(bid.mediaTypes.banner.sizes).join('_'); const rawSlaveId = bid.params.slaveId.replace('adocean', ''); payload.aosspsizes.push(rawSlaveId + '~' + slaveSizes); @@ -95,7 +95,7 @@ export const spec = { isBidRequestValid: function(bid) { const requiredParams = ['slaveId', 'masterId', 'emiter']; - if (requiredParams.some(name => !utils.isStr(bid.params[name]) || !bid.params[name].length)) { + if (requiredParams.some(name => !isStr(bid.params[name]) || !bid.params[name].length)) { return false; } @@ -106,12 +106,12 @@ export const spec = { const bidRequestsByMaster = {}; let requests = []; - utils._each(validBidRequests, function(bidRequest) { + _each(validBidRequests, function(bidRequest) { assignToMaster(bidRequest, bidRequestsByMaster); }); - utils._each(bidRequestsByMaster, function(masterRequests, masterId) { - utils._each(masterRequests, function(instanceRequests) { + _each(bidRequestsByMaster, function(masterRequests, masterId) { + _each(masterRequests, function(instanceRequests) { requests.push(buildRequest(instanceRequests, masterId, bidderRequest.gdprConsent)); }); }); @@ -122,8 +122,8 @@ export const spec = { interpretResponse: function(serverResponse, bidRequest) { let bids = []; - if (utils.isArray(serverResponse.body)) { - utils._each(serverResponse.body, function(placementResponse) { + if (isArray(serverResponse.body)) { + _each(serverResponse.body, function(placementResponse) { interpretResponse(placementResponse, bidRequest, bids); }); } diff --git a/modules/adpartnerBidAdapter.js b/modules/adpartnerBidAdapter.js index e8942884a9c..e8d8a43aa1b 100644 --- a/modules/adpartnerBidAdapter.js +++ b/modules/adpartnerBidAdapter.js @@ -1,5 +1,5 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js' +import { buildUrl } from '../src/utils.js' import {ajax} from '../src/ajax.js'; const BIDDER_CODE = 'adpartner'; @@ -64,7 +64,7 @@ export const spec = { beaconParams.tag = beaconParams.tag.join(','); beaconParams.sizes = beaconParams.sizes.join(','); - let adPartnerRequestUrl = utils.buildUrl({ + let adPartnerRequestUrl = buildUrl({ protocol: ENDPOINT_PROTOCOL, hostname: ENDPOINT_DOMAIN, pathname: ENDPOINT_PATH, @@ -127,7 +127,7 @@ export const spec = { onBidWon: function(data) { data.winNotification.forEach(function(unitWon) { - let adPartnerBidWonUrl = utils.buildUrl({ + let adPartnerBidWonUrl = buildUrl({ protocol: ENDPOINT_PROTOCOL, hostname: ENDPOINT_DOMAIN, pathname: unitWon.path diff --git a/modules/adpod.js b/modules/adpod.js index 57baf5b5fc6..ddceed1c344 100644 --- a/modules/adpod.js +++ b/modules/adpod.js @@ -12,7 +12,10 @@ * module that designed to support adpod video type ads. This import process allows this module to effectively act as a sub-module. */ -import * as utils from '../src/utils.js'; +import { + generateUUID, deepAccess, logWarn, logInfo, isArrayOfNums, isArray, isNumber, logError, groupBy, compareOn, + isPlainObject +} from '../src/utils.js'; import { addBidToAuction, doCallbacksIfTimedout, AUCTION_IN_PROGRESS, callPrebidCache, getPriceByGranularity, getPriceGranularity } from '../src/auction.js'; import { checkAdUnitSetup } from '../src/prebid.js'; import { checkVideoBidSetup } from '../src/video.js'; @@ -45,7 +48,7 @@ function createBidCacheRegistry() { registry[auctionId] = {}; registry[auctionId].bidStorage = new Set(); registry[auctionId].queueDispatcher = createDispatcher(queueTimeDelay); - registry[auctionId].initialCacheKey = utils.generateUUID(); + registry[auctionId].initialCacheKey = generateUUID(); } return { @@ -68,7 +71,7 @@ function createBidCacheRegistry() { setupInitialCacheKey: function (bid) { if (!registry[bid.auctionId]) { registry[bid.auctionId] = {}; - registry[bid.auctionId].initialCacheKey = utils.generateUUID(); + registry[bid.auctionId].initialCacheKey = generateUUID(); } }, getInitialCacheKey: function (bid) { @@ -115,9 +118,9 @@ function createDispatcher(timeoutDuration) { function getPricePartForAdpodKey(bid) { let pricePart let prioritizeDeals = config.getConfig('adpod.prioritizeDeals'); - if (prioritizeDeals && utils.deepAccess(bid, 'video.dealTier')) { + if (prioritizeDeals && deepAccess(bid, 'video.dealTier')) { const adpodDealPrefix = config.getConfig(`adpod.dealTier.${bid.bidderCode}.prefix`); - pricePart = (adpodDealPrefix) ? adpodDealPrefix + utils.deepAccess(bid, 'video.dealTier') : utils.deepAccess(bid, 'video.dealTier'); + pricePart = (adpodDealPrefix) ? adpodDealPrefix + deepAccess(bid, 'video.dealTier') : deepAccess(bid, 'video.dealTier'); } else { const granularity = getPriceGranularity(bid.mediaType); pricePart = getPriceByGranularity(granularity)(bid); @@ -132,12 +135,12 @@ function getPricePartForAdpodKey(bid) { */ function attachPriceIndustryDurationKeyToBid(bid, brandCategoryExclusion) { let initialCacheKey = bidCacheRegistry.getInitialCacheKey(bid); - let duration = utils.deepAccess(bid, 'video.durationBucket'); + let duration = deepAccess(bid, 'video.durationBucket'); const pricePart = getPricePartForAdpodKey(bid); let pcd; if (brandCategoryExclusion) { - let category = utils.deepAccess(bid, 'meta.adServerCatId'); + let category = deepAccess(bid, 'meta.adServerCatId'); pcd = `${pricePart}_${category}_${duration}s`; } else { pcd = `${pricePart}_${duration}s`; @@ -168,7 +171,7 @@ function updateBidQueue(auctionInstance, bidResponse, afterBidAdded) { let killQueue = !!(auctionInstance.getAuctionStatus() !== AUCTION_IN_PROGRESS); callDispatcher(auctionInstance, bidListArr, afterBidAdded, killQueue); } else { - utils.logWarn('Attempted to cache a bid from an unknown auction. Bid:', bidResponse); + logWarn('Attempted to cache a bid from an unknown auction. Bid:', bidResponse); } } @@ -196,7 +199,7 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { store(bidList, function (error, cacheIds) { if (error) { - utils.logWarn(`Failed to save to the video cache: ${error}. Video bid(s) must be discarded.`); + logWarn(`Failed to save to the video cache: ${error}. Video bid(s) must be discarded.`); for (let i = 0; i < bidList.length; i++) { doCallbacksIfTimedout(auctionInstance, bidList[i]); } @@ -206,7 +209,7 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { if (cacheIds[i].uuid !== '') { addBidToAuction(auctionInstance, bidList[i]); } else { - utils.logInfo(`Detected a bid was not cached because the custom key was already registered. Attempted to use key: ${bidList[i].customCacheKey}. Bid was: `, bidList[i]); + logInfo(`Detected a bid was not cached because the custom key was already registered. Attempted to use key: ${bidList[i].customCacheKey}. Bid was: `, bidList[i]); } afterBidAdded(); } @@ -223,12 +226,12 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { * @param {Object} bidderRequest copy of bid's associated bidderRequest object */ export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAdded, bidderRequest) { - let videoConfig = utils.deepAccess(bidderRequest, 'mediaTypes.video'); + let videoConfig = deepAccess(bidderRequest, 'mediaTypes.video'); if (videoConfig && videoConfig.context === ADPOD) { let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion'); - let adServerCatId = utils.deepAccess(bidResponse, 'meta.adServerCatId'); + let adServerCatId = deepAccess(bidResponse, 'meta.adServerCatId'); if (!adServerCatId && brandCategoryExclusion) { - utils.logWarn('Detected a bid without meta.adServerCatId while setConfig({adpod.brandCategoryExclusion}) was enabled. This bid has been rejected:', bidResponse) + logWarn('Detected a bid without meta.adServerCatId while setConfig({adpod.brandCategoryExclusion}) was enabled. This bid has been rejected:', bidResponse) afterBidAdded(); } else { if (config.getConfig('adpod.deferCaching') === false) { @@ -260,12 +263,12 @@ export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAd */ export function checkAdUnitSetupHook(fn, adUnits) { let goodAdUnits = adUnits.filter(adUnit => { - let mediaTypes = utils.deepAccess(adUnit, 'mediaTypes'); - let videoConfig = utils.deepAccess(mediaTypes, 'video'); + let mediaTypes = deepAccess(adUnit, 'mediaTypes'); + let videoConfig = deepAccess(mediaTypes, 'video'); if (videoConfig && videoConfig.context === ADPOD) { // run check to see if other mediaTypes are defined (ie multi-format); reject adUnit if so if (Object.keys(mediaTypes).length > 1) { - utils.logWarn(`Detected more than one mediaType in adUnitCode: ${adUnit.code} while attempting to define an 'adpod' video adUnit. 'adpod' adUnits cannot be mixed with other mediaTypes. This adUnit will be removed from the auction.`); + logWarn(`Detected more than one mediaType in adUnitCode: ${adUnit.code} while attempting to define an 'adpod' video adUnit. 'adpod' adUnits cannot be mixed with other mediaTypes. This adUnit will be removed from the auction.`); return false; } @@ -274,20 +277,20 @@ export function checkAdUnitSetupHook(fn, adUnits) { let playerSize = !!( ( videoConfig.playerSize && ( - utils.isArrayOfNums(videoConfig.playerSize, 2) || ( - utils.isArray(videoConfig.playerSize) && videoConfig.playerSize.every(sz => utils.isArrayOfNums(sz, 2)) + isArrayOfNums(videoConfig.playerSize, 2) || ( + isArray(videoConfig.playerSize) && videoConfig.playerSize.every(sz => isArrayOfNums(sz, 2)) ) ) ) || (videoConfig.sizeConfig) ); - let adPodDurationSec = !!(videoConfig.adPodDurationSec && utils.isNumber(videoConfig.adPodDurationSec) && videoConfig.adPodDurationSec > 0); - let durationRangeSec = !!(videoConfig.durationRangeSec && utils.isArrayOfNums(videoConfig.durationRangeSec) && videoConfig.durationRangeSec.every(range => range > 0)); + let adPodDurationSec = !!(videoConfig.adPodDurationSec && isNumber(videoConfig.adPodDurationSec) && videoConfig.adPodDurationSec > 0); + let durationRangeSec = !!(videoConfig.durationRangeSec && isArrayOfNums(videoConfig.durationRangeSec) && videoConfig.durationRangeSec.every(range => range > 0)); if (!playerSize || !adPodDurationSec || !durationRangeSec) { errMsg += (!playerSize) ? '\nmediaTypes.video.playerSize' : ''; errMsg += (!adPodDurationSec) ? '\nmediaTypes.video.adPodDurationSec' : ''; errMsg += (!durationRangeSec) ? '\nmediaTypes.video.durationRangeSec' : ''; - utils.logWarn(errMsg); + logWarn(errMsg); return false; } } @@ -313,8 +316,8 @@ export function checkAdUnitSetupHook(fn, adUnits) { */ function checkBidDuration(bidderRequest, bidResponse) { const buffer = 2; - let bidDuration = utils.deepAccess(bidResponse, 'video.durationSeconds'); - let videoConfig = utils.deepAccess(bidderRequest, 'mediaTypes.video'); + let bidDuration = deepAccess(bidResponse, 'video.durationSeconds'); + let videoConfig = deepAccess(bidderRequest, 'mediaTypes.video'); let adUnitRanges = videoConfig.durationRangeSec; adUnitRanges.sort((a, b) => a - b); // ensure the ranges are sorted in numeric order @@ -324,14 +327,14 @@ function checkBidDuration(bidderRequest, bidResponse) { let nextHighestRange = find(adUnitRanges, range => (range + buffer) >= bidDuration); bidResponse.video.durationBucket = nextHighestRange; } else { - utils.logWarn(`Detected a bid with a duration value outside the accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Rejecting bid: `, bidResponse); + logWarn(`Detected a bid with a duration value outside the accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Rejecting bid: `, bidResponse); return false; } } else { if (find(adUnitRanges, range => range === bidDuration)) { bidResponse.video.durationBucket = bidDuration; } else { - utils.logWarn(`Detected a bid with a duration value not part of the list of accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Exact match durations must be used for this adUnit. Rejecting bid: `, bidResponse); + logWarn(`Detected a bid with a duration value not part of the list of accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Exact match durations must be used for this adUnit. Rejecting bid: `, bidResponse); return false; } } @@ -352,16 +355,16 @@ export function checkVideoBidSetupHook(fn, bid, bidRequest, videoMediaType, cont if (context === ADPOD) { let result = true; let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion'); - if (brandCategoryExclusion && !utils.deepAccess(bid, 'meta.primaryCatId')) { + if (brandCategoryExclusion && !deepAccess(bid, 'meta.primaryCatId')) { result = false; } - if (utils.deepAccess(bid, 'video')) { - if (!utils.deepAccess(bid, 'video.context') || bid.video.context !== ADPOD) { + if (deepAccess(bid, 'video')) { + if (!deepAccess(bid, 'video.context') || bid.video.context !== ADPOD) { result = false; } - if (!utils.deepAccess(bid, 'video.durationSeconds') || bid.video.durationSeconds <= 0) { + if (!deepAccess(bid, 'video.durationSeconds') || bid.video.durationSeconds <= 0) { result = false; } else { let isBidGood = checkBidDuration(bidRequest, bid); @@ -370,7 +373,7 @@ export function checkVideoBidSetupHook(fn, bid, bidRequest, videoMediaType, cont } if (!config.getConfig('cache.url') && bid.vastXml && !bid.vastUrl) { - utils.logError(` + logError(` This bid contains only vastXml and will not work when a prebid cache url is not specified. Try enabling prebid cache with pbjs.setConfig({ cache: {url: "..."} }); `); @@ -392,7 +395,7 @@ export function adpodSetConfig(config) { if (typeof config.bidQueueTimeDelay === 'number' && config.bidQueueTimeDelay > 0) { queueTimeDelay = config.bidQueueTimeDelay; } else { - utils.logWarn(`Detected invalid value for adpod.bidQueueTimeDelay in setConfig; must be a positive number. Using default: ${queueTimeDelay}`) + logWarn(`Detected invalid value for adpod.bidQueueTimeDelay in setConfig; must be a positive number. Using default: ${queueTimeDelay}`) } } @@ -400,7 +403,7 @@ export function adpodSetConfig(config) { if (typeof config.bidQueueSizeLimit === 'number' && config.bidQueueSizeLimit > 0) { queueSizeLimit = config.bidQueueSizeLimit; } else { - utils.logWarn(`Detected invalid value for adpod.bidQueueSizeLimit in setConfig; must be a positive number. Using default: ${queueSizeLimit}`) + logWarn(`Detected invalid value for adpod.bidQueueSizeLimit in setConfig; must be a positive number. Using default: ${queueSizeLimit}`) } } } @@ -464,7 +467,7 @@ export function sortByPricePerSecond(a, b) { */ export function getTargeting({ codes, callback } = {}) { if (!callback) { - utils.logError('No callback function was defined in the getTargeting call. Aborting getTargeting().'); + logError('No callback function was defined in the getTargeting call. Aborting getTargeting().'); return; } codes = codes || []; @@ -480,7 +483,7 @@ export function getTargeting({ codes, callback } = {}) { let prioritizeDeals = config.getConfig('adpod.prioritizeDeals'); if (prioritizeDeals) { let [otherBids, highPriorityDealBids] = bids.reduce((partitions, bid) => { - let bidDealTier = utils.deepAccess(bid, 'video.dealTier'); + let bidDealTier = deepAccess(bid, 'video.dealTier'); let minDealTier = config.getConfig(`adpod.dealTier.${bid.bidderCode}.minDealTier`); if (minDealTier && bidDealTier) { if (bidDealTier >= minDealTier) { @@ -506,7 +509,7 @@ export function getTargeting({ codes, callback } = {}) { if (deferCachingEnabled === false) { adPodAdUnits.forEach((adUnit) => { let adPodTargeting = []; - let adPodDurationSeconds = utils.deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); + let adPodDurationSeconds = deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); bids .filter((bid) => bid.adUnitCode === adUnit.code) @@ -530,7 +533,7 @@ export function getTargeting({ codes, callback } = {}) { } else { let bidsToCache = []; adPodAdUnits.forEach((adUnit) => { - let adPodDurationSeconds = utils.deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); + let adPodDurationSeconds = deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); bids .filter((bid) => bid.adUnitCode === adUnit.code) @@ -546,7 +549,7 @@ export function getTargeting({ codes, callback } = {}) { if (error) { callback(error, null); } else { - let groupedBids = utils.groupBy(bidsSuccessfullyCached, 'adUnitCode'); + let groupedBids = groupBy(bidsSuccessfullyCached, 'adUnitCode'); Object.keys(groupedBids).forEach((adUnitCode) => { let adPodTargeting = []; @@ -578,7 +581,7 @@ export function getTargeting({ codes, callback } = {}) { */ function getAdPodAdUnits(codes) { return auctionManager.getAdUnits() - .filter((adUnit) => utils.deepAccess(adUnit, 'mediaTypes.video.context') === ADPOD) + .filter((adUnit) => deepAccess(adUnit, 'mediaTypes.video.context') === ADPOD) .filter((adUnit) => (codes.length > 0) ? codes.indexOf(adUnit.code) != -1 : true); } @@ -590,10 +593,10 @@ function getAdPodAdUnits(codes) { function getExclusiveBids(bidsReceived) { let bids = bidsReceived .map((bid) => Object.assign({}, bid, { [TARGETING_KEY_PB_CAT_DUR]: bid.adserverTargeting[TARGETING_KEY_PB_CAT_DUR] })); - bids = utils.groupBy(bids, TARGETING_KEY_PB_CAT_DUR); + bids = groupBy(bids, TARGETING_KEY_PB_CAT_DUR); let filteredBids = []; Object.keys(bids).forEach((targetingKey) => { - bids[targetingKey].sort(utils.compareOn('responseTimestamp')); + bids[targetingKey].sort(compareOn('responseTimestamp')); filteredBids.push(bids[targetingKey][0]); }); return filteredBids; @@ -619,8 +622,8 @@ const sharedMethods = { Object.freeze(sharedMethods); module('adpod', function shareAdpodUtilities(...args) { - if (!utils.isPlainObject(args[0])) { - utils.logError('Adpod module needs plain object to share methods with submodule'); + if (!isPlainObject(args[0])) { + logError('Adpod module needs plain object to share methods with submodule'); return; } function addMethods(object, func) { diff --git a/modules/adprimeBidAdapter.js b/modules/adprimeBidAdapter.js index ef370301184..2b5a7e15af2 100644 --- a/modules/adprimeBidAdapter.js +++ b/modules/adprimeBidAdapter.js @@ -1,6 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; +import { isFn, deepAccess, logMessage } from '../src/utils.js'; const BIDDER_CODE = 'adprime'; const AD_URL = 'https://delta.adprime.com/pbjs'; @@ -24,8 +24,8 @@ function isBidResponseValid(bid) { } function getBidFloor(bid) { - if (!utils.isFn(bid.getFloor)) { - return utils.deepAccess(bid, 'params.bidfloor', 0); + if (!isFn(bid.getFloor)) { + return deepAccess(bid, 'params.bidfloor', 0); } try { @@ -56,7 +56,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - utils.logMessage(e); + logMessage(e); }; let placements = []; let request = { diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index bbff7edea47..ce31f64d705 100644 --- a/modules/adqueryBidAdapter.js +++ b/modules/adqueryBidAdapter.js @@ -1,6 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; +import { logInfo, buildUrl, triggerPixel } from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; const ADQUERY_GVLID = 902; @@ -55,8 +55,8 @@ export const spec = { * @return {Bid[]} */ interpretResponse: (response, request) => { - utils.logInfo(request); - utils.logInfo(response); + logInfo(request); + logInfo(response); const res = response && response.body && response.body.data; let bidResponses = []; @@ -84,7 +84,7 @@ export const spec = { } }; bidResponses.push(bidResponse); - utils.logInfo('bidResponses', bidResponses); + logInfo('bidResponses', bidResponses); return bidResponses; }, @@ -96,7 +96,7 @@ export const spec = { if (timeoutData == null) { return; } - utils.logInfo('onTimeout ', timeoutData); + logInfo('onTimeout ', timeoutData); let params = { bidder: timeoutData.bidder, bId: timeoutData.bidId, @@ -104,40 +104,40 @@ export const spec = { timeout: timeoutData.timeout, auctionId: timeoutData.auctionId, }; - let adqueryRequestUrl = utils.buildUrl({ + let adqueryRequestUrl = buildUrl({ protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, hostname: ADQUERY_BIDDER_DOMAIN, pathname: '/prebid/eventTimeout', search: params }); - utils.triggerPixel(adqueryRequestUrl); + triggerPixel(adqueryRequestUrl); }, /** * @param {Bid} bid */ onBidWon: (bid) => { - utils.logInfo('onBidWon', bid); + logInfo('onBidWon', bid); const bidString = JSON.stringify(bid); const encodedBuf = window.btoa(bidString); let params = { q: encodedBuf, }; - let adqueryRequestUrl = utils.buildUrl({ + let adqueryRequestUrl = buildUrl({ protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, hostname: ADQUERY_BIDDER_DOMAIN, pathname: '/prebid/eventBidWon', search: params }); - utils.triggerPixel(adqueryRequestUrl); + triggerPixel(adqueryRequestUrl); }, /** * @param {Bid} bid */ onSetTargeting: (bid) => { - utils.logInfo('onSetTargeting', bid); + logInfo('onSetTargeting', bid); let params = { bidder: bid.bidder, @@ -150,13 +150,13 @@ export const spec = { adUnitCode: bid.adUnitCode }; - let adqueryRequestUrl = utils.buildUrl({ + let adqueryRequestUrl = buildUrl({ protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, hostname: ADQUERY_BIDDER_DOMAIN, pathname: '/prebid/eventSetTargeting', search: params }); - utils.triggerPixel(adqueryRequestUrl); + triggerPixel(adqueryRequestUrl); }, getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { let syncUrl = ADQUERY_USER_SYNC_DOMAIN; diff --git a/modules/adrelevantisBidAdapter.js b/modules/adrelevantisBidAdapter.js index b6832cfeb0d..649031d1e3b 100644 --- a/modules/adrelevantisBidAdapter.js +++ b/modules/adrelevantisBidAdapter.js @@ -1,5 +1,8 @@ import { Renderer } from '../src/Renderer.js'; -import * as utils from '../src/utils.js'; +import { + logError, convertTypes, convertCamelToUnderscore, isArray, deepClone, logWarn, logMessage, getBidRequest, deepAccess, + isStr, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, chunk, isArrayOfNums +} from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; @@ -145,7 +148,7 @@ export const spec = { if (!serverResponse || serverResponse.error) { let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`; if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - utils.logError(errorMessage); + logError(errorMessage); return bids; } @@ -166,9 +169,9 @@ export const spec = { }, transformBidParams: function(params, isOpenRtb) { - params = utils.convertTypes({ + params = convertTypes({ 'placementId': 'number', - 'keywords': utils.transformBidderParamKeywords + 'keywords': transformBidderParamKeywords }, params); if (isOpenRtb) { @@ -180,7 +183,7 @@ export const spec = { } Object.keys(params).forEach(paramKey => { - let convertedKey = utils.convertCamelToUnderscore(paramKey); + let convertedKey = convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { params[convertedKey] = params[paramKey]; delete params[paramKey]; @@ -193,7 +196,7 @@ export const spec = { } function isPopulatedArray(arr) { - return !!(utils.isArray(arr) && arr.length > 0); + return !!(isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -206,9 +209,9 @@ function formatRequest(payload, bidderRequest) { let request = []; if (payload.tags.length > MAX_IMPS_PER_REQUEST) { - const clonedPayload = utils.deepClone(payload); + const clonedPayload = deepClone(payload); - utils.chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { + chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { clonedPayload.tags = tags; const payloadString = JSON.stringify(clonedPayload); request.push({ @@ -243,14 +246,14 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { try { renderer.setRender(outstreamRender); } catch (err) { - utils.logWarn('Prebid Error calling setRender on renderer', err); + logWarn('Prebid Error calling setRender on renderer', err); } renderer.setEventHandlers({ - impression: () => utils.logMessage('AdRelevantis outstream video impression event'), - loaded: () => utils.logMessage('AdRelevantis outstream video loaded event'), + impression: () => logMessage('AdRelevantis outstream video impression event'), + loaded: () => logMessage('AdRelevantis outstream video loaded event'), ended: () => { - utils.logMessage('AdRelevantis outstream renderer video event'); + logMessage('AdRelevantis outstream renderer video event'); document.querySelector(`#${adUnitCode}`).style.display = 'none'; } }); @@ -295,7 +298,7 @@ function handleOutstreamRendererEvents(bid, id, eventName) { * @return Bid */ function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); + const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { requestId: serverBid.uuid, cpm: rtbBid.cpm, @@ -324,7 +327,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { ttl: 3600 }); - const videoContext = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); + const videoContext = deepAccess(bidRequest, 'mediaTypes.video.context'); switch (videoContext) { case OUTSTREAM: bid.adResponse = serverBid; @@ -334,7 +337,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (rtbBid.renderer_url) { const videoBid = find(bidderRequest.bids, bid => bid.bidId === serverBid.uuid); - const rendererOptions = utils.deepAccess(videoBid, 'renderer.options'); + const rendererOptions = deepAccess(videoBid, 'renderer.options'); bid.renderer = newRenderer(bid.adUnitCode, rtbBid, rendererOptions); } break; @@ -354,7 +357,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (jsTrackers == undefined) { jsTrackers = jsTrackerDisarmed; - } else if (utils.isStr(jsTrackers)) { + } else if (isStr(jsTrackers)) { jsTrackers = [jsTrackers, jsTrackerDisarmed]; } else { jsTrackers.push(jsTrackerDisarmed); @@ -402,10 +405,10 @@ function newBid(serverBid, rtbBid, bidderRequest) { }); try { const url = rtbBid.rtb.trackers[0].impression_urls[0]; - const tracker = utils.createTrackPixelHtml(url); + const tracker = createTrackPixelHtml(url); bid.ad += tracker; } catch (error) { - utils.logError('Error appending tracking pixel', error); + logError('Error appending tracking pixel', error); } } @@ -449,8 +452,8 @@ function bidToTag(bid) { if (bid.params.externalImpId) { tag.external_imp_id = bid.params.externalImpId; } - if (!utils.isEmpty(bid.params.keywords)) { - let keywords = utils.transformBidderParamKeywords(bid.params.keywords); + if (!isEmpty(bid.params.keywords)) { + let keywords = transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); @@ -461,7 +464,7 @@ function bidToTag(bid) { tag.category = bid.params.category; } - if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) { + if (bid.mediaType === NATIVE || deepAccess(bid, `mediaTypes.${NATIVE}`)) { tag.ad_types.push(NATIVE); if (tag.sizes.length === 0) { tag.sizes = transformSizes([1, 1]); @@ -473,8 +476,8 @@ function bidToTag(bid) { } } - const videoMediaType = utils.deepAccess(bid, `mediaTypes.${VIDEO}`); - const context = utils.deepAccess(bid, 'mediaTypes.video.context'); + const videoMediaType = deepAccess(bid, `mediaTypes.${VIDEO}`); + const context = deepAccess(bid, 'mediaTypes.video.context'); tag.hb_source = 1; if (bid.mediaType === VIDEO || videoMediaType) { @@ -499,7 +502,7 @@ function bidToTag(bid) { } if ( - (utils.isEmpty(bid.mediaType) && utils.isEmpty(bid.mediaTypes)) || + (isEmpty(bid.mediaType) && isEmpty(bid.mediaTypes)) || (bid.mediaType === BANNER || (bid.mediaTypes && bid.mediaTypes[BANNER])) ) { tag.ad_types.push(BANNER); @@ -513,8 +516,8 @@ function transformSizes(requestSizes) { let sizes = []; let sizeObj = {}; - if (utils.isArray(requestSizes) && requestSizes.length === 2 && - !utils.isArray(requestSizes[0])) { + if (isArray(requestSizes) && requestSizes.length === 2 && + !isArray(requestSizes[0])) { sizeObj.width = parseInt(requestSizes[0], 10); sizeObj.height = parseInt(requestSizes[1], 10); sizes.push(sizeObj); @@ -575,7 +578,7 @@ function buildNativeRequest(params) { const isImageAsset = !!(requestKey === NATIVE_MAPPING.image.serverName || requestKey === NATIVE_MAPPING.icon.serverName); if (isImageAsset && request[requestKey].sizes) { let sizes = request[requestKey].sizes; - if (utils.isArrayOfNums(sizes) || (utils.isArray(sizes) && sizes.length > 0 && sizes.every(sz => utils.isArrayOfNums(sz)))) { + if (isArrayOfNums(sizes) || (isArray(sizes) && sizes.length > 0 && sizes.every(sz => isArrayOfNums(sz)))) { request[requestKey].sizes = transformSizes(request[requestKey].sizes); } }