Skip to content

Commit

Permalink
Revert "Nativo Bid Adapter: adding UserId support (prebid#9583)" (pre…
Browse files Browse the repository at this point in the history
…bid#9691)

This reverts commit aa100bc.
  • Loading branch information
ChrisHuie authored and jorgeluisrocha committed May 18, 2023
1 parent 6c86fba commit bbb4e38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 205 deletions.
115 changes: 10 additions & 105 deletions modules/nativoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
const requestData = new RequestData()
requestData.addBidRequestDataSource(new UserEIDs())

// Parse values from bid requests
const placementIds = new Set()
const bidDataMap = BidDataMap()
Expand Down Expand Up @@ -169,8 +166,6 @@ export const spec = {
if (bidRequestFloorPriceData) {
floorPriceData[bidRequest.adUnitCode] = bidRequestFloorPriceData
}

requestData.processBidRequestData(bidRequest, bidderRequest)
})
bidRequestMap[bidderRequest.bidderRequestId] = bidDataMap

Expand Down Expand Up @@ -260,12 +255,9 @@ export const spec = {
params.unshift({ key: 'us_privacy', value: bidderRequest.uspConsent })
}

const qsParamStrings = [requestData.getRequestDataQueryString(), arrayToQS(params)]
const requestUrl = buildRequestUrl(BIDDER_ENDPOINT, qsParamStrings)

let serverRequest = {
method: 'GET',
url: requestUrl
url: BIDDER_ENDPOINT + arrayToQS(params),
}

