UNPKG

4.51 kBTypeScriptView Raw
1// Type definitions for cookie-session 2.0
2// Project: https://github.com/expressjs/cookie-session
3// Definitions by: Borislav Zhivkov <https://github.com/borislavjivkov>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.9
6
7/// <reference types="express" />
8/// <reference types="keygrip" />
9
10declare namespace Express {
11 interface Request extends CookieSessionInterfaces.CookieSessionRequest {}
12}
13
14declare namespace CookieSessionInterfaces {
15 interface CookieSessionOptions {
16 /**
17 * The name of the cookie to set, defaults to session.
18 */
19 name?: string | undefined;
20
21 /**
22 * The list of keys to use to sign & verify cookie values. Set cookies are always signed with keys[0], while the other keys are valid for verification, allowing for key rotation.
23 */
24 keys?: Array<string> | import('keygrip') | undefined;
25
26 /**
27 * A string which will be used as single key if keys is not provided.
28 */
29 secret?: string | undefined;
30
31 /**
32 * a number representing the milliseconds from Date.now() for expiry.
33 */
34 maxAge?: number | undefined;
35
36 /**
37 * a Date object indicating the cookie's expiration date (expires at the end of session by default).
38 */
39 expires?: Date | undefined;
40
41 /**
42 * a string indicating the path of the cookie (/ by default).
43 */
44 path?: string | undefined;
45
46 /**
47 * a string indicating the domain of the cookie (no default).
48 */
49 domain?: string | undefined;
50
51 /**
52 * a boolean or string indicating whether the cookie is a "same site" cookie (false by default). This can be set to 'strict', 'lax', 'none', or true (which maps to 'strict').
53 */
54 sameSite?: "strict" | "lax" | "none" | boolean | undefined;
55
56 /**
57 * a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).
58 */
59 secure?: boolean | undefined;
60
61 /**
62 * a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).
63 */
64 secureProxy?: boolean | undefined;
65
66 /**
67 * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).
68 */
69 httpOnly?: boolean | undefined;
70
71 /**
72 * a boolean indicating whether the cookie is to be signed (true by default). If this is true, another cookie of the same name with the .sig suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the
73 * first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.
74 */
75 signed?: boolean | undefined;
76
77 /**
78 * a boolean indicating whether to overwrite previously set cookies of the same name (true by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
79 */
80 overwrite?: boolean | undefined;
81 }
82
83 interface CookieSessionObject {
84 /**
85 * Is true if the session has been changed during the request.
86 */
87 isChanged?: boolean | undefined;
88
89 /**
90 * Is true if the session is new.
91 */
92 isNew?: boolean | undefined;
93
94 /**
95 * Determine if the session has been populated with data or is empty.
96 */
97 isPopulated?: boolean | undefined;
98
99 [propertyName: string]: any;
100 }
101
102 interface CookieSessionRequest {
103 /**
104 * Represents the session for the given request.
105 */
106 session?: CookieSessionObject | null | undefined;
107
108 /**
109 * Represents the session options for the current request. These options are a shallow clone of what was provided at middleware construction and can be altered to change cookie setting behavior on a per-request basis.
110 */
111 sessionOptions: CookieSessionOptions;
112 }
113}
114
115declare module "cookie-session" {
116 import express = require('express');
117
118 function cookieSession(options?: CookieSessionInterfaces.CookieSessionOptions): express.RequestHandler;
119 export = cookieSession;
120}