@mherod/get-cookie 4.3.2 → 4.4.1
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/.claude/settings.local.json +3 -0
- package/.dependency-cruiser.js +277 -0
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.husky/pre-push +0 -0
- package/README.md +106 -48
- package/biome.json +39 -16
- package/dist/cli.cjs +76 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +76 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +660 -283
- package/dist/index.d.ts +660 -283
- package/dist/index.js +76 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +23 -2
- package/examples/auth-tokens.ts +143 -0
- package/examples/chrome-cookies-demo.sh +117 -0
- package/examples/chrome-profile-demo.sh +126 -0
- package/examples/cli-examples.sh +0 -0
- package/examples/comprehensive-demo.ts +202 -0
- package/examples/curl-demo.sh +102 -0
- package/examples/curl-integration.sh +276 -0
- package/examples/curl-with-url.sh +136 -0
- package/examples/deduplication-demo.sh +110 -0
- package/examples/final-chrome-demo.sh +115 -0
- package/examples/github-api.sh +101 -0
- package/examples/github-private-access.sh +118 -0
- package/examples/list-profiles-demo.sh +120 -0
- package/examples/proper-curl-usage.sh +120 -0
- package/examples/simple-curl.sh +95 -0
- package/examples/test-expired-filtering.sh +68 -0
- package/examples/test-github-access.sh +245 -0
- package/examples/test-github-auth-improved.sh +136 -0
- package/examples/working-curl.sh +117 -0
- package/examples/working-github-auth.sh +87 -0
- package/package.json +72 -50
- package/tsconfig.cli.json +5 -1
- package/tsup.cli.ts +31 -1
- package/tsup.lib.ts +11 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import * as consola from 'consola';
|
|
3
|
+
import { ConsolaInstance } from 'consola';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Schema for cookie specification parameters
|
|
@@ -28,15 +29,9 @@ import * as consola from 'consola';
|
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
31
|
declare const CookieSpecSchema: z.ZodObject<{
|
|
31
|
-
name: z.
|
|
32
|
-
domain: z.
|
|
33
|
-
},
|
|
34
|
-
name: string;
|
|
35
|
-
domain: string;
|
|
36
|
-
}, {
|
|
37
|
-
name: string;
|
|
38
|
-
domain: string;
|
|
39
|
-
}>;
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
domain: z.ZodString;
|
|
34
|
+
}, z.core.$strict>;
|
|
40
35
|
/**
|
|
41
36
|
* Type definition for cookie specification
|
|
42
37
|
* Used for specifying which cookie to query
|
|
@@ -92,59 +87,19 @@ type CookieSpec = z.infer<typeof CookieSpecSchema>;
|
|
|
92
87
|
* ```
|
|
93
88
|
*/
|
|
94
89
|
declare const ExportedCookieSchema: z.ZodObject<{
|
|
95
|
-
domain: z.
|
|
96
|
-
name: z.
|
|
97
|
-
value: z.
|
|
98
|
-
expiry: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
|
|
90
|
+
domain: z.ZodString;
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
value: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<unknown, string>>, z.ZodAny>;
|
|
93
|
+
expiry: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
|
|
99
94
|
meta: z.ZodOptional<z.ZodObject<{
|
|
100
95
|
file: z.ZodOptional<z.ZodString>;
|
|
101
96
|
browser: z.ZodOptional<z.ZodString>;
|
|
102
97
|
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
103
98
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
104
99
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
105
|
-
path: z.ZodOptional<z.ZodDefault<z.
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
109
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
110
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
112
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
113
|
-
}, z.ZodUnknown, "strict">, z.objectInputType<{
|
|
114
|
-
file: z.ZodOptional<z.ZodString>;
|
|
115
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
116
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
117
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
118
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
119
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
120
|
-
}, z.ZodUnknown, "strict">>>;
|
|
121
|
-
}, "strict", z.ZodTypeAny, {
|
|
122
|
-
name: string;
|
|
123
|
-
domain: string;
|
|
124
|
-
value?: any;
|
|
125
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
126
|
-
meta?: z.objectOutputType<{
|
|
127
|
-
file: z.ZodOptional<z.ZodString>;
|
|
128
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
129
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
130
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
131
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
133
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
134
|
-
}, {
|
|
135
|
-
name: string;
|
|
136
|
-
value: string;
|
|
137
|
-
domain: string;
|
|
138
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
139
|
-
meta?: z.objectInputType<{
|
|
140
|
-
file: z.ZodOptional<z.ZodString>;
|
|
141
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
142
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
143
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
144
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
145
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
146
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
147
|
-
}>;
|
|
100
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
101
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
102
|
+
}, z.core.$strict>;
|
|
148
103
|
/**
|
|
149
104
|
* Type definition for exported cookie data
|
|
150
105
|
* Represents the structure of a cookie after it has been retrieved
|
|
@@ -177,22 +132,30 @@ declare const ExportedCookieSchema: z.ZodObject<{
|
|
|
177
132
|
* ```
|
|
178
133
|
*/
|
|
179
134
|
type ExportedCookie = z.infer<typeof ExportedCookieSchema>;
|
|
135
|
+
/**
|
|
136
|
+
* Schema for raw cookie data from browser stores
|
|
137
|
+
*/
|
|
138
|
+
declare const CookieRowSchema: z.ZodObject<{
|
|
139
|
+
expiry: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
domain: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>]>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
/**
|
|
145
|
+
* Type definition for raw cookie data
|
|
146
|
+
*/
|
|
147
|
+
type CookieRow = z.infer<typeof CookieRowSchema>;
|
|
180
148
|
/**
|
|
181
149
|
* Schema for cookie render options
|
|
182
150
|
*/
|
|
183
151
|
declare const RenderOptionsSchema: z.ZodObject<{
|
|
184
|
-
format: z.ZodOptional<z.ZodEnum<
|
|
152
|
+
format: z.ZodOptional<z.ZodEnum<{
|
|
153
|
+
merged: "merged";
|
|
154
|
+
grouped: "grouped";
|
|
155
|
+
}>>;
|
|
185
156
|
separator: z.ZodOptional<z.ZodString>;
|
|
186
157
|
showFilePaths: z.ZodOptional<z.ZodBoolean>;
|
|
187
|
-
},
|
|
188
|
-
format?: "merged" | "grouped" | undefined;
|
|
189
|
-
separator?: string | undefined;
|
|
190
|
-
showFilePaths?: boolean | undefined;
|
|
191
|
-
}, {
|
|
192
|
-
format?: "merged" | "grouped" | undefined;
|
|
193
|
-
separator?: string | undefined;
|
|
194
|
-
showFilePaths?: boolean | undefined;
|
|
195
|
-
}>;
|
|
158
|
+
}, z.core.$strict>;
|
|
196
159
|
/**
|
|
197
160
|
* Type definition for render options
|
|
198
161
|
*/
|
|
@@ -200,107 +163,24 @@ type RenderOptions = z.infer<typeof RenderOptionsSchema>;
|
|
|
200
163
|
/**
|
|
201
164
|
* Schema for browser names
|
|
202
165
|
*/
|
|
203
|
-
declare const BrowserNameSchema: z.ZodEnum<
|
|
166
|
+
declare const BrowserNameSchema: z.ZodEnum<{
|
|
167
|
+
unknown: "unknown";
|
|
168
|
+
Chrome: "Chrome";
|
|
169
|
+
Firefox: "Firefox";
|
|
170
|
+
Safari: "Safari";
|
|
171
|
+
internal: "internal";
|
|
172
|
+
}>;
|
|
204
173
|
/**
|
|
205
174
|
* Type definition for browser names
|
|
206
175
|
*/
|
|
207
176
|
type BrowserName = z.infer<typeof BrowserNameSchema>;
|
|
208
|
-
/**
|
|
209
|
-
* Schema for cookie query strategy
|
|
210
|
-
*/
|
|
211
|
-
declare const CookieQueryStrategySchema: z.ZodObject<{
|
|
212
|
-
browserName: z.ZodEnum<["Chrome", "Firefox", "Safari", "internal", "unknown"]>;
|
|
213
|
-
queryCookies: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodOptional<z.ZodString>, z.ZodOptional<z.ZodBoolean>], z.ZodUnknown>, z.ZodPromise<z.ZodArray<z.ZodObject<{
|
|
214
|
-
domain: z.ZodEffects<z.ZodString, string, string>;
|
|
215
|
-
name: z.ZodEffects<z.ZodString, string, string>;
|
|
216
|
-
value: z.ZodPipeline<z.ZodEffects<z.ZodString, unknown, string>, z.ZodAny>;
|
|
217
|
-
expiry: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
|
|
218
|
-
meta: z.ZodOptional<z.ZodObject<{
|
|
219
|
-
file: z.ZodOptional<z.ZodString>;
|
|
220
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
221
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
224
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
225
|
-
}, "strict", z.ZodUnknown, z.objectOutputType<{
|
|
226
|
-
file: z.ZodOptional<z.ZodString>;
|
|
227
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
228
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
231
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
232
|
-
}, z.ZodUnknown, "strict">, z.objectInputType<{
|
|
233
|
-
file: z.ZodOptional<z.ZodString>;
|
|
234
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
235
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
236
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
238
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
239
|
-
}, z.ZodUnknown, "strict">>>;
|
|
240
|
-
}, "strict", z.ZodTypeAny, {
|
|
241
|
-
name: string;
|
|
242
|
-
domain: string;
|
|
243
|
-
value?: any;
|
|
244
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
245
|
-
meta?: z.objectOutputType<{
|
|
246
|
-
file: z.ZodOptional<z.ZodString>;
|
|
247
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
248
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
249
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
250
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
251
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
252
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
253
|
-
}, {
|
|
254
|
-
name: string;
|
|
255
|
-
value: string;
|
|
256
|
-
domain: string;
|
|
257
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
258
|
-
meta?: z.objectInputType<{
|
|
259
|
-
file: z.ZodOptional<z.ZodString>;
|
|
260
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
261
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
262
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
263
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
264
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
265
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
266
|
-
}>, "many">>>;
|
|
267
|
-
}, "strict", z.ZodTypeAny, {
|
|
268
|
-
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
269
|
-
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, args_3: boolean | undefined, ...args: unknown[]) => Promise<{
|
|
270
|
-
name: string;
|
|
271
|
-
domain: string;
|
|
272
|
-
value?: any;
|
|
273
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
274
|
-
meta?: z.objectOutputType<{
|
|
275
|
-
file: z.ZodOptional<z.ZodString>;
|
|
276
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
277
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
278
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
280
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
281
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
282
|
-
}[]>;
|
|
283
|
-
}, {
|
|
284
|
-
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
285
|
-
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, args_3: boolean | undefined, ...args: unknown[]) => Promise<{
|
|
286
|
-
name: string;
|
|
287
|
-
value: string;
|
|
288
|
-
domain: string;
|
|
289
|
-
expiry?: number | Date | "Infinity" | undefined;
|
|
290
|
-
meta?: z.objectInputType<{
|
|
291
|
-
file: z.ZodOptional<z.ZodString>;
|
|
292
|
-
browser: z.ZodOptional<z.ZodString>;
|
|
293
|
-
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
294
|
-
secure: z.ZodOptional<z.ZodBoolean>;
|
|
295
|
-
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
296
|
-
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
297
|
-
}, z.ZodUnknown, "strict"> | undefined;
|
|
298
|
-
}[]>;
|
|
299
|
-
}>;
|
|
300
177
|
/**
|
|
301
178
|
* Type definition for cookie query strategy
|
|
302
179
|
*/
|
|
303
|
-
type CookieQueryStrategy =
|
|
180
|
+
type CookieQueryStrategy = {
|
|
181
|
+
browserName: BrowserName;
|
|
182
|
+
queryCookies: (domain: string, name: string, path?: string, secure?: boolean) => Promise<ExportedCookie[]>;
|
|
183
|
+
};
|
|
304
184
|
/**
|
|
305
185
|
* Type representing either a single cookie specification or an array of specifications.
|
|
306
186
|
* Useful when you need to query multiple cookies in a single operation.
|
|
@@ -322,31 +202,73 @@ type CookieQueryStrategy = z.infer<typeof CookieQueryStrategySchema>;
|
|
|
322
202
|
type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
323
203
|
|
|
324
204
|
/**
|
|
325
|
-
*
|
|
326
|
-
* This
|
|
327
|
-
*
|
|
328
|
-
* @param cookieSpec.name - The name of the cookie to search for
|
|
329
|
-
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
330
|
-
* @returns An array of ExportedCookie objects that match the specification
|
|
331
|
-
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
332
|
-
* to the console without throwing to the caller
|
|
205
|
+
* A composite strategy that combines multiple cookie query strategies.
|
|
206
|
+
* This class implements the CookieQueryStrategy interface and allows querying cookies
|
|
207
|
+
* from multiple browser-specific strategies simultaneously.
|
|
333
208
|
* @example
|
|
334
209
|
* ```typescript
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* // Get cookies named "userPref" from specific domain
|
|
342
|
-
* const domainCookies = await getCookie({
|
|
343
|
-
* name: "userPref",
|
|
344
|
-
* domain: "example.com"
|
|
345
|
-
* });
|
|
346
|
-
* // Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]
|
|
210
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
211
|
+
* new ChromeCookieQueryStrategy(),
|
|
212
|
+
* new FirefoxCookieQueryStrategy(),
|
|
213
|
+
* new SafariCookieQueryStrategy()
|
|
214
|
+
* ]);
|
|
215
|
+
* const cookies = await strategy.queryCookies('sessionId', 'example.com');
|
|
347
216
|
* ```
|
|
348
217
|
*/
|
|
349
|
-
declare
|
|
218
|
+
declare class CompositeCookieQueryStrategy implements CookieQueryStrategy {
|
|
219
|
+
private readonly strategies;
|
|
220
|
+
private readonly logger;
|
|
221
|
+
/**
|
|
222
|
+
* The browser name identifier for this strategy
|
|
223
|
+
* @remarks Always returns 'internal' as this is a composite strategy
|
|
224
|
+
*/
|
|
225
|
+
readonly browserName: BrowserName;
|
|
226
|
+
/**
|
|
227
|
+
* Creates a new instance of CompositeCookieQueryStrategy
|
|
228
|
+
* @param strategies - Array of browser-specific strategies to use for querying cookies
|
|
229
|
+
* @remarks
|
|
230
|
+
* - Each strategy in the array should implement the CookieQueryStrategy interface
|
|
231
|
+
* - The order of strategies determines the order of cookie querying
|
|
232
|
+
* - Failed strategies will be gracefully handled and skipped
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
236
|
+
* new ChromeCookieQueryStrategy(),
|
|
237
|
+
* new FirefoxCookieQueryStrategy()
|
|
238
|
+
* ]);
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
constructor(strategies: CookieQueryStrategy[]);
|
|
242
|
+
/**
|
|
243
|
+
* Handles strategy-specific errors and logs them appropriately
|
|
244
|
+
* @internal
|
|
245
|
+
* @param error - The error that occurred during strategy execution
|
|
246
|
+
* @param strategy - The strategy that failed
|
|
247
|
+
*/
|
|
248
|
+
private handleStrategyError;
|
|
249
|
+
/**
|
|
250
|
+
* Queries cookies using all available strategies in parallel
|
|
251
|
+
* @param name - The name pattern to match cookies against
|
|
252
|
+
* @param domain - The domain pattern to match cookies against
|
|
253
|
+
* @param store - The store pattern to match cookies against
|
|
254
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
255
|
+
* @returns Promise resolving to combined array of cookies from all strategies
|
|
256
|
+
* @remarks
|
|
257
|
+
* - Failures in individual strategies are logged but don't affect other strategies
|
|
258
|
+
* - Results are combined from all successful strategy queries
|
|
259
|
+
* - Empty arrays are returned for failed strategy queries
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
263
|
+
* new ChromeCookieQueryStrategy(),
|
|
264
|
+
* new FirefoxCookieQueryStrategy()
|
|
265
|
+
* ]);
|
|
266
|
+
* const cookies = await strategy.queryCookies('sessionId', 'example.com');
|
|
267
|
+
* console.log(cookies); // Combined results from all browsers
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
queryCookies(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
271
|
+
}
|
|
350
272
|
|
|
351
273
|
/**
|
|
352
274
|
* Base class for cookie query strategies.
|
|
@@ -390,38 +312,129 @@ declare abstract class BaseCookieQueryStrategy implements CookieQueryStrategy {
|
|
|
390
312
|
}
|
|
391
313
|
|
|
392
314
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
315
|
+
* Create a logger instance with a component tag
|
|
316
|
+
* @param component - The component name to tag logs with
|
|
317
|
+
* @returns A logger instance that prefixes all messages with the component tag
|
|
396
318
|
* @example
|
|
397
319
|
* ```typescript
|
|
398
|
-
* const
|
|
399
|
-
*
|
|
320
|
+
* const dbLogger = createTaggedLogger('Database');
|
|
321
|
+
* dbLogger.info('Connection established');
|
|
400
322
|
* ```
|
|
401
323
|
*/
|
|
402
|
-
declare
|
|
324
|
+
declare function createTaggedLogger(component: string): ConsolaInstance;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Interface for platform-specific browser control operations
|
|
328
|
+
* Following SOLID principles - Interface Segregation
|
|
329
|
+
*/
|
|
330
|
+
interface PlatformBrowserControl {
|
|
403
331
|
/**
|
|
404
|
-
*
|
|
332
|
+
* Check if the browser is supported on this platform
|
|
333
|
+
* @param browserName - The name of the browser to check
|
|
334
|
+
* @returns True if the browser is supported on this platform
|
|
405
335
|
*/
|
|
406
|
-
|
|
336
|
+
isBrowserSupported(browserName: BrowserName): boolean;
|
|
407
337
|
/**
|
|
408
|
-
*
|
|
409
|
-
* @param
|
|
410
|
-
* @
|
|
411
|
-
* @param store - Optional path to a specific cookie store file
|
|
412
|
-
* @param _force - Whether to force operations despite warnings (e.g., locked databases)
|
|
413
|
-
* @returns A promise that resolves to an array of exported cookies
|
|
414
|
-
* @protected
|
|
415
|
-
* @example
|
|
416
|
-
* ```typescript
|
|
417
|
-
* // This method is called internally by queryCookies
|
|
418
|
-
* const cookies = await strategy.queryCookies('session', 'example.com');
|
|
419
|
-
* console.log(cookies);
|
|
420
|
-
* ```
|
|
338
|
+
* Get executable names for a browser on this platform
|
|
339
|
+
* @param browserName - The name of the browser
|
|
340
|
+
* @returns Array of executable names for the browser
|
|
421
341
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
342
|
+
getBrowserExecutables(browserName: BrowserName): string[];
|
|
343
|
+
/**
|
|
344
|
+
* Launch a browser on this platform
|
|
345
|
+
* @param browserName - The name of the browser to launch
|
|
346
|
+
* @returns Promise that resolves when the browser is launched
|
|
347
|
+
* @throws {Error} When the browser is not supported or cannot be launched
|
|
348
|
+
*/
|
|
349
|
+
launchBrowser(browserName: BrowserName): Promise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Get the platform name
|
|
352
|
+
* @returns The name of the current platform
|
|
353
|
+
*/
|
|
354
|
+
getPlatformName(): string;
|
|
355
|
+
/**
|
|
356
|
+
* Check if a browser is installed
|
|
357
|
+
* @param browserName - The name of the browser to check
|
|
358
|
+
* @returns Promise that resolves to true if the browser is installed
|
|
359
|
+
*/
|
|
360
|
+
isBrowserInstalled(browserName: BrowserName): Promise<boolean>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Result of a browser conflict handling operation
|
|
365
|
+
*/
|
|
366
|
+
interface BrowserLockResult {
|
|
367
|
+
/** Whether the conflict was resolved */
|
|
368
|
+
resolved: boolean;
|
|
369
|
+
/** Whether the browser should be relaunched */
|
|
370
|
+
shouldRelaunch: boolean;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Shared handler for browser lock/permission issues
|
|
374
|
+
* Follows DRY principle to avoid duplicating logic across browser strategies
|
|
375
|
+
* Uses Strategy pattern for platform-specific operations
|
|
376
|
+
*/
|
|
377
|
+
declare class BrowserLockHandler {
|
|
378
|
+
private readonly logger;
|
|
379
|
+
private readonly browserName;
|
|
380
|
+
private readonly platformControl;
|
|
381
|
+
/**
|
|
382
|
+
* Creates a new BrowserLockHandler instance
|
|
383
|
+
* @param logger - Tagged logger instance for this handler
|
|
384
|
+
* @param browserName - Name of the browser this handler manages
|
|
385
|
+
* @param platformControl - Optional platform control strategy (for testing)
|
|
386
|
+
*/
|
|
387
|
+
constructor(logger: ReturnType<typeof createTaggedLogger>, browserName: BrowserName, platformControl?: PlatformBrowserControl);
|
|
388
|
+
/**
|
|
389
|
+
* Handle database lock or permission errors
|
|
390
|
+
* @param error - The error to check
|
|
391
|
+
* @param file - The file that was locked/inaccessible
|
|
392
|
+
* @param processes - Running processes for this browser
|
|
393
|
+
* @param autoClose - Whether to attempt auto-closing the browser
|
|
394
|
+
* @returns Promise that resolves to lock result
|
|
395
|
+
*/
|
|
396
|
+
handleBrowserConflict(error: unknown, file: string, processes: Array<{
|
|
397
|
+
pid: number;
|
|
398
|
+
command: string;
|
|
399
|
+
}>, autoClose?: boolean): Promise<BrowserLockResult>;
|
|
400
|
+
/**
|
|
401
|
+
* Check if an error indicates a database lock or permission issue
|
|
402
|
+
* @param error - The error to check
|
|
403
|
+
* @returns True if this is a lock-related error
|
|
404
|
+
*/
|
|
405
|
+
private isLockError;
|
|
406
|
+
/**
|
|
407
|
+
* Log detailed file handle information
|
|
408
|
+
* @param file - The file that was locked
|
|
409
|
+
* @param processes - Browser processes detected
|
|
410
|
+
*/
|
|
411
|
+
private logFileHandleInfo;
|
|
412
|
+
/**
|
|
413
|
+
* Handle process conflicts and optionally close the browser
|
|
414
|
+
* @param file - The file that was locked
|
|
415
|
+
* @param processes - Browser processes detected
|
|
416
|
+
* @param autoClose - Whether to attempt auto-closing
|
|
417
|
+
* @returns Promise that resolves to lock result
|
|
418
|
+
*/
|
|
419
|
+
private handleProcessConflict;
|
|
420
|
+
/**
|
|
421
|
+
* Handle detected browser processes
|
|
422
|
+
* @param file - The file that was locked
|
|
423
|
+
* @param processes - Browser processes detected
|
|
424
|
+
* @param autoClose - Whether to attempt auto-closing
|
|
425
|
+
* @returns Promise that resolves to lock result
|
|
426
|
+
*/
|
|
427
|
+
private handleBrowserProcesses;
|
|
428
|
+
/**
|
|
429
|
+
* Attempt to close the browser gracefully
|
|
430
|
+
* @returns Promise that resolves to lock result
|
|
431
|
+
*/
|
|
432
|
+
private attemptBrowserClose;
|
|
433
|
+
/**
|
|
434
|
+
* Relaunch browser after successful operation
|
|
435
|
+
* @returns Promise that resolves when browser is relaunched
|
|
436
|
+
*/
|
|
437
|
+
relaunchBrowser(): Promise<void>;
|
|
425
438
|
}
|
|
426
439
|
|
|
427
440
|
/**
|
|
@@ -432,31 +445,186 @@ declare class ChromeCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
432
445
|
/**
|
|
433
446
|
* Supported Chromium-based browsers
|
|
434
447
|
*/
|
|
435
|
-
declare const CHROMIUM_BASED_BROWSERS: readonly ["chrome", "chromium", "brave", "edge", "opera", "vivaldi", "whale"];
|
|
448
|
+
declare const CHROMIUM_BASED_BROWSERS: readonly ["chrome", "chromium", "brave", "edge", "arc", "opera", "opera-gx", "vivaldi", "whale"];
|
|
449
|
+
/**
|
|
450
|
+
* Type representing all supported Chromium-based browsers.
|
|
451
|
+
* This includes Chrome, Edge, Brave, Arc, Opera, and other Chromium derivatives.
|
|
452
|
+
*/
|
|
436
453
|
type ChromiumBrowser = (typeof CHROMIUM_BASED_BROWSERS)[number];
|
|
437
454
|
|
|
455
|
+
interface DecryptionContext {
|
|
456
|
+
file: string;
|
|
457
|
+
password: string | Buffer;
|
|
458
|
+
browser: string;
|
|
459
|
+
metaVersion?: number;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Base strategy for querying cookies from Chromium-based browsers.
|
|
463
|
+
* This abstract class provides shared logic for Chrome, Chromium, Brave, Edge, etc.
|
|
464
|
+
*/
|
|
465
|
+
declare abstract class BaseChromiumCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
466
|
+
protected lockHandler: BrowserLockHandler;
|
|
467
|
+
protected browserDisplayName: string;
|
|
468
|
+
protected browserType: ChromiumBrowser;
|
|
469
|
+
/**
|
|
470
|
+
* Creates a new instance of BaseChromiumCookieQueryStrategy
|
|
471
|
+
* @param strategyName - Name of the strategy for logging
|
|
472
|
+
* @param browserName - Display name of the browser
|
|
473
|
+
* @param browserType - The Chromium browser type for password retrieval
|
|
474
|
+
*/
|
|
475
|
+
constructor(strategyName: string, browserName: string, browserType?: ChromiumBrowser);
|
|
476
|
+
/**
|
|
477
|
+
* Batch query cookies for multiple specs
|
|
478
|
+
* Optimized to execute combined SQL queries per database file
|
|
479
|
+
* @param specs - Array of cookie specifications
|
|
480
|
+
* @returns Array of exported cookies
|
|
481
|
+
*/
|
|
482
|
+
batchQueryCookies(specs: CookieSpec[]): Promise<ExportedCookie[]>;
|
|
483
|
+
/**
|
|
484
|
+
* Process a batch of specs for a single cookie file
|
|
485
|
+
* @param file - Cookie file path
|
|
486
|
+
* @param specs - Array of cookie specifications
|
|
487
|
+
* @param password - Decryption password
|
|
488
|
+
* @returns Array of exported cookies
|
|
489
|
+
*/
|
|
490
|
+
protected processBatchFile(file: string, specs: CookieSpec[], password: string | Buffer): Promise<ExportedCookie[]>;
|
|
491
|
+
/**
|
|
492
|
+
* Get cookie file paths for the browser
|
|
493
|
+
* @param store - Optional specific store path
|
|
494
|
+
* @returns Array of cookie file paths
|
|
495
|
+
*/
|
|
496
|
+
protected abstract getCookieFilePaths(store?: string): string[];
|
|
497
|
+
/**
|
|
498
|
+
* Get the browser-specific display name
|
|
499
|
+
* @returns Browser display name
|
|
500
|
+
*/
|
|
501
|
+
protected getBrowserName(): string;
|
|
502
|
+
/**
|
|
503
|
+
* Executes the Chromium-specific query logic
|
|
504
|
+
* @param name - The name pattern to match cookies against
|
|
505
|
+
* @param domain - The domain pattern to match cookies against
|
|
506
|
+
* @param store - Optional path to a specific cookie store file
|
|
507
|
+
* @param force - Whether to force operations despite warnings
|
|
508
|
+
* @returns A promise that resolves to an array of exported cookies
|
|
509
|
+
*/
|
|
510
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
511
|
+
/**
|
|
512
|
+
* Check if the current platform is supported
|
|
513
|
+
* @returns True if platform is supported
|
|
514
|
+
*/
|
|
515
|
+
protected isPlatformSupported(): boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Get cookie files to process
|
|
518
|
+
* @param store - Optional specific store path
|
|
519
|
+
* @returns Array of file paths
|
|
520
|
+
*/
|
|
521
|
+
protected getCookieFiles(store?: string): string[];
|
|
522
|
+
/**
|
|
523
|
+
* Convert error to string message
|
|
524
|
+
* @param error - The error to convert
|
|
525
|
+
* @returns Error message string
|
|
526
|
+
*/
|
|
527
|
+
protected getErrorMessage(error: unknown): string;
|
|
528
|
+
/**
|
|
529
|
+
* Process a file with retry logic for lock conflicts
|
|
530
|
+
* @param file - Cookie file path
|
|
531
|
+
* @param name - Cookie name pattern
|
|
532
|
+
* @param domain - Domain pattern
|
|
533
|
+
* @param password - Decryption password
|
|
534
|
+
* @param force - Force processing
|
|
535
|
+
* @returns Array of exported cookies
|
|
536
|
+
*/
|
|
537
|
+
private processFileWithRetry;
|
|
538
|
+
/**
|
|
539
|
+
* Handle file processing errors
|
|
540
|
+
* @param error - The error that occurred
|
|
541
|
+
* @param file - File path
|
|
542
|
+
* @param name - Cookie name pattern
|
|
543
|
+
* @param domain - Domain pattern
|
|
544
|
+
* @param force - Whether to force operations
|
|
545
|
+
* @returns Lock result indicating if resolved and should relaunch
|
|
546
|
+
*/
|
|
547
|
+
private handleFileError;
|
|
548
|
+
/**
|
|
549
|
+
* Retry after browser close
|
|
550
|
+
* @param file - Cookie file path
|
|
551
|
+
* @param name - Cookie name pattern
|
|
552
|
+
* @param domain - Domain pattern
|
|
553
|
+
* @param password - Decryption password
|
|
554
|
+
* @param shouldRelaunch - Whether to relaunch browser
|
|
555
|
+
* @returns Array of exported cookies
|
|
556
|
+
*/
|
|
557
|
+
private retryAfterBrowserClose;
|
|
558
|
+
/**
|
|
559
|
+
* Process a single cookie file
|
|
560
|
+
* @param file - Cookie file path
|
|
561
|
+
* @param name - Cookie name pattern
|
|
562
|
+
* @param domain - Domain pattern
|
|
563
|
+
* @param password - Decryption password
|
|
564
|
+
* @returns Array of exported cookies
|
|
565
|
+
*/
|
|
566
|
+
protected processFile(file: string, name: string, domain: string, password: string | Buffer): Promise<ExportedCookie[]>;
|
|
567
|
+
/**
|
|
568
|
+
* Get meta version from Chrome database
|
|
569
|
+
* @param file - Database file path
|
|
570
|
+
* @returns Meta version number
|
|
571
|
+
*/
|
|
572
|
+
protected getMetaVersion(file: string): Promise<number>;
|
|
573
|
+
/**
|
|
574
|
+
* Process a single cookie
|
|
575
|
+
* @param cookie - Cookie row from database
|
|
576
|
+
* @param context - Decryption context
|
|
577
|
+
* @returns Exported cookie
|
|
578
|
+
*/
|
|
579
|
+
protected processCookie(cookie: CookieRow, context: DecryptionContext): Promise<ExportedCookie>;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Strategy for querying cookies from Chrome browser.
|
|
584
|
+
* This class extends the BaseChromiumCookieQueryStrategy with Chrome-specific logic.
|
|
585
|
+
* @example
|
|
586
|
+
* ```typescript
|
|
587
|
+
* const strategy = new ChromeCookieQueryStrategy();
|
|
588
|
+
* const cookies = await strategy.queryCookies('session', 'example.com');
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
declare class ChromeCookieQueryStrategy extends BaseChromiumCookieQueryStrategy {
|
|
592
|
+
private readonly profileName?;
|
|
593
|
+
/**
|
|
594
|
+
* Creates a new instance of ChromeCookieQueryStrategy
|
|
595
|
+
* @param profileName - Optional specific profile name to target
|
|
596
|
+
*/
|
|
597
|
+
constructor(profileName?: string);
|
|
598
|
+
/**
|
|
599
|
+
* Get Chrome-specific cookie file paths
|
|
600
|
+
* @param store - Optional specific store path
|
|
601
|
+
* @returns Array of cookie file paths
|
|
602
|
+
*/
|
|
603
|
+
protected getCookieFilePaths(store?: string): string[];
|
|
604
|
+
}
|
|
605
|
+
|
|
438
606
|
/**
|
|
439
607
|
* Strategy for querying cookies from Chromium-based browsers (Chrome, Brave, Edge, etc.)
|
|
440
|
-
* This class extends the
|
|
441
|
-
*
|
|
608
|
+
* This class extends the BaseChromiumCookieQueryStrategy with browser-specific path discovery.
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* const strategy = new ChromiumCookieQueryStrategy('brave');
|
|
612
|
+
* const cookies = await strategy.queryCookies('session', 'example.com');
|
|
613
|
+
* ```
|
|
442
614
|
*/
|
|
443
|
-
declare class ChromiumCookieQueryStrategy extends
|
|
444
|
-
private browser;
|
|
615
|
+
declare class ChromiumCookieQueryStrategy extends BaseChromiumCookieQueryStrategy {
|
|
616
|
+
private readonly browser;
|
|
445
617
|
/**
|
|
446
618
|
* Creates a new instance of ChromiumCookieQueryStrategy
|
|
447
619
|
* @param browser - The Chromium-based browser to query (chrome, brave, edge, etc.)
|
|
448
620
|
*/
|
|
449
621
|
constructor(browser?: ChromiumBrowser);
|
|
450
622
|
/**
|
|
451
|
-
*
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Executes the Chromium-specific query logic
|
|
623
|
+
* Get browser-specific cookie file paths
|
|
624
|
+
* @param store - Optional specific store path
|
|
625
|
+
* @returns Array of cookie file paths
|
|
456
626
|
*/
|
|
457
|
-
protected
|
|
458
|
-
private processFile;
|
|
459
|
-
private processCookie;
|
|
627
|
+
protected getCookieFilePaths(store?: string): string[];
|
|
460
628
|
}
|
|
461
629
|
|
|
462
630
|
/**
|
|
@@ -474,28 +642,79 @@ declare class ChromiumCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
474
642
|
* ```
|
|
475
643
|
*/
|
|
476
644
|
declare class FirefoxCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
645
|
+
private readonly lockHandler;
|
|
477
646
|
/**
|
|
478
647
|
* Creates a new instance of FirefoxCookieQueryStrategy
|
|
479
648
|
*/
|
|
480
649
|
constructor();
|
|
481
650
|
/**
|
|
482
|
-
*
|
|
483
|
-
* @param
|
|
484
|
-
* @param
|
|
485
|
-
* @
|
|
651
|
+
* Creates the query parameters for cookie extraction using the new query builder
|
|
652
|
+
* @param name - The cookie name to search for
|
|
653
|
+
* @param domain - The domain pattern to match cookies against
|
|
654
|
+
* @param file - The database file path for metadata
|
|
655
|
+
* @returns Query configuration object
|
|
656
|
+
* @private
|
|
657
|
+
*/
|
|
658
|
+
private createCookieQueryConfig;
|
|
659
|
+
/**
|
|
660
|
+
* Handles errors that occur during cookie extraction
|
|
661
|
+
* @param error - The error that occurred
|
|
662
|
+
* @param file - The database file being queried
|
|
663
|
+
* @param force - Whether operations are being forced
|
|
664
|
+
* @param name - The cookie name being searched
|
|
665
|
+
* @param domain - The domain being searched
|
|
666
|
+
* @returns Promise resolving to retry configuration
|
|
486
667
|
* @private
|
|
487
668
|
*/
|
|
488
|
-
private
|
|
669
|
+
private handleCookieExtractionError;
|
|
670
|
+
/**
|
|
671
|
+
* Logs cookie extraction errors in a consistent format
|
|
672
|
+
* @param error - The error to log
|
|
673
|
+
* @param file - The file that failed
|
|
674
|
+
* @param name - The cookie name
|
|
675
|
+
* @param domain - The domain
|
|
676
|
+
* @private
|
|
677
|
+
*/
|
|
678
|
+
private logExtractError;
|
|
679
|
+
/**
|
|
680
|
+
* Performs a retry attempt after browser closure
|
|
681
|
+
* @param queryConfig - The cookie query configuration
|
|
682
|
+
* @param shouldRelaunch - Whether to relaunch the browser after success
|
|
683
|
+
* @returns Promise resolving to extracted cookies
|
|
684
|
+
* @private
|
|
685
|
+
*/
|
|
686
|
+
private performRetryAfterClose;
|
|
687
|
+
/**
|
|
688
|
+
* Processes a single Firefox cookie file for the given parameters
|
|
689
|
+
* @param file - The cookie file to process
|
|
690
|
+
* @param name - The cookie name to search for
|
|
691
|
+
* @param domain - The domain pattern to match
|
|
692
|
+
* @param force - Whether to force operations despite warnings
|
|
693
|
+
* @returns Promise resolving to extracted cookies from this file
|
|
694
|
+
* @private
|
|
695
|
+
*/
|
|
696
|
+
private processCookieFile;
|
|
697
|
+
/**
|
|
698
|
+
* Execute query using the new SQL utilities
|
|
699
|
+
* @param queryConfig - Query configuration from createCookieQueryConfig
|
|
700
|
+
* @param queryConfig.file
|
|
701
|
+
* @param queryConfig.sql
|
|
702
|
+
* @param queryConfig.params
|
|
703
|
+
* @param queryConfig.rowTransform
|
|
704
|
+
* @returns Promise resolving to exported cookies
|
|
705
|
+
* @private
|
|
706
|
+
*/
|
|
707
|
+
private executeQueryWithNewUtilities;
|
|
489
708
|
/**
|
|
490
709
|
* Executes the Firefox-specific query logic
|
|
491
710
|
* @param name - The name pattern to match cookies against
|
|
492
711
|
* @param domain - The domain pattern to match cookies against
|
|
493
712
|
* @param store - Optional path to a specific cookie store file
|
|
494
|
-
* @param
|
|
713
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
495
714
|
* @returns A promise that resolves to an array of exported cookies
|
|
496
715
|
* @protected
|
|
497
716
|
*/
|
|
498
|
-
protected executeQuery(name: string, domain: string, store?: string,
|
|
717
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
499
718
|
}
|
|
500
719
|
|
|
501
720
|
/**
|
|
@@ -504,6 +723,7 @@ declare class FirefoxCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
504
723
|
* cookie extraction logic.
|
|
505
724
|
*/
|
|
506
725
|
declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
726
|
+
private readonly lockHandler;
|
|
507
727
|
/**
|
|
508
728
|
* Creates a new instance of SafariCookieQueryStrategy
|
|
509
729
|
*/
|
|
@@ -517,7 +737,7 @@ declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
517
737
|
/**
|
|
518
738
|
* Formats the domain by removing leading dot if present
|
|
519
739
|
* @param domain - Domain to format
|
|
520
|
-
* @returns Formatted domain
|
|
740
|
+
* @returns Formatted domain or empty string if domain is invalid
|
|
521
741
|
*/
|
|
522
742
|
private formatDomain;
|
|
523
743
|
/**
|
|
@@ -550,88 +770,245 @@ declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
550
770
|
* @param cookieDbPath - Path to the cookie database
|
|
551
771
|
* @param name - Name of the cookie to find
|
|
552
772
|
* @param domain - Domain to filter cookies by
|
|
773
|
+
* @param force - Whether to skip interactive prompts
|
|
553
774
|
* @returns Array of exported cookies
|
|
554
775
|
*/
|
|
555
776
|
private decodeCookies;
|
|
777
|
+
/**
|
|
778
|
+
* Check file permissions and handle permission errors
|
|
779
|
+
* @param cookieDbPath - Path to the cookie database
|
|
780
|
+
* @param force - Whether to skip interactive prompts
|
|
781
|
+
* @returns True if permissions are granted, false otherwise
|
|
782
|
+
*/
|
|
783
|
+
private checkAndHandlePermissions;
|
|
784
|
+
/**
|
|
785
|
+
* Process and filter cookies based on name and domain criteria
|
|
786
|
+
* @param cookies - Raw cookies from binary file
|
|
787
|
+
* @param name - Name filter
|
|
788
|
+
* @param domain - Domain filter
|
|
789
|
+
* @param cookieDbPath - Path to cookie database for metadata
|
|
790
|
+
* @returns Processed and filtered cookies
|
|
791
|
+
*/
|
|
792
|
+
private processCookies;
|
|
793
|
+
/**
|
|
794
|
+
* Check if cookie matches the search criteria
|
|
795
|
+
* @param cookie - Raw cookie object
|
|
796
|
+
* @param name - Name filter
|
|
797
|
+
* @param domain - Domain filter
|
|
798
|
+
* @returns True if cookie matches criteria
|
|
799
|
+
*/
|
|
800
|
+
private matchesCriteria;
|
|
801
|
+
/**
|
|
802
|
+
* Type guard to check if an object is a valid cookie object
|
|
803
|
+
* @param cookie - Object to check
|
|
804
|
+
* @returns True if object has expected cookie properties
|
|
805
|
+
*/
|
|
806
|
+
private isCookieObject;
|
|
807
|
+
/**
|
|
808
|
+
* Map raw cookie to ExportedCookie format
|
|
809
|
+
* @param cookie - Raw cookie object
|
|
810
|
+
* @param cookieDbPath - Path to cookie database for metadata
|
|
811
|
+
* @returns Formatted ExportedCookie
|
|
812
|
+
*/
|
|
813
|
+
private mapToExportedCookie;
|
|
814
|
+
/**
|
|
815
|
+
* Handle errors that occur during cookie decoding
|
|
816
|
+
* @param error - The error that occurred
|
|
817
|
+
* @param cookieDbPath - Path to the cookie database
|
|
818
|
+
* @param name - Name filter used
|
|
819
|
+
* @param domain - Domain filter used
|
|
820
|
+
* @param force - Whether interactive prompts were skipped
|
|
821
|
+
* @returns Empty array as fallback
|
|
822
|
+
*/
|
|
823
|
+
private handleDecodingError;
|
|
824
|
+
/**
|
|
825
|
+
* Handle permission-related errors
|
|
826
|
+
* @param error - The error that occurred
|
|
827
|
+
* @param cookieDbPath - Path to the cookie database
|
|
828
|
+
* @param name - Name filter used
|
|
829
|
+
* @param domain - Domain filter used
|
|
830
|
+
* @param force - Whether interactive prompts were skipped
|
|
831
|
+
*/
|
|
832
|
+
private handlePermissionError;
|
|
833
|
+
/**
|
|
834
|
+
* Log non-permission errors that occur during decoding
|
|
835
|
+
* @param error - The error that occurred
|
|
836
|
+
* @param cookieDbPath - Path to the cookie database
|
|
837
|
+
* @param name - Name filter used
|
|
838
|
+
* @param domain - Domain filter used
|
|
839
|
+
*/
|
|
840
|
+
private logDecodingError;
|
|
556
841
|
/**
|
|
557
842
|
* Executes the Safari-specific query logic
|
|
558
843
|
* @param name - Name of the cookie to find
|
|
559
844
|
* @param domain - Domain to filter cookies by
|
|
560
845
|
* @param store - Optional store path
|
|
561
|
-
* @param
|
|
846
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
562
847
|
* @returns Array of matching cookies, or empty array if none found
|
|
563
848
|
* @protected
|
|
564
849
|
*/
|
|
565
|
-
protected executeQuery(name: string, domain: string, store?: string,
|
|
850
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
851
|
+
/**
|
|
852
|
+
* Validate home directory
|
|
853
|
+
* @param home - Home directory path
|
|
854
|
+
* @returns True if valid, false otherwise
|
|
855
|
+
*/
|
|
856
|
+
private isValidHomeDirectory;
|
|
857
|
+
/**
|
|
858
|
+
* Attempt to decode cookies with lock conflict handling
|
|
859
|
+
* @param cookieDbPath - Path to cookie database
|
|
860
|
+
* @param name - Normalized cookie name filter
|
|
861
|
+
* @param domain - Normalized domain filter
|
|
862
|
+
* @param force - Whether to force operations
|
|
863
|
+
* @returns Result object with success status and data
|
|
864
|
+
*/
|
|
865
|
+
private attemptDecodeWithLockHandling;
|
|
866
|
+
/**
|
|
867
|
+
* Handle browser lock conflicts
|
|
868
|
+
* @param error - The error that occurred
|
|
869
|
+
* @param cookieDbPath - Path to cookie database
|
|
870
|
+
* @param force - Whether to force operations
|
|
871
|
+
* @returns Result indicating what action to take next
|
|
872
|
+
*/
|
|
873
|
+
private handleLockConflict;
|
|
874
|
+
/**
|
|
875
|
+
* Check if error indicates a lock conflict
|
|
876
|
+
* @param error - Error to check
|
|
877
|
+
* @returns True if this is a lock-related error
|
|
878
|
+
*/
|
|
879
|
+
private isLockError;
|
|
880
|
+
/**
|
|
881
|
+
* Retry cookie extraction after browser was closed
|
|
882
|
+
* @param cookieDbPath - Path to cookie database
|
|
883
|
+
* @param name - Cookie name filter
|
|
884
|
+
* @param domain - Domain filter
|
|
885
|
+
* @param force - Whether to force operations
|
|
886
|
+
* @param shouldRelaunch - Whether browser should be relaunched
|
|
887
|
+
* @returns Cookies or empty array
|
|
888
|
+
*/
|
|
889
|
+
private retryAfterBrowserClose;
|
|
890
|
+
/**
|
|
891
|
+
* Handle failure during retry attempt
|
|
892
|
+
* @param retryError - Error that occurred during retry
|
|
893
|
+
* @param cookieDbPath - Path to cookie database
|
|
894
|
+
* @param shouldRelaunch - Whether browser should be relaunched
|
|
895
|
+
* @returns Empty array
|
|
896
|
+
*/
|
|
897
|
+
private handleRetryFailure;
|
|
898
|
+
/**
|
|
899
|
+
* Log query errors
|
|
900
|
+
* @param error - The error that occurred
|
|
901
|
+
* @param name - Cookie name filter
|
|
902
|
+
* @param domain - Domain filter
|
|
903
|
+
*/
|
|
904
|
+
private logQueryError;
|
|
566
905
|
}
|
|
567
906
|
|
|
568
907
|
/**
|
|
569
|
-
*
|
|
570
|
-
* This
|
|
571
|
-
*
|
|
908
|
+
* Retrieves browser cookies that match the specified cookie name and domain criteria.
|
|
909
|
+
* This function provides a way to search and filter cookies based on given specifications.
|
|
910
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
911
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
912
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
913
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
914
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
915
|
+
* to the console without throwing to the caller
|
|
572
916
|
* @example
|
|
573
917
|
* ```typescript
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* ]
|
|
579
|
-
*
|
|
918
|
+
* import { getCookie } from "@mherod/get-cookie";
|
|
919
|
+
*
|
|
920
|
+
* // Get all cookies named "sessionId"
|
|
921
|
+
* const cookies = await getCookie({ name: "sessionId" });
|
|
922
|
+
* // Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
|
|
923
|
+
*
|
|
924
|
+
* // Get cookies named "userPref" from specific domain
|
|
925
|
+
* const domainCookies = await getCookie({
|
|
926
|
+
* name: "userPref",
|
|
927
|
+
* domain: "example.com"
|
|
928
|
+
* });
|
|
929
|
+
* // Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]
|
|
580
930
|
* ```
|
|
581
931
|
*/
|
|
582
|
-
declare
|
|
583
|
-
|
|
584
|
-
|
|
932
|
+
declare function getCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Options for batch cookie retrieval
|
|
936
|
+
*/
|
|
937
|
+
interface BatchGetCookiesOptions {
|
|
585
938
|
/**
|
|
586
|
-
*
|
|
587
|
-
*
|
|
939
|
+
* Whether to deduplicate cookies across all specs
|
|
940
|
+
* When true, keeps the cookie with the longest value for each unique name+domain combination
|
|
941
|
+
* @default true
|
|
588
942
|
*/
|
|
589
|
-
|
|
943
|
+
deduplicate?: boolean;
|
|
590
944
|
/**
|
|
591
|
-
*
|
|
592
|
-
* @
|
|
593
|
-
* @remarks
|
|
594
|
-
* - Each strategy in the array should implement the CookieQueryStrategy interface
|
|
595
|
-
* - The order of strategies determines the order of cookie querying
|
|
596
|
-
* - Failed strategies will be gracefully handled and skipped
|
|
597
|
-
* @example
|
|
598
|
-
* ```typescript
|
|
599
|
-
* const strategy = new CompositeCookieQueryStrategy([
|
|
600
|
-
* new ChromeCookieQueryStrategy(),
|
|
601
|
-
* new FirefoxCookieQueryStrategy()
|
|
602
|
-
* ]);
|
|
603
|
-
* ```
|
|
945
|
+
* Maximum number of concurrent requests
|
|
946
|
+
* @default 10
|
|
604
947
|
*/
|
|
605
|
-
|
|
948
|
+
concurrency?: number;
|
|
606
949
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* @
|
|
610
|
-
* @param strategy - The strategy that failed
|
|
950
|
+
* Whether to continue on errors for individual specs
|
|
951
|
+
* When true, errors for individual specs won't fail the entire batch
|
|
952
|
+
* @default true
|
|
611
953
|
*/
|
|
612
|
-
|
|
954
|
+
continueOnError?: boolean;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Result for a single cookie spec in batch operation
|
|
958
|
+
*/
|
|
959
|
+
interface BatchCookieResult {
|
|
613
960
|
/**
|
|
614
|
-
*
|
|
615
|
-
* @param name - The name pattern to match cookies against
|
|
616
|
-
* @param domain - The domain pattern to match cookies against
|
|
617
|
-
* @param store - The store pattern to match cookies against
|
|
618
|
-
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
619
|
-
* @returns Promise resolving to combined array of cookies from all strategies
|
|
620
|
-
* @remarks
|
|
621
|
-
* - Failures in individual strategies are logged but don't affect other strategies
|
|
622
|
-
* - Results are combined from all successful strategy queries
|
|
623
|
-
* - Empty arrays are returned for failed strategy queries
|
|
624
|
-
* @example
|
|
625
|
-
* ```typescript
|
|
626
|
-
* const strategy = new CompositeCookieQueryStrategy([
|
|
627
|
-
* new ChromeCookieQueryStrategy(),
|
|
628
|
-
* new FirefoxCookieQueryStrategy()
|
|
629
|
-
* ]);
|
|
630
|
-
* const cookies = await strategy.queryCookies('sessionId', 'example.com');
|
|
631
|
-
* console.log(cookies); // Combined results from all browsers
|
|
632
|
-
* ```
|
|
961
|
+
* The original spec that was queried
|
|
633
962
|
*/
|
|
634
|
-
|
|
963
|
+
spec: CookieSpec;
|
|
964
|
+
/**
|
|
965
|
+
* The cookies retrieved for this spec
|
|
966
|
+
*/
|
|
967
|
+
cookies: ExportedCookie[];
|
|
968
|
+
/**
|
|
969
|
+
* Error if the query failed (only when continueOnError is true)
|
|
970
|
+
*/
|
|
971
|
+
error?: Error;
|
|
635
972
|
}
|
|
973
|
+
/**
|
|
974
|
+
* Retrieves multiple cookie specifications in parallel with intelligent deduplication.
|
|
975
|
+
* This function efficiently fetches cookies for multiple specifications and can optionally
|
|
976
|
+
* deduplicate the results to keep only the most valid cookie for each unique name+domain pair.
|
|
977
|
+
* @param specs - Array of cookie specifications to retrieve
|
|
978
|
+
* @param options - Options for batch retrieval
|
|
979
|
+
* @returns Array of exported cookies, optionally deduplicated
|
|
980
|
+
* @example
|
|
981
|
+
* ```typescript
|
|
982
|
+
* import { batchGetCookies } from "@mherod/get-cookie";
|
|
983
|
+
*
|
|
984
|
+
* // Fetch multiple cookies in parallel
|
|
985
|
+
* const cookies = await batchGetCookies([
|
|
986
|
+
* { name: "auth", domain: "api.example.com" },
|
|
987
|
+
* { name: "session", domain: "example.com" },
|
|
988
|
+
* { name: "token", domain: "*.example.com" }
|
|
989
|
+
* ]);
|
|
990
|
+
*
|
|
991
|
+
* // With options
|
|
992
|
+
* const cookies = await batchGetCookies(
|
|
993
|
+
* [
|
|
994
|
+
* { name: "auth", domain: "api.example.com" },
|
|
995
|
+
* { name: "session", domain: "example.com" }
|
|
996
|
+
* ],
|
|
997
|
+
* {
|
|
998
|
+
* deduplicate: true, // Keep only the best cookie for each name+domain
|
|
999
|
+
* concurrency: 5, // Limit concurrent requests
|
|
1000
|
+
* continueOnError: true // Don't fail entire batch on individual errors
|
|
1001
|
+
* }
|
|
1002
|
+
* );
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
declare function batchGetCookies(specs: CookieSpec[], options?: BatchGetCookiesOptions): Promise<ExportedCookie[]>;
|
|
1006
|
+
/**
|
|
1007
|
+
* Retrieves multiple cookie specifications with detailed results for each spec
|
|
1008
|
+
* @param specs - Array of cookie specifications to retrieve
|
|
1009
|
+
* @param options - Options for batch retrieval
|
|
1010
|
+
* @returns Array of batch results with cookies and potential errors
|
|
1011
|
+
*/
|
|
1012
|
+
declare function batchGetCookiesWithResults(specs: CookieSpec[], options?: Omit<BatchGetCookiesOptions, "deduplicate">): Promise<BatchCookieResult[]>;
|
|
636
1013
|
|
|
637
|
-
export { type BrowserName, ChromeCookieQueryStrategy, ChromiumCookieQueryStrategy, CompositeCookieQueryStrategy, type CookieQueryStrategy, type CookieSpec, type ExportedCookie, FirefoxCookieQueryStrategy, type MultiCookieSpec, type RenderOptions, SafariCookieQueryStrategy, getCookie };
|
|
1014
|
+
export { type BatchCookieResult, type BatchGetCookiesOptions, type BrowserName, ChromeCookieQueryStrategy, ChromiumCookieQueryStrategy, CompositeCookieQueryStrategy, type CookieQueryStrategy, type CookieSpec, type ExportedCookie, FirefoxCookieQueryStrategy, type MultiCookieSpec, type RenderOptions, SafariCookieQueryStrategy, batchGetCookies, batchGetCookiesWithResults, getCookie };
|