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