return serverRequest
Expand Down Expand Up @@ -417,7 +409,7 @@ export const spec = {
* Adapter can fire a ajax or pixel call to register a timeout at thier end.
* @param {Object} timeoutData - Timeout specific data
*/
onTimeout: function (timeoutData) { },
onTimeout: function (timeoutData) {},

/**
* Will be called when a bid from the adapter won the auction.
Expand All @@ -437,7 +429,7 @@ export const spec = {
* Will be called when the adserver targeting has been set for a bid from the adapter.
* @param {Object} bidder - The bid of which the targeting has been set
*/
onSetTargeting: function (bid) { },
onSetTargeting: function (bid) {},

/**
* Maps Prebid's bidId to Nativo's placementId values per unique bidderRequestId
Expand All @@ -459,78 +451,6 @@ export const spec = {
registerBidder(spec)

// Utils
export class RequestData {
constructor() {
this.bidRequestDataSources = []
}

addBidRequestDataSource(bidRequestDataSource) {
if (!(bidRequestDataSource instanceof BidRequestDataSource)) return

this.bidRequestDataSources.push(bidRequestDataSource)
}

processBidRequestData(bidRequest, bidderRequest) {
for (let bidRequestDataSource of this.bidRequestDataSources) {
bidRequestDataSource.processBidRequestData(bidRequest, bidderRequest)
}
}

getRequestDataQueryString() {
if (this.bidRequestDataSources.length == 0) return

const queryParams = this.bidRequestDataSources.map(dataSource => dataSource.getRequestQueryString()).filter(queryString => queryString !== '')
return queryParams.join('&')
}
}

export class BidRequestDataSource {
constructor() {
this.type = 'BidRequestDataSource'
}
processBidRequestData(bidRequest, bidderRequest) { }
getRequestQueryString() { return '' }
}

export class UserEIDs extends BidRequestDataSource {
constructor() {
super()
this.type = 'UserEIDs'
this.qsParam = new QueryStringParam('ntv_pb_eid')
this.eids = []
}

processBidRequestData(bidRequest, bidderRequest) {
if (bidRequest.userIdAsEids === undefined || this.eids.length > 0) return
this.eids = bidRequest.userIdAsEids
}

getRequestQueryString() {
if (this.eids.length === 0) return ''

const encodedValueArray = encodeToBase64(this.eids)
this.qsParam.value = encodedValueArray
return this.qsParam.toString()
}
}

export class QueryStringParam {
constructor(key, value) {
this.key = key
this.value = value
}
}

QueryStringParam.prototype.toString = function () {
return `${this.key}=${this.value}`
}

export function encodeToBase64(value) {
try {
return btoa(JSON.stringify(value))
} catch (err) { }
}

export function parseFloorPriceData(bidRequest) {
if (typeof bidRequest.getFloor !== 'function') return

Expand Down Expand Up @@ -669,9 +589,12 @@ function appendQSParamString(str, key, value) {
* @returns
*/
function arrayToQS(arr) {
return arr.reduce((value, obj) => {
return appendQSParamString(value, obj.key, obj.value)
}, '')
return (
'?' +
arr.reduce((value, obj) => {
return appendQSParamString(value, obj.key, obj.value)
}, '')
)
}

/**
Expand All @@ -692,24 +615,6 @@ function getLargestSize(sizes, method = area) {
})
}

/**
* Build the final request url
*/
export function buildRequestUrl(baseUrl, qsParamStringArray = []) {
if (qsParamStringArray.length === 0 || !Array.isArray(qsParamStringArray)) return baseUrl

const nonEmptyQSParamStrings = qsParamStringArray.filter(qsParamString => qsParamString.trim() !== '')

if (nonEmptyQSParamStrings.length === 0) return baseUrl

let requestUrl = `${baseUrl}?${nonEmptyQSParamStrings[0]}`
for (let i = 1; i < nonEmptyQSParamStrings.length; i++) {
requestUrl += `&${nonEmptyQSParamStrings[i]}`
}

return requestUrl
}

/**
* Calculate the area
* @param {Array} size - [width, height]
Expand Down Expand Up @@ -740,7 +645,7 @@ export function getPageUrlFromBidRequest(bidRequest) {
try {
const url = new URL(paramPageUrl)
return url.href
} catch (err) { }
} catch (err) {}
}

export function hasProtocol(url) {
Expand Down
100 changes: 0 additions & 100 deletions test/spec/modules/nativoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
getPageUrlFromBidRequest,
hasProtocol,
addProtocol,
BidRequestDataSource,
RequestData,
UserEIDs,
buildRequestUrl,
} from '../../../modules/nativoBidAdapter'

describe('bidDataMap', function () {
Expand Down Expand Up @@ -735,99 +731,3 @@ describe('getPageUrlFromBidRequest', () => {
expect(url).not.to.be.undefined
})
})

describe('RequestData', () => {
describe('addBidRequestDataSource', () => {
it('Adds a BidRequestDataSource', () => {
const requestData = new RequestData()
const testBidRequestDataSource = new BidRequestDataSource()

requestData.addBidRequestDataSource(testBidRequestDataSource)

expect(requestData.bidRequestDataSources.length == 1)
})

it("Doeasn't add a non BidRequestDataSource", () => {
const requestData = new RequestData()

requestData.addBidRequestDataSource({})
requestData.addBidRequestDataSource('test')
requestData.addBidRequestDataSource(1)
requestData.addBidRequestDataSource(true)

expect(requestData.bidRequestDataSources.length == 0)
})
})

describe('getRequestDataString', () => {
it("Doesn't append empty query strings", () => {
const requestData = new RequestData()
const testBidRequestDataSource = new BidRequestDataSource()

requestData.addBidRequestDataSource(testBidRequestDataSource)

let qs = requestData.getRequestDataQueryString()
expect(qs).to.be.empty

testBidRequestDataSource.getRequestQueryString = () => {
return 'ntv_test=true'
}
qs = requestData.getRequestDataQueryString()
expect(qs).to.be.equal('ntv_test=true')
})
})
})

describe('UserEIDs', () => {
const userEids = new UserEIDs()
const eids = [{ 'testId': 1111 }]

describe('processBidRequestData', () => {
it('Processes bid request without eids', () => {
userEids.processBidRequestData({})

expect(userEids.values).to.be.empty
})

it('Processed bid request with eids', () => {
userEids.processBidRequestData({ userIdAsEids: eids })

expect(userEids.values).to.not.be.empty
})
})

describe('getRequestQueryString', () => {
it('Correctly prints out QS param string', () => {
const qs = userEids.getRequestQueryString()
const value = qs.slice(11)

expect(qs).to.include('ntv_pb_eid=')
try {
expect(JSON.parse(value)).to.be.equal(eids)
} catch (err) { }
})
})
})

describe.only('buildRequestUrl', () => {
const baseUrl = 'https://www.testExchange.com'
it('Returns baseUrl if no QS strings passed', () => {
const url = buildRequestUrl(baseUrl)
expect(url).to.be.equal(baseUrl)
})

it('Returns baseUrl if empty QS strings passed', () => {
const url = buildRequestUrl(baseUrl, ['', '', ''])
expect(url).to.be.equal(baseUrl)
})

it('Returns baseUrl + QS params if QS strings passed', () => {
const url = buildRequestUrl(baseUrl, ['ntv_ptd=123456&ntv_test=true', 'ntv_foo=bar'])
expect(url).to.be.equal(`${baseUrl}?ntv_ptd=123456&ntv_test=true&ntv_foo=bar`)
})

it('Returns baseUrl + QS params if mixed QS strings passed', () => {
const url = buildRequestUrl(baseUrl, ['ntv_ptd=123456&ntv_test=true', '', '', 'ntv_foo=bar'])
expect(url).to.be.equal(`${baseUrl}?ntv_ptd=123456&ntv_test=true&ntv_foo=bar`)
})
})

0 comments on commit bbb4e38

Please sign in to comment.