Skip to content

Commit 0c0e4fa

Browse files
use new impl
1 parent c24f144 commit 0c0e4fa

5 files changed

Lines changed: 383 additions & 191 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sha2 = { workspace = true }
4343
tokio = { workspace = true }
4444
toml = { workspace = true }
4545
trusted-server-js = { path = "../js" }
46+
trusted-server-openrtb = { path = "../openrtb" }
4647
url = { workspace = true }
4748
urlencoding = { workspace = true }
4849
uuid = { workspace = true }

crates/common/src/auction/formats.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::auction::context::ContextValue;
1616
use crate::creative;
1717
use crate::error::TrustedServerError;
1818
use crate::geo::GeoInfo;
19-
use crate::openrtb::{OpenRtbBid, OpenRtbResponse, ResponseExt, SeatBid};
19+
use crate::openrtb::{
20+
build_openrtb_bid, build_openrtb_response, build_seat_bid, maybe_object_from_serializable,
21+
OpenRtbBidFields, ResponseExt,
22+
};
2023
use crate::settings::Settings;
2124
use crate::synthetic::{generate_synthetic_id, get_or_generate_synthetic_id};
2225

@@ -240,21 +243,18 @@ pub fn convert_to_openrtb_response(
240243
String::new()
241244
};
242245

