UNPKG

azion

Version:

Azion Packages for Edge Computing.

92 lines (87 loc) 3.32 kB
type CookieOptions = { domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; path?: string; sameSite?: 'Lax' | 'None' | 'Strict'; secure?: boolean; prefix?: 'host' | 'secure'; partitioned?: boolean; }; interface SetCookie { /** * Sets a cookie in the response headers. * * @param {Response} res - The HTTP response object. * @param {string} key - The key of the cookie to set. * @param {string} value - The value of the cookie to set. * @param {CookieOptions} [options] - Optional settings for the cookie. * @returns {Response} The modified response object with the Set-Cookie header. */ (res: Response, key: string, value: string, options?: CookieOptions): Response; } /** * Sets a cookie in the response headers. * * @param {Response} response - The HTTP response object. * @param {string} key - The key of the cookie to set. * @param {string} value - The value of the cookie to set. * @param {CookieOptions} [options] - Optional settings for the cookie. * @returns {Response} The modified response object with the Set-Cookie header. * * @example * // Set a simple cookie * setCookie(response, 'session_id', 'abc123'); * * @example * // Set a cookie with options * setCookie(response, 'session_id', 'abc123', { httpOnly: true, secure: true }); */ declare const setCookie: SetCookie; type CookiePrefix = 'host' | 'secure'; interface GetCookie { /** * Retrieves a cookie value from the request headers. * * @param {Request} req - The HTTP request object. * @param {string} [key] - The key of the cookie to retrieve. * @returns {string | undefined | Record<string, string>} The cookie value or an object of all cookies if no key is provided. */ (req: Request, key?: string): string | undefined | Record<string, string>; /** * Retrieves a cookie value from the request headers with a prefix. * * @param {Request} req - The HTTP request object. * @param {string} key - The key of the cookie to retrieve. * @param {CookiePrefix} prefixOptions - The prefix options for the cookie key. * @returns {string | undefined | Record<string, string>} The cookie value or an object of all cookies if no key is provided. */ (req: Request, key: string, prefixOptions: CookiePrefix): string | undefined | Record<string, string>; } /** * Retrieves a cookie value from the request headers. * * @param {Request} request - The HTTP request object. * @param {string} [key] - The key of the cookie to retrieve. * @param {CookiePrefix} [prefix] - The prefix options for the cookie key. * @returns {string | undefined | Record<string, string>} The cookie value or an object of all cookies if no key is provided. * * @example * // Retrieve a specific cookie * const cookieValue = getCookie(request, 'session_id'); * * @example * // Retrieve a specific cookie with a prefix * const cookieValue = getCookie(request, 'session_id', 'user'); * * @example * // Retrieve all cookies * const allCookies = getCookie(request); */ declare const getCookie: GetCookie; declare const cookies: { getCookie: GetCookie; setCookie: SetCookie; }; export { type CookieOptions, type CookiePrefix, cookies as default, getCookie, setCookie };