Skip to content

Commit

Permalink
AdUp Technology bid adapter: avoid modification of bid request
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenAnders committed Mar 13, 2023
1 parent 7a75340 commit a9df947
Showing 1 changed file with 41 additions and 37 deletions.
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

0 comments on commit a9df947

Please sign in to comment.