getRecord

tcmts.atproto.getRecord · #z47gy2af · function · runs on the server

uses tcmts.atproto.pdsOf, which uses tcmts.atproto.localNetwork, which uses process

A record, as its author's PDS serves it, without signing in: by its at:// URI, or its DID, collection and key. Undefined if there's none. Not checked against their repository's signature: #iqqihysc is.

import { atUri, didDocument, guardedFetch, okJson, pdsOf } from "#codebase/tcmts/atproto";

export async function getRecord<T = Record<string, unknown>>(
  at: string | { did: string; collection: string; rkey: string },
): Promise<{ uri: string; cid: string; value: T } | undefined> {
  const { did, collection, rkey } = typeof at === "string" ? atUri(at) : at;
  const pds = pdsOf(await didDocument(did), did);
  const q = new URLSearchParams({ repo: did, collection, rkey });
  const res = await guardedFetch(`${pds}/xrpc/com.atproto.repo.getRecord?${q}`, `${did}'s PDS`, {
    headers: { accept: "application/json" },
  });
  if (res.status === 400 || res.status === 404) return undefined;
  return okJson(res, `${did}'s ${collection}/${rkey}`);
}

uses

used by