@@ -2,13 +2,20 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js';
22import { registerBidder } from '../src/adapters/bidderFactory.js' ;
33import { BANNER } from '../src/mediaTypes.js' ;
44import { getStorageManager } from '../src/storageManager.js' ;
5+ import {
6+ buildOrtbRequest ,
7+ ortbConverterRequest ,
8+ ortbConverterImp ,
9+ buildBidObjectBase ,
10+ commonOnBidWonHandler ,
11+ commonIsBidRequestValid ,
12+ createOrtbConverter ,
13+ getPublisherIdFromBids ,
14+ packageOrtbRequest
15+ } from '../libraries/blueUtils/bidderUtils.js' ;
516import {
617 replaceAuctionPrice ,
7- isFn ,
8- isPlainObject ,
9- deepSetValue ,
10- isEmpty ,
11- triggerPixel ,
18+ isEmpty
1219} from '../src/utils.js' ;
1320const BIDDER_CODE = 'blue' ;
1421const ENDPOINT_URL = 'https://bidder-us-east-1.getblue.io/engine/?src=prebid' ;
@@ -17,90 +24,27 @@ const DEFAULT_CURRENCY = 'USD';
1724
1825export const storage = getStorageManager ( { bidderCode : BIDDER_CODE } ) ;
1926
20- function getBidFloor ( bid ) {
21- if ( isFn ( bid . getFloor ) ) {
22- let floor = bid . getFloor ( {
23- currency : DEFAULT_CURRENCY ,
24- mediaType : BANNER ,
25- size : '*' ,
26- } ) ;
27- if (
28- isPlainObject ( floor ) &&
29- ! isNaN ( floor . floor ) &&
30- floor . currency === DEFAULT_CURRENCY
31- ) {
32- return floor . floor ;
33- }
34- }
35- return null ;
36- }
37-
38- const converter = ortbConverter ( {
39- context : {
40- netRevenue : true , // Default netRevenue setting
41- ttl : 100 , // Default time-to-live for bid responses
42- } ,
43- imp,
44- request,
45- } ) ;
46-
47- function request ( buildRequest , imps , bidderRequest , context ) {
48- let request = buildRequest ( imps , bidderRequest , context ) ;
49- deepSetValue ( request , 'site.publisher.id' , context . publisherId ) ;
50- return request ;
51- }
52-
53- function imp ( buildImp , bidRequest , context ) {
54- let imp = buildImp ( bidRequest , context ) ;
55- const floor = getBidFloor ( bidRequest ) ;
56- imp . tagid = bidRequest . params . placementId ;
57-
58- if ( floor ) {
59- imp . bidfloor = floor ;
60- imp . bidfloorcur = DEFAULT_CURRENCY ;
61- }
62-
63- return imp ;
64- }
27+ const converter = createOrtbConverter ( ortbConverter , BANNER , DEFAULT_CURRENCY , ortbConverterImp , ortbConverterRequest ) ;
6528
6629export const spec = {
6730 code : BIDDER_CODE ,
6831 gvlid : GVLID ,
6932 supportedMediaTypes : [ BANNER ] ,
7033
7134 // Validate bid request
72- isBidRequestValid : function ( bid ) {
73- return ! ! bid . params . placementId && ! ! bid . params . publisherId ;
74- } ,
35+ isBidRequestValid : commonIsBidRequestValid ,
7536
7637 // Build OpenRTB requests using `ortbConverter`
7738 buildRequests : function ( validBidRequests , bidderRequest ) {
7839 const context = {
79- publisherId : validBidRequests . find (
80- ( bidRequest ) => bidRequest . params ?. publisherId
81- ) ?. params . publisherId ,
40+ publisherId : getPublisherIdFromBids ( validBidRequests ) ,
8241 } ;
42+ const ortbRequestData = buildOrtbRequest ( validBidRequests , bidderRequest , context , GVLID , converter ) ;
8343
84- const ortbRequest = converter . toORTB ( {
85- bidRequests : validBidRequests ,
86- bidderRequest,
87- context,
88- } ) ;
89-
90- // Add extensions to the request
91- ortbRequest . ext = ortbRequest . ext || { } ;
92- deepSetValue ( ortbRequest , 'ext.gvlid' , GVLID ) ;
44+ const blueDataProcessor = ( data ) => data ;
45+ const blueOptions = { contentType : 'application/json' } ;
9346
94- return [
95- {
96- method : 'POST' ,
97- url : ENDPOINT_URL ,
98- data : ortbRequest ,
99- options : {
100- contentType : 'application/json' ,
101- } ,
102- } ,
103- ] ;
47+ return packageOrtbRequest ( ortbRequestData , ENDPOINT_URL , blueDataProcessor , blueOptions ) ;
10448 } ,
10549
10650 interpretResponse : ( serverResponse ) => {
@@ -109,41 +53,17 @@ export const spec = {
10953 let bids = [ ] ;
11054 serverResponse . body . seatbid . forEach ( ( response ) => {
11155 response . bid . forEach ( ( bid ) => {
112- const mediaType = bid . ext ?. mediaType || 'banner' ;
113- bids . push ( {
114- ad : replaceAuctionPrice ( bid . adm , bid . price ) ,
115- adapterCode : BIDDER_CODE ,
116- cpm : bid . price ,
117- creativeId : bid . ext . blue . adId ,
118- creative_id : bid . ext . blue . adId ,
119- currency : serverResponse . body . cur || 'USD' ,
120- deferBilling : false ,
121- deferRendering : false ,
122- width : bid . w ,
123- height : bid . h ,
124- mediaType,
125- netRevenue : true ,
126- originalCpm : bid . price ,
127- originalCurrency : serverResponse . body . cur || 'USD' ,
128- requestId : bid . impid ,
129- seatBidId : bid . id ,
130- ttl : 1200 ,
131- } ) ;
56+ const baseBid = buildBidObjectBase ( bid , serverResponse . body , BIDDER_CODE , DEFAULT_CURRENCY ) ;
57+ const blueSpecific = { creativeId : bid . ext . blue . adId , creative_id : bid . ext . blue . adId , ttl : 1200 } ;
58+ bids . push ( { ...baseBid , ...blueSpecific } ) ;
13259 } ) ;
13360 } ) ;
13461 return bids ;
13562 } ,
13663
13764 onBidWon : function ( bid ) {
138- const { burl, nurl } = bid || { } ;
139-
140- if ( nurl ) {
141- triggerPixel ( replaceAuctionPrice ( nurl , bid . originalCpm || bid . cpm ) ) ;
142- }
143-
144- if ( burl ) {
145- triggerPixel ( replaceAuctionPrice ( burl , bid . originalCpm || bid . cpm ) ) ;
146- }
65+ // replaceAuctionPrice is available in this scope due to the import from ../src/utils.js
66+ commonOnBidWonHandler ( bid , ( url , bidData ) => replaceAuctionPrice ( url , bidData . originalCpm || bidData . cpm ) ) ;
14767 } ,
14868} ;
14969
0 commit comments