Skip to content

Conversation

@aram356
Copy link
Collaborator

@aram356 aram356 commented Feb 5, 2026

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

  • Bundles prebid.js ^10.18.0 directly (replaces the old shim that expected a publisher-provided pbjs global)
  • Registers a custom trustedServer bid adapter that routes all bid requests through the /auction orchestrator endpoint
  • Shims pbjs.requestBids() to inject the trustedServer bidder into every ad unit automatically
  • Server-side config (account_id, timeout, debug, bidders) injected via window.__tsjs_prebid from trusted-server.toml
  • Server expands the trustedServer bidder placeholder to real PBS bidders (e.g., mocktioneer) before forwarding to Prebid Server

Per-Module JS Build Pipeline

  • Each integration is now built as a separate IIFE at compile time (tsjs-core.js, tsjs-prebid.js, tsjs-creative.js, etc.)
  • New build-all.mjs script replaces the single Vite build, building core + each integration in parallel
  • build.rs auto-discovers dist/tsjs-*.js files and generates tsjs_modules.rs with include_str!() for each
  • At runtime, the server concatenates only enabled modules based on IntegrationRegistry config
  • Module selection is now a config change — no JS rebuild needed
  • URL stays /static/tsjs=tsjs-unified.min.js?v=<hash> for backward compatibility

Auction Flow (Browser → Server → PBS)

  1. Browser: Prebid.js trustedServer adapter → POST /auction (AdRequest format)
  2. Server: handle_auctionAuctionOrchestratorPrebidAuctionProvider
  3. Server: Converts AdRequest to OpenRTB, expands trustedServer → configured bidders
  4. Server: POST {server_url}/openrtb2/auction → Prebid Server
  5. Server: Parses OpenRTB response, rewrites creatives → returns to browser

Core JS Cleanup

  • Removed dead exports: getAllCodes, isArray, renderCreativeIntoSlot, writeHtmlToIframe
  • Moved types to proper modules: Configconfig.ts, RequestAdsCallback/RequestAdsOptionsrequest.ts
  • Removed unused RequestMode enum
  • types.ts now only contains the public API contract (TsjsApi, AdUnit, Size)

Key Files Changed

Area Files
Prebid adapter crates/js/lib/src/integrations/prebid/index.ts (new)
Shared auction crates/js/lib/src/core/auction.ts (new), request.ts
Build pipeline build-all.mjs (new), build.rs, bundle.rs, vite.config.ts
Module registry registry.rs (js_module_ids()), tsjs.rs, html_processor.rs, publisher.rs
Prebid server-side prebid.rs (head injector, bidder expansion, logging)
Deleted ext/prebidjs.ts, ext/index.ts, ext/types.ts

Bundle 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 — 148 JS tests pass (16 test files)
  • cargo test --workspace — 353 Rust tests pass
  • npm run build — 8 module files produced in dist/
  • Playwright diagnostic confirms /auction request fires on live page
  • Verify Prebid Server returns 200 with valid stored request / account config
  • Verify creative rendering in iframe after successful auction
  • Test with Prebid disabled — verify bundle excludes tsjs-prebid.js

Closes #250
Related to #179

- 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
@aram356 aram356 marked this pull request as draft February 5, 2026 19:35
@aram356 aram356 self-assigned this Feb 5, 2026
@aram356 aram356 added enhancement New feature or request and removed enhancement New feature or request labels Feb 5, 2026
Base automatically changed from feature/cert-verification-port-handling to main February 9, 2026 19:42
@aram356 aram356 linked an issue Feb 10, 2026 that may be closed by this pull request
@aram356 aram356 changed the title Add Prebid.js NPM integration Add Prebid.js NPM integration with per-module JS builds Feb 11, 2026
@aram356 aram356 marked this pull request as ready for review February 11, 2026 05:48
@prk-Jr prk-Jr force-pushed the feature/prebid-npm-integration branch from fed073e to a9569b6 Compare February 11, 2026 09:12
Copy link
Collaborator

@ChristianPavilonis ChristianPavilonis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

I'm not sure if there's more setup I need or if this isn't 100% done yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Prebid.js NPM integration

2 participants