UNPKG

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