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; } // 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> { /** * 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; getStatusCode(): number; 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; } // 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 = BaseBid & Omit & PROPS; type _BannerBid = BidFrom; type _VideoBid = BidFrom; type _NativeBid = BidFrom; 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 = {[K in keyof T]?: undefined}; type NullBid = NullProps<_BannerBid> & NullProps<_VideoBid> & NullProps<_NativeBid>; type ExtendBid = B & Omit; 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 = {}) { 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): Partial { return new Bid(identifiers); }