-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
replace usePrebidCache with cache:url and remove default #1904
Changes from 1 commit
c903646
9c891a4
adc745d
7473130
4a6c6e0
ea09bc8
786a638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,128 +46,130 @@ const ALL_TOPICS = '*'; | |
/** | ||
* @typedef {object} PrebidConfig | ||
* | ||
* @property {bool} usePrebidCache True if we should use prebid-cache to store video bids before adding | ||
* bids to the auction, and false otherwise. **NOTE** This must be true if you want to use the | ||
* dfpAdServerVideo module. | ||
* @property {bool} config.cacheUrl Set a url if we should use prebid-cache to store video bids before adding | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this should be a Just so you're aware, we'll be building some cache features into To give you some idea, this is (roughly) the API I'm planning for PBS:
If you have feedback on this, feel free to discuss it over on prebid/prebid-server#216. For this PR, though: It might be better to make a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm cool with that. I'll update it to be |
||
* bids to the auction. **NOTE** This must be set if you want to use the dfpAdServerVideo module. | ||
*/ | ||
|
||
export function newConfig() { | ||
let listeners = []; | ||
|
||
let defaults = {}; | ||
|
||
let config = { | ||
// `debug` is equivalent to legacy `pbjs.logging` property | ||
_debug: DEFAULT_DEBUG, | ||
get debug() { | ||
return this._debug; | ||
}, | ||
set debug(val) { | ||
this._debug = val; | ||
}, | ||
|
||
// default timeout for all bids | ||
_bidderTimeout: DEFAULT_BIDDER_TIMEOUT, | ||
get bidderTimeout() { | ||
return this._bidderTimeout; | ||
}, | ||
set bidderTimeout(val) { | ||
this._bidderTimeout = val; | ||
}, | ||
|
||
// domain where prebid is running for cross domain iframe communication | ||
_publisherDomain: DEFAULT_PUBLISHER_DOMAIN, | ||
get publisherDomain() { | ||
return this._publisherDomain; | ||
}, | ||
set publisherDomain(val) { | ||
this._publisherDomain = val; | ||
}, | ||
|
||
// delay to request cookie sync to stay out of critical path | ||
_cookieSyncDelay: DEFAULT_COOKIESYNC_DELAY, | ||
get cookieSyncDelay() { | ||
return $$PREBID_GLOBAL$$.cookieSyncDelay || this._cookieSyncDelay; | ||
}, | ||
set cookieSyncDelay(val) { | ||
this._cookieSyncDelay = val; | ||
}, | ||
|
||
// calls existing function which may be moved after deprecation | ||
_priceGranularity: GRANULARITY_OPTIONS.MEDIUM, | ||
set priceGranularity(val) { | ||
if (validatePriceGranularity(val)) { | ||
if (typeof val === 'string') { | ||
this._priceGranularity = (hasGranularity(val)) ? val : GRANULARITY_OPTIONS.MEDIUM; | ||
} else if (typeof val === 'object') { | ||
this._customPriceBucket = val; | ||
this._priceGranularity = GRANULARITY_OPTIONS.CUSTOM; | ||
utils.logMessage('Using custom price granularity'); | ||
let defaults; | ||
let config; | ||
|
||
function resetConfig() { | ||
defaults = {}; | ||
config = { | ||
// `debug` is equivalent to legacy `pbjs.logging` property | ||
_debug: DEFAULT_DEBUG, | ||
get debug() { | ||
return this._debug; | ||
}, | ||
set debug(val) { | ||
this._debug = val; | ||
}, | ||
|
||
// default timeout for all bids | ||
_bidderTimeout: DEFAULT_BIDDER_TIMEOUT, | ||
get bidderTimeout() { | ||
return this._bidderTimeout; | ||
}, | ||
set bidderTimeout(val) { | ||
this._bidderTimeout = val; | ||
}, | ||
|
||
// domain where prebid is running for cross domain iframe communication | ||
_publisherDomain: DEFAULT_PUBLISHER_DOMAIN, | ||
get publisherDomain() { | ||
return this._publisherDomain; | ||
}, | ||
set publisherDomain(val) { | ||
this._publisherDomain = val; | ||
}, | ||
|
||
// delay to request cookie sync to stay out of critical path | ||
_cookieSyncDelay: DEFAULT_COOKIESYNC_DELAY, | ||
get cookieSyncDelay() { | ||
return $$PREBID_GLOBAL$$.cookieSyncDelay || this._cookieSyncDelay; | ||
}, | ||
set cookieSyncDelay(val) { | ||
this._cookieSyncDelay = val; | ||
}, | ||
|
||
// calls existing function which may be moved after deprecation | ||
_priceGranularity: GRANULARITY_OPTIONS.MEDIUM, | ||
set priceGranularity(val) { | ||
if (validatePriceGranularity(val)) { | ||
if (typeof val === 'string') { | ||
this._priceGranularity = (hasGranularity(val)) ? val : GRANULARITY_OPTIONS.MEDIUM; | ||
} else if (typeof val === 'object') { | ||
this._customPriceBucket = val; | ||
this._priceGranularity = GRANULARITY_OPTIONS.CUSTOM; | ||
utils.logMessage('Using custom price granularity'); | ||
} | ||
} | ||
} | ||
}, | ||
get priceGranularity() { | ||
return this._priceGranularity; | ||
}, | ||
|
||
_customPriceBucket: {}, | ||
get customPriceBucket() { | ||
return this._customPriceBucket; | ||
}, | ||
|
||
_sendAllBids: DEFAULT_ENABLE_SEND_ALL_BIDS, | ||
get enableSendAllBids() { | ||
return this._sendAllBids; | ||
}, | ||
set enableSendAllBids(val) { | ||
this._sendAllBids = val; | ||
}, | ||
|
||
_bidderSequence: DEFAULT_BIDDER_SEQUENCE, | ||
get bidderSequence() { | ||
return this._bidderSequence; | ||
}, | ||
set bidderSequence(val) { | ||
if (VALID_ORDERS[val]) { | ||
this._bidderSequence = val; | ||
} else { | ||
utils.logWarn(`Invalid order: ${val}. Bidder Sequence was not set.`); | ||
} | ||
}, | ||
|
||
// timeout buffer to adjust for bidder CDN latency | ||
_timoutBuffer: DEFAULT_TIMEOUTBUFFER, | ||
get timeoutBuffer() { | ||
return this._timoutBuffer; | ||
}, | ||
set timeoutBuffer(val) { | ||
this._timoutBuffer = val; | ||
}, | ||
|
||
// userSync defaults | ||
userSync: DEFAULT_USERSYNC | ||
}; | ||
|
||
function hasGranularity(val) { | ||
return Object.keys(GRANULARITY_OPTIONS).find(option => val === GRANULARITY_OPTIONS[option]); | ||
} | ||
}, | ||
get priceGranularity() { | ||
return this._priceGranularity; | ||
}, | ||
|
||
_customPriceBucket: {}, | ||
get customPriceBucket() { | ||
return this._customPriceBucket; | ||
}, | ||
|
||
_sendAllBids: DEFAULT_ENABLE_SEND_ALL_BIDS, | ||
get enableSendAllBids() { | ||
return this._sendAllBids; | ||
}, | ||
set enableSendAllBids(val) { | ||
this._sendAllBids = val; | ||
}, | ||
|
||
_bidderSequence: DEFAULT_BIDDER_SEQUENCE, | ||
get bidderSequence() { | ||
return this._bidderSequence; | ||
}, | ||
set bidderSequence(val) { | ||
if (VALID_ORDERS[val]) { | ||
this._bidderSequence = val; | ||
} else { | ||
utils.logWarn(`Invalid order: ${val}. Bidder Sequence was not set.`); | ||
} | ||
}, | ||
|
||
// timeout buffer to adjust for bidder CDN latency | ||
_timoutBuffer: DEFAULT_TIMEOUTBUFFER, | ||
get timeoutBuffer() { | ||
return this._timoutBuffer; | ||
}, | ||
set timeoutBuffer(val) { | ||
this._timoutBuffer = val; | ||
}, | ||
|
||
// userSync defaults | ||
userSync: DEFAULT_USERSYNC | ||
}; | ||
|
||
function validatePriceGranularity(val) { | ||
if (!val) { | ||
utils.logError('Prebid Error: no value passed to `setPriceGranularity()`'); | ||
return false; | ||
function hasGranularity(val) { | ||
return Object.keys(GRANULARITY_OPTIONS).find(option => val === GRANULARITY_OPTIONS[option]); | ||
} | ||
if (typeof val === 'string') { | ||
if (!hasGranularity(val)) { | ||
utils.logWarn('Prebid Warning: setPriceGranularity was called with invalid setting, using `medium` as default.'); | ||
} | ||
} else if (typeof val === 'object') { | ||
if (!isValidPriceConfig(val)) { | ||
utils.logError('Invalid custom price value passed to `setPriceGranularity()`'); | ||
|
||
function validatePriceGranularity(val) { | ||
if (!val) { | ||
utils.logError('Prebid Error: no value passed to `setPriceGranularity()`'); | ||
return false; | ||
} | ||
if (typeof val === 'string') { | ||
if (!hasGranularity(val)) { | ||
utils.logWarn('Prebid Warning: setPriceGranularity was called with invalid setting, using `medium` as default.'); | ||
} | ||
} else if (typeof val === 'object') { | ||
if (!isValidPriceConfig(val)) { | ||
utils.logError('Invalid custom price value passed to `setPriceGranularity()`'); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
|
||
/* | ||
|
@@ -289,10 +291,13 @@ export function newConfig() { | |
.forEach(listener => listener.callback(options)); | ||
} | ||
|
||
resetConfig(); | ||
|
||
return { | ||
getConfig, | ||
setConfig, | ||
setDefaults | ||
setDefaults, | ||
resetConfig | ||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import 'mocha'; | ||
import chai from 'chai'; | ||
import { getCacheUrl, store } from 'src/videoCache'; | ||
import { config } from 'src/config'; | ||
|
||
const should = chai.should(); | ||
|
||
|
@@ -48,9 +49,17 @@ describe('The video cache', () => { | |
xhr = sinon.useFakeXMLHttpRequest(); | ||
requests = []; | ||
xhr.onCreate = (request) => requests.push(request); | ||
config.setConfig({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why wouldn't you just use It cuts down on the changes you need to make for this PR by quite a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that |
||
video: { | ||
cacheUrl: 'https://prebid.adnxs.com/pbc/v1/cache' | ||
} | ||
}) | ||
}); | ||
|
||
afterEach(() => xhr.restore()); | ||
afterEach(() => { | ||
xhr.restore(); | ||
config.resetConfig(); | ||
}); | ||
|
||
it('should execute the callback with a successful result when store() is called', () => { | ||
const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371'; | ||
|
@@ -128,6 +137,18 @@ describe('The video cache', () => { | |
}); | ||
|
||
describe('The getCache function', () => { | ||
beforeEach(() => { | ||
config.setConfig({ | ||
video: { | ||
cacheUrl: 'https://prebid.adnxs.com/pbc/v1/cache' | ||
} | ||
}) | ||
}); | ||
|
||
afterEach(() => { | ||
config.resetConfig(); | ||
}); | ||
|
||
it('should return the expected URL', () => { | ||
const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371'; | ||
const url = getCacheUrl(uuid); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snapwich Not sure if I did something wrong when checking this branch out locally but I see one remaining reference to
usePrebidCache
in this file on line 155. Everything else lgtmThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you are correct. It looks like Jaimin added a new call to
usePrebidCache
after the creation of this pull-request which I got with the latest merge update. Just fixed and updated, as well as removed a call to it in one of the bid adapters.