forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidxBidAdapter.js
56 lines (48 loc) · 1.5 KB
/
idxBidAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER } from '../src/mediaTypes.js'
import { isArray, isNumber } from '../src/utils.js'
import { interpretResponse } from '../libraries/precisoUtils/bidUtils.js';
const BIDDER_CODE = 'idx'
const ENDPOINT_URL = 'https://dev-event.dxmdp.com/rest/api/v1/bid'
const SUPPORTED_MEDIA_TYPES = [ BANNER ]
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
isBidRequestValid: function (bid) {
return isArray(bid.mediaTypes?.banner?.sizes) && bid.mediaTypes.banner.sizes.every(size => {
return isArray(size) && size.length === 2 && isNumber(size[0]) && isNumber(size[1])
})
},
buildRequests: function (bidRequests, bidderRequest) {
const payload = {
id: bidderRequest.bidderRequestId,
imp: bidRequests.map(request => {
const { bidId, sizes } = request
const item = {
id: bidId,
}
if (request.mediaTypes.banner) {
item.banner = {
format: (request.mediaTypes.banner.sizes || sizes).map(size => {
return { w: size[0], h: size[1] }
}),
}
}
return item
}),
}
const payloadString = JSON.stringify(payload)
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
bidderRequest,
options: {
withCredentials: false,
contentType: 'application/json'
}
}
},
interpretResponse,
}
registerBidder(spec)