Skip to content

Commit

Permalink
Use optional chaining
Browse files Browse the repository at this point in the history
Adding these changes back after review discovered the missing optional chain which was causing test failure in a previous commit.
  • Loading branch information
gwhigs committed Dec 5, 2024
1 parent 35610a7 commit 9b21ad1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/native.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
deepAccess,
deepClone, getDefinedParams,
insertHtmlIntoIframe,
isArray,
Expand Down Expand Up @@ -373,25 +372,25 @@ export function getNativeTargeting(bid, {index = auctionManager.index} = {}) {

Object.keys(flatBidNativeKeys).forEach(asset => {
const key = nativeKeys[asset];
let value = getAssetValue(bid.native[asset]) || getAssetValue(deepAccess(bid, `native.ext.${asset}`));
let value = getAssetValue(bid.native[asset]) || getAssetValue(bid?.native?.ext?.[asset]);

if (asset === 'adTemplate' || !key || !value) {
return;
}

let sendPlaceholder = deepAccess(adUnit, `nativeParams.${asset}.sendId`);
let sendPlaceholder = adUnit?.nativeParams?.[asset]?.sendId;
if (typeof sendPlaceholder !== 'boolean') {
sendPlaceholder = deepAccess(adUnit, `nativeParams.ext.${asset}.sendId`);
sendPlaceholder = adUnit?.nativeParams?.ext?.[asset]?.sendId;
}

if (sendPlaceholder) {
const placeholder = `${key}:${bid.adId}`;
value = placeholder;
}

let assetSendTargetingKeys = deepAccess(adUnit, `nativeParams.${asset}.sendTargetingKeys`);
let assetSendTargetingKeys = adUnit?.nativeParams?.[asset]?.sendTargetingKeys;
if (typeof assetSendTargetingKeys !== 'boolean') {
assetSendTargetingKeys = deepAccess(adUnit, `nativeParams.ext.${asset}.sendTargetingKeys`);
assetSendTargetingKeys = adUnit?.nativeParams?.ext?.[asset]?.sendTargetingKeys;
}

const sendTargeting = typeof assetSendTargetingKeys === 'boolean' ? assetSendTargetingKeys : globalSendTargetingKeys;
Expand Down

0 comments on commit 9b21ad1

Please sign in to comment.