Skip to content

Commit

Permalink
Multiple Bid/Analytics/ID/ other modules: import utils functions as n…
Browse files Browse the repository at this point in the history
…eeded and not the whole module (#7498)

* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* Revert "import utils functions as needed and not the whole module"

This reverts commit bc6c9f6.

* Revert "import utils functions as needed and not the whole module"

This reverts commit ef500ab.

* Revert "import utils functions as needed and not the whole module"

This reverts commit 7e3fa3f.

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module
  • Loading branch information
pm-harshad-mane authored Sep 29, 2021
1 parent d98c5e8 commit 0624937
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 131 deletions.
30 changes: 15 additions & 15 deletions modules/timeoutRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { submodule } from '../src/hook.js';
import * as ajax from '../src/ajax.js';
import * as utils from '../src/utils.js';
import { logInfo, deepAccess, logError } from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';

const SUBMODULE_NAME = 'timeout';
Expand Down Expand Up @@ -70,14 +70,14 @@ function getConnectionSpeed() {
* @return {int}
*/
function calculateTimeoutModifier(adUnits, rules) {
utils.logInfo('Timeout rules', rules);
logInfo('Timeout rules', rules);
let timeoutModifier = 0;
let toAdd = 0;

if (rules.includesVideo) {
const hasVideo = timeoutRtdFunctions.checkVideo(adUnits);
toAdd = rules.includesVideo[hasVideo] || 0;
utils.logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`)
logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`)
timeoutModifier += toAdd;
}

Expand All @@ -89,7 +89,7 @@ function calculateTimeoutModifier(adUnits, rules) {
for (const [rangeStr, timeoutVal] of entries(rules.numAdUnits)) {
const [lowerBound, upperBound] = rangeStr.split('-');
if (parseInt(lowerBound) <= numAdUnits && numAdUnits <= parseInt(upperBound)) {
utils.logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`)
logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`)
timeoutModifier += timeoutVal;
break;
}
Expand All @@ -100,18 +100,18 @@ function calculateTimeoutModifier(adUnits, rules) {
if (rules.deviceType) {
const deviceType = timeoutRtdFunctions.getDeviceType();
toAdd = rules.deviceType[deviceType] || 0;
utils.logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`)
logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`)
timeoutModifier += toAdd;
}

if (rules.connectionSpeed) {
const connectionSpeed = timeoutRtdFunctions.getConnectionSpeed();
toAdd = rules.connectionSpeed[connectionSpeed] || 0;
utils.logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`)
logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`)
timeoutModifier += toAdd;
}

utils.logInfo('timeout Modifier calculated', timeoutModifier);
logInfo('timeout Modifier calculated', timeoutModifier);
return timeoutModifier;
}

Expand All @@ -123,30 +123,30 @@ function calculateTimeoutModifier(adUnits, rules) {
* @param {Object} userConsent
*/
function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) {
utils.logInfo('Timeout rtd config', config);
const timeoutUrl = utils.deepAccess(config, 'params.endpoint.url');
logInfo('Timeout rtd config', config);
const timeoutUrl = deepAccess(config, 'params.endpoint.url');
if (timeoutUrl) {
utils.logInfo('Timeout url', timeoutUrl);
logInfo('Timeout url', timeoutUrl);
ajax.ajaxBuilder()(timeoutUrl, {
success: function(response) {
try {
const rules = JSON.parse(response);
timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules);
} catch (e) {
utils.logError('Error parsing json response from timeout provider.')
logError('Error parsing json response from timeout provider.')
}
callback();
},
error: function(errorStatus) {
utils.logError('Timeout request error!', errorStatus);
logError('Timeout request error!', errorStatus);
callback();
}
});
} else if (utils.deepAccess(config, 'params.rules')) {
timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, utils.deepAccess(config, 'params.rules'));
} else if (deepAccess(config, 'params.rules')) {
timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, deepAccess(config, 'params.rules'));
callback();
} else {
utils.logInfo('No timeout endpoint or timeout rules found. Exiting timeout rtd module');
logInfo('No timeout endpoint or timeout rules found. Exiting timeout rtd module');
callback();
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/tpmnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-tabs */
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import { parseUrl, deepAccess } from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';

export const ADAPTER_VERSION = '1';
Expand Down Expand Up @@ -72,7 +72,7 @@ registerBidder(spec);
* Creates site description object
*/
function createSite(refInfo) {
let url = utils.parseUrl(refInfo.referer);
let url = parseUrl(refInfo.referer);
let site = {
'domain': url.hostname,
'page': url.protocol + '://' + url.hostname + url.pathname
Expand Down Expand Up @@ -102,7 +102,7 @@ function parseSizes(sizes) {
}

function getBannerSizes(bidRequest) {
return parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes);
return parseSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes);
}

function bidToRequest(bid) {
Expand Down
30 changes: 15 additions & 15 deletions modules/trionBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { getBidIdParameter, parseSizesInput, tryAppendQueryString } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';

Expand Down Expand Up @@ -112,11 +112,11 @@ function getPublisherUrl() {
}

function buildTrionUrlParams(bid, bidderRequest) {
var pubId = utils.getBidIdParameter('pubId', bid.params);
var sectionId = utils.getBidIdParameter('sectionId', bid.params);
var pubId = getBidIdParameter('pubId', bid.params);
var sectionId = getBidIdParameter('sectionId', bid.params);
var url = getPublisherUrl();
var bidSizes = getBidSizesFromBidRequest(bid);
var sizes = utils.parseSizesInput(bidSizes).join(',');
var sizes = parseSizesInput(bidSizes).join(',');
var isAutomated = (navigator && navigator.webdriver) ? '1' : '0';
var isHidden = (document.hidden) ? '1' : '0';
var visibilityState = encodeURIComponent(document.visibilityState);
Expand All @@ -131,33 +131,33 @@ function buildTrionUrlParams(bid, bidderRequest) {
setStorageData(BASE_KEY + 'lps', pubId + ':' + sectionId);
var trionUrl = '';

trionUrl = utils.tryAppendQueryString(trionUrl, 'bidId', bid.bidId);
trionUrl = utils.tryAppendQueryString(trionUrl, 'pubId', pubId);
trionUrl = utils.tryAppendQueryString(trionUrl, 'sectionId', sectionId);
trionUrl = utils.tryAppendQueryString(trionUrl, 'vers', '$prebid.version$');
trionUrl = tryAppendQueryString(trionUrl, 'bidId', bid.bidId);
trionUrl = tryAppendQueryString(trionUrl, 'pubId', pubId);
trionUrl = tryAppendQueryString(trionUrl, 'sectionId', sectionId);
trionUrl = tryAppendQueryString(trionUrl, 'vers', '$prebid.version$');
if (url) {
trionUrl += 'url=' + url + '&';
}
if (sizes) {
trionUrl += 'sizes=' + sizes + '&';
}
if (intT) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT));
trionUrl = tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT));
}
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_wd', isAutomated);
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_hd', isHidden);
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_vs', visibilityState);
trionUrl = tryAppendQueryString(trionUrl, 'tr_wd', isAutomated);
trionUrl = tryAppendQueryString(trionUrl, 'tr_hd', isHidden);
trionUrl = tryAppendQueryString(trionUrl, 'tr_vs', visibilityState);
if (bidderRequest && bidderRequest.gdprConsent) {
var gdpr = bidderRequest.gdprConsent;
if (gdpr) {
if (gdpr.consentString) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString));
trionUrl = tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString));
}
trionUrl = utils.tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0));
trionUrl = tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0));
}
}
if (bidderRequest && bidderRequest.uspConsent) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent));
trionUrl = tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent));
}
// remove the trailing "&"
if (trionUrl.lastIndexOf('&') === trionUrl.length - 1) {
Expand Down
46 changes: 23 additions & 23 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tryAppendQueryString, logMessage, isEmpty } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';

