UNPKG

11.2 kBTypeScriptView Raw
1import type { Cookie } from './cookie/cookie';
2import { Store } from './store';
3import { Callback, ErrorCallback, Nullable } from './utils';
4/**
5 * The internal structure used in {@link MemoryCookieStore}.
6 * @internal
7 */
8export type MemoryCookieStoreIndex = {
9 [domain: string]: {
10 [path: string]: {
11 [key: string]: Cookie;
12 };
13 };
14};
15/**
16 * An in-memory {@link Store} implementation for {@link CookieJar}. This is the default implementation used by
17 * {@link CookieJar} and supports both async and sync operations. Also supports serialization, getAllCookies, and removeAllCookies.
18 * @public
19 */
20export declare class MemoryCookieStore extends Store {
21 /**
22 * This value is `true` since {@link MemoryCookieStore} implements synchronous functionality.
23 */
24 synchronous: boolean;
25 /**
26 * @internal
27 */
28 idx: MemoryCookieStoreIndex;
29 /**
30 * Create a new {@link MemoryCookieStore}.
31 */
32 constructor();
33 /**
34 * Retrieve a {@link Cookie} with the given `domain`, `path`, and `key` (`name`). The RFC maintains that exactly
35 * one of these cookies should exist in a store. If the store is using versioning, this means that the latest or
36 * newest such cookie should be returned.
37 *
38 * @param domain - The cookie domain to match against.
39 * @param path - The cookie path to match against.
40 * @param key - The cookie name to match against.
41 */
42 findCookie(domain: Nullable<string>, path: Nullable<string>, key: Nullable<string>): Promise<Cookie | undefined>;
43 /**
44 * Retrieve a {@link Cookie} with the given `domain`, `path`, and `key` (`name`). The RFC maintains that exactly
45 * one of these cookies should exist in a store. If the store is using versioning, this means that the latest or
46 * newest such cookie should be returned.
47 *
48 * Callback takes an error and the resulting Cookie object. If no cookie is found then null MUST be passed instead (that is, not an error).
49 * @param domain - The cookie domain to match against.
50 * @param path - The cookie path to match against.
51 * @param key - The cookie name to match against.
52 * @param callback - A function to call with either the found cookie or an error.
53 */
54 findCookie(domain: Nullable<string>, path: Nullable<string>, key: Nullable<string>, callback: Callback<Cookie | undefined>): void;
55 /**
56 * Locates all {@link Cookie} values matching the given `domain` and `path`.
57 *
58 * The resulting list is checked for applicability to the current request according to the RFC (`domain-match`, `path-match`,
59 * `http-only-flag`, `secure-flag`, `expiry`, and so on), so it's OK to use an optimistic search algorithm when implementing
60 * this method. However, the search algorithm used SHOULD try to find cookies that {@link domainMatch} the `domain` and
61 * {@link pathMatch} the `path` in order to limit the amount of checking that needs to be done.
62 *
63 * @remarks
64 * - As of version `0.9.12`, the `allPaths` option to cookiejar.getCookies() above causes the path here to be `null`.
65 *
66 * - If the `path` is `null`, `path-matching` MUST NOT be performed (that is, `domain-matching` only).
67 *
68 * @param domain - The cookie domain to match against.
69 * @param path - The cookie path to match against.
70 * @param allowSpecialUseDomain - If `true` then special-use domain suffixes, will be allowed in matches. Defaults to `false`.
71 */
72 findCookies(domain: string, path: string, allowSpecialUseDomain?: boolean): Promise<Cookie[]>;
73 /**
74 * Locates all {@link Cookie} values matching the given `domain` and `path`.
75 *
76 * The resulting list is checked for applicability to the current request according to the RFC (`domain-match`, `path-match`,
77 * `http-only-flag`, `secure-flag`, `expiry`, and so on), so it's OK to use an optimistic search algorithm when implementing
78 * this method. However, the search algorithm used SHOULD try to find cookies that {@link domainMatch} the `domain` and
79 * {@link pathMatch} the `path` in order to limit the amount of checking that needs to be done.
80 *
81 * @remarks
82 * - As of version `0.9.12`, the `allPaths` option to cookiejar.getCookies() above causes the path here to be `null`.
83 *
84 * - If the `path` is `null`, `path-matching` MUST NOT be performed (that is, `domain-matching` only).
85 *
86 * @param domain - The cookie domain to match against.
87 * @param path - The cookie path to match against.
88 * @param allowSpecialUseDomain - If `true` then special-use domain suffixes, will be allowed in matches. Defaults to `false`.
89 * @param callback - A function to call with either the found cookies or an error.
90 */
91 findCookies(domain: string, path: string, allowSpecialUseDomain?: boolean, callback?: Callback<Cookie[]>): void;
92 /**
93 * Adds a new {@link Cookie} to the store. The implementation SHOULD replace any existing cookie with the same `domain`,
94 * `path`, and `key` properties.
95 *
96 * @remarks
97 * - Depending on the nature of the implementation, it's possible that between the call to `fetchCookie` and `putCookie`
98 * that a duplicate `putCookie` can occur.
99 *
100 * - The {@link Cookie} object MUST NOT be modified; as the caller has already updated the `creation` and `lastAccessed` properties.
101 *
102 * @param cookie - The cookie to store.
103 */
104 putCookie(cookie: Cookie): Promise<void>;
105 /**
106 * Adds a new {@link Cookie} to the store. The implementation SHOULD replace any existing cookie with the same `domain`,
107 * `path`, and `key` properties.
108 *
109 * @remarks
110 * - Depending on the nature of the implementation, it's possible that between the call to `fetchCookie` and `putCookie`
111 * that a duplicate `putCookie` can occur.
112 *
113 * - The {@link Cookie} object MUST NOT be modified; as the caller has already updated the `creation` and `lastAccessed` properties.
114 *
115 * @param cookie - The cookie to store.
116 * @param callback - A function to call when the cookie has been stored or an error has occurred.
117 */
118 putCookie(cookie: Cookie, callback: ErrorCallback): void;
119 /**
120 * Update an existing {@link Cookie}. The implementation MUST update the `value` for a cookie with the same `domain`,
121 * `path`, and `key`. The implementation SHOULD check that the old value in the store is equivalent to oldCookie -
122 * how the conflict is resolved is up to the store.
123 *
124 * @remarks
125 * - The `lastAccessed` property is always different between the two objects (to the precision possible via JavaScript's clock).
126 *
127 * - Both `creation` and `creationIndex` are guaranteed to be the same.
128 *
129 * - Stores MAY ignore or defer the `lastAccessed` change at the cost of affecting how cookies are selected for automatic deletion.
130 *
131 * - Stores may wish to optimize changing the `value` of the cookie in the store versus storing a new cookie.
132 *
133 * - The `newCookie` and `oldCookie` objects MUST NOT be modified.
134 *
135 * @param oldCookie - the cookie that is already present in the store.
136 * @param newCookie - the cookie to replace the one already present in the store.
137 */
138 updateCookie(oldCookie: Cookie, newCookie: Cookie): Promise<void>;
139 /**
140 * Update an existing {@link Cookie}. The implementation MUST update the `value` for a cookie with the same `domain`,
141 * `path`, and `key`. The implementation SHOULD check that the old value in the store is equivalent to oldCookie -
142 * how the conflict is resolved is up to the store.
143 *
144 * @remarks
145 * - The `lastAccessed` property is always different between the two objects (to the precision possible via JavaScript's clock).
146 *
147 * - Both `creation` and `creationIndex` are guaranteed to be the same.
148 *
149 * - Stores MAY ignore or defer the `lastAccessed` change at the cost of affecting how cookies are selected for automatic deletion.
150 *
151 * - Stores may wish to optimize changing the `value` of the cookie in the store versus storing a new cookie.
152 *
153 * - The `newCookie` and `oldCookie` objects MUST NOT be modified.
154 *
155 * @param oldCookie - the cookie that is already present in the store.
156 * @param newCookie - the cookie to replace the one already present in the store.
157 * @param callback - A function to call when the cookie has been updated or an error has occurred.
158 */
159 updateCookie(oldCookie: Cookie, newCookie: Cookie, callback: ErrorCallback): void;
160 /**
161 * Remove a cookie from the store (see notes on `findCookie` about the uniqueness constraint).
162 *
163 * @param domain - The cookie domain to match against.
164 * @param path - The cookie path to match against.
165 * @param key - The cookie name to match against.
166 */
167 removeCookie(domain: string, path: string, key: string): Promise<void>;
168 /**
169 * Remove a cookie from the store (see notes on `findCookie` about the uniqueness constraint).
170 *
171 * @param domain - The cookie domain to match against.
172 * @param path - The cookie path to match against.
173 * @param key - The cookie name to match against.
174 * @param callback - A function to call when the cookie has been removed or an error occurs.
175 */
176 removeCookie(domain: string, path: string, key: string, callback: ErrorCallback): void;
177 /**
178 * Removes matching cookies from the store. The `path` parameter is optional and if missing,
179 * means all paths in a domain should be removed.
180 *
181 * @param domain - The cookie domain to match against.
182 * @param path - The cookie path to match against.
183 */
184 removeCookies(domain: string, path: string): Promise<void>;
185 /**
186 * Removes matching cookies from the store. The `path` parameter is optional and if missing,
187 * means all paths in a domain should be removed.
188 *
189 * @param domain - The cookie domain to match against.
190 * @param path - The cookie path to match against.
191 * @param callback - A function to call when the cookies have been removed or an error occurs.
192 */
193 removeCookies(domain: string, path: string, callback: ErrorCallback): void;
194 /**
195 * Removes all cookies from the store.
196 */
197 removeAllCookies(): Promise<void>;
198 /**
199 * Removes all cookies from the store.
200 *
201 * @param callback - A function to call when all the cookies have been removed or an error occurs.
202 */
203 removeAllCookies(callback: ErrorCallback): void;
204 /**
205 * Gets all the cookies in the store.
206 *
207 * @remarks
208 * - Cookies SHOULD be returned in creation order to preserve sorting via {@link cookieCompare}.
209 */
210 getAllCookies(): Promise<Cookie[]>;
211 /**
212 * Gets all the cookies in the store.
213 *
214 * @remarks
215 * - Cookies SHOULD be returned in creation order to preserve sorting via {@link cookieCompare}.
216 *
217 * @param callback - A function to call when all the cookies have been retrieved or an error occurs.
218 */
219 getAllCookies(callback: Callback<Cookie[]>): void;
220}