UNPKG

mentoss

Version:

A utility to mock fetch requests and responses.

77 lines (76 loc) 2.31 kB
/** * A class that represents cookie-based credentials. * @implements {Credentials} */ export class CookieCredentials implements Credentials { /** * Creates a new CookieCredentials instance. * @param {string|URL} [baseUrl] The base URL for the credentials */ constructor(baseUrl?: string | URL); /** * Gets the domain for the cookie credentials. * @returns {string|undefined} The domain for the cookie credentials. */ get domain(): string | undefined; /** * Gets the base path for the cookie credentials. * @return {string} The base path for the cookie credentials. */ get basePath(): string; /** * Sets a cookie for the cookie credentials. * @param {CookieInfo} cookieInfo The cookie to set. * @returns {void} * @throws {TypeError} If the cookie already exists. * @throws {TypeError} If the cookie domain does not match the credentials domain. */ setCookie(cookieInfo: CookieInfo): void; /** * Deletes a cookie from the cookie credentials. * @param {Omit<CookieInfo, "value">} cookieInfo The cookie to delete. * @returns {void} * @throws {TypeError} If the cookie does not exist. */ deleteCookie(cookieInfo: Omit<CookieInfo, "value">): void; /** * Gets the credentials headers for the given request. * @param {Request} request The request to get the credentials for. * @return {Headers} The credentials headers for the request. */ getHeadersForRequest(request: Request): Headers; /** * Clears all cookies from the cookie credentials. * @returns {void} */ clear(): void; #private; } export type Credentials = import("./types.js").Credentials; export type SameSiteType = "strict" | "lax" | "none"; export type CookieInfo = { /** * The name of the cookie. */ name: string; /** * The value of the cookie. */ value: string; /** * The domain of the cookie. */ domain?: string | undefined; /** * The path of the cookie. */ path?: string | undefined; /** * The secure flag of the cookie. */ secure?: boolean | undefined; /** * The SameSite attribute of the cookie. */ sameSite?: SameSiteType | undefined; };