UNPKG

4.91 kBTypeScriptView Raw
1// Type definitions for CookieJar 2.1
2// Project: https://github.com/bmeck/node-cookiejar
3// Definitions by: Rafal Proszowski <https://github.com/paroxp>, Charles Samborski <https://github.com/demurgos>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.2
6
7export class CookieAccessInfo {
8 /**
9 * Class to determine matching qualities of a cookie
10 * @param domain string domain to match
11 * @param path string path to match
12 * @param secure boolean access is secure (ssl generally)
13 * @param script boolean access is from a script
14 */
15 constructor(domain: string, path?: string, secure?: boolean, script?: boolean);
16
17 static All: CookieAccessInfo;
18 domain: string; // domain to match
19 path: string; // path to match
20 secure: boolean; // access is secure (ssl generally)
21 script: boolean; // access is from a script
22}
23
24export class Cookie {
25 name: string; // name of the cookie
26 value: string; // string associated with the cookie
27 domain: string; // domain to match (on a cookie a '.' at the start means a wildcard matching anything ending in the rest)
28 explicit_domain: boolean; // if the domain was explicitly set via the cookie string
29 path: string; // base path to match (matches any path starting with this '/' is root)
30 explicit_path: boolean; // if the path was explicitly set via the cookie string
31 noscript: boolean; // if it should be kept from scripts
32 secure: boolean; // should it only be transmitted over secure means
33 expiration_date: number; // number of millis since 1970 at which this should be removed
34
35 /**
36 * It turns input into a Cookie (singleton if given a Cookie), the
37 * request_domain argument is used to default the domain if it is not
38 * explicit in the cookie string, the request_path argument is used to set
39 * the path if it is not explicit in a cookie String.
40 *
41 * Explicit domains/paths will cascade, implied domains/paths must exactly
42 * match (see http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Pat).
43 * @param cookie string or a cookie to work on
44 * @param requestDomain string argument is used to default the domain if it is not explicit in the cookie string
45 * @param requestPath string argument is used to set the path if it is not explicit in a cookie String
46 */
47 constructor(cookie: string | Cookie, requestDomain?: string, requestPath?: string);
48
49 /**
50 * the set-cookie: string for this cookie
51 */
52 toString(): string;
53
54 /**
55 * the cookie: string for this cookie
56 */
57 toValueString(): string;
58
59 /**
60 * parses the string onto this cookie or a new one if called directly
61 * @param cookie string to be parsed into a Cookie
62 * @param requestDomain string definind the requesting domain
63 * @param requestPath string defining the requesting path
64 */
65 parse(cookie: string, requestDomain?: string, requestPath?: string): Cookie;
66
67 /**
68 * returns true if the access_info allows retrieval of this cookie
69 * @param accessInfo CookieAccessInfo
70 */
71 matches(accessInfo: CookieAccessInfo): boolean;
72
73 /**
74 * returns true if the cookies cannot exist in the same space
75 * (domain and path match)
76 * @param cookie Cookie
77 */
78 collidesWith(cookie: Cookie): boolean;
79}
80
81export class CookieJar {
82 /**
83 * class to hold numerous cookies from multiple domains correctly
84 */
85 constructor();
86
87 /**
88 * modify (or add if not already-existing) a cookie to the jar
89 * @param cookie string | Cookie
90 * @param requestDomain string argument is used to default the domain if it is not explicit in the cookie string
91 * @param requestPath string argument is used to set the path if it is not explicit in a cookie String
92 */
93 setCookie(cookie: string | Cookie, requestDomain?: string, requestPath?: string): Cookie | false;
94
95 /**
96 * modify (or add if not already-existing) a large number of cookies to the
97 * jar
98 * @param cookie string or list of strings defining cookies
99 * @param requestDomain string argument is used to default the domain if it is not explicit in the cookie string
100 * @param requestPath string argument is used to set the path if it is not explicit in a cookie String
101 */
102 setCookies(cookie: string | ReadonlyArray<string>, requestDomain?: string, requestPath?: string): Cookie[];
103
104 /**
105 * get a cookie with the name and access_info matching
106 * @param cookieName string to be parsed into a Cookie
107 * @param accessInfo CookieAccessInfo
108 */
109 getCookie(cookieName: string, accessInfo: CookieAccessInfo): Cookie | undefined;
110
111 /**
112 * grab all cookies matching this access_info
113 * @param accessInfo CookieAccessInfo
114 */
115 getCookies(accessInfo: CookieAccessInfo): ReadonlyArray<Cookie> & { toValueString(): string };
116}