@adcp/sdk API Reference - v7.9.0
    Preparing search index...

    Function createOAuthPassthroughResolver

    • Create an accounts.resolve implementation that resolves buyer-supplied AccountReference against an upstream OAuth-protected listing endpoint. Returns just the resolve function — adapters compose it into their own AccountStore (typically alongside a no-op upsert since Shape B adapters don't manage account lifecycle).

      Type Parameters

      • TUpstreamRow extends Record<string, unknown>
      • TCtxMeta = Record<string, unknown>

      Returns (
          ref: AccountReference | undefined,
          ctx?: ResolveContext,
      ) => Promise<Account<TCtxMeta> | null>

      import {
      createUpstreamHttpClient,
      createOAuthPassthroughResolver,
      defineSalesPlatform,
      } from '@adcp/sdk/server';

      const snap = createUpstreamHttpClient({
      baseUrl: 'https://adsapi.snapchat.com',
      auth: {
      kind: 'dynamic_bearer',
      getToken: async (ctx) => (ctx as any)?.authInfo?.credential?.token,
      },
      });

      const resolve = createOAuthPassthroughResolver({
      httpClient: snap,
      listEndpoint: '/v1/me/adaccounts',
      idField: 'id',
      rowsPath: 'adaccounts',
      toAccount: (row, ctx) => ({
      id: row.id,
      name: row.name,
      status: 'active',
      advertiser: row.advertiser_url,
      ctx_metadata: {
      upstreamId: row.id,
      // Treat as secret — see `toAccount` JSDoc above.
      accessToken: (ctx as any)?.authInfo?.credential?.token,
      },
      }),
      cache: { ttlMs: 60_000 },
      });

      defineSalesPlatform({
      accounts: { resolve },
      ...
      });

      Behavior:

      • The factory only handles the { account_id } discriminated-union arm. Other arms ({ brand, operator }) and undefined ref return null without calling upstream.
      • Upstream throws (4xx/5xx other than 404) propagate verbatim — adopters compose composeMethod over the result if they want to catch and map to a typed envelope (e.g. throw AdcpError('AUTH_REQUIRED') on 401).
      • Cache is opt-in and listing-keyed: one upstream hit per buyer per TTL window regardless of how many account_ids that buyer queries.