@mherod/get-cookie 2.1.3 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/commit-msg +2 -0
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +4 -0
- package/README.md +163 -18
- package/commitlint.config.js +12 -0
- package/dist/chunk-56Z35D5R.js +2 -0
- package/dist/chunk-56Z35D5R.js.map +1 -0
- package/dist/chunk-5FUMK7M3.js +4 -0
- package/dist/chunk-5FUMK7M3.js.map +1 -0
- package/dist/chunk-5ZT2G45S.js +2 -0
- package/dist/chunk-5ZT2G45S.js.map +1 -0
- package/dist/chunk-FR2MKDHT.js +2 -0
- package/dist/chunk-FR2MKDHT.js.map +1 -0
- package/dist/chunk-HMKSQBDC.js +2 -0
- package/dist/chunk-HMKSQBDC.js.map +1 -0
- package/dist/chunk-VMBA4NVU.js +2 -0
- package/dist/chunk-VMBA4NVU.js.map +1 -0
- package/dist/chunk-W3JALMAX.js +2 -0
- package/dist/chunk-W3JALMAX.js.map +1 -0
- package/dist/cli.cjs +19 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/getChromeCookie-4ZWACG6M.js +2 -0
- package/dist/getChromeCookie-4ZWACG6M.js.map +1 -0
- package/dist/getChromePassword-GTIXL733.js +2 -0
- package/dist/getChromePassword-GTIXL733.js.map +1 -0
- package/dist/getCookie-43FKMQEZ.js +2 -0
- package/dist/getCookie-43FKMQEZ.js.map +1 -0
- package/dist/getFirefoxCookie-OJYYZFZP.js +2 -0
- package/dist/getFirefoxCookie-OJYYZFZP.js.map +1 -0
- package/dist/getGroupedRenderedCookies-P5VZXZUC.js +2 -0
- package/dist/getGroupedRenderedCookies-P5VZXZUC.js.map +1 -0
- package/dist/getMergedRenderedCookies-C6TXK2I4.js +2 -0
- package/dist/getMergedRenderedCookies-C6TXK2I4.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +252 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +2 -24712
- package/dist/index.js.map +1 -0
- package/eslint.config.js +243 -0
- package/jest.setup.js +11 -0
- package/package.json +87 -36
- package/tsconfig.build.json +9 -0
- package/tsup.cli.ts +27 -0
- package/tsup.config.ts +27 -0
- package/tsup.lib.ts +27 -0
- package/typedoc.json +22 -0
- package/.parcelrc +0 -7
- package/.prettierignore +0 -5
- package/.prettierrc +0 -12
- package/.terserrc +0 -26
- package/build-indexes.ts +0 -108
- package/bun.lockb +0 -0
- package/dist/cli.js +0 -18319
- package/dist/types.d.ts +0 -361
- package/jest.config.ts +0 -14
- package/package-lock.json +0 -5608
- package/src/CookieRow.ts +0 -43
- package/src/CookieSpec.ts +0 -42
- package/src/ExportedCookie.ts +0 -19
- package/src/FetchResponse.ts +0 -13
- package/src/SpecialCases.ts +0 -15
- package/src/StringToRegex.ts +0 -16
- package/src/argv.ts +0 -30
- package/src/browsers/CompositeCookieQueryStrategy.ts +0 -76
- package/src/browsers/CookieQueryStrategy.ts +0 -7
- package/src/browsers/CookieStoreQueryStrategy.ts +0 -115
- package/src/browsers/QuerySqliteThenTransform.ts +0 -48
- package/src/browsers/chrome/ChromeApplicationSupport.ts +0 -14
- package/src/browsers/chrome/ChromeCookieQueryStrategy.ts +0 -158
- package/src/browsers/chrome/decrypt.ts +0 -154
- package/src/browsers/chrome/getChromePassword.ts +0 -28
- package/src/browsers/firefox/FirefoxCookieQueryStrategy.ts +0 -109
- package/src/browsers/getEncryptedChromeCookie.ts +0 -122
- package/src/browsers/index.ts +0 -12
- package/src/browsers/mock/MockCookieQueryStrategy.ts +0 -22
- package/src/browsers/safari/SafariCookieQueryStrategy.ts +0 -42
- package/src/cli.ts +0 -94
- package/src/cliQueryCookies.ts +0 -65
- package/src/comboQueryCookieSpec.test.ts +0 -92
- package/src/comboQueryCookieSpec.ts +0 -26
- package/src/cookieQueryOptions.ts +0 -27
- package/src/cookieSpecsFromUrl.test.ts +0 -65
- package/src/cookieSpecsFromUrl.ts +0 -73
- package/src/decodeBinaryCookies.ts +0 -72
- package/src/execSimple.ts +0 -12
- package/src/fetchWithCookies.test.ts +0 -32
- package/src/fetchWithCookies.ts +0 -217
- package/src/findAllFiles.ts +0 -48
- package/src/getChromeCookie.ts +0 -19
- package/src/getCookie.ts +0 -22
- package/src/getFirefoxCookie.ts +0 -25
- package/src/getGroupedRenderedCookies.ts +0 -42
- package/src/getMergedRenderedCookies.test.ts +0 -43
- package/src/getMergedRenderedCookies.ts +0 -19
- package/src/global.ts +0 -8
- package/src/index.ts +0 -16
- package/src/isValidJwt.ts +0 -26
- package/src/listChromeProfiles.ts +0 -53
- package/src/logger.ts +0 -12
- package/src/processBeforeReturn.ts +0 -29
- package/src/queryCookies.ts +0 -41
- package/src/resultsRendered.ts +0 -24
- package/src/unpackHeaders.ts +0 -18
- package/src/util/flatMapAsync.test.ts +0 -55
- package/src/util/flatMapAsync.ts +0 -41
- package/src/util/index.ts +0 -1
- package/tsconfig.json +0 -26
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object matches the CookieRenderOptions interface.
|
|
3
|
+
* Used to validate render options before processing cookie output.
|
|
4
|
+
* @param obj - The object to check.
|
|
5
|
+
* @returns True if the object contains valid render options.
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { isCookieRenderOptions } from 'get-cookie';
|
|
9
|
+
*
|
|
10
|
+
* // Valid render options
|
|
11
|
+
* console.log(isCookieRenderOptions({ format: "json" })); // true
|
|
12
|
+
* console.log(isCookieRenderOptions({
|
|
13
|
+
* format: "text",
|
|
14
|
+
* separator: "\n",
|
|
15
|
+
* showFilePaths: true
|
|
16
|
+
* })); // true
|
|
17
|
+
*
|
|
18
|
+
* // Invalid examples
|
|
19
|
+
* console.log(isCookieRenderOptions({ format: "csv" })); // false - invalid format
|
|
20
|
+
* console.log(isCookieRenderOptions({ separator: "\n" })); // false - missing format
|
|
21
|
+
* console.log(isCookieRenderOptions(null)); // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
type RenderFormat = "merged" | "grouped";
|
|
25
|
+
/**
|
|
26
|
+
* Options for rendering cookies.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { RenderOptions } from 'get-cookie';
|
|
30
|
+
*
|
|
31
|
+
* // Basic rendering options
|
|
32
|
+
* const basicOptions: RenderOptions = {
|
|
33
|
+
* format: 'merged',
|
|
34
|
+
* separator: '; ',
|
|
35
|
+
* showFilePaths: false
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* // Grouped format with file paths
|
|
39
|
+
* const groupedOptions: RenderOptions = {
|
|
40
|
+
* format: 'grouped',
|
|
41
|
+
* separator: '; ',
|
|
42
|
+
* showFilePaths: true
|
|
43
|
+
* };
|
|
44
|
+
*
|
|
45
|
+
* // Custom separator
|
|
46
|
+
* const customOptions: RenderOptions = {
|
|
47
|
+
* format: 'merged',
|
|
48
|
+
* separator: ' && ',
|
|
49
|
+
* showFilePaths: false
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
interface RenderOptions {
|
|
54
|
+
/** The format to use when rendering cookies. */
|
|
55
|
+
format?: RenderFormat;
|
|
56
|
+
/** The separator to use between cookies. */
|
|
57
|
+
separator?: string;
|
|
58
|
+
/** Whether to show file paths in the output. */
|
|
59
|
+
showFilePaths?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Specification for identifying a cookie by its domain and name.
|
|
64
|
+
* Used to query specific cookies from browser storage.
|
|
65
|
+
* @remarks
|
|
66
|
+
* - Domain matching is exact unless using wildcards.
|
|
67
|
+
* - Name can be "*" to match all cookies for a domain.
|
|
68
|
+
* - Leading dots in domains match all subdomains.
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { CookieSpec } from 'get-cookie';
|
|
72
|
+
*
|
|
73
|
+
* // Basic cookie specification
|
|
74
|
+
* const cookieSpec: CookieSpec = {
|
|
75
|
+
* domain: "example.com",
|
|
76
|
+
* name: "sessionId"
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* // Using wildcards to match all cookies
|
|
80
|
+
* const allCookies: CookieSpec = {
|
|
81
|
+
* domain: "example.com",
|
|
82
|
+
* name: "*" // Match all cookies for example.com
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* // Subdomain specification
|
|
86
|
+
* const apiCookies: CookieSpec = {
|
|
87
|
+
* domain: "api.example.com",
|
|
88
|
+
* name: "auth"
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* // Match cookies across all subdomains
|
|
92
|
+
* const allSubdomainCookies: CookieSpec = {
|
|
93
|
+
* domain: ".example.com", // Note the leading dot
|
|
94
|
+
* name: "tracking"
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* // Multiple domain levels
|
|
98
|
+
* const deepSubdomainCookie: CookieSpec = {
|
|
99
|
+
* domain: "dev.api.example.com",
|
|
100
|
+
* name: "debug"
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
interface CookieSpec {
|
|
105
|
+
/** The domain the cookie belongs to. */
|
|
106
|
+
domain: string;
|
|
107
|
+
/** The name of the cookie. */
|
|
108
|
+
name: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Interface representing a cookie that has been exported from a browser's storage.
|
|
113
|
+
* This is the core data structure used to represent cookies after they have been
|
|
114
|
+
* retrieved from various browser storage mechanisms (Chrome, Firefox, etc.).
|
|
115
|
+
* @remarks
|
|
116
|
+
* - All cookies must have domain, name, and value properties.
|
|
117
|
+
* - Expiry is optional and can be a Date, "Infinity", or undefined.
|
|
118
|
+
* - Meta information is useful for tracking the cookie's origin and state.
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { ExportedCookie } from 'get-cookie';
|
|
122
|
+
*
|
|
123
|
+
* // Basic cookie with required fields
|
|
124
|
+
* const basicCookie: ExportedCookie = {
|
|
125
|
+
* domain: "example.com",
|
|
126
|
+
* name: "sessionId",
|
|
127
|
+
* value: "abc123"
|
|
128
|
+
* };
|
|
129
|
+
*
|
|
130
|
+
* // Cookie with expiry and metadata
|
|
131
|
+
* const detailedCookie: ExportedCookie = {
|
|
132
|
+
* domain: "api.example.com",
|
|
133
|
+
* name: "authToken",
|
|
134
|
+
* value: "xyz789",
|
|
135
|
+
* expiry: new Date("2024-12-31"),
|
|
136
|
+
* meta: {
|
|
137
|
+
* file: "Cookies.sqlite",
|
|
138
|
+
* browser: "Firefox",
|
|
139
|
+
* decrypted: true,
|
|
140
|
+
* secure: true,
|
|
141
|
+
* httpOnly: true,
|
|
142
|
+
* path: "/"
|
|
143
|
+
* }
|
|
144
|
+
* };
|
|
145
|
+
*
|
|
146
|
+
* // Cookie with infinite expiry (session cookie)
|
|
147
|
+
* const persistentCookie: ExportedCookie = {
|
|
148
|
+
* domain: "app.example.com",
|
|
149
|
+
* name: "preferences",
|
|
150
|
+
* value: "theme=dark",
|
|
151
|
+
* expiry: "Infinity"
|
|
152
|
+
* };
|
|
153
|
+
*
|
|
154
|
+
* // Subdomain cookie example
|
|
155
|
+
* const subdomainCookie: ExportedCookie = {
|
|
156
|
+
* domain: ".example.com", // Note the leading dot for all subdomains
|
|
157
|
+
* name: "tracking",
|
|
158
|
+
* value: "user123",
|
|
159
|
+
* meta: {
|
|
160
|
+
* browser: "Chrome",
|
|
161
|
+
* decrypted: true
|
|
162
|
+
* }
|
|
163
|
+
* };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
interface ExportedCookie {
|
|
167
|
+
/** The domain the cookie belongs to. */
|
|
168
|
+
domain: string;
|
|
169
|
+
/** The name of the cookie. */
|
|
170
|
+
name: string;
|
|
171
|
+
/** The value of the cookie. */
|
|
172
|
+
value: string;
|
|
173
|
+
/** When the cookie expires (Date object, "Infinity", or undefined). */
|
|
174
|
+
expiry?: Date | "Infinity";
|
|
175
|
+
/** Additional metadata about the cookie. */
|
|
176
|
+
meta?: {
|
|
177
|
+
/** Path to the file the cookie was exported from. */
|
|
178
|
+
file?: string;
|
|
179
|
+
/** Browser the cookie was exported from. */
|
|
180
|
+
browser?: string;
|
|
181
|
+
/** Whether the cookie value was decrypted. */
|
|
182
|
+
decrypted?: boolean;
|
|
183
|
+
/** Any additional metadata. */
|
|
184
|
+
[key: string]: unknown;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Dynamic import for the getCookie function.
|
|
190
|
+
* @internal
|
|
191
|
+
* @returns Promise resolving to the getCookie function
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const getCookieFn = await getCookie();
|
|
195
|
+
* const cookies = await getCookieFn({ domain: 'example.com' });
|
|
196
|
+
* // Returns: [{ name: 'sessionId', value: 'abc123', domain: 'example.com' }, ...]
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare const getCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
200
|
+
/**
|
|
201
|
+
* Dynamic import for Chrome-specific cookie retrieval.
|
|
202
|
+
* @internal
|
|
203
|
+
* @returns Promise resolving to the getChromeCookie function
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const chromeCookieFn = await getChromeCookie();
|
|
207
|
+
* const cookies = await chromeCookieFn({ domain: 'example.com', secure: true });
|
|
208
|
+
* // Returns Chrome-format cookies: [{ name: 'auth', value: 'xyz789', secure: true }, ...]
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare const getChromeCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
212
|
+
/**
|
|
213
|
+
* Dynamic import for Firefox-specific cookie retrieval.
|
|
214
|
+
* @internal
|
|
215
|
+
* @returns Promise resolving to the getFirefoxCookie function
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const firefoxCookieFn = await getFirefoxCookie();
|
|
219
|
+
* const cookies = await firefoxCookieFn({ path: '/api' });
|
|
220
|
+
* // Returns Firefox-format cookies: [{ name: 'token', value: 'def456', path: '/api' }, ...]
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare const getFirefoxCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
224
|
+
/**
|
|
225
|
+
* Dynamic import for retrieving grouped and rendered cookies.
|
|
226
|
+
* @internal
|
|
227
|
+
* @returns Promise resolving to the getGroupedRenderedCookies function
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const groupedCookiesFn = await getGroupedRenderedCookies();
|
|
231
|
+
* const cookieStrings = await groupedCookiesFn({ domain: 'example.com' });
|
|
232
|
+
* // Returns: ['sessionId=abc123; Domain=example.com', 'auth=xyz789; Domain=example.com']
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare const getGroupedRenderedCookies: () => Promise<(cookieSpec: CookieSpec) => Promise<string[]>>;
|
|
236
|
+
/**
|
|
237
|
+
* Dynamic import for retrieving merged and rendered cookies.
|
|
238
|
+
* @internal
|
|
239
|
+
* @returns Promise resolving to the getMergedRenderedCookies function
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const mergedCookiesFn = await getMergedRenderedCookies();
|
|
243
|
+
* const cookieString = await mergedCookiesFn(
|
|
244
|
+
* { domain: 'example.com' },
|
|
245
|
+
* { separator: '; ' }
|
|
246
|
+
* );
|
|
247
|
+
* // Returns: "sessionId=abc123; auth=xyz789"
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
declare const getMergedRenderedCookies: () => Promise<(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">) => Promise<string>>;
|
|
251
|
+
|
|
252
|
+
export { getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object matches the CookieRenderOptions interface.
|
|
3
|
+
* Used to validate render options before processing cookie output.
|
|
4
|
+
* @param obj - The object to check.
|
|
5
|
+
* @returns True if the object contains valid render options.
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { isCookieRenderOptions } from 'get-cookie';
|
|
9
|
+
*
|
|
10
|
+
* // Valid render options
|
|
11
|
+
* console.log(isCookieRenderOptions({ format: "json" })); // true
|
|
12
|
+
* console.log(isCookieRenderOptions({
|
|
13
|
+
* format: "text",
|
|
14
|
+
* separator: "\n",
|
|
15
|
+
* showFilePaths: true
|
|
16
|
+
* })); // true
|
|
17
|
+
*
|
|
18
|
+
* // Invalid examples
|
|
19
|
+
* console.log(isCookieRenderOptions({ format: "csv" })); // false - invalid format
|
|
20
|
+
* console.log(isCookieRenderOptions({ separator: "\n" })); // false - missing format
|
|
21
|
+
* console.log(isCookieRenderOptions(null)); // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
type RenderFormat = "merged" | "grouped";
|
|
25
|
+
/**
|
|
26
|
+
* Options for rendering cookies.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { RenderOptions } from 'get-cookie';
|
|
30
|
+
*
|
|
31
|
+
* // Basic rendering options
|
|
32
|
+
* const basicOptions: RenderOptions = {
|
|
33
|
+
* format: 'merged',
|
|
34
|
+
* separator: '; ',
|
|
35
|
+
* showFilePaths: false
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* // Grouped format with file paths
|
|
39
|
+
* const groupedOptions: RenderOptions = {
|
|
40
|
+
* format: 'grouped',
|
|
41
|
+
* separator: '; ',
|
|
42
|
+
* showFilePaths: true
|
|
43
|
+
* };
|
|
44
|
+
*
|
|
45
|
+
* // Custom separator
|
|
46
|
+
* const customOptions: RenderOptions = {
|
|
47
|
+
* format: 'merged',
|
|
48
|
+
* separator: ' && ',
|
|
49
|
+
* showFilePaths: false
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
interface RenderOptions {
|
|
54
|
+
/** The format to use when rendering cookies. */
|
|
55
|
+
format?: RenderFormat;
|
|
56
|
+
/** The separator to use between cookies. */
|
|
57
|
+
separator?: string;
|
|
58
|
+
/** Whether to show file paths in the output. */
|
|
59
|
+
showFilePaths?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Specification for identifying a cookie by its domain and name.
|
|
64
|
+
* Used to query specific cookies from browser storage.
|
|
65
|
+
* @remarks
|
|
66
|
+
* - Domain matching is exact unless using wildcards.
|
|
67
|
+
* - Name can be "*" to match all cookies for a domain.
|
|
68
|
+
* - Leading dots in domains match all subdomains.
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { CookieSpec } from 'get-cookie';
|
|
72
|
+
*
|
|
73
|
+
* // Basic cookie specification
|
|
74
|
+
* const cookieSpec: CookieSpec = {
|
|
75
|
+
* domain: "example.com",
|
|
76
|
+
* name: "sessionId"
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* // Using wildcards to match all cookies
|
|
80
|
+
* const allCookies: CookieSpec = {
|
|
81
|
+
* domain: "example.com",
|
|
82
|
+
* name: "*" // Match all cookies for example.com
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* // Subdomain specification
|
|
86
|
+
* const apiCookies: CookieSpec = {
|
|
87
|
+
* domain: "api.example.com",
|
|
88
|
+
* name: "auth"
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* // Match cookies across all subdomains
|
|
92
|
+
* const allSubdomainCookies: CookieSpec = {
|
|
93
|
+
* domain: ".example.com", // Note the leading dot
|
|
94
|
+
* name: "tracking"
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* // Multiple domain levels
|
|
98
|
+
* const deepSubdomainCookie: CookieSpec = {
|
|
99
|
+
* domain: "dev.api.example.com",
|
|
100
|
+
* name: "debug"
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
interface CookieSpec {
|
|
105
|
+
/** The domain the cookie belongs to. */
|
|
106
|
+
domain: string;
|
|
107
|
+
/** The name of the cookie. */
|
|
108
|
+
name: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Interface representing a cookie that has been exported from a browser's storage.
|
|
113
|
+
* This is the core data structure used to represent cookies after they have been
|
|
114
|
+
* retrieved from various browser storage mechanisms (Chrome, Firefox, etc.).
|
|
115
|
+
* @remarks
|
|
116
|
+
* - All cookies must have domain, name, and value properties.
|
|
117
|
+
* - Expiry is optional and can be a Date, "Infinity", or undefined.
|
|
118
|
+
* - Meta information is useful for tracking the cookie's origin and state.
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { ExportedCookie } from 'get-cookie';
|
|
122
|
+
*
|
|
123
|
+
* // Basic cookie with required fields
|
|
124
|
+
* const basicCookie: ExportedCookie = {
|
|
125
|
+
* domain: "example.com",
|
|
126
|
+
* name: "sessionId",
|
|
127
|
+
* value: "abc123"
|
|
128
|
+
* };
|
|
129
|
+
*
|
|
130
|
+
* // Cookie with expiry and metadata
|
|
131
|
+
* const detailedCookie: ExportedCookie = {
|
|
132
|
+
* domain: "api.example.com",
|
|
133
|
+
* name: "authToken",
|
|
134
|
+
* value: "xyz789",
|
|
135
|
+
* expiry: new Date("2024-12-31"),
|
|
136
|
+
* meta: {
|
|
137
|
+
* file: "Cookies.sqlite",
|
|
138
|
+
* browser: "Firefox",
|
|
139
|
+
* decrypted: true,
|
|
140
|
+
* secure: true,
|
|
141
|
+
* httpOnly: true,
|
|
142
|
+
* path: "/"
|
|
143
|
+
* }
|
|
144
|
+
* };
|
|
145
|
+
*
|
|
146
|
+
* // Cookie with infinite expiry (session cookie)
|
|
147
|
+
* const persistentCookie: ExportedCookie = {
|
|
148
|
+
* domain: "app.example.com",
|
|
149
|
+
* name: "preferences",
|
|
150
|
+
* value: "theme=dark",
|
|
151
|
+
* expiry: "Infinity"
|
|
152
|
+
* };
|
|
153
|
+
*
|
|
154
|
+
* // Subdomain cookie example
|
|
155
|
+
* const subdomainCookie: ExportedCookie = {
|
|
156
|
+
* domain: ".example.com", // Note the leading dot for all subdomains
|
|
157
|
+
* name: "tracking",
|
|
158
|
+
* value: "user123",
|
|
159
|
+
* meta: {
|
|
160
|
+
* browser: "Chrome",
|
|
161
|
+
* decrypted: true
|
|
162
|
+
* }
|
|
163
|
+
* };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
interface ExportedCookie {
|
|
167
|
+
/** The domain the cookie belongs to. */
|
|
168
|
+
domain: string;
|
|
169
|
+
/** The name of the cookie. */
|
|
170
|
+
name: string;
|
|
171
|
+
/** The value of the cookie. */
|
|
172
|
+
value: string;
|
|
173
|
+
/** When the cookie expires (Date object, "Infinity", or undefined). */
|
|
174
|
+
expiry?: Date | "Infinity";
|
|
175
|
+
/** Additional metadata about the cookie. */
|
|
176
|
+
meta?: {
|
|
177
|
+
/** Path to the file the cookie was exported from. */
|
|
178
|
+
file?: string;
|
|
179
|
+
/** Browser the cookie was exported from. */
|
|
180
|
+
browser?: string;
|
|
181
|
+
/** Whether the cookie value was decrypted. */
|
|
182
|
+
decrypted?: boolean;
|
|
183
|
+
/** Any additional metadata. */
|
|
184
|
+
[key: string]: unknown;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Dynamic import for the getCookie function.
|
|
190
|
+
* @internal
|
|
191
|
+
* @returns Promise resolving to the getCookie function
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const getCookieFn = await getCookie();
|
|
195
|
+
* const cookies = await getCookieFn({ domain: 'example.com' });
|
|
196
|
+
* // Returns: [{ name: 'sessionId', value: 'abc123', domain: 'example.com' }, ...]
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare const getCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
200
|
+
/**
|
|
201
|
+
* Dynamic import for Chrome-specific cookie retrieval.
|
|
202
|
+
* @internal
|
|
203
|
+
* @returns Promise resolving to the getChromeCookie function
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const chromeCookieFn = await getChromeCookie();
|
|
207
|
+
* const cookies = await chromeCookieFn({ domain: 'example.com', secure: true });
|
|
208
|
+
* // Returns Chrome-format cookies: [{ name: 'auth', value: 'xyz789', secure: true }, ...]
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare const getChromeCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
212
|
+
/**
|
|
213
|
+
* Dynamic import for Firefox-specific cookie retrieval.
|
|
214
|
+
* @internal
|
|
215
|
+
* @returns Promise resolving to the getFirefoxCookie function
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const firefoxCookieFn = await getFirefoxCookie();
|
|
219
|
+
* const cookies = await firefoxCookieFn({ path: '/api' });
|
|
220
|
+
* // Returns Firefox-format cookies: [{ name: 'token', value: 'def456', path: '/api' }, ...]
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare const getFirefoxCookie: () => Promise<(cookieSpec: CookieSpec) => Promise<ExportedCookie[]>>;
|
|
224
|
+
/**
|
|
225
|
+
* Dynamic import for retrieving grouped and rendered cookies.
|
|
226
|
+
* @internal
|
|
227
|
+
* @returns Promise resolving to the getGroupedRenderedCookies function
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const groupedCookiesFn = await getGroupedRenderedCookies();
|
|
231
|
+
* const cookieStrings = await groupedCookiesFn({ domain: 'example.com' });
|
|
232
|
+
* // Returns: ['sessionId=abc123; Domain=example.com', 'auth=xyz789; Domain=example.com']
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare const getGroupedRenderedCookies: () => Promise<(cookieSpec: CookieSpec) => Promise<string[]>>;
|
|
236
|
+
/**
|
|
237
|
+
* Dynamic import for retrieving merged and rendered cookies.
|
|
238
|
+
* @internal
|
|
239
|
+
* @returns Promise resolving to the getMergedRenderedCookies function
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const mergedCookiesFn = await getMergedRenderedCookies();
|
|
243
|
+
* const cookieString = await mergedCookiesFn(
|
|
244
|
+
* { domain: 'example.com' },
|
|
245
|
+
* { separator: '; ' }
|
|
246
|
+
* );
|
|
247
|
+
* // Returns: "sessionId=abc123; auth=xyz789"
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
declare const getMergedRenderedCookies: () => Promise<(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">) => Promise<string>>;
|
|
251
|
+
|
|
252
|
+
export { getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|