Consolidate slot config into trusted-server.toml and namespace window globals under window._ts#745
Draft
prk-Jr wants to merge 5 commits into
Draft
Conversation
…ver.toml Add [[creative_opportunities.slot]] array to trusted-server.toml and remove the separate creative-opportunities.toml file. Slots now deserialize directly into CreativeOpportunitiesConfig.slot via the existing vec_from_seq_or_map deserializer, with compile_slots() called in Settings::prepare_runtime(). Update publisher.rs and main.rs function signatures from &CreativeOpportunitiesFile to &[CreativeOpportunitySlot]. Build.rs slot-ID validation now reads from the merged settings rather than a separate file.
Replace 7 flat `window.__ts*` globals with properties on a single
`window._ts` namespace object:
window.__ts_ad_slots → window._ts.adSlots
window.__ts_bids → window._ts.bids
window.__tsAdInit → window._ts.adInit
window.__tsPrevGptSlots → window._ts.prevGptSlots
window.__tsServicesEnabled → window._ts.servicesEnabled
window.__tsDivToSlotId → window._ts.divToSlotId
window.__tsSpaHookInstalled → window._ts.spaHookInstalled
Both publisher.rs injected scripts and the JS/TS bundle now initialise
`window._ts` with `||{}` before accessing any property, so the bootstrap
script and TSJS bundle are safe to run in either order.
Add clarifying comments around the ts.bids snapshot vs live-read distinction in installTsAdInit() so the intentional SPA correctness design is self-documenting. Remove the erroneous re-assignment of tw._ts after delete in beforeEach so '_ts' in window is reliably false between tests.
- Narrow `formats` from `Array<number[]>` to `Array<[number, number]>` so each format is statically typed as exactly width + height. - Remove the now-unnecessary `as Array<number | number[]>` cast at the `defineSlot` call site — `[number, number]` satisfies `number[]` which satisfies `number | number[]`. - Extract `TS_INITIAL_TARGETING_KEY = 'ts_initial' as const` and use it in the `setTargeting` call; the bootstrap JS already carries the "Keep in sync with TS_INITIAL_TARGETING_KEY" comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
trusted-server.toml: the separatecreative-opportunities.tomlfile is removed. All[[creative_opportunities.slot]]entries now live inside the main config file, giving them the same env-var override mechanism as other settings (TRUSTED_SERVER__CREATIVE_OPPORTUNITIES__SLOT='[...]'). Thebuild.rsvalidator now reads fromtrusted-server.tomldirectly.window._ts: seven flatwindow.__ts*properties are collapsed into a singlewindow._tsobject. This reduces window namespace pollution from 7 properties to 1 and makes the Trusted Server presence on the page discoverable via a single well-known key.TsAdSlot.formatstype corrected andts_initialconstant extracted for clarity in the GPT bootstrap script.Breaking change — JS globals rename
Publishers and downstream integrations that read
window.__ts*variables must update towindow._ts.*:window.__ts_ad_slotswindow._ts.adSlotswindow.__ts_bidswindow._ts.bidswindow.__tsAdInitwindow._ts.adInitwindow.__tsPrevGptSlotswindow._ts.prevGptSlotswindow.__tsServicesEnabledwindow._ts.servicesEnabledwindow.__tsDivToSlotIdwindow._ts.divToSlotIdwindow.__tsSpaHookInstalledwindow._ts.spaHookInstalledReading server-injected bid data in the browser:
Slot config — new location in
trusted-server.tomlChanged files
creative-opportunities.tomltrusted-server.tomltrusted-server.toml[[creative_opportunities.slot]]entriescrates/trusted-server-core/build.rstrusted-server.toml; removedcreative-opportunities.tomlpathcrates/trusted-server-core/src/settings.rscrates/trusted-server-core/src/creative_opportunities.rscrates/trusted-server-core/src/html_processor.rswindow._tsinitializer instead of individual flat globalscrates/trusted-server-core/src/publisher.rswindow._ts.bidscrates/trusted-server-core/src/integrations/gpt.rswindow._ts.*keyscrates/trusted-server-core/src/integrations/gpt_bootstrap.jsts_initialconstant; fixedformatstypecrates/trusted-server-core/src/auction/endpoints.rscrates/trusted-server-adapter-fastly/src/main.rscrates/trusted-server-adapter-fastly/src/route_tests.rscrates/js/lib/src/integrations/gpt/index.tswindow.__ts*references renamed towindow._ts.*crates/js/lib/src/integrations/gpt/index.test.tswindow._tsdocs/superpowers/plans/2026-05-29-pr680-reviewer-findings.mdTest plan
cargo fmt --all -- --check— passescargo clippy --workspace --all-targets --all-features -- -D warnings— passescargo test --workspace— 1,054 tests pass (20 + 1010 + 21 + 3)cd crates/js/lib && npx vitest run— 300 tests passcd crates/js/lib && npm run format— passescd docs && npm run format— passes (formatting fix committed)fastly compute serveand confirmwindow._tsis populated in browser devtoolswindow.__ts_bidshave been updated or notified