@mherod/get-cookie 4.3.2 → 4.4.0
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 -0
- package/.husky/pre-commit +0 -0
- 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 +647 -126
- package/dist/index.d.ts +647 -126
- 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 +46 -27
- 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
|
|
@@ -132,8 +133,8 @@ declare const ExportedCookieSchema: z.ZodObject<{
|
|
|
132
133
|
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
133
134
|
}, z.ZodUnknown, "strict"> | undefined;
|
|
134
135
|
}, {
|
|
135
|
-
name: string;
|
|
136
136
|
value: string;
|
|
137
|
+
name: string;
|
|
137
138
|
domain: string;
|
|
138
139
|
expiry?: number | Date | "Infinity" | undefined;
|
|
139
140
|
meta?: z.objectInputType<{
|
|
@@ -177,6 +178,29 @@ declare const ExportedCookieSchema: z.ZodObject<{
|
|
|
177
178
|
* ```
|
|
178
179
|
*/
|
|
179
180
|
type ExportedCookie = z.infer<typeof ExportedCookieSchema>;
|
|
181
|
+
/**
|
|
182
|
+
* Schema for raw cookie data from browser stores
|
|
183
|
+
*/
|
|
184
|
+
declare const CookieRowSchema: z.ZodObject<{
|
|
185
|
+
expiry: z.ZodOptional<z.ZodNumber>;
|
|
186
|
+
domain: z.ZodEffects<z.ZodString, string, string>;
|
|
187
|
+
name: z.ZodEffects<z.ZodString, string, string>;
|
|
188
|
+
value: z.ZodUnion<[z.ZodString, z.ZodType<Buffer<ArrayBufferLike>, z.ZodTypeDef, Buffer<ArrayBufferLike>>]>;
|
|
189
|
+
}, "strict", z.ZodTypeAny, {
|
|
190
|
+
value: string | Buffer<ArrayBufferLike>;
|
|
191
|
+
name: string;
|
|
192
|
+
domain: string;
|
|
193
|
+
expiry?: number | undefined;
|
|
194
|
+
}, {
|
|
195
|
+
value: string | Buffer<ArrayBufferLike>;
|
|
196
|
+
name: string;
|
|
197
|
+
domain: string;
|
|
198
|
+
expiry?: number | undefined;
|
|
199
|
+
}>;
|
|
200
|
+
/**
|
|
201
|
+
* Type definition for raw cookie data
|
|
202
|
+
*/
|
|
203
|
+
type CookieRow = z.infer<typeof CookieRowSchema>;
|
|
180
204
|
/**
|
|
181
205
|
* Schema for cookie render options
|
|
182
206
|
*/
|
|
@@ -251,8 +275,8 @@ declare const CookieQueryStrategySchema: z.ZodObject<{
|
|
|
251
275
|
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
252
276
|
}, z.ZodUnknown, "strict"> | undefined;
|
|
253
277
|
}, {
|
|
254
|
-
name: string;
|
|
255
278
|
value: string;
|
|
279
|
+
name: string;
|
|
256
280
|
domain: string;
|
|
257
281
|
expiry?: number | Date | "Infinity" | undefined;
|
|
258
282
|
meta?: z.objectInputType<{
|
|
@@ -283,8 +307,8 @@ declare const CookieQueryStrategySchema: z.ZodObject<{
|
|
|
283
307
|
}, {
|
|
284
308
|
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
285
309
|
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, args_3: boolean | undefined, ...args: unknown[]) => Promise<{
|
|
286
|
-
name: string;
|
|
287
310
|
value: string;
|
|
311
|
+
name: string;
|
|
288
312
|
domain: string;
|
|
289
313
|
expiry?: number | Date | "Infinity" | undefined;
|
|
290
314
|
meta?: z.objectInputType<{
|
|
@@ -322,31 +346,73 @@ type CookieQueryStrategy = z.infer<typeof CookieQueryStrategySchema>;
|
|
|
322
346
|
type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
323
347
|
|
|
324
348
|
/**
|
|
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
|
|
349
|
+
* A composite strategy that combines multiple cookie query strategies.
|
|
350
|
+
* This class implements the CookieQueryStrategy interface and allows querying cookies
|
|
351
|
+
* from multiple browser-specific strategies simultaneously.
|
|
333
352
|
* @example
|
|
334
353
|
* ```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", ... }]
|
|
354
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
355
|
+
* new ChromeCookieQueryStrategy(),
|
|
356
|
+
* new FirefoxCookieQueryStrategy(),
|
|
357
|
+
* new SafariCookieQueryStrategy()
|
|
358
|
+
* ]);
|
|
359
|
+
* const cookies = await strategy.queryCookies('sessionId', 'example.com');
|
|
347
360
|
* ```
|
|
348
361
|
*/
|
|
349
|
-
declare
|
|
362
|
+
declare class CompositeCookieQueryStrategy implements CookieQueryStrategy {
|
|
363
|
+
private readonly strategies;
|
|
364
|
+
private readonly logger;
|
|
365
|
+
/**
|
|
366
|
+
* The browser name identifier for this strategy
|
|
367
|
+
* @remarks Always returns 'internal' as this is a composite strategy
|
|
368
|
+
*/
|
|
369
|
+
readonly browserName: BrowserName;
|
|
370
|
+
/**
|
|
371
|
+
* Creates a new instance of CompositeCookieQueryStrategy
|
|
372
|
+
* @param strategies - Array of browser-specific strategies to use for querying cookies
|
|
373
|
+
* @remarks
|
|
374
|
+
* - Each strategy in the array should implement the CookieQueryStrategy interface
|
|
375
|
+
* - The order of strategies determines the order of cookie querying
|
|
376
|
+
* - Failed strategies will be gracefully handled and skipped
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
380
|
+
* new ChromeCookieQueryStrategy(),
|
|
381
|
+
* new FirefoxCookieQueryStrategy()
|
|
382
|
+
* ]);
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
constructor(strategies: CookieQueryStrategy[]);
|
|
386
|
+
/**
|
|
387
|
+
* Handles strategy-specific errors and logs them appropriately
|
|
388
|
+
* @internal
|
|
389
|
+
* @param error - The error that occurred during strategy execution
|
|
390
|
+
* @param strategy - The strategy that failed
|
|
391
|
+
*/
|
|
392
|
+
private handleStrategyError;
|
|
393
|
+
/**
|
|
394
|
+
* Queries cookies using all available strategies in parallel
|
|
395
|
+
* @param name - The name pattern to match cookies against
|
|
396
|
+
* @param domain - The domain pattern to match cookies against
|
|
397
|
+
* @param store - The store pattern to match cookies against
|
|
398
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
399
|
+
* @returns Promise resolving to combined array of cookies from all strategies
|
|
400
|
+
* @remarks
|
|
401
|
+
* - Failures in individual strategies are logged but don't affect other strategies
|
|
402
|
+
* - Results are combined from all successful strategy queries
|
|
403
|
+
* - Empty arrays are returned for failed strategy queries
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const strategy = new CompositeCookieQueryStrategy([
|
|
407
|
+
* new ChromeCookieQueryStrategy(),
|
|
408
|
+
* new FirefoxCookieQueryStrategy()
|
|
409
|
+
* ]);
|
|
410
|
+
* const cookies = await strategy.queryCookies('sessionId', 'example.com');
|
|
411
|
+
* console.log(cookies); // Combined results from all browsers
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
queryCookies(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
415
|
+
}
|
|
350
416
|
|
|
351
417
|
/**
|
|
352
418
|
* Base class for cookie query strategies.
|
|
@@ -390,38 +456,129 @@ declare abstract class BaseCookieQueryStrategy implements CookieQueryStrategy {
|
|
|
390
456
|
}
|
|
391
457
|
|
|
392
458
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
459
|
+
* Create a logger instance with a component tag
|
|
460
|
+
* @param component - The component name to tag logs with
|
|
461
|
+
* @returns A logger instance that prefixes all messages with the component tag
|
|
396
462
|
* @example
|
|
397
463
|
* ```typescript
|
|
398
|
-
* const
|
|
399
|
-
*
|
|
464
|
+
* const dbLogger = createTaggedLogger('Database');
|
|
465
|
+
* dbLogger.info('Connection established');
|
|
400
466
|
* ```
|
|
401
467
|
*/
|
|
402
|
-
declare
|
|
468
|
+
declare function createTaggedLogger(component: string): ConsolaInstance;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Interface for platform-specific browser control operations
|
|
472
|
+
* Following SOLID principles - Interface Segregation
|
|
473
|
+
*/
|
|
474
|
+
interface PlatformBrowserControl {
|
|
403
475
|
/**
|
|
404
|
-
*
|
|
476
|
+
* Check if the browser is supported on this platform
|
|
477
|
+
* @param browserName - The name of the browser to check
|
|
478
|
+
* @returns True if the browser is supported on this platform
|
|
405
479
|
*/
|
|
406
|
-
|
|
480
|
+
isBrowserSupported(browserName: BrowserName): boolean;
|
|
407
481
|
/**
|
|
408
|
-
*
|
|
409
|
-
* @param
|
|
410
|
-
* @
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
*
|
|
415
|
-
* @
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
482
|
+
* Get executable names for a browser on this platform
|
|
483
|
+
* @param browserName - The name of the browser
|
|
484
|
+
* @returns Array of executable names for the browser
|
|
485
|
+
*/
|
|
486
|
+
getBrowserExecutables(browserName: BrowserName): string[];
|
|
487
|
+
/**
|
|
488
|
+
* Launch a browser on this platform
|
|
489
|
+
* @param browserName - The name of the browser to launch
|
|
490
|
+
* @returns Promise that resolves when the browser is launched
|
|
491
|
+
* @throws {Error} When the browser is not supported or cannot be launched
|
|
492
|
+
*/
|
|
493
|
+
launchBrowser(browserName: BrowserName): Promise<void>;
|
|
494
|
+
/**
|
|
495
|
+
* Get the platform name
|
|
496
|
+
* @returns The name of the current platform
|
|
497
|
+
*/
|
|
498
|
+
getPlatformName(): string;
|
|
499
|
+
/**
|
|
500
|
+
* Check if a browser is installed
|
|
501
|
+
* @param browserName - The name of the browser to check
|
|
502
|
+
* @returns Promise that resolves to true if the browser is installed
|
|
503
|
+
*/
|
|
504
|
+
isBrowserInstalled(browserName: BrowserName): Promise<boolean>;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Result of a browser conflict handling operation
|
|
509
|
+
*/
|
|
510
|
+
interface BrowserLockResult {
|
|
511
|
+
/** Whether the conflict was resolved */
|
|
512
|
+
resolved: boolean;
|
|
513
|
+
/** Whether the browser should be relaunched */
|
|
514
|
+
shouldRelaunch: boolean;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Shared handler for browser lock/permission issues
|
|
518
|
+
* Follows DRY principle to avoid duplicating logic across browser strategies
|
|
519
|
+
* Uses Strategy pattern for platform-specific operations
|
|
520
|
+
*/
|
|
521
|
+
declare class BrowserLockHandler {
|
|
522
|
+
private readonly logger;
|
|
523
|
+
private readonly browserName;
|
|
524
|
+
private readonly platformControl;
|
|
525
|
+
/**
|
|
526
|
+
* Creates a new BrowserLockHandler instance
|
|
527
|
+
* @param logger - Tagged logger instance for this handler
|
|
528
|
+
* @param browserName - Name of the browser this handler manages
|
|
529
|
+
* @param platformControl - Optional platform control strategy (for testing)
|
|
530
|
+
*/
|
|
531
|
+
constructor(logger: ReturnType<typeof createTaggedLogger>, browserName: BrowserName, platformControl?: PlatformBrowserControl);
|
|
532
|
+
/**
|
|
533
|
+
* Handle database lock or permission errors
|
|
534
|
+
* @param error - The error to check
|
|
535
|
+
* @param file - The file that was locked/inaccessible
|
|
536
|
+
* @param processes - Running processes for this browser
|
|
537
|
+
* @param autoClose - Whether to attempt auto-closing the browser
|
|
538
|
+
* @returns Promise that resolves to lock result
|
|
421
539
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
540
|
+
handleBrowserConflict(error: unknown, file: string, processes: Array<{
|
|
541
|
+
pid: number;
|
|
542
|
+
command: string;
|
|
543
|
+
}>, autoClose?: boolean): Promise<BrowserLockResult>;
|
|
544
|
+
/**
|
|
545
|
+
* Check if an error indicates a database lock or permission issue
|
|
546
|
+
* @param error - The error to check
|
|
547
|
+
* @returns True if this is a lock-related error
|
|
548
|
+
*/
|
|
549
|
+
private isLockError;
|
|
550
|
+
/**
|
|
551
|
+
* Log detailed file handle information
|
|
552
|
+
* @param file - The file that was locked
|
|
553
|
+
* @param processes - Browser processes detected
|
|
554
|
+
*/
|
|
555
|
+
private logFileHandleInfo;
|
|
556
|
+
/**
|
|
557
|
+
* Handle process conflicts and optionally close the browser
|
|
558
|
+
* @param file - The file that was locked
|
|
559
|
+
* @param processes - Browser processes detected
|
|
560
|
+
* @param autoClose - Whether to attempt auto-closing
|
|
561
|
+
* @returns Promise that resolves to lock result
|
|
562
|
+
*/
|
|
563
|
+
private handleProcessConflict;
|
|
564
|
+
/**
|
|
565
|
+
* Handle detected browser processes
|
|
566
|
+
* @param file - The file that was locked
|
|
567
|
+
* @param processes - Browser processes detected
|
|
568
|
+
* @param autoClose - Whether to attempt auto-closing
|
|
569
|
+
* @returns Promise that resolves to lock result
|
|
570
|
+
*/
|
|
571
|
+
private handleBrowserProcesses;
|
|
572
|
+
/**
|
|
573
|
+
* Attempt to close the browser gracefully
|
|
574
|
+
* @returns Promise that resolves to lock result
|
|
575
|
+
*/
|
|
576
|
+
private attemptBrowserClose;
|
|
577
|
+
/**
|
|
578
|
+
* Relaunch browser after successful operation
|
|
579
|
+
* @returns Promise that resolves when browser is relaunched
|
|
580
|
+
*/
|
|
581
|
+
relaunchBrowser(): Promise<void>;
|
|
425
582
|
}
|
|
426
583
|
|
|
427
584
|
/**
|
|
@@ -432,31 +589,186 @@ declare class ChromeCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
432
589
|
/**
|
|
433
590
|
* Supported Chromium-based browsers
|
|
434
591
|
*/
|
|
435
|
-
declare const CHROMIUM_BASED_BROWSERS: readonly ["chrome", "chromium", "brave", "edge", "opera", "vivaldi", "whale"];
|
|
592
|
+
declare const CHROMIUM_BASED_BROWSERS: readonly ["chrome", "chromium", "brave", "edge", "arc", "opera", "opera-gx", "vivaldi", "whale"];
|
|
593
|
+
/**
|
|
594
|
+
* Type representing all supported Chromium-based browsers.
|
|
595
|
+
* This includes Chrome, Edge, Brave, Arc, Opera, and other Chromium derivatives.
|
|
596
|
+
*/
|
|
436
597
|
type ChromiumBrowser = (typeof CHROMIUM_BASED_BROWSERS)[number];
|
|
437
598
|
|
|
599
|
+
interface DecryptionContext {
|
|
600
|
+
file: string;
|
|
601
|
+
password: string | Buffer;
|
|
602
|
+
browser: string;
|
|
603
|
+
metaVersion?: number;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Base strategy for querying cookies from Chromium-based browsers.
|
|
607
|
+
* This abstract class provides shared logic for Chrome, Chromium, Brave, Edge, etc.
|
|
608
|
+
*/
|
|
609
|
+
declare abstract class BaseChromiumCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
610
|
+
protected lockHandler: BrowserLockHandler;
|
|
611
|
+
protected browserDisplayName: string;
|
|
612
|
+
protected browserType: ChromiumBrowser;
|
|
613
|
+
/**
|
|
614
|
+
* Creates a new instance of BaseChromiumCookieQueryStrategy
|
|
615
|
+
* @param strategyName - Name of the strategy for logging
|
|
616
|
+
* @param browserName - Display name of the browser
|
|
617
|
+
* @param browserType - The Chromium browser type for password retrieval
|
|
618
|
+
*/
|
|
619
|
+
constructor(strategyName: string, browserName: string, browserType?: ChromiumBrowser);
|
|
620
|
+
/**
|
|
621
|
+
* Batch query cookies for multiple specs
|
|
622
|
+
* Optimized to execute combined SQL queries per database file
|
|
623
|
+
* @param specs - Array of cookie specifications
|
|
624
|
+
* @returns Array of exported cookies
|
|
625
|
+
*/
|
|
626
|
+
batchQueryCookies(specs: CookieSpec[]): Promise<ExportedCookie[]>;
|
|
627
|
+
/**
|
|
628
|
+
* Process a batch of specs for a single cookie file
|
|
629
|
+
* @param file - Cookie file path
|
|
630
|
+
* @param specs - Array of cookie specifications
|
|
631
|
+
* @param password - Decryption password
|
|
632
|
+
* @returns Array of exported cookies
|
|
633
|
+
*/
|
|
634
|
+
protected processBatchFile(file: string, specs: CookieSpec[], password: string | Buffer): Promise<ExportedCookie[]>;
|
|
635
|
+
/**
|
|
636
|
+
* Get cookie file paths for the browser
|
|
637
|
+
* @param store - Optional specific store path
|
|
638
|
+
* @returns Array of cookie file paths
|
|
639
|
+
*/
|
|
640
|
+
protected abstract getCookieFilePaths(store?: string): string[];
|
|
641
|
+
/**
|
|
642
|
+
* Get the browser-specific display name
|
|
643
|
+
* @returns Browser display name
|
|
644
|
+
*/
|
|
645
|
+
protected getBrowserName(): string;
|
|
646
|
+
/**
|
|
647
|
+
* Executes the Chromium-specific query logic
|
|
648
|
+
* @param name - The name pattern to match cookies against
|
|
649
|
+
* @param domain - The domain pattern to match cookies against
|
|
650
|
+
* @param store - Optional path to a specific cookie store file
|
|
651
|
+
* @param force - Whether to force operations despite warnings
|
|
652
|
+
* @returns A promise that resolves to an array of exported cookies
|
|
653
|
+
*/
|
|
654
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
655
|
+
/**
|
|
656
|
+
* Check if the current platform is supported
|
|
657
|
+
* @returns True if platform is supported
|
|
658
|
+
*/
|
|
659
|
+
protected isPlatformSupported(): boolean;
|
|
660
|
+
/**
|
|
661
|
+
* Get cookie files to process
|
|
662
|
+
* @param store - Optional specific store path
|
|
663
|
+
* @returns Array of file paths
|
|
664
|
+
*/
|
|
665
|
+
protected getCookieFiles(store?: string): string[];
|
|
666
|
+
/**
|
|
667
|
+
* Convert error to string message
|
|
668
|
+
* @param error - The error to convert
|
|
669
|
+
* @returns Error message string
|
|
670
|
+
*/
|
|
671
|
+
protected getErrorMessage(error: unknown): string;
|
|
672
|
+
/**
|
|
673
|
+
* Process a file with retry logic for lock conflicts
|
|
674
|
+
* @param file - Cookie file path
|
|
675
|
+
* @param name - Cookie name pattern
|
|
676
|
+
* @param domain - Domain pattern
|
|
677
|
+
* @param password - Decryption password
|
|
678
|
+
* @param force - Force processing
|
|
679
|
+
* @returns Array of exported cookies
|
|
680
|
+
*/
|
|
681
|
+
private processFileWithRetry;
|
|
682
|
+
/**
|
|
683
|
+
* Handle file processing errors
|
|
684
|
+
* @param error - The error that occurred
|
|
685
|
+
* @param file - File path
|
|
686
|
+
* @param name - Cookie name pattern
|
|
687
|
+
* @param domain - Domain pattern
|
|
688
|
+
* @param force - Whether to force operations
|
|
689
|
+
* @returns Lock result indicating if resolved and should relaunch
|
|
690
|
+
*/
|
|
691
|
+
private handleFileError;
|
|
692
|
+
/**
|
|
693
|
+
* Retry after browser close
|
|
694
|
+
* @param file - Cookie file path
|
|
695
|
+
* @param name - Cookie name pattern
|
|
696
|
+
* @param domain - Domain pattern
|
|
697
|
+
* @param password - Decryption password
|
|
698
|
+
* @param shouldRelaunch - Whether to relaunch browser
|
|
699
|
+
* @returns Array of exported cookies
|
|
700
|
+
*/
|
|
701
|
+
private retryAfterBrowserClose;
|
|
702
|
+
/**
|
|
703
|
+
* Process a single cookie file
|
|
704
|
+
* @param file - Cookie file path
|
|
705
|
+
* @param name - Cookie name pattern
|
|
706
|
+
* @param domain - Domain pattern
|
|
707
|
+
* @param password - Decryption password
|
|
708
|
+
* @returns Array of exported cookies
|
|
709
|
+
*/
|
|
710
|
+
protected processFile(file: string, name: string, domain: string, password: string | Buffer): Promise<ExportedCookie[]>;
|
|
711
|
+
/**
|
|
712
|
+
* Get meta version from Chrome database
|
|
713
|
+
* @param file - Database file path
|
|
714
|
+
* @returns Meta version number
|
|
715
|
+
*/
|
|
716
|
+
protected getMetaVersion(file: string): Promise<number>;
|
|
717
|
+
/**
|
|
718
|
+
* Process a single cookie
|
|
719
|
+
* @param cookie - Cookie row from database
|
|
720
|
+
* @param context - Decryption context
|
|
721
|
+
* @returns Exported cookie
|
|
722
|
+
*/
|
|
723
|
+
protected processCookie(cookie: CookieRow, context: DecryptionContext): Promise<ExportedCookie>;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Strategy for querying cookies from Chrome browser.
|
|
728
|
+
* This class extends the BaseChromiumCookieQueryStrategy with Chrome-specific logic.
|
|
729
|
+
* @example
|
|
730
|
+
* ```typescript
|
|
731
|
+
* const strategy = new ChromeCookieQueryStrategy();
|
|
732
|
+
* const cookies = await strategy.queryCookies('session', 'example.com');
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
declare class ChromeCookieQueryStrategy extends BaseChromiumCookieQueryStrategy {
|
|
736
|
+
private readonly profileName?;
|
|
737
|
+
/**
|
|
738
|
+
* Creates a new instance of ChromeCookieQueryStrategy
|
|
739
|
+
* @param profileName - Optional specific profile name to target
|
|
740
|
+
*/
|
|
741
|
+
constructor(profileName?: string);
|
|
742
|
+
/**
|
|
743
|
+
* Get Chrome-specific cookie file paths
|
|
744
|
+
* @param store - Optional specific store path
|
|
745
|
+
* @returns Array of cookie file paths
|
|
746
|
+
*/
|
|
747
|
+
protected getCookieFilePaths(store?: string): string[];
|
|
748
|
+
}
|
|
749
|
+
|
|
438
750
|
/**
|
|
439
751
|
* Strategy for querying cookies from Chromium-based browsers (Chrome, Brave, Edge, etc.)
|
|
440
|
-
* This class extends the
|
|
441
|
-
*
|
|
752
|
+
* This class extends the BaseChromiumCookieQueryStrategy with browser-specific path discovery.
|
|
753
|
+
* @example
|
|
754
|
+
* ```typescript
|
|
755
|
+
* const strategy = new ChromiumCookieQueryStrategy('brave');
|
|
756
|
+
* const cookies = await strategy.queryCookies('session', 'example.com');
|
|
757
|
+
* ```
|
|
442
758
|
*/
|
|
443
|
-
declare class ChromiumCookieQueryStrategy extends
|
|
444
|
-
private browser;
|
|
759
|
+
declare class ChromiumCookieQueryStrategy extends BaseChromiumCookieQueryStrategy {
|
|
760
|
+
private readonly browser;
|
|
445
761
|
/**
|
|
446
762
|
* Creates a new instance of ChromiumCookieQueryStrategy
|
|
447
763
|
* @param browser - The Chromium-based browser to query (chrome, brave, edge, etc.)
|
|
448
764
|
*/
|
|
449
765
|
constructor(browser?: ChromiumBrowser);
|
|
450
766
|
/**
|
|
451
|
-
*
|
|
767
|
+
* Get browser-specific cookie file paths
|
|
768
|
+
* @param store - Optional specific store path
|
|
769
|
+
* @returns Array of cookie file paths
|
|
452
770
|
*/
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Executes the Chromium-specific query logic
|
|
456
|
-
*/
|
|
457
|
-
protected executeQuery(name: string, domain: string, store?: string, _force?: boolean): Promise<ExportedCookie[]>;
|
|
458
|
-
private processFile;
|
|
459
|
-
private processCookie;
|
|
771
|
+
protected getCookieFilePaths(store?: string): string[];
|
|
460
772
|
}
|
|
461
773
|
|
|
462
774
|
/**
|
|
@@ -474,28 +786,79 @@ declare class ChromiumCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
474
786
|
* ```
|
|
475
787
|
*/
|
|
476
788
|
declare class FirefoxCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
789
|
+
private readonly lockHandler;
|
|
477
790
|
/**
|
|
478
791
|
* Creates a new instance of FirefoxCookieQueryStrategy
|
|
479
792
|
*/
|
|
480
793
|
constructor();
|
|
481
794
|
/**
|
|
482
|
-
*
|
|
483
|
-
* @param
|
|
484
|
-
* @param
|
|
485
|
-
* @
|
|
795
|
+
* Creates the query parameters for cookie extraction using the new query builder
|
|
796
|
+
* @param name - The cookie name to search for
|
|
797
|
+
* @param domain - The domain pattern to match cookies against
|
|
798
|
+
* @param file - The database file path for metadata
|
|
799
|
+
* @returns Query configuration object
|
|
800
|
+
* @private
|
|
801
|
+
*/
|
|
802
|
+
private createCookieQueryConfig;
|
|
803
|
+
/**
|
|
804
|
+
* Handles errors that occur during cookie extraction
|
|
805
|
+
* @param error - The error that occurred
|
|
806
|
+
* @param file - The database file being queried
|
|
807
|
+
* @param force - Whether operations are being forced
|
|
808
|
+
* @param name - The cookie name being searched
|
|
809
|
+
* @param domain - The domain being searched
|
|
810
|
+
* @returns Promise resolving to retry configuration
|
|
811
|
+
* @private
|
|
812
|
+
*/
|
|
813
|
+
private handleCookieExtractionError;
|
|
814
|
+
/**
|
|
815
|
+
* Logs cookie extraction errors in a consistent format
|
|
816
|
+
* @param error - The error to log
|
|
817
|
+
* @param file - The file that failed
|
|
818
|
+
* @param name - The cookie name
|
|
819
|
+
* @param domain - The domain
|
|
820
|
+
* @private
|
|
821
|
+
*/
|
|
822
|
+
private logExtractError;
|
|
823
|
+
/**
|
|
824
|
+
* Performs a retry attempt after browser closure
|
|
825
|
+
* @param queryConfig - The cookie query configuration
|
|
826
|
+
* @param shouldRelaunch - Whether to relaunch the browser after success
|
|
827
|
+
* @returns Promise resolving to extracted cookies
|
|
828
|
+
* @private
|
|
829
|
+
*/
|
|
830
|
+
private performRetryAfterClose;
|
|
831
|
+
/**
|
|
832
|
+
* Processes a single Firefox cookie file for the given parameters
|
|
833
|
+
* @param file - The cookie file to process
|
|
834
|
+
* @param name - The cookie name to search for
|
|
835
|
+
* @param domain - The domain pattern to match
|
|
836
|
+
* @param force - Whether to force operations despite warnings
|
|
837
|
+
* @returns Promise resolving to extracted cookies from this file
|
|
838
|
+
* @private
|
|
839
|
+
*/
|
|
840
|
+
private processCookieFile;
|
|
841
|
+
/**
|
|
842
|
+
* Execute query using the new SQL utilities
|
|
843
|
+
* @param queryConfig - Query configuration from createCookieQueryConfig
|
|
844
|
+
* @param queryConfig.file
|
|
845
|
+
* @param queryConfig.sql
|
|
846
|
+
* @param queryConfig.params
|
|
847
|
+
* @param queryConfig.rowTransform
|
|
848
|
+
* @returns Promise resolving to exported cookies
|
|
486
849
|
* @private
|
|
487
850
|
*/
|
|
488
|
-
private
|
|
851
|
+
private executeQueryWithNewUtilities;
|
|
489
852
|
/**
|
|
490
853
|
* Executes the Firefox-specific query logic
|
|
491
854
|
* @param name - The name pattern to match cookies against
|
|
492
855
|
* @param domain - The domain pattern to match cookies against
|
|
493
856
|
* @param store - Optional path to a specific cookie store file
|
|
494
|
-
* @param
|
|
857
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
495
858
|
* @returns A promise that resolves to an array of exported cookies
|
|
496
859
|
* @protected
|
|
497
860
|
*/
|
|
498
|
-
protected executeQuery(name: string, domain: string, store?: string,
|
|
861
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
499
862
|
}
|
|
500
863
|
|
|
501
864
|
/**
|
|
@@ -504,6 +867,7 @@ declare class FirefoxCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
504
867
|
* cookie extraction logic.
|
|
505
868
|
*/
|
|
506
869
|
declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
870
|
+
private readonly lockHandler;
|
|
507
871
|
/**
|
|
508
872
|
* Creates a new instance of SafariCookieQueryStrategy
|
|
509
873
|
*/
|
|
@@ -517,7 +881,7 @@ declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
517
881
|
/**
|
|
518
882
|
* Formats the domain by removing leading dot if present
|
|
519
883
|
* @param domain - Domain to format
|
|
520
|
-
* @returns Formatted domain
|
|
884
|
+
* @returns Formatted domain or empty string if domain is invalid
|
|
521
885
|
*/
|
|
522
886
|
private formatDomain;
|
|
523
887
|
/**
|
|
@@ -550,88 +914,245 @@ declare class SafariCookieQueryStrategy extends BaseCookieQueryStrategy {
|
|
|
550
914
|
* @param cookieDbPath - Path to the cookie database
|
|
551
915
|
* @param name - Name of the cookie to find
|
|
552
916
|
* @param domain - Domain to filter cookies by
|
|
917
|
+
* @param force - Whether to skip interactive prompts
|
|
553
918
|
* @returns Array of exported cookies
|
|
554
919
|
*/
|
|
555
920
|
private decodeCookies;
|
|
921
|
+
/**
|
|
922
|
+
* Check file permissions and handle permission errors
|
|
923
|
+
* @param cookieDbPath - Path to the cookie database
|
|
924
|
+
* @param force - Whether to skip interactive prompts
|
|
925
|
+
* @returns True if permissions are granted, false otherwise
|
|
926
|
+
*/
|
|
927
|
+
private checkAndHandlePermissions;
|
|
928
|
+
/**
|
|
929
|
+
* Process and filter cookies based on name and domain criteria
|
|
930
|
+
* @param cookies - Raw cookies from binary file
|
|
931
|
+
* @param name - Name filter
|
|
932
|
+
* @param domain - Domain filter
|
|
933
|
+
* @param cookieDbPath - Path to cookie database for metadata
|
|
934
|
+
* @returns Processed and filtered cookies
|
|
935
|
+
*/
|
|
936
|
+
private processCookies;
|
|
937
|
+
/**
|
|
938
|
+
* Check if cookie matches the search criteria
|
|
939
|
+
* @param cookie - Raw cookie object
|
|
940
|
+
* @param name - Name filter
|
|
941
|
+
* @param domain - Domain filter
|
|
942
|
+
* @returns True if cookie matches criteria
|
|
943
|
+
*/
|
|
944
|
+
private matchesCriteria;
|
|
945
|
+
/**
|
|
946
|
+
* Type guard to check if an object is a valid cookie object
|
|
947
|
+
* @param cookie - Object to check
|
|
948
|
+
* @returns True if object has expected cookie properties
|
|
949
|
+
*/
|
|
950
|
+
private isCookieObject;
|
|
951
|
+
/**
|
|
952
|
+
* Map raw cookie to ExportedCookie format
|
|
953
|
+
* @param cookie - Raw cookie object
|
|
954
|
+
* @param cookieDbPath - Path to cookie database for metadata
|
|
955
|
+
* @returns Formatted ExportedCookie
|
|
956
|
+
*/
|
|
957
|
+
private mapToExportedCookie;
|
|
958
|
+
/**
|
|
959
|
+
* Handle errors that occur during cookie decoding
|
|
960
|
+
* @param error - The error that occurred
|
|
961
|
+
* @param cookieDbPath - Path to the cookie database
|
|
962
|
+
* @param name - Name filter used
|
|
963
|
+
* @param domain - Domain filter used
|
|
964
|
+
* @param force - Whether interactive prompts were skipped
|
|
965
|
+
* @returns Empty array as fallback
|
|
966
|
+
*/
|
|
967
|
+
private handleDecodingError;
|
|
968
|
+
/**
|
|
969
|
+
* Handle permission-related errors
|
|
970
|
+
* @param error - The error that occurred
|
|
971
|
+
* @param cookieDbPath - Path to the cookie database
|
|
972
|
+
* @param name - Name filter used
|
|
973
|
+
* @param domain - Domain filter used
|
|
974
|
+
* @param force - Whether interactive prompts were skipped
|
|
975
|
+
*/
|
|
976
|
+
private handlePermissionError;
|
|
977
|
+
/**
|
|
978
|
+
* Log non-permission errors that occur during decoding
|
|
979
|
+
* @param error - The error that occurred
|
|
980
|
+
* @param cookieDbPath - Path to the cookie database
|
|
981
|
+
* @param name - Name filter used
|
|
982
|
+
* @param domain - Domain filter used
|
|
983
|
+
*/
|
|
984
|
+
private logDecodingError;
|
|
556
985
|
/**
|
|
557
986
|
* Executes the Safari-specific query logic
|
|
558
987
|
* @param name - Name of the cookie to find
|
|
559
988
|
* @param domain - Domain to filter cookies by
|
|
560
989
|
* @param store - Optional store path
|
|
561
|
-
* @param
|
|
990
|
+
* @param force - Whether to force operations despite warnings (e.g., locked databases)
|
|
562
991
|
* @returns Array of matching cookies, or empty array if none found
|
|
563
992
|
* @protected
|
|
564
993
|
*/
|
|
565
|
-
protected executeQuery(name: string, domain: string, store?: string,
|
|
994
|
+
protected executeQuery(name: string, domain: string, store?: string, force?: boolean): Promise<ExportedCookie[]>;
|
|
995
|
+
/**
|
|
996
|
+
* Validate home directory
|
|
997
|
+
* @param home - Home directory path
|
|
998
|
+
* @returns True if valid, false otherwise
|
|
999
|
+
*/
|
|
1000
|
+
private isValidHomeDirectory;
|
|
1001
|
+
/**
|
|
1002
|
+
* Attempt to decode cookies with lock conflict handling
|
|
1003
|
+
* @param cookieDbPath - Path to cookie database
|
|
1004
|
+
* @param name - Normalized cookie name filter
|
|
1005
|
+
* @param domain - Normalized domain filter
|
|
1006
|
+
* @param force - Whether to force operations
|
|
1007
|
+
* @returns Result object with success status and data
|
|
1008
|
+
*/
|
|
1009
|
+
private attemptDecodeWithLockHandling;
|
|
1010
|
+
/**
|
|
1011
|
+
* Handle browser lock conflicts
|
|
1012
|
+
* @param error - The error that occurred
|
|
1013
|
+
* @param cookieDbPath - Path to cookie database
|
|
1014
|
+
* @param force - Whether to force operations
|
|
1015
|
+
* @returns Result indicating what action to take next
|
|
1016
|
+
*/
|
|
1017
|
+
private handleLockConflict;
|
|
1018
|
+
/**
|
|
1019
|
+
* Check if error indicates a lock conflict
|
|
1020
|
+
* @param error - Error to check
|
|
1021
|
+
* @returns True if this is a lock-related error
|
|
1022
|
+
*/
|
|
1023
|
+
private isLockError;
|
|
1024
|
+
/**
|
|
1025
|
+
* Retry cookie extraction after browser was closed
|
|
1026
|
+
* @param cookieDbPath - Path to cookie database
|
|
1027
|
+
* @param name - Cookie name filter
|
|
1028
|
+
* @param domain - Domain filter
|
|
1029
|
+
* @param force - Whether to force operations
|
|
1030
|
+
* @param shouldRelaunch - Whether browser should be relaunched
|
|
1031
|
+
* @returns Cookies or empty array
|
|
1032
|
+
*/
|
|
1033
|
+
private retryAfterBrowserClose;
|
|
1034
|
+
/**
|
|
1035
|
+
* Handle failure during retry attempt
|
|
1036
|
+
* @param retryError - Error that occurred during retry
|
|
1037
|
+
* @param cookieDbPath - Path to cookie database
|
|
1038
|
+
* @param shouldRelaunch - Whether browser should be relaunched
|
|
1039
|
+
* @returns Empty array
|
|
1040
|
+
*/
|
|
1041
|
+
private handleRetryFailure;
|
|
1042
|
+
/**
|
|
1043
|
+
* Log query errors
|
|
1044
|
+
* @param error - The error that occurred
|
|
1045
|
+
* @param name - Cookie name filter
|
|
1046
|
+
* @param domain - Domain filter
|
|
1047
|
+
*/
|
|
1048
|
+
private logQueryError;
|
|
566
1049
|
}
|
|
567
1050
|
|
|
568
1051
|
/**
|
|
569
|
-
*
|
|
570
|
-
* This
|
|
571
|
-
*
|
|
1052
|
+
* Retrieves browser cookies that match the specified cookie name and domain criteria.
|
|
1053
|
+
* This function provides a way to search and filter cookies based on given specifications.
|
|
1054
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
1055
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
1056
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
1057
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
1058
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
1059
|
+
* to the console without throwing to the caller
|
|
572
1060
|
* @example
|
|
573
1061
|
* ```typescript
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* ]
|
|
579
|
-
*
|
|
1062
|
+
* import { getCookie } from "@mherod/get-cookie";
|
|
1063
|
+
*
|
|
1064
|
+
* // Get all cookies named "sessionId"
|
|
1065
|
+
* const cookies = await getCookie({ name: "sessionId" });
|
|
1066
|
+
* // Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
|
|
1067
|
+
*
|
|
1068
|
+
* // Get cookies named "userPref" from specific domain
|
|
1069
|
+
* const domainCookies = await getCookie({
|
|
1070
|
+
* name: "userPref",
|
|
1071
|
+
* domain: "example.com"
|
|
1072
|
+
* });
|
|
1073
|
+
* // Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]
|
|
580
1074
|
* ```
|
|
581
1075
|
*/
|
|
582
|
-
declare
|
|
583
|
-
|
|
584
|
-
|
|
1076
|
+
declare function getCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Options for batch cookie retrieval
|
|
1080
|
+
*/
|
|
1081
|
+
interface BatchGetCookiesOptions {
|
|
585
1082
|
/**
|
|
586
|
-
*
|
|
587
|
-
*
|
|
1083
|
+
* Whether to deduplicate cookies across all specs
|
|
1084
|
+
* When true, keeps the cookie with the longest value for each unique name+domain combination
|
|
1085
|
+
* @default true
|
|
588
1086
|
*/
|
|
589
|
-
|
|
1087
|
+
deduplicate?: boolean;
|
|
590
1088
|
/**
|
|
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
|
-
* ```
|
|
1089
|
+
* Maximum number of concurrent requests
|
|
1090
|
+
* @default 10
|
|
604
1091
|
*/
|
|
605
|
-
|
|
1092
|
+
concurrency?: number;
|
|
606
1093
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* @
|
|
610
|
-
* @param strategy - The strategy that failed
|
|
1094
|
+
* Whether to continue on errors for individual specs
|
|
1095
|
+
* When true, errors for individual specs won't fail the entire batch
|
|
1096
|
+
* @default true
|
|
611
1097
|
*/
|
|
612
|
-
|
|
1098
|
+
continueOnError?: boolean;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Result for a single cookie spec in batch operation
|
|
1102
|
+
*/
|
|
1103
|
+
interface BatchCookieResult {
|
|
613
1104
|
/**
|
|
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
|
-
* ```
|
|
1105
|
+
* The original spec that was queried
|
|
633
1106
|
*/
|
|
634
|
-
|
|
1107
|
+
spec: CookieSpec;
|
|
1108
|
+
/**
|
|
1109
|
+
* The cookies retrieved for this spec
|
|
1110
|
+
*/
|
|
1111
|
+
cookies: ExportedCookie[];
|
|
1112
|
+
/**
|
|
1113
|
+
* Error if the query failed (only when continueOnError is true)
|
|
1114
|
+
*/
|
|
1115
|
+
error?: Error;
|
|
635
1116
|
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Retrieves multiple cookie specifications in parallel with intelligent deduplication.
|
|
1119
|
+
* This function efficiently fetches cookies for multiple specifications and can optionally
|
|
1120
|
+
* deduplicate the results to keep only the most valid cookie for each unique name+domain pair.
|
|
1121
|
+
* @param specs - Array of cookie specifications to retrieve
|
|
1122
|
+
* @param options - Options for batch retrieval
|
|
1123
|
+
* @returns Array of exported cookies, optionally deduplicated
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```typescript
|
|
1126
|
+
* import { batchGetCookies } from "@mherod/get-cookie";
|
|
1127
|
+
*
|
|
1128
|
+
* // Fetch multiple cookies in parallel
|
|
1129
|
+
* const cookies = await batchGetCookies([
|
|
1130
|
+
* { name: "auth", domain: "api.example.com" },
|
|
1131
|
+
* { name: "session", domain: "example.com" },
|
|
1132
|
+
* { name: "token", domain: "*.example.com" }
|
|
1133
|
+
* ]);
|
|
1134
|
+
*
|
|
1135
|
+
* // With options
|
|
1136
|
+
* const cookies = await batchGetCookies(
|
|
1137
|
+
* [
|
|
1138
|
+
* { name: "auth", domain: "api.example.com" },
|
|
1139
|
+
* { name: "session", domain: "example.com" }
|
|
1140
|
+
* ],
|
|
1141
|
+
* {
|
|
1142
|
+
* deduplicate: true, // Keep only the best cookie for each name+domain
|
|
1143
|
+
* concurrency: 5, // Limit concurrent requests
|
|
1144
|
+
* continueOnError: true // Don't fail entire batch on individual errors
|
|
1145
|
+
* }
|
|
1146
|
+
* );
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
declare function batchGetCookies(specs: CookieSpec[], options?: BatchGetCookiesOptions): Promise<ExportedCookie[]>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Retrieves multiple cookie specifications with detailed results for each spec
|
|
1152
|
+
* @param specs - Array of cookie specifications to retrieve
|
|
1153
|
+
* @param options - Options for batch retrieval
|
|
1154
|
+
* @returns Array of batch results with cookies and potential errors
|
|
1155
|
+
*/
|
|
1156
|
+
declare function batchGetCookiesWithResults(specs: CookieSpec[], options?: Omit<BatchGetCookiesOptions, "deduplicate">): Promise<BatchCookieResult[]>;
|
|
636
1157
|
|
|
637
|
-
export { type BrowserName, ChromeCookieQueryStrategy, ChromiumCookieQueryStrategy, CompositeCookieQueryStrategy, type CookieQueryStrategy, type CookieSpec, type ExportedCookie, FirefoxCookieQueryStrategy, type MultiCookieSpec, type RenderOptions, SafariCookieQueryStrategy, getCookie };
|
|
1158
|
+
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 };
|