-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
blastoBidAdapter.js
77 lines (70 loc) · 2.52 KB
/
blastoBidAdapter.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
const BIDDER_CODE = 'blasto';
const SOURCE_ID_MACRO = '[sourceid]';
const ACCOUNT_ID_MACRO = '[accountid]';
const HOST_MACRO = '[host]';
const URL = `https://${HOST_MACRO}.blasto.ai/bid?rtb_seat_id=${SOURCE_ID_MACRO}&secret_key=${ACCOUNT_ID_MACRO}&integration_type=prebidjs`;
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_HOST = 'us-e-node1';
const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 20,
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
if (!imp.bidfloor) imp.bidfloor = bidRequest.params.bidfloor || 0;
imp.ext = {
[BIDDER_CODE]: {
accountId: bidRequest.params.accountId,
sourceId: bidRequest.params.sourceId,
host: bidRequest.params.host || DEFAULT_HOST,
}
}
return imp;
},
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
const bid = context.bidRequests[0];
request.test = config.getConfig('debug') ? 1 : 0;
if (!request.cur) request.cur = [bid.params.currency || DEFAULT_CURRENCY];
return request;
},
bidResponse(buildBidResponse, bid, context) {
const bidResponse = buildBidResponse(bid, context);
bidResponse.cur = bid.cur || DEFAULT_CURRENCY;
return bidResponse;
}
});
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: (bid) => {
return Boolean(bid.params.sourceId) && Boolean(bid.params.accountId);
},
buildRequests: (validBidRequests, bidderRequest) => {
if (validBidRequests && validBidRequests.length === 0) return [];
const { sourceId, accountId } = validBidRequests[0].params;
const host = validBidRequests[0].params.host;
const endpointURL = URL.replace(HOST_MACRO, host || DEFAULT_HOST)
.replace(ACCOUNT_ID_MACRO, accountId)
.replace(SOURCE_ID_MACRO, sourceId);
const request = converter.toORTB({ bidRequests: validBidRequests, bidderRequest });
return {
method: 'POST',
url: endpointURL,
data: request
};
},
interpretResponse: (response, request) => {
if (response?.body) {
const bids = converter.fromORTB({ response: response.body, request: request.data }).bids;
return bids;
}
return [];
},
};
registerBidder(spec);