243-
let openrtb_bid = OpenRtbBid {
246+
let openrtb_bid = build_openrtb_bid(OpenRtbBidFields {
244247
id: format!("{}-{}", bid.bidder, slot_id),
245248
impid: slot_id.to_string(),
246249
price,
247250
adm: Some(creative_html),
248251
crid: Some(format!("{}-creative", bid.bidder)),
249-
w: Some(bid.width),
250-
h: Some(bid.height),
252+
width: Some(bid.width),
253+
height: Some(bid.height),
251254
adomain: Some(bid.adomain.clone().unwrap_or_default()),
252-
};
253-
254-
seatbids.push(SeatBid {
255-
seat: Some(bid.bidder.clone()),
256-
bid: vec![openrtb_bid],
257255
});
256+
257+
seatbids.push(build_seat_bid(Some(bid.bidder.clone()), vec![openrtb_bid]));
258258
}
259259

260260
// Determine strategy name for response metadata
@@ -271,10 +271,10 @@ pub fn convert_to_openrtb_response(
271271
.map(ProviderSummary::from)
272272
.collect();
273273

274-
let response_body = OpenRtbResponse {
275-
id: auction_request.id.to_string(),
276-
seatbid: seatbids,
277-
ext: Some(ResponseExt {
274+
let response_body = build_openrtb_response(
275+
auction_request.id.to_string(),
276+
seatbids,
277+
maybe_object_from_serializable(&ResponseExt {
278278
orchestrator: OrchestratorExt {
279279
strategy: strategy_name.to_string(),
280280
providers: result.provider_responses.len(),
@@ -283,7 +283,7 @@ pub fn convert_to_openrtb_response(
283283
provider_details,
284284
},
285285
}),
286-
};
286+
);
287287

288288
let body_bytes =
289289
serde_json::to_vec(&response_body).change_context(TrustedServerError::Auction {

crates/common/src/integrations/prebid.rs

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ use crate::integrations::{
2323
IntegrationRegistration,
2424
};
2525
use crate::openrtb::{
26-
Banner, Device, Format, Geo, Imp, ImpExt, OpenRtbRequest, PrebidExt, PrebidImpExt, Regs,
27-
RegsExt, RequestExt, Site, TrustedServerExt, User, UserExt,
26+
build_banner, build_device, build_format, build_geo, build_imp, build_openrtb_request,
27+
build_regs, build_site, build_user, maybe_object_from_serializable, ImpExt, OpenRtbRequest,
28+
PrebidExt, PrebidImpExt, RegsExt, RequestExt, TrustedServerExt, UserExt,
2829
};
2930
use crate::request_signing::{RequestSigner, SigningParams, SIGNING_VERSION};
3031
use crate::settings::{IntegrationConfig, Settings};
@@ -488,18 +489,15 @@ impl PrebidAuctionProvider {
488489
context: &AuctionContext<'_>,
489490
signer: Option<(&RequestSigner, String, &SigningParams)>,
490491
) -> OpenRtbRequest {
491-
let imps: Vec<Imp> = request
492+
let imps = request
492493
.slots
493494
.iter()
494495
.map(|slot| {
495-
let formats: Vec<Format> = slot
496+
let formats = slot
496497
.formats
497498
.iter()
498499
.filter(|f| f.media_type == MediaType::Banner)
499-
.map(|f| Format {
500-
w: f.width,
501-
h: f.height,
502-
})
500+
.map(|f| build_format(f.width, f.height))
503501
.collect();
504502

505503
// Extract zone from trustedServer params (sent by the JS
@@ -552,13 +550,13 @@ impl PrebidAuctionProvider {
552550
}
553551
}
554552

555-
Imp {
556-
id: slot.id.clone(),
557-
banner: Some(Banner { format: formats }),
558-
ext: Some(ImpExt {
553+
build_imp(
554+
slot.id.clone(),
555+
Some(build_banner(formats)),
556+
maybe_object_from_serializable(&ImpExt {
559557
prebid: PrebidImpExt { bidder },
560558
}),
561-
}
559+
)
562560
})
563561
.collect();
564562

@@ -572,35 +570,36 @@ impl PrebidAuctionProvider {
572570
});
573571

574572
// Build user object
575-
let user = Some(User {
576-
id: Some(request.user.id.clone()),
577-
ext: Some(UserExt {
573+
let user = Some(build_user(
574+
Some(request.user.id.clone()),
575+
maybe_object_from_serializable(&UserExt {
578576
synthetic_fresh: Some(request.user.fresh_id.clone()),
579577
}),
580-
});
578+
));
581579

582580
// Build device object with user-agent, client IP, and geo if available.
583581
// Forwarding the real client IP is critical: without it PBS infers the
584582
// IP from the incoming connection (a data-center / edge IP), causing
585583
// bidders like PubMatic to filter the traffic as non-human.
586-
let device = request.device.as_ref().map(|d| Device {
587-
ua: d.user_agent.clone(),
588-
ip: d.ip.clone(),
589-
geo: d.geo.as_ref().map(|geo| Geo {
590-
geo_type: 2, // IP address per OpenRTB spec
591-
country: Some(geo.country.clone()),
592-
city: Some(geo.city.clone()),
593-
region: geo.region.clone(),
594-
}),
584+
let device = request.device.as_ref().map(|d| {
585+
build_device(
586+
d.user_agent.clone(),
587+
d.ip.clone(),
588+
d.geo.as_ref().map(|geo| {
589+
build_geo(
590+
Some(geo.country.clone()),
591+
Some(geo.city.clone()),
592+
geo.region.clone(),
593+
)
594+
}),
595+
)
595596
});
596597

597598
// Build regs object if Sec-GPC header is present
598599
let regs = if context.request.get_header("Sec-GPC").is_some() {
599-
Some(Regs {
600-
ext: Some(RegsExt {
601-
us_privacy: Some("1YYN".to_string()),
602-
}),
603-
})
600+
Some(build_regs(maybe_object_from_serializable(&RegsExt {
601+
us_privacy: Some("1YYN".to_string()),
602+
})))
604603
} else {
605604
None
606605
};
@@ -620,7 +619,7 @@ impl PrebidAuctionProvider {
620619

621620
let debug_enabled = self.config.debug;
622621

623-
let ext = Some(RequestExt {
622+
let ext = maybe_object_from_serializable(&RequestExt {
624623
prebid: Some(PrebidExt {
625624
debug: debug_enabled.then_some(true),
626625
returnallbidstatus: debug_enabled.then_some(true),
@@ -635,19 +634,16 @@ impl PrebidAuctionProvider {
635634
}),
636635
});
637636

638-
OpenRtbRequest {
639-
id: request.id.clone(),
640-
imp: imps,
641-
site: Some(Site {
642-
domain: Some(request.publisher.domain.clone()),
643-
page: page_url,
644-
}),
637+
build_openrtb_request(
638+
request.id.clone(),
639+
imps,
640+
Some(build_site(Some(request.publisher.domain.clone()), page_url)),
645641
user,
646642
device,
647643
regs,
648-
test: self.config.test_mode.then_some(1),
644+
self.config.test_mode.then_some(1),
649645
ext,
650-
}
646+
)
651647
}
652648

653649
/// Parse `OpenRTB` response into auction response.

0 commit comments

Comments
 (0)