From 33762d1ee5abd0363e2b35fbbb07cb2d38287972 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 12 Sep 2019 16:38:12 -0700 Subject: [PATCH 01/10] 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/10] 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/10] 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/10] 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/10] 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 af8d06779f9758c987b030c80dd0340bd93e5077 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 23 Sep 2021 14:12:21 -0700 Subject: [PATCH 06/10] validationFPDModule: import only what is needed from utils --- modules/validationFpdModule/index.js | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/validationFpdModule/index.js b/modules/validationFpdModule/index.js index a1d1a3823f0..2db170c1bd1 100644 --- a/modules/validationFpdModule/index.js +++ b/modules/validationFpdModule/index.js @@ -3,7 +3,7 @@ * @module modules/firstPartyData */ import { config } from '../../src/config.js'; -import * as utils from '../../src/utils.js'; +import { isEmpty, isNumber, logWarn, deepAccess } from '../../src/utils.js'; import { ORTB_MAP } from './config.js'; import { submodule } from '../../src/hook.js'; import { getStorageManager } from '../../src/storageManager.js'; @@ -19,9 +19,9 @@ let optout; function isEmptyData(data) { let check = true; - if (typeof data === 'object' && !utils.isEmpty(data)) { + if (typeof data === 'object' && !isEmpty(data)) { check = false; - } else if (typeof data !== 'object' && (utils.isNumber(data) || data)) { + } else if (typeof data !== 'object' && (isNumber(data) || data)) { check = false; } @@ -42,7 +42,7 @@ function getRequiredData(obj, required, parent, i) { required.forEach(key => { if (!obj[key] || isEmptyData(obj[key])) { check = false; - utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: missing required property ${key}`); + logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: missing required property ${key}`); } }); @@ -91,17 +91,17 @@ export function filterArrayData(arr, child, path, parent) { return true; } - utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); + logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); }).filter((index, i) => { let requiredCheck = true; - let mapping = utils.deepAccess(ORTB_MAP, path); + let mapping = deepAccess(ORTB_MAP, path); if (mapping && mapping.required) requiredCheck = getRequiredData(index, mapping.required, parent, i); if (requiredCheck) return true; }).reduce((result, value, i) => { let typeBool = false; - let mapping = utils.deepAccess(ORTB_MAP, path); + let mapping = deepAccess(ORTB_MAP, path); switch (child.type) { case 'string': @@ -126,7 +126,7 @@ export function filterArrayData(arr, child, path, parent) { break; } - if (!typeBool) utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); + if (!typeBool) logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); return result; }, []); @@ -146,26 +146,26 @@ export function validateFpd(fpd, path = '', parent = '') { // Filter out imp property if exists let validObject = Object.assign({}, Object.keys(fpd).filter(key => { - let mapping = utils.deepAccess(ORTB_MAP, path + key); + let mapping = deepAccess(ORTB_MAP, path + key); if (!mapping || !mapping.invalid) return key; - utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: invalid property`); + logWarn(`Filtered ${parent}${key} property in ortb2 data: invalid property`); }).filter(key => { - let mapping = utils.deepAccess(ORTB_MAP, path + key); + let mapping = deepAccess(ORTB_MAP, path + key); // let typeBool = false; let typeBool = (mapping) ? typeValidation(fpd[key], {type: mapping.type, isArray: mapping.isArray}) : true; if (typeBool || !mapping) return key; - utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: expected type ${(mapping.isArray) ? 'array' : mapping.type}`); + logWarn(`Filtered ${parent}${key} property in ortb2 data: expected type ${(mapping.isArray) ? 'array' : mapping.type}`); }).reduce((result, key) => { - let mapping = utils.deepAccess(ORTB_MAP, path + key); + let mapping = deepAccess(ORTB_MAP, path + key); let modified = {}; if (mapping) { if (mapping.optoutApplies && optout) { - utils.logWarn(`Filtered ${parent}${key} data: pubcid optout found`); + logWarn(`Filtered ${parent}${key} data: pubcid optout found`); return result; } @@ -176,7 +176,7 @@ export function validateFpd(fpd, path = '', parent = '') { // Check if modified data has data and return (!isEmptyData(modified)) ? result[key] = modified - : utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: empty data found`); + : logWarn(`Filtered ${parent}${key} property in ortb2 data: empty data found`); } else { result[key] = fpd[key]; } From 864ace546fe63dcd40440e49e766e403699941e8 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 23 Sep 2021 14:28:28 -0700 Subject: [PATCH 07/10] userIdModule: import only what is needed from utils --- modules/userId/eids.js | 18 +++++------ modules/userId/index.js | 72 +++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/modules/userId/eids.js b/modules/userId/eids.js index 0a8e94883b4..0f159c4f33b 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -1,4 +1,4 @@ -import * as utils from '../../src/utils.js'; +import { pick, isFn, isStr, isPlainObject, deepAccess } from '../../src/utils.js'; // Each user-id sub-module is expected to mention respective config here const USER_IDS_CONFIG = { @@ -64,7 +64,7 @@ const USER_IDS_CONFIG = { return null; }, getUidExt: function(parrableId) { - const extendedData = utils.pick(parrableId, [ + const extendedData = pick(parrableId, [ 'ibaOptout', 'ccpaOptout' ]); @@ -248,11 +248,11 @@ function createEidObject(userIdData, subModuleKey) { if (conf && userIdData) { let eid = {}; eid.source = conf['source']; - const value = utils.isFn(conf['getValue']) ? conf['getValue'](userIdData) : userIdData; - if (utils.isStr(value)) { + const value = isFn(conf['getValue']) ? conf['getValue'](userIdData) : userIdData; + if (isStr(value)) { const uid = { id: value, atype: conf['atype'] }; // getUidExt - if (utils.isFn(conf['getUidExt'])) { + if (isFn(conf['getUidExt'])) { const uidExt = conf['getUidExt'](userIdData); if (uidExt) { uid.ext = uidExt; @@ -260,7 +260,7 @@ function createEidObject(userIdData, subModuleKey) { } eid.uids = [uid]; // getEidExt - if (utils.isFn(conf['getEidExt'])) { + if (isFn(conf['getEidExt'])) { const eidExt = conf['getEidExt'](userIdData); if (eidExt) { eid.ext = eidExt; @@ -297,11 +297,11 @@ export function createEidsArray(bidRequestUserId) { */ export function buildEidPermissions(submodules) { let eidPermissions = []; - submodules.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length) + submodules.filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length) .forEach(i => { Object.keys(i.idObj).forEach(key => { - if (utils.deepAccess(i, 'config.bidders') && Array.isArray(i.config.bidders) && - utils.deepAccess(USER_IDS_CONFIG, key + '.source')) { + if (deepAccess(i, 'config.bidders') && Array.isArray(i.config.bidders) && + deepAccess(USER_IDS_CONFIG, key + '.source')) { eidPermissions.push( { source: USER_IDS_CONFIG[key].source, diff --git a/modules/userId/index.js b/modules/userId/index.js index a6a824fe89e..b0293a9c26a 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -133,14 +133,16 @@ import find from 'core-js-pure/features/array/find.js'; import { config } from '../../src/config.js'; import events from '../../src/events.js'; -import * as utils from '../../src/utils.js'; import { getGlobal } from '../../src/prebidGlobal.js'; import { gdprDataHandler } from '../../src/adapterManager.js'; import CONSTANTS from '../../src/constants.json'; import { module, hook } from '../../src/hook.js'; import { createEidsArray, buildEidPermissions } from './eids.js'; import { getCoreStorageManager } from '../../src/storageManager.js'; -import {getPrebidInternal} from '../../src/utils.js'; +import { + getPrebidInternal, isPlainObject, logError, isArray, cyrb53Hash, deepAccess, timestamp, delayExecution, logInfo, isFn, + logWarn, isEmptyStr, isNumber +} from '../../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const MODULE_NAME = 'User ID'; @@ -199,7 +201,7 @@ export function setStoredValue(submodule, value) { const domainOverride = (typeof submodule.submodule.domainOverride === 'function') ? submodule.submodule.domainOverride() : null; try { - const valueStr = utils.isPlainObject(value) ? JSON.stringify(value) : value; + const valueStr = isPlainObject(value) ? JSON.stringify(value) : value; const expiresStr = (new Date(Date.now() + (storage.expires * (60 * 60 * 24 * 1000)))).toUTCString(); if (storage.type === COOKIE) { coreStorage.setCookie(storage.name, valueStr, expiresStr, 'Lax', domainOverride); @@ -214,13 +216,13 @@ export function setStoredValue(submodule, value) { } } } catch (error) { - utils.logError(error); + logError(error); } } function setPrebidServerEidPermissions(initializedSubmodules) { let setEidPermissions = getPrebidInternal().setEidPermissions; - if (typeof setEidPermissions === 'function' && utils.isArray(initializedSubmodules)) { + if (typeof setEidPermissions === 'function' && isArray(initializedSubmodules)) { setEidPermissions(buildEidPermissions(initializedSubmodules)); } } @@ -253,7 +255,7 @@ function getStoredValue(storage, key = undefined) { storedValue = JSON.parse(storedValue); } } catch (e) { - utils.logError(e); + logError(e); } return storedValue; } @@ -278,7 +280,7 @@ function makeStoredConsentDataHash(consentData) { storedConsentData.apiVersion = consentData.apiVersion; } - return utils.cyrb53Hash(JSON.stringify(storedConsentData)); + return cyrb53Hash(JSON.stringify(storedConsentData)); } /** @@ -290,7 +292,7 @@ export function setStoredConsentData(consentData) { const expiresStr = (new Date(Date.now() + (CONSENT_DATA_COOKIE_STORAGE_CONFIG.expires * (60 * 60 * 24 * 1000)))).toUTCString(); coreStorage.setCookie(CONSENT_DATA_COOKIE_STORAGE_CONFIG.name, makeStoredConsentDataHash(consentData), expiresStr, 'Lax'); } catch (error) { - utils.logError(error); + logError(error); } } @@ -302,7 +304,7 @@ function getStoredConsentData() { try { return coreStorage.getCookie(CONSENT_DATA_COOKIE_STORAGE_CONFIG.name); } catch (e) { - utils.logError(e); + logError(e); } } @@ -332,10 +334,10 @@ function hasGDPRConsent(consentData) { if (!consentData.consentString) { return false; } - if (consentData.apiVersion === 1 && utils.deepAccess(consentData, 'vendorData.purposeConsents.1') === false) { + if (consentData.apiVersion === 1 && deepAccess(consentData, 'vendorData.purposeConsents.1') === false) { return false; } - if (consentData.apiVersion === 2 && utils.deepAccess(consentData, 'vendorData.purpose.consents.1') === false) { + if (consentData.apiVersion === 2 && deepAccess(consentData, 'vendorData.purpose.consents.1') === false) { return false; } } @@ -363,7 +365,7 @@ export function findRootDomain(fullDomain = window.location.hostname) { const TEST_COOKIE_VALUE = 'writeable'; do { rootDomain = domainParts.slice(startIndex).join('.'); - let expirationDate = new Date(utils.timestamp() + 10 * 1000).toUTCString(); + let expirationDate = new Date(timestamp() + 10 * 1000).toUTCString(); // Write a test cookie coreStorage.setCookie( @@ -403,7 +405,7 @@ export function findRootDomain(fullDomain = window.location.hostname) { function processSubmoduleCallbacks(submodules, cb) { let done = () => {}; if (cb) { - done = utils.delayExecution(() => { + done = delayExecution(() => { clearTimeout(timeoutID); cb(); }, submodules.length); @@ -418,7 +420,7 @@ function processSubmoduleCallbacks(submodules, cb) { // cache decoded value (this is copied to every adUnit bid) submodule.idObj = submodule.submodule.decode(idObj, submodule.config); } else { - utils.logInfo(`${MODULE_NAME}: ${submodule.submodule.name} - request id responded with an empty value`); + logInfo(`${MODULE_NAME}: ${submodule.submodule.name} - request id responded with an empty value`); } done(); }); @@ -436,7 +438,7 @@ function getCombinedSubmoduleIds(submodules) { if (!Array.isArray(submodules) || !submodules.length) { return {}; } - const combinedSubmoduleIds = submodules.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length).reduce((carry, i) => { + const combinedSubmoduleIds = submodules.filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length).reduce((carry, i) => { Object.keys(i.idObj).forEach(key => { carry[key] = i.idObj[key]; }); @@ -456,8 +458,8 @@ function getCombinedSubmoduleIdsForBidder(submodules, bidder) { return {}; } return submodules - .filter(i => !i.config.bidders || !utils.isArray(i.config.bidders) || includes(i.config.bidders, bidder)) - .filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length) + .filter(i => !i.config.bidders || !isArray(i.config.bidders) || includes(i.config.bidders, bidder)) + .filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length) .reduce((carry, i) => { Object.keys(i.idObj).forEach(key => { carry[key] = i.idObj[key]; @@ -475,7 +477,7 @@ function addIdDataToAdUnitBids(adUnits, submodules) { return; } adUnits.forEach(adUnit => { - if (adUnit.bids && utils.isArray(adUnit.bids)) { + if (adUnit.bids && isArray(adUnit.bids)) { adUnit.bids.forEach(bid => { const combinedSubmoduleIds = getCombinedSubmoduleIdsForBidder(submodules, bid.bidder); if (Object.keys(combinedSubmoduleIds).length) { @@ -500,7 +502,7 @@ function initializeSubmodulesAndExecuteCallbacks(continueAuction) { if (initializedSubmodules.length) { setPrebidServerEidPermissions(initializedSubmodules); // list of submodules that have callbacks that need to be executed - const submodulesWithCallbacks = initializedSubmodules.filter(item => utils.isFn(item.callback)); + const submodulesWithCallbacks = initializedSubmodules.filter(item => isFn(item.callback)); if (submodulesWithCallbacks.length) { if (continueAuction && auctionDelay > 0) { @@ -513,7 +515,7 @@ function initializeSubmodulesAndExecuteCallbacks(continueAuction) { continueAuction(); } } - utils.logInfo(`${MODULE_NAME} - auction delayed by ${auctionDelay} at most to fetch ids`); + logInfo(`${MODULE_NAME} - auction delayed by ${auctionDelay} at most to fetch ids`); timeoutID = setTimeout(continueCallback, auctionDelay); processSubmoduleCallbacks(submodulesWithCallbacks, continueCallback); @@ -596,7 +598,7 @@ function refreshUserIds(options, callback) { // gdpr consent with purpose one is required, otherwise exit immediately let {userIdModules, hasValidated} = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { - utils.logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); + logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); return; } @@ -611,7 +613,7 @@ function refreshUserIds(options, callback) { continue; } - utils.logInfo(`${MODULE_NAME} - refreshing ${submodule.submodule.name}`); + logInfo(`${MODULE_NAME} - refreshing ${submodule.submodule.name}`); populateSubmoduleId(submodule, consentData, storedConsentData, true); updateInitializedSubmodules(submodule); @@ -619,7 +621,7 @@ function refreshUserIds(options, callback) { setPrebidServerEidPermissions(initializedSubmodules); } - if (utils.isFn(submodule.callback)) { + if (isFn(submodule.callback)) { callbackSubmodules.push(submodule); } } @@ -663,7 +665,7 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef response = submodule.submodule.extendId(submodule.config, consentData, storedId); } - if (utils.isPlainObject(response)) { + if (isPlainObject(response)) { if (response.id) { // A getId/extendId result assumed to be valid user id data, which should be saved to users local storage or cookies setStoredValue(submodule, response.id); @@ -685,7 +687,7 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef submodule.idObj = submodule.config.value; } else { const response = submodule.submodule.getId(submodule.config, consentData, undefined); - if (utils.isPlainObject(response)) { + if (isPlainObject(response)) { if (typeof response.callback === 'function') { submodule.callback = response.callback; } if (response.id) { submodule.idObj = submodule.submodule.decode(response.id, submodule.config); } } @@ -701,7 +703,7 @@ function initSubmodules(submodules, consentData) { // gdpr consent with purpose one is required, otherwise exit immediately let { userIdModules, hasValidated } = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { - utils.logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); + logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); return []; } @@ -746,17 +748,17 @@ function getValidSubmoduleConfigs(configRegistry, submoduleRegistry, activeStora } return configRegistry.reduce((carry, config) => { // every submodule config obj must contain a valid 'name' - if (!config || utils.isEmptyStr(config.name)) { + if (!config || isEmptyStr(config.name)) { return carry; } // Validate storage config contains 'type' and 'name' properties with non-empty string values // 'type' must be a value currently enabled in the browser if (config.storage && - !utils.isEmptyStr(config.storage.type) && - !utils.isEmptyStr(config.storage.name) && + !isEmptyStr(config.storage.type) && + !isEmptyStr(config.storage.name) && activeStorageTypes.indexOf(config.storage.type) !== -1) { carry.push(config); - } else if (utils.isPlainObject(config.value)) { + } else if (isPlainObject(config.value)) { carry.push(config); } else if (!config.storage && !config.value) { carry.push(config); @@ -793,7 +795,7 @@ function updateSubmodules() { if (!addedUserIdHook && submodules.length) { // priority value 40 will load after consentManagement with a priority of 50 getGlobal().requestBids.before(requestBidsHook, 40); - utils.logInfo(`${MODULE_NAME} - usersync config updated for ${submodules.length} submodules: `, submodules.map(a => a.submodule.name)); + logInfo(`${MODULE_NAME} - usersync config updated for ${submodules.length} submodules: `, submodules.map(a => a.submodule.name)); addedUserIdHook = true; } } @@ -828,11 +830,11 @@ export function init(config) { // exit immediately if opt out cookie or local storage keys exists. if (validStorageTypes.indexOf(COOKIE) !== -1 && coreStorage.getCookie(PBJS_USER_ID_OPTOUT_NAME)) { - utils.logInfo(`${MODULE_NAME} - opt-out cookie found, exit module`); + logInfo(`${MODULE_NAME} - opt-out cookie found, exit module`); return; } if (validStorageTypes.indexOf(LOCAL_STORAGE) !== -1 && coreStorage.getDataFromLocalStorage(PBJS_USER_ID_OPTOUT_NAME)) { - utils.logInfo(`${MODULE_NAME} - opt-out localStorage found, exit module`); + logInfo(`${MODULE_NAME} - opt-out localStorage found, exit module`); return; } @@ -842,8 +844,8 @@ export function init(config) { const userSync = conf.userSync; if (userSync && userSync.userIds) { configRegistry = userSync.userIds; - syncDelay = utils.isNumber(userSync.syncDelay) ? userSync.syncDelay : DEFAULT_SYNC_DELAY; - auctionDelay = utils.isNumber(userSync.auctionDelay) ? userSync.auctionDelay : NO_AUCTION_DELAY; + syncDelay = isNumber(userSync.syncDelay) ? userSync.syncDelay : DEFAULT_SYNC_DELAY; + auctionDelay = isNumber(userSync.auctionDelay) ? userSync.auctionDelay : NO_AUCTION_DELAY; updateSubmodules(); } }); From 3097bac4deb682507c4dde270059991016e2c2e4 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 23 Sep 2021 14:31:46 -0700 Subject: [PATCH 08/10] rtdModule: import only what is needed from utils --- modules/rtdModule/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/rtdModule/index.js b/modules/rtdModule/index.js index e235868f791..7dce09f0d1d 100644 --- a/modules/rtdModule/index.js +++ b/modules/rtdModule/index.js @@ -143,7 +143,7 @@ import {config} from '../../src/config.js'; import {module} from '../../src/hook.js'; -import * as utils from '../../src/utils.js'; +import { logError, logWarn } from '../../src/utils.js'; import events from '../../src/events.js'; import CONSTANTS from '../../src/constants.json'; import {gdprDataHandler, uspDataHandler} from '../../src/adapterManager.js'; @@ -174,7 +174,7 @@ export function attachRealTimeDataProvider(submodule) { export function init(config) { const confListener = config.getConfig(MODULE_NAME, ({realTimeData}) => { if (!realTimeData.dataProviders) { - utils.logError('missing parameters for real time module'); + logError('missing parameters for real time module'); return; } confListener(); // unsubscribe config listener @@ -314,7 +314,7 @@ export function getAdUnitTargeting(auction) { if (smTargeting && typeof smTargeting === 'object') { targeting.push(smTargeting); } else { - utils.logWarn('invalid getTargetingData response for sub module', relevantSubModules[i].name); + logWarn('invalid getTargetingData response for sub module', relevantSubModules[i].name); } } // place data on auction adUnits From 0df536fd11b5de2ac784c0768f7dc0747ee858d8 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 23 Sep 2021 14:49:11 -0700 Subject: [PATCH 09/10] PBS: import only what is needed from utils --- modules/prebidServerBidAdapter/index.js | 212 ++++++++++++------------ 1 file changed, 108 insertions(+), 104 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index d7caf0dbad8..245cb7fc0b0 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -1,6 +1,11 @@ import Adapter from '../../src/adapter.js'; import { createBid } from '../../src/bidfactory.js'; -import * as utils from '../../src/utils.js'; +import { + getPrebidInternal, logError, isStr, isPlainObject, logWarn, generateUUID, bind, logMessage, + triggerPixel, insertUserSyncIframe, deepAccess, mergeDeep, deepSetValue, cleanObj, parseSizesInput, + getBidRequest, getDefinedParams, createTrackPixelHtml, pick, deepClone, uniques, flatten, isNumber, + isEmpty, isArray, logInfo +} from '../../src/utils.js'; import CONSTANTS from '../../src/constants.json'; import adapterManager from '../../src/adapterManager.js'; import { config } from '../../src/config.js'; @@ -12,7 +17,6 @@ import includes from 'core-js-pure/features/array/includes.js'; import { S2S_VENDORS } from './config.js'; import { ajax } from '../../src/ajax.js'; import find from 'core-js-pure/features/array/find.js'; -import { getPrebidInternal } from '../../src/utils.js'; const getConfig = config.getConfig; @@ -100,7 +104,7 @@ function updateConfigDefaultVendor(option) { } }); } else { - utils.logError('Incorrect or unavailable prebid server default vendor option: ' + vendor); + logError('Incorrect or unavailable prebid server default vendor option: ' + vendor); return false; } } @@ -116,7 +120,7 @@ function validateConfigRequiredProps(option) { const keys = Object.keys(option); if (['accountId', 'bidders', 'endpoint'].filter(key => { if (!includes(keys, key)) { - utils.logError(key + ' missing in server to server config'); + logError(key + ' missing in server to server config'); return true; } return false; @@ -129,14 +133,14 @@ function validateConfigRequiredProps(option) { // could be removed later as part of a major release, if we decide to not support the old format function formatUrlParams(option) { ['endpoint', 'syncEndpoint'].forEach((prop) => { - if (utils.isStr(option[prop])) { + if (isStr(option[prop])) { let temp = option[prop]; option[prop] = { p1Consent: temp, noP1Consent: temp }; } - if (utils.isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) { + if (isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) { ['p1Consent', 'noP1Consent'].forEach((conUrl) => { if (!option[prop][conUrl]) { - utils.logWarn(`s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios.`); + logWarn(`s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios.`); } }); } @@ -171,7 +175,7 @@ function setS2sConfig(options) { return true; } } - utils.logWarn('prebidServer: s2s config is disabled'); + logWarn('prebidServer: s2s config is disabled'); return false; }); @@ -198,13 +202,13 @@ function queueSync(bidderCodes, gdprConsent, uspConsent, s2sConfig) { _syncCount++; const payload = { - uuid: utils.generateUUID(), + uuid: generateUUID(), bidders: bidderCodes, account: s2sConfig.accountId }; let userSyncLimit = s2sConfig.userSyncLimit; - if (utils.isNumber(userSyncLimit) && userSyncLimit > 0) { + if (isNumber(userSyncLimit) && userSyncLimit > 0) { payload['limit'] = userSyncLimit; } @@ -232,7 +236,7 @@ function queueSync(bidderCodes, gdprConsent, uspConsent, s2sConfig) { response = JSON.parse(response); doAllSyncs(response.bidder_status, s2sConfig); } catch (e) { - utils.logError(e); + logError(e); } }, jsonPayload, @@ -252,7 +256,7 @@ function doAllSyncs(bidders, s2sConfig) { // if PBS reports this bidder doesn't have an ID, then call the sync and recurse to the next sync entry if (thisSync.no_cookie) { - doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, utils.bind.call(doAllSyncs, null, bidders, s2sConfig), s2sConfig); + doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, bind.call(doAllSyncs, null, bidders, s2sConfig), s2sConfig); } else { // bidder already has an ID, so just recurse to the next sync entry doAllSyncs(bidders, s2sConfig); @@ -287,16 +291,16 @@ function doPreBidderSync(type, url, bidder, done, s2sConfig) { */ function doBidderSync(type, url, bidder, done) { if (!url) { - utils.logError(`No sync url for bidder "${bidder}": ${url}`); + logError(`No sync url for bidder "${bidder}": ${url}`); done(); } else if (type === 'image' || type === 'redirect') { - utils.logMessage(`Invoking image pixel user sync for bidder: "${bidder}"`); - utils.triggerPixel(url, done); + logMessage(`Invoking image pixel user sync for bidder: "${bidder}"`); + triggerPixel(url, done); } else if (type == 'iframe') { - utils.logMessage(`Invoking iframe user sync for bidder: "${bidder}"`); - utils.insertUserSyncIframe(url, done); + logMessage(`Invoking iframe user sync for bidder: "${bidder}"`); + insertUserSyncIframe(url, done); } else { - utils.logError(`User sync type "${type}" not supported for bidder: "${bidder}"`); + logError(`User sync type "${type}" not supported for bidder: "${bidder}"`); done(); } } @@ -312,7 +316,7 @@ function doClientSideSyncs(bidders, gdprConsent, uspConsent) { if (clientAdapter && clientAdapter.registerSyncs) { config.runWithBidder( bidder, - utils.bind.call( + bind.call( clientAdapter.registerSyncs, clientAdapter, [], @@ -333,12 +337,12 @@ function _appendSiteAppDevice(request, pageUrl, accountId) { request.app.publisher = {id: accountId} } else { request.site = {}; - if (utils.isPlainObject(config.getConfig('site'))) { + if (isPlainObject(config.getConfig('site'))) { request.site = config.getConfig('site'); } // set publisher.id if not already defined - if (!utils.deepAccess(request.site, 'publisher.id')) { - utils.deepSetValue(request.site, 'publisher.id', accountId); + if (!deepAccess(request.site, 'publisher.id')) { + deepSetValue(request.site, 'publisher.id', accountId); } // set site.page if not already defined if (!request.site.page) { @@ -364,7 +368,7 @@ function addBidderFirstPartyDataToRequest(request) { const fpdConfigs = Object.keys(bidderConfig).reduce((acc, bidder) => { const currBidderConfig = bidderConfig[bidder]; if (currBidderConfig.ortb2) { - const ortb2 = utils.mergeDeep({}, currBidderConfig.ortb2); + const ortb2 = mergeDeep({}, currBidderConfig.ortb2); acc.push({ bidders: [ bidder ], @@ -375,7 +379,7 @@ function addBidderFirstPartyDataToRequest(request) { }, []); if (fpdConfigs.length) { - utils.deepSetValue(request, 'ext.prebid.bidderconfig', fpdConfigs); + deepSetValue(request, 'ext.prebid.bidderconfig', fpdConfigs); } } @@ -442,13 +446,13 @@ let wurlMap = {}; * @param {string} wurl events.winurl passed from prebidServer as wurl */ function addWurl(auctionId, adId, wurl) { - if ([auctionId, adId].every(utils.isStr)) { + if ([auctionId, adId].every(isStr)) { wurlMap[`${auctionId}${adId}`] = wurl; } } function getPbsResponseData(bidderRequests, response, pbsName, pbjsName) { - const bidderValues = utils.deepAccess(response, `ext.${pbsName}`); + const bidderValues = deepAccess(response, `ext.${pbsName}`); if (bidderValues) { Object.keys(bidderValues).forEach(bidder => { let biddersReq = find(bidderRequests, bidderReq => bidderReq.bidderCode === bidder); @@ -464,7 +468,7 @@ function getPbsResponseData(bidderRequests, response, pbsName, pbjsName) { * @param {string} adId generated value set to bidObject.adId by bidderFactory Bid() */ function removeWurl(auctionId, adId) { - if ([auctionId, adId].every(utils.isStr)) { + if ([auctionId, adId].every(isStr)) { wurlMap[`${auctionId}${adId}`] = undefined; } } @@ -474,7 +478,7 @@ function removeWurl(auctionId, adId) { * @return {(string|undefined)} events.winurl which was passed as wurl */ function getWurl(auctionId, adId) { - if ([auctionId, adId].every(utils.isStr)) { + if ([auctionId, adId].every(isStr)) { return wurlMap[`${auctionId}${adId}`]; } } @@ -506,7 +510,7 @@ const OPEN_RTB_PROTOCOL = { } impIds.add(impressionId); - const nativeParams = processNativeAdUnitParams(utils.deepAccess(adUnit, 'mediaTypes.native')); + const nativeParams = processNativeAdUnitParams(deepAccess(adUnit, 'mediaTypes.native')); let nativeAssets; if (nativeParams) { try { @@ -516,19 +520,19 @@ const OPEN_RTB_PROTOCOL = { function newAsset(obj) { return Object.assign({ required: params.required ? 1 : 0 - }, obj ? utils.cleanObj(obj) : {}); + }, obj ? cleanObj(obj) : {}); } switch (type) { case 'image': case 'icon': let imgTypeId = nativeImgIdMap[type]; - let asset = utils.cleanObj({ + let asset = cleanObj({ type: imgTypeId, - w: utils.deepAccess(params, 'sizes.0'), - h: utils.deepAccess(params, 'sizes.1'), - wmin: utils.deepAccess(params, 'aspect_ratios.0.min_width'), - hmin: utils.deepAccess(params, 'aspect_ratios.0.min_height') + w: deepAccess(params, 'sizes.0'), + h: deepAccess(params, 'sizes.1'), + wmin: deepAccess(params, 'aspect_ratios.0.min_width'), + hmin: deepAccess(params, 'aspect_ratios.0.min_height') }); if (!((asset.w && asset.h) || (asset.hmin && asset.wmin))) { throw 'invalid img sizes (must provide sizes or min_height & min_width if using aspect_ratios)'; @@ -569,11 +573,11 @@ const OPEN_RTB_PROTOCOL = { return assets; }, []); } catch (e) { - utils.logError('error creating native request: ' + String(e)) + logError('error creating native request: ' + String(e)) } } - const videoParams = utils.deepAccess(adUnit, 'mediaTypes.video'); - const bannerParams = utils.deepAccess(adUnit, 'mediaTypes.banner'); + const videoParams = deepAccess(adUnit, 'mediaTypes.video'); + const bannerParams = deepAccess(adUnit, 'mediaTypes.banner'); adUnit.bids.forEach(bid => { // OpenRTB response contains imp.id and bidder name. These are @@ -592,7 +596,7 @@ const OPEN_RTB_PROTOCOL = { let mediaTypes = {}; if (bannerParams && bannerParams.sizes) { - const sizes = utils.parseSizesInput(bannerParams.sizes); + const sizes = parseSizesInput(bannerParams.sizes); // get banner sizes in form [{ w: , h: }, ...] const format = sizes.map(size => { @@ -607,10 +611,10 @@ const OPEN_RTB_PROTOCOL = { if (bannerParams.pos) mediaTypes['banner'].pos = bannerParams.pos; } - if (!utils.isEmpty(videoParams)) { + if (!isEmpty(videoParams)) { if (videoParams.context === 'outstream' && !videoParams.renderer && !adUnit.renderer) { // Don't push oustream w/o renderer to request object. - utils.logError('Outstream bid without renderer cannot be sent to Prebid Server.'); + logError('Outstream bid without renderer cannot be sent to Prebid Server.'); } else { if (videoParams.context === 'instream' && !videoParams.hasOwnProperty('placement')) { videoParams.placement = 1; @@ -619,8 +623,8 @@ const OPEN_RTB_PROTOCOL = { mediaTypes['video'] = Object.keys(videoParams).filter(param => param !== 'context') .reduce((result, param) => { if (param === 'playerSize') { - result.w = utils.deepAccess(videoParams, `${param}.0.0`); - result.h = utils.deepAccess(videoParams, `${param}.0.1`); + result.w = deepAccess(videoParams, `${param}.0.0`); + result.h = deepAccess(videoParams, `${param}.0.1`); } else { result[param] = videoParams[param]; } @@ -646,7 +650,7 @@ const OPEN_RTB_PROTOCOL = { ver: '1.2' } } catch (e) { - utils.logError('error creating native request: ' + String(e)) + logError('error creating native request: ' + String(e)) } } @@ -659,11 +663,11 @@ const OPEN_RTB_PROTOCOL = { } acc[bid.bidder] = (s2sConfig.adapterOptions && s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, s2sConfig.adapterOptions[bid.bidder]) : bid.params; return acc; - }, {...utils.deepAccess(adUnit, 'ortb2Imp.ext')}); + }, {...deepAccess(adUnit, 'ortb2Imp.ext')}); const imp = { id: impressionId, ext, secure: s2sConfig.secure }; - const ortb2 = {...utils.deepAccess(adUnit, 'ortb2Imp.ext.data')}; + const ortb2 = {...deepAccess(adUnit, 'ortb2Imp.ext.data')}; Object.keys(ortb2).forEach(prop => { /** * Prebid AdSlot @@ -671,7 +675,7 @@ const OPEN_RTB_PROTOCOL = { */ if (prop === 'pbadslot') { if (typeof ortb2[prop] === 'string' && ortb2[prop]) { - utils.deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); + deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); } else { // remove pbadslot property if it doesn't meet the spec delete imp.ext.data.pbadslot; @@ -682,13 +686,13 @@ const OPEN_RTB_PROTOCOL = { */ ['name', 'adslot'].forEach(name => { /** @type {(string|undefined)} */ - const value = utils.deepAccess(ortb2, `adserver.${name}`); + const value = deepAccess(ortb2, `adserver.${name}`); if (typeof value === 'string' && value) { - utils.deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); + deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); } }); } else { - utils.deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); + deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); } }); @@ -697,7 +701,7 @@ const OPEN_RTB_PROTOCOL = { // if storedAuctionResponse has been set, pass SRID const storedAuctionResponseBid = find(firstBidRequest.bids, bid => (bid.adUnitCode === adUnit.code && bid.storedAuctionResponse)); if (storedAuctionResponseBid) { - utils.deepSetValue(imp, 'ext.prebid.storedauctionresponse.id', storedAuctionResponseBid.storedAuctionResponse.toString()); + deepSetValue(imp, 'ext.prebid.storedauctionresponse.id', storedAuctionResponseBid.storedAuctionResponse.toString()); } const getFloorBid = find(firstBidRequest.bids, bid => bid.adUnitCode === adUnit.code && typeof bid.getFloor === 'function'); @@ -709,7 +713,7 @@ const OPEN_RTB_PROTOCOL = { currency: config.getConfig('currency.adServerCurrency') || DEFAULT_S2S_CURRENCY, }); } catch (e) { - utils.logError('PBS: getFloor threw an error: ', e); + logError('PBS: getFloor threw an error: ', e); } if (floorInfo && floorInfo.currency && !isNaN(parseFloat(floorInfo.floor))) { imp.bidfloor = parseFloat(floorInfo.floor); @@ -723,7 +727,7 @@ const OPEN_RTB_PROTOCOL = { }); if (!imps.length) { - utils.logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.'); + logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.'); return; } const request = { @@ -775,36 +779,36 @@ const OPEN_RTB_PROTOCOL = { _appendSiteAppDevice(request, bidRequests[0].refererInfo.referer, s2sConfig.accountId); // pass schain object if it is present - const schain = utils.deepAccess(bidRequests, '0.bids.0.schain'); + const schain = deepAccess(bidRequests, '0.bids.0.schain'); if (schain) { request.source.ext = { schain: schain }; } - if (!utils.isEmpty(aliases)) { + if (!isEmpty(aliases)) { request.ext.prebid.aliases = {...request.ext.prebid.aliases, ...aliases}; } - const bidUserIdAsEids = utils.deepAccess(bidRequests, '0.bids.0.userIdAsEids'); - if (utils.isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { - utils.deepSetValue(request, 'user.ext.eids', bidUserIdAsEids); + const bidUserIdAsEids = deepAccess(bidRequests, '0.bids.0.userIdAsEids'); + if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { + deepSetValue(request, 'user.ext.eids', bidUserIdAsEids); } - if (utils.isArray(eidPermissions) && eidPermissions.length > 0) { - if (requestedBidders && utils.isArray(requestedBidders)) { + if (isArray(eidPermissions) && eidPermissions.length > 0) { + if (requestedBidders && isArray(requestedBidders)) { eidPermissions.forEach(i => { if (i.bidders) { i.bidders = i.bidders.filter(bidder => requestedBidders.includes(bidder)) } }); } - utils.deepSetValue(request, 'ext.prebid.data.eidpermissions', eidPermissions); + deepSetValue(request, 'ext.prebid.data.eidpermissions', eidPermissions); } const multibid = config.getConfig('multibid'); if (multibid) { - utils.deepSetValue(request, 'ext.prebid.multibid', multibid.reduce((result, i) => { + deepSetValue(request, 'ext.prebid.multibid', multibid.reduce((result, i) => { let obj = {}; Object.keys(i).forEach(key => { @@ -824,25 +828,25 @@ const OPEN_RTB_PROTOCOL = { if (typeof firstBidRequest.gdprConsent.gdprApplies === 'boolean') { gdprApplies = firstBidRequest.gdprConsent.gdprApplies ? 1 : 0; } - utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies); - utils.deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString); + deepSetValue(request, 'regs.ext.gdpr', gdprApplies); + deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString); if (firstBidRequest.gdprConsent.addtlConsent && typeof firstBidRequest.gdprConsent.addtlConsent === 'string') { - utils.deepSetValue(request, 'user.ext.ConsentedProvidersSettings.consented_providers', firstBidRequest.gdprConsent.addtlConsent); + deepSetValue(request, 'user.ext.ConsentedProvidersSettings.consented_providers', firstBidRequest.gdprConsent.addtlConsent); } } // US Privacy (CCPA) support if (firstBidRequest.uspConsent) { - utils.deepSetValue(request, 'regs.ext.us_privacy', firstBidRequest.uspConsent); + deepSetValue(request, 'regs.ext.us_privacy', firstBidRequest.uspConsent); } } if (getConfig('coppa') === true) { - utils.deepSetValue(request, 'regs.coppa', 1); + deepSetValue(request, 'regs.coppa', 1); } const commonFpd = getConfig('ortb2') || {}; - utils.mergeDeep(request, commonFpd); + mergeDeep(request, commonFpd); addBidderFirstPartyDataToRequest(request); @@ -862,7 +866,7 @@ const OPEN_RTB_PROTOCOL = { let bidRequest; let key = `${bid.impid}${seatbid.seat}`; if (bidIdMap[key]) { - bidRequest = utils.getBidRequest( + bidRequest = getBidRequest( bidIdMap[key], bidderRequests ); @@ -879,31 +883,31 @@ const OPEN_RTB_PROTOCOL = { // temporarily leaving attaching it to each bidResponse so no breaking change // BUT: this is a flat map, so it should be only attached to bidderRequest, a the change above does - let serverResponseTimeMs = utils.deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.')); + let serverResponseTimeMs = deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.')); if (bidRequest && serverResponseTimeMs) { bidRequest.serverResponseTimeMs = serverResponseTimeMs; } // Look for seatbid[].bid[].ext.prebid.bidid and place it in the bidResponse object for use in analytics adapters as 'pbsBidId' - const bidId = utils.deepAccess(bid, 'ext.prebid.bidid'); - if (utils.isStr(bidId)) { + const bidId = deepAccess(bid, 'ext.prebid.bidid'); + if (isStr(bidId)) { bidObject.pbsBidId = bidId; } // store wurl by auctionId and adId so it can be accessed from the BID_WON event handler - if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.win'))) { - addWurl(bidRequest.auctionId, bidObject.adId, utils.deepAccess(bid, 'ext.prebid.events.win')); + if (isStr(deepAccess(bid, 'ext.prebid.events.win'))) { + addWurl(bidRequest.auctionId, bidObject.adId, deepAccess(bid, 'ext.prebid.events.win')); } - let extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting'); + let extPrebidTargeting = deepAccess(bid, 'ext.prebid.targeting'); // If ext.prebid.targeting exists, add it as a property value named 'adserverTargeting' // The removal of hb_winurl and hb_bidid targeting values is temporary // once we get through the transition, this block will be removed. - if (utils.isPlainObject(extPrebidTargeting)) { + if (isPlainObject(extPrebidTargeting)) { // If wurl exists, remove hb_winurl and hb_bidid targeting attributes - if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.win'))) { - extPrebidTargeting = utils.getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting) + if (isStr(deepAccess(bid, 'ext.prebid.events.win'))) { + extPrebidTargeting = getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting) .filter(i => (i.indexOf('hb_winurl') === -1 && i.indexOf('hb_bidid') === -1))); } bidObject.adserverTargeting = extPrebidTargeting; @@ -911,7 +915,7 @@ const OPEN_RTB_PROTOCOL = { bidObject.seatBidId = bid.id; - if (utils.deepAccess(bid, 'ext.prebid.type') === VIDEO) { + if (deepAccess(bid, 'ext.prebid.type') === VIDEO) { bidObject.mediaType = VIDEO; let sizes = bidRequest.sizes && bidRequest.sizes[0]; bidObject.playerWidth = sizes[0]; @@ -930,7 +934,7 @@ const OPEN_RTB_PROTOCOL = { if (bid.adm) { bidObject.vastXml = bid.adm; } if (!bidObject.vastUrl && bid.nurl) { bidObject.vastUrl = bid.nurl; } - } else if (utils.deepAccess(bid, 'ext.prebid.type') === NATIVE) { + } else if (deepAccess(bid, 'ext.prebid.type') === NATIVE) { bidObject.mediaType = NATIVE; let adm; if (typeof bid.adm === 'string') { @@ -956,18 +960,18 @@ const OPEN_RTB_PROTOCOL = { }); } - if (utils.isPlainObject(adm) && Array.isArray(adm.assets)) { + if (isPlainObject(adm) && Array.isArray(adm.assets)) { let origAssets = nativeAssetCache[bid.impid]; - bidObject.native = utils.cleanObj(adm.assets.reduce((native, asset) => { + bidObject.native = cleanObj(adm.assets.reduce((native, asset) => { let origAsset = origAssets[asset.id]; - if (utils.isPlainObject(asset.img)) { - native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = utils.pick( + if (isPlainObject(asset.img)) { + native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = pick( asset.img, ['url', 'w as width', 'h as height'] ); - } else if (utils.isPlainObject(asset.title)) { + } else if (isPlainObject(asset.title)) { native['title'] = asset.title.text - } else if (utils.isPlainObject(asset.data)) { + } else if (isPlainObject(asset.data)) { nativeDataNames.forEach(dataType => { if (nativeDataIdMap[dataType] === origAsset.data.type) { native[dataType] = asset.data.value; @@ -975,19 +979,19 @@ const OPEN_RTB_PROTOCOL = { }); } return native; - }, utils.cleanObj({ + }, cleanObj({ clickUrl: adm.link, - clickTrackers: utils.deepAccess(adm, 'link.clicktrackers'), + clickTrackers: deepAccess(adm, 'link.clicktrackers'), impressionTrackers: trackers[nativeEventTrackerMethodMap.img], javascriptTrackers: trackers[nativeEventTrackerMethodMap.js] }))); } else { - utils.logError('prebid server native response contained no assets'); + logError('prebid server native response contained no assets'); } } else { // banner if (bid.adm && bid.nurl) { bidObject.ad = bid.adm; - bidObject.ad += utils.createTrackPixelHtml(decodeURIComponent(bid.nurl)); + bidObject.ad += createTrackPixelHtml(decodeURIComponent(bid.nurl)); } else if (bid.adm) { bidObject.ad = bid.adm; } else if (bid.nurl) { @@ -1004,8 +1008,8 @@ const OPEN_RTB_PROTOCOL = { if (bid.burl) { bidObject.burl = bid.burl; } bidObject.currency = (response.cur) ? response.cur : DEFAULT_S2S_CURRENCY; bidObject.meta = {}; - let extPrebidMeta = utils.deepAccess(bid, 'ext.prebid.meta'); - if (extPrebidMeta && utils.isPlainObject(extPrebidMeta)) { bidObject.meta = utils.deepClone(extPrebidMeta); } + let extPrebidMeta = deepAccess(bid, 'ext.prebid.meta'); + if (extPrebidMeta && isPlainObject(extPrebidMeta)) { bidObject.meta = deepClone(extPrebidMeta); } if (bid.adomain) { bidObject.meta.advertiserDomains = bid.adomain; } // the OpenRTB location for "TTL" as understood by Prebid.js is "exp" (expiration). @@ -1028,9 +1032,9 @@ const OPEN_RTB_PROTOCOL = { */ function bidWonHandler(bid) { const wurl = getWurl(bid.auctionId, bid.adId); - if (utils.isStr(wurl)) { - utils.logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`); - utils.triggerPixel(wurl); + if (isStr(wurl)) { + logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`); + triggerPixel(wurl); // remove from wurl cache, since the wurl url was called removeWurl(bid.auctionId, bid.adId); @@ -1041,7 +1045,7 @@ function hasPurpose1Consent(gdprConsent) { let result = true; if (gdprConsent) { if (gdprConsent.gdprApplies && gdprConsent.apiVersion === 2) { - result = !!(utils.deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -1068,7 +1072,7 @@ export function PrebidServer() { /* Prebid executes this function when the page asks to send out bid requests */ baseAdapter.callBids = function(s2sBidRequest, bidRequests, addBidResponse, done, ajax) { - const adUnits = utils.deepClone(s2sBidRequest.ad_units); + const adUnits = deepClone(s2sBidRequest.ad_units); let { gdprConsent, uspConsent } = getConsentData(bidRequests); // at this point ad units should have a size array either directly or mapped so filter for that @@ -1078,9 +1082,9 @@ export function PrebidServer() { // in case config.bidders contains invalid bidders, we only process those we sent requests for const requestedBidders = validAdUnits - .map(adUnit => adUnit.bids.map(bid => bid.bidder).filter(utils.uniques)) - .reduce(utils.flatten) - .filter(utils.uniques); + .map(adUnit => adUnit.bids.map(bid => bid.bidder).filter(uniques)) + .reduce(flatten) + .filter(uniques); if (Array.isArray(_s2sConfigs)) { if (s2sBidRequest.s2sConfig && s2sBidRequest.s2sConfig.syncEndpoint && getMatchingConsentUrl(s2sBidRequest.s2sConfig.syncEndpoint, gdprConsent)) { @@ -1093,7 +1097,7 @@ export function PrebidServer() { const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits, s2sBidRequest.s2sConfig, requestedBidders); const requestJson = request && JSON.stringify(request); - utils.logInfo('BidRequest: ' + requestJson); + logInfo('BidRequest: ' + requestJson); const endpointUrl = getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent); if (request && requestJson && endpointUrl) { ajax( @@ -1106,7 +1110,7 @@ export function PrebidServer() { { contentType: 'text/plain', withCredentials: true } ); } else { - utils.logError('PBS request not made. Check endpoints.'); + logError('PBS request not made. Check endpoints.'); } } }; @@ -1134,11 +1138,11 @@ export function PrebidServer() { bidderRequests.forEach(bidderRequest => events.emit(CONSTANTS.EVENTS.BIDDER_DONE, bidderRequest)); } catch (error) { - utils.logError(error); + logError(error); } if (!result || (result.status && includes(result.status, 'Error'))) { - utils.logError('error parsing response: ', result.status); + logError('error parsing response: ', result.status); } done(); From 1cec53f5b22c5b2d2f6fa6484a27fa739c16da78 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 23 Sep 2021 14:58:38 -0700 Subject: [PATCH 10/10] multibid: import only what is needed from utils --- modules/multibid/index.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/multibid/index.js b/modules/multibid/index.js index dd4999b2dca..cf4821de183 100644 --- a/modules/multibid/index.js +++ b/modules/multibid/index.js @@ -5,7 +5,9 @@ import {config} from '../../src/config.js'; import {setupBeforeHookFnOnce, getHook} from '../../src/hook.js'; -import * as utils from '../../src/utils.js'; +import { + logWarn, deepAccess, getUniqueIdentifierStr, deepSetValue, groupBy +} from '../../src/utils.js'; import events from '../../src/events.js'; import CONSTANTS from '../../src/constants.json'; import {addBidderRequests} from '../../src/auction.js'; @@ -50,7 +52,7 @@ export function validateMultibid(conf) { let duplicate = conf.filter(entry => { // Check if entry.bidder is not defined or typeof string, filter entry and reset configuration if ((!entry.bidder || typeof entry.bidder !== 'string') && (!entry.bidders || !Array.isArray(entry.bidders))) { - utils.logWarn('Filtering multibid entry. Missing required bidder or bidders property.'); + logWarn('Filtering multibid entry. Missing required bidder or bidders property.'); check = false; return false; } @@ -97,26 +99,26 @@ export function adjustBidderRequestsHook(fn, bidderRequests) { * @param {Object} bid object */ export function addBidResponseHook(fn, adUnitCode, bid) { - let floor = utils.deepAccess(bid, 'floorData.floorValue'); + let floor = deepAccess(bid, 'floorData.floorValue'); if (!config.getConfig('multibid')) resetMultiConfig(); // Checks if multiconfig exists and bid bidderCode exists within config and is an adpod bid // Else checks if multiconfig exists and bid bidderCode exists within config // Else continue with no modifications - if (hasMultibid && multiConfig[bid.bidderCode] && utils.deepAccess(bid, 'video.context') === 'adpod') { + if (hasMultibid && multiConfig[bid.bidderCode] && deepAccess(bid, 'video.context') === 'adpod') { fn.call(this, adUnitCode, bid); } else if (hasMultibid && multiConfig[bid.bidderCode]) { // Set property multibidPrefix on bid if (multiConfig[bid.bidderCode].prefix) bid.multibidPrefix = multiConfig[bid.bidderCode].prefix; bid.originalBidder = bid.bidderCode; // Check if stored bids for auction include adUnitCode.bidder and max limit not reach for ad unit - if (utils.deepAccess(multibidUnits, `${adUnitCode}.${bid.bidderCode}`)) { + if (deepAccess(multibidUnits, `${adUnitCode}.${bid.bidderCode}`)) { // Store request id under new property originalRequestId, create new unique bidId, // and push bid into multibid stored bids for auction if max not reached and bid cpm above floor if (!multibidUnits[adUnitCode][bid.bidderCode].maxReached && (!floor || floor <= bid.cpm)) { bid.originalRequestId = bid.requestId; - bid.requestId = utils.getUniqueIdentifierStr(); + bid.requestId = getUniqueIdentifierStr(); multibidUnits[adUnitCode][bid.bidderCode].ads.push(bid); let length = multibidUnits[adUnitCode][bid.bidderCode].ads.length; @@ -126,12 +128,12 @@ export function addBidResponseHook(fn, adUnitCode, bid) { fn.call(this, adUnitCode, bid); } else { - utils.logWarn(`Filtering multibid received from bidder ${bid.bidderCode}: ` + ((multibidUnits[adUnitCode][bid.bidderCode].maxReached) ? `Maximum bid limit reached for ad unit code ${adUnitCode}` : 'Bid cpm under floors value.')); + logWarn(`Filtering multibid received from bidder ${bid.bidderCode}: ` + ((multibidUnits[adUnitCode][bid.bidderCode].maxReached) ? `Maximum bid limit reached for ad unit code ${adUnitCode}` : 'Bid cpm under floors value.')); } } else { - if (utils.deepAccess(bid, 'floorData.floorValue')) utils.deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {floor: utils.deepAccess(bid, 'floorData.floorValue')}); + if (deepAccess(bid, 'floorData.floorValue')) deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {floor: deepAccess(bid, 'floorData.floorValue')}); - utils.deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {ads: [bid]}); + deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {ads: [bid]}); if (multibidUnits[adUnitCode][bid.bidderCode].ads.length === multiConfig[bid.bidderCode].maxbids) multibidUnits[adUnitCode][bid.bidderCode].maxReached = true; fn.call(this, adUnitCode, bid); @@ -170,11 +172,11 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi if (hasMultibid) { const dealPrioritization = config.getConfig('sendBidsControl.dealPrioritization'); let modifiedBids = []; - let buckets = utils.groupBy(bidsReceived, 'adUnitCode'); + let buckets = groupBy(bidsReceived, 'adUnitCode'); let bids = [].concat.apply([], Object.keys(buckets).reduce((result, slotId) => { let bucketBids = []; // Get bids and group by property originalBidder - let bidsByBidderName = utils.groupBy(buckets[slotId], 'originalBidder'); + let bidsByBidderName = groupBy(buckets[slotId], 'originalBidder'); let adjustedBids = [].concat.apply([], Object.keys(bidsByBidderName).map(key => { // Reset all bidderCodes to original bidder values and sort by CPM return bidsByBidderName[key].sort((bidA, bidB) => { @@ -183,7 +185,7 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi return bidA.cpm > bidB.cpm ? -1 : (bidA.cpm < bidB.cpm ? 1 : 0); }).map((bid, index) => { // For each bid (post CPM sort), set dynamic bidderCode using prefix and index if less than maxbid amount - if (utils.deepAccess(multiConfig, `${bid.bidderCode}.prefix`) && index !== 0 && index < multiConfig[bid.bidderCode].maxbids) { + if (deepAccess(multiConfig, `${bid.bidderCode}.prefix`) && index !== 0 && index < multiConfig[bid.bidderCode].maxbids) { bid.bidderCode = multiConfig[bid.bidderCode].prefix + (index + 1); } @@ -191,7 +193,7 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi }) })); // Get adjustedBids by bidderCode and reduce using highestCpmCallback - let bidsByBidderCode = utils.groupBy(adjustedBids, 'bidderCode'); + let bidsByBidderCode = groupBy(adjustedBids, 'bidderCode'); Object.keys(bidsByBidderCode).forEach(key => bucketBids.push(bidsByBidderCode[key].reduce(highestCpmCallback))); // if adUnitBidLimit is set, pass top N number bids if (adUnitBidLimit > 0) {