Add Prebid.js NPM integration with per-module JS builds#242
Conversation
- Add `Proxy.certificate_check` setting (defaults to true for secure production) - Add `compute_host_header()` to properly format Host header with non-standard ports - Extend `ensure_origin_backend()` with certificate_check parameter - Include cert setting in backend name to avoid reusing backends with different settings - Add comprehensive tests for port preservation in proxy signing and HTML rewriting - Update all call sites to pass certificate_check=true (secure default) This fixes an issue where backends behind reverse proxies would generate URLs without the port when the Host header didn't include it.
- Add prebid.js ^10.18.0 as a dependency - Add prebid integration module that configures Prebid for server-side bidding - Configure s2sConfig to route bid requests through Trusted Server's /ad/auction endpoint - Include required Prebid modules: prebidServerBidAdapter, consentManagement, consentManagementGpp The integration: - Sets up server-side bidding with dynamic bidder discovery - Routes all bid requests through the Trusted Server proxy - Auto-configures Prebid on module load
fed073e to
a9569b6
Compare
There was a problem hiding this comment.
Looks good, currently isn't working for me, I get bids back from trusted server but nothing renders and I get this error:
ERROR: Trying to make a request for bidder that does not exist: mocktioneer (client side error)
I'm not sure if there's more setup I need or if this isn't 100% done yet.
…ich includes changes to how bidder settings are configured.
@ChristianPavilonis I am made a small tweak to JS to set Here is my config that worked: Please make sure to configure |
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Let's fix the possible panic
…dded a test for the prebid integration.
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Looks good overall, tested it locally.
|
@aram356 to test Kargo request |
…sher overwrites The bidderSettings with allowedAlternateBidderCodes: ['*'] was being set once at init time, but publisher code that reassigns pbjs.bidderSettings would drop the trustedServer entry, causing Prebid to reject bids from alternate seat codes (e.g. "mocktioneer") with "Bidder code is not allowed by allowedAlternateBidderCodes". Moving it into the requestBids shim ensures the setting is re-applied before every auction.
Summary
Replaces the old Prebid extension shim (
ext/prebidjs.ts) with a full NPM-bundled Prebid.js integration and introduces per-module JS builds with runtime concatenation.Prebid.js NPM Integration
prebid.js ^10.18.0directly (replaces the old shim that expected a publisher-providedpbjsglobal)trustedServerbid adapter that routes all bid requests through the/auctionorchestrator endpointpbjs.requestBids()to inject thetrustedServerbidder into every ad unit automaticallyaccount_id,timeout,debug,bidders) injected viawindow.__tsjs_prebidfromtrusted-server.tomltrustedServerbidder placeholder to real PBS bidders (e.g.,mocktioneer) before forwarding to Prebid ServerPer-Module JS Build Pipeline
tsjs-core.js,tsjs-prebid.js,tsjs-creative.js, etc.)build-all.mjsscript replaces the single Vite build, building core + each integration in parallelbuild.rsauto-discoversdist/tsjs-*.jsfiles and generatestsjs_modules.rswithinclude_str!()for eachIntegrationRegistryconfig/static/tsjs=tsjs-unified.min.js?v=<hash>for backward compatibilityAuction Flow (Browser → Server → PBS)
trustedServeradapter →POST /auction(AdRequest format)handle_auction→AuctionOrchestrator→PrebidAuctionProvidertrustedServer→ configured biddersPOST {server_url}/openrtb2/auction→ Prebid ServerBug Fixes
window.__tsjs_prebid) are now injected before the bundle<script>tag so the bundle's auto-init code can read them. Previously the bundle loaded first, causing config values (liketimeout) to be ignored in favor of defaults.parse_responseerror logging now usesfloor_char_boundary(1000)instead of a raw byte-index slice, preventing a panic when byte 1000 falls inside a multibyte character.Core JS Cleanup
getAllCodes,isArray,renderCreativeIntoSlot,writeHtmlToIframeConfig→config.ts,RequestAdsCallback/RequestAdsOptions→request.tsRequestModeenumtypes.tsnow only contains the public API contract (TsjsApi,AdUnit,Size)Key Files Changed
crates/js/lib/src/integrations/prebid/index.ts(new)crates/js/lib/src/core/auction.ts(new),request.tsbuild-all.mjs(new),build.rs,bundle.rs,vite.config.tsregistry.rs(js_module_ids()),tsjs.rs,html_processor.rs,publisher.rsprebid.rs(head injector, bidder expansion, logging)ext/prebidjs.ts,ext/index.ts,ext/types.ts,ext/prebidjs.test.tsBundle Size Impact
Publishers without Prebid: ~15KB (core only, down from ~218KB unified)
Publishers with Prebid: ~215KB (core + prebid module, similar to before)
Test plan
npx vitest run— 150 JS tests pass (16 test files)cargo test --workspace— 361 Rust tests passnpm run build— 8 module files produced indist//auctionrequest fires on live pagetsjs-prebid.jsstaginggetpurpose.aiCloses #250
Related to #179