Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/common",
"crates/fastly",
"crates/js",
"crates/openrtb",
]

# Build defaults exclude the web-only tsjs crate, which is compiled via wasm-pack.
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ serde_json = { workspace = true }
sha2 = { workspace = true }
tokio = { workspace = true }
trusted-server-js = { path = "../js" }
trusted-server-openrtb = { path = "../openrtb" }
url = { workspace = true }
urlencoding = { workspace = true }
uuid = { workspace = true }
Expand Down
28 changes: 14 additions & 14 deletions crates/common/src/auction/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use crate::auction::types::OrchestratorExt;
use crate::creative;
use crate::error::TrustedServerError;
use crate::geo::GeoInfo;
use crate::openrtb::{OpenRtbBid, OpenRtbResponse, ResponseExt, SeatBid};
use crate::openrtb::{
build_openrtb_bid, build_openrtb_response, build_seat_bid, maybe_object_from_serializable,
OpenRtbBidFields, ResponseExt,
};
use crate::settings::Settings;
use crate::synthetic::{generate_synthetic_id, get_or_generate_synthetic_id};

Expand Down Expand Up @@ -206,21 +209,18 @@ pub fn convert_to_openrtb_response(
String::new()
};

let openrtb_bid = OpenRtbBid {
let openrtb_bid = build_openrtb_bid(OpenRtbBidFields {
id: format!("{}-{}", bid.bidder, slot_id),
impid: slot_id.to_string(),
price,
adm: Some(creative_html),
crid: Some(format!("{}-creative", bid.bidder)),
w: Some(bid.width),
h: Some(bid.height),
width: Some(bid.width),
height: Some(bid.height),
adomain: Some(bid.adomain.clone().unwrap_or_default()),
};

seatbids.push(SeatBid {
seat: Some(bid.bidder.clone()),
bid: vec![openrtb_bid],
});

seatbids.push(build_seat_bid(Some(bid.bidder.clone()), vec![openrtb_bid]));
}

// Determine strategy name for response metadata
Expand All @@ -230,18 +230,18 @@ pub fn convert_to_openrtb_response(
"parallel_only"
};

let response_body = OpenRtbResponse {
id: auction_request.id.to_string(),
seatbid: seatbids,
ext: Some(ResponseExt {
let response_body = build_openrtb_response(
auction_request.id.to_string(),
seatbids,
maybe_object_from_serializable(&ResponseExt {
orchestrator: OrchestratorExt {
strategy: strategy_name.to_string(),
providers: result.provider_responses.len(),
total_bids: result.total_bids(),
time_ms: result.total_time_ms,
},
}),
};
);

let body_bytes =
serde_json::to_vec(&response_body).change_context(TrustedServerError::Auction {
Expand Down
74 changes: 35 additions & 39 deletions crates/common/src/integrations/prebid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use crate::integrations::{
IntegrationEndpoint, IntegrationProxy, IntegrationRegistration,
};
use crate::openrtb::{
Banner, Device, Format, Geo, Imp, ImpExt, OpenRtbRequest, PrebidExt, PrebidImpExt, Regs,
RegsExt, RequestExt, Site, TrustedServerExt, User, UserExt,
build_banner, build_device, build_format, build_geo, build_imp, build_openrtb_request,
build_regs, build_site, build_user, maybe_object_from_serializable, ImpExt, OpenRtbRequest,
PrebidExt, PrebidImpExt, RegsExt, RequestExt, TrustedServerExt, UserExt,
};
use crate::request_signing::RequestSigner;
use crate::settings::{IntegrationConfig, Settings};
Expand Down Expand Up @@ -396,18 +397,15 @@ impl PrebidAuctionProvider {
context: &AuctionContext<'_>,
signer: Option<(&RequestSigner, String)>,
) -> OpenRtbRequest {
let imps: Vec<Imp> = request
let imps = request
.slots
.iter()
.map(|slot| {
let formats: Vec<Format> = slot
let formats = slot
.formats
.iter()
.filter(|f| f.media_type == MediaType::Banner)
.map(|f| Format {
w: f.width,
h: f.height,
})
.map(|f| build_format(f.width, f.height))
.collect();

// Use bidder params from the slot (passed through from the request)
Expand All @@ -424,13 +422,13 @@ impl PrebidAuctionProvider {
}
}

Imp {
id: slot.id.clone(),
banner: Some(Banner { format: formats }),
ext: Some(ImpExt {
build_imp(
slot.id.clone(),
Some(build_banner(formats)),
maybe_object_from_serializable(&ImpExt {
prebid: PrebidImpExt { bidder },
}),
}
)
})
.collect();

Expand All @@ -444,31 +442,32 @@ impl PrebidAuctionProvider {
});

// Build user object
let user = Some(User {
id: Some(request.user.id.clone()),
ext: Some(UserExt {
let user = Some(build_user(
Some(request.user.id.clone()),
maybe_object_from_serializable(&UserExt {
synthetic_fresh: Some(request.user.fresh_id.clone()),
}),
});
));

// Build device object with user-agent and geo if available
let device = request.device.as_ref().map(|d| Device {
ua: d.user_agent.clone(),
geo: d.geo.as_ref().map(|geo| Geo {
geo_type: 2, // IP address per OpenRTB spec
country: Some(geo.country.clone()),
city: Some(geo.city.clone()),
region: geo.region.clone(),
}),
let device = request.device.as_ref().map(|d| {
build_device(
d.user_agent.clone(),
d.geo.as_ref().map(|geo| {
build_geo(
Some(geo.country.clone()),
Some(geo.city.clone()),
geo.region.clone(),
)
}),
)
});

// Build regs object if Sec-GPC header is present
let regs = if context.request.get_header("Sec-GPC").is_some() {
Some(Regs {
ext: Some(RegsExt {
us_privacy: Some("1YYN".to_string()),
}),
})
Some(build_regs(maybe_object_from_serializable(&RegsExt {
us_privacy: Some("1YYN".to_string()),
})))
} else {
None
};
Expand All @@ -479,7 +478,7 @@ impl PrebidAuctionProvider {
.map(|(s, sig)| (Some(sig), Some(s.kid.clone())))
.unwrap_or((None, None));

let ext = Some(RequestExt {
let ext = maybe_object_from_serializable(&RequestExt {
prebid: if self.config.debug {
Some(PrebidExt { debug: Some(true) })
} else {
Expand All @@ -493,18 +492,15 @@ impl PrebidAuctionProvider {
}),
});

OpenRtbRequest {
id: request.id.clone(),
imp: imps,
site: Some(Site {
domain: Some(request.publisher.domain.clone()),
page: page_url,
}),
build_openrtb_request(
request.id.clone(),
imps,
Some(build_site(Some(request.publisher.domain.clone()), page_url)),
user,
device,
regs,
ext,
}
)
}

/// Parse `OpenRTB` response into auction response.
Expand Down
Loading