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 (#7502)

* 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 0624937 commit 23215eb
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 256 deletions.
48 changes: 24 additions & 24 deletions modules/videobyteBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logMessage, logError, deepAccess, isFn, isPlainObject, isStr, isNumber, isArray, deepSetValue } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import {VIDEO} from '../src/mediaTypes.js';

const BIDDER_CODE = 'videobyte';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const spec = {
const {params} = bidRequest;
let pubId = params.pubId;
if (bidRequest.params.video && bidRequest.params.video.e2etest) {
utils.logMessage('E2E test mode enabled');
logMessage('E2E test mode enabled');
pubId = 'e2etest'
}
return {
Expand Down Expand Up @@ -98,7 +98,7 @@ export const spec = {
bidResponses.push(bidResponse)
}
} else {
utils.logError('invalid server response received');
logError('invalid server response received');
}
return bidResponses;
},
Expand All @@ -118,7 +118,7 @@ export const spec = {
}

serverResponses.forEach(resp => {
const userSync = utils.deepAccess(resp, 'body.ext.usersync');
const userSync = deepAccess(resp, 'body.ext.usersync');
if (userSync) {
let syncDetails = [];
Object.keys(userSync).forEach(key => {
Expand Down Expand Up @@ -152,8 +152,8 @@ export const spec = {
function buildRequestData(bidRequest, bidderRequest) {
const {params} = bidRequest;

const videoAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {});
const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = deepAccess(bidRequest, 'params.video', {});

const videoParams = {
...videoAdUnit,
Expand Down Expand Up @@ -194,7 +194,7 @@ function buildRequestData(bidRequest, bidderRequest) {
size: '*'
};
let floorData = bidRequest.params
if (utils.isFn(bidRequest.getFloor)) {
if (isFn(bidRequest.getFloor)) {
floorData = bidRequest.getFloor(bidFloorRequest);
} else {
if (params.bidfloor) {
Expand Down Expand Up @@ -226,41 +226,41 @@ function buildRequestData(bidRequest, bidderRequest) {
};

// content
if (videoParams.content && utils.isPlainObject(videoParams.content)) {
if (videoParams.content && isPlainObject(videoParams.content)) {
openrtbRequest.site.content = {};
const contentStringKeys = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language'];
const contentNumberkeys = ['episode', 'prodq', 'context', 'livestream', 'len'];
const contentArrayKeys = ['cat'];
const contentObjectKeys = ['ext'];
for (const contentKey in videoBidderParams.content) {
if (
(contentStringKeys.indexOf(contentKey) > -1 && utils.isStr(videoParams.content[contentKey])) ||
(contentNumberkeys.indexOf(contentKey) > -1 && utils.isNumber(videoParams.content[contentKey])) ||
(contentObjectKeys.indexOf(contentKey) > -1 && utils.isPlainObject(videoParams.content[contentKey])) ||
(contentArrayKeys.indexOf(contentKey) > -1 && utils.isArray(videoParams.content[contentKey]) &&
videoParams.content[contentKey].every(catStr => utils.isStr(catStr)))) {
(contentStringKeys.indexOf(contentKey) > -1 && isStr(videoParams.content[contentKey])) ||
(contentNumberkeys.indexOf(contentKey) > -1 && isNumber(videoParams.content[contentKey])) ||
(contentObjectKeys.indexOf(contentKey) > -1 && isPlainObject(videoParams.content[contentKey])) ||
(contentArrayKeys.indexOf(contentKey) > -1 && isArray(videoParams.content[contentKey]) &&
videoParams.content[contentKey].every(catStr => isStr(catStr)))) {
openrtbRequest.site.content[contentKey] = videoParams.content[contentKey];
} else {
utils.logMessage('videobyte bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined');
logMessage('videobyte bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined');
}
}
}

// adding schain object
if (bidRequest.schain) {
utils.deepSetValue(openrtbRequest, 'source.ext.schain', bidRequest.schain);
deepSetValue(openrtbRequest, 'source.ext.schain', bidRequest.schain);
openrtbRequest.source.ext.schain.nodes[0].rid = openrtbRequest.id;
}

// Attaching GDPR Consent Params
if (bidderRequest.gdprConsent) {
utils.deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
utils.deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}

// CCPA
if (bidderRequest.uspConsent) {
utils.deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent);
deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}
return openrtbRequest;
}
Expand All @@ -271,12 +271,12 @@ function validateVideo(bidRequest) {
}

if (!bidRequest.params.pubId) {
utils.logError('failed validation: publisher id not declared');
logError('failed validation: publisher id not declared');
return false;
}

const videoAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {});
const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = deepAccess(bidRequest, 'params.video', {});

if (videoBidderParams && videoBidderParams.e2etest) {
return true;
Expand All @@ -288,16 +288,16 @@ function validateVideo(bidRequest) {
};

if (!videoParams.context) {
utils.logError('failed validation: context id not declared');
logError('failed validation: context id not declared');
return false;
}
if (videoParams.context !== 'instream') {
utils.logError('failed validation: only context instream is supported ');
logError('failed validation: only context instream is supported ');
return false;
}

if (typeof videoParams.playerSize === 'undefined' || !Array.isArray(videoParams.playerSize) || !Array.isArray(videoParams.playerSize[0])) {
utils.logError('failed validation: player size not declared or is not in format [[w,h]]');
logError('failed validation: player size not declared or is not in format [[w,h]]');
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions modules/videoreachBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getValue, getBidIdParameter } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
const utils = require('../src/utils.js');
const BIDDER_CODE = 'videoreach';
const ENDPOINT_URL = 'https://a.videoreach.com/hb/';
const GVLID = 547;
Expand All @@ -17,12 +17,12 @@ export const spec = {
let data = {
data: validBidRequests.map(function(bid) {
return {
TagId: utils.getValue(bid.params, 'TagId'),
adUnitCode: utils.getBidIdParameter('adUnitCode', bid),
bidId: utils.getBidIdParameter('bidId', bid),
bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid),
auctionId: utils.getBidIdParameter('auctionId', bid),
transactionId: utils.getBidIdParameter('transactionId', bid)
TagId: getValue(bid.params, 'TagId'),
adUnitCode: getBidIdParameter('adUnitCode', bid),
bidId: getBidIdParameter('bidId', bid),
bidderRequestId: getBidIdParameter('bidderRequestId', bid),
auctionId: getBidIdParameter('auctionId', bid),
transactionId: getBidIdParameter('transactionId', bid)
}
})
};
Expand Down
18 changes: 9 additions & 9 deletions modules/vidoomyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError, deepAccess } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import * as utils from '../src/utils.js';
import { Renderer } from '../src/Renderer.js';
import { INSTREAM, OUTSTREAM } from '../src/video.js';

Expand All @@ -13,22 +13,22 @@ const COOKIE_SYNC_JSON = 'https://vpaid.vidoomy.com/sync/urls.json';

const isBidRequestValid = bid => {
if (!bid.params) {
utils.logError(BIDDER_CODE + ': bid.params should be non-empty');
logError(BIDDER_CODE + ': bid.params should be non-empty');
return false;
}

if (!+bid.params.pid) {
utils.logError(BIDDER_CODE + ': bid.params.pid should be non-empty Number');
logError(BIDDER_CODE + ': bid.params.pid should be non-empty Number');
return false;
}

if (!+bid.params.id) {
utils.logError(BIDDER_CODE + ': bid.params.id should be non-empty Number');
logError(BIDDER_CODE + ': bid.params.id should be non-empty Number');
return false;
}

if (bid.params && bid.params.mediaTypes && bid.params.mediaTypes.video && bid.params.mediaTypes.video.context === INSTREAM && !bid.params.mediaTypes.video.playerSize) {
utils.logError(BIDDER_CODE + ': bid.params.mediaType.video should have a playerSize property to tell player size when is INSTREAM');
logError(BIDDER_CODE + ': bid.params.mediaType.video should have a playerSize property to tell player size when is INSTREAM');
return false;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ const buildRequests = (validBidRequests, bidderRequest) => {
aElement.href = (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) || top.location.href;
const hostname = aElement.hostname

const videoContext = utils.deepAccess(bid, 'mediaTypes.video.context');
const videoContext = deepAccess(bid, 'mediaTypes.video.context');

const queryParams = [];
queryParams.push(['id', bid.params.id]);
Expand Down Expand Up @@ -146,7 +146,7 @@ const interpretResponse = (serverResponse, bidRequest) => {
responseBody.renderer = renderer;
} catch (e) {
responseBody.ad = responseBody.vastUrl;
utils.logError(BIDDER_CODE + ': error while installing renderer to show outstream ad');
logError(BIDDER_CODE + ': error while installing renderer to show outstream ad');
}
}
}
Expand Down Expand Up @@ -186,12 +186,12 @@ const interpretResponse = (serverResponse, bidRequest) => {
if (isBidResponseValid(bid)) {
bids.push(bid);
} else {
utils.logError(BIDDER_CODE + ': server returns invalid response');
logError(BIDDER_CODE + ': server returns invalid response');
}

return bids;
} catch (e) {
utils.logError(BIDDER_CODE + ': error parsing server response to Prebid format');
logError(BIDDER_CODE + ': error parsing server response to Prebid format');
return [];
}
};
Expand Down
34 changes: 17 additions & 17 deletions modules/viewdeosDXBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, isArray, flatten, logError, parseSizesInput } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {VIDEO, BANNER} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
Expand All @@ -16,7 +16,7 @@ export const spec = {
gvlid: 924,
supportedMediaTypes: [VIDEO, BANNER],
isBidRequestValid: function (bid) {
return !!utils.deepAccess(bid, 'params.aid');
return !!deepAccess(bid, 'params.aid');
},
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];
Expand All @@ -43,9 +43,9 @@ export const spec = {
}

if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) {
utils.isArray(serverResponses) && serverResponses.forEach((response) => {
isArray(serverResponses) && serverResponses.forEach((response) => {
if (response.body) {
if (utils.isArray(response.body)) {
if (isArray(response.body)) {
response.body.forEach(b => {
addSyncs(b);
})
Expand Down Expand Up @@ -81,28 +81,28 @@ export const spec = {
serverResponse = serverResponse.body;
let bids = [];

if (!utils.isArray(serverResponse)) {
if (!isArray(serverResponse)) {
return parseRTBResponse(serverResponse, bidderRequest);
}

serverResponse.forEach(serverBidResponse => {
bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, bidderRequest));
bids = flatten(bids, parseRTBResponse(serverBidResponse, bidderRequest));
});

return bids;
}
};

function parseRTBResponse(serverResponse, bidderRequest) {
const isInvalidValidResp = !serverResponse || !utils.isArray(serverResponse.bids);
const isInvalidValidResp = !serverResponse || !isArray(serverResponse.bids);

const bids = [];

if (isInvalidValidResp) {
const extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : '';
const errorMessage = `in response for ${bidderRequest.bidderCode} adapter ${extMessage}`;

utils.logError(errorMessage);
logError(errorMessage);

return bids;
}
Expand All @@ -125,15 +125,15 @@ function parseRTBResponse(serverResponse, bidderRequest) {

function bidToTag(bidRequests, bidderRequest) {
const tag = {
domain: utils.deepAccess(bidderRequest, 'refererInfo.referer')
domain: deepAccess(bidderRequest, 'refererInfo.referer')
};

if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) {
if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) {
tag.gdpr = 1;
tag.gdpr_consent = utils.deepAccess(bidderRequest, 'gdprConsent.consentString');
tag.gdpr_consent = deepAccess(bidderRequest, 'gdprConsent.consentString');
}

if (utils.deepAccess(bidderRequest, 'bidderRequest.uspConsent')) {
if (deepAccess(bidderRequest, 'bidderRequest.uspConsent')) {
tag.us_privacy = bidderRequest.uspConsent;
}

Expand All @@ -151,14 +151,14 @@ function bidToTag(bidRequests, bidderRequest) {
* @returns {object}
*/
function prepareRTBRequestParams(_index, bid) {
const mediaType = utils.deepAccess(bid, 'mediaTypes.video') ? VIDEO : DISPLAY;
const mediaType = deepAccess(bid, 'mediaTypes.video') ? VIDEO : DISPLAY;
const index = !_index ? '' : `${_index + 1}`;
const sizes = bid.sizes ? bid.sizes : (mediaType === VIDEO ? utils.deepAccess(bid, 'mediaTypes.video.playerSize') : utils.deepAccess(bid, 'mediaTypes.banner.sizes'));
const sizes = bid.sizes ? bid.sizes : (mediaType === VIDEO ? deepAccess(bid, 'mediaTypes.video.playerSize') : deepAccess(bid, 'mediaTypes.banner.sizes'));
return {
['callbackId' + index]: bid.bidId,
['aid' + index]: bid.params.aid,
['ad_type' + index]: mediaType,
['sizes' + index]: utils.parseSizesInput(sizes).join()
['sizes' + index]: parseSizesInput(sizes).join()
};
}

Expand All @@ -168,8 +168,8 @@ function prepareRTBRequestParams(_index, bid) {
* @returns {object}
*/
function getMediaType(bidderRequest) {
const videoMediaType = utils.deepAccess(bidderRequest, 'mediaTypes.video');
const context = utils.deepAccess(bidderRequest, 'mediaTypes.video.context');
const videoMediaType = deepAccess(bidderRequest, 'mediaTypes.video');
const context = deepAccess(bidderRequest, 'mediaTypes.video.context');

return !videoMediaType ? DISPLAY : context === OUTSTREAM ? OUTSTREAM : VIDEO;
}
Expand Down
13 changes: 6 additions & 7 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as utils from '../src/utils.js';
import { triggerPixel, parseSizesInput, deepAccess, logError } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { INSTREAM as VIDEO_INSTREAM } from '../src/video.js';
const { parseSizesInput, logError, deepAccess } = utils;
const BIDDER_CODE = 'visx';
const GVLID = 154;
const BASE_URL = 'https://t.visx.net';
Expand Down Expand Up @@ -188,18 +187,18 @@ export const spec = {
onSetTargeting: function(bid) {
// Call '/track/pending' with the corresponding bid.requestId
if (bid.ext && bid.ext.events && bid.ext.events.pending) {
utils.triggerPixel(bid.ext.events.pending);
triggerPixel(bid.ext.events.pending);
}
},
onBidWon: function(bid) {
// Call '/track/win' with the corresponding bid.requestId
if (bid.ext && bid.ext.events && bid.ext.events.win) {
utils.triggerPixel(bid.ext.events.win);
triggerPixel(bid.ext.events.win);
}
},
onTimeout: function(timeoutData) {
// Call '/track/bid_timeout' with timeout data
utils.triggerPixel(buildUrl(TRACK_TIMEOUT_PATH) + '?data=' + JSON.stringify(timeoutData));
triggerPixel(buildUrl(TRACK_TIMEOUT_PATH) + '?data=' + JSON.stringify(timeoutData));
}
};

Expand All @@ -210,7 +209,7 @@ function buildUrl(path) {
function makeBanner(bannerParams) {
const bannerSizes = bannerParams && bannerParams.sizes;
if (bannerSizes) {
const sizes = utils.parseSizesInput(bannerSizes);
const sizes = parseSizesInput(bannerSizes);
if (sizes.length) {
const format = sizes.map(size => {
const [ width, height ] = size.split('x');
Expand All @@ -229,7 +228,7 @@ function makeVideo(videoParams = {}) {
.reduce((result, param) => {
result[param] = videoParams[param];
return result;
}, { w: utils.deepAccess(videoParams, 'playerSize.0.0'), h: utils.deepAccess(videoParams, 'playerSize.0.1') });
}, { w: deepAccess(videoParams, 'playerSize.0.0'), h: deepAccess(videoParams, 'playerSize.0.1') });

if (video.w && video.h && video.mimes) {
return video;
Expand Down
Loading

0 comments on commit 23215eb

Please sign in to comment.