Skip to content
Open
Show file tree
Hide file tree
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
50 changes: 46 additions & 4 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').ServerRequest} ServerRequest
* @typedef {import('../src/adapters/bidderFactory.js').UserSync} UserSync
* @typedef {import('../src/types/ortb/ext/dsa.d.ts').DSARequest} DSARequest
*/

const VIDEO_PARAMS = ['pos', 'context', 'placement', 'plcmt', 'api', 'mimes', 'protocols', 'playbackmethod', 'minduration', 'maxduration',
Expand Down Expand Up @@ -124,9 +125,10 @@
'zoneId' in bidRequest.params &&
!isNaN(Number(bidRequest.params.zoneId)) &&
bidRequest.params.zoneId > 0 &&
bidRequest.mediaTypes &&
(bidRequest.mediaTypes.banner || bidRequest.mediaTypes.video ||
(bidRequest.mediaTypes.native && validateNativeAdUnit(bidRequest.mediaTypes.native))
(
isPlainObject(bidRequest?.mediaTypes?.banner) ||
isPlainObject(bidRequest?.mediaTypes?.video) ||
(isPlainObject(bidRequest?.mediaTypes?.native) && validateNativeAdUnit(bidRequest.mediaTypes.native))
);
},

Expand Down Expand Up @@ -224,6 +226,9 @@
if (isStr(rtbBid.ext.agency_name)) {
deepSetValue(prBid, 'meta.agencyName', rtbBid.ext.agency_name);
}
if (isPlainObject(rtbBid.ext.dsa)) {
deepSetValue(prBid, 'meta.dsa', rtbBid.ext.dsa);
Comment thread
ckbo3hrk marked this conversation as resolved.
}
}

return prBid;
Expand Down Expand Up @@ -332,9 +337,9 @@
if (pbVideo.playerSize) {
sizes = pbVideo.playerSize[0];
typedImp.video = Object.assign(typedImp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {});
} else if (pbVideo.w && pbVideo.h) {
typedImp.video.w = pbVideo.w;
typedImp.video.h = pbVideo.h;

Check warning on line 342 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

340-342 lines are not covered with tests
}
initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : VIDEO);
result.push(typedImp);
Expand All @@ -342,8 +347,8 @@

if (mediaTypes?.native) {
if (isMultiformat) {
typedImp = { ...imp };
typedImp.id = typedImp.id + MULTI_FORMAT_SUFFIX_NATIVE;

Check warning on line 351 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

350-351 lines are not covered with tests
} else {
typedImp = imp;
}
Expand Down Expand Up @@ -431,7 +436,7 @@
if (isEmpty(appConfig)) {
return { site: createSite(refererInfo, fpd) };
} else {
return { app: appConfig };

Check warning on line 439 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

439 line is not covered with tests
}
}

Expand Down Expand Up @@ -499,10 +504,10 @@
'tmax': parseInt(bidderRequest.timeout)
};
if (!isEmpty(fpd.bcat)) {
request.bcat = fpd.bcat;

Check warning on line 507 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

507 line is not covered with tests
}
if (!isEmpty(fpd.badv)) {
request.badv = fpd.badv;

Check warning on line 510 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

510 line is not covered with tests
}
return request;
}
Expand All @@ -521,6 +526,42 @@
}
}

/**
* Initialize DSA request
* @param fpd {Object}
*/
function makeDSARequest(fpd) {
/**
* @type {DSARequest}
*/
const pubDsa = fpd?.regs?.ext?.dsa;
if (!isPlainObject(pubDsa)) {
return;
}
const dsaObj = {};
['dsarequired', 'pubrender', 'datatopub'].forEach((dsaKey) => {
if (isNumber(pubDsa[dsaKey])) {
dsaObj[dsaKey] = pubDsa[dsaKey];
}
});
if (isArray(pubDsa.transparency) && pubDsa.transparency.every((v) => isPlainObject(v))) {
const tpData = [];
pubDsa.transparency.forEach((tpObj) => {
if (isStr(tpObj.domain) && tpObj.domain !== '' && isArray(tpObj.dsaparams) && tpObj.dsaparams.every((v) => isNumber(v))) {
tpData.push(tpObj);
}
});
if (tpData.length > 0) {
dsaObj.transparency = tpData;
}
}
if (!isEmpty(dsaObj)) {
let res = {};
deepSetValue(res, 'regs.ext.dsa', dsaObj);
return res;
}
}

/**
* Builds complete rtb request
* @param imps {Object} Collection of rtb impressions
Expand All @@ -537,10 +578,11 @@
makeSiteOrApp(bidderRequest, fpd),
makeUser(bidderRequest, fpd),
makeRegulations(bidderRequest),
makeSyncInfo(bidderRequest)
makeSyncInfo(bidderRequest),
makeDSARequest(fpd)
);
if (schain) {
deepSetValue(req, 'source.ext.schain', schain);

Check warning on line 585 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

585 line is not covered with tests
}
return req;
}
Expand All @@ -564,7 +606,7 @@
};
mergeDeep(site, fpd.site);
if (refInfo.ref != null) {
site.ref = refInfo.ref;

Check warning on line 609 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

609 line is not covered with tests
} else {
delete site.ref;
}
Expand Down Expand Up @@ -594,7 +636,7 @@
* Basic validates to comply with platform requirements
*/
function validateNativeAdUnit(adUnit) {
return validateNativeImageSize(adUnit.image) && validateNativeImageSize(adUnit.icon) &&

Check warning on line 639 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

639 line is not covered with tests
!deepAccess(adUnit, 'privacyLink.required') && // not supported yet
!deepAccess(adUnit, 'privacyIcon.required'); // not supported yet
}
Expand All @@ -603,11 +645,11 @@
* Validates image asset size definition
*/
function validateNativeImageSize(img) {
if (!img) {
return true;

Check warning on line 649 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

648-649 lines are not covered with tests
}
if (img.sizes) {
return isArrayOfNums(img.sizes, 2);

Check warning on line 652 in modules/adkernelBidAdapter.js

View workflow job for this annotation

GitHub Actions / Coverage

651-652 lines are not covered with tests
}
if (isArray(img.aspect_ratios)) {
return img.aspect_ratios.length > 0 && img.aspect_ratios[0].min_height && img.aspect_ratios[0].min_width;
Expand Down
Loading
Loading