const GVLID = 28;
Expand All @@ -23,41 +23,41 @@ export const tripleliftAdapterSpec = {
let tlCall = STR_ENDPOINT;
let data = _buildPostBody(bidRequests);

tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid');
tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$');
tlCall = tryAppendQueryString(tlCall, 'lib', 'prebid');
tlCall = tryAppendQueryString(tlCall, 'v', '$prebid.version$');

if (bidderRequest && bidderRequest.refererInfo) {
let referrer = bidderRequest.refererInfo.referer;
tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer);
tlCall = tryAppendQueryString(tlCall, 'referrer', referrer);
}

if (bidderRequest && bidderRequest.timeout) {
tlCall = utils.tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout);
tlCall = tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout);
}

if (bidderRequest && bidderRequest.gdprConsent) {
if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') {
gdprApplies = bidderRequest.gdprConsent.gdprApplies;
tlCall = utils.tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString());
tlCall = tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString());
}
if (typeof bidderRequest.gdprConsent.consentString !== 'undefined') {
consentString = bidderRequest.gdprConsent.consentString;
tlCall = utils.tryAppendQueryString(tlCall, 'cmp_cs', consentString);
tlCall = tryAppendQueryString(tlCall, 'cmp_cs', consentString);
}
}

if (bidderRequest && bidderRequest.uspConsent) {
tlCall = utils.tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent);
tlCall = tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent);
}

