@mherod/get-cookie 2.0.0-rc.2 → 2.0.0-rc.4
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 +145 -19
- package/package-lock.json +12055 -0
- package/package.json +5 -2
- package/src/CookieRow.ts +1 -1
- package/src/CookieSpec.ts +2 -2
- package/src/CookieStore.ts +10 -0
- package/src/ExportedCookie.ts +1 -1
- package/src/FetchResponse.ts +2 -0
- package/src/IsCookieRow.ts +1 -1
- package/src/IsExportedCookie.ts +1 -1
- package/src/SpecialCases.ts +1 -1
- package/src/StringToRegex.ts +6 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +16 -7
- package/src/browsers/CompositeCookieQueryStrategy.ts +14 -4
- package/src/browsers/CookieQueryStrategy.ts +2 -1
- package/src/browsers/CookieStoreQueryStrategy.ts +88 -0
- package/src/browsers/FirefoxCookieQueryStrategy.ts +5 -3
- package/src/browsers/SafariCookieQueryStrategy.ts +3 -1
- package/src/cli.ts +84 -88
- package/src/doSqliteQuery1.ts +1 -1
- package/src/fetchWithCookies.ts +59 -19
- package/src/getGroupedRenderedCookies.ts +2 -2
- package/src/index.ts +3 -2
- package/src/queryCookies.ts +2 -2
- package/src/resultsRendered.ts +1 -1
- package/src/unpackHeaders.ts +7 -4
- package/dist/cli.js +0 -3
- package/dist/cli.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/module.js +0 -586
- package/dist/module.js.map +0 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var $7oI3p$lodash = require("lodash");
|
|
3
3
|
var $7oI3p$lrucache = require("lru-cache");
|
|
4
|
+
var $7oI3p$colorette = require("colorette");
|
|
4
5
|
var $7oI3p$fs = require("fs");
|
|
5
6
|
var $7oI3p$crypto = require("crypto");
|
|
6
7
|
var $7oI3p$path = require("path");
|
|
7
8
|
var $7oI3p$child_process = require("child_process");
|
|
8
9
|
var $7oI3p$sqlite3 = require("sqlite3");
|
|
10
|
+
var $7oI3p$toughcookie = require("tough-cookie");
|
|
11
|
+
var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
|
|
9
12
|
var $7oI3p$jsonwebtoken = require("jsonwebtoken");
|
|
10
13
|
var $7oI3p$crossfetch = require("cross-fetch");
|
|
11
14
|
var $7oI3p$destr = require("destr");
|
|
@@ -38,6 +41,7 @@ $parcel$export(module.exports, "getFirefoxCookie", () => $cd1ba0160120c006$expor
|
|
|
38
41
|
$parcel$export(module.exports, "getChromeCookie", () => $cd1ba0160120c006$export$e5637297e9eb6f2e);
|
|
39
42
|
$parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
|
|
40
43
|
$parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
|
|
44
|
+
$parcel$export(module.exports, "stringToRegex", () => $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb);
|
|
41
45
|
|
|
42
46
|
const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
|
|
43
47
|
(0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
|
|
@@ -180,7 +184,16 @@ function $d66f40b581ba8bfa$export$963c8d651337e4a4(obj) {
|
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
|
|
187
|
+
function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
188
|
+
const s1 = s.replaceAll(/\./gi, ".");
|
|
189
|
+
const s2 = s1.replace(/%/g, ".*");
|
|
190
|
+
const s3 = s2.replace(/\*/g, ".*");
|
|
191
|
+
return new RegExp(s3);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
183
195
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
196
|
+
browserName = "Chrome";
|
|
184
197
|
async queryCookies(name, domain) {
|
|
185
198
|
if (process.platform !== "darwin") throw new Error("This only works on macOS");
|
|
186
199
|
if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
|
|
@@ -259,15 +272,18 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
259
272
|
const wildcardRegexp = /^([*%])$/i;
|
|
260
273
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
261
274
|
const specifiedDomain = domain.match(wildcardRegexp) == null;
|
|
262
|
-
|
|
275
|
+
const wildcardDomain = domain.match(/[%*]/) != null;
|
|
276
|
+
const queryDomain = specifiedDomain && !wildcardDomain;
|
|
277
|
+
// if we have a wildcard domain, we need to use a regexp
|
|
278
|
+
if (specifiedName || queryDomain) {
|
|
263
279
|
sql += ` WHERE `;
|
|
264
280
|
if (specifiedName) {
|
|
265
281
|
sql += `name = '${name}'`;
|
|
266
|
-
if (
|
|
282
|
+
if (queryDomain) sql += ` AND `;
|
|
267
283
|
}
|
|
268
|
-
if (
|
|
284
|
+
if (queryDomain) sql += `host_key LIKE '${domain}';`;
|
|
269
285
|
}
|
|
270
|
-
|
|
286
|
+
const sqliteQuery1 = await (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
|
|
271
287
|
file: file,
|
|
272
288
|
sql: sql,
|
|
273
289
|
rowTransform: (row)=>{
|
|
@@ -278,6 +294,9 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
278
294
|
};
|
|
279
295
|
}
|
|
280
296
|
});
|
|
297
|
+
return sqliteQuery1.filter((row)=>{
|
|
298
|
+
return row.domain.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(domain)) != null;
|
|
299
|
+
});
|
|
281
300
|
}
|
|
282
301
|
async function $269fe42bfd555305$var$getChromePassword() {
|
|
283
302
|
return (0, $25b78d6746d4ad48$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
|
|
@@ -354,6 +373,7 @@ function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain
|
|
|
354
373
|
|
|
355
374
|
|
|
356
375
|
class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
|
|
376
|
+
browserName = "Firefox";
|
|
357
377
|
async queryCookies(name, domain) {
|
|
358
378
|
if (process.platform !== "darwin") throw new Error("This only works on macOS");
|
|
359
379
|
if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
|
|
@@ -423,6 +443,7 @@ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
|
|
|
423
443
|
|
|
424
444
|
|
|
425
445
|
class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 {
|
|
446
|
+
browserName = "Safari";
|
|
426
447
|
async queryCookies(name, domain) {
|
|
427
448
|
return [];
|
|
428
449
|
}
|
|
@@ -430,14 +451,92 @@ class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 {
|
|
|
430
451
|
|
|
431
452
|
|
|
432
453
|
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
var $53a3bcc99a05dfcf$require$FileCookieStore = $7oI3p$toughcookiefilestore.FileCookieStore;
|
|
458
|
+
const $53a3bcc99a05dfcf$export$6c62df16f2e9c7e8 = new $53a3bcc99a05dfcf$require$FileCookieStore(`${(0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3)["HOME"]}/cookie-star.json`);
|
|
459
|
+
const $53a3bcc99a05dfcf$export$928a906645f9d018 = new (0, $7oI3p$toughcookie.CookieJar)($53a3bcc99a05dfcf$export$6c62df16f2e9c7e8);
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
464
|
+
browserName = "internal";
|
|
465
|
+
async queryCookies(name, domain) {
|
|
466
|
+
const exportedCookies = [];
|
|
467
|
+
if (name.match(/[%*]/) || domain.match(/[%*]/)) {
|
|
468
|
+
const cookies = await this.#getAllCookies();
|
|
469
|
+
const allExportedCookies = cookies.map((cookie)=>{
|
|
470
|
+
return this.#extracted(cookie, {
|
|
471
|
+
name: name,
|
|
472
|
+
domain: domain
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
exportedCookies.push(...allExportedCookies);
|
|
476
|
+
}
|
|
477
|
+
if (name == "%" && domain == "%") return exportedCookies;
|
|
478
|
+
const path = "/";
|
|
479
|
+
if (domain != "%") {
|
|
480
|
+
const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
481
|
+
const url = new URL("https://" + domain1);
|
|
482
|
+
url.pathname = path;
|
|
483
|
+
const cookies1 = await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).getCookies(url.href);
|
|
484
|
+
const domainCookies = cookies1.map((cookie)=>{
|
|
485
|
+
return this.#extracted(cookie, {
|
|
486
|
+
domain: domain,
|
|
487
|
+
name: name
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
exportedCookies.push(...domainCookies);
|
|
491
|
+
}
|
|
492
|
+
if (name == "%") return exportedCookies;
|
|
493
|
+
const cookie = await (0, $53a3bcc99a05dfcf$export$6c62df16f2e9c7e8).findCookie(domain, path, name);
|
|
494
|
+
if (cookie) {
|
|
495
|
+
const singleCookie = this.#extracted(cookie, {
|
|
496
|
+
name: name,
|
|
497
|
+
domain: domain
|
|
498
|
+
});
|
|
499
|
+
return [
|
|
500
|
+
singleCookie
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
return exportedCookies.filter((cookie)=>{
|
|
504
|
+
return cookie.name.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(name)) && cookie.domain.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(domain));
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
#extracted(cookie, cookieSpec) {
|
|
508
|
+
return {
|
|
509
|
+
domain: cookie.domain ?? cookieSpec.domain,
|
|
510
|
+
name: cookie.key ?? cookieSpec.name,
|
|
511
|
+
value: cookie.value,
|
|
512
|
+
meta: {
|
|
513
|
+
file: "memory"
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
#getAllCookies() {
|
|
518
|
+
return new Promise((resolve, reject)=>{
|
|
519
|
+
// @ts-ignore
|
|
520
|
+
return (0, $53a3bcc99a05dfcf$export$6c62df16f2e9c7e8).getAllCookies((err, cookies)=>{
|
|
521
|
+
if (err) reject(err);
|
|
522
|
+
else resolve(cookies ?? []);
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
433
530
|
const $f72befa528c23ca7$var$cache = new (0, ($parcel$interopDefault($7oI3p$lrucache)))({
|
|
434
531
|
ttl: 2000,
|
|
435
532
|
max: 10
|
|
436
533
|
});
|
|
437
534
|
class $f72befa528c23ca7$export$2e2bcd8739ae039 {
|
|
535
|
+
browserName = "all";
|
|
438
536
|
#strategies;
|
|
439
537
|
constructor(){
|
|
440
538
|
this.#strategies = [
|
|
539
|
+
(0, $e4efb16e005540de$export$2e2bcd8739ae039),
|
|
441
540
|
(0, $269fe42bfd555305$export$2e2bcd8739ae039),
|
|
442
541
|
(0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039),
|
|
443
542
|
(0, $fad6f51bd5c7bae2$export$2e2bcd8739ae039),
|
|
@@ -446,13 +545,18 @@ class $f72befa528c23ca7$export$2e2bcd8739ae039 {
|
|
|
446
545
|
});
|
|
447
546
|
}
|
|
448
547
|
async queryCookies(name, domain) {
|
|
548
|
+
// domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
449
549
|
const key = `${name}:${domain}`;
|
|
450
550
|
const cached = $f72befa528c23ca7$var$cache.get(key);
|
|
451
551
|
if (cached) return cached;
|
|
552
|
+
console.log("Querying cookies:", name, domain);
|
|
452
553
|
const results = await Promise.all(this.#strategies.map(async (strategy)=>{
|
|
453
554
|
// @ts-ignore
|
|
454
555
|
const cookies = strategy.queryCookies(name, domain);
|
|
455
|
-
return cookies.catch(()=>
|
|
556
|
+
return cookies.catch((e)=>{
|
|
557
|
+
console.log((0, $7oI3p$colorette.red)(`Error querying ${strategy.browserName} cookies`), e);
|
|
558
|
+
return [];
|
|
559
|
+
});
|
|
456
560
|
}));
|
|
457
561
|
const flat = results.flat();
|
|
458
562
|
$f72befa528c23ca7$var$cache.set(`${name}:${domain}`, flat);
|
|
@@ -535,7 +639,8 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417(//
|
|
|
535
639
|
|
|
536
640
|
|
|
537
641
|
|
|
538
|
-
|
|
642
|
+
|
|
643
|
+
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
539
644
|
const defaultOptions = {
|
|
540
645
|
headers: {
|
|
541
646
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
|
|
@@ -547,10 +652,11 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}) {
|
|
|
547
652
|
const domain = url1.hostname.replace(/^.*(\.\w+\.\w+)$/, (match, p1)=>{
|
|
548
653
|
return `%${p1}`;
|
|
549
654
|
});
|
|
550
|
-
const
|
|
655
|
+
const cookieSpec = {
|
|
551
656
|
name: "%",
|
|
552
657
|
domain: domain
|
|
553
|
-
}
|
|
658
|
+
};
|
|
659
|
+
const cookies = await (0, $300d8b33187a203c$export$4d2e9997e2c23417)(cookieSpec).catch(()=>[]);
|
|
554
660
|
const cookie = cookies.pop();
|
|
555
661
|
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
|
|
556
662
|
headers: {
|
|
@@ -558,26 +664,45 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}) {
|
|
|
558
664
|
}
|
|
559
665
|
});
|
|
560
666
|
try {
|
|
561
|
-
const res = await
|
|
667
|
+
const res = await fetch(url2, newOptions1);
|
|
668
|
+
const headers = [];
|
|
669
|
+
res.headers.forEach((value, key)=>{
|
|
670
|
+
headers.push([
|
|
671
|
+
key,
|
|
672
|
+
value
|
|
673
|
+
]);
|
|
674
|
+
});
|
|
675
|
+
for (const [key, value] of headers)if (key === "set-cookie") await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
562
676
|
const newUrl = res.headers.get("location");
|
|
563
677
|
if (res.redirected || newUrl && newUrl !== url2) return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(newUrl, newOptions1);
|
|
564
678
|
const arrayBuffer1 = res.arrayBuffer();
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
679
|
+
async function arrayBuffer() {
|
|
680
|
+
return arrayBuffer1;
|
|
681
|
+
}
|
|
682
|
+
async function buffer() {
|
|
683
|
+
return arrayBuffer().then(Buffer.from);
|
|
684
|
+
}
|
|
685
|
+
async function text() {
|
|
686
|
+
return buffer().then((buffer)=>buffer.toString("utf8"));
|
|
687
|
+
}
|
|
688
|
+
async function json() {
|
|
689
|
+
return text().then((text)=>(0, ($parcel$interopDefault($7oI3p$destr)))(text));
|
|
690
|
+
}
|
|
691
|
+
async function formData() {
|
|
692
|
+
const urlSearchParams = await text().then((text)=>new URLSearchParams(text));
|
|
693
|
+
const formData = new FormData();
|
|
694
|
+
for (const [key, value] of urlSearchParams.entries())formData.append(key, value);
|
|
695
|
+
return formData;
|
|
696
|
+
}
|
|
697
|
+
const res1 = res;
|
|
570
698
|
const source2 = {
|
|
571
|
-
status: res.status,
|
|
572
|
-
statusText: res.statusText,
|
|
573
|
-
headers: res.headers,
|
|
574
699
|
arrayBuffer: arrayBuffer,
|
|
575
|
-
buffer: buffer,
|
|
576
700
|
text: text,
|
|
577
701
|
json: json,
|
|
702
|
+
buffer: buffer,
|
|
578
703
|
formData: formData
|
|
579
704
|
};
|
|
580
|
-
return (0, $7oI3p$lodash.merge)(
|
|
705
|
+
return (0, $7oI3p$lodash.merge)(res1, source2);
|
|
581
706
|
} catch (e) {
|
|
582
707
|
throw e;
|
|
583
708
|
}
|
|
@@ -593,6 +718,7 @@ var $3d7e27b54f670f46$exports = {};
|
|
|
593
718
|
var $6c197c88880e045c$exports = {};
|
|
594
719
|
|
|
595
720
|
|
|
721
|
+
|
|
596
722
|
async function $cd1ba0160120c006$export$4be65e66cfa2648a(params) {
|
|
597
723
|
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
598
724
|
if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
|