From 8e0c1a586b7818373e461e1b62ad836384dcdc4b Mon Sep 17 00:00:00 2001 From: Alexandr Kim Date: Thu, 26 Nov 2026 07:58:22 +0500 Subject: [PATCH] Yaleo Bid Adapter: add forceDarkTheme param and warn about invalid values Declare the `forceDarkTheme` param and warn about invalid param values. The bids are still sent: rejecting them would invalidate previously accepted values, a breaking change held for the next major release. Co-Authored-By: Claude Opus 5.5 --- modules/yaleoBidAdapter.ts | 32 +++++++++- test/spec/modules/yaleoBidAdapter_spec.js | 74 ++++++++++++++++++++--- 2 files changed, 97 insertions(+), 9 deletions(-) diff --git a/modules/yaleoBidAdapter.ts b/modules/yaleoBidAdapter.ts index dcae1d5fd60..01d095aca99 100755 --- a/modules/yaleoBidAdapter.ts +++ b/modules/yaleoBidAdapter.ts @@ -19,6 +19,10 @@ interface YaleoBidParams { * Maximum CPM value. Bids with a CPM higher than the specified value will be rejected. */ maxCpm?: number; + /** + * Renders the ad unit in the dark theme. + */ + forceDarkTheme?: boolean; } interface YaleoConfig { @@ -46,6 +50,7 @@ const AUDIENZZ_VENDOR_ID = 783; const DEFAULT_ENDPOINT = 'https://bidder.yaleo.com/prebid'; const ALLOWED_ENDPOINTS = new Set([DEFAULT_ENDPOINT, 'https://dev-bidder.yaleo.com/prebid']); const DEFAULT_TTL = 300; +const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; const converter = ortbConverter({ context: { @@ -67,12 +72,35 @@ const resolveEndpoint = (): string => { return customEndpoint; }; +const getInvalidParamMessages = ({ placementId, memberId, maxCpm, forceDarkTheme }: YaleoBidParams): string[] => { + const messages: string[] = []; + if (!UUID_PATTERN.test(placementId)) { + messages.push(`placementId must be a UUID, got "${placementId}"`); + } + if (memberId !== undefined && !(Number.isInteger(memberId) && memberId >= 1)) { + messages.push(`memberId must be a positive integer, got "${memberId}"`); + } + if (maxCpm !== undefined && !(Number.isFinite(maxCpm) && maxCpm >= 0)) { + messages.push(`maxCpm must be a number greater than or equal to 0, got "${maxCpm}"`); + } + if (forceDarkTheme !== undefined && typeof forceDarkTheme !== 'boolean') { + messages.push(`forceDarkTheme must be a boolean, got "${forceDarkTheme}"`); + } + return messages; +}; + const isBidRequestValid: BidderSpec['isBidRequestValid'] = (request) => { - if (!request.params || typeof request.params.placementId !== 'string') { + const { params } = request; + if (!params || typeof params.placementId !== 'string' || !params.placementId) { return false; } - return !!request.params.placementId; + // Warn only: rejecting previously accepted values is a breaking change. + getInvalidParamMessages(params).forEach((message) => { + logWarn(`${BIDDER_CODE}: ${message}. The bid is still sent, but a future major Prebid.js release will reject it.`); + }); + + return true; }; const buildRequests: BidderSpec['buildRequests'] = (validBidRequests, bidderRequest) => { diff --git a/test/spec/modules/yaleoBidAdapter_spec.js b/test/spec/modules/yaleoBidAdapter_spec.js index 46bfeb2ee29..83f881db9ed 100644 --- a/test/spec/modules/yaleoBidAdapter_spec.js +++ b/test/spec/modules/yaleoBidAdapter_spec.js @@ -1,7 +1,11 @@ import { cloneDeep } from "lodash"; +import sinon from 'sinon'; import { config } from "src/config.js"; +import * as utils from "src/utils.js"; import { spec } from "../../../modules/yaleoBidAdapter.ts"; +const PLACEMENT_ID = '9c752583-d856-4b44-a227-c0ce6c7a8cfa'; + const bannerBidRequestBase = { adUnitCode: 'banner-ad-unit-code', auctionId: 'banner-auction-id', @@ -9,7 +13,7 @@ const bannerBidRequestBase = { bidder: 'yaleo', bidderRequestId: 'banner-bidder-request-id', mediaTypes: { banner: [[300, 250]] }, - params: { placementId: '12345' }, + params: { placementId: PLACEMENT_ID }, }; const bannerServerResponseBase = { @@ -62,15 +66,16 @@ describe('Yaleo bid adapter', () => { describe('isBidRequestValid', () => { it('returns true when all params are specified', () => { bannerBidRequest.params = { - placementId: '12345', + placementId: PLACEMENT_ID, maxCpm: 5.00, memberId: 12345, + forceDarkTheme: true, }; expect(spec.isBidRequestValid(bannerBidRequest)).to.be.true; }); it('returns true when required params are specified', () => { - bannerBidRequest.params = { placementId: '12345' }; + bannerBidRequest.params = { placementId: PLACEMENT_ID }; expect(spec.isBidRequestValid(bannerBidRequest)).to.be.true; }); @@ -118,6 +123,59 @@ describe('Yaleo bid adapter', () => { bannerBidRequest.params = { placementId: null }; expect(spec.isBidRequestValid(bannerBidRequest)).to.be.false; }); + + it('returns false when placementId is an empty string', () => { + bannerBidRequest.params = { placementId: '' }; + expect(spec.isBidRequestValid(bannerBidRequest)).to.be.false; + }); + + describe('params outside the Prebid Server schema', () => { + const describeValue = (value) => (typeof value === 'string' ? `"${value}"` : String(value)); + let logWarnStub; + + beforeEach(() => { + logWarnStub = sinon.stub(utils, 'logWarn'); + }); + + afterEach(() => { + logWarnStub.restore(); + }); + + [ + { placementId: PLACEMENT_ID }, + { placementId: PLACEMENT_ID.toUpperCase() }, + { placementId: PLACEMENT_ID, memberId: 1, maxCpm: 0, forceDarkTheme: false }, + { placementId: PLACEMENT_ID, memberId: 3927, maxCpm: 5.5, forceDarkTheme: true }, + ].forEach((params) => { + it(`accepts the bid without a warning: ${JSON.stringify(params)}`, () => { + bannerBidRequest.params = params; + expect(spec.isBidRequestValid(bannerBidRequest)).to.be.true; + sinon.assert.notCalled(logWarnStub); + }); + }); + + [ + ['placementId', ['12345', `${PLACEMENT_ID}0`, ` ${PLACEMENT_ID}`, PLACEMENT_ID.replace(/-/g, ''), 'zz752583-d856-4b44-a227-c0ce6c7a8cfa']], + ['memberId', [0, -1, 1.5, NaN, '3927', null, true]], + ['maxCpm', [-0.01, NaN, Infinity, '5', null]], + ['forceDarkTheme', ['true', 1, null]], + ].forEach(([param, values]) => { + values.forEach((value) => { + it(`still accepts the bid but warns when ${param} is ${describeValue(value)}`, () => { + bannerBidRequest.params = { placementId: PLACEMENT_ID, [param]: value }; + expect(spec.isBidRequestValid(bannerBidRequest)).to.be.true; + sinon.assert.calledOnce(logWarnStub); + expect(logWarnStub.firstCall.args[0]).to.include(`yaleo: ${param} must be`); + }); + }); + }); + + it('warns once per invalid param', () => { + bannerBidRequest.params = { placementId: '12345', memberId: 0, maxCpm: -1, forceDarkTheme: 'true' }; + expect(spec.isBidRequestValid(bannerBidRequest)).to.be.true; + sinon.assert.callCount(logWarnStub, 4); + }); + }); }); describe('buildRequests', () => { @@ -212,9 +270,10 @@ describe('Yaleo bid adapter', () => { it('checks that all params are passed to the request', () => { bannerBidRequest.params = { - placementId: '12345', + placementId: PLACEMENT_ID, maxCpm: 5.00, memberId: 12345, + forceDarkTheme: true, }; const bidderRequest = { bids: [bannerBidRequest], @@ -225,15 +284,16 @@ describe('Yaleo bid adapter', () => { const request = spec.buildRequests([bannerBidRequest], bidderRequest); const yaleoParams = request.data.imp[0].ext.prebid.bidder.yaleo; - expect(yaleoParams.placementId).to.equal('12345'); + expect(yaleoParams.placementId).to.equal(PLACEMENT_ID); expect(yaleoParams.maxCpm).to.equal(5.00); expect(yaleoParams.memberId).to.equal(12345); + expect(yaleoParams.forceDarkTheme).to.be.true; }); }); it('checks that only specified params are passed to the request', () => { bannerBidRequest.params = { - placementId: '12345', + placementId: PLACEMENT_ID, }; const bidderRequest = { @@ -245,7 +305,7 @@ describe('Yaleo bid adapter', () => { const request = spec.buildRequests([bannerBidRequest], bidderRequest); const yaleoParams = request.data.imp[0].ext.prebid.bidder.yaleo; - expect(yaleoParams).to.deep.equal({ placementId: '12345' }); + expect(yaleoParams).to.deep.equal({ placementId: PLACEMENT_ID }); }); describe('interpretResponse', () => {