Skip to content

Commit

Permalink
Merge branch 'master' of github.com:prebid/Prebid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
smenzer committed Jun 26, 2020
2 parents 1cb31ec + 81d0c58 commit ebabc8e
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 140 deletions.
13 changes: 7 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ function injectFakeServerEndpointDev() {

function startFakeServer() {
const fakeServer = spawn('node', ['./test/fake-server/index.js', `--port=${FAKE_SERVER_PORT}`]);
fakeServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
fakeServer.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
fakeServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
fakeServer.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
}

// support tasks
Expand All @@ -372,6 +372,7 @@ gulp.task('build', gulp.series(clean, 'build-bundle-prod'));
gulp.task('build-postbid', gulp.series(escapePostbidConfig, buildPostbid));

gulp.task('serve', gulp.series(clean, lint, gulp.parallel('build-bundle-dev', watch, test)));
gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', watch)));
gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer));

gulp.task('default', gulp.series(clean, makeWebpackPkg));
Expand Down
4 changes: 2 additions & 2 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const spec = {
if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdprConsent = {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : null
};
}

Expand Down Expand Up @@ -80,7 +80,7 @@ export const spec = {

try {
bidRequests = JSON.parse(request.data).Bids;
} catch (e) {
} catch (err) {
// json error initial request can't be read
}

Expand Down
30 changes: 12 additions & 18 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const BIDDER_CODE = 'improvedigital';
const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';

export const spec = {
version: '7.0.0',
version: '7.1.0',
code: BIDDER_CODE,
gvlid: 253,
aliases: ['id'],
Expand Down Expand Up @@ -123,15 +123,15 @@ export const spec = {

// Deal ID. Composite ads can have multiple line items and the ID of the first
// dealID line item will be used.
if (utils.isNumber(bidObject.lid) && bidObject.buying_type === 'deal_id') {
if (utils.isNumber(bidObject.lid) && bidObject.buying_type && bidObject.buying_type !== 'rtb') {
bid.dealId = bidObject.lid;
} else if (Array.isArray(bidObject.lid) &&
Array.isArray(bidObject.buying_type) &&
bidObject.lid.length === bidObject.buying_type.length) {
let isDeal = false;
bidObject.buying_type.forEach((bt, i) => {
if (isDeal) return;
if (bt === 'deal_id') {
if (bt && bt !== 'rtb') {
isDeal = true;
bid.dealId = bidObject.lid[i];
}
Expand Down Expand Up @@ -182,9 +182,10 @@ export const spec = {
};

function isInstreamVideo(bid) {
const mediaTypes = Object.keys(utils.deepAccess(bid, 'mediaTypes', {}));
const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
const context = utils.deepAccess(bid, 'mediaTypes.video.context');
return bid.mediaType === 'video' || (videoMediaType && context !== 'outstream');
return bid.mediaType === 'video' || (mediaTypes.length === 1 && videoMediaType && context !== 'outstream');
}

function isOutstreamVideo(bid) {
Expand All @@ -197,30 +198,23 @@ function outstreamRender(bid) {
bid.renderer.push(() => {
window.ANOutstreamVideo.renderAd({
sizes: [bid.width, bid.height],
width: bid.width,
height: bid.height,
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
rendererOptions: {
showBigPlayButton: false,
showProgressBar: 'bar',
showVolume: false,
allowFullscreen: true,
skippable: false,
}
});
rendererOptions: bid.renderer.getConfig()
}, handleOutstreamRendererEvents.bind(null, bid));
});
}

function handleOutstreamRendererEvents(bid, id, eventName) {
bid.renderer.handleVideoEvent({ id, eventName });
}

function createRenderer(bidRequest) {
const renderer = Renderer.install({
id: bidRequest.adUnitCode,
url: RENDERER_URL,
loaded: false,
config: {
player_width: bidRequest.mediaTypes.video.playerSize[0][0],
player_height: bidRequest.mediaTypes.video.playerSize[0][1]
},
config: utils.deepAccess(bidRequest, 'renderer.options'),
adUnitCode: bidRequest.adUnitCode
});
try {
Expand Down
63 changes: 59 additions & 4 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,29 @@ export function updateAdUnitsForAuction(adUnits, floorData, auctionId) {
});
}

export function pickRandomModel(modelGroups, weightSum) {
// we loop through the models subtracting the current model weight from our random number
// once we are at or below zero, we return the associated model
let random = Math.floor(Math.random() * weightSum + 1)
for (let i = 0; i < modelGroups.length; i++) {
random -= modelGroups[i].modelWeight;
if (random <= 0) {
return modelGroups[i];
}
}
};

/**
* @summary Updates the adUnits accordingly and returns the necessary floorsData for the current auction
*/
export function createFloorsDataForAuction(adUnits, auctionId) {
let resolvedFloorsData = utils.deepClone(_floorsConfig);
// if using schema 2 pick a model here:
if (utils.deepAccess(resolvedFloorsData, 'data.floorsSchemaVersion') === 2) {
// merge the models specific stuff into the top level data settings (now it looks like floorsSchemaVersion 1!)
let { modelGroups, ...rest } = resolvedFloorsData.data;
resolvedFloorsData.data = Object.assign(rest, pickRandomModel(modelGroups, rest.modelWeightSum));
}

// if we do not have a floors data set, we will try to use data set on adUnits
let useAdUnitData = Object.keys(utils.deepAccess(resolvedFloorsData, 'data.values') || {}).length === 0;
Expand Down Expand Up @@ -372,6 +390,36 @@ function validateRules(floorsData, numFields, delimiter) {
return Object.keys(floorsData.values).length > 0;
}

function modelIsValid(model) {
// schema.fields has only allowed attributes
if (!validateSchemaFields(utils.deepAccess(model, 'schema.fields'))) {
return false;
}
return validateRules(model, model.schema.fields.length, model.schema.delimiter || '|')
}

/**
* @summary Mapping of floor schema version to it's corresponding validation
*/
const floorsSchemaValidation = {
1: data => modelIsValid(data),
2: data => {
// model groups should be an array with at least one element
if (!Array.isArray(data.modelGroups) || data.modelGroups.length === 0) {
return false;
}
// every model should have valid schema, as well as an accompanying modelWeight
data.modelWeightSum = 0;
return data.modelGroups.every(model => {
if (typeof model.modelWeight === 'number' && modelIsValid(model)) {
data.modelWeightSum += model.modelWeight;
return true;
}
return false;
});
}
};

/**
* @summary Fields array should have at least one entry and all should match allowed fields
* Each rule in the values array should have a 'key' and 'floor' param
Expand All @@ -382,11 +430,12 @@ export function isFloorsDataValid(floorsData) {
if (typeof floorsData !== 'object') {
return false;
}
// schema.fields has only allowed attributes
if (!validateSchemaFields(utils.deepAccess(floorsData, 'schema.fields'))) {
floorsData.floorsSchemaVersion = floorsData.floorsSchemaVersion || 1;
if (typeof floorsSchemaValidation[floorsData.floorsSchemaVersion] !== 'function') {
utils.logError(`${MODULE_NAME}: Unknown floorsSchemaVersion: `, floorsData.floorsSchemaVersion);
return false;
}
return validateRules(floorsData, floorsData.schema.fields.length, floorsData.schema.delimiter || '|')
return floorsSchemaValidation[floorsData.floorsSchemaVersion](floorsData);
}

/**
Expand Down Expand Up @@ -458,7 +507,13 @@ export function handleFetchResponse(fetchResponse) {
floorResponse = fetchResponse;
}
// Update the global floors object according to the fetched data
_floorsConfig.data = parseFloorData(floorResponse, 'fetch') || _floorsConfig.data;
const fetchData = parseFloorData(floorResponse, 'fetch');
if (fetchData) {
// set .data to it
_floorsConfig.data = fetchData;
// set skipRate override if necessary
_floorsConfig.skipRate = utils.isNumber(fetchData.skipRate) ? fetchData.skipRate : _floorsConfig.skipRate;
}

// if any auctions are waiting for fetch to finish, we need to continue them!
resumeDelayedAuctions();
Expand Down
36 changes: 19 additions & 17 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@ export const spec = {
let sovrnImps = [];
let iv;
let schain;
let digitrust;
let unifiedID;

utils._each(bidReqs, function (bid) {
if (!digitrust) {
const bidRequestDigitrust = utils.deepAccess(bid, 'userId.digitrustid.data');
if (bidRequestDigitrust && (!bidRequestDigitrust.privacy || !bidRequestDigitrust.privacy.optout)) {
digitrust = {
id: bidRequestDigitrust.id,
keyv: bidRequestDigitrust.keyv
}
}
if (!unifiedID) {
unifiedID = utils.deepAccess(bid, 'userId.tdid');
}

if (bid.schain) {
schain = schain || bid.schain;
}
Expand All @@ -47,6 +42,7 @@ export const spec = {
bidSizes = bidSizes.filter(size => utils.isArray(size))
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))
sovrnImps.push({
adunitcode: bid.adUnitCode,
id: bid.bidId,
banner: {
format: processedSizes,
Expand Down Expand Up @@ -88,15 +84,22 @@ export const spec = {
utils.deepSetValue(sovrnBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

if (digitrust) {
utils.deepSetValue(sovrnBidReq, 'user.ext.digitrust', {
id: digitrust.id,
keyv: digitrust.keyv
})
if (unifiedID) {
const idArray = [{
source: 'adserver.org',
uids: [
{
id: unifiedID,
ext: {
rtiPartner: 'TDID'
}
}
]
}]
utils.deepSetValue(sovrnBidReq, 'user.ext.eids', idArray)
}

let url = `https://ap.lijit.com/rtb/bid?` +
`src=$$REPO_AND_VERSION$$`;
let url = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`;
if (iv) url += `&iv=${iv}`;

return {
Expand Down Expand Up @@ -176,7 +179,6 @@ export const spec = {
.forEach(url => tracks.push({ type: 'image', url }))
}
}

return tracks
} catch (e) {
return []
Expand Down
Loading

0 comments on commit ebabc8e

Please sign in to comment.