UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

150 lines (149 loc) 5.5 kB
import type { DBInterface, DBWallet, DBExpert } from "./interfaces.js"; /** * Remote implementation of the DBInterface * Uses fetch to communicate with a DBServer instance */ /** * Configuration options for DBRemoteClient */ export interface DBRemoteClientOptions { /** URL of the DBServer, default 'https://api.askexperts.io' */ url?: string; /** Optional private key for authentication (as Uint8Array) */ privateKey?: Uint8Array; /** * Optional token for bearer authentication * Can be a string or a callback function that returns a Promise<string> */ token?: string | (() => Promise<string>); } export declare class DBRemoteClient implements DBInterface { #private; private baseUrl; private privateKey?; /** * Creates a new DBRemoteClient instance * @param options - Configuration options for the client */ constructor(options: DBRemoteClientOptions); /** * Create request headers with authentication if privateKey is provided * @param method - HTTP method for the request * @param url - URL for the request * @returns Headers object with authentication if available */ private createHeaders; get token(): string | (() => Promise<string>) | undefined; set token(value: string | (() => Promise<string>) | undefined); /** * List all wallets * @returns Promise resolving to an array of wallet objects */ listWallets(): Promise<DBWallet[]>; /** * List wallets by specific IDs * @param ids - Array of wallet IDs to retrieve * @returns Promise resolving to an array of wallet objects matching the provided IDs */ listWalletsByIds(ids: string[]): Promise<DBWallet[]>; /** * Get a wallet by ID * @param id - ID of the wallet to get * @returns Promise resolving to the wallet if found, null otherwise */ getWallet(id: string): Promise<DBWallet | null>; /** * Get a wallet by name * @param name - Name of the wallet to get * @returns Promise resolving to the wallet if found, null otherwise */ getWalletByName(name: string): Promise<DBWallet | null>; /** * Get the default wallet * @returns Promise resolving to the default wallet if found, null otherwise */ getDefaultWallet(): Promise<DBWallet | null>; /** * Insert a new wallet * @param wallet - Wallet to insert (without id) * @returns Promise resolving to the ID of the inserted wallet */ insertWallet(wallet: Omit<DBWallet, "id">): Promise<string>; /** * Update an existing wallet * @param wallet - Wallet to update * @returns Promise resolving to true if wallet was updated, false otherwise */ updateWallet(wallet: DBWallet): Promise<boolean>; /** * Delete a wallet * @param id - ID of the wallet to delete * @returns Promise resolving to true if wallet was deleted, false otherwise */ deleteWallet(id: string): Promise<boolean>; /** * List all experts * @returns Promise resolving to an array of expert objects */ listExperts(): Promise<DBExpert[]>; /** * List experts by specific IDs * @param ids - Array of expert pubkeys to retrieve * @returns Promise resolving to an array of expert objects matching the provided IDs */ listExpertsByIds(ids: string[]): Promise<DBExpert[]>; /** * List experts with timestamp newer than the provided timestamp * @param timestamp - Only return experts with timestamp newer than this * @param limit - Maximum number of experts to return (default: 1000) * @returns Promise resolving to an array of expert objects */ listExpertsAfter(timestamp: number, limit?: number): Promise<DBExpert[]>; /** * Get an expert by pubkey * @param pubkey - Pubkey of the expert to get * @returns Promise resolving to the expert if found, null otherwise */ getExpert(pubkey: string): Promise<DBExpert | null>; /** * Insert a new expert * @param expert - Expert to insert * @returns Promise resolving to true if expert was inserted, false otherwise */ insertExpert(expert: DBExpert): Promise<boolean>; /** * Update an existing expert * @param expert - Expert to update * @returns Promise resolving to true if expert was updated, false otherwise */ updateExpert(expert: DBExpert): Promise<boolean>; /** * Set the disabled status of an expert * @param pubkey - Pubkey of the expert to update * @param disabled - Whether the expert should be disabled * @returns Promise resolving to true if expert was updated, false otherwise */ setExpertDisabled(pubkey: string, disabled: boolean): Promise<boolean>; /** * Delete an expert * @param pubkey - Pubkey of the expert to delete * @returns Promise resolving to true if expert was deleted, false otherwise */ deleteExpert(pubkey: string): Promise<boolean>; /** * Get the current user ID * @returns Promise resolving to the current user ID */ getUserId(): Promise<string>; /** * Sign up on the remote server * This will create a new user if one doesn't exist for the current pubkey * * @returns Promise resolving to the user ID */ signup(uploadPrivkey?: boolean): Promise<string>; /** * Symbol.dispose method for releasing resources */ [Symbol.dispose](): void; }