forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbidfactory.ts
More file actions
220 lines (195 loc) · 6.28 KB
/
Copy pathbidfactory.ts
File metadata and controls
220 lines (195 loc) · 6.28 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { getUniqueIdentifierStr } from './utils.js';
import type { BidderCode, BidSource, ContextIdentifiers, Currency, Identifier } from "./types/common.d.ts";
import { MediaType } from "./mediaTypes.ts";
import type { DSAResponse } from "./types/ortb/ext/dsa.d.ts";
import type { EventTrackerResponse } from "./types/ortb/native.d.ts";
import { Metrics } from "./utils/perfMetrics.ts";
import { Renderer } from './Renderer.js';
import { type BID_STATUS } from "./constants.ts";
import type { DemandChain } from "./types/ortb/ext/dchain.d.ts";
type BidIdentifiers = ContextIdentifiers & {
src: BidSource;
bidder: BidderCode;
bidId: Identifier;
};
/**
* Bid metadata.
*/
export interface BidMeta {
[key: string]: unknown;
/**
* Advertiser domains (corresponds to ORTB `bid.adomain`).
*/
advertiserDomains?: string[];
/**
* Primary category ID (corresponds to ORTB `bid.cat[0]`).
*/
primaryCatId?: string;
/**
* IDs of all other categories (corresponds to ORTB `bid.cat.slice(1)`).
*/
secondaryCatIds?: string[];
/**
* Creative attributes (corresponds to ORTB `bid.attr`).
*/
attr?: number[];
/**
* DSA transparency information.
*/
dsa?: DSAResponse;
/**
* Demand chain object.
*/
dchain?: DemandChain
/**
* DSP network name.
*/
networkName?: string;
/**
* DSP network ID.
*/
networkId?: string | number;
}
/**
* Bid responses as provided by adapters; core then transforms these into `Bid`s
*/
export interface BaseBidResponse {
bidderCode?: BidderCode;
/**
* This bid's BidRequest's `.bidId`.
*/
requestId: Identifier;
mediaType: MediaType;
cpm: number;
currency: Currency;
/**
* The time to live for this bid response in seconds
*/
ttl: number;
creativeId: string;
/**
* True if the CPM is the one this bidder will pay
*/
netRevenue: boolean;
/**
* If the bid is associated with a Deal, this field contains the deal ID.
* @see https://docs.prebid.org/adops/deals.html
*/
dealId?: string;
meta?: BidMeta;
/**
* If true, and deferred billing was requested for this bid, its creative will not be rendered
* until billing is explicitly triggered with `pbjs.triggerBilling()`.
* Useful to avoid premature firing of trackers embedded in the creative.
*/
deferRendering?: boolean;
/**
* Event trackers for this bid.
*/
eventtrackers?: EventTrackerResponse[];
renderer?: Renderer;
/**
* Billing tracker URL.
*/
burl?: string;
}
// <format>BidResponesProperties - adapter interpretResponse properties specific to the format.
// they are included in both BidResponse and Bid types.
// Here we have only "naked" declarations, extended in banner/video/native.ts as well as modules.
export interface BannerBidResponseProperties {
mediaType: 'banner';
}
export interface VideoBidResponseProperties {
mediaType: 'video';
}
export interface NativeBidResponseProperties {
mediaType: 'native';
}
export interface AudioBidResponseProperties {
mediaType: 'audio';
}
export type BannerBidResponse = BaseBidResponse & BannerBidResponseProperties;
export type VideoBidResponse = BaseBidResponse & VideoBidResponseProperties;
export type NativeBidResponse = BaseBidResponse & NativeBidResponseProperties;
export type AudioBidResponse = BaseBidResponse & AudioBidResponseProperties;
export type BidResponse = BannerBidResponse | VideoBidResponse | NativeBidResponse | AudioBidResponse;
export interface BaseBid extends ContextIdentifiers, Required<Pick<BaseBidResponse, 'meta' | 'deferRendering'>> {
/**
* This bid's BidRequest's `.bidId`. Can be null in some `allowUnknownBidderCodes` scenarios.
*/
requestId: Identifier | null;
metrics: Metrics;
source: BidSource;
width: number;
height: number;
adId: Identifier;
getSize(): string;
status?: (typeof BID_STATUS)[keyof typeof BID_STATUS]
bidderCode: BidderCode;
adapterCode?: BidderCode;
/**
* CPM of this bid before currency conversions or adjustments.
*/
originalCpm?: number;
/**
* Currency for `originalCpm`.
*/
originalCurrency?: Currency;
/**
* If true, this bid will not fire billing trackers until they are explicitly
* triggered with `pbjs.triggerBilling()`.
*/
deferBilling: boolean;
}
// <format>BidProperties - format specific properties of Bid objects generated by Prebid, but not in
// (or different from) adapter responses. Again,these are just naked declarations, extended in their place of
// use.
export interface BannerBidProperties {
mediaType: 'banner';
}
export interface NativeBidProperties {
mediaType: 'native';
}
export interface VideoBidProperties {
mediaType: 'video' | 'audio';
}
type BidFrom<RESP, PROPS> = BaseBid & Omit<RESP, keyof BaseBid | keyof PROPS> & PROPS;
type _BannerBid = BidFrom<BannerBidResponse, BannerBidProperties>;
type _VideoBid = BidFrom<VideoBidResponse, VideoBidProperties>;
type _NativeBid = BidFrom<NativeBidResponse, NativeBidProperties>;
type _AudioBid = _VideoBid;
type AnyBid = _BannerBid | _VideoBid | _NativeBid | _AudioBid;
// the following adds `property?: undefined` declarations for each property
// that is in some other format, to avoid requiring type casts
// every time that property is used
type NullProps<T> = { [K in keyof T]?: undefined };
type NullBid = NullProps<_BannerBid> & NullProps<_VideoBid> & NullProps<_NativeBid>;
type ExtendBid<B extends AnyBid> = B & Omit<NullBid, keyof B>;
export type BannerBid = ExtendBid<_BannerBid>;
export type VideoBid = ExtendBid<_VideoBid>;
export type NativeBid = ExtendBid<_NativeBid>;
export type AudioBid = VideoBid;
export type Bid = BannerBid | VideoBid | NativeBid | AudioBid;
// eslint-disable-next-line @typescript-eslint/no-redeclare
function Bid({ src = 'client', bidder = '', bidId, transactionId, adUnitId, auctionId }: Partial<BidIdentifiers> = {}) {
var _bidSrc = src;
Object.assign(this, {
bidderCode: bidder,
width: 0,
height: 0,
adId: getUniqueIdentifierStr(),
requestId: bidId,
transactionId,
adUnitId,
auctionId,
mediaType: 'banner',
source: _bidSrc
})
// returns the size of the bid creative. Concatenation of width and height by ‘x’.
this.getSize = function () {
return this.width + 'x' + this.height;
};
}
export function createBid(identifiers?: Partial<BidIdentifiers>): Partial<Bid> {
return new Bid(identifiers);
}