Skip to content

Commit

Permalink
null-safe getFloor in adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Komorski authored and Marcin Komorski committed Oct 22, 2024
1 parent 70f722c commit 3ac680f
Show file tree
Hide file tree
Showing 78 changed files with 115 additions and 109 deletions.
2 changes: 1 addition & 1 deletion libraries/advangUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function isVideoBid(bid) {

export function getBannerBidFloor(bid) {
let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {};
return floorInfo.floor || getBannerBidParam(bid, 'bidfloor');
return floorInfo?.floor || getBannerBidParam(bid, 'bidfloor');
}

export function getVideoBidFloor(bid) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/currencyUtils/floor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (_) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/dspxUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (_) {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/precisoUtils/bidUtilsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (_) {
return 0
}
Expand Down
5 changes: 3 additions & 2 deletions libraries/riseUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
isEmpty,
contains,
isInteger,
getBidIdParameter
getBidIdParameter,
isPlainObject
} from '../../src/utils.js';
import { BANNER, VIDEO } from '../../src/mediaTypes.js';
import {config} from '../../src/config.js';
Expand All @@ -19,7 +20,7 @@ export function getFloor(bid, mediaType) {
mediaType: mediaType,
size: '*'
});
return floorResult.currency === 'USD' && floorResult.floor ? floorResult.floor : 0;
return isPlainObject(floorResult) && floorResult.currency === 'USD' && floorResult.floor ? floorResult.floor : 0;
}

export function getSizesArray(bid, mediaType) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/teqblazeUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getBidFloor = (bid) => {
size: '*',
});

return bidFloor.floor;
return bidFloor?.floor;
} catch (err) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/vidazooUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
size: '*'
});

if (floorInfo.currency === 'USD') {
if (floorInfo?.currency === 'USD') {
bidFloor = floorInfo.floor;
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/xeUtils/bidderUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepAccess, getBidIdParameter, isFn, logError, isArray, parseSizesInput} from '../../src/utils.js';
import {deepAccess, getBidIdParameter, isFn, logError, isArray, parseSizesInput, isPlainObject} from '../../src/utils.js';
import {getAdUnitSizes} from '../sizeUtils/sizeUtils.js';
import {findIndex} from '../../src/polyfill.js';

Expand All @@ -13,7 +13,7 @@ export function getBidFloor(bid, currency = 'USD') {
size: '*'
});

if (typeof floor === 'object' && !isNaN(floor.floor) && floor.currency === currency) {
if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === currency) {
return floor.floor;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ function _getBidFloors(bidRequest, size, mediaType) {
size: [ size.w, size.h ]
});

