Skip to content

Commit

Permalink
Prebid Core: emit seatnonbid from prebid server (#9453)
Browse files Browse the repository at this point in the history
* Parse and emit seatnonbid from server

* Fix testing adjustments

* Use onResponse for seatNonBids

* Fix linting error

* Emit to auction and add unit tests

* Use optional property chaining

* returnallbidstatus

* fix varname in spec
  • Loading branch information
spotxslagle authored Feb 27, 2023
1 parent 72ad8f0 commit bb997b2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
18 changes: 16 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,13 @@ export function PrebidServer() {
}

processPBSRequest(s2sBidRequest, bidRequests, ajax, {
onResponse: function (isValid, requestedBidders) {
onResponse: function (isValid, requestedBidders, response) {
if (isValid) {
bidRequests.forEach(bidderRequest => events.emit(CONSTANTS.EVENTS.BIDDER_DONE, bidderRequest));
}
if (shouldEmitNonbids(s2sBidRequest.s2sConfig, response)) {
emitNonBids(response.ext.seatnonbid, bidRequests[0].auctionId);
}
done();
doClientSideSyncs(requestedBidders, gdprConsent, uspConsent, gppConsent);
},
Expand Down Expand Up @@ -551,7 +554,7 @@ export const processPBSRequest = hook('sync', function (s2sBidRequest, bidReques
logError('error parsing response: ', result ? result.status : 'not valid JSON');
onResponse(false, requestedBidders);
} else {
onResponse(true, requestedBidders);
onResponse(true, requestedBidders, result);
}
},
error: function () {
Expand All @@ -567,6 +570,17 @@ export const processPBSRequest = hook('sync', function (s2sBidRequest, bidReques
}
}, 'processPBSRequest');

function shouldEmitNonbids(s2sConfig, response) {
return s2sConfig?.extPrebid?.returnallbidstatus && response?.ext?.seatnonbid;
}

function emitNonBids(seatnonbid, auctionId) {
events.emit(CONSTANTS.EVENTS.SEAT_NON_BID, {
seatnonbid,
auctionId
});
}

/**
* Global setter that sets eids permissions for bidders
* This setter is to be used by userId module when included
Expand Down
12 changes: 11 additions & 1 deletion src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
let _auctionEnd;
let _timer;
let _auctionStatus;
let _nonBids = [];

function addBidRequests(bidderRequests) { _bidderRequests = _bidderRequests.concat(bidderRequests); }
function addBidReceived(bidsReceived) { _bidsReceived = _bidsReceived.concat(bidsReceived); }
function addBidRejected(bidsRejected) { _bidsRejected = _bidsRejected.concat(bidsRejected); }
function addNoBid(noBid) { _noBids = _noBids.concat(noBid); }
function addNonBids(seatnonbids) { _nonBids = _nonBids.concat(seatnonbids); }

function getProperties() {
return {
Expand All @@ -172,7 +174,8 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
bidsRejected: _bidsRejected,
winningBids: _winningBids,
timeout: _timeout,
metrics: metrics
metrics: metrics,
seatNonBids: _nonBids
};
}

Expand Down Expand Up @@ -369,6 +372,12 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
adapterManager.callSetTargetingBidder(bid.adapterCode || bid.bidder, bid);
}

events.on(CONSTANTS.EVENTS.SEAT_NON_BID, (event) => {
if (event.auctionId === _auctionId) {
addNonBids(event.seatnonbid)
}
});

return {
addBidReceived,
addBidRejected,
Expand All @@ -387,6 +396,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
getBidRequests: () => _bidderRequests,
getBidsReceived: () => _bidsReceived,
getNoBids: () => _noBids,
getNonBids: () => _nonBids,
getFPD: () => ortb2Fragments,
getMetrics: () => metrics,
};
Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"BID_RESPONSE": "bidResponse",
"BID_REJECTED": "bidRejected",
"NO_BID": "noBid",
"SEAT_NON_BID": "seatNonBid",
"BID_WON": "bidWon",
"BIDDER_DONE": "bidderDone",
"BIDDER_ERROR": "bidderError",
Expand Down
14 changes: 14 additions & 0 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,20 @@ describe('auctionmanager.js', function () {
sinon.assert.calledWith(stubMakeBidRequests, ...anyArgs.slice(0, 5).concat([sinon.match.same(ortb2Fragments)]));
sinon.assert.calledWith(stubCallAdapters, ...anyArgs.slice(0, 7).concat([sinon.match.same(ortb2Fragments)]));
});

it('correctly adds nonbids when they are emitted', () => {
const ortb2Fragments = {
global: {},
bidder: {}
}
const auction = auctionManager.createAuction({adUnits, ortb2Fragments});
expect(auction.getNonBids()[0]).to.equal(undefined);
events.emit(CONSTANTS.EVENTS.SEAT_NON_BID, {
auctionId: auction.getAuctionId(),
seatnonbid: ['test']
});
expect(auction.getNonBids()[0]).to.equal('test');
});
});

describe('addBidResponse #1', function () {
Expand Down
15 changes: 15 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,21 @@ describe('S2S Adapter', function () {
expect(response).to.have.property('ttl', 60);
});

it('handles seatnonbid responses and calls SEAT_NON_BID', function () {
const original = CONFIG;
CONFIG.extPrebid = { returnallbidstatus: true };
const nonbidResponse = {...RESPONSE_OPENRTB, ext: {seatnonbid: [{}]}};
config.setConfig({ CONFIG });
CONFIG = original;
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
const responding = deepClone(nonbidResponse);
Object.assign(responding.ext.seatnonbid, [{auctionId: 2}])
server.requests[0].respond(200, {}, JSON.stringify(responding));
const event = events.emit.secondCall.args;
expect(event[0]).to.equal(CONSTANTS.EVENTS.SEAT_NON_BID);
expect(event[1].seatnonbid[0]).to.have.property('auctionId', 2);
});

it('respects defaultTtl', function () {
const s2sConfig = Object.assign({}, CONFIG, {
defaultTtl: 30
Expand Down

0 comments on commit bb997b2

Please sign in to comment.