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

Sync with upstream master #3

Merged
merged 7 commits into from
Mar 16, 2021
115 changes: 54 additions & 61 deletions modules/amxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { parseUrl, deepAccess, _each, formatQS, getUniqueIdentifierStr, triggerPixel } from '../src/utils.js';
import { parseUrl, deepAccess, _each, formatQS, getUniqueIdentifierStr, triggerPixel, isFn, logError } from '../src/utils.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';

Expand All @@ -9,7 +9,6 @@ const storage = getStorageManager(737, BIDDER_CODE);
const SIMPLE_TLD_TEST = /\.com?\.\w{2,4}$/;
const DEFAULT_ENDPOINT = 'https://prebid.a-mo.net/a/c';
const VERSION = 'pba1.2.1';
const xmlDTDRxp = /^\s*<\?xml[^\?]+\?>/;
const VAST_RXP = /^\s*<\??(?:vast|xml)/i;
const TRACKING_ENDPOINT = 'https://1x1.a-mo.net/hbx/';
const AMUID_KEY = '__amuidpb';
Expand Down Expand Up @@ -45,11 +44,16 @@ function flatMap(input, mapFn) {
.reduce((acc, item) => item != null && acc.concat(item), [])
}

const generateDTD = (xmlDocument) =>
`<?xml version="${xmlDocument.xmlVersion}" encoding="${xmlDocument.xmlEncoding}" ?>`;

const isVideoADM = (html) => html != null && VAST_RXP.test(html);
const getMediaType = (bid) => isVideoADM(bid.adm) ? VIDEO : BANNER;

function getMediaType(bid) {
if (isVideoADM(bid.adm)) {
return VIDEO;
}

return BANNER;
}

const nullOrType = (value, type) =>
value == null || (typeof value) === type // eslint-disable-line valid-typeof

