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

* 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 866f090 commit 7ae15d6
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 259 deletions.
80 changes: 40 additions & 40 deletions modules/mediakeysBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getWindowTop, isFn, logWarn, getDNT, deepAccess, isArray, inIframe, mergeDeep, isStr, isEmpty, deepSetValue, deepClone, parseUrl, cleanObj, logError, triggerPixel } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import { createEidsArray } from './userId/eids.js';

const AUCTION_TYPE = 1;
Expand All @@ -19,7 +19,7 @@ const NET_REVENUE = true;
*/
function canAccessTopWindow() {
try {
return !!utils.getWindowTop().location.href;
return !!getWindowTop().location.href;
} catch (error) {
return false;
}
Expand Down Expand Up @@ -65,12 +65,12 @@ function getOS() {
* @returns {number|boolean}
*/
function getFloor(bid, mediaType, size = '*') {
if (!utils.isFn(bid.getFloor)) {
if (!isFn(bid.getFloor)) {
return false;
}

if (SUPPORTED_MEDIA_TYPES.indexOf(mediaType) === -1) {
utils.logWarn(`${BIDDER_CODE}: Unable to detect floor price for unsupported mediaType ${mediaType}. No floor will be used.`);
logWarn(`${BIDDER_CODE}: Unable to detect floor price for unsupported mediaType ${mediaType}. No floor will be used.`);
return false;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ function createOrtbTemplate() {
device: {
ip: '',
js: 1,
dnt: utils.getDNT(),
dnt: getDNT(),
ua: navigator.userAgent,
devicetype: getDeviceType(),
os: getOS(),
Expand Down Expand Up @@ -128,10 +128,10 @@ function createOrtbTemplate() {
*/
function createBannerImp(bid) {
let sizes = bid.mediaTypes.banner.sizes;
const params = utils.deepAccess(bid, 'params', {});
const params = deepAccess(bid, 'params', {});

if (!utils.isArray(sizes) || !sizes.length) {
utils.logWarn(`${BIDDER_CODE}: mediaTypes.banner.size missing for adunit: ${bid.params.adUnit}. Ignoring the banner impression in the adunit.`);
if (!isArray(sizes) || !sizes.length) {
logWarn(`${BIDDER_CODE}: mediaTypes.banner.size missing for adunit: ${bid.params.adUnit}. Ignoring the banner impression in the adunit.`);
} else {
const banner = {};

Expand All @@ -146,7 +146,7 @@ function createBannerImp(bid) {
});
banner.format = format;

banner.topframe = utils.inIframe() ? 0 : 1;
banner.topframe = inIframe() ? 0 : 1;
banner.pos = params.pos || 0;

return banner;
Expand Down Expand Up @@ -185,10 +185,10 @@ function createImp(bid) {
}

// handle FPD for imp.
const ortb2Imp = utils.deepAccess(bid, 'ortb2Imp.ext.data');
const ortb2Imp = deepAccess(bid, 'ortb2Imp.ext.data');
if (ortb2Imp) {
const fpd = { ...bid.ortb2Imp };
utils.mergeDeep(imp, fpd);
mergeDeep(imp, fpd);
}

return imp;
Expand All @@ -202,13 +202,13 @@ function createImp(bid) {
* @returns {string|null}
*/
function getPrimaryCatFromResponse(cat) {
if (!cat || (utils.isArray(cat) && !cat.length)) {
if (!cat || (isArray(cat) && !cat.length)) {
return;
}

if (utils.isArray(cat)) {
if (isArray(cat)) {
return cat[0];
} else if (utils.isStr(cat)) {
} else if (isStr(cat)) {
return cat;
}
}
Expand All @@ -221,19 +221,19 @@ export const spec = {
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,

isBidRequestValid: function(bid) {
return !!(bid && !utils.isEmpty(bid));
return !!(bid && !isEmpty(bid));
},

buildRequests: function(validBidRequests, bidderRequest) {
const payload = createOrtbTemplate();

// Pass the auctionId as ortb2 id
// See https://github.com/prebid/Prebid.js/issues/6563
utils.deepSetValue(payload, 'id', bidderRequest.auctionId);
utils.deepSetValue(payload, 'source.tid', bidderRequest.auctionId);
deepSetValue(payload, 'id', bidderRequest.auctionId);
deepSetValue(payload, 'source.tid', bidderRequest.auctionId);

validBidRequests.forEach(validBid => {
let bid = utils.deepClone(validBid);
let bid = deepClone(validBid);

// No additional params atm.
const imp = createImp(bid);
Expand All @@ -242,53 +242,53 @@ export const spec = {
});

if (validBidRequests[0].schain) {
utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain);
deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain);
}

if (bidderRequest && bidderRequest.gdprConsent) {
utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}

if (bidderRequest && bidderRequest.uspConsent) {
utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

if (config.getConfig('coppa') === true) {
utils.deepSetValue(payload, 'regs.coppa', 1);
deepSetValue(payload, 'regs.coppa', 1);
}

if (utils.deepAccess(validBidRequests[0], 'userId')) {
utils.deepSetValue(payload, 'user.ext.eids', createEidsArray(validBidRequests[0].userId));
if (deepAccess(validBidRequests[0], 'userId')) {
deepSetValue(payload, 'user.ext.eids', createEidsArray(validBidRequests[0].userId));
}

// Assign payload.site from refererinfo
if (bidderRequest.refererInfo) {
if (bidderRequest.refererInfo.reachedTop) {
const sitePage = bidderRequest.refererInfo.referer;
utils.deepSetValue(payload, 'site.page', sitePage);
utils.deepSetValue(payload, 'site.domain', utils.parseUrl(sitePage, {
deepSetValue(payload, 'site.page', sitePage);
deepSetValue(payload, 'site.domain', parseUrl(sitePage, {
noDecodeWholeURL: true
}).hostname);

if (canAccessTopWindow()) {
utils.deepSetValue(payload, 'site.ref', utils.getWindowTop().document.referrer);
deepSetValue(payload, 'site.ref', getWindowTop().document.referrer);
}
}
}

// Handle First Party Data (need publisher fpd setup)
const fpd = config.getConfig('ortb2') || {};
if (fpd.site) {
utils.mergeDeep(payload, { site: fpd.site });
mergeDeep(payload, { site: fpd.site });
}
if (fpd.user) {
utils.mergeDeep(payload, { user: fpd.user });
mergeDeep(payload, { user: fpd.user });
}
// Here we can handle device.geo prop
const deviceGeo = utils.deepAccess(fpd, 'device.geo');
const deviceGeo = deepAccess(fpd, 'device.geo');
if (deviceGeo) {
utils.mergeDeep(payload.device, { geo: deviceGeo });
mergeDeep(payload.device, { geo: deviceGeo });
}

const request = {
Expand All @@ -307,19 +307,19 @@ export const spec = {
const bidResponses = [];

try {
if (serverResponse.body && serverResponse.body.seatbid && utils.isArray(serverResponse.body.seatbid)) {
if (serverResponse.body && serverResponse.body.seatbid && isArray(serverResponse.body.seatbid)) {
const currency = serverResponse.body.cur || DEFAULT_CURRENCY;
const referrer = bidRequest.site && bidRequest.site.ref ? bidRequest.site.ref : '';

serverResponse.body.seatbid.forEach(bidderSeat => {
if (!utils.isArray(bidderSeat.bid) || !bidderSeat.bid.length) {
if (!isArray(bidderSeat.bid) || !bidderSeat.bid.length) {
return;
}

bidderSeat.bid.forEach(bid => {
let mediaType;
// Actually only BANNER is supported, but other types will be added soon.
switch (utils.deepAccess(bid, 'ext.prebid.type')) {
switch (deepAccess(bid, 'ext.prebid.type')) {
case 'V':
mediaType = VIDEO;
break;
Expand All @@ -332,8 +332,8 @@ export const spec = {

const meta = {
advertiserDomains: (Array.isArray(bid.adomain) && bid.adomain.length) ? bid.adomain : [],
advertiserName: utils.deepAccess(bid, 'ext.advertiser_name', null),
agencyName: utils.deepAccess(bid, 'ext.agency_name', null),
advertiserName: deepAccess(bid, 'ext.advertiser_name', null),
agencyName: deepAccess(bid, 'ext.agency_name', null),
primaryCatId: getPrimaryCatFromResponse(bid.cat),
mediaType
}
Expand All @@ -352,15 +352,15 @@ export const spec = {
ad: bid.adm,
mediaType,
burl: bid.burl,
meta: utils.cleanObj(meta)
meta: cleanObj(meta)
};

bidResponses.push(newBid);
});
});
}
} catch (e) {
utils.logError(BIDDER_CODE, e);
logError(BIDDER_CODE, e);
}

return bidResponses;
Expand All @@ -373,7 +373,7 @@ export const spec = {

const url = bid.burl.replace(/\$\{AUCTION_PRICE\}/, bid.cpm);

utils.triggerPixel(url);
triggerPixel(url);
}
}

Expand Down
Loading

0 comments on commit 7ae15d6

Please sign in to comment.