Skip to content

Commit c902d6c

Browse files
lksharmaLove Sharma
andauthored
chore: code cleanup [PB-2828] (#11468)
Co-authored-by: Love Sharma <[email protected]>
1 parent 3c4ebab commit c902d6c

File tree

2 files changed

+8
-319
lines changed

2 files changed

+8
-319
lines changed

modules/ixBidAdapter.js

Lines changed: 7 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ import {
1818
} from '../src/utils.js';
1919
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
2020
import { config } from '../src/config.js';
21-
import { EVENTS } from '../src/constants.js';
2221
import { getStorageManager } from '../src/storageManager.js';
23-
import * as events from '../src/events.js';
2422
import { find } from '../src/polyfill.js';
2523
import { registerBidder } from '../src/adapters/bidderFactory.js';
2624
import { INSTREAM, OUTSTREAM } from '../src/video.js';
2725
import { Renderer } from '../src/Renderer.js';
2826
import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js';
29-
import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js';
3027

3128
const BIDDER_CODE = 'ix';
3229
const ALIAS_BIDDER_CODE = 'roundel';
@@ -49,17 +46,6 @@ const PRICE_TO_DOLLAR_FACTOR = {
4946
const IFRAME_USER_SYNC_URL = 'https://js-sec.indexww.com/um/ixmatch.html';
5047
const FLOOR_SOURCE = { PBJS: 'p', IX: 'x' };
5148
const IMG_USER_SYNC_URL = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid';
52-
export const ERROR_CODES = {
53-
BID_SIZE_INVALID_FORMAT: 1,
54-
BID_SIZE_NOT_INCLUDED: 2,
55-
PROPERTY_NOT_INCLUDED: 3,
56-
SITE_ID_INVALID_VALUE: 4,
57-
BID_FLOOR_INVALID_FORMAT: 5,
58-
IX_FPD_EXCEEDS_MAX_SIZE: 6,
59-
EXCEEDS_MAX_SIZE: 7,
60-
PB_FPD_EXCEEDS_MAX_SIZE: 8,
61-
VIDEO_DURATION_INVALID: 9
62-
};
6349
const FIRST_PARTY_DATA = {
6450
SITE: [
6551
'id', 'name', 'domain', 'cat', 'sectioncat', 'pagecat', 'page', 'ref', 'search', 'mobile',
@@ -110,7 +96,6 @@ const VIDEO_PARAMS_ALLOW_LIST = [
11096
];
11197
const LOCAL_STORAGE_KEY = 'ixdiag';
11298
export const LOCAL_STORAGE_FEATURE_TOGGLES_KEY = `${BIDDER_CODE}_features`;
113-
let hasRegisteredHandler = false;
11499
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
115100
export const FEATURE_TOGGLES = {
116101
// Update with list of CFTs to be requested from Exchange
@@ -262,8 +247,7 @@ export function bidToVideoImp(bid) {
262247

263248
if (imp.video.minduration > imp.video.maxduration) {
264249
logError(
265-
`IX Bid Adapter: video minduration [${imp.video.minduration}] cannot be greater than video maxduration [${imp.video.maxduration}]`,
266-
{ bidder: BIDDER_CODE, code: ERROR_CODES.VIDEO_DURATION_INVALID }
250+
`IX Bid Adapter: video minduration [${imp.video.minduration}] cannot be greater than video maxduration [${imp.video.maxduration}]`
267251
);
268252
return {};
269253
}
@@ -883,13 +867,6 @@ function enrichRequest(r, bidderRequest, impressions, validBidRequests, userEids
883867
r.ext.ixdiag.syncsPerBidder = config.getConfig('userSync').syncsPerBidder;
884868
}
885869

886-
// Get cached errors stored in LocalStorage
887-
const cachedErrors = getCachedErrors();
888-
889-
if (!isEmpty(cachedErrors)) {
890-
r.ext.ixdiag.err = cachedErrors;
891-
}
892-
893870
// Add number of available imps to ixDiag.
894871
r.ext.ixdiag.imps = Object.keys(impressions).length;
895872

@@ -1546,104 +1523,6 @@ function createMissingBannerImp(bid, imp, newSize) {
15461523
return newImp;
15471524
}
15481525

1549-
/**
1550-
* @typedef {Array[message: string, err: Object<bidder: string, code: number>]} ErrorData
1551-
* @property {string} message - The error message.
1552-
* @property {object} err - The error object.
1553-
* @property {string} err.bidder - The bidder of the error.
1554-
* @property {string} err.code - The error code.
1555-
*/
1556-
1557-
/**
1558-
* Error Event handler that receives type and arguments in a data object.
1559-
*
1560-
* @param {ErrorData} data
1561-
*/
1562-
function storeErrorEventData(data) {
1563-
if (!storage.localStorageIsEnabled()) {
1564-
return;
1565-
}
1566-
1567-
let currentStorage;
1568-
1569-
try {
1570-
currentStorage = JSON.parse(storage.getDataFromLocalStorage(LOCAL_STORAGE_KEY) || '{}');
1571-
} catch (e) {
1572-
logWarn('ix can not read ixdiag from localStorage.');
1573-
}
1574-
1575-
const todayDate = new Date();
1576-
1577-
Object.keys(currentStorage).map((errorDate) => {
1578-
const date = new Date(errorDate);
1579-
1580-
if (date.setDate(date.getDate() + 7) - todayDate < 0) {
1581-
delete currentStorage[errorDate];
1582-
}
1583-
});
1584-
1585-
if (data.type === 'ERROR' && data.arguments && data.arguments[1] && data.arguments[1].bidder === BIDDER_CODE) {
1586-
const todayString = todayDate.toISOString().slice(0, 10);
1587-
1588-
const errorCode = data.arguments[1].code;
1589-
1590-
if (errorCode) {
1591-
currentStorage[todayString] = currentStorage[todayString] || {};
1592-
1593-
if (!Number(currentStorage[todayString][errorCode])) {
1594-
currentStorage[todayString][errorCode] = 0;
1595-
}
1596-
1597-
currentStorage[todayString][errorCode]++;
1598-
};
1599-
}
1600-
1601-
storage.setDataInLocalStorage(LOCAL_STORAGE_KEY, JSON.stringify(currentStorage));
1602-
}
1603-
1604-
/**
1605-
* Event handler for storing data into local storage. It will only store data if
1606-
* local storage premissions are avaliable
1607-
*/
1608-
function localStorageHandler(data) {
1609-
if (data.type === 'ERROR' && data.arguments && data.arguments[1] && data.arguments[1].bidder === BIDDER_CODE) {
1610-
storeErrorEventData(data);
1611-
}
1612-
}
1613-
1614-
/**
1615-
* Get ixdiag stored in LocalStorage and format to be added to request payload
1616-
*
1617-
* @returns {Object} Object with error codes and counts
1618-
*/
1619-
function getCachedErrors() {
1620-
if (!storage.localStorageIsEnabled()) {
1621-
return;
1622-
}
1623-
1624-
const errors = {};
1625-
let currentStorage;
1626-
1627-
try {
1628-
currentStorage = JSON.parse(storage.getDataFromLocalStorage(LOCAL_STORAGE_KEY) || '{}');
1629-
} catch (e) {
1630-
logError('ix can not read ixdiag from localStorage.');
1631-
return null;
1632-
}
1633-
1634-
Object.keys(currentStorage).forEach((date) => {
1635-
Object.keys(currentStorage[date]).forEach((code) => {
1636-
if (typeof currentStorage[date][code] === 'number') {
1637-
errors[code] = errors[code]
1638-
? errors[code] + currentStorage[date][code]
1639-
: currentStorage[date][code];
1640-
}
1641-
});
1642-
});
1643-
1644-
return errors;
1645-
}
1646-
16471526
/**
16481527
*
16491528
* Initialize IX Outstream Renderer
@@ -1738,12 +1617,6 @@ export const spec = {
17381617
* @return {boolean} True if this is a valid bid, and false otherwise.
17391618
*/
17401619
isBidRequestValid: function (bid) {
1741-
if (!hasRegisteredHandler) {
1742-
events.on(EVENTS.AUCTION_DEBUG, localStorageHandler);
1743-
events.on(EVENTS.AD_RENDER_FAILED, localStorageHandler);
1744-
hasRegisteredHandler = true;
1745-
}
1746-
17471620
const paramsVideoRef = deepAccess(bid, 'params.video');
17481621
const paramsSize = deepAccess(bid, 'params.size');
17491622
const mediaTypeBannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes');
@@ -1765,14 +1638,14 @@ export const spec = {
17651638
// since there is an ix bidder level size, make sure its valid
17661639
const ixSize = getFirstSize(paramsSize);
17671640
if (!ixSize) {
1768-
logError('IX Bid Adapter: size has invalid format.', { bidder: BIDDER_CODE, code: ERROR_CODES.BID_SIZE_INVALID_FORMAT });
1641+
logError('IX Bid Adapter: size has invalid format.');
17691642
return false;
17701643
}
17711644
// check if the ix bidder level size, is present in ad unit level
17721645
if (!includesSize(bid.sizes, ixSize) &&
17731646
!(includesSize(mediaTypeVideoPlayerSize, ixSize)) &&
17741647
!(includesSize(mediaTypeBannerSizes, ixSize))) {
1775-
logError('IX Bid Adapter: bid size is not included in ad unit sizes or player size.', { bidder: BIDDER_CODE, code: ERROR_CODES.BID_SIZE_NOT_INCLUDED });
1648+
logError('IX Bid Adapter: bid size is not included in ad unit sizes or player size.');
17761649
return false;
17771650
}
17781651
}
@@ -1784,19 +1657,19 @@ export const spec = {
17841657

17851658
if (bid.params.siteId !== undefined) {
17861659
if (typeof bid.params.siteId !== 'string' && typeof bid.params.siteId !== 'number') {
1787-
logError('IX Bid Adapter: siteId must be string or number type.', { bidder: BIDDER_CODE, code: ERROR_CODES.SITE_ID_INVALID_VALUE });
1660+
logError('IX Bid Adapter: siteId must be string or number type.');
17881661
return false;
17891662
}
17901663

17911664
if (typeof bid.params.siteId !== 'string' && isNaN(Number(bid.params.siteId))) {
1792-
logError('IX Bid Adapter: siteId must valid value', { bidder: BIDDER_CODE, code: ERROR_CODES.SITE_ID_INVALID_VALUE });
1665+
logError('IX Bid Adapter: siteId must valid value');
17931666
return false;
17941667
}
17951668
}
17961669

17971670
if (hasBidFloor || hasBidFloorCur) {
17981671
if (!(hasBidFloor && hasBidFloorCur && isValidBidFloorParams(bid.params.bidFloor, bid.params.bidFloorCur))) {
1799-
logError('IX Bid Adapter: bidFloor / bidFloorCur parameter has invalid format.', { bidder: BIDDER_CODE, code: ERROR_CODES.BID_FLOOR_INVALID_FORMAT });
1672+
logError('IX Bid Adapter: bidFloor / bidFloorCur parameter has invalid format.');
18001673
return false;
18011674
}
18021675
}
@@ -1815,7 +1688,7 @@ export const spec = {
18151688

18161689
if (errorList.length) {
18171690
errorList.forEach((err) => {
1818-
logError(err, { bidder: BIDDER_CODE, code: ERROR_CODES.PROPERTY_NOT_INCLUDED });
1691+
logError(err);
18191692
});
18201693
return false;
18211694
}
@@ -1997,18 +1870,6 @@ export const spec = {
19971870
}
19981871
},
19991872

2000-
/**
2001-
* Covert bid param types for S2S
2002-
* @param {Object} params bid params
2003-
* @param {Boolean} isOpenRtb boolean to check openrtb2 protocol
2004-
* @return {Object} params bid params
2005-
*/
2006-
transformBidParams: function (params, isOpenRtb) {
2007-
return convertTypes({
2008-
'siteID': 'number'
2009-
}, params);
2010-
},
2011-
20121873
/**
20131874
* Determine which user syncs should occur
20141875
* @param {object} syncOptions

0 commit comments

Comments
 (0)