UNPKG

3.21 kBTypeScriptView Raw
1
2import { CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
3
4//#region lib/server-runtime/cookies.d.ts
5interface CookieSignatureOptions {
6 /**
7 * An array of secrets that may be used to sign/unsign the value of a cookie.
8 *
9 * The array makes it easy to rotate secrets. New secrets should be added to
10 * the beginning of the array. `cookie.serialize()` will always use the first
11 * value in the array, but `cookie.parse()` may use any of them so that
12 * cookies that were signed with older secrets still work.
13 */
14 secrets?: string[];
15}
16type CookieOptions = CookieParseOptions$1 & CookieSerializeOptions$1 & CookieSignatureOptions;
17/**
18 * A HTTP cookie.
19 *
20 * A Cookie is a logical container for metadata about a HTTP cookie; its name
21 * and options. But it doesn't contain a value. Instead, it has `parse()` and
22 * `serialize()` methods that allow a single instance to be reused for
23 * parsing/encoding multiple different values.
24 *
25 * @see https://remix.run/utils/cookies#cookie-api
26 */
27interface Cookie {
28 /**
29 * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
30 */
31 readonly name: string;
32 /**
33 * True if this cookie uses one or more secrets for verification.
34 */
35 readonly isSigned: boolean;
36 /**
37 * The Date this cookie expires.
38 *
39 * Note: This is calculated at access time using `maxAge` when no `expires`
40 * option is provided to `createCookie()`.
41 */
42 readonly expires?: Date;
43 /**
44 * Parses a raw `Cookie` header and returns the value of this cookie or
45 * `null` if it's not present.
46 */
47 parse(cookieHeader: string | null, options?: CookieParseOptions$1): Promise<any>;
48 /**
49 * Serializes the given value to a string and returns the `Set-Cookie`
50 * header.
51 */
52 serialize(value: any, options?: CookieSerializeOptions$1): Promise<string>;
53}
54/**
55 * Creates a logical container for managing a browser cookie from the server.
56 *
57 * @public
58 * @category Utils
59 * @mode framework
60 * @mode data
61 * @param name The name of the cookie.
62 * @param cookieOptions Options for parsing and serializing the cookie.
63 * @returns A {@link Cookie} object for parsing and serializing the cookie.
64 */
65declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
66/**
67 * A function that determines whether a value is a React Router {@link Cookie}
68 * object.
69 *
70 * @public
71 * @category Utils
72 * @mode framework
73 * @mode data
74 * @param object The value to check.
75 * @returns `true` if the value is a React Router {@link Cookie} object;
76 * otherwise, `false`.
77 */
78type IsCookieFunction = (object: any) => object is Cookie;
79/**
80 * Returns `true` if a value is a React Router {@link Cookie} object.
81 *
82 * @public
83 * @category Utils
84 * @mode framework
85 * @mode data
86 * @param object The value to check.
87 * @returns `true` if the value is a React Router {@link Cookie} object;
88 * otherwise, `false`.
89 */
90declare const isCookie: IsCookieFunction;
91//#endregion
92export { Cookie, CookieOptions, type CookieParseOptions$1 as CookieParseOptions, type CookieSerializeOptions$1 as CookieSerializeOptions, CookieSignatureOptions, IsCookieFunction, createCookie, isCookie };
\No newline at end of file