ts-web-scraper
Version: 
A powerful web scraper for both static and client-side rendered sites using only Bun native APIs
65 lines • 1.88 kB
TypeScript
/**
 * Cookie and Session Management
 *
 * Handle cookies for authenticated scraping
 * Uses ONLY Bun native APIs - no external dependencies!
 */
export declare interface Cookie {
  name: string
  value: string
  domain?: string
  path?: string
  expires?: Date
  maxAge?: number
  secure?: boolean
  httpOnly?: boolean
  sameSite?: 'Strict' | 'Lax' | 'None'
}
export declare interface CookieJarOptions {
  persistPath?: string
  autoSave?: boolean
}
/**
 * Cookie Jar for managing cookies across requests
 */
export declare class CookieJar {
  private cookies: Map<string, Cookie>;
  private options?: CookieJarOptions;
  constructor(options?: CookieJarOptions);
  setCookie(cookie: Cookie | string, url?: string): void;
  getCookies(url: string): Cookie[];
  getCookieString(url: string): string;
  getAllCookies(): Cookie[];
  deleteCookie(name: string, domain?: string): boolean;
  clearCookies(): void;
  clearExpired(): number;
  saveToDisk(path: string): Promise<void>;
  loadFromDisk(path: string): Promise<void>;
  size(): number;
  has(key: string): boolean;
  keys(): string[];
  private parseCookie(cookieString: string, url?: string): Cookie | null;
  private getCookieKey(cookie: Cookie): string;
  private domainMatches(hostname: string, cookieDomain: string): boolean;
  private pathMatches(pathname: string, cookiePath: string): boolean;
}
/**
 * Session Manager
 */
export declare class SessionManager {
  private cookieJar: CookieJar;
  private options?: {
      cookieJar?: CookieJar
      persistPath?: string
    };
  constructor(options?: {
      cookieJar?: CookieJar
      persistPath?: string
    });
  getCookieJar(): CookieJar;
  fetch(url: string, options?: RequestInit): Promise<Response>;
  clearSession(): void;
  saveSession(path?: string): Promise<void>;
  loadSession(path?: string): Promise<void>;
  extractCSRFToken(html: string): string | null;
}