Skip to content

Add authenticated S2S batch sync endpoint#558

Draft
ChristianPavilonis wants to merge 1 commit intofeature/ec-bidstream-decorationfrom
feature/ec-s2s-batch-sync
Draft

Add authenticated S2S batch sync endpoint#558
ChristianPavilonis wants to merge 1 commit intofeature/ec-bidstream-decorationfrom
feature/ec-s2s-batch-sync

Conversation

@ChristianPavilonis
Copy link
Collaborator

Summary

  • Add POST /api/v1/sync S2S batch sync endpoint with Bearer-token partner auth, per-partner rate limiting, request validation, per-mapping processing, and 200/207 response behavior.
  • Add KV write path upsert_partner_id_if_exists returning explicit outcomes (Written, NotFound, ConsentWithdrawn, Stale) so batch sync can reject unknown hashes, block withdrawn consent, and treat stale timestamps as accepted no-ops.
  • Reuse sync rate-limit primitives by exposing RateLimiter/FastlyRateLimiter and route S2S sync in the adapter with direct return (skipping EC cookie finalize middleware for non-browser traffic).

Details

  • New module: crates/trusted-server-core/src/ec/batch_sync.rs
    • Parses Authorization: Bearer <token>
    • Authenticates via PartnerStore::find_by_api_key_hash(hash_api_key(token))
    • Enforces per-partner rate limit using partner.batch_rate_limit
    • Validates max batch size (1000), hash format, non-empty partner_uid, required timestamp
    • Normalizes incoming ssc_hash to lowercase before KV lookup
    • Returns JSON summary { accepted, rejected, errors[] }
  • KV updates: crates/trusted-server-core/src/ec/kv.rs
    • UpsertResult enum
    • upsert_partner_id_if_exists(...) CAS write without auto-create
  • Adapter route: crates/trusted-server-adapter-fastly/src/main.rs
    • Wires POST /api/v1/sync
    • Skips ec_finalize_response for this S2S endpoint

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace (798 tests)
  • cd crates/js/lib && npx vitest run (282 tests)

Closes

Implement Story 8 (#541): POST /api/v1/sync with Bearer API key auth,
per-partner rate limiting, batch size cap, per-mapping validation and
rejection reasons, 200/207 response semantics, tolerant Bearer parsing,
and KV-abort on store unavailability.
@ChristianPavilonis ChristianPavilonis force-pushed the feature/ec-bidstream-decoration branch from f26c040 to 8226904 Compare March 26, 2026 00:00
@ChristianPavilonis ChristianPavilonis force-pushed the feature/ec-s2s-batch-sync branch from fa846e3 to 65f6c4d Compare March 26, 2026 00:00
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.

1 participant