@mherod/get-cookie 2.1.2 → 2.1.3

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/dist/index.js CHANGED
@@ -5640,19 +5640,6 @@ var require_minimist = __commonJS((exports, module) => {
5640
5640
  };
5641
5641
  });
5642
5642
 
5643
- // src/argv.ts
5644
- var import_minimist, import_lodash, argv, minimistArgs, defaultOptions, parsedArgs;
5645
- var init_argv = __esm(() => {
5646
- import_minimist = __toESM(require_minimist(), 1);
5647
- import_lodash = __toESM(require_lodash(), 1);
5648
- argv = process.argv ?? [];
5649
- minimistArgs = import_minimist.default(argv.slice(2));
5650
- defaultOptions = {
5651
- verbose: false
5652
- };
5653
- parsedArgs = import_lodash.merge(defaultOptions, minimistArgs);
5654
- });
5655
-
5656
5643
  // node_modules/consola/dist/core.mjs
5657
5644
  class Consola {
5658
5645
  constructor(options = {}) {
@@ -7417,174 +7404,6 @@ var init_consola_36c0034f = __esm(() => {
7417
7404
  consola = createConsola2();
7418
7405
  });
7419
7406
 
7420
- // node_modules/consola/dist/index.mjs
7421
- var init_dist = __esm(() => {
7422
- init_consola_36c0034f();
7423
- init_core();
7424
- init_consola_06ad8a64();
7425
- init_utils();
7426
- });
7427
-
7428
- // src/logger.ts
7429
- var consola2, logger_default;
7430
- var init_logger = __esm(() => {
7431
- init_dist();
7432
- consola2 = createConsola2({
7433
- fancy: true,
7434
- formatOptions: {
7435
- showLogLevel: true,
7436
- colors: true,
7437
- date: false
7438
- }
7439
- });
7440
- logger_default = consola2;
7441
- });
7442
-
7443
- // src/CookieRow.ts
7444
- function isCookieRow(obj) {
7445
- if (typeof obj !== "object" || obj === null) {
7446
- logger_default.warn("Object is not an object or is null:", obj);
7447
- return false;
7448
- }
7449
- const { domain, name, value } = obj;
7450
- if (typeof domain !== "string") {
7451
- logger_default.warn("Domain is not a string:", domain);
7452
- return false;
7453
- }
7454
- if (typeof name !== "string") {
7455
- logger_default.warn("Name is not a string:", name);
7456
- return false;
7457
- }
7458
- if (!(value instanceof Uint8Array) && !Buffer.isBuffer(value)) {
7459
- logger_default.warn("Value is not a Uint8Array or Buffer:", value);
7460
- return false;
7461
- }
7462
- return true;
7463
- }
7464
- var init_CookieRow = __esm(() => {
7465
- init_logger();
7466
- });
7467
-
7468
- // src/global.ts
7469
- var import_lodash2, env2, HOME;
7470
- var init_global = __esm(() => {
7471
- import_lodash2 = __toESM(require_lodash(), 1);
7472
- env2 = {};
7473
- import_lodash2.merge(env2, process?.env ?? {});
7474
- HOME = env2["HOME"];
7475
- if (!HOME) {
7476
- throw new Error("HOME environment variable is not set");
7477
- }
7478
- });
7479
-
7480
- // src/browsers/chrome/ChromeApplicationSupport.ts
7481
- import {join} from "path";
7482
- var chromeApplicationSupport;
7483
- var init_ChromeApplicationSupport = __esm(() => {
7484
- init_global();
7485
- if (HOME === undefined) {
7486
- throw new Error("HOME environment variable is not defined");
7487
- }
7488
- chromeApplicationSupport = join(HOME, "Library", "Application Support", "Google", "Chrome");
7489
- });
7490
-
7491
- // src/browsers/chrome/decrypt.ts
7492
- import {createDecipheriv, pbkdf2} from "crypto";
7493
- async function decrypt(password, encryptedData) {
7494
- return decryptor.decrypt(password, encryptedData);
7495
- }
7496
-
7497
- class BufferDecryptor {
7498
- async decrypt(password, encryptedData) {
7499
- this.validatePassword(password);
7500
- const preparedData = this.validateAndPrepareEncryptedData(encryptedData);
7501
- if (parsedArgs.verbose) {
7502
- logger_default.start(`Trying to decrypt with password: ${password}`);
7503
- }
7504
- const decryptedData = await this.performDecryption(password, preparedData);
7505
- if (parsedArgs.verbose) {
7506
- logger_default.success(`Decryption successful: ${decryptedData}`);
7507
- }
7508
- return decryptedData;
7509
- }
7510
- validatePassword(password) {
7511
- if (typeof password !== "string") {
7512
- throw new Error("password must be a string: " + password);
7513
- }
7514
- }
7515
- validateAndPrepareEncryptedData(encryptedData) {
7516
- if (encryptedData == null || !(encryptedData instanceof Buffer || Array.isArray(encryptedData) && Buffer.isBuffer(encryptedData[0]))) {
7517
- throw new Error("encryptedData must be a Buffer or an array of Buffers: " + encryptedData);
7518
- }
7519
- if (Array.isArray(encryptedData) && Buffer.isBuffer(encryptedData[0])) {
7520
- encryptedData = encryptedData[0];
7521
- if (parsedArgs.verbose) {
7522
- logger_default.info(`encryptedData is an array of buffers, selected first: ${encryptedData}`);
7523
- }
7524
- }
7525
- return Buffer.from(encryptedData);
7526
- }
7527
- performDecryption(password, encryptedData) {
7528
- return new Promise((resolve, reject) => {
7529
- this.deriveKey(password).then((key) => this.decryptData(key, encryptedData)).then((decrypted) => resolve(decrypted)).catch((error) => reject(error));
7530
- });
7531
- }
7532
- deriveKey(password) {
7533
- return new Promise((resolve, reject) => {
7534
- pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer) => {
7535
- if (error) {
7536
- this.logError("Error doing pbkdf2", error);
7537
- reject(error);
7538
- return;
7539
- }
7540
- if (buffer.length !== 16) {
7541
- this.logError("Error doing pbkdf2, buffer length is not 16", buffer.length);
7542
- reject(new Error("Buffer length is not 16"));
7543
- return;
7544
- }
7545
- resolve(buffer);
7546
- });
7547
- });
7548
- }
7549
- decryptData(key, encryptedData) {
7550
- return new Promise((resolve, reject) => {
7551
- const iv = Buffer.from(new Array(17).join(" "), "binary");
7552
- const decipher = createDecipheriv("aes-128-cbc", key, iv);
7553
- decipher.setAutoPadding(false);
7554
- const slicedData = encryptedData.slice(3);
7555
- if (slicedData.length % 16 !== 0) {
7556
- this.logError("Error, encryptedData length is not a multiple of 16", slicedData.length);
7557
- reject(new Error("encryptedData length is not a multiple of 16"));
7558
- return;
7559
- }
7560
- let decoded = decipher.update(slicedData);
7561
- try {
7562
- decipher.final("utf-8");
7563
- } catch (e) {
7564
- this.logError("Error doing decipher.final()", e);
7565
- reject(e);
7566
- return;
7567
- }
7568
- const padding = decoded[decoded.length - 1];
7569
- if (padding) {
7570
- decoded = decoded.slice(0, 0 - padding);
7571
- }
7572
- resolve(decoded.toString("utf8"));
7573
- });
7574
- }
7575
- logError(message, error) {
7576
- if (parsedArgs.verbose) {
7577
- logger_default.error(message, error);
7578
- }
7579
- }
7580
- }
7581
- var decryptor;
7582
- var init_decrypt = __esm(() => {
7583
- init_argv();
7584
- init_logger();
7585
- decryptor = new BufferDecryptor;
7586
- });
7587
-
7588
7407
  // node_modules/fast-glob/out/utils/array.js
