@mherod/get-cookie 2.0.0-rc.2 → 2.0.0-rc.21
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/.idea/runConfigurations/build.xml +12 -0
- package/.prettierignore +5 -0
- package/README.md +2 -2
- package/dist/cli.js +1110 -2
- package/dist/index.js +642 -231
- package/dist/index.js.map +1 -1
- package/dist/module.js +634 -224
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +246 -34
- package/dist/types.d.ts.map +1 -1
- package/package-lock.json +7539 -0
- package/package.json +24 -22
- package/src/CookieRow.ts +2 -1
- package/src/CookieSpec.ts +4 -2
- package/src/CookieStore.ts +27 -0
- package/src/ExportedCookie.ts +2 -1
- package/src/FetchResponse.ts +2 -0
- package/src/FileCookieStore.ts +170 -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/argv.ts +19 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +106 -24
- package/src/browsers/CompositeCookieQueryStrategy.ts +32 -8
- package/src/browsers/CookieQueryStrategy.ts +3 -1
- package/src/browsers/CookieStoreQueryStrategy.ts +99 -0
- package/src/browsers/FirefoxCookieQueryStrategy.ts +57 -9
- package/src/browsers/SafariCookieQueryStrategy.ts +4 -1
- package/src/cli.ts +101 -93
- package/src/comboQueryCookieSpec.ts +24 -0
- package/src/cookieSpecsFromUrl.ts +26 -0
- package/src/doSqliteQuery1Params.ts +8 -0
- package/src/fetchWithCookies.ts +131 -40
- package/src/findAllFiles.ts +5 -9
- package/src/getChromeCookie.ts +19 -0
- package/src/getCookie.ts +19 -0
- package/src/getFirefoxCookie.ts +19 -0
- package/src/getGroupedRenderedCookies.ts +12 -25
- package/src/getMergedRenderedCookies.ts +14 -0
- package/src/index.ts +13 -52
- package/src/isValidJwt.ts +2 -2
- package/src/queryCookies.ts +16 -12
- package/src/resultsRendered.ts +7 -4
- package/src/unpackHeaders.ts +7 -4
- package/src/utils.ts +0 -25
- package/tsconfig.json +11 -15
- package/.github/dependabot.yml +0 -6
- package/dist/cli.js.map +0 -1
- package/src/doSqliteQuery1.ts +0 -51
|
@@ -2,8 +2,12 @@ import ChromeCookieQueryStrategy from "./ChromeCookieQueryStrategy";
|
|
|
2
2
|
import FirefoxCookieQueryStrategy from "./FirefoxCookieQueryStrategy";
|
|
3
3
|
import SafariCookieQueryStrategy from "./SafariCookieQueryStrategy";
|
|
4
4
|
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
5
|
-
import
|
|
5
|
+
import ExportedCookie from "../ExportedCookie";
|
|
6
6
|
import LRUCache from "lru-cache";
|
|
7
|
+
import CookieStoreQueryStrategy from "./CookieStoreQueryStrategy";
|
|
8
|
+
import { red } from "colorette";
|
|
9
|
+
import { merge } from "lodash";
|
|
10
|
+
import { parsedArgs } from "../argv";
|
|
7
11
|
|
|
8
12
|
const cache = new LRUCache<string, ExportedCookie[]>({
|
|
9
13
|
ttl: 1000 * 2,
|
|
@@ -13,10 +17,13 @@ const cache = new LRUCache<string, ExportedCookie[]>({
|
|
|
13
17
|
export default class CompositeCookieQueryStrategy
|
|
14
18
|
implements CookieQueryStrategy
|
|
15
19
|
{
|
|
20
|
+
browserName = "all";
|
|
21
|
+
|
|
16
22
|
#strategies;
|
|
17
23
|
|
|
18
24
|
constructor() {
|
|
19
25
|
this.#strategies = [
|
|
26
|
+
CookieStoreQueryStrategy,
|
|
20
27
|
ChromeCookieQueryStrategy,
|
|
21
28
|
FirefoxCookieQueryStrategy,
|
|
22
29
|
SafariCookieQueryStrategy,
|
|
@@ -26,19 +33,36 @@ export default class CompositeCookieQueryStrategy
|
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
36
|
+
// domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
29
37
|
const key = `${name}:${domain}`;
|
|
30
38
|
const cached = cache.get(key);
|
|
31
39
|
if (cached) {
|
|
32
40
|
return cached;
|
|
33
41
|
}
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if (parsedArgs.verbose) {
|
|
43
|
+
console.log("Querying cookies:", name, domain);
|
|
44
|
+
}
|
|
45
|
+
const results: ExportedCookie[][] = await Promise.all(
|
|
46
|
+
this.#strategies.map(async (strategy: CookieQueryStrategy) => {
|
|
36
47
|
// @ts-ignore
|
|
37
|
-
|
|
38
|
-
name,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
return strategy
|
|
49
|
+
.queryCookies(name, domain)
|
|
50
|
+
.then((cookies: ExportedCookie[]) => {
|
|
51
|
+
return cookies.map((cookie: ExportedCookie) => {
|
|
52
|
+
return merge(cookie, {
|
|
53
|
+
meta: {
|
|
54
|
+
browser: strategy.browserName,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.catch((e) => {
|
|
60
|
+
console.log(
|
|
61
|
+
red(`Error querying ${strategy.browserName} cookies`),
|
|
62
|
+
e
|
|
63
|
+
);
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
42
66
|
})
|
|
43
67
|
);
|
|
44
68
|
const flat: ExportedCookie[] = results.flat();
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
2
|
+
import CookieSpec from "../CookieSpec";
|
|
3
|
+
import ExportedCookie from "../ExportedCookie";
|
|
4
|
+
import { Cookie, Store } from "tough-cookie";
|
|
5
|
+
import { cookieJarPromise, cookieStorePromise } from "../CookieStore";
|
|
6
|
+
import { stringToRegex } from "../StringToRegex";
|
|
7
|
+
|
|
8
|
+
export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
9
|
+
browserName = "internal";
|
|
10
|
+
|
|
11
|
+
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
12
|
+
const exportedCookies: ExportedCookie[] = [];
|
|
13
|
+
|
|
14
|
+
// if (name.match(/[%*]/) || domain.match(/[%*]/)) {
|
|
15
|
+
const cookies: Cookie[] = await this.#getAllCookies();
|
|
16
|
+
const allExportedCookies = cookies.map((cookie: Cookie) => {
|
|
17
|
+
return this.#extracted(cookie, { name, domain });
|
|
18
|
+
});
|
|
19
|
+
exportedCookies.push(...allExportedCookies);
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
const wildcardRegexp = /^([*%])$/i;
|
|
23
|
+
if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) {
|
|
24
|
+
return exportedCookies;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const path = "/";
|
|
28
|
+
|
|
29
|
+
if (domain != "%") {
|
|
30
|
+
const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
31
|
+
const url = new URL("https://" + domain1);
|
|
32
|
+
url.pathname = path;
|
|
33
|
+
const cookies: Cookie[] = await this.#getCookies(url.href);
|
|
34
|
+
const domainCookies = cookies.map((cookie: Cookie) => {
|
|
35
|
+
return this.#extracted(cookie, {
|
|
36
|
+
domain,
|
|
37
|
+
name,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
exportedCookies.push(...domainCookies);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (name == "%") {
|
|
44
|
+
return exportedCookies.filter((cookie: ExportedCookie) => {
|
|
45
|
+
return cookie.domain.match(stringToRegex(domain));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return exportedCookies.filter((cookie: ExportedCookie) => {
|
|
50
|
+
return (
|
|
51
|
+
cookie.name.match(stringToRegex(name)) &&
|
|
52
|
+
cookie.domain.match(stringToRegex(domain))
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#extracted(cookie: Cookie, cookieSpec: CookieSpec): ExportedCookie {
|
|
58
|
+
return {
|
|
59
|
+
domain: cookie.domain ?? cookieSpec.domain,
|
|
60
|
+
name: cookie.key ?? cookieSpec.name,
|
|
61
|
+
value: cookie.value,
|
|
62
|
+
expiry: cookie.expires ?? "Infinity",
|
|
63
|
+
meta: {
|
|
64
|
+
file: "tough-cookie",
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async #getCookies(url: string): Promise<Cookie[]> {
|
|
70
|
+
const cookieJar = await cookieJarPromise;
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
return cookieJar.getCookies(
|
|
73
|
+
url,
|
|
74
|
+
(err: Error | null, cookies: Cookie[]) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
} else {
|
|
78
|
+
resolve(cookies ?? []);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async #getAllCookies(): Promise<Cookie[]> {
|
|
86
|
+
const cookieStore: Store = await cookieStorePromise;
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
return cookieStore.getAllCookies(
|
|
89
|
+
(err: Error | null, cookies: Cookie[]) => {
|
|
90
|
+
if (err) {
|
|
91
|
+
reject(err);
|
|
92
|
+
} else {
|
|
93
|
+
resolve(cookies ?? []);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,20 +1,67 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
3
|
-
import {
|
|
4
|
-
import { existsSync } from "fs";
|
|
3
|
+
import { HOME } from "../global";
|
|
4
|
+
import fs, { existsSync } from "fs";
|
|
5
5
|
import { findAllFiles } from "../findAllFiles";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { CookieSpec } from "../CookieSpec";
|
|
6
|
+
import ExportedCookie from "../ExportedCookie";
|
|
7
|
+
import CookieRow from "../CookieRow";
|
|
8
|
+
import CookieSpec from "../CookieSpec";
|
|
10
9
|
import { specialCases } from "../SpecialCases";
|
|
10
|
+
import { parsedArgs } from "../argv";
|
|
11
|
+
import { DoSqliteQuery1Params } from "../doSqliteQuery1Params";
|
|
12
|
+
import * as sqlite3 from "sqlite3";
|
|
13
|
+
import { merge } from "lodash";
|
|
14
|
+
|
|
15
|
+
export async function doSqliteQuery1({
|
|
16
|
+
file,
|
|
17
|
+
sql,
|
|
18
|
+
rowTransform,
|
|
19
|
+
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
20
|
+
if (!file || (file && !fs.existsSync(file))) {
|
|
21
|
+
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
22
|
+
}
|
|
23
|
+
const db = new sqlite3.Database(file);
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
db.all(sql, (err: Error, rows: any[]) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
reject(err);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const rows1: any[] = rows;
|
|
31
|
+
if (rows1 == null || rows1.length === 0) {
|
|
32
|
+
resolve([]);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(rows1)) {
|
|
36
|
+
const cookieRows: CookieRow[] = rows1.map((row: any) => {
|
|
37
|
+
const newVar = {
|
|
38
|
+
meta: {
|
|
39
|
+
file: file,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
43
|
+
return merge(newVar, cookieRow);
|
|
44
|
+
});
|
|
45
|
+
resolve(cookieRows);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (parsedArgs.verbose) {
|
|
49
|
+
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
50
|
+
}
|
|
51
|
+
resolve([rows1]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
11
55
|
|
|
12
56
|
export default class FirefoxCookieQueryStrategy implements CookieQueryStrategy {
|
|
57
|
+
browserName = "Firefox";
|
|
58
|
+
|
|
13
59
|
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
14
60
|
if (process.platform !== "darwin") {
|
|
15
|
-
|
|
61
|
+
// TODO: implement
|
|
62
|
+
return [];
|
|
16
63
|
}
|
|
17
|
-
if (
|
|
64
|
+
if (parsedArgs.browser !== "firefox") {
|
|
18
65
|
return [];
|
|
19
66
|
}
|
|
20
67
|
const cookies = await this.#getFirefoxCookie({ name, domain });
|
|
@@ -47,7 +94,8 @@ export default class FirefoxCookieQueryStrategy implements CookieQueryStrategy {
|
|
|
47
94
|
const fn: (file: string) => Promise<CookieRow[]> = async (file: string) => {
|
|
48
95
|
return await this.#queryCookiesDb(file, name, domain);
|
|
49
96
|
};
|
|
50
|
-
const all:
|
|
97
|
+
const all: CookieRow[][] = await Promise.all(files.map(fn));
|
|
98
|
+
// flatten
|
|
51
99
|
return all.flat();
|
|
52
100
|
}
|
|
53
101
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
2
|
-
import
|
|
2
|
+
import ExportedCookie from "../ExportedCookie";
|
|
3
3
|
|
|
4
4
|
export default class SafariCookieQueryStrategy implements CookieQueryStrategy {
|
|
5
|
+
browserName = "Safari";
|
|
6
|
+
|
|
5
7
|
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
8
|
+
// TODO: implement
|
|
6
9
|
return [];
|
|
7
10
|
}
|
|
8
11
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,118 +1,126 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { argv } from "./argv";
|
|
5
|
-
import { env } from "./global";
|
|
6
|
-
import { queryCookies } from "./queryCookies";
|
|
3
|
+
import { argv, parsedArgs } from "./argv";
|
|
7
4
|
import { groupBy } from "lodash";
|
|
8
|
-
import { green, yellow } from "colorette";
|
|
5
|
+
import { green, red, yellow } from "colorette";
|
|
9
6
|
import { resultsRendered } from "./resultsRendered";
|
|
10
7
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
11
8
|
import { unpackHeaders } from "./unpackHeaders";
|
|
9
|
+
import CookieSpec from "./CookieSpec";
|
|
10
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
11
|
+
import { cookieSpecsFromUrl } from "./cookieSpecsFromUrl";
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async function cliQueryCookies(name: string, domain: string) {
|
|
13
|
+
async function cliQueryCookies(cookieSpec: CookieSpec | CookieSpec[]) {
|
|
16
14
|
try {
|
|
17
|
-
const results = await
|
|
18
|
-
if (results.length
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
const results = await comboQueryCookieSpec(cookieSpec);
|
|
16
|
+
if (results == null || results.length == 0) {
|
|
17
|
+
console.error(red("No results"));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (parsedArgs["dump"] || parsedArgs["d"]) {
|
|
21
|
+
console.log(results);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (parsedArgs["dump-grouped"] || parsedArgs["D"]) {
|
|
25
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
26
|
+
console.log(green(JSON.stringify(groupedByFile, null, 2)));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
parsedArgs["render"] ||
|
|
31
|
+
parsedArgs["render-merged"] ||
|
|
32
|
+
parsedArgs["r"]
|
|
33
|
+
) {
|
|
34
|
+
console.log(yellow(resultsRendered(results)));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (parsedArgs["render-grouped"] || parsedArgs["R"]) {
|
|
38
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
39
|
+
for (const file of Object.keys(groupedByFile)) {
|
|
40
|
+
let results = groupedByFile[file];
|
|
41
|
+
console.log(green(file) + ": ", yellow(resultsRendered(results)));
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const result of results) {
|
|
46
|
+
console.log(result.value);
|
|
41
47
|
}
|
|
42
48
|
} catch (e) {
|
|
43
49
|
console.error(e);
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
function main() {
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
async function main() {
|
|
54
|
+
if (parsedArgs["help"] || parsedArgs["h"]) {
|
|
55
|
+
console.log(`Usage: ${argv[1]} [name] [domain] [options] `);
|
|
56
|
+
console.log(`Options:`);
|
|
57
|
+
console.log(` -h, --help: Show this help`);
|
|
58
|
+
console.log(` -v, --verbose: Show verbose output`);
|
|
59
|
+
console.log(` -d, --dump: Dump all results`);
|
|
60
|
+
console.log(` -D, --dump-grouped: Dump all results, grouped by profile`);
|
|
61
|
+
console.log(` -r, --render: Render all results`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
parsedArgs["verbose"] = parsedArgs["verbose"] || parsedArgs["v"];
|
|
66
|
+
|
|
67
|
+
const fetchUrl: string = parsedArgs["fetch"] || parsedArgs["F"];
|
|
68
|
+
if (fetchUrl) {
|
|
69
|
+
let url: URL;
|
|
70
|
+
try {
|
|
71
|
+
url = new URL(<string>fetchUrl);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error("Invalid URL", fetchUrl);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const headerArgs: string[] | string = parsedArgs["H"];
|
|
77
|
+
const headers = unpackHeaders(headerArgs);
|
|
78
|
+
const onfulfilled = (res: Response) => {
|
|
79
|
+
if (parsedArgs["dump-response-headers"]) {
|
|
80
|
+
res.headers.forEach((value: string, key: string) => {
|
|
81
|
+
console.log(`${key}: ${value}`);
|
|
82
|
+
});
|
|
59
83
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const onfulfilled = (res: Response) => {
|
|
63
|
-
return res.text().then((r) => {
|
|
84
|
+
if (parsedArgs["dump-response-body"]) {
|
|
85
|
+
res.text().then((r) => {
|
|
64
86
|
console.log(r);
|
|
65
87
|
});
|
|
66
|
-
}
|
|
67
|
-
fetchWithCookies(
|
|
68
|
-
url,
|
|
69
|
-
{
|
|
70
|
-
//
|
|
71
|
-
headers,
|
|
72
|
-
}
|
|
73
|
-
//
|
|
74
|
-
).then(
|
|
75
|
-
onfulfilled,
|
|
76
|
-
console.error
|
|
77
|
-
//
|
|
78
|
-
);
|
|
88
|
+
}
|
|
79
89
|
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (argv.includes("--chrome-only")) {
|
|
97
|
-
env.CHROME_ONLY = tru;
|
|
98
|
-
}
|
|
99
|
-
if (argv.includes("--firefox-only")) {
|
|
100
|
-
env.FIREFOX_ONLY = tru;
|
|
101
|
-
}
|
|
102
|
-
if (argv.includes("--ignore-expired")) {
|
|
103
|
-
env.IGNORE_EXPIRED = tru;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (argv.includes("--single")) {
|
|
107
|
-
env.SINGLE = tru;
|
|
108
|
-
}
|
|
90
|
+
};
|
|
91
|
+
fetchWithCookies(
|
|
92
|
+
url,
|
|
93
|
+
{
|
|
94
|
+
//
|
|
95
|
+
headers,
|
|
96
|
+
}
|
|
97
|
+
//
|
|
98
|
+
).then(
|
|
99
|
+
onfulfilled,
|
|
100
|
+
console.error
|
|
101
|
+
//
|
|
102
|
+
);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
const cookieSpecs: CookieSpec[] = [];
|
|
107
|
+
const argUrl: string = parsedArgs["url"] || parsedArgs["u"];
|
|
108
|
+
if (argUrl) {
|
|
109
|
+
for (const cookieSpec of cookieSpecsFromUrl(argUrl)) {
|
|
110
|
+
cookieSpecs.push(cookieSpec);
|
|
112
111
|
}
|
|
112
|
+
} else {
|
|
113
|
+
cookieSpecs.push({
|
|
114
|
+
name: parsedArgs["name"] || parsedArgs["_"][0] || "%",
|
|
115
|
+
domain: parsedArgs["domain"] || parsedArgs["_"][1] || "%",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
113
118
|
|
|
114
|
-
|
|
119
|
+
if (parsedArgs.verbose) {
|
|
120
|
+
console.log("cookieSpecs", cookieSpecs);
|
|
115
121
|
}
|
|
122
|
+
|
|
123
|
+
await cliQueryCookies(cookieSpecs).catch(console.error);
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
main();
|
|
126
|
+
main().then((r) => r, console.error);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import CookieSpec, { MultiCookieSpec } from "./CookieSpec";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
|
+
import { queryCookies } from "./queryCookies";
|
|
4
|
+
import { uniqBy } from "lodash";
|
|
5
|
+
|
|
6
|
+
export async function comboQueryCookieSpec(
|
|
7
|
+
cookieSpec: MultiCookieSpec
|
|
8
|
+
): Promise<ExportedCookie[]> {
|
|
9
|
+
const cookies: ExportedCookie[] = [];
|
|
10
|
+
if (Array.isArray(cookieSpec)) {
|
|
11
|
+
const results: Awaited<ExportedCookie[]>[] = await Promise.all(
|
|
12
|
+
cookieSpec.map((cs) => {
|
|
13
|
+
return queryCookies(cs);
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
for (const exportedCookie of results.flat()) {
|
|
17
|
+
cookies.push(exportedCookie);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
const singleQuery: ExportedCookie[] = await queryCookies(cookieSpec);
|
|
21
|
+
cookies.push(...singleQuery);
|
|
22
|
+
}
|
|
23
|
+
return uniqBy(cookies, JSON.stringify);
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import CookieSpec from "./CookieSpec";
|
|
2
|
+
import { uniqBy } from "lodash";
|
|
3
|
+
|
|
4
|
+
export function cookieSpecsFromUrl(url: URL | string): CookieSpec[] {
|
|
5
|
+
const url1 = typeof url == "string" ? new URL(url) : url;
|
|
6
|
+
const cookieSpecs = [];
|
|
7
|
+
const splits = url1.hostname.split(".");
|
|
8
|
+
const tld = splits.slice(-2).join(".");
|
|
9
|
+
const cookieSpec: CookieSpec = {
|
|
10
|
+
name: "%",
|
|
11
|
+
domain: "%." + tld,
|
|
12
|
+
};
|
|
13
|
+
cookieSpecs.push(cookieSpec);
|
|
14
|
+
const cookieSpec1: CookieSpec = {
|
|
15
|
+
name: "%",
|
|
16
|
+
domain: url1.hostname,
|
|
17
|
+
};
|
|
18
|
+
cookieSpecs.push(cookieSpec1);
|
|
19
|
+
// const isWww = splits.slice(-3)[0] === "www";
|
|
20
|
+
const cookieSpec2: CookieSpec = {
|
|
21
|
+
name: "%",
|
|
22
|
+
domain: tld,
|
|
23
|
+
};
|
|
24
|
+
cookieSpecs.push(cookieSpec2);
|
|
25
|
+
return uniqBy(cookieSpecs, JSON.stringify);
|
|
26
|
+
}
|