Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from prebid/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
pro-nsk authored May 27, 2021
2 parents 7412dc6 + 438b0e9 commit f161c29
Show file tree
Hide file tree
Showing 77 changed files with 3,756 additions and 754 deletions.
2 changes: 1 addition & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ version-resolver:
patch:
labels:
- 'patch'
default: patch
default: minor
template: |
## In This Release
$CHANGES
1 change: 0 additions & 1 deletion allowedModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
'modules': [
...sharedWhiteList,
'criteo-direct-rsa-validate',
'jsencrypt',
'crypto-js',
'live-connect' // Maintained by LiveIntent : https://github.com/liveintent-berlin/live-connect/
],
Expand Down
79 changes: 22 additions & 57 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,27 @@ import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { loadExternalScript } from '../src/adloader.js';
import JSEncrypt from 'jsencrypt/bin/jsencrypt.js';
import sha256 from 'crypto-js/sha256.js';
import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
import { getStorageManager } from '../src/storageManager.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { createEidsArray } from './userId/eids.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
import { OUTSTREAM } from '../src/video.js';

export const BIDDER_CODE = 'adagio';
export const LOG_PREFIX = 'Adagio:';
export const VERSION = '2.10.0';
export const FEATURES_VERSION = '1';
const BIDDER_CODE = 'adagio';
const LOG_PREFIX = 'Adagio:';
export const VERSION = '2.11.0';
const FEATURES_VERSION = '1';
export const ENDPOINT = 'https://mp.4dex.io/prebid';
export const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
export const ADAGIO_TAG_URL = 'https://script.4dex.io/localstore.js';
export const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
export const GVLID = 617;
const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
const ADAGIO_TAG_URL = 'https://script.4dex.io/localstore.js';
const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
const GVLID = 617;
export const storage = getStorageManager(GVLID, 'adagio');
export const RENDERER_URL = 'https://script.4dex.io/outstream-player.js';
export const MAX_SESS_DURATION = 30 * 60 * 1000;
export const ADAGIO_PUBKEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9el0+OEn6fvEh1RdVHQu4cnT0
jFSzIbGJJyg3cKqvtE6A0iaz9PkIdJIvSSSNrmJv+lRGKPEyRA/VnzJIieL39Ngl
t0b0lsHN+W4n9kitS/DZ/xnxWK/9vxhv0ZtL1LL/rwR5Mup7rmJbNtDoNBw4TIGj
pV6EP3MTLosuUEpLaQIDAQAB
-----END PUBLIC KEY-----`;
const MAX_SESS_DURATION = 30 * 60 * 1000;
const ADAGIO_PUBKEY = 'AL16XT44Sfp+8SHVF1UdC7hydPSMVLMhsYknKDdwqq+0ToDSJrP0+Qh0ki9JJI2uYm/6VEYo8TJED9WfMkiJ4vf02CW3RvSWwc35bif2SK1L8Nn/GfFYr/2/GG/Rm0vUsv+vBHky6nuuYls20Og0HDhMgaOlXoQ/cxMuiy5QSktp';
const ADAGIO_PUBKEY_E = 65537;

// This provide a whitelist and a basic validation
// of OpenRTB 2.5 options used by the Adagio SSP.
Expand Down Expand Up @@ -81,10 +75,7 @@ export function adagioScriptFromLocalStorageCb(ls) {
const hash = r[2];
const content = r[3];

var jsEncrypt = new JSEncrypt();
jsEncrypt.setPublicKey(ADAGIO_PUBKEY);

if (jsEncrypt.verify(content, hash, sha256)) {
if (verify(content, hash, ADAGIO_PUBKEY, ADAGIO_PUBKEY_E)) {
utils.logInfo(`${LOG_PREFIX} start script.`);
Function(ls)(); // eslint-disable-line no-new-func
} else {
Expand Down Expand Up @@ -524,19 +515,8 @@ function autoDetectAdUnitElementId(adUnitCode) {

function autoDetectEnvironment() {
const device = _features.getDevice();
let environment;
switch (device) {
case 2:
environment = 'desktop';
break;
case 4:
environment = 'mobile';
break;
case 5:
environment = 'tablet';
break;
};
return environment;
const map = { 2: 'desktop', 4: 'mobile', 5: 'tablet' };
return map[device] || 'unknown';
};

function supportIObs() {
Expand Down Expand Up @@ -653,25 +633,12 @@ function _getGdprConsent(bidderRequest) {
allowAuctionWithoutConsent
} = bidderRequest.gdprConsent;

const consent = {};

if (apiVersion !== undefined) {
consent.apiVersion = apiVersion;
}

if (consentString !== undefined) {
consent.consentString = consentString;
}

if (gdprApplies !== undefined) {
consent.consentRequired = (gdprApplies) ? 1 : 0;
}

if (allowAuctionWithoutConsent !== undefined) {
consent.allowAuctionWithoutConsent = allowAuctionWithoutConsent ? 1 : 0;
}

return consent;
return utils.cleanObj({
apiVersion,
consentString,
consentRequired: gdprApplies ? 1 : 0,
allowAuctionWithoutConsent: allowAuctionWithoutConsent ? 1 : 0
});
}

function _getCoppa() {
Expand All @@ -685,9 +652,7 @@ function _getUspConsent(bidderRequest) {
}

function _getSchain(bidRequest) {
if (utils.deepAccess(bidRequest, 'schain')) {
return bidRequest.schain;
}
return utils.deepAccess(bidRequest, 'schain');
}

function _getEids(bidRequest) {
Expand Down
130 changes: 109 additions & 21 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
NATIVE
NATIVE, BANNER, VIDEO
} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';

const { getConfig } = config;

const BIDDER_CODE = 'adf';
const GVLID = 50;
Expand Down Expand Up @@ -45,28 +48,58 @@ const NATIVE_PARAMS = {
name: 'data'
}
};
const OUTSTREAM_RENDERER_URL = 'https://s2.adform.net/banners/scripts/video/outstream/render.js';

export const spec = {
code: BIDDER_CODE,
aliases: BIDDER_ALIAS,
gvlid: GVLID,
supportedMediaTypes: [ NATIVE ],
supportedMediaTypes: [ NATIVE, BANNER, VIDEO ],
isBidRequestValid: bid => !!bid.params.mid,
buildRequests: (validBidRequests, bidderRequest) => {
const page = bidderRequest.refererInfo.referer;
let app, site;

const commonFpd = getConfig('ortb2') || {};
let { user } = commonFpd;

if (typeof getConfig('app') === 'object') {
app = getConfig('app') || {};
if (commonFpd.app) {
utils.mergeDeep(app, commonFpd.app);
}
} else {
site = getConfig('site') || {};
if (commonFpd.site) {
utils.mergeDeep(site, commonFpd.site);
}

if (!site.page) {
site.page = bidderRequest.refererInfo.referer;
}
}

const device = getConfig('device') || {};
device.w = device.w || window.innerWidth;
device.h = device.h || window.innerHeight;
device.ua = device.ua || navigator.userAgent;

const adxDomain = setOnAny(validBidRequests, 'params.adxDomain') || 'adx.adform.net';
const ua = navigator.userAgent;

const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net';
const tid = validBidRequests[0].transactionId; // ??? check with ssp
const tid = validBidRequests[0].transactionId;
const test = setOnAny(validBidRequests, 'params.test');
const publisher = setOnAny(validBidRequests, 'params.publisher');
const siteId = setOnAny(validBidRequests, 'params.siteId');
const currency = config.getConfig('currency.adServerCurrency');
const currency = getConfig('currency.adServerCurrency');
const cur = currency && [ currency ];
const eids = setOnAny(validBidRequests, 'userIdAsEids');

const imp = validBidRequests.map((bid, id) => {
bid.netRevenue = pt;

const imp = {
id: id + 1,
tagid: bid.params.mid
};

const assets = utils._map(bid.nativeParams, (bidParams, key) => {
const props = NATIVE_PARAMS[key];
const asset = {
Expand Down Expand Up @@ -102,21 +135,51 @@ export const spec = {
}
}).filter(Boolean);

return {
id: id + 1,
tagid: bid.params.mid,
native: {
if (assets.length) {
imp.native = {
request: {
assets
}
}
};
};

bid.mediaType = NATIVE;
return imp;
}

const bannerParams = utils.deepAccess(bid, 'mediaTypes.banner');

if (bannerParams && bannerParams.sizes) {
const sizes = utils.parseSizesInput(bannerParams.sizes);
const format = sizes.map(size => {
const [ width, height ] = size.split('x');
const w = parseInt(width, 10);
const h = parseInt(height, 10);
return { w, h };
});

imp.banner = {
format
};
bid.mediaType = BANNER;

return imp;
}

const videoParams = utils.deepAccess(bid, 'mediaTypes.video');
if (videoParams) {
imp.video = videoParams;
bid.mediaType = VIDEO;

return imp;
}
});

const request = {
id: bidderRequest.auctionId,
site: { id: siteId, page, publisher },
device: { ua },
site,
app,
user,
device,
source: { tid, fd: 1 },
ext: { pt },
cur,
Expand All @@ -128,8 +191,8 @@ export const spec = {
request.test = 1;
}
if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) {
request.user = { ext: { consent: bidderRequest.gdprConsent.consentString } };
request.regs = { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies & 1 } };
utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
utils.deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1);
}

if (bidderRequest.uspConsent) {
Expand Down Expand Up @@ -164,16 +227,35 @@ export const spec = {
return bids.map((bid, id) => {
const bidResponse = bidResponses[id];
if (bidResponse) {
return {
const result = {
requestId: bid.bidId,
cpm: bidResponse.price,
creativeId: bidResponse.crid,
ttl: 360,
netRevenue: bid.netRevenue === 'net',
currency: cur,
mediaType: NATIVE,
native: parseNative(bidResponse)
mediaType: bid.mediaType,
width: bidResponse.w,
height: bidResponse.h,
dealId: bidResponse.dealid,
meta: {
mediaType: bid.mediaType,
advertiserDomains: bidResponse.adomain
}
};

if (bidResponse.native) {
result.native = parseNative(bidResponse);
} else {
result[ bid.mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm;
}

if (!bid.renderer && bid.mediaType === VIDEO && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
result.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL, adUnitCode: bid.adUnitCode});
result.renderer.setRender(renderer);
}

return result;
}
}).filter(Boolean);
}
Expand Down Expand Up @@ -212,3 +294,9 @@ function setOnAny(collection, key) {
function flatten(arr) {
return [].concat(...arr);
}

function renderer(bid) {
bid.renderer.push(() => {
window.Adform.renderOutstream(bid);
});
}
Loading

0 comments on commit f161c29

Please sign in to comment.