Commit 7e5f2c4
feat(decisioning): createUpstreamHttpClient + createTranslationMap (#464)
* feat(decisioning): createUpstreamHttpClient + createTranslationMap (translator helpers)
Port the JS @adcp/sdk@6.7 helpers to Python so translator-pattern
adopters (Prebid, GAM-shaped publishers, the v3 reference seller) stop
hand-rolling the same ~200 lines of httpx boilerplate per adapter.
create_upstream_http_client wraps httpx.AsyncClient with auth
injection (StaticBearer / DynamicBearer / ApiKey / NoAuth as a
discriminated dataclass union), default-header merge, query-string
serialization, 404→None for resource lookups, and projection of
non-2xx responses to spec-conformant AdcpError codes (AUTH_REQUIRED,
PERMISSION_DENIED, MEDIA_BUY_NOT_FOUND, RATE_LIMITED,
SERVICE_UNAVAILABLE, INVALID_REQUEST). DynamicBearer.get_token
receives a per-call auth_context so the same client supports
single-key tenant fan-out, per-operator credential lookup, and
pass-through of the caller's principal without per-operator client
construction. The 404 code is configurable per call via
not_found_code for endpoints whose missing-resource semantics aren't
a media buy.
create_translation_map provides a bidirectional, type-safe key
mapping (AdCP wire ↔ upstream platform values) with to_upstream /
to_adcp / has_adcp / has_upstream methods. Collisions in either
direction are detected at construction time so silent overwrite can't
produce wrong-tenant routing in production.
Doesn't refactor the v3 reference seller's hand-rolled upstream.py
to use the helpers — that's a follow-up.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(upstream): treat 3xx as error gate + widen return type to Any (#464 fix-pack)
Code reviewer flagged two should-fix issues:
1. response.status_code >= 400 skipped 3xx redirects, which then crashed
on response.json() for non-JSON redirect bodies. Lowered to >= 300.
httpx defaults to no auto-follow, so any 3xx from a misconfigured
upstream now produces a structured AdcpError instead of a JSONDecodeError.
2. Return type was dict[str, Any] but JSON arrays/scalars at the top
level (list endpoints) violated the annotation. Widened to Any —
adopters narrow at the call site.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 9301acf commit 7e5f2c4
4 files changed
Lines changed: 1044 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
155 | 159 | | |
156 | 160 | | |
157 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
158 | 172 | | |
159 | 173 | | |
160 | 174 | | |
| |||
195 | 209 | | |
196 | 210 | | |
197 | 211 | | |
| 212 | + | |
198 | 213 | | |
| 214 | + | |
199 | 215 | | |
200 | 216 | | |
201 | 217 | | |
| |||
218 | 234 | | |
219 | 235 | | |
220 | 236 | | |
| 237 | + | |
221 | 238 | | |
222 | 239 | | |
223 | 240 | | |
| |||
231 | 248 | | |
232 | 249 | | |
233 | 250 | | |
| 251 | + | |
234 | 252 | | |
235 | 253 | | |
236 | 254 | | |
| |||
249 | 267 | | |
250 | 268 | | |
251 | 269 | | |
| 270 | + | |
252 | 271 | | |
253 | 272 | | |
254 | 273 | | |
255 | 274 | | |
| 275 | + | |
256 | 276 | | |
| 277 | + | |
| 278 | + | |
257 | 279 | | |
258 | 280 | | |
259 | 281 | | |
| |||
262 | 284 | | |
263 | 285 | | |
264 | 286 | | |
| 287 | + | |
| 288 | + | |
265 | 289 | | |
266 | 290 | | |
267 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
0 commit comments