@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
95 lines • 4.22 kB
TypeScript
export declare const JAR_HEADER: string;
export declare const HTTP_ONLY_PREFIX = "#HttpOnly_";
export declare const MAX_LIFETIME: number;
export declare const SECURE_HOSTS: ReadonlySet<string>;
export declare const ZONES: Readonly<Record<string, number>>;
export interface Cookie {
name: string;
value: string;
domain: string | null;
tailmatch: boolean;
path: string | null;
secure: boolean;
httpOnly: boolean;
expires: number;
created: number;
}
export declare function epochNow(): number;
/**
* The seconds since the epoch an Expires attribute names, null when it does
* not parse.
*
* The forms curl reads: a day of the month, a month name and a year in any
* order, a time (midnight without one), and a zone, RFC 822's names or a
* `+hhmm` offset of at most 1400, the first one found (UTC without one). A
* sign before a larger number only separates it (`01-Jan-1970`), and a
* number with no field left to fill fails the date. A two-digit year above
* 70 is in the 1900s, the rest in the 2000s, and a date before 1970 does not
* parse (curl 8.14.1). Zone names past RFC 822's are a deliberate gap: curl
* knows more of them.
*/
export declare function parseDate(text: string): number | null;
/**
* The path a cookie set without one takes: the request's up to and including
* its last slash. curl keeps that slash, which RFC 6265 drops, and the
* matching below ignores it.
*/
export declare function defaultPath(path: string): string;
/**
* Whether a cookie's path covers a request's: RFC 6265's rule, the same path
* or one below it, over the path the cookie matches with.
*/
export declare function pathMatches(cookiePath: string | null, path: string): boolean;
/**
* Whether two URLs share an origin: scheme, host and port. A Cookie header
* the line typed goes only to the first request's origin (curl 8.14.1).
*/
export declare function sameOrigin(a: string, b: string): boolean;
/**
* The Cookie value a request carries: the jar's part, then the typed one.
* A deliberate divergence: curl sends the two as separate Cookie lines, and
* one line joined with `; ` reads the same to a server (node joins them so).
*/
export declare function cookieValue(part: string | null, typed: string | null): string | null;
/**
* curl's cookie engine for one invocation: what -b loads, what each response
* sets, what each request sends, and the file -c writes.
*
* Matching follows curl 8.14.1 where it parts from RFC 6265: a Secure cookie
* also rides plain http to localhost, 127.0.0.1 and ::1, and a request sends
* longer paths first, then longer names, then newer cookies. One deliberate
* gap: curl refuses a Domain that is a public suffix (co.uk) through the
* public suffix list, whose license mirage cannot ship, so only a suffix of
* one label (com) is refused here. A host-only cookie's domain is the host
* lowercase, as the URL parser hands it over, where curl keeps it as typed.
*/
export declare class CookieJar {
readonly engine: boolean;
readonly literal: string | null;
readonly now: () => number;
readonly cookies: Cookie[];
readonly sent: (string | null)[];
private arrivals;
constructor(engine: boolean, literal?: string | null, now?: () => number);
private keep;
/**
* Add one Set-Cookie value. `url` is the request it answered, null for a
* line a file gave, which no host, path or scheme constrains.
*/
private add;
/** Keep what one response to `url` set. */
store(url: string, headers: readonly string[]): void;
/**
* Load a cookie file: curl's tab-separated lines, `#HttpOnly_` marking a
* domain, or `Set-Cookie:` header lines. A line that does not parse, one
* whose expiry passes 64 bits, and a cookie already expired, are skipped
* (curl 8.14.1). An expiry past 2^53 loses its low digits here, which
* Python keeps: no date is that far out.
*/
load(text: string): void;
/** The jar's part of the Cookie header a request to `url` sends. */
header(url: string): string | null;
/** The file -c writes: every live cookie with a domain, newest first. */
render(): string;
}
//# sourceMappingURL=cookie.d.ts.map