if (config.getConfig('coppa') === true) {
tlCall = utils.tryAppendQueryString(tlCall, 'coppa', true);
tlCall = tryAppendQueryString(tlCall, 'coppa', true);
}

if (tlCall.lastIndexOf('&') === tlCall.length - 1) {
tlCall = tlCall.substring(0, tlCall.length - 1);
}
utils.logMessage('tlCall request built: ' + tlCall);
logMessage('tlCall request built: ' + tlCall);

return {
method: 'POST',
Expand All @@ -81,17 +81,17 @@ export const tripleliftAdapterSpec = {
let syncEndpoint = 'https://eb2.3lift.com/sync?';

if (syncType === 'image') {
syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'px', 1);
syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'src', 'prebid');
syncEndpoint = tryAppendQueryString(syncEndpoint, 'px', 1);
syncEndpoint = tryAppendQueryString(syncEndpoint, 'src', 'prebid');
}

if (consentString !== null) {
syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies);
syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString);
syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies);
syncEndpoint = tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString);
}

if (usPrivacy) {
syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy);
syncEndpoint = tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy);
}

return [{
Expand Down Expand Up @@ -124,7 +124,7 @@ function _buildPostBody(bidRequests) {
} else if (bidRequest.mediaTypes.banner) {
imp.banner = { format: _sizes(bidRequest.sizes) };
};
if (!utils.isEmpty(bidRequest.ortb2Imp)) {
if (!isEmpty(bidRequest.ortb2Imp)) {
imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp);
}
return imp;
Expand All @@ -145,7 +145,7 @@ function _buildPostBody(bidRequests) {

let ext = _getExt(schain, globalFpd);

if (!utils.isEmpty(ext)) {
if (!isEmpty(ext)) {
data.ext = ext;
}
return data;
Expand Down Expand Up @@ -200,10 +200,10 @@ function _getGlobalFpd() {
_addEntries(context, fpdContext);
_addEntries(user, fpdUser);

if (!utils.isEmpty(context)) {
if (!isEmpty(context)) {
fpd.context = context;
}
if (!utils.isEmpty(user)) {
if (!isEmpty(user)) {
fpd.user = user;
}
return fpd;
Expand All @@ -215,15 +215,15 @@ function _getAdUnitFpd(adUnitFpd) {

_addEntries(context, adUnitFpd.ext);

if (!utils.isEmpty(context)) {
if (!isEmpty(context)) {
fpd.context = context;
}

return fpd;
}

function _addEntries(target, source) {
if (!utils.isEmpty(source)) {
if (!isEmpty(source)) {
Object.keys(source).forEach(key => {
if (source[key] != null) {
target[key] = source[key];
Expand All @@ -234,10 +234,10 @@ function _addEntries(target, source) {

function _getExt(schain, fpd) {
let ext = {};
if (!utils.isEmpty(schain)) {
if (!isEmpty(schain)) {
ext.schain = { ...schain };
}
if (!utils.isEmpty(fpd)) {
if (!isEmpty(fpd)) {
ext.fpd = { ...fpd };
}
return ext;
Expand Down
8 changes: 4 additions & 4 deletions modules/truereachBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, getUniqueIdentifierStr } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
Expand All @@ -13,7 +13,7 @@ export const spec = {

isBidRequestValid: function (bidRequest) {
return (bidRequest.params.site_id && bidRequest.params.bidfloor &&
utils.deepAccess(bidRequest, 'mediaTypes.banner') && (utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0));
deepAccess(bidRequest, 'mediaTypes.banner') && (deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0));
},

buildRequests: function (validBidRequests, bidderRequest) {
Expand All @@ -23,7 +23,7 @@ export const spec = {

let queryParams = buildCommonQueryParamsFromBids(validBidRequests, bidderRequest);

let siteId = utils.deepAccess(validBidRequests[0], 'params.site_id');
let siteId = deepAccess(validBidRequests[0], 'params.site_id');

let url = BIDDER_URL + siteId + '?hb=1&transactionId=' + validBidRequests[0].transactionId;

Expand Down Expand Up @@ -121,7 +121,7 @@ function buildCommonQueryParamsFromBids(validBidRequests, bidderRequest) {
let page = window.location.host + window.location.pathname + location.search + location.hash;

let defaultParams = {
id: utils.getUniqueIdentifierStr(),
id: getUniqueIdentifierStr(),
imp: [
{
id: validBidRequests[0].bidId,
Expand Down
Loading

0 comments on commit 0624937

Please sign in to comment.