Session

tcmts.atproto.Session · #cjdfheaz · interface

A signed-in account, to act as: requests to its PDS as them (fetch, /xrpc/…), its records read, written and deleted (a record's $type is its collection unless it says), service-auth tokens for other services, and signing out. The same in a program (#dg2vjclv) and in a browser.

export interface Session {
  readonly did: string;
  readonly handle?: string;
  /** what it may do, as its sign-in was granted */
  readonly scope: string;
  fetch(path: string, init?: RequestInit): Promise<Response>;
  getRecord<T = Record<string, unknown>>(
    collection: string,
    rkey: string,
  ): Promise<{ uri: string; cid: string; value: T } | undefined>;
  putRecord(
    collection: string,
    rkey: string,
    record: Record<string, unknown>,
  ): Promise<{ uri: string; cid: string }>;
  createRecord(
    collection: string,
    record: Record<string, unknown>,
    rkey?: string,
  ): Promise<{ uri: string; cid: string }>;
  deleteRecord(collection: string, rkey: string): Promise<void>;
  listRecords<T = Record<string, unknown>>(
    collection: string,
    o?: { limit?: number; cursor?: string },
  ): Promise<{ records: { uri: string; cid: string; value: T }[]; cursor?: string }>;
  /** a token its PDS signs for the service `aud` alone, for the method `lxm`, until `exp` (ms; a minute from now) */
  serviceAuth(o: { aud: string; lxm: string; exp?: number }): Promise<string>;
  signOut(): Promise<void>;
}

used by