7589
7408
  var require_array = __commonJS((exports) => {
7590
7409
  var flatten = function(items) {
@@ -12760,638 +12579,102 @@ var require_out4 = __commonJS((exports, module) => {
12760
12579
  module.exports = FastGlob;
12761
12580
  });
12762
12581
 
12763
- // src/findAllFiles.ts
12764
- import {existsSync} from "fs";
12765
- function findAllFiles({
12766
- path,
12767
- name,
12768
- maxDepth = 2
12769
- }) {
12770
- if (!existsSync(path)) {
12771
- throw new Error(`Path ${path} does not exist`);
12772
- }
12773
- if (parsedArgs.verbose) {
12774
- consola.start(`Searching for ${name} files in ${path}`);
12775
- }
12776
- const files = import_fast_glob.sync(`${path}/**/${name}`, {
12777
- onlyFiles: true,
12778
- deep: maxDepth
12779
- });
12780
- if (parsedArgs.verbose) {
12781
- if (files.length > 0) {
12782
- consola.success(`Found ${files.length} ${name} files`);
12783
- consola.info(files);
12582
+ // node_modules/lru-cache/index.js
12583
+ var require_lru_cache = __commonJS((exports, module) => {
12584
+ var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
12585
+ var hasAbortController = typeof AbortController === "function";
12586
+ var AC = hasAbortController ? AbortController : class AbortController2 {
12587
+ constructor() {
12588
+ this.signal = new AS;
12784
12589
  }
12785
- }
12786
- return files;
12787
- }
12788
- var import_fast_glob;
12789
- var init_findAllFiles = __esm(() => {
12790
- init_argv();
12791
- init_dist();
12792
- import_fast_glob = __toESM(require_out4(), 1);
12793
- });
12590
+ abort() {
12591
+ this.signal.dispatchEvent("abort");
12592
+ }
12593
+ };
12594
+ var hasAbortSignal = typeof AbortSignal === "function";
12595
+ var hasACAbortSignal = typeof AC.AbortSignal === "function";
12596
+ var AS = hasAbortSignal ? AbortSignal : hasACAbortSignal ? AC.AbortController : class AbortSignal2 {
12597
+ constructor() {
12598
+ this.aborted = false;
12599
+ this._listeners = [];
12600
+ }
12601
+ dispatchEvent(type) {
12602
+ if (type === "abort") {
12603
+ this.aborted = true;
12604
+ const e = { type, target: this };
12605
+ this.onabort(e);
12606
+ this._listeners.forEach((f2) => f2(e), this);
12607
+ }
12608
+ }
12609
+ onabort() {
12610
+ }
12611
+ addEventListener(ev, fn) {
12612
+ if (ev === "abort") {
12613
+ this._listeners.push(fn);
12614
+ }
12615
+ }
12616
+ removeEventListener(ev, fn) {
12617
+ if (ev === "abort") {
12618
+ this._listeners = this._listeners.filter((f2) => f2 !== fn);
12619
+ }
12620
+ }
12621
+ };
12622
+ var warned = new Set;
12623
+ var deprecatedOption = (opt, instead) => {
12624
+ const code = `LRU_CACHE_OPTION_${opt}`;
12625
+ if (shouldWarn(code)) {
12626
+ warn(code, `${opt} option`, `options.${instead}`, LRUCache);
12627
+ }
12628
+ };
12629
+ var deprecatedMethod = (method, instead) => {
12630
+ const code = `LRU_CACHE_METHOD_${method}`;
12631
+ if (shouldWarn(code)) {
12632
+ const { prototype } = LRUCache;
12633
+ const { get } = Object.getOwnPropertyDescriptor(prototype, method);
12634
+ warn(code, `${method} method`, `cache.${instead}()`, get);
12635
+ }
12636
+ };
12637
+ var deprecatedProperty = (field, instead) => {
12638
+ const code = `LRU_CACHE_PROPERTY_${field}`;
12639
+ if (shouldWarn(code)) {
12640
+ const { prototype } = LRUCache;
12641
+ const { get } = Object.getOwnPropertyDescriptor(prototype, field);
12642
+ warn(code, `${field} property`, `cache.${instead}`, get);
12643
+ }
12644
+ };
12645
+ var emitWarning = (...a) => {
12646
+ typeof process === "object" && process && typeof process.emitWarning === "function" ? process.emitWarning(...a) : console.error(...a);
12647
+ };
12648
+ var shouldWarn = (code) => !warned.has(code);
12649
+ var warn = (code, what, instead, fn) => {
12650
+ warned.add(code);
12651
+ const msg = `The ${what} is deprecated. Please use ${instead} instead.`;
12652
+ emitWarning(msg, "DeprecationWarning", code, fn);
12653
+ };
12654
+ var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
12655
+ var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
12794
12656
 
12795
- // src/execSimple.ts
12796
- async function execSimple(command) {
12797
- try {
12798
- const { execSync } = await import("child_process");
12799
- const stdout2 = execSync(command, {
12800
- encoding: "binary",
12801
- maxBuffer: 5120
12802
- });
12803
- return stdout2.trim();
12804
- } catch (error) {
12805
- throw error;
12657
+ class ZeroArray extends Array {
12658
+ constructor(size) {
12659
+ super(size);
12660
+ this.fill(0);
12661
+ }
12806
12662
  }
12807
- }
12808
- var init_execSimple = __esm(() => {
12809
- });
12810
12663
 
12811
- // src/browsers/chrome/getChromePassword.ts
12812
- async function getChromePassword() {
12813
- return await passwordRetriever.retrievePassword();
12814
- }
12815
-
12816
- class MacOSPasswordRetriever {
12817
- async retrievePassword() {
12818
- return execSimple('security find-generic-password -w -s "Chrome Safe Storage"');
12819
- }
12820
- }
12821
-
12822
- class UnsupportedPlatformPasswordRetriever {
12823
- async retrievePassword() {
12824
- return Promise.reject(new Error("This only works on macOS"));
12825
- }
12826
- }
12827
- var passwordRetriever;
12828
- var init_getChromePassword = __esm(() => {
12829
- init_execSimple();
12830
- passwordRetriever = process.platform == "darwin" ? new MacOSPasswordRetriever : new UnsupportedPlatformPasswordRetriever;
12831
- });
12832
-
12833
- // src/ExportedCookie.ts
12834
- function isExportedCookie(obj) {
12835
- return typeof obj.domain === "string" && typeof obj.name === "string" && typeof obj.value === "string" && (obj.expiry === undefined || obj.expiry instanceof Date || obj.expiry === "Infinity") && (obj.meta === undefined || typeof obj.meta === "object");
12836
- }
12837
- var init_ExportedCookie = __esm(() => {
12838
- });
12839
-
12840
- // src/util/flatMapAsync.ts
12841
- async function flatMapAsync(array, callback, or) {
12842
- if (or) {
12843
- const errorHandlingCallback = async (value, index, array2) => {
12844
- try {
12845
- return await callback(value, index, array2);
12846
- } catch (error) {
12847
- return typeof or === "function" ? await or(error) : or;
12664
+ class Stack {
12665
+ constructor(max) {
12666
+ if (max === 0) {
12667
+ return [];
12848
12668
  }
12849
- };
12850
- return flatMapAsync(array, errorHandlingCallback);
12851
- }
12852
- const promises = [];
12853
- for (let i = 0;i < array.length; i++) {
12854
- promises.push(callback(array[i], i, array));
12855
- }
12856
- const awaitedAll = await Promise.all(promises);
12857
- return awaitedAll.flat();
12858
- }
12859
- var init_flatMapAsync = __esm(() => {
12860
- });
12861
-
12862
- // src/browsers/QuerySqliteThenTransform.ts
12863
- import fs from "fs";
12864
- import {Database} from "bun:sqlite";
12865
- async function checkFileExistence(file) {
12866
- if (!file || !fs.existsSync(file))
12867
- throw new Error(`File ${file} does not exist`);
12868
- }
12869
- async function transformRows(rows, rowFilter, rowTransform, file) {
12870
- const filteredRows = rows.filter(rowFilter);
12871
- const transformedRows = filteredRows.map((row) => import_lodash3.merge({ meta: { file } }, rowTransform(row)));
12872
- return transformedRows;
12873
- }
12874
- async function querySqliteThenTransform({
12875
- file,
12876
- sql,
12877
- rowFilter = () => true,
12878
- rowTransform
12879
- }) {
12880
- await checkFileExistence(file);
12881
- const db = new Database(file);
12882
- try {
12883
- const rows = db.query(sql).all();
12884
- if (!rows || rows.length === 0)
12885
- return [];
12886
- return await transformRows(rows, rowFilter, rowTransform, file);
12887
- } catch (err) {
12888
- throw err;
12889
- }
12890
- }
12891
- var import_lodash3;
12892
- var init_QuerySqliteThenTransform = __esm(() => {
12893
- import_lodash3 = __toESM(require_lodash(), 1);
12894
- });
12895
-
12896
- // src/StringToRegex.ts
12897
- function stringToRegex(s3) {
12898
- let s1 = s3.replace(/\./g, "\\.");
12899
- let s22 = s1.replace(/%/g, ".*");
12900
- let s32 = s22.replace(/\*/g, ".*");
12901
- return new RegExp(s32);
12902
- }
12903
- var init_StringToRegex = __esm(() => {
12904
- });
12905
-
12906
- // src/browsers/getEncryptedChromeCookie.ts
12907
- import {existsSync as existsSync2} from "fs";
12908
- import {join as join2} from "path";
12909
- async function getEncryptedChromeCookie({
12910
- name,
12911
- domain,
12912
- file = join2(chromeApplicationSupport, "Default", "Cookies")
12913
- }) {
12914
- if (!existsSync2(file)) {
12915
- throw new Error(`File ${file} does not exist`);
12916
- }
12917
- const sqlQueryBuilder = new SqlQueryBuilder;
12918
- sqlQueryBuilder.addCondition("name", name);
12919
- const wildcardDomain = /[%*]/.test(domain);
12920
- if (!wildcardDomain) {
12921
- const sqlEmbedDomain = domain.replace(/^[.%]?/, "%");
12922
- sqlQueryBuilder.addCondition("host_key", sqlEmbedDomain, "LIKE");
12923
- }
12924
- const sql = sqlQueryBuilder.build();
12925
- const verboseLogger = new VerboseLogger;
12926
- verboseLogger.log(file, name, domain, sql);
12927
- const domainRegexp = stringToRegex(domain);
12928
- const rowTransformer = new RowTransformer;
12929
- let sqliteQuery1;
12930
- try {
12931
- sqliteQuery1 = await querySqliteThenTransform({
12932
- file,
12933
- sql,
12934
- rowFilter: (row) => {
12935
- return row["host_key"].match(domainRegexp) != null;
12936
- },
12937
- rowTransform: rowTransformer.transform.bind(rowTransformer)
12938
- });
12939
- } catch (error) {
12940
- throw error;
12941
- }
12942
- const filteredResults = sqliteQuery1.filter((row) => {
12943
- return row.domain.match(domainRegexp) != null;
12944
- });
12945
- return filteredResults;
12946
- }
12947
-
12948
- class SqlQueryBuilder {
12949
- baseQuery;
12950
- conditions;
12951
- constructor(baseQuery = "SELECT encrypted_value, name, host_key, expires_utc FROM cookies") {
12952
- this.baseQuery = baseQuery;
12953
- this.conditions = [];
12954
- }
12955
- addCondition(field, value, operator = "=") {
12956
- const wildcardRegexp = /^([*%])$/i;
12957
- if (!wildcardRegexp.test(value)) {
12958
- const condition = `${field} ${operator} '${value}'`;
12959
- this.conditions.push(condition);
12669
+ const UintArray = getUintArray(max);
12670
+ this.heap = new UintArray(max);
12671
+ this.length = 0;
12960
12672
  }
12961
- }
12962
- build() {
12963
- let sql = this.baseQuery;
12964
- if (this.conditions.length > 0) {
12965
- sql += ` WHERE ${this.conditions.join(" AND ")}`;
12673
+ push(n) {
12674
+ this.heap[this.length++] = n;
12966
12675
  }
12967
- return sql;
12968
- }
12969
- }
12970
-
12971
- class VerboseLogger {
12972
- log(file, name, domain, sql) {
12973
- if (parsedArgs.verbose) {
12974
- const s3 = file.split("/").slice(-3).join("/");
12975
- logger_default.start(`Trying Chrome (at ${s3}) cookie ${name} for domain ${domain}`);
12976
- }
12977
- }
12978
- }
12979
-
12980
- class RowTransformer {
12981
- transform(row) {
12982
- const cookieRow = {
12983
- expiry: (row["expires_utc"] / 1e6 - 11644473600) * 1000,
12984
- domain: row["host_key"],
12985
- name: row["name"],
12986
- value: row["encrypted_value"]
12987
- };
12988
- return cookieRow;
12989
- }
12990
- }
12991
- var init_getEncryptedChromeCookie = __esm(() => {
12992
- init_ChromeApplicationSupport();
12993
- init_QuerySqliteThenTransform();
12994
- init_argv();
12995
- init_StringToRegex();
12996
- init_logger();
12997
- });
12998
-
12999
- // src/browsers/chrome/ChromeCookieQueryStrategy.ts
13000
- class ChromeCookieQueryStrategy {
13001
- browserName = "Chrome";
13002
- async queryCookies(name, domain) {
13003
- this.ensurePlatformIsMacOS();
13004
- if (env2.FIREFOX_ONLY) {
13005
- return [];
13006
- }
13007
- return this.getChromeCookies({
13008
- requireJwt: false,
13009
- name,
13010
- domain
13011
- });
13012
- }
13013
- ensurePlatformIsMacOS() {
13014
- if (process.platform !== "darwin") {
13015
- throw new Error("This only works on macOS");
13016
- }
13017
- }
13018
- async getChromeCookies({
13019
- name,
13020
- domain = "%",
13021
- requireJwt = false
13022
- }) {
13023
- const encryptedDataItems = await this.getEncryptedCookies(name, domain);
13024
- const password = await getChromePassword();
13025
- const decryptedCookies = await this.decryptCookies(encryptedDataItems, password);
13026
- return decryptedCookies;
13027
- }
13028
- async getEncryptedCookies(name, domain) {
13029
- try {
13030
- const files = findAllFiles({
13031
- path: chromeApplicationSupport,
13032
- name: "Cookies"
13033
- });
13034
- const results = await flatMapAsync(files, async (file) => {
13035
- return await this.getCookiesFromFile(name, domain, file);
13036
- });
13037
- return results.filter(isCookieRow);
13038
- } catch (error) {
13039
- consola3.warn("Error finding encrypted cookies", error);
13040
- return [];
13041
- }
13042
- }
13043
- async getCookiesFromFile(name, domain, file) {
13044
- try {
13045
- return await getEncryptedChromeCookie({
13046
- name,
13047
- domain,
13048
- file
13049
- });
13050
- } catch (e) {
13051
- consola3.warn("Error getting encrypted cookie from file", e);
13052
- return [];
13053
- }
13054
- }
13055
- async decryptCookies(encryptedDataItems, password) {
13056
- const decrypted = encryptedDataItems.filter(({ value }) => value != null && value.length > 0).map(async (cookieRow) => {
13057
- const encryptedValue = cookieRow.value;
13058
- const decryptedValue = await this.decryptValue(password, encryptedValue);
13059
- return this.createExportedCookie(cookieRow, decryptedValue);
13060
- });
13061
- return (await Promise.all(decrypted)).filter(isExportedCookie);
13062
- }
13063
- async decryptValue(password, encryptedValue) {
13064
- let decrypted;
13065
- try {
13066
- const bufferValue = Buffer.isBuffer(encryptedValue) ? encryptedValue : Buffer.from(encryptedValue);
13067
- decrypted = await decrypt(password, bufferValue);
13068
- } catch (e) {
13069
- consola3.warn("Error decrypting cookie", e);
13070
- decrypted = null;
13071
- }
13072
- return decrypted ?? encryptedValue.toString("utf-8");
13073
- }
13074
- createExportedCookie(cookieRow, decryptedValue) {
13075
- const meta = {};
13076
- import_lodash4.merge(meta, cookieRow.meta ?? {});
13077
- const exportedCookie = {
13078
- domain: cookieRow.domain,
13079
- name: cookieRow.name,
13080
- value: decryptedValue,
13081
- meta
13082
- };
13083
- const expiry = cookieRow.expiry;
13084
- const mergeExpiry = expiry != null && expiry > 0 ? {
13085
- expiry: new Date(expiry)
13086
- } : {
13087
- expiry: "Infinity"
13088
- };
13089
- import_lodash4.merge(exportedCookie, mergeExpiry);
13090
- return exportedCookie;
13091
- }
13092
- }
13093
- var import_lodash4, consola3;
13094
- var init_ChromeCookieQueryStrategy = __esm(() => {
13095
- init_CookieRow();
13096
- init_ChromeApplicationSupport();
13097
- init_decrypt();
13098
- init_global();
13099
- init_findAllFiles();
13100
- init_getChromePassword();
13101
- init_ExportedCookie();
13102
- import_lodash4 = __toESM(require_lodash(), 1);
13103
- init_flatMapAsync();
13104
- init_getEncryptedChromeCookie();
13105
- init_logger();
13106
- consola3 = logger_default.withTag("ChromeCookieQueryStrategy");
13107
- });
13108
-
13109
- // src/SpecialCases.ts
13110
- function specialCases({ name, domain }) {
13111
- const wildcardRegexp = /^([*%])$/i;
13112
- const specifiedName = name.match(wildcardRegexp) == null;
13113
- const specifiedDomain = domain.match(wildcardRegexp) == null;
13114
- return {
13115
- specifiedName,
13116
- specifiedDomain
13117
- };
13118
- }
13119
- var init_SpecialCases = __esm(() => {
13120
- });
13121
-
13122
- // src/browsers/firefox/FirefoxCookieQueryStrategy.ts
13123
- import * as path from "path";
13124
- import {existsSync as existsSync3} from "fs";
13125
-
13126
- class FirefoxCookieQueryStrategy {
13127
- browserName = "Firefox";
13128
- async queryCookies(name, domain) {
13129
- if (process.platform !== "darwin") {
13130
- return [];
13131
- }
13132
- if (parsedArgs.browser !== "firefox") {
13133
- return [];
13134
- }
13135
- const cookies = await this.getFirefoxCookie({ name, domain });
13136
- if (Array.isArray(cookies)) {
13137
- return cookies.map((cookie) => {
13138
- return {
13139
- domain: cookie.domain,
13140
- name: cookie.name,
13141
- value: Buffer.isBuffer(cookie.value) ? cookie.value.toString("utf8") : Buffer.from(cookie.value).toString("utf8")
13142
- };
13143
- });
13144
- } else {
13145
- return [];
13146
- }
13147
- }
13148
- async getFirefoxCookie({ name, domain }) {
13149
- if (!HOME) {
13150
- throw new Error("HOME environment variable is not set");
13151
- }
13152
- const files = findAllFiles({
13153
- path: path.join(HOME, "Library", "Application Support", "Firefox", "Profiles"),
13154
- name: "cookies.sqlite"
13155
- });
13156
- const all = await Promise.all(files.map(async (file) => {
13157
- return await this.queryCookiesDb(file, name, domain);
13158
- }));
13159
- return all.flat();
13160
- }
13161
- async queryCookiesDb(file, name, domain) {
13162
- if (!existsSync3(file)) {
13163
- throw new Error(`File ${file} does not exist`);
13164
- }
13165
- let sql;
13166
- sql = "SELECT value, name, host FROM moz_cookies";
13167
- const { specifiedName, specifiedDomain } = specialCases({ name, domain });
13168
- if (specifiedName || specifiedDomain) {
13169
- sql += ` WHERE `;
13170
- if (specifiedName) {
13171
- sql += `name = '${name}'`;
13172
- if (specifiedDomain) {
13173
- sql += ` AND `;
13174
- }
13175
- }
13176
- if (specifiedDomain) {
13177
- sql += `host LIKE '${domain}';`;
13178
- }
13179
- }
13180
- const rowTransform = (row) => {
13181
- const value = row.value;
13182
- return {
13183
- domain: row.domain,
13184
- name: row.name,
13185
- value: Buffer.from(value, "utf8")
13186
- };
13187
- };
13188
- try {
13189
- return await querySqliteThenTransform({
13190
- file,
13191
- sql,
13192
- rowTransform
13193
- });
13194
- } catch (e) {
13195
- console.error(`Error querying ${file}`, e);
13196
- return [];
13197
- }
13198
- }
13199
- }
13200
- var init_FirefoxCookieQueryStrategy = __esm(() => {
13201
- init_global();
13202
- init_findAllFiles();
13203
- init_SpecialCases();
13204
- init_argv();
13205
- init_QuerySqliteThenTransform();
13206
- });
13207
-
13208
- // src/decodeBinaryCookies.ts
13209
- import fs2 from "fs/promises";
13210
- var decodeBinaryCookies;
13211
- var init_decodeBinaryCookies = __esm(() => {
13212
- decodeBinaryCookies = async (cookieDbPath) => {
13213
- try {
13214
- await fs2.access(cookieDbPath);
13215
- } catch {
13216
- return [];
13217
- }
13218
- const magicBytes = Buffer.from([99, 111, 107, 107]);
13219
- const buffer = await fs2.readFile(cookieDbPath);
13220
- if (!buffer.slice(0, 4).equals(magicBytes)) {
13221
- throw new Error("Not a cookie file");
13222
- }
13223
- const count = buffer.readUInt32BE(4);
13224
- const cookies = [];
13225
- let offset = 8;
13226
- for (let i = 0;i < count; i++) {
13227
- const pageSize = buffer.readUInt32BE(offset);
13228
- offset += 4;
13229
- const page = buffer.slice(offset, offset + pageSize);
13230
- offset += pageSize;
13231
- if (!page.slice(0, 4).equals(Buffer.from([0, 0, 1, 0]))) {
13232
- throw new Error("Bad page header");
13233
- }
13234
- const cookieCount = page.readUInt32LE(4);
13235
- let pageOffset = 8;
13236
- for (let j2 = 0;j2 < cookieCount; j2++) {
13237
- const cookieOffset = page.readUInt32LE(pageOffset);
13238
- pageOffset += 4;
13239
- const cookieLength = page.readUInt32LE(cookieOffset);
13240
- const cookie = page.slice(cookieOffset, cookieOffset + cookieLength);
13241
- const flags = cookie.readUInt32LE(8);
13242
- const urlOffset = cookie.readUInt32LE(16);
13243
- const nameOffset = cookie.readUInt32LE(20);
13244
- const valueOffset = cookie.readUInt32LE(28);
13245
- const expiry = cookie.readDoubleLE(40) + 978307200;
13246
- const url = cookie.slice(urlOffset, nameOffset).toString("utf8").replace(/\0/g, "");
13247
- const name = cookie.slice(nameOffset, valueOffset).toString("utf8").replace(/\0/g, "");
13248
- const value = cookie.slice(valueOffset, cookie.length).toString("utf8").replace(/\0/g, "");
13249
- cookies.push({
13250
- domain: url,
13251
- name,
13252
- value: Buffer.from(value, "utf8"),
13253
- expiry: new Date(expiry * 1000).getTime(),
13254
- meta: {
13255
- path: cookie.slice(cookie.readUInt32LE(24), valueOffset).toString("utf8").replace(/\0/g, ""),
13256
- httpOnly: (flags & 4) === 4,
13257
- secure: (flags & 1) === 1
13258
- }
13259
- });
13260
- }
13261
- if (!page.slice(cookieCount * 4 + 8, cookieCount * 4 + 12).equals(Buffer.from([0, 0, 0, 0]))) {
13262
- throw new Error("Bad page trailer");
13263
- }
13264
- }
13265
- return cookies;
13266
- };
13267
- });
13268
-
13269
- // src/browsers/safari/SafariCookieQueryStrategy.ts
13270
- import {join as join4} from "path";
13271
-
13272
- class SafariCookieQueryStrategy {
13273
- browserName = "Safari";
13274
- async queryCookies(name, domain) {
13275
- const homeDir = process.env.HOME;
13276
- if (!homeDir) {
13277
- throw new Error("HOME environment variable is not set");
13278
- }
13279
- const cookieDbPath = join4(homeDir, "Library", "Cookies", "Cookies.binarycookies");
13280
- try {
13281
- const cookies = await decodeBinaryCookies(cookieDbPath);
13282
- const filteredCookies = cookies.filter((cookie) => cookie.name === name && cookie.domain.includes(domain));
13283
- const exportedCookies = filteredCookies.map((cookie) => ({
13284
- domain: cookie.domain,
13285
- name: cookie.name,
13286
- value: cookie.value.toString("utf8")
13287
- }));
13288
- return exportedCookies;
13289
- } catch (e) {
13290
- console.error(`Error decoding ${cookieDbPath}`, e);
13291
- return [];
13292
- }
13293
- }
13294
- }
13295
- var init_SafariCookieQueryStrategy = __esm(() => {
13296
- init_decodeBinaryCookies();
13297
- });
13298
-
13299
- // node_modules/lru-cache/index.js
13300
- var require_lru_cache = __commonJS((exports, module) => {
13301
- var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
13302
- var hasAbortController = typeof AbortController === "function";
13303
- var AC = hasAbortController ? AbortController : class AbortController2 {
13304
- constructor() {
13305
- this.signal = new AS;
13306
- }
13307
- abort() {
13308
- this.signal.dispatchEvent("abort");
13309
- }
13310
- };
13311
- var hasAbortSignal = typeof AbortSignal === "function";
13312
- var hasACAbortSignal = typeof AC.AbortSignal === "function";
13313
- var AS = hasAbortSignal ? AbortSignal : hasACAbortSignal ? AC.AbortController : class AbortSignal2 {
13314
- constructor() {
13315
- this.aborted = false;
13316
- this._listeners = [];
13317
- }
13318
- dispatchEvent(type) {
13319
- if (type === "abort") {
13320
- this.aborted = true;
13321
- const e = { type, target: this };
13322
- this.onabort(e);
13323
- this._listeners.forEach((f2) => f2(e), this);
13324
- }
13325
- }
13326
- onabort() {
13327
- }
13328
- addEventListener(ev, fn) {
13329
- if (ev === "abort") {
13330
- this._listeners.push(fn);
13331
- }
13332
- }
13333
- removeEventListener(ev, fn) {
13334
- if (ev === "abort") {
13335
- this._listeners = this._listeners.filter((f2) => f2 !== fn);
13336
- }
13337
- }
13338
- };
13339
- var warned = new Set;
13340
- var deprecatedOption = (opt, instead) => {
13341
- const code = `LRU_CACHE_OPTION_${opt}`;
13342
- if (shouldWarn(code)) {
13343
- warn(code, `${opt} option`, `options.${instead}`, LRUCache);
13344
- }
13345
- };
13346
- var deprecatedMethod = (method, instead) => {
13347
- const code = `LRU_CACHE_METHOD_${method}`;
13348
- if (shouldWarn(code)) {
13349
- const { prototype } = LRUCache;
13350
- const { get } = Object.getOwnPropertyDescriptor(prototype, method);
13351
- warn(code, `${method} method`, `cache.${instead}()`, get);
13352
- }
13353
- };
13354
- var deprecatedProperty = (field, instead) => {
13355
- const code = `LRU_CACHE_PROPERTY_${field}`;
13356
- if (shouldWarn(code)) {
13357
- const { prototype } = LRUCache;
13358
- const { get } = Object.getOwnPropertyDescriptor(prototype, field);
13359
- warn(code, `${field} property`, `cache.${instead}`, get);
13360
- }
13361
- };
13362
- var emitWarning = (...a) => {
13363
- typeof process === "object" && process && typeof process.emitWarning === "function" ? process.emitWarning(...a) : console.error(...a);
13364
- };
13365
- var shouldWarn = (code) => !warned.has(code);
13366
- var warn = (code, what, instead, fn) => {
13367
- warned.add(code);
13368
- const msg = `The ${what} is deprecated. Please use ${instead} instead.`;
13369
- emitWarning(msg, "DeprecationWarning", code, fn);
13370
- };
13371
- var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
13372
- var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
13373
-
13374
- class ZeroArray extends Array {
13375
- constructor(size) {
13376
- super(size);
13377
- this.fill(0);
13378
- }
13379
- }
13380
-
13381
- class Stack {
13382
- constructor(max) {
13383
- if (max === 0) {
13384
- return [];
13385
- }
13386
- const UintArray = getUintArray(max);
13387
- this.heap = new UintArray(max);
13388
- this.length = 0;
13389
- }
13390
- push(n) {
13391
- this.heap[this.length++] = n;
13392
- }
13393
- pop() {
13394
- return this.heap[--this.length];
12676
+ pop() {
12677
+ return this.heap[--this.length];
13395
12678
  }
13396
12679
  }
13397
12680
 
@@ -14097,60 +13380,6 @@ var require_lru_cache = __commonJS((exports, module) => {
14097
13380
  module.exports = LRUCache;
14098
13381
  });
14099
13382
 
14100
- // src/browsers/CompositeCookieQueryStrategy.ts
14101
- class CompositeCookieQueryStrategy {
14102
- browserName = "all";
14103
- strategies;
14104
- constructor() {
14105
- this.strategies = [
14106
- ChromeCookieQueryStrategy,
14107
- FirefoxCookieQueryStrategy,
14108
- SafariCookieQueryStrategy
14109
- ].map((Strategy) => new Strategy);
14110
- }
14111
- async queryCookies(name, domain) {
14112
- const key = `${name}:${domain}`;
14113
- logger_default.info(`Querying cookies for name: ${name}, domain: ${domain}`);
14114
- if (cache.has(key)) {
14115
- const cached = cache.get(key);
14116
- if (cached) {
14117
- logger_default.info(`Cache hit for key: ${key}, returning ${cached.length} cookies`);
14118
- return cached;
14119
- }
14120
- }
14121
- const results = await flatMapAsync(this.strategies, async (strategy) => {
14122
- try {
14123
- const cookies = await strategy.queryCookies(name, domain);
14124
- return cookies.map((cookie) => import_lodash5.merge(cookie, {
14125
- meta: {
14126
- browser: strategy.browserName
14127
- }
14128
- }));
14129
- } catch (e) {
14130
- logger_default.error(`Error querying cookies for ${name} on ${domain} using ${strategy.browserName}`, e);
14131
- return [];
14132
- }
14133
- });
14134
- cache.set(key, results);
14135
- logger_default.info(`Query result size for key: ${key} is ${results.length} cookies`);
14136
- return results;
14137
- }
14138
- }
14139
- var import_lru_cache, import_lodash5, cache;
14140
- var init_CompositeCookieQueryStrategy = __esm(() => {
14141
- init_ChromeCookieQueryStrategy();
14142
- init_FirefoxCookieQueryStrategy();
14143
- init_SafariCookieQueryStrategy();
14144
- import_lru_cache = __toESM(require_lru_cache(), 1);
14145
- import_lodash5 = __toESM(require_lodash(), 1);
14146
- init_flatMapAsync();
14147
- init_logger();
14148
- cache = new import_lru_cache.default({
14149
- ttl: 1e4,
14150
- max: 10
14151
- });
14152
- });
14153
-
14154
13383
  // node_modules/jsonwebtoken/lib/JsonWebTokenError.js
14155
13384
  var require_JsonWebTokenError = __commonJS((exports, module) => {
14156
13385
  var JsonWebTokenError = function(message, error) {
@@ -17919,293 +17148,6 @@ var require_jsonwebtoken = __commonJS((exports, module) => {
17919
17148
  });
17920
17149
  });
17921
17150
 
17922
- // src/isValidJwt.ts
17923
- function isValidJwt(token) {
17924
- try {
17925
- const result = import_jsonwebtoken.default.decode(token, { complete: true });
17926
- if (parsedArgs.verbose && result) {
17927
- console.debug(result);
17928
- }
17929
- const payload = result?.payload;
17930
- if (payload) {
17931
- const exp = payload.exp;
17932
- if (exp) {
17933
- const now = new Date().getTime() / 1000;
17934
- if (now > exp) {
17935
- return false;
17936
- }
17937
- }
17938
- }
17939
- return true;
17940
- } catch (err) {
17941
- return false;
17942
- }
17943
- }
17944
- var import_jsonwebtoken;
17945
- var init_isValidJwt = __esm(() => {
17946
- import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
17947
- init_argv();
17948
- });
17949
-
17950
- // src/queryCookies.ts
17951
- async function queryCookies({ name, domain }, options) {
17952
- const strategy = options?.strategy || new CompositeCookieQueryStrategy;
17953
- logger_default.debug(`Using strategy: ${strategy.browserName}`);
17954
- const results = await strategy.queryCookies(name, domain);
17955
- const allCookies = import_lodash6.uniqBy(results, JSON.stringify);
17956
- const filterCookies = (cookies, filterFn) => {
17957
- const filteredCookies = [];
17958
- for (const cookie of cookies) {
17959
- if (filterFn(cookie.value)) {
17960
- filteredCookies.push(cookie);
17961
- }
17962
- }
17963
- return filteredCookies;
17964
- };
17965
- const jwtCookies = parsedArgs["require-jwt"] ? filterCookies(allCookies, isValidJwt) : allCookies;
17966
- return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
17967
- }
17968
- var import_lodash6;
17969
- var init_queryCookies = __esm(() => {
17970
- import_lodash6 = __toESM(require_lodash(), 1);
17971
- init_argv();
17972
- init_CompositeCookieQueryStrategy();
17973
- init_isValidJwt();
17974
- init_logger();
17975
- });
17976
-
17977
- // src/getCookie.ts
17978
- var exports_getCookie = {};
17979
- __export(exports_getCookie, {
17980
- getCookie: () => {
17981
- {
17982
- return getCookie;
17983
- }
17984
- },
17985
- default: () => {
17986
- {
17987
- return getCookie_default;
17988
- }
17989
- }
17990
- });
17991
- async function getCookie(params) {
17992
- const cookies = await queryCookies(params, {
17993
- strategy: queryStrategy
17994
- });
17995
- if (Array.isArray(cookies) && cookies.length > 0) {
17996
- return cookies.find((cookie) => cookie != null);
17997
- } else {
17998
- throw new Error("Cookie not found");
17999
- }
18000
- }
18001
- var queryStrategy, getCookie_default;
18002
- var init_getCookie = __esm(() => {
18003
- init_queryCookies();
18004
- init_CompositeCookieQueryStrategy();
18005
- queryStrategy = new CompositeCookieQueryStrategy;
18006
- getCookie_default = getCookie;
18007
- });
18008
-
18009
- // src/getChromeCookie.ts
18010
- var exports_getChromeCookie = {};
18011
- __export(exports_getChromeCookie, {
18012
- getChromeCookie: () => {
18013
- {
18014
- return getChromeCookie;
18015
- }
18016
- }
18017
- });
18018
- async function getChromeCookie(params) {
18019
- const cookies = await queryCookies(params, {
18020
- strategy: new ChromeCookieQueryStrategy
18021
- });
18022
- if (cookies.length === 0) {
18023
- throw new Error("Cookie not found");
18024
- }
18025
- return cookies.find(isExportedCookie);
18026
- }
18027
- var init_getChromeCookie = __esm(() => {
18028
- init_queryCookies();
18029
- init_ChromeCookieQueryStrategy();
18030
- init_ExportedCookie();
18031
- });
18032
-
18033
- // src/getFirefoxCookie.ts
18034
- var exports_getFirefoxCookie = {};
18035
- __export(exports_getFirefoxCookie, {
18036
- getFirefoxCookie: () => {
18037
- {
18038
- return getFirefoxCookie;
18039
- }
18040
- }
18041
- });
18042
- async function getFirefoxCookie(params) {
18043
- const cookies = await queryCookies(params, {
18044
- strategy: new FirefoxCookieQueryStrategy
18045
- });
18046
- if (!Array.isArray(cookies) || cookies.length === 0) {
18047
- throw new Error("Cookie not found");
18048
- }
18049
- const validCookie = cookies.find((cookie) => cookie != null);
18050
- if (!validCookie) {
18051
- throw new Error("Cookie not found");
18052
- }
18053
- return validCookie;
18054
- }
18055
- var init_getFirefoxCookie = __esm(() => {
18056
- init_queryCookies();
18057
- init_FirefoxCookieQueryStrategy();
18058
- });
18059
-
18060
- // src/resultsRendered.ts
18061
- function resultsRendered(results) {
18062
- const orderedResults = sortResults(results);
18063
- const uniqueResults = getUniqueResults(orderedResults);
18064
- return formatResults(uniqueResults);
18065
- }
18066
- var import_lodash7, sortResults, getUniqueResults, formatResults;
18067
- var init_resultsRendered = __esm(() => {
18068
- import_lodash7 = __toESM(require_lodash(), 1);
18069
- sortResults = function(results) {
18070
- return import_lodash7.orderBy(results, ["name", "expiry"], ["asc", "desc"]);
18071
- };
18072
- getUniqueResults = function(results) {
18073
- return import_lodash7.uniqBy(results, "name");
18074
- };
18075
- formatResults = function(results) {
18076
- const resultStrings = [];
18077
- for (const result of results) {
18078
- resultStrings.push(`${result.name}=${result.value}`);
18079
- }
18080
- return resultStrings.join("; ");
18081
- };
18082
- });
18083
-
18084
- // src/util/index.ts
18085
- var init_util = __esm(() => {
18086
- init_flatMapAsync();
18087
- });
18088
-
18089
- // src/cookieQueryOptions.ts
18090
- function mergedWithDefaults(options) {
18091
- const mergedOptions = import_lodash8.merge({}, defaultCookieQueryOptions, options);
18092
- return mergedOptions;
18093
- }
18094
- var import_lodash8, defaultCookieQueryOptions;
18095
- var init_cookieQueryOptions = __esm(() => {
18096
- init_CompositeCookieQueryStrategy();
18097
- import_lodash8 = __toESM(require_lodash(), 1);
18098
- defaultCookieQueryOptions = {
18099
- strategy: new CompositeCookieQueryStrategy,
18100
- limit: undefined,
18101
- removeExpired: undefined
18102
- };
18103
- });
18104
-
18105
- // src/processBeforeReturn.ts
18106
- function processBeforeReturn(cookies, options) {
18107
- let processedCookies = cookies;
18108
- if (options && options.removeExpired) {
18109
- const now = Date.now();
18110
- processedCookies = processedCookies.filter((c2) => {
18111
- const expiry = c2.expiry;
18112
- return expiry === undefined || expiry === "Infinity" || expiry.getTime() > now;
18113
- });
18114
- }
18115
- if (options && options.limit) {
18116
- processedCookies = processedCookies.slice(0, options.limit);
18117
- }
18118
- return import_lodash9.uniqBy(processedCookies, (cookie) => JSON.stringify(cookie));
18119
- }
18120
- var import_lodash9;
18121
- var init_processBeforeReturn = __esm(() => {
18122
- import_lodash9 = __toESM(require_lodash(), 1);
18123
- });
18124
-
18125
- // src/comboQueryCookieSpec.ts
18126
- async function comboQueryCookieSpec(cookieSpec, options) {
18127
- const optsWithDefaults = mergedWithDefaults(options);
18128
- const queryFn = async (cs) => queryCookies(cs, optsWithDefaults);
18129
- let cookies;
18130
- if (Array.isArray(cookieSpec)) {
18131
- cookies = await flatMapAsync(cookieSpec, queryFn);
18132
- } else {
18133
- cookies = await queryFn(cookieSpec);
18134
- }
18135
- return processBeforeReturn(cookies, options);
18136
- }
18137
- var init_comboQueryCookieSpec = __esm(() => {
18138
- init_queryCookies();
18139
- init_util();
18140
- init_cookieQueryOptions();
18141
- init_processBeforeReturn();
18142
- });
18143
-
18144
- // src/getGroupedRenderedCookies.ts
18145
- var exports_getGroupedRenderedCookies = {};
18146
- __export(exports_getGroupedRenderedCookies, {
18147
- getGroupedRenderedCookies: () => {
18148
- {
18149
- return getGroupedRenderedCookies;
18150
- }
18151
- }
18152
- });
18153
- async function getGroupedRenderedCookies(cookieSpec) {
18154
- const cookies = await fetchCookies(cookieSpec);
18155
- const groupedByFile = groupCookiesByFile(cookies);
18156
- return renderGroupedCookies(groupedByFile);
18157
- }
18158
- async function fetchCookies(cookieSpec) {
18159
- const cookies = await comboQueryCookieSpec(cookieSpec);
18160
- if (cookies.length === 0) {
18161
- throw new Error("Cookie not found");
18162
- }
18163
- return cookies;
18164
- }
18165
- var import_lodash10, groupCookiesByFile, renderGroupedCookies;
18166
- var init_getGroupedRenderedCookies = __esm(() => {
18167
- import_lodash10 = __toESM(require_lodash(), 1);
18168
- init_resultsRendered();
18169
- init_comboQueryCookieSpec();
18170
- groupCookiesByFile = function(cookies) {
18171
- return import_lodash10.groupBy(cookies, (r2) => r2.meta?.file);
18172
- };
18173
- renderGroupedCookies = function(groupedByFile) {
18174
- const renderedResults = [];
18175
- for (const file in groupedByFile) {
18176
- if (groupedByFile.hasOwnProperty(file)) {
18177
- const results = groupedByFile[file];
18178
- renderedResults.push(resultsRendered(results));
18179
- }
18180
- }
18181
- return renderedResults;
18182
- };
18183
- });
18184
-
18185
- // src/getMergedRenderedCookies.ts
18186
- var exports_getMergedRenderedCookies = {};
18187
- __export(exports_getMergedRenderedCookies, {
18188
- getMergedRenderedCookies: () => {
18189
- {
18190
- return getMergedRenderedCookies;
18191
- }
18192
- }
18193
- });
18194
- async function getMergedRenderedCookies(cookieSpec, strategy = new CompositeCookieQueryStrategy) {
18195
- const cookies = await comboQueryCookieSpec(cookieSpec, {
18196
- strategy
18197
- });
18198
- if (cookies.length > 0) {
18199
- return resultsRendered(cookies);
18200
- }
18201
- return "";
18202
- }
18203
- var init_getMergedRenderedCookies = __esm(() => {
18204
- init_resultsRendered();
18205
- init_comboQueryCookieSpec();
18206
- init_CompositeCookieQueryStrategy();
18207
- });
18208
-
18209
17151
  // node_modules/webidl-conversions/lib/index.js
18210
17152
  var require_lib = __commonJS((exports, module) => {
18211
17153
  var sign = function(x) {
@@ -24091,668 +23033,1552 @@ var require_lib3 = __commonJS((exports, module) => {
24091
23033
  });
24092
23034
  return;
24093
23035
  }
24094
- if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
24095
- body = body.pipe(zlib.createBrotliDecompress());
24096
- response = new Response(body, response_options);
24097
- resolve(response);
23036
+ if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
23037
+ body = body.pipe(zlib.createBrotliDecompress());
23038
+ response = new Response(body, response_options);
23039
+ resolve(response);
23040
+ return;
23041
+ }
23042
+ response = new Response(body, response_options);
23043
+ resolve(response);
23044
+ });
23045
+ writeToStream(req, request);
23046
+ });
23047
+ };
23048
+ var fixResponseChunkedTransferBadEnding = function(request, errorCallback) {
23049
+ let socket;
23050
+ request.on("socket", function(s3) {
23051
+ socket = s3;
23052
+ });
23053
+ request.on("response", function(response) {
23054
+ const headers = response.headers;
23055
+ if (headers["transfer-encoding"] === "chunked" && !headers["content-length"]) {
23056
+ response.once("close", function(hadError) {
23057
+ const hasDataListener = socket && socket.listenerCount("data") > 0;
23058
+ if (hasDataListener && !hadError) {
23059
+ const err = new Error("Premature close");
23060
+ err.code = "ERR_STREAM_PREMATURE_CLOSE";
23061
+ errorCallback(err);
23062
+ }
23063
+ });
23064
+ }
23065
+ });
23066
+ };
23067
+ var destroyStream = function(stream, err) {
23068
+ if (stream.destroy) {
23069
+ stream.destroy(err);
23070
+ } else {
23071
+ stream.emit("error", err);
23072
+ stream.end();
23073
+ }
23074
+ };
23075
+ Object.defineProperty(exports, "__esModule", { value: true });
23076
+ var Stream = _interopDefault(__require("stream"));
23077
+ var http = _interopDefault(__require("http"));
23078
+ var Url = _interopDefault(__require("url"));
23079
+ var whatwgUrl = _interopDefault(require_public_api());
23080
+ var https = _interopDefault(__require("https"));
23081
+ var zlib = _interopDefault(__require("zlib"));
23082
+ var Readable = Stream.Readable;
23083
+ var BUFFER = Symbol("buffer");
23084
+ var TYPE = Symbol("type");
23085
+
23086
+ class Blob {
23087
+ constructor() {
23088
+ this[TYPE] = "";
23089
+ const blobParts = arguments[0];
23090
+ const options = arguments[1];
23091
+ const buffers = [];
23092
+ let size = 0;
23093
+ if (blobParts) {
23094
+ const a = blobParts;
23095
+ const length = Number(a.length);
23096
+ for (let i = 0;i < length; i++) {
23097
+ const element = a[i];
23098
+ let buffer;
23099
+ if (element instanceof Buffer) {
23100
+ buffer = element;
23101
+ } else if (ArrayBuffer.isView(element)) {
23102
+ buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
23103
+ } else if (element instanceof ArrayBuffer) {
23104
+ buffer = Buffer.from(element);
23105
+ } else if (element instanceof Blob) {
23106
+ buffer = element[BUFFER];
23107
+ } else {
23108
+ buffer = Buffer.from(typeof element === "string" ? element : String(element));
23109
+ }
23110
+ size += buffer.length;
23111
+ buffers.push(buffer);
23112
+ }
23113
+ }
23114
+ this[BUFFER] = Buffer.concat(buffers);
23115
+ let type = options && options.type !== undefined && String(options.type).toLowerCase();
23116
+ if (type && !/[^\u0020-\u007E]/.test(type)) {
23117
+ this[TYPE] = type;
23118
+ }
23119
+ }
23120
+ get size() {
23121
+ return this[BUFFER].length;
23122
+ }
23123
+ get type() {
23124
+ return this[TYPE];
23125
+ }
23126
+ text() {
23127
+ return Promise.resolve(this[BUFFER].toString());
23128
+ }
23129
+ arrayBuffer() {
23130
+ const buf = this[BUFFER];
23131
+ const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
23132
+ return Promise.resolve(ab);
23133
+ }
23134
+ stream() {
23135
+ const readable = new Readable;
23136
+ readable._read = function() {
23137
+ };
23138
+ readable.push(this[BUFFER]);
23139
+ readable.push(null);
23140
+ return readable;
23141
+ }
23142
+ toString() {
23143
+ return "[object Blob]";
23144
+ }
23145
+ slice() {
23146
+ const size = this.size;
23147
+ const start = arguments[0];
23148
+ const end = arguments[1];
23149
+ let relativeStart, relativeEnd;
23150
+ if (start === undefined) {
23151
+ relativeStart = 0;
23152
+ } else if (start < 0) {
23153
+ relativeStart = Math.max(size + start, 0);
23154
+ } else {
23155
+ relativeStart = Math.min(start, size);
23156
+ }
23157
+ if (end === undefined) {
23158
+ relativeEnd = size;
23159
+ } else if (end < 0) {
23160
+ relativeEnd = Math.max(size + end, 0);
23161
+ } else {
23162
+ relativeEnd = Math.min(end, size);
23163
+ }
23164
+ const span = Math.max(relativeEnd - relativeStart, 0);
23165
+ const buffer = this[BUFFER];
23166
+ const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
23167
+ const blob = new Blob([], { type: arguments[2] });
23168
+ blob[BUFFER] = slicedBuffer;
23169
+ return blob;
23170
+ }
23171
+ }
23172
+ Object.defineProperties(Blob.prototype, {
23173
+ size: { enumerable: true },
23174
+ type: { enumerable: true },
23175
+ slice: { enumerable: true }
23176
+ });
23177
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
23178
+ value: "Blob",
23179
+ writable: false,
23180
+ enumerable: false,
23181
+ configurable: true
23182
+ });
23183
+ FetchError.prototype = Object.create(Error.prototype);
23184
+ FetchError.prototype.constructor = FetchError;
23185
+ FetchError.prototype.name = "FetchError";
23186
+ var convert;
23187
+ try {
23188
+ convert = require_encoding().convert;
23189
+ } catch (e) {
23190
+ }
23191
+ var INTERNALS = Symbol("Body internals");
23192
+ var PassThrough = Stream.PassThrough;
23193
+ Body.prototype = {
23194
+ get body() {
23195
+ return this[INTERNALS].body;
23196
+ },
23197
+ get bodyUsed() {
23198
+ return this[INTERNALS].disturbed;
23199
+ },
23200
+ arrayBuffer() {
23201
+ return consumeBody.call(this).then(function(buf) {
23202
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
23203
+ });
23204
+ },
23205
+ blob() {
23206
+ let ct = this.headers && this.headers.get("content-type") || "";
23207
+ return consumeBody.call(this).then(function(buf) {
23208
+ return Object.assign(new Blob([], {
23209
+ type: ct.toLowerCase()
23210
+ }), {
23211
+ [BUFFER]: buf
23212
+ });
23213
+ });
23214
+ },
23215
+ json() {
23216
+ var _this2 = this;
23217
+ return consumeBody.call(this).then(function(buffer) {
23218
+ try {
23219
+ return JSON.parse(buffer.toString());
23220
+ } catch (err) {
23221
+ return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, "invalid-json"));
23222
+ }
23223
+ });
23224
+ },
23225
+ text() {
23226
+ return consumeBody.call(this).then(function(buffer) {
23227
+ return buffer.toString();
23228
+ });
23229
+ },
23230
+ buffer() {
23231
+ return consumeBody.call(this);
23232
+ },
23233
+ textConverted() {
23234
+ var _this3 = this;
23235
+ return consumeBody.call(this).then(function(buffer) {
23236
+ return convertBody(buffer, _this3.headers);
23237
+ });
23238
+ }
23239
+ };
23240
+ Object.defineProperties(Body.prototype, {
23241
+ body: { enumerable: true },
23242
+ bodyUsed: { enumerable: true },
23243
+ arrayBuffer: { enumerable: true },
23244
+ blob: { enumerable: true },
23245
+ json: { enumerable: true },
23246
+ text: { enumerable: true }
23247
+ });
23248
+ Body.mixIn = function(proto) {
23249
+ for (const name of Object.getOwnPropertyNames(Body.prototype)) {
23250
+ if (!(name in proto)) {
23251
+ const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
23252
+ Object.defineProperty(proto, name, desc);
23253
+ }
23254
+ }
23255
+ };
23256
+ Body.Promise = global.Promise;
23257
+ var invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
23258
+ var invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
23259
+ var MAP = Symbol("map");
23260
+
23261
+ class Headers {
23262
+ constructor() {
23263
+ let init2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
23264
+ this[MAP] = Object.create(null);
23265
+ if (init2 instanceof Headers) {
23266
+ const rawHeaders = init2.raw();
23267
+ const headerNames = Object.keys(rawHeaders);
23268
+ for (const headerName of headerNames) {
23269
+ for (const value of rawHeaders[headerName]) {
23270
+ this.append(headerName, value);
23271
+ }
23272
+ }
23273
+ return;
23274
+ }
23275
+ if (init2 == null)
23276
+ ;
23277
+ else if (typeof init2 === "object") {
23278
+ const method = init2[Symbol.iterator];
23279
+ if (method != null) {
23280
+ if (typeof method !== "function") {
23281
+ throw new TypeError("Header pairs must be iterable");
23282
+ }
23283
+ const pairs = [];
23284
+ for (const pair of init2) {
23285
+ if (typeof pair !== "object" || typeof pair[Symbol.iterator] !== "function") {
23286
+ throw new TypeError("Each header pair must be iterable");
23287
+ }
23288
+ pairs.push(Array.from(pair));
23289
+ }
23290
+ for (const pair of pairs) {
23291
+ if (pair.length !== 2) {
23292
+ throw new TypeError("Each header pair must be a name/value tuple");
23293
+ }
23294
+ this.append(pair[0], pair[1]);
23295
+ }
23296
+ } else {
23297
+ for (const key of Object.keys(init2)) {
23298
+ const value = init2[key];
23299
+ this.append(key, value);
23300
+ }
23301
+ }
23302
+ } else {
23303
+ throw new TypeError("Provided initializer must be an object");
23304
+ }
23305
+ }
23306
+ get(name) {
23307
+ name = `${name}`;
23308
+ validateName(name);
23309
+ const key = find(this[MAP], name);
23310
+ if (key === undefined) {
23311
+ return null;
23312
+ }
23313
+ return this[MAP][key].join(", ");
23314
+ }
23315
+ forEach(callback) {
23316
+ let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
23317
+ let pairs = getHeaders(this);
23318
+ let i = 0;
23319
+ while (i < pairs.length) {
23320
+ var _pairs$i = pairs[i];
23321
+ const name = _pairs$i[0], value = _pairs$i[1];
23322
+ callback.call(thisArg, value, name, this);
23323
+ pairs = getHeaders(this);
23324
+ i++;
23325
+ }
23326
+ }
23327
+ set(name, value) {
23328
+ name = `${name}`;
23329
+ value = `${value}`;
23330
+ validateName(name);
23331
+ validateValue(value);
23332
+ const key = find(this[MAP], name);
23333
+ this[MAP][key !== undefined ? key : name] = [value];
23334
+ }
23335
+ append(name, value) {
23336
+ name = `${name}`;
23337
+ value = `${value}`;
23338
+ validateName(name);
23339
+ validateValue(value);
23340
+ const key = find(this[MAP], name);
23341
+ if (key !== undefined) {
23342
+ this[MAP][key].push(value);
23343
+ } else {
23344
+ this[MAP][name] = [value];
23345
+ }
23346
+ }
23347
+ has(name) {
23348
+ name = `${name}`;
23349
+ validateName(name);
23350
+ return find(this[MAP], name) !== undefined;
23351
+ }
23352
+ delete(name) {
23353
+ name = `${name}`;
23354
+ validateName(name);
23355
+ const key = find(this[MAP], name);
23356
+ if (key !== undefined) {
23357
+ delete this[MAP][key];
23358
+ }
23359
+ }
23360
+ raw() {
23361
+ return this[MAP];
23362
+ }
23363
+ keys() {
23364
+ return createHeadersIterator(this, "key");
23365
+ }
23366
+ values() {
23367
+ return createHeadersIterator(this, "value");
23368
+ }
23369
+ [Symbol.iterator]() {
23370
+ return createHeadersIterator(this, "key+value");
23371
+ }
23372
+ }
23373
+ Headers.prototype.entries = Headers.prototype[Symbol.iterator];
23374
+ Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
23375
+ value: "Headers",
23376
+ writable: false,
23377
+ enumerable: false,
23378
+ configurable: true
23379
+ });
23380
+ Object.defineProperties(Headers.prototype, {
23381
+ get: { enumerable: true },
23382
+ forEach: { enumerable: true },
23383
+ set: { enumerable: true },
23384
+ append: { enumerable: true },
23385
+ has: { enumerable: true },
23386
+ delete: { enumerable: true },
23387
+ keys: { enumerable: true },
23388
+ values: { enumerable: true },
23389
+ entries: { enumerable: true }
23390
+ });
23391
+ var INTERNAL = Symbol("internal");
23392
+ var HeadersIteratorPrototype = Object.setPrototypeOf({
23393
+ next() {
23394
+ if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
23395
+ throw new TypeError("Value of `this` is not a HeadersIterator");
23396
+ }
23397
+ var _INTERNAL = this[INTERNAL];
23398
+ const { target, kind, index } = _INTERNAL;
23399
+ const values = getHeaders(target, kind);
23400
+ const len = values.length;
23401
+ if (index >= len) {
23402
+ return {
23403
+ value: undefined,
23404
+ done: true
23405
+ };
23406
+ }
23407
+ this[INTERNAL].index = index + 1;
23408
+ return {
23409
+ value: values[index],
23410
+ done: false
23411
+ };
23412
+ }
23413
+ }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
23414
+ Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
23415
+ value: "HeadersIterator",
23416
+ writable: false,
23417
+ enumerable: false,
23418
+ configurable: true
23419
+ });
23420
+ var INTERNALS$1 = Symbol("Response internals");
23421
+ var STATUS_CODES = http.STATUS_CODES;
23422
+
23423
+ class Response {
23424
+ constructor() {
23425
+ let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
23426
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
23427
+ Body.call(this, body, opts);
23428
+ const status = opts.status || 200;
23429
+ const headers = new Headers(opts.headers);
23430
+ if (body != null && !headers.has("Content-Type")) {
23431
+ const contentType = extractContentType(body);
23432
+ if (contentType) {
23433
+ headers.append("Content-Type", contentType);
23434
+ }
23435
+ }
23436
+ this[INTERNALS$1] = {
23437
+ url: opts.url,
23438
+ status,
23439
+ statusText: opts.statusText || STATUS_CODES[status],
23440
+ headers,
23441
+ counter: opts.counter
23442
+ };
23443
+ }
23444
+ get url() {
23445
+ return this[INTERNALS$1].url || "";
23446
+ }
23447
+ get status() {
23448
+ return this[INTERNALS$1].status;
23449
+ }
23450
+ get ok() {
23451
+ return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
23452
+ }
23453
+ get redirected() {
23454
+ return this[INTERNALS$1].counter > 0;
23455
+ }
23456
+ get statusText() {
23457
+ return this[INTERNALS$1].statusText;
23458
+ }
23459
+ get headers() {
23460
+ return this[INTERNALS$1].headers;
23461
+ }
23462
+ clone() {
23463
+ return new Response(clone(this), {
23464
+ url: this.url,
23465
+ status: this.status,
23466
+ statusText: this.statusText,
23467
+ headers: this.headers,
23468
+ ok: this.ok,
23469
+ redirected: this.redirected
23470
+ });
23471
+ }
23472
+ }
23473
+ Body.mixIn(Response.prototype);
23474
+ Object.defineProperties(Response.prototype, {
23475
+ url: { enumerable: true },
23476
+ status: { enumerable: true },
23477
+ ok: { enumerable: true },
23478
+ redirected: { enumerable: true },
23479
+ statusText: { enumerable: true },
23480
+ headers: { enumerable: true },
23481
+ clone: { enumerable: true }
23482
+ });
23483
+ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
23484
+ value: "Response",
23485
+ writable: false,
23486
+ enumerable: false,
23487
+ configurable: true
23488
+ });
23489
+ var INTERNALS$2 = Symbol("Request internals");
23490
+ var URL2 = Url.URL || whatwgUrl.URL;
23491
+ var parse_url = Url.parse;
23492
+ var format_url = Url.format;
23493
+ var streamDestructionSupported = "destroy" in Stream.Readable.prototype;
23494
+
23495
+ class Request {
23496
+ constructor(input) {
23497
+ let init2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
23498
+ let parsedURL;
23499
+ if (!isRequest(input)) {
23500
+ if (input && input.href) {
23501
+ parsedURL = parseURL(input.href);
23502
+ } else {
23503
+ parsedURL = parseURL(`${input}`);
23504
+ }
23505
+ input = {};
23506
+ } else {
23507
+ parsedURL = parseURL(input.url);
23508
+ }
23509
+ let method = init2.method || input.method || "GET";
23510
+ method = method.toUpperCase();
23511
+ if ((init2.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
23512
+ throw new TypeError("Request with GET/HEAD method cannot have body");
23513
+ }
23514
+ let inputBody = init2.body != null ? init2.body : isRequest(input) && input.body !== null ? clone(input) : null;
23515
+ Body.call(this, inputBody, {
23516
+ timeout: init2.timeout || input.timeout || 0,
23517
+ size: init2.size || input.size || 0
23518
+ });
23519
+ const headers = new Headers(init2.headers || input.headers || {});
23520
+ if (inputBody != null && !headers.has("Content-Type")) {
23521
+ const contentType = extractContentType(inputBody);
23522
+ if (contentType) {
23523
+ headers.append("Content-Type", contentType);
23524
+ }
23525
+ }
23526
+ let signal = isRequest(input) ? input.signal : null;
23527
+ if ("signal" in init2)
23528
+ signal = init2.signal;
23529
+ if (signal != null && !isAbortSignal(signal)) {
23530
+ throw new TypeError("Expected signal to be an instanceof AbortSignal");
23531
+ }
23532
+ this[INTERNALS$2] = {
23533
+ method,
23534
+ redirect: init2.redirect || input.redirect || "follow",
23535
+ headers,
23536
+ parsedURL,
23537
+ signal
23538
+ };
23539
+ this.follow = init2.follow !== undefined ? init2.follow : input.follow !== undefined ? input.follow : 20;
23540
+ this.compress = init2.compress !== undefined ? init2.compress : input.compress !== undefined ? input.compress : true;
23541
+ this.counter = init2.counter || input.counter || 0;
23542
+ this.agent = init2.agent || input.agent;
23543
+ }
23544
+ get method() {
23545
+ return this[INTERNALS$2].method;
23546
+ }
23547
+ get url() {
23548
+ return format_url(this[INTERNALS$2].parsedURL);
23549
+ }
23550
+ get headers() {
23551
+ return this[INTERNALS$2].headers;
23552
+ }
23553
+ get redirect() {
23554
+ return this[INTERNALS$2].redirect;
23555
+ }
23556
+ get signal() {
23557
+ return this[INTERNALS$2].signal;
23558
+ }
23559
+ clone() {
23560
+ return new Request(this);
23561
+ }
23562
+ }
23563
+ Body.mixIn(Request.prototype);
23564
+ Object.defineProperty(Request.prototype, Symbol.toStringTag, {
23565
+ value: "Request",
23566
+ writable: false,
23567
+ enumerable: false,
23568
+ configurable: true
23569
+ });
23570
+ Object.defineProperties(Request.prototype, {
23571
+ method: { enumerable: true },
23572
+ url: { enumerable: true },
23573
+ headers: { enumerable: true },
23574
+ redirect: { enumerable: true },
23575
+ clone: { enumerable: true },
23576
+ signal: { enumerable: true }
23577
+ });
23578
+ AbortError.prototype = Object.create(Error.prototype);
23579
+ AbortError.prototype.constructor = AbortError;
23580
+ AbortError.prototype.name = "AbortError";
23581
+ var URL$1 = Url.URL || whatwgUrl.URL;
23582
+ var PassThrough$1 = Stream.PassThrough;
23583
+ var isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
23584
+ const orig = new URL$1(original).hostname;
23585
+ const dest = new URL$1(destination).hostname;
23586
+ return orig === dest || orig[orig.length - dest.length - 1] === "." && orig.endsWith(dest);
23587
+ };
23588
+ var isSameProtocol = function isSameProtocol(destination, original) {
23589
+ const orig = new URL$1(original).protocol;
23590
+ const dest = new URL$1(destination).protocol;
23591
+ return orig === dest;
23592
+ };
23593
+ fetch.isRedirect = function(code) {
23594
+ return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
23595
+ };
23596
+ fetch.Promise = global.Promise;
23597
+ module.exports = exports = fetch;
23598
+ Object.defineProperty(exports, "__esModule", { value: true });
23599
+ exports.default = exports;
23600
+ exports.Headers = Headers;
23601
+ exports.Request = Request;
23602
+ exports.Response = Response;
23603
+ exports.FetchError = FetchError;
23604
+ exports.AbortError = AbortError;
23605
+ });
23606
+
23607
+ // node_modules/cross-fetch/dist/node-ponyfill.js
23608
+ var require_node_ponyfill = __commonJS((exports, module) => {
23609
+ var nodeFetch = require_lib3();
23610
+ var realFetch = nodeFetch.default || nodeFetch;
23611
+ var fetch = function(url, options) {
23612
+ if (/^\/\//.test(url)) {
23613
+ url = "https:" + url;
23614
+ }
23615
+ return realFetch.call(this, url, options);
23616
+ };
23617
+ fetch.ponyfill = true;
23618
+ module.exports = exports = fetch;
23619
+ exports.fetch = fetch;
23620
+ exports.Headers = nodeFetch.Headers;
23621
+ exports.Request = nodeFetch.Request;
23622
+ exports.Response = nodeFetch.Response;
23623
+ exports.default = fetch;
23624
+ });
23625
+
23626
+ // src/queryCookies.ts
23627
+ var import_lodash6 = __toESM(require_lodash(), 1);
23628
+
23629
+ // src/argv.ts
23630
+ var import_minimist = __toESM(require_minimist(), 1);
23631
+ var import_lodash = __toESM(require_lodash(), 1);
23632
+ var argv = process.argv ?? [];
23633
+ var minimistArgs = import_minimist.default(argv.slice(2));
23634
+ var defaultOptions = {
23635
+ verbose: false
23636
+ };
23637
+ var parsedArgs = import_lodash.merge(defaultOptions, minimistArgs);
23638
+
23639
+ // node_modules/consola/dist/index.mjs
23640
+ init_consola_36c0034f();
23641
+ init_core();
23642
+ init_consola_06ad8a64();
23643
+ init_utils();
23644
+
23645
+ // src/logger.ts
23646
+ var consola2 = createConsola2({
23647
+ fancy: true,
23648
+ formatOptions: {
23649
+ showLogLevel: true,
23650
+ colors: true,
23651
+ date: false
23652
+ }
23653
+ });
23654
+ var logger_default = consola2;
23655
+
23656
+ // src/CookieRow.ts
23657
+ function isCookieRow(obj) {
23658
+ if (typeof obj !== "object" || obj === null) {
23659
+ logger_default.warn("Object is not an object or is null:", obj);
23660
+ return false;
23661
+ }
23662
+ const { domain, name, value } = obj;
23663
+ if (typeof domain !== "string") {
23664
+ logger_default.warn("Domain is not a string:", domain);
23665
+ return false;
23666
+ }
23667
+ if (typeof name !== "string") {
23668
+ logger_default.warn("Name is not a string:", name);
23669
+ return false;
23670
+ }
23671
+ if (!(value instanceof Uint8Array) && !Buffer.isBuffer(value)) {
23672
+ logger_default.warn("Value is not a Uint8Array or Buffer:", value);
23673
+ return false;
23674
+ }
23675
+ return true;
23676
+ }
23677
+
23678
+ // src/browsers/chrome/ChromeApplicationSupport.ts
23679
+ import {join} from "path";
23680
+
23681
+ // src/global.ts
23682
+ var import_lodash2 = __toESM(require_lodash(), 1);
23683
+ var env2 = {};
23684
+ import_lodash2.merge(env2, process?.env ?? {});
23685
+ var HOME = env2["HOME"];
23686
+ if (!HOME) {
23687
+ throw new Error("HOME environment variable is not set");
23688
+ }
23689
+
23690
+ // src/browsers/chrome/ChromeApplicationSupport.ts
23691
+ if (HOME === undefined) {
23692
+ throw new Error("HOME environment variable is not defined");
23693
+ }
23694
+ var chromeApplicationSupport = join(HOME, "Library", "Application Support", "Google", "Chrome");
23695
+
23696
+ // src/browsers/chrome/decrypt.ts
23697
+ import {createDecipheriv, pbkdf2} from "crypto";
23698
+ async function decrypt(password, encryptedData) {
23699
+ return decryptor.decrypt(password, encryptedData);
23700
+ }
23701
+
23702
+ class BufferDecryptor {
23703
+ async decrypt(password, encryptedData) {
23704
+ this.validatePassword(password);
23705
+ const preparedData = this.validateAndPrepareEncryptedData(encryptedData);
23706
+ if (parsedArgs.verbose) {
23707
+ logger_default.start(`Trying to decrypt with password: ${password}`);
23708
+ }
23709
+ const decryptedData = await this.performDecryption(password, preparedData);
23710
+ if (parsedArgs.verbose) {
23711
+ logger_default.success(`Decryption successful: ${decryptedData}`);
23712
+ }
23713
+ return decryptedData;
23714
+ }
23715
+ validatePassword(password) {
23716
+ if (typeof password !== "string") {
23717
+ throw new Error("password must be a string: " + password);
23718
+ }
23719
+ }
23720
+ validateAndPrepareEncryptedData(encryptedData) {
23721
+ if (encryptedData == null || !(encryptedData instanceof Buffer || Array.isArray(encryptedData) && Buffer.isBuffer(encryptedData[0]))) {
23722
+ throw new Error("encryptedData must be a Buffer or an array of Buffers: " + encryptedData);
23723
+ }
23724
+ if (Array.isArray(encryptedData) && Buffer.isBuffer(encryptedData[0])) {
23725
+ encryptedData = encryptedData[0];
23726
+ if (parsedArgs.verbose) {
23727
+ logger_default.info(`encryptedData is an array of buffers, selected first: ${encryptedData}`);
23728
+ }
23729
+ }
23730
+ return Buffer.from(encryptedData);
23731
+ }
23732
+ performDecryption(password, encryptedData) {
23733
+ return new Promise((resolve, reject) => {
23734
+ this.deriveKey(password).then((key) => this.decryptData(key, encryptedData)).then((decrypted) => resolve(decrypted)).catch((error) => reject(error));
23735
+ });
23736
+ }
23737
+ deriveKey(password) {
23738
+ return new Promise((resolve, reject) => {
23739
+ pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer) => {
23740
+ if (error) {
23741
+ this.logError("Error doing pbkdf2", error);
23742
+ reject(error);
23743
+ return;
23744
+ }
23745
+ if (buffer.length !== 16) {
23746
+ this.logError("Error doing pbkdf2, buffer length is not 16", buffer.length);
23747
+ reject(new Error("Buffer length is not 16"));
24098
23748
  return;
24099
23749
  }
24100
- response = new Response(body, response_options);
24101
- resolve(response);
23750
+ resolve(buffer);
24102
23751
  });
24103
- writeToStream(req, request);
24104
- });
24105
- };
24106
- var fixResponseChunkedTransferBadEnding = function(request, errorCallback) {
24107
- let socket;
24108
- request.on("socket", function(s3) {
24109
- socket = s3;
24110
23752
  });
24111
- request.on("response", function(response) {
24112
- const headers = response.headers;
24113
- if (headers["transfer-encoding"] === "chunked" && !headers["content-length"]) {
24114
- response.once("close", function(hadError) {
24115
- const hasDataListener = socket && socket.listenerCount("data") > 0;
24116
- if (hasDataListener && !hadError) {
24117
- const err = new Error("Premature close");
24118
- err.code = "ERR_STREAM_PREMATURE_CLOSE";
24119
- errorCallback(err);
24120
- }
24121
- });
23753
+ }
23754
+ decryptData(key, encryptedData) {
23755
+ return new Promise((resolve, reject) => {
23756
+ const iv = Buffer.from(new Array(17).join(" "), "binary");
23757
+ const decipher = createDecipheriv("aes-128-cbc", key, iv);
23758
+ decipher.setAutoPadding(false);
23759
+ const slicedData = encryptedData.slice(3);
23760
+ if (slicedData.length % 16 !== 0) {
23761
+ this.logError("Error, encryptedData length is not a multiple of 16", slicedData.length);
23762
+ reject(new Error("encryptedData length is not a multiple of 16"));
23763
+ return;
24122
23764
  }
24123
- });
24124
- };
24125
- var destroyStream = function(stream, err) {
24126
- if (stream.destroy) {
24127
- stream.destroy(err);
24128
- } else {
24129
- stream.emit("error", err);
24130
- stream.end();
24131
- }
24132
- };
24133
- Object.defineProperty(exports, "__esModule", { value: true });
24134
- var Stream = _interopDefault(__require("stream"));
24135
- var http = _interopDefault(__require("http"));
24136
- var Url = _interopDefault(__require("url"));
24137
- var whatwgUrl = _interopDefault(require_public_api());
24138
- var https = _interopDefault(__require("https"));
24139
- var zlib = _interopDefault(__require("zlib"));
24140
- var Readable = Stream.Readable;
24141
- var BUFFER = Symbol("buffer");
24142
- var TYPE = Symbol("type");
24143
-
24144
- class Blob {
24145
- constructor() {
24146
- this[TYPE] = "";
24147
- const blobParts = arguments[0];
24148
- const options = arguments[1];
24149
- const buffers = [];
24150
- let size = 0;
24151
- if (blobParts) {
24152
- const a = blobParts;
24153
- const length = Number(a.length);
24154
- for (let i = 0;i < length; i++) {
24155
- const element = a[i];
24156
- let buffer;
24157
- if (element instanceof Buffer) {
24158
- buffer = element;
24159
- } else if (ArrayBuffer.isView(element)) {
24160
- buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
24161
- } else if (element instanceof ArrayBuffer) {
24162
- buffer = Buffer.from(element);
24163
- } else if (element instanceof Blob) {
24164
- buffer = element[BUFFER];
24165
- } else {
24166
- buffer = Buffer.from(typeof element === "string" ? element : String(element));
24167
- }
24168
- size += buffer.length;
24169
- buffers.push(buffer);
24170
- }
23765
+ let decoded = decipher.update(slicedData);
23766
+ try {
23767
+ decipher.final("utf-8");
23768
+ } catch (e) {
23769
+ this.logError("Error doing decipher.final()", e);
23770
+ reject(e);
23771
+ return;
24171
23772
  }
24172
- this[BUFFER] = Buffer.concat(buffers);
24173
- let type = options && options.type !== undefined && String(options.type).toLowerCase();
24174
- if (type && !/[^\u0020-\u007E]/.test(type)) {
24175
- this[TYPE] = type;
23773
+ const padding = decoded[decoded.length - 1];
23774
+ if (padding) {
23775
+ decoded = decoded.slice(0, 0 - padding);
24176
23776
  }
23777
+ resolve(decoded.toString("utf8"));
23778
+ });
23779
+ }
23780
+ logError(message, error) {
23781
+ if (parsedArgs.verbose) {
23782
+ logger_default.error(message, error);
24177
23783
  }
24178
- get size() {
24179
- return this[BUFFER].length;
24180
- }
24181
- get type() {
24182
- return this[TYPE];
24183
- }
24184
- text() {
24185
- return Promise.resolve(this[BUFFER].toString());
24186
- }
24187
- arrayBuffer() {
24188
- const buf = this[BUFFER];
24189
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
24190
- return Promise.resolve(ab);
24191
- }
24192
- stream() {
24193
- const readable = new Readable;
24194
- readable._read = function() {
24195
- };
24196
- readable.push(this[BUFFER]);
24197
- readable.push(null);
24198
- return readable;
24199
- }
24200
- toString() {
24201
- return "[object Blob]";
23784
+ }
23785
+ }
23786
+ var decryptor = new BufferDecryptor;
23787
+
23788
+ // src/findAllFiles.ts
23789
+ import {existsSync} from "fs";
23790
+ var import_fast_glob = __toESM(require_out4(), 1);
23791
+ function findAllFiles({
23792
+ path,
23793
+ name,
23794
+ maxDepth = 2
23795
+ }) {
23796
+ if (!existsSync(path)) {
23797
+ throw new Error(`Path ${path} does not exist`);
23798
+ }
23799
+ if (parsedArgs.verbose) {
23800
+ consola.start(`Searching for ${name} files in ${path}`);
23801
+ }
23802
+ const files = import_fast_glob.sync(`${path}/**/${name}`, {
23803
+ onlyFiles: true,
23804
+ deep: maxDepth
23805
+ });
23806
+ if (parsedArgs.verbose) {
23807
+ if (files.length > 0) {
23808
+ consola.success(`Found ${files.length} ${name} files`);
23809
+ consola.info(files);
24202
23810
  }
24203
- slice() {
24204
- const size = this.size;
24205
- const start = arguments[0];
24206
- const end = arguments[1];
24207
- let relativeStart, relativeEnd;
24208
- if (start === undefined) {
24209
- relativeStart = 0;
24210
- } else if (start < 0) {
24211
- relativeStart = Math.max(size + start, 0);
24212
- } else {
24213
- relativeStart = Math.min(start, size);
24214
- }
24215
- if (end === undefined) {
24216
- relativeEnd = size;
24217
- } else if (end < 0) {
24218
- relativeEnd = Math.max(size + end, 0);
24219
- } else {
24220
- relativeEnd = Math.min(end, size);
23811
+ }
23812
+ return files;
23813
+ }
23814
+
23815
+ // src/execSimple.ts
23816
+ async function execSimple(command) {
23817
+ try {
23818
+ const { execSync } = await import("child_process");
23819
+ const stdout2 = execSync(command, {
23820
+ encoding: "binary",
23821
+ maxBuffer: 5120
23822
+ });
23823
+ return stdout2.trim();
23824
+ } catch (error) {
23825
+ throw error;
23826
+ }
23827
+ }
23828
+
23829
+ // src/browsers/chrome/getChromePassword.ts
23830
+ async function getChromePassword() {
23831
+ return await passwordRetriever.retrievePassword();
23832
+ }
23833
+
23834
+ class MacOSPasswordRetriever {
23835
+ async retrievePassword() {
23836
+ return execSimple('security find-generic-password -w -s "Chrome Safe Storage"');
23837
+ }
23838
+ }
23839
+
23840
+ class UnsupportedPlatformPasswordRetriever {
23841
+ async retrievePassword() {
23842
+ return Promise.reject(new Error("This only works on macOS"));
23843
+ }
23844
+ }
23845
+ var passwordRetriever = process.platform == "darwin" ? new MacOSPasswordRetriever : new UnsupportedPlatformPasswordRetriever;
23846
+
23847
+ // src/ExportedCookie.ts
23848
+ function isExportedCookie(obj) {
23849
+ return typeof obj.domain === "string" && typeof obj.name === "string" && typeof obj.value === "string" && (obj.expiry === undefined || obj.expiry instanceof Date || obj.expiry === "Infinity") && (obj.meta === undefined || typeof obj.meta === "object");
23850
+ }
23851
+
23852
+ // src/browsers/chrome/ChromeCookieQueryStrategy.ts
23853
+ var import_lodash4 = __toESM(require_lodash(), 1);
23854
+
23855
+ // src/util/flatMapAsync.ts
23856
+ async function flatMapAsync(array, callback, or) {
23857
+ if (or) {
23858
+ const errorHandlingCallback = async (value, index, array2) => {
23859
+ try {
23860
+ return await callback(value, index, array2);
23861
+ } catch (error) {
23862
+ return typeof or === "function" ? await or(error) : or;
24221
23863
  }
24222
- const span = Math.max(relativeEnd - relativeStart, 0);
24223
- const buffer = this[BUFFER];
24224
- const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
24225
- const blob = new Blob([], { type: arguments[2] });
24226
- blob[BUFFER] = slicedBuffer;
24227
- return blob;
24228
- }
23864
+ };
23865
+ return flatMapAsync(array, errorHandlingCallback);
24229
23866
  }
24230
- Object.defineProperties(Blob.prototype, {
24231
- size: { enumerable: true },
24232
- type: { enumerable: true },
24233
- slice: { enumerable: true }
24234
- });
24235
- Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
24236
- value: "Blob",
24237
- writable: false,
24238
- enumerable: false,
24239
- configurable: true
24240
- });
24241
- FetchError.prototype = Object.create(Error.prototype);
24242
- FetchError.prototype.constructor = FetchError;
24243
- FetchError.prototype.name = "FetchError";
24244
- var convert;
23867
+ const promises = [];
23868
+ for (let i = 0;i < array.length; i++) {
23869
+ promises.push(callback(array[i], i, array));
23870
+ }
23871
+ const awaitedAll = await Promise.all(promises);
23872
+ return awaitedAll.flat();
23873
+ }
23874
+
23875
+ // src/browsers/QuerySqliteThenTransform.ts
23876
+ var import_lodash3 = __toESM(require_lodash(), 1);
23877
+ import fs from "fs";
23878
+ import {Database} from "bun:sqlite";
23879
+ async function checkFileExistence(file) {
23880
+ if (!file || !fs.existsSync(file))
23881
+ throw new Error(`File ${file} does not exist`);
23882
+ }
23883
+ async function transformRows(rows, rowFilter, rowTransform, file) {
23884
+ const filteredRows = rows.filter(rowFilter);
23885
+ const transformedRows = filteredRows.map((row) => import_lodash3.merge({ meta: { file } }, rowTransform(row)));
23886
+ return transformedRows;
23887
+ }
23888
+ async function querySqliteThenTransform({
23889
+ file,
23890
+ sql,
23891
+ rowFilter = () => true,
23892
+ rowTransform
23893
+ }) {
23894
+ await checkFileExistence(file);
23895
+ const db = new Database(file);
24245
23896
  try {
24246
- convert = require_encoding().convert;
24247
- } catch (e) {
23897
+ const rows = db.query(sql).all();
23898
+ if (!rows || rows.length === 0)
23899
+ return [];
23900
+ return await transformRows(rows, rowFilter, rowTransform, file);
23901
+ } catch (err) {
23902
+ throw err;
24248
23903
  }
24249
- var INTERNALS = Symbol("Body internals");
24250
- var PassThrough = Stream.PassThrough;
24251
- Body.prototype = {
24252
- get body() {
24253
- return this[INTERNALS].body;
24254
- },
24255
- get bodyUsed() {
24256
- return this[INTERNALS].disturbed;
24257
- },
24258
- arrayBuffer() {
24259
- return consumeBody.call(this).then(function(buf) {
24260
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
24261
- });
24262
- },
24263
- blob() {
24264
- let ct = this.headers && this.headers.get("content-type") || "";
24265
- return consumeBody.call(this).then(function(buf) {
24266
- return Object.assign(new Blob([], {
24267
- type: ct.toLowerCase()
24268
- }), {
24269
- [BUFFER]: buf
24270
- });
24271
- });
24272
- },
24273
- json() {
24274
- var _this2 = this;
24275
- return consumeBody.call(this).then(function(buffer) {
24276
- try {
24277
- return JSON.parse(buffer.toString());
24278
- } catch (err) {
24279
- return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, "invalid-json"));
24280
- }
24281
- });
24282
- },
24283
- text() {
24284
- return consumeBody.call(this).then(function(buffer) {
24285
- return buffer.toString();
24286
- });
24287
- },
24288
- buffer() {
24289
- return consumeBody.call(this);
24290
- },
24291
- textConverted() {
24292
- var _this3 = this;
24293
- return consumeBody.call(this).then(function(buffer) {
24294
- return convertBody(buffer, _this3.headers);
24295
- });
24296
- }
24297
- };
24298
- Object.defineProperties(Body.prototype, {
24299
- body: { enumerable: true },
24300
- bodyUsed: { enumerable: true },
24301
- arrayBuffer: { enumerable: true },
24302
- blob: { enumerable: true },
24303
- json: { enumerable: true },
24304
- text: { enumerable: true }
23904
+ }
23905
+
23906
+ // src/browsers/getEncryptedChromeCookie.ts
23907
+ import {existsSync as existsSync2} from "fs";
23908
+ import {join as join2} from "path";
23909
+
23910
+ // src/StringToRegex.ts
23911
+ function stringToRegex(s3) {
23912
+ let s1 = s3.replace(/\./g, "\\.");
23913
+ let s22 = s1.replace(/%/g, ".*");
23914
+ let s32 = s22.replace(/\*/g, ".*");
23915
+ return new RegExp(s32);
23916
+ }
23917
+
23918
+ // src/browsers/getEncryptedChromeCookie.ts
23919
+ async function getEncryptedChromeCookie({
23920
+ name,
23921
+ domain,
23922
+ file = join2(chromeApplicationSupport, "Default", "Cookies")
23923
+ }) {
23924
+ if (!existsSync2(file)) {
23925
+ throw new Error(`File ${file} does not exist`);
23926
+ }
23927
+ const sqlQueryBuilder = new SqlQueryBuilder;
23928
+ sqlQueryBuilder.addCondition("name", name);
23929
+ const wildcardDomain = /[%*]/.test(domain);
23930
+ if (!wildcardDomain) {
23931
+ const sqlEmbedDomain = domain.replace(/^[.%]?/, "%");
23932
+ sqlQueryBuilder.addCondition("host_key", sqlEmbedDomain, "LIKE");
23933
+ }
23934
+ const sql = sqlQueryBuilder.build();
23935
+ const verboseLogger = new VerboseLogger;
23936
+ verboseLogger.log(file, name, domain, sql);
23937
+ const domainRegexp = stringToRegex(domain);
23938
+ const rowTransformer = new RowTransformer;
23939
+ let sqliteQuery1;
23940
+ try {
23941
+ sqliteQuery1 = await querySqliteThenTransform({
23942
+ file,
23943
+ sql,
23944
+ rowFilter: (row) => {
23945
+ return row["host_key"].match(domainRegexp) != null;
23946
+ },
23947
+ rowTransform: rowTransformer.transform.bind(rowTransformer)
23948
+ });
23949
+ } catch (error) {
23950
+ throw error;
23951
+ }
23952
+ const filteredResults = sqliteQuery1.filter((row) => {
23953
+ return row.domain.match(domainRegexp) != null;
24305
23954
  });
24306
- Body.mixIn = function(proto) {
24307
- for (const name of Object.getOwnPropertyNames(Body.prototype)) {
24308
- if (!(name in proto)) {
24309
- const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
24310
- Object.defineProperty(proto, name, desc);
24311
- }
24312
- }
24313
- };
24314
- Body.Promise = global.Promise;
24315
- var invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
24316
- var invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
24317
- var MAP = Symbol("map");
23955
+ return filteredResults;
23956
+ }
24318
23957
 
24319
- class Headers {
24320
- constructor() {
24321
- let init2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
24322
- this[MAP] = Object.create(null);
24323
- if (init2 instanceof Headers) {
24324
- const rawHeaders = init2.raw();
24325
- const headerNames = Object.keys(rawHeaders);
24326
- for (const headerName of headerNames) {
24327
- for (const value of rawHeaders[headerName]) {
24328
- this.append(headerName, value);
24329
- }
24330
- }
24331
- return;
24332
- }
24333
- if (init2 == null)
24334
- ;
24335
- else if (typeof init2 === "object") {
24336
- const method = init2[Symbol.iterator];
24337
- if (method != null) {
24338
- if (typeof method !== "function") {
24339
- throw new TypeError("Header pairs must be iterable");
24340
- }
24341
- const pairs = [];
24342
- for (const pair of init2) {
24343
- if (typeof pair !== "object" || typeof pair[Symbol.iterator] !== "function") {
24344
- throw new TypeError("Each header pair must be iterable");
24345
- }
24346
- pairs.push(Array.from(pair));
24347
- }
24348
- for (const pair of pairs) {
24349
- if (pair.length !== 2) {
24350
- throw new TypeError("Each header pair must be a name/value tuple");
24351
- }
24352
- this.append(pair[0], pair[1]);
24353
- }
24354
- } else {
24355
- for (const key of Object.keys(init2)) {
24356
- const value = init2[key];
24357
- this.append(key, value);
24358
- }
24359
- }
24360
- } else {
24361
- throw new TypeError("Provided initializer must be an object");
24362
- }
23958
+ class SqlQueryBuilder {
23959
+ baseQuery;
23960
+ conditions;
23961
+ constructor(baseQuery = "SELECT encrypted_value, name, host_key, expires_utc FROM cookies") {
23962
+ this.baseQuery = baseQuery;
23963
+ this.conditions = [];
23964
+ }
23965
+ addCondition(field, value, operator = "=") {
23966
+ const wildcardRegexp = /^([*%])$/i;
23967
+ if (!wildcardRegexp.test(value)) {
23968
+ const condition = `${field} ${operator} '${value}'`;
23969
+ this.conditions.push(condition);
24363
23970
  }
24364
- get(name) {
24365
- name = `${name}`;
24366
- validateName(name);
24367
- const key = find(this[MAP], name);
24368
- if (key === undefined) {
24369
- return null;
24370
- }
24371
- return this[MAP][key].join(", ");
23971
+ }
23972
+ build() {
23973
+ let sql = this.baseQuery;
23974
+ if (this.conditions.length > 0) {
23975
+ sql += ` WHERE ${this.conditions.join(" AND ")}`;
24372
23976
  }
24373
- forEach(callback) {
24374
- let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
24375
- let pairs = getHeaders(this);
24376
- let i = 0;
24377
- while (i < pairs.length) {
24378
- var _pairs$i = pairs[i];
24379
- const name = _pairs$i[0], value = _pairs$i[1];
24380
- callback.call(thisArg, value, name, this);
24381
- pairs = getHeaders(this);
24382
- i++;
24383
- }
23977
+ return sql;
23978
+ }
23979
+ }
23980
+
23981
+ class VerboseLogger {
23982
+ log(file, name, domain, sql) {
23983
+ if (parsedArgs.verbose) {
23984
+ const s3 = file.split("/").slice(-3).join("/");
23985
+ logger_default.start(`Trying Chrome (at ${s3}) cookie ${name} for domain ${domain}`);
24384
23986
  }
24385
- set(name, value) {
24386
- name = `${name}`;
24387
- value = `${value}`;
24388
- validateName(name);
24389
- validateValue(value);
24390
- const key = find(this[MAP], name);
24391
- this[MAP][key !== undefined ? key : name] = [value];
23987
+ }
23988
+ }
23989
+
23990
+ class RowTransformer {
23991
+ transform(row) {
23992
+ const cookieRow = {
23993
+ expiry: (row["expires_utc"] / 1e6 - 11644473600) * 1000,
23994
+ domain: row["host_key"],
23995
+ name: row["name"],
23996
+ value: row["encrypted_value"]
23997
+ };
23998
+ return cookieRow;
23999
+ }
24000
+ }
24001
+
24002
+ // src/browsers/chrome/ChromeCookieQueryStrategy.ts
24003
+ var consola3 = logger_default.withTag("ChromeCookieQueryStrategy");
24004
+
24005
+ class ChromeCookieQueryStrategy {
24006
+ browserName = "Chrome";
24007
+ async queryCookies(name, domain) {
24008
+ this.ensurePlatformIsMacOS();
24009
+ if (env2.FIREFOX_ONLY) {
24010
+ return [];
24392
24011
  }
24393
- append(name, value) {
24394
- name = `${name}`;
24395
- value = `${value}`;
24396
- validateName(name);
24397
- validateValue(value);
24398
- const key = find(this[MAP], name);
24399
- if (key !== undefined) {
24400
- this[MAP][key].push(value);
24401
- } else {
24402
- this[MAP][name] = [value];
24403
- }
24012
+ return this.getChromeCookies({
24013
+ requireJwt: false,
24014
+ name,
24015
+ domain
24016
+ });
24017
+ }
24018
+ ensurePlatformIsMacOS() {
24019
+ if (process.platform !== "darwin") {
24020
+ throw new Error("This only works on macOS");
24404
24021
  }
24405
- has(name) {
24406
- name = `${name}`;
24407
- validateName(name);
24408
- return find(this[MAP], name) !== undefined;
24022
+ }
24023
+ async getChromeCookies({
24024
+ name,
24025
+ domain = "%",
24026
+ requireJwt = false
24027
+ }) {
24028
+ const encryptedDataItems = await this.getEncryptedCookies(name, domain);
24029
+ const password = await getChromePassword();
24030
+ const decryptedCookies = await this.decryptCookies(encryptedDataItems, password);
24031
+ return decryptedCookies;
24032
+ }
24033
+ async getEncryptedCookies(name, domain) {
24034
+ try {
24035
+ const files = findAllFiles({
24036
+ path: chromeApplicationSupport,
24037
+ name: "Cookies"
24038
+ });
24039
+ const results = await flatMapAsync(files, async (file) => {
24040
+ return await this.getCookiesFromFile(name, domain, file);
24041
+ });
24042
+ return results.filter(isCookieRow);
24043
+ } catch (error) {
24044
+ consola3.warn("Error finding encrypted cookies", error);
24045
+ return [];
24409
24046
  }
24410
- delete(name) {
24411
- name = `${name}`;
24412
- validateName(name);
24413
- const key = find(this[MAP], name);
24414
- if (key !== undefined) {
24415
- delete this[MAP][key];
24416
- }
24047
+ }
24048
+ async getCookiesFromFile(name, domain, file) {
24049
+ try {
24050
+ return await getEncryptedChromeCookie({
24051
+ name,
24052
+ domain,
24053
+ file
24054
+ });
24055
+ } catch (e) {
24056
+ consola3.warn("Error getting encrypted cookie from file", e);
24057
+ return [];
24417
24058
  }
24418
- raw() {
24419
- return this[MAP];
24059
+ }
24060
+ async decryptCookies(encryptedDataItems, password) {
24061
+ const decrypted = encryptedDataItems.filter(({ value }) => value != null && value.length > 0).map(async (cookieRow) => {
24062
+ const encryptedValue = cookieRow.value;
24063
+ const decryptedValue = await this.decryptValue(password, encryptedValue);
24064
+ return this.createExportedCookie(cookieRow, decryptedValue);
24065
+ });
24066
+ return (await Promise.all(decrypted)).filter(isExportedCookie);
24067
+ }
24068
+ async decryptValue(password, encryptedValue) {
24069
+ let decrypted;
24070
+ try {
24071
+ const bufferValue = Buffer.isBuffer(encryptedValue) ? encryptedValue : Buffer.from(encryptedValue);
24072
+ decrypted = await decrypt(password, bufferValue);
24073
+ } catch (e) {
24074
+ consola3.warn("Error decrypting cookie", e);
24075
+ decrypted = null;
24420
24076
  }
24421
- keys() {
24422
- return createHeadersIterator(this, "key");
24077
+ return decrypted ?? encryptedValue.toString("utf-8");
24078
+ }
24079
+ createExportedCookie(cookieRow, decryptedValue) {
24080
+ const meta = {};
24081
+ import_lodash4.merge(meta, cookieRow.meta ?? {});
24082
+ const exportedCookie = {
24083
+ domain: cookieRow.domain,
24084
+ name: cookieRow.name,
24085
+ value: decryptedValue,
24086
+ meta
24087
+ };
24088
+ const expiry = cookieRow.expiry;
24089
+ const mergeExpiry = expiry != null && expiry > 0 ? {
24090
+ expiry: new Date(expiry)
24091
+ } : {
24092
+ expiry: "Infinity"
24093
+ };
24094
+ import_lodash4.merge(exportedCookie, mergeExpiry);
24095
+ return exportedCookie;
24096
+ }
24097
+ }
24098
+
24099
+ // src/browsers/firefox/FirefoxCookieQueryStrategy.ts
24100
+ import * as path from "path";
24101
+ import {existsSync as existsSync3} from "fs";
24102
+
24103
+ // src/SpecialCases.ts
24104
+ function specialCases({ name, domain }) {
24105
+ const wildcardRegexp = /^([*%])$/i;
24106
+ const specifiedName = name.match(wildcardRegexp) == null;
24107
+ const specifiedDomain = domain.match(wildcardRegexp) == null;
24108
+ return {
24109
+ specifiedName,
24110
+ specifiedDomain
24111
+ };
24112
+ }
24113
+
24114
+ // src/browsers/firefox/FirefoxCookieQueryStrategy.ts
24115
+ class FirefoxCookieQueryStrategy {
24116
+ browserName = "Firefox";
24117
+ async queryCookies(name, domain) {
24118
+ if (process.platform !== "darwin") {
24119
+ return [];
24423
24120
  }
24424
- values() {
24425
- return createHeadersIterator(this, "value");
24121
+ if (parsedArgs.browser !== "firefox") {
24122
+ return [];
24426
24123
  }
24427
- [Symbol.iterator]() {
24428
- return createHeadersIterator(this, "key+value");
24124
+ const cookies = await this.getFirefoxCookie({ name, domain });
24125
+ if (Array.isArray(cookies)) {
24126
+ return cookies.map((cookie) => {
24127
+ return {
24128
+ domain: cookie.domain,
24129
+ name: cookie.name,
24130
+ value: Buffer.isBuffer(cookie.value) ? cookie.value.toString("utf8") : Buffer.from(cookie.value).toString("utf8")
24131
+ };
24132
+ });
24133
+ } else {
24134
+ return [];
24429
24135
  }
24430
24136
  }
24431
- Headers.prototype.entries = Headers.prototype[Symbol.iterator];
24432
- Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
24433
- value: "Headers",
24434
- writable: false,
24435
- enumerable: false,
24436
- configurable: true
24437
- });
24438
- Object.defineProperties(Headers.prototype, {
24439
- get: { enumerable: true },
24440
- forEach: { enumerable: true },
24441
- set: { enumerable: true },
24442
- append: { enumerable: true },
24443
- has: { enumerable: true },
24444
- delete: { enumerable: true },
24445
- keys: { enumerable: true },
24446
- values: { enumerable: true },
24447
- entries: { enumerable: true }
24448
- });
24449
- var INTERNAL = Symbol("internal");
24450
- var HeadersIteratorPrototype = Object.setPrototypeOf({
24451
- next() {
24452
- if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
24453
- throw new TypeError("Value of `this` is not a HeadersIterator");
24137
+ async getFirefoxCookie({ name, domain }) {
24138
+ if (!HOME) {
24139
+ throw new Error("HOME environment variable is not set");
24140
+ }
24141
+ const files = findAllFiles({
24142
+ path: path.join(HOME, "Library", "Application Support", "Firefox", "Profiles"),
24143
+ name: "cookies.sqlite"
24144
+ });
24145
+ const all = await Promise.all(files.map(async (file) => {
24146
+ return await this.queryCookiesDb(file, name, domain);
24147
+ }));
24148
+ return all.flat();
24149
+ }
24150
+ async queryCookiesDb(file, name, domain) {
24151
+ if (!existsSync3(file)) {
24152
+ throw new Error(`File ${file} does not exist`);
24153
+ }
24154
+ let sql;
24155
+ sql = "SELECT value, name, host FROM moz_cookies";
24156
+ const { specifiedName, specifiedDomain } = specialCases({ name, domain });
24157
+ if (specifiedName || specifiedDomain) {
24158
+ sql += ` WHERE `;
24159
+ if (specifiedName) {
24160
+ sql += `name = '${name}'`;
24161
+ if (specifiedDomain) {
24162
+ sql += ` AND `;
24163
+ }
24454
24164
  }
24455
- var _INTERNAL = this[INTERNAL];
24456
- const { target, kind, index } = _INTERNAL;
24457
- const values = getHeaders(target, kind);
24458
- const len = values.length;
24459
- if (index >= len) {
24460
- return {
24461
- value: undefined,
24462
- done: true
24463
- };
24165
+ if (specifiedDomain) {
24166
+ sql += `host LIKE '${domain}';`;
24464
24167
  }
24465
- this[INTERNAL].index = index + 1;
24168
+ }
24169
+ const rowTransform = (row) => {
24170
+ const value = row.value;
24466
24171
  return {
24467
- value: values[index],
24468
- done: false
24172
+ domain: row.domain,
24173
+ name: row.name,
24174
+ value: Buffer.from(value, "utf8")
24469
24175
  };
24176
+ };
24177
+ try {
24178
+ return await querySqliteThenTransform({
24179
+ file,
24180
+ sql,
24181
+ rowTransform
24182
+ });
24183
+ } catch (e) {
24184
+ console.error(`Error querying ${file}`, e);
24185
+ return [];
24470
24186
  }
24471
- }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
24472
- Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
24473
- value: "HeadersIterator",
24474
- writable: false,
24475
- enumerable: false,
24476
- configurable: true
24477
- });
24478
- var INTERNALS$1 = Symbol("Response internals");
24479
- var STATUS_CODES = http.STATUS_CODES;
24187
+ }
24188
+ }
24480
24189
 
24481
- class Response {
24482
- constructor() {
24483
- let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
24484
- let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24485
- Body.call(this, body, opts);
24486
- const status = opts.status || 200;
24487
- const headers = new Headers(opts.headers);
24488
- if (body != null && !headers.has("Content-Type")) {
24489
- const contentType = extractContentType(body);
24490
- if (contentType) {
24491
- headers.append("Content-Type", contentType);
24190
+ // src/browsers/safari/SafariCookieQueryStrategy.ts
24191
+ import {join as join4} from "path";
24192
+
24193
+ // src/decodeBinaryCookies.ts
24194
+ import fs2 from "fs/promises";
24195
+ var decodeBinaryCookies = async (cookieDbPath) => {
24196
+ try {
24197
+ await fs2.access(cookieDbPath);
24198
+ } catch {
24199
+ return [];
24200
+ }
24201
+ const magicBytes = Buffer.from([99, 111, 107, 107]);
24202
+ const buffer = await fs2.readFile(cookieDbPath);
24203
+ if (!buffer.slice(0, 4).equals(magicBytes)) {
24204
+ throw new Error("Not a cookie file");
24205
+ }
24206
+ const count = buffer.readUInt32BE(4);
24207
+ const cookies = [];
24208
+ let offset = 8;
24209
+ for (let i = 0;i < count; i++) {
24210
+ const pageSize = buffer.readUInt32BE(offset);
24211
+ offset += 4;
24212
+ const page = buffer.slice(offset, offset + pageSize);
24213
+ offset += pageSize;
24214
+ if (!page.slice(0, 4).equals(Buffer.from([0, 0, 1, 0]))) {
24215
+ throw new Error("Bad page header");
24216
+ }
24217
+ const cookieCount = page.readUInt32LE(4);
24218
+ let pageOffset = 8;
24219
+ for (let j2 = 0;j2 < cookieCount; j2++) {
24220
+ const cookieOffset = page.readUInt32LE(pageOffset);
24221
+ pageOffset += 4;
24222
+ const cookieLength = page.readUInt32LE(cookieOffset);
24223
+ const cookie = page.slice(cookieOffset, cookieOffset + cookieLength);
24224
+ const flags = cookie.readUInt32LE(8);
24225
+ const urlOffset = cookie.readUInt32LE(16);
24226
+ const nameOffset = cookie.readUInt32LE(20);
24227
+ const valueOffset = cookie.readUInt32LE(28);
24228
+ const expiry = cookie.readDoubleLE(40) + 978307200;
24229
+ const url = cookie.slice(urlOffset, nameOffset).toString("utf8").replace(/\0/g, "");
24230
+ const name = cookie.slice(nameOffset, valueOffset).toString("utf8").replace(/\0/g, "");
24231
+ const value = cookie.slice(valueOffset, cookie.length).toString("utf8").replace(/\0/g, "");
24232
+ cookies.push({
24233
+ domain: url,
24234
+ name,
24235
+ value: Buffer.from(value, "utf8"),
24236
+ expiry: new Date(expiry * 1000).getTime(),
24237
+ meta: {
24238
+ path: cookie.slice(cookie.readUInt32LE(24), valueOffset).toString("utf8").replace(/\0/g, ""),
24239
+ httpOnly: (flags & 4) === 4,
24240
+ secure: (flags & 1) === 1
24492
24241
  }
24493
- }
24494
- this[INTERNALS$1] = {
24495
- url: opts.url,
24496
- status,
24497
- statusText: opts.statusText || STATUS_CODES[status],
24498
- headers,
24499
- counter: opts.counter
24500
- };
24242
+ });
24501
24243
  }
24502
- get url() {
24503
- return this[INTERNALS$1].url || "";
24244
+ if (!page.slice(cookieCount * 4 + 8, cookieCount * 4 + 12).equals(Buffer.from([0, 0, 0, 0]))) {
24245
+ throw new Error("Bad page trailer");
24504
24246
  }
24505
- get status() {
24506
- return this[INTERNALS$1].status;
24247
+ }
24248
+ return cookies;
24249
+ };
24250
+
24251
+ // src/browsers/safari/SafariCookieQueryStrategy.ts
24252
+ class SafariCookieQueryStrategy {
24253
+ browserName = "Safari";
24254
+ async queryCookies(name, domain) {
24255
+ const homeDir = process.env.HOME;
24256
+ if (!homeDir) {
24257
+ throw new Error("HOME environment variable is not set");
24507
24258
  }
24508
- get ok() {
24509
- return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
24259
+ const cookieDbPath = join4(homeDir, "Library", "Cookies", "Cookies.binarycookies");
24260
+ try {
24261
+ const cookies = await decodeBinaryCookies(cookieDbPath);
24262
+ const filteredCookies = cookies.filter((cookie) => cookie.name === name && cookie.domain.includes(domain));
24263
+ const exportedCookies = filteredCookies.map((cookie) => ({
24264
+ domain: cookie.domain,
24265
+ name: cookie.name,
24266
+ value: cookie.value.toString("utf8")
24267
+ }));
24268
+ return exportedCookies;
24269
+ } catch (e) {
24270
+ console.error(`Error decoding ${cookieDbPath}`, e);
24271
+ return [];
24510
24272
  }
24511
- get redirected() {
24512
- return this[INTERNALS$1].counter > 0;
24273
+ }
24274
+ }
24275
+
24276
+ // src/browsers/CompositeCookieQueryStrategy.ts
24277
+ var import_lru_cache = __toESM(require_lru_cache(), 1);
24278
+ var import_lodash5 = __toESM(require_lodash(), 1);
24279
+ var cache = new import_lru_cache.default({
24280
+ ttl: 1e4,
24281
+ max: 10
24282
+ });
24283
+
24284
+ class CompositeCookieQueryStrategy {
24285
+ browserName = "all";
24286
+ strategies;
24287
+ constructor() {
24288
+ this.strategies = [
24289
+ ChromeCookieQueryStrategy,
24290
+ FirefoxCookieQueryStrategy,
24291
+ SafariCookieQueryStrategy
24292
+ ].map((Strategy) => new Strategy);
24293
+ }
24294
+ async queryCookies(name, domain) {
24295
+ const key = `${name}:${domain}`;
24296
+ logger_default.info(`Querying cookies for name: ${name}, domain: ${domain}`);
24297
+ if (cache.has(key)) {
24298
+ const cached = cache.get(key);
24299
+ if (cached) {
24300
+ logger_default.info(`Cache hit for key: ${key}, returning ${cached.length} cookies`);
24301
+ return cached;
24302
+ }
24513
24303
  }
24514
- get statusText() {
24515
- return this[INTERNALS$1].statusText;
24304
+ const results = await flatMapAsync(this.strategies, async (strategy) => {
24305
+ try {
24306
+ const cookies = await strategy.queryCookies(name, domain);
24307
+ return cookies.map((cookie) => import_lodash5.merge(cookie, {
24308
+ meta: {
24309
+ browser: strategy.browserName
24310
+ }
24311
+ }));
24312
+ } catch (e) {
24313
+ logger_default.error(`Error querying cookies for ${name} on ${domain} using ${strategy.browserName}`, e);
24314
+ return [];
24315
+ }
24316
+ });
24317
+ cache.set(key, results);
24318
+ logger_default.info(`Query result size for key: ${key} is ${results.length} cookies`);
24319
+ return results;
24320
+ }
24321
+ }
24322
+
24323
+ // src/isValidJwt.ts
24324
+ var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
24325
+ function isValidJwt(token) {
24326
+ try {
24327
+ const result = import_jsonwebtoken.default.decode(token, { complete: true });
24328
+ if (parsedArgs.verbose && result) {
24329
+ console.debug(result);
24516
24330
  }
24517
- get headers() {
24518
- return this[INTERNALS$1].headers;
24331
+ const payload = result?.payload;
24332
+ if (payload) {
24333
+ const exp = payload.exp;
24334
+ if (exp) {
24335
+ const now = new Date().getTime() / 1000;
24336
+ if (now > exp) {
24337
+ return false;
24338
+ }
24339
+ }
24519
24340
  }
24520
- clone() {
24521
- return new Response(clone(this), {
24522
- url: this.url,
24523
- status: this.status,
24524
- statusText: this.statusText,
24525
- headers: this.headers,
24526
- ok: this.ok,
24527
- redirected: this.redirected
24528
- });
24341
+ return true;
24342
+ } catch (err) {
24343
+ return false;
24344
+ }
24345
+ }
24346
+
24347
+ // src/queryCookies.ts
24348
+ async function queryCookies({ name, domain }, options) {
24349
+ const strategy = options?.strategy || new CompositeCookieQueryStrategy;
24350
+ logger_default.debug(`Using strategy: ${strategy.browserName}`);
24351
+ const results = await strategy.queryCookies(name, domain);
24352
+ const allCookies = import_lodash6.uniqBy(results, JSON.stringify);
24353
+ const filterCookies = (cookies, filterFn) => {
24354
+ const filteredCookies = [];
24355
+ for (const cookie of cookies) {
24356
+ if (filterFn(cookie.value)) {
24357
+ filteredCookies.push(cookie);
24358
+ }
24359
+ }
24360
+ return filteredCookies;
24361
+ };
24362
+ const jwtCookies = parsedArgs["require-jwt"] ? filterCookies(allCookies, isValidJwt) : allCookies;
24363
+ return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
24364
+ }
24365
+
24366
+ // src/getCookie.ts
24367
+ async function getCookie(params) {
24368
+ const cookies = await queryCookies(params, {
24369
+ strategy: queryStrategy
24370
+ });
24371
+ if (Array.isArray(cookies) && cookies.length > 0) {
24372
+ return cookies.find((cookie) => cookie != null);
24373
+ } else {
24374
+ throw new Error("Cookie not found");
24375
+ }
24376
+ }
24377
+ var queryStrategy = new CompositeCookieQueryStrategy;
24378
+
24379
+ // src/getChromeCookie.ts
24380
+ async function getChromeCookie(params) {
24381
+ const cookies = await queryCookies(params, {
24382
+ strategy: new ChromeCookieQueryStrategy
24383
+ });
24384
+ if (cookies.length === 0) {
24385
+ throw new Error("Cookie not found");
24386
+ }
24387
+ return cookies.find(isExportedCookie);
24388
+ }
24389
+
24390
+ // src/getFirefoxCookie.ts
24391
+ async function getFirefoxCookie(params) {
24392
+ const cookies = await queryCookies(params, {
24393
+ strategy: new FirefoxCookieQueryStrategy
24394
+ });
24395
+ if (!Array.isArray(cookies) || cookies.length === 0) {
24396
+ throw new Error("Cookie not found");
24397
+ }
24398
+ const validCookie = cookies.find((cookie) => cookie != null);
24399
+ if (!validCookie) {
24400
+ throw new Error("Cookie not found");
24401
+ }
24402
+ return validCookie;
24403
+ }
24404
+
24405
+ // src/getGroupedRenderedCookies.ts
24406
+ var import_lodash10 = __toESM(require_lodash(), 1);
24407
+
24408
+ // src/resultsRendered.ts
24409
+ var import_lodash7 = __toESM(require_lodash(), 1);
24410
+ var sortResults = function(results) {
24411
+ return import_lodash7.orderBy(results, ["name", "expiry"], ["asc", "desc"]);
24412
+ };
24413
+ var getUniqueResults = function(results) {
24414
+ return import_lodash7.uniqBy(results, "name");
24415
+ };
24416
+ var formatResults = function(results) {
24417
+ const resultStrings = [];
24418
+ for (const result of results) {
24419
+ resultStrings.push(`${result.name}=${result.value}`);
24420
+ }
24421
+ return resultStrings.join("; ");
24422
+ };
24423
+ function resultsRendered(results) {
24424
+ const orderedResults = sortResults(results);
24425
+ const uniqueResults = getUniqueResults(orderedResults);
24426
+ return formatResults(uniqueResults);
24427
+ }
24428
+ // src/cookieQueryOptions.ts
24429
+ var import_lodash8 = __toESM(require_lodash(), 1);
24430
+ function mergedWithDefaults(options) {
24431
+ const mergedOptions = import_lodash8.merge({}, defaultCookieQueryOptions, options);
24432
+ return mergedOptions;
24433
+ }
24434
+ var defaultCookieQueryOptions = {
24435
+ strategy: new CompositeCookieQueryStrategy,
24436
+ limit: undefined,
24437
+ removeExpired: undefined
24438
+ };
24439
+
24440
+ // src/processBeforeReturn.ts
24441
+ var import_lodash9 = __toESM(require_lodash(), 1);
24442
+ function processBeforeReturn(cookies, options) {
24443
+ let processedCookies = cookies;
24444
+ if (options && options.removeExpired) {
24445
+ const now = Date.now();
24446
+ processedCookies = processedCookies.filter((c2) => {
24447
+ const expiry = c2.expiry;
24448
+ return expiry === undefined || expiry === "Infinity" || expiry.getTime() > now;
24449
+ });
24450
+ }
24451
+ if (options && options.limit) {
24452
+ processedCookies = processedCookies.slice(0, options.limit);
24453
+ }
24454
+ return import_lodash9.uniqBy(processedCookies, (cookie) => JSON.stringify(cookie));
24455
+ }
24456
+
24457
+ // src/comboQueryCookieSpec.ts
24458
+ async function comboQueryCookieSpec(cookieSpec, options) {
24459
+ const optsWithDefaults = mergedWithDefaults(options);
24460
+ const queryFn = async (cs) => queryCookies(cs, optsWithDefaults);
24461
+ let cookies;
24462
+ if (Array.isArray(cookieSpec)) {
24463
+ cookies = await flatMapAsync(cookieSpec, queryFn);
24464
+ } else {
24465
+ cookies = await queryFn(cookieSpec);
24466
+ }
24467
+ return processBeforeReturn(cookies, options);
24468
+ }
24469
+
24470
+ // src/getGroupedRenderedCookies.ts
24471
+ async function getGroupedRenderedCookies(cookieSpec) {
24472
+ const cookies = await fetchCookies(cookieSpec);
24473
+ const groupedByFile = groupCookiesByFile(cookies);
24474
+ return renderGroupedCookies(groupedByFile);
24475
+ }
24476
+ async function fetchCookies(cookieSpec) {
24477
+ const cookies = await comboQueryCookieSpec(cookieSpec);
24478
+ if (cookies.length === 0) {
24479
+ throw new Error("Cookie not found");
24480
+ }
24481
+ return cookies;
24482
+ }
24483
+ var groupCookiesByFile = function(cookies) {
24484
+ return import_lodash10.groupBy(cookies, (r2) => r2.meta?.file);
24485
+ };
24486
+ var renderGroupedCookies = function(groupedByFile) {
24487
+ const renderedResults = [];
24488
+ for (const file in groupedByFile) {
24489
+ if (groupedByFile.hasOwnProperty(file)) {
24490
+ const results = groupedByFile[file];
24491
+ renderedResults.push(resultsRendered(results));
24529
24492
  }
24530
24493
  }
24531
- Body.mixIn(Response.prototype);
24532
- Object.defineProperties(Response.prototype, {
24533
- url: { enumerable: true },
24534
- status: { enumerable: true },
24535
- ok: { enumerable: true },
24536
- redirected: { enumerable: true },
24537
- statusText: { enumerable: true },
24538
- headers: { enumerable: true },
24539
- clone: { enumerable: true }
24540
- });
24541
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
24542
- value: "Response",
24543
- writable: false,
24544
- enumerable: false,
24545
- configurable: true
24494
+ return renderedResults;
24495
+ };
24496
+
24497
+ // src/getMergedRenderedCookies.ts
24498
+ async function getMergedRenderedCookies(cookieSpec, strategy = new CompositeCookieQueryStrategy) {
24499
+ const cookies = await comboQueryCookieSpec(cookieSpec, {
24500
+ strategy
24546
24501
  });
24547
- var INTERNALS$2 = Symbol("Request internals");
24548
- var URL2 = Url.URL || whatwgUrl.URL;
24549
- var parse_url = Url.parse;
24550
- var format_url = Url.format;
24551
- var streamDestructionSupported = "destroy" in Stream.Readable.prototype;
24502
+ if (cookies.length > 0) {
24503
+ return resultsRendered(cookies);
24504
+ }
24505
+ return "";
24506
+ }
24552
24507
 
24553
- class Request {
24554
- constructor(input) {
24555
- let init2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24556
- let parsedURL;
24557
- if (!isRequest(input)) {
24558
- if (input && input.href) {
24559
- parsedURL = parseURL(input.href);
24560
- } else {
24561
- parsedURL = parseURL(`${input}`);
24562
- }
24563
- input = {};
24564
- } else {
24565
- parsedURL = parseURL(input.url);
24566
- }
24567
- let method = init2.method || input.method || "GET";
24568
- method = method.toUpperCase();
24569
- if ((init2.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
24570
- throw new TypeError("Request with GET/HEAD method cannot have body");
24571
- }
24572
- let inputBody = init2.body != null ? init2.body : isRequest(input) && input.body !== null ? clone(input) : null;
24573
- Body.call(this, inputBody, {
24574
- timeout: init2.timeout || input.timeout || 0,
24575
- size: init2.size || input.size || 0
24576
- });
24577
- const headers = new Headers(init2.headers || input.headers || {});
24578
- if (inputBody != null && !headers.has("Content-Type")) {
24579
- const contentType = extractContentType(inputBody);
24580
- if (contentType) {
24581
- headers.append("Content-Type", contentType);
24582
- }
24583
- }
24584
- let signal = isRequest(input) ? input.signal : null;
24585
- if ("signal" in init2)
24586
- signal = init2.signal;
24587
- if (signal != null && !isAbortSignal(signal)) {
24588
- throw new TypeError("Expected signal to be an instanceof AbortSignal");
24589
- }
24590
- this[INTERNALS$2] = {
24591
- method,
24592
- redirect: init2.redirect || input.redirect || "follow",
24593
- headers,
24594
- parsedURL,
24595
- signal
24596
- };
24597
- this.follow = init2.follow !== undefined ? init2.follow : input.follow !== undefined ? input.follow : 20;
24598
- this.compress = init2.compress !== undefined ? init2.compress : input.compress !== undefined ? input.compress : true;
24599
- this.counter = init2.counter || input.counter || 0;
24600
- this.agent = init2.agent || input.agent;
24508
+ // src/fetchWithCookies.ts
24509
+ var import_cross_fetch = __toESM(require_node_ponyfill(), 1);
24510
+ var import_lodash12 = __toESM(require_lodash(), 1);
24511
+
24512
+ // node_modules/destr/dist/index.mjs
24513
+ var jsonParseTransform = function(key, value) {
24514
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
24515
+ warnKeyDropped(key);
24516
+ return;
24517
+ }
24518
+ return value;
24519
+ };
24520
+ var warnKeyDropped = function(key) {
24521
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
24522
+ };
24523
+ var destr = function(value, options = {}) {
24524
+ if (typeof value !== "string") {
24525
+ return value;
24526
+ }
24527
+ const _value = value.trim();
24528
+ if (value[0] === '"' && value.at(-1) === '"' && !value.includes("\\")) {
24529
+ return _value.slice(1, -1);
24530
+ }
24531
+ if (_value.length <= 9) {
24532
+ const _lval = _value.toLowerCase();
24533
+ if (_lval === "true") {
24534
+ return true;
24601
24535
  }
24602
- get method() {
24603
- return this[INTERNALS$2].method;
24536
+ if (_lval === "false") {
24537
+ return false;
24604
24538
  }
24605
- get url() {
24606
- return format_url(this[INTERNALS$2].parsedURL);
24539
+ if (_lval === "undefined") {
24540
+ return;
24607
24541
  }
24608
- get headers() {
24609
- return this[INTERNALS$2].headers;
24542
+ if (_lval === "null") {
24543
+ return null;
24610
24544
  }
24611
- get redirect() {
24612
- return this[INTERNALS$2].redirect;
24545
+ if (_lval === "nan") {
24546
+ return Number.NaN;
24613
24547
  }
24614
- get signal() {
24615
- return this[INTERNALS$2].signal;
24548
+ if (_lval === "infinity") {
24549
+ return Number.POSITIVE_INFINITY;
24616
24550
  }
24617
- clone() {
24618
- return new Request(this);
24551
+ if (_lval === "-infinity") {
24552
+ return Number.NEGATIVE_INFINITY;
24619
24553
  }
24620
24554
  }
24621
- Body.mixIn(Request.prototype);
24622
- Object.defineProperty(Request.prototype, Symbol.toStringTag, {
24623
- value: "Request",
24624
- writable: false,
24625
- enumerable: false,
24626
- configurable: true
24627
- });
24628
- Object.defineProperties(Request.prototype, {
24629
- method: { enumerable: true },
24630
- url: { enumerable: true },
24631
- headers: { enumerable: true },
24632
- redirect: { enumerable: true },
24633
- clone: { enumerable: true },
24634
- signal: { enumerable: true }
24635
- });
24636
- AbortError.prototype = Object.create(Error.prototype);
24637
- AbortError.prototype.constructor = AbortError;
24638
- AbortError.prototype.name = "AbortError";
24639
- var URL$1 = Url.URL || whatwgUrl.URL;
24640
- var PassThrough$1 = Stream.PassThrough;
24641
- var isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
24642
- const orig = new URL$1(original).hostname;
24643
- const dest = new URL$1(destination).hostname;
24644
- return orig === dest || orig[orig.length - dest.length - 1] === "." && orig.endsWith(dest);
24645
- };
24646
- var isSameProtocol = function isSameProtocol(destination, original) {
24647
- const orig = new URL$1(original).protocol;
24648
- const dest = new URL$1(destination).protocol;
24649
- return orig === dest;
24650
- };
24651
- fetch.isRedirect = function(code) {
24652
- return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
24653
- };
24654
- fetch.Promise = global.Promise;
24655
- module.exports = exports = fetch;
24656
- Object.defineProperty(exports, "__esModule", { value: true });
24657
- exports.default = exports;
24658
- exports.Headers = Headers;
24659
- exports.Request = Request;
24660
- exports.Response = Response;
24661
- exports.FetchError = FetchError;
24662
- exports.AbortError = AbortError;
24663
- });
24664
-
24665
- // node_modules/cross-fetch/dist/node-ponyfill.js
24666
- var require_node_ponyfill = __commonJS((exports, module) => {
24667
- var nodeFetch = require_lib3();
24668
- var realFetch = nodeFetch.default || nodeFetch;
24669
- var fetch = function(url, options) {
24670
- if (/^\/\//.test(url)) {
24671
- url = "https:" + url;
24672
- }
24673
- return realFetch.call(this, url, options);
24674
- };
24675
- fetch.ponyfill = true;
24676
- module.exports = exports = fetch;
24677
- exports.fetch = fetch;
24678
- exports.Headers = nodeFetch.Headers;
24679
- exports.Request = nodeFetch.Request;
24680
- exports.Response = nodeFetch.Response;
24681
- exports.default = fetch;
24682
- });
24683
-
24684
- // node_modules/destr/dist/index.mjs
24685
- var jsonParseTransform, warnKeyDropped, destr, suspectProtoRx, suspectConstructorRx, JsonSigRx;
24686
- var init_dist2 = __esm(() => {
24687
- jsonParseTransform = function(key, value) {
24688
- if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
24689
- warnKeyDropped(key);
24690
- return;
24555
+ if (!JsonSigRx.test(value)) {
24556
+ if (options.strict) {
24557
+ throw new SyntaxError("[destr] Invalid JSON");
24691
24558
  }
24692
24559
  return value;
24693
- };
24694
- warnKeyDropped = function(key) {
24695
- console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
24696
- };
24697
- destr = function(value, options = {}) {
24698
- if (typeof value !== "string") {
24699
- return value;
24700
- }
24701
- const _value = value.trim();
24702
- if (value[0] === '"' && value.at(-1) === '"' && !value.includes("\\")) {
24703
- return _value.slice(1, -1);
24704
- }
24705
- if (_value.length <= 9) {
24706
- const _lval = _value.toLowerCase();
24707
- if (_lval === "true") {
24708
- return true;
24709
- }
24710
- if (_lval === "false") {
24711
- return false;
24712
- }
24713
- if (_lval === "undefined") {
24714
- return;
24715
- }
24716
- if (_lval === "null") {
24717
- return null;
24718
- }
24719
- if (_lval === "nan") {
24720
- return Number.NaN;
24721
- }
24722
- if (_lval === "infinity") {
24723
- return Number.POSITIVE_INFINITY;
24724
- }
24725
- if (_lval === "-infinity") {
24726
- return Number.NEGATIVE_INFINITY;
24727
- }
24728
- }
24729
- if (!JsonSigRx.test(value)) {
24560
+ }
24561
+ try {
24562
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
24730
24563
  if (options.strict) {
24731
- throw new SyntaxError("[destr] Invalid JSON");
24564
+ throw new Error("[destr] Possible prototype pollution");
24732
24565
  }
24733
- return value;
24566
+ return JSON.parse(value, jsonParseTransform);
24734
24567
  }
24735
- try {
24736
- if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
24737
- if (options.strict) {
24738
- throw new Error("[destr] Possible prototype pollution");
24739
- }
24740
- return JSON.parse(value, jsonParseTransform);
24741
- }
24742
- return JSON.parse(value);
24743
- } catch (error) {
24744
- if (options.strict) {
24745
- throw error;
24746
- }
24747
- return value;
24568
+ return JSON.parse(value);
24569
+ } catch (error) {
24570
+ if (options.strict) {
24571
+ throw error;
24748
24572
  }
24749
- };
24750
- suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
24751
- suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
24752
- JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
24753
- });
24573
+ return value;
24574
+ }
24575
+ };
24576
+ var suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
24577
+ var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
24578
+ var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
24754
24579
 
24755
24580
  // src/cookieSpecsFromUrl.ts
24581
+ var import_lodash11 = __toESM(require_lodash(), 1);
24756
24582
  function cookieSpecsFromUrl(url) {
24757
24583
  if (!url || url === "") {
24758
24584
  return [];
@@ -24763,40 +24589,31 @@ function cookieSpecsFromUrl(url) {
24763
24589
  const cookieSpecs = createCookieSpecs(urlObj.hostname, topLevelDomain);
24764
24590
  return import_lodash11.uniqBy(cookieSpecs, (spec) => `${spec.name}:${spec.domain}`);
24765
24591
  }
24766
- var import_lodash11, parseUrl, splitHostname, getTopLevelDomain, createCookieSpecs;
24767
- var init_cookieSpecsFromUrl = __esm(() => {
24768
- import_lodash11 = __toESM(require_lodash(), 1);
24769
- parseUrl = function(url) {
24770
- return typeof url === "string" ? new URL(url) : url;
24771
- };
24772
- splitHostname = function(hostname) {
24773
- return hostname.split(".");
24774
- };
24775
- getTopLevelDomain = function(hostnameParts) {
24776
- return hostnameParts.slice(-2).join(".");
24777
- };
24778
- createCookieSpecs = function(hostname, topLevelDomain) {
24779
- return [
24780
- { name: "%", domain: `%.${topLevelDomain}` },
24781
- { name: "%", domain: hostname },
24782
- { name: "%", domain: topLevelDomain }
24783
- ];
24784
- };
24785
- });
24592
+ var parseUrl = function(url) {
24593
+ return typeof url === "string" ? new URL(url) : url;
24594
+ };
24595
+ var splitHostname = function(hostname) {
24596
+ return hostname.split(".");
24597
+ };
24598
+ var getTopLevelDomain = function(hostnameParts) {
24599
+ return hostnameParts.slice(-2).join(".");
24600
+ };
24601
+ var createCookieSpecs = function(hostname, topLevelDomain) {
24602
+ return [
24603
+ { name: "%", domain: `%.${topLevelDomain}` },
24604
+ { name: "%", domain: hostname },
24605
+ { name: "%", domain: topLevelDomain }
24606
+ ];
24607
+ };
24786
24608
 
24787
24609
  // src/fetchWithCookies.ts
24788
- var exports_fetchWithCookies = {};
24789
- __export(exports_fetchWithCookies, {
24790
- fetchWithCookies: () => {
24791
- {
24792
- return fetchWithCookies;
24793
- }
24794
- }
24795
- });
24796
24610
  async function fetchWithCookies(url, options = {}, fetch = import_cross_fetch.fetch, originalRequest) {
24797
24611
  const fetcher = new FetchWithCookies(fetch, userAgent);
24798
24612
  return fetcher.fetchWithCookies(url, options, originalRequest);
24799
24613
  }
24614
+ if (typeof import_cross_fetch.fetch !== "function") {
24615
+ throw new Error("fetch is not a function");
24616
+ }
24800
24617
 
24801
24618
  class UserAgentBuilder {
24802
24619
  platform;
@@ -24813,6 +24630,7 @@ class UserAgentBuilder {
24813
24630
  return `${this.platform} ${this.engine} ${this.browser} ${this.layout}`;
24814
24631
  }
24815
24632
  }
24633
+ var userAgent = new UserAgentBuilder().build();
24816
24634
 
24817
24635
  class FetchWithCookies {
24818
24636
  fetch;
@@ -24884,31 +24702,11 @@ class FetchWithCookies {
24884
24702
  }
24885
24703
  }
24886
24704
  }
24887
- var import_cross_fetch, import_lodash12, userAgent;
24888
- var init_fetchWithCookies = __esm(() => {
24889
- import_cross_fetch = __toESM(require_node_ponyfill(), 1);
24890
- import_lodash12 = __toESM(require_lodash(), 1);
24891
- init_dist2();
24892
- init_getMergedRenderedCookies();
24893
- init_cookieSpecsFromUrl();
24894
- if (typeof import_cross_fetch.fetch !== "function") {
24895
- throw new Error("fetch is not a function");
24896
- }
24897
- userAgent = new UserAgentBuilder().build();
24898
- });
24899
-
24900
- // src/index.ts
24901
- var getCookie2 = () => Promise.resolve().then(() => (init_getCookie(), exports_getCookie)).then((module) => module.getCookie);
24902
- var getChromeCookie2 = () => Promise.resolve().then(() => (init_getChromeCookie(), exports_getChromeCookie)).then((module) => module.getChromeCookie);
24903
- var getFirefoxCookie2 = () => Promise.resolve().then(() => (init_getFirefoxCookie(), exports_getFirefoxCookie)).then((module) => module.getFirefoxCookie);
24904
- var getGroupedRenderedCookies2 = () => Promise.resolve().then(() => (init_getGroupedRenderedCookies(), exports_getGroupedRenderedCookies)).then((module) => module.getGroupedRenderedCookies);
24905
- var getMergedRenderedCookies3 = () => Promise.resolve().then(() => (init_getMergedRenderedCookies(), exports_getMergedRenderedCookies)).then((module) => module.getMergedRenderedCookies);
24906
- var fetchWithCookies2 = () => Promise.resolve().then(() => (init_fetchWithCookies(), exports_fetchWithCookies)).then((module) => module.fetchWithCookies);
24907
24705
  export {
24908
- getMergedRenderedCookies3 as getMergedRenderedCookies,
24909
- getGroupedRenderedCookies2 as getGroupedRenderedCookies,
24910
- getFirefoxCookie2 as getFirefoxCookie,
24911
- getCookie2 as getCookie,
24912
- getChromeCookie2 as getChromeCookie,
24913
- fetchWithCookies2 as fetchWithCookies
24706
+ getMergedRenderedCookies,
24707
+ getGroupedRenderedCookies,
24708
+ getFirefoxCookie,
24709
+ getCookie,
24710
+ getChromeCookie,
24711
+ fetchWithCookies
24914
24712
  };