Expand Down Expand Up @@ -103,6 +107,32 @@ const trackEvent = (eventName, data) =>
eid: getUniqueIdentifierStr(),
})}`);

const DEFAULT_MIN_FLOOR = 0;

function ensureFloor(floorValue) {
return typeof floorValue === 'number' && isFinite(floorValue) && floorValue > 0.0
? floorValue : DEFAULT_MIN_FLOOR;
}

function getFloor(bid) {
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.floor', DEFAULT_MIN_FLOOR);
}

try {
const floor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*',
bidRequest: bid
});
return floor.floor;
} catch (e) {
logError('call to getFloor failed: ', e);
return DEFAULT_MIN_FLOOR;
}
}

function convertRequest(bid) {
const size = largestSize(bid.sizes, bid.mediaTypes) || [0, 0];
const isVideoBid = bid.mediaType === VIDEO || VIDEO in bid.mediaTypes
Expand All @@ -116,16 +146,21 @@ function convertRequest(bid) {
bid.sizes,
deepAccess(bid, `mediaTypes.${BANNER}.sizes`, []) || [],
deepAccess(bid, `mediaTypes.${VIDEO}.sizes`, []) || [],
]
];

const videoData = deepAccess(bid, `mediaTypes.${VIDEO}`, {}) || {};

const params = {
au,
av,
vd: videoData,
vr: isVideoBid,
ms: multiSizes,
aw: size[0],
ah: size[1],
tf: 0,
sc: bid.schain || {},
f: ensureFloor(getFloor(bid))
};

if (typeof tid === 'string' && tid.length > 0) {
Expand All @@ -143,52 +178,6 @@ function decorateADM(bid) {
return bid.adm + impressions;
}

function transformXmlSimple(bid) {
const pixels = []
_each([bid.nurl].concat(bid.ext != null && bid.ext.himp != null ? bid.ext.himp : []), (pixel) => {
if (pixel != null) {
pixels.push(`<Impression><![CDATA[${pixel}]]></Impression>`)
}
});
// find the current "Impression" here & slice ours in
const impressionIndex = bid.adm.indexOf('<Impression')
return bid.adm.slice(0, impressionIndex) + pixels.join('') + bid.adm.slice(impressionIndex)
}

function getOuterHTML(node) {
return 'outerHTML' in node && node.outerHTML != null
? node.outerHTML : (new XMLSerializer()).serializeToString(node)
}

function decorateVideoADM(bid) {
if (typeof DOMParser === 'undefined' || DOMParser.prototype.parseFromString == null) {
return transformXmlSimple(bid)
}

const doc = new DOMParser().parseFromString(bid.adm, 'text/xml');
if (doc == null || doc.querySelector('parsererror') != null) {
return null;
}

const root = doc.querySelector('InLine,Wrapper')
if (root == null) {
return null;
}

const pixels = [bid.nurl].concat(bid.ext != null && bid.ext.himp != null ? bid.ext.himp : [])
.filter((url) => url != null);

_each(pixels, (pxl) => {
const imagePixel = doc.createElement('Impression');
const cdata = doc.createCDATASection(pxl);
imagePixel.appendChild(cdata);
root.appendChild(imagePixel);
});

const dtdMatch = xmlDTDRxp.exec(bid.adm);
return (dtdMatch != null ? dtdMatch[0] : generateDTD(doc)) + getOuterHTML(doc.documentElement);
}

function resolveSize(bid, request, bidId) {
if (bid.w != null && bid.w > 1 && bid.h != null && bid.h > 1) {
return [bid.w, bid.h];
Expand All @@ -212,14 +201,16 @@ function values(source) {
});
}

const isTrue = (boolValue) =>
boolValue === true || boolValue === 1 || boolValue === 'true';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid(bid) {
return nullOrType(deepAccess(bid, 'params.endpoint', null), 'string') &&
nullOrType(deepAccess(bid, 'params.tagId', null), 'string') &&
nullOrType(deepAccess(bid, 'params.testMode', null), 'boolean');
nullOrType(deepAccess(bid, 'params.tagId', null), 'string')
},

buildRequests(bidRequests, bidderRequest) {
Expand All @@ -239,8 +230,9 @@ export const spec = {
brc: fbid.bidderRequestsCount || 0,
bwc: fbid.bidderWinsCount || 0,
trc: fbid.bidRequestsCount || 0,
tm: testMode,
tm: isTrue(testMode),
V: '$prebid.version$',
vg: '$$PREBID_GLOBAL$$',
i: (testMode && tagId != null) ? tagId : getID(loc),
l: {},
f: 0.01,
Expand All @@ -259,7 +251,8 @@ export const spec = {
d: '',
m: createBidMap(bidRequests),
cpp: config.getConfig('coppa') ? 1 : 0,
fpd: config.getLegacyFpd(config.getConfig('ortb2')),
fpd2: config.getConfig('ortb2'),
tmax: config.getConfig('bidderTimeout'),
eids: values(bidRequests.reduce((all, bid) => {
// we only want unique ones in here
if (bid == null || bid.userIdAsEids == null) {
Expand Down Expand Up @@ -306,7 +299,6 @@ export const spec = {
},

interpretResponse(serverResponse, request) {
// validate the body/response
const response = serverResponse.body;
if (response == null || typeof response === 'string') {
return [];
Expand All @@ -320,13 +312,14 @@ export const spec = {
return flatMap(response.r[bidID], (siteBid) =>
siteBid.b.map((bid) => {
const mediaType = getMediaType(bid);
// let ad = null;
let ad = mediaType === BANNER ? decorateADM(bid) : decorateVideoADM(bid);
const ad = mediaType === BANNER ? decorateADM(bid) : bid.adm;

if (ad == null) {
return null;
}

const size = resolveSize(bid, request.data, bidID);
const defaultExpiration = mediaType === BANNER ? 240 : 300;

return ({
requestId: bidID,
Expand All @@ -341,7 +334,7 @@ export const spec = {
advertiserDomains: bid.adomain,
mediaType,
},
ttl: mediaType === VIDEO ? 90 : 70
ttl: typeof bid.exp === 'number' ? bid.exp : defaultExpiration,
});
})).filter((possibleBid) => possibleBid != null);
});
Expand Down
24 changes: 12 additions & 12 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,24 @@ function _getVidParams (attributes) {
* @param {Object} bid
* @returns {Number} floor
*/
function _getFloor (mediaTypes, bidfloor, bid) {
function _getFloor (mediaTypes, staticBidfloor, bid) {
const curMediaType = Object.keys(mediaTypes)[0] || 'banner';
let floor = bidfloor || 0;
const bidFloor = { floor: 0, currency: 'USD' };

if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({
currency: 'USD',
const { currency, floor } = bid.getFloor({
mediaType: curMediaType,
size: '*'
});
floor && (bidFloor.floor = floor);
currency && (bidFloor.currency = currency);

if (typeof floorInfo === 'object' &&
floorInfo.currency === 'USD' &&
!isNaN(parseFloat(floorInfo.floor))) {
floor = Math.max(floor, parseFloat(floorInfo.floor));
if (staticBidfloor && floor && currency === 'USD') {
bidFloor.floor = Math.max(staticBidfloor, parseFloat(floor));
}
}

return floor;
return bidFloor;
}

/**
Expand All @@ -250,7 +249,7 @@ function buildRequests (validBidRequests, bidderRequest) {
transactionId,
userId = {}
} = bidRequest;
const bidFloor = _getFloor(mediaTypes, params.bidfloor, bidRequest);
const { currency, floor } = _getFloor(mediaTypes, params.bidfloor, bidRequest);
let sizes = [1, 1];
let data = {};

Expand All @@ -265,8 +264,9 @@ function buildRequests (validBidRequests, bidderRequest) {
data.pv = pageViewId;
}

if (bidFloor) {
data.fp = bidFloor;
if (floor) {
data.fp = floor;
data.fpc = currency;
}

if (params.iriscat && typeof params.iriscat === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion modules/hybridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function wrapAd(bid, bidData) {
parentDocument.style.width = "100%";
}
var _content = "${encodeURIComponent(JSON.stringify(bid.inImageContent))}";
window._ao_ssp.registerInImage(JSON.parse(decodeURIComponent(_content)));
window._hyb_prebid_ssp.registerInImage(JSON.parse(decodeURIComponent(_content)));
</script>
</body>
</html>`;
Expand Down
3 changes: 2 additions & 1 deletion modules/ironsourceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ function generateParameters(bid, bidderRequest) {
bid_id: utils.getBidIdParameter('bidId', bid),
bidder_request_id: utils.getBidIdParameter('bidderRequestId', bid),
transaction_id: utils.getBidIdParameter('transactionId', bid),
session_id: utils.getBidIdParameter('auctionId', bid),
session_id: params.sessionId || utils.getBidIdParameter('auctionId', bid),
is_wrapper: !!params.isWrapper,
publisher_name: domain,
site_domain: domain,
bidder_version: BIDDER_VERSION
Expand Down
10 changes: 1 addition & 9 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,7 @@ export const liveIntentIdSubmodule = {
const result = function(callback) {
liveConnect.resolve(
response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
callback(response);
},
error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
Expand Down
3 changes: 2 additions & 1 deletion modules/riseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ function generateParameters(bid, bidderRequest) {
bid_id: utils.getBidIdParameter('bidId', bid),
bidder_request_id: utils.getBidIdParameter('bidderRequestId', bid),
transaction_id: utils.getBidIdParameter('transactionId', bid),
session_id: utils.getBidIdParameter('auctionId', bid),
session_id: params.sessionId || utils.getBidIdParameter('auctionId', bid),
is_wrapper: !!params.isWrapper,
publisher_name: domain,
site_domain: domain,
bidder_version: BIDDER_VERSION
Expand Down
4 changes: 2 additions & 2 deletions modules/voxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function wrapInImageBanner(bid, bidData) {
var s = document.getElementById("prebidrenderer");
s.onload = function () {
var _html = "${encodeURIComponent(JSON.stringify(bid))}";
window._ao_ssp.registerInImage(JSON.parse(decodeURIComponent(_html)));
window._hyb_prebid_ssp.registerInImage(JSON.parse(decodeURIComponent(_html)));
}
s.src = "https://st.hybrid.ai/prebidrenderer.js?t=" + Date.now();
if (parent.window.frames[window.name]) {
Expand Down Expand Up @@ -157,7 +157,7 @@ function wrapBanner(bid, bidData) {
var s = document.getElementById("prebidrenderer");
s.onload = function () {
var _html = "${encodeURIComponent(JSON.stringify(bid))}";
window._ao_ssp.registerAds(JSON.parse(decodeURIComponent(_html)));
window._hyb_prebid_ssp.registerAds(JSON.parse(decodeURIComponent(_html)));
}
s.src = "https://st.hybrid.ai/prebidrenderer.js?t=" + Date.now();
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) {
var renderer = null;

// the renderer for the mediaType takes precendence
if (mediaTypeRenderer && mediaTypeRenderer.url && !(mediaTypeRenderer.backupOnly === true && mediaTypeRenderer.render)) {
if (mediaTypeRenderer && mediaTypeRenderer.url && mediaTypeRenderer.render && !(mediaTypeRenderer.backupOnly === true && bid.renderer)) {
renderer = mediaTypeRenderer;
} else if (adUnitRenderer && adUnitRenderer.url && !(adUnitRenderer.backupOnly === true && bid.renderer)) {
} else if (adUnitRenderer && adUnitRenderer.url && adUnitRenderer.render && !(adUnitRenderer.backupOnly === true && bid.renderer)) {
renderer = adUnitRenderer;
}

Expand Down
Loading