announceCodebase
List a codebase as the signed-in account: its record written to their repository, at its name. Listed again, it's left as it is when it says the same (but when), and replaced when its URL or description changed.
import { pdsFetch } from "#codebase/tcmts/atproto"; import type { OAuthSession } from "#codebase/tcmts/atproto"; import { listedCodebase } from "#codebase/tcmts/cli/announce"; import { CODEBASE_COLLECTION } from "#codebase/tcmts/records"; import type { CodebaseRecord } from "#codebase/tcmts/records"; export async function announceCodebase( s: OAuthSession, record: CodebaseRecord, ): Promise<{ uri: string; was: "new" | "same" | "updated" }> { const uri = `at://${s.did}/${CODEBASE_COLLECTION}/${record.name}`; const old = await listedCodebase(s, record.name); if (old && old.value.url === record.url && (old.value.description ?? "") === record.description) return { uri, was: "same" }; const res = await pdsFetch(s, `/xrpc/com.atproto.repo.${old ? "putRecord" : "createRecord"}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ repo: s.did, collection: CODEBASE_COLLECTION, rkey: record.name, // (listed since it was first: a new URL or description doesn't make it new) record: old ? { ...record, createdAt: old.value.createdAt } : record, ...(old ? { swapRecord: old.cid } : {}), }), }); if (!res.ok) { const e = (await res.json().catch(() => ({}))) as { error?: string; message?: string }; throw new Error(`writing ${uri}: ${res.status} ${e.message ?? e.error ?? ""}`.trim()); } return { uri, was: old ? "updated" : "new" }; }
uses
- tcmts.atproto.OAuthSession
- tcmts.atproto.pdsFetch
- tcmts.cli.announce.listedCodebase
- tcmts.records.CODEBASE_COLLECTION
- tcmts.records.CodebaseRecord