Something went wrong. Try again.
A CLI for Semble link crawling and connection making
Something went wrong. Try again.
2.5 kB · 89 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import { Client } from '@atcute/client';import type {} from '@atcute/atproto';import * as NetworkCosmikCard from './lexicons/types/network/cosmik/card.js';import * as NetworkCosmikConnection from './lexicons/types/network/cosmik/connection.js';
export interface UrlMetadata { title?: string; description?: string; author?: string; siteName?: string; imageUrl?: string; type?: string; publishedDate?: string;}
export async function createCard( client: Client, did: string, url: string, metadata?: UrlMetadata,): Promise<string> { const now = new Date().toISOString(); const urlMetadata: NetworkCosmikCard.UrlMetadata | undefined = metadata ? { $type: 'network.cosmik.card#urlMetadata', title: metadata.title, description: metadata.description, author: metadata.author, siteName: metadata.siteName, type: metadata.type, publishedDate: metadata.publishedDate, } : undefined;
const record: NetworkCosmikCard.Main = { $type: 'network.cosmik.card', type: 'URL', content: { $type: 'network.cosmik.card#urlContent', url: url as NetworkCosmikCard.UrlContent['url'], metadata: urlMetadata, }, createdAt: now, };
const response = await client.post('com.atproto.repo.createRecord', { input: { repo: did as `did:${string}:${string}`, collection: 'network.cosmik.card', record, }, }); if (!response.ok) { throw new Error(`Failed to create card: ${(response.data as { error?: string; message?: string }).error ?? 'unknown'}`); } return (response.data as { uri: string }).uri;}
export async function createConnection( client: Client, did: string, source: string, target: string, connectionType = 'RELATED',): Promise<string> { const now = new Date().toISOString(); const record: NetworkCosmikConnection.Main = { $type: 'network.cosmik.connection', source, target, connectionType, createdAt: now, updatedAt: now, };
const response = await client.post('com.atproto.repo.createRecord', { input: { repo: did as `did:${string}:${string}`, collection: 'network.cosmik.connection', record, }, }); if (!response.ok) { throw new Error( `Failed to create connection: ${(response.data as { error?: string; message?: string }).error ?? 'unknown'}`, ); } return (response.data as { uri: string }).uri;}