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#7496)

* 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 and Chris Pabst committed Jan 10, 2022
1 parent 5c55e0b commit d94f3f7
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 297 deletions.
20 changes: 10 additions & 10 deletions modules/seedtagBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js'
import { isArray, _map, triggerPixel } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { VIDEO, BANNER } from '../src/mediaTypes.js'

Expand Down Expand Up @@ -62,13 +62,13 @@ function hasMandatoryVideoParams(bid) {
const videoParams = getVideoParams(bid)

return hasVideoMediaType(bid) && !!videoParams.playerSize &&
utils.isArray(videoParams.playerSize) &&
isArray(videoParams.playerSize) &&
videoParams.playerSize.length > 0;
}

function buildBidRequest(validBidRequest) {
const params = validBidRequest.params;
const mediaTypes = utils._map(
const mediaTypes = _map(
Object.keys(validBidRequest.mediaTypes),
function (pbjsType) {
return mediaTypesMap[pbjsType];
Expand Down Expand Up @@ -145,8 +145,8 @@ function buildBidResponse(seedtagBid) {
export function getTimeoutUrl (data) {
let queryParams = '';
if (
utils.isArray(data) && data[0] &&
utils.isArray(data[0].params) && data[0].params[0]
isArray(data) && data[0] &&
isArray(data[0].params) && data[0].params[0]
) {
const params = data[0].params[0];
queryParams =
Expand Down Expand Up @@ -186,7 +186,7 @@ export const spec = {
timeout: bidderRequest.timeout,
version: '$prebid.version$',
connectionType: getConnectionType(),
bidRequests: utils._map(validBidRequests, buildBidRequest)
bidRequests: _map(validBidRequests, buildBidRequest)
};

if (payload.cmp) {
Expand All @@ -211,8 +211,8 @@ export const spec = {
*/
interpretResponse: function(serverResponse) {
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) {
return buildBidResponse(bid);
});
} else {
Expand Down Expand Up @@ -243,7 +243,7 @@ export const spec = {
*/
onTimeout(data) {
const url = getTimeoutUrl(data);
utils.triggerPixel(url);
triggerPixel(url);
},

/**
Expand All @@ -252,7 +252,7 @@ export const spec = {
*/
onBidWon: function (bid) {
if (bid && bid.nurl) {
utils.triggerPixel(bid.nurl);
triggerPixel(bid.nurl);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions modules/sharedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @requires module:modules/userId
*/

import * as utils from '../src/utils.js';
import { parseUrl, buildUrl, triggerPixel, logInfo, hasDeviceAccess, generateUUID } from '../src/utils.js';
import {submodule} from '../src/hook.js';
import { coppaDataHandler } from '../src/adapterManager.js';
import {getStorageManager} from '../src/storageManager.js';
Expand Down Expand Up @@ -53,12 +53,12 @@ function queuePixelCallback(pixelUrl, id = '', callback) {
}

// Use pubcid as a cache buster
const urlInfo = utils.parseUrl(pixelUrl);
const urlInfo = parseUrl(pixelUrl);
urlInfo.search.id = encodeURIComponent('pubcid:' + id);
const targetUrl = utils.buildUrl(urlInfo);
const targetUrl = buildUrl(urlInfo);

return function () {
utils.triggerPixel(targetUrl);
triggerPixel(targetUrl);
};
}

Expand Down Expand Up @@ -89,10 +89,10 @@ export const sharedIdSystemSubmodule = {
*/
decode(value, config) {
if (hasOptedOut()) {
utils.logInfo('PubCommonId decode: Has opted-out');
logInfo('PubCommonId decode: Has opted-out');
return undefined;
}
utils.logInfo(' Decoded value PubCommonId ' + value);
logInfo(' Decoded value PubCommonId ' + value);
const idObj = {'pubcid': value};
return idObj;
},
Expand All @@ -106,13 +106,13 @@ export const sharedIdSystemSubmodule = {
*/
getId: function (config = {}, consentData, storedId) {
if (hasOptedOut()) {
utils.logInfo('PubCommonId: Has opted-out');
logInfo('PubCommonId: Has opted-out');
return;
}
const coppa = coppaDataHandler.getCoppa();

if (coppa) {
utils.logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId');
logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId');
return;
}
const {params: {create = true, pixelUrl} = {}} = config;
Expand All @@ -126,7 +126,7 @@ export const sharedIdSystemSubmodule = {
} catch (e) {
}

if (!newId) newId = (create && utils.hasDeviceAccess()) ? utils.generateUUID() : undefined;
if (!newId) newId = (create && hasDeviceAccess()) ? generateUUID() : undefined;
}

const pixelCallback = queuePixelCallback(pixelUrl, newId);
Expand All @@ -153,12 +153,12 @@ export const sharedIdSystemSubmodule = {
*/
extendId: function(config = {}, consentData, storedId) {
if (hasOptedOut()) {
utils.logInfo('PubCommonId: Has opted-out');
logInfo('PubCommonId: Has opted-out');
return {id: undefined};
}
const coppa = coppaDataHandler.getCoppa();
if (coppa) {
utils.logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId');
logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId');
return;
}
const {params: {extend = false, pixelUrl} = {}} = config;
Expand Down
16 changes: 8 additions & 8 deletions modules/sharethroughAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tryAppendQueryString } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
const utils = require('../src/utils.js');

const emptyUrl = '';
const analyticsType = 'endpoint';
Expand Down Expand Up @@ -42,18 +42,18 @@ var sharethroughAdapter = Object.assign(adapter(

fireLoseBeacon(winningBidderCode, winningCPM, arid, type) {
let loseBeaconUrl = this.STR_BEACON_HOST;
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'winnerBidderCode', winningBidderCode);
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'winnerCpm', winningCPM);
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'arid', arid);
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'type', type);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerBidderCode', winningBidderCode);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerCpm', winningCPM);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'arid', arid);
loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'type', type);
loseBeaconUrl = this.appendEnvFields(loseBeaconUrl);

this.fireBeacon(loseBeaconUrl);
},
appendEnvFields(url) {
url = utils.tryAppendQueryString(url, 'hbVersion', '$prebid.version$');
url = utils.tryAppendQueryString(url, 'strVersion', STR_VERSION);
url = utils.tryAppendQueryString(url, 'hbSource', 'prebid');
url = tryAppendQueryString(url, 'hbVersion', '$prebid.version$');
url = tryAppendQueryString(url, 'strVersion', STR_VERSION);
url = tryAppendQueryString(url, 'hbSource', 'prebid');

return url;
},
Expand Down
16 changes: 8 additions & 8 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateUUID, deepAccess, inIframe } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { createEidsArray } from './userId/eids.js';
Expand Down Expand Up @@ -29,7 +29,7 @@ export const sharethroughAdapterSpec = {
const secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1);

const req = {
id: utils.generateUUID(),
id: generateUUID(),
at: 1,
cur: ['USD'],
tmax: timeout,
Expand Down Expand Up @@ -82,7 +82,7 @@ export const sharethroughAdapterSpec = {
const imps = bidRequests.map(bidReq => {
const impression = {};

const gpid = utils.deepAccess(bidReq, 'ortb2Imp.ext.data.pbadslot');
const gpid = deepAccess(bidReq, 'ortb2Imp.ext.data.pbadslot');
if (gpid) {
impression.ext = { gpid: gpid };
}
Expand All @@ -104,7 +104,7 @@ export const sharethroughAdapterSpec = {

impression.video = {
pos: nullish(videoRequest.pos, 0),
topframe: utils.inIframe() ? 0 : 1,
topframe: inIframe() ? 0 : 1,
skip: nullish(videoRequest.skip, 0),
linearity: nullish(videoRequest.linearity, 1),
minduration: nullish(videoRequest.minduration, 5),
Expand All @@ -126,8 +126,8 @@ export const sharethroughAdapterSpec = {
if (videoRequest.companionad) impression.video.companionad = videoRequest.companionad;
} else {
impression.banner = {
pos: utils.deepAccess(bidReq, 'mediaTypes.banner.pos', 0),
topframe: utils.inIframe() ? 0 : 1,
pos: deepAccess(bidReq, 'mediaTypes.banner.pos', 0),
topframe: inIframe() ? 0 : 1,
format: bidReq.sizes.map(size => ({ w: +size[0], h: +size[1] })),
};
}
Expand Down Expand Up @@ -252,9 +252,9 @@ function getBidRequestFloor(bid) {
}

function userIdAsEids(bidRequest) {
const eids = createEidsArray(utils.deepAccess(bidRequest, 'userId')) || [];
const eids = createEidsArray(deepAccess(bidRequest, 'userId')) || [];

const flocData = utils.deepAccess(bidRequest, 'userId.flocId');
const flocData = deepAccess(bidRequest, 'userId.flocId');
const isFlocIdValid = flocData && flocData.id && flocData.version;
if (isFlocIdValid) {
eids.push({
Expand Down
46 changes: 23 additions & 23 deletions modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, getBidIdParameter, getWindowTop, logError } from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -32,18 +32,18 @@ export const spec = {
let adUnits = [];
const pageURL = validBidRequests[0].params.contentPageUrl || bidderRequest.refererInfo.referer;
const isStage = !!validBidRequests[0].params.stage;
const isOutstream = utils.deepAccess(validBidRequests[0], 'mediaTypes.video.context') === 'outstream';
const isCustomRender = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.customRender');
const isNodeRender = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.slot') || utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.iframe');
const isNativeRender = utils.deepAccess(validBidRequests[0], 'renderer');
const outstreamOptions = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions');
const isOutstream = deepAccess(validBidRequests[0], 'mediaTypes.video.context') === 'outstream';
const isCustomRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.customRender');
const isNodeRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.slot') || deepAccess(validBidRequests[0], 'params.outstreamOptions.iframe');
const isNativeRender = deepAccess(validBidRequests[0], 'renderer');
const outstreamOptions = deepAccess(validBidRequests[0], 'params.outstreamOptions');
const isBanner = !!validBidRequests[0].mediaTypes.banner || (isOutstream && !(isCustomRender || isNativeRender || isNodeRender));
const defaultSchain = validBidRequests[0].schain || {};

validBidRequests.forEach((bid) => {
const videoSizes = getVideoSizes(bid);
const bannerSizes = getBannerSizes(bid);
const vpaidMode = utils.getBidIdParameter('vpaidMode', bid.params);
const vpaidMode = getBidIdParameter('vpaidMode', bid.params);

const makeBids = (type, size) => {
let context = '';
Expand All @@ -52,7 +52,7 @@ export const spec = {
if (type === BANNER) {
streamType = 5;
} else {
context = utils.deepAccess(bid, 'mediaTypes.video.context');
context = deepAccess(bid, 'mediaTypes.video.context');
if (vpaidMode && context === 'instream') {
streamType = 1;
}
Expand All @@ -66,7 +66,7 @@ export const spec = {
bidId: bid.bidId,
mediaType: type,
context: context,
playerId: utils.getBidIdParameter('playerId', bid.params),
playerId: getBidIdParameter('playerId', bid.params),
auctionId: bidderRequest.auctionId,
bidderCode: BIDDER_CODE,
gdprConsent: bidderRequest.gdprConsent,
Expand Down Expand Up @@ -100,7 +100,7 @@ export const spec = {
'adapterVersion': 2,
'pageURL': encodeURIComponent(pageURL),
'vastCacheEnabled': (!!config.getConfig('cache') && !isBanner && !outstreamOptions) || false,
'isDesktop': utils.getWindowTop().document.documentElement.clientWidth > 700,
'isDesktop': getWindowTop().document.documentElement.clientWidth > 700,
'xmlAndTag': !!(isOutstream && isCustomRender) || false,
'stage': isStage || undefined
},
Expand Down Expand Up @@ -192,9 +192,9 @@ function createBids(bidRes, reqData) {
vastXml: bid.vastXml,
debug: reqData.debug,
isStage: !!reqData.meta.stage,
customRender: utils.getBidIdParameter('customRender', currentBidParams.outstreamOptions),
slot: utils.getBidIdParameter('slot', currentBidParams.outstreamOptions),
iframe: utils.getBidIdParameter('iframe', currentBidParams.outstreamOptions),
customRender: getBidIdParameter('customRender', currentBidParams.outstreamOptions),
slot: getBidIdParameter('slot', currentBidParams.outstreamOptions),
iframe: getBidIdParameter('iframe', currentBidParams.outstreamOptions),
}
});
renderer.setRender(outstreamRender);
Expand All @@ -212,28 +212,28 @@ function outstreamRender(bid) {
bid.renderer.config.customRender(bid, embedCode);
} else {
try {
const inIframe = utils.getBidIdParameter('iframe', bid.renderer.config);
const inIframe = getBidIdParameter('iframe', bid.renderer.config);
if (inIframe && window.document.getElementById(inIframe).nodeName === 'IFRAME') {
const iframe = window.document.getElementById(inIframe);
let framedoc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
framedoc.body.appendChild(embedCode);
return;
}

const slot = utils.getBidIdParameter('slot', bid.renderer.config) || bid.adUnitCode;
const slot = getBidIdParameter('slot', bid.renderer.config) || bid.adUnitCode;
if (slot && window.document.getElementById(slot)) {
window.document.getElementById(slot).appendChild(embedCode);
} else if (slot) {
utils.logError('[ShowHeroes][renderer] Error: spot not found');
logError('[ShowHeroes][renderer] Error: spot not found');
}
} catch (err) {
utils.logError('[ShowHeroes][renderer] Error:' + err.message)
logError('[ShowHeroes][renderer] Error:' + err.message)
}
}
}

function createOutstreamEmbedCode(bid) {
const isStage = utils.getBidIdParameter('isStage', bid.renderer.config);
const isStage = getBidIdParameter('isStage', bid.renderer.config);
const urls = getEnvURLs(isStage);

const fragment = window.document.createDocumentFragment();
Expand All @@ -245,9 +245,9 @@ function createOutstreamEmbedCode(bid) {

const spot = window.document.createElement('div');
spot.setAttribute('class', 'showheroes-spot');
spot.setAttribute('data-player', utils.getBidIdParameter('playerId', bid.renderer.config));
spot.setAttribute('data-debug', utils.getBidIdParameter('debug', bid.renderer.config));
spot.setAttribute('data-ad-vast-tag', utils.getBidIdParameter('vastUrl', bid.renderer.config));
spot.setAttribute('data-player', getBidIdParameter('playerId', bid.renderer.config));
spot.setAttribute('data-debug', getBidIdParameter('debug', bid.renderer.config));
spot.setAttribute('data-ad-vast-tag', getBidIdParameter('vastUrl', bid.renderer.config));
spot.setAttribute('data-stream-type', 'outstream');

fragment.appendChild(spot);
Expand Down Expand Up @@ -275,11 +275,11 @@ function getBannerHtml (bid, reqBid, reqData) {
}

function getVideoSizes(bidRequest) {
return formatSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') || []);
return formatSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize') || []);
}

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

function formatSizes(sizes) {
Expand Down
Loading

0 comments on commit d94f3f7

Please sign in to comment.