Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdUp Technology Bid Adapter: use deepClone to avoid modification of bid request #9656

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions modules/aduptechBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getAdUnitSizes, isArray, isBoolean, isEmpty, isFn, isPlainObject} from '../src/utils.js';
import {deepClone, getAdUnitSizes, 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';
Expand All @@ -20,14 +20,14 @@ export const internal = {
* @returns {null|Object.<string, string|boolean>}
*/
extractGdpr: (bidderRequest) => {
if (bidderRequest && bidderRequest.gdprConsent) {
return {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: (isBoolean(bidderRequest.gdprConsent.gdprApplies)) ? bidderRequest.gdprConsent.gdprApplies : true
};
if (!bidderRequest?.gdprConsent) {
return null;
}

return null;
return {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: (isBoolean(bidderRequest.gdprConsent.gdprApplies)) ? bidderRequest.gdprConsent.gdprApplies : true
};
},

/**
Expand Down Expand Up @@ -59,30 +59,34 @@ export const internal = {
* @returns {null|Object.<string, *>}
*/
extractBannerConfig: (bidRequest) => {
const sizes = getAdUnitSizes(bidRequest);
if (isArray(sizes) && !isEmpty(sizes)) {
const banner = { sizes: sizes };
const adUnitSizes = getAdUnitSizes(bidRequest);
if (!isArray(adUnitSizes) || isEmpty(adUnitSizes)) {
return null;
}

// try to add floor for each banner size
banner.sizes.forEach(size => {
const floor = internal.getFloor(bidRequest, { mediaType: BANNER, size });
if (floor) {
size.push(floor.floor);
size.push(floor.currency);
}
});
const banner = { sizes: [] };

// try to add default floor for banner
const floor = internal.getFloor(bidRequest, { mediaType: BANNER, size: '*' });
adUnitSizes.forEach(adUnitSize => {
const size = deepClone(adUnitSize);

// try to add floor for each banner size
const floor = internal.getFloor(bidRequest, { mediaType: BANNER, size: adUnitSize });
if (floor) {
banner.floorPrice = floor.floor;
banner.floorCurrency = floor.currency;
size.push(floor.floor);
size.push(floor.currency);
}

return banner;
banner.sizes.push(size);
});

// try to add default floor for banner
const floor = internal.getFloor(bidRequest, { mediaType: BANNER, size: '*' });
if (floor) {
banner.floorPrice = floor.floor;
banner.floorCurrency = floor.currency;
}

return null;
return banner;
},

/**
Expand All @@ -92,20 +96,20 @@ export const internal = {
* @returns {null|Object.<string, *>}
*/
extractNativeConfig: (bidRequest) => {
if (bidRequest?.mediaTypes?.native) {
const native = bidRequest.mediaTypes.native;
if (!bidRequest?.mediaTypes?.native) {
return null;
}

// try to add default floor for native
const floor = internal.getFloor(bidRequest, { mediaType: NATIVE, size: '*' });
if (floor) {
native.floorPrice = floor.floor;
native.floorCurrency = floor.currency;
}
const native = deepClone(bidRequest.mediaTypes.native);

return native;
// try to add default floor for native
const floor = internal.getFloor(bidRequest, { mediaType: NATIVE, size: '*' });
if (floor) {
native.floorPrice = floor.floor;
native.floorCurrency = floor.currency;
}

return null;
return native;
},

/**
Expand All @@ -115,11 +119,11 @@ export const internal = {
* @returns {null|Object.<string, *>}
*/
extractParams: (bidRequest) => {
if (bidRequest && bidRequest.params) {
return bidRequest.params
if (!bidRequest?.params) {
return null;
}

return null;
return deepClone(bidRequest.params);
},

/**
Expand Down