Something went wrong. Try again.
A fully featured CLI used as an alternative to AppView applications (Bsky.app/mu.social)
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import * as CRYPTO from 'node:crypto';import type { Client } from './api.ts';
// The account's app preferences: saved feeds, muted words and the rest, kept// by the app view as one list of typed entries. Changing one means reading// them all, changing that entry, and writing them all back.
export type Preference = Record<string, unknown> & { $type: string };
export const SAVED_FEEDS = 'app.bsky.actor.defs#savedFeedsPrefV2';export const MUTED_WORDS = 'app.bsky.actor.defs#mutedWordsPref';
export interface SavedFeed { id: string; type: 'feed' | 'list' | 'timeline'; value: string; pinned: boolean;}
export interface MutedWord { id?: string; value: string; targets: Array<'content' | 'tag'>; actorTarget?: 'all' | 'exclude-following'; expiresAt?: string;}
export async function getPreferences(client: Client): Promise<Preference[]> { const { preferences } = await client.appview<{ preferences: Preference[] }>('app.bsky.actor.getPreferences', {}, { signedIn: true }); return preferences;}
/** Change the entry of one type (adding it if there is none), and write everything back. */export async function updatePreference<T extends Preference>(client: Client, type: string, change: (current: T | undefined) => T): Promise<T> { const preferences = await getPreferences(client); const at = preferences.findIndex((preference) => preference.$type === type); const next = change(at >= 0 ? preferences[at] as T : undefined); if (at >= 0) preferences[at] = next; else preferences.push(next); await client.appview('app.bsky.actor.putPreferences', undefined, { input: { preferences } }); return next;}
export function newId(): string { return CRYPTO.randomBytes(8).toString('hex');}