Skip to content

Commit

Permalink
import utils functions as needed and not the whole module
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-harshad-mane committed Sep 24, 2021
1 parent ef500ab commit 7e3fa3f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
44 changes: 22 additions & 22 deletions modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
const BIDDER_CODE = 'beop';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const spec = {
*/
buildRequests: function(validBidRequests, bidderRequest) {
const slots = validBidRequests.map(beOpRequestSlotsMaker);
let pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href');
let pageUrl = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href');
let fpd = config.getLegacyFpd(config.getConfig('ortb2'));
let gdpr = bidderRequest.gdprConsent;
let firstSlot = slots[0];
Expand All @@ -50,7 +50,7 @@ export const spec = {
kwds: (fpd && fpd.site && fpd.site.keywords) || [],
dbg: false,
slts: slots,
is_amp: utils.deepAccess(bidderRequest, 'referrerInfo.isAmp'),
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null,
};
const payloadString = JSON.stringify(payloadObject);
Expand All @@ -61,7 +61,7 @@ export const spec = {
}
},
interpretResponse: function(serverResponse, request) {
if (serverResponse && serverResponse.body && utils.isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) {
if (serverResponse && serverResponse.body && isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) {
return serverResponse.body.bids;
}
return [];
Expand All @@ -73,8 +73,8 @@ export const spec = {

let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout);

utils.logWarn(BIDDER_CODE + ': timed out request');
utils.triggerPixel(utils.buildUrl({
logWarn(BIDDER_CODE + ': timed out request');
triggerPixel(buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
Expand All @@ -87,8 +87,8 @@ export const spec = {
}
let trackingParams = buildTrackingParams(bid, 'won', bid.cpm);

utils.logInfo(BIDDER_CODE + ': won request');
utils.triggerPixel(utils.buildUrl({
logInfo(BIDDER_CODE + ': won request');
triggerPixel(buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
Expand All @@ -113,8 +113,8 @@ function buildTrackingParams(data, info, value) {
}

function beOpRequestSlotsMaker(bid) {
const bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes');
const publisherCurrency = config.getConfig('currency.adServerCurrency') || utils.getValue(bid.params, 'currency') || 'EUR';
const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes');
const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR';
let floor;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]});
Expand All @@ -123,19 +123,19 @@ function beOpRequestSlotsMaker(bid) {
}
}
return {
sizes: utils.isArray(bannerSizes) ? bannerSizes : bid.sizes,
sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes,
flr: floor,
pid: utils.getValue(bid.params, 'accountId'),
nid: utils.getValue(bid.params, 'networkId'),
nptnid: utils.getValue(bid.params, 'networkPartnerId'),
bid: utils.getBidIdParameter('bidId', bid),
brid: utils.getBidIdParameter('bidderRequestId', bid),
name: utils.getBidIdParameter('adUnitCode', bid),
aid: utils.getBidIdParameter('auctionId', bid),
tid: utils.getBidIdParameter('transactionId', bid),
brc: utils.getBidIdParameter('bidRequestsCount', bid),
bdrc: utils.getBidIdParameter('bidderRequestCount', bid),
bwc: utils.getBidIdParameter('bidderWinsCount', bid),
pid: getValue(bid.params, 'accountId'),
nid: getValue(bid.params, 'networkId'),
nptnid: getValue(bid.params, 'networkPartnerId'),
bid: getBidIdParameter('bidId', bid),
brid: getBidIdParameter('bidderRequestId', bid),
name: getBidIdParameter('adUnitCode', bid),
aid: getBidIdParameter('auctionId', bid),
tid: getBidIdParameter('transactionId', bid),
brc: getBidIdParameter('bidRequestsCount', bid),
bdrc: getBidIdParameter('bidderRequestCount', bid),
bwc: getBidIdParameter('bidderWinsCount', bid),
}
}

Expand Down
14 changes: 7 additions & 7 deletions modules/bidViewabilityIO.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logMessage } from '../src/utils.js';
import { config } from '../src/config.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.json';
import * as utils from '../src/utils.js';

const MODULE_NAME = 'bidViewabilityIO';
const CONFIG_ENABLED = 'enabled';
Expand All @@ -23,8 +23,8 @@ export let isSupportedMediaType = (bid) => {
return supportedMediaTypes.indexOf(bid.mediaType) > -1;
}

let logMessage = (message) => {
return utils.logMessage(`${MODULE_NAME}: ${message}`);
let _logMessage = (message) => {
return logMessage(`${MODULE_NAME}: ${message}`);
}

// returns options for the iO that detects if the ad is viewable
Expand All @@ -43,7 +43,7 @@ export let markViewed = (bid, entry, observer) => {
return () => {
observer.unobserve(entry.target);
events.emit(EVENTS.BID_VIEWABLE, bid);
logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`);
_logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`);
}
}

Expand All @@ -59,13 +59,13 @@ export let viewCallbackFactory = (bid) => {
return (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`);
_logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`);
entry.target.view_tracker = setTimeout(markViewed(bid, entry, observer), IAB_VIEWABLE_DISPLAY_TIME);
} else {
logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`);
_logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`);
if (entry.target.view_tracker) {
clearTimeout(entry.target.view_tracker);
logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`);
_logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`);
}
}
});
Expand Down
16 changes: 8 additions & 8 deletions modules/bidglassBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { _each, isArray, getBidIdParameter, deepClone, getUniqueIdentifierStr } from '../src/utils.js';
// import {config} from 'src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';

Expand Down Expand Up @@ -69,12 +69,12 @@ export const spec = {

let bidglass = window['bidglass'];

utils._each(validBidRequests, function(bid) {
bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]);
bid.sizes = bid.sizes.filter(size => utils.isArray(size));
_each(validBidRequests, function(bid) {
bid.sizes = ((isArray(bid.sizes) && isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]);
bid.sizes = bid.sizes.filter(size => isArray(size));

var adUnitId = utils.getBidIdParameter('adUnitId', bid.params);
var options = utils.deepClone(bid.params);
var adUnitId = getBidIdParameter('adUnitId', bid.params);
var options = deepClone(bid.params);

delete options.adUnitId;

Expand All @@ -96,7 +96,7 @@ export const spec = {

// Stuff to send: page URL
const bidReq = {
reqId: utils.getUniqueIdentifierStr(),
reqId: getUniqueIdentifierStr(),
imps: imps,
ref: getReferer(),
ori: getOrigins()
Expand Down Expand Up @@ -125,7 +125,7 @@ export const spec = {
interpretResponse: function(serverResponse) {
const bidResponses = [];

utils._each(serverResponse.body.bidResponses, function(serverBid) {
_each(serverResponse.body.bidResponses, function(serverBid) {
const bidResponse = {
requestId: serverBid.requestId,
cpm: parseFloat(serverBid.cpm),
Expand Down
6 changes: 3 additions & 3 deletions modules/bidscubeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logMessage, getWindowLocation } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'
import * as utils from '../src/utils.js'

const BIDDER_CODE = 'bidscube'
const URL = 'https://supply.bidscube.com/?c=o&m=multi'
Expand All @@ -20,9 +20,9 @@ export const spec = {
try {
window.top.location.toString()
winTop = window.top
} catch (e) { utils.logMessage(e) }
} catch (e) { logMessage(e) }

const location = utils.getWindowLocation()
const location = getWindowLocation()
const placements = []

for (let i = 0; i < validBidRequests.length; i++) {
Expand Down
20 changes: 10 additions & 10 deletions modules/bizzclickBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logMessage, getDNT, deepSetValue, deepAccess, _map, logWarn } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
const BIDDER_CODE = 'bizzclick';
const ACCOUNTID_MACROS = '[account_id]';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const spec = {
winTop = window.top;
} catch (e) {
location = winTop.location;
utils.logMessage(e);
logMessage(e);
};
let bids = [];
for (let bidRequest of validBidRequests) {
Expand All @@ -80,7 +80,7 @@ export const spec = {
device: {
w: winTop.screen.width,
h: winTop.screen.height,
dnt: utils.getDNT() ? 1 : 0,
dnt: getDNT() ? 1 : 0,
language: (navigator && navigator.language) ? navigator.language.indexOf('-') != -1 ? navigator.language.split('-')[0] : navigator.language : '',
},
site: {
Expand Down Expand Up @@ -124,12 +124,12 @@ export const spec = {
}
if (bidRequest) {
if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) {
utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0);
utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString);
deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0);
deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString);
}

if (bidRequest.uspConsent !== undefined) {
utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent);
deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent);
}
}
bids.push(data)
Expand Down Expand Up @@ -194,7 +194,7 @@ export const spec = {
* @returns {boolean}
*/
const checkRequestType = (bidRequest, type) => {
return (typeof utils.deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined');
return (typeof deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined');
}
const parseNative = admObject => {
const { assets, link, imptrackers, jstracker } = admObject.native;
Expand Down Expand Up @@ -240,7 +240,7 @@ const addNativeParameters = bidRequest => {
id: bidRequest.transactionId,
ver: NATIVE_VERSION,
};
const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => {
const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => {
const props = NATIVE_PARAMS[key];
const asset = {
required: bidParams.required & 1,
Expand Down Expand Up @@ -286,7 +286,7 @@ const parseSizes = (bid, mediaType) => {
mediaTypes.video.w,
mediaTypes.video.h
];
} else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) {
} else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) {
size = bid.mediaTypes.video.playerSize[0];
} else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) {
size = bid.sizes[0];
Expand All @@ -299,7 +299,7 @@ const parseSizes = (bid, mediaType) => {
} else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) {
sizes = bid.sizes
} else {
utils.logWarn('no sizes are setup or found');
logWarn('no sizes are setup or found');
}
return sizes
}
Expand Down

0 comments on commit 7e3fa3f

Please sign in to comment.