Skip to content

Commit

Permalink
allow s2s bidders call pbs without need of a client adapter file (pre…
Browse files Browse the repository at this point in the history
…bid#2704)

* allow s2s adapters call pbs without client adapter file

* add support in aliasBidAdapter for s2s-only bidders
  • Loading branch information
jsnellbaker authored and dluxemburg committed Jul 17, 2018
1 parent 0aa13a3 commit 5cbdcd3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
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
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 @@ -393,12 +393,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 @@ -340,9 +340,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;

if (!adUnit.transactionId) {
adUnit.transactionId = utils.generateUUID();
}
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/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E1suTDogFAZgFAKAF______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 @@ -719,6 +720,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

0 comments on commit 5cbdcd3

Please sign in to comment.