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

prebidServerBidAdapter cleanup #2844

Merged
merged 5 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ export const spec = {
url: '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html'
}];
}
},
transformBidParams: function(params) {
params.use_pmt_rule = (typeof params.usePaymentRule === 'boolean') ? params.usePaymentRule : false;
if (params.usePaymentRule) { delete params.usePaymentRule; }

Object.keys(params).forEach(paramKey => {
let convertedKey = utils.convertCamelToUnderscore(paramKey);
if (convertedKey !== paramKey) {
params[convertedKey] = params[paramKey];
delete params[paramKey];
}
});
return params;
}
}

Expand Down
98 changes: 13 additions & 85 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VIDEO } from 'src/mediaTypes';
import { isValid } from 'src/adapters/bidderFactory';
import events from 'src/events';
import includes from 'core-js/library/fn/array/includes';
import { S2S_VENDORS, paramTypes } from './s2sVendors.js';

const getConfig = config.getConfig;

Expand All @@ -32,26 +33,6 @@ config.setDefaults({
's2sConfig': s2sDefaultConfig
});

// accountId and bidders params are not included here, should be configured by end-user
const availVendorDefaults = {
'appnexus': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid.adnxs.com/pbs/v1/openrtb2/auction',
syncEndpoint: '//prebid.adnxs.com/pbs/v1/cookie_sync',
timeout: 1000
},
'rubicon': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid-server.rubiconproject.com/auction',
syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync',
timeout: 500
}
};

