UNPKG

1.4 kBTypeScriptView Raw
1import * as express from "express";
2
3declare module "express" {
4 // Inject additional properties on express.Request
5 interface Request {
6 /**
7 * This request's secret.
8 * Optionally set by cookie-parser if secret(s) are provided. Can be used by other middleware.
9 * [Declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) can be used to add your own properties.
10 */
11 secret?: string | undefined;
12 /** Parsed cookies that have not been signed */
13 cookies: Record<string, any>;
14 /** Parsed cookies that have been signed */
15 signedCookies: Record<string, any>;
16 }
17}
18
19declare function cookieParser(
20 secret?: string | string[],
21 options?: cookieParser.CookieParseOptions,
22): express.RequestHandler;
23
24declare namespace cookieParser {
25 interface CookieParseOptions {
26 decode?(val: string): string;
27 }
28
29 function JSONCookie(jsonCookie: string): object | undefined;
30
31 function JSONCookies<T extends { [key: string]: string }>(jsonCookies: T): { [P in keyof T]: object | undefined };
32
33 function signedCookie(cookie: string, secret: string | string[]): string | false;
34
35 function signedCookies<T extends { [key: string]: string }>(
36 cookies: T,
37 secret: string | string[],
38 ): { [P in keyof T]?: string | false };
39}
40
41export = cookieParser;