From 33762d1ee5abd0363e2b35fbbb07cb2d38287972 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 12 Sep 2019 16:38:12 -0700 Subject: [PATCH 01/14] added support for pubcommon, digitrust, id5id --- modules/pubmaticBidAdapter.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index facecdaa578..2ec353a2f4e 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -624,10 +624,31 @@ function _handleTTDId(eids, validBidRequests) { } } +/** + * Produces external userid object in ortb 3.0 model. + */ +function _addExternalUserId(eids, value, source, atype) { + if (value) { + eids.push({ + source, + uids: [{ + id: value, + atype + }] + }); + } +} + function _handleEids(payload, validBidRequests) { let eids = []; _handleDigitrustId(eids); _handleTTDId(eids, validBidRequests); + const bidRequest = validBidRequests[0]; + if(bidRequest && bidRequest.userId){ + _addExternalUserId(eids, bidRequest.userId.pubcid, 'pubcommon', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest.userId.digitrustid, 'data.id'), 'digitru.st', 1); + _addExternalUserId(eids, bidRequest.userId.id5id, 'id5id', 1); + } if (eids.length > 0) { payload.user.eids = eids; } From 0722354d7e62dc2237e16f8b7f469557ef388a20 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 12 Sep 2019 20:11:24 -0700 Subject: [PATCH 02/14] added support for IdentityLink --- modules/pubmaticBidAdapter.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 2ec353a2f4e..8c72367ba6e 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -644,10 +644,12 @@ function _handleEids(payload, validBidRequests) { _handleDigitrustId(eids); _handleTTDId(eids, validBidRequests); const bidRequest = validBidRequests[0]; - if(bidRequest && bidRequest.userId){ - _addExternalUserId(eids, bidRequest.userId.pubcid, 'pubcommon', 1); - _addExternalUserId(eids, utils.deepAccess(bidRequest.userId.digitrustid, 'data.id'), 'digitru.st', 1); - _addExternalUserId(eids, bidRequest.userId.id5id, 'id5id', 1); + if (bidRequest && bidRequest.userId) { + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.pubcid`), 'pubcommon', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.digitrustid.data.id`), 'digitru.st', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5id', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.criteortus.${BIDDER_CODE}.userid`), 'criteortus', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.idl_env`), 'identity_link_envelope', 1); } if (eids.length > 0) { payload.user.eids = eids; From f2c32c07b4a4996e1e7d59510974c07d2eec7d5e Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 13 Sep 2019 10:02:20 -0700 Subject: [PATCH 03/14] changed the source for id5 --- modules/pubmaticBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 8c72367ba6e..c768583b96c 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -647,7 +647,7 @@ function _handleEids(payload, validBidRequests) { if (bidRequest && bidRequest.userId) { _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.pubcid`), 'pubcommon', 1); _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.digitrustid.data.id`), 'digitru.st', 1); - _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5id', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1); _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.criteortus.${BIDDER_CODE}.userid`), 'criteortus', 1); _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.idl_env`), 'identity_link_envelope', 1); } From eaed9874c1fc91d79118b148bbd740569e562023 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 13 Sep 2019 14:19:36 -0700 Subject: [PATCH 04/14] added unit test cases --- modules/pubmaticBidAdapter.js | 2 +- test/spec/modules/pubmaticBidAdapter_spec.js | 186 +++++++++++++++++++ 2 files changed, 187 insertions(+), 1 deletion(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index c768583b96c..a85a2c8e19c 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -628,7 +628,7 @@ function _handleTTDId(eids, validBidRequests) { * Produces external userid object in ortb 3.0 model. */ function _addExternalUserId(eids, value, source, atype) { - if (value) { + if (utils.isStr(value)) { eids.push({ source, uids: [{ diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 3de83c56213..d0d0ce8c08b 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1476,6 +1476,192 @@ describe('PubMatic adapter', function () { }); }); + describe('UserIds from request', function() { + describe('pubcommon Id', function() { + it('send the pubcommon id if it is present', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.pubcid = 'pub_common_user_id'; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'pubcommon', + 'uids': [{ + 'id': 'pub_common_user_id', + 'atype': 1 + }] + }]); + }); + + it('do not pass if not string', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.pubcid = 1; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.pubcid = []; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.pubcid = null; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.pubcid = {}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + }); + }); + + describe('Digitrust Id', function() { + it('send the digitrust id if it is present', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.digitrustid = {data: {id: 'digitrust_user_id'}}; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'digitru.st', + 'uids': [{ + 'id': 'digitrust_user_id', + 'atype': 1 + }] + }]); + }); + + it('do not pass if not string', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.digitrustid = {data: {id: 1}}; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.digitrustid = {data: {id: []}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.digitrustid = {data: {id: null}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.digitrustid = {data: {id: {}}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + }); + }); + + describe('ID5 Id', function() { + it('send the id5 id if it is present', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.id5id = 'id5-user-id'; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'id5-sync.com', + 'uids': [{ + 'id': 'id5-user-id', + 'atype': 1 + }] + }]); + }); + + it('do not pass if not string', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.id5id = 1; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.id5id = []; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.id5id = null; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.id5id = {}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + }); + }); + + describe('CriteoRTUS Id', function() { + it('send the criteo id if it is present', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.criteortus = {pubmatic: {userid: 'criteo-rtus-user-id'}}; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'criteortus', + 'uids': [{ + 'id': 'criteo-rtus-user-id', + 'atype': 1 + }] + }]); + }); + + it('do not pass if not string', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.criteortus = {appnexus: {userid: 'criteo-rtus-user-id'}}; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.criteortus = {pubmatic: {userid: 1}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.criteortus = {pubmatic: {userid: []}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.criteortus = {pubmatic: {userid: null}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.criteortus = {pubmatic: {userid: {}}}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + }); + }); + + describe('IdentityLink Id', function() { + it('send the identity-link id if it is present', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.idl_env = 'identity-link-user-id'; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'identity_link_envelope', + 'uids': [{ + 'id': 'identity-link-user-id', + 'atype': 1 + }] + }]); + }); + + it('do not pass if not string', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.idl_env = 1; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.idl_env = []; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.idl_env = null; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + bidRequests[0].userId.idl_env = {}; + request = spec.buildRequests(bidRequests, {}); + data = JSON.parse(request.data); + expect(data.user.eids).to.equal(undefined); + }); + }); + }) + it('Request params check for video ad', function () { let request = spec.buildRequests(videoBidRequests); let data = JSON.parse(request.data); From 602ee7ea83c07cf1ff83f6c000473512a9525b4c Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 16 Sep 2019 14:24:27 -0700 Subject: [PATCH 05/14] changed source param for identityLink --- modules/pubmaticBidAdapter.js | 2 +- test/spec/modules/pubmaticBidAdapter_spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index a85a2c8e19c..d1e1d072673 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -649,7 +649,7 @@ function _handleEids(payload, validBidRequests) { _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.digitrustid.data.id`), 'digitru.st', 1); _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1); _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.criteortus.${BIDDER_CODE}.userid`), 'criteortus', 1); - _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.idl_env`), 'identity_link_envelope', 1); + _addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.idl_env`), 'liveramp.com', 1); } if (eids.length > 0) { payload.user.eids = eids; diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index d0d0ce8c08b..ababf2dcf5f 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1632,7 +1632,7 @@ describe('PubMatic adapter', function () { let request = spec.buildRequests(bidRequests, {}); let data = JSON.parse(request.data); expect(data.user.eids).to.deep.equal([{ - 'source': 'identity_link_envelope', + 'source': 'liveramp.com', 'uids': [{ 'id': 'identity-link-user-id', 'atype': 1 From bc6c9f61f889e9aa2ef8ab207b87d4e7b49e3e57 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 12:55:56 -0700 Subject: [PATCH 06/14] import utils functions as needed and not the whole module --- modules/apacdexBidAdapter.js | 32 ++++----- modules/appnexusBidAdapter.js | 118 +++++++++++++++++----------------- modules/apstreamBidAdapter.js | 10 +-- modules/asoBidAdapter.js | 60 ++++++++--------- modules/astraoneBidAdapter.js | 4 +- 5 files changed, 112 insertions(+), 112 deletions(-) diff --git a/modules/apacdexBidAdapter.js b/modules/apacdexBidAdapter.js index 6c1c350b800..421eb99b4c1 100644 --- a/modules/apacdexBidAdapter.js +++ b/modules/apacdexBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'apacdex'; @@ -32,16 +32,16 @@ export const spec = { if (!bid.params.siteId && !bid.params.placementId) { return false; } - if (!utils.deepAccess(bid, 'mediaTypes.banner') && !utils.deepAccess(bid, 'mediaTypes.video')) { + if (!deepAccess(bid, 'mediaTypes.banner') && !deepAccess(bid, 'mediaTypes.video')) { return false; } - if (utils.deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video - if (!utils.deepAccess(bid, 'mediaTypes.banner.sizes')) { + if (deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video + if (!deepAccess(bid, 'mediaTypes.banner.sizes')) { // sizes at the banner is required. return false; } - } else if (utils.deepAccess(bid, 'mediaTypes.video')) { - if (!utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { + } else if (deepAccess(bid, 'mediaTypes.video')) { + if (!deepAccess(bid, 'mediaTypes.video.playerSize')) { // playerSize is required for instream adUnits. return false; } @@ -170,12 +170,12 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { const serverBody = serverResponse.body; - if (!serverBody || !utils.isPlainObject(serverBody)) { + if (!serverBody || !isPlainObject(serverBody)) { return []; } const serverBids = serverBody.bids; - if (!serverBids || !utils.isArray(serverBids)) { + if (!serverBids || !isArray(serverBids)) { return []; } @@ -197,12 +197,12 @@ export const spec = { bidResponse.dealId = dealId; } if (bid.vastXml) { - bidResponse.vastXml = utils.replaceAuctionPrice(bid.vastXml, bid.cpm); + bidResponse.vastXml = replaceAuctionPrice(bid.vastXml, bid.cpm); } else { - bidResponse.ad = utils.replaceAuctionPrice(bid.ad, bid.cpm); + bidResponse.ad = replaceAuctionPrice(bid.ad, bid.cpm); } bidResponse.meta = {}; - if (bid.meta && bid.meta.advertiserDomains && utils.isArray(bid.meta.advertiserDomains)) { + if (bid.meta && bid.meta.advertiserDomains && isArray(bid.meta.advertiserDomains)) { bidResponse.meta.advertiserDomains = bid.meta.advertiserDomains; } bidResponses.push(bidResponse); @@ -285,7 +285,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { if (config.getConfig('pageUrl')) { return config.getConfig('pageUrl'); } - if (utils.deepAccess(bidderRequest, 'refererInfo.referer')) { + if (deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -303,7 +303,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { * @returns {string} */ function _extractTopWindowReferrerFromBidderRequest(bidderRequest) { - if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.referer')) { + if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -340,7 +340,7 @@ export function getDomain(pageUrl) { * @returns {boolean} */ export function validateGeoObject(geo) { - if (!utils.isPlainObject(geo)) { + if (!isPlainObject(geo)) { return false; } if (!geo.lat) { @@ -362,7 +362,7 @@ export function validateGeoObject(geo) { * @returns {float||null} */ function getBidFloor(bid) { - if (!utils.isFn(bid.getFloor)) { + if (!isFn(bid.getFloor)) { return (bid.params.floorPrice) ? bid.params.floorPrice : null; } @@ -371,7 +371,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 9882e71fe4f..7dcbd74d779 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,5 +1,5 @@ +import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, logError, logInfo, deepAccess, logMessage, convertTypes, isStr, getParameterByName, deepClone, chunk, logWarn, getBidRequest, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, getMaxValueFromArray, fill, getMinValueFromArray, isArrayOfNums, isFn } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; -import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder, getIabSubCategory } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO, ADPOD } from '../src/mediaTypes.js'; @@ -109,13 +109,13 @@ export const spec = { Object.keys(userObjBid.params.user) .filter(param => includes(USER_PARAMS, param)) .forEach((param) => { - let uparam = utils.convertCamelToUnderscore(param); - if (param === 'segments' && utils.isArray(userObjBid.params.user[param])) { + let uparam = convertCamelToUnderscore(param); + if (param === 'segments' && isArray(userObjBid.params.user[param])) { let segs = []; userObjBid.params.user[param].forEach(val => { - if (utils.isNumber(val)) { + if (isNumber(val)) { segs.push({'id': val}); - } else if (utils.isPlainObject(val)) { + } else if (isPlainObject(val)) { segs.push(val); } }); @@ -152,7 +152,7 @@ export const spec = { try { debugObj = JSON.parse(debugCookie); } catch (e) { - utils.logError('AppNexus Debug Auction Cookie Error:\n\n' + e); + logError('AppNexus Debug Auction Cookie Error:\n\n' + e); } } else { const debugBidRequest = find(bidRequests, hasDebug); @@ -208,7 +208,7 @@ export const spec = { if (debugObjParams.enabled) { payload.debug = debugObjParams; - utils.logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); + logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); } if (bidderRequest && bidderRequest.gdprConsent) { @@ -253,12 +253,12 @@ export const spec = { if (bidRequests[0].userId) { let eids = []; - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); - addUserId(eids, utils.deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); + addUserId(eids, deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); + addUserId(eids, deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); + addUserId(eids, deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); + addUserId(eids, deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); + addUserId(eids, deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); + addUserId(eids, deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); if (eids.length) { payload.eids = eids; @@ -285,7 +285,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; } @@ -313,8 +313,8 @@ export const spec = { .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags - utils.logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); - utils.logMessage(debugText); + logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); + logMessage(debugText); } return bids; @@ -348,11 +348,11 @@ export const spec = { }, transformBidParams: function (params, isOpenRtb) { - params = utils.convertTypes({ + params = convertTypes({ 'member': 'string', 'invCode': 'string', 'placementId': 'number', - 'keywords': utils.transformBidderParamKeywords, + 'keywords': transformBidderParamKeywords, 'publisherId': 'number' }, params); @@ -365,7 +365,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]; @@ -388,7 +388,7 @@ export const spec = { } function isPopulatedArray(arr) { - return !!(utils.isArray(arr) && arr.length > 0); + return !!(isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -460,9 +460,9 @@ function strIsAppnexusViewabilityScript(str) { function getAppnexusViewabilityScriptFromJsTrackers(jsTrackerArray) { let viewJsPayload; - if (utils.isStr(jsTrackerArray) && strIsAppnexusViewabilityScript(jsTrackerArray)) { + if (isStr(jsTrackerArray) && strIsAppnexusViewabilityScript(jsTrackerArray)) { viewJsPayload = jsTrackerArray; - } else if (utils.isArray(jsTrackerArray)) { + } else if (isArray(jsTrackerArray)) { for (let i = 0; i < jsTrackerArray.length; i++) { let currentJsTracker = jsTrackerArray[i]; if (strIsAppnexusViewabilityScript(currentJsTracker)) { @@ -486,7 +486,7 @@ function hasPurpose1Consent(bidderRequest) { let result = true; if (bidderRequest && bidderRequest.gdprConsent) { if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -504,16 +504,16 @@ function formatRequest(payload, bidderRequest) { endpointUrl = URL_SIMPLE; } - if (utils.getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true) { + if (getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true) { options.customHeaders = { 'X-Is-Test': 1 } } 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({ @@ -550,14 +550,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('AppNexus outstream video impression event'), - loaded: () => utils.logMessage('AppNexus outstream video loaded event'), + impression: () => logMessage('AppNexus outstream video impression event'), + loaded: () => logMessage('AppNexus outstream video loaded event'), ended: () => { - utils.logMessage('AppNexus outstream renderer video event'); + logMessage('AppNexus outstream renderer video event'); document.querySelector(`#${adUnitCode}`).style.display = 'none'; } }); @@ -572,7 +572,7 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { * @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, @@ -607,7 +607,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 ADPOD: const primaryCatId = getIabSubCategory(bidRequest.bidder, rtbBid.brand_category_id); @@ -628,7 +628,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; @@ -648,7 +648,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); @@ -697,11 +697,11 @@ function newBid(serverBid, rtbBid, bidderRequest) { try { if (rtbBid.rtb.trackers) { 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); } } @@ -751,8 +751,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); @@ -760,12 +760,12 @@ function bidToTag(bid) { tag.keywords = keywords; } - let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); if (gpid) { tag.gpid = gpid; } - 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]); @@ -777,8 +777,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'); if (videoMediaType && context === 'adpod') { tag.hb_source = 7; @@ -804,7 +804,7 @@ function bidToTag(bid) { case 'context': case 'playback_method': let type = bid.params.video[param]; - type = (utils.isArray(type)) ? type[0] : type; + type = (isArray(type)) ? type[0] : type; tag.video[param] = VIDEO_MAPPING[param][type]; break; // Deprecating tags[].video.frameworks in favor of tags[].video_frameworks @@ -815,7 +815,7 @@ function bidToTag(bid) { } }); - if (bid.params.video.frameworks && utils.isArray(bid.params.video.frameworks)) { + if (bid.params.video.frameworks && isArray(bid.params.video.frameworks)) { tag['video_frameworks'] = bid.params.video.frameworks; } } @@ -840,7 +840,7 @@ function bidToTag(bid) { case 'playbackmethod': if (typeof tag.video['playback_method'] !== 'number') { let type = videoMediaType[param]; - type = (utils.isArray(type)) ? type[0] : type; + type = (isArray(type)) ? type[0] : type; // we only support iab's options 1-4 at this time. if (type >= 1 && type <= 4) { @@ -849,7 +849,7 @@ function bidToTag(bid) { } break; case 'api': - if (!tag['video_frameworks'] && utils.isArray(videoMediaType[param])) { + if (!tag['video_frameworks'] && isArray(videoMediaType[param])) { // need to read thru array; remove 6 (we don't support it), swap 4 <> 5 if found (to match our adserver mapping for these specific values) let apiTmp = videoMediaType[param].map(val => { let v = (val === 4) ? 5 : (val === 5) ? 4 : val; @@ -869,7 +869,7 @@ function bidToTag(bid) { tag.video = Object.assign({}, tag.video, { custom_renderer_present: true }); } - if (bid.params.frameworks && utils.isArray(bid.params.frameworks)) { + if (bid.params.frameworks && isArray(bid.params.frameworks)) { tag['banner_frameworks'] = bid.params.frameworks; } @@ -890,8 +890,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); @@ -945,10 +945,10 @@ function hasOmidSupport(bid) { let hasOmid = false; const bidderParams = bid.params; const videoParams = bid.params.video; - if (bidderParams.frameworks && utils.isArray(bidderParams.frameworks)) { + if (bidderParams.frameworks && isArray(bidderParams.frameworks)) { hasOmid = includes(bid.params.frameworks, 6); } - if (!hasOmid && videoParams && videoParams.frameworks && utils.isArray(videoParams.frameworks)) { + if (!hasOmid && videoParams && videoParams.frameworks && isArray(videoParams.frameworks)) { hasOmid = includes(bid.params.video.frameworks, 6); } return hasOmid; @@ -963,14 +963,14 @@ function createAdPodRequest(tags, adPodBid) { const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = utils.getMaxValueFromArray(durationRangeSec); + const maxDuration = getMaxValueFromArray(durationRangeSec); const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); - let request = utils.fill(...tagToDuplicate, numberOfPlacements); + let request = fill(...tagToDuplicate, numberOfPlacements); if (requireExactDuration) { const divider = Math.ceil(numberOfPlacements / durationRangeSec.length); - const chunked = utils.chunk(request, divider); + const chunked = chunk(request, divider); // each configured duration is set as min/maxduration for a subset of requests durationRangeSec.forEach((duration, index) => { @@ -989,7 +989,7 @@ function createAdPodRequest(tags, adPodBid) { function getAdPodPlacementNumber(videoParams) { const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = utils.getMinValueFromArray(durationRangeSec); + const minAllowedDuration = getMinValueFromArray(durationRangeSec); const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); return requireExactDuration @@ -998,7 +998,7 @@ function getAdPodPlacementNumber(videoParams) { } function setVideoProperty(tag, key, value) { - if (utils.isEmpty(tag.video)) { tag.video = {}; } + if (isEmpty(tag.video)) { tag.video = {}; } tag.video[key] = value; } @@ -1029,7 +1029,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); } } @@ -1108,7 +1108,7 @@ function addUserId(eids, id, source, rti) { } function getBidFloor(bid) { - if (!utils.isFn(bid.getFloor)) { + if (!isFn(bid.getFloor)) { return (bid.params.reserve) ? bid.params.reserve : null; } @@ -1117,7 +1117,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/apstreamBidAdapter.js b/modules/apstreamBidAdapter.js index 4fb89b9c720..f2d4189f237 100644 --- a/modules/apstreamBidAdapter.js +++ b/modules/apstreamBidAdapter.js @@ -1,6 +1,6 @@ +import { generateUUID, deepAccess, createTrackPixelHtml, getDNT } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; -import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; const CONSTANTS = { @@ -221,7 +221,7 @@ var dsuModule = (function() { } function generateDsu() { - var dsuId = utils.generateUUID(); + var dsuId = generateUUID(); var loc = location(); var dsuIdSuffix = hashWithKey(dsuId + loc.toString()); @@ -303,7 +303,7 @@ function getConsentStringFromPrebid(gdprConsentConfig) { } function getIabConsentString(bidderRequest) { - if (utils.deepAccess(bidderRequest, 'gdprConsent')) { + if (deepAccess(bidderRequest, 'gdprConsent')) { return getConsentStringFromPrebid(bidderRequest.gdprConsent); } @@ -318,7 +318,7 @@ function injectPixels(ad, pixels, scripts) { let trackedAd = ad; if (pixels) { pixels.forEach(pixel => { - const tracker = utils.createTrackPixelHtml(pixel); + const tracker = createTrackPixelHtml(pixel); trackedAd += tracker; }); } @@ -420,7 +420,7 @@ function buildRequests(bidRequests, bidderRequest) { med: encodeURIComponent(window.location.href), auid: bidderRequest.auctionId, ref: document.referrer, - dnt: utils.getDNT() ? 1 : 0, + dnt: getDNT() ? 1 : 0, sr: getScreenParams() }; diff --git a/modules/asoBidAdapter.js b/modules/asoBidAdapter.js index 8f06b8ed856..bf45b9ee48f 100644 --- a/modules/asoBidAdapter.js +++ b/modules/asoBidAdapter.js @@ -1,5 +1,5 @@ +import { _each, deepAccess, logWarn, tryAppendQueryString, inIframe, getWindowTop, parseUrl, parseSizesInput, isFn, getDNT, deepSetValue } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; @@ -22,16 +22,16 @@ export const spec = { buildRequests: (validBidRequests, bidderRequest) => { let serverRequests = []; - utils._each(validBidRequests, bidRequest => { + _each(validBidRequests, bidRequest => { const payload = createBasePayload(bidRequest, bidderRequest); - const bannerParams = utils.deepAccess(bidRequest, 'mediaTypes.banner'); - const videoParams = utils.deepAccess(bidRequest, 'mediaTypes.video'); + const bannerParams = deepAccess(bidRequest, 'mediaTypes.banner'); + const videoParams = deepAccess(bidRequest, 'mediaTypes.video'); let imp; if (bannerParams && videoParams) { - utils.logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') + logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') } if (bannerParams) { @@ -93,7 +93,7 @@ export const spec = { bid.ad = serverBid.adm; } else if (bid.mediaType === VIDEO) { bid.vastXml = serverBid.adm; - if (utils.deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { + if (deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { bid.adResponse = { content: bid.vastXml, }; @@ -112,25 +112,25 @@ export const spec = { if (serverResponses && serverResponses.length !== 0) { let query = ''; if (gdprConsent) { - query = utils.tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); - query = utils.tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); + query = tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + query = tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); const consentsIds = getConsentsIds(gdprConsent); if (consentsIds) { - query = utils.tryAppendQueryString(query, 'consents', consentsIds); + query = tryAppendQueryString(query, 'consents', consentsIds); } } if (uspConsent) { - query = utils.tryAppendQueryString(query, 'us_privacy', uspConsent); + query = tryAppendQueryString(query, 'us_privacy', uspConsent); } - utils._each(serverResponses, resp => { - const userSyncs = utils.deepAccess(resp, 'body.ext.user_syncs'); + _each(serverResponses, resp => { + const userSyncs = deepAccess(resp, 'body.ext.user_syncs'); if (!userSyncs) { return; } - utils._each(userSyncs, us => { + _each(userSyncs, us => { urls.push({ type: us.type, url: us.url + (query ? '?' + query : '') @@ -159,7 +159,7 @@ function createRenderer(bid, url) { id: bid.bidId, url: url, loaded: false, - config: utils.deepAccess(bid, 'renderer.options'), + config: deepAccess(bid, 'renderer.options'), adUnitCode: bid.adUnitCode }); renderer.setRender(outstreamRender); @@ -172,16 +172,16 @@ function getUrlsInfo(bidderRequest) { const {refererInfo} = bidderRequest; - if (utils.inIframe()) { + if (inIframe()) { page = refererInfo.referer; } else { - const w = utils.getWindowTop(); + const w = getWindowTop(); page = w.location.href; referrer = w.document.referrer || ''; } page = config.getConfig('pageUrl') || page; - const url = utils.parseUrl(page); + const url = parseUrl(page); const domain = url.hostname; return { @@ -192,7 +192,7 @@ function getUrlsInfo(bidderRequest) { } function getSize(paramSizes) { - const parsedSizes = utils.parseSizesInput(paramSizes); + const parsedSizes = parseSizesInput(paramSizes); const sizes = parsedSizes.map(size => { const [width, height] = size.split('x'); const w = parseInt(width, 10); @@ -204,7 +204,7 @@ function getSize(paramSizes) { } function getBidFloor(bidRequest, size) { - if (!utils.isFn(bidRequest.getFloor)) { + if (!isFn(bidRequest.getFloor)) { return null; } @@ -245,7 +245,7 @@ function createBannerImp(bidRequest, bannerParams) { imp.banner = { w: size.w, h: size.h, - topframe: utils.inIframe() ? 0 : 1 + topframe: inIframe() ? 0 : 1 } return imp; @@ -284,7 +284,7 @@ function getEnpoint(bidRequest) { } function getConsentsIds(gdprConsent) { - const consents = utils.deepAccess(gdprConsent, 'vendorData.purpose.consents', []); + const consents = deepAccess(gdprConsent, 'vendorData.purpose.consents', []); let consentsIds = []; Object.keys(consents).forEach(function (key) { @@ -310,7 +310,7 @@ function createBasePayload(bidRequest, bidderRequest) { ref: urlsInfo.referrer }, device: { - dnt: utils.getDNT() ? 1 : 0, + dnt: getDNT() ? 1 : 0, h: window.innerHeight, w: window.innerWidth, }, @@ -320,29 +320,29 @@ function createBasePayload(bidRequest, bidderRequest) { }; if (bidRequest.params.attr) { - utils.deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); + deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); } if (bidderRequest.gdprConsent) { - utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); const consentsIds = getConsentsIds(bidderRequest.gdprConsent); if (consentsIds) { - utils.deepSetValue(payload, 'user.ext.consents', consentsIds); + deepSetValue(payload, 'user.ext.consents', consentsIds); } - utils.deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); + deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); } if (bidderRequest.uspConsent) { - utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa')) { - utils.deepSetValue(payload, 'regs.coppa', 1); + deepSetValue(payload, 'regs.coppa', 1); } - const eids = utils.deepAccess(bidRequest, 'userIdAsEids'); + const eids = deepAccess(bidRequest, 'userIdAsEids'); if (eids && eids.length) { - utils.deepSetValue(payload, 'user.ext.eids', eids); + deepSetValue(payload, 'user.ext.eids', eids); } return payload; diff --git a/modules/astraoneBidAdapter.js b/modules/astraoneBidAdapter.js index 2fec3892d27..c233e665499 100644 --- a/modules/astraoneBidAdapter.js +++ b/modules/astraoneBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js' +import { _map } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER } from '../src/mediaTypes.js' @@ -7,7 +7,7 @@ const SSP_ENDPOINT = 'https://ssp.astraone.io/auction/prebid'; const TTL = 60; function buildBidRequests(validBidRequests) { - return utils._map(validBidRequests, function(validBidRequest) { + return _map(validBidRequests, function(validBidRequest) { const params = validBidRequest.params; const bidRequest = { bidId: validBidRequest.bidId, From ef500abb06648c763caa066ccd18fd5a18f2a1b5 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 13:03:13 -0700 Subject: [PATCH 07/14] import utils functions as needed and not the whole module --- modules/atsAnalyticsAdapter.js | 22 +++++++-------- modules/audiencerunBidAdapter.js | 30 ++++++++++----------- modules/automatadBidAdapter.js | 4 +-- modules/axonixBidAdapter.js | 14 +++++----- modules/beachfrontBidAdapter.js | 46 ++++++++++++++++---------------- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index 0cff7bbd68f..df293556a4c 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -1,7 +1,7 @@ +import { logError, logInfo } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adaptermanager from '../src/adapterManager.js'; -import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -256,7 +256,7 @@ export function parseBrowser() { let browserName = result && result.length ? result[0].name : ''; return (listOfSupportedBrowsers.indexOf(browserName) >= 0) ? browserName : 'Unknown'; } catch (err) { - utils.logError('ATS Analytics - Error while checking user browser!', err); + logError('ATS Analytics - Error while checking user browser!', err); } } @@ -265,20 +265,20 @@ function sendDataToAnalytic () { try { let dataToSend = {'Data': atsAnalyticsAdapter.context.events}; let strJSON = JSON.stringify(dataToSend); - utils.logInfo('ATS Analytics - tried to send analytics data!'); + logInfo('ATS Analytics - tried to send analytics data!'); ajax(analyticsUrl, function () { }, strJSON, {method: 'POST', contentType: 'application/json'}); } catch (err) { - utils.logError('ATS Analytics - request encounter an error: ', err); + logError('ATS Analytics - request encounter an error: ', err); } } // preflight request, to check did publisher have permission to send data to analytics endpoint function preflightRequest (envelopeSourceCookieValue) { - utils.logInfo('ATS Analytics - preflight request!'); + logInfo('ATS Analytics - preflight request!'); ajax(preflightUrl + atsAnalyticsAdapter.context.pid, function (data) { let samplingRateObject = JSON.parse(data); - utils.logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); + logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); let samplingRate = samplingRateObject['samplingRate']; setSamplingCookie(samplingRate); let samplingRateNumber = Number(samplingRate); @@ -332,7 +332,7 @@ let atsAnalyticsAdapter = Object.assign(adapter( } } } catch (err) { - utils.logError('ATS Analytics - preflight request encounter an error: ', err); + logError('ATS Analytics - preflight request encounter an error: ', err); } } } @@ -345,10 +345,10 @@ atsAnalyticsAdapter.originEnableAnalytics = atsAnalyticsAdapter.enableAnalytics; atsAnalyticsAdapter.shouldFireRequest = function (samplingRate) { if (samplingRate !== 0) { let shouldFireRequestValue = (Math.floor((Math.random() * 100 + 1)) === 100); - utils.logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); + logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); return shouldFireRequestValue; } else { - utils.logInfo('ATS Analytics - Should Fire Request: ', false); + logInfo('ATS Analytics - Should Fire Request: ', false); return false; } }; @@ -359,7 +359,7 @@ atsAnalyticsAdapter.getUserAgent = function () { // override enableAnalytics so we can get access to the config passed in from the page atsAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.pid) { - utils.logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); + logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); return; } atsAnalyticsAdapter.context = { @@ -367,7 +367,7 @@ atsAnalyticsAdapter.enableAnalytics = function (config) { pid: config.options.pid }; let initOptions = config.options; - utils.logInfo('ATS Analytics - adapter enabled! '); + logInfo('ATS Analytics - adapter enabled! '); atsAnalyticsAdapter.originEnableAnalytics(initOptions); // call the base class function }; diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index da0cbb39925..2c100bce27b 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, isFn, logError, getValue, getBidIdParameter, _each, isArray, triggerPixel } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -20,7 +20,7 @@ let requestedBids = []; function getPageUrl(bidderRequest) { return ( config.getConfig('pageUrl') || - utils.deepAccess(bidderRequest, 'refererInfo.referer') || + deepAccess(bidderRequest, 'refererInfo.referer') || null ); } @@ -32,8 +32,8 @@ function getPageUrl(bidderRequest) { * @returns {number} */ 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 { @@ -61,8 +61,8 @@ export const spec = { */ isBidRequestValid: function (bid) { let isValid = true; - if (!utils.deepAccess(bid, 'params.zoneId')) { - utils.logError('AudienceRun zoneId parameter is required. Bid aborted.'); + if (!deepAccess(bid, 'params.zoneId')) { + logError('AudienceRun zoneId parameter is required. Bid aborted.'); isValid = false; } return isValid; @@ -77,19 +77,19 @@ export const spec = { */ buildRequests: function (bidRequests, bidderRequest) { const bids = bidRequests.map((bid) => { - const sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes', []); + const sizes = deepAccess(bid, 'mediaTypes.banner.sizes', []); return { - zoneId: utils.getValue(bid.params, 'zoneId'), + zoneId: getValue(bid.params, 'zoneId'), sizes: sizes.map((size) => ({ w: size[0], h: size[1], })), bidfloor: getBidFloor(bid), bidId: bid.bidId, - bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), - adUnitCode: utils.getBidIdParameter('adUnitCode', bid), - auctionId: utils.getBidIdParameter('auctionId', bid), - transactionId: utils.getBidIdParameter('transactionId', bid), + bidderRequestId: getBidIdParameter('bidderRequestId', bid), + adUnitCode: getBidIdParameter('adUnitCode', bid), + auctionId: getBidIdParameter('auctionId', bid), + transactionId: getBidIdParameter('transactionId', bid), }; }); @@ -133,7 +133,7 @@ export const spec = { */ interpretResponse: function (serverResponse, bidRequest) { const bids = []; - utils._each(serverResponse.body.bid, function (bidObject) { + _each(serverResponse.body.bid, function (bidObject) { if (!bidObject.cpm || bidObject.cpm === null || !bidObject.adm) { return; } @@ -196,7 +196,7 @@ export const spec = { * @param {Array} timeoutData timeout specific data */ onTimeout: function (timeoutData) { - if (!utils.isArray(timeoutData)) { + if (!isArray(timeoutData)) { return; } @@ -204,7 +204,7 @@ export const spec = { const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId); if (bidOnTimeout) { - utils.triggerPixel( + triggerPixel( `${TIMEOUT_EVENT_URL}/${bidOnTimeout.zoneId}/${bidOnTimeout.bidId}` ); } diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 415c52ba6d3..2cfcfbe98b4 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -1,5 +1,5 @@ +import { logInfo } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js' -import * as utils from '../src/utils.js' import {BANNER} from '../src/mediaTypes.js' import {ajax} from '../src/ajax.js' @@ -92,7 +92,7 @@ export const spec = { }) }) } else { - utils.logInfo('automatad :: no valid responses to interpret') + logInfo('automatad :: no valid responses to interpret') } return bidResponses diff --git a/modules/axonixBidAdapter.js b/modules/axonixBidAdapter.js index daaac27e6a4..7cd8f63bd2a 100644 --- a/modules/axonixBidAdapter.js +++ b/modules/axonixBidAdapter.js @@ -1,7 +1,7 @@ +import { isArray, logError, deepAccess, isEmpty, triggerPixel, replaceAuctionPrice } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; -import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; const BIDDER_CODE = 'axonix'; @@ -68,9 +68,9 @@ export const spec = { // video bid request validation if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { if (!bid.mediaTypes[VIDEO].hasOwnProperty('mimes') || - !utils.isArray(bid.mediaTypes[VIDEO].mimes) || + !isArray(bid.mediaTypes[VIDEO].mimes) || bid.mediaTypes[VIDEO].mimes.length === 0) { - utils.logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); + logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); return false; } @@ -142,7 +142,7 @@ export const spec = { interpretResponse: function(serverResponse) { const response = serverResponse ? serverResponse.body : []; - if (!utils.isArray(response)) { + if (!isArray(response)) { return []; } @@ -160,9 +160,9 @@ export const spec = { }, onTimeout: function(timeoutData) { - const params = utils.deepAccess(timeoutData, '0.params.0'); + const params = deepAccess(timeoutData, '0.params.0'); - if (!utils.isEmpty(params)) { + if (!isEmpty(params)) { ajax(getURL(params, 'prebid/timeout'), null, timeoutData[0], { method: 'POST', options: { @@ -177,7 +177,7 @@ export const spec = { const { nurl } = bid || {}; if (bid.nurl) { - utils.triggerPixel(utils.replaceAuctionPrice(nurl, bid.cpm)); + triggerPixel(replaceAuctionPrice(nurl, bid.cpm)); }; } } diff --git a/modules/beachfrontBidAdapter.js b/modules/beachfrontBidAdapter.js index 3531fa45d1b..a882a796851 100644 --- a/modules/beachfrontBidAdapter.js +++ b/modules/beachfrontBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { logWarn, deepAccess, isArray, parseSizesInput, isFn, parseUrl, getUniqueIdentifierStr } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; @@ -34,21 +34,21 @@ export const spec = { isBidRequestValid(bid) { if (isVideoBid(bid)) { if (!getVideoBidParam(bid, 'appId')) { - utils.logWarn('Beachfront: appId param is required for video bids.'); + logWarn('Beachfront: appId param is required for video bids.'); return false; } if (!getVideoBidParam(bid, 'bidfloor')) { - utils.logWarn('Beachfront: bidfloor param is required for video bids.'); + logWarn('Beachfront: bidfloor param is required for video bids.'); return false; } } if (isBannerBid(bid)) { if (!getBannerBidParam(bid, 'appId')) { - utils.logWarn('Beachfront: appId param is required for banner bids.'); + logWarn('Beachfront: appId param is required for banner bids.'); return false; } if (!getBannerBidParam(bid, 'bidfloor')) { - utils.logWarn('Beachfront: bidfloor param is required for banner bids.'); + logWarn('Beachfront: bidfloor param is required for banner bids.'); return false; } } @@ -85,12 +85,12 @@ export const spec = { if (isVideoBid(bidRequest)) { if (!response || !response.bidPrice) { - utils.logWarn(`No valid video bids from ${spec.code} bidder`); + logWarn(`No valid video bids from ${spec.code} bidder`); return []; } let sizes = getVideoSizes(bidRequest); let firstSize = getFirstSize(sizes); - let context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); + let context = deepAccess(bidRequest, 'mediaTypes.video.context'); let responseType = getVideoBidParam(bidRequest, 'responseType') || 'both'; let responseMeta = Object.assign({ mediaType: VIDEO, advertiserDomains: [] }, response.meta); let bidResponse = { @@ -119,7 +119,7 @@ export const spec = { return bidResponse; } else { if (!response || !response.length) { - utils.logWarn(`No valid banner bids from ${spec.code} bidder`); + logWarn(`No valid banner bids from ${spec.code} bidder`); return []; } return response @@ -148,7 +148,7 @@ export const spec = { getUserSyncs(syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '') { let syncs = []; let { gdprApplies, consentString = '' } = gdprConsent; - let bannerResponse = find(serverResponses, (res) => utils.isArray(res.body)); + let bannerResponse = find(serverResponses, (res) => isArray(res.body)); if (bannerResponse) { if (syncOptions.iframeEnabled) { @@ -206,7 +206,7 @@ function getFirstSize(sizes) { } function parseSizes(sizes) { - return utils.parseSizesInput(sizes).map(size => { + return parseSizesInput(sizes).map(size => { let [ width, height ] = size.split('x'); return { w: parseInt(width, 10) || undefined, @@ -216,11 +216,11 @@ function parseSizes(sizes) { } function getVideoSizes(bid) { - return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); + return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); } function getBannerSizes(bid) { - return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); + return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); } function getOsVersion() { @@ -257,33 +257,33 @@ function getDoNotTrack() { } function isVideoBid(bid) { - return utils.deepAccess(bid, 'mediaTypes.video'); + return deepAccess(bid, 'mediaTypes.video'); } function isBannerBid(bid) { - return utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); + return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); } function getVideoBidParam(bid, key) { - return utils.deepAccess(bid, 'params.video.' + key) || utils.deepAccess(bid, 'params.' + key); + return deepAccess(bid, 'params.video.' + key) || deepAccess(bid, 'params.' + key); } function getBannerBidParam(bid, key) { - return utils.deepAccess(bid, 'params.banner.' + key) || utils.deepAccess(bid, 'params.' + key); + return deepAccess(bid, 'params.banner.' + key) || deepAccess(bid, 'params.' + key); } function getPlayerBidParam(bid, key, defaultValue) { - let param = utils.deepAccess(bid, 'params.player.' + key); + let param = deepAccess(bid, 'params.player.' + key); return param === undefined ? defaultValue : param; } function getBannerBidFloor(bid) { - let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; + let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); } function getVideoBidFloor(bid) { - let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; + let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); } @@ -297,7 +297,7 @@ function isBannerBidValid(bid) { function getTopWindowLocation(bidderRequest) { let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return utils.parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); + return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); } function getTopWindowReferrer() { @@ -316,7 +316,7 @@ function getEids(bid) { function getUserId(bid) { return ({ key, source, rtiPartner, atype }) => { - let id = utils.deepAccess(bid, `userId.${key}`); + let id = deepAccess(bid, `userId.${key}`); return id ? formatEid(id, source, rtiPartner, atype) : null; }; } @@ -364,7 +364,7 @@ function createVideoRequestData(bid, bidderRequest) { isPrebid: true, appId: appId, domain: document.location.hostname, - id: utils.getUniqueIdentifierStr(), + id: getUniqueIdentifierStr(), imp: [{ video: Object.assign({ w: firstSize.w, @@ -469,7 +469,7 @@ function createBannerRequestData(bids, bidderRequest) { } SUPPORTED_USER_IDS.forEach(({ key, queryParam }) => { - let id = utils.deepAccess(bids, `0.userId.${key}`) + let id = deepAccess(bids, `0.userId.${key}`) if (id) { payload[queryParam] = id; } From 7e3fa3feba9ec9b8e81524419c3c13e94ee1049e Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 13:11:58 -0700 Subject: [PATCH 08/14] import utils functions as needed and not the whole module --- modules/beopBidAdapter.js | 44 +++++++++++++++++----------------- modules/bidViewabilityIO.js | 14 +++++------ modules/bidglassBidAdapter.js | 16 ++++++------- modules/bidscubeBidAdapter.js | 6 ++--- modules/bizzclickBidAdapter.js | 20 ++++++++-------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index aed5d04a151..a6bc8a5687d 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'beop'; @@ -36,7 +36,7 @@ export const spec = { */ buildRequests: function(validBidRequests, bidderRequest) { const slots = validBidRequests.map(beOpRequestSlotsMaker); - let pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); + let pageUrl = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href'); let fpd = config.getLegacyFpd(config.getConfig('ortb2')); let gdpr = bidderRequest.gdprConsent; let firstSlot = slots[0]; @@ -50,7 +50,7 @@ export const spec = { kwds: (fpd && fpd.site && fpd.site.keywords) || [], dbg: false, slts: slots, - is_amp: utils.deepAccess(bidderRequest, 'referrerInfo.isAmp'), + is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'), tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null, }; const payloadString = JSON.stringify(payloadObject); @@ -61,7 +61,7 @@ export const spec = { } }, interpretResponse: function(serverResponse, request) { - if (serverResponse && serverResponse.body && utils.isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { + if (serverResponse && serverResponse.body && isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { return serverResponse.body.bids; } return []; @@ -73,8 +73,8 @@ export const spec = { let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout); - utils.logWarn(BIDDER_CODE + ': timed out request'); - utils.triggerPixel(utils.buildUrl({ + logWarn(BIDDER_CODE + ': timed out request'); + triggerPixel(buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -87,8 +87,8 @@ export const spec = { } let trackingParams = buildTrackingParams(bid, 'won', bid.cpm); - utils.logInfo(BIDDER_CODE + ': won request'); - utils.triggerPixel(utils.buildUrl({ + logInfo(BIDDER_CODE + ': won request'); + triggerPixel(buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -113,8 +113,8 @@ function buildTrackingParams(data, info, value) { } function beOpRequestSlotsMaker(bid) { - const bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); - const publisherCurrency = config.getConfig('currency.adServerCurrency') || utils.getValue(bid.params, 'currency') || 'EUR'; + const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes'); + const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR'; let floor; if (typeof bid.getFloor === 'function') { const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]}); @@ -123,19 +123,19 @@ function beOpRequestSlotsMaker(bid) { } } return { - sizes: utils.isArray(bannerSizes) ? bannerSizes : bid.sizes, + sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes, flr: floor, - pid: utils.getValue(bid.params, 'accountId'), - nid: utils.getValue(bid.params, 'networkId'), - nptnid: utils.getValue(bid.params, 'networkPartnerId'), - bid: utils.getBidIdParameter('bidId', bid), - brid: utils.getBidIdParameter('bidderRequestId', bid), - name: utils.getBidIdParameter('adUnitCode', bid), - aid: utils.getBidIdParameter('auctionId', bid), - tid: utils.getBidIdParameter('transactionId', bid), - brc: utils.getBidIdParameter('bidRequestsCount', bid), - bdrc: utils.getBidIdParameter('bidderRequestCount', bid), - bwc: utils.getBidIdParameter('bidderWinsCount', bid), + pid: getValue(bid.params, 'accountId'), + nid: getValue(bid.params, 'networkId'), + nptnid: getValue(bid.params, 'networkPartnerId'), + bid: getBidIdParameter('bidId', bid), + brid: getBidIdParameter('bidderRequestId', bid), + name: getBidIdParameter('adUnitCode', bid), + aid: getBidIdParameter('auctionId', bid), + tid: getBidIdParameter('transactionId', bid), + brc: getBidIdParameter('bidRequestsCount', bid), + bdrc: getBidIdParameter('bidderRequestCount', bid), + bwc: getBidIdParameter('bidderWinsCount', bid), } } diff --git a/modules/bidViewabilityIO.js b/modules/bidViewabilityIO.js index 4651e424d00..d936fb4aeec 100644 --- a/modules/bidViewabilityIO.js +++ b/modules/bidViewabilityIO.js @@ -1,7 +1,7 @@ +import { logMessage } from '../src/utils.js'; import { config } from '../src/config.js'; import * as events from '../src/events.js'; import { EVENTS } from '../src/constants.json'; -import * as utils from '../src/utils.js'; const MODULE_NAME = 'bidViewabilityIO'; const CONFIG_ENABLED = 'enabled'; @@ -23,8 +23,8 @@ export let isSupportedMediaType = (bid) => { return supportedMediaTypes.indexOf(bid.mediaType) > -1; } -let logMessage = (message) => { - return utils.logMessage(`${MODULE_NAME}: ${message}`); +let _logMessage = (message) => { + return logMessage(`${MODULE_NAME}: ${message}`); } // returns options for the iO that detects if the ad is viewable @@ -43,7 +43,7 @@ export let markViewed = (bid, entry, observer) => { return () => { observer.unobserve(entry.target); events.emit(EVENTS.BID_VIEWABLE, bid); - logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); + _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); } } @@ -59,13 +59,13 @@ export let viewCallbackFactory = (bid) => { return (entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { - logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + _logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); entry.target.view_tracker = setTimeout(markViewed(bid, entry, observer), IAB_VIEWABLE_DISPLAY_TIME); } else { - logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); + _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); if (entry.target.view_tracker) { clearTimeout(entry.target.view_tracker); - logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + _logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); } } }); diff --git a/modules/bidglassBidAdapter.js b/modules/bidglassBidAdapter.js index b77ca474e13..3184372881b 100644 --- a/modules/bidglassBidAdapter.js +++ b/modules/bidglassBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { _each, isArray, getBidIdParameter, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; // import {config} from 'src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; @@ -69,12 +69,12 @@ export const spec = { let bidglass = window['bidglass']; - utils._each(validBidRequests, function(bid) { - bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); - bid.sizes = bid.sizes.filter(size => utils.isArray(size)); + _each(validBidRequests, function(bid) { + bid.sizes = ((isArray(bid.sizes) && isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); + bid.sizes = bid.sizes.filter(size => isArray(size)); - var adUnitId = utils.getBidIdParameter('adUnitId', bid.params); - var options = utils.deepClone(bid.params); + var adUnitId = getBidIdParameter('adUnitId', bid.params); + var options = deepClone(bid.params); delete options.adUnitId; @@ -96,7 +96,7 @@ export const spec = { // Stuff to send: page URL const bidReq = { - reqId: utils.getUniqueIdentifierStr(), + reqId: getUniqueIdentifierStr(), imps: imps, ref: getReferer(), ori: getOrigins() @@ -125,7 +125,7 @@ export const spec = { interpretResponse: function(serverResponse) { const bidResponses = []; - utils._each(serverResponse.body.bidResponses, function(serverBid) { + _each(serverResponse.body.bidResponses, function(serverBid) { const bidResponse = { requestId: serverBid.requestId, cpm: parseFloat(serverBid.cpm), diff --git a/modules/bidscubeBidAdapter.js b/modules/bidscubeBidAdapter.js index d3f27a5ac6d..951bd97d255 100644 --- a/modules/bidscubeBidAdapter.js +++ b/modules/bidscubeBidAdapter.js @@ -1,6 +1,6 @@ +import { logMessage, getWindowLocation } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js' -import * as utils from '../src/utils.js' const BIDDER_CODE = 'bidscube' const URL = 'https://supply.bidscube.com/?c=o&m=multi' @@ -20,9 +20,9 @@ export const spec = { try { window.top.location.toString() winTop = window.top - } catch (e) { utils.logMessage(e) } + } catch (e) { logMessage(e) } - const location = utils.getWindowLocation() + const location = getWindowLocation() const placements = [] for (let i = 0; i < validBidRequests.length; i++) { diff --git a/modules/bizzclickBidAdapter.js b/modules/bizzclickBidAdapter.js index 95c53b78de2..38195f8f9d9 100644 --- a/modules/bizzclickBidAdapter.js +++ b/modules/bizzclickBidAdapter.js @@ -1,6 +1,6 @@ +import { logMessage, getDNT, deepSetValue, deepAccess, _map, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'bizzclick'; const ACCOUNTID_MACROS = '[account_id]'; @@ -67,7 +67,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - utils.logMessage(e); + logMessage(e); }; let bids = []; for (let bidRequest of validBidRequests) { @@ -80,7 +80,7 @@ export const spec = { device: { w: winTop.screen.width, h: winTop.screen.height, - dnt: utils.getDNT() ? 1 : 0, + dnt: getDNT() ? 1 : 0, language: (navigator && navigator.language) ? navigator.language.indexOf('-') != -1 ? navigator.language.split('-')[0] : navigator.language : '', }, site: { @@ -124,12 +124,12 @@ export const spec = { } if (bidRequest) { if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) { - utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); - utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); + deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); + deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); } if (bidRequest.uspConsent !== undefined) { - utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); + deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); } } bids.push(data) @@ -194,7 +194,7 @@ export const spec = { * @returns {boolean} */ const checkRequestType = (bidRequest, type) => { - return (typeof utils.deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); + return (typeof deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); } const parseNative = admObject => { const { assets, link, imptrackers, jstracker } = admObject.native; @@ -240,7 +240,7 @@ const addNativeParameters = bidRequest => { id: bidRequest.transactionId, ver: NATIVE_VERSION, }; - const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => { + const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -286,7 +286,7 @@ const parseSizes = (bid, mediaType) => { mediaTypes.video.w, mediaTypes.video.h ]; - } else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { + } else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { size = bid.mediaTypes.video.playerSize[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) { size = bid.sizes[0]; @@ -299,7 +299,7 @@ const parseSizes = (bid, mediaType) => { } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { sizes = bid.sizes } else { - utils.logWarn('no sizes are setup or found'); + logWarn('no sizes are setup or found'); } return sizes } From 0a32ede82f3f19f22e8696fd03dd735eae758dbf Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 13:19:31 -0700 Subject: [PATCH 09/14] Revert "import utils functions as needed and not the whole module" This reverts commit bc6c9f61f889e9aa2ef8ab207b87d4e7b49e3e57. --- modules/apacdexBidAdapter.js | 32 ++++----- modules/appnexusBidAdapter.js | 118 +++++++++++++++++----------------- modules/apstreamBidAdapter.js | 10 +-- modules/asoBidAdapter.js | 60 ++++++++--------- modules/astraoneBidAdapter.js | 4 +- 5 files changed, 112 insertions(+), 112 deletions(-) diff --git a/modules/apacdexBidAdapter.js b/modules/apacdexBidAdapter.js index 421eb99b4c1..6c1c350b800 100644 --- a/modules/apacdexBidAdapter.js +++ b/modules/apacdexBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'apacdex'; @@ -32,16 +32,16 @@ export const spec = { if (!bid.params.siteId && !bid.params.placementId) { return false; } - if (!deepAccess(bid, 'mediaTypes.banner') && !deepAccess(bid, 'mediaTypes.video')) { + if (!utils.deepAccess(bid, 'mediaTypes.banner') && !utils.deepAccess(bid, 'mediaTypes.video')) { return false; } - if (deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video - if (!deepAccess(bid, 'mediaTypes.banner.sizes')) { + if (utils.deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video + if (!utils.deepAccess(bid, 'mediaTypes.banner.sizes')) { // sizes at the banner is required. return false; } - } else if (deepAccess(bid, 'mediaTypes.video')) { - if (!deepAccess(bid, 'mediaTypes.video.playerSize')) { + } else if (utils.deepAccess(bid, 'mediaTypes.video')) { + if (!utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { // playerSize is required for instream adUnits. return false; } @@ -170,12 +170,12 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { const serverBody = serverResponse.body; - if (!serverBody || !isPlainObject(serverBody)) { + if (!serverBody || !utils.isPlainObject(serverBody)) { return []; } const serverBids = serverBody.bids; - if (!serverBids || !isArray(serverBids)) { + if (!serverBids || !utils.isArray(serverBids)) { return []; } @@ -197,12 +197,12 @@ export const spec = { bidResponse.dealId = dealId; } if (bid.vastXml) { - bidResponse.vastXml = replaceAuctionPrice(bid.vastXml, bid.cpm); + bidResponse.vastXml = utils.replaceAuctionPrice(bid.vastXml, bid.cpm); } else { - bidResponse.ad = replaceAuctionPrice(bid.ad, bid.cpm); + bidResponse.ad = utils.replaceAuctionPrice(bid.ad, bid.cpm); } bidResponse.meta = {}; - if (bid.meta && bid.meta.advertiserDomains && isArray(bid.meta.advertiserDomains)) { + if (bid.meta && bid.meta.advertiserDomains && utils.isArray(bid.meta.advertiserDomains)) { bidResponse.meta.advertiserDomains = bid.meta.advertiserDomains; } bidResponses.push(bidResponse); @@ -285,7 +285,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { if (config.getConfig('pageUrl')) { return config.getConfig('pageUrl'); } - if (deepAccess(bidderRequest, 'refererInfo.referer')) { + if (utils.deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -303,7 +303,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { * @returns {string} */ function _extractTopWindowReferrerFromBidderRequest(bidderRequest) { - if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) { + if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -340,7 +340,7 @@ export function getDomain(pageUrl) { * @returns {boolean} */ export function validateGeoObject(geo) { - if (!isPlainObject(geo)) { + if (!utils.isPlainObject(geo)) { return false; } if (!geo.lat) { @@ -362,7 +362,7 @@ export function validateGeoObject(geo) { * @returns {float||null} */ function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return (bid.params.floorPrice) ? bid.params.floorPrice : null; } @@ -371,7 +371,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 7dcbd74d779..9882e71fe4f 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,5 +1,5 @@ -import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, logError, logInfo, deepAccess, logMessage, convertTypes, isStr, getParameterByName, deepClone, chunk, logWarn, getBidRequest, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, getMaxValueFromArray, fill, getMinValueFromArray, isArrayOfNums, isFn } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder, getIabSubCategory } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO, ADPOD } from '../src/mediaTypes.js'; @@ -109,13 +109,13 @@ export const spec = { Object.keys(userObjBid.params.user) .filter(param => includes(USER_PARAMS, param)) .forEach((param) => { - let uparam = convertCamelToUnderscore(param); - if (param === 'segments' && isArray(userObjBid.params.user[param])) { + let uparam = utils.convertCamelToUnderscore(param); + if (param === 'segments' && utils.isArray(userObjBid.params.user[param])) { let segs = []; userObjBid.params.user[param].forEach(val => { - if (isNumber(val)) { + if (utils.isNumber(val)) { segs.push({'id': val}); - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { segs.push(val); } }); @@ -152,7 +152,7 @@ export const spec = { try { debugObj = JSON.parse(debugCookie); } catch (e) { - logError('AppNexus Debug Auction Cookie Error:\n\n' + e); + utils.logError('AppNexus Debug Auction Cookie Error:\n\n' + e); } } else { const debugBidRequest = find(bidRequests, hasDebug); @@ -208,7 +208,7 @@ export const spec = { if (debugObjParams.enabled) { payload.debug = debugObjParams; - logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); + utils.logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); } if (bidderRequest && bidderRequest.gdprConsent) { @@ -253,12 +253,12 @@ export const spec = { if (bidRequests[0].userId) { let eids = []; - addUserId(eids, deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); - addUserId(eids, deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); if (eids.length) { payload.eids = eids; @@ -285,7 +285,7 @@ export const spec = { if (!serverResponse || serverResponse.error) { let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`; if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - logError(errorMessage); + utils.logError(errorMessage); return bids; } @@ -313,8 +313,8 @@ export const spec = { .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags - logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); - logMessage(debugText); + utils.logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); + utils.logMessage(debugText); } return bids; @@ -348,11 +348,11 @@ export const spec = { }, transformBidParams: function (params, isOpenRtb) { - params = convertTypes({ + params = utils.convertTypes({ 'member': 'string', 'invCode': 'string', 'placementId': 'number', - 'keywords': transformBidderParamKeywords, + 'keywords': utils.transformBidderParamKeywords, 'publisherId': 'number' }, params); @@ -365,7 +365,7 @@ export const spec = { } Object.keys(params).forEach(paramKey => { - let convertedKey = convertCamelToUnderscore(paramKey); + let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { params[convertedKey] = params[paramKey]; delete params[paramKey]; @@ -388,7 +388,7 @@ export const spec = { } function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); + return !!(utils.isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -460,9 +460,9 @@ function strIsAppnexusViewabilityScript(str) { function getAppnexusViewabilityScriptFromJsTrackers(jsTrackerArray) { let viewJsPayload; - if (isStr(jsTrackerArray) && strIsAppnexusViewabilityScript(jsTrackerArray)) { + if (utils.isStr(jsTrackerArray) && strIsAppnexusViewabilityScript(jsTrackerArray)) { viewJsPayload = jsTrackerArray; - } else if (isArray(jsTrackerArray)) { + } else if (utils.isArray(jsTrackerArray)) { for (let i = 0; i < jsTrackerArray.length; i++) { let currentJsTracker = jsTrackerArray[i]; if (strIsAppnexusViewabilityScript(currentJsTracker)) { @@ -486,7 +486,7 @@ function hasPurpose1Consent(bidderRequest) { let result = true; if (bidderRequest && bidderRequest.gdprConsent) { if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -504,16 +504,16 @@ function formatRequest(payload, bidderRequest) { endpointUrl = URL_SIMPLE; } - if (getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true) { + if (utils.getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true) { options.customHeaders = { 'X-Is-Test': 1 } } if (payload.tags.length > MAX_IMPS_PER_REQUEST) { - const clonedPayload = deepClone(payload); + const clonedPayload = utils.deepClone(payload); - chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { + utils.chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { clonedPayload.tags = tags; const payloadString = JSON.stringify(clonedPayload); request.push({ @@ -550,14 +550,14 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } renderer.setEventHandlers({ - impression: () => logMessage('AppNexus outstream video impression event'), - loaded: () => logMessage('AppNexus outstream video loaded event'), + impression: () => utils.logMessage('AppNexus outstream video impression event'), + loaded: () => utils.logMessage('AppNexus outstream video loaded event'), ended: () => { - logMessage('AppNexus outstream renderer video event'); + utils.logMessage('AppNexus outstream renderer video event'); document.querySelector(`#${adUnitCode}`).style.display = 'none'; } }); @@ -572,7 +572,7 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { * @return Bid */ function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); + const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { requestId: serverBid.uuid, cpm: rtbBid.cpm, @@ -607,7 +607,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { ttl: 3600 }); - const videoContext = deepAccess(bidRequest, 'mediaTypes.video.context'); + const videoContext = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); switch (videoContext) { case ADPOD: const primaryCatId = getIabSubCategory(bidRequest.bidder, rtbBid.brand_category_id); @@ -628,7 +628,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (rtbBid.renderer_url) { const videoBid = find(bidderRequest.bids, bid => bid.bidId === serverBid.uuid); - const rendererOptions = deepAccess(videoBid, 'renderer.options'); + const rendererOptions = utils.deepAccess(videoBid, 'renderer.options'); bid.renderer = newRenderer(bid.adUnitCode, rtbBid, rendererOptions); } break; @@ -648,7 +648,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (jsTrackers == undefined) { jsTrackers = jsTrackerDisarmed; - } else if (isStr(jsTrackers)) { + } else if (utils.isStr(jsTrackers)) { jsTrackers = [jsTrackers, jsTrackerDisarmed]; } else { jsTrackers.push(jsTrackerDisarmed); @@ -697,11 +697,11 @@ function newBid(serverBid, rtbBid, bidderRequest) { try { if (rtbBid.rtb.trackers) { const url = rtbBid.rtb.trackers[0].impression_urls[0]; - const tracker = createTrackPixelHtml(url); + const tracker = utils.createTrackPixelHtml(url); bid.ad += tracker; } } catch (error) { - logError('Error appending tracking pixel', error); + utils.logError('Error appending tracking pixel', error); } } @@ -751,8 +751,8 @@ function bidToTag(bid) { if (bid.params.externalImpId) { tag.external_imp_id = bid.params.externalImpId; } - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); + if (!utils.isEmpty(bid.params.keywords)) { + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); @@ -760,12 +760,12 @@ function bidToTag(bid) { tag.keywords = keywords; } - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); if (gpid) { tag.gpid = gpid; } - if (bid.mediaType === NATIVE || deepAccess(bid, `mediaTypes.${NATIVE}`)) { + if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) { tag.ad_types.push(NATIVE); if (tag.sizes.length === 0) { tag.sizes = transformSizes([1, 1]); @@ -777,8 +777,8 @@ function bidToTag(bid) { } } - const videoMediaType = deepAccess(bid, `mediaTypes.${VIDEO}`); - const context = deepAccess(bid, 'mediaTypes.video.context'); + const videoMediaType = utils.deepAccess(bid, `mediaTypes.${VIDEO}`); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); if (videoMediaType && context === 'adpod') { tag.hb_source = 7; @@ -804,7 +804,7 @@ function bidToTag(bid) { case 'context': case 'playback_method': let type = bid.params.video[param]; - type = (isArray(type)) ? type[0] : type; + type = (utils.isArray(type)) ? type[0] : type; tag.video[param] = VIDEO_MAPPING[param][type]; break; // Deprecating tags[].video.frameworks in favor of tags[].video_frameworks @@ -815,7 +815,7 @@ function bidToTag(bid) { } }); - if (bid.params.video.frameworks && isArray(bid.params.video.frameworks)) { + if (bid.params.video.frameworks && utils.isArray(bid.params.video.frameworks)) { tag['video_frameworks'] = bid.params.video.frameworks; } } @@ -840,7 +840,7 @@ function bidToTag(bid) { case 'playbackmethod': if (typeof tag.video['playback_method'] !== 'number') { let type = videoMediaType[param]; - type = (isArray(type)) ? type[0] : type; + type = (utils.isArray(type)) ? type[0] : type; // we only support iab's options 1-4 at this time. if (type >= 1 && type <= 4) { @@ -849,7 +849,7 @@ function bidToTag(bid) { } break; case 'api': - if (!tag['video_frameworks'] && isArray(videoMediaType[param])) { + if (!tag['video_frameworks'] && utils.isArray(videoMediaType[param])) { // need to read thru array; remove 6 (we don't support it), swap 4 <> 5 if found (to match our adserver mapping for these specific values) let apiTmp = videoMediaType[param].map(val => { let v = (val === 4) ? 5 : (val === 5) ? 4 : val; @@ -869,7 +869,7 @@ function bidToTag(bid) { tag.video = Object.assign({}, tag.video, { custom_renderer_present: true }); } - if (bid.params.frameworks && isArray(bid.params.frameworks)) { + if (bid.params.frameworks && utils.isArray(bid.params.frameworks)) { tag['banner_frameworks'] = bid.params.frameworks; } @@ -890,8 +890,8 @@ function transformSizes(requestSizes) { let sizes = []; let sizeObj = {}; - if (isArray(requestSizes) && requestSizes.length === 2 && - !isArray(requestSizes[0])) { + if (utils.isArray(requestSizes) && requestSizes.length === 2 && + !utils.isArray(requestSizes[0])) { sizeObj.width = parseInt(requestSizes[0], 10); sizeObj.height = parseInt(requestSizes[1], 10); sizes.push(sizeObj); @@ -945,10 +945,10 @@ function hasOmidSupport(bid) { let hasOmid = false; const bidderParams = bid.params; const videoParams = bid.params.video; - if (bidderParams.frameworks && isArray(bidderParams.frameworks)) { + if (bidderParams.frameworks && utils.isArray(bidderParams.frameworks)) { hasOmid = includes(bid.params.frameworks, 6); } - if (!hasOmid && videoParams && videoParams.frameworks && isArray(videoParams.frameworks)) { + if (!hasOmid && videoParams && videoParams.frameworks && utils.isArray(videoParams.frameworks)) { hasOmid = includes(bid.params.video.frameworks, 6); } return hasOmid; @@ -963,14 +963,14 @@ function createAdPodRequest(tags, adPodBid) { const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = utils.getMaxValueFromArray(durationRangeSec); const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); - let request = fill(...tagToDuplicate, numberOfPlacements); + let request = utils.fill(...tagToDuplicate, numberOfPlacements); if (requireExactDuration) { const divider = Math.ceil(numberOfPlacements / durationRangeSec.length); - const chunked = chunk(request, divider); + const chunked = utils.chunk(request, divider); // each configured duration is set as min/maxduration for a subset of requests durationRangeSec.forEach((duration, index) => { @@ -989,7 +989,7 @@ function createAdPodRequest(tags, adPodBid) { function getAdPodPlacementNumber(videoParams) { const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = getMinValueFromArray(durationRangeSec); + const minAllowedDuration = utils.getMinValueFromArray(durationRangeSec); const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); return requireExactDuration @@ -998,7 +998,7 @@ function getAdPodPlacementNumber(videoParams) { } function setVideoProperty(tag, key, value) { - if (isEmpty(tag.video)) { tag.video = {}; } + if (utils.isEmpty(tag.video)) { tag.video = {}; } tag.video[key] = value; } @@ -1029,7 +1029,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 (isArrayOfNums(sizes) || (isArray(sizes) && sizes.length > 0 && sizes.every(sz => isArrayOfNums(sz)))) { + if (utils.isArrayOfNums(sizes) || (utils.isArray(sizes) && sizes.length > 0 && sizes.every(sz => utils.isArrayOfNums(sz)))) { request[requestKey].sizes = transformSizes(request[requestKey].sizes); } } @@ -1108,7 +1108,7 @@ function addUserId(eids, id, source, rti) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return (bid.params.reserve) ? bid.params.reserve : null; } @@ -1117,7 +1117,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/apstreamBidAdapter.js b/modules/apstreamBidAdapter.js index f2d4189f237..4fb89b9c720 100644 --- a/modules/apstreamBidAdapter.js +++ b/modules/apstreamBidAdapter.js @@ -1,6 +1,6 @@ -import { generateUUID, deepAccess, createTrackPixelHtml, getDNT } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; const CONSTANTS = { @@ -221,7 +221,7 @@ var dsuModule = (function() { } function generateDsu() { - var dsuId = generateUUID(); + var dsuId = utils.generateUUID(); var loc = location(); var dsuIdSuffix = hashWithKey(dsuId + loc.toString()); @@ -303,7 +303,7 @@ function getConsentStringFromPrebid(gdprConsentConfig) { } function getIabConsentString(bidderRequest) { - if (deepAccess(bidderRequest, 'gdprConsent')) { + if (utils.deepAccess(bidderRequest, 'gdprConsent')) { return getConsentStringFromPrebid(bidderRequest.gdprConsent); } @@ -318,7 +318,7 @@ function injectPixels(ad, pixels, scripts) { let trackedAd = ad; if (pixels) { pixels.forEach(pixel => { - const tracker = createTrackPixelHtml(pixel); + const tracker = utils.createTrackPixelHtml(pixel); trackedAd += tracker; }); } @@ -420,7 +420,7 @@ function buildRequests(bidRequests, bidderRequest) { med: encodeURIComponent(window.location.href), auid: bidderRequest.auctionId, ref: document.referrer, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, sr: getScreenParams() }; diff --git a/modules/asoBidAdapter.js b/modules/asoBidAdapter.js index bf45b9ee48f..8f06b8ed856 100644 --- a/modules/asoBidAdapter.js +++ b/modules/asoBidAdapter.js @@ -1,5 +1,5 @@ -import { _each, deepAccess, logWarn, tryAppendQueryString, inIframe, getWindowTop, parseUrl, parseSizesInput, isFn, getDNT, deepSetValue } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; @@ -22,16 +22,16 @@ export const spec = { buildRequests: (validBidRequests, bidderRequest) => { let serverRequests = []; - _each(validBidRequests, bidRequest => { + utils._each(validBidRequests, bidRequest => { const payload = createBasePayload(bidRequest, bidderRequest); - const bannerParams = deepAccess(bidRequest, 'mediaTypes.banner'); - const videoParams = deepAccess(bidRequest, 'mediaTypes.video'); + const bannerParams = utils.deepAccess(bidRequest, 'mediaTypes.banner'); + const videoParams = utils.deepAccess(bidRequest, 'mediaTypes.video'); let imp; if (bannerParams && videoParams) { - logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') + utils.logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') } if (bannerParams) { @@ -93,7 +93,7 @@ export const spec = { bid.ad = serverBid.adm; } else if (bid.mediaType === VIDEO) { bid.vastXml = serverBid.adm; - if (deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { + if (utils.deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { bid.adResponse = { content: bid.vastXml, }; @@ -112,25 +112,25 @@ export const spec = { if (serverResponses && serverResponses.length !== 0) { let query = ''; if (gdprConsent) { - query = tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); - query = tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); + query = utils.tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + query = utils.tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); const consentsIds = getConsentsIds(gdprConsent); if (consentsIds) { - query = tryAppendQueryString(query, 'consents', consentsIds); + query = utils.tryAppendQueryString(query, 'consents', consentsIds); } } if (uspConsent) { - query = tryAppendQueryString(query, 'us_privacy', uspConsent); + query = utils.tryAppendQueryString(query, 'us_privacy', uspConsent); } - _each(serverResponses, resp => { - const userSyncs = deepAccess(resp, 'body.ext.user_syncs'); + utils._each(serverResponses, resp => { + const userSyncs = utils.deepAccess(resp, 'body.ext.user_syncs'); if (!userSyncs) { return; } - _each(userSyncs, us => { + utils._each(userSyncs, us => { urls.push({ type: us.type, url: us.url + (query ? '?' + query : '') @@ -159,7 +159,7 @@ function createRenderer(bid, url) { id: bid.bidId, url: url, loaded: false, - config: deepAccess(bid, 'renderer.options'), + config: utils.deepAccess(bid, 'renderer.options'), adUnitCode: bid.adUnitCode }); renderer.setRender(outstreamRender); @@ -172,16 +172,16 @@ function getUrlsInfo(bidderRequest) { const {refererInfo} = bidderRequest; - if (inIframe()) { + if (utils.inIframe()) { page = refererInfo.referer; } else { - const w = getWindowTop(); + const w = utils.getWindowTop(); page = w.location.href; referrer = w.document.referrer || ''; } page = config.getConfig('pageUrl') || page; - const url = parseUrl(page); + const url = utils.parseUrl(page); const domain = url.hostname; return { @@ -192,7 +192,7 @@ function getUrlsInfo(bidderRequest) { } function getSize(paramSizes) { - const parsedSizes = parseSizesInput(paramSizes); + const parsedSizes = utils.parseSizesInput(paramSizes); const sizes = parsedSizes.map(size => { const [width, height] = size.split('x'); const w = parseInt(width, 10); @@ -204,7 +204,7 @@ function getSize(paramSizes) { } function getBidFloor(bidRequest, size) { - if (!isFn(bidRequest.getFloor)) { + if (!utils.isFn(bidRequest.getFloor)) { return null; } @@ -245,7 +245,7 @@ function createBannerImp(bidRequest, bannerParams) { imp.banner = { w: size.w, h: size.h, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 } return imp; @@ -284,7 +284,7 @@ function getEnpoint(bidRequest) { } function getConsentsIds(gdprConsent) { - const consents = deepAccess(gdprConsent, 'vendorData.purpose.consents', []); + const consents = utils.deepAccess(gdprConsent, 'vendorData.purpose.consents', []); let consentsIds = []; Object.keys(consents).forEach(function (key) { @@ -310,7 +310,7 @@ function createBasePayload(bidRequest, bidderRequest) { ref: urlsInfo.referrer }, device: { - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, h: window.innerHeight, w: window.innerWidth, }, @@ -320,29 +320,29 @@ function createBasePayload(bidRequest, bidderRequest) { }; if (bidRequest.params.attr) { - deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); + utils.deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); } if (bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); const consentsIds = getConsentsIds(bidderRequest.gdprConsent); if (consentsIds) { - deepSetValue(payload, 'user.ext.consents', consentsIds); + utils.deepSetValue(payload, 'user.ext.consents', consentsIds); } - deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); + utils.deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); } if (bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa')) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } - const eids = deepAccess(bidRequest, 'userIdAsEids'); + const eids = utils.deepAccess(bidRequest, 'userIdAsEids'); if (eids && eids.length) { - deepSetValue(payload, 'user.ext.eids', eids); + utils.deepSetValue(payload, 'user.ext.eids', eids); } return payload; diff --git a/modules/astraoneBidAdapter.js b/modules/astraoneBidAdapter.js index c233e665499..2fec3892d27 100644 --- a/modules/astraoneBidAdapter.js +++ b/modules/astraoneBidAdapter.js @@ -1,4 +1,4 @@ -import { _map } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER } from '../src/mediaTypes.js' @@ -7,7 +7,7 @@ const SSP_ENDPOINT = 'https://ssp.astraone.io/auction/prebid'; const TTL = 60; function buildBidRequests(validBidRequests) { - return _map(validBidRequests, function(validBidRequest) { + return utils._map(validBidRequests, function(validBidRequest) { const params = validBidRequest.params; const bidRequest = { bidId: validBidRequest.bidId, From e4dc4955c78551d746a257cc59189d6f7df69538 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 13:19:35 -0700 Subject: [PATCH 10/14] Revert "import utils functions as needed and not the whole module" This reverts commit ef500abb06648c763caa066ccd18fd5a18f2a1b5. --- modules/atsAnalyticsAdapter.js | 22 +++++++-------- modules/audiencerunBidAdapter.js | 30 ++++++++++----------- modules/automatadBidAdapter.js | 4 +-- modules/axonixBidAdapter.js | 14 +++++----- modules/beachfrontBidAdapter.js | 46 ++++++++++++++++---------------- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index df293556a4c..0cff7bbd68f 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { logError, logInfo } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adaptermanager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -256,7 +256,7 @@ export function parseBrowser() { let browserName = result && result.length ? result[0].name : ''; return (listOfSupportedBrowsers.indexOf(browserName) >= 0) ? browserName : 'Unknown'; } catch (err) { - logError('ATS Analytics - Error while checking user browser!', err); + utils.logError('ATS Analytics - Error while checking user browser!', err); } } @@ -265,20 +265,20 @@ function sendDataToAnalytic () { try { let dataToSend = {'Data': atsAnalyticsAdapter.context.events}; let strJSON = JSON.stringify(dataToSend); - logInfo('ATS Analytics - tried to send analytics data!'); + utils.logInfo('ATS Analytics - tried to send analytics data!'); ajax(analyticsUrl, function () { }, strJSON, {method: 'POST', contentType: 'application/json'}); } catch (err) { - logError('ATS Analytics - request encounter an error: ', err); + utils.logError('ATS Analytics - request encounter an error: ', err); } } // preflight request, to check did publisher have permission to send data to analytics endpoint function preflightRequest (envelopeSourceCookieValue) { - logInfo('ATS Analytics - preflight request!'); + utils.logInfo('ATS Analytics - preflight request!'); ajax(preflightUrl + atsAnalyticsAdapter.context.pid, function (data) { let samplingRateObject = JSON.parse(data); - logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); + utils.logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); let samplingRate = samplingRateObject['samplingRate']; setSamplingCookie(samplingRate); let samplingRateNumber = Number(samplingRate); @@ -332,7 +332,7 @@ let atsAnalyticsAdapter = Object.assign(adapter( } } } catch (err) { - logError('ATS Analytics - preflight request encounter an error: ', err); + utils.logError('ATS Analytics - preflight request encounter an error: ', err); } } } @@ -345,10 +345,10 @@ atsAnalyticsAdapter.originEnableAnalytics = atsAnalyticsAdapter.enableAnalytics; atsAnalyticsAdapter.shouldFireRequest = function (samplingRate) { if (samplingRate !== 0) { let shouldFireRequestValue = (Math.floor((Math.random() * 100 + 1)) === 100); - logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); + utils.logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); return shouldFireRequestValue; } else { - logInfo('ATS Analytics - Should Fire Request: ', false); + utils.logInfo('ATS Analytics - Should Fire Request: ', false); return false; } }; @@ -359,7 +359,7 @@ atsAnalyticsAdapter.getUserAgent = function () { // override enableAnalytics so we can get access to the config passed in from the page atsAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.pid) { - logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); + utils.logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); return; } atsAnalyticsAdapter.context = { @@ -367,7 +367,7 @@ atsAnalyticsAdapter.enableAnalytics = function (config) { pid: config.options.pid }; let initOptions = config.options; - logInfo('ATS Analytics - adapter enabled! '); + utils.logInfo('ATS Analytics - adapter enabled! '); atsAnalyticsAdapter.originEnableAnalytics(initOptions); // call the base class function }; diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index 2c100bce27b..da0cbb39925 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isFn, logError, getValue, getBidIdParameter, _each, isArray, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -20,7 +20,7 @@ let requestedBids = []; function getPageUrl(bidderRequest) { return ( config.getConfig('pageUrl') || - deepAccess(bidderRequest, 'refererInfo.referer') || + utils.deepAccess(bidderRequest, 'refererInfo.referer') || null ); } @@ -32,8 +32,8 @@ function getPageUrl(bidderRequest) { * @returns {number} */ function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); } try { @@ -61,8 +61,8 @@ export const spec = { */ isBidRequestValid: function (bid) { let isValid = true; - if (!deepAccess(bid, 'params.zoneId')) { - logError('AudienceRun zoneId parameter is required. Bid aborted.'); + if (!utils.deepAccess(bid, 'params.zoneId')) { + utils.logError('AudienceRun zoneId parameter is required. Bid aborted.'); isValid = false; } return isValid; @@ -77,19 +77,19 @@ export const spec = { */ buildRequests: function (bidRequests, bidderRequest) { const bids = bidRequests.map((bid) => { - const sizes = deepAccess(bid, 'mediaTypes.banner.sizes', []); + const sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes', []); return { - zoneId: getValue(bid.params, 'zoneId'), + zoneId: utils.getValue(bid.params, 'zoneId'), sizes: sizes.map((size) => ({ w: size[0], h: size[1], })), bidfloor: getBidFloor(bid), bidId: bid.bidId, - bidderRequestId: getBidIdParameter('bidderRequestId', bid), - adUnitCode: getBidIdParameter('adUnitCode', bid), - auctionId: getBidIdParameter('auctionId', bid), - transactionId: getBidIdParameter('transactionId', bid), + bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), + adUnitCode: utils.getBidIdParameter('adUnitCode', bid), + auctionId: utils.getBidIdParameter('auctionId', bid), + transactionId: utils.getBidIdParameter('transactionId', bid), }; }); @@ -133,7 +133,7 @@ export const spec = { */ interpretResponse: function (serverResponse, bidRequest) { const bids = []; - _each(serverResponse.body.bid, function (bidObject) { + utils._each(serverResponse.body.bid, function (bidObject) { if (!bidObject.cpm || bidObject.cpm === null || !bidObject.adm) { return; } @@ -196,7 +196,7 @@ export const spec = { * @param {Array} timeoutData timeout specific data */ onTimeout: function (timeoutData) { - if (!isArray(timeoutData)) { + if (!utils.isArray(timeoutData)) { return; } @@ -204,7 +204,7 @@ export const spec = { const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId); if (bidOnTimeout) { - triggerPixel( + utils.triggerPixel( `${TIMEOUT_EVENT_URL}/${bidOnTimeout.zoneId}/${bidOnTimeout.bidId}` ); } diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 2cfcfbe98b4..415c52ba6d3 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -1,5 +1,5 @@ -import { logInfo } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js' +import * as utils from '../src/utils.js' import {BANNER} from '../src/mediaTypes.js' import {ajax} from '../src/ajax.js' @@ -92,7 +92,7 @@ export const spec = { }) }) } else { - logInfo('automatad :: no valid responses to interpret') + utils.logInfo('automatad :: no valid responses to interpret') } return bidResponses diff --git a/modules/axonixBidAdapter.js b/modules/axonixBidAdapter.js index 7cd8f63bd2a..daaac27e6a4 100644 --- a/modules/axonixBidAdapter.js +++ b/modules/axonixBidAdapter.js @@ -1,7 +1,7 @@ -import { isArray, logError, deepAccess, isEmpty, triggerPixel, replaceAuctionPrice } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; const BIDDER_CODE = 'axonix'; @@ -68,9 +68,9 @@ export const spec = { // video bid request validation if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { if (!bid.mediaTypes[VIDEO].hasOwnProperty('mimes') || - !isArray(bid.mediaTypes[VIDEO].mimes) || + !utils.isArray(bid.mediaTypes[VIDEO].mimes) || bid.mediaTypes[VIDEO].mimes.length === 0) { - logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); + utils.logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); return false; } @@ -142,7 +142,7 @@ export const spec = { interpretResponse: function(serverResponse) { const response = serverResponse ? serverResponse.body : []; - if (!isArray(response)) { + if (!utils.isArray(response)) { return []; } @@ -160,9 +160,9 @@ export const spec = { }, onTimeout: function(timeoutData) { - const params = deepAccess(timeoutData, '0.params.0'); + const params = utils.deepAccess(timeoutData, '0.params.0'); - if (!isEmpty(params)) { + if (!utils.isEmpty(params)) { ajax(getURL(params, 'prebid/timeout'), null, timeoutData[0], { method: 'POST', options: { @@ -177,7 +177,7 @@ export const spec = { const { nurl } = bid || {}; if (bid.nurl) { - triggerPixel(replaceAuctionPrice(nurl, bid.cpm)); + utils.triggerPixel(utils.replaceAuctionPrice(nurl, bid.cpm)); }; } } diff --git a/modules/beachfrontBidAdapter.js b/modules/beachfrontBidAdapter.js index a882a796851..3531fa45d1b 100644 --- a/modules/beachfrontBidAdapter.js +++ b/modules/beachfrontBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, deepAccess, isArray, parseSizesInput, isFn, parseUrl, getUniqueIdentifierStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; @@ -34,21 +34,21 @@ export const spec = { isBidRequestValid(bid) { if (isVideoBid(bid)) { if (!getVideoBidParam(bid, 'appId')) { - logWarn('Beachfront: appId param is required for video bids.'); + utils.logWarn('Beachfront: appId param is required for video bids.'); return false; } if (!getVideoBidParam(bid, 'bidfloor')) { - logWarn('Beachfront: bidfloor param is required for video bids.'); + utils.logWarn('Beachfront: bidfloor param is required for video bids.'); return false; } } if (isBannerBid(bid)) { if (!getBannerBidParam(bid, 'appId')) { - logWarn('Beachfront: appId param is required for banner bids.'); + utils.logWarn('Beachfront: appId param is required for banner bids.'); return false; } if (!getBannerBidParam(bid, 'bidfloor')) { - logWarn('Beachfront: bidfloor param is required for banner bids.'); + utils.logWarn('Beachfront: bidfloor param is required for banner bids.'); return false; } } @@ -85,12 +85,12 @@ export const spec = { if (isVideoBid(bidRequest)) { if (!response || !response.bidPrice) { - logWarn(`No valid video bids from ${spec.code} bidder`); + utils.logWarn(`No valid video bids from ${spec.code} bidder`); return []; } let sizes = getVideoSizes(bidRequest); let firstSize = getFirstSize(sizes); - let context = deepAccess(bidRequest, 'mediaTypes.video.context'); + let context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); let responseType = getVideoBidParam(bidRequest, 'responseType') || 'both'; let responseMeta = Object.assign({ mediaType: VIDEO, advertiserDomains: [] }, response.meta); let bidResponse = { @@ -119,7 +119,7 @@ export const spec = { return bidResponse; } else { if (!response || !response.length) { - logWarn(`No valid banner bids from ${spec.code} bidder`); + utils.logWarn(`No valid banner bids from ${spec.code} bidder`); return []; } return response @@ -148,7 +148,7 @@ export const spec = { getUserSyncs(syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '') { let syncs = []; let { gdprApplies, consentString = '' } = gdprConsent; - let bannerResponse = find(serverResponses, (res) => isArray(res.body)); + let bannerResponse = find(serverResponses, (res) => utils.isArray(res.body)); if (bannerResponse) { if (syncOptions.iframeEnabled) { @@ -206,7 +206,7 @@ function getFirstSize(sizes) { } function parseSizes(sizes) { - return parseSizesInput(sizes).map(size => { + return utils.parseSizesInput(sizes).map(size => { let [ width, height ] = size.split('x'); return { w: parseInt(width, 10) || undefined, @@ -216,11 +216,11 @@ function parseSizes(sizes) { } function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); } function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); } function getOsVersion() { @@ -257,33 +257,33 @@ function getDoNotTrack() { } function isVideoBid(bid) { - return deepAccess(bid, 'mediaTypes.video'); + return utils.deepAccess(bid, 'mediaTypes.video'); } function isBannerBid(bid) { - return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); + return utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); } function getVideoBidParam(bid, key) { - return deepAccess(bid, 'params.video.' + key) || deepAccess(bid, 'params.' + key); + return utils.deepAccess(bid, 'params.video.' + key) || utils.deepAccess(bid, 'params.' + key); } function getBannerBidParam(bid, key) { - return deepAccess(bid, 'params.banner.' + key) || deepAccess(bid, 'params.' + key); + return utils.deepAccess(bid, 'params.banner.' + key) || utils.deepAccess(bid, 'params.' + key); } function getPlayerBidParam(bid, key, defaultValue) { - let param = deepAccess(bid, 'params.player.' + key); + let param = utils.deepAccess(bid, 'params.player.' + key); return param === undefined ? defaultValue : param; } function getBannerBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; + let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); } function getVideoBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; + let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); } @@ -297,7 +297,7 @@ function isBannerBidValid(bid) { function getTopWindowLocation(bidderRequest) { let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); + return utils.parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); } function getTopWindowReferrer() { @@ -316,7 +316,7 @@ function getEids(bid) { function getUserId(bid) { return ({ key, source, rtiPartner, atype }) => { - let id = deepAccess(bid, `userId.${key}`); + let id = utils.deepAccess(bid, `userId.${key}`); return id ? formatEid(id, source, rtiPartner, atype) : null; }; } @@ -364,7 +364,7 @@ function createVideoRequestData(bid, bidderRequest) { isPrebid: true, appId: appId, domain: document.location.hostname, - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: [{ video: Object.assign({ w: firstSize.w, @@ -469,7 +469,7 @@ function createBannerRequestData(bids, bidderRequest) { } SUPPORTED_USER_IDS.forEach(({ key, queryParam }) => { - let id = deepAccess(bids, `0.userId.${key}`) + let id = utils.deepAccess(bids, `0.userId.${key}`) if (id) { payload[queryParam] = id; } From 9e42ba5700bce0aca28084ff1b41a747bdb9e2d1 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 13:19:40 -0700 Subject: [PATCH 11/14] Revert "import utils functions as needed and not the whole module" This reverts commit 7e3fa3feba9ec9b8e81524419c3c13e94ee1049e. --- modules/beopBidAdapter.js | 44 +++++++++++++++++----------------- modules/bidViewabilityIO.js | 14 +++++------ modules/bidglassBidAdapter.js | 16 ++++++------- modules/bidscubeBidAdapter.js | 6 ++--- modules/bizzclickBidAdapter.js | 20 ++++++++-------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index a6bc8a5687d..aed5d04a151 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'beop'; @@ -36,7 +36,7 @@ export const spec = { */ buildRequests: function(validBidRequests, bidderRequest) { const slots = validBidRequests.map(beOpRequestSlotsMaker); - let pageUrl = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href'); + let pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); let fpd = config.getLegacyFpd(config.getConfig('ortb2')); let gdpr = bidderRequest.gdprConsent; let firstSlot = slots[0]; @@ -50,7 +50,7 @@ export const spec = { kwds: (fpd && fpd.site && fpd.site.keywords) || [], dbg: false, slts: slots, - is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'), + is_amp: utils.deepAccess(bidderRequest, 'referrerInfo.isAmp'), tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null, }; const payloadString = JSON.stringify(payloadObject); @@ -61,7 +61,7 @@ export const spec = { } }, interpretResponse: function(serverResponse, request) { - if (serverResponse && serverResponse.body && isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { + if (serverResponse && serverResponse.body && utils.isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { return serverResponse.body.bids; } return []; @@ -73,8 +73,8 @@ export const spec = { let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout); - logWarn(BIDDER_CODE + ': timed out request'); - triggerPixel(buildUrl({ + utils.logWarn(BIDDER_CODE + ': timed out request'); + utils.triggerPixel(utils.buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -87,8 +87,8 @@ export const spec = { } let trackingParams = buildTrackingParams(bid, 'won', bid.cpm); - logInfo(BIDDER_CODE + ': won request'); - triggerPixel(buildUrl({ + utils.logInfo(BIDDER_CODE + ': won request'); + utils.triggerPixel(utils.buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -113,8 +113,8 @@ function buildTrackingParams(data, info, value) { } function beOpRequestSlotsMaker(bid) { - const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes'); - const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR'; + const bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); + const publisherCurrency = config.getConfig('currency.adServerCurrency') || utils.getValue(bid.params, 'currency') || 'EUR'; let floor; if (typeof bid.getFloor === 'function') { const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]}); @@ -123,19 +123,19 @@ function beOpRequestSlotsMaker(bid) { } } return { - sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes, + sizes: utils.isArray(bannerSizes) ? bannerSizes : bid.sizes, flr: floor, - pid: getValue(bid.params, 'accountId'), - nid: getValue(bid.params, 'networkId'), - nptnid: getValue(bid.params, 'networkPartnerId'), - bid: getBidIdParameter('bidId', bid), - brid: getBidIdParameter('bidderRequestId', bid), - name: getBidIdParameter('adUnitCode', bid), - aid: getBidIdParameter('auctionId', bid), - tid: getBidIdParameter('transactionId', bid), - brc: getBidIdParameter('bidRequestsCount', bid), - bdrc: getBidIdParameter('bidderRequestCount', bid), - bwc: getBidIdParameter('bidderWinsCount', bid), + pid: utils.getValue(bid.params, 'accountId'), + nid: utils.getValue(bid.params, 'networkId'), + nptnid: utils.getValue(bid.params, 'networkPartnerId'), + bid: utils.getBidIdParameter('bidId', bid), + brid: utils.getBidIdParameter('bidderRequestId', bid), + name: utils.getBidIdParameter('adUnitCode', bid), + aid: utils.getBidIdParameter('auctionId', bid), + tid: utils.getBidIdParameter('transactionId', bid), + brc: utils.getBidIdParameter('bidRequestsCount', bid), + bdrc: utils.getBidIdParameter('bidderRequestCount', bid), + bwc: utils.getBidIdParameter('bidderWinsCount', bid), } } diff --git a/modules/bidViewabilityIO.js b/modules/bidViewabilityIO.js index d936fb4aeec..4651e424d00 100644 --- a/modules/bidViewabilityIO.js +++ b/modules/bidViewabilityIO.js @@ -1,7 +1,7 @@ -import { logMessage } from '../src/utils.js'; import { config } from '../src/config.js'; import * as events from '../src/events.js'; import { EVENTS } from '../src/constants.json'; +import * as utils from '../src/utils.js'; const MODULE_NAME = 'bidViewabilityIO'; const CONFIG_ENABLED = 'enabled'; @@ -23,8 +23,8 @@ export let isSupportedMediaType = (bid) => { return supportedMediaTypes.indexOf(bid.mediaType) > -1; } -let _logMessage = (message) => { - return logMessage(`${MODULE_NAME}: ${message}`); +let logMessage = (message) => { + return utils.logMessage(`${MODULE_NAME}: ${message}`); } // returns options for the iO that detects if the ad is viewable @@ -43,7 +43,7 @@ export let markViewed = (bid, entry, observer) => { return () => { observer.unobserve(entry.target); events.emit(EVENTS.BID_VIEWABLE, bid); - _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); } } @@ -59,13 +59,13 @@ export let viewCallbackFactory = (bid) => { return (entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { - _logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); entry.target.view_tracker = setTimeout(markViewed(bid, entry, observer), IAB_VIEWABLE_DISPLAY_TIME); } else { - _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); if (entry.target.view_tracker) { clearTimeout(entry.target.view_tracker); - _logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); } } }); diff --git a/modules/bidglassBidAdapter.js b/modules/bidglassBidAdapter.js index 3184372881b..b77ca474e13 100644 --- a/modules/bidglassBidAdapter.js +++ b/modules/bidglassBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, isArray, getBidIdParameter, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; // import {config} from 'src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; @@ -69,12 +69,12 @@ export const spec = { let bidglass = window['bidglass']; - _each(validBidRequests, function(bid) { - bid.sizes = ((isArray(bid.sizes) && isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); - bid.sizes = bid.sizes.filter(size => isArray(size)); + utils._each(validBidRequests, function(bid) { + bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); + bid.sizes = bid.sizes.filter(size => utils.isArray(size)); - var adUnitId = getBidIdParameter('adUnitId', bid.params); - var options = deepClone(bid.params); + var adUnitId = utils.getBidIdParameter('adUnitId', bid.params); + var options = utils.deepClone(bid.params); delete options.adUnitId; @@ -96,7 +96,7 @@ export const spec = { // Stuff to send: page URL const bidReq = { - reqId: getUniqueIdentifierStr(), + reqId: utils.getUniqueIdentifierStr(), imps: imps, ref: getReferer(), ori: getOrigins() @@ -125,7 +125,7 @@ export const spec = { interpretResponse: function(serverResponse) { const bidResponses = []; - _each(serverResponse.body.bidResponses, function(serverBid) { + utils._each(serverResponse.body.bidResponses, function(serverBid) { const bidResponse = { requestId: serverBid.requestId, cpm: parseFloat(serverBid.cpm), diff --git a/modules/bidscubeBidAdapter.js b/modules/bidscubeBidAdapter.js index 951bd97d255..d3f27a5ac6d 100644 --- a/modules/bidscubeBidAdapter.js +++ b/modules/bidscubeBidAdapter.js @@ -1,6 +1,6 @@ -import { logMessage, getWindowLocation } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js' +import * as utils from '../src/utils.js' const BIDDER_CODE = 'bidscube' const URL = 'https://supply.bidscube.com/?c=o&m=multi' @@ -20,9 +20,9 @@ export const spec = { try { window.top.location.toString() winTop = window.top - } catch (e) { logMessage(e) } + } catch (e) { utils.logMessage(e) } - const location = getWindowLocation() + const location = utils.getWindowLocation() const placements = [] for (let i = 0; i < validBidRequests.length; i++) { diff --git a/modules/bizzclickBidAdapter.js b/modules/bizzclickBidAdapter.js index 38195f8f9d9..95c53b78de2 100644 --- a/modules/bizzclickBidAdapter.js +++ b/modules/bizzclickBidAdapter.js @@ -1,6 +1,6 @@ -import { logMessage, getDNT, deepSetValue, deepAccess, _map, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'bizzclick'; const ACCOUNTID_MACROS = '[account_id]'; @@ -67,7 +67,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let bids = []; for (let bidRequest of validBidRequests) { @@ -80,7 +80,7 @@ export const spec = { device: { w: winTop.screen.width, h: winTop.screen.height, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, language: (navigator && navigator.language) ? navigator.language.indexOf('-') != -1 ? navigator.language.split('-')[0] : navigator.language : '', }, site: { @@ -124,12 +124,12 @@ export const spec = { } if (bidRequest) { if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) { - deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); - deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); + utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); + utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); } if (bidRequest.uspConsent !== undefined) { - deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); + utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); } } bids.push(data) @@ -194,7 +194,7 @@ export const spec = { * @returns {boolean} */ const checkRequestType = (bidRequest, type) => { - return (typeof deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); + return (typeof utils.deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); } const parseNative = admObject => { const { assets, link, imptrackers, jstracker } = admObject.native; @@ -240,7 +240,7 @@ const addNativeParameters = bidRequest => { id: bidRequest.transactionId, ver: NATIVE_VERSION, }; - const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => { + const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -286,7 +286,7 @@ const parseSizes = (bid, mediaType) => { mediaTypes.video.w, mediaTypes.video.h ]; - } else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { + } else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { size = bid.mediaTypes.video.playerSize[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) { size = bid.sizes[0]; @@ -299,7 +299,7 @@ const parseSizes = (bid, mediaType) => { } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { sizes = bid.sizes } else { - logWarn('no sizes are setup or found'); + utils.logWarn('no sizes are setup or found'); } return sizes } From 8200e6b275c41736b4d25255e96a1c12503c7210 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 27 Sep 2021 11:59:19 -0700 Subject: [PATCH 12/14] import utils functions as needed and not the whole module --- modules/timeoutRtdProvider.js | 30 ++++++++++----------- modules/tpmnBidAdapter.js | 6 ++--- modules/trionBidAdapter.js | 30 ++++++++++----------- modules/tripleliftBidAdapter.js | 46 ++++++++++++++++----------------- modules/truereachBidAdapter.js | 8 +++--- 5 files changed, 60 insertions(+), 60 deletions(-) diff --git a/modules/timeoutRtdProvider.js b/modules/timeoutRtdProvider.js index 8f68cf1bcc5..323a5291e2d 100644 --- a/modules/timeoutRtdProvider.js +++ b/modules/timeoutRtdProvider.js @@ -1,7 +1,7 @@ import { submodule } from '../src/hook.js'; import * as ajax from '../src/ajax.js'; -import * as utils from '../src/utils.js'; +import { logInfo, deepAccess, logError } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; const SUBMODULE_NAME = 'timeout'; @@ -70,14 +70,14 @@ function getConnectionSpeed() { * @return {int} */ function calculateTimeoutModifier(adUnits, rules) { - utils.logInfo('Timeout rules', rules); + logInfo('Timeout rules', rules); let timeoutModifier = 0; let toAdd = 0; if (rules.includesVideo) { const hasVideo = timeoutRtdFunctions.checkVideo(adUnits); toAdd = rules.includesVideo[hasVideo] || 0; - utils.logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`) + logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`) timeoutModifier += toAdd; } @@ -89,7 +89,7 @@ function calculateTimeoutModifier(adUnits, rules) { for (const [rangeStr, timeoutVal] of entries(rules.numAdUnits)) { const [lowerBound, upperBound] = rangeStr.split('-'); if (parseInt(lowerBound) <= numAdUnits && numAdUnits <= parseInt(upperBound)) { - utils.logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`) + logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`) timeoutModifier += timeoutVal; break; } @@ -100,18 +100,18 @@ function calculateTimeoutModifier(adUnits, rules) { if (rules.deviceType) { const deviceType = timeoutRtdFunctions.getDeviceType(); toAdd = rules.deviceType[deviceType] || 0; - utils.logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`) + logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`) timeoutModifier += toAdd; } if (rules.connectionSpeed) { const connectionSpeed = timeoutRtdFunctions.getConnectionSpeed(); toAdd = rules.connectionSpeed[connectionSpeed] || 0; - utils.logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`) + logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`) timeoutModifier += toAdd; } - utils.logInfo('timeout Modifier calculated', timeoutModifier); + logInfo('timeout Modifier calculated', timeoutModifier); return timeoutModifier; } @@ -123,30 +123,30 @@ function calculateTimeoutModifier(adUnits, rules) { * @param {Object} userConsent */ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { - utils.logInfo('Timeout rtd config', config); - const timeoutUrl = utils.deepAccess(config, 'params.endpoint.url'); + logInfo('Timeout rtd config', config); + const timeoutUrl = deepAccess(config, 'params.endpoint.url'); if (timeoutUrl) { - utils.logInfo('Timeout url', timeoutUrl); + logInfo('Timeout url', timeoutUrl); ajax.ajaxBuilder()(timeoutUrl, { success: function(response) { try { const rules = JSON.parse(response); timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules); } catch (e) { - utils.logError('Error parsing json response from timeout provider.') + logError('Error parsing json response from timeout provider.') } callback(); }, error: function(errorStatus) { - utils.logError('Timeout request error!', errorStatus); + logError('Timeout request error!', errorStatus); callback(); } }); - } else if (utils.deepAccess(config, 'params.rules')) { - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, utils.deepAccess(config, 'params.rules')); + } else if (deepAccess(config, 'params.rules')) { + timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, deepAccess(config, 'params.rules')); callback(); } else { - utils.logInfo('No timeout endpoint or timeout rules found. Exiting timeout rtd module'); + logInfo('No timeout endpoint or timeout rules found. Exiting timeout rtd module'); callback(); } } diff --git a/modules/tpmnBidAdapter.js b/modules/tpmnBidAdapter.js index ec9d30c0e29..006357cd4b9 100644 --- a/modules/tpmnBidAdapter.js +++ b/modules/tpmnBidAdapter.js @@ -1,6 +1,6 @@ /* eslint-disable no-tabs */ import { registerBidder } from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js'; +import { parseUrl, deepAccess } from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; export const ADAPTER_VERSION = '1'; @@ -72,7 +72,7 @@ registerBidder(spec); * 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 @@ -102,7 +102,7 @@ function parseSizes(sizes) { } function getBannerSizes(bidRequest) { - return parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes); + return parseSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes); } function bidToRequest(bid) { diff --git a/modules/trionBidAdapter.js b/modules/trionBidAdapter.js index e9e030ce33f..dd1624f90d7 100644 --- a/modules/trionBidAdapter.js +++ b/modules/trionBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { getBidIdParameter, parseSizesInput, tryAppendQueryString } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -112,11 +112,11 @@ function getPublisherUrl() { } function buildTrionUrlParams(bid, bidderRequest) { - var pubId = utils.getBidIdParameter('pubId', bid.params); - var sectionId = utils.getBidIdParameter('sectionId', bid.params); + var pubId = getBidIdParameter('pubId', bid.params); + var sectionId = getBidIdParameter('sectionId', bid.params); var url = getPublisherUrl(); var bidSizes = getBidSizesFromBidRequest(bid); - var sizes = utils.parseSizesInput(bidSizes).join(','); + var sizes = parseSizesInput(bidSizes).join(','); var isAutomated = (navigator && navigator.webdriver) ? '1' : '0'; var isHidden = (document.hidden) ? '1' : '0'; var visibilityState = encodeURIComponent(document.visibilityState); @@ -131,10 +131,10 @@ function buildTrionUrlParams(bid, bidderRequest) { setStorageData(BASE_KEY + 'lps', pubId + ':' + sectionId); var trionUrl = ''; - trionUrl = utils.tryAppendQueryString(trionUrl, 'bidId', bid.bidId); - trionUrl = utils.tryAppendQueryString(trionUrl, 'pubId', pubId); - trionUrl = utils.tryAppendQueryString(trionUrl, 'sectionId', sectionId); - trionUrl = utils.tryAppendQueryString(trionUrl, 'vers', '$prebid.version$'); + trionUrl = tryAppendQueryString(trionUrl, 'bidId', bid.bidId); + trionUrl = tryAppendQueryString(trionUrl, 'pubId', pubId); + trionUrl = tryAppendQueryString(trionUrl, 'sectionId', sectionId); + trionUrl = tryAppendQueryString(trionUrl, 'vers', '$prebid.version$'); if (url) { trionUrl += 'url=' + url + '&'; } @@ -142,22 +142,22 @@ function buildTrionUrlParams(bid, bidderRequest) { trionUrl += 'sizes=' + sizes + '&'; } if (intT) { - trionUrl = utils.tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT)); + trionUrl = tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT)); } - trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_wd', isAutomated); - trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_hd', isHidden); - trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_vs', visibilityState); + trionUrl = tryAppendQueryString(trionUrl, 'tr_wd', isAutomated); + trionUrl = tryAppendQueryString(trionUrl, 'tr_hd', isHidden); + trionUrl = tryAppendQueryString(trionUrl, 'tr_vs', visibilityState); if (bidderRequest && bidderRequest.gdprConsent) { var gdpr = bidderRequest.gdprConsent; if (gdpr) { if (gdpr.consentString) { - trionUrl = utils.tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString)); + trionUrl = tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString)); } - trionUrl = utils.tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0)); + trionUrl = tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0)); } } if (bidderRequest && bidderRequest.uspConsent) { - trionUrl = utils.tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent)); + trionUrl = tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent)); } // remove the trailing "&" if (trionUrl.lastIndexOf('&') === trionUrl.length - 1) { diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 2dc0b069a3c..01df88f62ee 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -1,6 +1,6 @@ +import { tryAppendQueryString, logMessage, isEmpty } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; const GVLID = 28; @@ -23,41 +23,41 @@ export const tripleliftAdapterSpec = { let tlCall = STR_ENDPOINT; let data = _buildPostBody(bidRequests); - tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid'); - tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$'); + tlCall = tryAppendQueryString(tlCall, 'lib', 'prebid'); + tlCall = tryAppendQueryString(tlCall, 'v', '$prebid.version$'); if (bidderRequest && bidderRequest.refererInfo) { let referrer = bidderRequest.refererInfo.referer; - tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer); + tlCall = tryAppendQueryString(tlCall, 'referrer', referrer); } if (bidderRequest && bidderRequest.timeout) { - tlCall = utils.tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout); + tlCall = tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout); } if (bidderRequest && bidderRequest.gdprConsent) { if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') { gdprApplies = bidderRequest.gdprConsent.gdprApplies; - tlCall = utils.tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString()); + tlCall = tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString()); } if (typeof bidderRequest.gdprConsent.consentString !== 'undefined') { consentString = bidderRequest.gdprConsent.consentString; - tlCall = utils.tryAppendQueryString(tlCall, 'cmp_cs', consentString); + tlCall = tryAppendQueryString(tlCall, 'cmp_cs', consentString); } } if (bidderRequest && bidderRequest.uspConsent) { - tlCall = utils.tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent); + tlCall = tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa') === true) { - tlCall = utils.tryAppendQueryString(tlCall, 'coppa', true); + tlCall = tryAppendQueryString(tlCall, 'coppa', true); } if (tlCall.lastIndexOf('&') === tlCall.length - 1) { tlCall = tlCall.substring(0, tlCall.length - 1); } - utils.logMessage('tlCall request built: ' + tlCall); + logMessage('tlCall request built: ' + tlCall); return { method: 'POST', @@ -81,17 +81,17 @@ export const tripleliftAdapterSpec = { let syncEndpoint = 'https://eb2.3lift.com/sync?'; if (syncType === 'image') { - syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'px', 1); - syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'src', 'prebid'); + syncEndpoint = tryAppendQueryString(syncEndpoint, 'px', 1); + syncEndpoint = tryAppendQueryString(syncEndpoint, 'src', 'prebid'); } if (consentString !== null) { - syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies); - syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString); + syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies); + syncEndpoint = tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString); } if (usPrivacy) { - syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy); + syncEndpoint = tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy); } return [{ @@ -124,7 +124,7 @@ function _buildPostBody(bidRequests) { } else if (bidRequest.mediaTypes.banner) { imp.banner = { format: _sizes(bidRequest.sizes) }; }; - if (!utils.isEmpty(bidRequest.ortb2Imp)) { + if (!isEmpty(bidRequest.ortb2Imp)) { imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp); } return imp; @@ -145,7 +145,7 @@ function _buildPostBody(bidRequests) { let ext = _getExt(schain, globalFpd); - if (!utils.isEmpty(ext)) { + if (!isEmpty(ext)) { data.ext = ext; } return data; @@ -200,10 +200,10 @@ function _getGlobalFpd() { _addEntries(context, fpdContext); _addEntries(user, fpdUser); - if (!utils.isEmpty(context)) { + if (!isEmpty(context)) { fpd.context = context; } - if (!utils.isEmpty(user)) { + if (!isEmpty(user)) { fpd.user = user; } return fpd; @@ -215,7 +215,7 @@ function _getAdUnitFpd(adUnitFpd) { _addEntries(context, adUnitFpd.ext); - if (!utils.isEmpty(context)) { + if (!isEmpty(context)) { fpd.context = context; } @@ -223,7 +223,7 @@ function _getAdUnitFpd(adUnitFpd) { } function _addEntries(target, source) { - if (!utils.isEmpty(source)) { + if (!isEmpty(source)) { Object.keys(source).forEach(key => { if (source[key] != null) { target[key] = source[key]; @@ -234,10 +234,10 @@ function _addEntries(target, source) { function _getExt(schain, fpd) { let ext = {}; - if (!utils.isEmpty(schain)) { + if (!isEmpty(schain)) { ext.schain = { ...schain }; } - if (!utils.isEmpty(fpd)) { + if (!isEmpty(fpd)) { ext.fpd = { ...fpd }; } return ext; diff --git a/modules/truereachBidAdapter.js b/modules/truereachBidAdapter.js index fadc952b5fb..a0244e3a349 100755 --- a/modules/truereachBidAdapter.js +++ b/modules/truereachBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, getUniqueIdentifierStr } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -13,7 +13,7 @@ export const spec = { isBidRequestValid: function (bidRequest) { return (bidRequest.params.site_id && bidRequest.params.bidfloor && - utils.deepAccess(bidRequest, 'mediaTypes.banner') && (utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0)); + deepAccess(bidRequest, 'mediaTypes.banner') && (deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0)); }, buildRequests: function (validBidRequests, bidderRequest) { @@ -23,7 +23,7 @@ export const spec = { let queryParams = buildCommonQueryParamsFromBids(validBidRequests, bidderRequest); - let siteId = utils.deepAccess(validBidRequests[0], 'params.site_id'); + let siteId = deepAccess(validBidRequests[0], 'params.site_id'); let url = BIDDER_URL + siteId + '?hb=1&transactionId=' + validBidRequests[0].transactionId; @@ -121,7 +121,7 @@ function buildCommonQueryParamsFromBids(validBidRequests, bidderRequest) { let page = window.location.host + window.location.pathname + location.search + location.hash; let defaultParams = { - id: utils.getUniqueIdentifierStr(), + id: getUniqueIdentifierStr(), imp: [ { id: validBidRequests[0].bidId, From 232d94a4a85597a433b1b7f4247fd04187a502ff Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 27 Sep 2021 12:08:06 -0700 Subject: [PATCH 13/14] import utils functions as needed and not the whole module --- modules/trustxBidAdapter.js | 26 +++++++++++++------------- modules/ucfunnelBidAdapter.js | 6 +++--- modules/uid2IdSystem.js | 12 ++++++------ modules/underdogmediaBidAdapter.js | 8 ++++---- modules/unicornBidAdapter.js | 26 +++++++++++++------------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js index d99dbf0cd87..bd7c5c9a5c3 100644 --- a/modules/trustxBidAdapter.js +++ b/modules/trustxBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { isEmpty, deepAccess, logError, logWarn, parseGPTSingleSizeArrayToRtbSize } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; @@ -102,7 +102,7 @@ export const spec = { } }; - if (!utils.isEmpty(keywords)) { + if (!isEmpty(keywords)) { if (!pageKeywords) { pageKeywords = keywords; } @@ -188,8 +188,8 @@ export const spec = { request.user = user; } - const userKeywords = utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; - const siteKeywords = utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; + const userKeywords = deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; + const siteKeywords = deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; if (userKeywords) { pageKeywords = pageKeywords || {}; @@ -267,7 +267,7 @@ export const spec = { _addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses, RendererConst); }); } - if (errorMessage) utils.logError(errorMessage); + if (errorMessage) logError(errorMessage); return bidResponses; }, getUserSyncs: function(syncOptions, responses, gdprConsent, uspConsent) { @@ -302,11 +302,11 @@ export const spec = { function _getBidFromResponse(respItem) { if (!respItem) { - utils.logError(LOG_ERROR_MESS.emptySeatbid); + logError(LOG_ERROR_MESS.emptySeatbid); } else if (!respItem.bid) { - utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); + logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); } else if (!respItem.bid[0]) { - utils.logError(LOG_ERROR_MESS.noBid); + logError(LOG_ERROR_MESS.noBid); } return respItem && respItem.bid && respItem.bid[0]; } @@ -356,7 +356,7 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst) { } } if (errorMessage) { - utils.logError(errorMessage); + logError(errorMessage); } } @@ -379,7 +379,7 @@ function createRenderer (bid, rendererParams, RendererConst) { try { rendererInst.setRender(outstreamRender); } catch (err) { - utils.logWarn('Prebid Error calling setRender on renderer', err); + logWarn('Prebid Error calling setRender on renderer', err); } return rendererInst; @@ -390,7 +390,7 @@ function createVideoRequest(bid, mediaType) { const size = (playerSize || bid.sizes || [])[0]; if (!size) return; - let result = utils.parseGPTSingleSizeArrayToRtbSize(size); + let result = parseGPTSingleSizeArrayToRtbSize(size); if (mimes) { result.mimes = mimes; @@ -412,8 +412,8 @@ function createBannerRequest(bid, mediaType) { const sizes = mediaType.sizes || bid.sizes; if (!sizes || !sizes.length) return; - let format = sizes.map((size) => utils.parseGPTSingleSizeArrayToRtbSize(size)); - let result = utils.parseGPTSingleSizeArrayToRtbSize(sizes[0]); + let format = sizes.map((size) => parseGPTSingleSizeArrayToRtbSize(size)); + let result = parseGPTSingleSizeArrayToRtbSize(sizes[0]); if (format.length) { result.format = format diff --git a/modules/ucfunnelBidAdapter.js b/modules/ucfunnelBidAdapter.js index 69cbbc697fc..8b85f1ebad3 100644 --- a/modules/ucfunnelBidAdapter.js +++ b/modules/ucfunnelBidAdapter.js @@ -1,8 +1,8 @@ +import { generateUUID, _each } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; import { config } from '../src/config.js'; -import * as utils from '../src/utils.js'; const storage = getStorageManager(); const COOKIE_NAME = 'ucf_uid'; const VER = 'ADGENT_PREBID-2018011501'; @@ -283,7 +283,7 @@ function getRequestData(bid, bidderRequest) { ucfUid = storage.getCookie(COOKIE_NAME); bidData.ucfUid = ucfUid; } else { - ucfUid = utils.generateUUID(); + ucfUid = generateUUID(); bidData.ucfUid = ucfUid; storage.setCookie(COOKIE_NAME, ucfUid); } @@ -335,7 +335,7 @@ function getRequestData(bid, bidderRequest) { function addUserId(bidData, userId) { bidData['eids'] = ''; - utils._each(userId, (userIdObjectOrValue, userIdProviderKey) => { + _each(userId, (userIdObjectOrValue, userIdProviderKey) => { switch (userIdProviderKey) { case 'haloId': if (userIdObjectOrValue.haloId) { diff --git a/modules/uid2IdSystem.js b/modules/uid2IdSystem.js index 053b57cb76d..c0cd9166784 100644 --- a/modules/uid2IdSystem.js +++ b/modules/uid2IdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import * as utils from '../src/utils.js' +import { logInfo } from '../src/utils.js'; import {submodule} from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -28,11 +28,11 @@ function getStorage() { const storage = getStorage(); -const logInfo = createLogInfo(LOG_PRE_FIX); +const _logInfo = createLogInfo(LOG_PRE_FIX); function createLogInfo(prefix) { return function (...strings) { - utils.logInfo(prefix + ' ', ...strings); + logInfo(prefix + ' ', ...strings); } } @@ -48,7 +48,7 @@ function encodeId(value) { id: value } result.uid2 = bidIds; - logInfo('Decoded value ' + JSON.stringify(result)); + _logInfo('Decoded value ' + JSON.stringify(result)); return result; } return undefined; @@ -85,9 +85,9 @@ export const uid2IdSubmodule = { * @returns {uid2Id} */ getId(config, consentData) { - logInfo('Creating UID 2.0'); + _logInfo('Creating UID 2.0'); let value = readCookie() || readFromLocalStorage(); - logInfo('The advertising token: ' + value); + _logInfo('The advertising token: ' + value); return {id: value} }, diff --git a/modules/underdogmediaBidAdapter.js b/modules/underdogmediaBidAdapter.js index 6268774bc12..2ca4de7a555 100644 --- a/modules/underdogmediaBidAdapter.js +++ b/modules/underdogmediaBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { logMessage, flatten, parseSizesInput } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'underdogmedia'; @@ -7,7 +7,7 @@ const UDM_VENDOR_ID = '159'; const prebidVersion = '$prebid.version$'; let USER_SYNCED = false; -utils.logMessage(`Initializing UDM Adapter. PBJS Version: ${prebidVersion} with adapter version: ${UDM_ADAPTER_VERSION} Updated 20191028`); +logMessage(`Initializing UDM Adapter. PBJS Version: ${prebidVersion} with adapter version: ${UDM_ADAPTER_VERSION} Updated 20191028`); // helper function for testing user syncs export function resetUserSync() { @@ -29,7 +29,7 @@ export const spec = { validBidRequests.forEach(bidParam => { let bidParamSizes = bidParam.mediaTypes && bidParam.mediaTypes.banner && bidParam.mediaTypes.banner.sizes ? bidParam.mediaTypes.banner.sizes : bidParam.sizes; - sizes = utils.flatten(sizes, utils.parseSizesInput(bidParamSizes)); + sizes = flatten(sizes, parseSizesInput(bidParamSizes)); siteId = bidParam.params.siteId; }); @@ -99,7 +99,7 @@ export const spec = { var sizeNotFound = true; const bidParamSizes = bidParam.mediaTypes && bidParam.mediaTypes.banner && bidParam.mediaTypes.banner.sizes ? bidParam.mediaTypes.banner.sizes : bidParam.sizes - utils.parseSizesInput(bidParamSizes).forEach(size => { + parseSizesInput(bidParamSizes).forEach(size => { if (size === mid.width + 'x' + mid.height) { sizeNotFound = false; } diff --git a/modules/unicornBidAdapter.js b/modules/unicornBidAdapter.js index e74c4425626..d89866ef379 100644 --- a/modules/unicornBidAdapter.js +++ b/modules/unicornBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { logInfo, deepAccess, generateUUID } from '../src/utils.js'; import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -39,8 +39,8 @@ export const buildRequests = (validBidRequests, bidderRequest) => { * @returns {string} */ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { - utils.logInfo('[UNICORN] buildOpenRtbBidRequestPayload.validBidRequests:', validBidRequests); - utils.logInfo('[UNICORN] buildOpenRtbBidRequestPayload.bidderRequest:', bidderRequest); + logInfo('[UNICORN] buildOpenRtbBidRequestPayload.validBidRequests:', validBidRequests); + logInfo('[UNICORN] buildOpenRtbBidRequestPayload.bidderRequest:', bidderRequest); const imp = validBidRequests.map(br => { return { id: br.bidId, @@ -49,7 +49,7 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { w: br.sizes[0][0], h: br.sizes[0][1] }, - tagid: utils.deepAccess(br, 'params.placementId') || br.adUnitCode, + tagid: deepAccess(br, 'params.placementId') || br.adUnitCode, secure: 1, bidfloor: parseFloat(0) }; @@ -60,9 +60,9 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { imp, cur: UNICORN_DEFAULT_CURRENCY, site: { - id: utils.deepAccess(validBidRequests[0], 'params.mediaId') || '', + id: deepAccess(validBidRequests[0], 'params.mediaId') || '', publisher: { - id: utils.deepAccess(validBidRequests[0], 'params.publisherId') || 0 + id: deepAccess(validBidRequests[0], 'params.publisherId') || 0 }, domain: window.location.hostname, page: window.location.href, @@ -75,7 +75,7 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { user: { id: getUid() }, - bcat: utils.deepAccess(validBidRequests[0], 'params.bcat') || [], + bcat: deepAccess(validBidRequests[0], 'params.bcat') || [], source: { ext: { stype: 'prebid_uncn', @@ -84,16 +84,16 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { } }, ext: { - accountId: utils.deepAccess(validBidRequests[0], 'params.accountId') + accountId: deepAccess(validBidRequests[0], 'params.accountId') } }; - utils.logInfo('[UNICORN] OpenRTB Formatted Request:', request); + logInfo('[UNICORN] OpenRTB Formatted Request:', request); return JSON.stringify(request); } const interpretResponse = (serverResponse, request) => { - utils.logInfo('[UNICORN] interpretResponse.serverResponse:', serverResponse); - utils.logInfo('[UNICORN] interpretResponse.request:', request); + logInfo('[UNICORN] interpretResponse.serverResponse:', serverResponse); + logInfo('[UNICORN] interpretResponse.request:', request); const res = serverResponse.body; var bids = [] if (res) { @@ -119,7 +119,7 @@ const interpretResponse = (serverResponse, request) => { }) }); } - utils.logInfo('[UNICORN] interpretResponse bids:', bids); + logInfo('[UNICORN] interpretResponse bids:', bids); return bids; }; @@ -132,7 +132,7 @@ const getUid = () => { return JSON.parse(ck)['uid']; } else { const newCk = { - uid: utils.generateUUID() + uid: generateUUID() }; const expireIn = new Date(Date.now() + 24 * 60 * 60 * 10000).toUTCString(); storage.setCookie(UNICORN_PB_COOKIE_KEY, JSON.stringify(newCk), expireIn); From f64776f2df958373a2d2d0e408d7522121257e74 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 27 Sep 2021 12:14:00 -0700 Subject: [PATCH 14/14] import utils functions as needed and not the whole module --- modules/unifiedIdSystem.js | 8 ++++---- modules/unrulyBidAdapter.js | 32 ++++++++++++++++---------------- modules/vdoaiBidAdapter.js | 4 ++-- modules/verizonMediaIdSystem.js | 10 +++++----- modules/vidazooBidAdapter.js | 10 +++++----- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/modules/unifiedIdSystem.js b/modules/unifiedIdSystem.js index bc033f37992..8ec5fcd3f90 100644 --- a/modules/unifiedIdSystem.js +++ b/modules/unifiedIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import * as utils from '../src/utils.js' +import { logError } from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js' @@ -40,7 +40,7 @@ export const unifiedIdSubmodule = { getId(config) { const configParams = (config && config.params) || {}; if (!configParams || (typeof configParams.partner !== 'string' && typeof configParams.url !== 'string')) { - utils.logError('User ID - unifiedId submodule requires either partner or url to be defined'); + logError('User ID - unifiedId submodule requires either partner or url to be defined'); return; } // use protocol relative urls for http or https @@ -54,13 +54,13 @@ export const unifiedIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - utils.logError(error); + logError(error); } } callback(responseObj); }, error: error => { - utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; diff --git a/modules/unrulyBidAdapter.js b/modules/unrulyBidAdapter.js index d04192acf15..99fbe63aeb4 100644 --- a/modules/unrulyBidAdapter.js +++ b/modules/unrulyBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js' +import { deepAccess, logError } from '../src/utils.js'; import {Renderer} from '../src/Renderer.js' import {registerBidder} from '../src/adapters/bidderFactory.js' import {VIDEO, BANNER} from '../src/mediaTypes.js' @@ -41,7 +41,7 @@ const addBidFloorInfo = (validBid) => { }; const RemoveDuplicateSizes = (validBid) => { - let bannerMediaType = utils.deepAccess(validBid, 'mediaTypes.banner'); + let bannerMediaType = deepAccess(validBid, 'mediaTypes.banner'); if (bannerMediaType) { let seenSizes = {}; let newSizesArray = []; @@ -87,12 +87,12 @@ const handleBidResponseByMediaType = (bids) => { bids.forEach((bid) => { let parsedBidResponse; - let bidMediaType = utils.deepAccess(bid, 'meta.mediaType'); + let bidMediaType = deepAccess(bid, 'meta.mediaType'); if (bidMediaType && bidMediaType.toLowerCase() === 'banner') { bid.mediaType = BANNER; parsedBidResponse = handleBannerBid(bid); } else if (bidMediaType && bidMediaType.toLowerCase() === 'video') { - let context = utils.deepAccess(bid, 'meta.videoContext'); + let context = deepAccess(bid, 'meta.videoContext'); bid.mediaType = VIDEO; if (context === 'instream') { parsedBidResponse = handleInStreamBid(bid); @@ -111,7 +111,7 @@ const handleBidResponseByMediaType = (bids) => { const handleBannerBid = (bid) => { if (!bid.ad) { - utils.logError(new Error('UnrulyBidAdapter: Missing ad config.')); + logError(new Error('UnrulyBidAdapter: Missing ad config.')); return; } @@ -120,7 +120,7 @@ const handleBannerBid = (bid) => { const handleInStreamBid = (bid) => { if (!(bid.vastUrl || bid.vastXml)) { - utils.logError(new Error('UnrulyBidAdapter: Missing vastUrl or vastXml config.')); + logError(new Error('UnrulyBidAdapter: Missing vastUrl or vastXml config.')); return; } @@ -128,19 +128,19 @@ const handleInStreamBid = (bid) => { }; const handleOutStreamBid = (bid) => { - const hasConfig = !!utils.deepAccess(bid, 'ext.renderer.config'); - const hasSiteId = !!utils.deepAccess(bid, 'ext.renderer.config.siteId'); + const hasConfig = !!deepAccess(bid, 'ext.renderer.config'); + const hasSiteId = !!deepAccess(bid, 'ext.renderer.config.siteId'); if (!hasConfig) { - utils.logError(new Error('UnrulyBidAdapter: Missing renderer config.')); + logError(new Error('UnrulyBidAdapter: Missing renderer config.')); return; } if (!hasSiteId) { - utils.logError(new Error('UnrulyBidAdapter: Missing renderer siteId.')); + logError(new Error('UnrulyBidAdapter: Missing renderer siteId.')); return; } - const exchangeRenderer = utils.deepAccess(bid, 'ext.renderer'); + const exchangeRenderer = deepAccess(bid, 'ext.renderer'); configureUniversalTag(exchangeRenderer, bid.requestId); configureRendererQueue(); @@ -152,7 +152,7 @@ const handleOutStreamBid = (bid) => { bid, { renderer: rendererInstance, - adUnitCode: utils.deepAccess(bid, 'ext.adUnitCode') + adUnitCode: deepAccess(bid, 'ext.adUnitCode') } ); @@ -165,8 +165,8 @@ const handleOutStreamBid = (bid) => { }; const isMediaTypesValid = (bid) => { - const mediaTypeVideoData = utils.deepAccess(bid, 'mediaTypes.video'); - const mediaTypeBannerData = utils.deepAccess(bid, 'mediaTypes.banner'); + const mediaTypeVideoData = deepAccess(bid, 'mediaTypes.video'); + const mediaTypeBannerData = deepAccess(bid, 'mediaTypes.banner'); let isValid = !!(mediaTypeVideoData || mediaTypeBannerData); if (isValid && mediaTypeVideoData) { isValid = isVideoMediaTypeValid(mediaTypeVideoData); @@ -194,7 +194,7 @@ export const adapter = { code: 'unruly', supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - let siteId = utils.deepAccess(bid, 'params.siteId'); + let siteId = deepAccess(bid, 'params.siteId'); let isBidValid = siteId && isMediaTypesValid(bid); return !!isBidValid; }, @@ -202,7 +202,7 @@ export const adapter = { buildRequests: function (validBidRequests, bidderRequest) { let endPoint = 'https://targeting.unrulymedia.com/unruly_prebid'; if (validBidRequests[0]) { - endPoint = utils.deepAccess(validBidRequests[0], 'params.endpoint') || endPoint; + endPoint = deepAccess(validBidRequests[0], 'params.endpoint') || endPoint; } const url = endPoint; diff --git a/modules/vdoaiBidAdapter.js b/modules/vdoaiBidAdapter.js index 4bf5a27c002..40e3b3322a7 100644 --- a/modules/vdoaiBidAdapter.js +++ b/modules/vdoaiBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { getAdUnitSizes } from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; @@ -32,7 +32,7 @@ export const spec = { } return validBidRequests.map(bidRequest => { - const sizes = utils.getAdUnitSizes(bidRequest); + const sizes = getAdUnitSizes(bidRequest); const payload = { placementId: bidRequest.params.placementId, sizes: sizes, diff --git a/modules/verizonMediaIdSystem.js b/modules/verizonMediaIdSystem.js index ca395087d2d..280a6c47894 100644 --- a/modules/verizonMediaIdSystem.js +++ b/modules/verizonMediaIdSystem.js @@ -7,7 +7,7 @@ import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js'; -import * as utils from '../src/utils.js'; +import { logError, formatQS } from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const MODULE_NAME = 'verizonMediaId'; @@ -51,7 +51,7 @@ export const verizonMediaIdSubmodule = { const params = config.params || {}; if (!params || typeof params.he !== 'string' || (typeof params.pixelId === 'undefined' && typeof params.endpoint === 'undefined')) { - utils.logError('The verizonMediaId submodule requires the \'he\' and \'pixelId\' parameters to be defined.'); + logError('The verizonMediaId submodule requires the \'he\' and \'pixelId\' parameters to be defined.'); return; } @@ -75,18 +75,18 @@ export const verizonMediaIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - utils.logError(error); + logError(error); } } callback(responseObj); }, error: error => { - utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; const endpoint = VMCID_ENDPOINT.replace(PLACEHOLDER, params.pixelId); - let url = `${params.endpoint || endpoint}?${utils.formatQS(data)}`; + let url = `${params.endpoint || endpoint}?${formatQS(data)}`; verizonMediaIdSubmodule.getAjaxFn()(url, callbacks, null, {method: 'GET', withCredentials: true}); }; return {callback: resp}; diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index 3fb94870d3f..0e7b4ee63b2 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { _each, deepAccess, parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -94,7 +94,7 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { data: data }; - utils._each(ext, (value, key) => { + _each(ext, (value, key) => { dto.data['ext.' + key] = value; }); @@ -103,13 +103,13 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { function appendUserIdsToRequestPayload(payloadRef, userIds) { let key; - utils._each(userIds, (userId, idSystemProviderName) => { + _each(userIds, (userId, idSystemProviderName) => { if (SUPPORTED_ID_SYSTEMS[idSystemProviderName]) { key = `uid.${idSystemProviderName}`; switch (idSystemProviderName) { case 'digitrustid': - payloadRef[key] = utils.deepAccess(userId, 'data.id'); + payloadRef[key] = deepAccess(userId, 'data.id'); break; case 'lipb': payloadRef[key] = userId.lipbid; @@ -131,7 +131,7 @@ function buildRequests(validBidRequests, bidderRequest) { const topWindowUrl = bidderRequest.refererInfo.referer; const requests = []; validBidRequests.forEach(validBidRequest => { - const sizes = utils.parseSizesInput(validBidRequest.sizes); + const sizes = parseSizesInput(validBidRequest.sizes); const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest); requests.push(request); });