From 801a2ea204675b19c5b30ef98d421de485b7d2d6 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:23:52 -0700 Subject: [PATCH 01/23] remove bind --- modules/prebidServerBidAdapter/index.js | 8 +++----- src/adapterManager.js | 11 ++--------- src/auction.js | 3 +-- src/config.js | 19 ++++++++++++++----- src/prebid.js | 3 +-- src/utils.js | 11 ----------- 6 files changed, 21 insertions(+), 34 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index 3cae4497354..68fd7fad627 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -1,6 +1,6 @@ import Adapter from '../../src/adapter.js'; import { - bind, + deepAccess, deepClone, flatten, generateUUID, @@ -15,7 +15,6 @@ import { logWarn, triggerPixel, uniques, - deepAccess, } from '../../src/utils.js'; import CONSTANTS from '../../src/constants.json'; import adapterManager, {s2sActivityParams} from '../../src/adapterManager.js'; @@ -297,7 +296,7 @@ function doAllSyncs(bidders, s2sConfig) { // if PBS reports this bidder doesn't have an ID, then call the sync and recurse to the next sync entry if (thisSync.no_cookie) { - doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, bind.call(doAllSyncs, null, bidders, s2sConfig), s2sConfig); + doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, doAllSyncs.bind(null, bidders, s2sConfig), s2sConfig); } else { // bidder already has an ID, so just recurse to the next sync entry doAllSyncs(bidders, s2sConfig); @@ -356,8 +355,7 @@ function doClientSideSyncs(bidders, gdprConsent, uspConsent, gppConsent) { if (clientAdapter && clientAdapter.registerSyncs) { config.runWithBidder( bidder, - bind.call( - clientAdapter.registerSyncs, + clientAdapter.registerSyncs.bind( clientAdapter, [], gdprConsent, diff --git a/src/adapterManager.js b/src/adapterManager.js index 45c4d890944..9d0bba086a4 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -2,7 +2,6 @@ import { _each, - bind, deepAccess, deepClone, flatten, @@ -31,12 +30,7 @@ import {hook} from './hook.js'; import {find, includes} from './polyfill.js'; import {adunitCounter} from './adUnits.js'; import {getRefererInfo} from './refererDetection.js'; -import { - GDPR_GVLIDS, - gdprDataHandler, - uspDataHandler, - gppDataHandler, -} from './consentHandler.js'; +import {GDPR_GVLIDS, gdprDataHandler, gppDataHandler, uspDataHandler,} from './consentHandler.js'; import * as events from './events.js'; import CONSTANTS from './constants.json'; import {useMetrics} from './utils/perfMetrics.js'; @@ -465,8 +459,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request try { config.runWithBidder( bidRequest.bidderCode, - bind.call( - adapter.callBids, + adapter.callBids.bind( adapter, bidRequest, addBidResponse, diff --git a/src/auction.js b/src/auction.js index 48e1a8e3436..3336134bd83 100644 --- a/src/auction.js +++ b/src/auction.js @@ -60,7 +60,6 @@ import { _each, adUnitsFilter, - bind, deepAccess, flatten, generateUUID, @@ -216,7 +215,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a if (_callback != null) { const adUnitCodes = _adUnitCodes; const bids = _bidsReceived - .filter(bind.call(adUnitsFilter, this, adUnitCodes)) + .filter(adUnitsFilter.bind(this, adUnitCodes)) .reduce(groupByPlacement, {}); _callback.apply(pbjsInstance, [bids, timedOut, _auctionId]); _callback = null; diff --git a/src/config.js b/src/config.js index 48909d677e9..d4dc07989af 100644 --- a/src/config.js +++ b/src/config.js @@ -12,11 +12,20 @@ * @property {(string|Object)} [video-outstream] */ -import { isValidPriceConfig } from './cpmBucketManager.js'; -import {find, includes, arrayFrom as from} from './polyfill.js'; +import {isValidPriceConfig} from './cpmBucketManager.js'; +import {arrayFrom as from, find, includes} from './polyfill.js'; import { - mergeDeep, deepClone, getParameterByName, isPlainObject, logMessage, logWarn, logError, - isArray, isStr, isBoolean, deepAccess, bind + deepAccess, + deepClone, + getParameterByName, + isArray, + isBoolean, + isPlainObject, + isStr, + logError, + logMessage, + logWarn, + mergeDeep } from './utils.js'; import CONSTANTS from './constants.json'; @@ -505,7 +514,7 @@ export function newConfig() { return function(cb) { return function(...args) { if (typeof cb === 'function') { - return runWithBidder(bidder, bind.call(cb, this, ...args)) + return runWithBidder(bidder, cb.bind(this, ...args)) } else { logWarn('config.callbackWithBidder callback is not a function'); } diff --git a/src/prebid.js b/src/prebid.js index 94ade8e5f83..016ccbbd15e 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -3,7 +3,6 @@ import {getGlobal} from './prebidGlobal.js'; import { adUnitsFilter, - bind, callBurl, contains, createInvisibleIframe, @@ -338,7 +337,7 @@ pbjsInstance.getConsentMetadata = function () { function getBids(type) { const responses = auctionManager[type]() - .filter(bind.call(adUnitsFilter, this, auctionManager.getAdUnitCodes())); + .filter(adUnitsFilter.bind(this, auctionManager.getAdUnitCodes())) // find the last auction id to get responses for most recent auction only const currentAuctionId = auctionManager.getLastAuctionId(); diff --git a/src/utils.js b/src/utils.js index ece29732723..5f9c0d08af0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,17 +64,6 @@ export function getPrebidInternal() { return prebidInternal; } -var uniqueRef = {}; -export let bind = function(a, b) { return b; }.bind(null, 1, uniqueRef)() === uniqueRef - ? Function.prototype.bind - : function(bind) { - var self = this; - var args = Array.prototype.slice.call(arguments, 1); - return function() { - return self.apply(bind, args.concat(Array.prototype.slice.call(arguments))); - }; - }; - /* utility method to get incremental integer starting from 1 */ var getIncrementalInteger = (function () { var count = 0; From c70a7d97b62cdc70a27d8b704eecb107b5187668 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:31:51 -0700 Subject: [PATCH 02/23] bidderUtils/getBidIdParameter --- libraries/bidderUtils/bidderUtils.js | 7 +++++++ modules/adgenerationBidAdapter.js | 3 ++- modules/admaticBidAdapter.js | 3 ++- modules/adriverBidAdapter.js | 3 ++- modules/ajaBidAdapter.js | 3 ++- modules/audiencerunBidAdapter.js | 2 +- modules/beopBidAdapter.js | 2 +- modules/bidglassBidAdapter.js | 3 ++- modules/brightcomBidAdapter.js | 3 ++- modules/brightcomSSPBidAdapter.js | 2 +- modules/cadentApertureMXBidAdapter.js | 2 +- modules/conversantBidAdapter.js | 2 +- modules/cpmstarBidAdapter.js | 12 ++++++------ modules/datawrkzBidAdapter.js | 3 ++- modules/dspxBidAdapter.js | 3 ++- modules/ebdrBidAdapter.js | 3 ++- modules/eskimiBidAdapter.js | 9 +++++---- modules/getintentBidAdapter.js | 3 ++- modules/gmosspBidAdapter.js | 2 +- modules/growadvertisingBidAdapter.js | 3 ++- modules/holidBidAdapter.js | 2 +- modules/improvedigitalBidAdapter.js | 3 ++- modules/iqmBidAdapter.js | 3 ++- modules/ivsBidAdapter.js | 3 ++- modules/kueezBidAdapter.js | 3 ++- modules/lockerdomeBidAdapter.js | 2 +- modules/mediasniperBidAdapter.js | 2 +- modules/mgidBidAdapter.js | 2 +- modules/minutemediaBidAdapter.js | 3 ++- modules/nextMillenniumBidAdapter.js | 2 +- modules/nextrollBidAdapter.js | 2 +- modules/onomagicBidAdapter.js | 2 +- modules/open8BidAdapter.js | 3 ++- modules/orbitsoftBidAdapter.js | 13 +++++++------ modules/otmBidAdapter.js | 2 +- modules/relaidoBidAdapter.js | 3 ++- modules/riseBidAdapter.js | 3 ++- modules/shinezBidAdapter.js | 3 ++- modules/showheroes-bsBidAdapter.js | 2 +- modules/slimcutBidAdapter.js | 3 ++- modules/smartxBidAdapter.js | 3 ++- modules/sovrnBidAdapter.js | 2 +- modules/spotxBidAdapter.js | 3 ++- modules/teadsBidAdapter.js | 3 ++- modules/trionBidAdapter.js | 3 ++- modules/viantOrtbBidAdapter.js | 3 ++- modules/videonowBidAdapter.js | 3 ++- modules/videoreachBidAdapter.js | 3 ++- modules/waardexBidAdapter.js | 3 ++- modules/xeBidAdapter.js | 3 ++- src/utils.js | 8 -------- test/spec/libraries/bidderUtils_spec.js | 22 ++++++++++++++++++++++ test/spec/utils_spec.js | 20 +------------------- 53 files changed, 124 insertions(+), 89 deletions(-) create mode 100644 libraries/bidderUtils/bidderUtils.js create mode 100644 test/spec/libraries/bidderUtils_spec.js diff --git a/libraries/bidderUtils/bidderUtils.js b/libraries/bidderUtils/bidderUtils.js new file mode 100644 index 00000000000..551d8817e97 --- /dev/null +++ b/libraries/bidderUtils/bidderUtils.js @@ -0,0 +1,7 @@ +export function getBidIdParameter(key, paramsObj) { + if (paramsObj && paramsObj[key]) { + return paramsObj[key]; + } + + return ''; +} diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index bf75756174d..54da4194c96 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,8 +1,9 @@ -import {tryAppendQueryString, getBidIdParameter, escapeUnsafeChars, deepAccess} from '../src/utils.js'; +import {tryAppendQueryString, escapeUnsafeChars, deepAccess} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const ADG_BIDDER_CODE = 'adgeneration'; diff --git a/modules/admaticBidAdapter.js b/modules/admaticBidAdapter.js index 436f918a0f6..8568f1159f6 100644 --- a/modules/admaticBidAdapter.js +++ b/modules/admaticBidAdapter.js @@ -1,7 +1,8 @@ -import { getValue, logError, isEmpty, deepAccess, getBidIdParameter, isArray } from '../src/utils.js'; +import { getValue, logError, isEmpty, deepAccess, isArray } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; let SYNC_URL = ''; const BIDDER_CODE = 'admatic'; export const spec = { diff --git a/modules/adriverBidAdapter.js b/modules/adriverBidAdapter.js index 1af0cffa700..731ff0d1d32 100644 --- a/modules/adriverBidAdapter.js +++ b/modules/adriverBidAdapter.js @@ -1,7 +1,8 @@ // ADRIVER BID ADAPTER for Prebid 1.13 -import { logInfo, getWindowLocation, getBidIdParameter, _each } from '../src/utils.js'; +import { logInfo, getWindowLocation, _each } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'adriver'; const ADRIVER_BID_URL = 'https://pb.adriver.ru/cgi-bin/bid.cgi'; diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index ffab41611ef..1563ed19591 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -1,7 +1,8 @@ -import { getBidIdParameter, tryAppendQueryString, createTrackPixelHtml, logError, logWarn, deepAccess } from '../src/utils.js'; +import { tryAppendQueryString, createTrackPixelHtml, logError, logWarn, deepAccess } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BidderCode = 'aja'; const URL = 'https://ad.as.amanad.adtdp.com/v2/prebid'; diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index 9beb20d4f77..b85af63ff28 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -2,7 +2,6 @@ import { _each, deepAccess, formatQS, - getBidIdParameter, getValue, isArray, isFn, @@ -12,6 +11,7 @@ import { import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'audiencerun'; const BASE_URL = 'https://d.audiencerun.com'; diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index c5282c28cfc..c99554ddd5e 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,7 +1,6 @@ import { buildUrl, deepAccess, - getBidIdParameter, getValue, isArray, logInfo, @@ -12,6 +11,7 @@ import {getRefererInfo} from '../src/refererDetection.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'beop'; const ENDPOINT_URL = 'https://hb.beop.io/bid'; diff --git a/modules/bidglassBidAdapter.js b/modules/bidglassBidAdapter.js index 3184372881b..98acb01311a 100644 --- a/modules/bidglassBidAdapter.js +++ b/modules/bidglassBidAdapter.js @@ -1,6 +1,7 @@ -import { _each, isArray, getBidIdParameter, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; +import { _each, isArray, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; // import {config} from 'src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'bidglass'; diff --git a/modules/brightcomBidAdapter.js b/modules/brightcomBidAdapter.js index c4cc5394a03..5175eb20c39 100644 --- a/modules/brightcomBidAdapter.js +++ b/modules/brightcomBidAdapter.js @@ -1,7 +1,8 @@ -import { getBidIdParameter, _each, isArray, getWindowTop, getUniqueIdentifierStr, deepSetValue, logError, logWarn, createTrackPixelHtml, getWindowSelf, isFn, isPlainObject } from '../src/utils.js'; +import { _each, isArray, getWindowTop, getUniqueIdentifierStr, deepSetValue, logError, logWarn, createTrackPixelHtml, getWindowSelf, isFn, isPlainObject } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'brightcom'; const URL = 'https://brightcombid.marphezis.com/hb'; diff --git a/modules/brightcomSSPBidAdapter.js b/modules/brightcomSSPBidAdapter.js index b85a01c8fc7..76270fa5afb 100644 --- a/modules/brightcomSSPBidAdapter.js +++ b/modules/brightcomSSPBidAdapter.js @@ -1,5 +1,4 @@ import { - getBidIdParameter, isArray, getWindowTop, getUniqueIdentifierStr, @@ -15,6 +14,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {ajax} from '../src/ajax.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'bcmssp'; const URL = 'https://rt.marphezis.com/hb'; diff --git a/modules/cadentApertureMXBidAdapter.js b/modules/cadentApertureMXBidAdapter.js index 32c0a4e4643..187999da716 100644 --- a/modules/cadentApertureMXBidAdapter.js +++ b/modules/cadentApertureMXBidAdapter.js @@ -1,7 +1,6 @@ import { _each, deepAccess, - getBidIdParameter, isArray, isFn, isPlainObject, @@ -14,6 +13,7 @@ import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; import {find, includes} from '../src/polyfill.js'; import {parseDomain} from '../src/refererDetection.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'cadent_aperture_mx'; const ENDPOINT = 'hb.emxdgt.com'; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index fd436e51461..2388cf0e2b0 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -3,7 +3,6 @@ import { isStr, deepAccess, isArray, - getBidIdParameter, deepSetValue, isEmpty, _each, @@ -19,6 +18,7 @@ import { import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; // Maintainer: mediapsr@epsilon.com diff --git a/modules/cpmstarBidAdapter.js b/modules/cpmstarBidAdapter.js index 9e237ef2558..a7759b2b200 100755 --- a/modules/cpmstarBidAdapter.js +++ b/modules/cpmstarBidAdapter.js @@ -1,8 +1,8 @@ - import * as utils from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { VIDEO, BANNER } from '../src/mediaTypes.js'; -import { config } from '../src/config.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {config} from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'cpmstar'; @@ -49,13 +49,13 @@ export const spec = { var bidRequest = validBidRequests[i]; var referer = bidderRequest.refererInfo.page ? bidderRequest.refererInfo.page : bidderRequest.refererInfo.domain; referer = encodeURIComponent(referer); - var e = utils.getBidIdParameter('endpoint', bidRequest.params); + var e = getBidIdParameter('endpoint', bidRequest.params); var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION; var mediaType = spec.getMediaType(bidRequest); var playerSize = spec.getPlayerSize(bidRequest); var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : ''); var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') + - '&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) + + '&json=c_b&mv=1&poolid=' + getBidIdParameter('placementId', bidRequest.params) + '&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) + '&requestid=' + bidRequest.bidId + '&referer=' + encodeURIComponent(referer); diff --git a/modules/datawrkzBidAdapter.js b/modules/datawrkzBidAdapter.js index 2cf28c36330..f5967d6c90d 100644 --- a/modules/datawrkzBidAdapter.js +++ b/modules/datawrkzBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, getBidIdParameter, isArray, getUniqueIdentifierStr, contains, isFn, isPlainObject } from '../src/utils.js'; +import { deepAccess, isArray, getUniqueIdentifierStr, contains, isFn, isPlainObject } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -6,6 +6,7 @@ import { createBid } from '../src/bidfactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import CONSTANTS from '../src/constants.json'; import { OUTSTREAM, INSTREAM } from '../src/video.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'datawrkz'; const ALIASES = []; diff --git a/modules/dspxBidAdapter.js b/modules/dspxBidAdapter.js index b8e812f581a..de17e4b1bd7 100644 --- a/modules/dspxBidAdapter.js +++ b/modules/dspxBidAdapter.js @@ -1,8 +1,9 @@ -import {deepAccess, getBidIdParameter, isFn, logError, logMessage, logWarn} from '../src/utils.js'; +import {deepAccess, isFn, logError, logMessage, logWarn} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; import {includes} from '../src/polyfill.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'dspx'; const ENDPOINT_URL = 'https://buyer.dspx.tv/request/'; diff --git a/modules/ebdrBidAdapter.js b/modules/ebdrBidAdapter.js index a03a1ec12ca..0f51214b326 100644 --- a/modules/ebdrBidAdapter.js +++ b/modules/ebdrBidAdapter.js @@ -1,6 +1,7 @@ -import { logInfo, getBidIdParameter } from '../src/utils.js'; +import { logInfo} from '../src/utils.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'ebdr'; export const spec = { code: BIDDER_CODE, diff --git a/modules/eskimiBidAdapter.js b/modules/eskimiBidAdapter.js index 88d8f95b859..d1c6bd63e88 100644 --- a/modules/eskimiBidAdapter.js +++ b/modules/eskimiBidAdapter.js @@ -1,7 +1,8 @@ -import { ortbConverter } from '../libraries/ortbConverter/converter.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; +import {ortbConverter} from '../libraries/ortbConverter/converter.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; import * as utils from '../src/utils.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'eskimi'; // const ENDPOINT = 'https://hb.eskimi.com/bids' @@ -65,7 +66,7 @@ const CONVERTER = ortbConverter({ imp.secure = Number(window.location.protocol === 'https:'); if (!imp.bidfloor && bidRequest.params.bidFloor) { imp.bidfloor = bidRequest.params.bidFloor; - imp.bidfloorcur = utils.getBidIdParameter('bidFloorCur', bidRequest.params).toUpperCase() || 'USD' + imp.bidfloorcur = getBidIdParameter('bidFloorCur', bidRequest.params).toUpperCase() || 'USD' } if (bidRequest.mediaTypes[VIDEO]) { diff --git a/modules/getintentBidAdapter.js b/modules/getintentBidAdapter.js index 25322d81f9b..aa4d0dcb55c 100644 --- a/modules/getintentBidAdapter.js +++ b/modules/getintentBidAdapter.js @@ -1,5 +1,6 @@ -import { getBidIdParameter, isFn, isInteger } from '../src/utils.js'; +import { isFn, isInteger } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'getintent'; const IS_NET_REVENUE = true; diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index 8c90d0cccfe..8b054a31822 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -2,7 +2,6 @@ import { createTrackPixelHtml, deepAccess, deepSetValue, - getBidIdParameter, getDNT, getWindowTop, isEmpty, @@ -12,6 +11,7 @@ import { import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER} from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'gmossp'; const ENDPOINT = 'https://sp.gmossp-sp.jp/hb/prebid/query.ad'; diff --git a/modules/growadvertisingBidAdapter.js b/modules/growadvertisingBidAdapter.js index b9b256dbaff..1deef8c0c48 100644 --- a/modules/growadvertisingBidAdapter.js +++ b/modules/growadvertisingBidAdapter.js @@ -1,9 +1,10 @@ 'use strict'; -import { getBidIdParameter, deepAccess, _each, triggerPixel } from '../src/utils.js'; +import { deepAccess, _each, triggerPixel } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'growads'; diff --git a/modules/holidBidAdapter.js b/modules/holidBidAdapter.js index 2073063168d..30cce6fdfc9 100644 --- a/modules/holidBidAdapter.js +++ b/modules/holidBidAdapter.js @@ -1,7 +1,6 @@ import { deepAccess, deepSetValue, - getBidIdParameter, isStr, logMessage, triggerPixel, @@ -11,6 +10,7 @@ import CONSTANTS from '../src/constants.json'; import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'holid' const GVLID = 1177 diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index b56cc56a186..6149302bd50 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -1,4 +1,4 @@ -import {deepAccess, deepSetValue, getBidIdParameter, getUniqueIdentifierStr, logWarn, mergeDeep} from '../src/utils.js'; +import {deepAccess, deepSetValue, getUniqueIdentifierStr, logWarn, mergeDeep} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; @@ -6,6 +6,7 @@ import {Renderer} from '../src/Renderer.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js'; import {loadExternalScript} from '../src/adloader.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'improvedigital'; const CREATIVE_TTL = 300; diff --git a/modules/iqmBidAdapter.js b/modules/iqmBidAdapter.js index c3808afd225..8de9d379d10 100644 --- a/modules/iqmBidAdapter.js +++ b/modules/iqmBidAdapter.js @@ -1,7 +1,8 @@ -import {_each, deepAccess, getBidIdParameter, isArray} from '../src/utils.js'; +import {_each, deepAccess, isArray} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {INSTREAM} from '../src/video.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'iqm'; const VERSION = 'v.1.0.0'; diff --git a/modules/ivsBidAdapter.js b/modules/ivsBidAdapter.js index 47685fbbe46..3cb199354c2 100644 --- a/modules/ivsBidAdapter.js +++ b/modules/ivsBidAdapter.js @@ -1,8 +1,9 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js'; -import { deepAccess, deepSetValue, getBidIdParameter, logError } from '../src/utils.js'; +import { deepAccess, deepSetValue, logError } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO } from '../src/mediaTypes.js'; import { INSTREAM } from '../src/video.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'ivs'; const ENDPOINT_URL = 'https://a.ivstracker.net/prod/openrtb/2.5'; diff --git a/modules/kueezBidAdapter.js b/modules/kueezBidAdapter.js index 0a868661310..1e3d41f606f 100644 --- a/modules/kueezBidAdapter.js +++ b/modules/kueezBidAdapter.js @@ -1,7 +1,8 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, getBidIdParameter, triggerPixel, isInteger } from '../src/utils.js'; +import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_ENDPOINT = 'https://hb.kueezssp.com/hb-kz-multi'; const BIDDER_TEST_ENDPOINT = 'https://hb.kueezssp.com/hb-multi-kz-test' diff --git a/modules/lockerdomeBidAdapter.js b/modules/lockerdomeBidAdapter.js index 5c38753c1e2..2522e5f86bc 100644 --- a/modules/lockerdomeBidAdapter.js +++ b/modules/lockerdomeBidAdapter.js @@ -1,6 +1,6 @@ -import { getBidIdParameter } from '../src/utils.js'; import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; export const spec = { code: 'lockerdome', diff --git a/modules/mediasniperBidAdapter.js b/modules/mediasniperBidAdapter.js index 378a804487a..22f8487c484 100644 --- a/modules/mediasniperBidAdapter.js +++ b/modules/mediasniperBidAdapter.js @@ -2,7 +2,6 @@ import { deepAccess, deepClone, deepSetValue, - getBidIdParameter, inIframe, isArray, isEmpty, @@ -17,6 +16,7 @@ import { import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'mediasniper'; const DEFAULT_BID_TTL = 360; diff --git a/modules/mgidBidAdapter.js b/modules/mgidBidAdapter.js index 8e889261e52..d63cb316702 100644 --- a/modules/mgidBidAdapter.js +++ b/modules/mgidBidAdapter.js @@ -9,7 +9,6 @@ import { isEmpty, triggerPixel, logWarn, - getBidIdParameter, isFn, isNumber, isBoolean, @@ -21,6 +20,7 @@ import {config} from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {USERSYNC_DEFAULT_CONFIG} from '../src/userSync.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const GVLID = 358; const DEFAULT_CUR = 'USD'; diff --git a/modules/minutemediaBidAdapter.js b/modules/minutemediaBidAdapter.js index bb0bb76bdbc..338b1a28cf8 100644 --- a/modules/minutemediaBidAdapter.js +++ b/modules/minutemediaBidAdapter.js @@ -1,7 +1,8 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, getBidIdParameter, triggerPixel, isInteger } from '../src/utils.js'; +import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'minutemedia'; diff --git a/modules/nextMillenniumBidAdapter.js b/modules/nextMillenniumBidAdapter.js index cb660ad9fd6..ed788cca6ff 100644 --- a/modules/nextMillenniumBidAdapter.js +++ b/modules/nextMillenniumBidAdapter.js @@ -2,7 +2,6 @@ import { _each, createTrackPixelHtml, deepAccess, - getBidIdParameter, getDefinedParams, getWindowTop, isArray, @@ -20,6 +19,7 @@ import * as events from '../src/events.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getRefererInfo} from '../src/refererDetection.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'nextMillennium'; const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction'; diff --git a/modules/nextrollBidAdapter.js b/modules/nextrollBidAdapter.js index 0dd4b334f6e..5f5158f922b 100644 --- a/modules/nextrollBidAdapter.js +++ b/modules/nextrollBidAdapter.js @@ -1,6 +1,5 @@ import { deepAccess, - getBidIdParameter, isArray, isFn, isNumber, @@ -14,6 +13,7 @@ import {BANNER, NATIVE} from '../src/mediaTypes.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {find} from '../src/polyfill.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'nextroll'; const BIDDER_ENDPOINT = 'https://d.adroll.com/bid/prebid/'; diff --git a/modules/onomagicBidAdapter.js b/modules/onomagicBidAdapter.js index edab625e541..60a425da102 100644 --- a/modules/onomagicBidAdapter.js +++ b/modules/onomagicBidAdapter.js @@ -1,7 +1,6 @@ import { _each, createTrackPixelHtml, - getBidIdParameter, getUniqueIdentifierStr, getWindowSelf, getWindowTop, @@ -13,6 +12,7 @@ import { } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'onomagic'; const URL = 'https://bidder.onomagic.com/hb'; diff --git a/modules/open8BidAdapter.js b/modules/open8BidAdapter.js index 5fa1dd0a143..927ed88e3db 100644 --- a/modules/open8BidAdapter.js +++ b/modules/open8BidAdapter.js @@ -1,8 +1,9 @@ import { Renderer } from '../src/Renderer.js'; import {ajax} from '../src/ajax.js'; -import { createTrackPixelHtml, getBidIdParameter, logError, logWarn, tryAppendQueryString } from '../src/utils.js'; +import { createTrackPixelHtml, logError, logWarn, tryAppendQueryString } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'open8'; const URL = 'https://as.vt.open8.com/v1/control/prebid'; diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 4c3f2e38c58..6d0b89e48c1 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,5 +1,6 @@ import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'orbitsoft'; let styleParamsMap = { @@ -45,10 +46,10 @@ export const spec = { for (let i = 0; i < validBidRequests.length; i++) { bidRequest = validBidRequests[i]; let bidRequestParams = bidRequest.params; - let placementId = utils.getBidIdParameter('placementId', bidRequestParams); - let requestUrl = utils.getBidIdParameter('requestUrl', bidRequestParams); - let referrer = utils.getBidIdParameter('ref', bidRequestParams); - let location = utils.getBidIdParameter('loc', bidRequestParams); + let placementId = getBidIdParameter('placementId', bidRequestParams); + let requestUrl = getBidIdParameter('requestUrl', bidRequestParams); + let referrer = getBidIdParameter('ref', bidRequestParams); + let location = getBidIdParameter('loc', bidRequestParams); // Append location & referrer if (location === '') { location = utils.getWindowLocation(); @@ -58,7 +59,7 @@ export const spec = { } // Styles params - let stylesParams = utils.getBidIdParameter('style', bidRequestParams); + let stylesParams = getBidIdParameter('style', bidRequestParams); let stylesParamsArray = {}; for (let currentValue in stylesParams) { if (stylesParams.hasOwnProperty(currentValue)) { @@ -74,7 +75,7 @@ export const spec = { } } // Custom params - let customParams = utils.getBidIdParameter('customParams', bidRequestParams); + let customParams = getBidIdParameter('customParams', bidRequestParams); let customParamsArray = {}; for (let customField in customParams) { if (customParams.hasOwnProperty(customField)) { diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js index 6125cee6593..e2fa4667a31 100644 --- a/modules/otmBidAdapter.js +++ b/modules/otmBidAdapter.js @@ -2,7 +2,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { logInfo, logError, - getBidIdParameter, _each, getValue, isFn, @@ -12,6 +11,7 @@ import { isNumber, } from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'otm'; const OTM_BID_URL = 'https://ssp.otm-r.com/adjson'; diff --git a/modules/relaidoBidAdapter.js b/modules/relaidoBidAdapter.js index b2961b09eb5..f149211da66 100644 --- a/modules/relaidoBidAdapter.js +++ b/modules/relaidoBidAdapter.js @@ -1,9 +1,10 @@ -import { deepAccess, logWarn, getBidIdParameter, parseQueryStringParameters, triggerPixel, generateUUID, isArray, isNumber, parseSizesInput } from '../src/utils.js'; +import { deepAccess, logWarn, parseQueryStringParameters, triggerPixel, generateUUID, isArray, isNumber, parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { Renderer } from '../src/Renderer.js'; import { getStorageManager } from '../src/storageManager.js'; import sha1 from 'crypto-js/sha1'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'relaido'; const BIDDER_DOMAIN = 'api.relaido.jp'; diff --git a/modules/riseBidAdapter.js b/modules/riseBidAdapter.js index d5c6469db12..be2d141c9c7 100644 --- a/modules/riseBidAdapter.js +++ b/modules/riseBidAdapter.js @@ -1,7 +1,8 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, getBidIdParameter, triggerPixel, isInteger } from '../src/utils.js'; +import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'rise'; diff --git a/modules/shinezBidAdapter.js b/modules/shinezBidAdapter.js index 96b6d281fdc..2d2a37eb283 100644 --- a/modules/shinezBidAdapter.js +++ b/modules/shinezBidAdapter.js @@ -1,7 +1,8 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, getBidIdParameter, triggerPixel, isInteger } from '../src/utils.js'; +import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'shinez'; diff --git a/modules/showheroes-bsBidAdapter.js b/modules/showheroes-bsBidAdapter.js index a241cb71a5d..e183b6e7894 100644 --- a/modules/showheroes-bsBidAdapter.js +++ b/modules/showheroes-bsBidAdapter.js @@ -1,6 +1,5 @@ import { deepAccess, - getBidIdParameter, getWindowTop, triggerPixel, logInfo, @@ -11,6 +10,7 @@ import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { loadExternalScript } from '../src/adloader.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const PROD_ENDPOINT = 'https://bs.showheroes.com/api/v1/bid'; const STAGE_ENDPOINT = 'https://bid-service.stage.showheroes.com/api/v1/bid'; diff --git a/modules/slimcutBidAdapter.js b/modules/slimcutBidAdapter.js index 447e314958f..1c8018c1c5c 100644 --- a/modules/slimcutBidAdapter.js +++ b/modules/slimcutBidAdapter.js @@ -1,10 +1,11 @@ -import { getValue, parseSizesInput, getBidIdParameter } from '../src/utils.js'; +import { getValue, parseSizesInput} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ajax } from '../src/ajax.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'slimcut'; const ENDPOINT_URL = 'https://sb.freeskreen.com/pbr'; export const spec = { diff --git a/modules/smartxBidAdapter.js b/modules/smartxBidAdapter.js index d91b62729bc..c66e6b028be 100644 --- a/modules/smartxBidAdapter.js +++ b/modules/smartxBidAdapter.js @@ -1,4 +1,4 @@ -import { logError, deepAccess, isArray, getBidIdParameter, getDNT, generateUUID, isEmpty, _each, logMessage, logWarn, isFn, isPlainObject } from '../src/utils.js'; +import { logError, deepAccess, isArray, getDNT, generateUUID, isEmpty, _each, logMessage, logWarn, isFn, isPlainObject } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; @@ -8,6 +8,7 @@ import { import { VIDEO } from '../src/mediaTypes.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'smartx'; const URL = 'https://bid.sxp.smartclip.net/bid/1000'; const GVLID = 115; diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 0d077ad2ae3..01ecbfda266 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,6 +1,5 @@ import { _each, - getBidIdParameter, isArray, getUniqueIdentifierStr, deepSetValue, @@ -15,6 +14,7 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js' +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const ORTB_VIDEO_PARAMS = { 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), diff --git a/modules/spotxBidAdapter.js b/modules/spotxBidAdapter.js index 874207adcf8..e189e99e7cf 100644 --- a/modules/spotxBidAdapter.js +++ b/modules/spotxBidAdapter.js @@ -1,9 +1,10 @@ -import { logError, deepAccess, isArray, getBidIdParameter, getDNT, deepSetValue, isEmpty, _each, logMessage, logWarn, isBoolean, isNumber, isPlainObject, isFn, setScriptAttributes } from '../src/utils.js'; +import { logError, deepAccess, isArray, getDNT, deepSetValue, isEmpty, _each, logMessage, logWarn, isBoolean, isNumber, isPlainObject, isFn, setScriptAttributes } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO } from '../src/mediaTypes.js'; import { loadExternalScript } from '../src/adloader.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'spotx'; const URL = 'https://search.spotxchange.com/openrtb/2.3/dados/'; diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 570ee51df9c..325602e0fec 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -1,6 +1,7 @@ -import { getValue, logError, deepAccess, getBidIdParameter, parseSizesInput, isArray } from '../src/utils.js'; +import { getValue, logError, deepAccess, parseSizesInput, isArray } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'teads'; const GVL_ID = 132; diff --git a/modules/trionBidAdapter.js b/modules/trionBidAdapter.js index b6375243a5a..b6211418ca5 100644 --- a/modules/trionBidAdapter.js +++ b/modules/trionBidAdapter.js @@ -1,6 +1,7 @@ -import { getBidIdParameter, parseSizesInput, tryAppendQueryString } from '../src/utils.js'; +import { parseSizesInput, tryAppendQueryString } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BID_REQUEST_BASE_URL = 'https://in-appadvertising.com/api/bidRequest'; const USER_SYNC_URL = 'https://in-appadvertising.com/api/userSync.html'; diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index e7bf9129a62..f6159dd0c43 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -2,7 +2,8 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import * as utils from '../src/utils.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js' -import {deepAccess, getBidIdParameter, logError} from '../src/utils.js'; +import {deepAccess, logError} from '../src/utils.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'viant'; const ENDPOINT = 'https://bidders-us-east-1.adelphic.net/d/rtb/v25/prebid/bidder_test' diff --git a/modules/videonowBidAdapter.js b/modules/videonowBidAdapter.js index bfbc07fdff1..75a520bbac8 100644 --- a/modules/videonowBidAdapter.js +++ b/modules/videonowBidAdapter.js @@ -1,6 +1,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import {_each, getBidIdParameter, getValue, logError, logInfo} from '../src/utils.js'; +import {_each, getValue, logError, logInfo} from '../src/utils.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'videonow'; const RTB_URL = 'https://adx.videonow.ru/yhb' diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js index 9fd5853c75e..d3debf61b87 100644 --- a/modules/videoreachBidAdapter.js +++ b/modules/videoreachBidAdapter.js @@ -1,5 +1,6 @@ -import { getValue, getBidIdParameter } from '../src/utils.js'; +import { getValue} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'videoreach'; const ENDPOINT_URL = 'https://a.videoreach.com/hb/'; const GVLID = 547; diff --git a/modules/waardexBidAdapter.js b/modules/waardexBidAdapter.js index 92b7fc26e4c..a61e123be21 100644 --- a/modules/waardexBidAdapter.js +++ b/modules/waardexBidAdapter.js @@ -1,8 +1,9 @@ -import {deepAccess, getBidIdParameter, isArray, logError} from '../src/utils.js'; +import {deepAccess, isArray, logError} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {find} from '../src/polyfill.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const ENDPOINT = `https://hb.justbidit.xyz:8843/prebid`; const BIDDER_CODE = 'waardex'; diff --git a/modules/xeBidAdapter.js b/modules/xeBidAdapter.js index 94a66e9980e..266aa9d4689 100644 --- a/modules/xeBidAdapter.js +++ b/modules/xeBidAdapter.js @@ -1,7 +1,8 @@ import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { getAdUnitSizes, parseSizesInput, isFn, deepAccess, getBidIdParameter, logError, isArray } from '../src/utils.js'; +import { getAdUnitSizes, parseSizesInput, isFn, deepAccess, logError, isArray } from '../src/utils.js'; +import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const CUR = 'USD'; const BIDDER_CODE = 'xe'; diff --git a/src/utils.js b/src/utils.js index 5f9c0d08af0..87a2612df4a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -102,14 +102,6 @@ function _getRandomData() { } } -export function getBidIdParameter(key, paramsObj) { - if (paramsObj && paramsObj[key]) { - return paramsObj[key]; - } - - return ''; -} - export function tryAppendQueryString(existingUrl, key, value) { if (value) { return existingUrl + key + '=' + encodeURIComponent(value) + '&'; diff --git a/test/spec/libraries/bidderUtils_spec.js b/test/spec/libraries/bidderUtils_spec.js new file mode 100644 index 00000000000..0de91adcf77 --- /dev/null +++ b/test/spec/libraries/bidderUtils_spec.js @@ -0,0 +1,22 @@ +import {getBidIdParameter} from '../../../libraries/bidderUtils/bidderUtils.js'; +import assert from 'assert'; + +describe('getBidIdParameter', function () { + it('should return value of the key in input object', function () { + var obj = { + a: 'valueA', + b: 'valueB' + }; + var output = getBidIdParameter('a', obj); + assert.equal(output, 'valueA'); + }); + + it('should return empty string, if the key is not existsed in the object', function () { + var obj = { + a: 'valueA', + b: 'valueB' + }; + var output = getBidIdParameter('c', obj); + assert.equal(output, ''); + }); +}); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index e26683074c8..b9cf79328ba 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -3,6 +3,7 @@ import {expect} from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; import {deepEqual, memoize, waitForElementToLoad} from 'src/utils.js'; +import {getBidIdParameter} from '../../libraries/bidderUtils/bidderUtils.js'; var assert = require('assert'); @@ -19,25 +20,6 @@ describe('Utils', function () { type_array = 'Array', type_function = 'Function'; - describe('getBidIdParameter', function () { - it('should return value of the key in input object', function () { - var obj = { - a: 'valueA', - b: 'valueB' - }; - var output = utils.getBidIdParameter('a', obj); - assert.equal(output, 'valueA'); - }); - - it('should return empty string, if the key is not existsed in the object', function () { - var obj = { - a: 'valueA', - b: 'valueB' - }; - var output = utils.getBidIdParameter('c', obj); - assert.equal(output, ''); - }); - }); describe('tryAppendQueryString', function () { it('should append query string to existing url', function () { From 055618b881c6c38b6e0d1e6011395110be21d2c2 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:39:05 -0700 Subject: [PATCH 03/23] urlUtils/tryAppendQuerySTring --- libraries/urlUtils/urlUtils.js | 7 +++++++ modules/adWMGBidAdapter.js | 2 +- modules/adgenerationBidAdapter.js | 3 ++- modules/ajaBidAdapter.js | 3 ++- modules/asoBidAdapter.js | 4 ++-- modules/connectadBidAdapter.js | 3 ++- modules/docereeBidAdapter.js | 2 +- modules/gmosspBidAdapter.js | 4 ++-- modules/growthCodeIdSystem.js | 3 ++- modules/growthCodeRtdProvider.js | 3 ++- modules/open8BidAdapter.js | 3 ++- modules/sharethroughAnalyticsAdapter.js | 2 +- modules/trionBidAdapter.js | 3 ++- modules/tripleliftBidAdapter.js | 3 ++- modules/weboramaRtdProvider.js | 4 ++-- src/utils.js | 8 -------- test/spec/libraries/urlUtils_spec.js | 24 ++++++++++++++++++++++++ test/spec/utils_spec.js | 25 +------------------------ 18 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 libraries/urlUtils/urlUtils.js create mode 100644 test/spec/libraries/urlUtils_spec.js diff --git a/libraries/urlUtils/urlUtils.js b/libraries/urlUtils/urlUtils.js new file mode 100644 index 00000000000..f0c5823aab1 --- /dev/null +++ b/libraries/urlUtils/urlUtils.js @@ -0,0 +1,7 @@ +export function tryAppendQueryString(existingUrl, key, value) { + if (value) { + return existingUrl + key + '=' + encodeURIComponent(value) + '&'; + } + + return existingUrl; +} diff --git a/modules/adWMGBidAdapter.js b/modules/adWMGBidAdapter.js index 36935e80d3b..d268c4cafa8 100644 --- a/modules/adWMGBidAdapter.js +++ b/modules/adWMGBidAdapter.js @@ -1,9 +1,9 @@ 'use strict'; -import { tryAppendQueryString } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'adWMG'; const ENDPOINT = 'https://hb.adwmg.com/hb'; diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index 54da4194c96..db7e1000013 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,9 +1,10 @@ -import {tryAppendQueryString, escapeUnsafeChars, deepAccess} from '../src/utils.js'; +import {escapeUnsafeChars, deepAccess} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const ADG_BIDDER_CODE = 'adgeneration'; diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index 1563ed19591..447c69b5827 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -1,8 +1,9 @@ -import { tryAppendQueryString, createTrackPixelHtml, logError, logWarn, deepAccess } from '../src/utils.js'; +import { createTrackPixelHtml, logError, logWarn, deepAccess } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BidderCode = 'aja'; const URL = 'https://ad.as.amanad.adtdp.com/v2/prebid'; diff --git a/modules/asoBidAdapter.js b/modules/asoBidAdapter.js index e569f04a2a8..704cffefb39 100644 --- a/modules/asoBidAdapter.js +++ b/modules/asoBidAdapter.js @@ -7,14 +7,14 @@ import { isArray, isFn, logWarn, - parseSizesInput, - tryAppendQueryString + parseSizesInput } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { Renderer } from '../src/Renderer.js'; import { parseDomain } from '../src/refererDetection.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'aso'; const DEFAULT_SERVER_URL = 'https://srv.aso1.net'; diff --git a/modules/connectadBidAdapter.js b/modules/connectadBidAdapter.js index d5665b318be..f7d70a7ed69 100644 --- a/modules/connectadBidAdapter.js +++ b/modules/connectadBidAdapter.js @@ -1,7 +1,8 @@ -import { deepSetValue, convertTypes, tryAppendQueryString, logWarn } from '../src/utils.js'; +import { deepSetValue, convertTypes, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js' import {config} from '../src/config.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'connectad'; const BIDDER_CODE_ALIAS = 'connectadrealtime'; const ENDPOINT_URL = 'https://i.connectad.io/api/v2'; diff --git a/modules/docereeBidAdapter.js b/modules/docereeBidAdapter.js index 524f464cee3..fa4446ede47 100644 --- a/modules/docereeBidAdapter.js +++ b/modules/docereeBidAdapter.js @@ -1,7 +1,7 @@ -import { tryAppendQueryString } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'doceree'; const END_POINT = 'https://bidder.doceree.com' diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index 8b054a31822..55a1e074cd0 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -5,13 +5,13 @@ import { getDNT, getWindowTop, isEmpty, - logError, - tryAppendQueryString + logError } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER} from '../src/mediaTypes.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'gmossp'; const ENDPOINT = 'https://sp.gmossp-sp.jp/hb/prebid/query.ad'; diff --git a/modules/growthCodeIdSystem.js b/modules/growthCodeIdSystem.js index aec49c64fa3..e50a4e73019 100644 --- a/modules/growthCodeIdSystem.js +++ b/modules/growthCodeIdSystem.js @@ -5,11 +5,12 @@ * @requires module:modules/userId */ -import {logError, logInfo, pick, tryAppendQueryString} from '../src/utils.js'; +import {logError, logInfo, pick} from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import { submodule } from '../src/hook.js' import {getStorageManager} from '../src/storageManager.js'; import {MODULE_TYPE_UID} from '../src/activities/modules.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const MODULE_NAME = 'growthCodeId'; const GC_DATA_KEY = '_gc_data'; diff --git a/modules/growthCodeRtdProvider.js b/modules/growthCodeRtdProvider.js index 370ace9a203..ef5c7906ad7 100644 --- a/modules/growthCodeRtdProvider.js +++ b/modules/growthCodeRtdProvider.js @@ -5,10 +5,11 @@ import { submodule } from '../src/hook.js' import { getStorageManager } from '../src/storageManager.js'; import { - logMessage, logError, tryAppendQueryString, mergeDeep + logMessage, logError, mergeDeep } from '../src/utils.js'; import * as ajax from '../src/ajax.js'; import { MODULE_TYPE_RTD } from '../src/activities/modules.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const MODULE_NAME = 'growthCodeRtd'; const LOG_PREFIX = 'GrowthCodeRtd: '; diff --git a/modules/open8BidAdapter.js b/modules/open8BidAdapter.js index 927ed88e3db..eca2c6c4bfa 100644 --- a/modules/open8BidAdapter.js +++ b/modules/open8BidAdapter.js @@ -1,9 +1,10 @@ import { Renderer } from '../src/Renderer.js'; import {ajax} from '../src/ajax.js'; -import { createTrackPixelHtml, logError, logWarn, tryAppendQueryString } from '../src/utils.js'; +import { createTrackPixelHtml, logError, logWarn} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'open8'; const URL = 'https://as.vt.open8.com/v1/control/prebid'; diff --git a/modules/sharethroughAnalyticsAdapter.js b/modules/sharethroughAnalyticsAdapter.js index 6502c7e3a53..dc621e8da92 100644 --- a/modules/sharethroughAnalyticsAdapter.js +++ b/modules/sharethroughAnalyticsAdapter.js @@ -1,6 +1,6 @@ -import { tryAppendQueryString } from '../src/utils.js'; import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const emptyUrl = ''; const analyticsType = 'endpoint'; diff --git a/modules/trionBidAdapter.js b/modules/trionBidAdapter.js index b6211418ca5..c10e8058d6c 100644 --- a/modules/trionBidAdapter.js +++ b/modules/trionBidAdapter.js @@ -1,7 +1,8 @@ -import { parseSizesInput, tryAppendQueryString } from '../src/utils.js'; +import { parseSizesInput} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BID_REQUEST_BASE_URL = 'https://in-appadvertising.com/api/bidRequest'; const USER_SYNC_URL = 'https://in-appadvertising.com/api/userSync.html'; diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 22936ba750a..bfbf1409c1b 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -1,8 +1,9 @@ -import { tryAppendQueryString, logMessage, logError, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; +import { logMessage, logError, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const GVLID = 28; const BIDDER_CODE = 'triplelift'; diff --git a/modules/weboramaRtdProvider.js b/modules/weboramaRtdProvider.js index 6ba502d2c8b..14abba95323 100644 --- a/modules/weboramaRtdProvider.js +++ b/modules/weboramaRtdProvider.js @@ -109,8 +109,7 @@ import { isBoolean, isPlainObject, logWarn, - mergeDeep, - tryAppendQueryString + mergeDeep } from '../src/utils.js'; import { submodule @@ -123,6 +122,7 @@ import { } from '../src/storageManager.js'; import adapterManager from '../src/adapterManager.js'; import {MODULE_TYPE_RTD} from '../src/activities/modules.js'; +import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; /** @type {string} */ const MODULE_NAME = 'realTimeData'; diff --git a/src/utils.js b/src/utils.js index 87a2612df4a..7adce8b3425 100644 --- a/src/utils.js +++ b/src/utils.js @@ -102,14 +102,6 @@ function _getRandomData() { } } -export function tryAppendQueryString(existingUrl, key, value) { - if (value) { - return existingUrl + key + '=' + encodeURIComponent(value) + '&'; - } - - return existingUrl; -} - // parse a query string object passed in bid params // bid params should be an object such as {key: "value", key1 : "value1"} // aliases to formatQS diff --git a/test/spec/libraries/urlUtils_spec.js b/test/spec/libraries/urlUtils_spec.js new file mode 100644 index 00000000000..9dd66b05407 --- /dev/null +++ b/test/spec/libraries/urlUtils_spec.js @@ -0,0 +1,24 @@ +import {tryAppendQueryString} from '../../../libraries/urlUtils/urlUtils.js'; +import assert from 'assert'; + +describe('tryAppendQueryString', function () { + it('should append query string to existing url', function () { + var url = 'www.a.com?'; + var key = 'b'; + var value = 'c'; + + var output = tryAppendQueryString(url, key, value); + + var expectedResult = url + key + '=' + encodeURIComponent(value) + '&'; + assert.equal(output, expectedResult); + }); + + it('should return existing url, if the value is empty', function () { + var url = 'www.a.com?'; + var key = 'b'; + var value = ''; + + var output = tryAppendQueryString(url, key, value); + assert.equal(output, url); + }); +}); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index b9cf79328ba..2f56e44e9af 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -3,7 +3,7 @@ import {expect} from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; import {deepEqual, memoize, waitForElementToLoad} from 'src/utils.js'; -import {getBidIdParameter} from '../../libraries/bidderUtils/bidderUtils.js'; +import {tryAppendQueryString} from '../../libraries/urlUtils/urlUtils.js'; var assert = require('assert'); @@ -20,29 +20,6 @@ describe('Utils', function () { type_array = 'Array', type_function = 'Function'; - - describe('tryAppendQueryString', function () { - it('should append query string to existing url', function () { - var url = 'www.a.com?'; - var key = 'b'; - var value = 'c'; - - var output = utils.tryAppendQueryString(url, key, value); - - var expectedResult = url + key + '=' + encodeURIComponent(value) + '&'; - assert.equal(output, expectedResult); - }); - - it('should return existing url, if the value is empty', function () { - var url = 'www.a.com?'; - var key = 'b'; - var value = ''; - - var output = utils.tryAppendQueryString(url, key, value); - assert.equal(output, url); - }); - }); - describe('parseQueryStringParameters', function () { it('should append query string to existing using the input obj', function () { var obj = { From 0f300dae93c8d8d8bc5b3f39491df9b1c6ba3ea3 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:43:10 -0700 Subject: [PATCH 04/23] sizeUtils/getAdUnitSizes --- libraries/sizeUtils/sizeUtils.js | 29 ++++++++++++++++++++++++++ modules/adkernelBidAdapter.js | 2 +- modules/aduptechBidAdapter.js | 3 ++- modules/betweenBidAdapter.js | 3 ++- modules/datablocksBidAdapter.js | 3 ++- modules/iasRtdProvider.js | 9 ++++---- modules/imdsBidAdapter.js | 3 ++- modules/oguryBidAdapter.js | 3 ++- modules/optidigitalBidAdapter.js | 3 ++- modules/rasBidAdapter.js | 3 ++- modules/revcontentBidAdapter.js | 3 ++- modules/smaatoBidAdapter.js | 2 +- modules/vdoaiBidAdapter.js | 2 +- modules/xeBidAdapter.js | 3 ++- src/utils.js | 30 --------------------------- test/spec/libraries/sizeUtils_spec.js | 30 +++++++++++++++++++++++++++ test/spec/utils_spec.js | 30 +-------------------------- 17 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 libraries/sizeUtils/sizeUtils.js create mode 100644 test/spec/libraries/sizeUtils_spec.js diff --git a/libraries/sizeUtils/sizeUtils.js b/libraries/sizeUtils/sizeUtils.js new file mode 100644 index 00000000000..41cdd71df89 --- /dev/null +++ b/libraries/sizeUtils/sizeUtils.js @@ -0,0 +1,29 @@ +/** + * Read an adUnit object and return the sizes used in an [[728, 90]] format (even if they had [728, 90] defined) + * Preference is given to the `adUnit.mediaTypes.banner.sizes` object over the `adUnit.sizes` + * @param {object} adUnit one adUnit object from the normal list of adUnits + * @returns {Array.} array of arrays containing numeric sizes + */ +export function getAdUnitSizes(adUnit) { + if (!adUnit) { + return; + } + + let sizes = []; + if (adUnit.mediaTypes && adUnit.mediaTypes.banner && Array.isArray(adUnit.mediaTypes.banner.sizes)) { + let bannerSizes = adUnit.mediaTypes.banner.sizes; + if (Array.isArray(bannerSizes[0])) { + sizes = bannerSizes; + } else { + sizes.push(bannerSizes); + } + // TODO - remove this else block when we're ready to deprecate adUnit.sizes for bidders + } else if (Array.isArray(adUnit.sizes)) { + if (Array.isArray(adUnit.sizes[0])) { + sizes = adUnit.sizes; + } else { + sizes.push(adUnit.sizes); + } + } + return sizes; +} diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js index ac0984fec68..d7f5622d5d0 100644 --- a/modules/adkernelBidAdapter.js +++ b/modules/adkernelBidAdapter.js @@ -5,7 +5,6 @@ import { createTrackPixelHtml, deepAccess, deepSetValue, - getAdUnitSizes, getDefinedParams, getDNT, isArray, @@ -22,6 +21,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {find} from '../src/polyfill.js'; import {config} from '../src/config.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; /* * In case you're AdKernel whitelable platform's client who needs branded adapter to diff --git a/modules/aduptechBidAdapter.js b/modules/aduptechBidAdapter.js index 1ea5f1a0096..49187da2fe2 100644 --- a/modules/aduptechBidAdapter.js +++ b/modules/aduptechBidAdapter.js @@ -1,7 +1,8 @@ -import {deepClone, getAdUnitSizes, isArray, isBoolean, isEmpty, isFn, isPlainObject} from '../src/utils.js'; +import {deepClone, isArray, isBoolean, isEmpty, isFn, isPlainObject} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; export const BIDDER_CODE = 'aduptech'; export const GVLID = 647; diff --git a/modules/betweenBidAdapter.js b/modules/betweenBidAdapter.js index d615e433cc0..6883b7cce2c 100644 --- a/modules/betweenBidAdapter.js +++ b/modules/betweenBidAdapter.js @@ -1,6 +1,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getAdUnitSizes, parseSizesInput} from '../src/utils.js'; +import {parseSizesInput} from '../src/utils.js'; import {includes} from '../src/polyfill.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'between'; let ENDPOINT = 'https://ads.betweendigital.com/adjson?t=prebid'; diff --git a/modules/datablocksBidAdapter.js b/modules/datablocksBidAdapter.js index 11d3ebb1589..395706994fe 100644 --- a/modules/datablocksBidAdapter.js +++ b/modules/datablocksBidAdapter.js @@ -1,10 +1,11 @@ -import {deepAccess, getAdUnitSizes, getWindowTop, isEmpty, isGptPubadsDefined} from '../src/utils.js'; +import {deepAccess, getWindowTop, isEmpty, isGptPubadsDefined} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; import {ajax} from '../src/ajax.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; export const storage = getStorageManager({bidderCode: 'datablocks'}); diff --git a/modules/iasRtdProvider.js b/modules/iasRtdProvider.js index 994be7c0804..d50684b8765 100644 --- a/modules/iasRtdProvider.js +++ b/modules/iasRtdProvider.js @@ -1,7 +1,8 @@ -import { submodule } from '../src/hook.js'; +import {submodule} from '../src/hook.js'; import * as utils from '../src/utils.js'; -import { ajax } from '../src/ajax.js'; -import { getGlobal } from '../src/prebidGlobal.js'; +import {ajax} from '../src/ajax.js'; +import {getGlobal} from '../src/prebidGlobal.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; /** @type {string} */ const MODULE_NAME = 'realTimeData'; @@ -86,7 +87,7 @@ function getAdUnitPath(adSlot, bidRequest, adUnitPath) { } function stringifySlot(bidRequest, adUnitPath) { - const sizes = utils.getAdUnitSizes(bidRequest); + const sizes = getAdUnitSizes(bidRequest); const id = bidRequest.code; const ss = stringifySlotSizes(sizes); const adSlot = utils.getGptSlotInfoForAdUnitCode(bidRequest.code); diff --git a/modules/imdsBidAdapter.js b/modules/imdsBidAdapter.js index d6f3df94409..122662feb8a 100644 --- a/modules/imdsBidAdapter.js +++ b/modules/imdsBidAdapter.js @@ -1,10 +1,11 @@ 'use strict'; -import {deepAccess, deepSetValue, getAdUnitSizes, isFn, isPlainObject, logWarn, mergeDeep} from '../src/utils.js'; +import {deepAccess, deepSetValue, isFn, isPlainObject, logWarn, mergeDeep} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {includes} from '../src/polyfill.js'; import {config} from '../src/config.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BID_SCHEME = 'https://'; const BID_DOMAIN = 'technoratimedia.com'; diff --git a/modules/oguryBidAdapter.js b/modules/oguryBidAdapter.js index 4fd9b711b42..c1c8376de87 100644 --- a/modules/oguryBidAdapter.js +++ b/modules/oguryBidAdapter.js @@ -1,9 +1,10 @@ 'use strict'; import {BANNER} from '../src/mediaTypes.js'; -import {getAdUnitSizes, getWindowSelf, getWindowTop, isFn, logWarn} from '../src/utils.js'; +import {getWindowSelf, getWindowTop, isFn, logWarn} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {ajax} from '../src/ajax.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'ogury'; const GVLID = 31; diff --git a/modules/optidigitalBidAdapter.js b/modules/optidigitalBidAdapter.js index 9f84ff034ea..1c53ea88ec8 100755 --- a/modules/optidigitalBidAdapter.js +++ b/modules/optidigitalBidAdapter.js @@ -1,6 +1,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; -import { deepAccess, parseSizesInput, getAdUnitSizes } from '../src/utils.js'; +import { deepAccess, parseSizesInput} from '../src/utils.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'optidigital'; const GVL_ID = 915; diff --git a/modules/rasBidAdapter.js b/modules/rasBidAdapter.js index a7aceb107b9..801457aa552 100644 --- a/modules/rasBidAdapter.js +++ b/modules/rasBidAdapter.js @@ -1,7 +1,8 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; -import { isEmpty, getAdUnitSizes, parseSizesInput, deepAccess } from '../src/utils.js'; +import { isEmpty, parseSizesInput, deepAccess } from '../src/utils.js'; import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'ras'; const VERSION = '1.0'; diff --git a/modules/revcontentBidAdapter.js b/modules/revcontentBidAdapter.js index 5bf7dd691e7..f1d5521f780 100644 --- a/modules/revcontentBidAdapter.js +++ b/modules/revcontentBidAdapter.js @@ -3,9 +3,10 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; -import {_map, deepAccess, getAdUnitSizes, isFn, parseGPTSingleSizeArrayToRtbSize, triggerPixel} from '../src/utils.js'; +import {_map, deepAccess, isFn, parseGPTSingleSizeArrayToRtbSize, triggerPixel} from '../src/utils.js'; import {parseDomain} from '../src/refererDetection.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'revcontent'; const NATIVE_PARAMS = { diff --git a/modules/smaatoBidAdapter.js b/modules/smaatoBidAdapter.js index 1b50e033074..f275c1192cf 100644 --- a/modules/smaatoBidAdapter.js +++ b/modules/smaatoBidAdapter.js @@ -3,7 +3,6 @@ import { deepAccess, deepSetValue, fill, - getAdUnitSizes, getDNT, getMaxValueFromArray, getMinValueFromArray, @@ -17,6 +16,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {ADPOD, BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import CONSTANTS from '../src/constants.json'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const { NATIVE_IMAGE_TYPES } = CONSTANTS; const BIDDER_CODE = 'smaato'; diff --git a/modules/vdoaiBidAdapter.js b/modules/vdoaiBidAdapter.js index fa1e2898a4a..05960378d23 100644 --- a/modules/vdoaiBidAdapter.js +++ b/modules/vdoaiBidAdapter.js @@ -1,6 +1,6 @@ -import {getAdUnitSizes} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'vdoai'; const ENDPOINT_URL = 'https://prebid.vdo.ai/auction'; diff --git a/modules/xeBidAdapter.js b/modules/xeBidAdapter.js index 266aa9d4689..aef0bd5b6d2 100644 --- a/modules/xeBidAdapter.js +++ b/modules/xeBidAdapter.js @@ -1,8 +1,9 @@ import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { getAdUnitSizes, parseSizesInput, isFn, deepAccess, logError, isArray } from '../src/utils.js'; +import { parseSizesInput, isFn, deepAccess, logError, isArray } from '../src/utils.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const CUR = 'USD'; const BIDDER_CODE = 'xe'; diff --git a/src/utils.js b/src/utils.js index 7adce8b3425..dab29167e91 100644 --- a/src/utils.js +++ b/src/utils.js @@ -125,36 +125,6 @@ export function transformAdServerTargetingObj(targeting) { } } -/** - * Read an adUnit object and return the sizes used in an [[728, 90]] format (even if they had [728, 90] defined) - * Preference is given to the `adUnit.mediaTypes.banner.sizes` object over the `adUnit.sizes` - * @param {object} adUnit one adUnit object from the normal list of adUnits - * @returns {Array.} array of arrays containing numeric sizes - */ -export function getAdUnitSizes(adUnit) { - if (!adUnit) { - return; - } - - let sizes = []; - if (adUnit.mediaTypes && adUnit.mediaTypes.banner && Array.isArray(adUnit.mediaTypes.banner.sizes)) { - let bannerSizes = adUnit.mediaTypes.banner.sizes; - if (Array.isArray(bannerSizes[0])) { - sizes = bannerSizes; - } else { - sizes.push(bannerSizes); - } - // TODO - remove this else block when we're ready to deprecate adUnit.sizes for bidders - } else if (Array.isArray(adUnit.sizes)) { - if (Array.isArray(adUnit.sizes[0])) { - sizes = adUnit.sizes; - } else { - sizes.push(adUnit.sizes); - } - } - return sizes; -} - /** * Parse a GPT-Style general size Array like `[[300, 250]]` or `"300x250,970x90"` into an array of sizes `["300x250"]` or '['300x250', '970x90']' * @param {(Array.|Array.)} sizeObj Input array or double array [300,250] or [[300,250], [728,90]] diff --git a/test/spec/libraries/sizeUtils_spec.js b/test/spec/libraries/sizeUtils_spec.js new file mode 100644 index 00000000000..1c954c6accf --- /dev/null +++ b/test/spec/libraries/sizeUtils_spec.js @@ -0,0 +1,30 @@ +import {getAdUnitSizes} from '../../../libraries/sizeUtils/sizeUtils.js'; +import {expect} from 'chai/index.js'; + +describe('getAdUnitSizes', function () { + it('returns an empty response when adUnits is undefined', function () { + let sizes = getAdUnitSizes(); + expect(sizes).to.be.undefined; + }); + + it('returns an empty array when invalid data is present in adUnit object', function () { + let sizes = getAdUnitSizes({sizes: 300}); + expect(sizes).to.deep.equal([]); + }); + + it('retuns an array of arrays when reading from adUnit.sizes', function () { + let sizes = getAdUnitSizes({sizes: [300, 250]}); + expect(sizes).to.deep.equal([[300, 250]]); + + sizes = getAdUnitSizes({sizes: [[300, 250], [300, 600]]}); + expect(sizes).to.deep.equal([[300, 250], [300, 600]]); + }); + + it('returns an array of arrays when reading from adUnit.mediaTypes.banner.sizes', function () { + let sizes = getAdUnitSizes({mediaTypes: {banner: {sizes: [300, 250]}}}); + expect(sizes).to.deep.equal([[300, 250]]); + + sizes = getAdUnitSizes({mediaTypes: {banner: {sizes: [[300, 250], [300, 600]]}}}); + expect(sizes).to.deep.equal([[300, 250], [300, 600]]); + }); +}); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 2f56e44e9af..176096c75ea 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -3,7 +3,7 @@ import {expect} from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; import {deepEqual, memoize, waitForElementToLoad} from 'src/utils.js'; -import {tryAppendQueryString} from '../../libraries/urlUtils/urlUtils.js'; +import {getAdUnitSizes} from '../../libraries/sizeUtils/sizeUtils.js'; var assert = require('assert'); @@ -733,34 +733,6 @@ describe('Utils', function () { }); }); - describe('getAdUnitSizes', function () { - it('returns an empty response when adUnits is undefined', function () { - let sizes = utils.getAdUnitSizes(); - expect(sizes).to.be.undefined; - }); - - it('returns an empty array when invalid data is present in adUnit object', function () { - let sizes = utils.getAdUnitSizes({ sizes: 300 }); - expect(sizes).to.deep.equal([]); - }); - - it('retuns an array of arrays when reading from adUnit.sizes', function () { - let sizes = utils.getAdUnitSizes({ sizes: [300, 250] }); - expect(sizes).to.deep.equal([[300, 250]]); - - sizes = utils.getAdUnitSizes({ sizes: [[300, 250], [300, 600]] }); - expect(sizes).to.deep.equal([[300, 250], [300, 600]]); - }); - - it('returns an array of arrays when reading from adUnit.mediaTypes.banner.sizes', function () { - let sizes = utils.getAdUnitSizes({ mediaTypes: { banner: { sizes: [300, 250] } } }); - expect(sizes).to.deep.equal([[300, 250]]); - - sizes = utils.getAdUnitSizes({ mediaTypes: { banner: { sizes: [[300, 250], [300, 600]] } } }); - expect(sizes).to.deep.equal([[300, 250], [300, 600]]); - }); - }); - describe('URL helpers', function () { describe('parseUrl()', function () { let parsed; From 360c699ec38181d53e1aeb27b1917d5109a184ab Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:50:59 -0700 Subject: [PATCH 05/23] getWindowFromDocument --- modules/appnexusBidAdapter.js | 3 +-- modules/displayioBidAdapter.js | 4 ++-- src/utils.js | 9 --------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index ae4b1a0d489..e059bac44cb 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -11,7 +11,6 @@ import { getMinValueFromArray, getParameterByName, getUniqueIdentifierStr, - getWindowFromDocument, isArray, isArrayOfNums, isEmpty, @@ -1142,7 +1141,7 @@ function outstreamRender(bid, doc) { hideSASIframe(bid.adUnitCode); // push to render queue because ANOutstreamVideo may not be loaded yet bid.renderer.push(() => { - const win = getWindowFromDocument(doc) || window; + const win = doc?.defaultView || window; win.ANOutstreamVideo.renderAd({ tagId: bid.adResponse.tag_id, sizes: [bid.getSize().split('x')], diff --git a/modules/displayioBidAdapter.js b/modules/displayioBidAdapter.js index 3d34f2c8b26..3cdfd3a77cd 100644 --- a/modules/displayioBidAdapter.js +++ b/modules/displayioBidAdapter.js @@ -1,7 +1,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; -import {getWindowFromDocument, logWarn} from '../src/utils.js'; +import {logWarn} from '../src/utils.js'; import {getStorageManager} from '../src/storageManager.js'; import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js'; @@ -156,7 +156,7 @@ function newRenderer(bid) { function webisRender(bid, doc) { bid.renderer.push(() => { - const win = getWindowFromDocument(doc) || window; + const win = doc?.defaultView || window; win.webis.init(bid.adData, bid.adUnitCode, bid.params); }) } diff --git a/src/utils.js b/src/utils.js index dab29167e91..69d9fbf349c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1271,15 +1271,6 @@ export function cyrb53Hash(str, seed = 0) { return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(); } -/** - * returns a window object, which holds the provided document or null - * @param {Document} doc - * @returns {Window} - */ -export function getWindowFromDocument(doc) { - return (doc) ? doc.defaultView : null; -} - /** * returns the result of `JSON.parse(data)`, or undefined if that throws an error. * @param data From d5d1bee013deed60518535a81e1754834ff51e77 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:52:19 -0700 Subject: [PATCH 06/23] htmlEscape/escapeUnsafeChars --- libraries/htmlEscape/htmlEscape.js | 26 ++++++++++++++++++++++++++ modules/adgenerationBidAdapter.js | 3 ++- src/utils.js | 27 --------------------------- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 libraries/htmlEscape/htmlEscape.js diff --git a/libraries/htmlEscape/htmlEscape.js b/libraries/htmlEscape/htmlEscape.js new file mode 100644 index 00000000000..f0952c02e3c --- /dev/null +++ b/libraries/htmlEscape/htmlEscape.js @@ -0,0 +1,26 @@ +/** + * Encode a string for inclusion in HTML. + * See https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss.html and + * https://codeql.github.com/codeql-query-help/javascript/js-bad-code-sanitization/ + * @return {string} + */ +export const escapeUnsafeChars = (() => { + const escapes = { + '<': '\\u003C', + '>': '\\u003E', + '/': '\\u002F', + '\\': '\\\\', + '\b': '\\b', + '\f': '\\f', + '\n': '\\n', + '\r': '\\r', + '\t': '\\t', + '\0': '\\0', + '\u2028': '\\u2028', + '\u2029': '\\u2029' + }; + + return function (str) { + return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, x => escapes[x]); + }; +})(); diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index db7e1000013..15a71286b59 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,10 +1,11 @@ -import {escapeUnsafeChars, deepAccess} from '../src/utils.js'; +import {deepAccess} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; +import {escapeUnsafeChars} from '../libraries/htmlEscape/htmlEscape.js'; const ADG_BIDDER_CODE = 'adgeneration'; diff --git a/src/utils.js b/src/utils.js index 69d9fbf349c..b1fb1d6d9b8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1315,30 +1315,3 @@ export function setScriptAttributes(script, attributes) { } } } - -/** - * Encode a string for inclusion in HTML. - * See https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss.html and - * https://codeql.github.com/codeql-query-help/javascript/js-bad-code-sanitization/ - * @return {string} - */ -export const escapeUnsafeChars = (() => { - const escapes = { - '<': '\\u003C', - '>': '\\u003E', - '/': '\\u002F', - '\\': '\\\\', - '\b': '\\b', - '\f': '\\f', - '\n': '\\n', - '\r': '\\r', - '\t': '\\t', - '\0': '\\0', - '\u2028': '\\u2028', - '\u2029': '\\u2029' - }; - - return function(str) { - return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, x => escapes[x]) - } -})(); From 137f4cdac2d4c47e4636f6904a6a7f62a06a39bf Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 05:57:44 -0700 Subject: [PATCH 07/23] compareOn to adpod --- modules/adpod.js | 18 +++++++++++++++++- src/utils.js | 17 ----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/adpod.js b/modules/adpod.js index 4ab8e4e5ab9..4d9d1137ac1 100644 --- a/modules/adpod.js +++ b/modules/adpod.js @@ -13,7 +13,6 @@ */ import { - compareOn, deepAccess, generateUUID, groupBy, @@ -595,6 +594,23 @@ function getAdPodAdUnits(codes) { .filter((adUnit) => (codes.length > 0) ? codes.indexOf(adUnit.code) != -1 : true); } +/** + * This function will create compare function to sort on object property + * @param {string} property + * @returns {function} compare function to be used in sorting + */ +function compareOn(property) { + return function compare(a, b) { + if (a[property] < b[property]) { + return 1; + } + if (a[property] > b[property]) { + return -1; + } + return 0; + } +} + /** * This function removes bids of same category. It will be used when competitive exclusion is enabled. * @param {Array[Object]} bidsReceived diff --git a/src/utils.js b/src/utils.js index b1fb1d6d9b8..c7fe6779479 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1092,23 +1092,6 @@ export function getMaxValueFromArray(array) { return Math.max(...array); } -/** - * This function will create compare function to sort on object property - * @param {string} property - * @returns {function} compare function to be used in sorting - */ -export function compareOn(property) { - return function compare(a, b) { - if (a[property] < b[property]) { - return 1; - } - if (a[property] > b[property]) { - return -1; - } - return 0; - } -} - export function parseQS(query) { return !query ? {} : query .replace(/^\?/, '') From 6f0b22c60bfda596afb287f3116edef1e70213d8 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 06:27:16 -0700 Subject: [PATCH 08/23] remove Math.min/max copies --- modules/appnexusBidAdapter.js | 6 ++---- modules/goldbachBidAdapter.js | 10 ++++------ modules/mediafuseBidAdapter.js | 6 ++---- modules/smaatoBidAdapter.js | 18 +++--------------- src/utils.js | 8 -------- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index e059bac44cb..97e86530283 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -7,8 +7,6 @@ import { deepClone, fill, getBidRequest, - getMaxValueFromArray, - getMinValueFromArray, getParameterByName, getUniqueIdentifierStr, isArray, @@ -1030,7 +1028,7 @@ function createAdPodRequest(tags, adPodBid) { const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = Math.max(...durationRangeSec); const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); let request = fill(...tagToDuplicate, numberOfPlacements); @@ -1056,7 +1054,7 @@ function createAdPodRequest(tags, adPodBid) { function getAdPodPlacementNumber(videoParams) { const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = getMinValueFromArray(durationRangeSec); + const minAllowedDuration = Math.min(...durationRangeSec); const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); return requireExactDuration diff --git a/modules/goldbachBidAdapter.js b/modules/goldbachBidAdapter.js index 4768931950c..76a1b9fc0fe 100644 --- a/modules/goldbachBidAdapter.js +++ b/modules/goldbachBidAdapter.js @@ -8,8 +8,6 @@ import { deepClone, fill, getBidRequest, - getMaxValueFromArray, - getMinValueFromArray, getParameterByName, isArray, isArrayOfNums, @@ -29,8 +27,8 @@ import {auctionManager} from '../src/auctionManager.js'; import {find, includes} from '../src/polyfill.js'; import {INSTREAM, OUTSTREAM} from '../src/video.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; -import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; -import { APPNEXUS_CATEGORY_MAPPING } from '../libraries/categoryTranslationMapping/index.js'; +import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; +import {APPNEXUS_CATEGORY_MAPPING} from '../libraries/categoryTranslationMapping/index.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusKeywords/anKeywords.js'; const BIDDER_CODE = 'goldbach'; @@ -971,7 +969,7 @@ function createAdPodRequest(tags, adPodBid) { const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = Math.max(...durationRangeSec); const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); let request = fill(...tagToDuplicate, numberOfPlacements); @@ -997,7 +995,7 @@ function createAdPodRequest(tags, adPodBid) { function getAdPodPlacementNumber(videoParams) { const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = getMinValueFromArray(durationRangeSec); + const minAllowedDuration = Math.min(...durationRangeSec); const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); return requireExactDuration diff --git a/modules/mediafuseBidAdapter.js b/modules/mediafuseBidAdapter.js index 98179c49e0d..84a36472ec0 100644 --- a/modules/mediafuseBidAdapter.js +++ b/modules/mediafuseBidAdapter.js @@ -7,8 +7,6 @@ import { deepClone, fill, getBidRequest, - getMaxValueFromArray, - getMinValueFromArray, getParameterByName, isArray, isArrayOfNums, @@ -959,7 +957,7 @@ function createAdPodRequest(tags, adPodBid) { const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = Math.max(...durationRangeSec); const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); let request = fill(...tagToDuplicate, numberOfPlacements); @@ -985,7 +983,7 @@ function createAdPodRequest(tags, adPodBid) { function getAdPodPlacementNumber(videoParams) { const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = getMinValueFromArray(durationRangeSec); + const minAllowedDuration = Math.min(...durationRangeSec); const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); return requireExactDuration diff --git a/modules/smaatoBidAdapter.js b/modules/smaatoBidAdapter.js index f275c1192cf..0cefcbd80b4 100644 --- a/modules/smaatoBidAdapter.js +++ b/modules/smaatoBidAdapter.js @@ -1,16 +1,4 @@ -import { - chunk, - deepAccess, - deepSetValue, - fill, - getDNT, - getMaxValueFromArray, - getMinValueFromArray, - isEmpty, - isNumber, - logError, - logInfo -} from '../src/utils.js'; +import {chunk, deepAccess, deepSetValue, fill, getDNT, isEmpty, isNumber, logError, logInfo} from '../src/utils.js'; import {find} from '../src/polyfill.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; @@ -466,7 +454,7 @@ function createAdPodImp(bidRequest, videoMediaType) { }); } else { // all maxdurations should be the same - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = Math.max(...durationRangeSec); imps.map((imp, index) => { const sequence = index + 1; imp.video.maxduration = maxDuration @@ -481,7 +469,7 @@ function createAdPodImp(bidRequest, videoMediaType) { function getAdPodNumberOfPlacements(videoMediaType) { const {adPodDurationSec, durationRangeSec, requireExactDuration} = videoMediaType - const minAllowedDuration = getMinValueFromArray(durationRangeSec) + const minAllowedDuration = Math.min(...durationRangeSec) const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration) return requireExactDuration diff --git a/src/utils.js b/src/utils.js index c7fe6779479..6b8e654d66e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1084,14 +1084,6 @@ export function chunk(array, size) { return newArray; } -export function getMinValueFromArray(array) { - return Math.min(...array); -} - -export function getMaxValueFromArray(array) { - return Math.max(...array); -} - export function parseQS(query) { return !query ? {} : query .replace(/^\?/, '') From a86c505ac870239ca717d504df79b7f7144714a4 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 06:36:27 -0700 Subject: [PATCH 09/23] undo getBidIdParameter --- libraries/bidderUtils/bidderUtils.js | 7 ------ modules/adgenerationBidAdapter.js | 3 +-- modules/admaticBidAdapter.js | 3 +-- modules/adriverBidAdapter.js | 3 +-- modules/ajaBidAdapter.js | 3 +-- modules/audiencerunBidAdapter.js | 17 +++++++------- modules/beopBidAdapter.js | 15 ++++++------ modules/bidglassBidAdapter.js | 3 +-- modules/brightcomBidAdapter.js | 16 +++++++++++-- modules/brightcomSSPBidAdapter.js | 21 ++++++++--------- modules/cadentApertureMXBidAdapter.js | 17 +++++++------- modules/conversantBidAdapter.js | 31 ++++++++++++------------- modules/cpmstarBidAdapter.js | 2 +- modules/datawrkzBidAdapter.js | 11 +++++++-- modules/dspxBidAdapter.js | 3 +-- modules/ebdrBidAdapter.js | 3 +-- modules/eskimiBidAdapter.js | 2 +- modules/getintentBidAdapter.js | 3 +-- modules/gmosspBidAdapter.js | 15 ++++++------ modules/growadvertisingBidAdapter.js | 3 +-- modules/holidBidAdapter.js | 11 ++++----- modules/improvedigitalBidAdapter.js | 3 +-- modules/iqmBidAdapter.js | 3 +-- modules/ivsBidAdapter.js | 3 +-- modules/kueezBidAdapter.js | 15 ++++++++++-- modules/lockerdomeBidAdapter.js | 2 +- modules/mediasniperBidAdapter.js | 27 +++++++++++---------- modules/mgidBidAdapter.js | 29 +++++++++++------------ modules/minutemediaBidAdapter.js | 15 ++++++++++-- modules/nextMillenniumBidAdapter.js | 23 +++++++++--------- modules/nextrollBidAdapter.js | 17 +++++++------- modules/onomagicBidAdapter.js | 21 ++++++++--------- modules/open8BidAdapter.js | 3 +-- modules/orbitsoftBidAdapter.js | 2 +- modules/otmBidAdapter.js | 19 +++++++-------- modules/relaidoBidAdapter.js | 13 +++++++++-- modules/riseBidAdapter.js | 15 ++++++++++-- modules/shinezBidAdapter.js | 15 ++++++++++-- modules/showheroes-bsBidAdapter.js | 11 ++++----- modules/slimcutBidAdapter.js | 3 +-- modules/smartxBidAdapter.js | 16 +++++++++++-- modules/sovrnBidAdapter.js | 17 +++++++------- modules/spotxBidAdapter.js | 19 +++++++++++++-- modules/teadsBidAdapter.js | 3 +-- modules/trionBidAdapter.js | 3 +-- modules/viantOrtbBidAdapter.js | 3 +-- modules/videonowBidAdapter.js | 3 +-- modules/videoreachBidAdapter.js | 3 +-- modules/waardexBidAdapter.js | 3 +-- modules/xeBidAdapter.js | 3 +-- src/utils.js | 4 ++++ test/spec/libraries/bidderUtils_spec.js | 22 ------------------ test/spec/utils_spec.js | 21 ++++++++++++++++- 53 files changed, 304 insertions(+), 247 deletions(-) delete mode 100644 libraries/bidderUtils/bidderUtils.js delete mode 100644 test/spec/libraries/bidderUtils_spec.js diff --git a/libraries/bidderUtils/bidderUtils.js b/libraries/bidderUtils/bidderUtils.js deleted file mode 100644 index 551d8817e97..00000000000 --- a/libraries/bidderUtils/bidderUtils.js +++ /dev/null @@ -1,7 +0,0 @@ -export function getBidIdParameter(key, paramsObj) { - if (paramsObj && paramsObj[key]) { - return paramsObj[key]; - } - - return ''; -} diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index 15a71286b59..b40378c8e35 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,9 +1,8 @@ -import {deepAccess} from '../src/utils.js'; +import {deepAccess, getBidIdParameter} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; import {escapeUnsafeChars} from '../libraries/htmlEscape/htmlEscape.js'; diff --git a/modules/admaticBidAdapter.js b/modules/admaticBidAdapter.js index 8568f1159f6..52c06318ec0 100644 --- a/modules/admaticBidAdapter.js +++ b/modules/admaticBidAdapter.js @@ -1,8 +1,7 @@ -import { getValue, logError, isEmpty, deepAccess, isArray } from '../src/utils.js'; +import {getValue, logError, isEmpty, deepAccess, isArray, getBidIdParameter} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; let SYNC_URL = ''; const BIDDER_CODE = 'admatic'; export const spec = { diff --git a/modules/adriverBidAdapter.js b/modules/adriverBidAdapter.js index 731ff0d1d32..5bce315f572 100644 --- a/modules/adriverBidAdapter.js +++ b/modules/adriverBidAdapter.js @@ -1,8 +1,7 @@ // ADRIVER BID ADAPTER for Prebid 1.13 -import { logInfo, getWindowLocation, _each } from '../src/utils.js'; +import {logInfo, getWindowLocation, _each, getBidIdParameter} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'adriver'; const ADRIVER_BID_URL = 'https://pb.adriver.ru/cgi-bin/bid.cgi'; diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index 447c69b5827..9049197e565 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -1,8 +1,7 @@ -import { createTrackPixelHtml, logError, logWarn, deepAccess } from '../src/utils.js'; +import {createTrackPixelHtml, logError, logWarn, deepAccess, getBidIdParameter} from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BidderCode = 'aja'; diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index b85af63ff28..872dbb43e64 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -1,17 +1,16 @@ import { - _each, - deepAccess, - formatQS, - getValue, - isArray, - isFn, - logError, - triggerPixel, + _each, + deepAccess, + formatQS, getBidIdParameter, + getValue, + isArray, + isFn, + logError, + triggerPixel, } from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'audiencerun'; const BASE_URL = 'https://d.audiencerun.com'; diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index c99554ddd5e..c25c5a2e350 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,17 +1,16 @@ import { - buildUrl, - deepAccess, - getValue, - isArray, - logInfo, - logWarn, - triggerPixel + buildUrl, + deepAccess, getBidIdParameter, + getValue, + isArray, + logInfo, + logWarn, + triggerPixel } from '../src/utils.js'; import {getRefererInfo} from '../src/refererDetection.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'beop'; const ENDPOINT_URL = 'https://hb.beop.io/bid'; diff --git a/modules/bidglassBidAdapter.js b/modules/bidglassBidAdapter.js index 98acb01311a..a29976cfcb7 100644 --- a/modules/bidglassBidAdapter.js +++ b/modules/bidglassBidAdapter.js @@ -1,7 +1,6 @@ -import { _each, isArray, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; +import {_each, isArray, deepClone, getUniqueIdentifierStr, getBidIdParameter} from '../src/utils.js'; // import {config} from 'src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'bidglass'; diff --git a/modules/brightcomBidAdapter.js b/modules/brightcomBidAdapter.js index 5175eb20c39..04f8f29407b 100644 --- a/modules/brightcomBidAdapter.js +++ b/modules/brightcomBidAdapter.js @@ -1,8 +1,20 @@ -import { _each, isArray, getWindowTop, getUniqueIdentifierStr, deepSetValue, logError, logWarn, createTrackPixelHtml, getWindowSelf, isFn, isPlainObject } from '../src/utils.js'; +import { + _each, + isArray, + getWindowTop, + getUniqueIdentifierStr, + deepSetValue, + logError, + logWarn, + createTrackPixelHtml, + getWindowSelf, + isFn, + isPlainObject, + getBidIdParameter +} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'brightcom'; const URL = 'https://brightcombid.marphezis.com/hb'; diff --git a/modules/brightcomSSPBidAdapter.js b/modules/brightcomSSPBidAdapter.js index 76270fa5afb..5139e3df83e 100644 --- a/modules/brightcomSSPBidAdapter.js +++ b/modules/brightcomSSPBidAdapter.js @@ -1,20 +1,19 @@ import { - isArray, - getWindowTop, - getUniqueIdentifierStr, - deepSetValue, - logError, - logWarn, - createTrackPixelHtml, - getWindowSelf, - isFn, - isPlainObject, + isArray, + getWindowTop, + getUniqueIdentifierStr, + deepSetValue, + logError, + logWarn, + createTrackPixelHtml, + getWindowSelf, + isFn, + isPlainObject, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {ajax} from '../src/ajax.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'bcmssp'; const URL = 'https://rt.marphezis.com/hb'; diff --git a/modules/cadentApertureMXBidAdapter.js b/modules/cadentApertureMXBidAdapter.js index 187999da716..8942c95463d 100644 --- a/modules/cadentApertureMXBidAdapter.js +++ b/modules/cadentApertureMXBidAdapter.js @@ -1,19 +1,18 @@ import { - _each, - deepAccess, - isArray, - isFn, - isPlainObject, - isStr, - logError, - logWarn + _each, + deepAccess, getBidIdParameter, + isArray, + isFn, + isPlainObject, + isStr, + logError, + logWarn } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; import {find, includes} from '../src/polyfill.js'; import {parseDomain} from '../src/refererDetection.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'cadent_aperture_mx'; const ENDPOINT = 'hb.emxdgt.com'; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index 2388cf0e2b0..2f3380ea8d7 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -1,24 +1,23 @@ import { - logWarn, - isStr, - deepAccess, - isArray, - deepSetValue, - isEmpty, - _each, - convertTypes, - parseUrl, - mergeDeep, - buildUrl, - _map, - logError, - isFn, - isPlainObject, + logWarn, + isStr, + deepAccess, + isArray, + deepSetValue, + isEmpty, + _each, + convertTypes, + parseUrl, + mergeDeep, + buildUrl, + _map, + logError, + isFn, + isPlainObject, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; // Maintainer: mediapsr@epsilon.com diff --git a/modules/cpmstarBidAdapter.js b/modules/cpmstarBidAdapter.js index a7759b2b200..e076fb4b0bb 100755 --- a/modules/cpmstarBidAdapter.js +++ b/modules/cpmstarBidAdapter.js @@ -2,7 +2,7 @@ import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {getBidIdParameter} from '../src/utils.js'; const BIDDER_CODE = 'cpmstar'; diff --git a/modules/datawrkzBidAdapter.js b/modules/datawrkzBidAdapter.js index f5967d6c90d..e569c007b77 100644 --- a/modules/datawrkzBidAdapter.js +++ b/modules/datawrkzBidAdapter.js @@ -1,4 +1,12 @@ -import { deepAccess, isArray, getUniqueIdentifierStr, contains, isFn, isPlainObject } from '../src/utils.js'; +import { + deepAccess, + isArray, + getUniqueIdentifierStr, + contains, + isFn, + isPlainObject, + getBidIdParameter +} from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -6,7 +14,6 @@ import { createBid } from '../src/bidfactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import CONSTANTS from '../src/constants.json'; import { OUTSTREAM, INSTREAM } from '../src/video.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'datawrkz'; const ALIASES = []; diff --git a/modules/dspxBidAdapter.js b/modules/dspxBidAdapter.js index de17e4b1bd7..b8e812f581a 100644 --- a/modules/dspxBidAdapter.js +++ b/modules/dspxBidAdapter.js @@ -1,9 +1,8 @@ -import {deepAccess, isFn, logError, logMessage, logWarn} from '../src/utils.js'; +import {deepAccess, getBidIdParameter, isFn, logError, logMessage, logWarn} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; import {includes} from '../src/polyfill.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'dspx'; const ENDPOINT_URL = 'https://buyer.dspx.tv/request/'; diff --git a/modules/ebdrBidAdapter.js b/modules/ebdrBidAdapter.js index 0f51214b326..e830f8a94f7 100644 --- a/modules/ebdrBidAdapter.js +++ b/modules/ebdrBidAdapter.js @@ -1,7 +1,6 @@ -import { logInfo} from '../src/utils.js'; +import {getBidIdParameter, logInfo} from '../src/utils.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'ebdr'; export const spec = { code: BIDDER_CODE, diff --git a/modules/eskimiBidAdapter.js b/modules/eskimiBidAdapter.js index d1c6bd63e88..81b8c5d8058 100644 --- a/modules/eskimiBidAdapter.js +++ b/modules/eskimiBidAdapter.js @@ -2,7 +2,7 @@ import {ortbConverter} from '../libraries/ortbConverter/converter.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import * as utils from '../src/utils.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {getBidIdParameter} from '../src/utils.js'; const BIDDER_CODE = 'eskimi'; // const ENDPOINT = 'https://hb.eskimi.com/bids' diff --git a/modules/getintentBidAdapter.js b/modules/getintentBidAdapter.js index aa4d0dcb55c..2b6ea1c2c2a 100644 --- a/modules/getintentBidAdapter.js +++ b/modules/getintentBidAdapter.js @@ -1,6 +1,5 @@ -import { isFn, isInteger } from '../src/utils.js'; +import {getBidIdParameter, isFn, isInteger} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'getintent'; const IS_NET_REVENUE = true; diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index 55a1e074cd0..a174bf7811a 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -1,16 +1,15 @@ import { - createTrackPixelHtml, - deepAccess, - deepSetValue, - getDNT, - getWindowTop, - isEmpty, - logError + createTrackPixelHtml, + deepAccess, + deepSetValue, getBidIdParameter, + getDNT, + getWindowTop, + isEmpty, + logError } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER} from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'gmossp'; diff --git a/modules/growadvertisingBidAdapter.js b/modules/growadvertisingBidAdapter.js index 1deef8c0c48..f6f7867f0fe 100644 --- a/modules/growadvertisingBidAdapter.js +++ b/modules/growadvertisingBidAdapter.js @@ -1,10 +1,9 @@ 'use strict'; -import { deepAccess, _each, triggerPixel } from '../src/utils.js'; +import {deepAccess, _each, triggerPixel, getBidIdParameter} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'growads'; diff --git a/modules/holidBidAdapter.js b/modules/holidBidAdapter.js index 30cce6fdfc9..8c791ee4ba6 100644 --- a/modules/holidBidAdapter.js +++ b/modules/holidBidAdapter.js @@ -1,16 +1,15 @@ import { - deepAccess, - deepSetValue, - isStr, - logMessage, - triggerPixel, + deepAccess, + deepSetValue, getBidIdParameter, + isStr, + logMessage, + triggerPixel, } from '../src/utils.js'; import * as events from '../src/events.js'; import CONSTANTS from '../src/constants.json'; import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'holid' const GVLID = 1177 diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 6149302bd50..b56cc56a186 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -1,4 +1,4 @@ -import {deepAccess, deepSetValue, getUniqueIdentifierStr, logWarn, mergeDeep} from '../src/utils.js'; +import {deepAccess, deepSetValue, getBidIdParameter, getUniqueIdentifierStr, logWarn, mergeDeep} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; @@ -6,7 +6,6 @@ import {Renderer} from '../src/Renderer.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js'; import {loadExternalScript} from '../src/adloader.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'improvedigital'; const CREATIVE_TTL = 300; diff --git a/modules/iqmBidAdapter.js b/modules/iqmBidAdapter.js index 8de9d379d10..c3808afd225 100644 --- a/modules/iqmBidAdapter.js +++ b/modules/iqmBidAdapter.js @@ -1,8 +1,7 @@ -import {_each, deepAccess, isArray} from '../src/utils.js'; +import {_each, deepAccess, getBidIdParameter, isArray} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {INSTREAM} from '../src/video.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'iqm'; const VERSION = 'v.1.0.0'; diff --git a/modules/ivsBidAdapter.js b/modules/ivsBidAdapter.js index 3cb199354c2..6f4c024f09f 100644 --- a/modules/ivsBidAdapter.js +++ b/modules/ivsBidAdapter.js @@ -1,9 +1,8 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js'; -import { deepAccess, deepSetValue, logError } from '../src/utils.js'; +import {deepAccess, deepSetValue, getBidIdParameter, logError} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO } from '../src/mediaTypes.js'; import { INSTREAM } from '../src/video.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'ivs'; const ENDPOINT_URL = 'https://a.ivstracker.net/prod/openrtb/2.5'; diff --git a/modules/kueezBidAdapter.js b/modules/kueezBidAdapter.js index 1e3d41f606f..bae181351cd 100644 --- a/modules/kueezBidAdapter.js +++ b/modules/kueezBidAdapter.js @@ -1,8 +1,19 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; +import { + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter +} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_ENDPOINT = 'https://hb.kueezssp.com/hb-kz-multi'; const BIDDER_TEST_ENDPOINT = 'https://hb.kueezssp.com/hb-multi-kz-test' diff --git a/modules/lockerdomeBidAdapter.js b/modules/lockerdomeBidAdapter.js index 2522e5f86bc..5038eadce30 100644 --- a/modules/lockerdomeBidAdapter.js +++ b/modules/lockerdomeBidAdapter.js @@ -1,6 +1,6 @@ import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {getBidIdParameter} from '../src/utils.js'; export const spec = { code: 'lockerdome', diff --git a/modules/mediasniperBidAdapter.js b/modules/mediasniperBidAdapter.js index 22f8487c484..1c913eec929 100644 --- a/modules/mediasniperBidAdapter.js +++ b/modules/mediasniperBidAdapter.js @@ -1,22 +1,21 @@ import { - deepAccess, - deepClone, - deepSetValue, - inIframe, - isArray, - isEmpty, - isFn, - isNumber, - isStr, - logError, - logMessage, - logWarn, - triggerPixel, + deepAccess, + deepClone, + deepSetValue, getBidIdParameter, + inIframe, + isArray, + isEmpty, + isFn, + isNumber, + isStr, + logError, + logMessage, + logWarn, + triggerPixel, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'mediasniper'; const DEFAULT_BID_TTL = 360; diff --git a/modules/mgidBidAdapter.js b/modules/mgidBidAdapter.js index d63cb316702..9842205d5cd 100644 --- a/modules/mgidBidAdapter.js +++ b/modules/mgidBidAdapter.js @@ -1,18 +1,18 @@ import { - _each, - deepAccess, - isPlainObject, - isArray, - isStr, - logInfo, - parseUrl, - isEmpty, - triggerPixel, - logWarn, - isFn, - isNumber, - isBoolean, - isInteger, deepSetValue, + _each, + deepAccess, + isPlainObject, + isArray, + isStr, + logInfo, + parseUrl, + isEmpty, + triggerPixel, + logWarn, + isFn, + isNumber, + isBoolean, + isInteger, deepSetValue, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; @@ -20,7 +20,6 @@ import {config} from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {USERSYNC_DEFAULT_CONFIG} from '../src/userSync.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const GVLID = 358; const DEFAULT_CUR = 'USD'; diff --git a/modules/minutemediaBidAdapter.js b/modules/minutemediaBidAdapter.js index 338b1a28cf8..d426baeb519 100644 --- a/modules/minutemediaBidAdapter.js +++ b/modules/minutemediaBidAdapter.js @@ -1,8 +1,19 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; +import { + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter +} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'minutemedia'; diff --git a/modules/nextMillenniumBidAdapter.js b/modules/nextMillenniumBidAdapter.js index ed788cca6ff..c7dc047b411 100644 --- a/modules/nextMillenniumBidAdapter.js +++ b/modules/nextMillenniumBidAdapter.js @@ -1,15 +1,15 @@ import { - _each, - createTrackPixelHtml, - deepAccess, - getDefinedParams, - getWindowTop, - isArray, - isStr, - logMessage, - parseGPTSingleSizeArrayToRtbSize, - parseUrl, - triggerPixel, + _each, + createTrackPixelHtml, + deepAccess, getBidIdParameter, + getDefinedParams, + getWindowTop, + isArray, + isStr, + logMessage, + parseGPTSingleSizeArrayToRtbSize, + parseUrl, + triggerPixel, } from '../src/utils.js'; import CONSTANTS from '../src/constants.json'; @@ -19,7 +19,6 @@ import * as events from '../src/events.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getRefererInfo} from '../src/refererDetection.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'nextMillennium'; const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction'; diff --git a/modules/nextrollBidAdapter.js b/modules/nextrollBidAdapter.js index 5f5158f922b..b7ac61e8473 100644 --- a/modules/nextrollBidAdapter.js +++ b/modules/nextrollBidAdapter.js @@ -1,19 +1,18 @@ import { - deepAccess, - isArray, - isFn, - isNumber, - isPlainObject, - isStr, - parseUrl, - replaceAuctionPrice, + deepAccess, getBidIdParameter, + isArray, + isFn, + isNumber, + isPlainObject, + isStr, + parseUrl, + replaceAuctionPrice, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {find} from '../src/polyfill.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'nextroll'; const BIDDER_ENDPOINT = 'https://d.adroll.com/bid/prebid/'; diff --git a/modules/onomagicBidAdapter.js b/modules/onomagicBidAdapter.js index 60a425da102..46e6aeac538 100644 --- a/modules/onomagicBidAdapter.js +++ b/modules/onomagicBidAdapter.js @@ -1,18 +1,17 @@ import { - _each, - createTrackPixelHtml, - getUniqueIdentifierStr, - getWindowSelf, - getWindowTop, - isArray, - isFn, - isPlainObject, - logError, - logWarn + _each, + createTrackPixelHtml, getBidIdParameter, + getUniqueIdentifierStr, + getWindowSelf, + getWindowTop, + isArray, + isFn, + isPlainObject, + logError, + logWarn } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'onomagic'; const URL = 'https://bidder.onomagic.com/hb'; diff --git a/modules/open8BidAdapter.js b/modules/open8BidAdapter.js index eca2c6c4bfa..49523926c0e 100644 --- a/modules/open8BidAdapter.js +++ b/modules/open8BidAdapter.js @@ -1,9 +1,8 @@ import { Renderer } from '../src/Renderer.js'; import {ajax} from '../src/ajax.js'; -import { createTrackPixelHtml, logError, logWarn} from '../src/utils.js'; +import {createTrackPixelHtml, getBidIdParameter, logError, logWarn} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BIDDER_CODE = 'open8'; diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 6d0b89e48c1..f55c7ff9917 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,6 +1,6 @@ import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {getBidIdParameter} from '../src/utils.js'; const BIDDER_CODE = 'orbitsoft'; let styleParamsMap = { diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js index e2fa4667a31..984cd92574b 100644 --- a/modules/otmBidAdapter.js +++ b/modules/otmBidAdapter.js @@ -1,17 +1,16 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { - logInfo, - logError, - _each, - getValue, - isFn, - isPlainObject, - isArray, - isStr, - isNumber, + logInfo, + logError, + _each, + getValue, + isFn, + isPlainObject, + isArray, + isStr, + isNumber, getBidIdParameter, } from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'otm'; const OTM_BID_URL = 'https://ssp.otm-r.com/adjson'; diff --git a/modules/relaidoBidAdapter.js b/modules/relaidoBidAdapter.js index f149211da66..6ac882758ee 100644 --- a/modules/relaidoBidAdapter.js +++ b/modules/relaidoBidAdapter.js @@ -1,10 +1,19 @@ -import { deepAccess, logWarn, parseQueryStringParameters, triggerPixel, generateUUID, isArray, isNumber, parseSizesInput } from '../src/utils.js'; +import { + deepAccess, + logWarn, + parseQueryStringParameters, + triggerPixel, + generateUUID, + isArray, + isNumber, + parseSizesInput, + getBidIdParameter +} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { Renderer } from '../src/Renderer.js'; import { getStorageManager } from '../src/storageManager.js'; import sha1 from 'crypto-js/sha1'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'relaido'; const BIDDER_DOMAIN = 'api.relaido.jp'; diff --git a/modules/riseBidAdapter.js b/modules/riseBidAdapter.js index be2d141c9c7..4cb24086234 100644 --- a/modules/riseBidAdapter.js +++ b/modules/riseBidAdapter.js @@ -1,8 +1,19 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; +import { + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter +} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'rise'; diff --git a/modules/shinezBidAdapter.js b/modules/shinezBidAdapter.js index 2d2a37eb283..1dd9fbb650b 100644 --- a/modules/shinezBidAdapter.js +++ b/modules/shinezBidAdapter.js @@ -1,8 +1,19 @@ -import { logWarn, logInfo, isArray, isFn, deepAccess, isEmpty, contains, timestamp, triggerPixel, isInteger } from '../src/utils.js'; +import { + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter +} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; const BIDDER_CODE = 'shinez'; diff --git a/modules/showheroes-bsBidAdapter.js b/modules/showheroes-bsBidAdapter.js index e183b6e7894..db5fc0708c1 100644 --- a/modules/showheroes-bsBidAdapter.js +++ b/modules/showheroes-bsBidAdapter.js @@ -1,16 +1,15 @@ import { - deepAccess, - getWindowTop, - triggerPixel, - logInfo, - logError + deepAccess, + getWindowTop, + triggerPixel, + logInfo, + logError, getBidIdParameter } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { loadExternalScript } from '../src/adloader.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const PROD_ENDPOINT = 'https://bs.showheroes.com/api/v1/bid'; const STAGE_ENDPOINT = 'https://bid-service.stage.showheroes.com/api/v1/bid'; diff --git a/modules/slimcutBidAdapter.js b/modules/slimcutBidAdapter.js index 1c8018c1c5c..c3f06556652 100644 --- a/modules/slimcutBidAdapter.js +++ b/modules/slimcutBidAdapter.js @@ -1,11 +1,10 @@ -import { getValue, parseSizesInput} from '../src/utils.js'; +import {getBidIdParameter, getValue, parseSizesInput} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ajax } from '../src/ajax.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'slimcut'; const ENDPOINT_URL = 'https://sb.freeskreen.com/pbr'; export const spec = { diff --git a/modules/smartxBidAdapter.js b/modules/smartxBidAdapter.js index c66e6b028be..0f448e86dc1 100644 --- a/modules/smartxBidAdapter.js +++ b/modules/smartxBidAdapter.js @@ -1,4 +1,17 @@ -import { logError, deepAccess, isArray, getDNT, generateUUID, isEmpty, _each, logMessage, logWarn, isFn, isPlainObject } from '../src/utils.js'; +import { + logError, + deepAccess, + isArray, + getDNT, + generateUUID, + isEmpty, + _each, + logMessage, + logWarn, + isFn, + isPlainObject, + getBidIdParameter +} from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; @@ -8,7 +21,6 @@ import { import { VIDEO } from '../src/mediaTypes.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'smartx'; const URL = 'https://bid.sxp.smartclip.net/bid/1000'; const GVLID = 115; diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 01ecbfda266..4a5725a3947 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,12 +1,12 @@ import { - _each, - isArray, - getUniqueIdentifierStr, - deepSetValue, - logError, - deepAccess, - isInteger, - logWarn + _each, + isArray, + getUniqueIdentifierStr, + deepSetValue, + logError, + deepAccess, + isInteger, + logWarn, getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { @@ -14,7 +14,6 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js' -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const ORTB_VIDEO_PARAMS = { 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), diff --git a/modules/spotxBidAdapter.js b/modules/spotxBidAdapter.js index e189e99e7cf..c7bd8e9da93 100644 --- a/modules/spotxBidAdapter.js +++ b/modules/spotxBidAdapter.js @@ -1,10 +1,25 @@ -import { logError, deepAccess, isArray, getDNT, deepSetValue, isEmpty, _each, logMessage, logWarn, isBoolean, isNumber, isPlainObject, isFn, setScriptAttributes } from '../src/utils.js'; +import { + logError, + deepAccess, + isArray, + getDNT, + deepSetValue, + isEmpty, + _each, + logMessage, + logWarn, + isBoolean, + isNumber, + isPlainObject, + isFn, + setScriptAttributes, + getBidIdParameter +} from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO } from '../src/mediaTypes.js'; import { loadExternalScript } from '../src/adloader.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'spotx'; const URL = 'https://search.spotxchange.com/openrtb/2.3/dados/'; diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 325602e0fec..7ec7656078e 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -1,7 +1,6 @@ -import { getValue, logError, deepAccess, parseSizesInput, isArray } from '../src/utils.js'; +import {getValue, logError, deepAccess, parseSizesInput, isArray, getBidIdParameter} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'teads'; const GVL_ID = 132; diff --git a/modules/trionBidAdapter.js b/modules/trionBidAdapter.js index c10e8058d6c..e976396c71c 100644 --- a/modules/trionBidAdapter.js +++ b/modules/trionBidAdapter.js @@ -1,7 +1,6 @@ -import { parseSizesInput} from '../src/utils.js'; +import {getBidIdParameter, parseSizesInput} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; const BID_REQUEST_BASE_URL = 'https://in-appadvertising.com/api/bidRequest'; diff --git a/modules/viantOrtbBidAdapter.js b/modules/viantOrtbBidAdapter.js index f6159dd0c43..e7bf9129a62 100644 --- a/modules/viantOrtbBidAdapter.js +++ b/modules/viantOrtbBidAdapter.js @@ -2,8 +2,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import * as utils from '../src/utils.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js' -import {deepAccess, logError} from '../src/utils.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {deepAccess, getBidIdParameter, logError} from '../src/utils.js'; const BIDDER_CODE = 'viant'; const ENDPOINT = 'https://bidders-us-east-1.adelphic.net/d/rtb/v25/prebid/bidder_test' diff --git a/modules/videonowBidAdapter.js b/modules/videonowBidAdapter.js index 75a520bbac8..bfbc07fdff1 100644 --- a/modules/videonowBidAdapter.js +++ b/modules/videonowBidAdapter.js @@ -1,7 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import {_each, getValue, logError, logInfo} from '../src/utils.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {_each, getBidIdParameter, getValue, logError, logInfo} from '../src/utils.js'; const BIDDER_CODE = 'videonow'; const RTB_URL = 'https://adx.videonow.ru/yhb' diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js index d3debf61b87..8835398d7cc 100644 --- a/modules/videoreachBidAdapter.js +++ b/modules/videoreachBidAdapter.js @@ -1,6 +1,5 @@ -import { getValue} from '../src/utils.js'; +import {getBidIdParameter, getValue} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const BIDDER_CODE = 'videoreach'; const ENDPOINT_URL = 'https://a.videoreach.com/hb/'; const GVLID = 547; diff --git a/modules/waardexBidAdapter.js b/modules/waardexBidAdapter.js index a61e123be21..92b7fc26e4c 100644 --- a/modules/waardexBidAdapter.js +++ b/modules/waardexBidAdapter.js @@ -1,9 +1,8 @@ -import {deepAccess, isArray, logError} from '../src/utils.js'; +import {deepAccess, getBidIdParameter, isArray, logError} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {find} from '../src/polyfill.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; const ENDPOINT = `https://hb.justbidit.xyz:8843/prebid`; const BIDDER_CODE = 'waardex'; diff --git a/modules/xeBidAdapter.js b/modules/xeBidAdapter.js index aef0bd5b6d2..6f527d905d6 100644 --- a/modules/xeBidAdapter.js +++ b/modules/xeBidAdapter.js @@ -1,8 +1,7 @@ import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { parseSizesInput, isFn, deepAccess, logError, isArray } from '../src/utils.js'; -import {getBidIdParameter} from '../libraries/bidderUtils/bidderUtils.js'; +import {parseSizesInput, isFn, deepAccess, logError, isArray, getBidIdParameter} from '../src/utils.js'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const CUR = 'USD'; diff --git a/src/utils.js b/src/utils.js index 6b8e654d66e..fea408b699c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -102,6 +102,10 @@ function _getRandomData() { } } +export function getBidIdParameter(key, paramsObj) { + return paramsObj?.[key] || ''; +} + // parse a query string object passed in bid params // bid params should be an object such as {key: "value", key1 : "value1"} // aliases to formatQS diff --git a/test/spec/libraries/bidderUtils_spec.js b/test/spec/libraries/bidderUtils_spec.js deleted file mode 100644 index 0de91adcf77..00000000000 --- a/test/spec/libraries/bidderUtils_spec.js +++ /dev/null @@ -1,22 +0,0 @@ -import {getBidIdParameter} from '../../../libraries/bidderUtils/bidderUtils.js'; -import assert from 'assert'; - -describe('getBidIdParameter', function () { - it('should return value of the key in input object', function () { - var obj = { - a: 'valueA', - b: 'valueB' - }; - var output = getBidIdParameter('a', obj); - assert.equal(output, 'valueA'); - }); - - it('should return empty string, if the key is not existsed in the object', function () { - var obj = { - a: 'valueA', - b: 'valueB' - }; - var output = getBidIdParameter('c', obj); - assert.equal(output, ''); - }); -}); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 176096c75ea..3491bf4015a 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -3,7 +3,6 @@ import {expect} from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; import {deepEqual, memoize, waitForElementToLoad} from 'src/utils.js'; -import {getAdUnitSizes} from '../../libraries/sizeUtils/sizeUtils.js'; var assert = require('assert'); @@ -20,6 +19,26 @@ describe('Utils', function () { type_array = 'Array', type_function = 'Function'; + describe('getBidIdParameter', function () { + it('should return value of the key in input object', function () { + var obj = { + a: 'valueA', + b: 'valueB' + }; + var output = utils.getBidIdParameter('a', obj); + assert.equal(output, 'valueA'); + }); + + it('should return empty string, if the key is not existsed in the object', function () { + var obj = { + a: 'valueA', + b: 'valueB' + }; + var output = utils.getBidIdParameter('c', obj); + assert.equal(output, ''); + }); + }); + describe('parseQueryStringParameters', function () { it('should append query string to existing using the input obj', function () { var obj = { From 93cdd6f2845b7fb29ddcfdea1beebf7a833d79be Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 06:52:33 -0700 Subject: [PATCH 10/23] _each --- src/adapterManager.js | 3 +-- src/auction.js | 3 +-- src/events.js | 8 ++++---- src/utils.js | 27 ++++----------------------- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/adapterManager.js b/src/adapterManager.js index 9d0bba086a4..84942e2ed02 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -1,7 +1,6 @@ /** @module adaptermanger */ import { - _each, deepAccess, deepClone, flatten, @@ -584,7 +583,7 @@ adapterManager.enableAnalytics = function (config) { config = [config]; } - _each(config, adapterConfig => { + config.forEach(adapterConfig => { const entry = _analyticsRegistry[adapterConfig.provider]; if (entry && entry.adapter) { if (dep.isAllowed(ACTIVITY_REPORT_ANALYTICS, activityParams(MODULE_TYPE_ANALYTICS, adapterConfig.provider, {[ACTIVITY_PARAM_ANL_CONFIG]: adapterConfig}))) { diff --git a/src/auction.js b/src/auction.js index 3336134bd83..aaa5d352d0e 100644 --- a/src/auction.js +++ b/src/auction.js @@ -58,7 +58,6 @@ */ import { - _each, adUnitsFilter, deepAccess, flatten, @@ -960,7 +959,7 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]; custBidObj.size = custBidObj.getSize(); - _each(targeting, function (kvPair) { + targeting?.forEach(function (kvPair) { var key = kvPair.key; var value = kvPair.val; diff --git a/src/events.js b/src/events.js index 62f8c070deb..d0495c6385d 100644 --- a/src/events.js +++ b/src/events.js @@ -62,7 +62,7 @@ const _public = (function () { push.apply(callbacks, event.que); /** call each of the callbacks */ - utils._each(callbacks, function (fn) { + callbacks?.forEach(function (fn) { if (!fn) return; try { fn.apply(null, args); @@ -111,14 +111,14 @@ const _public = (function () { } if (id) { - utils._each(event[id].que, function (_handler) { + event[id].que?.forEach(function (_handler) { var que = event[id].que; if (_handler === handler) { que.splice(que.indexOf(_handler), 1); } }); } else { - utils._each(event.que, function (_handler) { + event.que?.forEach(function (_handler) { var que = event.que; if (_handler === handler) { que.splice(que.indexOf(_handler), 1); @@ -143,7 +143,7 @@ const _public = (function () { */ _public.getEvents = function () { var arrayCopy = []; - utils._each(eventsFired, function (value) { + eventsFired.forEach(function (value) { var newProp = Object.assign({}, value); arrayCopy.push(newProp); }); diff --git a/src/utils.js b/src/utils.js index fea408b699c..4df2579a99e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -8,7 +8,6 @@ import {getGlobal} from './prebidGlobal.js'; export { default as deepAccess } from 'dlv/index.js'; export { dset as deepSetValue } from 'dset'; -var tArr = 'Array'; var tStr = 'String'; var tFn = 'Function'; var tNumb = 'Number'; @@ -322,9 +321,7 @@ export function isStr(object) { return isA(object, tStr); } -export function isArray(object) { - return isA(object, tArr); -} +export const isArray = Array.isArray.bind(Array); export function isNumber(object) { return isA(object, tNumb); @@ -349,12 +346,7 @@ export function isEmpty(object) { if (isArray(object) || isStr(object)) { return !(object.length > 0); } - - for (var k in object) { - if (hasOwnProperty.call(object, k)) return false; - } - - return true; + return Object.keys(object).length <= 0; } /** @@ -373,19 +365,8 @@ export function isEmptyStr(str) { * @param {Function(value, key, object)} fn */ export function _each(object, fn) { - if (isEmpty(object)) return; - if (isFn(object.forEach)) return object.forEach(fn, this); - - var k = 0; - var l = object.length; - - if (l > 0) { - for (; k < l; k++) fn(object[k], k, object); - } else { - for (k in object) { - if (hasOwnProperty.call(object, k)) fn.call(this, object[k], k); - } - } + if (isFn(object?.forEach)) return object.forEach(fn, this); + Object.entries(object || {}).forEach(([k, v]) => fn.call(this, v, k)); } export function contains(a, obj) { From 6cce2262d51122bf088eda706628cb67cd4fe4d9 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:19:37 -0700 Subject: [PATCH 11/23] map/contains --- src/events.js | 12 ++++-------- src/prebid.js | 3 +-- src/utils.js | 27 +++------------------------ 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/events.js b/src/events.js index d0495c6385d..d7d2c1ac08a 100644 --- a/src/events.js +++ b/src/events.js @@ -9,9 +9,7 @@ var push = Array.prototype.push; // define entire events // var allEvents = ['bidRequested','bidResponse','bidWon','bidTimeout']; -var allEvents = utils._map(CONSTANTS.EVENTS, function (v) { - return v; -}); +var allEvents = Object.values(CONSTANTS.EVENTS) var idPaths = CONSTANTS.EVENT_ID_PATHS; @@ -34,9 +32,7 @@ const _public = (function () { var idPath = idPaths[eventString]; var key = eventPayload[idPath]; var event = _handlers[eventString] || { que: [] }; - var eventKeys = utils._map(event, function (v, k) { - return k; - }); + var eventKeys = Object.keys(event) var callbacks = []; @@ -54,7 +50,7 @@ const _public = (function () { * each function in the `que` array as an argument to push to the * `callbacks` array * */ - if (key && utils.contains(eventKeys, key)) { + if (key && eventKeys.includes(key)) { push.apply(callbacks, event[key].que); } @@ -73,7 +69,7 @@ const _public = (function () { } function _checkAvailableEvent(event) { - return utils.contains(allEvents, event); + return allEvents.includes(event) } _public.on = function (eventString, handler, id) { diff --git a/src/prebid.js b/src/prebid.js index 016ccbbd15e..d38781e400e 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -4,7 +4,6 @@ import {getGlobal} from './prebidGlobal.js'; import { adUnitsFilter, callBurl, - contains, createInvisibleIframe, deepAccess, deepClone, @@ -89,7 +88,7 @@ function checkDefinedPlacement(id) { .reduce(flatten) .filter(uniques); - if (!contains(adUnitCodes, id)) { + if (!adUnitCodes.includes(id)) { logError('The "' + id + '" placement is not defined.'); return; } diff --git a/src/utils.js b/src/utils.js index 4df2579a99e..48a1a7cc025 100644 --- a/src/utils.js +++ b/src/utils.js @@ -370,22 +370,7 @@ export function _each(object, fn) { } export function contains(a, obj) { - if (isEmpty(a)) { - return false; - } - - if (isFn(a.indexOf)) { - return a.indexOf(obj) !== -1; - } - - var i = a.length; - while (i--) { - if (a[i] === obj) { - return true; - } - } - - return false; + return isFn(a?.includes) && a.includes(obj); } /** @@ -396,14 +381,8 @@ export function contains(a, obj) { * @return {Array} */ export function _map(object, callback) { - if (isEmpty(object)) return []; - if (isFn(object.map)) return object.map(callback); - var output = []; - _each(object, function (value, key) { - output.push(callback(value, key, object)); - }); - - return output; + if (isFn(object?.map)) return object.map(callback); + return Object.entries(object || {}).map(([k, v]) => callback(v, k, object)) } export function hasOwn(objectToCheck, propertyToCheckFor) { From 8ebfcda9765e0b0e44aa2250ab0859a2cef65b1b Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:25:59 -0700 Subject: [PATCH 12/23] hasOwn --- modules/dchain.js | 4 ++-- modules/iasRtdProvider.js | 2 +- modules/schain.js | 27 ++++++++++++++------------- src/utils.js | 14 +++----------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/modules/dchain.js b/modules/dchain.js index daf97a7551f..7f84282b81e 100644 --- a/modules/dchain.js +++ b/modules/dchain.js @@ -1,7 +1,7 @@ import {includes} from '../src/polyfill.js'; import {config} from '../src/config.js'; import {getHook} from '../src/hook.js'; -import {_each, deepAccess, deepClone, hasOwn, isArray, isPlainObject, isStr, logError, logWarn} from '../src/utils.js'; +import {_each, deepAccess, deepClone, isArray, isPlainObject, isStr, logError, logWarn} from '../src/utils.js'; import {timedBidResponseHook} from '../src/utils/perfMetrics.js'; const shouldBeAString = ' should be a string'; @@ -49,7 +49,7 @@ export function checkDchainSyntax(bid, mode) { appendFailMsg(`dchain.ver` + shouldBeAString); } - if (hasOwn(dchainObj, 'ext')) { + if (dchainObj.hasOwnProperty('ext')) { if (!isPlainObject(dchainObj.ext)) { appendFailMsg(`dchain.ext` + shouldBeAnObject); } diff --git a/modules/iasRtdProvider.js b/modules/iasRtdProvider.js index d50684b8765..a720826f284 100644 --- a/modules/iasRtdProvider.js +++ b/modules/iasRtdProvider.js @@ -77,7 +77,7 @@ function getAdUnitPath(adSlot, bidRequest, adUnitPath) { if (!utils.isEmpty(adSlot)) { p = adSlot.gptSlot; } else { - if (!utils.isEmpty(adUnitPath) && utils.hasOwn(adUnitPath, bidRequest.code)) { + if (!utils.isEmpty(adUnitPath) && adUnitPath.hasOwnProperty(bidRequest.code)) { if (utils.isStr(adUnitPath[bidRequest.code]) && !utils.isEmpty(adUnitPath[bidRequest.code])) { p = adUnitPath[bidRequest.code]; } diff --git a/modules/schain.js b/modules/schain.js index 2991bb5b3d5..726679b133f 100644 --- a/modules/schain.js +++ b/modules/schain.js @@ -1,16 +1,17 @@ -import { config } from '../src/config.js'; +import {config} from '../src/config.js'; import adapterManager from '../src/adapterManager.js'; import { - isNumber, - isStr, + _each, + deepAccess, + deepClone, + deepSetValue, isArray, + isInteger, + isNumber, isPlainObject, - hasOwn, + isStr, logError, - isInteger, - _each, - logWarn, - deepAccess, deepSetValue, deepClone + logWarn } from '../src/utils.js'; import {registerOrtbProcessor, REQUEST} from '../src/pbjsORTB.js'; @@ -63,7 +64,7 @@ export function isSchainObjectValid(schainObject, returnOnError) { } // ext: Object [optional] - if (hasOwn(schainObject, 'ext')) { + if (schainObject.hasOwnProperty('ext')) { if (!isPlainObject(schainObject.ext)) { appendFailMsg(`schain.config.ext` + shouldBeAnObject); } @@ -92,28 +93,28 @@ export function isSchainObjectValid(schainObject, returnOnError) { } // rid: String [Optional] - if (hasOwn(node, 'rid')) { + if (node.hasOwnProperty('rid')) { if (!isStr(node.rid)) { appendFailMsg(`schain.config.nodes[${index}].rid` + shouldBeAString); } } // name: String [Optional] - if (hasOwn(node, 'name')) { + if (node.hasOwnProperty('name')) { if (!isStr(node.name)) { appendFailMsg(`schain.config.nodes[${index}].name` + shouldBeAString); } } // domain: String [Optional] - if (hasOwn(node, 'domain')) { + if (node.hasOwnProperty('domain')) { if (!isStr(node.domain)) { appendFailMsg(`schain.config.nodes[${index}].domain` + shouldBeAString); } } // ext: Object [Optional] - if (hasOwn(node, 'ext')) { + if (node.hasOwnProperty('ext')) { if (!isPlainObject(node.ext)) { appendFailMsg(`schain.config.nodes[${index}].ext` + shouldBeAnObject); } diff --git a/src/utils.js b/src/utils.js index 48a1a7cc025..05d70c36ce8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -145,9 +145,9 @@ export function parseSizesInput(sizeObj) { // start of line, at least 1 number, an "x" , then at least 1 number, and the then end of the line var sizeRegex = /^(\d)+x(\d)+$/i; if (sizes) { - for (var curSizePos in sizes) { - if (hasOwn(sizes, curSizePos) && sizes[curSizePos].match(sizeRegex)) { - parsedSizes.push(sizes[curSizePos]); + for (const size of sizes) { + if (size.match(sizeRegex)) { + parsedSizes.push(size); } } } @@ -385,14 +385,6 @@ export function _map(object, callback) { return Object.entries(object || {}).map(([k, v]) => callback(v, k, object)) } -export function hasOwn(objectToCheck, propertyToCheckFor) { - if (objectToCheck.hasOwnProperty) { - return objectToCheck.hasOwnProperty(propertyToCheckFor); - } else { - return (typeof objectToCheck[propertyToCheckFor] !== 'undefined') && (objectToCheck.constructor.prototype[propertyToCheckFor] !== objectToCheck[propertyToCheckFor]); - } -}; - /* * Inserts an element(elm) as targets child, by default as first child * @param {HTMLElement} elm From 95b59c9d900835df2661e13861597fc9d9713653 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:34:00 -0700 Subject: [PATCH 13/23] insertHtmlIntoIframe --- src/utils.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/utils.js b/src/utils.js index 05d70c36ce8..ebf74d25505 100644 --- a/src/utils.js +++ b/src/utils.js @@ -291,6 +291,9 @@ export function createInvisibleIframe() { f.frameBorder = '0'; f.src = 'about:blank'; f.style.display = 'none'; + f.style.height = '0px'; + f.style.width = '0px'; + f.allowtransparency = 'true'; return f; } @@ -467,27 +470,14 @@ export function insertHtmlIntoIframe(htmlCode) { if (!htmlCode) { return; } - - let iframe = document.createElement('iframe'); - iframe.id = getUniqueIdentifierStr(); - iframe.width = 0; - iframe.height = 0; - iframe.hspace = '0'; - iframe.vspace = '0'; - iframe.marginWidth = '0'; - iframe.marginHeight = '0'; - iframe.style.display = 'none'; - iframe.style.height = '0px'; - iframe.style.width = '0px'; - iframe.scrolling = 'no'; - iframe.frameBorder = '0'; - iframe.allowtransparency = 'true'; - + const iframe = createInvisibleIframe(); internal.insertElement(iframe, document, 'body'); - iframe.contentWindow.document.open(); - iframe.contentWindow.document.write(htmlCode); - iframe.contentWindow.document.close(); + ((doc) => { + doc.open(); + doc.write(htmlCode); + doc.close(); + })(iframe.contentWindow.document); } /** From 78b2817f550f4a8c898db8ba4c5ea3648304041c Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:41:33 -0700 Subject: [PATCH 14/23] getValueString/getKeys --- libraries/appnexusKeywords/anKeywords.js | 15 ++++++++++++++- modules/iasRtdProvider.js | 2 +- src/utils.js | 21 ++------------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/libraries/appnexusKeywords/anKeywords.js b/libraries/appnexusKeywords/anKeywords.js index 5dc0b453253..d6714dacc21 100644 --- a/libraries/appnexusKeywords/anKeywords.js +++ b/libraries/appnexusKeywords/anKeywords.js @@ -1,4 +1,4 @@ -import {_each, deepAccess, getValueString, isArray, isStr, mergeDeep, isNumber} from '../../src/utils.js'; +import {_each, deepAccess, isArray, isNumber, isStr, mergeDeep, logWarn} from '../../src/utils.js'; import {getAllOrtbKeywords} from '../keywords/keywords.js'; import {CLIENT_SECTIONS} from '../../src/fpd/oneClient.js'; @@ -12,6 +12,19 @@ const ORTB_SEG_PATHS = ['user.data'].concat( CLIENT_SECTIONS.map((prefix) => `${prefix}.content.data`) ); +function getValueString(param, val, defaultValue) { + if (val === undefined || val === null) { + return defaultValue; + } + if (isStr(val)) { + return val; + } + if (isNumber(val)) { + return val.toString(); + } + logWarn('Unsuported type for param: ' + param + ' required type: String'); +} + /** * Converts an object of arrays (either strings or numbers) into an array of objects containing key and value properties * normally read from bidder params diff --git a/modules/iasRtdProvider.js b/modules/iasRtdProvider.js index a720826f284..93680abdc13 100644 --- a/modules/iasRtdProvider.js +++ b/modules/iasRtdProvider.js @@ -93,7 +93,7 @@ function stringifySlot(bidRequest, adUnitPath) { const adSlot = utils.getGptSlotInfoForAdUnitCode(bidRequest.code); const p = getAdUnitPath(adSlot, bidRequest, adUnitPath); const slot = { id, ss, p }; - const keyValues = utils.getKeys(slot).map(function (key) { + const keyValues = Object.keys(slot).map(function (key) { return [key, slot[key]].join(':'); }); return '{' + keyValues.join(',') + '}'; diff --git a/src/utils.js b/src/utils.js index ebf74d25505..c7b8dd5a249 100644 --- a/src/utils.js +++ b/src/utils.js @@ -121,8 +121,8 @@ export function parseQueryStringParameters(queryObj) { export function transformAdServerTargetingObj(targeting) { // we expect to receive targeting for a single slot at a time if (targeting && Object.getOwnPropertyNames(targeting).length > 0) { - return getKeys(targeting) - .map(key => `${key}=${encodeURIComponent(getValue(targeting, key))}`).join('&'); + return Object.keys(targeting) + .map(key => `${key}=${encodeURIComponent(targeting[key])}`).join('&'); } else { return ''; } @@ -543,19 +543,6 @@ export function createTrackPixelIframeHtml(url, encodeUri = true, sandbox = '') `; } -export function getValueString(param, val, defaultValue) { - if (val === undefined || val === null) { - return defaultValue; - } - if (isStr(val)) { - return val; - } - if (isNumber(val)) { - return val.toString(); - } - internal.logWarn('Unsuported type for param: ' + param + ' required type: String'); -} - export function uniques(value, index, arry) { return arry.indexOf(value) === index; } @@ -579,10 +566,6 @@ export function getBidRequest(id, bidderRequests) { return bidRequest; } -export function getKeys(obj) { - return Object.keys(obj); -} - export function getValue(obj, key) { return obj[key]; } From d4d90661222456f3fe1bf1cd6237ea93b734c7a0 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:46:20 -0700 Subject: [PATCH 15/23] getBidRequest --- src/utils.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/utils.js b/src/utils.js index c7b8dd5a249..b401a4c6814 100644 --- a/src/utils.js +++ b/src/utils.js @@ -555,15 +555,8 @@ export function getBidRequest(id, bidderRequests) { if (!id) { return; } - let bidRequest; - bidderRequests.some(bidderRequest => { - let result = find(bidderRequest.bids, bid => ['bidId', 'adId', 'bid_id'].some(type => bid[type] === id)); - if (result) { - bidRequest = result; - } - return result; - }); - return bidRequest; + return bidderRequests.flatMap(br => br.bids) + .find(bid => ['bidId', 'adId', 'bid_id'].some(prop => bid[prop] === id)) } export function getValue(obj, key) { From 7cb0bb2f9214607180d54c5acaab428831f1cd36 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:49:07 -0700 Subject: [PATCH 16/23] getKeyByValue --- src/native.js | 4 +++- src/utils.js | 13 ------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/native.js b/src/native.js index 1414c7a2ee7..12d6dc0d623 100644 --- a/src/native.js +++ b/src/native.js @@ -422,12 +422,14 @@ function assetsMessage(data, adObject, keys, {index = auctionManager.index} = {} return message; } +const NATIVE_KEYS_INVERTED = Object.fromEntries(Object.entries(CONSTANTS.NATIVE_KEYS).map(([k, v]) => [v, k])); + /** * Constructs a message object containing asset values for each of the * requested data keys. */ export function getAssetMessage(data, adObject) { - const keys = data.assets.map((k) => getKeyByValue(CONSTANTS.NATIVE_KEYS, k)); + const keys = data.assets.map((k) => NATIVE_KEYS_INVERTED[k]); return assetsMessage(data, adObject, keys); } diff --git a/src/utils.js b/src/utils.js index b401a4c6814..478ecff4fe5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -563,19 +563,6 @@ export function getValue(obj, key) { return obj[key]; } -/** - * Get the key of an object for a given value - */ -export function getKeyByValue(obj, value) { - for (let prop in obj) { - if (obj.hasOwnProperty(prop)) { - if (obj[prop] === value) { - return prop; - } - } - } -} - export function getBidderCodes(adUnits = pbjsInstance.adUnits) { // this could memoize adUnits return adUnits.map(unit => unit.bids.map(bid => bid.bidder) From 2e153adcc557c08008d25970d23c1d54fe9e18d3 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 07:58:53 -0700 Subject: [PATCH 17/23] adUnitsFilter --- src/auction.js | 4 +--- src/prebid.js | 3 +-- src/utils.js | 4 ---- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/auction.js b/src/auction.js index aaa5d352d0e..c32655e1bde 100644 --- a/src/auction.js +++ b/src/auction.js @@ -58,7 +58,6 @@ */ import { - adUnitsFilter, deepAccess, flatten, generateUUID, @@ -212,9 +211,8 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a bidsBackCallback(_adUnits, function () { try { if (_callback != null) { - const adUnitCodes = _adUnitCodes; const bids = _bidsReceived - .filter(adUnitsFilter.bind(this, adUnitCodes)) + .filter(bid => _adUnitCodes.includes(bid.adUnitCode)) .reduce(groupByPlacement, {}); _callback.apply(pbjsInstance, [bids, timedOut, _auctionId]); _callback = null; diff --git a/src/prebid.js b/src/prebid.js index d38781e400e..65b2ebc1d35 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -2,7 +2,6 @@ import {getGlobal} from './prebidGlobal.js'; import { - adUnitsFilter, callBurl, createInvisibleIframe, deepAccess, @@ -336,7 +335,7 @@ pbjsInstance.getConsentMetadata = function () { function getBids(type) { const responses = auctionManager[type]() - .filter(adUnitsFilter.bind(this, auctionManager.getAdUnitCodes())) + .filter(bid => auctionManager.getAdUnitCodes().includes(bid.adUnitCode)) // find the last auction id to get responses for most recent auction only const currentAuctionId = auctionManager.getLastAuctionId(); diff --git a/src/utils.js b/src/utils.js index 478ecff4fe5..eb37222c5aa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -627,10 +627,6 @@ export function shuffle(array) { return array; } -export function adUnitsFilter(filter, bid) { - return includes(filter, bid && bid.adUnitCode); -} - export function deepClone(obj) { return clone(obj); } From da99e50b2ce5e618437b57dec749c45f5cd57a11 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 08:10:23 -0700 Subject: [PATCH 18/23] gptUtils --- libraries/gptUtils/gptUtils.js | 37 ++++++++++++++++++ modules/33acrossBidAdapter.js | 2 +- modules/adagioBidAdapter.js | 2 +- modules/adlooxAnalyticsAdapter.js | 2 +- modules/adlooxRtdProvider.js | 2 +- modules/eplanningBidAdapter.js | 3 +- modules/fledgeForGpt.js | 3 +- modules/iasRtdProvider.js | 3 +- modules/ixBidAdapter.js | 2 +- modules/medianetBidAdapter.js | 2 +- modules/priceFloors.js | 2 +- modules/pubmaticAnalyticsAdapter.js | 3 +- modules/pubxaiAnalyticsAdapter.js | 3 +- modules/sonobiBidAdapter.js | 3 +- modules/underdogmediaBidAdapter.js | 2 +- modules/visxBidAdapter.js | 3 +- src/utils.js | 39 +------------------ .../modules/pubxaiAnalyticsAdapter_spec.js | 16 +++----- test/spec/modules/sonobiBidAdapter_spec.js | 13 ++++--- 19 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 libraries/gptUtils/gptUtils.js diff --git a/libraries/gptUtils/gptUtils.js b/libraries/gptUtils/gptUtils.js new file mode 100644 index 00000000000..950f28c618f --- /dev/null +++ b/libraries/gptUtils/gptUtils.js @@ -0,0 +1,37 @@ +import {find} from '../../src/polyfill.js'; +import {compareCodeAndSlot, isGptPubadsDefined} from '../../src/utils.js'; + +/** + * Returns filter function to match adUnitCode in slot + * @param {string} adUnitCode AdUnit code + * @return {function} filter function + */ +export function isSlotMatchingAdUnitCode(adUnitCode) { + return (slot) => compareCodeAndSlot(slot, adUnitCode); +} + +/** + * @summary Uses the adUnit's code in order to find a matching gpt slot object on the page + */ +export function getGptSlotForAdUnitCode(adUnitCode) { + let matchingSlot; + if (isGptPubadsDefined()) { + // find the first matching gpt slot on the page + matchingSlot = find(window.googletag.pubads().getSlots(), isSlotMatchingAdUnitCode(adUnitCode)); + } + return matchingSlot; +} + +/** + * @summary Uses the adUnit's code in order to find a matching gptSlot on the page + */ +export function getGptSlotInfoForAdUnitCode(adUnitCode) { + const matchingSlot = getGptSlotForAdUnitCode(adUnitCode); + if (matchingSlot) { + return { + gptSlot: matchingSlot.getAdUnitPath(), + divId: matchingSlot.getSlotElementId() + }; + } + return {}; +} diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index b965183de19..0e9beb22013 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -6,7 +6,6 @@ import { getWindowTop, isArray, isGptPubadsDefined, - isSlotMatchingAdUnitCode, logInfo, logWarn, mergeDeep, @@ -14,6 +13,7 @@ import { uniques } from '../src/utils.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {isSlotMatchingAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; // **************************** UTILS *************************** // const BIDDER_CODE = '33across'; diff --git a/modules/adagioBidAdapter.js b/modules/adagioBidAdapter.js index c642dff5a8f..3de584a1195 100644 --- a/modules/adagioBidAdapter.js +++ b/modules/adagioBidAdapter.js @@ -6,7 +6,6 @@ import { deepClone, generateUUID, getDNT, - getGptSlotInfoForAdUnitCode, getUniqueIdentifierStr, getWindowSelf, getWindowTop, @@ -34,6 +33,7 @@ import {OUTSTREAM} from '../src/video.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import { userSync } from '../src/userSync.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'adagio'; const LOG_PREFIX = 'Adagio:'; diff --git a/modules/adlooxAnalyticsAdapter.js b/modules/adlooxAnalyticsAdapter.js index 5db75c656bb..9284d543298 100644 --- a/modules/adlooxAnalyticsAdapter.js +++ b/modules/adlooxAnalyticsAdapter.js @@ -14,7 +14,6 @@ import {find} from '../src/polyfill.js'; import {getRefererInfo} from '../src/refererDetection.js'; import { deepAccess, - getGptSlotInfoForAdUnitCode, getUniqueIdentifierStr, insertElement, isFn, @@ -28,6 +27,7 @@ import { mergeDeep, parseUrl } from '../src/utils.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const MODULE = 'adlooxAnalyticsAdapter'; diff --git a/modules/adlooxRtdProvider.js b/modules/adlooxRtdProvider.js index c2037429185..727dc84e399 100644 --- a/modules/adlooxRtdProvider.js +++ b/modules/adlooxRtdProvider.js @@ -25,7 +25,6 @@ import { deepAccess, deepClone, deepSetValue, - getGptSlotInfoForAdUnitCode, isArray, isBoolean, isInteger, @@ -37,6 +36,7 @@ import { parseUrl, safeJSONParse } from '../src/utils.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const MODULE_NAME = 'adloox'; const MODULE = `${MODULE_NAME}RtdProvider`; diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 1ebbc78730c..d57804c04e6 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -1,8 +1,9 @@ -import {getWindowSelf, isEmpty, parseSizesInput, isGptPubadsDefined, isSlotMatchingAdUnitCode} from '../src/utils.js'; +import {getWindowSelf, isEmpty, parseSizesInput, isGptPubadsDefined} from '../src/utils.js'; import {getGlobal} from '../src/prebidGlobal.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {isSlotMatchingAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'eplanning'; export const storage = getStorageManager({bidderCode: BIDDER_CODE}); diff --git a/modules/fledgeForGpt.js b/modules/fledgeForGpt.js index e592cd38044..0e78ee55434 100644 --- a/modules/fledgeForGpt.js +++ b/modules/fledgeForGpt.js @@ -4,8 +4,9 @@ */ import { config } from '../src/config.js'; import { getHook } from '../src/hook.js'; -import { getGptSlotForAdUnitCode, logInfo, logWarn } from '../src/utils.js'; +import { logInfo, logWarn } from '../src/utils.js'; import {IMP, PBS, registerOrtbProcessor, RESPONSE} from '../src/pbjsORTB.js'; +import {getGptSlotForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const MODULE = 'fledgeForGpt' diff --git a/modules/iasRtdProvider.js b/modules/iasRtdProvider.js index 93680abdc13..b9de7ef4e46 100644 --- a/modules/iasRtdProvider.js +++ b/modules/iasRtdProvider.js @@ -3,6 +3,7 @@ import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getGlobal} from '../src/prebidGlobal.js'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; /** @type {string} */ const MODULE_NAME = 'realTimeData'; @@ -90,7 +91,7 @@ function stringifySlot(bidRequest, adUnitPath) { const sizes = getAdUnitSizes(bidRequest); const id = bidRequest.code; const ss = stringifySlotSizes(sizes); - const adSlot = utils.getGptSlotInfoForAdUnitCode(bidRequest.code); + const adSlot = getGptSlotInfoForAdUnitCode(bidRequest.code); const p = getAdUnitPath(adSlot, bidRequest, adUnitPath); const slot = { id, ss, p }; const keyValues = Object.keys(slot).map(function (key) { diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index d083fb46798..ffe12f744b8 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -4,7 +4,6 @@ import { deepAccess, deepClone, deepSetValue, - getGptSlotInfoForAdUnitCode, inIframe, isArray, isEmpty, @@ -24,6 +23,7 @@ import { find } from '../src/polyfill.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { INSTREAM, OUTSTREAM } from '../src/video.js'; import { Renderer } from '../src/Renderer.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'ix'; const ALIAS_BIDDER_CODE = 'roundel'; diff --git a/modules/medianetBidAdapter.js b/modules/medianetBidAdapter.js index 659da0c16fb..041db71cd34 100644 --- a/modules/medianetBidAdapter.js +++ b/modules/medianetBidAdapter.js @@ -1,7 +1,6 @@ import { buildUrl, deepAccess, - getGptSlotInfoForAdUnitCode, getWindowTop, isArray, isEmpty, @@ -18,6 +17,7 @@ import {getRefererInfo} from '../src/refererDetection.js'; import {Renderer} from '../src/Renderer.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {getGlobal} from '../src/prebidGlobal.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'medianet'; const TRUSTEDSTACK_CODE = 'trustedstack'; diff --git a/modules/priceFloors.js b/modules/priceFloors.js index 37167fff691..79d812de206 100644 --- a/modules/priceFloors.js +++ b/modules/priceFloors.js @@ -4,7 +4,6 @@ import { deepClone, deepSetValue, generateUUID, - getGptSlotInfoForAdUnitCode, getParameterByName, isNumber, logError, @@ -29,6 +28,7 @@ import {IMP, PBS, registerOrtbProcessor, REQUEST} from '../src/pbjsORTB.js'; import {timedAuctionHook, timedBidResponseHook} from '../src/utils/perfMetrics.js'; import {beConvertCurrency} from '../src/utils/currency.js'; import {adjustCpm} from '../src/utils/cpm.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; /** * @summary This Module is intended to provide users with the ability to dynamically set and enforce price floors on a per auction basis. diff --git a/modules/pubmaticAnalyticsAdapter.js b/modules/pubmaticAnalyticsAdapter.js index 3391773a3d2..31d6dc7fda3 100755 --- a/modules/pubmaticAnalyticsAdapter.js +++ b/modules/pubmaticAnalyticsAdapter.js @@ -1,10 +1,11 @@ -import { _each, pick, logWarn, isStr, isArray, logError, getGptSlotInfoForAdUnitCode } from '../src/utils.js'; +import { _each, pick, logWarn, isStr, isArray, logError} from '../src/utils.js'; import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import { ajax } from '../src/ajax.js'; import { config } from '../src/config.js'; import { getGlobal } from '../src/prebidGlobal.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; /// /////////// CONSTANTS ////////////// const ADAPTER_CODE = 'pubmatic'; diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index 19a3c236942..e97e5505768 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -1,9 +1,10 @@ -import { deepAccess, getGptSlotInfoForAdUnitCode, parseSizesInput, getWindowLocation, buildUrl } from '../src/utils.js'; +import { deepAccess, parseSizesInput, getWindowLocation, buildUrl } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import {getGlobal} from '../src/prebidGlobal.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const emptyUrl = ''; const analyticsType = 'endpoint'; diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index 704275cc1bf..cd7654ac9bc 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -1,11 +1,12 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, getGptSlotInfoForAdUnitCode, isFn, isPlainObject } from '../src/utils.js'; +import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, isFn, isPlainObject } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { userSync } from '../src/userSync.js'; import { bidderSettings } from '../src/bidderSettings.js'; import { getAllOrtbKeywords } from '../libraries/keywords/keywords.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'sonobi'; const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json'; const PAGEVIEW_ID = generateUUID(); diff --git a/modules/underdogmediaBidAdapter.js b/modules/underdogmediaBidAdapter.js index 7561cdb60de..4c2bdfe175f 100644 --- a/modules/underdogmediaBidAdapter.js +++ b/modules/underdogmediaBidAdapter.js @@ -4,7 +4,6 @@ import { getWindowSelf, getWindowTop, isGptPubadsDefined, - isSlotMatchingAdUnitCode, logInfo, logMessage, logWarn, @@ -12,6 +11,7 @@ import { } from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {isSlotMatchingAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'underdogmedia'; const UDM_ADAPTER_VERSION = '7.30V'; diff --git a/modules/visxBidAdapter.js b/modules/visxBidAdapter.js index c1bb626a39c..6c588335aa0 100644 --- a/modules/visxBidAdapter.js +++ b/modules/visxBidAdapter.js @@ -1,9 +1,10 @@ -import { triggerPixel, parseSizesInput, deepAccess, logError, getGptSlotInfoForAdUnitCode } from '../src/utils.js'; +import { triggerPixel, parseSizesInput, deepAccess, logError} from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { INSTREAM as VIDEO_INSTREAM } from '../src/video.js'; import {getStorageManager} from '../src/storageManager.js'; +import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; const BIDDER_CODE = 'visx'; const GVLID = 154; const BASE_URL = 'https://t.visx.net'; diff --git a/src/utils.js b/src/utils.js index eb37222c5aa..5451f5b5a58 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,6 @@ import {config} from './config.js'; import clone from 'just-clone'; -import {find, includes} from './polyfill.js'; +import {includes} from './polyfill.js'; import CONSTANTS from './constants.json'; import {GreedyPromise} from './utils/promise.js'; import {getGlobal} from './prebidGlobal.js'; @@ -786,7 +786,7 @@ export function getDNT() { return navigator.doNotTrack === '1' || window.doNotTrack === '1' || navigator.msDoNotTrack === '1' || navigator.doNotTrack === 'yes'; } -const compareCodeAndSlot = (slot, adUnitCode) => slot.getAdUnitPath() === adUnitCode || slot.getSlotElementId() === adUnitCode; +export const compareCodeAndSlot = (slot, adUnitCode) => slot.getAdUnitPath() === adUnitCode || slot.getSlotElementId() === adUnitCode; /** * Returns filter function to match adUnitCode in slot @@ -797,41 +797,6 @@ export function isAdUnitCodeMatchingSlot(slot) { return (adUnitCode) => compareCodeAndSlot(slot, adUnitCode); } -/** - * Returns filter function to match adUnitCode in slot - * @param {string} adUnitCode AdUnit code - * @return {function} filter function - */ -export function isSlotMatchingAdUnitCode(adUnitCode) { - return (slot) => compareCodeAndSlot(slot, adUnitCode); -} - -/** - * @summary Uses the adUnit's code in order to find a matching gpt slot object on the page - */ -export function getGptSlotForAdUnitCode(adUnitCode) { - let matchingSlot; - if (isGptPubadsDefined()) { - // find the first matching gpt slot on the page - matchingSlot = find(window.googletag.pubads().getSlots(), isSlotMatchingAdUnitCode(adUnitCode)); - } - return matchingSlot; -}; - -/** - * @summary Uses the adUnit's code in order to find a matching gptSlot on the page - */ -export function getGptSlotInfoForAdUnitCode(adUnitCode) { - const matchingSlot = getGptSlotForAdUnitCode(adUnitCode); - if (matchingSlot) { - return { - gptSlot: matchingSlot.getAdUnitPath(), - divId: matchingSlot.getSlotElementId() - } - } - return {}; -}; - /** * Constructs warning message for when unsupported bidders are dropped from an adunit * @param {Object} adUnit ad unit from which the bidder is being dropped diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index 1dce87e4b8e..e0f4497a8c8 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -1,13 +1,9 @@ -import pubxaiAnalyticsAdapter from 'modules/pubxaiAnalyticsAdapter.js'; -import { getDeviceType, getBrowser, getOS } from 'modules/pubxaiAnalyticsAdapter.js'; -import { - expect -} from 'chai'; +import pubxaiAnalyticsAdapter, {getBrowser, getDeviceType, getOS} from 'modules/pubxaiAnalyticsAdapter.js'; +import {expect} from 'chai'; import adapterManager from 'src/adapterManager.js'; import * as utils from 'src/utils.js'; -import { - server -} from 'test/mocks/xhr.js'; +import {server} from 'test/mocks/xhr.js'; +import {getGptSlotInfoForAdUnitCode} from '../../../libraries/gptUtils/gptUtils.js'; let events = require('src/events'); let constants = require('src/constants.json'); @@ -527,7 +523,7 @@ describe('pubxai analytics adapter', function() { 'bidderCode': 'appnexus', 'bidId': '248f9a4489835e', 'adUnitCode': '/19968336/header-bid-tag-1', - 'gptSlotCode': utils.getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || null, + 'gptSlotCode': getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || null, 'auctionId': 'bc3806e4-873e-453c-8ae5-204f35e923b4', 'sizes': '300x250', 'renderStatus': 2, @@ -596,7 +592,7 @@ describe('pubxai analytics adapter', function() { let expectedAfterBidWon = { 'winningBid': { 'adUnitCode': '/19968336/header-bid-tag-1', - 'gptSlotCode': utils.getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || null, + 'gptSlotCode': getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || null, 'auctionId': 'bc3806e4-873e-453c-8ae5-204f35e923b4', 'bidderCode': 'appnexus', 'bidId': '248f9a4489835e', diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js index de8d0a5bda7..7290e83e170 100644 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ b/test/spec/modules/sonobiBidAdapter_spec.js @@ -1,9 +1,10 @@ -import { expect } from 'chai' -import { spec, _getPlatform } from 'modules/sonobiBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' -import { userSync } from '../../../src/userSync.js'; -import { config } from 'src/config.js'; +import {expect} from 'chai'; +import {_getPlatform, spec} from 'modules/sonobiBidAdapter.js'; +import {newBidder} from 'src/adapters/bidderFactory.js'; +import {userSync} from '../../../src/userSync.js'; +import {config} from 'src/config.js'; import * as utils from '../../../src/utils.js'; +import {getGptSlotInfoForAdUnitCode} from '../../../libraries/gptUtils/gptUtils.js'; describe('SonobiBidAdapter', function () { const adapter = newBidder(spec) @@ -254,7 +255,7 @@ describe('SonobiBidAdapter', function () { }); afterEach(function () { userSync.canBidderRegisterSync.restore(); - utils.getGptSlotInfoForAdUnitCode.restore(); + getGptSlotInfoForAdUnitCode.restore(); sandbox.restore(); }); let bidRequest = [{ From cf5d3390aecfe9d735f345c04f0ed80e07bee677 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 08:15:54 -0700 Subject: [PATCH 19/23] isInteger --- src/utils.js | 8 +------- test/spec/modules/sonobiBidAdapter_spec.js | 7 +++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/utils.js b/src/utils.js index 5451f5b5a58..d84947b11ee 100644 --- a/src/utils.js +++ b/src/utils.js @@ -818,13 +818,7 @@ export function unsupportedBidderMessage(adUnit, bidder) { * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger * @param {*} value */ -export function isInteger(value) { - if (Number.isInteger) { - return Number.isInteger(value); - } else { - return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; - } -} +export const isInteger = Number.isInteger.bind(Number); /** * Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id' diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js index 7290e83e170..1e3596ee736 100644 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ b/test/spec/modules/sonobiBidAdapter_spec.js @@ -3,8 +3,7 @@ import {_getPlatform, spec} from 'modules/sonobiBidAdapter.js'; import {newBidder} from 'src/adapters/bidderFactory.js'; import {userSync} from '../../../src/userSync.js'; import {config} from 'src/config.js'; -import * as utils from '../../../src/utils.js'; -import {getGptSlotInfoForAdUnitCode} from '../../../libraries/gptUtils/gptUtils.js'; +import * as gptUtils from '../../../libraries/gptUtils/gptUtils.js'; describe('SonobiBidAdapter', function () { const adapter = newBidder(spec) @@ -249,13 +248,13 @@ describe('SonobiBidAdapter', function () { let sandbox; beforeEach(function () { sinon.stub(userSync, 'canBidderRegisterSync'); - sinon.stub(utils, 'getGptSlotInfoForAdUnitCode') + sinon.stub(gptUtils, 'getGptSlotInfoForAdUnitCode') .onFirstCall().returns({ gptSlot: '/123123/gpt_publisher/adunit-code-3', divId: 'adunit-code-3-div-id' }); sandbox = sinon.createSandbox(); }); afterEach(function () { userSync.canBidderRegisterSync.restore(); - getGptSlotInfoForAdUnitCode.restore(); + gptUtils.getGptSlotInfoForAdUnitCode.restore(); sandbox.restore(); }); let bidRequest = [{ From ed2067bf1e893c122dd6ca6151a22cc605aefd34 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 08:21:25 -0700 Subject: [PATCH 20/23] convertCamelCaseToUnderscore --- .../anKeywords.js | 0 libraries/appnexusUtils/anUtils.js | 9 +++++++++ modules/adrelevantisBidAdapter.js | 4 ++-- modules/appnexusBidAdapter.js | 4 ++-- modules/craftBidAdapter.js | 5 +++-- modules/goldbachBidAdapter.js | 4 ++-- modules/mediafuseBidAdapter.js | 4 ++-- modules/pixfutureBidAdapter.js | 5 +++-- modules/prismaBidAdapter.js | 2 +- modules/ventesBidAdapter.js | 3 ++- modules/winrBidAdapter.js | 4 ++-- src/utils.js | 15 +-------------- test/spec/appnexusKeywords_spec.js | 2 +- test/spec/utils_spec.js | 5 +++-- 14 files changed, 33 insertions(+), 33 deletions(-) rename libraries/{appnexusKeywords => appnexusUtils}/anKeywords.js (100%) create mode 100644 libraries/appnexusUtils/anUtils.js diff --git a/libraries/appnexusKeywords/anKeywords.js b/libraries/appnexusUtils/anKeywords.js similarity index 100% rename from libraries/appnexusKeywords/anKeywords.js rename to libraries/appnexusUtils/anKeywords.js diff --git a/libraries/appnexusUtils/anUtils.js b/libraries/appnexusUtils/anUtils.js new file mode 100644 index 00000000000..c8fff6d2776 --- /dev/null +++ b/libraries/appnexusUtils/anUtils.js @@ -0,0 +1,9 @@ +/** + * Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id' + * @param {string} value string value to convert + */ +export function convertCamelToUnderscore(value) { + return value.replace(/(?:^|\.?)([A-Z])/g, function (x, y) { + return '_' + y.toLowerCase(); + }).replace(/^_/, ''); +} diff --git a/modules/adrelevantisBidAdapter.js b/modules/adrelevantisBidAdapter.js index f1f92e5dd5e..a6bb8c96a62 100644 --- a/modules/adrelevantisBidAdapter.js +++ b/modules/adrelevantisBidAdapter.js @@ -1,7 +1,6 @@ import {Renderer} from '../src/Renderer.js'; import { chunk, - convertCamelToUnderscore, convertTypes, createTrackPixelHtml, deepAccess, @@ -21,7 +20,8 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {find, includes} from '../src/polyfill.js'; import {INSTREAM, OUTSTREAM} from '../src/video.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; -import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'adrelevantis'; const URL = 'https://ssp.adrelevantis.com/prebid'; diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 97e86530283..94c5c414a60 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,6 +1,5 @@ import { chunk, - convertCamelToUnderscore, convertTypes, createTrackPixelHtml, deepAccess, @@ -37,7 +36,8 @@ import { getANKewyordParamFromMaps, getANKeywordParam, transformBidderParamKeywords -} from '../libraries/appnexusKeywords/anKeywords.js'; +} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'appnexus'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/craftBidAdapter.js b/modules/craftBidAdapter.js index 8f7821173c1..5c7804f8c69 100644 --- a/modules/craftBidAdapter.js +++ b/modules/craftBidAdapter.js @@ -1,4 +1,4 @@ -import {convertCamelToUnderscore, convertTypes, getBidRequest, logError} from '../src/utils.js'; +import {convertTypes, getBidRequest, logError} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {auctionManager} from '../src/auctionManager.js'; @@ -7,7 +7,8 @@ import {getStorageManager} from '../src/storageManager.js'; import {ajax} from '../src/ajax.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; -import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'craft'; const URL_BASE = 'https://gacraft.jp/prebid-v3'; diff --git a/modules/goldbachBidAdapter.js b/modules/goldbachBidAdapter.js index 76a1b9fc0fe..6b6393e43da 100644 --- a/modules/goldbachBidAdapter.js +++ b/modules/goldbachBidAdapter.js @@ -1,7 +1,6 @@ import {Renderer} from '../src/Renderer.js'; import { chunk, - convertCamelToUnderscore, convertTypes, createTrackPixelHtml, deepAccess, @@ -29,7 +28,8 @@ import {INSTREAM, OUTSTREAM} from '../src/video.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {APPNEXUS_CATEGORY_MAPPING} from '../libraries/categoryTranslationMapping/index.js'; -import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'goldbach'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/mediafuseBidAdapter.js b/modules/mediafuseBidAdapter.js index 84a36472ec0..ed5864bc423 100644 --- a/modules/mediafuseBidAdapter.js +++ b/modules/mediafuseBidAdapter.js @@ -1,6 +1,5 @@ import { chunk, - convertCamelToUnderscore, convertTypes, createTrackPixelHtml, deepAccess, @@ -36,7 +35,8 @@ import { getANKewyordParamFromMaps, getANKeywordParam, transformBidderParamKeywords -} from '../libraries/appnexusKeywords/anKeywords.js'; +} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'mediafuse'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/pixfutureBidAdapter.js b/modules/pixfutureBidAdapter.js index 608ba20aa5f..1c3f9b8da1a 100644 --- a/modules/pixfutureBidAdapter.js +++ b/modules/pixfutureBidAdapter.js @@ -3,10 +3,11 @@ import {getStorageManager} from '../src/storageManager.js'; import {BANNER} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {find, includes} from '../src/polyfill.js'; -import {convertCamelToUnderscore, deepAccess, isArray, isFn, isNumber, isPlainObject} from '../src/utils.js'; +import {deepAccess, isArray, isFn, isNumber, isPlainObject} from '../src/utils.js'; import {auctionManager} from '../src/auctionManager.js'; import {getGlobal} from '../src/prebidGlobal.js'; -import {getANKeywordParam} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const SOURCE = 'pbjs'; const storageManager = getStorageManager({bidderCode: 'pixfuture'}); diff --git a/modules/prismaBidAdapter.js b/modules/prismaBidAdapter.js index 7c9108f60b1..c13e6e1c330 100644 --- a/modules/prismaBidAdapter.js +++ b/modules/prismaBidAdapter.js @@ -2,7 +2,7 @@ import {ajax} from '../src/ajax.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; -import {getANKeywordParam} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js'; const BIDDER_CODE = 'prisma'; const BIDDER_URL = 'https://prisma.nexx360.io/prebid'; diff --git a/modules/ventesBidAdapter.js b/modules/ventesBidAdapter.js index 73ae0a7e5f1..78c580c4116 100644 --- a/modules/ventesBidAdapter.js +++ b/modules/ventesBidAdapter.js @@ -1,8 +1,9 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; -import {convertCamelToUnderscore, isArray, isNumber, isPlainObject, isStr, replaceAuctionPrice} from '../src/utils.js'; +import {isArray, isNumber, isPlainObject, isStr, replaceAuctionPrice} from '../src/utils.js'; import {find} from '../src/polyfill.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BID_METHOD = 'POST'; const BIDDER_URL = 'https://ad.ventesavenues.in/va/ad'; diff --git a/modules/winrBidAdapter.js b/modules/winrBidAdapter.js index 5cc063d16b4..5bde14a48c0 100644 --- a/modules/winrBidAdapter.js +++ b/modules/winrBidAdapter.js @@ -1,5 +1,4 @@ import { - convertCamelToUnderscore, convertTypes, deepAccess, getBidRequest, @@ -16,7 +15,8 @@ import {BANNER} from '../src/mediaTypes.js'; import {find, includes} from '../src/polyfill.js'; import {getStorageManager} from '../src/storageManager.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; -import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusKeywords/anKeywords.js'; +import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; +import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; const BIDDER_CODE = 'winr'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/src/utils.js b/src/utils.js index d84947b11ee..7f9b6b66668 100644 --- a/src/utils.js +++ b/src/utils.js @@ -820,25 +820,12 @@ export function unsupportedBidderMessage(adUnit, bidder) { */ export const isInteger = Number.isInteger.bind(Number); -/** - * Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id' - * @param {string} value string value to convert - */ -export function convertCamelToUnderscore(value) { - return value.replace(/(?:^|\.?)([A-Z])/g, function (x, y) { return '_' + y.toLowerCase() }).replace(/^_/, ''); -} - /** * Returns a new object with undefined properties removed from given object * @param obj the object to clean */ export function cleanObj(obj) { - return Object.keys(obj).reduce((newObj, key) => { - if (typeof obj[key] !== 'undefined') { - newObj[key] = obj[key]; - } - return newObj; - }, {}) + return Object.fromEntries(Object.entries(obj).filter(([_, v]) => typeof v !== 'undefined')) } /** diff --git a/test/spec/appnexusKeywords_spec.js b/test/spec/appnexusKeywords_spec.js index 9bf567a27c5..68faeff0b82 100644 --- a/test/spec/appnexusKeywords_spec.js +++ b/test/spec/appnexusKeywords_spec.js @@ -1,4 +1,4 @@ -import {transformBidderParamKeywords} from '../../libraries/appnexusKeywords/anKeywords.js'; +import {transformBidderParamKeywords} from '../../libraries/appnexusUtils/anKeywords.js'; import {expect} from 'chai/index.js'; import * as utils from '../../src/utils.js'; diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 3491bf4015a..8a3c4c7791b 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -3,6 +3,7 @@ import {expect} from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; import {deepEqual, memoize, waitForElementToLoad} from 'src/utils.js'; +import {convertCamelToUnderscore} from '../../libraries/appnexusUtils/anUtils.js'; var assert = require('assert'); @@ -743,11 +744,11 @@ describe('Utils', function () { describe('convertCamelToUnderscore', function () { it('returns converted string value using underscore syntax instead of camelCase', function () { let var1 = 'placementIdTest'; - let test1 = utils.convertCamelToUnderscore(var1); + let test1 = convertCamelToUnderscore(var1); expect(test1).to.equal('placement_id_test'); let var2 = 'my_test_value'; - let test2 = utils.convertCamelToUnderscore(var2); + let test2 = convertCamelToUnderscore(var2); expect(test2).to.equal(var2); }); }); From c2a368e52aa5785e8d2f0db91ea007accafd91b9 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 08:25:21 -0700 Subject: [PATCH 21/23] convertTypes --- libraries/appnexusUtils/anUtils.js | 16 ++++++ .../transformParamsUtils/convertTypes.js | 36 ++++++++++++++ modules/adrelevantisBidAdapter.js | 2 +- modules/adtelligentBidAdapter.js | 3 +- modules/appnexusBidAdapter.js | 5 +- modules/connectadBidAdapter.js | 3 +- modules/conversantBidAdapter.js | 2 +- modules/craftBidAdapter.js | 3 +- modules/goldbachBidAdapter.js | 5 +- modules/ixBidAdapter.js | 2 +- modules/mediafuseBidAdapter.js | 5 +- modules/openwebBidAdapter.js | 3 +- modules/openxBidAdapter.js | 3 +- modules/pubmaticBidAdapter.js | 3 +- modules/pulsepointBidAdapter.js | 3 +- modules/rubiconBidAdapter.js | 2 +- modules/smaatoBidAdapter.js | 3 +- modules/trafficgateBidAdapter.js | 3 +- modules/winrBidAdapter.js | 2 +- src/utils.js | 49 ------------------- 20 files changed, 81 insertions(+), 72 deletions(-) create mode 100644 libraries/transformParamsUtils/convertTypes.js diff --git a/libraries/appnexusUtils/anUtils.js b/libraries/appnexusUtils/anUtils.js index c8fff6d2776..9b55cd5c2a4 100644 --- a/libraries/appnexusUtils/anUtils.js +++ b/libraries/appnexusUtils/anUtils.js @@ -2,8 +2,24 @@ * Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id' * @param {string} value string value to convert */ +import {deepClone, isPlainObject} from '../../src/utils.js'; + export function convertCamelToUnderscore(value) { return value.replace(/(?:^|\.?)([A-Z])/g, function (x, y) { return '_' + y.toLowerCase(); }).replace(/^_/, ''); } + +/** + * Creates an array of n length and fills each item with the given value + */ +export function fill(value, length) { + let newArray = []; + + for (let i = 0; i < length; i++) { + let valueToPush = isPlainObject(value) ? deepClone(value) : value; + newArray.push(valueToPush); + } + + return newArray; +} diff --git a/libraries/transformParamsUtils/convertTypes.js b/libraries/transformParamsUtils/convertTypes.js new file mode 100644 index 00000000000..813d8e6e693 --- /dev/null +++ b/libraries/transformParamsUtils/convertTypes.js @@ -0,0 +1,36 @@ +import {isFn} from '../../src/utils.js'; + +/** + * Try to convert a value to a type. + * If it can't be done, the value will be returned. + * + * @param {string} typeToConvert The target type. e.g. "string", "number", etc. + * @param {*} value The value to be converted into typeToConvert. + */ +function tryConvertType(typeToConvert, value) { + if (typeToConvert === 'string') { + return value && value.toString(); + } else if (typeToConvert === 'number') { + return Number(value); + } else { + return value; + } +} + +export function convertTypes(types, params) { + Object.keys(types).forEach(key => { + if (params[key]) { + if (isFn(types[key])) { + params[key] = types[key](params[key]); + } else { + params[key] = tryConvertType(types[key], params[key]); + } + + // don't send invalid values + if (isNaN(params[key])) { + delete params.key; + } + } + }); + return params; +} diff --git a/modules/adrelevantisBidAdapter.js b/modules/adrelevantisBidAdapter.js index a6bb8c96a62..deb2bb9f45d 100644 --- a/modules/adrelevantisBidAdapter.js +++ b/modules/adrelevantisBidAdapter.js @@ -1,7 +1,6 @@ import {Renderer} from '../src/Renderer.js'; import { chunk, - convertTypes, createTrackPixelHtml, deepAccess, deepClone, @@ -22,6 +21,7 @@ import {INSTREAM, OUTSTREAM} from '../src/video.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'adrelevantis'; const URL = 'https://ssp.adrelevantis.com/prebid'; diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index cab2b8956bc..1c74a63b019 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -1,9 +1,10 @@ -import {_map, chunk, convertTypes, deepAccess, flatten, isArray, parseSizesInput} from '../src/utils.js'; +import {_map, chunk, deepAccess, flatten, isArray, 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'; import {Renderer} from '../src/Renderer.js'; import {find} from '../src/polyfill.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const subdomainSuffixes = ['', 1, 2]; const AUCTION_PATH = '/v2/auction/'; diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 94c5c414a60..72d7cdc58dc 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,10 +1,8 @@ import { chunk, - convertTypes, createTrackPixelHtml, deepAccess, deepClone, - fill, getBidRequest, getParameterByName, getUniqueIdentifierStr, @@ -37,7 +35,8 @@ import { getANKeywordParam, transformBidderParamKeywords } from '../libraries/appnexusUtils/anKeywords.js'; -import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'appnexus'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/connectadBidAdapter.js b/modules/connectadBidAdapter.js index f7d70a7ed69..b40ef30f6bc 100644 --- a/modules/connectadBidAdapter.js +++ b/modules/connectadBidAdapter.js @@ -1,8 +1,9 @@ -import { deepSetValue, convertTypes, logWarn } from '../src/utils.js'; +import { deepSetValue, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js' import {config} from '../src/config.js'; import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'connectad'; const BIDDER_CODE_ALIAS = 'connectadrealtime'; const ENDPOINT_URL = 'https://i.connectad.io/api/v2'; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index 2f3380ea8d7..b04bda2d8b0 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -6,7 +6,6 @@ import { deepSetValue, isEmpty, _each, - convertTypes, parseUrl, mergeDeep, buildUrl, @@ -18,6 +17,7 @@ import { import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; // Maintainer: mediapsr@epsilon.com diff --git a/modules/craftBidAdapter.js b/modules/craftBidAdapter.js index 5c7804f8c69..a2a054d7659 100644 --- a/modules/craftBidAdapter.js +++ b/modules/craftBidAdapter.js @@ -1,4 +1,4 @@ -import {convertTypes, getBidRequest, logError} from '../src/utils.js'; +import {getBidRequest, logError} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {auctionManager} from '../src/auctionManager.js'; @@ -9,6 +9,7 @@ import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'craft'; const URL_BASE = 'https://gacraft.jp/prebid-v3'; diff --git a/modules/goldbachBidAdapter.js b/modules/goldbachBidAdapter.js index 6b6393e43da..8c2741b9828 100644 --- a/modules/goldbachBidAdapter.js +++ b/modules/goldbachBidAdapter.js @@ -1,11 +1,9 @@ import {Renderer} from '../src/Renderer.js'; import { chunk, - convertTypes, createTrackPixelHtml, deepAccess, deepClone, - fill, getBidRequest, getParameterByName, isArray, @@ -29,7 +27,8 @@ import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {APPNEXUS_CATEGORY_MAPPING} from '../libraries/categoryTranslationMapping/index.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; -import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'goldbach'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index ffe12f744b8..235551d8232 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -1,6 +1,5 @@ import { contains, - convertTypes, deepAccess, deepClone, deepSetValue, @@ -24,6 +23,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { INSTREAM, OUTSTREAM } from '../src/video.js'; import { Renderer } from '../src/Renderer.js'; import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'ix'; const ALIAS_BIDDER_CODE = 'roundel'; diff --git a/modules/mediafuseBidAdapter.js b/modules/mediafuseBidAdapter.js index ed5864bc423..1f7ee9f8af4 100644 --- a/modules/mediafuseBidAdapter.js +++ b/modules/mediafuseBidAdapter.js @@ -1,10 +1,8 @@ import { chunk, - convertTypes, createTrackPixelHtml, deepAccess, deepClone, - fill, getBidRequest, getParameterByName, isArray, @@ -36,7 +34,8 @@ import { getANKeywordParam, transformBidderParamKeywords } from '../libraries/appnexusUtils/anKeywords.js'; -import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'mediafuse'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/openwebBidAdapter.js b/modules/openwebBidAdapter.js index 296bfc682f1..547447039da 100644 --- a/modules/openwebBidAdapter.js +++ b/modules/openwebBidAdapter.js @@ -1,8 +1,9 @@ -import {convertTypes, deepAccess, flatten, isArray, isNumber, parseSizesInput} from '../src/utils.js'; +import {deepAccess, flatten, isArray, isNumber, 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'; import {find} from '../src/polyfill.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const ENDPOINT = 'https://ghb.spotim.market/v2/auction'; const BIDDER_CODE = 'openweb'; diff --git a/modules/openxBidAdapter.js b/modules/openxBidAdapter.js index 03423a028b4..ebef1645de7 100644 --- a/modules/openxBidAdapter.js +++ b/modules/openxBidAdapter.js @@ -4,6 +4,7 @@ import * as utils from '../src/utils.js'; import {mergeDeep} from '../src/utils.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const bidderConfig = 'hb_pb_ortb'; const bidderVersion = '2.0'; @@ -149,7 +150,7 @@ const converter = ortbConverter({ }); function transformBidParams(params, isOpenRtb) { - return utils.convertTypes({ + return convertTypes({ 'unit': 'string', 'customFloor': 'number' }, params); diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index a3833551fff..ab67f78c6b5 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -1,10 +1,11 @@ -import { getBidRequest, logWarn, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques, isPlainObject, isInteger } from '../src/utils.js'; +import { getBidRequest, logWarn, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, uniques, isPlainObject, isInteger } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO, NATIVE, ADPOD } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { bidderSettings } from '../src/bidderSettings.js'; import CONSTANTS from '../src/constants.json'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'pubmatic'; const LOG_WARN_PREFIX = 'PubMatic: '; diff --git a/modules/pulsepointBidAdapter.js b/modules/pulsepointBidAdapter.js index 7297c931326..516254b358b 100644 --- a/modules/pulsepointBidAdapter.js +++ b/modules/pulsepointBidAdapter.js @@ -1,6 +1,7 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js'; -import {convertTypes, isArray} from '../src/utils.js'; +import {isArray} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const DEFAULT_CURRENCY = 'USD'; const KNOWN_PARAMS = ['cp', 'ct', 'cf', 'battr', 'deals']; diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 2c2a02e1949..bce524ce1c2 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -7,7 +7,6 @@ import { find } from '../src/polyfill.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { Renderer } from '../src/Renderer.js'; import { - convertTypes, deepAccess, deepSetValue, formatQS, @@ -21,6 +20,7 @@ import { parseSizesInput, _each } from '../src/utils.js'; import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const DEFAULT_INTEGRATION = 'pbjs_lite'; const DEFAULT_PBS_INTEGRATION = 'pbjs'; diff --git a/modules/smaatoBidAdapter.js b/modules/smaatoBidAdapter.js index 0cefcbd80b4..73cd052aec4 100644 --- a/modules/smaatoBidAdapter.js +++ b/modules/smaatoBidAdapter.js @@ -1,10 +1,11 @@ -import {chunk, deepAccess, deepSetValue, fill, getDNT, isEmpty, isNumber, logError, logInfo} from '../src/utils.js'; +import {chunk, deepAccess, deepSetValue, getDNT, isEmpty, isNumber, logError, logInfo} from '../src/utils.js'; import {find} from '../src/polyfill.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {ADPOD, BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import CONSTANTS from '../src/constants.json'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; +import {fill} from '../libraries/appnexusUtils/anUtils.js'; const { NATIVE_IMAGE_TYPES } = CONSTANTS; const BIDDER_CODE = 'smaato'; diff --git a/modules/trafficgateBidAdapter.js b/modules/trafficgateBidAdapter.js index 25289a19801..fcd84306099 100644 --- a/modules/trafficgateBidAdapter.js +++ b/modules/trafficgateBidAdapter.js @@ -1,7 +1,8 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {ortbConverter} from '../libraries/ortbConverter/converter.js'; -import {deepAccess, mergeDeep, convertTypes} from '../src/utils.js'; +import {deepAccess, mergeDeep} from '../src/utils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'trafficgate'; const URL = 'https://[HOST].bc-plugin.com/prebidjs' diff --git a/modules/winrBidAdapter.js b/modules/winrBidAdapter.js index 5bde14a48c0..41efc432e11 100644 --- a/modules/winrBidAdapter.js +++ b/modules/winrBidAdapter.js @@ -1,5 +1,4 @@ import { - convertTypes, deepAccess, getBidRequest, getParameterByName, @@ -17,6 +16,7 @@ import {getStorageManager} from '../src/storageManager.js'; import {hasPurpose1Consent} from '../src/utils/gpdr.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; +import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; const BIDDER_CODE = 'winr'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/src/utils.js b/src/utils.js index 7f9b6b66668..1a6d0f41e5d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -862,59 +862,10 @@ export function pick(obj, properties) { }, {}); } -/** - * Try to convert a value to a type. - * If it can't be done, the value will be returned. - * - * @param {string} typeToConvert The target type. e.g. "string", "number", etc. - * @param {*} value The value to be converted into typeToConvert. - */ -function tryConvertType(typeToConvert, value) { - if (typeToConvert === 'string') { - return value && value.toString(); - } else if (typeToConvert === 'number') { - return Number(value); - } else { - return value; - } -} - -export function convertTypes(types, params) { - Object.keys(types).forEach(key => { - if (params[key]) { - if (isFn(types[key])) { - params[key] = types[key](params[key]); - } else { - params[key] = tryConvertType(types[key], params[key]); - } - - // don't send invalid values - if (isNaN(params[key])) { - delete params.key; - } - } - }); - return params; -} - export function isArrayOfNums(val, size) { return (isArray(val)) && ((size) ? val.length === size : true) && (val.every(v => isInteger(v))); } -/** - * Creates an array of n length and fills each item with the given value - */ -export function fill(value, length) { - let newArray = []; - - for (let i = 0; i < length; i++) { - let valueToPush = isPlainObject(value) ? deepClone(value) : value; - newArray.push(valueToPush); - } - - return newArray; -} - /** * http://npm.im/chunk * Returns an array with *size* chunks from given array From 5977aa4529f9f7b77075fb281d97099a62144715 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 08:37:00 -0700 Subject: [PATCH 22/23] chunk --- libraries/chunk/chunk.js | 19 +++++++++++++++++++ modules/adrelevantisBidAdapter.js | 2 +- modules/adtargetBidAdapter.js | 3 ++- modules/adtelligentBidAdapter.js | 3 ++- modules/appnexusBidAdapter.js | 2 +- modules/goldbachBidAdapter.js | 2 +- modules/mediafuseBidAdapter.js | 2 +- modules/smaatoBidAdapter.js | 3 ++- modules/vidazooBidAdapter.js | 3 ++- src/utils.js | 20 -------------------- 10 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 libraries/chunk/chunk.js diff --git a/libraries/chunk/chunk.js b/libraries/chunk/chunk.js new file mode 100644 index 00000000000..57be7bd5016 --- /dev/null +++ b/libraries/chunk/chunk.js @@ -0,0 +1,19 @@ +/** + * http://npm.im/chunk + * Returns an array with *size* chunks from given array + * + * Example: + * ['a', 'b', 'c', 'd', 'e'] chunked by 2 => + * [['a', 'b'], ['c', 'd'], ['e']] + */ +export function chunk(array, size) { + let newArray = []; + + for (let i = 0; i < Math.ceil(array.length / size); i++) { + let start = i * size; + let end = start + size; + newArray.push(array.slice(start, end)); + } + + return newArray; +} diff --git a/modules/adrelevantisBidAdapter.js b/modules/adrelevantisBidAdapter.js index deb2bb9f45d..3c9c661b09c 100644 --- a/modules/adrelevantisBidAdapter.js +++ b/modules/adrelevantisBidAdapter.js @@ -1,6 +1,5 @@ import {Renderer} from '../src/Renderer.js'; import { - chunk, createTrackPixelHtml, deepAccess, deepClone, @@ -22,6 +21,7 @@ import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore} from '../libraries/appnexusUtils/anUtils.js'; import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const BIDDER_CODE = 'adrelevantis'; const URL = 'https://ssp.adrelevantis.com/prebid'; diff --git a/modules/adtargetBidAdapter.js b/modules/adtargetBidAdapter.js index 89ba4878acf..a1dec5a420f 100644 --- a/modules/adtargetBidAdapter.js +++ b/modules/adtargetBidAdapter.js @@ -1,8 +1,9 @@ -import {_map, chunk, deepAccess, flatten, isArray, logError, parseSizesInput} from '../src/utils.js'; +import {_map, deepAccess, flatten, isArray, logError, parseSizesInput} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {find} from '../src/polyfill.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const ENDPOINT = 'https://ghb.console.adtarget.com.tr/v2/auction/'; const BIDDER_CODE = 'adtarget'; diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index 1c74a63b019..5bb34b33159 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -1,10 +1,11 @@ -import {_map, chunk, deepAccess, flatten, isArray, parseSizesInput} from '../src/utils.js'; +import {_map, deepAccess, flatten, isArray, 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'; import {Renderer} from '../src/Renderer.js'; import {find} from '../src/polyfill.js'; import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const subdomainSuffixes = ['', 1, 2]; const AUCTION_PATH = '/v2/auction/'; diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 72d7cdc58dc..e6b3441b988 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,5 +1,4 @@ import { - chunk, createTrackPixelHtml, deepAccess, deepClone, @@ -37,6 +36,7 @@ import { } from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const BIDDER_CODE = 'appnexus'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/goldbachBidAdapter.js b/modules/goldbachBidAdapter.js index 8c2741b9828..8892df130df 100644 --- a/modules/goldbachBidAdapter.js +++ b/modules/goldbachBidAdapter.js @@ -1,6 +1,5 @@ import {Renderer} from '../src/Renderer.js'; import { - chunk, createTrackPixelHtml, deepAccess, deepClone, @@ -29,6 +28,7 @@ import {APPNEXUS_CATEGORY_MAPPING} from '../libraries/categoryTranslationMapping import {getANKeywordParam, transformBidderParamKeywords} from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const BIDDER_CODE = 'goldbach'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/mediafuseBidAdapter.js b/modules/mediafuseBidAdapter.js index 1f7ee9f8af4..1fdd3530fae 100644 --- a/modules/mediafuseBidAdapter.js +++ b/modules/mediafuseBidAdapter.js @@ -1,5 +1,4 @@ import { - chunk, createTrackPixelHtml, deepAccess, deepClone, @@ -36,6 +35,7 @@ import { } from '../libraries/appnexusUtils/anKeywords.js'; import {convertCamelToUnderscore, fill} from '../libraries/appnexusUtils/anUtils.js'; import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const BIDDER_CODE = 'mediafuse'; const URL = 'https://ib.adnxs.com/ut/v3/prebid'; diff --git a/modules/smaatoBidAdapter.js b/modules/smaatoBidAdapter.js index 73cd052aec4..b735953d099 100644 --- a/modules/smaatoBidAdapter.js +++ b/modules/smaatoBidAdapter.js @@ -1,4 +1,4 @@ -import {chunk, deepAccess, deepSetValue, getDNT, isEmpty, isNumber, logError, logInfo} from '../src/utils.js'; +import {deepAccess, deepSetValue, getDNT, isEmpty, isNumber, logError, logInfo} from '../src/utils.js'; import {find} from '../src/polyfill.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; @@ -6,6 +6,7 @@ import {ADPOD, BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import CONSTANTS from '../src/constants.json'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; import {fill} from '../libraries/appnexusUtils/anUtils.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const { NATIVE_IMAGE_TYPES } = CONSTANTS; const BIDDER_CODE = 'smaato'; diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index ba21a9c82d2..b5323181c6c 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,9 +1,10 @@ -import {_each, chunk, deepAccess, isFn, parseSizesInput, parseUrl, uniques, isArray} from '../src/utils.js'; +import {_each, deepAccess, isFn, parseSizesInput, parseUrl, uniques, isArray} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; import {bidderSettings} from '../src/bidderSettings.js'; import {config} from '../src/config.js'; +import {chunk} from '../libraries/chunk/chunk.js'; const GVLID = 744; const DEFAULT_SUB_DOMAIN = 'prebid'; diff --git a/src/utils.js b/src/utils.js index 1a6d0f41e5d..7fd1b6333ff 100644 --- a/src/utils.js +++ b/src/utils.js @@ -866,26 +866,6 @@ export function isArrayOfNums(val, size) { return (isArray(val)) && ((size) ? val.length === size : true) && (val.every(v => isInteger(v))); } -/** - * http://npm.im/chunk - * Returns an array with *size* chunks from given array - * - * Example: - * ['a', 'b', 'c', 'd', 'e'] chunked by 2 => - * [['a', 'b'], ['c', 'd'], ['e']] - */ -export function chunk(array, size) { - let newArray = []; - - for (let i = 0; i < Math.ceil(array.length / size); i++) { - let start = i * size; - let end = start + size; - newArray.push(array.slice(start, end)); - } - - return newArray; -} - export function parseQS(query) { return !query ? {} : query .replace(/^\?/, '') From 22cf7fdeb06196688751a5cce7e40ed6e7d6b649 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Wed, 6 Sep 2023 09:14:59 -0700 Subject: [PATCH 23/23] fix lint --- modules/audiencerunBidAdapter.js | 16 +++++----- modules/beopBidAdapter.js | 14 ++++----- modules/brightcomBidAdapter.js | 24 +++++++-------- modules/brightcomSSPBidAdapter.js | 20 ++++++------- modules/cadentApertureMXBidAdapter.js | 16 +++++----- modules/conversantBidAdapter.js | 28 +++++++++--------- modules/datawrkzBidAdapter.js | 14 ++++----- modules/gmosspBidAdapter.js | 14 ++++----- modules/holidBidAdapter.js | 10 +++---- modules/kueezBidAdapter.js | 22 +++++++------- modules/mediasniperBidAdapter.js | 26 ++++++++--------- modules/mgidBidAdapter.js | 28 +++++++++--------- modules/minutemediaBidAdapter.js | 22 +++++++------- modules/nextMillenniumBidAdapter.js | 22 +++++++------- modules/nextrollBidAdapter.js | 16 +++++----- modules/onomagicBidAdapter.js | 20 ++++++------- modules/optidigitalBidAdapter.js | 6 ++-- modules/otmBidAdapter.js | 18 ++++++------ modules/pubmaticAnalyticsAdapter.js | 8 ++--- modules/relaidoBidAdapter.js | 18 ++++++------ modules/riseBidAdapter.js | 22 +++++++------- modules/shinezBidAdapter.js | 22 +++++++------- modules/showheroes-bsBidAdapter.js | 10 +++---- modules/smartxBidAdapter.js | 24 +++++++-------- modules/sovrnBidAdapter.js | 16 +++++----- modules/spotxBidAdapter.js | 30 +++++++++---------- modules/visxBidAdapter.js | 11 +++---- src/adapterManager.js | 2 +- src/auction.js | 2 +- src/events.js | 6 ++-- src/native.js | 1 - src/utils.js | 42 +++++---------------------- 32 files changed, 261 insertions(+), 289 deletions(-) diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index 872dbb43e64..e716fe94c8b 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -1,12 +1,12 @@ import { - _each, - deepAccess, - formatQS, getBidIdParameter, - getValue, - isArray, - isFn, - logError, - triggerPixel, + _each, + deepAccess, + formatQS, getBidIdParameter, + getValue, + isArray, + isFn, + logError, + triggerPixel, } from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index c25c5a2e350..b6b6107ddd0 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,11 +1,11 @@ import { - buildUrl, - deepAccess, getBidIdParameter, - getValue, - isArray, - logInfo, - logWarn, - triggerPixel + buildUrl, + deepAccess, getBidIdParameter, + getValue, + isArray, + logInfo, + logWarn, + triggerPixel } from '../src/utils.js'; import {getRefererInfo} from '../src/refererDetection.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; diff --git a/modules/brightcomBidAdapter.js b/modules/brightcomBidAdapter.js index 04f8f29407b..1fa1dac4e95 100644 --- a/modules/brightcomBidAdapter.js +++ b/modules/brightcomBidAdapter.js @@ -1,16 +1,16 @@ import { - _each, - isArray, - getWindowTop, - getUniqueIdentifierStr, - deepSetValue, - logError, - logWarn, - createTrackPixelHtml, - getWindowSelf, - isFn, - isPlainObject, - getBidIdParameter + _each, + isArray, + getWindowTop, + getUniqueIdentifierStr, + deepSetValue, + logError, + logWarn, + createTrackPixelHtml, + getWindowSelf, + isFn, + isPlainObject, + getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; diff --git a/modules/brightcomSSPBidAdapter.js b/modules/brightcomSSPBidAdapter.js index 5139e3df83e..4750881da40 100644 --- a/modules/brightcomSSPBidAdapter.js +++ b/modules/brightcomSSPBidAdapter.js @@ -1,14 +1,14 @@ import { - isArray, - getWindowTop, - getUniqueIdentifierStr, - deepSetValue, - logError, - logWarn, - createTrackPixelHtml, - getWindowSelf, - isFn, - isPlainObject, getBidIdParameter, + isArray, + getWindowTop, + getUniqueIdentifierStr, + deepSetValue, + logError, + logWarn, + createTrackPixelHtml, + getWindowSelf, + isFn, + isPlainObject, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; diff --git a/modules/cadentApertureMXBidAdapter.js b/modules/cadentApertureMXBidAdapter.js index 8942c95463d..17318a38d71 100644 --- a/modules/cadentApertureMXBidAdapter.js +++ b/modules/cadentApertureMXBidAdapter.js @@ -1,12 +1,12 @@ import { - _each, - deepAccess, getBidIdParameter, - isArray, - isFn, - isPlainObject, - isStr, - logError, - logWarn + _each, + deepAccess, getBidIdParameter, + isArray, + isFn, + isPlainObject, + isStr, + logError, + logWarn } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index b04bda2d8b0..bef65a43616 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -1,18 +1,18 @@ import { - logWarn, - isStr, - deepAccess, - isArray, - deepSetValue, - isEmpty, - _each, - parseUrl, - mergeDeep, - buildUrl, - _map, - logError, - isFn, - isPlainObject, getBidIdParameter, + logWarn, + isStr, + deepAccess, + isArray, + deepSetValue, + isEmpty, + _each, + parseUrl, + mergeDeep, + buildUrl, + _map, + logError, + isFn, + isPlainObject, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; diff --git a/modules/datawrkzBidAdapter.js b/modules/datawrkzBidAdapter.js index e569c007b77..127e7893ec5 100644 --- a/modules/datawrkzBidAdapter.js +++ b/modules/datawrkzBidAdapter.js @@ -1,11 +1,11 @@ import { - deepAccess, - isArray, - getUniqueIdentifierStr, - contains, - isFn, - isPlainObject, - getBidIdParameter + deepAccess, + isArray, + getUniqueIdentifierStr, + contains, + isFn, + isPlainObject, + getBidIdParameter } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index a174bf7811a..559f9f77aaf 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -1,11 +1,11 @@ import { - createTrackPixelHtml, - deepAccess, - deepSetValue, getBidIdParameter, - getDNT, - getWindowTop, - isEmpty, - logError + createTrackPixelHtml, + deepAccess, + deepSetValue, getBidIdParameter, + getDNT, + getWindowTop, + isEmpty, + logError } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; diff --git a/modules/holidBidAdapter.js b/modules/holidBidAdapter.js index 8c791ee4ba6..fbcbb9492c7 100644 --- a/modules/holidBidAdapter.js +++ b/modules/holidBidAdapter.js @@ -1,9 +1,9 @@ import { - deepAccess, - deepSetValue, getBidIdParameter, - isStr, - logMessage, - triggerPixel, + deepAccess, + deepSetValue, getBidIdParameter, + isStr, + logMessage, + triggerPixel, } from '../src/utils.js'; import * as events from '../src/events.js'; import CONSTANTS from '../src/constants.json'; diff --git a/modules/kueezBidAdapter.js b/modules/kueezBidAdapter.js index bae181351cd..5a5536e0c1a 100644 --- a/modules/kueezBidAdapter.js +++ b/modules/kueezBidAdapter.js @@ -1,15 +1,15 @@ import { - logWarn, - logInfo, - isArray, - isFn, - deepAccess, - isEmpty, - contains, - timestamp, - triggerPixel, - isInteger, - getBidIdParameter + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; diff --git a/modules/mediasniperBidAdapter.js b/modules/mediasniperBidAdapter.js index 1c913eec929..aee5f6230b2 100644 --- a/modules/mediasniperBidAdapter.js +++ b/modules/mediasniperBidAdapter.js @@ -1,17 +1,17 @@ import { - deepAccess, - deepClone, - deepSetValue, getBidIdParameter, - inIframe, - isArray, - isEmpty, - isFn, - isNumber, - isStr, - logError, - logMessage, - logWarn, - triggerPixel, + deepAccess, + deepClone, + deepSetValue, getBidIdParameter, + inIframe, + isArray, + isEmpty, + isFn, + isNumber, + isStr, + logError, + logMessage, + logWarn, + triggerPixel, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; diff --git a/modules/mgidBidAdapter.js b/modules/mgidBidAdapter.js index 9842205d5cd..1e158236deb 100644 --- a/modules/mgidBidAdapter.js +++ b/modules/mgidBidAdapter.js @@ -1,18 +1,18 @@ import { - _each, - deepAccess, - isPlainObject, - isArray, - isStr, - logInfo, - parseUrl, - isEmpty, - triggerPixel, - logWarn, - isFn, - isNumber, - isBoolean, - isInteger, deepSetValue, getBidIdParameter, + _each, + deepAccess, + isPlainObject, + isArray, + isStr, + logInfo, + parseUrl, + isEmpty, + triggerPixel, + logWarn, + isFn, + isNumber, + isBoolean, + isInteger, deepSetValue, getBidIdParameter, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; diff --git a/modules/minutemediaBidAdapter.js b/modules/minutemediaBidAdapter.js index d426baeb519..e67534d74fe 100644 --- a/modules/minutemediaBidAdapter.js +++ b/modules/minutemediaBidAdapter.js @@ -1,15 +1,15 @@ import { - logWarn, - logInfo, - isArray, - isFn, - deepAccess, - isEmpty, - contains, - timestamp, - triggerPixel, - isInteger, - getBidIdParameter + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; diff --git a/modules/nextMillenniumBidAdapter.js b/modules/nextMillenniumBidAdapter.js index c7dc047b411..0cbe954175c 100644 --- a/modules/nextMillenniumBidAdapter.js +++ b/modules/nextMillenniumBidAdapter.js @@ -1,15 +1,15 @@ import { - _each, - createTrackPixelHtml, - deepAccess, getBidIdParameter, - getDefinedParams, - getWindowTop, - isArray, - isStr, - logMessage, - parseGPTSingleSizeArrayToRtbSize, - parseUrl, - triggerPixel, + _each, + createTrackPixelHtml, + deepAccess, getBidIdParameter, + getDefinedParams, + getWindowTop, + isArray, + isStr, + logMessage, + parseGPTSingleSizeArrayToRtbSize, + parseUrl, + triggerPixel, } from '../src/utils.js'; import CONSTANTS from '../src/constants.json'; diff --git a/modules/nextrollBidAdapter.js b/modules/nextrollBidAdapter.js index b7ac61e8473..eab174d22dd 100644 --- a/modules/nextrollBidAdapter.js +++ b/modules/nextrollBidAdapter.js @@ -1,12 +1,12 @@ import { - deepAccess, getBidIdParameter, - isArray, - isFn, - isNumber, - isPlainObject, - isStr, - parseUrl, - replaceAuctionPrice, + deepAccess, getBidIdParameter, + isArray, + isFn, + isNumber, + isPlainObject, + isStr, + parseUrl, + replaceAuctionPrice, } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; diff --git a/modules/onomagicBidAdapter.js b/modules/onomagicBidAdapter.js index 46e6aeac538..78f00153a8b 100644 --- a/modules/onomagicBidAdapter.js +++ b/modules/onomagicBidAdapter.js @@ -1,14 +1,14 @@ import { - _each, - createTrackPixelHtml, getBidIdParameter, - getUniqueIdentifierStr, - getWindowSelf, - getWindowTop, - isArray, - isFn, - isPlainObject, - logError, - logWarn + _each, + createTrackPixelHtml, getBidIdParameter, + getUniqueIdentifierStr, + getWindowSelf, + getWindowTop, + isArray, + isFn, + isPlainObject, + logError, + logWarn } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; diff --git a/modules/optidigitalBidAdapter.js b/modules/optidigitalBidAdapter.js index 1c53ea88ec8..56d6c7902d7 100755 --- a/modules/optidigitalBidAdapter.js +++ b/modules/optidigitalBidAdapter.js @@ -1,6 +1,6 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER } from '../src/mediaTypes.js'; -import { deepAccess, parseSizesInput} from '../src/utils.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {BANNER} from '../src/mediaTypes.js'; +import {deepAccess, parseSizesInput} from '../src/utils.js'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; const BIDDER_CODE = 'optidigital'; diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js index 984cd92574b..7d4049e3054 100644 --- a/modules/otmBidAdapter.js +++ b/modules/otmBidAdapter.js @@ -1,14 +1,14 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { - logInfo, - logError, - _each, - getValue, - isFn, - isPlainObject, - isArray, - isStr, - isNumber, getBidIdParameter, + logInfo, + logError, + _each, + getValue, + isFn, + isPlainObject, + isArray, + isStr, + isNumber, getBidIdParameter, } from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; diff --git a/modules/pubmaticAnalyticsAdapter.js b/modules/pubmaticAnalyticsAdapter.js index 31d6dc7fda3..07228a236e8 100755 --- a/modules/pubmaticAnalyticsAdapter.js +++ b/modules/pubmaticAnalyticsAdapter.js @@ -1,10 +1,10 @@ -import { _each, pick, logWarn, isStr, isArray, logError} from '../src/utils.js'; +import {_each, isArray, isStr, logError, logWarn, pick} from '../src/utils.js'; import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; -import { ajax } from '../src/ajax.js'; -import { config } from '../src/config.js'; -import { getGlobal } from '../src/prebidGlobal.js'; +import {ajax} from '../src/ajax.js'; +import {config} from '../src/config.js'; +import {getGlobal} from '../src/prebidGlobal.js'; import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; /// /////////// CONSTANTS ////////////// diff --git a/modules/relaidoBidAdapter.js b/modules/relaidoBidAdapter.js index 6ac882758ee..1e702d812f0 100644 --- a/modules/relaidoBidAdapter.js +++ b/modules/relaidoBidAdapter.js @@ -1,13 +1,13 @@ import { - deepAccess, - logWarn, - parseQueryStringParameters, - triggerPixel, - generateUUID, - isArray, - isNumber, - parseSizesInput, - getBidIdParameter + deepAccess, + logWarn, + parseQueryStringParameters, + triggerPixel, + generateUUID, + isArray, + isNumber, + parseSizesInput, + getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; diff --git a/modules/riseBidAdapter.js b/modules/riseBidAdapter.js index 4cb24086234..78740f7f87d 100644 --- a/modules/riseBidAdapter.js +++ b/modules/riseBidAdapter.js @@ -1,15 +1,15 @@ import { - logWarn, - logInfo, - isArray, - isFn, - deepAccess, - isEmpty, - contains, - timestamp, - triggerPixel, - isInteger, - getBidIdParameter + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; diff --git a/modules/shinezBidAdapter.js b/modules/shinezBidAdapter.js index 1dd9fbb650b..47fca317de2 100644 --- a/modules/shinezBidAdapter.js +++ b/modules/shinezBidAdapter.js @@ -1,15 +1,15 @@ import { - logWarn, - logInfo, - isArray, - isFn, - deepAccess, - isEmpty, - contains, - timestamp, - triggerPixel, - isInteger, - getBidIdParameter + logWarn, + logInfo, + isArray, + isFn, + deepAccess, + isEmpty, + contains, + timestamp, + triggerPixel, + isInteger, + getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; diff --git a/modules/showheroes-bsBidAdapter.js b/modules/showheroes-bsBidAdapter.js index db5fc0708c1..a1e7df49d18 100644 --- a/modules/showheroes-bsBidAdapter.js +++ b/modules/showheroes-bsBidAdapter.js @@ -1,9 +1,9 @@ import { - deepAccess, - getWindowTop, - triggerPixel, - logInfo, - logError, getBidIdParameter + deepAccess, + getWindowTop, + triggerPixel, + logInfo, + logError, getBidIdParameter } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; diff --git a/modules/smartxBidAdapter.js b/modules/smartxBidAdapter.js index 0f448e86dc1..45cc45192ef 100644 --- a/modules/smartxBidAdapter.js +++ b/modules/smartxBidAdapter.js @@ -1,16 +1,16 @@ import { - logError, - deepAccess, - isArray, - getDNT, - generateUUID, - isEmpty, - _each, - logMessage, - logWarn, - isFn, - isPlainObject, - getBidIdParameter + logError, + deepAccess, + isArray, + getDNT, + generateUUID, + isEmpty, + _each, + logMessage, + logWarn, + isFn, + isPlainObject, + getBidIdParameter } from '../src/utils.js'; import { Renderer diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 4a5725a3947..79481b81936 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,12 +1,12 @@ import { - _each, - isArray, - getUniqueIdentifierStr, - deepSetValue, - logError, - deepAccess, - isInteger, - logWarn, getBidIdParameter + _each, + isArray, + getUniqueIdentifierStr, + deepSetValue, + logError, + deepAccess, + isInteger, + logWarn, getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { diff --git a/modules/spotxBidAdapter.js b/modules/spotxBidAdapter.js index c7bd8e9da93..017544cc596 100644 --- a/modules/spotxBidAdapter.js +++ b/modules/spotxBidAdapter.js @@ -1,19 +1,19 @@ import { - logError, - deepAccess, - isArray, - getDNT, - deepSetValue, - isEmpty, - _each, - logMessage, - logWarn, - isBoolean, - isNumber, - isPlainObject, - isFn, - setScriptAttributes, - getBidIdParameter + logError, + deepAccess, + isArray, + getDNT, + deepSetValue, + isEmpty, + _each, + logMessage, + logWarn, + isBoolean, + isNumber, + isPlainObject, + isFn, + setScriptAttributes, + getBidIdParameter } from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; diff --git a/modules/visxBidAdapter.js b/modules/visxBidAdapter.js index 6c588335aa0..a45a1db9ece 100644 --- a/modules/visxBidAdapter.js +++ b/modules/visxBidAdapter.js @@ -1,10 +1,11 @@ -import { triggerPixel, parseSizesInput, deepAccess, logError} from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { config } from '../src/config.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import { INSTREAM as VIDEO_INSTREAM } from '../src/video.js'; +import {deepAccess, logError, parseSizesInput, triggerPixel} from '../src/utils.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {config} from '../src/config.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {INSTREAM as VIDEO_INSTREAM} from '../src/video.js'; import {getStorageManager} from '../src/storageManager.js'; import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; + const BIDDER_CODE = 'visx'; const GVLID = 154; const BASE_URL = 'https://t.visx.net'; diff --git a/src/adapterManager.js b/src/adapterManager.js index 84942e2ed02..c007207742b 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -29,7 +29,7 @@ import {hook} from './hook.js'; import {find, includes} from './polyfill.js'; import {adunitCounter} from './adUnits.js'; import {getRefererInfo} from './refererDetection.js'; -import {GDPR_GVLIDS, gdprDataHandler, gppDataHandler, uspDataHandler,} from './consentHandler.js'; +import {GDPR_GVLIDS, gdprDataHandler, gppDataHandler, uspDataHandler, } from './consentHandler.js'; import * as events from './events.js'; import CONSTANTS from './constants.json'; import {useMetrics} from './utils/perfMetrics.js'; diff --git a/src/auction.js b/src/auction.js index c32655e1bde..0959c3f5693 100644 --- a/src/auction.js +++ b/src/auction.js @@ -957,7 +957,7 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]; custBidObj.size = custBidObj.getSize(); - targeting?.forEach(function (kvPair) { + (targeting || []).forEach(function (kvPair) { var key = kvPair.key; var value = kvPair.val; diff --git a/src/events.js b/src/events.js index d7d2c1ac08a..5bb282f4735 100644 --- a/src/events.js +++ b/src/events.js @@ -58,7 +58,7 @@ const _public = (function () { push.apply(callbacks, event.que); /** call each of the callbacks */ - callbacks?.forEach(function (fn) { + (callbacks || []).forEach(function (fn) { if (!fn) return; try { fn.apply(null, args); @@ -107,14 +107,14 @@ const _public = (function () { } if (id) { - event[id].que?.forEach(function (_handler) { + (event[id].que || []).forEach(function (_handler) { var que = event[id].que; if (_handler === handler) { que.splice(que.indexOf(_handler), 1); } }); } else { - event.que?.forEach(function (_handler) { + (event.que || []).forEach(function (_handler) { var que = event.que; if (_handler === handler) { que.splice(que.indexOf(_handler), 1); diff --git a/src/native.js b/src/native.js index 12d6dc0d623..c4709dd77e2 100644 --- a/src/native.js +++ b/src/native.js @@ -1,7 +1,6 @@ import { deepAccess, deepClone, - getKeyByValue, insertHtmlIntoIframe, isArray, isBoolean, diff --git a/src/utils.js b/src/utils.js index 7fd1b6333ff..14f310c1dfb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -134,41 +134,17 @@ export function transformAdServerTargetingObj(targeting) { * @return {Array.} Array of strings like `["300x250"]` or `["300x250", "728x90"]` */ export function parseSizesInput(sizeObj) { - var parsedSizes = []; - - // if a string for now we can assume it is a single size, like "300x250" if (typeof sizeObj === 'string') { // multiple sizes will be comma-separated - var sizes = sizeObj.split(','); - - // regular expression to match strigns like 300x250 - // start of line, at least 1 number, an "x" , then at least 1 number, and the then end of the line - var sizeRegex = /^(\d)+x(\d)+$/i; - if (sizes) { - for (const size of sizes) { - if (size.match(sizeRegex)) { - parsedSizes.push(size); - } - } - } + return sizeObj.split(',').filter(sz => sz.match(/^(\d)+x(\d)+$/i)) } else if (typeof sizeObj === 'object') { - var sizeArrayLength = sizeObj.length; - - // don't process empty array - if (sizeArrayLength > 0) { - // if we are a 2 item array of 2 numbers, we must be a SingleSize array - if (sizeArrayLength === 2 && typeof sizeObj[0] === 'number' && typeof sizeObj[1] === 'number') { - parsedSizes.push(parseGPTSingleSizeArray(sizeObj)); - } else { - // otherwise, we must be a MultiSize array - for (var i = 0; i < sizeArrayLength; i++) { - parsedSizes.push(parseGPTSingleSizeArray(sizeObj[i])); - } - } + if (sizeObj.length === 2 && typeof sizeObj[0] === 'number' && typeof sizeObj[1] === 'number') { + return [parseGPTSingleSizeArray(sizeObj)]; + } else { + return sizeObj.map(parseGPTSingleSizeArray) } } - - return parsedSizes; + return []; } // Parse a GPT style single size array, (i.e [300, 250]) @@ -1066,9 +1042,5 @@ export function memoize(fn, key = function (arg) { return arg; }) { * @param {object} attributes */ export function setScriptAttributes(script, attributes) { - for (let key in attributes) { - if (attributes.hasOwnProperty(key)) { - script.setAttribute(key, attributes[key]); - } - } + Object.entries(attributes).forEach(([k, v]) => script.setAttribute(k, v)) }