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

Criteo Bid Adapter: get rid of getLegacyFpd call #8344

Merged
merged 1 commit into from
Apr 29, 2022
Merged
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
40 changes: 20 additions & 20 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {deepAccess, getUniqueIdentifierStr, isArray, logError, logInfo, logWarn, parseUrl} from '../src/utils.js';
import {loadExternalScript} from '../src/adloader.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {find} from '../src/polyfill.js';
import {verify} from 'criteo-direct-rsa-validate/build/verify.js'; // ref#2
import {getStorageManager} from '../src/storageManager.js';
import { deepAccess, getUniqueIdentifierStr, isArray, logError, logInfo, logWarn, parseUrl } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { find } from '../src/polyfill.js';
import { verify } from 'criteo-direct-rsa-validate/build/verify.js'; // ref#2
import { getStorageManager } from '../src/storageManager.js';

const GVLID = 91;
export const ADAPTER_VERSION = 34;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const PROFILE_ID_INLINE = 207;
export const PROFILE_ID_PUBLISHERTAG = 185;
const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE});
const storage = getStorageManager({ gvlid: GVLID, bidderCode: BIDDER_CODE });
const LOG_PREFIX = 'Criteo: ';

/*
Expand All @@ -35,7 +35,7 @@ const FAST_BID_PUBKEY_N = 'ztQYwCE5BU7T9CDM5he6rKoabstXRmkzx54zFPZkWbK530dwtLBDe
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [ BANNER, VIDEO, NATIVE ],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],

/** f
* @param {object} bid
Expand Down Expand Up @@ -65,11 +65,11 @@ export const spec = {
buildRequests: (bidRequests, bidderRequest) => {
let url;
let data;
let fpd = config.getLegacyFpd(config.getConfig('ortb2')) || {};
let fpd = config.getConfig('ortb2') || {};

Object.assign(bidderRequest, {
publisherExt: fpd.context,
userExt: fpd.user,
publisherExt: fpd.site?.ext,
userExt: fpd.user?.ext,
ceh: config.getConfig('criteo.ceh')
});

Expand Down Expand Up @@ -265,11 +265,11 @@ function checkNativeSendId(bidRequest) {
return !(bidRequest.nativeParams &&
(
(bidRequest.nativeParams.image && ((bidRequest.nativeParams.image.sendId !== true || bidRequest.nativeParams.image.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.icon && ((bidRequest.nativeParams.icon.sendId !== true || bidRequest.nativeParams.icon.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.clickUrl && ((bidRequest.nativeParams.clickUrl.sendId !== true || bidRequest.nativeParams.clickUrl.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.displayUrl && ((bidRequest.nativeParams.displayUrl.sendId !== true || bidRequest.nativeParams.displayUrl.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.privacyLink && ((bidRequest.nativeParams.privacyLink.sendId !== true || bidRequest.nativeParams.privacyLink.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.privacyIcon && ((bidRequest.nativeParams.privacyIcon.sendId !== true || bidRequest.nativeParams.privacyIcon.sendTargetingKeys === true)))
(bidRequest.nativeParams.icon && ((bidRequest.nativeParams.icon.sendId !== true || bidRequest.nativeParams.icon.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.clickUrl && ((bidRequest.nativeParams.clickUrl.sendId !== true || bidRequest.nativeParams.clickUrl.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.displayUrl && ((bidRequest.nativeParams.displayUrl.sendId !== true || bidRequest.nativeParams.displayUrl.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.privacyLink && ((bidRequest.nativeParams.privacyLink.sendId !== true || bidRequest.nativeParams.privacyLink.sendTargetingKeys === true))) ||
(bidRequest.nativeParams.privacyIcon && ((bidRequest.nativeParams.privacyIcon.sendId !== true || bidRequest.nativeParams.privacyIcon.sendTargetingKeys === true)))
));
}

Expand All @@ -285,7 +285,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
const request = {
publisher: {
url: context.url,
ext: bidderRequest.publisherExt
ext: bidderRequest.publisherExt,
},
slots: bidRequests.map(bidRequest => {
networkId = bidRequest.params.networkId || networkId;
Expand Down Expand Up @@ -405,7 +405,7 @@ function hasValidVideoMediaType(bidRequest) {

var requiredMediaTypesParams = ['mimes', 'playerSize', 'maxduration', 'protocols', 'api', 'skip', 'placement', 'playbackmethod'];

requiredMediaTypesParams.forEach(function(param) {
requiredMediaTypesParams.forEach(function (param) {
if (deepAccess(bidRequest, 'mediaTypes.video.' + param) === undefined && deepAccess(bidRequest, 'params.video.' + param) === undefined) {
isValid = false;
logError('Criteo Bid Adapter: mediaTypes.video.' + param + ' is required');
Expand Down
66 changes: 33 additions & 33 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('The Criteo bidding adapter', function () {
sandbox = sinon.sandbox.create();
});

afterEach(function() {
afterEach(function () {
global.Criteo = undefined;
utilsMock.restore();
sandbox.restore();
Expand Down Expand Up @@ -457,7 +457,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {},
nativeCallback: function () { },
integrationMode: 'amp'
},
},
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('The Criteo bidding adapter', function () {
}
},
params: {
nativeCallback: function() {}
nativeCallback: function () { }
},
},
];
Expand All @@ -540,7 +540,7 @@ describe('The Criteo bidding adapter', function () {
}
},
params: {
nativeCallback: function() {}
nativeCallback: function () { }
},
},
];
Expand Down Expand Up @@ -852,7 +852,7 @@ describe('The Criteo bidding adapter', function () {
sizes: [[300, 250]],
mediaTypes: {
video: {
playerSize: [ [300, 250] ],
playerSize: [[300, 250]],
mimes: ['video/mp4', 'video/MPV', 'video/H264', 'video/webm', 'video/ogg'],
minduration: 1,
maxduration: 30,
Expand Down Expand Up @@ -970,7 +970,7 @@ describe('The Criteo bidding adapter', function () {
});

it('should properly build a request with first party data', function () {
const contextData = {
const siteData = {
keywords: ['power tools'],
ext: {
data: {
Expand Down Expand Up @@ -1015,16 +1015,16 @@ describe('The Criteo bidding adapter', function () {
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
ortb2: {
site: contextData,
site: siteData,
user: userData
}
};
return utils.deepAccess(config, key);
});

const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.publisher.ext).to.deep.equal({keywords: ['power tools'], data: {pageType: 'article'}});
expect(request.data.user.ext).to.deep.equal({gender: 'M', data: {registered: true}});
expect(request.data.publisher.ext).to.deep.equal({ data: { pageType: 'article' } });
expect(request.data.user.ext).to.deep.equal({ data: { registered: true } });
expect(request.data.slots[0].ext).to.deep.equal({
bidfloor: 0.75,
data: {
Expand Down Expand Up @@ -1171,13 +1171,13 @@ describe('The Criteo bidding adapter', function () {
'advertiser': {
'description': 'sponsor',
'domain': 'criteo.com',
'logo': {'url': 'https://www.criteo.com/images/criteo-logo.svg', 'height': 300, 'width': 300}
'logo': { 'url': 'https://www.criteo.com/images/criteo-logo.svg', 'height': 300, 'width': 300 }
},
'privacy': {
'optout_click_url': 'https://info.criteo.com/privacy/informations',
'optout_image_url': 'https://static.criteo.net/flash/icon/nai_small.png',
},
'impression_pixels': [{'url': 'https://my-impression-pixel/test/impression'}, {'url': 'https://cas.com/lg.com'}]
'impression_pixels': [{ 'url': 'https://my-impression-pixel/test/impression' }, { 'url': 'https://cas.com/lg.com' }]
}
}],
},
Expand All @@ -1201,7 +1201,7 @@ describe('The Criteo bidding adapter', function () {
});

it('should warn only once if sendTargetingKeys set to true on required fields for native bidRequest', () => {
const bidderRequest = { };
const bidderRequest = {};
const bidRequests = [
{
bidder: 'criteo',
Expand All @@ -1211,7 +1211,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {}
nativeCallback: function () { }
},
},
{
Expand All @@ -1222,7 +1222,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 456,
publisherSubId: '456',
nativeCallback: function() {}
nativeCallback: function () { }
},
},
];
Expand Down Expand Up @@ -1276,7 +1276,7 @@ describe('The Criteo bidding adapter', function () {
.withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)')
.exactly(nativeParamsWithSendTargetingKeys.length * bidRequests.length);
nativeParamsWithSendTargetingKeys.forEach(nativeParams => {
let transformedBidRequests = {...bidRequests};
let transformedBidRequests = { ...bidRequests };
transformedBidRequests = [Object.assign(transformedBidRequests[0], nativeParams), Object.assign(transformedBidRequests[1], nativeParams)];
spec.buildRequests(transformedBidRequests, bidderRequest);
});
Expand Down Expand Up @@ -1440,7 +1440,7 @@ describe('The Criteo bidding adapter', function () {

describe('when pubtag prebid adapter is not available', function () {
it('should not warn if sendId is provided on required fields for native bidRequest', () => {
const bidderRequest = { };
const bidderRequest = {};
const bidRequestsWithSendId = [
{
bidder: 'criteo',
Expand All @@ -1450,7 +1450,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {}
nativeCallback: function () { }
},
nativeParams: {
image: {
Expand Down Expand Up @@ -1481,7 +1481,7 @@ describe('The Criteo bidding adapter', function () {
});

it('should warn only once if sendId is not provided on required fields for native bidRequest', () => {
const bidderRequest = { };
const bidderRequest = {};
const bidRequests = [
{
bidder: 'criteo',
Expand All @@ -1491,7 +1491,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 123,
publisherSubId: '123',
nativeCallback: function() {}
nativeCallback: function () { }
},
},
{
Expand All @@ -1502,7 +1502,7 @@ describe('The Criteo bidding adapter', function () {
params: {
zoneId: 456,
publisherSubId: '456',
nativeCallback: function() {}
nativeCallback: function () { }
},
},
];
Expand Down Expand Up @@ -1556,7 +1556,7 @@ describe('The Criteo bidding adapter', function () {
.withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)')
.exactly(nativeParamsWithoutSendId.length * bidRequests.length);
nativeParamsWithoutSendId.forEach(nativeParams => {
let transformedBidRequests = {...bidRequests};
let transformedBidRequests = { ...bidRequests };
transformedBidRequests = [Object.assign(transformedBidRequests[0], nativeParams), Object.assign(transformedBidRequests[1], nativeParams)];
spec.buildRequests(transformedBidRequests, bidderRequest);
});
Expand All @@ -1569,10 +1569,10 @@ describe('The Criteo bidding adapter', function () {
const response = {};
const request = {};

const adapter = { interpretResponse: function() {} };
const adapter = { interpretResponse: function () { } };
const adapterMock = sinon.mock(adapter);
adapterMock.expects('interpretResponse').withExactArgs(response, request).once().returns('ok');
const prebidAdapter = { GetAdapter: function() {} };
const prebidAdapter = { GetAdapter: function () { } };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(request).once().returns(adapter);

Expand All @@ -1592,10 +1592,10 @@ describe('The Criteo bidding adapter', function () {
it('should forward bid to pubtag when calling onBidWon', () => {
const bid = { auctionId: 123 };

const adapter = { handleBidWon: function() {} };
const adapter = { handleBidWon: function () { } };
const adapterMock = sinon.mock(adapter);
adapterMock.expects('handleBidWon').withExactArgs(bid).once();
const prebidAdapter = { GetAdapter: function() {} };
const prebidAdapter = { GetAdapter: function () { } };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(bid.auctionId).once().returns(adapter);

Expand All @@ -1615,10 +1615,10 @@ describe('The Criteo bidding adapter', function () {
it('should forward bid to pubtag when calling onSetTargeting', () => {
const bid = { auctionId: 123 };

const adapter = { handleSetTargeting: function() {} };
const adapter = { handleSetTargeting: function () { } };
const adapterMock = sinon.mock(adapter);
adapterMock.expects('handleSetTargeting').withExactArgs(bid).once();
const prebidAdapter = { GetAdapter: function() {} };
const prebidAdapter = { GetAdapter: function () { } };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(bid.auctionId).once().returns(adapter);

Expand All @@ -1638,10 +1638,10 @@ describe('The Criteo bidding adapter', function () {
it('should forward bid to pubtag when calling onTimeout', () => {
const timeoutData = [{ auctionId: 123 }];

const adapter = { handleBidTimeout: function() {} };
const adapter = { handleBidTimeout: function () { } };
const adapterMock = sinon.mock(adapter);
adapterMock.expects('handleBidTimeout').once();
const prebidAdapter = { GetAdapter: function() {} };
const prebidAdapter = { GetAdapter: function () { } };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(timeoutData[0].auctionId).once().returns(adapter);

Expand All @@ -1659,15 +1659,15 @@ describe('The Criteo bidding adapter', function () {
});

it('should return a POST method with url & data from pubtag', () => {
const bidRequests = { };
const bidderRequest = { };
const bidRequests = {};
const bidderRequest = {};

const prebidAdapter = { buildCdbUrl: function() {}, buildCdbRequest: function() {} };
const prebidAdapter = { buildCdbUrl: function () { }, buildCdbRequest: function () { } };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('buildCdbUrl').once().returns('cdbUrl');
prebidAdapterMock.expects('buildCdbRequest').once().returns('cdbRequest');

const adapters = { Prebid: function() {} };
const adapters = { Prebid: function () { } };
const adaptersMock = sinon.mock(adapters);
adaptersMock.expects('Prebid').withExactArgs(PROFILE_ID_PUBLISHERTAG, ADAPTER_VERSION, bidRequests, bidderRequest, '$prebid.version$').once().returns(prebidAdapter);

Expand Down