Skip to content

Commit

Permalink
Merge pull request #17 from pm-nitin-shirsat/UOE-10758
Browse files Browse the repository at this point in the history
Update master with latest
  • Loading branch information
pm-nitin-shirsat authored Jul 4, 2024
2 parents 6cfb9be + 11e3c90 commit ba054e9
Show file tree
Hide file tree
Showing 111 changed files with 7,174 additions and 7,145 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = {
'no-useless-escape': 'off',
'no-console': 'error',
'jsdoc/check-types': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/newline-after-description': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',
Expand Down Expand Up @@ -96,7 +97,7 @@ module.exports = {
// code in other packages (such as plugins/eslint) is not "seen" by babel and its parser will complain.
files: 'plugins/*/**/*.js',
parser: 'esprima'
},
},
{
files: '**BidAdapter.js',
rules: {
Expand Down
3 changes: 2 additions & 1 deletion creative/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line prebid/validate-imports
import { AD_RENDER_FAILED_REASON, EVENTS, MESSAGES } from '../src/constants.js';
import {AD_RENDER_FAILED_REASON, EVENTS, MESSAGES} from '../src/constants.js';

export {PB_LOCATOR} from '../src/constants.js';
export const MESSAGE_REQUEST = MESSAGES.REQUEST;
export const MESSAGE_RESPONSE = MESSAGES.RESPONSE;
export const MESSAGE_EVENT = MESSAGES.EVENT;
Expand Down
20 changes: 16 additions & 4 deletions creative/crossDomain.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
ERROR_EXCEPTION,
EVENT_AD_RENDER_FAILED, EVENT_AD_RENDER_SUCCEEDED,
EVENT_AD_RENDER_FAILED,
EVENT_AD_RENDER_SUCCEEDED,
MESSAGE_EVENT,
MESSAGE_REQUEST,
MESSAGE_RESPONSE
MESSAGE_RESPONSE,
PB_LOCATOR
} from './constants.js';

const mkFrame = (() => {
Expand All @@ -24,14 +26,24 @@ const mkFrame = (() => {
};
})();

function isPrebidWindow(win) {
return !!win.frames[PB_LOCATOR];
}

export function renderer(win) {
let target = win.parent;
while (target !== win.top && !isPrebidWindow(target)) {
target = target.parent;
}
if (!isPrebidWindow(target)) target = win.parent;

return function ({adId, pubUrl, clickUrl}) {
const pubDomain = new URL(pubUrl, window.location).origin;

function sendMessage(type, payload, responseListener) {
const channel = new MessageChannel();
channel.port1.onmessage = guard(responseListener);
win.parent.postMessage(JSON.stringify(Object.assign({message: type, adId}, payload)), pubDomain, [channel.port2]);
target.postMessage(JSON.stringify(Object.assign({message: type, adId}, payload)), pubDomain, [channel.port2]);
}

function onError(e) {
Expand Down Expand Up @@ -77,7 +89,7 @@ export function renderer(win) {
W.Promise.resolve(W.render(data, {sendMessage, mkFrame}, win)).then(
() => sendMessage(MESSAGE_EVENT, {event: EVENT_AD_RENDER_SUCCEEDED}),
onError
)
);
});
win.document.body.appendChild(renderer);
}
Expand Down
2 changes: 1 addition & 1 deletion integrationExamples/gpt/x-domain/creative.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// creative will be rendered, e.g. GAM delivering a SafeFrame

// this code is autogenerated, also available in 'build/creative/creative.js'
<script>!function(){"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();var t;window.pbRender=(t=window,function({adId:r,pubUrl:s,clickUrl:o}){const i=new URL(s,window.location).origin;function a(e,n,s){const o=new MessageChannel;o.port1.onmessage=d(s),t.parent.postMessage(JSON.stringify(Object.assign({message:e,adId:r},n)),i,[o.port2])}function c(n){a(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function d(e){return function(){try{return e.apply(this,arguments)}catch(e){c(e)}}}a("Prebid Request",{options:{clickUrl:o}},(function(s){let o;try{o=JSON.parse(s.data)}catch(e){return}if("Prebid Response"===o.message&&o.adId===r){const r=n(t.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${o.renderer}<\/script>`});r.onload=d((function(){const s=r.contentWindow;s.Promise.resolve(s.render(o,{sendMessage:a,mkFrame:n},t)).then((()=>a(e,{event:"adRenderSucceeded"})),c)})),t.document.body.appendChild(r)}}))})}();</script>
<script>(()=>{"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();function t(e){return!!e.frames.__pb_locator__}window.pbRender=function(r){let o=r.parent;for(;o!==r.top&&!t(o);)o=o.parent;return t(o)||(o=r.parent),function({adId:t,pubUrl:s,clickUrl:i}){const a=new URL(s,window.location).origin;function c(e,n,r){const s=new MessageChannel;s.port1.onmessage=l(r),o.postMessage(JSON.stringify(Object.assign({message:e,adId:t},n)),a,[s.port2])}function d(n){c(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function l(e){return function(){try{return e.apply(this,arguments)}catch(e){d(e)}}}c("Prebid Request",{options:{clickUrl:i}},(function(o){let s;try{s=JSON.parse(o.data)}catch(e){return}if("Prebid Response"===s.message&&s.adId===t){const t=n(r.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${s.renderer}<\/script>`});t.onload=l((function(){const o=t.contentWindow;o.Promise.resolve(o.render(s,{sendMessage:c,mkFrame:n},r)).then((()=>c(e,{event:"adRenderSucceeded"})),d)})),r.document.body.appendChild(t)}}))}}(window)})();</script>

<script>
pbRender({
Expand Down
2 changes: 1 addition & 1 deletion libraries/creative-renderer-display/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libraries/creative-renderer-native/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions libraries/processResponse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { logError } from '../../src/utils.js';

export function getBidFromResponse(respItem, LOG_ERROR_MESS) {
if (!respItem) {
logError(LOG_ERROR_MESS.emptySeatbid);
} else if (!respItem.bid) {
logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
} else if (!respItem.bid[0]) {
logError(LOG_ERROR_MESS.noBid);
}
return respItem && respItem.bid && respItem.bid[0];
}
19 changes: 9 additions & 10 deletions libraries/vidazooUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export function appendUserIdsToRequestPayload(payloadRef, userIds) {
let key;
_each(userIds, (userId, idSystemProviderName) => {
key = `uid.${idSystemProviderName}`;

switch (idSystemProviderName) {
case 'lipb':
payloadRef[key] = userId.lipbid;
Expand All @@ -217,7 +218,7 @@ export function getVidazooSessionId(storage) {
return getStorageItem(storage, SESSION_ID_KEY) || '';
}

export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, getUniqueRequestData) {
export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, getUniqueRequestData) {
const {
params,
bidId,
Expand All @@ -234,7 +235,7 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
const {ext} = params;
let {bidFloor} = params;
const hashUrl = hashCode(topWindowUrl);
const uniqueRequestData = isFn(getUniqueRequestData) ? getUniqueRequestData(hashUrl) : {};
const uniqueRequestData = isFn(getUniqueRequestData) ? getUniqueRequestData(hashUrl, bid) : {};
const uniqueDealId = getUniqueDealId(storage, hashUrl);
const pId = extractPID(params);
const isStorageAllowed = bidderSettings.get(bidderCode, 'storageAllowed');
Expand Down Expand Up @@ -285,7 +286,6 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
bidderRequestsCount: bidderRequestsCount,
bidderWinsCount: bidderWinsCount,
bidderTimeout: bidderTimeout,
webSessionId: webSessionId,
...uniqueRequestData
};

Expand Down Expand Up @@ -331,13 +331,13 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
return data;
}

export function createInterpretResponseFn(bidderCode) {
export function createInterpretResponseFn(bidderCode, allowSingleRequest) {
return function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body) {
return [];
}

const singleRequestMode = config.getConfig(`${bidderCode}.singleRequest`);
const singleRequestMode = allowSingleRequest && config.getConfig(`${bidderCode}.singleRequest`);
const reqBidId = deepAccess(request, 'data.bidId');
const {results} = serverResponse.body;

Expand Down Expand Up @@ -410,12 +410,12 @@ export function createInterpretResponseFn(bidderCode) {
}
}

export function createBuildRequestsFn(createRequestDomain, createUniqueRequestData, webSessionId, storage, bidderCode, bidderVersion) {
export function createBuildRequestsFn(createRequestDomain, createUniqueRequestData, storage, bidderCode, bidderVersion, allowSingleRequest) {
function buildRequest(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout) {
const {params} = bid;
const cId = extractCID(params);
const subDomain = extractSubDomain(params);
const data = buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, createUniqueRequestData);
const data = buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, createUniqueRequestData);
const dto = {
method: 'POST', url: `${createRequestDomain(subDomain)}/prebid/multi/${cId}`, data: data
};
Expand All @@ -428,7 +428,7 @@ export function createBuildRequestsFn(createRequestDomain, createUniqueRequestDa
const subDomain = extractSubDomain(params);
const data = bidRequests.map(bid => {
const sizes = parseSizesInput(bid.sizes);
return buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, createUniqueRequestData)
return buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, createUniqueRequestData)
});
const chunkSize = Math.min(20, config.getConfig(`${bidderCode}.chunkSize`) || 10);

Expand All @@ -445,11 +445,10 @@ export function createBuildRequestsFn(createRequestDomain, createUniqueRequestDa
}

return function buildRequests(validBidRequests, bidderRequest) {
// TODO: does the fallback make sense here?
const topWindowUrl = bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation;
const bidderTimeout = config.getConfig('bidderTimeout');

const singleRequestMode = config.getConfig('vidazoo.singleRequest');
const singleRequestMode = allowSingleRequest && config.getConfig(`${bidderCode}.singleRequest`);

const requests = [];

Expand Down
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"reconciliationRtdProvider",
"relevadRtdProvider",
"sirdataRtdProvider",
"symitriDapRtdProvider",
"timeoutRtdProvider",
"weboramaRtdProvider"
],
Expand Down
2 changes: 1 addition & 1 deletion modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export const spec = {
sessionData.rnd = Math.random()
}

const aucId = deepAccess('bidderRequest', 'ortb2.site.ext.data.adg_rtd.uid') || generateUUID()
const aucId = deepAccess(bidderRequest, 'ortb2.site.ext.data.adg_rtd.uid') || generateUUID()

const adUnits = validBidRequests.map(rawBidRequest => {
const bidRequest = deepClone(rawBidRequest);
Expand Down
16 changes: 9 additions & 7 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,18 @@ function onGetBidRequestData(bidReqConfig, callback, config) {

const adUnits = bidReqConfig.adUnits || getGlobal().adUnits || [];
adUnits.forEach(adUnit => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
const ortb2Imp = deepAccess(adUnit, 'ortb2Imp');

// A divId is required to compute the slot position and later to track viewability.
// If nothing has been explicitly set, we try to get the divId from the GPT slot and fallback to the adUnit code in last resort.
if (!deepAccess(ortb2Imp, 'ext.data.divId')) {
const divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
let divId = deepAccess(ortb2Imp, 'ext.data.divId')
if (!divId) {
divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
deepSetValue(ortb2Imp, `ext.data.divId`, divId || adUnit.code);
}

const slotPosition = getSlotPosition(adUnit);
const slotPosition = getSlotPosition(divId);
deepSetValue(ortb2Imp, `ext.data.adg_rtd.adunit_position`, slotPosition);

// It is expected that the publisher set a `adUnits[].ortb2Imp.ext.data.placement` value.
Expand Down Expand Up @@ -430,7 +433,7 @@ function getElementFromTopWindow(element, currentWindow) {
}
};

function getSlotPosition(adUnit) {
function getSlotPosition(divId) {
if (!isSafeFrameWindow() && !canAccessWindowTop()) {
return '';
}
Expand All @@ -451,16 +454,15 @@ function getSlotPosition(adUnit) {
// window.top based computing
const wt = getWindowTop();
const d = wt.document;
const adUnitElementId = deepAccess(adUnit, 'ortb2Imp.ext.data.divId');

let domElement;

if (inIframe() === true) {
const ws = getWindowSelf();
const currentElement = ws.document.getElementById(adUnitElementId);
const currentElement = ws.document.getElementById(divId);
domElement = getElementFromTopWindow(currentElement, ws);
} else {
domElement = wt.document.getElementById(adUnitElementId);
domElement = wt.document.getElementById(divId);
}

if (!domElement) {
Expand Down
11 changes: 1 addition & 10 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {deepAccess, deepClone, deepSetValue, mergeDeep, parseSizesInput} from '../src/utils.js';
import {deepAccess, deepClone, deepSetValue, mergeDeep, parseSizesInput, setOnAny} from '../src/utils.js';
import {config} from '../src/config.js';
import {Renderer} from '../src/Renderer.js';

Expand Down Expand Up @@ -255,15 +255,6 @@ export const spec = {

registerBidder(spec);

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const spec = {
{code: 'headbidder'},
{code: 'digiad'},
{code: 'monetix'},
{code: 'hyperbrainz'}
{code: 'hyperbrainz'},
{code: 'globalsun'}
],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],

Expand Down
Loading

0 comments on commit ba054e9

Please sign in to comment.