@mherod/get-cookie 2.0.0-rc.1 → 2.0.0-rc.10
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 +377 -145
- package/package-lock.json +12295 -0
- package/package.json +10 -7
- package/src/CookieRow.ts +2 -1
- package/src/CookieSpec.ts +2 -2
- package/src/CookieStore.ts +10 -0
- package/src/ExportedCookie.ts +2 -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/argv.ts +4 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +92 -22
- package/src/browsers/CompositeCookieQueryStrategy.ts +32 -8
- package/src/browsers/CookieQueryStrategy.ts +2 -1
- package/src/browsers/CookieStoreQueryStrategy.ts +94 -0
- package/src/browsers/FirefoxCookieQueryStrategy.ts +5 -3
- package/src/browsers/SafariCookieQueryStrategy.ts +3 -1
- package/src/cli.ts +84 -91
- package/src/doSqliteQuery1.ts +4 -8
- package/src/doSqliteQuery1Params.ts +7 -0
- package/src/fetchWithCookies.ts +78 -27
- 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 +19 -22
- package/src/getMergedRenderedCookies.ts +25 -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/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/src/cli.ts
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { argv } from "./argv";
|
|
5
|
-
import { env } from "./global";
|
|
3
|
+
import { argv, parsedArgs } from "./argv";
|
|
6
4
|
import { queryCookies } from "./queryCookies";
|
|
7
5
|
import { groupBy } from "lodash";
|
|
8
|
-
import { green, yellow } from "colorette";
|
|
6
|
+
import { green, red, yellow } from "colorette";
|
|
9
7
|
import { resultsRendered } from "./resultsRendered";
|
|
10
8
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
11
9
|
import { unpackHeaders } from "./unpackHeaders";
|
|
10
|
+
import CookieSpec from "./CookieSpec";
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async function cliQueryCookies(name: string, domain: string) {
|
|
12
|
+
async function cliQueryCookies({ name, domain }: CookieSpec) {
|
|
16
13
|
try {
|
|
17
14
|
const results = await queryCookies({ name, domain });
|
|
18
|
-
if (results.length
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
if (results == null || results.length == 0) {
|
|
16
|
+
console.error(red("No results"));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (parsedArgs["dump"] || parsedArgs["d"]) {
|
|
20
|
+
console.log(results);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (parsedArgs["dump-grouped"] || parsedArgs["D"]) {
|
|
24
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
25
|
+
console.log(green(JSON.stringify(groupedByFile, null, 2)));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (
|
|
29
|
+
parsedArgs["render"] ||
|
|
30
|
+
parsedArgs["render-merged"] ||
|
|
31
|
+
parsedArgs["r"]
|
|
32
|
+
) {
|
|
33
|
+
console.log(yellow(resultsRendered(results)));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (parsedArgs["render-grouped"] || parsedArgs["R"]) {
|
|
37
|
+
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
38
|
+
for (const file of Object.keys(groupedByFile)) {
|
|
39
|
+
let results = groupedByFile[file];
|
|
40
|
+
console.log(green(file) + ": ", yellow(resultsRendered(results)));
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const result of results) {
|
|
45
|
+
console.log(result.value);
|
|
41
46
|
}
|
|
42
47
|
} catch (e) {
|
|
43
48
|
console.error(e);
|
|
@@ -45,74 +50,62 @@ async function cliQueryCookies(name: string, domain: string) {
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
function main() {
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if (parsedArgs["help"] || parsedArgs["h"]) {
|
|
54
|
+
console.log(`Usage: ${argv[1]} [name] [domain] [options] `);
|
|
55
|
+
console.log(`Options:`);
|
|
56
|
+
console.log(` -h, --help: Show this help`);
|
|
57
|
+
console.log(` -v, --verbose: Show verbose output`);
|
|
58
|
+
console.log(` -d, --dump: Dump all results`);
|
|
59
|
+
console.log(` -D, --dump-grouped: Dump all results, grouped by profile`);
|
|
60
|
+
console.log(` -r, --render: Render all results`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const fetchUrl: string = parsedArgs["fetch"] || parsedArgs["F"];
|
|
65
|
+
if (fetchUrl) {
|
|
66
|
+
let url: URL;
|
|
67
|
+
try {
|
|
68
|
+
url = new URL(<string>fetchUrl);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error("Invalid URL", fetchUrl);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const headerArgs: string[] | string = parsedArgs["H"];
|
|
74
|
+
const headers = unpackHeaders(headerArgs);
|
|
75
|
+
const onfulfilled = (res: Response) => {
|
|
76
|
+
if (parsedArgs["dump-response-headers"]) {
|
|
77
|
+
res.headers.forEach((value: string, key: string) => {
|
|
78
|
+
console.log(`${key}: ${value}`);
|
|
79
|
+
});
|
|
59
80
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const onfulfilled = (res: Response) => {
|
|
63
|
-
return res.text().then((r) => {
|
|
81
|
+
if (parsedArgs["dump-response-body"]) {
|
|
82
|
+
res.text().then((r) => {
|
|
64
83
|
console.log(r);
|
|
65
84
|
});
|
|
66
|
-
}
|
|
67
|
-
fetchWithCookies(
|
|
68
|
-
url,
|
|
69
|
-
{
|
|
70
|
-
//
|
|
71
|
-
headers,
|
|
72
|
-
}
|
|
73
|
-
//
|
|
74
|
-
).then(
|
|
75
|
-
onfulfilled,
|
|
76
|
-
console.error
|
|
77
|
-
//
|
|
78
|
-
);
|
|
85
|
+
}
|
|
79
86
|
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
|
-
}
|
|
87
|
+
};
|
|
88
|
+
fetchWithCookies(
|
|
89
|
+
url,
|
|
90
|
+
{
|
|
91
|
+
//
|
|
92
|
+
headers,
|
|
93
|
+
}
|
|
94
|
+
//
|
|
95
|
+
).then(
|
|
96
|
+
onfulfilled,
|
|
97
|
+
console.error
|
|
98
|
+
//
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
109
102
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
const cookieSpec: CookieSpec = {
|
|
104
|
+
name: parsedArgs["name"] || parsedArgs["_"][0] || "%",
|
|
105
|
+
domain: parsedArgs["domain"] || parsedArgs["_"][1] || "%",
|
|
106
|
+
};
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
}
|
|
108
|
+
cliQueryCookies(cookieSpec).catch(console.error);
|
|
116
109
|
}
|
|
117
110
|
|
|
118
111
|
main();
|
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as sqlite3 from "sqlite3";
|
|
3
|
-
import
|
|
3
|
+
import CookieRow from "./CookieRow";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
file: string;
|
|
8
|
-
sql: string;
|
|
9
|
-
rowTransform: (row: any) => CookieRow;
|
|
10
|
-
}
|
|
5
|
+
import { parsedArgs } from "./argv";
|
|
6
|
+
import { DoSqliteQuery1Params } from "./doSqliteQuery1Params";
|
|
11
7
|
|
|
12
8
|
export async function doSqliteQuery1({
|
|
13
9
|
file,
|
|
@@ -42,7 +38,7 @@ export async function doSqliteQuery1({
|
|
|
42
38
|
resolve(cookieRows);
|
|
43
39
|
return;
|
|
44
40
|
}
|
|
45
|
-
if (
|
|
41
|
+
if (parsedArgs.verbose) {
|
|
46
42
|
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
47
43
|
}
|
|
48
44
|
resolve([rows1]);
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
// noinspection JSUnusedGlobalSymbols
|
|
2
2
|
|
|
3
|
-
import { fetch } from "cross-fetch";
|
|
3
|
+
import { fetch as fetchImpl } from "cross-fetch";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
// noinspection SpellCheckingInspection
|
|
6
6
|
import destr from "destr";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
7
|
+
import CookieSpec from "./CookieSpec";
|
|
8
|
+
import { cookieJar } from "./CookieStore";
|
|
9
|
+
import UserAgent from "user-agents";
|
|
10
|
+
import { parsedArgs } from "./argv";
|
|
11
|
+
import { blue, yellow } from "colorette";
|
|
12
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
9
13
|
|
|
10
14
|
export async function fetchWithCookies(
|
|
11
15
|
url: RequestInfo | URL,
|
|
12
|
-
options: RequestInit | undefined = {}
|
|
13
|
-
|
|
16
|
+
options: RequestInit | undefined = {},
|
|
17
|
+
fetch: Function = fetchImpl
|
|
18
|
+
): Promise<Response> {
|
|
14
19
|
const defaultOptions: RequestInit = {
|
|
15
20
|
headers: {
|
|
16
|
-
"User-Agent":
|
|
17
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
|
21
|
+
"User-Agent": new UserAgent().toString(),
|
|
18
22
|
},
|
|
19
23
|
redirect: "manual",
|
|
20
24
|
};
|
|
@@ -23,41 +27,88 @@ export async function fetchWithCookies(
|
|
|
23
27
|
const domain = url1.hostname.replace(/^.*(\.\w+\.\w+)$/, (match, p1) => {
|
|
24
28
|
return `%${p1}`;
|
|
25
29
|
});
|
|
26
|
-
const
|
|
30
|
+
const cookieSpec: CookieSpec = {
|
|
27
31
|
name: "%",
|
|
28
32
|
domain: domain,
|
|
29
|
-
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
};
|
|
34
|
+
// const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
35
|
+
// () => []
|
|
36
|
+
// );
|
|
37
|
+
// const cookie = cookies.pop();
|
|
38
|
+
const cookie = await getMergedRenderedCookies(cookieSpec).catch(() => "");
|
|
39
|
+
const headers = {};
|
|
40
|
+
if (cookie.length > 0) {
|
|
41
|
+
merge(headers, {
|
|
33
42
|
Cookie: cookie,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const newOptions1: RequestInit = merge(defaultOptions, options, { headers });
|
|
36
46
|
try {
|
|
37
47
|
const res: Response = await fetch(url2, newOptions1);
|
|
38
|
-
const
|
|
48
|
+
const headers: [string, string][] = [];
|
|
49
|
+
res.headers.forEach((value, key) => {
|
|
50
|
+
headers.push([key, value]);
|
|
51
|
+
});
|
|
52
|
+
for (const [key, value] of headers) {
|
|
53
|
+
if (key === "set-cookie") {
|
|
54
|
+
await cookieJar.setCookie(value, url2);
|
|
55
|
+
if (parsedArgs.verbose) {
|
|
56
|
+
console.log(blue(`Set-Cookie: ${yellow(value)} ${yellow(url2)}`));
|
|
57
|
+
}
|
|
58
|
+
// const cookie = tough.parse(value);
|
|
59
|
+
// if (cookie instanceof Cookie) {
|
|
60
|
+
// await memoryCookieStore.putCookie(cookie);
|
|
61
|
+
// }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const newUrl: string = res.headers.get("location") as string;
|
|
39
66
|
if (res.redirected || (newUrl && newUrl !== url2)) {
|
|
67
|
+
if (parsedArgs.verbose) {
|
|
68
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
69
|
+
}
|
|
40
70
|
return fetchWithCookies(newUrl, newOptions1);
|
|
41
71
|
}
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
|
|
73
|
+
const arrayBuffer1: Promise<ArrayBuffer> = res.arrayBuffer();
|
|
74
|
+
|
|
75
|
+
async function arrayBuffer(): Promise<ArrayBuffer> {
|
|
76
|
+
return arrayBuffer1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function buffer(): Promise<Buffer> {
|
|
80
|
+
return arrayBuffer().then(Buffer.from);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function text(): Promise<string> {
|
|
84
|
+
return buffer().then((buffer) => buffer.toString("utf8"));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function json(): Promise<any> {
|
|
88
|
+
return text().then((text) => destr(text));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function formData(): Promise<FormData> {
|
|
92
|
+
const urlSearchParams: URLSearchParams = await text().then(
|
|
93
|
+
(text) => new URLSearchParams(text)
|
|
94
|
+
);
|
|
95
|
+
const formData = new FormData();
|
|
96
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
97
|
+
formData.append(key, value);
|
|
98
|
+
}
|
|
99
|
+
return formData;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const res1: Response = res;
|
|
49
103
|
const source2 = {
|
|
50
|
-
status: res.status,
|
|
51
|
-
statusText: res.statusText,
|
|
52
|
-
headers: res.headers,
|
|
53
104
|
arrayBuffer,
|
|
54
|
-
buffer,
|
|
55
105
|
text,
|
|
56
106
|
json,
|
|
107
|
+
buffer,
|
|
57
108
|
formData,
|
|
58
109
|
//
|
|
59
110
|
};
|
|
60
|
-
return merge(
|
|
111
|
+
return merge(res1, source2);
|
|
61
112
|
} catch (e) {
|
|
62
113
|
throw e;
|
|
63
114
|
}
|
package/src/findAllFiles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { env } from "./global";
|
|
2
1
|
import * as fs from "fs";
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
|
|
4
4
|
export async function findAllFiles({
|
|
5
5
|
path,
|
|
@@ -12,16 +12,12 @@ export async function findAllFiles({
|
|
|
12
12
|
maxDepth?: number;
|
|
13
13
|
}): Promise<string[]> {
|
|
14
14
|
const rootSegments = path.split("/").length;
|
|
15
|
-
|
|
16
|
-
if (env.VERBOSE) {
|
|
17
|
-
console.log(`Searching for ${name} in ${path}`);
|
|
18
|
-
}
|
|
19
15
|
const files: string[] = [];
|
|
20
16
|
let readdirSync;
|
|
21
17
|
try {
|
|
22
18
|
readdirSync = fs.readdirSync(path);
|
|
23
19
|
} catch (e) {
|
|
24
|
-
if (
|
|
20
|
+
if (parsedArgs.verbose) {
|
|
25
21
|
console.log(`Error reading ${path}`, e);
|
|
26
22
|
}
|
|
27
23
|
return [];
|
|
@@ -32,7 +28,7 @@ export async function findAllFiles({
|
|
|
32
28
|
try {
|
|
33
29
|
stat = fs.statSync(filePath);
|
|
34
30
|
} catch (e) {
|
|
35
|
-
if (
|
|
31
|
+
if (parsedArgs.verbose) {
|
|
36
32
|
console.error(`Error getting stat for ${filePath}`, e);
|
|
37
33
|
}
|
|
38
34
|
continue;
|
|
@@ -47,7 +43,7 @@ export async function findAllFiles({
|
|
|
47
43
|
});
|
|
48
44
|
files.push(...subFiles);
|
|
49
45
|
} catch (e) {
|
|
50
|
-
if (
|
|
46
|
+
if (parsedArgs.verbose) {
|
|
51
47
|
console.error(e);
|
|
52
48
|
}
|
|
53
49
|
}
|
|
@@ -56,7 +52,7 @@ export async function findAllFiles({
|
|
|
56
52
|
files.push(filePath);
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
|
-
if (
|
|
55
|
+
if (parsedArgs.verbose) {
|
|
60
56
|
if (files.length > 0) {
|
|
61
57
|
console.log(`Found ${files.length} ${name} files`);
|
|
62
58
|
console.log(files);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CookieSpec from "./CookieSpec";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
|
+
import { queryCookies } from "./queryCookies";
|
|
4
|
+
import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
|
|
5
|
+
import { isExportedCookie } from "./IsExportedCookie";
|
|
6
|
+
|
|
7
|
+
export async function getChromeCookie(
|
|
8
|
+
params: CookieSpec
|
|
9
|
+
): Promise<ExportedCookie | undefined> {
|
|
10
|
+
const cookies = await queryCookies(
|
|
11
|
+
params,
|
|
12
|
+
new ChromeCookieQueryStrategy()
|
|
13
|
+
//
|
|
14
|
+
);
|
|
15
|
+
if (cookies.length == 0) {
|
|
16
|
+
throw new Error("Cookie not found");
|
|
17
|
+
}
|
|
18
|
+
return cookies.find(isExportedCookie);
|
|
19
|
+
}
|
package/src/getCookie.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CookieSpec from "./CookieSpec";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
|
+
import { queryCookies } from "./queryCookies";
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
|
+
|
|
6
|
+
export async function getCookie(
|
|
7
|
+
params: CookieSpec
|
|
8
|
+
): Promise<ExportedCookie | undefined> {
|
|
9
|
+
const cookies = await queryCookies(
|
|
10
|
+
params,
|
|
11
|
+
new CompositeCookieQueryStrategy()
|
|
12
|
+
//
|
|
13
|
+
);
|
|
14
|
+
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
15
|
+
return cookies.find((cookie) => cookie != null);
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error("Cookie not found");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CookieSpec from "./CookieSpec";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
|
+
import { queryCookies } from "./queryCookies";
|
|
4
|
+
import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
|
|
5
|
+
|
|
6
|
+
export async function getFirefoxCookie(
|
|
7
|
+
params: CookieSpec
|
|
8
|
+
): Promise<ExportedCookie | undefined> {
|
|
9
|
+
const cookies = await queryCookies(
|
|
10
|
+
params,
|
|
11
|
+
new FirefoxCookieQueryStrategy()
|
|
12
|
+
//
|
|
13
|
+
);
|
|
14
|
+
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
15
|
+
return cookies.find((cookie) => cookie != null);
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error("Cookie not found");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { queryCookies } from "./queryCookies";
|
|
2
|
-
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
3
1
|
import { groupBy } from "lodash";
|
|
2
|
+
import { queryCookies } from "./queryCookies";
|
|
4
3
|
import { resultsRendered } from "./resultsRendered";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
|
+
import CookieSpec from "./CookieSpec";
|
|
6
|
+
import ExportedCookie from "./ExportedCookie";
|
|
7
7
|
|
|
8
|
-
export async function getGroupedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
domain,
|
|
13
|
-
}: //
|
|
14
|
-
CookieSpec
|
|
15
|
-
): //
|
|
16
|
-
Promise<string[]> {
|
|
8
|
+
export async function getGroupedRenderedCookies({
|
|
9
|
+
name,
|
|
10
|
+
domain,
|
|
11
|
+
}: CookieSpec): Promise<string[]> {
|
|
17
12
|
const cookies: ExportedCookie[] = await queryCookies(
|
|
18
|
-
{
|
|
13
|
+
{
|
|
14
|
+
name,
|
|
15
|
+
domain,
|
|
16
|
+
},
|
|
19
17
|
new CompositeCookieQueryStrategy()
|
|
20
18
|
//
|
|
21
19
|
);
|
|
22
|
-
if (
|
|
23
|
-
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
-
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
25
|
-
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
-
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
-
return resultsRendered(results);
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
20
|
+
if (cookies.length == 0) {
|
|
30
21
|
throw new Error("Cookie not found");
|
|
31
22
|
}
|
|
23
|
+
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
+
const groupedByFile = groupBy(results, (r: ExportedCookie) => r.meta?.file);
|
|
25
|
+
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
+
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
+
return resultsRendered(results);
|
|
28
|
+
});
|
|
32
29
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { groupBy } from "lodash";
|
|
2
|
+
import { queryCookies } from "./queryCookies";
|
|
3
|
+
import { resultsRendered } from "./resultsRendered";
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
|
+
import CookieSpec from "./CookieSpec";
|
|
6
|
+
import ExportedCookie from "./ExportedCookie";
|
|
7
|
+
|
|
8
|
+
export async function getMergedRenderedCookies({
|
|
9
|
+
name,
|
|
10
|
+
domain,
|
|
11
|
+
}: CookieSpec): Promise<string> {
|
|
12
|
+
const cookies: ExportedCookie[] = await queryCookies(
|
|
13
|
+
{
|
|
14
|
+
name,
|
|
15
|
+
domain,
|
|
16
|
+
},
|
|
17
|
+
new CompositeCookieQueryStrategy()
|
|
18
|
+
//
|
|
19
|
+
);
|
|
20
|
+
if (cookies.length == 0) {
|
|
21
|
+
throw new Error("Cookie not found");
|
|
22
|
+
}
|
|
23
|
+
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
+
return resultsRendered(results);
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,61 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// noinspection JSUnusedGlobalSymbols
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
8
|
-
import { CookieSpec } from "./CookieSpec";
|
|
9
|
-
import { ExportedCookie } from "./ExportedCookie";
|
|
4
|
+
import { getCookie } from "./getCookie";
|
|
5
|
+
import { getChromeCookie } from "./getChromeCookie";
|
|
6
|
+
import { getFirefoxCookie } from "./getFirefoxCookie";
|
|
10
7
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
8
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
11
9
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
12
10
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return cookies.find((cookie) => cookie != null);
|
|
23
|
-
} else {
|
|
24
|
-
throw new Error("Cookie not found");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getFirefoxCookie(
|
|
29
|
-
params: CookieSpec
|
|
30
|
-
): Promise<ExportedCookie | undefined> {
|
|
31
|
-
const cookies = await queryCookies(
|
|
32
|
-
params,
|
|
33
|
-
new FirefoxCookieQueryStrategy()
|
|
34
|
-
//
|
|
35
|
-
);
|
|
36
|
-
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
37
|
-
return cookies.find((cookie) => cookie != null);
|
|
38
|
-
} else {
|
|
39
|
-
throw new Error("Cookie not found");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function getChromeCookie(
|
|
44
|
-
params: CookieSpec
|
|
45
|
-
): Promise<ExportedCookie | undefined> {
|
|
46
|
-
const cookies = await queryCookies(
|
|
47
|
-
params,
|
|
48
|
-
new ChromeCookieQueryStrategy()
|
|
49
|
-
//
|
|
50
|
-
);
|
|
51
|
-
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
52
|
-
return cookies.find((cookie) => cookie != null);
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error("Cookie not found");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { getGroupedRenderedCookies, fetchWithCookies };
|
|
11
|
+
export {
|
|
12
|
+
getCookie,
|
|
13
|
+
getChromeCookie,
|
|
14
|
+
getFirefoxCookie,
|
|
15
|
+
getMergedRenderedCookies,
|
|
16
|
+
getGroupedRenderedCookies,
|
|
17
|
+
fetchWithCookies,
|
|
18
|
+
//
|
|
19
|
+
};
|
|
59
20
|
|
|
60
21
|
export * from "./CookieSpec";
|
|
61
22
|
export * from "./CookieRow";
|
package/src/isValidJwt.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import jsonwebtoken, { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
import {
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
|
|
4
4
|
export default function isValidJwt(token: any) {
|
|
5
5
|
try {
|
|
6
6
|
const result = jsonwebtoken.decode(token, { complete: true });
|
|
7
|
-
if (
|
|
7
|
+
if (parsedArgs.verbose && result) {
|
|
8
8
|
console.log(result);
|
|
9
9
|
}
|
|
10
10
|
const payload: JwtPayload = result?.payload as JwtPayload;
|