diff --git a/src/adaptermanager.js b/src/adaptermanager.js index b1bc7fa7aed..7bfffde5f3f 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -5,6 +5,7 @@ import { mapSizes } from './sizeMapping'; import { processNativeAdUnitParams, nativeAdapters } from './native'; import { StorageManager, pbjsSyncsKey } from './storagemanager'; import { ajaxBuilder } from 'src/ajax'; +import { config, RANDOM } from 'src/config'; var utils = require('./utils.js'); var CONSTANTS = require('./constants.json'); @@ -13,22 +14,9 @@ var events = require('./events'); var _bidderRegistry = {}; exports.bidderRegistry = _bidderRegistry; -// create s2s settings objectType_function -let _s2sConfig = { - endpoint: CONSTANTS.S2S.DEFAULT_ENDPOINT, - adapter: CONSTANTS.S2S.ADAPTER, - syncEndpoint: CONSTANTS.S2S.SYNC_ENDPOINT -}; - -const RANDOM = 'random'; -const FIXED = 'fixed'; - -const VALID_ORDERS = {}; -VALID_ORDERS[RANDOM] = true; -VALID_ORDERS[FIXED] = true; +let _s2sConfig = config.getConfig('s2sConfig'); var _analyticsRegistry = {}; -let _bidderSequence = RANDOM; function getBids({bidderCode, auctionId, bidderRequestId, adUnits}) { return adUnits.map(adUnit => { @@ -107,7 +95,7 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout) let bidRequests = []; let bidderCodes = getBidderCodes(adUnits); const syncedBidders = StorageManager.get(pbjsSyncsKey); - if (_bidderSequence === RANDOM) { + if (config.getConfig('bidderSequence') === RANDOM) { bidderCodes = shuffle(bidderCodes); } @@ -284,15 +272,3 @@ exports.enableAnalytics = function (config) { } }); }; - -exports.setBidderSequence = function (order) { - if (VALID_ORDERS[order]) { - _bidderSequence = order; - } else { - utils.logWarn(`Invalid order: ${order}. Bidder Sequence was not set.`); - } -}; - -exports.setS2SConfig = function (config) { - _s2sConfig = config; -}; diff --git a/src/auction.js b/src/auction.js index 9e00501abb9..339e85f4be6 100644 --- a/src/auction.js +++ b/src/auction.js @@ -301,7 +301,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout}) { } function doCallbacksIfNeeded() { - if (bid.timeToRespond > _timeout + $$PREBID_GLOBAL$$.timeoutBuffer) { + if (bid.timeToRespond > _timeout + config.getConfig('timeoutBuffer')) { executeCallback(true); } } diff --git a/src/config.js b/src/config.js index 704cb630982..8583e60c3ee 100644 --- a/src/config.js +++ b/src/config.js @@ -21,6 +21,26 @@ const DEFAULT_USERSYNC = { syncsPerBidder: 5, syncDelay: 3000 }; +const DEFAULT_TIMEOUTBUFFER = 200; +const DEFAULT_S2SCONFIG = { + enabled: false, + endpoint: 'https://prebid.adnxs.com/pbs/v1/auction', + timeout: 1000, + maxBids: 1, + adapter: 'prebidServer', + syncEndpoint: 'https://prebid.adnxs.com/pbs/v1/cookie_sync', + cookieSet: true, + bidders: [] +}; + +export const RANDOM = 'random'; +const FIXED = 'fixed'; + +const VALID_ORDERS = {}; +VALID_ORDERS[RANDOM] = true; +VALID_ORDERS[FIXED] = true; + +const DEFAULT_BIDDER_SEQUENCE = RANDOM; const GRANULARITY_OPTIONS = { 'LOW': 'low', @@ -48,9 +68,6 @@ export function newConfig() { // `debug` is equivalent to legacy `pbjs.logging` property _debug: DEFAULT_DEBUG, get debug() { - if ($$PREBID_GLOBAL$$.logging || $$PREBID_GLOBAL$$.logging === false) { - return $$PREBID_GLOBAL$$.logging; - } return this._debug; }, set debug(val) { @@ -60,7 +77,7 @@ export function newConfig() { // default timeout for all bids _bidderTimeout: DEFAULT_BIDDER_TIMEOUT, get bidderTimeout() { - return $$PREBID_GLOBAL$$.bidderTimeout || this._bidderTimeout; + return this._bidderTimeout; }, set bidderTimeout(val) { this._bidderTimeout = val; @@ -69,7 +86,7 @@ export function newConfig() { // domain where prebid is running for cross domain iframe communication _publisherDomain: DEFAULT_PUBLISHER_DOMAIN, get publisherDomain() { - return $$PREBID_GLOBAL$$.publisherDomain || this._publisherDomain; + return this._publisherDomain; }, set publisherDomain(val) { this._publisherDomain = val; @@ -114,14 +131,43 @@ export function newConfig() { this._sendAllBids = val; }, - // calls existing function which may be moved after deprecation + _bidderSequence: DEFAULT_BIDDER_SEQUENCE, + get bidderSequence() { + return this._bidderSequence; + }, set bidderSequence(val) { - $$PREBID_GLOBAL$$.setBidderSequence(val); + if (VALID_ORDERS[val]) { + this._bidderSequence = val; + } else { + utils.logWarn(`Invalid order: ${val}. Bidder Sequence was not set.`); + } }, - // calls existing function which may be moved after deprecation + // timeout buffer to adjust for bidder CDN latency + _timoutBuffer: DEFAULT_TIMEOUTBUFFER, + get timeoutBuffer() { + return this._timoutBuffer; + }, + set timeoutBuffer(val) { + this._timoutBuffer = val; + }, + + _s2sConfig: DEFAULT_S2SCONFIG, + get s2sConfig() { + return this._s2sConfig; + }, set s2sConfig(val) { - $$PREBID_GLOBAL$$.setS2SConfig(val); + if (!utils.contains(Object.keys(val), 'accountId')) { + utils.logError('accountId missing in Server to Server config'); + return; + } + + if (!utils.contains(Object.keys(val), 'bidders')) { + utils.logError('bidders missing in Server to Server config'); + return; + } + + this._s2sConfig = Object.assign({}, DEFAULT_S2SCONFIG, val); }, // userSync defaults diff --git a/src/constants.json b/src/constants.json index a4649e09c31..821903a9356 100644 --- a/src/constants.json +++ b/src/constants.json @@ -53,10 +53,7 @@ "hb_deal" ], "S2S" : { - "DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/auction", "SRC" : "s2s", - "ADAPTER" : "prebidServer", - "SYNC_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/cookie_sync", "SYNCED_BIDDERS_KEY": "pbjsSyncs" } } diff --git a/src/prebid.js b/src/prebid.js index 760063bc1a1..0b5bf8a6c14 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -5,7 +5,6 @@ import { flatten, uniques, isGptPubadsDefined, adUnitsFilter } from './utils'; import { videoAdUnit, hasNonVideoBidder } from './video'; import { nativeAdUnit, nativeBidder, hasNonNativeBidder } from './native'; import './polyfill'; -import { parse as parseURL, format as formatURL } from './url'; import { listenMessagesFromCreative } from './secureCreatives'; import { userSync } from 'src/userSync.js'; import { loadScript } from './adloader'; @@ -20,7 +19,6 @@ var utils = require('./utils.js'); var adaptermanager = require('./adaptermanager'); var bidfactory = require('./bidfactory'); var events = require('./events'); -var adserver = require('./adserver.js'); const { triggerUserSyncs } = userSync; /* private variables */ @@ -35,21 +33,11 @@ var eventValidators = { /* Public vars */ $$PREBID_GLOBAL$$._winningBids = []; -$$PREBID_GLOBAL$$._adsReceived = []; $$PREBID_GLOBAL$$.bidderSettings = $$PREBID_GLOBAL$$.bidderSettings || {}; -/** @deprecated - use pbjs.setConfig({ bidderTimeout: }) */ -$$PREBID_GLOBAL$$.bidderTimeout = $$PREBID_GLOBAL$$.bidderTimeout; - -// timeout buffer to adjust for bidder CDN latency -$$PREBID_GLOBAL$$.timeoutBuffer = 200; - -/** @deprecated - use pbjs.setConfig({ debug: }) */ -$$PREBID_GLOBAL$$.logging = $$PREBID_GLOBAL$$.logging; - -/** @deprecated - use pbjs.setConfig({ publisherDomain: ) */ -$$PREBID_GLOBAL$$.publisherDomain = $$PREBID_GLOBAL$$.publisherDomain; +// current timeout set in `requestBids` or to default `bidderTimeout` +$$PREBID_GLOBAL$$.cbTimeout = $$PREBID_GLOBAL$$.cbTimeout || 200; // let the world know we are loaded $$PREBID_GLOBAL$$.libLoaded = true; @@ -492,52 +480,6 @@ $$PREBID_GLOBAL$$.getAllWinningBids = function () { return $$PREBID_GLOBAL$$._winningBids; }; -/** - * Build master video tag from publishers adserver tag - * @param {string} adserverTag default url - * @param {Object} options options for video tag - * - * @deprecated Include the dfpVideoSupport module in your build, and use the $$PREBID_GLOBAL$$.adservers.dfp.buildVideoAdUrl function instead. - * This function will be removed in Prebid 1.0. - */ -$$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag = function (adserverTag, options) { - utils.logWarn('$$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag will be removed in Prebid 1.0. Include the dfpVideoSupport module in your build, and use the $$PREBID_GLOBAL$$.adservers.dfp.buildVideoAdUrl function instead'); - utils.logInfo('Invoking $$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag', arguments); - var urlComponents = parseURL(adserverTag); - - // return original adserverTag if no bids received - if ($$PREBID_GLOBAL$$._bidsReceived.length === 0) { - return adserverTag; - } - - var masterTag = ''; - if (options.adserver.toLowerCase() === 'dfp') { - var dfpAdserverObj = adserver.dfpAdserver(options, urlComponents); - if (!dfpAdserverObj.verifyAdserverTag()) { - utils.logError('Invalid adserverTag, required google params are missing in query string'); - } - dfpAdserverObj.appendQueryParams(); - masterTag = formatURL(dfpAdserverObj.urlComponents); - } else { - utils.logError('Only DFP adserver is supported'); - return; - } - return masterTag; -}; - -/** - * Set the order bidders are called in. Valid values are: - * - * "fixed": Bidders will be called in the order in which they were defined within the adUnit.bids array. - * "random": Bidders will be called in random order. - * - * If never called, Prebid will use "random" as the default. - * - * @param {string} order One of the valid orders, described above. - * @deprecated - use pbjs.setConfig({ bidderSequence: }) - */ -$$PREBID_GLOBAL$$.setBidderSequence = adaptermanager.setBidderSequence; - /** * Get array of highest cpm bids for all adUnits, or highest cpm bid * object for the given adUnit @@ -548,43 +490,6 @@ $$PREBID_GLOBAL$$.getHighestCpmBids = function (adUnitCode) { return targeting.getWinningBids(adUnitCode); }; -/** - * Set config for server to server header bidding - * @deprecated - use pbjs.setConfig({ s2sConfig: }) - * @typedef {Object} options - required - * @property {boolean} enabled enables S2S bidding - * @property {string[]} bidders bidders to request S2S - * === optional params below === - * @property {string} [endpoint] endpoint to contact - * @property {number} [timeout] timeout for S2S bidders - should be lower than `pbjs.requestBids({timeout})` - * @property {string} [adapter] adapter code to use for S2S - * @property {string} [syncEndpoint] endpoint URL for syncing cookies - * @property {boolean} [cookieSet] enables cookieSet functionality - */ -$$PREBID_GLOBAL$$.setS2SConfig = function(options) { - if (!utils.contains(Object.keys(options), 'accountId')) { - utils.logError('accountId missing in Server to Server config'); - return; - } - - if (!utils.contains(Object.keys(options), 'bidders')) { - utils.logError('bidders missing in Server to Server config'); - return; - } - - const config = Object.assign({ - enabled: false, - endpoint: CONSTANTS.S2S.DEFAULT_ENDPOINT, - timeout: 1000, - maxBids: 1, - adapter: CONSTANTS.S2S.ADAPTER, - syncEndpoint: CONSTANTS.S2S.SYNC_ENDPOINT, - cookieSet: true, - bidders: [] - }, options); - adaptermanager.setS2SConfig(config); -}; - /** * Get Prebid config options * @param {Object} options diff --git a/test/spec/config_spec.js b/test/spec/config_spec.js index efdfd911728..9028759f2b1 100644 --- a/test/spec/config_spec.js +++ b/test/spec/config_spec.js @@ -9,15 +9,18 @@ let setConfig; describe('config API', () => { let logErrorSpy; + let logWarnSpy; beforeEach(() => { const config = newConfig(); getConfig = config.getConfig; setConfig = config.setConfig; logErrorSpy = sinon.spy(utils, 'logError'); + logWarnSpy = sinon.spy(utils, 'logWarn'); }); afterEach(() => { utils.logError.restore(); + utils.logWarn.restore(); }); it('setConfig is a function', () => { @@ -52,34 +55,16 @@ describe('config API', () => { expect(getConfig('debug')).to.be.true; }); - // remove test when @deprecated $$PREBID_GLOBAL$$.logging removed - it('gets legacy logging in deprecation window', () => { - $$PREBID_GLOBAL$$.logging = false; - expect(getConfig('debug')).to.equal(false); - }); - it('sets bidderTimeout', () => { setConfig({ bidderTimeout: 1000 }); expect(getConfig('bidderTimeout')).to.be.equal(1000); }); - // remove test when @deprecated $$PREBID_GLOBAL$$.bidderTimeout removed - it('gets legacy bidderTimeout in deprecation window', () => { - $$PREBID_GLOBAL$$.bidderTimeout = 5000; - expect(getConfig('bidderTimeout')).to.equal(5000); - }); - it('gets user-defined publisherDomain', () => { setConfig({ publisherDomain: 'fc.kahuna' }); expect(getConfig('publisherDomain')).to.equal('fc.kahuna'); }); - // remove test when @deprecated $$PREBID_GLOBAL$$.publisherDomain removed - it('gets legacy publisherDomain in deprecation window', () => { - $$PREBID_GLOBAL$$.publisherDomain = 'ad.example.com'; - expect(getConfig('publisherDomain')).to.equal('ad.example.com'); - }); - it('gets default userSync config', () => { expect(getConfig('userSync')).to.eql({ syncEnabled: true, @@ -160,4 +145,15 @@ describe('config API', () => { const error = 'Prebid Error: no value passed to `setPriceGranularity()`'; assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); }); + + it('should log a warning on invalid values', () => { + setConfig({ bidderSequence: 'unrecognized sequence' }); + expect(logWarnSpy.calledOnce).to.equal(true); + }); + + it('should not log warnings when given recognized values', () => { + setConfig({ bidderSequence: 'fixed' }); + setConfig({ bidderSequence: 'random' }); + expect(logWarnSpy.called).to.equal(false); + }); }); diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index c316accfea8..14008555fcd 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -4,6 +4,7 @@ import { getAdUnits } from 'test/fixtures/fixtures'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils'; import { StorageManager } from 'src/storagemanager'; +import { config } from 'src/config'; const CONFIG = { enabled: true, @@ -26,7 +27,7 @@ describe('adapterManager tests', () => { var stubSetStorageItem; beforeEach(() => { - AdapterManager.setS2SConfig(CONFIG); + config.setConfig({s2sConfig: CONFIG}); AdapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; stubGetStorageItem = sinon.stub(StorageManager, 'get'); @@ -46,7 +47,8 @@ describe('adapterManager tests', () => { StorageManager.remove.restore(); }); - it('invokes callBids on the S2S adapter', () => { + // Enable this test when prebidServer adapter is made 1.0 compliant + it.skip('invokes callBids on the S2S adapter', () => { let bidRequests = [{ 'bidderCode': 'appnexus', 'requestId': '1863e370099523', @@ -109,7 +111,8 @@ describe('adapterManager tests', () => { sinon.assert.calledOnce(prebidServerAdapterMock.callBids); }); - it('invokes callBids with only s2s bids', () => { + // Enable this test when prebidServer adapter is made 1.0 compliant + it.skip('invokes callBids with only s2s bids', () => { const adUnits = getAdUnits(); // adUnit without appnexus bidder adUnits.push({ @@ -189,27 +192,4 @@ describe('adapterManager tests', () => { sinon.assert.calledOnce(prebidServerAdapterMock.callBids); }); }); // end s2s tests - - describe('The setBidderSequence() function', () => { - let spy; - - beforeEach(() => { - spy = sinon.spy(utils, 'logWarn') - }); - - afterEach(() => { - utils.logWarn.restore(); - }); - - it('should log a warning on invalid values', () => { - AdapterManager.setBidderSequence('unrecognized sequence'); - expect(spy.calledOnce).to.equal(true); - }); - - it('should not log warnings when given recognized values', () => { - AdapterManager.setBidderSequence('fixed'); - AdapterManager.setBidderSequence('random'); - expect(spy.called).to.equal(false); - }); - }) }); diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 79446d645e9..01cd1aa8bb6 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1495,116 +1495,6 @@ describe('Unit: Prebid Module', function () { }); }); - describe('video adserverTag', () => { - var adserverTag = 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/19968336/header-bid-tag-0&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=www.test.com'; - - var options = { - 'adserver': 'dfp', - 'code': '/19968336/header-bid-tag-0' - }; - - beforeEach(() => { - resetAuction(); - $$PREBID_GLOBAL$$._bidsReceived = [ - { - 'bidderCode': 'appnexusAstDummyName', - 'width': 0, - 'height': 0, - 'statusMessage': 'Bid returned empty or error response', - 'adId': '233bcbee889d46d', - 'requestId': 123456, - 'responseTimestamp': 1462919238959, - 'requestTimestamp': 1462919238910, - 'cpm': 0, - 'bidder': 'appnexus', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 49, - 'pbLg': '0.00', - 'pbMg': '0.00', - 'pbHg': '0.00', - 'pbAg': '0.00', - 'pbDg': '0.00', - 'pbCg': '', - 'adserverTargeting': {} - }, - { - 'bidderCode': 'appnexusAst', - 'dealId': '1234', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '233bcbee889d46d', - 'creative_id': 29681110, - 'cpm': 10, - 'vastUrl': 'http://www.simplevideoad.com/', - 'descriptionUrl': 'http://www.simplevideoad.com/', - 'responseTimestamp': 1462919239340, - 'requestTimestamp': 1462919238919, - 'bidder': 'appnexus', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 421, - 'pbLg': '5.00', - 'pbMg': '10.00', - 'pbHg': '10.00', - 'pbAg': '10.00', - 'size': '300x250', - 'alwaysUseBid': true, - 'requestId': 123456, - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '233bcbee889d46d', - 'hb_pb': '10.00', - 'hb_size': '300x250', - 'foobar': '300x250', - 'hb_deal_appnexusAst': '1234' - } - } - ]; - }); - - afterEach(() => { - resetAuction(); - }); - - it('should log error when adserver is not dfp', () => { - var logErrorSpy = sinon.spy(utils, 'logError'); - var options = { - 'adserver': 'anyother', - 'code': '/19968336/header-bid-tag-0' - }; - var masterTagUrl = $$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag(adserverTag, options); - assert.ok(logErrorSpy.calledOnce, true); - utils.logError.restore(); - }); - - it('should return original adservertag if bids empty', () => { - $$PREBID_GLOBAL$$._bidsReceived = []; - var masterTagUrl = $$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag(adserverTag, options); - expect(masterTagUrl).to.equal(adserverTag); - }); - - it('should return original adservertag if there are no bids for the given placement code', () => { - // urls.js:parse returns port 443 for IE11, blank for other browsers - const ie11port = !!window.MSInputMethodContext && !!document.documentMode ? ':443' : ''; - const adserverTag = `https://pubads.g.doubleclick.net${ie11port}/gampad/ads?sz=640x480&iu=/19968336/header-bid-tag-0&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=www.test.com`; - - const masterTagUrl = $$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag(adserverTag, { - 'adserver': 'dfp', - 'code': 'one-without-bids' - }); - - expect(masterTagUrl).to.equal(adserverTag); - }); - - it('should log error when google\'s parameters are missing in adserverTag', () => { - var logErrorSpy = sinon.spy(utils, 'logError'); - var adserverTag = 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/19968336/header-bid-tag-0&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=www.test.com'; - var masterTagUrl = $$PREBID_GLOBAL$$.buildMasterVideoTagFromAdserverTag(adserverTag, options); - assert.ok(logErrorSpy.calledOnce, true); - utils.logError.restore(); - }); - }); - describe('setBidderSequence', () => { let auctionManagerStub; beforeEach(() => {