Skip to content

Commit 403d17f

Browse files
Add EC sync and identify endpoints
1 parent e6ed6d3 commit 403d17f

5 files changed

Lines changed: 997 additions & 0 deletions

File tree

crates/trusted-server-adapter-fastly/src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use trusted_server_core::constants::{
1212
};
1313
use trusted_server_core::ec::admin::handle_register_partner;
1414
use trusted_server_core::ec::finalize::ec_finalize_response;
15+
use trusted_server_core::ec::identify::{cors_preflight_identify, handle_identify};
1516
use trusted_server_core::ec::kv::KvIdentityGraph;
1617
use trusted_server_core::ec::partner::PartnerStore;
18+
use trusted_server_core::ec::sync_pixel::handle_sync;
1719
use trusted_server_core::ec::EcContext;
1820
use trusted_server_core::error::TrustedServerError;
1921
use trusted_server_core::geo::GeoInfo;
@@ -137,6 +139,18 @@ async fn route_request(
137139
require_partner_store(settings).and_then(|store| handle_register_partner(&store, req))
138140
}
139141

142+
(Method::GET, "/sync") => require_identity_graph(settings).and_then(|kv| {
143+
require_partner_store(settings).and_then(|partner_store| {
144+
handle_sync(settings, &kv, &partner_store, &req, &mut ec_context)
145+
})
146+
}),
147+
(Method::GET, "/identify") => require_identity_graph(settings).and_then(|kv| {
148+
require_partner_store(settings).and_then(|partner_store| {
149+
handle_identify(settings, &kv, &partner_store, &req, &ec_context)
150+
})
151+
}),
152+
(Method::OPTIONS, "/identify") => cors_preflight_identify(settings, &req),
153+
140154
// Unified auction endpoint (returns creative HTML inline)
141155
(Method::POST, "/auction") => {
142156
handle_auction(settings, orchestrator, kv_graph.as_ref(), &ec_context, req).await
@@ -268,3 +282,17 @@ fn require_partner_store(settings: &Settings) -> Result<PartnerStore, Report<Tru
268282
})?;
269283
Ok(PartnerStore::new(store_name))
270284
}
285+
286+
/// Constructs a `KvIdentityGraph` from settings, or returns 503 if the
287+
/// `ec_store` config is not set.
288+
fn require_identity_graph(
289+
settings: &Settings,
290+
) -> Result<KvIdentityGraph, Report<TrustedServerError>> {
291+
let store_name = settings.ec.ec_store.as_deref().ok_or_else(|| {
292+
Report::new(TrustedServerError::KvStore {
293+
store_name: "ec.ec_store".to_owned(),
294+
message: "ec.ec_store is not configured".to_owned(),
295+
})
296+
})?;
297+
Ok(KvIdentityGraph::new(store_name))
298+
}

crates/trusted-server-core/src/constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pub const COOKIE_TS_EC: &str = "ts-ec";
44

55
pub const HEADER_X_PUB_USER_ID: HeaderName = HeaderName::from_static("x-pub-user-id");
66
pub const HEADER_X_TS_EC: HeaderName = HeaderName::from_static("x-ts-ec");
7+
pub const HEADER_X_TS_EIDS: HeaderName = HeaderName::from_static("x-ts-eids");
8+
pub const HEADER_X_TS_EC_CONSENT: HeaderName = HeaderName::from_static("x-ts-ec-consent");
9+
pub const HEADER_X_TS_EIDS_TRUNCATED: HeaderName = HeaderName::from_static("x-ts-eids-truncated");
710
pub const HEADER_X_CONSENT_ADVERTISING: HeaderName =
811
HeaderName::from_static("x-consent-advertising");
912
pub const HEADER_X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
@@ -44,6 +47,9 @@ pub const HEADER_REFERER: HeaderName = HeaderName::from_static("referer");
4447
/// in `const` context.
4548
pub const INTERNAL_HEADERS: &[&str] = &[
4649
"x-ts-ec",
50+
"x-ts-eids",
51+
"x-ts-ec-consent",
52+
"x-ts-eids-truncated",
4753
"x-pub-user-id",
4854
"x-subject-id",
4955
"x-consent-advertising",

0 commit comments

Comments
 (0)