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

allow s2s bidders call pbs without need of a client adapter file #2704

Merged
merged 4 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 10 additions & 3 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ const OPEN_RTB_PROTOCOL = {
response.seatbid.forEach(seatbid => {
(seatbid.bid || []).forEach(bid => {
const bidRequest = utils.getBidRequest(
this.bidMap[`${bid.impid}${seatbid.seat}`],
this.bidMap[`${bid.impid}${seatbid.seat}`].bid_id,
bidderRequests
);

Expand Down Expand Up @@ -704,11 +704,12 @@ export function PrebidServer() {
/* Notify Prebid of bid responses so bids can get in the auction */
function handleResponse(response, requestedBidders, bidderRequests, addBidResponse, done) {
let result;
let bids = [];

try {
result = JSON.parse(response);

const bids = protocolAdapter().interpretResponse(
bids = protocolAdapter().interpretResponse(
result,
bidderRequests,
requestedBidders
Expand All @@ -734,7 +735,13 @@ export function PrebidServer() {
utils.logError('error parsing response: ', result.status);
}

done();
const videoBid = bids.some(bidResponse => bidResponse.bid.mediaType === 'video');
const cacheEnabled = config.getConfig('cache.url');

// video bids with cache enabled need to be cached first before they are considered done
Copy link
Member

Choose a reason for hiding this comment

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

is this a separate change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No those changes are part of this PR. They are needed to ensure pbs video bids that are using prebid cache are properly used in the auction. Without this change; the adapter calls the done() before the caching process has finished which ends the auction prematurely.

if (!(videoBid && cacheEnabled)) {
done();
}
doClientSideSyncs(requestedBidders);
}

Expand Down
14 changes: 11 additions & 3 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,20 @@ exports.registerBidAdapter = function (bidAdaptor, bidderCode, {supportedMediaTy
};

exports.aliasBidAdapter = function (bidderCode, alias) {
var existingAlias = _bidderRegistry[alias];
let existingAlias = _bidderRegistry[alias];

if (typeof existingAlias === 'undefined') {
var bidAdaptor = _bidderRegistry[bidderCode];
let bidAdaptor = _bidderRegistry[bidderCode];
if (typeof bidAdaptor === 'undefined') {
utils.logError('bidderCode "' + bidderCode + '" is not an existing bidder.', 'adaptermanager.aliasBidAdapter');
// check if alias is part of s2sConfig and allow them to register if so (as base bidder may be s2s-only)
const s2sConfig = config.getConfig('s2sConfig');
const s2sBidders = s2sConfig && s2sConfig.bidders;

if (!(s2sBidders && includes(s2sBidders, alias))) {
utils.logError('bidderCode "' + bidderCode + '" is not an existing bidder.', 'adaptermanager.aliasBidAdapter');
} else {
exports.aliasRegistry[alias] = bidderCode;
}
} else {
try {
let newAdapter;
Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
],
"S2S" : {
"SRC" : "s2s",
"DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/openrtb2/auction",
"SYNCED_BIDDERS_KEY": "pbjsSyncs"
}
}
8 changes: 7 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,15 @@ $$PREBID_GLOBAL$$.requestBids = createHook('asyncSeries', function ({ bidsBackHa
const adUnitMediaTypes = Object.keys(adUnit.mediaTypes || {'banner': 'banner'});

// get the bidder's mediaTypes
const bidders = adUnit.bids.map(bid => bid.bidder);
const allBidders = adUnit.bids.map(bid => bid.bidder);
const bidderRegistry = adaptermanager.bidderRegistry;

const s2sConfig = config.getConfig('s2sConfig');
const s2sBidders = s2sConfig && s2sConfig.bidders;
const bidders = (s2sBidders) ? allBidders.filter(bidder => {
return !includes(s2sBidders, bidder);
}) : allBidders;

bidders.forEach(bidder => {
const adapter = bidderRegistry[bidder];
const spec = adapter && adapter.getSpec && adapter.getSpec()
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const RESPONSE_OPENRTB = {
'bid': [
{
'id': '8750901685062148',
'impid': '123',
'impid': 'div-gpt-ad-1460505748561-0',
'price': 0.5,
'adm': '<script src="http://lax1-ib.adnxs.com/ab?e=wqT_3QKgB6CgAwAAAwDWAAUBCJ7kvtMFEPft7JnIuImSdBj87IDv8q21rXcqNgkAAAECCOA_EQEHNAAA4D8ZAAAAgOtR4D8hERIAKREJADERG6Aw8ub8BDi-B0C-B0gCUNbLkw5Y4YBIYABokUB48NIEgAEBigEDVVNEkgUG8FKYAawCoAH6AagBAbABALgBAsABA8gBAtABCdgBAOABAPABAIoCOnVmKCdhJywgNDk0NDcyLCAxNTE3MjY5NTM0KTt1ZigncicsIDI5NjgxMTEwLDIeAPCckgKBAiFqRHF3RUFpNjBJY0VFTmJMa3c0WUFDRGhnRWd3QURnQVFBUkl2Z2RROHViOEJGZ0FZUF9fX184UGFBQndBWGdCZ0FFQmlBRUJrQUVCbUFFQm9BRUJxQUVEc0FFQXVRRXBpNGlEQUFEZ1A4RUJLWXVJZ3dBQTREX0pBVkx3MU5mdl9lMF8yUUVBQUFBQUFBRHdQLUFCQVBVQgUPKEpnQ0FLQUNBTFVDBRAETDAJCPBUTUFDQWNnQ0FkQUNBZGdDQWVBQ0FPZ0NBUGdDQUlBREFaQURBSmdEQWFnRHV0Q0hCTG9ERVdSbFptRjFiSFFqVEVGWU1Ub3pPRFk1mgI5IS1ndndfUTYEAfCENFlCSUlBUW9BRG9SWkdWbVlYVnNkQ05NUVZneE9qTTROamsu2ALoB-ACx9MB6gJHaHR0cDovL3ByZWJpZC5sb2NhbGhvc3Q6OTk5OS9pbnRlZ3JhdGlvbkV4YW1wbGVzL2dwdC9hcHBuZXh1cy10ZXN0Lmh0bWzyAhAKBkFEVl9JRBIGNCXTHPICEQoGQ1BHARM4BzE5Nzc5MzPyAhAKBUNQBRPwljg1MTM1OTSAAwGIAwGQAwCYAxSgAwGqAwDAA6wCyAMA2AMA4AMA6AMA-AMDgAQAkgQJL29wZW5ydGIymAQAogQMMjE2LjU1LjQ3Ljk0qAQAsgQMCAAQABgAIAAwADgAuAQAwAQAyAQA0gQRZGVmYXVsdCNMQVgxOjM4NjnaBAIIAeAEAPAE1suTDogFAZgFAKAF______8BA7ABqgUkYzdkY2YxNGYtZjliYS00Yzc3LWEzYjQtMjdmNmRmMzkwNjdmwAUAyQVpLhTwP9IFCQkJDFAAANgFAeAFAfAFAfoFBAgAEACQBgA.&s=f4dc8b6fa65845d08f0a87c145e12cb7d6288c2a&referrer=http%3A%2F%2Fprebid.localhost%3A9999%2FintegrationExamples%2Fgpt%2Fappnexus-test.html&pp=${AUCTION_PRICE}"></script>',
'adid': '29681110',
Expand Down Expand Up @@ -285,7 +285,7 @@ const RESPONSE_OPENRTB_VIDEO = {
bid: [
{
id: '1987250005171537465',
impid: '/19968336/header-bid-tag-0',
impid: 'div-gpt-ad-1460505748561-0',
price: 10,
adm: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><VAST version="3.0"><Ad id="81877115" sequence="0"><Wrapper><AdSystem version="3.0">adnxs</AdSystem><VASTAdTagURI><![CDATA[http://lax1-ib.adnxs.com/ab?e=wqT_3QLZBq]]></VASTAdTagURI><Impression><![CDATA[http://ib.adnxs.com/nop]]></Impression><Creatives><Creative adID="81877115"><Linear></Linear></Creative></Creatives></Wrapper></Ad></VAST>',
adid: '81877115',
Expand Down
33 changes: 32 additions & 1 deletion test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const CONFIG = {
timeout: 1000,
maxBids: 1,
adapter: 'prebidServer',
bidders: ['appnexus']
bidders: ['appnexus'],
accountId: 'abc'
};
var prebidServerAdapterMock = {
bidder: 'prebidServer',
Expand Down Expand Up @@ -716,6 +717,36 @@ describe('adapterManager tests', () => {
expect(AdapterManager.videoAdapters).to.include(alias);
});
});

describe('special case for s2s-only bidders', () => {
beforeEach(() => {
sinon.stub(utils, 'logError');
});

afterEach(() => {
config.resetConfig();
utils.logError.restore();
});

it('should allow an alias if alias is part of s2sConfig.bidders', () => {
let testS2sConfig = utils.deepClone(CONFIG);
testS2sConfig.bidders = ['s2sAlias'];
config.setConfig({s2sConfig: testS2sConfig});

AdapterManager.aliasBidAdapter('s2sBidder', 's2sAlias');
expect(AdapterManager.aliasRegistry).to.have.property('s2sAlias');
});

it('should throw an error if alias + bidder are unknown and not part of s2sConfig.bidders', () => {
let testS2sConfig = utils.deepClone(CONFIG);
testS2sConfig.bidders = ['s2sAlias'];
config.setConfig({s2sConfig: testS2sConfig});

AdapterManager.aliasBidAdapter('s2sBidder1', 's2sAlias1');
sinon.assert.calledOnce(utils.logError);
expect(AdapterManager.aliasRegistry).to.not.have.property('s2sAlias1');
});
});
});

describe('makeBidRequests', () => {
Expand Down