UNPKG

@alessiofrittoli/next-api

Version:
81 lines (78 loc) 3.2 kB
import * as _alessiofrittoli_web_utils from '@alessiofrittoli/web-utils'; import { A as Api } from '../types-BCw6mdsz.mjs'; import { ParsedCookieMap, RawCookie, Cookie } from '@alessiofrittoli/web-utils/storage/Cookie'; export { ParsedCookie, ParsedCookieMap, Priority, RawCookie, SameSite } from '@alessiofrittoli/web-utils/storage/Cookie'; import '../page-DAsxsEeP.mjs'; import 'next'; import 'fs'; import 'node:stream/web'; import 'next/server'; import '@alessiofrittoli/stream-reader/types'; /** * Easly handle HTTP cookies. * */ declare class HttpCookie { /** * Internal Next.js API Request object use to read cookies. * */ private static _request?; /** * Internal Response Headers used to set new cookies. * */ private static _headers?; /** * Set internal `request` reference so `HttpCookie` can retrieve cookies from the Request Headers. * * @param request The Next.js API Request object. * @returns The `HttpCookie` reference for chaining purposes. */ static request<T>(request: Api.Route.Request<T>): typeof HttpCookie; /** * Set internal `headers` reference so `HttpCookie` can set cookies to the Response Headers. * * @param headers The Response `Headers` instance. Those headers must be returned in the server response so cookies can be effectively set. * @returns The `HttpCookie` reference for chaining purposes. */ static headers(headers: Headers): typeof HttpCookie; /** * Get Response Headers. * * @returns The Response Headers. */ static getHeaders(): Headers; /** * Get a cookie by cookie name from Request Headers. * * @param name The name of the cookie. * @returns The found parsed cookie or `undefined` if no cookie has been found in Request Headers. */ static get<T, K extends string | number | symbol = string>(name: K): (K extends infer T_1 extends keyof Record<K, T> ? { [P in T_1]: ParsedCookieMap<P, Record<K, T>[P]>; } : never)[K] | undefined; /** * Get all cookies from Request Headers. * * @returns The parsed cookie found in Request Headers. */ static getAll<T extends Record<string, unknown>>(): _alessiofrittoli_web_utils.TypedMap<keyof T extends infer T_1 extends keyof T ? { [P in T_1]: ParsedCookieMap<P, T[P]>; } : never, true, keyof T>; /** * Set a cookie to Response Headers. * * @param options The cookie options or a parsed Cookie Map. * @returns The `HttpCookie` reference for chaining purposes. */ static set<K = string, V = unknown>(options: RawCookie<K, V> | ParsedCookieMap<K, V>): typeof HttpCookie; /** * Delete a cookie by cookie name from `Document.cookie`. * * @param name The name of the cookie. * @returns `true` if successful, `false` otherwise. */ static delete<K = string, V = unknown>(options: RawCookie<K, V> | ParsedCookieMap<K, V>): typeof HttpCookie; static toString: typeof Cookie.toString; static fromString: typeof Cookie.fromString; static fromListString: typeof Cookie.fromListString; static parse: typeof Cookie.parse; } export { HttpCookie };