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 (prebid#7485)

* 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

* fix typo

Co-authored-by: Chris Huie <[email protected]>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent fc3a622 commit efa1ea3
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 178 deletions.
15 changes: 7 additions & 8 deletions modules/growadvertisingBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

import * as utils from '../src/utils.js';
import { getBidIdParameter, deepAccess, _each, triggerPixel } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import {triggerPixel} from '../src/utils.js';

const BIDDER_CODE = 'growads';

Expand All @@ -23,8 +22,8 @@ export const spec = {
const zoneCounters = {};

return validBidRequests.map(bidRequest => {
zoneId = utils.getBidIdParameter('zoneId', bidRequest.params);
domain = utils.getBidIdParameter('domain', bidRequest.params);
zoneId = getBidIdParameter('zoneId', bidRequest.params);
domain = getBidIdParameter('domain', bidRequest.params);

if (!(zoneId in zoneCounters)) {
zoneCounters[zoneId] = 0;
Expand Down Expand Up @@ -77,8 +76,8 @@ export const spec = {
width = parseInt(response.width);
height = parseInt(response.height);

minCPM = utils.getBidIdParameter('minCPM', request.params);
maxCPM = utils.getBidIdParameter('maxCPM', request.params);
minCPM = getBidIdParameter('minCPM', request.params);
maxCPM = getBidIdParameter('maxCPM', request.params);
width = parseInt(response.width);
height = parseInt(response.height);

Expand All @@ -102,7 +101,7 @@ export const spec = {
netRevenue: true,
ttl: response.ttl,
adUnitCode: request.adUnitCode,
referrer: utils.deepAccess(request, 'refererInfo.referer')
referrer: deepAccess(request, 'refererInfo.referer')
};

if (response.hasOwnProperty(NATIVE)) {
Expand Down Expand Up @@ -137,7 +136,7 @@ export const spec = {
bid.ad = response.ad;
bid.mediaType = BANNER;
// Ensure that response ad matches one of the placement sizes.
utils._each(utils.deepAccess(request, 'mediaTypes.banner.sizes', []), function (size) {
_each(deepAccess(request, 'mediaTypes.banner.sizes', []), function (size) {
if (width === size[0] && height === size[1]) {
isCorrectSize = true;
}
Expand Down
28 changes: 13 additions & 15 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as utils from '../src/utils.js'

import { logError, logWarn, parseSizesInput, _each, deepAccess } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

import { config } from '../src/config.js'
import { getStorageManager } from '../src/storageManager.js';
import includes from 'core-js-pure/features/array/includes';
Expand Down Expand Up @@ -51,7 +49,7 @@ function _getBrowserParams(topWindowUrl) {
topScreen = topWindow.screen;
topUrl = topWindowUrl || '';
} catch (error) {
utils.logError(error);
logError(error);
return browserParams
}

Expand Down Expand Up @@ -131,7 +129,7 @@ function isBidRequestValid(bid) {
const id = legacyParamID || params.slot || params.native || params.zone || params.pubID;

if (invalidRequestIds[id]) {
utils.logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`);
logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`);
return false;
}

Expand All @@ -146,12 +144,12 @@ function isBidRequestValid(bid) {
case !!(params.inVideo): break;
case !!(params.videoPubID): break;
default:
utils.logWarn(`[GumGum] No product selected for the placement ${adUnitCode}, please check your implementation.`);
logWarn(`[GumGum] No product selected for the placement ${adUnitCode}, please check your implementation.`);
return false;
}

if (params.bidfloor && !(typeof params.bidfloor === 'number' && isFinite(params.bidfloor))) {
utils.logWarn('[GumGum] bidfloor must be a Number');
logWarn('[GumGum] bidfloor must be a Number');
return false;
}

Expand All @@ -173,7 +171,7 @@ function _getVidParams(attributes) {
protocols = [],
playerSize = []
} = attributes;
const sizes = utils.parseSizesInput(playerSize);
const sizes = parseSizesInput(playerSize);
const [viw, vih] = sizes[0] && sizes[0].split('x');
let pr = '';

Expand Down Expand Up @@ -279,7 +277,7 @@ function buildRequests(validBidRequests, bidderRequest) {
const uspConsent = bidderRequest && bidderRequest.uspConsent;
const timeout = config.getConfig('bidderTimeout');
const topWindowUrl = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
utils._each(validBidRequests, bidRequest => {
_each(validBidRequests, bidRequest => {
const {
bidId,
mediaTypes = {},
Expand All @@ -299,9 +297,9 @@ function buildRequests(validBidRequests, bidderRequest) {
for (const eid in eids) data[eid] = eids[eid];

// ADJS-1024 & ADSS-1297
if (utils.deepAccess(ortb2Imp, 'ext.data.pbadslot')) {
gpid = utils.deepAccess(ortb2Imp, 'ext.data.pbadslot')
} else if (utils.deepAccess(ortb2Imp, 'ext.data.adserver.name')) {
if (deepAccess(ortb2Imp, 'ext.data.pbadslot')) {
gpid = deepAccess(ortb2Imp, 'ext.data.pbadslot')
} else if (deepAccess(ortb2Imp, 'ext.data.adserver.name')) {
gpid = ortb2Imp.ext.data.adserver.adslot
}

Expand Down Expand Up @@ -435,7 +433,7 @@ function interpretResponse(serverResponse, bidRequest) {
setTimeout(() => {
!!invalidRequestIds[id] && delete invalidRequestIds[id];
}, delayTime);
utils.logWarn(`[GumGum] Please check the implementation for ${id}`);
logWarn(`[GumGum] Please check the implementation for ${id}`);
}

const defaultResponse = {
Expand Down Expand Up @@ -483,14 +481,14 @@ function interpretResponse(serverResponse, bidRequest) {
advertiserDomains: advertiserDomains || [],
mediaType: type || mediaType
};
let sizes = utils.parseSizesInput(bidRequest.sizes);
let sizes = parseSizesInput(bidRequest.sizes);

if (maxw && maxh) {
sizes = [`${maxw}x${maxh}`];
} else if (product === 5 && includes(sizes, '1x1')) {
sizes = ['1x1'];
} else if (product === 2 && includes(sizes, '1x1')) {
sizes = responseWidth && responseHeight ? [`${responseWidth}x${responseHeight}`] : utils.parseSizesInput(bidRequest.sizes)
sizes = responseWidth && responseHeight ? [`${responseWidth}x${responseHeight}`] : parseSizesInput(bidRequest.sizes)
}

let [width, height] = sizes[0].split('x');
Expand Down
24 changes: 12 additions & 12 deletions modules/h12mediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { inIframe, logError, logMessage, deepAccess } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'h12media';
const DEFAULT_URL = 'https://bidder.h12-media.com/prebid/';
Expand All @@ -15,7 +15,7 @@ export const spec = {
},

buildRequests: function(validBidRequests, bidderRequest) {
const isiframe = utils.inIframe();
const isiframe = inIframe();
const screenSize = getClientDimensions();
const docSize = getDocumentDimensions();

Expand All @@ -24,7 +24,7 @@ export const spec = {
const requestUrl = bidderParams.endpointdom || DEFAULT_URL;
let pubsubid = bidderParams.pubsubid || '';
if (pubsubid && pubsubid.length > 32) {
utils.logError('Bidder param \'pubsubid\' should be not more than 32 chars.');
logError('Bidder param \'pubsubid\' should be not more than 32 chars.');
pubsubid = '';
}
const pubcontainerid = bidderParams.pubcontainerid;
Expand Down Expand Up @@ -57,7 +57,7 @@ export const spec = {
try {
windowTop = window.top;
} catch (e) {
utils.logMessage(e);
logMessage(e);
windowTop = window;
}

Expand All @@ -66,11 +66,11 @@ export const spec = {
url: requestUrl,
options: {withCredentials: true},
data: {
gdpr: !!utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies', false),
gdpr_cs: utils.deepAccess(bidderRequest, 'gdprConsent.consentString', ''),
usp: !!utils.deepAccess(bidderRequest, 'uspConsent', false),
usp_cs: utils.deepAccess(bidderRequest, 'uspConsent', ''),
topLevelUrl: utils.deepAccess(bidderRequest, 'refererInfo.referer', ''),
gdpr: !!deepAccess(bidderRequest, 'gdprConsent.gdprApplies', false),
gdpr_cs: deepAccess(bidderRequest, 'gdprConsent.consentString', ''),
usp: !!deepAccess(bidderRequest, 'uspConsent', false),
usp_cs: deepAccess(bidderRequest, 'uspConsent', ''),
topLevelUrl: deepAccess(bidderRequest, 'refererInfo.referer', ''),
refererUrl: windowTop.document.referrer,
isiframe,
version: '$prebid.version$',
Expand Down Expand Up @@ -122,14 +122,14 @@ export const spec = {
}
return bidResponses;
} catch (err) {
utils.logError(err);
logError(err);
}
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, usPrivacy) {
const syncs = [];
const uspApplies = !!utils.deepAccess(usPrivacy, 'uspConsent', false);
const uspString = utils.deepAccess(usPrivacy, 'uspConsent', '');
const uspApplies = !!deepAccess(usPrivacy, 'uspConsent', false);
const uspString = deepAccess(usPrivacy, 'uspConsent', '');
gdprConsent = gdprConsent || {
gdprApplies: false, consentString: '',
};
Expand Down
16 changes: 8 additions & 8 deletions modules/haloIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {ajax} from '../src/ajax.js';
import {getStorageManager} from '../src/storageManager.js';
import {submodule} from '../src/hook.js';
import * as utils from '../src/utils.js';
import { isFn, isStr, isPlainObject, logError } from '../src/utils.js';

const MODULE_NAME = 'haloId';
const AU_GVLID = 561;
Expand All @@ -21,9 +21,9 @@ export const storage = getStorageManager(AU_GVLID, 'halo');
* @param {String} defaultVal
*/
function paramOrDefault(param, defaultVal, arg) {
if (utils.isFn(param)) {
if (isFn(param)) {
return param(arg);
} else if (utils.isStr(param)) {
} else if (isStr(param)) {
return param;
}
return defaultVal;
Expand All @@ -44,7 +44,7 @@ export const haloIdSubmodule = {
*/
decode(value) {
let haloId = storage.getDataFromLocalStorage('auHaloId');
if (utils.isStr(haloId)) {
if (isStr(haloId)) {
return {haloId: haloId};
}
return (value && typeof value['haloId'] === 'string') ? { 'haloId': value['haloId'] } : undefined;
Expand All @@ -56,7 +56,7 @@ export const haloIdSubmodule = {
* @returns {IdResponse|undefined}
*/
getId(config) {
if (!utils.isPlainObject(config.params)) {
if (!isPlainObject(config.params)) {
config.params = {};
}
const url = paramOrDefault(config.params.url,
Expand All @@ -65,7 +65,7 @@ export const haloIdSubmodule = {

const resp = function (callback) {
let haloId = storage.getDataFromLocalStorage('auHaloId');
if (utils.isStr(haloId)) {
if (isStr(haloId)) {
const responseObj = {haloId: haloId};
callback(responseObj);
} else {
Expand All @@ -76,13 +76,13 @@ export const haloIdSubmodule = {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
logError(error);
}
}
callback(responseObj);
},
error: error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
callback();
}
};
Expand Down
14 changes: 7 additions & 7 deletions modules/hybridBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js'
import { _map, logWarn, deepAccess, isArray } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { auctionManager } from '../src/auctionManager.js'
import { BANNER, VIDEO } from '../src/mediaTypes.js'
Expand All @@ -21,7 +21,7 @@ const placementTypes = {
};

function buildBidRequests(validBidRequests) {
return utils._map(validBidRequests, function(validBidRequest) {
return _map(validBidRequests, function(validBidRequest) {
const params = validBidRequest.params;
const bidRequest = {
bidId: validBidRequest.bidId,
Expand Down Expand Up @@ -63,7 +63,7 @@ const createRenderer = (bid) => {
try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on renderer', err);
logWarn('Prebid Error calling setRender on renderer', err);
}

return renderer;
Expand Down Expand Up @@ -143,8 +143,8 @@ function hasVideoMandatoryParams(mediaTypes) {
const isHasVideoContext = !!mediaTypes.video && (mediaTypes.video.context === 'instream' || mediaTypes.video.context === 'outstream');

const isPlayerSize =
!!utils.deepAccess(mediaTypes, 'video.playerSize') &&
utils.isArray(utils.deepAccess(mediaTypes, 'video.playerSize'));
!!deepAccess(mediaTypes, 'video.playerSize') &&
isArray(deepAccess(mediaTypes, 'video.playerSize'));

return isHasVideoContext && isPlayerSize;
}
Expand Down Expand Up @@ -237,8 +237,8 @@ export const spec = {
let bidRequests = JSON.parse(bidRequest.data).bidRequests;
const serverBody = serverResponse.body;

if (serverBody && serverBody.bids && utils.isArray(serverBody.bids)) {
return utils._map(serverBody.bids, function(bid) {
if (serverBody && serverBody.bids && isArray(serverBody.bids)) {
return _map(serverBody.bids, function(bid) {
let rawBid = find(bidRequests, function (item) {
return item.bidId === bid.bidId;
});
Expand Down
14 changes: 7 additions & 7 deletions modules/iasRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArray, getAdUnitSizes, getKeys, logError } from '../src/utils.js';
import { submodule } from '../src/hook.js';
import { getGlobal } from '../src/prebidGlobal.js';
import * as utils from '../src/utils.js';
import { ajaxBuilder } from '../src/ajax.js';

/** @type {string} */
Expand All @@ -21,7 +21,7 @@ export function init(config, userConsent) {

function stringifySlotSizes(sizes) {
let result = '';
if (utils.isArray(sizes)) {
if (isArray(sizes)) {
result = sizes.reduce((acc, size) => {
acc.push(size.join('.'));
return acc;
Expand All @@ -32,12 +32,12 @@ function stringifySlotSizes(sizes) {
}

function stringifySlot(bidRequest, adUnitPath) {
const sizes = utils.getAdUnitSizes(bidRequest);
const sizes = getAdUnitSizes(bidRequest);
const id = bidRequest.code;
const ss = stringifySlotSizes(sizes);
const p = bidRequest.code;
const slot = { id, ss, p };
const keyValues = utils.getKeys(slot).map(function (key) {
const keyValues = getKeys(slot).map(function (key) {
return [key, slot[key]].join(':');
});
return '{' + keyValues.join(',') + '}';
Expand All @@ -62,7 +62,7 @@ function getPageLevelKeywords(response) {
}

function shallowMerge(dest, src) {
utils.getKeys(src).reduce((dest, srcKey) => {
getKeys(src).reduce((dest, srcKey) => {
dest[srcKey] = src[srcKey];
return dest;
}, dest);
Expand Down Expand Up @@ -114,7 +114,7 @@ function getBidRequestData(reqBidsConfigObj, callback, config) {
callback();
},
error: function () {
utils.logError('failed to retrieve targeting information');
logError('failed to retrieve targeting information');
callback();
}
});
Expand All @@ -128,7 +128,7 @@ function getTargetingData(adUnits, config, userConsent) {
targeting[adUnit] = bidResponses;
});
} catch (err) {
utils.logError('error', err);
logError('error', err);
}
return targeting;
}
Expand Down
Loading

0 comments on commit efa1ea3

Please sign in to comment.