#!/usr/bin/env python3 """Writes records to a person's own atproto repo — the one write path. Everything in the product that reads is a GET. This is the other side, and it lives in auth/ because a write is made as somebody through their OAuth session: a topic request is the requester's own words, so it goes in their repo under their name. `com.atproto.repo.createRecord` takes any collection NSID and any JSON body; the PDS stores it and the relay puts it on the firehose, where the ingest worker's jetstream watcher sees it and creates the topic. Custom records need no permission from anyone. The NSID's authority must be a domain you control — `click.aligned.feed.request` is authorised by `feed.aligned.click` — because that is the only claim of ownership the protocol makes. """ from auth import bsky def create(collection: str, record: dict, did: str) -> dict: """Create one record under a generated TID key. Returns {uri, cid}.""" out = bsky._call("com.atproto.repo.createRecord", { "repo": did, "collection": collection, "record": record, }, did) return {"uri": out["uri"], "cid": out["cid"]} def put(collection: str, rkey: str, record: dict, did: str) -> dict: """Write a record at a key you chose, creating or replacing it. For records whose key *is* their identity — a lexicon schema lives at its own NSID — where creating a second one is meaningless and updating in place is the only sensible operation. """ out = bsky._call("com.atproto.repo.putRecord", { "repo": did, "collection": collection, "rkey": rkey, "record": record, }, did) return {"uri": out["uri"], "cid": out["cid"]} def delete(collection: str, rkey: str, did: str) -> None: """Remove a record from a repo. Publishing is not reversible, only retractable — anything that already mirrored it keeps its copy.""" bsky._call("com.atproto.repo.deleteRecord", {"repo": did, "collection": collection, "rkey": rkey}, did)