···
} from "@/lib/types/atproto";
+
ComAtprotoRepoGetRecordResponse} from "@/lib/types/lexicon/com.atproto.repo.getRecord";
+
comAtprotoRepoGetRecordResponseSchema,
+
} from "@/lib/types/lexicon/com.atproto.repo.getRecord";
import type { Result } from "@/lib/utils/result";
import type { DidDocumentResolver } from "@atcute/identity-resolver";
···
return { ok: false, error: responseParseError };
return { ok: true, data: record.value };
+
export const getCommitFromFullAtUri = async ({
+
}: AtUri): Promise<Result<ComAtprotoRepoGetRecordResponse, unknown>> => {
+
const didDocResult = await resolveDidDoc(authority);
+
if (!didDocResult.ok) return { ok: false, error: didDocResult.error };
+
if (!collection || !rKey)
+
error: "No rkey or collection found in provided AtUri object",
+
const { service: services } = didDocResult.data;
+
error: { message: "Resolved DID document has no service field." },
+
const pdsService = services.find(
+
service.id === "#atproto_pds" &&
+
service.type === "AtprotoPersonalDataServer",
+
"Resolved DID document has no PDS service listed in the document.",
+
const pdsEndpointRecord = pdsService.serviceEndpoint;
+
// @ts-expect-error yes, we are coercing something that is explicitly not a string into a string, but in this case we want to be specific. only serviceEndpoints with valid atproto pds URLs should be allowed.
+
pdsEndpointUrl = new URL(pdsEndpointRecord).origin;
+
return { ok: false, error: err };
+
const req = new Request(
+
`${pdsEndpointUrl}/xrpc/com.atproto.repo.getRecord?repo=${didDocResult.data.id}&collection=${collection}&rkey=${rKey}`,
+
const res = await fetch(req);
+
const data: unknown = await res.json();
+
success: responseParseSuccess,
+
error: responseParseError,
+
} = comAtprotoRepoGetRecordResponseSchema.safeParse(data);
+
if (!responseParseSuccess) {
+
return { ok: false, error: responseParseError };
+
return { ok: true, data: record };
export const didDocResolver: DidDocumentResolver =