/**
* Set config for server to server header bidding
* @typedef {Object} options - required
Expand All @@ -69,13 +50,12 @@ function setS2sConfig(options) {
if (options.defaultVendor) {
let vendor = options.defaultVendor;
let optionKeys = Object.keys(options);

if (availVendorDefaults.hasOwnProperty(vendor)) {
if (S2S_VENDORS[vendor]) {
// vendor keys will be set if either: the key was not specified by user
// or if the user did not set their own distinct value (ie using the system default) to override the vendor
Object.keys(availVendorDefaults[vendor]).forEach(function(vendorKey) {
Object.keys(S2S_VENDORS[vendor]).forEach((vendorKey) => {
if (s2sDefaultConfig[vendorKey] === options[vendorKey] || !includes(optionKeys, vendorKey)) {
options[vendorKey] = availVendorDefaults[vendor][vendorKey];
options[vendorKey] = S2S_VENDORS[vendor][vendorKey];
}
});
} else {
Expand Down Expand Up @@ -201,52 +181,6 @@ function tryConvertType(typeToConvert, value) {
}
}

const tryConvertString = tryConvertType.bind(null, 'string');
const tryConvertNumber = tryConvertType.bind(null, 'number');

const paramTypes = {
'appnexus': {
'member': tryConvertString,
'invCode': tryConvertString,
'placementId': tryConvertNumber,
'keywords': utils.transformBidderParamKeywords
},
'rubicon': {
'accountId': tryConvertNumber,
'siteId': tryConvertNumber,
'zoneId': tryConvertNumber
},
'indexExchange': {
'siteID': tryConvertNumber
},
'audienceNetwork': {
'placementId': tryConvertString
},
'pubmatic': {
'publisherId': tryConvertString,
'adSlot': tryConvertString
},
'districtm': {
'member': tryConvertString,
'invCode': tryConvertString,
'placementId': tryConvertNumber
},
'pulsepoint': {
'cf': tryConvertString,
'cp': tryConvertNumber,
'ct': tryConvertNumber
},
'conversant': {
'site_id': tryConvertString,
'secure': tryConvertNumber,
'mobile': tryConvertNumber
},
'openx': {
'unit': tryConvertString,
'customFloor': tryConvertNumber
},
};

/*
* Modify an adunit's bidder parameters to match the expected parameter types
*/
Expand All @@ -255,11 +189,15 @@ function convertTypes(adUnits) {
adUnit.bids.forEach(bid => {
// aliases use the base bidder's paramTypes
const bidder = adaptermanager.aliasRegistry[bid.bidder] || bid.bidder;
const types = paramTypes[bidder] || [];
const types = paramTypes[bidder] || {};

Object.keys(types).forEach(key => {
if (bid.params[key]) {
bid.params[key] = types[key](bid.params[key]);
if (utils.isFn(types[key])) {
bid.params[key] = types[key](bid.params[key]);
} else {
bid.params[key] = tryConvertType(types[key], bid.params[key]);
}

// don't send invalid values
if (isNaN(bid.params[key])) {
Expand Down Expand Up @@ -504,19 +442,9 @@ const OPEN_RTB_PROTOCOL = {

// get bidder params in form { <bidder code>: {...params} }
const ext = adUnit.bids.reduce((acc, bid) => {
// TODO: move this bidder specific out to a more ideal location (submodule?); https://github.com/prebid/Prebid.js/issues/2420
// convert all AppNexus keys to underscore format for pbs
if (bid.bidder === 'appnexus') {
bid.params.use_pmt_rule = (typeof bid.params.usePaymentRule === 'boolean') ? bid.params.usePaymentRule : false;
if (bid.params.usePaymentRule) { delete bid.params.usePaymentRule; }

Object.keys(bid.params).forEach(paramKey => {
let convertedKey = utils.convertCamelToUnderscore(paramKey);
if (convertedKey !== paramKey) {
bid.params[convertedKey] = bid.params[paramKey];
delete bid.params[paramKey];
}
});
const adapter = adaptermanager.bidderRegistry[bid.bidder];
if (adapter && adapter.getSpec().transformBidParams) {
bid.params = adapter.getSpec().transformBidParams(bid.params);
}
acc[bid.bidder] = bid.params;
return acc;
Expand Down
64 changes: 64 additions & 0 deletions modules/s2sVendors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { transformBidderParamKeywords } from 'src/utils';

// accountId and bidders params are not included here, should be configured by end-user
export const S2S_VENDORS = {
'appnexus': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid.adnxs.com/pbs/v1/openrtb2/auction',
syncEndpoint: '//prebid.adnxs.com/pbs/v1/cookie_sync',
timeout: 1000
},
'rubicon': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid-server.rubiconproject.com/auction',
syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync',
timeout: 500
}
}

export const paramTypes = {
Copy link
Member

@mkendall07 mkendall07 Jul 16, 2018

Choose a reason for hiding this comment

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

I do wonder if these belong here. Seems like we've split up transformation in 2 places now (in the bidder transformBidParams function and here). I do like these centralized since it's more of a problem with PBS / PBJS being in sync but wondering if they belong here or not.

'appnexus': {
'member': 'string',
'invCode': 'string',
'placementId': 'number',
'keywords': transformBidderParamKeywords
},
'rubicon': {
'accountId': 'number',
'siteId': 'number',
'zoneId': 'number'
},
'indexExchange': {
'siteID': 'number'
},
'audienceNetwork': {
'placementId': 'string'
},
'pubmatic': {
'publisherId': 'string',
'adSlot': 'string'
},
'districtm': {
'member': 'string',
'invCode': 'string',
'placementId': 'number'
},
'pulsepoint': {
'cf': 'string',
'cp': 'number',
'ct': 'number'
},
'conversant': {
'site_id': 'string',
'secure': 'number',
'mobile': 'number'
},
'openx': {
'unit': 'string',
'customFloor': 'number'
},
};
2 changes: 2 additions & 0 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { logWarn, logError, parseQueryStringParameters, delayExecution, parseSiz
* from the server, determine which user syncs should occur. The argument array will contain every element
* which has been sent through to interpretResponse. The order of syncs in this array matters. The most
* important ones should come first, since publishers may limit how many are dropped on their page.
* @property {function(object): object} transformBidParams Updates bid params before creating bid request
}}
*/

/**
Expand Down