From 33762d1ee5abd0363e2b35fbbb07cb2d38287972 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 12 Sep 2019 16:38:12 -0700 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 aa489227a0878932cb75b58dac2998f730e122c0 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 11:44:24 -0700 Subject: [PATCH 6/8] import utils functions as needed and not the whole module --- modules/adriverBidAdapter.js | 26 ++++++------ modules/adtargetBidAdapter.js | 48 +++++++++++----------- modules/adtelligentBidAdapter.js | 58 +++++++++++++------------- modules/adtrueBidAdapter.js | 70 ++++++++++++++++---------------- modules/aduptechBidAdapter.js | 20 ++++----- 5 files changed, 111 insertions(+), 111 deletions(-) diff --git a/modules/adriverBidAdapter.js b/modules/adriverBidAdapter.js index d5a777f6111..67e039e4692 100644 --- a/modules/adriverBidAdapter.js +++ b/modules/adriverBidAdapter.js @@ -1,5 +1,5 @@ // ADRIVER BID ADAPTER for Prebid 1.13 -import * as utils from '../src/utils.js'; +import { logInfo, getWindowLocation, getBidIdParameter, _each } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'adriver'; @@ -21,12 +21,12 @@ export const spec = { }, buildRequests: function (validBidRequests, bidderRequest) { - utils.logInfo('validBidRequests', validBidRequests); + logInfo('validBidRequests', validBidRequests); - let win = utils.getWindowLocation(); + let win = getWindowLocation(); let customID = Math.round(Math.random() * 999999999) + '-' + Math.round(new Date() / 1000) + '-1-46-'; - let siteId = utils.getBidIdParameter('siteid', validBidRequests[0].params) + ''; - let currency = utils.getBidIdParameter('currency', validBidRequests[0].params); + let siteId = getBidIdParameter('siteid', validBidRequests[0].params) + ''; + let currency = getBidIdParameter('currency', validBidRequests[0].params); currency = 'RUB'; let timeout = null; @@ -58,8 +58,8 @@ export const spec = { 'imp': [] }; - utils._each(validBidRequests, (bid) => { - utils._each(bid.sizes, (sizes) => { + _each(validBidRequests, (bid) => { + _each(bid.sizes, (sizes) => { let width; let height; let par; @@ -67,7 +67,7 @@ export const spec = { let floorAndCurrency = _getFloor(bid, currency, sizes); let bidFloor = floorAndCurrency.floor; - let dealId = utils.getBidIdParameter('dealid', bid.params); + let dealId = getBidIdParameter('dealid', bid.params); if (typeof sizes[0] === 'number' && typeof sizes[1] === 'number') { width = sizes[0]; height = sizes[1]; @@ -93,7 +93,7 @@ export const spec = { }] }; } - utils.logInfo('par', par); + logInfo('par', par); payload.imp.push(par); }); }); @@ -108,11 +108,11 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { - utils.logInfo('serverResponse.body.seatbid', serverResponse.body.seatbid); + logInfo('serverResponse.body.seatbid', serverResponse.body.seatbid); const bidResponses = []; let nurl = 0; - utils._each(serverResponse.body.seatbid, (seatbid) => { - utils.logInfo('_each', seatbid); + _each(serverResponse.body.seatbid, (seatbid) => { + logInfo('_each', seatbid); var bid = seatbid.bid[0]; if (bid.nurl !== undefined) { nurl = bid.nurl.split('://'); @@ -135,7 +135,7 @@ export const spec = { }, ad: '' }; - utils.logInfo('bidResponse', bidResponse); + logInfo('bidResponse', bidResponse); bidResponses.push(bidResponse); } }); diff --git a/modules/adtargetBidAdapter.js b/modules/adtargetBidAdapter.js index 1779ba94371..0ad0177815a 100644 --- a/modules/adtargetBidAdapter.js +++ b/modules/adtargetBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, isArray, chunk, _map, flatten, logError, parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -13,7 +13,7 @@ export const spec = { code: BIDDER_CODE, supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - return !!utils.deepAccess(bid, 'params.aid'); + return !!deepAccess(bid, 'params.aid'); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -42,9 +42,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - utils.isArray(serverResponses) && serverResponses.forEach((response) => { + isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (utils.isArray(response.body)) { + if (isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -59,10 +59,10 @@ export const spec = { buildRequests: function (bidRequests, adapterRequest) { const adapterSettings = config.getConfig(adapterRequest.bidderCode) - const chunkSize = utils.deepAccess(adapterSettings, 'chunkSize', 10); + const chunkSize = deepAccess(adapterSettings, 'chunkSize', 10); const { tag, bids } = bidToTag(bidRequests, adapterRequest); - const bidChunks = utils.chunk(bids, chunkSize); - return utils._map(bidChunks, (bids) => { + const bidChunks = chunk(bids, chunkSize); + return _map(bidChunks, (bids) => { return { data: Object.assign({}, tag, { BidRequests: bids }), adapterRequest, @@ -75,12 +75,12 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!utils.isArray(serverResponse)) { + if (!isArray(serverResponse)) { return parseResponse(serverResponse, adapterRequest); } serverResponse.forEach(serverBidResponse => { - bids = utils.flatten(bids, parseResponse(serverBidResponse, adapterRequest)); + bids = flatten(bids, parseResponse(serverBidResponse, adapterRequest)); }); return bids; @@ -88,14 +88,14 @@ export const spec = { }; function parseResponse(serverResponse, adapterRequest) { - const isInvalidValidResp = !serverResponse || !utils.isArray(serverResponse.bids); + const isInvalidValidResp = !serverResponse || !isArray(serverResponse.bids); const bids = []; if (isInvalidValidResp) { const extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : ''; const errorMessage = `in response for ${adapterRequest.bidderCode} adapter ${extMessage}`; - utils.logError(errorMessage); + logError(errorMessage); return bids; } @@ -117,23 +117,23 @@ function parseResponse(serverResponse, adapterRequest) { function bidToTag(bidRequests, adapterRequest) { const tag = { - Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer') + Domain: deepAccess(adapterRequest, 'refererInfo.referer') }; if (config.getConfig('coppa') === true) { tag.Coppa = 1; } - if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { + if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { tag.GDPR = 1; - tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString'); + tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString'); } - if (utils.deepAccess(adapterRequest, 'uspConsent')) { - tag.USP = utils.deepAccess(adapterRequest, 'uspConsent'); + if (deepAccess(adapterRequest, 'uspConsent')) { + tag.USP = deepAccess(adapterRequest, 'uspConsent'); } - if (utils.deepAccess(bidRequests[0], 'schain')) { - tag.Schain = utils.deepAccess(bidRequests[0], 'schain'); + if (deepAccess(bidRequests[0], 'schain')) { + tag.Schain = deepAccess(bidRequests[0], 'schain'); } - if (utils.deepAccess(bidRequests[0], 'userId')) { - tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); + if (deepAccess(bidRequests[0], 'userId')) { + tag.UserIds = deepAccess(bidRequests[0], 'userId'); } const bids = [] @@ -147,19 +147,19 @@ function bidToTag(bidRequests, adapterRequest) { } function prepareBidRequests(bidReq) { - const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; - const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes'); + const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; + const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes'); const bidReqParams = { 'CallbackId': bidReq.bidId, 'Aid': bidReq.params.aid, 'AdType': mediaType, - 'Sizes': utils.parseSizesInput(sizes).join(',') + 'Sizes': parseSizesInput(sizes).join(',') }; return bidReqParams; } function getMediaType(bidderRequest) { - return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; + return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; } function createBid(bidResponse, bidRequest) { diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index e1c6dc1ca35..8523e01c0ea 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, isArray, chunk, _map, flatten, convertTypes, parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -44,7 +44,7 @@ export const spec = { ], supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - return !!utils.deepAccess(bid, 'params.aid'); + return !!deepAccess(bid, 'params.aid'); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -73,9 +73,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - utils.isArray(serverResponses) && serverResponses.forEach((response) => { + isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (utils.isArray(response.body)) { + if (isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -94,10 +94,10 @@ export const spec = { */ buildRequests: function (bidRequests, adapterRequest) { const adapterSettings = config.getConfig(adapterRequest.bidderCode) - const chunkSize = utils.deepAccess(adapterSettings, 'chunkSize', 10); + const chunkSize = deepAccess(adapterSettings, 'chunkSize', 10); const { tag, bids } = bidToTag(bidRequests, adapterRequest); - const bidChunks = utils.chunk(bids, chunkSize); - return utils._map(bidChunks, (bids) => { + const bidChunks = chunk(bids, chunkSize); + return _map(bidChunks, (bids) => { return { data: Object.assign({}, tag, { BidRequests: bids }), adapterRequest, @@ -117,26 +117,26 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!utils.isArray(serverResponse)) { + if (!isArray(serverResponse)) { return parseRTBResponse(serverResponse, adapterRequest); } serverResponse.forEach(serverBidResponse => { - bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); + bids = flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); }); return bids; }, transformBidParams(params) { - return utils.convertTypes({ + return convertTypes({ 'aid': 'number', }, params); } }; function parseRTBResponse(serverResponse, adapterRequest) { - const isEmptyResponse = !serverResponse || !utils.isArray(serverResponse.bids); + const isEmptyResponse = !serverResponse || !isArray(serverResponse.bids); const bids = []; if (isEmptyResponse) { @@ -161,26 +161,26 @@ function parseRTBResponse(serverResponse, adapterRequest) { function bidToTag(bidRequests, adapterRequest) { // start publisher env const tag = { - Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer') + Domain: deepAccess(adapterRequest, 'refererInfo.referer') }; if (config.getConfig('coppa') === true) { tag.Coppa = 1; } - if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { + if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { tag.GDPR = 1; - tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString'); + tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString'); } - if (utils.deepAccess(adapterRequest, 'uspConsent')) { - tag.USP = utils.deepAccess(adapterRequest, 'uspConsent'); + if (deepAccess(adapterRequest, 'uspConsent')) { + tag.USP = deepAccess(adapterRequest, 'uspConsent'); } - if (utils.deepAccess(bidRequests[0], 'schain')) { - tag.Schain = utils.deepAccess(bidRequests[0], 'schain'); + if (deepAccess(bidRequests[0], 'schain')) { + tag.Schain = deepAccess(bidRequests[0], 'schain'); } - if (utils.deepAccess(bidRequests[0], 'userId')) { - tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); + if (deepAccess(bidRequests[0], 'userId')) { + tag.UserIds = deepAccess(bidRequests[0], 'userId'); } - if (utils.deepAccess(bidRequests[0], 'userIdAsEids')) { - tag.UserEids = utils.deepAccess(bidRequests[0], 'userIdAsEids'); + if (deepAccess(bidRequests[0], 'userIdAsEids')) { + tag.UserEids = deepAccess(bidRequests[0], 'userIdAsEids'); } if (window.adtDmp && window.adtDmp.ready) { tag.DMPId = window.adtDmp.getUID(); @@ -203,13 +203,13 @@ function bidToTag(bidRequests, adapterRequest) { * @returns {object} */ function prepareBidRequests(bidReq) { - const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; - const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes'); + const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; + const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes'); const bidReqParams = { 'CallbackId': bidReq.bidId, 'Aid': bidReq.params.aid, 'AdType': mediaType, - 'Sizes': utils.parseSizesInput(sizes).join(',') + 'Sizes': parseSizesInput(sizes).join(',') }; bidReqParams.PlacementId = bidReq.adUnitCode; @@ -220,9 +220,9 @@ function prepareBidRequests(bidReq) { bidReqParams.PlacementId = bidReq.params.vpb_placement_id; } if (mediaType === VIDEO) { - const context = utils.deepAccess(bidReq, 'mediaTypes.video.context'); + const context = deepAccess(bidReq, 'mediaTypes.video.context'); if (context === ADPOD) { - bidReqParams.Adpod = utils.deepAccess(bidReq, 'mediaTypes.video'); + bidReqParams.Adpod = deepAccess(bidReq, 'mediaTypes.video'); } } return bidReqParams; @@ -234,7 +234,7 @@ function prepareBidRequests(bidReq) { * @returns {object} */ function getMediaType(bidderRequest) { - return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; + return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; } /** @@ -245,7 +245,7 @@ function getMediaType(bidderRequest) { */ function createBid(bidResponse, bidRequest) { const mediaType = getMediaType(bidRequest) - const context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); + const context = deepAccess(bidRequest, 'mediaTypes.video.context'); const bid = { requestId: bidResponse.requestId, creativeId: bidResponse.cmpId, diff --git a/modules/adtrueBidAdapter.js b/modules/adtrueBidAdapter.js index 96f1ceb12f0..df848fba823 100644 --- a/modules/adtrueBidAdapter.js +++ b/modules/adtrueBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { logWarn, isArray, inIframe, isNumber, isStr, deepClone, deepSetValue, logError, deepAccess, isBoolean } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; @@ -190,22 +190,22 @@ function _checkParamDataType(key, value, datatype) { var functionToExecute; switch (datatype) { case DATA_TYPES.BOOLEAN: - functionToExecute = utils.isBoolean; + functionToExecute = isBoolean; break; case DATA_TYPES.NUMBER: - functionToExecute = utils.isNumber; + functionToExecute = isNumber; break; case DATA_TYPES.STRING: - functionToExecute = utils.isStr; + functionToExecute = isStr; break; case DATA_TYPES.ARRAY: - functionToExecute = utils.isArray; + functionToExecute = isArray; break; } if (functionToExecute(value)) { return value; } - utils.logWarn(LOG_WARN_PREFIX + errMsg); + logWarn(LOG_WARN_PREFIX + errMsg); return UNDEFINED; } @@ -216,7 +216,7 @@ function _parseNativeResponse(bid, newBid) { try { adm = JSON.parse(bid.adm.replace(/\\/g, '')); } catch (ex) { - // utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); + // logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); return; } if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) { @@ -274,13 +274,13 @@ function _createBannerRequest(bid) { var sizes = bid.mediaTypes.banner.sizes; var format = []; var bannerObj; - if (sizes !== UNDEFINED && utils.isArray(sizes)) { + if (sizes !== UNDEFINED && isArray(sizes)) { bannerObj = {}; if (!bid.params.width && !bid.params.height) { if (sizes.length === 0) { // i.e. since bid.params does not have width or height, and length of sizes is 0, need to ignore this banner imp bannerObj = UNDEFINED; - utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); return bannerObj; } else { bannerObj.w = parseInt(sizes[0][0], 10); @@ -303,9 +303,9 @@ function _createBannerRequest(bid) { } } bannerObj.pos = 0; - bannerObj.topframe = utils.inIframe() ? 0 : 1; + bannerObj.topframe = inIframe() ? 0 : 1; } else { - utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); bannerObj = UNDEFINED; } return bannerObj; @@ -323,10 +323,10 @@ function _createVideoRequest(bid) { } } // read playersize and assign to h and w. - if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { + if (isArray(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0][0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[0][1], 10); - } else if (utils.isNumber(bid.mediaTypes.video.playerSize[0])) { + } else if (isNumber(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[1], 10); } @@ -337,7 +337,7 @@ function _createVideoRequest(bid) { } } else { videoObj = UNDEFINED; - utils.logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); + logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); } return videoObj; } @@ -355,7 +355,7 @@ function _checkMediaType(adm, newBid) { newBid.mediaType = NATIVE; } } catch (e) { - utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); + logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); } } } @@ -401,9 +401,9 @@ function _createImpressionObject(bid, conf) { pos: 0, w: bid.params.width, h: bid.params.height, - topframe: utils.inIframe() ? 0 : 1 + topframe: inIframe() ? 0 : 1 }; - if (utils.isArray(sizes) && sizes.length > 1) { + if (isArray(sizes) && sizes.length > 1) { sizes = sizes.splice(1, sizes.length - 1); sizes.forEach(size => { format.push({ @@ -428,19 +428,19 @@ export const spec = { isBidRequestValid: function (bid) { if (bid && bid.params) { if (!bid.params.zoneId) { - utils.logWarn(LOG_WARN_PREFIX + 'Error: missing zoneId'); + logWarn(LOG_WARN_PREFIX + 'Error: missing zoneId'); return false; } if (!bid.params.publisherId) { - utils.logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId'); + logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId'); return false; } - if (!utils.isStr(bid.params.publisherId)) { - utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric'); + if (!isStr(bid.params.publisherId)) { + logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric'); return false; } - if (!utils.isStr(bid.params.zoneId)) { - utils.logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric'); + if (!isStr(bid.params.zoneId)) { + logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric'); return false; } return true; @@ -458,7 +458,7 @@ export const spec = { let bidCurrency = ''; let bid; validBidRequests.forEach(originalBid => { - bid = utils.deepClone(originalBid); + bid = deepClone(originalBid); _parseAdSlot(bid); conf.zoneId = conf.zoneId || bid.params.zoneId; @@ -468,7 +468,7 @@ export const spec = { if (bidCurrency === '') { bidCurrency = bid.params.currency || UNDEFINED; } else if (bid.params.hasOwnProperty('currency') && bidCurrency !== bid.params.currency) { - utils.logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); + logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); } bid.params.currency = bidCurrency; @@ -502,28 +502,28 @@ export const spec = { if (typeof config.getConfig('device') === 'object') { payload.device = Object.assign(payload.device, config.getConfig('device')); } - utils.deepSetValue(payload, 'source.tid', conf.transactionId); + deepSetValue(payload, 'source.tid', conf.transactionId); // test bids if (window.location.href.indexOf('adtrueTest=true') !== -1) { payload.test = 1; } // adding schain object if (validBidRequests[0].schain) { - utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } // Attaching GDPR Consent Params if (bidderRequest && bidderRequest.gdprConsent) { - utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest && bidderRequest.uspConsent) { - utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // coppa compliance if (config.getConfig('coppa') === true) { - utils.deepSetValue(payload, 'regs.coppa', 1); + deepSetValue(payload, 'regs.coppa', 1); } return { @@ -539,12 +539,12 @@ export const spec = { let parsedRequest = JSON.parse(bidderRequest.data); let parsedReferrer = parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : ''; try { - if (serverResponses.body && serverResponses.body.seatbid && utils.isArray(serverResponses.body.seatbid)) { + if (serverResponses.body && serverResponses.body.seatbid && isArray(serverResponses.body.seatbid)) { // Supporting multiple bid responses for same adSize respCur = serverResponses.body.cur || respCur; serverResponses.body.seatbid.forEach(seatbidder => { seatbidder.bid && - utils.isArray(seatbidder.bid) && + isArray(seatbidder.bid) && seatbidder.bid.forEach(bid => { let newBid = { requestId: bid.impid, @@ -598,7 +598,7 @@ export const spec = { }); } } catch (error) { - utils.logError(error); + logError(error); } return bidResponses; }, @@ -607,7 +607,7 @@ export const spec = { return []; } return responses.reduce((accum, rsp) => { - let cookieSyncs = utils.deepAccess(rsp, 'body.ext.cookie_sync'); + let cookieSyncs = deepAccess(rsp, 'body.ext.cookie_sync'); if (cookieSyncs) { let cookieSyncObjects = cookieSyncs.map(cookieSync => { return { diff --git a/modules/aduptechBidAdapter.js b/modules/aduptechBidAdapter.js index b70f7cf3ce6..1186e0410ab 100644 --- a/modules/aduptechBidAdapter.js +++ b/modules/aduptechBidAdapter.js @@ -1,7 +1,7 @@ +import { deepAccess, getWindowTop, getWindowSelf, getAdUnitSizes } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js' -import * as utils from '../src/utils.js'; export const BIDDER_CODE = 'aduptech'; export const ENDPOINT_URL_PUBLISHER_PLACEHOLDER = '{PUBLISHER}'; @@ -37,7 +37,7 @@ export const internal = { * @returns {string} */ extractPageUrl: (bidderRequest) => { - if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl')) { + if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.canonicalUrl')) { return bidderRequest.refererInfo.canonicalUrl; } @@ -46,9 +46,9 @@ export const internal = { } try { - return utils.getWindowTop().location.href; + return getWindowTop().location.href; } catch (e) { - return utils.getWindowSelf().location.href; + return getWindowSelf().location.href; } }, @@ -59,14 +59,14 @@ export const internal = { * @returns {string} */ extractReferrer: (bidderRequest) => { - if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.referer')) { + if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } try { - return utils.getWindowTop().document.referrer; + return getWindowTop().document.referrer; } catch (e) { - return utils.getWindowSelf().document.referrer; + return getWindowSelf().document.referrer; } }, @@ -77,7 +77,7 @@ export const internal = { * @returns {null|Object.} */ extractBannerConfig: (bidRequest) => { - const sizes = utils.getAdUnitSizes(bidRequest); + const sizes = getAdUnitSizes(bidRequest); if (Array.isArray(sizes) && sizes.length > 0) { return { sizes: sizes }; } @@ -92,7 +92,7 @@ export const internal = { * @returns {null|Object.} */ extractNativeConfig: (bidRequest) => { - if (bidRequest && utils.deepAccess(bidRequest, 'mediaTypes.native')) { + if (bidRequest && deepAccess(bidRequest, 'mediaTypes.native')) { return bidRequest.mediaTypes.native; } @@ -267,7 +267,7 @@ export const spec = { const bidResponses = []; // stop here on invalid or empty data - if (!response || !utils.deepAccess(response, 'body.bids') || response.body.bids.length === 0) { + if (!response || !deepAccess(response, 'body.bids') || response.body.bids.length === 0) { return bidResponses; } From 85996a603cd22148d80c71c355fb178494117060 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 11:57:50 -0700 Subject: [PATCH 7/8] import utils functions as needed and not the whole module --- modules/adWMGBidAdapter.js | 8 +- modules/advangelistsBidAdapter.js | 28 +++---- modules/adxcgAnalyticsAdapter.js | 10 +-- modules/adxcgBidAdapter.js | 112 +++++++++++++------------- modules/adxpremiumAnalyticsAdapter.js | 34 ++++---- 5 files changed, 96 insertions(+), 96 deletions(-) diff --git a/modules/adWMGBidAdapter.js b/modules/adWMGBidAdapter.js index a3d78a69d91..7bf6c703a55 100644 --- a/modules/adWMGBidAdapter.js +++ b/modules/adWMGBidAdapter.js @@ -1,6 +1,6 @@ 'use strict'; -import * as utils from '../src/utils.js'; +import { tryAppendQueryString } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -128,11 +128,11 @@ export const spec = { }, getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { if (gdprConsent && SYNC_ENDPOINT.indexOf('gdpr') === -1) { - SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); } if (gdprConsent && typeof gdprConsent.consentString === 'string' && SYNC_ENDPOINT.indexOf('gdpr_consent') === -1) { - SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'gdpr_consent', gdprConsent.consentString); + SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'gdpr_consent', gdprConsent.consentString); } if (SYNC_ENDPOINT.slice(-1) === '&') { @@ -140,7 +140,7 @@ export const spec = { } /* if (uspConsent) { - SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'us_privacy', uspConsent); + SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'us_privacy', uspConsent); } */ let syncs = []; if (syncOptions.iframeEnabled) { diff --git a/modules/advangelistsBidAdapter.js b/modules/advangelistsBidAdapter.js index edf58fefd64..854c65b1f22 100755 --- a/modules/advangelistsBidAdapter.js +++ b/modules/advangelistsBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { isEmpty, deepAccess, isFn, parseSizesInput, generateUUID, parseUrl } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; @@ -56,7 +56,7 @@ export const spec = { interpretResponse(serverResponse, {bidRequest}) { let response = serverResponse.body; - if (response !== null && utils.isEmpty(response) == false) { + if (response !== null && isEmpty(response) == false) { if (isVideoBid(bidRequest)) { let bidResponse = { requestId: response.id, @@ -103,20 +103,20 @@ export const spec = { }; function isBannerBid(bid) { - return utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); + return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); } function isVideoBid(bid) { - return utils.deepAccess(bid, 'mediaTypes.video'); + return deepAccess(bid, 'mediaTypes.video'); } function getBannerBidFloor(bid) { - let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {}; + let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {}; return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); } function getVideoBidFloor(bid) { - let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'video', size: '*' }) : {}; + let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'video', size: '*' }) : {}; return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); } @@ -129,11 +129,11 @@ function isBannerBidValid(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 isMobile() { @@ -184,7 +184,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, @@ -194,11 +194,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 getTopWindowReferrer() { @@ -290,7 +290,7 @@ function createVideoRequestData(bid, bidderRequest) { 'bidfloorcur': 'USD', 'secure': secure, 'video': Object.assign({ - 'id': utils.generateUUID(), + 'id': generateUUID(), 'pos': 0, 'w': firstSize.w, 'h': firstSize.h, @@ -311,7 +311,7 @@ function createVideoRequestData(bid, bidderRequest) { 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 createBannerRequestData(bid, bidderRequest) { @@ -378,7 +378,7 @@ function createBannerRequestData(bid, bidderRequest) { 'bidfloorcur': 'USD', 'secure': secure, 'banner': { - 'id': utils.generateUUID(), + 'id': generateUUID(), 'pos': 0, 'w': size['w'], 'h': size['h'] diff --git a/modules/adxcgAnalyticsAdapter.js b/modules/adxcgAnalyticsAdapter.js index 9f514c545a1..5cd04ce13cd 100644 --- a/modules/adxcgAnalyticsAdapter.js +++ b/modules/adxcgAnalyticsAdapter.js @@ -1,8 +1,8 @@ +import { parseSizesInput, uniques, buildUrl, logError } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; -import * as utils from '../src/utils.js'; /** * Analytics adapter from adxcg.com @@ -32,7 +32,7 @@ var adxcgAnalyticsAdapter = Object.assign(adapter( case CONSTANTS.EVENTS.BID_ADJUSTMENT: break; case CONSTANTS.EVENTS.BID_TIMEOUT: - adxcgAnalyticsAdapter.context.events.bidTimeout = args.map(item => item.bidder).filter(utils.uniques); + adxcgAnalyticsAdapter.context.events.bidTimeout = args.map(item => item.bidder).filter(uniques); break; case CONSTANTS.EVENTS.BIDDER_DONE: break; @@ -67,7 +67,7 @@ function mapBidRequested (bidRequests) { adUnitCode: bid.adUnitCode, bidId: bid.bidId, start: bid.startTime, - sizes: utils.parseSizesInput(bid.sizes).toString(), + sizes: parseSizesInput(bid.sizes).toString(), params: bid.params }; }), @@ -112,7 +112,7 @@ function mapBidWon (bidResponse) { } function send (data) { - let adxcgAnalyticsRequestUrl = utils.buildUrl({ + let adxcgAnalyticsRequestUrl = buildUrl({ protocol: 'https', hostname: adxcgAnalyticsAdapter.context.host, pathname: '/pbrx/v2', @@ -143,7 +143,7 @@ adxcgAnalyticsAdapter.context = {}; adxcgAnalyticsAdapter.originEnableAnalytics = adxcgAnalyticsAdapter.enableAnalytics; adxcgAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.publisherId) { - utils.logError('PublisherId option is not defined. Analytics won\'t work'); + logError('PublisherId option is not defined. Analytics won\'t work'); return; } diff --git a/modules/adxcgBidAdapter.js b/modules/adxcgBidAdapter.js index e10eeaa3302..a02812a1608 100644 --- a/modules/adxcgBidAdapter.js +++ b/modules/adxcgBidAdapter.js @@ -1,5 +1,5 @@ +import { logWarn, isStr, deepAccess, inIframe, checkCookieSupport, timestamp, getBidIdParameter, parseSizesInput, buildUrl, logMessage, isArray, deepSetValue, isPlainObject, triggerPixel, replaceAuctionPrice, isFn } from '../src/utils.js'; import {config} from '../src/config.js' -import * as utils from '../src/utils.js' import {registerBidder} from '../src/adapters/bidderFactory.js' import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js' import includes from 'core-js-pure/features/array/includes.js' @@ -36,44 +36,44 @@ export const spec = { */ isBidRequestValid: function (bid) { if (!bid || !bid.params) { - utils.logWarn(BIDDER_CODE + ': Missing bid parameters'); + logWarn(BIDDER_CODE + ': Missing bid parameters'); return false } - if (!utils.isStr(bid.params.adzoneid)) { - utils.logWarn(BIDDER_CODE + ': adzoneid must be specified as a string'); + if (!isStr(bid.params.adzoneid)) { + logWarn(BIDDER_CODE + ': adzoneid must be specified as a string'); return false } if (isBannerRequest(bid)) { - const banneroAdUnit = utils.deepAccess(bid, 'mediaTypes.banner'); + const banneroAdUnit = deepAccess(bid, 'mediaTypes.banner'); if (!banneroAdUnit.sizes) { - utils.logWarn(BIDDER_CODE + ': banner sizes must be specified'); + logWarn(BIDDER_CODE + ': banner sizes must be specified'); return false; } } if (isVideoRequest(bid)) { // prebid 4.0 use standardized Video parameters - const videoAdUnit = utils.deepAccess(bid, 'mediaTypes.video'); + const videoAdUnit = deepAccess(bid, 'mediaTypes.video'); if (!Array.isArray(videoAdUnit.playerSize)) { - utils.logWarn(BIDDER_CODE + ': video playerSize must be an array of integers'); + logWarn(BIDDER_CODE + ': video playerSize must be an array of integers'); return false; } if (!videoAdUnit.context) { - utils.logWarn(BIDDER_CODE + ': video context must be specified'); + logWarn(BIDDER_CODE + ': video context must be specified'); return false; } if (!Array.isArray(videoAdUnit.mimes) || videoAdUnit.mimes.length === 0) { - utils.logWarn(BIDDER_CODE + ': video mimes must be an array of strings'); + logWarn(BIDDER_CODE + ': video mimes must be an array of strings'); return false; } if (!Array.isArray(videoAdUnit.protocols) || videoAdUnit.protocols.length === 0) { - utils.logWarn(BIDDER_CODE + ': video protocols must be an array of integers'); + logWarn(BIDDER_CODE + ': video protocols must be an array of integers'); return false; } } @@ -97,8 +97,8 @@ export const spec = { bt = Math.min(window.PREBID_TIMEOUT, bt); } - let referrer = utils.deepAccess(bidderRequest, 'refererInfo.referer'); - let page = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); + let referrer = deepAccess(bidderRequest, 'refererInfo.referer'); + let page = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href'); // add common parameters let beaconParams = { @@ -110,10 +110,10 @@ export const spec = { uh: window.screen.height, dpr: ratio, bt: bt, - isinframe: utils.inIframe(), - cookies: utils.checkCookieSupport() ? '1' : '0', + isinframe: inIframe(), + cookies: checkCookieSupport() ? '1' : '0', tz: dt.getTimezoneOffset(), - dt: utils.timestamp(), + dt: timestamp(), iob: iobavailable ? '1' : '0', pbjs: '$prebid.version$', rndid: Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000, @@ -126,19 +126,19 @@ export const spec = { beaconParams.gdpr_consent = bidderRequest.gdprConsent.consentString; } - if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.pubcid'))) { + if (isStr(deepAccess(validBidRequests, '0.userId.pubcid'))) { beaconParams.pubcid = validBidRequests[0].userId.pubcid; } - if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.tdid'))) { + if (isStr(deepAccess(validBidRequests, '0.userId.tdid'))) { beaconParams.tdid = validBidRequests[0].userId.tdid; } - if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.id5id.uid'))) { + if (isStr(deepAccess(validBidRequests, '0.userId.id5id.uid'))) { beaconParams.id5id = validBidRequests[0].userId.id5id.uid; } - if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.idl_env'))) { + if (isStr(deepAccess(validBidRequests, '0.userId.idl_env'))) { beaconParams.idl_env = validBidRequests[0].userId.idl_env; } @@ -156,14 +156,14 @@ export const spec = { let bidfloors = []; validBidRequests.forEach((bid, index) => { - adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params)); + adZoneIds.push(getBidIdParameter('adzoneid', bid.params)); prebidBidIds.push(bid.bidId); let bidfloor = getFloor(bid); bidfloors.push(bidfloor); // copy all custom parameters impression level parameters not supported above - let customBidParams = utils.getBidIdParameter('custom', bid.params) || {} + let customBidParams = getBidIdParameter('custom', bid.params) || {} if (customBidParams) { Object.keys(customBidParams) .filter(param => includes(USER_PARAMS_BID, param)) @@ -171,7 +171,7 @@ export const spec = { } if (isBannerRequest(bid)) { - sizes.push(utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('|')); + sizes.push(parseSizesInput(bid.mediaTypes.banner.sizes).join('|')); } if (isNativeRequest(bid)) { @@ -185,10 +185,10 @@ export const spec = { .forEach(param => beaconParams['video.' + param + '.' + index] = encodeURIComponent(bid.params.video[param])) } // copy video standarized params - beaconParams['video.context' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.context'); - sizes.push(utils.parseSizesInput(bid.mediaTypes.video.playerSize).join('|')); - beaconParams['video.mimes' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.mimes').join(','); - beaconParams['video.protocols' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.protocols').join(','); + beaconParams['video.context' + '.' + index] = deepAccess(bid, 'mediaTypes.video.context'); + sizes.push(parseSizesInput(bid.mediaTypes.video.playerSize).join('|')); + beaconParams['video.mimes' + '.' + index] = deepAccess(bid, 'mediaTypes.video.mimes').join(','); + beaconParams['video.protocols' + '.' + index] = deepAccess(bid, 'mediaTypes.video.protocols').join(','); } }) @@ -197,14 +197,14 @@ export const spec = { beaconParams.prebidBidIds = prebidBidIds.join(','); beaconParams.bidfloors = bidfloors.join(','); - let adxcgRequestUrl = utils.buildUrl({ + let adxcgRequestUrl = buildUrl({ protocol: 'https', hostname: 'hbps.adxcg.net', pathname: '/get/adi', search: beaconParams }); - utils.logMessage(`calling adi adxcg`); + logMessage(`calling adi adxcg`); return { contentType: 'text/plain', method: 'GET', @@ -220,11 +220,11 @@ export const spec = { */ interpretResponse: function (serverResponse) { - utils.logMessage(`interpretResponse adxcg`); + logMessage(`interpretResponse adxcg`); let bidsAll = []; - if (!serverResponse || !serverResponse.body || !utils.isArray(serverResponse.body.seatbid) || !serverResponse.body.seatbid.length) { - utils.logWarn(BIDDER_CODE + ': empty bid response'); + if (!serverResponse || !serverResponse.body || !isArray(serverResponse.body.seatbid) || !serverResponse.body.seatbid.length) { + logWarn(BIDDER_CODE + ': empty bid response'); return bidsAll; } @@ -256,28 +256,28 @@ export const spec = { bid.mediaType = 'native'; bid.native = parseNative(JSON.parse(serverResponseOneItem.adm)); } else { - utils.logWarn(BIDDER_CODE + ': unknown or undefined crType'); + logWarn(BIDDER_CODE + ': unknown or undefined crType'); } // prebid 4.0 meta taxonomy - if (utils.isArray(serverResponseOneItem.adomain)) { - utils.deepSetValue(bid, 'meta.advertiserDomains', serverResponseOneItem.adomain); + if (isArray(serverResponseOneItem.adomain)) { + deepSetValue(bid, 'meta.advertiserDomains', serverResponseOneItem.adomain); } - if (utils.isArray(serverResponseOneItem.cat)) { - utils.deepSetValue(bid, 'meta.secondaryCatIds', serverResponseOneItem.cat); + if (isArray(serverResponseOneItem.cat)) { + deepSetValue(bid, 'meta.secondaryCatIds', serverResponseOneItem.cat); } - if (utils.isPlainObject(serverResponseOneItem.ext)) { - if (utils.isStr(serverResponseOneItem.ext.advertiser_id)) { - utils.deepSetValue(bid, 'meta.mediaType', serverResponseOneItem.ext.mediaType); + if (isPlainObject(serverResponseOneItem.ext)) { + if (isStr(serverResponseOneItem.ext.advertiser_id)) { + deepSetValue(bid, 'meta.mediaType', serverResponseOneItem.ext.mediaType); } - if (utils.isStr(serverResponseOneItem.ext.advertiser_id)) { - utils.deepSetValue(bid, 'meta.advertiserId', serverResponseOneItem.ext.advertiser_id); + if (isStr(serverResponseOneItem.ext.advertiser_id)) { + deepSetValue(bid, 'meta.advertiserId', serverResponseOneItem.ext.advertiser_id); } - if (utils.isStr(serverResponseOneItem.ext.advertiser_name)) { - utils.deepSetValue(bid, 'meta.advertiserName', serverResponseOneItem.ext.advertiser_name); + if (isStr(serverResponseOneItem.ext.advertiser_name)) { + deepSetValue(bid, 'meta.advertiserName', serverResponseOneItem.ext.advertiser_name); } - if (utils.isStr(serverResponseOneItem.ext.agency_name)) { - utils.deepSetValue(bid, 'meta.agencyName', serverResponseOneItem.ext.agency_name); + if (isStr(serverResponseOneItem.ext.agency_name)) { + deepSetValue(bid, 'meta.agencyName', serverResponseOneItem.ext.agency_name); } } bidsAll.push(bid) @@ -288,7 +288,7 @@ export const spec = { onBidWon: (bid) => { if (bid.burl) { - utils.triggerPixel(utils.replaceAuctionPrice(bid.burl, bid.originalCpm)); + triggerPixel(replaceAuctionPrice(bid.burl, bid.originalCpm)); } }, @@ -304,14 +304,14 @@ export const spec = { cn: timeoutData.timeout, aud: timeoutData.auctionId, }; - let adxcgRequestUrl = utils.buildUrl({ + let adxcgRequestUrl = buildUrl({ protocol: 'https', hostname: 'hbps.adxcg.net', pathname: '/event/timeout.gif', search: beaconParams }); - utils.logWarn(BIDDER_CODE + ': onTimeout called'); - utils.triggerPixel(adxcgRequestUrl); + logWarn(BIDDER_CODE + ': onTimeout called'); + triggerPixel(adxcgRequestUrl); }, getUserSyncs: function (syncOptions, serverResponses, gdprConsent) { @@ -336,20 +336,20 @@ export const spec = { } function isVideoRequest(bid) { - return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video'); + return bid.mediaType === 'video' || !!deepAccess(bid, 'mediaTypes.video'); } function isBannerRequest(bid) { - return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner'); + return bid.mediaType === 'banner' || !!deepAccess(bid, 'mediaTypes.banner'); } function isNativeRequest(bid) { - return bid.mediaType === 'native' || !!utils.deepAccess(bid, 'mediaTypes.native'); + return bid.mediaType === 'native' || !!deepAccess(bid, 'mediaTypes.native'); } function getFloor(bid) { - if (!utils.isFn(bid.getFloor)) { - return utils.deepAccess(bid, 'params.floor', DEFAULT_MIN_FLOOR); + if (!isFn(bid.getFloor)) { + return deepAccess(bid, 'params.floor', DEFAULT_MIN_FLOOR); } try { @@ -361,7 +361,7 @@ function getFloor(bid) { }); return floor.floor; } catch (e) { - utils.logWarn(BIDDER_CODE + ': call to getFloor failed:' + e.message); + logWarn(BIDDER_CODE + ': call to getFloor failed:' + e.message); return DEFAULT_MIN_FLOOR; } } diff --git a/modules/adxpremiumAnalyticsAdapter.js b/modules/adxpremiumAnalyticsAdapter.js index f11e3b8d4e5..3e30de14052 100644 --- a/modules/adxpremiumAnalyticsAdapter.js +++ b/modules/adxpremiumAnalyticsAdapter.js @@ -1,8 +1,8 @@ +import { logError, logInfo, deepClone } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; -import * as utils from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const analyticsType = 'endpoint'; @@ -95,7 +95,7 @@ function auctionInit(args) { completeObject.auction_id = args.auctionId; completeObject.publisher_id = adxpremiumAnalyticsAdapter.initOptions.pubId; - try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.referer.split('?')[0]); } catch (e) { utils.logError('AdxPremium Analytics - ' + e.message); } + try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.referer.split('?')[0]); } catch (e) { logError('AdxPremium Analytics - ' + e.message); } if (args.adUnitCodes && args.adUnitCodes.length > 0) { elementIds = args.adUnitCodes; } @@ -140,20 +140,20 @@ function bidWon(args) { if (requestDelivered) { if (completeObject.events[eventIndex]) { // do the upgrade - utils.logInfo('AdxPremium Analytics - Upgrading request'); + logInfo('AdxPremium Analytics - Upgrading request'); completeObject.events[eventIndex].is_winning = true; completeObject.events[eventIndex].is_upgrade = true; - upgradedObject = utils.deepClone(completeObject); + upgradedObject = deepClone(completeObject); upgradedObject.events = [completeObject.events[eventIndex]]; sendEvent(upgradedObject); // send upgrade } else { - utils.logInfo('AdxPremium Analytics - CANNOT FIND INDEX FOR REQUEST ' + args.requestId); + logInfo('AdxPremium Analytics - CANNOT FIND INDEX FOR REQUEST ' + args.requestId); } } else { completeObject.events[eventIndex].is_winning = true; } } else { - utils.logInfo('AdxPremium Analytics - Response not found, creating new one.'); + logInfo('AdxPremium Analytics - Response not found, creating new one.'); let tmpObject = { type: 'RESPONSE', bidder_code: args.bidderCode, @@ -167,14 +167,14 @@ function bidWon(args) { is_winning: true, is_lost: true }; - let lostObject = utils.deepClone(completeObject); + let lostObject = deepClone(completeObject); lostObject.events = [tmpObject]; sendEvent(lostObject); // send lost object } } function bidTimeout(args) { - let timeoutObject = utils.deepClone(completeObject); + let timeoutObject = deepClone(completeObject); timeoutObject.events = []; let usedRequestIds = []; @@ -191,12 +191,12 @@ function bidTimeout(args) { if (timeoutObject.events.length > 0) { sendEvent(timeoutObject); // send timeouted - utils.logInfo('AdxPremium Analytics - Sending timeouted requests'); + logInfo('AdxPremium Analytics - Sending timeouted requests'); } } function auctionEnd(args) { - utils.logInfo('AdxPremium Analytics - Auction Ended at ' + Date.now()); + logInfo('AdxPremium Analytics - Auction Ended at ' + Date.now()); if (timeoutBased) { setTimeout(function () { requestSent = true; sendEvent(completeObject); }, 3500); } else { sendEventFallback(); } } @@ -212,22 +212,22 @@ function deviceType() { } function clearSlot(elementId) { - if (includes(elementIds, elementId)) { elementIds.splice(elementIds.indexOf(elementId), 1); utils.logInfo('AdxPremium Analytics - Done with: ' + elementId); } + if (includes(elementIds, elementId)) { elementIds.splice(elementIds.indexOf(elementId), 1); logInfo('AdxPremium Analytics - Done with: ' + elementId); } if (elementIds.length == 0 && !requestSent && !timeoutBased) { requestSent = true; sendEvent(completeObject); - utils.logInfo('AdxPremium Analytics - Everything ready'); + logInfo('AdxPremium Analytics - Everything ready'); } } export function testSend() { sendEvent(completeObject); - utils.logInfo('AdxPremium Analytics - Sending without any conditions, used for testing'); + logInfo('AdxPremium Analytics - Sending without any conditions, used for testing'); } function sendEventFallback() { setTimeout(function () { - if (!requestSent) { requestSent = true; sendEvent(completeObject); utils.logInfo('AdxPremium Analytics - Sending event using fallback method.'); } + if (!requestSent) { requestSent = true; sendEvent(completeObject); logInfo('AdxPremium Analytics - Sending event using fallback method.'); } }, 2000); } @@ -241,11 +241,11 @@ function sendEvent(completeObject) { if (adxpremiumAnalyticsAdapter.initOptions.sid) { ajaxEndpoint = 'https://' + adxpremiumAnalyticsAdapter.initOptions.sid + '.adxpremium.services/graphql' } - ajax(ajaxEndpoint, function () { utils.logInfo('AdxPremium Analytics - Sending complete events at ' + Date.now()) }, dataToSend, { + ajax(ajaxEndpoint, function () { logInfo('AdxPremium Analytics - Sending complete events at ' + Date.now()) }, dataToSend, { contentType: 'application/json', method: 'POST' }); - } catch (err) { utils.logError('AdxPremium Analytics - Sending event error: ' + err); } + } catch (err) { logError('AdxPremium Analytics - Sending event error: ' + err); } } // save the base class function @@ -256,7 +256,7 @@ adxpremiumAnalyticsAdapter.enableAnalytics = function (config) { adxpremiumAnalyticsAdapter.initOptions = config.options; if (!config.options.pubId) { - utils.logError('AdxPremium Analytics - Publisher ID (pubId) option is not defined. Analytics won\'t work'); + logError('AdxPremium Analytics - Publisher ID (pubId) option is not defined. Analytics won\'t work'); return; } From 4f7beb4b0ca718458fca7a173be33344bfd87124 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Fri, 24 Sep 2021 12:05:55 -0700 Subject: [PATCH 8/8] import utils functions as needed and not the whole module --- modules/adyoulikeBidAdapter.js | 22 +++++++++++----------- modules/ajaBidAdapter.js | 24 ++++++++++++------------ modules/akamaiDAPIdSystem.js | 18 +++++++++--------- modules/aniviewBidAdapter.js | 4 ++-- modules/aolBidAdapter.js | 26 +++++++++++++------------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 38731fdc91c..334309aec5c 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { deepAccess, buildUrl, parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import find from 'core-js-pure/features/array/find.js'; @@ -175,11 +175,11 @@ function getCanonicalUrl() { /* Get mediatype from bidRequest */ function getMediatype(bidRequest) { - if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { + if (deepAccess(bidRequest, 'mediaTypes.video')) { return VIDEO; - } else if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { + } else if (deepAccess(bidRequest, 'mediaTypes.banner')) { return BANNER; - } else if (utils.deepAccess(bidRequest, 'mediaTypes.native')) { + } else if (deepAccess(bidRequest, 'mediaTypes.native')) { return NATIVE; } } @@ -210,7 +210,7 @@ function getPageRefreshed() { /* Create endpoint url */ function createEndpoint(bidRequests, bidderRequest) { let host = getHostname(bidRequests); - return utils.buildUrl({ + return buildUrl({ protocol: 'https', host: `${DEFAULT_DC}${host}.omnitagjs.com`, pathname: '/hb-api/prebid/v1', @@ -260,7 +260,7 @@ function getSizeArray(bid) { } } - return utils.parseSizesInput(inputSize); + return parseSizesInput(inputSize); } /* Get parsed size from request size */ @@ -342,7 +342,7 @@ function getVideoAd(response) { var adJson = {}; if (typeof response.Ad === 'string') { adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); - return utils.deepAccess(adJson, 'Content.MainVideo.Vast'); + return deepAccess(adJson, 'Content.MainVideo.Vast'); } } @@ -404,7 +404,7 @@ function getNativeAssets(response, nativeConfig) { imgSize[1] = response.Height || 250; } - const url = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Thumbnail.Image'), imgSize[0], imgSize[1]); + const url = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Thumbnail.Image'), imgSize[0], imgSize[1]); if (url) { native[key] = { url, @@ -422,7 +422,7 @@ function getNativeAssets(response, nativeConfig) { iconSize[1] = 50; } - const icurl = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Sponsor.Logo.Resource'), iconSize[0], iconSize[1]); + const icurl = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Sponsor.Logo.Resource'), iconSize[0], iconSize[1]); if (url) { native[key] = { @@ -433,10 +433,10 @@ function getNativeAssets(response, nativeConfig) { } break; case 'privacyIcon': - native[key] = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Credit.Logo.Resource'), 25, 25); + native[key] = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Credit.Logo.Resource'), 25, 25); break; case 'privacyLink': - native[key] = utils.deepAccess(adJson, 'Content.Preview.Credit.Url'); + native[key] = deepAccess(adJson, 'Content.Preview.Credit.Url'); break; } }); diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index f7a9bfe5793..a9364a7a05f 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -1,5 +1,5 @@ +import { getBidIdParameter, tryAppendQueryString, createTrackPixelHtml, logError, logWarn } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; -import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'; @@ -42,20 +42,20 @@ export const spec = { const bidRequest = validBidRequests[i]; let queryString = ''; - const asi = utils.getBidIdParameter('asi', bidRequest.params); - queryString = utils.tryAppendQueryString(queryString, 'asi', asi); - queryString = utils.tryAppendQueryString(queryString, 'skt', SDK_TYPE); - queryString = utils.tryAppendQueryString(queryString, 'tid', bidRequest.transactionId) - queryString = utils.tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId); - queryString = utils.tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$'); + const asi = getBidIdParameter('asi', bidRequest.params); + queryString = tryAppendQueryString(queryString, 'asi', asi); + queryString = tryAppendQueryString(queryString, 'skt', SDK_TYPE); + queryString = tryAppendQueryString(queryString, 'tid', bidRequest.transactionId) + queryString = tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId); + queryString = tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$'); if (pageUrl) { - queryString = utils.tryAppendQueryString(queryString, 'page_url', pageUrl); + queryString = tryAppendQueryString(queryString, 'page_url', pageUrl); } const eids = bidRequest.userIdAsEids; if (eids && eids.length) { - queryString = utils.tryAppendQueryString(queryString, 'eids', JSON.stringify({ + queryString = tryAppendQueryString(queryString, 'eids', JSON.stringify({ 'eids': eids, })) } @@ -114,11 +114,11 @@ export const spec = { }); try { bannerAd.imps.forEach(impTracker => { - const tracker = utils.createTrackPixelHtml(impTracker); + const tracker = createTrackPixelHtml(impTracker); bid.ad += tracker; }); } catch (error) { - utils.logError('Error appending tracking pixel', error); + logError('Error appending tracking pixel', error); } Array.prototype.push.apply(bid.meta.advertiserDomains, bannerAd.adomain) @@ -207,7 +207,7 @@ function newRenderer(bidderResponse) { try { renderer.setRender(outstreamRender); } catch (err) { - utils.logWarn('Prebid Error calling setRender on newRenderer', err); + logWarn('Prebid Error calling setRender on newRenderer', err); } return renderer; diff --git a/modules/akamaiDAPIdSystem.js b/modules/akamaiDAPIdSystem.js index a78d65b40a9..5e3a607d5fd 100644 --- a/modules/akamaiDAPIdSystem.js +++ b/modules/akamaiDAPIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import * as utils from '../src/utils.js' +import { logMessage, logError } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -29,7 +29,7 @@ export const akamaiDAPIdSubmodule = { * @returns {{dapId:string}} */ decode(value) { - utils.logMessage('akamaiDAPId [decode] value=', value); + logMessage('akamaiDAPId [decode] value=', value); return { dapId: value }; }, @@ -43,23 +43,23 @@ export const akamaiDAPIdSubmodule = { getId(config, consentData) { const configParams = (config && config.params); if (!configParams) { - utils.logError('User ID - akamaiDAPId submodule requires a valid configParams'); + logError('User ID - akamaiDAPId submodule requires a valid configParams'); return; } else if (typeof configParams.apiHostname !== 'string') { - utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.apiHostname'); + logError('User ID - akamaiDAPId submodule requires a valid configParams.apiHostname'); return; } else if (typeof configParams.domain !== 'string') { - utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.domain'); + logError('User ID - akamaiDAPId submodule requires a valid configParams.domain'); return; } else if (typeof configParams.type !== 'string') { - utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.type'); + logError('User ID - akamaiDAPId submodule requires a valid configParams.type'); return; } const hasGdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const gdprConsentString = hasGdpr ? consentData.consentString : ''; const uspConsent = uspDataHandler.getConsentData(); if (hasGdpr && (!gdprConsentString || gdprConsentString === '')) { - utils.logError('User ID - akamaiDAPId submodule requires consent string to call API'); + logError('User ID - akamaiDAPId submodule requires consent string to call API'); return; } // XXX: retrieve first-party data here if needed @@ -99,14 +99,14 @@ export const akamaiDAPIdSubmodule = { storage.setDataInLocalStorage(STORAGE_KEY, token); }, error: error => { - utils.logError('akamaiDAPId [getId:ajax.error] failed to retrieve ' + tokenName, error); + logError('akamaiDAPId [getId:ajax.error] failed to retrieve ' + tokenName, error); } }; ajax(url, cb, JSON.stringify(postData), { contentType: 'application/json' }); let token = storage.getDataFromLocalStorage(STORAGE_KEY); - utils.logMessage('akamaiDAPId [getId] returning', token); + logMessage('akamaiDAPId [getId] returning', token); return { id: token }; } diff --git a/modules/aniviewBidAdapter.js b/modules/aniviewBidAdapter.js index 83a1ab20bb4..96bdf153e3f 100644 --- a/modules/aniviewBidAdapter.js +++ b/modules/aniviewBidAdapter.js @@ -1,7 +1,7 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; -import * as utils from '../src/utils.js'; +import { logError } from '../src/utils.js'; const BIDDER_CODE = 'aniview'; const GVLID = 780; @@ -224,7 +224,7 @@ function interpretResponse(serverResponse, bidRequest) { }); bidResponse.vastUrl = window.URL.createObjectURL(blob); } catch (ex) { - utils.logError('Aniview Debug create vastXml error:\n\n' + ex); + logError('Aniview Debug create vastXml error:\n\n' + ex); } bidResponse.vastXml = xmlStr; if (bidRequest.bidRequest && bidRequest.bidRequest.mediaTypes && bidRequest.bidRequest.mediaTypes.video && bidRequest.bidRequest.mediaTypes.video.context === 'outstream') { diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js index 4ab6f53ebdc..7203439059b 100644 --- a/modules/aolBidAdapter.js +++ b/modules/aolBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import { isInteger, logError, isEmpty, logWarn, getUniqueIdentifierStr, _each, deepSetValue } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -64,7 +64,7 @@ function template(strings, ...keys) { let dict = values[values.length - 1] || {}; let result = [strings[0]]; keys.forEach(function (key, i) { - let value = utils.isInteger(key) ? values[key] : dict[key]; + let value = isInteger(key) ? values[key] : dict[key]; result.push(value, strings[i + 1]); }); return result.join(''); @@ -147,7 +147,7 @@ export const spec = { }, interpretResponse({ body }, bidRequest) { if (!body) { - utils.logError('Empty bid response', bidRequest.bidderCode, body); + logError('Empty bid response', bidRequest.bidderCode, body); } else { let bid = this._parseBidResponse(body, bidRequest); @@ -157,7 +157,7 @@ export const spec = { } }, getUserSyncs(options, serverResponses) { - const bidResponse = !utils.isEmpty(serverResponses) && serverResponses[0].body; + const bidResponse = !isEmpty(serverResponses) && serverResponses[0].body; if (bidResponse && bidResponse.ext && bidResponse.ext.pixels) { return this.parsePixelItems(bidResponse.ext.pixels); @@ -215,7 +215,7 @@ export const spec = { let server; if (!MP_SERVER_MAP.hasOwnProperty(regionParam)) { - utils.logWarn(`Unknown region '${regionParam}' for AOL bidder.`); + logWarn(`Unknown region '${regionParam}' for AOL bidder.`); regionParam = 'us'; // Default region. } @@ -234,7 +234,7 @@ export const spec = { placement: parseInt(params.placement), pageid: params.pageId || 0, sizeid: params.sizeId || 0, - alias: params.alias || utils.getUniqueIdentifierStr(), + alias: params.alias || getUniqueIdentifierStr(), misc: new Date().getTime(), // cache busting dynamicParams: this.formatMarketplaceDynamicParams(params, consentData) })); @@ -273,7 +273,7 @@ export const spec = { Object.assign(queryParams, this.formatConsentData(consentData)); let paramsFormatted = ''; - utils._each(queryParams, (value, key) => { + _each(queryParams, (value, key) => { paramsFormatted += `${key}=${encodeURIComponent(value)};`; }); @@ -287,7 +287,7 @@ export const spec = { Object.assign(params, this.formatConsentData(consentData)); let paramsFormatted = ''; - utils._each(params, (value, key) => { + _each(params, (value, key) => { paramsFormatted += `&${key}=${encodeURIComponent(value)}`; }); @@ -300,14 +300,14 @@ export const spec = { }; if (this.isEUConsentRequired(consentData)) { - utils.deepSetValue(openRtbObject, 'regs.ext.gdpr', NUMERIC_VALUES.TRUE); + deepSetValue(openRtbObject, 'regs.ext.gdpr', NUMERIC_VALUES.TRUE); if (consentData.gdpr.consentString) { - utils.deepSetValue(openRtbObject, 'user.ext.consent', consentData.gdpr.consentString); + deepSetValue(openRtbObject, 'user.ext.consent', consentData.gdpr.consentString); } } if (consentData.uspConsent) { - utils.deepSetValue(openRtbObject, 'regs.ext.us_privacy', consentData.uspConsent); + deepSetValue(openRtbObject, 'regs.ext.us_privacy', consentData.uspConsent); } if (typeof bid.userId === 'object') { @@ -328,7 +328,7 @@ export const spec = { formatKeyValues(keyValues) { let keyValuesHash = {}; - utils._each(keyValues, (value, key) => { + _each(keyValues, (value, key) => { keyValuesHash[`kv${key}`] = value; }); @@ -394,7 +394,7 @@ export const spec = { cpm = bidData.price; if (cpm === null || isNaN(cpm)) { - utils.logError('Invalid price in bid response', AOL_BIDDERS_CODES.AOL, bidData); + logError('Invalid price in bid response', AOL_BIDDERS_CODES.AOL, bidData); return; } }