/** * Shared cookie-store library. * * Design: * - CDP-native cookie format (matches Playwright/agent-browser output). * - Caller chooses the store path on construction; the harn defaults are * `~/.cache/harnery/cookies.json`. Consumers can point at any path. * - Pure synchronous I/O; the store is small (<1MB typical) so async * buys nothing and complicates the merge-on-write path. */ /** CDP-native cookie. `expires === -1` means session cookie / no expiry. */ export interface Cookie { name: string; value: string; domain: string; path: string; expires: number; size?: number; httpOnly: boolean; secure: boolean; session?: boolean; sameSite?: string; } export interface OriginEntry { origin: string; localStorage: { name: string; value: string; }[]; } export interface CookieStore { cookies: Cookie[]; origins: OriginEntry[]; exportedAt?: string; exportedFrom?: string; } export interface CookieJarOptions { /** Absolute path to the JSON store. Caller must provide. */ path: string; /** `exportedFrom` tag stamped on every save. Defaults to `"harn-cookies"`. */ source?: string; } export interface InfoResult { path: string; exists: boolean; bytes: number; active: number; expired: number; total: number; domains: string[]; origins: number; exportedAt?: string; exportedFrom?: string; } export declare class CookieStoreParseError extends Error { readonly path: string; constructor(path: string, cause: unknown); } export declare class CookieJar { readonly path: string; private readonly source; constructor(opts: CookieJarOptions); exists(): boolean; load(): CookieStore; /** * Persist a store, stamping `exportedAt` (now) and `exportedFrom` * (constructor-provided source). Creates the parent directory if needed. */ save(store: CookieStore): void; private saveUnlocked; private stamp; private update; /** * Read + filter helper. Drops expired cookies. Optional domain filter * uses the same `domainMatches` logic Playwright/CDP do (leading dot * means subdomain match). */ list(filter?: { domain?: string; }): Cookie[]; /** * Set a single cookie, merging into the store on `(name, domain, path)`. * Returns the saved store. */ set(cookie: Cookie): CookieStore; /** Merge cookies and origins in one interprocess-coordinated update. */ merge(cookies: Cookie[], origins?: OriginEntry[]): CookieStore; /** * Clear cookies. Pass `{ all: true }` to wipe everything (including * origins/localStorage), or `{ domain: "..." }` to drop matching cookies * + origins. Returns counts before/after. */ clear(opts: { domain?: string; all?: boolean; }): { before: number; after: number; }; /** * Build a `Cookie:` header value for a URL. Only cookies that match * domain + path + secure rules are included. Returns `""` when nothing * matches. */ header(url: string): string; /** * Import cookies from a JSON file. Accepts three shapes: * - `{ cookies: [...] }` (CDP/agent-browser native) * - `{ data: { cookies: [...] } }` (agent-browser wrapper envelope) * - `[...]` (raw array) * * `replace: true` overwrites the store; default merges on `(name, domain, path)`. * Returns the count imported. */ import(filePath: string, opts?: { replace?: boolean; }): { count: number; }; /** Write the entire store to a file (for sharing with another tool). */ export(filePath: string): { count: number; }; /** Stats for the `info` command. Stable shape so callers can JSON it. */ info(): InfoResult; } /** * Merge cookies into a store. Newer entries with the same * `(name, domain, path)` triple replace older ones. Pure; caller must save. */ export declare function mergeCookies(store: CookieStore, incoming: Cookie[]): CookieStore; /** RFC 6265 domain match. Leading dot in cookie domain means subdomain match. */ export declare function domainMatches(cookieDomain: string, hostname: string): boolean; /** RFC 6265 path match. */ export declare function pathMatches(cookiePath: string, urlPath: string): boolean; /** `expires <= 0` is a session cookie / no expiry; otherwise compare to now. */ export declare function isExpired(cookie: Cookie): boolean; /** Cookies that should be sent with a request to `url`. */ export declare function matchingCookies(store: CookieStore, url: string): Cookie[]; //# sourceMappingURL=client.d.ts.map