if (!isNaN(bidFloors.floor) && (bidFloors.currency === CURRENCY)) {
if (!isNaN(bidFloors?.floor) && (bidFloors?.currency === CURRENCY)) {
return bidFloors.floor;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function _getFloors(bidRequest) {
floors.push(cleanObj({
mt: mediaType,
s: isArray(size) ? `${size[0]}x${size[1]}` : undefined,
f: (!isNaN(info.floor) && info.currency === CURRENCY) ? info.floor : undefined
f: (!isNaN(info?.floor) && info?.currency === CURRENCY) ? info?.floor : undefined
}));
}

Expand Down
4 changes: 2 additions & 2 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export const spec = {
mediaType: '*'
}) : {};

const bidfloor = floorInfo.floor;
const bidfloorcur = floorInfo.currency;
const bidfloor = floorInfo?.floor;
const bidfloorcur = floorInfo?.currency;
const { mid, inv, mname } = bid.params;
const impExtData = bid.ortb2Imp?.ext?.data;

Expand Down
2 changes: 1 addition & 1 deletion modules/admixerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (_) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ function getFloor(adUnit, size, mediaType, currency) {

const floorResult = adUnit.getFloor({ currency, mediaType, size });

return floorResult.currency === currency ? floorResult.floor : 0;
return floorResult?.currency === currency ? floorResult?.floor : 0;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions modules/adriverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ADRIVER BID ADAPTER for Prebid 1.13
import {logInfo, getWindowLocation, _each, getBidIdParameter} from '../src/utils.js';
import {logInfo, getWindowLocation, _each, getBidIdParameter, isPlainObject} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';

Expand Down Expand Up @@ -188,12 +188,12 @@ function _getFloor(bid, currencyPar, sizes) {
size: isSize ? sizes : '*'
});

if (typeof floorInfo === 'object' &&
!isNaN(parseFloat(floorInfo.floor))) {
if (isPlainObject(floorInfo) &&
!isNaN(parseFloat(floorInfo?.floor))) {
floor = floorInfo.floor;
}

if (typeof floorInfo === 'object' && floorInfo.currency) {
if (isPlainObject(floorInfo) && floorInfo.currency) {
currencyResult = floorInfo.currency;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/adtrgtmeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function getFloorModuleData(bid) {
mediaType: BANNER,
size: '*'
};
return (isFn(bid.getFloor)) ? bid.getFloor(getFloorRequestObject) : false;
return (isFn(bid.getFloor)) ? (bid.getFloor(getFloorRequestObject) || {}) : false;
};

function generateOpenRtbObject(bidderRequest, bid) {
Expand Down
2 changes: 1 addition & 1 deletion modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function getFloor(bidRequest, size, mediaType) {
size: [ size.width, size.height ]
});

if (!isNaN(bidFloors.floor) && (bidFloors.currency === CURRENCY)) {
if (!isNaN(bidFloors?.floor) && (bidFloors?.currency === CURRENCY)) {
return bidFloors.floor;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/amxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getFloor(bid) {
size: '*',
bidRequest: bid,
});
return floor.floor;
return floor?.floor;
} catch (e) {
logError('call to getFloor failed: ', e);
return DEFAULT_MIN_FLOOR;
Expand Down
2 changes: 1 addition & 1 deletion modules/appushBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (err) {
logError(err);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/audiencerunBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getBidFloor(bid) {
mediaType: BANNER,
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (_) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/axonixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getBidFloor(bidRequest) {
});
}

return floorInfo.floor || 0;
return floorInfo?.floor || 0;
}

function getPageUrl(bidRequest, bidderRequest) {
Expand Down
3 changes: 2 additions & 1 deletion modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
deepAccess, getBidIdParameter,
getValue,
isArray,
isPlainObject,
logInfo,
logWarn,
triggerPixel
Expand Down Expand Up @@ -147,7 +148,7 @@ function beOpRequestSlotsMaker(bid) {
let floor;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]});
if (typeof floorInfo === 'object' && floorInfo.currency === publisherCurrency && !isNaN(parseFloat(floorInfo.floor))) {
if (isPlainObject(floorInfo) && floorInfo.currency === publisherCurrency && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/brightMountainMediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateUUID, deepAccess, logWarn, deepSetValue } from '../src/utils.js';
import { generateUUID, deepAccess, logWarn, deepSetValue, isPlainObject } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
Expand Down Expand Up @@ -224,7 +224,7 @@ function getFloor(bid, size) {
size: size,
});

if (typeof floorInfo === 'object' && floorInfo.currency === 'USD') {
if (isPlainObject(floorInfo) && floorInfo.currency === 'USD') {
return parseFloat(floorInfo.floor);
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/c1xBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function getBidFloor(bidRequest) {
}

let floor =
floorInfo.floor ||
floorInfo?.floor ||
bidRequest.params.bidfloor ||
bidRequest.params.floorPriceMap ||
0;
Expand Down
4 changes: 2 additions & 2 deletions modules/carodaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function getImps (validBidRequests, common) {
const floorInfo = bid.getFloor
? bid.getFloor({ currency: common.currency || 'EUR' })
: {};
const bidfloor = floorInfo.floor;
const bidfloorcur = floorInfo.currency;
const bidfloor = floorInfo?.floor;
const bidfloorcur = floorInfo?.currency;
const { ctok, placementId } = bid.params;
const imp = {
bid_id: bid.bidId,
Expand Down
2 changes: 1 addition & 1 deletion modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getBidFloor(bid) {
mediaType: '*',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (err) {
logError(err);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/connectadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function getBidFloor(bidRequest) {
});
}

let floor = floorInfo.floor || bidRequest.params.bidfloor || bidRequest.params.floorprice || 0;
let floor = floorInfo?.floor || bidRequest.params.bidfloor || bidRequest.params.floorprice || 0;

return floor;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/dailyhuntBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const createOrtbPublisherObj = (validBidRequests) => ({ ...extractKeyInfo(validB
// get bidFloor Function for different creatives
function getBidFloor(bid, creative) {
let floorInfo = typeof (bid.getFloor) == 'function' ? bid.getFloor({ currency: 'USD', mediaType: creative, size: '*' }) : {};
return Math.floor(floorInfo.floor || (bid.params.bidfloor ? bid.params.bidfloor : 0.0));
return Math.floor(floorInfo?.floor || (bid.params.bidfloor ? bid.params.bidfloor : 0.0));
}

const createOrtbImpObj = (bid) => {
Expand Down
2 changes: 1 addition & 1 deletion modules/deltaprojectsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function getBidFloor(bid, mediaType, size, currency) {
if (isFn(bid.getFloor)) {
const bidFloorCurrency = currency || 'USD';
const bidFloor = bid.getFloor({currency: bidFloorCurrency, mediaType: mediaType, size: size});
if (isNumber(bidFloor.floor)) {
if (isNumber(bidFloor?.floor)) {
return bidFloor;
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/dianomiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export const spec = {
currency: currency || 'USD',
})
: {};
const bidfloor = floorInfo.floor;
const bidfloorcur = floorInfo.currency;
const bidfloor = floorInfo?.floor;
const bidfloorcur = floorInfo?.currency;
const { smartadId } = bid.params;

const imp = {
Expand Down
2 changes: 1 addition & 1 deletion modules/eplanningBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function getFloorStr(bid) {
currency: DOLLAR_CODE,
mediaType: '*',
size: '*'
});
}) || {};

if (bidFloor.floor) {
return '|' + encodeURIComponent(bidFloor.floor);
Expand Down
2 changes: 1 addition & 1 deletion modules/freewheel-sspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function getBidFloor(bid, config) {
mediaType: typeof bid.mediaTypes['banner'] == 'object' ? 'banner' : 'video',
size: '*',
});
return bidFloor.floor;
return bidFloor?.floor;
} catch (e) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/getintentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function getBidFloor(bidRequest, currency) {
currency: currency || DEFAULT_CURRENCY,
mediaType: bidRequest.mediaType,
size: bidRequest.sizes || '*'
});
}) || {};
}

return {
Expand Down
5 changes: 3 additions & 2 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
mergeDeep,
logWarn,
isNumber,
isStr
isStr,
isPlainObject
} from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -503,7 +504,7 @@ function _getFloor (mediaTypes, bid) {
size: bid.sizes.map(([w, h]) => ({w, h}))
});

if (typeof floorInfo === 'object' &&
if (isPlainObject(floorInfo) &&
floorInfo.currency === 'USD' &&
!isNaN(parseFloat(floorInfo.floor))) {
floor = Math.max(floor, parseFloat(floorInfo.floor));
Expand Down
2 changes: 1 addition & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function _getFloor(mediaTypes, staticBidFloor, bid) {
const { currency, floor } = bid.getFloor({
mediaType: curMediaType,
size: '*'
});
}) || {};
floor && (bidFloor.floor = floor);
currency && (bidFloor.currency = currency);

Expand Down
4 changes: 2 additions & 2 deletions modules/impactifyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js';
import { deepAccess, deepSetValue, generateUUID, isPlainObject } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { ajax } from '../src/ajax.js';
Expand Down Expand Up @@ -98,7 +98,7 @@ const helpers = {
mediaType: '*',
size: '*'
});
if (typeof floorInfo === 'object' && floorInfo.currency === DEFAULT_CURRENCY && !isNaN(parseFloat(floorInfo.floor))) {
if (isPlainObject(floorInfo) && floorInfo.currency === DEFAULT_CURRENCY && !isNaN(parseFloat(floorInfo.floor))) {
return parseFloat(floorInfo.floor);
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel, logError } from '../src/utils.js';
import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel, logError, isPlainObject } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -527,7 +527,7 @@ function getImpression(bid) {
} catch (e) {
logError('Kargo: getFloor threw an error: ', e);
}
imp.floor = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined;
imp.floor = isPlainObject(floorInfo) && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined;
}
}

Expand Down
Loading

0 comments on commit 3ac680f

Please sign in to comment.