withdrawCodebase

tcmts.cli.announce.withdrawCodebase · #5apgpckb · term · runs anywhere

Stop listing a codebase: its record deleted from the signed-in account's repository. Returns whether it was there.

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";

export async function withdrawCodebase(s: OAuthSession, name: string): Promise<boolean> {
  if (!(await listedCodebase(s, name))) return false;
  const res = await pdsFetch(s, "/xrpc/com.atproto.repo.deleteRecord", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ repo: s.did, collection: CODEBASE_COLLECTION, rkey: name }),
  });
  if (!res.ok) {
    const e = (await res.json().catch(() => ({}))) as { error?: string; message?: string };
    throw new Error(
      `deleting at://${s.did}/${CODEBASE_COLLECTION}/${name}: ${res.status} ${e.message ?? e.error ?? ""}`.trim(),
    );
  }
  return true;
}

uses

used by