Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid Core: refactor bidderSettings to have only one entry point #7712

Merged
merged 13 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ module.exports = {
'BROWSERSTACK_USERNAME': false,
'BROWSERSTACK_KEY': false
},
// use babel as parser for fancy syntax
parser: '@babel/eslint-parser',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need @babel/eslint-parser?
Looking at the npm description I see:

ESLint's default parser and core rules only support the latest final ECMAScript standard and do not support experimental (such as new features) and non-standard (such as Flow or TypeScript types) syntax provided by Babel

Do we need these 'experimental and non-standard' syntax? Or am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of the class syntax, specifically field declaration and private (#) methods and fields. Btw I care about objects but not really about syntax, I don't mind going either way with this.

parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
},

rules: {
'comma-dangle': 'off',
semi: 'off',
Expand All @@ -49,5 +52,9 @@ module.exports = {
rules: {
'prebid/validate-imports': ['error', allowedModules[key]]
}
}))
})).concat([{
// code in other packages (such as plugins/eslint) is not "seen" by babel and its parser will complain.
files: 'plugins/*/**/*.js',
parser: 'esprima'
}])
};
5 changes: 3 additions & 2 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, logError, logInfo, deepAccess, logMessage, convertTypes, isStr, getParameterByName, deepClone, chunk, logWarn, getBidRequest, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, getMaxValueFromArray, fill, getMinValueFromArray, isArrayOfNums, isFn, isAllowZeroCpmBidsEnabled } from '../src/utils.js';
import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, logError, logInfo, deepAccess, logMessage, convertTypes, isStr, getParameterByName, deepClone, chunk, logWarn, getBidRequest, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, getMaxValueFromArray, fill, getMinValueFromArray, isArrayOfNums, isFn } from '../src/utils.js';
import { Renderer } from '../src/Renderer.js';
import { config } from '../src/config.js';
import { registerBidder, getIabSubCategory } from '../src/adapters/bidderFactory.js';
Expand All @@ -8,6 +8,7 @@ import find from 'core-js-pure/features/array/find.js';
import includes from 'core-js-pure/features/array/includes.js';
import { OUTSTREAM, INSTREAM } from '../src/video.js';
import { getStorageManager } from '../src/storageManager.js';
import { bidderSettings } from '../src/bidderSettings.js';

const BIDDER_CODE = 'appnexus';
const URL = 'https://ib.adnxs.com/ut/v3/prebid';
Expand Down Expand Up @@ -292,7 +293,7 @@ export const spec = {
serverResponse.tags.forEach(serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
const cpmCheck = (isAllowZeroCpmBidsEnabled(bidderRequest.bidderCode)) ? rtbBid.cpm >= 0 : rtbBid.cpm > 0;
const cpmCheck = (bidderSettings.get(bidderRequest.bidderCode, 'allowZeroCpmBids') === true) ? rtbBid.cpm >= 0 : rtbBid.cpm > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From readability perspective, to me, personally, previous version was much clearer.
You just execute some function to get the info you need (isAllowZeroCpmBidsEnabled).
With this new approach code is longer and it's more error prone since you have to remember name of the property allowZeroCpmBids.

But, I guess since that is used in 2,3 places in the entire prebid.js than it's fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree but there's a problem with circular imports when we put everything in utils. (new bidderSettings needs utils.deepClone, and a few others)

if (cpmCheck && includes(this.supportedMediaTypes, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid, bidderRequest);
bid.mediaType = parseMediaType(rtbBid);
Expand Down
3 changes: 2 additions & 1 deletion modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getHook } from '../src/hook.js';
import { createBid } from '../src/bidfactory.js';
import find from 'core-js-pure/features/array/find.js';
import { getRefererInfo } from '../src/refererDetection.js';
import {bidderSettings} from '../src/bidderSettings.js';

/**
* @summary This Module is intended to provide users with the ability to dynamically set and enforce price floors on a per auction basis.
Expand Down Expand Up @@ -147,7 +148,7 @@ function generatePossibleEnumerations(arrayOfFields, delimiter) {
* @summary If a the input bidder has a registered cpmadjustment it returns the input CPM after being adjusted
*/
export function getBiddersCpmAdjustment(bidderName, inputCpm, bid = {}) {
const adjustmentFunction = deepAccess(getGlobal(), `bidderSettings.${bidderName}.bidCpmAdjustment`) || deepAccess(getGlobal(), 'bidderSettings.standard.bidCpmAdjustment');
const adjustmentFunction = bidderSettings.get(bidderName, 'bidCpmAdjustment');
if (adjustmentFunction) {
return parseFloat(adjustmentFunction(inputCpm, {...bid, cpm: inputCpm}));
}
Expand Down
9 changes: 5 additions & 4 deletions modules/sortableAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import adapterManager from '../src/adapterManager.js';
import {ajax} from '../src/ajax.js';
import {getGlobal} from '../src/prebidGlobal.js';
import { config } from '../src/config.js';
import {bidderSettings} from '../src/bidderSettings.js';

const DEFAULT_PROTOCOL = 'https';
const DEFAULT_HOST = 'pa.deployads.com';
Expand Down Expand Up @@ -182,11 +183,11 @@ function getFactor(bidder) {
}

function getBiddersFactors() {
const pb = getGlobal();
const result = {};
if (pb && pb.bidderSettings) {
Object.keys(pb.bidderSettings).forEach(bidderKey => {
const bidder = pb.bidderSettings[bidderKey];
const settings = bidderSettings.getSettings();
if (settings) {
Object.keys(settings).forEach(bidderKey => {
const bidder = settings[bidderKey];
const factor = getFactor(bidder);
if (factor !== null) {
result[bidderKey] = factor;
Expand Down
Loading