Skip to content

Commit

Permalink
Multiple Bid/Analytics/ID/ other modules: import utils functions as n…
Browse files Browse the repository at this point in the history
…eeded and not the whole module (prebid#7492)

* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* Revert "import utils functions as needed and not the whole module"

This reverts commit bc6c9f6.

* Revert "import utils functions as needed and not the whole module"

This reverts commit ef500ab.

* Revert "import utils functions as needed and not the whole module"

This reverts commit 7e3fa3f.

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module
  • Loading branch information
pm-harshad-mane authored and Chris Pabst committed Jan 10, 2022
1 parent da6ff18 commit df117c9
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 410 deletions.
26 changes: 13 additions & 13 deletions modules/ooloAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _each, deepClone, pick, deepSetValue, getOrigin, logError, logInfo } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js'
import adapterManager from '../src/adapterManager.js'
import CONSTANTS from '../src/constants.json'
import * as utils from '../src/utils.js'
import { ajax } from '../src/ajax.js'
import { config } from '../src/config.js'

Expand Down Expand Up @@ -64,7 +64,7 @@ const onAuctionInit = (args) => {

handleCustomFields(auction, AUCTION_INIT, args)

utils._each(adUnits, adUnit => {
_each(adUnits, adUnit => {
auction.adUnits[adUnit.code] = {
...adUnit,
auctionId,
Expand Down Expand Up @@ -144,7 +144,7 @@ const onBidWon = (args) => {
}

const onBidTimeout = (args) => {
utils._each(args, bid => {
_each(args, bid => {
const { auctionId, adUnitCode } = bid
const bidId = parseBidId(bid)
let bidCache = auctions[auctionId].adUnits[adUnitCode].bids[bidId]
Expand Down Expand Up @@ -172,7 +172,7 @@ const onAuctionEnd = (args) => {
}

const onAdRenderFailed = (args) => {
const data = utils.deepClone(args)
const data = deepClone(args)
data.timestamp = Date.now()

if (data.bid) {
Expand Down Expand Up @@ -232,7 +232,7 @@ function handleEvent(eventType, args) {
}

function sendEvent(eventType, args, isRaw) {
let data = utils.deepClone(args)
let data = deepClone(args)

Object.assign(data, buildCommonDataProperties(), {
eventType
Expand Down Expand Up @@ -268,7 +268,7 @@ function checkEventsQueue() {
}

function buildAuctionData(auction) {
const auctionData = utils.deepClone(auction)
const auctionData = deepClone(auction)
const keysToRemove = ['adUnitCodes', 'auctionStatus', 'bidderRequests', 'bidsReceived', 'noBids', 'winningBids', 'timestamp', 'config']

keysToRemove.forEach(key => {
Expand Down Expand Up @@ -367,12 +367,12 @@ function handleCustomFields(obj, eventType, args) {
const { pickFields, omitFields } = initOptions.serverConfig.events[eventType]

if (pickFields && obj && args) {
Object.assign(obj, utils.pick(args, pickFields))
Object.assign(obj, pick(args, pickFields))
}

if (omitFields && obj && args) {
omitFields.forEach(field => {
utils.deepSetValue(obj, field, undefined)
deepSetValue(obj, field, undefined)
})
}
} catch (e) { }
Expand All @@ -382,7 +382,7 @@ function handleCustomRawFields(obj, omitRawFields) {
try {
if (omitRawFields && obj) {
omitRawFields.forEach(field => {
utils.deepSetValue(obj, field, undefined)
deepSetValue(obj, field, undefined)
})
}
} catch (e) { }
Expand Down Expand Up @@ -419,7 +419,7 @@ function sendPage() {
screenHeight: window.screen.height,
url: window.location.href,
protocol: window.location.protocol,
origin: utils.getOrigin(),
origin: getOrigin(),
referrer: getTopWindowReferrer(),
pbVersion: prebidVersion,
}
Expand Down Expand Up @@ -507,7 +507,7 @@ ooloAdapter.enableAnalytics = function (config) {
initOptions = config ? config.options : {}

if (!initOptions.pid) {
utils.logError(buildLogMessage('enableAnalytics missing config object with "pid"'))
logError(buildLogMessage('enableAnalytics missing config object with "pid"'))
return
}

Expand All @@ -520,9 +520,9 @@ ooloAdapter.enableAnalytics = function (config) {
window.addEventListener('load', sendPage)
}

utils.logInfo(buildLogMessage('enabled analytics adapter'), config)
logInfo(buildLogMessage('enabled analytics adapter'), config)
ooloAdapter.enableAnalytics = function () {
utils.logInfo(buildLogMessage('Analytics adapter already enabled..'))
logInfo(buildLogMessage('Analytics adapter already enabled..'))
}
}

Expand Down
52 changes: 26 additions & 26 deletions modules/openwebBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { isNumber, deepAccess, isArray, flatten, convertTypes, parseSizesInput } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
Expand All @@ -14,7 +14,7 @@ export const spec = {
gvlid: 280,
supportedMediaTypes: [VIDEO, BANNER, ADPOD],
isBidRequestValid: function (bid) {
return utils.isNumber(utils.deepAccess(bid, 'params.aid'));
return isNumber(deepAccess(bid, 'params.aid'));
},
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];
Expand Down Expand Up @@ -43,9 +43,9 @@ export const spec = {
}

if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) {
utils.isArray(serverResponses) && serverResponses.forEach((response) => {
isArray(serverResponses) && serverResponses.forEach((response) => {
if (response.body) {
if (utils.isArray(response.body)) {
if (isArray(response.body)) {
response.body.forEach(b => {
addSyncs(b);
})
Expand Down Expand Up @@ -82,26 +82,26 @@ export const spec = {
serverResponse = serverResponse.body;
let bids = [];

if (!utils.isArray(serverResponse)) {
if (!isArray(serverResponse)) {
return parseRTBResponse(serverResponse, adapterRequest);
}

serverResponse.forEach(serverBidResponse => {
bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest));
bids = flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest));
});

return bids;
},

transformBidParams(params) {
return utils.convertTypes({
return convertTypes({
'aid': 'number',
}, params);
}
};

function parseRTBResponse(serverResponse, adapterRequest) {
const isEmptyResponse = !serverResponse || !utils.isArray(serverResponse.bids);
const isEmptyResponse = !serverResponse || !isArray(serverResponse.bids);
const bids = [];

if (isEmptyResponse) {
Expand All @@ -126,26 +126,26 @@ function parseRTBResponse(serverResponse, adapterRequest) {
function bidToTag(bidRequests, adapterRequest) {
// start publisher env
const tag = {
Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer')
Domain: deepAccess(adapterRequest, 'refererInfo.referer')
};
if (config.getConfig('coppa') === true) {
tag.Coppa = 1;
}
if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) {
if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) {
tag.GDPR = 1;
tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString');
tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString');
}
if (utils.deepAccess(adapterRequest, 'uspConsent')) {
tag.USP = utils.deepAccess(adapterRequest, 'uspConsent');
if (deepAccess(adapterRequest, 'uspConsent')) {
tag.USP = deepAccess(adapterRequest, 'uspConsent');
}
if (utils.deepAccess(bidRequests[0], 'schain')) {
tag.Schain = utils.deepAccess(bidRequests[0], 'schain');
if (deepAccess(bidRequests[0], 'schain')) {
tag.Schain = deepAccess(bidRequests[0], 'schain');
}
if (utils.deepAccess(bidRequests[0], 'userId')) {
tag.UserIds = utils.deepAccess(bidRequests[0], 'userId');
if (deepAccess(bidRequests[0], 'userId')) {
tag.UserIds = deepAccess(bidRequests[0], 'userId');
}
if (utils.deepAccess(bidRequests[0], 'userIdAsEids')) {
tag.UserEids = utils.deepAccess(bidRequests[0], 'userIdAsEids');
if (deepAccess(bidRequests[0], 'userIdAsEids')) {
tag.UserEids = deepAccess(bidRequests[0], 'userIdAsEids');
}
// end publisher env
const bids = []
Expand All @@ -164,23 +164,23 @@ function bidToTag(bidRequests, adapterRequest) {
* @returns {object}
*/
function prepareBidRequests(bidReq) {
const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY;
const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes');
const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY;
const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes');
const bidReqParams = {
'CallbackId': bidReq.bidId,
'Aid': bidReq.params.aid,
'AdType': mediaType,
'Sizes': utils.parseSizesInput(sizes).join(',')
'Sizes': parseSizesInput(sizes).join(',')
};

bidReqParams.PlacementId = bidReq.adUnitCode;
if (bidReq.params.iframe) {
bidReqParams.AdmType = 'iframe';
}
if (mediaType === VIDEO) {
const context = utils.deepAccess(bidReq, 'mediaTypes.video.context');
const context = deepAccess(bidReq, 'mediaTypes.video.context');
if (context === ADPOD) {
bidReqParams.Adpod = utils.deepAccess(bidReq, 'mediaTypes.video');
bidReqParams.Adpod = deepAccess(bidReq, 'mediaTypes.video');
}
}
return bidReqParams;
Expand All @@ -192,7 +192,7 @@ function prepareBidRequests(bidReq) {
* @returns {object}
*/
function getMediaType(bidderRequest) {
return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER;
return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER;
}

/**
Expand All @@ -203,7 +203,7 @@ function getMediaType(bidderRequest) {
*/
function createBid(bidResponse, bidRequest) {
const mediaType = getMediaType(bidRequest)
const context = utils.deepAccess(bidRequest, 'mediaTypes.video.context');
const context = deepAccess(bidRequest, 'mediaTypes.video.context');
const bid = {
requestId: bidResponse.requestId,
creativeId: bidResponse.cmpId,
Expand Down
Loading

0 comments on commit df117c9

Please sign in to comment.