import { User } from '../models/data/User'; import { IAuthCookie } from '../types/auth/AuthCookie'; import { ICookieProvider } from './adapters/CookieProvider'; import { IBrowserRettiwtConfig } from './config/BrowserRettiwtConfig'; import { BrowserDirectMessageService } from './services/BrowserDirectMessageService'; import { BrowserListService } from './services/BrowserListService'; import { BrowserTweetService } from './services/BrowserTweetService'; import { BrowserUserService } from './services/BrowserUserService'; /** * Configuration options for RettiwtBrowser. * * @public */ export interface IRettiwtBrowserConfig extends IBrowserRettiwtConfig { /** * Custom cookie provider. If not provided, uses BrowserCookieProvider * which gets cookies from chrome.cookies API. */ cookieProvider?: ICookieProvider; } /** * Browser extension-specific Rettiwt class. * Automatically retrieves cookies from browser context - no need to pass authentication parameters. * * @example * ```ts * import { RettiwtBrowser } from 'rettiwt-api/browser'; * * const rettiwt = new RettiwtBrowser(); * * // Check if logged in * if (await rettiwt.isLoggedIn()) { * // Initialize and verify * const user = await rettiwt.initialize(); * console.log(`Logged in as: ${user.userName}`); * * // Use the API * const tweet = await rettiwt.tweet.details('1234567890'); * } * ``` * * @public */ export declare class RettiwtBrowser { /** The configuration for Rettiwt. */ private _config; /** The cookie provider for getting Twitter cookies. */ private _cookieProvider; /** Whether the instance has been initialized. */ private _initialized; /** The cached cookies. */ private _cookies?; /** The instance used to fetch data related to direct messages. */ dm: BrowserDirectMessageService; /** The instance used to fetch data related to lists. */ list: BrowserListService; /** The instance used to fetch data related to tweets. */ tweet: BrowserTweetService; /** The instance used to fetch data related to users. */ user: BrowserUserService; /** * Creates a new RettiwtBrowser instance. * * @param config - Optional configuration options. */ constructor(config?: IRettiwtBrowserConfig); /** * Checks if the user is logged in to Twitter. * This method only checks for the presence of required cookies - it does NOT make any API calls. * * @returns true if the required Twitter authentication cookies are present. * * @example * ```ts * const rettiwt = new RettiwtBrowser(); * * if (await rettiwt.isLoggedIn()) { * console.log('User is logged in to Twitter'); * } else { * console.log('User is not logged in'); * } * ``` */ isLoggedIn(): Promise; /** * Initializes the library by getting cookies from the browser and verifying authentication. * This method must be called before using other methods. * * The method: * 1. Gets Twitter authentication cookies from the browser * 2. Initializes the configuration with these cookies * 3. Creates the service instances (dm, list, tweet, user) * 4. Verifies authentication by fetching the current user's profile * * @returns The authenticated user's profile. * @throws Error if not logged in to Twitter or if authentication verification fails. * * @example * ```ts * const rettiwt = new RettiwtBrowser(); * * try { * const user = await rettiwt.initialize(); * console.log(`Logged in as: ${user.userName}`); * } catch (error) { * console.error('Failed to initialize:', error.message); * } * ``` */ initialize(): Promise; /** * Alias for initialize() - verifies authentication and returns user profile. * * @returns The authenticated user's profile. * @throws Error if not logged in or verification fails. */ verify(): Promise; /** * Whether the instance has been initialized. */ get isInitialized(): boolean; /** * Gets the authenticated user's ID (extracted from twid cookie). * Returns undefined if not initialized. */ get userId(): string | undefined; /** * Gets the current authentication cookies. * Returns undefined if not initialized. */ get cookies(): IAuthCookie | undefined; /** * Sets custom headers for all API requests. */ set headers(headers: { [key: string]: string; }); }