Repository navigation
feat(adapters): createOAuthPassthroughResolver (#1363) - #1369
Merged
Merged
Conversation
Standardize the canonical "Shape B" account-resolution pattern that every adapter wrapping a vendor OAuth + ad-account API (Snap, Meta, TikTok, LinkedIn, Reddit, Pinterest, etc.) re-derives by hand: extract bearer from ctx.authInfo → GET /me/adaccounts (or equivalent) → match upstream row by account_id → return tenant with ctx_metadata populated Without the factory, each adapter writes ~30 LOC of boilerplate; the agentic-adapters monorepo had this pattern repeated across 13 of 14 adapters when this issue was filed. The factory composes with createUpstreamHttpClient — adopters configure dynamic_bearer.getToken on the http client for per-buyer credential injection; the factory's getAuthContext output flows through as the authContext per-call option. Configurable shape: - idField (default 'id') — match column on the upstream row - rowsPath (default 'data', null = body is flat array) - getAuthContext (default forwards ctx?.authInfo verbatim) - toAccount mapper — adopter shapes the framework Account - cache opt-in TTL — auth-context-keyed so different buyers don't share cached entries; getCacheKey override for narrowing the cache dimension when authContext carries request-id noise Closes #1363. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#1369) Address expert-review findings on PR #1369: 1. **Listing-keyed cache** (product reviewer). Previous shape cached `(authContext, account_id) → Account` — N upstream hits for N account_ids on the same buyer. The whole point of /me/adaccounts is to return ALL accounts in one call; per-id caching defeats it. Cache now stores the full row array per buyer, resolves account_id matches in-memory within the TTL window. Memory cost trivial; the upstream-hit-rate win is meaningful for multi-account buyers calling 3-5 tools concurrently. 2. **SHA-256 cache key default** (security reviewer). Previous default was `JSON.stringify(authContext)` — embeds the raw bearer in Map keys for the TTL window. Heap dumps, util.inspect(cache), or debug logs that iterate the Map surface the token. Now hashes the serialized authContext (same isolation guarantee, no plaintext at rest). Adopters can still supply their own `getCacheKey` to narrow the dimension. 3. **maxEntries with LRU eviction** (code reviewer). Default 1024. Bounds memory under token-rotation churn; insertion-order Map iteration gives O(1) LRU eviction. 4. **JSDoc warnings**: - `toAccount` callout: treat ctx_metadata.accessToken as a secret; adopter throws/logs that include the account WILL leak it. - `cache.ttlMs` guidance: distinguish read-tool TTL (60-300s) from mutating-tool TTL (0-30s, or skip cache via composeMethod). Revoked-but-not-expired bearer would otherwise authorize mutations for the full TTL window. - `idField` footgun: when `TUpstreamRow` is inferred, `keyof & string` collapses and typos compile fine, silently always returning null. - `rowsPath` carve-out: TikTok's `data.list` and Google Ads' `customers:listAccessibleCustomers` are not direct fits. 5. **JSON.stringify failure fallback**: circular refs / BigInt / non-serializable auth contexts now produce a truncated literal key instead of throwing. New tests cover: listing-cache (1 buyer × 3 account_ids = 1 hit), sha256-stability (same token → cache hit; different token → miss), LRU eviction at maxEntries. Closes the open expert-review items on adcp-client#1369. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 3, 2026
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
Closes #1363. Standardizes the canonical "Shape B" account-resolution pattern that every adapter wrapping a vendor OAuth + ad-account API (Snap, Meta, TikTok, LinkedIn, Reddit, Pinterest, etc.) re-derives by hand:
Without the factory, each adapter writes ~30 LOC of boilerplate. The doha-v20 (
scope3data/agentic-adapters) monorepo had this pattern repeated across 13 of 14 adapters when #1363 was filed.Usage
Configurable shape
idField'id'rowsPath'data'null= body is flat arraygetAuthContext(ctx) => ctx?.authInfodynamic_bearer.getTokentoAccountAccount<TCtxMeta>mappercache.ttlMscache.getCacheKeyJSON.stringify(authContext)Behavior
{ account_id }arm —{ brand, operator }andundefinedref returnnullwithout calling upstreamcomposeMethodover the result for typed envelope mapping (e.g.AUTH_REQUIREDon 401)Test plan
test/server-adapters-oauth-passthrough-resolver.test.jscovering: ref-arm short-circuits, upstream lookup + match, no-match returns null, empty body returns null, error propagation, customidField/rowsPath/getAuthContext, cache hit/miss, TTL expiry, multi-buyer isolation, customgetCacheKey, public re-export from@adcp/sdknpm run build:libcleannpm run format:checkcleanSource
#1340 triage thread → #1363 spin-off. The 8–12 line snippet in the planned
docs/guides/account-resolution.md(PR #1357) is fine for one or two adopters; for a multi-adapter monorepo it's pure repetition. This factory is the ergonomic answer for that case.🤖 Generated with Claude Code