Skip to content

Commit

Permalink
AdagioBidAdapter: use video helper for ortb fields validation
Browse files Browse the repository at this point in the history
  • Loading branch information
osazos committed Jul 17, 2024
1 parent 569438f commit 335f25f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 51 deletions.
60 changes: 10 additions & 50 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import {
getDNT,
getWindowSelf,
isArray,
isArrayOfNums,
isFn,
isInteger,
isNumber,
isStr,
logError,
logInfo,
logWarn,
} from '../src/utils.js';
import { getRefererInfo, parseDomain } from '../src/refererDetection.js';
import { OUTSTREAM } from '../src/video.js';
import { OUTSTREAM, validateOrtbVideoFields } from '../src/video.js';
import { Renderer } from '../src/Renderer.js';
import { _ADAGIO } from '../libraries/adagioUtils/adagioUtils.js';
import { config } from '../src/config.js';
Expand All @@ -40,39 +38,6 @@ export const BB_RENDERER_URL = `https://${BB_PUBLICATION}.bbvms.com/r/$RENDERER.

const CURRENCY = 'USD';

// This provide a whitelist and a basic validation of OpenRTB 2.5 options used by the Adagio SSP.
// Accept all options but 'protocol', 'companionad', 'companiontype', 'ext'
// https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf
export const ORTB_VIDEO_PARAMS = {
'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'),
'minduration': (value) => isInteger(value),
'maxduration': (value) => isInteger(value),
'protocols': (value) => isArrayOfNums(value),
'w': (value) => isInteger(value),
'h': (value) => isInteger(value),
'startdelay': (value) => isInteger(value),
'placement': (value) => {
logWarn(LOG_PREFIX, 'The OpenRTB video param `placement` is deprecated and should not be used anymore.');
return isInteger(value)
},
'plcmt': (value) => isInteger(value),
'linearity': (value) => isInteger(value),
'skip': (value) => [1, 0].includes(value),
'skipmin': (value) => isInteger(value),
'skipafter': (value) => isInteger(value),
'sequence': (value) => isInteger(value),
'battr': (value) => isArrayOfNums(value),
'maxextended': (value) => isInteger(value),
'minbitrate': (value) => isInteger(value),
'maxbitrate': (value) => isInteger(value),
'boxingallowed': (value) => isInteger(value),
'playbackmethod': (value) => isArrayOfNums(value),
'playbackend': (value) => isInteger(value),
'delivery': (value) => isArrayOfNums(value),
'pos': (value) => isInteger(value),
'api': (value) => isArrayOfNums(value)
};

/**
* Returns the window.ADAGIO global object used to store Adagio data.
* This object is created in window.top if possible, otherwise in window.self.
Expand Down Expand Up @@ -186,6 +151,12 @@ function _getEids(bidRequest) {
}
}

/**
* Merge and compute video params set at mediaTypes and bidder params level
*
* @param {object} bidRequest - copy of the original bidRequest object.
* @returns {void}
*/
function _buildVideoBidRequest(bidRequest) {
const videoAdUnitParams = deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = deepAccess(bidRequest, 'params.video', {});
Expand All @@ -206,22 +177,11 @@ function _buildVideoBidRequest(bidRequest) {
};

if (videoParams.context && videoParams.context === OUTSTREAM) {
bidRequest.mediaTypes.video.playerName = getPlayerName(bidRequest);
videoParams.playerName = getPlayerName(bidRequest);
}

// Only whitelisted OpenRTB options need to be validated.
// Other options will still remain in the `mediaTypes.video` object
// sent in the ad-request, but will be ignored by the SSP.
Object.keys(ORTB_VIDEO_PARAMS).forEach(paramName => {
if (videoParams.hasOwnProperty(paramName)) {
if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) {
bidRequest.mediaTypes.video[paramName] = videoParams[paramName];
} else {
delete bidRequest.mediaTypes.video[paramName];
logWarn(`${LOG_PREFIX} The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`);
}
}
});
validateOrtbVideoFields(videoParams)
bidRequest.mediaTypes.video = videoParams;
}

function _parseNativeBidResponse(bid) {
Expand Down
1 change: 0 additions & 1 deletion test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ describe('Adagio bid adapter', () => {
const requests = spec.buildRequests([bid01], bidderRequest);
expect(requests).to.have.lengthOf(1);
expect(requests[0].data.adUnits[0].mediaTypes.video).to.deep.equal(expected);
sinon.assert.calledTwice(utils.logWarn.withArgs(sinon.match(new RegExp(/^Adagio: The OpenRTB/))));
});
});

Expand Down

0 comments on commit 335f25f

Please sign in to comment.